diff options
author | Axel Lin <axel.lin@ingics.com> | 2013-07-28 04:37:23 -0400 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2013-07-28 08:41:52 -0400 |
commit | 550bf89366e068cd6e29c36156f700a02dbb6388 (patch) | |
tree | 97e02e8e3760b5cd8487bc91db0512f8ab2cdc76 /drivers/regulator/da903x.c | |
parent | 6c918d220925eeeca75b67e896eabffd061cd128 (diff) |
regulator: da903x: Convert da9034 ldo12 to use linear ranges
The voltage table of da9034 LDO12 is:
1700000, 1750000, 1800000, 1850000, 1900000, 1950000, 2000000, 2050000
2700000, 2750000, 2800000, 2850000, 2900000, 2950000, 3000000, 3050000
The voltage table is composed of two linear ranges:
for selector 0 ... 7:
volt = 1700000 + 50000 * selector
for selector: 8 ... 15:
volt = 2700000 + 50000 * (selector - 8)
This patch converts da9034 LDO12 to use newly introduced helpers for multiple
linear ranges.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'drivers/regulator/da903x.c')
-rw-r--r-- | drivers/regulator/da903x.c | 45 |
1 files changed, 10 insertions, 35 deletions
diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c index 2afa5730f324..1378a242a3af 100644 --- a/drivers/regulator/da903x.c +++ b/drivers/regulator/da903x.c | |||
@@ -252,39 +252,12 @@ static int da9034_set_dvc_voltage_sel(struct regulator_dev *rdev, | |||
252 | return ret; | 252 | return ret; |
253 | } | 253 | } |
254 | 254 | ||
255 | static int da9034_map_ldo12_voltage(struct regulator_dev *rdev, | 255 | static const struct regulator_linear_range da9034_ldo12_ranges[] = { |
256 | int min_uV, int max_uV) | 256 | { .min_uV = 1700000, .max_uV = 2050000, .min_sel = 0, .max_sel = 7, |
257 | { | 257 | .uV_step = 50000 }, |
258 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | 258 | { .min_uV = 2700000, .max_uV = 3050000, .min_sel = 8, .max_sel = 15, |
259 | int sel; | 259 | .uV_step = 50000 }, |
260 | 260 | }; | |
261 | if (check_range(info, min_uV, max_uV)) { | ||
262 | pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV); | ||
263 | return -EINVAL; | ||
264 | } | ||
265 | |||
266 | sel = DIV_ROUND_UP(min_uV - info->desc.min_uV, info->desc.uV_step); | ||
267 | sel = (sel >= 20) ? sel - 12 : ((sel > 7) ? 8 : sel); | ||
268 | |||
269 | return sel; | ||
270 | } | ||
271 | |||
272 | static int da9034_list_ldo12_voltage(struct regulator_dev *rdev, | ||
273 | unsigned selector) | ||
274 | { | ||
275 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | ||
276 | int volt; | ||
277 | |||
278 | if (selector >= 8) | ||
279 | volt = 2700000 + rdev->desc->uV_step * (selector - 8); | ||
280 | else | ||
281 | volt = rdev->desc->min_uV + rdev->desc->uV_step * selector; | ||
282 | |||
283 | if (volt > info->max_uV) | ||
284 | return -EINVAL; | ||
285 | |||
286 | return volt; | ||
287 | } | ||
288 | 261 | ||
289 | static struct regulator_ops da903x_regulator_ldo_ops = { | 262 | static struct regulator_ops da903x_regulator_ldo_ops = { |
290 | .set_voltage_sel = da903x_set_voltage_sel, | 263 | .set_voltage_sel = da903x_set_voltage_sel, |
@@ -332,8 +305,8 @@ static struct regulator_ops da9034_regulator_dvc_ops = { | |||
332 | static struct regulator_ops da9034_regulator_ldo12_ops = { | 305 | static struct regulator_ops da9034_regulator_ldo12_ops = { |
333 | .set_voltage_sel = da903x_set_voltage_sel, | 306 | .set_voltage_sel = da903x_set_voltage_sel, |
334 | .get_voltage_sel = da903x_get_voltage_sel, | 307 | .get_voltage_sel = da903x_get_voltage_sel, |
335 | .list_voltage = da9034_list_ldo12_voltage, | 308 | .list_voltage = regulator_list_voltage_linear_range, |
336 | .map_voltage = da9034_map_ldo12_voltage, | 309 | .map_voltage = regulator_map_voltage_linear_range, |
337 | .enable = da903x_enable, | 310 | .enable = da903x_enable, |
338 | .disable = da903x_disable, | 311 | .disable = da903x_disable, |
339 | .is_enabled = da903x_is_enabled, | 312 | .is_enabled = da903x_is_enabled, |
@@ -476,6 +449,8 @@ static int da903x_regulator_probe(struct platform_device *pdev) | |||
476 | if (ri->desc.id == DA9034_ID_LDO12) { | 449 | if (ri->desc.id == DA9034_ID_LDO12) { |
477 | ri->desc.ops = &da9034_regulator_ldo12_ops; | 450 | ri->desc.ops = &da9034_regulator_ldo12_ops; |
478 | ri->desc.n_voltages = 16; | 451 | ri->desc.n_voltages = 16; |
452 | ri->desc.linear_ranges = da9034_ldo12_ranges; | ||
453 | ri->desc.n_linear_ranges = ARRAY_SIZE(da9034_ldo12_ranges); | ||
479 | } | 454 | } |
480 | 455 | ||
481 | if (ri->desc.id == DA9030_ID_LDO14) | 456 | if (ri->desc.id == DA9030_ID_LDO14) |