Skip to content

Commit 65c6f74

Browse files
LaurentiuM1234Uwe Kleine-König
authored andcommitted
pwm: imx-tpm: Reset counter if CMOD is 0
As per the i.MX93 TRM, section 67.3.2.1 "MOD register update", the value of the TPM counter does NOT get updated when writing MOD.MOD unless SC.CMOD != 0. Therefore, with the current code, assuming the following sequence: 1) pwm_disable() 2) pwm_apply_might_sleep() /* period is changed here */ 3) pwm_enable() and assuming only one channel is active, if CNT.COUNT is higher than the MOD.MOD value written during the pwm_apply_might_sleep() call then, when re-enabling the PWM during pwm_enable(), the counter will end up resetting after UINT32_MAX - CNT.COUNT + MOD.MOD cycles instead of MOD.MOD cycles as normally expected. Fix this problem by forcing a reset of the TPM counter before MOD.MOD is written. Fixes: 738a1cf ("pwm: Add i.MX TPM PWM driver support") Cc: [email protected] Signed-off-by: Laurentiu Mihalcea <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Uwe Kleine-König <[email protected]>
1 parent f21d136 commit 65c6f74

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/pwm/pwm-imx-tpm.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,15 @@ static int pwm_imx_tpm_apply_hw(struct pwm_chip *chip,
204204
val |= FIELD_PREP(PWM_IMX_TPM_SC_PS, p->prescale);
205205
writel(val, tpm->base + PWM_IMX_TPM_SC);
206206

207+
/*
208+
* if the counter is disabled (CMOD == 0), programming the new
209+
* period length (MOD) will not reset the counter (CNT). If
210+
* CNT.COUNT happens to be bigger than the new MOD value then
211+
* the counter will end up being reset way too late. Therefore,
212+
* manually reset it to 0.
213+
*/
214+
if (!cmod)
215+
writel(0x0, tpm->base + PWM_IMX_TPM_CNT);
207216
/*
208217
* set period count:
209218
* if the PWM is disabled (CMOD[1:0] = 2b00), then MOD register

0 commit comments

Comments
 (0)