init.S 6.1 KB

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