Home | History | Annotate | Line # | Download | only in hpc
bivideo.c revision 1.4
      1  1.4  sato /*	$NetBSD: bivideo.c,v 1.4 2001/03/09 08:54:18 sato Exp $	*/
      2  1.1   uch 
      3  1.1   uch /*-
      4  1.2   uch  * Copyright (c) 1999-2001
      5  1.1   uch  *         Shin Takemura and PocketBSD Project. All rights reserved.
      6  1.1   uch  *
      7  1.1   uch  * Redistribution and use in source and binary forms, with or without
      8  1.1   uch  * modification, are permitted provided that the following conditions
      9  1.1   uch  * are met:
     10  1.1   uch  * 1. Redistributions of source code must retain the above copyright
     11  1.1   uch  *    notice, this list of conditions and the following disclaimer.
     12  1.1   uch  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1   uch  *    notice, this list of conditions and the following disclaimer in the
     14  1.1   uch  *    documentation and/or other materials provided with the distribution.
     15  1.1   uch  * 3. All advertising materials mentioning features or use of this software
     16  1.1   uch  *    must display the following acknowledgement:
     17  1.1   uch  *	This product includes software developed by the PocketBSD project
     18  1.1   uch  *	and its contributors.
     19  1.1   uch  * 4. Neither the name of the project nor the names of its contributors
     20  1.1   uch  *    may be used to endorse or promote products derived from this software
     21  1.1   uch  *    without specific prior written permission.
     22  1.1   uch  *
     23  1.1   uch  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  1.1   uch  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  1.1   uch  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.1   uch  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  1.1   uch  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  1.1   uch  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  1.1   uch  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  1.1   uch  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  1.1   uch  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  1.1   uch  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  1.1   uch  * SUCH DAMAGE.
     34  1.1   uch  *
     35  1.1   uch  */
     36  1.1   uch #define FBDEBUG
     37  1.1   uch static const char _copyright[] __attribute__ ((unused)) =
     38  1.1   uch     "Copyright (c) 1999 Shin Takemura.  All rights reserved.";
     39  1.1   uch static const char _rcsid[] __attribute__ ((unused)) =
     40  1.4  sato     "$Id: bivideo.c,v 1.4 2001/03/09 08:54:18 sato Exp $";
     41  1.1   uch 
     42  1.1   uch #include <sys/param.h>
     43  1.1   uch #include <sys/systm.h>
     44  1.1   uch #include <sys/device.h>
     45  1.1   uch #include <sys/buf.h>
     46  1.1   uch #include <sys/ioctl.h>
     47  1.1   uch #include <sys/reboot.h>
     48  1.1   uch 
     49  1.1   uch #include <uvm/uvm_extern.h>
     50  1.1   uch 
     51  1.1   uch #include <machine/bus.h>
     52  1.1   uch #include <machine/autoconf.h>
     53  1.1   uch #include <machine/bootinfo.h>
     54  1.1   uch #include <machine/config_hook.h>
     55  1.1   uch 
     56  1.1   uch #include <dev/wscons/wsconsio.h>
     57  1.1   uch #include <dev/wscons/wsdisplayvar.h>
     58  1.1   uch 
     59  1.1   uch #include <dev/rasops/rasops.h>
     60  1.1   uch 
     61  1.1   uch #include <dev/hpc/hpcfbvar.h>
     62  1.1   uch #include <dev/hpc/hpcfbio.h>
     63  1.1   uch #include <dev/hpc/bivideovar.h>
     64  1.1   uch #include <dev/hpc/hpccmapvar.h>
     65  1.1   uch 
     66  1.1   uch #define VPRINTF(arg)	do { if (bootverbose) printf arg; } while(0);
     67  1.1   uch 
     68  1.1   uch /*
     69  1.1   uch  *  global variables
     70  1.1   uch  */
     71  1.1   uch int bivideo_dont_attach = 0;
     72  1.1   uch 
     73  1.1   uch /*
     74  1.1   uch  *  function prototypes
     75  1.1   uch  */
     76  1.2   uch int	bivideomatch(struct device *, struct cfdata *, void *);
     77  1.2   uch void	bivideoattach(struct device *, struct device *, void *);
     78  1.2   uch int	bivideo_ioctl(void *, u_long, caddr_t, int, struct proc *);
     79  1.2   uch paddr_t	bivideo_mmap(void *, off_t, int);
     80  1.1   uch 
     81  1.1   uch struct bivideo_softc {
     82  1.1   uch 	struct device		sc_dev;
     83  1.1   uch 	struct hpcfb_fbconf	sc_fbconf;
     84  1.1   uch 	struct hpcfb_dspconf	sc_dspconf;
     85  1.1   uch 	void			*sc_powerhook;	/* power management hook */
     86  1.1   uch 	int			sc_powerstate;
     87  1.1   uch #define PWRSTAT_SUSPEND		(1<<0)
     88  1.4  sato #define PWRSTAT_VIDEOOFF	(1<<1)
     89  1.4  sato #define PWRSTAT_LCD		(1<<2)
     90  1.4  sato #define PWRSTAT_BACKLIGHT	(1<<3)
     91  1.1   uch #define PWRSTAT_ALL		(0xffffffff)
     92  1.3  sato 	int			sc_brightness;
     93  1.3  sato 	int			sc_brightness_save;
     94  1.3  sato 	int			sc_max_brightness;
     95  1.3  sato 	int			sc_contrast;
     96  1.3  sato 	int			sc_max_contrast;
     97  1.3  sato 
     98  1.1   uch };
     99  1.3  sato 
    100  1.2   uch static int bivideo_init(struct hpcfb_fbconf *);
    101  1.2   uch static void bivideo_power(int, void *);
    102  1.2   uch static void bivideo_update_powerstate(struct bivideo_softc *, int);
    103  1.3  sato void	bivideo_get_backlight(struct bivideo_softc *);
    104  1.3  sato void	bivideo_init_brightness(struct bivideo_softc *);
    105  1.3  sato void	bivideo_init_contrast(struct bivideo_softc *);
    106  1.3  sato void	bivideo_set_brightness(struct bivideo_softc *, int);
    107  1.3  sato void	bivideo_set_contrast(struct bivideo_softc *, int);
    108  1.2   uch 
    109  1.2   uch #if defined __mips__ || defined __sh__ || defined __arm__
    110  1.2   uch #define __BTOP(x)		((paddr_t)(x) >> PGSHIFT)
    111  1.2   uch #define __PTOB(x)		((paddr_t)(x) << PGSHIFT)
    112  1.2   uch #else
    113  1.2   uch #error "define btop, ptob."
    114  1.2   uch #endif
    115  1.1   uch 
    116  1.1   uch /*
    117  1.1   uch  *  static variables
    118  1.1   uch  */
    119  1.1   uch struct cfattach bivideo_ca = {
    120  1.1   uch 	sizeof(struct bivideo_softc), bivideomatch, bivideoattach,
    121  1.1   uch };
    122  1.1   uch struct hpcfb_accessops bivideo_ha = {
    123  1.1   uch 	bivideo_ioctl, bivideo_mmap
    124  1.1   uch };
    125  1.1   uch 
    126  1.1   uch static int console_flag = 0;
    127  1.1   uch static int attach_flag = 0;
    128  1.1   uch 
    129  1.1   uch /*
    130  1.1   uch  *  function bodies
    131  1.1   uch  */
    132  1.1   uch int
    133  1.2   uch bivideomatch(struct device *parent, struct cfdata *match, void *aux)
    134  1.1   uch {
    135  1.1   uch 	struct mainbus_attach_args *ma = aux;
    136  1.1   uch 
    137  1.1   uch 	if (bivideo_dont_attach ||
    138  1.1   uch 	    strcmp(ma->ma_name, match->cf_driver->cd_name))
    139  1.1   uch 		return 0;
    140  1.1   uch 
    141  1.1   uch 	return (1);
    142  1.1   uch }
    143  1.1   uch 
    144  1.1   uch void
    145  1.2   uch bivideoattach(struct device *parent, struct device *self, void *aux)
    146  1.1   uch {
    147  1.1   uch 	struct bivideo_softc *sc = (struct bivideo_softc *)self;
    148  1.1   uch 	struct hpcfb_attach_args ha;
    149  1.1   uch 
    150  1.1   uch 	if (attach_flag) {
    151  1.1   uch 		panic("%s(%d): bivideo attached twice", __FILE__, __LINE__);
    152  1.1   uch 	}
    153  1.1   uch 	attach_flag = 1;
    154  1.1   uch 
    155  1.1   uch 	printf(": ");
    156  1.1   uch 	if (bivideo_init(&sc->sc_fbconf) != 0) {
    157  1.1   uch 		/* just return so that hpcfb will not be attached */
    158  1.1   uch 		return;
    159  1.1   uch 	}
    160  1.1   uch 
    161  1.1   uch 	printf("pseudo video controller");
    162  1.1   uch 	if (console_flag) {
    163  1.1   uch 		printf(", console");
    164  1.1   uch 	}
    165  1.1   uch 	printf("\n");
    166  1.1   uch 	printf("%s: framebuffer address: 0x%08lx\n",
    167  1.1   uch 		sc->sc_dev.dv_xname, (u_long)bootinfo->fb_addr);
    168  1.1   uch 
    169  1.1   uch 	/* Add a suspend hook to power saving */
    170  1.1   uch 	sc->sc_powerstate = 0;
    171  1.1   uch 	sc->sc_powerhook = powerhook_establish(bivideo_power, sc);
    172  1.1   uch 	if (sc->sc_powerhook == NULL)
    173  1.1   uch 		printf("%s: WARNING: unable to establish power hook\n",
    174  1.1   uch 			sc->sc_dev.dv_xname);
    175  1.1   uch 
    176  1.3  sato 	/* initialize backlight brightness and lcd contrast */
    177  1.3  sato 	sc->sc_brightness = sc->sc_contrast =
    178  1.3  sato 	sc->sc_max_brightness = sc->sc_max_contrast = -1;
    179  1.3  sato 	bivideo_get_backlight(sc);
    180  1.3  sato 	bivideo_init_brightness(sc);
    181  1.3  sato 	bivideo_init_contrast(sc);
    182  1.3  sato 
    183  1.1   uch 	ha.ha_console = console_flag;
    184  1.1   uch 	ha.ha_accessops = &bivideo_ha;
    185  1.1   uch 	ha.ha_accessctx = sc;
    186  1.1   uch 	ha.ha_curfbconf = 0;
    187  1.1   uch 	ha.ha_nfbconf = 1;
    188  1.1   uch 	ha.ha_fbconflist = &sc->sc_fbconf;
    189  1.1   uch 	ha.ha_curdspconf = 0;
    190  1.1   uch 	ha.ha_ndspconf = 1;
    191  1.1   uch 	ha.ha_dspconflist = &sc->sc_dspconf;
    192  1.1   uch 
    193  1.1   uch 	config_found(self, &ha, hpcfbprint);
    194  1.1   uch }
    195  1.1   uch 
    196  1.1   uch int
    197  1.2   uch bivideo_getcnfb(struct hpcfb_fbconf *fb)
    198  1.1   uch {
    199  1.1   uch 	console_flag = 1;
    200  1.1   uch 
    201  1.1   uch 	return bivideo_init(fb);
    202  1.1   uch }
    203  1.1   uch 
    204  1.1   uch static int
    205  1.2   uch bivideo_init(struct hpcfb_fbconf *fb)
    206  1.1   uch {
    207  1.1   uch 	/*
    208  1.1   uch 	 * get fb settings from bootinfo
    209  1.1   uch 	 */
    210  1.1   uch 	if (bootinfo == NULL ||
    211  1.1   uch 	    bootinfo->fb_addr == 0 ||
    212  1.1   uch 	    bootinfo->fb_line_bytes == 0 ||
    213  1.1   uch 	    bootinfo->fb_width == 0 ||
    214  1.1   uch 	    bootinfo->fb_height == 0) {
    215  1.1   uch 		printf("no frame buffer infomation.\n");
    216  1.1   uch 		return (-1);
    217  1.1   uch 	}
    218  1.1   uch 
    219  1.1   uch 	/* zero fill */
    220  1.1   uch 	bzero(fb, sizeof(*fb));
    221  1.1   uch 
    222  1.1   uch 	fb->hf_conf_index	= 0;	/* configuration index		*/
    223  1.1   uch 	fb->hf_nconfs		= 1;   	/* how many configurations	*/
    224  1.1   uch 	strcpy(fb->hf_name, "built-in video");
    225  1.1   uch 					/* frame buffer name		*/
    226  1.1   uch 	strcpy(fb->hf_conf_name, "default");
    227  1.1   uch 					/* configuration name		*/
    228  1.1   uch 	fb->hf_height		= bootinfo->fb_height;
    229  1.1   uch 	fb->hf_width		= bootinfo->fb_width;
    230  1.1   uch 	fb->hf_baseaddr		= (u_long)bootinfo->fb_addr;
    231  1.1   uch 	fb->hf_offset		= (u_long)bootinfo->fb_addr -
    232  1.2   uch 				      __PTOB(__BTOP(bootinfo->fb_addr));
    233  1.1   uch 					/* frame buffer start offset   	*/
    234  1.1   uch 	fb->hf_bytes_per_line	= bootinfo->fb_line_bytes;
    235  1.1   uch 	fb->hf_nplanes		= 1;
    236  1.1   uch 	fb->hf_bytes_per_plane	= bootinfo->fb_height *
    237  1.1   uch 					bootinfo->fb_line_bytes;
    238  1.1   uch 
    239  1.1   uch 	fb->hf_access_flags |= HPCFB_ACCESS_BYTE;
    240  1.1   uch 	fb->hf_access_flags |= HPCFB_ACCESS_WORD;
    241  1.1   uch 	fb->hf_access_flags |= HPCFB_ACCESS_DWORD;
    242  1.1   uch 
    243  1.1   uch 	switch (bootinfo->fb_type) {
    244  1.1   uch 		/*
    245  1.1   uch 		 * gray scale
    246  1.1   uch 		 */
    247  1.1   uch 	case BIFB_D2_M2L_3:
    248  1.1   uch 	case BIFB_D2_M2L_3x2:
    249  1.1   uch 		fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
    250  1.1   uch 		/* fall through */
    251  1.1   uch 	case BIFB_D2_M2L_0:
    252  1.1   uch 	case BIFB_D2_M2L_0x2:
    253  1.1   uch 		fb->hf_class = HPCFB_CLASS_GRAYSCALE;
    254  1.1   uch 		fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
    255  1.1   uch 		fb->hf_pack_width = 8;
    256  1.1   uch 		fb->hf_pixels_per_pack = 4;
    257  1.1   uch 		fb->hf_pixel_width = 2;
    258  1.1   uch 		fb->hf_class_data_length = sizeof(struct hf_gray_tag);
    259  1.1   uch 		fb->hf_u.hf_gray.hf_flags = 0;	/* reserved for future use */
    260  1.1   uch 		break;
    261  1.1   uch 
    262  1.1   uch 	case BIFB_D4_M2L_F:
    263  1.1   uch 	case BIFB_D4_M2L_Fx2:
    264  1.1   uch 		fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
    265  1.1   uch 		/* fall through */
    266  1.1   uch 	case BIFB_D4_M2L_0:
    267  1.1   uch 	case BIFB_D4_M2L_0x2:
    268  1.1   uch 		fb->hf_class = HPCFB_CLASS_GRAYSCALE;
    269  1.1   uch 		fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
    270  1.1   uch 		fb->hf_pack_width = 8;
    271  1.1   uch 		fb->hf_pixels_per_pack = 2;
    272  1.1   uch 		fb->hf_pixel_width = 4;
    273  1.1   uch 		fb->hf_class_data_length = sizeof(struct hf_gray_tag);
    274  1.1   uch 		fb->hf_u.hf_gray.hf_flags = 0;	/* reserved for future use */
    275  1.1   uch 		break;
    276  1.1   uch 
    277  1.1   uch 		/*
    278  1.1   uch 		 * indexed color
    279  1.1   uch 		 */
    280  1.1   uch 	case BIFB_D8_FF:
    281  1.1   uch 		fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
    282  1.1   uch 		/* fall through */
    283  1.1   uch 	case BIFB_D8_00:
    284  1.1   uch 		fb->hf_class = HPCFB_CLASS_INDEXCOLOR;
    285  1.1   uch 		fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
    286  1.1   uch 		fb->hf_pack_width = 8;
    287  1.1   uch 		fb->hf_pixels_per_pack = 1;
    288  1.1   uch 		fb->hf_pixel_width = 8;
    289  1.1   uch 		fb->hf_class_data_length = sizeof(struct hf_indexed_tag);
    290  1.1   uch 		fb->hf_u.hf_indexed.hf_flags = 0; /* reserved for future use */
    291  1.1   uch 		break;
    292  1.1   uch 
    293  1.1   uch 		/*
    294  1.1   uch 		 * RGB color
    295  1.1   uch 		 */
    296  1.1   uch 	case BIFB_D16_FFFF:
    297  1.1   uch 		fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
    298  1.1   uch 		/* fall through */
    299  1.1   uch 	case BIFB_D16_0000:
    300  1.1   uch 		fb->hf_class = HPCFB_CLASS_RGBCOLOR;
    301  1.1   uch 		fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
    302  1.1   uch #if BYTE_ORDER == LITTLE_ENDIAN
    303  1.1   uch 		fb->hf_swap_flags = HPCFB_SWAP_BYTE;
    304  1.1   uch #endif
    305  1.1   uch 		fb->hf_pack_width = 16;
    306  1.1   uch 		fb->hf_pixels_per_pack = 1;
    307  1.1   uch 		fb->hf_pixel_width = 16;
    308  1.1   uch 
    309  1.1   uch 		fb->hf_class_data_length = sizeof(struct hf_rgb_tag);
    310  1.1   uch 		fb->hf_u.hf_rgb.hf_flags = 0;	/* reserved for future use */
    311  1.1   uch 
    312  1.1   uch 		fb->hf_u.hf_rgb.hf_red_width = 5;
    313  1.1   uch 		fb->hf_u.hf_rgb.hf_red_shift = 11;
    314  1.1   uch 		fb->hf_u.hf_rgb.hf_green_width = 6;
    315  1.1   uch 		fb->hf_u.hf_rgb.hf_green_shift = 5;
    316  1.1   uch 		fb->hf_u.hf_rgb.hf_blue_width = 5;
    317  1.1   uch 		fb->hf_u.hf_rgb.hf_blue_shift = 0;
    318  1.1   uch 		fb->hf_u.hf_rgb.hf_alpha_width = 0;
    319  1.1   uch 		fb->hf_u.hf_rgb.hf_alpha_shift = 0;
    320  1.1   uch 		break;
    321  1.1   uch 
    322  1.1   uch 	default:
    323  1.1   uch 		printf("unsupported type %d.\n", bootinfo->fb_type);
    324  1.1   uch 		return (-1);
    325  1.1   uch 		break;
    326  1.1   uch 	}
    327  1.1   uch 
    328  1.1   uch 	return (0); /* no error */
    329  1.1   uch }
    330  1.1   uch 
    331  1.1   uch static void
    332  1.2   uch bivideo_power(int why, void *arg)
    333  1.1   uch {
    334  1.1   uch 	struct bivideo_softc *sc = arg;
    335  1.1   uch 
    336  1.1   uch 	switch (why) {
    337  1.1   uch 	case PWR_SUSPEND:
    338  1.1   uch 	case PWR_STANDBY:
    339  1.1   uch 		sc->sc_powerstate |= PWRSTAT_SUSPEND;
    340  1.1   uch 		bivideo_update_powerstate(sc, PWRSTAT_ALL);
    341  1.1   uch 		break;
    342  1.1   uch 	case PWR_RESUME:
    343  1.1   uch 		sc->sc_powerstate &= ~PWRSTAT_SUSPEND;
    344  1.1   uch 		bivideo_update_powerstate(sc, PWRSTAT_ALL);
    345  1.1   uch 		break;
    346  1.1   uch 	}
    347  1.1   uch }
    348  1.1   uch 
    349  1.1   uch static void
    350  1.2   uch bivideo_update_powerstate(struct bivideo_softc *sc, int updates)
    351  1.1   uch {
    352  1.1   uch 	if (updates & PWRSTAT_LCD)
    353  1.1   uch 		config_hook_call(CONFIG_HOOK_POWERCONTROL,
    354  1.1   uch 		    CONFIG_HOOK_POWERCONTROL_LCD,
    355  1.4  sato 		    (void*)!(sc->sc_powerstate &
    356  1.4  sato 				(PWRSTAT_VIDEOOFF|PWRSTAT_SUSPEND)));
    357  1.1   uch 
    358  1.1   uch 	if (updates & PWRSTAT_BACKLIGHT)
    359  1.1   uch 		config_hook_call(CONFIG_HOOK_POWERCONTROL,
    360  1.1   uch 		    CONFIG_HOOK_POWERCONTROL_LCDLIGHT,
    361  1.4  sato 		    (void*)(!(sc->sc_powerstate &
    362  1.4  sato 				(PWRSTAT_VIDEOOFF|PWRSTAT_SUSPEND)) &&
    363  1.1   uch 			     (sc->sc_powerstate & PWRSTAT_BACKLIGHT)));
    364  1.1   uch }
    365  1.1   uch 
    366  1.1   uch int
    367  1.2   uch bivideo_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
    368  1.1   uch {
    369  1.1   uch 	struct bivideo_softc *sc = (struct bivideo_softc *)v;
    370  1.1   uch 	struct hpcfb_fbconf *fbconf;
    371  1.1   uch 	struct hpcfb_dspconf *dspconf;
    372  1.1   uch 	struct wsdisplay_cmap *cmap;
    373  1.1   uch 	struct wsdisplay_param *dispparam;
    374  1.1   uch 
    375  1.1   uch 	switch (cmd) {
    376  1.1   uch 	case WSDISPLAYIO_GETCMAP:
    377  1.1   uch 		cmap = (struct wsdisplay_cmap*)data;
    378  1.1   uch 
    379  1.1   uch 		if (sc->sc_fbconf.hf_class != HPCFB_CLASS_INDEXCOLOR ||
    380  1.1   uch 		    sc->sc_fbconf.hf_pack_width != 8 ||
    381  1.1   uch 		    256 <= cmap->index ||
    382  1.1   uch 		    256 < (cmap->index + cmap->count))
    383  1.1   uch 			return (EINVAL);
    384  1.1   uch 
    385  1.1   uch 		if (!uvm_useracc(cmap->red, cmap->count, B_WRITE) ||
    386  1.1   uch 		    !uvm_useracc(cmap->green, cmap->count, B_WRITE) ||
    387  1.1   uch 		    !uvm_useracc(cmap->blue, cmap->count, B_WRITE))
    388  1.1   uch 			return (EFAULT);
    389  1.1   uch 
    390  1.1   uch 		copyout(&bivideo_cmap_r[cmap->index], cmap->red, cmap->count);
    391  1.1   uch 		copyout(&bivideo_cmap_g[cmap->index], cmap->green,cmap->count);
    392  1.1   uch 		copyout(&bivideo_cmap_b[cmap->index], cmap->blue, cmap->count);
    393  1.1   uch 
    394  1.1   uch 		return (0);
    395  1.1   uch 
    396  1.1   uch 	case WSDISPLAYIO_PUTCMAP:
    397  1.1   uch 		/*
    398  1.1   uch 		 * This driver can't set color map.
    399  1.1   uch 		 */
    400  1.1   uch 		return (EINVAL);
    401  1.4  sato 
    402  1.4  sato 	case WSDISPLAYIO_SVIDEO:
    403  1.4  sato 		if (*(int *)data == WSDISPLAYIO_VIDEO_OFF)
    404  1.4  sato 			sc->sc_powerstate |= PWRSTAT_VIDEOOFF;
    405  1.4  sato 		else
    406  1.4  sato 			sc->sc_powerstate &= ~PWRSTAT_VIDEOOFF;
    407  1.4  sato 		bivideo_update_powerstate(sc, PWRSTAT_ALL);
    408  1.4  sato 		return 0;
    409  1.4  sato 
    410  1.4  sato 	case WSDISPLAYIO_GVIDEO:
    411  1.4  sato 		*(int *)data = (sc->sc_powerstate&PWRSTAT_VIDEOOFF) ?
    412  1.4  sato 				WSDISPLAYIO_VIDEO_OFF:WSDISPLAYIO_VIDEO_ON;
    413  1.4  sato 		return 0;
    414  1.1   uch 
    415  1.3  sato 
    416  1.1   uch 	case WSDISPLAYIO_GETPARAM:
    417  1.1   uch 		dispparam = (struct wsdisplay_param*)data;
    418  1.1   uch 		switch (dispparam->param) {
    419  1.1   uch 		case WSDISPLAYIO_PARAM_BACKLIGHT:
    420  1.3  sato 			VPRINTF(("bivideo_ioctl: GETPARAM:BACKLIGHT call\n"));
    421  1.3  sato 			if (sc->sc_max_brightness == -1)
    422  1.3  sato 				bivideo_init_brightness(sc);
    423  1.3  sato 			bivideo_get_backlight(sc);
    424  1.1   uch 			dispparam->min = 0;
    425  1.1   uch 			dispparam->max = 1;
    426  1.3  sato 			if (sc->sc_max_brightness > 0)
    427  1.3  sato 				dispparam->curval = sc->sc_brightness > 0? 1: 0;
    428  1.3  sato 			else
    429  1.3  sato 				dispparam->curval =
    430  1.3  sato 				    (sc->sc_powerstate & PWRSTAT_BACKLIGHT) ? 1 : 0;
    431  1.1   uch 			VPRINTF(("bivideo_ioctl: GETPARAM:BACKLIGHT:%d\n",
    432  1.1   uch 				dispparam->curval));
    433  1.3  sato 			return 0;
    434  1.1   uch 			break;
    435  1.1   uch 		case WSDISPLAYIO_PARAM_CONTRAST:
    436  1.3  sato 			VPRINTF(("bivideo_ioctl: GETPARAM:CONTRAST call\n"));
    437  1.3  sato 			if (sc->sc_max_contrast == -1)
    438  1.3  sato 				bivideo_init_contrast(sc);
    439  1.3  sato 			if (sc->sc_max_contrast > 0) {
    440  1.3  sato 				dispparam->min = 0;
    441  1.3  sato 				dispparam->max = sc->sc_max_contrast;
    442  1.3  sato 				dispparam->curval = sc->sc_contrast;
    443  1.3  sato 				VPRINTF(("bivideo_ioctl: GETPARAM:CONTRAST max=%d, current=%d\n", sc->sc_max_contrast, sc->sc_contrast));
    444  1.3  sato 				return 0;
    445  1.3  sato 			} else {
    446  1.3  sato 				VPRINTF(("bivideo_ioctl: GETPARAM:CONTRAST ret\n"));
    447  1.3  sato 				return (EINVAL);
    448  1.3  sato 			}
    449  1.3  sato 			break;
    450  1.1   uch 		case WSDISPLAYIO_PARAM_BRIGHTNESS:
    451  1.3  sato 			VPRINTF(("bivideo_ioctl: GETPARAM:BRIGHTNESS call\n"));
    452  1.3  sato 			if (sc->sc_max_brightness == -1)
    453  1.3  sato 				bivideo_init_brightness(sc);
    454  1.3  sato 			if (sc->sc_max_brightness > 0) {
    455  1.3  sato 				dispparam->min = 0;
    456  1.3  sato 				dispparam->max = sc->sc_max_brightness;
    457  1.3  sato 				dispparam->curval = sc->sc_brightness;
    458  1.3  sato 				VPRINTF(("bivideo_ioctl: GETPARAM:BRIGHTNESS max=%d, current=%d\n", sc->sc_max_brightness, sc->sc_brightness));
    459  1.3  sato 				return 0;
    460  1.3  sato 			} else {
    461  1.3  sato 				VPRINTF(("bivideo_ioctl: GETPARAM:BRIGHTNESS ret\n"));
    462  1.3  sato 				return (EINVAL);
    463  1.3  sato 			}
    464  1.1   uch 			return (EINVAL);
    465  1.1   uch 		default:
    466  1.1   uch 			return (EINVAL);
    467  1.1   uch 		}
    468  1.1   uch 		return (0);
    469  1.1   uch 
    470  1.1   uch 	case WSDISPLAYIO_SETPARAM:
    471  1.1   uch 		dispparam = (struct wsdisplay_param*)data;
    472  1.1   uch 		switch (dispparam->param) {
    473  1.1   uch 		case WSDISPLAYIO_PARAM_BACKLIGHT:
    474  1.3  sato 			VPRINTF(("bivideo_ioctl: SETPARAM:BACKLIGHT call\n"));
    475  1.1   uch 			if (dispparam->curval < 0 ||
    476  1.1   uch 			    1 < dispparam->curval)
    477  1.1   uch 				return (EINVAL);
    478  1.3  sato 			if (sc->sc_max_brightness == -1)
    479  1.3  sato 				bivideo_init_brightness(sc);
    480  1.3  sato 			VPRINTF(("bivideo_ioctl: SETPARAM:max brightness=%d\n", sc->sc_max_brightness));
    481  1.3  sato 			if (sc->sc_max_brightness > 0) { /* dimmer */
    482  1.3  sato 				if (dispparam->curval == 0){
    483  1.3  sato 					sc->sc_brightness_save = sc->sc_brightness;
    484  1.3  sato 					bivideo_set_brightness(sc, 0);	/* min */
    485  1.3  sato 				} else {
    486  1.3  sato 					if (sc->sc_brightness_save == 0)
    487  1.3  sato 						sc->sc_brightness_save = sc->sc_max_brightness;
    488  1.3  sato 					bivideo_set_brightness(sc, sc->sc_brightness_save);
    489  1.3  sato 				}
    490  1.3  sato 				VPRINTF(("bivideo_ioctl: SETPARAM:BACKLIGHT: brightness=%d\n", sc->sc_brightness));
    491  1.3  sato 			} else { /* off */
    492  1.3  sato 				if (dispparam->curval == 0)
    493  1.3  sato 					sc->sc_powerstate &= ~PWRSTAT_BACKLIGHT;
    494  1.3  sato 				else
    495  1.3  sato 					sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
    496  1.3  sato 				VPRINTF(("bivideo_ioctl: SETPARAM:BACKLIGHT: powerstate %d\n",
    497  1.3  sato 						(sc->sc_powerstate & PWRSTAT_BACKLIGHT)?1:0));
    498  1.3  sato 				bivideo_update_powerstate(sc, PWRSTAT_BACKLIGHT);
    499  1.3  sato 				VPRINTF(("bivideo_ioctl: SETPARAM:BACKLIGHT:%d\n",
    500  1.3  sato 					(sc->sc_powerstate & PWRSTAT_BACKLIGHT)?1:0));
    501  1.3  sato 			}
    502  1.3  sato 			return 0;
    503  1.1   uch 			break;
    504  1.1   uch 		case WSDISPLAYIO_PARAM_CONTRAST:
    505  1.3  sato 			VPRINTF(("bivideo_ioctl: SETPARAM:CONTRAST call\n"));
    506  1.3  sato 			if (sc->sc_max_contrast == -1)
    507  1.3  sato 				bivideo_init_contrast(sc);
    508  1.3  sato 			if (dispparam->curval < 0 ||
    509  1.3  sato 			    sc->sc_max_contrast < dispparam->curval)
    510  1.3  sato 				return (EINVAL);
    511  1.3  sato 			if (sc->sc_max_contrast > 0) {
    512  1.3  sato 				int org = sc->sc_contrast;
    513  1.3  sato 				bivideo_set_contrast(sc, dispparam->curval);
    514  1.3  sato 				VPRINTF(("bivideo_ioctl: SETPARAM:CONTRAST org=%d, current=%d\n", org, sc->sc_contrast));
    515  1.3  sato 				return 0;
    516  1.3  sato 			} else {
    517  1.3  sato 				VPRINTF(("bivideo_ioctl: SETPARAM:CONTRAST ret\n"));
    518  1.3  sato 				return (EINVAL);
    519  1.3  sato 			}
    520  1.3  sato 			break;
    521  1.1   uch 		case WSDISPLAYIO_PARAM_BRIGHTNESS:
    522  1.3  sato 			VPRINTF(("bivideo_ioctl: SETPARAM:BRIGHTNESS call\n"));
    523  1.3  sato 			if (sc->sc_max_brightness == -1)
    524  1.3  sato 				bivideo_init_brightness(sc);
    525  1.3  sato 			if (dispparam->curval < 0 ||
    526  1.3  sato 			    sc->sc_max_brightness < dispparam->curval)
    527  1.3  sato 				return (EINVAL);
    528  1.3  sato 			if (sc->sc_max_brightness > 0) {
    529  1.3  sato 				int org = sc->sc_brightness;
    530  1.3  sato 				bivideo_set_brightness(sc, dispparam->curval);
    531  1.3  sato 				VPRINTF(("bivideo_ioctl: SETPARAM:BRIGHTNESS org=%d, current=%d\n", org, sc->sc_brightness));
    532  1.3  sato 				return 0;
    533  1.3  sato 			} else {
    534  1.3  sato 				VPRINTF(("bivideo_ioctl: SETPARAM:BRIGHTNESS ret\n"));
    535  1.3  sato 				return (EINVAL);
    536  1.3  sato 			}
    537  1.3  sato 			break;
    538  1.1   uch 		default:
    539  1.1   uch 			return (EINVAL);
    540  1.1   uch 		}
    541  1.1   uch 		return (0);
    542  1.1   uch 
    543  1.1   uch 	case HPCFBIO_GCONF:
    544  1.1   uch 		fbconf = (struct hpcfb_fbconf *)data;
    545  1.1   uch 		if (fbconf->hf_conf_index != 0 &&
    546  1.1   uch 		    fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
    547  1.1   uch 			return (EINVAL);
    548  1.1   uch 		}
    549  1.1   uch 		*fbconf = sc->sc_fbconf;	/* structure assignment */
    550  1.1   uch 		return (0);
    551  1.1   uch 	case HPCFBIO_SCONF:
    552  1.1   uch 		fbconf = (struct hpcfb_fbconf *)data;
    553  1.1   uch 		if (fbconf->hf_conf_index != 0 &&
    554  1.1   uch 		    fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
    555  1.1   uch 			return (EINVAL);
    556  1.1   uch 		}
    557  1.1   uch 		/*
    558  1.1   uch 		 * nothing to do because we have only one configration
    559  1.1   uch 		 */
    560  1.1   uch 		return (0);
    561  1.1   uch 	case HPCFBIO_GDSPCONF:
    562  1.1   uch 		dspconf = (struct hpcfb_dspconf *)data;
    563  1.1   uch 		if ((dspconf->hd_unit_index != 0 &&
    564  1.1   uch 		     dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
    565  1.1   uch 		    (dspconf->hd_conf_index != 0 &&
    566  1.1   uch 		     dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
    567  1.1   uch 			return (EINVAL);
    568  1.1   uch 		}
    569  1.1   uch 		*dspconf = sc->sc_dspconf;	/* structure assignment */
    570  1.1   uch 		return (0);
    571  1.1   uch 	case HPCFBIO_SDSPCONF:
    572  1.1   uch 		dspconf = (struct hpcfb_dspconf *)data;
    573  1.1   uch 		if ((dspconf->hd_unit_index != 0 &&
    574  1.1   uch 		     dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
    575  1.1   uch 		    (dspconf->hd_conf_index != 0 &&
    576  1.1   uch 		     dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
    577  1.1   uch 			return (EINVAL);
    578  1.1   uch 		}
    579  1.1   uch 		/*
    580  1.1   uch 		 * nothing to do
    581  1.1   uch 		 * because we have only one unit and one configration
    582  1.1   uch 		 */
    583  1.1   uch 		return (0);
    584  1.1   uch 	case HPCFBIO_GOP:
    585  1.1   uch 	case HPCFBIO_SOP:
    586  1.1   uch 		/*
    587  1.1   uch 		 * curently not implemented...
    588  1.1   uch 		 */
    589  1.1   uch 		return (EINVAL);
    590  1.1   uch 	}
    591  1.1   uch 
    592  1.1   uch 	return (ENOTTY);
    593  1.1   uch }
    594  1.1   uch 
    595  1.1   uch paddr_t
    596  1.2   uch bivideo_mmap(void *ctx, off_t offset, int prot)
    597  1.1   uch {
    598  1.1   uch 	struct bivideo_softc *sc = (struct bivideo_softc *)ctx;
    599  1.1   uch 
    600  1.1   uch 	if (offset < 0 ||
    601  1.1   uch 	    (sc->sc_fbconf.hf_bytes_per_plane +
    602  1.1   uch 		sc->sc_fbconf.hf_offset) <  offset)
    603  1.1   uch 		return -1;
    604  1.1   uch 
    605  1.2   uch 	return __BTOP((u_long)bootinfo->fb_addr + offset);
    606  1.3  sato }
    607  1.3  sato 
    608  1.3  sato void
    609  1.3  sato bivideo_get_backlight(struct bivideo_softc *sc)
    610  1.3  sato {
    611  1.3  sato 	int val = -1;
    612  1.3  sato 
    613  1.3  sato 	if (sc->sc_max_brightness < 0) {
    614  1.3  sato 		if (config_hook_call(CONFIG_HOOK_GET,
    615  1.3  sato 		     CONFIG_HOOK_POWER_LCDLIGHT, &val) != -1) {
    616  1.3  sato 			if (val == 0)
    617  1.3  sato 				sc->sc_powerstate &= ~PWRSTAT_BACKLIGHT;
    618  1.3  sato 			else
    619  1.3  sato 				sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
    620  1.3  sato 		}
    621  1.3  sato 	}
    622  1.3  sato }
    623  1.3  sato 
    624  1.3  sato void
    625  1.3  sato bivideo_init_brightness(struct bivideo_softc *sc)
    626  1.3  sato {
    627  1.3  sato 	int val = -1;
    628  1.3  sato 
    629  1.3  sato 	if (config_hook_call(CONFIG_HOOK_GET,
    630  1.3  sato 	     CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
    631  1.3  sato 		sc->sc_brightness_save = sc->sc_brightness = val;
    632  1.3  sato 	}
    633  1.3  sato 	val = -1;
    634  1.3  sato 	if (config_hook_call(CONFIG_HOOK_GET,
    635  1.3  sato 	     CONFIG_HOOK_BRIGHTNESS_MAX, &val) != -1) {
    636  1.3  sato 		sc->sc_max_brightness = val;
    637  1.3  sato 	}
    638  1.3  sato 	return;
    639  1.3  sato }
    640  1.3  sato 
    641  1.3  sato 
    642  1.3  sato void
    643  1.3  sato bivideo_init_contrast(struct bivideo_softc *sc)
    644  1.3  sato {
    645  1.3  sato 	int val = -1;
    646  1.3  sato 
    647  1.3  sato 	if (config_hook_call(CONFIG_HOOK_GET,
    648  1.3  sato 	     CONFIG_HOOK_CONTRAST, &val) != -1) {
    649  1.3  sato 		sc->sc_contrast = val;
    650  1.3  sato 	}
    651  1.3  sato 	val = -1;
    652  1.3  sato 	if (config_hook_call(CONFIG_HOOK_GET,
    653  1.3  sato 	     CONFIG_HOOK_CONTRAST_MAX, &val) != -1) {
    654  1.3  sato 		sc->sc_max_contrast = val;
    655  1.3  sato 	}
    656  1.3  sato 	return;
    657  1.3  sato }
    658  1.3  sato 
    659  1.3  sato void
    660  1.3  sato bivideo_set_brightness(struct bivideo_softc *sc, int val)
    661  1.3  sato {
    662  1.3  sato 	sc->sc_brightness = val;
    663  1.3  sato 
    664  1.3  sato 	config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
    665  1.3  sato 	if (config_hook_call(CONFIG_HOOK_GET,
    666  1.3  sato 	     CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
    667  1.3  sato 		sc->sc_brightness = val;
    668  1.3  sato 	}
    669  1.3  sato }
    670  1.3  sato 
    671  1.3  sato void
    672  1.3  sato bivideo_set_contrast(struct bivideo_softc *sc, int val)
    673  1.3  sato {
    674  1.3  sato 	sc->sc_contrast = val;
    675  1.3  sato 
    676  1.3  sato 	config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST, &val);
    677  1.3  sato 	if (config_hook_call(CONFIG_HOOK_GET,
    678  1.3  sato 	     CONFIG_HOOK_CONTRAST, &val) != -1) {
    679  1.3  sato 		sc->sc_contrast = val;
    680  1.3  sato 	}
    681  1.1   uch }
    682