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
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 This commit implements .determine_rate, so that our factor clocks can be
10 reparented when needed.
12 Signed-off-by: Emilio López <emilio@elopez.com.ar>
14 drivers/clk/sunxi/clk-factors.c | 36 ++++++++++++++++++++++++++++++++++++
15 1 file changed, 36 insertions(+)
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,
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)
29 + struct clk *clk = hw->clk, *parent, *best_parent = NULL;
31 + unsigned long parent_rate, best = 0, child_rate, best_child_rate = 0;
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);
39 + if (__clk_get_flags(clk) & CLK_SET_RATE_PARENT)
40 + parent_rate = __clk_round_rate(parent, rate);
42 + parent_rate = __clk_get_rate(parent);
44 + child_rate = clk_factors_round_rate(hw, rate, &parent_rate);
46 + if (child_rate <= rate && child_rate > best_child_rate) {
47 + best_parent = parent;
49 + best_child_rate = child_rate;
54 + *best_parent_p = best_parent;
55 + *best_parent_rate = best;
57 + return best_child_rate;
60 static int clk_factors_set_rate(struct clk_hw *hw, unsigned long rate,
61 unsigned long parent_rate)
63 @@ -113,6 +148,7 @@ static int clk_factors_set_rate(struct clk_hw *hw, unsigned long rate,
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,