Home | History | Annotate | Line # | Download | only in dev
plumvideo.c revision 1.22.2.6
      1  1.22.2.6  nathanw /*	$NetBSD: plumvideo.c,v 1.22.2.6 2002/10/18 02:37:07 nathanw Exp $ */
      2  1.22.2.2  nathanw 
      3  1.22.2.2  nathanw /*-
      4  1.22.2.3  nathanw  * Copyright (c) 1999-2002 The NetBSD Foundation, Inc.
      5  1.22.2.2  nathanw  * All rights reserved.
      6  1.22.2.2  nathanw  *
      7  1.22.2.2  nathanw  * This code is derived from software contributed to The NetBSD Foundation
      8  1.22.2.2  nathanw  * by UCHIYAMA Yasushi.
      9  1.22.2.2  nathanw  *
     10  1.22.2.2  nathanw  * Redistribution and use in source and binary forms, with or without
     11  1.22.2.2  nathanw  * modification, are permitted provided that the following conditions
     12  1.22.2.2  nathanw  * are met:
     13  1.22.2.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     14  1.22.2.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     15  1.22.2.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.22.2.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     17  1.22.2.2  nathanw  *    documentation and/or other materials provided with the distribution.
     18  1.22.2.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     19  1.22.2.2  nathanw  *    must display the following acknowledgement:
     20  1.22.2.2  nathanw  *        This product includes software developed by the NetBSD
     21  1.22.2.2  nathanw  *        Foundation, Inc. and its contributors.
     22  1.22.2.2  nathanw  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.22.2.2  nathanw  *    contributors may be used to endorse or promote products derived
     24  1.22.2.2  nathanw  *    from this software without specific prior written permission.
     25  1.22.2.2  nathanw  *
     26  1.22.2.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.22.2.2  nathanw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.22.2.2  nathanw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.22.2.2  nathanw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.22.2.2  nathanw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.22.2.2  nathanw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.22.2.2  nathanw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.22.2.2  nathanw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.22.2.2  nathanw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.22.2.2  nathanw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.22.2.2  nathanw  * POSSIBILITY OF SUCH DAMAGE.
     37  1.22.2.2  nathanw  */
     38  1.22.2.2  nathanw 
     39  1.22.2.2  nathanw #undef PLUMVIDEODEBUG
     40  1.22.2.2  nathanw #include "plumohci.h" /* Plum2 OHCI shared memory allocated on V-RAM */
     41  1.22.2.3  nathanw #include "bivideo.h"
     42  1.22.2.2  nathanw 
     43  1.22.2.2  nathanw #include <sys/param.h>
     44  1.22.2.2  nathanw #include <sys/systm.h>
     45  1.22.2.2  nathanw #include <sys/device.h>
     46  1.22.2.2  nathanw 
     47  1.22.2.2  nathanw #include <sys/ioctl.h>
     48  1.22.2.2  nathanw #include <sys/buf.h>
     49  1.22.2.2  nathanw #include <uvm/uvm_extern.h>
     50  1.22.2.2  nathanw 
     51  1.22.2.2  nathanw #include <dev/cons.h> /* consdev */
     52  1.22.2.2  nathanw 
     53  1.22.2.2  nathanw #include <mips/cache.h>
     54  1.22.2.2  nathanw 
     55  1.22.2.2  nathanw #include <machine/bus.h>
     56  1.22.2.2  nathanw #include <machine/intr.h>
     57  1.22.2.2  nathanw #include <machine/config_hook.h>
     58  1.22.2.2  nathanw 
     59  1.22.2.2  nathanw #include <hpcmips/tx/tx39var.h>
     60  1.22.2.2  nathanw #include <hpcmips/dev/plumvar.h>
     61  1.22.2.2  nathanw #include <hpcmips/dev/plumicuvar.h>
     62  1.22.2.2  nathanw #include <hpcmips/dev/plumpowervar.h>
     63  1.22.2.2  nathanw #include <hpcmips/dev/plumvideoreg.h>
     64  1.22.2.2  nathanw 
     65  1.22.2.2  nathanw #include <machine/bootinfo.h>
     66  1.22.2.2  nathanw 
     67  1.22.2.2  nathanw #include <dev/wscons/wsdisplayvar.h>
     68  1.22.2.2  nathanw #include <dev/rasops/rasops.h>
     69  1.22.2.2  nathanw #include <dev/hpc/video_subr.h>
     70  1.22.2.2  nathanw 
     71  1.22.2.2  nathanw #include <dev/wscons/wsconsio.h>
     72  1.22.2.2  nathanw #include <dev/hpc/hpcfbvar.h>
     73  1.22.2.2  nathanw #include <dev/hpc/hpcfbio.h>
     74  1.22.2.3  nathanw #if NBIVIDEO > 0
     75  1.22.2.3  nathanw #include <dev/hpc/bivideovar.h>
     76  1.22.2.3  nathanw #endif
     77  1.22.2.2  nathanw 
     78  1.22.2.2  nathanw #ifdef PLUMVIDEODEBUG
     79  1.22.2.2  nathanw int	plumvideo_debug = 1;
     80  1.22.2.2  nathanw #define	DPRINTF(arg) if (plumvideo_debug) printf arg;
     81  1.22.2.2  nathanw #define	DPRINTFN(n, arg) if (plumvideo_debug > (n)) printf arg;
     82  1.22.2.2  nathanw #else
     83  1.22.2.2  nathanw #define	DPRINTF(arg)
     84  1.22.2.2  nathanw #define DPRINTFN(n, arg)
     85  1.22.2.2  nathanw #endif
     86  1.22.2.2  nathanw 
     87  1.22.2.2  nathanw struct plumvideo_softc {
     88  1.22.2.2  nathanw 	struct device sc_dev;
     89  1.22.2.2  nathanw 	tx_chipset_tag_t sc_tc;
     90  1.22.2.2  nathanw 	plum_chipset_tag_t sc_pc;
     91  1.22.2.2  nathanw 
     92  1.22.2.2  nathanw 	void *sc_powerhook;	/* power management hook */
     93  1.22.2.2  nathanw 	int sc_console;
     94  1.22.2.2  nathanw 
     95  1.22.2.2  nathanw 	/* control register */
     96  1.22.2.2  nathanw 	bus_space_tag_t sc_regt;
     97  1.22.2.2  nathanw 	bus_space_handle_t sc_regh;
     98  1.22.2.2  nathanw 	/* frame buffer */
     99  1.22.2.2  nathanw 	bus_space_tag_t sc_fbiot;
    100  1.22.2.2  nathanw 	bus_space_handle_t sc_fbioh;
    101  1.22.2.2  nathanw 	/* clut buffer (8bpp only) */
    102  1.22.2.2  nathanw 	bus_space_tag_t sc_clutiot;
    103  1.22.2.2  nathanw 	bus_space_handle_t sc_clutioh;
    104  1.22.2.2  nathanw 	/* bitblt */
    105  1.22.2.2  nathanw 	bus_space_tag_t sc_bitbltt;
    106  1.22.2.2  nathanw 	bus_space_handle_t sc_bitblth;
    107  1.22.2.2  nathanw 
    108  1.22.2.2  nathanw 	struct video_chip sc_chip;
    109  1.22.2.2  nathanw 	struct hpcfb_fbconf sc_fbconf;
    110  1.22.2.2  nathanw 	struct hpcfb_dspconf sc_dspconf;
    111  1.22.2.2  nathanw };
    112  1.22.2.2  nathanw 
    113  1.22.2.2  nathanw int	plumvideo_match(struct device*, struct cfdata*, void*);
    114  1.22.2.2  nathanw void	plumvideo_attach(struct device*, struct device*, void*);
    115  1.22.2.2  nathanw 
    116  1.22.2.2  nathanw int	plumvideo_ioctl(void *, u_long, caddr_t, int, struct proc *);
    117  1.22.2.2  nathanw paddr_t	plumvideo_mmap(void *, off_t, int);
    118  1.22.2.2  nathanw 
    119  1.22.2.6  nathanw CFATTACH_DECL(plumvideo, sizeof(struct plumvideo_softc),
    120  1.22.2.6  nathanw     plumvideo_match, plumvideo_attach, NULL, NULL);
    121  1.22.2.2  nathanw 
    122  1.22.2.2  nathanw struct hpcfb_accessops plumvideo_ha = {
    123  1.22.2.2  nathanw 	plumvideo_ioctl, plumvideo_mmap
    124  1.22.2.2  nathanw };
    125  1.22.2.2  nathanw 
    126  1.22.2.2  nathanw int	plumvideo_power(void *, int, long, void *);
    127  1.22.2.2  nathanw 
    128  1.22.2.2  nathanw int	plumvideo_init(struct plumvideo_softc *, int *);
    129  1.22.2.2  nathanw void	plumvideo_hpcfbinit(struct plumvideo_softc *, int);
    130  1.22.2.2  nathanw 
    131  1.22.2.2  nathanw void	plumvideo_clut_default(struct plumvideo_softc *);
    132  1.22.2.2  nathanw void	plumvideo_clut_set(struct plumvideo_softc *, u_int32_t *, int, int);
    133  1.22.2.2  nathanw void	plumvideo_clut_get(struct plumvideo_softc *, u_int32_t *, int, int);
    134  1.22.2.2  nathanw void	__plumvideo_clut_access(struct plumvideo_softc *,
    135  1.22.2.2  nathanw 	    void (*)(bus_space_tag_t, bus_space_handle_t));
    136  1.22.2.2  nathanw static void _flush_cache(void) __attribute__((__unused__)); /* !!! */
    137  1.22.2.2  nathanw 
    138  1.22.2.2  nathanw #ifdef PLUMVIDEODEBUG
    139  1.22.2.2  nathanw void	plumvideo_dump(struct plumvideo_softc*);
    140  1.22.2.2  nathanw #endif
    141  1.22.2.2  nathanw 
    142  1.22.2.2  nathanw #define ON	1
    143  1.22.2.2  nathanw #define OFF	0
    144  1.22.2.2  nathanw 
    145  1.22.2.2  nathanw int
    146  1.22.2.2  nathanw plumvideo_match(struct device *parent, struct cfdata *cf, void *aux)
    147  1.22.2.2  nathanw {
    148  1.22.2.2  nathanw 	/*
    149  1.22.2.2  nathanw 	 * VRAM area also uses as UHOSTC shared RAM.
    150  1.22.2.2  nathanw 	 */
    151  1.22.2.2  nathanw 	return (2); /* 1st attach group */
    152  1.22.2.2  nathanw }
    153  1.22.2.2  nathanw 
    154  1.22.2.2  nathanw void
    155  1.22.2.2  nathanw plumvideo_attach(struct device *parent, struct device *self, void *aux)
    156  1.22.2.2  nathanw {
    157  1.22.2.2  nathanw 	struct plum_attach_args *pa = aux;
    158  1.22.2.2  nathanw 	struct plumvideo_softc *sc = (void*)self;
    159  1.22.2.2  nathanw 	struct hpcfb_attach_args ha;
    160  1.22.2.2  nathanw 	int console, reverse_flag;
    161  1.22.2.2  nathanw 
    162  1.22.2.2  nathanw 	sc->sc_console = console = cn_tab ? 0 : 1;
    163  1.22.2.2  nathanw 	sc->sc_pc	= pa->pa_pc;
    164  1.22.2.2  nathanw 	sc->sc_regt	= pa->pa_regt;
    165  1.22.2.2  nathanw 	sc->sc_fbiot = sc->sc_clutiot = sc->sc_bitbltt  = pa->pa_iot;
    166  1.22.2.2  nathanw 
    167  1.22.2.2  nathanw 	printf(": ");
    168  1.22.2.2  nathanw 
    169  1.22.2.2  nathanw 	/* map register area */
    170  1.22.2.2  nathanw 	if (bus_space_map(sc->sc_regt, PLUM_VIDEO_REGBASE,
    171  1.22.2.2  nathanw 	    PLUM_VIDEO_REGSIZE, 0, &sc->sc_regh)) {
    172  1.22.2.2  nathanw 		printf("register map failed\n");
    173  1.22.2.2  nathanw 		return;
    174  1.22.2.2  nathanw 	}
    175  1.22.2.2  nathanw 
    176  1.22.2.2  nathanw 	/* power control */
    177  1.22.2.2  nathanw 	plumvideo_power(sc, 0, 0,
    178  1.22.2.2  nathanw 	    (void *)(console ? PWR_RESUME : PWR_SUSPEND));
    179  1.22.2.2  nathanw 	/* Add a hard power hook to power saving */
    180  1.22.2.2  nathanw 	sc->sc_powerhook = config_hook(CONFIG_HOOK_PMEVENT,
    181  1.22.2.2  nathanw 	    CONFIG_HOOK_PMEVENT_HARDPOWER,
    182  1.22.2.2  nathanw 	    CONFIG_HOOK_SHARE,
    183  1.22.2.2  nathanw 	    plumvideo_power, sc);
    184  1.22.2.2  nathanw 	if (sc->sc_powerhook == 0)
    185  1.22.2.2  nathanw 		printf("WARNING unable to establish hard power hook");
    186  1.22.2.2  nathanw 
    187  1.22.2.2  nathanw 	/*
    188  1.22.2.2  nathanw 	 *  Initialize LCD controller
    189  1.22.2.2  nathanw 	 *	map V-RAM area.
    190  1.22.2.2  nathanw 	 *	reinstall bootinfo structure.
    191  1.22.2.2  nathanw 	 *	some OHCI shared-buffer hack. XXX
    192  1.22.2.2  nathanw 	 */
    193  1.22.2.2  nathanw 	if (plumvideo_init(sc, &reverse_flag) != 0)
    194  1.22.2.2  nathanw 		return;
    195  1.22.2.2  nathanw 
    196  1.22.2.2  nathanw 	printf("\n");
    197  1.22.2.2  nathanw 
    198  1.22.2.2  nathanw 	/* Attach frame buffer device */
    199  1.22.2.2  nathanw 	plumvideo_hpcfbinit(sc, reverse_flag);
    200  1.22.2.2  nathanw 
    201  1.22.2.2  nathanw #ifdef PLUMVIDEODEBUG
    202  1.22.2.2  nathanw 	if (plumvideo_debug > 0)
    203  1.22.2.2  nathanw 		plumvideo_dump(sc);
    204  1.22.2.2  nathanw 	/* attach debug draw routine (debugging use) */
    205  1.22.2.2  nathanw 	video_attach_drawfunc(&sc->sc_chip);
    206  1.22.2.2  nathanw 	tx_conf_register_video(sc->sc_pc->pc_tc, &sc->sc_chip);
    207  1.22.2.2  nathanw #endif /* PLUMVIDEODEBUG */
    208  1.22.2.2  nathanw 
    209  1.22.2.2  nathanw 	if(console && hpcfb_cnattach(&sc->sc_fbconf) != 0) {
    210  1.22.2.2  nathanw 		panic("plumvideo_attach: can't init fb console");
    211  1.22.2.2  nathanw 	}
    212  1.22.2.2  nathanw 
    213  1.22.2.2  nathanw 	ha.ha_console = console;
    214  1.22.2.2  nathanw 	ha.ha_accessops = &plumvideo_ha;
    215  1.22.2.2  nathanw 	ha.ha_accessctx = sc;
    216  1.22.2.2  nathanw 	ha.ha_curfbconf = 0;
    217  1.22.2.2  nathanw 	ha.ha_nfbconf = 1;
    218  1.22.2.2  nathanw 	ha.ha_fbconflist = &sc->sc_fbconf;
    219  1.22.2.2  nathanw 	ha.ha_curdspconf = 0;
    220  1.22.2.2  nathanw 	ha.ha_ndspconf = 1;
    221  1.22.2.2  nathanw 	ha.ha_dspconflist = &sc->sc_dspconf;
    222  1.22.2.2  nathanw 
    223  1.22.2.2  nathanw 	config_found(self, &ha, hpcfbprint);
    224  1.22.2.3  nathanw #if NBIVIDEO > 0
    225  1.22.2.3  nathanw 	/* bivideo is no longer need */
    226  1.22.2.3  nathanw 	bivideo_dont_attach = 1;
    227  1.22.2.3  nathanw #endif /* NBIVIDEO > 0 */
    228  1.22.2.2  nathanw }
    229  1.22.2.2  nathanw 
    230  1.22.2.2  nathanw void
    231  1.22.2.2  nathanw plumvideo_hpcfbinit(struct plumvideo_softc *sc, int reverse_flag)
    232  1.22.2.2  nathanw {
    233  1.22.2.2  nathanw 	struct hpcfb_fbconf *fb = &sc->sc_fbconf;
    234  1.22.2.2  nathanw 	struct video_chip *chip = &sc->sc_chip;
    235  1.22.2.2  nathanw 	vaddr_t fbvaddr = (vaddr_t)sc->sc_fbioh;
    236  1.22.2.2  nathanw 	int height = chip->vc_fbheight;
    237  1.22.2.2  nathanw 	int width = chip->vc_fbwidth;
    238  1.22.2.2  nathanw 	int depth = chip->vc_fbdepth;
    239  1.22.2.2  nathanw 
    240  1.22.2.2  nathanw 	memset(fb, 0, sizeof(struct hpcfb_fbconf));
    241  1.22.2.2  nathanw 
    242  1.22.2.2  nathanw 	fb->hf_conf_index	= 0;	/* configuration index		*/
    243  1.22.2.2  nathanw 	fb->hf_nconfs		= 1;   	/* how many configurations	*/
    244  1.22.2.2  nathanw 	strncpy(fb->hf_name, "PLUM built-in video", HPCFB_MAXNAMELEN);
    245  1.22.2.2  nathanw 	/* frame buffer name		*/
    246  1.22.2.2  nathanw 	strncpy(fb->hf_conf_name, "LCD", HPCFB_MAXNAMELEN);
    247  1.22.2.2  nathanw 	/* configuration name		*/
    248  1.22.2.2  nathanw 	fb->hf_height		= height;
    249  1.22.2.2  nathanw 	fb->hf_width		= width;
    250  1.22.2.2  nathanw 	fb->hf_baseaddr		= (u_long)fbvaddr;
    251  1.22.2.2  nathanw 	fb->hf_offset		= (u_long)fbvaddr - mips_ptob(mips_btop(fbvaddr));
    252  1.22.2.2  nathanw 	/* frame buffer start offset   	*/
    253  1.22.2.2  nathanw 	fb->hf_bytes_per_line	= (width * depth) / NBBY;
    254  1.22.2.2  nathanw 	fb->hf_nplanes		= 1;
    255  1.22.2.2  nathanw 	fb->hf_bytes_per_plane	= height * fb->hf_bytes_per_line;
    256  1.22.2.2  nathanw 
    257  1.22.2.2  nathanw 	fb->hf_access_flags |= HPCFB_ACCESS_BYTE;
    258  1.22.2.2  nathanw 	fb->hf_access_flags |= HPCFB_ACCESS_WORD;
    259  1.22.2.2  nathanw 	fb->hf_access_flags |= HPCFB_ACCESS_DWORD;
    260  1.22.2.2  nathanw 	if (reverse_flag)
    261  1.22.2.2  nathanw 		fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
    262  1.22.2.2  nathanw 
    263  1.22.2.2  nathanw 	switch (depth) {
    264  1.22.2.2  nathanw 	default:
    265  1.22.2.6  nathanw 		panic("plumvideo_hpcfbinit: not supported color depth");
    266  1.22.2.2  nathanw 		/* NOTREACHED */
    267  1.22.2.2  nathanw 	case 16:
    268  1.22.2.2  nathanw 		fb->hf_class = HPCFB_CLASS_RGBCOLOR;
    269  1.22.2.2  nathanw 		fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
    270  1.22.2.2  nathanw 		fb->hf_pack_width = 16;
    271  1.22.2.2  nathanw 		fb->hf_pixels_per_pack = 1;
    272  1.22.2.2  nathanw 		fb->hf_pixel_width = 16;
    273  1.22.2.2  nathanw 
    274  1.22.2.2  nathanw 		fb->hf_class_data_length = sizeof(struct hf_rgb_tag);
    275  1.22.2.2  nathanw 		/* reserved for future use */
    276  1.22.2.2  nathanw 		fb->hf_u.hf_rgb.hf_flags = 0;
    277  1.22.2.2  nathanw 
    278  1.22.2.2  nathanw 		fb->hf_u.hf_rgb.hf_red_width = 5;
    279  1.22.2.2  nathanw 		fb->hf_u.hf_rgb.hf_red_shift = 11;
    280  1.22.2.2  nathanw 		fb->hf_u.hf_rgb.hf_green_width = 6;
    281  1.22.2.2  nathanw 		fb->hf_u.hf_rgb.hf_green_shift = 5;
    282  1.22.2.2  nathanw 		fb->hf_u.hf_rgb.hf_blue_width = 5;
    283  1.22.2.2  nathanw 		fb->hf_u.hf_rgb.hf_blue_shift = 0;
    284  1.22.2.2  nathanw 		fb->hf_u.hf_rgb.hf_alpha_width = 0;
    285  1.22.2.2  nathanw 		fb->hf_u.hf_rgb.hf_alpha_shift = 0;
    286  1.22.2.2  nathanw 		break;
    287  1.22.2.2  nathanw 
    288  1.22.2.2  nathanw 	case 8:
    289  1.22.2.2  nathanw 		fb->hf_class = HPCFB_CLASS_INDEXCOLOR;
    290  1.22.2.2  nathanw 		fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
    291  1.22.2.2  nathanw 		fb->hf_pack_width = 8;
    292  1.22.2.2  nathanw 		fb->hf_pixels_per_pack = 1;
    293  1.22.2.2  nathanw 		fb->hf_pixel_width = 8;
    294  1.22.2.2  nathanw 		fb->hf_class_data_length = sizeof(struct hf_indexed_tag);
    295  1.22.2.2  nathanw 		/* reserved for future use */
    296  1.22.2.2  nathanw 		fb->hf_u.hf_indexed.hf_flags = 0;
    297  1.22.2.2  nathanw 		break;
    298  1.22.2.2  nathanw 	}
    299  1.22.2.2  nathanw }
    300  1.22.2.2  nathanw 
    301  1.22.2.2  nathanw int
    302  1.22.2.2  nathanw plumvideo_init(struct plumvideo_softc *sc, int *reverse)
    303  1.22.2.2  nathanw {
    304  1.22.2.2  nathanw 	struct video_chip *chip = &sc->sc_chip;
    305  1.22.2.2  nathanw 	bus_space_tag_t regt = sc->sc_regt;
    306  1.22.2.2  nathanw 	bus_space_handle_t regh = sc->sc_regh;
    307  1.22.2.2  nathanw 	plumreg_t reg;
    308  1.22.2.2  nathanw 	size_t vram_size;
    309  1.22.2.2  nathanw 	int bpp, width, height, vram_pitch;
    310  1.22.2.2  nathanw 
    311  1.22.2.2  nathanw 	*reverse = video_reverse_color();
    312  1.22.2.2  nathanw 	chip->vc_v = sc->sc_pc->pc_tc;
    313  1.22.2.2  nathanw #if notyet
    314  1.22.2.2  nathanw 	/* map BitBlt area */
    315  1.22.2.2  nathanw 	if (bus_space_map(sc->sc_bitbltt,
    316  1.22.2.2  nathanw 	    PLUM_VIDEO_BITBLT_IOBASE,
    317  1.22.2.2  nathanw 	    PLUM_VIDEO_BITBLT_IOSIZE, 0,
    318  1.22.2.2  nathanw 	    &sc->sc_bitblth)) {
    319  1.22.2.2  nathanw 		printf(": BitBlt map failed\n");
    320  1.22.2.2  nathanw 		return (1);
    321  1.22.2.2  nathanw 	}
    322  1.22.2.2  nathanw #endif
    323  1.22.2.2  nathanw 	reg = plum_conf_read(regt, regh, PLUM_VIDEO_PLGMD_REG);
    324  1.22.2.2  nathanw 
    325  1.22.2.2  nathanw 	switch (reg & PLUM_VIDEO_PLGMD_GMODE_MASK) {
    326  1.22.2.2  nathanw 	case PLUM_VIDEO_PLGMD_16BPP:
    327  1.22.2.2  nathanw #if NPLUMOHCI > 0 /* reserve V-RAM area for USB OHCI */
    328  1.22.2.2  nathanw 		/* FALLTHROUGH */
    329  1.22.2.2  nathanw #else
    330  1.22.2.2  nathanw 		bpp = 16;
    331  1.22.2.2  nathanw 		break;
    332  1.22.2.2  nathanw #endif
    333  1.22.2.2  nathanw 	default:
    334  1.22.2.2  nathanw 		bootinfo->fb_type = *reverse ? BIFB_D8_FF : BIFB_D8_00;
    335  1.22.2.2  nathanw 		reg &= ~PLUM_VIDEO_PLGMD_GMODE_MASK;
    336  1.22.2.2  nathanw 		plum_conf_write(regt, regh, PLUM_VIDEO_PLGMD_REG, reg);
    337  1.22.2.2  nathanw 		reg |= PLUM_VIDEO_PLGMD_8BPP;
    338  1.22.2.2  nathanw 		plum_conf_write(regt, regh, PLUM_VIDEO_PLGMD_REG, reg);
    339  1.22.2.2  nathanw #if notyet
    340  1.22.2.2  nathanw 		/* change BitBlt color depth */
    341  1.22.2.2  nathanw 		plum_conf_write(sc->sc_bitbltt, sc->sc_bitblth, 0x8, 0);
    342  1.22.2.2  nathanw #endif
    343  1.22.2.2  nathanw 		/* FALLTHROUGH */
    344  1.22.2.2  nathanw 	case PLUM_VIDEO_PLGMD_8BPP:
    345  1.22.2.2  nathanw 		bpp = 8;
    346  1.22.2.2  nathanw 		break;
    347  1.22.2.2  nathanw 	}
    348  1.22.2.2  nathanw 	chip->vc_fbdepth = bpp;
    349  1.22.2.2  nathanw 
    350  1.22.2.2  nathanw 	/*
    351  1.22.2.2  nathanw 	 * Get display size from WindowsCE setted.
    352  1.22.2.2  nathanw 	 */
    353  1.22.2.2  nathanw 	chip->vc_fbwidth = width = bootinfo->fb_width =
    354  1.22.2.2  nathanw 	    plum_conf_read(regt, regh, PLUM_VIDEO_PLHPX_REG) + 1;
    355  1.22.2.2  nathanw 	chip->vc_fbheight = height = bootinfo->fb_height =
    356  1.22.2.2  nathanw 	    plum_conf_read(regt, regh, PLUM_VIDEO_PLVT_REG) -
    357  1.22.2.2  nathanw 	    plum_conf_read(regt, regh, PLUM_VIDEO_PLVDS_REG);
    358  1.22.2.2  nathanw 
    359  1.22.2.2  nathanw 	/*
    360  1.22.2.2  nathanw 	 * set line byte length to bootinfo and LCD controller.
    361  1.22.2.2  nathanw 	 */
    362  1.22.2.2  nathanw 	vram_pitch = bootinfo->fb_line_bytes = (width * bpp) / NBBY;
    363  1.22.2.2  nathanw 	plum_conf_write(regt, regh, PLUM_VIDEO_PLPIT1_REG, vram_pitch);
    364  1.22.2.2  nathanw 	plum_conf_write(regt, regh, PLUM_VIDEO_PLPIT2_REG,
    365  1.22.2.2  nathanw 	    vram_pitch & PLUM_VIDEO_PLPIT2_MASK);
    366  1.22.2.2  nathanw 	plum_conf_write(regt, regh, PLUM_VIDEO_PLOFS_REG, vram_pitch);
    367  1.22.2.2  nathanw 
    368  1.22.2.2  nathanw 	/*
    369  1.22.2.2  nathanw 	 * boot messages and map CLUT(if any).
    370  1.22.2.2  nathanw 	 */
    371  1.22.2.2  nathanw 	printf("display mode: ");
    372  1.22.2.2  nathanw 	switch (bpp) {
    373  1.22.2.2  nathanw 	default:
    374  1.22.2.2  nathanw 		printf("disabled ");
    375  1.22.2.2  nathanw 		break;
    376  1.22.2.2  nathanw 	case 8:
    377  1.22.2.2  nathanw 		printf("8bpp ");
    378  1.22.2.2  nathanw 		/* map CLUT area */
    379  1.22.2.2  nathanw 		if (bus_space_map(sc->sc_clutiot,
    380  1.22.2.2  nathanw 		    PLUM_VIDEO_CLUT_LCD_IOBASE,
    381  1.22.2.2  nathanw 		    PLUM_VIDEO_CLUT_LCD_IOSIZE, 0,
    382  1.22.2.2  nathanw 		    &sc->sc_clutioh)) {
    383  1.22.2.2  nathanw 			printf(": CLUT map failed\n");
    384  1.22.2.2  nathanw 			return (1);
    385  1.22.2.2  nathanw 		}
    386  1.22.2.2  nathanw 		/* install default CLUT */
    387  1.22.2.2  nathanw 		plumvideo_clut_default(sc);
    388  1.22.2.2  nathanw 		break;
    389  1.22.2.2  nathanw 	case 16:
    390  1.22.2.2  nathanw 		printf("16bpp ");
    391  1.22.2.2  nathanw 		break;
    392  1.22.2.2  nathanw 	}
    393  1.22.2.2  nathanw 
    394  1.22.2.2  nathanw 	/*
    395  1.22.2.2  nathanw 	 * calcurate frame buffer size.
    396  1.22.2.2  nathanw 	 */
    397  1.22.2.2  nathanw 	reg = plum_conf_read(regt, regh, PLUM_VIDEO_PLGMD_REG);
    398  1.22.2.2  nathanw 	vram_size = (width * height * bpp) / NBBY;
    399  1.22.2.2  nathanw 	vram_size = mips_round_page(vram_size);
    400  1.22.2.2  nathanw 	chip->vc_fbsize = vram_size;
    401  1.22.2.2  nathanw 
    402  1.22.2.2  nathanw 	/*
    403  1.22.2.2  nathanw 	 * map V-RAM area.
    404  1.22.2.2  nathanw 	 */
    405  1.22.2.2  nathanw 	if (bus_space_map(sc->sc_fbiot, PLUM_VIDEO_VRAM_IOBASE,
    406  1.22.2.2  nathanw 	    vram_size, 0, &sc->sc_fbioh)) {
    407  1.22.2.2  nathanw 		printf(": V-RAM map failed\n");
    408  1.22.2.2  nathanw 		return (1);
    409  1.22.2.2  nathanw 	}
    410  1.22.2.2  nathanw 
    411  1.22.2.2  nathanw 	bootinfo->fb_addr = (unsigned char *)sc->sc_fbioh;
    412  1.22.2.2  nathanw 	chip->vc_fbvaddr = (vaddr_t)sc->sc_fbioh;
    413  1.22.2.2  nathanw 	chip->vc_fbpaddr = PLUM_VIDEO_VRAM_IOBASE_PHYSICAL;
    414  1.22.2.2  nathanw 
    415  1.22.2.2  nathanw 	return (0);
    416  1.22.2.2  nathanw }
    417  1.22.2.2  nathanw 
    418  1.22.2.2  nathanw int
    419  1.22.2.2  nathanw plumvideo_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
    420  1.22.2.2  nathanw {
    421  1.22.2.2  nathanw 	struct plumvideo_softc *sc = (struct plumvideo_softc *)v;
    422  1.22.2.2  nathanw 	struct hpcfb_fbconf *fbconf;
    423  1.22.2.2  nathanw 	struct hpcfb_dspconf *dspconf;
    424  1.22.2.2  nathanw 	struct wsdisplay_cmap *cmap;
    425  1.22.2.2  nathanw 	u_int8_t *r, *g, *b;
    426  1.22.2.2  nathanw 	u_int32_t *rgb;
    427  1.22.2.2  nathanw 	int idx, error;
    428  1.22.2.2  nathanw 	size_t cnt;
    429  1.22.2.2  nathanw 
    430  1.22.2.2  nathanw 	switch (cmd) {
    431  1.22.2.2  nathanw 	case WSDISPLAYIO_GETCMAP:
    432  1.22.2.2  nathanw 		cmap = (struct wsdisplay_cmap*)data;
    433  1.22.2.2  nathanw 		cnt = cmap->count;
    434  1.22.2.2  nathanw 		idx = cmap->index;
    435  1.22.2.2  nathanw 
    436  1.22.2.2  nathanw 		if (sc->sc_fbconf.hf_class != HPCFB_CLASS_INDEXCOLOR ||
    437  1.22.2.2  nathanw 		    sc->sc_fbconf.hf_pack_width != 8 ||
    438  1.22.2.2  nathanw 		    !LEGAL_CLUT_INDEX(idx) ||
    439  1.22.2.2  nathanw 		    !LEGAL_CLUT_INDEX(idx + cnt -1)) {
    440  1.22.2.2  nathanw 			return (EINVAL);
    441  1.22.2.2  nathanw 		}
    442  1.22.2.2  nathanw 
    443  1.22.2.2  nathanw 		if (!uvm_useracc(cmap->red, cnt, B_WRITE) ||
    444  1.22.2.2  nathanw 		    !uvm_useracc(cmap->green, cnt, B_WRITE) ||
    445  1.22.2.2  nathanw 		    !uvm_useracc(cmap->blue, cnt, B_WRITE)) {
    446  1.22.2.2  nathanw 			return (EFAULT);
    447  1.22.2.2  nathanw 		}
    448  1.22.2.2  nathanw 
    449  1.22.2.2  nathanw 		error = cmap_work_alloc(&r, &g, &b, &rgb, cnt);
    450  1.22.2.2  nathanw 		if (error != 0) {
    451  1.22.2.2  nathanw 			cmap_work_free(r, g, b, rgb);
    452  1.22.2.2  nathanw 			return  (ENOMEM);
    453  1.22.2.2  nathanw 		}
    454  1.22.2.2  nathanw 		plumvideo_clut_get(sc, rgb, idx, cnt);
    455  1.22.2.2  nathanw 		rgb24_decompose(rgb, r, g, b, cnt);
    456  1.22.2.2  nathanw 
    457  1.22.2.2  nathanw 		copyout(r, cmap->red, cnt);
    458  1.22.2.2  nathanw 		copyout(g, cmap->green,cnt);
    459  1.22.2.2  nathanw 		copyout(b, cmap->blue, cnt);
    460  1.22.2.2  nathanw 
    461  1.22.2.2  nathanw 		cmap_work_free(r, g, b, rgb);
    462  1.22.2.2  nathanw 
    463  1.22.2.2  nathanw 		return (0);
    464  1.22.2.2  nathanw 
    465  1.22.2.2  nathanw 	case WSDISPLAYIO_PUTCMAP:
    466  1.22.2.2  nathanw 		cmap = (struct wsdisplay_cmap*)data;
    467  1.22.2.2  nathanw 		cnt = cmap->count;
    468  1.22.2.2  nathanw 		idx = cmap->index;
    469  1.22.2.2  nathanw 
    470  1.22.2.2  nathanw 		if (sc->sc_fbconf.hf_class != HPCFB_CLASS_INDEXCOLOR ||
    471  1.22.2.2  nathanw 		    sc->sc_fbconf.hf_pack_width != 8 ||
    472  1.22.2.2  nathanw 		    !LEGAL_CLUT_INDEX(idx) ||
    473  1.22.2.2  nathanw 		    !LEGAL_CLUT_INDEX(idx + cnt -1)) {
    474  1.22.2.2  nathanw 			return (EINVAL);
    475  1.22.2.2  nathanw 		}
    476  1.22.2.2  nathanw 
    477  1.22.2.2  nathanw 		if (!uvm_useracc(cmap->red, cnt, B_WRITE) ||
    478  1.22.2.2  nathanw 		    !uvm_useracc(cmap->green, cnt, B_WRITE) ||
    479  1.22.2.2  nathanw 		    !uvm_useracc(cmap->blue, cnt, B_WRITE)) {
    480  1.22.2.2  nathanw 			return (EFAULT);
    481  1.22.2.2  nathanw 		}
    482  1.22.2.2  nathanw 
    483  1.22.2.2  nathanw 		error = cmap_work_alloc(&r, &g, &b, &rgb, cnt);
    484  1.22.2.2  nathanw 		if (error != 0) {
    485  1.22.2.2  nathanw 			cmap_work_free(r, g, b, rgb);
    486  1.22.2.2  nathanw 			return  (ENOMEM);
    487  1.22.2.2  nathanw 		}
    488  1.22.2.2  nathanw 		copyin(cmap->red,   r, cnt);
    489  1.22.2.2  nathanw 		copyin(cmap->green, g, cnt);
    490  1.22.2.2  nathanw 		copyin(cmap->blue,  b, cnt);
    491  1.22.2.2  nathanw 		rgb24_compose(rgb, r, g, b, cnt);
    492  1.22.2.2  nathanw 		plumvideo_clut_set(sc, rgb, idx, cnt);
    493  1.22.2.2  nathanw 
    494  1.22.2.2  nathanw 		cmap_work_free(r, g, b, rgb);
    495  1.22.2.2  nathanw 
    496  1.22.2.2  nathanw 		return (0);
    497  1.22.2.2  nathanw 
    498  1.22.2.2  nathanw 	case HPCFBIO_GCONF:
    499  1.22.2.2  nathanw 		fbconf = (struct hpcfb_fbconf *)data;
    500  1.22.2.2  nathanw 		if (fbconf->hf_conf_index != 0 &&
    501  1.22.2.2  nathanw 		    fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
    502  1.22.2.2  nathanw 			return (EINVAL);
    503  1.22.2.2  nathanw 		}
    504  1.22.2.2  nathanw 		*fbconf = sc->sc_fbconf;	/* structure assignment */
    505  1.22.2.2  nathanw 		return (0);
    506  1.22.2.2  nathanw 
    507  1.22.2.2  nathanw 	case HPCFBIO_SCONF:
    508  1.22.2.2  nathanw 		fbconf = (struct hpcfb_fbconf *)data;
    509  1.22.2.2  nathanw 		if (fbconf->hf_conf_index != 0 &&
    510  1.22.2.2  nathanw 		    fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
    511  1.22.2.2  nathanw 			return (EINVAL);
    512  1.22.2.2  nathanw 		}
    513  1.22.2.2  nathanw 		/*
    514  1.22.2.2  nathanw 		 * nothing to do because we have only one configration
    515  1.22.2.2  nathanw 		 */
    516  1.22.2.2  nathanw 		return (0);
    517  1.22.2.2  nathanw 
    518  1.22.2.2  nathanw 	case HPCFBIO_GDSPCONF:
    519  1.22.2.2  nathanw 		dspconf = (struct hpcfb_dspconf *)data;
    520  1.22.2.2  nathanw 		if ((dspconf->hd_unit_index != 0 &&
    521  1.22.2.2  nathanw 		    dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
    522  1.22.2.2  nathanw 		    (dspconf->hd_conf_index != 0 &&
    523  1.22.2.2  nathanw 			dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
    524  1.22.2.2  nathanw 			return (EINVAL);
    525  1.22.2.2  nathanw 		}
    526  1.22.2.2  nathanw 		*dspconf = sc->sc_dspconf;	/* structure assignment */
    527  1.22.2.2  nathanw 		return (0);
    528  1.22.2.2  nathanw 
    529  1.22.2.2  nathanw 	case HPCFBIO_SDSPCONF:
    530  1.22.2.2  nathanw 		dspconf = (struct hpcfb_dspconf *)data;
    531  1.22.2.2  nathanw 		if ((dspconf->hd_unit_index != 0 &&
    532  1.22.2.2  nathanw 		    dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
    533  1.22.2.2  nathanw 		    (dspconf->hd_conf_index != 0 &&
    534  1.22.2.2  nathanw 			dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
    535  1.22.2.2  nathanw 			return (EINVAL);
    536  1.22.2.2  nathanw 		}
    537  1.22.2.2  nathanw 		/*
    538  1.22.2.2  nathanw 		 * nothing to do
    539  1.22.2.2  nathanw 		 * because we have only one unit and one configration
    540  1.22.2.2  nathanw 		 */
    541  1.22.2.2  nathanw 		return (0);
    542  1.22.2.2  nathanw 
    543  1.22.2.2  nathanw 	case HPCFBIO_GOP:
    544  1.22.2.2  nathanw 	case HPCFBIO_SOP:
    545  1.22.2.2  nathanw 		/* XXX not implemented yet */
    546  1.22.2.2  nathanw 		return (EINVAL);
    547  1.22.2.2  nathanw 	}
    548  1.22.2.2  nathanw 
    549  1.22.2.3  nathanw 	return (EPASSTHROUGH);
    550  1.22.2.2  nathanw }
    551  1.22.2.2  nathanw 
    552  1.22.2.2  nathanw paddr_t
    553  1.22.2.2  nathanw plumvideo_mmap(void *ctx, off_t offset, int prot)
    554  1.22.2.2  nathanw {
    555  1.22.2.2  nathanw 	struct plumvideo_softc *sc = (struct plumvideo_softc *)ctx;
    556  1.22.2.2  nathanw 
    557  1.22.2.2  nathanw 	if (offset < 0 || (sc->sc_fbconf.hf_bytes_per_plane +
    558  1.22.2.2  nathanw 	    sc->sc_fbconf.hf_offset) <  offset) {
    559  1.22.2.2  nathanw 		return (-1);
    560  1.22.2.2  nathanw 	}
    561  1.22.2.2  nathanw 
    562  1.22.2.2  nathanw 	return (mips_btop(PLUM_VIDEO_VRAM_IOBASE_PHYSICAL + offset));
    563  1.22.2.2  nathanw }
    564  1.22.2.2  nathanw 
    565  1.22.2.2  nathanw void
    566  1.22.2.2  nathanw plumvideo_clut_get(struct plumvideo_softc *sc, u_int32_t *rgb, int beg,
    567  1.22.2.2  nathanw     int cnt)
    568  1.22.2.2  nathanw {
    569  1.22.2.2  nathanw 	static void __plumvideo_clut_get(bus_space_tag_t,
    570  1.22.2.2  nathanw 	    bus_space_handle_t);
    571  1.22.2.2  nathanw 	static void __plumvideo_clut_get(iot, ioh)
    572  1.22.2.2  nathanw 	    bus_space_tag_t iot;
    573  1.22.2.2  nathanw 	bus_space_handle_t ioh;
    574  1.22.2.2  nathanw 	{
    575  1.22.2.2  nathanw 		int i;
    576  1.22.2.2  nathanw 
    577  1.22.2.2  nathanw 		for (i = 0, beg *= 4; i < cnt; i++, beg += 4) {
    578  1.22.2.2  nathanw 			*rgb++ = bus_space_read_4(iot, ioh, beg) &
    579  1.22.2.2  nathanw 			    0x00ffffff;
    580  1.22.2.2  nathanw 		}
    581  1.22.2.2  nathanw 	}
    582  1.22.2.2  nathanw 
    583  1.22.2.2  nathanw 	KASSERT(rgb);
    584  1.22.2.2  nathanw 	KASSERT(LEGAL_CLUT_INDEX(beg));
    585  1.22.2.2  nathanw 	KASSERT(LEGAL_CLUT_INDEX(beg + cnt - 1));
    586  1.22.2.2  nathanw 	__plumvideo_clut_access(sc, __plumvideo_clut_get);
    587  1.22.2.2  nathanw }
    588  1.22.2.2  nathanw 
    589  1.22.2.2  nathanw void
    590  1.22.2.2  nathanw plumvideo_clut_set(struct plumvideo_softc *sc, u_int32_t *rgb, int beg,
    591  1.22.2.2  nathanw     int cnt)
    592  1.22.2.2  nathanw {
    593  1.22.2.2  nathanw 	static void __plumvideo_clut_set(bus_space_tag_t,
    594  1.22.2.2  nathanw 	    bus_space_handle_t);
    595  1.22.2.2  nathanw 	static void __plumvideo_clut_set(iot, ioh)
    596  1.22.2.2  nathanw 	    bus_space_tag_t iot;
    597  1.22.2.2  nathanw 	bus_space_handle_t ioh;
    598  1.22.2.2  nathanw 	{
    599  1.22.2.2  nathanw 		int i;
    600  1.22.2.2  nathanw 
    601  1.22.2.2  nathanw 		for (i = 0, beg *= 4; i < cnt; i++, beg +=4) {
    602  1.22.2.2  nathanw 			bus_space_write_4(iot, ioh, beg,
    603  1.22.2.2  nathanw 			    *rgb++ & 0x00ffffff);
    604  1.22.2.2  nathanw 		}
    605  1.22.2.2  nathanw 	}
    606  1.22.2.2  nathanw 
    607  1.22.2.2  nathanw 	KASSERT(rgb);
    608  1.22.2.2  nathanw 	KASSERT(LEGAL_CLUT_INDEX(beg));
    609  1.22.2.2  nathanw 	KASSERT(LEGAL_CLUT_INDEX(beg + cnt - 1));
    610  1.22.2.2  nathanw 	__plumvideo_clut_access(sc, __plumvideo_clut_set);
    611  1.22.2.2  nathanw }
    612  1.22.2.2  nathanw 
    613  1.22.2.2  nathanw void
    614  1.22.2.2  nathanw plumvideo_clut_default(struct plumvideo_softc *sc)
    615  1.22.2.2  nathanw {
    616  1.22.2.2  nathanw 	static void __plumvideo_clut_default(bus_space_tag_t,
    617  1.22.2.2  nathanw 	    bus_space_handle_t);
    618  1.22.2.2  nathanw 	static void __plumvideo_clut_default(iot, ioh)
    619  1.22.2.2  nathanw 	    bus_space_tag_t iot;
    620  1.22.2.2  nathanw 	bus_space_handle_t ioh;
    621  1.22.2.2  nathanw 	{
    622  1.22.2.5  nathanw 		static const u_int8_t compo6[6] = { 0, 51, 102, 153, 204, 255 };
    623  1.22.2.5  nathanw 		static const u_int32_t ansi_color[16] = {
    624  1.22.2.2  nathanw 			0x000000, 0xff0000, 0x00ff00, 0xffff00,
    625  1.22.2.2  nathanw 			0x0000ff, 0xff00ff, 0x00ffff, 0xffffff,
    626  1.22.2.2  nathanw 			0x000000, 0x800000, 0x008000, 0x808000,
    627  1.22.2.2  nathanw 			0x000080, 0x800080, 0x008080, 0x808080,
    628  1.22.2.2  nathanw 		};
    629  1.22.2.2  nathanw 		int i, r, g, b;
    630  1.22.2.2  nathanw 
    631  1.22.2.2  nathanw 		/* ANSI escape sequence */
    632  1.22.2.2  nathanw 		for (i = 0; i < 16; i++) {
    633  1.22.2.2  nathanw 			bus_space_write_4(iot, ioh, i << 2, ansi_color[i]);
    634  1.22.2.2  nathanw 		}
    635  1.22.2.2  nathanw 		/* 16 - 31, gray scale */
    636  1.22.2.2  nathanw 		for ( ; i < 32; i++) {
    637  1.22.2.2  nathanw 			int j = (i - 16) * 17;
    638  1.22.2.2  nathanw 			bus_space_write_4(iot, ioh, i << 2, RGB24(j, j, j));
    639  1.22.2.2  nathanw 		}
    640  1.22.2.2  nathanw 		/* 32 - 247, RGB color */
    641  1.22.2.2  nathanw 		for (r = 0; r < 6; r++) {
    642  1.22.2.2  nathanw 			for (g = 0; g < 6; g++) {
    643  1.22.2.2  nathanw 				for (b = 0; b < 6; b++) {
    644  1.22.2.2  nathanw 					bus_space_write_4(iot, ioh, i << 2,
    645  1.22.2.2  nathanw 					    RGB24(compo6[r],
    646  1.22.2.2  nathanw 						compo6[g],
    647  1.22.2.2  nathanw 						compo6[b]));
    648  1.22.2.2  nathanw 					i++;
    649  1.22.2.2  nathanw 				}
    650  1.22.2.2  nathanw 			}
    651  1.22.2.2  nathanw 		}
    652  1.22.2.2  nathanw 		/* 248 - 245, just white */
    653  1.22.2.2  nathanw 		for ( ; i < 256; i++) {
    654  1.22.2.2  nathanw 			bus_space_write_4(iot, ioh, i << 2, 0xffffff);
    655  1.22.2.2  nathanw 		}
    656  1.22.2.2  nathanw 	}
    657  1.22.2.2  nathanw 
    658  1.22.2.2  nathanw 	__plumvideo_clut_access(sc, __plumvideo_clut_default);
    659  1.22.2.2  nathanw }
    660  1.22.2.2  nathanw 
    661  1.22.2.2  nathanw void
    662  1.22.2.2  nathanw __plumvideo_clut_access(struct plumvideo_softc *sc, void (*palette_func)
    663  1.22.2.2  nathanw     (bus_space_tag_t, bus_space_handle_t))
    664  1.22.2.2  nathanw {
    665  1.22.2.2  nathanw 	bus_space_tag_t regt = sc->sc_regt;
    666  1.22.2.2  nathanw 	bus_space_handle_t regh = sc->sc_regh;
    667  1.22.2.2  nathanw 	plumreg_t val, gmode;
    668  1.22.2.2  nathanw 
    669  1.22.2.2  nathanw 	/* display off */
    670  1.22.2.2  nathanw 	val = bus_space_read_4(regt, regh, PLUM_VIDEO_PLGMD_REG);
    671  1.22.2.2  nathanw 	gmode = val & PLUM_VIDEO_PLGMD_GMODE_MASK;
    672  1.22.2.2  nathanw 	val &= ~PLUM_VIDEO_PLGMD_GMODE_MASK;
    673  1.22.2.2  nathanw 	bus_space_write_4(regt, regh, PLUM_VIDEO_PLGMD_REG, val);
    674  1.22.2.2  nathanw 
    675  1.22.2.2  nathanw 	/* palette access disable */
    676  1.22.2.2  nathanw 	val &= ~PLUM_VIDEO_PLGMD_PALETTE_ENABLE;
    677  1.22.2.2  nathanw 	bus_space_write_4(regt, regh, PLUM_VIDEO_PLGMD_REG, val);
    678  1.22.2.2  nathanw 
    679  1.22.2.2  nathanw 	/* change palette mode to CPU */
    680  1.22.2.2  nathanw 	val &= ~PLUM_VIDEO_PLGMD_MODE_DISPLAY;
    681  1.22.2.2  nathanw 	bus_space_write_4(regt, regh, PLUM_VIDEO_PLGMD_REG, val);
    682  1.22.2.2  nathanw 
    683  1.22.2.2  nathanw 	/* palette access */
    684  1.22.2.2  nathanw 	(*palette_func) (sc->sc_clutiot, sc->sc_clutioh);
    685  1.22.2.2  nathanw 
    686  1.22.2.2  nathanw 	/* change palette mode to Display */
    687  1.22.2.2  nathanw 	val |= PLUM_VIDEO_PLGMD_MODE_DISPLAY;
    688  1.22.2.2  nathanw 	bus_space_write_4(regt, regh, PLUM_VIDEO_PLGMD_REG, val);
    689  1.22.2.2  nathanw 
    690  1.22.2.2  nathanw 	/* palette access enable */
    691  1.22.2.2  nathanw 	val |= PLUM_VIDEO_PLGMD_PALETTE_ENABLE;
    692  1.22.2.2  nathanw 	bus_space_write_4(regt, regh, PLUM_VIDEO_PLGMD_REG, val);
    693  1.22.2.2  nathanw 
    694  1.22.2.2  nathanw 	/* display on */
    695  1.22.2.2  nathanw 	val |= gmode;
    696  1.22.2.2  nathanw 	bus_space_write_4(regt, regh, PLUM_VIDEO_PLGMD_REG, val);
    697  1.22.2.2  nathanw }
    698  1.22.2.2  nathanw 
    699  1.22.2.2  nathanw /* !!! */
    700  1.22.2.2  nathanw static void
    701  1.22.2.2  nathanw _flush_cache()
    702  1.22.2.2  nathanw {
    703  1.22.2.2  nathanw 	mips_dcache_wbinv_all();
    704  1.22.2.2  nathanw 	mips_icache_sync_all();
    705  1.22.2.2  nathanw }
    706  1.22.2.2  nathanw 
    707  1.22.2.2  nathanw int
    708  1.22.2.2  nathanw plumvideo_power(void *ctx, int type, long id, void *msg)
    709  1.22.2.2  nathanw {
    710  1.22.2.2  nathanw 	struct plumvideo_softc *sc = ctx;
    711  1.22.2.2  nathanw 	plum_chipset_tag_t pc = sc->sc_pc;
    712  1.22.2.2  nathanw 	bus_space_tag_t regt = sc->sc_regt;
    713  1.22.2.2  nathanw 	bus_space_handle_t regh = sc->sc_regh;
    714  1.22.2.2  nathanw 	int why = (int)msg;
    715  1.22.2.2  nathanw 
    716  1.22.2.2  nathanw 	switch (why) {
    717  1.22.2.2  nathanw 	case PWR_RESUME:
    718  1.22.2.2  nathanw 		if (!sc->sc_console)
    719  1.22.2.2  nathanw 			return (0); /* serial console */
    720  1.22.2.2  nathanw 
    721  1.22.2.2  nathanw 		DPRINTF(("%s: ON\n", sc->sc_dev.dv_xname));
    722  1.22.2.2  nathanw 		/* power on */
    723  1.22.2.2  nathanw 		/* LCD power on and display on */
    724  1.22.2.2  nathanw 		plum_power_establish(pc, PLUM_PWR_LCD);
    725  1.22.2.2  nathanw 		/* back-light on */
    726  1.22.2.2  nathanw 		plum_power_establish(pc, PLUM_PWR_BKL);
    727  1.22.2.2  nathanw 		plum_conf_write(regt, regh, PLUM_VIDEO_PLLUM_REG,
    728  1.22.2.2  nathanw 		    PLUM_VIDEO_PLLUM_MAX);
    729  1.22.2.2  nathanw 		break;
    730  1.22.2.2  nathanw 	case PWR_SUSPEND:
    731  1.22.2.2  nathanw 		/* FALLTHROUGH */
    732  1.22.2.2  nathanw 	case PWR_STANDBY:
    733  1.22.2.2  nathanw 		DPRINTF(("%s: OFF\n", sc->sc_dev.dv_xname));
    734  1.22.2.2  nathanw 		/* back-light off */
    735  1.22.2.2  nathanw 		plum_conf_write(regt, regh, PLUM_VIDEO_PLLUM_REG,
    736  1.22.2.2  nathanw 		    PLUM_VIDEO_PLLUM_MIN);
    737  1.22.2.2  nathanw 		plum_power_disestablish(pc, PLUM_PWR_BKL);
    738  1.22.2.2  nathanw 		/* power down */
    739  1.22.2.2  nathanw 		plum_power_disestablish(pc, PLUM_PWR_LCD);
    740  1.22.2.2  nathanw 		break;
    741  1.22.2.2  nathanw 	}
    742  1.22.2.2  nathanw 
    743  1.22.2.2  nathanw 	return (0);
    744  1.22.2.2  nathanw }
    745  1.22.2.2  nathanw 
    746  1.22.2.2  nathanw #ifdef PLUMVIDEODEBUG
    747  1.22.2.2  nathanw void
    748  1.22.2.2  nathanw plumvideo_dump(struct plumvideo_softc *sc)
    749  1.22.2.2  nathanw {
    750  1.22.2.2  nathanw 	bus_space_tag_t regt = sc->sc_regt;
    751  1.22.2.2  nathanw 	bus_space_handle_t regh = sc->sc_regh;
    752  1.22.2.2  nathanw 
    753  1.22.2.2  nathanw 	plumreg_t reg;
    754  1.22.2.2  nathanw 	int i;
    755  1.22.2.2  nathanw 
    756  1.22.2.2  nathanw 	for (i = 0; i < 0x160; i += 4) {
    757  1.22.2.2  nathanw 		reg = plum_conf_read(regt, regh, i);
    758  1.22.2.2  nathanw 		printf("0x%03x %08x", i, reg);
    759  1.22.2.2  nathanw 		dbg_bit_print(reg);
    760  1.22.2.2  nathanw 	}
    761  1.22.2.2  nathanw }
    762  1.22.2.2  nathanw #endif /* PLUMVIDEODEBUG */
    763