]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/blackfin/mach-bf548/head.S
Blackfin arch: unify the duplicated _real_start functions
[karo-tx-linux.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 __FINIT
216
217 .section .l1.text
218 #ifdef CONFIG_BFIN_KERNEL_CLOCK
219 ENTRY(_start_dma_code)
220
221         /* Enable PHY CLK buffer output */
222         p0.h = hi(VR_CTL);
223         p0.l = lo(VR_CTL);
224         r0.l = w[p0];
225         bitset(r0, 14);
226         w[p0] = r0.l;
227         ssync;
228
229         p0.h = hi(SIC_IWR0);
230         p0.l = lo(SIC_IWR0);
231         r0.l = 0x1;
232         r0.h = 0x0;
233         [p0] = r0;
234         SSYNC;
235
236         /*
237          *  Set PLL_CTL
238          *   - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors
239          *   - [8]     = BYPASS    : BYPASS the PLL, run CLKIN into CCLK/SCLK
240          *   - [7]     = output delay (add 200ps of delay to mem signals)
241          *   - [6]     = input delay (add 200ps of input delay to mem signals)
242          *   - [5]     = PDWN      : 1=All Clocks off
243          *   - [3]     = STOPCK    : 1=Core Clock off
244          *   - [1]     = PLL_OFF   : 1=Disable Power to PLL
245          *   - [0]     = DF        : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL
246          *   all other bits set to zero
247          */
248
249         p0.h = hi(PLL_LOCKCNT);
250         p0.l = lo(PLL_LOCKCNT);
251         r0 = 0x300(Z);
252         w[p0] = r0.l;
253         ssync;
254
255 #if defined(CONFIG_BF54x)
256         P2.H = hi(EBIU_RSTCTL);
257         P2.L = lo(EBIU_RSTCTL);
258         R0 = [P2];
259         BITSET (R0, 3);
260 #else
261         P2.H = hi(EBIU_SDGCTL);
262         P2.L = lo(EBIU_SDGCTL);
263         R0 = [P2];
264         BITSET (R0, 24);
265 #endif
266         [P2] = R0;
267         SSYNC;
268 #if defined(CONFIG_BF54x)
269 .LSRR_MODE:
270         R0 = [P2];
271         CC = BITTST(R0, 4);
272         if !CC JUMP .LSRR_MODE;
273 #endif
274
275         r0 = CONFIG_VCO_MULT & 63;       /* Load the VCO multiplier         */
276         r0 = r0 << 9;                    /* Shift it over,                  */
277         r1 = CLKIN_HALF;                 /* Do we need to divide CLKIN by 2?*/
278         r0 = r1 | r0;
279         r1 = PLL_BYPASS;                 /* Bypass the PLL?                 */
280         r1 = r1 << 8;                    /* Shift it over                   */
281         r0 = r1 | r0;                    /* add them all together           */
282
283         p0.h = hi(PLL_CTL);
284         p0.l = lo(PLL_CTL);              /* Load the address                */
285         cli r2;                          /* Disable interrupts              */
286         ssync;
287         w[p0] = r0.l;                    /* Set the value                   */
288         idle;                            /* Wait for the PLL to stablize    */
289         sti r2;                          /* Enable interrupts               */
290
291 .Lcheck_again:
292         p0.h = hi(PLL_STAT);
293         p0.l = lo(PLL_STAT);
294         R0 = W[P0](Z);
295         CC = BITTST(R0,5);
296         if ! CC jump .Lcheck_again;
297
298         /* Configure SCLK & CCLK Dividers */
299         r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
300         p0.h = hi(PLL_DIV);
301         p0.l = lo(PLL_DIV);
302         w[p0] = r0.l;
303         ssync;
304
305 #if defined(CONFIG_BF54x)
306         P2.H = hi(EBIU_RSTCTL);
307         P2.L = lo(EBIU_RSTCTL);
308         R0 = [P2];
309         CC = BITTST(R0, 0);
310         if CC jump .Lskipddrrst;
311         BITSET (R0, 0);
312 .Lskipddrrst:
313         BITCLR (R0, 3);
314         [P2] = R0;
315         SSYNC;
316
317         p0.l = lo(EBIU_DDRCTL0);
318         p0.h = hi(EBIU_DDRCTL0);
319         r0.l = lo(mem_DDRCTL0);
320         r0.h = hi(mem_DDRCTL0);
321         [p0] = r0;
322         ssync;
323
324         p0.l = lo(EBIU_DDRCTL1);
325         p0.h = hi(EBIU_DDRCTL1);
326         r0.l = lo(mem_DDRCTL1);
327         r0.h = hi(mem_DDRCTL1);
328         [p0] = r0;
329         ssync;
330
331         p0.l = lo(EBIU_DDRCTL2);
332         p0.h = hi(EBIU_DDRCTL2);
333         r0.l = lo(mem_DDRCTL2);
334         r0.h = hi(mem_DDRCTL2);
335         [p0] = r0;
336         ssync;
337 #else
338         p0.l = lo(EBIU_SDRRC);
339         p0.h = hi(EBIU_SDRRC);
340         r0 = mem_SDRRC;
341         w[p0] = r0.l;
342         ssync;
343
344         p0.l = LO(EBIU_SDBCTL);
345         p0.h = HI(EBIU_SDBCTL);     /* SDRAM Memory Bank Control Register */
346         r0 = mem_SDBCTL;
347         w[p0] = r0.l;
348         ssync;
349
350         P2.H = hi(EBIU_SDGCTL);
351         P2.L = lo(EBIU_SDGCTL);
352         R0 = [P2];
353         BITCLR (R0, 24);
354         p0.h = hi(EBIU_SDSTAT);
355         p0.l = lo(EBIU_SDSTAT);
356         r2.l = w[p0];
357         cc = bittst(r2,3);
358         if !cc jump .Lskip;
359         NOP;
360         BITSET (R0, 23);
361 .Lskip:
362         [P2] = R0;
363         SSYNC;
364
365         R0.L = lo(mem_SDGCTL);
366         R0.H = hi(mem_SDGCTL);
367         R1 = [p2];
368         R1 = R1 | R0;
369         [P2] = R1;
370         SSYNC;
371 #endif
372
373         p0.h = hi(SIC_IWR0);
374         p0.l = lo(SIC_IWR0);
375         r0.l = lo(IWR_ENABLE_ALL);
376         r0.h = hi(IWR_ENABLE_ALL);
377         [p0] = r0;
378         SSYNC;
379
380         RTS;
381 ENDPROC(_start_dma_code)
382 #endif /* CONFIG_BFIN_KERNEL_CLOCK */