937fbef26a5178a348ffba019c61ff8ba6f3c9ee
[safe/jmp/linux-2.6] / arch / blackfin / mach-bf548 / head.S
1 /*
2  * File:         arch/blackfin/mach-bf548/head.S
3  * Based on:     arch/blackfin/mach-bf537/head.S
4  * Author:       Jeff Dionne <jeff@uclinux.org> COPYRIGHT 1998 D. Jeff Dionne
5  *
6  * Created:      1998
7  * Description:  Startup code for Blackfin BF548
8  *
9  * Modified:
10  *               Copyright 2004-2007 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 #include <asm/trace.h>
33 #if CONFIG_BFIN_KERNEL_CLOCK
34 #include <asm/mach-common/clocks.h>
35 #include <asm/mach/mem_init.h>
36 #endif
37
38 .global __rambase
39 .global __ramstart
40 .global __ramend
41 .extern ___bss_stop
42 .extern ___bss_start
43 .extern _bf53x_relocate_l1_mem
44
45 #define INITIAL_STACK   0xFFB01000
46
47 .text
48
49 ENTRY(__start)
50 ENTRY(__stext)
51         /* R0: argument of command line string, passed from uboot, save it */
52         R7 = R0;
53         /* Enable Cycle Counter and Nesting Of Interrupts */
54 #ifdef CONFIG_BFIN_SCRATCH_REG_CYCLES
55         R0 = SYSCFG_SNEN;
56 #else
57         R0 = SYSCFG_SNEN | SYSCFG_CCEN;
58 #endif
59         SYSCFG = R0;
60         R0 = 0;
61
62         /* Clear Out All the data and pointer  Registers*/
63         R1 = R0;
64         R2 = R0;
65         R3 = R0;
66         R4 = R0;
67         R5 = R0;
68         R6 = R0;
69
70         P0 = R0;
71         P1 = R0;
72         P2 = R0;
73         P3 = R0;
74         P4 = R0;
75         P5 = R0;
76
77         LC0 = r0;
78         LC1 = r0;
79         L0 = r0;
80         L1 = r0;
81         L2 = r0;
82         L3 = r0;
83
84         /* Clear Out All the DAG Registers*/
85         B0 = r0;
86         B1 = r0;
87         B2 = r0;
88         B3 = r0;
89
90         I0 = r0;
91         I1 = r0;
92         I2 = r0;
93         I3 = r0;
94
95         M0 = r0;
96         M1 = r0;
97         M2 = r0;
98         M3 = r0;
99
100         trace_buffer_init(p0,r0);
101         P0 = R1;
102         R0 = R1;
103
104         /* Turn off the icache */
105         p0.l = LO(IMEM_CONTROL);
106         p0.h = HI(IMEM_CONTROL);
107         R1 = [p0];
108         R0 = ~ENICPLB;
109         R0 = R0 & R1;
110         [p0] = R0;
111         SSYNC;
112
113         /* Turn off the dcache */
114         p0.l = LO(DMEM_CONTROL);
115         p0.h = HI(DMEM_CONTROL);
116         R1 = [p0];
117         R0 = ~ENDCPLB;
118         R0 = R0 & R1;
119         [p0] = R0;
120         SSYNC;
121
122         /* Initialize stack pointer */
123         SP.L = LO(INITIAL_STACK);
124         SP.H = HI(INITIAL_STACK);
125         FP = SP;
126         USP = SP;
127
128         /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */
129         call _bf53x_relocate_l1_mem;
130 #if CONFIG_BFIN_KERNEL_CLOCK
131         call _start_dma_code;
132 #endif
133         /* Code for initializing Async memory banks */
134
135         p2.h = hi(EBIU_AMBCTL1);
136         p2.l = lo(EBIU_AMBCTL1);
137         r0.h = hi(AMBCTL1VAL);
138         r0.l = lo(AMBCTL1VAL);
139         [p2] = r0;
140         ssync;
141
142         p2.h = hi(EBIU_AMBCTL0);
143         p2.l = lo(EBIU_AMBCTL0);
144         r0.h = hi(AMBCTL0VAL);
145         r0.l = lo(AMBCTL0VAL);
146         [p2] = r0;
147         ssync;
148
149         p2.h = hi(EBIU_AMGCTL);
150         p2.l = lo(EBIU_AMGCTL);
151         r0 = AMGCTLVAL;
152         w[p2] = r0;
153         ssync;
154
155         /* This section keeps the processor in supervisor mode
156          * during kernel boot.  Switches to user mode at end of boot.
157          * See page 3-9 of Hardware Reference manual for documentation.
158          */
159
160         /* EVT15 = _real_start */
161
162         p0.l = lo(EVT15);
163         p0.h = hi(EVT15);
164         p1.l = _real_start;
165         p1.h = _real_start;
166         [p0] = p1;
167         csync;
168
169         p0.l = lo(IMASK);
170         p0.h = hi(IMASK);
171         p1.l = IMASK_IVG15;
172         p1.h = 0x0;
173         [p0] = p1;
174         csync;
175
176         raise 15;
177         p0.l = .LWAIT_HERE;
178         p0.h = .LWAIT_HERE;
179         reti = p0;
180 #if ANOMALY_05000281
181         nop;
182         nop;
183         nop;
184 #endif
185         rti;
186
187 .LWAIT_HERE:
188         jump .LWAIT_HERE;
189
190 ENTRY(_real_start)
191         [ -- sp ] = reti;
192         p0.l = lo(WDOG_CTL);
193         p0.h = hi(WDOG_CTL);
194         r0 = 0xAD6(z);
195         w[p0] = r0;     /* watchdog off for now */
196         ssync;
197
198         /* Code update for BSS size == 0
199          * Zero out the bss region.
200          */
201
202         p1.l = ___bss_start;
203         p1.h = ___bss_start;
204         p2.l = ___bss_stop;
205         p2.h = ___bss_stop;
206         r0 = 0;
207         p2 -= p1;
208         lsetup (.L_clear_bss, .L_clear_bss ) lc0 = p2;
209 .L_clear_bss:
210         B[p1++] = r0;
211
212         /* In case there is a NULL pointer reference
213          * Zero out region before stext
214          */
215
216         p1.l = 0x0;
217         p1.h = 0x0;
218         r0.l = __stext;
219         r0.h = __stext;
220         r0 = r0 >> 1;
221         p2 = r0;
222         r0 = 0;
223         lsetup (.L_clear_zero, .L_clear_zero ) lc0 = p2;
224 .L_clear_zero:
225         W[p1++] = r0;
226
227         /* pass the uboot arguments to the global value command line */
228         R0 = R7;
229         call _cmdline_init;
230
231         p1.l = __rambase;
232         p1.h = __rambase;
233         r0.l = __sdata;
234         r0.h = __sdata;
235         [p1] = r0;
236
237         p1.l = __ramstart;
238         p1.h = __ramstart;
239         p3.l = ___bss_stop;
240         p3.h = ___bss_stop;
241
242         r1 = p3;
243         [p1] = r1;
244
245
246         /*
247          *  load the current thread pointer and stack
248          */
249         r1.l = _init_thread_union;
250         r1.h = _init_thread_union;
251
252         r2.l = 0x2000;
253         r2.h = 0x0000;
254         r1 = r1 + r2;
255         sp = r1;
256         usp = sp;
257         fp = sp;
258         call _start_kernel;
259 .L_exit:
260         jump.s  .L_exit;
261
262 .section .l1.text
263 #if CONFIG_BFIN_KERNEL_CLOCK
264 ENTRY(_start_dma_code)
265
266         /* Enable PHY CLK buffer output */
267         p0.h = hi(VR_CTL);
268         p0.l = lo(VR_CTL);
269         r0.l = w[p0];
270         bitset(r0, 14);
271         w[p0] = r0.l;
272         ssync;
273
274         p0.h = hi(SIC_IWR);
275         p0.l = lo(SIC_IWR);
276         r0.l = 0x1;
277         r0.h = 0x0;
278         [p0] = r0;
279         SSYNC;
280
281         /*
282          *  Set PLL_CTL
283          *   - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors
284          *   - [8]     = BYPASS    : BYPASS the PLL, run CLKIN into CCLK/SCLK
285          *   - [7]     = output delay (add 200ps of delay to mem signals)
286          *   - [6]     = input delay (add 200ps of input delay to mem signals)
287          *   - [5]     = PDWN      : 1=All Clocks off
288          *   - [3]     = STOPCK    : 1=Core Clock off
289          *   - [1]     = PLL_OFF   : 1=Disable Power to PLL
290          *   - [0]     = DF        : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL
291          *   all other bits set to zero
292          */
293
294         p0.h = hi(PLL_LOCKCNT);
295         p0.l = lo(PLL_LOCKCNT);
296         r0 = 0x300(Z);
297         w[p0] = r0.l;
298         ssync;
299
300         P2.H = hi(EBIU_SDGCTL);
301         P2.L = lo(EBIU_SDGCTL);
302         R0 = [P2];
303         BITSET (R0, 24);
304         [P2] = R0;
305         SSYNC;
306
307         r0 = CONFIG_VCO_MULT & 63;       /* Load the VCO multiplier         */
308         r0 = r0 << 9;                    /* Shift it over,                  */
309         r1 = CLKIN_HALF;                 /* Do we need to divide CLKIN by 2?*/
310         r0 = r1 | r0;
311         r1 = PLL_BYPASS;                 /* Bypass the PLL?                 */
312         r1 = r1 << 8;                    /* Shift it over                   */
313         r0 = r1 | r0;                    /* add them all together           */
314
315         p0.h = hi(PLL_CTL);
316         p0.l = lo(PLL_CTL);              /* Load the address                */
317         cli r2;                          /* Disable interrupts              */
318         ssync;
319         w[p0] = r0.l;                    /* Set the value                   */
320         idle;                            /* Wait for the PLL to stablize    */
321         sti r2;                          /* Enable interrupts               */
322
323 .Lcheck_again:
324         p0.h = hi(PLL_STAT);
325         p0.l = lo(PLL_STAT);
326         R0 = W[P0](Z);
327         CC = BITTST(R0,5);
328         if ! CC jump .Lcheck_again;
329
330         /* Configure SCLK & CCLK Dividers */
331         r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
332         p0.h = hi(PLL_DIV);
333         p0.l = lo(PLL_DIV);
334         w[p0] = r0.l;
335         ssync;
336
337         p0.l = lo(EBIU_SDRRC);
338         p0.h = hi(EBIU_SDRRC);
339         r0 = mem_SDRRC;
340         w[p0] = r0.l;
341         ssync;
342
343         p0.l = LO(EBIU_SDBCTL);
344         p0.h = HI(EBIU_SDBCTL);     /* SDRAM Memory Bank Control Register */
345         r0 = mem_SDBCTL;
346         w[p0] = r0.l;
347         ssync;
348
349         P2.H = hi(EBIU_SDGCTL);
350         P2.L = lo(EBIU_SDGCTL);
351         R0 = [P2];
352         BITCLR (R0, 24);
353         p0.h = hi(EBIU_SDSTAT);
354         p0.l = lo(EBIU_SDSTAT);
355         r2.l = w[p0];
356         cc = bittst(r2,3);
357         if !cc jump .Lskip;
358         NOP;
359         BITSET (R0, 23);
360 .Lskip:
361         [P2] = R0;
362         SSYNC;
363
364         R0.L = lo(mem_SDGCTL);
365         R0.H = hi(mem_SDGCTL);
366         R1 = [p2];
367         R1 = R1 | R0;
368         [P2] = R1;
369         SSYNC;
370
371         p0.h = hi(SIC_IWR);
372         p0.l = lo(SIC_IWR);
373         r0.l = lo(IWR_ENABLE_ALL);
374         r0.h = hi(IWR_ENABLE_ALL);
375         [p0] = r0;
376         SSYNC;
377
378         RTS;
379 #endif /* CONFIG_BFIN_KERNEL_CLOCK */
380
381 ENTRY(_bfin_reset)
382         /* No more interrupts to be handled*/
383         CLI R6;
384         SSYNC;
385
386 #if 0 /* Need to determine later if this is here necessary for BF54x */
387 #if defined(CONFIG_MTD_M25P80)
388 /*
389  * The following code fix the SPI flash reboot issue,
390  * /CS signal of the chip which is using PF10 return to GPIO mode
391  */
392         p0.h = hi(PORTF_FER);
393         p0.l = lo(PORTF_FER);
394         r0.l = 0x0000;
395         w[p0] = r0.l;
396         SSYNC;
397
398 /* /CS return to high */
399         p0.h = hi(PORTFIO);
400         p0.l = lo(PORTFIO);
401         r0.l = 0xFFFF;
402         w[p0] = r0.l;
403         SSYNC;
404
405 /* Delay some time, This is necessary */
406         r1.h = 0;
407         r1.l = 0x400;
408         p1   = r1;
409         lsetup (_delay_lab1,_delay_lab1_end ) lc1 = p1;
410 _delay_lab1:
411         r0.h = 0;
412         r0.l = 0x8000;
413         p0   = r0;
414         lsetup (_delay_lab0,_delay_lab0_end ) lc0 = p0;
415 _delay_lab0:
416         nop;
417 _delay_lab0_end:
418         nop;
419 _delay_lab1_end:
420         nop;
421 #endif
422 #endif
423
424         /* Clear the bits 13-15 in SWRST if they werent cleared */
425         p0.h = hi(SWRST);
426         p0.l = lo(SWRST);
427         csync;
428         r0.l = w[p0];
429
430         /* Clear the IMASK register */
431         p0.h = hi(IMASK);
432         p0.l = lo(IMASK);
433         r0 = 0x0;
434         [p0] = r0;
435
436         /* Clear the ILAT register */
437         p0.h = hi(ILAT);
438         p0.l = lo(ILAT);
439         r0 = [p0];
440         [p0] = r0;
441         SSYNC;
442
443         /* Disable the WDOG TIMER */
444         p0.h = hi(WDOG_CTL);
445         p0.l = lo(WDOG_CTL);
446         r0.l = 0xAD6;
447         w[p0] = r0.l;
448         SSYNC;
449
450         /* Clear the sticky bit incase it is already set */
451         p0.h = hi(WDOG_CTL);
452         p0.l = lo(WDOG_CTL);
453         r0.l = 0x8AD6;
454         w[p0] = r0.l;
455         SSYNC;
456
457         /* Program the count value */
458         R0.l = 0x100;
459         R0.h = 0x0;
460         P0.h = hi(WDOG_CNT);
461         P0.l = lo(WDOG_CNT);
462         [P0] = R0;
463         SSYNC;
464
465         /* Program WDOG_STAT if necessary */
466         P0.h = hi(WDOG_CTL);
467         P0.l = lo(WDOG_CTL);
468         R0 = W[P0](Z);
469         CC = BITTST(R0,1);
470         if !CC JUMP .LWRITESTAT;
471         CC = BITTST(R0,2);
472         if !CC JUMP .LWRITESTAT;
473         JUMP .LSKIP_WRITE;
474
475 .LWRITESTAT:
476         /* When watch dog timer is enabled,
477          * a write to STAT will load the contents of CNT to STAT
478          */
479         R0 = 0x0000(z);
480         P0.h = hi(WDOG_STAT);
481         P0.l = lo(WDOG_STAT)
482         [P0] = R0;
483         SSYNC;
484
485 .LSKIP_WRITE:
486         /* Enable the reset event */
487         P0.h = hi(WDOG_CTL);
488         P0.l = lo(WDOG_CTL);
489         R0 = W[P0](Z);
490         BITCLR(R0,1);
491         BITCLR(R0,2);
492         W[P0] = R0.L;
493         SSYNC;
494         NOP;
495
496         /* Enable the wdog counter */
497         R0 = W[P0](Z);
498         BITCLR(R0,4);
499         W[P0] = R0.L;
500         SSYNC;
501
502         IDLE;
503
504         RTS;
505
506 .data
507
508 /*
509  * Set up the usable of RAM stuff. Size of RAM is determined then
510  * an initial stack set up at the end.
511  */
512
513 .align 4
514 __rambase:
515 .long   0
516 __ramstart:
517 .long   0
518 __ramend:
519 .long   0