diff options
author | Mark Brown <broonie@linaro.org> | 2013-07-02 18:35:22 -0400 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2013-07-15 06:20:32 -0400 |
commit | 5ff26a14c333113967f3abe5fcb81c8e49d282c0 (patch) | |
tree | 56bbd485c1eff2e4f75f9c8b22d7d117f6c3ed4d | |
parent | 6692e432a9d59b55edbfdb4ed388e03c7f17e43c (diff) |
regulator: wm831x-ldo: Convert to use linear ranges
Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r-- | drivers/regulator/wm831x-ldo.c | 104 |
1 files changed, 24 insertions, 80 deletions
diff --git a/drivers/regulator/wm831x-ldo.c b/drivers/regulator/wm831x-ldo.c index 9ff883f80878..76792c7d86f3 100644 --- a/drivers/regulator/wm831x-ldo.c +++ b/drivers/regulator/wm831x-ldo.c | |||
@@ -62,41 +62,12 @@ static irqreturn_t wm831x_ldo_uv_irq(int irq, void *data) | |||
62 | * General purpose LDOs | 62 | * General purpose LDOs |
63 | */ | 63 | */ |
64 | 64 | ||
65 | #define WM831X_GP_LDO_SELECTOR_LOW 0xe | 65 | static const struct regulator_linear_range wm831x_gp_ldo_ranges[] = { |
66 | #define WM831X_GP_LDO_MAX_SELECTOR 0x1f | 66 | { .min_uV = 900000, .max_uV = 1650000, .min_sel = 0, .max_sel = 14, |
67 | 67 | .uV_step = 50000 }, | |
68 | static int wm831x_gp_ldo_list_voltage(struct regulator_dev *rdev, | 68 | { .min_uV = 1700000, .max_uV = 3300000, .min_sel = 15, .max_sel = 31, |
69 | unsigned int selector) | 69 | .uV_step = 100000 }, |
70 | { | 70 | }; |
71 | /* 0.9-1.6V in 50mV steps */ | ||
72 | if (selector <= WM831X_GP_LDO_SELECTOR_LOW) | ||
73 | return 900000 + (selector * 50000); | ||
74 | /* 1.7-3.3V in 100mV steps */ | ||
75 | if (selector <= WM831X_GP_LDO_MAX_SELECTOR) | ||
76 | return 1600000 + ((selector - WM831X_GP_LDO_SELECTOR_LOW) | ||
77 | * 100000); | ||
78 | return -EINVAL; | ||
79 | } | ||
80 | |||
81 | static int wm831x_gp_ldo_map_voltage(struct regulator_dev *rdev, | ||
82 | int min_uV, int max_uV) | ||
83 | { | ||
84 | int volt, vsel; | ||
85 | |||
86 | if (min_uV < 900000) | ||
87 | vsel = 0; | ||
88 | else if (min_uV < 1700000) | ||
89 | vsel = ((min_uV - 900000) / 50000); | ||
90 | else | ||
91 | vsel = ((min_uV - 1700000) / 100000) | ||
92 | + WM831X_GP_LDO_SELECTOR_LOW + 1; | ||
93 | |||
94 | volt = wm831x_gp_ldo_list_voltage(rdev, vsel); | ||
95 | if (volt < min_uV || volt > max_uV) | ||
96 | return -EINVAL; | ||
97 | |||
98 | return vsel; | ||
99 | } | ||
100 | 71 | ||
101 | static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev, | 72 | static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev, |
102 | int uV) | 73 | int uV) |
@@ -105,7 +76,7 @@ static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev, | |||
105 | struct wm831x *wm831x = ldo->wm831x; | 76 | struct wm831x *wm831x = ldo->wm831x; |
106 | int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; | 77 | int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; |
107 | 78 | ||
108 | sel = wm831x_gp_ldo_map_voltage(rdev, uV, uV); | 79 | sel = regulator_map_voltage_linear_range(rdev, uV, uV); |
109 | if (sel < 0) | 80 | if (sel < 0) |
110 | return sel; | 81 | return sel; |
111 | 82 | ||
@@ -230,8 +201,8 @@ static unsigned int wm831x_gp_ldo_get_optimum_mode(struct regulator_dev *rdev, | |||
230 | 201 | ||
231 | 202 | ||
232 | static struct regulator_ops wm831x_gp_ldo_ops = { | 203 | static struct regulator_ops wm831x_gp_ldo_ops = { |
233 | .list_voltage = wm831x_gp_ldo_list_voltage, | 204 | .list_voltage = regulator_list_voltage_linear_range, |
234 | .map_voltage = wm831x_gp_ldo_map_voltage, | 205 | .map_voltage = regulator_map_voltage_linear_range, |
235 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | 206 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
236 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | 207 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
237 | .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage, | 208 | .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage, |
@@ -290,7 +261,7 @@ static int wm831x_gp_ldo_probe(struct platform_device *pdev) | |||
290 | 261 | ||
291 | ldo->desc.id = id; | 262 | ldo->desc.id = id; |
292 | ldo->desc.type = REGULATOR_VOLTAGE; | 263 | ldo->desc.type = REGULATOR_VOLTAGE; |
293 | ldo->desc.n_voltages = WM831X_GP_LDO_MAX_SELECTOR + 1; | 264 | ldo->desc.n_voltages = 32; |
294 | ldo->desc.ops = &wm831x_gp_ldo_ops; | 265 | ldo->desc.ops = &wm831x_gp_ldo_ops; |
295 | ldo->desc.owner = THIS_MODULE; | 266 | ldo->desc.owner = THIS_MODULE; |
296 | ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL; | 267 | ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL; |
@@ -299,6 +270,8 @@ static int wm831x_gp_ldo_probe(struct platform_device *pdev) | |||
299 | ldo->desc.enable_mask = 1 << id; | 270 | ldo->desc.enable_mask = 1 << id; |
300 | ldo->desc.bypass_reg = ldo->base; | 271 | ldo->desc.bypass_reg = ldo->base; |
301 | ldo->desc.bypass_mask = WM831X_LDO1_SWI; | 272 | ldo->desc.bypass_mask = WM831X_LDO1_SWI; |
273 | ldo->desc.linear_ranges = wm831x_gp_ldo_ranges; | ||
274 | ldo->desc.n_linear_ranges = ARRAY_SIZE(wm831x_gp_ldo_ranges); | ||
302 | 275 | ||
303 | config.dev = pdev->dev.parent; | 276 | config.dev = pdev->dev.parent; |
304 | if (pdata) | 277 | if (pdata) |
@@ -358,43 +331,12 @@ static struct platform_driver wm831x_gp_ldo_driver = { | |||
358 | * Analogue LDOs | 331 | * Analogue LDOs |
359 | */ | 332 | */ |
360 | 333 | ||
361 | 334 | static const struct regulator_linear_range wm831x_aldo_ranges[] = { | |
362 | #define WM831X_ALDO_SELECTOR_LOW 0xc | 335 | { .min_uV = 1000000, .max_uV = 1650000, .min_sel = 0, .max_sel = 12, |
363 | #define WM831X_ALDO_MAX_SELECTOR 0x1f | 336 | .uV_step = 50000 }, |
364 | 337 | { .min_uV = 1700000, .max_uV = 3500000, .min_sel = 13, .max_sel = 31, | |
365 | static int wm831x_aldo_list_voltage(struct regulator_dev *rdev, | 338 | .uV_step = 100000 }, |
366 | unsigned int selector) | 339 | }; |
367 | { | ||
368 | /* 1-1.6V in 50mV steps */ | ||
369 | if (selector <= WM831X_ALDO_SELECTOR_LOW) | ||
370 | return 1000000 + (selector * 50000); | ||
371 | /* 1.7-3.5V in 100mV steps */ | ||
372 | if (selector <= WM831X_ALDO_MAX_SELECTOR) | ||
373 | return 1600000 + ((selector - WM831X_ALDO_SELECTOR_LOW) | ||
374 | * 100000); | ||
375 | return -EINVAL; | ||
376 | } | ||
377 | |||
378 | static int wm831x_aldo_map_voltage(struct regulator_dev *rdev, | ||
379 | int min_uV, int max_uV) | ||
380 | { | ||
381 | int volt, vsel; | ||
382 | |||
383 | if (min_uV < 1000000) | ||
384 | vsel = 0; | ||
385 | else if (min_uV < 1700000) | ||
386 | vsel = ((min_uV - 1000000) / 50000); | ||
387 | else | ||
388 | vsel = ((min_uV - 1700000) / 100000) | ||
389 | + WM831X_ALDO_SELECTOR_LOW + 1; | ||
390 | |||
391 | volt = wm831x_aldo_list_voltage(rdev, vsel); | ||
392 | if (volt < min_uV || volt > max_uV) | ||
393 | return -EINVAL; | ||
394 | |||
395 | return vsel; | ||
396 | |||
397 | } | ||
398 | 340 | ||
399 | static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev, | 341 | static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev, |
400 | int uV) | 342 | int uV) |
@@ -403,7 +345,7 @@ static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev, | |||
403 | struct wm831x *wm831x = ldo->wm831x; | 345 | struct wm831x *wm831x = ldo->wm831x; |
404 | int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; | 346 | int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; |
405 | 347 | ||
406 | sel = wm831x_aldo_map_voltage(rdev, uV, uV); | 348 | sel = regulator_map_voltage_linear_range(rdev, uV, uV); |
407 | if (sel < 0) | 349 | if (sel < 0) |
408 | return sel; | 350 | return sel; |
409 | 351 | ||
@@ -486,8 +428,8 @@ static int wm831x_aldo_get_status(struct regulator_dev *rdev) | |||
486 | } | 428 | } |
487 | 429 | ||
488 | static struct regulator_ops wm831x_aldo_ops = { | 430 | static struct regulator_ops wm831x_aldo_ops = { |
489 | .list_voltage = wm831x_aldo_list_voltage, | 431 | .list_voltage = regulator_list_voltage_linear_range, |
490 | .map_voltage = wm831x_aldo_map_voltage, | 432 | .map_voltage = regulator_map_voltage_linear_range, |
491 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | 433 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
492 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | 434 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
493 | .set_suspend_voltage = wm831x_aldo_set_suspend_voltage, | 435 | .set_suspend_voltage = wm831x_aldo_set_suspend_voltage, |
@@ -545,7 +487,9 @@ static int wm831x_aldo_probe(struct platform_device *pdev) | |||
545 | 487 | ||
546 | ldo->desc.id = id; | 488 | ldo->desc.id = id; |
547 | ldo->desc.type = REGULATOR_VOLTAGE; | 489 | ldo->desc.type = REGULATOR_VOLTAGE; |
548 | ldo->desc.n_voltages = WM831X_ALDO_MAX_SELECTOR + 1; | 490 | ldo->desc.n_voltages = 32; |
491 | ldo->desc.linear_ranges = wm831x_aldo_ranges; | ||
492 | ldo->desc.n_linear_ranges = ARRAY_SIZE(wm831x_aldo_ranges); | ||
549 | ldo->desc.ops = &wm831x_aldo_ops; | 493 | ldo->desc.ops = &wm831x_aldo_ops; |
550 | ldo->desc.owner = THIS_MODULE; | 494 | ldo->desc.owner = THIS_MODULE; |
551 | ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL; | 495 | ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL; |