lowlevel_init.S 9.7 KB

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