Skip to contentSkip to conversation

leds-lp50xx: Support reg to set multi_index.

PATCH Superseded Johan Adolfsson 3 participants 7 messages Jun 16, 2025 – Jun 17, 2025 1 message not in the archive

Subsystems (2)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#1 lore raw

PATCH v6 1/2 leds: leds-lp50xx: Handle reg to get correct multi_index

In reply to Johan Adolfsson

mc_subled used for multi_index needs well defined array indexes, to guarantee the desired result, use reg for that.

If devicetree child nodes is processed in random or reverse order you may end up with multi_index "blue green red" instead of the expected "red green blue".
If user space apps uses multi_index to deduce how to control the leds they would most likely be broken without this patch if devicetree processing is reversed (which it appears to be).

arch/arm/boot/dts/aspeed/aspeed-bmc-facebook-fuji.dts has reg set but I don't see how it can have worked without this change.

If reg is not set, an error is returned,
If reg is out of range, an error is returned.
reg within led child nodes starts with 0, to map to the iout in each bank.

---
 drivers/leds/leds-lp50xx.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/leds/leds-lp50xx.c +10 -1
index 02cb1565a9fb..344791b6c575 100644
@@ -476,6 +476,7 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
 			return -ENOMEM;
 
 		fwnode_for_each_child_node(child, led_node) {
+			int multi_index = num_colors;
 			ret = fwnode_property_read_u32(led_node, "color",
 						       &color_id);
 			if (ret) {
@@ -483,8 +484,16 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
 				dev_err(priv->dev, "Cannot read color\n");
 				return ret;
 			}
+			ret = fwnode_property_read_u32(led_node, "reg", &multi_index);
+			if (ret != 0) {
+				dev_err(priv->dev, "reg must be set\n");
+				return -EINVAL;
+			} else if (multi_index >= LP50XX_LEDS_PER_MODULE) {
+				dev_err(priv->dev, "reg %i out of range\n", multi_index);
+				return -EINVAL;
+			}
 
-			mc_led_info[num_colors].color_index = color_id;
+			mc_led_info[multi_index].color_index = color_id;
 			num_colors++;
 		}
 
Signature · 1 line
2.30.2
#4 lore raw

PATCH v6 2/2 dt-bindings: leds: lp50xx: Document child reg, fix example

In reply to Johan Adolfsson

The led child reg node is the index within the bank, document that and update the example accordingly.

---
 .../devicetree/bindings/leds/leds-lp50xx.yaml       | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
Documentation/devicetree/bindings/leds/leds-lp50xx.yaml +14 -7
index 402c25424525..cb450aed718c 100644
@@ -81,7 +81,14 @@ patternProperties:
 
         properties:
           reg:
-            maxItems: 1
+            items:
+              - minimum: 0
+                maximum: 2
+
+            description:
+              This property denotes the index within the LED bank.
+              The value will act as the index in the multi_index file to give
+              consistent result independent of devicetree processing order.
 
         required:
           - reg
@@ -138,18 +145,18 @@ examples:
                 color = <LED_COLOR_ID_RGB>;
                 function = LED_FUNCTION_STANDBY;
 
