summaryrefslogtreecommitdiff
path: root/drivers/gpio
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2023-01-09 16:58:35 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2023-01-10 15:53:29 +0100
commit9fb2fa240d5871088517f104c7aecd6ba85514c4 (patch)
treea5c8b09ce6a31567d2eee1b28c758e104d2aaa76 /drivers/gpio
parent36e96c6d7269490520fc35bc677e65a9e6df1f4f (diff)
downloadbarebox-9fb2fa240d5871088517f104c7aecd6ba85514c4.tar.gz
gpiolib: implement dev_gpiod_get_index
Linux devm_gpiod_get_index is a superset of devm_gpiod_get. We already support gpiod_get to simplify kernel code porting, so reimplement it in terms of a new dev_gpiod_get_index to simplify porting kernel code using that as well. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230109155836.2220277-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/gpiolib.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 773d07c130..4e8244b25f 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -542,17 +542,20 @@ static const char *gpio_suffixes[] = {
"gpio",
};
+#ifdef CONFIG_OFDEVICE
/* Linux compatibility helper: Get a GPIO descriptor from device tree */
-int gpiod_get(struct device *dev, const char *_con_id, enum gpiod_flags flags)
+int dev_gpiod_get_index(struct device *dev,
+ struct device_node *np,
+ const char *_con_id, int index,
+ enum gpiod_flags flags,
+ const char *label)
{
- struct device_node *np = dev->of_node;
enum of_gpio_flags of_flags;
- const char *label = dev_name(dev);
char *buf = NULL, *con_id;
int gpio;
int ret, i;
- if (!IS_ENABLED(CONFIG_OFDEVICE) || !dev->of_node)
+ if (!np)
return -ENODEV;
for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
@@ -564,7 +567,7 @@ int gpiod_get(struct device *dev, const char *_con_id, enum gpiod_flags flags)
if (!con_id)
return -ENOMEM;
- gpio = of_get_named_gpio_flags(np, con_id, 0, &of_flags);
+ gpio = of_get_named_gpio_flags(np, con_id, index, &of_flags);
free(con_id);
if (gpio_is_valid(gpio))
@@ -579,10 +582,11 @@ int gpiod_get(struct device *dev, const char *_con_id, enum gpiod_flags flags)
buf = NULL;
- if (_con_id) {
- label = buf = basprintf("%s-%s", dev_name(dev), _con_id);
- if (!label)
- return -ENOMEM;
+ if (!label) {
+ if (con_id)
+ label = buf = basprintf("%s-%s", dev_name(dev), _con_id);
+ else
+ label = dev_name(dev);
}
ret = gpio_request_one(gpio, flags, label);
@@ -590,6 +594,7 @@ int gpiod_get(struct device *dev, const char *_con_id, enum gpiod_flags flags)
return ret ?: gpio;
}
+#endif
int gpiochip_add(struct gpio_chip *chip)
{