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 /drivers/regulator | |
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>
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/core.c | 34 |
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) | |||
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" |