regulator: ab8500: Remove is_enabled from struct ab8500_regulator_info
PATCH 1/1 regulator: ab8500: Remove is_enabled from struct ab8500_regulator_info
The is_enabled flag looks not necessary at all, it also introduces some issues because current code updates info->is_enabled flag in error paths of ab8500_regulator_enable() and ab8500_regulator_disable().
Thus this patch removes is_enabled from struct ab8500_regulator_info.
This patch also removes info->is_enabled checking in ab8500_regulator_set_mode(), so it allows setting mode even the regulator is disabled.
---
Hi,
This patch also removes info->is_enabled checking in ab8500_regulator_set_mode(). I'm not very clear if we should avoid setting mode when the regulator is disabled. It looks to me if we don't want to allow setting mode when regulator is disabled, this checking should be done in regulator-core.
Seems current code in other regulator drivers does not check if regulator is enabled or not in set_mode callback implementation.
Axel
drivers/regulator/ab8500.c | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-)
drivers/regulator/ab8500.c +10 -26
@@ -30,7 +30,6 @@* @dev: device pointer * @desc: regulator description * @regulator_dev: regulator device -* @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
@@ -48,7 +47,6 @@ struct ab8500_regulator_info {struct device *dev;struct regulator_desc desc;struct regulator_dev *regulator; -bool is_enabled;int load_lp_uA;u8 update_bank;u8 update_reg;
@@ -121,8 +119,6 @@ static int ab8500_regulator_enable(struct regulator_dev *rdev)dev_err (rdev_get_dev (rdev),"couldn't set enable bits for regulator\n" ); - 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,
@@ -148,8 +144,6 @@ static int ab8500_regulator_disable(struct regulator_dev *rdev)dev_err (rdev_get_dev (rdev),"couldn't set disable bits for regulator\n" ); - 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,
@@ -202,20 +196,15 @@ static int ab8500_regulator_set_mode(struct regulator_dev *rdev,return -EINVAL ; } -if (info->is_enabled) { - ret =abx500_mask_and_set_register_interruptible (info->dev, - info->update_bank, info->update_reg, - info->update_mask, info->update_val); -if (ret <0 ) -dev_err (rdev_get_dev (rdev), -"couldn't set regulator mode\n" ); - -dev_vdbg (rdev_get_dev (rdev), -"%s-set_mode (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, info->update_val); - } + ret =abx500_mask_and_set_register_interruptible (info->dev, + info->update_bank, info->update_reg, + info->update_mask, info->update_val); +if (ret <0 ) +dev_err (rdev_get_dev (rdev),"couldn't set regulator mode\n" ); + +dev_vdbg (rdev_get_dev (rdev),"%s-set_mode (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, info->update_val);return ret; }
@@ -265,12 +254,7 @@ static int ab8500_regulator_is_enabled(struct regulator_dev *rdev) 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; +return regval & info->update_mask; }static int ab8500_regulator_get_voltage_sel (struct regulator_dev *rdev)
Signature · 1 line
1.7.10.4
Quoted 7 lines · Axel Lin
The
is_enabledflag looks not necessary at all, it also introduces some issues because current code updatesinfo->is_enabledflag in error paths ofab8500_regulator_enable()andab8500_regulator_disable().
Thus this patch removesis_enabledfrom structab8500_regulator_info.This patch also removes
info->is_enabledchecking inab8500_regulator_set_mode(), so it allows setting mode even the regulator is disabled.
This patch will change the behaviour of set_mode as the ab8500 regulators share mode and enable in the same register bits:
- off = 0b00
- low power mode= 0b11
- full powermode = 0b01
- (HW control mode = 0b10)
To keep regulator_enable/disable apart from regulator_set_mode I think this patch should not go in.
Quoted 8 lines
Signed-off-by Axel Lin <[email protected]>---
Hi,
This patch also removesinfo->is_enabledchecking inab8500_regulator_set_mode(). I'm not very clear if we should avoid setting mode when the regulator is disabled. It looks to me if we don't want to allow setting mode when regulator is disabled, this checking should be done in regulator-core.
Checking in regulator-core seems like a good idea to me.It would make the ab8500 code more clean, but I don't know how other drivers will be affected.
Quoted 3 lines
Seems current code in other regulator drivers does not check if regulator is enabled or not in
set_modecallback implementation.
Axel
I know some other hardware has separate register bits for mode and enable which matches the framework better.
Bengt
2013/3/26 Bengt Jönsson <[email protected]>:
Quoted 19 lines · Axel Lin
Quoted 10 lines
The
is_enabledflag looks not necessary at all, it also introduces some issues
because current code updatesinfo->is_enabledflag in error paths ofab8500_regulator_enable()andab8500_regulator_disable(). Thus this patch removesis_enabledfrom structab8500_regulator_info.This patch also removes
info->is_enabledchecking inab8500_regulator_set_mode(),
so it allows setting mode even the regulator is disabled.This patch will change the behaviour of
set_modeas the ab8500 regulators share mode and enable in the same register bits:
- off = 0b00
- low power mode= 0b11
- full powermode = 0b01
- (HW control mode = 0b10)
Quoted 2 lines
To keep regulator_enable/disable apart from
regulator_set_modeI think this patch should not go in.
Thanks for the review.
I'll send a patch to avoid update is_enabled flag in error paths.
Axel