Home | History | Annotate | Line # | Download | only in sun
bwtwo.c revision 1.2
      1 /*	$NetBSD: bwtwo.c,v 1.2 2000/08/20 19:58:53 pk 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 <machine/autoconf.h>
    102 #include <machine/eeprom.h>
    103 #include <machine/conf.h>
    104 
    105 #include <dev/sun/fbio.h>
    106 #include <dev/sun/fbvar.h>
    107 #include <dev/sun/btreg.h>
    108 #include <dev/sun/bwtworeg.h>
    109 #include <dev/sun/bwtwovar.h>
    110 #include <dev/sun/pfourreg.h>
    111 
    112 /* cdevsw prototypes */
    113 cdev_decl(bwtwo);
    114 
    115 extern struct cfdriver bwtwo_cd;
    116 
    117 /* XXX we do not handle frame buffer interrupts (do not know how) */
    118 static void	bwtwounblank(struct device *);
    119 
    120 /* frame buffer generic driver */
    121 static struct fbdriver bwtwofbdriver = {
    122 	bwtwounblank, bwtwoopen, bwtwoclose, bwtwoioctl, bwtwopoll, bwtwommap
    123 };
    124 
    125 int
    126 bwtwo_pfour_probe(vaddr, arg)
    127 	void *vaddr;
    128 	void *arg;
    129 {
    130 	struct cfdata *cf = arg;
    131 
    132 	switch (fb_pfour_id(vaddr)) {
    133 	case PFOUR_ID_BW:
    134 	case PFOUR_ID_COLOR8P1:		/* bwtwo in ... */
    135 	case PFOUR_ID_COLOR24:		/* ...overlay plane */
    136 		/* This is wrong; should be done in bwtwo_attach() */
    137 		cf->cf_flags |= FB_PFOUR;
    138 		/* FALLTHROUGH */
    139 	case PFOUR_NOTPFOUR:
    140 		return (1);
    141 	}
    142 	return (0);
    143 }
    144 
    145 void
    146 bwtwoattach(sc, name, isconsole)
    147 	struct	bwtwo_softc *sc;
    148 	char	*name;
    149 	int	isconsole;
    150 {
    151 	struct fbdevice *fb = &sc->sc_fb;
    152 
    153 	/* Fill in the remaining fbdevice values */
    154 	fb->fb_driver = &bwtwofbdriver;
    155 	fb->fb_device = &sc->sc_dev;
    156 	fb->fb_type.fb_type = FBTYPE_SUN2BW;
    157 	fb->fb_type.fb_cmsize = 0;
    158 	fb->fb_type.fb_size = fb->fb_type.fb_height * fb->fb_linebytes;
    159 	printf(": %s, %d x %d", name,
    160 	       fb->fb_type.fb_width, fb->fb_type.fb_height);
    161 
    162 	/* Insure video is enabled */
    163 	sc->sc_set_video(sc, 1);
    164 
    165 	if (isconsole) {
    166 		printf(" (console)\n");
    167 #ifdef RASTERCONSOLE
    168 		/*
    169 		 * XXX rcons doesn't seem to work properly on the overlay
    170 		 * XXX plane.  This is a temporary kludge until someone
    171 		 * XXX fixes it.
    172 		 */
    173 		if ((fb->fb_flags & FB_PFOUR) == 0 ||
    174 		    (sc->sc_ovtype == BWO_NONE))
    175 			fbrcons_init(fb);
    176 #endif
    177 	} else
    178 		printf("\n");
    179 
    180 	if ((fb->fb_flags & FB_PFOUR) && (sc->sc_ovtype != BWO_NONE)) {
    181 		char *ovnam;
    182 
    183 		switch (sc->sc_ovtype) {
    184 		case BWO_CGFOUR:
    185 			ovnam = "cgfour";
    186 			break;
    187 
    188 		case BWO_CGEIGHT:
    189 			ovnam = "cgeight";
    190 			break;
    191 
    192 		default:
    193 			ovnam = "unknown";
    194 			break;
    195 		}
    196 		printf("%s: %s overlay plane\n", sc->sc_dev.dv_xname, ovnam);
    197 	}
    198 
    199 	/*
    200 	 * If we're on an overlay plane of a color framebuffer,
    201 	 * then we don't force the issue in fb_attach() because
    202 	 * we'd like the color framebuffer to actually be the
    203 	 * "console framebuffer".  We're only around to speed
    204 	 * up rconsole.
    205 	 */
    206 	if ((fb->fb_flags & FB_PFOUR) && (sc->sc_ovtype != BWO_NONE ))
    207 		fb_attach(fb, 0);
    208 	else
    209 		fb_attach(fb, isconsole);
    210 }
    211 
    212 int
    213 bwtwoopen(dev, flags, mode, p)
    214 	dev_t dev;
    215 	int flags, mode;
    216 	struct proc *p;
    217 {
    218 	int unit = minor(dev);
    219 
    220 	if (unit >= bwtwo_cd.cd_ndevs || bwtwo_cd.cd_devs[unit] == NULL)
    221 		return (ENXIO);
    222 
    223 	return (0);
    224 }
    225 
    226 int
    227 bwtwoclose(dev, flags, mode, p)
    228 	dev_t dev;
    229 	int flags, mode;
    230 	struct proc *p;
    231 {
    232 
    233 	return (0);
    234 }
    235 
    236 int
    237 bwtwoioctl(dev, cmd, data, flags, p)
    238 	dev_t dev;
    239 	u_long cmd;
    240 	caddr_t data;
    241 	int flags;
    242 	struct proc *p;
    243 {
    244 	struct bwtwo_softc *sc = bwtwo_cd.cd_devs[minor(dev)];
    245 
    246 	switch (cmd) {
    247 
    248 	case FBIOGTYPE:
    249 		*(struct fbtype *)data = sc->sc_fb.fb_type;
    250 		break;
    251 
    252 	case FBIOGVIDEO:
    253 		*(int *)data = sc->sc_get_video(sc);
    254 		break;
    255 
    256 	case FBIOSVIDEO:
    257 		sc->sc_set_video(sc, (*(int *)data));
    258 		break;
    259 
    260 	default:
    261 		return (ENOTTY);
    262 	}
    263 	return (0);
    264 }
    265 
    266 static void
    267 bwtwounblank(dev)
    268 	struct device *dev;
    269 {
    270 	struct bwtwo_softc *sc = (struct bwtwo_softc *)dev;
    271 
    272 	sc->sc_set_video(sc, 1);
    273 }
    274 
    275 int
    276 bwtwopoll(dev, events, p)
    277 	dev_t dev;
    278 	int events;
    279 	struct proc *p;
    280 {
    281 
    282 	return (seltrue(dev, events, p));
    283 }
    284 
    285 /*
    286  * Return the address that would map the given device at the given
    287  * offset, allowing for the given protection, or return -1 for error.
    288  */
    289 paddr_t
    290 bwtwommap(dev, off, prot)
    291 	dev_t dev;
    292 	off_t off;
    293 	int prot;
    294 {
    295 	struct bwtwo_softc *sc = bwtwo_cd.cd_devs[minor(dev)];
    296 	bus_space_handle_t bh;
    297 
    298 	if (off & PGOFSET)
    299 		panic("bwtwommap");
    300 
    301 	if (off >= sc->sc_fb.fb_type.fb_size)
    302 		return (-1);
    303 
    304 	if (bus_space_mmap(sc->sc_bustag,
    305 			   sc->sc_btype,
    306 			   sc->sc_paddr + sc->sc_pixeloffset + off,
    307 			   BUS_SPACE_MAP_LINEAR, &bh))
    308 		return (-1);
    309 
    310 	return ((paddr_t)bh);
    311 }
    312