lowlevel_init.S 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. /*
  2. * Copyright (C) 2011 Andes Technology Corporation
  3. * Shawn Lin, Andes Technology Corporation <nobuhiro@andestech.com>
  4. * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. .pic
  9. .text
  10. #include <common.h>
  11. #include <config.h>
  12. #include <asm/macro.h>
  13. #include <generated/asm-offsets.h>
  14. /*
  15. * parameters for the SDRAM controller
  16. */
  17. #define SDMC_TP1_A (CONFIG_FTSDMC021_BASE + FTSDMC021_TP1)
  18. #define SDMC_TP2_A (CONFIG_FTSDMC021_BASE + FTSDMC021_TP2)
  19. #define SDMC_CR1_A (CONFIG_FTSDMC021_BASE + FTSDMC021_CR1)
  20. #define SDMC_CR2_A (CONFIG_FTSDMC021_BASE + FTSDMC021_CR2)
  21. #define SDMC_B0_BSR_A (CONFIG_FTSDMC021_BASE + FTSDMC021_BANK0_BSR)
  22. #define SDMC_B1_BSR_A (CONFIG_FTSDMC021_BASE + FTSDMC021_BANK1_BSR)
  23. #define SDMC_TP1_D CONFIG_SYS_FTSDMC021_TP1
  24. #define SDMC_TP2_D CONFIG_SYS_FTSDMC021_TP2
  25. #define SDMC_CR1_D CONFIG_SYS_FTSDMC021_CR1
  26. #define SDMC_CR2_D CONFIG_SYS_FTSDMC021_CR2
  27. #define SDMC_B0_BSR_D CONFIG_SYS_FTSDMC021_BANK0_BSR
  28. #define SDMC_B1_BSR_D CONFIG_SYS_FTSDMC021_BANK1_BSR
  29. /*
  30. * for Orca and Emerald
  31. */
  32. #define BOARD_ID_REG 0x104
  33. #define BOARD_ID_FAMILY_MASK 0xfff000
  34. #define BOARD_ID_FAMILY_V5 0x556000
  35. #define BOARD_ID_FAMILY_K7 0x74b000
  36. /*
  37. * parameters for the static memory controller
  38. */
  39. #define SMC_BANK0_CR_A (CONFIG_FTSMC020_BASE + FTSMC020_BANK0_CR)
  40. #define SMC_BANK0_TPR_A (CONFIG_FTSMC020_BASE + FTSMC020_BANK0_TPR)
  41. #define SMC_BANK0_CR_D FTSMC020_BANK0_LOWLV_CONFIG
  42. #define SMC_BANK0_TPR_D FTSMC020_BANK0_LOWLV_TIMING
  43. /*
  44. * parameters for the ahbc controller
  45. */
  46. #define AHBC_CR_A (CONFIG_FTAHBC020S_BASE + FTAHBC020S_CR)
  47. #define AHBC_BSR6_A (CONFIG_FTAHBC020S_BASE + FTAHBC020S_SLAVE_BSR_6)
  48. /*
  49. * for Orca and Emerald
  50. */
  51. #define AHBC_BSR4_A (CONFIG_FTAHBC020S_BASE + FTAHBC020S_SLAVE_BSR_4)
  52. #define AHBC_BSR6_D CONFIG_SYS_FTAHBC020S_SLAVE_BSR_6
  53. /*
  54. * parameters for the pmu controoler
  55. */
  56. #define PMU_PDLLCR0_A (CONFIG_FTPMU010_BASE + FTPMU010_PDLLCR0)
  57. /*
  58. * numeric 7 segment display
  59. */
  60. .macro led, num
  61. write32 CONFIG_DEBUG_LED, \num
  62. .endm
  63. /*
  64. * Waiting for SDRAM to set up
  65. */
  66. .macro wait_sdram
  67. li $r0, CONFIG_FTSDMC021_BASE
  68. 1:
  69. lwi $r1, [$r0+FTSDMC021_CR2]
  70. bnez $r1, 1b
  71. .endm
  72. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  73. .globl lowlevel_init
  74. lowlevel_init:
  75. move $r10, $lp
  76. led 0x0
  77. jal mem_init
  78. led 0x10
  79. jal remap
  80. #if (defined(NDS32_EXT_FPU_DP) || defined(NDS32_EXT_FPU_SP))
  81. led 0x1f
  82. jal enable_fpu
  83. #endif
  84. led 0x20
  85. ret $r10
  86. mem_init:
  87. move $r11, $lp
  88. /*
  89. * mem_init:
  90. * There are 2 bank connected to FTSMC020 on AG101
  91. * BANK0: FLASH/ROM (SW5, J16), BANK1: OnBoard SDRAM.
  92. * we need to set onboard SDRAM before remap and relocation.
  93. */
  94. led 0x01
  95. /*
  96. * for Orca and Emerald
  97. * disable write protection and reset bank size
  98. */
  99. li $r0, SMC_BANK0_CR_A
  100. lwi $r1, [$r0+#0x00]
  101. ori $r1, $r1, 0x8f0
  102. xori $r1, $r1, 0x8f0
  103. /*
  104. * check board
  105. */
  106. li $r3, CONFIG_FTPMU010_BASE + BOARD_ID_REG
  107. lwi $r3, [$r3]
  108. li $r4, BOARD_ID_FAMILY_MASK
  109. and $r3, $r3, $r4
  110. li $r4, BOARD_ID_FAMILY_K7
  111. xor $r4, $r3, $r4
  112. beqz $r4, use_flash_16bit_boot
  113. /*
  114. * 32-bit mode
  115. */
  116. use_flash_32bit_boot:
  117. ori $r1, $r1, 0x50
  118. li $r2, 0x00151151
  119. j sdram_b0_cr
  120. /*
  121. * 16-bit mode
  122. */
  123. use_flash_16bit_boot:
  124. ori $r1, $r1, 0x60
  125. li $r2, 0x00153153
  126. /*
  127. * SRAM bank0 config
  128. */
  129. sdram_b0_cr:
  130. swi $r1, [$r0+#0x00]
  131. swi $r2, [$r0+#0x04]
  132. /*
  133. * config AHB Controller
  134. */
  135. led 0x02
  136. /*
  137. * config PMU controller
  138. */
  139. /* ftpmu010_dlldis_disable, must do it in lowleve_init */
  140. led 0x03
  141. setbf32 PMU_PDLLCR0_A, FTPMU010_PDLLCR0_DLLDIS ! 0x00010000
  142. /*
  143. * config SDRAM controller
  144. */
  145. led 0x04
  146. write32 SDMC_TP1_A, SDMC_TP1_D ! 0x00011312
  147. led 0x05
  148. write32 SDMC_TP2_A, SDMC_TP2_D ! 0x00480180
  149. led 0x06
  150. write32 SDMC_CR1_A, SDMC_CR1_D ! 0x00002326
  151. led 0x07
  152. write32 SDMC_CR2_A, FTSDMC021_CR2_IPREC ! 0x00000010
  153. wait_sdram
  154. led 0x08
  155. write32 SDMC_CR2_A, FTSDMC021_CR2_ISMR ! 0x00000004
  156. wait_sdram
  157. led 0x09
  158. write32 SDMC_CR2_A, FTSDMC021_CR2_IREF ! 0x00000008
  159. wait_sdram
  160. led 0x0a
  161. move $lp, $r11
  162. ret
  163. remap:
  164. move $r11, $lp
  165. #ifdef __NDS32_N1213_43U1H__ /* NDS32 V0 ISA - AG101 Only */
  166. bal 2f
  167. relo_base:
  168. move $r0, $lp
  169. #else
  170. relo_base:
  171. mfusr $r0, $pc
  172. #endif /* __NDS32_N1213_43U1H__ */
  173. /*
  174. * Remapping
  175. */
  176. led 0x1a
  177. write32 SDMC_B0_BSR_A, SDMC_B0_BSR_D ! 0x00001800
  178. write32 SDMC_B1_BSR_A, SDMC_B1_BSR_D ! 0x00001880
  179. /* clear empty BSR registers */
  180. led 0x1b
  181. li $r4, CONFIG_FTSDMC021_BASE
  182. li $r5, 0x0
  183. swi $r5, [$r4 + FTSDMC021_BANK2_BSR]
  184. swi $r5, [$r4 + FTSDMC021_BANK3_BSR]
  185. #ifdef CONFIG_MEM_REMAP
  186. /*
  187. * Copy ROM code to SDRAM base for memory remap layout.
  188. * This is not the real relocation, the real relocation is the function
  189. * relocate_code() is start.S which supports the systems is memory
  190. * remapped or not.
  191. */
  192. /*
  193. * Doing memory remap is essential for preparing some non-OS or RTOS
  194. * applications.
  195. *
  196. * This is also a must on ADP-AG101 board.
  197. * The reason is because the ROM/FLASH circuit on PCB board.
  198. * AG101-A0 board has 2 jumpers MA17 and SW5 to configure which
  199. * ROM/FLASH is used to boot.
  200. *
  201. * When SW5 = "0101", MA17 = LO, the ROM is connected to BANK0,
  202. * and the FLASH is connected to BANK1.
  203. * When SW5 = "1010", MA17 = HI, the ROM is disabled (still at BANK0),
  204. * and the FLASH is connected to BANK0.
  205. * It will occur problem when doing flash probing if the flash is at
  206. * BANK0 (0x00000000) while memory remapping was skipped.
  207. *
  208. * Other board like ADP-AG101P may not enable this since there is only
  209. * a FLASH connected to bank0.
  210. */
  211. led 0x11
  212. /*
  213. * for Orca and Emerald
  214. * read sdram base address automatically
  215. */
  216. li $r5, AHBC_BSR6_A
  217. lwi $r8, [$r5]
  218. li $r4, 0xfff00000 /* r4 = bank6 base */
  219. and $r4, $r4, $r8
  220. la $r5, _start@GOTOFF
  221. la $r6, _end@GOTOFF
  222. 1:
  223. lwi.p $r7, [$r5], #4
  224. swi.p $r7, [$r4], #4
  225. blt $r5, $r6, 1b
  226. /* set remap bit */
  227. /*
  228. * MEM remap bit is operational
  229. * - use it to map writeable memory at 0x00000000, in place of flash
  230. * - before remap: flash/rom 0x00000000, sdram: 0x10000000-0x4fffffff
  231. * - after remap: flash/rom 0x80000000, sdram: 0x00000000
  232. */
  233. led 0x1c
  234. write32 SDMC_B0_BSR_A, 0x00001000
  235. write32 SDMC_B1_BSR_A, 0x00001200
  236. li $r5, CONFIG_SYS_TEXT_BASE /* flash base address */
  237. add $r11, $r11, $r5 /* add flash address offset for ret */
  238. add $r10, $r10, $r5
  239. move $lp, $r11
  240. setbf15 AHBC_CR_A, FTAHBC020S_CR_REMAP ! 0x1
  241. /*
  242. * for Orca and Emerald
  243. * extend sdram size from 256MB to 2GB
  244. */
  245. li $r5, AHBC_BSR6_A
  246. lwi $r6, [$r5]
  247. li $r4, 0xfff0ffff
  248. and $r6 ,$r4, $r6
  249. li $r4, 0x000b0000
  250. or $r6, $r4, $r6
  251. swi $r6, [$r5]
  252. /*
  253. * for Orca and Emerald
  254. * extend rom base from 256MB to 2GB
  255. */
  256. li $r4, AHBC_BSR4_A
  257. lwi $r5, [$r4]
  258. li $r6, 0xffffff
  259. and $r5, $r5, $r6
  260. li $r6, 0x80000000
  261. or $r5, $r5, $r6
  262. swi $r5, [$r4]
  263. #endif /* #ifdef CONFIG_MEM_REMAP */
  264. move $lp, $r11
  265. 2:
  266. ret
  267. /*
  268. * enable_fpu:
  269. * Some of Andes CPU version support FPU coprocessor, if so,
  270. * and toolchain support FPU instruction set, we should enable it.
  271. */
  272. #if (defined(NDS32_EXT_FPU_DP) || defined(NDS32_EXT_FPU_SP))
  273. enable_fpu:
  274. mfsr $r0, $CPU_VER /* enable FPU if it exists */
  275. srli $r0, $r0, 3
  276. andi $r0, $r0, 1
  277. beqz $r0, 1f /* skip if no COP */
  278. mfsr $r0, $FUCOP_EXIST
  279. srli $r0, $r0, 31
  280. beqz $r0, 1f /* skip if no FPU */
  281. mfsr $r0, $FUCOP_CTL
  282. ori $r0, $r0, 1
  283. mtsr $r0, $FUCOP_CTL
  284. 1:
  285. ret
  286. #endif
  287. .globl show_led
  288. show_led:
  289. li $r8, (CONFIG_DEBUG_LED)
  290. swi $r7, [$r8]
  291. ret
  292. #endif /* #ifndef CONFIG_SKIP_LOWLEVEL_INIT */