Skip to contentSkip to conversation

led: add function naming option from linux

PATCH In review Heiko Schocher 2 participants 6 messages Jan 28, 2025 – Feb 7, 2025

lore
Share & tools
lore
#0 lore raw

v4 cover led: add function naming option from linux

in linux we have the option to create the name of a led optionally through the following properties:

- function
- color
- function-enumerator

This series adds support for parsing this properties if there is no label property.

patch 1 is new in this series since v4, which deletes the file doc/device-tree-bindings/leds/common.txt as Tom suggested.

Azure build:
https://dev.azure.com/hs0298/hs/_build/results?buildId=168&view=results

shows an error:
https://dev.azure.com/hs0298/hs/_build/results?buildId=168&view=logs&j=c680f105-64bc-5146-6f22-9781d9f94790&t=9b6dc287-5896-5328-71bc-12fc1ca8ea8d

for sandbox64_clang ... sandbox64 target works! The error has nothing ToDo with this patchseries, as it is in dm_test_cmd_hash_md5, which tests content from source files, this series do not touch.

Changes in v4:
- new in version 4
- remove ./doc/device-tree-bindings/leds/common.txt in
seperate patch as this is now already in ./dts/upstream/Bindings/leds/common.txt
as Tom commented.
measured size impact of patch "led: add function naming option from linux":

        $ ./u-boot-size-test.sh capricorn_cxg3 --branch led-mainline
        [...]
           aarch64: (for 1/1 boards) all +886.0 rodata +230.0 text +656.0
                    capricorn_cxg3 : all +886 rodata +230 text +656
                       u-boot: add: 1/0, grow: 1/0 bytes: 416/0 (416)
                         function                                   old     new   delta
                         led_post_bind                              220     516    +296
                         led_colors                                   -     120    +120
        $ ./u-boot-size-test.sh aristainetos2c --branch led-mainline
        [...]
        01: Merge patch series "add the support of sha256_hmac and sha256_hkdf"
        40: led: add function naming option from linux
               arm: (for 2/2 boards) all +557.0 bss +20.0 rodata +161.0 text +376.0
                    aristainetos2c : all +557 bss +20 rodata +161 text +376
                       u-boot: add: 1/0, grow: 1/0 bytes: 264/0 (264)
                         function                                   old     new   delta
                         led_post_bind                              128     332    +204
                         led_colors                                   -      60     +60
                    aristainetos2ccslb: all +557 bss +20 rodata +161 text +376
                       u-boot: add: 1/0, grow: 1/0 bytes: 264/0 (264)
                         function                                   old     new   delta
                         led_post_bind                              128     332    +204
                         led_colors                                   -      60     +60
- rebase to current HEAD
  d8a7100d658. ("Subtree merge tag 'v6.13-dts' of dts repo [1] into dts/upstream")

Changes in v3:
- work in comment from Tom:
remove new file include/dt-bindings/leds/common.h in this patch as it is already in dts/upstream/include/dt-bindings/leds/common.h and so the checkpatch warnings from this file are gone! Thanks! Good catch!
remove file include/linux/uapi/linux/uleds.h and
as we only need one define from it, add this define
in include/led.h

Changes in v2:
- remove unused name variable in function led_get_label()
- rebased patch to current HEAD
82d262ae162 ("Merge patch series "MediaTek MT7629 OF_UPSTREAM migration (v2)"")

Heiko Schocher (2):
doc: remove redundant leds bindings
led: add function naming option from linux

 arch/sandbox/dts/test.dts                | 37 ++++++++++++-
 doc/device-tree-bindings/leds/common.txt | 23 --------
 drivers/led/led-uclass.c                 | 70 ++++++++++++++++++++++--
 include/led.h                            |  6 ++
 test/dm/led.c                            | 22 +++++++-
 test/dm/ofnode.c                         |  2 +-
 6 files changed, 130 insertions(+), 30 deletions(-)
 delete mode 100644 doc/device-tree-bindings/leds/common.txt
Signature · 1 line
2.20.1
#1 lore raw

PATCH v4 1/2 doc: remove redundant leds bindings

remove file doc/device-tree-bindings/leds/common.txt as we have this now already in dts/upstream/include/dt-bindings/leds/common.h which is imported from linux.

---

Changes in v4:
- new in version 4

 doc/device-tree-bindings/leds/common.txt | 23 -----------------------
 1 file changed, 23 deletions(-)
 delete mode 100644 doc/device-tree-bindings/leds/common.txt
doc/device-tree-bindings/leds/common.txt deleted +0 -23
deleted file mode 100644
index 2d88816dd55..00000000000
@@ -1,23 +0,0 @@
-Common leds properties.
-
-Optional properties for child nodes:
-- label : The label for this LED.  If omitted, the label is
-  taken from the node name (excluding the unit address).
-
-- linux,default-trigger :  This parameter, if present, is a
-    string defining the trigger assigned to the LED.  Current triggers are:
-     "backlight" - LED will act as a back-light, controlled by the framebuffer
-		   system
-     "default-on" - LED will turn on (but for leds-gpio see "default-state"
-		    property in Documentation/devicetree/bindings/gpio/led.txt)
-     "heartbeat" - LED "double" flashes at a load average based rate
-     "ide-disk" - LED indicates disk activity
-     "timer" - LED flashes at a fixed, configurable rate
-
-Examples:
-
-system-status {
-	label = "Status";
-	linux,default-trigger = "heartbeat";
-	...
-};
Signature · 1 line
2.20.1
Reviewed-by on v4 1/2
#2 lore raw

