regulator: selector stepping for voltage regulators
cover regulator: selector stepping for voltage regulators
From: Bartosz Golaszewski <[email protected]>
Hi Mark, Liam,
I know this won't make it for v5.3, but I thought I'd send it already for you to take a look. Some time ago we discussed implementing the voltage stepping in the regulator core. Here's a first go at that. The first user is the max77650 driver which actually uses it. I think there are more drivers that could reuse it later if accepted.
Bartosz Golaszewski (2):
regulator: implement selector stepping
regulator: max77650: use vsel_step
drivers/regulator/core.c | 63 ++++++++++++++++++++++ drivers/regulator/max77650-regulator.c | 73 ++++---------------------- include/linux/regulator/driver.h | 6 +++ 3 files changed, 78 insertions(+), 64 deletions(-)
Signature · 1 line
2.21.0
PATCH 1/2 regulator: implement selector stepping
From: Bartosz Golaszewski <[email protected]>
Some regulators require that the requested voltage be reached gradually by setting all or some of the intermediate values. Implement a new field in the regulator description struct that allows users to specify the number of selectors by which the regulator API should step when ramping the voltage up/down.
--- drivers/regulator/core.c | 63 ++++++++++++++++++++++++++++++++ include/linux/regulator/driver.h | 6 +++ 2 files changed, 69 insertions(+)
drivers/regulator/core.c +63 -0
@@ -3106,6 +3106,66 @@ static int _regulator_call_set_voltage_sel(struct regulator_dev *rdev,return ret; } +static int _regulator_set_voltage_sel_step (struct regulator_dev *rdev, +int uV,int new_selector) +{ +const struct regulator_ops *ops = rdev->desc->ops; +int diff, old_sel, curr_sel, ret; + +/* Stepping is only needed if the regulator is enabled. */ +if (!_regulator_is_enabled (rdev)) + goto final_set; + +if (!ops->get_voltage_sel) +return -EINVAL ; + + old_sel = ops->get_voltage_sel (rdev); +if (old_sel <0 ) +return old_sel; + + diff = new_selector - old_sel; +if (diff ==0 ) +return 0 ;/* No change needed. */ + +if (diff >0 ) { +/* Stepping up. */ +for (curr_sel = old_sel + rdev->desc->vsel_step; + curr_sel < new_selector; + curr_sel += rdev->desc->vsel_step) { +/* +* Call the callback directly instead of using +* _regulator_call_set_voltage_sel() as we don't +* want to notify anyone yet. Same in the branch +* below. +*/ + ret = ops->set_voltage_sel (rdev, curr_sel); +if (ret) + goto try_revert; + } + }else { +/* Stepping down. */ +for (curr_sel = old_sel - rdev->desc->vsel_step; + curr_sel > new_selector; + curr_sel -= rdev->desc->vsel_step) { + ret = ops->set_voltage_sel (rdev, curr_sel); +if (ret) + goto try_revert; + } + } + +final_set: +/* The final selector will trigger the notifiers. */ +return _regulator_call_set_voltage_sel (rdev, uV, new_selector); + +try_revert: +/* +* At least try to return to the previous voltage if setting a new +* one failed. +*/ + (void )ops->set_voltage_sel (rdev, old_sel); +return ret; +} +static int _regulator_set_voltage_time (struct regulator_dev *rdev,int old_uV,int new_uV) {
@@ -3179,6 +3239,9 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev, selector = ret;if (old_selector == selector) ret =0 ; +else if (rdev->desc->vsel_step) + ret =_regulator_set_voltage_sel_step ( + rdev, best_val, selector);else ret =_regulator_call_set_voltage_sel ( rdev, best_val, selector);
include/linux/regulator/driver.h +6 -0
@@ -286,6 +286,11 @@ enum regulator_type {* @vsel_range_mask: Mask for register bitfield used for range selector * @vsel_reg: Register for selector when using regulator_regmap_X_voltage_ * @vsel_mask: Mask for register bitfield used for selector +* @vsel_step: Specify the resolution of selector stepping when setting +* voltage. If 0, then no stepping is done (requested selector is +* set directly), if >0 then the regulator API will ramp the +* voltage up/down gradually each time increasing/decreasing the +* selector by the specified step value. * @csel_reg: Register for current limit selector using regmap set_current_limit * @csel_mask: Mask for register bitfield used for current limit selector * @apply_reg: Register for initiate voltage change on the output when
@@ -360,6 +365,7 @@ struct regulator_desc {unsigned int vsel_range_mask;unsigned int vsel_reg;unsigned int vsel_mask; +unsigned int vsel_step;unsigned int csel_reg;unsigned int csel_mask;unsigned int apply_reg;
Signature · 1 line
2.21.0
Mark Brown
maintainerApplied "regulator: implement selector stepping" to the regulator tree
The patch
regulator: implement selector stepping
has been applied to the regulator tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-5.3
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
From 2da8d9473e20a2f6645dcb0cea4848a2c1e83af9 Mon Sep 17 00:00:00 2001
From: Bartosz Golaszewski <[email protected]>
Date: Wed, 3 Jul 2019 18:10:34 +0200
Subject: [PATCH] regulator: implement selector stepping
Some regulators require that the requested voltage be reached gradually by setting all or some of the intermediate values. Implement a new field in the regulator description struct that allows users to specify the number of selectors by which the regulator API should step when ramping the voltage up/down.
--- drivers/regulator/core.c | 63 ++++++++++++++++++++++++++++++++ include/linux/regulator/driver.h | 6 +++ 2 files changed, 69 insertions(+)
drivers/regulator/core.c +63 -0
@@ -3106,6 +3106,66 @@ static int _regulator_call_set_voltage_sel(struct regulator_dev *rdev,return ret; } +static int _regulator_set_voltage_sel_step (struct regulator_dev *rdev, +int uV,int new_selector) +{ +const struct regulator_ops *ops = rdev->desc->ops; +int diff, old_sel, curr_sel, ret; + +/* Stepping is only needed if the regulator is enabled. */ +if (!_regulator_is_enabled (rdev)) + goto final_set; + +if (!ops->get_voltage_sel) +return -EINVAL ; + + old_sel = ops->get_voltage_sel (rdev); +if (old_sel <0 ) +return old_sel; + + diff = new_selector - old_sel; +if (diff ==0 ) +return 0 ;/* No change needed. */ + +if (diff >0 ) { +/* Stepping up. */ +for (curr_sel = old_sel + rdev->desc->vsel_step; + curr_sel < new_selector; + curr_sel += rdev->desc->vsel_step) { +/* +* Call the callback directly instead of using +* _regulator_call_set_voltage_sel() as we don't +* want to notify anyone yet. Same in the branch +* below. +*/ + ret = ops->set_voltage_sel (rdev, curr_sel); +if (ret) + goto try_revert; + } + }else { +/* Stepping down. */ +for (curr_sel = old_sel - rdev->desc->vsel_step; + curr_sel > new_selector; + curr_sel -= rdev->desc->vsel_step) { + ret = ops->set_voltage_sel (rdev, curr_sel); +if (ret) + goto try_revert; + } + } + +final_set: +/* The final selector will trigger the notifiers. */ +return _regulator_call_set_voltage_sel (rdev, uV, new_selector); + +try_revert: +/* +* At least try to return to the previous voltage if setting a new +* one failed. +*/ + (void )ops->set_voltage_sel (rdev, old_sel); +return ret; +} +static int _regulator_set_voltage_time (struct regulator_dev *rdev,int old_uV,int new_uV) {
@@ -3179,6 +3239,9 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev, selector = ret;if (old_selector == selector) ret =0 ; +else if (rdev->desc->vsel_step) + ret =_regulator_set_voltage_sel_step ( + rdev, best_val, selector);else ret =_regulator_call_set_voltage_sel ( rdev, best_val, selector);
include/linux/regulator/driver.h +6 -0
@@ -286,6 +286,11 @@ enum regulator_type {* @vsel_range_mask: Mask for register bitfield used for range selector * @vsel_reg: Register for selector when using regulator_regmap_X_voltage_ * @vsel_mask: Mask for register bitfield used for selector +* @vsel_step: Specify the resolution of selector stepping when setting +* voltage. If 0, then no stepping is done (requested selector is +* set directly), if >0 then the regulator API will ramp the +* voltage up/down gradually each time increasing/decreasing the +* selector by the specified step value. * @csel_reg: Register for current limit selector using regmap set_current_limit * @csel_mask: Mask for register bitfield used for current limit selector * @apply_reg: Register for initiate voltage change on the output when
@@ -360,6 +365,7 @@ struct regulator_desc {unsigned int vsel_range_mask;unsigned int vsel_reg;unsigned int vsel_mask; +unsigned int vsel_step;unsigned int csel_reg;unsigned int csel_mask;unsigned int apply_reg;
Signature · 1 line
2.20.1
PATCH 2/2 regulator: max77650: use vsel_step
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
Use the new vsel_step field in the regulator description to instruct the regulator API on the required voltage ramping. Switch to using the generic regmap helpers for voltage setting and remove the old set_voltage callback that handcoded the selector stepping.
--- drivers/regulator/max77650-regulator.c | 73 ++++---------------------- 1 file changed, 9 insertions(+), 64 deletions(-)
drivers/regulator/max77650-regulator.c +9 -64
@@ -108,67 +108,6 @@ static int max77650_regulator_disable(struct regulator_dev *rdev) MAX77650_REGULATOR_DISABLED); } -static int max77650_regulator_set_voltage_sel (struct regulator_dev *rdev, -unsigned int sel) -{ -struct max77650_regulator_desc *rdesc =rdev_get_drvdata (rdev); -int rv =0 , curr, diff; -bool ascending; - -/* -* If the regulator is disabled, we can program the desired -* voltage right away. -*/ -if (!max77650_regulator_is_enabled (rdev)) { -if (rdesc == &max77651_SBB1_desc) -return regulator_set_voltage_sel_pickable_regmap (rdev, - sel); -else -return regulator_set_voltage_sel_regmap (rdev, sel); - } - -/* -* Otherwise we need to manually ramp the output voltage up/down -* one step at a time. -*/ - -if (rdesc == &max77651_SBB1_desc) - curr =regulator_get_voltage_sel_pickable_regmap (rdev); -else - curr =regulator_get_voltage_sel_regmap (rdev); - -if (curr <0 ) -return curr; - - diff = curr - sel; -if (diff ==0 ) -return 0 ;/* Already there. */ -else if (diff >0 ) - ascending = false; -else - ascending = true; - -/* -* Make sure we'll get to the right voltage and break the loop even if -* the selector equals 0. -*/ -for (ascending ? curr++ : curr--;; ascending ? curr++ : curr--) { -if (rdesc == &max77651_SBB1_desc) - rv =regulator_set_voltage_sel_pickable_regmap (rdev, - curr); -else - rv =regulator_set_voltage_sel_regmap (rdev, curr); - -if (rv) -return rv; - -if (curr == sel) -break ; - } - -return 0 ; -} -static const struct regulator_ops max77650_regulator_LDO_ops = { .is_enabled = max77650_regulator_is_enabled, .enable = max77650_regulator_enable,
@@ -176,7 +115,7 @@ static const struct regulator_ops max77650_regulator_LDO_ops = { .list_voltage = regulator_list_voltage_linear, .map_voltage = regulator_map_voltage_linear, .get_voltage_sel = regulator_get_voltage_sel_regmap, - .set_voltage_sel = max77650_regulator_set_voltage_sel, + .set_voltage_sel = regulator_set_voltage_sel_regmap, .set_active_discharge = regulator_set_active_discharge_regmap, };
@@ -187,7 +126,7 @@ static const struct regulator_ops max77650_regulator_SBB_ops = { .list_voltage = regulator_list_voltage_linear, .map_voltage = regulator_map_voltage_linear, .get_voltage_sel = regulator_get_voltage_sel_regmap, - .set_voltage_sel = max77650_regulator_set_voltage_sel, + .set_voltage_sel = regulator_set_voltage_sel_regmap, .get_current_limit = regulator_get_current_limit_regmap, .set_current_limit = regulator_set_current_limit_regmap, .set_active_discharge = regulator_set_active_discharge_regmap,
@@ -200,7 +139,7 @@ static const struct regulator_ops max77651_SBB1_regulator_ops = { .disable = max77650_regulator_disable, .list_voltage = regulator_list_voltage_pickable_linear_range, .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap, - .set_voltage_sel = max77650_regulator_set_voltage_sel, + .set_voltage_sel = regulator_set_voltage_sel_pickable_regmap, .get_current_limit = regulator_get_current_limit_regmap, .set_current_limit = regulator_set_current_limit_regmap, .set_active_discharge = regulator_set_active_discharge_regmap,
@@ -217,6 +156,7 @@ static struct max77650_regulator_desc max77650_LDO_desc = { .min_uV = 1350000, .uV_step = 12500, .n_voltages = 128, + .vsel_step = 1, .vsel_mask = MAX77650_REGULATOR_V_LDO_MASK, .vsel_reg = MAX77650_REG_CNFG_LDO_A, .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED,
@@ -242,6 +182,7 @@ static struct max77650_regulator_desc max77650_SBB0_desc = { .min_uV = 800000, .uV_step = 25000, .n_voltages = 64, + .vsel_step = 1, .vsel_mask = MAX77650_REGULATOR_V_SBB_MASK, .vsel_reg = MAX77650_REG_CNFG_SBB0_A, .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED,
@@ -271,6 +212,7 @@ static struct max77650_regulator_desc max77650_SBB1_desc = { .min_uV = 800000, .uV_step = 12500, .n_voltages = 64, + .vsel_step = 1, .vsel_mask = MAX77650_REGULATOR_V_SBB_MASK, .vsel_reg = MAX77650_REG_CNFG_SBB1_A, .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED,
@@ -301,6 +243,7 @@ static struct max77650_regulator_desc max77651_SBB1_desc = { .linear_ranges = max77651_sbb1_volt_ranges, .n_linear_ranges = ARRAY_SIZE(max77651_sbb1_volt_ranges), .n_voltages = 58, + .vsel_step = 1, .vsel_range_mask = MAX77651_REGULATOR_V_SBB1_RANGE_MASK, .vsel_range_reg = MAX77650_REG_CNFG_SBB1_A, .vsel_mask = MAX77651_REGULATOR_V_SBB1_MASK,
@@ -332,6 +275,7 @@ static struct max77650_regulator_desc max77650_SBB2_desc = { .min_uV = 800000, .uV_step = 50000, .n_voltages = 64, + .vsel_step = 1, .vsel_mask = MAX77650_REGULATOR_V_SBB_MASK, .vsel_reg = MAX77650_REG_CNFG_SBB2_A, .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED,
@@ -361,6 +305,7 @@ static struct max77650_regulator_desc max77651_SBB2_desc = { .min_uV = 2400000, .uV_step = 50000, .n_voltages = 64, + .vsel_step = 1, .vsel_mask = MAX77650_REGULATOR_V_SBB_MASK, .vsel_reg = MAX77650_REG_CNFG_SBB2_A, .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED,
Signature · 1 line
2.21.0
Mark Brown
maintainerApplied "regulator: max77650: use vsel_step" to the regulator tree
The patch
regulator: max77650: use vsel_step
has been applied to the regulator tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-5.3
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
From 3c7577d442a76c2015dd765497395fb394b78051 Mon Sep 17 00:00:00 2001
From: Bartosz Golaszewski <[email protected]>
Date: Wed, 3 Jul 2019 18:10:35 +0200
Subject: [PATCH] regulator: max77650: use vsel_step
Use the new vsel_step field in the regulator description to instruct the regulator API on the required voltage ramping. Switch to using the generic regmap helpers for voltage setting and remove the old set_voltage callback that handcoded the selector stepping.
--- drivers/regulator/max77650-regulator.c | 73 ++++---------------------- 1 file changed, 9 insertions(+), 64 deletions(-)
drivers/regulator/max77650-regulator.c +9 -64
@@ -108,67 +108,6 @@ static int max77650_regulator_disable(struct regulator_dev *rdev) MAX77650_REGULATOR_DISABLED); } -static int max77650_regulator_set_voltage_sel (struct regulator_dev *rdev, -unsigned int sel) -{ -struct max77650_regulator_desc *rdesc =rdev_get_drvdata (rdev); -int rv =0 , curr, diff; -bool ascending; - -/* -* If the regulator is disabled, we can program the desired -* voltage right away. -*/ -if (!max77650_regulator_is_enabled (rdev)) { -if (rdesc == &max77651_SBB1_desc) -return regulator_set_voltage_sel_pickable_regmap (rdev, - sel); -else -return regulator_set_voltage_sel_regmap (rdev, sel); - } - -/* -* Otherwise we need to manually ramp the output voltage up/down -* one step at a time. -*/ - -if (rdesc == &max77651_SBB1_desc) - curr =regulator_get_voltage_sel_pickable_regmap (rdev); -else - curr =regulator_get_voltage_sel_regmap (rdev); - -if (curr <0 ) -return curr; - - diff = curr - sel; -if (diff ==0 ) -return 0 ;/* Already there. */ -else if (diff >0 ) - ascending = false; -else - ascending = true; - -/* -* Make sure we'll get to the right voltage and break the loop even if -* the selector equals 0. -*/ -for (ascending ? curr++ : curr--;; ascending ? curr++ : curr--) { -if (rdesc == &max77651_SBB1_desc) - rv =regulator_set_voltage_sel_pickable_regmap (rdev, - curr); -else - rv =regulator_set_voltage_sel_regmap (rdev, curr); - -if (rv) -return rv; - -if (curr == sel) -break ; - } - -return 0 ; -} -static const struct regulator_ops max77650_regulator_LDO_ops = { .is_enabled = max77650_regulator_is_enabled, .enable = max77650_regulator_enable,
@@ -176,7 +115,7 @@ static const struct regulator_ops max77650_regulator_LDO_ops = { .list_voltage = regulator_list_voltage_linear, .map_voltage = regulator_map_voltage_linear, .get_voltage_sel = regulator_get_voltage_sel_regmap, - .set_voltage_sel = max77650_regulator_set_voltage_sel, + .set_voltage_sel = regulator_set_voltage_sel_regmap, .set_active_discharge = regulator_set_active_discharge_regmap, };
@@ -187,7 +126,7 @@ static const struct regulator_ops max77650_regulator_SBB_ops = { .list_voltage = regulator_list_voltage_linear, .map_voltage = regulator_map_voltage_linear, .get_voltage_sel = regulator_get_voltage_sel_regmap, - .set_voltage_sel = max77650_regulator_set_voltage_sel, + .set_voltage_sel = regulator_set_voltage_sel_regmap, .get_current_limit = regulator_get_current_limit_regmap, .set_current_limit = regulator_set_current_limit_regmap, .set_active_discharge = regulator_set_active_discharge_regmap,
@@ -200,7 +139,7 @@ static const struct regulator_ops max77651_SBB1_regulator_ops = { .disable = max77650_regulator_disable, .list_voltage = regulator_list_voltage_pickable_linear_range, .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap, - .set_voltage_sel = max77650_regulator_set_voltage_sel, + .set_voltage_sel = regulator_set_voltage_sel_pickable_regmap, .get_current_limit = regulator_get_current_limit_regmap, .set_current_limit = regulator_set_current_limit_regmap, .set_active_discharge = regulator_set_active_discharge_regmap,
@@ -217,6 +156,7 @@ static struct max77650_regulator_desc max77650_LDO_desc = { .min_uV = 1350000, .uV_step = 12500, .n_voltages = 128, + .vsel_step = 1, .vsel_mask = MAX77650_REGULATOR_V_LDO_MASK, .vsel_reg = MAX77650_REG_CNFG_LDO_A, .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED,
@@ -242,6 +182,7 @@ static struct max77650_regulator_desc max77650_SBB0_desc = { .min_uV = 800000, .uV_step = 25000, .n_voltages = 64, + .vsel_step = 1, .vsel_mask = MAX77650_REGULATOR_V_SBB_MASK, .vsel_reg = MAX77650_REG_CNFG_SBB0_A, .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED,
@@ -271,6 +212,7 @@ static struct max77650_regulator_desc max77650_SBB1_desc = { .min_uV = 800000, .uV_step = 12500, .n_voltages = 64, + .vsel_step = 1, .vsel_mask = MAX77650_REGULATOR_V_SBB_MASK, .vsel_reg = MAX77650_REG_CNFG_SBB1_A, .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED,
@@ -301,6 +243,7 @@ static struct max77650_regulator_desc max77651_SBB1_desc = { .linear_ranges = max77651_sbb1_volt_ranges, .n_linear_ranges = ARRAY_SIZE(max77651_sbb1_volt_ranges), .n_voltages = 58, + .vsel_step = 1, .vsel_range_mask = MAX77651_REGULATOR_V_SBB1_RANGE_MASK, .vsel_range_reg = MAX77650_REG_CNFG_SBB1_A, .vsel_mask = MAX77651_REGULATOR_V_SBB1_MASK,
@@ -332,6 +275,7 @@ static struct max77650_regulator_desc max77650_SBB2_desc = { .min_uV = 800000, .uV_step = 50000, .n_voltages = 64, + .vsel_step = 1, .vsel_mask = MAX77650_REGULATOR_V_SBB_MASK, .vsel_reg = MAX77650_REG_CNFG_SBB2_A, .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED,
@@ -361,6 +305,7 @@ static struct max77650_regulator_desc max77651_SBB2_desc = { .min_uV = 2400000, .uV_step = 50000, .n_voltages = 64, + .vsel_step = 1, .vsel_mask = MAX77650_REGULATOR_V_SBB_MASK, .vsel_reg = MAX77650_REG_CNFG_SBB2_A, .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED,
Signature · 1 line
2.20.1