blob: 39de2f4904381c65baaa948ac31f9f81562e5985 [file] [log] [blame]
Ilko Iliev8b954a92009-04-16 21:30:48 +02001/*
2 * Memory Setup stuff - taken from blob memsetup.S
3 *
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)
6 *
7 * Copyright (C) 2008 Ronetix Ilko Iliev (www.ronetix.at)
8 * Copyright (C) 2009 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
9 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
Ilko Iliev8b954a92009-04-16 21:30:48 +020011 */
12
13#include <config.h>
Ilko Iliev8b954a92009-04-16 21:30:48 +020014#include <asm/arch/hardware.h>
15#include <asm/arch/at91_pmc.h>
Ilko Iliev8b954a92009-04-16 21:30:48 +020016#include <asm/arch/at91_wdt.h>
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010017#include <asm/arch/at91_pio.h>
18#include <asm/arch/at91_matrix.h>
Ilko Iliev8b954a92009-04-16 21:30:48 +020019#include <asm/arch/at91sam9_sdramc.h>
20#include <asm/arch/at91sam9_smc.h>
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010021#include <asm/arch/at91_rstc.h>
Xu, Hong4fae89c2011-06-10 21:31:25 +000022#ifdef CONFIG_ATMEL_LEGACY
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010023#include <asm/arch/at91sam9_matrix.h>
24#endif
25#ifndef CONFIG_SYS_MATRIX_EBICSA_VAL
26#define CONFIG_SYS_MATRIX_EBICSA_VAL CONFIG_SYS_MATRIX_EBI0CSA_VAL
27#endif
Ilko Iliev8b954a92009-04-16 21:30:48 +020028
29_TEXT_BASE:
Wolfgang Denk0708bc62010-10-07 21:51:12 +020030 .word CONFIG_SYS_TEXT_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +020031
32.globl lowlevel_init
33.type lowlevel_init,function
34lowlevel_init:
35
36 mov r5, pc /* r5 = POS1 + 4 current */
37POS1:
38 ldr r0, =POS1 /* r0 = POS1 compile */
39 ldr r2, _TEXT_BASE
40 sub r0, r0, r2 /* r0 = POS1-_TEXT_BASE (POS1 relative) */
Wolfgang Denk0708bc62010-10-07 21:51:12 +020041 sub r5, r5, r0 /* r0 = CONFIG_SYS_TEXT_BASE-1 */
Ilko Iliev8b954a92009-04-16 21:30:48 +020042 sub r5, r5, #4 /* r1 = text base - current */
43
44 /* memory control configuration 1 */
45 ldr r0, =SMRDATA
46 ldr r2, =SMRDATA1
47 ldr r1, _TEXT_BASE
48 sub r0, r0, r1
49 sub r2, r2, r1
50 add r0, r0, r5
51 add r2, r2, r5
520:
53 /* the address */
54 ldr r1, [r0], #4
55 /* the value */
56 ldr r3, [r0], #4
57 str r3, [r1]
58 cmp r2, r0
59 bne 0b
60
61/* ----------------------------------------------------------------------------
62 * PMC Init Step 1.
63 * ----------------------------------------------------------------------------
64 * - Check if the PLL is already initialized
65 * ----------------------------------------------------------------------------
66 */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010067 ldr r1, =(AT91_ASM_PMC_MCKR)
Ilko Iliev8b954a92009-04-16 21:30:48 +020068 ldr r0, [r1]
69 and r0, r0, #3
70 cmp r0, #0
71 bne PLL_setup_end
72
73/* ---------------------------------------------------------------------------
74 * - Enable the Main Oscillator
75 * ---------------------------------------------------------------------------
76 */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010077 ldr r1, =(AT91_ASM_PMC_MOR)
78 ldr r2, =(AT91_ASM_PMC_SR)
Jean-Christophe PLAGNIOL-VILLARDe32eb4c2009-06-13 12:50:04 +020079 /* Main oscillator Enable register PMC_MOR: */
Jean-Christophe PLAGNIOL-VILLARD0ae32d92009-06-12 21:20:38 +020080 ldr r0, =CONFIG_SYS_MOR_VAL
Jean-Christophe PLAGNIOL-VILLARDe32eb4c2009-06-13 12:50:04 +020081 str r0, [r1]
Ilko Iliev8b954a92009-04-16 21:30:48 +020082
83 /* Reading the PMC Status to detect when the Main Oscillator is enabled */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010084 mov r4, #AT91_PMC_IXR_MOSCS
Ilko Iliev8b954a92009-04-16 21:30:48 +020085MOSCS_Loop:
86 ldr r3, [r2]
87 and r3, r4, r3
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010088 cmp r3, #AT91_PMC_IXR_MOSCS
Ilko Iliev8b954a92009-04-16 21:30:48 +020089 bne MOSCS_Loop
90
91/* ----------------------------------------------------------------------------
92 * PMC Init Step 2.
93 * ----------------------------------------------------------------------------
94 * Setup PLLA
95 * ----------------------------------------------------------------------------
96 */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010097 ldr r1, =(AT91_ASM_PMC_PLLAR)
Ilko Iliev8b954a92009-04-16 21:30:48 +020098 ldr r0, =CONFIG_SYS_PLLAR_VAL
99 str r0, [r1]
100
101 /* Reading the PMC Status register to detect when the PLLA is locked */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100102 mov r4, #AT91_PMC_IXR_LOCKA
Ilko Iliev8b954a92009-04-16 21:30:48 +0200103MOSCS_Loop1:
104 ldr r3, [r2]
105 and r3, r4, r3
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100106 cmp r3, #AT91_PMC_IXR_LOCKA
Ilko Iliev8b954a92009-04-16 21:30:48 +0200107 bne MOSCS_Loop1
108
109/* ----------------------------------------------------------------------------
110 * PMC Init Step 3.
111 * ----------------------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARDe32eb4c2009-06-13 12:50:04 +0200112 * - Switch on the Main Oscillator
Ilko Iliev8b954a92009-04-16 21:30:48 +0200113 * ----------------------------------------------------------------------------
114 */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100115 ldr r1, =(AT91_ASM_PMC_MCKR)
Ilko Iliev8b954a92009-04-16 21:30:48 +0200116
117 /* -Master Clock Controller register PMC_MCKR */
118 ldr r0, =CONFIG_SYS_MCKR1_VAL
119 str r0, [r1]
120
121 /* Reading the PMC Status to detect when the Master clock is ready */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100122 mov r4, #AT91_PMC_IXR_MCKRDY
Ilko Iliev8b954a92009-04-16 21:30:48 +0200123MCKRDY_Loop:
124 ldr r3, [r2]
125 and r3, r4, r3
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100126 cmp r3, #AT91_PMC_IXR_MCKRDY
Ilko Iliev8b954a92009-04-16 21:30:48 +0200127 bne MCKRDY_Loop
128
129 ldr r0, =CONFIG_SYS_MCKR2_VAL
130 str r0, [r1]
131
132 /* Reading the PMC Status to detect when the Master clock is ready */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100133 mov r4, #AT91_PMC_IXR_MCKRDY
Ilko Iliev8b954a92009-04-16 21:30:48 +0200134MCKRDY_Loop1:
135 ldr r3, [r2]
136 and r3, r4, r3
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100137 cmp r3, #AT91_PMC_IXR_MCKRDY
Ilko Iliev8b954a92009-04-16 21:30:48 +0200138 bne MCKRDY_Loop1
Ilko Iliev8b954a92009-04-16 21:30:48 +0200139PLL_setup_end:
140
141/* ----------------------------------------------------------------------------
142 * - memory control configuration 2
143 * ----------------------------------------------------------------------------
144 */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100145 ldr r0, =(AT91_ASM_SDRAMC_TR)
Ilko Iliev8b954a92009-04-16 21:30:48 +0200146 ldr r1, [r0]
147 cmp r1, #0
148 bne SDRAM_setup_end
149
150 ldr r0, =SMRDATA1
151 ldr r2, =SMRDATA2
152 ldr r1, _TEXT_BASE
153 sub r0, r0, r1
154 sub r2, r2, r1
155 add r0, r0, r5
156 add r2, r2, r5
Ilko Iliev8b954a92009-04-16 21:30:48 +02001572:
158 /* the address */
159 ldr r1, [r0], #4
160 /* the value */
161 ldr r3, [r0], #4
162 str r3, [r1]
163 cmp r2, r0
164 bne 2b
165
166SDRAM_setup_end:
167 /* everything is fine now */
168 mov pc, lr
169
170 .ltorg
171
172SMRDATA:
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100173 .word AT91_ASM_WDT_MR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200174 .word CONFIG_SYS_WDTC_WDMR_VAL
Jean-Christophe PLAGNIOL-VILLARDe32eb4c2009-06-13 12:50:04 +0200175 /* configure PIOx as EBI0 D[16-31] */
176#if defined(CONFIG_AT91SAM9263)
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100177 .word AT91_ASM_PIOD_PDR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200178 .word CONFIG_SYS_PIOD_PDR_VAL1
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100179 .word AT91_ASM_PIOD_PUDR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200180 .word CONFIG_SYS_PIOD_PPUDR_VAL
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100181 .word AT91_ASM_PIOD_ASR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200182 .word CONFIG_SYS_PIOD_PPUDR_VAL
Tom Rix799a05b2009-09-27 11:10:09 -0500183#elif defined(CONFIG_AT91SAM9260) || defined(CONFIG_AT91SAM9261) \
184 || defined(CONFIG_AT91SAM9G20)
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100185 .word AT91_ASM_PIOC_PDR
Jean-Christophe PLAGNIOL-VILLARDe32eb4c2009-06-13 12:50:04 +0200186 .word CONFIG_SYS_PIOC_PDR_VAL1
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100187 .word AT91_ASM_PIOC_PUDR
Jean-Christophe PLAGNIOL-VILLARDe32eb4c2009-06-13 12:50:04 +0200188 .word CONFIG_SYS_PIOC_PPUDR_VAL
189#endif
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100190 .word AT91_ASM_MATRIX_CSA0
Jean-Christophe PLAGNIOL-VILLARDe32eb4c2009-06-13 12:50:04 +0200191 .word CONFIG_SYS_MATRIX_EBICSA_VAL
Ilko Iliev8b954a92009-04-16 21:30:48 +0200192
193 /* flash */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100194 .word AT91_ASM_SMC_MODE0
Jean-Christophe PLAGNIOL-VILLARDb3d4b282009-06-12 21:20:37 +0200195 .word CONFIG_SYS_SMC0_MODE0_VAL
Ilko Iliev8b954a92009-04-16 21:30:48 +0200196
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100197 .word AT91_ASM_SMC_CYCLE0
Ilko Iliev8b954a92009-04-16 21:30:48 +0200198 .word CONFIG_SYS_SMC0_CYCLE0_VAL
199
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100200 .word AT91_ASM_SMC_PULSE0
Ilko Iliev8b954a92009-04-16 21:30:48 +0200201 .word CONFIG_SYS_SMC0_PULSE0_VAL
202
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100203 .word AT91_ASM_SMC_SETUP0
Ilko Iliev8b954a92009-04-16 21:30:48 +0200204 .word CONFIG_SYS_SMC0_SETUP0_VAL
205
Ilko Iliev8b954a92009-04-16 21:30:48 +0200206SMRDATA1:
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100207 .word AT91_ASM_SDRAMC_MR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200208 .word CONFIG_SYS_SDRC_MR_VAL1
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100209 .word AT91_ASM_SDRAMC_TR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200210 .word CONFIG_SYS_SDRC_TR_VAL1
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100211 .word AT91_ASM_SDRAMC_CR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200212 .word CONFIG_SYS_SDRC_CR_VAL
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100213 .word AT91_ASM_SDRAMC_MDR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200214 .word CONFIG_SYS_SDRC_MDR_VAL
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100215 .word AT91_ASM_SDRAMC_MR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200216 .word CONFIG_SYS_SDRC_MR_VAL2
Eric Benard470a57b2011-06-06 22:48:27 +0000217 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200218 .word CONFIG_SYS_SDRAM_VAL1
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100219 .word AT91_ASM_SDRAMC_MR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200220 .word CONFIG_SYS_SDRC_MR_VAL3
Eric Benard470a57b2011-06-06 22:48:27 +0000221 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200222 .word CONFIG_SYS_SDRAM_VAL2
Eric Benard470a57b2011-06-06 22:48:27 +0000223 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200224 .word CONFIG_SYS_SDRAM_VAL3
Eric Benard470a57b2011-06-06 22:48:27 +0000225 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200226 .word CONFIG_SYS_SDRAM_VAL4
Eric Benard470a57b2011-06-06 22:48:27 +0000227 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200228 .word CONFIG_SYS_SDRAM_VAL5
Eric Benard470a57b2011-06-06 22:48:27 +0000229 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200230 .word CONFIG_SYS_SDRAM_VAL6
Eric Benard470a57b2011-06-06 22:48:27 +0000231 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200232 .word CONFIG_SYS_SDRAM_VAL7
Eric Benard470a57b2011-06-06 22:48:27 +0000233 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200234 .word CONFIG_SYS_SDRAM_VAL8
Eric Benard470a57b2011-06-06 22:48:27 +0000235 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200236 .word CONFIG_SYS_SDRAM_VAL9
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100237 .word AT91_ASM_SDRAMC_MR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200238 .word CONFIG_SYS_SDRC_MR_VAL4
Eric Benard470a57b2011-06-06 22:48:27 +0000239 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200240 .word CONFIG_SYS_SDRAM_VAL10
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100241 .word AT91_ASM_SDRAMC_MR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200242 .word CONFIG_SYS_SDRC_MR_VAL5
Eric Benard470a57b2011-06-06 22:48:27 +0000243 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200244 .word CONFIG_SYS_SDRAM_VAL11
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100245 .word AT91_ASM_SDRAMC_TR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200246 .word CONFIG_SYS_SDRC_TR_VAL2
Eric Benard470a57b2011-06-06 22:48:27 +0000247 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200248 .word CONFIG_SYS_SDRAM_VAL12
249 /* User reset enable*/
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100250 .word AT91_ASM_RSTC_MR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200251 .word CONFIG_SYS_RSTC_RMR_VAL
252#ifdef CONFIG_SYS_MATRIX_MCFG_REMAP
253 /* MATRIX_MCFG - REMAP all masters */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100254 .word AT91_ASM_MATRIX_MCFG
Ilko Iliev8b954a92009-04-16 21:30:48 +0200255 .word 0x1FF
256#endif
Ilko Iliev8b954a92009-04-16 21:30:48 +0200257SMRDATA2:
258 .word 0