All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] regulator: Don't increment use_count for boot_on regulators
@ 2009-03-16 19:36 Mark Brown
  2009-03-16 19:36 ` [PATCH 2/2] regulator: Support disabling of unused regulators by machines Mark Brown
  2009-03-19 18:09 ` [PATCH 1/2] regulator: Don't increment use_count for boot_on regulators Liam Girdwood
  0 siblings, 2 replies; 4+ messages in thread
From: Mark Brown @ 2009-03-16 19:36 UTC (permalink / raw)
  To: Liam Girdwood; +Cc: linux-kernel, Mark Brown

Don't set use_count for regulators that are enabled at boot since this
stops the supply being disabled by well-behaved consumers which do
balanced enables and disabled. Any consumers which don't do disables
which are not matched by enables are unable to share regulators - shared
regulators are the common case so the API should facilitate them.

Consumers that want to disable regulators that are enabled when they
start have two options:

 - Do a regulator_enable() prior to the disable to bring the use count
   in sync with the hardware state; this will ensure that if the
   regulator was enabled by another driver then this consumer will play
   nicely with it.
 - Use regulator_force_disable(); this explicitly bypasses any checks
   done by the core and documents the inability of the driver to share
   the supply.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
 drivers/regulator/core.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 9448875..8588a24 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -814,7 +814,6 @@ static int set_machine_constraints(struct regulator_dev *rdev,
 			rdev->constraints = NULL;
 			goto out;
 		}
-		rdev->use_count = 1;
 	}
 
 	print_constraints(rdev);
-- 
1.6.2


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

* [PATCH 2/2] regulator: Support disabling of unused regulators by machines
  2009-03-16 19:36 [PATCH 1/2] regulator: Don't increment use_count for boot_on regulators Mark Brown
@ 2009-03-16 19:36 ` Mark Brown
  2009-03-19 18:09   ` Liam Girdwood
  2009-03-19 18:09 ` [PATCH 1/2] regulator: Don't increment use_count for boot_on regulators Liam Girdwood
  1 sibling, 1 reply; 4+ messages in thread
From: Mark Brown @ 2009-03-16 19:36 UTC (permalink / raw)
  To: Liam Girdwood; +Cc: linux-kernel, Mark Brown

At present it is not possible for machine constraints to disable
regulators which have been left on when the system starts, for example
as a result of fixed default configurations in hardware. This means that
power may be wasted by these regulators if they are not in use.

Provide intial support for this with a late_initcall which will disable
any unused regulators if the machine has enabled this feature by calling
regulator_has_full_constraints(). If this has not been called then print
a warning to encourage users to fully specify their constraints so that
we can change this to be the default behaviour in future.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
 drivers/regulator/core.c          |   92 +++++++++++++++++++++++++++++++++++++
 include/linux/regulator/machine.h |    2 +
 2 files changed, 94 insertions(+), 0 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 8588a24..01f7702 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -28,6 +28,7 @@
 static DEFINE_MUTEX(regulator_list_mutex);
 static LIST_HEAD(regulator_list);
 static LIST_HEAD(regulator_map_list);
+static int has_full_constraints;
 
 /*
  * struct regulator_map
@@ -2143,6 +2144,23 @@ out:
 EXPORT_SYMBOL_GPL(regulator_suspend_prepare);
 
 /**
+ * regulator_has_full_constraints - the system has fully specified constraints
+ *
+ * Calling this function will cause the regulator API to disable all
+ * regulators which have a zero use count and don't have an always_on
+ * constraint in a late_initcall.
+ *
+ * The intention is that this will become the default behaviour in a
+ * future kernel release so users are encouraged to use this facility
+ * now.
+ */
+void regulator_has_full_constraints(void)
+{
+	has_full_constraints = 1;
+}
+EXPORT_SYMBOL_GPL(regulator_has_full_constraints);
+
+/**
  * rdev_get_drvdata - get rdev regulator driver data
  * @rdev: regulator
  *
@@ -2209,3 +2227,77 @@ static int __init regulator_init(void)
 
 /* init early to allow our consumers to complete system booting */
 core_initcall(regulator_init);
+
+static int __init regulator_init_complete(void)
+{
+	struct regulator_dev *rdev;
+	struct regulator_ops *ops;
+	struct regulation_constraints *c;
+	int enabled, ret;
+	const char *name;
+
+	mutex_lock(&regulator_list_mutex);
+
+	/* If we have a full configuration then disable any regulators
+	 * which are not in use or always_on.  This will become the
+	 * default behaviour in the future.
+	 */
+	list_for_each_entry(rdev, &regulator_list, list) {
+		ops = rdev->desc->ops;
+		c = rdev->constraints;
+
+		if (c->name)
+			name = c->name;
+		else if (rdev->desc->name)
+			name = rdev->desc->name;
+		else
+			name = "regulator";
+
+		if (!ops->disable || c->always_on)
+			continue;
+
+		mutex_lock(&rdev->mutex);
+
+		if (rdev->use_count)
+			goto unlock;
+
+		/* If we can't read the status assume it's on. */
+		if (ops->is_enabled)
+			enabled = ops->is_enabled(rdev);
+		else
+			enabled = 1;
+
+		if (!enabled)
+			goto unlock;
+
+		if (has_full_constraints) {
+			/* We log since this may kill the system if it
+			 * goes wrong. */
+			printk(KERN_INFO "%s: disabling %s\n",
+			       __func__, name);
+			ret = ops->disable(rdev);
+			if (ret != 0) {
+				printk(KERN_ERR
+				       "%s: couldn't disable %s: %d\n",
+				       __func__, name, ret);
+			}
+		} else {
+			/* The intention is that in future we will
+			 * assume that full constraints are provided
+			 * so warn even if we aren't going to do
+			 * anything here.
+			 */
+			printk(KERN_WARNING
+			       "%s: incomplete constraints, leaving %s on\n",
+			       __func__, name);
+		}
+
+unlock:
+		mutex_unlock(&rdev->mutex);
+	}
+
+	mutex_unlock(&regulator_list_mutex);
+
+	return 0;
+}
+late_initcall(regulator_init_complete);
diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h
index 5de7aa3..bac64fa 100644
--- a/include/linux/regulator/machine.h
+++ b/include/linux/regulator/machine.h
@@ -166,4 +166,6 @@ struct regulator_init_data {
 
 int regulator_suspend_prepare(suspend_state_t state);
 
+void regulator_has_full_constraints(void);
+
 #endif
-- 
1.6.2


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

* Re: [PATCH 1/2] regulator: Don't increment use_count for boot_on regulators
  2009-03-16 19:36 [PATCH 1/2] regulator: Don't increment use_count for boot_on regulators Mark Brown
  2009-03-16 19:36 ` [PATCH 2/2] regulator: Support disabling of unused regulators by machines Mark Brown
