]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/armv7/mx5/lowlevel_init.S
ARM: mx5: customize PLL setup for TX53
[karo-tx-uboot.git] / arch / arm / cpu / armv7 / mx5 / lowlevel_init.S
1 /*
2  * Copyright (C) 2007, Guennadi Liakhovetski <lg@denx.de>
3  *
4  * (C) Copyright 2009 Freescale Semiconductor, Inc.
5  *
6  * SPDX-License-Identifier:     GPL-2.0+
7  */
8
9 #include <config.h>
10 #include <asm/arch/imx-regs.h>
11 #include <generated/asm-offsets.h>
12 #include <linux/linkage.h>
13
14 .section ".text.init", "x"
15
16 .macro init_arm_erratum
17         /* ARM erratum ID #468414 */
18         mrc 15, 0, r1, c1, c0, 1
19         orr r1, r1, #(1 << 5)    /* enable L1NEON bit */
20         mcr 15, 0, r1, c1, c0, 1
21 .endm
22
23 /*
24  * L2CC Cache setup/invalidation/disable
25  */
26 .macro init_l2cc
27         /* explicitly disable L2 cache */
28         mrc 15, 0, r0, c1, c0, 1
29         bic r0, r0, #0x2
30         mcr 15, 0, r0, c1, c0, 1
31
32         /* reconfigure L2 cache aux control reg */
33         ldr r0, =0xC0 |                 /* tag RAM */ \
34                  0x4 |                  /* data RAM */ \
35                  1 << 24 |              /* disable write allocate delay */ \
36                  1 << 23 |              /* disable write allocate combine */ \
37                  1 << 22                /* disable write allocate */
38
39 #if defined(CONFIG_MX51)
40         ldr r3, [r4, #ROM_SI_REV]
41         cmp r3, #0x10
42
43         /* disable write combine for TO 2 and lower revs */
44         orrls r0, r0, #1 << 25
45 #endif
46
47         mcr 15, 1, r0, c9, c0, 2
48 .endm /* init_l2cc */
49
50 /* AIPS setup - Only setup MPROTx registers.
51  * The PACR default values are good.*/
52 .macro init_aips
53         /*
54          * Set all MPROTx to be non-bufferable, trusted for R/W,
55          * not forced to user-mode.
56          */
57         ldr r0, =AIPS1_BASE_ADDR
58         ldr r1, =0x77777777
59         str r1, [r0, #0x0]
60         str r1, [r0, #0x4]
61         ldr r0, =AIPS2_BASE_ADDR
62         str r1, [r0, #0x0]
63         str r1, [r0, #0x4]
64         /*
65          * Clear the on and off peripheral modules Supervisor Protect bit
66          * for SDMA to access them. Did not change the AIPS control registers
67          * (offset 0x20) access type
68          */
69 .endm /* init_aips */
70
71 /* M4IF setup */
72 .macro init_m4if
73 #ifdef CONFIG_MX51
74         /* VPU and IPU given higher priority (0x4)
75          * IPU accesses with ID=0x1 given highest priority (=0xA)
76          */
77         ldr r0, =M4IF_BASE_ADDR
78
79         ldr r1, =0x00000203
80         str r1, [r0, #0x40]
81
82         str r4, [r0, #0x44]
83
84         ldr r1, =0x00120125
85         str r1, [r0, #0x9C]
86
87         ldr r1, =0x001901A3
88         str r1, [r0, #0x48]
89
90 #endif
91 .endm /* init_m4if */
92
93 .macro setup_pll pll, freq
94         ldr r3, =\pll
95         adr r2, W_DP_\freq
96         bl setup_pll_func
97 .endm
98
99 #define W_DP_OP         0
100 #define W_DP_MFD        4
101 #define W_DP_MFN        8
102
103 setup_pll_func:
104         ldr r1, =0x00001232
105         str r1, [r3, #PLL_DP_CTL] /* Set DPLL ON (set UPEN bit): BRMO=1 */
106         mov r1, #0x2
107         str r1, [r3, #PLL_DP_CONFIG] /* Enable auto-restart AREN bit */
108
109         ldr r1, [r2, #W_DP_OP]
110         str r1, [r3, #PLL_DP_OP]
111         str r1, [r3, #PLL_DP_HFS_OP]
112
113         ldr r1, [r2, #W_DP_MFD]
114         str r1, [r3, #PLL_DP_MFD]
115         str r1, [r3, #PLL_DP_HFS_MFD]
116
117         ldr r1, [r2, #W_DP_MFN]
118         str r1, [r3, #PLL_DP_MFN]
119         str r1, [r3, #PLL_DP_HFS_MFN]
120
121         ldr r1, =0x00001232
122         str r1, [r3, #PLL_DP_CTL]
123 1:      ldr r1, [r3, #PLL_DP_CTL]
124         ands r1, r1, #0x1
125         beq 1b
126
127         /* r10 saved upper lr */
128         mov pc, lr
129
130 .macro setup_pll_errata pll, freq
131         ldr r2, =\pll
132         str r4, [r2, #PLL_DP_CONFIG] /* Disable auto-restart AREN bit */
133         ldr r1, =0x00001236
134         str r1, [r2, #PLL_DP_CTL]    /* Restart PLL with PLM=1 */
135 1:      ldr r1, [r2, #PLL_DP_CTL]    /* Wait for lock */
136         ands r1, r1, #0x1
137         beq 1b
138
139         ldr r5, \freq
140         str r5, [r2, #PLL_DP_MFN]    /* Modify MFN value */
141         str r5, [r2, #PLL_DP_HFS_MFN]
142
143         mov r1, #0x1
144         str r1, [r2, #PLL_DP_CONFIG] /* Reload MFN value */
145
146 2:      ldr r1, [r2, #PLL_DP_CONFIG]
147         tst r1, #1
148         bne 2b
149
150         ldr r1, =100                 /* Wait at least 4 us */
151 3:      subs r1, r1, #1
152         bge 3b
153
154         mov r1, #0x2
155         str r1, [r2, #PLL_DP_CONFIG] /* Enable auto-restart AREN bit */
156 .endm
157
158 .macro init_clock
159         ldr r0, =CCM_BASE_ADDR
160 #if defined (CONFIG_MX51)
161         /* Gate off clocks to the peripherals first */
162         ldr r1, =0x3FFFFFFF
163         str r1, [r0, #CLKCTL_CCGR0]
164         str r4, [r0, #CLKCTL_CCGR1]
165         str r4, [r0, #CLKCTL_CCGR2]
166         str r4, [r0, #CLKCTL_CCGR3]
167
168         ldr r1, =0x00030000
169         str r1, [r0, #CLKCTL_CCGR4]
170         ldr r1, =0x00FFF030
171         str r1, [r0, #CLKCTL_CCGR5]
172         ldr r1, =0x00000300
173         str r1, [r0, #CLKCTL_CCGR6]
174
175         /* Disable IPU and HSC dividers */
176         mov r1, #0x60000
177         str r1, [r0, #CLKCTL_CCDR]
178
179         /* Make sure to switch the DDR away from PLL 1 */
180         ldr r1, =0x19239145
181         str r1, [r0, #CLKCTL_CBCDR]
182         /* make sure divider effective */
183 1:      ldr r1, [r0, #CLKCTL_CDHIPR]
184         tst r1, #0x7f
185         bne 1b
186
187         /* Switch ARM to step clock */
188         mov r1, #0x4
189         str r1, [r0, #CLKCTL_CCSR]
190
191 #if defined(CONFIG_MX51_PLL_ERRATA)
192         setup_pll PLL1_BASE_ADDR, 864
193         setup_pll_errata PLL1_BASE_ADDR, W_DP_MFN_800_DIT
194 #else
195 #if !defined(CONFIG_SYS_CPU_CLK) || CONFIG_SYS_CPU_CLK == 800
196         setup_pll PLL1_BASE_ADDR, 800
197 #elif CONFIG_SYS_CPU_CLK == 600
198         setup_pll PLL1_BASE_ADDR, 600
199 #else
200 #error Unsupported CONFIG_SYS_CPU_CLK value
201 #endif
202 #endif
203
204         setup_pll PLL3_BASE_ADDR, 665
205
206         /* Switch peripheral to PLL 3 */
207         ldr r1, =0x000010C0 | CONFIG_SYS_DDR_CLKSEL
208         str r1, [r0, #CLKCTL_CBCMR]
209         ldr r1, =0x13239145
210         str r1, [r0, #CLKCTL_CBCDR]
211         setup_pll PLL2_BASE_ADDR, 665
212
213         /* Switch peripheral to PLL2 */
214         ldr r1, =0x19239145
215         str r1, [r0, #CLKCTL_CBCDR]
216         ldr r1, =0x000020C0 | CONFIG_SYS_DDR_CLKSEL
217         str r1, [r0, #CLKCTL_CBCMR]
218
219         setup_pll PLL3_BASE_ADDR, 216
220
221         /* Set the platform clock dividers */
222         ldr r0, =ARM_BASE_ADDR
223         ldr r1, =0x00000725
224         str r1, [r0, #0x14]
225
226         ldr r0, =CCM_BASE_ADDR
227
228         /* Run 3.0 at Full speed, for other TO's wait till we increase VDDGP */
229         ldr r3, [r4, #ROM_SI_REV]
230         cmp r3, #0x10
231         movls r1, #0x1
232         movhi r1, #0
233
234         str r1, [r0, #CLKCTL_CACRR]
235
236         /* Switch ARM back to PLL 1 */
237         str r4, [r0, #CLKCTL_CCSR]
238
239         /* setup the rest */
240         /* Use lp_apm (24MHz) source for perclk */
241         ldr r1, =0x000020C2 | CONFIG_SYS_DDR_CLKSEL
242         str r1, [r0, #CLKCTL_CBCMR]
243         /* ddr clock from PLL 1, all perclk dividers are 1 since using 24MHz */
244         ldr r1, =CONFIG_SYS_CLKTL_CBCDR
245         str r1, [r0, #CLKCTL_CBCDR]
246
247         /* Restore the default values in the Gate registers */
248         ldr r1, =0xFFFFFFFF
249         str r1, [r0, #CLKCTL_CCGR0]
250         str r1, [r0, #CLKCTL_CCGR1]
251         str r1, [r0, #CLKCTL_CCGR2]
252         str r1, [r0, #CLKCTL_CCGR3]
253         str r1, [r0, #CLKCTL_CCGR4]
254         str r1, [r0, #CLKCTL_CCGR5]
255         str r1, [r0, #CLKCTL_CCGR6]
256
257         /* Use PLL 2 for UART's, get 66.5MHz from it */
258         ldr r1, =0xA5A2A020
259         str r1, [r0, #CLKCTL_CSCMR1]
260         ldr r1, =0x00C30321
261         str r1, [r0, #CLKCTL_CSCDR1]
262         /* make sure divider effective */
263 1:      ldr r1, [r0, #CLKCTL_CDHIPR]
264         tst r1, #0x7f
265         bne 1b
266
267         str r4, [r0, #CLKCTL_CCDR]
268
269         /* for cko - for ARM div by 8 */
270         mov r1, #0x000A0000
271         add r1, r1, #0x00000F0
272         str r1, [r0, #CLKCTL_CCOSR]
273 #else   /* CONFIG_MX53 */
274         /* Gate off clocks to the peripherals first */
275         ldr r1, =0x3FFFFFFF
276         str r1, [r0, #CLKCTL_CCGR0]
277         str r4, [r0, #CLKCTL_CCGR1]
278         str r4, [r0, #CLKCTL_CCGR2]
279         str r4, [r0, #CLKCTL_CCGR3]
280         str r4, [r0, #CLKCTL_CCGR7]
281         ldr r1, =0x00030000
282         str r1, [r0, #CLKCTL_CCGR4]
283         ldr r1, =0x00FFF030
284         str r1, [r0, #CLKCTL_CCGR5]
285         ldr r1, =0x0F00030F
286         str r1, [r0, #CLKCTL_CCGR6]
287
288         /* Switch ARM to step clock */
289         mov r1, #0x4
290         str r1, [r0, #CLKCTL_CCSR]
291
292 #if !defined(CONFIG_SYS_CPU_CLK) || CONFIG_SYS_CPU_CLK == 800
293         setup_pll PLL1_BASE_ADDR, 800
294 #elif CONFIG_SYS_CPU_CLK == 600
295         setup_pll PLL1_BASE_ADDR, 600
296 #else
297 #error Unsupported CONFIG_SYS_CPU_CLK value
298 #endif
299
300         setup_pll PLL3_BASE_ADDR, 400
301 #ifndef CONFIG_TX53
302         /* Switch peripheral to PLL3 */
303         ldr r1, =0x00015154
304         str r1, [r0, #CLKCTL_CBCMR]
305         ldr r1, =0x02898945
306         str r1, [r0, #CLKCTL_CBCDR]
307         /* make sure change is effective */
308 1:      ldr r1, [r0, #CLKCTL_CDHIPR]
309         tst r1, #0x7f
310         bne 1b
311
312         setup_pll PLL2_BASE_ADDR, 400
313
314         /* Switch peripheral to PLL2 */
315         ldr r1, =0x00888945
316         str r1, [r0, #CLKCTL_CBCDR]
317
318         ldr r1, =0x00016154
319         str r1, [r0, #CLKCTL_CBCMR]
320
321         /* change uart clk parent to pll2 */
322         ldr r1, [r0, #CLKCTL_CSCMR1]
323         bic r1, #(0x3 << 24)
324         orr r1, r1, #(0x1 << 24)
325         str r1, [r0, #CLKCTL_CSCMR1]
326
327         /* make sure change is effective */
328 1:      ldr r1, [r0, #CLKCTL_CDHIPR]
329         tst r1, #0x7f
330         bne 1b
331
332         setup_pll PLL4_BASE_ADDR, 455
333
334 #else /* CONFIG_TX53 */
335         /* Switch peripheral to PLL 3 */
336         ldr r1, [r0, #CLKCTL_CBCMR]
337         bic r1, #(0x3 << 12)
338         orr r1, r1, #(1 << 12)
339         str r1, [r0, #CLKCTL_CBCMR]
340
341         ldr r1, [r0, #CLKCTL_CBCDR]
342         orr r1, r1, #(1 << 25)
343         str r1, [r0, #CLKCTL_CBCDR]
344 1:
345         /* make sure change is effective */
346         ldr r1, [r0, #CLKCTL_CDHIPR]
347         tst r1, #0x7f
348         bne 1b
349
350 #if CONFIG_SYS_SDRAM_CLK == 533
351         setup_pll PLL2_BASE_ADDR, 533
352 #elif CONFIG_SYS_SDRAM_CLK == 400
353         setup_pll PLL2_BASE_ADDR, 400
354 #elif CONFIG_SYS_SDRAM_CLK == 333
355         setup_pll PLL2_BASE_ADDR, 333
356 #else
357 #error Unsupported CONFIG_SYS_SDRAM_CLK
358 #endif
359
360         /* Switch peripheral to PLL2 */
361         ldr r1, [r0, #CLKCTL_CBCDR]
362         bic r1, #(1 << 25)
363         str r1, [r0, #CLKCTL_CBCDR]
364
365         ldr r1, [r0, #CLKCTL_CBCMR]
366         bic r1, #(3 << 12)
367         orr r1, #(2 << 12)
368         str r1, [r0, #CLKCTL_CBCMR]
369 #endif
370         setup_pll PLL3_BASE_ADDR, 216
371
372         /* Set the platform clock dividers */
373         ldr r0, =ARM_BASE_ADDR
374         ldr r1, =0x00000124
375         str r1, [r0, #0x14]
376
377         ldr r0, =CCM_BASE_ADDR
378         mov r1, #0
379         str r1, [r0, #CLKCTL_CACRR]
380
381         /* Switch ARM back to PLL 1. */
382         mov r1, #0x0
383         str r1, [r0, #CLKCTL_CCSR]
384
385         /* make uart div=6 */
386         ldr r1, [r0, #CLKCTL_CSCDR1]
387         bic r1, #(0x3f << 0)
388         orr r1, r1, #0x0a
389         str r1, [r0, #CLKCTL_CSCDR1]
390         /* make sure divider effective */
391 1:      ldr r1, [r0, #CLKCTL_CDHIPR]
392         tst r1, #0x7f
393         bne 1b
394
395         /* Restore the default values in the Gate registers */
396         ldr r1, =0xFFFFFFFF
397         str r1, [r0, #CLKCTL_CCGR0]
398         str r1, [r0, #CLKCTL_CCGR1]
399         str r1, [r0, #CLKCTL_CCGR2]
400         str r1, [r0, #CLKCTL_CCGR3]
401         str r1, [r0, #CLKCTL_CCGR4]
402         str r1, [r0, #CLKCTL_CCGR5]
403         str r1, [r0, #CLKCTL_CCGR6]
404         str r1, [r0, #CLKCTL_CCGR7]
405
406         mov r1, #0x00000
407         str r1, [r0, #CLKCTL_CCDR]
408
409         /* for cko - for ARM div by 8 */
410         mov r1, #0x000A0000
411         add r1, r1, #0x00000F0
412         str r1, [r0, #CLKCTL_CCOSR]
413
414 #endif  /* CONFIG_MX53 */
415 .endm
416
417 .macro setup_wdog
418         ldr r0, =WDOG1_BASE_ADDR
419         mov r1, #0x30
420         strh r1, [r0]
421 .endm
422
423 ENTRY(lowlevel_init)
424         mov r10, lr
425         mov r4, #0      /* Fix R4 to 0 */
426
427 #if defined(CONFIG_SYS_MAIN_PWR_ON)
428         ldr r0, =GPIO1_BASE_ADDR
429         ldr r1, [r0, #0x0]
430         orr r1, r1, #1 << 23
431         str r1, [r0, #0x0]
432         ldr r1, [r0, #0x4]
433         orr r1, r1, #1 << 23
434         str r1, [r0, #0x4]
435 #endif
436
437         init_arm_erratum
438
439         init_l2cc
440
441         init_aips
442
443         init_m4if
444
445         init_clock
446
447         mov pc, r10
448 ENDPROC(lowlevel_init)
449
450 /* Board level setting value */
451 #if defined(CONFIG_MX51_PLL_ERRATA)
452 W_DP_864:               .word DP_OP_864
453                         .word DP_MFD_864
454                         .word DP_MFN_864
455 W_DP_MFN_800_DIT:       .word DP_MFN_800_DIT
456 #else
457 W_DP_800:               .word DP_OP_800
458                         .word DP_MFD_800
459                         .word DP_MFN_800
460 #endif
461 #if defined(CONFIG_MX51)
462 W_DP_665:               .word DP_OP_665
463                         .word DP_MFD_665
464                         .word DP_MFN_665
465 W_DP_600:               .word DP_OP_600
466                         .word DP_MFD_600
467                         .word DP_MFN_600
468 #endif
469 W_DP_216:               .word DP_OP_216
470                         .word DP_MFD_216
471                         .word DP_MFN_216
472 W_DP_400:               .word DP_OP_400
473                         .word DP_MFD_400
474                         .word DP_MFN_400
475 W_DP_455:               .word DP_OP_455
476                         .word DP_MFD_455
477                         .word DP_MFN_455
478 W_DP_533:               .word DP_OP_533
479                         .word DP_MFD_533
480                         .word DP_MFN_533