Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/cooloney...
[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 <linux/init.h>
32 #include <asm/blackfin.h>
33 #include <asm/trace.h>
34 #ifdef CONFIG_BFIN_KERNEL_CLOCK
35 #include <asm/mach-common/clocks.h>
36 #include <asm/mach/mem_init.h>
37 #endif
38
39 .extern ___bss_stop
40 .extern ___bss_start
41 .extern _bf53x_relocate_l1_mem
42
43 #define INITIAL_STACK   0xFFB01000
44
45 __INIT
46
47 ENTRY(__start)
48         /* R0: argument of command line string, passed from uboot, save it */
49         R7 = R0;
50         /* Enable Cycle Counter and Nesting Of Interrupts */
51 #ifdef CONFIG_BFIN_SCRATCH_REG_CYCLES
52         R0 = SYSCFG_SNEN;
53 #else
54         R0 = SYSCFG_SNEN | SYSCFG_CCEN;
55 #endif
56         SYSCFG = R0;
57         R0 = 0;
58
59         /* Clear Out All the data and pointer  Registers*/
60         R1 = R0;
61         R2 = R0;
62         R3 = R0;
63         R4 = R0;
64         R5 = R0;
65         R6 = R0;
66
67         P0 = R0;
68         P1 = R0;
69         P2 = R0;
70         P3 = R0;
71         P4 = R0;
72         P5 = R0;
73
74         LC0 = r0;
75         LC1 = r0;
76         L0 = r0;
77         L1 = r0;
78         L2 = r0;
79         L3 = r0;
80
81         /* Clear Out All the DAG Registers*/
82         B0 = r0;
83         B1 = r0;
84         B2 = r0;
85         B3 = r0;
86
87         I0 = r0;
88         I1 = r0;
89         I2 = r0;
90         I3 = r0;
91
92         M0 = r0;
93         M1 = r0;
94         M2 = r0;
95         M3 = r0;
96
97         trace_buffer_init(p0,r0);
98         P0 = R1;
99         R0 = R1;
100
101         /* Turn off the icache */
102         p0.l = LO(IMEM_CONTROL);
103         p0.h = HI(IMEM_CONTROL);
104         R1 = [p0];
105         R0 = ~ENICPLB;
106         R0 = R0 & R1;
107         [p0] = R0;
108         SSYNC;
109
110         /* Turn off the dcache */
111         p0.l = LO(DMEM_CONTROL);
112         p0.h = HI(DMEM_CONTROL);
113         R1 = [p0];
114         R0 = ~ENDCPLB;
115         R0 = R0 & R1;
116         [p0] = R0;
117         SSYNC;
118
119         /* Initialize stack pointer */
120         SP.L = LO(INITIAL_STACK);
121         SP.H = HI(INITIAL_STACK);
122         FP = SP;
123         USP = SP;
124
125 #ifdef CONFIG_EARLY_PRINTK
126         SP += -12;
127         call _init_early_exception_vectors;
128         SP += 12;
129 #endif
130
131         /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */
132         call _bf53x_relocate_l1_mem;
133 #ifdef CONFIG_BFIN_KERNEL_CLOCK
134         call _start_dma_code;
135 #endif
136         /* Code for initializing Async memory banks */
137
138         p2.h = hi(EBIU_AMBCTL1);
139         p2.l = lo(EBIU_AMBCTL1);
140         r0.h = hi(AMBCTL1VAL);
141         r0.l = lo(AMBCTL1VAL);
142         [p2] = r0;
143         ssync;
144
145         p2.h = hi(EBIU_AMBCTL0);
146         p2.l = lo(EBIU_AMBCTL0);
147         r0.h = hi(AMBCTL0VAL);
148         r0.l = lo(AMBCTL0VAL);
149         [p2] = r0;
150         ssync;
151
152         p2.h = hi(EBIU_AMGCTL);
153         p2.l = lo(EBIU_AMGCTL);
154         r0 = AMGCTLVAL;
155         w[p2] = r0;
156         ssync;
157
158         p2.h = hi(EBIU_MBSCTL);
159         p2.l = lo(EBIU_MBSCTL);
160         r0.h = hi(CONFIG_EBIU_MBSCTLVAL);
161         r0.l = lo(CONFIG_EBIU_MBSCTLVAL);
162         [p2] = r0;
163         ssync;
164
165         p2.h = hi(EBIU_MODE);
166         p2.l = lo(EBIU_MODE);
167         r0.h = hi(CONFIG_EBIU_MODEVAL);
168         r0.l = lo(CONFIG_EBIU_MODEVAL);
169         [p2] = r0;
170         ssync;
171
172         p2.h = hi(EBIU_FCTL);
173         p2.l = lo(EBIU_FCTL);
174         r0.h = hi(CONFIG_EBIU_FCTLVAL);
175         r0.l = lo(CONFIG_EBIU_FCTLVAL);
176         [p2] = r0;
177         ssync;
178
179         /* This section keeps the processor in supervisor mode
180          * during kernel boot.  Switches to user mode at end of boot.
181          * See page 3-9 of Hardware Reference manual for documentation.
182          */
183
184         /* EVT15 = _real_start */
185
186         p0.l = lo(EVT15);
187         p0.h = hi(EVT15);
188         p1.l = _real_start;
189         p1.h = _real_start;
190         [p0] = p1;
191         csync;
192
193         p0.l = lo(IMASK);
194         p0.h = hi(IMASK);
195         p1.l = IMASK_IVG15;
196         p1.h = 0x0;
197         [p0] = p1;
198         csync;
199
200         raise 15;
201         p0.l = .LWAIT_HERE;
202         p0.h = .LWAIT_HERE;
203         reti = p0;
204 #if ANOMALY_05000281
205         nop;
206         nop;
207         nop;
208 #endif
209         rti;
210
211 .LWAIT_HERE:
212         jump .LWAIT_HERE;
213 ENDPROC(__start)
214
215 ENTRY(_real_start)
216         [ -- sp ] = reti;
217         p0.l = lo(WDOG_CTL);
218         p0.h = hi(WDOG_CTL);
219         r0 = 0xAD6(z);
220         w[p0] = r0;     /* watchdog off for now */
221         ssync;
222
223         /* Code update for BSS size == 0
224          * Zero out the bss region.
225          */
226
227         p1.l = ___bss_start;
228         p1.h = ___bss_start;
229         p2.l = ___bss_stop;
230         p2.h = ___bss_stop;
231         r0 = 0;
232         p2 -= p1;
233         lsetup (.L_clear_bss, .L_clear_bss ) lc0 = p2;
234 .L_clear_bss:
235         B[p1++] = r0;
236
237         /* In case there is a NULL pointer reference
238          * Zero out region before stext
239          */
240
241         p1.l = 0x0;
242         p1.h = 0x0;
243         r0.l = __stext;
244         r0.h = __stext;
245         r0 = r0 >> 1;
246         p2 = r0;
247         r0 = 0;
248         lsetup (.L_clear_zero, .L_clear_zero ) lc0 = p2;
249 .L_clear_zero:
250         W[p1++] = r0;
251
252         /* pass the uboot arguments to the global value command line */
253         R0 = R7;
254         call _cmdline_init;
255
256         p1.l = __rambase;
257         p1.h = __rambase;
258         r0.l = __sdata;
259         r0.h = __sdata;
260         [p1] = r0;
261
262         p1.l = __ramstart;
263         p1.h = __ramstart;
264         p3.l = ___bss_stop;
265         p3.h = ___bss_stop;
266
267         r1 = p3;
268         [p1] = r1;
269
270
271         /*
272          *  load the current thread pointer and stack
273          */
274         r1.l = _init_thread_union;
275         r1.h = _init_thread_union;
276
277         r2.l = 0x2000;
278         r2.h = 0x0000;
279         r1 = r1 + r2;
280         sp = r1;
281         usp = sp;
282         fp = sp;
283         call _start_kernel;
284 .L_exit:
285         jump.s  .L_exit;
286 ENDPROC(_real_start)
287
288 __FINIT
289
290 .section .l1.text
291 #ifdef CONFIG_BFIN_KERNEL_CLOCK
292 ENTRY(_start_dma_code)
293
294         /* Enable PHY CLK buffer output */
295         p0.h = hi(VR_CTL);
296         p0.l = lo(VR_CTL);
297         r0.l = w[p0];
298         bitset(r0, 14);
299         w[p0] = r0.l;
300         ssync;
301
302         p0.h = hi(SIC_IWR0);
303         p0.l = lo(SIC_IWR0);
304         r0.l = 0x1;
305         r0.h = 0x0;
306         [p0] = r0;
307         SSYNC;
308
309         /*
310          *  Set PLL_CTL
311          *   - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors
312          *   - [8]     = BYPASS    : BYPASS the PLL, run CLKIN into CCLK/SCLK
313          *   - [7]     = output delay (add 200ps of delay to mem signals)
314          *   - [6]     = input delay (add 200ps of input delay to mem signals)
315          *   - [5]     = PDWN      : 1=All Clocks off
316          *   - [3]     = STOPCK    : 1=Core Clock off
317          *   - [1]     = PLL_OFF   : 1=Disable Power to PLL
318          *   - [0]     = DF        : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL
319          *   all other bits set to zero
320          */
321
322         p0.h = hi(PLL_LOCKCNT);
323         p0.l = lo(PLL_LOCKCNT);
324         r0 = 0x300(Z);
325         w[p0] = r0.l;
326         ssync;
327
328 #if defined(CONFIG_BF54x)
329         P2.H = hi(EBIU_RSTCTL);
330         P2.L = lo(EBIU_RSTCTL);
331         R0 = [P2];
332         BITSET (R0, 3);
333 #else
334         P2.H = hi(EBIU_SDGCTL);
335         P2.L = lo(EBIU_SDGCTL);
336         R0 = [P2];
337         BITSET (R0, 24);
338 #endif
339         [P2] = R0;
340         SSYNC;
341 #if defined(CONFIG_BF54x)
342 .LSRR_MODE:
343         R0 = [P2];
344         CC = BITTST(R0, 4);
345         if !CC JUMP .LSRR_MODE;
346 #endif
347
348         r0 = CONFIG_VCO_MULT & 63;       /* Load the VCO multiplier         */
349         r0 = r0 << 9;                    /* Shift it over,                  */
350         r1 = CLKIN_HALF;                 /* Do we need to divide CLKIN by 2?*/
351         r0 = r1 | r0;
352         r1 = PLL_BYPASS;                 /* Bypass the PLL?                 */
353         r1 = r1 << 8;                    /* Shift it over                   */
354         r0 = r1 | r0;                    /* add them all together           */
355
356         p0.h = hi(PLL_CTL);
357         p0.l = lo(PLL_CTL);              /* Load the address                */
358         cli r2;                          /* Disable interrupts              */
359         ssync;
360         w[p0] = r0.l;                    /* Set the value                   */
361         idle;                            /* Wait for the PLL to stablize    */
362         sti r2;                          /* Enable interrupts               */
363
364 .Lcheck_again:
365         p0.h = hi(PLL_STAT);
366         p0.l = lo(PLL_STAT);
367         R0 = W[P0](Z);
368         CC = BITTST(R0,5);
369         if ! CC jump .Lcheck_again;
370
371         /* Configure SCLK & CCLK Dividers */
372         r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
373         p0.h = hi(PLL_DIV);
374         p0.l = lo(PLL_DIV);
375         w[p0] = r0.l;
376         ssync;
377
378 #if defined(CONFIG_BF54x)
379         P2.H = hi(EBIU_RSTCTL);
380         P2.L = lo(EBIU_RSTCTL);
381         R0 = [P2];
382         CC = BITTST(R0, 0);
383         if CC jump .Lskipddrrst;
384         BITSET (R0, 0);
385 .Lskipddrrst:
386         BITCLR (R0, 3);
387         [P2] = R0;
388         SSYNC;
389
390         p0.l = lo(EBIU_DDRCTL0);
391         p0.h = hi(EBIU_DDRCTL0);
392         r0.l = lo(mem_DDRCTL0);
393         r0.h = hi(mem_DDRCTL0);
394         [p0] = r0;
395         ssync;
396
397         p0.l = lo(EBIU_DDRCTL1);
398         p0.h = hi(EBIU_DDRCTL1);
399         r0.l = lo(mem_DDRCTL1);
400         r0.h = hi(mem_DDRCTL1);
401         [p0] = r0;
402         ssync;
403
404         p0.l = lo(EBIU_DDRCTL2);
405         p0.h = hi(EBIU_DDRCTL2);
406         r0.l = lo(mem_DDRCTL2);
407         r0.h = hi(mem_DDRCTL2);
408         [p0] = r0;
409         ssync;
410 #else
411         p0.l = lo(EBIU_SDRRC);
412         p0.h = hi(EBIU_SDRRC);
413         r0 = mem_SDRRC;
414         w[p0] = r0.l;
415         ssync;
416
417         p0.l = LO(EBIU_SDBCTL);
418         p0.h = HI(EBIU_SDBCTL);     /* SDRAM Memory Bank Control Register */
419         r0 = mem_SDBCTL;
420         w[p0] = r0.l;
421         ssync;
422
423         P2.H = hi(EBIU_SDGCTL);
424         P2.L = lo(EBIU_SDGCTL);
425         R0 = [P2];
426         BITCLR (R0, 24);
427         p0.h = hi(EBIU_SDSTAT);
428         p0.l = lo(EBIU_SDSTAT);
429         r2.l = w[p0];
430         cc = bittst(r2,3);
431         if !cc jump .Lskip;
432         NOP;
433         BITSET (R0, 23);
434 .Lskip:
435         [P2] = R0;
436         SSYNC;
437
438         R0.L = lo(mem_SDGCTL);
439         R0.H = hi(mem_SDGCTL);
440         R1 = [p2];
441         R1 = R1 | R0;
442         [P2] = R1;
443         SSYNC;
444 #endif
445
446         p0.h = hi(SIC_IWR0);
447         p0.l = lo(SIC_IWR0);
448         r0.l = lo(IWR_ENABLE_ALL);
449         r0.h = hi(IWR_ENABLE_ALL);
450         [p0] = r0;
451         SSYNC;
452
453         RTS;
454 ENDPROC(_start_dma_code)
455 #endif /* CONFIG_BFIN_KERNEL_CLOCK */