regulator: wm831x-dcdc: Convert to use regulator_linear_range for wm831x_buckv
authorAxel Lin <axel.lin@ingics.com>
Sun, 20 Jan 2019 07:33:56 +0000 (15:33 +0800)
committerMark Brown <broonie@kernel.org>
Tue, 22 Jan 2019 17:26:24 +0000 (17:26 +0000)
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/regulator/wm831x-dcdc.c

index 5a5bc4bb08d26ee78926aacaa906010cc1f426c2..4a573eea284a387185f7bf5742a00d35c718ce76 100644 (file)
@@ -205,33 +205,10 @@ static irqreturn_t wm831x_dcdc_oc_irq(int irq, void *data)
  * BUCKV specifics
  */
 
-static int wm831x_buckv_list_voltage(struct regulator_dev *rdev,
-                                     unsigned selector)
-{
-       if (selector <= 0x8)
-               return 600000;
-       if (selector <= WM831X_BUCKV_MAX_SELECTOR)
-               return 600000 + ((selector - 0x8) * 12500);
-       return -EINVAL;
-}
-
-static int wm831x_buckv_map_voltage(struct regulator_dev *rdev,
-                                  int min_uV, int max_uV)
-{
-       u16 vsel;
-
-       if (min_uV < 600000)
-               vsel = 0;
-       else if (min_uV <= 1800000)
-               vsel = DIV_ROUND_UP(min_uV - 600000, 12500) + 8;
-       else
-               return -EINVAL;
-
-       if (wm831x_buckv_list_voltage(rdev, vsel) > max_uV)
-               return -EINVAL;
-
-       return vsel;
-}
+static const struct regulator_linear_range wm831x_buckv_ranges[] = {
+       REGULATOR_LINEAR_RANGE(600000, 0, 0x7, 0),
+       REGULATOR_LINEAR_RANGE(600000, 0x8, 0x68, 12500),
+};
 
 static int wm831x_buckv_set_dvs(struct regulator_dev *rdev, int state)
 {
@@ -309,7 +286,7 @@ static int wm831x_buckv_set_suspend_voltage(struct regulator_dev *rdev,
        u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL;
        int vsel;
 
-       vsel = wm831x_buckv_map_voltage(rdev, uV, uV);
+       vsel = regulator_map_voltage_linear_range(rdev, uV, uV);
        if (vsel < 0)
                return vsel;
 
@@ -368,8 +345,8 @@ static int wm831x_buckv_get_current_limit(struct regulator_dev *rdev)
 static const struct regulator_ops wm831x_buckv_ops = {
        .set_voltage_sel = wm831x_buckv_set_voltage_sel,
        .get_voltage_sel = wm831x_buckv_get_voltage_sel,
-       .list_voltage = wm831x_buckv_list_voltage,
-       .map_voltage = wm831x_buckv_map_voltage,
+       .list_voltage = regulator_list_voltage_linear_range,
+       .map_voltage = regulator_map_voltage_linear_range,
        .set_suspend_voltage = wm831x_buckv_set_suspend_voltage,
        .set_current_limit = wm831x_buckv_set_current_limit,
        .get_current_limit = wm831x_buckv_get_current_limit,
@@ -492,6 +469,8 @@ static int wm831x_buckv_probe(struct platform_device *pdev)
        dcdc->desc.id = id;
        dcdc->desc.type = REGULATOR_VOLTAGE;
        dcdc->desc.n_voltages = WM831X_BUCKV_MAX_SELECTOR + 1;
+       dcdc->desc.linear_ranges = wm831x_buckv_ranges;
+       dcdc->desc.n_linear_ranges = ARRAY_SIZE(wm831x_buckv_ranges);
        dcdc->desc.ops = &wm831x_buckv_ops;
        dcdc->desc.owner = THIS_MODULE;
        dcdc->desc.enable_reg = WM831X_DCDC_ENABLE;