lowlevel_init.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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. /* Set up GPIO pins first ----------------------------------------- */
  44. ldr r0, =GPSR0
  45. ldr r1, =CONFIG_SYS_GPSR0_VAL
  46. str r1, [r0]
  47. ldr r0, =GPSR1
  48. ldr r1, =CONFIG_SYS_GPSR1_VAL
  49. str r1, [r0]
  50. ldr r0, =GPSR2
  51. ldr r1, =CONFIG_SYS_GPSR2_VAL
  52. str r1, [r0]
  53. ldr r0, =GPCR0
  54. ldr r1, =CONFIG_SYS_GPCR0_VAL
  55. str r1, [r0]
  56. ldr r0, =GPCR1
  57. ldr r1, =CONFIG_SYS_GPCR1_VAL
  58. str r1, [r0]
  59. ldr r0, =GPCR2
  60. ldr r1, =CONFIG_SYS_GPCR2_VAL
  61. str r1, [r0]
  62. ldr r0, =GPDR0
  63. ldr r1, =CONFIG_SYS_GPDR0_VAL
  64. str r1, [r0]
  65. ldr r0, =GPDR1
  66. ldr r1, =CONFIG_SYS_GPDR1_VAL
  67. str r1, [r0]
  68. ldr r0, =GPDR2
  69. ldr r1, =CONFIG_SYS_GPDR2_VAL
  70. str r1, [r0]
  71. ldr r0, =GAFR0_L
  72. ldr r1, =CONFIG_SYS_GAFR0_L_VAL
  73. str r1, [r0]
  74. ldr r0, =GAFR0_U
  75. ldr r1, =CONFIG_SYS_GAFR0_U_VAL
  76. str r1, [r0]
  77. ldr r0, =GAFR1_L
  78. ldr r1, =CONFIG_SYS_GAFR1_L_VAL
  79. str r1, [r0]
  80. ldr r0, =GAFR1_U
  81. ldr r1, =CONFIG_SYS_GAFR1_U_VAL
  82. str r1, [r0]
  83. ldr r0, =GAFR2_L
  84. ldr r1, =CONFIG_SYS_GAFR2_L_VAL
  85. str r1, [r0]
  86. ldr r0, =GAFR2_U
  87. ldr r1, =CONFIG_SYS_GAFR2_U_VAL
  88. str r1, [r0]
  89. ldr r0, =PSSR /* enable GPIO pins */
  90. ldr r1, =CONFIG_SYS_PSSR_VAL
  91. str r1, [r0]
  92. /* ---------------------------------------------------------------- */
  93. /* Enable memory interface */
  94. /* */
  95. /* The sequence below is based on the recommended init steps */
  96. /* detailed in the Intel PXA250 Operating Systems Developers Guide, */
  97. /* Chapter 10. */
  98. /* ---------------------------------------------------------------- */
  99. /* ---------------------------------------------------------------- */
  100. /* Step 1: Wait for at least 200 microsedonds to allow internal */
  101. /* clocks to settle. Only necessary after hard reset... */
  102. /* FIXME: can be optimized later */
  103. /* ---------------------------------------------------------------- */
  104. ldr r3, =OSCR /* reset the OS Timer Count to zero */
  105. mov r2, #0
  106. str r2, [r3]
  107. ldr r4, =0x300 /* really 0x2E1 is about 200usec, */
  108. /* so 0x300 should be plenty */
  109. 1:
  110. ldr r2, [r3]
  111. cmp r4, r2
  112. bgt 1b
  113. mem_init:
  114. ldr r1, =MEMC_BASE /* get memory controller base addr. */
  115. /* ---------------------------------------------------------------- */
  116. /* Step 2a: Initialize Asynchronous static memory controller */
  117. /* ---------------------------------------------------------------- */
  118. /* MSC registers: timing, bus width, mem type */
  119. /* MSC0: nCS(0,1) */
  120. ldr r2, =CONFIG_SYS_MSC0_VAL
  121. str r2, [r1, #MSC0_OFFSET]
  122. ldr r2, [r1, #MSC0_OFFSET] /* read back to ensure */
  123. /* that data latches */
  124. /* MSC1: nCS(2,3) */
  125. ldr r2, =CONFIG_SYS_MSC1_VAL
  126. str r2, [r1, #MSC1_OFFSET]
  127. ldr r2, [r1, #MSC1_OFFSET]
  128. /* MSC2: nCS(4,5) */
  129. ldr r2, =CONFIG_SYS_MSC2_VAL
  130. str r2, [r1, #MSC2_OFFSET]
  131. ldr r2, [r1, #MSC2_OFFSET]
  132. /* ---------------------------------------------------------------- */
  133. /* Step 2b: Initialize Card Interface */
  134. /* ---------------------------------------------------------------- */
  135. /* MECR: Memory Expansion Card Register */
  136. ldr r2, =CONFIG_SYS_MECR_VAL
  137. str r2, [r1, #MECR_OFFSET]
  138. ldr r2, [r1, #MECR_OFFSET]
  139. /* MCMEM0: Card Interface slot 0 timing */
  140. ldr r2, =CONFIG_SYS_MCMEM0_VAL
  141. str r2, [r1, #MCMEM0_OFFSET]
  142. ldr r2, [r1, #MCMEM0_OFFSET]
  143. /* MCMEM1: Card Interface slot 1 timing */
  144. ldr r2, =CONFIG_SYS_MCMEM1_VAL
  145. str r2, [r1, #MCMEM1_OFFSET]
  146. ldr r2, [r1, #MCMEM1_OFFSET]
  147. /* MCATT0: Card Interface Attribute Space Timing, slot 0 */
  148. ldr r2, =CONFIG_SYS_MCATT0_VAL
  149. str r2, [r1, #MCATT0_OFFSET]
  150. ldr r2, [r1, #MCATT0_OFFSET]
  151. /* MCATT1: Card Interface Attribute Space Timing, slot 1 */
  152. ldr r2, =CONFIG_SYS_MCATT1_VAL
  153. str r2, [r1, #MCATT1_OFFSET]
  154. ldr r2, [r1, #MCATT1_OFFSET]
  155. /* MCIO0: Card Interface I/O Space Timing, slot 0 */
  156. ldr r2, =CONFIG_SYS_MCIO0_VAL
  157. str r2, [r1, #MCIO0_OFFSET]
  158. ldr r2, [r1, #MCIO0_OFFSET]
  159. /* MCIO1: Card Interface I/O Space Timing, slot 1 */
  160. ldr r2, =CONFIG_SYS_MCIO1_VAL
  161. str r2, [r1, #MCIO1_OFFSET]
  162. ldr r2, [r1, #MCIO1_OFFSET]
  163. /* ---------------------------------------------------------------- */
  164. /* Step 2c: Write FLYCNFG FIXME: what's that??? */
  165. /* ---------------------------------------------------------------- */
  166. /* ---------------------------------------------------------------- */
  167. /* Step 2d: Initialize Timing for Sync Memory (SDCLK0) */
  168. /* ---------------------------------------------------------------- */
  169. /* Before accessing MDREFR we need a valid DRI field, so we set */
  170. /* this to power on defaults + DRI field. */
  171. ldr r3, =CONFIG_SYS_MDREFR_VAL
  172. ldr r2, =0xFFF
  173. and r3, r3, r2
  174. ldr r4, =0x03ca4000
  175. orr r4, r4, r3
  176. str r4, [r1, #MDREFR_OFFSET] /* write back MDREFR */
  177. ldr r4, [r1, #MDREFR_OFFSET]
  178. /* Note: preserve the mdrefr value in r4 */
  179. /* ---------------------------------------------------------------- */
  180. /* Step 3: Initialize Synchronous Static Memory (Flash/Peripherals) */
  181. /* ---------------------------------------------------------------- */
  182. /* Initialize SXCNFG register. Assert the enable bits */
  183. /* Write SXMRS to cause an MRS command to all enabled banks of */
  184. /* synchronous static memory. Note that SXLCR need not be written */
  185. /* at this time. */
  186. /* FIXME: we use async mode for now */
  187. /* ---------------------------------------------------------------- */
  188. /* Step 4: Initialize SDRAM */
  189. /* ---------------------------------------------------------------- */
  190. /* set MDREFR according to user define with exception of a few bits */
  191. ldr r4, =CONFIG_SYS_MDREFR_VAL
  192. orr r4, r4, #(MDREFR_SLFRSH)
  193. bic r4, r4, #(MDREFR_E1PIN|MDREFR_E0PIN)
  194. str r4, [r1, #MDREFR_OFFSET] /* write back MDREFR */
  195. ldr r4, [r1, #MDREFR_OFFSET]
  196. /* Step 4b: de-assert MDREFR:SLFRSH. */
  197. bic r4, r4, #(MDREFR_SLFRSH)
  198. str r4, [r1, #MDREFR_OFFSET] /* write back MDREFR */
  199. ldr r4, [r1, #MDREFR_OFFSET]
  200. /* Step 4c: assert MDREFR:E1PIN and E0PIO as desired */
  201. ldr r4, =CONFIG_SYS_MDREFR_VAL
  202. str r4, [r1, #MDREFR_OFFSET] /* write back MDREFR */
  203. ldr r4, [r1, #MDREFR_OFFSET]
  204. /* Step 4d: write MDCNFG with MDCNFG:DEx deasserted (set to 0), to */
  205. /* configure but not enable each SDRAM partition pair. */
  206. ldr r4, =CONFIG_SYS_MDCNFG_VAL
  207. bic r4, r4, #(MDCNFG_DE0|MDCNFG_DE1)
  208. str r4, [r1, #MDCNFG_OFFSET] /* write back MDCNFG */
  209. ldr r4, [r1, #MDCNFG_OFFSET]
  210. /* Step 4e: Wait for the clock to the SDRAMs to stabilize, */
  211. /* 100..200 µsec. */
  212. ldr r3, =OSCR /* reset the OS Timer Count to zero */
  213. mov r2, #0
  214. str r2, [r3]
  215. ldr r4, =0x300 /* really 0x2E1 is about 200usec, */
  216. /* so 0x300 should be plenty */
  217. 1:
  218. ldr r2, [r3]
  219. cmp r4, r2
  220. bgt 1b
  221. /* Step 4f: Trigger a number (usually 8) refresh cycles by */
  222. /* attempting non-burst read or write accesses to disabled */
  223. /* SDRAM, as commonly specified in the power up sequence */
  224. /* documented in SDRAM data sheets. The address(es) used */
  225. /* for this purpose must not be cacheable. */
  226. ldr r3, =CONFIG_SYS_DRAM_BASE
  227. str r2, [r3]
  228. str r2, [r3]
  229. str r2, [r3]
  230. str r2, [r3]
  231. str r2, [r3]
  232. str r2, [r3]
  233. str r2, [r3]
  234. str r2, [r3]
  235. /* Step 4g: Write MDCNFG with enable bits asserted */
  236. /* (MDCNFG:DEx set to 1). */
  237. ldr r3, [r1, #MDCNFG_OFFSET]
  238. orr r3, r3, #(MDCNFG_DE0|MDCNFG_DE1)
  239. str r3, [r1, #MDCNFG_OFFSET]
  240. /* Step 4h: Write MDMRS. */
  241. ldr r2, =CONFIG_SYS_MDMRS_VAL
  242. str r2, [r1, #MDMRS_OFFSET]
  243. /* We are finished with Intel's memory controller initialisation */
  244. /* ---------------------------------------------------------------- */
  245. /* Disable (mask) all interrupts at interrupt controller */
  246. /* ---------------------------------------------------------------- */
  247. initirqs:
  248. mov r1, #0 /* clear int. level register (IRQ, not FIQ) */
  249. ldr r2, =ICLR
  250. str r1, [r2]
  251. ldr r2, =ICMR /* mask all interrupts at the controller */
  252. str r1, [r2]
  253. /* ---------------------------------------------------------------- */
  254. /* Clock initialisation */
  255. /* ---------------------------------------------------------------- */
  256. initclks:
  257. /* Disable the peripheral clocks, and set the core clock frequency */
  258. /* (hard-coding at 398.12MHz for now). */
  259. /* Turn Off ALL on-chip peripheral clocks for re-configuration */
  260. /* Note: See label 'ENABLECLKS' for the re-enabling */
  261. ldr r1, =CKEN
  262. mov r2, #0
  263. str r2, [r1]
  264. /* default value in case no valid rotary switch setting is found */
  265. ldr r2, =(CCCR_L27|CCCR_M2|CCCR_N10) /* DEFAULT: {200/200/100} */
  266. /* ... and write the core clock config register */
  267. ldr r1, =CCCR
  268. str r2, [r1]
  269. #ifdef RTC
  270. /* enable the 32Khz oscillator for RTC and PowerManager */
  271. ldr r1, =OSCC
  272. mov r2, #OSCC_OON
  273. str r2, [r1]
  274. /* NOTE: spin here until OSCC.OOK get set, meaning the PLL */
  275. /* has settled. */
  276. 60:
  277. ldr r2, [r1]
  278. ands r2, r2, #1
  279. beq 60b
  280. #endif
  281. /* ---------------------------------------------------------------- */
  282. /* */
  283. /* ---------------------------------------------------------------- */
  284. /* Save SDRAM size */
  285. ldr r1, =DRAM_SIZE
  286. str r8, [r1]
  287. /* Interrupt init: Mask all interrupts */
  288. ldr r0, =ICMR /* enable no sources */
  289. mov r1, #0
  290. str r1, [r0]
  291. /* FIXME */
  292. #define NODEBUG
  293. #ifdef NODEBUG
  294. /*Disable software and data breakpoints */
  295. mov r0,#0
  296. mcr p15,0,r0,c14,c8,0 /* ibcr0 */
  297. mcr p15,0,r0,c14,c9,0 /* ibcr1 */
  298. mcr p15,0,r0,c14,c4,0 /* dbcon */
  299. /*Enable all debug functionality */
  300. mov r0,#0x80000000
  301. mcr p14,0,r0,c10,c0,0 /* dcsr */
  302. #endif
  303. /* ---------------------------------------------------------------- */
  304. /* End lowlevel_init */
  305. /* ---------------------------------------------------------------- */
  306. endlowlevel_init:
  307. mov pc, lr