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