Skip to content

Commit 4ab2bf8

Browse files
mripardbebarino
authored andcommitted
clk: si5351: msynth: Switch to determine_rate
The SI5351 msynth 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-55-971d5077e7d2@cerno.tech Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent 08add3c commit 4ab2bf8

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

drivers/clk/clk-si5351.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -642,11 +642,12 @@ static unsigned long si5351_msynth_recalc_rate(struct clk_hw *hw,
642642
return (unsigned long)rate;
643643
}
644644

645-
static long si5351_msynth_round_rate(struct clk_hw *hw, unsigned long rate,
646-
unsigned long *parent_rate)
645+
static int si5351_msynth_determine_rate(struct clk_hw *hw,
646+
struct clk_rate_request *req)
647647
{
648648
struct si5351_hw_data *hwdata =
649649
container_of(hw, struct si5351_hw_data, hw);
650+
unsigned long rate = req->rate;
650651
unsigned long long lltmp;
651652
unsigned long a, b, c;
652653
int divby4;
@@ -681,10 +682,10 @@ static long si5351_msynth_round_rate(struct clk_hw *hw, unsigned long rate,
681682
b = 0;
682683
c = 1;
683684

684-
*parent_rate = a * rate;
685+
req->best_parent_rate = a * rate;
685686
} else if (hwdata->num >= 6) {
686687
/* determine the closest integer divider */
687-
a = DIV_ROUND_CLOSEST(*parent_rate, rate);
688+
a = DIV_ROUND_CLOSEST(req->best_parent_rate, rate);
688689
if (a < SI5351_MULTISYNTH_A_MIN)
689690
a = SI5351_MULTISYNTH_A_MIN;
690691
if (a > SI5351_MULTISYNTH67_A_MAX)
@@ -702,15 +703,15 @@ static long si5351_msynth_round_rate(struct clk_hw *hw, unsigned long rate,
702703
}
703704

704705
/* determine integer part of divider equation */
705-
a = *parent_rate / rate;
706+
a = req->best_parent_rate / rate;
706707
if (a < SI5351_MULTISYNTH_A_MIN)
707708
a = SI5351_MULTISYNTH_A_MIN;
708709
if (a > SI5351_MULTISYNTH_A_MAX)
709710
a = SI5351_MULTISYNTH_A_MAX;
710711

711712
/* find best approximation for b/c = fVCO mod fOUT */
712713
denom = 1000 * 1000;
713-
lltmp = (*parent_rate) % rate;
714+
lltmp = req->best_parent_rate % rate;
714715
lltmp *= denom;
715716
do_div(lltmp, rate);
716717
rfrac = (unsigned long)lltmp;
@@ -724,7 +725,7 @@ static long si5351_msynth_round_rate(struct clk_hw *hw, unsigned long rate,
724725
}
725726

726727
/* recalculate rate by fOUT = fIN / (a + b/c) */
727-
lltmp = *parent_rate;
728+
lltmp = req->best_parent_rate;
728729
lltmp *= c;
729730
do_div(lltmp, a * c + b);
730731
rate = (unsigned long)lltmp;
@@ -749,9 +750,11 @@ static long si5351_msynth_round_rate(struct clk_hw *hw, unsigned long rate,
749750
dev_dbg(&hwdata->drvdata->client->dev,
750751
"%s - %s: a = %lu, b = %lu, c = %lu, divby4 = %d, parent_rate = %lu, rate = %lu\n",
751752
__func__, clk_hw_get_name(hw), a, b, c, divby4,
752-
*parent_rate, rate);
753+
req->best_parent_rate, rate);
753754

754-
return rate;
755+
req->rate = rate;
756+
757+
return 0;
755758
}
756759

757760
static int si5351_msynth_set_rate(struct clk_hw *hw, unsigned long rate,
@@ -791,7 +794,7 @@ static const struct clk_ops si5351_msynth_ops = {
791794
.set_parent = si5351_msynth_set_parent,
792795
.get_parent = si5351_msynth_get_parent,
793796
.recalc_rate = si5351_msynth_recalc_rate,
794-
.round_rate = si5351_msynth_round_rate,
797+
.determine_rate = si5351_msynth_determine_rate,
795798
.set_rate = si5351_msynth_set_rate,
796799
};
797800

0 commit comments

Comments
 (0)