From patchwork Thu Aug 25 17:50:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olliver Schinagl X-Patchwork-Id: 9299639 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 B4E7560757 for ; Thu, 25 Aug 2016 17:52:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AABDF293AD for ; Thu, 25 Aug 2016 17:52:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F28E293B4; Thu, 25 Aug 2016 17:52:33 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 34289293AD for ; Thu, 25 Aug 2016 17:52:33 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bcyo7-0004v1-FR; Thu, 25 Aug 2016 17:51:15 +0000 Received: from 7of9.schinagl.nl ([88.159.158.68]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bcyni-0004kE-5e for linux-arm-kernel@lists.infradead.org; Thu, 25 Aug 2016 17:50:51 +0000 Received: from um-mbp-306.ultimaker.com (unknown [92.69.209.117]) by 7of9.schinagl.nl (Postfix) with ESMTPA id A8DA039A936; Thu, 25 Aug 2016 19:50:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=schinagl.nl; s=7of9; t=1472147428; bh=pALPhxTEsAvQF9zY2JX/03vaZWHy45HnrzM9Qb58764=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kczHBYEDYeMZp5KQGqx3DYV9TP7iVm9XnC4psdFNaS9Z52QRQujLLkZgiT5YQnpNg +Wdon6Na6nX0IRi10lLJwz3t5Wdr5KqlnbRs+I/MqCCybPxRS5RtFoibOEdpE/cwVZ rovuAmSzIM98nwvd2NRUN3HHBs00JQd30p5YSC5U= From: Olliver Schinagl To: Alexandre Belloni , Thierry Reding , Maxime Ripard , Chen-Yu Tsai Subject: [PATCH 1/2] pwm: sunxi: allow the pwm to finish its pulse before disable Date: Thu, 25 Aug 2016 19:50:10 +0200 Message-Id: <1472147411-30424-2-git-send-email-oliver@schinagl.nl> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1472147411-30424-1-git-send-email-oliver@schinagl.nl> References: <1472147411-30424-1-git-send-email-oliver@schinagl.nl> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160825_105050_498852_083FF31C X-CRM114-Status: GOOD ( 11.66 ) 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: Olliver Schinagl , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org 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 When we inform the PWM block to stop toggeling the output, we may end up in a state where the output is not what we would expect (e.g. not the low-pulse) but whatever the output was at when the clock got disabled. To counter this we have to wait for maximally the time of one whole period to ensure the pwm hardware was able to finish. Since we already told the PWM hardware to disable it self, it will not continue toggling but merly finish its current pulse. If a whole period is considered to much, it may be contemplated to use a half period + a little bit to ensure we get passed the transition. Signed-off-by: Olliver Schinagl Tested-by: Jonathan Liu --- drivers/pwm/pwm-sun4i.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c index 03a99a5..5e97c8a 100644 --- a/drivers/pwm/pwm-sun4i.c +++ b/drivers/pwm/pwm-sun4i.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -245,6 +246,16 @@ static void sun4i_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) spin_lock(&sun4i_pwm->ctrl_lock); val = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG); val &= ~BIT_CH(PWM_EN, pwm->hwpwm); + sun4i_pwm_writel(sun4i_pwm, val, PWM_CTRL_REG); + spin_unlock(&sun4i_pwm->ctrl_lock); + + /* Allow for the PWM hardware to finish its last toggle. The pulse + * may have just started and thus we should wait a full period. + */ + ndelay(pwm_get_period(pwm)); + + spin_lock(&sun4i_pwm->ctrl_lock); + val = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG); val &= ~BIT_CH(PWM_CLK_GATING, pwm->hwpwm); sun4i_pwm_writel(sun4i_pwm, val, PWM_CTRL_REG); spin_unlock(&sun4i_pwm->ctrl_lock);