gpiolib: Introduce gpiochip_node_count() helper
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Fri, 1 Apr 2022 10:35:53 +0000 (13:35 +0300)
committerAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Fri, 8 Apr 2022 12:54:54 +0000 (15:54 +0300)
The gpiochip_node_count() helper iterates over the device child nodes that
have the "gpio-controller" property set. It returns the number of such nodes
under a given device.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Bartosz Golaszewski <brgl@bgdev.pl>
include/linux/gpio/driver.h

index bfc91f1..12de0b2 100644 (file)
@@ -755,4 +755,15 @@ static inline void gpiochip_unlock_as_irq(struct gpio_chip *gc,
        device_for_each_child_node(dev, child)                                  \
                if (!fwnode_property_present(child, "gpio-controller")) {} else
 
+static inline unsigned int gpiochip_node_count(struct device *dev)
+{
+       struct fwnode_handle *child;
+       unsigned int count = 0;
+
+       for_each_gpiochip_node(dev, child)
+               count++;
+
+       return count;
+}
+
 #endif /* __LINUX_GPIO_DRIVER_H */