Skip to content

Commit 6f0b2c6

Browse files
Yadwinder Singh Brarbroonie
authored andcommitted
regulator: Add ramp_delay configuration to constraints
For some hardwares ramp_delay for BUCKs is a configurable parameter which can be configured through DT or board file.This patch adds ramp_delay to regulator constraints and allow user to configure it for regulators which supports this feature, through DT or board file. It will provide two ways of setting the ramp_delay for a regulator: First, by setting it as constraints in board file(for configurable regulators) and set_machine_constraints() will take care of setting it on hardware by calling(the provided) .set_ramp_delay() operation(callback). Second, by setting it as data in regulator_desc(as fixed/default ramp_delay rate) for a regulator in driver. regulator_set_voltage_time_sel() will give preference to constraints->ramp_delay while reading ramp_delay rate for regulator. Similarly users should also take care accordingly while refering ramp_delay rate(in case of implementing their private .set_voltage_time_sel() callbacks for different regulators). [Rewrote subject for 80 columns -- broonie] Signed-off-by: Yadwinder Singh Brar <yadi.brar@samsung.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
1 parent b5fb77e commit 6f0b2c6

5 files changed

Lines changed: 31 additions & 5 deletions

File tree

‎Documentation/devicetree/bindings/regulator/regulator.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Optional properties:
1010
- regulator-always-on: boolean, regulator should never be disabled
1111
- regulator-boot-on: bootloader/firmware enabled regulator
1212
- <name>-supply: phandle to the parent supply/regulator node
13+
- regulator-ramp-delay: ramp delay for regulator(in mV/uS)
1314

1415
Example:
1516

‎drivers/regulator/core.c‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,14 @@ static int set_machine_constraints(struct regulator_dev *rdev,
967967
}
968968
}
969969

970+
if (rdev->constraints->ramp_delay && ops->set_ramp_delay) {
971+
ret = ops->set_ramp_delay(rdev, rdev->constraints->ramp_delay);
972+
if (ret < 0) {
973+
rdev_err(rdev, "failed to set ramp_delay\n");
974+
goto out;
975+
}
976+
}
977+
970978
print_constraints(rdev);
971979
return 0;
972980
out:
@@ -2296,10 +2304,17 @@ int regulator_set_voltage_time_sel(struct regulator_dev *rdev,
22962304
unsigned int old_selector,
22972305
unsigned int new_selector)
22982306
{
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);
2307+
if (rdev->desc->uV_step) {
2308+
if (rdev->constraints->ramp_delay)
2309+
return DIV_ROUND_UP(rdev->desc->uV_step *
2310+
abs(new_selector - old_selector),
2311+
rdev->constraints->ramp_delay * 1000);
2312+
if (rdev->desc->ramp_delay)
2313+
return DIV_ROUND_UP(rdev->desc->uV_step *
2314+
abs(new_selector - old_selector),
2315+
rdev->desc->ramp_delay * 1000);
2316+
rdev_warn(rdev, "ramp_delay not set\n");
2317+
}
23032318
return 0;
23042319
}
23052320

‎drivers/regulator/of_regulator.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static void of_get_regulation_constraints(struct device_node *np,
2020
struct regulator_init_data **init_data)
2121
{
2222
const __be32 *min_uV, *max_uV, *uV_offset;
23-
const __be32 *min_uA, *max_uA;
23+
const __be32 *min_uA, *max_uA, *ramp_delay;
2424
struct regulation_constraints *constraints = &(*init_data)->constraints;
2525

2626
constraints->name = of_get_property(np, "regulator-name", NULL);
@@ -60,6 +60,10 @@ static void of_get_regulation_constraints(struct device_node *np,
6060
constraints->always_on = true;
6161
else /* status change should be possible if not always on. */
6262
constraints->valid_ops_mask |= REGULATOR_CHANGE_STATUS;
63+
64+
ramp_delay = of_get_property(np, "regulator-ramp-delay", NULL);
65+
if (ramp_delay)
66+
constraints->min_uV = be32_to_cpu(*ramp_delay);
6367
}
6468

6569
/**

‎include/linux/regulator/driver.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ enum regulator_status {
6767
*
6868
* @enable_time: Time taken for the regulator voltage output voltage to
6969
* stabilise after being enabled, in microseconds.
70+
* @set_ramp_delay: Set the ramp delay for the regulator. The driver should
71+
* select ramp delay equal to or less than(closest) ramp_delay.
7072
* @set_voltage_time_sel: Time taken for the regulator voltage output voltage
7173
* to stabilise after being set to a new value, in microseconds.
7274
* The function provides the from and to voltage selector, the
@@ -113,6 +115,7 @@ struct regulator_ops {
113115

114116
/* Time taken to enable or set voltage on the regulator */
115117
int (*enable_time) (struct regulator_dev *);
118+
int (*set_ramp_delay) (struct regulator_dev *, int ramp_delay);
116119
int (*set_voltage_time_sel) (struct regulator_dev *,
117120
unsigned int old_selector,
118121
unsigned int new_selector);

‎include/linux/regulator/machine.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ struct regulator_state {
9292
* mode.
9393
* @initial_state: Suspend state to set by default.
9494
* @initial_mode: Mode to set at startup.
95+
* @ramp_delay: Time to settle down after voltage change (unit: mV/us)
9596
*/
9697
struct regulation_constraints {
9798

@@ -125,6 +126,8 @@ struct regulation_constraints {
125126
/* mode to set on startup */
126127
unsigned int initial_mode;
127128

129+
unsigned int ramp_delay;
130+
128131
/* constraint flags */
129132
unsigned always_on:1; /* regulator never off when system is on */
130133
unsigned boot_on:1; /* bootloader/firmware enabled regulator */

0 commit comments

Comments
 (0)