Skip to content

Commit 7224e54

Browse files
committed
Merge branch 'at91-5.4-trunk/base_clk' into linux-5.4-at91
2 parents 63cdda6 + 96df32a commit 7224e54

5 files changed

Lines changed: 55 additions & 22 deletions

File tree

drivers/clk/at91/clk-generated.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ static int clk_generated_determine_rate(struct clk_hw *hw,
170170

171171
for (div = 1; div < GENERATED_MAX_DIV + 2; div++) {
172172
req_parent.rate = req->rate * div;
173-
__clk_determine_rate(parent, &req_parent);
173+
if (__clk_determine_rate(parent, &req_parent))
174+
continue;
174175
clk_generated_best_diff(req, parent, req_parent.rate, div,
175176
&best_diff, &best_rate);
176177

@@ -184,8 +185,8 @@ static int clk_generated_determine_rate(struct clk_hw *hw,
184185
__clk_get_name((req->best_parent_hw)->clk),
185186
req->best_parent_rate);
186187

187-
if (best_rate < 0)
188-
return best_rate;
188+
if (best_rate < 0 || (gck->range.max && best_rate > gck->range.max))
189+
return -EINVAL;
189190

190191
req->rate = best_rate;
191192
return 0;

drivers/clk/at91/clk-peripheral.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ at91_clk_register_peripheral(struct regmap *regmap, const char *name,
111111

112112
init.name = name;
113113
init.ops = &peripheral_ops;
114-
init.parent_names = (parent_name ? &parent_name : NULL);
115-
init.num_parents = (parent_name ? 1 : 0);
114+
init.parent_names = &parent_name;
115+
init.num_parents = 1;
116116
init.flags = 0;
117117

118118
periph->id = id;

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

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,38 @@
1414

1515
#include "pmc.h"
1616

17+
#define PMC_PLL_CTRL0 0xc
18+
#define PMC_PLL_CTRL0_DIV_MSK GENMASK(7, 0)
19+
#define PMC_PLL_CTRL0_ENPLL BIT(28)
20+
#define PMC_PLL_CTRL0_ENPLLCK BIT(29)
21+
#define PMC_PLL_CTRL0_ENLOCK BIT(31)
22+
23+
#define PMC_PLL_CTRL1 0x10
24+
#define PMC_PLL_CTRL1_FRACR_MSK GENMASK(21, 0)
25+
#define PMC_PLL_CTRL1_MUL_MSK GENMASK(30, 24)
26+
27+
#define PMC_PLL_ACR 0x18
28+
#define PMC_PLL_ACR_DEFAULT_UPLL 0x12020010UL
29+
#define PMC_PLL_ACR_DEFAULT_PLLA 0x00020010UL
30+
#define PMC_PLL_ACR_UTMIVR BIT(12)
31+
#define PMC_PLL_ACR_UTMIBG BIT(13)
32+
#define PMC_PLL_ACR_LOOP_FILTER_MSK GENMASK(31, 24)
33+
34+
#define PMC_PLL_UPDT 0x1c
35+
#define PMC_PLL_UPDT_UPDATE BIT(8)
36+
37+
#define PMC_PLL_ISR0 0xec
1738
#define PMC_PLL_CTRL0_DIV_MSK GENMASK(7, 0)
18-
#define PMC_PLL_CTRL1_MUL_MSK GENMASK(30, 24)
39+
#define PMC_PLL_CTRL1_MUL_MSK GENMASK(31, 24)
40+
#define PMC_PLL_CTRL1_FRACR_MSK GENMASK(21, 0)
1941

2042
#define PLL_DIV_MAX (FIELD_GET(PMC_PLL_CTRL0_DIV_MSK, UINT_MAX) + 1)
2143
#define UPLL_DIV 2
2244
#define PLL_MUL_MAX (FIELD_GET(PMC_PLL_CTRL1_MUL_MSK, UINT_MAX) + 1)
2345

46+
#define FCORE_MIN (600000000)
47+
#define FCORE_MAX (1200000000)
48+
2449
#define PLL_MAX_ID 1
2550

2651
struct sam9x60_pll {
@@ -52,7 +77,7 @@ static int sam9x60_pll_prepare(struct clk_hw *hw)
5277
unsigned long flags;
5378
u8 div;
5479
u16 mul;
55-
u32 val;
80+
u32 val, frac;
5681

5782
spin_lock_irqsave(pll->lock, flags);
5883
regmap_write(regmap, AT91_PMC_PLL_UPDT, pll->id);
@@ -62,9 +87,10 @@ static int sam9x60_pll_prepare(struct clk_hw *hw)
6287

6388
regmap_read(regmap, AT91_PMC_PLL_CTRL1, &val);
6489
mul = FIELD_GET(PMC_PLL_CTRL1_MUL_MSK, val);
90+
frac = FIELD_GET(PMC_PLL_CTRL1_FRACR_MSK, val);
6591

6692
if (sam9x60_pll_ready(regmap, pll->id) &&
67-
(div == pll->div && mul == pll->mul)) {
93+
(div == pll->div && mul == pll->mul && frac == pll->frac)) {
6894
spin_unlock_irqrestore(pll->lock, flags);
6995
return 0;
7096
}
@@ -77,7 +103,8 @@ static int sam9x60_pll_prepare(struct clk_hw *hw)
77103
regmap_write(regmap, AT91_PMC_PLL_ACR, val);
78104

79105
regmap_write(regmap, AT91_PMC_PLL_CTRL1,
80-
FIELD_PREP(PMC_PLL_CTRL1_MUL_MSK, pll->mul));
106+
FIELD_PREP(PMC_PLL_CTRL1_MUL_MSK, pll->mul) |
107+
FIELD_PREP(PMC_PLL_CTRL1_FRACR_MSK, pll->frac));
81108

82109
if (pll->characteristics->upll) {
83110
/* Enable the UTMI internal bandgap */
@@ -152,7 +179,8 @@ static unsigned long sam9x60_pll_recalc_rate(struct clk_hw *hw,
152179
{
153180
struct sam9x60_pll *pll = to_sam9x60_pll(hw);
154181

155-
return (parent_rate * (pll->mul + 1)) / (pll->div + 1);
182+
return DIV_ROUND_CLOSEST_ULL((parent_rate * (pll->mul + 1) +
183+
((u64)parent_rate * pll->frac >> 22)), (pll->div + 1));
156184
}
157185

158186
static long sam9x60_pll_get_best_div_mul(struct sam9x60_pll *pll,
@@ -168,6 +196,7 @@ static long sam9x60_pll_get_best_div_mul(struct sam9x60_pll *pll,
168196
unsigned long bestdiv = 0;
169197
unsigned long bestmul = 0;
170198
unsigned long bestfrac = 0;
199+
u64 fcore = 0;
171200

172201
if (rate < characteristics->output[0].min ||
173202
rate > characteristics->output[0].max)
@@ -212,6 +241,11 @@ static long sam9x60_pll_get_best_div_mul(struct sam9x60_pll *pll,
212241
remainder = rate - tmprate;
213242
}
214243

244+
fcore = parent_rate * (tmpmul + 1) +
245+
((u64)parent_rate * tmpfrac >> 22);
246+
if (fcore < FCORE_MIN || fcore > FCORE_MAX)
247+
continue;
248+
215249
/*
216250
* Compare the remainder with the best remainder found until
217251
* now and elect a new best multiplier/divider pair if the
@@ -231,7 +265,8 @@ static long sam9x60_pll_get_best_div_mul(struct sam9x60_pll *pll,
231265
}
232266

233267
/* Check if bestrate is a valid output rate */
234-
if (bestrate < characteristics->output[0].min &&
268+
if (fcore < FCORE_MIN || fcore > FCORE_MAX ||
269+
bestrate < characteristics->output[0].min ||
235270
bestrate > characteristics->output[0].max)
236271
return -ERANGE;
237272

drivers/clk/at91/sam9x60.c

Lines changed: 5 additions & 9 deletions
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 = {
@@ -159,7 +159,6 @@ static void __init sam9x60_pmc_setup(struct device_node *np)
159159
struct regmap *regmap;
160160
struct clk_hw *hw;
161161
int i;
162-
bool bypass;
163162

164163
i = of_property_match_string(np, "clock-names", "td_slck");
165164
if (i < 0)
@@ -178,7 +177,7 @@ static void __init sam9x60_pmc_setup(struct device_node *np)
178177
return;
179178
mainxtal_name = of_clk_get_parent_name(np, i);
180179

181-
regmap = syscon_node_to_regmap(np);
180+
regmap = device_node_to_regmap(np);
182181
if (IS_ERR(regmap))
183182
return;
184183

@@ -189,15 +188,12 @@ static void __init sam9x60_pmc_setup(struct device_node *np)
189188
if (!sam9x60_pmc)
190189
return;
191190

192-
hw = at91_clk_register_main_rc_osc(regmap, "main_rc_osc", 24000000,
191+
hw = at91_clk_register_main_rc_osc(regmap, "main_rc_osc", 12000000,
193192
50000000);
194193
if (IS_ERR(hw))
195194
goto err_free;
196195

197-
bypass = of_property_read_bool(np, "atmel,osc-bypass");
198-
199-
hw = at91_clk_register_main_osc(regmap, "main_osc", mainxtal_name,
200-
bypass);
196+
hw = at91_clk_register_main_osc(regmap, "main_osc", mainxtal_name, 0);
201197
if (IS_ERR(hw))
202198
goto err_free;
203199

@@ -245,7 +241,7 @@ static void __init sam9x60_pmc_setup(struct device_node *np)
245241
parent_names[3] = "masterck";
246242
parent_names[4] = "pllack";
247243
parent_names[5] = "upllck";
248-
for (i = 0; i < 8; i++) {
244+
for (i = 0; i < 2; i++) {
249245
char name[6];
250246

251247
snprintf(name, sizeof(name), "prog%d", i);

drivers/clk/at91/sckc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,9 @@ static void __init of_sam9x60_sckc_setup(struct device_node *np)
471471
if (!regbase)
472472
return;
473473

474-
slow_rc = clk_hw_register_fixed_rate(NULL, parent_names[0], NULL, 0,
475-
32768);
474+
slow_rc = clk_hw_register_fixed_rate_with_accuracy(NULL, parent_names[0],
475+
NULL, 0, 32768,
476+
93750000);
476477
if (IS_ERR(slow_rc))
477478
return;
478479

0 commit comments

Comments
 (0)