regulator: palmas: add support for ext power req
Gaurav Batra [Tue, 2 Apr 2013 18:56:42 +0000 (11:56 -0700)]
Bug 1242520

Change-Id: I0911977291a8fa0eccff3cba0d7fdedafbc91a36
Signed-off-by: Gaurav Batra <gbatra@nvidia.com>
Reviewed-on: http://git-master/r/215721
Reviewed-by: Laxman Dewangan <ldewangan@nvidia.com>
Tested-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-by: Automatic_Commit_Validation_User

drivers/regulator/palmas-regulator.c
include/linux/mfd/palmas.h

index 4948659..b83b3bc 100644 (file)
@@ -2,6 +2,7 @@
  * Driver for Regulator part of Palmas PMIC Chips
  *
  * Copyright 2011-2012 Texas Instruments Inc.
+ * Copyright (c) 2013, NVIDIA CORPORATION.  All rights reserved.
  *
  * Author: Graeme Gregory <gg@slimlogic.co.uk>
  *
 #define PALMA_SMPS10_BYPASS_EN BIT(1)
 #define PALMA_SMPS10_SWITCH_EN BIT(0)
 
+#define EXT_PWR_REQ (PALMAS_EXT_CONTROL_ENABLE1 |      \
+                    PALMAS_EXT_CONTROL_ENABLE2 |       \
+                    PALMAS_EXT_CONTROL_NSLEEP)
+
 struct regs_info {
        char    *name;
        u8      vsel_addr;
@@ -293,6 +298,9 @@ static int palmas_is_enabled_smps(struct regulator_dev *dev)
        int id = rdev_get_id(dev);
        unsigned int reg;
 
+       if (EXT_PWR_REQ & pmic->roof_floor[id])
+               return true;
+
        palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
 
        reg &= PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
@@ -307,6 +315,9 @@ static int palmas_enable_smps(struct regulator_dev *dev)
        int id = rdev_get_id(dev);
        unsigned int reg;
 
+       if (EXT_PWR_REQ & pmic->roof_floor[id])
+               return 0;
+
        palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
 
        reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
@@ -326,6 +337,9 @@ static int palmas_disable_smps(struct regulator_dev *dev)
        int id = rdev_get_id(dev);
        unsigned int reg;
 
+       if (EXT_PWR_REQ & pmic->roof_floor[id])
+               return 0;
+
        palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
 
        reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
@@ -566,9 +580,13 @@ static struct regulator_ops palmas_ops_smps = {
 static int palmas_is_enabled_smps10(struct regulator_dev *dev)
 {
        struct palmas_pmic *pmic = rdev_get_drvdata(dev);
+       int id = rdev_get_id(dev);
        unsigned int reg;
        int ret;
 
+       if (EXT_PWR_REQ & pmic->roof_floor[id])
+               return true;
+
        ret = palmas_smps_read(pmic->palmas, PALMAS_SMPS10_STATUS, &reg);
        if (ret < 0) {
                dev_err(pmic->palmas->dev,
@@ -589,6 +607,9 @@ static int palmas_enable_smps10(struct regulator_dev *dev)
        unsigned int reg;
        int ret;
 
+       if (EXT_PWR_REQ & pmic->roof_floor[id])
+               return 0;
+
        ret = palmas_smps_read(pmic->palmas,
                                palmas_regs_info[id].ctrl_addr, &reg);
        if (ret < 0) {
@@ -615,6 +636,9 @@ static int palmas_disable_smps10(struct regulator_dev *dev)
        unsigned int reg;
        int ret;
 
+       if (EXT_PWR_REQ & pmic->roof_floor[id])
+               return 0;
+
        ret = palmas_smps_read(pmic->palmas,
                                palmas_regs_info[id].ctrl_addr, &reg);
        if (ret < 0) {
@@ -707,6 +731,9 @@ static int palmas_is_enabled_ldo(struct regulator_dev *dev)
        int id = rdev_get_id(dev);
        unsigned int reg;
 
+       if (EXT_PWR_REQ & pmic->roof_floor[id])
+               return true;
+
        palmas_ldo_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
 
        reg &= PALMAS_LDO1_CTRL_STATUS;
@@ -720,6 +747,9 @@ static int palmas_enable_ldo(struct regulator_dev *dev)
        int id = rdev_get_id(dev);
        unsigned int reg;
 
+       if (EXT_PWR_REQ & pmic->roof_floor[id])
+               return 0;
+
        palmas_ldo_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
 
        reg |= SMPS_CTRL_MODE_ON;
@@ -735,6 +765,9 @@ static int palmas_disable_ldo(struct regulator_dev *dev)
        int id = rdev_get_id(dev);
        unsigned int reg;
 
+       if (EXT_PWR_REQ & pmic->roof_floor[id])
+               return 0;
+
        palmas_ldo_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
 
        reg &= ~SMPS_CTRL_MODE_ON;
@@ -808,6 +841,9 @@ static int palmas_is_enabled_extreg(struct regulator_dev *dev)
        unsigned int reg;
        int ret;
 
+       if (EXT_PWR_REQ & pmic->roof_floor[id])
+               return true;
+
        ret = palmas_resource_read(pmic->palmas,
                        palmas_regs_info[id].ctrl_addr, &reg);
        reg &= PALMAS_REGEN1_CTRL_STATUS;
@@ -824,6 +860,9 @@ static int palmas_enable_extreg(struct regulator_dev *dev)
        unsigned int reg;
        int ret;
 
+       if (EXT_PWR_REQ & pmic->roof_floor[id])
+               return 0;
+
        ret = palmas_resource_read(pmic->palmas,
                        palmas_regs_info[id].ctrl_addr, &reg);
        if (ret < 0)
@@ -842,6 +881,9 @@ static int palmas_disable_extreg(struct regulator_dev *dev)
        unsigned int reg;
        int ret;
 
+       if (EXT_PWR_REQ & pmic->roof_floor[id])
+               return 0;
+
        ret = palmas_resource_read(pmic->palmas,
                        palmas_regs_info[id].ctrl_addr, &reg);
        if (ret < 0)
@@ -1374,6 +1416,7 @@ static __devinit int palmas_probe(struct platform_device *pdev)
                if (pdata && pdata->reg_init) {
                        reg_init = pdata->reg_init[id];
                        if (reg_init) {
+                               pmic->roof_floor[id] = reg_init->roof_floor;
                                ret = palmas_smps_init(palmas, id, reg_init);
                                if (ret)
                                        goto err_unregister_regulator;
@@ -1463,6 +1506,7 @@ static __devinit int palmas_probe(struct platform_device *pdev)
                if (pdata->reg_init) {
                        reg_init = pdata->reg_init[id];
                        if (reg_init) {
+                               pmic->roof_floor[id] = reg_init->roof_floor;
                                if (id < PALMAS_REG_REGEN1)
                                        ret = palmas_ldo_init(palmas, id,
                                                                reg_init);
index 43e3fa9..db06ebd 100644 (file)
@@ -309,6 +309,7 @@ struct palmas_pmic {
        unsigned int current_mode_reg[PALMAS_NUM_REGS];
 
        int range[PALMAS_REG_SMPS10];
+       unsigned long roof_floor[PALMAS_NUM_REGS];
 };
 
 /* defines so we can store the mux settings */