cgtwelve.c revision 1.3 1 1.3 macallan /* $NetBSD: cgtwelve.c,v 1.3 2010/04/14 04:37:11 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.3 macallan __KERNEL_RCSID(0, "$NetBSD: cgtwelve.c,v 1.3 2010/04/14 04:37:11 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.3 macallan bus_space_handle_t sc_regh;
66 1.3 macallan bus_addr_t sc_paddr;
67 1.1 macallan void *sc_fbaddr;
68 1.2 macallan void *sc_shadow;
69 1.3 macallan uint8_t *sc_wids;
70 1.3 macallan void *sc_int;
71 1.1 macallan int sc_width;
72 1.1 macallan int sc_height;
73 1.1 macallan int sc_stride;
74 1.1 macallan int sc_fbsize;
75 1.1 macallan int sc_mode;
76 1.1 macallan struct vcons_data vd;
77 1.1 macallan };
78 1.1 macallan
79 1.1 macallan static int cgtwelve_match(device_t, cfdata_t, void *);
80 1.1 macallan static void cgtwelve_attach(device_t, device_t, void *);
81 1.1 macallan static int cgtwelve_ioctl(void *, void *, u_long, void *, int,
82 1.1 macallan struct lwp*);
83 1.1 macallan static paddr_t cgtwelve_mmap(void *, void *, off_t, int);
84 1.1 macallan static void cgtwelve_init_screen(void *, struct vcons_screen *, int,
85 1.1 macallan long *);
86 1.3 macallan static void cgtwelve_write_wid(struct cgtwelve_softc *, int, uint8_t);
87 1.3 macallan static void cgtwelve_select_ovl(struct cgtwelve_softc *, int);
88 1.3 macallan #define CG12_SEL_OVL 0
89 1.3 macallan #define CG12_SEL_ENABLE 1
90 1.3 macallan #define CG12_SEL_8BIT 2
91 1.3 macallan #define CG12_SEL_24BIT 3
92 1.3 macallan #define CG12_SEL_WID 4
93 1.3 macallan static void cgtwelve_write_dac(struct cgtwelve_softc *, int, int, int, int);
94 1.3 macallan static void cgtwelve_setup(struct cgtwelve_softc *, int);
95 1.1 macallan
96 1.1 macallan CFATTACH_DECL_NEW(cgtwelve, sizeof(struct cgtwelve_softc),
97 1.1 macallan cgtwelve_match, cgtwelve_attach, NULL, NULL);
98 1.1 macallan
99 1.1 macallan struct wsscreen_descr cgtwelve_defscreendesc = {
100 1.1 macallan "default",
101 1.1 macallan 0, 0,
102 1.1 macallan NULL,
103 1.1 macallan 8, 16,
104 1.1 macallan 0,
105 1.1 macallan };
106 1.1 macallan
107 1.1 macallan static struct vcons_screen cgtwelve_console_screen;
108 1.1 macallan
109 1.1 macallan const struct wsscreen_descr *_cgtwelve_scrlist[] = {
110 1.1 macallan &cgtwelve_defscreendesc,
111 1.1 macallan /* XXX other formats, graphics screen? */
112 1.1 macallan };
113 1.1 macallan
114 1.1 macallan struct wsscreen_list cgtwelve_screenlist = {
115 1.1 macallan sizeof(_cgtwelve_scrlist) / sizeof(struct wsscreen_descr *),
116 1.1 macallan _cgtwelve_scrlist
117 1.1 macallan };
118 1.1 macallan
119 1.1 macallan struct wsdisplay_accessops cgtwelve_accessops = {
120 1.1 macallan cgtwelve_ioctl,
121 1.1 macallan cgtwelve_mmap,
122 1.1 macallan NULL, /* vcons_alloc_screen */
123 1.1 macallan NULL, /* vcons_free_screen */
124 1.1 macallan NULL, /* vcons_show_screen */
125 1.1 macallan NULL, /* load_font */
126 1.1 macallan NULL, /* polls */
127 1.1 macallan NULL, /* scroll */
128 1.1 macallan };
129 1.1 macallan
130 1.1 macallan static int
131 1.1 macallan cgtwelve_match(device_t parent, cfdata_t cf, void *aux)
132 1.1 macallan {
133 1.1 macallan struct sbus_attach_args *sa = aux;
134 1.1 macallan
135 1.1 macallan if (strcmp("cgtwelve", sa->sa_name) == 0)
136 1.1 macallan return 100;
137 1.1 macallan return 0;
138 1.1 macallan }
139 1.1 macallan
140 1.1 macallan /*
141 1.1 macallan * Attach a display. We need to notice if it is the console, too.
142 1.1 macallan */
143 1.1 macallan static void
144 1.1 macallan cgtwelve_attach(device_t parent, device_t self, void *args)
145 1.1 macallan {
146 1.1 macallan struct cgtwelve_softc *sc = device_private(self);
147 1.1 macallan struct sbus_attach_args *sa = args;
148 1.1 macallan struct wsemuldisplaydev_attach_args aa;
149 1.1 macallan struct rasops_info *ri;
150 1.1 macallan unsigned long defattr;
151 1.1 macallan bus_space_handle_t bh;
152 1.1 macallan int node = sa->sa_node;
153 1.1 macallan int isconsole;
154 1.1 macallan
155 1.1 macallan aprint_normal("\n");
156 1.1 macallan sc->sc_dev = self;
157 1.1 macallan sc->sc_tag = sa->sa_bustag;
158 1.1 macallan
159 1.3 macallan sc->sc_paddr = sbus_bus_addr(sa->sa_bustag, sa->sa_slot, sa->sa_offset);
160 1.3 macallan
161 1.1 macallan /* read geometry information from the device tree */
162 1.1 macallan sc->sc_width = prom_getpropint(sa->sa_node, "width", 1152);
163 1.1 macallan sc->sc_height = prom_getpropint(sa->sa_node, "height", 900);
164 1.1 macallan sc->sc_stride = (sc->sc_width + 7) >> 3;
165 1.1 macallan
166 1.1 macallan sc->sc_fbsize = sc->sc_height * sc->sc_stride;
167 1.1 macallan sc->sc_fbaddr = (void *)prom_getpropint(sa->sa_node, "address", 0);
168 1.1 macallan if (sc->sc_fbaddr == NULL) {
169 1.1 macallan if (sbus_bus_map(sa->sa_bustag,
170 1.1 macallan sa->sa_slot,
171 1.1 macallan sa->sa_offset + CG12_FB_MONO,
172 1.1 macallan sc->sc_fbsize,
173 1.1 macallan BUS_SPACE_MAP_LINEAR, &bh) != 0) {
174 1.1 macallan aprint_error_dev(self, "cannot map framebuffer\n");
175 1.1 macallan return;
176 1.1 macallan }
177 1.1 macallan sc->sc_fbaddr = bus_space_vaddr(sa->sa_bustag, bh);
178 1.1 macallan }
179 1.1 macallan
180 1.1 macallan aprint_normal_dev(self, "%d x %d\n", sc->sc_width, sc->sc_height);
181 1.1 macallan
182 1.3 macallan
183 1.3 macallan if (sbus_bus_map(sa->sa_bustag,
184 1.3 macallan sa->sa_slot,
185 1.3 macallan sa->sa_offset + CG12_OFF_REGISTERS,
186 1.3 macallan 0xc0000, 0, &sc->sc_regh) != 0) {
187 1.3 macallan aprint_error("%s: couldn't map registers\n",
188 1.3 macallan device_xname(sc->sc_dev));
189 1.3 macallan return;
190 1.3 macallan }
191 1.3 macallan
192 1.3 macallan if (sbus_bus_map(sa->sa_bustag,
193 1.3 macallan sa->sa_slot,
194 1.3 macallan sa->sa_offset + CG12_OFF_WID, 0x100000,
195 1.3 macallan BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_LARGE,
196 1.3 macallan &bh) != 0) {
197 1.3 macallan aprint_error("%s: couldn't map WID\n",
198 1.3 macallan device_xname(sc->sc_dev));
199 1.3 macallan return;
200 1.3 macallan }
201 1.3 macallan sc->sc_wids = bus_space_vaddr(sa->sa_bustag, bh);
202 1.3 macallan
203 1.3 macallan if (sbus_bus_map(sa->sa_bustag,
204 1.3 macallan sa->sa_slot,
205 1.3 macallan sa->sa_offset + CG12_OFF_INTEN, 0x400000,
206 1.3 macallan BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_LARGE,
207 1.3 macallan &bh) != 0) {
208 1.3 macallan aprint_error("%s: couldn't map colour fb\n",
209 1.3 macallan device_xname(sc->sc_dev));
210 1.3 macallan return;
211 1.3 macallan }
212 1.3 macallan sc->sc_int = bus_space_vaddr(sa->sa_bustag, bh);
213 1.3 macallan
214 1.3 macallan cgtwelve_setup(sc, 1);
215 1.3 macallan
216 1.2 macallan sc->sc_shadow = kmem_alloc(sc->sc_fbsize, KM_SLEEP);
217 1.1 macallan isconsole = fb_is_console(node);
218 1.1 macallan
219 1.1 macallan sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
220 1.1 macallan wsfont_init();
221 1.1 macallan
222 1.1 macallan vcons_init(&sc->vd, sc, &cgtwelve_defscreendesc, &cgtwelve_accessops);
223 1.1 macallan sc->vd.init_screen = cgtwelve_init_screen;
224 1.1 macallan
225 1.1 macallan vcons_init_screen(&sc->vd, &cgtwelve_console_screen, 1, &defattr);
226 1.1 macallan cgtwelve_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
227 1.1 macallan
228 1.1 macallan ri = &cgtwelve_console_screen.scr_ri;
229 1.1 macallan
230 1.1 macallan cgtwelve_defscreendesc.nrows = ri->ri_rows;
231 1.1 macallan cgtwelve_defscreendesc.ncols = ri->ri_cols;
232 1.1 macallan cgtwelve_defscreendesc.textops = &ri->ri_ops;
233 1.1 macallan cgtwelve_defscreendesc.capabilities = ri->ri_caps;
234 1.1 macallan
235 1.1 macallan if(isconsole) {
236 1.1 macallan wsdisplay_cnattach(&cgtwelve_defscreendesc, ri, 0, 0, defattr);
237 1.1 macallan vcons_replay_msgbuf(&cgtwelve_console_screen);
238 1.1 macallan }
239 1.1 macallan
240 1.1 macallan aa.console = isconsole;
241 1.1 macallan aa.scrdata = &cgtwelve_screenlist;
242 1.1 macallan aa.accessops = &cgtwelve_accessops;
243 1.1 macallan aa.accesscookie = &sc->vd;
244 1.1 macallan
245 1.1 macallan config_found(self, &aa, wsemuldisplaydevprint);
246 1.3 macallan #if 0
247 1.3 macallan {
248 1.3 macallan bus_space_handle_r bh = sc->sc_regh;
249 1.2 macallan int i, j;
250 1.2 macallan
251 1.2 macallan bus_space_write_4(sa->sa_bustag, bh, CG12_EIC_RESET, 0);
252 1.2 macallan
253 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
254 1.2 macallan CG12DPU_PLN_RDMSK_HOST, CG12_PLN_RD_ENABLE);
255 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
256 1.2 macallan CG12DPU_PLN_WRMSK_HOST, CG12_PLN_WR_ENABLE);
257 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
258 1.2 macallan CG12DPU_PLN_SL_HOST, CG12_PLN_SL_ENABLE);
259 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
260 1.2 macallan CG12APU_HPAGE, CG12_HPAGE_ENABLE);
261 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
262 1.2 macallan CG12APU_HACCESS, CG12_HACCESS_ENABLE);
263 1.2 macallan memset(sc->sc_fbaddr, 0, 0x10000);
264 1.2 macallan
265 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
266 1.2 macallan CG12DPU_PLN_RDMSK_LOC, 0xffffffff);
267 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
268 1.2 macallan CG12DPU_PLN_WRMSK_LOC, 0xffffffff);
269 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
270 1.2 macallan CG12APU_LACCESS, CG12_HACCESS_24BIT);
271 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
272 1.2 macallan CG12APU_LPAGE, CG12_HPAGE_24BIT);
273 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
274 1.2 macallan CG12DPU_PLN_SL_LOCAL0, CG12_PLN_SL_24BIT);
275 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
276 1.2 macallan CG12APU_DWG_CTL, DWGCTL_BITBLT | 0x00f30000);
277 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
278 1.2 macallan CG12APU_F_XLEFT, 10);
279 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
280 1.2 macallan CG12APU_F_XRIGHT, 1010);
281 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
282 1.2 macallan CG12APU_Y_DST, 10);
283 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
284 1.2 macallan CG12DPU_COLOUR0, 0xffffffff);
285 1.2 macallan #if 1
286 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
287 1.2 macallan CG12APU_LENGTH | 0x1000, 800);
288 1.2 macallan #endif
289 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
290 1.2 macallan CG12DPU_PLN_RDMSK_HOST, CG12_PLN_RD_OVERLAY);
291 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
292 1.2 macallan CG12DPU_PLN_WRMSK_HOST, CG12_PLN_WR_OVERLAY);
293 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
294 1.2 macallan CG12DPU_PLN_SL_HOST, CG12_PLN_SL_OVERLAY);
295 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
296 1.2 macallan CG12APU_HPAGE, CG12_HPAGE_OVERLAY);
297 1.2 macallan bus_space_write_4(sa->sa_bustag, bh,
298 1.2 macallan CG12APU_HACCESS, CG12_HACCESS_OVERLAY);
299 1.2 macallan
300 1.2 macallan for (i = 0x100; i < 0x300; i += 32) {
301 1.2 macallan printf("%04x:", i);
302 1.2 macallan for (j = 0; j < 32; j += 4) {
303 1.2 macallan printf(" %08x", bus_space_read_4(sa->sa_bustag,
304 1.2 macallan bh, i + j));
305 1.2 macallan }
306 1.2 macallan printf("\n");
307 1.2 macallan }
308 1.2 macallan }
309 1.2 macallan panic("poof");
310 1.2 macallan #endif
311 1.1 macallan }
312 1.1 macallan
313 1.3 macallan /* 0 - overlay plane, 1 - enable plane, 2 - 8bit fb, 3 - 24bit fb, 4 - WIDs */
314 1.3 macallan static void
315 1.3 macallan cgtwelve_select_ovl(struct cgtwelve_softc *sc, int which)
316 1.3 macallan {
317 1.3 macallan switch(which) {
318 1.3 macallan case 0:
319 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
320 1.3 macallan CG12DPU_PLN_RDMSK_HOST, CG12_PLN_RD_OVERLAY);
321 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
322 1.3 macallan CG12DPU_PLN_WRMSK_HOST, CG12_PLN_WR_OVERLAY);
323 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
324 1.3 macallan CG12DPU_PLN_SL_HOST, CG12_PLN_SL_OVERLAY);
325 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
326 1.3 macallan CG12APU_HPAGE, CG12_HPAGE_OVERLAY);
327 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
328 1.3 macallan CG12APU_HACCESS, CG12_HACCESS_OVERLAY);
329 1.3 macallan break;
330 1.3 macallan case 1:
331 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
332 1.3 macallan CG12DPU_PLN_RDMSK_HOST, CG12_PLN_RD_ENABLE);
333 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
334 1.3 macallan CG12DPU_PLN_WRMSK_HOST, CG12_PLN_WR_ENABLE);
335 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
336 1.3 macallan CG12DPU_PLN_SL_HOST, CG12_PLN_SL_ENABLE);
337 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
338 1.3 macallan CG12APU_HPAGE, CG12_HPAGE_ENABLE);
339 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
340 1.3 macallan CG12APU_HACCESS, CG12_HACCESS_ENABLE);
341 1.3 macallan break;
342 1.3 macallan case 2:
343 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
344 1.3 macallan CG12DPU_PLN_RDMSK_HOST, CG12_PLN_RD_8BIT);
345 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
346 1.3 macallan CG12DPU_PLN_WRMSK_HOST, CG12_PLN_WR_8BIT);
347 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
348 1.3 macallan CG12DPU_PLN_SL_HOST, CG12_PLN_SL_8BIT);
349 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
350 1.3 macallan CG12APU_HPAGE, CG12_HPAGE_8BIT);
351 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
352 1.3 macallan CG12APU_HACCESS, CG12_HACCESS_8BIT);
353 1.3 macallan break;
354 1.3 macallan case 3:
355 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
356 1.3 macallan CG12DPU_PLN_RDMSK_HOST, CG12_PLN_RD_24BIT);
357 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
358 1.3 macallan CG12DPU_PLN_WRMSK_HOST, CG12_PLN_WR_24BIT);
359 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
360 1.3 macallan CG12DPU_PLN_SL_HOST, CG12_PLN_SL_24BIT);
361 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
362 1.3 macallan CG12APU_HPAGE, CG12_HPAGE_24BIT);
363 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
364 1.3 macallan CG12APU_HACCESS, CG12_HACCESS_24BIT);
365 1.3 macallan break;
366 1.3 macallan case 4:
367 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
368 1.3 macallan CG12DPU_PLN_RDMSK_HOST, CG12_PLN_RD_WID);
369 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
370 1.3 macallan CG12DPU_PLN_WRMSK_HOST, CG12_PLN_WR_WID);
371 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
372 1.3 macallan CG12DPU_PLN_SL_HOST, CG12_PLN_SL_WID);
373 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
374 1.3 macallan CG12APU_HPAGE, CG12_HPAGE_WID);
375 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh,
376 1.3 macallan CG12APU_HACCESS, CG12_HACCESS_WID);
377 1.3 macallan break;
378 1.3 macallan }
379 1.3 macallan }
380 1.3 macallan
381 1.3 macallan static void
382 1.3 macallan cgtwelve_write_wid(struct cgtwelve_softc *sc, int idx, uint8_t wid)
383 1.3 macallan {
384 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, CG12_WSC_ADDR, idx << 16);
385 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, CG12_WSC_DATA,
386 1.3 macallan ((uint32_t)wid) << 16);
387 1.3 macallan }
388 1.3 macallan
389 1.3 macallan static void
390 1.3 macallan cgtwelve_write_dac(struct cgtwelve_softc *sc, int idx, int r, int g, int b)
391 1.3 macallan {
392 1.3 macallan uint32_t lo = (idx & 0xff);
393 1.3 macallan uint32_t hi = (idx >> 8) & 0xff;
394 1.3 macallan
395 1.3 macallan lo |= lo << 8 | lo << 16;
396 1.3 macallan hi |= hi << 8 | hi << 16;
397 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, CG12DAC_ADDR0, lo);
398 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, CG12DAC_ADDR1, hi);
399 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, CG12DAC_DATA,
400 1.3 macallan b << 16 | g << 8 | r);
401 1.3 macallan }
402 1.3 macallan
403 1.3 macallan static void
404 1.3 macallan cgtwelve_setup(struct cgtwelve_softc *sc, int depth)
405 1.3 macallan {
406 1.3 macallan int i;
407 1.3 macallan
408 1.3 macallan /* first let's put some stuff into the WID table */
409 1.3 macallan cgtwelve_write_wid(sc, 0, CG12_WID_8_BIT);
410 1.3 macallan cgtwelve_write_wid(sc, 1, CG12_WID_24_BIT);
411 1.3 macallan
412 1.3 macallan /* a linear ramp for the gamma table */
413 1.3 macallan for (i = 0; i < 256; i++)
414 1.3 macallan cgtwelve_write_dac(sc, i + 0x100, i, i, i);
415 1.3 macallan
416 1.3 macallan switch(depth) {
417 1.3 macallan case 1:
418 1.3 macallan /* setup the console */
419 1.3 macallan
420 1.3 macallan /* first, make the overlay all opaque */
421 1.3 macallan cgtwelve_select_ovl(sc, CG12_SEL_ENABLE);
422 1.3 macallan memset(sc->sc_fbaddr, 0xff, 0x20000);
423 1.3 macallan
424 1.3 macallan /* now write the right thing into the WID plane */
425 1.3 macallan cgtwelve_select_ovl(sc, CG12_SEL_WID);
426 1.3 macallan memset(sc->sc_wids, 0, 0x100000);
427 1.3 macallan
428 1.3 macallan /* now clean the plane */
429 1.3 macallan cgtwelve_select_ovl(sc, CG12_SEL_OVL);
430 1.3 macallan memset(sc->sc_fbaddr, 0, 0x20000);
431 1.3 macallan break;
432 1.3 macallan case 24:
433 1.3 macallan case 32:
434 1.3 macallan /* setup the 24bit fb for X */
435 1.3 macallan /*
436 1.3 macallan * first clean the 24bit fb - for aesthetic reasons do it while
437 1.3 macallan * it's still not visible ( we hope... )
438 1.3 macallan */
439 1.3 macallan cgtwelve_select_ovl(sc, CG12_SEL_24BIT);
440 1.3 macallan memset(sc->sc_int, 0x80, 0x400000);
441 1.3 macallan
442 1.3 macallan /* now write the right thing into the WID plane */
443 1.3 macallan cgtwelve_select_ovl(sc, CG12_SEL_WID);
444 1.3 macallan memset(sc->sc_wids, 1, 0x100000);
445 1.3 macallan
446 1.3 macallan /* hide the overlay */
447 1.3 macallan cgtwelve_select_ovl(sc, CG12_SEL_ENABLE);
448 1.3 macallan memset(sc->sc_fbaddr, 0, 0x20000);
449 1.3 macallan
450 1.3 macallan /* now clean the plane */
451 1.3 macallan cgtwelve_select_ovl(sc, CG12_SEL_OVL);
452 1.3 macallan memset(sc->sc_fbaddr, 0, 0x20000);
453 1.3 macallan
454 1.3 macallan /* and make sure we can write the 24bit fb */
455 1.3 macallan cgtwelve_select_ovl(sc, CG12_SEL_24BIT);
456 1.3 macallan break;
457 1.3 macallan }
458 1.3 macallan }
459 1.1 macallan
460 1.1 macallan static void
461 1.1 macallan cgtwelve_init_screen(void *cookie, struct vcons_screen *scr,
462 1.1 macallan int existing, long *defattr)
463 1.1 macallan {
464 1.1 macallan struct cgtwelve_softc *sc = cookie;
465 1.1 macallan struct rasops_info *ri = &scr->scr_ri;
466 1.1 macallan
467 1.1 macallan ri->ri_depth = 1;
468 1.1 macallan ri->ri_width = sc->sc_width;
469 1.1 macallan ri->ri_height = sc->sc_height;
470 1.1 macallan ri->ri_stride = sc->sc_stride;
471 1.1 macallan ri->ri_flg = RI_CENTER;
472 1.1 macallan
473 1.2 macallan if (sc->sc_shadow == NULL) {
474 1.2 macallan ri->ri_bits = sc->sc_fbaddr;
475 1.2 macallan } else {
476 1.2 macallan ri->ri_hwbits = sc->sc_fbaddr;
477 1.2 macallan ri->ri_bits = sc->sc_shadow;
478 1.2 macallan }
479 1.1 macallan
480 1.1 macallan rasops_init(ri, ri->ri_height/8, ri->ri_width/8);
481 1.1 macallan ri->ri_caps = WSSCREEN_REVERSE;
482 1.1 macallan rasops_reconfig(ri, ri->ri_height / ri->ri_font->fontheight,
483 1.1 macallan ri->ri_width / ri->ri_font->fontwidth);
484 1.1 macallan }
485 1.1 macallan
486 1.1 macallan static int
487 1.1 macallan cgtwelve_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
488 1.1 macallan struct lwp *l)
489 1.1 macallan {
490 1.3 macallan struct vcons_data *vd = v;
491 1.3 macallan struct cgtwelve_softc *sc = vd->cookie;
492 1.3 macallan struct wsdisplay_fbinfo *wdf;
493 1.3 macallan struct vcons_screen *ms = vd->active;
494 1.1 macallan
495 1.1 macallan switch (cmd) {
496 1.1 macallan case WSDISPLAYIO_GTYPE:
497 1.1 macallan *(u_int *)data = WSDISPLAY_TYPE_SUNCG12;
498 1.1 macallan return 0;
499 1.3 macallan
500 1.3 macallan case WSDISPLAYIO_GINFO:
501 1.3 macallan wdf = (void *)data;
502 1.3 macallan wdf->height = sc->sc_height;
503 1.3 macallan wdf->width = sc->sc_width;
504 1.3 macallan wdf->depth = 32;
505 1.3 macallan wdf->cmsize = 256;
506 1.3 macallan return 0;
507 1.3 macallan
508 1.3 macallan case FBIOGVIDEO:
509 1.3 macallan case WSDISPLAYIO_GVIDEO:
510 1.3 macallan *(int *)data = 1;
511 1.3 macallan return 0;
512 1.3 macallan
513 1.3 macallan case WSDISPLAYIO_SVIDEO:
514 1.3 macallan case FBIOSVIDEO:
515 1.3 macallan /* when we figure out how to do this... */
516 1.3 macallan /*cgtwelve_set_video(sc, *(int *)data);*/
517 1.3 macallan return 0;
518 1.3 macallan
519 1.3 macallan case WSDISPLAYIO_LINEBYTES:
520 1.3 macallan {
521 1.3 macallan int *ret = (int *)data;
522 1.3 macallan *ret = sc->sc_width << 2;
523 1.3 macallan }
524 1.3 macallan return 0;
525 1.3 macallan
526 1.3 macallan case WSDISPLAYIO_SMODE:
527 1.3 macallan {
528 1.3 macallan int new_mode = *(int*)data;
529 1.3 macallan if (new_mode != sc->sc_mode)
530 1.3 macallan {
531 1.3 macallan sc->sc_mode = new_mode;
532 1.3 macallan if (new_mode == WSDISPLAYIO_MODE_EMUL)
533 1.3 macallan {
534 1.3 macallan cgtwelve_setup(sc, 1);
535 1.3 macallan vcons_redraw_screen(ms);
536 1.3 macallan } else {
537 1.3 macallan cgtwelve_setup(sc, 32);
538 1.3 macallan }
539 1.3 macallan }
540 1.3 macallan }
541 1.1 macallan }
542 1.1 macallan
543 1.1 macallan return EPASSTHROUGH;
544 1.1 macallan }
545 1.1 macallan
546 1.1 macallan static paddr_t
547 1.1 macallan cgtwelve_mmap(void *v, void *vs, off_t offset, int prot)
548 1.1 macallan {
549 1.3 macallan struct vcons_data *vd = v;
550 1.3 macallan struct cgtwelve_softc *sc = vd->cookie;
551 1.1 macallan
552 1.1 macallan /* regular fb mapping at 0 */
553 1.3 macallan if ((offset >= 0) && (offset < 0x400000)) {
554 1.3 macallan return bus_space_mmap(sc->sc_tag, sc->sc_paddr + CG12_OFF_INTEN,
555 1.3 macallan offset, prot, BUS_SPACE_MAP_LINEAR);
556 1.1 macallan }
557 1.1 macallan
558 1.1 macallan return -1;
559 1.1 macallan }
560