[PATCH] pwm: stm32: handle polarity change when PWM is enabled

Sean Nyekjaer sean at geanix.com
Mon Jan 5 23:01:57 PST 2026


After commit 7346e7a058a2 ("pwm: stm32: Always do lazy disabling"),
polarity changes are ignored. Updates to the TIMx_CCER CCxP bits are
ignored by the hardware when the master output is enabled via the
TIMx_BDTR MOE bit.

Handle polarity changes by temporarily disabling the PWM when required,
in line with apply() implementations used by other PWM drivers.

Fixes: 7346e7a058a2 ("pwm: stm32: Always do lazy disabling")
Cc: stable at vger.kernel.org
Signed-off-by: Sean Nyekjaer <sean at geanix.com>
---
This patch is only applicable for stable tree's <= 6.12
How to explicitly state that and what is the procedure?
---
 drivers/pwm/pwm-stm32.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/pwm/pwm-stm32.c b/drivers/pwm/pwm-stm32.c
index eb24054f9729734da21eb96f2e37af03339e3440..d5f79e87a0653e1710d46e6bf9268a59638943fe 100644
--- a/drivers/pwm/pwm-stm32.c
+++ b/drivers/pwm/pwm-stm32.c
@@ -452,15 +452,23 @@ static int stm32_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 
 	enabled = pwm->state.enabled;
 
+	if (state->polarity != pwm->state.polarity) {
+		if (enabled) {
+			stm32_pwm_disable(priv, pwm->hwpwm);
+			enabled = false;
+		}
+
+		ret = stm32_pwm_set_polarity(priv, pwm->hwpwm, state->polarity);
+		if (ret)
+			return ret;
+	}
+
 	if (!state->enabled) {
 		if (enabled)
 			stm32_pwm_disable(priv, pwm->hwpwm);
 		return 0;
 	}
 
-	if (state->polarity != pwm->state.polarity)
-		stm32_pwm_set_polarity(priv, pwm->hwpwm, state->polarity);
-
 	ret = stm32_pwm_config(priv, pwm->hwpwm,
 			       state->duty_cycle, state->period);
 	if (ret)

---
base-commit: eb18504ca5cf1e6a76a752b73daf0ef51de3551b
change-id: 20260105-stm32-pwm-91cb843680f4

Best regards,
-- 
Sean Nyekjaer <sean at geanix.com>




More information about the linux-arm-kernel mailing list