[PATCH v3 3/9] led: implement LED boot API

Simon Glass sjg at chromium.org
Thu Sep 19 16:14:05 CEST 2024


Hi Christian,

On Mon, 12 Aug 2024 at 12:33, Christian Marangi <ansuelsmth at gmail.com> wrote:
>
> Implement LED boot API to signal correct boot of the system.
>
> led_boot_on/off/blink() are introduced to turn ON, OFF and BLINK the
> designated boot LED.
>
> New Kconfig are introduced, CONFIG_LED_BOOT_ENABLE to enable the feature.
> This makes use of the /config property "u-boot,boot-led" to the define
> the boot LED.
> It's also introduced a new /config property "u-boot,boot-led-period" to
> define the default period when the LED is set to blink mode.
>
> If "u-boot,boot-led-period" is not defined, the value of 250 (ms) is
> used by default.
>
> If CONFIG_LED_BLINK or CONFIG_LED_SW_BLINK is not enabled,
> led_boot_blink call will fallback to simple LED ON.
>
> Signed-off-by: Christian Marangi <ansuelsmth at gmail.com>
> ---
>  doc/device-tree-bindings/config.txt |  3 ++
>  drivers/led/Kconfig                 | 20 +++++++++
>  include/led.h                       | 64 +++++++++++++++++++++++++++++
>  3 files changed, 87 insertions(+)
>
> diff --git a/doc/device-tree-bindings/config.txt b/doc/device-tree-bindings/config.txt
> index f50c68bbdc3..68edd177040 100644
> --- a/doc/device-tree-bindings/config.txt
> +++ b/doc/device-tree-bindings/config.txt
> @@ -31,6 +31,9 @@ u-boot,error-led (string)
>         This is used to specify the label for an LED to indicate an error and
>         a successful boot, on supported hardware.
>
> +u-boot,boot-led-period (int)
> +       This is used to specify the default period for an LED in blink mode.
> +

I'm sorry to say that this is out-of-date.

The new schema is in options/ and is documented at dtschema:

dtschema/schemas/options/u-boot.yaml

You should add new things there. If you have time, it would be great
if you could send bindings for the things in config.txt

>  bootsecure (int)
>         Indicates that U-Boot should use secure_boot_cmd() to run commands,
>         rather than the normal CLI. This can be used in production images, to
> diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig
> index bee74b25751..fd9442edaf3 100644
> --- a/drivers/led/Kconfig
> +++ b/drivers/led/Kconfig
> @@ -9,6 +9,26 @@ config LED
>           can provide access to board-specific LEDs. Use of the device tree
>           for configuration is encouraged.
>
> +config LED_BOOT_ENABLE
> +       bool "Enable LED boot support"
> +       help
> +         Enable LED boot support.
> +
> +         LED boot is a specific LED assigned to signal boot operation status.
> +
> +config LED_BOOT_LABEL
> +       string "LED boot label"
> +       depends on LED_BOOT_ENABLE
> +       help
> +         LED label defined in DT to assign for LED boot usage.
> +
> +config LED_BOOT_PERIOD
> +       int "LED boot period"
> +       depends on LED_BOOT_ENABLE && (LED_BLINK || LED_SW_BLINK)
> +       default 2

Should that be 2000? It is a very fast blink if it is 2ms

> +       help
> +         LED boot blink period in ms.
> +
>  config LED_BCM6328
>         bool "LED Support for BCM6328"
>         depends on LED && ARCH_BMIPS
> diff --git a/include/led.h b/include/led.h
> index c1f3380f253..2d3b89674e2 100644
> --- a/include/led.h
> +++ b/include/led.h
> @@ -9,6 +9,7 @@
>
>  #include <stdbool.h>
>  #include <cyclic.h>
> +#include <dm/ofnode.h>
>
>  struct udevice;
>
> @@ -159,4 +160,67 @@ int led_sw_set_period(struct udevice *dev, int period_ms);
>  bool led_sw_is_blinking(struct udevice *dev);
>  bool led_sw_on_state_change(struct udevice *dev, enum led_state_t state);
>
> +#ifdef CONFIG_LED_BOOT_ENABLE
> +
> +/**
> + * led_boot_on() - turn ON the designated LED for booting
> + *
> + * Return: 0 if OK, -ve on error
> + */
> +static inline int led_boot_on(void)

I wonder why these are inline functions?

You should be able to put this code in the C file, with an #ifdef in
the header to create an empty, static-inline function if needed.

> +{
> +       const char *led_name;
> +
> +       led_name = ofnode_conf_read_str("u-boot,boot-led");
> +       if (!led_name)
> +               return -ENOENT;
> +
> +       return led_set_state_by_label(led_name, LEDST_ON);
> +}
> +
> +/**
> + * led_boot_off() - turn OFF the designated LED for booting
> + *
> + * Return: 0 if OK, -ve on error
> + */
> +static inline int led_boot_off(void)
> +{
> +       const char *led_name;
> +
> +       led_name = ofnode_conf_read_str("u-boot,boot-led");
> +       if (!led_name)
> +               return -ENOENT;
> +
> +       return led_set_state_by_label(CONFIG_LED_BOOT_LABEL, LEDST_OFF);
> +}
> +
> +#if defined(CONFIG_LED_BLINK) || defined(CONFIG_LED_SW_BLINK)
> +/**
> + * led_boot_blink() - turn ON the designated LED for booting
> + *
> + * Return: 0 if OK, -ve on error
> + */
> +static inline int led_boot_blink(void)
> +{
> +       const char *led_name;
> +       int led_period, ret;
> +
> +       led_name = ofnode_conf_read_str("u-boot,boot-led");
> +       if (!led_name)
> +               return -ENOENT;
> +
> +       led_period = ofnode_conf_read_int("u-boot,boot-led-period", 250);
> +
> +       ret = led_set_period_by_label(led_name, led_period);
> +       if (ret)
> +               return ret;
> +
> +       return led_set_state_by_label(led_name, LEDST_BLINK);
> +}
> +#else
> +/* If LED BLINK is not supported/enabled, fallback to LED ON */
> +#define led_boot_blink led_boot_on
> +#endif
> +#endif
> +
>  #endif
> --
> 2.45.2
>

Regards,
Simon


More information about the U-Boot mailing list