memsetup.S 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * Memory sub-system initialization code for INCA-IP development board.
  3. *
  4. * Copyright (c) 2003 Wolfgang Denk <wd@denx.de>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <config.h>
  25. #include <version.h>
  26. #include <asm/regdef.h>
  27. #define EBU_MODUL_BASE 0xB8000200
  28. #define EBU_CLC(value) 0x0000(value)
  29. #define EBU_CON(value) 0x0010(value)
  30. #define EBU_ADDSEL0(value) 0x0020(value)
  31. #define EBU_ADDSEL1(value) 0x0024(value)
  32. #define EBU_ADDSEL2(value) 0x0028(value)
  33. #define EBU_BUSCON0(value) 0x0060(value)
  34. #define EBU_BUSCON1(value) 0x0064(value)
  35. #define EBU_BUSCON2(value) 0x0068(value)
  36. #define MC_MODUL_BASE 0xBF800000
  37. #define MC_ERRCAUSE(value) 0x0100(value)
  38. #define MC_ERRADDR(value) 0x0108(value)
  39. #define MC_IOGP(value) 0x0800(value)
  40. #define MC_SELFRFSH(value) 0x0A00(value)
  41. #define MC_CTRLENA(value) 0x1000(value)
  42. #define MC_MRSCODE(value) 0x1008(value)
  43. #define MC_CFGDW(value) 0x1010(value)
  44. #define MC_CFGPB0(value) 0x1018(value)
  45. #define MC_LATENCY(value) 0x1038(value)
  46. #define MC_TREFRESH(value) 0x1040(value)
  47. #define CGU_MODUL_BASE 0xBF107000
  48. #define CGU_PLL1CR(value) 0x0008(value)
  49. #define CGU_DIVCR(value) 0x0010(value)
  50. #define CGU_MUXCR(value) 0x0014(value)
  51. #define CGU_PLL1SR(value) 0x000C(value)
  52. .set noreorder
  53. /*
  54. * void ebu_init(long)
  55. *
  56. * a0 has the clock value we are going to run at
  57. */
  58. .globl ebu_init
  59. .ent ebu_init
  60. ebu_init:
  61. li t1, EBU_MODUL_BASE
  62. li t2, 0xA0000041
  63. sw t2, EBU_ADDSEL0(t1)
  64. li t2, 0xA0800041
  65. sw t2, EBU_ADDSEL2(t1)
  66. li t2, 0xBE0000F1
  67. sw t2, EBU_ADDSEL1(t1)
  68. li t3, 100000000
  69. beq a0, t3, 1f
  70. nop
  71. li t3, 133000000
  72. beq a0, t3, 2f
  73. nop
  74. li t3, 150000000
  75. beq a0, t3, 2f
  76. nop
  77. b 3f
  78. nop
  79. /* 100 MHz */
  80. 1:
  81. li t2, 0x8841417D
  82. sw t2, EBU_BUSCON0(t1)
  83. sw t2, EBU_BUSCON2(t1)
  84. li t2, 0x684142BD
  85. b 3f
  86. sw t2, EBU_BUSCON1(t1) /* delay slot */
  87. /* 133 or 150 MHz */
  88. 2:
  89. li t2, 0x8841417E
  90. sw t2, EBU_BUSCON0(t1)
  91. sw t2, EBU_BUSCON2(t1)
  92. li t2, 0x684143FD
  93. sw t2, EBU_BUSCON1(t1)
  94. 3:
  95. j ra
  96. nop
  97. .end ebu_init
  98. /*
  99. * void cgu_init(long)
  100. *
  101. * a0 has the clock value
  102. */
  103. .globl cgu_init
  104. .ent cgu_init
  105. cgu_init:
  106. li t1, CGU_MODUL_BASE
  107. li t3, 100000000
  108. beq a0, t3, 1f
  109. nop
  110. li t3, 133000000
  111. beq a0, t3, 2f
  112. nop
  113. li t3, 150000000
  114. beq a0, t3, 3f
  115. nop
  116. b 5f
  117. nop
  118. /* 100 MHz clock */
  119. 1:
  120. li t2, 0x80000014
  121. sw t2, CGU_DIVCR(t1)
  122. li t2, 0x80000000
  123. sw t2, CGU_MUXCR(t1)
  124. li t2, 0x800B0001
  125. b 5f
  126. sw t2, CGU_PLL1CR(t1) /* delay slot */
  127. /* 133 MHz clock */
  128. 2:
  129. li t2, 0x80000054
  130. sw t2, CGU_DIVCR(t1)
  131. li t2, 0x80000000
  132. sw t2, CGU_MUXCR(t1)
  133. li t2, 0x800B0001
  134. b 5f
  135. sw t2, CGU_PLL1CR(t1) /* delay slot */
  136. /* 150 MHz clock */
  137. 3:
  138. li t2, 0x80000017
  139. sw t2, CGU_DIVCR(t1)
  140. li t2, 0xC00B0001
  141. sw t2, CGU_PLL1CR(t1)
  142. li t3, 0x80000000
  143. 4:
  144. lw t2, CGU_PLL1SR(t1)
  145. and t2, t2, t3
  146. beq t2, zero, 4b
  147. nop
  148. li t2, 0x80000001
  149. sw t2, CGU_MUXCR(t1)
  150. 5:
  151. j ra
  152. nop
  153. .end cgu_init
  154. .globl memsetup
  155. .ent memsetup
  156. memsetup:
  157. /* EBU and CGU Initialization.
  158. */
  159. li a0, CPU_CLOCK_RATE
  160. move t0, ra
  161. /* We rely on the fact that neither ebu_init() nor cgu_init()
  162. * modify t0 and a0.
  163. */
  164. bal ebu_init
  165. nop
  166. bal cgu_init
  167. nop
  168. move ra, t0
  169. /* SDRAM Initialization.
  170. */
  171. li t0, MC_MODUL_BASE
  172. /* Clear Error log registers */
  173. sw zero, MC_ERRCAUSE(t0)
  174. sw zero, MC_ERRADDR(t0)
  175. /* Set clock ratio to 1:1 */
  176. li t1, 0x03 /* clkrat=1:1, rddel=3 */
  177. sw t1, MC_IOGP(t0)
  178. /* Clear Power-down registers */
  179. sw zero, MC_SELFRFSH(t0)
  180. /* Set CAS Latency */
  181. li t1, 0x00000020 /* CL = 2 */
  182. sw t1, MC_MRSCODE(t0)
  183. /* Set word width to 16 bit */
  184. li t1, 0x2
  185. sw t1, MC_CFGDW(t0)
  186. /* Set CS0 to SDRAM parameters */
  187. li t1, 0x000014C9
  188. sw t1, MC_CFGPB0(t0)
  189. /* Set SDRAM latency parameters */
  190. li t1, 0x00026325 /* BC PC100 */
  191. sw t1, MC_LATENCY(t0)
  192. /* Set SDRAM refresh rate */
  193. li t1, 0x00000C30 /* 4K/64ms @ 100MHz */
  194. sw t1, MC_TREFRESH(t0)
  195. /* Finally enable the controller */
  196. li t1, 1
  197. sw t1, MC_CTRLENA(t0)
  198. j ra
  199. nop
  200. .end memsetup