init.S 12 KB

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