regulator: palmas: implement sleep mode configuration
[linux-2.6.git] / drivers / regulator / wm8994-regulator.c
index 5a1dc8a..75ed402 100644 (file)
@@ -43,7 +43,7 @@ static int wm8994_ldo_enable(struct regulator_dev *rdev)
        if (!ldo->enable)
                return 0;
 
-       gpio_set_value(ldo->enable, 1);
+       gpio_set_value_cansleep(ldo->enable, 1);
        ldo->is_enabled = true;
 
        return 0;
@@ -57,7 +57,7 @@ static int wm8994_ldo_disable(struct regulator_dev *rdev)
        if (!ldo->enable)
                return -EINVAL;
 
-       gpio_set_value(ldo->enable, 0);
+       gpio_set_value_cansleep(ldo->enable, 0);
        ldo->is_enabled = false;
 
        return 0;
@@ -86,7 +86,7 @@ static int wm8994_ldo1_list_voltage(struct regulator_dev *rdev,
        return (selector * 100000) + 2400000;
 }
 
-static int wm8994_ldo1_get_voltage(struct regulator_dev *rdev)
+static int wm8994_ldo1_get_voltage_sel(struct regulator_dev *rdev)
 {
        struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
        int val;
@@ -95,13 +95,11 @@ static int wm8994_ldo1_get_voltage(struct regulator_dev *rdev)
        if (val < 0)
                return val;
 
-       val = (val & WM8994_LDO1_VSEL_MASK) >> WM8994_LDO1_VSEL_SHIFT;
-
-       return wm8994_ldo1_list_voltage(rdev, val);
+       return (val & WM8994_LDO1_VSEL_MASK) >> WM8994_LDO1_VSEL_SHIFT;
 }
 
 static int wm8994_ldo1_set_voltage(struct regulator_dev *rdev,
-                                  int min_uV, int max_uV)
+                                  int min_uV, int max_uV, unsigned *s)
 {
        struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
        int selector, v;
@@ -111,6 +109,7 @@ static int wm8994_ldo1_set_voltage(struct regulator_dev *rdev,
        if (v < 0 || v > max_uV)
                return -EINVAL;
 
+       *s = selector;
        selector <<= WM8994_LDO1_VSEL_SHIFT;
 
        return wm8994_set_bits(ldo->wm8994, WM8994_LDO_1,
@@ -124,20 +123,37 @@ static struct regulator_ops wm8994_ldo1_ops = {
        .enable_time = wm8994_ldo_enable_time,
 
        .list_voltage = wm8994_ldo1_list_voltage,
-       .get_voltage = wm8994_ldo1_get_voltage,
+       .get_voltage_sel = wm8994_ldo1_get_voltage_sel,
        .set_voltage = wm8994_ldo1_set_voltage,
 };
 
 static int wm8994_ldo2_list_voltage(struct regulator_dev *rdev,
                                    unsigned int selector)
 {
+       struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
+
        if (selector > WM8994_LDO2_MAX_SELECTOR)
                return -EINVAL;
 
-       return (selector * 100000) + 900000;
+       switch (ldo->wm8994->type) {
+       case WM8994:
+               return (selector * 100000) + 900000;
+       case WM8958:
+               return (selector * 100000) + 1000000;
+       case WM1811:
+               switch (selector) {
+               case 0:
+                       return -EINVAL;
+               default:
+                       return (selector * 100000) + 950000;
+               }
+               break;
+       default:
+               return -EINVAL;
+       }
 }
 
-static int wm8994_ldo2_get_voltage(struct regulator_dev *rdev)
+static int wm8994_ldo2_get_voltage_sel(struct regulator_dev *rdev)
 {
        struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
        int val;
@@ -146,22 +162,36 @@ static int wm8994_ldo2_get_voltage(struct regulator_dev *rdev)
        if (val < 0)
                return val;
 
-       val = (val & WM8994_LDO2_VSEL_MASK) >> WM8994_LDO2_VSEL_SHIFT;
-
-       return wm8994_ldo2_list_voltage(rdev, val);
+       return (val & WM8994_LDO2_VSEL_MASK) >> WM8994_LDO2_VSEL_SHIFT;
 }
 
 static int wm8994_ldo2_set_voltage(struct regulator_dev *rdev,
-                                  int min_uV, int max_uV)
+                                  int min_uV, int max_uV, unsigned *s)
 {
        struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
        int selector, v;
 
-       selector = (min_uV - 900000) / 100000;
+       switch (ldo->wm8994->type) {
+       case WM8994:
+               selector = (min_uV - 900000) / 100000;
+               break;
+       case WM8958:
+               selector = (min_uV - 1000000) / 100000;
+               break;
+       case WM1811:
+               selector = (min_uV - 950000) / 100000;
+               if (selector == 0)
+                       selector = 1;
+               break;
+       default:
+               return -EINVAL;
+       }
+
        v = wm8994_ldo2_list_voltage(rdev, selector);
        if (v < 0 || v > max_uV)
                return -EINVAL;
 
+       *s = selector;
        selector <<= WM8994_LDO2_VSEL_SHIFT;
 
        return wm8994_set_bits(ldo->wm8994, WM8994_LDO_2,
@@ -175,7 +205,7 @@ static struct regulator_ops wm8994_ldo2_ops = {
        .enable_time = wm8994_ldo_enable_time,
 
        .list_voltage = wm8994_ldo2_list_voltage,
-       .get_voltage = wm8994_ldo2_get_voltage,
+       .get_voltage_sel = wm8994_ldo2_get_voltage_sel,
        .set_voltage = wm8994_ldo2_set_voltage,
 };
 
@@ -211,7 +241,7 @@ static __devinit int wm8994_ldo_probe(struct platform_device *pdev)
        if (!pdata)
                return -ENODEV;
 
-       ldo = kzalloc(sizeof(struct wm8994_ldo), GFP_KERNEL);
+       ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm8994_ldo), GFP_KERNEL);
        if (ldo == NULL) {
                dev_err(&pdev->dev, "Unable to allocate private data\n");
                return -ENOMEM;
@@ -219,8 +249,6 @@ static __devinit int wm8994_ldo_probe(struct platform_device *pdev)
 
        ldo->wm8994 = wm8994;
 
-       ldo->is_enabled = true;
-
        if (pdata->ldo[id].enable && gpio_is_valid(pdata->ldo[id].enable)) {
                ldo->enable = pdata->ldo[id].enable;
 
@@ -237,10 +265,11 @@ static __devinit int wm8994_ldo_probe(struct platform_device *pdev)
                                ret);
                        goto err_gpio;
                }
-       }
+       } else
+               ldo->is_enabled = true;
 
        ldo->regulator = regulator_register(&wm8994_ldo_desc[id], &pdev->dev,
-                                            pdata->ldo[id].init_data, ldo);
+                                            pdata->ldo[id].init_data, ldo, NULL);
        if (IS_ERR(ldo->regulator)) {
                ret = PTR_ERR(ldo->regulator);
                dev_err(wm8994->dev, "Failed to register LDO%d: %d\n",
@@ -256,7 +285,6 @@ err_gpio:
        if (gpio_is_valid(ldo->enable))
                gpio_free(ldo->enable);
 err:
-       kfree(ldo);
        return ret;
 }
 
@@ -269,7 +297,6 @@ static __devexit int wm8994_ldo_remove(struct platform_device *pdev)
        regulator_unregister(ldo->regulator);
        if (gpio_is_valid(ldo->enable))
                gpio_free(ldo->enable);
-       kfree(ldo);
 
        return 0;
 }