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