lowlevel_init.S 6.7 KB

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