Skip to content

Commit c8bfcfc

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

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

drivers/clk/clk-si5351.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,11 +1037,12 @@ static unsigned long si5351_clkout_recalc_rate(struct clk_hw *hw,
10371037
return parent_rate >> rdiv;
10381038
}
10391039

1040-
static long si5351_clkout_round_rate(struct clk_hw *hw, unsigned long rate,
1041-
unsigned long *parent_rate)
1040+
static int si5351_clkout_determine_rate(struct clk_hw *hw,
1041+
struct clk_rate_request *req)
10421042
{
10431043
struct si5351_hw_data *hwdata =
10441044
container_of(hw, struct si5351_hw_data, hw);
1045+
unsigned long rate = req->rate;
10451046
unsigned char rdiv;
10461047

10471048
/* clkout6/7 can only handle output freqencies < 150MHz */
@@ -1063,13 +1064,13 @@ static long si5351_clkout_round_rate(struct clk_hw *hw, unsigned long rate,
10631064
rdiv += 1;
10641065
rate *= 2;
10651066
}
1066-
*parent_rate = rate;
1067+
req->best_parent_rate = rate;
10671068
} else {
10681069
unsigned long new_rate, new_err, err;
10691070

10701071
/* round to closed rdiv */
10711072
rdiv = SI5351_OUTPUT_CLK_DIV_1;
1072-
new_rate = *parent_rate;
1073+
new_rate = req->best_parent_rate;
10731074
err = abs(new_rate - rate);
10741075
do {
10751076
new_rate >>= 1;
@@ -1080,14 +1081,15 @@ static long si5351_clkout_round_rate(struct clk_hw *hw, unsigned long rate,
10801081
err = new_err;
10811082
} while (1);
10821083
}
1083-
rate = *parent_rate >> rdiv;
1084+
rate = req->best_parent_rate >> rdiv;
10841085

10851086
dev_dbg(&hwdata->drvdata->client->dev,
10861087
"%s - %s: rdiv = %u, parent_rate = %lu, rate = %lu\n",
10871088
__func__, clk_hw_get_name(hw), (1 << rdiv),
1088-
*parent_rate, rate);
1089+
req->best_parent_rate, rate);
10891090

1090-
return rate;
1091+
req->rate = rate;
1092+
return 0;
10911093
}
10921094

10931095
static int si5351_clkout_set_rate(struct clk_hw *hw, unsigned long rate,
@@ -1147,7 +1149,7 @@ static const struct clk_ops si5351_clkout_ops = {
11471149
.set_parent = si5351_clkout_set_parent,
11481150
.get_parent = si5351_clkout_get_parent,
11491151
.recalc_rate = si5351_clkout_recalc_rate,
1150-
.round_rate = si5351_clkout_round_rate,
1152+
.determine_rate = si5351_clkout_determine_rate,
11511153
.set_rate = si5351_clkout_set_rate,
11521154
};
11531155

0 commit comments

Comments
 (0)