]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - cpu/arm_cortexa8/mx51/lowlevel_init.S
Merge branch 'master' of git://git.denx.de/u-boot-arm
[karo-tx-uboot.git] / cpu / arm_cortexa8 / mx51 / 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         /* VPU and IPU given higher priority (0x4)
74          * IPU accesses with ID=0x1 given highest priority (=0xA)
75          */
76         ldr r0, =M4IF_BASE_ADDR
77
78         ldr r1, =0x00000203
79         str r1, [r0, #0x40]
80
81         ldr r1, =0x0
82         str r1, [r0, #0x44]
83
84         ldr r1, =0x00120125
85         str r1, [r0, #0x9C]
86
87         ldr r1, =0x001901A3
88         str r1, [r0, #0x48]
89
90 .endm /* init_m4if */
91
92 .macro setup_pll pll, freq
93         ldr r2, =\pll
94         ldr r1, =0x00001232
95         str r1, [r2, #PLL_DP_CTL] /* Set DPLL ON (set UPEN bit): BRMO=1 */
96         mov r1, #0x2
97         str r1, [r2, #PLL_DP_CONFIG] /* Enable auto-restart AREN bit */
98
99         str r3, [r2, #PLL_DP_OP]
100         str r3, [r2, #PLL_DP_HFS_OP]
101
102         str r4, [r2, #PLL_DP_MFD]
103         str r4, [r2, #PLL_DP_HFS_MFD]
104
105         str r5, [r2, #PLL_DP_MFN]
106         str r5, [r2, #PLL_DP_HFS_MFN]
107
108         ldr r1, =0x00001232
109         str r1, [r2, #PLL_DP_CTL]
110 1:      ldr r1, [r2, #PLL_DP_CTL]
111         ands r1, r1, #0x1
112         beq 1b
113 .endm
114
115 .macro init_clock
116         ldr r0, =CCM_BASE_ADDR
117
118         /* Gate of clocks to the peripherals first */
119         ldr r1, =0x3FFFFFFF
120         str r1, [r0, #CLKCTL_CCGR0]
121         ldr r1, =0x0
122         str r1, [r0, #CLKCTL_CCGR1]
123         str r1, [r0, #CLKCTL_CCGR2]
124         str r1, [r0, #CLKCTL_CCGR3]
125
126         ldr r1, =0x00030000
127         str r1, [r0, #CLKCTL_CCGR4]
128         ldr r1, =0x00FFF030
129         str r1, [r0, #CLKCTL_CCGR5]
130         ldr r1, =0x00000300
131         str r1, [r0, #CLKCTL_CCGR6]
132
133         /* Disable IPU and HSC dividers */
134         mov r1, #0x60000
135         str r1, [r0, #CLKCTL_CCDR]
136
137         /* Make sure to switch the DDR away from PLL 1 */
138         ldr r1, =0x19239145
139         str r1, [r0, #CLKCTL_CBCDR]
140         /* make sure divider effective */
141 1:      ldr r1, [r0, #CLKCTL_CDHIPR]
142         cmp r1, #0x0
143         bne 1b
144
145         /* Switch ARM to step clock */
146         mov r1, #0x4
147         str r1, [r0, #CLKCTL_CCSR]
148         mov r3, #DP_OP_800
149         mov r4, #DP_MFD_800
150         mov r5, #DP_MFN_800
151         setup_pll PLL1_BASE_ADDR
152
153         mov r3, #DP_OP_665
154         mov r4, #DP_MFD_665
155         mov r5, #DP_MFN_665
156         setup_pll PLL3_BASE_ADDR
157
158         /* Switch peripheral to PLL 3 */
159         ldr r0, =CCM_BASE_ADDR
160         ldr r1, =0x000010C0
161         str r1, [r0, #CLKCTL_CBCMR]
162         ldr r1, =0x13239145
163         str r1, [r0, #CLKCTL_CBCDR]
164         mov r3, #DP_OP_665
165         mov r4, #DP_MFD_665
166         mov r5, #DP_MFN_665
167         setup_pll PLL2_BASE_ADDR
168
169         /* Switch peripheral to PLL2 */
170         ldr r0, =CCM_BASE_ADDR
171         ldr r1, =0x19239145
172         str r1, [r0, #CLKCTL_CBCDR]
173         ldr r1, =0x000020C0
174         str r1, [r0, #CLKCTL_CBCMR]
175
176         mov r3, #DP_OP_216
177         mov r4, #DP_MFD_216
178         mov r5, #DP_MFN_216
179         setup_pll PLL3_BASE_ADDR
180
181
182         /* Set the platform clock dividers */
183         ldr r0, =ARM_BASE_ADDR
184         ldr r1, =0x00000725
185         str r1, [r0, #0x14]
186
187         ldr r0, =CCM_BASE_ADDR
188
189         /* Run 3.0 at Full speed, for other TO's wait till we increase VDDGP */
190         ldr r1, =0x0
191         ldr r3, [r1, #ROM_SI_REV]
192         cmp r3, #0x10
193         movls r1, #0x1
194         movhi r1, #0
195         str r1, [r0, #CLKCTL_CACRR]
196
197         /* Switch ARM back to PLL 1 */
198         mov r1, #0
199         str r1, [r0, #CLKCTL_CCSR]
200
201         /* setup the rest */
202         /* Use lp_apm (24MHz) source for perclk */
203         ldr r1, =0x000020C2
204         str r1, [r0, #CLKCTL_CBCMR]
205         /* ddr clock from PLL 1, all perclk dividers are 1 since using 24MHz */
206         ldr r1, =0x59E35100
207         str r1, [r0, #CLKCTL_CBCDR]
208
209         /* Restore the default values in the Gate registers */
210         ldr r1, =0xFFFFFFFF
211         str r1, [r0, #CLKCTL_CCGR0]
212         str r1, [r0, #CLKCTL_CCGR1]
213         str r1, [r0, #CLKCTL_CCGR2]
214         str r1, [r0, #CLKCTL_CCGR3]
215         str r1, [r0, #CLKCTL_CCGR4]
216         str r1, [r0, #CLKCTL_CCGR5]
217         str r1, [r0, #CLKCTL_CCGR6]
218
219         /* Use PLL 2 for UART's, get 66.5MHz from it */
220         ldr r1, =0xA5A2A020
221         str r1, [r0, #CLKCTL_CSCMR1]
222         ldr r1, =0x00C30321
223         str r1, [r0, #CLKCTL_CSCDR1]
224
225         /* make sure divider effective */
226 1:      ldr r1, [r0, #CLKCTL_CDHIPR]
227         cmp r1, #0x0
228         bne 1b
229
230         mov r1, #0x0
231         str r1, [r0, #CLKCTL_CCDR]
232
233         /* for cko - for ARM div by 8 */
234         mov r1, #0x000A0000
235         add r1, r1, #0x00000F0
236         str r1, [r0, #CLKCTL_CCOSR]
237 .endm
238
239 .macro setup_wdog
240         ldr r0, =WDOG1_BASE_ADDR
241         mov r1, #0x30
242         strh r1, [r0]
243 .endm
244
245 .section ".text.init", "x"
246
247 .globl lowlevel_init
248 lowlevel_init:
249         ldr r0, =GPIO1_BASE_ADDR
250         ldr r1, [r0, #0x0]
251         orr r1, r1, #(1 << 23)
252         str r1, [r0, #0x0]
253         ldr r1, [r0, #0x4]
254         orr r1, r1, #(1 << 23)
255         str r1, [r0, #0x4]
256
257 #ifdef ENABLE_IMPRECISE_ABORT
258         mrs r1, spsr            /* save old spsr */
259         mrs r0, cpsr            /* read out the cpsr */
260         bic r0, r0, #0x100      /* clear the A bit */
261         msr spsr, r0            /* update spsr */
262         add lr, pc, #0x8        /* update lr */
263         movs pc, lr             /* update cpsr */
264         nop
265         nop
266         nop
267         nop
268         msr spsr, r1            /* restore old spsr */
269 #endif
270
271         init_l2cc
272
273         init_aips
274
275         init_m4if
276
277         init_clock
278
279         /* r12 saved upper lr*/
280         mov pc,lr
281
282 /* Board level setting value */
283 DDR_PERCHARGE_CMD:      .word 0x04008008
284 DDR_REFRESH_CMD:        .word 0x00008010
285 DDR_LMR1_W:             .word 0x00338018
286 DDR_LMR_CMD:            .word 0xB2220000
287 DDR_TIMING_W:           .word 0xB02567A9
288 DDR_MISC_W:             .word 0x000A0104