Skip to content

Commit 0a1be86

Browse files
jbrun3tsuperna9999
authored andcommitted
clk: meson: add ROUND_CLOSEST to the pll driver
Provide an option for the pll driver to round to the rate closest to the requested rate, instead of systematically rounding down. This may allow the provided rate to be closer to the requested rate when rounding up is not an issue Signed-off-by: Jerome Brunet <[email protected]> Signed-off-by: Neil Armstrong <[email protected]>
1 parent c77de0e commit 0a1be86

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

drivers/clk/meson/clk-pll.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ static u16 __pll_params_with_frac(unsigned long rate,
105105
u64 val = (u64)rate * pllt->n;
106106

107107
val <<= pllt->od + pllt->od2 + pllt->od3;
108-
val = div_u64(val * frac_max, parent_rate);
108+
109+
if (pll->flags & CLK_MESON_PLL_ROUND_CLOSEST)
110+
val = DIV_ROUND_CLOSEST_ULL(val * frac_max, parent_rate);
111+
else
112+
val = div_u64(val * frac_max, parent_rate);
113+
109114
val -= pllt->m * frac_max;
110115

111116
return min((u16)val, (u16)(frac_max - 1));
@@ -125,9 +130,13 @@ meson_clk_get_pll_settings(unsigned long rate,
125130
while (table[i].rate && table[i].rate <= rate)
126131
i++;
127132

128-
/* Select the setting of the rounded down rate */
129-
if (i != 0)
130-
i--;
133+
if (i != 0) {
134+
if (MESON_PARM_APPLICABLE(&pll->frac) ||
135+
!(pll->flags & CLK_MESON_PLL_ROUND_CLOSEST) ||
136+
(abs(rate - table[i - 1].rate) <
137+
abs(rate - table[i].rate)))
138+
i--;
139+
}
131140

132141
return (struct pll_rate_table *)&table[i];
133142
}

drivers/clk/meson/clkc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ struct pll_rate_table {
7171
.od = (_od), \
7272
}
7373

74+
#define CLK_MESON_PLL_ROUND_CLOSEST BIT(0)
75+
7476
struct meson_clk_pll_data {
7577
struct parm m;
7678
struct parm n;

0 commit comments

Comments
 (0)