init.S 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. #define LI32(reg,val) \
  32. addis reg,0,val@h;\
  33. ori reg,reg,val@l
  34. #define WDCR_EBC(reg,val) \
  35. addi r4,0,reg;\
  36. mtdcr EBC0_CFGADDR,r4;\
  37. addis r4,0,val@h;\
  38. ori r4,r4,val@l;\
  39. mtdcr EBC0_CFGDATA,r4
  40. #define WDCR_SDRAM(reg,val) \
  41. addi r4,0,reg;\
  42. mtdcr SDRAM0_CFGADDR,r4;\
  43. addis r4,0,val@h;\
  44. ori r4,r4,val@l;\
  45. mtdcr SDRAM0_CFGDATA,r4
  46. /******************************************************************************
  47. * Function: ext_bus_cntlr_init
  48. *
  49. * Description: Configures EBC Controller and a few basic chip selects.
  50. *
  51. * CS0 is setup to get the Boot Flash out of the addresss range
  52. * so that we may setup a stack. CS7 is setup so that we can
  53. * access and reset the hardware watchdog.
  54. *
  55. * IMPORTANT: For pass1 this code must run from
  56. * cache since you can not reliably change a peripheral banks
  57. * timing register (pbxap) while running code from that bank.
  58. * For ex., since we are running from ROM on bank 0, we can NOT
  59. * execute the code that modifies bank 0 timings from ROM, so
  60. * we run it from cache.
  61. *
  62. * Notes: Does NOT use the stack.
  63. *****************************************************************************/
  64. .section ".text"
  65. .align 2
  66. .globl ext_bus_cntlr_init
  67. .type ext_bus_cntlr_init, @function
  68. ext_bus_cntlr_init:
  69. mflr r0
  70. /********************************************************************
  71. * Prefetch entire ext_bus_cntrl_init function into the icache.
  72. * This is necessary because we are going to change the same CS we
  73. * are executing from. Otherwise a CPU lockup may occur.
  74. *******************************************************************/
  75. bl ..getAddr
  76. ..getAddr:
  77. mflr r3 /* get address of ..getAddr */
  78. /* Calculate number of cache lines for this function */
  79. addi r4, 0, (((.Lfe0 - ..getAddr) / CONFIG_SYS_CACHELINE_SIZE) + 2)
  80. mtctr r4
  81. ..ebcloop:
  82. icbt r0, r3 /* prefetch cache line for addr in r3*/
  83. addi r3, r3, CONFIG_SYS_CACHELINE_SIZE /* move to next cache line */
  84. bdnz ..ebcloop /* continue for $CTR cache lines */
  85. /********************************************************************
  86. * Delay to ensure all accesses to ROM are complete before changing
  87. * bank 0 timings. 200usec should be enough.
  88. * 200,000,000 (cycles/sec) X .000200 (sec) = 0x9C40 cycles.
  89. *******************************************************************/
  90. addis r3, 0, 0x0
  91. ori r3, r3, 0xA000 /* wait 200us from reset */
  92. mtctr r3
  93. ..spinlp:
  94. bdnz ..spinlp /* spin loop */
  95. /********************************************************************
  96. * SETUP CPC0_CR0
  97. *******************************************************************/
  98. LI32(r4, 0x007000c0)
  99. mtdcr CPC0_CR0, r4
  100. /********************************************************************
  101. * Setup CPC0_CR1: Change PCIINT signal to PerWE
  102. *******************************************************************/
  103. mfdcr r4, CPC0_CR1
  104. ori r4, r4, 0x4000
  105. mtdcr CPC0_CR1, r4
  106. /********************************************************************
  107. * Setup External Bus Controller (EBC).
  108. *******************************************************************/
  109. WDCR_EBC(EBC0_CFG, 0xd84c0000)
  110. /********************************************************************
  111. * Memory Bank 0 (Intel 28F128J3 Flash) initialization
  112. *******************************************************************/
  113. /*WDCR_EBC(PB1AP, 0x02869200)*/
  114. WDCR_EBC(PB1AP, 0x07869200)
  115. WDCR_EBC(PB0CR, 0xfe0bc000)
  116. /********************************************************************
  117. * Memory Bank 1 (Holtek HT6542B PS/2) initialization
  118. *******************************************************************/
  119. WDCR_EBC(PB1AP, 0x1f869200)
  120. WDCR_EBC(PB1CR, 0xf0818000)
  121. /********************************************************************
  122. * Memory Bank 2 (Epson S1D13506) initialization
  123. *******************************************************************/
  124. WDCR_EBC(PB2AP, 0x05860300)
  125. WDCR_EBC(PB2CR, 0xf045a000)
  126. /********************************************************************
  127. * Memory Bank 3 (Philips SJA1000 CAN Controllers) initialization
  128. *******************************************************************/
  129. WDCR_EBC(PB3AP, 0x0387d200)
  130. WDCR_EBC(PB3CR, 0xf021c000)
  131. /********************************************************************
  132. * Memory Bank 4-7 (Unused) initialization
  133. *******************************************************************/
  134. WDCR_EBC(PB4AP, 0)
  135. WDCR_EBC(PB4CR, 0)
  136. WDCR_EBC(PB5AP, 0)
  137. WDCR_EBC(PB5CR, 0)
  138. WDCR_EBC(PB6AP, 0)
  139. WDCR_EBC(PB6CR, 0)
  140. WDCR_EBC(PB7AP, 0)
  141. WDCR_EBC(PB7CR, 0)
  142. /* We are all done */
  143. mtlr r0 /* Restore link register */
  144. blr /* Return to calling function */
  145. .Lfe0: .size ext_bus_cntlr_init,.Lfe0-ext_bus_cntlr_init
  146. /* end ext_bus_cntlr_init() */
  147. /******************************************************************************
  148. * Function: sdram_init
  149. *
  150. * Description: Configures SDRAM memory banks.
  151. *
  152. * Notes: Does NOT use the stack.
  153. *****************************************************************************/
  154. .section ".text"
  155. .align 2
  156. .globl sdram_init
  157. .type sdram_init, @function
  158. sdram_init:
  159. /*
  160. * Disable memory controller to allow
  161. * values to be changed.
  162. */
  163. WDCR_SDRAM(SDRAM0_CFG, 0x00000000)
  164. /*
  165. * Configure Memory Banks
  166. */
  167. WDCR_SDRAM(SDRAM0_B0CR, 0x00084001)
  168. WDCR_SDRAM(SDRAM0_B1CR, 0x00000000)
  169. WDCR_SDRAM(SDRAM0_B2CR, 0x00000000)
  170. WDCR_SDRAM(SDRAM0_B3CR, 0x00000000)
  171. /*
  172. * Set up SDTR1 (SDRAM Timing Register)
  173. */
  174. WDCR_SDRAM(SDRAM0_TR, 0x00854009)
  175. /*
  176. * Set RTR (Refresh Timing Register)
  177. */
  178. WDCR_SDRAM(SDRAM0_RTR, 0x10000000)
  179. /* WDCR_SDRAM(SDRAM0_RTR, 0x05f00000) */
  180. /********************************************************************
  181. * Delay to ensure 200usec have elapsed since reset. Assume worst
  182. * case that the core is running 200Mhz:
  183. * 200,000,000 (cycles/sec) X .000200 (sec) = 0x9C40 cycles
  184. *******************************************************************/
  185. addis r3, 0, 0x0000
  186. ori r3, r3, 0xA000 /* Wait >200us from reset */
  187. mtctr r3
  188. ..spinlp2:
  189. bdnz ..spinlp2 /* spin loop */
  190. /********************************************************************
  191. * Set memory controller options reg, MCOPT1.
  192. *******************************************************************/
  193. WDCR_SDRAM(SDRAM0_CFG,0x80800000)
  194. ..sdri_done:
  195. blr /* Return to calling function */
  196. .Lfe1: .size sdram_init,.Lfe1-sdram_init
  197. /* end sdram_init() */