Commit 8a165df7a915cb212f41c1dec9abc5ac8f8ee6b6
Committed by
Mark Brown
1 parent
5bae062830
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
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() Signed-off-by: Axel Lin <axel.lin@gmail.com> Acked-by: Graeme Gregory <gg@slimlogic.co.uk> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Showing 1 changed file with 14 additions and 3 deletions Side-by-side Diff
drivers/regulator/palmas-regulator.c
... | ... | @@ -373,11 +373,22 @@ |
373 | 373 | static int palmas_map_voltage_smps(struct regulator_dev *rdev, |
374 | 374 | int min_uV, int max_uV) |
375 | 375 | { |
376 | + struct palmas_pmic *pmic = rdev_get_drvdata(rdev); | |
377 | + int id = rdev_get_id(rdev); | |
376 | 378 | int ret, voltage; |
377 | 379 | |
378 | - ret = ((min_uV - 500000) / 10000) + 1; | |
379 | - if (ret < 0) | |
380 | - return ret; | |
380 | + if (min_uV == 0) | |
381 | + return 0; | |
382 | + | |
383 | + if (pmic->range[id]) { /* RANGE is x2 */ | |
384 | + if (min_uV < 1000000) | |
385 | + min_uV = 1000000; | |
386 | + ret = DIV_ROUND_UP(min_uV - 1000000, 20000) + 1; | |
387 | + } else { /* RANGE is x1 */ | |
388 | + if (min_uV < 500000) | |
389 | + min_uV = 500000; | |
390 | + ret = DIV_ROUND_UP(min_uV - 500000, 10000) + 1; | |
391 | + } | |
381 | 392 | |
382 | 393 | /* Map back into a voltage to verify we're still in bounds */ |
383 | 394 | voltage = palmas_list_voltage_smps(rdev, ret); |