Skip to contentSkip to conversation

led: introduce LED boot and activity function

PATCH Superseded Christian Marangi 4 participants 25 messages Sep 21, 2024 – Sep 29, 2024 Networking

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover led: introduce LED boot and activity function

This series is a reworked version of the previous seried:
misc: introduce STATUS LED activity function

This series port and expand the legacy concept of LED boot from the legacy Status LED API to new LED API.

One thing that many device need is a way to communicate to the user that the device is actually doing something.

This is especially useful for recovery steps where an user (for example) insert an USB drive, keep a button pressed and the device autorecover.

There is currently no way to signal the user externally that the bootloader is processing/recoverying aside from setting a LED on.

A solid LED on is not enough and won't actually signal any kind of progress.
Solution is the good old blinking LED but uboot doesn't suggest (and support) interrupts and almost all the LED are usually GPIO LED that doesn't support HW blink.

Additional Kconfg are also introduced to set the LED boot and activity. Those are referenced by label.

A documentation for old and these new LED API is created.

(world tested with the azure pipeline)

Changes v4:
- Drop led_set_state/period_by_label
- Switch to /options/u-boot
- Rework to cache label and dev in led uclass
- Add multiple patch for additional helper
- Rework patches to limit ifdef in some place
Changes v3:
- Switch to /config property
Changes v2:
- Drop GPIO SW implementation
- Add fix for new LED SW BLINK

Christian Marangi (11):
led: toggle LED on initial SW blink
dm: core: implement ofnode_options helpers
led: implement LED boot API
common: board_r: rework BOOT LED handling
led: implement LED activity API
tftp: implement support for LED activity
mtd: implement support for LED activity
ubi: implement support for LED activity
doc: introduce led.rst documentation
test: dm: Add tests for LED boot and activity
test: dm: Expand ofnode options test with new helper

 arch/sandbox/dts/test.dts  |   5 +
 cmd/mtd.c                  |  11 +++
 cmd/ubi.c                  |  13 ++-
 common/board_r.c           |  28 ++++--
 doc/api/index.rst          |   1 +
 doc/api/led.rst            |  10 ++
 drivers/core/ofnode.c      |  33 +++++++
 drivers/led/Kconfig        |  15 +++
 drivers/led/led-uclass.c   | 188 +++++++++++++++++++++++++++++++++++++
 drivers/led/led_sw_blink.c |  10 +-
 include/dm/ofnode.h        |  41 ++++++++
 include/led.h              | 149 ++++++++++++++++++++++++++++-
 include/status_led.h       |  13 +++
 net/net.c                  |   4 +
 net/tftp.c                 |   5 +
 test/dm/led.c              |  72 ++++++++++++++
 test/dm/ofnode.c           |   9 ++
 17 files changed, 594 insertions(+), 13 deletions(-)
 create mode 100644 doc/api/led.rst
Signature · 1 line
2.45.2
#1 lore raw

PATCH v4 1/11 led: toggle LED on initial SW blink

We currently init the LED OFF when SW blink is triggered when on_state_change() is called. This can be problematic for very short period as the ON/OFF blink might never trigger.

Toggle the LED (ON if OFF, OFF if ON) on initial SW blink to handle this corner case and better display a LED blink from the user.

---
 drivers/led/led_sw_blink.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/led/led_sw_blink.c +9 -1
index 9e36edbee47..9d9820720c6 100644
@@ -103,8 +103,16 @@ bool led_sw_on_state_change(struct udevice *dev, enum led_state_t state)
 		return false;
 
 	if (state == LEDST_BLINK) {
+		struct led_ops *ops = led_get_ops(dev);
+		enum led_state_t curr_state = led_get_state(dev);
+
+		curr_state = ops->get_state(dev);
+		/* toggle led initially */
+		ops->set_state(dev, curr_state == LEDST_ON ? LEDST_OFF :
+			       LEDST_ON);
 		/* start blinking on next led_sw_blink() call */
-		sw_blink->state = LED_SW_BLINK_ST_OFF;
+		sw_blink->state = curr_state == LEDST_ON ? LED_SW_BLINK_ST_OFF :
+				  LED_SW_BLINK_ST_ON;
 		return true;
 	}
 
Signature · 1 line
2.45.2
#2 lore raw

Re: [PATCH v4 01/11] led: toggle LED on initial SW blink

Hi

Quoted 19 lines · Christian Marangi

We currently init the LED OFF when SW blink is triggered when on_state_change() is called. This can be problematic for very short period as the ON/OFF blink might never trigger.

Toggle the LED (ON if OFF, OFF if ON) on initial SW blink to handle this corner case and better display a LED blink from the user.

---
 drivers/led/led_sw_blink.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/led/led_sw_blink.c +0 -0
index 9e36edbee47..9d9820720c6 100644

drivers/led/led_sw_blink.c bool led_sw_on_state_change(struct udevice *dev, enum led_state_t state) · line 109

Quoted 7 lines
drivers/led/led_sw_blink.c +4 -0
@@ -103,8 +103,16 @@ bool led_sw_on_state_change(struct udevice *dev, enum led_state_t state)
                return false;
 
        if (state == LEDST_BLINK) {
+               struct led_ops *ops = led_get_ops(dev);
+               enum led_state_t curr_state = led_get_state(dev);
+
+               curr_state = ops->get_state(dev);

The led_get_state return curr_state. You need to use a) led_set/get state or them from ops

if (state == LEDST_BLINK) {
        const struct led_ops *ops = led_get_ops(dev);
        enum led_state_t curr_state = ops->get_state(dev);
        enun led_state_t next_state;

        switch (curr_state) {
        case LEDST_ON:
                sw_blink->state = LED_SW_BLINK_ST_OFF;
                next_state = LEDST_OFF;
               break;
        case LEDST_OFF:
                sw_blink->state = LED_SW_BLINK_ST_ON;
                next_state = LEDST_ON;
                break;
        }

        ops->set_state(dev, next_state);
        return true;
}

Michael

Quoted 15 lines
drivers/led/led_sw_blink.c +5 -1
+               /* toggle led initially */
+               ops->set_state(dev, curr_state == LEDST_ON ? LEDST_OFF :
+                              LEDST_ON);
                /* start blinking on next led_sw_blink() call */
-               sw_blink->state = LED_SW_BLINK_ST_OFF;
+               sw_blink->state = curr_state == LEDST_ON ? LED_SW_BLINK_ST_OFF :
+                                 LED_SW_BLINK_ST_ON;
 
 
                return true;
        }

--
2.45.2

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
#3 lore raw

