blob: 994f42eb4a2015d325f6887f8be35ae588d2f851 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Ilko Iliev8b954a92009-04-16 21:30:48 +02002/*
3 * Memory Setup stuff - taken from blob memsetup.S
4 *
5 * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl) and
6 * Jan-Derk Bakker (J.D.Bakker@its.tudelft.nl)
7 *
8 * Copyright (C) 2008 Ronetix Ilko Iliev (www.ronetix.at)
9 * Copyright (C) 2009 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Ilko Iliev8b954a92009-04-16 21:30:48 +020010 */
11
12#include <config.h>
Ilko Iliev8b954a92009-04-16 21:30:48 +020013#include <asm/arch/hardware.h>
14#include <asm/arch/at91_pmc.h>
Ilko Iliev8b954a92009-04-16 21:30:48 +020015#include <asm/arch/at91_wdt.h>
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010016#include <asm/arch/at91_pio.h>
17#include <asm/arch/at91_matrix.h>
Ilko Iliev8b954a92009-04-16 21:30:48 +020018#include <asm/arch/at91sam9_sdramc.h>
19#include <asm/arch/at91sam9_smc.h>
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010020#include <asm/arch/at91_rstc.h>
Xu, Hong4fae89c2011-06-10 21:31:25 +000021#ifdef CONFIG_ATMEL_LEGACY
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010022#include <asm/arch/at91sam9_matrix.h>
23#endif
24#ifndef CONFIG_SYS_MATRIX_EBICSA_VAL
25#define CONFIG_SYS_MATRIX_EBICSA_VAL CONFIG_SYS_MATRIX_EBI0CSA_VAL
26#endif
Ilko Iliev8b954a92009-04-16 21:30:48 +020027
Ilko Iliev8b954a92009-04-16 21:30:48 +020028.globl lowlevel_init
29.type lowlevel_init,function
30lowlevel_init:
31
Ilko Iliev8b954a92009-04-16 21:30:48 +020032POS1:
Albert ARIBAUD6e294722014-02-22 17:53:43 +010033 adr r5, POS1 /* r5 = POS1 run time */
Ilko Iliev8b954a92009-04-16 21:30:48 +020034 ldr r0, =POS1 /* r0 = POS1 compile */
Wolfgang Denk0708bc62010-10-07 21:51:12 +020035 sub r5, r5, r0 /* r0 = CONFIG_SYS_TEXT_BASE-1 */
Ilko Iliev8b954a92009-04-16 21:30:48 +020036
37 /* memory control configuration 1 */
38 ldr r0, =SMRDATA
39 ldr r2, =SMRDATA1
Ilko Iliev8b954a92009-04-16 21:30:48 +020040 add r0, r0, r5
41 add r2, r2, r5
420:
43 /* the address */
44 ldr r1, [r0], #4
45 /* the value */
46 ldr r3, [r0], #4
47 str r3, [r1]
48 cmp r2, r0
49 bne 0b
50
51/* ----------------------------------------------------------------------------
52 * PMC Init Step 1.
53 * ----------------------------------------------------------------------------
54 * - Check if the PLL is already initialized
55 * ----------------------------------------------------------------------------
56 */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010057 ldr r1, =(AT91_ASM_PMC_MCKR)
Ilko Iliev8b954a92009-04-16 21:30:48 +020058 ldr r0, [r1]
59 and r0, r0, #3
60 cmp r0, #0
61 bne PLL_setup_end
62
63/* ---------------------------------------------------------------------------
64 * - Enable the Main Oscillator
65 * ---------------------------------------------------------------------------
66 */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010067 ldr r1, =(AT91_ASM_PMC_MOR)
68 ldr r2, =(AT91_ASM_PMC_SR)
Jean-Christophe PLAGNIOL-VILLARDe32eb4c2009-06-13 12:50:04 +020069 /* Main oscillator Enable register PMC_MOR: */
Jean-Christophe PLAGNIOL-VILLARD0ae32d92009-06-12 21:20:38 +020070 ldr r0, =CONFIG_SYS_MOR_VAL
Jean-Christophe PLAGNIOL-VILLARDe32eb4c2009-06-13 12:50:04 +020071 str r0, [r1]
Ilko Iliev8b954a92009-04-16 21:30:48 +020072
73 /* Reading the PMC Status to detect when the Main Oscillator is enabled */
Martin Townsendac6d6d32021-02-26 08:44:44 +000074 mov r6, #AT91_PMC_IXR_MOSCS
Ilko Iliev8b954a92009-04-16 21:30:48 +020075MOSCS_Loop:
76 ldr r3, [r2]
Martin Townsendac6d6d32021-02-26 08:44:44 +000077 and r3, r6, r3
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010078 cmp r3, #AT91_PMC_IXR_MOSCS
Ilko Iliev8b954a92009-04-16 21:30:48 +020079 bne MOSCS_Loop
80
81/* ----------------------------------------------------------------------------
82 * PMC Init Step 2.
83 * ----------------------------------------------------------------------------
84 * Setup PLLA
85 * ----------------------------------------------------------------------------
86 */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010087 ldr r1, =(AT91_ASM_PMC_PLLAR)
Ilko Iliev8b954a92009-04-16 21:30:48 +020088 ldr r0, =CONFIG_SYS_PLLAR_VAL
89 str r0, [r1]
90
91 /* Reading the PMC Status register to detect when the PLLA is locked */
Martin Townsendac6d6d32021-02-26 08:44:44 +000092 mov r6, #AT91_PMC_IXR_LOCKA
Ilko Iliev8b954a92009-04-16 21:30:48 +020093MOSCS_Loop1:
94 ldr r3, [r2]
Martin Townsendac6d6d32021-02-26 08:44:44 +000095 and r3, r6, r3
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010096 cmp r3, #AT91_PMC_IXR_LOCKA
Ilko Iliev8b954a92009-04-16 21:30:48 +020097 bne MOSCS_Loop1
98
99/* ----------------------------------------------------------------------------
100 * PMC Init Step 3.
101 * ----------------------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARDe32eb4c2009-06-13 12:50:04 +0200102 * - Switch on the Main Oscillator
Ilko Iliev8b954a92009-04-16 21:30:48 +0200103 * ----------------------------------------------------------------------------
104 */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100105 ldr r1, =(AT91_ASM_PMC_MCKR)
Ilko Iliev8b954a92009-04-16 21:30:48 +0200106
107 /* -Master Clock Controller register PMC_MCKR */
108 ldr r0, =CONFIG_SYS_MCKR1_VAL
109 str r0, [r1]
110
111 /* Reading the PMC Status to detect when the Master clock is ready */
Martin Townsendac6d6d32021-02-26 08:44:44 +0000112 mov r6, #AT91_PMC_IXR_MCKRDY
Ilko Iliev8b954a92009-04-16 21:30:48 +0200113MCKRDY_Loop:
114 ldr r3, [r2]
Martin Townsendac6d6d32021-02-26 08:44:44 +0000115 and r3, r6, r3
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100116 cmp r3, #AT91_PMC_IXR_MCKRDY
Ilko Iliev8b954a92009-04-16 21:30:48 +0200117 bne MCKRDY_Loop
118
119 ldr r0, =CONFIG_SYS_MCKR2_VAL
120 str r0, [r1]
121
122 /* Reading the PMC Status to detect when the Master clock is ready */
Martin Townsendac6d6d32021-02-26 08:44:44 +0000123 mov r6, #AT91_PMC_IXR_MCKRDY
Ilko Iliev8b954a92009-04-16 21:30:48 +0200124MCKRDY_Loop1:
125 ldr r3, [r2]
Martin Townsendac6d6d32021-02-26 08:44:44 +0000126 and r3, r6, r3
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100127 cmp r3, #AT91_PMC_IXR_MCKRDY
Ilko Iliev8b954a92009-04-16 21:30:48 +0200128 bne MCKRDY_Loop1
Ilko Iliev8b954a92009-04-16 21:30:48 +0200129PLL_setup_end:
130
131/* ----------------------------------------------------------------------------
132 * - memory control configuration 2
133 * ----------------------------------------------------------------------------
134 */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100135 ldr r0, =(AT91_ASM_SDRAMC_TR)
Ilko Iliev8b954a92009-04-16 21:30:48 +0200136 ldr r1, [r0]
137 cmp r1, #0
138 bne SDRAM_setup_end
139
140 ldr r0, =SMRDATA1
141 ldr r2, =SMRDATA2
Ilko Iliev8b954a92009-04-16 21:30:48 +0200142 add r0, r0, r5
143 add r2, r2, r5
Ilko Iliev8b954a92009-04-16 21:30:48 +02001442:
145 /* the address */
146 ldr r1, [r0], #4
147 /* the value */
148 ldr r3, [r0], #4
149 str r3, [r1]
150 cmp r2, r0
151 bne 2b
152
153SDRAM_setup_end:
154 /* everything is fine now */
155 mov pc, lr
156
157 .ltorg
158
159SMRDATA:
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100160 .word AT91_ASM_WDT_MR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200161 .word CONFIG_SYS_WDTC_WDMR_VAL
Jean-Christophe PLAGNIOL-VILLARDe32eb4c2009-06-13 12:50:04 +0200162 /* configure PIOx as EBI0 D[16-31] */
163#if defined(CONFIG_AT91SAM9263)
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100164 .word AT91_ASM_PIOD_PDR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200165 .word CONFIG_SYS_PIOD_PDR_VAL1
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100166 .word AT91_ASM_PIOD_PUDR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200167 .word CONFIG_SYS_PIOD_PPUDR_VAL
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100168 .word AT91_ASM_PIOD_ASR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200169 .word CONFIG_SYS_PIOD_PPUDR_VAL
Tom Rix799a05b2009-09-27 11:10:09 -0500170#elif defined(CONFIG_AT91SAM9260) || defined(CONFIG_AT91SAM9261) \
171 || defined(CONFIG_AT91SAM9G20)
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100172 .word AT91_ASM_PIOC_PDR
Jean-Christophe PLAGNIOL-VILLARDe32eb4c2009-06-13 12:50:04 +0200173 .word CONFIG_SYS_PIOC_PDR_VAL1
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100174 .word AT91_ASM_PIOC_PUDR
Jean-Christophe PLAGNIOL-VILLARDe32eb4c2009-06-13 12:50:04 +0200175 .word CONFIG_SYS_PIOC_PPUDR_VAL
176#endif
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100177 .word AT91_ASM_MATRIX_CSA0
Jean-Christophe PLAGNIOL-VILLARDe32eb4c2009-06-13 12:50:04 +0200178 .word CONFIG_SYS_MATRIX_EBICSA_VAL
Ilko Iliev8b954a92009-04-16 21:30:48 +0200179
180 /* flash */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100181 .word AT91_ASM_SMC_MODE0
Jean-Christophe PLAGNIOL-VILLARDb3d4b282009-06-12 21:20:37 +0200182 .word CONFIG_SYS_SMC0_MODE0_VAL
Ilko Iliev8b954a92009-04-16 21:30:48 +0200183
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100184 .word AT91_ASM_SMC_CYCLE0
Ilko Iliev8b954a92009-04-16 21:30:48 +0200185 .word CONFIG_SYS_SMC0_CYCLE0_VAL
186
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100187 .word AT91_ASM_SMC_PULSE0
Ilko Iliev8b954a92009-04-16 21:30:48 +0200188 .word CONFIG_SYS_SMC0_PULSE0_VAL
189
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100190 .word AT91_ASM_SMC_SETUP0
Ilko Iliev8b954a92009-04-16 21:30:48 +0200191 .word CONFIG_SYS_SMC0_SETUP0_VAL
192
Ilko Iliev8b954a92009-04-16 21:30:48 +0200193SMRDATA1:
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100194 .word AT91_ASM_SDRAMC_MR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200195 .word CONFIG_SYS_SDRC_MR_VAL1
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100196 .word AT91_ASM_SDRAMC_TR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200197 .word CONFIG_SYS_SDRC_TR_VAL1
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100198 .word AT91_ASM_SDRAMC_CR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200199 .word CONFIG_SYS_SDRC_CR_VAL
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100200 .word AT91_ASM_SDRAMC_MDR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200201 .word CONFIG_SYS_SDRC_MDR_VAL
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100202 .word AT91_ASM_SDRAMC_MR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200203 .word CONFIG_SYS_SDRC_MR_VAL2
Eric Benard470a57b2011-06-06 22:48:27 +0000204 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200205 .word CONFIG_SYS_SDRAM_VAL1
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100206 .word AT91_ASM_SDRAMC_MR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200207 .word CONFIG_SYS_SDRC_MR_VAL3
Eric Benard470a57b2011-06-06 22:48:27 +0000208 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200209 .word CONFIG_SYS_SDRAM_VAL2
Eric Benard470a57b2011-06-06 22:48:27 +0000210 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200211 .word CONFIG_SYS_SDRAM_VAL3
Eric Benard470a57b2011-06-06 22:48:27 +0000212 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200213 .word CONFIG_SYS_SDRAM_VAL4
Eric Benard470a57b2011-06-06 22:48:27 +0000214 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200215 .word CONFIG_SYS_SDRAM_VAL5
Eric Benard470a57b2011-06-06 22:48:27 +0000216 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200217 .word CONFIG_SYS_SDRAM_VAL6
Eric Benard470a57b2011-06-06 22:48:27 +0000218 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200219 .word CONFIG_SYS_SDRAM_VAL7
Eric Benard470a57b2011-06-06 22:48:27 +0000220 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200221 .word CONFIG_SYS_SDRAM_VAL8
Eric Benard470a57b2011-06-06 22:48:27 +0000222 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200223 .word CONFIG_SYS_SDRAM_VAL9
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100224 .word AT91_ASM_SDRAMC_MR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200225 .word CONFIG_SYS_SDRC_MR_VAL4
Eric Benard470a57b2011-06-06 22:48:27 +0000226 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200227 .word CONFIG_SYS_SDRAM_VAL10
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100228 .word AT91_ASM_SDRAMC_MR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200229 .word CONFIG_SYS_SDRC_MR_VAL5
Eric Benard470a57b2011-06-06 22:48:27 +0000230 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200231 .word CONFIG_SYS_SDRAM_VAL11
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100232 .word AT91_ASM_SDRAMC_TR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200233 .word CONFIG_SYS_SDRC_TR_VAL2
Eric Benard470a57b2011-06-06 22:48:27 +0000234 .word CONFIG_SYS_SDRAM_BASE
Ilko Iliev8b954a92009-04-16 21:30:48 +0200235 .word CONFIG_SYS_SDRAM_VAL12
236 /* User reset enable*/
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100237 .word AT91_ASM_RSTC_MR
Ilko Iliev8b954a92009-04-16 21:30:48 +0200238 .word CONFIG_SYS_RSTC_RMR_VAL
239#ifdef CONFIG_SYS_MATRIX_MCFG_REMAP
240 /* MATRIX_MCFG - REMAP all masters */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100241 .word AT91_ASM_MATRIX_MCFG
Ilko Iliev8b954a92009-04-16 21:30:48 +0200242 .word 0x1FF
243#endif
Ilko Iliev8b954a92009-04-16 21:30:48 +0200244SMRDATA2:
245 .word 0