blob: 55985cf559cded9ab8194d26abe18c47e3cb03e8 [file] [log] [blame]
Macpaul Lin83dbca72011-10-11 22:33:18 +00001/*
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 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24
25.text
26
27#include <common.h>
28#include <config.h>
29
30#include <asm/macro.h>
31#include <generated/asm-offsets.h>
32
33/*
34 * parameters for the SDRAM controller
35 */
36#define SDMC_TP1_A (CONFIG_FTSDMC021_BASE + FTSDMC021_TP1)
37#define SDMC_TP2_A (CONFIG_FTSDMC021_BASE + FTSDMC021_TP2)
38#define SDMC_CR1_A (CONFIG_FTSDMC021_BASE + FTSDMC021_CR1)
39#define SDMC_CR2_A (CONFIG_FTSDMC021_BASE + FTSDMC021_CR2)
40#define SDMC_B0_BSR_A (CONFIG_FTSDMC021_BASE + FTSDMC021_BANK0_BSR)
ken kuo7abab272013-06-08 11:14:09 +080041#define SDMC_B1_BSR_A (CONFIG_FTSDMC021_BASE + FTSDMC021_BANK1_BSR)
Macpaul Lin83dbca72011-10-11 22:33:18 +000042
43#define SDMC_TP1_D CONFIG_SYS_FTSDMC021_TP1
44#define SDMC_TP2_D CONFIG_SYS_FTSDMC021_TP2
45#define SDMC_CR1_D CONFIG_SYS_FTSDMC021_CR1
46#define SDMC_CR2_D CONFIG_SYS_FTSDMC021_CR2
47
48#define SDMC_B0_BSR_D CONFIG_SYS_FTSDMC021_BANK0_BSR
ken kuo7abab272013-06-08 11:14:09 +080049#define SDMC_B1_BSR_D CONFIG_SYS_FTSDMC021_BANK1_BSR
Macpaul Lin83dbca72011-10-11 22:33:18 +000050
51/*
52 * parameters for the static memory controller
53 */
54#define SMC_BANK0_CR_A (CONFIG_FTSMC020_BASE + FTSMC020_BANK0_CR)
55#define SMC_BANK0_TPR_A (CONFIG_FTSMC020_BASE + FTSMC020_BANK0_TPR)
56
57#define SMC_BANK0_CR_D FTSMC020_BANK0_LOWLV_CONFIG
58#define SMC_BANK0_TPR_D FTSMC020_BANK0_LOWLV_TIMING
59
60/*
61 * parameters for the ahbc controller
62 */
63#define AHBC_CR_A (CONFIG_FTAHBC020S_BASE + FTAHBC020S_CR)
64#define AHBC_BSR6_A (CONFIG_FTAHBC020S_BASE + FTAHBC020S_SLAVE_BSR_6)
65
66#define AHBC_BSR6_D CONFIG_SYS_FTAHBC020S_SLAVE_BSR_6
67
68/*
69 * parameters for the pmu controoler
70 */
71#define PMU_PDLLCR0_A (CONFIG_FTPMU010_BASE + FTPMU010_PDLLCR0)
72
73/*
74 * numeric 7 segment display
75 */
76.macro led, num
77 write32 CONFIG_DEBUG_LED, \num
78.endm
79
80/*
81 * Waiting for SDRAM to set up
82 */
83.macro wait_sdram
84 li $r0, CONFIG_FTSDMC021_BASE
851:
86 lwi $r1, [$r0+FTSDMC021_CR2]
87 bnez $r1, 1b
88.endm
89
90#ifndef CONFIG_SKIP_LOWLEVEL_INIT
91.globl lowlevel_init
92lowlevel_init:
93 move $r10, $lp
94
95 led 0x0
96 jal mem_init
97
98 led 0x10
99 jal remap
100
101 led 0x20
102 ret $r10
103
104mem_init:
105 move $r11, $lp
106
107 /*
108 * mem_init:
109 * There are 2 bank connected to FTSMC020 on AG101
110 * BANK0: FLASH/ROM (SW5, J16), BANK1: OnBoard SDRAM.
111 * we need to set onboard SDRAM before remap and relocation.
112 */
113 led 0x01
114 write32 SMC_BANK0_CR_A, SMC_BANK0_CR_D ! 0x10000052
115 write32 SMC_BANK0_TPR_A, SMC_BANK0_TPR_D ! 0x00151151
116
117 /*
118 * config AHB Controller
119 */
120 led 0x02
121 write32 AHBC_BSR6_A, AHBC_BSR6_D
122
123 /*
124 * config PMU controller
125 */
126 /* ftpmu010_dlldis_disable, must do it in lowleve_init */
127 led 0x03
128 setbf32 PMU_PDLLCR0_A, FTPMU010_PDLLCR0_DLLDIS ! 0x00010000
129
130 /*
131 * config SDRAM controller
132 */
133 led 0x04
134 write32 SDMC_TP1_A, SDMC_TP1_D ! 0x00011312
135 led 0x05
136 write32 SDMC_TP2_A, SDMC_TP2_D ! 0x00480180
137 led 0x06
138 write32 SDMC_CR1_A, SDMC_CR1_D ! 0x00002326
139
140 led 0x07
141 write32 SDMC_CR2_A, FTSDMC021_CR2_IPREC ! 0x00000010
142 wait_sdram
143
144 led 0x08
145 write32 SDMC_CR2_A, FTSDMC021_CR2_ISMR ! 0x00000004
146 wait_sdram
147
148 led 0x09
149 write32 SDMC_CR2_A, FTSDMC021_CR2_IREF ! 0x00000008
150 wait_sdram
151
152 led 0x0a
153 move $lp, $r11
154 ret
155
156remap:
157 move $r11, $lp
158#ifdef __NDS32_N1213_43U1H__ /* NDS32 V0 ISA - AG101 Only */
159 bal 2f
160relo_base:
161 move $r0, $lp
162#else
163relo_base:
164 mfusr $r0, $pc
165#endif /* __NDS32_N1213_43U1H__ */
166
167 /*
168 * Remapping
169 */
170 led 0x1a
171 write32 SDMC_B0_BSR_A, SDMC_B0_BSR_D ! 0x00001100
ken kuo7abab272013-06-08 11:14:09 +0800172 write32 SDMC_B1_BSR_A, SDMC_B1_BSR_D ! 0x00001140
Macpaul Lin83dbca72011-10-11 22:33:18 +0000173
174 /* clear empty BSR registers */
175 led 0x1b
176 li $r4, CONFIG_FTSDMC021_BASE
177 li $r5, 0x0
Macpaul Lin83dbca72011-10-11 22:33:18 +0000178 swi $r5, [$r4 + FTSDMC021_BANK2_BSR]
179 swi $r5, [$r4 + FTSDMC021_BANK3_BSR]
180
181#ifdef CONFIG_MEM_REMAP
182 /*
183 * Copy ROM code to SDRAM base for memory remap layout.
184 * This is not the real relocation, the real relocation is the function
185 * relocate_code() is start.S which supports the systems is memory
186 * remapped or not.
187 */
188 /*
189 * Doing memory remap is essential for preparing some non-OS or RTOS
190 * applications.
191 *
192 * This is also a must on ADP-AG101 board.
193 * The reason is because the ROM/FLASH circuit on PCB board.
194 * AG101-A0 board has 2 jumpers MA17 and SW5 to configure which
195 * ROM/FLASH is used to boot.
196 *
197 * When SW5 = "0101", MA17 = LO, the ROM is connected to BANK0,
198 * and the FLASH is connected to BANK1.
199 * When SW5 = "1010", MA17 = HI, the ROM is disabled (still at BANK0),
200 * and the FLASH is connected to BANK0.
201 * It will occur problem when doing flash probing if the flash is at
202 * BANK0 (0x00000000) while memory remapping was skipped.
203 *
204 * Other board like ADP-AG101P may not enable this since there is only
205 * a FLASH connected to bank0.
206 */
207 led 0x11
208 li $r4, PHYS_SDRAM_0_AT_INIT /* 0x10000000 */
209 li $r5, 0x0
210 la $r1, relo_base /* get $pc or $lp */
211 sub $r2, $r0, $r1
212 sethi $r6, hi20(_end)
213 ori $r6, $r6, lo12(_end)
214 add $r6, $r6, $r2
2151:
216 lwi.p $r7, [$r5], #4
217 swi.p $r7, [$r4], #4
218 blt $r5, $r6, 1b
219
220 /* set remap bit */
221 /*
222 * MEM remap bit is operational
223 * - use it to map writeable memory at 0x00000000, in place of flash
224 * - before remap: flash/rom 0x00000000, sdram: 0x10000000-0x4fffffff
225 * - after remap: flash/rom 0x80000000, sdram: 0x00000000
226 */
227 led 0x1c
ken kuo7abab272013-06-08 11:14:09 +0800228 write32 SDMC_B0_BSR_A, 0x00001000
229 write32 SDMC_B1_BSR_A, 0x00001040
Macpaul Lin83dbca72011-10-11 22:33:18 +0000230 setbf15 AHBC_CR_A, FTAHBC020S_CR_REMAP ! 0x1
231
232#endif /* #ifdef CONFIG_MEM_REMAP */
233 move $lp, $r11
2342:
235 ret
236
237.globl show_led
238show_led:
239 li $r8, (CONFIG_DEBUG_LED)
240 swi $r7, [$r8]
241 ret
242#endif /* #ifndef CONFIG_SKIP_LOWLEVEL_INIT */