Annotation of sys/arch/hp300/dev/dvbox.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: dvbox.c,v 1.13 2006/08/11 18:33:13 miod Exp $ */
! 2:
! 3: /*
! 4: * Copyright (c) 2005, Miodrag Vallat
! 5: *
! 6: * Redistribution and use in source and binary forms, with or without
! 7: * modification, are permitted provided that the following conditions
! 8: * are met:
! 9: * 1. Redistributions of source code must retain the above copyright
! 10: * notice, this list of conditions and the following disclaimer.
! 11: * 2. Redistributions in binary form must reproduce the above copyright
! 12: * notice, this list of conditions and the following disclaimer in the
! 13: * documentation and/or other materials provided with the distribution.
! 14: *
! 15: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
! 16: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
! 18: * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
! 19: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
! 20: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
! 21: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 22: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
! 23: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
! 24: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
! 25: * POSSIBILITY OF SUCH DAMAGE.
! 26: */
! 27: /*
! 28: * Copyright (c) 1996 Jason R. Thorpe. All rights reserved.
! 29: * Copyright (c) 1988 University of Utah.
! 30: * Copyright (c) 1990, 1993
! 31: * The Regents of the University of California. All rights reserved.
! 32: *
! 33: * This code is derived from software contributed to Berkeley by
! 34: * the Systems Programming Group of the University of Utah Computer
! 35: * Science Department.
! 36: *
! 37: * Redistribution and use in source and binary forms, with or without
! 38: * modification, are permitted provided that the following conditions
! 39: * are met:
! 40: * 1. Redistributions of source code must retain the above copyright
! 41: * notice, this list of conditions and the following disclaimer.
! 42: * 2. Redistributions in binary form must reproduce the above copyright
! 43: * notice, this list of conditions and the following disclaimer in the
! 44: * documentation and/or other materials provided with the distribution.
! 45: * 3. Neither the name of the University nor the names of its contributors
! 46: * may be used to endorse or promote products derived from this software
! 47: * without specific prior written permission.
! 48: *
! 49: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
! 50: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 51: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 52: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
! 53: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 54: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 55: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 56: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 57: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 58: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 59: * SUCH DAMAGE.
! 60: *
! 61: * from: Utah $Hdr: grf_dv.c 1.12 93/08/13$
! 62: *
! 63: * @(#)grf_dv.c 8.4 (Berkeley) 1/12/94
! 64: */
! 65:
! 66: /*
! 67: * Graphics routines for the DaVinci, HP98730/98731 Graphics system.
! 68: */
! 69:
! 70: #include <sys/param.h>
! 71: #include <sys/systm.h>
! 72: #include <sys/conf.h>
! 73: #include <sys/device.h>
! 74: #include <sys/proc.h>
! 75: #include <sys/ioctl.h>
! 76:
! 77: #include <machine/autoconf.h>
! 78: #include <machine/bus.h>
! 79: #include <machine/cpu.h>
! 80:
! 81: #include <hp300/dev/dioreg.h>
! 82: #include <hp300/dev/diovar.h>
! 83: #include <hp300/dev/diodevs.h>
! 84: #include <hp300/dev/intiovar.h>
! 85:
! 86: #include <dev/wscons/wsconsio.h>
! 87: #include <dev/wscons/wsdisplayvar.h>
! 88: #include <dev/rasops/rasops.h>
! 89:
! 90: #include <hp300/dev/diofbreg.h>
! 91: #include <hp300/dev/diofbvar.h>
! 92: #include <hp300/dev/dvboxreg.h>
! 93:
! 94: struct dvbox_softc {
! 95: struct device sc_dev;
! 96: struct diofb *sc_fb;
! 97: struct diofb sc_fb_store;
! 98: int sc_scode;
! 99: };
! 100:
! 101: int dvbox_dio_match(struct device *, void *, void *);
! 102: void dvbox_dio_attach(struct device *, struct device *, void *);
! 103: int dvbox_intio_match(struct device *, void *, void *);
! 104: void dvbox_intio_attach(struct device *, struct device *, void *);
! 105:
! 106: struct cfattach dvbox_dio_ca = {
! 107: sizeof(struct dvbox_softc), dvbox_dio_match, dvbox_dio_attach
! 108: };
! 109:
! 110: struct cfattach dvbox_intio_ca = {
! 111: sizeof(struct dvbox_softc), dvbox_intio_match, dvbox_intio_attach
! 112: };
! 113:
! 114: struct cfdriver dvbox_cd = {
! 115: NULL, "dvbox", DV_DULL
! 116: };
! 117:
! 118: int dvbox_reset(struct diofb *, int, struct diofbreg *);
! 119: void dvbox_restore(struct diofb *);
! 120: void dvbox_setcolor(struct diofb *, u_int,
! 121: u_int8_t, u_int8_t, u_int8_t);
! 122: int dvbox_windowmove(struct diofb *, u_int16_t, u_int16_t, u_int16_t,
! 123: u_int16_t, u_int16_t, u_int16_t, int16_t, int16_t);
! 124:
! 125: int dvbox_ioctl(void *, u_long, caddr_t, int, struct proc *);
! 126: void dvbox_burner(void *, u_int, u_int);
! 127:
! 128: struct wsdisplay_accessops dvbox_accessops = {
! 129: dvbox_ioctl,
! 130: diofb_mmap,
! 131: diofb_alloc_screen,
! 132: diofb_free_screen,
! 133: diofb_show_screen,
! 134: NULL, /* load_font */
! 135: NULL, /* scrollback */
! 136: NULL, /* getchar */
! 137: dvbox_burner
! 138: };
! 139:
! 140: /*
! 141: * Attachment glue
! 142: */
! 143:
! 144: int
! 145: dvbox_intio_match(struct device *parent, void *match, void *aux)
! 146: {
! 147: struct intio_attach_args *ia = aux;
! 148: struct diofbreg *fbr;
! 149:
! 150: fbr = (struct diofbreg *)IIOV(GRFIADDR);
! 151:
! 152: if (badaddr((caddr_t)fbr))
! 153: return (0);
! 154:
! 155: if (fbr->id == GRFHWID && fbr->fbid == GID_DAVINCI) {
! 156: ia->ia_addr = (caddr_t)GRFIADDR;
! 157: return (1);
! 158: }
! 159:
! 160: return (0);
! 161: }
! 162:
! 163: void
! 164: dvbox_intio_attach(struct device *parent, struct device *self, void *aux)
! 165: {
! 166: struct dvbox_softc *sc = (struct dvbox_softc *)self;
! 167: struct diofbreg *fbr;
! 168:
! 169: fbr = (struct diofbreg *)IIOV(GRFIADDR);
! 170: sc->sc_scode = CONSCODE_INTERNAL;
! 171:
! 172: if (sc->sc_scode == conscode) {
! 173: sc->sc_fb = &diofb_cn;
! 174: } else {
! 175: sc->sc_fb = &sc->sc_fb_store;
! 176: dvbox_reset(sc->sc_fb, sc->sc_scode, fbr);
! 177: }
! 178:
! 179: diofb_end_attach(sc, &dvbox_accessops, sc->sc_fb,
! 180: sc->sc_scode == conscode, NULL);
! 181: }
! 182:
! 183: int
! 184: dvbox_dio_match(struct device *parent, void *match, void *aux)
! 185: {
! 186: struct dio_attach_args *da = aux;
! 187:
! 188: if (da->da_id == DIO_DEVICE_ID_FRAMEBUFFER &&
! 189: da->da_secid == DIO_DEVICE_SECID_DAVINCI)
! 190: return (1);
! 191:
! 192: return (0);
! 193: }
! 194:
! 195: void
! 196: dvbox_dio_attach(struct device *parent, struct device *self, void *aux)
! 197: {
! 198: struct dvbox_softc *sc = (struct dvbox_softc *)self;
! 199: struct dio_attach_args *da = aux;
! 200: struct diofbreg *fbr;
! 201:
! 202: sc->sc_scode = da->da_scode;
! 203: if (sc->sc_scode == conscode) {
! 204: fbr = (struct diofbreg *)conaddr; /* already mapped */
! 205: sc->sc_fb = &diofb_cn;
! 206: } else {
! 207: sc->sc_fb = &sc->sc_fb_store;
! 208: fbr = (struct diofbreg *)
! 209: iomap(dio_scodetopa(sc->sc_scode), da->da_size);
! 210: if (fbr == NULL ||
! 211: dvbox_reset(sc->sc_fb, sc->sc_scode, fbr) != 0) {
! 212: printf(": can't map framebuffer\n");
! 213: return;
! 214: }
! 215: }
! 216:
! 217: diofb_end_attach(sc, &dvbox_accessops, sc->sc_fb,
! 218: sc->sc_scode == conscode, NULL);
! 219: }
! 220:
! 221: /*
! 222: * Initialize hardware and display routines.
! 223: */
! 224: int
! 225: dvbox_reset(struct diofb *fb, int scode, struct diofbreg *fbr)
! 226: {
! 227: int rc;
! 228:
! 229: if ((rc = diofb_fbinquire(fb, scode, fbr)) != 0)
! 230: return (rc);
! 231:
! 232: /*
! 233: * Restrict the framebuffer to a monochrome view for now, until
! 234: * I know better how to detect and frob overlay planes, and
! 235: * setup a proper colormap. -- miod
! 236: */
! 237: fb->planes = fb->planemask = 1;
! 238:
! 239: fb->bmv = dvbox_windowmove;
! 240: dvbox_restore(fb);
! 241: diofb_fbsetup(fb);
! 242:
! 243: return (0);
! 244: }
! 245:
! 246: /*
! 247: * Magic initialization code.
! 248: */
! 249: void
! 250: dvbox_restore(struct diofb *fb)
! 251: {
! 252: volatile struct dvboxfb *db = (struct dvboxfb *)fb->regkva;
! 253: u_int i;
! 254:
! 255: db->regs.id = 0x80;
! 256: DELAY(100);
! 257:
! 258: db->regs.interrupt = 0x04;
! 259: db->en_scan = 0x01;
! 260: db->fbwen = ~0;
! 261: db->opwen = ~0;
! 262: db->fold = 0x01; /* 8bpp */
! 263: db->drive = 0x01; /* use FB plane */
! 264: db->rep_rule = DVBOX_DUALROP(RR_COPY);
! 265: db->alt_rr = DVBOX_DUALROP(RR_COPY);
! 266: db->zrr = DVBOX_DUALROP(RR_COPY);
! 267:
! 268: db->fbvenp = 0xFF; /* enable video */
! 269: db->dispen = 0x01; /* enable display */
! 270: db->fbvens = 0x0;
! 271: db->fv_trig = 0x01;
! 272: DELAY(100);
! 273: db->vdrive = 0x0;
! 274: db->zconfig = 0x0;
! 275:
! 276: while (db->wbusy & 0x01)
! 277: DELAY(10);
! 278:
! 279: db->cmapbank = 0;
! 280:
! 281: db->red0 = 0;
! 282: db->red1 = 0;
! 283: db->green0 = 0;
! 284: db->green1 = 0;
! 285: db->blue0 = 0;
! 286: db->blue1 = 0;
! 287:
! 288: db->panxh = 0;
! 289: db->panxl = 0;
! 290: db->panyh = 0;
! 291: db->panyl = 0;
! 292: db->zoom = 0;
! 293: db->cdwidth = 0x50;
! 294: db->chstart = 0x52;
! 295: db->cvwidth = 0x22;
! 296: db->pz_trig = 1;
! 297:
! 298: /*
! 299: * Turn on frame buffer, turn on overlay planes, set replacement
! 300: * rule, enable top overlay plane writes for ite, disable all frame
! 301: * buffer planes, set byte per pixel, and display frame buffer 0.
! 302: * Lastly, turn on the box.
! 303: */
! 304: db->regs.interrupt = 0x04;
! 305: db->drive = 0x10;
! 306: db->rep_rule = DVBOX_DUALROP(RR_COPY);
! 307: db->opwen = 0x01;
! 308: db->fbwen = 0x0;
! 309: db->fold = 0x01;
! 310: db->vdrive = 0x0;
! 311: db->dispen = 0x01;
! 312:
! 313: /*
! 314: * Video enable top overlay plane.
! 315: */
! 316: db->opvenp = 0x01;
! 317: db->opvens = 0x01;
! 318:
! 319: /*
! 320: * Make sure that overlay planes override frame buffer planes.
! 321: */
! 322: db->ovly0p = 0x0;
! 323: db->ovly0s = 0x0;
! 324: db->ovly1p = 0x0;
! 325: db->ovly1s = 0x0;
! 326: db->fv_trig = 0x1;
! 327: DELAY(100);
! 328:
! 329: /*
! 330: * Setup the overlay colormaps. Need to set the 0,1 (black/white)
! 331: * color for both banks.
! 332: */
! 333: db_waitbusy(db);
! 334: for (i = 0; i <= 1; i++) {
! 335: db->cmapbank = i;
! 336: db->rgb[0].red = 0x00;
! 337: db->rgb[0].green = 0x00;
! 338: db->rgb[0].blue = 0x00;
! 339: db->rgb[1].red = 0xff;
! 340: db->rgb[1].green = 0xff;
! 341: db->rgb[1].blue = 0xff;
! 342: }
! 343: db->cmapbank = 0;
! 344: db_waitbusy(db);
! 345: }
! 346:
! 347: int
! 348: dvbox_ioctl(void *v, u_long cmd, caddr_t data, int flags, struct proc *p)
! 349: {
! 350: struct diofb *fb = v;
! 351: struct wsdisplay_fbinfo *wdf;
! 352:
! 353: switch (cmd) {
! 354: case WSDISPLAYIO_GTYPE:
! 355: *(u_int *)data = WSDISPLAY_TYPE_DVBOX;
! 356: break;
! 357: case WSDISPLAYIO_SMODE:
! 358: fb->mapmode = *(u_int *)data;
! 359: if (fb->mapmode == WSDISPLAYIO_MODE_EMUL)
! 360: dvbox_restore(fb);
! 361: break;
! 362: case WSDISPLAYIO_GINFO:
! 363: wdf = (void *)data;
! 364: wdf->width = fb->ri.ri_width;
! 365: wdf->height = fb->ri.ri_height;
! 366: wdf->depth = fb->ri.ri_depth;
! 367: wdf->cmsize = 0; /* XXX */
! 368: break;
! 369: case WSDISPLAYIO_LINEBYTES:
! 370: *(u_int *)data = fb->ri.ri_stride;
! 371: break;
! 372: case WSDISPLAYIO_GETCMAP:
! 373: case WSDISPLAYIO_PUTCMAP:
! 374: break; /* XXX until color support is implemented */
! 375: case WSDISPLAYIO_GVIDEO:
! 376: case WSDISPLAYIO_SVIDEO:
! 377: break;
! 378: default:
! 379: return (-1);
! 380: }
! 381:
! 382: return (0);
! 383: }
! 384:
! 385: void
! 386: dvbox_burner(void *v, u_int on, u_int flags)
! 387: {
! 388: struct diofb *fb = v;
! 389: volatile struct dvboxfb *db = (struct dvboxfb *)fb->regkva;
! 390:
! 391: if (on)
! 392: db->dispen = 0x01;
! 393: else
! 394: db->dispen = 0x00;
! 395: }
! 396:
! 397: int
! 398: dvbox_windowmove(struct diofb *fb, u_int16_t sx, u_int16_t sy,
! 399: u_int16_t dx, u_int16_t dy, u_int16_t cx, u_int16_t cy, int16_t rop,
! 400: int16_t planemask)
! 401: {
! 402: volatile struct dvboxfb *db = (struct dvboxfb *)fb->regkva;
! 403:
! 404: if (planemask != 0xff)
! 405: return (EINVAL);
! 406:
! 407: db_waitbusy(db);
! 408:
! 409: db->rep_rule = DVBOX_DUALROP(rop);
! 410: db->source_y = sy;
! 411: db->source_x = sx;
! 412: db->dest_y = dy;
! 413: db->dest_x = dx;
! 414: db->wheight = cy;
! 415: db->wwidth = cx;
! 416: db->wmove = 1;
! 417:
! 418: db_waitbusy(db);
! 419:
! 420: return (0);
! 421: }
! 422:
! 423: /*
! 424: * DaVinci console support
! 425: */
! 426:
! 427: void
! 428: dvboxcninit()
! 429: {
! 430: dvbox_reset(&diofb_cn, conscode, (struct diofbreg *)conaddr);
! 431: diofb_cnattach(&diofb_cn);
! 432: }
CVSweb