v1.5 branch refresh based upon upstream master @ c8677ca89e53e3be7988d54280fce166cc894a7e
[librecmc/librecmc.git] / target / linux / sunxi / patches-4.9 / 0004-clk-sunxi-ng-Finish-to-convert-to-structures-for-arg.patch
1 From b8302c7267dedaeeb1bf38143f099defbf16dce8 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime.ripard@free-electrons.com>
3 Date: Thu, 29 Sep 2016 23:50:21 +0200
4 Subject: clk: sunxi-ng: Finish to convert to structures for arguments
5
6 Some clocks still use an explicit list of arguments, which make it a bit
7 more tedious to add new parameters.
8
9 Convert those over to a structure pointer argument to add as many
10 arguments as possible without having to many noise in our patches, or a
11 very long list of arguments.
12
13 Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
14 Acked-by: Chen-Yu Tsai <wens@csie.org>
15 ---
16  drivers/clk/sunxi-ng/ccu_mult.c | 28 ++++++++++++++++++++--------
17  drivers/clk/sunxi-ng/ccu_nk.c   | 39 ++++++++++++++++++++++-----------------
18  2 files changed, 42 insertions(+), 25 deletions(-)
19
20 --- a/drivers/clk/sunxi-ng/ccu_mult.c
21 +++ b/drivers/clk/sunxi-ng/ccu_mult.c
22 @@ -13,10 +13,20 @@
23  #include "ccu_gate.h"
24  #include "ccu_mult.h"
25  
26 +struct _ccu_mult {
27 +       unsigned long   mult, max;
28 +};
29 +
30  static void ccu_mult_find_best(unsigned long parent, unsigned long rate,
31 -                              unsigned int max_n, unsigned int *n)
32 +                              struct _ccu_mult *mult)
33  {
34 -       *n = rate / parent;
35 +       int _mult;
36 +
37 +       _mult = rate / parent;
38 +       if (_mult > mult->max)
39 +               _mult = mult->max;
40 +
41 +       mult->mult = _mult;
42  }
43  
44  static unsigned long ccu_mult_round_rate(struct ccu_mux_internal *mux,
45 @@ -25,11 +35,12 @@ static unsigned long ccu_mult_round_rate
46                                         void *data)
47  {
48         struct ccu_mult *cm = data;
49 -       unsigned int n;
50 +       struct _ccu_mult _cm;
51  
52 -       ccu_mult_find_best(parent_rate, rate, 1 << cm->mult.width, &n);
53 +       _cm.max = 1 << cm->mult.width;
54 +       ccu_mult_find_best(parent_rate, rate, &_cm);
55  
56 -       return parent_rate * n;
57 +       return parent_rate * _cm.mult;
58  }
59  
60  static void ccu_mult_disable(struct clk_hw *hw)
61 @@ -83,21 +94,22 @@ static int ccu_mult_set_rate(struct clk_
62                            unsigned long parent_rate)
63  {
64         struct ccu_mult *cm = hw_to_ccu_mult(hw);
65 +       struct _ccu_mult _cm;
66         unsigned long flags;
67 -       unsigned int n;
68         u32 reg;
69  
70         ccu_mux_helper_adjust_parent_for_prediv(&cm->common, &cm->mux, -1,
71                                                 &parent_rate);
72  
73 -       ccu_mult_find_best(parent_rate, rate, 1 << cm->mult.width, &n);
74 +       _cm.max = 1 << cm->mult.width;
75 +       ccu_mult_find_best(parent_rate, rate, &_cm);
76  
77         spin_lock_irqsave(cm->common.lock, flags);
78  
79         reg = readl(cm->common.base + cm->common.reg);
80         reg &= ~GENMASK(cm->mult.width + cm->mult.shift - 1, cm->mult.shift);
81  
82 -       writel(reg | ((n - 1) << cm->mult.shift),
83 +       writel(reg | ((_cm.mult - 1) << cm->mult.shift),
84                cm->common.base + cm->common.reg);
85  
86         spin_unlock_irqrestore(cm->common.lock, flags);
87 --- a/drivers/clk/sunxi-ng/ccu_nk.c
88 +++ b/drivers/clk/sunxi-ng/ccu_nk.c
89 @@ -9,21 +9,24 @@
90   */
91  
92  #include <linux/clk-provider.h>
93 -#include <linux/rational.h>
94  
95  #include "ccu_gate.h"
96  #include "ccu_nk.h"
97  
98 +struct _ccu_nk {
99 +       unsigned long   n, max_n;
100 +       unsigned long   k, max_k;
101 +};
102 +
103  static void ccu_nk_find_best(unsigned long parent, unsigned long rate,
104 -                            unsigned int max_n, unsigned int max_k,
105 -                            unsigned int *n, unsigned int *k)
106 +                            struct _ccu_nk *nk)
107  {
108         unsigned long best_rate = 0;
109         unsigned int best_k = 0, best_n = 0;
110         unsigned int _k, _n;
111  
112 -       for (_k = 1; _k <= max_k; _k++) {
113 -               for (_n = 1; _n <= max_n; _n++) {
114 +       for (_k = 1; _k <= nk->max_k; _k++) {
115 +               for (_n = 1; _n <= nk->max_n; _n++) {
116                         unsigned long tmp_rate = parent * _n * _k;
117  
118                         if (tmp_rate > rate)
119 @@ -37,8 +40,8 @@ static void ccu_nk_find_best(unsigned lo
120                 }
121         }
122  
123 -       *k = best_k;
124 -       *n = best_n;
125 +       nk->k = best_k;
126 +       nk->n = best_n;
127  }
128  
129  static void ccu_nk_disable(struct clk_hw *hw)
130 @@ -89,16 +92,17 @@ static long ccu_nk_round_rate(struct clk
131                               unsigned long *parent_rate)
132  {
133         struct ccu_nk *nk = hw_to_ccu_nk(hw);
134 -       unsigned int n, k;
135 +       struct _ccu_nk _nk;
136  
137         if (nk->common.features & CCU_FEATURE_FIXED_POSTDIV)
138                 rate *= nk->fixed_post_div;
139  
140 -       ccu_nk_find_best(*parent_rate, rate,
141 -                        1 << nk->n.width, 1 << nk->k.width,
142 -                        &n, &k);
143 +       _nk.max_n = 1 << nk->n.width;
144 +       _nk.max_k = 1 << nk->k.width;
145 +
146 +       ccu_nk_find_best(*parent_rate, rate, &_nk);
147 +       rate = *parent_rate * _nk.n * _nk.k;
148  
149 -       rate = *parent_rate * n * k;
150         if (nk->common.features & CCU_FEATURE_FIXED_POSTDIV)
151                 rate = rate / nk->fixed_post_div;
152  
153 @@ -110,15 +114,16 @@ static int ccu_nk_set_rate(struct clk_hw
154  {
155         struct ccu_nk *nk = hw_to_ccu_nk(hw);
156         unsigned long flags;
157 -       unsigned int n, k;
158 +       struct _ccu_nk _nk;
159         u32 reg;
160  
161         if (nk->common.features & CCU_FEATURE_FIXED_POSTDIV)
162                 rate = rate * nk->fixed_post_div;
163  
164 -       ccu_nk_find_best(parent_rate, rate,
165 -                        1 << nk->n.width, 1 << nk->k.width,
166 -                        &n, &k);
167 +       _nk.max_n = 1 << nk->n.width;
168 +       _nk.max_k = 1 << nk->k.width;
169 +
170 +       ccu_nk_find_best(parent_rate, rate, &_nk);
171  
172         spin_lock_irqsave(nk->common.lock, flags);
173  
174 @@ -126,7 +131,7 @@ static int ccu_nk_set_rate(struct clk_hw
175         reg &= ~GENMASK(nk->n.width + nk->n.shift - 1, nk->n.shift);
176         reg &= ~GENMASK(nk->k.width + nk->k.shift - 1, nk->k.shift);
177  
178 -       writel(reg | ((k - 1) << nk->k.shift) | ((n - 1) << nk->n.shift),
179 +       writel(reg | ((_nk.k - 1) << nk->k.shift) | ((_nk.n - 1) << nk->n.shift),
180                nk->common.base + nk->common.reg);
181  
182         spin_unlock_irqrestore(nk->common.lock, flags);