* [PATCH] regulator: core: set current constraints while setting machine constraints
@ 2013-09-19 14:46 Laxman Dewangan
2013-09-19 14:50 ` Mark Brown
0 siblings, 1 reply; 2+ messages in thread
From: Laxman Dewangan @ 2013-09-19 14:46 UTC (permalink / raw)
To: broonie; +Cc: lgirdwood, linux-kernel, swarren, Laxman Dewangan
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>
---
drivers/regulator/core.c | 38 ++++++++++++++++++++++++++++++++++++++
1 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index b698e2b..617e337 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -904,6 +904,40 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
return 0;
}
+static int machine_constraints_current(struct regulator_dev *rdev,
+ struct regulation_constraints *constraints)
+{
+ int current_uA;
+ int ret;
+
+ if (!rdev->desc->ops->set_current_limit ||
+ !rdev->desc->ops->get_current_limit)
+ return 0;
+
+ if (!rdev->constraints->min_uA && !rdev->constraints->max_uA)
+ return 0;
+
+ if (rdev->constraints->min_uA > rdev->constraints->max_uA) {
+ rdev_err(rdev, "Current constraint is invalid\n");
+ return -EINVAL;
+ }
+
+ /* Set regulator current in constraint range */
+ current_uA = rdev->desc->ops->get_current_limit(rdev);
+ if (current_uA < rdev->constraints->min_uA ||
+ current_uA > rdev->constraints->max_uA) {
+ ret = rdev->desc->ops->set_current_limit(rdev,
+ rdev->constraints->min_uA,
+ rdev->constraints->max_uA);
+ if (ret < 0) {
+ rdev_err(rdev,
+ "Failed to set current constraint, %d\n", ret);
+ return ret;
+ }
+ }
+ return 0;
+}
+
/**
* set_machine_constraints - sets regulator constraints
* @rdev: regulator source
@@ -934,6 +968,10 @@ static int set_machine_constraints(struct regulator_dev *rdev,
if (ret != 0)
goto out;
+ ret = machine_constraints_current(rdev, rdev->constraints);
+ if (ret != 0)
+ goto out;
+
/* do we need to setup our suspend state */
if (rdev->constraints->initial_state) {
ret = suspend_prepare(rdev, rdev->constraints->initial_state);
--
1.7.1.1
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] regulator: core: set current constraints while setting machine constraints
2013-09-19 14:46 [PATCH] regulator: core: set current constraints while setting machine constraints Laxman Dewangan
@ 2013-09-19 14:50 ` Mark Brown
0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2013-09-19 14:50 UTC (permalink / raw)
To: Laxman Dewangan; +Cc: lgirdwood, linux-kernel, swarren
[-- Attachment #1: Type: text/plain, Size: 920 bytes --]
On Thu, Sep 19, 2013 at 08:16:28PM +0530, Laxman Dewangan wrote:
> + if (!rdev->desc->ops->set_current_limit ||
> + !rdev->desc->ops->get_current_limit)
> + return 0;
> +
The indentation here is odd and we probably ought to complain if someone
tries to set a current constarint on a regulator that doesn't support
the operation, if only to avoid surprises later on when the limits don't
take effect.
> + current_uA = rdev->desc->ops->get_current_limit(rdev);
> + if (current_uA < rdev->constraints->min_uA ||
> + current_uA > rdev->constraints->max_uA) {
> + ret = rdev->desc->ops->set_current_limit(rdev,
> + rdev->constraints->min_uA,
> + rdev->constraints->max_uA);
> + if (ret < 0) {
> + rdev_err(rdev,
> + "Failed to set current constraint, %d\n", ret);
> + return ret;
> + }
Why is this conditional on the existing setting? Just apply the
constraint.
> + }
> + return 0;
Missing blank.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-09-19 14:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-19 14:46 [PATCH] regulator: core: set current constraints while setting machine constraints Laxman Dewangan
2013-09-19 14:50 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®