All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/5] gpiolib: Introduce gpiochip_count() helper
@ 2022-03-25 20:03 ` Andy Shevchenko
  0 siblings, 0 replies; 42+ messages in thread
From: Andy Shevchenko @ 2022-03-25 20:03 UTC (permalink / raw)
  To: Andy Shevchenko, Gregory CLEMENT, Geert Uytterhoeven,
	Fabien Dessenne, Linus Walleij, linux-gpio, linux-arm-kernel,
	linux-amlogic, linux-kernel, linux-renesas-soc, linux-stm32
  Cc: Neil Armstrong, Kevin Hilman, Jerome Brunet, Martin Blumenstingl,
	Andrew Lunn, Sebastian Hesselbarth, Maxime Coquelin,
	Alexandre Torgue, Bartosz Golaszewski

The gpiochip_count() helper iterates over the device child nodes that have
the "gpio-controller" property set. It returns the number of such nodes
under given device.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/linux/gpio/driver.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index 894eab753fdf..52918ef5d288 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -9,6 +9,7 @@
 #include <linux/lockdep.h>
 #include <linux/pinctrl/pinctrl.h>
 #include <linux/pinctrl/pinconf-generic.h>
+#include <linux/property.h>
 #include <linux/types.h>
 
 struct gpio_desc;
@@ -750,4 +751,17 @@ static inline void gpiochip_unlock_as_irq(struct gpio_chip *gc,
 }
 #endif /* CONFIG_GPIOLIB */
 
+static inline unsigned int gpiochip_count(struct device *dev)
+{
+	struct fwnode_handle *child;
+	unsigned int count = 0;
+
+	device_for_each_child_node(dev, child) {
+		if (device_property_read_bool(child, "gpio-controller"))
+			count++;
+	}
+
+	return count;
+}
+
 #endif /* __LINUX_GPIO_DRIVER_H */
-- 
2.35.1


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply related	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2022-03-29 12:30 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-25 20:03 [PATCH v1 1/5] gpiolib: Introduce gpiochip_count() helper Andy Shevchenko
2022-03-25 20:03 ` Andy Shevchenko
2022-03-25 20:03 ` Andy Shevchenko
2022-03-25 20:03 ` [PATCH v1 2/5] pinctrl: stm32: Replace custom code by gpiochip_count() call Andy Shevchenko
2022-03-25 20:03   ` Andy Shevchenko
2022-03-25 20:03   ` Andy Shevchenko
2022-03-29  7:59   ` Fabien DESSENNE
2022-03-29  7:59     ` Fabien DESSENNE
2022-03-29  7:59     ` Fabien DESSENNE
2022-03-29 11:14     ` Andy Shevchenko
2022-03-29 11:14       ` Andy Shevchenko
2022-03-29 11:14       ` Andy Shevchenko
2022-03-29 12:07   ` Fabien DESSENNE
2022-03-29 12:07     ` Fabien DESSENNE
2022-03-29 12:07     ` Fabien DESSENNE
2022-03-29 12:25     ` Andy Shevchenko
2022-03-29 12:25       ` Andy Shevchenko
2022-03-29 12:25       ` Andy Shevchenko
2022-03-25 20:03 ` [PATCH v1 3/5] pinctrl: renesas: " Andy Shevchenko
2022-03-25 20:03   ` Andy Shevchenko
2022-03-25 20:03   ` Andy Shevchenko
2022-03-25 20:03 ` [PATCH v1 4/5] pinctrl: meson: " Andy Shevchenko
2022-03-25 20:03   ` Andy Shevchenko
2022-03-25 20:03   ` Andy Shevchenko
2022-03-29 12:29   ` Neil Armstrong
2022-03-29 12:29     ` Neil Armstrong
2022-03-29 12:29     ` Neil Armstrong
2022-03-25 20:03 ` [PATCH v1 5/5] pinctrl: armada-37xx: " Andy Shevchenko
2022-03-25 20:03   ` Andy Shevchenko
2022-03-25 20:03   ` Andy Shevchenko
2022-03-26  8:41   ` Sergey Shtylyov
2022-03-26  8:41     ` Sergey Shtylyov
2022-03-26  8:41     ` Sergey Shtylyov
2022-03-27 19:58     ` Andy Shevchenko
2022-03-27 19:58       ` Andy Shevchenko
2022-03-27 19:58       ` Andy Shevchenko
2022-03-28  7:35 ` [PATCH v1 1/5] gpiolib: Introduce gpiochip_count() helper Geert Uytterhoeven
2022-03-28  7:35   ` Geert Uytterhoeven
2022-03-28  7:35   ` Geert Uytterhoeven
2022-03-28  9:14   ` Andy Shevchenko
2022-03-28  9:14     ` Andy Shevchenko
2022-03-28  9:14     ` Andy Shevchenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.