memsetup.S 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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/memsetup.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 CFG_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 memsetup
  41. memsetup:
  42. mov r10, lr
  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, =GPCR0
  54. ldr r1, =CFG_GPCR0_VAL
  55. str r1, [r0]
  56. ldr r0, =GPCR1
  57. ldr r1, =CFG_GPCR1_VAL
  58. str r1, [r0]
  59. ldr r0, =GPCR2
  60. ldr r1, =CFG_GPCR2_VAL
  61. str r1, [r0]
  62. ldr r0, =GPDR0
  63. ldr r1, =CFG_GPDR0_VAL
  64. str r1, [r0]
  65. ldr r0, =GPDR1
  66. ldr r1, =CFG_GPDR1_VAL
  67. str r1, [r0]
  68. ldr r0, =GPDR2
  69. ldr r1, =CFG_GPDR2_VAL
  70. str r1, [r0]
  71. ldr r0, =GAFR0_L
  72. ldr r1, =CFG_GAFR0_L_VAL
  73. str r1, [r0]
  74. ldr r0, =GAFR0_U
  75. ldr r1, =CFG_GAFR0_U_VAL
  76. str r1, [r0]
  77. ldr r0, =GAFR1_L
  78. ldr r1, =CFG_GAFR1_L_VAL
  79. str r1, [r0]
  80. ldr r0, =GAFR1_U
  81. ldr r1, =CFG_GAFR1_U_VAL
  82. str r1, [r0]
  83. ldr r0, =GAFR2_L
  84. ldr r1, =CFG_GAFR2_L_VAL
  85. str r1, [r0]
  86. ldr r0, =GAFR2_U
  87. ldr r1, =CFG_GAFR2_U_VAL
  88. str r1, [r0]
  89. ldr r0, =PSSR /* enable GPIO pins */
  90. ldr r1, =CFG_PSSR_VAL
  91. str r1, [r0]
  92. /* ldr r3, =MSC1 / low - bank 2 Lubbock Registers / SRAM */
  93. /* ldr r2, =CFG_MSC1_VAL / high - bank 3 Ethernet Controller */
  94. /* str r2, [r3] / need to set MSC1 before trying to write to the HEX LEDs */
  95. /* ldr r2, [r3] / need to read it back to make sure the value latches (see MSC section of manual) */
  96. /* */
  97. /* ldr r1, =LED_BLANK */
  98. /* mov r0, #0xFF */
  99. /* str r0, [r1] / turn on hex leds */
  100. /* */
  101. /*loop: */
  102. /* */
  103. /* ldr r0, =0xB0070001 */
  104. /* ldr r1, =_LED */
  105. /* str r0, [r1] / hex display */
  106. /* ---------------------------------------------------------------- */
  107. /* Enable memory interface */
  108. /* */
  109. /* The sequence below is based on the recommended init steps */
  110. /* detailed in the Intel PXA250 Operating Systems Developers Guide, */
  111. /* Chapter 10. */
  112. /* ---------------------------------------------------------------- */
  113. /* ---------------------------------------------------------------- */
  114. /* Step 1: Wait for at least 200 microsedonds to allow internal */
  115. /* clocks to settle. Only necessary after hard reset... */
  116. /* FIXME: can be optimized later */
  117. /* ---------------------------------------------------------------- */
  118. ldr r3, =OSCR /* reset the OS Timer Count to zero */
  119. mov r2, #0
  120. str r2, [r3]
  121. ldr r4, =0x300 /* really 0x2E1 is about 200usec, */
  122. /* so 0x300 should be plenty */
  123. 1:
  124. ldr r2, [r3]
  125. cmp r4, r2
  126. bgt 1b
  127. mem_init:
  128. ldr r1, =MEMC_BASE /* get memory controller base addr. */
  129. /* ---------------------------------------------------------------- */
  130. /* Step 2a: Initialize Asynchronous static memory controller */
  131. /* ---------------------------------------------------------------- */
  132. /* MSC registers: timing, bus width, mem type */
  133. /* MSC0: nCS(0,1) */
  134. ldr r2, =CFG_MSC0_VAL
  135. str r2, [r1, #MSC0_OFFSET]
  136. ldr r2, [r1, #MSC0_OFFSET] /* read back to ensure */
  137. /* that data latches */
  138. /* MSC1: nCS(2,3) */
  139. ldr r2, =CFG_MSC1_VAL
  140. str r2, [r1, #MSC1_OFFSET]
  141. ldr r2, [r1, #MSC1_OFFSET]
  142. /* MSC2: nCS(4,5) */
  143. ldr r2, =CFG_MSC2_VAL
  144. str r2, [r1, #MSC2_OFFSET]
  145. ldr r2, [r1, #MSC2_OFFSET]
  146. /* ---------------------------------------------------------------- */
  147. /* Step 2b: Initialize Card Interface */
  148. /* ---------------------------------------------------------------- */
  149. /* MECR: Memory Expansion Card Register */
  150. ldr r2, =CFG_MECR_VAL
  151. str r2, [r1, #MECR_OFFSET]
  152. ldr r2, [r1, #MECR_OFFSET]
  153. /* MCMEM0: Card Interface slot 0 timing */
  154. ldr r2, =CFG_MCMEM0_VAL
  155. str r2, [r1, #MCMEM0_OFFSET]
  156. ldr r2, [r1, #MCMEM0_OFFSET]
  157. /* MCMEM1: Card Interface slot 1 timing */
  158. ldr r2, =CFG_MCMEM1_VAL
  159. str r2, [r1, #MCMEM1_OFFSET]
  160. ldr r2, [r1, #MCMEM1_OFFSET]
  161. /* MCATT0: Card Interface Attribute Space Timing, slot 0 */
  162. ldr r2, =CFG_MCATT0_VAL
  163. str r2, [r1, #MCATT0_OFFSET]
  164. ldr r2, [r1, #MCATT0_OFFSET]
  165. /* MCATT1: Card Interface Attribute Space Timing, slot 1 */
  166. ldr r2, =CFG_MCATT1_VAL
  167. str r2, [r1, #MCATT1_OFFSET]
  168. ldr r2, [r1, #MCATT1_OFFSET]
  169. /* MCIO0: Card Interface I/O Space Timing, slot 0 */
  170. ldr r2, =CFG_MCIO0_VAL
  171. str r2, [r1, #MCIO0_OFFSET]
  172. ldr r2, [r1, #MCIO0_OFFSET]
  173. /* MCIO1: Card Interface I/O Space Timing, slot 1 */
  174. ldr r2, =CFG_MCIO1_VAL
  175. str r2, [r1, #MCIO1_OFFSET]
  176. ldr r2, [r1, #MCIO1_OFFSET]
  177. /* ---------------------------------------------------------------- */
  178. /* Step 2c: Write FLYCNFG FIXME: what's that??? */
  179. /* ---------------------------------------------------------------- */
  180. /* ---------------------------------------------------------------- */
  181. /* Step 2d: Initialize Timing for Sync Memory (SDCLK0) */
  182. /* ---------------------------------------------------------------- */
  183. /* Before accessing MDREFR we need a valid DRI field, so we set */
  184. /* this to power on defaults + DIR field. */
  185. ldr r4, =0x03ca4fff
  186. str r4, [r1, #MDREFR_OFFSET] /* write back MDREFR */
  187. ldr r4, [r1, #MDREFR_OFFSET]
  188. ldr r4, =0x03ca4030
  189. str r4, [r1, #MDREFR_OFFSET] /* write back MDREFR */
  190. ldr r4, [r1, #MDREFR_OFFSET]
  191. /* Note: preserve the mdrefr value in r4 */
  192. /* ---------------------------------------------------------------- */
  193. /* Step 3: Initialize Synchronous Static Memory (Flash/Peripherals) */
  194. /* ---------------------------------------------------------------- */
  195. /* Initialize SXCNFG register. Assert the enable bits */
  196. /* Write SXMRS to cause an MRS command to all enabled banks of */
  197. /* synchronous static memory. Note that SXLCR need not be written */
  198. /* at this time. */
  199. /* FIXME: we use async mode for now */
  200. /* ---------------------------------------------------------------- */
  201. /* Step 4: Initialize SDRAM */
  202. /* ---------------------------------------------------------------- */
  203. /* Step 4a: assert MDREFR:K1RUN and MDREFR:K2RUN and configure */
  204. /* MDREFR:K1DB2 and MDREFR:K2DB2 as desired. */
  205. orr r4, r4, #(MDREFR_K1RUN|MDREFR_K0RUN)
  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 */
  213. orr r4, r4, #(MDREFR_E1PIN|MDREFR_E0PIN)
  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, =CFG_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. /* There should 9 writes, since the first write doesn't */
  239. /* trigger a refresh cycle on PXA250. See Intel PXA250 and */
  240. /* PXA210 Processors Specification Update, */
  241. /* Jan 2003, Errata #116, page 30. */
  242. ldr r3, =CFG_DRAM_BASE
  243. str r2, [r3]
  244. str r2, [r3]
  245. str r2, [r3]
  246. str r2, [r3]
  247. str r2, [r3]
  248. str r2, [r3]
  249. str r2, [r3]
  250. str r2, [r3]
  251. str r2, [r3]
  252. /* Step 4g: Write MDCNFG with enable bits asserted */
  253. /* (MDCNFG:DEx set to 1). */
  254. ldr r3, [r1, #MDCNFG_OFFSET]
  255. orr r3, r3, #(MDCNFG_DE0|MDCNFG_DE1)
  256. str r3, [r1, #MDCNFG_OFFSET]
  257. /* Step 4h: Write MDMRS. */
  258. ldr r2, =CFG_MDMRS_VAL
  259. str r2, [r1, #MDMRS_OFFSET]
  260. /* We are finished with Intel's memory controller initialisation */
  261. /* ---------------------------------------------------------------- */
  262. /* Disable (mask) all interrupts at interrupt controller */
  263. /* ---------------------------------------------------------------- */
  264. initirqs:
  265. mov r1, #0 /* clear int. level register (IRQ, not FIQ) */
  266. ldr r2, =ICLR
  267. str r1, [r2]
  268. ldr r2, =ICMR /* mask all interrupts at the controller */
  269. str r1, [r2]
  270. /* ---------------------------------------------------------------- */
  271. /* Clock initialisation */
  272. /* ---------------------------------------------------------------- */
  273. initclks:
  274. /* Disable the peripheral clocks, and set the core clock frequency */
  275. /* (hard-coding at 398.12MHz for now). */
  276. /* Turn Off ALL on-chip peripheral clocks for re-configuration */
  277. /* Note: See label 'ENABLECLKS' for the re-enabling */
  278. ldr r1, =CKEN
  279. mov r2, #0
  280. str r2, [r1]
  281. /* default value in case no valid rotary switch setting is found */
  282. ldr r2, =(CCCR_L27|CCCR_M2|CCCR_N10) /* DEFAULT: {200/200/100} */
  283. /* ... and write the core clock config register */
  284. ldr r1, =CCCR
  285. str r2, [r1]
  286. /* enable the 32Khz oscillator for RTC and PowerManager */
  287. /*
  288. ldr r1, =OSCC
  289. mov r2, #OSCC_OON
  290. str r2, [r1]
  291. */
  292. /* NOTE: spin here until OSCC.OOK get set, meaning the PLL */
  293. /* has settled. */
  294. 60:
  295. ldr r2, [r1]
  296. ands r2, r2, #1
  297. beq 60b
  298. /* ---------------------------------------------------------------- */
  299. /* */
  300. /* ---------------------------------------------------------------- */
  301. /* Save SDRAM size */
  302. ldr r1, =DRAM_SIZE
  303. str r8, [r1]
  304. /* Interrupt init: Mask all interrupts */
  305. ldr r0, =ICMR /* enable no sources */
  306. mov r1, #0
  307. str r1, [r0]
  308. /* FIXME */
  309. #ifndef DEBUG
  310. /*Disable software and data breakpoints */
  311. mov r0,#0
  312. mcr p15,0,r0,c14,c8,0 /* ibcr0 */
  313. mcr p15,0,r0,c14,c9,0 /* ibcr1 */
  314. mcr p15,0,r0,c14,c4,0 /* dbcon */
  315. /*Enable all debug functionality */
  316. mov r0,#0x80000000
  317. mcr p14,0,r0,c10,c0,0 /* dcsr */
  318. #endif
  319. /* ---------------------------------------------------------------- */
  320. /* End memsetup */
  321. /* ---------------------------------------------------------------- */
  322. endmemsetup:
  323. mov pc, lr