Hi Svyatoslav, Jonas,

On 2/9/26 7:07 PM, Svyatoslav Ryhel wrote:
From: Jonas Schwöbel <[email protected]>

In the case of active-low behavior the Duty Cycle needs to be set to 100%.
The PWM driver takes care of this but the LED_PWM driver does not take
this into account. Adjust LED_PWM to take into account polarity of PWM.

Signed-off-by: Jonas Schwöbel <[email protected]>
Signed-off-by: Svyatoslav Ryhel <[email protected]>
---
  drivers/led/led_pwm.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/led/led_pwm.c b/drivers/led/led_pwm.c
index 15dd836509b..7edfa286468 100644
--- a/drivers/led/led_pwm.c
+++ b/drivers/led/led_pwm.c
@@ -34,7 +34,7 @@ static int led_pwm_enable(struct udevice *dev)
        if (ret)
                return ret;
- ret = pwm_set_enable(priv->pwm, priv->channel, true);
+       ret = pwm_set_enable(priv->pwm, priv->channel, priv->active_low);
        if (ret)
                return ret;
@@ -52,7 +52,7 @@ static int led_pwm_disable(struct udevice *dev)
        if (ret)
                return ret;
- ret = pwm_set_enable(priv->pwm, priv->channel, false);
+       ret = pwm_set_enable(priv->pwm, priv->channel, priv->active_low);

This feels wrong. Why would both enable and disable paths use the exact same value for pwm_set_enable()?

I can also see that the disable path doesn't actually call pwm_set_invert() unlike in the enable path. I'm assuming this means we cannot call disable before enable and have consistent behavior?

The kernel seems to use active_low as a way to invert the duty cycle if I'm understanding the code properly. In U-Boot, it seems we don't handle that at all and always pass the "normal" duty cycle. Maybe there's something we need to do there.

I'm also assuming there are setups where PWM should be enabled but with a duty cycle of 0?

I'm also unsure what's the difference between active-low and PWM_POLARITY_INVERTED (I've seen them both mentioned or mixed in the kernel DTSes).

I don't have experience with PWM so maybe that's a just a misunderstanding from my side?

Cheers,
Quentin

Reply via email to