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