Skip to content

Commit 08add3c

Browse files
mripardbebarino
authored andcommitted
clk: si5351: pll: Switch to determine_rate
The SI5351 PLL clocks implements a mux with a set_parent hook, but doesn't provide a determine_rate implementation. This is a bit odd, since set_parent() is there to, as its name implies, change the parent of a clock. However, the most likely candidate to trigger that parent change is a call to clk_set_rate(), with determine_rate() figuring out which parent is the best suited for a given rate. The other trigger would be a call to clk_set_parent(), but it's far less used, and it doesn't look like there's any obvious user for that clock. So, the set_parent hook is effectively unused, possibly because of an oversight. However, it could also be an explicit decision by the original author to avoid any reparenting but through an explicit call to clk_set_parent(). The driver does implement round_rate() though, which means that we can change the rate of the clock, but we will never get to change the parent. However, It's hard to tell whether it's been done on purpose or not. Since we'll start mandating a determine_rate() implementation, let's convert the round_rate() implementation to a determine_rate(), which will also make the current behavior explicit. And if it was an oversight, the clock behaviour can be adjusted later on. Signed-off-by: Maxime Ripard <maxime@cerno.tech> Link: https://lore.kernel.org/r/20221018-clk-range-checks-fixes-v4-54-971d5077e7d2@cerno.tech Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent 61c34af commit 08add3c

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

drivers/clk/clk-si5351.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,12 @@ static unsigned long si5351_pll_recalc_rate(struct clk_hw *hw,
442442
return (unsigned long)rate;
443443
}
444444

445-
static long si5351_pll_round_rate(struct clk_hw *hw, unsigned long rate,
446-
unsigned long *parent_rate)
445+
static int si5351_pll_determine_rate(struct clk_hw *hw,
446+
struct clk_rate_request *req)
447447
{
448448
struct si5351_hw_data *hwdata =
449449
container_of(hw, struct si5351_hw_data, hw);
450+
unsigned long rate = req->rate;
450451
unsigned long rfrac, denom, a, b, c;
451452
unsigned long long lltmp;
452453

@@ -456,18 +457,18 @@ static long si5351_pll_round_rate(struct clk_hw *hw, unsigned long rate,
456457
rate = SI5351_PLL_VCO_MAX;
457458

458459
/* determine integer part of feedback equation */
459-
a = rate / *parent_rate;
460+
a = rate / req->best_parent_rate;
460461

461462
if (a < SI5351_PLL_A_MIN)
462-
rate = *parent_rate * SI5351_PLL_A_MIN;
463+
rate = req->best_parent_rate * SI5351_PLL_A_MIN;
463464
if (a > SI5351_PLL_A_MAX)
464-
rate = *parent_rate * SI5351_PLL_A_MAX;
465+
rate = req->best_parent_rate * SI5351_PLL_A_MAX;
465466

466467
/* find best approximation for b/c = fVCO mod fIN */
467468
denom = 1000 * 1000;
468-
lltmp = rate % (*parent_rate);
469+
lltmp = rate % (req->best_parent_rate);
469470
lltmp *= denom;
470-
do_div(lltmp, *parent_rate);
471+
do_div(lltmp, req->best_parent_rate);
471472
rfrac = (unsigned long)lltmp;
472473

473474
b = 0;
@@ -484,19 +485,20 @@ static long si5351_pll_round_rate(struct clk_hw *hw, unsigned long rate,
484485
hwdata->params.p1 -= 512;
485486

486487
/* recalculate rate by fIN * (a + b/c) */
487-
lltmp = *parent_rate;
488+
lltmp = req->best_parent_rate;
488489
lltmp *= b;
489490
do_div(lltmp, c);
490491

491492
rate = (unsigned long)lltmp;
492-
rate += *parent_rate * a;
493+
rate += req->best_parent_rate * a;
493494

494495
dev_dbg(&hwdata->drvdata->client->dev,
495496
"%s - %s: a = %lu, b = %lu, c = %lu, parent_rate = %lu, rate = %lu\n",
496497
__func__, clk_hw_get_name(hw), a, b, c,
497-
*parent_rate, rate);
498+
req->best_parent_rate, rate);
498499

499-
return rate;
500+
req->rate = rate;
501+
return 0;
500502
}
501503

502504
static int si5351_pll_set_rate(struct clk_hw *hw, unsigned long rate,
@@ -533,7 +535,7 @@ static const struct clk_ops si5351_pll_ops = {
533535
.set_parent = si5351_pll_set_parent,
534536
.get_parent = si5351_pll_get_parent,
535537
.recalc_rate = si5351_pll_recalc_rate,
536-
.round_rate = si5351_pll_round_rate,
538+
.determine_rate = si5351_pll_determine_rate,
537539
.set_rate = si5351_pll_set_rate,
538540
};
539541

0 commit comments

Comments
 (0)