]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
regulator: Add devm_regulator_get()
authorStephen Boyd <sboyd@codeaurora.org>
Tue, 17 Jan 2012 03:39:58 +0000 (19:39 -0800)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Fri, 20 Jan 2012 12:02:55 +0000 (12:02 +0000)
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>
Documentation/driver-model/devres.txt
drivers/regulator/core.c
include/linux/regulator/consumer.h

index 10c64c8a13d4f2aec7bebb0bd6a44ce401aa78cc..016fd2b06a5729d9c00697a8513ebd1fdf61d164 100644 (file)
@@ -267,3 +267,6 @@ IOMAP
   pcim_iounmap()
   pcim_iomap_table()   : array of mapped addresses indexed by BAR
   pcim_iomap_regions() : do request_region() and iomap() on multiple BARs
+
+REGULATOR
+  devm_regulator_get()
index ca86f39a0fdc824fba463f0eb30157ce933bbe9c..214640db084b466c931957d11f8eabd29dee9525 100644 (file)
@@ -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"
index f2698a0edfc44486a95bd8379b1fa40dd56e1e70..bcfe10658763dff7ed5ae791d51ac141333b411f 100644 (file)
@@ -132,6 +132,8 @@ struct regulator_bulk_data {
 /* regulator get and put */
 struct regulator *__must_check regulator_get(struct device *dev,
                                             const char *id);
+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);
 void regulator_put(struct regulator *regulator);
@@ -200,6 +202,13 @@ static inline struct regulator *__must_check regulator_get(struct device *dev,
         */
        return NULL;
 }
+
+static inline struct regulator *__must_check
+devm_regulator_get(struct device *dev, const char *id)
+{
+       return NULL;
+}
+
 static inline void regulator_put(struct regulator *regulator)
 {
 }