Author: avg
Date: Thu Jul 30 14:01:54 2020
New Revision: 363696
URL: https://svnweb.freebsd.org/changeset/base/363696

Log:
  MFC r363382: gpioiic: never drive lines active high
  
  Few drivers support GPIO_PIN_OPENDRAIN.

Modified:
  stable/12/sys/dev/gpio/gpioiic.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/dev/gpio/gpioiic.c
==============================================================================
--- stable/12/sys/dev/gpio/gpioiic.c    Thu Jul 30 13:56:45 2020        
(r363695)
+++ stable/12/sys/dev/gpio/gpioiic.c    Thu Jul 30 14:01:54 2020        
(r363696)
@@ -191,16 +191,14 @@ static void
 gpioiic_setsda(device_t dev, int val)
 {
        struct gpioiic_softc *sc = device_get_softc(dev);
-       int err;
 
-       /*
-        * Some controllers cannot set an output value while a pin is in input
-        * mode; in that case we set the pin again after changing mode.
-        */
-       err = gpio_pin_set_active(sc->sdapin, val);
-       gpio_pin_setflags(sc->sdapin, GPIO_PIN_OUTPUT | GPIO_PIN_OPENDRAIN);
-       if (err != 0)
-               gpio_pin_set_active(sc->sdapin, val);
+       if (val) {
+               gpio_pin_setflags(sc->sdapin, GPIO_PIN_INPUT);
+       } else {
+               gpio_pin_setflags(sc->sdapin,
+                   GPIO_PIN_OUTPUT | GPIO_PIN_OPENDRAIN);
+               gpio_pin_set_active(sc->sdapin, 0);
+       }
 }
 
 static void
@@ -208,8 +206,13 @@ gpioiic_setscl(device_t dev, int val)
 {
        struct gpioiic_softc *sc = device_get_softc(dev);
 
-       gpio_pin_setflags(sc->sclpin, GPIO_PIN_OUTPUT | GPIO_PIN_OPENDRAIN);
-       gpio_pin_set_active(sc->sclpin, val);
+       if (val) {
+               gpio_pin_setflags(sc->sclpin, GPIO_PIN_INPUT);
+       } else {
+               gpio_pin_setflags(sc->sclpin,
+                   GPIO_PIN_OUTPUT | GPIO_PIN_OPENDRAIN);
+               gpio_pin_set_active(sc->sclpin, 0);
+       }
 }
 
 static int
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to