blob: 46222a75321a5d7f8fa21e103b4ce9ae666967cd [file] [log] [blame]
Roy Huang24a07a12007-07-12 22:41:45 +08001/*
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>
Bryan Wuc0514892008-02-29 12:02:10 +080031#include <linux/init.h>
Roy Huang24a07a12007-07-12 22:41:45 +080032#include <asm/blackfin.h>
Robin Getz669b7922007-06-21 16:34:08 +080033#include <asm/trace.h>
Roy Huang24a07a12007-07-12 22:41:45 +080034#if CONFIG_BFIN_KERNEL_CLOCK
Robin Getzf16295e2007-08-03 18:07:17 +080035#include <asm/mach-common/clocks.h>
Roy Huang24a07a12007-07-12 22:41:45 +080036#include <asm/mach/mem_init.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
Bryan Wuc0514892008-02-29 12:02:10 +080048__INIT
Roy Huang24a07a12007-07-12 22:41:45 +080049
50ENTRY(__start)
Roy Huang24a07a12007-07-12 22:41:45 +080051 /* R0: argument of command line string, passed from uboot, save it */
52 R7 = R0;
Mike Frysingerf0b5d122007-08-05 17:03:59 +080053 /* 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;
Roy Huang24a07a12007-07-12 22:41:45 +080060 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
Robin Getz518039b2007-07-25 11:03:28 +0800100 trace_buffer_init(p0,r0);
Robin Getz669b7922007-06-21 16:34:08 +0800101 P0 = R1;
102 R0 = R1;
103
Roy Huang24a07a12007-07-12 22:41:45 +0800104 /* Turn off the icache */
Mike Frysingere208f832007-07-25 10:11:42 +0800105 p0.l = LO(IMEM_CONTROL);
106 p0.h = HI(IMEM_CONTROL);
Roy Huang24a07a12007-07-12 22:41:45 +0800107 R1 = [p0];
108 R0 = ~ENICPLB;
109 R0 = R0 & R1;
110 [p0] = R0;
111 SSYNC;
112
113 /* Turn off the dcache */
Mike Frysingere208f832007-07-25 10:11:42 +0800114 p0.l = LO(DMEM_CONTROL);
115 p0.h = HI(DMEM_CONTROL);
Roy Huang24a07a12007-07-12 22:41:45 +0800116 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
Robin Getz337d3902007-10-09 17:31:46 +0800128#ifdef CONFIG_EARLY_PRINTK
129 SP += -12;
130 call _init_early_exception_vectors;
131 SP += 12;
132#endif
133
Roy Huang24a07a12007-07-12 22:41:45 +0800134 /* 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
Sonic Zhange40540b2007-11-21 23:49:52 +0800161 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
Roy Huang24a07a12007-07-12 22:41:45 +0800182 /* 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;
Mike Frysinger1aafd902007-07-25 11:19:14 +0800207#if ANOMALY_05000281
Roy Huang24a07a12007-07-12 22:41:45 +0800208 nop;
209 nop;
210 nop;
211#endif
212 rti;
213
214.LWAIT_HERE:
215 jump .LWAIT_HERE;
Bryan Wuc0514892008-02-29 12:02:10 +0800216ENDPROC(__start)
Roy Huang24a07a12007-07-12 22:41:45 +0800217
218ENTRY(_real_start)
219 [ -- sp ] = reti;
220 p0.l = lo(WDOG_CTL);
221 p0.h = hi(WDOG_CTL);
222 r0 = 0xAD6(z);
223 w[p0] = r0; /* watchdog off for now */
224 ssync;
225
226 /* Code update for BSS size == 0
227 * Zero out the bss region.
228 */
229
230 p1.l = ___bss_start;
231 p1.h = ___bss_start;
232 p2.l = ___bss_stop;
233 p2.h = ___bss_stop;
234 r0 = 0;
235 p2 -= p1;
236 lsetup (.L_clear_bss, .L_clear_bss ) lc0 = p2;
237.L_clear_bss:
238 B[p1++] = r0;
239
240 /* In case there is a NULL pointer reference
241 * Zero out region before stext
242 */
243
244 p1.l = 0x0;
245 p1.h = 0x0;
246 r0.l = __stext;
247 r0.h = __stext;
248 r0 = r0 >> 1;
249 p2 = r0;
250 r0 = 0;
251 lsetup (.L_clear_zero, .L_clear_zero ) lc0 = p2;
252.L_clear_zero:
253 W[p1++] = r0;
254
255 /* pass the uboot arguments to the global value command line */
256 R0 = R7;
257 call _cmdline_init;
258
259 p1.l = __rambase;
260 p1.h = __rambase;
261 r0.l = __sdata;
262 r0.h = __sdata;
263 [p1] = r0;
264
265 p1.l = __ramstart;
266 p1.h = __ramstart;
267 p3.l = ___bss_stop;
268 p3.h = ___bss_stop;
269
270 r1 = p3;
271 [p1] = r1;
272
273
274 /*
275 * load the current thread pointer and stack
276 */
277 r1.l = _init_thread_union;
278 r1.h = _init_thread_union;
279
280 r2.l = 0x2000;
281 r2.h = 0x0000;
282 r1 = r1 + r2;
283 sp = r1;
284 usp = sp;
285 fp = sp;
286 call _start_kernel;
287.L_exit:
288 jump.s .L_exit;
Bryan Wuc0514892008-02-29 12:02:10 +0800289ENDPROC(_real_start)
290
291__FINIT
Roy Huang24a07a12007-07-12 22:41:45 +0800292
293.section .l1.text
294#if CONFIG_BFIN_KERNEL_CLOCK
295ENTRY(_start_dma_code)
296
297 /* Enable PHY CLK buffer output */
298 p0.h = hi(VR_CTL);
299 p0.l = lo(VR_CTL);
300 r0.l = w[p0];
301 bitset(r0, 14);
302 w[p0] = r0.l;
303 ssync;
304
Sonic Zhangfb5f0042007-12-23 23:02:13 +0800305 p0.h = hi(SIC_IWR0);
306 p0.l = lo(SIC_IWR0);
Roy Huang24a07a12007-07-12 22:41:45 +0800307 r0.l = 0x1;
308 r0.h = 0x0;
309 [p0] = r0;
310 SSYNC;
311
312 /*
313 * Set PLL_CTL
314 * - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors
315 * - [8] = BYPASS : BYPASS the PLL, run CLKIN into CCLK/SCLK
316 * - [7] = output delay (add 200ps of delay to mem signals)
317 * - [6] = input delay (add 200ps of input delay to mem signals)
318 * - [5] = PDWN : 1=All Clocks off
319 * - [3] = STOPCK : 1=Core Clock off
320 * - [1] = PLL_OFF : 1=Disable Power to PLL
321 * - [0] = DF : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL
322 * all other bits set to zero
323 */
324
325 p0.h = hi(PLL_LOCKCNT);
326 p0.l = lo(PLL_LOCKCNT);
327 r0 = 0x300(Z);
328 w[p0] = r0.l;
329 ssync;
330
Sonic Zhang971d5bc2008-01-27 16:32:31 +0800331#if defined(CONFIG_BF54x)
332 P2.H = hi(EBIU_RSTCTL);
333 P2.L = lo(EBIU_RSTCTL);
334 R0 = [P2];
335 BITSET (R0, 3);
336#else
Roy Huang24a07a12007-07-12 22:41:45 +0800337 P2.H = hi(EBIU_SDGCTL);
338 P2.L = lo(EBIU_SDGCTL);
339 R0 = [P2];
340 BITSET (R0, 24);
Sonic Zhang971d5bc2008-01-27 16:32:31 +0800341#endif
Roy Huang24a07a12007-07-12 22:41:45 +0800342 [P2] = R0;
343 SSYNC;
Sonic Zhang971d5bc2008-01-27 16:32:31 +0800344#if defined(CONFIG_BF54x)
345.LSRR_MODE:
346 R0 = [P2];
347 CC = BITTST(R0, 4);
348 if !CC JUMP .LSRR_MODE;
349#endif
Roy Huang24a07a12007-07-12 22:41:45 +0800350
351 r0 = CONFIG_VCO_MULT & 63; /* Load the VCO multiplier */
352 r0 = r0 << 9; /* Shift it over, */
353 r1 = CLKIN_HALF; /* Do we need to divide CLKIN by 2?*/
354 r0 = r1 | r0;
355 r1 = PLL_BYPASS; /* Bypass the PLL? */
356 r1 = r1 << 8; /* Shift it over */
357 r0 = r1 | r0; /* add them all together */
358
359 p0.h = hi(PLL_CTL);
360 p0.l = lo(PLL_CTL); /* Load the address */
361 cli r2; /* Disable interrupts */
362 ssync;
363 w[p0] = r0.l; /* Set the value */
364 idle; /* Wait for the PLL to stablize */
365 sti r2; /* Enable interrupts */
366
367.Lcheck_again:
368 p0.h = hi(PLL_STAT);
369 p0.l = lo(PLL_STAT);
370 R0 = W[P0](Z);
371 CC = BITTST(R0,5);
372 if ! CC jump .Lcheck_again;
373
374 /* Configure SCLK & CCLK Dividers */
375 r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
376 p0.h = hi(PLL_DIV);
377 p0.l = lo(PLL_DIV);
378 w[p0] = r0.l;
379 ssync;
380
Sonic Zhang971d5bc2008-01-27 16:32:31 +0800381#if defined(CONFIG_BF54x)
382 P2.H = hi(EBIU_RSTCTL);
383 P2.L = lo(EBIU_RSTCTL);
384 R0 = [P2];
385 CC = BITTST(R0, 0);
386 if CC jump .Lskipddrrst;
387 BITSET (R0, 0);
388.Lskipddrrst:
389 BITCLR (R0, 3);
390 [P2] = R0;
391 SSYNC;
392
393 p0.l = lo(EBIU_DDRCTL0);
394 p0.h = hi(EBIU_DDRCTL0);
395 r0.l = lo(mem_DDRCTL0);
396 r0.h = hi(mem_DDRCTL0);
397 [p0] = r0;
398 ssync;
399
400 p0.l = lo(EBIU_DDRCTL1);
401 p0.h = hi(EBIU_DDRCTL1);
402 r0.l = lo(mem_DDRCTL1);
403 r0.h = hi(mem_DDRCTL1);
404 [p0] = r0;
405 ssync;
406
407 p0.l = lo(EBIU_DDRCTL2);
408 p0.h = hi(EBIU_DDRCTL2);
409 r0.l = lo(mem_DDRCTL2);
410 r0.h = hi(mem_DDRCTL2);
411 [p0] = r0;
412 ssync;
413#else
Roy Huang24a07a12007-07-12 22:41:45 +0800414 p0.l = lo(EBIU_SDRRC);
415 p0.h = hi(EBIU_SDRRC);
416 r0 = mem_SDRRC;
417 w[p0] = r0.l;
418 ssync;
419
Mike Frysingere208f832007-07-25 10:11:42 +0800420 p0.l = LO(EBIU_SDBCTL);
421 p0.h = HI(EBIU_SDBCTL); /* SDRAM Memory Bank Control Register */
Roy Huang24a07a12007-07-12 22:41:45 +0800422 r0 = mem_SDBCTL;
423 w[p0] = r0.l;
424 ssync;
425
426 P2.H = hi(EBIU_SDGCTL);
427 P2.L = lo(EBIU_SDGCTL);
428 R0 = [P2];
429 BITCLR (R0, 24);
430 p0.h = hi(EBIU_SDSTAT);
431 p0.l = lo(EBIU_SDSTAT);
432 r2.l = w[p0];
433 cc = bittst(r2,3);
434 if !cc jump .Lskip;
435 NOP;
436 BITSET (R0, 23);
437.Lskip:
438 [P2] = R0;
439 SSYNC;
440
441 R0.L = lo(mem_SDGCTL);
442 R0.H = hi(mem_SDGCTL);
443 R1 = [p2];
444 R1 = R1 | R0;
445 [P2] = R1;
446 SSYNC;
Sonic Zhang971d5bc2008-01-27 16:32:31 +0800447#endif
Roy Huang24a07a12007-07-12 22:41:45 +0800448
Sonic Zhangfb5f0042007-12-23 23:02:13 +0800449 p0.h = hi(SIC_IWR0);
450 p0.l = lo(SIC_IWR0);
Roy Huang24a07a12007-07-12 22:41:45 +0800451 r0.l = lo(IWR_ENABLE_ALL);
452 r0.h = hi(IWR_ENABLE_ALL);
453 [p0] = r0;
454 SSYNC;
455
456 RTS;
Bryan Wuc0514892008-02-29 12:02:10 +0800457ENDPROC(_start_dma_code)
Roy Huang24a07a12007-07-12 22:41:45 +0800458#endif /* CONFIG_BFIN_KERNEL_CLOCK */
459
Roy Huang24a07a12007-07-12 22:41:45 +0800460.data
461
462/*
463 * Set up the usable of RAM stuff. Size of RAM is determined then
464 * an initial stack set up at the end.
465 */
466
467.align 4
468__rambase:
469.long 0
470__ramstart:
471.long 0
472__ramend:
473.long 0