]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/freescale/mx51_3stack/lowlevel_init.S
applied patches from Freescale and Ka-Ro
[karo-tx-uboot.git] / board / freescale / mx51_3stack / lowlevel_init.S
1 /*
2  * Copyright (C) 2007, Guennadi Liakhovetski <lg@denx.de>
3  *
4  * (C) Copyright 2009-2010 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/mx51.h>
24 #include "board-mx51_3stack.h"
25
26 /*
27  * return soc version
28  *      0x10:  TO1
29  *      0x20:  TO2
30  *      0x30:  TO3
31  */
32 .macro check_soc_version ret, tmp
33 .endm
34
35 /*
36  * L2CC Cache setup/invalidation/disable
37  */
38 .macro init_l2cc
39         /* explicitly disable L2 cache */
40         mrc 15, 0, r0, c1, c0, 1
41         bic r0, r0, #0x2
42         mcr 15, 0, r0, c1, c0, 1
43
44         /* reconfigure L2 cache aux control reg */
45         mov r0, #0xC0                   /* tag RAM */
46         add r0, r0, #0x4                /* data RAM */
47         orr r0, r0, #(1 << 24)          /* disable write allocate delay */
48         orr r0, r0, #(1 << 23)          /* disable write allocate combine */
49         orr r0, r0, #(1 << 22)          /* disable write allocate */
50
51         ldr r1, =0x00000000
52         ldr r3, [r1, #ROM_SI_REV]
53         cmp r3, #0x10    /* r3 contains the silicon rev */
54         /* disable write combine for TO 2 and lower */
55         orrls r0, r0, #(1 << 25)
56
57         mcr 15, 1, r0, c9, c0, 2
58 .endm /* init_l2cc */
59
60 /* AIPS setup - Only setup MPROTx registers.
61  * The PACR default values are good.*/
62 .macro init_aips
63         /*
64          * Set all MPROTx to be non-bufferable, trusted for R/W,
65          * not forced to user-mode.
66          */
67         ldr r0, =AIPS1_BASE_ADDR
68         ldr r1, =0x77777777
69         str r1, [r0, #0x0]
70         str r1, [r0, #0x4]
71         ldr r0, =AIPS2_BASE_ADDR
72         str r1, [r0, #0x0]
73         str r1, [r0, #0x4]
74         /*
75          * Clear the on and off peripheral modules Supervisor Protect bit
76          * for SDMA to access them. Did not change the AIPS control registers
77          * (offset 0x20) access type
78          */
79 .endm /* init_aips */
80
81 /* MAX (Multi-Layer AHB Crossbar Switch) setup */
82 .macro init_max
83 .endm /* init_max */
84
85 /* M4IF setup */
86 .macro init_m4if
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         ldr r1, =0x0
96         str r1, [r0, #0x44]
97
98         ldr r1, =0x00120125
99         str r1, [r0, #0x9C]
100
101         ldr r1, =0x001901A3
102         str r1, [r0, #0x48]
103 .endm /* init_m4if */
104
105 /* To support 133MHz DDR */
106 .macro  init_drive_strength
107 .endm /* init_drive_strength */
108
109 /* CPLD on CS5 setup */
110 .macro init_debug_board
111 .endm /* init_debug_board */
112
113 .macro setup_pll pll, freq
114         ldr r2, =\pll
115         ldr r1, =0x00001232
116         str r1, [r2, #PLL_DP_CTL] /* Set DPLL ON (set UPEN bit): BRMO=1 */
117         mov r1, #0x2
118         str r1, [r2, #PLL_DP_CONFIG] /* Enable auto-restart AREN bit */
119
120         str r3, [r2, #PLL_DP_OP]
121         str r3, [r2, #PLL_DP_HFS_OP]
122
123         str r4, [r2, #PLL_DP_MFD]
124         str r4, [r2, #PLL_DP_HFS_MFD]
125
126         str r5, [r2, #PLL_DP_MFN]
127         str r5, [r2, #PLL_DP_HFS_MFN]
128
129         ldr r1, =0x00001232
130         str r1, [r2, #PLL_DP_CTL]
131 1:      ldr r1, [r2, #PLL_DP_CTL]
132         ands r1, r1, #0x1
133         beq 1b
134 .endm
135
136 .macro init_clock
137         ldr r0, =CCM_BASE_ADDR
138
139         /* Gate of clocks to the peripherals first */
140         ldr r1, =0x3FFFFFFF
141         str r1, [r0, #CLKCTL_CCGR0]
142         ldr r1, =0x0
143         str r1, [r0, #CLKCTL_CCGR1]
144         str r1, [r0, #CLKCTL_CCGR2]
145         str r1, [r0, #CLKCTL_CCGR3]
146
147         ldr r1, =0x00030000
148         str r1, [r0, #CLKCTL_CCGR4]
149         ldr r1, =0x00FFF030
150         str r1, [r0, #CLKCTL_CCGR5]
151         ldr r1, =0x00000300
152         str r1, [r0, #CLKCTL_CCGR6]
153
154         /* Disable IPU and HSC dividers */
155         mov r1, #0x60000
156         str r1, [r0, #CLKCTL_CCDR]
157
158         /* Make sure to switch the DDR away from PLL 1 */
159         ldr r1, =0x19239145
160         str r1, [r0, #CLKCTL_CBCDR]
161         /* make sure divider effective */
162 1:      ldr r1, [r0, #CLKCTL_CDHIPR]
163         cmp r1, #0x0
164         bne 1b
165
166         /* Switch ARM to step clock */
167         mov r1, #0x4
168         str r1, [r0, #CLKCTL_CCSR]
169
170         mov r3, #DP_OP_800
171         mov r4, #DP_MFD_800
172         mov r5, #DP_MFN_800
173         setup_pll PLL1_BASE_ADDR
174         mov r3, #DP_OP_665
175         mov r4, #DP_MFD_665
176         mov r5, #DP_MFN_665
177         setup_pll PLL3_BASE_ADDR
178
179         /* Switch peripheral to PLL 3 */
180         ldr r0, =CCM_BASE_ADDR
181         ldr r1, =0x000010C0
182         str r1, [r0, #CLKCTL_CBCMR]
183         ldr r1, =0x13239145
184         str r1, [r0, #CLKCTL_CBCDR]
185
186         mov r3, #DP_OP_665
187         mov r4, #DP_MFD_665
188         mov r5, #DP_MFN_665
189         setup_pll PLL2_BASE_ADDR
190
191         /* Switch peripheral to PLL2 */
192         ldr r0, =CCM_BASE_ADDR
193         ldr r1, =0x19239145
194         str r1, [r0, #CLKCTL_CBCDR]
195         ldr r1, =0x000020C0
196         str r1, [r0, #CLKCTL_CBCMR]
197
198         mov r3, #DP_OP_216
199         mov r4, #DP_MFD_216
200         mov r5, #DP_MFN_216
201         setup_pll PLL3_BASE_ADDR
202
203         /* Set the platform clock dividers */
204         ldr r0, =ARM_BASE_ADDR
205         ldr r1, =0x00000725
206         str r1, [r0, #0x14]
207
208         ldr r0, =CCM_BASE_ADDR
209         /* Run TO 3.0 at Full speed, for other TO's wait
210         till we increase VDDGP */
211         ldr r1, =0x0
212         ldr r3, [r1, #ROM_SI_REV]
213         cmp r3, #0x10
214         movls r1, #0x1
215         movhi r1, #0
216         str r1, [r0, #CLKCTL_CACRR]
217
218         /* Switch ARM back to PLL 1 */
219         mov r1, #0
220         str r1, [r0, #CLKCTL_CCSR]
221
222         /* setup the rest */
223         /* Use lp_apm (24MHz) source for perclk */
224         ldr r1, =0x000020C2
225         str r1, [r0, #CLKCTL_CBCMR]
226         /* ddr clock from PLL 1, all perclk dividers are 1 since using 24MHz */
227 #ifdef CONFIG_IMX51_MDDR
228         ldr r1, =0x61E35100
229 #else
230         ldr r1, =0x59E35100
231 #endif
232         str r1, [r0, #CLKCTL_CBCDR]
233
234         /* Restore the default values in the Gate registers */
235         ldr r1, =0xFFFFFFFF
236         str r1, [r0, #CLKCTL_CCGR0]
237         str r1, [r0, #CLKCTL_CCGR1]
238         str r1, [r0, #CLKCTL_CCGR2]
239         str r1, [r0, #CLKCTL_CCGR3]
240         str r1, [r0, #CLKCTL_CCGR4]
241         str r1, [r0, #CLKCTL_CCGR5]
242         str r1, [r0, #CLKCTL_CCGR6]
243
244         /* Use PLL 2 for UART's, get 66.5MHz from it */
245         ldr r1, =0xA5A2A020
246         str r1, [r0, #CLKCTL_CSCMR1]
247         ldr r1, =0x00C30321
248         str r1, [r0, #CLKCTL_CSCDR1]
249
250         /* make sure divider effective */
251 1:      ldr r1, [r0, #CLKCTL_CDHIPR]
252         cmp r1, #0x0
253         bne 1b
254
255         mov r1, #0x0
256         str r1, [r0, #CLKCTL_CCDR]
257
258         /* for cko - for ARM div by 8 */
259         mov r1, #0x000A0000
260         add r1, r1, #0x00000F0
261         str r1, [r0, #CLKCTL_CCOSR]
262 .endm
263
264 .macro setup_wdog
265         ldr r0, =WDOG1_BASE_ADDR
266         mov r1, #0x30
267         strh r1, [r0]
268 .endm
269
270 .macro setup_sdram
271         ldr r0, =ESDCTL_BASE_ADDR
272         /* Set CSD0 */
273         mov r1, #0x80000000
274         str r1, [r0, #ESDCTL_ESDCTL0]
275         /* Precharge command */
276         ldr r1, DDR_PERCHARGE_CMD
277         str r1, [r0, #ESDCTL_ESDSCR]
278         /* 2 refresh commands */
279         ldr r1, DDR_REFRESH_CMD
280         str r1, [r0, #ESDCTL_ESDSCR]
281         str r1, [r0, #ESDCTL_ESDSCR]
282         /* LMR with CAS=3 and BL=3 */
283         ldr r1, DDR_LMR1_W
284         str r1, [r0, #ESDCTL_ESDSCR]
285         /* 13 ROW, 10 COL, 32Bit, SREF=4 Micron Model */
286         ldr r1, DDR_LMR_CMD
287         str r1, [r0, #ESDCTL_ESDCTL0]
288         /* Timing parameters */
289         ldr r1, DDR_TIMING_W
290         str r1, [r0, #ESDCTL_ESDCFG0]
291         /* MDDR enable, RLAT=2 */
292         ldr r1, DDR_MISC_W
293         str r1, [r0, #ESDCTL_ESDMISC]
294         /* Normal mode */
295         mov r1, #0x00000000
296         str r1, [r0, #ESDCTL_ESDSCR]
297 1:
298 .endm /* setup_sdram */
299
300 .section ".text.init", "x"
301
302 .globl lowlevel_init
303 lowlevel_init:
304         ldr r1, =0x00000000
305         ldr r3, [r1, #ROM_SI_REV]
306         ldr r0, =GPC_BASE_ADDR
307         cmp r3, #0x10    // r3 contains the silicon rev
308         ldrls r1, =0x1FC00000
309         ldrhi r1, =0x1A800000
310         str r1, [r0, #4]
311
312 #ifdef ENABLE_IMPRECISE_ABORT
313         mrs r1, spsr            /* save old spsr */
314         mrs r0, cpsr            /* read out the cpsr */
315         bic r0, r0, #0x100      /* clear the A bit */
316         msr spsr, r0            /* update spsr */
317         add lr, pc, #0x8        /* update lr */
318         movs pc, lr             /* update cpsr */
319         nop
320         nop
321         nop
322         nop
323         msr spsr, r1            /* restore old spsr */
324 #endif
325
326         /* ARM errata ID #468414 */
327         mrc 15, 0, r1, c1, c0, 1
328         orr r1, r1, #(1 << 5)    /* enable L1NEON bit */
329         mcr 15, 0, r1, c1, c0, 1
330
331         init_l2cc
332
333         init_aips
334
335
336         init_max
337
338         init_m4if
339
340         init_drive_strength
341
342         cmp pc, #PHYS_SDRAM_1
343         blo do_sdram_setup
344         cmp pc, #(PHYS_SDRAM_1 + PHYS_SDRAM_1_SIZE)
345         blo init_clock_start
346
347 do_sdram_setup:
348         setup_sdram
349
350 init_clock_start:
351         init_clock
352         init_debug_board
353         /*init_sdram*/
354
355         /* return from mxc_nand_load */
356         /* r12 saved upper lr*/
357         b mxc_nand_load
358
359 /* Board level setting value */
360 DDR_PERCHARGE_CMD:      .word 0x04008008
361 DDR_REFRESH_CMD:        .word 0x00008010
362 DDR_LMR1_W:             .word 0x00338018
363 DDR_LMR_CMD:            .word 0xB2220000
364 DDR_TIMING_W:           .word 0xB02567A9
365 DDR_MISC_W:             .word 0x000A0104