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