1*8ac3875aSrmind /* $NetBSD: grf_gv.c,v 1.15 2011/02/08 20:20:25 rmind Exp $ */
2320e7320Soki
3320e7320Soki /*
4*8ac3875aSrmind * Copyright (c) 1988 University of Utah.
5320e7320Soki * Copyright (c) 1990, 1993
6320e7320Soki * The Regents of the University of California. All rights reserved.
7320e7320Soki *
8320e7320Soki * This code is derived from software contributed to Berkeley by
9320e7320Soki * the Systems Programming Group of the University of Utah Computer
10320e7320Soki * Science Department.
11320e7320Soki *
12320e7320Soki * Redistribution and use in source and binary forms, with or without
13320e7320Soki * modification, are permitted provided that the following conditions
14320e7320Soki * are met:
15320e7320Soki * 1. Redistributions of source code must retain the above copyright
16320e7320Soki * notice, this list of conditions and the following disclaimer.
17320e7320Soki * 2. Redistributions in binary form must reproduce the above copyright
18320e7320Soki * notice, this list of conditions and the following disclaimer in the
19320e7320Soki * documentation and/or other materials provided with the distribution.
20aad01611Sagc * 3. Neither the name of the University nor the names of its contributors
21aad01611Sagc * may be used to endorse or promote products derived from this software
22aad01611Sagc * without specific prior written permission.
23aad01611Sagc *
24aad01611Sagc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25aad01611Sagc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26aad01611Sagc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27aad01611Sagc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28aad01611Sagc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29aad01611Sagc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30aad01611Sagc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31aad01611Sagc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32aad01611Sagc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33aad01611Sagc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34aad01611Sagc * SUCH DAMAGE.
35aad01611Sagc *
36aad01611Sagc * from: Utah $Hdr: grf_tc.c 1.20 93/08/13$
37aad01611Sagc *
38aad01611Sagc * @(#)grf_tc.c 8.4 (Berkeley) 1/12/94
39aad01611Sagc */
40320e7320Soki
41320e7320Soki /*
42320e7320Soki * Graphics routines for the X68K native custom chip set.
43320e7320Soki */
4437b378d8Sthorpej
45ab48a212Slukem #include <sys/cdefs.h>
46*8ac3875aSrmind __KERNEL_RCSID(0, "$NetBSD: grf_gv.c,v 1.15 2011/02/08 20:20:25 rmind Exp $");
4737b378d8Sthorpej
48320e7320Soki #include <sys/param.h>
49320e7320Soki #include <sys/device.h>
50320e7320Soki #include <sys/errno.h>
51320e7320Soki
528ca78cfbSisaki #include <machine/cpu.h>
53d082dd3dSminoura #include <machine/grfioctl.h>
54d082dd3dSminoura
55320e7320Soki #include <x68k/dev/grfvar.h>
56320e7320Soki #include <x68k/x68k/iodevice.h>
57320e7320Soki
5853524e44Schristos int gv_init(struct grf_softc *, void *);
5953524e44Schristos int gv_mode(struct grf_softc *, u_long, void *);
6094186152Soki
61320e7320Soki /* Initialize hardware.
62320e7320Soki * Must fill in the grfinfo structure in g_softc.
63320e7320Soki * Returns 0 if hardware not present, non-zero ow.
64320e7320Soki */
658823c49fSoki int
gv_init(struct grf_softc * gp,void * addr)6653524e44Schristos gv_init(struct grf_softc *gp, void *addr)
67320e7320Soki {
68320e7320Soki struct grfinfo *gi = &gp->g_display;
69320e7320Soki
70320e7320Soki gi->gd_fbwidth = 1024;
71320e7320Soki gi->gd_fbheight = 1024;
72320e7320Soki gi->gd_planes = 4;
73320e7320Soki gi->gd_regaddr = (void *)0x00e80000;
74320e7320Soki gi->gd_regsize = 0x00010000; /* contains system port */
75320e7320Soki gi->gd_fbaddr = (void *)0x00c00000;
76320e7320Soki gi->gd_fbsize = gi->gd_fbwidth * gi->gd_fbheight * 2;
77320e7320Soki gp->g_regkva = addr;
78320e7320Soki gp->g_fbkva = addr;
79320e7320Soki switch(IODEVbase->io_sram[0x1d]) {
80320e7320Soki case 18:
81320e7320Soki /*
82320e7320Soki * mode 18, 24kHz
83320e7320Soki */
84320e7320Soki gi->gd_dwidth = 1024;
85320e7320Soki gi->gd_dheight = 848;
86320e7320Soki break;
87320e7320Soki case 19:
88320e7320Soki /*
89320e7320Soki * mode 19, 31kHz VGA mode
90320e7320Soki */
91320e7320Soki gi->gd_dwidth = 640;
92320e7320Soki gi->gd_dheight = 480;
93320e7320Soki break;
94320e7320Soki default:
95320e7320Soki /*
96320e7320Soki * mode 16, 31kHz (default)
97320e7320Soki */
98320e7320Soki gi->gd_dwidth = 768;
99320e7320Soki gi->gd_dheight = 512;
100320e7320Soki break;
101320e7320Soki }
102320e7320Soki gi->gd_colors = 16;
103320e7320Soki
104873a493dSminoura return 1;
105320e7320Soki }
106320e7320Soki
107320e7320Soki /*
108320e7320Soki * Change the mode of the display.
109320e7320Soki * Right now all we can do is grfon/grfoff.
110320e7320Soki * Return a UNIX error number or 0 for success.
111320e7320Soki */
112320e7320Soki /*ARGSUSED*/
1138823c49fSoki int
gv_mode(struct grf_softc * gp,u_long cmd,void * data)11453524e44Schristos gv_mode(struct grf_softc *gp, u_long cmd, void *data)
115320e7320Soki {
116320e7320Soki int error = 0;
117320e7320Soki
118320e7320Soki switch (cmd) {
119320e7320Soki case GM_GRFON:
120320e7320Soki case GM_GRFOFF:
121320e7320Soki break;
122320e7320Soki
123320e7320Soki /*
124320e7320Soki * Remember UVA of mapping for GCDESCRIBE.
125320e7320Soki * XXX this should be per-process.
126320e7320Soki */
127320e7320Soki case GM_MAP:
128320e7320Soki gp->g_data = data;
129320e7320Soki break;
130320e7320Soki
131320e7320Soki case GM_UNMAP:
132320e7320Soki gp->g_data = 0;
133320e7320Soki break;
134320e7320Soki
135320e7320Soki case GM_GRFSETVMODE:
136320e7320Soki if (*(int *)data == 1) {
137320e7320Soki struct grfinfo *gi = &gp->g_display;
138320e7320Soki volatile struct crtc *crtc = &IODEVbase->io_crtc;
139873a493dSminoura /* Reset CRTC, set dwidth and dheight accordingly */
140320e7320Soki crtc->r20 = (crtc->r20 & 0xFF00) | 0x1a;
141320e7320Soki crtc->r08 = 0x1b;
142320e7320Soki crtc->r07 = 0x19c;
143320e7320Soki crtc->r06 = 0x1c;
144320e7320Soki crtc->r05 = 0x02;
145320e7320Soki crtc->r04 = 0x019f;
146320e7320Soki crtc->r03 = 0x9a;
147320e7320Soki crtc->r02 = 0x1a;
148320e7320Soki crtc->r01 = 0x09;
149320e7320Soki crtc->r00 = 0xa4;
150320e7320Soki gi->gd_dwidth = 1024;
151320e7320Soki gi->gd_dheight = 768;
152320e7320Soki }
153320e7320Soki break;
154320e7320Soki
155320e7320Soki default:
156320e7320Soki error = EINVAL;
157320e7320Soki break;
158320e7320Soki }
159873a493dSminoura return error;
160320e7320Soki }
161