Skip to contentSkip to conversation

leds-lp50xx: Support reg to set multi_index.

RFC PATCH Superseded Johan Adolfsson 4 participants 10 messages May 26, 2025 – Jun 19, 2025

Subsystems (2)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 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 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         | 19 ++++++++++++-------
 drivers/leds/leds-lp50xx.c                            |  8 +++++++-
 2 files changed, 19 insertions(+), 8 deletions(-)

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

Best regards,

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

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

mc_subled used for multi_index needs well defined array indexes, to guarantee the desired result, optionally 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, the previous behavior is kept, index will be in the order nodes are processed.
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 | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/leds/leds-lp50xx.c +7 -1
index 02cb1565a9fb..8067aaa916bf 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,13 @@ 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 && 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
#2 lore raw

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

Hi Johan,

Quoted 10 lines · Johan Adolfsson

mc_subled used for multi_index needs well defined array indexes, to guarantee the desired result, optionally 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).

Quoted 5 lines

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, the previous behavior is kept, index will be in the order nodes are processed.

This is a bug and I don't see any value in keeping buggy code. Just expect reg to be present and make sure that all in-tree dts files using these bindings use them in a proper way.

To not break existing users of stable releases, if any of them implement DT subnodes without 'reg' property, we can just not mark this commit with "Fixed" tag, so that it wasn't applied to stable releases. Although I am not sure if we should not fix it there as well. I'm leaving it to Lee.

Quoted 36 lines

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 | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
drivers/leds/leds-lp50xx.c +7 -1
index 02cb1565a9fb..8067aaa916bf 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,13 @@ 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 && 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
maintainer
#3 lore raw

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

Quoted 23 lines · Jacek Anaszewski

Hi Johan,

Quoted 10 lines · Johan Adolfsson

mc_subled used for multi_index needs well defined array indexes, to guarantee the desired result, optionally 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).

Quoted 5 lines

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, the previous behavior is kept, index will be in the order nodes are processed.

This is a bug and I don't see any value in keeping buggy code. Just expect reg to be present and make sure that all in-tree dts files using these bindings use them in a proper way.

Quoted 5 lines

To not break existing users of stable releases, if any of them implement DT subnodes without 'reg' property, we can just not mark this commit with "Fixed" tag, so that it wasn't applied to stable releases. Although I am not sure if we should not fix it there as well. I'm leaving it to Lee.

We cannot assume that a patch won't end up in LTS just by omitting the
Fixes: tag. Sasha's AUTOSEL tooling it still likely to pick it up if we describe the commit as a fix, which we do and is correct.

I see no reason not to apply it. If users are relying on broken semantics, then those should be fixed also.

Is everyone happy with this patch as-is?

Quoted 38 lines
Quoted 33 lines

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 | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
drivers/leds/leds-lp50xx.c +7 -1
index 02cb1565a9fb..8067aaa916bf 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,13 @@ 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 && 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
Signature · 1 line
Lee Jones [李琼斯]
#4 lore raw

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

Quoted 31 lines · Lee Jones
Quoted 23 lines · Jacek Anaszewski

Hi Johan,

Quoted 10 lines · Johan Adolfsson

mc_subled used for multi_index needs well defined array indexes, to guarantee the desired result, optionally 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).

Quoted 5 lines

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, the previous behavior is kept, index will be in the order nodes are processed.

This is a bug and I don't see any value in keeping buggy code. Just expect reg to be present and make sure that all in-tree dts files using these bindings use them in a proper way.

Quoted 5 lines

To not break existing users of stable releases, if any of them implement DT subnodes without 'reg' property, we can just not mark this commit with "Fixed" tag, so that it wasn't applied to stable releases. Although I am not sure if we should not fix it there as well. I'm leaving it to Lee.

Quoted 8 lines

We cannot assume that a patch won't end up in LTS just by omitting the
Fixes: tag. Sasha's AUTOSEL tooling it still likely to pick it up if we describe the commit as a fix, which we do and is correct.

I see no reason not to apply it. If users are relying on broken semantics, then those should be fixed also.

Is everyone happy with this patch as-is?

Nope, we should require presence of proper 'reg' value then.

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines

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 | 8 +++++++-
   1 file changed, 7 insertions(+), 1 deletion(-)
drivers/leds/leds-lp50xx.c +1 -0
index 02cb1565a9fb..8067aaa916bf 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",
Quoted 8 lines
Quoted 8 lines

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

Quoted 8 lines
drivers/leds/leds-lp50xx.c +2 -0
   						       &color_id);
   			if (ret) {
@@ -483,8 +484,13 @@ 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 && multi_index >= LP50XX_LEDS_PER_MODULE) {

Here we should fail if 'reg' is not present too.

Quoted 14 lines
Quoted 13 lines
Quoted 8 lines
drivers/leds/leds-lp50xx.c +4 -1
+				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
Signature · 2 lines
Best regards,
Jacek Anaszewski
maintainer
#5 lore raw

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

Quoted 62 lines · Jacek Anaszewski
Quoted 31 lines · Lee Jones
Quoted 23 lines · Jacek Anaszewski

Hi Johan,

Quoted 10 lines · Johan Adolfsson

mc_subled used for multi_index needs well defined array indexes, to guarantee the desired result, optionally 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).

Quoted 5 lines

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, the previous behavior is kept, index will be in the order nodes are processed.

This is a bug and I don't see any value in keeping buggy code. Just expect reg to be present and make sure that all in-tree dts files using these bindings use them in a proper way.

Quoted 5 lines

