Home | History | Annotate | Line # | Download | only in dev
bw2.c revision 1.1
      1 /*	$NetBSD: bw2.c,v 1.1 1995/03/10 01:50:53 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/device.h>
     55 #include <sys/ioctl.h>
     56 #include <sys/malloc.h>
     57 #include <sys/mman.h>
     58 #include <sys/tty.h>
     59 
     60 #include <vm/vm.h>
     61 
     62 #include <machine/fbio.h>
     63 #include <machine/autoconf.h>
     64 #include <machine/pmap.h>
     65 #include <machine/control.h>
     66 #include <machine/cpu.h>
     67 #include <machine/eeprom.h>
     68 
     69 #include "fbvar.h"
     70 #include "bw2reg.h"
     71 
     72 extern unsigned char cpu_machine_id;
     73 
     74 /* per-display variables */
     75 struct bw2_softc {
     76 	struct	device sc_dev;		/* base device */
     77 	struct	fbdevice sc_fb;		/* frame buffer device */
     78 	int 	sc_phys;		/* display RAM (phys addr) */
     79 };
     80 
     81 /* autoconfiguration driver */
     82 static void	bw2attach __P((struct device *, struct device *, void *));
     83 static int	bw2match __P((struct device *, void *, void *));
     84 
     85 struct cfdriver bwtwocd = {
     86 	NULL, "bwtwo", bw2match, bw2attach,
     87 	DV_DULL, sizeof(struct bw2_softc) };
     88 
     89 /* XXX we do not handle frame buffer interrupts */
     90 
     91 /* frame buffer generic driver */
     92 int bw2open(), bw2close(), bw2ioctl(), bw2map();
     93 
     94 static int  bw2gvideo __P((struct fbdevice *, int *));
     95 static int	bw2svideo __P((struct fbdevice *, int *));
     96 
     97 static struct fbdriver bw2fbdriver = {
     98 	bw2open, bw2close, bw2map,
     99 	enoioctl, /* gattr */
    100 	bw2gvideo, bw2svideo,
    101 	enoioctl, enoioctl };
    102 
    103 static int
    104 bw2match(parent, vcf, args)
    105 	struct device *parent;
    106 	void *vcf, *args;
    107 {
    108 	struct cfdata *cf = vcf;
    109 	struct confargs *ca = args;
    110 	int x;
    111 
    112 	/*
    113 	 * This driver only supports one unit because the
    114 	 * system enable register is used for blanking.
    115 	 */
    116 	if (cf->cf_unit != 0)
    117 		return (0);
    118 
    119 	if (ca->ca_paddr == -1) {
    120 		if (cpu_machine_id == SUN3_MACH_50)
    121 			ca->ca_paddr = BW2_50_PADDR;
    122 		else
    123 			ca->ca_paddr = BW2_FB_PADDR;
    124 	}
    125 
    126 	/* The peek returns -1 on bus error. */
    127 	x = bus_peek(ca->ca_bustype, ca->ca_paddr, 1);
    128 	return (x != -1);
    129 }
    130 
    131 /*
    132  * Attach a display.  We need to notice if it is the console, too.
    133  */
    134 static void
    135 bw2attach(parent, self, args)
    136 	struct device *parent, *self;
    137 	void *args;
    138 {
    139 	struct bw2_softc *sc = (struct bw2_softc *)self;
    140 	struct fbdevice *fb = &sc->sc_fb;
    141 	struct confargs *ca = args;
    142 	struct fbtype *fbt;
    143 	int ramsize;
    144 
    145 	sc->sc_phys = ca->ca_paddr;
    146 
    147 	fb->fb_driver = &bw2fbdriver;
    148 	fb->fb_private = sc;
    149 	fb->fb_name = sc->sc_dev.dv_xname;
    150 
    151 	fbt = &fb->fb_fbtype;
    152 	fbt->fb_type = FBTYPE_SUN2BW;
    153 	fbt->fb_depth = 1;
    154 	fbt->fb_cmsize = 0;
    155 
    156 	fbt->fb_width = 1152;
    157 	fbt->fb_height = 900;
    158 	fbt->fb_size = BW2_FBSIZE;
    159 
    160 	/*
    161 	 * Only the model 60 can have hi-res.
    162 	 * XXX - Use PROM screen size values?
    163 	 */
    164 	if (cpu_machine_id == SUN3_MACH_60) {
    165 		int tmp;
    166 	    tmp = bus_peek(BUS_OBMEM, BW2_CR_PADDR, 1);
    167 		if ((tmp != -1) && (tmp & 0x80) == 0) {
    168 			fbt->fb_width = 1600;
    169 			fbt->fb_height = 1280;
    170 			fbt->fb_size = BW2_FBSIZE_HIRES;
    171 		}
    172 	}
    173 
    174 	printf(" (%dx%d)\n", fbt->fb_width, fbt->fb_height);
    175 
    176 	if (ee_console == EE_CONS_BW) {
    177 		fb_attach(fb);
    178 	}
    179 }
    180 
    181 int
    182 bw2open(dev, flags, mode, p)
    183 	dev_t dev;
    184 	int flags, mode;
    185 	struct proc *p;
    186 {
    187 	int unit = minor(dev);
    188 
    189 	if (unit >= bwtwocd.cd_ndevs || bwtwocd.cd_devs[unit] == NULL)
    190 		return (ENXIO);
    191 	return (0);
    192 }
    193 
    194 int
    195 bw2close(dev, flags, mode, p)
    196 	dev_t dev;
    197 	int flags, mode;
    198 	struct proc *p;
    199 {
    200 
    201 	return (0);
    202 }
    203 
    204 int
    205 bw2ioctl(dev, cmd, data, flags, p)
    206 	dev_t dev;
    207 	u_long cmd;
    208 	caddr_t data;
    209 	int flags;
    210 	struct proc *p;
    211 {
    212 	struct bw2_softc *sc = bwtwocd.cd_devs[minor(dev)];
    213 
    214 	return (fbioctlfb(&sc->sc_fb, cmd, data));
    215 }
    216 
    217 /*
    218  * Return the address that would map the given device at the given
    219  * offset, allowing for the given protection, or return -1 for error.
    220  */
    221 int
    222 bw2map(dev, off, prot)
    223 	dev_t dev;
    224 	int off, prot;
    225 {
    226 	struct bw2_softc *sc = bwtwocd.cd_devs[minor(dev)];
    227 
    228 	if (off & PGOFSET)
    229 		return (-1);
    230 	if ((unsigned)off >= sc->sc_fb.fb_fbtype.fb_size)
    231 		return (-1);
    232 	/*
    233 	 * I turned on PMAP_NC here to disable the cache as I was
    234 	 * getting horribly broken behaviour with it on.
    235 	 */
    236 	return ((sc->sc_phys + off) | PMAP_NC);
    237 }
    238 
    239 /* FBIOGVIDEO: */
    240 static int bw2gvideo(fb, on)
    241 	struct fbdevice *fb;
    242 	int *on;
    243 {
    244 	int s, ena;
    245 
    246 	s = splhigh();
    247 	ena = get_control_byte((char *)SYSTEM_ENAB);
    248 	splx(s);
    249 
    250 	*on = (ena & SYSTEM_ENAB_VIDEO) ? 1 : 0;
    251 	return (0);
    252 }
    253 
    254 /* FBIOSVIDEO */
    255 static int bw2svideo(fb, on)
    256 	struct fbdevice *fb;
    257 	int *on;
    258 {
    259 	int s, ena;
    260 
    261 	s = splhigh();
    262 	ena = get_control_byte((char *)SYSTEM_ENAB);
    263 
    264 	if (*on) ena |= SYSTEM_ENAB_VIDEO;
    265 	else ena &= ~SYSTEM_ENAB_VIDEO;
    266 
    267 	set_control_byte((char *)SYSTEM_ENAB, ena);
    268 	splx(s);
    269 
    270 	return(0);
    271 }
    272