regulator: ab8500: Update info->update_val only when successfully update register
PATCH 1/1 regulator: ab8500: Update info->update_val only when successfully update register
This fixes 2 issues:
1. Don't update info->update_val if write to the register fails.
2. Don't update info->update_val if regulator is disabled, this avoid inconsistent status between the register value and info->update_val.
Signed-off-by Axel Lin <[email protected]>
--- drivers/regulator/ab8500.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-)
drivers/regulator/ab8500.c +25 -16
@@ -182,8 +182,8 @@ static unsigned int ab8500_regulator_get_optimum_mode(static int ab8500_regulator_set_mode (struct regulator_dev *rdev,unsigned int mode) { -int ret =0 ; - +int ret; +u8 update_val;struct ab8500_regulator_info *info =rdev_get_drvdata (rdev);if (info ==NULL ) {
@@ -191,32 +191,41 @@ static int ab8500_regulator_set_mode(struct regulator_dev *rdev,return -EINVAL ; } +/* ab8500 regulators share mode and enable in the same register bits. +off = 0b00 +low power mode= 0b11 +full powermode = 0b01 +(HW control mode = 0b10) +Thus we don't change the mode settings when regulator is disabled. +*/ +if (!info->is_enabled) +return 0 ; +switch (mode) {case REGULATOR_MODE_NORMAL : - info->update_val = info->update_val_normal; + update_val = info->update_val_normal;break ;case REGULATOR_MODE_IDLE : - info->update_val = info->update_val_idle; + update_val = info->update_val_idle;break ;default :return -EINVAL ; } -if (info->is_enabled) { - ret =abx500_mask_and_set_register_interruptible (info->dev, + 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); + info->update_mask, update_val); +if (ret <0 ) { +dev_err (rdev_get_dev (rdev),"couldn't set regulator mode\n" ); +return ret; } + info->update_val = update_val; + +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; }
Signature · 1 line
1.7.10.4
Quoted 7 lines · Axel Lin
This fixes 2 issues:
1. Don't update
info->update_valif write to the register fails.
2. Don't updateinfo->update_valif regulator is disabled, this avoidinconsistent status between the register value and info->update_val.Signed-off-by Axel Lin <[email protected]>
Looks fine, thanks.
Acked-by Bengt Jonsson <[email protected]>
Quoted 75 lines
--- drivers/regulator/ab8500.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-)drivers/regulator/ab8500.c +25
-16@@ -182,8 +182,8 @@ static unsigned int ab8500_regulator_get_optimum_mode(static int ab8500_regulator_set_mode (struct regulator_dev *rdev,unsigned int mode) { -int ret =0 ; - +int ret; +u8 update_val;struct ab8500_regulator_info *info =rdev_get_drvdata (rdev);if (info ==NULL ) {@@ -191,32 +191,41 @@ static int ab8500_regulator_set_mode(struct regulator_dev *rdev,return -EINVAL ; } +/* ab8500 regulators share mode and enable in the same register bits. +off = 0b00 +low power mode= 0b11 +full powermode = 0b01 +(HW control mode = 0b10) +Thus we don't change the mode settings when regulator is disabled. +*/ +if (!info->is_enabled) +return 0 ; +switch (mode) {case REGULATOR_MODE_NORMAL : - info->update_val = info->update_val_normal; + update_val = info->update_val_normal;break ;case REGULATOR_MODE_IDLE : - info->update_val = info->update_val_idle; + update_val = info->update_val_idle;break ;default :return -EINVAL ; } -if (info->is_enabled) { - ret =abx500_mask_and_set_register_interruptible (info->dev, + 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); + info->update_mask, update_val); +if (ret <0 ) { +dev_err (rdev_get_dev (rdev),"couldn't set regulator mode\n" ); +return ret; } + info->update_val = update_val; + +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; }