init.S 9.5 KB

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