qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v3 2/7] gpiolib: Add support for gpiochipN-based table lookup


From: Geert Uytterhoeven
Subject: [PATCH v3 2/7] gpiolib: Add support for gpiochipN-based table lookup
Date: Wed, 27 Nov 2019 09:42:48 +0100

Currently GPIO controllers can only be referred to by label in GPIO
lookup tables.

Add support for looking them up by "gpiochipN" name, with "N" either the
corresponding GPIO device's ID number, or the GPIO controller's first
GPIO number.

Signed-off-by: Geert Uytterhoeven <address@hidden>
---
If this is rejected, the GPIO Aggregator documentation must be updated.

The second variant is currently used by the legacy sysfs interface only,
so perhaps the chip->base check should be dropped?

v3:
  - New.
---
 drivers/gpio/gpiolib.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index c9e47620d2434983..d24a3d79dcfe69ad 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1746,9 +1746,29 @@ static int gpiochip_match_name(struct gpio_chip *chip, 
void *data)
        return !strcmp(chip->label, name);
 }
 
+static int gpiochip_match_id(struct gpio_chip *chip, void *data)
+{
+       int id = (uintptr_t)data;
+
+       return id == chip->base || id == chip->gpiodev->id;
+}
+
 static struct gpio_chip *find_chip_by_name(const char *name)
 {
-       return gpiochip_find((void *)name, gpiochip_match_name);
+       struct gpio_chip *chip;
+       int id;
+
+       chip = gpiochip_find((void *)name, gpiochip_match_name);
+       if (chip)
+               return chip;
+
+       if (!str_has_prefix(name, GPIOCHIP_NAME))
+               return NULL;
+
+       if (kstrtoint(name + strlen(GPIOCHIP_NAME), 10, &id))
+               return NULL;
+
+       return gpiochip_find((void *)(uintptr_t)id, gpiochip_match_id);
 }
 
 #ifdef CONFIG_GPIOLIB_IRQCHIP
-- 
2.17.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]