]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
leds: pwm-multicolor: Disable PWM when going to suspend
authorJakob Riepler <jakob+lkml@paranoidlabs.org>
Mon, 16 Dec 2024 21:37:55 +0000 (22:37 +0100)
committerLee Jones <lee@kernel.org>
Tue, 17 Dec 2024 15:04:46 +0000 (15:04 +0000)
This fixes suspend on platforms like stm32mp1xx, where the PWM consumer
has to be disabled for the PWM to enter suspend.
Another positive side effect is that active-low LEDs now properly
turn off instead of going back to full brightness when they are set to 0.

Link: https://lore.kernel.org/all/20240417153846.271751-2-u.kleine-koenig@pengutronix.de/
Signed-off-by: Jakob Riepler <jakob+lkml@paranoidlabs.org>
Acked-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Link: https://lore.kernel.org/r/20241216213754.18374-2-jakob+lkml@paranoidlabs.org
Signed-off-by: Lee Jones <lee@kernel.org>
drivers/leds/rgb/leds-pwm-multicolor.c

index e1a81e0109e8a57e357d121dd1cf74b18220082c..f80a06cc31f8a4fca0ac6d42d69181ceb4624e04 100644 (file)
@@ -50,7 +50,13 @@ static int led_pwm_mc_set(struct led_classdev *cdev,
                        duty = priv->leds[i].state.period - duty;
 
                priv->leds[i].state.duty_cycle = duty;
-               priv->leds[i].state.enabled = duty > 0;
+               /*
+                * Disabling a PWM doesn't guarantee that it emits the inactive level.
+                * So keep it on. Only for suspending the PWM should be disabled because
+                * otherwise it refuses to suspend. The possible downside is that the
+                * LED might stay (or even go) on.
+                */
+               priv->leds[i].state.enabled = !(cdev->flags & LED_SUSPENDED);
                ret = pwm_apply_might_sleep(priv->leds[i].pwm,
                                            &priv->leds[i].state);
                if (ret)