From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751656AbcGLNSd (ORCPT ); Tue, 12 Jul 2016 09:18:33 -0400 Received: from devils.ext.ti.com ([198.47.26.153]:43922 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750717AbcGLNSb (ORCPT ); Tue, 12 Jul 2016 09:18:31 -0400 Subject: Re: [PATCH] pwm: twl: Reliably disable TWL6030 PWMs To: Paul Kocialkowski , , References: <1459277745-16878-1-git-send-email-contact@paulk.fr> CC: Thierry Reding , Tony Lindgren , From: Peter Ujfalusi Message-ID: Date: Tue, 12 Jul 2016 16:18:18 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <1459277745-16878-1-git-send-email-contact@paulk.fr> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/29/16 21:55, Paul Kocialkowski wrote: > The current TWL6030 code for the TWL PWM driver does not reliably disable the > PWM output, as tested with LEDs. The previous commit to that driver introduced > that regression. > > However, it does make sense to disable the PWM clock after resetting the PWM, > but for some obscure reason, doing it all at once simply doesn't work. > > The TWL6030 datasheet mentions that PWMs have to be disabled in two distinct > steps. However, clearing the clock enable bit in a second step (after issuing a > reset first) does not work. > > The only approach that works is the one that was in place before the previous > commit to the driver. It consists in enabling the PWM clock after issuing a > reset. This is what TI kernel trees and production code seem to be using. > > However, adding an extra step to disable the PWM clock seems to work reliably, > despite looking quite odd. Unfortunately I don't have board to test, but based on the documentation and your explanation, this is the correct way. Thank you for debugging and fixing it! Acked-by: Peter Ujfalusi > > Signed-off-by: Paul Kocialkowski > --- > drivers/pwm/pwm-twl.c | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/drivers/pwm/pwm-twl.c b/drivers/pwm/pwm-twl.c > index 04f7672..7a993b0 100644 > --- a/drivers/pwm/pwm-twl.c > +++ b/drivers/pwm/pwm-twl.c > @@ -269,6 +269,22 @@ static void twl6030_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) > goto out; > } > > + val |= TWL6030_PWM_TOGGLE(pwm->hwpwm, TWL6030_PWMXEN); > + > + ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, val, TWL6030_TOGGLE3_REG); > + if (ret < 0) { > + dev_err(chip->dev, "%s: Failed to disable PWM\n", pwm->label); > + goto out; > + } > + > + val &= ~TWL6030_PWM_TOGGLE(pwm->hwpwm, TWL6030_PWMXEN); > + > + ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, val, TWL6030_TOGGLE3_REG); > + if (ret < 0) { > + dev_err(chip->dev, "%s: Failed to disable PWM\n", pwm->label); > + goto out; > + } > + > twl->twl6030_toggle3 = val; > out: > mutex_unlock(&twl->mutex); > -- Péter