linux-pwm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: Sachin Kamat <sachin.kamat@linaro.org>
Cc: linux-pwm@vger.kernel.org, linux-samsung-soc@vger.kernel.org,
	tomasz.figa@gmail.com, Andrew Bresticker <abrestic@chromium.org>
Subject: Re: [PATCH 1/1] pwm: samsung: avoid setting manual update bit unnecessarily
Date: Thu, 28 Nov 2013 14:26:41 +0100	[thread overview]
Message-ID: <20131128132640.GA23201@ulmo.nvidia.com> (raw)
In-Reply-To: <1383108704-3297-1-git-send-email-sachin.kamat@linaro.org>

[-- Attachment #1: Type: text/plain, Size: 2555 bytes --]

On Wed, Oct 30, 2013 at 10:21:44AM +0530, Sachin Kamat wrote:
> From: Andrew Bresticker <abrestic@chromium.org>
> 
> When possible, avoid setting the manual update bit and starting/stopping
> the PWM when adjusting the PWM as it causes noticable flickering when
> setting the backlight brightness.
> 
> Signed-off-by: Andrew Bresticker <abrestic@chromium.org>
> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
> ---
>  drivers/pwm/pwm-samsung.c |   23 +++++++++++++++++++----
>  1 file changed, 19 insertions(+), 4 deletions(-)

There has been no comment on this, so can I assume this is fine with
everyone?

Thierry

> diff --git a/drivers/pwm/pwm-samsung.c b/drivers/pwm/pwm-samsung.c
> index b59639e..6d23eb3 100644
> --- a/drivers/pwm/pwm-samsung.c
> +++ b/drivers/pwm/pwm-samsung.c
> @@ -34,6 +34,7 @@
>  
>  #define REG_TCNTB(chan)			(0x0c + ((chan) * 0xc))
>  #define REG_TCMPB(chan)			(0x10 + ((chan) * 0xc))
> +#define REG_TCNTO(chan)			(0x14 + ((chan) * 0xc))
>  
>  #define TCFG0_PRESCALER_MASK		0xff
>  #define TCFG0_PRESCALER1_SHIFT		8
> @@ -234,15 +235,29 @@ static int pwm_samsung_enable(struct pwm_chip *chip, struct pwm_device *pwm)
>  	struct samsung_pwm_chip *our_chip = to_samsung_pwm_chip(chip);
>  	unsigned int tcon_chan = to_tcon_channel(pwm->hwpwm);
>  	unsigned long flags;
> -	u32 tcon;
> +	u32 tcon, tcnt, tcnt_o;
>  
>  	spin_lock_irqsave(&samsung_pwm_lock, flags);
>  
>  	tcon = readl(our_chip->base + REG_TCON);
> +	tcnt = readl(our_chip->base + REG_TCNTB(pwm->hwpwm));
> +	tcnt_o = readl(our_chip->base + REG_TCNTO(pwm->hwpwm));
>  
> -	tcon &= ~TCON_START(tcon_chan);
> -	tcon |= TCON_MANUALUPDATE(tcon_chan);
> -	writel(tcon, our_chip->base + REG_TCON);
> +	/*
> +	 * If we've got a big value stuck in the PWM we need to adjust it using
> +	 * manualupdate.  The start bit needs to be off for that to work
> +	 * properly so we only do this if strictly necessary since it can cause
> +	 * the PWM to blink.
> +	 *
> +	 * We will also use manualupdate if we find that the autoreload bit
> +	 * wasn't set previously since the very first time the timer is
> +	 * configured we seem to need to kickstart the PWM.
> +	 */
> +	if ((tcnt_o > tcnt) || !(tcon & TCON_AUTORELOAD(tcon_chan))) {
> +		tcon &= ~TCON_START(tcon_chan);
> +		tcon |= TCON_MANUALUPDATE(tcon_chan);
> +		writel(tcon, our_chip->base + REG_TCON);
> +	}
>  
>  	tcon &= ~TCON_MANUALUPDATE(tcon_chan);
>  	tcon |= TCON_START(tcon_chan) | TCON_AUTORELOAD(tcon_chan);
> -- 
> 1.7.9.5
> 

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

  reply	other threads:[~2013-11-28 13:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-30  4:51 [PATCH 1/1] pwm: samsung: avoid setting manual update bit unnecessarily Sachin Kamat
2013-11-28 13:26 ` Thierry Reding [this message]
2013-11-28 13:44   ` Tomasz Figa
2013-11-28 14:05 ` Tomasz Figa

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=20131128132640.GA23201@ulmo.nvidia.com \
    --to=thierry.reding@gmail.com \
    --cc=abrestic@chromium.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=sachin.kamat@linaro.org \
    --cc=tomasz.figa@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).