Hello

I encoutered this problem with gpio_resume(): it will attemp to restore state 
for all pins, calling xxx_pin_ctl() and xxx_pin_write() for each of them.

The behavior may be harmful if the firmware uses some pins, for instance
to enable/disable other chips. The state we restore may be irrelevant
at resume time, and wreck the system. 

What about this change, so that the underlying GPIO driver can prevent
state resume for some pins?

Index: sys/dev/gpio/gpio.c
===================================================================
RCS file: /cvsroot/src/sys/dev/gpio/gpio.c,v
retrieving revision 1.71
diff -U4 -r1.71 gpio.c
--- sys/dev/gpio/gpio.c 27 Apr 2022 23:15:30 -0000      1.71
+++ sys/dev/gpio/gpio.c 17 Aug 2022 09:59:25 -0000
@@ -147,8 +147,10 @@
        struct gpio_softc *sc = device_private(self);
        int pin;
 
        for (pin = 0; pin < sc->sc_npins; pin++) {
+               if (sc->sc_pins[pin].pin_flags & GPIO_PIN_NORESUME)
+                       continue;
                gpiobus_pin_ctl(sc->sc_gc, pin, sc->sc_pins[pin].pin_flags);
                gpiobus_pin_write(sc->sc_gc, pin, sc->sc_pins[pin].pin_state);
        }
        return true;
cvs diff: Diffing sys/sys
Index: sys/sys/gpio.h
===================================================================
RCS file: /cvsroot/src/sys/sys/gpio.h,v
retrieving revision 1.16
diff -U4 -r1.16 gpio.h
--- sys/sys/gpio.h      19 May 2018 13:59:06 -0000      1.16
+++ sys/sys/gpio.h      17 Aug 2022 09:59:25 -0000
@@ -51,8 +51,9 @@
 #define GPIO_PIN_ALT4          0x00100000      /* alternate function 4 */
 #define GPIO_PIN_ALT5          0x00200000      /* alternate function 5 */
 #define GPIO_PIN_ALT6          0x00400000      /* alternate function 6 */
 #define GPIO_PIN_ALT7          0x00800000      /* alternate function 7 */
+#define GPIO_PIN_NORESUME      0x01000000      /* Do not resume state */
 
 #define        GPIO_PIN_HWCAPS         (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT | \
                                 GPIO_PIN_INOUT | GPIO_PIN_OPENDRAIN | \
                                 GPIO_PIN_PUSHPULL | GPIO_PIN_TRISTATE | \


-- 
Emmanuel Dreyfus
m...@netbsd.org

Reply via email to