wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * armboot - Startup Code for ARM720 CPU-core |
| 3 | * |
Albert ARIBAUD | fa82f87 | 2011-08-04 18:45:45 +0200 | [diff] [blame] | 4 | * Copyright (c) 2001 Marius Gröger <mag@sysgo.de> |
| 5 | * Copyright (c) 2002 Alex Züpke <azu@sysgo.de> |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 6 | * |
| 7 | * See file CREDITS for list of people who contributed to this |
| 8 | * project. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
wdenk | cdc7fea | 2004-07-11 22:27:55 +0000 | [diff] [blame] | 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
| 24 | */ |
| 25 | |
Wolfgang Denk | 25ddd1f | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 26 | #include <asm-offsets.h> |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 27 | #include <config.h> |
| 28 | #include <version.h> |
wdenk | 3953988 | 2004-07-01 16:30:44 +0000 | [diff] [blame] | 29 | #include <asm/hardware.h> |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 30 | |
| 31 | /* |
| 32 | ************************************************************************* |
| 33 | * |
| 34 | * Jump vector table as in table 3.1 in [1] |
| 35 | * |
| 36 | ************************************************************************* |
| 37 | */ |
| 38 | |
| 39 | |
| 40 | .globl _start |
wdenk | cdc7fea | 2004-07-11 22:27:55 +0000 | [diff] [blame] | 41 | _start: b reset |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 42 | ldr pc, _undefined_instruction |
| 43 | ldr pc, _software_interrupt |
| 44 | ldr pc, _prefetch_abort |
| 45 | ldr pc, _data_abort |
Gary Jennejohn | 6bd2447 | 2007-01-24 12:16:56 +0100 | [diff] [blame] | 46 | #ifdef CONFIG_LPC2292 |
| 47 | .word 0xB4405F76 /* 2's complement of the checksum of the vectors */ |
| 48 | #else |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 49 | ldr pc, _not_used |
Gary Jennejohn | 6bd2447 | 2007-01-24 12:16:56 +0100 | [diff] [blame] | 50 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 51 | ldr pc, _irq |
| 52 | ldr pc, _fiq |
| 53 | |
Allen Martin | c7da6c6 | 2012-08-31 08:30:07 +0000 | [diff] [blame] | 54 | #ifdef CONFIG_SPL_BUILD |
| 55 | _undefined_instruction: .word _undefined_instruction |
| 56 | _software_interrupt: .word _software_interrupt |
| 57 | _prefetch_abort: .word _prefetch_abort |
| 58 | _data_abort: .word _data_abort |
| 59 | _not_used: .word _not_used |
| 60 | _irq: .word _irq |
| 61 | _fiq: .word _fiq |
Allen Martin | c037c93 | 2012-08-31 08:30:09 +0000 | [diff] [blame] | 62 | _pad: .word 0x12345678 /* now 16*4=64 */ |
Allen Martin | c7da6c6 | 2012-08-31 08:30:07 +0000 | [diff] [blame] | 63 | #else |
wdenk | cdc7fea | 2004-07-11 22:27:55 +0000 | [diff] [blame] | 64 | _undefined_instruction: .word undefined_instruction |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 65 | _software_interrupt: .word software_interrupt |
| 66 | _prefetch_abort: .word prefetch_abort |
| 67 | _data_abort: .word data_abort |
| 68 | _not_used: .word not_used |
| 69 | _irq: .word irq |
| 70 | _fiq: .word fiq |
Allen Martin | c037c93 | 2012-08-31 08:30:09 +0000 | [diff] [blame] | 71 | _pad: .word 0x12345678 /* now 16*4=64 */ |
Allen Martin | c7da6c6 | 2012-08-31 08:30:07 +0000 | [diff] [blame] | 72 | #endif /* CONFIG_SPL_BUILD */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 73 | |
| 74 | .balignl 16,0xdeadbeef |
| 75 | |
| 76 | |
| 77 | /* |
| 78 | ************************************************************************* |
| 79 | * |
| 80 | * Startup Code (reset vector) |
| 81 | * |
wdenk | f6e20fc | 2004-02-08 19:38:38 +0000 | [diff] [blame] | 82 | * do important init only if we don't start from RAM! |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 83 | * relocate armboot to ram |
| 84 | * setup stack |
| 85 | * jump to second stage |
| 86 | * |
| 87 | ************************************************************************* |
| 88 | */ |
| 89 | |
Heiko Schocher | abef7b8 | 2010-09-17 13:10:52 +0200 | [diff] [blame] | 90 | .globl _TEXT_BASE |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 91 | _TEXT_BASE: |
Allen Martin | c037c93 | 2012-08-31 08:30:09 +0000 | [diff] [blame] | 92 | #ifdef CONFIG_SPL_BUILD |
| 93 | .word CONFIG_SPL_TEXT_BASE |
| 94 | #else |
Wolfgang Denk | 14d0a02 | 2010-10-07 21:51:12 +0200 | [diff] [blame] | 95 | .word CONFIG_SYS_TEXT_BASE |
Allen Martin | c037c93 | 2012-08-31 08:30:09 +0000 | [diff] [blame] | 96 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 97 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 98 | /* |
wdenk | f6e20fc | 2004-02-08 19:38:38 +0000 | [diff] [blame] | 99 | * These are defined in the board-specific linker script. |
Albert Aribaud | 3336ca6 | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 100 | * Subtracting _start from them lets the linker put their |
| 101 | * relative position in the executable instead of leaving |
| 102 | * them null. |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 103 | */ |
Albert Aribaud | 3336ca6 | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 104 | .globl _bss_start_ofs |
| 105 | _bss_start_ofs: |
| 106 | .word __bss_start - _start |
wdenk | f6e20fc | 2004-02-08 19:38:38 +0000 | [diff] [blame] | 107 | |
Albert Aribaud | 3336ca6 | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 108 | .globl _bss_end_ofs |
| 109 | _bss_end_ofs: |
Po-Yu Chuang | 44c6e65 | 2011-03-01 22:59:59 +0000 | [diff] [blame] | 110 | .word __bss_end__ - _start |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 111 | |
Po-Yu Chuang | f326cbb | 2011-03-01 23:02:04 +0000 | [diff] [blame] | 112 | .globl _end_ofs |
| 113 | _end_ofs: |
| 114 | .word _end - _start |
| 115 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 116 | #ifdef CONFIG_USE_IRQ |
| 117 | /* IRQ stack memory (calculated at run-time) */ |
| 118 | .globl IRQ_STACK_START |
| 119 | IRQ_STACK_START: |
| 120 | .word 0x0badc0de |
| 121 | |
| 122 | /* IRQ stack memory (calculated at run-time) */ |
| 123 | .globl FIQ_STACK_START |
| 124 | FIQ_STACK_START: |
| 125 | .word 0x0badc0de |
| 126 | #endif |
| 127 | |
Heiko Schocher | abef7b8 | 2010-09-17 13:10:52 +0200 | [diff] [blame] | 128 | /* IRQ stack memory (calculated at run-time) + 8 bytes */ |
| 129 | .globl IRQ_STACK_START_IN |
| 130 | IRQ_STACK_START_IN: |
| 131 | .word 0x0badc0de |
| 132 | |
Heiko Schocher | abef7b8 | 2010-09-17 13:10:52 +0200 | [diff] [blame] | 133 | /* |
| 134 | * the actual reset code |
| 135 | */ |
| 136 | |
| 137 | reset: |
| 138 | /* |
| 139 | * set the cpu to SVC32 mode |
| 140 | */ |
| 141 | mrs r0,cpsr |
| 142 | bic r0,r0,#0x1f |
| 143 | orr r0,r0,#0xd3 |
| 144 | msr cpsr,r0 |
| 145 | |
| 146 | /* |
| 147 | * we do sys-critical inits only at reboot, |
| 148 | * not when booting from ram! |
| 149 | */ |
| 150 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
| 151 | bl cpu_init_crit |
| 152 | #endif |
| 153 | |
| 154 | #ifdef CONFIG_LPC2292 |
| 155 | bl lowlevel_init |
| 156 | #endif |
| 157 | |
| 158 | /* Set stackpointer in internal RAM to call board_init_f */ |
| 159 | call_board_init_f: |
| 160 | ldr sp, =(CONFIG_SYS_INIT_SP_ADDR) |
Heiko Schocher | 296cae7 | 2010-11-12 07:53:55 +0100 | [diff] [blame] | 161 | bic sp, sp, #7 /* 8-byte alignment for ABI compliance */ |
Heiko Schocher | abef7b8 | 2010-09-17 13:10:52 +0200 | [diff] [blame] | 162 | ldr r0,=0x00000000 |
| 163 | bl board_init_f |
| 164 | |
| 165 | /*------------------------------------------------------------------------------*/ |
| 166 | |
| 167 | /* |
| 168 | * void relocate_code (addr_sp, gd, addr_moni) |
| 169 | * |
| 170 | * This "function" does not return, instead it continues in RAM |
| 171 | * after relocating the monitor code. |
| 172 | * |
| 173 | */ |
| 174 | .globl relocate_code |
| 175 | relocate_code: |
| 176 | mov r4, r0 /* save addr_sp */ |
| 177 | mov r5, r1 /* save addr of gd */ |
| 178 | mov r6, r2 /* save addr of destination */ |
Heiko Schocher | abef7b8 | 2010-09-17 13:10:52 +0200 | [diff] [blame] | 179 | |
| 180 | /* Set up the stack */ |
| 181 | stack_setup: |
| 182 | mov sp, r4 |
| 183 | |
| 184 | adr r0, _start |
Andreas Bießmann | a1a47d3 | 2010-12-01 00:58:34 +0100 | [diff] [blame] | 185 | cmp r0, r6 |
Allen Martin | c7da6c6 | 2012-08-31 08:30:07 +0000 | [diff] [blame] | 186 | moveq r9, #0 /* no relocation. relocation offset(r9) = 0 */ |
Andreas Bießmann | a1a47d3 | 2010-12-01 00:58:34 +0100 | [diff] [blame] | 187 | beq clear_bss /* skip relocation */ |
Andreas Bießmann | a78fb68 | 2010-12-01 00:58:33 +0100 | [diff] [blame] | 188 | mov r1, r6 /* r1 <- scratch for copy_loop */ |
Albert Aribaud | 3336ca6 | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 189 | ldr r3, _bss_start_ofs |
| 190 | add r2, r0, r3 /* r2 <- source end address */ |
Heiko Schocher | abef7b8 | 2010-09-17 13:10:52 +0200 | [diff] [blame] | 191 | |
Heiko Schocher | abef7b8 | 2010-09-17 13:10:52 +0200 | [diff] [blame] | 192 | copy_loop: |
| 193 | ldmia r0!, {r9-r10} /* copy from source address [r0] */ |
Andreas Bießmann | a78fb68 | 2010-12-01 00:58:33 +0100 | [diff] [blame] | 194 | stmia r1!, {r9-r10} /* copy to target address [r1] */ |
Albert Aribaud | da90d4c | 2010-10-05 16:06:39 +0200 | [diff] [blame] | 195 | cmp r0, r2 /* until source end address [r2] */ |
| 196 | blo copy_loop |
Heiko Schocher | abef7b8 | 2010-09-17 13:10:52 +0200 | [diff] [blame] | 197 | |
Aneesh V | 401bb30 | 2011-07-13 05:11:07 +0000 | [diff] [blame] | 198 | #ifndef CONFIG_SPL_BUILD |
Albert Aribaud | 3336ca6 | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 199 | /* |
| 200 | * fix .rel.dyn relocations |
| 201 | */ |
| 202 | ldr r0, _TEXT_BASE /* r0 <- Text base */ |
Andreas Bießmann | a78fb68 | 2010-12-01 00:58:33 +0100 | [diff] [blame] | 203 | sub r9, r6, r0 /* r9 <- relocation offset */ |
Albert Aribaud | 3336ca6 | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 204 | ldr r10, _dynsym_start_ofs /* r10 <- sym table ofs */ |
| 205 | add r10, r10, r0 /* r10 <- sym table in FLASH */ |
| 206 | ldr r2, _rel_dyn_start_ofs /* r2 <- rel dyn start ofs */ |
| 207 | add r2, r2, r0 /* r2 <- rel dyn start in FLASH */ |
| 208 | ldr r3, _rel_dyn_end_ofs /* r3 <- rel dyn end ofs */ |
| 209 | add r3, r3, r0 /* r3 <- rel dyn end in FLASH */ |
Heiko Schocher | abef7b8 | 2010-09-17 13:10:52 +0200 | [diff] [blame] | 210 | fixloop: |
Albert Aribaud | 3336ca6 | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 211 | ldr r0, [r2] /* r0 <- location to fix up, IN FLASH! */ |
| 212 | add r0, r0, r9 /* r0 <- location to fix up in RAM */ |
| 213 | ldr r1, [r2, #4] |
Andreas Bießmann | 1f52d89 | 2010-12-01 00:58:35 +0100 | [diff] [blame] | 214 | and r7, r1, #0xff |
| 215 | cmp r7, #23 /* relative fixup? */ |
Albert Aribaud | 3336ca6 | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 216 | beq fixrel |
Andreas Bießmann | 1f52d89 | 2010-12-01 00:58:35 +0100 | [diff] [blame] | 217 | cmp r7, #2 /* absolute fixup? */ |
Albert Aribaud | 3336ca6 | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 218 | beq fixabs |
| 219 | /* ignore unknown type of fixup */ |
| 220 | b fixnext |
| 221 | fixabs: |
| 222 | /* absolute fix: set location to (offset) symbol value */ |
| 223 | mov r1, r1, LSR #4 /* r1 <- symbol index in .dynsym */ |
| 224 | add r1, r10, r1 /* r1 <- address of symbol in table */ |
| 225 | ldr r1, [r1, #4] /* r1 <- symbol value */ |
Wolfgang Denk | 3600945 | 2010-12-09 11:26:24 +0100 | [diff] [blame] | 226 | add r1, r1, r9 /* r1 <- relocated sym addr */ |
Albert Aribaud | 3336ca6 | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 227 | b fixnext |
| 228 | fixrel: |
| 229 | /* relative fix: increase location by offset */ |
| 230 | ldr r1, [r0] |
| 231 | add r1, r1, r9 |
| 232 | fixnext: |
| 233 | str r1, [r0] |
| 234 | add r2, r2, #8 /* each rel.dyn entry is 8 bytes */ |
Heiko Schocher | abef7b8 | 2010-09-17 13:10:52 +0200 | [diff] [blame] | 235 | cmp r2, r3 |
Wolfgang Denk | 79e6313 | 2010-10-23 23:22:38 +0200 | [diff] [blame] | 236 | blo fixloop |
Heiko Schocher | abef7b8 | 2010-09-17 13:10:52 +0200 | [diff] [blame] | 237 | #endif |
Heiko Schocher | abef7b8 | 2010-09-17 13:10:52 +0200 | [diff] [blame] | 238 | |
| 239 | clear_bss: |
Aneesh V | 401bb30 | 2011-07-13 05:11:07 +0000 | [diff] [blame] | 240 | #ifndef CONFIG_SPL_BUILD |
Albert Aribaud | 3336ca6 | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 241 | ldr r0, _bss_start_ofs |
| 242 | ldr r1, _bss_end_ofs |
Andreas Bießmann | a78fb68 | 2010-12-01 00:58:33 +0100 | [diff] [blame] | 243 | mov r4, r6 /* reloc addr */ |
Heiko Schocher | abef7b8 | 2010-09-17 13:10:52 +0200 | [diff] [blame] | 244 | add r0, r0, r4 |
Heiko Schocher | abef7b8 | 2010-09-17 13:10:52 +0200 | [diff] [blame] | 245 | add r1, r1, r4 |
| 246 | mov r2, #0x00000000 /* clear */ |
| 247 | |
Zhong Hongbo | 448217d | 2012-07-07 03:24:33 +0000 | [diff] [blame] | 248 | clbss_l:cmp r0, r1 /* clear loop... */ |
| 249 | bhs clbss_e /* if reached end of bss, exit */ |
| 250 | str r2, [r0] |
Heiko Schocher | abef7b8 | 2010-09-17 13:10:52 +0200 | [diff] [blame] | 251 | add r0, r0, #4 |
Zhong Hongbo | 448217d | 2012-07-07 03:24:33 +0000 | [diff] [blame] | 252 | b clbss_l |
| 253 | clbss_e: |
Heiko Schocher | abef7b8 | 2010-09-17 13:10:52 +0200 | [diff] [blame] | 254 | |
| 255 | bl coloured_LED_init |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 256 | bl red_led_on |
Heiko Schocher | abef7b8 | 2010-09-17 13:10:52 +0200 | [diff] [blame] | 257 | #endif |
| 258 | |
| 259 | /* |
| 260 | * We are done. Do not return, instead branch to second part of board |
| 261 | * initialization, now running from RAM. |
| 262 | */ |
Albert Aribaud | 3336ca6 | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 263 | ldr r0, _board_init_r_ofs |
| 264 | adr r1, _start |
| 265 | add lr, r0, r1 |
| 266 | add lr, lr, r9 |
Heiko Schocher | abef7b8 | 2010-09-17 13:10:52 +0200 | [diff] [blame] | 267 | /* setup parameters for board_init_r */ |
| 268 | mov r0, r5 /* gd_t */ |
Andreas Bießmann | a78fb68 | 2010-12-01 00:58:33 +0100 | [diff] [blame] | 269 | mov r1, r6 /* dest_addr */ |
Heiko Schocher | abef7b8 | 2010-09-17 13:10:52 +0200 | [diff] [blame] | 270 | /* jump to it ... */ |
Heiko Schocher | abef7b8 | 2010-09-17 13:10:52 +0200 | [diff] [blame] | 271 | mov pc, lr |
| 272 | |
Albert Aribaud | 3336ca6 | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 273 | _board_init_r_ofs: |
| 274 | .word board_init_r - _start |
| 275 | |
| 276 | _rel_dyn_start_ofs: |
| 277 | .word __rel_dyn_start - _start |
| 278 | _rel_dyn_end_ofs: |
| 279 | .word __rel_dyn_end - _start |
| 280 | _dynsym_start_ofs: |
| 281 | .word __dynsym_start - _start |
Heiko Schocher | abef7b8 | 2010-09-17 13:10:52 +0200 | [diff] [blame] | 282 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 283 | /* |
| 284 | ************************************************************************* |
| 285 | * |
| 286 | * CPU_init_critical registers |
| 287 | * |
| 288 | * setup important registers |
| 289 | * setup memory timing |
| 290 | * |
| 291 | ************************************************************************* |
| 292 | */ |
| 293 | |
Wolfgang Denk | c1f8750 | 2011-09-05 14:37:30 +0200 | [diff] [blame] | 294 | #if defined(CONFIG_LPC2292) |
Gary Jennejohn | 6bd2447 | 2007-01-24 12:16:56 +0100 | [diff] [blame] | 295 | PLLCFG_ADR: .word PLLCFG |
| 296 | PLLFEED_ADR: .word PLLFEED |
| 297 | PLLCON_ADR: .word PLLCON |
| 298 | PLLSTAT_ADR: .word PLLSTAT |
| 299 | VPBDIV_ADR: .word VPBDIV |
| 300 | MEMMAP_ADR: .word MEMMAP |
| 301 | |
wdenk | 3953988 | 2004-07-01 16:30:44 +0000 | [diff] [blame] | 302 | #endif |
| 303 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 304 | cpu_init_crit: |
Wolfgang Denk | c1f8750 | 2011-09-05 14:37:30 +0200 | [diff] [blame] | 305 | #if defined(CONFIG_NETARM) |
wdenk | 2d1a537 | 2004-02-23 19:30:57 +0000 | [diff] [blame] | 306 | /* |
| 307 | * prior to software reset : need to set pin PORTC4 to be *HRESET |
| 308 | */ |
| 309 | ldr r0, =NETARM_GEN_MODULE_BASE |
| 310 | ldr r1, =(NETARM_GEN_PORT_MODE(0x10) | \ |
| 311 | NETARM_GEN_PORT_DIR(0x10)) |
| 312 | str r1, [r0, #+NETARM_GEN_PORTC] |
| 313 | /* |
| 314 | * software reset : see HW Ref. Guide 8.2.4 : Software Service register |
wdenk | cdc7fea | 2004-07-11 22:27:55 +0000 | [diff] [blame] | 315 | * for an explanation of this process |
wdenk | 2d1a537 | 2004-02-23 19:30:57 +0000 | [diff] [blame] | 316 | */ |
| 317 | ldr r0, =NETARM_GEN_MODULE_BASE |
| 318 | ldr r1, =NETARM_GEN_SW_SVC_RESETA |
| 319 | str r1, [r0, #+NETARM_GEN_SOFTWARE_SERVICE] |
| 320 | ldr r1, =NETARM_GEN_SW_SVC_RESETB |
| 321 | str r1, [r0, #+NETARM_GEN_SOFTWARE_SERVICE] |
| 322 | ldr r1, =NETARM_GEN_SW_SVC_RESETA |
| 323 | str r1, [r0, #+NETARM_GEN_SOFTWARE_SERVICE] |
| 324 | ldr r1, =NETARM_GEN_SW_SVC_RESETB |
| 325 | str r1, [r0, #+NETARM_GEN_SOFTWARE_SERVICE] |
| 326 | /* |
| 327 | * setup PLL and System Config |
| 328 | */ |
| 329 | ldr r0, =NETARM_GEN_MODULE_BASE |
| 330 | |
| 331 | ldr r1, =( NETARM_GEN_SYS_CFG_LENDIAN | \ |
| 332 | NETARM_GEN_SYS_CFG_BUSFULL | \ |
| 333 | NETARM_GEN_SYS_CFG_USER_EN | \ |
| 334 | NETARM_GEN_SYS_CFG_ALIGN_ABORT | \ |
| 335 | NETARM_GEN_SYS_CFG_BUSARB_INT | \ |
| 336 | NETARM_GEN_SYS_CFG_BUSMON_EN ) |
| 337 | |
| 338 | str r1, [r0, #+NETARM_GEN_SYSTEM_CONTROL] |
| 339 | |
Wolfgang Denk | 3df5bea | 2005-10-09 01:41:48 +0200 | [diff] [blame] | 340 | #ifndef CONFIG_NETARM_PLL_BYPASS |
wdenk | 2d1a537 | 2004-02-23 19:30:57 +0000 | [diff] [blame] | 341 | ldr r1, =( NETARM_GEN_PLL_CTL_PLLCNT(NETARM_PLL_COUNT_VAL) | \ |
| 342 | NETARM_GEN_PLL_CTL_POLTST_DEF | \ |
| 343 | NETARM_GEN_PLL_CTL_INDIV(1) | \ |
| 344 | NETARM_GEN_PLL_CTL_ICP_DEF | \ |
| 345 | NETARM_GEN_PLL_CTL_OUTDIV(2) ) |
| 346 | str r1, [r0, #+NETARM_GEN_PLL_CONTROL] |
Wolfgang Denk | 3df5bea | 2005-10-09 01:41:48 +0200 | [diff] [blame] | 347 | #endif |
| 348 | |
wdenk | 2d1a537 | 2004-02-23 19:30:57 +0000 | [diff] [blame] | 349 | /* |
| 350 | * mask all IRQs by clearing all bits in the INTMRs |
| 351 | */ |
| 352 | mov r1, #0 |
| 353 | ldr r0, =NETARM_GEN_MODULE_BASE |
| 354 | str r1, [r0, #+NETARM_GEN_INTR_ENABLE] |
wdenk | 3953988 | 2004-07-01 16:30:44 +0000 | [diff] [blame] | 355 | |
| 356 | #elif defined(CONFIG_S3C4510B) |
| 357 | |
| 358 | /* |
| 359 | * Mask off all IRQ sources |
| 360 | */ |
| 361 | ldr r1, =REG_INTMASK |
| 362 | ldr r0, =0x3FFFFF |
| 363 | str r0, [r1] |
| 364 | |
| 365 | /* |
| 366 | * Disable Cache |
| 367 | */ |
| 368 | ldr r0, =REG_SYSCFG |
wdenk | cdc7fea | 2004-07-11 22:27:55 +0000 | [diff] [blame] | 369 | ldr r1, =0x83ffffa0 /* cache-disabled */ |
wdenk | 3953988 | 2004-07-01 16:30:44 +0000 | [diff] [blame] | 370 | str r1, [r0] |
| 371 | |
Wolfgang Denk | 87cb686 | 2005-10-06 17:08:18 +0200 | [diff] [blame] | 372 | #elif defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_INTEGRATOR) |
| 373 | /* No specific initialisation for IntegratorAP/CM720T as yet */ |
Gary Jennejohn | 6bd2447 | 2007-01-24 12:16:56 +0100 | [diff] [blame] | 374 | #elif defined(CONFIG_LPC2292) |
| 375 | /* Set-up PLL */ |
| 376 | mov r3, #0xAA |
| 377 | mov r4, #0x55 |
Wolfgang Denk | f8db84f | 2007-01-30 00:50:40 +0100 | [diff] [blame] | 378 | /* First disconnect and disable the PLL */ |
Gary Jennejohn | 6bd2447 | 2007-01-24 12:16:56 +0100 | [diff] [blame] | 379 | ldr r0, PLLCON_ADR |
| 380 | mov r1, #0x00 |
| 381 | str r1, [r0] |
| 382 | ldr r0, PLLFEED_ADR /* start feed sequence */ |
| 383 | str r3, [r0] |
Wolfgang Denk | f8db84f | 2007-01-30 00:50:40 +0100 | [diff] [blame] | 384 | str r4, [r0] /* feed sequence done */ |
Gary Jennejohn | 6bd2447 | 2007-01-24 12:16:56 +0100 | [diff] [blame] | 385 | /* Set new M and P values */ |
| 386 | ldr r0, PLLCFG_ADR |
| 387 | mov r1, #0x23 /* M=4 and P=2 */ |
| 388 | str r1, [r0] |
| 389 | ldr r0, PLLFEED_ADR /* start feed sequence */ |
| 390 | str r3, [r0] |
| 391 | str r4, [r0] /* feed sequence done */ |
| 392 | /* Then enable the PLL */ |
| 393 | ldr r0, PLLCON_ADR |
| 394 | mov r1, #0x01 /* PLL enable bit */ |
| 395 | str r1, [r0] |
| 396 | ldr r0, PLLFEED_ADR /* start feed sequence */ |
| 397 | str r3, [r0] |
| 398 | str r4, [r0] /* feed sequence done */ |
Wolfgang Denk | f8db84f | 2007-01-30 00:50:40 +0100 | [diff] [blame] | 399 | /* Wait for the lock */ |
Gary Jennejohn | 6bd2447 | 2007-01-24 12:16:56 +0100 | [diff] [blame] | 400 | ldr r0, PLLSTAT_ADR |
| 401 | mov r1, #0x400 /* lock bit */ |
Wolfgang Denk | f8db84f | 2007-01-30 00:50:40 +0100 | [diff] [blame] | 402 | lock_loop: |
Gary Jennejohn | 6bd2447 | 2007-01-24 12:16:56 +0100 | [diff] [blame] | 403 | ldr r2, [r0] |
| 404 | and r2, r1, r2 |
| 405 | cmp r2, #0 |
| 406 | beq lock_loop |
| 407 | /* And finally connect the PLL */ |
| 408 | ldr r0, PLLCON_ADR |
| 409 | mov r1, #0x03 /* PLL enable bit and connect bit */ |
| 410 | str r1, [r0] |
| 411 | ldr r0, PLLFEED_ADR /* start feed sequence */ |
| 412 | str r3, [r0] |
Wolfgang Denk | f8db84f | 2007-01-30 00:50:40 +0100 | [diff] [blame] | 413 | str r4, [r0] /* feed sequence done */ |
Gary Jennejohn | 6bd2447 | 2007-01-24 12:16:56 +0100 | [diff] [blame] | 414 | /* Set-up VPBDIV register */ |
| 415 | ldr r0, VPBDIV_ADR |
| 416 | mov r1, #0x01 /* VPB clock is same as process clock */ |
| 417 | str r1, [r0] |
Allen Martin | c037c93 | 2012-08-31 08:30:09 +0000 | [diff] [blame] | 418 | #elif defined(CONFIG_TEGRA) |
| 419 | /* No cpu_init_crit for tegra as yet */ |
wdenk | 3953988 | 2004-07-01 16:30:44 +0000 | [diff] [blame] | 420 | #else |
| 421 | #error No cpu_init_crit() defined for current CPU type |
| 422 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 423 | |
| 424 | #ifdef CONFIG_ARM7_REVD |
| 425 | /* set clock speed */ |
| 426 | /* !!! we run @ 36 MHz due to a hardware flaw in Rev. D processors */ |
| 427 | /* !!! not doing DRAM refresh properly! */ |
| 428 | ldr r0, SYSCON3 |
| 429 | ldr r1, [r0] |
| 430 | bic r1, r1, #CLKCTL |
| 431 | orr r1, r1, #CLKCTL_36 |
| 432 | str r1, [r0] |
| 433 | #endif |
| 434 | |
Allen Martin | c037c93 | 2012-08-31 08:30:09 +0000 | [diff] [blame] | 435 | #if !defined(CONFIG_LPC2292) && !defined(CONFIG_TEGRA) |
Wolfgang Denk | 87cb686 | 2005-10-06 17:08:18 +0200 | [diff] [blame] | 436 | mov ip, lr |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 437 | /* |
| 438 | * before relocating, we have to setup RAM timing |
wdenk | f6e20fc | 2004-02-08 19:38:38 +0000 | [diff] [blame] | 439 | * because memory timing is board-dependent, you will |
wdenk | 400558b | 2005-04-02 23:52:25 +0000 | [diff] [blame] | 440 | * find a lowlevel_init.S in your board directory. |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 441 | */ |
wdenk | 400558b | 2005-04-02 23:52:25 +0000 | [diff] [blame] | 442 | bl lowlevel_init |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 443 | mov lr, ip |
Gary Jennejohn | 6bd2447 | 2007-01-24 12:16:56 +0100 | [diff] [blame] | 444 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 445 | |
| 446 | mov pc, lr |
| 447 | |
| 448 | |
Allen Martin | c7da6c6 | 2012-08-31 08:30:07 +0000 | [diff] [blame] | 449 | #ifndef CONFIG_SPL_BUILD |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 450 | /* |
| 451 | ************************************************************************* |
| 452 | * |
| 453 | * Interrupt handling |
| 454 | * |
| 455 | ************************************************************************* |
| 456 | */ |
| 457 | |
| 458 | @ |
| 459 | @ IRQ stack frame. |
| 460 | @ |
| 461 | #define S_FRAME_SIZE 72 |
| 462 | |
| 463 | #define S_OLD_R0 68 |
| 464 | #define S_PSR 64 |
| 465 | #define S_PC 60 |
| 466 | #define S_LR 56 |
| 467 | #define S_SP 52 |
| 468 | |
| 469 | #define S_IP 48 |
| 470 | #define S_FP 44 |
| 471 | #define S_R10 40 |
| 472 | #define S_R9 36 |
| 473 | #define S_R8 32 |
| 474 | #define S_R7 28 |
| 475 | #define S_R6 24 |
| 476 | #define S_R5 20 |
| 477 | #define S_R4 16 |
| 478 | #define S_R3 12 |
| 479 | #define S_R2 8 |
| 480 | #define S_R1 4 |
| 481 | #define S_R0 0 |
| 482 | |
| 483 | #define MODE_SVC 0x13 |
| 484 | #define I_BIT 0x80 |
| 485 | |
| 486 | /* |
| 487 | * use bad_save_user_regs for abort/prefetch/undef/swi ... |
| 488 | * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling |
| 489 | */ |
| 490 | |
| 491 | .macro bad_save_user_regs |
| 492 | sub sp, sp, #S_FRAME_SIZE |
| 493 | stmia sp, {r0 - r12} @ Calling r0-r12 |
wdenk | cdc7fea | 2004-07-11 22:27:55 +0000 | [diff] [blame] | 494 | add r8, sp, #S_PC |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 495 | |
Heiko Schocher | abef7b8 | 2010-09-17 13:10:52 +0200 | [diff] [blame] | 496 | ldr r2, IRQ_STACK_START_IN |
wdenk | cdc7fea | 2004-07-11 22:27:55 +0000 | [diff] [blame] | 497 | ldmia r2, {r2 - r4} @ get pc, cpsr, old_r0 |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 498 | add r0, sp, #S_FRAME_SIZE @ restore sp_SVC |
| 499 | |
| 500 | add r5, sp, #S_SP |
| 501 | mov r1, lr |
wdenk | cdc7fea | 2004-07-11 22:27:55 +0000 | [diff] [blame] | 502 | stmia r5, {r0 - r4} @ save sp_SVC, lr_SVC, pc, cpsr, old_r |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 503 | mov r0, sp |
| 504 | .endm |
| 505 | |
| 506 | .macro irq_save_user_regs |
| 507 | sub sp, sp, #S_FRAME_SIZE |
| 508 | stmia sp, {r0 - r12} @ Calling r0-r12 |
wdenk | cdc7fea | 2004-07-11 22:27:55 +0000 | [diff] [blame] | 509 | add r8, sp, #S_PC |
| 510 | stmdb r8, {sp, lr}^ @ Calling SP, LR |
| 511 | str lr, [r8, #0] @ Save calling PC |
| 512 | mrs r6, spsr |
| 513 | str r6, [r8, #4] @ Save CPSR |
| 514 | str r0, [r8, #8] @ Save OLD_R0 |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 515 | mov r0, sp |
| 516 | .endm |
| 517 | |
| 518 | .macro irq_restore_user_regs |
| 519 | ldmia sp, {r0 - lr}^ @ Calling r0 - lr |
| 520 | mov r0, r0 |
| 521 | ldr lr, [sp, #S_PC] @ Get PC |
| 522 | add sp, sp, #S_FRAME_SIZE |
| 523 | subs pc, lr, #4 @ return & move spsr_svc into cpsr |
| 524 | .endm |
| 525 | |
| 526 | .macro get_bad_stack |
Heiko Schocher | abef7b8 | 2010-09-17 13:10:52 +0200 | [diff] [blame] | 527 | ldr r13, IRQ_STACK_START_IN @ setup our mode stack |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 528 | |
| 529 | str lr, [r13] @ save caller lr / spsr |
| 530 | mrs lr, spsr |
wdenk | cdc7fea | 2004-07-11 22:27:55 +0000 | [diff] [blame] | 531 | str lr, [r13, #4] |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 532 | |
| 533 | mov r13, #MODE_SVC @ prepare SVC-Mode |
| 534 | msr spsr_c, r13 |
| 535 | mov lr, pc |
| 536 | movs pc, lr |
| 537 | .endm |
| 538 | |
| 539 | .macro get_irq_stack @ setup IRQ stack |
| 540 | ldr sp, IRQ_STACK_START |
| 541 | .endm |
| 542 | |
| 543 | .macro get_fiq_stack @ setup FIQ stack |
| 544 | ldr sp, FIQ_STACK_START |
| 545 | .endm |
| 546 | |
| 547 | /* |
| 548 | * exception handlers |
| 549 | */ |
wdenk | cdc7fea | 2004-07-11 22:27:55 +0000 | [diff] [blame] | 550 | .align 5 |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 551 | undefined_instruction: |
| 552 | get_bad_stack |
| 553 | bad_save_user_regs |
wdenk | cdc7fea | 2004-07-11 22:27:55 +0000 | [diff] [blame] | 554 | bl do_undefined_instruction |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 555 | |
| 556 | .align 5 |
| 557 | software_interrupt: |
| 558 | get_bad_stack |
| 559 | bad_save_user_regs |
wdenk | cdc7fea | 2004-07-11 22:27:55 +0000 | [diff] [blame] | 560 | bl do_software_interrupt |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 561 | |
| 562 | .align 5 |
| 563 | prefetch_abort: |
| 564 | get_bad_stack |
| 565 | bad_save_user_regs |
wdenk | cdc7fea | 2004-07-11 22:27:55 +0000 | [diff] [blame] | 566 | bl do_prefetch_abort |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 567 | |
| 568 | .align 5 |
| 569 | data_abort: |
| 570 | get_bad_stack |
| 571 | bad_save_user_regs |
wdenk | cdc7fea | 2004-07-11 22:27:55 +0000 | [diff] [blame] | 572 | bl do_data_abort |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 573 | |
| 574 | .align 5 |
| 575 | not_used: |
| 576 | get_bad_stack |
| 577 | bad_save_user_regs |
wdenk | cdc7fea | 2004-07-11 22:27:55 +0000 | [diff] [blame] | 578 | bl do_not_used |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 579 | |
| 580 | #ifdef CONFIG_USE_IRQ |
| 581 | |
| 582 | .align 5 |
| 583 | irq: |
| 584 | get_irq_stack |
| 585 | irq_save_user_regs |
wdenk | cdc7fea | 2004-07-11 22:27:55 +0000 | [diff] [blame] | 586 | bl do_irq |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 587 | irq_restore_user_regs |
| 588 | |
| 589 | .align 5 |
| 590 | fiq: |
| 591 | get_fiq_stack |
| 592 | /* someone ought to write a more effiction fiq_save_user_regs */ |
| 593 | irq_save_user_regs |
wdenk | cdc7fea | 2004-07-11 22:27:55 +0000 | [diff] [blame] | 594 | bl do_fiq |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 595 | irq_restore_user_regs |
| 596 | |
| 597 | #else |
| 598 | |
| 599 | .align 5 |
| 600 | irq: |
| 601 | get_bad_stack |
| 602 | bad_save_user_regs |
wdenk | cdc7fea | 2004-07-11 22:27:55 +0000 | [diff] [blame] | 603 | bl do_irq |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 604 | |
| 605 | .align 5 |
| 606 | fiq: |
| 607 | get_bad_stack |
| 608 | bad_save_user_regs |
wdenk | cdc7fea | 2004-07-11 22:27:55 +0000 | [diff] [blame] | 609 | bl do_fiq |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 610 | |
| 611 | #endif |
Allen Martin | c7da6c6 | 2012-08-31 08:30:07 +0000 | [diff] [blame] | 612 | #endif /* CONFIG_SPL_BUILD */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 613 | |
Wolfgang Denk | c1f8750 | 2011-09-05 14:37:30 +0200 | [diff] [blame] | 614 | #if defined(CONFIG_NETARM) |
wdenk | 3953988 | 2004-07-01 16:30:44 +0000 | [diff] [blame] | 615 | .align 5 |
| 616 | .globl reset_cpu |
| 617 | reset_cpu: |
wdenk | 2d1a537 | 2004-02-23 19:30:57 +0000 | [diff] [blame] | 618 | ldr r1, =NETARM_MEM_MODULE_BASE |
| 619 | ldr r0, [r1, #+NETARM_MEM_CS0_BASE_ADDR] |
| 620 | ldr r1, =0xFFFFF000 |
| 621 | and r0, r1, r0 |
Wolfgang Denk | 14d0a02 | 2010-10-07 21:51:12 +0200 | [diff] [blame] | 622 | ldr r1, =(relocate-CONFIG_SYS_TEXT_BASE) |
wdenk | 2d1a537 | 2004-02-23 19:30:57 +0000 | [diff] [blame] | 623 | add r0, r1, r0 |
| 624 | ldr r4, =NETARM_GEN_MODULE_BASE |
| 625 | ldr r1, =NETARM_GEN_SW_SVC_RESETA |
| 626 | str r1, [r4, #+NETARM_GEN_SOFTWARE_SERVICE] |
| 627 | ldr r1, =NETARM_GEN_SW_SVC_RESETB |
| 628 | str r1, [r4, #+NETARM_GEN_SOFTWARE_SERVICE] |
| 629 | ldr r1, =NETARM_GEN_SW_SVC_RESETA |
| 630 | str r1, [r4, #+NETARM_GEN_SOFTWARE_SERVICE] |
| 631 | ldr r1, =NETARM_GEN_SW_SVC_RESETB |
| 632 | str r1, [r4, #+NETARM_GEN_SOFTWARE_SERVICE] |
| 633 | mov pc, r0 |
wdenk | 3953988 | 2004-07-01 16:30:44 +0000 | [diff] [blame] | 634 | #elif defined(CONFIG_S3C4510B) |
| 635 | /* Nothing done here as reseting the CPU is board specific, depending |
| 636 | * on external peripherals such as watchdog timers, etc. */ |
Wolfgang Denk | 87cb686 | 2005-10-06 17:08:18 +0200 | [diff] [blame] | 637 | #elif defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_INTEGRATOR) |
| 638 | /* No specific reset actions for IntegratorAP/CM720T as yet */ |
Gary Jennejohn | 6bd2447 | 2007-01-24 12:16:56 +0100 | [diff] [blame] | 639 | #elif defined(CONFIG_LPC2292) |
| 640 | .align 5 |
| 641 | .globl reset_cpu |
| 642 | reset_cpu: |
| 643 | mov pc, r0 |
Allen Martin | c037c93 | 2012-08-31 08:30:09 +0000 | [diff] [blame] | 644 | #elif defined(CONFIG_TEGRA) |
| 645 | /* No specific reset actions for tegra as yet */ |
wdenk | 3953988 | 2004-07-01 16:30:44 +0000 | [diff] [blame] | 646 | #else |
| 647 | #error No reset_cpu() defined for current CPU type |
wdenk | 2d1a537 | 2004-02-23 19:30:57 +0000 | [diff] [blame] | 648 | #endif |