From 528d06d0bc229d08a2b877bcd430e58682e03258 Mon Sep 17 00:00:00 2001 From: patrick Date: Tue, 25 Apr 2023 11:21:01 +0000 Subject: [PATCH] Add suspend/resume support to pwmbl(4), so that when suspending the x13s the display turns off and it actually looks like it's properly suspended. ok kettenis@ tobhe@ --- sys/dev/fdt/pwmbl.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/sys/dev/fdt/pwmbl.c b/sys/dev/fdt/pwmbl.c index 08b63f7c3c9..e55484085b9 100644 --- a/sys/dev/fdt/pwmbl.c +++ b/sys/dev/fdt/pwmbl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pwmbl.c,v 1.7 2022/11/14 07:22:44 miod Exp $ */ +/* $OpenBSD: pwmbl.c,v 1.8 2023/04/25 11:21:01 patrick Exp $ */ /* * Copyright (c) 2019 Krystian Lewandowski * Copyright (c) 2019 Mark Kettenis @@ -39,15 +39,18 @@ struct pwmbl_softc { int sc_nlevels; uint32_t sc_max_level; uint32_t sc_def_level; + struct pwm_state sc_ps_saved; }; struct pwmbl_softc *sc_pwmbl; int pwmbl_match(struct device *, void *, void *); void pwmbl_attach(struct device *, struct device *, void *); +int pwmbl_activate(struct device *, int); const struct cfattach pwmbl_ca = { - sizeof(struct pwmbl_softc), pwmbl_match, pwmbl_attach + sizeof(struct pwmbl_softc), pwmbl_match, pwmbl_attach, NULL, + pwmbl_activate }; struct cfdriver pwmbl_cd = { @@ -121,6 +124,29 @@ pwmbl_attach(struct device *parent, struct device *self, void *aux) ws_set_param = pwmbl_set_param; } +int +pwmbl_activate(struct device *self, int act) +{ + struct pwmbl_softc *sc = (struct pwmbl_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; +} + int pwmbl_get_brightness(void *cookie, uint32_t *level) { -- 2.20.1