Skip to content

Commit 8f23cfb

Browse files
andredbroonie
authored andcommitted
regulator: s2mps11: refactor S2MPG10 ::set_voltage_time() for S2MPG11 reuse
The upcoming S2MPG11 support needs a similar, but different version of ::set_voltage_time(). For S2MPG10, the downwards and upwards ramps for a rail are at different offsets at the same bit positions, while for S2MPG11 the ramps are at the same offset at different bit positions. Refactor the existing version slightly to allow reuse. Signed-off-by: André Draszik <andre.draszik@linaro.org> Link: https://patch.msgid.link/20260122-s2mpg1x-regulators-v7-17-3b1f9831fffd@linaro.org Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent a2b8b9f commit 8f23cfb

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

drivers/regulator/s2mps11.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -566,26 +566,23 @@ static int s2mpg10_regulator_buck_enable_time(struct regulator_dev *rdev)
566566
+ DIV_ROUND_UP(curr_uV, s2mpg10_desc->enable_ramp_rate));
567567
}
568568

569-
static int s2mpg10_regulator_buck_set_voltage_time(struct regulator_dev *rdev,
570-
int old_uV, int new_uV)
569+
static int s2mpg1x_regulator_buck_set_voltage_time(struct regulator_dev *rdev,
570+
int old_uV, int new_uV,
571+
unsigned int ramp_reg,
572+
unsigned int ramp_mask)
571573
{
572-
unsigned int ramp_reg, ramp_sel, ramp_rate;
574+
unsigned int ramp_sel, ramp_rate;
573575
int ret;
574576

575577
if (old_uV == new_uV)
576578
return 0;
577579

578-
ramp_reg = rdev->desc->ramp_reg;
579-
if (old_uV > new_uV)
580-
/* The downwards ramp is at a different offset. */
581-
ramp_reg += S2MPG10_PMIC_DVS_RAMP4 - S2MPG10_PMIC_DVS_RAMP1;
582-
583580
ret = regmap_read(rdev->regmap, ramp_reg, &ramp_sel);
584581
if (ret)
585582
return ret;
586583

587-
ramp_sel &= rdev->desc->ramp_mask;
588-
ramp_sel >>= ffs(rdev->desc->ramp_mask) - 1;
584+
ramp_sel &= ramp_mask;
585+
ramp_sel >>= ffs(ramp_mask) - 1;
589586
if (ramp_sel >= rdev->desc->n_ramp_values ||
590587
!rdev->desc->ramp_delay_table)
591588
return -EINVAL;
@@ -595,6 +592,21 @@ static int s2mpg10_regulator_buck_set_voltage_time(struct regulator_dev *rdev,
595592
return DIV_ROUND_UP(abs(new_uV - old_uV), ramp_rate);
596593
}
597594

595+
static int s2mpg10_regulator_buck_set_voltage_time(struct regulator_dev *rdev,
596+
int old_uV, int new_uV)
597+
{
598+
unsigned int ramp_reg;
599+
600+
ramp_reg = rdev->desc->ramp_reg;
601+
if (old_uV > new_uV)
602+
/* The downwards ramp is at a different offset. */
603+
ramp_reg += S2MPG10_PMIC_DVS_RAMP4 - S2MPG10_PMIC_DVS_RAMP1;
604+
605+
return s2mpg1x_regulator_buck_set_voltage_time(rdev, old_uV, new_uV,
606+
ramp_reg,
607+
rdev->desc->ramp_mask);
608+
}
609+
598610
/*
599611
* We assign both, ::set_voltage_time() and ::set_voltage_time_sel(), because
600612
* only if the latter is != NULL, the regulator core will call neither during

0 commit comments

Comments
 (0)