diff options
author | Stephen Boyd <sboyd@codeaurora.org> | 2014-09-04 16:21:50 -0400 |
---|---|---|
committer | Stephen Boyd <sboyd@codeaurora.org> | 2014-09-22 18:16:52 -0400 |
commit | 50c6a50344c58f73c697e2fe38960dc176a2e69f (patch) | |
tree | 013a93a48415beb8abeeebdf7b6919673867ad31 | |
parent | dc1b3f657f25798b2dc9ed8928b80eb3183019a2 (diff) |
clk: qcom: Consolidate frequency finding logic
There are two find_freq() functions in clk-rcg.c and clk-rcg2.c
that are almost exactly the same. Consolidate them into one
function to save on some code space.
Cc: Mike Turquette <mturquette@linaro.org>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
-rw-r--r-- | drivers/clk/qcom/clk-rcg.c | 20 | ||||
-rw-r--r-- | drivers/clk/qcom/clk-rcg2.c | 19 | ||||
-rw-r--r-- | drivers/clk/qcom/common.c | 16 | ||||
-rw-r--r-- | drivers/clk/qcom/common.h | 4 |
4 files changed, 27 insertions, 32 deletions
diff --git a/drivers/clk/qcom/clk-rcg.c b/drivers/clk/qcom/clk-rcg.c index b638c5846dbf..3db106b74934 100644 --- a/drivers/clk/qcom/clk-rcg.c +++ b/drivers/clk/qcom/clk-rcg.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <asm/div64.h> | 21 | #include <asm/div64.h> |
22 | 22 | ||
23 | #include "clk-rcg.h" | 23 | #include "clk-rcg.h" |
24 | #include "common.h" | ||
24 | 25 | ||
25 | static u32 ns_to_src(struct src_sel *s, u32 ns) | 26 | static u32 ns_to_src(struct src_sel *s, u32 ns) |
26 | { | 27 | { |
@@ -360,26 +361,13 @@ clk_dyn_rcg_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) | |||
360 | } | 361 | } |
361 | } | 362 | } |
362 | 363 | ||
363 | static const | ||
364 | struct freq_tbl *find_freq(const struct freq_tbl *f, unsigned long rate) | ||
365 | { | ||
366 | if (!f) | ||
367 | return NULL; | ||
368 | |||
369 | for (; f->freq; f++) | ||
370 | if (rate <= f->freq) | ||
371 | return f; | ||
372 | |||
373 | return NULL; | ||
374 | } | ||
375 | |||
376 | static long _freq_tbl_determine_rate(struct clk_hw *hw, | 364 | static long _freq_tbl_determine_rate(struct clk_hw *hw, |
377 | const struct freq_tbl *f, unsigned long rate, | 365 | const struct freq_tbl *f, unsigned long rate, |
378 | unsigned long *p_rate, struct clk **p) | 366 | unsigned long *p_rate, struct clk **p) |
379 | { | 367 | { |
380 | unsigned long clk_flags; | 368 | unsigned long clk_flags; |
381 | 369 | ||
382 | f = find_freq(f, rate); | 370 | f = qcom_find_freq(f, rate); |
383 | if (!f) | 371 | if (!f) |
384 | return -EINVAL; | 372 | return -EINVAL; |
385 | 373 | ||
@@ -477,7 +465,7 @@ static int clk_rcg_set_rate(struct clk_hw *hw, unsigned long rate, | |||
477 | struct clk_rcg *rcg = to_clk_rcg(hw); | 465 | struct clk_rcg *rcg = to_clk_rcg(hw); |
478 | const struct freq_tbl *f; | 466 | const struct freq_tbl *f; |
479 | 467 | ||
480 | f = find_freq(rcg->freq_tbl, rate); | 468 | f = qcom_find_freq(rcg->freq_tbl, rate); |
481 | if (!f) | 469 | if (!f) |
482 | return -EINVAL; | 470 | return -EINVAL; |
483 | 471 | ||
@@ -497,7 +485,7 @@ static int __clk_dyn_rcg_set_rate(struct clk_hw *hw, unsigned long rate) | |||
497 | struct clk_dyn_rcg *rcg = to_clk_dyn_rcg(hw); | 485 | struct clk_dyn_rcg *rcg = to_clk_dyn_rcg(hw); |
498 | const struct freq_tbl *f; | 486 | const struct freq_tbl *f; |
499 | 487 | ||
500 | f = find_freq(rcg->freq_tbl, rate); | 488 | f = qcom_find_freq(rcg->freq_tbl, rate); |
501 | if (!f) | 489 | if (!f) |
502 | return -EINVAL; | 490 | return -EINVAL; |
503 | 491 | ||
diff --git a/drivers/clk/qcom/clk-rcg2.c b/drivers/clk/qcom/clk-rcg2.c index cd185d5cc67a..cfa9eb4fe9ca 100644 --- a/drivers/clk/qcom/clk-rcg2.c +++ b/drivers/clk/qcom/clk-rcg2.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <asm/div64.h> | 24 | #include <asm/div64.h> |
25 | 25 | ||
26 | #include "clk-rcg.h" | 26 | #include "clk-rcg.h" |
27 | #include "common.h" | ||
27 | 28 | ||
28 | #define CMD_REG 0x0 | 29 | #define CMD_REG 0x0 |
29 | #define CMD_UPDATE BIT(0) | 30 | #define CMD_UPDATE BIT(0) |
@@ -172,27 +173,13 @@ clk_rcg2_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) | |||
172 | return calc_rate(parent_rate, m, n, mode, hid_div); | 173 | return calc_rate(parent_rate, m, n, mode, hid_div); |
173 | } | 174 | } |
174 | 175 | ||
175 | static const | ||
176 | struct freq_tbl *find_freq(const struct freq_tbl *f, unsigned long rate) | ||
177 | { | ||
178 | if (!f) | ||
179 | return NULL; | ||
180 | |||
181 | for (; f->freq; f++) | ||
182 | if (rate <= f->freq) | ||
183 | return f; | ||
184 | |||
185 | /* Default to our fastest rate */ | ||
186 | return f - 1; | ||
187 | } | ||
188 | |||
189 | static long _freq_tbl_determine_rate(struct clk_hw *hw, | 176 | static long _freq_tbl_determine_rate(struct clk_hw *hw, |
190 | const struct freq_tbl *f, unsigned long rate, | 177 | const struct freq_tbl *f, unsigned long rate, |
191 | unsigned long *p_rate, struct clk **p) | 178 | unsigned long *p_rate, struct clk **p) |
192 | { | 179 | { |
193 | unsigned long clk_flags; | 180 | unsigned long clk_flags; |
194 | 181 | ||
195 | f = find_freq(f, rate); | 182 | f = qcom_find_freq(f, rate); |
196 | if (!f) | 183 | if (!f) |
197 | return -EINVAL; | 184 | return -EINVAL; |
198 | 185 | ||
@@ -268,7 +255,7 @@ static int __clk_rcg2_set_rate(struct clk_hw *hw, unsigned long rate) | |||
268 | struct clk_rcg2 *rcg = to_clk_rcg2(hw); | 255 | struct clk_rcg2 *rcg = to_clk_rcg2(hw); |
269 | const struct freq_tbl *f; | 256 | const struct freq_tbl *f; |
270 | 257 | ||
271 | f = find_freq(rcg->freq_tbl, rate); | 258 | f = qcom_find_freq(rcg->freq_tbl, rate); |
272 | if (!f) | 259 | if (!f) |
273 | return -EINVAL; | 260 | return -EINVAL; |
274 | 261 | ||
diff --git a/drivers/clk/qcom/common.c b/drivers/clk/qcom/common.c index eeb3eea01f4c..e20d947db3e5 100644 --- a/drivers/clk/qcom/common.c +++ b/drivers/clk/qcom/common.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/reset-controller.h> | 18 | #include <linux/reset-controller.h> |
19 | 19 | ||
20 | #include "common.h" | 20 | #include "common.h" |
21 | #include "clk-rcg.h" | ||
21 | #include "clk-regmap.h" | 22 | #include "clk-regmap.h" |
22 | #include "reset.h" | 23 | #include "reset.h" |
23 | 24 | ||
@@ -27,6 +28,21 @@ struct qcom_cc { | |||
27 | struct clk *clks[]; | 28 | struct clk *clks[]; |
28 | }; | 29 | }; |
29 | 30 | ||
31 | const | ||
32 | struct freq_tbl *qcom_find_freq(const struct freq_tbl *f, unsigned long rate) | ||
33 | { | ||
34 | if (!f) | ||
35 | return NULL; | ||
36 | |||
37 | for (; f->freq; f++) | ||
38 | if (rate <= f->freq) | ||
39 | return f; | ||
40 | |||
41 | /* Default to our fastest rate */ | ||
42 | return f - 1; | ||
43 | } | ||
44 | EXPORT_SYMBOL_GPL(qcom_find_freq); | ||
45 | |||
30 | struct regmap * | 46 | struct regmap * |
31 | qcom_cc_map(struct platform_device *pdev, const struct qcom_cc_desc *desc) | 47 | qcom_cc_map(struct platform_device *pdev, const struct qcom_cc_desc *desc) |
32 | { | 48 | { |
diff --git a/drivers/clk/qcom/common.h b/drivers/clk/qcom/common.h index 2765e9d3da97..f519322acdf3 100644 --- a/drivers/clk/qcom/common.h +++ b/drivers/clk/qcom/common.h | |||
@@ -18,6 +18,7 @@ struct regmap_config; | |||
18 | struct clk_regmap; | 18 | struct clk_regmap; |
19 | struct qcom_reset_map; | 19 | struct qcom_reset_map; |
20 | struct regmap; | 20 | struct regmap; |
21 | struct freq_tbl; | ||
21 | 22 | ||
22 | struct qcom_cc_desc { | 23 | struct qcom_cc_desc { |
23 | const struct regmap_config *config; | 24 | const struct regmap_config *config; |
@@ -27,6 +28,9 @@ struct qcom_cc_desc { | |||
27 | size_t num_resets; | 28 | size_t num_resets; |
28 | }; | 29 | }; |
29 | 30 | ||
31 | extern const struct freq_tbl *qcom_find_freq(const struct freq_tbl *f, | ||
32 | unsigned long rate); | ||
33 | |||
30 | extern struct regmap *qcom_cc_map(struct platform_device *pdev, | 34 | extern struct regmap *qcom_cc_map(struct platform_device *pdev, |
31 | const struct qcom_cc_desc *desc); | 35 | const struct qcom_cc_desc *desc); |
32 | extern int qcom_cc_really_probe(struct platform_device *pdev, | 36 | extern int qcom_cc_really_probe(struct platform_device *pdev, |