cgtwo.c revision 1.2 1 1.2 pk /* $NetBSD: cgtwo.c,v 1.2 1995/10/02 09:07:04 pk Exp $ */
2 1.1 pk
3 1.1 pk /*
4 1.1 pk * Copyright (c) 1992, 1993
5 1.1 pk * The Regents of the University of California. All rights reserved.
6 1.1 pk *
7 1.1 pk * This software was developed by the Computer Systems Engineering group
8 1.1 pk * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 1.1 pk * contributed to Berkeley.
10 1.1 pk *
11 1.1 pk * All advertising materials mentioning features or use of this software
12 1.1 pk * must display the following acknowledgement:
13 1.1 pk * This product includes software developed by the University of
14 1.1 pk * California, Lawrence Berkeley Laboratory.
15 1.1 pk *
16 1.1 pk * Redistribution and use in source and binary forms, with or without
17 1.1 pk * modification, are permitted provided that the following conditions
18 1.1 pk * are met:
19 1.1 pk * 1. Redistributions of source code must retain the above copyright
20 1.1 pk * notice, this list of conditions and the following disclaimer.
21 1.1 pk * 2. Redistributions in binary form must reproduce the above copyright
22 1.1 pk * notice, this list of conditions and the following disclaimer in the
23 1.1 pk * documentation and/or other materials provided with the distribution.
24 1.1 pk * 3. All advertising materials mentioning features or use of this software
25 1.1 pk * must display the following acknowledgement:
26 1.1 pk * This product includes software developed by the University of
27 1.1 pk * California, Berkeley and its contributors.
28 1.1 pk * 4. Neither the name of the University nor the names of its contributors
29 1.1 pk * may be used to endorse or promote products derived from this software
30 1.1 pk * without specific prior written permission.
31 1.1 pk *
32 1.1 pk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 1.1 pk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 1.1 pk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 1.1 pk * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 1.1 pk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1 pk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1 pk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1 pk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 1.1 pk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 1.1 pk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 1.1 pk * SUCH DAMAGE.
43 1.1 pk *
44 1.1 pk * from: @(#)cgthree.c 8.2 (Berkeley) 10/30/93
45 1.1 pk */
46 1.1 pk
47 1.1 pk /*
48 1.1 pk * color display (cgtwo) driver.
49 1.1 pk *
50 1.1 pk * Does not handle interrupts, even though they can occur.
51 1.1 pk *
52 1.1 pk * XXX should defer colormap updates to vertical retrace interrupts
53 1.1 pk */
54 1.1 pk
55 1.1 pk #include <sys/param.h>
56 1.1 pk #include <sys/buf.h>
57 1.1 pk #include <sys/device.h>
58 1.1 pk #include <sys/ioctl.h>
59 1.1 pk #include <sys/malloc.h>
60 1.1 pk #include <sys/mman.h>
61 1.1 pk #include <sys/tty.h>
62 1.1 pk
63 1.1 pk #include <vm/vm.h>
64 1.1 pk
65 1.1 pk #include <machine/fbio.h>
66 1.1 pk #include <machine/autoconf.h>
67 1.1 pk #include <machine/pmap.h>
68 1.1 pk #include <machine/fbvar.h>
69 1.2 pk #if defined(SUN4)
70 1.2 pk #include <machine/eeprom.h>
71 1.2 pk #endif
72 1.1 pk
73 1.1 pk #include <sparc/dev/cgtworeg.h>
74 1.1 pk #include <sparc/dev/sbusvar.h>
75 1.1 pk
76 1.1 pk /* per-display variables */
77 1.1 pk struct cgtwo_softc {
78 1.1 pk struct device sc_dev; /* base device */
79 1.1 pk struct sbusdev sc_sd; /* sbus device */
80 1.1 pk struct fbdevice sc_fb; /* frame buffer device */
81 1.1 pk caddr_t sc_phys; /* display RAM (phys addr) */
82 1.1 pk volatile struct cg2reg *sc_reg; /* CG2 control registers */
83 1.1 pk };
84 1.1 pk
85 1.1 pk /* autoconfiguration driver */
86 1.1 pk static void cgtwoattach(struct device *, struct device *, void *);
87 1.1 pk static int cgtwomatch(struct device *, void *, void *);
88 1.1 pk int cgtwoopen __P((dev_t, int, int, struct proc *));
89 1.1 pk int cgtwoclose __P((dev_t, int, int, struct proc *));
90 1.1 pk int cgtwoioctl __P((dev_t, u_long, caddr_t, int, struct proc *));
91 1.1 pk int cgtwommap __P((dev_t, int, int));
92 1.1 pk static void cgtwounblank(struct device *);
93 1.1 pk
94 1.1 pk struct cfdriver cgtwocd = {
95 1.1 pk NULL, "cgtwo", cgtwomatch, cgtwoattach,
96 1.1 pk DV_DULL, sizeof(struct cgtwo_softc)
97 1.1 pk };
98 1.1 pk
99 1.1 pk /* frame buffer generic driver */
100 1.1 pk static struct fbdriver cgtwofbdriver = {
101 1.1 pk cgtwounblank, cgtwoopen, cgtwoclose, cgtwoioctl, cgtwommap
102 1.1 pk };
103 1.1 pk
104 1.1 pk extern int fbnode;
105 1.1 pk extern struct tty *fbconstty;
106 1.1 pk extern int nullop();
107 1.1 pk static int cgtwo_cnputc();
108 1.1 pk
109 1.1 pk static void cgtwoloadcmap __P((struct cgtwo_softc *, int, int));
110 1.1 pk
111 1.1 pk /*
112 1.1 pk * Match a cgtwo.
113 1.1 pk */
114 1.1 pk int
115 1.1 pk cgtwomatch(parent, vcf, aux)
116 1.1 pk struct device *parent;
117 1.1 pk void *vcf, *aux;
118 1.1 pk {
119 1.1 pk struct cfdata *cf = vcf;
120 1.1 pk struct confargs *ca = aux;
121 1.1 pk struct romaux *ra = &ca->ca_ra;
122 1.2 pk int probe;
123 1.2 pk caddr_t tmp;
124 1.2 pk
125 1.2 pk if (ca->ca_bustype != BUS_VME16)
126 1.2 pk return (0);
127 1.1 pk
128 1.1 pk if (strcmp(cf->cf_driver->cd_name, ra->ra_name))
129 1.1 pk return (0);
130 1.2 pk
131 1.2 pk #if defined(SUN4)
132 1.2 pk if (cputyp != CPU_SUN4 || cf->cf_unit != 0)
133 1.2 pk return (0);
134 1.2 pk
135 1.2 pk /* XXX - Must do our own mapping at CG2_CTLREG_OFF */
136 1.2 pk bus_untmp();
137 1.2 pk tmp = (caddr_t)bus_tmp(ra->ra_paddr + CG2_CTLREG_OFF, ca->ca_bustype);
138 1.2 pk if (probeget(tmp, 2) != -1)
139 1.2 pk return 1;
140 1.2 pk #endif
141 1.2 pk return 0;
142 1.1 pk }
143 1.1 pk
144 1.1 pk /*
145 1.1 pk * Attach a display. We need to notice if it is the console, too.
146 1.1 pk */
147 1.1 pk void
148 1.1 pk cgtwoattach(parent, self, args)
149 1.1 pk struct device *parent, *self;
150 1.1 pk void *args;
151 1.1 pk {
152 1.1 pk register struct cgtwo_softc *sc = (struct cgtwo_softc *)self;
153 1.1 pk register struct confargs *ca = args;
154 1.2 pk register int node, i;
155 1.1 pk register struct cgtwo_all *p;
156 1.1 pk int isconsole;
157 1.1 pk int sbus = 1;
158 1.1 pk char *nam;
159 1.1 pk
160 1.1 pk sc->sc_fb.fb_driver = &cgtwofbdriver;
161 1.1 pk sc->sc_fb.fb_device = &sc->sc_dev;
162 1.1 pk /*
163 1.1 pk * The defaults below match my screen, but are not guaranteed
164 1.1 pk * to be correct as defaults go...
165 1.1 pk */
166 1.1 pk sc->sc_fb.fb_type.fb_type = FBTYPE_SUN2COLOR;
167 1.1 pk switch (ca->ca_bustype) {
168 1.1 pk case BUS_OBIO:
169 1.1 pk case BUS_VME32:
170 1.1 pk case BUS_VME16:
171 1.1 pk sbus = node = 0;
172 1.1 pk sc->sc_fb.fb_type.fb_width = 1152;
173 1.1 pk sc->sc_fb.fb_type.fb_height = 900;
174 1.1 pk sc->sc_fb.fb_linebytes = 1152;
175 1.1 pk nam = "cgtwo";
176 1.2 pk
177 1.2 pk #if defined(SUN4)
178 1.2 pk if (cputyp==CPU_SUN4) {
179 1.2 pk struct eeprom *eep = (struct eeprom *)eeprom_va;
180 1.2 pk if (eep != NULL) {
181 1.2 pk switch (eep->eeScreenSize) {
182 1.2 pk case EE_SCR_1152X900:
183 1.2 pk /* Handled above. */
184 1.2 pk break;
185 1.2 pk
186 1.2 pk case EE_SCR_1024X1024:
187 1.2 pk sc->sc_fb.fb_type.fb_width = 1024;
188 1.2 pk sc->sc_fb.fb_type.fb_height = 1024;
189 1.2 pk sc->sc_fb.fb_linebytes = 128;
190 1.2 pk break;
191 1.2 pk
192 1.2 pk case EE_SCR_1600X1280:
193 1.2 pk sc->sc_fb.fb_type.fb_width = 1600;
194 1.2 pk sc->sc_fb.fb_type.fb_height = 1280;
195 1.2 pk sc->sc_fb.fb_linebytes = 200;
196 1.2 pk break;
197 1.2 pk
198 1.2 pk case EE_SCR_1440X1440:
199 1.2 pk sc->sc_fb.fb_type.fb_width = 1440;
200 1.2 pk sc->sc_fb.fb_type.fb_height = 1440;
201 1.2 pk sc->sc_fb.fb_linebytes = 180;
202 1.2 pk break;
203 1.2 pk
204 1.2 pk default:
205 1.2 pk /*
206 1.2 pk * XXX: Do nothing, I guess.
207 1.2 pk * Should we print a warning about
208 1.2 pk * an unknown value? --thorpej
209 1.2 pk */
210 1.2 pk break;
211 1.2 pk }
212 1.2 pk }
213 1.2 pk }
214 1.2 pk #endif
215 1.1 pk break;
216 1.2 pk #if 0
217 1.1 pk case BUS_SBUS:
218 1.1 pk node = ca->ca_ra.ra_node;
219 1.1 pk sc->sc_fb.fb_type.fb_width = getpropint(node, "width", 1152);
220 1.1 pk sc->sc_fb.fb_type.fb_height = getpropint(node, "height", 900);
221 1.1 pk sc->sc_fb.fb_linebytes = getpropint(node, "linebytes", 1152);
222 1.1 pk nam = getpropstring(node, "model");
223 1.1 pk break;
224 1.2 pk #endif
225 1.1 pk }
226 1.1 pk
227 1.1 pk sc->sc_fb.fb_type.fb_depth = 8;
228 1.1 pk sc->sc_fb.fb_type.fb_cmsize = 256;
229 1.2 pk sc->sc_fb.fb_type.fb_size = roundup(CG2_MAPPED_SIZE, NBPG);
230 1.1 pk printf(": %s, %d x %d", nam,
231 1.1 pk sc->sc_fb.fb_type.fb_width, sc->sc_fb.fb_type.fb_height);
232 1.1 pk
233 1.1 pk /*
234 1.1 pk * When the ROM has mapped in a cgtwo display, the address
235 1.1 pk * maps only the video RAM, so in any case we have to map the
236 1.1 pk * registers ourselves. We only need the video RAM if we are
237 1.1 pk * going to print characters via rconsole.
238 1.1 pk */
239 1.2 pk #if defined(SUN4)
240 1.2 pk if (cputyp == CPU_SUN4) {
241 1.2 pk struct eeprom *eep = (struct eeprom *)eeprom_va;
242 1.2 pk /*
243 1.2 pk * Assume this is the console if there's no eeprom info
244 1.2 pk * to be found.
245 1.2 pk */
246 1.2 pk if (eep == NULL || eep->eeConsole == EE_CONS_COLOR)
247 1.2 pk isconsole = (fbconstty != NULL);
248 1.2 pk else
249 1.2 pk isconsole = 0;
250 1.2 pk }
251 1.2 pk #endif
252 1.2 pk #if defined(SUN4C) || defined(SUN4M)
253 1.2 pk if (cputyp == CPU_SUN4C || cputyp == CPU_SUN4M)
254 1.2 pk isconsole = node == fbnode && fbconstty != NULL;
255 1.2 pk #endif
256 1.1 pk sc->sc_phys = (caddr_t)ca->ca_ra.ra_paddr;
257 1.1 pk if ((sc->sc_fb.fb_pixels = ca->ca_ra.ra_vaddr) == NULL && isconsole) {
258 1.1 pk /* this probably cannot happen, but what the heck */
259 1.2 pk sc->sc_fb.fb_pixels = mapiodev(sc->sc_phys + CG2_PIXMAP_OFF,
260 1.2 pk CG2_PIXMAP_SIZE,
261 1.1 pk ca->ca_bustype);
262 1.1 pk }
263 1.1 pk sc->sc_reg = (volatile struct cg2reg *)
264 1.1 pk mapiodev((caddr_t)sc->sc_phys + CG2_CTLREG_OFF, CG2_CTLREG_SIZE,
265 1.1 pk ca->ca_bustype);
266 1.1 pk
267 1.1 pk if (isconsole) {
268 1.1 pk printf(" (console)\n");
269 1.1 pk #ifdef RCONSOLE
270 1.1 pk fbrcons_init(&sc->sc_fb);
271 1.1 pk #endif
272 1.1 pk } else
273 1.1 pk printf("\n");
274 1.1 pk if (sbus)
275 1.1 pk sbus_establish(&sc->sc_sd, &sc->sc_dev);
276 1.1 pk if (node == fbnode)
277 1.1 pk fb_attach(&sc->sc_fb);
278 1.1 pk }
279 1.1 pk
280 1.1 pk int
281 1.1 pk cgtwoopen(dev, flags, mode, p)
282 1.1 pk dev_t dev;
283 1.1 pk int flags, mode;
284 1.1 pk struct proc *p;
285 1.1 pk {
286 1.1 pk int unit = minor(dev);
287 1.1 pk
288 1.1 pk if (unit >= cgtwocd.cd_ndevs || cgtwocd.cd_devs[unit] == NULL)
289 1.1 pk return (ENXIO);
290 1.1 pk return (0);
291 1.1 pk }
292 1.1 pk
293 1.1 pk int
294 1.1 pk cgtwoclose(dev, flags, mode, p)
295 1.1 pk dev_t dev;
296 1.1 pk int flags, mode;
297 1.1 pk struct proc *p;
298 1.1 pk {
299 1.1 pk
300 1.1 pk return (0);
301 1.1 pk }
302 1.1 pk
303 1.1 pk int
304 1.1 pk cgtwoioctl(dev, cmd, data, flags, p)
305 1.1 pk dev_t dev;
306 1.1 pk u_long cmd;
307 1.1 pk register caddr_t data;
308 1.1 pk int flags;
309 1.1 pk struct proc *p;
310 1.1 pk {
311 1.1 pk register struct cgtwo_softc *sc = cgtwocd.cd_devs[minor(dev)];
312 1.1 pk register struct fbgattr *fba;
313 1.1 pk int error;
314 1.1 pk
315 1.1 pk switch (cmd) {
316 1.1 pk
317 1.1 pk case FBIOGTYPE:
318 1.1 pk *(struct fbtype *)data = sc->sc_fb.fb_type;
319 1.1 pk break;
320 1.1 pk
321 1.1 pk case FBIOGATTR:
322 1.1 pk fba = (struct fbgattr *)data;
323 1.1 pk fba->real_type = sc->sc_fb.fb_type.fb_type;
324 1.1 pk fba->owner = 0; /* XXX ??? */
325 1.1 pk fba->fbtype = sc->sc_fb.fb_type;
326 1.1 pk fba->sattr.flags = 0;
327 1.1 pk fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
328 1.1 pk fba->sattr.dev_specific[0] = -1;
329 1.1 pk fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
330 1.1 pk fba->emu_types[1] = -1;
331 1.1 pk break;
332 1.1 pk
333 1.1 pk case FBIOGETCMAP:
334 1.1 pk return cgtwogetcmap(sc, data);
335 1.1 pk
336 1.1 pk case FBIOPUTCMAP:
337 1.1 pk return cgtwoputcmap(sc, data);
338 1.1 pk
339 1.1 pk case FBIOGVIDEO:
340 1.1 pk *(int *)data = sc->sc_reg->status.video_enab;
341 1.1 pk break;
342 1.1 pk
343 1.1 pk case FBIOSVIDEO:
344 1.1 pk sc->sc_reg->status.video_enab = (*(int*)data) & 1;
345 1.1 pk break;
346 1.1 pk
347 1.1 pk default:
348 1.1 pk return (ENOTTY);
349 1.1 pk }
350 1.1 pk return (0);
351 1.1 pk }
352 1.1 pk
353 1.1 pk /*
354 1.1 pk * Undo the effect of an FBIOSVIDEO that turns the video off.
355 1.1 pk */
356 1.1 pk static void
357 1.1 pk cgtwounblank(dev)
358 1.1 pk struct device *dev;
359 1.1 pk {
360 1.1 pk struct cgtwo_softc *sc = (struct cgtwo_softc *)dev;
361 1.1 pk sc->sc_reg->status.video_enab = 1;
362 1.1 pk }
363 1.1 pk
364 1.1 pk /*
365 1.1 pk */
366 1.1 pk int
367 1.1 pk cgtwogetcmap(sc, cmap)
368 1.1 pk register struct cgtwo_softc *sc;
369 1.1 pk register struct fbcmap *cmap;
370 1.1 pk {
371 1.1 pk u_char red[CG2_CMSIZE], green[CG2_CMSIZE], blue[CG2_CMSIZE];
372 1.1 pk int error, start, count, ecount;
373 1.1 pk register u_int i;
374 1.1 pk register u_short *p;
375 1.1 pk
376 1.1 pk start = cmap->index;
377 1.1 pk count = cmap->count;
378 1.1 pk ecount = start + count;
379 1.1 pk if (start >= CG2_CMSIZE || ecount > CG2_CMSIZE)
380 1.1 pk return (EINVAL);
381 1.1 pk
382 1.1 pk /* XXX - Wait for retrace? */
383 1.1 pk
384 1.1 pk /* Copy hardware to local arrays. */
385 1.1 pk p = &sc->sc_reg->redmap[start];
386 1.1 pk for (i = start; i < ecount; i++)
387 1.1 pk red[i] = *p++;
388 1.1 pk p = &sc->sc_reg->greenmap[start];
389 1.1 pk for (i = start; i < ecount; i++)
390 1.1 pk green[i] = *p++;
391 1.1 pk p = &sc->sc_reg->bluemap[start];
392 1.1 pk for (i = start; i < ecount; i++)
393 1.1 pk blue[i] = *p++;
394 1.1 pk
395 1.1 pk /* Copy local arrays to user space. */
396 1.1 pk if ((error = copyout(red + start, cmap->red, count)) != 0)
397 1.1 pk return (error);
398 1.1 pk if ((error = copyout(green + start, cmap->green, count)) != 0)
399 1.1 pk return (error);
400 1.1 pk if ((error = copyout(blue + start, cmap->blue, count)) != 0)
401 1.1 pk return (error);
402 1.1 pk
403 1.1 pk return (0);
404 1.1 pk }
405 1.1 pk
406 1.1 pk /*
407 1.1 pk */
408 1.1 pk int
409 1.1 pk cgtwoputcmap(sc, cmap)
410 1.1 pk register struct cgtwo_softc *sc;
411 1.1 pk register struct fbcmap *cmap;
412 1.1 pk {
413 1.1 pk u_char red[CG2_CMSIZE], green[CG2_CMSIZE], blue[CG2_CMSIZE];
414 1.1 pk int error, start, count, ecount;
415 1.1 pk register u_int i;
416 1.1 pk register u_short *p;
417 1.1 pk
418 1.1 pk start = cmap->index;
419 1.1 pk count = cmap->count;
420 1.1 pk ecount = start + count;
421 1.1 pk if (start >= CG2_CMSIZE || ecount > CG2_CMSIZE)
422 1.1 pk return (EINVAL);
423 1.1 pk
424 1.1 pk /* Copy from user space to local arrays. */
425 1.1 pk if ((error = copyin(cmap->red, red + start, count)) != 0)
426 1.1 pk return (error);
427 1.1 pk if ((error = copyin(cmap->green, green + start, count)) != 0)
428 1.1 pk return (error);
429 1.1 pk if ((error = copyin(cmap->blue, blue + start, count)) != 0)
430 1.1 pk return (error);
431 1.1 pk
432 1.1 pk /* XXX - Wait for retrace? */
433 1.1 pk
434 1.1 pk /* Copy from local arrays to hardware. */
435 1.1 pk p = &sc->sc_reg->redmap[start];
436 1.1 pk for (i = start; i < ecount; i++)
437 1.1 pk *p++ = red[i];
438 1.1 pk p = &sc->sc_reg->greenmap[start];
439 1.1 pk for (i = start; i < ecount; i++)
440 1.1 pk *p++ = green[i];
441 1.1 pk p = &sc->sc_reg->bluemap[start];
442 1.1 pk for (i = start; i < ecount; i++)
443 1.1 pk *p++ = blue[i];
444 1.1 pk
445 1.1 pk return (0);
446 1.1 pk }
447 1.1 pk
448 1.1 pk /*
449 1.1 pk * Return the address that would map the given device at the given
450 1.1 pk * offset, allowing for the given protection, or return -1 for error.
451 1.1 pk */
452 1.1 pk int
453 1.1 pk cgtwommap(dev, off, prot)
454 1.1 pk dev_t dev;
455 1.1 pk int off, prot;
456 1.1 pk {
457 1.1 pk register struct cgtwo_softc *sc = cgtwocd.cd_devs[minor(dev)];
458 1.1 pk
459 1.1 pk if (off & PGOFSET)
460 1.1 pk panic("cgtwommap");
461 1.1 pk
462 1.1 pk if ((unsigned)off >= sc->sc_fb.fb_type.fb_size)
463 1.1 pk return (-1);
464 1.1 pk
465 1.2 pk return ((int)sc->sc_phys + off + PMAP_VME16 + PMAP_NC);
466 1.1 pk }
467