Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/macppc/dev listen to PMF events in order to turn of...



details:   https://anonhg.NetBSD.org/src/rev/1e160bc92cef
branches:  trunk
changeset: 744551:1e160bc92cef
user:      macallan <macallan%NetBSD.org@localhost>
date:      Thu Feb 06 02:17:24 2020 +0000

description:
listen to PMF events in order to turn off keyboard lights when the lid is
closed or the screen is blanked

diffstat:

 sys/arch/macppc/dev/lmu.c |  56 ++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 51 insertions(+), 5 deletions(-)

diffs (107 lines):

diff -r 0f86b62a360b -r 1e160bc92cef sys/arch/macppc/dev/lmu.c
--- a/sys/arch/macppc/dev/lmu.c Thu Feb 06 01:37:46 2020 +0000
+++ b/sys/arch/macppc/dev/lmu.c Thu Feb 06 02:17:24 2020 +0000
@@ -1,4 +1,4 @@
- /* $NetBSD: lmu.c,v 1.1 2020/01/10 06:24:17 macallan Exp $ */
+ /* $NetBSD: lmu.c,v 1.2 2020/02/06 02:17:24 macallan Exp $ */
 
 /*-
  * Copyright (c) 2020 Michael Lorenz
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lmu.c,v 1.1 2020/01/10 06:24:17 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lmu.c,v 1.2 2020/02/06 02:17:24 macallan Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -56,7 +56,8 @@
        struct sysmon_envsys *sc_sme;
        envsys_data_t   sc_sensors[2];
        callout_t       sc_adjust;
-       int sc_thresh, sc_hyst;
+       int sc_thresh, sc_hyst, sc_level;
+       int             sc_lid_state, sc_video_state;
 };
 
 static int     lmu_match(device_t, cfdata_t, void *);
@@ -76,6 +77,38 @@
        { NULL,                 0 }
 };
 
+static void
+lmu_lid_open(device_t dev)
+{
+       struct lmu_softc * const sc = device_private(dev);
+
+       sc->sc_lid_state = true;
+}
+
+static void
+lmu_lid_close(device_t dev)
+{
+       struct lmu_softc * const sc = device_private(dev);
+
+       sc->sc_lid_state = false;
+}
+
+static void
+lmu_video_on(device_t dev)
+{
+       struct lmu_softc * const sc = device_private(dev);
+
+       sc->sc_video_state = true;
+}
+
+static void
+lmu_video_off(device_t dev)
+{
+       struct lmu_softc * const sc = device_private(dev);
+
+       sc->sc_video_state = false;
+}
+
 static int
 lmu_match(device_t parent, cfdata_t match, void *aux)
 {
@@ -103,6 +136,17 @@
        aprint_naive("\n");
        aprint_normal(": ambient light sensor\n");
 
+       sc->sc_lid_state = true;
+       pmf_event_register(sc->sc_dev, PMFE_CHASSIS_LID_OPEN,
+           lmu_lid_open, true);
+       pmf_event_register(sc->sc_dev, PMFE_CHASSIS_LID_CLOSE,
+           lmu_lid_close, true);
+       sc->sc_video_state = true;
+       pmf_event_register(sc->sc_dev, PMFE_DISPLAY_ON,
+           lmu_video_on, true);
+       pmf_event_register(sc->sc_dev, PMFE_DISPLAY_OFF,
+           lmu_video_off, true);
+
        sc->sc_sme = sysmon_envsys_create();
        sc->sc_sme->sme_name = device_xname(self);
        sc->sc_sme->sme_cookie = sc;
@@ -127,6 +171,7 @@
        /* TODO: make this adjustable via sysctl */
        sc->sc_thresh = 300;
        sc->sc_hyst = 30;
+       sc->sc_level = 100;
 
        callout_init(&sc->sc_adjust, 0);
        callout_setfunc(&sc->sc_adjust, lmu_adjust, sc);
@@ -189,10 +234,11 @@
        right = lmu_get_brightness(sc, 0);
        b = left > right ? left : right;
 
-       if (b > (sc->sc_thresh + sc->sc_hyst)) {
+       if ((b > (sc->sc_thresh + sc->sc_hyst)) ||
+          !(sc->sc_lid_state && sc->sc_video_state)) {
                lmu_set_brightness(sc, 0);
        } else if (b < sc->sc_thresh) {
-               lmu_set_brightness(sc, 100);
+               lmu_set_brightness(sc, sc->sc_level);
        }
 
        callout_schedule(&sc->sc_adjust, hz * 2);       



Home | Main Index | Thread Index | Old Index