memsetup.S 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. /*
  155. * void sdram_init(long)
  156. *
  157. * a0 has the clock value
  158. */
  159. .globl sdram_init
  160. .ent sdram_init
  161. sdram_init:
  162. li t1, MC_MODUL_BASE
  163. #if 0
  164. /* Disable memory controller before changing any of its registers */
  165. sw zero, MC_CTRLENA(t1)
  166. #endif
  167. li t2, 100000000
  168. beq a0, t2, 1f
  169. nop
  170. li t2, 133000000
  171. beq a0, t2, 2f
  172. nop
  173. li t2, 150000000
  174. beq a0, t2, 3f
  175. nop
  176. b 5f
  177. nop
  178. /* 100 MHz clock */
  179. 1:
  180. /* Set clock ratio (clkrat=1:1, rddel=3) */
  181. li t2, 0x00000003
  182. sw t2, MC_IOGP(t1)
  183. /* Set sdram refresh rate (4K/64ms @ 100MHz) */
  184. li t2, 0x0000061A
  185. b 4f
  186. sw t2, MC_TREFRESH(t1)
  187. /* 133 MHz clock */
  188. 2:
  189. /* Set clock ratio (clkrat=1:1, rddel=3) */
  190. li t2, 0x00000003
  191. sw t2, MC_IOGP(t1)
  192. /* Set sdram refresh rate (4K/64ms @ 133MHz) */
  193. li t2, 0x00000822
  194. b 4f
  195. sw t2, MC_TREFRESH(t1)
  196. /* 150 MHz clock */
  197. 3:
  198. /* Set clock ratio (clkrat=3:2, rddel=4) */
  199. li t2, 0x00000014
  200. sw t2, MC_IOGP(t1)
  201. /* Set sdram refresh rate (4K/64ms @ 150MHz) */
  202. li t2, 0x00000927
  203. sw t2, MC_TREFRESH(t1)
  204. 4:
  205. /* Clear Error log registers */
  206. sw zero, MC_ERRCAUSE(t1)
  207. sw zero, MC_ERRADDR(t1)
  208. /* Clear Power-down registers */
  209. sw zero, MC_SELFRFSH(t1)
  210. /* Set CAS Latency */
  211. li t2, 0x00000020 /* CL = 2 */
  212. sw t2, MC_MRSCODE(t1)
  213. /* Set word width to 16 bit */
  214. li t2, 0x2
  215. sw t2, MC_CFGDW(t1)
  216. /* Set CS0 to SDRAM parameters */
  217. li t2, 0x000014C9
  218. sw t2, MC_CFGPB0(t1)
  219. /* Set SDRAM latency parameters */
  220. li t2, 0x00026325 /* BC PC100 */
  221. sw t2, MC_LATENCY(t1)
  222. 5:
  223. /* Finally enable the controller */
  224. li t2, 0x00000001
  225. sw t2, MC_CTRLENA(t1)
  226. j ra
  227. nop
  228. .end sdram_init
  229. .globl memsetup
  230. .ent memsetup
  231. memsetup:
  232. /* EBU, CGU and SDRAM Initialization.
  233. */
  234. li a0, CPU_CLOCK_RATE
  235. move t0, ra
  236. /* We rely on the fact that neither ebu_init() nor cgu_init() nor sdram_init()
  237. * modify t0 and a0.
  238. */
  239. bal cgu_init
  240. nop
  241. bal ebu_init
  242. nop
  243. bal sdram_init
  244. nop
  245. move ra, t0
  246. j ra
  247. nop
  248. .end memsetup