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