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