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>
6 * SPDX-License-Identifier: GPL-2.0+
16 #include <asm/macro.h>
17 #include <generated/asm-offsets.h>
20 * parameters for the SDRAM controller
22 #define SDMC_TP1_A (CONFIG_FTSDMC021_BASE + FTSDMC021_TP1)
23 #define SDMC_TP2_A (CONFIG_FTSDMC021_BASE + FTSDMC021_TP2)
24 #define SDMC_CR1_A (CONFIG_FTSDMC021_BASE + FTSDMC021_CR1)
25 #define SDMC_CR2_A (CONFIG_FTSDMC021_BASE + FTSDMC021_CR2)
26 #define SDMC_B0_BSR_A (CONFIG_FTSDMC021_BASE + FTSDMC021_BANK0_BSR)
27 #define SDMC_B1_BSR_A (CONFIG_FTSDMC021_BASE + FTSDMC021_BANK1_BSR)
29 #define SDMC_TP1_D CONFIG_SYS_FTSDMC021_TP1
30 #define SDMC_TP2_D CONFIG_SYS_FTSDMC021_TP2
31 #define SDMC_CR1_D CONFIG_SYS_FTSDMC021_CR1
32 #define SDMC_CR2_D CONFIG_SYS_FTSDMC021_CR2
34 #define SDMC_B0_BSR_D CONFIG_SYS_FTSDMC021_BANK0_BSR
35 #define SDMC_B1_BSR_D CONFIG_SYS_FTSDMC021_BANK1_BSR
39 * for Orca and Emerald
41 #define BOARD_ID_REG 0x104
42 #define BOARD_ID_FAMILY_MASK 0xfff000
43 #define BOARD_ID_FAMILY_V5 0x556000
44 #define BOARD_ID_FAMILY_K7 0x74b000
47 * parameters for the static memory controller
49 #define SMC_BANK0_CR_A (CONFIG_FTSMC020_BASE + FTSMC020_BANK0_CR)
50 #define SMC_BANK0_TPR_A (CONFIG_FTSMC020_BASE + FTSMC020_BANK0_TPR)
52 #define SMC_BANK0_CR_D FTSMC020_BANK0_LOWLV_CONFIG
53 #define SMC_BANK0_TPR_D FTSMC020_BANK0_LOWLV_TIMING
56 * parameters for the ahbc controller
58 #define AHBC_CR_A (CONFIG_FTAHBC020S_BASE + FTAHBC020S_CR)
59 #define AHBC_BSR6_A (CONFIG_FTAHBC020S_BASE + FTAHBC020S_SLAVE_BSR_6)
62 * for Orca and Emerald
64 #define AHBC_BSR4_A (CONFIG_FTAHBC020S_BASE + FTAHBC020S_SLAVE_BSR_4)
65 #define AHBC_BSR6_D CONFIG_SYS_FTAHBC020S_SLAVE_BSR_6
68 * parameters for the pmu controoler
70 #define PMU_PDLLCR0_A (CONFIG_FTPMU010_BASE + FTPMU010_PDLLCR0)
73 * numeric 7 segment display
76 write32 CONFIG_DEBUG_LED, \num
80 * Waiting for SDRAM to set up
83 li $r0, CONFIG_FTSDMC021_BASE
85 lwi $r1, [$r0+FTSDMC021_CR2]
89 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
100 #if (defined(NDS32_EXT_FPU_DP) || defined(NDS32_EXT_FPU_SP))
113 * There are 2 bank connected to FTSMC020 on AG101
114 * BANK0: FLASH/ROM (SW5, J16), BANK1: OnBoard SDRAM.
115 * we need to set onboard SDRAM before remap and relocation.
120 * for Orca and Emerald
121 * disable write protection and reset bank size
123 li $r0, SMC_BANK0_CR_A
130 li $r3, CONFIG_FTPMU010_BASE + BOARD_ID_REG
132 li $r4, BOARD_ID_FAMILY_MASK
134 li $r4, BOARD_ID_FAMILY_K7
136 beqz $r4, use_flash_16bit_boot
140 use_flash_32bit_boot:
147 use_flash_16bit_boot:
158 * config AHB Controller
163 * config PMU controller
165 /* ftpmu010_dlldis_disable, must do it in lowleve_init */
167 setbf32 PMU_PDLLCR0_A, FTPMU010_PDLLCR0_DLLDIS ! 0x00010000
170 * config SDRAM controller
173 write32 SDMC_TP1_A, SDMC_TP1_D ! 0x00011312
175 write32 SDMC_TP2_A, SDMC_TP2_D ! 0x00480180
177 write32 SDMC_CR1_A, SDMC_CR1_D ! 0x00002326
180 write32 SDMC_CR2_A, FTSDMC021_CR2_IPREC ! 0x00000010
184 write32 SDMC_CR2_A, FTSDMC021_CR2_ISMR ! 0x00000004
188 write32 SDMC_CR2_A, FTSDMC021_CR2_IREF ! 0x00000008
197 #ifdef __NDS32_N1213_43U1H__ /* NDS32 V0 ISA - AG101 Only */
204 #endif /* __NDS32_N1213_43U1H__ */
210 write32 SDMC_B0_BSR_A, SDMC_B0_BSR_D ! 0x00001800
211 write32 SDMC_B1_BSR_A, SDMC_B1_BSR_D ! 0x00001880
213 /* clear empty BSR registers */
215 li $r4, CONFIG_FTSDMC021_BASE
217 swi $r5, [$r4 + FTSDMC021_BANK2_BSR]
218 swi $r5, [$r4 + FTSDMC021_BANK3_BSR]
220 #ifdef CONFIG_MEM_REMAP
222 * Copy ROM code to SDRAM base for memory remap layout.
223 * This is not the real relocation, the real relocation is the function
224 * relocate_code() is start.S which supports the systems is memory
228 * Doing memory remap is essential for preparing some non-OS or RTOS
231 * This is also a must on ADP-AG101 board.
232 * The reason is because the ROM/FLASH circuit on PCB board.
233 * AG101-A0 board has 2 jumpers MA17 and SW5 to configure which
234 * ROM/FLASH is used to boot.
236 * When SW5 = "0101", MA17 = LO, the ROM is connected to BANK0,
237 * and the FLASH is connected to BANK1.
238 * When SW5 = "1010", MA17 = HI, the ROM is disabled (still at BANK0),
239 * and the FLASH is connected to BANK0.
240 * It will occur problem when doing flash probing if the flash is at
241 * BANK0 (0x00000000) while memory remapping was skipped.
243 * Other board like ADP-AG101P may not enable this since there is only
244 * a FLASH connected to bank0.
248 * for Orca and Emerald
249 * read sdram base address automatically
253 li $r4, 0xfff00000 /* r4 = bank6 base */
256 la $r5, _start@GOTOFF
265 * MEM remap bit is operational
266 * - use it to map writeable memory at 0x00000000, in place of flash
267 * - before remap: flash/rom 0x00000000, sdram: 0x10000000-0x4fffffff
268 * - after remap: flash/rom 0x80000000, sdram: 0x00000000
271 write32 SDMC_B0_BSR_A, 0x00001000
272 write32 SDMC_B1_BSR_A, 0x00001200
273 li $r5, CONFIG_SYS_TEXT_BASE /* flash base address */
274 add $r11, $r11, $r5 /* add flash address offset for ret */
277 setbf15 AHBC_CR_A, FTAHBC020S_CR_REMAP ! 0x1
280 * for Orca and Emerald
281 * extend sdram size from 256MB to 2GB
292 * for Orca and Emerald
293 * extend rom base from 256MB to 2GB
302 #endif /* #ifdef CONFIG_MEM_REMAP */
309 * Some of Andes CPU version support FPU coprocessor, if so,
310 * and toolchain support FPU instruction set, we should enable it.
312 #if (defined(NDS32_EXT_FPU_DP) || defined(NDS32_EXT_FPU_SP))
314 mfsr $r0, $CPU_VER /* enable FPU if it exists */
317 beqz $r0, 1f /* skip if no COP */
318 mfsr $r0, $FUCOP_EXIST
320 beqz $r0, 1f /* skip if no FPU */
330 li $r8, (CONFIG_DEBUG_LED)
333 #endif /* #ifndef CONFIG_SKIP_LOWLEVEL_INIT */