Commit efa85048 authored by Stephen Boyd's avatar Stephen Boyd

clk: Inform the core about consumer devices

We'd like to have a pointer to the device that's consuming a particular
clk in the clk framework so we can link the consumer to the clk provider
with a PM device link. Add a device argument to clk_hw_create_clk() for
this so it can be used in subsequent patches to add and remove the link.

Cc: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Jerome Brunet <jbrunet@baylibre.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Michael Turquette <mturquette@baylibre.com>
Cc: Jeffrey Hugo <jhugo@codeaurora.org>
Cc: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: default avatarStephen Boyd <sboyd@kernel.org>
parent 4472287a
...@@ -82,6 +82,7 @@ struct clk_core { ...@@ -82,6 +82,7 @@ struct clk_core {
struct clk { struct clk {
struct clk_core *core; struct clk_core *core;
struct device *dev;
const char *dev_id; const char *dev_id;
const char *con_id; const char *con_id;
unsigned long min_rate; unsigned long min_rate;
...@@ -3273,6 +3274,7 @@ static void free_clk(struct clk *clk) ...@@ -3273,6 +3274,7 @@ static void free_clk(struct clk *clk)
/** /**
* clk_hw_create_clk: Allocate and link a clk consumer to a clk_core given * clk_hw_create_clk: Allocate and link a clk consumer to a clk_core given
* a clk_hw * a clk_hw
* @dev: clk consumer device
* @hw: clk_hw associated with the clk being consumed * @hw: clk_hw associated with the clk being consumed
* @dev_id: string describing device name * @dev_id: string describing device name
* @con_id: connection ID string on device * @con_id: connection ID string on device
...@@ -3281,7 +3283,7 @@ static void free_clk(struct clk *clk) ...@@ -3281,7 +3283,7 @@ static void free_clk(struct clk *clk)
* consumers. It connects a consumer to the clk_core and clk_hw structures * consumers. It connects a consumer to the clk_core and clk_hw structures
* used by the framework and clk provider respectively. * used by the framework and clk provider respectively.
*/ */
struct clk *clk_hw_create_clk(struct clk_hw *hw, struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw,
const char *dev_id, const char *con_id) const char *dev_id, const char *con_id)
{ {
struct clk *clk; struct clk *clk;
...@@ -3295,6 +3297,7 @@ struct clk *clk_hw_create_clk(struct clk_hw *hw, ...@@ -3295,6 +3297,7 @@ struct clk *clk_hw_create_clk(struct clk_hw *hw,
clk = alloc_clk(core, dev_id, con_id); clk = alloc_clk(core, dev_id, con_id);
if (IS_ERR(clk)) if (IS_ERR(clk))
return clk; return clk;
clk->dev = dev;
if (!try_module_get(core->owner)) { if (!try_module_get(core->owner)) {
free_clk(clk); free_clk(clk);
...@@ -4149,7 +4152,7 @@ struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec) ...@@ -4149,7 +4152,7 @@ struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec)
{ {
struct clk_hw *hw = of_clk_get_hw_from_clkspec(clkspec); struct clk_hw *hw = of_clk_get_hw_from_clkspec(clkspec);
return clk_hw_create_clk(hw, NULL, __func__); return clk_hw_create_clk(NULL, hw, NULL, __func__);
} }
EXPORT_SYMBOL_GPL(of_clk_get_from_provider); EXPORT_SYMBOL_GPL(of_clk_get_from_provider);
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
*/ */
struct clk_hw; struct clk_hw;
struct device;
struct of_phandle_args;
#if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK) #if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)
int of_parse_clkspec(const struct device_node *np, int index, const char *name, int of_parse_clkspec(const struct device_node *np, int index, const char *name,
...@@ -13,13 +15,14 @@ struct clk_hw *of_clk_get_hw_from_clkspec(struct of_phandle_args *clkspec); ...@@ -13,13 +15,14 @@ struct clk_hw *of_clk_get_hw_from_clkspec(struct of_phandle_args *clkspec);
#endif #endif
#ifdef CONFIG_COMMON_CLK #ifdef CONFIG_COMMON_CLK
struct clk *clk_hw_create_clk(struct clk_hw *hw, struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw,
const char *dev_id, const char *con_id); const char *dev_id, const char *con_id);
void __clk_put(struct clk *clk); void __clk_put(struct clk *clk);
#else #else
/* All these casts to avoid ifdefs in clkdev... */ /* All these casts to avoid ifdefs in clkdev... */
static inline struct clk * static inline struct clk *
clk_hw_create_clk(struct clk_hw *hw, const char *dev_id, const char *con_id) clk_hw_create_clk(struct device *dev, struct clk_hw *hw, const char *dev_id,
const char *con_id)
{ {
return (struct clk *)hw; return (struct clk *)hw;
} }
......
...@@ -51,7 +51,7 @@ static struct clk *__of_clk_get(struct device_node *np, ...@@ -51,7 +51,7 @@ static struct clk *__of_clk_get(struct device_node *np,
{ {
struct clk_hw *hw = of_clk_get_hw(np, index, con_id); struct clk_hw *hw = of_clk_get_hw(np, index, con_id);
return clk_hw_create_clk(hw, dev_id, con_id); return clk_hw_create_clk(NULL, hw, dev_id, con_id);
} }
struct clk *of_clk_get(struct device_node *np, int index) struct clk *of_clk_get(struct device_node *np, int index)
...@@ -130,7 +130,8 @@ static struct clk_lookup *clk_find(const char *dev_id, const char *con_id) ...@@ -130,7 +130,8 @@ static struct clk_lookup *clk_find(const char *dev_id, const char *con_id)
return cl; return cl;
} }
struct clk *clk_get_sys(const char *dev_id, const char *con_id) static struct clk *__clk_get_sys(struct device *dev, const char *dev_id,
const char *con_id)
{ {
struct clk_lookup *cl; struct clk_lookup *cl;
struct clk *clk = NULL; struct clk *clk = NULL;
...@@ -141,7 +142,7 @@ struct clk *clk_get_sys(const char *dev_id, const char *con_id) ...@@ -141,7 +142,7 @@ struct clk *clk_get_sys(const char *dev_id, const char *con_id)
if (!cl) if (!cl)
goto out; goto out;
clk = clk_hw_create_clk(cl->clk_hw, dev_id, con_id); clk = clk_hw_create_clk(dev, cl->clk_hw, dev_id, con_id);
if (IS_ERR(clk)) if (IS_ERR(clk))
cl = NULL; cl = NULL;
out: out:
...@@ -149,6 +150,11 @@ struct clk *clk_get_sys(const char *dev_id, const char *con_id) ...@@ -149,6 +150,11 @@ struct clk *clk_get_sys(const char *dev_id, const char *con_id)
return cl ? clk : ERR_PTR(-ENOENT); return cl ? clk : ERR_PTR(-ENOENT);
} }
struct clk *clk_get_sys(const char *dev_id, const char *con_id)
{
return __clk_get_sys(NULL, dev_id, con_id);
}
EXPORT_SYMBOL(clk_get_sys); EXPORT_SYMBOL(clk_get_sys);
struct clk *clk_get(struct device *dev, const char *con_id) struct clk *clk_get(struct device *dev, const char *con_id)
...@@ -159,10 +165,10 @@ struct clk *clk_get(struct device *dev, const char *con_id) ...@@ -159,10 +165,10 @@ struct clk *clk_get(struct device *dev, const char *con_id)
if (dev && dev->of_node) { if (dev && dev->of_node) {
hw = of_clk_get_hw(dev->of_node, 0, con_id); hw = of_clk_get_hw(dev->of_node, 0, con_id);
if (!IS_ERR(hw) || PTR_ERR(hw) == -EPROBE_DEFER) if (!IS_ERR(hw) || PTR_ERR(hw) == -EPROBE_DEFER)
return clk_hw_create_clk(hw, dev_id, con_id); return clk_hw_create_clk(dev, hw, dev_id, con_id);
} }
return clk_get_sys(dev_id, con_id); return __clk_get_sys(dev, dev_id, con_id);
} }
EXPORT_SYMBOL(clk_get); EXPORT_SYMBOL(clk_get);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment