Skip to content

Commit 1c8d7af

Browse files
committed
clk: sunxi-ng: convert from divider_round_rate_parent() to divider_determine_rate()
The divider_round_rate_parent() function is now deprecated, so let's migrate to divider_determine_rate() instead so that this deprecated API can be removed. Also go ahead and convert all of the driver from round rate type to determine rate that accepts a 'struct clk_rate_request' to simplify the overall driver code. Acked-by: Chen-Yu Tsai <wens@kernel.org> Signed-off-by: Brian Masney <bmasney@redhat.com>
1 parent a641384 commit 1c8d7af

6 files changed

Lines changed: 79 additions & 70 deletions

File tree

drivers/clk/sunxi-ng/ccu_div.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,25 @@
1010
#include "ccu_gate.h"
1111
#include "ccu_div.h"
1212

13-
static unsigned long ccu_div_round_rate(struct ccu_mux_internal *mux,
14-
struct clk_hw *parent,
15-
unsigned long *parent_rate,
16-
unsigned long rate,
17-
void *data)
13+
static int ccu_div_determine_rate_helper(struct ccu_mux_internal *mux,
14+
struct clk_rate_request *req,
15+
void *data)
1816
{
1917
struct ccu_div *cd = data;
18+
int ret;
2019

2120
if (cd->common.features & CCU_FEATURE_FIXED_POSTDIV)
22-
rate *= cd->fixed_post_div;
21+
req->rate *= cd->fixed_post_div;
2322

24-
rate = divider_round_rate_parent(&cd->common.hw, parent,
25-
rate, parent_rate,
26-
cd->div.table, cd->div.width,
27-
cd->div.flags);
23+
ret = divider_determine_rate(&cd->common.hw, req, cd->div.table,
24+
cd->div.width, cd->div.flags);
25+
if (ret)
26+
return ret;
2827

2928
if (cd->common.features & CCU_FEATURE_FIXED_POSTDIV)
30-
rate /= cd->fixed_post_div;
29+
req->rate /= cd->fixed_post_div;
3130

32-
return rate;
31+
return 0;
3332
}
3433

3534
static void ccu_div_disable(struct clk_hw *hw)
@@ -82,7 +81,7 @@ static int ccu_div_determine_rate(struct clk_hw *hw,
8281
struct ccu_div *cd = hw_to_ccu_div(hw);
8382

8483
return ccu_mux_helper_determine_rate(&cd->common, &cd->mux,
85-
req, ccu_div_round_rate, cd);
84+
req, ccu_div_determine_rate_helper, cd);
8685
}
8786

