regulator: ab8500-ext: Don't allow set idle mode if info->cfg->hwreq is set
PATCH 1/3 regulator: ab8500-ext: Don't allow set idle mode if info->cfg->hwreq is set
The regulator always on with high power mode if info->cfg->hwreq is set.
If we allow set idle mode when info->cfg->hwreq is set, get_mode() returns REGULATOR_MODE_IDLE but the regulator actually is in REGULATOR_MODE_NORMAL mode. This patch avoid inconsistent status return by get_mode().
--- drivers/regulator/ab8500-ext.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/regulator/ab8500-ext.c +4 -0
@@ -192,6 +192,10 @@ static int ab8500_ext_regulator_set_mode(struct regulator_dev *rdev, info->update_val = info->update_val_hp;break ;case REGULATOR_MODE_IDLE : +/* Always on with high power mode if info->cfg->hwreq is set */ +if (info->cfg && info->cfg->hwreq) +return -EINVAL ; + info->update_val = info->update_val_lp;break ;
Signature · 1 line
1.7.10.4
PATCH 2/3 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.
--- drivers/regulator/ab8500-ext.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/regulator/ab8500-ext.c +12 -7
@@ -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,14 +190,14 @@ 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 :/* Always on with high power mode if info->cfg->hwreq is set */ if (info->cfg && info->cfg->hwreq)return -EINVAL ; - info->update_val = info->update_val_lp; + regval = info->update_val_lp;break ;default :
@@ -204,12 +205,14 @@ static int ab8500_ext_regulator_set_mode(struct regulator_dev *rdev, }if (ab8500_ext_regulator_is_enabled (rdev)) { -u8 regval; - - ret =enable (info, ®val); -if (ret <0 ) + 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): "
@@ -218,7 +221,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)
Signature · 1 line
1.7.10.4
PATCH 3/3 regulator: ab8500-ext: Remove enable() and disable() functions
In reply to Axel LinBoth enable() and disable() functions have only one caller, thus remove them.
--- drivers/regulator/ab8500-ext.c | 62 ++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 40 deletions(-)
drivers/regulator/ab8500-ext.c +22 -40
@@ -54,32 +54,44 @@ struct ab8500_ext_regulator_info {u8 update_val_hw; }; -static int enable (struct ab8500_ext_regulator_info *info,u8 *regval) +static int ab8500_ext_regulator_enable (struct regulator_dev *rdev) {int ret; +struct ab8500_ext_regulator_info *info =rdev_get_drvdata (rdev); +u8 regval; - *regval = info->update_val; +if (info ==NULL ) { +dev_err (rdev_get_dev (rdev),"regulator info null pointer\n" ); +return -EINVAL ; + }/* * To satisfy both HW high power request and SW request, the regulator * must be on in high power. */ if (info->cfg && info->cfg->hwreq) - *regval = info->update_val_hp; + regval = info->update_val_hp; +else + regval = info->update_val; ret =abx500_mask_and_set_register_interruptible (info->dev, info->update_bank, info->update_reg, - info->update_mask, *regval); + info->update_mask, regval);if (ret <0 ) {dev_err (rdev_get_dev (info->rdev),"couldn't set enable bits for regulator\n" );return ret; } -return ret; +dev_dbg (rdev_get_dev (rdev),"%s-enable (bank, reg, mask, value):" +" 0x%02x, 0x%02x, 0x%02x, 0x%02x\n" , + info->desc.name, info->update_bank, info->update_reg, + info->update_mask, regval); + +return 0 ; } -static int ab8500_ext_regulator_enable (struct regulator_dev *rdev) +static int ab8500_ext_regulator_disable (struct regulator_dev *rdev) {int ret;struct ab8500_ext_regulator_info *info =rdev_get_drvdata (rdev);
@@ -90,53 +102,23 @@ static int ab8500_ext_regulator_enable(struct regulator_dev *rdev)return -EINVAL ; } - ret =enable (info, ®val); - -dev_dbg (rdev_get_dev (rdev),"%s-enable (bank, reg, mask, value):" -" 0x%02x, 0x%02x, 0x%02x, 0x%02x\n" , - info->desc.name, info->update_bank, info->update_reg, - info->update_mask, regval); - -return ret; -} - -static int disable (struct ab8500_ext_regulator_info *info,u8 *regval) -{ -int ret; - - *regval =0x0 ; -/* * Set the regulator in HW request mode if configured */ if (info->cfg && info->cfg->hwreq) - *regval = info->update_val_hw; + regval = info->update_val_hw; +else + regval =0 ; ret =abx500_mask_and_set_register_interruptible (info->dev, info->update_bank, info->update_reg, - info->update_mask, *regval); + info->update_mask, regval);if (ret <0 ) {dev_err (rdev_get_dev (info->rdev),"couldn't set disable bits for regulator\n" );return ret; } -return ret; -} - -static int ab8500_ext_regulator_disable (struct regulator_dev *rdev) -{ -int ret; -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" ); -return -EINVAL ; - } - - ret =disable (info, ®val); - dev_dbg(rdev_get_dev(rdev), "%s-disable (bank, reg, mask, value):" " 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", info->desc.name, info->update_bank, info->update_reg,
Signature · 1 line
1.7.10.4
Quoted 16 lines · Axel Lin
The regulator always on with high power mode if
info->cfg->hwreqis set.If we allow set idle mode when
info->cfg->hwreqis set,get_mode()returnsREGULATOR_MODE_IDLEbut the regulator actually is inREGULATOR_MODE_NORMALmode. This patch avoid inconsistent status return byget_mode().Signed-off-by Axel Lin <[email protected]>z--- drivers/regulator/ab8500-ext.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/regulator/ab8500-ext.c +0
-0
drivers/regulator/ab8500-ext.c static int ab8500_ext_regulator_set_mode(struct regulator_dev *rdev, · line 201
Quoted 10 lines
drivers/regulator/ab8500-ext.c +4
-0@@ -192,6 +192,10 @@ static int ab8500_ext_regulator_set_mode(struct regulator_dev *rdev, info->update_val = info->update_val_hp;break ;case REGULATOR_MODE_IDLE : +/* Always on with high power mode if info->cfg->hwreq is set */ +if (info->cfg && info->cfg->hwreq) +return -EINVAL ; + info->update_val = info->update_val_lp;break ;
I prefer to have info->update_val updated to reflect requested mode (in get_mode) instead of returning -EINVAL. This is how I interpret Mark's comment on the other patch ([PATCH] regulator: ab8500: Fix get_mode for shared mode regulators).Otherwise, the patch should work fine.
Regards,
Bengt
Re: [RFT][PATCH 2/3] regulator: ab8500-ext: Don't update info->update_val if set_mode() fails
In reply to Axel LinQuoted 57 lines · Axel Lin
This ensures
info->update_valstatus is still correct ifset_mode()call fails. Otherwise,get_mode()may return wrong status if aset_mode()call fails.Signed-off-by Axel Lin <[email protected]>--- drivers/regulator/ab8500-ext.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)drivers/regulator/ab8500-ext.c +9
-6@@ -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,14 +190,14 @@ 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 :/* Always on with high power mode if info->cfg->hwreq is set */ if (info->cfg && info->cfg->hwreq)return -EINVAL ; - info->update_val = info->update_val_lp; + regval = info->update_val_lp;break ;default :@@ -204,12 +205,14 @@ static int ab8500_ext_regulator_set_mode(struct regulator_dev *rdev, }if (ab8500_ext_regulator_is_enabled (rdev)) { -u8 regval; - - ret =enable (info, ®val); -if (ret <0 ) + 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): "
drivers/regulator/ab8500-ext.c static int ab8500_ext_regulator_set_mode(struct regulator_dev *rdev, · line 229
Quoted 10 lines
drivers/regulator/ab8500-ext.c +3
-1@@ -218,7 +221,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)
This patch is needed to fix the error path but it partly depends on the previous patch so I would like to get that one sorted out before ack-ing this patch.
Regards,
Bengt
Re: [RFT][PATCH 3/3] regulator: ab8500-ext: Remove enable() and disable() functions
In reply to Axel LinQuoted 3 lines · Axel Lin
Both
enable()anddisable()functions have only one caller, thus remove them.Signed-off-by Axel Lin <[email protected]>
This patch depends on the first one in the series so I would like to get first patch sorted out first.
If the first patch goes in, I am fine with this one too.
Regards,
Bengt
Quoted 117 lines
--- drivers/regulator/ab8500-ext.c | 62 ++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 40 deletions(-)drivers/regulator/ab8500-ext.c +22
-40@@ -54,32 +54,44 @@ struct ab8500_ext_regulator_info {u8 update_val_hw; }; -static int enable (struct ab8500_ext_regulator_info *info,u8 *regval) +static int ab8500_ext_regulator_enable (struct regulator_dev *rdev) {int ret; +struct ab8500_ext_regulator_info *info =rdev_get_drvdata (rdev); +u8 regval; - *regval = info->update_val; +if (info ==NULL ) { +dev_err (rdev_get_dev (rdev),"regulator info null pointer\n" ); +return -EINVAL ; + }/* * To satisfy both HW high power request and SW request, the regulator * must be on in high power. */ if (info->cfg && info->cfg->hwreq) - *regval = info->update_val_hp; + regval = info->update_val_hp; +else + regval = info->update_val; ret =abx500_mask_and_set_register_interruptible (info->dev, info->update_bank, info->update_reg, - info->update_mask, *regval); + info->update_mask, regval);if (ret <0 ) {dev_err (rdev_get_dev (info->rdev),"couldn't set enable bits for regulator\n" );return ret; } -return ret; +dev_dbg (rdev_get_dev (rdev),"%s-enable (bank, reg, mask, value):" +" 0x%02x, 0x%02x, 0x%02x, 0x%02x\n" , + info->desc.name, info->update_bank, info->update_reg, + info->update_mask, regval); + +return 0 ; } -static int ab8500_ext_regulator_enable (struct regulator_dev *rdev) +static int ab8500_ext_regulator_disable (struct regulator_dev *rdev) {int ret;struct ab8500_ext_regulator_info *info =rdev_get_drvdata (rdev);@@ -90,53 +102,23 @@ static int ab8500_ext_regulator_enable(struct regulator_dev *rdev)return -EINVAL ; } - ret =enable (info, ®val); - -dev_dbg (rdev_get_dev (rdev),"%s-enable (bank, reg, mask, value):" -" 0x%02x, 0x%02x, 0x%02x, 0x%02x\n" , - info->desc.name, info->update_bank, info->update_reg, - info->update_mask, regval); - -return ret; -} - -static int disable (struct ab8500_ext_regulator_info *info,u8 *regval) -{ -int ret; - - *regval =0x0 ; -/* * Set the regulator in HW request mode if configured */ if (info->cfg && info->cfg->hwreq) - *regval = info->update_val_hw; + regval = info->update_val_hw; +else + regval =0 ; ret =abx500_mask_and_set_register_interruptible (info->dev, info->update_bank, info->update_reg, - info->update_mask, *regval); + info->update_mask, regval);if (ret <0 ) {dev_err (rdev_get_dev (info->rdev),"couldn't set disable bits for regulator\n" );return ret; } -return ret; -} - -static int ab8500_ext_regulator_disable (struct regulator_dev *rdev) -{ -int ret; -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" ); -return -EINVAL ; - } - - ret =disable (info, ®val); - dev_dbg(rdev_get_dev(rdev), "%s-disable (bank, reg, mask, value):" " 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", info->desc.name, info->update_bank, info->update_reg,
2013/4/16 Bengt Jönsson <[email protected]>:
Quoted 30 lines · Axel Lin
Quoted 29 lines
The regulator always on with high power mode if
info->cfg->hwreqis set.If we allow set idle mode when
info->cfg->hwreqis set,get_mode()returnsREGULATOR_MODE_IDLEbut the regulator actually is inREGULATOR_MODE_NORMALmode.
This patch avoid inconsistent status return byget_mode().Signed-off-by Axel Lin <[email protected]>z--- drivers/regulator/ab8500-ext.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/regulator/ab8500-ext.c +1
-0@@ -192,6 +192,10 @@ static int ab8500_ext_regulator_set_mode(struct regulator_dev *rdev, info->update_val = info->update_val_hp;break ;case REGULATOR_MODE_IDLE : +/* Always on with high power mode if info->cfg->hwreq is set */
drivers/regulator/ab8500-ext.c +3
-0+if (info->cfg && info->cfg->hwreq) +return -EINVAL ; +
Quoted 8 lines
Quoted 3 lines
info->update_val = info->update_val_lp; break;I prefer to have
info->update_valupdated to reflect requested mode (inget_mode) instead of returning-EINVAL. This is how I interpret Mark's comment on the other patch ([PATCH] regulator: ab8500: Fixget_modefor shared mode regulators).Otherwise, the patch should work fine.
Well, I drop this path and send v2 for other patches now.
Thanks for the review,
Axel