regulator: ab8500: Get rid of is_enabled from struct ab8500_regulator_info
PATCH 1/4 regulator: ab8500: Get rid of is_enabled from struct ab8500_regulator_info
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.
--- drivers/regulator/ab8500.c | 72 ++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 40 deletions(-)
drivers/regulator/ab8500.c +32 -40
@@ -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, ®val); +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, ®val); -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;
Signature · 1 line
1.7.10.4
PATCH 2/4 regulator: ab8500-ext: Get rid of is_enabled from struct ab8500_ext_regulator_info
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.
--- drivers/regulator/ab8500-ext.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
drivers/regulator/ab8500-ext.c +3 -11
@@ -29,7 +29,6 @@* @desc: regulator description * @rdev: regulator device * @cfg: regulator configuration (extension of regulator FW configuration) -* @is_enabled: status of regulator (on/off) * @update_bank: bank to control on/off * @update_reg: register to control on/off * @update_mask: mask to enable/disable and set mode of regulator
@@ -46,7 +45,6 @@ struct ab8500_ext_regulator_info {struct regulator_desc desc;struct regulator_dev *rdev;struct ab8500_ext_regulator_cfg *cfg; -bool is_enabled;u8 update_bank;u8 update_reg;u8 update_mask;
@@ -78,8 +76,6 @@ static int enable(struct ab8500_ext_regulator_info *info, u8 *regval)return ret; } - info->is_enabled = true; -return ret; }
@@ -125,8 +121,6 @@ static int disable(struct ab8500_ext_regulator_info *info, u8 *regval)return ret; } - info->is_enabled = false; -return ret; }
@@ -177,11 +171,9 @@ static int ab8500_ext_regulator_is_enabled(struct regulator_dev *rdev)if (((regval & info->update_mask) == info->update_val_lp) || ((regval & info->update_mask) == info->update_val_hp)) - info->is_enabled = true; +return 1 ;else - info->is_enabled = false; - -return info->is_enabled; +return 0 ; } static int ab8500_ext_regulator_set_mode(struct regulator_dev *rdev,
@@ -207,7 +199,7 @@ static int ab8500_ext_regulator_set_mode(struct regulator_dev *rdev,return -EINVAL ; } -if (info->is_enabled) { +if (ab8500_ext_regulator_is_enabled (rdev)) {u8 regval; ret =enable (info, ®val);
Signature · 1 line
1.7.10.4
Re: [PATCH 2/4] regulator: ab8500-ext: Get rid of is_enabled from struct ab8500_ext_regulator_info
Quoted 8 lines · Axel Lin
The intention of this patch is to simplify the code.
Maintain the
is_enabledflag is not trivial, it not only needs to set/clear the flag in disable()/enable() but also needs to set the flag inis_enable()to get initial status. The only benefit of keepingis_enabledflag is just save a register read whenset_mode(). Removeis_enabledflag makes the code simpler.Signed-off-by Axel Lin <[email protected]>
Looks fine:
Quoted 65 lines
--- drivers/regulator/ab8500-ext.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)drivers/regulator/ab8500-ext.c +3
-11@@ -29,7 +29,6 @@* @desc: regulator description * @rdev: regulator device * @cfg: regulator configuration (extension of regulator FW configuration) -* @is_enabled: status of regulator (on/off) * @update_bank: bank to control on/off * @update_reg: register to control on/off * @update_mask: mask to enable/disable and set mode of regulator @@ -46,7 +45,6 @@ struct ab8500_ext_regulator_info {struct regulator_desc desc;struct regulator_dev *rdev;struct ab8500_ext_regulator_cfg *cfg; -bool is_enabled;u8 update_bank;u8 update_reg;u8 update_mask;@@ -78,8 +76,6 @@ static int enable(struct ab8500_ext_regulator_info *info, u8 *regval)return ret; } - info->is_enabled = true; -return ret; }@@ -125,8 +121,6 @@ static int disable(struct ab8500_ext_regulator_info *info, u8 *regval)return ret; } - info->is_enabled = false; -return ret; }@@ -177,11 +171,9 @@ static int ab8500_ext_regulator_is_enabled(struct regulator_dev *rdev)if (((regval & info->update_mask) == info->update_val_lp) || ((regval & info->update_mask) == info->update_val_hp)) - info->is_enabled = true; +return 1 ;else - info->is_enabled = false; - -return info->is_enabled; +return 0 ; } static int ab8500_ext_regulator_set_mode(struct regulator_dev *rdev,@@ -207,7 +199,7 @@ static int ab8500_ext_regulator_set_mode(struct regulator_dev *rdev,return -EINVAL ; } -if (info->is_enabled) { +if (ab8500_ext_regulator_is_enabled (rdev)) {u8 regval; ret =enable (info, ®val);
Signature · 4 lines
Lee Jones Linaro ST-Ericsson Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH 3/4 regulator: ab8500-ext: Remove unnecessary checking for ab9540 and ab8540
In reply to Axel LinThis code was added by commit 0fe17e20a6
"regulator: ab8500-ext: Add support for AB9540 regulators"
and commit bd44e2cb "regulator: ab8500: Also check for AB8505 based platforms"
The original patch[1] is to set info->desc.ops = &ab9540_ext_regulator_ops.
However, ab9540_ext_regulator_ops is identical to ab8500_ext_regulator_ops[2]. Thus we can complete remove the unnecessary checking for ab9540 and ab8540.
[1] https://lkml.org/lkml/2013/3/28/333
[2] https://lkml.org/lkml/2013/4/1/178
--- drivers/regulator/ab8500-ext.c | 7 ------- 1 file changed, 7 deletions(-)
drivers/regulator/ab8500-ext.c +0 -7
@@ -389,15 +389,8 @@ int ab8500_ext_regulator_init(struct platform_device *pdev) config.init_data = &pdata->ext_regulator[i]; config.driver_data = info; -if ((is_ab9540 (ab8500) ||is_ab8540 (ab8500)) && - ((info->desc.id ==AB8500_EXT_SUPPLY1 ) || - (info->desc.id ==AB8500_EXT_SUPPLY2 ) || - (info->desc.id ==AB8500_EXT_SUPPLY3 ))) - info->desc.ops = &ab8500_ext_regulator_ops; -/* register regulator with framework */ info->rdev =regulator_register (&info->desc, &config); -if (IS_ERR (info->rdev)) { err =PTR_ERR (info->rdev); dev_err(&pdev->dev, "failed to register regulator %s\n",
Signature · 1 line
1.7.10.4
PATCH 4/4 regulator: ab8500-ext: Remove get_voltage to avoid duplicate implementation
In reply to Axel LinThe implementation of ab8500_ext_fixed_get_voltage is identical to ab8500_ext_list_voltage. We can avoid the duplicate implementation by just remove get_voltage. For fixed regulator, regulator core will call list_voltage(rdev, 0) to get voltage if both get_voltage get_voltage_sel are not implemented.
--- drivers/regulator/ab8500-ext.c | 16 ---------------- 1 file changed, 16 deletions(-)
drivers/regulator/ab8500-ext.c +0 -16
@@ -237,21 +237,6 @@ static unsigned int ab8500_ext_regulator_get_mode(struct regulator_dev *rdev)return ret; } -static int ab8500_ext_fixed_get_voltage (struct regulator_dev *rdev) -{ -struct regulation_constraints *regu_constraints = rdev->constraints; - -if (regu_constraints ==NULL ) { -dev_err (rdev_get_dev (rdev),"regulator constraints null pointer\n" ); -return -EINVAL ; - } -if (regu_constraints->min_uV && regu_constraints->max_uV) { -if (regu_constraints->min_uV == regu_constraints->max_uV) -return regu_constraints->min_uV; - } -return -EINVAL ; -} -static int ab8500_ext_list_voltage (struct regulator_dev *rdev,unsigned selector) {
@@ -275,7 +260,6 @@ static struct regulator_ops ab8500_ext_regulator_ops = { .is_enabled = ab8500_ext_regulator_is_enabled, .set_mode = ab8500_ext_regulator_set_mode, .get_mode = ab8500_ext_regulator_get_mode, - .get_voltage = ab8500_ext_fixed_get_voltage, .list_voltage = ab8500_ext_list_voltage, };
Signature · 1 line
1.7.10.4
Re: [PATCH 4/4] regulator: ab8500-ext: Remove get_voltage to avoid duplicate implementation
Quoted 7 lines · Axel Lin
The implementation of
ab8500_ext_fixed_get_voltageis identical toab8500_ext_list_voltage. We can avoid the duplicate implementation by just removeget_voltage. For fixed regulator, regulator core will calllist_voltage(rdev, 0)to get voltage if bothget_voltageget_voltage_selare not implemented.Signed-off-by Axel Lin <[email protected]>
Nice simplification:
Quoted 38 lines
--- drivers/regulator/ab8500-ext.c | 16 ---------------- 1 file changed, 16 deletions(-)drivers/regulator/ab8500-ext.c +0
-16@@ -237,21 +237,6 @@ static unsigned int ab8500_ext_regulator_get_mode(struct regulator_dev *rdev)return ret; } -static int ab8500_ext_fixed_get_voltage (struct regulator_dev *rdev) -{ -struct regulation_constraints *regu_constraints = rdev->constraints; - -if (regu_constraints ==NULL ) { -dev_err (rdev_get_dev (rdev),"regulator constraints null pointer\n" ); -return -EINVAL ; - } -if (regu_constraints->min_uV && regu_constraints->max_uV) { -if (regu_constraints->min_uV == regu_constraints->max_uV) -return regu_constraints->min_uV; - } -return -EINVAL ; -} -static int ab8500_ext_list_voltage (struct regulator_dev *rdev,unsigned selector) {@@ -275,7 +260,6 @@ static struct regulator_ops ab8500_ext_regulator_ops = { .is_enabled = ab8500_ext_regulator_is_enabled, .set_mode = ab8500_ext_regulator_set_mode, .get_mode = ab8500_ext_regulator_get_mode, - .get_voltage = ab8500_ext_fixed_get_voltage, .list_voltage = ab8500_ext_list_voltage, };
Signature · 4 lines
Lee Jones Linaro ST-Ericsson Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Quoted 7 lines · Axel Lin
The intention of this patch is to simplify the code.
Maintain the
is_enabledflag is not trivial, it not only needs to set/clear the flag in disable()/enable() but also needs to set the flag inis_enable()to get initial status. The only benefit of keepingis_enabledflag is just save a register read whenset_mode(). Removeis_enabledflag makes the code simpler.
Quoted 8 lines
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 callab8500_regulator_is_enabled()inab8500_regulator_set_mode(). This change also makes the code better in readability by moving similar functions to one place.Signed-off-by Axel Lin <[email protected]>
Code looks good to me:
Quoted 129 lines
--- drivers/regulator/ab8500.c | 72 ++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 40 deletions(-)drivers/regulator/ab8500.c +32
-40@@ -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, ®val); +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, ®val); -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;
Signature · 4 lines
Lee Jones Linaro ST-Ericsson Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Mark Brown
AppliedQuoted 1 line · Axel Lin
The intention of this patch is to simplify the code.
Applied all, thanks.