]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/freescale/mx51_bbg/lowlevel_init.S
imported Ka-Ro specific additions to U-Boot 2009.08 for TX28
[karo-tx-uboot.git] / board / freescale / mx51_bbg / 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-imx51.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         orrls r0, r0, #(1 << 25)    /* disable write combine for TO 2 and lower revs */
55
56         mcr 15, 1, r0, c9, c0, 2
57 .endm /* init_l2cc */
58
59 /* AIPS setup - Only setup MPROTx registers.
60  * The PACR default values are good.*/
61 .macro init_aips
62         /*
63          * Set all MPROTx to be non-bufferable, trusted for R/W,
64          * not forced to user-mode.
65          */
66         ldr r0, =AIPS1_BASE_ADDR
67         ldr r1, =0x77777777
68         str r1, [r0, #0x0]
69         str r1, [r0, #0x4]
70         ldr r0, =AIPS2_BASE_ADDR
71         str r1, [r0, #0x0]
72         str r1, [r0, #0x4]
73         /*
74          * Clear the on and off peripheral modules Supervisor Protect bit
75          * for SDMA to access them. Did not change the AIPS control registers
76          * (offset 0x20) access type
77          */
78 .endm /* init_aips */
79
80 /* MAX (Multi-Layer AHB Crossbar Switch) setup */
81 .macro init_max
82 .endm /* init_max */
83
84 /* M4IF setup */
85 .macro init_m4if
86         /* VPU and IPU given higher priority (0x4)
87          * IPU accesses with ID=0x1 given highest priority (=0xA)
88          */
89         ldr r0, =M4IF_BASE_ADDR
90
91         ldr r1, =0x00000203
92         str r1, [r0, #0x40]
93
94         ldr r1, =0x0
95         str r1, [r0, #0x44]
96
97         ldr r1, =0x00120125
98         str r1, [r0, #0x9C]
99
100         ldr r1, =0x001901A3
101         str r1, [r0, #0x48]
102
103 /*
104         ldr r1, =0x00000a01
105         str r1, [r0, #0x48]
106         ldr r1, =0x00000404
107         str r1, [r0, #0x40]
108 */
109 .endm /* init_m4if */
110
111 /* To support 133MHz DDR */
112 .macro  init_drive_strength
113 .endm /* init_drive_strength */
114
115 /* CPLD on CS5 setup */
116 .macro init_debug_board
117 .endm /* init_debug_board */
118
119 .macro setup_pll pll, freq
120         ldr r2, =\pll
121         ldr r1, =0x00001232
122         str r1, [r2, #PLL_DP_CTL] /* Set DPLL ON (set UPEN bit): BRMO=1 */
123         mov r1, #0x2
124         str r1, [r2, #PLL_DP_CONFIG] /* Enable auto-restart AREN bit */
125
126         str r3, [r2, #PLL_DP_OP]
127         str r3, [r2, #PLL_DP_HFS_OP]
128
129         str r4, [r2, #PLL_DP_MFD]
130         str r4, [r2, #PLL_DP_HFS_MFD]
131
132         str r5, [r2, #PLL_DP_MFN]
133         str r5, [r2, #PLL_DP_HFS_MFN]
134
135         ldr r1, =0x00001232
136         str r1, [r2, #PLL_DP_CTL]
137 1:      ldr r1, [r2, #PLL_DP_CTL]
138         ands r1, r1, #0x1
139         beq 1b
140 .endm
141
142 .macro init_clock
143         ldr r0, =CCM_BASE_ADDR
144
145         /* Gate of clocks to the peripherals first */
146         ldr r1, =0x3FFFFFFF
147         str r1, [r0, #CLKCTL_CCGR0]
148         ldr r1, =0x0
149         str r1, [r0, #CLKCTL_CCGR1]
150         str r1, [r0, #CLKCTL_CCGR2]
151         str r1, [r0, #CLKCTL_CCGR3]
152
153         ldr r1, =0x00030000
154         str r1, [r0, #CLKCTL_CCGR4]
155         ldr r1, =0x00FFF030
156         str r1, [r0, #CLKCTL_CCGR5]
157         ldr r1, =0x00000300
158         str r1, [r0, #CLKCTL_CCGR6]
159
160         /* Disable IPU and HSC dividers */
161         mov r1, #0x60000
162         str r1, [r0, #CLKCTL_CCDR]
163
164         /* Make sure to switch the DDR away from PLL 1 */
165         ldr r1, =0x19239145
166         str r1, [r0, #CLKCTL_CBCDR]
167         /* make sure divider effective */
168 1:      ldr r1, [r0, #CLKCTL_CDHIPR]
169         cmp r1, #0x0
170         bne 1b
171
172         /* Switch ARM to step clock */
173         mov r1, #0x4
174         str r1, [r0, #CLKCTL_CCSR]
175         mov r3, #DP_OP_800
176         mov r4, #DP_MFD_800
177         mov r5, #DP_MFN_800
178         setup_pll PLL1_BASE_ADDR
179
180         mov r3, #DP_OP_665
181         mov r4, #DP_MFD_665
182         mov r5, #DP_MFN_665
183         setup_pll PLL3_BASE_ADDR
184
185         /* Switch peripheral to PLL 3 */
186         ldr r0, =CCM_BASE_ADDR
187         ldr r1, =0x000010C0
188         str r1, [r0, #CLKCTL_CBCMR]
189         ldr r1, =0x13239145
190         str r1, [r0, #CLKCTL_CBCDR]
191         mov r3, #DP_OP_665
192         mov r4, #DP_MFD_665
193         mov r5, #DP_MFN_665
194         setup_pll PLL2_BASE_ADDR
195
196         /* Switch peripheral to PLL2 */
197         ldr r0, =CCM_BASE_ADDR
198         ldr r1, =0x19239145
199         str r1, [r0, #CLKCTL_CBCDR]
200         ldr r1, =0x000020C0
201         str r1, [r0, #CLKCTL_CBCMR]
202
203         mov r3, #DP_OP_216
204         mov r4, #DP_MFD_216
205         mov r5, #DP_MFN_216
206         setup_pll PLL3_BASE_ADDR
207
208
209         /* Set the platform clock dividers */
210         ldr r0, =ARM_BASE_ADDR
211         ldr r1, =0x00000725
212         str r1, [r0, #0x14]
213
214         ldr r0, =CCM_BASE_ADDR
215         /* Run TO 3.0 at Full speed, for other TO's wait till we increase VDDGP */
216         ldr r1, =0x0
217         ldr r3, [r1, #ROM_SI_REV]
218         cmp r3, #0x10
219         movls r1, #0x1
220         movhi r1, #0
221         str r1, [r0, #CLKCTL_CACRR]
222
223         /* Switch ARM back to PLL 1 */
224         mov r1, #0
225         str r1, [r0, #CLKCTL_CCSR]
226
227         /* setup the rest */
228         /* Use lp_apm (24MHz) source for perclk */
229         ldr r1, =0x000020C2
230         str r1, [r0, #CLKCTL_CBCMR]
231         /* ddr clock from PLL 1, all perclk dividers are 1 since using 24MHz */
232         ldr r1, =0x59E35100
233         str r1, [r0, #CLKCTL_CBCDR]
234
235         /* Restore the default values in the Gate registers */
236         ldr r1, =0xFFFFFFFF
237         str r1, [r0, #CLKCTL_CCGR0]
238         str r1, [r0, #CLKCTL_CCGR1]
239         str r1, [r0, #CLKCTL_CCGR2]
240         str r1, [r0, #CLKCTL_CCGR3]
241         str r1, [r0, #CLKCTL_CCGR4]
242         str r1, [r0, #CLKCTL_CCGR5]
243         str r1, [r0, #CLKCTL_CCGR6]
244
245         /* Use PLL 2 for UART's, get 66.5MHz from it */
246         ldr r1, =0xA5A2A020
247         str r1, [r0, #CLKCTL_CSCMR1]
248         ldr r1, =0x00C30321
249         str r1, [r0, #CLKCTL_CSCDR1]
250
251         /* make sure divider effective */
252 1:      ldr r1, [r0, #CLKCTL_CDHIPR]
253         cmp r1, #0x0
254         bne 1b
255
256         mov r1, #0x0
257         str r1, [r0, #CLKCTL_CCDR]
258
259         /* for cko - for ARM div by 8 */
260         mov r1, #0x000A0000
261         add r1, r1, #0x00000F0
262         str r1, [r0, #CLKCTL_CCOSR]
263 .endm
264
265 .macro setup_wdog
266         ldr r0, =WDOG1_BASE_ADDR
267         mov r1, #0x30
268         strh r1, [r0]
269 .endm
270
271 .section ".text.init", "x"
272
273 .globl lowlevel_init
274 lowlevel_init:
275         ldr r0, =GPIO1_BASE_ADDR
276         ldr r1, [r0, #0x0]
277         orr r1, r1, #(1 << 23)
278         str r1, [r0, #0x0]
279         ldr r1, [r0, #0x4]
280         orr r1, r1, #(1 << 23)
281         str r1, [r0, #0x4]
282
283 #ifdef ENABLE_IMPRECISE_ABORT
284         mrs r1, spsr            /* save old spsr */
285         mrs r0, cpsr            /* read out the cpsr */
286         bic r0, r0, #0x100      /* clear the A bit */
287         msr spsr, r0            /* update spsr */
288         add lr, pc, #0x8        /* update lr */
289         movs pc, lr             /* update cpsr */
290         nop
291         nop
292         nop
293         nop
294         msr spsr, r1            /* restore old spsr */
295 #endif
296
297         /* ARM errata ID #468414 */
298         mrc 15, 0, r1, c1, c0, 1
299         orr r1, r1, #(1 << 5)    /* enable L1NEON bit */
300         mcr 15, 0, r1, c1, c0, 1
301
302         init_l2cc
303
304         init_aips
305
306         init_max
307
308         init_m4if
309
310         init_drive_strength
311
312         init_clock
313
314         init_debug_board
315
316         /* return from mxc_nand_load */
317         /* r12 saved upper lr*/
318         b mxc_nand_load
319
320 /* Board level setting value */
321 DDR_PERCHARGE_CMD:      .word 0x04008008
322 DDR_REFRESH_CMD:        .word 0x00008010
323 DDR_LMR1_W:             .word 0x00338018
324 DDR_LMR_CMD:            .word 0xB2220000
325 DDR_TIMING_W:           .word 0xB02567A9
326 DDR_MISC_W:             .word 0x000A0104