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