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