regulator: ab8500: Don't update lp_mode_req flag in set_mode() error paths

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>
Acked-by: Bengt Jonsson <bengt.g.jonsson@stericsson.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
This commit is contained in:
Axel Lin 2013-04-09 20:17:15 +08:00 committed by Mark Brown
parent f04adc5ab3
commit 0b665062a1

View File

@ -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 */
switch (mode) {
case REGULATOR_MODE_NORMAL:
val = info->update_val_normal;
break;
case REGULATOR_MODE_IDLE:
val = info->update_val_idle;
break;
default:
ret = -EINVAL;
goto out_unlock;
}
bank = info->update_bank;
reg = info->update_reg;
mask = info->update_mask;
}
if (dmr || ab8500_regulator_is_enabled(rdev)) {
if (info->shared_mode)
mutex_lock(&shared_mode_mutex);
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:
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;
}
if (info->mode_mask)
val = info->mode_val_idle;
else
val = info->update_val_idle;
break;
default:
ret = -EINVAL;
goto out_unlock;
}
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);