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