blob: b4377dddc127fd5e346e483123cd4b77dbff9243 [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
2 * File: arch/blackfin/mach-bf537/head.S
3 * Based on: arch/blackfin/mach-bf533/head.S
4 * Author: Jeff Dionne <jeff@uclinux.org> COPYRIGHT 1998 D. Jeff Dionne
5 *
6 * Created: 1998
7 * Description: Startup code for Blackfin BF537
8 *
9 * Modified:
10 * Copyright 2004-2006 Analog Devices Inc.
11 *
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see the file COPYING, or write
26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */
29
30#include <linux/linkage.h>
31#include <asm/blackfin.h>
32#if CONFIG_BFIN_KERNEL_CLOCK
33#include <asm/mach/mem_init.h>
34#endif
35
36.global __rambase
37.global __ramstart
38.global __ramend
39.extern ___bss_stop
40.extern ___bss_start
41.extern _bf53x_relocate_l1_mem
42
43#define INITIAL_STACK 0xFFB01000
44
45.text
46
47ENTRY(__start)
48ENTRY(__stext)
49 /* R0: argument of command line string, passed from uboot, save it */
50 R7 = R0;
51 /* Set the SYSCFG register */
52 R0 = 0x36;
53 SYSCFG = R0; /*Enable Cycle Counter and Nesting Of Interrupts(3rd Bit)*/
54 R0 = 0;
55
56 /* Clear Out All the data and pointer Registers*/
57 R1 = R0;
58 R2 = R0;
59 R3 = R0;
60 R4 = R0;
61 R5 = R0;
62 R6 = R0;
63
64 P0 = R0;
65 P1 = R0;
66 P2 = R0;
67 P3 = R0;
68 P4 = R0;
69 P5 = R0;
70
71 LC0 = r0;
72 LC1 = r0;
73 L0 = r0;
74 L1 = r0;
75 L2 = r0;
76 L3 = r0;
77
78 /* Clear Out All the DAG Registers*/
79 B0 = r0;
80 B1 = r0;
81 B2 = r0;
82 B3 = r0;
83
84 I0 = r0;
85 I1 = r0;
86 I2 = r0;
87 I3 = r0;
88
89 M0 = r0;
90 M1 = r0;
91 M2 = r0;
92 M3 = r0;
93
94 /* Turn off the icache */
95 p0.l = (IMEM_CONTROL & 0xFFFF);
96 p0.h = (IMEM_CONTROL >> 16);
97 R1 = [p0];
98 R0 = ~ENICPLB;
99 R0 = R0 & R1;
100
101 /* Anomaly 05000125 */
102#ifdef ANOMALY_05000125
103 CLI R2;
104 SSYNC;
105#endif
106 [p0] = R0;
107 SSYNC;
108#ifdef ANOMALY_05000125
109 STI R2;
110#endif
111
112 /* Turn off the dcache */
113 p0.l = (DMEM_CONTROL & 0xFFFF);
114 p0.h = (DMEM_CONTROL >> 16);
115 R1 = [p0];
116 R0 = ~ENDCPLB;
117 R0 = R0 & R1;
118
119 /* Anomaly 05000125 */
120#ifdef ANOMALY_05000125
121 CLI R2;
122 SSYNC;
123#endif
124 [p0] = R0;
125 SSYNC;
126#ifdef ANOMALY_05000125
127 STI R2;
128#endif
129
130 /* Initialise General-Purpose I/O Modules on BF537 */
131 /* Rev 0.0 Anomaly 05000212 - PORTx_FER,
132 * PORT_MUX Registers Do Not accept "writes" correctly:
133 */
134 p0.h = hi(BFIN_PORT_MUX);
135 p0.l = lo(BFIN_PORT_MUX);
136#ifdef ANOMALY_05000212
137 R0.L = W[P0]; /* Read */
138 SSYNC;
139#endif
140 R0 = (PGDE_UART | PFTE_UART)(Z);
141#ifdef ANOMALY_05000212
142 W[P0] = R0.L; /* Write */
143 SSYNC;
144#endif
145 W[P0] = R0.L; /* Enable both UARTS */
146 SSYNC;
147
148 p0.h = hi(PORTF_FER);
149 p0.l = lo(PORTF_FER);
150#ifdef ANOMALY_05000212
151 R0.L = W[P0]; /* Read */
152 SSYNC;
153#endif
154 R0 = 0x000F(Z);
155#ifdef ANOMALY_05000212
156 W[P0] = R0.L; /* Write */
157 SSYNC;
158#endif
159 /* Enable peripheral function of PORTF for UART0 and UART1 */
160 W[P0] = R0.L;
161 SSYNC;
162
163#if !defined(CONFIG_BF534)
164 p0.h = hi(EMAC_SYSTAT);
165 p0.l = lo(EMAC_SYSTAT);
166 R0.h = 0xFFFF; /* Clear EMAC Interrupt Status bits */
167 R0.l = 0xFFFF;
168 [P0] = R0;
169 SSYNC;
170#endif
171
172#ifdef CONFIG_BF537_PORT_H
173 p0.h = hi(PORTH_FER);
174 p0.l = lo(PORTH_FER);
175 R0.L = W[P0]; /* Read */
176 SSYNC;
177 R0 = 0x0000;
178 W[P0] = R0.L; /* Write */
179 SSYNC;
180 W[P0] = R0.L; /* Disable peripheral function of PORTH */
181 SSYNC;
182#endif
183
Mike Frysinger5079df92007-05-21 18:09:27 +0800184 /* Initialise UART - when booting from u-boot, the UART is not disabled
185 * so if we dont initalize here, our serial console gets hosed */
Bryan Wu1394f032007-05-06 14:50:22 -0700186 p0.h = hi(UART_LCR);
187 p0.l = lo(UART_LCR);
188 r0 = 0x0(Z);
189 w[p0] = r0.L; /* To enable DLL writes */
190 ssync;
191
192 p0.h = hi(UART_DLL);
193 p0.l = lo(UART_DLL);
194 r0 = 0x00(Z);
195 w[p0] = r0.L;
196 ssync;
197
198 p0.h = hi(UART_DLH);
199 p0.l = lo(UART_DLH);
200 r0 = 0x00(Z);
201 w[p0] = r0.L;
202 ssync;
203
204 p0.h = hi(UART_GCTL);
205 p0.l = lo(UART_GCTL);
206 r0 = 0x0(Z);
207 w[p0] = r0.L; /* To enable UART clock */
208 ssync;
209
210 /* Initialize stack pointer */
211 sp.l = lo(INITIAL_STACK);
212 sp.h = hi(INITIAL_STACK);
213 fp = sp;
214 usp = sp;
215
216 /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */
217 call _bf53x_relocate_l1_mem;
218#if CONFIG_BFIN_KERNEL_CLOCK
219 call _start_dma_code;
220#endif
221 /* Code for initializing Async memory banks */
222
223 p2.h = hi(EBIU_AMBCTL1);
224 p2.l = lo(EBIU_AMBCTL1);
225 r0.h = hi(AMBCTL1VAL);
226 r0.l = lo(AMBCTL1VAL);
227 [p2] = r0;
228 ssync;
229
230 p2.h = hi(EBIU_AMBCTL0);
231 p2.l = lo(EBIU_AMBCTL0);
232 r0.h = hi(AMBCTL0VAL);
233 r0.l = lo(AMBCTL0VAL);
234 [p2] = r0;
235 ssync;
236
237 p2.h = hi(EBIU_AMGCTL);
238 p2.l = lo(EBIU_AMGCTL);
239 r0 = AMGCTLVAL;
240 w[p2] = r0;
241 ssync;
242
243 /* This section keeps the processor in supervisor mode
244 * during kernel boot. Switches to user mode at end of boot.
245 * See page 3-9 of Hardware Reference manual for documentation.
246 */
247
248 /* EVT15 = _real_start */
249
250 p0.l = lo(EVT15);
251 p0.h = hi(EVT15);
252 p1.l = _real_start;
253 p1.h = _real_start;
254 [p0] = p1;
255 csync;
256
257 p0.l = lo(IMASK);
258 p0.h = hi(IMASK);
259 p1.l = IMASK_IVG15;
260 p1.h = 0x0;
261 [p0] = p1;
262 csync;
263
264 raise 15;
265 p0.l = .LWAIT_HERE;
266 p0.h = .LWAIT_HERE;
267 reti = p0;
268#if defined(ANOMALY_05000281)
269 nop; nop; nop;
270#endif
271 rti;
272
273.LWAIT_HERE:
274 jump .LWAIT_HERE;
275
276ENTRY(_real_start)
277 [ -- sp ] = reti;
278 p0.l = lo(WDOG_CTL);
279 p0.h = hi(WDOG_CTL);
280 r0 = 0xAD6(z);
281 w[p0] = r0; /* watchdog off for now */
282 ssync;
283
284 /* Code update for BSS size == 0
285 * Zero out the bss region.
286 */
287
288 p1.l = ___bss_start;
289 p1.h = ___bss_start;
290 p2.l = ___bss_stop;
291 p2.h = ___bss_stop;
292 r0 = 0;
293 p2 -= p1;
294 lsetup (.L_clear_bss, .L_clear_bss ) lc0 = p2;
295.L_clear_bss:
296 B[p1++] = r0;
297
298 /* In case there is a NULL pointer reference
299 * Zero out region before stext
300 */
301
302 p1.l = 0x0;
303 p1.h = 0x0;
304 r0.l = __stext;
305 r0.h = __stext;
306 r0 = r0 >> 1;
307 p2 = r0;
308 r0 = 0;
309 lsetup (.L_clear_zero, .L_clear_zero ) lc0 = p2;
310.L_clear_zero:
311 W[p1++] = r0;
312
313 /* pass the uboot arguments to the global value command line */
314 R0 = R7;
315 call _cmdline_init;
316
317 p1.l = __rambase;
318 p1.h = __rambase;
319 r0.l = __sdata;
320 r0.h = __sdata;
321 [p1] = r0;
322
323 p1.l = __ramstart;
324 p1.h = __ramstart;
325 p3.l = ___bss_stop;
326 p3.h = ___bss_stop;
327
328 r1 = p3;
329 [p1] = r1;
330
331
332 /*
333 * load the current thread pointer and stack
334 */
335 r1.l = _init_thread_union;
336 r1.h = _init_thread_union;
337
338 r2.l = 0x2000;
339 r2.h = 0x0000;
340 r1 = r1 + r2;
341 sp = r1;
342 usp = sp;
343 fp = sp;
344 call _start_kernel;
345.L_exit:
346 jump.s .L_exit;
347
348.section .l1.text
349#if CONFIG_BFIN_KERNEL_CLOCK
350ENTRY(_start_dma_code)
351
352 /* Enable PHY CLK buffer output */
353 p0.h = hi(VR_CTL);
354 p0.l = lo(VR_CTL);
355 r0.l = w[p0];
356 bitset(r0, 14);
357 w[p0] = r0.l;
358 ssync;
359
360 p0.h = hi(SIC_IWR);
361 p0.l = lo(SIC_IWR);
362 r0.l = 0x1;
363 r0.h = 0x0;
364 [p0] = r0;
365 SSYNC;
366
367 /*
368 * Set PLL_CTL
369 * - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors
370 * - [8] = BYPASS : BYPASS the PLL, run CLKIN into CCLK/SCLK
371 * - [7] = output delay (add 200ps of delay to mem signals)
372 * - [6] = input delay (add 200ps of input delay to mem signals)
373 * - [5] = PDWN : 1=All Clocks off
374 * - [3] = STOPCK : 1=Core Clock off
375 * - [1] = PLL_OFF : 1=Disable Power to PLL
376 * - [0] = DF : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL
377 * all other bits set to zero
378 */
379
380 p0.h = hi(PLL_LOCKCNT);
381 p0.l = lo(PLL_LOCKCNT);
382 r0 = 0x300(Z);
383 w[p0] = r0.l;
384 ssync;
385
386 P2.H = hi(EBIU_SDGCTL);
387 P2.L = lo(EBIU_SDGCTL);
388 R0 = [P2];
389 BITSET (R0, 24);
390 [P2] = R0;
391 SSYNC;
392
393 r0 = CONFIG_VCO_MULT & 63; /* Load the VCO multiplier */
394 r0 = r0 << 9; /* Shift it over, */
395 r1 = CLKIN_HALF; /* Do we need to divide CLKIN by 2?*/
396 r0 = r1 | r0;
397 r1 = PLL_BYPASS; /* Bypass the PLL? */
398 r1 = r1 << 8; /* Shift it over */
399 r0 = r1 | r0; /* add them all together */
400
401 p0.h = hi(PLL_CTL);
402 p0.l = lo(PLL_CTL); /* Load the address */
403 cli r2; /* Disable interrupts */
404 ssync;
405 w[p0] = r0.l; /* Set the value */
406 idle; /* Wait for the PLL to stablize */
407 sti r2; /* Enable interrupts */
408
409.Lcheck_again:
410 p0.h = hi(PLL_STAT);
411 p0.l = lo(PLL_STAT);
412 R0 = W[P0](Z);
413 CC = BITTST(R0,5);
414 if ! CC jump .Lcheck_again;
415
416 /* Configure SCLK & CCLK Dividers */
417 r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
418 p0.h = hi(PLL_DIV);
419 p0.l = lo(PLL_DIV);
420 w[p0] = r0.l;
421 ssync;
422
423 p0.l = lo(EBIU_SDRRC);
424 p0.h = hi(EBIU_SDRRC);
425 r0 = mem_SDRRC;
426 w[p0] = r0.l;
427 ssync;
428
429 p0.l = (EBIU_SDBCTL & 0xFFFF);
430 p0.h = (EBIU_SDBCTL >> 16); /* SDRAM Memory Bank Control Register */
431 r0 = mem_SDBCTL;
432 w[p0] = r0.l;
433 ssync;
434
435 P2.H = hi(EBIU_SDGCTL);
436 P2.L = lo(EBIU_SDGCTL);
437 R0 = [P2];
438 BITCLR (R0, 24);
439 p0.h = hi(EBIU_SDSTAT);
440 p0.l = lo(EBIU_SDSTAT);
441 r2.l = w[p0];
442 cc = bittst(r2,3);
443 if !cc jump .Lskip;
444 NOP;
445 BITSET (R0, 23);
446.Lskip:
447 [P2] = R0;
448 SSYNC;
449
450 R0.L = lo(mem_SDGCTL);
451 R0.H = hi(mem_SDGCTL);
452 R1 = [p2];
453 R1 = R1 | R0;
454 [P2] = R1;
455 SSYNC;
456
457 p0.h = hi(SIC_IWR);
458 p0.l = lo(SIC_IWR);
459 r0.l = lo(IWR_ENABLE_ALL);
460 r0.h = hi(IWR_ENABLE_ALL);
461 [p0] = r0;
462 SSYNC;
463
464 RTS;
465#endif /* CONFIG_BFIN_KERNEL_CLOCK */
466
467ENTRY(_bfin_reset)
468 /* No more interrupts to be handled*/
469 CLI R6;
470 SSYNC;
471
472#if defined(CONFIG_MTD_M25P80)
473/*
474 * The following code fix the SPI flash reboot issue,
475 * /CS signal of the chip which is using PF10 return to GPIO mode
476 */
477 p0.h = hi(PORTF_FER);
478 p0.l = lo(PORTF_FER);
479 r0.l = 0x0000;
480 w[p0] = r0.l;
481 SSYNC;
482
483/* /CS return to high */
484 p0.h = hi(PORTFIO);
485 p0.l = lo(PORTFIO);
486 r0.l = 0xFFFF;
487 w[p0] = r0.l;
488 SSYNC;
489
490/* Delay some time, This is necessary */
491 r1.h = 0;
492 r1.l = 0x400;
493 p1 = r1;
494 lsetup (_delay_lab1,_delay_lab1_end ) lc1 = p1;
495_delay_lab1:
496 r0.h = 0;
497 r0.l = 0x8000;
498 p0 = r0;
499 lsetup (_delay_lab0,_delay_lab0_end ) lc0 = p0;
500_delay_lab0:
501 nop;
502_delay_lab0_end:
503 nop;
504_delay_lab1_end:
505 nop;
506#endif
507
Bryan Wu1394f032007-05-06 14:50:22 -0700508 /* Clear the IMASK register */
509 p0.h = hi(IMASK);
510 p0.l = lo(IMASK);
511 r0 = 0x0;
512 [p0] = r0;
513
514 /* Clear the ILAT register */
515 p0.h = hi(ILAT);
516 p0.l = lo(ILAT);
517 r0 = [p0];
518 [p0] = r0;
519 SSYNC;
520
Mike Frysingeref9256d2007-05-21 18:09:26 +0800521 /* make sure SYSCR is set to use BMODE */
522 P0.h = hi(SYSCR);
523 P0.l = lo(SYSCR);
524 R0.l = 0x0;
525 W[P0] = R0.l;
Bryan Wu1394f032007-05-06 14:50:22 -0700526 SSYNC;
527
Mike Frysingeref9256d2007-05-21 18:09:26 +0800528 /* issue a system soft reset */
529 P1.h = hi(SWRST);
530 P1.l = lo(SWRST);
531 R1.l = 0x0007;
532 W[P1] = R1;
Bryan Wu1394f032007-05-06 14:50:22 -0700533 SSYNC;
534
Mike Frysingeref9256d2007-05-21 18:09:26 +0800535 /* clear system soft reset */
536 R0.l = 0x0000;
537 W[P0] = R0;
Bryan Wu1394f032007-05-06 14:50:22 -0700538 SSYNC;
539
Mike Frysingeref9256d2007-05-21 18:09:26 +0800540 /* issue core reset */
541 raise 1;
Bryan Wu1394f032007-05-06 14:50:22 -0700542
543 RTS;
Mike Frysingeref9256d2007-05-21 18:09:26 +0800544ENDPROC(_bfin_reset)
Bryan Wu1394f032007-05-06 14:50:22 -0700545
546.data
547
548/*
549 * Set up the usable of RAM stuff. Size of RAM is determined then
550 * an initial stack set up at the end.
551 */
552
553.align 4
554__rambase:
555.long 0
556__ramstart:
557.long 0
558__ramend:
559.long 0