pvr.c revision 1.3 1 /* $NetBSD: pvr.c,v 1.3 2001/01/21 22:46:22 marcus Exp $ */
2
3 /*-
4 * Copyright (c) 2001 Marcus Comstedt
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Marcus Comstedt.
18 * 4. Neither the name of The NetBSD Foundation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35
36 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <sys/device.h>
42 #include <sys/malloc.h>
43 #include <sys/conf.h>
44
45 #include <machine/cpu.h>
46 #include <machine/bus.h>
47
48 #include <dev/cons.h>
49
50 #include <dreamcast/dev/pvrvar.h>
51 #include <dreamcast/dev/maple/mkbdvar.h>
52 #include <dev/wscons/wsconsio.h>
53
54 #include <dev/rcons/raster.h>
55 #include <dev/wscons/wscons_raster.h>
56 #include <dev/wscons/wsdisplayvar.h>
57 #include <dev/wscons/wsconsio.h>
58 #include <dev/wscons/wscons_callbacks.h>
59
60 #include <sh3/shbvar.h>
61
62 #include "wsdisplay.h"
63 #include "mkbd.h"
64
65 #if NWSDISPLAY > 0
66 cdev_decl(wsdisplay);
67 #endif
68
69 int pvr_match __P((struct device *, struct cfdata *, void *));
70 void pvr_attach __P((struct device *, struct device *, void *));
71
72 struct cfattach pvr_ca = {
73 sizeof(struct pvr_softc),
74 pvr_match,
75 pvr_attach,
76 };
77
78
79 const struct wsdisplay_emulops pvr_emulops = {
80 rcons_cursor,
81 rcons_mapchar,
82 rcons_putchar,
83 rcons_copycols,
84 rcons_erasecols,
85 rcons_copyrows,
86 rcons_eraserows,
87 rcons_alloc_attr
88 };
89
90 const struct wsscreen_descr pvr_stdscreen = {
91 "52x20", 52, 20,
92 &pvr_emulops,
93 12, 24,
94 WSSCREEN_WSCOLORS,
95 };
96
97 const struct wsscreen_descr *_pvr_scrlist[] = {
98 &pvr_stdscreen,
99 };
100
101 const struct wsscreen_list pvr_screenlist = {
102 sizeof(_pvr_scrlist) / sizeof(struct wsscreen_descr *),
103 _pvr_scrlist
104 };
105
106 static int pvr_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
107 static paddr_t pvr_mmap __P((void *, off_t, int));
108 static int pvr_alloc_screen __P((void *, const struct wsscreen_descr *,
109 void **, int *, int *, long *));
110 static void pvr_free_screen __P((void *, void *));
111 static int pvr_show_screen __P((void *, void *, int,
112 void (*)(void *, int, int), void *));
113
114 static void pvr_check_cable __P((int *, int *));
115 static void pvr_init_dpy_hardware __P((void));
116
117
118 const struct wsdisplay_accessops pvr_accessops = {
119 pvr_ioctl,
120 pvr_mmap,
121 pvr_alloc_screen,
122 pvr_free_screen,
123 pvr_show_screen,
124 0 /* load_font */
125 };
126
127
128 static void
129 pvr_check_cable(vgamode_p, rgbmode_p)
130 int *vgamode_p;
131 int *rgbmode_p;
132 {
133 volatile u_int32_t *porta = (volatile u_int32_t *)0xff80002c;
134 u_int16_t v;
135
136 /* PORT8 and PORT9 is input */
137 *porta = (*porta & ~0xf0000) | 0xa0000;
138
139 /* Read PORT8 and PORT9 */
140 v = ((*(volatile u_int16_t *)(porta+1))>>8)&3;
141
142 if (! (v&2) )
143 *vgamode_p = *rgbmode_p = 1;
144 else {
145 *vgamode_p = 0;
146 *rgbmode_p = (v&1)? 0 : 1;
147 }
148 }
149
150 static void
151 pvr_init_dpy_hardware()
152 {
153 volatile u_int32_t *pvr = (volatile u_int32_t *)0xa05f8000;
154 int display_lines_per_field = 240;
155 int modulo = 1, voffset;
156 int vgamode, rgbmode;
157
158 pvr_check_cable(&vgamode, &rgbmode);
159
160 pvr[8/4] = 0; /* reset */
161 pvr[0x40/4] = 0; /* black border */
162
163 if(vgamode) {
164 pvr[0x44/4] = 0x800004; /* 31kHz, RGB565 */
165 pvr[0xd0/4] = 0x100; /* video output */
166 display_lines_per_field = 480;
167 voffset = 36;
168 } else {
169 pvr[0x44/4] = 0x000004; /* 15kHz, RGB565 */
170 pvr[0xd0/4] = 0x110; /* video output, NTSC, interlace */
171 modulo += 640*2/4; /* interlace -> skip every other line */
172 voffset = 18;
173 }
174
175 pvr[0x50/4]=0; /* video base address, long field */
176 pvr[0x54/4]=640*2; /* video base address, short field */
177
178 pvr[0x5c/4]=(modulo<<20)|((display_lines_per_field-1)<<10)|(640*2/4-1);
179
180 voffset = (voffset<<16) | voffset;
181
182 pvr[0xf0/4]=voffset; /* V start */
183 pvr[0xdc/4]=voffset+display_lines_per_field; /* V border */
184 pvr[0xec/4]=164; /* H start */
185 pvr[0xd8/4]=(524<<16)|857; /* HV counter */
186 pvr[0xd4/4]=(126<<16)|837; /* H border */
187 pvr[0xe8/4]=22<<16;
188
189 /* RGB / composite */
190 *(volatile u_int32_t *)0xa0702c00 = (rgbmode? 0 : 3) << 8;
191
192 pvr[0x44/4] |= 1; /* display on */
193 }
194
195
196
197
198 int
199 pvr_ioctl(v, cmd, data, flag, p)
200 void *v;
201 u_long cmd;
202 caddr_t data;
203 int flag;
204 struct proc *p;
205 {
206 switch (cmd) {
207 case WSDISPLAYIO_GTYPE:
208 case WSDISPLAYIO_GINFO:
209 case WSDISPLAYIO_GCURMAX:
210 case WSDISPLAYIO_GCURPOS:
211 case WSDISPLAYIO_GCURSOR:
212 case WSDISPLAYIO_GETCMAP:
213 case WSDISPLAYIO_GVIDEO:
214 case WSDISPLAYIO_PUTCMAP:
215 case WSDISPLAYIO_SCURPOS:
216 case WSDISPLAYIO_SCURSOR:
217 case WSDISPLAYIO_SVIDEO:
218 /* NONE of these operations are supported. */
219 return ENOTTY;
220 }
221
222 return -1;
223 }
224
225 static paddr_t
226 pvr_mmap(v, offset, prot)
227 void *v;
228 off_t offset;
229 int prot;
230 {
231 return (-1);
232 }
233
234 int
235 pvr_alloc_screen(v, type, cookiep, curxp, curyp, defattrp)
236 void *v;
237 const struct wsscreen_descr *type;
238 void **cookiep;
239 int *curxp, *curyp;
240 long *defattrp;
241 {
242 return (ENOMEM);
243 }
244
245 void
246 pvr_free_screen(v, cookie)
247 void *v;
248 void *cookie;
249 {
250 }
251
252 int
253 pvr_show_screen(v, cookie, waitok, cb, cbarg)
254 void *v;
255 void *cookie;
256 int waitok;
257 void (*cb) __P((void *, int, int));
258 void *cbarg;
259 {
260 return 0;
261 }
262
263
264 int
265 pvr_match(parent, match, aux)
266 struct device *parent;
267 struct cfdata *match;
268 void *aux;
269 {
270 struct shb_attach_args *sa = aux;
271
272 if(strcmp("pvr", match->cf_driver->cd_name))
273 return 0;
274
275 sa->ia_iosize = 0 /* 0x1400 */;
276 return (1);
277 }
278
279 void
280 pvr_attach(parent, self, aux)
281 struct device *parent;
282 struct device *self;
283 void *aux;
284 {
285 struct pvr_softc *sc;
286 struct wsemuldisplaydev_attach_args waa;
287 static int pvr_console_initted = 0;
288
289 sc = (struct pvr_softc *)self;
290
291 printf("\n");
292
293 /* initialize the raster */
294 waa.console = (++pvr_console_initted == 1);
295 waa.scrdata = &pvr_screenlist;
296 waa.accessops = &pvr_accessops;
297 waa.accesscookie = sc;
298
299 config_found(self, &waa, wsemuldisplaydevprint);
300 }
301
302
303 /* Console stuff */
304
305 void pvrcnprobe __P((struct consdev *));
306 void pvrcninit __P((struct consdev *));
307
308 void
309 pvrcninit(cndev)
310 struct consdev *cndev;
311 {
312 static struct rcons rcons;
313 static struct raster raster;
314 struct rcons *rcp;
315 struct raster *rap;
316
317 /* initialize the raster console blitter */
318 rap = &raster;
319 rap->width = 640;
320 rap->height = 480;
321 rap->depth = 16;
322 rap->linelongs = 640*2 / sizeof(u_int32_t);
323 rap->pixels = (void *)0xa5000000;
324
325 bzero(rap->pixels, 640*480*2);
326
327 pvr_init_dpy_hardware();
328
329 rcp = &rcons;
330 rcp->rc_sp = rap;
331 rcp->rc_crow = rcp->rc_ccol = -1;
332 rcp->rc_crowp = &rcp->rc_crow;
333 rcp->rc_ccolp = &rcp->rc_ccol;
334 rcons_init(rcp, 20, 52);
335
336 wsdisplay_cnattach(&pvr_stdscreen, rcp, 0, 0, 0);
337 cn_tab->cn_pri = CN_INTERNAL;
338
339 #if NMKBD > 0
340 mkbd_cnattach(); /* Connect keyboard and screen together */
341 #endif
342 }
343
344
345 void
346 pvrcnprobe(cndev)
347 struct consdev *cndev;
348 {
349 #if NWSDISPLAY > 0
350 int maj, unit;
351 #endif
352 cndev->cn_dev = NODEV;
353 cndev->cn_pri = CN_NORMAL;
354
355 #if NWSDISPLAY > 0
356 unit = 0;
357 for (maj = 0; maj < nchrdev; maj++) {
358 if (cdevsw[maj].d_open == wsdisplayopen) {
359 break;
360 }
361 }
362 if (maj != nchrdev) {
363 cndev->cn_pri = CN_INTERNAL;
364 cndev->cn_dev = makedev(maj, unit);
365 }
366 #endif
367 }
368