init.S 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. #include <config.h>
  23. #include <ppc4xx.h>
  24. #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
  25. #include <ppc_asm.tmpl>
  26. #include <ppc_defs.h>
  27. #include <asm/cache.h>
  28. #include <asm/mmu.h>
  29. /******************************************************************************
  30. * Function: ext_bus_cntlr_init
  31. *
  32. * Description: Configures EBC Controller and a few basic chip selects.
  33. *
  34. * CS0 is setup to get the Boot Flash out of the addresss range
  35. * so that we may setup a stack. CS7 is setup so that we can
  36. * access and reset the hardware watchdog.
  37. *
  38. * IMPORTANT: For pass1 this code must run from
  39. * cache since you can not reliably change a peripheral banks
  40. * timing register (pbxap) while running code from that bank.
  41. * For ex., since we are running from ROM on bank 0, we can NOT
  42. * execute the code that modifies bank 0 timings from ROM, so
  43. * we run it from cache.
  44. *
  45. * Notes: Does NOT use the stack.
  46. *****************************************************************************/
  47. .section ".text"
  48. .align 2
  49. .globl ext_bus_cntlr_init
  50. .type ext_bus_cntlr_init, @function
  51. ext_bus_cntlr_init:
  52. mflr r0
  53. /********************************************************************
  54. * Prefetch entire ext_bus_cntrl_init function into the icache.
  55. * This is necessary because we are going to change the same CS we
  56. * are executing from. Otherwise a CPU lockup may occur.
  57. *******************************************************************/
  58. bl ..getAddr
  59. ..getAddr:
  60. mflr r3 /* get address of ..getAddr */
  61. /* Calculate number of cache lines for this function */
  62. addi r4, 0, (((.Lfe0 - ..getAddr) / CONFIG_SYS_CACHELINE_SIZE) + 2)
  63. mtctr r4
  64. ..ebcloop:
  65. icbt r0, r3 /* prefetch cache line for addr in r3*/
  66. addi r3, r3, CONFIG_SYS_CACHELINE_SIZE /* move to next cache line */
  67. bdnz ..ebcloop /* continue for $CTR cache lines */
  68. /********************************************************************
  69. * Delay to ensure all accesses to ROM are complete before changing
  70. * bank 0 timings. 200usec should be enough.
  71. * 200,000,000 (cycles/sec) X .000200 (sec) = 0x9C40 cycles.
  72. *******************************************************************/
  73. addis r3, 0, 0x0
  74. ori r3, r3, 0xA000 /* wait 200us from reset */
  75. mtctr r3
  76. ..spinlp:
  77. bdnz ..spinlp /* spin loop */
  78. /********************************************************************
  79. * Setup External Bus Controller (EBC).
  80. *******************************************************************/
  81. addi r3, 0, epcr
  82. mtdcr ebccfga, r3
  83. addis r4, 0, 0xb040 /* Device base timeout = 1024 cycles */
  84. ori r4, r4, 0x0 /* Drive CS with external master */
  85. mtdcr ebccfgd, r4
  86. /********************************************************************
  87. * Change PCIINT signal to PerWE
  88. *******************************************************************/
  89. mfdcr r4, cntrl1
  90. ori r4, r4, 0x4000
  91. mtdcr cntrl1, r4
  92. /********************************************************************
  93. * Memory Bank 0 (Flash Bank 0) initialization
  94. *******************************************************************/
  95. addi r3, 0, pb0ap
  96. mtdcr ebccfga, r3
  97. addis r4, 0, CONFIG_SYS_W7O_EBC_PB0AP@h
  98. ori r4, r4, CONFIG_SYS_W7O_EBC_PB0AP@l
  99. mtdcr ebccfgd, r4
  100. addi r3, 0, pb0cr
  101. mtdcr ebccfga, r3
  102. addis r4, 0, CONFIG_SYS_W7O_EBC_PB0CR@h
  103. ori r4, r4, CONFIG_SYS_W7O_EBC_PB0CR@l
  104. mtdcr ebccfgd, r4
  105. /********************************************************************
  106. * Memory Bank 7 LEDs - NEEDED BECAUSE OF HW WATCHDOG AND LEDs.
  107. *******************************************************************/
  108. addi r3, 0, pb7ap
  109. mtdcr ebccfga, r3
  110. addis r4, 0, CONFIG_SYS_W7O_EBC_PB7AP@h
  111. ori r4, r4, CONFIG_SYS_W7O_EBC_PB7AP@l
  112. mtdcr ebccfgd, r4
  113. addi r3, 0, pb7cr
  114. mtdcr ebccfga, r3
  115. addis r4, 0, CONFIG_SYS_W7O_EBC_PB7CR@h
  116. ori r4, r4, CONFIG_SYS_W7O_EBC_PB7CR@l
  117. mtdcr ebccfgd, r4
  118. /* We are all done */
  119. mtlr r0 /* Restore link register */
  120. blr /* Return to calling function */
  121. .Lfe0: .size ext_bus_cntlr_init,.Lfe0-ext_bus_cntlr_init
  122. /* end ext_bus_cntlr_init() */
  123. /******************************************************************************
  124. * Function: sdram_init
  125. *
  126. * Description: Configures SDRAM memory banks.
  127. *
  128. * Serial Presence Detect, "SPD," reads the SDRAM EEPROM
  129. * via the IIC bus and then configures the SDRAM memory
  130. * banks appropriately. If Auto Memory Configuration is
  131. * is not used, it is assumed that a 4MB 11x8x2, non-ECC,
  132. * SDRAM is soldered down.
  133. *
  134. * Notes: Expects that the stack is already setup.
  135. *****************************************************************************/
  136. .section ".text"
  137. .align 2
  138. .globl sdram_init
  139. .type sdram_init, @function
  140. sdram_init:
  141. /* save the return info on stack */
  142. mflr r0 /* Get link register */
  143. stwu r1, -8(r1) /* Save back chain and move SP */
  144. stw r0, +12(r1) /* Save link register */
  145. /*
  146. * First call spd_sdram to try to init SDRAM according to the
  147. * contents of the SPD EEPROM. If the SPD EEPROM is blank or
  148. * erronious, spd_sdram returns 0 in R3.
  149. */
  150. li r3,0
  151. bl spd_sdram
  152. addic. r3, r3, 0 /* Check for error, save dram size */
  153. bne ..sdri_done /* If it worked, we're done... */
  154. /********************************************************************
  155. * If SPD detection fails, we'll default to 4MB, 11x8x2, as this
  156. * is the SMALLEST SDRAM size the 405 supports. We can do this
  157. * because W7O boards have soldered on RAM, and there will always
  158. * be some amount present. If we were using DIMMs, we should hang
  159. * the board instead, since it doesn't have any RAM to continue
  160. * running with.
  161. *******************************************************************/
  162. /*
  163. * Disable memory controller to allow
  164. * values to be changed.
  165. */
  166. addi r3, 0, mem_mcopt1
  167. mtdcr memcfga, r3
  168. addis r4, 0, 0x0
  169. ori r4, r4, 0x0
  170. mtdcr memcfgd, r4
  171. /*
  172. * Set MB0CF for ext bank 0. (0-4MB) Address Mode 5 since 11x8x2
  173. * All other banks are disabled.
  174. */
  175. addi r3, 0, mem_mb0cf
  176. mtdcr memcfga, r3
  177. addis r4, 0, 0x0000 /* BA=0x0, SZ=4MB */
  178. ori r4, r4, 0x8001 /* Mode is 5, 11x8x2or4, BE=Enabled */
  179. mtdcr memcfgd, r4
  180. /* Clear MB1CR,MB2CR,MB3CR to turn other banks off */
  181. addi r4, 0, 0 /* Zero the data reg */
  182. addi r3, r3, 4 /* Point to MB1CF reg */
  183. mtdcr memcfga, r3 /* Set the address */
  184. mtdcr memcfgd, r4 /* Zero the reg */
  185. addi r3, r3, 4 /* Point to MB2CF reg */
  186. mtdcr memcfga, r3 /* Set the address */
  187. mtdcr memcfgd, r4 /* Zero the reg */
  188. addi r3, r3, 4 /* Point to MB3CF reg */
  189. mtdcr memcfga, r3 /* Set the address */
  190. mtdcr memcfgd, r4 /* Zero the reg */
  191. /********************************************************************
  192. * Set the SDRAM Timing reg, SDTR1 and the refresh timer reg, RTR.
  193. * To set the appropriate timings, we assume sdram is
  194. * 100MHz (pc100 compliant).
  195. *******************************************************************/
  196. /*
  197. * Set up SDTR1
  198. */
  199. addi r3, 0, mem_sdtr1
  200. mtdcr memcfga, r3
  201. addis r4, 0, 0x0086 /* SDTR1 value for 100Mhz */
  202. ori r4, r4, 0x400D
  203. mtdcr memcfgd, r4
  204. /*
  205. * Set RTR
  206. */
  207. addi r3, 0, mem_rtr
  208. mtdcr memcfga, r3
  209. addis r4, 0, 0x05F0 /* RTR refresh val = 15.625ms@100Mhz */
  210. mtdcr memcfgd, r4
  211. /********************************************************************
  212. * Delay to ensure 200usec have elapsed since reset. Assume worst
  213. * case that the core is running 200Mhz:
  214. * 200,000,000 (cycles/sec) X .000200 (sec) = 0x9C40 cycles
  215. *******************************************************************/
  216. addis r3, 0, 0x0000
  217. ori r3, r3, 0xA000 /* Wait 200us from reset */
  218. mtctr r3
  219. ..spinlp2:
  220. bdnz ..spinlp2 /* spin loop */
  221. /********************************************************************
  222. * Set memory controller options reg, MCOPT1.
  223. *******************************************************************/
  224. addi r3, 0, mem_mcopt1
  225. mtdcr memcfga, r3
  226. addis r4, 0, 0x80E0 /* DC_EN=1,SRE=0,PME=0,MEMCHK=0 */
  227. ori r4, r4, 0x0000 /* REGEN=0,DRW=00,BRPF=01,ECCDD=1 */
  228. mtdcr memcfgd, r4 /* EMDULR=1 */
  229. ..sdri_done:
  230. /* restore and return */
  231. lwz r0, +12(r1) /* Get saved link register */
  232. addi r1, r1, +8 /* Remove frame from stack */
  233. mtlr r0 /* Restore link register */
  234. blr /* Return to calling function */
  235. .Lfe1: .size sdram_init,.Lfe1-sdram_init
  236. /* end sdram_init() */