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