devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Corentin Labbe <clabbe@baylibre.com>
To: andrew@lunn.ch, broonie@kernel.org, calvin.johnson@oss.nxp.com,
	davem@davemloft.net, edumazet@google.com, hkallweit1@gmail.com,
	jernej.skrabec@gmail.com, krzysztof.kozlowski+dt@linaro.org,
	kuba@kernel.org, lgirdwood@gmail.com, linux@armlinux.org.uk,
	pabeni@redhat.com, robh+dt@kernel.org, samuel@sholland.org,
	wens@csie.org
Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-sunxi@lists.linux.dev,
	netdev@vger.kernel.org, Corentin Labbe <clabbe@baylibre.com>
Subject: [PATCH v2 2/5] regulator: Add regulator_bulk_get_all
Date: Wed, 18 May 2022 20:09:36 +0000	[thread overview]
Message-ID: <20220518200939.689308-3-clabbe@baylibre.com> (raw)
In-Reply-To: <20220518200939.689308-1-clabbe@baylibre.com>

It work exactly like regulator_bulk_get() but instead of working on a
provided list of names, it get names from a regulators list.

Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
---
 drivers/regulator/core.c           | 49 ++++++++++++++++++++++++++++++
 include/linux/regulator/consumer.h |  2 ++
 2 files changed, 51 insertions(+)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 09578c3595de..719ce9a0db1b 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -4849,6 +4849,55 @@ static void regulator_bulk_enable_async(void *data, async_cookie_t cookie)
 	bulk->ret = regulator_enable(bulk->consumer);
 }
 
+/**
+ * regulator_bulk_get_all - get multiple regulator consumers
+ *
+ * @dev:           Device to supply
+ * @consumers:     Configuration of consumers; clients are stored here.
+ *
+ * @return number of regulators on success, an errno on failure.
+ *
+ * This helper function allows drivers to get several regulator
+ * consumers in one operation.  If any of the regulators cannot be
+ * acquired then any regulators that were allocated will be freed
+ * before returning to the caller.
+ */
+int regulator_bulk_get_all(struct device *dev, struct device_node *np,
+			   struct regulator_bulk_data **consumers)
+{
+	int num_consumers;
+	int i, ret;
+	struct regulator *tmp;
+	const char *p;
+
+	num_consumers = of_property_count_elems_of_size(np, "regulators",
+							sizeof(phandle));
+	if (num_consumers <= 0)
+		return num_consumers;
+
+	ret = of_property_count_strings(np, "regulator-names");
+	if (ret != num_consumers) {
+		dev_err(dev, "regulators and regulator-names does not have the same size\n");
+		return -EINVAL;
+	}
+	*consumers = kmalloc_array(num_consumers, sizeof(struct regulator_bulk_data), GFP_KERNEL);
+	if (!*consumers)
+		return -ENOMEM;
+	for (i = 0; i < num_consumers; i++) {
+		ret = of_property_read_string_helper(np, "regulator-names", &p, 1, i);
+		if (ret <= 0)
+			goto error;
+		tmp = regulator_get(dev, p);
+		(*consumers)[i].consumer = tmp;
+	}
+	return num_consumers;
+error:
+	while (--i >= 0)
+		regulator_put(consumers[i]->consumer);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(regulator_bulk_get_all);
+
 /**
  * regulator_bulk_enable - enable multiple regulator consumers
  *
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index bbf6590a6dec..b9b1d1cbdd07 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -238,6 +238,8 @@ int regulator_disable_deferred(struct regulator *regulator, int ms);
 
 int __must_check regulator_bulk_get(struct device *dev, int num_consumers,
 				    struct regulator_bulk_data *consumers);
+int __must_check regulator_bulk_get_all(struct device *dev, struct device_node *np,
+					struct regulator_bulk_data **consumers);
 int __must_check devm_regulator_bulk_get(struct device *dev, int num_consumers,
 					 struct regulator_bulk_data *consumers);
 int __must_check regulator_bulk_enable(int num_consumers,
-- 
2.35.1


  parent reply	other threads:[~2022-05-18 20:10 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-18 20:09 [PATCH v2 0/5] arm64: add ethernet to orange pi 3 Corentin Labbe
2022-05-18 20:09 ` [PATCH v2 1/5] regulator: Add of_get_regulator_from_list Corentin Labbe
2022-05-18 20:09 ` Corentin Labbe [this message]
2022-05-18 20:09 ` [PATCH v2 3/5] phy: handle optional regulator for PHY Corentin Labbe
2022-05-18 20:09 ` [PATCH v2 4/5] dt-bindings: net: Add documentation for optional regulators Corentin Labbe
2022-05-19  0:08   ` Rob Herring
2022-05-19  9:55   ` Krzysztof Kozlowski
2022-05-19 11:31     ` Mark Brown
2022-05-19 11:33       ` Krzysztof Kozlowski
2022-05-19 11:58         ` Andrew Lunn
2022-05-19 15:49           ` Mark Brown
2022-05-20  7:57             ` Krzysztof Kozlowski
2022-05-20  8:15               ` LABBE Corentin
2022-05-20 10:19                 ` Krzysztof Kozlowski
2022-05-19 20:17           ` Rob Herring
2022-05-18 20:09 ` [PATCH v2 5/5] arm64: dts: allwinner: orange-pi-3: Enable ethernet Corentin Labbe

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=20220518200939.689308-3-clabbe@baylibre.com \
    --to=clabbe@baylibre.com \
    --cc=andrew@lunn.ch \
    --cc=broonie@kernel.org \
    --cc=calvin.johnson@oss.nxp.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=jernej.skrabec@gmail.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=kuba@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=robh+dt@kernel.org \
    --cc=samuel@sholland.org \
    --cc=wens@csie.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).