[PATCH 4/7] led: status_led: add new activity LED config and functions

neil.armstrong at linaro.org neil.armstrong at linaro.org
Thu Jun 6 10:56:50 CEST 2024


On 05/06/2024 21:21, Christian Marangi wrote:
> 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...
> 
> Driver will call status_led_activity on each activity and LED will be
> toggled based on the defined FREQ config value.
> 
> Signed-off-by: Christian Marangi <ansuelsmth at gmail.com>
> ---
>   drivers/led/Kconfig       | 15 +++++++++++++++
>   drivers/misc/status_led.c | 25 ++++++++++++++++++++-----
>   include/status_led.h      |  1 +
>   3 files changed, 36 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig
> index 6c4f02d71f2..8eaa74bdd27 100644
> --- a/drivers/led/Kconfig
> +++ b/drivers/led/Kconfig
> @@ -359,6 +359,21 @@ config LED_STATUS_BOOT
>   
>   endif # LED_STATUS_BOOT_ENABLE
>   
> +config LED_STATUS_ACTIVITY_ENABLE
> +	bool "Enable BOOT LED"
> +	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.

I would add multiple entries here, like:
LED_STATUS_ACTIVITY_STORAGE
LED_STATUS_ACTIVITY_NETWORK
...

so we can enable either ones and specify different
leds for each applications.

Neil

> +
> +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 93bfb410662..9490e1d7341 100644
> --- a/drivers/misc/status_led.c
> +++ b/drivers/misc/status_led.c
> @@ -82,6 +82,14 @@ void status_led_init(void)
>   	status_led_init_done = 1;
>   }
>   
> +static void status_led_sw_blink(led_dev_t *ld)
> +{
> +	if (++ld->cnt >= ld->period) {
> +		__led_toggle(ld->mask);
> +		ld->cnt -= ld->period;
> +	}
> +}
> +
>   void status_led_tick(ulong timestamp)
>   {
>   	led_dev_t *ld;
> @@ -95,11 +103,7 @@ void status_led_tick(ulong timestamp)
>   		if (ld->state != CONFIG_LED_STATUS_BLINKING)
>   			continue;
>   
> -		if (++ld->cnt >= ld->period) {
> -			__led_toggle (ld->mask);
> -			ld->cnt -= ld->period;
> -		}
> -
> +		status_led_sw_blink(ld);
>   	}
>   }
>   
> @@ -140,3 +144,14 @@ void status_led_toggle(int led)
>   
>   	__led_toggle(ld->mask);
>   }
> +
> +void status_led_activity(int led)
> +{
> +	led_dev_t *ld;
> +
> +	ld = status_get_led_dev(led);
> +	if (!ld)
> +		return;
> +
> +	status_led_sw_blink(ld);
> +}
> diff --git a/include/status_led.h b/include/status_led.h
> index fe0c84fb4b4..037bad159c2 100644
> --- a/include/status_led.h
> +++ b/include/status_led.h
> @@ -39,6 +39,7 @@ 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(int led);
>   
>   /*****  MVS v1  **********************************************************/
>   #if (defined(CONFIG_MVS) && CONFIG_MVS < 2)



More information about the U-Boot mailing list