public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [patch 2.6.28-rc3] regulator: add REGULATOR_MODE_OFF
@ 2008-11-09 23:31 David Brownell
  2008-11-10 13:14 ` Liam Girdwood
  0 siblings, 1 reply; 30+ messages in thread
From: David Brownell @ 2008-11-09 23:31 UTC (permalink / raw)
  To: broonie, lrg; +Cc: lkml

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.

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2009-01-16  1:09 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-09 23:31 [patch 2.6.28-rc3] regulator: add REGULATOR_MODE_OFF David Brownell
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox