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