-                led@3 {
-                    reg = <0x3>;
+                led@0 {
+                    reg = <0x0>;
                     color = <LED_COLOR_ID_RED>;
                 };
 
-                led@4 {
-                    reg = <0x4>;
+                led@1 {
+                    reg = <0x1>;
                     color = <LED_COLOR_ID_GREEN>;
                 };
 
-                led@5 {
-                    reg = <0x5>;
+                led@2 {
+                    reg = <0x2>;
                     color = <LED_COLOR_ID_BLUE>;
                 };
             };
Signature · 1 line
2.30.2
#0 lore raw

v6 cover leds-lp50xx: Support reg to set multi_index.

Since devicetree nodes are (sometimes?) processed in reverse order, support reg as the actual multi_index index so yo get well defined color order presented in the multi_index file.
Not sure if reusing reg for this is the correct way or if another property such as "multi_index" or similar should be used instead. Looks like reg is used for similar things at least.
Or should the whole "reverse the devicetree" problem be fixed instead? Update bindings to match implementation, and add description for the reg property.

---
Changes in v6:
- Remove maxItems från devicetree binding
- Link to v5: https://lore.kernel.org/r/[email protected]

Changes in v5:
- Fail if reg is not set.
- Adjust devicetree schema, use items.
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Remove maxItems from devicetree schema, not compatible with minimum and maximum.
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Update To and Cc.
- Rephrase bindings descriptions, add constraints.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Avoid duplicate assignment. dev_err and return -EINVAL on error.
- Update bindings doc.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Johan Adolfsson (2):

      leds: leds-lp50xx: Handle reg to get correct multi_index
      dt-bindings: leds: lp50xx: Document child reg, fix example
 .../devicetree/bindings/leds/leds-lp50xx.yaml       | 21 ++++++++++++++-------
 drivers/leds/leds-lp50xx.c                          | 11 ++++++++++-
 2 files changed, 24 insertions(+), 8 deletions(-)

---
base-commit: 0ff41df1cb268fc69e703a08a57ee14ae967d0ca
change-id: 20250225-led-fix-444fb544584a

Best regards,

Signature · 1 line
Johan Adolfsson <[email protected]>
#5 lore raw

Re: [PATCH v6 2/2] dt-bindings: leds: lp50xx: Document child reg, fix example

In reply to Johan Adolfsson
Quoted 16 lines · Johan Adolfsson

The led child reg node is the index within the bank, document that and update the example accordingly.

---
 .../devicetree/bindings/leds/leds-lp50xx.yaml       | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
Documentation/devicetree/bindings/leds/leds-lp50xx.yaml +0 -0
index 402c25424525..cb450aed718c 100644
@@ -81,7 +81,14 @@ patternProperties:
 
         properties:
           reg:

Documentation/devicetree/bindings/leds/leds-lp50xx.yaml patternProperties: · line 92

Quoted 10 lines
Documentation/devicetree/bindings/leds/leds-lp50xx.yaml +8 -1
-            maxItems: 1
+            items:
+              - minimum: 0
+                maximum: 2
+
+            description:
+              This property denotes the index within the LED bank.
 
+              The value will act as the index in the multi_index file to give
+              consistent result independent of devicetree processing order.

This looks like commentary on the particulars of the driver implementation in linux, which shouldn't be in a binding.

Documentation/devicetree/bindings/leds/leds-lp50xx.yaml examples: · line 149

Quoted 11 lines
Documentation/devicetree/bindings/leds/leds-lp50xx.yaml +2 -2
         required:
           - reg
@@ -138,18 +145,18 @@ examples:
                 color = <LED_COLOR_ID_RGB>;
                 function = LED_FUNCTION_STANDBY;
 
-                led@3 {
-                    reg = <0x3>;
+                led@0 {
+                    reg = <0x0>;

Do you have any explanation for why these numbers, outside the range you said is valid, were in the binding's example?
Additionally, can you mention in the commit message what the source was for the 0-2 range?

Cheers,
Conor.

Quoted 21 lines
Documentation/devicetree/bindings/leds/leds-lp50xx.yaml +4 -4
                     color = <LED_COLOR_ID_RED>;
                 };
 
-                led@4 {
-                    reg = <0x4>;
+                led@1 {
+                    reg = <0x1>;
                     color = <LED_COLOR_ID_GREEN>;
                 };
 
-                led@5 {
-                    reg = <0x5>;
+                led@2 {
+                    reg = <0x2>;
                     color = <LED_COLOR_ID_BLUE>;
                 };
             };
Signature · 2 lines
-- 
2.30.2
#7 lore raw

Re: [PATCH v6 2/2] dt-bindings: leds: lp50xx: Document child reg, fix example

In reply to a message not in the archive
Quoted 36 lines · Johan Adolfsson

________________________________
From: Conor Dooley
Sent: Monday, June 16, 2025 17:03
To: Johan Adolfsson
Cc: Lee Jones; Pavel Machek; Rob Herring; Krzysztof Kozlowski; Conor Dooley; Andrew Davis; Jacek Anaszewski; [email protected]; [email protected]; [email protected]; Kernel
Subject: Re: [PATCH v6 2/2] dt-bindings: leds: lp50xx: Document child reg, fix example

Quoted 27 lines · Johan Adolfsson

The led child reg node is the index within the bank, document that and update the example accordingly.

---
 .../devicetree/bindings/leds/leds-lp50xx.yaml       | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
Documentation/devicetree/bindings/leds/leds-lp50xx.yaml +0 -0
index 402c25424525..cb450aed718c 100644
@@ -81,7 +81,14 @@ patternProperties:
 
Quoted 12 lines

properties:
reg:

Documentation/devicetree/bindings/leds/leds-lp50xx.yaml +8 -1
-            maxItems: 1
+            items:
+              - minimum: 0
+                maximum: 2
+
+            description:
+              This property denotes the index within the LED bank.
 
+              The value will act as the index in the multi_index file to give
+              consistent result independent of devicetree processing order.
Quoted 6 lines
Quoted 2 lines

This looks like commentary on the particulars of the driver implementation in linux, which shouldn't be in a binding.

Just trying to explain what the reg value actually does (and why).
Before my patch the bindings were there but no code that handled it.
If the weird reverse processing order wasn't a thing there would not have been a problem.

That's all driver implementation detail that another OS might not care about if implemented differently, and is therefore not permitted in the binding. The text about "index within the LED bank" should be sufficient to describe how the hardware is configured, no?

Quoted 25 lines
Quoted 6 lines
Quoted 6 lines

required:
- reg

Documentation/devicetree/bindings/leds/leds-lp50xx.yaml +0 -0
@@ -138,18 +145,18 @@ examples:
                 color = <LED_COLOR_ID_RGB>;
                 function = LED_FUNCTION_STANDBY;
 
Quoted 7 lines

Documentation/devicetree/bindings/leds/leds-lp50xx.yaml examples: · line 149

Quoted 4 lines
Documentation/devicetree/bindings/leds/leds-lp50xx.yaml +2 -2
-                led@3 {
-                    reg = <0x3>;
+                led@0 {
+                    reg = <0x0>;

Do you have any explanation for why these numbers, outside the range you said is valid, were in the binding's example?

No idea, the driver hasn't handled the reg property on the led child until my patch, but the property was introduced by this commit:
commit 3eb229f203c2bc42efbfbafba7f83c8deeca80c9

Author: Krzysztof Kozlowski <[email protected]>
Date:   Tue Jun 7 09:52:46 2022 +0200

dt-bindings: leds: lp50xx: correct reg/unit addresses in example

The multi-led node defined address/size cells, so it is intended to have children with unit addresses.

Quoted 7 lines

The second multi-led's reg property defined three LED indexes within one reg item, which is not correct - these are three separate items.

Right, so random shite that Krzysztof put in, based on the reg property in the multi-led parent, to satisfy the tooling. It's worth mentioning in your commit message that these values you're replacing were speculative.

Quoted 3 lines
Quoted 2 lines

Additionally, can you mention in the commit message what the source was for the 0-2 range?

The LED driver chip has banks with 3 outputs each, this is how I have interpreted what the code does.

Please put that in the commit message.

Reviewed-by on v6 1/2
#2 lore raw

Re: [PATCH v6 1/2] leds: leds-lp50xx: Handle reg to get correct multi_index

In reply to Johan Adolfsson

Hi Johan,

Quoted 27 lines · Johan Adolfsson

mc_subled used for multi_index needs well defined array indexes, to guarantee the desired result, use reg for that.

If devicetree child nodes is processed in random or reverse order you may end up with multi_index "blue green red" instead of the expected "red green blue".
If user space apps uses multi_index to deduce how to control the leds they would most likely be broken without this patch if devicetree processing is reversed (which it appears to be).

arch/arm/boot/dts/aspeed/aspeed-bmc-facebook-fuji.dts has reg set but I don't see how it can have worked without this change.

If reg is not set, an error is returned,
If reg is out of range, an error is returned.
reg within led child nodes starts with 0, to map to the iout in each bank.

---
  drivers/leds/leds-lp50xx.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
drivers/leds/leds-lp50xx.c +0 -0
index 02cb1565a9fb..344791b6c575 100644

drivers/leds/leds-lp50xx.c static int lp50xx_probe_dt(struct lp50xx *priv) · line 479

Quoted 4 lines
drivers/leds/leds-lp50xx.c +1 -0
@@ -476,6 +476,7 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
  			return -ENOMEM;
 
  		fwnode_for_each_child_node(child, led_node) {
+			int multi_index = num_colors;

Any specific reason for initializing this to num_colors?

Quoted 12 lines
drivers/leds/leds-lp50xx.c +4 -0
  			ret = fwnode_property_read_u32(led_node, "color",
  						       &color_id);
  			if (ret) {
@@ -483,8 +484,16 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
  				dev_err(priv->dev, "Cannot read color\n");
  				return ret;
  			}
+			ret = fwnode_property_read_u32(led_node, "reg", &multi_index);
+			if (ret != 0) {
+				dev_err(priv->dev, "reg must be set\n");
+				return -EINVAL;

drivers/leds/leds-lp50xx.c static int lp50xx_probe_dt(struct lp50xx *priv) · line 499

Quoted 10 lines
drivers/leds/leds-lp50xx.c +5 -1
+			} else if (multi_index >= LP50XX_LEDS_PER_MODULE) {
+				dev_err(priv->dev, "reg %i out of range\n", multi_index);
+				return -EINVAL;
+			}
 
-			mc_led_info[num_colors].color_index = color_id;
+			mc_led_info[multi_index].color_index = color_id;
  			num_colors++;
  		}
 
Signature · 2 lines
Best regards,
Jacek Anaszewski
#3 lore raw

Re: [PATCH v6 1/2] leds: leds-lp50xx: Handle reg to get correct multi_index

Hi Jacek.

Quoted 9 lines

From: Jacek Anaszewski <[email protected]>
Sent: Monday, June 16, 2025 23:29
To: Johan Adolfsson; Lee Jones; Pavel Machek; Rob Herring; Krzysztof Kozlowski; Conor Dooley; Andrew Davis
Cc: [email protected]; [email protected]; [email protected]; Kernel
Subject: Re: [PATCH v6 1/2] leds: leds-lp50xx: Handle reg to get correct multi_index

Hi Johan,

On 6/16/25 13:25, Johan Adolfsson wrote:

..

Quoted 10 lines
Quoted 10 lines
  drivers/leds/leds-lp50xx.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
drivers/leds/leds-lp50xx.c +0 -0
index 02cb1565a9fb..344791b6c575 100644
@@ -476,6 +476,7 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
                      return -ENOMEM;
 
Quoted 4 lines

drivers/leds/leds-lp50xx.c static int lp50xx_probe_dt(struct lp50xx *priv) · line 479

Quoted 2 lines
drivers/leds/leds-lp50xx.c +1 -0
              fwnode_for_each_child_node(child, led_node) {
+                     int multi_index = num_colors;

Any specific reason for initializing this to num_colors?

Sorry - leftover from initial patch where I kept the original behavior if reg was not set. Another patch version coming up soon (assuming failing on reg not set is the agreed upon solution).

Quoted 4 lines
Quoted 1 line

--
Best regards,
Jacek Anaszewski

Best regards
/Johan