lowlevel_init.S 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. * for Orca and Emerald
  45. */
  46. #define AHBC_BSR4_A (CONFIG_FTAHBC020S_BASE + FTAHBC020S_SLAVE_BSR_4)
  47. #define AHBC_BSR6_D CONFIG_SYS_FTAHBC020S_SLAVE_BSR_6
  48. /*
  49. * parameters for the pmu controoler
  50. */
  51. #define PMU_PDLLCR0_A (CONFIG_FTPMU010_BASE + FTPMU010_PDLLCR0)
  52. /*
  53. * numeric 7 segment display
  54. */
  55. .macro led, num
  56. write32 CONFIG_DEBUG_LED, \num
  57. .endm
  58. /*
  59. * Waiting for SDRAM to set up
  60. */
  61. .macro wait_sdram
  62. li $r0, CONFIG_FTSDMC021_BASE
  63. 1:
  64. lwi $r1, [$r0+FTSDMC021_CR2]
  65. bnez $r1, 1b
  66. .endm
  67. .globl mem_init
  68. mem_init:
  69. move $r11, $lp
  70. li $r0, SMC_BANK0_CR_A
  71. lwi $r1, [$r0+#0x00]
  72. ori $r1, $r1, 0x8f0
  73. xori $r1, $r1, 0x8f0
  74. /* 16-bit mode */
  75. ori $r1, $r1, 0x60
  76. li $r2, 0x00153153
  77. swi $r1, [$r0+#0x00]
  78. swi $r2, [$r0+#0x04]
  79. move $lp, $r11
  80. ret
  81. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  82. .globl lowlevel_init
  83. lowlevel_init:
  84. move $r10, $lp
  85. jal remap
  86. #if (defined(NDS32_EXT_FPU_DP) || defined(NDS32_EXT_FPU_SP))
  87. jal enable_fpu
  88. #endif
  89. ret $r10
  90. remap:
  91. move $r11, $lp
  92. relo_base:
  93. mfusr $r0, $pc
  94. #ifdef CONFIG_MEM_REMAP
  95. li $r4, 0x00000000
  96. li $r5, 0x80000000
  97. la $r6, _end@GOTOFF
  98. 1:
  99. lmw.bim $r12, [$r5], $r19
  100. smw.bim $r12, [$r4], $r19
  101. blt $r5, $r6, 1b
  102. #endif /* #ifdef CONFIG_MEM_REMAP */
  103. move $lp, $r11
  104. 2:
  105. ret
  106. /*
  107. * enable_fpu:
  108. * Some of Andes CPU version support FPU coprocessor, if so,
  109. * and toolchain support FPU instruction set, we should enable it.
  110. */
  111. #if (defined(NDS32_EXT_FPU_DP) || defined(NDS32_EXT_FPU_SP))
  112. enable_fpu:
  113. mfsr $r0, $CPU_VER /* enable FPU if it exists */
  114. srli $r0, $r0, 3
  115. andi $r0, $r0, 1
  116. beqz $r0, 1f /* skip if no COP */
  117. mfsr $r0, $FUCOP_EXIST
  118. srli $r0, $r0, 31
  119. beqz $r0, 1f /* skip if no FPU */
  120. mfsr $r0, $FUCOP_CTL
  121. ori $r0, $r0, 1
  122. mtsr $r0, $FUCOP_CTL
  123. 1:
  124. ret
  125. #endif
  126. #endif /* #ifndef CONFIG_SKIP_LOWLEVEL_INIT */