diff options
author | Dinh Nguyen <Dinh.Nguyen@freescale.com> | 2010-11-15 12:29:59 -0500 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2010-11-24 04:09:04 -0500 |
commit | c0abefd30b2c9db015df4914a95d268ecdb39b00 (patch) | |
tree | 810c6f6e8e00604a78379424a6aae2140d7fadd5 /arch/arm/mach-mx5/clock-mx51-mx53.c | |
parent | 374daa4f9019f75da1addb3f31a22df1966a5baa (diff) |
ARM: imx: Add core definitions for MX53
Add iomux, clocks, and memory map for Freescale's MX53 SoC.
Add cpu_is_mx53 function to common.h.
Add 3 more banks of gpio's to mxc_gpio_ports.
Add MX53 phys offset address.
Signed-off-by: Dinh Nguyen <Dinh.Nguyen@freescale.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/arm/mach-mx5/clock-mx51-mx53.c')
-rw-r--r-- | arch/arm/mach-mx5/clock-mx51-mx53.c | 1189 |
1 files changed, 1189 insertions, 0 deletions
diff --git a/arch/arm/mach-mx5/clock-mx51-mx53.c b/arch/arm/mach-mx5/clock-mx51-mx53.c new file mode 100644 index 000000000000..ca4f9d58cfeb --- /dev/null +++ b/arch/arm/mach-mx5/clock-mx51-mx53.c | |||
@@ -0,0 +1,1189 @@ | |||
1 | /* | ||
2 | * Copyright 2008-2010 Freescale Semiconductor, Inc. All Rights Reserved. | ||
3 | * Copyright (C) 2009-2010 Amit Kucheria <amit.kucheria@canonical.com> | ||
4 | * | ||
5 | * The code contained herein is licensed under the GNU General Public | ||
6 | * License. You may obtain a copy of the GNU General Public License | ||
7 | * Version 2 or later at the following locations: | ||
8 | * | ||
9 | * http://www.opensource.org/licenses/gpl-license.html | ||
10 | * http://www.gnu.org/copyleft/gpl.html | ||
11 | */ | ||
12 | |||
13 | #include <linux/mm.h> | ||
14 | #include <linux/delay.h> | ||
15 | #include <linux/clk.h> | ||
16 | #include <linux/io.h> | ||
17 | |||
18 | #include <asm/clkdev.h> | ||
19 | #include <asm/div64.h> | ||
20 | |||
21 | #include <mach/hardware.h> | ||
22 | #include <mach/common.h> | ||
23 | #include <mach/clock.h> | ||
24 | |||
25 | #include "crm_regs.h" | ||
26 | |||
27 | /* External clock values passed-in by the board code */ | ||
28 | static unsigned long external_high_reference, external_low_reference; | ||
29 | static unsigned long oscillator_reference, ckih2_reference; | ||
30 | |||
31 | static struct clk osc_clk; | ||
32 | static struct clk pll1_main_clk; | ||
33 | static struct clk pll1_sw_clk; | ||
34 | static struct clk pll2_sw_clk; | ||
35 | static struct clk pll3_sw_clk; | ||
36 | static struct clk mx53_pll4_sw_clk; | ||
37 | static struct clk lp_apm_clk; | ||
38 | static struct clk periph_apm_clk; | ||
39 | static struct clk ahb_clk; | ||
40 | static struct clk ipg_clk; | ||
41 | static struct clk usboh3_clk; | ||
42 | |||
43 | #define MAX_DPLL_WAIT_TRIES 1000 /* 1000 * udelay(1) = 1ms */ | ||
44 | |||
45 | /* calculate best pre and post dividers to get the required divider */ | ||
46 | static void __calc_pre_post_dividers(u32 div, u32 *pre, u32 *post, | ||
47 | u32 max_pre, u32 max_post) | ||
48 | { | ||
49 | if (div >= max_pre * max_post) { | ||
50 | *pre = max_pre; | ||
51 | *post = max_post; | ||
52 | } else if (div >= max_pre) { | ||
53 | u32 min_pre, temp_pre, old_err, err; | ||
54 | min_pre = DIV_ROUND_UP(div, max_post); | ||
55 | old_err = max_pre; | ||
56 | for (temp_pre = max_pre; temp_pre >= min_pre; temp_pre--) { | ||
57 | err = div % temp_pre; | ||
58 | if (err == 0) { | ||
59 | *pre = temp_pre; | ||
60 | break; | ||
61 | } | ||
62 | err = temp_pre - err; | ||
63 | if (err < old_err) { | ||
64 | old_err = err; | ||
65 | *pre = temp_pre; | ||
66 | } | ||
67 | } | ||
68 | *post = DIV_ROUND_UP(div, *pre); | ||
69 | } else { | ||
70 | *pre = div; | ||
71 | *post = 1; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | static void _clk_ccgr_setclk(struct clk *clk, unsigned mode) | ||
76 | { | ||
77 | u32 reg = __raw_readl(clk->enable_reg); | ||
78 | |||
79 | reg &= ~(MXC_CCM_CCGRx_CG_MASK << clk->enable_shift); | ||
80 | reg |= mode << clk->enable_shift; | ||
81 | |||
82 | __raw_writel(reg, clk->enable_reg); | ||
83 | } | ||
84 | |||
85 | static int _clk_ccgr_enable(struct clk *clk) | ||
86 | { | ||
87 | _clk_ccgr_setclk(clk, MXC_CCM_CCGRx_MOD_ON); | ||
88 | return 0; | ||
89 | } | ||
90 | |||
91 | static void _clk_ccgr_disable(struct clk *clk) | ||
92 | { | ||
93 | _clk_ccgr_setclk(clk, MXC_CCM_CCGRx_MOD_OFF); | ||
94 | } | ||
95 | |||
96 | static int _clk_ccgr_enable_inrun(struct clk *clk) | ||
97 | { | ||
98 | _clk_ccgr_setclk(clk, MXC_CCM_CCGRx_MOD_IDLE); | ||
99 | return 0; | ||
100 | } | ||
101 | |||
102 | static void _clk_ccgr_disable_inwait(struct clk *clk) | ||
103 | { | ||
104 | _clk_ccgr_setclk(clk, MXC_CCM_CCGRx_MOD_IDLE); | ||
105 | } | ||
106 | |||
107 | /* | ||
108 | * For the 4-to-1 muxed input clock | ||
109 | */ | ||
110 | static inline u32 _get_mux(struct clk *parent, struct clk *m0, | ||
111 | struct clk *m1, struct clk *m2, struct clk *m3) | ||
112 | { | ||
113 | if (parent == m0) | ||
114 | return 0; | ||
115 | else if (parent == m1) | ||
116 | return 1; | ||
117 | else if (parent == m2) | ||
118 | return 2; | ||
119 | else if (parent == m3) | ||
120 | return 3; | ||
121 | else | ||
122 | BUG(); | ||
123 | |||
124 | return -EINVAL; | ||
125 | } | ||
126 | |||
127 | static inline void __iomem *_get_pll_base(struct clk *pll) | ||
128 | { | ||
129 | if (pll == &pll1_main_clk) | ||
130 | return MX51_DPLL1_BASE; | ||
131 | else if (pll == &pll2_sw_clk) | ||
132 | return MX51_DPLL2_BASE; | ||
133 | else if (pll == &pll3_sw_clk) | ||
134 | return MX51_DPLL3_BASE; | ||
135 | else if (pll == &mx53_pll4_sw_clk) | ||
136 | return MX53_DPLL4_BASE; | ||
137 | else | ||
138 | BUG(); | ||
139 | |||
140 | return NULL; | ||
141 | } | ||
142 | |||
143 | static unsigned long clk_pll_get_rate(struct clk *clk) | ||
144 | { | ||
145 | long mfi, mfn, mfd, pdf, ref_clk, mfn_abs; | ||
146 | unsigned long dp_op, dp_mfd, dp_mfn, dp_ctl, pll_hfsm, dbl; | ||
147 | void __iomem *pllbase; | ||
148 | s64 temp; | ||
149 | unsigned long parent_rate; | ||
150 | |||
151 | parent_rate = clk_get_rate(clk->parent); | ||
152 | |||
153 | pllbase = _get_pll_base(clk); | ||
154 | |||
155 | dp_ctl = __raw_readl(pllbase + MXC_PLL_DP_CTL); | ||
156 | pll_hfsm = dp_ctl & MXC_PLL_DP_CTL_HFSM; | ||
157 | dbl = dp_ctl & MXC_PLL_DP_CTL_DPDCK0_2_EN; | ||
158 | |||
159 | if (pll_hfsm == 0) { | ||
160 | dp_op = __raw_readl(pllbase + MXC_PLL_DP_OP); | ||
161 | dp_mfd = __raw_readl(pllbase + MXC_PLL_DP_MFD); | ||
162 | dp_mfn = __raw_readl(pllbase + MXC_PLL_DP_MFN); | ||
163 | } else { | ||
164 | dp_op = __raw_readl(pllbase + MXC_PLL_DP_HFS_OP); | ||
165 | dp_mfd = __raw_readl(pllbase + MXC_PLL_DP_HFS_MFD); | ||
166 | dp_mfn = __raw_readl(pllbase + MXC_PLL_DP_HFS_MFN); | ||
167 | } | ||
168 | pdf = dp_op & MXC_PLL_DP_OP_PDF_MASK; | ||
169 | mfi = (dp_op & MXC_PLL_DP_OP_MFI_MASK) >> MXC_PLL_DP_OP_MFI_OFFSET; | ||
170 | mfi = (mfi <= 5) ? 5 : mfi; | ||
171 | mfd = dp_mfd & MXC_PLL_DP_MFD_MASK; | ||
172 | mfn = mfn_abs = dp_mfn & MXC_PLL_DP_MFN_MASK; | ||
173 | /* Sign extend to 32-bits */ | ||
174 | if (mfn >= 0x04000000) { | ||
175 | mfn |= 0xFC000000; | ||
176 | mfn_abs = -mfn; | ||
177 | } | ||
178 | |||
179 | ref_clk = 2 * parent_rate; | ||
180 | if (dbl != 0) | ||
181 | ref_clk *= 2; | ||
182 | |||
183 | ref_clk /= (pdf + 1); | ||
184 | temp = (u64) ref_clk * mfn_abs; | ||
185 | do_div(temp, mfd + 1); | ||
186 | if (mfn < 0) | ||
187 | temp = -temp; | ||
188 | temp = (ref_clk * mfi) + temp; | ||
189 | |||
190 | return temp; | ||
191 | } | ||
192 | |||
193 | static int _clk_pll_set_rate(struct clk *clk, unsigned long rate) | ||
194 | { | ||
195 | u32 reg; | ||
196 | void __iomem *pllbase; | ||
197 | |||
198 | long mfi, pdf, mfn, mfd = 999999; | ||
199 | s64 temp64; | ||
200 | unsigned long quad_parent_rate; | ||
201 | unsigned long pll_hfsm, dp_ctl; | ||
202 | unsigned long parent_rate; | ||
203 | |||
204 | parent_rate = clk_get_rate(clk->parent); | ||
205 | |||
206 | pllbase = _get_pll_base(clk); | ||
207 | |||
208 | quad_parent_rate = 4 * parent_rate; | ||
209 | pdf = mfi = -1; | ||
210 | while (++pdf < 16 && mfi < 5) | ||
211 | mfi = rate * (pdf+1) / quad_parent_rate; | ||
212 | if (mfi > 15) | ||
213 | return -EINVAL; | ||
214 | pdf--; | ||
215 | |||
216 | temp64 = rate * (pdf+1) - quad_parent_rate * mfi; | ||
217 | do_div(temp64, quad_parent_rate/1000000); | ||
218 | mfn = (long)temp64; | ||
219 | |||
220 | dp_ctl = __raw_readl(pllbase + MXC_PLL_DP_CTL); | ||
221 | /* use dpdck0_2 */ | ||
222 | __raw_writel(dp_ctl | 0x1000L, pllbase + MXC_PLL_DP_CTL); | ||
223 | pll_hfsm = dp_ctl & MXC_PLL_DP_CTL_HFSM; | ||
224 | if (pll_hfsm == 0) { | ||
225 | reg = mfi << 4 | pdf; | ||
226 | __raw_writel(reg, pllbase + MXC_PLL_DP_OP); | ||
227 | __raw_writel(mfd, pllbase + MXC_PLL_DP_MFD); | ||
228 | __raw_writel(mfn, pllbase + MXC_PLL_DP_MFN); | ||
229 | } else { | ||
230 | reg = mfi << 4 | pdf; | ||
231 | __raw_writel(reg, pllbase + MXC_PLL_DP_HFS_OP); | ||
232 | __raw_writel(mfd, pllbase + MXC_PLL_DP_HFS_MFD); | ||
233 | __raw_writel(mfn, pllbase + MXC_PLL_DP_HFS_MFN); | ||
234 | } | ||
235 | |||
236 | return 0; | ||
237 | } | ||
238 | |||
239 | static int _clk_pll_enable(struct clk *clk) | ||
240 | { | ||
241 | u32 reg; | ||
242 | void __iomem *pllbase; | ||
243 | int i = 0; | ||
244 | |||
245 | pllbase = _get_pll_base(clk); | ||
246 | reg = __raw_readl(pllbase + MXC_PLL_DP_CTL) | MXC_PLL_DP_CTL_UPEN; | ||
247 | __raw_writel(reg, pllbase + MXC_PLL_DP_CTL); | ||
248 | |||
249 | /* Wait for lock */ | ||
250 | do { | ||
251 | reg = __raw_readl(pllbase + MXC_PLL_DP_CTL); | ||
252 | if (reg & MXC_PLL_DP_CTL_LRF) | ||
253 | break; | ||
254 | |||
255 | udelay(1); | ||
256 | } while (++i < MAX_DPLL_WAIT_TRIES); | ||
257 | |||
258 | if (i == MAX_DPLL_WAIT_TRIES) { | ||
259 | pr_err("MX5: pll locking failed\n"); | ||
260 | return -EINVAL; | ||
261 | } | ||
262 | |||
263 | return 0; | ||
264 | } | ||
265 | |||
266 | static void _clk_pll_disable(struct clk *clk) | ||
267 | { | ||
268 | u32 reg; | ||
269 | void __iomem *pllbase; | ||
270 | |||
271 | pllbase = _get_pll_base(clk); | ||
272 | reg = __raw_readl(pllbase + MXC_PLL_DP_CTL) & ~MXC_PLL_DP_CTL_UPEN; | ||
273 | __raw_writel(reg, pllbase + MXC_PLL_DP_CTL); | ||
274 | } | ||
275 | |||
276 | static int _clk_pll1_sw_set_parent(struct clk *clk, struct clk *parent) | ||
277 | { | ||
278 | u32 reg, step; | ||
279 | |||
280 | reg = __raw_readl(MXC_CCM_CCSR); | ||
281 | |||
282 | /* When switching from pll_main_clk to a bypass clock, first select a | ||
283 | * multiplexed clock in 'step_sel', then shift the glitchless mux | ||
284 | * 'pll1_sw_clk_sel'. | ||
285 | * | ||
286 | * When switching back, do it in reverse order | ||
287 | */ | ||
288 | if (parent == &pll1_main_clk) { | ||
289 | /* Switch to pll1_main_clk */ | ||
290 | reg &= ~MXC_CCM_CCSR_PLL1_SW_CLK_SEL; | ||
291 | __raw_writel(reg, MXC_CCM_CCSR); | ||
292 | /* step_clk mux switched to lp_apm, to save power. */ | ||
293 | reg = __raw_readl(MXC_CCM_CCSR); | ||
294 | reg &= ~MXC_CCM_CCSR_STEP_SEL_MASK; | ||
295 | reg |= (MXC_CCM_CCSR_STEP_SEL_LP_APM << | ||
296 | MXC_CCM_CCSR_STEP_SEL_OFFSET); | ||
297 | } else { | ||
298 | if (parent == &lp_apm_clk) { | ||
299 | step = MXC_CCM_CCSR_STEP_SEL_LP_APM; | ||
300 | } else if (parent == &pll2_sw_clk) { | ||
301 | step = MXC_CCM_CCSR_STEP_SEL_PLL2_DIVIDED; | ||
302 | } else if (parent == &pll3_sw_clk) { | ||
303 | step = MXC_CCM_CCSR_STEP_SEL_PLL3_DIVIDED; | ||
304 | } else | ||
305 | return -EINVAL; | ||
306 | |||
307 | reg &= ~MXC_CCM_CCSR_STEP_SEL_MASK; | ||
308 | reg |= (step << MXC_CCM_CCSR_STEP_SEL_OFFSET); | ||
309 | |||
310 | __raw_writel(reg, MXC_CCM_CCSR); | ||
311 | /* Switch to step_clk */ | ||
312 | reg = __raw_readl(MXC_CCM_CCSR); | ||
313 | reg |= MXC_CCM_CCSR_PLL1_SW_CLK_SEL; | ||
314 | } | ||
315 | __raw_writel(reg, MXC_CCM_CCSR); | ||
316 | return 0; | ||
317 | } | ||
318 | |||
319 | static unsigned long clk_pll1_sw_get_rate(struct clk *clk) | ||
320 | { | ||
321 | u32 reg, div; | ||
322 | unsigned long parent_rate; | ||
323 | |||
324 | parent_rate = clk_get_rate(clk->parent); | ||
325 | |||
326 | reg = __raw_readl(MXC_CCM_CCSR); | ||
327 | |||
328 | if (clk->parent == &pll2_sw_clk) { | ||
329 | div = ((reg & MXC_CCM_CCSR_PLL2_PODF_MASK) >> | ||
330 | MXC_CCM_CCSR_PLL2_PODF_OFFSET) + 1; | ||
331 | } else if (clk->parent == &pll3_sw_clk) { | ||
332 | div = ((reg & MXC_CCM_CCSR_PLL3_PODF_MASK) >> | ||
333 | MXC_CCM_CCSR_PLL3_PODF_OFFSET) + 1; | ||
334 | } else | ||
335 | div = 1; | ||
336 | return parent_rate / div; | ||
337 | } | ||
338 | |||
339 | static int _clk_pll2_sw_set_parent(struct clk *clk, struct clk *parent) | ||
340 | { | ||
341 | u32 reg; | ||
342 | |||
343 | reg = __raw_readl(MXC_CCM_CCSR); | ||
344 | |||
345 | if (parent == &pll2_sw_clk) | ||
346 | reg &= ~MXC_CCM_CCSR_PLL2_SW_CLK_SEL; | ||
347 | else | ||
348 | reg |= MXC_CCM_CCSR_PLL2_SW_CLK_SEL; | ||
349 | |||
350 | __raw_writel(reg, MXC_CCM_CCSR); | ||
351 | return 0; | ||
352 | } | ||
353 | |||
354 | static int _clk_lp_apm_set_parent(struct clk *clk, struct clk *parent) | ||
355 | { | ||
356 | u32 reg; | ||
357 | |||
358 | if (parent == &osc_clk) | ||
359 | reg = __raw_readl(MXC_CCM_CCSR) & ~MXC_CCM_CCSR_LP_APM_SEL; | ||
360 | else | ||
361 | return -EINVAL; | ||
362 | |||
363 | __raw_writel(reg, MXC_CCM_CCSR); | ||
364 | |||
365 | return 0; | ||
366 | } | ||
367 | |||
368 | static unsigned long clk_cpu_get_rate(struct clk *clk) | ||
369 | { | ||
370 | u32 cacrr, div; | ||
371 | unsigned long parent_rate; | ||
372 | |||
373 | parent_rate = clk_get_rate(clk->parent); | ||
374 | cacrr = __raw_readl(MXC_CCM_CACRR); | ||
375 | div = (cacrr & MXC_CCM_CACRR_ARM_PODF_MASK) + 1; | ||
376 | |||
377 | return parent_rate / div; | ||
378 | } | ||
379 | |||
380 | static int clk_cpu_set_rate(struct clk *clk, unsigned long rate) | ||
381 | { | ||
382 | u32 reg, cpu_podf; | ||
383 | unsigned long parent_rate; | ||
384 | |||
385 | parent_rate = clk_get_rate(clk->parent); | ||
386 | cpu_podf = parent_rate / rate - 1; | ||
387 | /* use post divider to change freq */ | ||
388 | reg = __raw_readl(MXC_CCM_CACRR); | ||
389 | reg &= ~MXC_CCM_CACRR_ARM_PODF_MASK; | ||
390 | reg |= cpu_podf << MXC_CCM_CACRR_ARM_PODF_OFFSET; | ||
391 | __raw_writel(reg, MXC_CCM_CACRR); | ||
392 | |||
393 | return 0; | ||
394 | } | ||
395 | |||
396 | static int _clk_periph_apm_set_parent(struct clk *clk, struct clk *parent) | ||
397 | { | ||
398 | u32 reg, mux; | ||
399 | int i = 0; | ||
400 | |||
401 | mux = _get_mux(parent, &pll1_sw_clk, &pll3_sw_clk, &lp_apm_clk, NULL); | ||
402 | |||
403 | reg = __raw_readl(MXC_CCM_CBCMR) & ~MXC_CCM_CBCMR_PERIPH_CLK_SEL_MASK; | ||
404 | reg |= mux << MXC_CCM_CBCMR_PERIPH_CLK_SEL_OFFSET; | ||
405 | __raw_writel(reg, MXC_CCM_CBCMR); | ||
406 | |||
407 | /* Wait for lock */ | ||
408 | do { | ||
409 | reg = __raw_readl(MXC_CCM_CDHIPR); | ||
410 | if (!(reg & MXC_CCM_CDHIPR_PERIPH_CLK_SEL_BUSY)) | ||
411 | break; | ||
412 | |||
413 | udelay(1); | ||
414 | } while (++i < MAX_DPLL_WAIT_TRIES); | ||
415 | |||
416 | if (i == MAX_DPLL_WAIT_TRIES) { | ||
417 | pr_err("MX5: Set parent for periph_apm clock failed\n"); | ||
418 | return -EINVAL; | ||
419 | } | ||
420 | |||
421 | return 0; | ||
422 | } | ||
423 | |||
424 | static int _clk_main_bus_set_parent(struct clk *clk, struct clk *parent) | ||
425 | { | ||
426 | u32 reg; | ||
427 | |||
428 | reg = __raw_readl(MXC_CCM_CBCDR); | ||
429 | |||
430 | if (parent == &pll2_sw_clk) | ||
431 | reg &= ~MXC_CCM_CBCDR_PERIPH_CLK_SEL; | ||
432 | else if (parent == &periph_apm_clk) | ||
433 | reg |= MXC_CCM_CBCDR_PERIPH_CLK_SEL; | ||
434 | else | ||
435 | return -EINVAL; | ||
436 | |||
437 | __raw_writel(reg, MXC_CCM_CBCDR); | ||
438 | |||
439 | return 0; | ||
440 | } | ||
441 | |||
442 | static struct clk main_bus_clk = { | ||
443 | .parent = &pll2_sw_clk, | ||
444 | .set_parent = _clk_main_bus_set_parent, | ||
445 | }; | ||
446 | |||
447 | static unsigned long clk_ahb_get_rate(struct clk *clk) | ||
448 | { | ||
449 | u32 reg, div; | ||
450 | unsigned long parent_rate; | ||
451 | |||
452 | parent_rate = clk_get_rate(clk->parent); | ||
453 | |||
454 | reg = __raw_readl(MXC_CCM_CBCDR); | ||
455 | div = ((reg & MXC_CCM_CBCDR_AHB_PODF_MASK) >> | ||
456 | MXC_CCM_CBCDR_AHB_PODF_OFFSET) + 1; | ||
457 | return parent_rate / div; | ||
458 | } | ||
459 | |||
460 | |||
461 | static int _clk_ahb_set_rate(struct clk *clk, unsigned long rate) | ||
462 | { | ||
463 | u32 reg, div; | ||
464 | unsigned long parent_rate; | ||
465 | int i = 0; | ||
466 | |||
467 | parent_rate = clk_get_rate(clk->parent); | ||
468 | |||
469 | div = parent_rate / rate; | ||
470 | if (div > 8 || div < 1 || ((parent_rate / div) != rate)) | ||
471 | return -EINVAL; | ||
472 | |||
473 | reg = __raw_readl(MXC_CCM_CBCDR); | ||
474 | reg &= ~MXC_CCM_CBCDR_AHB_PODF_MASK; | ||
475 | reg |= (div - 1) << MXC_CCM_CBCDR_AHB_PODF_OFFSET; | ||
476 | __raw_writel(reg, MXC_CCM_CBCDR); | ||
477 | |||
478 | /* Wait for lock */ | ||
479 | do { | ||
480 | reg = __raw_readl(MXC_CCM_CDHIPR); | ||
481 | if (!(reg & MXC_CCM_CDHIPR_AHB_PODF_BUSY)) | ||
482 | break; | ||
483 | |||
484 | udelay(1); | ||
485 | } while (++i < MAX_DPLL_WAIT_TRIES); | ||
486 | |||
487 | if (i == MAX_DPLL_WAIT_TRIES) { | ||
488 | pr_err("MX5: clk_ahb_set_rate failed\n"); | ||
489 | return -EINVAL; | ||
490 | } | ||
491 | |||
492 | return 0; | ||
493 | } | ||
494 | |||
495 | static unsigned long _clk_ahb_round_rate(struct clk *clk, | ||
496 | unsigned long rate) | ||
497 | { | ||
498 | u32 div; | ||
499 | unsigned long parent_rate; | ||
500 | |||
501 | parent_rate = clk_get_rate(clk->parent); | ||
502 | |||
503 | div = parent_rate / rate; | ||
504 | if (div > 8) | ||
505 | div = 8; | ||
506 | else if (div == 0) | ||
507 | div++; | ||
508 | return parent_rate / div; | ||
509 | } | ||
510 | |||
511 | |||
512 | static int _clk_max_enable(struct clk *clk) | ||
513 | { | ||
514 | u32 reg; | ||
515 | |||
516 | _clk_ccgr_enable(clk); | ||
517 | |||
518 | /* Handshake with MAX when LPM is entered. */ | ||
519 | reg = __raw_readl(MXC_CCM_CLPCR); | ||
520 | if (cpu_is_mx51()) | ||
521 | reg &= ~MX51_CCM_CLPCR_BYPASS_MAX_LPM_HS; | ||
522 | else if (cpu_is_mx53()) | ||
523 | reg &= ~MX53_CCM_CLPCR_BYPASS_MAX_LPM_HS; | ||
524 | __raw_writel(reg, MXC_CCM_CLPCR); | ||
525 | |||
526 | return 0; | ||
527 | } | ||
528 | |||
529 | static void _clk_max_disable(struct clk *clk) | ||
530 | { | ||
531 | u32 reg; | ||
532 | |||
533 | _clk_ccgr_disable_inwait(clk); | ||
534 | |||
535 | /* No Handshake with MAX when LPM is entered as its disabled. */ | ||
536 | reg = __raw_readl(MXC_CCM_CLPCR); | ||
537 | if (cpu_is_mx51()) | ||
538 | reg |= MX51_CCM_CLPCR_BYPASS_MAX_LPM_HS; | ||
539 | else if (cpu_is_mx53()) | ||
540 | reg &= ~MX53_CCM_CLPCR_BYPASS_MAX_LPM_HS; | ||
541 | __raw_writel(reg, MXC_CCM_CLPCR); | ||
542 | } | ||
543 | |||
544 | static unsigned long clk_ipg_get_rate(struct clk *clk) | ||
545 | { | ||
546 | u32 reg, div; | ||
547 | unsigned long parent_rate; | ||
548 | |||
549 | parent_rate = clk_get_rate(clk->parent); | ||
550 | |||
551 | reg = __raw_readl(MXC_CCM_CBCDR); | ||
552 | div = ((reg & MXC_CCM_CBCDR_IPG_PODF_MASK) >> | ||
553 | MXC_CCM_CBCDR_IPG_PODF_OFFSET) + 1; | ||
554 | |||
555 | return parent_rate / div; | ||
556 | } | ||
557 | |||
558 | static unsigned long clk_ipg_per_get_rate(struct clk *clk) | ||
559 | { | ||
560 | u32 reg, prediv1, prediv2, podf; | ||
561 | unsigned long parent_rate; | ||
562 | |||
563 | parent_rate = clk_get_rate(clk->parent); | ||
564 | |||
565 | if (clk->parent == &main_bus_clk || clk->parent == &lp_apm_clk) { | ||
566 | /* the main_bus_clk is the one before the DVFS engine */ | ||
567 | reg = __raw_readl(MXC_CCM_CBCDR); | ||
568 | prediv1 = ((reg & MXC_CCM_CBCDR_PERCLK_PRED1_MASK) >> | ||
569 | MXC_CCM_CBCDR_PERCLK_PRED1_OFFSET) + 1; | ||
570 | prediv2 = ((reg & MXC_CCM_CBCDR_PERCLK_PRED2_MASK) >> | ||
571 | MXC_CCM_CBCDR_PERCLK_PRED2_OFFSET) + 1; | ||
572 | podf = ((reg & MXC_CCM_CBCDR_PERCLK_PODF_MASK) >> | ||
573 | MXC_CCM_CBCDR_PERCLK_PODF_OFFSET) + 1; | ||
574 | return parent_rate / (prediv1 * prediv2 * podf); | ||
575 | } else if (clk->parent == &ipg_clk) | ||
576 | return parent_rate; | ||
577 | else | ||
578 | BUG(); | ||
579 | } | ||
580 | |||
581 | static int _clk_ipg_per_set_parent(struct clk *clk, struct clk *parent) | ||
582 | { | ||
583 | u32 reg; | ||
584 | |||
585 | reg = __raw_readl(MXC_CCM_CBCMR); | ||
586 | |||
587 | reg &= ~MXC_CCM_CBCMR_PERCLK_LP_APM_CLK_SEL; | ||
588 | reg &= ~MXC_CCM_CBCMR_PERCLK_IPG_CLK_SEL; | ||
589 | |||
590 | if (parent == &ipg_clk) | ||
591 | reg |= MXC_CCM_CBCMR_PERCLK_IPG_CLK_SEL; | ||
592 | else if (parent == &lp_apm_clk) | ||
593 | reg |= MXC_CCM_CBCMR_PERCLK_LP_APM_CLK_SEL; | ||
594 | else if (parent != &main_bus_clk) | ||
595 | return -EINVAL; | ||
596 | |||
597 | __raw_writel(reg, MXC_CCM_CBCMR); | ||
598 | |||
599 | return 0; | ||
600 | } | ||
601 | |||
602 | #define clk_nfc_set_parent NULL | ||
603 | |||
604 | static unsigned long clk_nfc_get_rate(struct clk *clk) | ||
605 | { | ||
606 | unsigned long rate; | ||
607 | u32 reg, div; | ||
608 | |||
609 | reg = __raw_readl(MXC_CCM_CBCDR); | ||
610 | div = ((reg & MXC_CCM_CBCDR_NFC_PODF_MASK) >> | ||
611 | MXC_CCM_CBCDR_NFC_PODF_OFFSET) + 1; | ||
612 | rate = clk_get_rate(clk->parent) / div; | ||
613 | WARN_ON(rate == 0); | ||
614 | return rate; | ||
615 | } | ||
616 | |||
617 | static unsigned long clk_nfc_round_rate(struct clk *clk, | ||
618 | unsigned long rate) | ||
619 | { | ||
620 | u32 div; | ||
621 | unsigned long parent_rate = clk_get_rate(clk->parent); | ||
622 | |||
623 | if (!rate) | ||
624 | return -EINVAL; | ||
625 | |||
626 | div = parent_rate / rate; | ||
627 | |||
628 | if (parent_rate % rate) | ||
629 | div++; | ||
630 | |||
631 | if (div > 8) | ||
632 | return -EINVAL; | ||
633 | |||
634 | return parent_rate / div; | ||
635 | |||
636 | } | ||
637 | |||
638 | static int clk_nfc_set_rate(struct clk *clk, unsigned long rate) | ||
639 | { | ||
640 | u32 reg, div; | ||
641 | |||
642 | div = clk_get_rate(clk->parent) / rate; | ||
643 | if (div == 0) | ||
644 | div++; | ||
645 | if (((clk_get_rate(clk->parent) / div) != rate) || (div > 8)) | ||
646 | return -EINVAL; | ||
647 | |||
648 | reg = __raw_readl(MXC_CCM_CBCDR); | ||
649 | reg &= ~MXC_CCM_CBCDR_NFC_PODF_MASK; | ||
650 | reg |= (div - 1) << MXC_CCM_CBCDR_NFC_PODF_OFFSET; | ||
651 | __raw_writel(reg, MXC_CCM_CBCDR); | ||
652 | |||
653 | while (__raw_readl(MXC_CCM_CDHIPR) & | ||
654 | MXC_CCM_CDHIPR_NFC_IPG_INT_MEM_PODF_BUSY){ | ||
655 | } | ||
656 | |||
657 | return 0; | ||
658 | } | ||
659 | |||
660 | static unsigned long get_high_reference_clock_rate(struct clk *clk) | ||
661 | { | ||
662 | return external_high_reference; | ||
663 | } | ||
664 | |||
665 | static unsigned long get_low_reference_clock_rate(struct clk *clk) | ||
666 | { | ||
667 | return external_low_reference; | ||
668 | } | ||
669 | |||
670 | static unsigned long get_oscillator_reference_clock_rate(struct clk *clk) | ||
671 | { | ||
672 | return oscillator_reference; | ||
673 | } | ||
674 | |||
675 | static unsigned long get_ckih2_reference_clock_rate(struct clk *clk) | ||
676 | { | ||
677 | return ckih2_reference; | ||
678 | } | ||
679 | |||
680 | static unsigned long clk_emi_slow_get_rate(struct clk *clk) | ||
681 | { | ||
682 | u32 reg, div; | ||
683 | |||
684 | reg = __raw_readl(MXC_CCM_CBCDR); | ||
685 | div = ((reg & MXC_CCM_CBCDR_EMI_PODF_MASK) >> | ||
686 | MXC_CCM_CBCDR_EMI_PODF_OFFSET) + 1; | ||
687 | |||
688 | return clk_get_rate(clk->parent) / div; | ||
689 | } | ||
690 | |||
691 | /* External high frequency clock */ | ||
692 | static struct clk ckih_clk = { | ||
693 | .get_rate = get_high_reference_clock_rate, | ||
694 | }; | ||
695 | |||
696 | static struct clk ckih2_clk = { | ||
697 | .get_rate = get_ckih2_reference_clock_rate, | ||
698 | }; | ||
699 | |||
700 | static struct clk osc_clk = { | ||
701 | .get_rate = get_oscillator_reference_clock_rate, | ||
702 | }; | ||
703 | |||
704 | /* External low frequency (32kHz) clock */ | ||
705 | static struct clk ckil_clk = { | ||
706 | .get_rate = get_low_reference_clock_rate, | ||
707 | }; | ||
708 | |||
709 | static struct clk pll1_main_clk = { | ||
710 | .parent = &osc_clk, | ||
711 | .get_rate = clk_pll_get_rate, | ||
712 | .enable = _clk_pll_enable, | ||
713 | .disable = _clk_pll_disable, | ||
714 | }; | ||
715 | |||
716 | /* Clock tree block diagram (WIP): | ||
717 | * CCM: Clock Controller Module | ||
718 | * | ||
719 | * PLL output -> | | ||
720 | * | CCM Switcher -> CCM_CLK_ROOT_GEN -> | ||
721 | * PLL bypass -> | | ||
722 | * | ||
723 | */ | ||
724 | |||
725 | /* PLL1 SW supplies to ARM core */ | ||
726 | static struct clk pll1_sw_clk = { | ||
727 | .parent = &pll1_main_clk, | ||
728 | .set_parent = _clk_pll1_sw_set_parent, | ||
729 | .get_rate = clk_pll1_sw_get_rate, | ||
730 | }; | ||
731 | |||
732 | /* PLL2 SW supplies to AXI/AHB/IP buses */ | ||
733 | static struct clk pll2_sw_clk = { | ||
734 | .parent = &osc_clk, | ||
735 | .get_rate = clk_pll_get_rate, | ||
736 | .set_rate = _clk_pll_set_rate, | ||
737 | .set_parent = _clk_pll2_sw_set_parent, | ||
738 | .enable = _clk_pll_enable, | ||
739 | .disable = _clk_pll_disable, | ||
740 | }; | ||
741 | |||
742 | /* PLL3 SW supplies to serial clocks like USB, SSI, etc. */ | ||
743 | static struct clk pll3_sw_clk = { | ||
744 | .parent = &osc_clk, | ||
745 | .set_rate = _clk_pll_set_rate, | ||
746 | .get_rate = clk_pll_get_rate, | ||
747 | .enable = _clk_pll_enable, | ||
748 | .disable = _clk_pll_disable, | ||
749 | }; | ||
750 | |||
751 | /* PLL4 SW supplies to LVDS Display Bridge(LDB) */ | ||
752 | static struct clk mx53_pll4_sw_clk = { | ||
753 | .parent = &osc_clk, | ||
754 | .set_rate = _clk_pll_set_rate, | ||
755 | .enable = _clk_pll_enable, | ||
756 | .disable = _clk_pll_disable, | ||
757 | }; | ||
758 | |||
759 | /* Low-power Audio Playback Mode clock */ | ||
760 | static struct clk lp_apm_clk = { | ||
761 | .parent = &osc_clk, | ||
762 | .set_parent = _clk_lp_apm_set_parent, | ||
763 | }; | ||
764 | |||
765 | static struct clk periph_apm_clk = { | ||
766 | .parent = &pll1_sw_clk, | ||
767 | .set_parent = _clk_periph_apm_set_parent, | ||
768 | }; | ||
769 | |||
770 | static struct clk cpu_clk = { | ||
771 | .parent = &pll1_sw_clk, | ||
772 | .get_rate = clk_cpu_get_rate, | ||
773 | .set_rate = clk_cpu_set_rate, | ||
774 | }; | ||
775 | |||
776 | static struct clk ahb_clk = { | ||
777 | .parent = &main_bus_clk, | ||
778 | .get_rate = clk_ahb_get_rate, | ||
779 | .set_rate = _clk_ahb_set_rate, | ||
780 | .round_rate = _clk_ahb_round_rate, | ||
781 | }; | ||
782 | |||
783 | /* Main IP interface clock for access to registers */ | ||
784 | static struct clk ipg_clk = { | ||
785 | .parent = &ahb_clk, | ||
786 | .get_rate = clk_ipg_get_rate, | ||
787 | }; | ||
788 | |||
789 | static struct clk ipg_perclk = { | ||
790 | .parent = &lp_apm_clk, | ||
791 | .get_rate = clk_ipg_per_get_rate, | ||
792 | .set_parent = _clk_ipg_per_set_parent, | ||
793 | }; | ||
794 | |||
795 | static struct clk ahb_max_clk = { | ||
796 | .parent = &ahb_clk, | ||
797 | .enable_reg = MXC_CCM_CCGR0, | ||
798 | .enable_shift = MXC_CCM_CCGRx_CG14_OFFSET, | ||
799 | .enable = _clk_max_enable, | ||
800 | .disable = _clk_max_disable, | ||
801 | }; | ||
802 | |||
803 | static struct clk aips_tz1_clk = { | ||
804 | .parent = &ahb_clk, | ||
805 | .secondary = &ahb_max_clk, | ||
806 | .enable_reg = MXC_CCM_CCGR0, | ||
807 | .enable_shift = MXC_CCM_CCGRx_CG12_OFFSET, | ||
808 | .enable = _clk_ccgr_enable, | ||
809 | .disable = _clk_ccgr_disable_inwait, | ||
810 | }; | ||
811 | |||
812 | static struct clk aips_tz2_clk = { | ||
813 | .parent = &ahb_clk, | ||
814 | .secondary = &ahb_max_clk, | ||
815 | .enable_reg = MXC_CCM_CCGR0, | ||
816 | .enable_shift = MXC_CCM_CCGRx_CG13_OFFSET, | ||
817 | .enable = _clk_ccgr_enable, | ||
818 | .disable = _clk_ccgr_disable_inwait, | ||
819 | }; | ||
820 | |||
821 | static struct clk gpt_32k_clk = { | ||
822 | .id = 0, | ||
823 | .parent = &ckil_clk, | ||
824 | }; | ||
825 | |||
826 | static struct clk kpp_clk = { | ||
827 | .id = 0, | ||
828 | }; | ||
829 | |||
830 | static struct clk emi_slow_clk = { | ||
831 | .parent = &pll2_sw_clk, | ||
832 | .enable_reg = MXC_CCM_CCGR5, | ||
833 | .enable_shift = MXC_CCM_CCGRx_CG8_OFFSET, | ||
834 | .enable = _clk_ccgr_enable, | ||
835 | .disable = _clk_ccgr_disable_inwait, | ||
836 | .get_rate = clk_emi_slow_get_rate, | ||
837 | }; | ||
838 | |||
839 | #define DEFINE_CLOCK_CCGR(name, i, er, es, pfx, p, s) \ | ||
840 | static struct clk name = { \ | ||
841 | .id = i, \ | ||
842 | .enable_reg = er, \ | ||
843 | .enable_shift = es, \ | ||
844 | .get_rate = pfx##_get_rate, \ | ||
845 | .set_rate = pfx##_set_rate, \ | ||
846 | .round_rate = pfx##_round_rate, \ | ||
847 | .set_parent = pfx##_set_parent, \ | ||
848 | .enable = _clk_ccgr_enable, \ | ||
849 | .disable = _clk_ccgr_disable, \ | ||
850 | .parent = p, \ | ||
851 | .secondary = s, \ | ||
852 | } | ||
853 | |||
854 | #define DEFINE_CLOCK_MAX(name, i, er, es, pfx, p, s) \ | ||
855 | static struct clk name = { \ | ||
856 | .id = i, \ | ||
857 | .enable_reg = er, \ | ||
858 | .enable_shift = es, \ | ||
859 | .get_rate = pfx##_get_rate, \ | ||
860 | .set_rate = pfx##_set_rate, \ | ||
861 | .set_parent = pfx##_set_parent, \ | ||
862 | .enable = _clk_max_enable, \ | ||
863 | .disable = _clk_max_disable, \ | ||
864 | .parent = p, \ | ||
865 | .secondary = s, \ | ||
866 | } | ||
867 | |||
868 | #define CLK_GET_RATE(name, nr, bitsname) \ | ||
869 | static unsigned long clk_##name##_get_rate(struct clk *clk) \ | ||
870 | { \ | ||
871 | u32 reg, pred, podf; \ | ||
872 | \ | ||
873 | reg = __raw_readl(MXC_CCM_CSCDR##nr); \ | ||
874 | pred = (reg & MXC_CCM_CSCDR##nr##_##bitsname##_CLK_PRED_MASK) \ | ||
875 | >> MXC_CCM_CSCDR##nr##_##bitsname##_CLK_PRED_OFFSET; \ | ||
876 | podf = (reg & MXC_CCM_CSCDR##nr##_##bitsname##_CLK_PODF_MASK) \ | ||
877 | >> MXC_CCM_CSCDR##nr##_##bitsname##_CLK_PODF_OFFSET; \ | ||
878 | \ | ||
879 | return DIV_ROUND_CLOSEST(clk_get_rate(clk->parent), \ | ||
880 | (pred + 1) * (podf + 1)); \ | ||
881 | } | ||
882 | |||
883 | #define CLK_SET_PARENT(name, nr, bitsname) \ | ||
884 | static int clk_##name##_set_parent(struct clk *clk, struct clk *parent) \ | ||
885 | { \ | ||
886 | u32 reg, mux; \ | ||
887 | \ | ||
888 | mux = _get_mux(parent, &pll1_sw_clk, &pll2_sw_clk, \ | ||
889 | &pll3_sw_clk, &lp_apm_clk); \ | ||
890 | reg = __raw_readl(MXC_CCM_CSCMR##nr) & \ | ||
891 | ~MXC_CCM_CSCMR##nr##_##bitsname##_CLK_SEL_MASK; \ | ||
892 | reg |= mux << MXC_CCM_CSCMR##nr##_##bitsname##_CLK_SEL_OFFSET; \ | ||
893 | __raw_writel(reg, MXC_CCM_CSCMR##nr); \ | ||
894 | \ | ||
895 | return 0; \ | ||
896 | } | ||
897 | |||
898 | #define CLK_SET_RATE(name, nr, bitsname) \ | ||
899 | static int clk_##name##_set_rate(struct clk *clk, unsigned long rate) \ | ||
900 | { \ | ||
901 | u32 reg, div, parent_rate; \ | ||
902 | u32 pre = 0, post = 0; \ | ||
903 | \ | ||
904 | parent_rate = clk_get_rate(clk->parent); \ | ||
905 | div = parent_rate / rate; \ | ||
906 | \ | ||
907 | if ((parent_rate / div) != rate) \ | ||
908 | return -EINVAL; \ | ||
909 | \ | ||
910 | __calc_pre_post_dividers(div, &pre, &post, \ | ||
911 | (MXC_CCM_CSCDR##nr##_##bitsname##_CLK_PRED_MASK >> \ | ||
912 | MXC_CCM_CSCDR##nr##_##bitsname##_CLK_PRED_OFFSET) + 1, \ | ||
913 | (MXC_CCM_CSCDR##nr##_##bitsname##_CLK_PODF_MASK >> \ | ||
914 | MXC_CCM_CSCDR##nr##_##bitsname##_CLK_PODF_OFFSET) + 1);\ | ||
915 | \ | ||
916 | /* Set sdhc1 clock divider */ \ | ||
917 | reg = __raw_readl(MXC_CCM_CSCDR##nr) & \ | ||
918 | ~(MXC_CCM_CSCDR##nr##_##bitsname##_CLK_PRED_MASK \ | ||
919 | | MXC_CCM_CSCDR##nr##_##bitsname##_CLK_PODF_MASK); \ | ||
920 | reg |= (post - 1) << \ | ||
921 | MXC_CCM_CSCDR##nr##_##bitsname##_CLK_PODF_OFFSET; \ | ||
922 | reg |= (pre - 1) << \ | ||
923 | MXC_CCM_CSCDR##nr##_##bitsname##_CLK_PRED_OFFSET; \ | ||
924 | __raw_writel(reg, MXC_CCM_CSCDR##nr); \ | ||
925 | \ | ||
926 | return 0; \ | ||
927 | } | ||
928 | |||
929 | /* UART */ | ||
930 | CLK_GET_RATE(uart, 1, UART) | ||
931 | CLK_SET_PARENT(uart, 1, UART) | ||
932 | |||
933 | static struct clk uart_root_clk = { | ||
934 | .parent = &pll2_sw_clk, | ||
935 | .get_rate = clk_uart_get_rate, | ||
936 | .set_parent = clk_uart_set_parent, | ||
937 | }; | ||
938 | |||
939 | /* USBOH3 */ | ||
940 | CLK_GET_RATE(usboh3, 1, USBOH3) | ||
941 | CLK_SET_PARENT(usboh3, 1, USBOH3) | ||
942 | |||
943 | static struct clk usboh3_clk = { | ||
944 | .parent = &pll2_sw_clk, | ||
945 | .get_rate = clk_usboh3_get_rate, | ||
946 | .set_parent = clk_usboh3_set_parent, | ||
947 | }; | ||
948 | |||
949 | /* eCSPI */ | ||
950 | CLK_GET_RATE(ecspi, 2, CSPI) | ||
951 | CLK_SET_PARENT(ecspi, 1, CSPI) | ||
952 | |||
953 | static struct clk ecspi_main_clk = { | ||
954 | .parent = &pll3_sw_clk, | ||
955 | .get_rate = clk_ecspi_get_rate, | ||
956 | .set_parent = clk_ecspi_set_parent, | ||
957 | }; | ||
958 | |||
959 | /* eSDHC */ | ||
960 | CLK_GET_RATE(esdhc1, 1, ESDHC1_MSHC1) | ||
961 | CLK_SET_PARENT(esdhc1, 1, ESDHC1_MSHC1) | ||
962 | CLK_SET_RATE(esdhc1, 1, ESDHC1_MSHC1) | ||
963 | |||
964 | CLK_GET_RATE(esdhc2, 1, ESDHC2_MSHC2) | ||
965 | CLK_SET_PARENT(esdhc2, 1, ESDHC2_MSHC2) | ||
966 | CLK_SET_RATE(esdhc2, 1, ESDHC2_MSHC2) | ||
967 | |||
968 | #define DEFINE_CLOCK_FULL(name, i, er, es, gr, sr, e, d, p, s) \ | ||
969 | static struct clk name = { \ | ||
970 | .id = i, \ | ||
971 | .enable_reg = er, \ | ||
972 | .enable_shift = es, \ | ||
973 | .get_rate = gr, \ | ||
974 | .set_rate = sr, \ | ||
975 | .enable = e, \ | ||
976 | .disable = d, \ | ||
977 | .parent = p, \ | ||
978 | .secondary = s, \ | ||
979 | } | ||
980 | |||
981 | #define DEFINE_CLOCK(name, i, er, es, gr, sr, p, s) \ | ||
982 | DEFINE_CLOCK_FULL(name, i, er, es, gr, sr, _clk_ccgr_enable, _clk_ccgr_disable, p, s) | ||
983 | |||
984 | /* Shared peripheral bus arbiter */ | ||
985 | DEFINE_CLOCK(spba_clk, 0, MXC_CCM_CCGR5, MXC_CCM_CCGRx_CG0_OFFSET, | ||
986 | NULL, NULL, &ipg_clk, NULL); | ||
987 | |||
988 | /* UART */ | ||
989 | DEFINE_CLOCK(uart1_ipg_clk, 0, MXC_CCM_CCGR1, MXC_CCM_CCGRx_CG3_OFFSET, | ||
990 | NULL, NULL, &ipg_clk, &aips_tz1_clk); | ||
991 | DEFINE_CLOCK(uart2_ipg_clk, 1, MXC_CCM_CCGR1, MXC_CCM_CCGRx_CG5_OFFSET, | ||
992 | NULL, NULL, &ipg_clk, &aips_tz1_clk); | ||
993 | DEFINE_CLOCK(uart3_ipg_clk, 2, MXC_CCM_CCGR1, MXC_CCM_CCGRx_CG7_OFFSET, | ||
994 | NULL, NULL, &ipg_clk, &spba_clk); | ||
995 | DEFINE_CLOCK(uart1_clk, 0, MXC_CCM_CCGR1, MXC_CCM_CCGRx_CG4_OFFSET, | ||
996 | NULL, NULL, &uart_root_clk, &uart1_ipg_clk); | ||
997 | DEFINE_CLOCK(uart2_clk, 1, MXC_CCM_CCGR1, MXC_CCM_CCGRx_CG6_OFFSET, | ||
998 | NULL, NULL, &uart_root_clk, &uart2_ipg_clk); | ||
999 | DEFINE_CLOCK(uart3_clk, 2, MXC_CCM_CCGR1, MXC_CCM_CCGRx_CG8_OFFSET, | ||
1000 | NULL, NULL, &uart_root_clk, &uart3_ipg_clk); | ||
1001 | |||
1002 | /* GPT */ | ||
1003 | DEFINE_CLOCK(gpt_ipg_clk, 0, MXC_CCM_CCGR2, MXC_CCM_CCGRx_CG10_OFFSET, | ||
1004 | NULL, NULL, &ipg_clk, NULL); | ||
1005 | DEFINE_CLOCK(gpt_clk, 0, MXC_CCM_CCGR2, MXC_CCM_CCGRx_CG9_OFFSET, | ||
1006 | NULL, NULL, &ipg_clk, &gpt_ipg_clk); | ||
1007 | |||
1008 | /* I2C */ | ||
1009 | DEFINE_CLOCK(i2c1_clk, 0, MXC_CCM_CCGR1, MXC_CCM_CCGRx_CG9_OFFSET, | ||
1010 | NULL, NULL, &ipg_clk, NULL); | ||
1011 | DEFINE_CLOCK(i2c2_clk, 1, MXC_CCM_CCGR1, MXC_CCM_CCGRx_CG10_OFFSET, | ||
1012 | NULL, NULL, &ipg_clk, NULL); | ||
1013 | DEFINE_CLOCK(hsi2c_clk, 0, MXC_CCM_CCGR1, MXC_CCM_CCGRx_CG11_OFFSET, | ||
1014 | NULL, NULL, &ipg_clk, NULL); | ||
1015 | |||
1016 | /* FEC */ | ||
1017 | DEFINE_CLOCK(fec_clk, 0, MXC_CCM_CCGR2, MXC_CCM_CCGRx_CG12_OFFSET, | ||
1018 | NULL, NULL, &ipg_clk, NULL); | ||
1019 | |||
1020 | /* NFC */ | ||
1021 | DEFINE_CLOCK_CCGR(nfc_clk, 0, MXC_CCM_CCGR5, MXC_CCM_CCGRx_CG10_OFFSET, | ||
1022 | clk_nfc, &emi_slow_clk, NULL); | ||
1023 | |||
1024 | /* SSI */ | ||
1025 | DEFINE_CLOCK(ssi1_ipg_clk, 0, MXC_CCM_CCGR3, MXC_CCM_CCGRx_CG8_OFFSET, | ||
1026 | NULL, NULL, &ipg_clk, NULL); | ||
1027 | DEFINE_CLOCK(ssi1_clk, 0, MXC_CCM_CCGR3, MXC_CCM_CCGRx_CG9_OFFSET, | ||
1028 | NULL, NULL, &pll3_sw_clk, &ssi1_ipg_clk); | ||
1029 | DEFINE_CLOCK(ssi2_ipg_clk, 1, MXC_CCM_CCGR3, MXC_CCM_CCGRx_CG10_OFFSET, | ||
1030 | NULL, NULL, &ipg_clk, NULL); | ||
1031 | DEFINE_CLOCK(ssi2_clk, 1, MXC_CCM_CCGR3, MXC_CCM_CCGRx_CG11_OFFSET, | ||
1032 | NULL, NULL, &pll3_sw_clk, &ssi2_ipg_clk); | ||
1033 | |||
1034 | /* eCSPI */ | ||
1035 | DEFINE_CLOCK_FULL(ecspi1_ipg_clk, 0, MXC_CCM_CCGR4, MXC_CCM_CCGRx_CG9_OFFSET, | ||
1036 | NULL, NULL, _clk_ccgr_enable_inrun, _clk_ccgr_disable, | ||
1037 | &ipg_clk, &spba_clk); | ||
1038 | DEFINE_CLOCK(ecspi1_clk, 0, MXC_CCM_CCGR4, MXC_CCM_CCGRx_CG10_OFFSET, | ||
1039 | NULL, NULL, &ecspi_main_clk, &ecspi1_ipg_clk); | ||
1040 | DEFINE_CLOCK_FULL(ecspi2_ipg_clk, 0, MXC_CCM_CCGR4, MXC_CCM_CCGRx_CG11_OFFSET, | ||
1041 | NULL, NULL, _clk_ccgr_enable_inrun, _clk_ccgr_disable, | ||
1042 | &ipg_clk, &aips_tz2_clk); | ||
1043 | DEFINE_CLOCK(ecspi2_clk, 0, MXC_CCM_CCGR4, MXC_CCM_CCGRx_CG12_OFFSET, | ||
1044 | NULL, NULL, &ecspi_main_clk, &ecspi2_ipg_clk); | ||
1045 | |||
1046 | /* CSPI */ | ||
1047 | DEFINE_CLOCK(cspi_ipg_clk, 0, MXC_CCM_CCGR4, MXC_CCM_CCGRx_CG9_OFFSET, | ||
1048 | NULL, NULL, &ipg_clk, &aips_tz2_clk); | ||
1049 | DEFINE_CLOCK(cspi_clk, 0, MXC_CCM_CCGR4, MXC_CCM_CCGRx_CG13_OFFSET, | ||
1050 | NULL, NULL, &ipg_clk, &cspi_ipg_clk); | ||
1051 | |||
1052 | /* SDMA */ | ||
1053 | DEFINE_CLOCK(sdma_clk, 1, MXC_CCM_CCGR4, MXC_CCM_CCGRx_CG15_OFFSET, | ||
1054 | NULL, NULL, &ahb_clk, NULL); | ||
1055 | |||
1056 | /* eSDHC */ | ||
1057 | DEFINE_CLOCK_FULL(esdhc1_ipg_clk, 0, MXC_CCM_CCGR3, MXC_CCM_CCGRx_CG0_OFFSET, | ||
1058 | NULL, NULL, _clk_max_enable, _clk_max_disable, &ipg_clk, NULL); | ||
1059 | DEFINE_CLOCK_MAX(esdhc1_clk, 0, MXC_CCM_CCGR3, MXC_CCM_CCGRx_CG1_OFFSET, | ||
1060 | clk_esdhc1, &pll2_sw_clk, &esdhc1_ipg_clk); | ||
1061 | DEFINE_CLOCK_FULL(esdhc2_ipg_clk, 1, MXC_CCM_CCGR3, MXC_CCM_CCGRx_CG2_OFFSET, | ||
1062 | NULL, NULL, _clk_max_enable, _clk_max_disable, &ipg_clk, NULL); | ||
1063 | DEFINE_CLOCK_MAX(esdhc2_clk, 1, MXC_CCM_CCGR3, MXC_CCM_CCGRx_CG3_OFFSET, | ||
1064 | clk_esdhc2, &pll2_sw_clk, &esdhc2_ipg_clk); | ||
1065 | |||
1066 | #define _REGISTER_CLOCK(d, n, c) \ | ||
1067 | { \ | ||
1068 | .dev_id = d, \ | ||
1069 | .con_id = n, \ | ||
1070 | .clk = &c, \ | ||
1071 | }, | ||
1072 | |||
1073 | static struct clk_lookup mx51_lookups[] = { | ||
1074 | _REGISTER_CLOCK("imx-uart.0", NULL, uart1_clk) | ||
1075 | _REGISTER_CLOCK("imx-uart.1", NULL, uart2_clk) | ||
1076 | _REGISTER_CLOCK("imx-uart.2", NULL, uart3_clk) | ||
1077 | _REGISTER_CLOCK(NULL, "gpt", gpt_clk) | ||
1078 | _REGISTER_CLOCK("fec.0", NULL, fec_clk) | ||
1079 | _REGISTER_CLOCK("imx-i2c.0", NULL, i2c1_clk) | ||
1080 | _REGISTER_CLOCK("imx-i2c.1", NULL, i2c2_clk) | ||
1081 | _REGISTER_CLOCK("imx-i2c.2", NULL, hsi2c_clk) | ||
1082 | _REGISTER_CLOCK("mxc-ehci.0", "usb", usboh3_clk) | ||
1083 | _REGISTER_CLOCK("mxc-ehci.0", "usb_ahb", ahb_clk) | ||
1084 | _REGISTER_CLOCK("mxc-ehci.1", "usb", usboh3_clk) | ||
1085 | _REGISTER_CLOCK("mxc-ehci.1", "usb_ahb", ahb_clk) | ||
1086 | _REGISTER_CLOCK("fsl-usb2-udc", "usb", usboh3_clk) | ||
1087 | _REGISTER_CLOCK("fsl-usb2-udc", "usb_ahb", ahb_clk) | ||
1088 | _REGISTER_CLOCK("imx-keypad.0", NULL, kpp_clk) | ||
1089 | _REGISTER_CLOCK("mxc_nand", NULL, nfc_clk) | ||
1090 | _REGISTER_CLOCK("imx-ssi.0", NULL, ssi1_clk) | ||
1091 | _REGISTER_CLOCK("imx-ssi.1", NULL, ssi2_clk) | ||
1092 | _REGISTER_CLOCK("imx-sdma", NULL, sdma_clk) | ||
1093 | _REGISTER_CLOCK(NULL, "ckih", ckih_clk) | ||
1094 | _REGISTER_CLOCK(NULL, "ckih2", ckih2_clk) | ||
1095 | _REGISTER_CLOCK(NULL, "gpt_32k", gpt_32k_clk) | ||
1096 | _REGISTER_CLOCK("imx51-ecspi.0", NULL, ecspi1_clk) | ||
1097 | _REGISTER_CLOCK("imx51-ecspi.1", NULL, ecspi2_clk) | ||
1098 | _REGISTER_CLOCK("imx51-cspi.0", NULL, cspi_clk) | ||
1099 | _REGISTER_CLOCK("sdhci-esdhc-imx.0", NULL, esdhc1_clk) | ||
1100 | _REGISTER_CLOCK("sdhci-esdhc-imx.1", NULL, esdhc2_clk) | ||
1101 | _REGISTER_CLOCK(NULL, "cpu_clk", cpu_clk) | ||
1102 | }; | ||
1103 | |||
1104 | static struct clk_lookup mx53_lookups[] = { | ||
1105 | _REGISTER_CLOCK("imx-uart.0", NULL, uart1_clk) | ||
1106 | _REGISTER_CLOCK("imx-uart.1", NULL, uart2_clk) | ||
1107 | _REGISTER_CLOCK("imx-uart.2", NULL, uart3_clk) | ||
1108 | _REGISTER_CLOCK(NULL, "gpt", gpt_clk) | ||
1109 | _REGISTER_CLOCK("fec.0", NULL, fec_clk) | ||
1110 | }; | ||
1111 | |||
1112 | static void clk_tree_init(void) | ||
1113 | { | ||
1114 | u32 reg; | ||
1115 | |||
1116 | ipg_perclk.set_parent(&ipg_perclk, &lp_apm_clk); | ||
1117 | |||
1118 | /* | ||
1119 | * Initialise the IPG PER CLK dividers to 3. IPG_PER_CLK should be at | ||
1120 | * 8MHz, its derived from lp_apm. | ||
1121 | * | ||
1122 | * FIXME: Verify if true for all boards | ||
1123 | */ | ||
1124 | reg = __raw_readl(MXC_CCM_CBCDR); | ||
1125 | reg &= ~MXC_CCM_CBCDR_PERCLK_PRED1_MASK; | ||
1126 | reg &= ~MXC_CCM_CBCDR_PERCLK_PRED2_MASK; | ||
1127 | reg &= ~MXC_CCM_CBCDR_PERCLK_PODF_MASK; | ||
1128 | reg |= (2 << MXC_CCM_CBCDR_PERCLK_PRED1_OFFSET); | ||
1129 | __raw_writel(reg, MXC_CCM_CBCDR); | ||
1130 | } | ||
1131 | |||
1132 | int __init mx51_clocks_init(unsigned long ckil, unsigned long osc, | ||
1133 | unsigned long ckih1, unsigned long ckih2) | ||
1134 | { | ||
1135 | int i; | ||
1136 | |||
1137 | external_low_reference = ckil; | ||
1138 | external_high_reference = ckih1; | ||
1139 | ckih2_reference = ckih2; | ||
1140 | oscillator_reference = osc; | ||
1141 | |||
1142 | for (i = 0; i < ARRAY_SIZE(mx51_lookups); i++) | ||
1143 | clkdev_add(&mx51_lookups[i]); | ||
1144 | |||
1145 | clk_tree_init(); | ||
1146 | |||
1147 | clk_enable(&cpu_clk); | ||
1148 | clk_enable(&main_bus_clk); | ||
1149 | |||
1150 | /* set the usboh3_clk parent to pll2_sw_clk */ | ||
1151 | clk_set_parent(&usboh3_clk, &pll2_sw_clk); | ||
1152 | |||
1153 | /* Set SDHC parents to be PLL2 */ | ||
1154 | clk_set_parent(&esdhc1_clk, &pll2_sw_clk); | ||
1155 | clk_set_parent(&esdhc2_clk, &pll2_sw_clk); | ||
1156 | |||
1157 | /* set SDHC root clock as 166.25MHZ*/ | ||
1158 | clk_set_rate(&esdhc1_clk, 166250000); | ||
1159 | clk_set_rate(&esdhc2_clk, 166250000); | ||
1160 | |||
1161 | /* System timer */ | ||
1162 | mxc_timer_init(&gpt_clk, MX51_IO_ADDRESS(MX51_GPT1_BASE_ADDR), | ||
1163 | MX51_MXC_INT_GPT); | ||
1164 | return 0; | ||
1165 | } | ||
1166 | |||
1167 | int __init mx53_clocks_init(unsigned long ckil, unsigned long osc, | ||
1168 | unsigned long ckih1, unsigned long ckih2) | ||
1169 | { | ||
1170 | int i; | ||
1171 | |||
1172 | external_low_reference = ckil; | ||
1173 | external_high_reference = ckih1; | ||
1174 | ckih2_reference = ckih2; | ||
1175 | oscillator_reference = osc; | ||
1176 | |||
1177 | for (i = 0; i < ARRAY_SIZE(mx53_lookups); i++) | ||
1178 | clkdev_add(&mx53_lookups[i]); | ||
1179 | |||
1180 | clk_tree_init(); | ||
1181 | |||
1182 | clk_enable(&cpu_clk); | ||
1183 | clk_enable(&main_bus_clk); | ||
1184 | |||
1185 | /* System timer */ | ||
1186 | mxc_timer_init(&gpt_clk, MX53_IO_ADDRESS(MX53_GPT1_BASE_ADDR), | ||
1187 | MX53_INT_GPT); | ||
1188 | return 0; | ||
1189 | } | ||