Re: [PATCH v4 01/11] led: toggle LED on initial SW blink

Quoted 45 lines · Michael Nazzareno Trimarchi

Hi

Quoted 19 lines · Christian Marangi

We currently init the LED OFF when SW blink is triggered when on_state_change() is called. This can be problematic for very short period as the ON/OFF blink might never trigger.

Toggle the LED (ON if OFF, OFF if ON) on initial SW blink to handle this corner case and better display a LED blink from the user.

---
 drivers/led/led_sw_blink.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/led/led_sw_blink.c +0 -0
index 9e36edbee47..9d9820720c6 100644

drivers/led/led_sw_blink.c bool led_sw_on_state_change(struct udevice *dev, enum led_state_t state) · line 109

Quoted 7 lines
drivers/led/led_sw_blink.c +4 -0
@@ -103,8 +103,16 @@ bool led_sw_on_state_change(struct udevice *dev, enum led_state_t state)
                return false;
 
        if (state == LEDST_BLINK) {
+               struct led_ops *ops = led_get_ops(dev);
+               enum led_state_t curr_state = led_get_state(dev);
+
+               curr_state = ops->get_state(dev);

The led_get_state return curr_state. You need to use a) led_set/get state or them from ops

if (state == LEDST_BLINK) {
        const struct led_ops *ops = led_get_ops(dev);
        enum led_state_t curr_state = ops->get_state(dev);
        enun led_state_t next_state;

        switch (curr_state) {
        case LEDST_ON:
                sw_blink->state = LED_SW_BLINK_ST_OFF;
                next_state = LEDST_OFF;
               break;
        case LEDST_OFF:
Quoted 9 lines
                sw_blink->state = LED_SW_BLINK_ST_ON;
                next_state = LEDST_ON;
                break;
        }

        ops->set_state(dev, next_state);
        return true;
}

Hi,

I'm not following how this is different than the proposed code... Is this a suggestion to make it more readable, I'm a bit confused.

Quoted 30 lines
Quoted 16 lines
drivers/led/led_sw_blink.c +5 -1
+               /* toggle led initially */
+               ops->set_state(dev, curr_state == LEDST_ON ? LEDST_OFF :
+                              LEDST_ON);
                /* start blinking on next led_sw_blink() call */
-               sw_blink->state = LED_SW_BLINK_ST_OFF;
+               sw_blink->state = curr_state == LEDST_ON ? LED_SW_BLINK_ST_OFF :
+                                 LED_SW_BLINK_ST_ON;
 
 
                return true;
        }

--
2.45.2

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
Signature · 1 line
	Ansuel
#4 lore raw

PATCH v4 2/11 dm: core: implement ofnode_options helpers

In reply to Christian Marangi

Implement ofnode_options helpers to read options in /options/u-boot to adapt to the new way to declare options as described in [0].

[0] dtschema/schemas/options/u-boot.yaml

---
 drivers/core/ofnode.c | 33 +++++++++++++++++++++++++++++++++
 include/dm/ofnode.h   | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+)
drivers/core/ofnode.c +33 -0
index 4d563b47a5a..4404c4f4bab 100644
@@ -1734,6 +1734,39 @@ const char *ofnode_conf_read_str(const char *prop_name)
 	return ofnode_read_string(node, prop_name);
 }
 
+bool ofnode_options_read_bool(const char *prop_name)
+{
+	ofnode uboot;
+
+	uboot = ofnode_path("/options/u-boot");
+	if (!ofnode_valid(uboot))
+		return false;
+
+	return ofnode_read_bool(uboot, prop_name);
+}
+
+int ofnode_options_read_int(const char *prop_name, int default_val)
+{
+	ofnode uboot;
+
+	uboot = ofnode_path("/options/u-boot");
+	if (!ofnode_valid(uboot))
+		return default_val;
+
+	return ofnode_read_u32_default(uboot, prop_name, default_val);
+}
+
+const char *ofnode_options_read_str(const char *prop_name)
+{
+	ofnode uboot;
+
+	uboot = ofnode_path("/options/u-boot");
+	if (!ofnode_valid(uboot))
+		return NULL;
+
+	return ofnode_read_string(uboot, prop_name);
+}
+
 int ofnode_read_bootscript_address(u64 *bootscr_address, u64 *bootscr_offset)
 {
 	int ret;
include/dm/ofnode.h +41 -0

47 lines not on this page · raw message

Signature · 1 line
2.45.2
Reviewed-by on v4 2/11
#5 lore raw

Re: [PATCH v4 02/11] dm: core: implement ofnode_options helpers

Hi Christian,

Quoted 4 lines · Christian Marangi

Implement ofnode_options helpers to read options in /options/u-boot to adapt to the new way to declare options as described in [0].

Quoted 8 lines

[0] dtschema/schemas/options/u-boot.yaml

---
 drivers/core/ofnode.c | 33 +++++++++++++++++++++++++++++++++
 include/dm/ofnode.h   | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+)

It's fine to add the tests in the same patch, if you like

#6 lore raw

PATCH v4 3/11 led: implement LED boot API

In reply to Christian Marangi

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 is introduced, CONFIG_LED_BOOT to enable the feature. This makes use of the /options/u-boot property "boot-led" to the define the boot LED.
It's also introduced a new /options/u-boot property "boot-led-period" to define the default period when the LED is set to blink mode.

If "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.

To cache the data we repurpose the now unused led_uc_priv for storage of global LED uclass info.

---
 drivers/led/Kconfig      |   7 +++
 drivers/led/led-uclass.c | 100 +++++++++++++++++++++++++++++++++++++++
 include/led.h            |  56 +++++++++++++++++++++-
 3 files changed, 161 insertions(+), 2 deletions(-)
drivers/led/Kconfig +7 -0
index bee74b25751..6149cfa02b8 100644
@@ -9,6 +9,13 @@ config LED
 	  can provide access to board-specific LEDs. Use of the device tree
 	  for configuration is encouraged.
 
+config LED_BOOT
+	bool "Enable LED boot support"
+	help
+	  Enable LED boot support.
+
+	  LED boot is a specific LED assigned to signal boot operation status.
+
 config LED_BCM6328
 	bool "LED Support for BCM6328"
 	depends on LED && ARCH_BMIPS
drivers/led/led-uclass.c +100 -0

127 lines not on this page · raw message

include/led.h +54 -2

74 lines not on this page · raw message

Signature · 1 line
2.45.2
#7 lore raw

Re: [PATCH v4 03/11] led: implement LED boot API

Hi Christian,

