Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6
[sfrench/cifs-2.6.git] / arch / blackfin / mach-bf537 / head.S
1 /*
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 <linux/init.h>
32 #include <asm/blackfin.h>
33 #include <asm/trace.h>
34
35 #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
46 #define INITIAL_STACK   0xFFB01000
47
48 __INIT
49
50 ENTRY(__start)
51         /* R0: argument of command line string, passed from uboot, save it */
52         R7 = R0;
53         /* Set the SYSCFG register:
54          * Enable Cycle Counter and Nesting Of Interrupts (3rd Bit)
55          */
56         R0 = 0x36;
57         SYSCFG = R0;
58         R0 = 0;
59
60         /* Clear Out All the data and pointer Registers */
61         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
82         /* Clear Out All the DAG Registers */
83         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
98         trace_buffer_start(p0,r0);
99         P0 = R1;
100         R0 = R1;
101
102         /* 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
192         /* Initialise UART - when booting from u-boot, the UART is not disabled
193          * so if we dont initalize here, our serial console gets hosed */
194         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);
202         r0 = 0x0(Z);
203         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
229
230         /* 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;
284 ENDPROC(__start)
285
286 ENTRY(_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;
304         lsetup (.L_clear_bss, .L_clear_bss) lc0 = p2;
305 .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;
319         lsetup (.L_clear_zero, .L_clear_zero) lc0 = p2;
320 .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
341         /*
342          * load the current thread pointer and stack
343          */
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;
353         jump.l _start_kernel;
354 ENDPROC(_real_start)
355
356 __FINIT
357
358 .section .l1.text
359 #if CONFIG_BFIN_KERNEL_CLOCK
360 ENTRY(_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;
475 ENDPROC(_start_dma_code)
476 #endif /* CONFIG_BFIN_KERNEL_CLOCK */
477
478 ENTRY(_bfin_reset)
479         /* No more interrupts to be handled*/
480         CLI R6;
481         SSYNC;
482
483 #if defined(CONFIG_MTD_M25P80)
484         /*
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          */
488         p0.h = hi(PORTF_FER);
489         p0.l = lo(PORTF_FER);
490         r0.l = 0x0000;
491         w[p0] = r0.l;
492         SSYNC;
493
494         /* /CS return to high */
495         p0.h = hi(PORTFIO);
496         p0.l = lo(PORTFIO);
497         r0.l = 0xFFFF;
498         w[p0] = r0.l;
499         SSYNC;
500
501         /* Delay some time, This is necessary */
502         r1.h = 0;
503         r1.l = 0x400;
504         p1   = r1;
505         lsetup (.L_delay_lab1, .L_delay_lab1_end) lc1 = p1;
506 .L_delay_lab1:
507         r0.h = 0;
508         r0.l = 0x8000;
509         p0   = r0;
510         lsetup (.L_delay_lab0, .L_delay_lab0_end) lc0 = p0;
511 .L_delay_lab0:
512         nop;
513 .L_delay_lab0_end:
514         nop;
515 .L_delay_lab1_end:
516         nop;
517 #endif
518
519         /* 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
532         /* 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;
537         SSYNC;
538
539         /* issue a system soft reset */
540         P1.h = hi(SWRST);
541         P1.l = lo(SWRST);
542         R1.l = 0x0007;
543         W[P1] = R1;
544         SSYNC;
545
546         /* clear system soft reset */
547         R0.l = 0x0000;
548         W[P0] = R0;
549         SSYNC;
550
551         /* issue core reset */
552         raise 1;
553
554         RTS;
555 ENDPROC(_bfin_reset)
556
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