* [PATCH 1/2] regulator: Implement devm_regulator_free()
@ 2012-01-22 16:12 Mark Brown
2012-01-22 16:12 ` [PATCH 2/2] regulator: Provide devm_regulator_bulk_get() Mark Brown
0 siblings, 1 reply; 2+ messages in thread
From: Mark Brown @ 2012-01-22 16:12 UTC (permalink / raw)
To: Liam Girdwood; +Cc: linux-kernel, Mark Brown
Allow consumers to free regulators allocated using devm_regulator_get()
if they need to. This will not normally be required.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
drivers/regulator/core.c | 28 ++++++++++++++++++++++++++++
include/linux/regulator/consumer.h | 1 +
2 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 214640d..88bcb11 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1421,6 +1421,34 @@ void regulator_put(struct regulator *regulator)
}
EXPORT_SYMBOL_GPL(regulator_put);
+static int devm_regulator_match(struct device *dev, void *res, void *data)
+{
+ struct regulator **r = res;
+ if (!r || !*r) {
+ WARN_ON(!r || !*r);
+ return 0;
+ }
+ return *r == data;
+}
+
+/**
+ * devm_regulator_put - Resource managed regulator_put()
+ * @regulator: regulator to free
+ *
+ * Deallocate a regulator allocated with devm_regulator_get(). Normally
+ * this function will not need to be called and the resource management
+ * code will ensure that the resource is freed.
+ */
+void devm_regulator_put(struct regulator *regulator)
+{
+ int rc;
+
+ rc = devres_destroy(regulator->dev, devm_regulator_release,
+ devm_regulator_match, regulator);
+ WARN_ON(rc);
+}
+EXPORT_SYMBOL_GPL(devm_regulator_put);
+
static int _regulator_can_change_status(struct regulator_dev *rdev)
{
if (!rdev->constraints)
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index bcfe106..60c2f99 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -137,6 +137,7 @@ struct regulator *__must_check devm_regulator_get(struct device *dev,
struct regulator *__must_check regulator_get_exclusive(struct device *dev,
const char *id);
void regulator_put(struct regulator *regulator);
+void devm_regulator_free(struct regulator *regulator);
/* regulator output control and status */
int regulator_enable(struct regulator *regulator);
--
1.7.7.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] regulator: Provide devm_regulator_bulk_get()
2012-01-22 16:12 [PATCH 1/2] regulator: Implement devm_regulator_free() Mark Brown
@ 2012-01-22 16:12 ` Mark Brown
0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2012-01-22 16:12 UTC (permalink / raw)
To: Liam Girdwood; +Cc: linux-kernel, Mark Brown
Allow drivers to benefit from both the bulk APIs and managed resources
simultaneously.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
drivers/regulator/core.c | 46 ++++++++++++++++++++++++++++++++++++
include/linux/regulator/consumer.h | 2 +
2 files changed, 48 insertions(+), 0 deletions(-)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 88bcb11..1432c22 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;
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index 60c2f99..35c4283 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);
int regulator_bulk_get(struct device *dev, int num_consumers,
struct regulator_bulk_data *consumers);
+int devm_regulator_bulk_get(struct device *dev, int num_consumers,
+ struct regulator_bulk_data *consumers);
int regulator_bulk_enable(int num_consumers,
struct regulator_bulk_data *consumers);
int regulator_bulk_disable(int num_consumers,
--
1.7.7.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-01-22 16:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-22 16:12 [PATCH 1/2] regulator: Implement devm_regulator_free() Mark Brown
2012-01-22 16:12 ` [PATCH 2/2] regulator: Provide devm_regulator_bulk_get() Mark Brown
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).