* [PATCH] pwm: mtk-disp: Fix period readback
@ 2026-08-27 10:57 Chen-Yu Tsai
2026-08-27 11:03 ` Fei Shao
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Chen-Yu Tsai @ 2026-08-27 10:57 UTC (permalink / raw)
To: Uwe Kleine-König, Matthias Brugger, AngeloGioacchino Del Regno
Cc: Chen-Yu Tsai, linux-pwm, linux-mediatek, linux-arm-kernel,
linux-kernel, Jitao Shi
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@mediatek.com>
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
drivers/pwm/pwm-mtk-disp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pwm/pwm-mtk-disp.c b/drivers/pwm/pwm-mtk-disp.c
index b5409e15dac8..68a4512e821a 100644
--- a/drivers/pwm/pwm-mtk-disp.c
+++ b/drivers/pwm/pwm-mtk-disp.c
@@ -212,7 +212,7 @@ static int mtk_disp_pwm_get_state(struct pwm_chip *chip,
* period has 12 bits, clk_div 11 and NSEC_PER_SEC has 30,
* so period * (clk_div + 1) * NSEC_PER_SEC doesn't overflow.
*/
- state->period = DIV64_U64_ROUND_UP(period * (clk_div + 1) * NSEC_PER_SEC, rate);
+ state->period = DIV64_U64_ROUND_UP((period + 1) * (clk_div + 1) * NSEC_PER_SEC, rate);
high_width = FIELD_GET(PWM_HIGH_WIDTH_MASK, con1);
state->duty_cycle = DIV64_U64_ROUND_UP(high_width * (clk_div + 1) * NSEC_PER_SEC,
rate);
--
2.55.0.887.g758fc8c411-goog
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] pwm: mtk-disp: Fix period readback
2026-08-27 10:57 [PATCH] pwm: mtk-disp: Fix period readback Chen-Yu Tsai
@ 2026-08-27 11:03 ` Fei Shao
2026-09-08 7:14 ` AngeloGioacchino Del Regno
2026-09-08 9:52 ` Uwe Kleine-König
2 siblings, 0 replies; 4+ messages in thread
From: Fei Shao @ 2026-08-27 11:03 UTC (permalink / raw)
To: Chen-Yu Tsai
Cc: Uwe Kleine-König, Matthias Brugger,
AngeloGioacchino Del Regno, linux-pwm, linux-mediatek,
linux-arm-kernel, linux-kernel, Jitao Shi
On Thu, Aug 27, 2026 at 6:57 PM Chen-Yu Tsai <wenst@chromium.org> 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@mediatek.com>
> Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Reviewed-by: Fei Shao <fshao@chromium.org>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] pwm: mtk-disp: Fix period readback
2026-08-27 10:57 [PATCH] pwm: mtk-disp: Fix period readback Chen-Yu Tsai
2026-08-27 11:03 ` Fei Shao
@ 2026-09-08 7:14 ` AngeloGioacchino Del Regno
2026-09-08 9:52 ` Uwe Kleine-König
2 siblings, 0 replies; 4+ messages in thread
From: AngeloGioacchino Del Regno @ 2026-09-08 7:14 UTC (permalink / raw)
To: Chen-Yu Tsai, Uwe Kleine-König, Matthias Brugger
Cc: linux-pwm, linux-mediatek, linux-arm-kernel, linux-kernel, Jitao Shi
On 8/27/26 12:57, 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@mediatek.com>
> Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] pwm: mtk-disp: Fix period readback
2026-08-27 10:57 [PATCH] pwm: mtk-disp: Fix period readback Chen-Yu Tsai
2026-08-27 11:03 ` Fei Shao
2026-09-08 7:14 ` AngeloGioacchino Del Regno
@ 2026-09-08 9:52 ` Uwe Kleine-König
2 siblings, 0 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2026-09-08 9:52 UTC (permalink / raw)
To: Chen-Yu Tsai
Cc: Matthias Brugger, AngeloGioacchino Del Regno, linux-pwm,
linux-mediatek, linux-arm-kernel, linux-kernel, Jitao Shi
[-- Attachment #1: Type: text/plain, Size: 1656 bytes --]
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@mediatek.com>
> Signed-off-by: Chen-Yu Tsai <wenst@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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-08 9:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-27 10:57 [PATCH] pwm: mtk-disp: Fix period readback Chen-Yu Tsai
2026-08-27 11:03 ` Fei Shao
2026-09-08 7:14 ` AngeloGioacchino Del Regno
2026-09-08 9:52 ` Uwe Kleine-König
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®