wdenk | 2a83161 | 2005-04-06 00:04:16 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This was originally from the Lubbock u-boot port. |
| 3 | * |
| 4 | * Most of this taken from Redboot hal_platform_setup.h with cleanup |
| 5 | * |
| 6 | * NOTE: I haven't clean this up considerably, just enough to get it |
| 7 | * running. See hal_platform_setup.h for the source. See |
wdenk | 91fcc95 | 2005-04-06 13:52:31 +0000 | [diff] [blame] | 8 | * board/cradle/lowlevel_init.S for another PXA250 setup that is |
wdenk | 2a83161 | 2005-04-06 00:04:16 +0000 | [diff] [blame] | 9 | * much cleaner. |
| 10 | * |
| 11 | * See file CREDITS for list of people who contributed to this |
| 12 | * project. |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU General Public License as |
| 16 | * published by the Free Software Foundation; either version 2 of |
| 17 | * the License, or (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, write to the Free Software |
| 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 27 | * MA 02111-1307 USA |
| 28 | */ |
| 29 | |
| 30 | #include <config.h> |
| 31 | #include <version.h> |
| 32 | #include <asm/arch/pxa-regs.h> |
| 33 | |
| 34 | /* wait for coprocessor write complete */ |
| 35 | .macro CPWAIT reg |
| 36 | mrc p15,0,\reg,c2,c0,0 |
| 37 | mov \reg,\reg |
| 38 | sub pc,pc,#4 |
| 39 | .endm |
| 40 | |
| 41 | |
| 42 | /* |
| 43 | * Memory setup |
| 44 | */ |
| 45 | |
wdenk | 91fcc95 | 2005-04-06 13:52:31 +0000 | [diff] [blame] | 46 | .globl lowlevel_init |
| 47 | lowlevel_init: |
wdenk | 2a83161 | 2005-04-06 00:04:16 +0000 | [diff] [blame] | 48 | |
| 49 | /* Set up GPIO pins first ----------------------------------------- */ |
| 50 | |
| 51 | ldr r0, =GPSR0 |
| 52 | ldr r1, =CFG_GPSR0_VAL |
| 53 | str r1, [r0] |
| 54 | |
| 55 | ldr r0, =GPSR1 |
| 56 | ldr r1, =CFG_GPSR1_VAL |
| 57 | str r1, [r0] |
| 58 | |
| 59 | ldr r0, =GPSR2 |
| 60 | ldr r1, =CFG_GPSR2_VAL |
| 61 | str r1, [r0] |
| 62 | |
| 63 | ldr r0, =GPSR3 |
| 64 | ldr r1, =CFG_GPSR3_VAL |
| 65 | str r1, [r0] |
| 66 | |
| 67 | ldr r0, =GPCR0 |
| 68 | ldr r1, =CFG_GPCR0_VAL |
| 69 | str r1, [r0] |
| 70 | |
| 71 | ldr r0, =GPCR1 |
| 72 | ldr r1, =CFG_GPCR1_VAL |
| 73 | str r1, [r0] |
| 74 | |
| 75 | ldr r0, =GPCR2 |
| 76 | ldr r1, =CFG_GPCR2_VAL |
| 77 | str r1, [r0] |
| 78 | |
| 79 | ldr r0, =GPCR3 |
| 80 | ldr r1, =CFG_GPCR3_VAL |
| 81 | str r1, [r0] |
| 82 | |
| 83 | ldr r0, =GPDR0 |
| 84 | ldr r1, =CFG_GPDR0_VAL |
| 85 | str r1, [r0] |
| 86 | |
| 87 | ldr r0, =GPDR1 |
| 88 | ldr r1, =CFG_GPDR1_VAL |
| 89 | str r1, [r0] |
| 90 | |
| 91 | ldr r0, =GPDR2 |
| 92 | ldr r1, =CFG_GPDR2_VAL |
| 93 | str r1, [r0] |
| 94 | |
| 95 | ldr r0, =GPDR3 |
| 96 | ldr r1, =CFG_GPDR3_VAL |
| 97 | str r1, [r0] |
| 98 | |
| 99 | ldr r0, =GAFR0_L |
| 100 | ldr r1, =CFG_GAFR0_L_VAL |
| 101 | str r1, [r0] |
| 102 | |
| 103 | ldr r0, =GAFR0_U |
| 104 | ldr r1, =CFG_GAFR0_U_VAL |
| 105 | str r1, [r0] |
| 106 | |
| 107 | ldr r0, =GAFR1_L |
| 108 | ldr r1, =CFG_GAFR1_L_VAL |
| 109 | str r1, [r0] |
| 110 | |
| 111 | ldr r0, =GAFR1_U |
| 112 | ldr r1, =CFG_GAFR1_U_VAL |
| 113 | str r1, [r0] |
| 114 | |
| 115 | ldr r0, =GAFR2_L |
| 116 | ldr r1, =CFG_GAFR2_L_VAL |
| 117 | str r1, [r0] |
| 118 | |
| 119 | ldr r0, =GAFR2_U |
| 120 | ldr r1, =CFG_GAFR2_U_VAL |
| 121 | str r1, [r0] |
| 122 | |
| 123 | ldr r0, =GAFR3_L |
| 124 | ldr r1, =CFG_GAFR3_L_VAL |
| 125 | str r1, [r0] |
| 126 | |
| 127 | ldr r0, =GAFR3_U |
| 128 | ldr r1, =CFG_GAFR3_U_VAL |
| 129 | str r1, [r0] |
| 130 | |
| 131 | ldr r0, =PSSR /* enable GPIO pins */ |
| 132 | ldr r1, =CFG_PSSR_VAL |
| 133 | str r1, [r0] |
| 134 | |
| 135 | /* ---------------------------------------------------------------- */ |
| 136 | /* Enable memory interface */ |
| 137 | /* */ |
| 138 | /* The sequence below is based on the recommended init steps */ |
| 139 | /* detailed in the Intel PXA250 Operating Systems Developers Guide, */ |
| 140 | /* Chapter 10. */ |
| 141 | /* ---------------------------------------------------------------- */ |
| 142 | |
| 143 | /* ---------------------------------------------------------------- */ |
| 144 | /* Step 1: Wait for at least 200 microsedonds to allow internal */ |
| 145 | /* clocks to settle. Only necessary after hard reset... */ |
| 146 | /* FIXME: can be optimized later */ |
| 147 | /* ---------------------------------------------------------------- */ |
| 148 | |
| 149 | ldr r3, =OSCR /* reset the OS Timer Count to zero */ |
| 150 | mov r2, #0 |
| 151 | str r2, [r3] |
| 152 | ldr r4, =0x300 /* really 0x2E1 is about 200usec, */ |
| 153 | /* so 0x300 should be plenty */ |
| 154 | 1: |
| 155 | ldr r2, [r3] |
| 156 | cmp r4, r2 |
| 157 | bgt 1b |
| 158 | |
| 159 | mem_init: |
| 160 | |
| 161 | ldr r1, =MEMC_BASE /* get memory controller base addr. */ |
| 162 | |
| 163 | /* ---------------------------------------------------------------- */ |
| 164 | /* Step 2a: Initialize Asynchronous static memory controller */ |
| 165 | /* ---------------------------------------------------------------- */ |
| 166 | |
| 167 | /* MSC registers: timing, bus width, mem type */ |
| 168 | |
| 169 | /* MSC0: nCS(0,1) */ |
| 170 | ldr r2, =CFG_MSC0_VAL |
| 171 | str r2, [r1, #MSC0_OFFSET] |
| 172 | ldr r2, [r1, #MSC0_OFFSET] /* read back to ensure */ |
| 173 | /* that data latches */ |
| 174 | /* MSC1: nCS(2,3) */ |
| 175 | ldr r2, =CFG_MSC1_VAL |
| 176 | str r2, [r1, #MSC1_OFFSET] |
| 177 | ldr r2, [r1, #MSC1_OFFSET] |
| 178 | |
| 179 | /* MSC2: nCS(4,5) */ |
| 180 | ldr r2, =CFG_MSC2_VAL |
| 181 | str r2, [r1, #MSC2_OFFSET] |
| 182 | ldr r2, [r1, #MSC2_OFFSET] |
| 183 | |
| 184 | /* ---------------------------------------------------------------- */ |
| 185 | /* Step 2b: Initialize Card Interface */ |
| 186 | /* ---------------------------------------------------------------- */ |
| 187 | |
| 188 | /* MECR: Memory Expansion Card Register */ |
| 189 | ldr r2, =CFG_MECR_VAL |
| 190 | str r2, [r1, #MECR_OFFSET] |
| 191 | ldr r2, [r1, #MECR_OFFSET] |
| 192 | |
| 193 | /* MCMEM0: Card Interface slot 0 timing */ |
| 194 | ldr r2, =CFG_MCMEM0_VAL |
| 195 | str r2, [r1, #MCMEM0_OFFSET] |
| 196 | ldr r2, [r1, #MCMEM0_OFFSET] |
| 197 | |
| 198 | /* MCMEM1: Card Interface slot 1 timing */ |
| 199 | ldr r2, =CFG_MCMEM1_VAL |
| 200 | str r2, [r1, #MCMEM1_OFFSET] |
| 201 | ldr r2, [r1, #MCMEM1_OFFSET] |
| 202 | |
| 203 | /* MCATT0: Card Interface Attribute Space Timing, slot 0 */ |
| 204 | ldr r2, =CFG_MCATT0_VAL |
| 205 | str r2, [r1, #MCATT0_OFFSET] |
| 206 | ldr r2, [r1, #MCATT0_OFFSET] |
| 207 | |
| 208 | /* MCATT1: Card Interface Attribute Space Timing, slot 1 */ |
| 209 | ldr r2, =CFG_MCATT1_VAL |
| 210 | str r2, [r1, #MCATT1_OFFSET] |
| 211 | ldr r2, [r1, #MCATT1_OFFSET] |
| 212 | |
| 213 | /* MCIO0: Card Interface I/O Space Timing, slot 0 */ |
| 214 | ldr r2, =CFG_MCIO0_VAL |
| 215 | str r2, [r1, #MCIO0_OFFSET] |
| 216 | ldr r2, [r1, #MCIO0_OFFSET] |
| 217 | |
| 218 | /* MCIO1: Card Interface I/O Space Timing, slot 1 */ |
| 219 | ldr r2, =CFG_MCIO1_VAL |
| 220 | str r2, [r1, #MCIO1_OFFSET] |
| 221 | ldr r2, [r1, #MCIO1_OFFSET] |
| 222 | |
| 223 | /* ---------------------------------------------------------------- */ |
| 224 | /* Step 2c: Write FLYCNFG FIXME: what's that??? */ |
| 225 | /* ---------------------------------------------------------------- */ |
| 226 | ldr r2, =CFG_FLYCNFG_VAL |
| 227 | str r2, [r1, #FLYCNFG_OFFSET] |
| 228 | str r2, [r1, #FLYCNFG_OFFSET] |
| 229 | |
| 230 | /* ---------------------------------------------------------------- */ |
| 231 | /* Step 2d: Initialize Timing for Sync Memory (SDCLK0) */ |
| 232 | /* ---------------------------------------------------------------- */ |
| 233 | |
| 234 | /* Before accessing MDREFR we need a valid DRI field, so we set */ |
| 235 | /* this to power on defaults + DRI field. */ |
| 236 | |
| 237 | ldr r4, [r1, #MDREFR_OFFSET] |
| 238 | ldr r2, =0xFFF |
| 239 | bic r4, r4, r2 |
| 240 | |
| 241 | ldr r3, =CFG_MDREFR_VAL |
| 242 | and r3, r3, r2 |
| 243 | |
| 244 | orr r4, r4, r3 |
| 245 | str r4, [r1, #MDREFR_OFFSET] /* write back MDREFR */ |
| 246 | |
| 247 | orr r4, r4, #MDREFR_K0RUN |
| 248 | orr r4, r4, #MDREFR_K0DB4 |
| 249 | orr r4, r4, #MDREFR_K0FREE |
| 250 | orr r4, r4, #MDREFR_K0DB2 |
| 251 | orr r4, r4, #MDREFR_K1DB2 |
| 252 | bic r4, r4, #MDREFR_K1FREE |
| 253 | bic r4, r4, #MDREFR_K2FREE |
| 254 | |
| 255 | str r4, [r1, #MDREFR_OFFSET] /* write back MDREFR */ |
| 256 | ldr r4, [r1, #MDREFR_OFFSET] |
| 257 | |
| 258 | /* Note: preserve the mdrefr value in r4 */ |
| 259 | |
| 260 | |
| 261 | /* ---------------------------------------------------------------- */ |
| 262 | /* Step 3: Initialize Synchronous Static Memory (Flash/Peripherals) */ |
| 263 | /* ---------------------------------------------------------------- */ |
| 264 | |
| 265 | /* Initialize SXCNFG register. Assert the enable bits */ |
| 266 | |
| 267 | /* Write SXMRS to cause an MRS command to all enabled banks of */ |
| 268 | /* synchronous static memory. Note that SXLCR need not be written */ |
| 269 | /* at this time. */ |
| 270 | |
| 271 | ldr r2, =CFG_SXCNFG_VAL |
| 272 | str r2, [r1, #SXCNFG_OFFSET] |
| 273 | |
| 274 | /* ---------------------------------------------------------------- */ |
| 275 | /* Step 4: Initialize SDRAM */ |
| 276 | /* ---------------------------------------------------------------- */ |
| 277 | |
| 278 | bic r4, r4, #(MDREFR_K2FREE |MDREFR_K1FREE | MDREFR_K0FREE) |
| 279 | |
| 280 | orr r4, r4, #MDREFR_K1RUN |
| 281 | bic r4, r4, #MDREFR_K2DB2 |
| 282 | str r4, [r1, #MDREFR_OFFSET] |
| 283 | ldr r4, [r1, #MDREFR_OFFSET] |
| 284 | |
| 285 | bic r4, r4, #MDREFR_SLFRSH |
| 286 | str r4, [r1, #MDREFR_OFFSET] |
| 287 | ldr r4, [r1, #MDREFR_OFFSET] |
| 288 | |
| 289 | orr r4, r4, #MDREFR_E1PIN |
| 290 | str r4, [r1, #MDREFR_OFFSET] |
| 291 | ldr r4, [r1, #MDREFR_OFFSET] |
| 292 | |
| 293 | nop |
| 294 | nop |
| 295 | |
| 296 | |
| 297 | /* Step 4d: write MDCNFG with MDCNFG:DEx deasserted (set to 0), to */ |
| 298 | /* configure but not enable each SDRAM partition pair. */ |
| 299 | |
| 300 | ldr r4, =CFG_MDCNFG_VAL |
| 301 | bic r4, r4, #(MDCNFG_DE0|MDCNFG_DE1) |
| 302 | bic r4, r4, #(MDCNFG_DE2|MDCNFG_DE3) |
| 303 | |
| 304 | str r4, [r1, #MDCNFG_OFFSET] /* write back MDCNFG */ |
| 305 | ldr r4, [r1, #MDCNFG_OFFSET] |
| 306 | |
| 307 | |
| 308 | /* Step 4e: Wait for the clock to the SDRAMs to stabilize, */ |
| 309 | /* 100..200 µsec. */ |
| 310 | |
| 311 | ldr r3, =OSCR /* reset the OS Timer Count to zero */ |
| 312 | mov r2, #0 |
| 313 | str r2, [r3] |
| 314 | ldr r4, =0x300 /* really 0x2E1 is about 200usec, */ |
| 315 | /* so 0x300 should be plenty */ |
| 316 | 1: |
| 317 | ldr r2, [r3] |
| 318 | cmp r4, r2 |
| 319 | bgt 1b |
| 320 | |
| 321 | |
| 322 | /* Step 4f: Trigger a number (usually 8) refresh cycles by */ |
| 323 | /* attempting non-burst read or write accesses to disabled */ |
| 324 | /* SDRAM, as commonly specified in the power up sequence */ |
| 325 | /* documented in SDRAM data sheets. The address(es) used */ |
| 326 | /* for this purpose must not be cacheable. */ |
| 327 | |
| 328 | ldr r3, =CFG_DRAM_BASE |
| 329 | str r2, [r3] |
| 330 | str r2, [r3] |
| 331 | str r2, [r3] |
| 332 | str r2, [r3] |
| 333 | str r2, [r3] |
| 334 | str r2, [r3] |
| 335 | str r2, [r3] |
| 336 | str r2, [r3] |
| 337 | |
| 338 | |
| 339 | /* Step 4g: Write MDCNFG with enable bits asserted */ |
| 340 | /* (MDCNFG:DEx set to 1). */ |
| 341 | |
| 342 | ldr r3, [r1, #MDCNFG_OFFSET] |
| 343 | mov r4, r3 |
| 344 | orr r3, r3, #MDCNFG_DE0 |
| 345 | str r3, [r1, #MDCNFG_OFFSET] |
| 346 | mov r0, r3 |
| 347 | |
| 348 | /* Step 4h: Write MDMRS. */ |
| 349 | |
| 350 | ldr r2, =CFG_MDMRS_VAL |
| 351 | str r2, [r1, #MDMRS_OFFSET] |
| 352 | |
| 353 | /* enable APD */ |
| 354 | ldr r3, [r1, #MDREFR_OFFSET] |
| 355 | orr r3, r3, #MDREFR_APD |
| 356 | str r3, [r1, #MDREFR_OFFSET] |
| 357 | |
| 358 | /* We are finished with Intel's memory controller initialisation */ |
| 359 | |
| 360 | setvoltage: |
| 361 | |
| 362 | mov r10, lr |
| 363 | bl initPXAvoltage /* In case the board is rebooting with a */ |
| 364 | mov lr, r10 /* low voltage raise it up to a good one. */ |
| 365 | |
| 366 | wakeup: |
| 367 | /* Are we waking from sleep? */ |
| 368 | ldr r0, =RCSR |
| 369 | ldr r1, [r0] |
| 370 | and r1, r1, #(RCSR_GPR | RCSR_SMR | RCSR_WDR | RCSR_HWR) |
| 371 | str r1, [r0] |
| 372 | teq r1, #RCSR_SMR |
| 373 | |
| 374 | bne initirqs |
| 375 | |
| 376 | ldr r0, =PSSR |
| 377 | mov r1, #PSSR_PH |
| 378 | str r1, [r0] |
| 379 | |
| 380 | /* if so, resume at PSPR */ |
| 381 | ldr r0, =PSPR |
| 382 | ldr r1, [r0] |
| 383 | mov pc, r1 |
| 384 | |
| 385 | /* ---------------------------------------------------------------- */ |
| 386 | /* Disable (mask) all interrupts at interrupt controller */ |
| 387 | /* ---------------------------------------------------------------- */ |
| 388 | |
| 389 | initirqs: |
| 390 | |
| 391 | mov r1, #0 /* clear int. level register (IRQ, not FIQ) */ |
| 392 | ldr r2, =ICLR |
| 393 | str r1, [r2] |
| 394 | |
| 395 | ldr r2, =ICMR /* mask all interrupts at the controller */ |
| 396 | str r1, [r2] |
| 397 | |
| 398 | /* ---------------------------------------------------------------- */ |
| 399 | /* Clock initialisation */ |
| 400 | /* ---------------------------------------------------------------- */ |
| 401 | |
| 402 | initclks: |
| 403 | |
| 404 | /* Disable the peripheral clocks, and set the core clock frequency */ |
| 405 | |
| 406 | /* Turn Off on-chip peripheral clocks (except for memory) */ |
| 407 | /* for re-configuration. */ |
| 408 | ldr r1, =CKEN |
| 409 | ldr r2, =CFG_CKEN |
| 410 | str r2, [r1] |
| 411 | |
| 412 | /* ... and write the core clock config register */ |
| 413 | ldr r2, =CFG_CCCR |
| 414 | ldr r1, =CCCR |
| 415 | str r2, [r1] |
| 416 | |
| 417 | /* Turn on turbo mode */ |
| 418 | mrc p14, 0, r2, c6, c0, 0 |
| 419 | orr r2, r2, #0xB /* Turbo, Fast-Bus, Freq change**/ |
| 420 | mcr p14, 0, r2, c6, c0, 0 |
| 421 | |
| 422 | /* Re-write MDREFR */ |
| 423 | ldr r1, =MEMC_BASE |
| 424 | ldr r2, [r1, #MDREFR_OFFSET] |
| 425 | str r2, [r1, #MDREFR_OFFSET] |
| 426 | #ifdef RTC |
| 427 | /* enable the 32Khz oscillator for RTC and PowerManager */ |
| 428 | ldr r1, =OSCC |
| 429 | mov r2, #OSCC_OON |
| 430 | str r2, [r1] |
| 431 | |
| 432 | /* NOTE: spin here until OSCC.OOK get set, meaning the PLL */ |
| 433 | /* has settled. */ |
| 434 | 60: |
| 435 | ldr r2, [r1] |
| 436 | ands r2, r2, #1 |
| 437 | beq 60b |
| 438 | #else |
| 439 | #error "RTC not defined" |
| 440 | #endif |
| 441 | |
| 442 | /* Interrupt init: Mask all interrupts */ |
| 443 | ldr r0, =ICMR /* enable no sources */ |
| 444 | mov r1, #0 |
| 445 | str r1, [r0] |
| 446 | /* FIXME */ |
| 447 | |
wdenk | 2a83161 | 2005-04-06 00:04:16 +0000 | [diff] [blame] | 448 | #ifdef NODEBUG |
| 449 | /*Disable software and data breakpoints */ |
| 450 | mov r0,#0 |
| 451 | mcr p15,0,r0,c14,c8,0 /* ibcr0 */ |
| 452 | mcr p15,0,r0,c14,c9,0 /* ibcr1 */ |
| 453 | mcr p15,0,r0,c14,c4,0 /* dbcon */ |
| 454 | |
| 455 | /*Enable all debug functionality */ |
| 456 | mov r0,#0x80000000 |
| 457 | mcr p14,0,r0,c10,c0,0 /* dcsr */ |
wdenk | 2a83161 | 2005-04-06 00:04:16 +0000 | [diff] [blame] | 458 | #endif |
| 459 | |
| 460 | /* ---------------------------------------------------------------- */ |
wdenk | 91fcc95 | 2005-04-06 13:52:31 +0000 | [diff] [blame] | 461 | /* End lowlevel_init */ |
wdenk | 2a83161 | 2005-04-06 00:04:16 +0000 | [diff] [blame] | 462 | /* ---------------------------------------------------------------- */ |
| 463 | |
wdenk | 91fcc95 | 2005-04-06 13:52:31 +0000 | [diff] [blame] | 464 | endlowlevel_init: |
wdenk | 2a83161 | 2005-04-06 00:04:16 +0000 | [diff] [blame] | 465 | |
| 466 | mov pc, lr |