Merge branches 'release', 'asus', 'sony-laptop' and 'thinkpad' into release
[pandora-kernel.git] / 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 #ifdef CONFIG_EARLY_PRINTK
129         SP += -12;
130         call _init_early_exception_vectors;
131         SP += 12;
132 #endif
133
134         /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */
135         call _bf53x_relocate_l1_mem;
136 #if CONFIG_BFIN_KERNEL_CLOCK
137         call _start_dma_code;
138 #endif
139         /* Code for initializing Async memory banks */
140
141         p2.h = hi(EBIU_AMBCTL1);
142         p2.l = lo(EBIU_AMBCTL1);
143         r0.h = hi(AMBCTL1VAL);
144         r0.l = lo(AMBCTL1VAL);
145         [p2] = r0;
146         ssync;
147
148         p2.h = hi(EBIU_AMBCTL0);
149         p2.l = lo(EBIU_AMBCTL0);
150         r0.h = hi(AMBCTL0VAL);
151         r0.l = lo(AMBCTL0VAL);
152         [p2] = r0;
153         ssync;
154
155         p2.h = hi(EBIU_AMGCTL);
156         p2.l = lo(EBIU_AMGCTL);
157         r0 = AMGCTLVAL;
158         w[p2] = r0;
159         ssync;
160
161         p2.h = hi(EBIU_MBSCTL);
162         p2.l = lo(EBIU_MBSCTL);
163         r0.h = hi(CONFIG_EBIU_MBSCTLVAL);
164         r0.l = lo(CONFIG_EBIU_MBSCTLVAL);
165         [p2] = r0;
166         ssync;
167
168         p2.h = hi(EBIU_MODE);
169         p2.l = lo(EBIU_MODE);
170         r0.h = hi(CONFIG_EBIU_MODEVAL);
171         r0.l = lo(CONFIG_EBIU_MODEVAL);
172         [p2] = r0;
173         ssync;
174
175         p2.h = hi(EBIU_FCTL);
176         p2.l = lo(EBIU_FCTL);
177         r0.h = hi(CONFIG_EBIU_FCTLVAL);
178         r0.l = lo(CONFIG_EBIU_FCTLVAL);
179         [p2] = r0;
180         ssync;
181
182         /* This section keeps the processor in supervisor mode
183          * during kernel boot.  Switches to user mode at end of boot.
184          * See page 3-9 of Hardware Reference manual for documentation.
185          */
186
187         /* EVT15 = _real_start */
188
189         p0.l = lo(EVT15);
190         p0.h = hi(EVT15);
191         p1.l = _real_start;
192         p1.h = _real_start;
193         [p0] = p1;
194         csync;
195
196         p0.l = lo(IMASK);
197         p0.h = hi(IMASK);
198         p1.l = IMASK_IVG15;
199         p1.h = 0x0;
200         [p0] = p1;
201         csync;
202
203         raise 15;
204         p0.l = .LWAIT_HERE;
205         p0.h = .LWAIT_HERE;
206         reti = p0;
207 #if ANOMALY_05000281
208         nop;
209         nop;
210         nop;
211 #endif
212         rti;
213
214 .LWAIT_HERE:
215         jump .LWAIT_HERE;
216
217 ENTRY(_real_start)
218         [ -- sp ] = reti;
219         p0.l = lo(WDOG_CTL);
220         p0.h = hi(WDOG_CTL);
221         r0 = 0xAD6(z);
222         w[p0] = r0;     /* watchdog off for now */
223         ssync;
224
225         /* Code update for BSS size == 0
226          * Zero out the bss region.
227          */
228
229         p1.l = ___bss_start;
230         p1.h = ___bss_start;
231         p2.l = ___bss_stop;
232         p2.h = ___bss_stop;
233         r0 = 0;
234         p2 -= p1;
235         lsetup (.L_clear_bss, .L_clear_bss ) lc0 = p2;
236 .L_clear_bss:
237         B[p1++] = r0;
238
239         /* In case there is a NULL pointer reference
240          * Zero out region before stext
241          */
242
243         p1.l = 0x0;
244         p1.h = 0x0;
245         r0.l = __stext;
246         r0.h = __stext;
247         r0 = r0 >> 1;
248         p2 = r0;
249         r0 = 0;
250         lsetup (.L_clear_zero, .L_clear_zero ) lc0 = p2;
251 .L_clear_zero:
252         W[p1++] = r0;
253
254         /* pass the uboot arguments to the global value command line */
255         R0 = R7;
256         call _cmdline_init;
257
258         p1.l = __rambase;
259         p1.h = __rambase;
260         r0.l = __sdata;
261         r0.h = __sdata;
262         [p1] = r0;
263
264         p1.l = __ramstart;
265         p1.h = __ramstart;
266         p3.l = ___bss_stop;
267         p3.h = ___bss_stop;
268
269         r1 = p3;
270         [p1] = r1;
271
272
273         /*
274          *  load the current thread pointer and stack
275          */
276         r1.l = _init_thread_union;
277         r1.h = _init_thread_union;
278
279         r2.l = 0x2000;
280         r2.h = 0x0000;
281         r1 = r1 + r2;
282         sp = r1;
283         usp = sp;
284         fp = sp;
285         call _start_kernel;
286 .L_exit:
287         jump.s  .L_exit;
288
289 .section .l1.text
290 #if CONFIG_BFIN_KERNEL_CLOCK
291 ENTRY(_start_dma_code)
292
293         /* Enable PHY CLK buffer output */
294         p0.h = hi(VR_CTL);
295         p0.l = lo(VR_CTL);
296         r0.l = w[p0];
297         bitset(r0, 14);
298         w[p0] = r0.l;
299         ssync;
300
301         p0.h = hi(SIC_IWR0);
302         p0.l = lo(SIC_IWR0);
303         r0.l = 0x1;
304         r0.h = 0x0;
305         [p0] = r0;
306         SSYNC;
307
308         /*
309          *  Set PLL_CTL
310          *   - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors
311          *   - [8]     = BYPASS    : BYPASS the PLL, run CLKIN into CCLK/SCLK
312          *   - [7]     = output delay (add 200ps of delay to mem signals)
313          *   - [6]     = input delay (add 200ps of input delay to mem signals)
314          *   - [5]     = PDWN      : 1=All Clocks off
315          *   - [3]     = STOPCK    : 1=Core Clock off
316          *   - [1]     = PLL_OFF   : 1=Disable Power to PLL
317          *   - [0]     = DF        : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL
318          *   all other bits set to zero
319          */
320
321         p0.h = hi(PLL_LOCKCNT);
322         p0.l = lo(PLL_LOCKCNT);
323         r0 = 0x300(Z);
324         w[p0] = r0.l;
325         ssync;
326
327 #if defined(CONFIG_BF54x)
328         P2.H = hi(EBIU_RSTCTL);
329         P2.L = lo(EBIU_RSTCTL);
330         R0 = [P2];
331         BITSET (R0, 3);
332 #else
333         P2.H = hi(EBIU_SDGCTL);
334         P2.L = lo(EBIU_SDGCTL);
335         R0 = [P2];
336         BITSET (R0, 24);
337 #endif
338         [P2] = R0;
339         SSYNC;
340 #if defined(CONFIG_BF54x)
341 .LSRR_MODE:
342         R0 = [P2];
343         CC = BITTST(R0, 4);
344         if !CC JUMP .LSRR_MODE;
345 #endif
346
347         r0 = CONFIG_VCO_MULT & 63;       /* Load the VCO multiplier         */
348         r0 = r0 << 9;                    /* Shift it over,                  */
349         r1 = CLKIN_HALF;                 /* Do we need to divide CLKIN by 2?*/
350         r0 = r1 | r0;
351         r1 = PLL_BYPASS;                 /* Bypass the PLL?                 */
352         r1 = r1 << 8;                    /* Shift it over                   */
353         r0 = r1 | r0;                    /* add them all together           */
354
355         p0.h = hi(PLL_CTL);
356         p0.l = lo(PLL_CTL);              /* Load the address                */
357         cli r2;                          /* Disable interrupts              */
358         ssync;
359         w[p0] = r0.l;                    /* Set the value                   */
360         idle;                            /* Wait for the PLL to stablize    */
361         sti r2;                          /* Enable interrupts               */
362
363 .Lcheck_again:
364         p0.h = hi(PLL_STAT);
365         p0.l = lo(PLL_STAT);
366         R0 = W[P0](Z);
367         CC = BITTST(R0,5);
368         if ! CC jump .Lcheck_again;
369
370         /* Configure SCLK & CCLK Dividers */
371         r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
372         p0.h = hi(PLL_DIV);
373         p0.l = lo(PLL_DIV);
374         w[p0] = r0.l;
375         ssync;
376
377 #if defined(CONFIG_BF54x)
378         P2.H = hi(EBIU_RSTCTL);
379         P2.L = lo(EBIU_RSTCTL);
380         R0 = [P2];
381         CC = BITTST(R0, 0);
382         if CC jump .Lskipddrrst;
383         BITSET (R0, 0);
384 .Lskipddrrst:
385         BITCLR (R0, 3);
386         [P2] = R0;
387         SSYNC;
388
389         p0.l = lo(EBIU_DDRCTL0);
390         p0.h = hi(EBIU_DDRCTL0);
391         r0.l = lo(mem_DDRCTL0);
392         r0.h = hi(mem_DDRCTL0);
393         [p0] = r0;
394         ssync;
395
396         p0.l = lo(EBIU_DDRCTL1);
397         p0.h = hi(EBIU_DDRCTL1);
398         r0.l = lo(mem_DDRCTL1);
399         r0.h = hi(mem_DDRCTL1);
400         [p0] = r0;
401         ssync;
402
403         p0.l = lo(EBIU_DDRCTL2);
404         p0.h = hi(EBIU_DDRCTL2);
405         r0.l = lo(mem_DDRCTL2);
406         r0.h = hi(mem_DDRCTL2);
407         [p0] = r0;
408         ssync;
409 #else
410         p0.l = lo(EBIU_SDRRC);
411         p0.h = hi(EBIU_SDRRC);
412         r0 = mem_SDRRC;
413         w[p0] = r0.l;
414         ssync;
415
416         p0.l = LO(EBIU_SDBCTL);
417         p0.h = HI(EBIU_SDBCTL);     /* SDRAM Memory Bank Control Register */
418         r0 = mem_SDBCTL;
419         w[p0] = r0.l;
420         ssync;
421
422         P2.H = hi(EBIU_SDGCTL);
423         P2.L = lo(EBIU_SDGCTL);
424         R0 = [P2];
425         BITCLR (R0, 24);
426         p0.h = hi(EBIU_SDSTAT);
427         p0.l = lo(EBIU_SDSTAT);
428         r2.l = w[p0];
429         cc = bittst(r2,3);
430         if !cc jump .Lskip;
431         NOP;
432         BITSET (R0, 23);
433 .Lskip:
434         [P2] = R0;
435         SSYNC;
436
437         R0.L = lo(mem_SDGCTL);
438         R0.H = hi(mem_SDGCTL);
439         R1 = [p2];
440         R1 = R1 | R0;
441         [P2] = R1;
442         SSYNC;
443 #endif
444
445         p0.h = hi(SIC_IWR0);
446         p0.l = lo(SIC_IWR0);
447         r0.l = lo(IWR_ENABLE_ALL);
448         r0.h = hi(IWR_ENABLE_ALL);
449         [p0] = r0;
450         SSYNC;
451
452         RTS;
453 #endif /* CONFIG_BFIN_KERNEL_CLOCK */
454
455 .data
456
457 /*
458  * Set up the usable of RAM stuff. Size of RAM is determined then
459  * an initial stack set up at the end.
460  */
461
462 .align 4
463 __rambase:
464 .long   0
465 __ramstart:
466 .long   0
467 __ramend:
468 .long   0