From patchwork Tue Feb 28 06:43:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wu X-Patchwork-Id: 9594873 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 65893600CB for ; Tue, 28 Feb 2017 07:04:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5555F284DA for ; Tue, 28 Feb 2017 07:04:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 47A74284EC; Tue, 28 Feb 2017 07:04:01 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable 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 E4747284DA for ; Tue, 28 Feb 2017 07:03:47 +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=WztgkbpVcCWyOeTG3/FjbUdMUEMe5W5dyjvNzwxJFrQ=; b=nsa DHjF49mSVvH9MBtCOuWUFWsZ0KDMwyIaSUL5N+Bp/pqxrfZzpiOPafa+5bRyQJcufIg6MQPvn+hUX gYTZD/itjwGdQ2uQ9IvuJs/j99al7WyX67Vk5Qk6cPnsZidELRKTJxD3+mkGJxOBcEKzFZpM3bwar 5cl/sW+EMXsY1hTpSc5LEa5LQclG1d1Y9x0J7TYCeZAJgLHel86VrdbY3sGR3Nsddq3DXIQlIxmjS 39ifmwF4UqlO5nDLnke7vbMO+dTw3GulaT9huCHf+O8E/ABhJCxkqTEOOQW/IQ1M2zhfnOSRTfasJ xrEe+4z4wqgxCXE+k9yEOTQvS2DS11A==; 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 1cibp4-00045F-D1; Tue, 28 Feb 2017 07:03:46 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ciboT-0003iB-8k; Tue, 28 Feb 2017 07:03:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=qRATy/NqOk9G5NN3Z1hK8RUhCESaX1w+5Xqy8b0PU8I=; b=OdH12+TD1eCq7tWnljSjcwrya aIieSXDE+ooyMSySbXg+mt2ZjVGaUwrkvlFs+XF9cXwyHL8kN5M2LIUexpLn6FjF+a4w+GHrv3szr QNjakqputyrNgwT+XRBf7oTk2euEACG4b4QjBkLwS+bKucobNanUHASibeZgc+dFvn/4SNO9rpgRl 8KpUExcCeYdGyym+R+TmgJ7a3amUfcIt7S0zLGwHaSDypHDnTQO1ojlIPLtys1l6QJq2ipC830HTt LptzhCIX0p92Pu+tovJzH/k35DqPqV8sIdxHso5qVMBLpzTdtLBvATOCVWPCB5hNf0bfGhvJZIR+Q FAcveP8aA==; Received: from lucky1.263xmail.com ([211.157.147.135]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cibUz-0005Wp-Of; Tue, 28 Feb 2017 06:43:06 +0000 Received: from david.wu?rock-chips.com (unknown [192.168.167.139]) by lucky1.263xmail.com (Postfix) with ESMTP id 5E73375C; Tue, 28 Feb 2017 14:42:26 +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 202AF5F8; Tue, 28 Feb 2017 14:42:22 +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: <63c1c4bf5a35ca492ee552ea6adbd403> 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 17685A6IU04; Tue, 28 Feb 2017 14:42:25 +0800 (CST) From: David Wu To: boris.brezillon@free-electrons.com, briannorris@chromium.org, heiko@sntech.de, thierry.reding@gmail.com Subject: [PATCH] pwm: rockchip: State of pwm clock should synchronize with pwm enabled state Date: Tue, 28 Feb 2017 14:43:36 +0800 Message-Id: <1488264216-9361-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-20170228_064302_887107_11695268 X-CRM114-Status: GOOD ( 13.67 ) 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, 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. Signed-off-by: David Wu Reviewed-by: Boris Brezillon --- drivers/pwm/pwm-rockchip.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/drivers/pwm/pwm-rockchip.c b/drivers/pwm/pwm-rockchip.c index ef89df1..14a0445 100644 --- a/drivers/pwm/pwm-rockchip.c +++ b/drivers/pwm/pwm-rockchip.c @@ -191,6 +191,26 @@ static int rockchip_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, return 0; } +static int rk_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 +227,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 = rk_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); - + rk_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 = rk_pwm_enable(chip, pwm, state->enabled, + state->polarity); + if (ret) + goto out; + } /* * Update the state with the real hardware, which can differ a bit