Date: Sun, 22 May 2016 03:34:18 +0000 (UTC) From: Luiz Otavio O Souza <loos@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r300391 - head/sys/dev/gpio Message-ID: <201605220334.u4M3YIgG008752@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: loos Date: Sun May 22 03:34:18 2016 New Revision: 300391 URL: https://svnweb.freebsd.org/changeset/base/300391 Log: Use a better prefix for defines, return BUS_PROBE_DEFAULT for probe routine. Refuse to attach if the number of given pins is not enough for our needs. Modified: head/sys/dev/gpio/gpioiic.c Modified: head/sys/dev/gpio/gpioiic.c ============================================================================== --- head/sys/dev/gpio/gpioiic.c Sun May 22 03:12:49 2016 (r300390) +++ head/sys/dev/gpio/gpioiic.c Sun May 22 03:34:18 2016 (r300391) @@ -53,8 +53,9 @@ __FBSDID("$FreeBSD$"); #include "iicbb_if.h" -#define SCL_PIN_DEFAULT 0 /* default index of SCL pin on gpiobus */ -#define SDA_PIN_DEFAULT 1 +#define GPIOIIC_SCL_DFLT 0 +#define GPIOIIC_SDA_DFLT 1 +#define GPIOIIC_MIN_PINS 2 struct gpioiic_softc { @@ -79,14 +80,24 @@ static int gpioiic_reset(device_t, u_cha static int gpioiic_probe(device_t dev) { + struct gpiobus_ivar *devi; #ifdef FDT + if (!ofw_bus_status_okay(dev)) + return (ENXIO); if (!ofw_bus_is_compatible(dev, "gpioiic")) return (ENXIO); #endif + devi = GPIOBUS_IVAR(dev); + if (devi->npins < GPIOIIC_MIN_PINS) { + device_printf(dev, + "gpioiic needs at least %d GPIO pins (only %d given).\n", + GPIOIIC_MIN_PINS, devi->npins); + return (ENXIO); + } device_set_desc(dev, "GPIO I2C bit-banging driver"); - return (0); + return (BUS_PROBE_DEFAULT); } static int @@ -105,10 +116,10 @@ gpioiic_attach(device_t dev) sc->sc_busdev = device_get_parent(dev); if (resource_int_value(device_get_name(dev), device_get_unit(dev), "scl", &sc->scl_pin)) - sc->scl_pin = SCL_PIN_DEFAULT; + sc->scl_pin = GPIOIIC_SCL_DFLT; if (resource_int_value(device_get_name(dev), device_get_unit(dev), "sda", &sc->sda_pin)) - sc->sda_pin = SDA_PIN_DEFAULT; + sc->sda_pin = GPIOIIC_SDA_DFLT; #ifdef FDT if ((node = ofw_bus_get_node(dev)) == -1) @@ -120,9 +131,9 @@ gpioiic_attach(device_t dev) #endif if (sc->scl_pin < 0 || sc->scl_pin > 1) - sc->scl_pin = SCL_PIN_DEFAULT; + sc->scl_pin = GPIOIIC_SCL_DFLT; if (sc->sda_pin < 0 || sc->sda_pin > 1) - sc->sda_pin = SDA_PIN_DEFAULT; + sc->sda_pin = GPIOIIC_SDA_DFLT; devi = GPIOBUS_IVAR(dev); device_printf(dev, "SCL pin: %d, SDA pin: %d\n",
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605220334.u4M3YIgG008752>