lowlevel_init.S 12 KB

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