Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / hp300 / dev / grf_rb.c
blob22005b8d4ae974caca4c69eb22efd849e304ad03
1 /* $NetBSD: grf_rb.c,v 1.39 2008/03/29 06:47:07 tsutsui Exp $ */
3 /*-
4 * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1990, 1993
34 * The Regents of the University of California. All rights reserved.
36 * This code is derived from software contributed to Berkeley by
37 * the Systems Programming Group of the University of Utah Computer
38 * Science Department.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 * SUCH DAMAGE.
64 * from: Utah $Hdr: grf_rb.c 1.15 93/08/13$
66 * @(#)grf_rb.c 8.4 (Berkeley) 1/12/94
69 * Copyright (c) 1988 University of Utah.
71 * This code is derived from software contributed to Berkeley by
72 * the Systems Programming Group of the University of Utah Computer
73 * Science Department.
75 * Redistribution and use in source and binary forms, with or without
76 * modification, are permitted provided that the following conditions
77 * are met:
78 * 1. Redistributions of source code must retain the above copyright
79 * notice, this list of conditions and the following disclaimer.
80 * 2. Redistributions in binary form must reproduce the above copyright
81 * notice, this list of conditions and the following disclaimer in the
82 * documentation and/or other materials provided with the distribution.
83 * 3. All advertising materials mentioning features or use of this software
84 * must display the following acknowledgement:
85 * This product includes software developed by the University of
86 * California, Berkeley and its contributors.
87 * 4. Neither the name of the University nor the names of its contributors
88 * may be used to endorse or promote products derived from this software
89 * without specific prior written permission.
91 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
92 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
93 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
94 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
95 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
96 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
97 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
98 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
99 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
100 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
101 * SUCH DAMAGE.
103 * from: Utah $Hdr: grf_rb.c 1.15 93/08/13$
105 * @(#)grf_rb.c 8.4 (Berkeley) 1/12/94
109 * Graphics routines for the Renaissance, HP98720 Graphics system.
112 #include <sys/cdefs.h>
113 __KERNEL_RCSID(0, "$NetBSD: grf_rb.c,v 1.39 2008/03/29 06:47:07 tsutsui Exp $");
115 #include <sys/param.h>
116 #include <sys/systm.h>
117 #include <sys/conf.h>
118 #include <sys/device.h>
119 #include <sys/errno.h>
120 #include <sys/ioctl.h>
121 #include <sys/proc.h>
122 #include <sys/tty.h>
124 #include <uvm/uvm_extern.h>
126 #include <machine/autoconf.h>
127 #include <machine/cpu.h>
129 #include <dev/cons.h>
131 #include <hp300/dev/dioreg.h>
132 #include <hp300/dev/diovar.h>
133 #include <hp300/dev/diodevs.h>
134 #include <hp300/dev/intiovar.h>
136 #include <hp300/dev/grfioctl.h>
137 #include <hp300/dev/grfvar.h>
138 #include <hp300/dev/grfreg.h>
139 #include <hp300/dev/grf_rbreg.h>
141 #include <hp300/dev/itevar.h>
142 #include <hp300/dev/itereg.h>
144 #include "ite.h"
146 static int rb_init(struct grf_data *gp, int, uint8_t *);
147 static int rb_mode(struct grf_data *gp, int, void *);
149 static int rbox_intio_match(device_t, cfdata_t, void *);
150 static void rbox_intio_attach(device_t, device_t, void *);
152 static int rbox_dio_match(device_t, cfdata_t, void *);
153 static void rbox_dio_attach(device_t, device_t, void *);
155 int rboxcnattach(bus_space_tag_t, bus_addr_t, int);
157 CFATTACH_DECL_NEW(rbox_intio, sizeof(struct grfdev_softc),
158 rbox_intio_match, rbox_intio_attach, NULL, NULL);
160 CFATTACH_DECL_NEW(rbox_dio, sizeof(struct grfdev_softc),
161 rbox_dio_match, rbox_dio_attach, NULL, NULL);
163 /* Renaissance grf switch */
164 static struct grfsw rbox_grfsw = {
165 GID_RENAISSANCE, GRFRBOX, "renaissance", rb_init, rb_mode
168 static int rbconscode;
169 static void *rbconaddr;
171 #if NITE > 0
172 static void rbox_init(struct ite_data *);
173 static void rbox_deinit(struct ite_data *);
174 static void rbox_putc(struct ite_data *, int, int, int, int);
175 static void rbox_cursor(struct ite_data *, int);
176 static void rbox_clear(struct ite_data *, int, int, int, int);
177 static void rbox_scroll(struct ite_data *, int, int, int, int);
178 static void rbox_windowmove(struct ite_data *, int, int, int, int,
179 int, int, int);
181 /* Renaissance ite switch */
182 static struct itesw rbox_itesw = {
183 rbox_init, rbox_deinit, rbox_clear, rbox_putc,
184 rbox_cursor, rbox_scroll, ite_readbyte, ite_writeglyph
186 #endif /* NITE > 0 */
188 static int
189 rbox_intio_match(device_t parent, cfdata_t cf, void *aux)
191 struct intio_attach_args *ia = aux;
192 struct grfreg *grf;
194 if (strcmp("fb",ia->ia_modname) != 0)
195 return 0;
197 if (badaddr((void *)ia->ia_addr))
198 return 0;
200 grf = (struct grfreg *)ia->ia_addr;
202 if (grf->gr_id == DIO_DEVICE_ID_FRAMEBUFFER &&
203 grf->gr_id2 == DIO_DEVICE_SECID_RENASSIANCE) {
204 return 1;
207 return 0;
210 static void
211 rbox_intio_attach(device_t parent, device_t self, void *aux)
213 struct grfdev_softc *sc = device_private(self);
214 struct intio_attach_args *ia = aux;
215 void *grf;
217 sc->sc_dev = self;
219 grf = (void *)ia->ia_addr;
220 sc->sc_scode = -1; /* XXX internal i/o */
222 sc->sc_isconsole = (sc->sc_scode == rbconscode);
223 grfdev_attach(sc, rb_init, grf, &rbox_grfsw);
226 static int
227 rbox_dio_match(device_t parent, cfdata_t cf, void *aux)
229 struct dio_attach_args *da = aux;
231 if (da->da_id == DIO_DEVICE_ID_FRAMEBUFFER &&
232 da->da_secid == DIO_DEVICE_SECID_RENASSIANCE)
233 return 1;
235 return 0;
238 static void
239 rbox_dio_attach(device_t parent, device_t self, void *aux)
241 struct grfdev_softc *sc = device_private(self);
242 struct dio_attach_args *da = aux;
243 bus_space_handle_t bsh;
244 void *grf;
246 sc->sc_dev = self;
247 sc->sc_scode = da->da_scode;
248 if (sc->sc_scode == rbconscode)
249 grf = rbconaddr;
250 else {
251 if (bus_space_map(da->da_bst, da->da_addr, da->da_size,
252 0, &bsh)) {
253 aprint_error(": can't map framebuffer\n");
254 return;
256 grf = bus_space_vaddr(da->da_bst, bsh);
259 sc->sc_isconsole = (sc->sc_scode == rbconscode);
260 grfdev_attach(sc, rb_init, grf, &rbox_grfsw);
264 * Initialize hardware.
265 * Must point g_display at a grfinfo structure describing the hardware.
266 * Returns 0 if hardware not present, non-zero ow.
268 static int
269 rb_init(struct grf_data *gp, int scode, uint8_t *addr)
271 struct rboxfb *rbp;
272 struct grfinfo *gi = &gp->g_display;
273 int fboff;
276 * If the console has been initialized, and it was us, there's
277 * no need to repeat this.
279 if (scode != rbconscode) {
280 rbp = (struct rboxfb *)addr;
281 if (ISIIOVA(addr))
282 gi->gd_regaddr = (void *)IIOP(addr);
283 else
284 gi->gd_regaddr = dio_scodetopa(scode);
285 gi->gd_regsize = 0x20000;
286 gi->gd_fbwidth = (rbp->fbwmsb << 8) | rbp->fbwlsb;
287 gi->gd_fbheight = (rbp->fbhmsb << 8) | rbp->fbhlsb;
288 gi->gd_fbsize = gi->gd_fbwidth * gi->gd_fbheight;
289 fboff = (rbp->fbomsb << 8) | rbp->fbolsb;
290 gi->gd_fbaddr = (void *)(*(addr + fboff) << 16);
291 if ((vaddr_t)gi->gd_regaddr >= DIOIIBASE) {
293 * For DIO II space the fbaddr just computed is
294 * the offset from the select code base (regaddr)
295 * of the framebuffer. Hence it is also implicitly
296 * the size of the set.
298 gi->gd_regsize = (int)gi->gd_fbaddr;
299 gi->gd_fbaddr += (int)gi->gd_regaddr;
300 gp->g_regkva = addr;
301 gp->g_fbkva = addr + gi->gd_regsize;
302 } else {
304 * For DIO space we need to map the separate
305 * framebuffer.
307 gp->g_regkva = addr;
308 gp->g_fbkva = iomap(gi->gd_fbaddr, gi->gd_fbsize);
310 gi->gd_dwidth = (rbp->dwmsb << 8) | rbp->dwlsb;
311 gi->gd_dheight = (rbp->dwmsb << 8) | rbp->dwlsb;
312 gi->gd_planes = 0; /* ?? */
313 gi->gd_colors = 256;
315 return 1;
319 * Change the mode of the display.
320 * Right now all we can do is grfon/grfoff.
321 * Return a UNIX error number or 0 for success.
323 static int
324 rb_mode(struct grf_data *gp, int cmd, void *data)
326 struct rboxfb *rbp;
327 int error = 0;
329 rbp = (struct rboxfb *) gp->g_regkva;
330 switch (cmd) {
332 * The minimal info here is from the Renaissance X driver.
334 case GM_GRFON:
335 case GM_GRFOFF:
336 break;
338 case GM_GRFOVON:
339 rbp->write_enable = 0;
340 rbp->opwen = 0xF;
341 rbp->drive = 0x10;
342 break;
344 case GM_GRFOVOFF:
345 rbp->opwen = 0;
346 rbp->write_enable = 0xffffffff;
347 rbp->drive = 0x01;
348 break;
351 * Remember UVA of mapping for GCDESCRIBE.
352 * XXX this should be per-process.
354 case GM_MAP:
355 gp->g_data = data;
356 break;
358 case GM_UNMAP:
359 gp->g_data = 0;
360 break;
362 default:
363 error = EINVAL;
364 break;
366 return error;
369 #if NITE > 0
372 * Renaissance ite routines
375 #define REGBASE ((struct rboxfb *)(ip->regbase))
376 #define WINDOWMOVER rbox_windowmove
378 static void
379 rbox_init(struct ite_data *ip)
381 int i;
383 /* XXX */
384 if (ip->regbase == 0) {
385 struct grf_data *gp = ip->grf;
387 ip->regbase = gp->g_regkva;
388 ip->fbbase = gp->g_fbkva;
389 ip->fbwidth = gp->g_display.gd_fbwidth;
390 ip->fbheight = gp->g_display.gd_fbheight;
391 ip->dwidth = gp->g_display.gd_dwidth;
392 ip->dheight = gp->g_display.gd_dheight;
394 * XXX some displays (e.g. the davinci) appear
395 * to return a display height greater than the
396 * returned FB height. Guess we should go back
397 * to getting the display dimensions from the
398 * fontrom...
400 if (ip->dwidth > ip->fbwidth)
401 ip->dwidth = ip->fbwidth;
402 if (ip->dheight > ip->fbheight)
403 ip->dheight = ip->fbheight;
406 rb_waitbusy(ip->regbase);
408 REGBASE->reset = 0x39;
409 DELAY(1000);
411 REGBASE->interrupt = 0x04;
412 REGBASE->display_enable = 0x01;
413 REGBASE->video_enable = 0x01;
414 REGBASE->drive = 0x01;
415 REGBASE->vdrive = 0x0;
417 ite_fontinfo(ip);
419 REGBASE->opwen = 0xFF;
422 * Clear the framebuffer.
424 rbox_windowmove(ip, 0, 0, 0, 0, ip->fbheight, ip->fbwidth, RR_CLEAR);
425 rb_waitbusy(ip->regbase);
427 for(i = 0; i < 16; i++) {
428 *(ip->regbase + 0x63c3 + i*4) = 0x0;
429 *(ip->regbase + 0x6403 + i*4) = 0x0;
430 *(ip->regbase + 0x6803 + i*4) = 0x0;
431 *(ip->regbase + 0x6c03 + i*4) = 0x0;
432 *(ip->regbase + 0x73c3 + i*4) = 0x0;
433 *(ip->regbase + 0x7403 + i*4) = 0x0;
434 *(ip->regbase + 0x7803 + i*4) = 0x0;
435 *(ip->regbase + 0x7c03 + i*4) = 0x0;
438 REGBASE->rep_rule = 0x33;
441 * I cannot figure out how to make the blink planes stop. So, we
442 * must set both colormaps so that when the planes blink, and
443 * the secondary colormap is active, we still get text.
445 CM1RED[0x00].value = 0x00;
446 CM1GRN[0x00].value = 0x00;
447 CM1BLU[0x00].value = 0x00;
448 CM1RED[0x01].value = 0xFF;
449 CM1GRN[0x01].value = 0xFF;
450 CM1BLU[0x01].value = 0xFF;
452 CM2RED[0x00].value = 0x00;
453 CM2GRN[0x00].value = 0x00;
454 CM2BLU[0x00].value = 0x00;
455 CM2RED[0x01].value = 0xFF;
456 CM2GRN[0x01].value = 0xFF;
457 CM2BLU[0x01].value = 0xFF;
459 REGBASE->blink = 0x00;
460 REGBASE->write_enable = 0x01;
461 REGBASE->opwen = 0x00;
463 ite_fontinit(ip);
466 * Stash the inverted cursor.
468 rbox_windowmove(ip, charY(ip, ' '), charX(ip, ' '),
469 ip->cblanky, ip->cblankx, ip->ftheight,
470 ip->ftwidth, RR_COPYINVERTED);
473 static void
474 rbox_deinit(struct ite_data *ip)
476 rbox_windowmove(ip, 0, 0, 0, 0, ip->fbheight, ip->fbwidth, RR_CLEAR);
477 rb_waitbusy(ip->regbase);
479 ip->flags &= ~ITE_INITED;
482 static void
483 rbox_putc(struct ite_data *ip, int c, int dy, int dx, int mode)
485 int wrr = ((mode == ATTR_INV) ? RR_COPYINVERTED : RR_COPY);
487 rbox_windowmove(ip, charY(ip, c), charX(ip, c),
488 dy * ip->ftheight, dx * ip->ftwidth,
489 ip->ftheight, ip->ftwidth, wrr);
492 static void
493 rbox_cursor(struct ite_data *ip, int flag)
495 if (flag == DRAW_CURSOR)
496 draw_cursor(ip)
497 else if (flag == MOVE_CURSOR) {
498 erase_cursor(ip)
499 draw_cursor(ip)
501 else
502 erase_cursor(ip)
505 static void
506 rbox_clear(struct ite_data *ip, int sy, int sx, int h, int w)
508 rbox_windowmove(ip, sy * ip->ftheight, sx * ip->ftwidth,
509 sy * ip->ftheight, sx * ip->ftwidth,
510 h * ip->ftheight, w * ip->ftwidth,
511 RR_CLEAR);
514 static void
515 rbox_scroll(struct ite_data *ip, int sy, int sx, int count, int dir)
517 int dy;
518 int dx = sx;
519 int height = 1;
520 int width = ip->cols;
522 if (dir == SCROLL_UP) {
523 dy = sy - count;
524 height = ip->rows - sy;
526 else if (dir == SCROLL_DOWN) {
527 dy = sy + count;
528 height = ip->rows - dy - 1;
530 else if (dir == SCROLL_RIGHT) {
531 dy = sy;
532 dx = sx + count;
533 width = ip->cols - dx;
535 else {
536 dy = sy;
537 dx = sx - count;
538 width = ip->cols - sx;
541 rbox_windowmove(ip, sy * ip->ftheight, sx * ip->ftwidth,
542 dy * ip->ftheight, dx * ip->ftwidth,
543 height * ip->ftheight,
544 width * ip->ftwidth, RR_COPY);
547 static void
548 rbox_windowmove(struct ite_data *ip, int sy, int sx, int dy, int dx, int h,
549 int w, int func)
551 struct rboxfb *rp = REGBASE;
552 if (h == 0 || w == 0)
553 return;
555 rb_waitbusy(ip->regbase);
556 rp->rep_rule = func << 4 | func;
557 rp->source_y = sy;
558 rp->source_x = sx;
559 rp->dest_y = dy;
560 rp->dest_x = dx;
561 rp->wheight = h;
562 rp->wwidth = w;
563 rp->wmove = 1;
567 * Renaissance console support
570 rboxcnattach(bus_space_tag_t bst, bus_addr_t addr, int scode)
572 bus_space_handle_t bsh;
573 void *va;
574 struct grfreg *grf;
575 struct grf_data *gp = &grf_cn;
576 int size;
578 if (bus_space_map(bst, addr, PAGE_SIZE, 0, &bsh))
579 return 1;
580 va = bus_space_vaddr(bst, bsh);
581 grf = (struct grfreg *)va;
583 if (badaddr(va) ||
584 (grf->gr_id != GRFHWID) || (grf->gr_id2 != GID_RENAISSANCE)) {
585 bus_space_unmap(bst, bsh, PAGE_SIZE);
586 return 1;
589 size = DIO_SIZE(scode, va);
591 bus_space_unmap(bst, bsh, PAGE_SIZE);
592 if (bus_space_map(bst, addr, size, 0, &bsh))
593 return 1;
594 va = bus_space_vaddr(bst, bsh);
597 * Initialize the framebuffer hardware.
599 (void)rb_init(gp, scode, va);
600 rbconscode = scode;
601 rbconaddr = va;
604 * Set up required grf data.
606 gp->g_sw = &rbox_grfsw;
607 gp->g_display.gd_id = gp->g_sw->gd_swid;
608 gp->g_flags = GF_ALIVE;
611 * Initialize the terminal emulator.
613 itedisplaycnattach(gp, &rbox_itesw);
614 return 0;
617 #endif /* NITE > 0 */