lowlevel_init.S 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*
  2. * Memory sub-system initialization code for INCA-IP development board.
  3. *
  4. * Copyright (c) 2003 Wolfgang Denk <wd@denx.de>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <config.h>
  9. #include <asm/regdef.h>
  10. #define EBU_MODUL_BASE 0xB8000200
  11. #define EBU_CLC(value) 0x0000(value)
  12. #define EBU_CON(value) 0x0010(value)
  13. #define EBU_ADDSEL0(value) 0x0020(value)
  14. #define EBU_ADDSEL1(value) 0x0024(value)
  15. #define EBU_ADDSEL2(value) 0x0028(value)
  16. #define EBU_BUSCON0(value) 0x0060(value)
  17. #define EBU_BUSCON1(value) 0x0064(value)
  18. #define EBU_BUSCON2(value) 0x0068(value)
  19. #define MC_MODUL_BASE 0xBF800000
  20. #define MC_ERRCAUSE(value) 0x0100(value)
  21. #define MC_ERRADDR(value) 0x0108(value)
  22. #define MC_IOGP(value) 0x0800(value)
  23. #define MC_SELFRFSH(value) 0x0A00(value)
  24. #define MC_CTRLENA(value) 0x1000(value)
  25. #define MC_MRSCODE(value) 0x1008(value)
  26. #define MC_CFGDW(value) 0x1010(value)
  27. #define MC_CFGPB0(value) 0x1018(value)
  28. #define MC_LATENCY(value) 0x1038(value)
  29. #define MC_TREFRESH(value) 0x1040(value)
  30. #define CGU_MODUL_BASE 0xBF107000
  31. #define CGU_PLL1CR(value) 0x0008(value)
  32. #define CGU_DIVCR(value) 0x0010(value)
  33. #define CGU_MUXCR(value) 0x0014(value)
  34. #define CGU_PLL1SR(value) 0x000C(value)
  35. .set noreorder
  36. /*
  37. * void ebu_init(long)
  38. *
  39. * a0 has the clock value we are going to run at
  40. */
  41. .globl ebu_init
  42. .ent ebu_init
  43. ebu_init:
  44. __ebu_init:
  45. li t1, EBU_MODUL_BASE
  46. li t2, 0xA0000041
  47. sw t2, EBU_ADDSEL0(t1)
  48. li t2, 0xA0800041
  49. sw t2, EBU_ADDSEL2(t1)
  50. li t2, 0xBE0000F1
  51. sw t2, EBU_ADDSEL1(t1)
  52. li t3, 100000000
  53. beq a0, t3, 1f
  54. nop
  55. li t3, 133000000
  56. beq a0, t3, 2f
  57. nop
  58. li t3, 150000000
  59. beq a0, t3, 2f
  60. nop
  61. b 3f
  62. nop
  63. /* 100 MHz */
  64. 1:
  65. li t2, 0x8841417D
  66. sw t2, EBU_BUSCON0(t1)
  67. sw t2, EBU_BUSCON2(t1)
  68. li t2, 0x684142BD
  69. b 3f
  70. sw t2, EBU_BUSCON1(t1) /* delay slot */
  71. /* 133 or 150 MHz */
  72. 2:
  73. li t2, 0x8841417E
  74. sw t2, EBU_BUSCON0(t1)
  75. sw t2, EBU_BUSCON2(t1)
  76. li t2, 0x684143FD
  77. sw t2, EBU_BUSCON1(t1)
  78. 3:
  79. jr ra
  80. nop
  81. .end ebu_init
  82. /*
  83. * void cgu_init(long)
  84. *
  85. * a0 has the clock value
  86. */
  87. .globl cgu_init
  88. .ent cgu_init
  89. cgu_init:
  90. __cgu_init:
  91. li t1, CGU_MODUL_BASE
  92. li t3, 100000000
  93. beq a0, t3, 1f
  94. nop
  95. li t3, 133000000
  96. beq a0, t3, 2f
  97. nop
  98. li t3, 150000000
  99. beq a0, t3, 3f
  100. nop
  101. b 5f
  102. nop
  103. /* 100 MHz clock */
  104. 1:
  105. li t2, 0x80000014
  106. sw t2, CGU_DIVCR(t1)
  107. li t2, 0x80000000
  108. sw t2, CGU_MUXCR(t1)
  109. li t2, 0x800B0001
  110. b 5f
  111. sw t2, CGU_PLL1CR(t1) /* delay slot */
  112. /* 133 MHz clock */
  113. 2:
  114. li t2, 0x80000054
  115. sw t2, CGU_DIVCR(t1)
  116. li t2, 0x80000000
  117. sw t2, CGU_MUXCR(t1)
  118. li t2, 0x800B0001
  119. b 5f
  120. sw t2, CGU_PLL1CR(t1) /* delay slot */
  121. /* 150 MHz clock */
  122. 3:
  123. li t2, 0x80000017
  124. sw t2, CGU_DIVCR(t1)
  125. li t2, 0xC00B0001
  126. sw t2, CGU_PLL1CR(t1)
  127. li t3, 0x80000000
  128. 4:
  129. lw t2, CGU_PLL1SR(t1)
  130. and t2, t2, t3
  131. beq t2, zero, 4b
  132. nop
  133. li t2, 0x80000001
  134. sw t2, CGU_MUXCR(t1)
  135. 5:
  136. jr ra
  137. nop
  138. .end cgu_init
  139. /*
  140. * void sdram_init(long)
  141. *
  142. * a0 has the clock value
  143. */
  144. .globl sdram_init
  145. .ent sdram_init
  146. sdram_init:
  147. __sdram_init:
  148. li t1, MC_MODUL_BASE
  149. #if 0
  150. /* Disable memory controller before changing any of its registers */
  151. sw zero, MC_CTRLENA(t1)
  152. #endif
  153. li t2, 100000000
  154. beq a0, t2, 1f
  155. nop
  156. li t2, 133000000
  157. beq a0, t2, 2f
  158. nop
  159. li t2, 150000000
  160. beq a0, t2, 3f
  161. nop
  162. b 5f
  163. nop
  164. /* 100 MHz clock */
  165. 1:
  166. /* Set clock ratio (clkrat=1:1, rddel=3) */
  167. li t2, 0x00000003
  168. sw t2, MC_IOGP(t1)
  169. /* Set sdram refresh rate (4K/64ms @ 100MHz) */
  170. li t2, 0x0000061A
  171. b 4f
  172. sw t2, MC_TREFRESH(t1)
  173. /* 133 MHz clock */
  174. 2:
  175. /* Set clock ratio (clkrat=1:1, rddel=3) */
  176. li t2, 0x00000003
  177. sw t2, MC_IOGP(t1)
  178. /* Set sdram refresh rate (4K/64ms @ 133MHz) */
  179. li t2, 0x00000822
  180. b 4f
  181. sw t2, MC_TREFRESH(t1)
  182. /* 150 MHz clock */
  183. 3:
  184. /* Set clock ratio (clkrat=3:2, rddel=4) */
  185. li t2, 0x00000014
  186. sw t2, MC_IOGP(t1)
  187. /* Set sdram refresh rate (4K/64ms @ 150MHz) */
  188. li t2, 0x00000927
  189. sw t2, MC_TREFRESH(t1)
  190. 4:
  191. /* Clear Error log registers */
  192. sw zero, MC_ERRCAUSE(t1)
  193. sw zero, MC_ERRADDR(t1)
  194. /* Clear Power-down registers */
  195. sw zero, MC_SELFRFSH(t1)
  196. /* Set CAS Latency */
  197. li t2, 0x00000020 /* CL = 2 */
  198. sw t2, MC_MRSCODE(t1)
  199. /* Set word width to 16 bit */
  200. li t2, 0x2
  201. sw t2, MC_CFGDW(t1)
  202. /* Set CS0 to SDRAM parameters */
  203. li t2, 0x000014C9
  204. sw t2, MC_CFGPB0(t1)
  205. /* Set SDRAM latency parameters */
  206. li t2, 0x00026325 /* BC PC100 */
  207. sw t2, MC_LATENCY(t1)
  208. 5:
  209. /* Finally enable the controller */
  210. li t2, 0x00000001
  211. sw t2, MC_CTRLENA(t1)
  212. jr ra
  213. nop
  214. .end sdram_init
  215. .globl lowlevel_init
  216. .ent lowlevel_init
  217. lowlevel_init:
  218. /* Disable Watchdog.
  219. */
  220. la t9, disable_incaip_wdt
  221. jalr t9
  222. nop
  223. /* EBU, CGU and SDRAM Initialization.
  224. */
  225. li a0, CONFIG_CPU_CLOCK_RATE
  226. move t0, ra
  227. /* We rely on the fact that neither ebu_init() nor cgu_init() nor sdram_init()
  228. * modify t0 and a0.
  229. */
  230. bal __cgu_init
  231. nop
  232. bal __ebu_init
  233. nop
  234. bal __sdram_init
  235. nop
  236. move ra, t0
  237. jr ra
  238. nop
  239. .end lowlevel_init