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