diff options
author | Axel Lin <axel.lin@gmail.com> | 2012-03-01 20:19:02 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-03-11 16:48:47 -0400 |
commit | 48ee1160a44b6f404f5553a6fce8447507982311 (patch) | |
tree | 43eba9f53da1041947b61ed963dd832e05278326 /drivers/regulator/isl6271a-regulator.c | |
parent | 7b94791be6fb1c52c5ccb2cfde793da6c6b541b0 (diff) |
regulator: Simplify the code to get selector in isl6271a_set_voltage
Signed-off-by: Axel Lin <axel.lin@gmail.com>
Acked-by: Marek Vasut <marek.vasut@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/isl6271a-regulator.c')
-rw-r--r-- | drivers/regulator/isl6271a-regulator.c | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/drivers/regulator/isl6271a-regulator.c b/drivers/regulator/isl6271a-regulator.c index c1a456c4257c..775f5fd208c3 100644 --- a/drivers/regulator/isl6271a-regulator.c +++ b/drivers/regulator/isl6271a-regulator.c | |||
@@ -63,23 +63,15 @@ static int isl6271a_set_voltage(struct regulator_dev *dev, | |||
63 | unsigned *selector) | 63 | unsigned *selector) |
64 | { | 64 | { |
65 | struct isl_pmic *pmic = rdev_get_drvdata(dev); | 65 | struct isl_pmic *pmic = rdev_get_drvdata(dev); |
66 | int vsel, err, data; | 66 | int err, data; |
67 | 67 | ||
68 | if (minuV < ISL6271A_VOLTAGE_MIN || minuV > ISL6271A_VOLTAGE_MAX) | 68 | if (minuV < ISL6271A_VOLTAGE_MIN || minuV > ISL6271A_VOLTAGE_MAX) |
69 | return -EINVAL; | 69 | return -EINVAL; |
70 | if (maxuV < ISL6271A_VOLTAGE_MIN || maxuV > ISL6271A_VOLTAGE_MAX) | 70 | if (maxuV < ISL6271A_VOLTAGE_MIN || maxuV > ISL6271A_VOLTAGE_MAX) |
71 | return -EINVAL; | 71 | return -EINVAL; |
72 | 72 | ||
73 | /* Align to 50000 mV */ | 73 | data = DIV_ROUND_UP(minuV - ISL6271A_VOLTAGE_MIN, |
74 | vsel = minuV - (minuV % ISL6271A_VOLTAGE_STEP); | 74 | ISL6271A_VOLTAGE_STEP); |
75 | |||
76 | /* If the result fell out of [minuV,maxuV] range, put it back */ | ||
77 | if (vsel < minuV) | ||
78 | vsel += ISL6271A_VOLTAGE_STEP; | ||
79 | |||
80 | /* Convert the microvolts to data for the chip */ | ||
81 | data = (vsel - ISL6271A_VOLTAGE_MIN) / ISL6271A_VOLTAGE_STEP; | ||
82 | |||
83 | *selector = data; | 75 | *selector = data; |
84 | 76 | ||
85 | mutex_lock(&pmic->mtx); | 77 | mutex_lock(&pmic->mtx); |