Skip to content

Commit bb631af

Browse files
osctobebebarino
authored andcommitted
clk: at91: optimize clk_round_rate() for AUDIO_PLL
Stop the search for parent rate when exact match is found. This makes for 3 clk_round_rate() calls instead of 64 of them on SAMA5D2-based board when searching for 12.288MHz clock. Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl> Reviewed-by: Nicolas Ferre <nicolas.ferre@microchip.com> Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent 77977b8 commit bb631af

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/clk/at91/clk-audio-pll.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,12 @@ static long clk_audio_pll_pmc_round_rate(struct clk_hw *hw, unsigned long rate,
340340
pr_debug("A PLL/PMC: %s, rate = %lu (parent_rate = %lu)\n", __func__,
341341
rate, *parent_rate);
342342

343-
for (div = 1; div <= AUDIO_PLL_QDPMC_MAX; div++) {
343+
if (!rate)
344+
return 0;
345+
346+
best_parent_rate = clk_round_rate(pclk->clk, 1);
347+
div = max(best_parent_rate / rate, 1UL);
348+
for (; div <= AUDIO_PLL_QDPMC_MAX; div++) {
344349
best_parent_rate = clk_round_rate(pclk->clk, rate * div);
345350
tmp_rate = best_parent_rate / div;
346351
tmp_diff = abs(rate - tmp_rate);
@@ -350,6 +355,8 @@ static long clk_audio_pll_pmc_round_rate(struct clk_hw *hw, unsigned long rate,
350355
best_rate = tmp_rate;
351356
best_diff = tmp_diff;
352357
tmp_qd = div;
358+
if (!best_diff)
359+
break; /* got exact match */
353360
}
354361
}
355362

0 commit comments

Comments
 (0)