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
6 Some clocks still use an explicit list of arguments, which make it a bit
7 more tedious to add new parameters.
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.
13 Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
14 Acked-by: Chen-Yu Tsai <wens@csie.org>
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(-)
20 --- a/drivers/clk/sunxi-ng/ccu_mult.c
21 +++ b/drivers/clk/sunxi-ng/ccu_mult.c
27 + unsigned long mult, max;
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)
37 + _mult = rate / parent;
38 + if (_mult > mult->max)
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
48 struct ccu_mult *cm = data;
50 + struct _ccu_mult _cm;
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);
56 - return parent_rate * n;
57 + return parent_rate * _cm.mult;
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)
64 struct ccu_mult *cm = hw_to_ccu_mult(hw);
65 + struct _ccu_mult _cm;
70 ccu_mux_helper_adjust_parent_for_prediv(&cm->common, &cm->mux, -1,
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);
77 spin_lock_irqsave(cm->common.lock, flags);
79 reg = readl(cm->common.base + cm->common.reg);
80 reg &= ~GENMASK(cm->mult.width + cm->mult.shift - 1, cm->mult.shift);
82 - writel(reg | ((n - 1) << cm->mult.shift),
83 + writel(reg | ((_cm.mult - 1) << cm->mult.shift),
84 cm->common.base + cm->common.reg);
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
92 #include <linux/clk-provider.h>
93 -#include <linux/rational.h>
99 + unsigned long n, max_n;
100 + unsigned long k, max_k;
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)
108 unsigned long best_rate = 0;
109 unsigned int best_k = 0, best_n = 0;
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;
119 @@ -37,8 +40,8 @@ static void ccu_nk_find_best(unsigned lo
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)
133 struct ccu_nk *nk = hw_to_ccu_nk(hw);
135 + struct _ccu_nk _nk;
137 if (nk->common.features & CCU_FEATURE_FIXED_POSTDIV)
138 rate *= nk->fixed_post_div;
140 - ccu_nk_find_best(*parent_rate, rate,
141 - 1 << nk->n.width, 1 << nk->k.width,
143 + _nk.max_n = 1 << nk->n.width;
144 + _nk.max_k = 1 << nk->k.width;
146 + ccu_nk_find_best(*parent_rate, rate, &_nk);
147 + rate = *parent_rate * _nk.n * _nk.k;
149 - rate = *parent_rate * n * k;
150 if (nk->common.features & CCU_FEATURE_FIXED_POSTDIV)
151 rate = rate / nk->fixed_post_div;
153 @@ -110,15 +114,16 @@ static int ccu_nk_set_rate(struct clk_hw
155 struct ccu_nk *nk = hw_to_ccu_nk(hw);
158 + struct _ccu_nk _nk;
161 if (nk->common.features & CCU_FEATURE_FIXED_POSTDIV)
162 rate = rate * nk->fixed_post_div;
164 - ccu_nk_find_best(parent_rate, rate,
165 - 1 << nk->n.width, 1 << nk->k.width,
167 + _nk.max_n = 1 << nk->n.width;
168 + _nk.max_k = 1 << nk->k.width;
170 + ccu_nk_find_best(parent_rate, rate, &_nk);
172 spin_lock_irqsave(nk->common.lock, flags);
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);
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);
182 spin_unlock_irqrestore(nk->common.lock, flags);