svn commit: r300391 - head/sys/dev/gpio

Luiz Otavio O Souza loos at FreeBSD.org
Sun May 22 03:34:20 UTC 2016


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",


More information about the svn-src-all mailing list