lowlevel_init.S 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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 41 - 48 as UART1 / altern. Fkt. 2 */
  54. ldr r0, =0x40E10438 @ GPIO41 FFRXD
  55. ldr r1, =0x802
  56. str r1, [r0]
  57. ldr r0, =0x40E1043C @ GPIO42 FFTXD
  58. ldr r1, =0x802
  59. str r1, [r0]
  60. ldr r0, =0x40E10440 @ GPIO43 FFCTS
  61. ldr r1, =0x802
  62. str r1, [r0]
  63. ldr r0, =0x40E10444 @ GPIO 44 FFDCD
  64. ldr r1, =0x802
  65. str r1, [r0]
  66. ldr r0, =0x40E10448 @ GPIO 45 FFDSR
  67. ldr r1, =0x802
  68. str r1, [r0]
  69. ldr r0, =0x40E1044C @ GPIO 46 FFRI
  70. ldr r1, =0x802
  71. str r1, [r0]
  72. ldr r0, =0x40E10450 @ GPIO 47 FFDTR
  73. ldr r1, =0x802
  74. str r1, [r0]
  75. ldr r0, =0x40E10454 @ GPIO 48
  76. ldr r1, =0x802
  77. str r1, [r0]
  78. /* tebrandt - ASCR, clear the RDH bit */
  79. ldr r0, =ASCR
  80. ldr r1, [r0]
  81. bic r1, r1, #0x80000000
  82. str r1, [r0]
  83. /* ---------------------------------------------------------------- */
  84. /* Enable memory interface */
  85. /* */
  86. /* The sequence below is based on the recommended init steps */
  87. /* detailed in the Intel PXA250 Operating Systems Developers Guide, */
  88. /* Chapter 10. */
  89. /* ---------------------------------------------------------------- */
  90. /* ---------------------------------------------------------------- */
  91. /* Step 1: Wait for at least 200 microsedonds to allow internal */
  92. /* clocks to settle. Only necessary after hard reset... */
  93. /* FIXME: can be optimized later */
  94. /* ---------------------------------------------------------------- */
  95. /* mk: replaced with wait macro */
  96. /* ldr r3, =OSCR /\* reset the OS Timer Count to zero *\/ */
  97. /* mov r2, #0 */
  98. /* str r2, [r3] */
  99. /* ldr r4, =0x300 /\* really 0x2E1 is about 200usec, *\/ */
  100. /* /\* so 0x300 should be plenty *\/ */
  101. /* 1: */
  102. /* ldr r2, [r3] */
  103. /* cmp r4, r2 */
  104. /* bgt 1b */
  105. wait #300
  106. mem_init:
  107. /* configure the MEMCLKCFG register */
  108. ldr r1, =MEMCLKCFG
  109. ldr r2, =0x00010001
  110. str r2, [r1] @ WRITE
  111. ldr r2, [r1] @ DELAY UNTIL WRITTEN
  112. /* set CSADRCFG[0] to data flash SRAM mode */
  113. ldr r1, =CSADRCFG0
  114. ldr r2, =0x00320809
  115. str r2, [r1] @ WRITE
  116. ldr r2, [r1] @ DELAY UNTIL WRITTEN
  117. /* set CSADRCFG[1] to data flash SRAM mode */
  118. ldr r1, =CSADRCFG1
  119. ldr r2, =0x00320809
  120. str r2, [r1] @ WRITE
  121. ldr r2, [r1] @ DELAY UNTIL WRITTEN
  122. /* set MSC 0 register for SRAM memory */
  123. ldr r1, =MSC0
  124. ldr r2, =0x11191119
  125. str r2, [r1] @ WRITE
  126. ldr r2, [r1] @ DELAY UNTIL WRITTEN
  127. /* set CSADRCFG[2] to data flash SRAM mode */
  128. ldr r1, =CSADRCFG2
  129. ldr r2, =0x00320809
  130. str r2, [r1] @ WRITE
  131. ldr r2, [r1] @ DELAY UNTIL WRITTEN
  132. /* set CSADRCFG[3] to VLIO mode */
  133. ldr r1, =CSADRCFG3
  134. ldr r2, =0x0032080B
  135. str r2, [r1] @ WRITE
  136. ldr r2, [r1] @ DELAY UNTIL WRITTEN
  137. /* set MSC 1 register for VLIO memory */
  138. ldr r1, =MSC1
  139. ldr r2, =0x123C1119
  140. str r2, [r1] @ WRITE
  141. ldr r2, [r1] @ DELAY UNTIL WRITTEN
  142. #if 0
  143. /* This does not work in Zylonite. -SC */
  144. ldr r0, =0x15fffff0
  145. ldr r1, =0xb10b
  146. str r1, [r0]
  147. str r1, [r0, #4]
  148. #endif
  149. /* Configure ACCR Register */
  150. ldr r0, =ACCR @ ACCR
  151. ldr r1, =0x0180b108
  152. str r1, [r0]
  153. ldr r1, [r0]
  154. /* Configure MDCNFG Register */
  155. ldr r0, =MDCNFG @ MDCNFG
  156. ldr r1, =0x403
  157. str r1, [r0]
  158. ldr r1, [r0]
  159. /* Perform Resistive Compensation by configuring RCOMP register */
  160. ldr r1, =RCOMP @ RCOMP
  161. ldr r2, =0x000000ff
  162. str r2, [r1]
  163. ldr r2, [r1]
  164. /* Configure MDMRS Register for SDCS0 */
  165. ldr r1, =MDMRS @ MDMRS
  166. ldr r2, =0x60000023
  167. ldr r3, [r1]
  168. orr r2, r2, r3
  169. str r2, [r1]
  170. ldr r2, [r1]
  171. /* Configure MDMRS Register for SDCS1 */
  172. ldr r1, =MDMRS @ MDMRS
  173. ldr r2, =0xa0000023
  174. ldr r3, [r1]
  175. orr r2, r2, r3
  176. str r2, [r1]
  177. ldr r2, [r1]
  178. /* Configure MDREFR */
  179. ldr r1, =MDREFR @ MDREFR
  180. ldr r2, =0x00000006
  181. str r2, [r1]
  182. ldr r2, [r1]
  183. /* Configure EMPI */
  184. ldr r1, =EMPI @ EMPI
  185. ldr r2, =0x80000000
  186. str r2, [r1]
  187. ldr r2, [r1]
  188. /* Hardware DDR Read-Strobe Delay Calibration */
  189. ldr r0, =DDR_HCAL @ DDR_HCAL
  190. ldr r1, =0x803ffc07 @ the offset is correct? -SC
  191. str r1, [r0]
  192. wait #5
  193. ldr r1, [r0]
  194. /* Here we assume the hardware calibration alwasy be successful. -SC */
  195. /* Set DMCEN bit in MDCNFG Register */
  196. ldr r0, =MDCNFG @ MDCNFG
  197. ldr r1, [r0]
  198. orr r1, r1, #0x40000000 @ enable SDRAM for Normal Access
  199. str r1, [r0]
  200. #ifndef CFG_SKIP_DRAM_SCRUB
  201. /* scrub/init SDRAM if enabled/present */
  202. /* ldr r11, =0xa0000000 /\* base address of SDRAM (CFG_DRAM_BASE) *\/ */
  203. /* ldr r12, =0x04000000 /\* size of memory to scrub (CFG_DRAM_SIZE) *\/ */
  204. /* mov r8,r12 /\* save DRAM size (mk: why???) *\/ */
  205. ldr r8, =0xa0000000 /* base address of SDRAM (CFG_DRAM_BASE) */
  206. ldr r9, =0x04000000 /* size of memory to scrub (CFG_DRAM_SIZE) */
  207. mov r0, #0 /* scrub with 0x0000:0000 */
  208. mov r1, #0
  209. mov r2, #0
  210. mov r3, #0
  211. mov r4, #0
  212. mov r5, #0
  213. mov r6, #0
  214. mov r7, #0
  215. 10: /* fastScrubLoop */
  216. subs r9, r9, #32 /* 32 bytes/line */
  217. stmia r8!, {r0-r7}
  218. beq 15f
  219. b 10b
  220. #endif /* CFG_SKIP_DRAM_SCRUB */
  221. 15:
  222. /* Mask all interrupts */
  223. mov r1, #0
  224. mcr p6, 0, r1, c1, c0, 0 @ ICMR
  225. /* Disable software and data breakpoints */
  226. mov r0, #0
  227. mcr p15,0,r0,c14,c8,0 /* ibcr0 */
  228. mcr p15,0,r0,c14,c9,0 /* ibcr1 */
  229. mcr p15,0,r0,c14,c4,0 /* dbcon */
  230. /* Enable all debug functionality */
  231. mov r0,#0x80000000
  232. mcr p14,0,r0,c10,c0,0 /* dcsr */
  233. /* We are finished with Intel's memory controller initialisation */
  234. /* ---------------------------------------------------------------- */
  235. /* End lowlevel_init */
  236. /* ---------------------------------------------------------------- */
  237. endlowlevel_init:
  238. mov pc, lr
  239. /*
  240. @********************************************************************************
  241. @ DDR calibration
  242. @
  243. @ This function is used to calibrate DQS delay lines.
  244. @ Monahans supports three ways to do it. One is software
  245. @ calibration. Two is hardware calibration. Three is hybrid
  246. @ calibration.
  247. @
  248. @ TBD
  249. @ -SC
  250. ddr_calibration:
  251. @ Case 1: Write the correct delay value once
  252. @ Configure DDR_SCAL Register
  253. ldr r0, =DDR_SCAL @ DDR_SCAL
  254. q ldr r1, =0xaf2f2f2f
  255. str r1, [r0]
  256. ldr r1, [r0]
  257. */
  258. /* @ Case 2: Software Calibration
  259. @ Write test pattern to memory
  260. ldr r5, =0x0faf0faf @ Data Pattern
  261. ldr r4, =0xa0000000 @ DDR ram
  262. str r5, [r4]
  263. mov r1, =0x0 @ delay count
  264. mov r6, =0x0
  265. mov r7, =0x0
  266. ddr_loop1:
  267. add r1, r1, =0x1
  268. cmp r1, =0xf
  269. ble end_loop
  270. mov r3, r1
  271. mov r0, r1, lsl #30
  272. orr r3, r3, r0
  273. mov r0, r1, lsl #22
  274. orr r3, r3, r0
  275. mov r0, r1, lsl #14
  276. orr r3, r3, r0
  277. orr r3, r3, =0x80000000
  278. ldr r2, =DDR_SCAL
  279. str r3, [r2]
  280. ldr r2, [r4]
  281. cmp r2, r5
  282. bne ddr_loop1
  283. mov r6, r1
  284. ddr_loop2:
  285. add r1, r1, =0x1
  286. cmp r1, =0xf
  287. ble end_loop
  288. mov r3, r1
  289. mov r0, r1, lsl #30
  290. orr r3, r3, r0
  291. mov r0, r1, lsl #22
  292. orr r3, r3, r0
  293. mov r0, r1, lsl #14
  294. orr r3, r3, r0
  295. orr r3, r3, =0x80000000
  296. ldr r2, =DDR_SCAL
  297. str r3, [r2]
  298. ldr r2, [r4]
  299. cmp r2, r5
  300. be ddr_loop2
  301. mov r7, r2
  302. add r3, r6, r7
  303. lsr r3, r3, =0x1
  304. mov r0, r1, lsl #30
  305. orr r3, r3, r0
  306. mov r0, r1, lsl #22
  307. orr r3, r3, r0
  308. mov r0, r1, lsl #14
  309. orr r3, r3, r0
  310. orr r3, r3, =0x80000000
  311. ldr r2, =DDR_SCAL
  312. end_loop:
  313. @ Case 3: Hardware Calibratoin
  314. ldr r0, =DDR_HCAL @ DDR_HCAL
  315. ldr r1, =0x803ffc07 @ the offset is correct? -SC
  316. str r1, [r0]
  317. wait #5
  318. ldr r1, [r0]
  319. mov pc, lr
  320. */