@ 2009-03-19 18:09 ` Liam Girdwood
  1 sibling, 0 replies; 4+ messages in thread
From: Liam Girdwood @ 2009-03-19 18:09 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-kernel

On Mon, 2009-03-16 at 19:36 +0000, Mark Brown wrote:
> Don't set use_count for regulators that are enabled at boot since this
> stops the supply being disabled by well-behaved consumers which do
> balanced enables and disabled. Any consumers which don't do disables
> which are not matched by enables are unable to share regulators - shared
> regulators are the common case so the API should facilitate them.
> 
> Consumers that want to disable regulators that are enabled when they
> start have two options:
> 
>  - Do a regulator_enable() prior to the disable to bring the use count
>    in sync with the hardware state; this will ensure that if the
>    regulator was enabled by another driver then this consumer will play
>    nicely with it.
>  - Use regulator_force_disable(); this explicitly bypasses any checks
>    done by the core and documents the inability of the driver to share
>    the supply.
> 
> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
> ---
>  drivers/regulator/core.c |    1 -
>  1 files changed, 0 insertions(+), 1 deletions(-)

Applied.

Thanks

Liam


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

* Re: [PATCH 2/2] regulator: Support disabling of unused regulators by machines
  2009-03-16 19:36 ` [PATCH 2/2] regulator: Support disabling of unused regulators by machines Mark Brown
@ 2009-03-19 18:09   ` Liam Girdwood
  0 siblings, 0 replies; 4+ messages in thread
From: Liam Girdwood @ 2009-03-19 18:09 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-kernel

On Mon, 2009-03-16 at 19:36 +0000, Mark Brown wrote:
> At present it is not possible for machine constraints to disable
> regulators which have been left on when the system starts, for example
> as a result of fixed default configurations in hardware. This means that
> power may be wasted by these regulators if they are not in use.
> 
> Provide intial support for this with a late_initcall which will disable
> any unused regulators if the machine has enabled this feature by calling
> regulator_has_full_constraints(). If this has not been called then print
> a warning to encourage users to fully specify their constraints so that
> we can change this to be the default behaviour in future.
> 
> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
> ---
>  drivers/regulator/core.c          |   92 +++++++++++++++++++++++++++++++++++++
>  include/linux/regulator/machine.h |    2 +
>  2 files changed, 94 insertions(+), 0 deletions(-)
> 

Applied.

Thanks

Liam


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

end of thread, other threads:[~2009-03-19 18:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-16 19:36 [PATCH 1/2] regulator: Don't increment use_count for boot_on regulators Mark Brown
2009-03-16 19:36 ` [PATCH 2/2] regulator: Support disabling of unused regulators by machines Mark Brown
2009-03-19 18:09   ` Liam Girdwood
2009-03-19 18:09 ` [PATCH 1/2] regulator: Don't increment use_count for boot_on regulators Liam Girdwood

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.