cg4.c revision 1.14 1 1.14 gwr /* $NetBSD: cg4.c,v 1.14 1998/01/26 20:53:17 gwr Exp $ */
2 1.1 gwr
3 1.1 gwr /*
4 1.1 gwr * Copyright (c) 1992, 1993
5 1.1 gwr * The Regents of the University of California. All rights reserved.
6 1.1 gwr *
7 1.1 gwr * This software was developed by the Computer Systems Engineering group
8 1.1 gwr * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 1.1 gwr * contributed to Berkeley.
10 1.1 gwr *
11 1.1 gwr * All advertising materials mentioning features or use of this software
12 1.1 gwr * must display the following acknowledgement:
13 1.1 gwr * This product includes software developed by the University of
14 1.1 gwr * California, Lawrence Berkeley Laboratory.
15 1.1 gwr *
16 1.1 gwr * Redistribution and use in source and binary forms, with or without
17 1.1 gwr * modification, are permitted provided that the following conditions
18 1.1 gwr * are met:
19 1.1 gwr * 1. Redistributions of source code must retain the above copyright
20 1.1 gwr * notice, this list of conditions and the following disclaimer.
21 1.1 gwr * 2. Redistributions in binary form must reproduce the above copyright
22 1.1 gwr * notice, this list of conditions and the following disclaimer in the
23 1.1 gwr * documentation and/or other materials provided with the distribution.
24 1.1 gwr * 3. All advertising materials mentioning features or use of this software
25 1.1 gwr * must display the following acknowledgement:
26 1.1 gwr * This product includes software developed by the University of
27 1.1 gwr * California, Berkeley and its contributors.
28 1.1 gwr * 4. Neither the name of the University nor the names of its contributors
29 1.1 gwr * may be used to endorse or promote products derived from this software
30 1.1 gwr * without specific prior written permission.
31 1.1 gwr *
32 1.1 gwr * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 1.1 gwr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 1.1 gwr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 1.1 gwr * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 1.1 gwr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1 gwr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1 gwr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1 gwr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 1.1 gwr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 1.1 gwr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 1.1 gwr * SUCH DAMAGE.
43 1.1 gwr *
44 1.1 gwr * from: @(#)cgthree.c 8.2 (Berkeley) 10/30/93
45 1.1 gwr */
46 1.1 gwr
47 1.1 gwr /*
48 1.1 gwr * color display (cg4) driver.
49 1.1 gwr *
50 1.11 gwr * Credits, history:
51 1.11 gwr * Gordon Ross created this driver based on the cg3 driver from
52 1.11 gwr * the sparc port as distributed in BSD 4.4 Lite, but included
53 1.11 gwr * support for only the "type B" adapter (Brooktree DACs).
54 1.11 gwr * Ezra Story added support for the "type A" (AMD DACs).
55 1.1 gwr *
56 1.11 gwr * Todo:
57 1.11 gwr * Make this driver handle video interrupts.
58 1.11 gwr * Defer colormap updates to vertical retrace interrupts.
59 1.1 gwr */
60 1.1 gwr
61 1.1 gwr #include <sys/param.h>
62 1.11 gwr #include <sys/systm.h>
63 1.12 gwr #include <sys/conf.h>
64 1.1 gwr #include <sys/device.h>
65 1.1 gwr #include <sys/ioctl.h>
66 1.1 gwr #include <sys/malloc.h>
67 1.1 gwr #include <sys/mman.h>
68 1.12 gwr #include <sys/proc.h>
69 1.1 gwr #include <sys/tty.h>
70 1.1 gwr
71 1.1 gwr #include <vm/vm.h>
72 1.1 gwr
73 1.12 gwr #include <machine/autoconf.h>
74 1.2 gwr #include <machine/cpu.h>
75 1.1 gwr #include <machine/fbio.h>
76 1.12 gwr #include <machine/idprom.h>
77 1.1 gwr #include <machine/pmap.h>
78 1.1 gwr
79 1.1 gwr #include "fbvar.h"
80 1.1 gwr #include "btreg.h"
81 1.1 gwr #include "btvar.h"
82 1.1 gwr #include "cg4reg.h"
83 1.1 gwr
84 1.12 gwr cdev_decl(cg4);
85 1.12 gwr
86 1.11 gwr #define CG4_MMAP_SIZE (CG4_OVERLAY_SIZE + CG4_ENABLE_SIZE + CG4_PIXMAP_SIZE)
87 1.11 gwr
88 1.2 gwr extern unsigned char cpu_machine_id;
89 1.2 gwr
90 1.11 gwr #define CMAP_SIZE 256
91 1.11 gwr struct soft_cmap {
92 1.11 gwr u_char r[CMAP_SIZE];
93 1.11 gwr u_char g[CMAP_SIZE];
94 1.11 gwr u_char b[CMAP_SIZE];
95 1.11 gwr };
96 1.11 gwr
97 1.1 gwr /* per-display variables */
98 1.1 gwr struct cg4_softc {
99 1.1 gwr struct device sc_dev; /* base device */
100 1.1 gwr struct fbdevice sc_fb; /* frame buffer device */
101 1.11 gwr int sc_cg4type; /* A or B */
102 1.11 gwr int sc_pa_overlay; /* phys. addr. of overlay plane */
103 1.11 gwr int sc_pa_enable; /* phys. addr. of enable plane */
104 1.11 gwr int sc_pa_pixmap; /* phys. addr. of color plane */
105 1.14 gwr int sc_video_on; /* zero if blanked */
106 1.14 gwr void *sc_va_cmap; /* Colormap h/w (mapped KVA) */
107 1.14 gwr void *sc_btcm; /* Soft cmap, Brooktree format */
108 1.14 gwr struct soft_cmap sc_cmap; /* Soft cmap, user format */
109 1.1 gwr };
110 1.1 gwr
111 1.1 gwr /* autoconfiguration driver */
112 1.1 gwr static void cg4attach __P((struct device *, struct device *, void *));
113 1.12 gwr static int cg4match __P((struct device *, struct cfdata *, void *));
114 1.1 gwr
115 1.7 thorpej struct cfattach cgfour_ca = {
116 1.7 thorpej sizeof(struct cg4_softc), cg4match, cg4attach
117 1.7 thorpej };
118 1.7 thorpej
119 1.13 thorpej extern struct cfdriver cgfour_cd;
120 1.1 gwr
121 1.12 gwr static int cg4gattr __P((struct fbdevice *, void *));
122 1.12 gwr static int cg4gvideo __P((struct fbdevice *, void *));
123 1.12 gwr static int cg4svideo __P((struct fbdevice *, void *));
124 1.12 gwr static int cg4getcmap __P((struct fbdevice *, void *));
125 1.12 gwr static int cg4putcmap __P((struct fbdevice *, void *));
126 1.1 gwr
127 1.11 gwr static void cg4a_init __P((struct cg4_softc *));
128 1.11 gwr static void cg4a_ldcmap __P((struct cg4_softc *));
129 1.11 gwr
130 1.11 gwr static void cg4b_init __P((struct cg4_softc *));
131 1.11 gwr static void cg4b_ldcmap __P((struct cg4_softc *));
132 1.11 gwr
133 1.11 gwr static struct fbdriver cg4_fbdriver = {
134 1.6 gwr cg4open, cg4close, cg4mmap, cg4gattr,
135 1.1 gwr cg4gvideo, cg4svideo,
136 1.1 gwr cg4getcmap, cg4putcmap };
137 1.1 gwr
138 1.1 gwr /*
139 1.1 gwr * Match a cg4.
140 1.1 gwr */
141 1.1 gwr static int
142 1.12 gwr cg4match(parent, cf, args)
143 1.1 gwr struct device *parent;
144 1.12 gwr struct cfdata *cf;
145 1.12 gwr void *args;
146 1.1 gwr {
147 1.1 gwr struct confargs *ca = args;
148 1.11 gwr int paddr;
149 1.2 gwr
150 1.11 gwr /* XXX: Huge hack due to lack of probe info... */
151 1.11 gwr /* XXX: Machines that might have a cg4 (gag). */
152 1.11 gwr /* XXX: Need info on the "P4" register... */
153 1.2 gwr switch (cpu_machine_id) {
154 1.11 gwr
155 1.11 gwr case SUN3_MACH_110:
156 1.11 gwr /* XXX: Assume type A. */
157 1.11 gwr if (ca->ca_paddr == -1)
158 1.11 gwr ca->ca_paddr = CG4A_DEF_BASE;
159 1.11 gwr if (bus_peek(ca->ca_bustype, ca->ca_paddr, 1) == -1)
160 1.11 gwr return (0);
161 1.11 gwr if (bus_peek(BUS_OBIO, CG4A_OBIO_CMAP, 1) == -1)
162 1.11 gwr return (0);
163 1.11 gwr break;
164 1.11 gwr
165 1.2 gwr case SUN3_MACH_60:
166 1.11 gwr /* XXX: Assume type A. */
167 1.11 gwr if (ca->ca_paddr == -1)
168 1.11 gwr ca->ca_paddr = CG4B_DEF_BASE;
169 1.11 gwr paddr = ca->ca_paddr;
170 1.11 gwr if (bus_peek(ca->ca_bustype, paddr, 1) == -1)
171 1.11 gwr return (0);
172 1.14 gwr /* Make sure we're color */
173 1.11 gwr paddr += CG4B_OFF_PIXMAP;
174 1.11 gwr if (bus_peek(ca->ca_bustype, paddr, 1) == -1)
175 1.11 gwr return (0);
176 1.2 gwr break;
177 1.11 gwr
178 1.2 gwr default:
179 1.2 gwr return (0);
180 1.2 gwr }
181 1.1 gwr
182 1.3 gwr return (1);
183 1.1 gwr }
184 1.1 gwr
185 1.1 gwr /*
186 1.1 gwr * Attach a display. We need to notice if it is the console, too.
187 1.1 gwr */
188 1.1 gwr static void
189 1.1 gwr cg4attach(parent, self, args)
190 1.1 gwr struct device *parent, *self;
191 1.1 gwr void *args;
192 1.1 gwr {
193 1.1 gwr struct cg4_softc *sc = (struct cg4_softc *)self;
194 1.1 gwr struct fbdevice *fb = &sc->sc_fb;
195 1.1 gwr struct confargs *ca = args;
196 1.1 gwr struct fbtype *fbt;
197 1.1 gwr
198 1.11 gwr /* XXX: should do better than this... */
199 1.11 gwr switch (cpu_machine_id) {
200 1.11 gwr case SUN3_MACH_110:
201 1.11 gwr sc->sc_cg4type = CG4_TYPE_A;
202 1.11 gwr break;
203 1.11 gwr case SUN3_MACH_60:
204 1.11 gwr default:
205 1.11 gwr sc->sc_cg4type = CG4_TYPE_B;
206 1.11 gwr }
207 1.11 gwr
208 1.11 gwr fb->fb_driver = &cg4_fbdriver;
209 1.1 gwr fb->fb_private = sc;
210 1.1 gwr fb->fb_name = sc->sc_dev.dv_xname;
211 1.1 gwr
212 1.1 gwr fbt = &fb->fb_fbtype;
213 1.1 gwr fbt->fb_type = FBTYPE_SUN4COLOR;
214 1.1 gwr fbt->fb_depth = 8;
215 1.1 gwr fbt->fb_cmsize = 256;
216 1.1 gwr
217 1.1 gwr fbt->fb_width = 1152;
218 1.1 gwr fbt->fb_height = 900;
219 1.2 gwr fbt->fb_size = CG4_MMAP_SIZE;
220 1.1 gwr
221 1.11 gwr switch (sc->sc_cg4type) {
222 1.11 gwr case CG4_TYPE_A: /* Sun3/110 */
223 1.11 gwr sc->sc_va_cmap = bus_mapin(BUS_OBIO, CG4A_OBIO_CMAP,
224 1.11 gwr sizeof(struct amd_regs));
225 1.11 gwr sc->sc_pa_overlay = ca->ca_paddr + CG4A_OFF_OVERLAY;
226 1.11 gwr sc->sc_pa_enable = ca->ca_paddr + CG4A_OFF_ENABLE;
227 1.11 gwr sc->sc_pa_pixmap = ca->ca_paddr + CG4A_OFF_PIXMAP;
228 1.11 gwr cg4a_init(sc);
229 1.11 gwr break;
230 1.11 gwr
231 1.11 gwr case CG4_TYPE_B: /* Sun3/60 */
232 1.11 gwr default:
233 1.14 gwr sc->sc_va_cmap = bus_mapin(ca->ca_bustype, ca->ca_paddr,
234 1.14 gwr sizeof(struct bt_regs));
235 1.11 gwr sc->sc_pa_overlay = ca->ca_paddr + CG4B_OFF_OVERLAY;
236 1.11 gwr sc->sc_pa_enable = ca->ca_paddr + CG4B_OFF_ENABLE;
237 1.11 gwr sc->sc_pa_pixmap = ca->ca_paddr + CG4B_OFF_PIXMAP;
238 1.11 gwr cg4b_init(sc);
239 1.11 gwr break;
240 1.11 gwr }
241 1.1 gwr
242 1.10 christos printf(" (%dx%d)\n", fbt->fb_width, fbt->fb_height);
243 1.2 gwr fb_attach(fb, 4);
244 1.1 gwr }
245 1.1 gwr
246 1.1 gwr int
247 1.1 gwr cg4open(dev, flags, mode, p)
248 1.1 gwr dev_t dev;
249 1.1 gwr int flags, mode;
250 1.1 gwr struct proc *p;
251 1.1 gwr {
252 1.1 gwr int unit = minor(dev);
253 1.1 gwr
254 1.7 thorpej if (unit >= cgfour_cd.cd_ndevs || cgfour_cd.cd_devs[unit] == NULL)
255 1.1 gwr return (ENXIO);
256 1.1 gwr return (0);
257 1.1 gwr }
258 1.1 gwr
259 1.1 gwr int
260 1.1 gwr cg4close(dev, flags, mode, p)
261 1.1 gwr dev_t dev;
262 1.1 gwr int flags, mode;
263 1.1 gwr struct proc *p;
264 1.1 gwr {
265 1.1 gwr
266 1.1 gwr return (0);
267 1.1 gwr }
268 1.1 gwr
269 1.1 gwr int
270 1.1 gwr cg4ioctl(dev, cmd, data, flags, p)
271 1.1 gwr dev_t dev;
272 1.1 gwr u_long cmd;
273 1.1 gwr caddr_t data;
274 1.1 gwr int flags;
275 1.1 gwr struct proc *p;
276 1.1 gwr {
277 1.7 thorpej struct cg4_softc *sc = cgfour_cd.cd_devs[minor(dev)];
278 1.1 gwr
279 1.1 gwr return (fbioctlfb(&sc->sc_fb, cmd, data));
280 1.1 gwr }
281 1.1 gwr
282 1.1 gwr /*
283 1.1 gwr * Return the address that would map the given device at the given
284 1.1 gwr * offset, allowing for the given protection, or return -1 for error.
285 1.1 gwr *
286 1.1 gwr * X11 expects its mmap'd region to look like this:
287 1.11 gwr * 128k overlay data memory
288 1.11 gwr * 128k overlay enable bitmap
289 1.1 gwr * 1024k color memory
290 1.1 gwr *
291 1.1 gwr * The hardware really looks like this (starting at ca_paddr)
292 1.1 gwr * 4 bytes Brooktree DAC registers
293 1.1 gwr * 2MB-4 gap
294 1.1 gwr * 128k overlay memory
295 1.1 gwr * 1920k gap
296 1.1 gwr * 128k overlay-enable bitmap
297 1.1 gwr * 1920k gap
298 1.1 gwr * 1024k color memory
299 1.1 gwr */
300 1.1 gwr int
301 1.4 mycroft cg4mmap(dev, off, prot)
302 1.1 gwr dev_t dev;
303 1.14 gwr int off;
304 1.2 gwr int prot;
305 1.1 gwr {
306 1.7 thorpej struct cg4_softc *sc = cgfour_cd.cd_devs[minor(dev)];
307 1.2 gwr register int physbase;
308 1.1 gwr
309 1.1 gwr if (off & PGOFSET)
310 1.5 mycroft panic("cg4mmap");
311 1.1 gwr
312 1.14 gwr if ((off < 0) || (off >= CG4_MMAP_SIZE))
313 1.2 gwr return (-1);
314 1.2 gwr
315 1.2 gwr if (off < 0x40000) {
316 1.2 gwr if (off < 0x20000) {
317 1.11 gwr physbase = sc->sc_pa_overlay;
318 1.2 gwr } else {
319 1.2 gwr /* enable plane */
320 1.2 gwr off -= 0x20000;
321 1.11 gwr physbase = sc->sc_pa_enable;
322 1.2 gwr }
323 1.2 gwr } else {
324 1.2 gwr /* pixel map */
325 1.2 gwr off -= 0x40000;
326 1.11 gwr physbase = sc->sc_pa_pixmap;
327 1.1 gwr }
328 1.1 gwr
329 1.1 gwr /*
330 1.1 gwr * I turned on PMAP_NC here to disable the cache as I was
331 1.1 gwr * getting horribly broken behaviour with it on.
332 1.1 gwr */
333 1.2 gwr return ((physbase + off) | PMAP_NC);
334 1.1 gwr }
335 1.1 gwr
336 1.1 gwr /*
337 1.1 gwr * Internal ioctl functions.
338 1.1 gwr */
339 1.1 gwr
340 1.1 gwr /* FBIOGATTR: */
341 1.12 gwr static int cg4gattr(fb, data)
342 1.1 gwr struct fbdevice *fb;
343 1.12 gwr void *data;
344 1.1 gwr {
345 1.12 gwr struct fbgattr *fba = data;
346 1.1 gwr
347 1.1 gwr fba->real_type = fb->fb_fbtype.fb_type;
348 1.1 gwr fba->owner = 0; /* XXX - TIOCCONS stuff? */
349 1.1 gwr fba->fbtype = fb->fb_fbtype;
350 1.1 gwr fba->sattr.flags = 0;
351 1.1 gwr fba->sattr.emu_type = fb->fb_fbtype.fb_type;
352 1.1 gwr fba->sattr.dev_specific[0] = -1;
353 1.1 gwr fba->emu_types[0] = fb->fb_fbtype.fb_type;
354 1.1 gwr fba->emu_types[1] = -1;
355 1.1 gwr return (0);
356 1.1 gwr }
357 1.1 gwr
358 1.1 gwr /* FBIOGVIDEO: */
359 1.12 gwr static int cg4gvideo(fb, data)
360 1.1 gwr struct fbdevice *fb;
361 1.12 gwr void *data;
362 1.1 gwr {
363 1.14 gwr struct cg4_softc *sc = fb->fb_private;
364 1.12 gwr int *on = data;
365 1.1 gwr
366 1.14 gwr *on = sc->sc_video_on;
367 1.1 gwr return (0);
368 1.1 gwr }
369 1.1 gwr
370 1.1 gwr /* FBIOSVIDEO: */
371 1.12 gwr static int cg4svideo(fb, data)
372 1.1 gwr struct fbdevice *fb;
373 1.12 gwr void *data;
374 1.1 gwr {
375 1.14 gwr struct cg4_softc *sc = fb->fb_private;
376 1.12 gwr int *on = data;
377 1.11 gwr
378 1.14 gwr if (sc->sc_video_on == *on)
379 1.14 gwr return (0);
380 1.14 gwr
381 1.14 gwr sc->sc_video_on = *on;
382 1.11 gwr if (sc->sc_cg4type == CG4_TYPE_A)
383 1.14 gwr cg4a_ldcmap(sc);
384 1.11 gwr else
385 1.14 gwr cg4b_ldcmap(sc);
386 1.14 gwr
387 1.11 gwr return (0);
388 1.11 gwr }
389 1.11 gwr
390 1.11 gwr /*
391 1.11 gwr * FBIOGETCMAP:
392 1.11 gwr * Copy current colormap out to user space.
393 1.11 gwr */
394 1.12 gwr static int cg4getcmap(fb, data)
395 1.11 gwr struct fbdevice *fb;
396 1.12 gwr void *data;
397 1.11 gwr {
398 1.11 gwr struct cg4_softc *sc = fb->fb_private;
399 1.11 gwr struct soft_cmap *cm = &sc->sc_cmap;
400 1.14 gwr struct fbcmap *fbcm = data;
401 1.11 gwr int error, start, count;
402 1.11 gwr
403 1.11 gwr start = fbcm->index;
404 1.11 gwr count = fbcm->count;
405 1.11 gwr if ((start < 0) || (start >= CMAP_SIZE) ||
406 1.11 gwr (count < 0) || (start + count > CMAP_SIZE) )
407 1.11 gwr return (EINVAL);
408 1.11 gwr
409 1.11 gwr if ((error = copyout(&cm->r[start], fbcm->red, count)) != 0)
410 1.11 gwr return (error);
411 1.11 gwr
412 1.11 gwr if ((error = copyout(&cm->g[start], fbcm->green, count)) != 0)
413 1.11 gwr return (error);
414 1.11 gwr
415 1.11 gwr if ((error = copyout(&cm->b[start], fbcm->blue, count)) != 0)
416 1.11 gwr return (error);
417 1.11 gwr
418 1.11 gwr return (0);
419 1.11 gwr }
420 1.11 gwr
421 1.11 gwr /*
422 1.11 gwr * FBIOPUTCMAP:
423 1.11 gwr * Copy new colormap from user space and load.
424 1.11 gwr */
425 1.12 gwr static int cg4putcmap(fb, data)
426 1.11 gwr struct fbdevice *fb;
427 1.12 gwr void *data;
428 1.11 gwr {
429 1.11 gwr struct cg4_softc *sc = fb->fb_private;
430 1.11 gwr struct soft_cmap *cm = &sc->sc_cmap;
431 1.14 gwr struct fbcmap *fbcm = data;
432 1.11 gwr int error, start, count;
433 1.11 gwr
434 1.11 gwr start = fbcm->index;
435 1.11 gwr count = fbcm->count;
436 1.11 gwr if ((start < 0) || (start >= CMAP_SIZE) ||
437 1.11 gwr (count < 0) || (start + count > CMAP_SIZE) )
438 1.11 gwr return (EINVAL);
439 1.11 gwr
440 1.11 gwr if ((error = copyin(fbcm->red, &cm->r[start], count)) != 0)
441 1.11 gwr return (error);
442 1.11 gwr
443 1.11 gwr if ((error = copyin(fbcm->green, &cm->g[start], count)) != 0)
444 1.11 gwr return (error);
445 1.11 gwr
446 1.11 gwr if ((error = copyin(fbcm->blue, &cm->b[start], count)) != 0)
447 1.11 gwr return (error);
448 1.11 gwr
449 1.11 gwr if (sc->sc_cg4type == CG4_TYPE_A)
450 1.11 gwr cg4a_ldcmap(sc);
451 1.11 gwr else
452 1.11 gwr cg4b_ldcmap(sc);
453 1.1 gwr
454 1.11 gwr return (0);
455 1.11 gwr }
456 1.11 gwr
457 1.11 gwr /****************************************************************
458 1.11 gwr * Routines for the "Type A" hardware
459 1.11 gwr ****************************************************************/
460 1.11 gwr
461 1.11 gwr static void
462 1.11 gwr cg4a_init(sc)
463 1.11 gwr struct cg4_softc *sc;
464 1.11 gwr {
465 1.11 gwr volatile struct amd_regs *ar = sc->sc_va_cmap;
466 1.11 gwr struct soft_cmap *cm = &sc->sc_cmap;
467 1.11 gwr int i;
468 1.11 gwr
469 1.14 gwr /* Grab initial (current) color map. */
470 1.11 gwr for(i = 0; i < 256; i++) {
471 1.11 gwr cm->r[i] = ar->r[i];
472 1.11 gwr cm->g[i] = ar->g[i];
473 1.11 gwr cm->b[i] = ar->b[i];
474 1.11 gwr }
475 1.11 gwr }
476 1.11 gwr
477 1.11 gwr static void
478 1.11 gwr cg4a_ldcmap(sc)
479 1.11 gwr struct cg4_softc *sc;
480 1.11 gwr {
481 1.11 gwr volatile struct amd_regs *ar = sc->sc_va_cmap;
482 1.11 gwr struct soft_cmap *cm = &sc->sc_cmap;
483 1.11 gwr int i;
484 1.11 gwr
485 1.11 gwr /*
486 1.11 gwr * Now blast them into the chip!
487 1.11 gwr * XXX Should use retrace interrupt!
488 1.11 gwr * Just set a "need load" bit and let the
489 1.11 gwr * retrace interrupt handler do the work.
490 1.11 gwr */
491 1.14 gwr if (sc->sc_video_on) {
492 1.14 gwr /* Update H/W colormap. */
493 1.14 gwr for (i = 0; i < 256; i++) {
494 1.14 gwr ar->r[i] = cm->r[i];
495 1.14 gwr ar->g[i] = cm->g[i];
496 1.14 gwr ar->b[i] = cm->b[i];
497 1.14 gwr }
498 1.14 gwr } else {
499 1.14 gwr /* Clear H/W colormap. */
500 1.11 gwr for (i = 0; i < 256; i++) {
501 1.11 gwr ar->r[i] = 0;
502 1.11 gwr ar->g[i] = 0;
503 1.11 gwr ar->b[i] = 0;
504 1.11 gwr }
505 1.1 gwr }
506 1.11 gwr }
507 1.11 gwr
508 1.11 gwr
509 1.11 gwr /****************************************************************
510 1.11 gwr * Routines for the "Type B" hardware
511 1.11 gwr ****************************************************************/
512 1.1 gwr
513 1.11 gwr static void
514 1.11 gwr cg4b_init(sc)
515 1.11 gwr struct cg4_softc *sc;
516 1.11 gwr {
517 1.11 gwr volatile struct bt_regs *bt = sc->sc_va_cmap;
518 1.11 gwr struct soft_cmap *cm = &sc->sc_cmap;
519 1.14 gwr union bt_cmap *btcm;
520 1.11 gwr int i;
521 1.11 gwr
522 1.14 gwr /* Need a buffer for colormap format translation. */
523 1.14 gwr btcm = malloc(sizeof(union bt_cmap), M_DEVBUF, M_WAITOK);
524 1.14 gwr sc->sc_btcm = btcm;
525 1.14 gwr
526 1.11 gwr /*
527 1.11 gwr * BT458 chip initialization as described in Brooktree's
528 1.11 gwr * 1993 Graphics and Imaging Product Databook (DB004-1/93).
529 1.11 gwr */
530 1.11 gwr bt->bt_addr = 0x04; /* select read mask register */
531 1.11 gwr bt->bt_ctrl = 0xff; /* all planes on */
532 1.11 gwr bt->bt_addr = 0x05; /* select blink mask register */
533 1.11 gwr bt->bt_ctrl = 0x00; /* all planes non-blinking */
534 1.11 gwr bt->bt_addr = 0x06; /* select command register */
535 1.11 gwr bt->bt_ctrl = 0x43; /* palette enabled, overlay planes enabled */
536 1.11 gwr bt->bt_addr = 0x07; /* select test register */
537 1.11 gwr bt->bt_ctrl = 0x00; /* set test mode */
538 1.11 gwr
539 1.11 gwr /* grab initial (current) color map */
540 1.11 gwr bt->bt_addr = 0;
541 1.11 gwr for (i = 0; i < (256 * 3 / 4); i++) {
542 1.11 gwr btcm->cm_chip[i] = bt->bt_cmap;
543 1.11 gwr }
544 1.1 gwr
545 1.14 gwr /* Transpose into H/W cmap into S/W form. */
546 1.11 gwr for (i = 0; i < 256; i++) {
547 1.11 gwr cm->r[i] = btcm->cm_map[i][0];
548 1.11 gwr cm->g[i] = btcm->cm_map[i][1];
549 1.11 gwr cm->b[i] = btcm->cm_map[i][2];
550 1.1 gwr }
551 1.1 gwr }
552 1.1 gwr
553 1.11 gwr static void
554 1.11 gwr cg4b_ldcmap(sc)
555 1.11 gwr struct cg4_softc *sc;
556 1.1 gwr {
557 1.11 gwr volatile struct bt_regs *bt = sc->sc_va_cmap;
558 1.11 gwr struct soft_cmap *cm = &sc->sc_cmap;
559 1.11 gwr union bt_cmap *btcm = sc->sc_btcm;
560 1.11 gwr int i;
561 1.1 gwr
562 1.14 gwr /* Transpose S/W cmap into H/W form. */
563 1.14 gwr for (i = 0; i < 256; i++) {
564 1.14 gwr btcm->cm_map[i][0] = cm->r[i];
565 1.14 gwr btcm->cm_map[i][1] = cm->g[i];
566 1.14 gwr btcm->cm_map[i][2] = cm->b[i];
567 1.14 gwr }
568 1.14 gwr
569 1.11 gwr /*
570 1.11 gwr * Now blast them into the chip!
571 1.11 gwr * XXX Should use retrace interrupt!
572 1.11 gwr * Just set a "need load" bit and let the
573 1.11 gwr * retrace interrupt handler do the work.
574 1.11 gwr */
575 1.11 gwr bt->bt_addr = 0;
576 1.14 gwr if (sc->sc_video_on) {
577 1.14 gwr /* Update H/W colormap. */
578 1.14 gwr for (i = 0; i < (256 * 3 / 4); i++)
579 1.14 gwr bt->bt_cmap = btcm->cm_chip[i];
580 1.14 gwr } else {
581 1.14 gwr /* Clear H/W colormap. */
582 1.11 gwr for (i = 0; i < (256 * 3 / 4); i++)
583 1.11 gwr bt->bt_cmap = 0;
584 1.11 gwr }
585 1.1 gwr }
586 1.11 gwr
587