Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * File: arch/blackfin/mach-bf561/head.S |
| 3 | * Based on: arch/blackfin/mach-bf533/head.S |
| 4 | * Author: |
| 5 | * |
| 6 | * Created: |
| 7 | * Description: BF561 startup file |
| 8 | * |
| 9 | * Modified: |
| 10 | * Copyright 2004-2006 Analog Devices Inc. |
| 11 | * |
| 12 | * Bugs: Enter bugs at http://blackfin.uclinux.org/ |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License as published by |
| 16 | * the Free Software Foundation; either version 2 of the License, or |
| 17 | * (at your option) any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, see the file COPYING, or write |
| 26 | * to the Free Software Foundation, Inc., |
| 27 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 28 | */ |
| 29 | |
| 30 | #include <linux/linkage.h> |
| 31 | #include <asm/blackfin.h> |
| 32 | #if CONFIG_BFIN_KERNEL_CLOCK |
| 33 | #include <asm/mach/mem_init.h> |
| 34 | #endif |
| 35 | |
| 36 | .global __rambase |
| 37 | .global __ramstart |
| 38 | .global __ramend |
| 39 | .extern ___bss_stop |
| 40 | .extern ___bss_start |
| 41 | .extern _bf53x_relocate_l1_mem |
| 42 | |
| 43 | #define INITIAL_STACK 0xFFB01000 |
| 44 | |
| 45 | .text |
| 46 | |
| 47 | ENTRY(__start) |
| 48 | ENTRY(__stext) |
Mike Frysinger | 83a5c3e | 2007-06-11 15:31:30 +0800 | [diff] [blame^] | 49 | /* R0: argument of command line string, passed from uboot, save it */ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 50 | R7 = R0; |
Mike Frysinger | 83a5c3e | 2007-06-11 15:31:30 +0800 | [diff] [blame^] | 51 | /* Set the SYSCFG register: |
| 52 | * Enable Cycle Counter and Nesting Of Interrupts (3rd Bit) |
| 53 | */ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 54 | R0 = 0x36; |
Mike Frysinger | 83a5c3e | 2007-06-11 15:31:30 +0800 | [diff] [blame^] | 55 | SYSCFG = R0; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 56 | R0 = 0; |
| 57 | |
Mike Frysinger | 83a5c3e | 2007-06-11 15:31:30 +0800 | [diff] [blame^] | 58 | /* Clear Out All the data and pointer Registers */ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 59 | R1 = R0; |
| 60 | R2 = R0; |
| 61 | R3 = R0; |
| 62 | R4 = R0; |
| 63 | R5 = R0; |
| 64 | R6 = R0; |
| 65 | |
| 66 | P0 = R0; |
| 67 | P1 = R0; |
| 68 | P2 = R0; |
| 69 | P3 = R0; |
| 70 | P4 = R0; |
| 71 | P5 = R0; |
| 72 | |
| 73 | LC0 = r0; |
| 74 | LC1 = r0; |
| 75 | L0 = r0; |
| 76 | L1 = r0; |
| 77 | L2 = r0; |
| 78 | L3 = r0; |
| 79 | |
Mike Frysinger | 83a5c3e | 2007-06-11 15:31:30 +0800 | [diff] [blame^] | 80 | /* Clear Out All the DAG Registers */ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 81 | B0 = r0; |
| 82 | B1 = r0; |
| 83 | B2 = r0; |
| 84 | B3 = r0; |
| 85 | |
| 86 | I0 = r0; |
| 87 | I1 = r0; |
| 88 | I2 = r0; |
| 89 | I3 = r0; |
| 90 | |
| 91 | M0 = r0; |
| 92 | M1 = r0; |
| 93 | M2 = r0; |
| 94 | M3 = r0; |
| 95 | |
| 96 | /* Turn off the icache */ |
| 97 | p0.l = (IMEM_CONTROL & 0xFFFF); |
| 98 | p0.h = (IMEM_CONTROL >> 16); |
| 99 | R1 = [p0]; |
| 100 | R0 = ~ENICPLB; |
| 101 | R0 = R0 & R1; |
| 102 | |
| 103 | /* Anomaly 05000125 */ |
| 104 | #ifdef ANOMALY_05000125 |
| 105 | CLI R2; |
| 106 | SSYNC; |
| 107 | #endif |
| 108 | [p0] = R0; |
| 109 | SSYNC; |
| 110 | #ifdef ANOMALY_05000125 |
| 111 | STI R2; |
| 112 | #endif |
| 113 | |
| 114 | /* Turn off the dcache */ |
| 115 | p0.l = (DMEM_CONTROL & 0xFFFF); |
| 116 | p0.h = (DMEM_CONTROL >> 16); |
| 117 | R1 = [p0]; |
| 118 | R0 = ~ENDCPLB; |
| 119 | R0 = R0 & R1; |
| 120 | |
| 121 | /* Anomaly 05000125 */ |
| 122 | #ifdef ANOMALY_05000125 |
| 123 | CLI R2; |
| 124 | SSYNC; |
| 125 | #endif |
| 126 | [p0] = R0; |
| 127 | SSYNC; |
| 128 | #ifdef ANOMALY_05000125 |
| 129 | STI R2; |
| 130 | #endif |
| 131 | |
Mike Frysinger | 5079df9 | 2007-05-21 18:09:27 +0800 | [diff] [blame] | 132 | /* Initialise UART - when booting from u-boot, the UART is not disabled |
| 133 | * so if we dont initalize here, our serial console gets hosed */ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 134 | p0.h = hi(UART_LCR); |
| 135 | p0.l = lo(UART_LCR); |
| 136 | r0 = 0x0(Z); |
| 137 | w[p0] = r0.L; /* To enable DLL writes */ |
| 138 | ssync; |
| 139 | |
| 140 | p0.h = hi(UART_DLL); |
| 141 | p0.l = lo(UART_DLL); |
| 142 | r0 = 0x0(Z); |
| 143 | w[p0] = r0.L; |
| 144 | ssync; |
| 145 | |
| 146 | p0.h = hi(UART_DLH); |
| 147 | p0.l = lo(UART_DLH); |
| 148 | r0 = 0x00(Z); |
| 149 | w[p0] = r0.L; |
| 150 | ssync; |
| 151 | |
| 152 | p0.h = hi(UART_GCTL); |
| 153 | p0.l = lo(UART_GCTL); |
| 154 | r0 = 0x0(Z); |
| 155 | w[p0] = r0.L; /* To enable UART clock */ |
| 156 | ssync; |
| 157 | |
| 158 | /* Initialize stack pointer */ |
| 159 | sp.l = lo(INITIAL_STACK); |
| 160 | sp.h = hi(INITIAL_STACK); |
| 161 | fp = sp; |
| 162 | usp = sp; |
| 163 | |
| 164 | /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */ |
| 165 | call _bf53x_relocate_l1_mem; |
| 166 | #if CONFIG_BFIN_KERNEL_CLOCK |
| 167 | call _start_dma_code; |
| 168 | #endif |
| 169 | |
| 170 | /* Code for initializing Async memory banks */ |
| 171 | |
| 172 | p2.h = hi(EBIU_AMBCTL1); |
| 173 | p2.l = lo(EBIU_AMBCTL1); |
| 174 | r0.h = hi(AMBCTL1VAL); |
| 175 | r0.l = lo(AMBCTL1VAL); |
| 176 | [p2] = r0; |
| 177 | ssync; |
| 178 | |
| 179 | p2.h = hi(EBIU_AMBCTL0); |
| 180 | p2.l = lo(EBIU_AMBCTL0); |
| 181 | r0.h = hi(AMBCTL0VAL); |
| 182 | r0.l = lo(AMBCTL0VAL); |
| 183 | [p2] = r0; |
| 184 | ssync; |
| 185 | |
| 186 | p2.h = hi(EBIU_AMGCTL); |
| 187 | p2.l = lo(EBIU_AMGCTL); |
| 188 | r0 = AMGCTLVAL; |
| 189 | w[p2] = r0; |
| 190 | ssync; |
| 191 | |
| 192 | /* This section keeps the processor in supervisor mode |
| 193 | * during kernel boot. Switches to user mode at end of boot. |
| 194 | * See page 3-9 of Hardware Reference manual for documentation. |
| 195 | */ |
| 196 | |
| 197 | /* EVT15 = _real_start */ |
| 198 | |
| 199 | p0.l = lo(EVT15); |
| 200 | p0.h = hi(EVT15); |
| 201 | p1.l = _real_start; |
| 202 | p1.h = _real_start; |
| 203 | [p0] = p1; |
| 204 | csync; |
| 205 | |
| 206 | p0.l = lo(IMASK); |
| 207 | p0.h = hi(IMASK); |
| 208 | p1.l = IMASK_IVG15; |
| 209 | p1.h = 0x0; |
| 210 | [p0] = p1; |
| 211 | csync; |
| 212 | |
| 213 | raise 15; |
| 214 | p0.l = .LWAIT_HERE; |
| 215 | p0.h = .LWAIT_HERE; |
| 216 | reti = p0; |
| 217 | #if defined(ANOMALY_05000281) |
| 218 | nop; nop; nop; |
| 219 | #endif |
| 220 | rti; |
| 221 | |
| 222 | .LWAIT_HERE: |
| 223 | jump .LWAIT_HERE; |
| 224 | |
| 225 | ENTRY(_real_start) |
| 226 | [ -- sp ] = reti; |
| 227 | p0.l = lo(WDOGA_CTL); |
| 228 | p0.h = hi(WDOGA_CTL); |
| 229 | r0 = 0xAD6(z); |
| 230 | w[p0] = r0; /* watchdog off for now */ |
| 231 | ssync; |
| 232 | |
| 233 | /* Code update for BSS size == 0 |
| 234 | * Zero out the bss region. |
| 235 | */ |
| 236 | |
| 237 | p1.l = ___bss_start; |
| 238 | p1.h = ___bss_start; |
| 239 | p2.l = ___bss_stop; |
| 240 | p2.h = ___bss_stop; |
| 241 | r0 = 0; |
| 242 | p2 -= p1; |
Mike Frysinger | 83a5c3e | 2007-06-11 15:31:30 +0800 | [diff] [blame^] | 243 | lsetup (.L_clear_bss, .L_clear_bss) lc0 = p2; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 244 | .L_clear_bss: |
| 245 | B[p1++] = r0; |
| 246 | |
| 247 | /* In case there is a NULL pointer reference |
| 248 | * Zero out region before stext |
| 249 | */ |
| 250 | |
| 251 | p1.l = 0x0; |
| 252 | p1.h = 0x0; |
| 253 | r0.l = __stext; |
| 254 | r0.h = __stext; |
| 255 | r0 = r0 >> 1; |
| 256 | p2 = r0; |
| 257 | r0 = 0; |
Mike Frysinger | 83a5c3e | 2007-06-11 15:31:30 +0800 | [diff] [blame^] | 258 | lsetup (.L_clear_zero, .L_clear_zero) lc0 = p2; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 259 | .L_clear_zero: |
| 260 | W[p1++] = r0; |
| 261 | |
Mike Frysinger | 83a5c3e | 2007-06-11 15:31:30 +0800 | [diff] [blame^] | 262 | /* pass the uboot arguments to the global value command line */ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 263 | R0 = R7; |
| 264 | call _cmdline_init; |
| 265 | |
| 266 | p1.l = __rambase; |
| 267 | p1.h = __rambase; |
| 268 | r0.l = __sdata; |
| 269 | r0.h = __sdata; |
| 270 | [p1] = r0; |
| 271 | |
| 272 | p1.l = __ramstart; |
| 273 | p1.h = __ramstart; |
| 274 | p3.l = ___bss_stop; |
| 275 | p3.h = ___bss_stop; |
| 276 | |
| 277 | r1 = p3; |
| 278 | [p1] = r1; |
| 279 | |
| 280 | /* |
| 281 | * load the current thread pointer and stack |
| 282 | */ |
| 283 | r1.l = _init_thread_union; |
| 284 | r1.h = _init_thread_union; |
| 285 | |
| 286 | r2.l = 0x2000; |
| 287 | r2.h = 0x0000; |
| 288 | r1 = r1 + r2; |
| 289 | sp = r1; |
| 290 | usp = sp; |
| 291 | fp = sp; |
| 292 | call _start_kernel; |
| 293 | .L_exit: |
| 294 | jump.s .L_exit; |
| 295 | |
| 296 | .section .l1.text |
| 297 | #if CONFIG_BFIN_KERNEL_CLOCK |
| 298 | ENTRY(_start_dma_code) |
| 299 | p0.h = hi(SICA_IWR0); |
| 300 | p0.l = lo(SICA_IWR0); |
| 301 | r0.l = 0x1; |
| 302 | [p0] = r0; |
| 303 | SSYNC; |
| 304 | |
| 305 | /* |
| 306 | * Set PLL_CTL |
| 307 | * - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors |
| 308 | * - [8] = BYPASS : BYPASS the PLL, run CLKIN into CCLK/SCLK |
| 309 | * - [7] = output delay (add 200ps of delay to mem signals) |
| 310 | * - [6] = input delay (add 200ps of input delay to mem signals) |
| 311 | * - [5] = PDWN : 1=All Clocks off |
| 312 | * - [3] = STOPCK : 1=Core Clock off |
| 313 | * - [1] = PLL_OFF : 1=Disable Power to PLL |
| 314 | * - [0] = DF : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL |
| 315 | * all other bits set to zero |
| 316 | */ |
| 317 | |
| 318 | p0.h = hi(PLL_LOCKCNT); |
| 319 | p0.l = lo(PLL_LOCKCNT); |
| 320 | r0 = 0x300(Z); |
| 321 | w[p0] = r0.l; |
| 322 | ssync; |
| 323 | |
| 324 | P2.H = hi(EBIU_SDGCTL); |
| 325 | P2.L = lo(EBIU_SDGCTL); |
| 326 | R0 = [P2]; |
| 327 | BITSET (R0, 24); |
| 328 | [P2] = R0; |
| 329 | SSYNC; |
| 330 | |
| 331 | r0 = CONFIG_VCO_MULT & 63; /* Load the VCO multiplier */ |
| 332 | r0 = r0 << 9; /* Shift it over, */ |
| 333 | r1 = CLKIN_HALF; /* Do we need to divide CLKIN by 2?*/ |
| 334 | r0 = r1 | r0; |
| 335 | r1 = PLL_BYPASS; /* Bypass the PLL? */ |
| 336 | r1 = r1 << 8; /* Shift it over */ |
| 337 | r0 = r1 | r0; /* add them all together */ |
| 338 | |
| 339 | p0.h = hi(PLL_CTL); |
| 340 | p0.l = lo(PLL_CTL); /* Load the address */ |
| 341 | cli r2; /* Disable interrupts */ |
| 342 | ssync; |
| 343 | w[p0] = r0.l; /* Set the value */ |
| 344 | idle; /* Wait for the PLL to stablize */ |
| 345 | sti r2; /* Enable interrupts */ |
| 346 | |
| 347 | .Lcheck_again: |
| 348 | p0.h = hi(PLL_STAT); |
| 349 | p0.l = lo(PLL_STAT); |
| 350 | R0 = W[P0](Z); |
| 351 | CC = BITTST(R0,5); |
| 352 | if ! CC jump .Lcheck_again; |
| 353 | |
| 354 | /* Configure SCLK & CCLK Dividers */ |
Mike Frysinger | 83a5c3e | 2007-06-11 15:31:30 +0800 | [diff] [blame^] | 355 | r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 356 | p0.h = hi(PLL_DIV); |
| 357 | p0.l = lo(PLL_DIV); |
| 358 | w[p0] = r0.l; |
| 359 | ssync; |
| 360 | |
| 361 | p0.l = lo(EBIU_SDRRC); |
| 362 | p0.h = hi(EBIU_SDRRC); |
| 363 | r0 = mem_SDRRC; |
| 364 | w[p0] = r0.l; |
| 365 | ssync; |
| 366 | |
| 367 | p0.l = (EBIU_SDBCTL & 0xFFFF); |
| 368 | p0.h = (EBIU_SDBCTL >> 16); /* SDRAM Memory Bank Control Register */ |
| 369 | r0 = mem_SDBCTL; |
| 370 | w[p0] = r0.l; |
| 371 | ssync; |
| 372 | |
| 373 | P2.H = hi(EBIU_SDGCTL); |
| 374 | P2.L = lo(EBIU_SDGCTL); |
| 375 | R0 = [P2]; |
| 376 | BITCLR (R0, 24); |
| 377 | p0.h = hi(EBIU_SDSTAT); |
| 378 | p0.l = lo(EBIU_SDSTAT); |
| 379 | r2.l = w[p0]; |
| 380 | cc = bittst(r2,3); |
| 381 | if !cc jump .Lskip; |
| 382 | NOP; |
| 383 | BITSET (R0, 23); |
| 384 | .Lskip: |
| 385 | [P2] = R0; |
| 386 | SSYNC; |
| 387 | |
| 388 | R0.L = lo(mem_SDGCTL); |
| 389 | R0.H = hi(mem_SDGCTL); |
| 390 | R1 = [p2]; |
| 391 | R1 = R1 | R0; |
| 392 | [P2] = R1; |
| 393 | SSYNC; |
| 394 | |
| 395 | RTS; |
| 396 | #endif /* CONFIG_BFIN_KERNEL_CLOCK */ |
| 397 | |
| 398 | ENTRY(_bfin_reset) |
| 399 | /* No more interrupts to be handled*/ |
| 400 | CLI R6; |
| 401 | SSYNC; |
| 402 | |
| 403 | #if defined(CONFIG_BFIN_SHARED_FLASH_ENET) |
| 404 | p0.h = hi(FIO_INEN); |
| 405 | p0.l = lo(FIO_INEN); |
| 406 | r0.l = ~(PF1 | PF0); |
| 407 | w[p0] = r0.l; |
| 408 | |
| 409 | p0.h = hi(FIO_DIR); |
| 410 | p0.l = lo(FIO_DIR); |
| 411 | r0.l = (PF1 | PF0); |
| 412 | w[p0] = r0.l; |
| 413 | |
| 414 | p0.h = hi(FIO_FLAG_C); |
| 415 | p0.l = lo(FIO_FLAG_C); |
| 416 | r0.l = (PF1 | PF0); |
| 417 | w[p0] = r0.l; |
| 418 | #endif |
| 419 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 420 | /* Clear the IMASK register */ |
| 421 | p0.h = hi(IMASK); |
| 422 | p0.l = lo(IMASK); |
| 423 | r0 = 0x0; |
| 424 | [p0] = r0; |
| 425 | |
| 426 | /* Clear the ILAT register */ |
| 427 | p0.h = hi(ILAT); |
| 428 | p0.l = lo(ILAT); |
| 429 | r0 = [p0]; |
| 430 | [p0] = r0; |
| 431 | SSYNC; |
| 432 | |
Mike Frysinger | ef9256d | 2007-05-21 18:09:26 +0800 | [diff] [blame] | 433 | /* make sure SYSCR is set to use BMODE */ |
| 434 | P0.h = hi(SICA_SYSCR); |
| 435 | P0.l = lo(SICA_SYSCR); |
Mike Frysinger | ac57ac3 | 2007-05-21 18:09:29 +0800 | [diff] [blame] | 436 | R0.l = 0x20; |
Mike Frysinger | ef9256d | 2007-05-21 18:09:26 +0800 | [diff] [blame] | 437 | W[P0] = R0.l; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 438 | SSYNC; |
| 439 | |
Mike Frysinger | ef9256d | 2007-05-21 18:09:26 +0800 | [diff] [blame] | 440 | /* issue a system soft reset */ |
| 441 | P1.h = hi(SICA_SWRST); |
| 442 | P1.l = lo(SICA_SWRST); |
| 443 | R1.l = 0x0007; |
| 444 | W[P1] = R1; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 445 | SSYNC; |
| 446 | |
Mike Frysinger | ef9256d | 2007-05-21 18:09:26 +0800 | [diff] [blame] | 447 | /* clear system soft reset */ |
| 448 | R0.l = 0x0000; |
| 449 | W[P0] = R0; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 450 | SSYNC; |
| 451 | |
Mike Frysinger | ef9256d | 2007-05-21 18:09:26 +0800 | [diff] [blame] | 452 | /* issue core reset */ |
| 453 | raise 1; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 454 | |
| 455 | RTS; |
Mike Frysinger | ef9256d | 2007-05-21 18:09:26 +0800 | [diff] [blame] | 456 | ENDPROC(_bfin_reset) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 457 | |
| 458 | .data |
| 459 | |
| 460 | /* |
| 461 | * Set up the usable of RAM stuff. Size of RAM is determined then |
| 462 | * an initial stack set up at the end. |
| 463 | */ |
| 464 | |
| 465 | .align 4 |
| 466 | __rambase: |
| 467 | .long 0 |
| 468 | __ramstart: |
| 469 | .long 0 |
| 470 | __ramend: |
| 471 | .long 0 |