/* $NetBSD: psh3lcd.c,v 1.8 2021/10/24 20:00:11 andvar Exp $ */
/*
* Copyright (c) 2005 KIYOHARA Takashi
* 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 ``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 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.
*
*/
/*
* LCD contrast INC#: controlled by pin 0 in HD64461 GPIO port A.
* LCD contrast CS#: controlled by pin 1 in HD64461 GPIO port A.
* LCD contrast U/D#: controlled by pin 0 in SH7709 GPIO port D.
* 0 - down
* 1 - up
*/
#define PSH3LCD_CONTRAST_INC 0x01
#define PSH3LCD_CONTRAST_CS 0x02
#define PSH3LCD_CONTRAST_UD 0x01
/*
* LCD brightness: controlled by HG71C105FE at AREA2.
* XXXX: That is custom IC. We don't know spec. X-<
*/
#define PSH3LCD_BRIGHTNESS_REG0 0xaa000072
#define PSH3LCD_BRIGHTNESS_REG1 0xaa000150
#define PSH3LCD_BRIGHTNESS_REG2 0xaa000152
/* XXX: TODO: don't rely on CONFIG_HOOK_POWERCONTROL_LCD */
if (!pmf_device_register(self, NULL, NULL))
aprint_error_dev(self, "unable to establish power handler\n");
}
static int
psh3lcd_param(void *ctx, int type, long id, void *msg)
{
struct psh3lcd_softc *sc = ctx;
int value;
switch (type) {
case CONFIG_HOOK_GET:
switch (id) {
case CONFIG_HOOK_CONTRAST:
*(int *)msg = PSH3LCD_CONTRAST;
return 0;
case CONFIG_HOOK_CONTRAST_MAX:
*(int *)msg = PSH3LCD_CONTRAST_MAX;
return 0;
case CONFIG_HOOK_BRIGHTNESS:
*(int *)msg = sc->sc_brightness;
return 0;
case CONFIG_HOOK_BRIGHTNESS_MAX:
*(int *)msg = sc->sc_brightness_max;
return 0;
}
break;
case CONFIG_HOOK_SET:
value = *(int *)msg;
switch (id) {
case CONFIG_HOOK_CONTRAST:
if (value != PSH3LCD_CONTRAST_UP &&
value != PSH3LCD_CONTRAST_DOWN)
return EINVAL;
psh3lcd_set_contrast(value);
return 0;
case CONFIG_HOOK_BRIGHTNESS:
if (value < 0)
value = 0;
if (value > sc->sc_brightness_max)
value = sc->sc_brightness_max;
sc->sc_brightness = value;
sc->sc_set_brightness(sc->sc_brightness);
return 0;
}
break;
}
return EINVAL;
}
static int
psh3lcd_power(void *ctx, int type, long id, void *msg)
{
struct psh3lcd_softc *sc = ctx;
int on;
if (type != CONFIG_HOOK_POWERCONTROL ||
id != CONFIG_HOOK_POWERCONTROL_LCD)
return EINVAL;
on = (int)msg;
if (on)
sc->sc_set_brightness(sc->sc_brightness);
else
sc->sc_set_brightness(sc->sc_brightness_max + 1);