summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorloos <loos@FreeBSD.org>2014-05-31 14:27:50 +0000
committerloos <loos@FreeBSD.org>2014-05-31 14:27:50 +0000
commite4deb6b891826cd2159814f36c96c894d3906b7c (patch)
treeb62a0441a76213b5e00a22b695afd80c401f95f5
parentaec12e95d1fcd536d906a08b6638447b6a6c0f90 (diff)
downloadFreeBSD-src-e4deb6b891826cd2159814f36c96c894d3906b7c.zip
FreeBSD-src-e4deb6b891826cd2159814f36c96c894d3906b7c.tar.gz
Add a bounds verification to the SCL and SDA pin values.
At attach, print the SCL and SDA pin numbers. Remove a stray blank line. Remove the GPIOBUS locking from gpioiic_reset(), it is already called with this lock held. This fixes a crash when you try to scan the iicbus with i2c(8).
-rw-r--r--sys/dev/gpio/gpioiic.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/sys/dev/gpio/gpioiic.c b/sys/dev/gpio/gpioiic.c
index d7772b6..2698e50 100644
--- a/sys/dev/gpio/gpioiic.c
+++ b/sys/dev/gpio/gpioiic.c
@@ -46,6 +46,8 @@ __FBSDID("$FreeBSD$");
#include <dev/fdt/fdt_common.h>
#endif
+#include <dev/gpio/gpiobusvar.h>
+
#include <dev/iicbus/iiconf.h>
#include <dev/iicbus/iicbus.h>
@@ -74,7 +76,6 @@ static int gpioiic_getsda(device_t);
static int gpioiic_getscl(device_t);
static int gpioiic_reset(device_t, u_char, u_char, u_char *);
-
static int
gpioiic_probe(device_t dev)
{
@@ -91,13 +92,15 @@ gpioiic_probe(device_t dev)
static int
gpioiic_attach(device_t dev)
{
- struct gpioiic_softc *sc = device_get_softc(dev);
device_t bitbang;
#ifdef FDT
phandle_t node;
pcell_t pin;
#endif
+ struct gpiobus_ivar *devi;
+ struct gpioiic_softc *sc;
+ sc = device_get_softc(dev);
sc->sc_dev = dev;
sc->sc_busdev = device_get_parent(dev);
if (resource_int_value(device_get_name(dev),
@@ -116,6 +119,15 @@ gpioiic_attach(device_t dev)
sc->sda_pin = (int)pin;
#endif
+ if (sc->scl_pin < 0 || sc->scl_pin > 1)
+ sc->scl_pin = SCL_PIN_DEFAULT;
+ if (sc->sda_pin < 0 || sc->sda_pin > 1)
+ sc->sda_pin = SDA_PIN_DEFAULT;
+
+ devi = GPIOBUS_IVAR(dev);
+ device_printf(dev, "SCL pin: %d, SDA pin: %d\n",
+ devi->pins[sc->scl_pin], devi->pins[sc->sda_pin]);
+
/* add generic bit-banging code */
bitbang = device_add_child(dev, "iicbb", -1);
device_probe_and_attach(bitbang);
@@ -221,16 +233,11 @@ gpioiic_getsda(device_t dev)
static int
gpioiic_reset(device_t dev, u_char speed, u_char addr, u_char *oldaddr)
{
- struct gpioiic_softc *sc = device_get_softc(dev);
-
- GPIOBUS_LOCK_BUS(sc->sc_busdev);
- GPIOBUS_ACQUIRE_BUS(sc->sc_busdev, sc->sc_dev);
+ struct gpioiic_softc *sc;
+ sc = device_get_softc(dev);
gpioiic_reset_bus(sc->sc_dev);
- GPIOBUS_RELEASE_BUS(sc->sc_busdev, sc->sc_dev);
- GPIOBUS_UNLOCK_BUS(sc->sc_busdev);
-
return (IIC_ENOADDR);
}
OpenPOWER on IntegriCloud