Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Nov 2019 07:56:14 +0000 (UTC)
From:      Andriy Gapon <avg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r354532 - stable/12/sys/dev/gpio
Message-ID:  <201911080756.xA87uEVg069407@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avg
Date: Fri Nov  8 07:56:14 2019
New Revision: 354532
URL: https://svnweb.freebsd.org/changeset/base/354532

Log:
  MFC r354065: gpioiic: set output after switching to output mode...
  
  if presetting it failed.

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	Fri Nov  8 07:38:34 2019	(r354531)
+++ stable/12/sys/dev/gpio/gpioiic.c	Fri Nov  8 07:56:14 2019	(r354532)
@@ -168,59 +168,67 @@ gpioiic_reset_bus(device_t dev)
 }
 
 static void
-gpioiic_setsda(device_t dev, int val)
+gpioiic_setpin(struct gpioiic_softc *sc, int pin, int val)
 {
-	struct gpioiic_softc		*sc = device_get_softc(dev);
+	int				err;
 
 	if (val == 0) {
-		GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, sc->sda_pin, 0);
-		GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->sda_pin,
+		err = GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, pin, 0);
+		GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, pin,
 		    GPIO_PIN_OUTPUT);
+
+		/*
+		 * Some controllers cannot set output value while a pin is in
+		 * input mode.
+		 */
+		if (err != 0)
+			GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, pin, 0);
 	} else {
-		GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->sda_pin,
+		GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, pin,
 		    GPIO_PIN_INPUT);
 	}
 }
 
 static void
+gpioiic_setsda(device_t dev, int val)
+{
+	struct gpioiic_softc		*sc = device_get_softc(dev);
+
+	gpioiic_setpin(sc, sc->sda_pin, val);
+}
+
+static void
 gpioiic_setscl(device_t dev, int val)
 {
 	struct gpioiic_softc		*sc = device_get_softc(dev);
 
-	if (val == 0) {
-		GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, sc->scl_pin, 0);
-		GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->scl_pin,
-		    GPIO_PIN_OUTPUT);
-	} else {
-		GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->scl_pin,
-		    GPIO_PIN_INPUT);
-	}
+	gpioiic_setpin(sc, sc->scl_pin, val);
 }
 
 static int
-gpioiic_getscl(device_t dev)
+gpioiic_getpin(struct gpioiic_softc *sc, int pin)
 {
-	struct gpioiic_softc		*sc = device_get_softc(dev);
 	unsigned int			val;
 
-	GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->scl_pin,
-	    GPIO_PIN_INPUT);
-	GPIOBUS_PIN_GET(sc->sc_busdev, sc->sc_dev, sc->scl_pin, &val);
-
+	GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, pin, GPIO_PIN_INPUT);
+	GPIOBUS_PIN_GET(sc->sc_busdev, sc->sc_dev, pin, &val);
 	return ((int)val);
 }
 
 static int
-gpioiic_getsda(device_t dev)
+gpioiic_getscl(device_t dev)
 {
 	struct gpioiic_softc		*sc = device_get_softc(dev);
-	unsigned int			val;
 
-	GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->sda_pin,
-	    GPIO_PIN_INPUT);
-	GPIOBUS_PIN_GET(sc->sc_busdev, sc->sc_dev, sc->sda_pin, &val);
+	return (gpioiic_getpin(sc, sc->scl_pin));
+}
 
-	return ((int)val);
+static int
+gpioiic_getsda(device_t dev)
+{
+	struct gpioiic_softc		*sc = device_get_softc(dev);
+
+	return (gpioiic_getpin(sc, sc->sda_pin));
 }
 
 static int



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201911080756.xA87uEVg069407>