diff options
author | Stephen Boyd <sboyd@codeaurora.org> | 2012-01-16 22:39:58 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-01-20 07:02:55 -0500 |
commit | 070b9079226d4f3e3e7c9f4eb81f2e02e7d99572 (patch) | |
tree | 312b92136c28a321624bb811b43e8b03a03660ec | |
parent | dcd6c92267155e70a94b3927bce681ce74b80d1f (diff) |
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>
-rw-r--r-- | Documentation/driver-model/devres.txt | 3 | ||||
-rw-r--r-- | drivers/regulator/core.c | 34 | ||||
-rw-r--r-- | include/linux/regulator/consumer.h | 9 |
3 files changed, 46 insertions, 0 deletions
diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt index 10c64c8a13d4..016fd2b06a57 100644 --- a/Documentation/driver-model/devres.txt +++ b/Documentation/driver-model/devres.txt | |||
@@ -267,3 +267,6 @@ IOMAP | |||
267 | pcim_iounmap() | 267 | pcim_iounmap() |
268 | pcim_iomap_table() : array of mapped addresses indexed by BAR | 268 | pcim_iomap_table() : array of mapped addresses indexed by BAR |
269 | pcim_iomap_regions() : do request_region() and iomap() on multiple BARs | 269 | pcim_iomap_regions() : do request_region() and iomap() on multiple BARs |
270 | |||
271 | REGULATOR | ||
272 | devm_regulator_get() | ||
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) | |||
1320 | } | 1320 | } |
1321 | EXPORT_SYMBOL_GPL(regulator_get); | 1321 | EXPORT_SYMBOL_GPL(regulator_get); |
1322 | 1322 | ||
1323 | static void devm_regulator_release(struct device *dev, void *res) | ||
1324 | { | ||
1325 | regulator_put(*(struct regulator **)res); | ||
1326 | } | ||
1327 | |||
1328 | /** | ||
1329 | * devm_regulator_get - Resource managed regulator_get() | ||
1330 | * @dev: device for regulator "consumer" | ||
1331 | * @id: Supply name or regulator ID. | ||
1332 | * | ||
1333 | * Managed regulator_get(). Regulators returned from this function are | ||
1334 | * automatically regulator_put() on driver detach. See regulator_get() for more | ||
1335 | * information. | ||
1336 | */ | ||
1337 | struct regulator *devm_regulator_get(struct device *dev, const char *id) | ||
1338 | { | ||
1339 | struct regulator **ptr, *regulator; | ||
1340 | |||
1341 | ptr = devres_alloc(devm_regulator_release, sizeof(*ptr), GFP_KERNEL); | ||
1342 | if (!ptr) | ||
1343 | return ERR_PTR(-ENOMEM); | ||
1344 | |||
1345 | regulator = regulator_get(dev, id); | ||
1346 | if (!IS_ERR(regulator)) { | ||
1347 | *ptr = regulator; | ||
1348 | devres_add(dev, ptr); | ||
1349 | } else { | ||
1350 | devres_free(ptr); | ||
1351 | } | ||
1352 | |||
1353 | return regulator; | ||
1354 | } | ||
1355 | EXPORT_SYMBOL_GPL(devm_regulator_get); | ||
1356 | |||
1323 | /** | 1357 | /** |
1324 | * regulator_get_exclusive - obtain exclusive access to a regulator. | 1358 | * regulator_get_exclusive - obtain exclusive access to a regulator. |
1325 | * @dev: device for regulator "consumer" | 1359 | * @dev: device for regulator "consumer" |
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h index f2698a0edfc4..bcfe10658763 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h | |||
@@ -132,6 +132,8 @@ struct regulator_bulk_data { | |||
132 | /* regulator get and put */ | 132 | /* regulator get and put */ |
133 | struct regulator *__must_check regulator_get(struct device *dev, | 133 | struct regulator *__must_check regulator_get(struct device *dev, |
134 | const char *id); | 134 | const char *id); |
135 | struct regulator *__must_check devm_regulator_get(struct device *dev, | ||
136 | const char *id); | ||
135 | struct regulator *__must_check regulator_get_exclusive(struct device *dev, | 137 | struct regulator *__must_check regulator_get_exclusive(struct device *dev, |
136 | const char *id); | 138 | const char *id); |
137 | void regulator_put(struct regulator *regulator); | 139 | void regulator_put(struct regulator *regulator); |
@@ -200,6 +202,13 @@ static inline struct regulator *__must_check regulator_get(struct device *dev, | |||
200 | */ | 202 | */ |
201 | return NULL; | 203 | return NULL; |
202 | } | 204 | } |
205 | |||
206 | static inline struct regulator *__must_check | ||
207 | devm_regulator_get(struct device *dev, const char *id) | ||
208 | { | ||
209 | return NULL; | ||
210 | } | ||
211 | |||
203 | static inline void regulator_put(struct regulator *regulator) | 212 | static inline void regulator_put(struct regulator *regulator) |
204 | { | 213 | { |
205 | } | 214 | } |