blob: 238410dde44facbd4fb0cc6eac84227c0e9b56a4 [file] [log] [blame]
Macpaul Lin64715562011-09-23 17:03:19 +08001/*
2 * Copyright (C) 2011 Andes Technology Corporation
3 * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com>
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Macpaul Lin64715562011-09-23 17:03:19 +08006 */
7
8.text
9
10#include <common.h>
11#include <config.h>
12
13#include <asm/macro.h>
14#include <generated/asm-offsets.h>
15
16/*
17 * parameters for Synopsys DWC DDR2/DDR1 Memory Controller
18 */
19#define DDR2C_BASE_A (CONFIG_DWCDDR21MCTL_BASE)
20#define DDR2C_CCR_A (DDR2C_BASE_A + DWCDDR21MCTL_CCR)
21#define DDR2C_DCR_A (DDR2C_BASE_A + DWCDDR21MCTL_DCR)
22#define DDR2C_IOCR_A (DDR2C_BASE_A + DWCDDR21MCTL_IOCR)
23#define DDR2C_CSR_A (DDR2C_BASE_A + DWCDDR21MCTL_CSR)
24#define DDR2C_DRR_A (DDR2C_BASE_A + DWCDDR21MCTL_DRR)
25#define DDR2C_DLLCR0_A (DDR2C_BASE_A + DWCDDR21MCTL_DLLCR0)
26#define DDR2C_DLLCR1_A (DDR2C_BASE_A + DWCDDR21MCTL_DLLCR1)
27#define DDR2C_DLLCR2_A (DDR2C_BASE_A + DWCDDR21MCTL_DLLCR2)
28#define DDR2C_DLLCR3_A (DDR2C_BASE_A + DWCDDR21MCTL_DLLCR3)
29#define DDR2C_DLLCR4_A (DDR2C_BASE_A + DWCDDR21MCTL_DLLCR4)
30#define DDR2C_DLLCR5_A (DDR2C_BASE_A + DWCDDR21MCTL_DLLCR5)
31#define DDR2C_DLLCR6_A (DDR2C_BASE_A + DWCDDR21MCTL_DLLCR6)
32#define DDR2C_DLLCR7_A (DDR2C_BASE_A + DWCDDR21MCTL_DLLCR7)
33#define DDR2C_DLLCR8_A (DDR2C_BASE_A + DWCDDR21MCTL_DLLCR8)
34#define DDR2C_DLLCR9_A (DDR2C_BASE_A + DWCDDR21MCTL_DLLCR9)
35#define DDR2C_RSLR0_A (DDR2C_BASE_A + DWCDDR21MCTL_RSLR0)
36#define DDR2C_RDGR0_A (DDR2C_BASE_A + DWCDDR21MCTL_RDGR0)
37#define DDR2C_DTAR_A (DDR2C_BASE_A + DWCDDR21MCTL_DTAR)
38#define DDR2C_MR_A (DDR2C_BASE_A + DWCDDR21MCTL_MR)
39
40#define DDR2C_CCR_D CONFIG_SYS_DWCDDR21MCTL_CCR
41#define DDR2C_CCR_D2 CONFIG_SYS_DWCDDR21MCTL_CCR2
42#define DDR2C_DCR_D CONFIG_SYS_DWCDDR21MCTL_DCR
43#define DDR2C_IOCR_D CONFIG_SYS_DWCDDR21MCTL_IOCR
44#define DDR2C_CSR_D CONFIG_SYS_DWCDDR21MCTL_CSR
45#define DDR2C_DRR_D CONFIG_SYS_DWCDDR21MCTL_DRR
46#define DDR2C_RSLR0_D CONFIG_SYS_DWCDDR21MCTL_RSLR0
47#define DDR2C_RDGR0_D CONFIG_SYS_DWCDDR21MCTL_RDGR0
48#define DDR2C_DTAR_D CONFIG_SYS_DWCDDR21MCTL_DTAR
49#define DDR2C_MR_D CONFIG_SYS_DWCDDR21MCTL_MR
50
51#define DDR2C_DLLCR0_D CONFIG_SYS_DWCDDR21MCTL_DLLCR0 /* 0-9 are same */
52
53/*
54 * parameters for the ahbc controller
55 */
56#define AHBC_CR_A (CONFIG_FTAHBC020S_BASE + FTAHBC020S_CR)
57#define AHBC_BSR6_A (CONFIG_FTAHBC020S_BASE + FTAHBC020S_SLAVE_BSR_6)
58
59#define AHBC_BSR6_D CONFIG_SYS_FTAHBC020S_SLAVE_BSR_6
60
61/*
62 * parameters for the ANDES PCU controller
63 */
64#define PCU_PCS4_A (CONFIG_ANDES_PCU_BASE + ANDES_PCU_PCS4)
65#define PCU_PCS4_D CONFIG_SYS_ANDES_CPU_PCS4
66
67/*
68 * numeric 7 segment display
69 */
70.macro led, num
71 write32 CONFIG_DEBUG_LED, \num
72.endm
73
74/*
75 * Waiting for SDRAM to set up
76 */
77/*
78.macro wait_sdram
79 li $r0, DDR2C_CSR_A
801:
81 lwi $r1, [$r0+FTSDMC021_CR2]
82 bnez $r1, 1b
83.endm
84*/
85
86#ifndef CONFIG_SKIP_LOWLEVEL_INIT
87.globl lowlevel_init
88lowlevel_init:
89 move $r10, $lp
90
91 /* U200 */
92! led 0x00
93! jal scale_to_500mhz
94
95 led 0x10
96 jal mem_init
97
98 led 0x20
99 jal remap
100
ken kuob69fa0d2013-07-25 02:17:11 +0800101#if (defined(NDS32_EXT_FPU_DP) || defined(NDS32_EXT_FPU_SP))
102 led 0x2f
103 jal enable_fpu
104#endif
105
Macpaul Lin64715562011-09-23 17:03:19 +0800106 led 0x30
107 ret $r10
108
109scale_to_500mhz:
110 move $r11, $lp
111
112 /*
113 * scale to 500Mhz
114 */
115 led 0x01
116 write32 PCU_PCS4_A, 0x1102000f ! save data to PCS4
117
118 move $lp, $r11
119 ret
120
121mem_init:
122 move $r11, $lp
123
124 /*
125 * config AHB Controller
126 */
127 led 0x12
128 write32 AHBC_BSR6_A, AHBC_BSR6_D
129
130 /*
131 * config Synopsys DWC DDR2/DDR1 Memory Controller
132 */
133ddr2c_init:
134set_dcr:
135 led 0x14
136 write32 DDR2C_DCR_A, DDR2C_DCR_D ! 0x000020d4
137
138auto_sizing:
139 /*
140 * ebios: $r10->$r7, $r11->$r8, $r12->$r9, $r13->$r12, $r14->$r13
141 */
142set_iocr:
143 led 0x19
144 write32 DDR2C_IOCR_A, DDR2C_IOCR_D
145set_drr:
146 led 0x16
147 write32 DDR2C_DRR_A, DDR2C_DRR_D ! 0x00034812
148set_dllcr:
149 led 0x18
150 write32 DDR2C_DLLCR0_A, DDR2C_DLLCR0_D
151 write32 DDR2C_DLLCR1_A, DDR2C_DLLCR0_D
152 write32 DDR2C_DLLCR2_A, DDR2C_DLLCR0_D
153 write32 DDR2C_DLLCR3_A, DDR2C_DLLCR0_D
154 write32 DDR2C_DLLCR4_A, DDR2C_DLLCR0_D
155 write32 DDR2C_DLLCR5_A, DDR2C_DLLCR0_D
156 write32 DDR2C_DLLCR6_A, DDR2C_DLLCR0_D
157 write32 DDR2C_DLLCR7_A, DDR2C_DLLCR0_D
158 write32 DDR2C_DLLCR8_A, DDR2C_DLLCR0_D
159 write32 DDR2C_DLLCR9_A, DDR2C_DLLCR0_D
160set_rslr0:
161 write32 DDR2C_RSLR0_A, DDR2C_RSLR0_D ! 0x00000040
162set_rdgr0:
163 write32 DDR2C_RDGR0_A, DDR2C_RDGR0_D ! 0x000055cf
164set_dtar:
165 led 0x15
166 write32 DDR2C_DTAR_A, DDR2C_DTAR_D ! 0x00100000
167set_mode:
168 led 0x17
169 write32 DDR2C_MR_A, DDR2C_MR_D ! 0x00000852
170set_ccr:
171 write32 DDR2C_CCR_A, DDR2C_CCR_D
172
173#ifdef TRIGGER_INIT:
174trigger_init:
175 write32 DDR2C_CCR_A, DDR2C_CCR_D ! 0x80020000
176
177 /* Wait for ddr init state to be set */
178 msync ALL
179 isb
180
181 /* Wait until the config initialization is finish */
1821:
183 la $r4, DDR2C_CSR_A
184 lwi $r5, [$r4]
185 srli $r5, $r5, 23
186 bnez $r5, 1b
187#endif
188
189data_training:
190! write32 DDR2C_CCR_A, DDR2C_CCR_D2 ! 0x40020004
191
192 /* Wait for ddr init state to be set */
193 msync ALL
194 isb
195
196 /* wait until the ddr data trainning is complete */
1971:
198 la $r4, DDR2C_CSR_A
199 lwi $r5, [$r4]
200 srli $r6, $r5, 23
201 bnez $r6, 1b
202
203 lwi $r1, [$r4]
204 srli $r6, $r5, 20
205 li $r5, 0x00ffffff
206 swi $r1, [$r4]
207 bnez $r6, ddr2c_init
208
209 led 0x1a
210 move $lp, $r11
211 ret
212
213remap:
214 move $r11, $lp
215#ifdef __NDS32_N1213_43U1H__ /* NDS32 V0 ISA - AG101 Only */
216 bal 2f
217relo_base:
218 move $r0, $lp
219#else
220relo_base:
221 mfusr $r0, $pc
222#endif /* __NDS32_N1213_43U1H__ */
223
224 /*
225 * Remapping
226 */
227#ifdef CONFIG_MEM_REMAP
228 /*
229 * Copy ROM code to SDRAM base for memory remap layout.
230 * This is not the real relocation, the real relocation is the function
231 * relocate_code() is start.S which supports the systems is memory
232 * remapped or not.
233 */
234 /*
235 * Doing memory remap is essential for preparing some non-OS or RTOS
236 * applications.
237 *
238 * This is also a must on ADP-AG101 board.
239 * The reason is because the ROM/FLASH circuit on PCB board.
240 * AG101-A0 board has 2 jumpers MA17 and SW5 to configure which
241 * ROM/FLASH is used to boot.
242 *
243 * When SW5 = "0101", MA17 = LO, the ROM is connected to BANK0,
244 * and the FLASH is connected to BANK1.
245 * When SW5 = "1010", MA17 = HI, the ROM is disabled (still at BANK0),
246 * and the FLASH is connected to BANK0.
247 * It will occur problem when doing flash probing if the flash is at
248 * BANK0 (0x00000000) while memory remapping was skipped.
249 *
250 * Other board like ADP-AG101P may not enable this since there is only
251 * a FLASH connected to bank0.
252 */
253 led 0x21
254 li $r4, PHYS_SDRAM_0_AT_INIT /* 0x10000000 */
255 li $r5, 0x0
256 la $r1, relo_base /* get $pc or $lp */
257 sub $r2, $r0, $r1
258 sethi $r6, hi20(_end)
259 ori $r6, $r6, lo12(_end)
260 add $r6, $r6, $r2
2611:
262 lwi.p $r7, [$r5], #4
263 swi.p $r7, [$r4], #4
264 blt $r5, $r6, 1b
265
266 /* set remap bit */
267 /*
268 * MEM remap bit is operational
269 * - use it to map writeable memory at 0x00000000, in place of flash
270 * - before remap: flash/rom 0x00000000, sdram: 0x10000000-0x4fffffff
271 * - after remap: flash/rom 0x80000000, sdram: 0x00000000
272 */
273 led 0x2c
274 setbf15 AHBC_CR_A, FTAHBC020S_CR_REMAP ! 0x1
275
276#endif /* #ifdef CONFIG_MEM_REMAP */
277 move $lp, $r11
2782:
279 ret
ken kuob69fa0d2013-07-25 02:17:11 +0800280
281 /*
282 * enable_fpu:
283 * Some of Andes CPU version support FPU coprocessor, if so,
284 * and toolchain support FPU instruction set, we should enable it.
285 */
286#if (defined(NDS32_EXT_FPU_DP) || defined(NDS32_EXT_FPU_SP))
287enable_fpu:
288 mfsr $r0, $CPU_VER /* enable FPU if it exists */
289 srli $r0, $r0, 3
290 andi $r0, $r0, 1
291 beqz $r0, 1f /* skip if no COP */
292 mfsr $r0, $FUCOP_EXIST
293 srli $r0, $r0, 31
294 beqz $r0, 1f /* skip if no FPU */
295 mfsr $r0, $FUCOP_CTL
296 ori $r0, $r0, 1
297 mtsr $r0, $FUCOP_CTL
2981:
299 ret
300#endif
Macpaul Lin64715562011-09-23 17:03:19 +0800301
302.globl show_led
303show_led:
304 li $r8, (CONFIG_DEBUG_LED)
305 swi $r7, [$r8]
306 ret
307#endif /* #ifndef CONFIG_SKIP_LOWLEVEL_INIT */