]> git.karo-electronics.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/armv7/mx5/lowlevel_init.S
Merge branch 'agust@denx.de-next' of git://git.denx.de/u-boot-staging
[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 /*
30  * L2CC Cache setup/invalidation/disable
31  */
32 .macro init_l2cc
33         /* explicitly disable L2 cache */
34         mrc 15, 0, r0, c1, c0, 1
35         bic r0, r0, #0x2
36         mcr 15, 0, r0, c1, c0, 1
37
38         /* reconfigure L2 cache aux control reg */
39         ldr r0, =0xC0 |                 /* tag RAM */ \
40                  0x4 |                  /* data RAM */ \
41                  1 << 24 |              /* disable write allocate delay */ \
42                  1 << 23 |              /* disable write allocate combine */ \
43                  1 << 22                /* disable write allocate */
44
45 #if defined(CONFIG_MX51)
46         ldr r3, [r4, #ROM_SI_REV]
47         cmp r3, #0x10
48
49         /* disable write combine for TO 2 and lower revs */
50         orrls r0, r0, #1 << 25
51 #endif
52
53         mcr 15, 1, r0, c9, c0, 2
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_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 r0, =\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, [r0, #PLL_DP_CTL] /* Set DPLL ON (set UPEN bit): BRMO=1 */
112         mov r1, #0x2
113         str r1, [r0, #PLL_DP_CONFIG] /* Enable auto-restart AREN bit */
114
115         ldr r1, [r2, #W_DP_OP]
116         str r1, [r0, #PLL_DP_OP]
117         str r1, [r0, #PLL_DP_HFS_OP]
118
119         ldr r1, [r2, #W_DP_MFD]
120         str r1, [r0, #PLL_DP_MFD]
121         str r1, [r0, #PLL_DP_HFS_MFD]
122
123         ldr r1, [r2, #W_DP_MFN]
124         str r1, [r0, #PLL_DP_MFN]
125         str r1, [r0, #PLL_DP_HFS_MFN]
126
127         ldr r1, =0x00001232
128         str r1, [r0, #PLL_DP_CTL]
129 1:      ldr r1, [r0, #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
167 #if defined(CONFIG_MX51)
168         /* Gate of clocks to the peripherals first */
169         ldr r1, =0x3FFFFFFF
170         str r1, [r0, #CLKCTL_CCGR0]
171         str r4, [r0, #CLKCTL_CCGR1]
172         str r4, [r0, #CLKCTL_CCGR2]
173         str r4, [r0, #CLKCTL_CCGR3]
174
175         ldr r1, =0x00030000
176         str r1, [r0, #CLKCTL_CCGR4]
177         ldr r1, =0x00FFF030
178         str r1, [r0, #CLKCTL_CCGR5]
179         ldr r1, =0x00000300
180         str r1, [r0, #CLKCTL_CCGR6]
181
182         /* Disable IPU and HSC dividers */
183         mov r1, #0x60000
184         str r1, [r0, #CLKCTL_CCDR]
185
186         /* Make sure to switch the DDR away from PLL 1 */
187         ldr r1, =0x19239145
188         str r1, [r0, #CLKCTL_CBCDR]
189         /* make sure divider effective */
190 1:      ldr r1, [r0, #CLKCTL_CDHIPR]
191         cmp r1, #0x0
192         bne 1b
193 #else
194         ldr r1, =0x3FFFFFFF
195         str r1, [r0, #CLKCTL_CCGR0]
196         str r4, [r0, #CLKCTL_CCGR1]
197         str r4, [r0, #CLKCTL_CCGR2]
198         str r4, [r0, #CLKCTL_CCGR3]
199         str r4, [r0, #CLKCTL_CCGR7]
200
201         ldr r1, =0x00030000
202         str r1, [r0, #CLKCTL_CCGR4]
203         ldr r1, =0x00FFF030
204         str r1, [r0, #CLKCTL_CCGR5]
205         ldr r1, =0x0F00030F
206         str r1, [r0, #CLKCTL_CCGR6]
207 #endif
208
209         /* Switch ARM to step clock */
210         mov r1, #0x4
211         str r1, [r0, #CLKCTL_CCSR]
212
213 #if defined(CONFIG_MX51_PLL_ERRATA)
214         setup_pll PLL1_BASE_ADDR, 864
215         setup_pll_errata PLL1_BASE_ADDR, W_DP_MFN_800_DIT
216 #else
217         setup_pll PLL1_BASE_ADDR, 800
218 #endif
219
220 #if defined(CONFIG_MX51)
221         setup_pll PLL3_BASE_ADDR, 665
222
223         /* Switch peripheral to PLL 3 */
224         ldr r0, =CCM_BASE_ADDR
225         ldr r1, =0x000010C0 | CONFIG_SYS_DDR_CLKSEL
226         str r1, [r0, #CLKCTL_CBCMR]
227         ldr r1, =0x13239145
228         str r1, [r0, #CLKCTL_CBCDR]
229         setup_pll PLL2_BASE_ADDR, 665
230
231         /* Switch peripheral to PLL2 */
232         ldr r0, =CCM_BASE_ADDR
233         ldr r1, =0x19239145
234         str r1, [r0, #CLKCTL_CBCDR]
235         ldr r1, =0x000020C0 | CONFIG_SYS_DDR_CLKSEL
236         str r1, [r0, #CLKCTL_CBCMR]
237 #endif
238         setup_pll PLL3_BASE_ADDR, 216
239
240         /* Set the platform clock dividers */
241         ldr r0, =ARM_BASE_ADDR
242         ldr r1, =0x00000725
243         str r1, [r0, #0x14]
244
245         ldr r0, =CCM_BASE_ADDR
246
247 #if defined(CONFIG_MX51)
248         /* Run 3.0 at Full speed, for other TO's wait till we increase VDDGP */
249         ldr r3, [r4, #ROM_SI_REV]
250         cmp r3, #0x10
251         movls r1, #0x1
252         movhi r1, #0
253 #else
254         mov r1, #0
255 #endif
256         str r1, [r0, #CLKCTL_CACRR]
257
258         /* Switch ARM back to PLL 1 */
259         str r4, [r0, #CLKCTL_CCSR]
260
261 #if defined(CONFIG_MX51)
262         /* setup the rest */
263         /* Use lp_apm (24MHz) source for perclk */
264         ldr r1, =0x000020C2 | CONFIG_SYS_DDR_CLKSEL
265         str r1, [r0, #CLKCTL_CBCMR]
266         /* ddr clock from PLL 1, all perclk dividers are 1 since using 24MHz */
267         ldr r1, =CONFIG_SYS_CLKTL_CBCDR
268         str r1, [r0, #CLKCTL_CBCDR]
269 #endif
270
271         /* Restore the default values in the Gate registers */
272         ldr r1, =0xFFFFFFFF
273         str r1, [r0, #CLKCTL_CCGR0]
274         str r1, [r0, #CLKCTL_CCGR1]
275         str r1, [r0, #CLKCTL_CCGR2]
276         str r1, [r0, #CLKCTL_CCGR3]
277         str r1, [r0, #CLKCTL_CCGR4]
278         str r1, [r0, #CLKCTL_CCGR5]
279         str r1, [r0, #CLKCTL_CCGR6]
280 #if defined(CONFIG_MX53)
281         str r1, [r0, #CLKCTL_CCGR7]
282 #endif
283
284 #if defined(CONFIG_MX51)
285         /* Use PLL 2 for UART's, get 66.5MHz from it */
286         ldr r1, =0xA5A2A020
287         str r1, [r0, #CLKCTL_CSCMR1]
288         ldr r1, =0x00C30321
289         str r1, [r0, #CLKCTL_CSCDR1]
290 #elif defined(CONFIG_MX53)
291         /* Switch peripheral to PLL2 */
292         ldr r0, =CCM_BASE_ADDR
293         ldr r1, =0x00808145
294         orr r1, r1, #2 << 10
295         orr r1, r1, #1 << 19
296         str r1, [r0, #CLKCTL_CBCDR]
297
298         ldr r1, =0x00016154
299         str r1, [r0, #CLKCTL_CBCMR]
300         /* Change uart clk parent to pll2*/
301         ldr r1, [r0, #CLKCTL_CSCMR1]
302         and r1, r1, #0xfcffffff
303         orr r1, r1, #0x01000000
304         str r1, [r0, #CLKCTL_CSCMR1]
305         ldr r1, [r0, #CLKCTL_CSCDR1]
306         and r1, r1, #0xffffffc0
307         orr r1, r1, #0x0a
308         str r1, [r0, #CLKCTL_CSCDR1]
309 #endif
310         /* make sure divider effective */
311 1:      ldr r1, [r0, #CLKCTL_CDHIPR]
312         cmp r1, #0x0
313         bne 1b
314
315         str r4, [r0, #CLKCTL_CCDR]
316
317         /* for cko - for ARM div by 8 */
318         mov r1, #0x000A0000
319         add r1, r1, #0x00000F0
320         str r1, [r0, #CLKCTL_CCOSR]
321 .endm
322
323 .macro setup_wdog
324         ldr r0, =WDOG1_BASE_ADDR
325         mov r1, #0x30
326         strh r1, [r0]
327 .endm
328
329 ENTRY(lowlevel_init)
330         mov r10, lr
331         mov r4, #0      /* Fix R4 to 0 */
332
333 #if defined(CONFIG_MX51)
334         ldr r0, =GPIO1_BASE_ADDR
335         ldr r1, [r0, #0x0]
336         orr r1, r1, #1 << 23
337         str r1, [r0, #0x0]
338         ldr r1, [r0, #0x4]
339         orr r1, r1, #1 << 23
340         str r1, [r0, #0x4]
341 #endif
342
343         init_l2cc
344
345         init_aips
346
347         init_m4if
348
349         init_clock
350
351         mov pc, r10
352 ENDPROC(lowlevel_init)
353
354 /* Board level setting value */
355 #if defined(CONFIG_MX51_PLL_ERRATA)
356 W_DP_864:               .word DP_OP_864
357                         .word DP_MFD_864
358                         .word DP_MFN_864
359 W_DP_MFN_800_DIT:       .word DP_MFN_800_DIT
360 #else
361 W_DP_800:               .word DP_OP_800
362                         .word DP_MFD_800
363                         .word DP_MFN_800
364 #endif
365 #if defined(CONFIG_MX51)
366 W_DP_665:               .word DP_OP_665
367                         .word DP_MFD_665
368                         .word DP_MFN_665
369 #endif
370 W_DP_216:               .word DP_OP_216
371                         .word DP_MFD_216
372                         .word DP_MFN_216