regulator: qcom_spmi: Fix math of spmi_regulator_set_voltage_time_sel
authorJeffrey Hugo <jeffrey.l.hugo@gmail.com>
Wed, 19 Jun 2019 18:56:36 +0000 (11:56 -0700)
committerMark Brown <broonie@kernel.org>
Thu, 20 Jun 2019 13:18:57 +0000 (14:18 +0100)
commit61d7fdc49f03f4ec990974d1d2a8b05e64afeae4
tree3ece87bf6c4d89a4323ec0c28067b1be6ccd852d
parentfd5d10059d5ead12dd12f05ae6d96e70d1fac3df
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: e92a4047419c ("regulator: Add QCOM SPMI regulator driver")
Reported-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Reported-by: Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
Reported-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Jeffrey Hugo <jeffrey.l.hugo@gmail.com>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Tested-by: Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/regulator/qcom_spmi-regulator.c