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