xref: /openbsd/sys/arch/sparc64/dev/gfb.c (revision e5dd7070)
1 /*	$OpenBSD: gfb.c,v 1.2 2013/10/20 20:07:27 miod Exp $	*/
2 
3 /*
4  * Copyright (c) 2009 Mark Kettenis.
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #include <sys/param.h>
20 #include <sys/device.h>
21 #include <sys/systm.h>
22 
23 #include <machine/bus.h>
24 #include <machine/autoconf.h>
25 
26 #include <dev/wscons/wsconsio.h>
27 #include <dev/wscons/wsdisplayvar.h>
28 #include <dev/rasops/rasops.h>
29 #include <machine/fbvar.h>
30 
31 struct gfb_softc {
32 	struct sunfb sc_sunfb;
33 	bus_space_tag_t sc_bt;
34 	bus_space_handle_t sc_pixel_h;
35 	int sc_console;
36 	int sc_node;
37 	u_int sc_mode;
38 };
39 
40 int	gfb_match(struct device *, void *, void *);
41 void	gfb_attach(struct device *, struct device *, void *);
42 
43 int	gfb_ioctl(void *, u_long, caddr_t, int, struct proc *);
44 
45 struct wsdisplay_accessops gfb_accessops = {
46 	.ioctl = gfb_ioctl
47 };
48 
49 struct cfdriver gfb_cd = {
50 	NULL, "gfb", DV_DULL
51 };
52 
53 struct cfattach gfb_ca = {
54 	sizeof(struct gfb_softc), gfb_match, gfb_attach
55 };
56 
57 int
58 gfb_match(struct device *parent, void *match, void *aux)
59 {
60 	struct mainbus_attach_args *ma = aux;
61 
62 	if (strcmp(ma->ma_name, "SUNW,gfb") == 0)
63 		return (1);
64 	return (0);
65 }
66 
67 void
68 gfb_attach(struct device *parent, struct device *self, void *aux)
69 {
70 	struct gfb_softc *sc = (struct gfb_softc *)self;
71 	struct mainbus_attach_args *ma = aux;
72 	extern int fbnode;
73 
74 	sc->sc_bt = ma->ma_bustag;
75 
76 	printf("\n");
77 
78 	if (bus_space_map(ma->ma_bustag, ma->ma_reg[6].ur_paddr,
79 	    ma->ma_reg[6].ur_len, BUS_SPACE_MAP_LINEAR, &sc->sc_pixel_h))
80 		return;
81 
82 	sc->sc_console = (fbnode == ma->ma_node);
83 	sc->sc_node = ma->ma_node;
84 
85 	fb_setsize(&sc->sc_sunfb, 32, 1152, 900, sc->sc_node, 0);
86 	/* linesize has a fixed value, compensate */
87 	sc->sc_sunfb.sf_linebytes = 16384;
88 	sc->sc_sunfb.sf_fbsize = sc->sc_sunfb.sf_height * 16384;
89 
90 	sc->sc_sunfb.sf_ro.ri_bits = (void *)bus_space_vaddr(sc->sc_bt,
91 	    sc->sc_pixel_h);
92 	sc->sc_sunfb.sf_ro.ri_hw = sc;
93 	fbwscons_init(&sc->sc_sunfb, 0, sc->sc_console);
94 
95 	if (sc->sc_console)
96 		fbwscons_console_init(&sc->sc_sunfb, -1);
97 
98 	fbwscons_attach(&sc->sc_sunfb, &gfb_accessops, sc->sc_console);
99 	return;
100 }
101 
102 int
103 gfb_ioctl(void *v, u_long cmd, caddr_t data, int flags, struct proc *p)
104 {
105 	struct gfb_softc *sc = v;
106 	struct wsdisplay_fbinfo *wdf;
107 
108 	switch (cmd) {
109 	case WSDISPLAYIO_GTYPE:
110 		*(u_int *)data = WSDISPLAY_TYPE_UNKNOWN;
111 		break;
112 	case WSDISPLAYIO_SMODE:
113 		sc->sc_mode = *(u_int *)data;
114 		break;
115 	case WSDISPLAYIO_GINFO:
116 		wdf = (void *)data;
117 		wdf->height = sc->sc_sunfb.sf_height;
118 		wdf->width  = sc->sc_sunfb.sf_width;
119 		wdf->depth  = sc->sc_sunfb.sf_depth;
120 		wdf->cmsize = 256;
121 		break;
122 	case WSDISPLAYIO_LINEBYTES:
123 		*(u_int *)data = sc->sc_sunfb.sf_linebytes;
124 		break;
125 
126 #if 0
127 	case WSDISPLAYIO_GETCMAP:
128 		return gfb_getcmap(sc, (struct wsdisplay_cmap *)data);
129 	case WSDISPLAYIO_PUTCMAP:
130 		return gfb_putcmap(sc, (struct wsdisplay_cmap *)data);
131 #endif
132 
133 	case WSDISPLAYIO_SVIDEO:
134 	case WSDISPLAYIO_GVIDEO:
135 		break;
136 
137 	case WSDISPLAYIO_GCURPOS:
138 	case WSDISPLAYIO_SCURPOS:
139 	case WSDISPLAYIO_GCURMAX:
140 	case WSDISPLAYIO_GCURSOR:
141 	case WSDISPLAYIO_SCURSOR:
142 	default:
143 		return -1; /* not supported yet */
144         }
145 
146 	return (0);
147 }
148