* [PATCH v3] pwm: imx-tpm: Use correct MODULO value for EPWM mode
@ 2024-10-25 8:37 Erik Schumacher
2024-10-25 9:51 ` Uwe Kleine-König
0 siblings, 1 reply; 2+ messages in thread
From: Erik Schumacher @ 2024-10-25 8:37 UTC (permalink / raw)
To: ukleinek
Cc: kernel, thierry.reding, s.hauer, festevam, shawnguo,
linux-kernel, linux-arm-kernel, imx, linux-pwm
The modulo register defines the period of the edge-aligned PWM mode
(which is the only mode implemented). The reference manual states:
"The EPWM period is determined by (MOD + 0001h) ..." So the value that
is written to the MOD register must therefore be one less than the
calculated period length. Return -EINVAL if the calculated length is
already zero.
A correct MODULO value is particularly relevant if the PWM has to output
a high frequency due to a low period value.
Fixes: 738a1cfec2ed ("pwm: Add i.MX TPM PWM driver support")
Cc: stable@vger.kernel.org
Signed-off-by: Erik Schumacher <erik.schumacher@iris-sensing.com>
---
v2:
- Add Fixes: and Cc: tags
v3:
- Add period_count == 0 check and return -EINVAL
drivers/pwm/pwm-imx-tpm.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/pwm/pwm-imx-tpm.c b/drivers/pwm/pwm-imx-tpm.c
index 96ea343856f0..7ee7b65b9b90 100644
--- a/drivers/pwm/pwm-imx-tpm.c
+++ b/drivers/pwm/pwm-imx-tpm.c
@@ -106,7 +106,9 @@ static int pwm_imx_tpm_round_state(struct pwm_chip *chip,
p->prescale = prescale;
period_count = (clock_unit + ((1 << prescale) >> 1)) >> prescale;
- p->mod = period_count;
+ if (period_count == 0)
+ return -EINVAL;
+ p->mod = period_count - 1;
/* calculate real period HW can support */
tmp = (u64)period_count << prescale;
--
2.47.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH v3] pwm: imx-tpm: Use correct MODULO value for EPWM mode
2024-10-25 8:37 [PATCH v3] pwm: imx-tpm: Use correct MODULO value for EPWM mode Erik Schumacher
@ 2024-10-25 9:51 ` Uwe Kleine-König
0 siblings, 0 replies; 2+ messages in thread
From: Uwe Kleine-König @ 2024-10-25 9:51 UTC (permalink / raw)
To: Erik Schumacher
Cc: kernel, thierry.reding, s.hauer, festevam, shawnguo,
linux-kernel, linux-arm-kernel, imx, linux-pwm
[-- Attachment #1: Type: text/plain, Size: 999 bytes --]
Hello,
On Fri, Oct 25, 2024 at 08:37:00AM +0000, Erik Schumacher wrote:
> The modulo register defines the period of the edge-aligned PWM mode
> (which is the only mode implemented). The reference manual states:
> "The EPWM period is determined by (MOD + 0001h) ..." So the value that
> is written to the MOD register must therefore be one less than the
> calculated period length. Return -EINVAL if the calculated length is
> already zero.
> A correct MODULO value is particularly relevant if the PWM has to output
> a high frequency due to a low period value.
>
> Fixes: 738a1cfec2ed ("pwm: Add i.MX TPM PWM driver support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Erik Schumacher <erik.schumacher@iris-sensing.com>
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git pwm/fixes
I let it sit there for a few days to get some coverage in next and then
intend to send it to Linus for mainline inclusion ~ mid of next week.
Best regards
Uwe
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-10-25 9:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-25 8:37 [PATCH v3] pwm: imx-tpm: Use correct MODULO value for EPWM mode Erik Schumacher
2024-10-25 9:51 ` 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®