diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2021-06-08 11:36:32 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2021-06-09 13:35:14 +0200 |
commit | 371a4d9af3bddbb17533aa7c8a623a4be93eacb8 (patch) | |
tree | 0513dc074fa8ee956a676d3c80a6f5fd3189e3c3 /drivers | |
parent | 7689055a8b037363dae840eee33a0ed43f905b7a (diff) | |
download | barebox-371a4d9af3bddbb17533aa7c8a623a4be93eacb8.tar.gz barebox-371a4d9af3bddbb17533aa7c8a623a4be93eacb8.tar.xz |
gpio: allow -gpio suffix for gpio property names
GPIO properties in the device tree can have a -gpios suffix or a -gpio
suffix. The latter was not handled, this patch changes that.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Link: https://lore.barebox.org/20210608093635.5749-2-s.hauer@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-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; |