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.
This commit is contained in:
loos 2016-05-22 03:34:18 +00:00
parent 1be9be98e9
commit 78a7a5312b

View File

@ -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_char, u_char, u_char *);
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",