cgtwelve.c revision 1.2 1 1.2 macallan /* $NetBSD: cgtwelve.c,v 1.2 2010/04/08 16:49:34 macallan Exp $ */
2 1.1 macallan
3 1.1 macallan /*-
4 1.1 macallan * Copyright (c) 2010 Michael Lorenz
5 1.1 macallan * All rights reserved.
6 1.1 macallan *
7 1.1 macallan * Redistribution and use in source and binary forms, with or without
8 1.1 macallan * modification, are permitted provided that the following conditions
9 1.1 macallan * are met:
10 1.1 macallan * 1. Redistributions of source code must retain the above copyright
11 1.1 macallan * notice, this list of conditions and the following disclaimer.
12 1.1 macallan * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 macallan * notice, this list of conditions and the following disclaimer in the
14 1.1 macallan * documentation and/or other materials provided with the distribution.
15 1.1 macallan *
16 1.1 macallan * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.1 macallan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.1 macallan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.1 macallan * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.1 macallan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1 macallan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1 macallan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1 macallan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1 macallan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.1 macallan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 macallan * POSSIBILITY OF SUCH DAMAGE.
27 1.1 macallan */
28 1.1 macallan
29 1.1 macallan /* a console driver for the Sun CG12 / Matrox SG3 graphics board */
30 1.1 macallan
31 1.1 macallan #include <sys/cdefs.h>
32 1.2 macallan __KERNEL_RCSID(0, "$NetBSD: cgtwelve.c,v 1.2 2010/04/08 16:49:34 macallan Exp $");
33 1.1 macallan
34 1.1 macallan #include <sys/param.h>
35 1.1 macallan #include <sys/systm.h>
36 1.1 macallan #include <sys/buf.h>
37 1.1 macallan #include <sys/device.h>
38 1.1 macallan #include <sys/ioctl.h>
39 1.1 macallan #include <sys/conf.h>
40 1.2 macallan #include <sys/kmem.h>
41 1.1 macallan
42 1.1 macallan #include <sys/bus.h>
43 1.1 macallan #include <machine/autoconf.h>
44 1.1 macallan
45 1.1 macallan #include <dev/sbus/sbusvar.h>
46 1.1 macallan #include <dev/sun/fbio.h>
47 1.1 macallan #include <dev/sun/fbvar.h>
48 1.1 macallan
49 1.1 macallan #include <dev/wscons/wsdisplayvar.h>
50 1.1 macallan #include <dev/wscons/wsconsio.h>
51 1.1 macallan #include <dev/wsfont/wsfont.h>
52 1.1 macallan #include <dev/rasops/rasops.h>
53 1.1 macallan
54 1.1 macallan #include <dev/wscons/wsdisplay_vconsvar.h>
55 1.1 macallan
56 1.1 macallan #include <dev/sbus/cgtwelvereg.h>
57 1.1 macallan
58 1.1 macallan #include "opt_wsemul.h"
59 1.1 macallan #include "opt_cgtwelve.h"
60 1.1 macallan
61 1.1 macallan
62 1.1 macallan struct cgtwelve_softc {
63 1.1 macallan device_t sc_dev;
64 1.1 macallan bus_space_tag_t sc_tag;
65 1.1 macallan void *sc_fbaddr;
66 1.2 macallan void *sc_shadow;
67 1.1 macallan int sc_width;
68 1.1 macallan int sc_height;
69 1.1 macallan int sc_stride;
70 1.1 macallan int sc_fbsize;
71 1.1 macallan int sc_mode;
72 1.1 macallan struct vcons_data vd;
73 1.1 macallan };
74 1.1 macallan
75 1.1 macallan static int cgtwelve_match(device_t, cfdata_t, void *);
76 1.1 macallan static void cgtwelve_attach(device_t, device_t, void *);
77 1.1 macallan static int cgtwelve_ioctl(void *, void *, u_long, void *, int,
78 1.1 macallan struct lwp*);
79 1.1 macallan static paddr_t cgtwelve_mmap(void *, void *, off_t, int);
80 1.1 macallan static void cgtwelve_init_screen(void *, struct vcons_screen *, int,
81 1.1 macallan long *);
82 1.1 macallan
83 1.1 macallan CFATTACH_DECL_NEW(cgtwelve, sizeof(struct cgtwelve_softc),
84 1.1 macallan cgtwelve_match, cgtwelve_attach, NULL, NULL);
85 1.1 macallan
86 1.1 macallan struct wsscreen_descr cgtwelve_defscreendesc = {
87 1.1 macallan "default",
88 1.1 macallan 0, 0,
89 1.1 macallan NULL,
90 1.1 macallan 8, 16,
91 1.1 macallan 0,
92 1.1 macallan };
93 1.1 macallan
94 1.1 macallan static struct vcons_screen cgtwelve_console_screen;
95 1.1 macallan
96 1.1 macallan const struct wsscreen_descr *_cgtwelve_scrlist[] = {
97 1.1 macallan &cgtwelve_defscreendesc,
98 1.1 macallan /* XXX other formats, graphics screen? */
99 1.1 macallan };
100 1.1 macallan
101 1.1 macallan struct wsscreen_list cgtwelve_screenlist = {
102 1.1 macallan sizeof(_cgtwelve_scrlist) / sizeof(struct wsscreen_descr *),
103 1.1 macallan _cgtwelve_scrlist
104 1.1 macallan };
105 1.1 macallan
106 1.1 macallan struct wsdisplay_accessops cgtwelve_accessops = {
107 1.1 macallan cgtwelve_ioctl,
108 1.1 macallan cgtwelve_mmap,
109 1.1 macallan NULL, /* vcons_alloc_screen */
110 1.1 macallan NULL, /* vcons_free_screen */
111 1.1 macallan NULL, /* vcons_show_screen */
112 1.1 macallan NULL, /* load_font */
113 1.1 macallan NULL, /* polls */
114 1.1 macallan NULL, /* scroll */
115 1.1 macallan };
116 1.1 macallan
117 1.1 macallan static int
118 1.1 macallan cgtwelve_match(device_t parent, cfdata_t cf, void *aux)
119 1.1 macallan {
120 1.1 macallan struct sbus_attach_args *sa = aux;
121 1.1 macallan
122 1.1 macallan if (strcmp("cgtwelve", sa->sa_name) == 0)
123 1.1 macallan return 100;
124 1.1 macallan return 0;
125 1.1 macallan }
126 1.1 macallan
127 1.1 macallan /*
128 1.1 macallan * Attach a display. We need to notice if it is the console, too.
129 1.1 macallan */
130 1.1 macallan static void
131 1.1 macallan cgtwelve_attach(device_t parent, device_t self, void *args)
132 1.1 macallan {
133 1.1 macallan struct cgtwelve_softc *sc = device_private(self);
134 1.1 macallan struct sbus_attach_args *sa = args;
135 1.1 macallan struct wsemuldisplaydev_attach_args aa;
136 1.1 macallan struct rasops_info *ri;
137 1.1 macallan unsigned long defattr;
138 1.1 macallan bus_space_handle_t bh;
139 1.1 macallan int node = sa->sa_node;
140 1.1 macallan int isconsole;
141 1.1 macallan
142 1.1 macallan aprint_normal("\n");
143 1.1 macallan sc->sc_dev = self;
144 1.1 macallan sc->sc_tag = sa->sa_bustag;
145 1.1 macallan
146 1.1 macallan /* read geometry information from the device tree */
147 1.1 macallan sc->sc_width = prom_getpropint(sa->sa_node, "width", 1152);
148 1.1 macallan sc->sc_height = prom_getpropint(sa->sa_node, "height", 900);
149 1.1 macallan sc->sc_stride = (sc->sc_width + 7) >> 3;
150 1.1 macallan
151 1.1 macallan sc->sc_fbsize = sc->sc_height * sc->sc_stride;
152 1.1 macallan sc->sc_fbaddr = (void *)prom_getpropint(sa->sa_node, "address", 0);
153 1.1 macallan if (sc->sc_fbaddr == NULL) {
154 1.1 macallan if (sbus_bus_map(sa->sa_bustag,
155 1.1 macallan sa->sa_slot,
156 1.1 macallan sa->sa_offset + CG12_FB_MONO,
157 1.1 macallan sc->sc_fbsize,
158 1.1 macallan BUS_SPACE_MAP_LINEAR, &bh) != 0) {
159 1.1 macallan aprint_error_dev(self, "cannot map framebuffer\n");
160 1.1 macallan return;
161 1.1 macallan }
162 1.1 macallan sc->sc_fbaddr = bus_space_vaddr(sa->sa_bustag, bh);
163 1.1 macallan }
164 1.1 macallan
165 1.1 macallan aprint_normal_dev(self, "%d x %d\n", sc->sc_width, sc->sc_height);
166 1.1 macallan
167 1.2 macallan sc->sc_shadow = kmem_alloc(sc->sc_fbsize, KM_SLEEP);
168 1.1 macallan isconsole = fb_is_console(node);
169 1.1 macallan
170 1.1 macallan sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
171 1.1 macallan wsfont_init();
172 1.1 macallan
173 1.1 macallan vcons_init(&sc->vd, sc, &cgtwelve_defscreendesc, &cgtwelve_accessops);
174 1.1 macallan sc->vd.init_screen = cgtwelve_init_screen;
175 1.1 macallan
176 1.1 macallan vcons_init_screen(&sc->vd, &cgtwelve_console_screen, 1, &defattr);
177 1.1 macallan cgtwelve_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
178 1.1 macallan
179 1.1 macallan memset(sc->sc_fbaddr, 0, sc->sc_fbsize);
180 1.1 macallan
181 1.1 macallan ri = &cgtwelve_console_screen.scr_ri;
182 1.1 macallan
183 1.1 macallan cgtwelve_defscreendesc.nrows = ri->ri_rows;
184 1.1 macallan cgtwelve_defscreendesc.ncols = ri->ri_cols;
185 1.1 macallan cgtwelve_defscreendesc.textops = &ri->ri_ops;
186 1.1 macallan cgtwelve_defscreendesc.capabilities = ri->ri_caps;
187 1.1 macallan
188 1.1 macallan if(isconsole) {
189 1.1 macallan wsdisplay_cnattach(&cgtwelve_defscreendesc, ri, 0, 0, defattr);
190 1.1 macallan vcons_replay_msgbuf(&cgtwelve_console_screen);
191 1.1 macallan }
192 1.1 macallan
193 1.1 macallan aa.console = isconsole;
194 1.1 macallan aa.scrdata = &cgtwelve_screenlist;
195 1.1 macallan aa.accessops = &cgtwelve_accessops;
196 1.1 macallan aa.accesscookie = &sc->vd;
197 1.1 macallan
198 1.1 macallan config_found(self, &aa, wsemuldisplaydevprint);
199 1.2 macallan #if 0
200 1.2 macallan if (sbus_bus_map(sa->sa_bustag,
201 1.2 macallan sa->sa_slot,
202 1.2 macallan sa->sa_offset + CG12_OFF_REGISTERS,
203 1.2 macallan 0xc0000, 0, &bh) == 0) {
204 1.2 macallan int i, j;
205 1.2 macallan
206 1.2 macallan bus_space_write_4(sa->sa_bustag, bh, CG12_EIC_RESET, 0);
207 1.2 macallan
208 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
209 1.2 macallan CG12DPU_PLN_RDMSK_HOST, CG12_PLN_RD_ENABLE);
210 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
211 1.2 macallan CG12DPU_PLN_WRMSK_HOST, CG12_PLN_WR_ENABLE);
212 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
213 1.2 macallan CG12DPU_PLN_SL_HOST, CG12_PLN_SL_ENABLE);
214 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
215 1.2 macallan CG12APU_HPAGE, CG12_HPAGE_ENABLE);
216 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
217 1.2 macallan CG12APU_HACCESS, CG12_HACCESS_ENABLE);
218 1.2 macallan memset(sc->sc_fbaddr, 0, 0x10000);
219 1.2 macallan
220 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
221 1.2 macallan CG12DPU_PLN_RDMSK_LOC, 0xffffffff);
222 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
223 1.2 macallan CG12DPU_PLN_WRMSK_LOC, 0xffffffff);
224 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
225 1.2 macallan CG12APU_LACCESS, CG12_HACCESS_24BIT);
226 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
227 1.2 macallan CG12APU_LPAGE, CG12_HPAGE_24BIT);
228 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
229 1.2 macallan CG12DPU_PLN_SL_LOCAL0, CG12_PLN_SL_24BIT);
230 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
231 1.2 macallan CG12APU_DWG_CTL, DWGCTL_BITBLT | 0x00f30000);
232 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
233 1.2 macallan CG12APU_F_XLEFT, 10);
234 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
235 1.2 macallan CG12APU_F_XRIGHT, 1010);
236 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
237 1.2 macallan CG12APU_Y_DST, 10);
238 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
239 1.2 macallan CG12DPU_COLOUR0, 0xffffffff);
240 1.2 macallan #if 1
241 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
242 1.2 macallan CG12APU_LENGTH | 0x1000, 800);
243 1.2 macallan #endif
244 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
245 1.2 macallan CG12DPU_PLN_RDMSK_HOST, CG12_PLN_RD_OVERLAY);
246 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
247 1.2 macallan CG12DPU_PLN_WRMSK_HOST, CG12_PLN_WR_OVERLAY);
248 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
249 1.2 macallan CG12DPU_PLN_SL_HOST, CG12_PLN_SL_OVERLAY);
250 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
251 1.2 macallan CG12APU_HPAGE, CG12_HPAGE_OVERLAY);
252 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
253 1.2 macallan CG12APU_HACCESS, CG12_HACCESS_OVERLAY);
254 1.2 macallan
255 1.2 macallan for (i = 0x100; i < 0x300; i += 32) {
256 1.2 macallan printf("%04x:", i);
257 1.2 macallan for (j = 0; j < 32; j += 4) {
258 1.2 macallan printf(" %08x", bus_space_read_4(sa->sa_bustag,
259 1.2 macallan bh, i + j));
260 1.2 macallan }
261 1.2 macallan printf("\n");
262 1.2 macallan }
263 1.2 macallan bus_space_unmap(sa->sa_bustag, bh, 0xc0000);
264 1.2 macallan }
265 1.2 macallan panic("poof");
266 1.2 macallan #endif
267 1.1 macallan }
268 1.1 macallan
269 1.1 macallan
270 1.1 macallan static void
271 1.1 macallan cgtwelve_init_screen(void *cookie, struct vcons_screen *scr,
272 1.1 macallan int existing, long *defattr)
273 1.1 macallan {
274 1.1 macallan struct cgtwelve_softc *sc = cookie;
275 1.1 macallan struct rasops_info *ri = &scr->scr_ri;
276 1.1 macallan
277 1.1 macallan ri->ri_depth = 1;
278 1.1 macallan ri->ri_width = sc->sc_width;
279 1.1 macallan ri->ri_height = sc->sc_height;
280 1.1 macallan ri->ri_stride = sc->sc_stride;
281 1.1 macallan ri->ri_flg = RI_CENTER;
282 1.1 macallan
283 1.2 macallan if (sc->sc_shadow == NULL) {
284 1.2 macallan ri->ri_bits = sc->sc_fbaddr;
285 1.2 macallan } else {
286 1.2 macallan ri->ri_hwbits = sc->sc_fbaddr;
287 1.2 macallan ri->ri_bits = sc->sc_shadow;
288 1.2 macallan }
289 1.1 macallan
290 1.1 macallan rasops_init(ri, ri->ri_height/8, ri->ri_width/8);
291 1.1 macallan ri->ri_caps = WSSCREEN_REVERSE;
292 1.1 macallan rasops_reconfig(ri, ri->ri_height / ri->ri_font->fontheight,
293 1.1 macallan ri->ri_width / ri->ri_font->fontwidth);
294 1.1 macallan }
295 1.1 macallan
296 1.1 macallan static int
297 1.1 macallan cgtwelve_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
298 1.1 macallan struct lwp *l)
299 1.1 macallan {
300 1.1 macallan
301 1.1 macallan switch (cmd) {
302 1.1 macallan case WSDISPLAYIO_GTYPE:
303 1.1 macallan *(u_int *)data = WSDISPLAY_TYPE_SUNCG12;
304 1.1 macallan return 0;
305 1.1 macallan }
306 1.1 macallan
307 1.1 macallan return EPASSTHROUGH;
308 1.1 macallan }
309 1.1 macallan
310 1.1 macallan static paddr_t
311 1.1 macallan cgtwelve_mmap(void *v, void *vs, off_t offset, int prot)
312 1.1 macallan {
313 1.1 macallan struct cgtwelve_softc *sc = v;
314 1.1 macallan
315 1.1 macallan /* regular fb mapping at 0 */
316 1.1 macallan if ((offset >= 0) && (offset < sc->sc_fbsize)) {
317 1.1 macallan #if 0
318 1.1 macallan return bus_space_mmap(sc->sc_tag, sc->sc_paddr,
319 1.1 macallan CG12_FB_MONO + offset, prot,
320 1.1 macallan BUS_SPACE_MAP_LINEAR);
321 1.1 macallan #endif
322 1.1 macallan }
323 1.1 macallan
324 1.1 macallan return -1;
325 1.1 macallan }
326