From: "Viorel Suman (OSS)" <viorel.suman@oss.nxp.com>
To: "Uwe Kleine-König" <ukleinek@kernel.org>,
"Frank Li" <Frank.Li@nxp.com>,
"Sascha Hauer" <s.hauer@pengutronix.de>,
"Pengutronix Kernel Team" <kernel@pengutronix.de>,
"Fabio Estevam" <festevam@gmail.com>,
linux-pwm@vger.kernel.org, imx@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Cc: Viorel Suman <viorel.suman@oss.nxp.com>
Subject: [PATCH] pwm: imx-tpm: keep channel state instead of counting
Date: Fri, 30 Jan 2026 16:37:20 +0200 [thread overview]
Message-ID: <20260130143720.778514-1-viorel.suman@oss.nxp.com> (raw)
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 this problem by replacing counting logic with per-channel state handling.
Signed-off-by: Viorel Suman (OSS) <viorel.suman@oss.nxp.com>
---
drivers/pwm/pwm-imx-tpm.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/drivers/pwm/pwm-imx-tpm.c b/drivers/pwm/pwm-imx-tpm.c
index 5b399de16d60..0f8643f4a70b 100644
--- a/drivers/pwm/pwm-imx-tpm.c
+++ b/drivers/pwm/pwm-imx-tpm.c
@@ -62,7 +62,7 @@ struct imx_tpm_pwm_chip {
void __iomem *base;
struct mutex lock;
u32 user_count;
- u32 enable_count;
+ u32 enabled_channels;
u32 real_period;
};
@@ -166,6 +166,10 @@ static int pwm_imx_tpm_get_state(struct pwm_chip *chip,
/* get channel status */
state->enabled = FIELD_GET(PWM_IMX_TPM_CnSC_ELS, val) ? true : false;
+ if (state->enabled)
+ tpm->enabled_channels |= BIT(pwm->hwpwm);
+ else
+ tpm->enabled_channels &= ~BIT(pwm->hwpwm);
return 0;
}
@@ -282,15 +286,19 @@ static int pwm_imx_tpm_apply_hw(struct pwm_chip *chip,
}
writel(val, tpm->base + PWM_IMX_TPM_CnSC(pwm->hwpwm));
- /* control the counter status */
+ /* control the channel state */
if (state->enabled != c.enabled) {
val = readl(tpm->base + PWM_IMX_TPM_SC);
if (state->enabled) {
- if (++tpm->enable_count == 1)
+ if (tpm->enabled_channels == 0) {
val |= PWM_IMX_TPM_SC_CMOD_INC_EVERY_CLK;
+ }
+ tpm->enabled_channels |= BIT(pwm->hwpwm);
} else {
- if (--tpm->enable_count == 0)
+ tpm->enabled_channels &= ~BIT(pwm->hwpwm);
+ if (tpm->enabled_channels == 0) {
val &= ~PWM_IMX_TPM_SC_CMOD;
+ }
}
writel(val, tpm->base + PWM_IMX_TPM_SC);
}
@@ -394,7 +402,7 @@ static int pwm_imx_tpm_suspend(struct device *dev)
struct imx_tpm_pwm_chip *tpm = dev_get_drvdata(dev);
int ret;
- if (tpm->enable_count > 0)
+ if (tpm->enabled_channels > 0)
return -EBUSY;
/*
--
2.34.1
next reply other threads:[~2026-01-30 14:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-30 14:37 Viorel Suman (OSS) [this message]
2026-01-30 17:41 ` [PATCH] pwm: imx-tpm: keep channel state instead of counting Frank Li
2026-01-30 22:54 ` Uwe Kleine-König
2026-01-30 23:00 ` Uwe Kleine-König
2026-02-02 10:46 ` Viorel Suman (OSS)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260130143720.778514-1-viorel.suman@oss.nxp.com \
--to=viorel.suman@oss.nxp.com \
--cc=Frank.Li@nxp.com \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=ukleinek@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox