Add a new activity LED config and additional functions to implement a
simple software blink feature to signal activity of any kind.

Usual activity might be a file transfer with TFTP, a flash write...

User of this API will call status_led_activity_start/stop() on each
activity and LED will be toggled based on the defined FREQ config value.

With this enabled, cyclic API are also enabled as this makes use of
cyclic API to handle LED blink.

Signed-off-by: Christian Marangi <ansuels...@gmail.com>
---
 drivers/led/Kconfig       | 16 +++++++++++++++
 drivers/misc/status_led.c | 43 +++++++++++++++++++++++++++++++++++++++
 include/status_led.h      |  2 ++
 3 files changed, 61 insertions(+)

diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig
index 6c4f02d71f2..869ed78e87f 100644
--- a/drivers/led/Kconfig
+++ b/drivers/led/Kconfig
@@ -359,6 +359,22 @@ config LED_STATUS_BOOT
 
 endif # LED_STATUS_BOOT_ENABLE
 
+config LED_STATUS_ACTIVITY_ENABLE
+       bool "Enable BOOT LED"
+       select CYCLIC
+       help
+         Enable to turn an LED on when the board is doing some
+         activity (flash write, file download).
+
+if LED_STATUS_ACTIVITY_ENABLE
+
+config LED_STATUS_ACTIVITY
+       int "LED to light when the board is doing some activity"
+       help
+         Valid enabled LED device number.
+
+endif # LED_STATUS_ACTIVITY_ENABLE
+
 config LED_STATUS_RED_ENABLE
        bool "Enable red LED"
        help
diff --git a/drivers/misc/status_led.c b/drivers/misc/status_led.c
index 7912b4a9448..019096562ca 100644
--- a/drivers/misc/status_led.c
+++ b/drivers/misc/status_led.c
@@ -4,7 +4,10 @@
  * Wolfgang Denk, DENX Software Engineering, w...@denx.de.
  */
 
+#include <cyclic.h>
 #include <status_led.h>
+#include <stdio.h>
+#include <linux/kernel.h>
 #include <linux/types.h>
 
 /*
@@ -23,6 +26,7 @@ typedef struct {
        int state;
        int period;
        int cnt;
+       struct cyclic_info cyclic;
 } led_dev_t;
 
 led_dev_t led_dev[] = {
@@ -142,3 +146,42 @@ void status_led_toggle(int led)
 
        __led_toggle(ld->mask);
 }
+
+static void status_led_activity_toggle(struct cyclic_info *ctx)
+{
+       led_dev_t *ld = container_of(ctx, led_dev_t, cyclic);
+       __led_toggle(ld->mask);
+}
+
+void status_led_activity_start(int led)
+{
+       led_dev_t *ld;
+
+       ld = status_get_led_dev(led);
+       if (!ld)
+               return;
+
+       /* Use status LED state to track if cyclic is already register */
+       if (ld->state == CONFIG_LED_STATUS_BLINKING) {
+               printf("Cyclic for activity status LED %d already registered. 
THIS IS AN ERROR.\n",
+                      led);
+               cyclic_unregister(&ld->cyclic);
+       }
+
+       status_led_set(led, CONFIG_LED_STATUS_BLINKING);
+
+       cyclic_register(&ld->cyclic, status_led_activity_toggle,
+                       ld->period * 500, "activity");
+}
+
+void status_led_activity_stop(int led)
+{
+       led_dev_t *ld;
+
+       ld = status_get_led_dev(led);
+       if (!ld)
+               return;
+
+       cyclic_unregister(&ld->cyclic);
+       status_led_set(led, CONFIG_LED_STATUS_OFF);
+}
diff --git a/include/status_led.h b/include/status_led.h
index fe0c84fb4b4..7de40551621 100644
--- a/include/status_led.h
+++ b/include/status_led.h
@@ -39,6 +39,8 @@ void status_led_init(void);
 void status_led_tick(unsigned long timestamp);
 void status_led_set(int led, int state);
 void status_led_toggle(int led);
+void status_led_activity_start(int led);
+void status_led_activity_stop(int led);
 
 /*****  MVS v1  **********************************************************/
 #if (defined(CONFIG_MVS) && CONFIG_MVS < 2)
-- 
2.43.0

Reply via email to