public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Bengt Jönsson" <bengt.g.jonsson@stericsson.com>
To: Axel Lin <axel.lin@ingics.com>
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>,
	Lee Jones <lee.jones@linaro.org>,
	Yvan FILLION <yvan.fillion@stericsson.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] regulator: ab8500: Don't update lp_mode_req flag in set_mode() error paths
Date: Wed, 17 Apr 2013 11:49:25 +0200	[thread overview]
Message-ID: <516E7025.8040508@stericsson.com> (raw)
In-Reply-To: <1365509835.3801.3.camel@phoenix>

On 04/09/2013 02:17 PM, Axel Lin wrote:
> Currently, set invalid mode setting for shared mode regulators may change
> sm->lp_mode_req flag. This patch ensures we don't set lp_mode_req flag to wrong
> status if set_mode() fails.
>
> This patch includes some clean up, and these changes makes this patch looks like
> code refactor. The clean up is mainly to avoid adding ugly code to handle
> failure paths.
>
> Signed-off-by: Axel Lin <axel.lin@ingics.com>
Looks fine.

Acked-by: Bengt Jonsson <bengt.g.jonsson@stericsson.com>
> ---
>   drivers/regulator/ab8500.c |   98 +++++++++++++++++++-------------------------
>   1 file changed, 43 insertions(+), 55 deletions(-)
>
> diff --git a/drivers/regulator/ab8500.c b/drivers/regulator/ab8500.c
> index 1866dbf..88ab408 100644
> --- a/drivers/regulator/ab8500.c
> +++ b/drivers/regulator/ab8500.c
> @@ -348,11 +348,8 @@ static int ab8500_regulator_set_mode(struct regulator_dev *rdev,
>   				     unsigned int mode)
>   {
>   	int ret = 0;
> -	u8 bank;
> -	u8 reg;
> -	u8 mask;
> -	u8 val;
> -	bool dmr = false; /* Dedicated mode register */
> +	u8 bank, reg, mask, val;
> +	bool lp_mode_req = false;
>   	struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
>   
>   	if (info == NULL) {
> @@ -360,66 +357,54 @@ static int ab8500_regulator_set_mode(struct regulator_dev *rdev,
>   		return -EINVAL;
>   	}
>   
> -	if (info->shared_mode) {
> -		/*
> -		 * Special case where mode is shared between two regulators.
> -		 */
> -		struct ab8500_shared_mode *sm = info->shared_mode;
> -		mutex_lock(&shared_mode_mutex);
> -
> -		if (mode == REGULATOR_MODE_IDLE) {
> -			sm->lp_mode_req = true; /* Low power mode requested */
> -			if (!((sm->shared_regulator)->
> -			      shared_mode->lp_mode_req)) {
> -				mutex_unlock(&shared_mode_mutex);
> -				return 0; /* Other regulator prevent LP mode */
> -			}
> -		} else {
> -			sm->lp_mode_req = false;
> -		}
> -	}
> -
>   	if (info->mode_mask) {
> -		/* Dedicated register for handling mode */
> -
> -		dmr = true;
> -
> -		switch (mode) {
> -		case REGULATOR_MODE_NORMAL:
> -			val = info->mode_val_normal;
> -			break;
> -		case REGULATOR_MODE_IDLE:
> -			val = info->mode_val_idle;
> -			break;
> -		default:
> -			ret = -EINVAL;
> -			goto out_unlock;
> -		}
> -
>   		bank = info->mode_bank;
>   		reg = info->mode_reg;
>   		mask = info->mode_mask;
>   	} else {
> -		/* Mode register same as enable register */
> +		bank = info->update_bank;
> +		reg = info->update_reg;
> +		mask = info->update_mask;
> +	}
> +
> +	if (info->shared_mode)
> +		mutex_lock(&shared_mode_mutex);
>   
> -		switch (mode) {
> -		case REGULATOR_MODE_NORMAL:
> +	switch (mode) {
> +	case REGULATOR_MODE_NORMAL:
> +		if (info->shared_mode)
> +			lp_mode_req = false;
> +
> +		if (info->mode_mask)
> +			val = info->mode_val_normal;
> +		else
>   			val = info->update_val_normal;
> -			break;
> -		case REGULATOR_MODE_IDLE:
> -			val = info->update_val_idle;
> -			break;
> -		default:
> -			ret = -EINVAL;
> -			goto out_unlock;
> +		break;
> +	case REGULATOR_MODE_IDLE:
> +		if (info->shared_mode) {
> +			struct ab8500_regulator_info *shared_regulator;
> +
> +			shared_regulator = info->shared_mode->shared_regulator;
> +			if (!shared_regulator->shared_mode->lp_mode_req) {
> +				/* Other regulator prevent LP mode */
> +				info->shared_mode->lp_mode_req = true;
> +				goto out_unlock;
> +			}
> +
> +			lp_mode_req = true;
>   		}
>   
> -		bank = info->update_bank;
> -		reg = info->update_reg;
> -		mask = info->update_mask;
> +		if (info->mode_mask)
> +			val = info->mode_val_idle;
> +		else
> +			val = info->update_val_idle;
> +		break;
> +	default:
> +		ret = -EINVAL;
> +		goto out_unlock;
>   	}
>   
> -	if (dmr || ab8500_regulator_is_enabled(rdev)) {
> +	if (info->mode_mask || ab8500_regulator_is_enabled(rdev)) {
>   		ret = abx500_mask_and_set_register_interruptible(info->dev,
>   			bank, reg, mask, val);
>   		if (ret < 0) {
> @@ -435,9 +420,12 @@ static int ab8500_regulator_set_mode(struct regulator_dev *rdev,
>   			mask, val);
>   	}
>   
> -	if (!dmr)
> +	if (!info->mode_mask)
>   		info->update_val = val;
>   
> +	if (info->shared_mode)
> +		info->shared_mode->lp_mode_req = lp_mode_req;
> +
>   out_unlock:
>   	if (info->shared_mode)
>   		mutex_unlock(&shared_mode_mutex);


  reply	other threads:[~2013-04-17  9:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-09 12:15 [PATCH 1/2] regulator: ab8500: Don't update info->update_val if write to register fails Axel Lin
2013-04-09 12:17 ` [PATCH 2/2] regulator: ab8500: Don't update lp_mode_req flag in set_mode() error paths Axel Lin
2013-04-17  9:49   ` Bengt Jönsson [this message]
2013-04-16 16:51 ` [PATCH 1/2] regulator: ab8500: Don't update info->update_val if write to register fails Axel Lin
2013-04-17  9:48 ` Bengt Jönsson
2013-04-17 14:09 ` 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=516E7025.8040508@stericsson.com \
    --to=bengt.g.jonsson@stericsson.com \
    --cc=axel.lin@ingics.com \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=lee.jones@linaro.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox