All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@cam.ac.uk>
To: Liam Girdwood <lrg@kernel.org>
Cc: Jonathan Cameron <Jonathan.Cameron@gmail.com>,
	Mark Brown <broonie@sirena.org.uk>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: regulator: Add disable_on_boot flag to constraints.
Date: Wed, 21 Jan 2009 14:44:35 +0000	[thread overview]
Message-ID: <497734D3.4090207@cam.ac.uk> (raw)
In-Reply-To: <1232482483.16911.299.camel@vega.slimlogic.co.uk>

From: Jonathan Cameron <jic23@cam.ac.uk>

regulator: Add disable_on_boot flag to constraints.

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
Now based on voltage / for-next and with kernel doc
added.

Not quite sure what trashed the previous patch, but
hopefully this one should work.

Changes in response to Mark Browns comments.

Patch changed to disable_on_boot for more flexibility.
This only really involved removing the check in the enable code
found in the previous patch.

This is intended to allow the disabling of regulators during
registration.  Typical use case is regulators that aren't
actually connected to anything.

This is against a clean voltage for-next with Mark's 
hoisting of struct regulator_dev patch applied. (not that
it materially changes this patch).

 drivers/regulator/core.c          |   19 ++++++++++++++++++-
 include/linux/regulator/machine.h |    9 ++++++---
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 0ed13c2..ea7caaf 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -723,7 +723,14 @@ static int set_machine_constraints(struct regulator_dev *rdev,
 			goto out;
 		}
 	}
-
+	/* Sanity check */
+	if (constraints->always_on && constraints->disable_on_boot) {
+		printk(KERN_ERR "%s: always on and disable at boot both set for %s\n",
+		       __func__, name);
+		rdev->constraints = NULL;
+		ret = -EINVAL;
+		goto out;
+	}
 	/* if always_on is set then turn the regulator on if it's not
 	 * already on. */
 	if (constraints->always_on && ops->enable &&
@@ -736,6 +743,16 @@ static int set_machine_constraints(struct regulator_dev *rdev,
 			rdev->constraints = NULL;
 			goto out;
 		}
+	} else if (constraints->disable_on_boot && ops->disable &&
+		   ((ops->is_enabled && ops->is_enabled(rdev)) ||
+		    (!ops->is_enabled && constraints->boot_on))) {
+		ret = ops->disable(rdev);
+		if (ret < 0) {
+			printk(KERN_ERR "%s: failed to disable %s\n",
+			       __func__, name);
+			rdev->constraints = NULL;
+			goto out;
+		}
 	}
 
 	print_constraints(rdev);
diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h
index 3794773..f7d01dd 100644
--- a/include/linux/regulator/machine.h
+++ b/include/linux/regulator/machine.h
@@ -74,6 +74,8 @@ struct regulator_state {
  * @always_on: Set if the regulator should never be disabled.
  * @boot_on: Set if the regulator is enabled when the system is initially
  *           started.
+ * @disable_on_boot: Set if the regulator should be disabled. Typically
+ *                   for regulators that are not connected.
  * @apply_uV: Apply the voltage constraint when initialising.
  *
  * @input_uV: Input voltage for regulator when supplied by another regulator.
@@ -112,9 +114,10 @@ struct regulation_constraints {
 	suspend_state_t initial_state; /* suspend state to set at init */
 
 	/* constriant flags */
-	unsigned always_on:1;	/* regulator never off when system is on */
-	unsigned boot_on:1;	/* bootloader/firmware enabled regulator */
-	unsigned apply_uV:1;	/* apply uV constraint iff min == max */
+	unsigned always_on:1;		/* regulator never off when system on */
+	unsigned boot_on:1;		/* bootloader/firmware enabled reg */
+	unsigned disable_on_boot:1;	/* regulator to be disabled at boot */
+	unsigned apply_uV:1;		/* apply uV constraint iff min == max */
 };
 
 /**

  reply	other threads:[~2009-01-21 14:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-20 12:07 regulator: Add always off to constraints Jonathan Cameron
2009-01-20 12:43 ` Mark Brown
2009-01-20 13:00   ` Jonathan Cameron
2009-01-20 13:19     ` regulator: Add disable_on_boot flag " Jonathan Cameron
2009-01-20 20:14       ` Liam Girdwood
2009-01-21 14:44         ` Jonathan Cameron [this message]
2009-03-29 19:25           ` Jonathan Cameron
2009-03-30  9:52             ` Mark Brown
2009-03-31 10:55               ` Mark Brown
2009-01-20 20:25       ` 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=497734D3.4090207@cam.ac.uk \
    --to=jic23@cam.ac.uk \
    --cc=Jonathan.Cameron@gmail.com \
    --cc=broonie@sirena.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lrg@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.