regulator: Support regulators where voltage ranges are selectable
For example ROHM BD71837 and ROHM BD71847 Power management ICs have regulators which provide multiple linear ranges. Ranges can be selected by individual non contagious bit in vsel register. Add regmap helper functions for selecting ranges.
---
For example the BD71847 has BUCK which vsel register consists of bits [7:6] voltage range selection
[2:0] voltage selection from used range
We can't use table based mapping or linear range mapping and hide range selection in voltage selection because current table based mapping or linear range mapping options can't cope with the non contagious vsel_mask (because that would lead selector to be greater than n_voltages).
So here idea is to do simple 'selector to range' - mapping by assigning selector 0 as first selector for first voltage in firsr range and selector equal to "voltages in first range" as selector for first voltage in second range etc.
drivers/regulator/core.c | 5 + drivers/regulator/helpers.c | 232 +++++++++++++++++++++++++++++++++++++++ include/linux/regulator/driver.h | 20 +++- 3 files changed, 256 insertions(+), 1 deletion(-)
drivers/regulator/core.c +5 -0
@@ -2783,6 +2783,11 @@ static int regulator_map_voltage(struct regulator_dev *rdev, int min_uV,if (desc->ops->list_voltage == regulator_list_voltage_linear_range)return regulator_map_voltage_linear_range (rdev, min_uV, max_uV); +if (desc->ops->list_voltage == + regulator_list_voltage_pickable_linear_range) +return regulator_map_voltage_pickable_linear_range (rdev, + min_uV, max_uV); +return regulator_map_voltage_iterate (rdev, min_uV, max_uV); }
drivers/regulator/helpers.c +232 -0
250 lines not on this page · raw message
include/linux/regulator/driver.h +19 -1
@@ -271,9 +271,16 @@ enum regulator_type {* @ramp_delay: Time to settle down after voltage change (unit: uV/us) * @min_dropout_uV: The minimum dropout voltage this regulator can handle * @linear_ranges: A constant table of possible voltage ranges. -* @n_linear_ranges: Number of entries in the @linear_ranges table. +* @linear_range_selectors: A constant table of voltage range selectors. +* If pickable ranges are used each range must +* have corresponding selector here. +* @n_linear_ranges: Number of entries in the @linear_ranges (and in +* linear_range_selectors if used) table(s). * @volt_table: Voltage mapping table (if table based mapping) * +* @vsel_range_reg: Register for range selector when using pickable ranges +* and regulator_regmap_X_voltage_X_pickable functions. +* @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 * @csel_reg: Register for TPS65218 LS3 current regulator
@@ -338,10 +345,14 @@ struct regulator_desc {int min_dropout_uV;const struct regulator_linear_range *linear_ranges; +const unsigned int *linear_range_selectors; +int n_linear_ranges;const unsigned int *volt_table; +unsigned int vsel_range_reg; +unsigned int vsel_range_mask;unsigned int vsel_reg;unsigned int vsel_mask;unsigned int csel_reg;
@@ -498,18 +509,25 @@ int regulator_mode_to_status(unsigned int);int regulator_list_voltage_linear (struct regulator_dev *rdev,unsigned int selector); +int regulator_list_voltage_pickable_linear_range (struct regulator_dev *rdev, +unsigned int selector);int regulator_list_voltage_linear_range (struct regulator_dev *rdev,unsigned int selector);int regulator_list_voltage_table (struct regulator_dev *rdev,unsigned int selector);int regulator_map_voltage_linear (struct regulator_dev *rdev,int min_uV,int max_uV); +int regulator_map_voltage_pickable_linear_range (struct regulator_dev *rdev, +int min_uV,int max_uV);int regulator_map_voltage_linear_range (struct regulator_dev *rdev,int min_uV,int max_uV);int regulator_map_voltage_iterate (struct regulator_dev *rdev,int min_uV,int max_uV);int regulator_map_voltage_ascend (struct regulator_dev *rdev,int min_uV,int max_uV); +int regulator_get_voltage_sel_pickable_regmap (struct regulator_dev *rdev); +int regulator_set_voltage_sel_pickable_regmap (struct regulator_dev *rdev, +unsigned int sel);int regulator_get_voltage_sel_regmap (struct regulator_dev *rdev);int regulator_set_voltage_sel_regmap (struct regulator_dev *rdev,unsigned sel);int regulator_is_enabled_regmap (struct regulator_dev *rdev);
Signature · 1 line
2.14.3
Quoted 6 lines · Matti Vaittinen
For example ROHM BD71837 and ROHM BD71847 Power management ICs have regulators which provide multiple linear ranges. Ranges can be selected by individual non contagious bit in vsel register. Add regmap helper functions for selecting ranges.
Signed-off-by Matti Vaittinen <[email protected]>
[Snip...]
Quoted 43 lines
drivers/regulator/helpers.c +42
-0+static int regulator_range_selector_to_index (struct regulator_dev *rdev, +unsigned int rval) +{ +int i; + +if (!rdev->desc->linear_range_selectors) +return -EINVAL ; + + rval &= rdev->desc->vsel_range_mask; + +for (i =0 ; i < rdev->desc->n_linear_ranges; i++) { +if (rdev->desc->linear_range_selectors[i] == rval) +return i; + } +return -EINVAL ; +} + +/** +* regulator_get_voltage_sel_pickable_regmap - pickable range get_voltage_sel +* +* @rdev: regulator to operate on +* +* Regulators that use regmap for their register I/O and use pickable +* ranges can set the vsel_reg, vsel_mask, vsel_range_reg and vsel_range_mask +* fields in their descriptor and then use this as their get_voltage_vsel +* operation, saving some code. +*/ +int regulator_get_voltage_sel_pickable_regmap (struct regulator_dev *rdev) +{ +unsigned int r_val; +unsigned int range; +unsigned int val; +int ret, i; +unsigned int voltages_in_range =0 ; + +if (!rdev->desc->linear_ranges) +return -EINVAL ; + + ret =regmap_read (rdev->regmap, rdev->desc->vsel_reg, &val); +if (ret !=0 ) +return ret; +
drivers/regulator/helpers.c int regulator_disable_regmap(struct regulator_dev *rdev) · line 157
Quoted 10 lines
drivers/regulator/helpers.c +10
-0+ ret =regmap_read (rdev->regmap, rdev->desc->vsel_range_reg, &r_val); +if (ret !=0 ) +return ret; + + val &= rdev->desc->vsel_mask; + val >>=ffs (rdev->desc->vsel_mask) -1 ; + + range =regulator_range_selector_to_index (rdev, r_val); +if (range <0 ) +return -EINVAL ;
Got buildbot warning for checking whether unsigned int is negative. I'll fix this one.
Other than that - I have BD71847 support almost finished - should I send this change as part of that patch set as these helpers would be used by the BD71847 patch series?
Br,
Matti Vaittinen
Mark Brown
maintainerQuoted 3 lines · Matti Vaittinen
Other than that - I have BD71847 support almost finished - should I send this change as part of that patch set as these helpers would be used by the BD71847 patch series?
Yes.