diff options
| author | Laurentiu Mihalcea <[email protected]> | 2025-07-28 19:41:44 +0000 |
|---|---|---|
| committer | Uwe Kleine-König <[email protected]> | 2025-07-29 15:51:27 +0000 |
| commit | 65c6f742ab14ab1a2679fba72b82dcc0289d96f1 (patch) | |
| tree | 2e1c6d9bf4dcc3215b1730da12d16b823d107116 /drivers/pwm/pwm-imx-tpm.c | |
| parent | pwm: mediatek: Fix duty and period setting (diff) | |
| download | kernel-65c6f742ab14ab1a2679fba72b82dcc0289d96f1.tar.gz kernel-65c6f742ab14ab1a2679fba72b82dcc0289d96f1.zip | |
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: 738a1cfec2ed ("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]>
Diffstat (limited to 'drivers/pwm/pwm-imx-tpm.c')
| -rw-r--r-- | drivers/pwm/pwm-imx-tpm.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/drivers/pwm/pwm-imx-tpm.c b/drivers/pwm/pwm-imx-tpm.c index 7ee7b65b9b90..5b399de16d60 100644 --- a/drivers/pwm/pwm-imx-tpm.c +++ b/drivers/pwm/pwm-imx-tpm.c @@ -205,6 +205,15 @@ static int pwm_imx_tpm_apply_hw(struct pwm_chip *chip, writel(val, tpm->base + PWM_IMX_TPM_SC); /* + * if the counter is disabled (CMOD == 0), programming the new + * period length (MOD) will not reset the counter (CNT). If + * CNT.COUNT happens to be bigger than the new MOD value then + * the counter will end up being reset way too late. Therefore, + * manually reset it to 0. + */ + if (!cmod) + writel(0x0, tpm->base + PWM_IMX_TPM_CNT); + /* * set period count: * if the PWM is disabled (CMOD[1:0] = 2b00), then MOD register * is updated when MOD register is written. |
