lkml.org 
[lkml]   [2022]   [May]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2 2/5] regulator: Add regulator_bulk_get_all
Date
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
\
 
 \ /
  Last update: 2022-05-18 22:15    [W:0.113 / U:0.552 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site