blob: 6b43b9d03af16431e9ddce0f536dfd5d5b266980 [file] [log] [blame]
Wolfgang Denk97caf672006-03-12 02:12:27 +01001/*
Aubrey.Li9da597f2007-03-09 13:38:44 +08002 * U-boot - start.S Startup file of u-boot for BF533/BF561
Wolfgang Denk97caf672006-03-12 02:12:27 +01003 *
Aubrey Li314d22f2007-04-05 18:31:18 +08004 * Copyright (c) 2005-2007 Analog Devices Inc.
Wolfgang Denk97caf672006-03-12 02:12:27 +01005 *
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 Li314d22f2007-04-05 18:31:18 +080029 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
30 * MA 02110-1301 USA
Wolfgang Denk97caf672006-03-12 02:12:27 +010031 */
32
33/*
34 * Note: A change in this file subsequently requires a change in
Aubrey Lif83a65c2007-03-10 23:49:29 +080035 * board/$(board_name)/config.mk for a valid u-boot.bin
Wolfgang Denk97caf672006-03-12 02:12:27 +010036 */
37
38#define ASSEMBLY
39
40#include <linux/config.h>
Wolfgang Denk97caf672006-03-12 02:12:27 +010041#include <config.h>
Aubrey.Li9da597f2007-03-09 13:38:44 +080042#include <asm/blackfin.h>
43
Mike Frysinger66c4cf42008-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.Li9da597f2007-03-09 13:38:44 +080048.global _stext;
49.global __bss_start;
50.global start;
51.global _start;
52.global _rambase;
53.global _ramstart;
54.global _ramend;
55.global _bf533_data_dest;
56.global _bf533_data_size;
57.global edata;
58.global _initialize;
59.global _exit;
60.global flashdataend;
61.global init_sdram;
Wolfgang Denk97caf672006-03-12 02:12:27 +010062
63#if (CONFIG_CCLK_DIV == 1)
64#define CONFIG_CCLK_ACT_DIV CCLK_DIV1
65#endif
66#if (CONFIG_CCLK_DIV == 2)
67#define CONFIG_CCLK_ACT_DIV CCLK_DIV2
68#endif
69#if (CONFIG_CCLK_DIV == 4)
70#define CONFIG_CCLK_ACT_DIV CCLK_DIV4
71#endif
72#if (CONFIG_CCLK_DIV == 8)
73#define CONFIG_CCLK_ACT_DIV CCLK_DIV8
74#endif
75#ifndef CONFIG_CCLK_ACT_DIV
76#define CONFIG_CCLK_ACT_DIV CONFIG_CCLK_DIV_not_defined_properly
77#endif
78
Wolfgang Denk97caf672006-03-12 02:12:27 +010079.text
80_start:
81start:
82_stext:
83
Aubrey.Li9da597f2007-03-09 13:38:44 +080084 R0 = 0x32;
Wolfgang Denk97caf672006-03-12 02:12:27 +010085 SYSCFG = R0;
86 SSYNC;
87
88 /* As per HW reference manual DAG registers,
Aubrey Li01c337f2007-03-12 12:11:55 +080089 * DATA and Address resgister shall be zero'd
Wolfgang Denk97caf672006-03-12 02:12:27 +010090 * in initialization, after a reset state
91 */
92 r1 = 0; /* Data registers zero'd */
93 r2 = 0;
94 r3 = 0;
95 r4 = 0;
96 r5 = 0;
97 r6 = 0;
98 r7 = 0;
99
100 p0 = 0; /* Address registers zero'd */
101 p1 = 0;
102 p2 = 0;
103 p3 = 0;
104 p4 = 0;
105 p5 = 0;
Aubrey Li01c337f2007-03-12 12:11:55 +0800106
Wolfgang Denk97caf672006-03-12 02:12:27 +0100107 i0 = 0; /* DAG Registers zero'd */
108 i1 = 0;
109 i2 = 0;
110 i3 = 0;
111 m0 = 0;
112 m1 = 0;
113 m3 = 0;
114 m3 = 0;
115 l0 = 0;
116 l1 = 0;
117 l2 = 0;
118 l3 = 0;
119 b0 = 0;
120 b1 = 0;
121 b2 = 0;
122 b3 = 0;
123
124 /* Set loop counters to zero, to make sure that
125 * hw loops are disabled.
126 */
Aubrey.Li9da597f2007-03-09 13:38:44 +0800127 r0 = 0;
128 lc0 = r0;
129 lc1 = r0;
Wolfgang Denk97caf672006-03-12 02:12:27 +0100130
131 SSYNC;
132
133 /* Check soft reset status */
134 p0.h = SWRST >> 16;
135 p0.l = SWRST & 0xFFFF;
136 r0.l = w[p0];
137
138 cc = bittst(r0, 15);
139 if !cc jump no_soft_reset;
140
141 /* Clear Soft reset */
142 r0 = 0x0000;
143 w[p0] = r0;
144 ssync;
145
146no_soft_reset:
147 nop;
148
149 /* Clear EVT registers */
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500150 p0.h = (EVT0 >> 16);
151 p0.l = (EVT0 & 0xFFFF);
Wolfgang Denk97caf672006-03-12 02:12:27 +0100152 p0 += 8;
153 p1 = 14;
154 r1 = 0;
155 LSETUP(4,4) lc0 = p1;
156 [ p0 ++ ] = r1;
Aubrey Li01c337f2007-03-12 12:11:55 +0800157
Aubrey.Li9da597f2007-03-09 13:38:44 +0800158 p0.h = hi(SIC_IWR);
Aubrey Lif83a65c2007-03-10 23:49:29 +0800159 p0.l = lo(SIC_IWR);
160 r0.l = 0x1;
161 w[p0] = r0.l;
162 SSYNC;
Wolfgang Denk97caf672006-03-12 02:12:27 +0100163
Aubrey.Li9da597f2007-03-09 13:38:44 +0800164 sp.l = (0xffb01000 & 0xFFFF);
165 sp.h = (0xffb01000 >> 16);
Wolfgang Denk97caf672006-03-12 02:12:27 +0100166
Aubrey.Li9da597f2007-03-09 13:38:44 +0800167 call init_sdram;
Wolfgang Denk97caf672006-03-12 02:12:27 +0100168
Aubrey.Li9da597f2007-03-09 13:38:44 +0800169 /* relocate into to RAM */
170 call get_pc;
171offset:
172 r2.l = offset;
173 r2.h = offset;
174 r3.l = start;
175 r3.h = start;
176 r1 = r2 - r3;
Wolfgang Denk97caf672006-03-12 02:12:27 +0100177
Aubrey.Li9da597f2007-03-09 13:38:44 +0800178 r0 = r0 - r1;
179 p1 = r0;
Wolfgang Denk97caf672006-03-12 02:12:27 +0100180
Wolfgang Denk97caf672006-03-12 02:12:27 +0100181 p2.l = (CFG_MONITOR_BASE & 0xffff);
182 p2.h = (CFG_MONITOR_BASE >> 16);
Aubrey.Li9da597f2007-03-09 13:38:44 +0800183
184 p3 = 0x04;
185 p4.l = ((CFG_MONITOR_BASE + CFG_MONITOR_LEN) & 0xffff);
186 p4.h = ((CFG_MONITOR_BASE + CFG_MONITOR_LEN) >> 16);
Wolfgang Denk97caf672006-03-12 02:12:27 +0100187loop1:
Aubrey.Li9da597f2007-03-09 13:38:44 +0800188 r1 = [p1 ++ p3];
189 [p2 ++ p3] = r1;
190 cc=p2==p4;
Wolfgang Denk97caf672006-03-12 02:12:27 +0100191 if !cc jump loop1;
Wolfgang Denk97caf672006-03-12 02:12:27 +0100192 /*
193 * configure STACK
194 */
195 r0.h = (CONFIG_STACKBASE >> 16);
196 r0.l = (CONFIG_STACKBASE & 0xFFFF);
197 sp = r0;
198 fp = sp;
199
200 /*
201 * This next section keeps the processor in supervisor mode
202 * during kernel boot. Switches to user mode at end of boot.
203 * See page 3-9 of Hardware Reference manual for documentation.
204 */
205
206 /* To keep ourselves in the supervisor mode */
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500207 p0.l = (EVT15 & 0xFFFF);
208 p0.h = (EVT15 >> 16);
Wolfgang Denk97caf672006-03-12 02:12:27 +0100209
210 p1.l = _real_start;
211 p1.h = _real_start;
212 [p0] = p1;
213
214 p0.l = (IMASK & 0xFFFF);
215 p0.h = (IMASK >> 16);
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500216 r0.l = LO(EVT_IVG15);
217 r0.h = HI(EVT_IVG15);
Wolfgang Denk97caf672006-03-12 02:12:27 +0100218 [p0] = r0;
219 raise 15;
220 p0.l = WAIT_HERE;
221 p0.h = WAIT_HERE;
222 reti = p0;
223 rti;
224
225WAIT_HERE:
226 jump WAIT_HERE;
227
228.global _real_start;
229_real_start:
230 [ -- sp ] = reti;
231
Wolfgang Denk97caf672006-03-12 02:12:27 +0100232 /* DMA reset code to Hi of L1 SRAM */
233copy:
Aubrey.Li9da597f2007-03-09 13:38:44 +0800234 /* P1 Points to the beginning of SYSTEM MMR Space */
235 P1.H = hi(SYSMMR_BASE);
Wolfgang Denk97caf672006-03-12 02:12:27 +0100236 P1.L = lo(SYSMMR_BASE);
237
238 R0.H = reset_start; /* Source Address (high) */
239 R0.L = reset_start; /* Source Address (low) */
240 R1.H = reset_end;
241 R1.L = reset_end;
242 R2 = R1 - R0; /* Count */
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500243 R1.H = hi(L1_INST_SRAM); /* Destination Address (high) */
244 R1.L = lo(L1_INST_SRAM); /* Destination Address (low) */
Wolfgang Denk97caf672006-03-12 02:12:27 +0100245 R3.L = DMAEN; /* Source DMAConfig Value (8-bit words) */
Aubrey.Li9da597f2007-03-09 13:38:44 +0800246 /* Destination DMAConfig Value (8-bit words) */
247 R4.L = (DI_EN | WNR | DMAEN);
Wolfgang Denk97caf672006-03-12 02:12:27 +0100248
249DMA:
250 R6 = 0x1 (Z);
251 W[P1+OFFSET_(MDMA_S0_X_MODIFY)] = R6; /* Source Modify = 1 */
252 W[P1+OFFSET_(MDMA_D0_X_MODIFY)] = R6; /* Destination Modify = 1 */
253
254 [P1+OFFSET_(MDMA_S0_START_ADDR)] = R0; /* Set Source Base Address */
255 W[P1+OFFSET_(MDMA_S0_X_COUNT)] = R2; /* Set Source Count */
256 /* Set Source DMAConfig = DMA Enable,
257 Memory Read, 8-Bit Transfers, 1-D DMA, Flow - Stop */
258 W[P1+OFFSET_(MDMA_S0_CONFIG)] = R3;
259
Aubrey.Li9da597f2007-03-09 13:38:44 +0800260 /* Set Destination Base Address */
261 [P1+OFFSET_(MDMA_D0_START_ADDR)] = R1;
Wolfgang Denk97caf672006-03-12 02:12:27 +0100262 W[P1+OFFSET_(MDMA_D0_X_COUNT)] = R2; /* Set Destination Count */
263 /* Set Destination DMAConfig = DMA Enable,
264 Memory Write, 8-Bit Transfers, 1-D DMA, Flow - Stop, IOC */
265 W[P1+OFFSET_(MDMA_D0_CONFIG)] = R4;
Aubrey Li01c337f2007-03-12 12:11:55 +0800266
267WAIT_DMA_DONE:
Aubrey.Li9da597f2007-03-09 13:38:44 +0800268 p0.h = hi(MDMA_D0_IRQ_STATUS);
269 p0.l = lo(MDMA_D0_IRQ_STATUS);
270 R0 = W[P0](Z);
271 CC = BITTST(R0, 0);
272 if ! CC jump WAIT_DMA_DONE
Wolfgang Denk97caf672006-03-12 02:12:27 +0100273
274 R0 = 0x1;
Wolfgang Denk97caf672006-03-12 02:12:27 +0100275
Aubrey.Li9da597f2007-03-09 13:38:44 +0800276 /* Write 1 to clear DMA interrupt */
277 W[P1+OFFSET_(MDMA_D0_IRQ_STATUS)] = R0;
Wolfgang Denk97caf672006-03-12 02:12:27 +0100278
279 /* Initialize BSS Section with 0 s */
280 p1.l = __bss_start;
281 p1.h = __bss_start;
282 p2.l = _end;
283 p2.h = _end;
284 r1 = p1;
285 r2 = p2;
286 r3 = r2 - r1;
287 r3 = r3 >> 2;
288 p3 = r3;
289 lsetup (_clear_bss, _clear_bss_end ) lc1 = p3;
290 CC = p2<=p1;
291 if CC jump _clear_bss_skip;
292 r0 = 0;
293_clear_bss:
294_clear_bss_end:
295 [p1++] = r0;
296_clear_bss_skip:
297
298 p0.l = _start1;
299 p0.h = _start1;
300 jump (p0);
301
302reset_start:
303 p0.h = WDOG_CNT >> 16;
304 p0.l = WDOG_CNT & 0xffff;
305 r0 = 0x0010;
306 w[p0] = r0;
307 p0.h = WDOG_CTL >> 16;
308 p0.l = WDOG_CTL & 0xffff;
309 r0 = 0x0000;
310 w[p0] = r0;
311reset_wait:
312 jump reset_wait;
313
314reset_end: nop;
315
316_exit:
317 jump.s _exit;
Aubrey.Li9da597f2007-03-09 13:38:44 +0800318get_pc:
319 r0 = rets;
320 rts;