pwm: imx-tpm: Use correct MODULO value for EPWM mode
authorErik Schumacher <erik.schumacher@iris-sensing.com>
Fri, 25 Oct 2024 08:37:00 +0000 (08:37 +0000)
committerUwe Kleine-König <ukleinek@kernel.org>
Fri, 25 Oct 2024 09:29:17 +0000 (11:29 +0200)
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>
Link: https://lore.kernel.org/r/1a3890966d68b9f800d457cbf095746627495e18.camel@iris-sensing.com
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
drivers/pwm/pwm-imx-tpm.c

index 96ea343856f0c39fb16815fd061724b1c9b96a44..7ee7b65b9b90c576d3dca57eb69b981c51981da1 100644 (file)
@@ -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;