Quoted 12 lines · Christian Marangi

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 is introduced, CONFIG_LED_BOOT to enable the feature. This makes use of the /options/u-boot property "boot-led" to the define the boot LED.
It's also introduced a new /options/u-boot property "boot-led-period" to define the default period when the LED is set to blink mode.

Quoted 8 lines

If "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.

To cache the data we repurpose the now unused led_uc_priv for storage of global LED uclass info.

Some things to tweak below

Quoted 13 lines
---
 drivers/led/Kconfig      |   7 +++
 drivers/led/led-uclass.c | 100 +++++++++++++++++++++++++++++++++++++++
 include/led.h            |  56 +++++++++++++++++++++-
 3 files changed, 161 insertions(+), 2 deletions(-)
drivers/led/Kconfig +0 -0
index bee74b25751..6149cfa02b8 100644

drivers/led/Kconfig config LED · line 17

Quoted 9 lines
drivers/led/Kconfig +6 -0
@@ -9,6 +9,13 @@ config LED
          can provide access to board-specific LEDs. Use of the device tree
          for configuration is encouraged.
 
+config LED_BOOT
+       bool "Enable LED boot support"
+       help
+         Enable LED boot support.
+
+         LED boot is a specific LED assigned to signal boot operation status.

Here you should link to the /options binding in
doc/device-tree-bindings/options, perhaps

Quoted 12 lines
drivers/led/Kconfig +1 -0
+
 config LED_BCM6328
        bool "LED Support for BCM6328"
        depends on LED && ARCH_BMIPS
drivers/led/led-uclass.c +0 -0
index 199d68bc25a..c5b560982b0 100644
@@ -94,17 +94,101 @@ int led_set_period(struct udevice *dev, int period_ms)
        return -ENOSYS;
 }
 

drivers/led/led-uclass.c int led_set_period(struct udevice *dev, int period_ms) · line 106

Quoted 10 lines
drivers/led/led-uclass.c +10 -0
+#ifdef CONFIG_LED_BOOT
+int led_boot_on(void)
+{
+       struct uclass *uc = uclass_find(UCLASS_LED);
+       struct led_uc_priv *priv;
+       struct udevice *dev;
+
+       if (!uc)
+               return -ENOENT;
+

The normal way is:

ret = uclass_first_device_ret(UCLASS_LED, &dev);
if (ret)
return ret;

drivers/led/led-uclass.c int led_set_period(struct udevice *dev, int period_ms) · line 109

Quoted 3 lines
drivers/led/led-uclass.c +3 -0
+       priv = uclass_get_priv(uc);
+       if (!priv->boot_led_dev ||
+           uclass_get_device_tail(priv->boot_led_dev, 0, &dev)) {

That is an internal function...I suppose it should really have an underscore and be in uclass-internal.h

But if you are looking for boot_led_label, don't you need to search through the LEDs to find it? Or use led_get_by_label() ?

Quoted 7 lines
drivers/led/led-uclass.c +7 -0
+               printf("Failed to get boot LED %s\n",
+                      priv->boot_led_label);
+               return -EINVAL;
+       }
+
+       return led_set_state(dev, LEDST_ON);
+}

drivers/led/led-uclass.c int led_set_period(struct udevice *dev, int period_ms) · line 126

Quoted 10 lines
drivers/led/led-uclass.c +10 -0
+
+int led_boot_off(void)
+{
+       struct uclass *uc = uclass_find(UCLASS_LED);
+       struct led_uc_priv *priv;
+       struct udevice *dev;
+
+       if (!uc)
+               return -ENOENT;
+

Same here.

Quoted 19 lines
drivers/led/led-uclass.c +19 -0
+       priv = uclass_get_priv(uc);
+       if (!priv->boot_led_dev ||
+           uclass_get_device_tail(priv->boot_led_dev, 0, &dev)) {
+               printf("Failed to get boot LED %s\n",
+                      priv->boot_led_label);
+               return -EINVAL;
+       }
+
+       return led_set_state(dev, LEDST_OFF);
+}
+
+#if defined(CONFIG_LED_BLINK) || defined(CONFIG_LED_SW_BLINK)
+int led_boot_blink(void)
+{
+       struct uclass *uc = uclass_find(UCLASS_LED);
+       struct led_uc_priv *priv;
+       struct udevice *dev;
+       int ret;
+

drivers/led/led-uclass.c int led_set_period(struct udevice *dev, int period_ms) · line 155

Quoted 10 lines
drivers/led/led-uclass.c +10 -0
+       if (!uc)
+               return -ENOENT;
+
+       priv = uclass_get_priv(uc);
+       if (!priv->boot_led_dev ||
+           uclass_get_device_tail(priv->boot_led_dev, 0, &dev)) {
+               printf("Failed to get boot LED %s\n",
+                      priv->boot_led_label);
+               return -EINVAL;
+       }

This looks like the same code again. I think it should be in a function so the code is not repeated.

Quoted 55 lines
drivers/led/led-uclass.c +37 -0
+
+       ret = led_set_period(dev, priv->boot_led_period);
+       if (ret) {
+               if (ret != -ENOSYS)
+                       return ret;
+
+               /* fallback to ON with no set_period and no SW_BLINK */
+               return led_set_state(dev, LEDST_ON);
+       }
+
+       return led_set_state(dev, LEDST_BLINK);
+}
+#endif
+#endif
+
 static int led_post_bind(struct udevice *dev)
 {
        struct led_uc_plat *uc_plat = dev_get_uclass_plat(dev);
        const char *default_state;
 
+#ifdef CONFIG_LED_BOOT
+       struct led_uc_priv *priv = uclass_get_priv(dev->uclass);
+#endif
+
        if (!uc_plat->label)
                uc_plat->label = dev_read_string(dev, "label");
 
        if (!uc_plat->label && !dev_read_string(dev, "compatible"))
                uc_plat->label = ofnode_get_name(dev_ofnode(dev));
 
+#ifdef CONFIG_LED_BOOT
+       /* check if we are binding boot LED and assign it */
+       if (!strcmp(priv->boot_led_label, uc_plat->label))
+               priv->boot_led_dev = dev;
+#endif
+
        uc_plat->default_state = LEDST_COUNT;
 
        default_state = dev_read_string(dev, "default-state");
@@ -158,10 +242,26 @@ static int led_post_probe(struct udevice *dev)
        return ret;
 }
 
+#ifdef CONFIG_LED_BOOT
+static int led_init(struct uclass *uc)
+{
+       struct led_uc_priv *priv = uclass_get_priv(uc);
+
+       priv->boot_led_label = ofnode_options_read_str("boot-led");
+       priv->boot_led_period = ofnode_options_read_int("boot-led-period", 250);
+
+       return 0;
+}
+#endif
+

