16 #include <linux/slab.h>
21 #define PLL_NUM_OFFSET 0x10
22 #define PLL_DENOM_OFFSET 0x20
24 #define BM_PLL_POWER (0x1 << 12)
25 #define BM_PLL_ENABLE (0x1 << 13)
26 #define BM_PLL_BYPASS (0x1 << 16)
27 #define BM_PLL_LOCK (0x1 << 31)
48 #define to_clk_pllv3(_hw) container_of(_hw, struct clk_pllv3, hw)
50 static int clk_pllv3_prepare(
struct clk_hw *
hw)
62 writel_relaxed(val, pll->
base);
72 static void clk_pllv3_unprepare(
struct clk_hw *
hw)
83 writel_relaxed(val, pll->
base);
86 static int clk_pllv3_enable(
struct clk_hw *hw)
93 writel_relaxed(val, pll->
base);
98 static void clk_pllv3_disable(
struct clk_hw *hw)
105 writel_relaxed(val, pll->
base);
108 static unsigned long clk_pllv3_recalc_rate(
struct clk_hw *hw,
109 unsigned long parent_rate)
114 return (div == 1) ? parent_rate * 22 : parent_rate * 20;
117 static long clk_pllv3_round_rate(
struct clk_hw *hw,
unsigned long rate,
118 unsigned long *
prate)
120 unsigned long parent_rate = *
prate;
122 return (rate >= parent_rate * 22) ? parent_rate * 22 :
126 static int clk_pllv3_set_rate(
struct clk_hw *hw,
unsigned long rate,
127 unsigned long parent_rate)
132 if (rate == parent_rate * 22)
134 else if (rate == parent_rate * 20)
142 writel_relaxed(val, pll->
base);
147 static const struct clk_ops clk_pllv3_ops = {
148 .prepare = clk_pllv3_prepare,
149 .unprepare = clk_pllv3_unprepare,
150 .enable = clk_pllv3_enable,
151 .disable = clk_pllv3_disable,
152 .recalc_rate = clk_pllv3_recalc_rate,
153 .round_rate = clk_pllv3_round_rate,
154 .set_rate = clk_pllv3_set_rate,
157 static unsigned long clk_pllv3_sys_recalc_rate(
struct clk_hw *hw,
158 unsigned long parent_rate)
163 return parent_rate * div / 2;
166 static long clk_pllv3_sys_round_rate(
struct clk_hw *hw,
unsigned long rate,
167 unsigned long *prate)
169 unsigned long parent_rate = *
prate;
170 unsigned long min_rate = parent_rate * 54 / 2;
171 unsigned long max_rate = parent_rate * 108 / 2;
176 else if (rate < min_rate)
178 div = rate * 2 / parent_rate;
180 return parent_rate * div / 2;
183 static int clk_pllv3_sys_set_rate(
struct clk_hw *hw,
unsigned long rate,
184 unsigned long parent_rate)
187 unsigned long min_rate = parent_rate * 54 / 2;
188 unsigned long max_rate = parent_rate * 108 / 2;
191 if (rate < min_rate || rate > max_rate)
194 div = rate * 2 / parent_rate;
198 writel_relaxed(val, pll->
base);
203 static const struct clk_ops clk_pllv3_sys_ops = {
204 .prepare = clk_pllv3_prepare,
205 .unprepare = clk_pllv3_unprepare,
206 .enable = clk_pllv3_enable,
207 .disable = clk_pllv3_disable,
208 .recalc_rate = clk_pllv3_sys_recalc_rate,
209 .round_rate = clk_pllv3_sys_round_rate,
210 .set_rate = clk_pllv3_sys_set_rate,
213 static unsigned long clk_pllv3_av_recalc_rate(
struct clk_hw *hw,
214 unsigned long parent_rate)
221 return (parent_rate * div) + ((parent_rate / mfd) * mfn);
224 static long clk_pllv3_av_round_rate(
struct clk_hw *hw,
unsigned long rate,
225 unsigned long *prate)
227 unsigned long parent_rate = *
prate;
228 unsigned long min_rate = parent_rate * 27;
229 unsigned long max_rate = parent_rate * 54;
231 u32 mfn, mfd = 1000000;
236 else if (rate < min_rate)
239 div = rate / parent_rate;
240 temp64 = (
u64) (rate - div * parent_rate);
242 do_div(temp64, parent_rate);
245 return parent_rate * div + parent_rate / mfd * mfn;
248 static int clk_pllv3_av_set_rate(
struct clk_hw *hw,
unsigned long rate,
249 unsigned long parent_rate)
252 unsigned long min_rate = parent_rate * 27;
253 unsigned long max_rate = parent_rate * 54;
255 u32 mfn, mfd = 1000000;
258 if (rate < min_rate || rate > max_rate)
261 div = rate / parent_rate;
262 temp64 = (
u64) (rate - div * parent_rate);
264 do_div(temp64, parent_rate);
270 writel_relaxed(val, pll->
base);
277 static const struct clk_ops clk_pllv3_av_ops = {
278 .prepare = clk_pllv3_prepare,
279 .unprepare = clk_pllv3_unprepare,
280 .enable = clk_pllv3_enable,
281 .disable = clk_pllv3_disable,
282 .recalc_rate = clk_pllv3_av_recalc_rate,
283 .round_rate = clk_pllv3_av_round_rate,
284 .set_rate = clk_pllv3_av_set_rate,
287 static unsigned long clk_pllv3_enet_recalc_rate(
struct clk_hw *hw,
288 unsigned long parent_rate)
307 static long clk_pllv3_enet_round_rate(
struct clk_hw *hw,
unsigned long rate,
308 unsigned long *prate)
310 if (rate >= 125000000)
312 else if (rate >= 100000000)
314 else if (rate >= 50000000)
321 static int clk_pllv3_enet_set_rate(
struct clk_hw *hw,
unsigned long rate,
322 unsigned long parent_rate)
347 writel_relaxed(val, pll->
base);
352 static const struct clk_ops clk_pllv3_enet_ops = {
353 .prepare = clk_pllv3_prepare,
354 .unprepare = clk_pllv3_unprepare,
355 .enable = clk_pllv3_enable,
356 .disable = clk_pllv3_disable,
357 .recalc_rate = clk_pllv3_enet_recalc_rate,
358 .round_rate = clk_pllv3_enet_round_rate,
359 .set_rate = clk_pllv3_enet_set_rate,
362 static const struct clk_ops clk_pllv3_mlb_ops = {
363 .prepare = clk_pllv3_prepare,
364 .unprepare = clk_pllv3_unprepare,
365 .enable = clk_pllv3_enable,
366 .disable = clk_pllv3_disable,
370 const char *parent_name,
void __iomem *base,
376 struct clk_init_data init;
384 ops = &clk_pllv3_sys_ops;
387 ops = &clk_pllv3_ops;
388 pll->powerup_set =
true;
391 ops = &clk_pllv3_av_ops;
394 ops = &clk_pllv3_enet_ops;
397 ops = &clk_pllv3_mlb_ops;
400 ops = &clk_pllv3_ops;
403 pll->gate_mask = gate_mask;
409 init.parent_names = &parent_name;
410 init.num_parents = 1;