lowlevel_init.S 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. /* Memory sub-system initialization code */
  2. #include <config.h>
  3. #include <asm/regdef.h>
  4. #include <asm/au1x00.h>
  5. #include <asm/mipsregs.h>
  6. #define CP0_Config0 $16
  7. #define MEM_1MS ((CONFIG_SYS_MHZ) * 1000)
  8. #define GPIO_RJ1LY (1<<22)
  9. #define GPIO_CFRESET (1<<10)
  10. .text
  11. .set noreorder
  12. .set mips32
  13. .globl lowlevel_init
  14. lowlevel_init:
  15. /*
  16. * Step 2) Establish Status Register
  17. * (set BEV, clear ERL, clear EXL, clear IE)
  18. */
  19. li t1, 0x00400000
  20. mtc0 t1, CP0_STATUS
  21. /*
  22. * Step 3) Establish CP0 Config0
  23. * (set OD, set K0=3)
  24. */
  25. li t1, 0x00080003
  26. mtc0 t1, CP0_CONFIG
  27. /*
  28. * Step 4) Disable Watchpoint facilities
  29. */
  30. li t1, 0x00000000
  31. mtc0 t1, CP0_WATCHLO
  32. mtc0 t1, CP0_IWATCHLO
  33. /*
  34. * Step 5) Disable the performance counters
  35. */
  36. mtc0 zero, CP0_PERFORMANCE
  37. nop
  38. /*
  39. * Step 6) Establish EJTAG Debug register
  40. */
  41. mtc0 zero, CP0_DEBUG
  42. nop
  43. /*
  44. * Step 7) Establish Cause
  45. * (set IV bit)
  46. */
  47. li t1, 0x00800000
  48. mtc0 t1, CP0_CAUSE
  49. /* Establish Wired (and Random) */
  50. mtc0 zero, CP0_WIRED
  51. nop
  52. /* No workaround if running from ram */
  53. lui t0, 0xffc0
  54. lui t3, 0xbfc0
  55. and t1, ra, t0
  56. bne t1, t3, noCacheJump
  57. nop
  58. /*** From AMD YAMON ***/
  59. /*
  60. * Step 8) Initialize the caches
  61. */
  62. li t0, (16*1024)
  63. li t1, 32
  64. li t2, 0x80000000
  65. addu t3, t0, t2
  66. cacheloop:
  67. cache 0, 0(t2)
  68. cache 1, 0(t2)
  69. addu t2, t1
  70. bne t2, t3, cacheloop
  71. nop
  72. /* Save return address */
  73. move t3, ra
  74. /* Run from cacheable space now */
  75. bal cachehere
  76. nop
  77. cachehere:
  78. li t1, ~0x20000000 /* convert to KSEG0 */
  79. and t0, ra, t1
  80. addi t0, 5*4 /* 5 insns beyond cachehere */
  81. jr t0
  82. nop
  83. /* Restore return address */
  84. move ra, t3
  85. /*
  86. * Step 9) Initialize the TLB
  87. */
  88. li t0, 0 # index value
  89. li t1, 0x00000000 # entryhi value
  90. li t2, 32 # 32 entries
  91. tlbloop:
  92. /* Probe TLB for matching EntryHi */
  93. mtc0 t1, CP0_ENTRYHI
  94. tlbp
  95. nop
  96. /* Examine Index[P], 1=no matching entry */
  97. mfc0 t3, CP0_INDEX
  98. li t4, 0x80000000
  99. and t3, t4, t3
  100. addiu t1, t1, 1 # increment t1 (asid)
  101. beq zero, t3, tlbloop
  102. nop
  103. /* Initialize the TLB entry */
  104. mtc0 t0, CP0_INDEX
  105. mtc0 zero, CP0_ENTRYLO0
  106. mtc0 zero, CP0_ENTRYLO1
  107. mtc0 zero, CP0_PAGEMASK
  108. tlbwi
  109. /* Do it again */
  110. addiu t0, t0, 1
  111. bne t0, t2, tlbloop
  112. nop
  113. /* First setup pll:s to make serial work ok */
  114. /* We have a 12.5 MHz crystal */
  115. li t0, SYS_CPUPLL
  116. li t1, 0x28 /* CPU clock, 500 MHz */
  117. sw t1, 0(t0)
  118. sync
  119. nop
  120. nop
  121. /* wait 1mS for clocks to settle */
  122. li t1, MEM_1MS
  123. 1: add t1, -1
  124. bne t1, zero, 1b
  125. nop
  126. /* Setup AUX PLL */
  127. li t0, SYS_AUXPLL
  128. li t1, 0
  129. sw t1, 0(t0) /* aux pll */
  130. sync
  131. /* Static memory controller */
  132. /* RCE0 - can not change while fetching, do so from icache */
  133. move t2, ra /* Store return address */
  134. bal getAddr
  135. nop
  136. getAddr:
  137. move t1, ra
  138. move ra, t2 /* Move return addess back */
  139. cache 0x14,0(t1)
  140. cache 0x14,32(t1)
  141. /*** /From YAMON ***/
  142. noCacheJump:
  143. /* Static memory controller */
  144. /* RCE0 AMD 29LV800 Flash */
  145. li t0, MEM_STCFG0
  146. li t1, 0x00000243
  147. sw t1, 0(t0)
  148. li t0, MEM_STTIME0
  149. li t1, 0x040181D7 /* FIXME */
  150. sw t1, 0(t0)
  151. li t0, MEM_STADDR0
  152. li t1, 0x11E03F80
  153. sw t1, 0(t0)
  154. /* RCE1 PCMCIA 250ns */
  155. li t0, MEM_STCFG1
  156. li t1, 0x00000002
  157. sw t1, 0(t0)
  158. li t0, MEM_STTIME1
  159. li t1, 0x280E3E07
  160. sw t1, 0(t0)
  161. li t0, MEM_STADDR1
  162. li t1, 0x10000000
  163. sw t1, 0(t0)
  164. /* RCE2 CP Altera */
  165. li t0, MEM_STCFG2
  166. li t1, 0x00000280 /* BE, EW */
  167. sw t1, 0(t0)
  168. li t0, MEM_STTIME2
  169. li t1, 0x0303000c
  170. sw t1, 0(t0)
  171. li t0, MEM_STADDR2
  172. li t1, 0x10c03f80 /* 1 MB */
  173. sw t1, 0(t0)
  174. /* RCE3 DP Altera */
  175. li t0, MEM_STCFG3
  176. li t1, 0x00000280 /* BE, EW */
  177. sw t1, 0(t0)
  178. li t0, MEM_STTIME3
  179. li t1, 0x0303000c
  180. sw t1, 0(t0)
  181. li t0, MEM_STADDR3
  182. li t1, 0x10e03f80 /* 1 MB */
  183. sw t1, 0(t0)
  184. sync
  185. /* Set peripherals to a known state */
  186. li t0, IC0_CFG0CLR
  187. li t1, 0xFFFFFFFF
  188. sw t1, 0(t0)
  189. li t0, IC0_CFG0CLR
  190. sw t1, 0(t0)
  191. li t0, IC0_CFG1CLR
  192. sw t1, 0(t0)
  193. li t0, IC0_CFG2CLR
  194. sw t1, 0(t0)
  195. li t0, IC0_SRCSET
  196. sw t1, 0(t0)
  197. li t0, IC0_ASSIGNSET
  198. sw t1, 0(t0)
  199. li t0, IC0_WAKECLR
  200. sw t1, 0(t0)
  201. li t0, IC0_RISINGCLR
  202. sw t1, 0(t0)
  203. li t0, IC0_FALLINGCLR
  204. sw t1, 0(t0)
  205. li t0, IC0_TESTBIT
  206. li t1, 0x00000000
  207. sw t1, 0(t0)
  208. sync
  209. li t0, IC1_CFG0CLR
  210. li t1, 0xFFFFFFFF
  211. sw t1, 0(t0)
  212. li t0, IC1_CFG0CLR
  213. sw t1, 0(t0)
  214. li t0, IC1_CFG1CLR
  215. sw t1, 0(t0)
  216. li t0, IC1_CFG2CLR
  217. sw t1, 0(t0)
  218. li t0, IC1_SRCSET
  219. sw t1, 0(t0)
  220. li t0, IC1_ASSIGNSET
  221. sw t1, 0(t0)
  222. li t0, IC1_WAKECLR
  223. sw t1, 0(t0)
  224. li t0, IC1_RISINGCLR
  225. sw t1, 0(t0)
  226. li t0, IC1_FALLINGCLR
  227. sw t1, 0(t0)
  228. li t0, IC1_TESTBIT
  229. li t1, 0x00000000
  230. sw t1, 0(t0)
  231. sync
  232. li t0, SYS_FREQCTRL0
  233. li t1, 0x00000000
  234. sw t1, 0(t0)
  235. li t0, SYS_FREQCTRL1
  236. li t1, 0x00000000
  237. sw t1, 0(t0)
  238. li t0, SYS_CLKSRC
  239. li t1, 0x00000000
  240. sw t1, 0(t0)
  241. li t0, SYS_PININPUTEN
  242. li t1, 0x00000000
  243. sw t1, 0(t0)
  244. sync
  245. li t0, 0xB1100100
  246. li t1, 0x00000000
  247. sw t1, 0(t0)
  248. li t0, 0xB1400100
  249. li t1, 0x00000000
  250. sw t1, 0(t0)
  251. li t0, SYS_WAKEMSK
  252. li t1, 0x00000000
  253. sw t1, 0(t0)
  254. li t0, SYS_WAKESRC
  255. li t1, 0x00000000
  256. sw t1, 0(t0)
  257. /* wait 1mS before setup */
  258. li t1, MEM_1MS
  259. 1: add t1, -1
  260. bne t1, zero, 1b
  261. nop
  262. /* SDCS 0 SDRAM */
  263. li t0, MEM_SDMODE0
  264. li t1, 0x592CD1
  265. sw t1, 0(t0)
  266. li t0, MEM_SDMODE1
  267. li t1, 0x00000000
  268. sw t1, 0(t0)
  269. li t0, MEM_SDMODE2
  270. li t1, 0x00000000
  271. sw t1, 0(t0)
  272. /* 64 MB SDRAM at addr 0 */
  273. li t0, MEM_SDADDR0
  274. li t1, 0x001003F0
  275. sw t1, 0(t0)
  276. li t0, MEM_SDADDR1
  277. li t1, 0x00000000
  278. sw t1, 0(t0)
  279. li t0, MEM_SDADDR2
  280. li t1, 0x00000000
  281. sw t1, 0(t0)
  282. sync
  283. li t0, MEM_SDREFCFG
  284. li t1, 0x880007A1 /* Disable */
  285. sw t1, 0(t0)
  286. sync
  287. li t0, MEM_SDPRECMD
  288. sw zero, 0(t0)
  289. sync
  290. li t0, MEM_SDAUTOREF
  291. sw zero, 0(t0)
  292. sync
  293. sw zero, 0(t0)
  294. sync
  295. li t0, MEM_SDREFCFG
  296. li t1, 0x8A0007A1 /* Enable */
  297. sw t1, 0(t0)
  298. sync
  299. li t0, MEM_SDWRMD0
  300. li t1, 0x00000023
  301. sw t1, 0(t0)
  302. sync
  303. /* wait 1mS after setup */
  304. li t1, MEM_1MS
  305. 1: add t1, -1
  306. bne t1, zero, 1b
  307. nop
  308. /* Setup GPIO pins */
  309. li t0, SYS_PINFUNC
  310. li t1, 0x00007025 /* 0x8080 */
  311. sw t1, 0(t0)
  312. li t0, SYS_TRIOUTCLR
  313. li t1, 0xFFFFFFFF /* 0x1FFF */
  314. sw t1, 0(t0)
  315. /* Turn yellow front led on */
  316. /* Release reset on CF */
  317. li t0, SYS_OUTPUTCLR
  318. li t1, GPIO_RJ1LG
  319. sw t1, 0(t0)
  320. li t0, SYS_OUTPUTSET
  321. li t1, GPIO_RJ1LY|GPIO_CFRESET
  322. sw t1, 0(t0)
  323. sync
  324. j clearmem
  325. nop
  326. #if 0
  327. .globl memtest
  328. #endif
  329. memtest:
  330. /* Fill memory with address */
  331. li t0, 0x80000000
  332. li t1, 0xFFF000 /* 64 MB */
  333. mt0: sw t0, 0(t0)
  334. add t1, -1
  335. add t0, 4
  336. bne t1, zero, mt0
  337. nop
  338. nop
  339. /* Verify addr */
  340. li t0, 0x80000000
  341. li t1, 0xFFF000 /* 64 MB */
  342. mt1: lw t2, 0(t0)
  343. bne t0, t2, memhang
  344. add t1, -1
  345. add t0, 4
  346. bne t1, zero, mt1
  347. nop
  348. nop
  349. #if 0
  350. .globl clearmem
  351. #endif
  352. clearmem:
  353. /* Clear memory */
  354. li t0, 0x80000000
  355. li t1, 0xFFF000 /* 64 MB */
  356. mtc: sw zero, 0(t0)
  357. add t1, -1
  358. add t0, 4
  359. bne t1, zero, mtc
  360. nop
  361. nop
  362. memtestend:
  363. jr ra
  364. nop
  365. memhang:
  366. b memhang
  367. nop