lowlevel_init.S 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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 <asm/regdef.h>
  26. #define EBU_MODUL_BASE 0xB8000200
  27. #define EBU_CLC(value) 0x0000(value)
  28. #define EBU_CON(value) 0x0010(value)
  29. #define EBU_ADDSEL0(value) 0x0020(value)
  30. #define EBU_ADDSEL1(value) 0x0024(value)
  31. #define EBU_ADDSEL2(value) 0x0028(value)
  32. #define EBU_BUSCON0(value) 0x0060(value)
  33. #define EBU_BUSCON1(value) 0x0064(value)
  34. #define EBU_BUSCON2(value) 0x0068(value)
  35. #define MC_MODUL_BASE 0xBF800000
  36. #define MC_ERRCAUSE(value) 0x0100(value)
  37. #define MC_ERRADDR(value) 0x0108(value)
  38. #define MC_IOGP(value) 0x0800(value)
  39. #define MC_SELFRFSH(value) 0x0A00(value)
  40. #define MC_CTRLENA(value) 0x1000(value)
  41. #define MC_MRSCODE(value) 0x1008(value)
  42. #define MC_CFGDW(value) 0x1010(value)
  43. #define MC_CFGPB0(value) 0x1018(value)
  44. #define MC_LATENCY(value) 0x1038(value)
  45. #define MC_TREFRESH(value) 0x1040(value)
  46. #define CGU_MODUL_BASE 0xBF107000
  47. #define CGU_PLL1CR(value) 0x0008(value)
  48. #define CGU_DIVCR(value) 0x0010(value)
  49. #define CGU_MUXCR(value) 0x0014(value)
  50. #define CGU_PLL1SR(value) 0x000C(value)
  51. .set noreorder
  52. /*
  53. * void ebu_init(long)
  54. *
  55. * a0 has the clock value we are going to run at
  56. */
  57. .globl ebu_init
  58. .ent ebu_init
  59. 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. jr 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. __cgu_init:
  107. li t1, CGU_MODUL_BASE
  108. li t3, 100000000
  109. beq a0, t3, 1f
  110. nop
  111. li t3, 133000000
  112. beq a0, t3, 2f
  113. nop
  114. li t3, 150000000
  115. beq a0, t3, 3f
  116. nop
  117. b 5f
  118. nop
  119. /* 100 MHz clock */
  120. 1:
  121. li t2, 0x80000014
  122. sw t2, CGU_DIVCR(t1)
  123. li t2, 0x80000000
  124. sw t2, CGU_MUXCR(t1)
  125. li t2, 0x800B0001
  126. b 5f
  127. sw t2, CGU_PLL1CR(t1) /* delay slot */
  128. /* 133 MHz clock */
  129. 2:
  130. li t2, 0x80000054
  131. sw t2, CGU_DIVCR(t1)
  132. li t2, 0x80000000
  133. sw t2, CGU_MUXCR(t1)
  134. li t2, 0x800B0001
  135. b 5f
  136. sw t2, CGU_PLL1CR(t1) /* delay slot */
  137. /* 150 MHz clock */
  138. 3:
  139. li t2, 0x80000017
  140. sw t2, CGU_DIVCR(t1)
  141. li t2, 0xC00B0001
  142. sw t2, CGU_PLL1CR(t1)
  143. li t3, 0x80000000
  144. 4:
  145. lw t2, CGU_PLL1SR(t1)
  146. and t2, t2, t3
  147. beq t2, zero, 4b
  148. nop
  149. li t2, 0x80000001
  150. sw t2, CGU_MUXCR(t1)
  151. 5:
  152. jr ra
  153. nop
  154. .end cgu_init
  155. /*
  156. * void sdram_init(long)
  157. *
  158. * a0 has the clock value
  159. */
  160. .globl sdram_init
  161. .ent sdram_init
  162. sdram_init:
  163. __sdram_init:
  164. li t1, MC_MODUL_BASE
  165. #if 0
  166. /* Disable memory controller before changing any of its registers */
  167. sw zero, MC_CTRLENA(t1)
  168. #endif
  169. li t2, 100000000
  170. beq a0, t2, 1f
  171. nop
  172. li t2, 133000000
  173. beq a0, t2, 2f
  174. nop
  175. li t2, 150000000
  176. beq a0, t2, 3f
  177. nop
  178. b 5f
  179. nop
  180. /* 100 MHz clock */
  181. 1:
  182. /* Set clock ratio (clkrat=1:1, rddel=3) */
  183. li t2, 0x00000003
  184. sw t2, MC_IOGP(t1)
  185. /* Set sdram refresh rate (4K/64ms @ 100MHz) */
  186. li t2, 0x0000061A
  187. b 4f
  188. sw t2, MC_TREFRESH(t1)
  189. /* 133 MHz clock */
  190. 2:
  191. /* Set clock ratio (clkrat=1:1, rddel=3) */
  192. li t2, 0x00000003
  193. sw t2, MC_IOGP(t1)
  194. /* Set sdram refresh rate (4K/64ms @ 133MHz) */
  195. li t2, 0x00000822
  196. b 4f
  197. sw t2, MC_TREFRESH(t1)
  198. /* 150 MHz clock */
  199. 3:
  200. /* Set clock ratio (clkrat=3:2, rddel=4) */
  201. li t2, 0x00000014
  202. sw t2, MC_IOGP(t1)
  203. /* Set sdram refresh rate (4K/64ms @ 150MHz) */
  204. li t2, 0x00000927
  205. sw t2, MC_TREFRESH(t1)
  206. 4:
  207. /* Clear Error log registers */
  208. sw zero, MC_ERRCAUSE(t1)
  209. sw zero, MC_ERRADDR(t1)
  210. /* Clear Power-down registers */
  211. sw zero, MC_SELFRFSH(t1)
  212. /* Set CAS Latency */
  213. li t2, 0x00000020 /* CL = 2 */
  214. sw t2, MC_MRSCODE(t1)
  215. /* Set word width to 16 bit */
  216. li t2, 0x2
  217. sw t2, MC_CFGDW(t1)
  218. /* Set CS0 to SDRAM parameters */
  219. li t2, 0x000014C9
  220. sw t2, MC_CFGPB0(t1)
  221. /* Set SDRAM latency parameters */
  222. li t2, 0x00026325 /* BC PC100 */
  223. sw t2, MC_LATENCY(t1)
  224. 5:
  225. /* Finally enable the controller */
  226. li t2, 0x00000001
  227. sw t2, MC_CTRLENA(t1)
  228. jr ra
  229. nop
  230. .end sdram_init
  231. .globl lowlevel_init
  232. .ent lowlevel_init
  233. lowlevel_init:
  234. /* Disable Watchdog.
  235. */
  236. la t9, disable_incaip_wdt
  237. jalr t9
  238. nop
  239. /* EBU, CGU and SDRAM Initialization.
  240. */
  241. li a0, CPU_CLOCK_RATE
  242. move t0, ra
  243. /* We rely on the fact that neither ebu_init() nor cgu_init() nor sdram_init()
  244. * modify t0 and a0.
  245. */
  246. bal __cgu_init
  247. nop
  248. bal __ebu_init
  249. nop
  250. bal __sdram_init
  251. nop
  252. move ra, t0
  253. jr ra
  254. nop
  255. .end lowlevel_init