пн, 2 бер. 2026 р. о 15:07 Quentin Schulz <[email protected]> пише: > > 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()? >
Hello Quentin! You are mixing up the LED with the PWM that controls it. pwm_set_enable() triggers a PWM configuration update; therefore, the process is the same for both enabling and disabling. > 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 inversion setting is only relevant when the PWM is enabled. Since the disable operation forces the duty cycle to 0, the inversion state is inconsequential. > 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. > In U-Boot PWM should handle this in the set_invert operation. > I'm also assuming there are setups where PWM should be enabled but with > a duty cycle of 0? > A duty cycle of 0 is equivalent to pwm being turned off. In general most devices won't work on very low duty cycles. Fan needs at least 30%, LEDs make no sense below 10%, also most Display are not usable below 10% > 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). > These are properties of two different device classes: active-low is used with PWM-LEDs, while PWM_POLARITY_INVERTED is strictly a PWM property. > I don't have experience with PWM so maybe that's a just a > misunderstanding from my side? > > Cheers, > Quentin

