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