Message ID | 91bfd0c1726d2e6d10c96a3f2e141a7315b08467.camel@iris-sensing.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v2] pwm: imx-tpm: Use correct MODULO value for EPWM mode | expand |
Hello, [dropping anson.huang@nxp.com from Cc] On Thu, Oct 24, 2024 at 06:41:07AM +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. > > 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> No empty line between these trailer lines please. > 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; This looks bogus if period_count is 0. Best regards Uwe
Hello, thanks for the review. Am Donnerstag, dem 24.10.2024 um 23:01 +0200 schrieb Uwe Kleine-König: > Hello, > > [dropping anson.huang@nxp.com from Cc] > > On Thu, Oct 24, 2024 at 06:41:07AM +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. > > > > 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> > > No empty line between these trailer lines please. Noted for v3! > > > 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; > > This looks bogus if period_count is 0. > That's true. It can only be 0 if someone is requesting a period from the PWM that is lower than the period of the clock feeding the PWM. But, it would be an invalid config and returning -EINVAL there seems to be the right thing (instead of underflowing the integer). I will add such a check. > Best regards > Uwe Kind regards Erik
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;
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. 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 drivers/pwm/pwm-imx-tpm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)