]> git.ipfire.org Git - thirdparty/linux.git/commit
pwm: rockchip: Round period/duty down on apply, up on get
authorNicolas Frattaroli <nicolas.frattaroli@collabora.com>
Mon, 16 Jun 2025 15:14:17 +0000 (17:14 +0200)
committerUwe Kleine-König <ukleinek@kernel.org>
Mon, 7 Jul 2025 06:39:35 +0000 (08:39 +0200)
commit0b4d1abe5ca568c5b7f667345ec2b5ad0fb2e54b
treeaea2f530d299c46a79c360473804dfc3df4dfdf8
parentfd0b06972a8f92d57358e62267f5925721c73c6e
pwm: rockchip: Round period/duty down on apply, up on get

With CONFIG_PWM_DEBUG=y, the rockchip PWM driver produces warnings like
this:

  rockchip-pwm fd8b0010.pwm: .apply is supposed to round down
  duty_cycle (requested: 23529/50000, applied: 23542/50000)

This is because the driver chooses ROUND_CLOSEST for purported
idempotency reasons. However, it's possible to keep idempotency while
always rounding down in .apply().

Do this by making .get_state() always round up, and making .apply()
always round down. This is done with u64 maths, and setting both period
and duty to U32_MAX (the biggest the hardware can support) if they would
exceed their 32 bits confines.

Fixes: 12f9ce4a5198 ("pwm: rockchip: Fix period and duty cycle approximation")
Fixes: 1ebb74cf3537 ("pwm: rockchip: Add support for hardware readout")
Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
Link: https://lore.kernel.org/r/20250616-rockchip-pwm-rounding-fix-v2-1-a9c65acad7b6@collabora.com
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
drivers/pwm/pwm-rockchip.c