2 * Memory Setup stuff - taken from blob memsetup.S
4 * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl) and
5 * Jan-Derk Bakker (J.D.Bakker@its.tudelft.nl)
7 * Copyright (C) 2008 Ronetix Ilko Iliev (www.ronetix.at)
8 * Copyright (C) 2009 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
10 * See file CREDITS for list of people who contributed to this
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 #include <asm/arch/hardware.h>
31 #include <asm/arch/at91_pmc.h>
32 #include <asm/arch/at91_wdt.h>
33 #include <asm/arch/at91_pio.h>
34 #include <asm/arch/at91_matrix.h>
35 #include <asm/arch/at91sam9_sdramc.h>
36 #include <asm/arch/at91sam9_smc.h>
37 #include <asm/arch/at91_rstc.h>
38 #ifdef CONFIG_AT91_LEGACY
39 #include <asm/arch/at91sam9_matrix.h>
41 #ifndef CONFIG_SYS_MATRIX_EBICSA_VAL
42 #define CONFIG_SYS_MATRIX_EBICSA_VAL CONFIG_SYS_MATRIX_EBI0CSA_VAL
46 .word CONFIG_SYS_TEXT_BASE
49 .type lowlevel_init,function
52 mov r5, pc /* r5 = POS1 + 4 current */
54 ldr r0, =POS1 /* r0 = POS1 compile */
56 sub r0, r0, r2 /* r0 = POS1-_TEXT_BASE (POS1 relative) */
57 sub r5, r5, r0 /* r0 = CONFIG_SYS_TEXT_BASE-1 */
58 sub r5, r5, #4 /* r1 = text base - current */
60 /* memory control configuration 1 */
77 /* ----------------------------------------------------------------------------
79 * ----------------------------------------------------------------------------
80 * - Check if the PLL is already initialized
81 * ----------------------------------------------------------------------------
83 ldr r1, =(AT91_ASM_PMC_MCKR)
89 /* ---------------------------------------------------------------------------
90 * - Enable the Main Oscillator
91 * ---------------------------------------------------------------------------
93 ldr r1, =(AT91_ASM_PMC_MOR)
94 ldr r2, =(AT91_ASM_PMC_SR)
95 /* Main oscillator Enable register PMC_MOR: */
96 ldr r0, =CONFIG_SYS_MOR_VAL
99 /* Reading the PMC Status to detect when the Main Oscillator is enabled */
100 mov r4, #AT91_PMC_IXR_MOSCS
104 cmp r3, #AT91_PMC_IXR_MOSCS
107 /* ----------------------------------------------------------------------------
109 * ----------------------------------------------------------------------------
111 * ----------------------------------------------------------------------------
113 ldr r1, =(AT91_ASM_PMC_PLLAR)
114 ldr r0, =CONFIG_SYS_PLLAR_VAL
117 /* Reading the PMC Status register to detect when the PLLA is locked */
118 mov r4, #AT91_PMC_IXR_LOCKA
122 cmp r3, #AT91_PMC_IXR_LOCKA
125 /* ----------------------------------------------------------------------------
127 * ----------------------------------------------------------------------------
128 * - Switch on the Main Oscillator
129 * ----------------------------------------------------------------------------
131 ldr r1, =(AT91_ASM_PMC_MCKR)
133 /* -Master Clock Controller register PMC_MCKR */
134 ldr r0, =CONFIG_SYS_MCKR1_VAL
137 /* Reading the PMC Status to detect when the Master clock is ready */
138 mov r4, #AT91_PMC_IXR_MCKRDY
142 cmp r3, #AT91_PMC_IXR_MCKRDY
145 ldr r0, =CONFIG_SYS_MCKR2_VAL
148 /* Reading the PMC Status to detect when the Master clock is ready */
149 mov r4, #AT91_PMC_IXR_MCKRDY
153 cmp r3, #AT91_PMC_IXR_MCKRDY
157 /* ----------------------------------------------------------------------------
158 * - memory control configuration 2
159 * ----------------------------------------------------------------------------
161 ldr r0, =(AT91_ASM_SDRAMC_TR)
183 /* everything is fine now */
189 .word AT91_ASM_WDT_MR
190 .word CONFIG_SYS_WDTC_WDMR_VAL
191 /* configure PIOx as EBI0 D[16-31] */
192 #if defined(CONFIG_AT91SAM9263)
193 .word AT91_ASM_PIOD_PDR
194 .word CONFIG_SYS_PIOD_PDR_VAL1
195 .word AT91_ASM_PIOD_PUDR
196 .word CONFIG_SYS_PIOD_PPUDR_VAL
197 .word AT91_ASM_PIOD_ASR
198 .word CONFIG_SYS_PIOD_PPUDR_VAL
199 #elif defined(CONFIG_AT91SAM9260) || defined(CONFIG_AT91SAM9261) \
200 || defined(CONFIG_AT91SAM9G20)
201 .word AT91_ASM_PIOC_PDR
202 .word CONFIG_SYS_PIOC_PDR_VAL1
203 .word AT91_ASM_PIOC_PUDR
204 .word CONFIG_SYS_PIOC_PPUDR_VAL
206 .word AT91_ASM_MATRIX_CSA0
207 .word CONFIG_SYS_MATRIX_EBICSA_VAL
210 .word AT91_ASM_SMC_MODE0
211 .word CONFIG_SYS_SMC0_MODE0_VAL
213 .word AT91_ASM_SMC_CYCLE0
214 .word CONFIG_SYS_SMC0_CYCLE0_VAL
216 .word AT91_ASM_SMC_PULSE0
217 .word CONFIG_SYS_SMC0_PULSE0_VAL
219 .word AT91_ASM_SMC_SETUP0
220 .word CONFIG_SYS_SMC0_SETUP0_VAL
223 .word AT91_ASM_SDRAMC_MR
224 .word CONFIG_SYS_SDRC_MR_VAL1
225 .word AT91_ASM_SDRAMC_TR
226 .word CONFIG_SYS_SDRC_TR_VAL1
227 .word AT91_ASM_SDRAMC_CR
228 .word CONFIG_SYS_SDRC_CR_VAL
229 .word AT91_ASM_SDRAMC_MDR
230 .word CONFIG_SYS_SDRC_MDR_VAL
231 .word AT91_ASM_SDRAMC_MR
232 .word CONFIG_SYS_SDRC_MR_VAL2
233 .word CONFIG_SYS_SDRAM_BASE
234 .word CONFIG_SYS_SDRAM_VAL1
235 .word AT91_ASM_SDRAMC_MR
236 .word CONFIG_SYS_SDRC_MR_VAL3
237 .word CONFIG_SYS_SDRAM_BASE
238 .word CONFIG_SYS_SDRAM_VAL2
239 .word CONFIG_SYS_SDRAM_BASE
240 .word CONFIG_SYS_SDRAM_VAL3
241 .word CONFIG_SYS_SDRAM_BASE
242 .word CONFIG_SYS_SDRAM_VAL4
243 .word CONFIG_SYS_SDRAM_BASE
244 .word CONFIG_SYS_SDRAM_VAL5
245 .word CONFIG_SYS_SDRAM_BASE
246 .word CONFIG_SYS_SDRAM_VAL6
247 .word CONFIG_SYS_SDRAM_BASE
248 .word CONFIG_SYS_SDRAM_VAL7
249 .word CONFIG_SYS_SDRAM_BASE
250 .word CONFIG_SYS_SDRAM_VAL8
251 .word CONFIG_SYS_SDRAM_BASE
252 .word CONFIG_SYS_SDRAM_VAL9
253 .word AT91_ASM_SDRAMC_MR
254 .word CONFIG_SYS_SDRC_MR_VAL4
255 .word CONFIG_SYS_SDRAM_BASE
256 .word CONFIG_SYS_SDRAM_VAL10
257 .word AT91_ASM_SDRAMC_MR
258 .word CONFIG_SYS_SDRC_MR_VAL5
259 .word CONFIG_SYS_SDRAM_BASE
260 .word CONFIG_SYS_SDRAM_VAL11
261 .word AT91_ASM_SDRAMC_TR
262 .word CONFIG_SYS_SDRC_TR_VAL2
263 .word CONFIG_SYS_SDRAM_BASE
264 .word CONFIG_SYS_SDRAM_VAL12
265 /* User reset enable*/
266 .word AT91_ASM_RSTC_MR
267 .word CONFIG_SYS_RSTC_RMR_VAL
268 #ifdef CONFIG_SYS_MATRIX_MCFG_REMAP
269 /* MATRIX_MCFG - REMAP all masters */
270 .word AT91_ASM_MATRIX_MCFG