summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorsato <sato@NetBSD.org>2001-02-27 08:54:17 +0000
committersato <sato@NetBSD.org>2001-02-27 08:54:17 +0000
commitb8e5bc569c1e0e2c4e3d29ee8d84ba5c9ec6bfd2 (patch)
treedb833804aae6a71523de6db25a118d4e0387d77b /sys
parent269197a9566cf671169ecec30a18f3277f51a851 (diff)
* add WSDISPLAYIO_PARAM_BACKLIGHT, WSDISPLAYIO_PARAM_CONTRAST,
WSDISPLAYIO_PARAM_BRIGHTNESS supports.
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/hpcmips/dev/ite8181.c258
-rw-r--r--sys/arch/hpcmips/dev/ite8181var.h16
-rw-r--r--sys/arch/hpcmips/dev/mq200.c266
-rw-r--r--sys/arch/hpcmips/dev/mq200var.h12
-rw-r--r--sys/dev/hpc/bivideo.c210
5 files changed, 708 insertions, 54 deletions
diff --git a/sys/arch/hpcmips/dev/ite8181.c b/sys/arch/hpcmips/dev/ite8181.c
index c73d5cee3e6..37344840ff1 100644
--- a/sys/arch/hpcmips/dev/ite8181.c
+++ b/sys/arch/hpcmips/dev/ite8181.c
@@ -1,7 +1,7 @@
-/* $NetBSD: ite8181.c,v 1.7 2001/02/22 18:38:00 uch Exp $ */
+/* $NetBSD: ite8181.c,v 1.8 2001/02/27 08:54:18 sato Exp $ */
/*-
- * Copyright (c) 2000 SATO Kazumi
+ * Copyright (c) 2000,2001 SATO Kazumi
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -120,6 +120,14 @@ static int ite8181_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
static paddr_t ite8181_mmap __P((void *, off_t offset, int));
static void ite8181_erase_cursor __P((struct ite8181_softc *));
static int ite8181_lcd_power __P((struct ite8181_softc *, int));
+
+static void ite8181_update_powerstate __P((struct ite8181_softc *, int));
+void ite8181_get_backlight __P((struct ite8181_softc *));
+void ite8181_init_brightness __P((struct ite8181_softc *));
+void ite8181_init_contrast __P((struct ite8181_softc *));
+void ite8181_set_brightness __P((struct ite8181_softc *, int));
+void ite8181_set_contrast __P((struct ite8181_softc *, int));
+
/*
* static variables
*/
@@ -275,7 +283,6 @@ ite8181_attach(sc)
sc->sc_lcd = 1;
/* Add a power hook to power saving */
- sc->sc_powerstate = ITE8181_POWERSTATE_D0;
sc->sc_powerhook = powerhook_establish(ite8181_power, sc);
if (sc->sc_powerhook == NULL)
printf("%s: WARNING: unable to establish power hook\n",
@@ -292,6 +299,13 @@ ite8181_attach(sc)
ite8181_erase_cursor(sc);
+ /* initialize backlight brightness and lcd contrast */
+ sc->sc_brightness = sc->sc_contrast =
+ sc->sc_max_brightness = sc->sc_max_contrast = -1;
+ ite8181_get_backlight(sc);
+ ite8181_init_brightness(sc);
+ ite8181_init_contrast(sc);
+
if (console && hpcfb_cnattach(&sc->sc_fbconf) != 0) {
panic("ite8181_attach: can't init fb console");
}
@@ -409,6 +423,23 @@ ite8181_erase_cursor(sc)
/* other ? */
}
+static void
+ite8181_update_powerstate(sc, updates)
+ struct ite8181_softc *sc;
+ int updates;
+{
+ if (updates & PWRSTAT_LCD)
+ config_hook_call(CONFIG_HOOK_POWERCONTROL,
+ CONFIG_HOOK_POWERCONTROL_LCD,
+ (void*)!(sc->sc_powerstate & PWRSTAT_SUSPEND));
+
+ if (updates & PWRSTAT_BACKLIGHT)
+ config_hook_call(CONFIG_HOOK_POWERCONTROL,
+ CONFIG_HOOK_POWERCONTROL_LCDLIGHT,
+ (void*)(!(sc->sc_powerstate & PWRSTAT_SUSPEND) &&
+ (sc->sc_powerstate & PWRSTAT_BACKLIGHT)));
+}
+
static void
ite8181_power(why, arg)
int why;
@@ -428,18 +459,21 @@ ite8181_hardpower(ctx, type, id, msg)
switch (why) {
case PWR_STANDBY:
- sc->sc_powerstate = ITE8181_POWERSTATE_D3;
+ sc->sc_powerstate |= PWRSTAT_SUSPEND;
+ ite8181_update_powerstate(sc, PWRSTAT_ALL);
/* ite8181_lcd_power(sc, 0); */
delay(MSEC);
break;
case PWR_SUSPEND:
- sc->sc_powerstate = ITE8181_POWERSTATE_D2;
+ sc->sc_powerstate |= PWRSTAT_SUSPEND;
+ ite8181_update_powerstate(sc, PWRSTAT_ALL);
ite8181_lcd_power(sc, 0);
delay(MSEC);
break;
case PWR_RESUME:
+ sc->sc_powerstate &= ~PWRSTAT_SUSPEND;
+ ite8181_update_powerstate(sc, PWRSTAT_ALL);
delay(MSEC);
- sc->sc_powerstate = ITE8181_POWERSTATE_D0;
ite8181_lcd_power(sc, 1);
/*
* XXX:
@@ -459,7 +493,6 @@ ite8181_hardpower(ctx, type, id, msg)
return (0);
}
-
static int
ite8181_fbinit(fb)
struct hpcfb_fbconf *fb;
@@ -601,6 +634,7 @@ ite8181_ioctl(v, cmd, data, flag, p)
struct hpcfb_fbconf *fbconf;
struct hpcfb_dspconf *dspconf;
struct wsdisplay_cmap *cmap;
+ struct wsdisplay_param *dispparam;
switch (cmd) {
case WSDISPLAYIO_GETCMAP:
@@ -632,6 +666,134 @@ ite8181_ioctl(v, cmd, data, flag, p)
*/
return (EINVAL);
+
+ case WSDISPLAYIO_GETPARAM:
+ dispparam = (struct wsdisplay_param*)data;
+ switch (dispparam->param) {
+ case WSDISPLAYIO_PARAM_BACKLIGHT:
+ VPRINTF(("ite8181_ioctl: GETPARAM:BACKLIGHT call\n"));
+ if (sc->sc_max_brightness == -1)
+ ite8181_init_brightness(sc);
+ ite8181_get_backlight(sc);
+ 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(("ite8181_ioctl: GETPARAM:BACKLIGHT:%d\n",
+ dispparam->curval));
+ return 0;
+ break;
+ case WSDISPLAYIO_PARAM_CONTRAST:
+ VPRINTF(("ite8181_ioctl: GETPARAM:CONTRAST call\n"));
+ if (sc->sc_max_contrast == -1)
+ ite8181_init_contrast(sc);
+ if (sc->sc_max_contrast > 0) {
+ dispparam->min = 0;
+ dispparam->max = sc->sc_max_contrast;
+ dispparam->curval = sc->sc_contrast;
+ VPRINTF(("ite8181_ioctl: GETPARAM:CONTRAST max=%d, current=%d\n", sc->sc_max_contrast, sc->sc_contrast));
+ return 0;
+ } else {
+ VPRINTF(("ite8181_ioctl: GETPARAM:CONTRAST ret\n"));
+ return (EINVAL);
+ }
+ break;
+ case WSDISPLAYIO_PARAM_BRIGHTNESS:
+ VPRINTF(("ite8181_ioctl: GETPARAM:BRIGHTNESS call\n"));
+ if (sc->sc_max_brightness == -1)
+ ite8181_init_brightness(sc);
+ if (sc->sc_max_brightness > 0) {
+ dispparam->min = 0;
+ dispparam->max = sc->sc_max_brightness;
+ dispparam->curval = sc->sc_brightness;
+ VPRINTF(("ite8181_ioctl: GETPARAM:BRIGHTNESS max=%d, current=%d\n", sc->sc_max_brightness, sc->sc_brightness));
+ return 0;
+ } else {
+ VPRINTF(("ite8181_ioctl: GETPARAM:BRIGHTNESS ret\n"));
+ return (EINVAL);
+ }
+ return (EINVAL);
+ default:
+ return (EINVAL);
+ }
+ return (0);
+
+ case WSDISPLAYIO_SETPARAM:
+ dispparam = (struct wsdisplay_param*)data;
+ switch (dispparam->param) {
+ case WSDISPLAYIO_PARAM_BACKLIGHT:
+ VPRINTF(("ite8181_ioctl: SETPARAM:BACKLIGHT call\n"));
+ if (dispparam->curval < 0 ||
+ 1 < dispparam->curval)
+ return (EINVAL);
+ if (sc->sc_max_brightness == -1)
+ ite8181_init_brightness(sc);
+ VPRINTF(("ite8181_ioctl: SETPARAM: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;
+ ite8181_set_brightness(sc, 0); /* min */
+ } else {
+ if (sc->sc_brightness_save == 0)
+ sc->sc_brightness_save = sc->sc_max_brightness;
+ ite8181_set_brightness(sc, sc->sc_brightness_save);
+ }
+ VPRINTF(("ite8181_ioctl: SETPARAM: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(("ite8181_ioctl: SETPARAM:BACKLIGHT: powerstate %d\n",
+ (sc->sc_powerstate & PWRSTAT_BACKLIGHT)?1:0));
+ ite8181_update_powerstate(sc, PWRSTAT_BACKLIGHT);
+ VPRINTF(("ite8181_ioctl: SETPARAM:BACKLIGHT:%d\n",
+ (sc->sc_powerstate & PWRSTAT_BACKLIGHT)?1:0));
+ }
+ return 0;
+ break;
+ case WSDISPLAYIO_PARAM_CONTRAST:
+ VPRINTF(("ite8181_ioctl: SETPARAM:CONTRAST call\n"));
+ if (sc->sc_max_contrast == -1)
+ ite8181_init_contrast(sc);
+ if (dispparam->curval < 0 ||
+ sc->sc_max_contrast < dispparam->curval)
+ return (EINVAL);
+ if (sc->sc_max_contrast > 0) {
+ int org = sc->sc_contrast;
+ ite8181_set_contrast(sc, dispparam->curval);
+ VPRINTF(("ite8181_ioctl: SETPARAM:CONTRAST org=%d, current=%d\n", org, sc->sc_contrast));
+ return 0;
+ } else {
+ VPRINTF(("ite8181_ioctl: SETPARAM:CONTRAST ret\n"));
+ return (EINVAL);
+ }
+ break;
+ case WSDISPLAYIO_PARAM_BRIGHTNESS:
+ VPRINTF(("ite8181_ioctl: SETPARAM:BRIGHTNESS call\n"));
+ if (sc->sc_max_brightness == -1)
+ ite8181_init_brightness(sc);
+ if (dispparam->curval < 0 ||
+ sc->sc_max_brightness < dispparam->curval)
+ return (EINVAL);
+ if (sc->sc_max_brightness > 0) {
+ int org = sc->sc_brightness;
+ ite8181_set_brightness(sc, dispparam->curval);
+ VPRINTF(("ite8181_ioctl: SETPARAM:BRIGHTNESS org=%d, current=%d\n", org, sc->sc_brightness));
+ return 0;
+ } else {
+ VPRINTF(("ite8181_ioctl: SETPARAM:BRIGHTNESS ret\n"));
+ return (EINVAL);
+ }
+ break;
+ default:
+ return (EINVAL);
+ }
+ return (0);
+
case HPCFBIO_GCONF:
fbconf = (struct hpcfb_fbconf *)data;
if (fbconf->hf_conf_index != 0 &&
@@ -699,3 +861,85 @@ ite8181_mmap(ctx, offset, prot)
return mips_btop((u_long)bootinfo->fb_addr + offset);
}
+
+void
+ite8181_get_backlight(sc)
+ struct ite8181_softc *sc;
+{
+ int val = -1;
+
+ if (sc->sc_max_brightness < 0) {
+ if (config_hook_call(CONFIG_HOOK_GET,
+ CONFIG_HOOK_POWER_LCDLIGHT, &val) != -1) {
+ if (val == 0)
+ sc->sc_powerstate &= ~PWRSTAT_BACKLIGHT;
+ else
+ sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
+ }
+ }
+}
+
+void
+ite8181_init_brightness(sc)
+ struct ite8181_softc *sc;
+{
+ int val = -1;
+
+ if (config_hook_call(CONFIG_HOOK_GET,
+ CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
+ sc->sc_brightness = val;
+ }
+ val = -1;
+ if (config_hook_call(CONFIG_HOOK_GET,
+ CONFIG_HOOK_BRIGHTNESS_MAX, &val) != -1) {
+ sc->sc_brightness_save = sc->sc_max_brightness = val;
+ }
+ return;
+}
+
+
+void
+ite8181_init_contrast(sc)
+ struct ite8181_softc *sc;
+{
+ int val = -1;
+
+ if (config_hook_call(CONFIG_HOOK_GET,
+ CONFIG_HOOK_CONTRAST, &val) != -1) {
+ sc->sc_contrast = val;
+ }
+ val = -1;
+ if (config_hook_call(CONFIG_HOOK_GET,
+ CONFIG_HOOK_CONTRAST_MAX, &val) != -1) {
+ sc->sc_max_contrast = val;
+ }
+ return;
+}
+
+void
+ite8181_set_brightness(sc, val)
+ struct ite8181_softc *sc;
+ int val;
+{
+ sc->sc_brightness = val;
+
+ config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
+ if (config_hook_call(CONFIG_HOOK_GET,
+ CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
+ sc->sc_brightness = val;
+ }
+}
+
+void
+ite8181_set_contrast(sc, val)
+ struct ite8181_softc *sc;
+ int val;
+{
+ sc->sc_contrast = val;
+
+ config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST, &val);
+ if (config_hook_call(CONFIG_HOOK_GET,
+ CONFIG_HOOK_CONTRAST, &val) != -1) {
+ sc->sc_contrast = val;
+ }
+}
diff --git a/sys/arch/hpcmips/dev/ite8181var.h b/sys/arch/hpcmips/dev/ite8181var.h
index 0fa5f262482..5e80f82a0b7 100644
--- a/sys/arch/hpcmips/dev/ite8181var.h
+++ b/sys/arch/hpcmips/dev/ite8181var.h
@@ -1,4 +1,4 @@
-/* $NetBSD: ite8181var.h,v 1.2 2001/02/22 18:38:00 uch Exp $ */
+/* $NetBSD: ite8181var.h,v 1.3 2001/02/27 08:54:18 sato Exp $ */
/*-
* Copyright (c) 2000 SATO Kazumi
@@ -47,10 +47,16 @@ struct ite8181_softc {
void *sc_powerhook; /* power management hook */
config_hook_tag sc_hardpowerhook;
int sc_powerstate;
-#define ITE8181_POWERSTATE_D0 0
-#define ITE8181_POWERSTATE_D1 1
-#define ITE8181_POWERSTATE_D2 2
-#define ITE8181_POWERSTATE_D3 3
+#define PWRSTAT_SUSPEND (1<<0)
+#define PWRSTAT_LCD (1<<1)
+#define PWRSTAT_BACKLIGHT (1<<2)
+#define PWRSTAT_ALL (0xffffffff)
+ int sc_brightness;
+ int sc_brightness_save;
+ int sc_max_brightness;
+ int sc_contrast;
+ int sc_max_contrast;
+
struct hpcfb_fbconf sc_fbconf;
struct hpcfb_dspconf sc_dspconf;
int sc_lcd; /* lcd on/off */
diff --git a/sys/arch/hpcmips/dev/mq200.c b/sys/arch/hpcmips/dev/mq200.c
index c1f04b06cbc..c62ff480b83 100644
--- a/sys/arch/hpcmips/dev/mq200.c
+++ b/sys/arch/hpcmips/dev/mq200.c
@@ -1,4 +1,4 @@
-/* $NetBSD: mq200.c,v 1.9 2001/02/22 18:38:00 uch Exp $ */
+/* $NetBSD: mq200.c,v 1.10 2001/02/27 08:54:18 sato Exp $ */
/*-
* Copyright (c) 2000 Takemura Shin
@@ -78,6 +78,12 @@ static int mq200_hardpower __P((void *, int, long, void *));
static int mq200_fbinit __P((struct hpcfb_fbconf *));
static int mq200_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
static paddr_t mq200_mmap __P((void *, off_t offset, int));
+static void mq200_update_powerstate __P((struct mq200_softc *, int));
+void mq200_get_backlight __P((struct mq200_softc *));
+void mq200_init_brightness __P((struct mq200_softc *));
+void mq200_init_contrast __P((struct mq200_softc *));
+void mq200_set_brightness __P((struct mq200_softc *, int));
+void mq200_set_contrast __P((struct mq200_softc *, int));
/*
* static variables
@@ -137,7 +143,7 @@ mq200_attach(sc)
sc->sc_dev.dv_xname, (u_long)bootinfo->fb_addr);
/* Add a power hook to power saving */
- sc->sc_powerstate = MQ200_POWERSTATE_D0;
+ sc->sc_mq200pwstate = MQ200_POWERSTATE_D0;
sc->sc_powerhook = powerhook_establish(mq200_power, sc);
if (sc->sc_powerhook == NULL)
printf("%s: WARNING: unable to establish power hook\n",
@@ -152,6 +158,13 @@ mq200_attach(sc)
printf("%s: WARNING: unable to establish hard power hook\n",
sc->sc_dev.dv_xname);
+ /* initialize backlight brightness and lcd contrast */
+ sc->sc_brightness = sc->sc_contrast =
+ sc->sc_max_brightness = sc->sc_max_contrast = -1;
+ mq200_init_brightness(sc);
+ mq200_init_contrast(sc);
+ mq200_get_backlight(sc);
+
if (console && hpcfb_cnattach(&sc->sc_fbconf) != 0) {
panic("mq200_attach: can't init fb console");
}
@@ -176,6 +189,23 @@ mq200_attach(sc)
#endif /* NBIVIDEO > 0 */
}
+static void
+mq200_update_powerstate(sc, updates)
+ struct mq200_softc *sc;
+ int updates;
+{
+ if (updates & PWRSTAT_LCD)
+ config_hook_call(CONFIG_HOOK_POWERCONTROL,
+ CONFIG_HOOK_POWERCONTROL_LCD,
+ (void*)!(sc->sc_powerstate & PWRSTAT_SUSPEND));
+
+ if (updates & PWRSTAT_BACKLIGHT)
+ config_hook_call(CONFIG_HOOK_POWERCONTROL,
+ CONFIG_HOOK_POWERCONTROL_LCDLIGHT,
+ (void*)(!(sc->sc_powerstate & PWRSTAT_SUSPEND) &&
+ (sc->sc_powerstate & PWRSTAT_BACKLIGHT)));
+}
+
static void
mq200_power(why, arg)
int why;
@@ -186,19 +216,25 @@ mq200_power(why, arg)
switch (why) {
case PWR_SUSPEND:
- sc->sc_powerstate = MQ200_POWERSTATE_D2;
+ sc->sc_powerstate |= PWRSTAT_SUSPEND;
+ mq200_update_powerstate(sc, PWRSTAT_ALL);
+ sc->sc_mq200pwstate = MQ200_POWERSTATE_D2;
break;
case PWR_STANDBY:
- sc->sc_powerstate = MQ200_POWERSTATE_D3;
+ sc->sc_powerstate |= PWRSTAT_SUSPEND;
+ mq200_update_powerstate(sc, PWRSTAT_ALL);
+ sc->sc_mq200pwstate = MQ200_POWERSTATE_D3;
break;
case PWR_RESUME:
- sc->sc_powerstate = MQ200_POWERSTATE_D0;
+ sc->sc_powerstate &= ~PWRSTAT_SUSPEND;
+ mq200_update_powerstate(sc, PWRSTAT_ALL);
+ sc->sc_mq200pwstate = MQ200_POWERSTATE_D0;
break;
}
- printf("MQ200_PMCSR=%08x\n", sc->sc_powerstate);
+ printf("MQ200_PMCSR=%08x\n", sc->sc_mq200pwstate);
bus_space_write_4(sc->sc_iot, sc->sc_ioh,
- MQ200_PMCSR, sc->sc_powerstate);
+ MQ200_PMCSR, sc->sc_mq200pwstate);
#endif
}
@@ -214,18 +250,24 @@ mq200_hardpower(ctx, type, id, msg)
switch (why) {
case PWR_SUSPEND:
- sc->sc_powerstate = MQ200_POWERSTATE_D2;
+ sc->sc_powerstate |= PWRSTAT_SUSPEND;
+ mq200_update_powerstate(sc, PWRSTAT_ALL);
+ sc->sc_mq200pwstate = MQ200_POWERSTATE_D2;
break;
case PWR_STANDBY:
- sc->sc_powerstate = MQ200_POWERSTATE_D3;
+ sc->sc_powerstate |= PWRSTAT_SUSPEND;
+ mq200_update_powerstate(sc, PWRSTAT_ALL);
+ sc->sc_mq200pwstate = MQ200_POWERSTATE_D3;
break;
case PWR_RESUME:
- sc->sc_powerstate = MQ200_POWERSTATE_D0;
+ sc->sc_powerstate &= ~PWRSTAT_SUSPEND;
+ mq200_update_powerstate(sc, PWRSTAT_ALL);
+ sc->sc_mq200pwstate = MQ200_POWERSTATE_D0;
break;
}
bus_space_write_4(sc->sc_iot, sc->sc_ioh,
- MQ200_PMCSR, sc->sc_powerstate);
+ MQ200_PMCSR, sc->sc_mq200pwstate);
/*
* you should wait until the
@@ -236,7 +278,7 @@ mq200_hardpower(ctx, type, id, msg)
do {
tmp = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
MQ200_PMCSR);
- } while ((tmp & 0x3) != (sc->sc_powerstate & 0x3));
+ } while ((tmp & 0x3) != (sc->sc_mq200pwstate & 0x3));
delay(100000); /* XXX */
}
@@ -419,13 +461,50 @@ mq200_ioctl(v, cmd, data, flag, p)
dispparam = (struct wsdisplay_param*)data;
switch (dispparam->param) {
case WSDISPLAYIO_PARAM_BACKLIGHT:
- VPRINTF(("mq200_ioctl: GETPARAM:BACKLIGHT\n"));
- return (EINVAL);
+ VPRINTF(("mq200_ioctl: GETPARAM:BACKLIGHT call\n"));
+ if (sc->sc_max_brightness == -1)
+ mq200_init_brightness(sc);
+ mq200_get_backlight(sc);
+ 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(("mq200_ioctl: GETPARAM:BACKLIGHT:%d\n",
+ dispparam->curval));
+ return 0;
+ break;
case WSDISPLAYIO_PARAM_CONTRAST:
- VPRINTF(("mq200_ioctl: GETPARAM:CONTRAST\n"));
- return (EINVAL);
+ VPRINTF(("mq200_ioctl: GETPARAM:CONTRAST call\n"));
+ if (sc->sc_max_contrast == -1)
+ mq200_init_contrast(sc);
+ if (sc->sc_max_contrast > 0) {
+ dispparam->min = 0;
+ dispparam->max = sc->sc_max_contrast;
+ dispparam->curval = sc->sc_contrast;
+ VPRINTF(("mq200_ioctl: GETPARAM:CONTRAST max=%d, current=%d\n", sc->sc_max_contrast, sc->sc_contrast));
+ return 0;
+ } else {
+ VPRINTF(("mq200_ioctl: GETPARAM:CONTRAST ret\n"));
+ return (EINVAL);
+ }
+ break;
case WSDISPLAYIO_PARAM_BRIGHTNESS:
- VPRINTF(("mq200_ioctl: GETPARAM:BRIGHTNESS\n"));
+ VPRINTF(("mq200_ioctl: GETPARAM:BRIGHTNESS call\n"));
+ if (sc->sc_max_brightness == -1)
+ mq200_init_brightness(sc);
+ if (sc->sc_max_brightness > 0) {
+ dispparam->min = 0;
+ dispparam->max = sc->sc_max_brightness;
+ dispparam->curval = sc->sc_brightness;
+ VPRINTF(("mq200_ioctl: GETPARAM:BRIGHTNESS max=%d, current=%d\n", sc->sc_max_brightness, sc->sc_brightness));
+ return 0;
+ } else {
+ VPRINTF(("mq200_ioctl: GETPARAM:BRIGHTNESS ret\n"));
+ return (EINVAL);
+ }
return (EINVAL);
default:
return (EINVAL);
@@ -436,14 +515,70 @@ mq200_ioctl(v, cmd, data, flag, p)
dispparam = (struct wsdisplay_param*)data;
switch (dispparam->param) {
case WSDISPLAYIO_PARAM_BACKLIGHT:
- VPRINTF(("mq200_ioctl: GETPARAM:BACKLIGHT\n"));
- return (EINVAL);
+ VPRINTF(("mq200_ioctl: SETPARAM:BACKLIGHT call\n"));
+ if (dispparam->curval < 0 ||
+ 1 < dispparam->curval)
+ return (EINVAL);
+ if (sc->sc_max_brightness == -1)
+ mq200_init_brightness(sc);
+ VPRINTF(("mq200_ioctl: SETPARAM: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;
+ mq200_set_brightness(sc, 0); /* min */
+ } else {
+ if (sc->sc_brightness_save == 0)
+ sc->sc_brightness_save = sc->sc_max_brightness;
+ mq200_set_brightness(sc, sc->sc_brightness_save);
+ }
+ VPRINTF(("mq200_ioctl: SETPARAM: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(("mq200_ioctl: SETPARAM:BACKLIGHT: powerstate %d\n",
+ (sc->sc_powerstate & PWRSTAT_BACKLIGHT)?1:0));
+ mq200_update_powerstate(sc, PWRSTAT_BACKLIGHT);
+ VPRINTF(("mq200_ioctl: SETPARAM:BACKLIGHT:%d\n",
+ (sc->sc_powerstate & PWRSTAT_BACKLIGHT)?1:0));
+ }
+ return 0;
+ break;
case WSDISPLAYIO_PARAM_CONTRAST:
- VPRINTF(("mq200_ioctl: GETPARAM:CONTRAST\n"));
- return (EINVAL);
+ VPRINTF(("mq200_ioctl: SETPARAM:CONTRAST call\n"));
+ if (sc->sc_max_contrast == -1)
+ mq200_init_contrast(sc);
+ if (dispparam->curval < 0 ||
+ sc->sc_max_contrast < dispparam->curval)
+ return (EINVAL);
+ if (sc->sc_max_contrast > 0) {
+ int org = sc->sc_contrast;
+ mq200_set_contrast(sc, dispparam->curval);
+ VPRINTF(("mq200_ioctl: SETPARAM:CONTRAST org=%d, current=%d\n", org, sc->sc_contrast));
+ return 0;
+ } else {
+ VPRINTF(("mq200_ioctl: SETPARAM:CONTRAST ret\n"));
+ return (EINVAL);
+ }
+ break;
case WSDISPLAYIO_PARAM_BRIGHTNESS:
- VPRINTF(("mq200_ioctl: GETPARAM:BRIGHTNESS\n"));
- return (EINVAL);
+ VPRINTF(("mq200_ioctl: SETPARAM:BRIGHTNESS call\n"));
+ if (sc->sc_max_brightness == -1)
+ mq200_init_brightness(sc);
+ if (dispparam->curval < 0 ||
+ sc->sc_max_brightness < dispparam->curval)
+ return (EINVAL);
+ if (sc->sc_max_brightness > 0) {
+ int org = sc->sc_brightness;
+ mq200_set_brightness(sc, dispparam->curval);
+ VPRINTF(("mq200_ioctl: SETPARAM:BRIGHTNESS org=%d, current=%d\n", org, sc->sc_brightness));
+ return 0;
+ } else {
+ VPRINTF(("mq200_ioctl: SETPARAM:BRIGHTNESS ret\n"));
+ return (EINVAL);
+ }
+ break;
default:
return (EINVAL);
}
@@ -514,3 +649,88 @@ mq200_mmap(ctx, offset, prot)
return mips_btop(sc->sc_baseaddr + offset);
}
+
+
+void
+mq200_get_backlight(sc)
+ struct mq200_softc *sc;
+{
+ int val = -1;
+
+ if (sc->sc_max_brightness < 0) {
+ if (config_hook_call(CONFIG_HOOK_GET,
+ CONFIG_HOOK_POWER_LCDLIGHT, &val) != -1) {
+ if (val == 0)
+ sc->sc_powerstate &= ~PWRSTAT_BACKLIGHT;
+ else
+ sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
+ }
+ }
+}
+
+void
+mq200_init_brightness(sc)
+ struct mq200_softc *sc;
+{
+ int val = -1;
+
+ VPRINTF(("mq200_init_brightness\n"));
+ if (config_hook_call(CONFIG_HOOK_GET,
+ CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
+ sc->sc_brightness_save = sc->sc_brightness = val;
+ }
+ val = -1;
+ if (config_hook_call(CONFIG_HOOK_GET,
+ CONFIG_HOOK_BRIGHTNESS_MAX, &val) != -1) {
+ sc->sc_max_brightness = val;
+ }
+ return;
+}
+
+
+void
+mq200_init_contrast(sc)
+ struct mq200_softc *sc;
+{
+ int val = -1;
+
+ VPRINTF(("mq200_init_contrast\n"));
+ if (config_hook_call(CONFIG_HOOK_GET,
+ CONFIG_HOOK_CONTRAST, &val) != -1) {
+ sc->sc_contrast = val;
+ }
+ val = -1;
+ if (config_hook_call(CONFIG_HOOK_GET,
+ CONFIG_HOOK_CONTRAST_MAX, &val) != -1) {
+ sc->sc_max_contrast = val;
+ }
+ return;
+}
+
+void
+mq200_set_brightness(sc, val)
+ struct mq200_softc *sc;
+ int val;
+{
+ sc->sc_brightness = val;
+
+ config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
+ if (config_hook_call(CONFIG_HOOK_GET,
+ CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
+ sc->sc_brightness = val;
+ }
+}
+
+void
+mq200_set_contrast(sc, val)
+ struct mq200_softc *sc;
+ int val;
+{
+ sc->sc_contrast = val;
+
+ config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST, &val);
+ if (config_hook_call(CONFIG_HOOK_GET,
+ CONFIG_HOOK_CONTRAST, &val) != -1) {
+ sc->sc_contrast = val;
+ }
+}
diff --git a/sys/arch/hpcmips/dev/mq200var.h b/sys/arch/hpcmips/dev/mq200var.h
index 28e92975fe9..ebc05e2a8ba 100644
--- a/sys/arch/hpcmips/dev/mq200var.h
+++ b/sys/arch/hpcmips/dev/mq200var.h
@@ -1,4 +1,4 @@
-/* $NetBSD: mq200var.h,v 1.2 2001/02/22 18:38:00 uch Exp $ */
+/* $NetBSD: mq200var.h,v 1.3 2001/02/27 08:54:18 sato Exp $ */
/*-
* Copyright (c) 2000 Takemura Shin
@@ -46,6 +46,16 @@ struct mq200_softc {
void *sc_powerhook; /* power management hook */
config_hook_tag sc_hardpowerhook;
int sc_powerstate;
+#define PWRSTAT_SUSPEND (1<<0)
+#define PWRSTAT_LCD (1<<1)
+#define PWRSTAT_BACKLIGHT (1<<2)
+#define PWRSTAT_ALL (0xffffffff)
+ int sc_brightness;
+ int sc_brightness_save;
+ int sc_max_brightness;
+ int sc_contrast;
+ int sc_max_contrast;
+ int sc_mq200pwstate; /* mq200 power state */
struct hpcfb_fbconf sc_fbconf;
struct hpcfb_dspconf sc_dspconf;
};
diff --git a/sys/dev/hpc/bivideo.c b/sys/dev/hpc/bivideo.c
index 80c8bc72e54..926ab7462ba 100644
--- a/sys/dev/hpc/bivideo.c
+++ b/sys/dev/hpc/bivideo.c
@@ -1,4 +1,4 @@
-/* $NetBSD: bivideo.c,v 1.2 2001/02/24 19:51:20 uch Exp $ */
+/* $NetBSD: bivideo.c,v 1.3 2001/02/27 08:54:17 sato Exp $ */
/*-
* Copyright (c) 1999-2001
@@ -37,7 +37,7 @@
static const char _copyright[] __attribute__ ((unused)) =
"Copyright (c) 1999 Shin Takemura. All rights reserved.";
static const char _rcsid[] __attribute__ ((unused)) =
- "$Id: bivideo.c,v 1.2 2001/02/24 19:51:20 uch Exp $";
+ "$Id: bivideo.c,v 1.3 2001/02/27 08:54:17 sato Exp $";
#include <sys/param.h>
#include <sys/systm.h>
@@ -88,10 +88,22 @@ struct bivideo_softc {
#define PWRSTAT_LCD (1<<1)
#define PWRSTAT_BACKLIGHT (1<<2)
#define PWRSTAT_ALL (0xffffffff)
+ int sc_brightness;
+ int sc_brightness_save;
+ int sc_max_brightness;
+ int sc_contrast;
+ int sc_max_contrast;
+
};
+
static int bivideo_init(struct hpcfb_fbconf *);
static void bivideo_power(int, void *);
static void bivideo_update_powerstate(struct bivideo_softc *, int);
+void bivideo_get_backlight(struct bivideo_softc *);
+void bivideo_init_brightness(struct bivideo_softc *);
+void bivideo_init_contrast(struct bivideo_softc *);
+void bivideo_set_brightness(struct bivideo_softc *, int);
+void bivideo_set_contrast(struct bivideo_softc *, int);
#if defined __mips__ || defined __sh__ || defined __arm__
#define __BTOP(x) ((paddr_t)(x) >> PGSHIFT)
@@ -160,6 +172,13 @@ bivideoattach(struct device *parent, struct device *self, void *aux)
printf("%s: WARNING: unable to establish power hook\n",
sc->sc_dev.dv_xname);
+ /* initialize backlight brightness and lcd contrast */
+ sc->sc_brightness = sc->sc_contrast =
+ sc->sc_max_brightness = sc->sc_max_contrast = -1;
+ bivideo_get_backlight(sc);
+ bivideo_init_brightness(sc);
+ bivideo_init_contrast(sc);
+
ha.ha_console = console_flag;
ha.ha_accessops = &bivideo_ha;
ha.ha_accessctx = sc;
@@ -377,22 +396,55 @@ bivideo_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
*/
return (EINVAL);
+
case WSDISPLAYIO_GETPARAM:
dispparam = (struct wsdisplay_param*)data;
switch (dispparam->param) {
case WSDISPLAYIO_PARAM_BACKLIGHT:
+ VPRINTF(("bivideo_ioctl: GETPARAM:BACKLIGHT call\n"));
+ if (sc->sc_max_brightness == -1)
+ bivideo_init_brightness(sc);
+ bivideo_get_backlight(sc);
dispparam->min = 0;
dispparam->max = 1;
- dispparam->curval =
- (sc->sc_powerstate & PWRSTAT_BACKLIGHT) ? 1 : 0;
+ 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(("bivideo_ioctl: GETPARAM:BACKLIGHT:%d\n",
dispparam->curval));
+ return 0;
break;
case WSDISPLAYIO_PARAM_CONTRAST:
- VPRINTF(("bivideo_ioctl: GETPARAM:CONTRAST\n"));
- return (EINVAL);
+ VPRINTF(("bivideo_ioctl: GETPARAM:CONTRAST call\n"));
+ if (sc->sc_max_contrast == -1)
+ bivideo_init_contrast(sc);
+ if (sc->sc_max_contrast > 0) {
+ dispparam->min = 0;
+ dispparam->max = sc->sc_max_contrast;
+ dispparam->curval = sc->sc_contrast;
+ VPRINTF(("bivideo_ioctl: GETPARAM:CONTRAST max=%d, current=%d\n", sc->sc_max_contrast, sc->sc_contrast));
+ return 0;
+ } else {
+ VPRINTF(("bivideo_ioctl: GETPARAM:CONTRAST ret\n"));
+ return (EINVAL);
+ }
+ break;
case WSDISPLAYIO_PARAM_BRIGHTNESS:
- VPRINTF(("bivideo_ioctl: GETPARAM:BRIGHTNESS\n"));
+ VPRINTF(("bivideo_ioctl: GETPARAM:BRIGHTNESS call\n"));
+ if (sc->sc_max_brightness == -1)
+ bivideo_init_brightness(sc);
+ if (sc->sc_max_brightness > 0) {
+ dispparam->min = 0;
+ dispparam->max = sc->sc_max_brightness;
+ dispparam->curval = sc->sc_brightness;
+ VPRINTF(("bivideo_ioctl: GETPARAM:BRIGHTNESS max=%d, current=%d\n", sc->sc_max_brightness, sc->sc_brightness));
+ return 0;
+ } else {
+ VPRINTF(("bivideo_ioctl: GETPARAM:BRIGHTNESS ret\n"));
+ return (EINVAL);
+ }
return (EINVAL);
default:
return (EINVAL);
@@ -403,23 +455,70 @@ bivideo_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
dispparam = (struct wsdisplay_param*)data;
switch (dispparam->param) {
case WSDISPLAYIO_PARAM_BACKLIGHT:
+ VPRINTF(("bivideo_ioctl: SETPARAM:BACKLIGHT call\n"));
if (dispparam->curval < 0 ||
1 < dispparam->curval)
return (EINVAL);
- if (dispparam->curval == 0)
- sc->sc_powerstate &= ~PWRSTAT_BACKLIGHT;
- else
- sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
- bivideo_update_powerstate(sc, PWRSTAT_BACKLIGHT);
- VPRINTF(("bivideo_ioctl: SETPARAM:BACKLIGHT:%d\n",
- (sc->sc_powerstate & PWRSTAT_BACKLIGHT)?1:0));
+ if (sc->sc_max_brightness == -1)
+ bivideo_init_brightness(sc);
+ VPRINTF(("bivideo_ioctl: SETPARAM: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;
+ bivideo_set_brightness(sc, 0); /* min */
+ } else {
+ if (sc->sc_brightness_save == 0)
+ sc->sc_brightness_save = sc->sc_max_brightness;
+ bivideo_set_brightness(sc, sc->sc_brightness_save);
+ }
+ VPRINTF(("bivideo_ioctl: SETPARAM: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(("bivideo_ioctl: SETPARAM:BACKLIGHT: powerstate %d\n",
+ (sc->sc_powerstate & PWRSTAT_BACKLIGHT)?1:0));
+ bivideo_update_powerstate(sc, PWRSTAT_BACKLIGHT);
+ VPRINTF(("bivideo_ioctl: SETPARAM:BACKLIGHT:%d\n",
+ (sc->sc_powerstate & PWRSTAT_BACKLIGHT)?1:0));
+ }
+ return 0;
break;
case WSDISPLAYIO_PARAM_CONTRAST:
- VPRINTF(("bivideo_ioctl: SETPARAM:CONTRAST\n"));
- return (EINVAL);
+ VPRINTF(("bivideo_ioctl: SETPARAM:CONTRAST call\n"));
+ if (sc->sc_max_contrast == -1)
+ bivideo_init_contrast(sc);
+ if (dispparam->curval < 0 ||
+ sc->sc_max_contrast < dispparam->curval)
+ return (EINVAL);
+ if (sc->sc_max_contrast > 0) {
+ int org = sc->sc_contrast;
+ bivideo_set_contrast(sc, dispparam->curval);
+ VPRINTF(("bivideo_ioctl: SETPARAM:CONTRAST org=%d, current=%d\n", org, sc->sc_contrast));
+ return 0;
+ } else {
+ VPRINTF(("bivideo_ioctl: SETPARAM:CONTRAST ret\n"));
+ return (EINVAL);
+ }
+ break;
case WSDISPLAYIO_PARAM_BRIGHTNESS:
- VPRINTF(("mq200_ioctl: SETPARAM:BRIGHTNESS\n"));
- return (EINVAL);
+ VPRINTF(("bivideo_ioctl: SETPARAM:BRIGHTNESS call\n"));
+ if (sc->sc_max_brightness == -1)
+ bivideo_init_brightness(sc);
+ if (dispparam->curval < 0 ||
+ sc->sc_max_brightness < dispparam->curval)
+ return (EINVAL);
+ if (sc->sc_max_brightness > 0) {
+ int org = sc->sc_brightness;
+ bivideo_set_brightness(sc, dispparam->curval);
+ VPRINTF(("bivideo_ioctl: SETPARAM:BRIGHTNESS org=%d, current=%d\n", org, sc->sc_brightness));
+ return 0;
+ } else {
+ VPRINTF(("bivideo_ioctl: SETPARAM:BRIGHTNESS ret\n"));
+ return (EINVAL);
+ }
+ break;
default:
return (EINVAL);
}
@@ -489,3 +588,78 @@ bivideo_mmap(void *ctx, off_t offset, int prot)
return __BTOP((u_long)bootinfo->fb_addr + offset);
}
+
+void
+bivideo_get_backlight(struct bivideo_softc *sc)
+{
+ int val = -1;
+
+ if (sc->sc_max_brightness < 0) {
+ if (config_hook_call(CONFIG_HOOK_GET,
+ CONFIG_HOOK_POWER_LCDLIGHT, &val) != -1) {
+ if (val == 0)
+ sc->sc_powerstate &= ~PWRSTAT_BACKLIGHT;
+ else
+ sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
+ }
+ }
+}
+
+void
+bivideo_init_brightness(struct bivideo_softc *sc)
+{
+ int val = -1;
+
+ if (config_hook_call(CONFIG_HOOK_GET,
+ CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
+ sc->sc_brightness_save = sc->sc_brightness = val;
+ }
+ val = -1;
+ if (config_hook_call(CONFIG_HOOK_GET,
+ CONFIG_HOOK_BRIGHTNESS_MAX, &val) != -1) {
+ sc->sc_max_brightness = val;
+ }
+ return;
+}
+
+
+void
+bivideo_init_contrast(struct bivideo_softc *sc)
+{
+ int val = -1;
+
+ if (config_hook_call(CONFIG_HOOK_GET,
+ CONFIG_HOOK_CONTRAST, &val) != -1) {
+ sc->sc_contrast = val;
+ }
+ val = -1;
+ if (config_hook_call(CONFIG_HOOK_GET,
+ CONFIG_HOOK_CONTRAST_MAX, &val) != -1) {
+ sc->sc_max_contrast = val;
+ }
+ return;
+}
+
+void
+bivideo_set_brightness(struct bivideo_softc *sc, int val)
+{
+ sc->sc_brightness = val;
+
+ config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
+ if (config_hook_call(CONFIG_HOOK_GET,
+ CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
+ sc->sc_brightness = val;
+ }
+}
+
+void
+bivideo_set_contrast(struct bivideo_softc *sc, int val)
+{
+ sc->sc_contrast = val;
+
+ config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST, &val);
+ if (config_hook_call(CONFIG_HOOK_GET,
+ CONFIG_HOOK_CONTRAST, &val) != -1) {
+ sc->sc_contrast = val;
+ }
+}