From 66511fa4a7902fb9ffdffc8c153f1758817fb8a4 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 16 Apr 2013 23:29:12 +0800 Subject: [PATCH] regulator: ab8500-ext: Don't update info->update_val if set_mode() fails This ensures info->update_val status is still correct if set_mode() call fails. Otherwise, get_mode() may return wrong status if a set_mode() call fails. Signed-off-by: Axel Lin Acked-by: Bengt Jonsson Signed-off-by: Mark Brown --- drivers/regulator/ab8500-ext.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/regulator/ab8500-ext.c b/drivers/regulator/ab8500-ext.c index 20680f30a968..03faf9c698c4 100644 --- a/drivers/regulator/ab8500-ext.c +++ b/drivers/regulator/ab8500-ext.c @@ -181,6 +181,7 @@ static int ab8500_ext_regulator_set_mode(struct regulator_dev *rdev, { int ret = 0; struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev); + u8 regval; if (info == NULL) { dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); @@ -189,23 +190,30 @@ static int ab8500_ext_regulator_set_mode(struct regulator_dev *rdev, switch (mode) { case REGULATOR_MODE_NORMAL: - info->update_val = info->update_val_hp; + regval = info->update_val_hp; break; case REGULATOR_MODE_IDLE: - info->update_val = info->update_val_lp; + regval = info->update_val_lp; break; default: return -EINVAL; } - if (ab8500_ext_regulator_is_enabled(rdev)) { - u8 regval; - - ret = enable(info, ®val); - if (ret < 0) + /* If regulator is enabled and info->cfg->hwreq is set, the regulator + must be on in high power, so we don't need to write the register with + the same value. + */ + if (ab8500_ext_regulator_is_enabled(rdev) && + !(info->cfg && info->cfg->hwreq)) { + ret = abx500_mask_and_set_register_interruptible(info->dev, + info->update_bank, info->update_reg, + info->update_mask, regval); + if (ret < 0) { dev_err(rdev_get_dev(rdev), "Could not set regulator mode.\n"); + return ret; + } dev_dbg(rdev_get_dev(rdev), "%s-set_mode (bank, reg, mask, value): " @@ -214,7 +222,9 @@ static int ab8500_ext_regulator_set_mode(struct regulator_dev *rdev, info->update_mask, regval); } - return ret; + info->update_val = regval; + + return 0; } static unsigned int ab8500_ext_regulator_get_mode(struct regulator_dev *rdev) -- 2.39.5