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