All of lore.kernel.org
 help / color / mirror / Atom feed
* regulator: multiple consumers requirements
@ 2010-12-03 10:31 Thomas Petazzoni
  2010-12-03 10:31 ` [PATCH] regulator: Take into account the requirements of all consumers Thomas Petazzoni
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Petazzoni @ 2010-12-03 10:31 UTC (permalink / raw)
  To: linux-pm

Hello,

The following patch slightly extends the semantic of
regulator_set_voltage() so that it takes into account the voltage
requirements of all consumers connected to that regulator. This change
would allow the OMAP ARM architecture to use the regulator framework
more aggressively: we have multiple devices connected to a single
regulator, and the voltage needs to be set to the minimum voltage
acceptable by all consumers.

Thanks,

Thomas

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

* [PATCH] regulator: Take into account the requirements of all consumers
  2010-12-03 10:31 regulator: multiple consumers requirements Thomas Petazzoni
@ 2010-12-03 10:31 ` Thomas Petazzoni
  2010-12-03 11:09   ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Petazzoni @ 2010-12-03 10:31 UTC (permalink / raw)
  To: linux-pm; +Cc: Thomas Petazzoni, Mark Brown, Liam Girdwood

From: Thomas Petazzoni <t-petazzoni@ti.com>

Extend the regulator_set_voltage() function to take into account the
voltage requirements of all consumers of the regulator being changed,
in order to set the voltage to the minimum voltage acceptable to all
consumers. The existing behaviour was that the latest
regulator_set_voltage() call would win over previous
regulator_set_voltage() calls even if setting the voltage to a
non-acceptable level from other consumers.

Signed-off-by: Thomas Petazzoni <t-petazzoni@ti.com>
Cc: Liam Girdwood <lrg@slimlogic.co.uk>
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: Kevin Hilman <khilman@deeprootsystems.com>
---
 drivers/regulator/core.c |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index f1d10c9..12a1cae 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -132,6 +132,28 @@ static int regulator_check_voltage(struct regulator_dev *rdev,
 	return 0;
 }
 
+/* Make sure we select a voltage that suits the needs of all
+ * regulator consumers
+ */
+static int regulator_check_consumers(struct regulator_dev *rdev,
+				     int *min_uV, int *max_uV)
+{
+	struct regulator *regulator;
+
+	list_for_each_entry(regulator, &rdev->consumer_list, list)
+	{
+		if (*max_uV > regulator->max_uV)
+			*max_uV = regulator->max_uV;
+		if (*min_uV < regulator->min_uV)
+			*min_uV = regulator->min_uV;
+	}
+
+	if (*min_uV > *max_uV)
+		return -EINVAL;
+
+	return 0;
+}
+
 /* current constraint check */
 static int regulator_check_current_limit(struct regulator_dev *rdev,
 					int *min_uA, int *max_uA)
@@ -1636,6 +1658,11 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
 		goto out;
 	regulator->min_uV = min_uV;
 	regulator->max_uV = max_uV;
+
+	ret = regulator_check_consumers(rdev, &min_uV, &max_uV);
+	if (ret < 0)
+		goto out;
+
 	ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV);
 
 out:
-- 
1.7.0.4

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

* Re: [PATCH] regulator: Take into account the requirements of all consumers
  2010-12-03 10:31 ` [PATCH] regulator: Take into account the requirements of all consumers Thomas Petazzoni
@ 2010-12-03 11:09   ` Mark Brown
  2010-12-03 18:12     ` Liam Girdwood
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Brown @ 2010-12-03 11:09 UTC (permalink / raw)
  To: Thomas Petazzoni; +Cc: linux-pm, Thomas Petazzoni, Liam Girdwood

On Fri, Dec 03, 2010 at 11:31:07AM +0100, Thomas Petazzoni wrote:

> Extend the regulator_set_voltage() function to take into account the
> voltage requirements of all consumers of the regulator being changed,

Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>

Style nit:

> +	list_for_each_entry(regulator, &rdev->consumer_list, list)
> +	{

The { should be on the previous line.

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

* Re: [PATCH] regulator: Take into account the requirements of all consumers
  2010-12-03 11:09   ` Mark Brown
@ 2010-12-03 18:12     ` Liam Girdwood
  0 siblings, 0 replies; 4+ messages in thread
From: Liam Girdwood @ 2010-12-03 18:12 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-pm, Thomas Petazzoni

On Fri, 2010-12-03 at 11:09 +0000, Mark Brown wrote:
> On Fri, Dec 03, 2010 at 11:31:07AM +0100, Thomas Petazzoni wrote:
> 
> > Extend the regulator_set_voltage() function to take into account the
> > voltage requirements of all consumers of the regulator being changed,
> 
> Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
> 
> Style nit:
> 
> > +	list_for_each_entry(regulator, &rdev->consumer_list, list)
> > +	{
> 
> The { should be on the previous line.

Applied and fixed the style.

Thanks

Liam
-- 
Freelance Developer, SlimLogic Ltd
ASoC and Voltage Regulator Maintainer.
http://www.slimlogic.co.uk

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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-03 10:31 regulator: multiple consumers requirements Thomas Petazzoni
2010-12-03 10:31 ` [PATCH] regulator: Take into account the requirements of all consumers Thomas Petazzoni
2010-12-03 11:09   ` Mark Brown
2010-12-03 18:12     ` 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.