aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2012-01-20 15:10:08 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-01-22 11:15:39 -0500
commite6e740304aa2a49ef09497e6c0bb906ed7987f6b (patch)
tree1f42de6c608ef6f83f34d7df850536068cfa4de0
parentd5ad34f7cb8b23ab165cabef69577a2a20d53195 (diff)
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>
-rw-r--r--drivers/regulator/core.c46
-rw-r--r--include/linux/regulator/consumer.h2
2 files changed, 48 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:
2463} 2463}
2464EXPORT_SYMBOL_GPL(regulator_bulk_get); 2464EXPORT_SYMBOL_GPL(regulator_bulk_get);
2465 2465
2466/**
2467 * devm_regulator_bulk_get - managed get multiple regulator consumers
2468 *
2469 * @dev: Device to supply
2470 * @num_consumers: Number of consumers to register
2471 * @consumers: Configuration of consumers; clients are stored here.
2472 *
2473 * @return 0 on success, an errno on failure.
2474 *
2475 * This helper function allows drivers to get several regulator
2476 * consumers in one operation with management, the regulators will
2477 * automatically be freed when the device is unbound. If any of the
2478 * regulators cannot be acquired then any regulators that were
2479 * allocated will be freed before returning to the caller.
2480 */
2481int devm_regulator_bulk_get(struct device *dev, int num_consumers,
2482 struct regulator_bulk_data *consumers)
2483{
2484 int i;
2485 int ret;
2486
2487 for (i = 0; i < num_consumers; i++)
2488 consumers[i].consumer = NULL;
2489
2490 for (i = 0; i < num_consumers; i++) {
2491 consumers[i].consumer = devm_regulator_get(dev,
2492 consumers[i].supply);
2493 if (IS_ERR(consumers[i].consumer)) {
2494 ret = PTR_ERR(consumers[i].consumer);
2495 dev_err(dev, "Failed to get supply '%s': %d\n",
2496 consumers[i].supply, ret);
2497 consumers[i].consumer = NULL;
2498 goto err;
2499 }
2500 }
2501
2502 return 0;
2503
2504err:
2505 for (i = 0; i < num_consumers && consumers[i].consumer; i++)
2506 devm_regulator_put(consumers[i].consumer);
2507
2508 return ret;
2509}
2510EXPORT_SYMBOL_GPL(devm_regulator_bulk_get);
2511
2466static void regulator_bulk_enable_async(void *data, async_cookie_t cookie) 2512static void regulator_bulk_enable_async(void *data, async_cookie_t cookie)
2467{ 2513{
2468 struct regulator_bulk_data *bulk = data; 2514 struct regulator_bulk_data *bulk = data;
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index 60c2f996d895..35c42834ba3d 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -148,6 +148,8 @@ int regulator_disable_deferred(struct regulator *regulator, int ms);
148 148
149int regulator_bulk_get(struct device *dev, int num_consumers, 149int regulator_bulk_get(struct device *dev, int num_consumers,
150 struct regulator_bulk_data *consumers); 150 struct regulator_bulk_data *consumers);
151int devm_regulator_bulk_get(struct device *dev, int num_consumers,
152 struct regulator_bulk_data *consumers);
151int regulator_bulk_enable(int num_consumers, 153int regulator_bulk_enable(int num_consumers,
152 struct regulator_bulk_data *consumers); 154 struct regulator_bulk_data *consumers);
153int regulator_bulk_disable(int num_consumers, 155int regulator_bulk_disable(int num_consumers,