]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/blackfin/mach-bf548/head.S
[Blackfin] arch: Fix bug to Enable kernel to build for bf548 with PM.
[linux-2.6-omap-h63xx.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         P2.H = hi(EBIU_SDGCTL);
328         P2.L = lo(EBIU_SDGCTL);
329         R0 = [P2];
330         BITSET (R0, 24);
331         [P2] = R0;
332         SSYNC;
333
334         r0 = CONFIG_VCO_MULT & 63;       /* Load the VCO multiplier         */
335         r0 = r0 << 9;                    /* Shift it over,                  */
336         r1 = CLKIN_HALF;                 /* Do we need to divide CLKIN by 2?*/
337         r0 = r1 | r0;
338         r1 = PLL_BYPASS;                 /* Bypass the PLL?                 */
339         r1 = r1 << 8;                    /* Shift it over                   */
340         r0 = r1 | r0;                    /* add them all together           */
341
342         p0.h = hi(PLL_CTL);
343         p0.l = lo(PLL_CTL);              /* Load the address                */
344         cli r2;                          /* Disable interrupts              */
345         ssync;
346         w[p0] = r0.l;                    /* Set the value                   */
347         idle;                            /* Wait for the PLL to stablize    */
348         sti r2;                          /* Enable interrupts               */
349
350 .Lcheck_again:
351         p0.h = hi(PLL_STAT);
352         p0.l = lo(PLL_STAT);
353         R0 = W[P0](Z);
354         CC = BITTST(R0,5);
355         if ! CC jump .Lcheck_again;
356
357         /* Configure SCLK & CCLK Dividers */
358         r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
359         p0.h = hi(PLL_DIV);
360         p0.l = lo(PLL_DIV);
361         w[p0] = r0.l;
362         ssync;
363
364         p0.l = lo(EBIU_SDRRC);
365         p0.h = hi(EBIU_SDRRC);
366         r0 = mem_SDRRC;
367         w[p0] = r0.l;
368         ssync;
369
370         p0.l = LO(EBIU_SDBCTL);
371         p0.h = HI(EBIU_SDBCTL);     /* SDRAM Memory Bank Control Register */
372         r0 = mem_SDBCTL;
373         w[p0] = r0.l;
374         ssync;
375
376         P2.H = hi(EBIU_SDGCTL);
377         P2.L = lo(EBIU_SDGCTL);
378         R0 = [P2];
379         BITCLR (R0, 24);
380         p0.h = hi(EBIU_SDSTAT);
381         p0.l = lo(EBIU_SDSTAT);
382         r2.l = w[p0];
383         cc = bittst(r2,3);
384         if !cc jump .Lskip;
385         NOP;
386         BITSET (R0, 23);
387 .Lskip:
388         [P2] = R0;
389         SSYNC;
390
391         R0.L = lo(mem_SDGCTL);
392         R0.H = hi(mem_SDGCTL);
393         R1 = [p2];
394         R1 = R1 | R0;
395         [P2] = R1;
396         SSYNC;
397
398         p0.h = hi(SIC_IWR0);
399         p0.l = lo(SIC_IWR0);
400         r0.l = lo(IWR_ENABLE_ALL);
401         r0.h = hi(IWR_ENABLE_ALL);
402         [p0] = r0;
403         SSYNC;
404
405         RTS;
406 #endif /* CONFIG_BFIN_KERNEL_CLOCK */
407
408 .data
409
410 /*
411  * Set up the usable of RAM stuff. Size of RAM is determined then
412  * an initial stack set up at the end.
413  */
414
415 .align 4
416 __rambase:
417 .long   0
418 __ramstart:
419 .long   0
420 __ramend:
421 .long   0