Skip to content

Commit efa8504

Browse files
committed
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: Stephen Boyd <sboyd@kernel.org>
1 parent 4472287 commit efa8504

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

drivers/clk/clk.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct clk_core {
8282

8383
struct clk {
8484
struct clk_core *core;
85+
struct device *dev;
8586
const char *dev_id;
8687
const char *con_id;
8788
unsigned long min_rate;
@@ -3273,6 +3274,7 @@ static void free_clk(struct clk *clk)
32733274
/**
32743275
* clk_hw_create_clk: Allocate and link a clk consumer to a clk_core given
32753276
* a clk_hw
3277+
* @dev: clk consumer device
32763278
* @hw: clk_hw associated with the clk being consumed
32773279
* @dev_id: string describing device name
32783280
* @con_id: connection ID string on device
@@ -3281,7 +3283,7 @@ static void free_clk(struct clk *clk)
32813283
* consumers. It connects a consumer to the clk_core and clk_hw structures
32823284
* used by the framework and clk provider respectively.
32833285
*/
3284-
struct clk *clk_hw_create_clk(struct clk_hw *hw,
3286+
struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw,
32853287
const char *dev_id, const char *con_id)
32863288
{
32873289
struct clk *clk;
@@ -3295,6 +3297,7 @@ struct clk *clk_hw_create_clk(struct clk_hw *hw,
32953297
clk = alloc_clk(core, dev_id, con_id);
32963298
if (IS_ERR(clk))
32973299
return clk;
3300+
clk->dev = dev;
32983301

32993302
if (!try_module_get(core->owner)) {
33003303
free_clk(clk);
@@ -4149,7 +4152,7 @@ struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec)
41494152
{
41504153
struct clk_hw *hw = of_clk_get_hw_from_clkspec(clkspec);
41514154

4152-
return clk_hw_create_clk(hw, NULL, __func__);
4155+
return clk_hw_create_clk(NULL, hw, NULL, __func__);
41534156
}
41544157
EXPORT_SYMBOL_GPL(of_clk_get_from_provider);
41554158

drivers/clk/clk.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66

77
struct clk_hw;
8+
struct device;
9+
struct of_phandle_args;
810

911
#if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)
1012
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);
1315
#endif
1416

1517
#ifdef CONFIG_COMMON_CLK
16-
struct clk *clk_hw_create_clk(struct clk_hw *hw,
18+
struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw,
1719
const char *dev_id, const char *con_id);
1820
void __clk_put(struct clk *clk);
1921
#else
2022
/* All these casts to avoid ifdefs in clkdev... */
2123
static inline struct clk *
22-
clk_hw_create_clk(struct clk_hw *hw, const char *dev_id, const char *con_id)
24+
clk_hw_create_clk(struct device *dev, struct clk_hw *hw, const char *dev_id,
25+
const char *con_id)
2326
{
2427
return (struct clk *)hw;
2528
}

drivers/clk/clkdev.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static struct clk *__of_clk_get(struct device_node *np,
5151
{
5252
struct clk_hw *hw = of_clk_get_hw(np, index, con_id);
5353

54-
return clk_hw_create_clk(hw, dev_id, con_id);
54+
return clk_hw_create_clk(NULL, hw, dev_id, con_id);
5555
}
5656

5757
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)
130130
return cl;
131131
}
132132

133-
struct clk *clk_get_sys(const char *dev_id, const char *con_id)
133+
static struct clk *__clk_get_sys(struct device *dev, const char *dev_id,
134+
const char *con_id)
134135
{
135136
struct clk_lookup *cl;
136137
struct clk *clk = NULL;
@@ -141,14 +142,19 @@ struct clk *clk_get_sys(const char *dev_id, const char *con_id)
141142
if (!cl)
142143
goto out;
143144

144-
clk = clk_hw_create_clk(cl->clk_hw, dev_id, con_id);
145+
clk = clk_hw_create_clk(dev, cl->clk_hw, dev_id, con_id);
145146
if (IS_ERR(clk))
146147
cl = NULL;
147148
out:
148149
mutex_unlock(&clocks_mutex);
149150

150151
return cl ? clk : ERR_PTR(-ENOENT);
151152
}
153+
154+
struct clk *clk_get_sys(const char *dev_id, const char *con_id)
155+
{
156+
return __clk_get_sys(NULL, dev_id, con_id);
157+
}
152158
EXPORT_SYMBOL(clk_get_sys);
153159

154160
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)
159165
if (dev && dev->of_node) {
160166
hw = of_clk_get_hw(dev->of_node, 0, con_id);
161167
if (!IS_ERR(hw) || PTR_ERR(hw) == -EPROBE_DEFER)
162-
return clk_hw_create_clk(hw, dev_id, con_id);
168+
return clk_hw_create_clk(dev, hw, dev_id, con_id);
163169
}
164170

165-
return clk_get_sys(dev_id, con_id);
171+
return __clk_get_sys(dev, dev_id, con_id);
166172
}
167173
EXPORT_SYMBOL(clk_get);
168174

0 commit comments

Comments
 (0)