summaryrefslogtreecommitdiffstats
path: root/drivers/regulator/core.c
diff options
context:
space:
mode:
authorStephen Boyd2012-01-17 04:39:58 +0100
committerMark Brown2012-01-20 13:02:55 +0100
commit070b9079226d4f3e3e7c9f4eb81f2e02e7d99572 (patch)
tree312b92136c28a321624bb811b43e8b03a03660ec /drivers/regulator/core.c
parentLinux 3.3-rc1 (diff)
downloadkernel-qcow2-linux-070b9079226d4f3e3e7c9f4eb81f2e02e7d99572.tar.gz
kernel-qcow2-linux-070b9079226d4f3e3e7c9f4eb81f2e02e7d99572.tar.xz
kernel-qcow2-linux-070b9079226d4f3e3e7c9f4eb81f2e02e7d99572.zip
regulator: Add devm_regulator_get()
Add a resource managed regulator_get() to simplify regulator usage in drivers. This allows driver authors to "get and forget" about their regulators by automatically calling regulator_put() when the driver is detached. [Fixed up a couple of coding style issues -- broonie] Signed-off-by: Stephen Boyd <sboyd@codeaurora.org> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/core.c')
-rw-r--r--drivers/regulator/core.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index ca86f39a0fdc..214640db084b 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1320,6 +1320,40 @@ struct regulator *regulator_get(struct device *dev, const char *id)
}
EXPORT_SYMBOL_GPL(regulator_get);
+static void devm_regulator_release(struct device *dev, void *res)
+{
+ regulator_put(*(struct regulator **)res);
+}
+
+/**
+ * devm_regulator_get - Resource managed regulator_get()
+ * @dev: device for regulator "consumer"
+ * @id: Supply name or regulator ID.
+ *
+ * Managed regulator_get(). Regulators returned from this function are
+ * automatically regulator_put() on driver detach. See regulator_get() for more
+ * information.
+ */
+struct regulator *devm_regulator_get(struct device *dev, const char *id)
+{
+ struct regulator **ptr, *regulator;
+
+ ptr = devres_alloc(devm_regulator_release, sizeof(*ptr), GFP_KERNEL);
+ if (!ptr)
+ return ERR_PTR(-ENOMEM);
+
+ regulator = regulator_get(dev, id);
+ if (!IS_ERR(regulator)) {
+ *ptr = regulator;
+ devres_add(dev, ptr);
+ } else {
+ devres_free(ptr);
+ }
+
+ return regulator;
+}
+EXPORT_SYMBOL_GPL(devm_regulator_get);
+
/**
* regulator_get_exclusive - obtain exclusive access to a regulator.
* @dev: device for regulator "consumer"