Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 1 | /* |
| 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 | * |
| 10 | * See file CREDITS for list of people who contributed to this |
| 11 | * project. |
| 12 | * |
| 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. |
| 17 | * |
| 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. |
| 22 | * |
| 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, |
| 26 | * MA 02111-1307 USA |
| 27 | */ |
| 28 | |
| 29 | #include <config.h> |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 30 | #include <asm/arch/hardware.h> |
| 31 | #include <asm/arch/at91_pmc.h> |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 32 | #include <asm/arch/at91_wdt.h> |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 33 | #include <asm/arch/at91_pio.h> |
| 34 | #include <asm/arch/at91_matrix.h> |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 35 | #include <asm/arch/at91sam9_sdramc.h> |
| 36 | #include <asm/arch/at91sam9_smc.h> |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 37 | #include <asm/arch/at91_rstc.h> |
| 38 | #ifdef CONFIG_AT91_LEGACY |
| 39 | #include <asm/arch/at91sam9_matrix.h> |
| 40 | #endif |
| 41 | #ifndef CONFIG_SYS_MATRIX_EBICSA_VAL |
| 42 | #define CONFIG_SYS_MATRIX_EBICSA_VAL CONFIG_SYS_MATRIX_EBI0CSA_VAL |
| 43 | #endif |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 44 | |
| 45 | _TEXT_BASE: |
| 46 | .word TEXT_BASE |
| 47 | |
| 48 | .globl lowlevel_init |
| 49 | .type lowlevel_init,function |
| 50 | lowlevel_init: |
| 51 | |
| 52 | mov r5, pc /* r5 = POS1 + 4 current */ |
| 53 | POS1: |
| 54 | ldr r0, =POS1 /* r0 = POS1 compile */ |
| 55 | ldr r2, _TEXT_BASE |
| 56 | sub r0, r0, r2 /* r0 = POS1-_TEXT_BASE (POS1 relative) */ |
| 57 | sub r5, r5, r0 /* r0 = TEXT_BASE-1 */ |
| 58 | sub r5, r5, #4 /* r1 = text base - current */ |
| 59 | |
| 60 | /* memory control configuration 1 */ |
| 61 | ldr r0, =SMRDATA |
| 62 | ldr r2, =SMRDATA1 |
| 63 | ldr r1, _TEXT_BASE |
| 64 | sub r0, r0, r1 |
| 65 | sub r2, r2, r1 |
| 66 | add r0, r0, r5 |
| 67 | add r2, r2, r5 |
| 68 | 0: |
| 69 | /* the address */ |
| 70 | ldr r1, [r0], #4 |
| 71 | /* the value */ |
| 72 | ldr r3, [r0], #4 |
| 73 | str r3, [r1] |
| 74 | cmp r2, r0 |
| 75 | bne 0b |
| 76 | |
| 77 | /* ---------------------------------------------------------------------------- |
| 78 | * PMC Init Step 1. |
| 79 | * ---------------------------------------------------------------------------- |
| 80 | * - Check if the PLL is already initialized |
| 81 | * ---------------------------------------------------------------------------- |
| 82 | */ |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 83 | ldr r1, =(AT91_ASM_PMC_MCKR) |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 84 | ldr r0, [r1] |
| 85 | and r0, r0, #3 |
| 86 | cmp r0, #0 |
| 87 | bne PLL_setup_end |
| 88 | |
| 89 | /* --------------------------------------------------------------------------- |
| 90 | * - Enable the Main Oscillator |
| 91 | * --------------------------------------------------------------------------- |
| 92 | */ |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 93 | ldr r1, =(AT91_ASM_PMC_MOR) |
| 94 | ldr r2, =(AT91_ASM_PMC_SR) |
Jean-Christophe PLAGNIOL-VILLARD | 8096c51 | 2009-06-13 12:50:04 +0200 | [diff] [blame] | 95 | /* Main oscillator Enable register PMC_MOR: */ |
Jean-Christophe PLAGNIOL-VILLARD | 01550a2 | 2009-06-12 21:20:38 +0200 | [diff] [blame] | 96 | ldr r0, =CONFIG_SYS_MOR_VAL |
Jean-Christophe PLAGNIOL-VILLARD | 8096c51 | 2009-06-13 12:50:04 +0200 | [diff] [blame] | 97 | str r0, [r1] |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 98 | |
| 99 | /* Reading the PMC Status to detect when the Main Oscillator is enabled */ |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 100 | mov r4, #AT91_PMC_IXR_MOSCS |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 101 | MOSCS_Loop: |
| 102 | ldr r3, [r2] |
| 103 | and r3, r4, r3 |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 104 | cmp r3, #AT91_PMC_IXR_MOSCS |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 105 | bne MOSCS_Loop |
| 106 | |
| 107 | /* ---------------------------------------------------------------------------- |
| 108 | * PMC Init Step 2. |
| 109 | * ---------------------------------------------------------------------------- |
| 110 | * Setup PLLA |
| 111 | * ---------------------------------------------------------------------------- |
| 112 | */ |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 113 | ldr r1, =(AT91_ASM_PMC_PLLAR) |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 114 | ldr r0, =CONFIG_SYS_PLLAR_VAL |
| 115 | str r0, [r1] |
| 116 | |
| 117 | /* Reading the PMC Status register to detect when the PLLA is locked */ |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 118 | mov r4, #AT91_PMC_IXR_LOCKA |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 119 | MOSCS_Loop1: |
| 120 | ldr r3, [r2] |
| 121 | and r3, r4, r3 |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 122 | cmp r3, #AT91_PMC_IXR_LOCKA |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 123 | bne MOSCS_Loop1 |
| 124 | |
| 125 | /* ---------------------------------------------------------------------------- |
| 126 | * PMC Init Step 3. |
| 127 | * ---------------------------------------------------------------------------- |
Jean-Christophe PLAGNIOL-VILLARD | 8096c51 | 2009-06-13 12:50:04 +0200 | [diff] [blame] | 128 | * - Switch on the Main Oscillator |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 129 | * ---------------------------------------------------------------------------- |
| 130 | */ |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 131 | ldr r1, =(AT91_ASM_PMC_MCKR) |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 132 | |
| 133 | /* -Master Clock Controller register PMC_MCKR */ |
| 134 | ldr r0, =CONFIG_SYS_MCKR1_VAL |
| 135 | str r0, [r1] |
| 136 | |
| 137 | /* Reading the PMC Status to detect when the Master clock is ready */ |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 138 | mov r4, #AT91_PMC_IXR_MCKRDY |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 139 | MCKRDY_Loop: |
| 140 | ldr r3, [r2] |
| 141 | and r3, r4, r3 |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 142 | cmp r3, #AT91_PMC_IXR_MCKRDY |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 143 | bne MCKRDY_Loop |
| 144 | |
| 145 | ldr r0, =CONFIG_SYS_MCKR2_VAL |
| 146 | str r0, [r1] |
| 147 | |
| 148 | /* Reading the PMC Status to detect when the Master clock is ready */ |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 149 | mov r4, #AT91_PMC_IXR_MCKRDY |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 150 | MCKRDY_Loop1: |
| 151 | ldr r3, [r2] |
| 152 | and r3, r4, r3 |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 153 | cmp r3, #AT91_PMC_IXR_MCKRDY |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 154 | bne MCKRDY_Loop1 |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 155 | PLL_setup_end: |
| 156 | |
| 157 | /* ---------------------------------------------------------------------------- |
| 158 | * - memory control configuration 2 |
| 159 | * ---------------------------------------------------------------------------- |
| 160 | */ |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 161 | ldr r0, =(AT91_ASM_SDRAMC_TR) |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 162 | ldr r1, [r0] |
| 163 | cmp r1, #0 |
| 164 | bne SDRAM_setup_end |
| 165 | |
| 166 | ldr r0, =SMRDATA1 |
| 167 | ldr r2, =SMRDATA2 |
| 168 | ldr r1, _TEXT_BASE |
| 169 | sub r0, r0, r1 |
| 170 | sub r2, r2, r1 |
| 171 | add r0, r0, r5 |
| 172 | add r2, r2, r5 |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 173 | 2: |
| 174 | /* the address */ |
| 175 | ldr r1, [r0], #4 |
| 176 | /* the value */ |
| 177 | ldr r3, [r0], #4 |
| 178 | str r3, [r1] |
| 179 | cmp r2, r0 |
| 180 | bne 2b |
| 181 | |
| 182 | SDRAM_setup_end: |
| 183 | /* everything is fine now */ |
| 184 | mov pc, lr |
| 185 | |
| 186 | .ltorg |
| 187 | |
| 188 | SMRDATA: |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 189 | .word AT91_ASM_WDT_MR |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 190 | .word CONFIG_SYS_WDTC_WDMR_VAL |
Jean-Christophe PLAGNIOL-VILLARD | 8096c51 | 2009-06-13 12:50:04 +0200 | [diff] [blame] | 191 | /* configure PIOx as EBI0 D[16-31] */ |
| 192 | #if defined(CONFIG_AT91SAM9263) |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 193 | .word AT91_ASM_PIOD_PDR |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 194 | .word CONFIG_SYS_PIOD_PDR_VAL1 |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 195 | .word AT91_ASM_PIOD_PUDR |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 196 | .word CONFIG_SYS_PIOD_PPUDR_VAL |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 197 | .word AT91_ASM_PIOD_ASR |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 198 | .word CONFIG_SYS_PIOD_PPUDR_VAL |
Tom Rix | 23b8098 | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 199 | #elif defined(CONFIG_AT91SAM9260) || defined(CONFIG_AT91SAM9261) \ |
| 200 | || defined(CONFIG_AT91SAM9G20) |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 201 | .word AT91_ASM_PIOC_PDR |
Jean-Christophe PLAGNIOL-VILLARD | 8096c51 | 2009-06-13 12:50:04 +0200 | [diff] [blame] | 202 | .word CONFIG_SYS_PIOC_PDR_VAL1 |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 203 | .word AT91_ASM_PIOC_PUDR |
Jean-Christophe PLAGNIOL-VILLARD | 8096c51 | 2009-06-13 12:50:04 +0200 | [diff] [blame] | 204 | .word CONFIG_SYS_PIOC_PPUDR_VAL |
| 205 | #endif |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 206 | .word AT91_ASM_MATRIX_CSA0 |
Jean-Christophe PLAGNIOL-VILLARD | 8096c51 | 2009-06-13 12:50:04 +0200 | [diff] [blame] | 207 | .word CONFIG_SYS_MATRIX_EBICSA_VAL |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 208 | |
| 209 | /* flash */ |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 210 | .word AT91_ASM_SMC_MODE0 |
Jean-Christophe PLAGNIOL-VILLARD | 7a11c7f | 2009-06-12 21:20:37 +0200 | [diff] [blame] | 211 | .word CONFIG_SYS_SMC0_MODE0_VAL |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 212 | |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 213 | .word AT91_ASM_SMC_CYCLE0 |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 214 | .word CONFIG_SYS_SMC0_CYCLE0_VAL |
| 215 | |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 216 | .word AT91_ASM_SMC_PULSE0 |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 217 | .word CONFIG_SYS_SMC0_PULSE0_VAL |
| 218 | |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 219 | .word AT91_ASM_SMC_SETUP0 |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 220 | .word CONFIG_SYS_SMC0_SETUP0_VAL |
| 221 | |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 222 | SMRDATA1: |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 223 | .word AT91_ASM_SDRAMC_MR |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 224 | .word CONFIG_SYS_SDRC_MR_VAL1 |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 225 | .word AT91_ASM_SDRAMC_TR |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 226 | .word CONFIG_SYS_SDRC_TR_VAL1 |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 227 | .word AT91_ASM_SDRAMC_CR |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 228 | .word CONFIG_SYS_SDRC_CR_VAL |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 229 | .word AT91_ASM_SDRAMC_MDR |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 230 | .word CONFIG_SYS_SDRC_MDR_VAL |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 231 | .word AT91_ASM_SDRAMC_MR |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 232 | .word CONFIG_SYS_SDRC_MR_VAL2 |
| 233 | .word AT91_SDRAM_BASE |
| 234 | .word CONFIG_SYS_SDRAM_VAL1 |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 235 | .word AT91_ASM_SDRAMC_MR |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 236 | .word CONFIG_SYS_SDRC_MR_VAL3 |
| 237 | .word AT91_SDRAM_BASE |
| 238 | .word CONFIG_SYS_SDRAM_VAL2 |
| 239 | .word AT91_SDRAM_BASE |
| 240 | .word CONFIG_SYS_SDRAM_VAL3 |
| 241 | .word AT91_SDRAM_BASE |
| 242 | .word CONFIG_SYS_SDRAM_VAL4 |
| 243 | .word AT91_SDRAM_BASE |
| 244 | .word CONFIG_SYS_SDRAM_VAL5 |
| 245 | .word AT91_SDRAM_BASE |
| 246 | .word CONFIG_SYS_SDRAM_VAL6 |
| 247 | .word AT91_SDRAM_BASE |
| 248 | .word CONFIG_SYS_SDRAM_VAL7 |
| 249 | .word AT91_SDRAM_BASE |
| 250 | .word CONFIG_SYS_SDRAM_VAL8 |
| 251 | .word AT91_SDRAM_BASE |
| 252 | .word CONFIG_SYS_SDRAM_VAL9 |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 253 | .word AT91_ASM_SDRAMC_MR |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 254 | .word CONFIG_SYS_SDRC_MR_VAL4 |
| 255 | .word AT91_SDRAM_BASE |
| 256 | .word CONFIG_SYS_SDRAM_VAL10 |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 257 | .word AT91_ASM_SDRAMC_MR |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 258 | .word CONFIG_SYS_SDRC_MR_VAL5 |
| 259 | .word AT91_SDRAM_BASE |
| 260 | .word CONFIG_SYS_SDRAM_VAL11 |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 261 | .word AT91_ASM_SDRAMC_TR |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 262 | .word CONFIG_SYS_SDRC_TR_VAL2 |
| 263 | .word AT91_SDRAM_BASE |
| 264 | .word CONFIG_SYS_SDRAM_VAL12 |
| 265 | /* User reset enable*/ |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 266 | .word AT91_ASM_RSTC_MR |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 267 | .word CONFIG_SYS_RSTC_RMR_VAL |
| 268 | #ifdef CONFIG_SYS_MATRIX_MCFG_REMAP |
| 269 | /* MATRIX_MCFG - REMAP all masters */ |
Jens Scharsig | 0cf0b93 | 2010-02-03 22:46:58 +0100 | [diff] [blame^] | 270 | .word AT91_ASM_MATRIX_MCFG |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 271 | .word 0x1FF |
| 272 | #endif |
Ilko Iliev | f0a2c7b | 2009-04-16 21:30:48 +0200 | [diff] [blame] | 273 | SMRDATA2: |
| 274 | .word 0 |