lowlevel_init.S 11 KB

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