Home | History | Annotate | Line # | Download | only in dev
bwtwo_obio.c revision 1.1
      1 /*	$NetBSD: bwtwo_obio.c,v 1.1 1999/08/10 04:56:30 christos Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     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.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * Copyright (c) 1992, 1993
     41  *	The Regents of the University of California.  All rights reserved.
     42  *
     43  * This software was developed by the Computer Systems Engineering group
     44  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     45  * contributed to Berkeley.
     46  *
     47  * All advertising materials mentioning features or use of this software
     48  * must display the following acknowledgement:
     49  *	This product includes software developed by the University of
     50  *	California, Lawrence Berkeley Laboratory.
     51  *
     52  * Redistribution and use in source and binary forms, with or without
     53  * modification, are permitted provided that the following conditions
     54  * are met:
     55  * 1. Redistributions of source code must retain the above copyright
     56  *    notice, this list of conditions and the following disclaimer.
     57  * 2. Redistributions in binary form must reproduce the above copyright
     58  *    notice, this list of conditions and the following disclaimer in the
     59  *    documentation and/or other materials provided with the distribution.
     60  * 3. All advertising materials mentioning features or use of this software
     61  *    must display the following acknowledgement:
     62  *	This product includes software developed by the University of
     63  *	California, Berkeley and its contributors.
     64  * 4. Neither the name of the University nor the names of its contributors
     65  *    may be used to endorse or promote products derived from this software
     66  *    without specific prior written permission.
     67  *
     68  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     69  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     70  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     71  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     72  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     73  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     74  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     75  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     76  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     77  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     78  * SUCH DAMAGE.
     79  *
     80  *	@(#)bwtwo.c	8.1 (Berkeley) 6/11/93
     81  */
     82 
     83 /*
     84  * black&white display (bwtwo) driver.
     85  *
     86  * Does not handle interrupts, even though they can occur.
     87  *
     88  * P4 and overlay plane support by Jason R. Thorpe <thorpej (at) NetBSD.ORG>.
     89  * Overlay plane handling hints and ideas provided by Brad Spencer.
     90  */
     91 
     92 #include <sys/param.h>
     93 #include <sys/systm.h>
     94 #include <sys/device.h>
     95 #include <sys/ioctl.h>
     96 #include <sys/malloc.h>
     97 #include <sys/mman.h>
     98 #include <sys/tty.h>
     99 #include <sys/conf.h>
    100 
    101 #include <vm/vm.h>
    102 
    103 #include <machine/fbio.h>
    104 #include <machine/autoconf.h>
    105 #include <machine/pmap.h>
    106 #include <machine/fbvar.h>
    107 #include <machine/eeprom.h>
    108 #include <machine/ctlreg.h>
    109 #include <machine/conf.h>
    110 #include <sparc/sparc/asm.h>
    111 
    112 #include <sparc/dev/btreg.h>
    113 #include <sparc/dev/bwtworeg.h>
    114 #include <sparc/dev/bwtwovar.h>
    115 #include <sparc/dev/pfourreg.h>
    116 
    117 /* autoconfiguration driver */
    118 static void	bwtwoattach_obio __P((struct device *, struct device *, void *));
    119 static int	bwtwomatch_obio __P((struct device *, struct cfdata *, void *));
    120 
    121 
    122 struct cfattach bwtwo_obio_ca = {
    123 	sizeof(struct bwtwo_softc), bwtwomatch_obio, bwtwoattach_obio
    124 };
    125 
    126 static int	bwtwo_get_video_sun4  __P((struct bwtwo_softc *));
    127 static void	bwtwo_set_video_sun4 __P((struct bwtwo_softc *, int));
    128 
    129 extern int fbnode;
    130 extern struct tty *fbconstty;
    131 
    132 static int
    133 bwtwomatch_obio(parent, cf, aux)
    134 	struct device *parent;
    135 	struct cfdata *cf;
    136 	void *aux;
    137 {
    138 	union obio_attach_args *uoba = aux;
    139 	struct obio4_attach_args *oba;
    140 
    141 	if (uoba->uoba_isobio4 == 0)
    142 		return (0);
    143 
    144 	oba = &uoba->uoba_oba4;
    145 	return (bus_space_probe(oba->oba_bustag, 0, oba->oba_paddr,
    146 				4,	/* probe size */
    147 				0,	/* offset */
    148 				0,	/* flags */
    149 				bwtwo_pfour_probe, cf));
    150 }
    151 
    152 static void
    153 bwtwoattach_obio(parent, self, uax)
    154 	struct device *parent, *self;
    155 	void *uax;
    156 {
    157 	struct bwtwo_softc *sc = (struct bwtwo_softc *)self;
    158 	union obio_attach_args *uoba = uax;
    159 	struct obio4_attach_args *oba;
    160 	struct fbdevice *fb = &sc->sc_fb;
    161 	struct eeprom *eep = (struct eeprom *)eeprom_va;
    162 	bus_space_handle_t bh;
    163 	int constype, isconsole;
    164 	char *name;
    165 
    166 	oba = &uoba->uoba_oba4;
    167 
    168 	/* Remember cookies for bwtwo_mmap() */
    169 	sc->sc_bustag = oba->oba_bustag;
    170 	sc->sc_btype = (bus_type_t)0;
    171 	sc->sc_paddr = (bus_addr_t)oba->oba_paddr;
    172 
    173 	fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags;
    174 	fb->fb_type.fb_depth = 1;
    175 	fb_setsize_eeprom(fb, fb->fb_type.fb_depth, 1152, 900);
    176 
    177 	constype = (fb->fb_flags & FB_PFOUR) ? EE_CONS_P4OPT : EE_CONS_BW;
    178 	if (eep == NULL || eep->eeConsole == constype)
    179 		isconsole = (fbconstty != NULL);
    180 	else
    181 		isconsole = 0;
    182 
    183 	if (fb->fb_flags & FB_PFOUR) {
    184 		/*
    185 		 * Map the pfour control register.
    186 		 * Set pixel offset to appropriate overlay plane.
    187 		 */
    188 		name = "bwtwo/p4";
    189 
    190 		if (obio_bus_map(oba->oba_bustag,
    191 				 oba->oba_paddr,
    192 				 0,
    193 				 sizeof(u_int32_t),
    194 				 BUS_SPACE_MAP_LINEAR,
    195 				 0, &bh) != 0) {
    196 			printf("%s: cannot map pfour register\n",
    197 				self->dv_xname);
    198 			return;
    199 		}
    200 		fb->fb_pfour = (u_int32_t *)bh;
    201 		sc->sc_reg = NULL;
    202 
    203 		/*
    204 		 * Notice if this is an overlay plane on a color
    205 		 * framebuffer.  Note that PFOUR_COLOR_OFF_OVERLAY
    206 		 * is the same as PFOUR_BW_OFF, but we use the
    207 		 * different names anyway.
    208 		 */
    209 		switch (PFOUR_ID(*fb->fb_pfour)) {
    210 		case PFOUR_ID_COLOR8P1:
    211 			sc->sc_ovtype = BWO_CGFOUR;
    212 			sc->sc_pixeloffset = PFOUR_COLOR_OFF_OVERLAY;
    213 			break;
    214 
    215 		case PFOUR_ID_COLOR24:
    216 			sc->sc_ovtype = BWO_CGEIGHT;
    217 			sc->sc_pixeloffset = PFOUR_COLOR_OFF_OVERLAY;
    218 			break;
    219 
    220 		default:
    221 			sc->sc_ovtype = BWO_NONE;
    222 			sc->sc_pixeloffset = PFOUR_BW_OFF;
    223 			break;
    224 		}
    225 
    226 	} else {
    227 		/* A plain bwtwo */
    228 		if (obio_bus_map(oba->oba_bustag,
    229 				 oba->oba_paddr,
    230 				 BWREG_REG,
    231 				 sizeof(struct fbcontrol),
    232 				 BUS_SPACE_MAP_LINEAR,
    233 				 0, &bh) != 0) {
    234 			printf("%s: cannot map control registers\n",
    235 				self->dv_xname);
    236 			return;
    237 		}
    238 		sc->sc_reg = (struct fbcontrol *)bh;
    239 		fb->fb_pfour = NULL;
    240 
    241 		name = "bwtwo";
    242 		sc->sc_pixeloffset = BWREG_MEM;
    243 	}
    244 	sc->sc_get_video = bwtwo_get_video_sun4;
    245 	sc->sc_set_video = bwtwo_set_video_sun4;
    246 
    247 	if (isconsole) {
    248 		int ramsize = fb->fb_type.fb_height * fb->fb_linebytes;
    249 		if (obio_bus_map(oba->oba_bustag, oba->oba_paddr,
    250 				 sc->sc_pixeloffset,
    251 				 ramsize,
    252 				 BUS_SPACE_MAP_LINEAR,
    253 				 0, &bh) != 0) {
    254 			printf("%s: cannot map pixels\n", self->dv_xname);
    255 			return;
    256 		}
    257 		sc->sc_fb.fb_pixels = (char *)bh;
    258 	}
    259 
    260 	bwtwoattach(sc, name, isconsole, 1);
    261 }
    262 
    263 static void
    264 bwtwo_set_video_sun4(sc, enable)
    265 	struct bwtwo_softc *sc;
    266 	int enable;
    267 {
    268 
    269 	if (sc->sc_fb.fb_flags & FB_PFOUR) {
    270 		/*
    271 		 * This handles the overlay plane case, too.
    272 		 */
    273 		fb_pfour_set_video(&sc->sc_fb, enable);
    274 		return;
    275 	}
    276 	if (enable)
    277 		stba(AC_SYSENABLE, ASI_CONTROL,
    278 		     lduba(AC_SYSENABLE, ASI_CONTROL) | SYSEN_VIDEO);
    279 	else
    280 		stba(AC_SYSENABLE, ASI_CONTROL,
    281 		     lduba(AC_SYSENABLE, ASI_CONTROL) & ~SYSEN_VIDEO);
    282 
    283 	return;
    284 }
    285 
    286 static int
    287 bwtwo_get_video_sun4(sc)
    288 	struct bwtwo_softc *sc;
    289 {
    290 
    291 	if (sc->sc_fb.fb_flags & FB_PFOUR) {
    292 		/*
    293 		 * This handles the overlay plane case, too.
    294 		 */
    295 		return (fb_pfour_get_video(&sc->sc_fb));
    296 	} else
    297 		return ((lduba(AC_SYSENABLE, ASI_CONTROL) & SYSEN_VIDEO) != 0);
    298 }
    299