mirror of
https://github.com/followmsi/android_kernel_google_msm.git
synced 2024-11-06 23:17:41 +00:00
clk: Add devm_clk_get()
Add a resource managed clk_get() to simplify clock usage in drivers. This allows driver authors to "get and forget" about their clocks by automatically calling clk_put() when the driver is detached. This also encourages clock consumers to use the clk_get() API correctly by passing in a struct device as an argument. Change-Id: I1ed53cd3c26c0390fa30cd3c3dca14bcdd59939f Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
This commit is contained in:
parent
3924a3e96e
commit
64990c839b
2 changed files with 35 additions and 0 deletions
|
@ -83,6 +83,31 @@ struct clk *clk_get(struct device *dev, const char *con_id)
|
|||
}
|
||||
EXPORT_SYMBOL(clk_get);
|
||||
|
||||
static void devm_clk_release(struct device *dev, void *res)
|
||||
{
|
||||
clk_put(*(struct clk **)res);
|
||||
}
|
||||
|
||||
struct clk *devm_clk_get(struct device *dev, const char *id)
|
||||
{
|
||||
struct clk **ptr, *clk;
|
||||
|
||||
ptr = devres_alloc(devm_clk_release, sizeof(*ptr), GFP_KERNEL);
|
||||
if (!ptr)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
clk = clk_get(dev, id);
|
||||
if (!IS_ERR(clk)) {
|
||||
*ptr = clk;
|
||||
devres_add(dev, ptr);
|
||||
} else {
|
||||
devres_free(ptr);
|
||||
}
|
||||
|
||||
return clk;
|
||||
}
|
||||
EXPORT_SYMBOL(devm_clk_get);
|
||||
|
||||
void clk_put(struct clk *clk)
|
||||
{
|
||||
__clk_put(clk);
|
||||
|
|
|
@ -100,6 +100,16 @@ int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb);
|
|||
*/
|
||||
struct clk *clk_get(struct device *dev, const char *id);
|
||||
|
||||
/**
|
||||
* devm_clk_get - Resource managed clk_get()
|
||||
* @dev: device for clk "consumer"
|
||||
* @id: clk ID.
|
||||
*
|
||||
* Managed clk_get(). Clocks returned from this function are
|
||||
* automatically clk_put() on driver detach.
|
||||
*/
|
||||
struct clk *devm_clk_get(struct device *dev, const char *id);
|
||||
|
||||
/**
|
||||
* clk_prepare - prepare a clock source
|
||||
* @clk: clock source
|
||||
|
|
Loading…
Reference in a new issue