bw2.c revision 1.24 1 /* $NetBSD: bw2.c,v 1.24 2003/07/15 03:36:14 lukem 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/cdefs.h>
54 __KERNEL_RCSID(0, "$NetBSD: bw2.c,v 1.24 2003/07/15 03:36:14 lukem Exp $");
55
56 #include <sys/param.h>
57 #include <sys/systm.h>
58 #include <sys/conf.h>
59 #include <sys/device.h>
60 #include <sys/ioctl.h>
61 #include <sys/malloc.h>
62 #include <sys/mman.h>
63 #include <sys/proc.h>
64 #include <sys/tty.h>
65
66 #include <uvm/uvm_extern.h>
67
68 #include <machine/autoconf.h>
69 #include <machine/cpu.h>
70 #include <dev/sun/fbio.h>
71 #include <machine/idprom.h>
72 #include <machine/pmap.h>
73
74 #include <sun3/dev/fbvar.h>
75 #include <sun3/dev/bw2reg.h>
76 #include <sun3/dev/p4reg.h>
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 /* If using overlay plane of something, it is... */
84 int sc_ovtype; /* ... this type. */
85 int sc_video_on;
86 };
87
88 /* autoconfiguration driver */
89 static void bw2attach __P((struct device *, struct device *, void *));
90 static int bw2match __P((struct device *, struct cfdata *, void *));
91
92 CFATTACH_DECL(bwtwo, sizeof(struct bw2_softc),
93 bw2match, bw2attach, NULL, NULL);
94
95 extern struct cfdriver bwtwo_cd;
96
97 dev_type_open(bw2open);
98 dev_type_ioctl(bw2ioctl);
99 dev_type_mmap(bw2mmap);
100
101 const struct cdevsw bwtwo_cdevsw = {
102 bw2open, nullclose, noread, nowrite, bw2ioctl,
103 nostop, notty, nopoll, bw2mmap, nokqfilter,
104 };
105
106 /* XXX we do not handle frame buffer interrupts */
107
108 static int bw2gvideo __P((struct fbdevice *, void *));
109 static int bw2svideo __P((struct fbdevice *, void *));
110
111 static struct fbdriver bw2fbdriver = {
112 bw2open, nullclose, bw2mmap, nokqfilter,
113 fb_noioctl,
114 bw2gvideo, bw2svideo,
115 fb_noioctl, fb_noioctl, };
116
117 static int
118 bw2match(parent, cf, args)
119 struct device *parent;
120 struct cfdata *cf;
121 void *args;
122 {
123 struct confargs *ca = args;
124 int mid, p4id, peekval;
125 void *p4reg;
126
127 /* No default address support. */
128 if (ca->ca_paddr == -1)
129 return (0);
130
131 /*
132 * Slight hack here: The low four bits of the
133 * config flags, if set, restrict the match to
134 * that machine "implementation" only.
135 */
136 mid = cf->cf_flags & IDM_IMPL_MASK;
137 if (mid && (mid != (cpu_machine_id & IDM_IMPL_MASK)))
138 return (0);
139
140 /*
141 * Make sure something is there, and if so,
142 * see if it looks like a P4 register.
143 */
144 p4reg = bus_tmapin(ca->ca_bustype, ca->ca_paddr);
145 peekval = peek_long(p4reg);
146 p4id = (peekval == -1) ?
147 P4_NOTFOUND : fb_pfour_id(p4reg);
148 bus_tmapout(p4reg);
149 if (peekval == -1)
150 return (0);
151
152 /*
153 * The config flag 0x40 if set means we should match
154 * only on a CG? overlay plane. We can use only the
155 * CG4 and CG8, which both have a P4 register.
156 */
157 if (cf->cf_flags & 0x40) {
158 switch (p4id) {
159 case P4_ID_COLOR8P1:
160 case P4_ID_COLOR24:
161 return (1);
162 case P4_NOTFOUND:
163 default:
164 return (0);
165 }
166 }
167
168 /*
169 * OK, we are expecting a plain old BW2, and
170 * there may or may not be a P4 register.
171 */
172 switch (p4id) {
173 case P4_ID_BW:
174 case P4_NOTFOUND:
175 return (1);
176 default:
177 #ifdef DEBUG
178 printf("bwtwo at 0x%x match p4id=0x%x fails\n",
179 ca->ca_paddr, p4id & 0xFF);
180 #endif
181 break;
182 }
183
184 return (0);
185 }
186
187 /*
188 * Attach a display. We need to notice if it is the console, too.
189 */
190 static void
191 bw2attach(parent, self, args)
192 struct device *parent, *self;
193 void *args;
194 {
195 struct bw2_softc *sc = (struct bw2_softc *)self;
196 struct fbdevice *fb = &sc->sc_fb;
197 struct confargs *ca = args;
198 struct fbtype *fbt;
199 void *p4reg;
200 int p4id, tmp;
201 int pixeloffset; /* offset to framebuffer */
202
203 fbt = &fb->fb_fbtype;
204 fbt->fb_type = FBTYPE_SUN2BW;
205 fbt->fb_width = 1152; /* default - see below */
206 fbt->fb_height = 900; /* default - see below */
207 fbt->fb_depth = 1;
208 fbt->fb_cmsize = 0;
209 fbt->fb_size = BW2_FBSIZE; /* default - see below */
210 fb->fb_driver = &bw2fbdriver;
211 fb->fb_private = sc;
212 fb->fb_name = sc->sc_dev.dv_xname;
213 fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags;
214
215 /* Set up default pixel offset. May be changed below. */
216 pixeloffset = 0;
217
218 /* Does it have a P4 register? */
219 p4reg = bus_mapin(ca->ca_bustype, ca->ca_paddr, 4);
220 p4id = fb_pfour_id(p4reg);
221 if (p4id != P4_NOTFOUND)
222 fb->fb_pfour = p4reg;
223 else
224 bus_mapout(p4reg, 4);
225
226 switch (p4id) {
227 case P4_NOTFOUND:
228 pixeloffset = 0;
229 break;
230
231 case P4_ID_BW:
232 pixeloffset = P4_BW_OFF;
233 break;
234
235 default:
236 printf("%s: bad p4id=0x%x\n", fb->fb_name, p4id);
237 /* Must be some kinda color... */
238 /* fall through */
239 case P4_ID_COLOR8P1:
240 case P4_ID_COLOR24:
241 sc->sc_ovtype = p4id;
242 pixeloffset = P4_COLOR_OFF_OVERLAY;
243 break;
244 }
245 sc->sc_phys = ca->ca_paddr + pixeloffset;
246
247 /*
248 * Determine width and height as follows:
249 * If it has a P4 register, use that;
250 * else if unit==0, use the EEPROM size,
251 * else make our best guess.
252 */
253 if (fb->fb_pfour)
254 fb_pfour_setsize(fb);
255 else if (sc->sc_dev.dv_unit == 0)
256 fb_eeprom_setsize(fb);
257 else {
258 /* Guess based on machine ID. */
259 switch (cpu_machine_id) {
260 #ifdef _SUN3_
261 case SUN3_MACH_60:
262 /*
263 * Only the model 60 can have hi-res.
264 * Look at the "resolution" jumper.
265 */
266 tmp = bus_peek(BUS_OBMEM, BW2_CR_PADDR, 1);
267 if ((tmp != -1) && (tmp & 0x80) == 0)
268 goto high_res;
269 break;
270
271 case SUN3_MACH_260:
272 /* The Sun3/260 is ALWAYS high-resolution! */
273 /* fall through */
274 high_res:
275 fbt->fb_width = 1600;
276 fbt->fb_height = 1280;
277 fbt->fb_size = BW2_FBSIZE_HIRES;
278 break;
279 #endif /* SUN3 */
280
281 default:
282 /* Leave the defaults set above. */
283 break;
284 }
285 }
286 printf(" (%dx%d)\n", fbt->fb_width, fbt->fb_height);
287
288 /* Make sure video is on. */
289 tmp = 1;
290 bw2svideo(fb, &tmp);
291
292 /* Let /dev/fb know we are here. */
293 fb_attach(fb, 1);
294 }
295
296 int
297 bw2open(dev, flags, mode, p)
298 dev_t dev;
299 int flags, mode;
300 struct proc *p;
301 {
302 int unit = minor(dev);
303
304 if (unit >= bwtwo_cd.cd_ndevs || bwtwo_cd.cd_devs[unit] == NULL)
305 return (ENXIO);
306 return (0);
307 }
308
309 int
310 bw2ioctl(dev, cmd, data, flags, p)
311 dev_t dev;
312 u_long cmd;
313 caddr_t data;
314 int flags;
315 struct proc *p;
316 {
317 struct bw2_softc *sc = bwtwo_cd.cd_devs[minor(dev)];
318
319 return (fbioctlfb(&sc->sc_fb, cmd, data));
320 }
321
322 /*
323 * Return the address that would map the given device at the given
324 * offset, allowing for the given protection, or return -1 for error.
325 */
326 paddr_t
327 bw2mmap(dev, off, prot)
328 dev_t dev;
329 off_t off;
330 int prot;
331 {
332 struct bw2_softc *sc = bwtwo_cd.cd_devs[minor(dev)];
333 int size = sc->sc_fb.fb_fbtype.fb_size;
334
335 if (off & PGOFSET)
336 panic("bw2mmap");
337
338 if ((off < 0) || (off >= size))
339 return (-1);
340
341 /*
342 * I turned on PMAP_NC here to disable the cache as I was
343 * getting horribly broken behaviour without it.
344 */
345 return ((sc->sc_phys + off) | PMAP_NC);
346 }
347
348 /* FBIOGVIDEO: */
349 static int bw2gvideo(fb, data)
350 struct fbdevice *fb;
351 void *data;
352 {
353 struct bw2_softc *sc = fb->fb_private;
354 int *on = data;
355
356 *on = sc->sc_video_on;
357 return (0);
358 }
359
360 /* FBIOSVIDEO: */
361 static int bw2svideo(fb, data)
362 struct fbdevice *fb;
363 void *data;
364 {
365 struct bw2_softc *sc = fb->fb_private;
366 int *on = data;
367
368 if (sc->sc_video_on == *on)
369 return (0);
370 sc->sc_video_on = *on;
371
372 if (fb->fb_pfour)
373 fb_pfour_set_video(fb, sc->sc_video_on);
374 else
375 enable_video(sc->sc_video_on);
376
377 return(0);
378 }
379
380