drivers/led/led-uclass.c static int led_post_probe(struct udevice *dev) · line 266

Quoted 10 lines
drivers/led/led-uclass.c +4 -0
 UCLASS_DRIVER(led) = {
        .id             = UCLASS_LED,
        .name           = "led",
        .per_device_plat_auto   = sizeof(struct led_uc_plat),
        .post_bind      = led_post_bind,
        .post_probe     = led_post_probe,
+#ifdef CONFIG_LED_BOOT
+       .init           = led_init,
+       .priv_auto      = sizeof(struct led_uc_priv),
+#endif

I don't love all these #ifdefs but I suppose it is OK here. Ideally we would have static inline accessors for the fields, in the header file, e.g. like asm-generic/global_data.h

Quoted 83 lines
drivers/led/led-uclass.c +0 -0
 };
include/led.h +54 -3
index 99f93c5ef86..ca495217777 100644
@@ -9,6 +9,7 @@
 
 #include <stdbool.h>
 #include <cyclic.h>
+#include <dm/ofnode.h>
 
 struct udevice;
 
@@ -52,10 +53,16 @@ struct led_uc_plat {
 /**
  * struct led_uc_priv - Private data the uclass stores about each device
  *
- * @period_ms: Flash period in milliseconds
+ * @boot_led_label:    Boot LED label
+ * @boot_led_dev:      Boot LED dev
+ * @boot_led_period:   Boot LED blink period
  */
 struct led_uc_priv {
-       int period_ms;
+#ifdef CONFIG_LED_BOOT
+       const char *boot_led_label;
+       struct udevice *boot_led_dev;
+       int boot_led_period;
+#endif
 };
 
 struct led_ops {
@@ -141,4 +148,49 @@ 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
+
+/**
+ * led_boot_on() - turn ON the designated LED for booting
+ *
+ * Return: 0 if OK, -ve on error
+ */
+int led_boot_on(void);
+
+/**
+ * led_boot_off() - turn OFF the designated LED for booting
+ *
+ * Return: 0 if OK, -ve on error
+ */
+int led_boot_off(void);
+
+#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
+ */
+int led_boot_blink(void);
+
+#else
+/* If LED BLINK is not supported/enabled, fallback to LED ON */
+#define led_boot_blink led_boot_on
+#endif
+#else
+static inline int led_boot_on(void)
+{
+       return -ENOSYS;
+}
+
+static inline int led_boot_off(void)
+{
+       return -ENOSYS;
+}
+
+static inline int led_boot_blink(void)
+{
+       return -ENOSYS;
+}
+#endif
+
 #endif
--
Quoted 2 lines

2.45.2

Regards,
Simon

#8 lore raw

Re: [PATCH v4 03/11] led: implement LED boot API

Quoted 18 lines · Simon Glass

Hi Christian,

Quoted 15 lines · Christian Marangi

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 is introduced, CONFIG_LED_BOOT to enable the feature. This makes use of the /options/u-boot property "boot-led" to the define the boot LED.
It's also introduced a new /options/u-boot property "boot-led-period" to define the default period when the LED is set to blink mode.

If "boot-led-period" is not defined, the value of 250 (ms) is used by default.

Quoted 8 lines
Quoted 5 lines

If CONFIG_LED_BLINK or CONFIG_LED_SW_BLINK is not enabled, led_boot_blink call will fallback to simple LED ON.

To cache the data we repurpose the now unused led_uc_priv for storage of global LED uclass info.

Some things to tweak below

Hi, thanks for the review. I asked some clarification, thanks for any comments.

Quoted 16 lines
Quoted 16 lines
---
 drivers/led/Kconfig      |   7 +++
 drivers/led/led-uclass.c | 100 +++++++++++++++++++++++++++++++++++++++
 include/led.h            |  56 +++++++++++++++++++++-
 3 files changed, 161 insertions(+), 2 deletions(-)
drivers/led/Kconfig +0 -0
index bee74b25751..6149cfa02b8 100644
@@ -9,6 +9,13 @@ config LED
          can provide access to board-specific LEDs. Use of the device tree
          for configuration is encouraged.
 
Quoted 10 lines

drivers/led/Kconfig config LED · line 17

Quoted 6 lines
drivers/led/Kconfig +6 -0
+config LED_BOOT
+       bool "Enable LED boot support"
+       help
+         Enable LED boot support.
+
+         LED boot is a specific LED assigned to signal boot operation status.

Here you should link to the /options binding in
doc/device-tree-bindings/options, perhaps

Ok.

Quoted 33 lines
Quoted 12 lines
drivers/led/Kconfig +1 -0
+
 config LED_BCM6328
        bool "LED Support for BCM6328"
        depends on LED && ARCH_BMIPS
drivers/led/led-uclass.c +0 -0
index 199d68bc25a..c5b560982b0 100644
@@ -94,17 +94,101 @@ int led_set_period(struct udevice *dev, int period_ms)
        return -ENOSYS;
 }
 

drivers/led/led-uclass.c int led_set_period(struct udevice *dev, int period_ms) · line 106

Quoted 10 lines
drivers/led/led-uclass.c +10 -0
+#ifdef CONFIG_LED_BOOT
+int led_boot_on(void)
+{
+       struct uclass *uc = uclass_find(UCLASS_LED);
+       struct led_uc_priv *priv;
+       struct udevice *dev;
+
+       if (!uc)
+               return -ENOENT;
+

The normal way is:

ret = uclass_first_device_ret(UCLASS_LED, &dev);
if (ret)
return ret;

drivers/led/led-uclass.c int led_set_period(struct udevice *dev, int period_ms) · line 109

Quoted 3 lines
drivers/led/led-uclass.c +3 -0
+       priv = uclass_get_priv(uc);
+       if (!priv->boot_led_dev ||
+           uclass_get_device_tail(priv->boot_led_dev, 0, &dev)) {
Quoted 6 lines

That is an internal function...I suppose it should really have an underscore and be in uclass-internal.h

But if you are looking for boot_led_label, don't you need to search through the LEDs to find it? Or use led_get_by_label() ?

Idea here and up is to cache the dev on bind to prevent useless/additional loop on search in each UCLASS LED the boot LED.

uclass_get_device_tail is needed to actually trigger probe of the LED if it hasn't been done prev.

The uclass_get_priv is followed by the rkmtd_get_cur_dev() implementation, for the sake of getting the UCLASS alone it seems too much to have all the additional operation to get the first device.

Also considering uclass_get_device_tail is also used by get_by_label I assume it's ok to also use it here.

Should I ignore caching the dev and just search for the boot LED from label everytime out of simplicity?

Quoted 114 lines
Quoted 7 lines
drivers/led/led-uclass.c +7 -0
+               printf("Failed to get boot LED %s\n",
+                      priv->boot_led_label);
+               return -EINVAL;
+       }
+
+       return led_set_state(dev, LEDST_ON);
+}

drivers/led/led-uclass.c int led_set_period(struct udevice *dev, int period_ms) · line 126

Quoted 10 lines
drivers/led/led-uclass.c +10 -0
+
+int led_boot_off(void)
+{
+       struct uclass *uc = uclass_find(UCLASS_LED);
+       struct led_uc_priv *priv;
+       struct udevice *dev;
+
+       if (!uc)
+               return -ENOENT;
+

Same here.

Quoted 19 lines
drivers/led/led-uclass.c +19 -0
+       priv = uclass_get_priv(uc);
+       if (!priv->boot_led_dev ||
+           uclass_get_device_tail(priv->boot_led_dev, 0, &dev)) {
+               printf("Failed to get boot LED %s\n",
+                      priv->boot_led_label);
+               return -EINVAL;
+       }
+
+       return led_set_state(dev, LEDST_OFF);
+}
+
+#if defined(CONFIG_LED_BLINK) || defined(CONFIG_LED_SW_BLINK)
+int led_boot_blink(void)
+{
+       struct uclass *uc = uclass_find(UCLASS_LED);
+       struct led_uc_priv *priv;
+       struct udevice *dev;
+       int ret;
+

drivers/led/led-uclass.c int led_set_period(struct udevice *dev, int period_ms) · line 155

Quoted 10 lines
drivers/led/led-uclass.c +10 -0
+       if (!uc)
+               return -ENOENT;
+
+       priv = uclass_get_priv(uc);
+       if (!priv->boot_led_dev ||
+           uclass_get_device_tail(priv->boot_led_dev, 0, &dev)) {
+               printf("Failed to get boot LED %s\n",
+                      priv->boot_led_label);
+               return -EINVAL;
+       }

This looks like the same code again. I think it should be in a function so the code is not repeated.

Quoted 61 lines
drivers/led/led-uclass.c +37 -0
+
+       ret = led_set_period(dev, priv->boot_led_period);
+       if (ret) {
+               if (ret != -ENOSYS)
+                       return ret;
+
+               /* fallback to ON with no set_period and no SW_BLINK */
+               return led_set_state(dev, LEDST_ON);
+       }
+
+       return led_set_state(dev, LEDST_BLINK);
+}
+#endif
+#endif
+
 static int led_post_bind(struct udevice *dev)
 {
        struct led_uc_plat *uc_plat = dev_get_uclass_plat(dev);
        const char *default_state;
 
+#ifdef CONFIG_LED_BOOT
+       struct led_uc_priv *priv = uclass_get_priv(dev->uclass);
+#endif
+
        if (!uc_plat->label)
                uc_plat->label = dev_read_string(dev, "label");
 
        if (!uc_plat->label && !dev_read_string(dev, "compatible"))
                uc_plat->label = ofnode_get_name(dev_ofnode(dev));
 
+#ifdef CONFIG_LED_BOOT
+       /* check if we are binding boot LED and assign it */
+       if (!strcmp(priv->boot_led_label, uc_plat->label))
+               priv->boot_led_dev = dev;
+#endif
+
        uc_plat->default_state = LEDST_COUNT;
 
        default_state = dev_read_string(dev, "default-state");
@@ -158,10 +242,26 @@ static int led_post_probe(struct udevice *dev)
        return ret;
 }
 
+#ifdef CONFIG_LED_BOOT
+static int led_init(struct uclass *uc)
+{
+       struct led_uc_priv *priv = uclass_get_priv(uc);
+
+       priv->boot_led_label = ofnode_options_read_str("boot-led");
+       priv->boot_led_period = ofnode_options_read_int("boot-led-period", 250);
+
+       return 0;
+}
+#endif
+
 UCLASS_DRIVER(led) = {
        .id             = UCLASS_LED,
        .name           = "led",
        .per_device_plat_auto   = sizeof(struct led_uc_plat),
        .post_bind      = led_post_bind,
        .post_probe     = led_post_probe,
Quoted 9 lines

drivers/led/led-uclass.c static int led_post_probe(struct udevice *dev) · line 266

Quoted 4 lines
drivers/led/led-uclass.c +4 -0
+#ifdef CONFIG_LED_BOOT
+       .init           = led_init,
+       .priv_auto      = sizeof(struct led_uc_priv),
+#endif

I don't love all these #ifdefs but I suppose it is OK here. Ideally we would have static inline accessors for the fields, in the header file, e.g. like asm-generic/global_data.h

Didn't know of the global_data but then I read the comments and it seems we should not really pollute it with too much stuff. Also considering most of the LED are driven with gpio the possibility of having this that early on boot might be closer to 0.

Quoted 88 lines
Quoted 83 lines
drivers/led/led-uclass.c +0 -0
 };
include/led.h +54 -3
index 99f93c5ef86..ca495217777 100644
@@ -9,6 +9,7 @@
 
 #include <stdbool.h>
 #include <cyclic.h>
+#include <dm/ofnode.h>
 
 struct udevice;
 
@@ -52,10 +53,16 @@ struct led_uc_plat {
 /**
  * struct led_uc_priv - Private data the uclass stores about each device
  *
- * @period_ms: Flash period in milliseconds
+ * @boot_led_label:    Boot LED label
+ * @boot_led_dev:      Boot LED dev
+ * @boot_led_period:   Boot LED blink period
  */
 struct led_uc_priv {
-       int period_ms;
+#ifdef CONFIG_LED_BOOT
+       const char *boot_led_label;
+       struct udevice *boot_led_dev;
+       int boot_led_period;
+#endif
 };
 
 struct led_ops {
@@ -141,4 +148,49 @@ 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
+
+/**
+ * led_boot_on() - turn ON the designated LED for booting
+ *
+ * Return: 0 if OK, -ve on error
+ */
+int led_boot_on(void);
+
+/**
+ * led_boot_off() - turn OFF the designated LED for booting
+ *
+ * Return: 0 if OK, -ve on error
+ */
+int led_boot_off(void);
+
+#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
+ */
+int led_boot_blink(void);
+
+#else
+/* If LED BLINK is not supported/enabled, fallback to LED ON */
+#define led_boot_blink led_boot_on
+#endif
+#else
+static inline int led_boot_on(void)
+{
+       return -ENOSYS;
+}
+
+static inline int led_boot_off(void)
+{
+       return -ENOSYS;
+}
+
+static inline int led_boot_blink(void)
+{
+       return -ENOSYS;
+}
+#endif
+
 #endif
--
Quoted 2 lines

2.45.2

Regards,
Simon

Signature · 1 line
	Ansuel
#9 lore raw

PATCH v4 4/11 common: board_r: rework BOOT LED handling

In reply to Christian Marangi

Rework BOOT LED handling. There is currently one legacy implementation for BOOT LED from Status Led API.

This work on ancient implementation used by BOOTP by setting the LED to Blink on boot and to turn it OFF when the firmware was correctly received by network.

Now that we new LED implementation have support for LED boot, rework this by also set the new BOOT LED to blink and also set it to ON before entering main loop to confirm successful boot.

---
 common/board_r.c     | 28 ++++++++++++++++++++--------
 include/status_led.h | 13 +++++++++++++
 2 files changed, 33 insertions(+), 8 deletions(-)
common/board_r.c +20 -8
index d4ba245ac69..c3f8dd5d4ee 100644
@@ -39,6 +39,7 @@
 #include <initcall.h>
 #include <kgdb.h>
 #include <irq_func.h>
+#include <led.h>
 #include <malloc.h>
 #include <mapmem.h>
 #include <miiphy.h>
@@ -459,17 +460,28 @@ static int initr_malloc_bootparams(void)
 }
 #endif
 
-#if defined(CONFIG_LED_STATUS)
 static int initr_status_led(void)
 {
-#if defined(CONFIG_LED_STATUS_BOOT)
-	status_led_set(CONFIG_LED_STATUS_BOOT, CONFIG_LED_STATUS_BLINKING);
-#else
 	status_led_init();
-#endif
+
+	return 0;
+}
+
+static int initr_boot_led_blink(void)
+{
+	status_led_boot_blink();
+
+	led_boot_blink();
+
+	return 0;
+}
+
+static int initr_boot_led_on(void)
+{
+	led_boot_on();
+
 	return 0;
 }
-#endif
 
 #ifdef CONFIG_CMD_NET
 static int initr_net(void)
@@ -713,9 +725,8 @@ static init_fnc_t init_sequence_r[] = {
 #if defined(CONFIG_MICROBLAZE) || defined(CONFIG_M68K)
 	timer_init,		/* initialize timer */
 #endif
-#if defined(CONFIG_LED_STATUS)
 	initr_status_led,
-#endif
+	initr_boot_led_blink,
 	/* PPC has a udelay(20) here dating from 2002. Why? */
 #ifdef CONFIG_BOARD_LATE_INIT
 	board_late_init,
@@ -738,6 +749,7 @@ static init_fnc_t init_sequence_r[] = {
 #if defined(CFG_PRAM)
 	initr_mem,
 #endif
+	initr_boot_led_on,
 	run_main_loop,
 };
 
include/status_led.h +13 -0
index 6707ab1d29d..1282022253e 100644
@@ -39,6 +39,13 @@ void status_led_init(void);
 void status_led_tick(unsigned long timestamp);
 void status_led_set(int led, int state);
 
+static inline void status_led_boot_blink(void)
+{
+#ifdef CONFIG_LED_STATUS_BOOT_ENABLE
+	status_led_set(CONFIG_LED_STATUS_BOOT, CONFIG_LED_STATUS_BLINKING);
+#endif
+}
+
 /*****  MVS v1  **********************************************************/
 #if (defined(CONFIG_MVS) && CONFIG_MVS < 2)
 # define STATUS_LED_PAR		im_ioport.iop_pdpar
@@ -72,6 +79,12 @@ void __led_blink(led_id_t mask, int freq);
 # include <asm/status_led.h>
 #endif
 
+#else
+
+static inline void status_led_init(void) { }
+static inline void status_led_set(int led, int state) { }
+static inline void status_led_boot_blink(void) { }
+
 #endif	/* CONFIG_LED_STATUS	*/
 
 /*
Signature · 1 line
2.45.2
Reviewed-by on v4 4/11
#10 lore raw

Re: [PATCH v4 04/11] common: board_r: rework BOOT LED handling

Quoted 12 lines · Christian Marangi

Rework BOOT LED handling. There is currently one legacy implementation for BOOT LED from Status Led API.

This work on ancient implementation used by BOOTP by setting the LED to Blink on boot and to turn it OFF when the firmware was correctly received by network.

Now that we new LED implementation have support for LED boot, rework this by also set the new BOOT LED to blink and also set it to ON before entering main loop to confirm successful boot.

Quoted 5 lines
---
 common/board_r.c     | 28 ++++++++++++++++++++--------
 include/status_led.h | 13 +++++++++++++
 2 files changed, 33 insertions(+), 8 deletions(-)
#11 lore raw

PATCH v4 5/11 led: implement LED activity API

In reply to Christian Marangi

Implement LED activity API similar to BOOT LED API.

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

User of this API will call led_activity_on/off/blink() to signal these kind of activity.

New Kconfig is implemented similar to BOOT LED, LED_ACTIVITY to enable support for it.

It's introduced a new /options/u-boot property "activity-led" and "activity-led-period" to define the activity LED label and the default period when the activity LED is set to blink mode.

If "activity-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.

---
 drivers/led/Kconfig      |  8 ++++
 drivers/led/led-uclass.c | 94 ++++++++++++++++++++++++++++++++++++++--
 include/led.h            | 52 ++++++++++++++++++++++
 3 files changed, 151 insertions(+), 3 deletions(-)
drivers/led/Kconfig +8 -0
index 6149cfa02b8..f0434f247a4 100644
@@ -16,6 +16,14 @@ config LED_BOOT
 
 	  LED boot is a specific LED assigned to signal boot operation status.
 
+config LED_ACTIVITY
+	bool "Enable LED activity support"
+	help
+	  Enable LED activity support.
+
+	  LED activity is a specific LED assigned to signal activity operation
+	  like file trasnfer, flash write/erase...
+
 config LED_BCM6328
 	bool "LED Support for BCM6328"
 	depends on LED && ARCH_BMIPS
drivers/led/led-uclass.c +91 -3

129 lines not on this page · raw message

include/led.h +52 -0

70 lines not on this page · raw message

Signature · 1 line
2.45.2
#12 lore raw

PATCH v4 6/11 tftp: implement support for LED activity

In reply to Christian Marangi

Implement support for LED activity. If the feature is enabled, make the defined ACTIVITY LED to signal traffic.

Also turn the ACTIVITY LED OFF if a CTRL-C is detected in the main net loop function.

---
 net/net.c  | 4 ++++
 net/tftp.c | 5 +++++
 2 files changed, 9 insertions(+)
net/net.c +4 -0
index d9bc9df643f..94bfde43f85 100644
@@ -87,6 +87,7 @@
 #include <env_internal.h>
 #include <errno.h>
 #include <image.h>
+#include <led.h>
 #include <log.h>
 #include <net.h>
 #include <net6.h>
@@ -659,6 +660,9 @@ restart:
 			/* Invalidate the last protocol */
 			eth_set_last_protocol(BOOTP);
 
+			/* Turn off activity LED if triggered */
+			led_activity_off();
+
 			puts("\nAbort\n");
 			/* include a debug print as well incase the debug
 			   messages are directed to stderr */
net/tftp.c +5 -0
index 2e073183d5a..5cb06d2038b 100644
@@ -10,6 +10,7 @@
 #include <efi_loader.h>
 #include <env.h>
 #include <image.h>
+#include <led.h>
 #include <lmb.h>
 #include <log.h>
 #include <mapmem.h>
@@ -192,6 +193,7 @@ static void new_transfer(void)
 #ifdef CONFIG_CMD_TFTPPUT
 	tftp_put_final_block_sent = 0;
 #endif
+	led_activity_blink();
 }
 
 #ifdef CONFIG_CMD_TFTPPUT
@@ -301,6 +303,9 @@ static void tftp_complete(void)
 			time_start * 1000, "/s");
 	}
 	puts("\ndone\n");
