Blackfin arch: unify differences between our diff head.S files -- no functional changes
[platform/kernel/linux-starfive.git] / arch / blackfin / mach-bf533 / head.S
1 /*
2  * File:         arch/blackfin/mach-bf533/head.S
3  * Based on:
4  * Author:       Jeff Dionne <jeff@uclinux.org> COPYRIGHT 1998 D. Jeff Dionne
5  *
6  * Created:      1998
7  * Description:  bf533 startup file
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 #if CONFIG_DEBUG_KERNEL_START
36 #include <asm/mach-common/def_LPBlackfin.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 .text
49
50 ENTRY(__start)
51 ENTRY(__stext)
52         /* R0: argument of command line string, passed from uboot, save it */
53         R7 = R0;
54         /* Set the SYSCFG register:
55          * Enable Cycle Counter and Nesting Of Interrupts (3rd Bit)
56          */
57         R0 = 0x36;
58         SYSCFG = R0;
59         R0 = 0;
60
61         /* Clear Out All the data and pointer Registers */
62         R1 = R0;
63         R2 = R0;
64         R3 = R0;
65         R4 = R0;
66         R5 = R0;
67         R6 = R0;
68
69         P0 = R0;
70         P1 = R0;
71         P2 = R0;
72         P3 = R0;
73         P4 = R0;
74         P5 = R0;
75
76         LC0 = r0;
77         LC1 = r0;
78         L0 = r0;
79         L1 = r0;
80         L2 = r0;
81         L3 = r0;
82
83         /* Clear Out All the DAG Registers */
84         B0 = r0;
85         B1 = r0;
86         B2 = r0;
87         B3 = r0;
88
89         I0 = r0;
90         I1 = r0;
91         I2 = r0;
92         I3 = r0;
93
94         M0 = r0;
95         M1 = r0;
96         M2 = r0;
97         M3 = r0;
98
99 #if CONFIG_DEBUG_KERNEL_START
100
101 /*
102  * Set up a temporary Event Vector Table, so if something bad happens before
103  * the kernel is fully started, it doesn't vector off into the bootloaders
104  * table
105  */
106         P0.l = lo(EVT2);
107         P0.h = hi(EVT2);
108         P1.l = lo(EVT15);
109         P1.h = hi(EVT15);
110         P2.l = debug_kernel_start_trap;
111         P2.h = debug_kernel_start_trap;
112
113         RTS = P2;
114         RTI = P2;
115         RTX = P2;
116         RTN = P2;
117         RTE = P2;
118
119 .Lfill_temp_vector_table:
120         [P0++] = P2;    /* Core Event Vector Table */
121         CC = P0 == P1;
122         if !CC JUMP .Lfill_temp_vector_table
123         P0 = r0;
124         P1 = r0;
125         P2 = r0;
126
127 #endif
128
129         p0.h = hi(FIO_MASKA_C);
130         p0.l = lo(FIO_MASKA_C);
131         r0 = 0xFFFF(Z);
132         w[p0] = r0.L;   /* Disable all interrupts */
133         ssync;
134
135         p0.h = hi(FIO_MASKB_C);
136         p0.l = lo(FIO_MASKB_C);
137         r0 = 0xFFFF(Z);
138         w[p0] = r0.L;   /* Disable all interrupts */
139         ssync;
140
141         /* Turn off the icache */
142         p0.l = (IMEM_CONTROL & 0xFFFF);
143         p0.h = (IMEM_CONTROL >> 16);
144         R1 = [p0];
145         R0 = ~ENICPLB;
146         R0 = R0 & R1;
147
148         /* Anomaly 05000125 */
149 #ifdef ANOMALY_05000125
150         CLI R2;
151         SSYNC;
152 #endif
153         [p0] = R0;
154         SSYNC;
155 #ifdef ANOMALY_05000125
156         STI R2;
157 #endif
158
159         /* Turn off the dcache */
160         p0.l = (DMEM_CONTROL & 0xFFFF);
161         p0.h = (DMEM_CONTROL >> 16);
162         R1 = [p0];
163         R0 = ~ENDCPLB;
164         R0 = R0 & R1;
165
166         /* Anomaly 05000125 */
167 #ifdef ANOMALY_05000125
168         CLI R2;
169         SSYNC;
170 #endif
171         [p0] = R0;
172         SSYNC;
173 #ifdef ANOMALY_05000125
174         STI R2;
175 #endif
176
177         /* Initialise UART - when booting from u-boot, the UART is not disabled
178          * so if we dont initalize here, our serial console gets hosed */
179         p0.h = hi(UART_LCR);
180         p0.l = lo(UART_LCR);
181         r0 = 0x0(Z);
182         w[p0] = r0.L;   /* To enable DLL writes */
183         ssync;
184
185         p0.h = hi(UART_DLL);
186         p0.l = lo(UART_DLL);
187         r0 = 0x0(Z);
188         w[p0] = r0.L;
189         ssync;
190
191         p0.h = hi(UART_DLH);
192         p0.l = lo(UART_DLH);
193         r0 = 0x00(Z);
194         w[p0] = r0.L;
195         ssync;
196
197         p0.h = hi(UART_GCTL);
198         p0.l = lo(UART_GCTL);
199         r0 = 0x0(Z);
200         w[p0] = r0.L;   /* To enable UART clock */
201         ssync;
202
203         /* Initialize stack pointer */
204         sp.l = lo(INITIAL_STACK);
205         sp.h = hi(INITIAL_STACK);
206         fp = sp;
207         usp = sp;
208
209         /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */
210         call _bf53x_relocate_l1_mem;
211 #if CONFIG_BFIN_KERNEL_CLOCK
212         call _start_dma_code;
213 #endif
214
215         /* Code for initializing Async memory banks */
216
217         p2.h = hi(EBIU_AMBCTL1);
218         p2.l = lo(EBIU_AMBCTL1);
219         r0.h = hi(AMBCTL1VAL);
220         r0.l = lo(AMBCTL1VAL);
221         [p2] = r0;
222         ssync;
223
224         p2.h = hi(EBIU_AMBCTL0);
225         p2.l = lo(EBIU_AMBCTL0);
226         r0.h = hi(AMBCTL0VAL);
227         r0.l = lo(AMBCTL0VAL);
228         [p2] = r0;
229         ssync;
230
231         p2.h = hi(EBIU_AMGCTL);
232         p2.l = lo(EBIU_AMGCTL);
233         r0 = AMGCTLVAL;
234         w[p2] = r0;
235         ssync;
236
237         /* This section keeps the processor in supervisor mode
238          * during kernel boot.  Switches to user mode at end of boot.
239          * See page 3-9 of Hardware Reference manual for documentation.
240          */
241
242         /* EVT15 = _real_start */
243
244         p0.l = lo(EVT15);
245         p0.h = hi(EVT15);
246         p1.l = _real_start;
247         p1.h = _real_start;
248         [p0] = p1;
249         csync;
250
251         p0.l = lo(IMASK);
252         p0.h = hi(IMASK);
253         p1.l = IMASK_IVG15;
254         p1.h = 0x0;
255         [p0] = p1;
256         csync;
257
258         raise 15;
259         p0.l = .LWAIT_HERE;
260         p0.h = .LWAIT_HERE;
261         reti = p0;
262 #if defined(ANOMALY_05000281)
263         nop; nop; nop;
264 #endif
265         rti;
266
267 .LWAIT_HERE:
268         jump .LWAIT_HERE;
269
270 ENTRY(_real_start)
271         [ -- sp ] = reti;
272         p0.l = lo(WDOG_CTL);
273         p0.h = hi(WDOG_CTL);
274         r0 = 0xAD6(z);
275         w[p0] = r0;     /* watchdog off for now */
276         ssync;
277
278         /* Code update for BSS size == 0
279          * Zero out the bss region.
280          */
281
282         p1.l = ___bss_start;
283         p1.h = ___bss_start;
284         p2.l = ___bss_stop;
285         p2.h = ___bss_stop;
286         r0 = 0;
287         p2 -= p1;
288         lsetup (.L_clear_bss, .L_clear_bss) lc0 = p2;
289 .L_clear_bss:
290         B[p1++] = r0;
291
292         /* In case there is a NULL pointer reference
293          * Zero out region before stext
294          */
295
296         p1.l = 0x0;
297         p1.h = 0x0;
298         r0.l = __stext;
299         r0.h = __stext;
300         r0 = r0 >> 1;
301         p2 = r0;
302         r0 = 0;
303         lsetup (.L_clear_zero, .L_clear_zero) lc0 = p2;
304 .L_clear_zero:
305         W[p1++] = r0;
306
307         /* pass the uboot arguments to the global value command line */
308         R0 = R7;
309         call _cmdline_init;
310
311         p1.l = __rambase;
312         p1.h = __rambase;
313         r0.l = __sdata;
314         r0.h = __sdata;
315         [p1] = r0;
316
317         p1.l = __ramstart;
318         p1.h = __ramstart;
319         p3.l = ___bss_stop;
320         p3.h = ___bss_stop;
321
322         r1 = p3;
323         [p1] = r1;
324
325         /*
326          * load the current thread pointer and stack
327          */
328         r1.l = _init_thread_union;
329         r1.h = _init_thread_union;
330
331         r2.l = 0x2000;
332         r2.h = 0x0000;
333         r1 = r1 + r2;
334         sp = r1;
335         usp = sp;
336         fp = sp;
337         call _start_kernel;
338 .L_exit:
339         jump.s  .L_exit;
340
341 .section .l1.text
342 #if CONFIG_BFIN_KERNEL_CLOCK
343 ENTRY(_start_dma_code)
344         p0.h = hi(SIC_IWR);
345         p0.l = lo(SIC_IWR);
346         r0.l = 0x1;
347         r0.h = 0x0;
348         [p0] = r0;
349         SSYNC;
350
351         /*
352          *  Set PLL_CTL
353          *   - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors
354          *   - [8]     = BYPASS    : BYPASS the PLL, run CLKIN into CCLK/SCLK
355          *   - [7]     = output delay (add 200ps of delay to mem signals)
356          *   - [6]     = input delay (add 200ps of input delay to mem signals)
357          *   - [5]     = PDWN      : 1=All Clocks off
358          *   - [3]     = STOPCK    : 1=Core Clock off
359          *   - [1]     = PLL_OFF   : 1=Disable Power to PLL
360          *   - [0]     = DF        : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL
361          *   all other bits set to zero
362          */
363
364         p0.h = hi(PLL_LOCKCNT);
365         p0.l = lo(PLL_LOCKCNT);
366         r0 = 0x300(Z);
367         w[p0] = r0.l;
368         ssync;
369
370         P2.H = hi(EBIU_SDGCTL);
371         P2.L = lo(EBIU_SDGCTL);
372         R0 = [P2];
373         BITSET (R0, 24);
374         [P2] = R0;
375         SSYNC;
376
377         r0 = CONFIG_VCO_MULT & 63;       /* Load the VCO multiplier         */
378         r0 = r0 << 9;                    /* Shift it over,                  */
379         r1 = CLKIN_HALF;                 /* Do we need to divide CLKIN by 2?*/
380         r0 = r1 | r0;
381         r1 = PLL_BYPASS;                 /* Bypass the PLL?                 */
382         r1 = r1 << 8;                    /* Shift it over                   */
383         r0 = r1 | r0;                    /* add them all together           */
384
385         p0.h = hi(PLL_CTL);
386         p0.l = lo(PLL_CTL);              /* Load the address                */
387         cli r2;                          /* Disable interrupts              */
388         ssync;
389         w[p0] = r0.l;                    /* Set the value                   */
390         idle;                            /* Wait for the PLL to stablize    */
391         sti r2;                          /* Enable interrupts               */
392
393 .Lcheck_again:
394         p0.h = hi(PLL_STAT);
395         p0.l = lo(PLL_STAT);
396         R0 = W[P0](Z);
397         CC = BITTST(R0,5);
398         if ! CC jump .Lcheck_again;
399
400         /* Configure SCLK & CCLK Dividers */
401         r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
402         p0.h = hi(PLL_DIV);
403         p0.l = lo(PLL_DIV);
404         w[p0] = r0.l;
405         ssync;
406
407         p0.l = lo(EBIU_SDRRC);
408         p0.h = hi(EBIU_SDRRC);
409         r0 = mem_SDRRC;
410         w[p0] = r0.l;
411         ssync;
412
413         p0.l = (EBIU_SDBCTL & 0xFFFF);
414         p0.h = (EBIU_SDBCTL >> 16);     /* SDRAM Memory Bank Control Register */
415         r0 = mem_SDBCTL;
416         w[p0] = r0.l;
417         ssync;
418
419         P2.H = hi(EBIU_SDGCTL);
420         P2.L = lo(EBIU_SDGCTL);
421         R0 = [P2];
422         BITCLR (R0, 24);
423         p0.h = hi(EBIU_SDSTAT);
424         p0.l = lo(EBIU_SDSTAT);
425         r2.l = w[p0];
426         cc = bittst(r2,3);
427         if !cc jump .Lskip;
428         NOP;
429         BITSET (R0, 23);
430 .Lskip:
431         [P2] = R0;
432         SSYNC;
433
434         R0.L = lo(mem_SDGCTL);
435         R0.H = hi(mem_SDGCTL);
436         R1 = [p2];
437         R1 = R1 | R0;
438         [P2] = R1;
439         SSYNC;
440
441         p0.h = hi(SIC_IWR);
442         p0.l = lo(SIC_IWR);
443         r0.l = lo(IWR_ENABLE_ALL);
444         r0.h = hi(IWR_ENABLE_ALL);
445         [p0] = r0;
446         SSYNC;
447
448         RTS;
449 #endif /* CONFIG_BFIN_KERNEL_CLOCK */
450
451 ENTRY(_bfin_reset)
452         /* No more interrupts to be handled*/
453         CLI R6;
454         SSYNC;
455
456 #if defined(CONFIG_BFIN_SHARED_FLASH_ENET)
457         p0.h = hi(FIO_INEN);
458         p0.l = lo(FIO_INEN);
459         r0.l = ~(1 << CONFIG_ENET_FLASH_PIN);
460         w[p0] = r0.l;
461
462         p0.h = hi(FIO_DIR);
463         p0.l = lo(FIO_DIR);
464         r0.l = (1 << CONFIG_ENET_FLASH_PIN);
465         w[p0] = r0.l;
466
467         p0.h = hi(FIO_FLAG_C);
468         p0.l = lo(FIO_FLAG_C);
469         r0.l = (1 << CONFIG_ENET_FLASH_PIN);
470         w[p0] = r0.l;
471 #endif
472
473         /* Clear the IMASK register */
474         p0.h = hi(IMASK);
475         p0.l = lo(IMASK);
476         r0 = 0x0;
477         [p0] = r0;
478
479         /* Clear the ILAT register */
480         p0.h = hi(ILAT);
481         p0.l = lo(ILAT);
482         r0 = [p0];
483         [p0] = r0;
484         SSYNC;
485
486         /* make sure SYSCR is set to use BMODE */
487         P0.h = hi(SYSCR);
488         P0.l = lo(SYSCR);
489         R0.l = 0x0;
490         W[P0] = R0.l;
491         SSYNC;
492
493         /* issue a system soft reset */
494         P1.h = hi(SWRST);
495         P1.l = lo(SWRST);
496         R1.l = 0x0007;
497         W[P1] = R1;
498         SSYNC;
499
500         /* clear system soft reset */
501         R0.l = 0x0000;
502         W[P0] = R0;
503         SSYNC;
504
505         /* issue core reset */
506         raise 1;
507
508         RTS;
509 ENDPROC(_bfin_reset)
510
511 #if CONFIG_DEBUG_KERNEL_START
512 debug_kernel_start_trap:
513         /* Set up a temp stack in L1 - SDRAM might not be working  */
514         P0.L = lo(L1_DATA_A_START + 0x100);
515         P0.H = hi(L1_DATA_A_START + 0x100);
516         SP = P0;
517
518         /* Make sure the Clocks are the way I think they should be */
519         r0 = CONFIG_VCO_MULT & 63;       /* Load the VCO multiplier         */
520         r0 = r0 << 9;                    /* Shift it over,                  */
521         r1 = CLKIN_HALF;                 /* Do we need to divide CLKIN by 2?*/
522         r0 = r1 | r0;
523         r1 = PLL_BYPASS;                 /* Bypass the PLL?                 */
524         r1 = r1 << 8;                    /* Shift it over                   */
525         r0 = r1 | r0;                    /* add them all together           */
526
527         p0.h = hi(PLL_CTL);
528         p0.l = lo(PLL_CTL);              /* Load the address                */
529         cli r2;                          /* Disable interrupts              */
530         ssync;
531         w[p0] = r0.l;                    /* Set the value                   */
532         idle;                            /* Wait for the PLL to stablize    */
533         sti r2;                          /* Enable interrupts               */
534
535 .Lcheck_again1:
536         p0.h = hi(PLL_STAT);
537         p0.l = lo(PLL_STAT);
538         R0 = W[P0](Z);
539         CC = BITTST(R0,5);
540         if ! CC jump .Lcheck_again1;
541
542         /* Configure SCLK & CCLK Dividers */
543         r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
544         p0.h = hi(PLL_DIV);
545         p0.l = lo(PLL_DIV);
546         w[p0] = r0.l;
547         ssync;
548
549         /* Make sure UART is enabled - you can never be sure */
550
551 /*
552  * Setup for console. Argument comes from the menuconfig
553  */
554
555 #ifdef CONFIG_BAUD_9600
556 #define CONSOLE_BAUD_RATE       9600
557 #elif CONFIG_BAUD_19200
558 #define CONSOLE_BAUD_RATE       19200
559 #elif CONFIG_BAUD_38400
560 #define CONSOLE_BAUD_RATE       38400
561 #elif CONFIG_BAUD_57600
562 #define CONSOLE_BAUD_RATE       57600
563 #elif CONFIG_BAUD_115200
564 #define CONSOLE_BAUD_RATE       115200
565 #endif
566
567         p0.h = hi(UART_GCTL);
568         p0.l = lo(UART_GCTL);
569         r0 = 0x00(Z);
570         w[p0] = r0.L;   /* To Turn off UART clocks */
571         ssync;
572
573         p0.h = hi(UART_LCR);
574         p0.l = lo(UART_LCR);
575         r0 = 0x83(Z);
576         w[p0] = r0.L;   /* To enable DLL writes */
577         ssync;
578
579         R1 = (((CONFIG_CLKIN_HZ * CONFIG_VCO_MULT) / CONFIG_SCLK_DIV) / (CONSOLE_BAUD_RATE * 16));
580
581         p0.h = hi(UART_DLL);
582         p0.l = lo(UART_DLL);
583         r0 = 0xFF(Z);
584         r0 = R1 & R0;
585         w[p0] = r0.L;
586         ssync;
587
588         p0.h = hi(UART_DLH);
589         p0.l = lo(UART_DLH);
590         r1 >>= 8 ;
591         w[p0] = r1.L;
592         ssync;
593
594         p0.h = hi(UART_GCTL);
595         p0.l = lo(UART_GCTL);
596         r0 = 0x0(Z);
597         w[p0] = r0.L;   /* To enable UART clock */
598         ssync;
599
600         p0.h = hi(UART_LCR);
601         p0.l = lo(UART_LCR);
602         r0 = 0x03(Z);
603         w[p0] = r0.L;   /* To Turn on UART */
604         ssync;
605
606         p0.h = hi(UART_GCTL);
607         p0.l = lo(UART_GCTL);
608         r0 = 0x01(Z);
609         w[p0] = r0.L;   /* To Turn on UART Clocks */
610         ssync;
611
612         P0.h = hi(UART_THR);
613         P0.l = lo(UART_THR);
614         P1.h = hi(UART_LSR);
615         P1.l = lo(UART_LSR);
616
617         R0.L = 'K';
618         call .Lwait_char;
619         R0.L='e';
620         call .Lwait_char;
621         R0.L='r';
622         call .Lwait_char;
623         R0.L='n'
624         call .Lwait_char;
625         R0.L='e'
626         call .Lwait_char;
627         R0.L='l';
628         call .Lwait_char;
629         R0.L=' ';
630         call .Lwait_char;
631         R0.L='c';
632         call .Lwait_char;
633         R0.L='r';
634         call .Lwait_char;
635         R0.L='a';
636         call .Lwait_char;
637         R0.L='s';
638         call .Lwait_char;
639         R0.L='h';
640         call .Lwait_char;
641         R0.L='\r';
642         call .Lwait_char;
643         R0.L='\n';
644         call .Lwait_char;
645
646         R0.L='S';
647         call .Lwait_char;
648         R0.L='E';
649         call .Lwait_char;
650         R0.L='Q'
651         call .Lwait_char;
652         R0.L='S'
653         call .Lwait_char;
654         R0.L='T';
655         call .Lwait_char;
656         R0.L='A';
657         call .Lwait_char;
658         R0.L='T';
659         call .Lwait_char;
660         R0.L='=';
661         call .Lwait_char;
662         R2 = SEQSTAT;
663         call .Ldump_reg;
664
665         R0.L=' ';
666         call .Lwait_char;
667         R0.L='R';
668         call .Lwait_char;
669         R0.L='E'
670         call .Lwait_char;
671         R0.L='T'
672         call .Lwait_char;
673         R0.L='X';
674         call .Lwait_char;
675         R0.L='=';
676         call .Lwait_char;
677         R2 = RETX;
678         call .Ldump_reg;
679
680         R0.L='\r';
681         call .Lwait_char;
682         R0.L='\n';
683         call .Lwait_char;
684
685 .Ldebug_kernel_start_trap_done:
686         JUMP    .Ldebug_kernel_start_trap_done;
687 .Ldump_reg:
688         R3 = 32;
689         R4 = 0x0F;
690         R5 = ':';  /* one past 9 */
691
692 .Ldump_reg2:
693         R0 = R2;
694         R3 += -4;
695         R0 >>>= R3;
696         R0 = R0 & R4;
697         R0 += 0x30;
698         CC = R0 <= R5;
699         if CC JUMP .Ldump_reg1;
700         R0 += 7;
701
702 .Ldump_reg1:
703         R1.l = W[P1];
704         CC = BITTST(R1, 5);
705         if !CC JUMP .Ldump_reg1;
706         W[P0] = r0;
707
708         CC = R3 == 0;
709         if !CC JUMP .Ldump_reg2
710         RTS;
711
712 .Lwait_char:
713         R1.l = W[P1];
714         CC = BITTST(R1, 5);
715         if !CC JUMP .Lwait_char;
716         W[P0] = r0;
717         RTS;
718
719 #endif  /* CONFIG_DEBUG_KERNEL_START  */
720
721 .data
722
723 /*
724  * Set up the usable of RAM stuff. Size of RAM is determined then
725  * an initial stack set up at the end.
726  */
727
728 .align 4
729 __rambase:
730 .long   0
731 __ramstart:
732 .long   0
733 __ramend:
734 .long   0