lowlevel_init.S 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. /*
  2. * Most of this taken from Redboot hal_platform_setup.h with cleanup
  3. *
  4. * NOTE: I haven't clean this up considerably, just enough to get it
  5. * running. See hal_platform_setup.h for the source. See
  6. * board/cradle/lowlevel_init.S for another PXA250 setup that is
  7. * much cleaner.
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <config.h>
  28. #include <version.h>
  29. #include <asm/arch/pxa-regs.h>
  30. DRAM_SIZE: .long CONFIG_SYS_DRAM_SIZE
  31. /* wait for coprocessor write complete */
  32. .macro CPWAIT reg
  33. mrc p15,0,\reg,c2,c0,0
  34. mov \reg,\reg
  35. sub pc,pc,#4
  36. .endm
  37. /*
  38. * Memory setup
  39. */
  40. .globl lowlevel_init
  41. lowlevel_init:
  42. mov r10, lr
  43. #ifdef DEBUG_BLINK_ENABLE
  44. /* 3rd blink */
  45. bl blink
  46. #endif
  47. /* Set up GPIO pins first ----------------------------------------- */
  48. ldr r0, =GPSR0
  49. ldr r1, =CONFIG_SYS_GPSR0_VAL
  50. str r1, [r0]
  51. ldr r0, =GPSR1
  52. ldr r1, =CONFIG_SYS_GPSR1_VAL
  53. str r1, [r0]
  54. ldr r0, =GPSR2
  55. ldr r1, =CONFIG_SYS_GPSR2_VAL
  56. str r1, [r0]
  57. ldr r0, =GPCR0
  58. ldr r1, =CONFIG_SYS_GPCR0_VAL
  59. str r1, [r0]
  60. ldr r0, =GPCR1
  61. ldr r1, =CONFIG_SYS_GPCR1_VAL
  62. str r1, [r0]
  63. ldr r0, =GPCR2
  64. ldr r1, =CONFIG_SYS_GPCR2_VAL
  65. str r1, [r0]
  66. ldr r0, =GPDR0
  67. ldr r1, =CONFIG_SYS_GPDR0_VAL
  68. str r1, [r0]
  69. ldr r0, =GPDR1
  70. ldr r1, =CONFIG_SYS_GPDR1_VAL
  71. str r1, [r0]
  72. ldr r0, =GPDR2
  73. ldr r1, =CONFIG_SYS_GPDR2_VAL
  74. str r1, [r0]
  75. ldr r0, =GAFR0_L
  76. ldr r1, =CONFIG_SYS_GAFR0_L_VAL
  77. str r1, [r0]
  78. ldr r0, =GAFR0_U
  79. ldr r1, =CONFIG_SYS_GAFR0_U_VAL
  80. str r1, [r0]
  81. ldr r0, =GAFR1_L
  82. ldr r1, =CONFIG_SYS_GAFR1_L_VAL
  83. str r1, [r0]
  84. ldr r0, =GAFR1_U
  85. ldr r1, =CONFIG_SYS_GAFR1_U_VAL
  86. str r1, [r0]
  87. ldr r0, =GAFR2_L
  88. ldr r1, =CONFIG_SYS_GAFR2_L_VAL
  89. str r1, [r0]
  90. ldr r0, =GAFR2_U
  91. ldr r1, =CONFIG_SYS_GAFR2_U_VAL
  92. str r1, [r0]
  93. ldr r0, =PSSR /* enable GPIO pins */
  94. ldr r1, =CONFIG_SYS_PSSR_VAL
  95. str r1, [r0]
  96. #ifdef DEBUG_BLINK_ENABLE
  97. /* 4th debug blink */
  98. bl blink
  99. #endif
  100. /* ---------------------------------------------------------------- */
  101. /* Enable memory interface */
  102. /* */
  103. /* The sequence below is based on the recommended init steps */
  104. /* detailed in the Intel PXA250 Operating Systems Developers Guide, */
  105. /* Chapter 10. */
  106. /* ---------------------------------------------------------------- */
  107. /* ---------------------------------------------------------------- */
  108. /* Step 1: Wait for at least 200 microsedonds to allow internal */
  109. /* clocks to settle. Only necessary after hard reset... */
  110. /* FIXME: can be optimized later */
  111. /* ---------------------------------------------------------------- */
  112. ldr r3, =OSCR /* reset the OS Timer Count to zero */
  113. mov r2, #0
  114. str r2, [r3]
  115. ldr r4, =0x300 /* really 0x2E1 is about 200usec, */
  116. /* so 0x300 should be plenty */
  117. 1:
  118. ldr r2, [r3]
  119. cmp r4, r2
  120. bgt 1b
  121. mem_init:
  122. ldr r1, =MEMC_BASE /* get memory controller base addr. */
  123. /* ---------------------------------------------------------------- */
  124. /* Step 2a: Initialize Asynchronous static memory controller */
  125. /* ---------------------------------------------------------------- */
  126. /* MSC registers: timing, bus width, mem type */
  127. /* MSC0: nCS(0,1) */
  128. ldr r2, =CONFIG_SYS_MSC0_VAL
  129. str r2, [r1, #MSC0_OFFSET]
  130. ldr r2, [r1, #MSC0_OFFSET] /* read back to ensure */
  131. /* that data latches */
  132. /* MSC1: nCS(2,3) */
  133. ldr r2, =CONFIG_SYS_MSC1_VAL
  134. str r2, [r1, #MSC1_OFFSET]
  135. ldr r2, [r1, #MSC1_OFFSET]
  136. /* MSC2: nCS(4,5) */
  137. ldr r2, =CONFIG_SYS_MSC2_VAL
  138. str r2, [r1, #MSC2_OFFSET]
  139. ldr r2, [r1, #MSC2_OFFSET]
  140. /* ---------------------------------------------------------------- */
  141. /* Step 2b: Initialize Card Interface */
  142. /* ---------------------------------------------------------------- */
  143. /* MECR: Memory Expansion Card Register */
  144. ldr r2, =CONFIG_SYS_MECR_VAL
  145. str r2, [r1, #MECR_OFFSET]
  146. ldr r2, [r1, #MECR_OFFSET]
  147. /* MCMEM0: Card Interface slot 0 timing */
  148. ldr r2, =CONFIG_SYS_MCMEM0_VAL
  149. str r2, [r1, #MCMEM0_OFFSET]
  150. ldr r2, [r1, #MCMEM0_OFFSET]
  151. /* MCMEM1: Card Interface slot 1 timing */
  152. ldr r2, =CONFIG_SYS_MCMEM1_VAL
  153. str r2, [r1, #MCMEM1_OFFSET]
  154. ldr r2, [r1, #MCMEM1_OFFSET]
  155. /* MCATT0: Card Interface Attribute Space Timing, slot 0 */
  156. ldr r2, =CONFIG_SYS_MCATT0_VAL
  157. str r2, [r1, #MCATT0_OFFSET]
  158. ldr r2, [r1, #MCATT0_OFFSET]
  159. /* MCATT1: Card Interface Attribute Space Timing, slot 1 */
  160. ldr r2, =CONFIG_SYS_MCATT1_VAL
  161. str r2, [r1, #MCATT1_OFFSET]
  162. ldr r2, [r1, #MCATT1_OFFSET]
  163. /* MCIO0: Card Interface I/O Space Timing, slot 0 */
  164. ldr r2, =CONFIG_SYS_MCIO0_VAL
  165. str r2, [r1, #MCIO0_OFFSET]
  166. ldr r2, [r1, #MCIO0_OFFSET]
  167. /* MCIO1: Card Interface I/O Space Timing, slot 1 */
  168. ldr r2, =CONFIG_SYS_MCIO1_VAL
  169. str r2, [r1, #MCIO1_OFFSET]
  170. ldr r2, [r1, #MCIO1_OFFSET]
  171. #ifdef DEBUG_BLINK_ENABLE
  172. /* 5th blink */
  173. bl blink
  174. #endif
  175. /* ---------------------------------------------------------------- */
  176. /* Step 2c: Write FLYCNFG FIXME: what's that??? */
  177. /* ---------------------------------------------------------------- */
  178. /* ---------------------------------------------------------------- */
  179. /* Step 2d: Initialize Timing for Sync Memory (SDCLK0) */
  180. /* ---------------------------------------------------------------- */
  181. /* Before accessing MDREFR we need a valid DRI field, so we set */
  182. /* this to power on defaults + DRI field. */
  183. ldr r3, =CONFIG_SYS_MDREFR_VAL
  184. ldr r2, =0xFFF
  185. and r3, r3, r2
  186. ldr r4, =0x03ca4000
  187. orr r4, r4, r3
  188. str r4, [r1, #MDREFR_OFFSET] /* write back MDREFR */
  189. ldr r4, [r1, #MDREFR_OFFSET]
  190. /* Note: preserve the mdrefr value in r4 */
  191. /* ---------------------------------------------------------------- */
  192. /* Step 3: Initialize Synchronous Static Memory (Flash/Peripherals) */
  193. /* ---------------------------------------------------------------- */
  194. /* Initialize SXCNFG register. Assert the enable bits */
  195. /* Write SXMRS to cause an MRS command to all enabled banks of */
  196. /* synchronous static memory. Note that SXLCR need not be written */
  197. /* at this time. */
  198. /* FIXME: we use async mode for now */
  199. /* ---------------------------------------------------------------- */
  200. /* Step 4: Initialize SDRAM */
  201. /* ---------------------------------------------------------------- */
  202. /* set MDREFR according to user define with exception of a few bits */
  203. ldr r4, =CONFIG_SYS_MDREFR_VAL
  204. orr r4, r4, #(MDREFR_SLFRSH)
  205. bic r4, r4, #(MDREFR_E1PIN|MDREFR_E0PIN)
  206. str r4, [r1, #MDREFR_OFFSET] /* write back MDREFR */
  207. ldr r4, [r1, #MDREFR_OFFSET]
  208. /* Step 4b: de-assert MDREFR:SLFRSH. */
  209. bic r4, r4, #(MDREFR_SLFRSH)
  210. str r4, [r1, #MDREFR_OFFSET] /* write back MDREFR */
  211. ldr r4, [r1, #MDREFR_OFFSET]
  212. /* Step 4c: assert MDREFR:E1PIN and E0PIO as desired */
  213. ldr r4, =CONFIG_SYS_MDREFR_VAL
  214. str r4, [r1, #MDREFR_OFFSET] /* write back MDREFR */
  215. ldr r4, [r1, #MDREFR_OFFSET]
  216. /* Step 4d: write MDCNFG with MDCNFG:DEx deasserted (set to 0), to */
  217. /* configure but not enable each SDRAM partition pair. */
  218. ldr r4, =CONFIG_SYS_MDCNFG_VAL
  219. bic r4, r4, #(MDCNFG_DE0|MDCNFG_DE1)
  220. str r4, [r1, #MDCNFG_OFFSET] /* write back MDCNFG */
  221. ldr r4, [r1, #MDCNFG_OFFSET]
  222. /* Step 4e: Wait for the clock to the SDRAMs to stabilize, */
  223. /* 100..200 µsec. */
  224. ldr r3, =OSCR /* reset the OS Timer Count to zero */
  225. mov r2, #0
  226. str r2, [r3]
  227. ldr r4, =0x300 /* really 0x2E1 is about 200usec, */
  228. /* so 0x300 should be plenty */
  229. 1:
  230. ldr r2, [r3]
  231. cmp r4, r2
  232. bgt 1b
  233. /* Step 4f: Trigger a number (usually 8) refresh cycles by */
  234. /* attempting non-burst read or write accesses to disabled */
  235. /* SDRAM, as commonly specified in the power up sequence */
  236. /* documented in SDRAM data sheets. The address(es) used */
  237. /* for this purpose must not be cacheable. */
  238. ldr r3, =CONFIG_SYS_DRAM_BASE
  239. str r2, [r3]
  240. str r2, [r3]
  241. str r2, [r3]
  242. str r2, [r3]
  243. str r2, [r3]
  244. str r2, [r3]
  245. str r2, [r3]
  246. str r2, [r3]
  247. /* Step 4g: Write MDCNFG with enable bits asserted */
  248. /* (MDCNFG:DEx set to 1). */
  249. ldr r3, [r1, #MDCNFG_OFFSET]
  250. orr r3, r3, #(MDCNFG_DE0|MDCNFG_DE1)
  251. str r3, [r1, #MDCNFG_OFFSET]
  252. /* Step 4h: Write MDMRS. */
  253. ldr r2, =CONFIG_SYS_MDMRS_VAL
  254. str r2, [r1, #MDMRS_OFFSET]
  255. /* We are finished with Intel's memory controller initialisation */
  256. #if 0
  257. /* FIXME turn on serial ports */
  258. /* look into moving this to board_init() */
  259. ldr r2, =(PXA_CS5_PHYS + 0x03C0002c)
  260. mov r3, #0x13
  261. str r3, [r2]
  262. #endif
  263. #ifdef DEBUG_BLINK_ENABLE
  264. /* 6th blink */
  265. bl blink
  266. #endif
  267. /* ---------------------------------------------------------------- */
  268. /* Disable (mask) all interrupts at interrupt controller */
  269. /* ---------------------------------------------------------------- */
  270. initirqs:
  271. mov r1, #0 /* clear int. level register (IRQ, not FIQ) */
  272. ldr r2, =ICLR
  273. str r1, [r2]
  274. ldr r2, =ICMR /* mask all interrupts at the controller */
  275. str r1, [r2]
  276. /* ---------------------------------------------------------------- */
  277. /* Clock initialisation */
  278. /* ---------------------------------------------------------------- */
  279. initclks:
  280. /* Disable the peripheral clocks, and set the core clock frequency */
  281. /* (hard-coding at 398.12MHz for now). */
  282. /* Turn Off ALL on-chip peripheral clocks for re-configuration */
  283. /* Note: See label 'ENABLECLKS' for the re-enabling */
  284. #if 0
  285. ldr r1, =CKEN
  286. mov r2, #0
  287. str r2, [r1]
  288. /* default value in case no valid rotary switch setting is found */
  289. ldr r2, =(CCCR_L27|CCCR_M2|CCCR_N10) /* DEFAULT: {200/200/100} */
  290. /* ... and write the core clock config register */
  291. ldr r1, =CCCR
  292. str r2, [r1]
  293. #endif
  294. #ifdef RTC
  295. /* enable the 32Khz oscillator for RTC and PowerManager */
  296. ldr r1, =OSCC
  297. mov r2, #OSCC_OON
  298. str r2, [r1]
  299. /* NOTE: spin here until OSCC.OOK get set, meaning the PLL */
  300. /* has settled. */
  301. 60:
  302. ldr r2, [r1]
  303. ands r2, r2, #1
  304. beq 60b
  305. #endif
  306. /* ---------------------------------------------------------------- */
  307. /* */
  308. /* ---------------------------------------------------------------- */
  309. /* Save SDRAM size */
  310. ldr r1, =DRAM_SIZE
  311. str r8, [r1]
  312. /* Interrupt init: Mask all interrupts */
  313. ldr r0, =ICMR /* enable no sources */
  314. mov r1, #0
  315. str r1, [r0]
  316. /* FIXME */
  317. #define NODEBUG
  318. #ifdef NODEBUG
  319. /*Disable software and data breakpoints */
  320. mov r0,#0
  321. mcr p15,0,r0,c14,c8,0 /* ibcr0 */
  322. mcr p15,0,r0,c14,c9,0 /* ibcr1 */
  323. mcr p15,0,r0,c14,c4,0 /* dbcon */
  324. /*Enable all debug functionality */
  325. mov r0,#0x80000000
  326. mcr p14,0,r0,c10,c0,0 /* dcsr */
  327. #endif
  328. /* ---------------------------------------------------------------- */
  329. /* End memsetup */
  330. /* ---------------------------------------------------------------- */
  331. #ifdef DEBUG_BLINK_ENABLE
  332. /* 7th blink */
  333. bl blink
  334. #endif
  335. endlowlevel_init:
  336. mov pc, r10
  337. #ifdef DEBUG_BLINK_ENABLE
  338. /* debug LED code */
  339. /* delay about 200ms */
  340. delay:
  341. /* reset OSCR to 0 */
  342. ldr r8, =OSCR
  343. mov r9, #0
  344. str r9, [r8]
  345. /* make sure new value has stuck */
  346. 1:
  347. ldr r8, =OSCR
  348. ldr r9, [r8]
  349. mov r8, #0x10000
  350. cmp r9, r8
  351. bgt 1b
  352. /* now, wait for delay to expire */
  353. 1:
  354. ldr r8, =OSCR
  355. ldr r9, [r8]
  356. mov r8, #0xd4000
  357. cmp r8, r9
  358. bgt 1b
  359. mov pc, lr
  360. /* blink code -- trashes r7, r8, r9 */
  361. .globl blink
  362. blink:
  363. mov r7, lr
  364. /* set GPIO10 as outout */
  365. ldr r8, =GPDR0
  366. ldr r9, [r8]
  367. orr r9, r9, #(1<<10)
  368. str r9, [r8]
  369. /* turn LED off */
  370. mov r9, #(1<<10)
  371. ldr r8, =GPCR0
  372. str r9, [r8]
  373. bl delay
  374. /* turn LED on */
  375. mov r9, #(1<<10)
  376. ldr r8, =GPSR0
  377. str r9, [r8]
  378. bl delay
  379. /* turn LED off */
  380. mov r9, #(1<<10)
  381. ldr r8, =GPCR0
  382. str r9, [r8]
  383. mov pc, r7
  384. #endif