Home | History | Annotate | Line # | Download | only in dev
grf_gv.c revision 1.14.8.1
      1  1.14.8.1    jruoho /*	$NetBSD: grf_gv.c,v 1.14.8.1 2011/06/06 09:07:01 jruoho Exp $	*/
      2       1.1       oki 
      3       1.1       oki /*
      4  1.14.8.1    jruoho  * Copyright (c) 1988 University of Utah.
      5       1.1       oki  * Copyright (c) 1990, 1993
      6       1.1       oki  *	The Regents of the University of California.  All rights reserved.
      7       1.1       oki  *
      8       1.1       oki  * This code is derived from software contributed to Berkeley by
      9       1.1       oki  * the Systems Programming Group of the University of Utah Computer
     10       1.1       oki  * Science Department.
     11       1.1       oki  *
     12       1.1       oki  * Redistribution and use in source and binary forms, with or without
     13       1.1       oki  * modification, are permitted provided that the following conditions
     14       1.1       oki  * are met:
     15       1.1       oki  * 1. Redistributions of source code must retain the above copyright
     16       1.1       oki  *    notice, this list of conditions and the following disclaimer.
     17       1.1       oki  * 2. Redistributions in binary form must reproduce the above copyright
     18       1.1       oki  *    notice, this list of conditions and the following disclaimer in the
     19       1.1       oki  *    documentation and/or other materials provided with the distribution.
     20       1.8       agc  * 3. Neither the name of the University nor the names of its contributors
     21       1.8       agc  *    may be used to endorse or promote products derived from this software
     22       1.8       agc  *    without specific prior written permission.
     23       1.8       agc  *
     24       1.8       agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25       1.8       agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26       1.8       agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27       1.8       agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28       1.8       agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29       1.8       agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30       1.8       agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31       1.8       agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32       1.8       agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33       1.8       agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34       1.8       agc  * SUCH DAMAGE.
     35       1.8       agc  *
     36       1.8       agc  * from: Utah $Hdr: grf_tc.c 1.20 93/08/13$
     37       1.8       agc  *
     38       1.8       agc  *	@(#)grf_tc.c	8.4 (Berkeley) 1/12/94
     39       1.8       agc  */
     40       1.1       oki 
     41       1.1       oki /*
     42       1.1       oki  * Graphics routines for the X68K native custom chip set.
     43       1.1       oki  */
     44       1.7     lukem 
     45       1.7     lukem #include <sys/cdefs.h>
     46  1.14.8.1    jruoho __KERNEL_RCSID(0, "$NetBSD: grf_gv.c,v 1.14.8.1 2011/06/06 09:07:01 jruoho Exp $");
     47       1.4   thorpej 
     48       1.1       oki #include <sys/param.h>
     49       1.1       oki #include <sys/device.h>
     50       1.1       oki #include <sys/errno.h>
     51       1.1       oki 
     52      1.14     isaki #include <machine/cpu.h>
     53       1.5   minoura #include <machine/grfioctl.h>
     54       1.5   minoura 
     55       1.1       oki #include <x68k/dev/grfvar.h>
     56       1.1       oki #include <x68k/x68k/iodevice.h>
     57       1.1       oki 
     58      1.12  christos int gv_init(struct grf_softc *, void *);
     59      1.12  christos int gv_mode(struct grf_softc *, u_long, void *);
     60       1.1       oki 
     61       1.1       oki /* Initialize hardware.
     62       1.1       oki  * Must fill in the grfinfo structure in g_softc.
     63       1.1       oki  * Returns 0 if hardware not present, non-zero ow.
     64       1.1       oki  */
     65       1.2       oki int
     66      1.12  christos gv_init(struct grf_softc *gp, void *addr)
     67       1.1       oki {
     68       1.1       oki 	struct grfinfo *gi = &gp->g_display;
     69       1.1       oki 
     70       1.1       oki 	gi->gd_fbwidth  = 1024;
     71       1.1       oki 	gi->gd_fbheight = 1024;
     72       1.1       oki 	gi->gd_planes  = 4;
     73       1.1       oki 	gi->gd_regaddr = (void *)0x00e80000;
     74       1.1       oki 	gi->gd_regsize = 0x00010000;  /* contains system port */
     75       1.1       oki 	gi->gd_fbaddr  = (void *)0x00c00000;
     76       1.1       oki 	gi->gd_fbsize  = gi->gd_fbwidth * gi->gd_fbheight * 2;
     77       1.1       oki 	gp->g_regkva   = addr;
     78       1.1       oki 	gp->g_fbkva    = addr;
     79       1.1       oki 	switch(IODEVbase->io_sram[0x1d]) {
     80       1.1       oki 	case 18:
     81       1.1       oki 		/*
     82       1.1       oki 		 * mode 18, 24kHz
     83       1.1       oki 		 */
     84       1.1       oki 		gi->gd_dwidth  = 1024;
     85       1.1       oki 		gi->gd_dheight =  848;
     86       1.1       oki 		break;
     87       1.1       oki 	case 19:
     88       1.1       oki 		/*
     89       1.1       oki 		 * mode 19, 31kHz VGA mode
     90       1.1       oki 		 */
     91       1.1       oki 		gi->gd_dwidth  = 640;
     92       1.1       oki 		gi->gd_dheight = 480;
     93       1.1       oki 		break;
     94       1.1       oki 	default:
     95       1.1       oki 		/*
     96       1.1       oki 		 * mode 16, 31kHz (default)
     97       1.1       oki 		 */
     98       1.1       oki 		gi->gd_dwidth  = 768;
     99       1.1       oki 		gi->gd_dheight = 512;
    100       1.1       oki 		break;
    101       1.1       oki 	}
    102       1.1       oki 	gi->gd_colors  = 16;
    103       1.1       oki 
    104       1.9   minoura 	return 1;
    105       1.1       oki }
    106       1.1       oki 
    107       1.1       oki /*
    108       1.1       oki  * Change the mode of the display.
    109       1.1       oki  * Right now all we can do is grfon/grfoff.
    110       1.1       oki  * Return a UNIX error number or 0 for success.
    111       1.1       oki  */
    112       1.1       oki /*ARGSUSED*/
    113       1.2       oki int
    114      1.12  christos gv_mode(struct grf_softc *gp, u_long cmd, void *data)
    115       1.1       oki {
    116       1.1       oki 	int error = 0;
    117       1.1       oki 
    118       1.1       oki 	switch (cmd) {
    119       1.1       oki 	case GM_GRFON:
    120       1.1       oki 	case GM_GRFOFF:
    121       1.1       oki 		break;
    122       1.1       oki 
    123       1.1       oki 	/*
    124       1.1       oki 	 * Remember UVA of mapping for GCDESCRIBE.
    125       1.1       oki 	 * XXX this should be per-process.
    126       1.1       oki 	 */
    127       1.1       oki 	case GM_MAP:
    128       1.1       oki 		gp->g_data = data;
    129       1.1       oki 		break;
    130       1.1       oki 
    131       1.1       oki 	case GM_UNMAP:
    132       1.1       oki 		gp->g_data = 0;
    133       1.1       oki 		break;
    134       1.1       oki 
    135       1.1       oki 	case GM_GRFSETVMODE:
    136       1.1       oki 		if (*(int *)data == 1) {
    137       1.1       oki 			struct grfinfo *gi = &gp->g_display;
    138       1.1       oki 			volatile struct crtc *crtc = &IODEVbase->io_crtc;
    139       1.9   minoura 			/* Reset CRTC, set dwidth and dheight accordingly */
    140       1.1       oki 			crtc->r20 = (crtc->r20 & 0xFF00) | 0x1a;
    141       1.1       oki 			crtc->r08 = 0x1b;
    142       1.1       oki 			crtc->r07 = 0x19c;
    143       1.1       oki 			crtc->r06 = 0x1c;
    144       1.1       oki 			crtc->r05 = 0x02;
    145       1.1       oki 			crtc->r04 = 0x019f;
    146       1.1       oki 			crtc->r03 = 0x9a;
    147       1.1       oki 			crtc->r02 = 0x1a;
    148       1.1       oki 			crtc->r01 = 0x09;
    149       1.1       oki 			crtc->r00 = 0xa4;
    150       1.1       oki 			gi->gd_dwidth = 1024;
    151       1.1       oki 			gi->gd_dheight = 768;
    152       1.1       oki 		}
    153       1.1       oki 		break;
    154       1.1       oki 
    155       1.1       oki 	default:
    156       1.1       oki 		error = EINVAL;
    157       1.1       oki 		break;
    158       1.1       oki 	}
    159       1.9   minoura 	return error;
    160       1.1       oki }
    161