regulator: Add devm_regulator_get()
Subsystems (2)
PATCH 1/1 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.
--- Documentation/driver-model/devres.txt | 3 +++ drivers/regulator/core.c | 33 +++++++++++++++++++++++++++++++++ include/linux/regulator/consumer.h | 7 +++++++ 3 files changed, 43 insertions(+), 0 deletions(-)
Documentation/driver-model/devres.txt +3 -0
@@ -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()
drivers/regulator/core.c +33 -0
@@ -1320,6 +1320,39 @@ 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"
include/linux/regulator/consumer.h +7 -0
@@ -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,11 @@ 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) { }
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Quoted 4 lines · Stephen Boyd
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 callingregulator_put()when the driver is detached.
So, I've gone ahead and applied this as it's obviously useful as-is but it's obviously something that should have a bulk version - I'll probably add that myself. We really ought to have release functions too in case something wants to release the resource earlier, though I can't think where you'd actually use those.
include/linux/regulator/consumer.h static inline struct regulator *__must_check regulator_get(struct device *dev, · line 212
Quoted 12 lines · Stephen Boyd
include/linux/regulator/consumer.h +5
-0@@ -200,6 +202,11 @@ 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) { }
Oh, and it's not obvious from the diff but blank lines please like the adjacent code.
Quoted 16 lines · Mark Brown
include/linux/regulator/consumer.h static inline struct regulator *__must_check regulator_get(struct device *dev, · line 212
Quoted 12 lines · Stephen Boyd
include/linux/regulator/consumer.h +5
-0@@ -200,6 +202,11 @@ 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) { }Oh, and it's not obvious from the diff but blank lines please like the adjacent code.
Should I resend or are you ok with adding the newline there yourself?
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Quoted 6 lines · Stephen Boyd
Quoted 2 lines · Mark Brown
Oh, and it's not obvious from the diff but blank lines please like the adjacent code.
Should I resend or are you ok with adding the newline there yourself?
I fixed that and also added some missing braces.