Skip to content

Commit a1bb281

Browse files
committed
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 <claudiu.beznea@microchip.com> Link: https://lore.kernel.org/r/1595403506-8209-6-git-send-email-claudiu.beznea@microchip.com Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent 51c7917 commit a1bb281

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
#define UPLL_DIV 2
4343
#define PLL_MUL_MAX (FIELD_GET(PMC_PLL_CTRL1_MUL_MSK, UINT_MAX) + 1)
4444

45+
#define FCORE_MIN (600000000)
46+
#define FCORE_MAX (1200000000)
47+
4548
#define PLL_MAX_ID 1
4649

4750
struct sam9x60_pll {
@@ -187,6 +190,7 @@ static long sam9x60_pll_get_best_div_mul(struct sam9x60_pll *pll,
187190
unsigned long bestdiv = 0;
188191
unsigned long bestmul = 0;
189192
unsigned long bestfrac = 0;
193+
u64 fcore = 0;
190194

191195
if (rate < characteristics->output[0].min ||
192196
rate > characteristics->output[0].max)
@@ -231,6 +235,11 @@ static long sam9x60_pll_get_best_div_mul(struct sam9x60_pll *pll,
231235
remainder = rate - tmprate;
232236
}
233237

238+
fcore = parent_rate * (tmpmul + 1) +
239+
((u64)parent_rate * tmpfrac >> 22);
240+
if (fcore < FCORE_MIN || fcore > FCORE_MAX)
241+
continue;
242+
234243
/*
235244
* Compare the remainder with the best remainder found until
236245
* now and elect a new best multiplier/divider pair if the
@@ -250,7 +259,8 @@ static long sam9x60_pll_get_best_div_mul(struct sam9x60_pll *pll,
250259
}
251260

252261
/* Check if bestrate is a valid output rate */
253-
if (bestrate < characteristics->output[0].min ||
262+
if (fcore < FCORE_MIN || fcore > FCORE_MAX ||
263+
bestrate < characteristics->output[0].min ||
254264
bestrate > characteristics->output[0].max)
255265
return -ERANGE;
256266

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)