linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Mark Brown <broonie@kernel.org>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
	linux-kernel@vger.kernel.org,
	Bjorn Andersson <bjorn.andersson@sonymobile.com>
Subject: [PATCH 4/4] regulator: core: make bulk API support optional supplies
Date: Fri,  3 Feb 2017 15:16:19 -0800	[thread overview]
Message-ID: <20170203231619.8013-4-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20170203231619.8013-1-dmitry.torokhov@gmail.com>

Make it possible to use the bulk API with optional supplies, by allowing
the consumer to marking supplies as optional in the regulator_bulk_data.

Based on earlier patch by Bjorn Andersson <bjorn.andersson@sonymobile.com>

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/regulator/core.c           | 41 ++++++++++++++++++++++++--------------
 include/linux/regulator/consumer.h |  3 +++
 2 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 9eb2e04f1219..540d1dec6e06 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -3546,20 +3546,22 @@ static int _notifier_call_chain(struct regulator_dev *rdev,
 int regulator_bulk_get(struct device *dev, int num_consumers,
 		       struct regulator_bulk_data *consumers)
 {
+	struct regulator *r;
 	int i;
 	int ret;
 
-	for (i = 0; i < num_consumers; i++)
-		consumers[i].consumer = NULL;
-
 	for (i = 0; i < num_consumers; i++) {
-		consumers[i].consumer = regulator_get(dev,
-						      consumers[i].supply);
-		if (IS_ERR(consumers[i].consumer)) {
-			ret = PTR_ERR(consumers[i].consumer);
+		r = _regulator_get(dev, consumers[i].supply,
+				   consumers[i].optional ?
+					OPTIONAL_GET : NORMAL_GET);
+		ret = PTR_ERR_OR_ZERO(r);
+		if (!ret) {
+			consumers[i].consumer = r;
+		} else if (ret == -ENODEV && consumers[i].optional) {
+			consumers[i].consumer = NULL;
+		} else {
 			dev_err(dev, "Failed to get supply '%s': %d\n",
 				consumers[i].supply, ret);
-			consumers[i].consumer = NULL;
 			goto err;
 		}
 	}
@@ -3568,7 +3570,8 @@ int regulator_bulk_get(struct device *dev, int num_consumers,
 
 err:
 	while (--i >= 0)
-		regulator_put(consumers[i].consumer);
+		if (consumers[i].consumer)
+			regulator_put(consumers[i].consumer);
 
 	return ret;
 }
@@ -3601,7 +3604,7 @@ int regulator_bulk_enable(int num_consumers,
 	int ret = 0;
 
 	for (i = 0; i < num_consumers; i++) {
-		if (consumers[i].consumer->always_on)
+		if (!consumers[i].consumer || consumers[i].consumer->always_on)
 			consumers[i].ret = 0;
 		else
 			async_schedule_domain(regulator_bulk_enable_async,
@@ -3625,7 +3628,7 @@ int regulator_bulk_enable(int num_consumers,
 		if (consumers[i].ret < 0)
 			pr_err("Failed to enable %s: %d\n", consumers[i].supply,
 			       consumers[i].ret);
-		else
+		else if (consumers[i].consumer)
 			regulator_disable(consumers[i].consumer);
 	}
 
@@ -3652,6 +3655,9 @@ int regulator_bulk_disable(int num_consumers,
 	int ret, r;
 
 	for (i = num_consumers - 1; i >= 0; --i) {
+		if (!consumers[i].consumer)
+			continue;
+
 		ret = regulator_disable(consumers[i].consumer);
 		if (ret != 0)
 			goto err;
@@ -3662,6 +3668,9 @@ int regulator_bulk_disable(int num_consumers,
 err:
 	pr_err("Failed to disable %s: %d\n", consumers[i].supply, ret);
 	for (++i; i < num_consumers; ++i) {
+		if (!consumers[i].consumer)
+			continue;
+
 		r = regulator_enable(consumers[i].consumer);
 		if (r != 0)
 			pr_err("Failed to re-enable %s: %d\n",
@@ -3693,8 +3702,8 @@ int regulator_bulk_force_disable(int num_consumers,
 	int ret = 0;
 
 	for (i = 0; i < num_consumers; i++) {
-		consumers[i].ret =
-			    regulator_force_disable(consumers[i].consumer);
+		consumers[i].ret = consumers[i].consumer ?
+			regulator_force_disable(consumers[i].consumer) : 0;
 
 		/* Store first error for reporting */
 		if (consumers[i].ret && !ret)
@@ -3720,8 +3729,10 @@ void regulator_bulk_free(int num_consumers,
 	int i;
 
 	for (i = 0; i < num_consumers; i++) {
-		regulator_put(consumers[i].consumer);
-		consumers[i].consumer = NULL;
+		if (consumers[i].consumer) {
+			regulator_put(consumers[i].consumer);
+			consumers[i].consumer = NULL;
+		}
 	}
 }
 EXPORT_SYMBOL_GPL(regulator_bulk_free);
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index ea0fffa5faeb..acaeeec279af 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -159,6 +159,8 @@ struct regulator;
  *
  * @supply:   The name of the supply.  Initialised by the user before
  *            using the bulk regulator APIs.
+ * @optional: The supply should be considered optional. Initialised by the user
+ *            before using the bulk regulator APIs.
  * @consumer: The regulator consumer for the supply.  This will be managed
  *            by the bulk API.
  *
@@ -168,6 +170,7 @@ struct regulator;
  */
 struct regulator_bulk_data {
 	const char *supply;
+	bool optional;
 	struct regulator *consumer;
 
 	/* private: Internal use */
-- 
2.11.0.483.g087da7b7c-goog

  parent reply	other threads:[~2017-02-03 23:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-03 23:16 [PATCH 1/4] regulator: core: fix typo in regulator_bulk_disable() Dmitry Torokhov
2017-02-03 23:16 ` [PATCH 2/4] regulator: core: simplify regulator_bulk_force_disable() Dmitry Torokhov
2017-02-04 10:48   ` Applied "regulator: core: simplify regulator_bulk_force_disable()" to the regulator tree Mark Brown
2017-02-03 23:16 ` [PATCH 3/4] regulator: core: optimize devm_regulator_bulk_get() Dmitry Torokhov
2017-02-04 10:48   ` Applied "regulator: core: optimize devm_regulator_bulk_get()" to the regulator tree Mark Brown
2017-02-03 23:16 ` Dmitry Torokhov [this message]
2017-02-04  7:53   ` [PATCH 4/4] regulator: core: make bulk API support optional supplies kbuild test robot
2017-02-04 10:56   ` Mark Brown
2017-02-04 18:13     ` Dmitry Torokhov
2017-02-05 16:07       ` Mark Brown
2017-02-06  4:30         ` Dmitry Torokhov
2017-02-06 12:08           ` Mark Brown
2017-02-07  0:21   ` Bjorn Andersson
2017-02-07  0:47     ` Dmitry Torokhov
2017-02-04 10:47 ` Applied "regulator: core: fix typo in regulator_bulk_disable()" to the regulator tree 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=20170203231619.8013-4-dmitry.torokhov@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=bjorn.andersson@sonymobile.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).