Skip to contentSkip to conversation

leds: pwm: Add default-brightness property

PATCH Superseded George Stark 3 participants 6 messages Nov 1, 2024 – Nov 5, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover leds: pwm: Add default-brightness property

led-pwm driver supports default-state DT property and if that state is on then the driver during initialization turns on the LED setting maximum brightness. Sometimes it's desirable to use lower initial brightness.
This patch series adds support for DT property default-brightness.

Things to discuss:
If such a property is acceptable it could be moved to leds/common.yaml due to several drivers support multiple brightness levels and could support the property too.

Changes in v2:
leds: pwm: Add optional DT property default-brightness
- refactor patch to make it more accurate
link to v1: [1]

[1] https://lore.kernel.org/lkml/[email protected]/T/

George Stark (2):
dt-bindings: leds: pwm: Add default-brightness property
leds: pwm: Add optional DT property default-brightness

 .../devicetree/bindings/leds/leds-pwm.yaml      |  6 ++++++
 drivers/leds/leds-pwm.c                         | 17 ++++++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

--
2.25.1

#1 lore raw

PATCH v2 1/2 dt-bindings: leds: pwm: Add default-brightness property

Optional default-brightness property specifies brightness value to be used if default LED state is on.

---
 Documentation/devicetree/bindings/leds/leds-pwm.yaml | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/leds/leds-pwm.yaml +6 -0
index 113b7c218303..61b97e8bc36d 100644
@@ -34,6 +34,12 @@ patternProperties:
           Maximum brightness possible for the LED
         $ref: /schemas/types.yaml#/definitions/uint32
 
+      default-brightness:
+        description:
+          Brightness to be set if LED's default state is on. Used only during
+          initialization. If the option is not set then max brightness is used.
+        $ref: /schemas/types.yaml#/definitions/uint32
+
     required:
       - pwms
       - max-brightness
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH v2 1/2] dt-bindings: leds: pwm: Add default-brightness property

Quoted 8 lines · George Stark

Optional default-brightness property specifies brightness value to be used if default LED state is on.

---
 Documentation/devicetree/bindings/leds/leds-pwm.yaml | 6 ++++++
 1 file changed, 6 insertions(+)

<form letter>
This is a friendly reminder during the review process.

It looks like you received a tag and forgot to add it.

If you do not know the process, here is a short explanation: Please add Acked-by/Reviewed-by/Tested-by tags when posting new versions, under or above your Signed-off-by tag. Tag is "received", when provided in a message replied to you on the mailing list. Tools like b4 can help here. However, there's no need to repost patches *only* to add the tags. The upstream maintainer will do that for tags received on the version they apply.

https://elixir.bootlin.com/linux/v6.5-rc3/source/Documentation/process/submitting-patches.rst#L577

If a tag was not added on purpose, please state why and what changed. </form letter>

Best regards,
Krzysztof

#3 lore raw

Re: [PATCH v2 1/2] dt-bindings: leds: pwm: Add default-brightness property

Hello Krzysztof, Rob

Thanks for noticing it, missed the tag not by purpose, sorry about it. Sure I'll add the tag to v3 if v3 happens.

Quoted 31 lines · Krzysztof Kozlowski
Quoted 8 lines · George Stark

Optional default-brightness property specifies brightness value to be used if default LED state is on.

---
  Documentation/devicetree/bindings/leds/leds-pwm.yaml | 6 ++++++
  1 file changed, 6 insertions(+)

<form letter>
This is a friendly reminder during the review process.

It looks like you received a tag and forgot to add it.

If you do not know the process, here is a short explanation: Please add Acked-by/Reviewed-by/Tested-by tags when posting new versions, under or above your Signed-off-by tag. Tag is "received", when provided in a message replied to you on the mailing list. Tools like b4 can help here. However, there's no need to repost patches *only* to add the tags. The upstream maintainer will do that for tags received on the version they apply.

https://elixir.bootlin.com/linux/v6.5-rc3/source/Documentation/process/submitting-patches.rst#L577

If a tag was not added on purpose, please state why and what changed. </form letter>

Best regards,
Krzysztof

Signature · 2 lines
Best regards
George
maintainer
#4 lore raw

Re: [PATCH v2 1/2] dt-bindings: leds: pwm: Add default-brightness property

Quoted 4 lines · George Stark

Hello Krzysztof, Rob

Thanks for noticing it, missed the tag not by purpose, sorry about it. Sure I'll add the tag to v3 if v3 happens.

Please reply directly under the text you're referring to. Top-posting is not allowed.

Please submit a v2 [RESEND] complete with the missing tags.

Quoted 36 lines · Krzysztof Kozlowski
Quoted 31 lines · George Stark
Quoted 8 lines

Optional default-brightness property specifies brightness value to be used if default LED state is on.

---
  Documentation/devicetree/bindings/leds/leds-pwm.yaml | 6 ++++++
  1 file changed, 6 insertions(+)

<form letter>
This is a friendly reminder during the review process.

It looks like you received a tag and forgot to add it.

If you do not know the process, here is a short explanation: Please add Acked-by/Reviewed-by/Tested-by tags when posting new versions, under or above your Signed-off-by tag. Tag is "received", when provided in a message replied to you on the mailing list. Tools like b4 can help here. However, there's no need to repost patches *only* to add the tags. The upstream maintainer will do that for tags received on the version they apply.

https://elixir.bootlin.com/linux/v6.5-rc3/source/Documentation/process/submitting-patches.rst#L577

If a tag was not added on purpose, please state why and what changed. </form letter>

Best regards,
Krzysztof

Signature · 2 lines
Best regards
George
Signature · 1 line
Lee Jones [李琼斯]
#5 lore raw

PATCH v2 2/2 leds: pwm: Add optional DT property default-brightness

In reply to George Stark

When probing if default LED state is on then default brightness will be applied instead of max brightness.

---
 drivers/leds/leds-pwm.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/leds/leds-pwm.c +16 -1
index 7961dca0db2f..7636ee178c39 100644
@@ -63,6 +63,20 @@ static int led_pwm_set(struct led_classdev *led_cdev,
 	return pwm_apply_might_sleep(led_dat->pwm, &led_dat->pwmstate);
 }
 
+static int led_pwm_default_brightness_get(struct fwnode_handle *fwnode,
+					  int max_brightness)
+{
+	unsigned int default_brightness;
+	int ret;
+
+	ret = fwnode_property_read_u32(fwnode, "default-brightness",
+				       &default_brightness);
+	if (ret < 0 || default_brightness > max_brightness)
+		default_brightness = max_brightness;
+
+	return default_brightness;
+}
+
 __attribute__((nonnull))
 static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv,
 		       struct led_pwm *led, struct fwnode_handle *fwnode)
@@ -104,7 +118,8 @@ static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv,
 	/* set brightness */
 	switch (led->default_state) {
 	case LEDS_DEFSTATE_ON:
-		led_data->cdev.brightness = led->max_brightness;
+		led_data->cdev.brightness =
+			led_pwm_default_brightness_get(fwnode, led->max_brightness);
 		break;
 	case LEDS_DEFSTATE_KEEP:
 		{
Signature · 1 line
2.25.1