All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marten Lindahl <martenli@axis.com>
To: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Cc: "Mårten Lindahl" <Marten.Lindahl@axis.com>,
	"Thierry Reding" <thierry.reding@gmail.com>,
	"Lee Jones" <lee.jones@linaro.org>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-samsung-soc@vger.kernel.org"
	<linux-samsung-soc@vger.kernel.org>,
	"linux-pwm@vger.kernel.org" <linux-pwm@vger.kernel.org>,
	kernel <kernel@axis.com>
Subject: Re: [PATCH] pwm: pwm-samsung: Trigger manual update when disabling PWM
Date: Wed, 8 Sep 2021 17:50:58 +0200	[thread overview]
Message-ID: <20210908155058.GA3587@axis.com> (raw)
In-Reply-To: <fc40e31d-16a2-33f3-1eb0-4af81fc27065@canonical.com>

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 <period> > pwm/period
> >   echo <period> > 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 <marten.lindahl@axis.com>
> > ---
> >  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

WARNING: multiple messages have this Message-ID (diff)
From: Marten Lindahl <martenli@axis.com>
To: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Cc: "Mårten Lindahl" <Marten.Lindahl@axis.com>,
	"Thierry Reding" <thierry.reding@gmail.com>,
	"Lee Jones" <lee.jones@linaro.org>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-samsung-soc@vger.kernel.org"
	<linux-samsung-soc@vger.kernel.org>,
	"linux-pwm@vger.kernel.org" <linux-pwm@vger.kernel.org>,
	kernel <kernel@axis.com>
Subject: Re: [PATCH] pwm: pwm-samsung: Trigger manual update when disabling PWM
Date: Wed, 8 Sep 2021 17:50:58 +0200	[thread overview]
Message-ID: <20210908155058.GA3587@axis.com> (raw)
In-Reply-To: <fc40e31d-16a2-33f3-1eb0-4af81fc27065@canonical.com>

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 <period> > pwm/period
> >   echo <period> > 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 <marten.lindahl@axis.com>
> > ---
> >  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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-09-08 15:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-08 14:27 [PATCH] pwm: pwm-samsung: Trigger manual update when disabling PWM Mårten Lindahl
2021-09-08 14:27 ` Mårten Lindahl
2021-09-08 14:54 ` Krzysztof Kozlowski
2021-09-08 14:54   ` Krzysztof Kozlowski
2021-09-08 15:50   ` Marten Lindahl [this message]
2021-09-08 15:50     ` Marten Lindahl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210908155058.GA3587@axis.com \
    --to=martenli@axis.com \
    --cc=Marten.Lindahl@axis.com \
    --cc=kernel@axis.com \
    --cc=krzysztof.kozlowski@canonical.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=thierry.reding@gmail.com \
    --cc=u.kleine-koenig@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.