summaryrefslogtreecommitdiffstats
path: root/drivers/regulator/core.c
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2012-01-20 20:10:08 +0000
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-01-22 16:15:39 +0000
commite6e740304aa2a49ef09497e6c0bb906ed7987f6b (patch)
tree1f42de6c608ef6f83f34d7df850536068cfa4de0 /drivers/regulator/core.c
parentd5ad34f7cb8b23ab165cabef69577a2a20d53195 (diff)
downloadlinux-e6e740304aa2a49ef09497e6c0bb906ed7987f6b.tar.gz
linux-e6e740304aa2a49ef09497e6c0bb906ed7987f6b.tar.xz
linux-e6e740304aa2a49ef09497e6c0bb906ed7987f6b.zip
regulator: Provide devm_regulator_bulk_get()
Allow drivers to benefit from both the bulk APIs and managed resources simultaneously. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/core.c')
-rw-r--r--drivers/regulator/core.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 88bcb111ca68..1432c22926b5 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2463,6 +2463,52 @@ err:
}
EXPORT_SYMBOL_GPL(regulator_bulk_get);
+/**
+ * devm_regulator_bulk_get - managed get multiple regulator consumers
+ *
+ * @dev: Device to supply
+ * @num_consumers: Number of consumers to register
+ * @consumers: Configuration of consumers; clients are stored here.
+ *
+ * @return 0 on success, an errno on failure.
+ *
+ * This helper function allows drivers to get several regulator
+ * consumers in one operation with management, the regulators will
+ * automatically be freed when the device is unbound. If any of the
+ * regulators cannot be acquired then any regulators that were
+ * allocated will be freed before returning to the caller.
+ */
+int devm_regulator_bulk_get(struct device *dev, int num_consumers,
+ struct regulator_bulk_data *consumers)
+{
+ 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 = devm_regulator_get(dev,
+ consumers[i].supply);
+ if (IS_ERR(consumers[i].consumer)) {
+ ret = PTR_ERR(consumers[i].consumer);
+ dev_err(dev, "Failed to get supply '%s': %d\n",
+ consumers[i].supply, ret);
+ consumers[i].consumer = NULL;
+ goto err;
+ }
+ }
+
+ return 0;
+
+err:
+ for (i = 0; i < num_consumers && consumers[i].consumer; i++)
+ devm_regulator_put(consumers[i].consumer);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(devm_regulator_bulk_get);
+
static void regulator_bulk_enable_async(void *data, async_cookie_t cookie)
{
struct regulator_bulk_data *bulk = data;