+
+	led_activity_off();
+
 	if (!tftp_put_active)
 		efi_set_bootdev("Net", "", tftp_filename,
 				map_sysmem(tftp_load_addr, 0),
Signature · 1 line
2.45.2
Reviewed-by on v4 6/11
#13 lore raw

Re: [PATCH v4 06/11] tftp: implement support for LED activity

Quoted 4 lines · Christian Marangi

Implement support for LED activity. If the feature is enabled, make the defined ACTIVITY LED to signal traffic.

Quoted 9 lines

Also turn the ACTIVITY LED OFF if a CTRL-C is detected in the main net loop function.

---
 net/net.c  | 4 ++++
 net/tftp.c | 5 +++++
 2 files changed, 9 insertions(+)
#14 lore raw

PATCH v4 7/11 mtd: implement support for LED activity

In reply to Christian Marangi

Implement support for LED activity. If the feature is enabled, make the defined ACTIVITY LED to signal mtd write or erase operations.

---
 cmd/mtd.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
cmd/mtd.c +11 -0
index 795aaa2b37d..dae90b0e6e4 100644
@@ -10,6 +10,7 @@
 
 #include <command.h>
 #include <console.h>
+#include <led.h>
 #if CONFIG_IS_ENABLED(CMD_MTD_OTP)
 #include <hexdump.h>
 #endif
@@ -558,6 +559,9 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,
 	while (mtd_block_isbad(mtd, off))
 		off += mtd->erasesize;
 
+	if (!read)
+		led_activity_blink();
+
 	/* Loop over the pages to do the actual read/write */
 	while (remaining) {
 		/* Skip the block if it is bad */
@@ -585,6 +589,9 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,
 		io_op.oobbuf += io_op.oobretlen;
 	}
 
+	if (!read)
+		led_activity_off();
+
 	if (!ret && dump)
 		mtd_dump_device_buf(mtd, start_off, buf, len, woob);
 
@@ -652,6 +659,8 @@ static int do_mtd_erase(struct cmd_tbl *cmdtp, int flag, int argc,
 	erase_op.addr = off;
 	erase_op.len = mtd->erasesize;
 
+	led_activity_blink();
+
 	while (len) {
 		if (!scrub) {
 			ret = mtd_block_isbad(mtd, erase_op.addr);
@@ -680,6 +689,8 @@ static int do_mtd_erase(struct cmd_tbl *cmdtp, int flag, int argc,
 		erase_op.addr += mtd->erasesize;
 	}
 
+	led_activity_off();
+
 	if (ret && ret != -EIO)
 		ret = CMD_RET_FAILURE;
 	else
Signature · 1 line
2.45.2
#15 lore raw

Re: [PATCH v4 07/11] mtd: implement support for LED activity

Hi Christian,

[email protected] wrote on Sat, 21 Sep 2024 00:50:00 +0200:

Quoted 2 lines

Implement support for LED activity. If the feature is enabled, make the defined ACTIVITY LED to signal mtd write or erase operations.

I'm curious, why did you not consider reads in your proposal? I think in general as long as you use a device the LED should blink. While you're performing a read you cannot do anything else with the chip so I would definitely consider the read path as well.

Also, I would expect the blinking to continue when the device is accessed, no matter who is asking for it. So for instance when I load my kernel into RAM, I believe it should blink. Hence, why not considering the mtd layer rather than the command .c file?

cmd/mtd.c

Quoted 10 lines
---
 cmd/mtd.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
cmd/mtd.c +0 -0
index 795aaa2b37d..dae90b0e6e4 100644

Thanks,
Miquèl

#16 lore raw

Re: [PATCH v4 07/11] mtd: implement support for LED activity

Quoted 12 lines · Miquel Raynal

Hi Christian,

[email protected] wrote on Sat, 21 Sep 2024 00:50:00 +0200:

Quoted 2 lines

Implement support for LED activity. If the feature is enabled, make the defined ACTIVITY LED to signal mtd write or erase operations.

I'm curious, why did you not consider reads in your proposal? I think in general as long as you use a device the LED should blink. While you're performing a read you cannot do anything else with the chip so I would definitely consider the read path as well.

Quoted 5 lines

Also, I would expect the blinking to continue when the device is accessed, no matter who is asking for it. So for instance when I load my kernel into RAM, I believe it should blink. Hence, why not considering the mtd layer rather than the command .c file?

My idea for the feature was really for recovery and flashing usage, soo everything that is initiated by the user or that does change thing.

Example a button trigger an automatic recovery procedure from an attached USB drive. Having the LED blink signal the user the procedure is actually working and something is happening.

But yes yours is not a bad idea, I don't think it would make a recovery procedure confusing, lets see if others agree on that ok?

Quoted 13 lines

cmd/mtd.c

Quoted 10 lines
---
 cmd/mtd.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
cmd/mtd.c +0 -0
index 795aaa2b37d..dae90b0e6e4 100644

Thanks,
Miquèl

Signature · 1 line
	Ansuel
#17 lore raw

PATCH v4 8/11 ubi: implement support for LED activity

In reply to Christian Marangi

Implement support for LED activity. If the feature is enabled, make the defined ACTIVITY LED to signal ubi write operation.

---
 cmd/ubi.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
cmd/ubi.c +11 -2
index 0e62e449327..56d7da82629 100644
@@ -14,6 +14,7 @@
 #include <command.h>
 #include <env.h>
 #include <exports.h>
+#include <led.h>
 #include <malloc.h>
 #include <memalign.h>
 #include <mtd.h>
@@ -488,10 +489,18 @@ exit:
 
 int ubi_volume_write(char *volume, void *buf, loff_t offset, size_t size)
 {
+	int ret;
+
+	led_activity_blink();
+
 	if (!offset)
-		return ubi_volume_begin_write(volume, buf, size, size);
+		ret = ubi_volume_begin_write(volume, buf, size, size);
+	else
+		ret = ubi_volume_offset_write(volume, buf, offset, size);
 
-	return ubi_volume_offset_write(volume, buf, offset, size);
+	led_activity_off();
+
+	return ret;
 }
 
 int ubi_volume_read(char *volume, char *buf, loff_t offset, size_t size)
Signature · 1 line
2.45.2
Reviewed-by on v4 8/11
#18 lore raw

Re: [PATCH v4 08/11] ubi: implement support for LED activity

Quoted 9 lines · Christian Marangi

Implement support for LED activity. If the feature is enabled, make the defined ACTIVITY LED to signal ubi write operation.

---
 cmd/ubi.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
#19 lore raw

PATCH v4 9/11 doc: introduce led.rst documentation

In reply to Christian Marangi

Introduce simple led.rst documentation to document all the additional Kconfig and the current limitation of LED_BLINK and GPIO software blink.

Also add missing definition for sw_blink in led_uc_plat struct.

---
 doc/api/index.rst |  1 +
 doc/api/led.rst   | 10 ++++++++++
 include/led.h     | 41 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 doc/api/led.rst
doc/api/index.rst +1 -0
index ec0b8adb2cf..9f7f23f868f 100644
@@ -14,6 +14,7 @@ U-Boot API documentation
    event
    getopt
    interrupt
+   led
    linker_lists
    lmb
    logging
doc/api/led.rst new file +10 -0
new file mode 100644
index 00000000000..e52e350d1bb
@@ -0,0 +1,10 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+LED
+===
+
+.. kernel-doc:: include/led.h
+   :doc: Overview
+
+.. kernel-doc:: include/led.h
+   :internal:
\ No newline at end of file
include/led.h +41 -0

53 lines not on this page · raw message

Signature · 1 line
2.45.2
Reviewed-by on v4 9/11
#20 lore raw

Re: [PATCH v4 09/11] doc: introduce led.rst documentation

Quoted 6 lines · Christian Marangi

Introduce simple led.rst documentation to document all the additional Kconfig and the current limitation of LED_BLINK and GPIO software blink.

Also add missing definition for sw_blink in led_uc_plat struct.

Quoted 7 lines
---
 doc/api/index.rst |  1 +
 doc/api/led.rst   | 10 ++++++++++
 include/led.h     | 41 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 doc/api/led.rst
#21 lore raw

PATCH v4 10/11 test: dm: Add tests for LED boot and activity

In reply to Christian Marangi

Add tests for LED boot and activity feature and add required property in sandbox test DTS.

---
 arch/sandbox/dts/test.dts |  2 ++
 test/dm/led.c             | 72 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+)
arch/sandbox/dts/test.dts +2 -0
index 5fb5eac862e..25859ad852d 100644
@@ -101,6 +101,8 @@
 			bootscr-ram-offset = /bits/ 64 <0x12345678>;
 			bootscr-flash-offset = /bits/ 64 <0>;
 			bootscr-flash-size = /bits/ 64 <0x2000>;
+			boot-led = "sandbox:green";
+			activity-led = "sandbox:red";
 		};
 	};
 
test/dm/led.c +72 -0

75 lines not on this page · raw message

Signature · 1 line
2.45.2
Reviewed-by on v4 10/11
#22 lore raw

Re: [PATCH v4 10/11] test: dm: Add tests for LED boot and activity

Quoted 9 lines · Christian Marangi

Add tests for LED boot and activity feature and add required property in sandbox test DTS.

---
 arch/sandbox/dts/test.dts |  2 ++
 test/dm/led.c             | 72 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+)
