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