lowlevel_init.S 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. /*
  2. * Most of this taken from Redboot hal_platform_setup.h with cleanup
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <config.h>
  23. #include <version.h>
  24. #include <asm/arch/pxa-regs.h>
  25. DRAM_SIZE: .long CONFIG_SYS_DRAM_SIZE
  26. /* wait for coprocessor write complete */
  27. .macro CPWAIT reg
  28. mrc p15,0,\reg,c2,c0,0
  29. mov \reg,\reg
  30. sub pc,pc,#4
  31. .endm
  32. .globl lowlevel_init
  33. lowlevel_init:
  34. mov r10, lr
  35. /* Set up GPIO pins first */
  36. ldr r0, =GPSR0
  37. ldr r1, =CONFIG_SYS_GPSR0_VAL
  38. str r1, [r0]
  39. ldr r0, =GPSR1
  40. ldr r1, =CONFIG_SYS_GPSR1_VAL
  41. str r1, [r0]
  42. ldr r0, =GPSR2
  43. ldr r1, =CONFIG_SYS_GPSR2_VAL
  44. str r1, [r0]
  45. ldr r0, =GPCR0
  46. ldr r1, =CONFIG_SYS_GPCR0_VAL
  47. str r1, [r0]
  48. ldr r0, =GPCR1
  49. ldr r1, =CONFIG_SYS_GPCR1_VAL
  50. str r1, [r0]
  51. ldr r0, =GPCR2
  52. ldr r1, =CONFIG_SYS_GPCR2_VAL
  53. str r1, [r0]
  54. ldr r0, =GRER0
  55. ldr r1, =CONFIG_SYS_GRER0_VAL
  56. str r1, [r0]
  57. ldr r0, =GRER1
  58. ldr r1, =CONFIG_SYS_GRER1_VAL
  59. str r1, [r0]
  60. ldr r0, =GRER2
  61. ldr r1, =CONFIG_SYS_GRER2_VAL
  62. str r1, [r0]
  63. ldr r0, =GFER0
  64. ldr r1, =CONFIG_SYS_GFER0_VAL
  65. str r1, [r0]
  66. ldr r0, =GFER1
  67. ldr r1, =CONFIG_SYS_GFER1_VAL
  68. str r1, [r0]
  69. ldr r0, =GFER2
  70. ldr r1, =CONFIG_SYS_GFER2_VAL
  71. str r1, [r0]
  72. ldr r0, =GPDR0
  73. ldr r1, =CONFIG_SYS_GPDR0_VAL
  74. str r1, [r0]
  75. ldr r0, =GPDR1
  76. ldr r1, =CONFIG_SYS_GPDR1_VAL
  77. str r1, [r0]
  78. ldr r0, =GPDR2
  79. ldr r1, =CONFIG_SYS_GPDR2_VAL
  80. str r1, [r0]
  81. ldr r0, =GAFR0_L
  82. ldr r1, =CONFIG_SYS_GAFR0_L_VAL
  83. str r1, [r0]
  84. ldr r0, =GAFR0_U
  85. ldr r1, =CONFIG_SYS_GAFR0_U_VAL
  86. str r1, [r0]
  87. ldr r0, =GAFR1_L
  88. ldr r1, =CONFIG_SYS_GAFR1_L_VAL
  89. str r1, [r0]
  90. ldr r0, =GAFR1_U
  91. ldr r1, =CONFIG_SYS_GAFR1_U_VAL
  92. str r1, [r0]
  93. ldr r0, =GAFR2_L
  94. ldr r1, =CONFIG_SYS_GAFR2_L_VAL
  95. str r1, [r0]
  96. ldr r0, =GAFR2_U
  97. ldr r1, =CONFIG_SYS_GAFR2_U_VAL
  98. str r1, [r0]
  99. /* enable GPIO pins */
  100. ldr r0, =PSSR
  101. ldr r1, =CONFIG_SYS_PSSR_VAL
  102. str r1, [r0]
  103. /*********************************************************************
  104. Initlialize Memory Controller
  105. See PXA250 Operating System Developer's Guide
  106. pause for 200 uSecs- allow internal clocks to settle
  107. *Note: only need this if hard reset... doing it anyway for now
  108. */
  109. @ Step 1
  110. @ ---- Wait 200 usec
  111. ldr r3, =OSCR @ reset the OS Timer Count to zero
  112. mov r2, #0
  113. str r2, [r3]
  114. ldr r4, =0x300 @ really 0x2E1 is about 200usec, so 0x300 should be plenty
  115. 1:
  116. ldr r2, [r3]
  117. cmp r4, r2
  118. bgt 1b
  119. mem_init:
  120. @ get memory controller base address
  121. ldr r1, =MEMC_BASE
  122. @****************************************************************************
  123. @ Step 2
  124. @
  125. @ Step 2a
  126. @ write msc0, read back to ensure data latches
  127. @
  128. ldr r2, =CONFIG_SYS_MSC0_VAL
  129. str r2, [r1, #MSC0_OFFSET]
  130. ldr r2, [r1, #MSC0_OFFSET]
  131. @ write msc1
  132. ldr r2, =CONFIG_SYS_MSC1_VAL
  133. str r2, [r1, #MSC1_OFFSET]
  134. ldr r2, [r1, #MSC1_OFFSET]
  135. @ write msc2
  136. ldr r2, =CONFIG_SYS_MSC2_VAL
  137. str r2, [r1, #MSC2_OFFSET]
  138. ldr r2, [r1, #MSC2_OFFSET]
  139. @ Step 2b
  140. @ write mecr
  141. ldr r2, =CONFIG_SYS_MECR_VAL
  142. str r2, [r1, #MECR_OFFSET]
  143. @ write mcmem0
  144. ldr r2, =CONFIG_SYS_MCMEM0_VAL
  145. str r2, [r1, #MCMEM0_OFFSET]
  146. @ write mcmem1
  147. ldr r2, =CONFIG_SYS_MCMEM1_VAL
  148. str r2, [r1, #MCMEM1_OFFSET]
  149. @ write mcatt0
  150. ldr r2, =CONFIG_SYS_MCATT0_VAL
  151. str r2, [r1, #MCATT0_OFFSET]
  152. @ write mcatt1
  153. ldr r2, =CONFIG_SYS_MCATT1_VAL
  154. str r2, [r1, #MCATT1_OFFSET]
  155. @ write mcio0
  156. ldr r2, =CONFIG_SYS_MCIO0_VAL
  157. str r2, [r1, #MCIO0_OFFSET]
  158. @ write mcio1
  159. ldr r2, =CONFIG_SYS_MCIO1_VAL
  160. str r2, [r1, #MCIO1_OFFSET]
  161. @ Step 2c
  162. @ fly-by-dma is defeatured on this part
  163. @ write flycnfg
  164. @ldr r2, =CONFIG_SYS_FLYCNFG_VAL
  165. @str r2, [r1, #FLYCNFG_OFFSET]
  166. /* FIXME Does this sequence really make sense */
  167. #ifdef REDBOOT_WAY
  168. @ Step 2d
  169. @ get the mdrefr settings
  170. ldr r3, =CONFIG_SYS_MDREFR_VAL
  171. @ extract DRI field (we need a valid DRI field)
  172. @
  173. ldr r2, =0xFFF
  174. @ valid DRI field in r3
  175. @
  176. and r3, r3, r2
  177. @ get the reset state of MDREFR
  178. @
  179. ldr r4, [r1, #MDREFR_OFFSET]
  180. @ clear the DRI field
  181. @
  182. bic r4, r4, r2
  183. @ insert the valid DRI field loaded above
  184. @
  185. orr r4, r4, r3
  186. @ write back mdrefr
  187. @
  188. str r4, [r1, #MDREFR_OFFSET]
  189. @ *Note: preserve the mdrefr value in r4 *
  190. @****************************************************************************
  191. @ Step 3
  192. @
  193. @ NO SRAM
  194. mov pc, r10
  195. @****************************************************************************
  196. @ Step 4
  197. @
  198. @ Assumes previous mdrefr value in r4, if not then read current mdrefr
  199. @ clear the free-running clock bits
  200. @ (clear K0Free, K1Free, K2Free
  201. @
  202. bic r4, r4, #(0x00800000 | 0x01000000 | 0x02000000)
  203. @ set K0RUN for CPLD clock
  204. @
  205. orr r4, r4, #0x00002000
  206. @ set K1RUN if bank 0 installed
  207. @
  208. orr r4, r4, #0x00010000
  209. @ write back mdrefr
  210. @
  211. str r4, [r1, #MDREFR_OFFSET]
  212. ldr r4, [r1, #MDREFR_OFFSET]
  213. @ deassert SLFRSH
  214. @
  215. bic r4, r4, #0x00400000
  216. @ write back mdrefr
  217. @
  218. str r4, [r1, #MDREFR_OFFSET]
  219. @ assert E1PIN
  220. @
  221. orr r4, r4, #0x00008000
  222. @ write back mdrefr
  223. @
  224. str r4, [r1, #MDREFR_OFFSET]
  225. ldr r4, [r1, #MDREFR_OFFSET]
  226. nop
  227. nop
  228. #else
  229. @ Step 2d
  230. @ get the mdrefr settings
  231. ldr r3, =CONFIG_SYS_MDREFR_VAL
  232. @ write back mdrefr
  233. @
  234. str r4, [r1, #MDREFR_OFFSET]
  235. @ Step 4
  236. @ set K0RUN for CPLD clock
  237. @
  238. orr r4, r4, #0x00002000
  239. @ set K1RUN for bank 0
  240. @
  241. orr r4, r4, #0x00010000
  242. @ write back mdrefr
  243. @
  244. str r4, [r1, #MDREFR_OFFSET]
  245. ldr r4, [r1, #MDREFR_OFFSET]
  246. @ deassert SLFRSH
  247. @
  248. bic r4, r4, #0x00400000
  249. @ write back mdrefr
  250. @
  251. str r4, [r1, #MDREFR_OFFSET]
  252. @ assert E1PIN
  253. @
  254. orr r4, r4, #0x00008000
  255. @ write back mdrefr
  256. @
  257. str r4, [r1, #MDREFR_OFFSET]
  258. ldr r4, [r1, #MDREFR_OFFSET]
  259. nop
  260. nop
  261. #endif
  262. @ Step 4d
  263. @ fetch platform value of mdcnfg
  264. @
  265. ldr r2, =CONFIG_SYS_MDCNFG_VAL
  266. @ disable all sdram banks
  267. @
  268. bic r2, r2, #(MDCNFG_DE0 | MDCNFG_DE1)
  269. bic r2, r2, #(MDCNFG_DE2 | MDCNFG_DE3)
  270. @ program banks 0/1 for bus width
  271. @
  272. bic r2, r2, #MDCNFG_DWID0 @0=32-bit
  273. @ write initial value of mdcnfg, w/o enabling sdram banks
  274. @
  275. str r2, [r1, #MDCNFG_OFFSET]
  276. @ Step 4e
  277. @ pause for 200 uSecs
  278. @
  279. ldr r3, =OSCR @ reset the OS Timer Count to zero
  280. mov r2, #0
  281. str r2, [r3]
  282. ldr r4, =0x300 @ really 0x2E1 is about 200usec, so 0x300 should be plenty
  283. 1:
  284. ldr r2, [r3]
  285. cmp r4, r2
  286. bgt 1b
  287. /* Why is this here??? */
  288. mov r0, #0x78 @turn everything off
  289. mcr p15, 0, r0, c1, c0, 0 @(caches off, MMU off, etc.)
  290. @ Step 4f
  291. @ Access memory *not yet enabled* for CBR refresh cycles (8)
  292. @ - CBR is generated for all banks
  293. ldr r2, =CONFIG_SYS_DRAM_BASE
  294. str r2, [r2]
  295. str r2, [r2]
  296. str r2, [r2]
  297. str r2, [r2]
  298. str r2, [r2]
  299. str r2, [r2]
  300. str r2, [r2]
  301. str r2, [r2]
  302. @ Step 4g
  303. @get memory controller base address
  304. @
  305. ldr r1, =MEMC_BASE
  306. @fetch current mdcnfg value
  307. @
  308. ldr r3, [r1, #MDCNFG_OFFSET]
  309. @enable sdram bank 0 if installed (must do for any populated bank)
  310. @
  311. orr r3, r3, #MDCNFG_DE0
  312. @write back mdcnfg, enabling the sdram bank(s)
  313. @
  314. str r3, [r1, #MDCNFG_OFFSET]
  315. @ Step 4h
  316. @ write mdmrs
  317. @
  318. ldr r2, =CONFIG_SYS_MDMRS_VAL
  319. str r2, [r1, #MDMRS_OFFSET]
  320. @ Done Memory Init
  321. /*SET_LED 6 */
  322. @********************************************************************
  323. @ Disable (mask) all interrupts at the interrupt controller
  324. @
  325. @ clear the interrupt level register (use IRQ, not FIQ)
  326. @
  327. mov r1, #0
  328. ldr r2, =ICLR
  329. str r1, [r2]
  330. @ Set interrupt mask register
  331. @
  332. ldr r1, =CONFIG_SYS_ICMR_VAL
  333. ldr r2, =ICMR
  334. str r1, [r2]
  335. @ ********************************************************************
  336. @ Disable the peripheral clocks, and set the core clock
  337. @
  338. @ Turn Off ALL on-chip peripheral clocks for re-configuration
  339. @
  340. ldr r1, =CKEN
  341. mov r2, #0
  342. str r2, [r1]
  343. @ set core clocks
  344. @
  345. ldr r2, =CONFIG_SYS_CCCR_VAL
  346. ldr r1, =CCCR
  347. str r2, [r1]
  348. #ifdef ENABLE32KHZ
  349. @ enable the 32Khz oscillator for RTC and PowerManager
  350. @
  351. ldr r1, =OSCC
  352. mov r2, #OSCC_OON
  353. str r2, [r1]
  354. @ NOTE: spin here until OSCC.OOK get set,
  355. @ meaning the PLL has settled.
  356. @
  357. 60:
  358. ldr r2, [r1]
  359. ands r2, r2, #1
  360. beq 60b
  361. #endif
  362. @ Turn on needed clocks
  363. @
  364. ldr r1, =CKEN
  365. ldr r2, =CONFIG_SYS_CKEN_VAL
  366. str r2, [r1]
  367. /*SET_LED 7 */
  368. /* Is this needed???? */
  369. #define NODEBUG
  370. #ifdef NODEBUG
  371. /*Disable software and data breakpoints */
  372. mov r0,#0
  373. mcr p15,0,r0,c14,c8,0 /* ibcr0 */
  374. mcr p15,0,r0,c14,c9,0 /* ibcr1 */
  375. mcr p15,0,r0,c14,c4,0 /* dbcon */
  376. /*Enable all debug functionality */
  377. mov r0,#0x80000000
  378. mcr p14,0,r0,c10,c0,0 /* dcsr */
  379. #endif
  380. mov pc, r10
  381. @ End lowlevel_init