mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Brownell <david-b@pacbell.net>
To: broonie@opensource.wolfsonmicro.com, lrg@slimlogic.co.uk
Cc: lkml <linux-kernel@vger.kernel.org>
Subject: [patch 2.6.28-rc3] regulator: add REGULATOR_MODE_OFF
Date: Sun, 9 Nov 2008 15:31:45 -0800	[thread overview]
Message-ID: <200811091531.46003.david-b@pacbell.net> (raw)

From: David Brownell <dbrownell@users.sourceforge.net>

The regulator framework needs to expose an OFF mode for regulators
with a single state machine.  Example:  TWL4030 regulators each
have a status register exposing the current mode, which will be
either ACTIVE, STANDBY, or OFF.  But regulator_ops.get_mode()
currently has no way to report that third (OFF) mode.

Add such an OFF mode, reporting it in the standard ways.

In the spirit of the existing interface, disable() operations are
still used to enter this mode:

 - regulator_set_mode() rejects it; drivers doing runtime power
   management must use regulator_disable().

 - the PM_SUSPEND_* notifier goes down the set_suspend_disable()
   path, not requiring set_suspend_mode() to handle OFF mode.

This doesn't address any other enable/disable issues... like the
way regulator_disable() clobbers state even on failure paths, or
refcounting isssues (e.g. two clients enable, one disables, then
the regulator should stay active.)

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
---
 drivers/regulator/core.c           |   16 +++++++++++++---
 include/linux/regulator/consumer.h |    4 ++++
 2 files changed, 17 insertions(+), 3 deletions(-)

--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -272,6 +272,8 @@ static ssize_t regulator_opmode_show(str
 		return sprintf(buf, "idle\n");
 	case REGULATOR_MODE_STANDBY:
 		return sprintf(buf, "standby\n");
+	case REGULATOR_MODE_OFF:
+		return sprintf(buf, "off\n");
 	}
 	return sprintf(buf, "unknown\n");
 }
@@ -411,6 +413,8 @@ static ssize_t suspend_opmode_show(struc
 		return sprintf(buf, "idle\n");
 	case REGULATOR_MODE_STANDBY:
 		return sprintf(buf, "standby\n");
+	case REGULATOR_MODE_OFF:
+		return sprintf(buf, "off\n");
 	}
 	return sprintf(buf, "unknown\n");
 }
@@ -589,7 +593,7 @@ static int suspend_set_state(struct regu
 		return -EINVAL;
 	}
 
-	if (rstate->enabled)
+	if (rstate->enabled && rstate->mode != REGULATOR_MODE_OFF)
 		ret = rdev->desc->ops->set_suspend_enable(rdev);
 	else
 		ret = rdev->desc->ops->set_suspend_disable(rdev);
@@ -668,7 +672,9 @@ static void print_constraints(struct reg
 	if (constraints->valid_modes_mask & REGULATOR_MODE_IDLE)
 		count += sprintf(buf + count, "idle ");
 	if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY)
-		count += sprintf(buf + count, "standby");
+		count += sprintf(buf + count, "standby ");
+	if (constraints->valid_modes_mask & REGULATOR_MODE_OFF)
+		count += sprintf(buf + count, "off ");
 
 	printk(KERN_INFO "regulator: %s: %s\n", rdev->desc->name, buf);
 }
@@ -1362,7 +1368,8 @@ EXPORT_SYMBOL_GPL(regulator_get_current_
  * @mode: operating mode - one of the REGULATOR_MODE constants
  *
  * Set regulator operating mode to increase regulator efficiency or improve
- * regulation performance.
+ * regulation performance.  You may not pass REGULATOR_MODE_OFF; to achieve
+ * that effect, call regulator_disable().
  *
  * NOTE: Regulator system constraints must be set for this regulator before
  * calling this function otherwise this call will fail.
@@ -1372,6 +1379,9 @@ int regulator_set_mode(struct regulator 
 	struct regulator_dev *rdev = regulator->rdev;
 	int ret;
 
+	if (mode == REGULATOR_MODE_OFF)
+		return -EINVAL;
+
 	mutex_lock(&rdev->mutex);
 
 	/* sanity check */
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -68,6 +68,9 @@
  *             the most noisy and may not be able to handle fast load
  *             switching.
  *
+ *  OFF        Regulator is disabled.  This mode may be observed from
+ *             some hardware after invoking disable() primitives.
+ *
  * NOTE: Most regulators will only support a subset of these modes. Some
  * will only just support NORMAL.
  *
@@ -78,6 +81,7 @@
 #define REGULATOR_MODE_NORMAL			0x2
 #define REGULATOR_MODE_IDLE			0x4
 #define REGULATOR_MODE_STANDBY			0x8
+#define REGULATOR_MODE_OFF			0x10
 
 /*
  * Regulator notifier events.

             reply	other threads:[~2008-11-09 23:31 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-09 23:31 David Brownell [this message]
2008-11-10 13:14 ` Liam Girdwood
2008-11-10 15:43   ` David Brownell
2008-11-10 16:56     ` Mark Brown
2008-11-11  4:56       ` David Brownell
2008-11-12 11:25         ` Mark Brown
2008-11-12 21:42           ` David Brownell
2008-11-12 23:09             ` Mark Brown
2008-11-12 22:23           ` Liam Girdwood
2008-11-13  0:00             ` David Brownell
2008-11-13 19:40           ` David Brownell
2008-11-13 21:53             ` Mark Brown
2008-11-15  1:15               ` David Brownell
2008-11-15  4:37                 ` Mark Brown
2008-11-16 20:28                   ` David Brownell
2008-11-16 22:58                   ` David Brownell
2008-11-17  1:51                     ` Mark Brown
2009-01-15  7:03                       ` David Brownell
2009-01-15 12:29                         ` Mark Brown
2009-01-15 22:32                           ` David Brownell
2009-01-16  1:08                             ` Mark Brown
2009-01-15  7:03                       ` [patch 2.6.29-rc] regulator: add get_status() David Brownell
2009-01-15 12:04                         ` Liam Girdwood
2009-01-15 12:40                         ` Mark Brown
2009-01-15 12:50                           ` Liam Girdwood
2009-01-15 15:35                             ` David Brownell
2009-01-15 16:05                               ` Mark Brown
2009-01-15 16:54                                 ` David Brownell
2009-01-15 18:11                             ` David Brownell
2009-01-15 18:24                               ` 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=200811091531.46003.david-b@pacbell.net \
    --to=david-b@pacbell.net \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lrg@slimlogic.co.uk \
    /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

Powered by JetHome