diff options
author | Tobias Heider <tobhe@cvs.openbsd.org> | 2023-04-25 11:12:39 +0000 |
---|---|---|
committer | Tobias Heider <tobhe@cvs.openbsd.org> | 2023-04-25 11:12:39 +0000 |
commit | ecb78a82fc23da1507500d3494f5fba27ff65aec (patch) | |
tree | 463458386bd88c8292d209d3fcd492ce7106625d /sys/dev | |
parent | f085855401551c98f43019d33cbaeb00c7e3a98b (diff) |
Disable keyboard backlight on Apple Silicon laptops on suspend,
restore on wakeup.
ok patrick@ kettenis@
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/fdt/pwmleds.c | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/sys/dev/fdt/pwmleds.c b/sys/dev/fdt/pwmleds.c index 24d2fe054c6..12b29ee15d9 100644 --- a/sys/dev/fdt/pwmleds.c +++ b/sys/dev/fdt/pwmleds.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pwmleds.c,v 1.1 2022/11/23 23:43:08 kettenis Exp $ */ +/* $OpenBSD: pwmleds.c,v 1.2 2023/04/25 11:12:38 tobhe Exp $ */ /* * Copyright (c) 2022 Mark Kettenis <kettenis@openbsd.org> * @@ -33,19 +33,22 @@ extern int (*wskbd_get_backlight)(struct wskbd_backlight *); extern int (*wskbd_set_backlight)(struct wskbd_backlight *); struct pwmleds_softc { - struct device sc_dev; + struct device sc_dev; /* Keyboard backlight. */ - uint32_t *sc_pwm; - int sc_pwm_len; - uint32_t sc_max_brightness; + uint32_t *sc_pwm; + int sc_pwm_len; + uint32_t sc_max_brightness; + struct pwm_state sc_ps_saved; }; int pwmleds_match(struct device *, void *, void *); void pwmleds_attach(struct device *, struct device *, void *); +int pwmleds_activate(struct device *, int); const struct cfattach pwmleds_ca = { - sizeof (struct pwmleds_softc), pwmleds_match, pwmleds_attach + sizeof (struct pwmleds_softc), pwmleds_match, pwmleds_attach, NULL, + pwmleds_activate }; struct cfdriver pwmleds_cd = { @@ -101,6 +104,29 @@ pwmleds_attach(struct device *parent, struct device *self, void *aux) } } +int +pwmleds_activate(struct device *self, int act) +{ + struct pwmleds_softc *sc = (struct pwmleds_softc *)self; + struct pwm_state ps; + int error; + + switch (act) { + case DVACT_QUIESCE: + error = pwm_get_state(sc->sc_pwm, &sc->sc_ps_saved); + if (error) + return error; + + pwm_init_state(sc->sc_pwm, &ps); + ps.ps_pulse_width = 0; + ps.ps_enabled = 0; + return pwm_set_state(sc->sc_pwm, &ps); + case DVACT_WAKEUP: + return pwm_set_state(sc->sc_pwm, &sc->sc_ps_saved); + } + return 0; +} + struct pwmleds_softc * pwmleds_kbd_backlight(void) { |