regulator: palma: Disable smps10 boost during suspend
[linux-2.6.git] / drivers / regulator / tps6586x-regulator.c
index 9ab8f3f..0c7cad3 100644 (file)
@@ -14,6 +14,7 @@
  */
 
 #include <linux/kernel.h>
+#include <linux/module.h>
 #include <linux/init.h>
 #include <linux/err.h>
 #include <linux/slab.h>
@@ -79,6 +80,11 @@ static int tps6586x_ldo_list_voltage(struct regulator_dev *rdev,
                                     unsigned selector)
 {
        struct tps6586x_regulator *info = rdev_get_drvdata(rdev);
+       int rid = rdev_get_id(rdev);
+
+       /* LDO0 has minimal voltage 1.2V rather than 1.25V */
+       if ((rid == TPS6586X_ID_LDO_0) && (selector == 0))
+               return (info->voltages[0] - 50) * 1000;
 
        return info->voltages[selector] * 1000;
 }
@@ -341,64 +347,69 @@ static inline int tps6586x_regulator_preinit(struct device *parent,
                                 1 << ri->enable_bit[1]);
 }
 
-static inline int tps6586x_regulator_set_pwm_mode(struct platform_device *pdev)
+static int tps6586x_regulator_set_slew_rate(struct platform_device *pdev)
 {
        struct device *parent = pdev->dev.parent;
        struct regulator_init_data *p = pdev->dev.platform_data;
        struct tps6586x_settings *setting = p->driver_data;
-       int ret = 0;
-       uint8_t mask;
+       uint8_t reg;
 
        if (setting == NULL)
                return 0;
 
+       if (!(setting->slew_rate & TPS6586X_SLEW_RATE_SET))
+               return 0;
+
+       /* only SM0 and SM1 can have the slew rate settings */
        switch (pdev->id) {
        case TPS6586X_ID_SM_0:
-               mask = 1 << SM0_PWM_BIT;
+               reg = TPS6586X_SM0SL;
                break;
        case TPS6586X_ID_SM_1:
-               mask = 1 << SM1_PWM_BIT;
-               break;
-       case TPS6586X_ID_SM_2:
-               mask = 1 << SM2_PWM_BIT;
+               reg = TPS6586X_SM1SL;
                break;
        default:
-               /* not all regulators have PWM/PFM option */
-               return 0;
+               dev_warn(&pdev->dev, "Only SM0/SM1 can set slew rate\n");
+               return -EINVAL;
        }
 
-       if (setting->sm_pwm_mode == PWM_ONLY)
-               ret = tps6586x_set_bits(parent, TPS6586X_SMODE1, mask);
-       else if (setting->sm_pwm_mode == AUTO_PWM_PFM)
-               ret = tps6586x_clr_bits(parent, TPS6586X_SMODE1, mask);
-
-       return ret;
+       return tps6586x_write(parent, reg,
+                       setting->slew_rate & TPS6586X_SLEW_RATE_MASK);
 }
 
-static inline int tps6586x_regulator_set_slew_rate(struct platform_device *pdev)
+static inline int tps6586x_regulator_set_pwm_mode(struct platform_device *pdev)
 {
        struct device *parent = pdev->dev.parent;
        struct regulator_init_data *p = pdev->dev.platform_data;
        struct tps6586x_settings *setting = p->driver_data;
-       uint8_t reg;
+       int ret = 0;
+       uint8_t mask;
 
        if (setting == NULL)
                return 0;
 
-       /* only SM0 and SM1 can have the slew rate settings */
        switch (pdev->id) {
        case TPS6586X_ID_SM_0:
-               reg = TPS6586X_SM0SL;
+               mask = 1 << SM0_PWM_BIT;
                break;
        case TPS6586X_ID_SM_1:
-               reg = TPS6586X_SM1SL;
+               mask = 1 << SM1_PWM_BIT;
+               break;
+       case TPS6586X_ID_SM_2:
+               mask = 1 << SM2_PWM_BIT;
                break;
        default:
+               /* not all regulators have PWM/PFM option */
                return 0;
        }
-       return tps6586x_write(parent, reg, setting->slew_rate);
-}
 
+       if (setting->sm_pwm_mode == PWM_ONLY)
+               ret = tps6586x_set_bits(parent, TPS6586X_SMODE1, mask);
+       else if (setting->sm_pwm_mode == AUTO_PWM_PFM)
+               ret = tps6586x_clr_bits(parent, TPS6586X_SMODE1, mask);
+
+       return ret;
+}
 static inline struct tps6586x_regulator *find_regulator_info(int id)
 {
        struct tps6586x_regulator *ri;
@@ -419,7 +430,7 @@ static int __devinit tps6586x_regulator_probe(struct platform_device *pdev)
        int id = pdev->id;
        int err;
 
-       dev_dbg(&pdev->dev, "Probing reulator %d\n", id);
+       dev_dbg(&pdev->dev, "Probing regulator %d\n", id);
 
        ri = find_regulator_info(id);
        if (ri == NULL) {
@@ -432,7 +443,7 @@ static int __devinit tps6586x_regulator_probe(struct platform_device *pdev)
                return err;
 
        rdev = regulator_register(&ri->desc, &pdev->dev,
-                                 pdev->dev.platform_data, ri);
+                                 pdev->dev.platform_data, ri, NULL);
        if (IS_ERR(rdev)) {
                dev_err(&pdev->dev, "failed to register regulator %s\n",
                                ri->desc.name);