blob: a48f3c6c7bd2c6696ea913724a2e87023d2fd01f [file] [log] [blame]
Aubrey Li26bf7de2007-03-19 01:24:52 +08001/*
2 * U-boot - start.S Startup file of u-boot for BF537
3 *
Aubrey Li155fd762007-04-05 18:31:18 +08004 * Copyright (c) 2005-2007 Analog Devices Inc.
Aubrey Li26bf7de2007-03-19 01:24:52 +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 Li26bf7de2007-03-19 01:24:52 +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 Li26bf7de2007-03-19 01:24:52 +080048.global _stext;
49.global __bss_start;
50.global start;
51.global _start;
Aubrey Li26bf7de2007-03-19 01:24:52 +080052.global edata;
Aubrey Li26bf7de2007-03-19 01:24:52 +080053.global _exit;
Aubrey Li26bf7de2007-03-19 01:24:52 +080054.global init_sdram;
55.global _icache_enable;
56.global _dcache_enable;
57#if defined(CONFIG_BF537)&&defined(CONFIG_POST)
58.global _memory_post_test;
59.global _post_flag;
60#endif
61
62#if (BFIN_BOOT_MODE == BF537_UART_BOOT)
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#endif
79
80.text
81_start:
82start:
83_stext:
84
85 R0 = 0x32;
86 SYSCFG = R0;
87 SSYNC;
88
89 /* As per HW reference manual DAG registers,
90 * DATA and Address resgister shall be zero'd
91 * in initialization, after a reset state
92 */
93 r1 = 0; /* Data registers zero'd */
94 r2 = 0;
95 r3 = 0;
96 r4 = 0;
97 r5 = 0;
98 r6 = 0;
99 r7 = 0;
100
101 p0 = 0; /* Address registers zero'd */
102 p1 = 0;
103 p2 = 0;
104 p3 = 0;
105 p4 = 0;
106 p5 = 0;
107
108 i0 = 0; /* DAG Registers zero'd */
109 i1 = 0;
110 i2 = 0;
111 i3 = 0;
112 m0 = 0;
113 m1 = 0;
114 m3 = 0;
115 m3 = 0;
116 l0 = 0;
117 l1 = 0;
118 l2 = 0;
119 l3 = 0;
120 b0 = 0;
121 b1 = 0;
122 b2 = 0;
123 b3 = 0;
124
125 /* Set loop counters to zero, to make sure that
126 * hw loops are disabled.
127 */
128 r0 = 0;
129 lc0 = r0;
130 lc1 = r0;
131
132 SSYNC;
133
134 /* Check soft reset status */
135 p0.h = SWRST >> 16;
136 p0.l = SWRST & 0xFFFF;
137 r0.l = w[p0];
138
139 cc = bittst(r0, 15);
140 if !cc jump no_soft_reset;
141
142 /* Clear Soft reset */
143 r0 = 0x0000;
144 w[p0] = r0;
145 ssync;
146
147no_soft_reset:
148 nop;
149
150 /* Clear EVT registers */
Mike Frysingerd4d77302008-02-04 19:26:55 -0500151 p0.h = (EVT0 >> 16);
152 p0.l = (EVT0 & 0xFFFF);
Aubrey Li26bf7de2007-03-19 01:24:52 +0800153 p0 += 8;
154 p1 = 14;
155 r1 = 0;
156 LSETUP(4,4) lc0 = p1;
157 [ p0 ++ ] = r1;
158
159#if (BFIN_BOOT_MODE != BF537_SPI_MASTER_BOOT)
160 p0.h = hi(SIC_IWR);
161 p0.l = lo(SIC_IWR);
162 r0.l = 0x1;
163 w[p0] = r0.l;
164 SSYNC;
165#endif
166
167#if (BFIN_BOOT_MODE == BF537_UART_BOOT)
168
169 p0.h = hi(SIC_IWR);
170 p0.l = lo(SIC_IWR);
171 r0.l = 0x1;
172 w[p0] = r0.l;
173 SSYNC;
174
175 /*
176 * PLL_LOCKCNT - how many SCLK Cycles to delay while PLL becomes stable
177 */
178 p0.h = hi(PLL_LOCKCNT);
179 p0.l = lo(PLL_LOCKCNT);
180 r0 = 0x300(Z);
181 w[p0] = r0.l;
182 ssync;
183
184 /*
185 * Put SDRAM in self-refresh, incase anything is running
186 */
187 P2.H = hi(EBIU_SDGCTL);
188 P2.L = lo(EBIU_SDGCTL);
189 R0 = [P2];
190 BITSET (R0, 24);
191 [P2] = R0;
192 SSYNC;
193
194 /*
195 * Set PLL_CTL with the value that we calculate in R0
196 * - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors
197 * - [8] = BYPASS : BYPASS the PLL, run CLKIN into CCLK/SCLK
198 * - [7] = output delay (add 200ps of delay to mem signals)
199 * - [6] = input delay (add 200ps of input delay to mem signals)
200 * - [5] = PDWN : 1=All Clocks off
201 * - [3] = STOPCK : 1=Core Clock off
202 * - [1] = PLL_OFF : 1=Disable Power to PLL
203 * - [0] = DF : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL
204 * all other bits set to zero
205 */
206
207 r0 = CONFIG_VCO_MULT & 63; /* Load the VCO multiplier */
208 r0 = r0 << 9; /* Shift it over, */
209 r1 = CONFIG_CLKIN_HALF; /* Do we need to divide CLKIN by 2?*/
210 r0 = r1 | r0;
211 r1 = CONFIG_PLL_BYPASS; /* Bypass the PLL? */
212 r1 = r1 << 8; /* Shift it over */
213 r0 = r1 | r0; /* add them all together */
214
215 p0.h = hi(PLL_CTL);
216 p0.l = lo(PLL_CTL); /* Load the address */
217 cli r2; /* Disable interrupts */
218 ssync;
219 w[p0] = r0.l; /* Set the value */
220 idle; /* Wait for the PLL to stablize */
221 sti r2; /* Enable interrupts */
222
223check_again:
224 p0.h = hi(PLL_STAT);
225 p0.l = lo(PLL_STAT);
226 R0 = W[P0](Z);
227 CC = BITTST(R0,5);
228 if ! CC jump check_again;
229
230 /* Configure SCLK & CCLK Dividers */
231 r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
232 p0.h = hi(PLL_DIV);
233 p0.l = lo(PLL_DIV);
234 w[p0] = r0.l;
235 ssync;
236#endif
237
238 /*
239 * We now are running at speed, time to set the Async mem bank wait states
240 * This will speed up execution, since we are normally running from FLASH.
241 * we need to read MAC address from FLASH
242 */
243 p2.h = (EBIU_AMBCTL1 >> 16);
244 p2.l = (EBIU_AMBCTL1 & 0xFFFF);
245 r0.h = (AMBCTL1VAL >> 16);
246 r0.l = (AMBCTL1VAL & 0xFFFF);
247 [p2] = r0;
248 ssync;
249
250 p2.h = (EBIU_AMBCTL0 >> 16);
251 p2.l = (EBIU_AMBCTL0 & 0xFFFF);
252 r0.h = (AMBCTL0VAL >> 16);
253 r0.l = (AMBCTL0VAL & 0xFFFF);
254 [p2] = r0;
255 ssync;
256
257 p2.h = (EBIU_AMGCTL >> 16);
258 p2.l = (EBIU_AMGCTL & 0xffff);
259 r0 = AMGCTLVAL;
260 w[p2] = r0;
261 ssync;
262
263#if ((BFIN_BOOT_MODE != BF537_SPI_MASTER_BOOT) && (BFIN_BOOT_MODE != BF537_UART_BOOT))
264 sp.l = (0xffb01000 & 0xFFFF);
265 sp.h = (0xffb01000 >> 16);
266
267 call init_sdram;
268#endif
269
270
271#if defined(CONFIG_BF537)&&defined(CONFIG_POST)
272 /* DMA POST code to Hi of L1 SRAM */
273postcopy:
274 /* P1 Points to the beginning of SYSTEM MMR Space */
275 P1.H = hi(SYSMMR_BASE);
276 P1.L = lo(SYSMMR_BASE);
277
278 R0.H = _text_l1;
279 R0.L = _text_l1;
280 R1.H = _etext_l1;
281 R1.L = _etext_l1;
282 R2 = R1 - R0; /* Count */
283 R0.H = _etext;
284 R0.L = _etext;
285 R1.H = (CFG_MONITOR_BASE >> 16);
286 R1.L = (CFG_MONITOR_BASE & 0xFFFF);
287 R0 = R0 - R1;
288 R1.H = (CFG_FLASH_BASE >> 16);
289 R1.L = (CFG_FLASH_BASE & 0xFFFF);
290 R0 = R0 + R1; /* Source Address */
Mike Frysingerd4d77302008-02-04 19:26:55 -0500291 R1.H = hi(L1_INST_SRAM); /* Destination Address (high) */
292 R1.L = lo(L1_INST_SRAM); /* Destination Address (low) */
Aubrey Li26bf7de2007-03-19 01:24:52 +0800293 R3.L = DMAEN; /* Source DMAConfig Value (8-bit words) */
294 /* Destination DMAConfig Value (8-bit words) */
295 R4.L = (DI_EN | WNR | DMAEN);
296
297 R6 = 0x1 (Z);
298 W[P1+OFFSET_(MDMA_S0_X_MODIFY)] = R6; /* Source Modify = 1 */
299 W[P1+OFFSET_(MDMA_D0_X_MODIFY)] = R6; /* Destination Modify = 1 */
300
301 [P1+OFFSET_(MDMA_S0_START_ADDR)] = R0; /* Set Source Base Address */
302 W[P1+OFFSET_(MDMA_S0_X_COUNT)] = R2; /* Set Source Count */
303 /* Set Source DMAConfig = DMA Enable,
304 Memory Read, 8-Bit Transfers, 1-D DMA, Flow - Stop */
305 W[P1+OFFSET_(MDMA_S0_CONFIG)] = R3;
306
307 [P1+OFFSET_(MDMA_D0_START_ADDR)] = R1; /* Set Destination Base Address */
308 W[P1+OFFSET_(MDMA_D0_X_COUNT)] = R2; /* Set Destination Count */
309 /* Set Destination DMAConfig = DMA Enable,
310 Memory Write, 8-Bit Transfers, 1-D DMA, Flow - Stop, IOC */
311 W[P1+OFFSET_(MDMA_D0_CONFIG)] = R4;
312
313POST_DMA_DONE:
314 p0.h = hi(MDMA_D0_IRQ_STATUS);
315 p0.l = lo(MDMA_D0_IRQ_STATUS);
316 R0 = W[P0](Z);
317 CC = BITTST(R0, 0);
318 if ! CC jump POST_DMA_DONE
319
320 R0 = 0x1;
321 W[P1+OFFSET_(MDMA_D0_IRQ_STATUS)] = R0; /* Write 1 to clear DMA interrupt */
322
323 /* DMA POST data to Hi of L1 SRAM */
324 R0.H = _rodata_l1;
325 R0.L = _rodata_l1;
326 R1.H = _erodata_l1;
327 R1.L = _erodata_l1;
328 R2 = R1 - R0; /* Count */
329 R0.H = _erodata;
330 R0.L = _erodata;
331 R1.H = (CFG_MONITOR_BASE >> 16);
332 R1.L = (CFG_MONITOR_BASE & 0xFFFF);
333 R0 = R0 - R1;
334 R1.H = (CFG_FLASH_BASE >> 16);
335 R1.L = (CFG_FLASH_BASE & 0xFFFF);
336 R0 = R0 + R1; /* Source Address */
337 R1.H = hi(DATA_BANKB_SRAM); /* Destination Address (high) */
338 R1.L = lo(DATA_BANKB_SRAM); /* Destination Address (low) */
339 R3.L = DMAEN; /* Source DMAConfig Value (8-bit words) */
340 R4.L = (DI_EN | WNR | DMAEN); /* Destination DMAConfig Value (8-bit words) */
341
342 R6 = 0x1 (Z);
343 W[P1+OFFSET_(MDMA_S0_X_MODIFY)] = R6; /* Source Modify = 1 */
344 W[P1+OFFSET_(MDMA_D0_X_MODIFY)] = R6; /* Destination Modify = 1 */
345
346 [P1+OFFSET_(MDMA_S0_START_ADDR)] = R0; /* Set Source Base Address */
347 W[P1+OFFSET_(MDMA_S0_X_COUNT)] = R2; /* Set Source Count */
348 /* Set Source DMAConfig = DMA Enable,
349 Memory Read, 8-Bit Transfers, 1-D DMA, Flow - Stop */
350 W[P1+OFFSET_(MDMA_S0_CONFIG)] = R3;
351
352 [P1+OFFSET_(MDMA_D0_START_ADDR)] = R1; /* Set Destination Base Address */
353 W[P1+OFFSET_(MDMA_D0_X_COUNT)] = R2; /* Set Destination Count */
354 /* Set Destination DMAConfig = DMA Enable,
355 Memory Write, 8-Bit Transfers, 1-D DMA, Flow - Stop, IOC */
356 W[P1+OFFSET_(MDMA_D0_CONFIG)] = R4;
357
358POST_DATA_DMA_DONE:
359 p0.h = hi(MDMA_D0_IRQ_STATUS);
360 p0.l = lo(MDMA_D0_IRQ_STATUS);
361 R0 = W[P0](Z);
362 CC = BITTST(R0, 0);
363 if ! CC jump POST_DATA_DMA_DONE
364
365 R0 = 0x1;
366 W[P1+OFFSET_(MDMA_D0_IRQ_STATUS)] = R0; /* Write 1 to clear DMA interrupt */
367
368 p0.l = _memory_post_test;
369 p0.h = _memory_post_test;
370 r0 = 0x0;
371 call (p0);
372 r7 = r0; /* save return value */
373
374 call init_sdram;
375#endif
376
377 /* relocate into to RAM */
378 call get_pc;
379offset:
380 r2.l = offset;
381 r2.h = offset;
382 r3.l = start;
383 r3.h = start;
384 r1 = r2 - r3;
385
386 r0 = r0 - r1;
387 p1 = r0;
388
389 p2.l = (CFG_MONITOR_BASE & 0xffff);
390 p2.h = (CFG_MONITOR_BASE >> 16);
391
392 p3 = 0x04;
393 p4.l = ((CFG_MONITOR_BASE + CFG_MONITOR_LEN) & 0xffff);
394 p4.h = ((CFG_MONITOR_BASE + CFG_MONITOR_LEN) >> 16);
395loop1:
396 r1 = [p1 ++ p3];
397 [p2 ++ p3] = r1;
398 cc=p2==p4;
399 if !cc jump loop1;
400 /*
401 * configure STACK
402 */
403 r0.h = (CONFIG_STACKBASE >> 16);
404 r0.l = (CONFIG_STACKBASE & 0xFFFF);
405 sp = r0;
406 fp = sp;
407
408 /*
409 * This next section keeps the processor in supervisor mode
410 * during kernel boot. Switches to user mode at end of boot.
411 * See page 3-9 of Hardware Reference manual for documentation.
412 */
413
414 /* To keep ourselves in the supervisor mode */
Mike Frysingerd4d77302008-02-04 19:26:55 -0500415 p0.l = (EVT15 & 0xFFFF);
416 p0.h = (EVT15 >> 16);
Aubrey Li26bf7de2007-03-19 01:24:52 +0800417
418 p1.l = _real_start;
419 p1.h = _real_start;
420 [p0] = p1;
421
422 p0.l = (IMASK & 0xFFFF);
423 p0.h = (IMASK >> 16);
Mike Frysingerd4d77302008-02-04 19:26:55 -0500424 r0.l = LO(EVT_IVG15);
425 r0.h = HI(EVT_IVG15);
Aubrey Li26bf7de2007-03-19 01:24:52 +0800426 [p0] = r0;
427 raise 15;
428 p0.l = WAIT_HERE;
429 p0.h = WAIT_HERE;
430 reti = p0;
431 rti;
432
433WAIT_HERE:
434 jump WAIT_HERE;
435
436.global _real_start;
437_real_start:
438 [ -- sp ] = reti;
439
440#ifdef CONFIG_BF537
441/* Initialise General-Purpose I/O Modules on BF537
442 * Rev 0.0 Anomaly 05000212 - PORTx_FER,
443 * PORT_MUX Registers Do Not accept "writes" correctly
444 */
445 p0.h = hi(PORTF_FER);
446 p0.l = lo(PORTF_FER);
447 R0.L = W[P0]; /* Read */
448 nop;
449 nop;
450 nop;
451 ssync;
452 R0 = 0x000F(Z);
453 W[P0] = R0.L; /* Write */
454 nop;
455 nop;
456 nop;
457 ssync;
458 W[P0] = R0.L; /* Enable peripheral function of PORTF for UART0 and UART1 */
459 nop;
460 nop;
461 nop;
462 ssync;
463
464 p0.h = hi(PORTH_FER);
465 p0.l = lo(PORTH_FER);
466 R0.L = W[P0]; /* Read */
467 nop;
468 nop;
469 nop;
470 ssync;
471 R0 = 0xFFFF(Z);
472 W[P0] = R0.L; /* Write */
473 nop;
474 nop;
475 nop;
476 ssync;
477 W[P0] = R0.L; /* Enable peripheral function of PORTH for MAC */
478 nop;
479 nop;
480 nop;
481 ssync;
482
483#endif
484
485 /* DMA reset code to Hi of L1 SRAM */
486copy:
487 P1.H = hi(SYSMMR_BASE); /* P1 Points to the beginning of SYSTEM MMR Space */
488 P1.L = lo(SYSMMR_BASE);
489
490 R0.H = reset_start; /* Source Address (high) */
491 R0.L = reset_start; /* Source Address (low) */
492 R1.H = reset_end;
493 R1.L = reset_end;
494 R2 = R1 - R0; /* Count */
Mike Frysingerd4d77302008-02-04 19:26:55 -0500495 R1.H = hi(L1_INST_SRAM); /* Destination Address (high) */
496 R1.L = lo(L1_INST_SRAM); /* Destination Address (low) */
Aubrey Li26bf7de2007-03-19 01:24:52 +0800497 R3.L = DMAEN; /* Source DMAConfig Value (8-bit words) */
498 R4.L = (DI_EN | WNR | DMAEN); /* Destination DMAConfig Value (8-bit words) */
499
500DMA:
501 R6 = 0x1 (Z);
502 W[P1+OFFSET_(MDMA_S0_X_MODIFY)] = R6; /* Source Modify = 1 */
503 W[P1+OFFSET_(MDMA_D0_X_MODIFY)] = R6; /* Destination Modify = 1 */
504
505 [P1+OFFSET_(MDMA_S0_START_ADDR)] = R0; /* Set Source Base Address */
506 W[P1+OFFSET_(MDMA_S0_X_COUNT)] = R2; /* Set Source Count */
507 /* Set Source DMAConfig = DMA Enable,
508 Memory Read, 8-Bit Transfers, 1-D DMA, Flow - Stop */
509 W[P1+OFFSET_(MDMA_S0_CONFIG)] = R3;
510
511 [P1+OFFSET_(MDMA_D0_START_ADDR)] = R1; /* Set Destination Base Address */
512 W[P1+OFFSET_(MDMA_D0_X_COUNT)] = R2; /* Set Destination Count */
513 /* Set Destination DMAConfig = DMA Enable,
514 Memory Write, 8-Bit Transfers, 1-D DMA, Flow - Stop, IOC */
515 W[P1+OFFSET_(MDMA_D0_CONFIG)] = R4;
516
517WAIT_DMA_DONE:
518 p0.h = hi(MDMA_D0_IRQ_STATUS);
519 p0.l = lo(MDMA_D0_IRQ_STATUS);
520 R0 = W[P0](Z);
521 CC = BITTST(R0, 0);
522 if ! CC jump WAIT_DMA_DONE
523
524 R0 = 0x1;
525 W[P1+OFFSET_(MDMA_D0_IRQ_STATUS)] = R0; /* Write 1 to clear DMA interrupt */
526
527 /* Initialize BSS Section with 0 s */
528 p1.l = __bss_start;
529 p1.h = __bss_start;
530 p2.l = _end;
531 p2.h = _end;
532 r1 = p1;
533 r2 = p2;
534 r3 = r2 - r1;
535 r3 = r3 >> 2;
536 p3 = r3;
537 lsetup (_clear_bss, _clear_bss_end ) lc1 = p3;
538 CC = p2<=p1;
539 if CC jump _clear_bss_skip;
540 r0 = 0;
541_clear_bss:
542_clear_bss_end:
543 [p1++] = r0;
544_clear_bss_skip:
545
546#if defined(CONFIG_BF537)&&defined(CONFIG_POST)
547 p0.l = _post_flag;
548 p0.h = _post_flag;
549 r0 = r7;
550 [p0] = r0;
551#endif
552
553 p0.l = _start1;
554 p0.h = _start1;
555 jump (p0);
556
557reset_start:
558 p0.h = WDOG_CNT >> 16;
559 p0.l = WDOG_CNT & 0xffff;
560 r0 = 0x0010;
561 w[p0] = r0;
562 p0.h = WDOG_CTL >> 16;
563 p0.l = WDOG_CTL & 0xffff;
564 r0 = 0x0000;
565 w[p0] = r0;
566reset_wait:
567 jump reset_wait;
568
569reset_end:
570 nop;
571
572_exit:
573 jump.s _exit;
574get_pc:
575 r0 = rets;
576 rts;