All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lee Jones <lee.jones@linaro.org>
To: Axel Lin <axel.lin@ingics.com>
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>,
	Bengt Jonsson <bengt.g.jonsson@stericsson.com>,
	Yvan FILLION <yvan.fillion@stericsson.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/4] regulator: ab8500: Get rid of is_enabled from struct ab8500_regulator_info
Date: Mon, 8 Apr 2013 08:52:16 +0100	[thread overview]
Message-ID: <20130408075216.GC3084@gmail.com> (raw)
In-Reply-To: <1365347548.9931.1.camel@phoenix>

On Sun, 07 Apr 2013, Axel Lin wrote:

> The intention of this patch is to simplify the code.
> 
> Maintain the is_enabled flag is not trivial, it not only needs to set/clear the
> flag in disable()/enable() but also needs to set the flag in is_enable() to get
> initial status. The only benefit of keeping is_enabled flag is just save a
> register read when set_mode(). Remove is_enabled flag makes the code simpler.
> 
> This patch also moves ab8500_regulator_is_enabled() close to
> ab8500_regulator_[en|dis]able functions.
> This is required to avoid a forward declaration because now we call
> ab8500_regulator_is_enabled() in ab8500_regulator_set_mode().
> This change also makes the code better in readability by moving similar
> functions to one place.
> 
> Signed-off-by: Axel Lin <axel.lin@ingics.com>

Code looks good to me:

Acked-by: Lee Jones <lee.jones@linaro.org>

> ---
>  drivers/regulator/ab8500.c |   72 ++++++++++++++++++++------------------------
>  1 file changed, 32 insertions(+), 40 deletions(-)
> 
> diff --git a/drivers/regulator/ab8500.c b/drivers/regulator/ab8500.c
> index 517305e..9ebd131 100644
> --- a/drivers/regulator/ab8500.c
> +++ b/drivers/regulator/ab8500.c
> @@ -46,7 +46,6 @@ struct ab8500_shared_mode {
>   * @desc: regulator description
>   * @regulator_dev: regulator device
>   * @shared_mode: used when mode is shared between two regulators
> - * @is_enabled: status of regulator (on/off)
>   * @load_lp_uA: maximum load in idle (low power) mode
>   * @update_bank: bank to control on/off
>   * @update_reg: register to control on/off
> @@ -69,7 +68,6 @@ struct ab8500_regulator_info {
>  	struct regulator_desc	desc;
>  	struct regulator_dev	*regulator;
>  	struct ab8500_shared_mode *shared_mode;
> -	bool is_enabled;
>  	int load_lp_uA;
>  	u8 update_bank;
>  	u8 update_reg;
> @@ -259,8 +257,6 @@ static int ab8500_regulator_enable(struct regulator_dev *rdev)
>  		return ret;
>  	}
>  
> -	info->is_enabled = true;
> -
>  	dev_vdbg(rdev_get_dev(rdev),
>  		"%s-enable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
>  		info->desc.name, info->update_bank, info->update_reg,
> @@ -288,8 +284,6 @@ static int ab8500_regulator_disable(struct regulator_dev *rdev)
>  		return ret;
>  	}
>  
> -	info->is_enabled = false;
> -
>  	dev_vdbg(rdev_get_dev(rdev),
>  		"%s-disable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
>  		info->desc.name, info->update_bank, info->update_reg,
> @@ -298,6 +292,37 @@ static int ab8500_regulator_disable(struct regulator_dev *rdev)
>  	return ret;
>  }
>  
> +static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
> +{
> +	int ret;
> +	struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
> +	u8 regval;
> +
> +	if (info == NULL) {
> +		dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
> +		return -EINVAL;
> +	}
> +
> +	ret = abx500_get_register_interruptible(info->dev,
> +		info->update_bank, info->update_reg, &regval);
> +	if (ret < 0) {
> +		dev_err(rdev_get_dev(rdev),
> +			"couldn't read 0x%x register\n", info->update_reg);
> +		return ret;
> +	}
> +
> +	dev_vdbg(rdev_get_dev(rdev),
> +		"%s-is_enabled (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
> +		" 0x%x\n",
> +		info->desc.name, info->update_bank, info->update_reg,
> +		info->update_mask, regval);
> +
> +	if (regval & info->update_mask)
> +		return 1;
> +	else
> +		return 0;
> +}
> +
>  static unsigned int ab8500_regulator_get_optimum_mode(
>  		struct regulator_dev *rdev, int input_uV,
>  		int output_uV, int load_uA)
> @@ -398,7 +423,7 @@ static int ab8500_regulator_set_mode(struct regulator_dev *rdev,
>  		mask = info->update_mask;
>  	}
>  
> -	if (info->is_enabled || dmr) {
> +	if (dmr || ab8500_regulator_is_enabled(rdev)) {
>  		ret = abx500_mask_and_set_register_interruptible(info->dev,
>  			bank, reg, mask, val);
>  		if (ret < 0)
> @@ -464,39 +489,6 @@ static unsigned int ab8500_regulator_get_mode(struct regulator_dev *rdev)
>  	return ret;
>  }
>  
> -static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
> -{
> -	int ret;
> -	struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
> -	u8 regval;
> -
> -	if (info == NULL) {
> -		dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
> -		return -EINVAL;
> -	}
> -
> -	ret = abx500_get_register_interruptible(info->dev,
> -		info->update_bank, info->update_reg, &regval);
> -	if (ret < 0) {
> -		dev_err(rdev_get_dev(rdev),
> -			"couldn't read 0x%x register\n", info->update_reg);
> -		return ret;
> -	}
> -
> -	dev_vdbg(rdev_get_dev(rdev),
> -		"%s-is_enabled (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
> -		" 0x%x\n",
> -		info->desc.name, info->update_bank, info->update_reg,
> -		info->update_mask, regval);
> -
> -	if (regval & info->update_mask)
> -		info->is_enabled = true;
> -	else
> -		info->is_enabled = false;
> -
> -	return info->is_enabled;
> -}
> -
>  static int ab8500_regulator_get_voltage_sel(struct regulator_dev *rdev)
>  {
>  	int ret, val;

-- 
Lee Jones
Linaro ST-Ericsson Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

  parent reply	other threads:[~2013-04-08  7:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-07 15:12 [PATCH 1/4] regulator: ab8500: Get rid of is_enabled from struct ab8500_regulator_info Axel Lin
2013-04-07 15:13 ` [PATCH 2/4] regulator: ab8500-ext: Get rid of is_enabled from struct ab8500_ext_regulator_info Axel Lin
2013-04-08  7:54   ` Lee Jones
2013-04-07 15:15 ` [PATCH 3/4] regulator: ab8500-ext: Remove unnecessary checking for ab9540 and ab8540 Axel Lin
2013-04-07 15:17 ` [PATCH 4/4] regulator: ab8500-ext: Remove get_voltage to avoid duplicate implementation Axel Lin
2013-04-08  7:53   ` Lee Jones
2013-04-08  7:52 ` Lee Jones [this message]
2013-04-08 10:24 ` [PATCH 1/4] regulator: ab8500: Get rid of is_enabled from struct ab8500_regulator_info Mark Brown

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=20130408075216.GC3084@gmail.com \
    --to=lee.jones@linaro.org \
    --cc=axel.lin@ingics.com \
    --cc=bengt.g.jonsson@stericsson.com \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yvan.fillion@stericsson.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 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.