Re: [PATCH v4 1/2] doc: remove redundant leds bindings

Quoted 7 lines · Heiko Schocher

remove file doc/device-tree-bindings/leds/common.txt as we have this now already in dts/upstream/include/dt-bindings/leds/common.h which is imported from linux.

Signature · 1 line
Tom
#3 lore raw

PATCH v4 2/2 led: add function naming option from linux

In reply to Heiko Schocher

in linux we have the option to create the name of a led optionally through the following properties:

- function
- color
- function-enumerator

This patch adds support for parsing this properties if there is no label property.

The led name is created in led_post_bind() and we need some storage place for it. Currently this patch prevents to use malloc() instead it stores the name in new member :

        char name[LED_MAX_NAME_SIZE];

of struct led_uc_plat. While at it append led tests for the new feature.

---

Changes in v4:
- remove ./doc/device-tree-bindings/leds/common.txt in
seperate patch as this is now already in ./dts/upstream/Bindings/leds/common.txt
as Tom commented.
measured size impact of patch "led: add function naming option from linux":

        $ ./u-boot-size-test.sh capricorn_cxg3 --branch led-mainline
        [...]
           aarch64: (for 1/1 boards) all +886.0 rodata +230.0 text +656.0
                    capricorn_cxg3 : all +886 rodata +230 text +656
                       u-boot: add: 1/0, grow: 1/0 bytes: 416/0 (416)
                         function                                   old     new   delta
                         led_post_bind                              220     516    +296
                         led_colors                                   -     120    +120
        $ ./u-boot-size-test.sh aristainetos2c --branch led-mainline
        [...]
        01: Merge patch series "add the support of sha256_hmac and sha256_hkdf"
        40: led: add function naming option from linux
               arm: (for 2/2 boards) all +557.0 bss +20.0 rodata +161.0 text +376.0
                    aristainetos2c : all +557 bss +20 rodata +161 text +376
                       u-boot: add: 1/0, grow: 1/0 bytes: 264/0 (264)
                         function                                   old     new   delta
                         led_post_bind                              128     332    +204
                         led_colors                                   -      60     +60
                    aristainetos2ccslb: all +557 bss +20 rodata +161 text +376
                       u-boot: add: 1/0, grow: 1/0 bytes: 264/0 (264)
                         function                                   old     new   delta
                         led_post_bind                              128     332    +204
                         led_colors                                   -      60     +60
- rebase to current HEAD
  d8a7100d658. ("Subtree merge tag 'v6.13-dts' of dts repo [1] into dts/upstream")

Changes in v3:
- work in comment from Tom:
remove new file include/dt-bindings/leds/common.h in this patch as it is already in dts/upstream/include/dt-bindings/leds/common.h and so the checkpatch warnings from this file are gone! Thanks! Good catch!
remove file include/linux/uapi/linux/uleds.h and
as we only need one define from it, add this define
in include/led.h

Changes in v2:
- remove unused name variable in function led_get_label()
- rebased patch to current HEAD
82d262ae162 ("Merge patch series "MediaTek MT7629 OF_UPSTREAM migration (v2)"")

 arch/sandbox/dts/test.dts | 37 ++++++++++++++++++++-
 drivers/led/led-uclass.c  | 70 ++++++++++++++++++++++++++++++++++++---
 include/led.h             |  6 ++++
 test/dm/led.c             | 22 +++++++++++-
 test/dm/ofnode.c          |  2 +-
 5 files changed, 130 insertions(+), 7 deletions(-)
arch/sandbox/dts/test.dts +36 -1
index ae52b375ccb..b8f3012873e 100644
@@ -13,6 +13,7 @@
 #include <dt-bindings/gpio/gpio.h>
 #include <dt-bindings/gpio/sandbox-gpio.h>
 #include <dt-bindings/input/input.h>
+#include <dt-bindings/leds/common.h>
 #include <dt-bindings/pinctrl/sandbox-pinmux.h>
 #include <dt-bindings/mux/mux.h>
 
@@ -820,7 +821,7 @@
 			gpio-controller;
 			#gpio-cells = <1>;
 			gpio-bank-name = "a";
-			sandbox,gpio-count = <20>;
+			sandbox,gpio-count = <25>;
 			hog_input_active_low {
 				gpio-hog;
 				input;
@@ -1010,6 +1011,40 @@
 			/* label intentionally omitted */
 			default-state = "off";
 		};
