regulator: palmas: Fix calcuating selector in palmas_map_voltage_smps
Subsystems (2)
PATCH 1/1 regulator: palmas: Fix calcuating selector in palmas_map_voltage_smps
The logic of calculating selector in palmas_map_voltage_smps() does not match the logic to list voltage in palmas_list_voltage_smps().
We use below equation to calculate voltage when selector > 0:
voltage = (0.49V + (selector * 0.01V)) * RANGE
RANGE is either x1 or x2
So we need to take into account with the multiplier set in VSEL register when calculating selector in palmas_map_voltage_smps()
--- drivers/regulator/palmas-regulator.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/regulator/palmas-regulator.c +14 -3
@@ -373,11 +373,22 @@ static int palmas_set_voltage_smps_sel(struct regulator_dev *dev,static int palmas_map_voltage_smps (struct regulator_dev *rdev,int min_uV,int max_uV) { +struct palmas_pmic *pmic =rdev_get_drvdata (rdev); +int id =rdev_get_id (rdev);int ret, voltage; - ret = ((min_uV -500000 ) /10000 ) +1 ; -if (ret <0 ) -return ret; +if (min_uV ==0 ) +return 0 ; + +if (pmic->range[id]) {/* RANGE is x2 */ +if (min_uV <1000000 ) + min_uV =1000000 ; + ret =DIV_ROUND_UP (min_uV -1000000 ,20000 ) +1 ; + }else {/* RANGE is x1 */ +if (min_uV <500000 ) + min_uV =500000 ; + ret =DIV_ROUND_UP (min_uV -500000 ,10000 ) +1 ; + }/* Map back into a voltage to verify we're still in bounds */ voltage =palmas_list_voltage_smps (rdev, ret);
Signature · 1 line
1.7.9.5
Good catch, thanks I totally forgot about the range bit in that function.
Quoted 45 lines · Axel Lin
The logic of calculating selector in
palmas_map_voltage_smps()does not match the logic to list voltage inpalmas_list_voltage_smps().We use below equation to calculate voltage when selector > 0:
voltage = (0.49V + (selector * 0.01V)) * RANGERANGE is either x1 or x2
So we need to take into account with the multiplier set in VSEL register when calculating selector in
palmas_map_voltage_smps()Signed-off-by Axel Lin <[email protected]>--- drivers/regulator/palmas-regulator.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)drivers/regulator/palmas-regulator.c +14
-3@@ -373,11 +373,22 @@ static int palmas_set_voltage_smps_sel(struct regulator_dev *dev,static int palmas_map_voltage_smps (struct regulator_dev *rdev,int min_uV,int max_uV) { +struct palmas_pmic *pmic =rdev_get_drvdata (rdev); +int id =rdev_get_id (rdev);int ret, voltage; - ret = ((min_uV -500000 ) /10000 ) +1 ; -if (ret <0 ) -return ret; +if (min_uV ==0 ) +return 0 ; + +if (pmic->range[id]) {/* RANGE is x2 */ +if (min_uV <1000000 ) + min_uV =1000000 ; + ret =DIV_ROUND_UP (min_uV -1000000 ,20000 ) +1 ; + }else {/* RANGE is x1 */ +if (min_uV <500000 ) + min_uV =500000 ; + ret =DIV_ROUND_UP (min_uV -500000 ,10000 ) +1 ; + }/* Map back into a voltage to verify we're still in bounds */ voltage =palmas_list_voltage_smps (rdev, ret);
Mark Brown
AppliedQuoted 2 lines · Axel Lin
The logic of calculating selector in
palmas_map_voltage_smps()does not match the logic to list voltage inpalmas_list_voltage_smps().
Applied, thanks.