regulator: Add devm_regulator_get_exclusive()
authorMatthias Kaehlcke <matthias.list@kaehlcke.net>
Sun, 25 Aug 2013 15:54:13 +0000 (17:54 +0200)
committerMark Brown <broonie@linaro.org>
Thu, 29 Aug 2013 18:38:33 +0000 (19:38 +0100)
Add a resource managed regulator_get_exclusive()

Signed-off-by: Matthias Kaehlcke <matthias@kaehlcke.net>
Signed-off-by: Mark Brown <broonie@linaro.org>
drivers/regulator/core.c
include/linux/regulator/consumer.h

index a27a5b6267dde117c8273877c0b12c5b1a498847..4b9039b43b6ceffa8d707f1757421df2f5caa432 100644 (file)
@@ -1493,6 +1493,36 @@ static void _regulator_put(struct regulator *regulator)
        module_put(rdev->owner);
 }
 
+/**
+ * devm_regulator_get_exclusive - Resource managed regulator_get_exclusive()
+ * @dev: device for regulator "consumer"
+ * @id: Supply name or regulator ID.
+ *
+ * Managed regulator_get_exclusive(). Regulators returned from this function
+ * are automatically regulator_put() on driver detach. See regulator_get() for
+ * more information.
+ */
+struct regulator *devm_regulator_get_exclusive(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, 1);
+       if (!IS_ERR(regulator)) {
+               *ptr = regulator;
+               devres_add(dev, ptr);
+       } else {
+               devres_free(ptr);
+       }
+
+       return regulator;
+}
+EXPORT_SYMBOL_GPL(devm_regulator_get_exclusive);
+
 /**
  * regulator_put - "free" the regulator source
  * @regulator: regulator source
index e2bac6db4abc7eb56e91a8d20a081bd582a45ba6..91aca11198d8fbd4ba9997dd78a733d0df5eedfa 100644 (file)
@@ -137,6 +137,8 @@ struct regulator *__must_check devm_regulator_get(struct device *dev,
                                             const char *id);
 struct regulator *__must_check regulator_get_exclusive(struct device *dev,
                                                       const char *id);
+struct regulator *__must_check devm_regulator_get_exclusive(struct device *dev,
+                                                       const char *id);
 struct regulator *__must_check regulator_get_optional(struct device *dev,
                                                      const char *id);
 struct regulator *__must_check devm_regulator_get_optional(struct device *dev,