[PATCH] regulator: pf1550: fix division by zero in the ramp rate selection

From: Donggeun Yoo

Date: Thu Sep 03 2026 - 05:59:29 EST


set_machine_constraints() calls the set_ramp_delay() op when either
constraints->ramp_delay or constraints->ramp_disable is set. The
regulator binding documents regulator-ramp-delay = <0> as the way to
disable ramp control, and of_get_regulation_constraints() turns that
into ramp_disable = true while leaving ramp_delay at 0, so the op is
called with a ramp_delay of 0. The range check rejects negative values
and values above 6250 but not zero, and the value is then used as a
divisor.

The mapping is also wrong for the values that do pass the check. The
hardware offers two rates, 6250 uV/us and 3125 uV/us, selected by
SWx_DVSSPEED in SWx_CTRL1. Dividing 6250 by the requested rate and
taking bit 1 of the quotient does not map monotonically onto them: a
request for 1500 uV/us selects 6250 uV/us, while a request for the
faster 2000 uV/us selects 3125 uV/us.

Replace the division with a direct mapping onto the two supported
rates. Requests at or below 3125 uV/us get the slower rate and anything
above it gets the faster one. A ramp_delay of 0 asks for ramp control
to be disabled, which this hardware cannot do, so it gets the fastest
rate; pfuze100 handles the disabled case the same way.

Fixes: 7320d41c29bb ("regulator: pf1550: Add support for regulator")
Signed-off-by: Donggeun Yoo <donggeunyoo.kernel@xxxxxxxxx>
---
Compile-tested only, I do not have PF1550 hardware. The register
semantics were checked against the PF1550 data sheet rev 3.0, table 28
(SWx DVS setting selection) and the SW1_CTRL1 register description.

drivers/regulator/pf1550-regulator.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/drivers/regulator/pf1550-regulator.c b/drivers/regulator/pf1550-regulator.c
index 610eac9bb9cb..5394bc784e1d 100644
--- a/drivers/regulator/pf1550-regulator.c
+++ b/drivers/regulator/pf1550-regulator.c
@@ -49,17 +49,26 @@ static const int pf1550_ldo13_volts[] = {
static int pf1550_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
{
int id = rdev_get_id(rdev);
- unsigned int ramp_bits = 0;
+ unsigned int ramp_bits;
int ret;

if (id > PF1550_VREFDDR)
return -EACCES;

- if (ramp_delay < 0 || ramp_delay > 6250)
+ switch (ramp_delay) {
+ case 0:
+ /* Ramp control is disabled, so use the fastest rate. */
+ ramp_bits = 0;
+ break;
+ case 1 ... 3125:
+ ramp_bits = 1;
+ break;
+ case 3126 ... 6250:
+ ramp_bits = 0;
+ break;
+ default:
return -EINVAL;
-
- ramp_delay = 6250 / ramp_delay;
- ramp_bits = ramp_delay >> 1;
+ }

ret = regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg + 4, 0x10,
ramp_bits << 4);
--
2.53.0