clk: add api to get clk consumer from clk_hw
clk_register() is deprecated. Using 'clk' member of struct clk_hw is discouraged. With this constraint, it is difficult for driver to register clocks using the clk_hw API and then use the clock with the consumer API This adds a simple helper, clk_hw_get_clk(), to get a struct clk from a struct clk_hw. Like other clk_get() variant, each call to this helper must be balanced with a call to clk_put(). To make life easier on the consumers, a memory managed version is provided as well. Cc: Martin Blumenstingl <martin.blumenstingl@googlemail.com> Signed-off-by: Jerome Brunet <jbrunet@baylibre.com> Link: https://lore.kernel.org/r/20201021162147.563655-3-jbrunet@baylibre.com Tested-by: Kevin Hilman <khilman@baylibre.com> [sboyd@kernel.org: Fix kernel-doc] Signed-off-by: Stephen Boyd <sboyd@kernel.org>
This commit is contained in:
parent
e5a4b9b99e
commit
30d6f8c15d
2 changed files with 66 additions and 0 deletions
|
@ -3667,6 +3667,24 @@ struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw,
|
||||||
return clk;
|
return clk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clk_hw_get_clk - get clk consumer given an clk_hw
|
||||||
|
* @hw: clk_hw associated with the clk being consumed
|
||||||
|
* @con_id: connection ID string on device
|
||||||
|
*
|
||||||
|
* Returns: new clk consumer
|
||||||
|
* This is the function to be used by providers which need
|
||||||
|
* to get a consumer clk and act on the clock element
|
||||||
|
* Calls to this function must be balanced with calls clk_put()
|
||||||
|
*/
|
||||||
|
struct clk *clk_hw_get_clk(struct clk_hw *hw, const char *con_id)
|
||||||
|
{
|
||||||
|
struct device *dev = hw->core->dev;
|
||||||
|
|
||||||
|
return clk_hw_create_clk(dev, hw, dev_name(dev), con_id);
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(clk_hw_get_clk);
|
||||||
|
|
||||||
static int clk_cpy_name(const char **dst_p, const char *src, bool must_exist)
|
static int clk_cpy_name(const char **dst_p, const char *src, bool must_exist)
|
||||||
{
|
{
|
||||||
const char *dst;
|
const char *dst;
|
||||||
|
@ -4187,6 +4205,49 @@ void devm_clk_hw_unregister(struct device *dev, struct clk_hw *hw)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(devm_clk_hw_unregister);
|
EXPORT_SYMBOL_GPL(devm_clk_hw_unregister);
|
||||||
|
|
||||||
|
static void devm_clk_release(struct device *dev, void *res)
|
||||||
|
{
|
||||||
|
clk_put(*(struct clk **)res);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* devm_clk_hw_get_clk - resource managed clk_hw_get_clk()
|
||||||
|
* @dev: device that is registering this clock
|
||||||
|
* @hw: clk_hw associated with the clk being consumed
|
||||||
|
* @con_id: connection ID string on device
|
||||||
|
*
|
||||||
|
* Managed clk_hw_get_clk(). Clocks got with this function are
|
||||||
|
* automatically clk_put() on driver detach. See clk_put()
|
||||||
|
* for more information.
|
||||||
|
*/
|
||||||
|
struct clk *devm_clk_hw_get_clk(struct device *dev, struct clk_hw *hw,
|
||||||
|
const char *con_id)
|
||||||
|
{
|
||||||
|
struct clk *clk;
|
||||||
|
struct clk **clkp;
|
||||||
|
|
||||||
|
/* This should not happen because it would mean we have drivers
|
||||||
|
* passing around clk_hw pointers instead of having the caller use
|
||||||
|
* proper clk_get() style APIs
|
||||||
|
*/
|
||||||
|
WARN_ON_ONCE(dev != hw->core->dev);
|
||||||
|
|
||||||
|
clkp = devres_alloc(devm_clk_release, sizeof(*clkp), GFP_KERNEL);
|
||||||
|
if (!clkp)
|
||||||
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
|
clk = clk_hw_get_clk(hw, con_id);
|
||||||
|
if (!IS_ERR(clk)) {
|
||||||
|
*clkp = clk;
|
||||||
|
devres_add(dev, clkp);
|
||||||
|
} else {
|
||||||
|
devres_free(clkp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return clk;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(devm_clk_hw_get_clk);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* clkdev helpers
|
* clkdev helpers
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1088,6 +1088,11 @@ static inline struct clk_hw *__clk_get_hw(struct clk *clk)
|
||||||
return (struct clk_hw *)clk;
|
return (struct clk_hw *)clk;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct clk *clk_hw_get_clk(struct clk_hw *hw, const char *con_id);
|
||||||
|
struct clk *devm_clk_hw_get_clk(struct device *dev, struct clk_hw *hw,
|
||||||
|
const char *con_id);
|
||||||
|
|
||||||
unsigned int clk_hw_get_num_parents(const struct clk_hw *hw);
|
unsigned int clk_hw_get_num_parents(const struct clk_hw *hw);
|
||||||
struct clk_hw *clk_hw_get_parent(const struct clk_hw *hw);
|
struct clk_hw *clk_hw_get_parent(const struct clk_hw *hw);
|
||||||
struct clk_hw *clk_hw_get_parent_by_index(const struct clk_hw *hw,
|
struct clk_hw *clk_hw_get_parent_by_index(const struct clk_hw *hw,
|
||||||
|
|
Loading…
Add table
Reference in a new issue