mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Laxman Dewangan <ldewangan@nvidia.com>
To: <broonie@kernel.org>
Cc: <lgirdwood@gmail.com>, <linux-kernel@vger.kernel.org>,
	<swarren@nvidia.com>, Laxman Dewangan <ldewangan@nvidia.com>
Subject: [PATCH] regulator: core: set current constraints while setting machine constraints
Date: Thu, 19 Sep 2013 20:16:28 +0530	[thread overview]
Message-ID: <1379601988-25839-1-git-send-email-ldewangan@nvidia.com> (raw)

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


             reply	other threads:[~2013-09-19 14:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-19 14:46 Laxman Dewangan [this message]
2013-09-19 14:50 ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1379601988-25839-1-git-send-email-ldewangan@nvidia.com \
    --to=ldewangan@nvidia.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=swarren@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®