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