punt Blackfin VDSP headers and import sanitized/auto-generated ones
[oweals/u-boot.git] / cpu / bf533 / start.S
1 /*
2  * U-boot - start.S Startup file of u-boot for BF533/BF561
3  *
4  * Copyright (c) 2005-2007 Analog Devices Inc.
5  *
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
29  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
30  * MA 02110-1301 USA
31  */
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
44 #include <asm/mach-common/bits/core.h>
45 #include <asm/mach-common/bits/dma.h>
46 #include <asm/mach-common/bits/pll.h>
47
48 .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;
62
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
79 .text
80 _start:
81 start:
82 _stext:
83
84         R0 = 0x32;
85         SYSCFG = R0;
86         SSYNC;
87
88         /* As per HW reference manual DAG registers,
89          * DATA and Address resgister shall be zero'd
90          * 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;
106
107         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          */
127         r0  = 0;
128         lc0 = r0;
129         lc1 = r0;
130
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
146 no_soft_reset:
147         nop;
148
149         /* Clear EVT registers */
150         p0.h = (EVT0 >> 16);
151         p0.l = (EVT0 & 0xFFFF);
152         p0 += 8;
153         p1 = 14;
154         r1 = 0;
155         LSETUP(4,4) lc0 = p1;
156         [ p0 ++ ] = r1;
157
158         p0.h = hi(SIC_IWR);
159         p0.l = lo(SIC_IWR);
160         r0.l = 0x1;
161         w[p0] = r0.l;
162         SSYNC;
163
164         sp.l = (0xffb01000 & 0xFFFF);
165         sp.h = (0xffb01000 >> 16);
166
167         call init_sdram;
168
169         /* relocate into to RAM */
170         call get_pc;
171 offset:
172         r2.l = offset;
173         r2.h = offset;
174         r3.l = start;
175         r3.h = start;
176         r1 = r2 - r3;
177
178         r0 = r0 - r1;
179         p1 = r0;
180
181         p2.l = (CFG_MONITOR_BASE & 0xffff);
182         p2.h = (CFG_MONITOR_BASE >> 16);
183
184         p3 = 0x04;
185         p4.l = ((CFG_MONITOR_BASE + CFG_MONITOR_LEN) & 0xffff);
186         p4.h = ((CFG_MONITOR_BASE + CFG_MONITOR_LEN) >> 16);
187 loop1:
188         r1 = [p1 ++ p3];
189         [p2 ++ p3] = r1;
190         cc=p2==p4;
191         if !cc jump loop1;
192         /*
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 */
207         p0.l = (EVT15 & 0xFFFF);
208         p0.h = (EVT15 >> 16);
209
210         p1.l = _real_start;
211         p1.h = _real_start;
212         [p0] = p1;
213
214         p0.l = (IMASK & 0xFFFF);
215         p0.h = (IMASK >> 16);
216         r0.l = LO(EVT_IVG15);
217         r0.h = HI(EVT_IVG15);
218         [p0] = r0;
219         raise 15;
220         p0.l = WAIT_HERE;
221         p0.h = WAIT_HERE;
222         reti = p0;
223         rti;
224
225 WAIT_HERE:
226         jump WAIT_HERE;
227
228 .global _real_start;
229 _real_start:
230         [ -- sp ] = reti;
231
232         /* DMA reset code to Hi of L1 SRAM */
233 copy:
234         /* P1 Points to the beginning of SYSTEM MMR Space */
235         P1.H = hi(SYSMMR_BASE);
236         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 */
243         R1.H = hi(L1_INST_SRAM);        /* Destination Address (high) */
244         R1.L = lo(L1_INST_SRAM);        /* Destination Address (low) */
245         R3.L = DMAEN;           /* Source DMAConfig Value (8-bit words) */
246         /* Destination DMAConfig Value (8-bit words) */
247         R4.L = (DI_EN | WNR | DMAEN);
248
249 DMA:
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
260         /* Set Destination Base Address */
261         [P1+OFFSET_(MDMA_D0_START_ADDR)] = R1;
262         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;
266
267 WAIT_DMA_DONE:
268         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
273
274         R0 = 0x1;
275
276         /* Write 1 to clear DMA interrupt */
277         W[P1+OFFSET_(MDMA_D0_IRQ_STATUS)] = R0;
278
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
302 reset_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;
311 reset_wait:
312         jump reset_wait;
313
314 reset_end: nop;
315
316 _exit:
317         jump.s  _exit;
318 get_pc:
319         r0 = rets;
320         rts;