/*-
* Copyright (c) 2000,2001 SATO Kazumi
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#define ITE8181DEBUG
#ifdef ITE8181DEBUG
#ifndef ITE8181DEBUG_CONF
#define ITE8181DEBUG_CONF 0
#endif
int ite8181_debug = ITE8181DEBUG_CONF;
#define DPRINTF(arg) if (ite8181_debug) printf arg
#define DPRINTFN(n, arg) if (ite8181_debug > (n)) printf arg
#define VPRINTF(arg) if (bootverbose || ite8181_debug) printf arg
#define VPRINTFN(n, arg) if (bootverbose || ite8181_debug > (n)) printf arg
#else
#define DPRINTF(arg)
#define DPRINTFN(n, arg)
#define VPRINTF(arg) if (bootverbose) printf arg
#define VPRINTFN(n, arg) if (bootverbose) printf arg
#endif
#ifndef ITE8181_LCD_CONTROL_ENABLE
int ite8181_lcd_control_disable = 1;
#else /* ITE8181_LCD_CONTROL_ENABLE */
int ite8181_lcd_control_disable = 0;
#endif /* ITE8181_LCD_CONTROL_ENABLE */
#define ITE8181_WINCE_CMAP
/*
* XXX:
* IBM WorkPad z50 power unit has too weak power.
* So we must wait too many times to access some device
* after LCD panel and BackLight on.
* Currently delay is not enough ??? FIXME
*/
#ifndef ITE8181_LCD_ON_SELF_DELAY
#define ITE8181_LCD_ON_SELF_DELAY 1000
#endif /* ITE8181_LCD_ON__SELF_DELAY */
#ifndef ITE8181_LCD_ON_DELAY
#define ITE8181_LCD_ON_DELAY 2000
#endif /* ITE8181_LCD_ON_DELAY */
int ite8181_lcd_on_self_delay = ITE8181_LCD_ON_SELF_DELAY; /* msec */
int ite8181_lcd_on_delay = ITE8181_LCD_ON_DELAY; /* msec */
printf(": ");
if (ite8181_fbinit(&sc->sc_fbconf) != 0) {
/* just return so that hpcfb will not be attached */
return;
}
regval = ite8181_config_read_4(sc->sc_iot, sc->sc_ioh, ITE8181_CLASS);
printf("ITE8181 Rev.%02lx", regval & ITE8181_REV_MASK);
if (console) {
printf(", console");
}
printf("\n");
printf("%s: framebuffer address: 0x%08lx\n",
device_xname(sc->sc_dev), (u_long)bootinfo->fb_addr);
if (ite8181_lcd_control_disable)
printf("%s: ite8181 lcd control is DISABLED.\n",
device_xname(sc->sc_dev));
/* set base offsets */
sc->sc_mba = ite8181_config_read_4(sc->sc_iot, sc->sc_ioh, ITE8181_MBA);
DPRINTFN(1, ("ite8181: Memory base offset %08x\n", sc->sc_mba));
sc->sc_gba = ite8181_config_read_4(sc->sc_iot, sc->sc_ioh, ITE8181_GBA);
DPRINTFN(1, ("ite8181: GUI base offset %08x\n", sc->sc_gba));
sc->sc_sba = ite8181_config_read_4(sc->sc_iot, sc->sc_ioh, ITE8181_SBA);
DPRINTFN(1, ("ite8181: Graphics base offset %08x\n", sc->sc_sba));
/* assume lcd is on */
sc->sc_lcd = 1;
/* erase wince cursor */
ite8181_erase_cursor(sc);
/* Add a power hook to power saving */
sc->sc_powerhook = powerhook_establish(device_xname(sc->sc_dev),
ite8181_power, sc);
if (sc->sc_powerhook == NULL)
printf("%s: WARNING: unable to establish power hook\n",
device_xname(sc->sc_dev));
/* Add a hard power hook to power saving */
sc->sc_hardpowerhook = config_hook(CONFIG_HOOK_PMEVENT,
CONFIG_HOOK_PMEVENT_HARDPOWER,
CONFIG_HOOK_SHARE,
ite8181_hardpower, sc);
if (sc->sc_hardpowerhook == NULL)
printf("%s: WARNING: unable to establish hard power hook\n",
device_xname(sc->sc_dev));
switch (why) {
case PWR_STANDBY:
sc->sc_powerstate |= PWRSTAT_SUSPEND;
ite8181_update_powerstate(sc, PWRSTAT_ALL);
break;
case PWR_SUSPEND:
sc->sc_powerstate |= PWRSTAT_SUSPEND;
ite8181_update_powerstate(sc, PWRSTAT_ALL);
break;
case PWR_RESUME:
sc->sc_powerstate &= ~PWRSTAT_SUSPEND;
ite8181_update_powerstate(sc, PWRSTAT_ALL);
break;
}
}
static int
ite8181_hardpower(void *ctx, int type, long id, void *msg)
{
struct ite8181_softc *sc = ctx;
int why = (int)msg;
switch (why) {
case PWR_STANDBY:
/* ite8181_lcd_power(sc, 0); */
delay(MSEC);
break;
case PWR_SUSPEND:
ite8181_lcd_power(sc, 0);
delay(MSEC);
break;
case PWR_RESUME:
delay(MSEC);
ite8181_lcd_power(sc, 1);
/*
* XXX:
* IBM WorkPad z50 power unit has too weak power.
* So we must wait too many times to access other devices
* after LCD panel and BackLight on.
*/
delay(ite8181_lcd_on_delay*MSEC);
break;
}
/*
* you should wait until the
* power state transit sequence will end.
*/
return (0);
}
static int
ite8181_fbinit(struct hpcfb_fbconf *fb)
{
void
ite8181_init_backlight(struct ite8181_softc *sc, int inattach)
{
int val = -1;
if (sc->sc_lcd_inited&BACKLIGHT_INITED)
return;
if (config_hook_call(CONFIG_HOOK_GET,
CONFIG_HOOK_POWER_LCDLIGHT, &val) != -1) {
/* we can get real light state */
VPRINTF(("ite8181_init_backlight: real backlight=%d\n", val));
if (val == 0)
sc->sc_powerstate &= ~PWRSTAT_BACKLIGHT;
else
sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
sc->sc_lcd_inited |= BACKLIGHT_INITED;
} else if (inattach) {
/*
we cannot get real light state in attach time
because light device not yet attached.
we will retry in !inattach.
temporary assume light is on.
*/
sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
} else {
/* we cannot get real light state, so work by myself state */
sc->sc_lcd_inited |= BACKLIGHT_INITED;
}
}
void
ite8181_init_brightness(struct ite8181_softc *sc, int inattach)
{
int val = -1;
if (sc->sc_lcd_inited&BRIGHTNESS_INITED)
return;
VPRINTF(("ite8181_init_brightness\n"));
if (config_hook_call(CONFIG_HOOK_GET,
CONFIG_HOOK_BRIGHTNESS_MAX, &val) != -1) {
/* we can get real brightness max */
VPRINTF(("ite8181_init_brightness: real brightness max=%d\n",
val));
sc->sc_max_brightness = val;
val = -1;
if (config_hook_call(CONFIG_HOOK_GET,
CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
/* we can get real brightness */
VPRINTF(("ite8181_init_brightness:"
" real brightness=%d\n", val));
sc->sc_brightness_save = sc->sc_brightness = val;
} else {
sc->sc_brightness_save =
sc->sc_brightness = sc->sc_max_brightness;
}
sc->sc_lcd_inited |= BRIGHTNESS_INITED;
} else if (inattach) {
/*
we cannot get real brightness in attach time
because brightness device not yet attached.
we will retry in !inattach.
*/
sc->sc_max_brightness = -1;
sc->sc_brightness = -1;
sc->sc_brightness_save = -1;
} else {
/* we cannot get real brightness */
sc->sc_lcd_inited |= BRIGHTNESS_INITED;
}
return;
}
void
ite8181_init_contrast(struct ite8181_softc *sc, int inattach)
{
int val = -1;
if (sc->sc_lcd_inited&CONTRAST_INITED)
return;
VPRINTF(("ite8181_init_contrast\n"));
if (config_hook_call(CONFIG_HOOK_GET,
CONFIG_HOOK_CONTRAST_MAX, &val) != -1) {
/* we can get real contrast max */
VPRINTF(("ite8181_init_contrast: real contrast max=%d\n", val));
sc->sc_max_contrast = val;
val = -1;
if (config_hook_call(CONFIG_HOOK_GET,
CONFIG_HOOK_CONTRAST, &val) != -1) {
/* we can get real contrast */
VPRINTF(("ite8181_init_contrast: real contrast=%d\n",
val));
sc->sc_contrast = val;
} else {
sc->sc_contrast = sc->sc_max_contrast;
}
sc->sc_lcd_inited |= CONTRAST_INITED;
} else if (inattach) {
/*
we cannot get real contrast in attach time
because contrast device not yet attached.
we will retry in !inattach.
*/
sc->sc_max_contrast = -1;
sc->sc_contrast = -1;
} else {
/* we cannot get real contrast */
sc->sc_lcd_inited |= CONTRAST_INITED;
}
return;
}
void
ite8181_set_brightness(struct ite8181_softc *sc, int val)
{