diff options
author | Axel Lin <axel.lin@gmail.com> | 2012-03-22 22:51:14 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-04-01 06:59:28 -0400 |
commit | 24c896f5482d864f526ce3d085eb90298b82c49f (patch) | |
tree | 75c1883a6a87012e71b8986bcbbe80a4e62f3213 /drivers/regulator/lp3972.c | |
parent | dd8e2314b0e8955f7f97c10536799886ee3f4487 (diff) |
regulator: Convert lp3972 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/lp3972.c')
-rw-r--r-- | drivers/regulator/lp3972.c | 63 |
1 files changed, 18 insertions, 45 deletions
diff --git a/drivers/regulator/lp3972.c b/drivers/regulator/lp3972.c index 49a15eefe5fe..4f28d36600a5 100644 --- a/drivers/regulator/lp3972.c +++ b/drivers/regulator/lp3972.c | |||
@@ -245,6 +245,11 @@ static int lp3972_set_bits(struct lp3972 *lp3972, u8 reg, u16 mask, u16 val) | |||
245 | static int lp3972_ldo_list_voltage(struct regulator_dev *dev, unsigned index) | 245 | static int lp3972_ldo_list_voltage(struct regulator_dev *dev, unsigned index) |
246 | { | 246 | { |
247 | int ldo = rdev_get_id(dev) - LP3972_LDO1; | 247 | int ldo = rdev_get_id(dev) - LP3972_LDO1; |
248 | |||
249 | if (index < LP3972_LDO_VOL_MIN_IDX(ldo) || | ||
250 | index > LP3972_LDO_VOL_MAX_IDX(ldo)) | ||
251 | return -EINVAL; | ||
252 | |||
248 | return 1000 * LP3972_LDO_VOL_VALUE_MAP(ldo)[index]; | 253 | return 1000 * LP3972_LDO_VOL_VALUE_MAP(ldo)[index]; |
249 | } | 254 | } |
250 | 255 | ||
@@ -292,34 +297,16 @@ static int lp3972_ldo_get_voltage(struct regulator_dev *dev) | |||
292 | return 1000 * LP3972_LDO_VOL_VALUE_MAP(ldo)[val]; | 297 | return 1000 * LP3972_LDO_VOL_VALUE_MAP(ldo)[val]; |
293 | } | 298 | } |
294 | 299 | ||
295 | static int lp3972_ldo_set_voltage(struct regulator_dev *dev, | 300 | static int lp3972_ldo_set_voltage_sel(struct regulator_dev *dev, |
296 | int min_uV, int max_uV, | 301 | unsigned int selector) |
297 | unsigned int *selector) | ||
298 | { | 302 | { |
299 | struct lp3972 *lp3972 = rdev_get_drvdata(dev); | 303 | struct lp3972 *lp3972 = rdev_get_drvdata(dev); |
300 | int ldo = rdev_get_id(dev) - LP3972_LDO1; | 304 | int ldo = rdev_get_id(dev) - LP3972_LDO1; |
301 | int min_vol = min_uV / 1000, max_vol = max_uV / 1000; | ||
302 | const int *vol_map = LP3972_LDO_VOL_VALUE_MAP(ldo); | ||
303 | u16 val; | ||
304 | int shift, ret; | 305 | int shift, ret; |
305 | 306 | ||
306 | if (min_vol < vol_map[LP3972_LDO_VOL_MIN_IDX(ldo)] || | ||
307 | min_vol > vol_map[LP3972_LDO_VOL_MAX_IDX(ldo)]) | ||
308 | return -EINVAL; | ||
309 | |||
310 | for (val = LP3972_LDO_VOL_MIN_IDX(ldo); | ||
311 | val <= LP3972_LDO_VOL_MAX_IDX(ldo); val++) | ||
312 | if (vol_map[val] >= min_vol) | ||
313 | break; | ||
314 | |||
315 | if (val > LP3972_LDO_VOL_MAX_IDX(ldo) || vol_map[val] > max_vol) | ||
316 | return -EINVAL; | ||
317 | |||
318 | *selector = val; | ||
319 | |||
320 | shift = LP3972_LDO_VOL_CONTR_SHIFT(ldo); | 307 | shift = LP3972_LDO_VOL_CONTR_SHIFT(ldo); |
321 | ret = lp3972_set_bits(lp3972, LP3972_LDO_VOL_CONTR_REG(ldo), | 308 | ret = lp3972_set_bits(lp3972, LP3972_LDO_VOL_CONTR_REG(ldo), |
322 | LP3972_LDO_VOL_MASK(ldo) << shift, val << shift); | 309 | LP3972_LDO_VOL_MASK(ldo) << shift, selector << shift); |
323 | 310 | ||
324 | if (ret) | 311 | if (ret) |
325 | return ret; | 312 | return ret; |
@@ -355,12 +342,17 @@ static struct regulator_ops lp3972_ldo_ops = { | |||
355 | .enable = lp3972_ldo_enable, | 342 | .enable = lp3972_ldo_enable, |
356 | .disable = lp3972_ldo_disable, | 343 | .disable = lp3972_ldo_disable, |
357 | .get_voltage = lp3972_ldo_get_voltage, | 344 | .get_voltage = lp3972_ldo_get_voltage, |
358 | .set_voltage = lp3972_ldo_set_voltage, | 345 | .set_voltage_sel = lp3972_ldo_set_voltage_sel, |
359 | }; | 346 | }; |
360 | 347 | ||
361 | static int lp3972_dcdc_list_voltage(struct regulator_dev *dev, unsigned index) | 348 | static int lp3972_dcdc_list_voltage(struct regulator_dev *dev, unsigned index) |
362 | { | 349 | { |
363 | int buck = rdev_get_id(dev) - LP3972_DCDC1; | 350 | int buck = rdev_get_id(dev) - LP3972_DCDC1; |
351 | |||
352 | if (index < LP3972_BUCK_VOL_MIN_IDX(buck) || | ||
353 | index > LP3972_BUCK_VOL_MAX_IDX(buck)) | ||
354 | return -EINVAL; | ||
355 | |||
364 | return 1000 * buck_voltage_map[buck][index]; | 356 | return 1000 * buck_voltage_map[buck][index]; |
365 | } | 357 | } |
366 | 358 | ||
@@ -419,34 +411,15 @@ static int lp3972_dcdc_get_voltage(struct regulator_dev *dev) | |||
419 | return val; | 411 | return val; |
420 | } | 412 | } |
421 | 413 | ||
422 | static int lp3972_dcdc_set_voltage(struct regulator_dev *dev, | 414 | static int lp3972_dcdc_set_voltage_sel(struct regulator_dev *dev, |
423 | int min_uV, int max_uV, | 415 | unsigned int selector) |
424 | unsigned int *selector) | ||
425 | { | 416 | { |
426 | struct lp3972 *lp3972 = rdev_get_drvdata(dev); | 417 | struct lp3972 *lp3972 = rdev_get_drvdata(dev); |
427 | int buck = rdev_get_id(dev) - LP3972_DCDC1; | 418 | int buck = rdev_get_id(dev) - LP3972_DCDC1; |
428 | int min_vol = min_uV / 1000, max_vol = max_uV / 1000; | ||
429 | const int *vol_map = buck_voltage_map[buck]; | ||
430 | u16 val; | ||
431 | int ret; | 419 | int ret; |
432 | 420 | ||
433 | if (min_vol < vol_map[LP3972_BUCK_VOL_MIN_IDX(buck)] || | ||
434 | min_vol > vol_map[LP3972_BUCK_VOL_MAX_IDX(buck)]) | ||
435 | return -EINVAL; | ||
436 | |||
437 | for (val = LP3972_BUCK_VOL_MIN_IDX(buck); | ||
438 | val <= LP3972_BUCK_VOL_MAX_IDX(buck); val++) | ||
439 | if (vol_map[val] >= min_vol) | ||
440 | break; | ||
441 | |||
442 | if (val > LP3972_BUCK_VOL_MAX_IDX(buck) || | ||
443 | vol_map[val] > max_vol) | ||
444 | return -EINVAL; | ||
445 | |||
446 | *selector = val; | ||
447 | |||
448 | ret = lp3972_set_bits(lp3972, LP3972_BUCK_VOL1_REG(buck), | 421 | ret = lp3972_set_bits(lp3972, LP3972_BUCK_VOL1_REG(buck), |
449 | LP3972_BUCK_VOL_MASK, val); | 422 | LP3972_BUCK_VOL_MASK, selector); |
450 | if (ret) | 423 | if (ret) |
451 | return ret; | 424 | return ret; |
452 | 425 | ||
@@ -468,7 +441,7 @@ static struct regulator_ops lp3972_dcdc_ops = { | |||
468 | .enable = lp3972_dcdc_enable, | 441 | .enable = lp3972_dcdc_enable, |
469 | .disable = lp3972_dcdc_disable, | 442 | .disable = lp3972_dcdc_disable, |
470 | .get_voltage = lp3972_dcdc_get_voltage, | 443 | .get_voltage = lp3972_dcdc_get_voltage, |
471 | .set_voltage = lp3972_dcdc_set_voltage, | 444 | .set_voltage_sel = lp3972_dcdc_set_voltage_sel, |
472 | }; | 445 | }; |
473 | 446 | ||
474 | static struct regulator_desc regulators[] = { | 447 | static struct regulator_desc regulators[] = { |