aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/gpio
diff options
context:
space:
mode:
authorAndriy Gapon <avg@FreeBSD.org>2019-10-25 09:37:54 +0000
committerAndriy Gapon <avg@FreeBSD.org>2019-10-25 09:37:54 +0000
commitab0a20286314b0d538ff04d14df248f820730024 (patch)
tree18fcad2484927c08a61fed8e7183bbc589f2c155 /sys/dev/gpio
parent8c017db74758aa51c2f3fe10f63d01ffc174e7f1 (diff)
Notes
Diffstat (limited to 'sys/dev/gpio')
-rw-r--r--sys/dev/gpio/gpioiic.c58
1 files changed, 33 insertions, 25 deletions
diff --git a/sys/dev/gpio/gpioiic.c b/sys/dev/gpio/gpioiic.c
index cad2e1b5c970..d084af82a90b 100644
--- a/sys/dev/gpio/gpioiic.c
+++ b/sys/dev/gpio/gpioiic.c
@@ -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