From eec5e9247e932bd29776052b5ec57339c7779a00 Mon Sep 17 00:00:00 2001 From: jmcneill Date: Thu, 10 May 2018 13:11:21 +0000 Subject: [PATCH] Keep the backlight off while the lid is closed. --- sys/dev/fdt/pwm_backlight.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/sys/dev/fdt/pwm_backlight.c b/sys/dev/fdt/pwm_backlight.c index c1f707032262..b9832898b41d 100644 --- a/sys/dev/fdt/pwm_backlight.c +++ b/sys/dev/fdt/pwm_backlight.c @@ -1,4 +1,4 @@ -/* $NetBSD: pwm_backlight.c,v 1.3 2018/05/07 12:58:58 jmcneill Exp $ */ +/* $NetBSD: pwm_backlight.c,v 1.4 2018/05/10 13:11:21 jmcneill Exp $ */ /*- * Copyright (c) 2018 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pwm_backlight.c,v 1.3 2018/05/07 12:58:58 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pwm_backlight.c,v 1.4 2018/05/10 13:11:21 jmcneill Exp $"); #include #include @@ -50,6 +50,8 @@ struct pwm_backlight_softc { u_int sc_nlevels; char *sc_levelstr; + + bool sc_lid_state; }; static int pwm_backlight_match(device_t, cfdata_t, void *); @@ -122,6 +124,8 @@ pwm_backlight_attach(device_t parent, device_t self, void *aux) aprint_verbose(">"); aprint_normal("\n"); + sc->sc_lid_state = true; + if (of_getprop_uint32(phandle, "default-brightness-level", &default_level) == 0) { /* set the default level now */ pwm_backlight_set(sc, default_level); @@ -247,7 +251,7 @@ pwm_backlight_display_on(device_t dev) { struct pwm_backlight_softc * const sc = device_private(dev); - if (sc->sc_pin) + if (sc->sc_pin && sc->sc_lid_state) fdtbus_gpio_write(sc->sc_pin, 1); } @@ -260,6 +264,28 @@ pwm_backlight_display_off(device_t dev) fdtbus_gpio_write(sc->sc_pin, 0); } +static void +pwm_backlight_chassis_lid_open(device_t dev) +{ + struct pwm_backlight_softc * const sc = device_private(dev); + + sc->sc_lid_state = true; + + if (sc->sc_pin) + fdtbus_gpio_write(sc->sc_pin, 1); +} + +static void +pwm_backlight_chassis_lid_close(device_t dev) +{ + struct pwm_backlight_softc * const sc = device_private(dev); + + sc->sc_lid_state = false; + + if (sc->sc_pin) + fdtbus_gpio_write(sc->sc_pin, 0); +} + static void pwm_backlight_display_brightness_up(device_t dev) { @@ -289,6 +315,10 @@ pwm_backlight_pmf_init(struct pwm_backlight_softc *sc) pwm_backlight_display_on, true); pmf_event_register(sc->sc_dev, PMFE_DISPLAY_OFF, pwm_backlight_display_off, true); + pmf_event_register(sc->sc_dev, PMFE_CHASSIS_LID_OPEN, + pwm_backlight_chassis_lid_open, true); + pmf_event_register(sc->sc_dev, PMFE_CHASSIS_LID_CLOSE, + pwm_backlight_chassis_lid_close, true); pmf_event_register(sc->sc_dev, PMFE_DISPLAY_BRIGHTNESS_UP, pwm_backlight_display_brightness_up, true); pmf_event_register(sc->sc_dev, PMFE_DISPLAY_BRIGHTNESS_DOWN,