init.S 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /*------------------------------------------------------------------------------+ */
  2. /* */
  3. /* This source code is dual-licensed. You may use it under the terms */
  4. /* of the GNU General Public License version 2, or under the license */
  5. /* below. */
  6. /* */
  7. /* This source code has been made available to you by IBM on an AS-IS */
  8. /* basis. Anyone receiving this source is licensed under IBM */
  9. /* copyrights to use it in any way he or she deems fit, including */
  10. /* copying it, modifying it, compiling it, and redistributing it either */
  11. /* with or without modifications. No license under IBM patents or */
  12. /* patent applications is to be implied by the copyright license. */
  13. /* */
  14. /* Any user of this software should understand that IBM cannot provide */
  15. /* technical support for this software and will not be responsible for */
  16. /* any consequences resulting from the use of this software. */
  17. /* */
  18. /* Any person who transfers this source code or any derivative work */
  19. /* must include the IBM copyright notice, this paragraph, and the */
  20. /* preceding two paragraphs in the transferred software. */
  21. /* */
  22. /* COPYRIGHT I B M CORPORATION 1995 */
  23. /* LICENSED MATERIAL - PROGRAM PROPERTY OF I B M */
  24. /*------------------------------------------------------------------------------- */
  25. /*----------------------------------------------------------------------------- */
  26. /* Function: ext_bus_cntlr_init */
  27. /* Description: Initializes the External Bus Controller for the external */
  28. /* peripherals. IMPORTANT: For pass1 this code must run from */
  29. /* cache since you can not reliably change a peripheral banks */
  30. /* timing register (pbxap) while running code from that bank. */
  31. /* For ex., since we are running from ROM on bank 0, we can NOT */
  32. /* execute the code that modifies bank 0 timings from ROM, so */
  33. /* we run it from cache. */
  34. /* */
  35. /*----------------------------------------------------------------------------- */
  36. #include <config.h>
  37. #include <asm/ppc4xx.h>
  38. #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
  39. #include <ppc_asm.tmpl>
  40. #include <ppc_defs.h>
  41. #include <asm/cache.h>
  42. #include <asm/mmu.h>
  43. .globl ext_bus_cntlr_init
  44. ext_bus_cntlr_init:
  45. mflr r4 /* save link register */
  46. bl ..getAddr
  47. ..getAddr:
  48. mflr r3 /* get address of ..getAddr */
  49. mtlr r4 /* restore link register */
  50. addi r4,0,14 /* set ctr to 10; used to prefetch */
  51. mtctr r4 /* 10 cache lines to fit this function */
  52. /* in cache (gives us 8x10=80 instrctns) */
  53. ..ebcloop:
  54. icbt r0,r3 /* prefetch cache line for addr in r3 */
  55. addi r3,r3,32 /* move to next cache line */
  56. bdnz ..ebcloop /* continue for 10 cache lines */
  57. /*------------------------------------------------------------------- */
  58. /* Delay to ensure all accesses to ROM are complete before changing */
  59. /* bank 0 timings. 200usec should be enough. */
  60. /* 200,000,000 (cycles/sec) X .000200 (sec) = 0x9C40 cycles */
  61. /*------------------------------------------------------------------- */
  62. addis r3,0,0x0
  63. ori r3,r3,0xA000 /* ensure 200usec have passed since reset */
  64. mtctr r3
  65. ..spinlp:
  66. bdnz ..spinlp /* spin loop */
  67. /*----------------------------------------------------------------------- */
  68. /* Memory Bank 0 (Flash) initialization (from openbios) */
  69. /*----------------------------------------------------------------------- */
  70. addi r4,0,PB1AP
  71. mtdcr EBC0_CFGADDR,r4
  72. addis r4,0,CS0_AP@h
  73. ori r4,r4,CS0_AP@l
  74. mtdcr EBC0_CFGDATA,r4
  75. addi r4,0,PB0CR
  76. mtdcr EBC0_CFGADDR,r4
  77. addis r4,0,CS0_CR@h
  78. ori r4,r4,CS0_CR@l
  79. mtdcr EBC0_CFGDATA,r4
  80. /*----------------------------------------------------------------------- */
  81. /* Memory Bank 1 (NVRAM/RTC) initialization */
  82. /*----------------------------------------------------------------------- */
  83. addi r4,0,PB1AP
  84. mtdcr EBC0_CFGADDR,r4
  85. addis r4,0,CS1_AP@h
  86. ori r4,r4,CS1_AP@l
  87. mtdcr EBC0_CFGDATA,r4
  88. addi r4,0,PB1CR
  89. mtdcr EBC0_CFGADDR,r4
  90. addis r4,0,CS1_CR@h
  91. ori r4,r4,CS1_CR@l
  92. mtdcr EBC0_CFGDATA,r4
  93. /*----------------------------------------------------------------------- */
  94. /* Memory Bank 2 (A/D converter) initialization */
  95. /*----------------------------------------------------------------------- */
  96. addi r4,0,PB2AP
  97. mtdcr EBC0_CFGADDR,r4
  98. addis r4,0,CS2_AP@h
  99. ori r4,r4,CS2_AP@l
  100. mtdcr EBC0_CFGDATA,r4
  101. addi r4,0,PB2CR
  102. mtdcr EBC0_CFGADDR,r4
  103. addis r4,0,CS2_CR@h
  104. ori r4,r4,CS2_CR@l
  105. mtdcr EBC0_CFGDATA,r4
  106. /*----------------------------------------------------------------------- */
  107. /* Memory Bank 3 (Ethernet PHY Reset) initialization */
  108. /*----------------------------------------------------------------------- */
  109. addi r4,0,PB3AP
  110. mtdcr EBC0_CFGADDR,r4
  111. addis r4,0,CS3_AP@h
  112. ori r4,r4,CS3_AP@l
  113. mtdcr EBC0_CFGDATA,r4
  114. addi r4,0,PB3CR
  115. mtdcr EBC0_CFGADDR,r4
  116. addis r4,0,CS3_CR@h
  117. ori r4,r4,CS3_CR@l
  118. mtdcr EBC0_CFGDATA,r4
  119. /*----------------------------------------------------------------------- */
  120. /* Memory Bank 4 (PC-MIP PRSNT1#) initialization */
  121. /*----------------------------------------------------------------------- */
  122. addi r4,0,PB4AP
  123. mtdcr EBC0_CFGADDR,r4
  124. addis r4,0,CS4_AP@h
  125. ori r4,r4,CS4_AP@l
  126. mtdcr EBC0_CFGDATA,r4
  127. addi r4,0,PB4CR
  128. mtdcr EBC0_CFGADDR,r4
  129. addis r4,0,CS4_CR@h
  130. ori r4,r4,CS4_CR@l
  131. mtdcr EBC0_CFGDATA,r4
  132. /*----------------------------------------------------------------------- */
  133. /* Memory Bank 5 (PC-MIP PRSNT2#) initialization */
  134. /*----------------------------------------------------------------------- */
  135. addi r4,0,PB5AP
  136. mtdcr EBC0_CFGADDR,r4
  137. addis r4,0,CS5_AP@h
  138. ori r4,r4,CS5_AP@l
  139. mtdcr EBC0_CFGDATA,r4
  140. addi r4,0,PB5CR
  141. mtdcr EBC0_CFGADDR,r4
  142. addis r4,0,CS5_CR@h
  143. ori r4,r4,CS5_CR@l
  144. mtdcr EBC0_CFGDATA,r4
  145. /*----------------------------------------------------------------------- */
  146. /* Memory Bank 6 (CPU LED0) initialization */
  147. /*----------------------------------------------------------------------- */
  148. addi r4,0,PB6AP
  149. mtdcr EBC0_CFGADDR,r4
  150. addis r4,0,CS6_AP@h
  151. ori r4,r4,CS6_AP@l
  152. mtdcr EBC0_CFGDATA,r4
  153. addi r4,0,PB6CR
  154. mtdcr EBC0_CFGADDR,r4
  155. addis r4,0,CS6_CR@h
  156. ori r4,r4,CS5_CR@l
  157. mtdcr EBC0_CFGDATA,r4
  158. /*----------------------------------------------------------------------- */
  159. /* Memory Bank 7 (CPU LED1) initialization */
  160. /*----------------------------------------------------------------------- */
  161. addi r4,0,PB7AP
  162. mtdcr EBC0_CFGADDR,r4
  163. addis r4,0,CS7_AP@h
  164. ori r4,r4,CS7_AP@l
  165. mtdcr EBC0_CFGDATA,r4
  166. addi r4,0,PB7CR
  167. mtdcr EBC0_CFGADDR,r4
  168. addis r4,0,CS7_CR@h
  169. ori r4,r4,CS7_CR@l
  170. mtdcr EBC0_CFGDATA,r4
  171. /* addis r4,r0,FPGA_BRDC@h */
  172. /* ori r4,r4,FPGA_BRDC@l */
  173. /* lbz r3,0(r4) /###*get FPGA board control reg */
  174. /* eieio */
  175. /* ori r3,r3,0x01 /###*set UART1 control to select CTS/RTS */
  176. /* stb r3,0(r4) */
  177. nop /* pass2 DCR errata #8 */
  178. blr
  179. /*----------------------------------------------------------------------------- */
  180. /* Function: sdram_init */
  181. /* Description: Configures SDRAM memory banks on ERIC. */
  182. /* We do manually init our SDRAM. */
  183. /* If we have two SDRAM banks, simply undef SINGLE_BANK (ROLF :-) */
  184. /* It is assumed that a 32MB 12x8(2) SDRAM is used. */
  185. /*----------------------------------------------------------------------------- */
  186. .globl sdram_init
  187. sdram_init:
  188. mflr r31
  189. #ifdef CONFIG_SYS_SDRAM_MANUALLY
  190. /*------------------------------------------------------------------- */
  191. /* Set MB0CF for bank 0. (0-32MB) Address Mode 4 since 12x8(2) */
  192. /*------------------------------------------------------------------- */
  193. addi r4,0,SDRAM0_B0CR
  194. mtdcr SDRAM0_CFGADDR,r4
  195. addis r4,0,MB0CF@h
  196. ori r4,r4,MB0CF@l
  197. mtdcr SDRAM0_CFGDATA,r4
  198. /*------------------------------------------------------------------- */
  199. /* Set MB1CF for bank 1. (32MB-64MB) Address Mode 4 since 12x8(2) */
  200. /*------------------------------------------------------------------- */
  201. addi r4,0,SDRAM0_B1CR
  202. mtdcr SDRAM0_CFGADDR,r4
  203. addis r4,0,MB1CF@h
  204. ori r4,r4,MB1CF@l
  205. mtdcr SDRAM0_CFGDATA,r4
  206. /*------------------------------------------------------------------- */
  207. /* Set MB2CF for bank 2. off */
  208. /*------------------------------------------------------------------- */
  209. addi r4,0,SDRAM0_B2CR
  210. mtdcr SDRAM0_CFGADDR,r4
  211. addis r4,0,MB2CF@h
  212. ori r4,r4,MB2CF@l
  213. mtdcr SDRAM0_CFGDATA,r4
  214. /*------------------------------------------------------------------- */
  215. /* Set MB3CF for bank 3. off */
  216. /*------------------------------------------------------------------- */
  217. addi r4,0,SDRAM0_B3CR
  218. mtdcr SDRAM0_CFGADDR,r4
  219. addis r4,0,MB3CF@h
  220. ori r4,r4,MB3CF@l
  221. mtdcr SDRAM0_CFGDATA,r4
  222. /*------------------------------------------------------------------- */
  223. /* Set the SDRAM Timing reg, SDTR1 and the refresh timer reg, RTR. */
  224. /* To set the appropriate timings, we need to know the SDRAM speed. */
  225. /* We can use the PLB speed since the SDRAM speed is the same as */
  226. /* the PLB speed. The PLB speed is the FBK divider times the */
  227. /* 405GP reference clock, which on the Walnut board is 33Mhz. */
  228. /* Thus, if FBK div is 2, SDRAM is 66Mhz; if FBK div is 3, SDRAM is */
  229. /* 100Mhz; if FBK is 3, SDRAM is 133Mhz. */
  230. /* NOTE: The Walnut board supports SDRAM speeds of 66Mhz, 100Mhz, and */
  231. /* maybe 133Mhz. */
  232. /*------------------------------------------------------------------- */
  233. mfdcr r5,CPC0_PSR /* determine FBK divider */
  234. /* via STRAP reg to calc PLB speed. */
  235. /* SDRAM speed is the same as the PLB */
  236. /* speed. */
  237. rlwinm r4,r5,4,0x3 /* get FBK divide bits */
  238. ..chk_66:
  239. cmpi %cr0,0,r4,0x1
  240. bne ..chk_100
  241. addis r6,0,SDTR_66@h /* SDTR1 value for 66Mhz */
  242. ori r6,r6,SDTR_66@l
  243. addis r7,0,RTR_66 /* RTR value for 66Mhz */
  244. b ..sdram_ok
  245. ..chk_100:
  246. cmpi %cr0,0,r4,0x2
  247. bne ..chk_133
  248. addis r6,0,SDTR_100@h /* SDTR1 value for 100Mhz */
  249. ori r6,r6,SDTR_100@l
  250. addis r7,0,RTR_100 /* RTR value for 100Mhz */
  251. b ..sdram_ok
  252. ..chk_133:
  253. addis r6,0,0x0107 /* SDTR1 value for 133Mhz */
  254. ori r6,r6,0x4015
  255. addis r7,0,0x07F0 /* RTR value for 133Mhz */
  256. ..sdram_ok:
  257. /*------------------------------------------------------------------- */
  258. /* Set SDTR1 */
  259. /*------------------------------------------------------------------- */
  260. addi r4,0,SDRAM0_TR
  261. mtdcr SDRAM0_CFGADDR,r4
  262. mtdcr SDRAM0_CFGDATA,r6
  263. /*------------------------------------------------------------------- */
  264. /* Set RTR */
  265. /*------------------------------------------------------------------- */
  266. addi r4,0,SDRAM0_RTR
  267. mtdcr SDRAM0_CFGADDR,r4
  268. mtdcr SDRAM0_CFGDATA,r7
  269. /*------------------------------------------------------------------- */
  270. /* Delay to ensure 200usec have elapsed since reset. Assume worst */
  271. /* case that the core is running 200Mhz: */
  272. /* 200,000,000 (cycles/sec) X .000200 (sec) = 0x9C40 cycles */
  273. /*------------------------------------------------------------------- */
  274. addis r3,0,0x0000
  275. ori r3,r3,0xA000 /* ensure 200usec have passed since reset */
  276. mtctr r3
  277. ..spinlp2:
  278. bdnz ..spinlp2 /* spin loop */
  279. /*------------------------------------------------------------------- */
  280. /* Set memory controller options reg, MCOPT1. */
  281. /* Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst */
  282. /* read/prefetch. */
  283. /*------------------------------------------------------------------- */
  284. addi r4,0,SDRAM0_CFG
  285. mtdcr SDRAM0_CFGADDR,r4
  286. addis r4,0,0x8080 /* set DC_EN=1 */
  287. ori r4,r4,0x0000
  288. mtdcr SDRAM0_CFGDATA,r4
  289. /*------------------------------------------------------------------- */
  290. /* Delay to ensure 10msec have elapsed since reset. This is */
  291. /* required for the MPC952 to stabalize. Assume worst */
  292. /* case that the core is running 200Mhz: */
  293. /* 200,000,000 (cycles/sec) X .010 (sec) = 0x1E8480 cycles */
  294. /* This delay should occur before accessing SDRAM. */
  295. /*------------------------------------------------------------------- */
  296. addis r3,0,0x001E
  297. ori r3,r3,0x8480 /* ensure 10msec have passed since reset */
  298. mtctr r3
  299. ..spinlp3:
  300. bdnz ..spinlp3 /* spin loop */
  301. #else
  302. /*fixme: do SDRAM Autoconfig from EEPROM here */
  303. #endif
  304. mtlr r31 /* restore lr */
  305. blr