LED

Generic LED API provided when a supported compatible is defined in DeviceTree.

To enable support for LEDs, enable the CONFIG_LED Kconfig option.

The most common implementation is for GPIO-connected LEDs. If using GPIO-connected LEDs, enable the LED_GPIO Kconfig option.

LED_BLINK support requires LED driver support and is therefore optional. If LED blink functionality is needed, enable the LED_BLINK Kconfig option. If LED driver doesn’t support HW Blink, SW Blink can be used with the Cyclic framework by enabling the CONFIG_LED_SW_BLINK.

Boot and Activity LEDs are also supported. These LEDs can signal various system operations during runtime, such as boot initialization, file transfers, and flash write/erase operations.

To enable a Boot LED, enable CONFIG_LED_BOOT and define in /options/u-boot root node the property boot-led. This will enable the specified LED to blink and turn ON when the bootloader initializes correctly.

To enable an Activity LED, enable CONFIG_LED_ACTIVITY and define in /options/u-boot root node the property activity-led. This will enable the specified LED to blink and turn ON during file transfers or flash write/erase operations.

Both Boot and Activity LEDs provide a simple API to turn the LED ON or OFF: led_boot_on(), led_boot_off(), led_activity_on(), and led_activity_off().

Both configurations can optionally define a boot/activity-led-period property if CONFIG_LED_BLINK or CONFIG_LED_SW_BLINK is enabled for LED blink operations, which is usually used by the Activity LED. If not defined the default value of 250 (ms) is used.

When CONFIG_LED_BLINK or CONFIG_LED_SW_BLINK is enabled, additional APIs are exposed: led_boot_blink() and led_activity_blink(). Note that if CONFIG_LED_BLINK or CONFIG_LED_SW_BLINK is disabled, these APIs will behave like the led_boot_on() and led_activity_on() APIs, respectively.

struct led_uc_plat

Platform data the uclass stores about each device

Definition

struct led_uc_plat {
  const char *label;
  enum led_state_t default_state;
  char name[LED_MAX_NAME_SIZE];
#ifdef CONFIG_LED_SW_BLINK;
  struct led_sw_blink *sw_blink;
#endif;
};

Members

label

LED label

default_state

LED default state

name

LED name, derived from function, color or function-enumerator property.

sw_blink

LED software blink struct

struct led_uc_priv

Private data the uclass stores about each device

Definition

struct led_uc_priv {
#ifdef CONFIG_LED_BOOT;
  const char *boot_led_label;
  int boot_led_period;
#endif;
#ifdef CONFIG_LED_ACTIVITY;
  const char *activity_led_label;
  int activity_led_period;
#endif;
};

Members

boot_led_label

Boot LED label

boot_led_period

Boot LED blink period

activity_led_label

Activity LED label

activity_led_period

Activity LED blink period

int led_get_by_label(const char *label, struct udevice **devp)

Find an LED device by label

Parameters

const char *label

LED label to look up

struct udevice **devp

Returns the associated device, if found

Return

0 if found, -ENODEV if not found, other -ve on error

int led_set_state(struct udevice *dev, enum led_state_t state)

set the state of an LED

Parameters

struct udevice *dev

LED device to change

enum led_state_t state

LED state to set

Return

0 if OK, -ve on error

enum led_state_t led_get_state(struct udevice *dev)

get the state of an LED

Parameters

struct udevice *dev

LED device to change

Return

LED state led_state_t, or -ve on error

int led_set_period(struct udevice *dev, int period_ms)

set the blink period of an LED

Parameters

struct udevice *dev

LED device to change

int period_ms

LED blink period in milliseconds

Return

0 if OK, -ve on error

int led_bind_generic(struct udevice *parent, const char *driver_name)

bind children of parent to given driver

Parameters

struct udevice *parent

Top-level LED device

const char *driver_name

Driver for handling individual child nodes

int led_boot_on(void)

turn ON the designated LED for booting

Parameters

void

no arguments

Return

0 if OK, -ve on error

int led_boot_off(void)

turn OFF the designated LED for booting

Parameters

void

no arguments

Return

0 if OK, -ve on error

turn ON the designated LED for booting

Parameters

void

no arguments

Return

0 if OK, -ve on error

int led_activity_on(void)

turn ON the designated LED for activity

Parameters

void

no arguments

Return

0 if OK, -ve on error

int led_activity_off(void)

turn OFF the designated LED for activity

Parameters

void

no arguments

Return

0 if OK, -ve on error

turn ON the designated LED for activity

Parameters

void

no arguments

Return

0 if OK, -ve on error

Legacy LED

Please use the new LED API as defined above. This section is only for reference for currently supported devices and to aid for migration to the new API.

Status LED

This README describes the status LED API.

The API is defined by the include file include/status_led.h

The first step is to enable CONFIG_LED_STATUS in menuconfig:

> Device Drivers > LED Support.

If the LED support is only for specific board, enable CONFIG_LED_STATUS_BOARD_SPECIFIC in the menuconfig.

Status LEDS 0 to 5 are enabled by the following configurations at menuconfig: CONFIG_STATUS_LED0, CONFIG_STATUS_LED1, … CONFIG_STATUS_LED5

The following should be configured for each of the enabled LEDs:

  • CONFIG_STATUS_LED_BIT<n>

  • CONFIG_STATUS_LED_STATE<n>

  • CONFIG_STATUS_LED_FREQ<n>

Where <n> is an integer 1 through 5 (empty for 0).

CONFIG_STATUS_LED_BIT is passed into the __led_* functions to identify which LED is being acted on. As such, the value choose must be unique with respect to the other CONFIG_STATUS_LED_BIT’s. Mapping the value to a physical LED is the reponsiblity of the __led_* function.

CONFIG_STATUS_LED_STATE is the initial state of the LED. It should be set to one of these values: CONFIG_LED_STATUS_OFF or CONFIG_LED_STATUS_ON.

CONFIG_STATUS_LED_FREQ determines the LED blink frequency. Values range from 2 to 10.

Some other LED macros

CONFIG_STATUS_LED_BOOT is the LED to light when the board is booting. This must be a valid LED number (0-5).

General LED functions

The following functions should be defined:

__led_init is called once to initialize the LED to CONFIG_STATUS_LED_STATE. One time start up code should be placed here.

__led_set is called to change the state of the LED.

__led_toggle is called to toggle the current state of the LED.

TBD : Describe older board dependent macros similar to what is done for

TBD : Describe general support via asm/status_led.h