]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
pwm: sifive: Fix rounding and idempotency issues in apply and get_state
authorNylon Chen <nylon.chen@sifive.com>
Thu, 29 May 2025 03:53:41 +0000 (11:53 +0800)
committerUwe Kleine-König <ukleinek@kernel.org>
Mon, 7 Jul 2025 06:39:34 +0000 (08:39 +0200)
commit6df3aac763fa995260ab0545c1e54f0c21b2feb8
tree53f814139e0f97136b54f6b5d70dc1f6d5c09ed3
parent7dbc4432ea6bf9d709391eb57f1e9fb44e99845a
pwm: sifive: Fix rounding and idempotency issues in apply and get_state

This fix ensures consistent rounding and avoids mismatches
between applied and reported PWM values that could trigger false
idempotency failures in debug checks

This change ensures:
- real_period is now calculated using DIV_ROUND_UP_ULL() to avoid underestimation.
- duty_cycle is rounded up to match the fractional computation in apply()
- apply() truncates the result to compensate for get_state's rounding up logic

These fixes resolve issues like:
.apply is supposed to round down duty_cycle (requested: 360/504000, applied: 361/504124)
.apply is not idempotent (ena=1 pol=0 1739692/4032985) -> (ena=1 pol=0 1739630/4032985)

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202505080303.dBfU5YMS-lkp@intel.com/
Co-developed-by: Zong Li <zong.li@sifive.com>
Signed-off-by: Zong Li <zong.li@sifive.com>
Signed-off-by: Nylon Chen <nylon.chen@sifive.com>
Link: https://lore.kernel.org/r/20250529035341.51736-4-nylon.chen@sifive.com
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
drivers/pwm/pwm-sifive.c