linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: paul.liu@linaro.org (Ying-Chun Liu (PaulLiu))
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH V2] mfd: anatop: make register accessor more flexible and rename meaningfully
Date: Mon, 14 May 2012 01:48:27 +0800	[thread overview]
Message-ID: <4FAFF3EB.4090904@linaro.org> (raw)
In-Reply-To: <1336871882-6796-1-git-send-email-richard.zhao@freescale.com>

(2012?05?13? 09:18), Richard Zhao wrote:
>  - rename to anatop_read_reg and anatop_write_reg
>  - anatop_read_reg directly return reg value
>  - anatop_write_reg write reg with mask
> 
> Signed-off-by: Richard Zhao <richard.zhao@freescale.com>
> ---
> Changes since V1:
> correct bit operation in anatop_write_reg
> 
>  drivers/mfd/anatop-mfd.c             |   35 +++++++++++-----------------------
>  drivers/regulator/anatop-regulator.c |   18 ++++++++---------
>  include/linux/mfd/anatop.h           |    4 ++--
>  3 files changed, 21 insertions(+), 36 deletions(-)
> 
> diff --git a/drivers/mfd/anatop-mfd.c b/drivers/mfd/anatop-mfd.c
> index 2af4248..6da0634 100644
> --- a/drivers/mfd/anatop-mfd.c
> +++ b/drivers/mfd/anatop-mfd.c
> @@ -41,39 +41,26 @@
>  #include <linux/of_address.h>
>  #include <linux/mfd/anatop.h>
>  
> -u32 anatop_get_bits(struct anatop *adata, u32 addr, int bit_shift,
> -		    int bit_width)
> +u32 anatop_read_reg(struct anatop *adata, u32 addr)
>  {
> -	u32 val, mask;
> -
> -	if (bit_width == 32)
> -		mask = ~0;
> -	else
> -		mask = (1 << bit_width) - 1;
> -
> -	val = readl(adata->ioreg + addr);
> -	val = (val >> bit_shift) & mask;
> -
> -	return val;
> +	return readl(adata->ioreg + addr);
>  }
> -EXPORT_SYMBOL_GPL(anatop_get_bits);
> +EXPORT_SYMBOL_GPL(anatop_read_reg);
>  
> -void anatop_set_bits(struct anatop *adata, u32 addr, int bit_shift,
> -		     int bit_width, u32 data)
> +void anatop_write_reg(struct anatop *adata, u32 addr, u32 data, u32 mask)
>  {
> -	u32 val, mask;
> +	u32 val;
>  
> -	if (bit_width == 32)
> -		mask = ~0;
> -	else
> -		mask = (1 << bit_width) - 1;
> +	data &= mask;
>  
>  	spin_lock(&adata->reglock);
> -	val = readl(adata->ioreg + addr) & ~(mask << bit_shift);
> -	writel((data << bit_shift) | val, adata->ioreg + addr);
> +	val = readl(adata->ioreg + addr);
> +	val &= ~mask;
> +	val |= data;
> +	writel(val, adata->ioreg + addr);
>  	spin_unlock(&adata->reglock);
>  }
> -EXPORT_SYMBOL_GPL(anatop_set_bits);
> +EXPORT_SYMBOL_GPL(anatop_write_reg);
>  
>  static const struct of_device_id of_anatop_match[] = {
>  	{ .compatible = "fsl,imx6q-anatop", },
> diff --git a/drivers/regulator/anatop-regulator.c b/drivers/regulator/anatop-regulator.c
> index 81fd606..0a34085 100644
> --- a/drivers/regulator/anatop-regulator.c
> +++ b/drivers/regulator/anatop-regulator.c
> @@ -47,7 +47,7 @@ static int anatop_set_voltage(struct regulator_dev *reg, int min_uV,
>  				  int max_uV, unsigned *selector)
>  {
>  	struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg);
> -	u32 val, sel;
> +	u32 val, sel, mask;
>  	int uv;
>  
>  	uv = min_uV;
> @@ -71,11 +71,10 @@ static int anatop_set_voltage(struct regulator_dev *reg, int min_uV,
>  	val = anatop_reg->min_bit_val + sel;
>  	*selector = sel;
>  	dev_dbg(&reg->dev, "%s: calculated val %d\n", __func__, val);
> -	anatop_set_bits(anatop_reg->mfd,
> -			anatop_reg->control_reg,
> -			anatop_reg->vol_bit_shift,
> -			anatop_reg->vol_bit_width,
> -			val);
> +	mask = ((1 << anatop_reg->vol_bit_width) - 1) <<
> +		anatop_reg->vol_bit_shift;
> +	val <<= anatop_reg->vol_bit_shift;
> +	anatop_write_reg(anatop_reg->mfd, anatop_reg->control_reg, val, mask);
>  
>  	return 0;
>  }
> @@ -88,10 +87,9 @@ static int anatop_get_voltage_sel(struct regulator_dev *reg)
>  	if (!anatop_reg->control_reg)
>  		return -ENOTSUPP;
>  
> -	val = anatop_get_bits(anatop_reg->mfd,
> -			      anatop_reg->control_reg,
> -			      anatop_reg->vol_bit_shift,
> -			      anatop_reg->vol_bit_width);
> +	val = anatop_read_reg(anatop_reg->mfd, anatop_reg->control_reg);
> +	val = (val & ((1 << anatop_reg->vol_bit_width) - 1)) >>
> +		anatop_reg->vol_bit_shift;
>  
>  	return val - anatop_reg->min_bit_val;
>  }
> diff --git a/include/linux/mfd/anatop.h b/include/linux/mfd/anatop.h
> index 22c1007..7f92acf 100644
> --- a/include/linux/mfd/anatop.h
> +++ b/include/linux/mfd/anatop.h
> @@ -34,7 +34,7 @@ struct anatop {
>  	spinlock_t reglock;
>  };
>  
> -extern u32 anatop_get_bits(struct anatop *, u32, int, int);
> -extern void anatop_set_bits(struct anatop *, u32, int, int, u32);
> +extern u32 anatop_read_reg(struct anatop *, u32);
> +extern void anatop_write_reg(struct anatop *, u32, u32, u32);
>  
>  #endif /*  __LINUX_MFD_ANATOP_H */

