Skip to contentSkip to conversation

pwm: mtk-disp: Fix period readback

PATCH In review Chen-Yu Tsai 4 participants 4 messages Aug 27 – Sep 8

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pwm: mtk-disp: Fix period readback

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 <[email protected]>
---
 drivers/pwm/pwm-mtk-disp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pwm/pwm-mtk-disp.c +1 -1
index b5409e15dac8..68a4512e821a 100644
@@ -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);
Signature · 1 line
2.55.0.887.g758fc8c411-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Chen-Yu Tsai

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)

Quoted 7 lines

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 <[email protected]>
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Chen-Yu Tsai
Quoted 8 lines · Chen-Yu Tsai

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)

Quoted 7 lines

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 <[email protected]>
#3 lore raw
In reply to Chen-Yu Tsai

Hello,

Quoted 8 lines · Chen-Yu Tsai

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)

Quoted 7 lines

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 <[email protected]>

Applied with the R-b tags by AngeloGioacchino Del Regno and Fei Shao and

drivers/pwm/pwm-mtk-disp.c +1 -1
index 68a4512e821a..56d10cde5b46 100644
@@ -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