Add suspend/resume support to pwmbl(4), so that when suspending the x13s
authorpatrick <patrick@openbsd.org>
Tue, 25 Apr 2023 11:21:01 +0000 (11:21 +0000)
committerpatrick <patrick@openbsd.org>
Tue, 25 Apr 2023 11:21:01 +0000 (11:21 +0000)
the display turns off and it actually looks like it's properly suspended.

ok kettenis@ tobhe@

sys/dev/fdt/pwmbl.c

index 08b63f7..e554840 100644 (file)
@@ -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 <kettenis@openbsd.org>
@@ -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)
 {