Skip to content

Commit d29f54d

Browse files
oliv3rbroonie
authored andcommitted
regulator: axp20x: add support for set_ramp_delay for AXP209
The AXP209 supports ramping up voltages on several regulators such as DCDC2 and LDO3. This patch adds preliminary support for the regulator-ramp-delay property for these 2 regulators. Note that the voltage ramp only works when regulator is already enabled. E.g. when going from say 0.7 V to 3.6 V. When turning on the regulator, no voltage ramp is performed in hardware. What this means, is that if the bootloader brings up the voltage at 0.7 V, the ramp delay property is properly applied. If however, the bootloader leaves the power off, no ramp delay is applied when the power is enabled by the regulator framework. Signed-off-by: Olliver Schinagl <[email protected]> Signed-off-by: Priit Laes <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 16aa70e commit d29f54d

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

drivers/regulator/axp20x-regulator.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@
5151
#define AXP20X_PWR_OUT_DCDC2_MASK BIT_MASK(4)
5252
#define AXP20X_PWR_OUT_LDO3_MASK BIT_MASK(6)
5353

54+
#define AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_RATE_MASK BIT_MASK(0)
55+
#define AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_RATE(x) \
56+
((x) << 0)
57+
#define AXP20X_DCDC2_LDO3_V_RAMP_LDO3_RATE_MASK BIT_MASK(1)
58+
#define AXP20X_DCDC2_LDO3_V_RAMP_LDO3_RATE(x) \
59+
((x) << 1)
60+
#define AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN_MASK BIT_MASK(2)
61+
#define AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN BIT(2)
62+
#define AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN_MASK BIT_MASK(3)
63+
#define AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN BIT(3)
64+
5465
#define AXP20X_LDO4_V_OUT_1250mV_START 0x0
5566
#define AXP20X_LDO4_V_OUT_1250mV_STEPS 0
5667
#define AXP20X_LDO4_V_OUT_1250mV_END \
@@ -346,6 +357,79 @@
346357
.ops = &axp20x_ops_range, \
347358
}
348359

360+
static const int axp209_dcdc2_ldo3_slew_rates[] = {
361+
1600,
362+
800,
363+
};
364+
365+
static int axp20x_set_ramp_delay(struct regulator_dev *rdev, int ramp)
366+
{
367+
struct axp20x_dev *axp20x = rdev_get_drvdata(rdev);
368+
const struct regulator_desc *desc = rdev->desc;
369+
u8 reg, mask, enable, cfg = 0xff;
370+
const int *slew_rates;
371+
int rate_count = 0;
372+
373+
if (!rdev)
374+
return -EINVAL;
375+
376+
switch (axp20x->variant) {
377+
case AXP209_ID:
378+
if (desc->id == AXP20X_DCDC2) {
379+
rate_count = ARRAY_SIZE(axp209_dcdc2_ldo3_slew_rates);
380+
reg = AXP20X_DCDC2_LDO3_V_RAMP;
381+
mask = AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_RATE_MASK |
382+
AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN_MASK;
383+
enable = (ramp > 0) ?
384+
AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN :
385+
!AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN;
386+
break;
387+
}
388+
389+
if (desc->id == AXP20X_LDO3) {
390+
slew_rates = axp209_dcdc2_ldo3_slew_rates;
391+
rate_count = ARRAY_SIZE(axp209_dcdc2_ldo3_slew_rates);
392+
reg = AXP20X_DCDC2_LDO3_V_RAMP;
393+
mask = AXP20X_DCDC2_LDO3_V_RAMP_LDO3_RATE_MASK |
394+
AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN_MASK;
395+
enable = (ramp > 0) ?
396+
AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN :
397+
!AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN;
398+
break;
399+
}
400+
401+
if (rate_count > 0)
402+
break;
403+
404+
/* fall through */
405+
default:
406+
/* Not supported for this regulator */
407+
return -ENOTSUPP;
408+
}
409+
410+
if (ramp == 0) {
411+
cfg = enable;
412+
} else {
413+
int i;
414+
415+
for (i = 0; i < rate_count; i++) {
416+
if (ramp <= slew_rates[i])
417+
cfg = AXP20X_DCDC2_LDO3_V_RAMP_LDO3_RATE(i);
418+
else
419+
break;
420+
}
421+
422+
if (cfg == 0xff) {
423+
dev_err(axp20x->dev, "unsupported ramp value %d", ramp);
424+
return -EINVAL;
425+
}
426+
427+
cfg |= enable;
428+
}
429+
430+
return regmap_update_bits(axp20x->regmap, reg, mask, cfg);
431+
}
432+
349433
static const struct regulator_ops axp20x_ops_fixed = {
350434
.list_voltage = regulator_list_voltage_linear,
351435
};
@@ -366,6 +450,7 @@ static const struct regulator_ops axp20x_ops = {
366450
.enable = regulator_enable_regmap,
367451
.disable = regulator_disable_regmap,
368452
.is_enabled = regulator_is_enabled_regmap,
453+
.set_ramp_delay = axp20x_set_ramp_delay,
369454
};
370455

371456
static const struct regulator_ops axp20x_ops_sw = {

0 commit comments

Comments
 (0)