kernel: update kernel 4.4 to version 4.4.110
[librecmc/librecmc.git] / target / linux / ipq806x / patches-4.4 / 136-clk-Add-safe-switch-hook.patch
1 From f7a00ea959be31f9b742042294a359d508edce94 Mon Sep 17 00:00:00 2001
2 From: Stephen Boyd <sboyd@codeaurora.org>
3 Date: Fri, 20 Mar 2015 23:45:23 -0700
4 Subject: [PATCH] clk: Add safe switch hook
5
6 Sometimes clocks can't accept their parent source turning off
7 while the source is reprogrammed to a different rate. Most
8 notably CPU clocks require a way to switch away from the current
9 PLL they're running on, reprogram that PLL to a new rate, and
10 then switch back to the PLL with the new rate once they're done.
11 Add a hook that drivers can implement allowing them to return a
12 'safe parent' that they can switch their parent to while the
13 upstream source is reprogrammed to support this.
14
15 Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
16 Signed-off-by: Ram Chandra Jangir <rjangi@codeaurora.org>
17 ---
18  drivers/clk/clk.c            | 61 ++++++++++++++++++++++++++++++++++++++------
19  include/linux/clk-provider.h |  1 +
20  2 files changed, 54 insertions(+), 8 deletions(-)
21
22 --- a/drivers/clk/clk.c
23 +++ b/drivers/clk/clk.c
24 @@ -51,9 +51,12 @@ struct clk_core {
25         struct clk_core         **parents;
26         u8                      num_parents;
27         u8                      new_parent_index;
28 +       u8                      safe_parent_index;
29         unsigned long           rate;
30         unsigned long           req_rate;
31 +       unsigned long           old_rate;
32         unsigned long           new_rate;
33 +       struct clk_core         *safe_parent;
34         struct clk_core         *new_parent;
35         struct clk_core         *new_child;
36         unsigned long           flags;
37 @@ -1271,7 +1274,8 @@ out:
38  static void clk_calc_subtree(struct clk_core *core, unsigned long new_rate,
39                              struct clk_core *new_parent, u8 p_index)
40  {
41 -       struct clk_core *child;
42 +       struct clk_core *child, *parent;
43 +       struct clk_hw *parent_hw;
44  
45         core->new_rate = new_rate;
46         core->new_parent = new_parent;
47 @@ -1281,6 +1285,18 @@ static void clk_calc_subtree(struct clk_
48         if (new_parent && new_parent != core->parent)
49                 new_parent->new_child = core;
50  
51 +       if (core->ops->get_safe_parent) {
52 +               parent_hw = core->ops->get_safe_parent(core->hw);
53 +               if (parent_hw) {
54 +                       parent = parent_hw->core;
55 +                       p_index = clk_fetch_parent_index(core, parent);
56 +                       core->safe_parent_index = p_index;
57 +                       core->safe_parent = parent;
58 +               }
59 +       } else {
60 +               core->safe_parent = NULL;
61 +       }
62 +
63         hlist_for_each_entry(child, &core->children, child_node) {
64                 child->new_rate = clk_recalc(child, new_rate);
65                 clk_calc_subtree(child, child->new_rate, NULL, 0);
66 @@ -1393,14 +1409,43 @@ static struct clk_core *clk_propagate_ra
67                                                   unsigned long event)
68  {
69         struct clk_core *child, *tmp_clk, *fail_clk = NULL;
70 +       struct clk_core *old_parent;
71         int ret = NOTIFY_DONE;
72  
73 -       if (core->rate == core->new_rate)
74 +       if (core->rate == core->new_rate && event != POST_RATE_CHANGE)
75                 return NULL;
76  
77 +       switch (event) {
78 +       case PRE_RATE_CHANGE:
79 +               if (core->safe_parent)
80 +                       core->ops->set_parent(core->hw, core->safe_parent_index);
81 +               core->old_rate = core->rate;
82 +               break;
83 +       case POST_RATE_CHANGE:
84 +               if (core->safe_parent) {
85 +                       old_parent = __clk_set_parent_before(core,
86 +                                                           core->new_parent);
87 +                       if (core->ops->set_rate_and_parent) {
88 +                               core->ops->set_rate_and_parent(core->hw,
89 +                                               core->new_rate,
90 +                                               core->new_parent ?
91 +                                               core->new_parent->rate : 0,
92 +                                               core->new_parent_index);
93 +                       } else if (core->ops->set_parent) {
94 +                               core->ops->set_parent(core->hw,
95 +                                               core->new_parent_index);
96 +                       }
97 +                       __clk_set_parent_after(core, core->new_parent,
98 +                                               old_parent);
99 +               }
100 +               break;
101 +       }
102 +
103         if (core->notifier_count) {
104 -               ret = __clk_notify(core, event, core->rate, core->new_rate);
105 -               if (ret & NOTIFY_STOP_MASK)
106 +               if (event != POST_RATE_CHANGE || core->old_rate != core->rate)
107 +                       ret = __clk_notify(core, event, core->old_rate,
108 +                                          core->new_rate);
109 +               if (ret & NOTIFY_STOP_MASK && event != POST_RATE_CHANGE)
110                         fail_clk = core;
111         }
112  
113 @@ -1446,7 +1491,8 @@ clk_change_rate(struct clk_core *core, u
114  
115         old_rate = core->rate;
116  
117 -       if (core->new_parent && core->new_parent != core->parent) {
118 +       if (core->new_parent && core->new_parent != core->parent &&
119 +                       !core->safe_parent) {
120                 old_parent = __clk_set_parent_before(core, core->new_parent);
121                 trace_clk_set_parent(core, core->new_parent);
122  
123 @@ -1472,9 +1518,6 @@ clk_change_rate(struct clk_core *core, u
124  
125         core->rate = core->new_rate;
126  
127 -       if (core->notifier_count && old_rate != core->rate)
128 -               __clk_notify(core, POST_RATE_CHANGE, old_rate, core->rate);
129 -
130         if (core->flags & CLK_RECALC_NEW_RATES)
131                 (void)clk_calc_new_rates(core, core->new_rate);
132  
133 @@ -1537,6 +1580,8 @@ static int clk_core_set_rate_nolock(stru
134  
135         core->req_rate = req_rate;
136  
137 +       clk_propagate_rate_change(top, POST_RATE_CHANGE);
138 +
139         return ret;
140  }
141  
142 --- a/include/linux/clk-provider.h
143 +++ b/include/linux/clk-provider.h
144 @@ -202,6 +202,7 @@ struct clk_ops {
145                                           struct clk_rate_request *req);
146         int             (*set_parent)(struct clk_hw *hw, u8 index);
147         u8              (*get_parent)(struct clk_hw *hw);
148 +       struct clk_hw   *(*get_safe_parent)(struct clk_hw *hw);
149         int             (*set_rate)(struct clk_hw *hw, unsigned long rate,
150                                     unsigned long parent_rate);
151         int             (*set_rate_and_parent)(struct clk_hw *hw,