regulator: tps6591x: supporting init state of output through board
Laxman Dewangan [Thu, 10 Feb 2011 10:44:46 +0000 (15:44 +0530)]
Supporting init state of the output power rails from tps6591x through
board files to enable/disable and setting required voltage level.

Original-Change-Id: Ifdf3c4fea889c1fed465db0bdb39df079bf1afa8
Reviewed-on: http://git-master/r/19061
Reviewed-by: Laxman Dewangan <ldewangan@nvidia.com>
Tested-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-by: Hanumanth Venkateswa Moganty <vmoganty@nvidia.com>
Original-Change-Id: I198d471ab98aa5bff125b77ccfa99c9104a86426

Rebase-Id: R2199888f87cb319ab257d5aad832bec5496fb64e

drivers/regulator/tps6591x-regulator.c
include/linux/regulator/tps6591x-regulator.h [new file with mode: 0644]

index 89fcbf9..6931d92 100755 (executable)
@@ -28,6 +28,7 @@
 #include <linux/platform_device.h>
 #include <linux/regulator/driver.h>
 #include <linux/regulator/machine.h>
+#include <linux/regulator/tps6591x-regulator.h>
 #include <linux/mfd/tps6591x.h>
 
 /* supply control and voltage setting  */
@@ -513,9 +514,70 @@ static struct tps6591x_regulator tps6591x_regulator[] = {
 };
 
 static inline int tps6591x_regulator_preinit(struct device *parent,
-                                            struct tps6591x_regulator *ri)
+               struct tps6591x_regulator *ri,
+               struct tps6591x_regulator_platform_data *tps6591x_pdata)
 {
-       return tps6591x_set_bits(parent, ri->supply_reg.addr, 0x1);
+       int ret;
+
+       if (!tps6591x_pdata->init_apply)
+               return 0;
+
+       if (tps6591x_pdata->init_uV >= 0) {
+               switch (ri->desc.id) {
+               case TPS6591X_ID_VIO:
+                       ret = __tps6591x_vio_set_voltage(parent, ri,
+                                       tps6591x_pdata->init_uV,
+                                       tps6591x_pdata->init_uV);
+                       break;
+
+               case TPS6591X_ID_LDO_1:
+               case TPS6591X_ID_LDO_2:
+               case TPS6591X_ID_LDO_4:
+                       ret = __tps6591x_ldo1_set_voltage(parent, ri,
+                                       tps6591x_pdata->init_uV,
+                                       tps6591x_pdata->init_uV);
+                       break;
+
+               case TPS6591X_ID_LDO_3:
+               case TPS6591X_ID_LDO_5:
+               case TPS6591X_ID_LDO_6:
+               case TPS6591X_ID_LDO_7:
+               case TPS6591X_ID_LDO_8:
+                       ret = __tps6591x_ldo3_set_voltage(parent, ri,
+                                       tps6591x_pdata->init_uV,
+                                       tps6591x_pdata->init_uV);
+                       break;
+
+               case TPS6591X_ID_VDD_1:
+               case TPS6591X_ID_VDD_2:
+               case TPS6591X_ID_VDDCTRL:
+                       ret = __tps6591x_vdd_set_voltage(parent, ri,
+                                       tps6591x_pdata->init_uV,
+                                       tps6591x_pdata->init_uV);
+                       break;
+
+               default:
+                       ret = -EINVAL;
+                       break;
+               }
+               if (ret < 0) {
+                       pr_err("Not able to initialize voltage %d for rail "
+                               "%d err %d\n", tps6591x_pdata->init_uV,
+                               ri->desc.id, ret);
+                       return ret;
+               }
+       }
+
+       if (tps6591x_pdata->init_enable)
+               ret = tps6591x_set_bits(parent, ri->supply_reg.addr, 0x1);
+       else
+               ret = tps6591x_clr_bits(parent, ri->supply_reg.addr, 0x1);
+
+       if (ret < 0)
+               pr_err("Not able to %s rail %d err %d\n",
+                       (tps6591x_pdata->init_enable) ? "enable" : "disable",
+                       ri->desc.id, ret);
+       return ret;
 }
 
 static inline struct tps6591x_regulator *find_regulator_info(int id)
@@ -535,6 +597,7 @@ static int __devinit tps6591x_regulator_probe(struct platform_device *pdev)
 {
        struct tps6591x_regulator *ri = NULL;
        struct regulator_dev *rdev;
+       struct tps6591x_regulator_platform_data *tps_pdata;
        int id = pdev->id;
        int err;
 
@@ -545,13 +608,14 @@ static int __devinit tps6591x_regulator_probe(struct platform_device *pdev)
                dev_err(&pdev->dev, "invalid regulator ID specified\n");
                return -EINVAL;
        }
+       tps_pdata = pdev->dev.platform_data;
 
-       err = tps6591x_regulator_preinit(pdev->dev.parent, ri);
+       err = tps6591x_regulator_preinit(pdev->dev.parent, ri, tps_pdata);
        if (err)
                return err;
 
        rdev = regulator_register(&ri->desc, &pdev->dev,
-                                 pdev->dev.platform_data, ri);
+                               &tps_pdata->regulator, ri);
        if (IS_ERR_OR_NULL(rdev)) {
                dev_err(&pdev->dev, "failed to register regulator %s\n",
                                ri->desc.name);
diff --git a/include/linux/regulator/tps6591x-regulator.h b/include/linux/regulator/tps6591x-regulator.h
new file mode 100644 (file)
index 0000000..ade9978
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * include/linux/regulator/tps6591x-regulator.h
+ *
+ * Interface for regulator driver for TI TPS6591x PMIC family
+ *
+ * Copyright (C) 2011 NVIDIA Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#ifndef __REGULATOR_TPS6591X_H
+#define        __REGULATOR_TPS6591X_H
+
+#include <linux/regulator/machine.h>
+
+/*
+ * struct tps6591x_regulator_platform_data - tps6591x regulator platform data.
+ *
+ * @regulator: The regulator init data.
+ * @init_uV: initial micro volts which need to be set.
+ * @init_enable: Enable or do not enable the rails during initialization.
+ * @init_apply: Init parameter applied or not.
+ */
+
+struct tps6591x_regulator_platform_data {
+       struct regulator_init_data regulator;
+       int init_uV;
+       unsigned init_enable:1;
+       unsigned init_apply:1;
+};
+
+#endif /* __REGULATOR_TPS6591X_H */