Skip to content

Commit a641384

Browse files
committed
clk: sophgo: cv18xx-ip: convert from divider_round_rate() to divider_determine_rate()
The divider_round_rate() 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. Signed-off-by: Brian Masney <bmasney@redhat.com>
1 parent 8f0b4cc commit a641384

1 file changed

Lines changed: 85 additions & 69 deletions

File tree

drivers/clk/sophgo/clk-cv18xx-ip.c

Lines changed: 85 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -152,28 +152,27 @@ static u32 div_helper_get_clockdiv(struct cv1800_clk_common *common,
152152
return clockdiv;
153153
}
154154

155-
static u32 div_helper_round_rate(struct cv1800_clk_regfield *div,
156-
struct clk_hw *hw, struct clk_hw *parent,
157-
unsigned long rate, unsigned long *prate)
155+
static int div_helper_determine_rate(struct cv1800_clk_regfield *div,
156+
struct clk_hw *hw,
157+
struct clk_rate_request *req)
158158
{
159159
if (div->width == 0) {
160160
if (div->initval <= 0)
161-
return DIV_ROUND_UP_ULL(*prate, 1);
161+
req->rate = DIV_ROUND_UP_ULL(req->best_parent_rate, 1);
162162
else
163-
return DIV_ROUND_UP_ULL(*prate, div->initval);
163+
req->rate = DIV_ROUND_UP_ULL(req->best_parent_rate, div->initval);
164+
165+
return 0;
164166
}
165167

166-
return divider_round_rate_parent(hw, parent, rate, prate, NULL,
167-
div->width, div->flags);
168+
return divider_determine_rate(hw, req, NULL, div->width, div->flags);
168169
}
169170

170-
static long div_round_rate(struct clk_hw *parent, unsigned long *parent_rate,
171-
unsigned long rate, int id, void *data)
171+
static int do_div_determine_rate(struct clk_rate_request *req, int id, void *data)
172172
{
173173
struct cv1800_clk_div *div = data;
174174

175-
return div_helper_round_rate(&div->div, &div->common.hw, parent,
176-
rate, parent_rate);
175+
return div_helper_determine_rate(&div->div, &div->common.hw, req);
177176
}
178177

