public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@cam.ac.uk>
To: Liam Girdwood <lrg@slimlogic.co.uk>
Cc: LKML <linux-kernel@vger.kernel.org>, broonie@opensource.wolfsonmicro.com
Subject: [RFC] Regulator: Add a voltage changed event to notify consumers
Date: Sun, 18 Jan 2009 18:47:25 +0000	[thread overview]
Message-ID: <4973793D.60803@cam.ac.uk> (raw)
In-Reply-To: <1231065078.11643.116.camel@vega.slimlogic.co.uk>

From: Jonathan Cameron <jic23@cam.ac.uk>
Regulator: Add a voltage changed event to notify consumers
that care when another device changes the regulator voltage.

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
If people are happy with this I'll post a follow up to update the
documentation to reflect this additional event.

This is pretty simple and very similar to the way the forced
disable event is handled. 

Worth noting is that (along with other events) the notifier
blocks are called with the regulator's lock held so any
attempt by consumers to update their voltage must be done
via a scheduled update call rather than within the callback
it self. The documentation will emphasize this.

Example of usage is the sht15 driver posted to lm-sensors where
the temperature measurement is dependent on the supply voltage
and hence needs to know if this has changed.

 drivers/regulator/core.c           |   10 ++++++----
 include/linux/regulator/consumer.h |    2 ++
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index f511a40..9fec166 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1231,18 +1231,20 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
 	/* sanity check */
 	if (!rdev->desc->ops->set_voltage) {
 		ret = -EINVAL;
-		goto out;
+		goto out_unlock;
 	}
 
 	/* constraints check */
 	ret = regulator_check_voltage(rdev, &min_uV, &max_uV);
 	if (ret < 0)
-		goto out;
+		goto out_unlock;
 	regulator->min_uV = min_uV;
 	regulator->max_uV = max_uV;
 	ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV);
-
-out:
+	mutex_unlock(&rdev->mutex);
+	_notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE, NULL);
+	return 0;
+out_unlock:
 	mutex_unlock(&rdev->mutex);
 	return ret;
 }
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index 801bf77..6107a70 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -88,6 +88,7 @@
  * FAIL           Regulator output has failed.
  * OVER_TEMP      Regulator over temp.
  * FORCE_DISABLE  Regulator shut down by software.
+ * VOLTAGE_CHANGE Regulator voltage changed.	
  *
  * NOTE: These events can be OR'ed together when passed into handler.
  */
@@ -98,6 +99,7 @@
 #define REGULATOR_EVENT_FAIL			0x08
 #define REGULATOR_EVENT_OVER_TEMP		0x10
 #define REGULATOR_EVENT_FORCE_DISABLE		0x20
+#define REGULATOR_EVENT_VOLTAGE_CHANGE		0x40
 
 struct regulator;
 

  reply	other threads:[~2009-01-18 18:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-03 21:11 [RFC] Regulator: Possibility of passing notifications of non alarm events Jonathan Cameron
2009-01-04 10:31 ` Liam Girdwood
2009-01-18 18:47   ` Jonathan Cameron [this message]
2009-01-19 15:29     ` [RFC] Regulator: Add a voltage changed event to notify consumers Mark Brown
2009-01-19 16:57       ` Jonathan Cameron
2009-01-19 18:08         ` Jonathan Cameron
2009-01-19 18:20           ` [RFC] Regulator: Push lock out of _notifier_call_chain + add voltage change event Jonathan Cameron
2009-01-20 20:09             ` Liam Girdwood

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=4973793D.60803@cam.ac.uk \
    --to=jic23@cam.ac.uk \
    --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