Reviewed-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

Thanks...

  reply	other threads:[~2012-05-13 17:48 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-13  0:59 [PATCH 1/2] mfd: anatop: make register accessor more flexible and rename meaningfully Richard Zhao
2012-05-13  0:59 ` [PATCH 2/2] mfd: anatop: permit adata be NULL when access register Richard Zhao
2012-05-14  3:51   ` Shawn Guo
2012-05-14  8:08     ` Mark Brown
2012-05-14  8:48       ` Shawn Guo
2012-05-14  9:01         ` Ying-Chun Liu (PaulLiu)
2012-05-14  9:43           ` Shawn Guo
2012-05-14 13:26             ` Ying-Chun Liu (PaulLiu)
2012-05-14 13:50               ` Richard Zhao
2012-05-18  9:59                 ` Richard Zhao
2012-05-21  4:13                   ` Shawn Guo
2012-05-21  9:27                     ` Ying-Chun Liu (PaulLiu)
2012-05-21  9:39                       ` Richard Zhao
2012-06-18 20:23                         ` Rob Lee
2012-06-18 21:58                           ` Samuel Ortiz
2012-06-18 22:59                             ` Rob Lee
2012-05-13  1:18 ` [PATCH V2] mfd: anatop: make register accessor more flexible and rename meaningfully Richard Zhao
2012-05-13 17:48   ` Ying-Chun Liu (PaulLiu) [this message]
2012-05-18  9:09   ` Samuel Ortiz

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=4FAFF3EB.4090904@linaro.org \
    --to=paul.liu@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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).