public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] leds: pca9532: don't stop blinking for non-zero brightness
@ 2026-03-21 10:21 Tobias Deiminger
  2026-03-31  9:47 ` Lee Jones
  0 siblings, 1 reply; 3+ messages in thread
From: Tobias Deiminger @ 2026-03-21 10:21 UTC (permalink / raw)
  To: lee, pavel
  Cc: eajames, j.weitzel, riku.voipio, linux-leds, linux-kernel,
	Tobias Deiminger

pca9532 unexpectedly stopped blinking when changing brightness to a
non-zero value. To reproduce:

 echo timer > /sys/class/leds/led-1/trigger   # blinks
 echo 255 > /sys/class/leds/led-1/brightness  # blinking stops, light on
 cat /sys/class/leds/led-1/trigger            # still claims [timer]

According to Documentation/leds/leds-class.rst, only brightness = 0
shall be a stop condition:

> You can change the brightness value of a LED independently of the
> timer trigger. However, if you set the brightness value to LED_OFF it
> will also disable the timer trigger.

Therefore add a guard to continue blinking when brightness != LED_OFF,
similar to how pca955x does it since 575f10dc64a2 ("leds: pca955x: Add
HW blink support").

Signed-off-by: Tobias Deiminger <tobias.deiminger@linutronix.de>
---

Notes:
    A more advanced solution was to not simply return early on
    set_brightness, but actually support blinking at arbitrary brightness.
    This would however require conditional fallback to SW blinking, since
    PCA 9532 doesn't support routing PWM 0 (dim) and PWM 1 (blink) in
    series. The bugfix here keeps it simple. Optional SW blinking could be
    tried in a separate patch.

 drivers/leds/leds-pca9532.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
index 0344189bb991..3de20e087334 100644
--- a/drivers/leds/leds-pca9532.c
+++ b/drivers/leds/leds-pca9532.c
@@ -184,6 +184,8 @@ static int pca9532_set_brightness(struct led_classdev *led_cdev,
 
 	if (value == LED_OFF)
 		led->state = PCA9532_OFF;
+	else if (led->state == PCA9532_PWM1)
+		return 0; /* non-zero brightness shall not stop HW blinking */
 	else if (value == LED_FULL)
 		led->state = PCA9532_ON;
 	else {

base-commit: b2c87f5e98cd88095dbc6802197526703d5e4e48
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] leds: pca9532: don't stop blinking for non-zero brightness
  2026-03-21 10:21 [PATCH] leds: pca9532: don't stop blinking for non-zero brightness Tobias Deiminger
@ 2026-03-31  9:47 ` Lee Jones
  2026-03-31 20:23   ` Tobias Deiminger
  0 siblings, 1 reply; 3+ messages in thread
From: Lee Jones @ 2026-03-31  9:47 UTC (permalink / raw)
  To: Tobias Deiminger
  Cc: pavel, eajames, j.weitzel, riku.voipio, linux-leds, linux-kernel

On Sat, 21 Mar 2026, Tobias Deiminger wrote:

> pca9532 unexpectedly stopped blinking when changing brightness to a
> non-zero value. To reproduce:
> 
>  echo timer > /sys/class/leds/led-1/trigger   # blinks
>  echo 255 > /sys/class/leds/led-1/brightness  # blinking stops, light on
>  cat /sys/class/leds/led-1/trigger            # still claims [timer]
> 
> According to Documentation/leds/leds-class.rst, only brightness = 0
> shall be a stop condition:
> 
> > You can change the brightness value of a LED independently of the
> > timer trigger. However, if you set the brightness value to LED_OFF it
> > will also disable the timer trigger.
> 
> Therefore add a guard to continue blinking when brightness != LED_OFF,
> similar to how pca955x does it since 575f10dc64a2 ("leds: pca955x: Add
> HW blink support").
> 
> Signed-off-by: Tobias Deiminger <tobias.deiminger@linutronix.de>
> ---
> 
> Notes:
>     A more advanced solution was to not simply return early on
>     set_brightness, but actually support blinking at arbitrary brightness.
>     This would however require conditional fallback to SW blinking, since
>     PCA 9532 doesn't support routing PWM 0 (dim) and PWM 1 (blink) in
>     series. The bugfix here keeps it simple. Optional SW blinking could be
>     tried in a separate patch.
> 
>  drivers/leds/leds-pca9532.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
> index 0344189bb991..3de20e087334 100644
> --- a/drivers/leds/leds-pca9532.c
> +++ b/drivers/leds/leds-pca9532.c
> @@ -184,6 +184,8 @@ static int pca9532_set_brightness(struct led_classdev *led_cdev,
>  
>  	if (value == LED_OFF)
>  		led->state = PCA9532_OFF;
> +	else if (led->state == PCA9532_PWM1)
> +		return 0; /* non-zero brightness shall not stop HW blinking */

Comments should start with a capital letter.

Also, as the final 'else' statement uses braces, should we perhaps take the
opportunity to add braces to all branches of this conditional block?

>  	else if (value == LED_FULL)
>  		led->state = PCA9532_ON;
>  	else {
> 
> base-commit: b2c87f5e98cd88095dbc6802197526703d5e4e48
> -- 
> 2.47.3
> 
> 

-- 
Lee Jones [李琼斯]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] leds: pca9532: don't stop blinking for non-zero brightness
  2026-03-31  9:47 ` Lee Jones
@ 2026-03-31 20:23   ` Tobias Deiminger
  0 siblings, 0 replies; 3+ messages in thread
From: Tobias Deiminger @ 2026-03-31 20:23 UTC (permalink / raw)
  To: Lee Jones; +Cc: pavel, eajames, riku.voipio, linux-leds, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 973 bytes --]

Am Dienstag, 31. März 2026, 11:47:30 Mitteleuropäische Sommerzeit schrieb Lee Jones:
> On Sat, 21 Mar 2026, Tobias Deiminger wrote:
> [...]
> > --- a/drivers/leds/leds-pca9532.c
> > +++ b/drivers/leds/leds-pca9532.c
> > @@ -184,6 +184,8 @@ static int pca9532_set_brightness(struct led_classdev *led_cdev,
> >  
> >  	if (value == LED_OFF)
> >  		led->state = PCA9532_OFF;
> > +	else if (led->state == PCA9532_PWM1)
> > +		return 0; /* non-zero brightness shall not stop HW blinking */
> 
> Comments should start with a capital letter.
> 
> Also, as the final 'else' statement uses braces, should we perhaps take the
> opportunity to add braces to all branches of this conditional block?

Thanks for taking a look, sounds reasonable. Will adjust the comment and K&R-ify the
hunk in v2.

- Tobias

> >  	else if (value == LED_FULL)
> >  		led->state = PCA9532_ON;
> >  	else {
> > 
> > base-commit: b2c87f5e98cd88095dbc6802197526703d5e4e48
> 
> 

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-03-31 20:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-21 10:21 [PATCH] leds: pca9532: don't stop blinking for non-zero brightness Tobias Deiminger
2026-03-31  9:47 ` Lee Jones
2026-03-31 20:23   ` Tobias Deiminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox