Skip to content

Commit 35d06f7

Browse files
claudiubezneabebarino
authored andcommitted
clk: at91: sam9x60-pll: use frac when setting frequency
In commit a436c2a ("clk: at91: add sam9x60 PLL driver") the fractional part of PLL wasn't set on registers but it was calculated and taken into account for determining div and mul (see sam9x60_pll_get_best_div_mul()). Fixes: a436c2a ("clk: at91: add sam9x60 PLL driver") Signed-off-by: Claudiu Beznea <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent 390227d commit 35d06f7

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#define PMC_PLL_CTRL0_DIV_MSK GENMASK(7, 0)
1818
#define PMC_PLL_CTRL1_MUL_MSK GENMASK(31, 24)
19+
#define PMC_PLL_CTRL1_FRACR_MSK GENMASK(21, 0)
1920

2021
#define PLL_DIV_MAX (FIELD_GET(PMC_PLL_CTRL0_DIV_MSK, UINT_MAX) + 1)
2122
#define UPLL_DIV 2
@@ -55,7 +56,7 @@ static int sam9x60_pll_prepare(struct clk_hw *hw)
5556
unsigned long flags;
5657
u8 div;
5758
u16 mul;
58-
u32 val;
59+
u32 val, frac;
5960

6061
spin_lock_irqsave(pll->lock, flags);
6162
regmap_write(regmap, AT91_PMC_PLL_UPDT, pll->id);
@@ -65,9 +66,10 @@ static int sam9x60_pll_prepare(struct clk_hw *hw)
6566

6667
regmap_read(regmap, AT91_PMC_PLL_CTRL1, &val);
6768
mul = FIELD_GET(PMC_PLL_CTRL1_MUL_MSK, val);
69+
frac = FIELD_GET(PMC_PLL_CTRL1_FRACR_MSK, val);
6870

6971
if (sam9x60_pll_ready(regmap, pll->id) &&
70-
(div == pll->div && mul == pll->mul)) {
72+
(div == pll->div && mul == pll->mul && frac == pll->frac)) {
7173
spin_unlock_irqrestore(pll->lock, flags);
7274
return 0;
7375
}
@@ -80,7 +82,8 @@ static int sam9x60_pll_prepare(struct clk_hw *hw)
8082
regmap_write(regmap, AT91_PMC_PLL_ACR, val);
8183

8284
regmap_write(regmap, AT91_PMC_PLL_CTRL1,
83-
FIELD_PREP(PMC_PLL_CTRL1_MUL_MSK, pll->mul));
85+
FIELD_PREP(PMC_PLL_CTRL1_MUL_MSK, pll->mul) |
86+
FIELD_PREP(PMC_PLL_CTRL1_FRACR_MSK, pll->frac));
8487

8588
if (pll->characteristics->upll) {
8689
/* Enable the UTMI internal bandgap */
@@ -155,7 +158,8 @@ static unsigned long sam9x60_pll_recalc_rate(struct clk_hw *hw,
155158
{
156159
struct sam9x60_pll *pll = to_sam9x60_pll(hw);
157160

158-
return (parent_rate * (pll->mul + 1)) / (pll->div + 1);
161+
return DIV_ROUND_CLOSEST_ULL((parent_rate * (pll->mul + 1) +
162+
((u64)parent_rate * pll->frac >> 22)), (pll->div + 1));
159163
}
160164

161165
static long sam9x60_pll_get_best_div_mul(struct sam9x60_pll *pll,

0 commit comments

Comments
 (0)