move boards to arch/<architecure>/boards
[barebox-mini2440.git] / arch / arm / boards / imx21ads / lowlevel_init.S
blob607da274761f12b7a85badb866a5a5f541f46c8a
1 /*
2  * Copyright (C) 2010 Jaccon Bastiaansen <jaccon.bastiaansen@gmail.com>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
17  * MA 02111-1307 USA
18  */
20 #include <config.h>
21 #include <mach/imx-regs.h>
23         .section ".text_bare_init","ax"
25 .globl board_init_lowlevel
26 board_init_lowlevel:
28 /* Save lr, because it is overwritten by the calls to mem_delay. */
29         mov     r10, lr
32  * Initialize the AHB-Lite IP Interface (AIPI) module (to enable access to
33  * on chip peripherals) as described in section 7.2 of rev3 of the i.MX21
34  * reference manual.
35  */
36         ldr     r0, =AIPI1_PSR0
37         ldr     r1, =0x00040304
38         str     r1, [r0]
39         ldr     r0, =AIPI1_PSR1
40         ldr     r1, =0xfffbfcfb
41         str     r1, [r0]
43         ldr     r0, =AIPI2_PSR0
44         ldr     r1, =0x3ffc0000
45         str     r1, [r0]
46         ldr     r0, =AIPI2_PSR1
47         ldr     r1, =0xffffffff
48         str     r1, [r0]
51  * Configure CPU core clock (266MHz), peripheral clock (133MHz) and enable
52  * the clock to peripherals.
53  */
54         ldr     r0, =CSCR
55         ldr     r1, =0x17180607
56         str     r1, [r0]
58         ldr     r0, =PCCR1
59         ldr     r1, =0x0e000000
60         str     r1, [r0]
64  * SDRAM and SDRAM controller configuration
65  */
67         /*
68          * CSD1 not required, because the MX21ADS board only contains 64Mbyte.
69          * CS3 can therefore be made available.
70          */
71         ldr     r0, =FMCR
72         ldr     r1, =0xffffffc9
73         str     r1, [r0]
75         /* Skip SDRAM initialization if we run from RAM */
76         cmp     pc, #0xc0000000
77         bls     1f
78         cmp     pc, #0xc8000000
79         bhi     1f
81         mov     pc, r10
84         /* Precharge */
85         ldr     r0, =SDCTL0
86         ldr     r1, =0x92120300
87         str     r1, [r0]
88         ldr     r2, =0xc0200000
89         ldr     r1, [r2]
91         bl      mem_delay
93         /* Auto refresh */
94         ldr     r1, =0xa2120300
95         str     r1, [r0]
96         ldr     r2, =0xc0000000
97         ldr     r1, [r2]
98         ldr     r1, [r2]
99         ldr     r1, [r2]
100         ldr     r1, [r2]
101         ldr     r1, [r2]
102         ldr     r1, [r2]
103         ldr     r1, [r2]
104         ldr     r1, [r2]
106         /* Set mode register */
107         ldr     r1, =0xB2120300
108         str     r1, [r0]
109         ldr     r1, =0xC0119800
110         ldr     r2, [r1]
112         bl      mem_delay
114         /* Back to Normal Mode */
115         ldr     r1, =0x8212F339
116         str     r1, [r0]
118         /* Set NFC_CLK to 24MHz */
119         ldr     r0, =PCDR0
120         ldr     r1, =0x6419a007
121         str     r1, [r0]
123 #ifdef CONFIG_NAND_IMX_BOOT
124         ldr     sp, =TEXT_BASE - 4      /* Setup a temporary stack in SDRAM */
126         ldr     r0, =IMX_NFC_BASE               /* start of NFC SRAM        */
127         ldr     r2, =IMX_NFC_BASE + 0x800       /* end of NFC SRAM          */
129         /* skip NAND boot if not running from NFC space */
130         cmp     pc, r0
131         bls     ret
132         cmp     pc, r2
133         bhi     ret
135         /* Move ourselves out of NFC SRAM */
136         ldr     r1, =TEXT_BASE
138 copy_loop:
139         ldmia   r0!, {r3-r9}            /* copy from source address [r0]    */
140         stmia   r1!, {r3-r9}            /* copy to   target address [r1]    */
141         cmp     r0, r2                  /* until source end addreee [r2]    */
142         ble     copy_loop
144         ldr     pc, =1f                 /* Jump to SDRAM                    */
146         bl      nand_boot               /* Load barebox from NAND Flash     */
148         ldr     r1, =IMX_NFC_BASE - TEXT_BASE
149         sub     r10, r10, r1            /* adjust return address from NFC   */
150                                         /* SRAM to SDRAM                    */
151 #endif /* CONFIG_NAND_IMX_BOOT */
153 ret:
154         mov     pc, r10
157  *  spin for a while.  we need to wait at least 200 usecs.
158  */
159 mem_delay:
160         mov     r4, #0x4000
161 spin:   subs    r4, r4, #1
162         bne     spin
163         mov     pc, lr