aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Boyd <sboyd@kernel.org>2018-12-19 18:09:14 -0500
committerStephen Boyd <sboyd@kernel.org>2019-03-01 14:17:22 -0500
commitcf13f2896807d516df79d118d1e82f9d2db3c336 (patch)
tree423de63a9bd0d46b5d4c8fb7f77ca917f42eca88
parentefa850487a6b6742699e3352d8562f5aba531ae7 (diff)
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>
-rw-r--r--drivers/clk/clk.c57
-rw-r--r--drivers/clk/clk.h11
-rw-r--r--drivers/clk/clkdev.c60
3 files changed, 62 insertions, 66 deletions
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 8244ef2ba977..937b8d092d17 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -4068,8 +4068,8 @@ void devm_of_clk_del_provider(struct device *dev)
4068} 4068}
4069EXPORT_SYMBOL(devm_of_clk_del_provider); 4069EXPORT_SYMBOL(devm_of_clk_del_provider);
4070 4070
4071int of_parse_clkspec(const struct device_node *np, int index, const char *name, 4071static int of_parse_clkspec(const struct device_node *np, int index,
4072 struct of_phandle_args *out_args) 4072 const char *name, struct of_phandle_args *out_args)
4073{ 4073{
4074 int ret = -ENOENT; 4074 int ret = -ENOENT;
4075 4075
@@ -4119,7 +4119,8 @@ __of_clk_get_hw_from_provider(struct of_clk_provider *provider,
4119 return __clk_get_hw(clk); 4119 return __clk_get_hw(clk);
4120} 4120}
4121 4121
4122struct clk_hw *of_clk_get_hw_from_clkspec(struct of_phandle_args *clkspec) 4122static struct clk_hw *
4123of_clk_get_hw_from_clkspec(struct of_phandle_args *clkspec)
4123{ 4124{
4124 struct of_clk_provider *provider; 4125 struct of_clk_provider *provider;
4125 struct clk_hw *hw = ERR_PTR(-EPROBE_DEFER); 4126 struct clk_hw *hw = ERR_PTR(-EPROBE_DEFER);
@@ -4156,6 +4157,56 @@ struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec)
4156} 4157}
4157EXPORT_SYMBOL_GPL(of_clk_get_from_provider); 4158EXPORT_SYMBOL_GPL(of_clk_get_from_provider);
4158 4159
4160struct 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
4177static 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
4186struct clk *of_clk_get(struct device_node *np, int index)
4187{
4188 return __of_clk_get(np, index, np->full_name, NULL);
4189}
4190EXPORT_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 */
4201struct 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}
4208EXPORT_SYMBOL(of_clk_get_by_name);
4209
4159/** 4210/**
4160 * of_clk_get_parent_count() - Count the number of clocks a device node has 4211 * of_clk_get_parent_count() - Count the number of clocks a device node has
4161 * @np: device node to count 4212 * @np: device node to count
diff --git a/drivers/clk/clk.h b/drivers/clk/clk.h
index 5ea2185e57a1..553f531cc232 100644
--- a/drivers/clk/clk.h
+++ b/drivers/clk/clk.h
@@ -9,9 +9,14 @@ struct device;
9struct of_phandle_args; 9struct of_phandle_args;
10 10
11#if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK) 11#if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)
12int of_parse_clkspec(const struct device_node *np, int index, const char *name, 12struct clk_hw *of_clk_get_hw(struct device_node *np,
13 struct of_phandle_args *out_args); 13 int index, const char *con_id);
14struct clk_hw *of_clk_get_hw_from_clkspec(struct of_phandle_args *clkspec); 14#else /* !CONFIG_COMMON_CLK || !CONFIG_OF */
15static 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}
15#endif 20#endif
16 21
17#ifdef CONFIG_COMMON_CLK 22#ifdef CONFIG_COMMON_CLK
diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index f2f4f2afd28c..d3758bf4305c 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -27,66 +27,6 @@
27static LIST_HEAD(clocks); 27static LIST_HEAD(clocks);
28static DEFINE_MUTEX(clocks_mutex); 28static DEFINE_MUTEX(clocks_mutex);
29 29
30#if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)
31static 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
48static 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
57struct clk *of_clk_get(struct device_node *np, int index)
58{
59 return __of_clk_get(np, index, np->full_name, NULL);
60}
61EXPORT_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 */
72struct 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}
79EXPORT_SYMBOL(of_clk_get_by_name);
80
81#else /* defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK) */
82
83static 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
90/* 30/*
91 * Find the correct struct clk for the device and connection ID. 31 * Find the correct struct clk for the device and connection ID.
92 * We do slightly fuzzy matching here: 32 * We do slightly fuzzy matching here: