[PATCH] gpio: Add support for gpio-line-names reading

Michal Simek michal.simek at xilinx.com
Tue Jul 21 15:14:56 CEST 2020


The commit 2bd261dd1712 ("gpio: search for gpio label if gpio is not found
through bank name") introduced the option to search gpio via labels (gpio
hog). This patch is just follow up on this and fills pin name based on
gpio-line-names DT property.

Signed-off-by: Michal Simek <michal.simek at xilinx.com>
---

 arch/sandbox/dts/test.dts  |  2 ++
 drivers/gpio/gpio-uclass.c | 31 +++++++++++++++++++++++++++++++
 test/dm/gpio.c             |  6 ++++++
 3 files changed, 39 insertions(+)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 3744a4660300..1b33cd4c0878 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -388,6 +388,8 @@
 			#gpio-cells = <2>;
 			gpio-bank-name = "c";
 			sandbox,gpio-count = <10>;
+			gpio-line-names = "ZERO", "ONE", "TWO", "THREE", "FOUR",
+					  "FIVE", "SIX", "SEVEL", "EIGHT", "";
 		};
 	};
 
diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 9c53299b6a3b..430c6849f4cd 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -1177,6 +1177,37 @@ static int gpio_post_probe(struct udevice *dev)
 	if (!uc_priv->name)
 		return -ENOMEM;
 
+	if (IS_ENABLED(CONFIG_DM_GPIO_LOOKUP_LABEL) &&
+	    dev_read_string(dev, "gpio-line-names")) {
+		int i, ret, count;
+		const char *name;
+		char *str;
+
+		count = dev_read_string_count(dev, "gpio-line-names");
+
+		if (count != uc_priv->gpio_count) {
+			printf("Incorrect gpio-line-names count %d/%d\n",
+			       count, uc_priv->gpio_count);
+			return -EINVAL;
+		}
+
+		for (i = 0; i < uc_priv->gpio_count; i++) {
+			ret = dev_read_string_index(dev, "gpio-line-names", i,
+						    &name);
+			if (ret)
+				return ret;
+
+			if (strlen(name)) {
+				str = strdup(name);
+				if (!str)
+					return -ENOMEM;
+
+				/* All the time there is pointer to name in DT */
+				uc_priv->name[i] = (char *)str;
+			}
+		}
+	}
+
 	return gpio_renumber(NULL);
 }
 
diff --git a/test/dm/gpio.c b/test/dm/gpio.c
index 29701389fcd5..623a157ff1db 100644
--- a/test/dm/gpio.c
+++ b/test/dm/gpio.c
@@ -142,6 +142,12 @@ static int dm_test_gpio(struct unit_test_state *uts)
 	ut_assert(gpio_lookup_name("hog_not_exist", &dev, &offset,
 				   &gpio));
 
+	/* Check if lookup for names filled via gpio-line-names work */
+	ut_assertok(gpio_lookup_name("EIGHT", &dev, &offset, &gpio));
+	ut_asserteq_str(dev->name, "pinmux-gpios");
+	ut_asserteq(8, offset);
+	ut_asserteq(CONFIG_SANDBOX_GPIO_COUNT + 20 + 10 + 8, gpio);
+
 	return 0;
 }
 DM_TEST(dm_test_gpio, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
-- 
2.27.0



More information about the U-Boot mailing list