From 183502af192962b0187d6f2ddc6e6a68b38869d0 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Fri, 26 Oct 2018 18:31:53 -0700 Subject: gpiolib: Introduce gpio_find_by_label() Introduce gpio_find_by_label() in order to allow manipulating GPIOs by the labels assigned to them via DT or board/driver code. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- drivers/gpio/gpiolib.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'drivers/gpio') diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 982bec0b69..4c7aee4a0b 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -91,6 +91,23 @@ done: return ret; } +int gpio_find_by_label(const char *label) +{ + int i; + + for (i = 0; i < ARCH_NR_GPIOS; i++) { + struct gpio_info *info = &gpio_desc[i]; + + if (!info->requested || !info->chip || !info->label) + continue; + + if (!strcmp(info->label, label)) + return i; + } + + return -ENOENT; +} + void gpio_free(unsigned gpio) { struct gpio_info *gi = gpio_to_desc(gpio); -- cgit v1.2.3