pwm: mediatek: Fix duty and period setting
authorUwe Kleine-König <u.kleine-koenig@baylibre.com>
Mon, 28 Jul 2025 16:00:18 +0000 (18:00 +0200)
committerUwe Kleine-König <ukleinek@kernel.org>
Tue, 29 Jul 2025 15:46:29 +0000 (17:46 +0200)
commitf21d136caf8171f94159d975ea4620c164431bd9
tree3943d3b87d044c7ae6c49927cc1a61e8130cf652
parent704d918341c378c5f9505dfdf32d315e256d3846
pwm: mediatek: Fix duty and period setting

The period generated by the hardware is

(PWMDWIDTH + 1) << CLKDIV) / freq

according to my tests with a signal analyser and also the documentation.

The current algorithm doesn't consider the `+ 1` part and so configures
slightly too high periods. The same issue exists for the duty cycle
setting. So subtract 1 from both the register values for period and
duty cycle. If period is 0, bail out, if duty_cycle is 0, just disable
the PWM which results in a constant low output.

Fixes: caf065f8fd58 ("pwm: Add MediaTek PWM support")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/6d1fa87a76f8020bfe3171529b8e19baffceab10.1753717973.git.u.kleine-koenig@baylibre.com
Cc: stable@vger.kernel.org
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
drivers/pwm/pwm-mediatek.c