aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@ingics.com>2019-01-20 02:33:56 -0500
committerMark Brown <broonie@kernel.org>2019-01-22 12:26:24 -0500
commitccffcb8e9a11fe91f3577cefeed00b1f58d51671 (patch)
tree3c176fea9c292b22d6241ab1e05ee6a4a0cb6c4b
parent93997a05e6bd7347eb8d103c96af7df4625933f1 (diff)
regulator: wm831x-dcdc: Convert to use regulator_linear_range for wm831x_buckv
Signed-off-by: Axel Lin <axel.lin@ingics.com> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--drivers/regulator/wm831x-dcdc.c39
1 files changed, 9 insertions, 30 deletions
diff --git a/drivers/regulator/wm831x-dcdc.c b/drivers/regulator/wm831x-dcdc.c
index 5a5bc4bb08d2..4a573eea284a 100644
--- a/drivers/regulator/wm831x-dcdc.c
+++ b/drivers/regulator/wm831x-dcdc.c
@@ -205,33 +205,10 @@ static irqreturn_t wm831x_dcdc_oc_irq(int irq, void *data)
205 * BUCKV specifics 205 * BUCKV specifics
206 */ 206 */
207 207
208static int wm831x_buckv_list_voltage(struct regulator_dev *rdev, 208static const struct regulator_linear_range wm831x_buckv_ranges[] = {
209 unsigned selector) 209 REGULATOR_LINEAR_RANGE(600000, 0, 0x7, 0),
210{ 210 REGULATOR_LINEAR_RANGE(600000, 0x8, 0x68, 12500),
211 if (selector <= 0x8) 211};
212 return 600000;
213 if (selector <= WM831X_BUCKV_MAX_SELECTOR)
214 return 600000 + ((selector - 0x8) * 12500);
215 return -EINVAL;
216}
217
218static int wm831x_buckv_map_voltage(struct regulator_dev *rdev,
219 int min_uV, int max_uV)
220{
221 u16 vsel;
222
223 if (min_uV < 600000)
224 vsel = 0;
225 else if (min_uV <= 1800000)
226 vsel = DIV_ROUND_UP(min_uV - 600000, 12500) + 8;
227 else
228 return -EINVAL;
229
230 if (wm831x_buckv_list_voltage(rdev, vsel) > max_uV)
231 return -EINVAL;
232
233 return vsel;
234}
235 212
236static int wm831x_buckv_set_dvs(struct regulator_dev *rdev, int state) 213static int wm831x_buckv_set_dvs(struct regulator_dev *rdev, int state)
237{ 214{
@@ -309,7 +286,7 @@ static int wm831x_buckv_set_suspend_voltage(struct regulator_dev *rdev,
309 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL; 286 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL;
310 int vsel; 287 int vsel;
311 288
312 vsel = wm831x_buckv_map_voltage(rdev, uV, uV); 289 vsel = regulator_map_voltage_linear_range(rdev, uV, uV);
313 if (vsel < 0) 290 if (vsel < 0)
314 return vsel; 291 return vsel;
315 292
@@ -368,8 +345,8 @@ static int wm831x_buckv_get_current_limit(struct regulator_dev *rdev)
368static const struct regulator_ops wm831x_buckv_ops = { 345static const struct regulator_ops wm831x_buckv_ops = {
369 .set_voltage_sel = wm831x_buckv_set_voltage_sel, 346 .set_voltage_sel = wm831x_buckv_set_voltage_sel,
370 .get_voltage_sel = wm831x_buckv_get_voltage_sel, 347 .get_voltage_sel = wm831x_buckv_get_voltage_sel,
371 .list_voltage = wm831x_buckv_list_voltage, 348 .list_voltage = regulator_list_voltage_linear_range,
372 .map_voltage = wm831x_buckv_map_voltage, 349 .map_voltage = regulator_map_voltage_linear_range,
373 .set_suspend_voltage = wm831x_buckv_set_suspend_voltage, 350 .set_suspend_voltage = wm831x_buckv_set_suspend_voltage,
374 .set_current_limit = wm831x_buckv_set_current_limit, 351 .set_current_limit = wm831x_buckv_set_current_limit,
375 .get_current_limit = wm831x_buckv_get_current_limit, 352 .get_current_limit = wm831x_buckv_get_current_limit,
@@ -492,6 +469,8 @@ static int wm831x_buckv_probe(struct platform_device *pdev)
492 dcdc->desc.id = id; 469 dcdc->desc.id = id;
493 dcdc->desc.type = REGULATOR_VOLTAGE; 470 dcdc->desc.type = REGULATOR_VOLTAGE;
494 dcdc->desc.n_voltages = WM831X_BUCKV_MAX_SELECTOR + 1; 471 dcdc->desc.n_voltages = WM831X_BUCKV_MAX_SELECTOR + 1;
472 dcdc->desc.linear_ranges = wm831x_buckv_ranges;
473 dcdc->desc.n_linear_ranges = ARRAY_SIZE(wm831x_buckv_ranges);
495 dcdc->desc.ops = &wm831x_buckv_ops; 474 dcdc->desc.ops = &wm831x_buckv_ops;
496 dcdc->desc.owner = THIS_MODULE; 475 dcdc->desc.owner = THIS_MODULE;
497 dcdc->desc.enable_reg = WM831X_DCDC_ENABLE; 476 dcdc->desc.enable_reg = WM831X_DCDC_ENABLE;