]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
led: introduce led_bind_generic()
authorRasmus Villemoes <rasmus.villemoes@prevas.dk>
Fri, 17 Nov 2023 11:38:08 +0000 (12:38 +0100)
committerTom Rini <trini@konsulko.com>
Wed, 13 Dec 2023 16:35:13 +0000 (11:35 -0500)
All existing drivers in drivers/led/ contain a .bind method that does
exactly the same thing, with just the actual driver name
differing. Create a helper so all those individual methods can be
changed to one-liners.

Reviewed-by: Marek Vasut <marex@denx.de>
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
drivers/led/led-uclass.c
include/led.h

index 0232fa84def370396720ede2867fc599973bf7a1..a4be56fc258443802fbf0ef4158890615ec20355 100644 (file)
 #include <errno.h>
 #include <led.h>
 #include <dm/device-internal.h>
+#include <dm/lists.h>
 #include <dm/root.h>
 #include <dm/uclass-internal.h>
 
+int led_bind_generic(struct udevice *parent, const char *driver_name)
+{
+       struct udevice *dev;
+       ofnode node;
+       int ret;
+
+       dev_for_each_subnode(node, parent) {
+               ret = device_bind_driver_to_node(parent, driver_name,
+                                                ofnode_get_name(node),
+                                                node, &dev);
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
+}
+
 int led_get_by_label(const char *label, struct udevice **devp)
 {
        struct udevice *dev;
index 329041008c1adb13e862635f428fcbb9cc18a3bd..a6353166289d294c416332ffc98faab9e7ee5343 100644 (file)
@@ -110,4 +110,12 @@ enum led_state_t led_get_state(struct udevice *dev);
  */
 int led_set_period(struct udevice *dev, int period_ms);
 
+/**
+ * led_bind_generic() - bind children of parent to given driver
+ *
+ * @parent:      Top-level LED device
+ * @driver_name: Driver for handling individual child nodes
+ */
+int led_bind_generic(struct udevice *parent, const char *driver_name);
+
 #endif