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