]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/armv7/mx5/lowlevel_init.S
Merge commit '7b2fac7654f7420c2787f74ec3b1540fa3b343e9'
[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 <asm/arch/asm-offsets.h>
25
26 /*
27  * L2CC Cache setup/invalidation/disable
28  */
29 .macro init_l2cc
30         /* explicitly disable L2 cache */
31         mrc 15, 0, r0, c1, c0, 1
32         bic r0, r0, #0x2
33         mcr 15, 0, r0, c1, c0, 1
34
35         /* reconfigure L2 cache aux control reg */
36         mov r0, #0xC0                   /* tag RAM */
37         add r0, r0, #0x4                /* data RAM */
38         orr r0, r0, #(1 << 24)          /* disable write allocate delay */
39         orr r0, r0, #(1 << 23)          /* disable write allocate combine */
40         orr r0, r0, #(1 << 22)          /* disable write allocate */
41
42 #if defined(CONFIG_MX51)
43         ldr r1, =0x0
44         ldr r3, [r1, #ROM_SI_REV]
45         cmp r3, #0x10
46
47         /* disable write combine for TO 2 and lower revs */
48         orrls r0, r0, #(1 << 25)
49 #endif
50
51         mcr 15, 1, r0, c9, c0, 2
52 .endm /* init_l2cc */
53
54 /* AIPS setup - Only setup MPROTx registers.
55  * The PACR default values are good.*/
56 .macro init_aips
57         /*
58          * Set all MPROTx to be non-bufferable, trusted for R/W,
59          * not forced to user-mode.
60          */
61         ldr r0, =AIPS1_BASE_ADDR
62         ldr r1, =0x77777777
63         str r1, [r0, #0x0]
64         str r1, [r0, #0x4]
65         ldr r0, =AIPS2_BASE_ADDR
66         str r1, [r0, #0x0]
67         str r1, [r0, #0x4]
68         /*
69          * Clear the on and off peripheral modules Supervisor Protect bit
70          * for SDMA to access them. Did not change the AIPS control registers
71          * (offset 0x20) access type
72          */
73 .endm /* init_aips */
74
75 /* M4IF setup */
76 .macro init_m4if
77 #ifdef CONFIG_MX51
78         /* VPU and IPU given higher priority (0x4)
79          * IPU accesses with ID=0x1 given highest priority (=0xA)
80          */
81         ldr r0, =M4IF_BASE_ADDR
82
83         ldr r1, =0x00000203
84         str r1, [r0, #0x40]
85
86         ldr r1, =0x0
87         str r1, [r0, #0x44]
88
89         ldr r1, =0x00120125
90         str r1, [r0, #0x9C]
91
92         ldr r1, =0x001901A3
93         str r1, [r0, #0x48]
94
95 #endif
96 .endm /* init_m4if */
97
98 .macro setup_pll pll, freq
99         ldr r0, =\pll
100         ldr r1, =0x00001232
101         str r1, [r0, #PLL_DP_CTL] /* Set DPLL ON (set UPEN bit): BRMO=1 */
102         mov r1, #0x2
103         str r1, [r0, #PLL_DP_CONFIG] /* Enable auto-restart AREN bit */
104
105         ldr r1, W_DP_OP_\freq
106         str r1, [r0, #PLL_DP_OP]
107         str r1, [r0, #PLL_DP_HFS_OP]
108
109         ldr r1, W_DP_MFD_\freq
110         str r1, [r0, #PLL_DP_MFD]
111         str r1, [r0, #PLL_DP_HFS_MFD]
112
113         ldr r1,  W_DP_MFN_\freq
114         str r1, [r0, #PLL_DP_MFN]
115         str r1, [r0, #PLL_DP_HFS_MFN]
116
117         ldr r1, =0x00001232
118         str r1, [r0, #PLL_DP_CTL]
119 1:      ldr r1, [r0, #PLL_DP_CTL]
120         ands r1, r1, #0x1
121         beq 1b
122 .endm
123
124 .macro init_clock
125         ldr r0, =CCM_BASE_ADDR
126
127 #if defined(CONFIG_MX51)
128         /* Gate of clocks to the peripherals first */
129         ldr r1, =0x3FFFFFFF
130         str r1, [r0, #CLKCTL_CCGR0]
131         ldr r1, =0x0
132         str r1, [r0, #CLKCTL_CCGR1]
133         str r1, [r0, #CLKCTL_CCGR2]
134         str r1, [r0, #CLKCTL_CCGR3]
135
136         ldr r1, =0x00030000
137         str r1, [r0, #CLKCTL_CCGR4]
138         ldr r1, =0x00FFF030
139         str r1, [r0, #CLKCTL_CCGR5]
140         ldr r1, =0x00000300
141         str r1, [r0, #CLKCTL_CCGR6]
142
143         /* Disable IPU and HSC dividers */
144         mov r1, #0x60000
145         str r1, [r0, #CLKCTL_CCDR]
146
147         /* Make sure to switch the DDR away from PLL 1 */
148         ldr r1, =0x19239145
149         str r1, [r0, #CLKCTL_CBCDR]
150         /* make sure divider effective */
151 1:      ldr r1, [r0, #CLKCTL_CDHIPR]
152         cmp r1, #0x0
153         bne 1b
154 #endif
155
156         /* Switch ARM to step clock */
157         mov r1, #0x4
158         str r1, [r0, #CLKCTL_CCSR]
159
160         setup_pll PLL1_BASE_ADDR, 800
161
162 #if defined(CONFIG_MX51)
163         setup_pll PLL3_BASE_ADDR, 665
164
165         /* Switch peripheral to PLL 3 */
166         ldr r0, =CCM_BASE_ADDR
167         ldr r1, =0x000010C0
168         orr r1,r1,#CONFIG_SYS_DDR_CLKSEL
169         str r1, [r0, #CLKCTL_CBCMR]
170         ldr r1, =0x13239145
171         str r1, [r0, #CLKCTL_CBCDR]
172         setup_pll PLL2_BASE_ADDR, 665
173
174         /* Switch peripheral to PLL2 */
175         ldr r0, =CCM_BASE_ADDR
176         ldr r1, =0x19239145
177         str r1, [r0, #CLKCTL_CBCDR]
178         ldr r1, =0x000020C0
179         orr r1,r1,#CONFIG_SYS_DDR_CLKSEL
180         str r1, [r0, #CLKCTL_CBCMR]
181 #endif
182         setup_pll PLL3_BASE_ADDR, 216
183
184         /* Set the platform clock dividers */
185         ldr r0, =ARM_BASE_ADDR
186         ldr r1, =0x00000725
187         str r1, [r0, #0x14]
188
189         ldr r0, =CCM_BASE_ADDR
190
191 #if defined(CONFIG_MX51)
192         /* Run 3.0 at Full speed, for other TO's wait till we increase VDDGP */
193         ldr r1, =0x0
194         ldr r3, [r1, #ROM_SI_REV]
195         cmp r3, #0x10
196         movls r1, #0x1
197         movhi r1, #0
198 #else
199         mov r1, #0
200
201 #endif
202         str r1, [r0, #CLKCTL_CACRR]
203         /* Switch ARM back to PLL 1 */
204         mov r1, #0
205         str r1, [r0, #CLKCTL_CCSR]
206
207 #if defined(CONFIG_MX51)
208         /* setup the rest */
209         /* Use lp_apm (24MHz) source for perclk */
210         ldr r1, =0x000020C2
211         orr r1,r1,#CONFIG_SYS_DDR_CLKSEL
212         str r1, [r0, #CLKCTL_CBCMR]
213         /* ddr clock from PLL 1, all perclk dividers are 1 since using 24MHz */
214         ldr r1, =CONFIG_SYS_CLKTL_CBCDR
215         str r1, [r0, #CLKCTL_CBCDR]
216 #endif
217
218         /* Restore the default values in the Gate registers */
219         ldr r1, =0xFFFFFFFF
220         str r1, [r0, #CLKCTL_CCGR0]
221         str r1, [r0, #CLKCTL_CCGR1]
222         str r1, [r0, #CLKCTL_CCGR2]
223         str r1, [r0, #CLKCTL_CCGR3]
224         str r1, [r0, #CLKCTL_CCGR4]
225         str r1, [r0, #CLKCTL_CCGR5]
226         str r1, [r0, #CLKCTL_CCGR6]
227 #if defined(CONFIG_MX53)
228         str r1, [r0, #CLKCTL_CCGR7]
229 #endif
230
231 #if defined(CONFIG_MX51)
232         /* Use PLL 2 for UART's, get 66.5MHz from it */
233         ldr r1, =0xA5A2A020
234         str r1, [r0, #CLKCTL_CSCMR1]
235         ldr r1, =0x00C30321
236         str r1, [r0, #CLKCTL_CSCDR1]
237 #elif defined(CONFIG_MX53)
238         ldr r1, [r0, #CLKCTL_CSCDR1]
239         orr r1, r1, #0x3f
240         eor r1, r1, #0x3f
241         orr r1, r1, #0x21
242         str r1, [r0, #CLKCTL_CSCDR1]
243 #endif
244         /* make sure divider effective */
245 1:      ldr r1, [r0, #CLKCTL_CDHIPR]
246         cmp r1, #0x0
247         bne 1b
248
249         mov r1, #0x0
250         str r1, [r0, #CLKCTL_CCDR]
251
252         /* for cko - for ARM div by 8 */
253         mov r1, #0x000A0000
254         add r1, r1, #0x00000F0
255         str r1, [r0, #CLKCTL_CCOSR]
256 .endm
257
258 .macro setup_wdog
259         ldr r0, =WDOG1_BASE_ADDR
260         mov r1, #0x30
261         strh r1, [r0]
262 .endm
263
264 .section ".text.init", "x"
265
266 .globl lowlevel_init
267 lowlevel_init:
268 #if defined(CONFIG_MX51)
269         ldr r0, =GPIO1_BASE_ADDR
270         ldr r1, [r0, #0x0]
271         orr r1, r1, #(1 << 23)
272         str r1, [r0, #0x0]
273         ldr r1, [r0, #0x4]
274         orr r1, r1, #(1 << 23)
275         str r1, [r0, #0x4]
276 #endif
277
278         init_l2cc
279
280         init_aips
281
282         init_m4if
283
284         init_clock
285
286         /* r12 saved upper lr*/
287         mov pc,lr
288
289 /* Board level setting value */
290 W_DP_OP_800:              .word DP_OP_800
291 W_DP_MFD_800:             .word DP_MFD_800
292 W_DP_MFN_800:             .word DP_MFN_800
293 W_DP_OP_665:              .word DP_OP_665
294 W_DP_MFD_665:             .word DP_MFD_665
295 W_DP_MFN_665:             .word DP_MFN_665
296 W_DP_OP_216:              .word DP_OP_216
297 W_DP_MFD_216:             .word DP_MFD_216
298 W_DP_MFN_216:             .word DP_MFN_216