1 /* $NetBSD: cgfour.c,v 1.44 2008/04/28 20:23:35 martin Exp $ */
4 * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1992, 1993
34 * The Regents of the University of California. All rights reserved.
36 * This software was developed by the Computer Systems Engineering group
37 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
38 * contributed to Berkeley.
40 * All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Lawrence Berkeley Laboratory.
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions
48 * 1. Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 * 2. Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution.
53 * 3. Neither the name of the University nor the names of its contributors
54 * may be used to endorse or promote products derived from this software
55 * without specific prior written permission.
57 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
58 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
59 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
60 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
61 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
62 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
63 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
64 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
65 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
66 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * from @(#)cgthree.c 8.2 (Berkeley) 10/30/93
73 * Copyright (c) 1995 Theo de Raadt. All rights reserved.
75 * Redistribution and use in source and binary forms, with or without
76 * modification, are permitted provided that the following conditions
78 * 1. Redistributions of source code must retain the above copyright
79 * notice, this list of conditions and the following disclaimer.
80 * 2. Redistributions in binary form must reproduce the above copyright
81 * notice, this list of conditions and the following disclaimer in the
82 * documentation and/or other materials provided with the distribution.
84 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
85 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
86 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
87 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
88 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
89 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
90 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
91 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
92 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
93 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
97 * color display (cgfour) driver.
99 * Does not handle interrupts, even though they can occur.
101 * XXX should defer colormap updates to vertical retrace interrupts
104 #include <sys/cdefs.h>
105 __KERNEL_RCSID(0, "$NetBSD: cgfour.c,v 1.44 2008/04/28 20:23:35 martin Exp $");
107 #include <sys/param.h>
108 #include <sys/systm.h>
110 #include <sys/device.h>
111 #include <sys/ioctl.h>
112 #include <sys/malloc.h>
113 #include <sys/mman.h>
115 #include <sys/conf.h>
117 #include <machine/autoconf.h>
118 #include <machine/eeprom.h>
120 #include <dev/sun/fbio.h>
121 #include <dev/sun/fbvar.h>
122 #include <dev/sun/btreg.h>
123 #include <dev/sun/btvar.h>
124 #include <dev/sun/pfourreg.h>
126 /* per-display variables */
127 struct cgfour_softc
{
128 struct device sc_dev
; /* base device */
129 struct fbdevice sc_fb
; /* frame buffer device */
130 bus_space_tag_t sc_bustag
;
131 bus_addr_t sc_paddr
; /* phys address for device mmap() */
133 volatile struct fbcontrol
*sc_fbc
; /* Brooktree registers */
134 union bt_cmap sc_cmap
; /* Brooktree color map */
137 /* autoconfiguration driver */
138 static int cgfourmatch(struct device
*, struct cfdata
*, void *);
139 static void cgfourattach(struct device
*, struct device
*, void *);
142 static void cgfourunblank(struct device
*);
145 static int cg4_pfour_probe(void *, void *);
147 CFATTACH_DECL(cgfour
, sizeof(struct cgfour_softc
),
148 cgfourmatch
, cgfourattach
, NULL
, NULL
);
150 extern struct cfdriver cgfour_cd
;
152 dev_type_open(cgfouropen
);
153 dev_type_ioctl(cgfourioctl
);
154 dev_type_mmap(cgfourmmap
);
156 const struct cdevsw cgfour_cdevsw
= {
157 cgfouropen
, nullclose
, noread
, nowrite
, cgfourioctl
,
158 nostop
, notty
, nopoll
, cgfourmmap
, nokqfilter
,
162 /* frame buffer generic driver */
163 static struct fbdriver cgfourfbdriver
= {
164 cgfourunblank
, cgfouropen
, nullclose
, cgfourioctl
, nopoll
,
165 cgfourmmap
, nokqfilter
168 static void cgfourloadcmap(struct cgfour_softc
*, int, int);
169 static int cgfour_get_video(struct cgfour_softc
*);
170 static void cgfour_set_video(struct cgfour_softc
*, int);
177 cgfourmatch(struct device
*parent
, struct cfdata
*cf
, void *aux
)
179 union obio_attach_args
*uoba
= aux
;
180 struct obio4_attach_args
*oba
;
182 if (uoba
->uoba_isobio4
== 0)
185 oba
= &uoba
->uoba_oba4
;
186 return (bus_space_probe(oba
->oba_bustag
, oba
->oba_paddr
,
190 cg4_pfour_probe
, NULL
));
194 cg4_pfour_probe(void *vaddr
, void *arg
)
197 return (fb_pfour_id(vaddr
) == PFOUR_ID_COLOR8P1
);
201 * Attach a display. We need to notice if it is the console, too.
204 cgfourattach(struct device
*parent
, struct device
*self
, void *aux
)
207 struct cgfour_softc
*sc
= device_private(self
);
208 union obio_attach_args
*uoba
= aux
;
209 struct obio4_attach_args
*oba
= &uoba
->uoba_oba4
;
210 bus_space_handle_t bh
;
211 volatile struct bt_regs
*bt
;
212 struct fbdevice
*fb
= &sc
->sc_fb
;
213 int ramsize
, i
, isconsole
;
215 sc
->sc_bustag
= oba
->oba_bustag
;
216 sc
->sc_paddr
= (bus_addr_t
)oba
->oba_paddr
;
218 /* Map the pfour register. */
219 if (bus_space_map(oba
->oba_bustag
, oba
->oba_paddr
,
221 BUS_SPACE_MAP_LINEAR
,
223 printf("%s: cannot map control registers\n", self
->dv_xname
);
226 fb
->fb_pfour
= (volatile uint32_t *)bh
;
228 fb
->fb_driver
= &cgfourfbdriver
;
229 fb
->fb_device
= &sc
->sc_dev
;
230 fb
->fb_type
.fb_type
= FBTYPE_SUN4COLOR
;
231 fb
->fb_flags
= device_cfdata(&sc
->sc_dev
)->cf_flags
& FB_USERMASK
;
232 fb
->fb_flags
|= FB_PFOUR
;
234 ramsize
= PFOUR_COLOR_OFF_END
- PFOUR_COLOR_OFF_OVERLAY
;
236 fb
->fb_type
.fb_depth
= 8;
237 fb_setsize_eeprom(fb
, fb
->fb_type
.fb_depth
, 1152, 900);
239 fb
->fb_type
.fb_cmsize
= 256;
240 fb
->fb_type
.fb_size
= ramsize
;
241 printf(": cgfour/p4, %d x %d",
242 fb
->fb_type
.fb_width
, fb
->fb_type
.fb_height
);
247 struct eeprom
*eep
= (struct eeprom
*)eeprom_va
;
250 * Assume this is the console if there's no eeprom info
253 if (eep
== NULL
|| eep
->eeConsole
== EE_CONS_P4OPT
)
254 isconsole
= fb_is_console(0);
259 * We don't do any of the console handling here. Instead,
260 * we let the bwtwo driver pick up the overlay plane and
261 * use it instead. Rconsole should have better performance
262 * with the 1-bit depth.
263 * -- Jason R. Thorpe <thorpej@NetBSD.org>
267 * When the ROM has mapped in a cgfour display, the address
268 * maps only the video RAM, so in any case we have to map the
269 * registers ourselves. We only need the video RAM if we are
270 * going to print characters via rconsole.
274 /* XXX this is kind of a waste */
275 fb
->fb_pixels
= mapiodev(ca
->ca_ra
.ra_reg
,
276 PFOUR_COLOR_OFF_OVERLAY
, ramsize
);
280 /* Map the Brooktree. */
281 if (bus_space_map(oba
->oba_bustag
,
282 oba
->oba_paddr
+ PFOUR_COLOR_OFF_CMAP
,
283 sizeof(struct fbcontrol
),
284 BUS_SPACE_MAP_LINEAR
,
286 printf("%s: cannot map control registers\n", self
->dv_xname
);
289 sc
->sc_fbc
= (volatile struct fbcontrol
*)bh
;
291 /* grab initial (current) color map */
292 bt
= &sc
->sc_fbc
->fbc_dac
;
294 for (i
= 0; i
< 256 * 3 / 4; i
++)
295 ((char *)&sc
->sc_cmap
)[i
] = bt
->bt_cmap
>> 24;
299 #if 0 /* See above. */
301 printf(" (console)\n");
302 #if defined(RASTERCONSOLE) && 0 /* XXX been told it doesn't work well. */
310 * Even though we're not using rconsole, we'd still like
311 * to notice if we're the console framebuffer.
313 fb_attach(fb
, isconsole
);
318 cgfouropen(dev_t dev
, int flags
, int mode
, struct lwp
*l
)
320 int unit
= minor(dev
);
322 if (device_lookup(&cgfour_cd
, unit
) == NULL
)
328 cgfourioctl(dev_t dev
, u_long cmd
, void *data
, int flags
, struct lwp
*l
)
331 struct cgfour_softc
*sc
= device_lookup_private(&cgfour_cd
, minor(dev
));
338 *(struct fbtype
*)data
= sc
->sc_fb
.fb_type
;
342 fba
= (struct fbgattr
*)data
;
343 fba
->real_type
= sc
->sc_fb
.fb_type
.fb_type
;
344 fba
->owner
= 0; /* XXX ??? */
345 fba
->fbtype
= sc
->sc_fb
.fb_type
;
346 fba
->sattr
.flags
= 0;
347 fba
->sattr
.emu_type
= sc
->sc_fb
.fb_type
.fb_type
;
348 fba
->sattr
.dev_specific
[0] = -1;
349 fba
->emu_types
[0] = sc
->sc_fb
.fb_type
.fb_type
;
350 fba
->emu_types
[1] = -1;
354 #define p ((struct fbcmap *)data)
355 return (bt_getcmap(p
, &sc
->sc_cmap
, 256, 1));
358 /* copy to software map */
359 error
= bt_putcmap(p
, &sc
->sc_cmap
, 256, 1);
362 /* now blast them into the chip */
363 /* XXX should use retrace interrupt */
364 cgfourloadcmap(sc
, p
->index
, p
->count
);
369 *(int *)data
= cgfour_get_video(sc
);
373 cgfour_set_video(sc
, *(int *)data
);
385 * Return the address that would map the given device at the given
386 * offset, allowing for the given protection, or return -1 for error.
388 * the cg4 maps it's overlay plane for 128K, followed by the enable
389 * plane for 128K, followed by the colour plane (for as much colour
392 * As well, mapping at an offset of 0x04000000 causes the cg4 to map
393 * only it's colour plane, at 0.
396 cgfourmmap(dev_t dev
, off_t off
, int prot
)
398 struct cgfour_softc
*sc
= device_lookup_private(&cgfour_cd
, minor(dev
));
401 #define START_ENABLE (128*1024)
402 #define START_COLOR ((128*1024) + (128*1024))
403 #define COLOR_SIZE (sc->sc_fb.fb_type.fb_width * \
404 sc->sc_fb.fb_type.fb_height)
405 #define END_COLOR (START_COLOR + COLOR_SIZE)
406 #define NOOVERLAY (0x04000000)
413 else if ((u_int
)off
>= NOOVERLAY
) {
417 * X11 maps a huge chunk of the frame buffer; far more than
418 * there really is. We compensate by double-mapping the
419 * first page for as many other pages as it wants
421 while ((u_int
)off
>= COLOR_SIZE
)
422 off
-= COLOR_SIZE
; /* XXX thorpej ??? */
424 poff
= off
+ PFOUR_COLOR_OFF_COLOR
;
425 } else if ((u_int
)off
< START_ENABLE
) {
429 poff
= PFOUR_COLOR_OFF_OVERLAY
+ off
;
430 } else if ((u_int
)off
< START_COLOR
) {
434 poff
= (off
- START_ENABLE
) + PFOUR_COLOR_OFF_ENABLE
;
435 } else if ((u_int
)off
< sc
->sc_fb
.fb_type
.fb_size
) {
439 poff
= (off
- START_COLOR
) + PFOUR_COLOR_OFF_COLOR
;
443 return (bus_space_mmap(sc
->sc_bustag
,
445 prot
, BUS_SPACE_MAP_LINEAR
));
450 * Undo the effect of an FBIOSVIDEO that turns the video off.
453 cgfourunblank(struct device
*dev
)
456 cgfour_set_video(device_private(dev
), 1);
460 cgfour_get_video(struct cgfour_softc
*sc
)
463 return (fb_pfour_get_video(&sc
->sc_fb
));
467 cgfour_set_video(struct cgfour_softc
*sc
, int enable
)
470 fb_pfour_set_video(&sc
->sc_fb
, enable
);
474 * Load a subset of the current (new) colormap into the Brooktree DAC.
477 cgfourloadcmap(struct cgfour_softc
*sc
, int start
, int ncolors
)
479 volatile struct bt_regs
*bt
;
483 ip
= &sc
->sc_cmap
.cm_chip
[BT_D4M3(start
)]; /* start/4 * 3 */
484 count
= BT_D4M3(start
+ ncolors
- 1) - BT_D4M3(start
) + 3;
485 bt
= &sc
->sc_fbc
->fbc_dac
;
486 bt
->bt_addr
= BT_D4M4(start
) << 24;
487 while (--count
>= 0) {
489 /* hardware that makes one want to pound boards with hammers */
491 bt
->bt_cmap
= i
<< 8;
492 bt
->bt_cmap
= i
<< 16;
493 bt
->bt_cmap
= i
<< 24;