8887
static int ccu_div_set_rate(struct clk_hw *hw, unsigned long rate,

drivers/clk/sunxi-ng/ccu_mp.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,17 @@ static unsigned long ccu_mp_find_best_with_parent_adj(struct clk_hw *hw,
103103
return best_rate;
104104
}
105105

106-
static unsigned long ccu_mp_round_rate(struct ccu_mux_internal *mux,
107-
struct clk_hw *hw,
108-
unsigned long *parent_rate,
109-
unsigned long rate,
110-
void *data)
106+
static int ccu_mp_determine_rate_helper(struct ccu_mux_internal *mux,
107+
struct clk_rate_request *req,
108+
void *data)
111109
{
112110
struct ccu_mp *cmp = data;
113111
unsigned int max_m, max_p;
114112
unsigned int m, p;
115113
bool shift = true;
116114

117115
if (cmp->common.features & CCU_FEATURE_FIXED_POSTDIV)
118-
rate *= cmp->fixed_post_div;
116+
req->rate *= cmp->fixed_post_div;
119117

120118
if (cmp->common.features & CCU_FEATURE_DUAL_DIV)
121119
shift = false;
@@ -127,17 +125,19 @@ static unsigned long ccu_mp_round_rate(struct ccu_mux_internal *mux,
127125
max_p = cmp->p.max ?: 1 << cmp->p.width;
128126

129127
if (!clk_hw_can_set_rate_parent(&cmp->common.hw)) {
130-
rate = ccu_mp_find_best(*parent_rate, rate, max_m, max_p, shift,
131-
&m, &p);
128+
req->rate = ccu_mp_find_best(req->best_parent_rate, req->rate,
129+
max_m, max_p, shift, &m, &p);
132130
} else {
133-
rate = ccu_mp_find_best_with_parent_adj(hw, parent_rate, rate,
134-
max_m, max_p, shift);
131+
req->rate = ccu_mp_find_best_with_parent_adj(req->best_parent_hw,
132+
&req->best_parent_rate,
133+
req->rate, max_m, max_p,
134+
shift);
135135
}
136136

137137
if (cmp->common.features & CCU_FEATURE_FIXED_POSTDIV)
138-
rate /= cmp->fixed_post_div;
138+
req->rate /= cmp->fixed_post_div;
139139

140-
return rate;
140+
return 0;
141141
}
142142

143143
static void ccu_mp_disable(struct clk_hw *hw)
@@ -201,7 +201,7 @@ static int ccu_mp_determine_rate(struct clk_hw *hw,
201201
struct ccu_mp *cmp = hw_to_ccu_mp(hw);
202202

203203
return ccu_mux_helper_determine_rate(&cmp->common, &cmp->mux,
204-
req, ccu_mp_round_rate, cmp);
204+
req, ccu_mp_determine_rate_helper, cmp);
205205
}
206206

207207
static int ccu_mp_set_rate(struct clk_hw *hw, unsigned long rate,

drivers/clk/sunxi-ng/ccu_mult.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ static void ccu_mult_find_best(unsigned long parent, unsigned long rate,
2929
mult->mult = _mult;
3030
}
3131

32-
static unsigned long ccu_mult_round_rate(struct ccu_mux_internal *mux,
33-
struct clk_hw *parent,
34-
unsigned long *parent_rate,
35-
unsigned long rate,
36-
void *data)
32+
static int ccu_mult_determine_rate_helper(struct ccu_mux_internal *mux,
33+
struct clk_rate_request *req,
34+
void *data)
3735
{
3836
struct ccu_mult *cm = data;
3937
struct _ccu_mult _cm;
@@ -45,9 +43,11 @@ static unsigned long ccu_mult_round_rate(struct ccu_mux_internal *mux,
4543
else
4644
_cm.max = (1 << cm->mult.width) + cm->mult.offset - 1;
4745

48-
ccu_mult_find_best(*parent_rate, rate, &_cm);
46+
ccu_mult_find_best(req->best_parent_rate, req->rate, &_cm);
4947

50-
return *parent_rate * _cm.mult;
48+
req->rate = req->best_parent_rate * _cm.mult;
49+
50+
return 0;
5151
}
5252

5353
static void ccu_mult_disable(struct clk_hw *hw)
@@ -97,7 +97,7 @@ static int ccu_mult_determine_rate(struct clk_hw *hw,
9797
struct ccu_mult *cm = hw_to_ccu_mult(hw);
9898

9999
return ccu_mux_helper_determine_rate(&cm->common, &cm->mux,
100-
req, ccu_mult_round_rate, cm);
100+
req, ccu_mult_determine_rate_helper, cm);
101101
}
102102

103103
static int ccu_mult_set_rate(struct clk_hw *hw, unsigned long rate,

drivers/clk/sunxi-ng/ccu_mux.c

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,41 +79,46 @@ static unsigned long ccu_mux_helper_unapply_prediv(struct ccu_common *common,
7979
int ccu_mux_helper_determine_rate(struct ccu_common *common,
8080
struct ccu_mux_internal *cm,
8181
struct clk_rate_request *req,
82-
unsigned long (*round)(struct ccu_mux_internal *,
83-
struct clk_hw *,
84-
unsigned long *,
85-
unsigned long,
86-
void *),
82+
int (*round)(struct ccu_mux_internal *,
83+
struct clk_rate_request *,
84+
void *),
8785
void *data)
8886
{
8987
unsigned long best_parent_rate = 0, best_rate = 0;
9088
struct clk_hw *best_parent, *hw = &common->hw;
9189
unsigned int i;
90+
int ret;
9291

9392
if (clk_hw_get_flags(hw) & CLK_SET_RATE_NO_REPARENT) {
94-
unsigned long adj_parent_rate;
93+
struct clk_rate_request adj_req = *req;
9594

9695
best_parent = clk_hw_get_parent(hw);
9796
best_parent_rate = clk_hw_get_rate(best_parent);
98-
adj_parent_rate = ccu_mux_helper_apply_prediv(common, cm, -1,
99-
best_parent_rate);
10097

101-
best_rate = round(cm, best_parent, &adj_parent_rate,
102-
req->rate, data);
98+
adj_req.best_parent_hw = best_parent;
99+
adj_req.best_parent_rate = ccu_mux_helper_apply_prediv(common, cm, -1,
100+
best_parent_rate);
101+
102+
ret = round(cm, &adj_req, data);
103+
if (ret)
104+
return ret;
105+
106+
best_rate = adj_req.rate;
103107

104108
/*
105-
* adj_parent_rate might have been modified by our clock.
109+
* best_parent_rate might have been modified by our clock.
106110
* Unapply the pre-divider if there's one, and give
107111
* the actual frequency the parent needs to run at.
108112
*/
109113
best_parent_rate = ccu_mux_helper_unapply_prediv(common, cm, -1,
110-
adj_parent_rate);
114+
adj_req.best_parent_rate);
111115

112116
goto out;
113117
}
114118

115119
for (i = 0; i < clk_hw_get_num_parents(hw); i++) {
116-
unsigned long tmp_rate, parent_rate;
120+
struct clk_rate_request tmp_req = *req;
121+
unsigned long parent_rate;
117122
struct clk_hw *parent;
118123

119124
parent = clk_hw_get_parent_by_index(hw, i);
@@ -123,24 +128,30 @@ int ccu_mux_helper_determine_rate(struct ccu_common *common,
123128
parent_rate = ccu_mux_helper_apply_prediv(common, cm, i,
124129
clk_hw_get_rate(parent));
125130

126-
tmp_rate = round(cm, parent, &parent_rate, req->rate, data);
131+
tmp_req.best_parent_hw = parent;
132+
tmp_req.best_parent_rate = parent_rate;
133+
134+
ret = round(cm, &tmp_req, data);
135+
if (ret)
136+
continue;
127137

128138
/*
129139
* parent_rate might have been modified by our clock.
130140
* Unapply the pre-divider if there's one, and give
131141
* the actual frequency the parent needs to run at.
132142
*/
133143
parent_rate = ccu_mux_helper_unapply_prediv(common, cm, i,
134-
parent_rate);
135-
if (tmp_rate == req->rate) {
144+
tmp_req.best_parent_rate);
145+
146+
if (tmp_req.rate == req->rate) {
136147
best_parent = parent;
137148
best_parent_rate = parent_rate;
138-
best_rate = tmp_rate;
149+
best_rate = tmp_req.rate;
139150
goto out;
140151
}
141152

142-
if (ccu_is_better_rate(common, req->rate, tmp_rate, best_rate)) {
143-
best_rate = tmp_rate;
153+
if (ccu_is_better_rate(common, req->rate, tmp_req.rate, best_rate)) {
154+
best_rate = tmp_req.rate;
144155
best_parent_rate = parent_rate;
145156
best_parent = parent;
146157
}

drivers/clk/sunxi-ng/ccu_mux.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,9 @@ unsigned long ccu_mux_helper_apply_prediv(struct ccu_common *common,
137137
int ccu_mux_helper_determine_rate(struct ccu_common *common,
138138
struct ccu_mux_internal *cm,
139139
struct clk_rate_request *req,
140-
unsigned long (*round)(struct ccu_mux_internal *,
141-
struct clk_hw *,
142-
unsigned long *,
143-
unsigned long,
144-
void *),
140+
int (*round)(struct ccu_mux_internal *,
141+
struct clk_rate_request *,
142+
void *),
145143
void *data);
146144
u8 ccu_mux_helper_get_parent(struct ccu_common *common,
147145
struct ccu_mux_internal *cm);

drivers/clk/sunxi-ng/ccu_nkm.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,9 @@ static unsigned long ccu_nkm_recalc_rate(struct clk_hw *hw,
162162
return rate;
163163
}
164164

165-
static unsigned long ccu_nkm_round_rate(struct ccu_mux_internal *mux,
166-
struct clk_hw *parent_hw,
167-
unsigned long *parent_rate,
168-
unsigned long rate,
169-
void *data)
165+
static int ccu_nkm_determine_rate_helper(struct ccu_mux_internal *mux,
166+
struct clk_rate_request *req,
167+
void *data)
170168
{
171169
struct ccu_nkm *nkm = data;
172170
struct _ccu_nkm _nkm;
@@ -179,18 +177,21 @@ static unsigned long ccu_nkm_round_rate(struct ccu_mux_internal *mux,
179177
_nkm.max_m = nkm->m.max ?: 1 << nkm->m.width;
180178

181179
if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV)
182-
rate *= nkm->fixed_post_div;
180+
req->rate *= nkm->fixed_post_div;
183181

184182
if (!clk_hw_can_set_rate_parent(&nkm->common.hw))
185-
rate = ccu_nkm_find_best(*parent_rate, rate, &_nkm, &nkm->common);
183+
req->rate = ccu_nkm_find_best(req->best_parent_rate, req->rate,
184+
&_nkm, &nkm->common);
186185
else
187-
rate = ccu_nkm_find_best_with_parent_adj(&nkm->common, parent_hw, parent_rate, rate,
188-
&_nkm);
186+
req->rate = ccu_nkm_find_best_with_parent_adj(&nkm->common,
187+
req->best_parent_hw,
188+
&req->best_parent_rate,
189+
req->rate, &_nkm);
189190

190191
if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV)
191-
rate /= nkm->fixed_post_div;
192+
req->rate /= nkm->fixed_post_div;
192193

193-
return rate;
194+
return 0;
194195
}
195196

196197
static int ccu_nkm_determine_rate(struct clk_hw *hw,
@@ -199,7 +200,7 @@ static int ccu_nkm_determine_rate(struct clk_hw *hw,
199200
struct ccu_nkm *nkm = hw_to_ccu_nkm(hw);
200201

201202
return ccu_mux_helper_determine_rate(&nkm->common, &nkm->mux,
202-
req, ccu_nkm_round_rate, nkm);
203+
req, ccu_nkm_determine_rate_helper, nkm);
203204
}
204205

205206
static int ccu_nkm_set_rate(struct clk_hw *hw, unsigned long rate,

0 commit comments

Comments
 (0)