From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12B05C433F5 for ; Wed, 8 Sep 2021 14:27:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E604A60E94 for ; Wed, 8 Sep 2021 14:27:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351890AbhIHO23 (ORCPT ); Wed, 8 Sep 2021 10:28:29 -0400 Received: from smtp1.axis.com ([195.60.68.17]:11638 "EHLO smtp1.axis.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229600AbhIHO21 (ORCPT ); Wed, 8 Sep 2021 10:28:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1631111240; x=1662647240; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=/Lcdys6WTmSrPy4bNO7GmCO4AO1+pwjwI5q1bpQDGaI=; b=Sh4Do36+stPRYvM4DuIhOe/PvTfpFsBjzAm7eQaU4PoIsyiUnW4rv0he 6+EhVcTyrhOAmESSv76a21EgBGAVNBNYORRb0uFhcv8foDPFCDogVDl+N VlQFZAxry+O8KwuFj861EYkntJsuS/Uww9fF65ixjVYn2+613iGLWs0S8 1/BYDU4xkdFn1gUCC3Bz9dEkkUnGL5z/6O1WydtTYZbY9j/1Hi7Rwzead XJ35y4DpXfhc2XMe2V3X0/pQNzNO4nxQ5D5Udu46Q3NS6sYKhgoPWFc83 6nMyJKD3GmIOPr40g1DVWsELWF9UJ4Qgidsw/1ZxHtxPzrufixABS99gf Q==; From: =?UTF-8?q?M=C3=A5rten=20Lindahl?= To: Krzysztof Kozlowski , Thierry Reding , Lee Jones CC: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , , , , , =?UTF-8?q?M=C3=A5rten=20Lindahl?= Subject: [PATCH] pwm: pwm-samsung: Trigger manual update when disabling PWM Date: Wed, 8 Sep 2021 16:27:08 +0200 Message-ID: <20210908142708.14145-1-marten.lindahl@axis.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org When duty-cycle is at full level (100%), the TCNTn and TCMPn registers needs to be flushed in order to disable the signal. The PWM manual does not say anything about this, but states that only clearing the TCON auto-reload bit should be needed, and this seems to be true when the PWM duty-cycle is not at full level. This can be observed on an Axis ARTPEC-8, by running: echo > pwm/period echo > pwm/duty_cycle echo 1 > pwm/enable echo 0 > pwm/enable Since the TCNTn and TCMPn registers are activated when enabling the PWM (setting TCON auto-reload bit), and are not touched when disabling the PWM, the double buffered auto-reload function seems to be still active. Lowering duty-cycle, and restoring it again in between the enabling and disabling, makes the disable work since it triggers a reload of the TCNTn and TCMPn registers. Fix this by securing a reload of the TCNTn and TCMPn registers when disabling the PWM and having a full duty-cycle. Signed-off-by: MÃ¥rten Lindahl --- drivers/pwm/pwm-samsung.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/drivers/pwm/pwm-samsung.c b/drivers/pwm/pwm-samsung.c index f6c528f02d43..7d90652402a0 100644 --- a/drivers/pwm/pwm-samsung.c +++ b/drivers/pwm/pwm-samsung.c @@ -105,6 +105,9 @@ struct samsung_pwm_chip { static DEFINE_SPINLOCK(samsung_pwm_lock); #endif +static void __pwm_samsung_manual_update(struct samsung_pwm_chip *chip, + struct pwm_device *pwm); + static inline struct samsung_pwm_chip *to_samsung_pwm_chip(struct pwm_chip *chip) { @@ -278,17 +281,21 @@ static void pwm_samsung_disable(struct pwm_chip *chip, struct pwm_device *pwm) our_chip->disabled_mask |= BIT(pwm->hwpwm); + /* + * In case the PWM is at 100% duty cycle, force a manual + * update to prevent the signal from staying high. + */ + if (readl(our_chip->base + REG_TCMPB(pwm->hwpwm)) == (u32)-1U) + __pwm_samsung_manual_update(our_chip, pwm); + spin_unlock_irqrestore(&samsung_pwm_lock, flags); } -static void pwm_samsung_manual_update(struct samsung_pwm_chip *chip, +static void __pwm_samsung_manual_update(struct samsung_pwm_chip *chip, struct pwm_device *pwm) { unsigned int tcon_chan = to_tcon_channel(pwm->hwpwm); u32 tcon; - unsigned long flags; - - spin_lock_irqsave(&samsung_pwm_lock, flags); tcon = readl(chip->base + REG_TCON); tcon |= TCON_MANUALUPDATE(tcon_chan); @@ -296,6 +303,16 @@ static void pwm_samsung_manual_update(struct samsung_pwm_chip *chip, tcon &= ~TCON_MANUALUPDATE(tcon_chan); writel(tcon, chip->base + REG_TCON); +} + +static void pwm_samsung_manual_update(struct samsung_pwm_chip *chip, + struct pwm_device *pwm) +{ + unsigned long flags; + + spin_lock_irqsave(&samsung_pwm_lock, flags); + + __pwm_samsung_manual_update(chip, pwm); spin_unlock_irqrestore(&samsung_pwm_lock, flags); } -- 2.20.1