Skip to content

Commit cf13f28

Browse files
committed
clk: Move of_clk_*() APIs into clk.c from clkdev.c
The API between clk.c and clkdev.c is purely getting the clk_hw structure (or the struct clk if it's not CCF) and then turning that struct clk_hw pointer into a struct clk pointer via clk_hw_create_clk(). There's no need to complicate clkdev.c with these DT parsing details that are only relevant to the common clk framework. Move the DT parsing logic into the core framework and just expose the APIs to get a clk_hw pointer and convert it. 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 efa8504 commit cf13f28

File tree

3 files changed

+62
-66
lines changed

3 files changed

+62
-66
lines changed

drivers/clk/clk.c

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4068,8 +4068,8 @@ void devm_of_clk_del_provider(struct device *dev)
40684068
}
40694069
EXPORT_SYMBOL(devm_of_clk_del_provider);
40704070

4071-
int of_parse_clkspec(const struct device_node *np, int index, const char *name,
4072-
struct of_phandle_args *out_args)
4071+
static int of_parse_clkspec(const struct device_node *np, int index,
4072+
const char *name, struct of_phandle_args *out_args)
40734073
{
40744074
int ret = -ENOENT;
40754075

@@ -4119,7 +4119,8 @@ __of_clk_get_hw_from_provider(struct of_clk_provider *provider,
41194119
return __clk_get_hw(clk);
41204120
}
41214121

4122-
struct clk_hw *of_clk_get_hw_from_clkspec(struct of_phandle_args *clkspec)
4122+
static struct clk_hw *
4123+
of_clk_get_hw_from_clkspec(struct of_phandle_args *clkspec)
41234124
{
41244125
struct of_clk_provider *provider;
41254126
struct clk_hw *hw = ERR_PTR(-EPROBE_DEFER);
@@ -4156,6 +4157,56 @@ struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec)
41564157
}
41574158
EXPORT_SYMBOL_GPL(of_clk_get_from_provider);
41584159

4160+
struct clk_hw *of_clk_get_hw(struct device_node *np, int index,
4161+
const char *con_id)
4162+
{
4163+
int ret;
4164+
struct clk_hw *hw;
4165+
struct of_phandle_args clkspec;
4166+
4167+
ret = of_parse_clkspec(np, index, con_id, &clkspec);
4168+
if (ret)
4169+
return ERR_PTR(ret);
4170+
4171+
hw = of_clk_get_hw_from_clkspec(&clkspec);
4172+
of_node_put(clkspec.np);
4173+
4174+
return hw;
4175+
}
4176+
4177+
static struct clk *__of_clk_get(struct device_node *np,
4178+
int index, const char *dev_id,
4179+
const char *con_id)
4180+
{
4181+
struct clk_hw *hw = of_clk_get_hw(np, index, con_id);
4182+
4183+
return clk_hw_create_clk(NULL, hw, dev_id, con_id);
4184+
}
4185+
4186+
struct clk *of_clk_get(struct device_node *np, int index)
4187+
{
4188+
return __of_clk_get(np, index, np->full_name, NULL);
4189+
}
4190+
EXPORT_SYMBOL(of_clk_get);
4191+
4192+
/**
4193+
* of_clk_get_by_name() - Parse and lookup a clock referenced by a device node
4194+
* @np: pointer to clock consumer node
4195+
* @name: name of consumer's clock input, or NULL for the first clock reference
4196+
*
4197+
* This function parses the clocks and clock-names properties,
4198+
* and uses them to look up the struct clk from the registered list of clock
4199+
* providers.
4200+
*/
4201+
struct clk *of_clk_get_by_name(struct device_node *np, const char *name)
4202+
{
4203+
if (!np)
4204+
return ERR_PTR(-ENOENT);
4205+
4206+
return __of_clk_get(np, -1, np->full_name, name);
4207+
}
4208+
EXPORT_SYMBOL(of_clk_get_by_name);
4209+
41594210
/**
41604211
* of_clk_get_parent_count() - Count the number of clocks a device node has
41614212
* @np: device node to count

drivers/clk/clk.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ struct device;
99
struct of_phandle_args;
1010

1111
#if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)
12-
int of_parse_clkspec(const struct device_node *np, int index, const char *name,
13-
struct of_phandle_args *out_args);
14-
struct clk_hw *of_clk_get_hw_from_clkspec(struct of_phandle_args *clkspec);
12+
struct clk_hw *of_clk_get_hw(struct device_node *np,
13+
int index, const char *con_id);
14+
#else /* !CONFIG_COMMON_CLK || !CONFIG_OF */
15+
static inline struct clk_hw *of_clk_get_hw(struct device_node *np,
16+
int index, const char *con_id)
17+
{
18+
return ERR_PTR(-ENOENT);
19+
}
1520
#endif
1621

1722
#ifdef CONFIG_COMMON_CLK

drivers/clk/clkdev.c

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -27,66 +27,6 @@
2727
static LIST_HEAD(clocks);
2828
static DEFINE_MUTEX(clocks_mutex);
2929

30-
#if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)
31-
static struct clk_hw *of_clk_get_hw(struct device_node *np,
32-
int index, const char *con_id)
33-
{
34-
int ret;
35-
struct clk_hw *hw;
36-
struct of_phandle_args clkspec;
37-
38-
ret = of_parse_clkspec(np, index, con_id, &clkspec);
39-
if (ret)
40-
return ERR_PTR(ret);
41-
42-
hw = of_clk_get_hw_from_clkspec(&clkspec);
43-
of_node_put(clkspec.np);
44-
45-
return hw;
46-
}
47-
48-
static struct clk *__of_clk_get(struct device_node *np,
49-
int index, const char *dev_id,
50-
const char *con_id)
51-
{
52-
struct clk_hw *hw = of_clk_get_hw(np, index, con_id);
53-
54-
return clk_hw_create_clk(NULL, hw, dev_id, con_id);
55-
}
56-
57-
struct clk *of_clk_get(struct device_node *np, int index)
58-
{
59-
return __of_clk_get(np, index, np->full_name, NULL);
60-
}
61-
EXPORT_SYMBOL(of_clk_get);
62-
63-
/**
64-
* of_clk_get_by_name() - Parse and lookup a clock referenced by a device node
65-
* @np: pointer to clock consumer node
66-
* @name: name of consumer's clock input, or NULL for the first clock reference
67-
*
68-
* This function parses the clocks and clock-names properties,
69-
* and uses them to look up the struct clk from the registered list of clock
70-
* providers.
71-
*/
72-
struct clk *of_clk_get_by_name(struct device_node *np, const char *name)
73-
{
74-
if (!np)
75-
return ERR_PTR(-ENOENT);
76-
77-
return __of_clk_get(np, -1, np->full_name, name);
78-
}
79-
EXPORT_SYMBOL(of_clk_get_by_name);
80-
81-
#else /* defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK) */
82-
83-
static struct clk_hw *of_clk_get_hw(struct device_node *np,
84-
int index, const char *con_id)
85-
{
86-
return ERR_PTR(-ENOENT);
87-
}
88-
#endif
89-
9030
/*
9131
* Find the correct struct clk for the device and connection ID.
9232
* We do slightly fuzzy matching here:

0 commit comments

Comments
 (0)