* [PATCH] regulator: Add devm_regulator_get()
@ 2012-01-17 3:39 Stephen Boyd
2012-01-17 10:41 ` Mark Brown
2012-01-17 11:04 ` Mark Brown
0 siblings, 2 replies; 5+ messages in thread
From: Stephen Boyd @ 2012-01-17 3:39 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown; +Cc: linux-kernel, linux-doc
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.
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
---
Documentation/driver-model/devres.txt | 3 +++
drivers/regulator/core.c | 33 +++++++++++++++++++++++++++++++++
include/linux/regulator/consumer.h | 7 +++++++
3 files changed, 43 insertions(+), 0 deletions(-)
diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt
index 10c64c8..016fd2b 100644
--- a/Documentation/driver-model/devres.txt
+++ b/Documentation/driver-model/devres.txt
@@ -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()
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index ca86f39..b05b058 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -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"
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index f2698a0..bbe45b0 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -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)
{
}
--
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] regulator: Add devm_regulator_get()
2012-01-17 3:39 [PATCH] regulator: Add devm_regulator_get() Stephen Boyd
@ 2012-01-17 10:41 ` Mark Brown
2012-01-17 11:04 ` Mark Brown
1 sibling, 0 replies; 5+ messages in thread
From: Mark Brown @ 2012-01-17 10:41 UTC (permalink / raw)
To: Stephen Boyd; +Cc: Liam Girdwood, linux-kernel, linux-doc
On Mon, Jan 16, 2012 at 07:39:58PM -0800, Stephen Boyd wrote:
> 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.
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] regulator: Add devm_regulator_get()
2012-01-17 3:39 [PATCH] regulator: Add devm_regulator_get() Stephen Boyd
2012-01-17 10:41 ` Mark Brown
@ 2012-01-17 11:04 ` Mark Brown
2012-01-17 16:54 ` Stephen Boyd
1 sibling, 1 reply; 5+ messages in thread
From: Mark Brown @ 2012-01-17 11:04 UTC (permalink / raw)
To: Stephen Boyd; +Cc: Liam Girdwood, linux-kernel, linux-doc
On Mon, Jan 16, 2012 at 07:39:58PM -0800, Stephen Boyd wrote:
> @@ -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.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] regulator: Add devm_regulator_get()
2012-01-17 11:04 ` Mark Brown
@ 2012-01-17 16:54 ` Stephen Boyd
2012-01-17 16:58 ` Mark Brown
0 siblings, 1 reply; 5+ messages in thread
From: Stephen Boyd @ 2012-01-17 16:54 UTC (permalink / raw)
To: Mark Brown; +Cc: Liam Girdwood, linux-kernel, linux-doc
On 01/17/12 03:04, Mark Brown wrote:
> On Mon, Jan 16, 2012 at 07:39:58PM -0800, Stephen Boyd wrote:
>
>> @@ -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?
--
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] regulator: Add devm_regulator_get()
2012-01-17 16:54 ` Stephen Boyd
@ 2012-01-17 16:58 ` Mark Brown
0 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2012-01-17 16:58 UTC (permalink / raw)
To: Stephen Boyd; +Cc: Liam Girdwood, linux-kernel, linux-doc
On Tue, Jan 17, 2012 at 08:54:40AM -0800, Stephen Boyd wrote:
> On 01/17/12 03:04, Mark Brown wrote:
> > 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.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-01-17 16:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-17 3:39 [PATCH] regulator: Add devm_regulator_get() Stephen Boyd
2012-01-17 10:41 ` Mark Brown
2012-01-17 11:04 ` Mark Brown
2012-01-17 16:54 ` Stephen Boyd
2012-01-17 16:58 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox