public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@avionic-design.de>
To: Tony Prisk <linux@prisktech.co.nz>
Cc: linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	vt8500-wm8505-linux-kernel@googlegroups.com
Subject: Re: [PATCH 1/2] pwm: vt8500: Register write busy test performed incorrectly
Date: Wed, 2 Jan 2013 14:55:18 +0100	[thread overview]
Message-ID: <20130102135518.GB4414@avionic-0098.adnet.avionic-design.de> (raw)
In-Reply-To: <1356899005-8876-1-git-send-email-linux@prisktech.co.nz>

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

On Mon, Dec 31, 2012 at 09:23:24AM +1300, Tony Prisk wrote:
> Correct operation for register writes is to perform a busy-wait
> after writing the register. Currently the busy wait it performed
> before, meaning subsequent register writes to bitfields may occur
> before the previous field has been updated.
> 
> Also, all registers are defined as 32-bit read/write. Change
> pwm_busy_wait() to use readl rather than readb.
> 
> Improve readability of code with defines for registers and bitfields.
> 
> Signed-off-by: Tony Prisk <linux@prisktech.co.nz>
> ---
> Thierry,
> 
> This patch is a fix but it can go to 3.9 rather than 3.8 (if you prefer)
> as the incorrect behaviour doesn't seem to cause a problem on current
> hardware.
> 
>  drivers/pwm/pwm-vt8500.c |   62 +++++++++++++++++++++++++++++++++++-----------
>  1 file changed, 48 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-vt8500.c b/drivers/pwm/pwm-vt8500.c
> index b0ba2d4..27ed0f4 100644
> --- a/drivers/pwm/pwm-vt8500.c
> +++ b/drivers/pwm/pwm-vt8500.c
> @@ -36,6 +36,25 @@
>   */
>  #define VT8500_NR_PWMS	2
>  
> +#define REG_CTRL(pwm)		(pwm << 4) + 0x00
> +#define REG_SCALAR(pwm)		(pwm << 4) + 0x04
> +#define REG_PERIOD(pwm)		(pwm << 4) + 0x08
> +#define REG_DUTY(pwm)		(pwm << 4) + 0x0C

To be on the safe side, I think these should be:

	(((pwm) << 4) + offset)

> -static inline void pwm_busy_wait(void __iomem *reg, u8 bitmask)
> +static inline void pwm_busy_wait(struct vt8500_chip *vt8500, int nr, u8 bitmask)
>  {
>  	int loops = msecs_to_loops(10);
> -	while ((readb(reg) & bitmask) && --loops)
> +	u32 mask = bitmask << (nr << 8);
> +
> +	while ((readl(vt8500->base + REG_STATUS) & mask) && --loops)
>  		cpu_relax();
>  
>  	if (unlikely(!loops))
>  		pr_warn("Waiting for status bits 0x%x to clear timed out\n",
> -			   bitmask);
> +			   mask);
>  }

Now that you're passing a struct vt8500_chip, couldn't you use
dev_warn() instead?

Thierry

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

      parent reply	other threads:[~2013-01-02 13:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-30 20:23 [PATCH 1/2] pwm: vt8500: Register write busy test performed incorrectly Tony Prisk
2012-12-30 20:23 ` [PATCH 2/2] pwm: vt8500: Add support for .set_polarity Tony Prisk
2013-01-02 14:09   ` Thierry Reding
2013-01-02 13:55 ` Thierry Reding [this message]

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=20130102135518.GB4414@avionic-0098.adnet.avionic-design.de \
    --to=thierry.reding@avionic-design.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@prisktech.co.nz \
    --cc=vt8500-wm8505-linux-kernel@googlegroups.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