Home | History | Annotate | Line # | Download | only in dev
pvr.c revision 1.15
      1 /*	$NetBSD: pvr.c,v 1.15 2002/09/27 02:16:28 thorpej 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.15 2002/09/27 02:16:28 thorpej 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 struct cfattach pvr_ca = {
    192 	sizeof(struct pvr_softc), pvr_match, pvr_attach,
    193 };
    194 
    195 void	pvr_getdevconfig(struct fb_devconfig *);
    196 
    197 struct fb_devconfig pvr_console_dc;
    198 
    199 char pvr_stdscreen_textgeom[32] = { "std" };	/* XXX yuck */
    200 
    201 struct wsscreen_descr pvr_stdscreen = {
    202 	pvr_stdscreen_textgeom, 0, 0,
    203 	0, /* textops */
    204 	0, 0,
    205 	WSSCREEN_WSCOLORS,
    206 };
    207 
    208 const struct wsscreen_descr *_pvr_scrlist[] = {
    209 	&pvr_stdscreen,
    210 };
    211 
    212 const struct wsscreen_list pvr_screenlist = {
    213 	sizeof(_pvr_scrlist) / sizeof(struct wsscreen_descr *), _pvr_scrlist
    214 };
    215 
    216 int	pvrioctl(void *, u_long, caddr_t, int, struct proc *);
    217 paddr_t	pvrmmap(void *, off_t, int);
    218 
    219 int	pvr_alloc_screen(void *, const struct wsscreen_descr *,
    220 	    void **, int *, int *, long *);
    221 void	pvr_free_screen(void *, void *);
    222 int	pvr_show_screen(void *, void *, int,
    223 	    void (*)(void *, int, int), void *);
    224 
    225 const struct wsdisplay_accessops pvr_accessops = {
    226 	pvrioctl,
    227 	pvrmmap,
    228 	pvr_alloc_screen,
    229 	pvr_free_screen,
    230 	pvr_show_screen,
    231 	NULL, /* load_font */
    232 };
    233 
    234 void	pvrinit(struct fb_devconfig *);
    235 
    236 int	pvr_is_console;
    237 
    238 int
    239 pvr_match(struct device *parent, struct cfdata *match, void *aux)
    240 {
    241 
    242 	return (1);
    243 }
    244 
    245 void
    246 pvr_getdevconfig(struct fb_devconfig *dc)
    247 {
    248 	int i, cookie;
    249 
    250 	dc->dc_paddr = PVRREG_FBSTART;
    251 	dc->dc_vaddr = SH3_PHYS_TO_P2SEG(dc->dc_paddr);
    252 
    253 	dc->dc_regpaddr = PVRREG_REGSTART;
    254 	dc->dc_regvaddr = SH3_PHYS_TO_P2SEG(dc->dc_regpaddr);
    255 
    256 	dc->dc_wid = 640;
    257 	dc->dc_ht = 480;
    258 	dc->dc_depth = 16;
    259 	dc->dc_rowbytes = dc->dc_wid * (dc->dc_depth / 8);
    260 	dc->dc_videobase = dc->dc_vaddr;
    261 	dc->dc_blanked = 0;
    262 	dc->dc_dispflags = 0;
    263 
    264 	/* Clear the screen. */
    265 	for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t))
    266 		*(u_int32_t *)(dc->dc_videobase + i) = 0x0;
    267 
    268 	/* Initialize the device. */
    269 	pvrinit(dc);
    270 
    271 	dc->rinfo.ri_flg = 0;
    272 	dc->rinfo.ri_depth = dc->dc_depth;
    273 	dc->rinfo.ri_bits = (void *) dc->dc_videobase;
    274 	dc->rinfo.ri_width = dc->dc_wid;
    275 	dc->rinfo.ri_height = dc->dc_ht;
    276 	dc->rinfo.ri_stride = dc->dc_rowbytes;
    277 
    278 	wsfont_init();
    279 	/* prefer 8 pixel wide font */
    280 	cookie = wsfont_find(NULL, 8, 0, 0, WSDISPLAY_FONTORDER_L2R,
    281 	    WSDISPLAY_FONTORDER_L2R);
    282 	if (cookie <= 0)
    283 		cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_L2R,
    284 		    WSDISPLAY_FONTORDER_L2R);
    285 	if (cookie <= 0) {
    286 		printf("pvr: font table is empty\n");
    287 		return;
    288 	}
    289 
    290 	if (wsfont_lock(cookie, &dc->rinfo.ri_font)) {
    291 		printf("pvr: unable to lock font\n");
    292 		return;
    293 	}
    294 	dc->rinfo.ri_wsfcookie = cookie;
    295 
    296 	rasops_init(&dc->rinfo, 500, 500);
    297 
    298 	/* XXX shouldn't be global */
    299 	pvr_stdscreen.nrows = dc->rinfo.ri_rows;
    300 	pvr_stdscreen.ncols = dc->rinfo.ri_cols;
    301 	pvr_stdscreen.textops = &dc->rinfo.ri_ops;
    302 	pvr_stdscreen.capabilities = dc->rinfo.ri_caps;
    303 
    304 	/* XXX yuck */
    305 	sprintf(pvr_stdscreen_textgeom, "%dx%d", pvr_stdscreen.ncols,
    306 	    pvr_stdscreen.nrows);
    307 }
    308 
    309 void
    310 pvr_attach(struct device *parent, struct device *self, void *aux)
    311 {
    312 	struct pvr_softc *sc = (void *) self;
    313 	struct wsemuldisplaydev_attach_args waa;
    314 	int console;
    315 	static const char *tvsystem_name[4] =
    316 		{ "NTSC", "PAL", "PAL-M", "PAL-N" };
    317 
    318 	console = pvr_is_console;
    319 	if (console) {
    320 		sc->sc_dc = &pvr_console_dc;
    321 		sc->nscreens = 1;
    322 	} else {
    323 		sc->sc_dc = malloc(sizeof(struct fb_devconfig), M_DEVBUF,
    324 		    M_WAITOK);
    325 		pvr_getdevconfig(sc->sc_dc);
    326 	}
    327 	printf(": %d x %d, %dbpp, %s, %s\n", sc->sc_dc->dc_wid,
    328 	    sc->sc_dc->dc_ht, sc->sc_dc->dc_depth,
    329 	    (sc->sc_dc->dc_dispflags & PVR_VGAMODE) ? "VGA" :
    330 	       tvsystem_name[sc->sc_dc->dc_tvsystem],
    331 	    (sc->sc_dc->dc_dispflags & PVR_RGBMODE) ? "RGB" : "composite");
    332 
    333 	/* XXX Colormap initialization? */
    334 
    335 	waa.console = console;
    336 	waa.scrdata = &pvr_screenlist;
    337 	waa.accessops = &pvr_accessops;
    338 	waa.accesscookie = sc;
    339 
    340 	(void) config_found(self, &waa, wsemuldisplaydevprint);
    341 }
    342 
    343 int
    344 pvrioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
    345 {
    346 	struct pvr_softc *sc = v;
    347 	struct fb_devconfig *dc = sc->sc_dc;
    348 
    349 	switch (cmd) {
    350 	case WSDISPLAYIO_GTYPE:
    351 		*(u_int *)data = WSDISPLAY_TYPE_DCPVR;
    352 		return (0);
    353 
    354 	case WSDISPLAYIO_GINFO:
    355 #define	wsd_fbip ((struct wsdisplay_fbinfo *)data)
    356 		wsd_fbip->height = sc->sc_dc->dc_ht;
    357 		wsd_fbip->width = sc->sc_dc->dc_wid;
    358 		wsd_fbip->depth = sc->sc_dc->dc_depth;
    359 		wsd_fbip->cmsize = 0;	/* XXX Colormap */
    360 #undef wsd_fbip
    361 		return (0);
    362 
    363 	case WSDISPLAYIO_GETCMAP:
    364 	case WSDISPLAYIO_PUTCMAP:
    365 		return (EPASSTHROUGH);	/* XXX Colormap */
    366 
    367 	case WSDISPLAYIO_SVIDEO:
    368 		return (EPASSTHROUGH);	/* XXX */
    369 
    370 	case WSDISPLAYIO_GVIDEO:
    371 		*(u_int *)data = dc->dc_blanked ?
    372 		    WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
    373 		return (0);
    374 
    375 	case WSDISPLAYIO_GCURPOS:
    376 	case WSDISPLAYIO_SCURPOS:
    377 	case WSDISPLAYIO_GCURMAX:
    378 	case WSDISPLAYIO_GCURSOR:
    379 	case WSDISPLAYIO_SCURSOR:
    380 		return (EPASSTHROUGH);	/* XXX */
    381 	}
    382 
    383 	return (EPASSTHROUGH);
    384 }
    385 
    386 paddr_t
    387 pvrmmap(void *v, off_t offset, int prot)
    388 {
    389 
    390 	/*
    391 	 * XXX This should be easy to support -- just need to define
    392 	 * XXX offsets for the contol regs, etc.
    393 	 */
    394 
    395 	struct pvr_softc *sc = v;
    396 	struct fb_devconfig *dc = sc->sc_dc;
    397 	paddr_t addr;
    398 
    399 	if (offset >= 0 &&
    400 	    offset < sh3_round_page(dc->dc_rowbytes * dc->dc_ht))
    401 		addr = sh3_btop(dc->dc_paddr + offset);
    402 	else
    403 		addr = (-1);	/* XXX bogus */
    404 
    405 	return addr;
    406 }
    407 
    408 int
    409 pvr_alloc_screen(void *v, const struct wsscreen_descr *type,
    410     void **cookiep, int *curxp, int *curyp, long *attrp)
    411 {
    412 	struct pvr_softc *sc = v;
    413 	long defattr;
    414 
    415 	if (sc->nscreens > 0)
    416 		return (ENOMEM);
    417 
    418 	*cookiep = &sc->sc_dc->rinfo; /* one and only for now */
    419 	*curxp = 0;
    420 	*curyp = 0;
    421 	(*sc->sc_dc->rinfo.ri_ops.allocattr)(&sc->sc_dc->rinfo, 0, 0, 0,
    422 	    &defattr);
    423 	*attrp = defattr;
    424 	sc->nscreens++;
    425 	return (0);
    426 }
    427 
    428 void
    429 pvr_free_screen(void *v, void *cookie)
    430 {
    431 	struct pvr_softc *sc = v;
    432 
    433 	if (sc->sc_dc == &pvr_console_dc)
    434 		panic("pvr_free_screen: console");
    435 
    436 	sc->nscreens--;
    437 }
    438 
    439 int
    440 pvr_show_screen(void *v, void *cookie, int waitok,
    441     void (*cb)(void *, int, int), void *cbarg)
    442 {
    443 
    444 	return (0);
    445 }
    446 
    447 static void
    448 pvr_check_cable(struct fb_devconfig *dc)
    449 {
    450 	__volatile u_int32_t *porta =
    451 	    (__volatile u_int32_t *)0xff80002c;
    452 	u_int16_t v;
    453 
    454 	/* PORT8 and PORT9 is input */
    455 	*porta = (*porta & ~0xf0000) | 0xa0000;
    456 
    457 	/* Read PORT8 and PORT9 */
    458 	v = ((*(__volatile u_int16_t *)(porta + 1)) >> 8) & 3;
    459 
    460 	if ((v & 2) == 0)
    461 		dc->dc_dispflags |= PVR_VGAMODE|PVR_RGBMODE;
    462 	else if ((v & 1) == 0)
    463 		dc->dc_dispflags |= PVR_RGBMODE;
    464 }
    465 
    466 static void
    467 pvr_check_tvsys(struct fb_devconfig *dc)
    468 {
    469 
    470 	/* XXX should use flashmem device when one exists */
    471 	dc->dc_tvsystem = (*(__volatile u_int8_t *)0xa021a004) & 3;
    472 }
    473 
    474 void
    475 pvrinit(struct fb_devconfig *dc)
    476 {
    477 	int display_lines_per_field;
    478 	int v_absolute_size;
    479 	int h_absolute_size;
    480 	int vborder_start, vborder_stop;
    481 	int hborder_start, hborder_stop;
    482 	int modulo = 1, voffset, hoffset;
    483 
    484 	pvr_check_cable(dc);
    485 	pvr_check_tvsys(dc);
    486 
    487 	PVR_REG_WRITE(dc, 8, 0);		/* reset */
    488 	PVR_REG_WRITE(dc, PVRREG_BRDCOLR, 0);	/* black border */
    489 
    490 	if (dc->dc_dispflags & PVR_VGAMODE) {
    491 		v_absolute_size = 524;
    492 		h_absolute_size = 857;
    493 
    494 		display_lines_per_field = 480;
    495 		hoffset = 164;
    496 		voffset = 36;
    497 
    498 		hborder_start = 126;
    499 		hborder_stop = 837;
    500 
    501 		vborder_start = 40;
    502 		vborder_stop = 444;		/* XXX */
    503 
    504 		/* 31kHz, RGB565 */
    505 		PVR_REG_WRITE(dc, PVRREG_DIWMODE,
    506 		    DIWMODE_C | DIWMODE_COL_RGB565);
    507 
    508 		/* video output */
    509 		PVR_REG_WRITE(dc, PVRREG_SYNCCONF, SYNCCONF_VO);
    510 	} else {
    511 		if (dc->dc_tvsystem & 1) {
    512 			/* 50 Hz PAL */
    513 			v_absolute_size = 624;
    514 			h_absolute_size = 863;
    515 
    516 			display_lines_per_field = 240;
    517 			hoffset = 174;
    518 			voffset = 18;
    519 
    520 			hborder_start = 116;
    521 			hborder_stop = 843;
    522 
    523 			vborder_start = 44;
    524 			vborder_stop = 536;	/* XXX */
    525 		} else {
    526 			/* 60 Hz NTSC */
    527 			v_absolute_size = 524;
    528 			h_absolute_size = 857;
    529 
    530 			display_lines_per_field = 240;
    531 			hoffset = 170;
    532 			voffset = 28;
    533 
    534 			hborder_start = 126;
    535 			hborder_stop = 837;
    536 
    537 			vborder_start = 18;
    538 			vborder_stop = 506;	/* XXX */
    539 		}
    540 
    541 		modulo += 640 * 2 / 4;	/* interlace -> skip every other line */
    542 
    543 		/* 15kHz, RGB565 */
    544 		PVR_REG_WRITE(dc, PVRREG_DIWMODE,
    545 		    DIWMODE_COL_RGB565);
    546 
    547 		/* video output, PAL/NTSC, interlace */
    548 		PVR_REG_WRITE(dc, PVRREG_SYNCCONF,
    549 		    SYNCCONF_VO | SYNCCONF_I | SYNCCONF_BC(dc->dc_tvsystem));
    550 	}
    551 
    552 	/* video base address, long field */
    553 	PVR_REG_WRITE(dc, PVRREG_DIWADDRL, 0);
    554 
    555 	/* video base address, short field */
    556 	PVR_REG_WRITE(dc, PVRREG_DIWADDRS, 640 * 2);
    557 
    558 	/* video size */
    559 	PVR_REG_WRITE(dc, PVRREG_DIWSIZE, DIWSIZE_MODULO(modulo) |
    560 	    DIWSIZE_LPF(display_lines_per_field - 1) |
    561 	    DIWSIZE_DPL(640 * 2 / 4 - 1));
    562 
    563 	PVR_REG_WRITE(dc, PVRREG_DIWVSTRT,		/* V start */
    564 	    DIWVSTRT_V1(voffset) | DIWVSTRT_V2(voffset));
    565 	PVR_REG_WRITE(dc, PVRREG_BRDVERT,		/* V border */
    566 	    BRDVERT_START(vborder_start) | BRDVERT_STOP(vborder_stop));
    567 	PVR_REG_WRITE(dc, PVRREG_DIWHSTRT, hoffset);	/* H start */
    568 	PVR_REG_WRITE(dc, PVRREG_SYNCSIZE,		/* HV counter */
    569 	    SYNCSIZE_V(v_absolute_size) | SYNCSIZE_H(h_absolute_size));
    570 	PVR_REG_WRITE(dc, PVRREG_BRDHORZ,		/* H border */
    571 	    BRDHORZ_START(hborder_start) | BRDHORZ_STOP(hborder_stop));
    572 	PVR_REG_WRITE(dc, PVRREG_DIWCONF, DIWCONF_MAGIC);
    573 
    574 	/* RGB / composite */
    575 	*(__volatile u_int32_t *)
    576 	    SH3_PHYS_TO_P2SEG(0x00702c00) =
    577 	    ((dc->dc_dispflags & PVR_RGBMODE) ? 0 : 3) << 8;
    578 
    579 	/* display on */
    580 	PVR_REG_WRITE(dc, PVRREG_DIWMODE,
    581 	    PVR_REG_READ(dc, PVRREG_DIWMODE) | DIWMODE_DE);
    582 }
    583 
    584 /* Console support. */
    585 
    586 void	pvrcnprobe(struct consdev *);
    587 void	pvrcninit(struct consdev *);
    588 
    589 void
    590 pvrcninit(struct consdev *cndev)
    591 {
    592 	struct fb_devconfig *dcp = &pvr_console_dc;
    593 	long defattr;
    594 
    595 	pvr_getdevconfig(dcp);
    596 	(*dcp->rinfo.ri_ops.allocattr)(&dcp->rinfo, 0, 0, 0, &defattr);
    597 	wsdisplay_cnattach(&pvr_stdscreen, &dcp->rinfo, 0, 0, defattr);
    598 
    599 	pvr_is_console = 1;
    600 
    601 	cn_tab->cn_pri = CN_INTERNAL;
    602 
    603 #if NMKBD > 0
    604 	mkbd_cnattach();	/* connect keyboard and screen together */
    605 #endif
    606 }
    607 
    608 void
    609 pvrcnprobe(struct consdev *cndev)
    610 {
    611 #if NWSDISPLAY > 0
    612 	int maj, unit;
    613 	extern const struct cdevsw wsdisplay_cdevsw;
    614 #endif
    615 	cndev->cn_dev = NODEV;
    616 	cndev->cn_pri = CN_NORMAL;
    617 
    618 #if NWSDISPLAY > 0
    619 	unit = 0;
    620 	maj = cdevsw_lookup_major(&wsdisplay_cdevsw);
    621 	if (maj != -1) {
    622 		cndev->cn_pri = CN_INTERNAL;
    623 		cndev->cn_dev = makedev(maj, unit);
    624 	}
    625 #endif
    626 }
    627