lowlevel_init.S 10 KB

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