lowlevel_init.S 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. * Copyright (C) 2011 Andes Technology Corporation
  3. * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. .text
  24. #include <common.h>
  25. #include <config.h>
  26. #include <asm/macro.h>
  27. #include <generated/asm-offsets.h>
  28. /*
  29. * parameters for Synopsys DWC DDR2/DDR1 Memory Controller
  30. */
  31. #define DDR2C_BASE_A (CONFIG_DWCDDR21MCTL_BASE)
  32. #define DDR2C_CCR_A (DDR2C_BASE_A + DWCDDR21MCTL_CCR)
  33. #define DDR2C_DCR_A (DDR2C_BASE_A + DWCDDR21MCTL_DCR)
  34. #define DDR2C_IOCR_A (DDR2C_BASE_A + DWCDDR21MCTL_IOCR)
  35. #define DDR2C_CSR_A (DDR2C_BASE_A + DWCDDR21MCTL_CSR)
  36. #define DDR2C_DRR_A (DDR2C_BASE_A + DWCDDR21MCTL_DRR)
  37. #define DDR2C_DLLCR0_A (DDR2C_BASE_A + DWCDDR21MCTL_DLLCR0)
  38. #define DDR2C_DLLCR1_A (DDR2C_BASE_A + DWCDDR21MCTL_DLLCR1)
  39. #define DDR2C_DLLCR2_A (DDR2C_BASE_A + DWCDDR21MCTL_DLLCR2)
  40. #define DDR2C_DLLCR3_A (DDR2C_BASE_A + DWCDDR21MCTL_DLLCR3)
  41. #define DDR2C_DLLCR4_A (DDR2C_BASE_A + DWCDDR21MCTL_DLLCR4)
  42. #define DDR2C_DLLCR5_A (DDR2C_BASE_A + DWCDDR21MCTL_DLLCR5)
  43. #define DDR2C_DLLCR6_A (DDR2C_BASE_A + DWCDDR21MCTL_DLLCR6)
  44. #define DDR2C_DLLCR7_A (DDR2C_BASE_A + DWCDDR21MCTL_DLLCR7)
  45. #define DDR2C_DLLCR8_A (DDR2C_BASE_A + DWCDDR21MCTL_DLLCR8)
  46. #define DDR2C_DLLCR9_A (DDR2C_BASE_A + DWCDDR21MCTL_DLLCR9)
  47. #define DDR2C_RSLR0_A (DDR2C_BASE_A + DWCDDR21MCTL_RSLR0)
  48. #define DDR2C_RDGR0_A (DDR2C_BASE_A + DWCDDR21MCTL_RDGR0)
  49. #define DDR2C_DTAR_A (DDR2C_BASE_A + DWCDDR21MCTL_DTAR)
  50. #define DDR2C_MR_A (DDR2C_BASE_A + DWCDDR21MCTL_MR)
  51. #define DDR2C_CCR_D CONFIG_SYS_DWCDDR21MCTL_CCR
  52. #define DDR2C_CCR_D2 CONFIG_SYS_DWCDDR21MCTL_CCR2
  53. #define DDR2C_DCR_D CONFIG_SYS_DWCDDR21MCTL_DCR
  54. #define DDR2C_IOCR_D CONFIG_SYS_DWCDDR21MCTL_IOCR
  55. #define DDR2C_CSR_D CONFIG_SYS_DWCDDR21MCTL_CSR
  56. #define DDR2C_DRR_D CONFIG_SYS_DWCDDR21MCTL_DRR
  57. #define DDR2C_RSLR0_D CONFIG_SYS_DWCDDR21MCTL_RSLR0
  58. #define DDR2C_RDGR0_D CONFIG_SYS_DWCDDR21MCTL_RDGR0
  59. #define DDR2C_DTAR_D CONFIG_SYS_DWCDDR21MCTL_DTAR
  60. #define DDR2C_MR_D CONFIG_SYS_DWCDDR21MCTL_MR
  61. #define DDR2C_DLLCR0_D CONFIG_SYS_DWCDDR21MCTL_DLLCR0 /* 0-9 are same */
  62. /*
  63. * parameters for the ahbc controller
  64. */
  65. #define AHBC_CR_A (CONFIG_FTAHBC020S_BASE + FTAHBC020S_CR)
  66. #define AHBC_BSR6_A (CONFIG_FTAHBC020S_BASE + FTAHBC020S_SLAVE_BSR_6)
  67. #define AHBC_BSR6_D CONFIG_SYS_FTAHBC020S_SLAVE_BSR_6
  68. /*
  69. * parameters for the ANDES PCU controller
  70. */
  71. #define PCU_PCS4_A (CONFIG_ANDES_PCU_BASE + ANDES_PCU_PCS4)
  72. #define PCU_PCS4_D CONFIG_SYS_ANDES_CPU_PCS4
  73. /*
  74. * numeric 7 segment display
  75. */
  76. .macro led, num
  77. write32 CONFIG_DEBUG_LED, \num
  78. .endm
  79. /*
  80. * Waiting for SDRAM to set up
  81. */
  82. /*
  83. .macro wait_sdram
  84. li $r0, DDR2C_CSR_A
  85. 1:
  86. lwi $r1, [$r0+FTSDMC021_CR2]
  87. bnez $r1, 1b
  88. .endm
  89. */
  90. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  91. .globl lowlevel_init
  92. lowlevel_init:
  93. move $r10, $lp
  94. /* U200 */
  95. ! led 0x00
  96. ! jal scale_to_500mhz
  97. led 0x10
  98. jal mem_init
  99. led 0x20
  100. jal remap
  101. led 0x30
  102. ret $r10
  103. scale_to_500mhz:
  104. move $r11, $lp
  105. /*
  106. * scale to 500Mhz
  107. */
  108. led 0x01
  109. write32 PCU_PCS4_A, 0x1102000f ! save data to PCS4
  110. move $lp, $r11
  111. ret
  112. mem_init:
  113. move $r11, $lp
  114. /*
  115. * config AHB Controller
  116. */
  117. led 0x12
  118. write32 AHBC_BSR6_A, AHBC_BSR6_D
  119. /*
  120. * config Synopsys DWC DDR2/DDR1 Memory Controller
  121. */
  122. ddr2c_init:
  123. set_dcr:
  124. led 0x14
  125. write32 DDR2C_DCR_A, DDR2C_DCR_D ! 0x000020d4
  126. auto_sizing:
  127. /*
  128. * ebios: $r10->$r7, $r11->$r8, $r12->$r9, $r13->$r12, $r14->$r13
  129. */
  130. set_iocr:
  131. led 0x19
  132. write32 DDR2C_IOCR_A, DDR2C_IOCR_D
  133. set_drr:
  134. led 0x16
  135. write32 DDR2C_DRR_A, DDR2C_DRR_D ! 0x00034812
  136. set_dllcr:
  137. led 0x18
  138. write32 DDR2C_DLLCR0_A, DDR2C_DLLCR0_D
  139. write32 DDR2C_DLLCR1_A, DDR2C_DLLCR0_D
  140. write32 DDR2C_DLLCR2_A, DDR2C_DLLCR0_D
  141. write32 DDR2C_DLLCR3_A, DDR2C_DLLCR0_D
  142. write32 DDR2C_DLLCR4_A, DDR2C_DLLCR0_D
  143. write32 DDR2C_DLLCR5_A, DDR2C_DLLCR0_D
  144. write32 DDR2C_DLLCR6_A, DDR2C_DLLCR0_D
  145. write32 DDR2C_DLLCR7_A, DDR2C_DLLCR0_D
  146. write32 DDR2C_DLLCR8_A, DDR2C_DLLCR0_D
  147. write32 DDR2C_DLLCR9_A, DDR2C_DLLCR0_D
  148. set_rslr0:
  149. write32 DDR2C_RSLR0_A, DDR2C_RSLR0_D ! 0x00000040
  150. set_rdgr0:
  151. write32 DDR2C_RDGR0_A, DDR2C_RDGR0_D ! 0x000055cf
  152. set_dtar:
  153. led 0x15
  154. write32 DDR2C_DTAR_A, DDR2C_DTAR_D ! 0x00100000
  155. set_mode:
  156. led 0x17
  157. write32 DDR2C_MR_A, DDR2C_MR_D ! 0x00000852
  158. set_ccr:
  159. write32 DDR2C_CCR_A, DDR2C_CCR_D
  160. #ifdef TRIGGER_INIT:
  161. trigger_init:
  162. write32 DDR2C_CCR_A, DDR2C_CCR_D ! 0x80020000
  163. /* Wait for ddr init state to be set */
  164. msync ALL
  165. isb
  166. /* Wait until the config initialization is finish */
  167. 1:
  168. la $r4, DDR2C_CSR_A
  169. lwi $r5, [$r4]
  170. srli $r5, $r5, 23
  171. bnez $r5, 1b
  172. #endif
  173. data_training:
  174. ! write32 DDR2C_CCR_A, DDR2C_CCR_D2 ! 0x40020004
  175. /* Wait for ddr init state to be set */
  176. msync ALL
  177. isb
  178. /* wait until the ddr data trainning is complete */
  179. 1:
  180. la $r4, DDR2C_CSR_A
  181. lwi $r5, [$r4]
  182. srli $r6, $r5, 23
  183. bnez $r6, 1b
  184. lwi $r1, [$r4]
  185. srli $r6, $r5, 20
  186. li $r5, 0x00ffffff
  187. swi $r1, [$r4]
  188. bnez $r6, ddr2c_init
  189. led 0x1a
  190. move $lp, $r11
  191. ret
  192. remap:
  193. move $r11, $lp
  194. #ifdef __NDS32_N1213_43U1H__ /* NDS32 V0 ISA - AG101 Only */
  195. bal 2f
  196. relo_base:
  197. move $r0, $lp
  198. #else
  199. relo_base:
  200. mfusr $r0, $pc
  201. #endif /* __NDS32_N1213_43U1H__ */
  202. /*
  203. * Remapping
  204. */
  205. #ifdef CONFIG_MEM_REMAP
  206. /*
  207. * Copy ROM code to SDRAM base for memory remap layout.
  208. * This is not the real relocation, the real relocation is the function
  209. * relocate_code() is start.S which supports the systems is memory
  210. * remapped or not.
  211. */
  212. /*
  213. * Doing memory remap is essential for preparing some non-OS or RTOS
  214. * applications.
  215. *
  216. * This is also a must on ADP-AG101 board.
  217. * The reason is because the ROM/FLASH circuit on PCB board.
  218. * AG101-A0 board has 2 jumpers MA17 and SW5 to configure which
  219. * ROM/FLASH is used to boot.
  220. *
  221. * When SW5 = "0101", MA17 = LO, the ROM is connected to BANK0,
  222. * and the FLASH is connected to BANK1.
  223. * When SW5 = "1010", MA17 = HI, the ROM is disabled (still at BANK0),
  224. * and the FLASH is connected to BANK0.
  225. * It will occur problem when doing flash probing if the flash is at
  226. * BANK0 (0x00000000) while memory remapping was skipped.
  227. *
  228. * Other board like ADP-AG101P may not enable this since there is only
  229. * a FLASH connected to bank0.
  230. */
  231. led 0x21
  232. li $r4, PHYS_SDRAM_0_AT_INIT /* 0x10000000 */
  233. li $r5, 0x0
  234. la $r1, relo_base /* get $pc or $lp */
  235. sub $r2, $r0, $r1
  236. sethi $r6, hi20(_end)
  237. ori $r6, $r6, lo12(_end)
  238. add $r6, $r6, $r2
  239. 1:
  240. lwi.p $r7, [$r5], #4
  241. swi.p $r7, [$r4], #4
  242. blt $r5, $r6, 1b
  243. /* set remap bit */
  244. /*
  245. * MEM remap bit is operational
  246. * - use it to map writeable memory at 0x00000000, in place of flash
  247. * - before remap: flash/rom 0x00000000, sdram: 0x10000000-0x4fffffff
  248. * - after remap: flash/rom 0x80000000, sdram: 0x00000000
  249. */
  250. led 0x2c
  251. setbf15 AHBC_CR_A, FTAHBC020S_CR_REMAP ! 0x1
  252. #endif /* #ifdef CONFIG_MEM_REMAP */
  253. move $lp, $r11
  254. 2:
  255. ret
  256. .globl show_led
  257. show_led:
  258. li $r8, (CONFIG_DEBUG_LED)
  259. swi $r7, [$r8]
  260. ret
  261. #endif /* #ifndef CONFIG_SKIP_LOWLEVEL_INIT */