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