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