Message ID | 20240812103254.26972-6-ansuelsmth@gmail.com |
---|---|
State | Changes Requested |
Delegated to: | Tom Rini |
Headers | show |
Series | led: introduce LED boot and activity function | expand |
Hi Christian, On Mon, 12 Aug 2024 at 12:33, Christian Marangi <ansuelsmth@gmail.com> wrote: > > 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 are implemented similar to BOOT LED, LED_ACTIVITY_ENABLE to > enable support for it. > > It's introduced a new /config property "u-boot,activity-led" and > "u-boot,activity-led-period" to define the activity LED label and the > default period when the activity LED is set to blink mode. > > If "u-boot,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. > > Signed-off-by: Christian Marangi <ansuelsmth@gmail.com> > --- > doc/device-tree-bindings/config.txt | 4 ++ > drivers/led/Kconfig | 21 ++++++++++ > include/led.h | 63 +++++++++++++++++++++++++++++ > 3 files changed, 88 insertions(+) Please see comments about /options on the other patch. This is a nice feature to have! > > diff --git a/doc/device-tree-bindings/config.txt b/doc/device-tree-bindings/config.txt > index 68edd177040..cd9ec88909b 100644 > --- a/doc/device-tree-bindings/config.txt > +++ b/doc/device-tree-bindings/config.txt > @@ -30,8 +30,12 @@ u-boot,boot-led (string) > 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,activity-led (string) > + This is used to specify the label for an LED to indicate an activity > + if supported by the operation. > > u-boot,boot-led-period (int) > +u-boot,activity-led-period (int) > This is used to specify the default period for an LED in blink mode. > > bootsecure (int) > diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig > index fd9442edaf3..1336f943dab 100644 > --- a/drivers/led/Kconfig > +++ b/drivers/led/Kconfig > @@ -29,6 +29,27 @@ config LED_BOOT_PERIOD > help > LED boot blink period in ms. > > +config LED_ACTIVITY_ENABLE > + 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_ACTIVITY_LABEL > + string "LED activity label" > + depends on LED_ACTIVITY_ENABLE > + help > + LED label defined in DT to assign for LED activity usage. > + > +config LED_ACTIVITY_PERIOD > + int "LED activity period" > + depends on LED_ACTIVITY_ENABLE && (LED_BLINK || LED_SW_BLINK) > + default 2 > + help > + LED activity 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 2d3b89674e2..6a1471dae85 100644 > --- a/include/led.h > +++ b/include/led.h > @@ -223,4 +223,67 @@ static inline int led_boot_blink(void) > #endif > #endif > > +#ifdef CONFIG_LED_ACTIVITY_ENABLE > + > +/** > + * led_activity_on() - turn ON the designated LED for activity > + * > + * Return: 0 if OK, -ve on error > + */ > +static inline int led_activity_on(void) > +{ > + const char *led_name; > + > + led_name = ofnode_conf_read_str("u-boot,activity-led"); > + if (!led_name) > + return -ENOENT; > + > + return led_set_state_by_label(led_name, LEDST_ON); > +} > + > +/** > + * led_activity_off() - turn OFF the designated LED for activity > + * > + * Return: 0 if OK, -ve on error > + */ > +static inline int led_activity_off(void) > +{ > + const char *led_name; > + > + led_name = ofnode_conf_read_str("u-boot,activity-led"); > + if (!led_name) > + return -ENOENT; -EINVAL for devicetree things that are missing. Also, please read the config in of_to_plat() rather than doing it when the driver is actually being used. > + > + return led_set_state_by_label(led_name, LEDST_OFF); > +} > + > +#if defined(CONFIG_LED_BLINK) || defined(CONFIG_LED_SW_BLINK) > +/** > + * led_activity_blink() - turn ON the designated LED for activity > + * > + * Return: 0 if OK, -ve on error > + */ > +static inline int led_activity_blink(void) Hmm again this code should be in a C file and in of_to_plat method.. > +{ > + const char *led_name; > + int led_period, ret; > + > + led_name = ofnode_conf_read_str("u-boot,activity-led"); > + if (!led_name) > + return -ENOENT; > + > + led_period = ofnode_conf_read_int("u-boot,activity-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_activity_blink led_activity_on > +#endif > +#endif > + > #endif > -- > 2.45.2 > Regards, Simon
diff --git a/doc/device-tree-bindings/config.txt b/doc/device-tree-bindings/config.txt index 68edd177040..cd9ec88909b 100644 --- a/doc/device-tree-bindings/config.txt +++ b/doc/device-tree-bindings/config.txt @@ -30,8 +30,12 @@ u-boot,boot-led (string) 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,activity-led (string) + This is used to specify the label for an LED to indicate an activity + if supported by the operation. u-boot,boot-led-period (int) +u-boot,activity-led-period (int) This is used to specify the default period for an LED in blink mode. bootsecure (int) diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig index fd9442edaf3..1336f943dab 100644 --- a/drivers/led/Kconfig +++ b/drivers/led/Kconfig @@ -29,6 +29,27 @@ config LED_BOOT_PERIOD help LED boot blink period in ms. +config LED_ACTIVITY_ENABLE + 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_ACTIVITY_LABEL + string "LED activity label" + depends on LED_ACTIVITY_ENABLE + help + LED label defined in DT to assign for LED activity usage. + +config LED_ACTIVITY_PERIOD + int "LED activity period" + depends on LED_ACTIVITY_ENABLE && (LED_BLINK || LED_SW_BLINK) + default 2 + help + LED activity 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 2d3b89674e2..6a1471dae85 100644 --- a/include/led.h +++ b/include/led.h @@ -223,4 +223,67 @@ static inline int led_boot_blink(void) #endif #endif +#ifdef CONFIG_LED_ACTIVITY_ENABLE + +/** + * led_activity_on() - turn ON the designated LED for activity + * + * Return: 0 if OK, -ve on error + */ +static inline int led_activity_on(void) +{ + const char *led_name; + + led_name = ofnode_conf_read_str("u-boot,activity-led"); + if (!led_name) + return -ENOENT; + + return led_set_state_by_label(led_name, LEDST_ON); +} + +/** + * led_activity_off() - turn OFF the designated LED for activity + * + * Return: 0 if OK, -ve on error + */ +static inline int led_activity_off(void) +{ + const char *led_name; + + led_name = ofnode_conf_read_str("u-boot,activity-led"); + if (!led_name) + return -ENOENT; + + return led_set_state_by_label(led_name, LEDST_OFF); +} + +#if defined(CONFIG_LED_BLINK) || defined(CONFIG_LED_SW_BLINK) +/** + * led_activity_blink() - turn ON the designated LED for activity + * + * Return: 0 if OK, -ve on error + */ +static inline int led_activity_blink(void) +{ + const char *led_name; + int led_period, ret; + + led_name = ofnode_conf_read_str("u-boot,activity-led"); + if (!led_name) + return -ENOENT; + + led_period = ofnode_conf_read_int("u-boot,activity-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_activity_blink led_activity_on +#endif +#endif + #endif
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 are implemented similar to BOOT LED, LED_ACTIVITY_ENABLE to enable support for it. It's introduced a new /config property "u-boot,activity-led" and "u-boot,activity-led-period" to define the activity LED label and the default period when the activity LED is set to blink mode. If "u-boot,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. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com> --- doc/device-tree-bindings/config.txt | 4 ++ drivers/led/Kconfig | 21 ++++++++++ include/led.h | 63 +++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+)