aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaxman Dewangan <ldewangan@nvidia.com>2013-09-20 03:43:02 -0400
committerMark Brown <broonie@linaro.org>2013-09-20 05:50:29 -0400
commitf8c1700dd7d2ce9b2238b20d364317b2968ac76b (patch)
tree6d42ffb2f3e7e9bee181e70745b7ee5e034874d2
parent00c877c69ba315d6c565a4df51c71b11e82cdeb8 (diff)
regulator: core: set current constraints while setting machine constraints
Machine constraints is configured during regulator register. If current constraints are provided through machine constraints then it is observed that sometime the current configured on rail is out of range what machine constraint has. Set the current constraints when setting machine constraints to make sure that rail's current is within the range of given machine constraints. Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com> Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r--drivers/regulator/core.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 5217c1964c32..66ae12d12c10 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -923,6 +923,36 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
923 return 0; 923 return 0;
924} 924}
925 925
926static int machine_constraints_current(struct regulator_dev *rdev,
927 struct regulation_constraints *constraints)
928{
929 struct regulator_ops *ops = rdev->desc->ops;
930 int ret;
931
932 if (!constraints->min_uA && !constraints->max_uA)
933 return 0;
934
935 if (constraints->min_uA > constraints->max_uA) {
936 rdev_err(rdev, "Invalid current constraints\n");
937 return -EINVAL;
938 }
939
940 if (!ops->set_current_limit || !ops->get_current_limit) {
941 rdev_warn(rdev, "Operation of current configuration missing\n");
942 return 0;
943 }
944
945 /* Set regulator current in constraints range */
946 ret = ops->set_current_limit(rdev, constraints->min_uA,
947 constraints->max_uA);
948 if (ret < 0) {
949 rdev_err(rdev, "Failed to set current constraint, %d\n", ret);
950 return ret;
951 }
952
953 return 0;
954}
955
926/** 956/**
927 * set_machine_constraints - sets regulator constraints 957 * set_machine_constraints - sets regulator constraints
928 * @rdev: regulator source 958 * @rdev: regulator source
@@ -953,6 +983,10 @@ static int set_machine_constraints(struct regulator_dev *rdev,
953 if (ret != 0) 983 if (ret != 0)
954 goto out; 984 goto out;
955 985
986 ret = machine_constraints_current(rdev, rdev->constraints);
987 if (ret != 0)
988 goto out;
989
956 /* do we need to setup our suspend state */ 990 /* do we need to setup our suspend state */
957 if (rdev->constraints->initial_state) { 991 if (rdev->constraints->initial_state) {
958 ret = suspend_prepare(rdev, rdev->constraints->initial_state); 992 ret = suspend_prepare(rdev, rdev->constraints->initial_state);