Home | History | Annotate | Line # | Download | only in dev
bw2.c revision 1.13
      1 /*	$NetBSD: bw2.c,v 1.13 1998/02/05 04:56:35 gwr Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1992, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This software was developed by the Computer Systems Engineering group
      8  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9  * contributed to Berkeley.
     10  *
     11  * All advertising materials mentioning features or use of this software
     12  * must display the following acknowledgement:
     13  *	This product includes software developed by the University of
     14  *	California, Lawrence Berkeley Laboratory.
     15  *
     16  * Redistribution and use in source and binary forms, with or without
     17  * modification, are permitted provided that the following conditions
     18  * are met:
     19  * 1. Redistributions of source code must retain the above copyright
     20  *    notice, this list of conditions and the following disclaimer.
     21  * 2. Redistributions in binary form must reproduce the above copyright
     22  *    notice, this list of conditions and the following disclaimer in the
     23  *    documentation and/or other materials provided with the distribution.
     24  * 3. All advertising materials mentioning features or use of this software
     25  *    must display the following acknowledgement:
     26  *	This product includes software developed by the University of
     27  *	California, Berkeley and its contributors.
     28  * 4. Neither the name of the University nor the names of its contributors
     29  *    may be used to endorse or promote products derived from this software
     30  *    without specific prior written permission.
     31  *
     32  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     33  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     34  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     35  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     36  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     40  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     41  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     42  * SUCH DAMAGE.
     43  *
     44  *	@(#)bwtwo.c	8.1 (Berkeley) 6/11/93
     45  */
     46 
     47 /*
     48  * black&white display (bw2) driver.
     49  *
     50  * Does not handle interrupts, even though they can occur.
     51  */
     52 
     53 #include <sys/param.h>
     54 #include <sys/systm.h>
     55 #include <sys/conf.h>
     56 #include <sys/device.h>
     57 #include <sys/ioctl.h>
     58 #include <sys/malloc.h>
     59 #include <sys/mman.h>
     60 #include <sys/proc.h>
     61 #include <sys/tty.h>
     62 
     63 #include <vm/vm.h>
     64 
     65 #include <machine/autoconf.h>
     66 #include <machine/cpu.h>
     67 #include <machine/fbio.h>
     68 #include <machine/idprom.h>
     69 #include <machine/pmap.h>
     70 
     71 #include <sun3/sun3/machdep.h>
     72 
     73 #include "fbvar.h"
     74 #include "bw2reg.h"
     75 
     76 cdev_decl(bw2);
     77 
     78 /* per-display variables */
     79 struct bw2_softc {
     80 	struct	device sc_dev;		/* base device */
     81 	struct	fbdevice sc_fb;		/* frame buffer device */
     82 	int 	sc_phys;		/* display RAM (phys addr) */
     83 	int 	sc_pixeloffset;		/* offset to framebuffer */
     84 	/* If using overlay plane of something, it is... */
     85 	int	sc_ovtype;		/* ... this type. */
     86 	int sc_video_on;
     87 };
     88 
     89 /* autoconfiguration driver */
     90 static void	bw2attach __P((struct device *, struct device *, void *));
     91 static int	bw2match __P((struct device *, struct cfdata *, void *));
     92 
     93 struct cfattach bwtwo_ca = {
     94 	sizeof(struct bw2_softc), bw2match, bw2attach
     95 };
     96 
     97 extern struct cfdriver bwtwo_cd;
     98 
     99 /* XXX we do not handle frame buffer interrupts */
    100 
    101 static int  bw2gvideo __P((struct fbdevice *, void *));
    102 static int	bw2svideo __P((struct fbdevice *, void *));
    103 
    104 static struct fbdriver bw2fbdriver = {
    105 	bw2open, bw2close, bw2mmap,
    106 	fb_noioctl,
    107 	bw2gvideo, bw2svideo,
    108 	fb_noioctl, fb_noioctl, };
    109 
    110 static int
    111 bw2match(parent, cf, args)
    112 	struct device *parent;
    113 	struct cfdata *cf;
    114 	void *args;
    115 {
    116 	struct confargs *ca = args;
    117 	int x;
    118 
    119 #if 0	/* XXX - Assume only one is in use anyway... */
    120 	/*
    121 	 * This driver only supports one unit because the
    122 	 * system enable register is used for blanking.
    123 	 */
    124 	if (cf->cf_unit != 0)
    125 		return (0);
    126 #endif
    127 
    128 	if (ca->ca_paddr == -1) {
    129 #ifdef	_SUN3X_
    130 		/* Demand an address locator on 3X. */
    131 		return (0);
    132 #else
    133 		if (cpu_machine_id == SUN3_MACH_50)
    134 			ca->ca_paddr = BW2_50_PADDR;
    135 		else
    136 			ca->ca_paddr = BW2_FB_PADDR;
    137 #endif
    138 	}
    139 
    140 	/* The peek returns -1 on bus error. */
    141 	x = bus_peek(ca->ca_bustype, ca->ca_paddr, 1);
    142 	return (x != -1);
    143 }
    144 
    145 /*
    146  * Attach a display.  We need to notice if it is the console, too.
    147  */
    148 static void
    149 bw2attach(parent, self, args)
    150 	struct device *parent, *self;
    151 	void *args;
    152 {
    153 	struct bw2_softc *sc = (struct bw2_softc *)self;
    154 	struct fbdevice *fb = &sc->sc_fb;
    155 	struct confargs *ca = args;
    156 	struct fbtype *fbt;
    157 #ifdef	_SUN3_
    158 	int tmp;
    159 #endif	/* SUN3 */
    160 
    161 	sc->sc_phys = ca->ca_paddr;
    162 
    163 	fbt = &fb->fb_fbtype;
    164 	fbt->fb_type = FBTYPE_SUN2BW;
    165 	fbt->fb_width = 1152;		/* default - see below */
    166 	fbt->fb_height = 900;		/* default - see below */
    167 	fbt->fb_depth = 1;
    168 	fbt->fb_cmsize = 0;
    169 	fbt->fb_size = BW2_FBSIZE;	/* default - see below */
    170 	fb->fb_driver = &bw2fbdriver;
    171 	fb->fb_private = sc;
    172 	fb->fb_name = sc->sc_dev.dv_xname;
    173 
    174 #ifdef	_SUN3_
    175 	switch (cpu_machine_id) {
    176 	case SUN3_MACH_60:
    177 		/*
    178 		 * Only the model 60 can have hi-res.
    179 		 * XXX - Use PROM screen size values?
    180 		 */
    181 		tmp = bus_peek(BUS_OBMEM, BW2_CR_PADDR, 1);
    182 		if ((tmp != -1) && (tmp & 0x80) == 0)
    183 			goto high_res;
    184 		break;
    185 
    186 	case SUN3_MACH_260:
    187 		/* The Sun3/260 is ALWAYS high-resolution! */
    188 	high_res:
    189 		fbt->fb_width = 1600;
    190 		fbt->fb_height = 1280;
    191 		fbt->fb_size = BW2_FBSIZE_HIRES;
    192 		break;
    193 	}
    194 #endif	/* SUN3 */
    195 
    196 	printf(" (%dx%d)\n", fbt->fb_width, fbt->fb_height);
    197 	fb_attach(fb, 1);
    198 }
    199 
    200 int
    201 bw2open(dev, flags, mode, p)
    202 	dev_t dev;
    203 	int flags, mode;
    204 	struct proc *p;
    205 {
    206 	int unit = minor(dev);
    207 
    208 	if (unit >= bwtwo_cd.cd_ndevs || bwtwo_cd.cd_devs[unit] == NULL)
    209 		return (ENXIO);
    210 	return (0);
    211 }
    212 
    213 int
    214 bw2close(dev, flags, mode, p)
    215 	dev_t dev;
    216 	int flags, mode;
    217 	struct proc *p;
    218 {
    219 
    220 	return (0);
    221 }
    222 
    223 int
    224 bw2ioctl(dev, cmd, data, flags, p)
    225 	dev_t dev;
    226 	u_long cmd;
    227 	caddr_t data;
    228 	int flags;
    229 	struct proc *p;
    230 {
    231 	struct bw2_softc *sc = bwtwo_cd.cd_devs[minor(dev)];
    232 
    233 	return (fbioctlfb(&sc->sc_fb, cmd, data));
    234 }
    235 
    236 /*
    237  * Return the address that would map the given device at the given
    238  * offset, allowing for the given protection, or return -1 for error.
    239  */
    240 int
    241 bw2mmap(dev, off, prot)
    242 	dev_t dev;
    243 	int off, prot;
    244 {
    245 	struct bw2_softc *sc = bwtwo_cd.cd_devs[minor(dev)];
    246 
    247 	if (off & PGOFSET)
    248 		return (-1);
    249 	if ((unsigned)off >= sc->sc_fb.fb_fbtype.fb_size)
    250 		return (-1);
    251 	/*
    252 	 * I turned on PMAP_NC here to disable the cache as I was
    253 	 * getting horribly broken behaviour with it on.
    254 	 */
    255 	return ((sc->sc_phys + off) | PMAP_NC);
    256 }
    257 
    258 /* FBIOGVIDEO: */
    259 static int bw2gvideo(fb, data)
    260 	struct fbdevice *fb;
    261 	void *data;
    262 {
    263 	struct bw2_softc *sc = fb->fb_private;
    264 	int *on = data;
    265 
    266 	*on = sc->sc_video_on;
    267 	return (0);
    268 }
    269 
    270 /* FBIOSVIDEO */
    271 static int bw2svideo(fb, data)
    272 	struct fbdevice *fb;
    273 	void *data;
    274 {
    275 	struct bw2_softc *sc = fb->fb_private;
    276 	int *on = data;
    277 
    278 	if (sc->sc_video_on == *on)
    279 		return (0);
    280 	sc->sc_video_on = *on;
    281 
    282 	/* XXX: P4 support... */
    283 	enable_video(sc->sc_video_on);
    284 
    285 	return(0);
    286 }
    287