regulator: palmas: fix build warnings
[linux-2.6.git] / drivers / regulator / wm831x-dcdc.c
index 2c5d54b..97bb31d 100644 (file)
@@ -267,23 +267,6 @@ static int wm831x_buckv_select_min_voltage(struct regulator_dev *rdev,
        return vsel;
 }
 
-static int wm831x_buckv_select_max_voltage(struct regulator_dev *rdev,
-                                          int min_uV, int max_uV)
-{
-       u16 vsel;
-
-       if (max_uV < 600000 || max_uV > 1800000)
-               return -EINVAL;
-
-       vsel = ((max_uV - 600000) / 12500) + 8;
-
-       if (wm831x_buckv_list_voltage(rdev, vsel) < min_uV ||
-           wm831x_buckv_list_voltage(rdev, vsel) < max_uV)
-               return -EINVAL;
-
-       return vsel;
-}
-
 static int wm831x_buckv_set_dvs(struct regulator_dev *rdev, int state)
 {
        struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
@@ -338,28 +321,23 @@ static int wm831x_buckv_set_voltage(struct regulator_dev *rdev,
        if (ret < 0)
                return ret;
 
-       /* Set the high voltage as the DVS voltage.  This is optimised
-        * for CPUfreq usage, most processors will keep the maximum
-        * voltage constant and lower the minimum with the frequency. */
-       vsel = wm831x_buckv_select_max_voltage(rdev, min_uV, max_uV);
-       if (vsel < 0) {
-               /* This should never happen - at worst the same vsel
-                * should be chosen */
-               WARN_ON(vsel < 0);
-               return 0;
+       /*
+        * If this VSEL is higher than the last one we've seen then
+        * remember it as the DVS VSEL.  This is optimised for CPUfreq
+        * usage where we want to get to the highest voltage very
+        * quickly.
+        */
+       if (vsel > dcdc->dvs_vsel) {
+               ret = wm831x_set_bits(wm831x, dvs_reg,
+                                     WM831X_DC1_DVS_VSEL_MASK,
+                                     vsel);
+               if (ret == 0)
+                       dcdc->dvs_vsel = vsel;
+               else
+                       dev_warn(wm831x->dev,
+                                "Failed to set DCDC DVS VSEL: %d\n", ret);
        }
 
-       /* Don't bother if it's the same VSEL we're already using */
-       if (vsel == dcdc->on_vsel)
-               return 0;
-
-       ret = wm831x_set_bits(wm831x, dvs_reg, WM831X_DC1_DVS_VSEL_MASK, vsel);
-       if (ret == 0)
-               dcdc->dvs_vsel = vsel;
-       else
-               dev_warn(wm831x->dev, "Failed to set DCDC DVS VSEL: %d\n",
-                        ret);
-
        return 0;
 }
 
@@ -402,13 +380,15 @@ static int wm831x_buckv_set_current_limit(struct regulator_dev *rdev,
        int i;
 
        for (i = 0; i < ARRAY_SIZE(wm831x_dcdc_ilim); i++) {
-               if (max_uA <= wm831x_dcdc_ilim[i])
+               if ((min_uA <= wm831x_dcdc_ilim[i]) &&
+                   (wm831x_dcdc_ilim[i] <= max_uA))
                        break;
        }
        if (i == ARRAY_SIZE(wm831x_dcdc_ilim))
                return -EINVAL;
 
-       return wm831x_set_bits(wm831x, reg, WM831X_DC1_HC_THR_MASK, i);
+       return wm831x_set_bits(wm831x, reg, WM831X_DC1_HC_THR_MASK,
+                              i << WM831X_DC1_HC_THR_SHIFT);
 }
 
 static int wm831x_buckv_get_current_limit(struct regulator_dev *rdev)
@@ -422,7 +402,8 @@ static int wm831x_buckv_get_current_limit(struct regulator_dev *rdev)
        if (val < 0)
                return val;
 
-       return wm831x_dcdc_ilim[val & WM831X_DC1_HC_THR_MASK];
+       val = (val & WM831X_DC1_HC_THR_MASK) >> WM831X_DC1_HC_THR_SHIFT;
+       return wm831x_dcdc_ilim[val];
 }
 
 static struct regulator_ops wm831x_buckv_ops = {
@@ -533,7 +514,8 @@ static __devinit int wm831x_buckv_probe(struct platform_device *pdev)
        if (pdata == NULL || pdata->dcdc[id] == NULL)
                return -ENODEV;
 
-       dcdc = kzalloc(sizeof(struct wm831x_dcdc), GFP_KERNEL);
+       dcdc = devm_kzalloc(&pdev->dev,  sizeof(struct wm831x_dcdc),
+                           GFP_KERNEL);
        if (dcdc == NULL) {
                dev_err(&pdev->dev, "Unable to allocate private data\n");
                return -ENOMEM;
@@ -575,7 +557,7 @@ static __devinit int wm831x_buckv_probe(struct platform_device *pdev)
                wm831x_buckv_dvs_init(dcdc, pdata->dcdc[id]->driver_data);
 
        dcdc->regulator = regulator_register(&dcdc->desc, &pdev->dev,
-                                            pdata->dcdc[id], dcdc);
+                                            pdata->dcdc[id], dcdc, NULL);
        if (IS_ERR(dcdc->regulator)) {
                ret = PTR_ERR(dcdc->regulator);
                dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n",
@@ -612,7 +594,6 @@ err_regulator:
 err:
        if (dcdc->dvs_gpio)
                gpio_free(dcdc->dvs_gpio);
-       kfree(dcdc);
        return ret;
 }
 
@@ -627,7 +608,6 @@ static __devexit int wm831x_buckv_remove(struct platform_device *pdev)
        regulator_unregister(dcdc->regulator);
        if (dcdc->dvs_gpio)
                gpio_free(dcdc->dvs_gpio);
-       kfree(dcdc);
 
        return 0;
 }
@@ -744,7 +724,8 @@ static __devinit int wm831x_buckp_probe(struct platform_device *pdev)
        if (pdata == NULL || pdata->dcdc[id] == NULL)
                return -ENODEV;
 
-       dcdc = kzalloc(sizeof(struct wm831x_dcdc), GFP_KERNEL);
+       dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc),
+                           GFP_KERNEL);
        if (dcdc == NULL) {
                dev_err(&pdev->dev, "Unable to allocate private data\n");
                return -ENOMEM;
@@ -769,7 +750,7 @@ static __devinit int wm831x_buckp_probe(struct platform_device *pdev)
        dcdc->desc.owner = THIS_MODULE;
 
        dcdc->regulator = regulator_register(&dcdc->desc, &pdev->dev,
-                                            pdata->dcdc[id], dcdc);
+                                            pdata->dcdc[id], dcdc, NULL);
        if (IS_ERR(dcdc->regulator)) {
                ret = PTR_ERR(dcdc->regulator);
                dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n",
@@ -793,7 +774,6 @@ static __devinit int wm831x_buckp_probe(struct platform_device *pdev)
 err_regulator:
        regulator_unregister(dcdc->regulator);
 err:
-       kfree(dcdc);
        return ret;
 }
 
