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