Skip to content

Commit 61d7fdc

Browse files
Jeffrey Hugobroonie
authored andcommitted
regulator: qcom_spmi: Fix math of spmi_regulator_set_voltage_time_sel
spmi_regulator_set_voltage_time_sel() calculates the amount of delay needed as the result of setting a new voltage. Essentially this is the absolute difference of the old and new voltages, divided by the slew rate. The implementation of spmi_regulator_set_voltage_time_sel() is wrong. It attempts to calculate the difference in voltages by using the difference in selectors and multiplying by the voltage step between selectors. This ignores the possibility that the old and new selectors might be from different ranges, which have different step values. Also, the difference between the selectors may encapsulate N ranges inbetween, so a summation of each selector change from old to new would be needed. Lets avoid all of that complexity, and just get the actual voltage represented by both the old and new selector, and use those to directly compute the voltage delta. This is more straight forward, and has the side benifit of avoiding issues with regulator implementations that don't have hardware register support to get the current configured range. Fixes: e92a404 ("regulator: Add QCOM SPMI regulator driver") Reported-by: Bjorn Andersson <[email protected]> Reported-by: Jorge Ramirez-Ortiz <[email protected]> Reported-by: Mark Brown <[email protected]> Signed-off-by: Jeffrey Hugo <[email protected]> Reviewed-by: Bjorn Andersson <[email protected]> Tested-by: Jorge Ramirez-Ortiz <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent fd5d100 commit 61d7fdc

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

drivers/regulator/qcom_spmi-regulator.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -813,14 +813,10 @@ static int spmi_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
813813
unsigned int old_selector, unsigned int new_selector)
814814
{
815815
struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
816-
const struct spmi_voltage_range *range;
817816
int diff_uV;
818817

819-
range = spmi_regulator_find_range(vreg);
820-
if (!range)
821-
return -EINVAL;
822-
823-
diff_uV = abs(new_selector - old_selector) * range->step_uV;
818+
diff_uV = abs(spmi_regulator_common_list_voltage(rdev, new_selector) -
819+
spmi_regulator_common_list_voltage(rdev, old_selector));
824820

825821
return DIV_ROUND_UP(diff_uV, vreg->slew_rate);
826822
}

0 commit comments

Comments
 (0)