lowlevel_init.S 7.4 KB

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