diff mbox series

[2/2] pwm: pxa: Set duty cycle to 0 before disabling

Message ID 20221002061552.45479-3-doug@schmorgal.com
State Superseded
Headers show
Series pwm: pxa: Fixes for enable/disable transitions | expand

Commit Message

Doug Brown Oct. 2, 2022, 6:15 a.m. UTC
Turning off the clock doesn't guarantee that the pin will be left in a
low state. Set the duty cycle to 0 first to force it to turn off.

Without this fix, the PWM peripheral on a PXA168 was observed to
randomly leave the PWM pin high after attempting to turn it off,
especially when the duty cycle was set to 100%.

Signed-off-by: Doug Brown <doug@schmorgal.com>
 drivers/pwm/pwm-pxa.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox series


diff --git a/drivers/pwm/pwm-pxa.c b/drivers/pwm/pwm-pxa.c
index 208c32c79453..d426e4f17241 100644
--- a/drivers/pwm/pwm-pxa.c
+++ b/drivers/pwm/pwm-pxa.c
@@ -103,6 +103,12 @@  static int pxa_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
 static void pxa_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
 	struct pxa_pwm_chip *pc = to_pxa_pwm_chip(chip);
+	unsigned long offset = pwm->hwpwm ? 0x10 : 0;
+	/* Ensure the duty cycle is set to 0 before turning off the clock.
+	 * Otherwise, the PWM pin might stay high.
+	 */
+	writel(0, pc->mmio_base + offset + PWMDCR);