Skip to content

Commit 390227d

Browse files
claudiubezneabebarino
authored andcommitted
clk: at91: sam9x60-pll: check fcore against ranges
According to datasheet the range of 600-1200MHz is for the frequency generated by the fractional part of the PLL (namely Fcorepllck according to datasheet). With this in mind the output range of the PLL itself (fractional + div), taking into account that the divider is 8 bits wide, is 600/256-1200Hz=2.3-1200MHz. 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 1bef098 commit 390227d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
#define UPLL_DIV 2
2222
#define PLL_MUL_MAX (FIELD_GET(PMC_PLL_CTRL1_MUL_MSK, UINT_MAX) + 1)
2323

24+
#define FCORE_MIN (600000000)
25+
#define FCORE_MAX (1200000000)
26+
2427
#define PLL_MAX_ID 1
2528

2629
struct sam9x60_pll {
@@ -168,6 +171,7 @@ static long sam9x60_pll_get_best_div_mul(struct sam9x60_pll *pll,
168171
unsigned long bestdiv = 0;
169172
unsigned long bestmul = 0;
170173
unsigned long bestfrac = 0;
174+
u64 fcore = 0;
171175

172176
if (rate < characteristics->output[0].min ||
173177
rate > characteristics->output[0].max)
@@ -212,6 +216,11 @@ static long sam9x60_pll_get_best_div_mul(struct sam9x60_pll *pll,
212216
remainder = rate - tmprate;
213217
}
214218

219+
fcore = parent_rate * (tmpmul + 1) +
220+
((u64)parent_rate * tmpfrac >> 22);
221+
if (fcore < FCORE_MIN || fcore > FCORE_MAX)
222+
continue;
223+
215224
/*
216225
* Compare the remainder with the best remainder found until
217226
* now and elect a new best multiplier/divider pair if the
@@ -231,7 +240,8 @@ static long sam9x60_pll_get_best_div_mul(struct sam9x60_pll *pll,
231240
}
232241

233242
/* Check if bestrate is a valid output rate */
234-
if (bestrate < characteristics->output[0].min ||
243+
if (fcore < FCORE_MIN || fcore > FCORE_MAX ||
244+
bestrate < characteristics->output[0].min ||
235245
bestrate > characteristics->output[0].max)
236246
return -ERANGE;
237247

drivers/clk/at91/sam9x60.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static const struct clk_master_layout sam9x60_master_layout = {
2222
};
2323

2424
static const struct clk_range plla_outputs[] = {
25-
{ .min = 300000000, .max = 600000000 },
25+
{ .min = 2343750, .max = 1200000000 },
2626
};
2727

2828
static const struct clk_pll_characteristics plla_characteristics = {

0 commit comments

Comments
 (0)