diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2021-06-16 10:54:37 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2021-06-16 10:54:37 +0200 |
commit | 226938796e525f42e002769f21dc66d16ac26f9b (patch) | |
tree | d7ef539c99a0da2885c65bdb0885f5570405eb27 /drivers/gpio | |
parent | 0e062b8296a22afff4157f56c5b6b64e7fac5aac (diff) | |
parent | e148f954c3eb025075f0cbf69eab1f3f62459b83 (diff) | |
download | barebox-226938796e525f42e002769f21dc66d16ac26f9b.tar.gz |
Merge branch 'for-next/net'
Diffstat (limited to 'drivers/gpio')
-rw-r--r-- | drivers/gpio/gpiolib.c | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 7b7261d01f..387b410f12 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -555,27 +555,39 @@ static int of_gpiochip_scan_hogs(struct gpio_chip *chip) return 0; } +static const char *gpio_suffixes[] = { + "gpios", + "gpio", +}; + /* Linux compatibility helper: Get a GPIO descriptor from device tree */ int gpiod_get(struct device_d *dev, const char *_con_id, enum gpiod_flags flags) { struct device_node *np = dev->device_node; enum of_gpio_flags of_flags; - const char *con_id = "gpios", *label = dev_name(dev); - char *buf = NULL; + const char *label = dev_name(dev); + char *buf = NULL, *con_id; int gpio; - int ret; + int ret, i; if (!IS_ENABLED(CONFIG_OFDEVICE) || !dev->device_node) return -ENODEV; - if (_con_id) { - con_id = buf = basprintf("%s-gpios", _con_id); - if (!buf) + for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) { + if (_con_id) + con_id = basprintf("%s-%s", _con_id, gpio_suffixes[i]); + else + con_id = basprintf("%s", gpio_suffixes[i]); + + if (!con_id) return -ENOMEM; - } - gpio = of_get_named_gpio_flags(np, con_id, 0, &of_flags); - free(buf); + gpio = of_get_named_gpio_flags(np, con_id, 0, &of_flags); + free(con_id); + + if (gpio_is_valid(gpio)) + break; + } if (!gpio_is_valid(gpio)) return gpio < 0 ? gpio : -EINVAL; |