[U-Boot] [PATCH v2 01/15] dm: gpio: Support numbered GPIOs

Simon Glass sjg at chromium.org
Thu Oct 23 05:37:01 CEST 2014


At present banks must be named and it is not possible to refer to GPIOs by
number in driver model. Some boards use numbering - e.g. OMAP. It is fairly
easy to support by detecting the absense of a bank name (which starts with
a letter).

Add support for numbered GPIOs in addition to the existing bank support.

Signed-off-by: Simon Glass <sjg at chromium.org>
Reviewed-by: Tom Rini <trini at ti.com>
---

Changes in v2: None

 drivers/gpio/gpio-uclass.c | 37 +++++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index f1bbc58..a5ffd85 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -8,6 +8,7 @@
 #include <dm.h>
 #include <errno.h>
 #include <asm/gpio.h>
+#include <linux/ctype.h>
 
 /**
  * gpio_to_device() - Convert global GPIO number to device, number
@@ -43,35 +44,47 @@ static int gpio_to_device(unsigned int gpio, struct udevice **devp,
 int gpio_lookup_name(const char *name, struct udevice **devp,
 		     unsigned int *offsetp, unsigned int *gpiop)
 {
-	struct gpio_dev_priv *uc_priv;
+	struct gpio_dev_priv *uc_priv = NULL;
 	struct udevice *dev;
+	ulong offset;
+	int numeric;
 	int ret;
 
 	if (devp)
 		*devp = NULL;
+	numeric = isdigit(*name) ? simple_strtoul(name, NULL, 10) : -1;
 	for (ret = uclass_first_device(UCLASS_GPIO, &dev);
 	     dev;
 	     ret = uclass_next_device(&dev)) {
-		ulong offset;
 		int len;
 
 		uc_priv = dev->uclass_priv;
+		if (numeric != -1) {
+			offset = numeric - uc_priv->gpio_base;
+			/* Allow GPIOs to be numbered from 0 */
+			if (offset >= 0 && offset < uc_priv->gpio_count)
+				break;
+		}
+
 		len = uc_priv->bank_name ? strlen(uc_priv->bank_name) : 0;
 
 		if (!strncasecmp(name, uc_priv->bank_name, len)) {
-			if (strict_strtoul(name + len, 10, &offset))
-				continue;
-			if (devp)
-				*devp = dev;
-			if (offsetp)
-				*offsetp = offset;
-			if (gpiop)
-				*gpiop = uc_priv->gpio_base + offset;
-			return 0;
+			if (!strict_strtoul(name + len, 10, &offset))
+				break;
 		}
 	}
 
-	return ret ? ret : -EINVAL;
+	if (!dev)
+		return ret ? ret : -EINVAL;
+
+	if (devp)
+		*devp = dev;
+	if (offsetp)
+		*offsetp = offset;
+	if (gpiop)
+		*gpiop = uc_priv->gpio_base + offset;
+
+	return 0;
 }
 
 /**
-- 
2.1.0.rc2.206.gedb03e5



More information about the U-Boot mailing list