regulator: wm831x-isink: Convert to use regulator_set/get_current_limit_regmap
authorAxel Lin <axel.lin@ingics.com>
Tue, 12 Mar 2019 16:33:56 +0000 (00:33 +0800)
committerMark Brown <broonie@kernel.org>
Wed, 13 Mar 2019 15:13:59 +0000 (15:13 +0000)
Use regulator_set/get_current_limit_regmap helpers to save some code.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Acked-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/mfd/wm831x-core.c
drivers/regulator/wm831x-isink.c
include/linux/mfd/wm831x/regulator.h

index e70d35ef5c6d6cf5e01234d150a1f9a175f01df5..e865a1fd4bd54cb347cbb95033a1874adefafad9 100644 (file)
@@ -33,7 +33,7 @@
 /* Current settings - values are 2*2^(reg_val/4) microamps.  These are
  * exported since they are used by multiple drivers.
  */
-int wm831x_isinkv_values[WM831X_ISINK_MAX_ISEL + 1] = {
+const unsigned int wm831x_isinkv_values[WM831X_ISINK_MAX_ISEL + 1] = {
        2,
        2,
        3,
index 5611890a724b461fbf9e287bf92f9a5d88c1b80c..bdc521a6f0483f1b05765d366bbd44f75e9705d2 100644 (file)
@@ -92,48 +92,12 @@ static int wm831x_isink_is_enabled(struct regulator_dev *rdev)
                return 0;
 }
 
-static int wm831x_isink_set_current(struct regulator_dev *rdev,
-                                   int min_uA, int max_uA)
-{
-       struct wm831x_isink *isink = rdev_get_drvdata(rdev);
-       struct wm831x *wm831x = isink->wm831x;
-       int ret, i;
-
-       for (i = ARRAY_SIZE(wm831x_isinkv_values) - 1; i >= 0; i--) {
-               int val = wm831x_isinkv_values[i];
-               if (min_uA <= val && val <= max_uA) {
-                       ret = wm831x_set_bits(wm831x, isink->reg,
-                                             WM831X_CS1_ISEL_MASK, i);
-                       return ret;
-               }
-       }
-
-       return -EINVAL;
-}
-
-static int wm831x_isink_get_current(struct regulator_dev *rdev)
-{
-       struct wm831x_isink *isink = rdev_get_drvdata(rdev);
-       struct wm831x *wm831x = isink->wm831x;
-       int ret;
-
-       ret = wm831x_reg_read(wm831x, isink->reg);
-       if (ret < 0)
-               return ret;
-
-       ret &= WM831X_CS1_ISEL_MASK;
-       if (ret > WM831X_ISINK_MAX_ISEL)
-               ret = WM831X_ISINK_MAX_ISEL;
-
-       return wm831x_isinkv_values[ret];
-}
-
 static const struct regulator_ops wm831x_isink_ops = {
        .is_enabled = wm831x_isink_is_enabled,
        .enable = wm831x_isink_enable,
        .disable = wm831x_isink_disable,
-       .set_current_limit = wm831x_isink_set_current,
-       .get_current_limit = wm831x_isink_get_current,
+       .set_current_limit = regulator_set_current_limit_regmap,
+       .get_current_limit = regulator_get_current_limit_regmap,
 };
 
 static irqreturn_t wm831x_isink_irq(int irq, void *data)
@@ -189,10 +153,15 @@ static int wm831x_isink_probe(struct platform_device *pdev)
        isink->desc.ops = &wm831x_isink_ops;
        isink->desc.type = REGULATOR_CURRENT;
        isink->desc.owner = THIS_MODULE;
+       isink->desc.curr_table = wm831x_isinkv_values,
+       isink->desc.n_current_limits = ARRAY_SIZE(wm831x_isinkv_values),
+       isink->desc.csel_reg = isink->reg,
+       isink->desc.csel_mask = WM831X_CS1_ISEL_MASK,
 
        config.dev = pdev->dev.parent;
        config.init_data = pdata->isink[id];
        config.driver_data = isink;
+       config.regmap = wm831x->regmap;
 
        isink->regulator = devm_regulator_register(&pdev->dev, &isink->desc,
                                                   &config);
index 955d30fc6a274aef932ac8c619e672453508b229..30c587a0624c32679d55827c7f012fad637bd8cd 100644 (file)
 #define WM831X_LDO1_OK_WIDTH                         1  /* LDO1_OK */
 
 #define WM831X_ISINK_MAX_ISEL 55
-extern int wm831x_isinkv_values[WM831X_ISINK_MAX_ISEL + 1];
+extern const unsigned int wm831x_isinkv_values[WM831X_ISINK_MAX_ISEL + 1];
 
 #endif