int j720lcd_power(void *ctx, int type, long id, void *msg) { struct sed1356_softc *sc = ctx; struct sa11x0_softc *psc = sc->sc_parent; uint32_t reg; int val; if (type != CONFIG_HOOK_POWERCONTROL || id != CONFIG_HOOK_POWERCONTROL_LCDLIGHT) return 0; sed1356_init_brightness(sc, 0); sed1356_init_contrast(sc, 0); if (msg) { bus_space_write_1(sc->sc_iot, sc->sc_regh, 0x1f0, 0); reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR); reg |= 0x1; bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg); delay(50000); val = sc->sc_contrast; config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST, &val); delay(100000); reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR); reg |= 0x4; bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg); val = sc->sc_brightness; config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val); reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR); reg |= 0x2; bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg); } else { reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR); reg &= ~0x2; bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg); reg &= ~0x4; bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg); delay(100000); val = -2; config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val); bus_space_write_1(sc->sc_iot, sc->sc_regh, 0x1f0, 1); delay(100000); reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR); reg &= ~0x1; bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg); } return 1; }
static int sed1356_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l) { struct sed1356_softc *sc = (struct sed1356_softc *)v; struct hpcfb_fbconf *fbconf; struct hpcfb_dspconf *dspconf; struct wsdisplay_param *dispparam; switch (cmd) { case WSDISPLAYIO_GETCMAP: case WSDISPLAYIO_PUTCMAP: /* * XXX should be able to handle color map in 4/8 bpp mode. */ return EINVAL; case WSDISPLAYIO_SVIDEO: if (*(int *)data == WSDISPLAYIO_VIDEO_OFF) sc->sc_powerstate |= PWRSTAT_VIDEOOFF; else sc->sc_powerstate &= ~PWRSTAT_VIDEOOFF; sed1356_update_powerstate(sc, PWRSTAT_ALL); return 0; case WSDISPLAYIO_GVIDEO: *(int *)data = (sc->sc_powerstate & PWRSTAT_VIDEOOFF) ? WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON; return 0; case WSDISPLAYIO_GETPARAM: dispparam = (struct wsdisplay_param *)data; switch (dispparam->param) { case WSDISPLAYIO_PARAM_BACKLIGHT: VPRINTF(("sed1356_ioctl: GET:BACKLIGHT\n")); sed1356_init_brightness(sc, 0); sed1356_init_backlight(sc, 0); VPRINTF(("sed1356_ioctl: GET:(real)BACKLIGHT %d\n", (sc->sc_powerstate & PWRSTAT_BACKLIGHT) ? 1: 0)); dispparam->min = 0; dispparam->max = 1; if (sc->sc_max_brightness > 0) dispparam->curval = (sc->sc_brightness > 0) ? 1 : 0; else dispparam->curval = (sc->sc_powerstate & PWRSTAT_BACKLIGHT) ? 1 : 0; VPRINTF(("sed1356_ioctl: GET:BACKLIGHT:%d(%s)\n", dispparam->curval, (sc->sc_max_brightness > 0) ? "brightness": "light")); return 0; case WSDISPLAYIO_PARAM_CONTRAST: VPRINTF(("sed1356_ioctl: GET:CONTRAST\n")); sed1356_init_contrast(sc, 0); if (sc->sc_max_contrast > 0) { dispparam->min = 0; dispparam->max = sc->sc_max_contrast; dispparam->curval = sc->sc_contrast; VPRINTF(("sed1356_ioctl: GET:CONTRAST max=%d," " current=%d\n", sc->sc_max_contrast, sc->sc_contrast)); return 0; } VPRINTF(("sed1356_ioctl: GET:CONTRAST EINVAL\n")); return EINVAL; case WSDISPLAYIO_PARAM_BRIGHTNESS: VPRINTF(("sed1356_ioctl: GET:BRIGHTNESS\n")); sed1356_init_brightness(sc, 0); if (sc->sc_max_brightness > 0) { dispparam->min = 0; dispparam->max = sc->sc_max_brightness; dispparam->curval = sc->sc_brightness; VPRINTF(("sed1356_ioctl: GET:BRIGHTNESS max=%d," " current=%d\n", sc->sc_max_brightness, sc->sc_brightness)); return 0; } VPRINTF(("sed1356_ioctl: GET:BRIGHTNESS EINVAL\n")); return EINVAL; default: return EINVAL; } break; case WSDISPLAYIO_SETPARAM: dispparam = (struct wsdisplay_param*)data; switch (dispparam->param) { case WSDISPLAYIO_PARAM_BACKLIGHT: VPRINTF(("sed1356_ioctl: SET:BACKLIGHT\n")); if (dispparam->curval < 0 || 1 < dispparam->curval) return EINVAL; sed1356_init_brightness(sc, 0); VPRINTF(("sed1356_ioctl: SET:max brightness=%d\n", sc->sc_max_brightness)); if (sc->sc_max_brightness > 0) { /* dimmer */ if (dispparam->curval == 0){ sc->sc_brightness_save = sc->sc_brightness; sed1356_set_brightness(sc, 0); /* min */ } else { if (sc->sc_brightness_save == 0) sc->sc_brightness_save = sc->sc_max_brightness; sed1356_set_brightness(sc, sc->sc_brightness_save); } VPRINTF(("sed1356_ioctl: SET:BACKLIGHT:" "brightness=%d\n", sc->sc_brightness)); } else { /* off */ if (dispparam->curval == 0) sc->sc_powerstate &= ~PWRSTAT_BACKLIGHT; else sc->sc_powerstate |= PWRSTAT_BACKLIGHT; VPRINTF(("sed1356_ioctl: SET:BACKLIGHT:" "powerstate %d\n", (sc->sc_powerstate & PWRSTAT_BACKLIGHT) ? 1 : 0)); sed1356_update_powerstate(sc, PWRSTAT_BACKLIGHT); VPRINTF(("sed1356_ioctl: SET:BACKLIGHT:%d\n", (sc->sc_powerstate & PWRSTAT_BACKLIGHT) ? 1 : 0)); } return 0; case WSDISPLAYIO_PARAM_CONTRAST: VPRINTF(("sed1356_ioctl: SET:CONTRAST\n")); sed1356_init_contrast(sc, 0); if (dispparam->curval < 0 || sc->sc_max_contrast < dispparam->curval) return EINVAL; if (sc->sc_max_contrast > 0) { VPRINTF(("sed1356_ioctl: SET:CONTRAST org=%d", sc->sc_contrast)); sed1356_set_contrast(sc, dispparam->curval); VPRINTF((", current=%d\n", sc->sc_contrast)); return 0; } VPRINTF(("sed1356_ioctl: SET:CONTRAST EINVAL\n")); return EINVAL; case WSDISPLAYIO_PARAM_BRIGHTNESS: VPRINTF(("sed1356_ioctl: SET:BRIGHTNESS\n")); sed1356_init_brightness(sc, 0); if (dispparam->curval < 0 || sc->sc_max_brightness < dispparam->curval) return EINVAL; if (sc->sc_max_brightness > 0) { VPRINTF(("sed1356_ioctl: SET:BRIGHTNESS org=%d", sc->sc_brightness)); sed1356_set_brightness(sc, dispparam->curval); VPRINTF((", current=%d\n", sc->sc_brightness)); return 0; } VPRINTF(("sed1356_ioctl: SET:BRIGHTNESS EINVAL\n")); return EINVAL; default: return EINVAL; } return 0; case HPCFBIO_GCONF: fbconf = (struct hpcfb_fbconf *)data; if (fbconf->hf_conf_index != 0 && fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) { return EINVAL; } *fbconf = sc->sc_fbconf; /* structure assignment */ return 0; case HPCFBIO_SCONF: fbconf = (struct hpcfb_fbconf *)data; if (fbconf->hf_conf_index != 0 && fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) { return EINVAL; } /* * nothing to do because we have only one configuration */ return 0; case HPCFBIO_GDSPCONF: dspconf = (struct hpcfb_dspconf *)data; if ((dspconf->hd_unit_index != 0 && dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) || (dspconf->hd_conf_index != 0 && dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) { return EINVAL; } *dspconf = sc->sc_dspconf; /* structure assignment */ return 0; case HPCFBIO_SDSPCONF: dspconf = (struct hpcfb_dspconf *)data; if ((dspconf->hd_unit_index != 0 && dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) || (dspconf->hd_conf_index != 0 && dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) { return EINVAL; } /* * nothing to do * because we have only one unit and one configuration */ return 0; case HPCFBIO_GOP: case HPCFBIO_SOP: /* * curently not implemented... */ return EINVAL; } return EPASSTHROUGH; }
static void sed1356_attach(struct device *parent, struct device *self, void *aux) { struct sed1356_softc *sc = (struct sed1356_softc *)self; struct hpcfb_attach_args ha; int console = (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) ? 0 : 1; if (attach_flag) { panic("%s(%d): sed1356 attached twice", __FILE__, __LINE__); } attach_flag = 1; if (sed1356_init(&sc->sc_fbconf) != 0) { /* just return so that hpcfb will not be attached */ return; } printf("\n"); sc->sc_iot = &sa11x0_bs_tag; sc->sc_parent = (struct sa11x0_softc *)parent; if (bus_space_map(sc->sc_iot, (bus_addr_t)bootinfo->fb_addr & ~0x3fffff, 0x200, 0, &sc->sc_regh)) { printf("%s: unable to map register\n", sc->sc_dev.dv_xname); return; } printf("%s: Epson SED1356", sc->sc_dev.dv_xname); if (console) { printf(", console"); } printf("\n"); printf("%s: framebuffer address: 0x%08lx\n", sc->sc_dev.dv_xname, (u_long)bootinfo->fb_addr); /* Add a suspend hook to power saving */ sc->sc_powerstate = 0; sc->sc_powerhook = powerhook_establish(self->dv_xname, sed1356_power, sc); if (sc->sc_powerhook == NULL) printf("%s: WARNING: unable to establish power hook\n", sc->sc_dev.dv_xname); /* Initialize backlight brightness and lcd contrast */ sc->sc_lcd_inited = 0; sed1356_init_brightness(sc, 1); sed1356_init_contrast(sc, 1); sed1356_init_backlight(sc, 1); if (console && hpcfb_cnattach(&sc->sc_fbconf) != 0) panic("sed1356_attach: cannot init fb console"); ha.ha_console = console; ha.ha_accessops = &sed1356_ha; ha.ha_accessctx = sc; ha.ha_curfbconf = 0; ha.ha_nfbconf = 1; ha.ha_fbconflist = &sc->sc_fbconf; ha.ha_curdspconf = 0; ha.ha_ndspconf = 1; ha.ha_dspconflist = &sc->sc_dspconf; /* XXX */ if (platid_match(&platid, &platid_mask_MACH_HP_JORNADA_7XX)) { config_hook(CONFIG_HOOK_POWERCONTROL, CONFIG_HOOK_POWERCONTROL_LCDLIGHT, CONFIG_HOOK_SHARE, j720lcd_power, sc); } config_found(self, &ha, hpcfbprint); }