Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
* [PATCH] pwm: imx-tpm: Use correct MODULO value for EPWM mode
@ 2024-10-23 12:33 Erik Schumacher
  2024-10-23 15:35 ` Frank Li
  0 siblings, 1 reply; 3+ messages in thread
From: Erik Schumacher @ 2024-10-23 12:33 UTC (permalink / raw)
  To: ukleinek@kernel.org
  Cc: kernel@pengutronix.de, s.hauer@pengutronix.de, festevam@gmail.com,
	linux-kernel@vger.kernel.org, shawnguo@kernel.org,
	linux-arm-kernel@lists.infradead.org, linux-pwm@vger.kernel.org,
	imx@lists.linux.dev

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.
A correct MODULO value is particularly relevant if the PWM has to output
a high frequency due to a low period value.

Signed-off-by: Erik Schumacher <erik.schumacher@iris-sensing.com>
---
 drivers/pwm/pwm-imx-tpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pwm/pwm-imx-tpm.c b/drivers/pwm/pwm-imx-tpm.c
index 96ea343856f0..a05b66ffe208 100644
--- a/drivers/pwm/pwm-imx-tpm.c
+++ b/drivers/pwm/pwm-imx-tpm.c
@@ -106,7 +106,7 @@ 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;
+	p->mod = period_count - 1;
 
 	/* calculate real period HW can support */
 	tmp = (u64)period_count << prescale;
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] pwm: imx-tpm: Use correct MODULO value for EPWM mode
  2024-10-23 12:33 [PATCH] pwm: imx-tpm: Use correct MODULO value for EPWM mode Erik Schumacher
@ 2024-10-23 15:35 ` Frank Li
  2024-10-24  6:11   ` Erik Schumacher
  0 siblings, 1 reply; 3+ messages in thread
From: Frank Li @ 2024-10-23 15:35 UTC (permalink / raw)
  To: Erik Schumacher
  Cc: ukleinek@kernel.org, kernel@pengutronix.de,
	s.hauer@pengutronix.de, festevam@gmail.com,
	linux-kernel@vger.kernel.org, shawnguo@kernel.org,
	linux-arm-kernel@lists.infradead.org, linux-pwm@vger.kernel.org,
	imx@lists.linux.dev

On Wed, Oct 23, 2024 at 12:33:53PM +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.
> A correct MODULO value is particularly relevant if the PWM has to output
> a high frequency due to a low period value.
>
This is bug fix,  add fix tag and cc stable

Frank

> Signed-off-by: Erik Schumacher <erik.schumacher@iris-sensing.com>
> ---
>  drivers/pwm/pwm-imx-tpm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/pwm/pwm-imx-tpm.c b/drivers/pwm/pwm-imx-tpm.c
> index 96ea343856f0..a05b66ffe208 100644
> --- a/drivers/pwm/pwm-imx-tpm.c
> +++ b/drivers/pwm/pwm-imx-tpm.c
> @@ -106,7 +106,7 @@ 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;
> +	p->mod = period_count - 1;
>
>  	/* calculate real period HW can support */
>  	tmp = (u64)period_count << prescale;
> --
> 2.47.0
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] pwm: imx-tpm: Use correct MODULO value for EPWM mode
  2024-10-23 15:35 ` Frank Li
@ 2024-10-24  6:11   ` Erik Schumacher
  0 siblings, 0 replies; 3+ messages in thread
From: Erik Schumacher @ 2024-10-24  6:11 UTC (permalink / raw)
  To: Frank.li@nxp.com
  Cc: kernel@pengutronix.de, s.hauer@pengutronix.de, festevam@gmail.com,
	linux-kernel@vger.kernel.org, shawnguo@kernel.org,
	linux-arm-kernel@lists.infradead.org, ukleinek@kernel.org,
	linux-pwm@vger.kernel.org, imx@lists.linux.dev

Am Mittwoch, dem 23.10.2024 um 11:35 -0400 schrieb Frank Li:
> On Wed, Oct 23, 2024 at 12:33:53PM +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.
> > A correct MODULO value is particularly relevant if the PWM has to output
> > a high frequency due to a low period value.
> > 
> This is bug fix,  add fix tag and cc stable
> 
> Frank

That's true. I will do a v2 with these tags.
Thank you!

Erik
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-10-24  6:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-23 12:33 [PATCH] pwm: imx-tpm: Use correct MODULO value for EPWM mode Erik Schumacher
2024-10-23 15:35 ` Frank Li
2024-10-24  6:11   ` Erik Schumacher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox