[PATCH] pwm: mtk-disp: Fix period readback
Uwe Kleine-König
ukleinek at kernel.org
Tue Sep 8 02:52:25 PDT 2026
Hello,
On Thu, Aug 27, 2026 at 06:57:36PM +0800, Chen-Yu Tsai wrote:
> The period value stored in the register is the number of clock cycles - 1.
>
> Account for the offset when calculating the period in nanoseconds. This
> fixes the discrepancy reported by the pwm core when CONFIG_PWM_DEBUG=1:
>
> mediatek-disp-pwm 1100e000.pwm: .apply is not idempotent
> (ena=1 pol=0 281500/499875) -> (ena=1 pol=0 281500/499750)
>
> Calculation discrepancy in the driver was found by AI run by a colleague
> while debugging another PWM related issue. Check against SoC datasheet
> and fix done by the author.
>
> Fixes: 3f2b16734914 ("pwm: mtk-disp: Implement atomic API .get_state()")
> Cc: Jitao Shi <jitao.shi at mediatek.com>
> Signed-off-by: Chen-Yu Tsai <wenst at chromium.org>
Applied with the R-b tags by AngeloGioacchino Del Regno and Fei Shao and
diff --git a/drivers/pwm/pwm-mtk-disp.c b/drivers/pwm/pwm-mtk-disp.c
index 68a4512e821a..56d10cde5b46 100644
--- a/drivers/pwm/pwm-mtk-disp.c
+++ b/drivers/pwm/pwm-mtk-disp.c
@@ -210,7 +210,7 @@ static int mtk_disp_pwm_get_state(struct pwm_chip *chip,
period = FIELD_GET(PWM_PERIOD_MASK, con1);
/*
* period has 12 bits, clk_div 11 and NSEC_PER_SEC has 30,
- * so period * (clk_div + 1) * NSEC_PER_SEC doesn't overflow.
+ * so (period + 1) * (clk_div + 1) * NSEC_PER_SEC doesn't overflow.
*/
state->period = DIV64_U64_ROUND_UP((period + 1) * (clk_div + 1) * NSEC_PER_SEC, rate);
high_width = FIELD_GET(PWM_HIGH_WIDTH_MASK, con1);
squashed in to
https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git pwm/for-next
.
Thanks
Uwe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20260908/be9bef27/attachment.sig>
More information about the linux-arm-kernel
mailing list