]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
pwm: imx-tpm: Count the number of enabled channels in probe
authorViorel Suman (OSS) <viorel.suman@oss.nxp.com>
Wed, 11 Mar 2026 12:33:09 +0000 (14:33 +0200)
committerUwe Kleine-König <ukleinek@kernel.org>
Fri, 13 Mar 2026 08:56:28 +0000 (09:56 +0100)
On a soft reset TPM PWM IP may preserve its internal state from previous
runtime, therefore on a subsequent OS boot and driver probe
"enable_count" value and TPM PWM IP internal channels "enabled" states
may get unaligned. In consequence on a suspend/resume cycle the call "if
(--tpm->enable_count == 0)" may lead to "enable_count" overflow the
system being blocked from entering suspend due to:

   if (tpm->enable_count > 0)
       return -EBUSY;

Fix the problem by counting the enabled channels in probe function.

Signed-off-by: Viorel Suman (OSS) <viorel.suman@oss.nxp.com>
Fixes: 738a1cfec2ed ("pwm: Add i.MX TPM PWM driver support")
Link: https://patch.msgid.link/20260311123309.348904-1-viorel.suman@oss.nxp.com
Cc: stable@vger.kernel.org
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
drivers/pwm/pwm-imx-tpm.c

index 5b399de16d6040a416b7babfaed59f197110f5ce..80fdb3303400f8abab80a89d970abb1f3aaebeb4 100644 (file)
@@ -352,7 +352,7 @@ static int pwm_imx_tpm_probe(struct platform_device *pdev)
        struct clk *clk;
        void __iomem *base;
        int ret;
-       unsigned int npwm;
+       unsigned int i, npwm;
        u32 val;
 
        base = devm_platform_ioremap_resource(pdev, 0);
@@ -382,6 +382,13 @@ static int pwm_imx_tpm_probe(struct platform_device *pdev)
 
        mutex_init(&tpm->lock);
 
+       /* count the enabled channels */
+       for (i = 0; i < npwm; ++i) {
+               val = readl(base + PWM_IMX_TPM_CnSC(i));
+               if (FIELD_GET(PWM_IMX_TPM_CnSC_ELS, val))
+                       ++tpm->enable_count;
+       }
+
        ret = devm_pwmchip_add(&pdev->dev, chip);
        if (ret)
                return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");