[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220518200939.689308-3-clabbe@baylibre.com>
Date: Wed, 18 May 2022 20:09:36 +0000
From: Corentin Labbe <clabbe@...libre.com>
To: andrew@...n.ch, broonie@...nel.org, calvin.johnson@....nxp.com,
davem@...emloft.net, edumazet@...gle.com, hkallweit1@...il.com,
jernej.skrabec@...il.com, krzysztof.kozlowski+dt@...aro.org,
kuba@...nel.org, lgirdwood@...il.com, linux@...linux.org.uk,
pabeni@...hat.com, robh+dt@...nel.org, samuel@...lland.org,
wens@...e.org
Cc: devicetree@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
linux-kernel@...r.kernel.org, linux-sunxi@...ts.linux.dev,
netdev@...r.kernel.org, Corentin Labbe <clabbe@...libre.com>
Subject: [PATCH v2 2/5] regulator: Add regulator_bulk_get_all
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@...libre.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
Powered by blists - more mailing lists