Home | History | Annotate | Line # | Download | only in hd64461
hd64461video.c revision 1.22
      1 /*	$NetBSD: hd64461video.c,v 1.22 2003/11/13 03:09:28 chs Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by UCHIYAMA Yasushi.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/cdefs.h>
     40 __KERNEL_RCSID(0, "$NetBSD: hd64461video.c,v 1.22 2003/11/13 03:09:28 chs Exp $");
     41 
     42 #include "debug_hpcsh.h"
     43 // #define HD64461VIDEO_HWACCEL
     44 
     45 #include <sys/param.h>
     46 #include <sys/systm.h>
     47 #include <sys/device.h>
     48 #include <sys/malloc.h>
     49 
     50 #include <sys/conf.h> /* cdev_decl */
     51 #include <dev/cons.h> /* consdev */
     52 
     53 /* ioctl */
     54 #include <sys/ioctl.h>
     55 #include <sys/buf.h>
     56 #include <uvm/uvm_extern.h>
     57 
     58 #include <machine/bus.h>
     59 #include <machine/intr.h>
     60 
     61 #include <hpcsh/dev/hd64461/hd64461var.h>
     62 #include <hpcsh/dev/hd64461/hd64461reg.h>
     63 #include <hpcsh/dev/hd64461/hd64461videoreg.h>
     64 
     65 #include <dev/wscons/wsdisplayvar.h>
     66 #include <dev/rasops/rasops.h>
     67 
     68 #include <dev/wscons/wsconsio.h>
     69 #include <dev/hpc/hpcfbvar.h>
     70 #include <dev/hpc/hpcfbio.h>
     71 #include <dev/hpc/video_subr.h>
     72 
     73 #include <machine/bootinfo.h>
     74 
     75 #ifdef	HD64461VIDEO_DEBUG
     76 #define DPRINTF_ENABLE
     77 #define DPRINTF_DEBUG	hd64461video_debug
     78 #endif
     79 #include <machine/debug.h>
     80 
     81 struct hd64461video_chip;
     82 struct hd64461video_font {
     83 	struct wsdisplay_font wsfont;
     84 	int c, cw, cstep;
     85 	int loaded;
     86 };
     87 
     88 struct hd64461video_softc {
     89 	struct device sc_dev;
     90 	enum hd64461_module_id sc_module_id;
     91 	struct hd64461video_chip *sc_vc;
     92 
     93 	struct hd64461video_font sc_font;
     94 };
     95 
     96 enum hd64461video_display_mode {
     97 	LCD256_C,
     98 	LCD64K_C,
     99 	LCD64_MONO,
    100 	LCD16_MONO,
    101 	LCD4_MONO,
    102 	LCD2_MONO,
    103 	CRT256_C,
    104 	LCDCRT
    105 };
    106 
    107 STATIC struct hd64461video_chip {
    108 	struct video_chip vc;
    109 	enum hd64461video_display_mode mode;
    110 	struct hpcfb_dspconf hd;
    111 	struct hpcfb_fbconf hf;
    112 	u_int8_t *off_screen_addr;
    113 	size_t off_screen_size;
    114 	int blanked;
    115 
    116 	int console;
    117 } hd64461video_chip;
    118 
    119 void	hd64461video_cnprobe(struct consdev *);
    120 void	hd64461video_cninit(struct consdev *);
    121 
    122 STATIC int hd64461video_match(struct device *, struct cfdata *, void *);
    123 STATIC void hd64461video_attach(struct device *, struct device *, void *);
    124 
    125 STATIC void hd64461video_setup_hpcfbif(struct hd64461video_chip *);
    126 STATIC void hd64461video_update_videochip_status(struct hd64461video_chip *);
    127 STATIC size_t hd64461video_frame_buffer_size(struct hd64461video_chip *);
    128 STATIC void hd64461video_hwaccel_init(struct hd64461video_chip *);
    129 
    130 STATIC void hd64461video_set_clut(struct hd64461video_chip *, int, int,
    131     u_int8_t *, u_int8_t *, u_int8_t *);
    132 STATIC void hd64461video_get_clut(struct hd64461video_chip *, int, int,
    133     u_int8_t *, u_int8_t *, u_int8_t *);
    134 STATIC void hd64461video_off(struct hd64461video_chip *vc);
    135 STATIC void hd64461video_on(struct hd64461video_chip *vc);
    136 
    137 #if notyet
    138 STATIC void hd64461video_set_display_mode(struct hd64461video_chip *);
    139 STATIC void hd64461video_set_display_mode_lcdc(struct hd64461video_chip *);
    140 STATIC void hd64461video_set_display_mode_crtc(struct hd64461video_chip *);
    141 #endif
    142 
    143 #ifdef HD64461VIDEO_DEBUG
    144 STATIC void hd64461video_info(struct hd64461video_softc *);
    145 STATIC void hd64461video_dump(void) __attribute__((__unused__));
    146 #endif
    147 
    148 CFATTACH_DECL(hd64461video, sizeof(struct hd64461video_softc),
    149     hd64461video_match, hd64461video_attach, NULL, NULL);
    150 
    151 int hd64461video_ioctl(void *, u_long, caddr_t, int, struct proc *);
    152 paddr_t hd64461video_mmap(void *, off_t, int);
    153 void hd64461video_cursor(void *, int, int, int, int, int);
    154 void hd64461video_bitblit(void *, int, int, int, int, int, int);
    155 void hd64461video_erase(void *, int, int, int, int, int);
    156 void hd64461video_putchar(void *, int, int, struct wsdisplay_font *, int, int,
    157     u_int, int);
    158 void hd64461video_setclut(void *, struct rasops_info *);
    159 void hd64461video_font(void *, struct wsdisplay_font *);
    160 void hd64461video_iodone(void *);
    161 
    162 struct hpcfb_accessops hd64461video_ha = {
    163 	.ioctl	= hd64461video_ioctl,
    164 	.mmap	= hd64461video_mmap,
    165 #ifdef HD64461VIDEO_HWACCEL
    166 	.cursor	= hd64461video_cursor,
    167 	.bitblit= hd64461video_bitblit,
    168 	.erase	= hd64461video_erase,
    169 	.putchar= hd64461video_putchar,
    170 	.setclut= hd64461video_setclut,
    171 	.font	= hd64461video_font,
    172 	.iodone	= hd64461video_iodone
    173 #endif /* HD64461VIDEO_HWACCEL */
    174 };
    175 
    176 /* font */
    177 STATIC void hd64461video_font_load_16bpp(u_int16_t *, u_int8_t *, int, int, int);
    178 STATIC void hd64461video_font_load_8bpp(u_int8_t *, u_int8_t *, int, int, int);
    179 STATIC void hd64461video_font_set_attr(struct hd64461video_softc *,
    180     struct wsdisplay_font *);
    181 STATIC void hd64461video_font_load(struct hd64461video_softc *);
    182 STATIC vaddr_t hd64461video_font_start_addr(struct hd64461video_softc *, int);
    183 
    184 int
    185 hd64461video_match(struct device *parent, struct cfdata *cf, void *aux)
    186 {
    187 	struct hd64461_attach_args *ha = aux;
    188 
    189 	return (ha->ha_module_id == HD64461_MODULE_VIDEO);
    190 }
    191 
    192 void
    193 hd64461video_attach(struct device *parent, struct device *self, void *aux)
    194 {
    195 	struct hd64461_attach_args *ha = aux;
    196 	struct hd64461video_softc *sc = (struct hd64461video_softc *)self;
    197 	struct hpcfb_attach_args hfa;
    198 	struct video_chip *vc = &hd64461video_chip.vc;
    199 	char pbuf[9];
    200 	size_t fbsize, on_screen_size;
    201 
    202 	sc->sc_module_id = ha->ha_module_id;
    203 	sc->sc_vc = &hd64461video_chip;
    204 	printf(": ");
    205 
    206 	/* detect frame buffer size */
    207 	fbsize = hd64461video_frame_buffer_size(&hd64461video_chip);
    208 	format_bytes(pbuf, sizeof(pbuf), fbsize);
    209 	printf("frame buffer = %s ", pbuf);
    210 
    211 	/* update chip status */
    212 	hd64461video_update_videochip_status(&hd64461video_chip);
    213 //	hd64461video_set_display_mode(&hd64461video_chip);
    214 
    215 	if (hd64461video_chip.console)
    216 		printf(", console");
    217 
    218 	printf("\n");
    219 #ifdef HD64461VIDEO_DEBUG
    220 	hd64461video_info(sc);
    221 	hd64461video_dump();
    222 #endif
    223 
    224 
    225 	/* setup hpcfb interface */
    226 	hd64461video_setup_hpcfbif(&hd64461video_chip);
    227 
    228 	/* setup off-screen buffer */
    229 	on_screen_size = (vc->vc_fbwidth * vc->vc_fbheight * vc->vc_fbdepth) /
    230 	    NBBY;
    231 	hd64461video_chip.off_screen_addr = (u_int8_t *)vc->vc_fbvaddr +
    232 	    on_screen_size;
    233 	hd64461video_chip.off_screen_size = fbsize - on_screen_size;
    234 	/* clean up off-screen area */
    235 	{
    236 		u_int8_t *p = hd64461video_chip.off_screen_addr;
    237 		u_int8_t *end = p + hd64461video_chip.off_screen_size;
    238 		while (p < end)
    239 			*p++ = 0xff;
    240 	}
    241 
    242 	/* initialize hardware acceralation */
    243 	hd64461video_hwaccel_init(&hd64461video_chip);
    244 
    245 	/* register interface to hpcfb */
    246 	hfa.ha_console	   = hd64461video_chip.console;
    247 	hfa.ha_accessops   = &hd64461video_ha;
    248 	hfa.ha_accessctx   = sc;
    249 	hfa.ha_curfbconf   = 0;
    250 	hfa.ha_nfbconf	   = 1;
    251 	hfa.ha_fbconflist  = &hd64461video_chip.hf;
    252 	hfa.ha_curdspconf  = 0;
    253 	hfa.ha_ndspconf	   = 1;
    254 	hfa.ha_dspconflist = &hd64461video_chip.hd;
    255 
    256 	config_found(self, &hfa, hpcfbprint);
    257 }
    258 
    259 /* console support */
    260 void
    261 hd64461video_cninit(struct consdev *cndev)
    262 {
    263 	hd64461video_chip.console = 1;
    264 	hd64461video_chip.vc.vc_reverse = video_reverse_color();
    265 
    266 	hd64461video_update_videochip_status(&hd64461video_chip);
    267 	hd64461video_setup_hpcfbif(&hd64461video_chip);
    268 	hpcfb_cnattach(&hd64461video_chip.hf);
    269 
    270 	cn_tab->cn_pri = CN_INTERNAL;
    271 }
    272 
    273 void
    274 hd64461video_cnprobe(struct consdev *cndev)
    275 {
    276 #if NWSDISPLAY > 0
    277 	extern const struct cdevsw wsdisplay_cdevsw;
    278 	int maj, unit;
    279 #endif
    280 	cndev->cn_dev = NODEV;
    281 	cndev->cn_pri = CN_NORMAL;
    282 
    283 #if NWSDISPLAY > 0
    284 	unit = 0;
    285 	maj = cdevsw_lookup_major(&wsdisplay_cdevsw);
    286 
    287 	if (maj != -1) {
    288 		cndev->cn_pri = CN_INTERNAL;
    289 		cndev->cn_dev = makedev(maj, unit);
    290 	}
    291 #endif /* NWSDISPLAY > 0 */
    292 }
    293 
    294 /* hpcfb support */
    295 void
    296 hd64461video_setup_hpcfbif(struct hd64461video_chip *hvc)
    297 {
    298 	struct video_chip *vc = &hvc->vc;
    299 	struct hpcfb_fbconf *fb = &hvc->hf;
    300 	vaddr_t fbvaddr = vc->vc_fbvaddr;
    301 	int height = vc->vc_fbheight;
    302 	int width = vc->vc_fbwidth;
    303 	int depth = vc->vc_fbdepth;
    304 
    305 	memset(fb, 0, sizeof(struct hpcfb_fbconf));
    306 
    307 	fb->hf_conf_index	= 0;	/* configuration index		*/
    308 	fb->hf_nconfs		= 1;   	/* how many configurations	*/
    309 	strncpy(fb->hf_name, "HD64461 video module", HPCFB_MAXNAMELEN);
    310 
    311 	/* frame buffer name */
    312 	strncpy(fb->hf_conf_name, "LCD", HPCFB_MAXNAMELEN);
    313 
    314 	/* configuration name */
    315 	fb->hf_height		= height;
    316 	fb->hf_width		= width;
    317 	fb->hf_baseaddr		= (u_long)fbvaddr;
    318 	fb->hf_offset		= (u_long)fbvaddr -
    319 	    sh3_ptob(sh3_btop(fbvaddr));
    320 
    321 	/* frame buffer start offset */
    322 	fb->hf_bytes_per_line	= (width * depth) / NBBY;
    323 	fb->hf_nplanes		= 1;
    324 	fb->hf_bytes_per_plane	= height * fb->hf_bytes_per_line;
    325 
    326 	fb->hf_access_flags |= HPCFB_ACCESS_BYTE;
    327 	fb->hf_access_flags |= HPCFB_ACCESS_WORD;
    328 	fb->hf_access_flags |= HPCFB_ACCESS_DWORD;
    329 	if (vc->vc_reverse)
    330 		fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
    331 
    332 	switch (depth) {
    333 	default:
    334 		panic("%s: not supported color depth", __FUNCTION__);
    335 		/* NOTREACHED */
    336 	case 16:
    337 		fb->hf_class = HPCFB_CLASS_RGBCOLOR;
    338 		fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
    339 		fb->hf_pack_width = 16;
    340 		fb->hf_pixels_per_pack = 1;
    341 		fb->hf_pixel_width = 16;
    342 
    343 		fb->hf_class_data_length = sizeof(struct hf_rgb_tag);
    344 		/* reserved for future use */
    345 		fb->hf_u.hf_rgb.hf_flags = 0;
    346 
    347 		fb->hf_u.hf_rgb.hf_red_width = 5;
    348 		fb->hf_u.hf_rgb.hf_red_shift = 11;
    349 		fb->hf_u.hf_rgb.hf_green_width = 6;
    350 		fb->hf_u.hf_rgb.hf_green_shift = 5;
    351 		fb->hf_u.hf_rgb.hf_blue_width = 5;
    352 		fb->hf_u.hf_rgb.hf_blue_shift = 0;
    353 		fb->hf_u.hf_rgb.hf_alpha_width = 0;
    354 		fb->hf_u.hf_rgb.hf_alpha_shift = 0;
    355 		break;
    356 
    357 	case 8:
    358 		fb->hf_class = HPCFB_CLASS_INDEXCOLOR;
    359 		fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
    360 		fb->hf_pack_width = 8;
    361 		fb->hf_pixels_per_pack = 1;
    362 		fb->hf_pixel_width = 8;
    363 		fb->hf_class_data_length = sizeof(struct hf_indexed_tag);
    364 		/* reserved for future use */
    365 		fb->hf_u.hf_indexed.hf_flags = 0;
    366 		break;
    367 	}
    368 }
    369 
    370 void
    371 hd64461video_hwaccel_init(struct hd64461video_chip *hvc)
    372 {
    373 	u_int16_t r;
    374 
    375 	r = HD64461_LCDGRCFGR_ACCRESET;
    376 	switch (hvc->vc.vc_fbdepth) {
    377 	default:
    378 		panic("no bitblit acceralation.");
    379 	case 16:
    380 		break;
    381 	case 8:
    382 		r |= HD64461_LCDGRCFGR_COLORDEPTH_8BPP;
    383 		break;
    384 	}
    385 	hd64461_reg_write_2(HD64461_LCDGRCFGR_REG16, r);
    386 
    387 	while ((hd64461_reg_read_2(HD64461_LCDGRCFGR_REG16) &
    388 	    HD64461_LCDGRCFGR_ACCSTATUS) != 0)
    389 		/* busy loop */;
    390 	r &= ~HD64461_LCDGRCFGR_ACCRESET;
    391 	hd64461_reg_write_2(HD64461_LCDGRCFGR_REG16, r);
    392 
    393 	while ((hd64461_reg_read_2(HD64461_LCDGRCFGR_REG16) &
    394 	    HD64461_LCDGRCFGR_ACCSTATUS) != 0)
    395 		/* busy loop */;
    396 
    397 	hd64461_reg_write_2(HD64461_LCDGRDOR_REG16,
    398 	    (hvc->vc.vc_fbwidth - 1) & HD64461_LCDGRDOR_MASK);
    399 }
    400 
    401 /* hpcfb ops */
    402 int
    403 hd64461video_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
    404 {
    405 	struct hd64461video_softc *sc = (struct hd64461video_softc *)v;
    406 	struct hpcfb_fbconf *hf = &sc->sc_vc->hf;
    407 	struct hpcfb_fbconf *fbconf;
    408 	struct hpcfb_dspconf *dspconf;
    409 	struct wsdisplay_cmap *cmap;
    410 	int turnoff;
    411 	u_int8_t *r, *g, *b;
    412 	int error;
    413 	size_t idx, cnt;
    414 
    415 	switch (cmd) {
    416 	case WSDISPLAYIO_GVIDEO:
    417 		*(u_int *)data = sc->sc_vc->blanked ?
    418 		    WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
    419 		return (0);
    420 
    421 	case WSDISPLAYIO_SVIDEO:
    422 		turnoff = (*(u_int *)data == WSDISPLAYIO_VIDEO_OFF);
    423 		if (sc->sc_vc->blanked != turnoff) {
    424 			sc->sc_vc->blanked = turnoff;
    425 			if (turnoff)
    426 				hd64461video_off(sc->sc_vc);
    427 			else
    428 				hd64461video_on(sc->sc_vc);
    429 		}
    430 
    431 		return (0);
    432 
    433 	case WSDISPLAYIO_GETCMAP:
    434 		cmap = (struct wsdisplay_cmap *)data;
    435 		cnt = cmap->count;
    436 		idx = cmap->index;
    437 
    438 		if (hf->hf_class != HPCFB_CLASS_INDEXCOLOR ||
    439 		    hf->hf_pack_width != 8 ||
    440 		    !LEGAL_CLUT_INDEX(idx) ||
    441 		    !LEGAL_CLUT_INDEX(idx + cnt -1)) {
    442 			return (EINVAL);
    443 		}
    444 
    445 		error = cmap_work_alloc(&r, &g, &b, 0, cnt);
    446 		if (error)
    447 			goto out;
    448 		hd64461video_get_clut(sc->sc_vc, idx, cnt, r, g, b);
    449 		error = copyout(r, cmap->red, cnt);
    450 		if (error)
    451 			goto out;
    452 		error = copyout(g, cmap->green,cnt);
    453 		if (error)
    454 			goto out;
    455 		error = copyout(b, cmap->blue, cnt);
    456 
    457 out:
    458 		cmap_work_free(r, g, b, 0);
    459 		return error;
    460 
    461 	case WSDISPLAYIO_PUTCMAP:
    462 		cmap = (struct wsdisplay_cmap *)data;
    463 		cnt = cmap->count;
    464 		idx = cmap->index;
    465 
    466 		if (hf->hf_class != HPCFB_CLASS_INDEXCOLOR ||
    467 		    hf->hf_pack_width != 8 ||
    468 		    !LEGAL_CLUT_INDEX(idx) ||
    469 		    !LEGAL_CLUT_INDEX(idx + cnt -1)) {
    470 			return (EINVAL);
    471 		}
    472 
    473 		error = cmap_work_alloc(&r, &g, &b, 0, cnt);
    474 		if (error)
    475 			goto out;
    476 
    477 		error = copyin(cmap->red, r, cnt);
    478 		if (error)
    479 			goto out;
    480 		error = copyin(cmap->green,g, cnt);
    481 		if (error)
    482 			goto out;
    483 		error = copyin(cmap->blue, b, cnt);
    484 		if (error)
    485 			goto out;
    486 		hd64461video_set_clut(sc->sc_vc, idx, cnt, r, g, b);
    487 		goto out;
    488 
    489 	case HPCFBIO_GCONF:
    490 		fbconf = (struct hpcfb_fbconf *)data;
    491 		if (fbconf->hf_conf_index != 0 &&
    492 		    fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
    493 			return (EINVAL);
    494 		}
    495 		*fbconf = *hf;	/* structure assignment */
    496 		return (0);
    497 
    498 	case HPCFBIO_SCONF:
    499 		fbconf = (struct hpcfb_fbconf *)data;
    500 		if (fbconf->hf_conf_index != 0 &&
    501 		    fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
    502 			return (EINVAL);
    503 		}
    504 		/*
    505 		 * nothing to do because we have only one configration
    506 		 */
    507 		return (0);
    508 
    509 	case HPCFBIO_GDSPCONF:
    510 		dspconf = (struct hpcfb_dspconf *)data;
    511 		if ((dspconf->hd_unit_index != 0 &&
    512 		    dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
    513 		    (dspconf->hd_conf_index != 0 &&
    514 			dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
    515 			return (EINVAL);
    516 		}
    517 		*dspconf = sc->sc_vc->hd;	/* structure assignment */
    518 		return (0);
    519 
    520 	case HPCFBIO_SDSPCONF:
    521 		dspconf = (struct hpcfb_dspconf *)data;
    522 		if ((dspconf->hd_unit_index != 0 &&
    523 		    dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
    524 		    (dspconf->hd_conf_index != 0 &&
    525 			dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
    526 			return (EINVAL);
    527 		}
    528 		/*
    529 		 * nothing to do
    530 		 * because we have only one unit and one configration
    531 		 */
    532 		return (0);
    533 
    534 	case HPCFBIO_GOP:
    535 	case HPCFBIO_SOP:
    536 		/* XXX not implemented yet */
    537 		return (EINVAL);
    538 	}
    539 
    540 	return (EPASSTHROUGH);
    541 }
    542 
    543 paddr_t
    544 hd64461video_mmap(void *ctx, off_t offset, int prot)
    545 {
    546 	struct hd64461video_softc *sc = (struct hd64461video_softc *)ctx;
    547 	struct hpcfb_fbconf *hf = &sc->sc_vc->hf;
    548 
    549 	if (offset < 0 || (hf->hf_bytes_per_plane + hf->hf_offset) < offset)
    550 		return (-1);
    551 
    552 	return (sh3_btop(HD64461_FBBASE + offset));
    553 }
    554 
    555 void
    556 hd64461video_cursor(void *ctx, int on, int xd, int yd, int w, int h)
    557 {
    558 	struct hd64461video_softc *sc = (struct hd64461video_softc *)ctx;
    559 	int xw, yh, width, bpp, adr;
    560 	u_int16_t r;
    561 
    562 	width = sc->sc_vc->vc.vc_fbwidth;
    563 	bpp = sc->sc_vc->vc.vc_fbdepth;
    564 	xw = w - 1;
    565 	yh = h - 1;
    566 
    567 	/* Wait until previous command done. */
    568 	hd64461video_iodone(ctx);
    569 
    570 	/* Destination addr */
    571 	adr = width * yd + xd;
    572 	if (bpp == 16)
    573 		adr *= 2;
    574 	hd64461_reg_write_2(HD64461_LCDBBTDSARH_REG16,
    575 	    HD64461_LCDBBTDSARH(adr));
    576 	hd64461_reg_write_2(HD64461_LCDBBTDSARL_REG16,
    577 	    HD64461_LCDBBTDSARL(adr));
    578 
    579 	// Width
    580 	hd64461_reg_write_2(HD64461_LCDBBTDWR_REG16,
    581 	    xw & HD64461_LCDBBTDWR_MASK);
    582 
    583 	// Height
    584 	hd64461_reg_write_2(HD64461_LCDBBTDHR_REG16,
    585 	    yh & HD64461_LCDBBTDHR_MASK);
    586 
    587 	// Operation (Destination Invert)
    588 	hd64461_reg_write_2(HD64461_LCDBBTROPR_REG16,
    589 	    HD64461_LCDC_BITBLT_DSTINVERT);
    590 
    591 	// BitBLT mode (Destination Invert)
    592 	hd64461_reg_write_2(HD64461_LCDBBTMDR_REG16, 0);
    593 
    594 	// Kick.
    595 	r = hd64461_reg_read_2(HD64461_LCDGRCFGR_REG16);
    596 	r &= ~HD64461_LCDGRCFGR_ACCSTART_MASK;
    597 	r |= HD64461_LCDGRCFGR_ACCSTART_BITBLT;
    598 	hd64461_reg_write_2(HD64461_LCDGRCFGR_REG16, r);
    599 }
    600 
    601 void
    602 hd64461video_bitblit(void *ctx, int xs, int ys, int xd, int yd, int h, int w)
    603 {
    604 	struct hd64461video_softc *sc = (struct hd64461video_softc *)ctx;
    605 	int xw, yh, width, bpp, condition_a, adr;
    606 	u_int16_t r;
    607 
    608 	xw = w - 1;
    609 	yh = h - 1;
    610 	width = sc->sc_vc->vc.vc_fbwidth;
    611 	bpp = sc->sc_vc->vc.vc_fbdepth;
    612 	condition_a = ((ys == yd) && (xs <= xd)) || (ys < yd);
    613 
    614 	hd64461video_iodone(ctx);
    615 
    616 	// Source addr
    617 	if (condition_a)
    618 		adr = (width * (ys + yh)) + (xs + xw);
    619 	else
    620 		adr = width * ys + xs;
    621 	if (bpp == 16)
    622 		adr *= 2;
    623 
    624 	hd64461_reg_write_2(HD64461_LCDBBTSSARH_REG16,
    625 	    HD64461_LCDBBTSSARH(adr));
    626 	hd64461_reg_write_2(HD64461_LCDBBTSSARL_REG16,
    627 	    HD64461_LCDBBTSSARL(adr));
    628 
    629 	// Destination addr
    630 	if (condition_a)
    631 		adr = (width * (yd + yh)) + (xd + xw);
    632 	else
    633 		adr = width * yd + xd;
    634 	if (bpp == 16)
    635 		adr *= 2;
    636 
    637 	hd64461_reg_write_2(HD64461_LCDBBTDSARH_REG16,
    638 	    HD64461_LCDBBTDSARH(adr));
    639 	hd64461_reg_write_2(HD64461_LCDBBTDSARL_REG16,
    640 	    HD64461_LCDBBTDSARL(adr));
    641 
    642 	// Width
    643 	hd64461_reg_write_2(HD64461_LCDBBTDWR_REG16,
    644 	    xw & HD64461_LCDBBTDWR_MASK);
    645 
    646 	// Height
    647 	hd64461_reg_write_2(HD64461_LCDBBTDHR_REG16,
    648 	    yh & HD64461_LCDBBTDHR_MASK);
    649 
    650 	// Operation (source copy)
    651 	hd64461_reg_write_2(HD64461_LCDBBTROPR_REG16,
    652 	    HD64461_LCDC_BITBLT_SRCCOPY);
    653 
    654 	// BitBLT mode (on screen to on screen)
    655 	r = HD64461_LCDBBTMDR_SET(0,
    656 	    HD64461_LCDBBTMDR_ON_SCREEN_TO_ON_SCREEN);
    657 	if (condition_a)	/* reverse direction */
    658 	    r |= HD64461_LCDBBTMDR_SCANDRCT_RL_BT;
    659 	hd64461_reg_write_2(HD64461_LCDBBTMDR_REG16, r);
    660 
    661 	// Kick.
    662 	r = hd64461_reg_read_2(HD64461_LCDGRCFGR_REG16);
    663 	r &= ~HD64461_LCDGRCFGR_ACCSTART_MASK;
    664 	r |= HD64461_LCDGRCFGR_ACCSTART_BITBLT;
    665 	hd64461_reg_write_2(HD64461_LCDGRCFGR_REG16, r);
    666 }
    667 
    668 void
    669 hd64461video_erase(void *ctx, int xd, int yd, int h, int w, int attr)
    670 {
    671 	struct hd64461video_softc *sc = (struct hd64461video_softc *)ctx;
    672 	int xw, yh, width, bpp, adr;
    673 	u_int16_t r;
    674 
    675 	width = sc->sc_vc->vc.vc_fbwidth;
    676 	bpp = sc->sc_vc->vc.vc_fbdepth;
    677 	xw = w - 1;
    678 	yh = h - 1;
    679 
    680 	/* Wait until previous command done. */
    681 	hd64461video_iodone(ctx);
    682 
    683 	/* Destination addr */
    684 	adr = width * yd + xd;
    685 	if (bpp == 16)
    686 		adr *= 2;
    687 	hd64461_reg_write_2(HD64461_LCDBBTDSARH_REG16,
    688 	    HD64461_LCDBBTDSARH(adr));
    689 	hd64461_reg_write_2(HD64461_LCDBBTDSARL_REG16,
    690 	    HD64461_LCDBBTDSARL(adr));
    691 
    692 	// Width
    693 	hd64461_reg_write_2(HD64461_LCDBBTDWR_REG16,
    694 	    xw & HD64461_LCDBBTDWR_MASK);
    695 
    696 	// Height
    697 	hd64461_reg_write_2(HD64461_LCDBBTDHR_REG16,
    698 	    yh & HD64461_LCDBBTDHR_MASK);
    699 
    700 	// Color
    701 	hd64461_reg_write_2(HD64461_LCDGRSCR_REG16, 0); //XXX black only
    702 
    703 	// Operation (Solid Color Fill)
    704 	hd64461_reg_write_2(HD64461_LCDBBTROPR_REG16,
    705 	    HD64461_LCDC_BITBLT_PATCOPY);
    706 
    707 	// BitBLT mode (Solid Color)
    708 	hd64461_reg_write_2(HD64461_LCDBBTMDR_REG16,
    709 	    HD64461_LCDBBTMDR_PATSELECT_SOLIDCOLOR);
    710 
    711 	// Kick.
    712 	r = hd64461_reg_read_2(HD64461_LCDGRCFGR_REG16);
    713 	r &= ~HD64461_LCDGRCFGR_ACCSTART_MASK;
    714 	r |= HD64461_LCDGRCFGR_ACCSTART_BITBLT;
    715 	hd64461_reg_write_2(HD64461_LCDGRCFGR_REG16, r);
    716 }
    717 
    718 void
    719 hd64461video_putchar(void *ctx, int row, int col, struct wsdisplay_font *font,
    720     int fclr, int uclr, u_int uc, int attr)
    721 {
    722 	struct hd64461video_softc *sc = (struct hd64461video_softc *)ctx;
    723 	int w, h, cw;
    724 
    725 	w = font->fontwidth;
    726 	h = font->fontheight;
    727 	cw = sc->sc_font.cw;
    728 	hd64461video_bitblit(ctx, (uc % cw) * w,
    729 	    sc->sc_vc->vc.vc_fbheight + (uc / cw) * h, row, col, h, w);
    730 }
    731 
    732 void
    733 hd64461video_setclut(void *ctx, struct rasops_info *info)
    734 {
    735 	struct hd64461video_softc *sc = (struct hd64461video_softc *)ctx;
    736 
    737 	if (sc->sc_vc->vc.vc_fbdepth != 8)
    738 		return;
    739 }
    740 
    741 void
    742 hd64461video_font(void *ctx, struct wsdisplay_font *font)
    743 {
    744 	struct hd64461video_softc *sc = (struct hd64461video_softc *)ctx;
    745 
    746 	hd64461video_font_set_attr(sc, font);
    747 	hd64461video_font_load(sc);
    748 }
    749 
    750 void
    751 hd64461video_iodone(void *ctx)
    752 {
    753 	while ((hd64461_reg_read_2(HD64461_LCDGRCFGR_REG16) &
    754 	    HD64461_LCDGRCFGR_ACCSTATUS) != 0)
    755 		/* busy loop */;
    756 }
    757 
    758 /* internal */
    759 void
    760 hd64461video_font_load_16bpp(u_int16_t *d, u_int8_t *s, int w, int h, int step)
    761 {
    762 	int i, j, n;
    763 	n = step / sizeof(u_int16_t);
    764 
    765 	for (i = 0; i < h; i++, d += n) {
    766 		for (j = 0; j < w; j++) {
    767 			d[j] = *s & (1 << (w - j - 1)) ? 0xffff : 0x0000;
    768 		}
    769 		s++;
    770 	}
    771 }
    772 
    773 void
    774 hd64461video_font_load_8bpp(u_int8_t *d, u_int8_t *s, int w, int h, int step)
    775 {
    776 	int i, j, n;
    777 	n = step / sizeof(u_int8_t);
    778 
    779 	for (i = 0; i < h; i++, d += n) {
    780 		for (j = 0; j < w; j++) {
    781 			d[j] = *s & (1 << (w - j - 1)) ? 0xff : 0x00;
    782 		}
    783 		s++;
    784 	}
    785 }
    786 
    787 void
    788 hd64461video_font_set_attr(struct hd64461video_softc *sc,
    789     struct wsdisplay_font *f)
    790 {
    791 	struct hd64461video_chip *hvc = sc->sc_vc;
    792 	struct wsdisplay_font *font = (struct wsdisplay_font *)&sc->sc_font;
    793 	int w, h, bpp;
    794 
    795 	w	= f->fontwidth;
    796 	h	= f->fontheight;
    797 	bpp	= hvc->vc.vc_fbdepth;
    798 
    799 	*font = *f;
    800 	sc->sc_font.c = (w * bpp) / NBBY;
    801 	sc->sc_font.cw = hvc->hf.hf_width / w;
    802 	sc->sc_font.cstep = ((w * h * bpp) / NBBY) * sc->sc_font.cw;
    803 
    804 	DPRINTF("c = %d cw = %d cstep = %d\n", sc->sc_font.c,
    805 	    sc->sc_font.cw, sc->sc_font.cstep);
    806 
    807 }
    808 
    809 /* return frame buffer virtual address of charcter #n */
    810 vaddr_t
    811 hd64461video_font_start_addr(struct hd64461video_softc *sc, int n)
    812 {
    813 	struct hd64461video_chip *hvc = sc->sc_vc;
    814 	struct hd64461video_font *font = &sc->sc_font;
    815 	vaddr_t base;
    816 
    817 	base = (vaddr_t)hvc->off_screen_addr;
    818 	base += (n / font->cw) * font->cstep + font->c * (n % font->cw);
    819 
    820 	return base;
    821 }
    822 
    823 void
    824 hd64461video_font_load(struct hd64461video_softc *sc)
    825 {
    826 	struct hd64461video_chip *hvc = sc->sc_vc;
    827 	struct wsdisplay_font *font = (struct wsdisplay_font *)&sc->sc_font;
    828 	u_int8_t *q;
    829 	int w, h, step, i, n;
    830 
    831 	if (sc->sc_font.loaded) {
    832 		printf("reload font\n");
    833 	}
    834 
    835 	w	= font->fontwidth;
    836 	h	= font->fontheight;
    837 	step	= sc->sc_font.cw * sc->sc_font.c;
    838 	n	= (w * h) / NBBY;
    839 	q	= font->data;
    840 
    841 	DPRINTF("%s (%dx%d) %d+%d\n", font->name, w, h, font->firstchar,
    842 	    font->numchars);
    843 	DPRINTF("bitorder %d byteorder %d stride %d\n", font->bitorder,
    844 	    font->byteorder, font->stride);
    845 
    846 	switch (hvc->vc.vc_fbdepth) {
    847 	case 8:
    848 		for (i = font->firstchar; i < font->numchars; i++) {
    849 			hd64461video_font_load_8bpp
    850 			    ((u_int8_t *)hd64461video_font_start_addr(sc, i),
    851 				q, w, h, step);
    852 			q += n;
    853 		}
    854 		break;
    855 	case 16:
    856 		for (i = font->firstchar; i < font->numchars; i++) {
    857 			hd64461video_font_load_16bpp
    858 			    ((u_int16_t *)hd64461video_font_start_addr(sc, i),
    859 				q, w, h, step);
    860 			q += n;
    861 		}
    862 		break;
    863 	}
    864 
    865 	sc->sc_font.loaded = TRUE;
    866 }
    867 
    868 void
    869 hd64461video_update_videochip_status(struct hd64461video_chip *hvc)
    870 {
    871 	struct video_chip *vc = &hvc->vc;
    872 	u_int16_t r;
    873 	int i;
    874 	int depth, width, height;
    875 
    876 	depth = 0;		/* XXX: -Wuninitialized */
    877 
    878 	/* display mode */
    879 	r = hd64461_reg_read_2(HD64461_LCDLDR3_REG16);
    880 	i = HD64461_LCDLDR3_CG(r);
    881 	switch (i) {
    882 	case HD64461_LCDLDR3_CG_COLOR16:
    883 		depth = 16;
    884 		hvc->mode = LCD64K_C;
    885 		break;
    886 	case HD64461_LCDLDR3_CG_COLOR8:
    887 		depth = 8;
    888 		hvc->mode = LCD256_C;
    889 		break;
    890 	case HD64461_LCDLDR3_CG_GRAY6:
    891 		depth = 6;
    892 		hvc->mode = LCD64_MONO;
    893 		break;
    894 	case HD64461_LCDLDR3_CG_GRAY4:
    895 		depth = 4;
    896 		hvc->mode = LCD16_MONO;
    897 		break;
    898 	case HD64461_LCDLDR3_CG_GRAY2:
    899 		depth = 2;
    900 		hvc->mode = LCD4_MONO;
    901 		break;
    902 	case HD64461_LCDLDR3_CG_GRAY1:
    903 		depth = 1;
    904 		hvc->mode = LCD2_MONO;
    905 		break;
    906 	}
    907 
    908 	r = hd64461_reg_read_2(HD64461_LCDCCR_REG16);
    909 	i = HD64461_LCDCCR_DSPSEL(i);
    910 	switch (i) {
    911 	case HD64461_LCDCCR_DSPSEL_LCD_CRT:
    912 		depth = 8;
    913 		hvc->mode = LCDCRT;
    914 		break;
    915 	case HD64461_LCDCCR_DSPSEL_CRT:
    916 		depth = 8;
    917 		hvc->mode = CRT256_C;
    918 		break;
    919 	case HD64461_LCDCCR_DSPSEL_LCD:
    920 		/* nothing to do */
    921 		break;
    922 	}
    923 
    924 	hvc->blanked = 0;	/* XXX */
    925 
    926 	width = bootinfo->fb_width;
    927 	height = bootinfo->fb_height;
    928 
    929 	vc->vc_fbvaddr	= HD64461_FBBASE;
    930 	vc->vc_fbpaddr	= HD64461_FBBASE;
    931 	vc->vc_fbdepth	= depth;
    932 	vc->vc_fbsize	= (width * height * depth) / NBBY;
    933 	vc->vc_fbwidth	= width;
    934 	vc->vc_fbheight	= height;
    935 }
    936 
    937 #if notyet
    938 void
    939 hd64461video_set_display_mode(struct hd64461video_chip *hvc)
    940 {
    941 
    942 	if (hvc->mode == LCDCRT || hvc->mode == CRT256_C)
    943 		hd64461video_set_display_mode_crtc(hvc);
    944 
    945 	hd64461video_set_display_mode_lcdc(hvc);
    946 }
    947 
    948 void
    949 hd64461video_set_display_mode_lcdc(struct hd64461video_chip *hvc)
    950 {
    951 	struct {
    952 		u_int16_t clor;	/* display size 640 x 240 */
    953 		u_int16_t ldr3;
    954 		const char *name;
    955 	} disp_conf[] = {
    956 		[LCD256_C]	= { 0x280 , HD64461_LCDLDR3_CG_COLOR8 ,
    957 				    "8bit color" },
    958 		[LCD64K_C]	= { 0x500 , HD64461_LCDLDR3_CG_COLOR16 ,
    959 				    "16bit color" },
    960 		[LCD64_MONO]	= { 0x280 , HD64461_LCDLDR3_CG_GRAY6 ,
    961 				    "6bit gray scale" },
    962 		[LCD16_MONO]	= { 0x140 , HD64461_LCDLDR3_CG_GRAY4 ,
    963 				    "4bit gray scale" },
    964 		[LCD4_MONO]	= { 0x0a0 , HD64461_LCDLDR3_CG_GRAY2 ,
    965 				    "2bit gray scale" },
    966 		[LCD2_MONO]	= { 0x050 , HD64461_LCDLDR3_CG_GRAY1 ,
    967 				    "mono chrome" },
    968 	}, *conf;
    969 	u_int16_t r;
    970 	int omode;
    971 
    972 	conf = &disp_conf[hvc->mode];
    973 
    974 	hd64461_reg_write_2(HD64461_LCDCLOR_REG16, conf->clor);
    975 	r = hd64461_reg_read_2(HD64461_LCDLDR3_REG16);
    976 	omode = HD64461_LCDLDR3_CG(r);
    977 	r = HD64461_LCDLDR3_CG_CLR(r);
    978 	r = HD64461_LCDLDR3_CG_SET(r, conf->ldr3);
    979 	hd64461_reg_write_2(HD64461_LCDLDR3_REG16, r);
    980 
    981 	printf("%s ", conf->name);
    982 }
    983 
    984 void
    985 hd64461video_set_display_mode_crtc(struct hd64461video_chip *hvc)
    986 {
    987 	/* not yet */
    988 }
    989 #endif /* notyet */
    990 
    991 size_t
    992 hd64461video_frame_buffer_size(struct hd64461video_chip *hvc)
    993 {
    994 	vaddr_t page, startaddr, endaddr;
    995 	int x;
    996 
    997 	startaddr = HD64461_FBBASE;
    998 	endaddr = startaddr + HD64461_FBSIZE - 1;
    999 
   1000 	page = startaddr;
   1001 
   1002 	x = random();
   1003 	*(volatile int *)(page + 0) = x;
   1004 	*(volatile int *)(page + 4) = ~x;
   1005 
   1006 	if (*(volatile int *)(page + 0) != x ||
   1007 	    *(volatile int *)(page + 4) != ~x)
   1008 		return (0);
   1009 
   1010 	for (page += HD64461_FBPAGESIZE; page < endaddr;
   1011 	    page += HD64461_FBPAGESIZE) {
   1012 		if (*(volatile int *)(page + 0) == x &&
   1013 		    *(volatile int *)(page + 4) == ~x)
   1014 			goto fbend_found;
   1015 	}
   1016 
   1017 	page -= HD64461_FBPAGESIZE;
   1018 	*(volatile int *)(page + 0) = x;
   1019 	*(volatile int *)(page + 4) = ~x;
   1020 
   1021 	if (*(volatile int *)(page + 0) != x ||
   1022 	    *(volatile int *)(page + 4) != ~x)
   1023 		return (0);
   1024 
   1025  fbend_found:
   1026 	return (page - startaddr);
   1027 }
   1028 
   1029 void
   1030 hd64461video_set_clut(struct hd64461video_chip *vc, int idx, int cnt,
   1031     u_int8_t *r, u_int8_t *g, u_int8_t *b)
   1032 {
   1033 	KASSERT(r && g && b);
   1034 
   1035 	/* index pallete */
   1036 	hd64461_reg_write_2(HD64461_LCDCPTWAR_REG16,
   1037 	    HD64461_LCDCPTWAR_SET(0, idx));
   1038 	/* set data */
   1039 	while (cnt && LEGAL_CLUT_INDEX(idx)) {
   1040 		u_int16_t v;
   1041 #define	HD64461VIDEO_SET_CLUT(x)					\
   1042 		v = (x >> 2) & 0x3f;					\
   1043 		hd64461_reg_write_2(HD64461_LCDCPTWDR_REG16, v)
   1044 		HD64461VIDEO_SET_CLUT(*r);
   1045 		HD64461VIDEO_SET_CLUT(*g);
   1046 		HD64461VIDEO_SET_CLUT(*b);
   1047 #undef	HD64461VIDEO_SET_CLUT
   1048 		r++, g++, b++;
   1049 		idx++, cnt--;
   1050 	}
   1051 }
   1052 
   1053 void
   1054 hd64461video_get_clut(struct hd64461video_chip *vc, int idx, int cnt,
   1055     u_int8_t *r, u_int8_t *g, u_int8_t *b)
   1056 {
   1057 	KASSERT(r && g && b);
   1058 
   1059 	/* index pallete */
   1060 	hd64461_reg_write_2(HD64461_LCDCPTRAR_REG16,
   1061 	    HD64461_LCDCPTRAR_SET(0, idx));
   1062 
   1063 	/* get data */
   1064 	while (cnt && LEGAL_CLUT_INDEX(idx)) {
   1065 		u_int16_t v;
   1066 #define	HD64461VIDEO_GET_CLUT(x)					\
   1067 	v = hd64461_reg_read_2(HD64461_LCDCPTWDR_REG16);		\
   1068 	x = HD64461_LCDCPTRDR(v);					\
   1069 	x <<= 2
   1070 		HD64461VIDEO_GET_CLUT(*r);
   1071 		HD64461VIDEO_GET_CLUT(*g);
   1072 		HD64461VIDEO_GET_CLUT(*b);
   1073 #undef	HD64461VIDEO_GET_CLUT
   1074 		r++, g++, b++;
   1075 		idx++, cnt--;
   1076 	}
   1077 }
   1078 
   1079 void
   1080 hd64461video_off(struct hd64461video_chip *vc)
   1081 {
   1082 	u_int16_t r;
   1083 
   1084 	r = hd64461_reg_read_2(HD64461_LCDLDR1_REG16);
   1085 	r &= ~HD64461_LCDLDR1_DON;
   1086 	hd64461_reg_write_2(HD64461_LCDLDR1_REG16, r);
   1087 }
   1088 
   1089 void
   1090 hd64461video_on(struct hd64461video_chip *vc)
   1091 {
   1092 	u_int16_t r;
   1093 
   1094 	r = hd64461_reg_read_2(HD64461_LCDLDR1_REG16);
   1095 	r |= HD64461_LCDLDR1_DON;
   1096 	hd64461_reg_write_2(HD64461_LCDLDR1_REG16, r);
   1097 }
   1098 
   1099 
   1100 #ifdef HD64461VIDEO_DEBUG
   1101 void
   1102 hd64461video_info(struct hd64461video_softc *sc)
   1103 {
   1104 	u_int16_t r;
   1105 	int color;
   1106 	int i;
   1107 
   1108 	dbg_banner_function();
   1109 	printf("---[LCD]---\n");
   1110 	/* Base Address Register */
   1111 	r = hd64461_reg_read_2(HD64461_LCDCBAR_REG16);
   1112 	printf("LCDCBAR Frame buffer base address (4k Byte align): 0x%08x\n",
   1113 	    HD64461_LCDCBAR_BASEADDR(r));
   1114 
   1115 	/* Line Address Offset Register */
   1116 	r = hd64461_reg_read_2(HD64461_LCDCLOR_REG16);
   1117 	printf("LCDCLOR Line address offset: %d\n", HD64461_LCDCLOR(r));
   1118 
   1119 	/* LCDC Control Register */
   1120 	r = hd64461_reg_read_2(HD64461_LCDCCR_REG16);
   1121 	i = HD64461_LCDCCR_DSPSEL(r);
   1122 #define	DBG_BITMASK_PRINT(r, m)	dbg_bitmask_print(r, HD64461_LCDCCR_##m, #m)
   1123 	printf("LCDCCR (LCD Control Register)\n");
   1124 	DBG_BITMASK_PRINT(r, STBAK);
   1125 	DBG_BITMASK_PRINT(r, STREQ);
   1126 	DBG_BITMASK_PRINT(r, MOFF);
   1127 	DBG_BITMASK_PRINT(r, REFSEL);
   1128 	DBG_BITMASK_PRINT(r, EPON);
   1129 	DBG_BITMASK_PRINT(r, SPON);
   1130 	printf("\n");
   1131 #undef	DBG_BITMASK_PRINT
   1132 	printf("LCDCCR Display selct LCD[%c] CRT[%c]\n",
   1133 	    i == HD64461_LCDCCR_DSPSEL_LCD_CRT ||
   1134 	    i == HD64461_LCDCCR_DSPSEL_LCD ? 'x' : '_',
   1135 	    i == HD64461_LCDCCR_DSPSEL_LCD_CRT ||
   1136 	    i == HD64461_LCDCCR_DSPSEL_CRT ? 'x' : '_');
   1137 
   1138 	/* LCD Display Register */
   1139 	/* 1 */
   1140 	r = hd64461_reg_read_2(HD64461_LCDLDR1_REG16);
   1141 	printf("(LCD Display Register)\n");
   1142 #define	DBG_BITMASK_PRINT(r, m)	dbg_bitmask_print(r, HD64461_LCDLDR1_##m, #m)
   1143 	printf("LCDLDR1: ");
   1144 	DBG_BITMASK_PRINT(r, DINV);
   1145 	DBG_BITMASK_PRINT(r, DON);
   1146 	printf("\n");
   1147 #undef	DBG_BITMASK_PRINT
   1148 	/* 2 */
   1149 	r = hd64461_reg_read_2(HD64461_LCDLDR2_REG16);
   1150 	i = HD64461_LCDLDR2_LM(r);
   1151 #define	DBG_BITMASK_PRINT(r, m)	dbg_bitmask_print(r, HD64461_LCDLDR2_##m, #m)
   1152 	printf("LCDLDR2: ");
   1153 	DBG_BITMASK_PRINT(r, CC1);
   1154 	DBG_BITMASK_PRINT(r, CC2);
   1155 #undef	DBG_BITMASK_PRINT
   1156 	color = 0;
   1157 	switch (i) {
   1158 	default:
   1159 		panic("unknown unknown LCD interface.");
   1160 		break;
   1161 	case HD64461_LCDLDR2_LM_COLOR:
   1162 		color = 1;
   1163 		printf("Color");
   1164 		break;
   1165 	case HD64461_LCDLDR2_LM_GRAY8:
   1166 		printf("8-bit grayscale");
   1167 		break;
   1168 	case HD64461_LCDLDR2_LM_GRAY4:
   1169 		printf("8-bit grayscale");
   1170 		break;
   1171 	}
   1172 	printf(" LCD interface\n");
   1173 	/* 3 */
   1174 	printf("LCDLDR3: ");
   1175 	r = hd64461_reg_read_2(HD64461_LCDLDR3_REG16);
   1176 	i = HD64461_LCDLDR3_CS(r);
   1177 	printf("CS ");
   1178 	switch (i) {
   1179 	case 0:
   1180 		printf("15");
   1181 		break;
   1182 	case 1:
   1183 		printf("2.5");
   1184 		break;
   1185 	case 2:
   1186 		printf("3.75");
   1187 		break;
   1188 	case 4:
   1189 		printf("5");
   1190 		break;
   1191 	case 8:
   1192 		printf("7.5");
   1193 		break;
   1194 	case 16:
   1195 		printf("10");
   1196 		break;
   1197 	}
   1198 	printf("%s MHz ", color ? "" : "/2");
   1199 	i = HD64461_LCDLDR3_CG(r);
   1200 	switch (i) {
   1201 	case HD64461_LCDLDR3_CG_COLOR16:
   1202 		printf("Color 64K colors\n");
   1203 		break;
   1204 	case HD64461_LCDLDR3_CG_COLOR8:
   1205 		printf("Color 256 colors\n");
   1206 		break;
   1207 	case HD64461_LCDLDR3_CG_GRAY6:
   1208 		printf("6-bit Grayscale\n");
   1209 		break;
   1210 	case HD64461_LCDLDR3_CG_GRAY4:
   1211 		printf("4-bit Grayscale\n");
   1212 		break;
   1213 	case HD64461_LCDLDR3_CG_GRAY2:
   1214 		printf("2-bit Grayscale\n");
   1215 		break;
   1216 	case HD64461_LCDLDR3_CG_GRAY1:
   1217 		printf("1-bit Grayscale\n");
   1218 		break;
   1219 	}
   1220 
   1221 	/* LCD Number of Characters in Horizontal Register */
   1222 	r = hd64461_reg_read_2(HD64461_LCDLDHNCR_REG16);
   1223 	printf("LDHNCR: NHD %d NHT %d (# of horizontal characters)\n",
   1224 	    HD64461_LCDLDHNCR_NHD(r), HD64461_LCDLDHNCR_NHT(r));
   1225 
   1226 	/* Start Position of Horizontal Register */
   1227 	r = hd64461_reg_read_2(HD64461_LCDLDHNSR_REG16);
   1228 	printf("LDHNSR: HSW %d HSP %d (start position of horizontal)\n",
   1229 	    HD64461_LCDLDHNSR_HSW(r), HD64461_LCDLDHNSR_HSP(r));
   1230 
   1231 	/* Total Vertical Lines Register */
   1232 	r = hd64461_reg_read_2(HD64461_LCDLDVNTR_REG16);
   1233 	printf("LDVNTR: %d (total vertical lines)\n",
   1234 	    HD64461_LCDLDVNTR_VTL(r));
   1235 
   1236 	/* Display Vertical Lines Register */
   1237 	r = hd64461_reg_read_2(HD64461_LCDLDVNDR_REG16);
   1238 	printf("LDVNDR: %d (display vertical lines)\n",
   1239 	    HD64461_LCDLDVSPR_VSP(r));
   1240 
   1241 	/* Vertical Synchronization Position Register */
   1242 	r = hd64461_reg_read_2(HD64461_LCDLDVSPR_REG16);
   1243 	printf("LDVSPR: %d (vertical synchronization position)\n",
   1244 	    HD64461_LCDLDVSPR_VSP(r));
   1245 
   1246 	/*
   1247 	 * CRT Control Register
   1248 	 */
   1249 	printf("---[CRT]---\n");
   1250 	r = hd64461_reg_read_2(HD64461_LCDCRTVTR_REG16);
   1251 	printf("CRTVTR: %d (CRTC total vertical lines)\n",
   1252 	    HD64461_LCDCRTVTR(r));
   1253 	r = hd64461_reg_read_2(HD64461_LCDCRTVRSR_REG16);
   1254 	printf("CRTVRSR: %d (CRTC vertical retrace start line)\n",
   1255 	    HD64461_LCDCRTVRSR(r));
   1256 	r = hd64461_reg_read_2(HD64461_LCDCRTVRER_REG16);
   1257 	printf("CRTVRER: %d (CRTC vertical retrace end line)\n",
   1258 	    HD64461_LCDCRTVRER(r));
   1259 
   1260 }
   1261 
   1262 void
   1263 hd64461video_dump()
   1264 {
   1265 	u_int16_t r;
   1266 	printf("---[Display Mode Setting]---\n");
   1267 #define	DUMPREG(x)							\
   1268 	r = hd64461_reg_read_2(HD64461_LCD ## x ## _REG16);		\
   1269 	__dbg_bit_print(r, sizeof(u_int16_t), 0, 0, #x, DBG_BIT_PRINT_COUNT)
   1270 	DUMPREG(CBAR);
   1271 	DUMPREG(CLOR);
   1272 	DUMPREG(CCR);
   1273 	DUMPREG(LDR1);
   1274 	DUMPREG(LDR2);
   1275 	DUMPREG(LDHNCR);
   1276 	DUMPREG(LDHNSR);
   1277 	DUMPREG(LDVNTR);
   1278 	DUMPREG(LDVNDR);
   1279 	DUMPREG(LDVSPR);
   1280 	DUMPREG(LDR3);
   1281 	DUMPREG(CRTVTR);
   1282 	DUMPREG(CRTVRSR);
   1283 	DUMPREG(CRTVRER);
   1284 #undef	DUMPREG
   1285 	dbg_banner_line();
   1286 }
   1287 
   1288 #endif /* HD64461VIDEO_DEBUG */
   1289