141480Smckusick /* 241480Smckusick * Copyright (c) 1988 University of Utah. 3*63151Sbostic * Copyright (c) 1990, 1993 4*63151Sbostic * The Regents of the University of California. 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 * 1253929Shibler * from: Utah $Hdr: grf_gb.c 1.17 92/01/21$ 1341480Smckusick * 14*63151Sbostic * @(#)grf_gb.c 8.1 (Berkeley) 06/10/93 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 */ 2756507Sbostic #include <sys/param.h> 2856507Sbostic #include <sys/errno.h> 2941480Smckusick 3056507Sbostic #include <hp/dev/grfioctl.h> 3156507Sbostic #include <hp/dev/grfvar.h> 3241480Smckusick 3356507Sbostic #include <hp300/dev/grf_gbreg.h> 3456507Sbostic #include <machine/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; 4949312Shibler caddr_t addr; 5041480Smckusick { 5141480Smckusick register struct gboxfb *gbp; 5241480Smckusick struct grfinfo *gi = &gp->g_display; 5341480Smckusick u_char *fbp, save; 5441480Smckusick int fboff; 5549312Shibler extern caddr_t sctopa(), iomap(); 5641480Smckusick 5741480Smckusick gbp = (struct gboxfb *) addr; 5849312Shibler if (ISIIOVA(addr)) 5949312Shibler gi->gd_regaddr = (caddr_t) IIOP(addr); 6049312Shibler else 6149312Shibler gi->gd_regaddr = sctopa(vatosc(addr)); 6241480Smckusick gi->gd_regsize = 0x10000; 6341480Smckusick gi->gd_fbwidth = 1024; /* XXX */ 6441480Smckusick gi->gd_fbheight = 1024; /* XXX */ 6549312Shibler gi->gd_fbsize = gi->gd_fbwidth * gi->gd_fbheight; 6641480Smckusick fboff = (gbp->fbomsb << 8) | gbp->fbolsb; 6749312Shibler gi->gd_fbaddr = (caddr_t) (*((u_char *)addr + fboff) << 16); 6849312Shibler gp->g_regkva = addr; 6949312Shibler gp->g_fbkva = iomap(gi->gd_fbaddr, gi->gd_fbsize); 7041480Smckusick gi->gd_dwidth = 1024; /* XXX */ 7141480Smckusick gi->gd_dheight = 768; /* XXX */ 7241480Smckusick gi->gd_planes = 0; /* how do we do this? */ 7341480Smckusick /* 7441480Smckusick * The minimal register info here is from the Gatorbox X driver. 7541480Smckusick */ 7649312Shibler fbp = (u_char *) gp->g_fbkva; 7741480Smckusick gbp->write_protect = 0; 7841480Smckusick gbp->interrupt = 4; /** fb_enable ? **/ 7941480Smckusick gbp->rep_rule = 3; /* GXcopy */ 8041480Smckusick gbp->blink1 = 0xff; 8141480Smckusick gbp->blink2 = 0xff; 8241480Smckusick 8341480Smckusick gb_microcode(gbp); 8441480Smckusick 8541480Smckusick /* 8641480Smckusick * Find out how many colors are available by determining 8741480Smckusick * which planes are installed. That is, write all ones to 8841480Smckusick * a frame buffer location, see how many ones are read back. 8941480Smckusick */ 9041480Smckusick save = *fbp; 9141480Smckusick *fbp = 0xFF; 9241480Smckusick gi->gd_colors = *fbp + 1; 9341480Smckusick *fbp = save; 9441480Smckusick return(1); 9541480Smckusick } 9641480Smckusick 9741480Smckusick /* 9841480Smckusick * Program the 6845. 9941480Smckusick */ 10041480Smckusick gb_microcode(gbp) 10141480Smckusick register struct gboxfb *gbp; 10241480Smckusick { 10341480Smckusick register int i; 10441480Smckusick 10541480Smckusick for (i = 0; i < CRTC_DATA_LENGTH; i++) { 10641480Smckusick gbp->crtc_address = i; 10741480Smckusick gbp->crtc_data = crtc_init_data[i]; 10841480Smckusick } 10941480Smckusick } 11041480Smckusick 11141480Smckusick /* 11241480Smckusick * Change the mode of the display. 11341480Smckusick * Right now all we can do is grfon/grfoff. 11441480Smckusick * Return a UNIX error number or 0 for success. 11541480Smckusick */ 11641480Smckusick gb_mode(gp, cmd) 11741480Smckusick register struct grf_softc *gp; 11841480Smckusick { 11941480Smckusick struct gboxfb *gbp; 12041480Smckusick int error = 0; 12141480Smckusick 12249312Shibler gbp = (struct gboxfb *) gp->g_regkva; 12341480Smckusick switch (cmd) { 12441480Smckusick case GM_GRFON: 12541480Smckusick gbp->sec_interrupt = 1; 12641480Smckusick break; 12741480Smckusick case GM_GRFOFF: 12841480Smckusick break; 12941480Smckusick default: 13041480Smckusick error = EINVAL; 13141480Smckusick break; 13241480Smckusick } 13341480Smckusick return(error); 13441480Smckusick } 13541480Smckusick 13641480Smckusick #endif 137