Home | History | Annotate | Line # | Download | only in dev
sed_saip.c revision 1.2
      1 /*	$NetBSD: sed_saip.c,v 1.2 2001/06/16 12:53:05 toshii 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     "$NetBSD: sed_saip.c,v 1.2 2001/06/16 12:53:05 toshii 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/hpccmapvar.h>
     64 
     65 #define VPRINTF(arg)	do { if (bootverbose) printf arg; } while(0);
     66 
     67 /*
     68  *  function prototypes
     69  */
     70 int	sed1356match(struct device *, struct cfdata *, void *);
     71 void	sed1356attach(struct device *, struct device *, void *);
     72 int	sed1356_ioctl(void *, u_long, caddr_t, int, struct proc *);
     73 paddr_t	sed1356_mmap(void *, off_t, int);
     74 
     75 struct sed1356_softc {
     76 	struct device		sc_dev;
     77 	struct hpcfb_fbconf	sc_fbconf;
     78 	struct hpcfb_dspconf	sc_dspconf;
     79 
     80 	void			*sc_powerhook;	/* power management hook */
     81 	int			sc_powerstate;
     82 #define PWRSTAT_SUSPEND		(1<<0)
     83 #define PWRSTAT_VIDEOOFF	(1<<1)
     84 #define PWRSTAT_LCD		(1<<2)
     85 #define PWRSTAT_BACKLIGHT	(1<<3)
     86 #define PWRSTAT_ALL		(0xffffffff)
     87 	int			sc_lcd_inited;
     88 #define BACKLIGHT_INITED	(1<<0)
     89 #define BRIGHTNESS_INITED	(1<<1)
     90 #define CONTRAST_INITED		(1<<2)
     91 	int			sc_brightness;
     92 	int			sc_brightness_save;
     93 	int			sc_max_brightness;
     94 	int			sc_contrast;
     95 	int			sc_max_contrast;
     96 
     97 };
     98 
     99 extern	struct bus_space sa11x0_bs_tag;
    100 
    101 static int sed1356_init(struct hpcfb_fbconf *);
    102 static void sed1356_power(int, void *);
    103 static void sed1356_update_powerstate(struct sed1356_softc *, int);
    104 void	sed1356_init_backlight(struct sed1356_softc *, int);
    105 void	sed1356_init_brightness(struct sed1356_softc *, int);
    106 void	sed1356_init_contrast(struct sed1356_softc *, int);
    107 void	sed1356_set_brightness(struct sed1356_softc *, int);
    108 void	sed1356_set_contrast(struct sed1356_softc *, int);
    109 
    110 #if defined __mips__ || defined __sh__ || defined __arm__
    111 #define __BTOP(x)		((paddr_t)(x) >> PGSHIFT)
    112 #define __PTOB(x)		((paddr_t)(x) << PGSHIFT)
    113 #else
    114 #error "define btop, ptob."
    115 #endif
    116 
    117 /*
    118  *  static variables
    119  */
    120 struct cfattach sed_ca = {
    121 	sizeof(struct sed1356_softc), sed1356match, sed1356attach,
    122 };
    123 struct hpcfb_accessops sed1356_ha = {
    124 	sed1356_ioctl, sed1356_mmap
    125 };
    126 
    127 static int console_flag = 0;
    128 static int attach_flag = 0;
    129 
    130 /*
    131  *  function bodies
    132  */
    133 int
    134 sed1356match(struct device *parent, struct cfdata *match, void *aux)
    135 {
    136 
    137 	/* XXX check version register */
    138 	return 1;
    139 }
    140 
    141 void
    142 sed1356attach(struct device *parent, struct device *self, void *aux)
    143 {
    144 	struct sed1356_softc *sc = (struct sed1356_softc *)self;
    145 	struct hpcfb_attach_args ha;
    146 
    147 	if (attach_flag) {
    148 		panic("%s(%d): sed1356 attached twice", __FILE__, __LINE__);
    149 	}
    150 	attach_flag = 1;
    151 
    152 	if (sed1356_init(&sc->sc_fbconf) != 0) {
    153 		/* just return so that hpcfb will not be attached */
    154 		return;
    155 	}
    156 
    157 	printf("%s: Epson SED1356", sc->sc_dev.dv_xname);
    158 	if (console_flag) {
    159 		printf(", console");
    160 	}
    161 	printf("\n");
    162 	printf("%s: framebuffer address: 0x%08lx\n",
    163 		sc->sc_dev.dv_xname, (u_long)bootinfo->fb_addr);
    164 
    165 	/* Add a suspend hook to power saving */
    166 	sc->sc_powerstate = 0;
    167 	sc->sc_powerhook = powerhook_establish(sed1356_power, sc);
    168 	if (sc->sc_powerhook == NULL)
    169 		printf("%s: WARNING: unable to establish power hook\n",
    170 			sc->sc_dev.dv_xname);
    171 
    172 	/* initialize backlight brightness and lcd contrast */
    173 	sc->sc_lcd_inited = 0;
    174 	sed1356_init_brightness(sc, 1);
    175 	sed1356_init_contrast(sc, 1);
    176 	sed1356_init_backlight(sc, 1);
    177 
    178 	ha.ha_console = console_flag;
    179 	ha.ha_accessops = &sed1356_ha;
    180 	ha.ha_accessctx = sc;
    181 	ha.ha_curfbconf = 0;
    182 	ha.ha_nfbconf = 1;
    183 	ha.ha_fbconflist = &sc->sc_fbconf;
    184 	ha.ha_curdspconf = 0;
    185 	ha.ha_ndspconf = 1;
    186 	ha.ha_dspconflist = &sc->sc_dspconf;
    187 
    188 	config_found(self, &ha, hpcfbprint);
    189 }
    190 
    191 int
    192 sed1356_getcnfb(struct hpcfb_fbconf *fb)
    193 {
    194 	console_flag = 1;
    195 
    196 	return sed1356_init(fb);
    197 }
    198 
    199 static int
    200 sed1356_init(struct hpcfb_fbconf *fb)
    201 {
    202 	/*
    203 	 * get fb settings from bootinfo
    204 	 */
    205 	if (bootinfo == NULL ||
    206 	    bootinfo->fb_addr == 0 ||
    207 	    bootinfo->fb_line_bytes == 0 ||
    208 	    bootinfo->fb_width == 0 ||
    209 	    bootinfo->fb_height == 0) {
    210 		printf("no frame buffer infomation.\n");
    211 		return (-1);
    212 	}
    213 
    214 	/* zero fill */
    215 	bzero(fb, sizeof(*fb));
    216 
    217 	fb->hf_conf_index	= 0;	/* configuration index		*/
    218 	fb->hf_nconfs		= 1;   	/* how many configurations	*/
    219 	strcpy(fb->hf_name, "built-in video");
    220 					/* frame buffer name		*/
    221 	strcpy(fb->hf_conf_name, "default");
    222 					/* configuration name		*/
    223 	fb->hf_height		= bootinfo->fb_height;
    224 	fb->hf_width		= bootinfo->fb_width;
    225 	if (bus_space_map(&sa11x0_bs_tag, (bus_addr_t)bootinfo->fb_addr,
    226 			   bootinfo->fb_height * bootinfo->fb_line_bytes,
    227 			   0, &fb->hf_baseaddr)) {
    228 		printf("unable to map framebuffer\n");
    229 		return (-1);
    230 	}
    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_D4_M2L_F:
    248 	case BIFB_D4_M2L_Fx2:
    249 		fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
    250 		/* fall through */
    251 	case BIFB_D4_M2L_0:
    252 	case BIFB_D4_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 = 2;
    257 		fb->hf_pixel_width = 4;
    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 		/*
    263 		 * indexed color
    264 		 */
    265 	case BIFB_D8_FF:
    266 		fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
    267 		/* fall through */
    268 	case BIFB_D8_00:
    269 		fb->hf_class = HPCFB_CLASS_INDEXCOLOR;
    270 		fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
    271 		fb->hf_pack_width = 8;
    272 		fb->hf_pixels_per_pack = 1;
    273 		fb->hf_pixel_width = 8;
    274 		fb->hf_class_data_length = sizeof(struct hf_indexed_tag);
    275 		fb->hf_u.hf_indexed.hf_flags = 0; /* reserved for future use */
    276 		break;
    277 
    278 		/*
    279 		 * RGB color
    280 		 */
    281 	case BIFB_D16_FFFF:
    282 		fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
    283 		/* fall through */
    284 	case BIFB_D16_0000:
    285 		fb->hf_class = HPCFB_CLASS_RGBCOLOR;
    286 		fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
    287 #if BYTE_ORDER == BIG_ENDIAN
    288 		fb->hf_swap_flags = HPCFB_SWAP_BYTE;
    289 #endif
    290 		fb->hf_pack_width = 16;
    291 		fb->hf_pixels_per_pack = 1;
    292 		fb->hf_pixel_width = 16;
    293 
    294 		fb->hf_class_data_length = sizeof(struct hf_rgb_tag);
    295 		fb->hf_u.hf_rgb.hf_flags = 0;	/* reserved for future use */
    296 
    297 		fb->hf_u.hf_rgb.hf_red_width = 5;
    298 		fb->hf_u.hf_rgb.hf_red_shift = 11;
    299 		fb->hf_u.hf_rgb.hf_green_width = 6;
    300 		fb->hf_u.hf_rgb.hf_green_shift = 5;
    301 		fb->hf_u.hf_rgb.hf_blue_width = 5;
    302 		fb->hf_u.hf_rgb.hf_blue_shift = 0;
    303 		fb->hf_u.hf_rgb.hf_alpha_width = 0;
    304 		fb->hf_u.hf_rgb.hf_alpha_shift = 0;
    305 		break;
    306 
    307 	default:
    308 		printf("unsupported type %d.\n", bootinfo->fb_type);
    309 		return (-1);
    310 		break;
    311 	}
    312 
    313 	return (0); /* no error */
    314 }
    315 
    316 static void
    317 sed1356_power(int why, void *arg)
    318 {
    319 	struct sed1356_softc *sc = arg;
    320 
    321 	switch (why) {
    322 	case PWR_SUSPEND:
    323 	case PWR_STANDBY:
    324 		sc->sc_powerstate |= PWRSTAT_SUSPEND;
    325 		sed1356_update_powerstate(sc, PWRSTAT_ALL);
    326 		break;
    327 	case PWR_RESUME:
    328 		sc->sc_powerstate &= ~PWRSTAT_SUSPEND;
    329 		sed1356_update_powerstate(sc, PWRSTAT_ALL);
    330 		break;
    331 	}
    332 }
    333 
    334 static void
    335 sed1356_update_powerstate(struct sed1356_softc *sc, int updates)
    336 {
    337 	if (updates & PWRSTAT_LCD)
    338 		config_hook_call(CONFIG_HOOK_POWERCONTROL,
    339 		    CONFIG_HOOK_POWERCONTROL_LCD,
    340 		    (void*)!(sc->sc_powerstate &
    341 				(PWRSTAT_VIDEOOFF|PWRSTAT_SUSPEND)));
    342 
    343 	if (updates & PWRSTAT_BACKLIGHT)
    344 		config_hook_call(CONFIG_HOOK_POWERCONTROL,
    345 		    CONFIG_HOOK_POWERCONTROL_LCDLIGHT,
    346 		    (void*)(!(sc->sc_powerstate &
    347 				(PWRSTAT_VIDEOOFF|PWRSTAT_SUSPEND)) &&
    348 			     (sc->sc_powerstate & PWRSTAT_BACKLIGHT)));
    349 }
    350 
    351 int
    352 sed1356_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
    353 {
    354 	struct sed1356_softc *sc = (struct sed1356_softc *)v;
    355 	struct hpcfb_fbconf *fbconf;
    356 	struct hpcfb_dspconf *dspconf;
    357 	struct wsdisplay_param *dispparam;
    358 
    359 	switch (cmd) {
    360 	case WSDISPLAYIO_GETCMAP:
    361 	case WSDISPLAYIO_PUTCMAP:
    362 		/*
    363 		 * XXX should be able to handle color map in 4/8 bpp mode.
    364 		 */
    365 		return (EINVAL);
    366 
    367 	case WSDISPLAYIO_SVIDEO:
    368 		if (*(int *)data == WSDISPLAYIO_VIDEO_OFF)
    369 			sc->sc_powerstate |= PWRSTAT_VIDEOOFF;
    370 		else
    371 			sc->sc_powerstate &= ~PWRSTAT_VIDEOOFF;
    372 		sed1356_update_powerstate(sc, PWRSTAT_ALL);
    373 		return 0;
    374 
    375 	case WSDISPLAYIO_GVIDEO:
    376 		*(int *)data = (sc->sc_powerstate&PWRSTAT_VIDEOOFF) ?
    377 				WSDISPLAYIO_VIDEO_OFF:WSDISPLAYIO_VIDEO_ON;
    378 		return 0;
    379 
    380 
    381 	case WSDISPLAYIO_GETPARAM:
    382 		dispparam = (struct wsdisplay_param*)data;
    383 		switch (dispparam->param) {
    384 		case WSDISPLAYIO_PARAM_BACKLIGHT:
    385 			VPRINTF(("sed1356_ioctl: GET:BACKLIGHT\n"));
    386 			sed1356_init_brightness(sc, 0);
    387 			sed1356_init_backlight(sc, 0);
    388 			VPRINTF(("sed1356_ioctl: GET:(real)BACKLIGHT %d\n",
    389 				 (sc->sc_powerstate&PWRSTAT_BACKLIGHT)? 1: 0));
    390 			dispparam->min = 0;
    391 			dispparam->max = 1;
    392 			if (sc->sc_max_brightness > 0)
    393 				dispparam->curval = sc->sc_brightness > 0? 1: 0;
    394 			else
    395 				dispparam->curval =
    396 				    (sc->sc_powerstate&PWRSTAT_BACKLIGHT) ? 1: 0;
    397 			VPRINTF(("sed1356_ioctl: GET:BACKLIGHT:%d(%s)\n",
    398 				dispparam->curval,
    399 				sc->sc_max_brightness > 0? "brightness": "light"));
    400 			return 0;
    401 			break;
    402 		case WSDISPLAYIO_PARAM_CONTRAST:
    403 			VPRINTF(("sed1356_ioctl: GET:CONTRAST\n"));
    404 			sed1356_init_contrast(sc, 0);
    405 			if (sc->sc_max_contrast > 0) {
    406 				dispparam->min = 0;
    407 				dispparam->max = sc->sc_max_contrast;
    408 				dispparam->curval = sc->sc_contrast;
    409 				VPRINTF(("sed1356_ioctl: GET:CONTRAST max=%d, current=%d\n", sc->sc_max_contrast, sc->sc_contrast));
    410 				return 0;
    411 			} else {
    412 				VPRINTF(("sed1356_ioctl: GET:CONTRAST EINVAL\n"));
    413 				return (EINVAL);
    414 			}
    415 			break;
    416 		case WSDISPLAYIO_PARAM_BRIGHTNESS:
    417 			VPRINTF(("sed1356_ioctl: GET:BRIGHTNESS\n"));
    418 			sed1356_init_brightness(sc, 0);
    419 			if (sc->sc_max_brightness > 0) {
    420 				dispparam->min = 0;
    421 				dispparam->max = sc->sc_max_brightness;
    422 				dispparam->curval = sc->sc_brightness;
    423 				VPRINTF(("sed1356_ioctl: GET:BRIGHTNESS max=%d, current=%d\n", sc->sc_max_brightness, sc->sc_brightness));
    424 				return 0;
    425 			} else {
    426 				VPRINTF(("sed1356_ioctl: GET:BRIGHTNESS EINVAL\n"));
    427 				return (EINVAL);
    428 			}
    429 			return (EINVAL);
    430 		default:
    431 			return (EINVAL);
    432 		}
    433 		return (0);
    434 
    435 	case WSDISPLAYIO_SETPARAM:
    436 		dispparam = (struct wsdisplay_param*)data;
    437 		switch (dispparam->param) {
    438 		case WSDISPLAYIO_PARAM_BACKLIGHT:
    439 			VPRINTF(("sed1356_ioctl: SET:BACKLIGHT\n"));
    440 			if (dispparam->curval < 0 ||
    441 			    1 < dispparam->curval)
    442 				return (EINVAL);
    443 			sed1356_init_brightness(sc, 0);
    444 			VPRINTF(("sed1356_ioctl: SET:max brightness=%d\n", sc->sc_max_brightness));
    445 			if (sc->sc_max_brightness > 0) { /* dimmer */
    446 				if (dispparam->curval == 0){
    447 					sc->sc_brightness_save = sc->sc_brightness;
    448 					sed1356_set_brightness(sc, 0);	/* min */
    449 				} else {
    450 					if (sc->sc_brightness_save == 0)
    451 						sc->sc_brightness_save = sc->sc_max_brightness;
    452 					sed1356_set_brightness(sc, sc->sc_brightness_save);
    453 				}
    454 				VPRINTF(("sed1356_ioctl: SET:BACKLIGHT:brightness=%d\n", sc->sc_brightness));
    455 			} else { /* off */
    456 				if (dispparam->curval == 0)
    457 					sc->sc_powerstate &= ~PWRSTAT_BACKLIGHT;
    458 				else
    459 					sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
    460 				VPRINTF(("sed1356_ioctl: SET:BACKLIGHT:powerstate %d\n",
    461 						(sc->sc_powerstate & PWRSTAT_BACKLIGHT)?1:0));
    462 				sed1356_update_powerstate(sc, PWRSTAT_BACKLIGHT);
    463 				VPRINTF(("sed1356_ioctl: SET:BACKLIGHT:%d\n",
    464 					(sc->sc_powerstate & PWRSTAT_BACKLIGHT)?1:0));
    465 			}
    466 			return 0;
    467 			break;
    468 		case WSDISPLAYIO_PARAM_CONTRAST:
    469 			VPRINTF(("sed1356_ioctl: SET:CONTRAST\n"));
    470 			sed1356_init_contrast(sc, 0);
    471 			if (dispparam->curval < 0 ||
    472 			    sc->sc_max_contrast < dispparam->curval)
    473 				return (EINVAL);
    474 			if (sc->sc_max_contrast > 0) {
    475 				int org = sc->sc_contrast;
    476 				sed1356_set_contrast(sc, dispparam->curval);
    477 				VPRINTF(("sed1356_ioctl: SET:CONTRAST org=%d, current=%d\n", org, sc->sc_contrast));
    478 				return 0;
    479 			} else {
    480 				VPRINTF(("sed1356_ioctl: SET:CONTRAST EINVAL\n"));
    481 				return (EINVAL);
    482 			}
    483 			break;
    484 		case WSDISPLAYIO_PARAM_BRIGHTNESS:
    485 			VPRINTF(("sed1356_ioctl: SET:BRIGHTNESS\n"));
    486 			sed1356_init_brightness(sc, 0);
    487 			if (dispparam->curval < 0 ||
    488 			    sc->sc_max_brightness < dispparam->curval)
    489 				return (EINVAL);
    490 			if (sc->sc_max_brightness > 0) {
    491 				int org = sc->sc_brightness;
    492 				sed1356_set_brightness(sc, dispparam->curval);
    493 				VPRINTF(("sed1356_ioctl: SET:BRIGHTNESS org=%d, current=%d\n", org, sc->sc_brightness));
    494 				return 0;
    495 			} else {
    496 				VPRINTF(("sed1356_ioctl: SET:BRIGHTNESS EINVAL\n"));
    497 				return (EINVAL);
    498 			}
    499 			break;
    500 		default:
    501 			return (EINVAL);
    502 		}
    503 		return (0);
    504 
    505 	case HPCFBIO_GCONF:
    506 		fbconf = (struct hpcfb_fbconf *)data;
    507 		if (fbconf->hf_conf_index != 0 &&
    508 		    fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
    509 			return (EINVAL);
    510 		}
    511 		*fbconf = sc->sc_fbconf;	/* structure assignment */
    512 		return (0);
    513 	case HPCFBIO_SCONF:
    514 		fbconf = (struct hpcfb_fbconf *)data;
    515 		if (fbconf->hf_conf_index != 0 &&
    516 		    fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
    517 			return (EINVAL);
    518 		}
    519 		/*
    520 		 * nothing to do because we have only one configration
    521 		 */
    522 		return (0);
    523 	case HPCFBIO_GDSPCONF:
    524 		dspconf = (struct hpcfb_dspconf *)data;
    525 		if ((dspconf->hd_unit_index != 0 &&
    526 		     dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
    527 		    (dspconf->hd_conf_index != 0 &&
    528 		     dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
    529 			return (EINVAL);
    530 		}
    531 		*dspconf = sc->sc_dspconf;	/* structure assignment */
    532 		return (0);
    533 	case HPCFBIO_SDSPCONF:
    534 		dspconf = (struct hpcfb_dspconf *)data;
    535 		if ((dspconf->hd_unit_index != 0 &&
    536 		     dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
    537 		    (dspconf->hd_conf_index != 0 &&
    538 		     dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
    539 			return (EINVAL);
    540 		}
    541 		/*
    542 		 * nothing to do
    543 		 * because we have only one unit and one configration
    544 		 */
    545 		return (0);
    546 	case HPCFBIO_GOP:
    547 	case HPCFBIO_SOP:
    548 		/*
    549 		 * curently not implemented...
    550 		 */
    551 		return (EINVAL);
    552 	}
    553 
    554 	return (ENOTTY);
    555 }
    556 
    557 paddr_t
    558 sed1356_mmap(void *ctx, off_t offset, int prot)
    559 {
    560 	struct sed1356_softc *sc = (struct sed1356_softc *)ctx;
    561 
    562 	if (offset < 0 ||
    563 	    (sc->sc_fbconf.hf_bytes_per_plane +
    564 		sc->sc_fbconf.hf_offset) <  offset)
    565 		return -1;
    566 
    567 	return __BTOP((u_long)bootinfo->fb_addr + offset);
    568 }
    569 
    570 
    571 void
    572 sed1356_init_backlight(struct sed1356_softc *sc, int inattach)
    573 {
    574 	int val = -1;
    575 
    576 	if (sc->sc_lcd_inited&BACKLIGHT_INITED)
    577 		return;
    578 
    579 	if (config_hook_call(CONFIG_HOOK_GET,
    580 	     CONFIG_HOOK_POWER_LCDLIGHT, &val) != -1) {
    581 		/* we can get real light state */
    582 		VPRINTF(("sed1356_init_backlight: real backlight=%d\n", val));
    583 		if (val == 0)
    584 			sc->sc_powerstate &= ~PWRSTAT_BACKLIGHT;
    585 		else
    586 			sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
    587 		sc->sc_lcd_inited |= BACKLIGHT_INITED;
    588 	} else if (inattach) {
    589 		/*
    590 		   we cannot get real light state in attach time
    591 		   because light device not yet attached.
    592 		   we will retry in !inattach.
    593 		   temporary assume light is on.
    594 		 */
    595 		sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
    596 	} else {
    597 		/* we cannot get real light state, so work by myself state */
    598 		sc->sc_lcd_inited |= BACKLIGHT_INITED;
    599 	}
    600 }
    601 
    602 void
    603 sed1356_init_brightness(struct sed1356_softc *sc, int inattach)
    604 {
    605 	int val = -1;
    606 
    607 	if (sc->sc_lcd_inited&BRIGHTNESS_INITED)
    608 		return;
    609 
    610 	VPRINTF(("sed1356_init_brightness\n"));
    611 	if (config_hook_call(CONFIG_HOOK_GET,
    612 	     CONFIG_HOOK_BRIGHTNESS_MAX, &val) != -1) {
    613 		/* we can get real brightness max */
    614 		VPRINTF(("sed1356_init_brightness: real brightness max=%d\n", val));
    615 		sc->sc_max_brightness = val;
    616 		val = -1;
    617 		if (config_hook_call(CONFIG_HOOK_GET,
    618 		     CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
    619 			/* we can get real brightness */
    620 			VPRINTF(("sed1356_init_brightness: real brightness=%d\n", val));
    621 			sc->sc_brightness_save = sc->sc_brightness = val;
    622 		} else {
    623 			sc->sc_brightness_save =
    624 			sc->sc_brightness = sc->sc_max_brightness;
    625 		}
    626 		sc->sc_lcd_inited |= BRIGHTNESS_INITED;
    627 	} else if (inattach) {
    628 		/*
    629 		   we cannot get real brightness in attach time
    630 		   because brightness device not yet attached.
    631 		   we will retry in !inattach.
    632 		 */
    633 		sc->sc_max_brightness = -1;
    634 		sc->sc_brightness = -1;
    635 		sc->sc_brightness_save = -1;
    636 	} else {
    637 		/* we cannot get real brightness */
    638 		sc->sc_lcd_inited |= BRIGHTNESS_INITED;
    639 	}
    640 
    641 	return;
    642 }
    643 
    644 void
    645 sed1356_init_contrast(struct sed1356_softc *sc, int inattach)
    646 {
    647 	int val = -1;
    648 
    649 	if (sc->sc_lcd_inited&CONTRAST_INITED)
    650 		return;
    651 
    652 	VPRINTF(("sed1356_init_contrast\n"));
    653 	if (config_hook_call(CONFIG_HOOK_GET,
    654 	     CONFIG_HOOK_CONTRAST_MAX, &val) != -1) {
    655 		/* we can get real contrast max */
    656 		VPRINTF(("sed1356_init_contrast: real contrast max=%d\n", val));
    657 		sc->sc_max_contrast = val;
    658 		val = -1;
    659 		if (config_hook_call(CONFIG_HOOK_GET,
    660 		     CONFIG_HOOK_CONTRAST, &val) != -1) {
    661 			/* we can get real contrast */
    662 			VPRINTF(("sed1356_init_contrast: real contrast=%d\n", val));
    663 			sc->sc_contrast = val;
    664 		} else {
    665 			sc->sc_contrast = sc->sc_max_contrast;
    666 		}
    667 		sc->sc_lcd_inited |= CONTRAST_INITED;
    668 	} else if (inattach) {
    669 		/*
    670 		   we cannot get real contrast in attach time
    671 		   because contrast device not yet attached.
    672 		   we will retry in !inattach.
    673 		 */
    674 		sc->sc_max_contrast = -1;
    675 		sc->sc_contrast = -1;
    676 	} else {
    677 		/* we cannot get real contrast */
    678 		sc->sc_lcd_inited |= CONTRAST_INITED;
    679 	}
    680 
    681 	return;
    682 }
    683 
    684 void
    685 sed1356_set_brightness(struct sed1356_softc *sc, int val)
    686 {
    687 	sc->sc_brightness = val;
    688 
    689 	config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
    690 	if (config_hook_call(CONFIG_HOOK_GET,
    691 	     CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
    692 		sc->sc_brightness = val;
    693 	}
    694 }
    695 
    696 void
    697 sed1356_set_contrast(struct sed1356_softc *sc, int val)
    698 {
    699 	sc->sc_contrast = val;
    700 
    701 	config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST, &val);
    702 	if (config_hook_call(CONFIG_HOOK_GET,
    703 	     CONFIG_HOOK_CONTRAST, &val) != -1) {
    704 		sc->sc_contrast = val;
    705 	}
    706 }
    707