From patchwork Wed Jun 8 16:34:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris BREZILLON X-Patchwork-Id: 9165203 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9A20960467 for ; Wed, 8 Jun 2016 16:39:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C93B25E13 for ; Wed, 8 Jun 2016 16:39:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80DDD265F9; Wed, 8 Jun 2016 16:39:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=2.0 tests=BAYES_00,FSL_HELO_HOME, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2314225E13 for ; Wed, 8 Jun 2016 16:39:41 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1bAgUf-00037k-ED; Wed, 08 Jun 2016 16:38:13 +0000 Received: from down.free-electrons.com ([37.187.137.238] helo=mail.free-electrons.com) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1bAgS9-0008Pf-0E; Wed, 08 Jun 2016 16:35:39 +0000 Received: by mail.free-electrons.com (Postfix, from userid 110) id B3D76467; Wed, 8 Jun 2016 18:34:58 +0200 (CEST) Received: from bbrezillon.home (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 193D3441; Wed, 8 Jun 2016 18:34:58 +0200 (CEST) From: Boris Brezillon To: Thierry Reding , linux-pwm@vger.kernel.org, Mark Brown , Liam Girdwood Subject: [PATCH v2 07/13] pwm: sti: Avoid glitches on already running PWMs Date: Wed, 8 Jun 2016 18:34:42 +0200 Message-Id: <1465403688-17098-8-git-send-email-boris.brezillon@free-electrons.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1465403688-17098-1-git-send-email-boris.brezillon@free-electrons.com> References: <1465403688-17098-1-git-send-email-boris.brezillon@free-electrons.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160608_093537_382594_3B4CD5E5 X-CRM114-Status: GOOD ( 16.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Milo Kim , Heiko Stuebner , Patrice Chotard , Laxman Dewangan , kernel@stlinux.com, Boris Brezillon , Brian Norris , Stephen Barber , linux-rockchip@lists.infradead.org, Caesar Wang , devicetree@vger.kernel.org, Pawel Moll , Ian Campbell , Doug Anderson , Rob Herring , linux-arm-kernel@lists.infradead.org, Maxime Coquelin , Srinivas Kandagatla , linux-kernel@vger.kernel.org, Kumar Gala , Ajit Pal Singh 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 The current logic will disable the PWM clk even if a PWM was left enabled by the bootloader (because it's controlling a critical device like a regulator for example). Keep the PWM clk enabled if at least one PWM is enabled to avoid any glitches. Signed-off-by: Boris Brezillon --- drivers/pwm/pwm-sti.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c index 6300d3e..5bda51d 100644 --- a/drivers/pwm/pwm-sti.c +++ b/drivers/pwm/pwm-sti.c @@ -340,7 +340,7 @@ static int sti_pwm_probe(struct platform_device *pdev) struct sti_pwm_compat_data *cdata; struct sti_pwm_chip *pc; struct resource *res; - int ret; + int i, ret; pc = devm_kzalloc(dev, sizeof(*pc), GFP_KERNEL); if (!pc) @@ -391,7 +391,7 @@ static int sti_pwm_probe(struct platform_device *pdev) return -EINVAL; } - ret = clk_prepare(pc->clk); + ret = clk_prepare_enable(pc->clk); if (ret) { dev_err(dev, "failed to prepare clock\n"); return ret; @@ -409,6 +409,16 @@ static int sti_pwm_probe(struct platform_device *pdev) return ret; } + /* + * Keep the PWM clk enabled if some PWMs appear to be up and + * running. + */ + for (i = 0; i < pc->chip.npwm; i++) { + if (pwm_is_enabled(&pc->chip.pwms[i])) + clk_enable(pc->clk); + } + clk_disable(pc->clk); + platform_set_drvdata(pdev, pc); return 0;