diff options
author | Axel Lin <axel.lin@ingics.com> | 2012-11-26 21:26:14 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-11-27 15:11:19 -0500 |
commit | 6b1f8a45666877d4885c03d9472657fd73edfa8b (patch) | |
tree | 10706af5a7600cae428ba0cf4e18889a934bf60d /drivers/regulator | |
parent | 5979b2a35f0d67c09b385424674ece6ae9e3bda6 (diff) |
regulator: da9055: Use linear_min_sel and regulator_[map|list]_voltage_linear
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/da9055-regulator.c | 55 |
1 files changed, 8 insertions, 47 deletions
diff --git a/drivers/regulator/da9055-regulator.c b/drivers/regulator/da9055-regulator.c index 121564bb5415..2253559703ce 100644 --- a/drivers/regulator/da9055-regulator.c +++ b/drivers/regulator/da9055-regulator.c | |||
@@ -57,7 +57,6 @@ struct da9055_volt_reg { | |||
57 | int reg_a; | 57 | int reg_a; |
58 | int reg_b; | 58 | int reg_b; |
59 | int sl_shift; | 59 | int sl_shift; |
60 | int v_offset; | ||
61 | int v_mask; | 60 | int v_mask; |
62 | int v_shift; | 61 | int v_shift; |
63 | }; | 62 | }; |
@@ -204,41 +203,6 @@ static int da9055_buck_set_current_limit(struct regulator_dev *rdev, int min_uA, | |||
204 | info->mode.mask, val << info->mode.shift); | 203 | info->mode.mask, val << info->mode.shift); |
205 | } | 204 | } |
206 | 205 | ||
207 | static int da9055_list_voltage(struct regulator_dev *rdev, unsigned selector) | ||
208 | { | ||
209 | struct da9055_regulator *regulator = rdev_get_drvdata(rdev); | ||
210 | struct da9055_regulator_info *info = regulator->info; | ||
211 | |||
212 | if (selector >= rdev->desc->n_voltages) | ||
213 | return -EINVAL; | ||
214 | |||
215 | if (selector < info->volt.v_offset) | ||
216 | return 0; | ||
217 | |||
218 | selector -= info->volt.v_offset; | ||
219 | return rdev->desc->min_uV + (rdev->desc->uV_step * selector); | ||
220 | } | ||
221 | |||
222 | static int da9055_map_voltage(struct regulator_dev *rdev, int min_uV, | ||
223 | int max_uV) | ||
224 | { | ||
225 | struct da9055_regulator *regulator = rdev_get_drvdata(rdev); | ||
226 | struct da9055_regulator_info *info = regulator->info; | ||
227 | int sel, voltage; | ||
228 | |||
229 | if (min_uV < rdev->desc->min_uV) | ||
230 | min_uV = rdev->desc->min_uV; | ||
231 | |||
232 | sel = DIV_ROUND_UP(min_uV - rdev->desc->min_uV, rdev->desc->uV_step); | ||
233 | sel += info->volt.v_offset; | ||
234 | |||
235 | voltage = da9055_list_voltage(rdev, sel); | ||
236 | if (voltage < min_uV || voltage > max_uV) | ||
237 | return -EINVAL; | ||
238 | |||
239 | return sel; | ||
240 | } | ||
241 | |||
242 | static int da9055_regulator_get_voltage_sel(struct regulator_dev *rdev) | 206 | static int da9055_regulator_get_voltage_sel(struct regulator_dev *rdev) |
243 | { | 207 | { |
244 | struct da9055_regulator *regulator = rdev_get_drvdata(rdev); | 208 | struct da9055_regulator *regulator = rdev_get_drvdata(rdev); |
@@ -267,10 +231,7 @@ static int da9055_regulator_get_voltage_sel(struct regulator_dev *rdev) | |||
267 | return ret; | 231 | return ret; |
268 | 232 | ||
269 | sel = (ret & volt.v_mask); | 233 | sel = (ret & volt.v_mask); |
270 | if (sel <= volt.v_offset) | 234 | return sel; |
271 | return 0; | ||
272 | else | ||
273 | return sel; | ||
274 | } | 235 | } |
275 | 236 | ||
276 | static int da9055_regulator_set_voltage_sel(struct regulator_dev *rdev, | 237 | static int da9055_regulator_set_voltage_sel(struct regulator_dev *rdev, |
@@ -331,7 +292,7 @@ static int da9055_regulator_set_suspend_voltage(struct regulator_dev *rdev, | |||
331 | return ret; | 292 | return ret; |
332 | } | 293 | } |
333 | 294 | ||
334 | ret = da9055_map_voltage(rdev, uV, uV); | 295 | ret = regulator_map_voltage_linear(rdev, uV, uV); |
335 | if (ret < 0) | 296 | if (ret < 0) |
336 | return ret; | 297 | return ret; |
337 | 298 | ||
@@ -374,8 +335,8 @@ static struct regulator_ops da9055_buck_ops = { | |||
374 | 335 | ||
375 | .get_voltage_sel = da9055_regulator_get_voltage_sel, | 336 | .get_voltage_sel = da9055_regulator_get_voltage_sel, |
376 | .set_voltage_sel = da9055_regulator_set_voltage_sel, | 337 | .set_voltage_sel = da9055_regulator_set_voltage_sel, |
377 | .list_voltage = da9055_list_voltage, | 338 | .list_voltage = regulator_list_voltage_linear, |
378 | .map_voltage = da9055_map_voltage, | 339 | .map_voltage = regulator_map_voltage_linear, |
379 | .is_enabled = regulator_is_enabled_regmap, | 340 | .is_enabled = regulator_is_enabled_regmap, |
380 | .enable = regulator_enable_regmap, | 341 | .enable = regulator_enable_regmap, |
381 | .disable = regulator_disable_regmap, | 342 | .disable = regulator_disable_regmap, |
@@ -392,8 +353,8 @@ static struct regulator_ops da9055_ldo_ops = { | |||
392 | 353 | ||
393 | .get_voltage_sel = da9055_regulator_get_voltage_sel, | 354 | .get_voltage_sel = da9055_regulator_get_voltage_sel, |
394 | .set_voltage_sel = da9055_regulator_set_voltage_sel, | 355 | .set_voltage_sel = da9055_regulator_set_voltage_sel, |
395 | .list_voltage = da9055_list_voltage, | 356 | .list_voltage = regulator_list_voltage_linear, |
396 | .map_voltage = da9055_map_voltage, | 357 | .map_voltage = regulator_map_voltage_linear, |
397 | .is_enabled = regulator_is_enabled_regmap, | 358 | .is_enabled = regulator_is_enabled_regmap, |
398 | .enable = regulator_enable_regmap, | 359 | .enable = regulator_enable_regmap, |
399 | .disable = regulator_disable_regmap, | 360 | .disable = regulator_disable_regmap, |
@@ -417,6 +378,7 @@ static struct regulator_ops da9055_ldo_ops = { | |||
417 | .enable_mask = 1, \ | 378 | .enable_mask = 1, \ |
418 | .min_uV = (min) * 1000,\ | 379 | .min_uV = (min) * 1000,\ |
419 | .uV_step = (step) * 1000,\ | 380 | .uV_step = (step) * 1000,\ |
381 | .linear_min_sel = (voffset),\ | ||
420 | .owner = THIS_MODULE,\ | 382 | .owner = THIS_MODULE,\ |
421 | },\ | 383 | },\ |
422 | .conf = {\ | 384 | .conf = {\ |
@@ -428,7 +390,6 @@ static struct regulator_ops da9055_ldo_ops = { | |||
428 | .reg_a = DA9055_REG_VBCORE_A + DA9055_ID_##_id, \ | 390 | .reg_a = DA9055_REG_VBCORE_A + DA9055_ID_##_id, \ |
429 | .reg_b = DA9055_REG_VBCORE_B + DA9055_ID_##_id, \ | 391 | .reg_b = DA9055_REG_VBCORE_B + DA9055_ID_##_id, \ |
430 | .sl_shift = 7,\ | 392 | .sl_shift = 7,\ |
431 | .v_offset = (voffset),\ | ||
432 | .v_mask = (1 << (vbits)) - 1,\ | 393 | .v_mask = (1 << (vbits)) - 1,\ |
433 | .v_shift = (vbits),\ | 394 | .v_shift = (vbits),\ |
434 | },\ | 395 | },\ |
@@ -446,6 +407,7 @@ static struct regulator_ops da9055_ldo_ops = { | |||
446 | .enable_mask = 1,\ | 407 | .enable_mask = 1,\ |
447 | .min_uV = (min) * 1000,\ | 408 | .min_uV = (min) * 1000,\ |
448 | .uV_step = (step) * 1000,\ | 409 | .uV_step = (step) * 1000,\ |
410 | .linear_min_sel = (voffset),\ | ||
449 | .owner = THIS_MODULE,\ | 411 | .owner = THIS_MODULE,\ |
450 | },\ | 412 | },\ |
451 | .conf = {\ | 413 | .conf = {\ |
@@ -457,7 +419,6 @@ static struct regulator_ops da9055_ldo_ops = { | |||
457 | .reg_a = DA9055_REG_VBCORE_A + DA9055_ID_##_id, \ | 419 | .reg_a = DA9055_REG_VBCORE_A + DA9055_ID_##_id, \ |
458 | .reg_b = DA9055_REG_VBCORE_B + DA9055_ID_##_id, \ | 420 | .reg_b = DA9055_REG_VBCORE_B + DA9055_ID_##_id, \ |
459 | .sl_shift = 7,\ | 421 | .sl_shift = 7,\ |
460 | .v_offset = (voffset),\ | ||
461 | .v_mask = (1 << (vbits)) - 1,\ | 422 | .v_mask = (1 << (vbits)) - 1,\ |
462 | .v_shift = (vbits),\ | 423 | .v_shift = (vbits),\ |
463 | },\ | 424 | },\ |