cgtwo.c revision 1.35.2.1 1 1.35.2.1 fvdl /* $NetBSD: cgtwo.c,v 1.35.2.1 2001/10/10 11:56:32 fvdl 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.11 christos #include <sys/systm.h>
57 1.1 pk #include <sys/buf.h>
58 1.1 pk #include <sys/device.h>
59 1.1 pk #include <sys/ioctl.h>
60 1.1 pk #include <sys/malloc.h>
61 1.1 pk #include <sys/mman.h>
62 1.1 pk #include <sys/tty.h>
63 1.14 christos #include <sys/conf.h>
64 1.35.2.1 fvdl #include <sys/vnode.h>
65 1.1 pk
66 1.1 pk #include <machine/autoconf.h>
67 1.34 pk
68 1.34 pk #include <dev/sun/fbio.h>
69 1.34 pk #include <dev/sun/fbvar.h>
70 1.24 pk
71 1.24 pk #include <dev/vme/vmevar.h>
72 1.24 pk
73 1.2 pk #include <machine/eeprom.h>
74 1.14 christos #include <machine/conf.h>
75 1.3 pk #include <machine/cgtworeg.h>
76 1.1 pk
77 1.11 christos
78 1.1 pk /* per-display variables */
79 1.1 pk struct cgtwo_softc {
80 1.1 pk struct device sc_dev; /* base device */
81 1.1 pk struct fbdevice sc_fb; /* frame buffer device */
82 1.24 pk vme_addr_t sc_paddr;
83 1.24 pk vme_chipset_tag_t sc_ct;
84 1.24 pk bus_space_tag_t sc_bt;
85 1.3 pk volatile struct cg2statusreg *sc_reg; /* CG2 control registers */
86 1.3 pk volatile u_short *sc_cmap;
87 1.3 pk #define sc_redmap(sc) ((sc)->sc_cmap)
88 1.3 pk #define sc_greenmap(sc) ((sc)->sc_cmap + CG2_CMSIZE)
89 1.3 pk #define sc_bluemap(sc) ((sc)->sc_cmap + 2 * CG2_CMSIZE)
90 1.1 pk };
91 1.1 pk
92 1.1 pk /* autoconfiguration driver */
93 1.16 mrg static void cgtwoattach __P((struct device *, struct device *, void *));
94 1.20 pk static int cgtwomatch __P((struct device *, struct cfdata *, void *));
95 1.11 christos static void cgtwounblank __P((struct device *));
96 1.11 christos int cgtwogetcmap __P((struct cgtwo_softc *, struct fbcmap *));
97 1.11 christos int cgtwoputcmap __P((struct cgtwo_softc *, struct fbcmap *));
98 1.1 pk
99 1.17 thorpej /* cdevsw prototypes */
100 1.17 thorpej cdev_decl(cgtwo);
101 1.17 thorpej
102 1.12 thorpej struct cfattach cgtwo_ca = {
103 1.12 thorpej sizeof(struct cgtwo_softc), cgtwomatch, cgtwoattach
104 1.12 thorpej };
105 1.12 thorpej
106 1.23 thorpej extern struct cfdriver cgtwo_cd;
107 1.1 pk
108 1.1 pk /* frame buffer generic driver */
109 1.1 pk static struct fbdriver cgtwofbdriver = {
110 1.17 thorpej cgtwounblank, cgtwoopen, cgtwoclose, cgtwoioctl, cgtwopoll, cgtwommap
111 1.1 pk };
112 1.1 pk
113 1.1 pk /*
114 1.1 pk * Match a cgtwo.
115 1.1 pk */
116 1.1 pk int
117 1.20 pk cgtwomatch(parent, cf, aux)
118 1.1 pk struct device *parent;
119 1.20 pk struct cfdata *cf;
120 1.20 pk void *aux;
121 1.1 pk {
122 1.24 pk struct vme_attach_args *va = aux;
123 1.30 drochner vme_chipset_tag_t ct = va->va_vct;
124 1.30 drochner vme_am_t mod;
125 1.10 thorpej
126 1.10 thorpej /*
127 1.10 thorpej * Mask out invalid flags from the user.
128 1.10 thorpej */
129 1.10 thorpej cf->cf_flags &= FB_USERMASK;
130 1.2 pk
131 1.30 drochner mod = 0x3d; /* VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA */
132 1.30 drochner if (vme_probe(ct, va->r[0].offset + CG2_CTLREG_OFF, 2, mod, VME_D16,
133 1.26 pk 0, 0)) {
134 1.30 drochner return (0);
135 1.24 pk }
136 1.1 pk
137 1.30 drochner return (1);
138 1.1 pk }
139 1.1 pk
140 1.1 pk /*
141 1.1 pk * Attach a display. We need to notice if it is the console, too.
142 1.1 pk */
143 1.1 pk void
144 1.24 pk cgtwoattach(parent, self, aux)
145 1.1 pk struct device *parent, *self;
146 1.24 pk void *aux;
147 1.1 pk {
148 1.24 pk struct vme_attach_args *va = aux;
149 1.30 drochner vme_chipset_tag_t ct = va->va_vct;
150 1.30 drochner bus_space_tag_t bt;
151 1.24 pk bus_space_handle_t bh;
152 1.30 drochner vme_am_t mod;
153 1.30 drochner vme_mapresc_t resc;
154 1.28 pk struct cgtwo_softc *sc = (struct cgtwo_softc *)self;
155 1.28 pk struct fbdevice *fb = &sc->sc_fb;
156 1.28 pk struct eeprom *eep = (struct eeprom *)eeprom_va;
157 1.11 christos int isconsole = 0;
158 1.11 christos char *nam = NULL;
159 1.1 pk
160 1.24 pk sc->sc_ct = ct;
161 1.28 pk fb->fb_driver = &cgtwofbdriver;
162 1.28 pk fb->fb_device = &sc->sc_dev;
163 1.28 pk fb->fb_type.fb_type = FBTYPE_SUN2COLOR;
164 1.28 pk fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags;
165 1.28 pk
166 1.28 pk fb->fb_type.fb_depth = 8;
167 1.28 pk fb_setsize_eeprom(fb, fb->fb_type.fb_depth, 1152, 900);
168 1.5 pk
169 1.28 pk fb->fb_type.fb_cmsize = 256;
170 1.28 pk fb->fb_type.fb_size = roundup(CG2_MAPPED_SIZE, NBPG);
171 1.19 christos printf(": %s, %d x %d", nam,
172 1.28 pk fb->fb_type.fb_width, fb->fb_type.fb_height);
173 1.1 pk
174 1.1 pk /*
175 1.1 pk * When the ROM has mapped in a cgtwo display, the address
176 1.1 pk * maps only the video RAM, so in any case we have to map the
177 1.1 pk * registers ourselves. We only need the video RAM if we are
178 1.1 pk * going to print characters via rconsole.
179 1.1 pk */
180 1.30 drochner sc->sc_paddr = va->r[0].offset;
181 1.30 drochner mod = 0x3d; /* VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA */
182 1.24 pk
183 1.30 drochner if (vme_space_map(ct, sc->sc_paddr + CG2_ROPMEM_OFF +
184 1.24 pk offsetof(struct cg2fb, status.reg),
185 1.30 drochner sizeof(struct cg2statusreg), mod, VME_D16, 0,
186 1.30 drochner &bt, &bh, &resc) != 0)
187 1.24 pk panic("cgtwo: vme_map status");
188 1.30 drochner sc->sc_bt = bt;
189 1.30 drochner sc->sc_reg = (volatile struct cg2statusreg *)bh; /* XXX */
190 1.24 pk
191 1.30 drochner if (vme_space_map(ct, sc->sc_paddr + CG2_ROPMEM_OFF +
192 1.24 pk offsetof(struct cg2fb, redmap[0]),
193 1.30 drochner 3 * CG2_CMSIZE, mod, VME_D16, 0,
194 1.30 drochner &bt, &bh, &resc) != 0)
195 1.24 pk panic("cgtwo: vme_map cmap");
196 1.30 drochner sc->sc_cmap = (volatile u_short *)bh; /* XXX */
197 1.1 pk
198 1.28 pk /*
199 1.28 pk * Assume this is the console if there's no eeprom info
200 1.28 pk * to be found.
201 1.28 pk */
202 1.28 pk if (eep == NULL || eep->eeConsole == EE_CONS_COLOR)
203 1.31 pk isconsole = fb_is_console(0);
204 1.28 pk else
205 1.28 pk isconsole = 0;
206 1.28 pk
207 1.1 pk if (isconsole) {
208 1.30 drochner if (vme_space_map(ct, sc->sc_paddr + CG2_PIXMAP_OFF,
209 1.30 drochner CG2_PIXMAP_SIZE, mod, VME_D16, 0,
210 1.30 drochner &bt, &bh, &resc) != 0)
211 1.28 pk panic("cgtwo: vme_map pixels");
212 1.28 pk
213 1.30 drochner fb->fb_pixels = (caddr_t)bh; /* XXX */
214 1.19 christos printf(" (console)\n");
215 1.4 pk #ifdef RASTERCONSOLE
216 1.28 pk fbrcons_init(fb);
217 1.1 pk #endif
218 1.1 pk } else
219 1.19 christos printf("\n");
220 1.9 pk
221 1.28 pk fb_attach(fb, isconsole);
222 1.1 pk }
223 1.1 pk
224 1.1 pk int
225 1.35.2.1 fvdl cgtwoopen(devvp, flags, mode, p)
226 1.35.2.1 fvdl struct vnode *devvp;
227 1.1 pk int flags, mode;
228 1.1 pk struct proc *p;
229 1.1 pk {
230 1.35.2.1 fvdl dev_t dev = vdev_rdev(devvp);
231 1.1 pk int unit = minor(dev);
232 1.1 pk
233 1.12 thorpej if (unit >= cgtwo_cd.cd_ndevs || cgtwo_cd.cd_devs[unit] == NULL)
234 1.1 pk return (ENXIO);
235 1.35.2.1 fvdl
236 1.35.2.1 fvdl vdev_setprivdata(devvp, cgtwo_cd.cd_devs[unit]);
237 1.35.2.1 fvdl
238 1.1 pk return (0);
239 1.1 pk }
240 1.1 pk
241 1.1 pk int
242 1.35.2.1 fvdl cgtwoclose(devvp, flags, mode, p)
243 1.35.2.1 fvdl struct vnode *devvp;
244 1.1 pk int flags, mode;
245 1.1 pk struct proc *p;
246 1.1 pk {
247 1.1 pk
248 1.1 pk return (0);
249 1.1 pk }
250 1.1 pk
251 1.1 pk int
252 1.35.2.1 fvdl cgtwoioctl(devvp, cmd, data, flags, p)
253 1.35.2.1 fvdl struct vnode *devvp;
254 1.1 pk u_long cmd;
255 1.1 pk register caddr_t data;
256 1.1 pk int flags;
257 1.1 pk struct proc *p;
258 1.1 pk {
259 1.35.2.1 fvdl register struct cgtwo_softc *sc = vdev_privdata(devvp);
260 1.1 pk register struct fbgattr *fba;
261 1.1 pk
262 1.1 pk switch (cmd) {
263 1.1 pk
264 1.1 pk case FBIOGTYPE:
265 1.1 pk *(struct fbtype *)data = sc->sc_fb.fb_type;
266 1.1 pk break;
267 1.1 pk
268 1.1 pk case FBIOGATTR:
269 1.1 pk fba = (struct fbgattr *)data;
270 1.1 pk fba->real_type = sc->sc_fb.fb_type.fb_type;
271 1.1 pk fba->owner = 0; /* XXX ??? */
272 1.1 pk fba->fbtype = sc->sc_fb.fb_type;
273 1.1 pk fba->sattr.flags = 0;
274 1.1 pk fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
275 1.1 pk fba->sattr.dev_specific[0] = -1;
276 1.1 pk fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
277 1.1 pk fba->emu_types[1] = -1;
278 1.1 pk break;
279 1.1 pk
280 1.1 pk case FBIOGETCMAP:
281 1.11 christos return cgtwogetcmap(sc, (struct fbcmap *) data);
282 1.1 pk
283 1.1 pk case FBIOPUTCMAP:
284 1.11 christos return cgtwoputcmap(sc, (struct fbcmap *) data);
285 1.1 pk
286 1.1 pk case FBIOGVIDEO:
287 1.3 pk *(int *)data = sc->sc_reg->video_enab;
288 1.1 pk break;
289 1.1 pk
290 1.1 pk case FBIOSVIDEO:
291 1.3 pk sc->sc_reg->video_enab = (*(int*)data) & 1;
292 1.1 pk break;
293 1.1 pk
294 1.1 pk default:
295 1.1 pk return (ENOTTY);
296 1.1 pk }
297 1.1 pk return (0);
298 1.17 thorpej }
299 1.17 thorpej
300 1.17 thorpej int
301 1.35.2.1 fvdl cgtwopoll(devvp, events, p)
302 1.35.2.1 fvdl struct vnode *devvp;
303 1.17 thorpej int events;
304 1.17 thorpej struct proc *p;
305 1.17 thorpej {
306 1.17 thorpej
307 1.35.2.1 fvdl return (seltrue(devvp, events, p));
308 1.1 pk }
309 1.1 pk
310 1.1 pk /*
311 1.1 pk * Undo the effect of an FBIOSVIDEO that turns the video off.
312 1.1 pk */
313 1.1 pk static void
314 1.1 pk cgtwounblank(dev)
315 1.1 pk struct device *dev;
316 1.1 pk {
317 1.1 pk struct cgtwo_softc *sc = (struct cgtwo_softc *)dev;
318 1.3 pk sc->sc_reg->video_enab = 1;
319 1.1 pk }
320 1.1 pk
321 1.1 pk /*
322 1.1 pk */
323 1.1 pk int
324 1.1 pk cgtwogetcmap(sc, cmap)
325 1.1 pk register struct cgtwo_softc *sc;
326 1.1 pk register struct fbcmap *cmap;
327 1.1 pk {
328 1.1 pk u_char red[CG2_CMSIZE], green[CG2_CMSIZE], blue[CG2_CMSIZE];
329 1.1 pk int error, start, count, ecount;
330 1.1 pk register u_int i;
331 1.3 pk register volatile u_short *p;
332 1.1 pk
333 1.1 pk start = cmap->index;
334 1.1 pk count = cmap->count;
335 1.1 pk ecount = start + count;
336 1.1 pk if (start >= CG2_CMSIZE || ecount > CG2_CMSIZE)
337 1.1 pk return (EINVAL);
338 1.1 pk
339 1.1 pk /* XXX - Wait for retrace? */
340 1.1 pk
341 1.1 pk /* Copy hardware to local arrays. */
342 1.3 pk p = &sc_redmap(sc)[start];
343 1.1 pk for (i = start; i < ecount; i++)
344 1.1 pk red[i] = *p++;
345 1.3 pk p = &sc_greenmap(sc)[start];
346 1.1 pk for (i = start; i < ecount; i++)
347 1.1 pk green[i] = *p++;
348 1.3 pk p = &sc_bluemap(sc)[start];
349 1.1 pk for (i = start; i < ecount; i++)
350 1.1 pk blue[i] = *p++;
351 1.1 pk
352 1.1 pk /* Copy local arrays to user space. */
353 1.1 pk if ((error = copyout(red + start, cmap->red, count)) != 0)
354 1.1 pk return (error);
355 1.1 pk if ((error = copyout(green + start, cmap->green, count)) != 0)
356 1.1 pk return (error);
357 1.1 pk if ((error = copyout(blue + start, cmap->blue, count)) != 0)
358 1.1 pk return (error);
359 1.1 pk
360 1.1 pk return (0);
361 1.1 pk }
362 1.1 pk
363 1.1 pk /*
364 1.1 pk */
365 1.1 pk int
366 1.1 pk cgtwoputcmap(sc, cmap)
367 1.1 pk register struct cgtwo_softc *sc;
368 1.1 pk register struct fbcmap *cmap;
369 1.1 pk {
370 1.1 pk u_char red[CG2_CMSIZE], green[CG2_CMSIZE], blue[CG2_CMSIZE];
371 1.35 jdolecek int error;
372 1.35 jdolecek u_int start, count, ecount;
373 1.1 pk register u_int i;
374 1.3 pk register volatile 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 /* Copy from user space to local arrays. */
383 1.1 pk if ((error = copyin(cmap->red, red + start, count)) != 0)
384 1.1 pk return (error);
385 1.1 pk if ((error = copyin(cmap->green, green + start, count)) != 0)
386 1.1 pk return (error);
387 1.1 pk if ((error = copyin(cmap->blue, blue + start, count)) != 0)
388 1.1 pk return (error);
389 1.1 pk
390 1.1 pk /* XXX - Wait for retrace? */
391 1.1 pk
392 1.1 pk /* Copy from local arrays to hardware. */
393 1.3 pk p = &sc_redmap(sc)[start];
394 1.1 pk for (i = start; i < ecount; i++)
395 1.1 pk *p++ = red[i];
396 1.3 pk p = &sc_greenmap(sc)[start];
397 1.1 pk for (i = start; i < ecount; i++)
398 1.1 pk *p++ = green[i];
399 1.3 pk p = &sc_bluemap(sc)[start];
400 1.1 pk for (i = start; i < ecount; i++)
401 1.1 pk *p++ = blue[i];
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 * Return the address that would map the given device at the given
408 1.1 pk * offset, allowing for the given protection, or return -1 for error.
409 1.1 pk */
410 1.32 simonb paddr_t
411 1.35.2.1 fvdl cgtwommap(devvp, off, prot)
412 1.35.2.1 fvdl struct vnode *devvp;
413 1.32 simonb off_t off;
414 1.32 simonb int prot;
415 1.1 pk {
416 1.35.2.1 fvdl register struct cgtwo_softc *sc = vdev_privdata(devvp);
417 1.30 drochner vme_am_t mod;
418 1.29 pk bus_space_handle_t bh;
419 1.30 drochner extern int sparc_vme_mmap_cookie __P((vme_addr_t, vme_am_t,
420 1.30 drochner bus_space_handle_t *));
421 1.1 pk
422 1.1 pk if (off & PGOFSET)
423 1.1 pk panic("cgtwommap");
424 1.1 pk
425 1.32 simonb if (off >= sc->sc_fb.fb_type.fb_size)
426 1.1 pk return (-1);
427 1.1 pk
428 1.24 pk /* Apparently, the pixels are in 32-bit data space */
429 1.30 drochner mod = 0x3d; /* VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA */
430 1.24 pk
431 1.30 drochner if (sparc_vme_mmap_cookie(sc->sc_paddr + off, mod, &bh) != 0)
432 1.24 pk panic("cgtwommap");
433 1.24 pk
434 1.32 simonb return ((paddr_t)bh);
435 1.1 pk }
436