blob: 0d94ab60a66569326a9256880d6c595885c0ae73 [file] [log] [blame]
wdenkca0e7742004-06-09 15:37:23 +00001#include <config.h>
2#include <version.h>
3#include <asm/arch/pxa-regs.h>
4
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02005DRAM_SIZE: .long CONFIG_SYS_DRAM_SIZE
wdenkca0e7742004-06-09 15:37:23 +00006
wdenk400558b2005-04-02 23:52:25 +00007.globl lowlevel_init
8lowlevel_init:
wdenkca0e7742004-06-09 15:37:23 +00009
10 mov r10, lr
11
12/* ---- GPIO INITIALISATION ---- */
13/* Set up GPIO pins first (3 groups [31:0] [63:32] [80:64]) */
14
15 /* General purpose set registers */
16 ldr r0, =GPSR0
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020017 ldr r1, =CONFIG_SYS_GPSR0_VAL
wdenkca0e7742004-06-09 15:37:23 +000018 str r1, [r0]
19 ldr r0, =GPSR1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020020 ldr r1, =CONFIG_SYS_GPSR1_VAL
wdenkca0e7742004-06-09 15:37:23 +000021 str r1, [r0]
22 ldr r0, =GPSR2
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020023 ldr r1, =CONFIG_SYS_GPSR2_VAL
wdenkca0e7742004-06-09 15:37:23 +000024 str r1, [r0]
25
26 /* General purpose clear registers */
27 ldr r0, =GPCR0
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020028 ldr r1, =CONFIG_SYS_GPCR0_VAL
wdenkca0e7742004-06-09 15:37:23 +000029 str r1, [r0]
30 ldr r0, =GPCR1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020031 ldr r1, =CONFIG_SYS_GPCR1_VAL
wdenkca0e7742004-06-09 15:37:23 +000032 str r1, [r0]
33 ldr r0, =GPCR2
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020034 ldr r1, =CONFIG_SYS_GPCR2_VAL
wdenkca0e7742004-06-09 15:37:23 +000035 str r1, [r0]
36
37 /* General rising edge registers */
38 ldr r0, =GRER0
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020039 ldr r1, =CONFIG_SYS_GRER0_VAL
wdenkca0e7742004-06-09 15:37:23 +000040 str r1, [r0]
41 ldr r0, =GRER1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020042 ldr r1, =CONFIG_SYS_GRER1_VAL
wdenkca0e7742004-06-09 15:37:23 +000043 str r1, [r0]
44 ldr r0, =GRER2
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020045 ldr r1, =CONFIG_SYS_GRER2_VAL
wdenkca0e7742004-06-09 15:37:23 +000046 str r1, [r0]
47
48 /* General falling edge registers */
49 ldr r0, =GFER0
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020050 ldr r1, =CONFIG_SYS_GFER0_VAL
wdenkca0e7742004-06-09 15:37:23 +000051 str r1, [r0]
52 ldr r0, =GFER1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020053 ldr r1, =CONFIG_SYS_GFER1_VAL
wdenkca0e7742004-06-09 15:37:23 +000054 str r1, [r0]
55 ldr r0, =GFER2
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020056 ldr r1, =CONFIG_SYS_GFER2_VAL
wdenkca0e7742004-06-09 15:37:23 +000057 str r1, [r0]
58
59 /* General edge detect registers */
60 ldr r0, =GPDR0
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020061 ldr r1, =CONFIG_SYS_GPDR0_VAL
wdenkca0e7742004-06-09 15:37:23 +000062 str r1, [r0]
63 ldr r0, =GPDR1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020064 ldr r1, =CONFIG_SYS_GPDR1_VAL
wdenkca0e7742004-06-09 15:37:23 +000065 str r1, [r0]
66 ldr r0, =GPDR2
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020067 ldr r1, =CONFIG_SYS_GPDR2_VAL
wdenkca0e7742004-06-09 15:37:23 +000068 str r1, [r0]
69
70 /* General alternate function registers */
71 ldr r0, =GAFR0_L /* [0:15] */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020072 ldr r1, =CONFIG_SYS_GAFR0_L_VAL
wdenkca0e7742004-06-09 15:37:23 +000073 str r1, [r0]
74 ldr r0, =GAFR0_U /* [31:16] */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020075 ldr r1, =CONFIG_SYS_GAFR0_U_VAL
wdenkca0e7742004-06-09 15:37:23 +000076 str r1, [r0]
77 ldr r0, =GAFR1_L /* [47:32] */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020078 ldr r1, =CONFIG_SYS_GAFR1_L_VAL
wdenkca0e7742004-06-09 15:37:23 +000079 str r1, [r0]
80 ldr r0, =GAFR1_U /* [63:48] */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020081 ldr r1, =CONFIG_SYS_GAFR1_U_VAL
wdenkca0e7742004-06-09 15:37:23 +000082 str r1, [r0]
83 ldr r0, =GAFR2_L /* [79:64] */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020084 ldr r1, =CONFIG_SYS_GAFR2_L_VAL
wdenkca0e7742004-06-09 15:37:23 +000085 str r1, [r0]
86 ldr r0, =GAFR2_U /* [80] */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020087 ldr r1, =CONFIG_SYS_GAFR2_U_VAL
wdenkca0e7742004-06-09 15:37:23 +000088 str r1, [r0]
89
90 /* General purpose direction registers */
91 ldr r0, =GPDR0
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020092 ldr r1, =CONFIG_SYS_GPDR0_VAL
wdenkca0e7742004-06-09 15:37:23 +000093 str r1, [r0]
94 ldr r0, =GPDR1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020095 ldr r1, =CONFIG_SYS_GPDR1_VAL
wdenkca0e7742004-06-09 15:37:23 +000096 str r1, [r0]
97 ldr r0, =GPDR2
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020098 ldr r1, =CONFIG_SYS_GPDR2_VAL
wdenkca0e7742004-06-09 15:37:23 +000099 str r1, [r0]
100
101 /* Power manager sleep status */
102 ldr r0, =PSSR
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200103 ldr r1, =CONFIG_SYS_PSSR_VAL
wdenkca0e7742004-06-09 15:37:23 +0000104 str r1, [r0]
105
106/* ---- MEMORY INITIALISATION ---- */
107/* Initialize Memory Controller, see PXA250 Operating System Developer's Guide */
108/* pause for 200 uSecs- allow internal clocks to settle */
109 ldr r3, =OSCR /* reset the OS Timer Count to zero */
110 mov r2, #0
111 str r2, [r3]
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200112 ldr r4, =0x300 /* really 0x2E1 is about 200usec, so 0x300 should be plenty */
wdenkca0e7742004-06-09 15:37:23 +00001131:
114 ldr r2, [r3]
115 cmp r4, r2
116 bgt 1b
117
118mem_init:
119/* get memory controller base address */
120 ldr r1, =MEMC_BASE
121
122/* ---- FLASH INITIALISATION ---- */
123/* Write MSC0 and read back to ensure data change is accepted by cpu */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200124 ldr r2, =CONFIG_SYS_MSC0_VAL
wdenkca0e7742004-06-09 15:37:23 +0000125 str r2, [r1, #MSC0_OFFSET]
126 ldr r2, [r1, #MSC0_OFFSET]
127
128/* ---- SDRAM INITIALISATION ---- */
129/* get the MDREFR settings */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200130 ldr r2, =CONFIG_SYS_MDREFR_VAL
wdenkca0e7742004-06-09 15:37:23 +0000131 str r2, [r1, #MDREFR_OFFSET]
132
133/* fetch platform value of MDCNFG */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200134 ldr r2, =CONFIG_SYS_MDCNFG_VAL
wdenkca0e7742004-06-09 15:37:23 +0000135
136/* disable all sdram banks */
137 bic r2, r2, #(MDCNFG_DE0 | MDCNFG_DE1)
138 bic r2, r2, #(MDCNFG_DE2 | MDCNFG_DE3)
139
140/* write initial value of MDCNFG, w/o enabling sdram banks */
141 str r2, [r1, #MDCNFG_OFFSET]
142
143/* pause for 200 uSecs */
144 ldr r3, =OSCR /* reset the OS Timer Count to zero */
145 mov r2, #0
146 str r2, [r3]
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200147 ldr r4, =0x300 /* about 200 usec */
wdenkca0e7742004-06-09 15:37:23 +00001481:
149 ldr r2, [r3]
150 cmp r4, r2
151 bgt 1b
152
153/* Access memory *not yet enabled* for CBR refresh cycles (8) */
154/* CBR is generated for all banks */
155
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200156 ldr r2, =CONFIG_SYS_DRAM_BASE
wdenkca0e7742004-06-09 15:37:23 +0000157 str r2, [r2]
158 str r2, [r2]
159 str r2, [r2]
160 str r2, [r2]
161 str r2, [r2]
162 str r2, [r2]
163 str r2, [r2]
164 str r2, [r2]
165
166/* get memory controller base address */
167 ldr r2, =MEMC_BASE
168
169/* Enable SDRAM bank 0 in MDCNFG register */
170 ldr r2, [r1, #MDCNFG_OFFSET]
171 orr r2, r2, #MDCNFG_DE0
172 str r2, [r1, #MDCNFG_OFFSET]
173
174/* write MDMRS to trigger an MSR command to all enabled SDRAM banks */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200175 ldr r2, =CONFIG_SYS_MDMRS_VAL
wdenkca0e7742004-06-09 15:37:23 +0000176 str r2, [r1, #MDMRS_OFFSET]
177
178/* ---- INTERRUPT INITIALISATION ---- */
179/* Disable (mask) all interrupts at the interrupt controller */
180/* clear the interrupt level register (use IRQ, not FIQ) */
181 mov r1, #0
182 ldr r2, =ICLR
183 str r1, [r2]
184
185/* Set interrupt mask register */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200186 ldr r1, =CONFIG_SYS_ICMR_VAL
wdenkca0e7742004-06-09 15:37:23 +0000187 ldr r2, =ICMR
188 str r1, [r2]
189
190/* ---- CLOCK INITIALISATION ---- */
191/* Disable the peripheral clocks, and set the core clock */
192
193/* Turn Off ALL on-chip peripheral clocks for re-configuration */
194 ldr r1, =CKEN
195 mov r2, #0
196 str r2, [r1]
197
198/* set core clocks */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200199 ldr r2, =CONFIG_SYS_CCCR_VAL
wdenkca0e7742004-06-09 15:37:23 +0000200 ldr r1, =CCCR
201 str r2, [r1]
202
203#ifdef ENABLE32KHZ
204/* enable the 32Khz oscillator for RTC and PowerManager */
205 ldr r1, =OSCC
206 mov r2, #OSCC_OON
207 str r2, [r1]
208
209/* NOTE: spin here until OSCC.OOK get set, meaning the PLL has settled. */
21060:
211 ldr r2, [r1]
212 ands r2, r2, #1
213 beq 60b
214#endif
215
216/* Turn on needed clocks */
217 ldr r1, =CKEN
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200218 ldr r2, =CONFIG_SYS_CKEN_VAL
wdenkca0e7742004-06-09 15:37:23 +0000219 str r2, [r1]
220
221 mov pc, r10