blob: 429c8a1019dab0de10bc9e7dfdc2f1392994cc42 [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>
Mike Frysinger52a07812007-06-11 15:31:30 +080031#include <linux/init.h>
Bryan Wu1394f032007-05-06 14:50:22 -070032#include <asm/blackfin.h>
Robin Getz669b7922007-06-21 16:34:08 +080033#include <asm/trace.h>
34
Bryan Wu1394f032007-05-06 14:50:22 -070035#if CONFIG_BFIN_KERNEL_CLOCK
36#include <asm/mach/mem_init.h>
37#endif
38
39.global __rambase
40.global __ramstart
41.global __ramend
42.extern ___bss_stop
43.extern ___bss_start
44.extern _bf53x_relocate_l1_mem
45
Mike Frysinger83a5c3e2007-06-11 15:31:30 +080046#define INITIAL_STACK 0xFFB01000
Bryan Wu1394f032007-05-06 14:50:22 -070047
Mike Frysinger52a07812007-06-11 15:31:30 +080048__INIT
Bryan Wu1394f032007-05-06 14:50:22 -070049
50ENTRY(__start)
Bryan Wu1394f032007-05-06 14:50:22 -070051 /* R0: argument of command line string, passed from uboot, save it */
52 R7 = R0;
Mike Frysinger83a5c3e2007-06-11 15:31:30 +080053 /* Set the SYSCFG register:
54 * Enable Cycle Counter and Nesting Of Interrupts (3rd Bit)
55 */
Bryan Wu1394f032007-05-06 14:50:22 -070056 R0 = 0x36;
Mike Frysinger83a5c3e2007-06-11 15:31:30 +080057 SYSCFG = R0;
Bryan Wu1394f032007-05-06 14:50:22 -070058 R0 = 0;
59
Mike Frysinger83a5c3e2007-06-11 15:31:30 +080060 /* Clear Out All the data and pointer Registers */
Bryan Wu1394f032007-05-06 14:50:22 -070061 R1 = R0;
62 R2 = R0;
63 R3 = R0;
64 R4 = R0;
65 R5 = R0;
66 R6 = R0;
67
68 P0 = R0;
69 P1 = R0;
70 P2 = R0;
71 P3 = R0;
72 P4 = R0;
73 P5 = R0;
74
75 LC0 = r0;
76 LC1 = r0;
77 L0 = r0;
78 L1 = r0;
79 L2 = r0;
80 L3 = r0;
81
Mike Frysinger83a5c3e2007-06-11 15:31:30 +080082 /* Clear Out All the DAG Registers */
Bryan Wu1394f032007-05-06 14:50:22 -070083 B0 = r0;
84 B1 = r0;
85 B2 = r0;
86 B3 = r0;
87
88 I0 = r0;
89 I1 = r0;
90 I2 = r0;
91 I3 = r0;
92
93 M0 = r0;
94 M1 = r0;
95 M2 = r0;
96 M3 = r0;
97
Robin Getz669b7922007-06-21 16:34:08 +080098 trace_buffer_start(p0,r0);
99 P0 = R1;
100 R0 = R1;
101
Bryan Wu1394f032007-05-06 14:50:22 -0700102 /* Turn off the icache */
103 p0.l = (IMEM_CONTROL & 0xFFFF);
104 p0.h = (IMEM_CONTROL >> 16);
105 R1 = [p0];
106 R0 = ~ENICPLB;
107 R0 = R0 & R1;
108
109 /* Anomaly 05000125 */
110#ifdef ANOMALY_05000125
111 CLI R2;
112 SSYNC;
113#endif
114 [p0] = R0;
115 SSYNC;
116#ifdef ANOMALY_05000125
117 STI R2;
118#endif
119
120 /* Turn off the dcache */
121 p0.l = (DMEM_CONTROL & 0xFFFF);
122 p0.h = (DMEM_CONTROL >> 16);
123 R1 = [p0];
124 R0 = ~ENDCPLB;
125 R0 = R0 & R1;
126
127 /* Anomaly 05000125 */
128#ifdef ANOMALY_05000125
129 CLI R2;
130 SSYNC;
131#endif
132 [p0] = R0;
133 SSYNC;
134#ifdef ANOMALY_05000125
135 STI R2;
136#endif
137
138 /* Initialise General-Purpose I/O Modules on BF537 */
139 /* Rev 0.0 Anomaly 05000212 - PORTx_FER,
140 * PORT_MUX Registers Do Not accept "writes" correctly:
141 */
142 p0.h = hi(BFIN_PORT_MUX);
143 p0.l = lo(BFIN_PORT_MUX);
144#ifdef ANOMALY_05000212
145 R0.L = W[P0]; /* Read */
146 SSYNC;
147#endif
148 R0 = (PGDE_UART | PFTE_UART)(Z);
149#ifdef ANOMALY_05000212
150 W[P0] = R0.L; /* Write */
151 SSYNC;
152#endif
153 W[P0] = R0.L; /* Enable both UARTS */
154 SSYNC;
155
156 p0.h = hi(PORTF_FER);
157 p0.l = lo(PORTF_FER);
158#ifdef ANOMALY_05000212
159 R0.L = W[P0]; /* Read */
160 SSYNC;
161#endif
162 R0 = 0x000F(Z);
163#ifdef ANOMALY_05000212
164 W[P0] = R0.L; /* Write */
165 SSYNC;
166#endif
167 /* Enable peripheral function of PORTF for UART0 and UART1 */
168 W[P0] = R0.L;
169 SSYNC;
170
171#if !defined(CONFIG_BF534)
172 p0.h = hi(EMAC_SYSTAT);
173 p0.l = lo(EMAC_SYSTAT);
174 R0.h = 0xFFFF; /* Clear EMAC Interrupt Status bits */
175 R0.l = 0xFFFF;
176 [P0] = R0;
177 SSYNC;
178#endif
179
180#ifdef CONFIG_BF537_PORT_H
181 p0.h = hi(PORTH_FER);
182 p0.l = lo(PORTH_FER);
183 R0.L = W[P0]; /* Read */
184 SSYNC;
185 R0 = 0x0000;
186 W[P0] = R0.L; /* Write */
187 SSYNC;
188 W[P0] = R0.L; /* Disable peripheral function of PORTH */
189 SSYNC;
190#endif
191
Mike Frysinger5079df92007-05-21 18:09:27 +0800192 /* Initialise UART - when booting from u-boot, the UART is not disabled
193 * so if we dont initalize here, our serial console gets hosed */
Bryan Wu1394f032007-05-06 14:50:22 -0700194 p0.h = hi(UART_LCR);
195 p0.l = lo(UART_LCR);
196 r0 = 0x0(Z);
197 w[p0] = r0.L; /* To enable DLL writes */
198 ssync;
199
200 p0.h = hi(UART_DLL);
201 p0.l = lo(UART_DLL);
Mike Frysinger83a5c3e2007-06-11 15:31:30 +0800202 r0 = 0x0(Z);
Bryan Wu1394f032007-05-06 14:50:22 -0700203 w[p0] = r0.L;
204 ssync;
205
206 p0.h = hi(UART_DLH);
207 p0.l = lo(UART_DLH);
208 r0 = 0x00(Z);
209 w[p0] = r0.L;
210 ssync;
211
212 p0.h = hi(UART_GCTL);
213 p0.l = lo(UART_GCTL);
214 r0 = 0x0(Z);
215 w[p0] = r0.L; /* To enable UART clock */
216 ssync;
217
218 /* Initialize stack pointer */
219 sp.l = lo(INITIAL_STACK);
220 sp.h = hi(INITIAL_STACK);
221 fp = sp;
222 usp = sp;
223
224 /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */
225 call _bf53x_relocate_l1_mem;
226#if CONFIG_BFIN_KERNEL_CLOCK
227 call _start_dma_code;
228#endif
Mike Frysinger83a5c3e2007-06-11 15:31:30 +0800229
Bryan Wu1394f032007-05-06 14:50:22 -0700230 /* Code for initializing Async memory banks */
231
232 p2.h = hi(EBIU_AMBCTL1);
233 p2.l = lo(EBIU_AMBCTL1);
234 r0.h = hi(AMBCTL1VAL);
235 r0.l = lo(AMBCTL1VAL);
236 [p2] = r0;
237 ssync;
238
239 p2.h = hi(EBIU_AMBCTL0);
240 p2.l = lo(EBIU_AMBCTL0);
241 r0.h = hi(AMBCTL0VAL);
242 r0.l = lo(AMBCTL0VAL);
243 [p2] = r0;
244 ssync;
245
246 p2.h = hi(EBIU_AMGCTL);
247 p2.l = lo(EBIU_AMGCTL);
248 r0 = AMGCTLVAL;
249 w[p2] = r0;
250 ssync;
251
252 /* This section keeps the processor in supervisor mode
253 * during kernel boot. Switches to user mode at end of boot.
254 * See page 3-9 of Hardware Reference manual for documentation.
255 */
256
257 /* EVT15 = _real_start */
258
259 p0.l = lo(EVT15);
260 p0.h = hi(EVT15);
261 p1.l = _real_start;
262 p1.h = _real_start;
263 [p0] = p1;
264 csync;
265
266 p0.l = lo(IMASK);
267 p0.h = hi(IMASK);
268 p1.l = IMASK_IVG15;
269 p1.h = 0x0;
270 [p0] = p1;
271 csync;
272
273 raise 15;
274 p0.l = .LWAIT_HERE;
275 p0.h = .LWAIT_HERE;
276 reti = p0;
277#if defined(ANOMALY_05000281)
278 nop; nop; nop;
279#endif
280 rti;
281
282.LWAIT_HERE:
283 jump .LWAIT_HERE;
Mike Frysinger52a07812007-06-11 15:31:30 +0800284ENDPROC(__start)
Bryan Wu1394f032007-05-06 14:50:22 -0700285
286ENTRY(_real_start)
287 [ -- sp ] = reti;
288 p0.l = lo(WDOG_CTL);
289 p0.h = hi(WDOG_CTL);
290 r0 = 0xAD6(z);
291 w[p0] = r0; /* watchdog off for now */
292 ssync;
293
294 /* Code update for BSS size == 0
295 * Zero out the bss region.
296 */
297
298 p1.l = ___bss_start;
299 p1.h = ___bss_start;
300 p2.l = ___bss_stop;
301 p2.h = ___bss_stop;
302 r0 = 0;
303 p2 -= p1;
Mike Frysinger83a5c3e2007-06-11 15:31:30 +0800304 lsetup (.L_clear_bss, .L_clear_bss) lc0 = p2;
Bryan Wu1394f032007-05-06 14:50:22 -0700305.L_clear_bss:
306 B[p1++] = r0;
307
308 /* In case there is a NULL pointer reference
309 * Zero out region before stext
310 */
311
312 p1.l = 0x0;
313 p1.h = 0x0;
314 r0.l = __stext;
315 r0.h = __stext;
316 r0 = r0 >> 1;
317 p2 = r0;
318 r0 = 0;
Mike Frysinger83a5c3e2007-06-11 15:31:30 +0800319 lsetup (.L_clear_zero, .L_clear_zero) lc0 = p2;
Bryan Wu1394f032007-05-06 14:50:22 -0700320.L_clear_zero:
321 W[p1++] = r0;
322
323 /* pass the uboot arguments to the global value command line */
324 R0 = R7;
325 call _cmdline_init;
326
327 p1.l = __rambase;
328 p1.h = __rambase;
329 r0.l = __sdata;
330 r0.h = __sdata;
331 [p1] = r0;
332
333 p1.l = __ramstart;
334 p1.h = __ramstart;
335 p3.l = ___bss_stop;
336 p3.h = ___bss_stop;
337
338 r1 = p3;
339 [p1] = r1;
340
Bryan Wu1394f032007-05-06 14:50:22 -0700341 /*
Mike Frysinger83a5c3e2007-06-11 15:31:30 +0800342 * load the current thread pointer and stack
Bryan Wu1394f032007-05-06 14:50:22 -0700343 */
344 r1.l = _init_thread_union;
345 r1.h = _init_thread_union;
346
347 r2.l = 0x2000;
348 r2.h = 0x0000;
349 r1 = r1 + r2;
350 sp = r1;
351 usp = sp;
352 fp = sp;
Mike Frysinger52a07812007-06-11 15:31:30 +0800353 jump.l _start_kernel;
354ENDPROC(_real_start)
355
356__FINIT
Bryan Wu1394f032007-05-06 14:50:22 -0700357
358.section .l1.text
359#if CONFIG_BFIN_KERNEL_CLOCK
360ENTRY(_start_dma_code)
361
362 /* Enable PHY CLK buffer output */
363 p0.h = hi(VR_CTL);
364 p0.l = lo(VR_CTL);
365 r0.l = w[p0];
366 bitset(r0, 14);
367 w[p0] = r0.l;
368 ssync;
369
370 p0.h = hi(SIC_IWR);
371 p0.l = lo(SIC_IWR);
372 r0.l = 0x1;
373 r0.h = 0x0;
374 [p0] = r0;
375 SSYNC;
376
377 /*
378 * Set PLL_CTL
379 * - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors
380 * - [8] = BYPASS : BYPASS the PLL, run CLKIN into CCLK/SCLK
381 * - [7] = output delay (add 200ps of delay to mem signals)
382 * - [6] = input delay (add 200ps of input delay to mem signals)
383 * - [5] = PDWN : 1=All Clocks off
384 * - [3] = STOPCK : 1=Core Clock off
385 * - [1] = PLL_OFF : 1=Disable Power to PLL
386 * - [0] = DF : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL
387 * all other bits set to zero
388 */
389
390 p0.h = hi(PLL_LOCKCNT);
391 p0.l = lo(PLL_LOCKCNT);
392 r0 = 0x300(Z);
393 w[p0] = r0.l;
394 ssync;
395
396 P2.H = hi(EBIU_SDGCTL);
397 P2.L = lo(EBIU_SDGCTL);
398 R0 = [P2];
399 BITSET (R0, 24);
400 [P2] = R0;
401 SSYNC;
402
403 r0 = CONFIG_VCO_MULT & 63; /* Load the VCO multiplier */
404 r0 = r0 << 9; /* Shift it over, */
405 r1 = CLKIN_HALF; /* Do we need to divide CLKIN by 2?*/
406 r0 = r1 | r0;
407 r1 = PLL_BYPASS; /* Bypass the PLL? */
408 r1 = r1 << 8; /* Shift it over */
409 r0 = r1 | r0; /* add them all together */
410
411 p0.h = hi(PLL_CTL);
412 p0.l = lo(PLL_CTL); /* Load the address */
413 cli r2; /* Disable interrupts */
414 ssync;
415 w[p0] = r0.l; /* Set the value */
416 idle; /* Wait for the PLL to stablize */
417 sti r2; /* Enable interrupts */
418
419.Lcheck_again:
420 p0.h = hi(PLL_STAT);
421 p0.l = lo(PLL_STAT);
422 R0 = W[P0](Z);
423 CC = BITTST(R0,5);
424 if ! CC jump .Lcheck_again;
425
426 /* Configure SCLK & CCLK Dividers */
427 r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
428 p0.h = hi(PLL_DIV);
429 p0.l = lo(PLL_DIV);
430 w[p0] = r0.l;
431 ssync;
432
433 p0.l = lo(EBIU_SDRRC);
434 p0.h = hi(EBIU_SDRRC);
435 r0 = mem_SDRRC;
436 w[p0] = r0.l;
437 ssync;
438
439 p0.l = (EBIU_SDBCTL & 0xFFFF);
440 p0.h = (EBIU_SDBCTL >> 16); /* SDRAM Memory Bank Control Register */
441 r0 = mem_SDBCTL;
442 w[p0] = r0.l;
443 ssync;
444
445 P2.H = hi(EBIU_SDGCTL);
446 P2.L = lo(EBIU_SDGCTL);
447 R0 = [P2];
448 BITCLR (R0, 24);
449 p0.h = hi(EBIU_SDSTAT);
450 p0.l = lo(EBIU_SDSTAT);
451 r2.l = w[p0];
452 cc = bittst(r2,3);
453 if !cc jump .Lskip;
454 NOP;
455 BITSET (R0, 23);
456.Lskip:
457 [P2] = R0;
458 SSYNC;
459
460 R0.L = lo(mem_SDGCTL);
461 R0.H = hi(mem_SDGCTL);
462 R1 = [p2];
463 R1 = R1 | R0;
464 [P2] = R1;
465 SSYNC;
466
467 p0.h = hi(SIC_IWR);
468 p0.l = lo(SIC_IWR);
469 r0.l = lo(IWR_ENABLE_ALL);
470 r0.h = hi(IWR_ENABLE_ALL);
471 [p0] = r0;
472 SSYNC;
473
474 RTS;
Mike Frysinger52a07812007-06-11 15:31:30 +0800475ENDPROC(_start_dma_code)
Bryan Wu1394f032007-05-06 14:50:22 -0700476#endif /* CONFIG_BFIN_KERNEL_CLOCK */
477
478ENTRY(_bfin_reset)
479 /* No more interrupts to be handled*/
480 CLI R6;
481 SSYNC;
482
483#if defined(CONFIG_MTD_M25P80)
Mike Frysingerc09c4e02007-05-21 18:09:30 +0800484 /*
485 * The following code fix the SPI flash reboot issue,
486 * /CS signal of the chip which is using PF10 return to GPIO mode
487 */
Bryan Wu1394f032007-05-06 14:50:22 -0700488 p0.h = hi(PORTF_FER);
489 p0.l = lo(PORTF_FER);
490 r0.l = 0x0000;
491 w[p0] = r0.l;
492 SSYNC;
493
Mike Frysingerc09c4e02007-05-21 18:09:30 +0800494 /* /CS return to high */
Bryan Wu1394f032007-05-06 14:50:22 -0700495 p0.h = hi(PORTFIO);
496 p0.l = lo(PORTFIO);
497 r0.l = 0xFFFF;
498 w[p0] = r0.l;
499 SSYNC;
500
Mike Frysingerc09c4e02007-05-21 18:09:30 +0800501 /* Delay some time, This is necessary */
Bryan Wu1394f032007-05-06 14:50:22 -0700502 r1.h = 0;
503 r1.l = 0x400;
504 p1 = r1;
Mike Frysingerc09c4e02007-05-21 18:09:30 +0800505 lsetup (.L_delay_lab1, .L_delay_lab1_end) lc1 = p1;
506.L_delay_lab1:
Bryan Wu1394f032007-05-06 14:50:22 -0700507 r0.h = 0;
508 r0.l = 0x8000;
509 p0 = r0;
Mike Frysingerc09c4e02007-05-21 18:09:30 +0800510 lsetup (.L_delay_lab0, .L_delay_lab0_end) lc0 = p0;
511.L_delay_lab0:
Bryan Wu1394f032007-05-06 14:50:22 -0700512 nop;
Mike Frysingerc09c4e02007-05-21 18:09:30 +0800513.L_delay_lab0_end:
Bryan Wu1394f032007-05-06 14:50:22 -0700514 nop;
Mike Frysingerc09c4e02007-05-21 18:09:30 +0800515.L_delay_lab1_end:
Bryan Wu1394f032007-05-06 14:50:22 -0700516 nop;
517#endif
518
Bryan Wu1394f032007-05-06 14:50:22 -0700519 /* Clear the IMASK register */
520 p0.h = hi(IMASK);
521 p0.l = lo(IMASK);
522 r0 = 0x0;
523 [p0] = r0;
524
525 /* Clear the ILAT register */
526 p0.h = hi(ILAT);
527 p0.l = lo(ILAT);
528 r0 = [p0];
529 [p0] = r0;
530 SSYNC;
531
Mike Frysingeref9256d2007-05-21 18:09:26 +0800532 /* make sure SYSCR is set to use BMODE */
533 P0.h = hi(SYSCR);
534 P0.l = lo(SYSCR);
535 R0.l = 0x0;
536 W[P0] = R0.l;
Bryan Wu1394f032007-05-06 14:50:22 -0700537 SSYNC;
538
Mike Frysingeref9256d2007-05-21 18:09:26 +0800539 /* issue a system soft reset */
540 P1.h = hi(SWRST);
541 P1.l = lo(SWRST);
542 R1.l = 0x0007;
543 W[P1] = R1;
Bryan Wu1394f032007-05-06 14:50:22 -0700544 SSYNC;
545
Mike Frysingeref9256d2007-05-21 18:09:26 +0800546 /* clear system soft reset */
547 R0.l = 0x0000;
548 W[P0] = R0;
Bryan Wu1394f032007-05-06 14:50:22 -0700549 SSYNC;
550
Mike Frysingeref9256d2007-05-21 18:09:26 +0800551 /* issue core reset */
552 raise 1;
Bryan Wu1394f032007-05-06 14:50:22 -0700553
554 RTS;
Mike Frysingeref9256d2007-05-21 18:09:26 +0800555ENDPROC(_bfin_reset)
Bryan Wu1394f032007-05-06 14:50:22 -0700556
557.data
558
559/*
560 * Set up the usable of RAM stuff. Size of RAM is determined then
561 * an initial stack set up at the end.
562 */
563
564.align 4
565__rambase:
566.long 0
567__ramstart:
568.long 0
569__ramend:
570.long 0