141480Smckusick /* 241480Smckusick * Copyright (c) 1988 University of Utah. 341480Smckusick * Copyright (c) 1990 The Regents of the University of California. 441480Smckusick * All rights reserved. 541480Smckusick * 641480Smckusick * This code is derived from software contributed to Berkeley by 741480Smckusick * the Systems Programming Group of the University of Utah Computer 841480Smckusick * Science Department. 941480Smckusick * 1041480Smckusick * %sccs.include.redist.c% 1141480Smckusick * 1245490Smckusick * from: Utah $Hdr: grf_gb.c 1.1 90/07/09$ 1341480Smckusick * 14*45788Sbostic * @(#)grf_gb.c 7.3 (Berkeley) 12/16/90 1541480Smckusick */ 1641480Smckusick 1741480Smckusick #include "grf.h" 1841480Smckusick #if NGRF > 0 1941480Smckusick 2041480Smckusick /* 2141480Smckusick * Graphics routines for the Gatorbox. 2241480Smckusick * 2341480Smckusick * Note: In the context of this system, "gator" and "gatorbox" both refer to 2441480Smckusick * HP 987x0 graphics systems. "Gator" is not used for high res mono. 2541480Smckusick * (as in 9837 Gator systems) 2641480Smckusick */ 27*45788Sbostic #include "sys/param.h" 28*45788Sbostic #include "sys/errno.h" 2941480Smckusick 3041480Smckusick #include "grfioctl.h" 3141480Smckusick #include "grfvar.h" 3241480Smckusick #include "grf_gbreg.h" 3341480Smckusick 34*45788Sbostic #include "../include/cpu.h" 3541480Smckusick 3641480Smckusick #define CRTC_DATA_LENGTH 0x0e 3741480Smckusick u_char crtc_init_data[CRTC_DATA_LENGTH] = { 3841480Smckusick 0x29, 0x20, 0x23, 0x04, 0x30, 0x0b, 0x30, 3941480Smckusick 0x30, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00 4041480Smckusick }; 4141480Smckusick 4241480Smckusick /* 4341480Smckusick * Initialize hardware. 4441480Smckusick * Must point g_display at a grfinfo structure describing the hardware. 4541480Smckusick * Returns 0 if hardware not present, non-zero ow. 4641480Smckusick */ 4741480Smckusick gb_init(gp, addr) 4841480Smckusick struct grf_softc *gp; 4941480Smckusick u_char *addr; 5041480Smckusick { 5141480Smckusick register struct gboxfb *gbp; 5241480Smckusick struct grfinfo *gi = &gp->g_display; 5341480Smckusick u_char *fbp, save; 5441480Smckusick int fboff; 5541480Smckusick 5641480Smckusick gbp = (struct gboxfb *) addr; 5741480Smckusick gi->gd_regaddr = (caddr_t) UNIOV(addr); 5841480Smckusick gi->gd_regsize = 0x10000; 5941480Smckusick gi->gd_fbwidth = 1024; /* XXX */ 6041480Smckusick gi->gd_fbheight = 1024; /* XXX */ 6141480Smckusick fboff = (gbp->fbomsb << 8) | gbp->fbolsb; 6241480Smckusick gi->gd_fbaddr = (caddr_t) (*(addr + fboff) << 16); 6341480Smckusick gi->gd_fbsize = gi->gd_fbwidth * gi->gd_fbheight; 6441480Smckusick gi->gd_dwidth = 1024; /* XXX */ 6541480Smckusick gi->gd_dheight = 768; /* XXX */ 6641480Smckusick gi->gd_planes = 0; /* how do we do this? */ 6741480Smckusick /* 6841480Smckusick * The minimal register info here is from the Gatorbox X driver. 6941480Smckusick */ 7041480Smckusick fbp = (u_char *) IOV(gi->gd_fbaddr); 7141480Smckusick gbp->write_protect = 0; 7241480Smckusick gbp->interrupt = 4; /** fb_enable ? **/ 7341480Smckusick gbp->rep_rule = 3; /* GXcopy */ 7441480Smckusick gbp->blink1 = 0xff; 7541480Smckusick gbp->blink2 = 0xff; 7641480Smckusick 7741480Smckusick gb_microcode(gbp); 7841480Smckusick 7941480Smckusick /* 8041480Smckusick * Find out how many colors are available by determining 8141480Smckusick * which planes are installed. That is, write all ones to 8241480Smckusick * a frame buffer location, see how many ones are read back. 8341480Smckusick */ 8441480Smckusick save = *fbp; 8541480Smckusick *fbp = 0xFF; 8641480Smckusick gi->gd_colors = *fbp + 1; 8741480Smckusick *fbp = save; 8841480Smckusick return(1); 8941480Smckusick } 9041480Smckusick 9141480Smckusick /* 9241480Smckusick * Program the 6845. 9341480Smckusick */ 9441480Smckusick gb_microcode(gbp) 9541480Smckusick register struct gboxfb *gbp; 9641480Smckusick { 9741480Smckusick register int i; 9841480Smckusick 9941480Smckusick for (i = 0; i < CRTC_DATA_LENGTH; i++) { 10041480Smckusick gbp->crtc_address = i; 10141480Smckusick gbp->crtc_data = crtc_init_data[i]; 10241480Smckusick } 10341480Smckusick } 10441480Smckusick 10541480Smckusick /* 10641480Smckusick * Change the mode of the display. 10741480Smckusick * Right now all we can do is grfon/grfoff. 10841480Smckusick * Return a UNIX error number or 0 for success. 10941480Smckusick */ 11041480Smckusick gb_mode(gp, cmd) 11141480Smckusick register struct grf_softc *gp; 11241480Smckusick { 11341480Smckusick struct gboxfb *gbp; 11441480Smckusick int error = 0; 11541480Smckusick 11641480Smckusick gbp = (struct gboxfb *) IOV(gp->g_display.gd_regaddr); 11741480Smckusick switch (cmd) { 11841480Smckusick case GM_GRFON: 11941480Smckusick gbp->sec_interrupt = 1; 12041480Smckusick break; 12141480Smckusick case GM_GRFOFF: 12241480Smckusick break; 12341480Smckusick default: 12441480Smckusick error = EINVAL; 12541480Smckusick break; 12641480Smckusick } 12741480Smckusick return(error); 12841480Smckusick } 12941480Smckusick 13041480Smckusick #endif 131