blob: 74fe258421a5546c88eb231f8265c6e5aba22fa9 [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>
31#include <asm/blackfin.h>
Robin Getz669b7922007-06-21 16:34:08 +080032#include <asm/trace.h>
Roy Huang24a07a12007-07-12 22:41:45 +080033#if CONFIG_BFIN_KERNEL_CLOCK
Robin Getzf16295e2007-08-03 18:07:17 +080034#include <asm/mach-common/clocks.h>
Roy Huang24a07a12007-07-12 22:41:45 +080035#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
49ENTRY(__start)
50ENTRY(__stext)
51 /* 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;
216
217ENTRY(_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
291ENTRY(_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
Sonic Zhangfb5f0042007-12-23 23:02:13 +0800301 p0.h = hi(SIC_IWR0);
302 p0.l = lo(SIC_IWR0);
Roy Huang24a07a12007-07-12 22:41:45 +0800303 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
Sonic Zhang971d5bc2008-01-27 16:32:31 +0800327#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
Roy Huang24a07a12007-07-12 22:41:45 +0800333 P2.H = hi(EBIU_SDGCTL);
334 P2.L = lo(EBIU_SDGCTL);
335 R0 = [P2];
336 BITSET (R0, 24);
Sonic Zhang971d5bc2008-01-27 16:32:31 +0800337#endif
Roy Huang24a07a12007-07-12 22:41:45 +0800338 [P2] = R0;
339 SSYNC;
Sonic Zhang971d5bc2008-01-27 16:32:31 +0800340#if defined(CONFIG_BF54x)
341.LSRR_MODE:
342 R0 = [P2];
343 CC = BITTST(R0, 4);
344 if !CC JUMP .LSRR_MODE;
345#endif
Roy Huang24a07a12007-07-12 22:41:45 +0800346
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
Sonic Zhang971d5bc2008-01-27 16:32:31 +0800377#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
Roy Huang24a07a12007-07-12 22:41:45 +0800410 p0.l = lo(EBIU_SDRRC);
411 p0.h = hi(EBIU_SDRRC);
412 r0 = mem_SDRRC;
413 w[p0] = r0.l;
414 ssync;
415
Mike Frysingere208f832007-07-25 10:11:42 +0800416 p0.l = LO(EBIU_SDBCTL);
417 p0.h = HI(EBIU_SDBCTL); /* SDRAM Memory Bank Control Register */
Roy Huang24a07a12007-07-12 22:41:45 +0800418 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;
Sonic Zhang971d5bc2008-01-27 16:32:31 +0800443#endif
Roy Huang24a07a12007-07-12 22:41:45 +0800444
Sonic Zhangfb5f0042007-12-23 23:02:13 +0800445 p0.h = hi(SIC_IWR0);
446 p0.l = lo(SIC_IWR0);
Roy Huang24a07a12007-07-12 22:41:45 +0800447 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
Roy Huang24a07a12007-07-12 22:41:45 +0800455.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