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