From: Rasmus Villemoes Date: Fri, 17 Nov 2023 11:38:08 +0000 (+0100) Subject: led: introduce led_bind_generic() X-Git-Url: http://git.dujemihanovic.xyz/?a=commitdiff_plain;h=3bf0515a07f7e82f2cdbf435bfd7fcd66651852d;p=u-boot.git led: introduce led_bind_generic() 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 Signed-off-by: Rasmus Villemoes --- diff --git a/drivers/led/led-uclass.c b/drivers/led/led-uclass.c index 0232fa84de..a4be56fc25 100644 --- a/drivers/led/led-uclass.c +++ b/drivers/led/led-uclass.c @@ -11,9 +11,27 @@ #include #include #include +#include #include #include +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; diff --git a/include/led.h b/include/led.h index 329041008c..a635316628 100644 --- a/include/led.h +++ b/include/led.h @@ -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