aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/da9055-regulator.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/regulator/da9055-regulator.c')
-rw-r--r--drivers/regulator/da9055-regulator.c55
1 files changed, 8 insertions, 47 deletions
diff --git a/drivers/regulator/da9055-regulator.c b/drivers/regulator/da9055-regulator.c
index db59ce7534cd..a4b9cb8c4317 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};
@@ -201,41 +200,6 @@ static int da9055_buck_set_current_limit(struct regulator_dev *rdev, int min_uA,
201 return -EINVAL; 200 return -EINVAL;
202} 201}
203 202
204static int da9055_list_voltage(struct regulator_dev *rdev, unsigned selector)
205{
206 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
207 struct da9055_regulator_info *info = regulator->info;
208
209 if (selector >= rdev->desc->n_voltages)
210 return -EINVAL;
211
212 if (selector < info->volt.v_offset)
213 return 0;
214
215 selector -= info->volt.v_offset;
216 return rdev->desc->min_uV + (rdev->desc->uV_step * selector);
217}
218
219static int da9055_map_voltage(struct regulator_dev *rdev, int min_uV,
220 int max_uV)
221{
222 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
223 struct da9055_regulator_info *info = regulator->info;
224 int sel, voltage;
225
226 if (min_uV < rdev->desc->min_uV)
227 min_uV = rdev->desc->min_uV;
228
229 sel = DIV_ROUND_UP(min_uV - rdev->desc->min_uV, rdev->desc->uV_step);
230 sel += info->volt.v_offset;
231
232 voltage = da9055_list_voltage(rdev, sel);
233 if (voltage < min_uV || voltage > max_uV)
234 return -EINVAL;
235
236 return sel;
237}
238
239static int da9055_regulator_get_voltage_sel(struct regulator_dev *rdev) 203static int da9055_regulator_get_voltage_sel(struct regulator_dev *rdev)
240{ 204{
241 struct da9055_regulator *regulator = rdev_get_drvdata(rdev); 205 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
@@ -264,10 +228,7 @@ static int da9055_regulator_get_voltage_sel(struct regulator_dev *rdev)
264 return ret; 228 return ret;
265 229
266 sel = (ret & volt.v_mask); 230 sel = (ret & volt.v_mask);
267 if (sel <= volt.v_offset) 231 return sel;
268 return 0;
269 else
270 return sel;
271} 232}
272 233
273static int da9055_regulator_set_voltage_sel(struct regulator_dev *rdev, 234static int da9055_regulator_set_voltage_sel(struct regulator_dev *rdev,
@@ -328,7 +289,7 @@ static int da9055_regulator_set_suspend_voltage(struct regulator_dev *rdev,
328 return ret; 289 return ret;
329 } 290 }
330 291
331 ret = da9055_map_voltage(rdev, uV, uV); 292 ret = regulator_map_voltage_linear(rdev, uV, uV);
332 if (ret < 0) 293 if (ret < 0)
333 return ret; 294 return ret;
334 295
@@ -371,8 +332,8 @@ static struct regulator_ops da9055_buck_ops = {
371 332
372 .get_voltage_sel = da9055_regulator_get_voltage_sel, 333 .get_voltage_sel = da9055_regulator_get_voltage_sel,
373 .set_voltage_sel = da9055_regulator_set_voltage_sel, 334 .set_voltage_sel = da9055_regulator_set_voltage_sel,
374 .list_voltage = da9055_list_voltage, 335 .list_voltage = regulator_list_voltage_linear,
375 .map_voltage = da9055_map_voltage, 336 .map_voltage = regulator_map_voltage_linear,
376 .is_enabled = regulator_is_enabled_regmap, 337 .is_enabled = regulator_is_enabled_regmap,
377 .enable = regulator_enable_regmap, 338 .enable = regulator_enable_regmap,
378 .disable = regulator_disable_regmap, 339 .disable = regulator_disable_regmap,
@@ -389,8 +350,8 @@ static struct regulator_ops da9055_ldo_ops = {
389 350
390 .get_voltage_sel = da9055_regulator_get_voltage_sel, 351 .get_voltage_sel = da9055_regulator_get_voltage_sel,
391 .set_voltage_sel = da9055_regulator_set_voltage_sel, 352 .set_voltage_sel = da9055_regulator_set_voltage_sel,
392 .list_voltage = da9055_list_voltage, 353 .list_voltage = regulator_list_voltage_linear,
393 .map_voltage = da9055_map_voltage, 354 .map_voltage = regulator_map_voltage_linear,
394 .is_enabled = regulator_is_enabled_regmap, 355 .is_enabled = regulator_is_enabled_regmap,
395 .enable = regulator_enable_regmap, 356 .enable = regulator_enable_regmap,
396 .disable = regulator_disable_regmap, 357 .disable = regulator_disable_regmap,
@@ -414,6 +375,7 @@ static struct regulator_ops da9055_ldo_ops = {
414 .enable_mask = 1, \ 375 .enable_mask = 1, \
415 .min_uV = (min) * 1000,\ 376 .min_uV = (min) * 1000,\
416 .uV_step = (step) * 1000,\ 377 .uV_step = (step) * 1000,\
378 .linear_min_sel = (voffset),\
417 .owner = THIS_MODULE,\ 379 .owner = THIS_MODULE,\
418 },\ 380 },\
419 .conf = {\ 381 .conf = {\
@@ -425,7 +387,6 @@ static struct regulator_ops da9055_ldo_ops = {
425 .reg_a = DA9055_REG_VBCORE_A + DA9055_ID_##_id, \ 387 .reg_a = DA9055_REG_VBCORE_A + DA9055_ID_##_id, \
426 .reg_b = DA9055_REG_VBCORE_B + DA9055_ID_##_id, \ 388 .reg_b = DA9055_REG_VBCORE_B + DA9055_ID_##_id, \
427 .sl_shift = 7,\ 389 .sl_shift = 7,\
428 .v_offset = (voffset),\
429 .v_mask = (1 << (vbits)) - 1,\ 390 .v_mask = (1 << (vbits)) - 1,\
430 .v_shift = (vbits),\ 391 .v_shift = (vbits),\
431 },\ 392 },\
@@ -443,6 +404,7 @@ static struct regulator_ops da9055_ldo_ops = {
443 .enable_mask = 1,\ 404 .enable_mask = 1,\
444 .min_uV = (min) * 1000,\ 405 .min_uV = (min) * 1000,\
445 .uV_step = (step) * 1000,\ 406 .uV_step = (step) * 1000,\
407 .linear_min_sel = (voffset),\
446 .owner = THIS_MODULE,\ 408 .owner = THIS_MODULE,\
447 },\ 409 },\
448 .conf = {\ 410 .conf = {\
@@ -454,7 +416,6 @@ static struct regulator_ops da9055_ldo_ops = {
454 .reg_a = DA9055_REG_VBCORE_A + DA9055_ID_##_id, \ 416 .reg_a = DA9055_REG_VBCORE_A + DA9055_ID_##_id, \
455 .reg_b = DA9055_REG_VBCORE_B + DA9055_ID_##_id, \ 417 .reg_b = DA9055_REG_VBCORE_B + DA9055_ID_##_id, \
456 .sl_shift = 7,\ 418 .sl_shift = 7,\
457 .v_offset = (voffset),\
458 .v_mask = (1 << (vbits)) - 1,\ 419 .v_mask = (1 << (vbits)) - 1,\
459 .v_shift = (vbits),\ 420 .v_shift = (vbits),\
460 },\ 421 },\