From patchwork Fri Sep 27 20:10:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 2956821 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 811CA9F289 for ; Fri, 27 Sep 2013 20:11:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A78E420268 for ; Fri, 27 Sep 2013 20:11:08 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8DAD8201B9 for ; Fri, 27 Sep 2013 20:11:07 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VPeNP-0001J2-2o; Fri, 27 Sep 2013 20:10:59 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VPeNM-0007Vw-Mq; Fri, 27 Sep 2013 20:10:56 +0000 Received: from top.free-electrons.com ([176.31.233.9] helo=mail.free-electrons.com) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VPeNJ-0007V2-Lz for linux-arm-kernel@lists.infradead.org; Fri, 27 Sep 2013 20:10:54 +0000 Received: by mail.free-electrons.com (Postfix, from userid 106) id 8303C8DB; Fri, 27 Sep 2013 22:10:30 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from localhost (128-79-216-144.hfc.dyn.abo.bbox.fr [128.79.216.144]) by mail.free-electrons.com (Postfix) with ESMTPSA id 016968A3; Fri, 27 Sep 2013 22:10:29 +0200 (CEST) From: Alexandre Belloni To: Thierry Reding Subject: [PATCH] PWM: atmel-pwm: use request/free instead of enable/disable Date: Fri, 27 Sep 2013 22:10:28 +0200 Message-Id: <1380312628-6564-1-git-send-email-alexandre.belloni@free-electrons.com> X-Mailer: git-send-email 1.8.1.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130927_161053_821332_E5D8DAF9 X-CRM114-Status: GOOD ( 10.44 ) X-Spam-Score: -3.7 (---) Cc: linux-pwm@vger.kernel.org, Nicolas Ferre , linux-kernel@vger.kernel.org, Ludovic Desroches , Alexandre Belloni , voice.shen@atmel.com, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP I found that disabling a pwm while it is at a low level will actually put it back at a high level. The main symptom is that leds-pwm is calling pwm_disable() after setting the duty cycle to 0. Hence, instead of getting a switched off LED, you get an LED lit up at full brightness. Solve that by using the request and free callbacks to enable and disable the pwm channels and the clock. Signed-off-by: Alexandre Belloni --- This patch applies after: [PATCH v4] PWM: atmel-pwm: add PWM controller driver drivers/pwm/pwm-atmel.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c index 6af7a50..4526e71 100644 --- a/drivers/pwm/pwm-atmel.c +++ b/drivers/pwm/pwm-atmel.c @@ -209,7 +209,7 @@ static int atmel_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm, return 0; } -static int atmel_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) +static int atmel_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) { struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip); int ret; @@ -225,23 +225,19 @@ static int atmel_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) return 0; } -static void atmel_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) +static void atmel_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) { struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip); - u32 val; atmel_pwm_writel(atmel_pwm, PWM_DIS, 1 << pwm->hwpwm); - - val = atmel_pwm_readl(atmel_pwm, PWM_SR); - if ((val & PWM_SR_ALL_CH_ON) == 0) - clk_disable(atmel_pwm->clk); + clk_disable(atmel_pwm->clk); } static const struct pwm_ops atmel_pwm_ops = { .config = atmel_pwm_config, .set_polarity = atmel_pwm_set_polarity, - .enable = atmel_pwm_enable, - .disable = atmel_pwm_disable, + .request = atmel_pwm_request, + .free = atmel_pwm_free, .owner = THIS_MODULE, };