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