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=-17.2 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_SANE_1 autolearn=ham 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 13473C433F5 for ; Wed, 8 Sep 2021 15:51:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E25E461090 for ; Wed, 8 Sep 2021 15:51:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349648AbhIHPwI (ORCPT ); Wed, 8 Sep 2021 11:52:08 -0400 Received: from smtp1.axis.com ([195.60.68.17]:19179 "EHLO smtp1.axis.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235678AbhIHPwH (ORCPT ); Wed, 8 Sep 2021 11:52:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1631116260; x=1662652260; h=date:to:cc:subject:message-id:references:mime-version: content-transfer-encoding:in-reply-to:from; bh=Ytxiloi0Se8cNDvzRVv5HQoxBt4Apdn3R7pe7pmPhwU=; b=N1tuqMh6SWyHGuGwtzywEwN/9NVE/Ql5zSGEwc/Knrpq2fRQ8e2+3AdJ jdHWzRrIArbFSPi7yQkO9kAu5OQjNY87wA09owBfoqfHhZfs4GgMVblke YGuGHUboU3jDqUWKowt4GqJ1URD3ypHc08bUEGZPCpuPSzrlNG1OLu4P7 Y9tF3zeYI7h6yM4dMUAtHTVomJsuLMqlCqLdZ9BautRYldciGMZokpp77 XPDNzXaDDruCPMqj9CKyjZmjth9EQeCJ1XNA0cFvwwVFVw6JNAcLBhDgC cvTLRA2/XNTrmI6zi2K8Yi7sibWsezMA3nRArcGkH90WVwIhEvQLVF6mS Q==; Date: Wed, 8 Sep 2021 17:50:58 +0200 To: Krzysztof Kozlowski CC: =?iso-8859-1?Q?M=E5rten?= Lindahl , Thierry Reding , Lee Jones , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , "linux-arm-kernel@lists.infradead.org" , "linux-samsung-soc@vger.kernel.org" , "linux-pwm@vger.kernel.org" , kernel Subject: Re: [PATCH] pwm: pwm-samsung: Trigger manual update when disabling PWM Message-ID: <20210908155058.GA3587@axis.com> References: <20210908142708.14145-1-marten.lindahl@axis.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) From: Marten Lindahl Precedence: bulk List-ID: X-Mailing-List: linux-pwm@vger.kernel.org On Wed, Sep 08, 2021 at 04:54:04PM +0200, Krzysztof Kozlowski wrote: > On 08/09/2021 16:27, Mårten Lindahl wrote: > > 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); > > I did not test it but looks reasonable. Just please move it above > setting "our_chip->disabled_mask", so the code will be close to > pwm_samsung_enable. > Hi Krzysztof! Thank you for the quick reply! I will do so. Kind regards Mårten > > Best regards, > Krzysztof 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=-15.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham 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 D5474C433F5 for ; Wed, 8 Sep 2021 15:53:32 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 99EEB61041 for ; Wed, 8 Sep 2021 15:53:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 99EEB61041 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=axis.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:From:In-Reply-To:MIME-Version: References:Message-ID:Subject:CC:To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=/YieENXpmBN4NR31JqQR7/4gvumdUAzE5XJWo5gR+Ic=; b=X8zn5O8LsGJN8lRpxc101wEptB YlN7bYU1w8d35C6Q+0/5/OVtbdvDH5ZkkbYk7fH6EAvD7rqeEeBWtBOQK73lClVnbb36uO0cteLD2 zZ1lYblhi9fFKjSjMDWbD2gor4hck3oVbYmnNZAAfEtV2Jpp+G4rKNGp4a0mZifGPzgESbpAlwnIb r4R4tKOZg3LbJZ9Ca7zrY1pysEBK980RbRv8ACi2Gxe67cGkUiFID2EiPcNWxY2pDmAAZrPlhtPYq M26XhpG3Urt1HwoYqaOtKT+nnZW1dT8mEu2S5g5WRuSwgdwio7MUiJ8Z5dYBbJQda5SSe117hxKST zTVDZ1EA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mNzqt-0075cl-W0; Wed, 08 Sep 2021 15:51:08 +0000 Received: from smtp1.axis.com ([195.60.68.17]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mNzqn-0075cF-Pt for linux-arm-kernel@lists.infradead.org; Wed, 08 Sep 2021 15:51:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1631116262; x=1662652262; h=date:to:cc:subject:message-id:references:mime-version: content-transfer-encoding:in-reply-to:from; bh=Ytxiloi0Se8cNDvzRVv5HQoxBt4Apdn3R7pe7pmPhwU=; b=Xt9dv5i/lUG0wvVTT3WQK4On0mFz5Kl++t28pcxUhBbGhKxZWQ+KlW7F dTp94DNdErrMzovFfNH3akQ3Ihc3rjJcgztxfEAdKmu/t+3fXK/N7b5LG KTSI+HfOFUu74P2rJCrOuvlU/Fe1B+xrT4VWUI2Y9vVDJdFdrj3rGCW0J nEOu4PTSla4hzDp6GDQ+fqRrRl05IutT6dmAwm2qblDWKNLClXjQa/Z5H FUZkBYva1bpxvPidyYtjo2mV2Cqtwju8R2hafTPU3blhRGIILLzHT4VVF lRjvmx3FrS18inR2COfZC7Mo2ufpxkAcUwUPhbfcg/+INHX/UCN9jm4fc g==; Date: Wed, 8 Sep 2021 17:50:58 +0200 To: Krzysztof Kozlowski CC: =?iso-8859-1?Q?M=E5rten?= Lindahl , Thierry Reding , Lee Jones , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , "linux-arm-kernel@lists.infradead.org" , "linux-samsung-soc@vger.kernel.org" , "linux-pwm@vger.kernel.org" , kernel Subject: Re: [PATCH] pwm: pwm-samsung: Trigger manual update when disabling PWM Message-ID: <20210908155058.GA3587@axis.com> References: <20210908142708.14145-1-marten.lindahl@axis.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) From: Marten Lindahl X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210908_085102_219625_E96EE43D X-CRM114-Status: GOOD ( 27.09 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Sep 08, 2021 at 04:54:04PM +0200, Krzysztof Kozlowski wrote: > On 08/09/2021 16:27, M=E5rten Lindahl wrote: > > 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=E5rten 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 |=3D 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)) =3D=3D (u32)-1U) > > + __pwm_samsung_manual_update(our_chip, pwm); > = > I did not test it but looks reasonable. Just please move it above > setting "our_chip->disabled_mask", so the code will be close to > pwm_samsung_enable. > = Hi Krzysztof! Thank you for the quick reply! I will do so. Kind regards M=E5rten > = > Best regards, > Krzysztof _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel