mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-12 05:48:40 +00:00
clk: Add (devm_)clk_get_optional() functions
This adds clk_get_optional() and devm_clk_get_optional() functions to get optional clocks. They behave the same as (devm_)clk_get() except where there is no clock producer. In this case, instead of returning -ENOENT, the function returns NULL. This makes error checking simpler and allows clk_prepare_enable, etc to be called on the returned reference without additional checks. Signed-off-by: Phil Edworthy <phil.edworthy@renesas.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: Russell King <linux@armlinux.org.uk> [sboyd@kernel.org: Document in devres.txt] Signed-off-by: Stephen Boyd <sboyd@kernel.org>
This commit is contained in:
parent
5c56dfe63b
commit
60b8f0ddf1
3 changed files with 48 additions and 0 deletions
|
@ -242,6 +242,7 @@ certainly invest a bit more effort into libata core layer).
|
||||||
|
|
||||||
CLOCK
|
CLOCK
|
||||||
devm_clk_get()
|
devm_clk_get()
|
||||||
|
devm_clk_get_optional()
|
||||||
devm_clk_put()
|
devm_clk_put()
|
||||||
devm_clk_hw_register()
|
devm_clk_hw_register()
|
||||||
devm_of_clk_add_hw_provider()
|
devm_of_clk_add_hw_provider()
|
||||||
|
|
|
@ -29,6 +29,17 @@ struct clk *devm_clk_get(struct device *dev, const char *id)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(devm_clk_get);
|
EXPORT_SYMBOL(devm_clk_get);
|
||||||
|
|
||||||
|
struct clk *devm_clk_get_optional(struct device *dev, const char *id)
|
||||||
|
{
|
||||||
|
struct clk *clk = devm_clk_get(dev, id);
|
||||||
|
|
||||||
|
if (clk == ERR_PTR(-ENOENT))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return clk;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(devm_clk_get_optional);
|
||||||
|
|
||||||
struct clk_bulk_devres {
|
struct clk_bulk_devres {
|
||||||
struct clk_bulk_data *clks;
|
struct clk_bulk_data *clks;
|
||||||
int num_clks;
|
int num_clks;
|
||||||
|
|
|
@ -383,6 +383,17 @@ int __must_check devm_clk_bulk_get_all(struct device *dev,
|
||||||
*/
|
*/
|
||||||
struct clk *devm_clk_get(struct device *dev, const char *id);
|
struct clk *devm_clk_get(struct device *dev, const char *id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* devm_clk_get_optional - lookup and obtain a managed reference to an optional
|
||||||
|
* clock producer.
|
||||||
|
* @dev: device for clock "consumer"
|
||||||
|
* @id: clock consumer ID
|
||||||
|
*
|
||||||
|
* Behaves the same as devm_clk_get() except where there is no clock producer.
|
||||||
|
* In this case, instead of returning -ENOENT, the function returns NULL.
|
||||||
|
*/
|
||||||
|
struct clk *devm_clk_get_optional(struct device *dev, const char *id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* devm_get_clk_from_child - lookup and obtain a managed reference to a
|
* devm_get_clk_from_child - lookup and obtain a managed reference to a
|
||||||
* clock producer from child node.
|
* clock producer from child node.
|
||||||
|
@ -718,6 +729,12 @@ static inline struct clk *devm_clk_get(struct device *dev, const char *id)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline struct clk *devm_clk_get_optional(struct device *dev,
|
||||||
|
const char *id)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static inline int __must_check devm_clk_bulk_get(struct device *dev, int num_clks,
|
static inline int __must_check devm_clk_bulk_get(struct device *dev, int num_clks,
|
||||||
struct clk_bulk_data *clks)
|
struct clk_bulk_data *clks)
|
||||||
{
|
{
|
||||||
|
@ -862,6 +879,25 @@ static inline void clk_bulk_disable_unprepare(int num_clks,
|
||||||
clk_bulk_unprepare(num_clks, clks);
|
clk_bulk_unprepare(num_clks, clks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clk_get_optional - lookup and obtain a reference to an optional clock
|
||||||
|
* producer.
|
||||||
|
* @dev: device for clock "consumer"
|
||||||
|
* @id: clock consumer ID
|
||||||
|
*
|
||||||
|
* Behaves the same as clk_get() except where there is no clock producer. In
|
||||||
|
* this case, instead of returning -ENOENT, the function returns NULL.
|
||||||
|
*/
|
||||||
|
static inline struct clk *clk_get_optional(struct device *dev, const char *id)
|
||||||
|
{
|
||||||
|
struct clk *clk = clk_get(dev, id);
|
||||||
|
|
||||||
|
if (clk == ERR_PTR(-ENOENT))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return clk;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)
|
#if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)
|
||||||
struct clk *of_clk_get(struct device_node *np, int index);
|
struct clk *of_clk_get(struct device_node *np, int index);
|
||||||
struct clk *of_clk_get_by_name(struct device_node *np, const char *name);
|
struct clk *of_clk_get_by_name(struct device_node *np, const char *name);
|
||||||
|
|
Loading…
Reference in a new issue