grf_gv.c revision 1.3 1 /* $NetBSD: grf_gv.c,v 1.3 1997/10/12 12:13:48 oki Exp $ */
2
3 /*
4 * Copyright (c) 1988 University of Utah.
5 * Copyright (c) 1990, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * the Systems Programming Group of the University of Utah Computer
10 * Science Department.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the University of
23 * California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 * from: Utah $Hdr: grf_tc.c 1.20 93/08/13$
41 *
42 * @(#)grf_tc.c 8.4 (Berkeley) 1/12/94
43 */
44
45 /*
46 * Graphics routines for the X68K native custom chip set.
47 */
48 #include <sys/param.h>
49 #include <sys/device.h>
50 #include <sys/errno.h>
51
52 #include <x68k/dev/grfioctl.h>
53 #include <x68k/dev/grfvar.h>
54 #include <x68k/x68k/iodevice.h>
55
56 #include <machine/cpu.h>
57
58 int gv_init __P((struct grf_softc *, caddr_t));
59 int gv_mode __P((struct grf_softc *, u_long, caddr_t));
60
61 /* Initialize hardware.
62 * Must fill in the grfinfo structure in g_softc.
63 * Returns 0 if hardware not present, non-zero ow.
64 */
65 int
66 gv_init(gp, addr)
67 struct grf_softc *gp;
68 caddr_t addr;
69 {
70 struct grfinfo *gi = &gp->g_display;
71
72 gi->gd_fbwidth = 1024;
73 gi->gd_fbheight = 1024;
74 gi->gd_planes = 4;
75 gi->gd_regaddr = (void *)0x00e80000;
76 gi->gd_regsize = 0x00010000; /* contains system port */
77 gi->gd_fbaddr = (void *)0x00c00000;
78 gi->gd_fbsize = gi->gd_fbwidth * gi->gd_fbheight * 2;
79 gp->g_regkva = addr;
80 gp->g_fbkva = addr;
81 switch(IODEVbase->io_sram[0x1d]) {
82 case 18:
83 /*
84 * mode 18, 24kHz
85 */
86 gi->gd_dwidth = 1024;
87 gi->gd_dheight = 848;
88 break;
89 case 19:
90 /*
91 * mode 19, 31kHz VGA mode
92 */
93 gi->gd_dwidth = 640;
94 gi->gd_dheight = 480;
95 break;
96 default:
97 /*
98 * mode 16, 31kHz (default)
99 */
100 gi->gd_dwidth = 768;
101 gi->gd_dheight = 512;
102 break;
103 }
104 gi->gd_colors = 16;
105
106 return(1);
107 }
108
109 /*
110 * Change the mode of the display.
111 * Right now all we can do is grfon/grfoff.
112 * Return a UNIX error number or 0 for success.
113 */
114 /*ARGSUSED*/
115 int
116 gv_mode(gp, cmd, data)
117 register struct grf_softc *gp;
118 u_long cmd;
119 caddr_t data;
120 {
121 int error = 0;
122
123 switch (cmd) {
124 case GM_GRFON:
125 case GM_GRFOFF:
126 break;
127
128 /*
129 * Remember UVA of mapping for GCDESCRIBE.
130 * XXX this should be per-process.
131 */
132 case GM_MAP:
133 gp->g_data = data;
134 break;
135
136 case GM_UNMAP:
137 gp->g_data = 0;
138 break;
139
140 #ifdef COMPAT_HPUX
141 case GM_DESCRIBE:
142 {
143 struct grf_fbinfo *fi = (struct grf_fbinfo *)data;
144 struct grfinfo *gi = &gp->g_display;
145 int i;
146
147 /* feed it what HP-UX expects */
148 fi->id = gi->gd_id;
149 fi->mapsize = gi->gd_fbsize;
150 fi->dwidth = gi->gd_dwidth;
151 fi->dlength = gi->gd_dheight;
152 fi->width = gi->gd_fbwidth;
153 fi->length = gi->gd_fbheight;
154 fi->bpp = NBBY;
155 fi->xlen = (fi->width * fi->bpp) / NBBY;
156 fi->npl = gi->gd_planes;
157 fi->bppu = fi->npl;
158 fi->nplbytes = fi->xlen * ((fi->length * fi->bpp) / NBBY);
159 /* XXX */
160 switch (gp->g_sw->gd_hwid) {
161 case GID_HRCCATSEYE:
162 bcopy("HP98550", fi->name, 8);
163 break;
164 case GID_LRCATSEYE:
165 bcopy("HP98549", fi->name, 8);
166 break;
167 case GID_HRMCATSEYE:
168 bcopy("HP98548", fi->name, 8);
169 break;
170 case GID_TOPCAT:
171 switch (gi->gd_colors) {
172 case 64:
173 bcopy("HP98547", fi->name, 8);
174 break;
175 case 16:
176 bcopy("HP98545", fi->name, 8);
177 break;
178 case 2:
179 bcopy("HP98544", fi->name, 8);
180 break;
181 }
182 break;
183 }
184 fi->attr = 2; /* HW block mover */
185 /*
186 * If mapped, return the UVA where mapped.
187 */
188 if (gp->g_data) {
189 fi->regbase = gp->g_data;
190 fi->fbbase = fi->regbase + gp->g_display.gd_regsize;
191 } else {
192 fi->fbbase = 0;
193 fi->regbase = 0;
194 }
195 for (i = 0; i < 6; i++)
196 fi->regions[i] = 0;
197 break;
198 }
199 #endif
200 #if 1
201 case GM_GRFSETVMODE:
202 if (*(int *)data == 1) {
203 struct grfinfo *gi = &gp->g_display;
204 volatile struct crtc *crtc = &IODEVbase->io_crtc;
205 /* CRTC $B$K@_Dj$r9T$J$$!"(Bdwidth $B$H(B dheight $B$r$$$8$k(B */
206 crtc->r20 = (crtc->r20 & 0xFF00) | 0x1a;
207 crtc->r08 = 0x1b;
208 crtc->r07 = 0x19c;
209 crtc->r06 = 0x1c;
210 crtc->r05 = 0x02;
211 crtc->r04 = 0x019f;
212 crtc->r03 = 0x9a;
213 crtc->r02 = 0x1a;
214 crtc->r01 = 0x09;
215 crtc->r00 = 0xa4;
216 gi->gd_dwidth = 1024;
217 gi->gd_dheight = 768;
218 }
219 break;
220 #endif
221
222 default:
223 error = EINVAL;
224 break;
225 }
226 return(error);
227 }
228