pvr.c revision 1.20 1 1.20 christos /* $NetBSD: pvr.c,v 1.20 2005/12/11 12:17:06 christos Exp $ */
2 1.1 marcus
3 1.3 marcus /*-
4 1.4 thorpej * Copyright (c) 2001 Marcus Comstedt.
5 1.4 thorpej * Copyright (c) 2001 Jason R. Thorpe.
6 1.1 marcus * All rights reserved.
7 1.1 marcus *
8 1.1 marcus * Redistribution and use in source and binary forms, with or without
9 1.1 marcus * modification, are permitted provided that the following conditions
10 1.1 marcus * are met:
11 1.1 marcus * 1. Redistributions of source code must retain the above copyright
12 1.1 marcus * notice, this list of conditions and the following disclaimer.
13 1.1 marcus * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 marcus * notice, this list of conditions and the following disclaimer in the
15 1.1 marcus * documentation and/or other materials provided with the distribution.
16 1.1 marcus * 3. All advertising materials mentioning features or use of this software
17 1.1 marcus * must display the following acknowledgement:
18 1.3 marcus * This product includes software developed by Marcus Comstedt.
19 1.3 marcus * 4. Neither the name of The NetBSD Foundation nor the names of its
20 1.3 marcus * contributors may be used to endorse or promote products derived
21 1.3 marcus * from this software without specific prior written permission.
22 1.1 marcus *
23 1.3 marcus * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 1.3 marcus * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 1.3 marcus * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 1.3 marcus * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 1.3 marcus * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 1.3 marcus * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 1.3 marcus * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 1.3 marcus * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 1.3 marcus * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 1.3 marcus * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 1.3 marcus * POSSIBILITY OF SUCH DAMAGE.
34 1.1 marcus */
35 1.1 marcus
36 1.4 thorpej /*
37 1.4 thorpej * Copyright (c) 1998, 1999 Tohru Nishimura. All rights reserved.
38 1.4 thorpej *
39 1.4 thorpej * Redistribution and use in source and binary forms, with or without
40 1.4 thorpej * modification, are permitted provided that the following conditions
41 1.4 thorpej * are met:
42 1.4 thorpej * 1. Redistributions of source code must retain the above copyright
43 1.4 thorpej * notice, this list of conditions and the following disclaimer.
44 1.4 thorpej * 2. Redistributions in binary form must reproduce the above copyright
45 1.4 thorpej * notice, this list of conditions and the following disclaimer in the
46 1.4 thorpej * documentation and/or other materials provided with the distribution.
47 1.4 thorpej * 3. All advertising materials mentioning features or use of this software
48 1.4 thorpej * must display the following acknowledgement:
49 1.4 thorpej * This product includes software developed by Tohru Nishimura
50 1.4 thorpej * for the NetBSD Project.
51 1.4 thorpej * 4. The name of the author may not be used to endorse or promote products
52 1.4 thorpej * derived from this software without specific prior written permission
53 1.4 thorpej *
54 1.4 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
55 1.4 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
56 1.4 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
57 1.4 thorpej * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
58 1.4 thorpej * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
59 1.4 thorpej * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
60 1.4 thorpej * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
61 1.4 thorpej * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
62 1.4 thorpej * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
63 1.4 thorpej * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 1.4 thorpej */
65 1.1 marcus
66 1.1 marcus #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
67 1.1 marcus
68 1.20 christos __KERNEL_RCSID(0, "$NetBSD: pvr.c,v 1.20 2005/12/11 12:17:06 christos Exp $");
69 1.4 thorpej
70 1.1 marcus #include <sys/param.h>
71 1.1 marcus #include <sys/systm.h>
72 1.1 marcus #include <sys/kernel.h>
73 1.1 marcus #include <sys/device.h>
74 1.4 thorpej #include <sys/malloc.h>
75 1.4 thorpej #include <sys/buf.h>
76 1.4 thorpej #include <sys/ioctl.h>
77 1.1 marcus
78 1.12 thorpej #include <machine/vmparam.h>
79 1.1 marcus #include <machine/cpu.h>
80 1.1 marcus #include <machine/bus.h>
81 1.1 marcus
82 1.4 thorpej #include <dev/cons.h>
83 1.1 marcus
84 1.1 marcus #include <dev/wscons/wsconsio.h>
85 1.4 thorpej #include <dev/wscons/wsdisplayvar.h>
86 1.1 marcus
87 1.1 marcus #include <dev/wscons/wscons_callbacks.h>
88 1.4 thorpej
89 1.4 thorpej #include <dev/rasops/rasops.h>
90 1.4 thorpej #include <dev/wsfont/wsfont.h>
91 1.4 thorpej
92 1.4 thorpej #include <dreamcast/dev/pvrvar.h>
93 1.4 thorpej #include <dreamcast/dev/maple/mkbdvar.h>
94 1.1 marcus
95 1.1 marcus #include "mkbd.h"
96 1.1 marcus
97 1.12 thorpej #define PVRREG_FBSTART 0x05000000
98 1.12 thorpej #define PVRREG_REGSTART 0x005f8000
99 1.12 thorpej
100 1.12 thorpej #define PVRREG_BRDCOLR 0x40
101 1.12 thorpej #define BRDCOLR_BLUE(x) ((x) << 0)
102 1.12 thorpej #define BRDCOLR_GREEN(x) ((x) << 8)
103 1.12 thorpej #define BRDCOLR_RED(x) ((x) << 16)
104 1.12 thorpej
105 1.12 thorpej #define PVRREG_DIWMODE 0x44
106 1.12 thorpej #define DIWMODE_DE (1U << 0) /* display enable */
107 1.12 thorpej #define DIWMODE_SD (1U << 1) /* scan double enable */
108 1.12 thorpej #define DIWMODE_COL(x) ((x) << 2)
109 1.12 thorpej #define DIWMODE_COL_RGB555 DIWMODE_COL(0) /* RGB555, 16-bit */
110 1.12 thorpej #define DIWMODE_COL_RGB565 DIWMODE_COL(1) /* RGB565, 16-bit */
111 1.12 thorpej #define DIWMODE_COL_RGB888 DIWMODE_COL(2) /* RGB888, 24-bit */
112 1.12 thorpej #define DIWMODE_COL_ARGB888 DIWMODE_COL(3) /* RGB888, 32-bit */
113 1.12 thorpej #define DIWMODE_C (1U << 23) /* 2x clock enable (VGA) */
114 1.12 thorpej
115 1.12 thorpej #define PVRREG_DIWADDRL 0x50
116 1.12 thorpej
117 1.12 thorpej #define PVRREG_DIWADDRS 0x54
118 1.12 thorpej
119 1.12 thorpej #define PVRREG_DIWSIZE 0x5c
120 1.12 thorpej #define DIWSIZE_DPL(x) ((x) << 0) /* pixel data per line */
121 1.12 thorpej #define DIWSIZE_LPF(x) ((x) << 10) /* lines per field */
122 1.12 thorpej #define DIWSIZE_MODULO(x) ((x) << 20) /* words to skip + 1 */
123 1.12 thorpej
124 1.12 thorpej #define PVRREG_RASEVTPOS 0xcc
125 1.12 thorpej #define RASEVTPOS_BOTTOM(x) ((x) << 0)
126 1.12 thorpej #define RASEVTPOS_TOP(x) ((x) << 16)
127 1.12 thorpej
128 1.12 thorpej #define PVRREG_SYNCCONF 0xd0
129 1.12 thorpej #define SYNCCONF_VP (1U << 0) /* V-sync polarity */
130 1.12 thorpej #define SYNCCONF_HP (1U << 1) /* H-sync polarity */
131 1.12 thorpej #define SYNCCONF_I (1U << 4) /* interlace */
132 1.12 thorpej #define SYNCCONF_BC(x) (1U << 6) /* broadcast standard */
133 1.12 thorpej #define SYNCCONF_VO (1U << 8) /* video output enable */
134 1.12 thorpej
135 1.12 thorpej #define PVRREG_BRDHORZ 0xd4
136 1.12 thorpej #define BRDHORZ_STOP(x) ((x) << 0)
137 1.12 thorpej #define BRDHORZ_START(x) ((x) << 16)
138 1.12 thorpej
139 1.12 thorpej #define PVRREG_SYNCSIZE 0xd8
140 1.12 thorpej #define SYNCSIZE_H(x) ((x) << 0)
141 1.12 thorpej #define SYNCSIZE_V(x) ((x) << 16)
142 1.12 thorpej
143 1.12 thorpej #define PVRREG_BRDVERT 0xdc
144 1.12 thorpej #define BRDVERT_STOP(x) ((x) << 0)
145 1.12 thorpej #define BRDVERT_START(x) ((x) << 16)
146 1.12 thorpej
147 1.12 thorpej #define PVRREG_DIWCONF 0xe8
148 1.12 thorpej #define DIWCONF_LR (1U << 8) /* low-res */
149 1.12 thorpej #define DIWCONF_MAGIC (22 << 16)
150 1.12 thorpej
151 1.12 thorpej #define PVRREG_DIWHSTRT 0xec
152 1.12 thorpej
153 1.12 thorpej #define PVRREG_DIWVSTRT 0xf0
154 1.12 thorpej #define DIWVSTRT_V1(x) ((x) << 0)
155 1.12 thorpej #define DIWVSTRT_V2(x) ((x) << 16)
156 1.12 thorpej
157 1.12 thorpej #define PVR_REG_READ(dc, reg) \
158 1.12 thorpej ((__volatile uint32_t *)(dc)->dc_regvaddr)[(reg) >> 2]
159 1.12 thorpej #define PVR_REG_WRITE(dc, reg, val) \
160 1.12 thorpej ((__volatile uint32_t *)(dc)->dc_regvaddr)[(reg) >> 2] = (val)
161 1.12 thorpej
162 1.4 thorpej struct fb_devconfig {
163 1.4 thorpej vaddr_t dc_vaddr; /* framebuffer virtual address */
164 1.4 thorpej vaddr_t dc_paddr; /* framebuffer physical address */
165 1.12 thorpej vaddr_t dc_regvaddr; /* registers virtual address */
166 1.12 thorpej vaddr_t dc_regpaddr; /* registers physical address */
167 1.4 thorpej int dc_wid; /* width of frame buffer */
168 1.4 thorpej int dc_ht; /* height of frame buffer */
169 1.4 thorpej int dc_depth; /* depth, bits per pixel */
170 1.4 thorpej int dc_rowbytes; /* bytes in a FB scan line */
171 1.4 thorpej vaddr_t dc_videobase; /* base of flat frame buffer */
172 1.4 thorpej int dc_blanked; /* currently has video disabled */
173 1.5 thorpej int dc_dispflags; /* display flags */
174 1.6 marcus int dc_tvsystem; /* TV broadcast system */
175 1.4 thorpej
176 1.4 thorpej struct rasops_info rinfo;
177 1.4 thorpej };
178 1.4 thorpej
179 1.5 thorpej #define PVR_RGBMODE 0x01 /* RGB or composite */
180 1.5 thorpej #define PVR_VGAMODE 0x02 /* VGA */
181 1.5 thorpej
182 1.4 thorpej struct pvr_softc {
183 1.4 thorpej struct device sc_dev;
184 1.4 thorpej struct fb_devconfig *sc_dc; /* device configuration */
185 1.4 thorpej int nscreens;
186 1.4 thorpej };
187 1.1 marcus
188 1.4 thorpej int pvr_match(struct device *, struct cfdata *, void *);
189 1.4 thorpej void pvr_attach(struct device *, struct device *, void *);
190 1.1 marcus
191 1.17 thorpej CFATTACH_DECL(pvr, sizeof(struct pvr_softc),
192 1.17 thorpej pvr_match, pvr_attach, NULL, NULL);
193 1.1 marcus
194 1.4 thorpej void pvr_getdevconfig(struct fb_devconfig *);
195 1.1 marcus
196 1.4 thorpej struct fb_devconfig pvr_console_dc;
197 1.4 thorpej
198 1.4 thorpej char pvr_stdscreen_textgeom[32] = { "std" }; /* XXX yuck */
199 1.1 marcus
200 1.4 thorpej struct wsscreen_descr pvr_stdscreen = {
201 1.4 thorpej pvr_stdscreen_textgeom, 0, 0,
202 1.4 thorpej 0, /* textops */
203 1.4 thorpej 0, 0,
204 1.1 marcus WSSCREEN_WSCOLORS,
205 1.1 marcus };
206 1.1 marcus
207 1.1 marcus const struct wsscreen_descr *_pvr_scrlist[] = {
208 1.1 marcus &pvr_stdscreen,
209 1.1 marcus };
210 1.1 marcus
211 1.1 marcus const struct wsscreen_list pvr_screenlist = {
212 1.4 thorpej sizeof(_pvr_scrlist) / sizeof(struct wsscreen_descr *), _pvr_scrlist
213 1.1 marcus };
214 1.1 marcus
215 1.20 christos int pvrioctl(void *, u_long, caddr_t, int, struct lwp *);
216 1.4 thorpej paddr_t pvrmmap(void *, off_t, int);
217 1.1 marcus
218 1.4 thorpej int pvr_alloc_screen(void *, const struct wsscreen_descr *,
219 1.4 thorpej void **, int *, int *, long *);
220 1.4 thorpej void pvr_free_screen(void *, void *);
221 1.4 thorpej int pvr_show_screen(void *, void *, int,
222 1.4 thorpej void (*)(void *, int, int), void *);
223 1.1 marcus
224 1.1 marcus const struct wsdisplay_accessops pvr_accessops = {
225 1.4 thorpej pvrioctl,
226 1.4 thorpej pvrmmap,
227 1.1 marcus pvr_alloc_screen,
228 1.1 marcus pvr_free_screen,
229 1.1 marcus pvr_show_screen,
230 1.4 thorpej NULL, /* load_font */
231 1.1 marcus };
232 1.1 marcus
233 1.4 thorpej void pvrinit(struct fb_devconfig *);
234 1.4 thorpej
235 1.4 thorpej int pvr_is_console;
236 1.1 marcus
237 1.4 thorpej int
238 1.4 thorpej pvr_match(struct device *parent, struct cfdata *match, void *aux)
239 1.1 marcus {
240 1.1 marcus
241 1.19 tsutsui return 1;
242 1.1 marcus }
243 1.1 marcus
244 1.4 thorpej void
245 1.4 thorpej pvr_getdevconfig(struct fb_devconfig *dc)
246 1.1 marcus {
247 1.4 thorpej int i, cookie;
248 1.1 marcus
249 1.12 thorpej dc->dc_paddr = PVRREG_FBSTART;
250 1.4 thorpej dc->dc_vaddr = SH3_PHYS_TO_P2SEG(dc->dc_paddr);
251 1.1 marcus
252 1.12 thorpej dc->dc_regpaddr = PVRREG_REGSTART;
253 1.12 thorpej dc->dc_regvaddr = SH3_PHYS_TO_P2SEG(dc->dc_regpaddr);
254 1.12 thorpej
255 1.4 thorpej dc->dc_wid = 640;
256 1.4 thorpej dc->dc_ht = 480;
257 1.4 thorpej dc->dc_depth = 16;
258 1.4 thorpej dc->dc_rowbytes = dc->dc_wid * (dc->dc_depth / 8);
259 1.4 thorpej dc->dc_videobase = dc->dc_vaddr;
260 1.4 thorpej dc->dc_blanked = 0;
261 1.5 thorpej dc->dc_dispflags = 0;
262 1.4 thorpej
263 1.4 thorpej /* Clear the screen. */
264 1.19 tsutsui for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(uint32_t))
265 1.19 tsutsui *(uint32_t *)(dc->dc_videobase + i) = 0x0;
266 1.4 thorpej
267 1.4 thorpej /* Initialize the device. */
268 1.4 thorpej pvrinit(dc);
269 1.4 thorpej
270 1.4 thorpej dc->rinfo.ri_flg = 0;
271 1.4 thorpej dc->rinfo.ri_depth = dc->dc_depth;
272 1.4 thorpej dc->rinfo.ri_bits = (void *) dc->dc_videobase;
273 1.4 thorpej dc->rinfo.ri_width = dc->dc_wid;
274 1.4 thorpej dc->rinfo.ri_height = dc->dc_ht;
275 1.4 thorpej dc->rinfo.ri_stride = dc->dc_rowbytes;
276 1.4 thorpej
277 1.4 thorpej wsfont_init();
278 1.4 thorpej /* prefer 8 pixel wide font */
279 1.9 ad cookie = wsfont_find(NULL, 8, 0, 0, WSDISPLAY_FONTORDER_L2R,
280 1.9 ad WSDISPLAY_FONTORDER_L2R);
281 1.9 ad if (cookie <= 0)
282 1.9 ad cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_L2R,
283 1.9 ad WSDISPLAY_FONTORDER_L2R);
284 1.4 thorpej if (cookie <= 0) {
285 1.4 thorpej printf("pvr: font table is empty\n");
286 1.4 thorpej return;
287 1.4 thorpej }
288 1.1 marcus
289 1.9 ad if (wsfont_lock(cookie, &dc->rinfo.ri_font)) {
290 1.4 thorpej printf("pvr: unable to lock font\n");
291 1.4 thorpej return;
292 1.1 marcus }
293 1.4 thorpej dc->rinfo.ri_wsfcookie = cookie;
294 1.1 marcus
295 1.4 thorpej rasops_init(&dc->rinfo, 500, 500);
296 1.4 thorpej
297 1.4 thorpej /* XXX shouldn't be global */
298 1.4 thorpej pvr_stdscreen.nrows = dc->rinfo.ri_rows;
299 1.4 thorpej pvr_stdscreen.ncols = dc->rinfo.ri_cols;
300 1.4 thorpej pvr_stdscreen.textops = &dc->rinfo.ri_ops;
301 1.4 thorpej pvr_stdscreen.capabilities = dc->rinfo.ri_caps;
302 1.4 thorpej
303 1.4 thorpej /* XXX yuck */
304 1.4 thorpej sprintf(pvr_stdscreen_textgeom, "%dx%d", pvr_stdscreen.ncols,
305 1.4 thorpej pvr_stdscreen.nrows);
306 1.4 thorpej }
307 1.1 marcus
308 1.4 thorpej void
309 1.4 thorpej pvr_attach(struct device *parent, struct device *self, void *aux)
310 1.4 thorpej {
311 1.4 thorpej struct pvr_softc *sc = (void *) self;
312 1.4 thorpej struct wsemuldisplaydev_attach_args waa;
313 1.4 thorpej int console;
314 1.6 marcus static const char *tvsystem_name[4] =
315 1.6 marcus { "NTSC", "PAL", "PAL-M", "PAL-N" };
316 1.1 marcus
317 1.4 thorpej console = pvr_is_console;
318 1.4 thorpej if (console) {
319 1.4 thorpej sc->sc_dc = &pvr_console_dc;
320 1.4 thorpej sc->nscreens = 1;
321 1.4 thorpej } else {
322 1.4 thorpej sc->sc_dc = malloc(sizeof(struct fb_devconfig), M_DEVBUF,
323 1.4 thorpej M_WAITOK);
324 1.4 thorpej pvr_getdevconfig(sc->sc_dc);
325 1.4 thorpej }
326 1.5 thorpej printf(": %d x %d, %dbpp, %s, %s\n", sc->sc_dc->dc_wid,
327 1.5 thorpej sc->sc_dc->dc_ht, sc->sc_dc->dc_depth,
328 1.6 marcus (sc->sc_dc->dc_dispflags & PVR_VGAMODE) ? "VGA" :
329 1.6 marcus tvsystem_name[sc->sc_dc->dc_tvsystem],
330 1.5 thorpej (sc->sc_dc->dc_dispflags & PVR_RGBMODE) ? "RGB" : "composite");
331 1.1 marcus
332 1.4 thorpej /* XXX Colormap initialization? */
333 1.1 marcus
334 1.4 thorpej waa.console = console;
335 1.4 thorpej waa.scrdata = &pvr_screenlist;
336 1.4 thorpej waa.accessops = &pvr_accessops;
337 1.4 thorpej waa.accesscookie = sc;
338 1.1 marcus
339 1.4 thorpej (void) config_found(self, &waa, wsemuldisplaydevprint);
340 1.1 marcus }
341 1.1 marcus
342 1.1 marcus int
343 1.20 christos pvrioctl(void *v, u_long cmd, caddr_t data, int flag, struct lwp *l)
344 1.1 marcus {
345 1.4 thorpej struct pvr_softc *sc = v;
346 1.4 thorpej struct fb_devconfig *dc = sc->sc_dc;
347 1.4 thorpej
348 1.1 marcus switch (cmd) {
349 1.1 marcus case WSDISPLAYIO_GTYPE:
350 1.4 thorpej *(u_int *)data = WSDISPLAY_TYPE_DCPVR;
351 1.19 tsutsui return 0;
352 1.4 thorpej
353 1.1 marcus case WSDISPLAYIO_GINFO:
354 1.4 thorpej #define wsd_fbip ((struct wsdisplay_fbinfo *)data)
355 1.4 thorpej wsd_fbip->height = sc->sc_dc->dc_ht;
356 1.4 thorpej wsd_fbip->width = sc->sc_dc->dc_wid;
357 1.4 thorpej wsd_fbip->depth = sc->sc_dc->dc_depth;
358 1.4 thorpej wsd_fbip->cmsize = 0; /* XXX Colormap */
359 1.4 thorpej #undef wsd_fbip
360 1.19 tsutsui return 0;
361 1.4 thorpej
362 1.1 marcus case WSDISPLAYIO_GETCMAP:
363 1.4 thorpej case WSDISPLAYIO_PUTCMAP:
364 1.19 tsutsui return EPASSTHROUGH; /* XXX Colormap */
365 1.4 thorpej
366 1.4 thorpej case WSDISPLAYIO_SVIDEO:
367 1.18 tsutsui switch (*(u_int *)data) {
368 1.18 tsutsui case WSDISPLAYIO_VIDEO_OFF:
369 1.18 tsutsui if (!dc->dc_blanked) {
370 1.18 tsutsui dc->dc_blanked = 1;
371 1.18 tsutsui PVR_REG_WRITE(dc, PVRREG_DIWMODE,
372 1.18 tsutsui PVR_REG_READ(dc, PVRREG_DIWMODE) &
373 1.18 tsutsui ~DIWMODE_DE);
374 1.18 tsutsui }
375 1.18 tsutsui break;
376 1.18 tsutsui case WSDISPLAYIO_VIDEO_ON:
377 1.18 tsutsui if (dc->dc_blanked) {
378 1.18 tsutsui dc->dc_blanked = 0;
379 1.18 tsutsui PVR_REG_WRITE(dc, PVRREG_DIWMODE,
380 1.18 tsutsui PVR_REG_READ(dc, PVRREG_DIWMODE) |
381 1.18 tsutsui DIWMODE_DE);
382 1.18 tsutsui }
383 1.18 tsutsui break;
384 1.18 tsutsui default:
385 1.19 tsutsui return EPASSTHROUGH; /* XXX */
386 1.18 tsutsui }
387 1.19 tsutsui return 0;
388 1.4 thorpej
389 1.1 marcus case WSDISPLAYIO_GVIDEO:
390 1.4 thorpej *(u_int *)data = dc->dc_blanked ?
391 1.4 thorpej WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
392 1.19 tsutsui return 0;
393 1.4 thorpej
394 1.4 thorpej case WSDISPLAYIO_GCURPOS:
395 1.1 marcus case WSDISPLAYIO_SCURPOS:
396 1.4 thorpej case WSDISPLAYIO_GCURMAX:
397 1.4 thorpej case WSDISPLAYIO_GCURSOR:
398 1.1 marcus case WSDISPLAYIO_SCURSOR:
399 1.19 tsutsui return EPASSTHROUGH; /* XXX */
400 1.1 marcus }
401 1.1 marcus
402 1.19 tsutsui return EPASSTHROUGH;
403 1.1 marcus }
404 1.1 marcus
405 1.4 thorpej paddr_t
406 1.4 thorpej pvrmmap(void *v, off_t offset, int prot)
407 1.1 marcus {
408 1.4 thorpej
409 1.4 thorpej /*
410 1.4 thorpej * XXX This should be easy to support -- just need to define
411 1.4 thorpej * XXX offsets for the contol regs, etc.
412 1.4 thorpej */
413 1.7 marcus
414 1.7 marcus struct pvr_softc *sc = v;
415 1.7 marcus struct fb_devconfig *dc = sc->sc_dc;
416 1.7 marcus paddr_t addr;
417 1.7 marcus
418 1.7 marcus if (offset >= 0 &&
419 1.7 marcus offset < sh3_round_page(dc->dc_rowbytes * dc->dc_ht))
420 1.7 marcus addr = sh3_btop(dc->dc_paddr + offset);
421 1.7 marcus else
422 1.7 marcus addr = (-1); /* XXX bogus */
423 1.7 marcus
424 1.7 marcus return addr;
425 1.1 marcus }
426 1.1 marcus
427 1.1 marcus int
428 1.4 thorpej pvr_alloc_screen(void *v, const struct wsscreen_descr *type,
429 1.4 thorpej void **cookiep, int *curxp, int *curyp, long *attrp)
430 1.1 marcus {
431 1.4 thorpej struct pvr_softc *sc = v;
432 1.4 thorpej long defattr;
433 1.4 thorpej
434 1.4 thorpej if (sc->nscreens > 0)
435 1.19 tsutsui return ENOMEM;
436 1.4 thorpej
437 1.4 thorpej *cookiep = &sc->sc_dc->rinfo; /* one and only for now */
438 1.4 thorpej *curxp = 0;
439 1.4 thorpej *curyp = 0;
440 1.13 junyoung (*sc->sc_dc->rinfo.ri_ops.allocattr)(&sc->sc_dc->rinfo, 0, 0, 0,
441 1.4 thorpej &defattr);
442 1.4 thorpej *attrp = defattr;
443 1.4 thorpej sc->nscreens++;
444 1.19 tsutsui return 0;
445 1.1 marcus }
446 1.1 marcus
447 1.1 marcus void
448 1.4 thorpej pvr_free_screen(void *v, void *cookie)
449 1.1 marcus {
450 1.4 thorpej struct pvr_softc *sc = v;
451 1.4 thorpej
452 1.4 thorpej if (sc->sc_dc == &pvr_console_dc)
453 1.4 thorpej panic("pvr_free_screen: console");
454 1.4 thorpej
455 1.4 thorpej sc->nscreens--;
456 1.1 marcus }
457 1.1 marcus
458 1.1 marcus int
459 1.4 thorpej pvr_show_screen(void *v, void *cookie, int waitok,
460 1.4 thorpej void (*cb)(void *, int, int), void *cbarg)
461 1.1 marcus {
462 1.4 thorpej
463 1.19 tsutsui return 0;
464 1.1 marcus }
465 1.1 marcus
466 1.4 thorpej static void
467 1.5 thorpej pvr_check_cable(struct fb_devconfig *dc)
468 1.4 thorpej {
469 1.19 tsutsui __volatile uint32_t *porta =
470 1.19 tsutsui (__volatile uint32_t *)0xff80002c;
471 1.19 tsutsui uint16_t v;
472 1.1 marcus
473 1.4 thorpej /* PORT8 and PORT9 is input */
474 1.4 thorpej *porta = (*porta & ~0xf0000) | 0xa0000;
475 1.1 marcus
476 1.4 thorpej /* Read PORT8 and PORT9 */
477 1.19 tsutsui v = ((*(__volatile uint16_t *)(porta + 1)) >> 8) & 3;
478 1.1 marcus
479 1.4 thorpej if ((v & 2) == 0)
480 1.5 thorpej dc->dc_dispflags |= PVR_VGAMODE|PVR_RGBMODE;
481 1.5 thorpej else if ((v & 1) == 0)
482 1.5 thorpej dc->dc_dispflags |= PVR_RGBMODE;
483 1.1 marcus }
484 1.1 marcus
485 1.6 marcus static void
486 1.6 marcus pvr_check_tvsys(struct fb_devconfig *dc)
487 1.6 marcus {
488 1.12 thorpej
489 1.6 marcus /* XXX should use flashmem device when one exists */
490 1.19 tsutsui dc->dc_tvsystem = (*(__volatile uint8_t *)0xa021a004) & 3;
491 1.6 marcus }
492 1.6 marcus
493 1.1 marcus void
494 1.4 thorpej pvrinit(struct fb_devconfig *dc)
495 1.1 marcus {
496 1.12 thorpej int display_lines_per_field;
497 1.12 thorpej int v_absolute_size;
498 1.12 thorpej int h_absolute_size;
499 1.12 thorpej int vborder_start, vborder_stop;
500 1.12 thorpej int hborder_start, hborder_stop;
501 1.12 thorpej int modulo = 1, voffset, hoffset;
502 1.4 thorpej
503 1.5 thorpej pvr_check_cable(dc);
504 1.6 marcus pvr_check_tvsys(dc);
505 1.4 thorpej
506 1.12 thorpej PVR_REG_WRITE(dc, 8, 0); /* reset */
507 1.12 thorpej PVR_REG_WRITE(dc, PVRREG_BRDCOLR, 0); /* black border */
508 1.4 thorpej
509 1.5 thorpej if (dc->dc_dispflags & PVR_VGAMODE) {
510 1.12 thorpej v_absolute_size = 524;
511 1.12 thorpej h_absolute_size = 857;
512 1.12 thorpej
513 1.4 thorpej display_lines_per_field = 480;
514 1.12 thorpej hoffset = 164;
515 1.4 thorpej voffset = 36;
516 1.12 thorpej
517 1.12 thorpej hborder_start = 126;
518 1.12 thorpej hborder_stop = 837;
519 1.12 thorpej
520 1.12 thorpej vborder_start = 40;
521 1.12 thorpej vborder_stop = 444; /* XXX */
522 1.12 thorpej
523 1.12 thorpej /* 31kHz, RGB565 */
524 1.12 thorpej PVR_REG_WRITE(dc, PVRREG_DIWMODE,
525 1.12 thorpej DIWMODE_C | DIWMODE_COL_RGB565);
526 1.12 thorpej
527 1.12 thorpej /* video output */
528 1.12 thorpej PVR_REG_WRITE(dc, PVRREG_SYNCCONF, SYNCCONF_VO);
529 1.4 thorpej } else {
530 1.12 thorpej if (dc->dc_tvsystem & 1) {
531 1.12 thorpej /* 50 Hz PAL */
532 1.12 thorpej v_absolute_size = 624;
533 1.6 marcus h_absolute_size = 863;
534 1.12 thorpej
535 1.12 thorpej display_lines_per_field = 240;
536 1.6 marcus hoffset = 174;
537 1.12 thorpej voffset = 18;
538 1.12 thorpej
539 1.12 thorpej hborder_start = 116;
540 1.12 thorpej hborder_stop = 843;
541 1.12 thorpej
542 1.12 thorpej vborder_start = 44;
543 1.12 thorpej vborder_stop = 536; /* XXX */
544 1.12 thorpej } else {
545 1.12 thorpej /* 60 Hz NTSC */
546 1.12 thorpej v_absolute_size = 524;
547 1.12 thorpej h_absolute_size = 857;
548 1.12 thorpej
549 1.12 thorpej display_lines_per_field = 240;
550 1.12 thorpej hoffset = 170;
551 1.12 thorpej voffset = 28;
552 1.12 thorpej
553 1.12 thorpej hborder_start = 126;
554 1.12 thorpej hborder_stop = 837;
555 1.12 thorpej
556 1.12 thorpej vborder_start = 18;
557 1.12 thorpej vborder_stop = 506; /* XXX */
558 1.6 marcus }
559 1.12 thorpej
560 1.12 thorpej modulo += 640 * 2 / 4; /* interlace -> skip every other line */
561 1.12 thorpej
562 1.12 thorpej /* 15kHz, RGB565 */
563 1.12 thorpej PVR_REG_WRITE(dc, PVRREG_DIWMODE,
564 1.12 thorpej DIWMODE_COL_RGB565);
565 1.12 thorpej
566 1.6 marcus /* video output, PAL/NTSC, interlace */
567 1.12 thorpej PVR_REG_WRITE(dc, PVRREG_SYNCCONF,
568 1.12 thorpej SYNCCONF_VO | SYNCCONF_I | SYNCCONF_BC(dc->dc_tvsystem));
569 1.4 thorpej }
570 1.4 thorpej
571 1.12 thorpej /* video base address, long field */
572 1.12 thorpej PVR_REG_WRITE(dc, PVRREG_DIWADDRL, 0);
573 1.1 marcus
574 1.12 thorpej /* video base address, short field */
575 1.12 thorpej PVR_REG_WRITE(dc, PVRREG_DIWADDRS, 640 * 2);
576 1.1 marcus
577 1.12 thorpej /* video size */
578 1.12 thorpej PVR_REG_WRITE(dc, PVRREG_DIWSIZE, DIWSIZE_MODULO(modulo) |
579 1.12 thorpej DIWSIZE_LPF(display_lines_per_field - 1) |
580 1.12 thorpej DIWSIZE_DPL(640 * 2 / 4 - 1));
581 1.12 thorpej
582 1.12 thorpej PVR_REG_WRITE(dc, PVRREG_DIWVSTRT, /* V start */
583 1.12 thorpej DIWVSTRT_V1(voffset) | DIWVSTRT_V2(voffset));
584 1.12 thorpej PVR_REG_WRITE(dc, PVRREG_BRDVERT, /* V border */
585 1.12 thorpej BRDVERT_START(vborder_start) | BRDVERT_STOP(vborder_stop));
586 1.12 thorpej PVR_REG_WRITE(dc, PVRREG_DIWHSTRT, hoffset); /* H start */
587 1.12 thorpej PVR_REG_WRITE(dc, PVRREG_SYNCSIZE, /* HV counter */
588 1.12 thorpej SYNCSIZE_V(v_absolute_size) | SYNCSIZE_H(h_absolute_size));
589 1.12 thorpej PVR_REG_WRITE(dc, PVRREG_BRDHORZ, /* H border */
590 1.12 thorpej BRDHORZ_START(hborder_start) | BRDHORZ_STOP(hborder_stop));
591 1.12 thorpej PVR_REG_WRITE(dc, PVRREG_DIWCONF, DIWCONF_MAGIC);
592 1.1 marcus
593 1.4 thorpej /* RGB / composite */
594 1.19 tsutsui *(__volatile uint32_t *)
595 1.5 thorpej SH3_PHYS_TO_P2SEG(0x00702c00) =
596 1.5 thorpej ((dc->dc_dispflags & PVR_RGBMODE) ? 0 : 3) << 8;
597 1.1 marcus
598 1.12 thorpej /* display on */
599 1.12 thorpej PVR_REG_WRITE(dc, PVRREG_DIWMODE,
600 1.12 thorpej PVR_REG_READ(dc, PVRREG_DIWMODE) | DIWMODE_DE);
601 1.1 marcus }
602 1.1 marcus
603 1.4 thorpej /* Console support. */
604 1.1 marcus
605 1.4 thorpej void pvrcnprobe(struct consdev *);
606 1.4 thorpej void pvrcninit(struct consdev *);
607 1.1 marcus
608 1.1 marcus void
609 1.4 thorpej pvrcninit(struct consdev *cndev)
610 1.1 marcus {
611 1.4 thorpej struct fb_devconfig *dcp = &pvr_console_dc;
612 1.4 thorpej long defattr;
613 1.4 thorpej
614 1.4 thorpej pvr_getdevconfig(dcp);
615 1.13 junyoung (*dcp->rinfo.ri_ops.allocattr)(&dcp->rinfo, 0, 0, 0, &defattr);
616 1.4 thorpej wsdisplay_cnattach(&pvr_stdscreen, &dcp->rinfo, 0, 0, defattr);
617 1.4 thorpej
618 1.4 thorpej pvr_is_console = 1;
619 1.1 marcus
620 1.1 marcus cn_tab->cn_pri = CN_INTERNAL;
621 1.1 marcus
622 1.1 marcus #if NMKBD > 0
623 1.4 thorpej mkbd_cnattach(); /* connect keyboard and screen together */
624 1.1 marcus #endif
625 1.1 marcus }
626 1.1 marcus
627 1.1 marcus void
628 1.4 thorpej pvrcnprobe(struct consdev *cndev)
629 1.1 marcus {
630 1.1 marcus #if NWSDISPLAY > 0
631 1.4 thorpej int maj, unit;
632 1.14 gehenna extern const struct cdevsw wsdisplay_cdevsw;
633 1.1 marcus #endif
634 1.1 marcus cndev->cn_dev = NODEV;
635 1.1 marcus cndev->cn_pri = CN_NORMAL;
636 1.1 marcus
637 1.1 marcus #if NWSDISPLAY > 0
638 1.1 marcus unit = 0;
639 1.14 gehenna maj = cdevsw_lookup_major(&wsdisplay_cdevsw);
640 1.14 gehenna if (maj != -1) {
641 1.1 marcus cndev->cn_pri = CN_INTERNAL;
642 1.1 marcus cndev->cn_dev = makedev(maj, unit);
643 1.1 marcus }
644 1.1 marcus #endif
645 1.1 marcus }
646