On 3/10/25 13:35, Patrice CHOTARD wrote:

On 3/10/25 11:00, Patrice CHOTARD wrote:

On 3/6/25 15:13, Patrice CHOTARD wrote:

On 3/6/25 11:56, Cheick Traore wrote:
It was possible to provide a duty_ns greater than period_ns to
"pwm config" command. The framework must check the values before
providing them to drivers.

Signed-off-by: Cheick Traore<[email protected]>
---

  drivers/pwm/pwm-uclass.c | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/drivers/pwm/pwm-uclass.c b/drivers/pwm/pwm-uclass.c
index 6543db1d623..b4491f7dcd4 100644
--- a/drivers/pwm/pwm-uclass.c
+++ b/drivers/pwm/pwm-uclass.c
@@ -27,6 +27,9 @@ int pwm_set_config(struct udevice *dev, uint channel, uint 
period_ns,
        if (!ops->set_config)
                return -ENOSYS;
+ if (duty_ns > period_ns)
+               return -EINVAL;
+
        return ops->set_config(dev, channel, period_ns, duty_ns);
  }
Reviewed-by: Patrice Chotard<[email protected]>

Thanks
Patrice
Applied to u-boot-stm32/next

Thanks
Patrice

Hi Cheick

Unfortunately, this patch is causing U-Boot CI test failed:
seehttps://source.denx.de/u-boot/custodians/u-boot-stm/-/jobs/1054426

More precisely ut_dm_dm_test_cros_ec_pwm, see test/dm/cros_ec_pwm.c

Either update test/dm/cros_ec_pwm.c or another solution is simply to
clamp duty_ns to period_ns as following ?

  +     if (duty_ns > period_ns)
  +             duty_ns = period_ns;
  +

Patrice


_______________________________________________
Uboot-stm32 mailing list
[email protected]
https://st-md-mailman.stormreply.com/mailman/listinfo/uboot-stm32

Hi Patrice,

It seems like this patch should finally be reverted.

When the duty cycle exceeds the period, some drivers already clamp the value of the duty cycle to the maximum value or do not apply the duty cycle.

So, I will check the duty cycle in|drivers/pwm/pwm-stm32.c|and return|-EINVAL|when it exceeds the period.

Thanks,

Cheick

Reply via email to