blob: a9ec81a75c81b31ec6d4c0609d4287da2aa7a741 [file] [log] [blame]
Ilko Ilievf0a2c7b2009-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 Denk3765b3e2013-10-07 13:07:26 +020010 * SPDX-License-Identifier: GPL-2.0+
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +020011 */
12
13#include <config.h>
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +020014#include <asm/arch/hardware.h>
15#include <asm/arch/at91_pmc.h>
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +020016#include <asm/arch/at91_wdt.h>
Jens Scharsig0cf0b932010-02-03 22:46:58 +010017#include <asm/arch/at91_pio.h>
18#include <asm/arch/at91_matrix.h>
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +020019#include <asm/arch/at91sam9_sdramc.h>
20#include <asm/arch/at91sam9_smc.h>
Jens Scharsig0cf0b932010-02-03 22:46:58 +010021#include <asm/arch/at91_rstc.h>
Xu, Hongffa280f2011-06-10 21:31:25 +000022#ifdef CONFIG_ATMEL_LEGACY
Jens Scharsig0cf0b932010-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 Ilievf0a2c7b2009-04-16 21:30:48 +020028
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +020029.globl lowlevel_init
30.type lowlevel_init,function
31lowlevel_init:
32
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +020033POS1:
Albert ARIBAUDb60eff32014-02-22 17:53:43 +010034 adr r5, POS1 /* r5 = POS1 run time */
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +020035 ldr r0, =POS1 /* r0 = POS1 compile */
Wolfgang Denk14d0a022010-10-07 21:51:12 +020036 sub r5, r5, r0 /* r0 = CONFIG_SYS_TEXT_BASE-1 */
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +020037
38 /* memory control configuration 1 */
39 ldr r0, =SMRDATA
40 ldr r2, =SMRDATA1
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +020041 add r0, r0, r5
42 add r2, r2, r5
430:
44 /* the address */
45 ldr r1, [r0], #4
46 /* the value */
47 ldr r3, [r0], #4
48 str r3, [r1]
49 cmp r2, r0
50 bne 0b
51
52/* ----------------------------------------------------------------------------
53 * PMC Init Step 1.
54 * ----------------------------------------------------------------------------
55 * - Check if the PLL is already initialized
56 * ----------------------------------------------------------------------------
57 */
Jens Scharsig0cf0b932010-02-03 22:46:58 +010058 ldr r1, =(AT91_ASM_PMC_MCKR)
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +020059 ldr r0, [r1]
60 and r0, r0, #3
61 cmp r0, #0
62 bne PLL_setup_end
63
64/* ---------------------------------------------------------------------------
65 * - Enable the Main Oscillator
66 * ---------------------------------------------------------------------------
67 */
Jens Scharsig0cf0b932010-02-03 22:46:58 +010068 ldr r1, =(AT91_ASM_PMC_MOR)
69 ldr r2, =(AT91_ASM_PMC_SR)
Jean-Christophe PLAGNIOL-VILLARD8096c512009-06-13 12:50:04 +020070 /* Main oscillator Enable register PMC_MOR: */
Jean-Christophe PLAGNIOL-VILLARD01550a22009-06-12 21:20:38 +020071 ldr r0, =CONFIG_SYS_MOR_VAL
Jean-Christophe PLAGNIOL-VILLARD8096c512009-06-13 12:50:04 +020072 str r0, [r1]
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +020073
74 /* Reading the PMC Status to detect when the Main Oscillator is enabled */
Jens Scharsig0cf0b932010-02-03 22:46:58 +010075 mov r4, #AT91_PMC_IXR_MOSCS
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +020076MOSCS_Loop:
77 ldr r3, [r2]
78 and r3, r4, r3
Jens Scharsig0cf0b932010-02-03 22:46:58 +010079 cmp r3, #AT91_PMC_IXR_MOSCS
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +020080 bne MOSCS_Loop
81
82/* ----------------------------------------------------------------------------
83 * PMC Init Step 2.
84 * ----------------------------------------------------------------------------
85 * Setup PLLA
86 * ----------------------------------------------------------------------------
87 */
Jens Scharsig0cf0b932010-02-03 22:46:58 +010088 ldr r1, =(AT91_ASM_PMC_PLLAR)
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +020089 ldr r0, =CONFIG_SYS_PLLAR_VAL
90 str r0, [r1]
91
92 /* Reading the PMC Status register to detect when the PLLA is locked */
Jens Scharsig0cf0b932010-02-03 22:46:58 +010093 mov r4, #AT91_PMC_IXR_LOCKA
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +020094MOSCS_Loop1:
95 ldr r3, [r2]
96 and r3, r4, r3
Jens Scharsig0cf0b932010-02-03 22:46:58 +010097 cmp r3, #AT91_PMC_IXR_LOCKA
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +020098 bne MOSCS_Loop1
99
100/* ----------------------------------------------------------------------------
101 * PMC Init Step 3.
102 * ----------------------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD8096c512009-06-13 12:50:04 +0200103 * - Switch on the Main Oscillator
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200104 * ----------------------------------------------------------------------------
105 */
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100106 ldr r1, =(AT91_ASM_PMC_MCKR)
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200107
108 /* -Master Clock Controller register PMC_MCKR */
109 ldr r0, =CONFIG_SYS_MCKR1_VAL
110 str r0, [r1]
111
112 /* Reading the PMC Status to detect when the Master clock is ready */
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100113 mov r4, #AT91_PMC_IXR_MCKRDY
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200114MCKRDY_Loop:
115 ldr r3, [r2]
116 and r3, r4, r3
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100117 cmp r3, #AT91_PMC_IXR_MCKRDY
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200118 bne MCKRDY_Loop
119
120 ldr r0, =CONFIG_SYS_MCKR2_VAL
121 str r0, [r1]
122
123 /* Reading the PMC Status to detect when the Master clock is ready */
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100124 mov r4, #AT91_PMC_IXR_MCKRDY
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200125MCKRDY_Loop1:
126 ldr r3, [r2]
127 and r3, r4, r3
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100128 cmp r3, #AT91_PMC_IXR_MCKRDY
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200129 bne MCKRDY_Loop1
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200130PLL_setup_end:
131
132/* ----------------------------------------------------------------------------
133 * - memory control configuration 2
134 * ----------------------------------------------------------------------------
135 */
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100136 ldr r0, =(AT91_ASM_SDRAMC_TR)
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200137 ldr r1, [r0]
138 cmp r1, #0
139 bne SDRAM_setup_end
140
141 ldr r0, =SMRDATA1
142 ldr r2, =SMRDATA2
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200143 add r0, r0, r5
144 add r2, r2, r5
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +02001452:
146 /* the address */
147 ldr r1, [r0], #4
148 /* the value */
149 ldr r3, [r0], #4
150 str r3, [r1]
151 cmp r2, r0
152 bne 2b
153
154SDRAM_setup_end:
155 /* everything is fine now */
156 mov pc, lr
157
158 .ltorg
159
160SMRDATA:
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100161 .word AT91_ASM_WDT_MR
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200162 .word CONFIG_SYS_WDTC_WDMR_VAL
Jean-Christophe PLAGNIOL-VILLARD8096c512009-06-13 12:50:04 +0200163 /* configure PIOx as EBI0 D[16-31] */
164#if defined(CONFIG_AT91SAM9263)
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100165 .word AT91_ASM_PIOD_PDR
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200166 .word CONFIG_SYS_PIOD_PDR_VAL1
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100167 .word AT91_ASM_PIOD_PUDR
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200168 .word CONFIG_SYS_PIOD_PPUDR_VAL
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100169 .word AT91_ASM_PIOD_ASR
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200170 .word CONFIG_SYS_PIOD_PPUDR_VAL
Tom Rix23b80982009-09-27 11:10:09 -0500171#elif defined(CONFIG_AT91SAM9260) || defined(CONFIG_AT91SAM9261) \
172 || defined(CONFIG_AT91SAM9G20)
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100173 .word AT91_ASM_PIOC_PDR
Jean-Christophe PLAGNIOL-VILLARD8096c512009-06-13 12:50:04 +0200174 .word CONFIG_SYS_PIOC_PDR_VAL1
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100175 .word AT91_ASM_PIOC_PUDR
Jean-Christophe PLAGNIOL-VILLARD8096c512009-06-13 12:50:04 +0200176 .word CONFIG_SYS_PIOC_PPUDR_VAL
177#endif
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100178 .word AT91_ASM_MATRIX_CSA0
Jean-Christophe PLAGNIOL-VILLARD8096c512009-06-13 12:50:04 +0200179 .word CONFIG_SYS_MATRIX_EBICSA_VAL
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200180
181 /* flash */
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100182 .word AT91_ASM_SMC_MODE0
Jean-Christophe PLAGNIOL-VILLARD7a11c7f2009-06-12 21:20:37 +0200183 .word CONFIG_SYS_SMC0_MODE0_VAL
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200184
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100185 .word AT91_ASM_SMC_CYCLE0
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200186 .word CONFIG_SYS_SMC0_CYCLE0_VAL
187
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100188 .word AT91_ASM_SMC_PULSE0
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200189 .word CONFIG_SYS_SMC0_PULSE0_VAL
190
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100191 .word AT91_ASM_SMC_SETUP0
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200192 .word CONFIG_SYS_SMC0_SETUP0_VAL
193
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200194SMRDATA1:
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100195 .word AT91_ASM_SDRAMC_MR
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200196 .word CONFIG_SYS_SDRC_MR_VAL1
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100197 .word AT91_ASM_SDRAMC_TR
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200198 .word CONFIG_SYS_SDRC_TR_VAL1
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100199 .word AT91_ASM_SDRAMC_CR
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200200 .word CONFIG_SYS_SDRC_CR_VAL
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100201 .word AT91_ASM_SDRAMC_MDR
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200202 .word CONFIG_SYS_SDRC_MDR_VAL
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100203 .word AT91_ASM_SDRAMC_MR
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200204 .word CONFIG_SYS_SDRC_MR_VAL2
Eric Benard96fd99062011-06-06 22:48:27 +0000205 .word CONFIG_SYS_SDRAM_BASE
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200206 .word CONFIG_SYS_SDRAM_VAL1
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100207 .word AT91_ASM_SDRAMC_MR
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200208 .word CONFIG_SYS_SDRC_MR_VAL3
Eric Benard96fd99062011-06-06 22:48:27 +0000209 .word CONFIG_SYS_SDRAM_BASE
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200210 .word CONFIG_SYS_SDRAM_VAL2
Eric Benard96fd99062011-06-06 22:48:27 +0000211 .word CONFIG_SYS_SDRAM_BASE
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200212 .word CONFIG_SYS_SDRAM_VAL3
Eric Benard96fd99062011-06-06 22:48:27 +0000213 .word CONFIG_SYS_SDRAM_BASE
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200214 .word CONFIG_SYS_SDRAM_VAL4
Eric Benard96fd99062011-06-06 22:48:27 +0000215 .word CONFIG_SYS_SDRAM_BASE
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200216 .word CONFIG_SYS_SDRAM_VAL5
Eric Benard96fd99062011-06-06 22:48:27 +0000217 .word CONFIG_SYS_SDRAM_BASE
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200218 .word CONFIG_SYS_SDRAM_VAL6
Eric Benard96fd99062011-06-06 22:48:27 +0000219 .word CONFIG_SYS_SDRAM_BASE
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200220 .word CONFIG_SYS_SDRAM_VAL7
Eric Benard96fd99062011-06-06 22:48:27 +0000221 .word CONFIG_SYS_SDRAM_BASE
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200222 .word CONFIG_SYS_SDRAM_VAL8
Eric Benard96fd99062011-06-06 22:48:27 +0000223 .word CONFIG_SYS_SDRAM_BASE
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200224 .word CONFIG_SYS_SDRAM_VAL9
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100225 .word AT91_ASM_SDRAMC_MR
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200226 .word CONFIG_SYS_SDRC_MR_VAL4
Eric Benard96fd99062011-06-06 22:48:27 +0000227 .word CONFIG_SYS_SDRAM_BASE
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200228 .word CONFIG_SYS_SDRAM_VAL10
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100229 .word AT91_ASM_SDRAMC_MR
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200230 .word CONFIG_SYS_SDRC_MR_VAL5
Eric Benard96fd99062011-06-06 22:48:27 +0000231 .word CONFIG_SYS_SDRAM_BASE
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200232 .word CONFIG_SYS_SDRAM_VAL11
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100233 .word AT91_ASM_SDRAMC_TR
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200234 .word CONFIG_SYS_SDRC_TR_VAL2
Eric Benard96fd99062011-06-06 22:48:27 +0000235 .word CONFIG_SYS_SDRAM_BASE
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200236 .word CONFIG_SYS_SDRAM_VAL12
237 /* User reset enable*/
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100238 .word AT91_ASM_RSTC_MR
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200239 .word CONFIG_SYS_RSTC_RMR_VAL
240#ifdef CONFIG_SYS_MATRIX_MCFG_REMAP
241 /* MATRIX_MCFG - REMAP all masters */
Jens Scharsig0cf0b932010-02-03 22:46:58 +0100242 .word AT91_ASM_MATRIX_MCFG
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200243 .word 0x1FF
244#endif
Ilko Ilievf0a2c7b2009-04-16 21:30:48 +0200245SMRDATA2:
246 .word 0