+
+		led-20 {
+			gpios = <&gpio_a 20 0>;
+			/* label intentionally omitted */
+			function = LED_FUNCTION_STATUS;
+			color = <LED_COLOR_ID_RED>;
+			function-enumerator = <20>;
+		};
+
+		led-21 {
+			gpios = <&gpio_a 21 0>;
+			/* label intentionally omitted */
+			function = LED_FUNCTION_STATUS;
+			color = <LED_COLOR_ID_GREEN>;
+		};
+
+		led-22 {
+			gpios = <&gpio_a 22 0>;
+			/* label intentionally omitted */
+			function = LED_FUNCTION_STATUS;
+		};
+
+		led-23 {
+			gpios = <&gpio_a 23 0>;
+			/* label intentionally omitted */
+			color = <LED_COLOR_ID_GREEN>;
+		};
+
+		led-24 {
+			gpios = <&gpio_a 24 0>;
+			label = "sandbox:function";
+			function = LED_FUNCTION_STATUS;
+			color = <LED_COLOR_ID_GREEN>;
+		};
 	};
 
 	wdt-gpio-toggle {
drivers/led/led-uclass.c +66 -4

104 lines not on this page · raw message

include/led.h +6 -0
index 64247cd3a70..a67db7af38d 100644
@@ -53,6 +53,11 @@
 
 struct udevice;
 
+/*
+ * value imported from linux:include/linux/uapi/linux/uleds.h
+ */
+#define LED_MAX_NAME_SIZE      64
+
 enum led_state_t {
 	LEDST_OFF = 0,
 	LEDST_ON = 1,
@@ -86,6 +91,7 @@ struct led_sw_blink {
 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
test/dm/led.c +21 -1
index e5b86326c3a..36652c2833a 100644
@@ -20,7 +20,12 @@ static int dm_test_led_base(struct unit_test_state *uts)
 	ut_assertok(uclass_get_device(UCLASS_LED, 1, &dev));
 	ut_assertok(uclass_get_device(UCLASS_LED, 2, &dev));
 	ut_assertok(uclass_get_device(UCLASS_LED, 3, &dev));
-	ut_asserteq(-ENODEV, uclass_get_device(UCLASS_LED, 4, &dev));
+	ut_assertok(uclass_get_device(UCLASS_LED, 4, &dev));
+	ut_assertok(uclass_get_device(UCLASS_LED, 5, &dev));
+	ut_assertok(uclass_get_device(UCLASS_LED, 6, &dev));
+	ut_assertok(uclass_get_device(UCLASS_LED, 7, &dev));
+	ut_assertok(uclass_get_device(UCLASS_LED, 8, &dev));
+	ut_asserteq(-ENODEV, uclass_get_device(UCLASS_LED, 9, &dev));
 
 	return 0;
 }
@@ -110,6 +115,21 @@ static int dm_test_led_label(struct unit_test_state *uts)
 
 	ut_asserteq(-ENODEV, led_get_by_label("sandbox:blue", &dev));
 
+	/* Test if function, color and function-enumerator naming works */
+	ut_assertok(led_get_by_label("red:status-20", &dev));
+
+	/* Test if function, color naming works */
+	ut_assertok(led_get_by_label("green:status", &dev));
+
+	/* Test if function, without color naming works */
+	ut_assertok(led_get_by_label(":status", &dev));
+
+	/* Test if color without function naming works */
+	ut_assertok(led_get_by_label("green:", &dev));
+
+	/* Test if function, color naming is ignored if label is found */
+	ut_assertok(led_get_by_label("sandbox:function", &dev));
+
 	return 0;
 }
 DM_TEST(dm_test_led_label, UTF_SCAN_PDATA | UTF_SCAN_FDT);
test/dm/ofnode.c +1 -1
index 4a23a3ca38c..cc8b444ff9a 100644
@@ -1599,7 +1599,7 @@ static int dm_test_ofnode_delete(struct unit_test_state *uts)
 	ut_assert(!ofnode_valid(node));
 	ut_assert(!ofnode_valid(ofnode_path("/leds/default_on")));
 
-	ut_asserteq(2, ofnode_get_child_count(ofnode_path("/leds")));
+	ut_asserteq(7, ofnode_get_child_count(ofnode_path("/leds")));
 
 	return 0;
 }
Signature · 1 line
2.20.1
Reviewed-by on v4 2/2
#4 lore raw
Quoted 14 lines · Heiko Schocher

in linux we have the option to create the name of a led optionally through the following properties:

- function
- color
- function-enumerator

This patch adds support for parsing this properties if there is no label property.

The led name is created in led_post_bind() and we need some storage place for it. Currently this patch prevents to use malloc() instead it stores the name in new member :

Quoted 6 lines
        char name[LED_MAX_NAME_SIZE];

of struct led_uc_plat. While at it append led tests for the new feature.

Signature · 1 line
Tom
#5 lore raw
In reply to Heiko Schocher
Quoted 8 lines · Heiko Schocher

in linux we have the option to create the name of a led optionally through the following properties:

- function
- color
- function-enumerator

[...]

Applied to u-boot/master, thanks!

Signature · 1 line
Tom