diff options
author | Axel Lin <axel.lin@gmail.com> | 2012-03-22 22:49:54 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-04-01 06:59:28 -0400 |
commit | dd8e2314b0e8955f7f97c10536799886ee3f4487 (patch) | |
tree | da5a5f22131cb3bbf9b91d22a92e945dba4016bd /drivers/regulator/lp3971.c | |
parent | 452534e50780697a7e1d3cf87cdfdd2b5a0d3c6b (diff) |
regulator: Convert lp3971 to set_voltage_sel
Signed-off-by: Axel Lin <axel.lin@gmail.com>
Acked-By: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/lp3971.c')
-rw-r--r-- | drivers/regulator/lp3971.c | 58 |
1 files changed, 15 insertions, 43 deletions
diff --git a/drivers/regulator/lp3971.c b/drivers/regulator/lp3971.c index 0cfabd318a59..49bcdb034895 100644 --- a/drivers/regulator/lp3971.c +++ b/drivers/regulator/lp3971.c | |||
@@ -124,6 +124,10 @@ static const int *ldo_voltage_map[] = { | |||
124 | static int lp3971_ldo_list_voltage(struct regulator_dev *dev, unsigned index) | 124 | static int lp3971_ldo_list_voltage(struct regulator_dev *dev, unsigned index) |
125 | { | 125 | { |
126 | int ldo = rdev_get_id(dev) - LP3971_LDO1; | 126 | int ldo = rdev_get_id(dev) - LP3971_LDO1; |
127 | |||
128 | if (index > LDO_VOL_MAX_IDX) | ||
129 | return -EINVAL; | ||
130 | |||
127 | return 1000 * LDO_VOL_VALUE_MAP(ldo)[index]; | 131 | return 1000 * LDO_VOL_VALUE_MAP(ldo)[index]; |
128 | } | 132 | } |
129 | 133 | ||
@@ -168,32 +172,15 @@ static int lp3971_ldo_get_voltage(struct regulator_dev *dev) | |||
168 | return 1000 * LDO_VOL_VALUE_MAP(ldo)[val]; | 172 | return 1000 * LDO_VOL_VALUE_MAP(ldo)[val]; |
169 | } | 173 | } |
170 | 174 | ||
171 | static int lp3971_ldo_set_voltage(struct regulator_dev *dev, | 175 | static int lp3971_ldo_set_voltage_sel(struct regulator_dev *dev, |
172 | int min_uV, int max_uV, | 176 | unsigned int selector) |
173 | unsigned int *selector) | ||
174 | { | 177 | { |
175 | struct lp3971 *lp3971 = rdev_get_drvdata(dev); | 178 | struct lp3971 *lp3971 = rdev_get_drvdata(dev); |
176 | int ldo = rdev_get_id(dev) - LP3971_LDO1; | 179 | int ldo = rdev_get_id(dev) - LP3971_LDO1; |
177 | int min_vol = min_uV / 1000, max_vol = max_uV / 1000; | ||
178 | const int *vol_map = LDO_VOL_VALUE_MAP(ldo); | ||
179 | u16 val; | ||
180 | |||
181 | if (min_vol < vol_map[LDO_VOL_MIN_IDX] || | ||
182 | min_vol > vol_map[LDO_VOL_MAX_IDX]) | ||
183 | return -EINVAL; | ||
184 | |||
185 | for (val = LDO_VOL_MIN_IDX; val <= LDO_VOL_MAX_IDX; val++) | ||
186 | if (vol_map[val] >= min_vol) | ||
187 | break; | ||
188 | |||
189 | if (val > LDO_VOL_MAX_IDX || vol_map[val] > max_vol) | ||
190 | return -EINVAL; | ||
191 | |||
192 | *selector = val; | ||
193 | 180 | ||
194 | return lp3971_set_bits(lp3971, LP3971_LDO_VOL_CONTR_REG(ldo), | 181 | return lp3971_set_bits(lp3971, LP3971_LDO_VOL_CONTR_REG(ldo), |
195 | LDO_VOL_CONTR_MASK << LDO_VOL_CONTR_SHIFT(ldo), | 182 | LDO_VOL_CONTR_MASK << LDO_VOL_CONTR_SHIFT(ldo), |
196 | val << LDO_VOL_CONTR_SHIFT(ldo)); | 183 | selector << LDO_VOL_CONTR_SHIFT(ldo)); |
197 | } | 184 | } |
198 | 185 | ||
199 | static struct regulator_ops lp3971_ldo_ops = { | 186 | static struct regulator_ops lp3971_ldo_ops = { |
@@ -202,11 +189,14 @@ static struct regulator_ops lp3971_ldo_ops = { | |||
202 | .enable = lp3971_ldo_enable, | 189 | .enable = lp3971_ldo_enable, |
203 | .disable = lp3971_ldo_disable, | 190 | .disable = lp3971_ldo_disable, |
204 | .get_voltage = lp3971_ldo_get_voltage, | 191 | .get_voltage = lp3971_ldo_get_voltage, |
205 | .set_voltage = lp3971_ldo_set_voltage, | 192 | .set_voltage_sel = lp3971_ldo_set_voltage_sel, |
206 | }; | 193 | }; |
207 | 194 | ||
208 | static int lp3971_dcdc_list_voltage(struct regulator_dev *dev, unsigned index) | 195 | static int lp3971_dcdc_list_voltage(struct regulator_dev *dev, unsigned index) |
209 | { | 196 | { |
197 | if (index < BUCK_TARGET_VOL_MIN_IDX || index > BUCK_TARGET_VOL_MAX_IDX) | ||
198 | return -EINVAL; | ||
199 | |||
210 | return 1000 * buck_voltage_map[index]; | 200 | return 1000 * buck_voltage_map[index]; |
211 | } | 201 | } |
212 | 202 | ||
@@ -259,33 +249,15 @@ static int lp3971_dcdc_get_voltage(struct regulator_dev *dev) | |||
259 | return val; | 249 | return val; |
260 | } | 250 | } |
261 | 251 | ||
262 | static int lp3971_dcdc_set_voltage(struct regulator_dev *dev, | 252 | static int lp3971_dcdc_set_voltage_sel(struct regulator_dev *dev, |
263 | int min_uV, int max_uV, | 253 | unsigned int selector) |
264 | unsigned int *selector) | ||
265 | { | 254 | { |
266 | struct lp3971 *lp3971 = rdev_get_drvdata(dev); | 255 | struct lp3971 *lp3971 = rdev_get_drvdata(dev); |
267 | int buck = rdev_get_id(dev) - LP3971_DCDC1; | 256 | int buck = rdev_get_id(dev) - LP3971_DCDC1; |
268 | int min_vol = min_uV / 1000, max_vol = max_uV / 1000; | ||
269 | const int *vol_map = buck_voltage_map; | ||
270 | u16 val; | ||
271 | int ret; | 257 | int ret; |
272 | 258 | ||
273 | if (min_vol < vol_map[BUCK_TARGET_VOL_MIN_IDX] || | ||
274 | min_vol > vol_map[BUCK_TARGET_VOL_MAX_IDX]) | ||
275 | return -EINVAL; | ||
276 | |||
277 | for (val = BUCK_TARGET_VOL_MIN_IDX; val <= BUCK_TARGET_VOL_MAX_IDX; | ||
278 | val++) | ||
279 | if (vol_map[val] >= min_vol) | ||
280 | break; | ||
281 | |||
282 | if (val > BUCK_TARGET_VOL_MAX_IDX || vol_map[val] > max_vol) | ||
283 | return -EINVAL; | ||
284 | |||
285 | *selector = val; | ||
286 | |||
287 | ret = lp3971_set_bits(lp3971, LP3971_BUCK_TARGET_VOL1_REG(buck), | 259 | ret = lp3971_set_bits(lp3971, LP3971_BUCK_TARGET_VOL1_REG(buck), |
288 | BUCK_TARGET_VOL_MASK, val); | 260 | BUCK_TARGET_VOL_MASK, selector); |
289 | if (ret) | 261 | if (ret) |
290 | return ret; | 262 | return ret; |
291 | 263 | ||
@@ -306,7 +278,7 @@ static struct regulator_ops lp3971_dcdc_ops = { | |||
306 | .enable = lp3971_dcdc_enable, | 278 | .enable = lp3971_dcdc_enable, |
307 | .disable = lp3971_dcdc_disable, | 279 | .disable = lp3971_dcdc_disable, |
308 | .get_voltage = lp3971_dcdc_get_voltage, | 280 | .get_voltage = lp3971_dcdc_get_voltage, |
309 | .set_voltage = lp3971_dcdc_set_voltage, | 281 | .set_voltage_sel = lp3971_dcdc_set_voltage_sel, |
310 | }; | 282 | }; |
311 | 283 | ||
312 | static struct regulator_desc regulators[] = { | 284 | static struct regulator_desc regulators[] = { |