Commit 398715ab authored by Axel Lin's avatar Axel Lin Committed by Mark Brown

regulator: core: Support table based mapping in regulator_set_voltage_time_sel

For table based mapping, we can calculate voltage difference by below equation:
abs(rdev->desc->volt_table[new_selector] - rdev->desc->volt_table[old_selector])

Thus we can make regulator_set_voltage_time_sel work for table based mapping.

regulator_set_voltage_time_sel() only supports linear or table based mapping.
In case it is misused, also warn if neither linear nor table based mapping
is used with regulator_set_voltage_time_sel().
Signed-off-by: default avatarAxel Lin <axel.lin@gmail.com>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent 086ccd43
...@@ -2296,25 +2296,38 @@ EXPORT_SYMBOL_GPL(regulator_set_voltage_time); ...@@ -2296,25 +2296,38 @@ EXPORT_SYMBOL_GPL(regulator_set_voltage_time);
* Provided with the starting and target voltage selectors, this function * Provided with the starting and target voltage selectors, this function
* returns time in microseconds required to rise or fall to this new voltage * returns time in microseconds required to rise or fall to this new voltage
* *
* Drivers providing uV_step in their regulator_desc and ramp_delay in * Drivers providing uV_step or volt_table in their regulator_desc and
* regulation_constraints can use this as their set_voltage_time_sel() * ramp_delay in regulation_constraints can use this as their
* operation. * set_voltage_time_sel() operation.
*/ */
int regulator_set_voltage_time_sel(struct regulator_dev *rdev, int regulator_set_voltage_time_sel(struct regulator_dev *rdev,
unsigned int old_selector, unsigned int old_selector,
unsigned int new_selector) unsigned int new_selector)
{ {
if (rdev->desc->uV_step) { unsigned int ramp_delay = 0;
if (rdev->constraints->ramp_delay)
return DIV_ROUND_UP(rdev->desc->uV_step * if (rdev->constraints->ramp_delay)
abs(new_selector - old_selector), ramp_delay = rdev->constraints->ramp_delay;
rdev->constraints->ramp_delay * 1000); else if (rdev->desc->ramp_delay)
if (rdev->desc->ramp_delay) ramp_delay = rdev->desc->ramp_delay;
return DIV_ROUND_UP(rdev->desc->uV_step *
abs(new_selector - old_selector), if (ramp_delay == 0) {
rdev->desc->ramp_delay * 1000);
rdev_warn(rdev, "ramp_delay not set\n"); rdev_warn(rdev, "ramp_delay not set\n");
return 0;
} }
if (rdev->desc->uV_step) {
return DIV_ROUND_UP(rdev->desc->uV_step *
abs(new_selector - old_selector),
ramp_delay * 1000);
} else if (rdev->desc->volt_table) {
return DIV_ROUND_UP(abs(rdev->desc->volt_table[new_selector] -
rdev->desc->volt_table[old_selector]),
ramp_delay * 1000);
} else {
rdev_warn(rdev, "Unsupported voltage mapping settings\n");
}
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment