Skip to content

Commit 98a175b

Browse files
Yadwinder Singh Brarbroonie
authored andcommitted
regulator: core: Add regulator_set_voltage_time_sel to calculate ramp delay.
This patch adds regulator_set_voltage_time_sel(), to move into core, the commonly used code by drivers to provide the .set_voltage_time_sel callback. It will also allow us to configure different ramp delay for different regulators easily. Signed-off-by: Yadwinder Singh Brar <yadi.brar@samsung.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
1 parent ab0d1cb commit 98a175b

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎drivers/regulator/core.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,6 +2279,30 @@ int regulator_set_voltage_time(struct regulator *regulator,
22792279
}
22802280
EXPORT_SYMBOL_GPL(regulator_set_voltage_time);
22812281

2282+
/**
2283+
*regulator_set_voltage_time_sel - get raise/fall time
2284+
* @regulator: regulator source
2285+
* @old_selector: selector for starting voltage
2286+
* @new_selector: selector for target voltage
2287+
*
2288+
* Provided with the starting and target voltage selectors, this function
2289+
* returns time in microseconds required to rise or fall to this new voltage
2290+
*
2291+
* Drivers providing uV_step in their regulator_desc and ramp_delay in
2292+
* regulation_constraints can use this as their set_voltage_time_sel()
2293+
* operation.
2294+
*/
2295+
int regulator_set_voltage_time_sel(struct regulator_dev *rdev,
2296+
unsigned int old_selector,
2297+
unsigned int new_selector)
2298+
{
2299+
if (rdev->desc->ramp_delay && rdev->desc->uV_step)
2300+
return DIV_ROUND_UP(rdev->desc->uV_step *
2301+
abs(new_selector - old_selector),
2302+
rdev->desc->ramp_delay) * 1000;
2303+
return 0;
2304+
}
2305+
22822306
/**
22832307
* regulator_sync_voltage - re-apply last regulator output voltage
22842308
* @regulator: regulator source

‎include/linux/regulator/driver.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ enum regulator_type {
170170
*
171171
* @min_uV: Voltage given by the lowest selector (if linear mapping)
172172
* @uV_step: Voltage increase with each selector (if linear mapping)
173+
* @ramp_delay: Time to settle down after voltage change (unit: mV/us)
173174
* @volt_table: Voltage mapping table (if table based mapping)
174175
*
175176
* @vsel_reg: Register for selector when using regulator_regmap_X_voltage_
@@ -189,6 +190,7 @@ struct regulator_desc {
189190

190191
unsigned int min_uV;
191192
unsigned int uV_step;
193+
unsigned int ramp_delay;
192194

193195
const unsigned int *volt_table;
194196

@@ -285,6 +287,9 @@ int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel);
285287
int regulator_is_enabled_regmap(struct regulator_dev *rdev);
286288
int regulator_enable_regmap(struct regulator_dev *rdev);
287289
int regulator_disable_regmap(struct regulator_dev *rdev);
290+
int regulator_set_voltage_time_sel(struct regulator_dev *rdev,
291+
unsigned int old_selector,
292+
unsigned int new_selector);
288293

289294
void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
290295

0 commit comments

Comments
 (0)