c772b9fe6f100c6824837b46eca2884f4d1cb2c5
[openwrt/openwrt.git] / target / linux / sunxi / patches-3.13 / 123-clk-sunxi-automatic-reparenting.patch
1 From 04b5b3f9c83c0c0b472c4704d83ec7f56a485a21 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= <emilio@elopez.com.ar>
3 Date: Thu, 5 Sep 2013 19:52:41 -0300
4 Subject: [PATCH] clk: sunxi: factors: automatic reparenting support
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 This commit implements .determine_rate, so that our factor clocks can be
10 reparented when needed.
11
12 Signed-off-by: Emilio López <emilio@elopez.com.ar>
13 ---
14 drivers/clk/sunxi/clk-factors.c | 36 ++++++++++++++++++++++++++++++++++++
15 1 file changed, 36 insertions(+)
16
17 diff --git a/drivers/clk/sunxi/clk-factors.c b/drivers/clk/sunxi/clk-factors.c
18 index 9e23264..3806d97 100644
19 --- a/drivers/clk/sunxi/clk-factors.c
20 +++ b/drivers/clk/sunxi/clk-factors.c
21 @@ -77,6 +77,41 @@ static long clk_factors_round_rate(struct clk_hw *hw, unsigned long rate,
22 return rate;
23 }
24
25 +static long clk_factors_determine_rate(struct clk_hw *hw, unsigned long rate,
26 + unsigned long *best_parent_rate,
27 + struct clk **best_parent_p)
28 +{
29 + struct clk *clk = hw->clk, *parent, *best_parent = NULL;
30 + int i, num_parents;
31 + unsigned long parent_rate, best = 0, child_rate, best_child_rate = 0;
32 +
33 + /* find the parent that can help provide the fastest rate <= rate */
34 + num_parents = __clk_get_num_parents(clk);
35 + for (i = 0; i < num_parents; i++) {
36 + parent = clk_get_parent_by_index(clk, i);
37 + if (!parent)
38 + continue;
39 + if (__clk_get_flags(clk) & CLK_SET_RATE_PARENT)
40 + parent_rate = __clk_round_rate(parent, rate);
41 + else
42 + parent_rate = __clk_get_rate(parent);
43 +
44 + child_rate = clk_factors_round_rate(hw, rate, &parent_rate);
45 +
46 + if (child_rate <= rate && child_rate > best_child_rate) {
47 + best_parent = parent;
48 + best = parent_rate;
49 + best_child_rate = child_rate;
50 + }
51 + }
52 +
53 + if (best_parent)
54 + *best_parent_p = best_parent;
55 + *best_parent_rate = best;
56 +
57 + return best_child_rate;
58 +}
59 +
60 static int clk_factors_set_rate(struct clk_hw *hw, unsigned long rate,
61 unsigned long parent_rate)
62 {
63 @@ -113,6 +148,7 @@ static int clk_factors_set_rate(struct clk_hw *hw, unsigned long rate,
64 }
65
66 const struct clk_ops clk_factors_ops = {
67 + .determine_rate = clk_factors_determine_rate,
68 .recalc_rate = clk_factors_recalc_rate,
69 .round_rate = clk_factors_round_rate,
70 .set_rate = clk_factors_set_rate,
71 --
72 1.8.5.1
73