[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <vwozlwajisjw5qomwtmnfdklmucevyxncsxl2cdmixn2yixxrk@x6j3r2lrl5qz>
Date: Wed, 2 Jul 2025 07:51:05 +0200
From: Uwe Kleine-König <ukleinek@...nel.org>
To: Laurentiu Mihalcea <laurentiumihalcea111@...il.com>
Cc: Shawn Guo <shawnguo@...nel.org>, Sascha Hauer <s.hauer@...gutronix.de>,
Fabio Estevam <festevam@...il.com>, Pengutronix Kernel Team <kernel@...gutronix.de>,
linux-pwm@...r.kernel.org, imx@...ts.linux.dev, linux-arm-kernel@...ts.infradead.org,
linux-kernel@...r.kernel.org, Laurentiu Mihalcea <laurentiu.mihalcea@....com>
Subject: Re: [PATCH] pwm: imx-tpm: reset counter if CMOD is 0
Hello,
On Tue, Jul 01, 2025 at 06:01:47PM -0400, Laurentiu Mihalcea wrote:
> From: Laurentiu Mihalcea <laurentiu.mihalcea@....com>
>
> 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.
>
> Signed-off-by: Laurentiu Mihalcea <laurentiu.mihalcea@....com>
> ---
> drivers/pwm/pwm-imx-tpm.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/drivers/pwm/pwm-imx-tpm.c b/drivers/pwm/pwm-imx-tpm.c
> index 7ee7b65b9b90..30f271826aed 100644
> --- a/drivers/pwm/pwm-imx-tpm.c
> +++ b/drivers/pwm/pwm-imx-tpm.c
> @@ -204,6 +204,19 @@ static int pwm_imx_tpm_apply_hw(struct pwm_chip *chip,
> val |= FIELD_PREP(PWM_IMX_TPM_SC_PS, p->prescale);
> writel(val, tpm->base + PWM_IMX_TPM_SC);
>
> + /*
> + * VERY IMPORTANT: if CMOD is set to 0 then writing
The "VERY IMPORTANT" is correct today as this is missing and so
disturbing operation. However once this patch is applied, it's only
normal to have it. So I suggest to drop this.
> + * MOD will NOT reset the value of the TPM counter.
> + *
> + * Therefore, if CNT.COUNT > MOD.MOD, the counter will reset
> + * after UINT32_MAX - CNT.COUNT + MOD.MOD cycles, which is
> + * incorrect.
> + *
> + * To avoid this, we need to force a reset of the
> + * counter before writing the new MOD value.
> + */
Without the reference manual at hand or a deeper understanding of the
hardware this isn't understandable. What is MOD? What is CMOD?
> + 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
Best regards
Uwe
Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)
Powered by blists - more mailing lists