Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Axel Lin and committed by
Mark Brown
ccffcb8e 93997a05

+9 -30
+9 -30
drivers/regulator/wm831x-dcdc.c
··· 205 205 * BUCKV specifics 206 206 */ 207 207 208 - static int wm831x_buckv_list_voltage(struct regulator_dev *rdev, 209 - unsigned selector) 210 - { 211 - if (selector <= 0x8) 212 - return 600000; 213 - if (selector <= WM831X_BUCKV_MAX_SELECTOR) 214 - return 600000 + ((selector - 0x8) * 12500); 215 - return -EINVAL; 216 - } 217 - 218 - static 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 - } 208 + static const struct regulator_linear_range wm831x_buckv_ranges[] = { 209 + REGULATOR_LINEAR_RANGE(600000, 0, 0x7, 0), 210 + REGULATOR_LINEAR_RANGE(600000, 0x8, 0x68, 12500), 211 + }; 235 212 236 213 static int wm831x_buckv_set_dvs(struct regulator_dev *rdev, int state) 237 214 { ··· 286 309 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL; 287 310 int vsel; 288 311 289 - vsel = wm831x_buckv_map_voltage(rdev, uV, uV); 312 + vsel = regulator_map_voltage_linear_range(rdev, uV, uV); 290 313 if (vsel < 0) 291 314 return vsel; 292 315 ··· 345 368 static const struct regulator_ops wm831x_buckv_ops = { 346 369 .set_voltage_sel = wm831x_buckv_set_voltage_sel, 347 370 .get_voltage_sel = wm831x_buckv_get_voltage_sel, 348 - .list_voltage = wm831x_buckv_list_voltage, 349 - .map_voltage = wm831x_buckv_map_voltage, 371 + .list_voltage = regulator_list_voltage_linear_range, 372 + .map_voltage = regulator_map_voltage_linear_range, 350 373 .set_suspend_voltage = wm831x_buckv_set_suspend_voltage, 351 374 .set_current_limit = wm831x_buckv_set_current_limit, 352 375 .get_current_limit = wm831x_buckv_get_current_limit, ··· 469 492 dcdc->desc.id = id; 470 493 dcdc->desc.type = REGULATOR_VOLTAGE; 471 494 dcdc->desc.n_voltages = WM831X_BUCKV_MAX_SELECTOR + 1; 495 + dcdc->desc.linear_ranges = wm831x_buckv_ranges; 496 + dcdc->desc.n_linear_ranges = ARRAY_SIZE(wm831x_buckv_ranges); 472 497 dcdc->desc.ops = &wm831x_buckv_ops; 473 498 dcdc->desc.owner = THIS_MODULE; 474 499 dcdc->desc.enable_reg = WM831X_DCDC_ENABLE;