kernel: update 3.14 to 3.14.18
[openwrt.git] / target / linux / sunxi / patches-3.14 / 187-clk-sunxi-automatic-reparenting.patch
1 From b416520f239aeaa4207ebe84c22247cff2da444f 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 --- a/drivers/clk/sunxi/clk-factors.c
18 +++ b/drivers/clk/sunxi/clk-factors.c
19 @@ -77,6 +77,41 @@ static long clk_factors_round_rate(struc
20         return rate;
21  }
22  
23 +static long clk_factors_determine_rate(struct clk_hw *hw, unsigned long rate,
24 +                                      unsigned long *best_parent_rate,
25 +                                      struct clk **best_parent_p)
26 +{
27 +       struct clk *clk = hw->clk, *parent, *best_parent = NULL;
28 +       int i, num_parents;
29 +       unsigned long parent_rate, best = 0, child_rate, best_child_rate = 0;
30 +
31 +       /* find the parent that can help provide the fastest rate <= rate */
32 +       num_parents = __clk_get_num_parents(clk);
33 +       for (i = 0; i < num_parents; i++) {
34 +               parent = clk_get_parent_by_index(clk, i);
35 +               if (!parent)
36 +                       continue;
37 +               if (__clk_get_flags(clk) & CLK_SET_RATE_PARENT)
38 +                       parent_rate = __clk_round_rate(parent, rate);
39 +               else
40 +                       parent_rate = __clk_get_rate(parent);
41 +
42 +               child_rate = clk_factors_round_rate(hw, rate, &parent_rate);
43 +
44 +               if (child_rate <= rate && child_rate > best_child_rate) {
45 +                       best_parent = parent;
46 +                       best = parent_rate;
47 +                       best_child_rate = child_rate;
48 +               }
49 +       }
50 +
51 +       if (best_parent)
52 +               *best_parent_p = best_parent;
53 +       *best_parent_rate = best;
54 +
55 +       return best_child_rate;
56 +}
57 +
58  static int clk_factors_set_rate(struct clk_hw *hw, unsigned long rate,
59                                 unsigned long parent_rate)
60  {
61 @@ -113,6 +148,7 @@ static int clk_factors_set_rate(struct c
62  }
63  
64  const struct clk_ops clk_factors_ops = {
65 +       .determine_rate = clk_factors_determine_rate,
66         .recalc_rate = clk_factors_recalc_rate,
67         .round_rate = clk_factors_round_rate,
68         .set_rate = clk_factors_set_rate,