lowlevel_init.S 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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 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. .macro wait time
  38. ldr r2, =OSCR
  39. mov r3, #0
  40. str r3, [r2]
  41. 0:
  42. ldr r3, [r2]
  43. cmp r3, \time
  44. bls 0b
  45. .endm
  46. /*
  47. * Memory setup
  48. */
  49. .globl lowlevel_init
  50. lowlevel_init:
  51. /* Set up GPIO pins first ----------------------------------------- */
  52. mov r10, lr
  53. /* Configure GPIO Pins 97, 98 UART1 / altern. Fkt. 1 */
  54. ldr r0, =GPIO97
  55. ldr r1, =0x801
  56. str r1, [r0]
  57. ldr r0, =GPIO98
  58. ldr r1, =0x801
  59. str r1, [r0]
  60. /* tebrandt - ASCR, clear the RDH bit */
  61. ldr r0, =ASCR
  62. ldr r1, [r0]
  63. bic r1, r1, #0x80000000
  64. str r1, [r0]
  65. /* ---------------------------------------------------------------- */
  66. /* Enable memory interface */
  67. /* ---------------------------------------------------------------- */
  68. /* ---------------------------------------------------------------- */
  69. /* Step 1: Wait for at least 200 microsedonds to allow internal */
  70. /* clocks to settle. Only necessary after hard reset... */
  71. /* FIXME: can be optimized later */
  72. /* ---------------------------------------------------------------- */
  73. ; wait #300
  74. mem_init:
  75. #define NEW_SDRAM_INIT 1
  76. #ifdef NEW_SDRAM_INIT
  77. /* Configure ACCR Register - enable DMEMC Clock at 260 / 2 MHz */
  78. ldr r0, =ACCR
  79. ldr r1, [r0]
  80. orr r1, r1, #0x3000
  81. str r1, [r0]
  82. ldr r1, [r0]
  83. /* 2. Programm MDCNFG, leaving DMCEN de-asserted */
  84. ldr r0, =MDCNFG
  85. ldr r1, =(MDCNFG_DMAP | MDCNFG_DTYPE | MDCNFG_DTC_2 | MDCNFG_DCSE0 | MDCNFG_DRAC_13)
  86. /* ldr r1, =0x80000403 */
  87. str r1, [r0]
  88. ldr r1, [r0] /* delay until written */
  89. /* 3. wait nop power up waiting period (200ms)
  90. * optimization: Steps 4+6 can be done during this
  91. */
  92. wait #300
  93. /* 4. Perform an initial Rcomp-calibration cycle */
  94. ldr r0, =RCOMP
  95. ldr r1, =0x80000000
  96. str r1, [r0]
  97. ldr r1, [r0] /* delay until written */
  98. /* missing: program for automatic rcomp evaluation cycles */
  99. /* 5. DDR DRAM strobe delay calibration */
  100. ldr r0, =DDR_HCAL
  101. ldr r1, =0x88000007
  102. str r1, [r0]
  103. wait #5
  104. ldr r1, [r0] /* delay until written */
  105. /* Set MDMRS */
  106. ldr r0, =MDMRS
  107. ldr r1, =0x60000033
  108. str r1, [r0]
  109. wait #300
  110. /* Configure MDREFR */
  111. ldr r0, =MDREFR
  112. ldr r1, =0x00000006
  113. str r1, [r0]
  114. ldr r1, [r0]
  115. /* Enable the dynamic memory controller */
  116. ldr r0, =MDCNFG
  117. ldr r1, [r0]
  118. orr r1, r1, #MDCNFG_DMCEN
  119. str r1, [r0]
  120. #else /* NEW_SDRAM_INIT */
  121. /* configure the MEMCLKCFG register */
  122. ldr r1, =MEMCLKCFG
  123. ldr r2, =0x00010001
  124. str r2, [r1] @ WRITE
  125. ldr r2, [r1] @ DELAY UNTIL WRITTEN
  126. /* set CSADRCFG[0] to data flash SRAM mode */
  127. ldr r1, =CSADRCFG0
  128. ldr r2, =0x00320809
  129. str r2, [r1] @ WRITE
  130. ldr r2, [r1] @ DELAY UNTIL WRITTEN
  131. /* set CSADRCFG[1] to data flash SRAM mode */
  132. ldr r1, =CSADRCFG1
  133. ldr r2, =0x00320809
  134. str r2, [r1] @ WRITE
  135. ldr r2, [r1] @ DELAY UNTIL WRITTEN
  136. /* set MSC 0 register for SRAM memory */
  137. ldr r1, =MSC0
  138. ldr r2, =0x11191119
  139. str r2, [r1] @ WRITE
  140. ldr r2, [r1] @ DELAY UNTIL WRITTEN
  141. /* set CSADRCFG[2] to data flash SRAM mode */
  142. ldr r1, =CSADRCFG2
  143. ldr r2, =0x00320809
  144. str r2, [r1] @ WRITE
  145. ldr r2, [r1] @ DELAY UNTIL WRITTEN
  146. /* set CSADRCFG[3] to VLIO mode */
  147. ldr r1, =CSADRCFG3
  148. ldr r2, =0x0032080B
  149. str r2, [r1] @ WRITE
  150. ldr r2, [r1] @ DELAY UNTIL WRITTEN
  151. /* set MSC 1 register for VLIO memory */
  152. ldr r1, =MSC1
  153. ldr r2, =0x123C1119
  154. str r2, [r1] @ WRITE
  155. ldr r2, [r1] @ DELAY UNTIL WRITTEN
  156. #if 0
  157. /* This does not work in Zylonite. -SC */
  158. ldr r0, =0x15fffff0
  159. ldr r1, =0xb10b
  160. str r1, [r0]
  161. str r1, [r0, #4]
  162. #endif
  163. /* Configure ACCR Register */
  164. ldr r0, =ACCR @ ACCR
  165. ldr r1, =0x0180b108
  166. str r1, [r0]
  167. ldr r1, [r0]
  168. /* Configure MDCNFG Register */
  169. ldr r0, =MDCNFG @ MDCNFG
  170. ldr r1, =0x403
  171. str r1, [r0]
  172. ldr r1, [r0]
  173. /* Perform Resistive Compensation by configuring RCOMP register */
  174. ldr r1, =RCOMP @ RCOMP
  175. ldr r2, =0x000000ff
  176. str r2, [r1]
  177. ldr r2, [r1]
  178. /* Configure MDMRS Register for SDCS0 */
  179. ldr r1, =MDMRS @ MDMRS
  180. ldr r2, =0x60000023
  181. ldr r3, [r1]
  182. orr r2, r2, r3
  183. str r2, [r1]
  184. ldr r2, [r1]
  185. /* Configure MDMRS Register for SDCS1 */
  186. ldr r1, =MDMRS @ MDMRS
  187. ldr r2, =0xa0000023
  188. ldr r3, [r1]
  189. orr r2, r2, r3
  190. str r2, [r1]
  191. ldr r2, [r1]
  192. /* Configure MDREFR */
  193. ldr r1, =MDREFR @ MDREFR
  194. ldr r2, =0x00000006
  195. str r2, [r1]
  196. ldr r2, [r1]
  197. /* Configure EMPI */
  198. ldr r1, =EMPI @ EMPI
  199. ldr r2, =0x80000000
  200. str r2, [r1]
  201. ldr r2, [r1]
  202. /* Hardware DDR Read-Strobe Delay Calibration */
  203. ldr r0, =DDR_HCAL @ DDR_HCAL
  204. ldr r1, =0x803ffc07 @ the offset is correct? -SC
  205. str r1, [r0]
  206. wait #5
  207. ldr r1, [r0]
  208. /* Here we assume the hardware calibration alwasy be successful. -SC */
  209. /* Set DMCEN bit in MDCNFG Register */
  210. ldr r0, =MDCNFG @ MDCNFG
  211. ldr r1, [r0]
  212. orr r1, r1, #0x40000000 @ enable SDRAM for Normal Access
  213. str r1, [r0]
  214. #endif /* NEW_SDRAM_INIT */
  215. #ifndef CFG_SKIP_DRAM_SCRUB
  216. /* scrub/init SDRAM if enabled/present */
  217. ldr r8, =CFG_DRAM_BASE /* base address of SDRAM (CFG_DRAM_BASE) */
  218. ldr r9, =CFG_DRAM_SIZE /* size of memory to scrub (CFG_DRAM_SIZE) */
  219. mov r0, #0 /* scrub with 0x0000:0000 */
  220. mov r1, #0
  221. mov r2, #0
  222. mov r3, #0
  223. mov r4, #0
  224. mov r5, #0
  225. mov r6, #0
  226. mov r7, #0
  227. 10: /* fastScrubLoop */
  228. subs r9, r9, #32 /* 8 words/line */
  229. stmia r8!, {r0-r7}
  230. beq 15f
  231. b 10b
  232. #endif /* CFG_SKIP_DRAM_SCRUB */
  233. 15:
  234. /* Mask all interrupts */
  235. mov r1, #0
  236. mcr p6, 0, r1, c1, c0, 0 @ ICMR
  237. /* Disable software and data breakpoints */
  238. mov r0, #0
  239. mcr p15,0,r0,c14,c8,0 /* ibcr0 */
  240. mcr p15,0,r0,c14,c9,0 /* ibcr1 */
  241. mcr p15,0,r0,c14,c4,0 /* dbcon */
  242. /* Enable all debug functionality */
  243. mov r0,#0x80000000
  244. mcr p14,0,r0,c10,c0,0 /* dcsr */
  245. endlowlevel_init:
  246. mov pc, lr
  247. /*
  248. @********************************************************************************
  249. @ DDR calibration
  250. @
  251. @ This function is used to calibrate DQS delay lines.
  252. @ Monahans supports three ways to do it. One is software
  253. @ calibration. Two is hardware calibration. Three is hybrid
  254. @ calibration.
  255. @
  256. @ TBD
  257. @ -SC
  258. ddr_calibration:
  259. @ Case 1: Write the correct delay value once
  260. @ Configure DDR_SCAL Register
  261. ldr r0, =DDR_SCAL @ DDR_SCAL
  262. q ldr r1, =0xaf2f2f2f
  263. str r1, [r0]
  264. ldr r1, [r0]
  265. */
  266. /* @ Case 2: Software Calibration
  267. @ Write test pattern to memory
  268. ldr r5, =0x0faf0faf @ Data Pattern
  269. ldr r4, =0xa0000000 @ DDR ram
  270. str r5, [r4]
  271. mov r1, =0x0 @ delay count
  272. mov r6, =0x0
  273. mov r7, =0x0
  274. ddr_loop1:
  275. add r1, r1, =0x1
  276. cmp r1, =0xf
  277. ble end_loop
  278. mov r3, r1
  279. mov r0, r1, lsl #30
  280. orr r3, r3, r0
  281. mov r0, r1, lsl #22
  282. orr r3, r3, r0
  283. mov r0, r1, lsl #14
  284. orr r3, r3, r0
  285. orr r3, r3, =0x80000000
  286. ldr r2, =DDR_SCAL
  287. str r3, [r2]
  288. ldr r2, [r4]
  289. cmp r2, r5
  290. bne ddr_loop1
  291. mov r6, r1
  292. ddr_loop2:
  293. add r1, r1, =0x1
  294. cmp r1, =0xf
  295. ble end_loop
  296. mov r3, r1
  297. mov r0, r1, lsl #30
  298. orr r3, r3, r0
  299. mov r0, r1, lsl #22
  300. orr r3, r3, r0
  301. mov r0, r1, lsl #14
  302. orr r3, r3, r0
  303. orr r3, r3, =0x80000000
  304. ldr r2, =DDR_SCAL
  305. str r3, [r2]
  306. ldr r2, [r4]
  307. cmp r2, r5
  308. be ddr_loop2
  309. mov r7, r2
  310. add r3, r6, r7
  311. lsr r3, r3, =0x1
  312. mov r0, r1, lsl #30
  313. orr r3, r3, r0
  314. mov r0, r1, lsl #22
  315. orr r3, r3, r0
  316. mov r0, r1, lsl #14
  317. orr r3, r3, r0
  318. orr r3, r3, =0x80000000
  319. ldr r2, =DDR_SCAL
  320. end_loop:
  321. @ Case 3: Hardware Calibratoin
  322. ldr r0, =DDR_HCAL @ DDR_HCAL
  323. ldr r1, =0x803ffc07 @ the offset is correct? -SC
  324. str r1, [r0]
  325. wait #5
  326. ldr r1, [r0]
  327. mov pc, lr
  328. */