@@ -805,7 +785,6 @@ static __devexit int wm831x_buckp_remove(struct platform_device *pdev)
 
        free_irq(platform_get_irq_byname(pdev, "UV"), dcdc);
        regulator_unregister(dcdc->regulator);
-       kfree(dcdc);
 
        return 0;
 }
@@ -896,7 +875,7 @@ static __devinit int wm831x_boostp_probe(struct platform_device *pdev)
        dcdc->desc.owner = THIS_MODULE;
 
        dcdc->regulator = regulator_register(&dcdc->desc, &pdev->dev,
-                                            pdata->dcdc[id], dcdc);
+                                            pdata->dcdc[id], dcdc, NULL);
        if (IS_ERR(dcdc->regulator)) {
                ret = PTR_ERR(dcdc->regulator);
                dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n",
@@ -995,7 +974,7 @@ static __devinit int wm831x_epe_probe(struct platform_device *pdev)
        dcdc->desc.owner = THIS_MODULE;
 
        dcdc->regulator = regulator_register(&dcdc->desc, &pdev->dev,
-                                            pdata->epe[id], dcdc);
+                                            pdata->epe[id], dcdc, NULL);
        if (IS_ERR(dcdc->regulator)) {
                ret = PTR_ERR(dcdc->regulator);
                dev_err(wm831x->dev, "Failed to register EPE%d: %d\n",