Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

André Draszik and committed by
Mark Brown
8f23cfbe a2b8b9f3

+22 -10
+22 -10
drivers/regulator/s2mps11.c
··· 566 566 + DIV_ROUND_UP(curr_uV, s2mpg10_desc->enable_ramp_rate)); 567 567 } 568 568 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) 571 573 { 572 - unsigned int ramp_reg, ramp_sel, ramp_rate; 574 + unsigned int ramp_sel, ramp_rate; 573 575 int ret; 574 576 575 577 if (old_uV == new_uV) 576 578 return 0; 577 579 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 - 583 580 ret = regmap_read(rdev->regmap, ramp_reg, &ramp_sel); 584 581 if (ret) 585 582 return ret; 586 583 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; 589 586 if (ramp_sel >= rdev->desc->n_ramp_values || 590 587 !rdev->desc->ramp_delay_table) 591 588 return -EINVAL; ··· 590 593 ramp_rate = rdev->desc->ramp_delay_table[ramp_sel]; 591 594 592 595 return DIV_ROUND_UP(abs(new_uV - old_uV), ramp_rate); 596 + } 597 + 598 + static int s2mpg10_regulator_buck_set_voltage_time(struct regulator_dev *rdev, 599 + int old_uV, int new_uV) 600 + { 601 + unsigned int ramp_reg; 602 + 603 + ramp_reg = rdev->desc->ramp_reg; 604 + if (old_uV > new_uV) 605 + /* The downwards ramp is at a different offset. */ 606 + ramp_reg += S2MPG10_PMIC_DVS_RAMP4 - S2MPG10_PMIC_DVS_RAMP1; 607 + 608 + return s2mpg1x_regulator_buck_set_voltage_time(rdev, old_uV, new_uV, 609 + ramp_reg, 610 + rdev->desc->ramp_mask); 593 611 } 594 612 595 613 /*