From: Guillermo Rodriguez Date: Fri, 13 May 2016 11:09:37 +0000 (+0200) Subject: pwm: atmel: Fix disabling of PWM channels X-Git-Tag: v4.14-rc1~2693^2~1^2~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f718c54c1abab7171d375112bffd199046749953;p=platform%2Fkernel%2Flinux-rpi.git pwm: atmel: Fix disabling of PWM channels When disabling a PWM channel, the PWM clock was being stopped immediately after writing to PWM_DIS. As a result, the disabling of the PWM channel did not complete properly, and the PWM output might be left at the wrong level. Fix this by waiting for the channel to be effectively disabled (by checking the PWM_SR register) before disabling the clock. Signed-off-by: Guillermo Rodriguez Acked-by: Alexandre Belloni Signed-off-by: Thierry Reding --- diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c index 0e4bd4e..f3df529 100644 --- a/drivers/pwm/pwm-atmel.c +++ b/drivers/pwm/pwm-atmel.c @@ -271,6 +271,16 @@ static void atmel_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) mutex_unlock(&atmel_pwm->isr_lock); atmel_pwm_writel(atmel_pwm, PWM_DIS, 1 << pwm->hwpwm); + /* + * Wait for the PWM channel disable operation to be effective before + * stopping the clock. + */ + timeout = jiffies + 2 * HZ; + + while ((atmel_pwm_readl(atmel_pwm, PWM_SR) & (1 << pwm->hwpwm)) && + time_before(jiffies, timeout)) + usleep_range(10, 100); + clk_disable(atmel_pwm->clk); }