From 7db9c4e659a0e35348d3cf55cd036ae0d02648cc Mon Sep 17 00:00:00 2001 From: Jukka Laitinen Date: Fri, 5 Apr 2024 11:58:52 +0300 Subject: [PATCH] arch/arm64/src/imx9/imx9_tpm_pwm.c: Fix re-starting PWM When the PWM outputs were stopped, it was not possible to re-start them Signed-off-by: Jukka Laitinen --- arch/arm64/src/imx9/imx9_tpm_pwm.c | 35 ++++++++++++++++++------------ 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/arch/arm64/src/imx9/imx9_tpm_pwm.c b/arch/arm64/src/imx9/imx9_tpm_pwm.c index 8c0366f2c01c7..8fbce96c9cf4a 100644 --- a/arch/arm64/src/imx9/imx9_tpm_pwm.c +++ b/arch/arm64/src/imx9/imx9_tpm_pwm.c @@ -376,8 +376,29 @@ static void tpm_mux(void) static int pwm_update_frequency(struct imx9_pwmtimer_s *priv, int freq) { + int i; + if (freq != priv->frequency) { + /* Start PWM on all channels if it was previously stopped */ + + if (freq > 0 && priv->frequency == 0) + { + /* Set the EPWM mode for all the configured channels: + * + * High-true pulses (clear output on counter match, set output + * on counter reload, clear output when counter first enabled + * or paused) + * SC[CPWMS] = 0, MSnB:MSnA = 1:0 ELSnB:ELSnA = 0 + */ + + for (i = 0; i < priv->n_channels; i++) + { + pwm_putreg(priv, IMX9_TPM_CXSC_OFFSET(CHMUX(priv, i)), + TPM_CXSC_MSB_MASK); + } + } + priv->period = freq > 0 ? priv->clk / freq : 0; pwminfo("PWM%d frequency: %" PRIu32" period: %" PRIu32 "\n", priv->id, @@ -660,20 +681,6 @@ struct pwm_lowerhalf_s *imx9_tpm_pwm_init(tpm_pwm_id_t pwmid) pwm_putreg(lower, IMX9_TPM_SC_OFFSET, 1 << TPM_SC_CMOD_SHIFT); pwminfo("PWM%d at %" PRIxPTR " configured\n", pwmid, lower->base); - - /* Set the EPWM mode for all the configured channels: - * - * High-true pulses (clear output on counter match, set output - * on counter reload, clear output when counter first enabled - * or paused) - * SC[CPWMS] = 0, MSnB:MSnA = 1:0 ELSnB:ELSnA = 0 - */ - - for (i = 0; i < lower->n_channels; i++) - { - pwm_putreg(lower, IMX9_TPM_CXSC_OFFSET(CHMUX(lower, i)), - TPM_CXSC_MSB_MASK); - } } else {