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