Home | History | Annotate | Line # | Download | only in tx
tx3912video.c revision 1.26
      1  1.26       uch /*	$NetBSD: tx3912video.c,v 1.26 2002/03/06 15:01:06 uch Exp $ */
      2   1.1       uch 
      3  1.11       uch /*-
      4  1.26       uch  * Copyright (c) 1999-2002 The NetBSD Foundation, Inc.
      5  1.18       uch  * All rights reserved.
      6  1.18       uch  *
      7  1.18       uch  * This code is derived from software contributed to The NetBSD Foundation
      8  1.18       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.10       uch  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.10       uch  *    notice, this list of conditions and the following disclaimer in the
     17  1.10       uch  *    documentation and/or other materials provided with the distribution.
     18  1.18       uch  * 3. All advertising materials mentioning features or use of this software
     19  1.18       uch  *    must display the following acknowledgement:
     20  1.18       uch  *        This product includes software developed by the NetBSD
     21  1.18       uch  *        Foundation, Inc. and its contributors.
     22  1.18       uch  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.18       uch  *    contributors may be used to endorse or promote products derived
     24  1.18       uch  *    from this software without specific prior written permission.
     25   1.1       uch  *
     26  1.18       uch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.18       uch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.18       uch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.18       uch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.18       uch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.18       uch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.18       uch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.18       uch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.18       uch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.18       uch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.18       uch  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1       uch  */
     38  1.18       uch 
     39  1.15       uch #define TX3912VIDEO_DEBUG
     40  1.10       uch 
     41   1.8       uch #include "hpcfb.h"
     42  1.26       uch #include "bivideo.h"
     43   1.1       uch 
     44   1.1       uch #include <sys/param.h>
     45   1.1       uch #include <sys/systm.h>
     46   1.1       uch #include <sys/device.h>
     47   1.1       uch #include <sys/extent.h>
     48   1.1       uch 
     49  1.11       uch #include <sys/ioctl.h>
     50  1.12       uch #include <sys/buf.h>
     51  1.17       mrg 
     52  1.17       mrg #include <uvm/uvm_extern.h>
     53  1.11       uch 
     54  1.19       uch #include <dev/cons.h> /* consdev */
     55  1.19       uch 
     56   1.1       uch #include <machine/bus.h>
     57  1.10       uch #include <machine/bootinfo.h>
     58  1.18       uch #include <machine/config_hook.h>
     59   1.1       uch 
     60   1.1       uch #include <hpcmips/tx/tx39var.h>
     61   1.1       uch #include <hpcmips/tx/tx3912videovar.h>
     62   1.1       uch #include <hpcmips/tx/tx3912videoreg.h>
     63   1.1       uch 
     64  1.12       uch /* CLUT */
     65  1.12       uch #include <dev/wscons/wsdisplayvar.h>
     66  1.12       uch #include <dev/rasops/rasops.h>
     67  1.22       uch #include <dev/hpc/video_subr.h>
     68  1.12       uch 
     69   1.9      sato #include <dev/wscons/wsconsio.h>
     70  1.22       uch #include <dev/hpc/hpcfbvar.h>
     71  1.22       uch #include <dev/hpc/hpcfbio.h>
     72  1.26       uch #if NBIVIDEO > 0
     73  1.26       uch #include <dev/hpc/bivideovar.h>
     74  1.26       uch #endif
     75   1.2       uch 
     76  1.18       uch #ifdef TX3912VIDEO_DEBUG
     77  1.18       uch int	tx3912video_debug = 1;
     78  1.18       uch #define	DPRINTF(arg) if (tx3912video_debug) printf arg;
     79  1.18       uch #define	DPRINTFN(n, arg) if (tx3912video_debug > (n)) printf arg;
     80  1.18       uch #else
     81  1.18       uch #define	DPRINTF(arg)
     82  1.18       uch #define DPRINTFN(n, arg)
     83  1.18       uch #endif
     84  1.18       uch 
     85   1.1       uch struct tx3912video_softc {
     86   1.1       uch 	struct device sc_dev;
     87  1.18       uch 	void *sc_powerhook;	/* power management hook */
     88  1.19       uch 	int sc_console;
     89  1.11       uch 	struct hpcfb_fbconf sc_fbconf;
     90  1.11       uch 	struct hpcfb_dspconf sc_dspconf;
     91  1.15       uch 	struct video_chip *sc_chip;
     92   1.1       uch };
     93   1.1       uch 
     94  1.15       uch /* TX3912 built-in video chip itself */
     95  1.15       uch static struct video_chip tx3912video_chip;
     96  1.15       uch 
     97  1.18       uch int	tx3912video_power(void *, int, long, void *);
     98  1.18       uch void	tx3912video_framebuffer_init(struct video_chip *);
     99  1.18       uch int	tx3912video_framebuffer_alloc(struct video_chip *, paddr_t, paddr_t *);
    100  1.18       uch void	tx3912video_reset(struct video_chip *);
    101  1.18       uch void	tx3912video_resolution_init(struct video_chip *);
    102  1.18       uch int	tx3912video_match(struct device *, struct cfdata *, void *);
    103  1.18       uch void	tx3912video_attach(struct device *, struct device *, void *);
    104  1.18       uch int	tx3912video_print(void *, const char *);
    105  1.18       uch 
    106  1.18       uch void	tx3912video_hpcfbinit(struct tx3912video_softc *);
    107  1.18       uch int	tx3912video_ioctl(void *, u_long, caddr_t, int, struct proc *);
    108  1.18       uch paddr_t	tx3912video_mmap(void *, off_t, int);
    109  1.18       uch 
    110  1.18       uch void	tx3912video_clut_init(struct tx3912video_softc *);
    111  1.18       uch void	tx3912video_clut_install(void *, struct rasops_info *);
    112  1.23       uch void	tx3912video_clut_get(struct tx3912video_softc *, u_int32_t *, int,
    113  1.23       uch 	    int);
    114  1.18       uch 
    115  1.18       uch static int __get_color8(int);
    116  1.18       uch static int __get_color4(int);
    117  1.12       uch 
    118   1.1       uch struct cfattach tx3912video_ca = {
    119   1.3       uch 	sizeof(struct tx3912video_softc), tx3912video_match,
    120   1.3       uch 	tx3912video_attach
    121   1.1       uch };
    122   1.1       uch 
    123  1.11       uch struct hpcfb_accessops tx3912video_ha = {
    124  1.12       uch 	tx3912video_ioctl, tx3912video_mmap, 0, 0, 0, 0,
    125  1.12       uch 	tx3912video_clut_install
    126  1.11       uch };
    127  1.11       uch 
    128   1.1       uch int
    129  1.18       uch tx3912video_match(struct device *parent, struct cfdata *cf, void *aux)
    130   1.1       uch {
    131  1.23       uch 	return (ATTACH_NORMAL);
    132   1.1       uch }
    133   1.1       uch 
    134   1.1       uch void
    135  1.18       uch tx3912video_attach(struct device *parent, struct device *self, void *aux)
    136   1.1       uch {
    137  1.10       uch 	struct tx3912video_softc *sc = (void *)self;
    138  1.15       uch 	struct video_chip *chip;
    139  1.10       uch 	const char *depth_print[] = {
    140  1.10       uch 		[TX3912_VIDEOCTRL1_BITSEL_MONOCHROME] = "monochrome",
    141  1.10       uch 		[TX3912_VIDEOCTRL1_BITSEL_2BITGREYSCALE] = "2bit greyscale",
    142  1.10       uch 		[TX3912_VIDEOCTRL1_BITSEL_4BITGREYSCALE] = "4bit greyscale",
    143  1.10       uch 		[TX3912_VIDEOCTRL1_BITSEL_8BITCOLOR] = "8bit color"
    144  1.10       uch 	};
    145  1.11       uch 	struct hpcfb_attach_args ha;
    146  1.12       uch 	tx_chipset_tag_t tc;
    147  1.12       uch 	txreg_t val;
    148  1.19       uch 	int console;
    149  1.10       uch 
    150  1.19       uch 	sc->sc_console = console = cn_tab ? 0 : 1;
    151  1.10       uch 	sc->sc_chip = chip = &tx3912video_chip;
    152  1.10       uch 
    153  1.10       uch 	/* print video module information */
    154  1.10       uch 	printf(": %s, frame buffer 0x%08x-0x%08x\n",
    155  1.23       uch 	    depth_print[(ffs(chip->vc_fbdepth) - 1) & 0x3],
    156  1.23       uch 	    (unsigned)chip->vc_fbpaddr,
    157  1.23       uch 	    (unsigned)(chip->vc_fbpaddr + chip->vc_fbsize));
    158   1.5       uch 
    159  1.12       uch 	/* don't inverse VDAT[3:0] signal */
    160  1.15       uch 	tc = chip->vc_v;
    161  1.12       uch 	val = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
    162  1.12       uch 	val &= ~TX3912_VIDEOCTRL1_INVVID;
    163  1.12       uch 	tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, val);
    164  1.12       uch 
    165  1.12       uch 	/* install default CLUT */
    166  1.12       uch 	tx3912video_clut_init(sc);
    167  1.12       uch 
    168  1.10       uch 	/* if serial console, power off video module */
    169  1.19       uch 	tx3912video_power(sc, 0, 0, (void *)
    170  1.23       uch 	    (console ? PWR_RESUME : PWR_SUSPEND));
    171  1.19       uch 
    172  1.18       uch 	/* Add a hard power hook to power saving */
    173  1.18       uch 	sc->sc_powerhook = config_hook(CONFIG_HOOK_PMEVENT,
    174  1.23       uch 	    CONFIG_HOOK_PMEVENT_HARDPOWER, CONFIG_HOOK_SHARE,
    175  1.23       uch 	    tx3912video_power, sc);
    176  1.18       uch 	if (sc->sc_powerhook == 0)
    177  1.18       uch 		printf("WARNING unable to establish hard power hook");
    178   1.6       uch 
    179  1.13       uch #ifdef TX3912VIDEO_DEBUG
    180  1.10       uch 	/* attach debug draw routine (debugging use) */
    181  1.15       uch 	video_attach_drawfunc(sc->sc_chip);
    182  1.15       uch 	tx_conf_register_video(tc, sc->sc_chip);
    183  1.13       uch #endif
    184  1.10       uch 
    185   1.1       uch 	/* Attach frame buffer device */
    186  1.11       uch 	tx3912video_hpcfbinit(sc);
    187  1.11       uch 
    188  1.11       uch 	if (console && hpcfb_cnattach(&sc->sc_fbconf) != 0) {
    189  1.11       uch 		panic("tx3912video_attach: can't init fb console");
    190   1.2       uch 	}
    191  1.11       uch 
    192  1.11       uch 	ha.ha_console = console;
    193  1.11       uch 	ha.ha_accessops = &tx3912video_ha;
    194  1.11       uch 	ha.ha_accessctx = sc;
    195  1.11       uch 	ha.ha_curfbconf = 0;
    196  1.11       uch 	ha.ha_nfbconf = 1;
    197  1.11       uch 	ha.ha_fbconflist = &sc->sc_fbconf;
    198  1.11       uch 	ha.ha_curdspconf = 0;
    199  1.11       uch 	ha.ha_ndspconf = 1;
    200  1.11       uch 	ha.ha_dspconflist = &sc->sc_dspconf;
    201  1.11       uch 
    202  1.11       uch 	config_found(self, &ha, hpcfbprint);
    203  1.26       uch #if NBIVIDEO > 0
    204  1.26       uch 	/* bivideo is no longer need */
    205  1.26       uch 	bivideo_dont_attach = 1;
    206  1.26       uch #endif /* NBIVIDEO > 0 */
    207   1.1       uch }
    208   1.1       uch 
    209  1.18       uch int
    210  1.18       uch tx3912video_power(void *ctx, int type, long id, void *msg)
    211  1.18       uch {
    212  1.18       uch 	struct tx3912video_softc *sc = ctx;
    213  1.18       uch 	struct video_chip *chip = sc->sc_chip;
    214  1.18       uch 	tx_chipset_tag_t tc = chip->vc_v;
    215  1.18       uch 	int why = (int)msg;
    216  1.18       uch 	txreg_t val;
    217  1.18       uch 
    218  1.18       uch 	switch (why) {
    219  1.18       uch 	case PWR_RESUME:
    220  1.19       uch 		if (!sc->sc_console)
    221  1.23       uch 			return (0); /* serial console */
    222  1.19       uch 
    223  1.18       uch 		DPRINTF(("%s: ON\n", sc->sc_dev.dv_xname));
    224  1.18       uch 		val = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
    225  1.18       uch 		val |= (TX3912_VIDEOCTRL1_DISPON | TX3912_VIDEOCTRL1_ENVID);
    226  1.18       uch 		tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, val);
    227  1.18       uch 		break;
    228  1.18       uch 	case PWR_SUSPEND:
    229  1.18       uch 		/* FALLTHROUGH */
    230  1.18       uch 	case PWR_STANDBY:
    231  1.18       uch 		DPRINTF(("%s: OFF\n", sc->sc_dev.dv_xname));
    232  1.18       uch 		val = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
    233  1.18       uch 		val &= ~(TX3912_VIDEOCTRL1_DISPON | TX3912_VIDEOCTRL1_ENVID);
    234  1.18       uch 		tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, val);
    235  1.18       uch 		break;
    236  1.18       uch 	}
    237  1.18       uch 
    238  1.23       uch 	return (0);
    239  1.18       uch }
    240  1.18       uch 
    241  1.11       uch void
    242  1.11       uch tx3912video_hpcfbinit(sc)
    243  1.11       uch 	struct tx3912video_softc *sc;
    244   1.1       uch {
    245  1.15       uch 	struct video_chip *chip = sc->sc_chip;
    246  1.11       uch 	struct hpcfb_fbconf *fb = &sc->sc_fbconf;
    247  1.15       uch 	vaddr_t fbvaddr = (vaddr_t)MIPS_PHYS_TO_KSEG1(chip->vc_fbpaddr);
    248  1.11       uch 
    249  1.11       uch 	memset(fb, 0, sizeof(struct hpcfb_fbconf));
    250  1.11       uch 
    251  1.11       uch 	fb->hf_conf_index	= 0;	/* configuration index		*/
    252  1.11       uch 	fb->hf_nconfs		= 1;   	/* how many configurations	*/
    253  1.12       uch 	strncpy(fb->hf_name, "TX3912 built-in video", HPCFB_MAXNAMELEN);
    254  1.11       uch 					/* frame buffer name		*/
    255  1.12       uch 	strncpy(fb->hf_conf_name, "LCD", HPCFB_MAXNAMELEN);
    256  1.11       uch 					/* configuration name		*/
    257  1.11       uch 	fb->hf_height		= chip->vc_fbheight;
    258  1.11       uch 	fb->hf_width		= chip->vc_fbwidth;
    259  1.21  takemura 	fb->hf_baseaddr		= (u_long)fbvaddr;
    260  1.21  takemura 	fb->hf_offset		= (u_long)fbvaddr -
    261  1.23       uch 	    mips_ptob(mips_btop(fbvaddr));
    262  1.11       uch 					/* frame buffer start offset   	*/
    263  1.12       uch 	fb->hf_bytes_per_line	= (chip->vc_fbwidth * chip->vc_fbdepth)
    264  1.23       uch 	    / NBBY;
    265  1.11       uch 	fb->hf_nplanes		= 1;
    266  1.11       uch 	fb->hf_bytes_per_plane	= chip->vc_fbheight * fb->hf_bytes_per_line;
    267  1.11       uch 
    268  1.11       uch 	fb->hf_access_flags |= HPCFB_ACCESS_BYTE;
    269  1.11       uch 	fb->hf_access_flags |= HPCFB_ACCESS_WORD;
    270  1.11       uch 	fb->hf_access_flags |= HPCFB_ACCESS_DWORD;
    271  1.20       uch 	if (video_reverse_color())
    272  1.20       uch 		fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
    273  1.20       uch 
    274  1.11       uch 
    275  1.11       uch 	switch (chip->vc_fbdepth) {
    276  1.11       uch 	default:
    277  1.11       uch 		panic("tx3912video_hpcfbinit: not supported color depth\n");
    278  1.11       uch 		/* NOTREACHED */
    279  1.11       uch 	case 2:
    280  1.11       uch 		fb->hf_class = HPCFB_CLASS_GRAYSCALE;
    281  1.11       uch 		fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
    282  1.11       uch 		fb->hf_pack_width = 8;
    283  1.11       uch 		fb->hf_pixels_per_pack = 4;
    284  1.11       uch 		fb->hf_pixel_width = 2;
    285  1.11       uch 		fb->hf_class_data_length = sizeof(struct hf_gray_tag);
    286  1.14       uch 		/* reserved for future use */
    287  1.14       uch 		fb->hf_u.hf_gray.hf_flags = 0;
    288  1.11       uch 		break;
    289  1.11       uch 	case 8:
    290  1.25       uch 		fb->hf_order_flags = HPCFB_REVORDER_BYTE | HPCFB_REVORDER_WORD;
    291  1.12       uch 		fb->hf_class = HPCFB_CLASS_INDEXCOLOR;
    292  1.11       uch 		fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
    293  1.11       uch 		fb->hf_pack_width = 8;
    294  1.11       uch 		fb->hf_pixels_per_pack = 1;
    295  1.11       uch 		fb->hf_pixel_width = 8;
    296  1.11       uch 		fb->hf_class_data_length = sizeof(struct hf_indexed_tag);
    297  1.14       uch 		/* reserved for future use */
    298  1.14       uch 		fb->hf_u.hf_indexed.hf_flags = 0;
    299  1.11       uch 		break;
    300  1.11       uch 	}
    301   1.1       uch }
    302   1.1       uch 
    303   1.1       uch int
    304  1.18       uch tx3912video_init(paddr_t fb_start, paddr_t *fb_end)
    305  1.10       uch {
    306  1.15       uch 	struct video_chip *chip = &tx3912video_chip;
    307   1.1       uch 	tx_chipset_tag_t tc;
    308   1.7       uch 	txreg_t reg;
    309  1.19       uch 	int fbdepth, reverse, error;
    310   1.1       uch 
    311  1.19       uch 	reverse = video_reverse_color();
    312  1.15       uch 	chip->vc_v = tc = tx_conf_get_tag();
    313  1.10       uch 
    314  1.10       uch 	reg = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
    315  1.10       uch 	fbdepth = 1 << (TX3912_VIDEOCTRL1_BITSEL(reg));
    316   1.7       uch 
    317  1.10       uch 	switch (fbdepth) {
    318   1.7       uch 	case 2:
    319  1.19       uch 		bootinfo->fb_type = reverse ? BIFB_D2_M2L_3 : BIFB_D2_M2L_0;
    320   1.7       uch 		break;
    321   1.7       uch 	case 4:
    322   1.7       uch 		/* XXX should implement rasops4.c */
    323  1.10       uch 		fbdepth = 2;
    324  1.19       uch 		bootinfo->fb_type = reverse ? BIFB_D2_M2L_3 : BIFB_D2_M2L_0;
    325   1.7       uch 		reg = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
    326   1.7       uch 		TX3912_VIDEOCTRL1_BITSEL_CLR(reg);
    327  1.23       uch 		reg = TX3912_VIDEOCTRL1_BITSEL_SET(reg,
    328  1.23       uch 		    TX3912_VIDEOCTRL1_BITSEL_2BITGREYSCALE);
    329   1.7       uch 		tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, reg);
    330   1.7       uch 		break;
    331   1.7       uch 	case 8:
    332  1.19       uch 		bootinfo->fb_type = reverse ? BIFB_D8_FF : BIFB_D8_00;
    333   1.7       uch 		break;
    334   1.7       uch 	}
    335   1.7       uch 
    336  1.15       uch 	chip->vc_fbdepth = fbdepth;
    337  1.15       uch 	chip->vc_fbwidth = bootinfo->fb_width;
    338  1.15       uch 	chip->vc_fbheight= bootinfo->fb_height;
    339   1.7       uch 
    340   1.1       uch 	/* Allocate framebuffer area */
    341  1.10       uch 	error = tx3912video_framebuffer_alloc(chip, fb_start, fb_end);
    342  1.10       uch 	if (error != 0)
    343  1.10       uch 		return (1);
    344  1.10       uch 
    345   1.1       uch #if notyet
    346  1.10       uch 	tx3912video_resolution_init(chip);
    347   1.1       uch #else
    348   1.1       uch 	/* Use Windows CE setting. */
    349   1.1       uch #endif
    350   1.1       uch 	/* Set DMA transfer address to VID module */
    351  1.10       uch 	tx3912video_framebuffer_init(chip);
    352   1.1       uch 
    353   1.1       uch 	/* Syncronize framebuffer addr to frame signal */
    354  1.10       uch 	tx3912video_reset(chip);
    355   1.1       uch 
    356  1.10       uch 	bootinfo->fb_line_bytes = (chip->vc_fbwidth * fbdepth) / NBBY;
    357  1.15       uch 	bootinfo->fb_addr = (void *)MIPS_PHYS_TO_KSEG1(chip->vc_fbpaddr);
    358  1.10       uch 
    359  1.10       uch 	return (0);
    360   1.1       uch }
    361   1.1       uch 
    362  1.23       uch int
    363  1.18       uch tx3912video_framebuffer_alloc(struct video_chip *chip, paddr_t fb_start,
    364  1.23       uch     paddr_t *fb_end /* buffer allocation hint */)
    365   1.1       uch {
    366  1.10       uch 	struct extent_fixed ex_fixed[10];
    367   1.1       uch 	struct extent *ex;
    368   1.1       uch 	u_long addr, size;
    369  1.10       uch 	int error;
    370  1.10       uch 
    371  1.10       uch 	/* calcurate frame buffer size */
    372  1.10       uch 	size = (chip->vc_fbwidth * chip->vc_fbheight * chip->vc_fbdepth) /
    373  1.23       uch 	    NBBY;
    374  1.10       uch 
    375  1.10       uch 	/* extent V-RAM region */
    376  1.10       uch 	ex = extent_create("Frame buffer address", fb_start, *fb_end,
    377  1.23       uch 	    0, (caddr_t)ex_fixed, sizeof ex_fixed,
    378  1.23       uch 	    EX_NOWAIT);
    379  1.10       uch 	if (ex == 0)
    380  1.10       uch 		return (1);
    381   1.1       uch 
    382   1.1       uch 	/* Allocate V-RAM area */
    383  1.14       uch 	error = extent_alloc_subregion(ex, fb_start, fb_start + size - 1,
    384  1.23       uch 	    size, TX3912_FRAMEBUFFER_ALIGNMENT,
    385  1.23       uch 	    TX3912_FRAMEBUFFER_BOUNDARY, EX_FAST|EX_NOWAIT, &addr);
    386  1.10       uch 	extent_destroy(ex);
    387  1.10       uch 
    388  1.23       uch 	if (error != 0)
    389  1.10       uch 		return (1);
    390  1.10       uch 
    391  1.15       uch 	chip->vc_fbpaddr = addr;
    392  1.15       uch 	chip->vc_fbvaddr = MIPS_PHYS_TO_KSEG1(addr);
    393  1.10       uch 	chip->vc_fbsize = size;
    394   1.6       uch 
    395  1.10       uch 	*fb_end = addr + size;
    396   1.1       uch 
    397  1.10       uch 	return (0);
    398   1.1       uch }
    399   1.1       uch 
    400  1.18       uch void
    401  1.18       uch tx3912video_framebuffer_init(struct video_chip *chip)
    402   1.1       uch {
    403  1.10       uch 	u_int32_t fb_addr, fb_size, vaddr, bank, base;
    404  1.10       uch 	txreg_t reg;
    405  1.15       uch 	tx_chipset_tag_t tc = chip->vc_v;
    406  1.10       uch 
    407  1.15       uch 	fb_addr = chip->vc_fbpaddr;
    408  1.10       uch 	fb_size = chip->vc_fbsize;
    409   1.1       uch 
    410   1.1       uch 	/*  XXX currently I don't set DFVAL, so force DF signal toggled on
    411   1.1       uch          *  XXX each frame. */
    412   1.1       uch 	reg = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
    413   1.1       uch 	reg &= ~TX3912_VIDEOCTRL1_DFMODE;
    414   1.1       uch 	tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, reg);
    415   1.1       uch 
    416   1.1       uch 	/* Set DMA transfer start and end address */
    417  1.10       uch 
    418   1.1       uch 	bank = TX3912_VIDEOCTRL3_VIDBANK(fb_addr);
    419   1.1       uch 	base = TX3912_VIDEOCTRL3_VIDBASEHI(fb_addr);
    420   1.1       uch 	reg = TX3912_VIDEOCTRL3_VIDBANK_SET(0, bank);
    421   1.1       uch 	/* Upper address counter */
    422   1.1       uch 	reg = TX3912_VIDEOCTRL3_VIDBASEHI_SET(reg, base);
    423   1.1       uch 	tx_conf_write(tc, TX3912_VIDEOCTRL3_REG, reg);
    424   1.1       uch 
    425   1.1       uch 	/* Lower address counter  */
    426   1.1       uch 	base = TX3912_VIDEOCTRL4_VIDBASELO(fb_addr + fb_size);
    427   1.1       uch 	reg = TX3912_VIDEOCTRL4_VIDBASELO_SET(0, base);
    428   1.1       uch 
    429   1.1       uch 	/* Set DF-signal rate */
    430   1.1       uch 	reg = TX3912_VIDEOCTRL4_DFVAL_SET(reg, 0); /* XXX not yet*/
    431   1.1       uch 
    432   1.1       uch 	/* Set VIDDONE signal delay after FRAME signal */
    433   1.1       uch 	/* XXX not yet*/
    434   1.1       uch 	tx_conf_write(tc, TX3912_VIDEOCTRL4_REG, reg);
    435   1.1       uch 
    436   1.1       uch 	/* Clear frame buffer */
    437   1.1       uch 	vaddr = MIPS_PHYS_TO_KSEG1(fb_addr);
    438  1.10       uch 	memset((void*)vaddr, 0, fb_size);
    439   1.1       uch }
    440   1.1       uch 
    441  1.18       uch void
    442  1.18       uch tx3912video_resolution_init(struct video_chip *chip)
    443   1.1       uch {
    444  1.10       uch 	int h, v, split, bit8, horzval, lineval;
    445  1.15       uch 	tx_chipset_tag_t tc = chip->vc_v;
    446  1.10       uch 	txreg_t reg;
    447  1.10       uch 	u_int32_t val;
    448  1.10       uch 
    449  1.10       uch 	h = chip->vc_fbwidth;
    450  1.10       uch 	v = chip->vc_fbheight;
    451   1.1       uch 	reg = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
    452   1.1       uch 	split = reg & TX3912_VIDEOCTRL1_DISPSPLIT;
    453   1.1       uch 	bit8  = (TX3912_VIDEOCTRL1_BITSEL(reg) ==
    454  1.23       uch 	    TX3912_VIDEOCTRL1_BITSEL_8BITCOLOR);
    455   1.1       uch 	val = TX3912_VIDEOCTRL1_BITSEL(reg);
    456   1.1       uch 
    457  1.23       uch 	if ((val == TX3912_VIDEOCTRL1_BITSEL_8BITCOLOR) && !split) {
    458   1.3       uch 		/* (LCD horizontal pixels / 8bit) * RGB - 1 */
    459   1.3       uch 		horzval = (h / 8) * 3 - 1;
    460   1.1       uch 	} else {
    461   1.1       uch 		horzval = h / 4 - 1;
    462   1.1       uch 	}
    463   1.1       uch 	lineval = (split ? v / 2 : v) - 1;
    464   1.1       uch 
    465   1.1       uch 	/* Video rate */
    466   1.3       uch 	/* XXX
    467   1.3       uch 	 *  probably This value should be determined from DFINT and LCDINT
    468   1.3       uch 	 */
    469   1.1       uch 	reg = TX3912_VIDEOCTRL2_VIDRATE_SET(0, horzval + 1);
    470   1.1       uch 	/* Horizontal size of LCD */
    471   1.1       uch 	reg = TX3912_VIDEOCTRL2_HORZVAL_SET(reg, horzval);
    472   1.1       uch 	/* # of lines for the LCD */
    473   1.1       uch 	reg = TX3912_VIDEOCTRL2_LINEVAL_SET(reg, lineval);
    474   1.1       uch 
    475   1.1       uch 	tx_conf_write(tc, TX3912_VIDEOCTRL2_REG, reg);
    476   1.1       uch }
    477   1.1       uch 
    478   1.1       uch void
    479  1.18       uch tx3912video_reset(struct video_chip *chip)
    480   1.1       uch {
    481  1.15       uch 	tx_chipset_tag_t tc = chip->vc_v;
    482  1.10       uch 	txreg_t reg;
    483   1.1       uch 
    484   1.1       uch 	reg = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
    485   1.3       uch 
    486   1.1       uch 	/* Disable video logic at end of this frame */
    487   1.1       uch 	reg |= TX3912_VIDEOCTRL1_ENFREEZEFRAME;
    488   1.1       uch 	tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, reg);
    489   1.3       uch 
    490   1.1       uch 	/* Wait for end of frame */
    491  1.10       uch 	delay(30 * 1000);
    492   1.3       uch 
    493   1.1       uch 	/* Make sure to disable video logic */
    494   1.1       uch 	reg &= ~TX3912_VIDEOCTRL1_ENVID;
    495   1.1       uch 	tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, reg);
    496   1.3       uch 
    497   1.1       uch 	delay(1000);
    498   1.3       uch 
    499   1.1       uch 	/* Enable video logic again */
    500   1.1       uch 	reg &= ~TX3912_VIDEOCTRL1_ENFREEZEFRAME;
    501   1.1       uch 	reg |= TX3912_VIDEOCTRL1_ENVID;
    502   1.1       uch 	tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, reg);
    503   1.3       uch 
    504   1.1       uch 	delay(1000);
    505   1.1       uch }
    506   1.1       uch 
    507  1.11       uch int
    508  1.18       uch tx3912video_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
    509  1.11       uch {
    510  1.11       uch 	struct tx3912video_softc *sc = (struct tx3912video_softc *)v;
    511  1.11       uch 	struct hpcfb_fbconf *fbconf;
    512  1.11       uch 	struct hpcfb_dspconf *dspconf;
    513  1.12       uch 	struct wsdisplay_cmap *cmap;
    514  1.12       uch 	u_int8_t *r, *g, *b;
    515  1.12       uch 	u_int32_t *rgb;
    516  1.12       uch 	int idx, cnt, error;
    517  1.11       uch 
    518  1.11       uch 	switch (cmd) {
    519  1.11       uch 	case WSDISPLAYIO_GETCMAP:
    520  1.12       uch 		cmap = (struct wsdisplay_cmap*)data;
    521  1.12       uch 		cnt = cmap->count;
    522  1.12       uch 		idx = cmap->index;
    523  1.12       uch 
    524  1.12       uch 		if (sc->sc_fbconf.hf_class != HPCFB_CLASS_INDEXCOLOR ||
    525  1.23       uch 		    sc->sc_fbconf.hf_pack_width != 8 ||
    526  1.23       uch 		    !LEGAL_CLUT_INDEX(idx) ||
    527  1.23       uch 		    !LEGAL_CLUT_INDEX(idx + cnt -1)) {
    528  1.12       uch 			return (EINVAL);
    529  1.12       uch 		}
    530  1.12       uch 
    531  1.12       uch 		if (!uvm_useracc(cmap->red, cnt, B_WRITE) ||
    532  1.12       uch 		    !uvm_useracc(cmap->green, cnt, B_WRITE) ||
    533  1.12       uch 		    !uvm_useracc(cmap->blue, cnt, B_WRITE)) {
    534  1.12       uch 			return (EFAULT);
    535  1.12       uch 		}
    536  1.12       uch 
    537  1.12       uch 		error = cmap_work_alloc(&r, &g, &b, &rgb, cnt);
    538  1.12       uch 		if (error != 0) {
    539  1.12       uch 			cmap_work_free(r, g, b, rgb);
    540  1.12       uch 			return  (ENOMEM);
    541  1.12       uch 		}
    542  1.12       uch 		tx3912video_clut_get(sc, rgb, idx, cnt);
    543  1.12       uch 		rgb24_decompose(rgb, r, g, b, cnt);
    544  1.12       uch 
    545  1.12       uch 		copyout(r, cmap->red, cnt);
    546  1.12       uch 		copyout(g, cmap->green,cnt);
    547  1.12       uch 		copyout(b, cmap->blue, cnt);
    548  1.12       uch 
    549  1.12       uch 		cmap_work_free(r, g, b, rgb);
    550  1.12       uch 
    551  1.12       uch 		return (0);
    552  1.11       uch 
    553  1.11       uch 	case WSDISPLAYIO_PUTCMAP:
    554  1.12       uch 		/*
    555  1.12       uch 		 * TX3912 can't change CLUT index. R:G:B = 3:3:2
    556  1.12       uch 		 */
    557  1.14       uch 		return (0);
    558  1.11       uch 
    559  1.11       uch 	case HPCFBIO_GCONF:
    560  1.11       uch 		fbconf = (struct hpcfb_fbconf *)data;
    561  1.11       uch 		if (fbconf->hf_conf_index != 0 &&
    562  1.11       uch 		    fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
    563  1.11       uch 			return (EINVAL);
    564  1.11       uch 		}
    565  1.11       uch 		*fbconf = sc->sc_fbconf;	/* structure assignment */
    566  1.11       uch 		return (0);
    567  1.11       uch 
    568  1.11       uch 	case HPCFBIO_SCONF:
    569  1.11       uch 		fbconf = (struct hpcfb_fbconf *)data;
    570  1.11       uch 		if (fbconf->hf_conf_index != 0 &&
    571  1.11       uch 		    fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
    572  1.11       uch 			return (EINVAL);
    573  1.11       uch 		}
    574  1.11       uch 		/*
    575  1.11       uch 		 * nothing to do because we have only one configration
    576  1.11       uch 		 */
    577  1.11       uch 		return (0);
    578  1.11       uch 
    579  1.11       uch 	case HPCFBIO_GDSPCONF:
    580  1.11       uch 		dspconf = (struct hpcfb_dspconf *)data;
    581  1.11       uch 		if ((dspconf->hd_unit_index != 0 &&
    582  1.23       uch 		    dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
    583  1.11       uch 		    (dspconf->hd_conf_index != 0 &&
    584  1.23       uch 			dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
    585  1.11       uch 			return (EINVAL);
    586  1.11       uch 		}
    587  1.11       uch 		*dspconf = sc->sc_dspconf;	/* structure assignment */
    588  1.11       uch 		return (0);
    589  1.11       uch 
    590  1.11       uch 	case HPCFBIO_SDSPCONF:
    591  1.11       uch 		dspconf = (struct hpcfb_dspconf *)data;
    592  1.11       uch 		if ((dspconf->hd_unit_index != 0 &&
    593  1.23       uch 		    dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
    594  1.11       uch 		    (dspconf->hd_conf_index != 0 &&
    595  1.23       uch 			dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
    596  1.11       uch 			return (EINVAL);
    597  1.11       uch 		}
    598  1.11       uch 		/*
    599  1.11       uch 		 * nothing to do
    600  1.11       uch 		 * because we have only one unit and one configration
    601  1.11       uch 		 */
    602  1.11       uch 		return (0);
    603  1.11       uch 
    604  1.11       uch 	case HPCFBIO_GOP:
    605  1.11       uch 	case HPCFBIO_SOP:
    606  1.11       uch 		/* XXX not implemented yet */
    607  1.11       uch 		return (EINVAL);
    608  1.11       uch 	}
    609  1.11       uch 
    610  1.11       uch 	return (ENOTTY);
    611  1.11       uch }
    612  1.11       uch 
    613  1.16    simonb paddr_t
    614  1.18       uch tx3912video_mmap(void *ctx, off_t offset, int prot)
    615  1.11       uch {
    616  1.11       uch 	struct tx3912video_softc *sc = (struct tx3912video_softc *)ctx;
    617  1.11       uch 
    618  1.11       uch 	if (offset < 0 || (sc->sc_fbconf.hf_bytes_per_plane +
    619  1.23       uch 	    sc->sc_fbconf.hf_offset) <  offset) {
    620  1.11       uch 		return (-1);
    621  1.11       uch 	}
    622  1.11       uch 
    623  1.15       uch 	return (mips_btop(sc->sc_chip->vc_fbpaddr + offset));
    624  1.12       uch }
    625  1.12       uch 
    626  1.12       uch /*
    627  1.12       uch  * CLUT staff
    628  1.12       uch  */
    629  1.12       uch static const struct {
    630  1.12       uch 	int mul, div;
    631  1.12       uch } dither_list [] = {
    632  1.12       uch 	[TX3912_VIDEO_DITHER_DUTYCYCLE_1]	= { 1, 1 },
    633  1.12       uch 	[TX3912_VIDEO_DITHER_DUTYCYCLE_6_7]	= { 6, 7 },
    634  1.12       uch 	[TX3912_VIDEO_DITHER_DUTYCYCLE_4_5]	= { 4, 5 },
    635  1.12       uch 	[TX3912_VIDEO_DITHER_DUTYCYCLE_3_4]	= { 3, 4 },
    636  1.12       uch 	[TX3912_VIDEO_DITHER_DUTYCYCLE_5_7]	= { 5, 7 },
    637  1.12       uch 	[TX3912_VIDEO_DITHER_DUTYCYCLE_2_3]	= { 2, 3 },
    638  1.12       uch 	[TX3912_VIDEO_DITHER_DUTYCYCLE_3_5]	= { 3, 5 },
    639  1.12       uch 	[TX3912_VIDEO_DITHER_DUTYCYCLE_4_7]	= { 4, 7 },
    640  1.12       uch 	[TX3912_VIDEO_DITHER_DUTYCYCLE_2_4]	= { 2, 4 },
    641  1.12       uch 	[TX3912_VIDEO_DITHER_DUTYCYCLE_3_7]	= { 3, 7 },
    642  1.12       uch 	[TX3912_VIDEO_DITHER_DUTYCYCLE_2_5]	= { 2, 5 },
    643  1.12       uch 	[TX3912_VIDEO_DITHER_DUTYCYCLE_1_3]	= { 1, 3 },
    644  1.12       uch 	[TX3912_VIDEO_DITHER_DUTYCYCLE_2_7]	= { 2, 7 },
    645  1.12       uch 	[TX3912_VIDEO_DITHER_DUTYCYCLE_1_5]	= { 1, 5 },
    646  1.12       uch 	[TX3912_VIDEO_DITHER_DUTYCYCLE_1_7]	= { 1, 7 },
    647  1.12       uch 	[TX3912_VIDEO_DITHER_DUTYCYCLE_0]	= { 0, 1 }
    648  1.12       uch }, *dlp;
    649  1.12       uch 
    650  1.12       uch static const int dither_level8[8] = {
    651  1.12       uch 	TX3912_VIDEO_DITHER_DUTYCYCLE_0,
    652  1.12       uch 	TX3912_VIDEO_DITHER_DUTYCYCLE_2_7,
    653  1.12       uch 	TX3912_VIDEO_DITHER_DUTYCYCLE_2_5,
    654  1.12       uch 	TX3912_VIDEO_DITHER_DUTYCYCLE_2_4,
    655  1.12       uch 	TX3912_VIDEO_DITHER_DUTYCYCLE_3_5,
    656  1.12       uch 	TX3912_VIDEO_DITHER_DUTYCYCLE_5_7,
    657  1.12       uch 	TX3912_VIDEO_DITHER_DUTYCYCLE_4_5,
    658  1.12       uch 	TX3912_VIDEO_DITHER_DUTYCYCLE_1,
    659  1.12       uch };
    660  1.12       uch 
    661  1.12       uch static const int dither_level4[4] = {
    662  1.12       uch 	TX3912_VIDEO_DITHER_DUTYCYCLE_0,
    663  1.12       uch 	TX3912_VIDEO_DITHER_DUTYCYCLE_1_3,
    664  1.12       uch 	TX3912_VIDEO_DITHER_DUTYCYCLE_5_7,
    665  1.12       uch 	TX3912_VIDEO_DITHER_DUTYCYCLE_1,
    666  1.12       uch };
    667  1.12       uch 
    668  1.12       uch static int
    669  1.18       uch __get_color8(int luti)
    670  1.12       uch {
    671  1.12       uch 	KASSERT(luti >=0 && luti < 8);
    672  1.12       uch 	dlp = &dither_list[dither_level8[luti]];
    673  1.12       uch 
    674  1.12       uch 	return ((0xff * dlp->mul) / dlp->div);
    675  1.12       uch }
    676  1.12       uch 
    677  1.12       uch static int
    678  1.18       uch __get_color4(int luti)
    679  1.12       uch {
    680  1.12       uch 	KASSERT(luti >=0 && luti < 4);
    681  1.12       uch 	dlp = &dither_list[dither_level4[luti]];
    682  1.12       uch 
    683  1.12       uch 	return ((0xff * dlp->mul) / dlp->div);
    684  1.12       uch }
    685  1.12       uch 
    686  1.12       uch void
    687  1.18       uch tx3912video_clut_get(struct tx3912video_softc *sc, u_int32_t *rgb, int beg,
    688  1.23       uch     int cnt)
    689  1.12       uch {
    690  1.12       uch 	int i;
    691  1.12       uch 
    692  1.12       uch 	KASSERT(rgb);
    693  1.12       uch 	KASSERT(LEGAL_CLUT_INDEX(beg));
    694  1.12       uch 	KASSERT(LEGAL_CLUT_INDEX(beg + cnt - 1));
    695  1.12       uch 
    696  1.14       uch 	for (i = beg; i < beg + cnt; i++) {
    697  1.14       uch 		*rgb++ =  RGB24(__get_color8((i >> 5) & 0x7),
    698  1.23       uch 		    __get_color8((i >> 2) & 0x7),
    699  1.23       uch 		    __get_color4(i & 0x3));
    700  1.12       uch 	}
    701  1.12       uch }
    702  1.12       uch 
    703  1.12       uch void
    704  1.18       uch tx3912video_clut_install(void *ctx, struct rasops_info *ri)
    705  1.12       uch {
    706  1.12       uch 	struct tx3912video_softc *sc = ctx;
    707  1.12       uch 	const int system_cmap[0x10] = {
    708  1.12       uch 		TX3912VIDEO_BLACK,
    709  1.12       uch 		TX3912VIDEO_RED,
    710  1.12       uch 		TX3912VIDEO_GREEN,
    711  1.12       uch 		TX3912VIDEO_YELLOW,
    712  1.12       uch 		TX3912VIDEO_BLUE,
    713  1.12       uch 		TX3912VIDEO_MAGENTA,
    714  1.12       uch 		TX3912VIDEO_CYAN,
    715  1.12       uch 		TX3912VIDEO_WHITE,
    716  1.12       uch 		TX3912VIDEO_DARK_BLACK,
    717  1.12       uch 		TX3912VIDEO_DARK_RED,
    718  1.12       uch 		TX3912VIDEO_DARK_GREEN,
    719  1.12       uch 		TX3912VIDEO_DARK_YELLOW,
    720  1.12       uch 		TX3912VIDEO_DARK_BLUE,
    721  1.12       uch 		TX3912VIDEO_DARK_MAGENTA,
    722  1.12       uch 		TX3912VIDEO_DARK_CYAN,
    723  1.12       uch 		TX3912VIDEO_DARK_WHITE,
    724  1.12       uch 	};
    725  1.12       uch 
    726  1.12       uch 	KASSERT(ri);
    727  1.12       uch 
    728  1.12       uch 	if (sc->sc_chip->vc_fbdepth == 8) {
    729  1.12       uch 		/* XXX 2bit gray scale LUT not supported */
    730  1.12       uch 		memcpy(ri->ri_devcmap, system_cmap, sizeof system_cmap);
    731  1.12       uch 	}
    732  1.12       uch }
    733  1.12       uch 
    734  1.12       uch void
    735  1.18       uch tx3912video_clut_init(struct tx3912video_softc *sc)
    736  1.12       uch {
    737  1.15       uch 	tx_chipset_tag_t tc = sc->sc_chip->vc_v;
    738  1.12       uch 
    739  1.12       uch 	if (sc->sc_chip->vc_fbdepth != 8) {
    740  1.12       uch 		return; /* XXX 2bit gray scale LUT not supported */
    741  1.12       uch 	}
    742  1.12       uch 
    743  1.12       uch 	/*
    744  1.12       uch 	 * time-based dithering pattern (TOSHIBA recommended pattern)
    745  1.12       uch 	 */
    746  1.12       uch 	/* 2/3, 1/3 */
    747  1.12       uch 	tx_conf_write(tc, TX3912_VIDEOCTRL8_REG,
    748  1.23       uch 	    TX3912_VIDEOCTRL8_PAT2_3_DEFAULT);
    749  1.12       uch 	/* 3/4, 2/4 */
    750  1.12       uch 	tx_conf_write(tc, TX3912_VIDEOCTRL9_REG,
    751  1.23       uch 	    (TX3912_VIDEOCTRL9_PAT3_4_DEFAULT << 16) |
    752  1.23       uch 	    TX3912_VIDEOCTRL9_PAT2_4_DEFAULT);
    753  1.12       uch 	/* 4/5, 1/5 */
    754  1.12       uch 	tx_conf_write(tc, TX3912_VIDEOCTRL10_REG,
    755  1.23       uch 	    TX3912_VIDEOCTRL10_PAT4_5_DEFAULT);
    756  1.12       uch 	/* 3/5, 2/5 */
    757  1.12       uch 	tx_conf_write(tc, TX3912_VIDEOCTRL11_REG,
    758  1.23       uch 	    TX3912_VIDEOCTRL11_PAT3_5_DEFAULT);
    759  1.12       uch 	/* 6/7, 1/7 */
    760  1.12       uch 	tx_conf_write(tc, TX3912_VIDEOCTRL12_REG,
    761  1.23       uch 	    TX3912_VIDEOCTRL12_PAT6_7_DEFAULT);
    762  1.12       uch 	/* 5/7, 2/7 */
    763  1.12       uch 	tx_conf_write(tc, TX3912_VIDEOCTRL13_REG,
    764  1.23       uch 	    TX3912_VIDEOCTRL13_PAT5_7_DEFAULT);
    765  1.12       uch 	/* 4/7, 3/7 */
    766  1.12       uch 	tx_conf_write(tc, TX3912_VIDEOCTRL14_REG,
    767  1.23       uch 	    TX3912_VIDEOCTRL14_PAT4_7_DEFAULT);
    768  1.12       uch 
    769  1.12       uch 	/*
    770  1.12       uch 	 * dither-pattern look-up table. (selected by uch)
    771  1.12       uch 	 */
    772  1.12       uch 	/* red */
    773  1.12       uch 	tx_conf_write(tc, TX3912_VIDEOCTRL5_REG,
    774  1.23       uch 	    (dither_level8[7] << 28) |
    775  1.23       uch 	    (dither_level8[6] << 24) |
    776  1.23       uch 	    (dither_level8[5] << 20) |
    777  1.23       uch 	    (dither_level8[4] << 16) |
    778  1.23       uch 	    (dither_level8[3] << 12) |
    779  1.23       uch 	    (dither_level8[2] << 8) |
    780  1.23       uch 	    (dither_level8[1] << 4) |
    781  1.23       uch 	    (dither_level8[0] << 0));
    782  1.12       uch 	/* green */
    783  1.12       uch 	tx_conf_write(tc, TX3912_VIDEOCTRL6_REG,
    784  1.23       uch 	    (dither_level8[7] << 28) |
    785  1.23       uch 	    (dither_level8[6] << 24) |
    786  1.23       uch 	    (dither_level8[5] << 20) |
    787  1.23       uch 	    (dither_level8[4] << 16) |
    788  1.23       uch 	    (dither_level8[3] << 12) |
    789  1.23       uch 	    (dither_level8[2] << 8) |
    790  1.23       uch 	    (dither_level8[1] << 4) |
    791  1.23       uch 	    (dither_level8[0] << 0));
    792  1.12       uch 	/* blue (2bit gray scale also use this look-up table) */
    793  1.12       uch 	tx_conf_write(tc, TX3912_VIDEOCTRL7_REG,
    794  1.23       uch 	    (dither_level4[3] << 12) |
    795  1.23       uch 	    (dither_level4[2] << 8) |
    796  1.23       uch 	    (dither_level4[1] << 4) |
    797  1.23       uch 	    (dither_level4[0] << 0));
    798  1.14       uch 
    799  1.14       uch 	tx3912video_reset(sc->sc_chip);
    800   1.6       uch }
    801