Skip to contentSkip to conversation

gpiolib: use platform GPIO mappings as fallback

PATCH In review Alexandre Courbot 2 participants 3 messages Nov 23, 2013 – Nov 29, 2013 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpiolib: use platform GPIO mappings as fallback

For platforms that use device tree or ACPI as the standard way to look GPIOs up, allow the platform-defined GPIO mappings to be used as a fallback. This may be useful for platforms that need extra GPIOs mappings not defined by the firmware.

---
 drivers/gpio/gpiolib.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/gpio/gpiolib.c +13 -3
index 86caf17..4edd68c 100644
@@ -2417,7 +2417,7 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
 					       const char *con_id,
 					       unsigned int idx)
 {
-	struct gpio_desc *desc;
+	struct gpio_desc *desc = NULL;
 	int status;
 	enum gpio_lookup_flags flags = 0;
 
@@ -2430,9 +2430,19 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
 	} else if (IS_ENABLED(CONFIG_ACPI) && dev && ACPI_HANDLE(dev)) {
 		dev_dbg(dev, "using ACPI for GPIO lookup\n");
 		desc = acpi_find_gpio(dev, con_id, idx, &flags);
-	} else {
+	}
+
+	/*
+	 * Either we are not using DT or ACPI, or their lookup did not return
+	 * a result. In that case, use platform lookup as a fallback.
+	 */
+	if (!desc || IS_ERR(desc)) {
+		struct gpio_desc *pdesc;
 		dev_dbg(dev, "using lookup tables for GPIO lookup");
-		desc = gpiod_find(dev, con_id, idx, &flags);
+		pdesc = gpiod_find(dev, con_id, idx, &flags);
+		/* If used as fallback, do not replace the previous error */
+		if (!IS_ERR(pdesc) || !desc)
+			desc = pdesc;
 	}
 
 	if (IS_ERR(desc)) {
Signature · 1 line
1.8.4.2
#1 lore raw
Quoted 6 lines · Alexandre Courbot

For platforms that use device tree or ACPI as the standard way to look GPIOs up, allow the platform-defined GPIO mappings to be used as a fallback. This may be useful for platforms that need extra GPIOs mappings not defined by the firmware.

Applied for fixes. I was considering applying it for the next kernel but it depends on the former patches and we should expect a bit of extra fuzz now with the new API.

Yours,
Linus Walleij

#2 lore raw
Quoted 7 lines · Linus Walleij
Quoted 5 lines · Alexandre Courbot

For platforms that use device tree or ACPI as the standard way to look GPIOs up, allow the platform-defined GPIO mappings to be used as a fallback. This may be useful for platforms that need extra GPIOs mappings not defined by the firmware.

Quoted 5 lines
Quoted 1 line

Applied for fixes. I was considering applying it for the next kernel but it depends on the former patches and we should expect a bit of extra fuzz now with the new API.

Thanks - I'd rather have all the problems coming in a row than incrementally as we introduce potentially incompatible changes.

Alex.