Pinctrl nodes adhering to the generic pinctrl bindings may contain
properties like input-low/input-high, which require pinctrl_ops.set_state
to have a handle on the relevant gpio chip.

Currently this would lead to code duplication: Both the pinctrl driver
and gpiolib will need to store a list of registered gpiochips.

Avoid this by providing a helper to query the registered gpio_chip
given a gpio's number.

Signed-off-by: Ahmad Fatoum <[email protected]>
---
 drivers/gpio/gpiolib.c | 7 +++++++
 include/gpio.h         | 1 +
 2 files changed, 8 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 4c7aee4a0b19..f96009896a41 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -475,6 +475,13 @@ int gpio_get_num(struct device_d *dev, int gpio)
        return -EPROBE_DEFER;
 }
 
+struct gpio_chip *gpio_get_chip(int gpio)
+{
+       struct gpio_info *gi = gpio_to_desc(gpio);
+
+       return gi ? gi->chip : NULL;
+}
+
 #ifdef CONFIG_CMD_GPIO
 static int do_gpiolib(int argc, char *argv[])
 {
diff --git a/include/gpio.h b/include/gpio.h
index 38d6ba2df913..e822fd53475d 100644
--- a/include/gpio.h
+++ b/include/gpio.h
@@ -153,5 +153,6 @@ int gpiochip_add(struct gpio_chip *chip);
 void gpiochip_remove(struct gpio_chip *chip);
 
 int gpio_get_num(struct device_d *dev, int gpio);
+struct gpio_chip *gpio_get_chip(int gpio);
 
 #endif /* __GPIO_H */
-- 
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Reply via email to