To not break existing users of stable releases, if any of them implement DT subnodes without 'reg' property, we can just not mark this commit with "Fixed" tag, so that it wasn't applied to stable releases. Although I am not sure if we should not fix it there as well. I'm leaving it to Lee.

Quoted 8 lines

We cannot assume that a patch won't end up in LTS just by omitting the
Fixes: tag. Sasha's AUTOSEL tooling it still likely to pick it up if we describe the commit as a fix, which we do and is correct.

I see no reason not to apply it. If users are relying on broken semantics, then those should be fixed also.

Is everyone happy with this patch as-is?

Nope, we should require presence of proper 'reg' value then.

Quoted 19 lines
Quoted 19 lines
Quoted 19 lines

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 | 8 +++++++-
   1 file changed, 7 insertions(+), 1 deletion(-)
drivers/leds/leds-lp50xx.c +1 -0
index 02cb1565a9fb..8067aaa916bf 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) {
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines

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

Quoted 6 lines
drivers/leds/leds-lp50xx.c +2 -0
@@ -483,8 +484,13 @@ 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 && multi_index >= LP50XX_LEDS_PER_MODULE) {

Here we should fail if 'reg' is not present too.

Works for me.

Signature · 1 line
Lee Jones [李琼斯]
#6 lore raw

RFC PATCH v4 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         | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
Documentation/devicetree/bindings/leds/leds-lp50xx.yaml +12 -7
index 402c25424525..a7b2d87cc39d 100644
@@ -81,7 +81,12 @@ patternProperties:
 
         properties:
           reg:
-            maxItems: 1
+            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 +143,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
#7 lore raw

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

Quoted 13 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         | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
Documentation/devicetree/bindings/leds/leds-lp50xx.yaml +0 -0
index 402c25424525..a7b2d87cc39d 100644

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

Quoted 6 lines
Documentation/devicetree/bindings/leds/leds-lp50xx.yaml +2 -1
@@ -81,7 +81,12 @@ patternProperties:
 
         properties:
           reg:
-            maxItems: 1
+            minimum: 0
+            maximum: 2

"not compatible with minimum
and maximum."

No, it is compatible. Just do:

items:
- minimum: 0
maximum: 2

You call this patchset still an RFC, which usually means - do not review, not ready. Usually when I review RFC I received negative response that why do I review it... Therefore I tend to don't care about RFC. Some maintainers completely ignore RFC.

Please EXPLICITLY document in cover letter why this is RFC and what you expect from us (IOW, why this is not ready for review).

If dropping RFC, keep versioning (people also tend to do it wrong completely messing up the tools), although I see you use b4, so this should be without problem.

Best regards,
Krzysztof

#8 lore raw

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

Quoted 32 lines

From: Krzysztof Kozlowski <[email protected]>
Sent: Monday, May 26, 2025 17:34
To: Johan Adolfsson; Lee Jones; Pavel Machek; Rob Herring; Krzysztof Kozlowski; Conor Dooley; Andrew Davis; Jacek Anaszewski
Cc: [email protected]; [email protected]; [email protected]; Kernel
Subject: Re: [PATCH RFC v4 2/2] dt-bindings: leds: lp50xx: Document child reg, fix example

Quoted 13 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         | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
Documentation/devicetree/bindings/leds/leds-lp50xx.yaml +0 -0
index 402c25424525..a7b2d87cc39d 100644

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

Quoted 6 lines
Documentation/devicetree/bindings/leds/leds-lp50xx.yaml +2 -1
@@ -81,7 +81,12 @@ patternProperties:
 
         properties:
           reg:
-            maxItems: 1
+            minimum: 0
+            maximum: 2

"not compatible with minimum
and maximum."

Quoted 5 lines

No, it is compatible. Just do:

items:
- minimum: 0
maximum: 2

I have tried every variant of that I can think of and can't make it pass the check:
DT_SCHEMA_FILES="Documentation/devicetree/bindings/leds/leds-lp50xx.yaml" make dt_binding_check

Exactly how should it look like?

Quoted 8 lines

You call this patchset still an RFC, which usually means - do not review, not ready. Usually when I review RFC I received negative response that why do I review it... Therefore I tend to don't care about RFC. Some maintainers completely ignore RFC.

Please EXPLICITLY document in cover letter why this is RFC and what you expect from us (IOW, why this is not ready for review).

Quoted 6 lines

If dropping RFC, keep versioning (people also tend to do it wrong completely messing up the tools), although I see you use b4, so this should be without problem.

Best regards,
Krzysztof

Thank you for your patience!
I think its' ready for review now, If I can figure out the correct syntax for maxItems together with minimum and maximum (if we need maxItems?) or would v4 be acceptable?

Best regards
/Johan

#9 lore raw

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

Quoted 16 lines · Johan Adolfsson
Quoted 16 lines

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

Quoted 11 lines
Documentation/devicetree/bindings/leds/leds-lp50xx.yaml +2 -1
index 402c25424525..a7b2d87cc39d 100644
@@ -81,7 +81,12 @@ patternProperties:
 
         properties:
           reg:
-            maxItems: 1
+            minimum: 0
+            maximum: 2

"not compatible with minimum
and maximum."

No, it is compatible. Just do:

Quoted 8 lines
Quoted 3 lines

items:
- minimum: 0
maximum: 2

I have tried every variant of that I can think of and can't make it pass the check:
DT_SCHEMA_FILES="Documentation/devicetree/bindings/leds/leds-lp50xx.yaml" make dt_binding_check

Exactly how should it look like?

I pasted the exact syntax.

Best regards,
Krzysztof