blob: 6565de8cfd0e21d703b17d02644cbddb89a1f997 [file] [log] [blame]
Aubrey Li65458982007-03-20 18:16:24 +08001/*
2 * U-boot - start.S Startup file of u-boot for BF533/BF561
3 *
Aubrey Li155fd762007-04-05 18:31:18 +08004 * Copyright (c) 2005-2007 Analog Devices Inc.
Aubrey Li65458982007-03-20 18:16:24 +08005 *
6 * This file is based on head.S
7 * Copyright (c) 2003 Metrowerks/Motorola
8 * Copyright (C) 1998 D. Jeff Dionne <jeff@ryeham.ee.ryerson.ca>,
9 * Kenneth Albanowski <kjahds@kjahds.com>,
10 * The Silver Hammer Group, Ltd.
11 * (c) 1995, Dionne & Associates
12 * (c) 1995, DKG Display Tech.
13 *
14 * See file CREDITS for list of people who contributed to this
15 * project.
16 *
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License as
19 * published by the Free Software Foundation; either version 2 of
20 * the License, or (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
Aubrey Li155fd762007-04-05 18:31:18 +080029 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
30 * MA 02110-1301 USA
Aubrey Li65458982007-03-20 18:16:24 +080031 */
32
33/*
34 * Note: A change in this file subsequently requires a change in
35 * board/$(board_name)/config.mk for a valid u-boot.bin
36 */
37
38#define ASSEMBLY
39
40#include <linux/config.h>
41#include <config.h>
42#include <asm/blackfin.h>
43
Mike Frysingerd4d77302008-02-04 19:26:55 -050044#include <asm/mach-common/bits/core.h>
45#include <asm/mach-common/bits/dma.h>
46#include <asm/mach-common/bits/pll.h>
47
Aubrey Li65458982007-03-20 18:16:24 +080048.global _stext;
49.global __bss_start;
50.global start;
51.global _start;
Aubrey Li65458982007-03-20 18:16:24 +080052.global edata;
Aubrey Li65458982007-03-20 18:16:24 +080053.global _exit;
Aubrey Li65458982007-03-20 18:16:24 +080054.global init_sdram;
55
56.text
57_start:
58start:
59_stext:
60
61 R0 = 0x32;
62 SYSCFG = R0;
63 SSYNC;
64
65 /*
66 * As per HW reference manual DAG registers,
67 * DATA and Address resgister shall be zero'd
68 * in initialization, after a reset state
69 */
70 r1 = 0; /* Data registers zero'd */
71 r2 = 0;
72 r3 = 0;
73 r4 = 0;
74 r5 = 0;
75 r6 = 0;
76 r7 = 0;
77
78 p0 = 0; /* Address registers zero'd */
79 p1 = 0;
80 p2 = 0;
81 p3 = 0;
82 p4 = 0;
83 p5 = 0;
84
85 i0 = 0; /* DAG Registers zero'd */
86 i1 = 0;
87 i2 = 0;
88 i3 = 0;
89 m0 = 0;
90 m1 = 0;
91 m3 = 0;
92 m3 = 0;
93 l0 = 0;
94 l1 = 0;
95 l2 = 0;
96 l3 = 0;
97 b0 = 0;
98 b1 = 0;
99 b2 = 0;
100 b3 = 0;
101
102 /*
103 * Set loop counters to zero, to make sure that
104 * hw loops are disabled.
105 */
106 r0 = 0;
107 lc0 = r0;
108 lc1 = r0;
109
110 SSYNC;
111
112 /* Check soft reset status */
113 p0.h = SWRST >> 16;
114 p0.l = SWRST & 0xFFFF;
115 r0.l = w[p0];
116
117 cc = bittst(r0, 15);
118 if !cc jump no_soft_reset;
119
120 /* Clear Soft reset */
121 r0 = 0x0000;
122 w[p0] = r0;
123 ssync;
124
125no_soft_reset:
126 nop;
127
128 /* Clear EVT registers */
Mike Frysingerd4d77302008-02-04 19:26:55 -0500129 p0.h = (EVT0 >> 16);
130 p0.l = (EVT0 & 0xFFFF);
Aubrey Li65458982007-03-20 18:16:24 +0800131 p0 += 8;
132 p1 = 14;
133 r1 = 0;
134 LSETUP(4,4) lc0 = p1;
135 [ p0 ++ ] = r1;
136
Mike Frysingerd4d77302008-02-04 19:26:55 -0500137 p0.h = hi(SICA_IWR0);
138 p0.l = lo(SICA_IWR0);
Aubrey Li65458982007-03-20 18:16:24 +0800139 r0.l = 0x1;
140 w[p0] = r0.l;
141 SSYNC;
142
143 sp.l = (0xffb01000 & 0xFFFF);
144 sp.h = (0xffb01000 >> 16);
145
146 /*
147 * Check if the code is in SDRAM
148 * If the code is in SDRAM, skip SDRAM initializaiton
149 */
150 call get_pc;
151 r3.l = 0x0;
152 r3.h = 0x2000;
153 cc = r0 < r3 (iu);
154 if cc jump sdram_initialized;
155 call init_sdram;
156 /* relocate into to RAM */
157sdram_initialized:
158 call get_pc;
159offset:
160 r2.l = offset;
161 r2.h = offset;
162 r3.l = start;
163 r3.h = start;
164 r1 = r2 - r3;
165
166 r0 = r0 - r1;
167 p1 = r0;
168
169 p2.l = (CFG_MONITOR_BASE & 0xffff);
170 p2.h = (CFG_MONITOR_BASE >> 16);
171
172 p3 = 0x04;
173 p4.l = ((CFG_MONITOR_BASE + CFG_MONITOR_LEN) & 0xffff);
174 p4.h = ((CFG_MONITOR_BASE + CFG_MONITOR_LEN) >> 16);
175loop1:
176 r1 = [p1 ++ p3];
177 [p2 ++ p3] = r1;
178 cc=p2==p4;
179 if !cc jump loop1;
180 /*
181 * configure STACK
182 */
183 r0.h = (CONFIG_STACKBASE >> 16);
184 r0.l = (CONFIG_STACKBASE & 0xFFFF);
185 sp = r0;
186 fp = sp;
187
188 /*
189 * This next section keeps the processor in supervisor mode
190 * during kernel boot. Switches to user mode at end of boot.
191 * See page 3-9 of Hardware Reference manual for documentation.
192 */
193
194 /* To keep ourselves in the supervisor mode */
Mike Frysingerd4d77302008-02-04 19:26:55 -0500195 p0.l = (EVT15 & 0xFFFF);
196 p0.h = (EVT15 >> 16);
Aubrey Li65458982007-03-20 18:16:24 +0800197
198 p1.l = _real_start;
199 p1.h = _real_start;
200 [p0] = p1;
201
202 p0.l = (IMASK & 0xFFFF);
203 p0.h = (IMASK >> 16);
Mike Frysingerd4d77302008-02-04 19:26:55 -0500204 r0.l = LO(EVT_IVG15);
205 r0.h = HI(EVT_IVG15);
Aubrey Li65458982007-03-20 18:16:24 +0800206 [p0] = r0;
207 raise 15;
208 p0.l = WAIT_HERE;
209 p0.h = WAIT_HERE;
210 reti = p0;
211 rti;
212
213WAIT_HERE:
214 jump WAIT_HERE;
215
216.global _real_start;
217_real_start:
218 [ -- sp ] = reti;
219
Aubrey Li65458982007-03-20 18:16:24 +0800220 /* DMA reset code to Hi of L1 SRAM */
221copy:
222 P1.H = hi(SYSMMR_BASE); /* P1 Points to the beginning of SYSTEM MMR Space */
223 P1.L = lo(SYSMMR_BASE);
224
225 R0.H = reset_start; /* Source Address (high) */
226 R0.L = reset_start; /* Source Address (low) */
227 R1.H = reset_end;
228 R1.L = reset_end;
229 R2 = R1 - R0; /* Count */
Mike Frysingerd4d77302008-02-04 19:26:55 -0500230 R1.H = hi(L1_INST_SRAM); /* Destination Address (high) */
231 R1.L = lo(L1_INST_SRAM); /* Destination Address (low) */
Aubrey Li65458982007-03-20 18:16:24 +0800232 R3.L = DMAEN; /* Source DMAConfig Value (8-bit words) */
233 R4.L = (DI_EN | WNR | DMAEN); /* Destination DMAConfig Value (8-bit words) */
234
235DMA:
236 R6 = 0x1 (Z);
Mike Frysingerd4d77302008-02-04 19:26:55 -0500237 W[P1+OFFSET_(IMDMA_S0_X_MODIFY)] = R6; /* Source Modify = 1 */
238 W[P1+OFFSET_(IMDMA_D0_X_MODIFY)] = R6; /* Destination Modify = 1 */
Aubrey Li65458982007-03-20 18:16:24 +0800239
Mike Frysingerd4d77302008-02-04 19:26:55 -0500240 [P1+OFFSET_(IMDMA_S0_START_ADDR)] = R0; /* Set Source Base Address */
241 W[P1+OFFSET_(IMDMA_S0_X_COUNT)] = R2; /* Set Source Count */
Aubrey Li65458982007-03-20 18:16:24 +0800242 /* Set Source DMAConfig = DMA Enable,
243 Memory Read, 8-Bit Transfers, 1-D DMA, Flow - Stop */
Mike Frysingerd4d77302008-02-04 19:26:55 -0500244 W[P1+OFFSET_(IMDMA_S0_CONFIG)] = R3;
Aubrey Li65458982007-03-20 18:16:24 +0800245
Mike Frysingerd4d77302008-02-04 19:26:55 -0500246 [P1+OFFSET_(IMDMA_D0_START_ADDR)] = R1; /* Set Destination Base Address */
247 W[P1+OFFSET_(IMDMA_D0_X_COUNT)] = R2; /* Set Destination Count */
Aubrey Li65458982007-03-20 18:16:24 +0800248 /* Set Destination DMAConfig = DMA Enable,
249 Memory Write, 8-Bit Transfers, 1-D DMA, Flow - Stop, IOC */
Mike Frysingerd4d77302008-02-04 19:26:55 -0500250 W[P1+OFFSET_(IMDMA_D0_CONFIG)] = R4;
Aubrey Li65458982007-03-20 18:16:24 +0800251
252WAIT_DMA_DONE:
Mike Frysingerd4d77302008-02-04 19:26:55 -0500253 p0.h = hi(IMDMA_D0_IRQ_STATUS);
254 p0.l = lo(IMDMA_D0_IRQ_STATUS);
Aubrey Li65458982007-03-20 18:16:24 +0800255 R0 = W[P0](Z);
256 CC = BITTST(R0, 0);
257 if ! CC jump WAIT_DMA_DONE
258
259 R0 = 0x1;
Mike Frysingerd4d77302008-02-04 19:26:55 -0500260 W[P1+OFFSET_(IMDMA_D0_IRQ_STATUS)] = R0; /* Write 1 to clear DMA interrupt */
Aubrey Li65458982007-03-20 18:16:24 +0800261
262 /* Initialize BSS Section with 0 s */
263 p1.l = __bss_start;
264 p1.h = __bss_start;
265 p2.l = _end;
266 p2.h = _end;
267 r1 = p1;
268 r2 = p2;
269 r3 = r2 - r1;
270 r3 = r3 >> 2;
271 p3 = r3;
272 lsetup (_clear_bss, _clear_bss_end ) lc1 = p3;
273 CC = p2<=p1;
274 if CC jump _clear_bss_skip;
275 r0 = 0;
276_clear_bss:
277_clear_bss_end:
278 [p1++] = r0;
279_clear_bss_skip:
280
281 p0.l = _start1;
282 p0.h = _start1;
283 jump (p0);
284
285reset_start:
286 p0.h = WDOG_CNT >> 16;
287 p0.l = WDOG_CNT & 0xffff;
288 r0 = 0x0010;
289 w[p0] = r0;
290 p0.h = WDOG_CTL >> 16;
291 p0.l = WDOG_CTL & 0xffff;
292 r0 = 0x0000;
293 w[p0] = r0;
294reset_wait:
295 jump reset_wait;
296
297reset_end: nop;
298
299_exit:
300 jump.s _exit;
301get_pc:
302 r0 = rets;
303 rts;