grf_gv.c revision 1.7 1 /* $NetBSD: grf_gv.c,v 1.7 2003/07/15 01:44:51 lukem 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
49 #include <sys/cdefs.h>
50 __KERNEL_RCSID(0, "$NetBSD: grf_gv.c,v 1.7 2003/07/15 01:44:51 lukem Exp $");
51
52 #include "opt_compat_hpux.h"
53
54 #include <sys/param.h>
55 #include <sys/device.h>
56 #include <sys/errno.h>
57
58 #include <machine/grfioctl.h>
59
60 #include <x68k/dev/grfvar.h>
61 #include <x68k/x68k/iodevice.h>
62
63 #include <machine/cpu.h>
64
65 int gv_init __P((struct grf_softc *, caddr_t));
66 int gv_mode __P((struct grf_softc *, u_long, caddr_t));
67
68 /* Initialize hardware.
69 * Must fill in the grfinfo structure in g_softc.
70 * Returns 0 if hardware not present, non-zero ow.
71 */
72 int
73 gv_init(gp, addr)
74 struct grf_softc *gp;
75 caddr_t addr;
76 {
77 struct grfinfo *gi = &gp->g_display;
78
79 gi->gd_fbwidth = 1024;
80 gi->gd_fbheight = 1024;
81 gi->gd_planes = 4;
82 gi->gd_regaddr = (void *)0x00e80000;
83 gi->gd_regsize = 0x00010000; /* contains system port */
84 gi->gd_fbaddr = (void *)0x00c00000;
85 gi->gd_fbsize = gi->gd_fbwidth * gi->gd_fbheight * 2;
86 gp->g_regkva = addr;
87 gp->g_fbkva = addr;
88 switch(IODEVbase->io_sram[0x1d]) {
89 case 18:
90 /*
91 * mode 18, 24kHz
92 */
93 gi->gd_dwidth = 1024;
94 gi->gd_dheight = 848;
95 break;
96 case 19:
97 /*
98 * mode 19, 31kHz VGA mode
99 */
100 gi->gd_dwidth = 640;
101 gi->gd_dheight = 480;
102 break;
103 default:
104 /*
105 * mode 16, 31kHz (default)
106 */
107 gi->gd_dwidth = 768;
108 gi->gd_dheight = 512;
109 break;
110 }
111 gi->gd_colors = 16;
112
113 return(1);
114 }
115
116 /*
117 * Change the mode of the display.
118 * Right now all we can do is grfon/grfoff.
119 * Return a UNIX error number or 0 for success.
120 */
121 /*ARGSUSED*/
122 int
123 gv_mode(gp, cmd, data)
124 register struct grf_softc *gp;
125 u_long cmd;
126 caddr_t data;
127 {
128 int error = 0;
129
130 switch (cmd) {
131 case GM_GRFON:
132 case GM_GRFOFF:
133 break;
134
135 /*
136 * Remember UVA of mapping for GCDESCRIBE.
137 * XXX this should be per-process.
138 */
139 case GM_MAP:
140 gp->g_data = data;
141 break;
142
143 case GM_UNMAP:
144 gp->g_data = 0;
145 break;
146
147 #ifdef COMPAT_HPUX
148 case GM_DESCRIBE:
149 {
150 struct grf_fbinfo *fi = (struct grf_fbinfo *)data;
151 struct grfinfo *gi = &gp->g_display;
152 int i;
153
154 /* feed it what HP-UX expects */
155 fi->id = gi->gd_id;
156 fi->mapsize = gi->gd_fbsize;
157 fi->dwidth = gi->gd_dwidth;
158 fi->dlength = gi->gd_dheight;
159 fi->width = gi->gd_fbwidth;
160 fi->length = gi->gd_fbheight;
161 fi->bpp = NBBY;
162 fi->xlen = (fi->width * fi->bpp) / NBBY;
163 fi->npl = gi->gd_planes;
164 fi->bppu = fi->npl;
165 fi->nplbytes = fi->xlen * ((fi->length * fi->bpp) / NBBY);
166 /* XXX */
167 switch (gp->g_sw->gd_hwid) {
168 case GID_HRCCATSEYE:
169 memcpy(fi->name, "HP98550", 8);
170 break;
171 case GID_LRCATSEYE:
172 memcpy(fi->name, "HP98549", 8);
173 break;
174 case GID_HRMCATSEYE:
175 memcpy(fi->name, "HP98548", 8);
176 break;
177 case GID_TOPCAT:
178 switch (gi->gd_colors) {
179 case 64:
180 memcpy(fi->name, "HP98547", 8);
181 break;
182 case 16:
183 memcpy(fi->name, "HP98545", 8);
184 break;
185 case 2:
186 memcpy(fi->name, "HP98544", 8);
187 break;
188 }
189 break;
190 }
191 fi->attr = 2; /* HW block mover */
192 /*
193 * If mapped, return the UVA where mapped.
194 */
195 if (gp->g_data) {
196 fi->regbase = gp->g_data;
197 fi->fbbase = fi->regbase + gp->g_display.gd_regsize;
198 } else {
199 fi->fbbase = 0;
200 fi->regbase = 0;
201 }
202 for (i = 0; i < 6; i++)
203 fi->regions[i] = 0;
204 break;
205 }
206 #endif
207 #if 1
208 case GM_GRFSETVMODE:
209 if (*(int *)data == 1) {
210 struct grfinfo *gi = &gp->g_display;
211 volatile struct crtc *crtc = &IODEVbase->io_crtc;
212 /* CRTC $B$K@_Dj$r9T$J$$!"(Bdwidth $B$H(B dheight $B$r$$$8$k(B */
213 crtc->r20 = (crtc->r20 & 0xFF00) | 0x1a;
214 crtc->r08 = 0x1b;
215 crtc->r07 = 0x19c;
216 crtc->r06 = 0x1c;
217 crtc->r05 = 0x02;
218 crtc->r04 = 0x019f;
219 crtc->r03 = 0x9a;
220 crtc->r02 = 0x1a;
221 crtc->r01 = 0x09;
222 crtc->r00 = 0xa4;
223 gi->gd_dwidth = 1024;
224 gi->gd_dheight = 768;
225 }
226 break;
227 #endif
228
229 default:
230 error = EINVAL;
231 break;
232 }
233 return(error);
234 }
235