179178
static bool div_is_better_rate(struct cv1800_clk_common *common,
@@ -188,53 +187,60 @@ static bool div_is_better_rate(struct cv1800_clk_common *common,
188187

189188
static int mux_helper_determine_rate(struct cv1800_clk_common *common,
190189
struct clk_rate_request *req,
191-
long (*round)(struct clk_hw *,
192-
unsigned long *,
193-
unsigned long,
194-
int,
195-
void *),
190+
int (*round)(struct clk_rate_request *,
191+
int,
192+
void *),
196193
void *data)
197194
{
198195
unsigned long best_parent_rate = 0, best_rate = 0;
199196
struct clk_hw *best_parent, *hw = &common->hw;
200197
unsigned int i;
198+
int ret;
201199

202200
if (clk_hw_get_flags(hw) & CLK_SET_RATE_NO_REPARENT) {
203-
unsigned long adj_parent_rate;
201+
struct clk_rate_request tmp_req = *req;
204202

205203
best_parent = clk_hw_get_parent(hw);
206-
best_parent_rate = clk_hw_get_rate(best_parent);
204+
tmp_req.best_parent_hw = best_parent;
205+
tmp_req.best_parent_rate = clk_hw_get_rate(best_parent);
207206

208-
best_rate = round(best_parent, &adj_parent_rate,
209-
req->rate, -1, data);
207+
ret = round(&tmp_req, -1, data);
208+
if (ret)
209+
return ret;
210+
211+
best_parent_rate = tmp_req.best_parent_rate;
212+
best_rate = tmp_req.rate;
210213

211214
goto find;
212215
}
213216

214217
for (i = 0; i < clk_hw_get_num_parents(hw); i++) {
215-
unsigned long tmp_rate, parent_rate;
218+
struct clk_rate_request tmp_req = *req;
216219
struct clk_hw *parent;
217220

218221
parent = clk_hw_get_parent_by_index(hw, i);
219222
if (!parent)
220223
continue;
221224

222-
parent_rate = clk_hw_get_rate(parent);
225+
tmp_req.best_parent_hw = parent;
226+
tmp_req.best_parent_rate = clk_hw_get_rate(parent);
223227

224-
tmp_rate = round(parent, &parent_rate, req->rate, i, data);
228+
ret = round(&tmp_req, i, data);
229+
if (ret)
230+
continue;
225231

226-
if (tmp_rate == req->rate) {
232+
if (tmp_req.rate == req->rate) {
227233
best_parent = parent;
228-
best_parent_rate = parent_rate;
229-
best_rate = tmp_rate;
234+
best_parent_rate = tmp_req.best_parent_rate;
235+
best_rate = tmp_req.rate;
230236
goto find;
231237
}
232238

233239
if (div_is_better_rate(common, req->rate,
234-
tmp_rate, best_rate)) {
240+
tmp_req.rate, best_rate)) {
235241
best_parent = parent;
236-
best_parent_rate = parent_rate;
237-
best_rate = tmp_rate;
242+
best_parent_rate = tmp_req.best_parent_rate;
243+
best_rate = tmp_req.rate;
238244
}
239245
}
240246

@@ -254,7 +260,7 @@ static int div_determine_rate(struct clk_hw *hw,
254260
struct cv1800_clk_div *div = hw_to_cv1800_clk_div(hw);
255261

256262
return mux_helper_determine_rate(&div->common, req,
257-
div_round_rate, div);
263+
do_div_determine_rate, div);
258264
}
259265

260266
static unsigned long div_recalc_rate(struct clk_hw *hw,
@@ -301,24 +307,28 @@ hw_to_cv1800_clk_bypass_div(struct clk_hw *hw)
301307
return container_of(div, struct cv1800_clk_bypass_div, div);
302308
}
303309

304-
static long bypass_div_round_rate(struct clk_hw *parent,
305-
unsigned long *parent_rate,
306-
unsigned long rate, int id, void *data)
310+
static int do_bypass_div_determine_rate(struct clk_rate_request *req, int id,
311+
void *data)
307312
{
308313
struct cv1800_clk_bypass_div *div = data;
309314

310315
if (id == -1) {
311-
if (cv1800_clk_checkbit(&div->div.common, &div->bypass))
312-
return *parent_rate;
313-
else
314-
return div_round_rate(parent, parent_rate, rate,
315-
-1, &div->div);
316+
if (cv1800_clk_checkbit(&div->div.common, &div->bypass)) {
317+
req->rate = req->best_parent_rate;
318+
319+
return 0;
320+
}
321+
322+
return do_div_determine_rate(req, -1, &div->div);
316323
}
317324

318-
if (id == 0)
319-
return *parent_rate;
325+
if (id == 0) {
326+
req->rate = req->best_parent_rate;
327+
328+
return 0;
329+
}
320330

321-
return div_round_rate(parent, parent_rate, rate, id - 1, &div->div);
331+
return do_div_determine_rate(req, id - 1, &div->div);
322332
}
323333

324334
static int bypass_div_determine_rate(struct clk_hw *hw,
@@ -327,7 +337,7 @@ static int bypass_div_determine_rate(struct clk_hw *hw,
327337
struct cv1800_clk_bypass_div *div = hw_to_cv1800_clk_bypass_div(hw);
328338

329339
return mux_helper_determine_rate(&div->div.common, req,
330-
bypass_div_round_rate, div);
340+
do_bypass_div_determine_rate, div);
331341
}
332342

333343
static unsigned long bypass_div_recalc_rate(struct clk_hw *hw,
@@ -414,13 +424,11 @@ static int mux_is_enabled(struct clk_hw *hw)
414424
return cv1800_clk_checkbit(&mux->common, &mux->gate);
415425
}
416426

417-
static long mux_round_rate(struct clk_hw *parent, unsigned long *parent_rate,
418-
unsigned long rate, int id, void *data)
427+
static int do_mux_determine_rate(struct clk_rate_request *req, int id, void *data)
419428
{
420429
struct cv1800_clk_mux *mux = data;
421430

422-
return div_helper_round_rate(&mux->div, &mux->common.hw, parent,
423-
rate, parent_rate);
431+
return div_helper_determine_rate(&mux->div, &mux->common.hw, req);
424432
}
425433

426434
static int mux_determine_rate(struct clk_hw *hw,
@@ -429,7 +437,7 @@ static int mux_determine_rate(struct clk_hw *hw,
429437
struct cv1800_clk_mux *mux = hw_to_cv1800_clk_mux(hw);
430438

431439
return mux_helper_determine_rate(&mux->common, req,
432-
mux_round_rate, mux);
440+
do_mux_determine_rate, mux);
433441
}
434442

435443
static unsigned long mux_recalc_rate(struct clk_hw *hw,
@@ -512,24 +520,28 @@ hw_to_cv1800_clk_bypass_mux(struct clk_hw *hw)
512520
return container_of(mux, struct cv1800_clk_bypass_mux, mux);
513521
}
514522

515-
static long bypass_mux_round_rate(struct clk_hw *parent,
516-
unsigned long *parent_rate,
517-
unsigned long rate, int id, void *data)
523+
static int do_bypass_mux_determine_rate(struct clk_rate_request *req, int id,
524+
void *data)
518525
{
519526
struct cv1800_clk_bypass_mux *mux = data;
520527

521528
if (id == -1) {
522-
if (cv1800_clk_checkbit(&mux->mux.common, &mux->bypass))
523-
return *parent_rate;
524-
else
525-
return mux_round_rate(parent, parent_rate, rate,
526-
-1, &mux->mux);
529+
if (cv1800_clk_checkbit(&mux->mux.common, &mux->bypass)) {
530+
req->rate = req->best_parent_rate;
531+
532+
return 0;
533+
}
534+
535+
return do_mux_determine_rate(req, -1, &mux->mux);
527536
}
528537

529-
if (id == 0)
530-
return *parent_rate;
538+
if (id == 0) {
539+
req->rate = req->best_parent_rate;
540+
541+
return 0;
542+
}
531543

532-
return mux_round_rate(parent, parent_rate, rate, id - 1, &mux->mux);
544+
return do_mux_determine_rate(req, id - 1, &mux->mux);
533545
}
534546

535547
static int bypass_mux_determine_rate(struct clk_hw *hw,
@@ -538,7 +550,7 @@ static int bypass_mux_determine_rate(struct clk_hw *hw,
538550
struct cv1800_clk_bypass_mux *mux = hw_to_cv1800_clk_bypass_mux(hw);
539551

540552
return mux_helper_determine_rate(&mux->mux.common, req,
541-
bypass_mux_round_rate, mux);
553+
do_bypass_mux_determine_rate, mux);
542554
}
543555

544556
static unsigned long bypass_mux_recalc_rate(struct clk_hw *hw,
@@ -639,27 +651,31 @@ static int mmux_is_enabled(struct clk_hw *hw)
639651
return cv1800_clk_checkbit(&mmux->common, &mmux->gate);
640652
}
641653

642-
static long mmux_round_rate(struct clk_hw *parent, unsigned long *parent_rate,
643-
unsigned long rate, int id, void *data)
654+
static int do_mmux_determine_rate(struct clk_rate_request *req, int id, void *data)
644655
{
645656
struct cv1800_clk_mmux *mmux = data;
646657
s8 div_id;
647658

648659
if (id == -1) {
649-
if (cv1800_clk_checkbit(&mmux->common, &mmux->bypass))
650-
return *parent_rate;
660+
if (cv1800_clk_checkbit(&mmux->common, &mmux->bypass)) {
661+
req->rate = req->best_parent_rate;
662+
663+
return 0;
664+
}
651665

652666
id = mmux_get_parent_id(mmux);
653667
}
654668

655669
div_id = mmux->parent2sel[id];
656670

657-
if (div_id < 0)
658-
return *parent_rate;
671+
if (div_id < 0) {
672+
req->rate = req->best_parent_rate;
673+
674+
return 0;
675+
}
659676

660-
return div_helper_round_rate(&mmux->div[div_id],
661-
&mmux->common.hw, parent,
662-
rate, parent_rate);
677+
return div_helper_determine_rate(&mmux->div[div_id], &mmux->common.hw,
678+
req);
663679
}
664680

665681
static int mmux_determine_rate(struct clk_hw *hw,
@@ -668,7 +684,7 @@ static int mmux_determine_rate(struct clk_hw *hw,
668684
struct cv1800_clk_mmux *mmux = hw_to_cv1800_clk_mmux(hw);
669685

670686
return mux_helper_determine_rate(&mmux->common, req,
671-
mmux_round_rate, mmux);
687+
do_mmux_determine_rate, mmux);
672688
}
673689

674690
static unsigned long mmux_recalc_rate(struct clk_hw *hw,

0 commit comments

Comments
 (0)