cgfour.c revision 1.36 1 1.36 uwe /* $NetBSD: cgfour.c,v 1.36 2003/08/24 17:31:59 uwe Exp $ */
2 1.14 thorpej
3 1.14 thorpej /*-
4 1.14 thorpej * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
5 1.14 thorpej * All rights reserved.
6 1.14 thorpej *
7 1.14 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.14 thorpej * by Jason R. Thorpe.
9 1.14 thorpej *
10 1.14 thorpej * Redistribution and use in source and binary forms, with or without
11 1.14 thorpej * modification, are permitted provided that the following conditions
12 1.14 thorpej * are met:
13 1.14 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.14 thorpej * notice, this list of conditions and the following disclaimer.
15 1.14 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.14 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.14 thorpej * documentation and/or other materials provided with the distribution.
18 1.14 thorpej * 3. All advertising materials mentioning features or use of this software
19 1.14 thorpej * must display the following acknowledgement:
20 1.14 thorpej * This product includes software developed by the NetBSD
21 1.14 thorpej * Foundation, Inc. and its contributors.
22 1.14 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.14 thorpej * contributors may be used to endorse or promote products derived
24 1.14 thorpej * from this software without specific prior written permission.
25 1.14 thorpej *
26 1.14 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.14 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.14 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.14 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.14 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.14 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.14 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.14 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.14 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.14 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.14 thorpej * POSSIBILITY OF SUCH DAMAGE.
37 1.14 thorpej */
38 1.1 thorpej
39 1.1 thorpej /*
40 1.1 thorpej * Copyright (c) 1992, 1993
41 1.1 thorpej * The Regents of the University of California. All rights reserved.
42 1.1 thorpej *
43 1.35 agc * This software was developed by the Computer Systems Engineering group
44 1.35 agc * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
45 1.35 agc * contributed to Berkeley.
46 1.35 agc *
47 1.35 agc * All advertising materials mentioning features or use of this software
48 1.35 agc * must display the following acknowledgement:
49 1.35 agc * This product includes software developed by the University of
50 1.35 agc * California, Lawrence Berkeley Laboratory.
51 1.35 agc *
52 1.35 agc * Redistribution and use in source and binary forms, with or without
53 1.35 agc * modification, are permitted provided that the following conditions
54 1.35 agc * are met:
55 1.35 agc * 1. Redistributions of source code must retain the above copyright
56 1.35 agc * notice, this list of conditions and the following disclaimer.
57 1.35 agc * 2. Redistributions in binary form must reproduce the above copyright
58 1.35 agc * notice, this list of conditions and the following disclaimer in the
59 1.35 agc * documentation and/or other materials provided with the distribution.
60 1.35 agc * 3. Neither the name of the University nor the names of its contributors
61 1.35 agc * may be used to endorse or promote products derived from this software
62 1.35 agc * without specific prior written permission.
63 1.35 agc *
64 1.35 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
65 1.35 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
66 1.35 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
67 1.35 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
68 1.35 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
69 1.35 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
70 1.35 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
71 1.35 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
72 1.35 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
73 1.35 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74 1.35 agc * SUCH DAMAGE.
75 1.35 agc *
76 1.35 agc * from @(#)cgthree.c 8.2 (Berkeley) 10/30/93
77 1.35 agc */
78 1.35 agc
79 1.35 agc /*
80 1.35 agc * Copyright (c) 1995 Theo de Raadt. All rights reserved.
81 1.35 agc *
82 1.1 thorpej * All advertising materials mentioning features or use of this software
83 1.1 thorpej * must display the following acknowledgement:
84 1.1 thorpej * This product includes software developed by Theo de Raadt.
85 1.1 thorpej *
86 1.1 thorpej * This software was developed by the Computer Systems Engineering group
87 1.1 thorpej * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
88 1.1 thorpej * contributed to Berkeley.
89 1.1 thorpej *
90 1.1 thorpej * All advertising materials mentioning features or use of this software
91 1.1 thorpej * must display the following acknowledgement:
92 1.1 thorpej * This product includes software developed by the University of
93 1.1 thorpej * California, Lawrence Berkeley Laboratory.
94 1.1 thorpej *
95 1.1 thorpej * Redistribution and use in source and binary forms, with or without
96 1.1 thorpej * modification, are permitted provided that the following conditions
97 1.1 thorpej * are met:
98 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
99 1.1 thorpej * notice, this list of conditions and the following disclaimer.
100 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
101 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
102 1.1 thorpej * documentation and/or other materials provided with the distribution.
103 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
104 1.1 thorpej * must display the following acknowledgement:
105 1.1 thorpej * This product includes software developed by the University of
106 1.1 thorpej * California, Berkeley and its contributors.
107 1.1 thorpej * 4. Neither the name of the University nor the names of its contributors
108 1.1 thorpej * may be used to endorse or promote products derived from this software
109 1.1 thorpej * without specific prior written permission.
110 1.1 thorpej *
111 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
112 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
113 1.1 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
114 1.1 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
115 1.1 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
116 1.1 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
117 1.1 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
118 1.1 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
119 1.1 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
120 1.1 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
121 1.1 thorpej * SUCH DAMAGE.
122 1.1 thorpej *
123 1.1 thorpej * from @(#)cgthree.c 8.2 (Berkeley) 10/30/93
124 1.1 thorpej */
125 1.1 thorpej
126 1.1 thorpej /*
127 1.1 thorpej * color display (cgfour) driver.
128 1.1 thorpej *
129 1.1 thorpej * Does not handle interrupts, even though they can occur.
130 1.1 thorpej *
131 1.1 thorpej * XXX should defer colormap updates to vertical retrace interrupts
132 1.1 thorpej */
133 1.34 lukem
134 1.34 lukem #include <sys/cdefs.h>
135 1.36 uwe __KERNEL_RCSID(0, "$NetBSD: cgfour.c,v 1.36 2003/08/24 17:31:59 uwe Exp $");
136 1.36 uwe
137 1.36 uwe #include "opt_rcons.h"
138 1.1 thorpej
139 1.1 thorpej #include <sys/param.h>
140 1.4 christos #include <sys/systm.h>
141 1.1 thorpej #include <sys/buf.h>
142 1.1 thorpej #include <sys/device.h>
143 1.1 thorpej #include <sys/ioctl.h>
144 1.1 thorpej #include <sys/malloc.h>
145 1.1 thorpej #include <sys/mman.h>
146 1.1 thorpej #include <sys/tty.h>
147 1.7 christos #include <sys/conf.h>
148 1.1 thorpej
149 1.1 thorpej #include <machine/autoconf.h>
150 1.1 thorpej #include <machine/eeprom.h>
151 1.1 thorpej
152 1.24 pk #include <dev/sun/fbio.h>
153 1.24 pk #include <dev/sun/fbvar.h>
154 1.24 pk #include <dev/sun/btreg.h>
155 1.24 pk #include <dev/sun/btvar.h>
156 1.24 pk #include <dev/sun/pfourreg.h>
157 1.1 thorpej
158 1.1 thorpej /* per-display variables */
159 1.1 thorpej struct cgfour_softc {
160 1.16 pk struct device sc_dev; /* base device */
161 1.16 pk struct fbdevice sc_fb; /* frame buffer device */
162 1.16 pk bus_space_tag_t sc_bustag;
163 1.26 pk bus_addr_t sc_paddr; /* phys address for device mmap() */
164 1.16 pk
165 1.1 thorpej volatile struct fbcontrol *sc_fbc; /* Brooktree registers */
166 1.16 pk union bt_cmap sc_cmap; /* Brooktree color map */
167 1.1 thorpej };
168 1.1 thorpej
169 1.1 thorpej /* autoconfiguration driver */
170 1.1 thorpej static void cgfourattach __P((struct device *, struct device *, void *));
171 1.12 pk static int cgfourmatch __P((struct device *, struct cfdata *, void *));
172 1.16 pk
173 1.6 pk #if defined(SUN4)
174 1.1 thorpej static void cgfourunblank __P((struct device *));
175 1.6 pk #endif
176 1.1 thorpej
177 1.16 pk static int cg4_pfour_probe __P((void *, void *));
178 1.16 pk
179 1.29 thorpej CFATTACH_DECL(cgfour, sizeof(struct cgfour_softc),
180 1.30 thorpej cgfourmatch, cgfourattach, NULL, NULL);
181 1.5 thorpej
182 1.15 thorpej extern struct cfdriver cgfour_cd;
183 1.1 thorpej
184 1.27 gehenna dev_type_open(cgfouropen);
185 1.27 gehenna dev_type_ioctl(cgfourioctl);
186 1.27 gehenna dev_type_mmap(cgfourmmap);
187 1.27 gehenna
188 1.27 gehenna const struct cdevsw cgfour_cdevsw = {
189 1.27 gehenna cgfouropen, nullclose, noread, nowrite, cgfourioctl,
190 1.31 jdolecek nostop, notty, nopoll, cgfourmmap, nokqfilter,
191 1.27 gehenna };
192 1.27 gehenna
193 1.6 pk #if defined(SUN4)
194 1.1 thorpej /* frame buffer generic driver */
195 1.1 thorpej static struct fbdriver cgfourfbdriver = {
196 1.27 gehenna cgfourunblank, cgfouropen, nullclose, cgfourioctl, nopoll,
197 1.31 jdolecek cgfourmmap, nokqfilter
198 1.1 thorpej };
199 1.1 thorpej
200 1.1 thorpej static void cgfourloadcmap __P((struct cgfour_softc *, int, int));
201 1.1 thorpej static int cgfour_get_video __P((struct cgfour_softc *));
202 1.1 thorpej static void cgfour_set_video __P((struct cgfour_softc *, int));
203 1.6 pk #endif
204 1.1 thorpej
205 1.1 thorpej /*
206 1.1 thorpej * Match a cgfour.
207 1.1 thorpej */
208 1.1 thorpej int
209 1.12 pk cgfourmatch(parent, cf, aux)
210 1.1 thorpej struct device *parent;
211 1.12 pk struct cfdata *cf;
212 1.12 pk void *aux;
213 1.1 thorpej {
214 1.16 pk union obio_attach_args *uoba = aux;
215 1.16 pk struct obio4_attach_args *oba;
216 1.1 thorpej
217 1.16 pk if (uoba->uoba_isobio4 == 0)
218 1.1 thorpej return (0);
219 1.1 thorpej
220 1.16 pk oba = &uoba->uoba_oba4;
221 1.26 pk return (bus_space_probe(oba->oba_bustag, oba->oba_paddr,
222 1.17 pk 4, /* probe size */
223 1.17 pk 0, /* offset */
224 1.17 pk 0, /* flags */
225 1.17 pk cg4_pfour_probe, NULL));
226 1.16 pk }
227 1.1 thorpej
228 1.16 pk int
229 1.16 pk cg4_pfour_probe(vaddr, arg)
230 1.16 pk void *vaddr;
231 1.16 pk void *arg;
232 1.16 pk {
233 1.1 thorpej
234 1.16 pk return (fb_pfour_id(vaddr) == PFOUR_ID_COLOR8P1);
235 1.1 thorpej }
236 1.1 thorpej
237 1.1 thorpej /*
238 1.1 thorpej * Attach a display. We need to notice if it is the console, too.
239 1.1 thorpej */
240 1.1 thorpej void
241 1.16 pk cgfourattach(parent, self, aux)
242 1.1 thorpej struct device *parent, *self;
243 1.16 pk void *aux;
244 1.1 thorpej {
245 1.6 pk #if defined(SUN4)
246 1.16 pk struct cgfour_softc *sc = (struct cgfour_softc *)self;
247 1.16 pk union obio_attach_args *uoba = aux;
248 1.16 pk struct obio4_attach_args *oba = &uoba->uoba_oba4;
249 1.16 pk bus_space_handle_t bh;
250 1.16 pk volatile struct bt_regs *bt;
251 1.1 thorpej struct fbdevice *fb = &sc->sc_fb;
252 1.16 pk int ramsize, i, isconsole;
253 1.1 thorpej
254 1.16 pk sc->sc_bustag = oba->oba_bustag;
255 1.16 pk sc->sc_paddr = (bus_addr_t)oba->oba_paddr;
256 1.1 thorpej
257 1.16 pk /* Map the pfour register. */
258 1.26 pk if (bus_space_map(oba->oba_bustag, oba->oba_paddr,
259 1.26 pk sizeof(u_int32_t),
260 1.26 pk BUS_SPACE_MAP_LINEAR,
261 1.26 pk &bh) != 0) {
262 1.16 pk printf("%s: cannot map control registers\n", self->dv_xname);
263 1.1 thorpej return;
264 1.1 thorpej }
265 1.16 pk fb->fb_pfour = (volatile u_int32_t *)bh;
266 1.1 thorpej
267 1.16 pk fb->fb_driver = &cgfourfbdriver;
268 1.16 pk fb->fb_device = &sc->sc_dev;
269 1.16 pk fb->fb_type.fb_type = FBTYPE_SUN4COLOR;
270 1.16 pk fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags & FB_USERMASK;
271 1.16 pk fb->fb_flags |= FB_PFOUR;
272 1.1 thorpej
273 1.1 thorpej ramsize = PFOUR_COLOR_OFF_END - PFOUR_COLOR_OFF_OVERLAY;
274 1.1 thorpej
275 1.1 thorpej fb->fb_type.fb_depth = 8;
276 1.16 pk fb_setsize_eeprom(fb, fb->fb_type.fb_depth, 1152, 900);
277 1.1 thorpej
278 1.1 thorpej fb->fb_type.fb_cmsize = 256;
279 1.1 thorpej fb->fb_type.fb_size = ramsize;
280 1.16 pk printf(": cgfour/p4, %d x %d",
281 1.16 pk fb->fb_type.fb_width, fb->fb_type.fb_height);
282 1.1 thorpej
283 1.1 thorpej isconsole = 0;
284 1.1 thorpej
285 1.6 pk if (CPU_ISSUN4) {
286 1.1 thorpej struct eeprom *eep = (struct eeprom *)eeprom_va;
287 1.1 thorpej
288 1.1 thorpej /*
289 1.1 thorpej * Assume this is the console if there's no eeprom info
290 1.1 thorpej * to be found.
291 1.1 thorpej */
292 1.1 thorpej if (eep == NULL || eep->eeConsole == EE_CONS_P4OPT)
293 1.20 pk isconsole = fb_is_console(0);
294 1.1 thorpej }
295 1.1 thorpej
296 1.1 thorpej #if 0
297 1.1 thorpej /*
298 1.1 thorpej * We don't do any of the console handling here. Instead,
299 1.1 thorpej * we let the bwtwo driver pick up the overlay plane and
300 1.1 thorpej * use it instead. Rconsole should have better performance
301 1.1 thorpej * with the 1-bit depth.
302 1.1 thorpej * -- Jason R. Thorpe <thorpej (at) NetBSD.ORG>
303 1.1 thorpej */
304 1.1 thorpej
305 1.1 thorpej /*
306 1.1 thorpej * When the ROM has mapped in a cgfour display, the address
307 1.1 thorpej * maps only the video RAM, so in any case we have to map the
308 1.1 thorpej * registers ourselves. We only need the video RAM if we are
309 1.1 thorpej * going to print characters via rconsole.
310 1.1 thorpej */
311 1.1 thorpej
312 1.1 thorpej if (isconsole) {
313 1.1 thorpej /* XXX this is kind of a waste */
314 1.1 thorpej fb->fb_pixels = mapiodev(ca->ca_ra.ra_reg,
315 1.13 pk PFOUR_COLOR_OFF_OVERLAY, ramsize);
316 1.1 thorpej }
317 1.1 thorpej #endif
318 1.1 thorpej
319 1.1 thorpej /* Map the Brooktree. */
320 1.26 pk if (bus_space_map(oba->oba_bustag,
321 1.26 pk oba->oba_paddr + PFOUR_COLOR_OFF_CMAP,
322 1.26 pk sizeof(struct fbcontrol),
323 1.26 pk BUS_SPACE_MAP_LINEAR,
324 1.26 pk &bh) != 0) {
325 1.16 pk printf("%s: cannot map control registers\n", self->dv_xname);
326 1.16 pk return;
327 1.16 pk }
328 1.16 pk sc->sc_fbc = (volatile struct fbcontrol *)bh;
329 1.1 thorpej
330 1.1 thorpej /* grab initial (current) color map */
331 1.1 thorpej bt = &sc->sc_fbc->fbc_dac;
332 1.1 thorpej bt->bt_addr = 0;
333 1.1 thorpej for (i = 0; i < 256 * 3 / 4; i++)
334 1.1 thorpej ((char *)&sc->sc_cmap)[i] = bt->bt_cmap >> 24;
335 1.1 thorpej
336 1.1 thorpej BT_INIT(bt, 24);
337 1.1 thorpej
338 1.1 thorpej #if 0 /* See above. */
339 1.1 thorpej if (isconsole) {
340 1.11 christos printf(" (console)\n");
341 1.1 thorpej #if defined(RASTERCONSOLE) && 0 /* XXX been told it doesn't work well. */
342 1.1 thorpej fbrcons_init(fb);
343 1.1 thorpej #endif
344 1.1 thorpej } else
345 1.1 thorpej #endif /* 0 */
346 1.11 christos printf("\n");
347 1.1 thorpej
348 1.1 thorpej /*
349 1.1 thorpej * Even though we're not using rconsole, we'd still like
350 1.1 thorpej * to notice if we're the console framebuffer.
351 1.1 thorpej */
352 1.1 thorpej fb_attach(fb, isconsole);
353 1.6 pk #endif
354 1.1 thorpej }
355 1.1 thorpej
356 1.1 thorpej int
357 1.33 fvdl cgfouropen(dev, flags, mode, p)
358 1.1 thorpej dev_t dev;
359 1.1 thorpej int flags, mode;
360 1.33 fvdl struct proc *p;
361 1.1 thorpej {
362 1.1 thorpej int unit = minor(dev);
363 1.1 thorpej
364 1.5 thorpej if (unit >= cgfour_cd.cd_ndevs || cgfour_cd.cd_devs[unit] == NULL)
365 1.1 thorpej return (ENXIO);
366 1.1 thorpej return (0);
367 1.1 thorpej }
368 1.1 thorpej
369 1.1 thorpej int
370 1.33 fvdl cgfourioctl(dev, cmd, data, flags, p)
371 1.1 thorpej dev_t dev;
372 1.1 thorpej u_long cmd;
373 1.18 pk caddr_t data;
374 1.1 thorpej int flags;
375 1.33 fvdl struct proc *p;
376 1.1 thorpej {
377 1.6 pk #if defined(SUN4)
378 1.18 pk struct cgfour_softc *sc = cgfour_cd.cd_devs[minor(dev)];
379 1.18 pk struct fbgattr *fba;
380 1.1 thorpej int error;
381 1.1 thorpej
382 1.1 thorpej switch (cmd) {
383 1.1 thorpej
384 1.1 thorpej case FBIOGTYPE:
385 1.1 thorpej *(struct fbtype *)data = sc->sc_fb.fb_type;
386 1.1 thorpej break;
387 1.1 thorpej
388 1.1 thorpej case FBIOGATTR:
389 1.1 thorpej fba = (struct fbgattr *)data;
390 1.1 thorpej fba->real_type = sc->sc_fb.fb_type.fb_type;
391 1.1 thorpej fba->owner = 0; /* XXX ??? */
392 1.1 thorpej fba->fbtype = sc->sc_fb.fb_type;
393 1.1 thorpej fba->sattr.flags = 0;
394 1.1 thorpej fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
395 1.1 thorpej fba->sattr.dev_specific[0] = -1;
396 1.1 thorpej fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
397 1.1 thorpej fba->emu_types[1] = -1;
398 1.1 thorpej break;
399 1.1 thorpej
400 1.1 thorpej case FBIOGETCMAP:
401 1.21 pk #define p ((struct fbcmap *)data)
402 1.21 pk return (bt_getcmap(p, &sc->sc_cmap, 256, 1));
403 1.1 thorpej
404 1.1 thorpej case FBIOPUTCMAP:
405 1.1 thorpej /* copy to software map */
406 1.21 pk error = bt_putcmap(p, &sc->sc_cmap, 256, 1);
407 1.1 thorpej if (error)
408 1.1 thorpej return (error);
409 1.1 thorpej /* now blast them into the chip */
410 1.1 thorpej /* XXX should use retrace interrupt */
411 1.1 thorpej cgfourloadcmap(sc, p->index, p->count);
412 1.1 thorpej #undef p
413 1.1 thorpej break;
414 1.1 thorpej
415 1.1 thorpej case FBIOGVIDEO:
416 1.1 thorpej *(int *)data = cgfour_get_video(sc);
417 1.1 thorpej break;
418 1.1 thorpej
419 1.1 thorpej case FBIOSVIDEO:
420 1.1 thorpej cgfour_set_video(sc, *(int *)data);
421 1.1 thorpej break;
422 1.1 thorpej
423 1.1 thorpej default:
424 1.1 thorpej return (ENOTTY);
425 1.1 thorpej }
426 1.6 pk #endif
427 1.1 thorpej return (0);
428 1.1 thorpej }
429 1.1 thorpej
430 1.1 thorpej /*
431 1.1 thorpej * Return the address that would map the given device at the given
432 1.1 thorpej * offset, allowing for the given protection, or return -1 for error.
433 1.1 thorpej *
434 1.1 thorpej * the cg4 maps it's overlay plane for 128K, followed by the enable
435 1.1 thorpej * plane for 128K, followed by the colour plane (for as much colour
436 1.1 thorpej * as their is.)
437 1.6 pk *
438 1.1 thorpej * As well, mapping at an offset of 0x04000000 causes the cg4 to map
439 1.1 thorpej * only it's colour plane, at 0.
440 1.1 thorpej */
441 1.22 simonb paddr_t
442 1.1 thorpej cgfourmmap(dev, off, prot)
443 1.1 thorpej dev_t dev;
444 1.22 simonb off_t off;
445 1.22 simonb int prot;
446 1.1 thorpej {
447 1.18 pk struct cgfour_softc *sc = cgfour_cd.cd_devs[minor(dev)];
448 1.22 simonb off_t poff;
449 1.1 thorpej
450 1.1 thorpej #define START_ENABLE (128*1024)
451 1.1 thorpej #define START_COLOR ((128*1024) + (128*1024))
452 1.1 thorpej #define COLOR_SIZE (sc->sc_fb.fb_type.fb_width * \
453 1.1 thorpej sc->sc_fb.fb_type.fb_height)
454 1.1 thorpej #define END_COLOR (START_COLOR + COLOR_SIZE)
455 1.1 thorpej #define NOOVERLAY (0x04000000)
456 1.1 thorpej
457 1.1 thorpej if (off & PGOFSET)
458 1.1 thorpej panic("cgfourmap");
459 1.1 thorpej
460 1.19 mrg if (off < 0)
461 1.19 mrg return (-1);
462 1.19 mrg else if ((u_int)off >= NOOVERLAY) {
463 1.8 thorpej off -= NOOVERLAY;
464 1.1 thorpej
465 1.1 thorpej /*
466 1.1 thorpej * X11 maps a huge chunk of the frame buffer; far more than
467 1.1 thorpej * there really is. We compensate by double-mapping the
468 1.1 thorpej * first page for as many other pages as it wants
469 1.1 thorpej */
470 1.19 mrg while ((u_int)off >= COLOR_SIZE)
471 1.1 thorpej off -= COLOR_SIZE; /* XXX thorpej ??? */
472 1.1 thorpej
473 1.1 thorpej poff = off + PFOUR_COLOR_OFF_COLOR;
474 1.1 thorpej } else if ((u_int)off < START_ENABLE) {
475 1.1 thorpej /*
476 1.1 thorpej * in overlay plane
477 1.1 thorpej */
478 1.1 thorpej poff = PFOUR_COLOR_OFF_OVERLAY + off;
479 1.1 thorpej } else if ((u_int)off < START_COLOR) {
480 1.1 thorpej /*
481 1.1 thorpej * in enable plane
482 1.1 thorpej */
483 1.1 thorpej poff = (off - START_ENABLE) + PFOUR_COLOR_OFF_ENABLE;
484 1.8 thorpej } else if ((u_int)off < sc->sc_fb.fb_type.fb_size) {
485 1.1 thorpej /*
486 1.1 thorpej * in colour plane
487 1.6 pk */
488 1.1 thorpej poff = (off - START_COLOR) + PFOUR_COLOR_OFF_COLOR;
489 1.1 thorpej } else
490 1.1 thorpej return (-1);
491 1.1 thorpej
492 1.25 eeh return (bus_space_mmap(sc->sc_bustag,
493 1.25 eeh sc->sc_paddr, poff,
494 1.25 eeh prot, BUS_SPACE_MAP_LINEAR));
495 1.1 thorpej }
496 1.1 thorpej
497 1.6 pk #if defined(SUN4)
498 1.6 pk /*
499 1.6 pk * Undo the effect of an FBIOSVIDEO that turns the video off.
500 1.6 pk */
501 1.6 pk static void
502 1.6 pk cgfourunblank(dev)
503 1.6 pk struct device *dev;
504 1.6 pk {
505 1.6 pk
506 1.6 pk cgfour_set_video((struct cgfour_softc *)dev, 1);
507 1.6 pk }
508 1.6 pk
509 1.1 thorpej static int
510 1.1 thorpej cgfour_get_video(sc)
511 1.1 thorpej struct cgfour_softc *sc;
512 1.1 thorpej {
513 1.1 thorpej
514 1.1 thorpej return (fb_pfour_get_video(&sc->sc_fb));
515 1.1 thorpej }
516 1.1 thorpej
517 1.1 thorpej static void
518 1.1 thorpej cgfour_set_video(sc, enable)
519 1.1 thorpej struct cgfour_softc *sc;
520 1.1 thorpej int enable;
521 1.1 thorpej {
522 1.1 thorpej
523 1.1 thorpej fb_pfour_set_video(&sc->sc_fb, enable);
524 1.1 thorpej }
525 1.6 pk
526 1.6 pk /*
527 1.6 pk * Load a subset of the current (new) colormap into the Brooktree DAC.
528 1.6 pk */
529 1.6 pk static void
530 1.6 pk cgfourloadcmap(sc, start, ncolors)
531 1.18 pk struct cgfour_softc *sc;
532 1.18 pk int start, ncolors;
533 1.6 pk {
534 1.18 pk volatile struct bt_regs *bt;
535 1.18 pk u_int *ip, i;
536 1.18 pk int count;
537 1.6 pk
538 1.6 pk ip = &sc->sc_cmap.cm_chip[BT_D4M3(start)]; /* start/4 * 3 */
539 1.6 pk count = BT_D4M3(start + ncolors - 1) - BT_D4M3(start) + 3;
540 1.6 pk bt = &sc->sc_fbc->fbc_dac;
541 1.6 pk bt->bt_addr = BT_D4M4(start) << 24;
542 1.6 pk while (--count >= 0) {
543 1.6 pk i = *ip++;
544 1.6 pk /* hardware that makes one want to pound boards with hammers */
545 1.6 pk bt->bt_cmap = i;
546 1.6 pk bt->bt_cmap = i << 8;
547 1.6 pk bt->bt_cmap = i << 16;
548 1.6 pk bt->bt_cmap = i << 24;
549 1.6 pk }
550 1.6 pk }
551 1.6 pk #endif
552