[PATCH 2/9] led: implement led_set_state/paeriod_by_label
Christian Marangi
ansuelsmth at gmail.com
Mon Jun 24 23:46:12 CEST 2024
Introduce new API led_set_state/period_by label as a shorthand to set
LED state and LED blink period by referencing them by label.
This is needed for the upcoming additional API that will declare LED in
.confg and reference them by their LED label name.
Signed-off-by: Christian Marangi <ansuelsmth at gmail.com>
---
drivers/led/led-uclass.c | 28 ++++++++++++++++++++++++++++
include/led.h | 18 ++++++++++++++++++
2 files changed, 46 insertions(+)
diff --git a/drivers/led/led-uclass.c b/drivers/led/led-uclass.c
index f37bf6a1550..d1e9916bb33 100644
--- a/drivers/led/led-uclass.c
+++ b/drivers/led/led-uclass.c
@@ -61,6 +61,20 @@ int led_set_state(struct udevice *dev, enum led_state_t state)
return ops->set_state(dev, state);
}
+int led_set_state_by_label(const char *label, enum led_state_t state)
+{
+ struct udevice *dev;
+ int ret;
+
+ ret = led_get_by_label(label, &dev);
+ if (ret) {
+ printf("Failed to get LED by label %s\n", label);
+ return ret;
+ }
+
+ return led_set_state(dev, state);
+}
+
enum led_state_t led_get_state(struct udevice *dev)
{
struct led_ops *ops = led_get_ops(dev);
@@ -81,6 +95,20 @@ int led_set_period(struct udevice *dev, int period_ms)
return ops->set_period(dev, period_ms);
}
+
+int led_set_period_by_label(const char *label, int period_ms)
+{
+ struct udevice *dev;
+ int ret;
+
+ ret = led_get_by_label(label, &dev);
+ if (ret) {
+ printf("Failed to get LED by label %s\n", label);
+ return ret;
+ }
+
+ return led_set_period(dev, period_ms);
+}
#endif
static int led_post_bind(struct udevice *dev)
diff --git a/include/led.h b/include/led.h
index a6353166289..71dd7a28d93 100644
--- a/include/led.h
+++ b/include/led.h
@@ -93,6 +93,15 @@ int led_get_by_label(const char *label, struct udevice **devp);
*/
int led_set_state(struct udevice *dev, enum led_state_t state);
+/**
+ * led_set_state_by_label - set the state of an LED referenced by Label
+ *
+ * @label: LED label
+ * @state: LED state to set
+ * Return: 0 if OK, -ve on error
+ */
+int led_set_state_by_label(const char *label, enum led_state_t state);
+
/**
* led_get_state() - get the state of an LED
*
@@ -110,6 +119,15 @@ enum led_state_t led_get_state(struct udevice *dev);
*/
int led_set_period(struct udevice *dev, int period_ms);
+/**
+ * led_set_period_by_label - set the blink period of an LED referenced by Label
+ *
+ * @label: LED label
+ * @period_ms: LED blink period in milliseconds
+ * Return: 0 if OK, -ve on error
+ */
+int led_set_period_by_label(const char *label, int period_ms);
+
/**
* led_bind_generic() - bind children of parent to given driver
*
--
2.45.1
More information about the U-Boot
mailing list