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