From patchwork Wed Mar 1 11:10:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wu X-Patchwork-Id: 9598265 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 06423604DC for ; Wed, 1 Mar 2017 11:10:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D35F527FB1 for ; Wed, 1 Mar 2017 11:10:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C7DA7284DD; Wed, 1 Mar 2017 11:10:20 +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=-1.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_SORBS_SPAM autolearn=no version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 540B427FB1 for ; Wed, 1 Mar 2017 11:10:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=WFFjhk1OcEWZPThylyTFy+rqxHvRPhDrOwxOTromp+k=; b=uXh lAH+fCaUTRfkRnCGFjxeT1VQ6B3UZGOipN+fPFNtjfnRunVB6NRFiIkUmIuHVoDvLRhAQIdkCoixu EPQDlcX1MakW5SdqNKqPlyuceu+zUQQrgepPk0y9WskAykdhO12yGehgUE58C3y+X0ZPR5iFozyna 2+ZfOngpDw+4sv4TAOJNaSw9nXnDtuVoyEqGCfwQ+ydMBN8PVpk4u6Fzao6Kwzgc/bnfGu4rtHk8+ wKe2e8sRwppaQPQVloMrVJPfpBL/XB++wW3ihZK+cwBk4tawHHvnPa0FdrNlk6LGg8QypV7omt1Z5 3oMuHXPWLXwruJHGXDCshOzzeboETiQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cj29D-00015y-QF; Wed, 01 Mar 2017 11:10:19 +0000 Received: from lucky1.263xmail.com ([211.157.147.133]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cj28e-00087C-HS; Wed, 01 Mar 2017 11:09:46 +0000 Received: from david.wu?rock-chips.com (unknown [192.168.167.243]) by lucky1.263xmail.com (Postfix) with ESMTP id 69A4F8F47A; Wed, 1 Mar 2017 19:09:20 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 1 X-MAIL-DELIVERY: 0 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTP id 33BBA398; Wed, 1 Mar 2017 19:09:20 +0800 (CST) X-RL-SENDER: david.wu@rock-chips.com X-FST-TO: boris.brezillon@free-electrons.com X-SENDER-IP: 58.22.7.114 X-LOGIN-NAME: david.wu@rock-chips.com X-UNIQUE-TAG: X-ATTACHMENT-NUM: 0 X-SENDER: wdc@rock-chips.com X-DNS-TYPE: 0 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (Postfix) whith ESMTP id 11378QVVRC3; Wed, 01 Mar 2017 19:09:21 +0800 (CST) From: David Wu To: boris.brezillon@free-electrons.com, briannorris@chromium.org, heiko@sntech.de, thierry.reding@gmail.com Subject: [PATCH v3] pwm: rockchip: State of pwm clock should synchronize with pwm enabled state Date: Wed, 1 Mar 2017 19:10:55 +0800 Message-Id: <1488366655-31387-1-git-send-email-david.wu@rock-chips.com> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170301_030944_940344_2B5D298C X-CRM114-Status: GOOD ( 11.00 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: huangtao@rock-chips.com, linux-pwm@vger.kernel.org, dianders@chromium.org, stable@vger.kernel.org, linux-kernel@vger.kernel.org, b.galvani@gmail.com, linux-rockchip@lists.infradead.org, caesar.wang@rock-chips.com, "david.wu" , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: "david.wu" If the pwm was not enabled at uboot loader, pwm could not work for clock always disabled at pwm driver. The pwm clock is enabled at beginning of pwm_apply(), but disabled at end of pwm_apply(). If the pwm was enabled at uboot loader, pwm clock is always enabled unless closed by ATF. The pwm-backlight might turn off the power at early suspend, should disable pwm clock for saving power consume. It is important to provide opportunity to enable/disable clock at pwm driver, the pwm consumer should ensure correct order to call pwm enable/disable, and pwm driver ensure state of pwm clock synchronized with pwm enabled state. Fixes: 2bf1c98aa5a4 ("pwm: rockchip: Add support for atomic update") Cc: stable@vger.kernel.org Signed-off-by: David Wu Reviewed-by: Boris Brezillon --- change in v2: - change the function name from rk_pwm_enable to rockchip_pwm_enable drivers/pwm/pwm-rockchip.c | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/drivers/pwm/pwm-rockchip.c b/drivers/pwm/pwm-rockchip.c index ef89df1..744d561 100644 --- a/drivers/pwm/pwm-rockchip.c +++ b/drivers/pwm/pwm-rockchip.c @@ -191,6 +191,28 @@ static int rockchip_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, return 0; } +static int rockchip_pwm_enable(struct pwm_chip *chip, + struct pwm_device *pwm, + bool enable, + enum pwm_polarity polarity) +{ + struct rockchip_pwm_chip *pc = to_rockchip_pwm_chip(chip); + int ret; + + if (enable) { + ret = clk_enable(pc->clk); + if (ret) + return ret; + } + + pc->data->set_enable(chip, pwm, enable, polarity); + + if (!enable) + clk_disable(pc->clk); + + return 0; +} + static int rockchip_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_state *state) { @@ -207,22 +229,26 @@ static int rockchip_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, return ret; if (state->polarity != curstate.polarity && enabled) { - pc->data->set_enable(chip, pwm, false, state->polarity); + ret = rockchip_pwm_enable(chip, pwm, false, state->polarity); + if (ret) + goto out; enabled = false; } ret = rockchip_pwm_config(chip, pwm, state->duty_cycle, state->period); if (ret) { if (enabled != curstate.enabled) - pc->data->set_enable(chip, pwm, !enabled, - state->polarity); - + rockchip_pwm_enable(chip, pwm, !enabled, + state->polarity); goto out; } - if (state->enabled != enabled) - pc->data->set_enable(chip, pwm, state->enabled, - state->polarity); + if (state->enabled != enabled) { + ret = rockchip_pwm_enable(chip, pwm, state->enabled, + state->polarity); + if (ret) + goto out; + } /* * Update the state with the real hardware, which can differ a bit