#23 lore raw

PATCH v4 11/11 test: dm: Expand ofnode options test with new helper

In reply to Christian Marangi

Expand ofnode options test with new generic helper for bool, int and string.

---
 arch/sandbox/dts/test.dts | 3 +++
 test/dm/ofnode.c          | 9 +++++++++
 2 files changed, 12 insertions(+)
arch/sandbox/dts/test.dts +3 -0
index 25859ad852d..e5381b56da4 100644
@@ -103,6 +103,9 @@
 			bootscr-flash-size = /bits/ 64 <0x2000>;
 			boot-led = "sandbox:green";
 			activity-led = "sandbox:red";
+			testing-bool;
+			testing-int = <123>;
+			testing-str = "testing";
 		};
 	};
 
test/dm/ofnode.c +9 -0
index 39191d7f52b..7c0adcd596b 100644
@@ -614,6 +614,15 @@ static int dm_test_ofnode_options(struct unit_test_state *uts)
 	u64 bootscr_address, bootscr_offset;
 	u64 bootscr_flash_offset, bootscr_flash_size;
 
+	ut_assert(!ofnode_options_read_bool("missing"));
+	ut_assert(ofnode_options_read_bool("testing-bool"));
+
+	ut_asserteq(123, ofnode_options_read_int("testing-int", 0));
+	ut_asserteq(6, ofnode_options_read_int("missing", 6));
+
+	ut_assertnull(ofnode_options_read_str("missing"));
+	ut_asserteq_str("testing", ofnode_options_read_str("testing-str"));
+
 	ut_assertok(ofnode_read_bootscript_address(&bootscr_address,
 						   &bootscr_offset));
 	ut_asserteq_64(0, bootscr_address);
Signature · 1 line
2.45.2
Reviewed-by on v4 11/11
#24 lore raw

Re: [PATCH v4 11/11] test: dm: Expand ofnode options test with new helper

Quoted 10 lines · Christian Marangi

Expand ofnode options test with new generic helper for bool, int and string.

---
 arch/sandbox/dts/test.dts | 3 +++
 test/dm/ofnode.c          | 9 +++++++++
 2 files changed, 12 insertions(+)