From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965247AbcFMJuV (ORCPT ); Mon, 13 Jun 2016 05:50:21 -0400 Received: from down.free-electrons.com ([37.187.137.238]:54258 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965140AbcFMJuT (ORCPT ); Mon, 13 Jun 2016 05:50:19 -0400 Date: Mon, 13 Jun 2016 11:50:07 +0200 From: Alexandre Belloni To: Guillermo Rodriguez Cc: Thierry Reding , linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, Nicolas Ferre Subject: Re: pwm: atmel: Fix disabling of PWM channels Message-ID: <20160613095007.GB3240@piout.net> References: <1463137777-27103-1-git-send-email-guille.rodriguez@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1463137777-27103-1-git-send-email-guille.rodriguez@gmail.com> User-Agent: Mutt/1.6.0 (2016-04-01) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 13/05/2016 at 13:09:37 +0200, Guillermo Rodriguez wrote : > 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 > --- > drivers/pwm/pwm-atmel.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c > index 0e4bd4e..a714434 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); > } > -- Alexandre Belloni, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com