blob: 72087c2e6a83e9c1458ced29aa256dd154524ca5 [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;
53 /* Set the SYSCFG register */
54 R0 = 0x36;
55 SYSCFG = R0; /*Enable Cycle Counter and Nesting Of Interrupts(3rd Bit)*/
56 R0 = 0;
57
58 /* Clear Out All the data and pointer Registers*/
59 R1 = R0;
60 R2 = R0;
61 R3 = R0;
62 R4 = R0;
63 R5 = R0;
64 R6 = R0;
65
66 P0 = R0;
67 P1 = R0;
68 P2 = R0;
69 P3 = R0;
70 P4 = R0;
71 P5 = R0;
72
73 LC0 = r0;
74 LC1 = r0;
75 L0 = r0;
76 L1 = r0;
77 L2 = r0;
78 L3 = r0;
79
80 /* Clear Out All the DAG Registers*/
81 B0 = r0;
82 B1 = r0;
83 B2 = r0;
84 B3 = r0;
85
86 I0 = r0;
87 I1 = r0;
88 I2 = r0;
89 I3 = r0;
90
91 M0 = r0;
92 M1 = r0;
93 M2 = r0;
94 M3 = r0;
95
Robin Getz669b7922007-06-21 16:34:08 +080096 trace_buffer_start(p0,r0);
97 P0 = R1;
98 R0 = R1;
99
Roy Huang24a07a12007-07-12 22:41:45 +0800100 /* Turn off the icache */
Mike Frysingere208f832007-07-25 10:11:42 +0800101 p0.l = LO(IMEM_CONTROL);
102 p0.h = HI(IMEM_CONTROL);
Roy Huang24a07a12007-07-12 22:41:45 +0800103 R1 = [p0];
104 R0 = ~ENICPLB;
105 R0 = R0 & R1;
106 [p0] = R0;
107 SSYNC;
108
109 /* Turn off the dcache */
Mike Frysingere208f832007-07-25 10:11:42 +0800110 p0.l = LO(DMEM_CONTROL);
111 p0.h = HI(DMEM_CONTROL);
Roy Huang24a07a12007-07-12 22:41:45 +0800112 R1 = [p0];
113 R0 = ~ENDCPLB;
114 R0 = R0 & R1;
115 [p0] = R0;
116 SSYNC;
117
118 /* Initialize stack pointer */
119 SP.L = LO(INITIAL_STACK);
120 SP.H = HI(INITIAL_STACK);
121 FP = SP;
122 USP = SP;
123
124 /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */
125 call _bf53x_relocate_l1_mem;
126#if CONFIG_BFIN_KERNEL_CLOCK
127 call _start_dma_code;
128#endif
129 /* Code for initializing Async memory banks */
130
131 p2.h = hi(EBIU_AMBCTL1);
132 p2.l = lo(EBIU_AMBCTL1);
133 r0.h = hi(AMBCTL1VAL);
134 r0.l = lo(AMBCTL1VAL);
135 [p2] = r0;
136 ssync;
137
138 p2.h = hi(EBIU_AMBCTL0);
139 p2.l = lo(EBIU_AMBCTL0);
140 r0.h = hi(AMBCTL0VAL);
141 r0.l = lo(AMBCTL0VAL);
142 [p2] = r0;
143 ssync;
144
145 p2.h = hi(EBIU_AMGCTL);
146 p2.l = lo(EBIU_AMGCTL);
147 r0 = AMGCTLVAL;
148 w[p2] = r0;
149 ssync;
150
151 /* This section keeps the processor in supervisor mode
152 * during kernel boot. Switches to user mode at end of boot.
153 * See page 3-9 of Hardware Reference manual for documentation.
154 */
155
156 /* EVT15 = _real_start */
157
158 p0.l = lo(EVT15);
159 p0.h = hi(EVT15);
160 p1.l = _real_start;
161 p1.h = _real_start;
162 [p0] = p1;
163 csync;
164
165 p0.l = lo(IMASK);
166 p0.h = hi(IMASK);
167 p1.l = IMASK_IVG15;
168 p1.h = 0x0;
169 [p0] = p1;
170 csync;
171
172 raise 15;
173 p0.l = .LWAIT_HERE;
174 p0.h = .LWAIT_HERE;
175 reti = p0;
Mike Frysinger1aafd902007-07-25 11:19:14 +0800176#if ANOMALY_05000281
Roy Huang24a07a12007-07-12 22:41:45 +0800177 nop;
178 nop;
179 nop;
180#endif
181 rti;
182
183.LWAIT_HERE:
184 jump .LWAIT_HERE;
185
186ENTRY(_real_start)
187 [ -- sp ] = reti;
188 p0.l = lo(WDOG_CTL);
189 p0.h = hi(WDOG_CTL);
190 r0 = 0xAD6(z);
191 w[p0] = r0; /* watchdog off for now */
192 ssync;
193
194 /* Code update for BSS size == 0
195 * Zero out the bss region.
196 */
197
198 p1.l = ___bss_start;
199 p1.h = ___bss_start;
200 p2.l = ___bss_stop;
201 p2.h = ___bss_stop;
202 r0 = 0;
203 p2 -= p1;
204 lsetup (.L_clear_bss, .L_clear_bss ) lc0 = p2;
205.L_clear_bss:
206 B[p1++] = r0;
207
208 /* In case there is a NULL pointer reference
209 * Zero out region before stext
210 */
211
212 p1.l = 0x0;
213 p1.h = 0x0;
214 r0.l = __stext;
215 r0.h = __stext;
216 r0 = r0 >> 1;
217 p2 = r0;
218 r0 = 0;
219 lsetup (.L_clear_zero, .L_clear_zero ) lc0 = p2;
220.L_clear_zero:
221 W[p1++] = r0;
222
223 /* pass the uboot arguments to the global value command line */
224 R0 = R7;
225 call _cmdline_init;
226
227 p1.l = __rambase;
228 p1.h = __rambase;
229 r0.l = __sdata;
230 r0.h = __sdata;
231 [p1] = r0;
232
233 p1.l = __ramstart;
234 p1.h = __ramstart;
235 p3.l = ___bss_stop;
236 p3.h = ___bss_stop;
237
238 r1 = p3;
239 [p1] = r1;
240
241
242 /*
243 * load the current thread pointer and stack
244 */
245 r1.l = _init_thread_union;
246 r1.h = _init_thread_union;
247
248 r2.l = 0x2000;
249 r2.h = 0x0000;
250 r1 = r1 + r2;
251 sp = r1;
252 usp = sp;
253 fp = sp;
254 call _start_kernel;
255.L_exit:
256 jump.s .L_exit;
257
258.section .l1.text
259#if CONFIG_BFIN_KERNEL_CLOCK
260ENTRY(_start_dma_code)
261
262 /* Enable PHY CLK buffer output */
263 p0.h = hi(VR_CTL);
264 p0.l = lo(VR_CTL);
265 r0.l = w[p0];
266 bitset(r0, 14);
267 w[p0] = r0.l;
268 ssync;
269
270 p0.h = hi(SIC_IWR);
271 p0.l = lo(SIC_IWR);
272 r0.l = 0x1;
273 r0.h = 0x0;
274 [p0] = r0;
275 SSYNC;
276
277 /*
278 * Set PLL_CTL
279 * - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors
280 * - [8] = BYPASS : BYPASS the PLL, run CLKIN into CCLK/SCLK
281 * - [7] = output delay (add 200ps of delay to mem signals)
282 * - [6] = input delay (add 200ps of input delay to mem signals)
283 * - [5] = PDWN : 1=All Clocks off
284 * - [3] = STOPCK : 1=Core Clock off
285 * - [1] = PLL_OFF : 1=Disable Power to PLL
286 * - [0] = DF : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL
287 * all other bits set to zero
288 */
289
290 p0.h = hi(PLL_LOCKCNT);
291 p0.l = lo(PLL_LOCKCNT);
292 r0 = 0x300(Z);
293 w[p0] = r0.l;
294 ssync;
295
296 P2.H = hi(EBIU_SDGCTL);
297 P2.L = lo(EBIU_SDGCTL);
298 R0 = [P2];
299 BITSET (R0, 24);
300 [P2] = R0;
301 SSYNC;
302
303 r0 = CONFIG_VCO_MULT & 63; /* Load the VCO multiplier */
304 r0 = r0 << 9; /* Shift it over, */
305 r1 = CLKIN_HALF; /* Do we need to divide CLKIN by 2?*/
306 r0 = r1 | r0;
307 r1 = PLL_BYPASS; /* Bypass the PLL? */
308 r1 = r1 << 8; /* Shift it over */
309 r0 = r1 | r0; /* add them all together */
310
311 p0.h = hi(PLL_CTL);
312 p0.l = lo(PLL_CTL); /* Load the address */
313 cli r2; /* Disable interrupts */
314 ssync;
315 w[p0] = r0.l; /* Set the value */
316 idle; /* Wait for the PLL to stablize */
317 sti r2; /* Enable interrupts */
318
319.Lcheck_again:
320 p0.h = hi(PLL_STAT);
321 p0.l = lo(PLL_STAT);
322 R0 = W[P0](Z);
323 CC = BITTST(R0,5);
324 if ! CC jump .Lcheck_again;
325
326 /* Configure SCLK & CCLK Dividers */
327 r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
328 p0.h = hi(PLL_DIV);
329 p0.l = lo(PLL_DIV);
330 w[p0] = r0.l;
331 ssync;
332
333 p0.l = lo(EBIU_SDRRC);
334 p0.h = hi(EBIU_SDRRC);
335 r0 = mem_SDRRC;
336 w[p0] = r0.l;
337 ssync;
338
Mike Frysingere208f832007-07-25 10:11:42 +0800339 p0.l = LO(EBIU_SDBCTL);
340 p0.h = HI(EBIU_SDBCTL); /* SDRAM Memory Bank Control Register */
Roy Huang24a07a12007-07-12 22:41:45 +0800341 r0 = mem_SDBCTL;
342 w[p0] = r0.l;
343 ssync;
344
345 P2.H = hi(EBIU_SDGCTL);
346 P2.L = lo(EBIU_SDGCTL);
347 R0 = [P2];
348 BITCLR (R0, 24);
349 p0.h = hi(EBIU_SDSTAT);
350 p0.l = lo(EBIU_SDSTAT);
351 r2.l = w[p0];
352 cc = bittst(r2,3);
353 if !cc jump .Lskip;
354 NOP;
355 BITSET (R0, 23);
356.Lskip:
357 [P2] = R0;
358 SSYNC;
359
360 R0.L = lo(mem_SDGCTL);
361 R0.H = hi(mem_SDGCTL);
362 R1 = [p2];
363 R1 = R1 | R0;
364 [P2] = R1;
365 SSYNC;
366
367 p0.h = hi(SIC_IWR);
368 p0.l = lo(SIC_IWR);
369 r0.l = lo(IWR_ENABLE_ALL);
370 r0.h = hi(IWR_ENABLE_ALL);
371 [p0] = r0;
372 SSYNC;
373
374 RTS;
375#endif /* CONFIG_BFIN_KERNEL_CLOCK */
376
377ENTRY(_bfin_reset)
378 /* No more interrupts to be handled*/
379 CLI R6;
380 SSYNC;
381
382#if defined(CONFIG_MTD_M25P80)
383/*
384 * The following code fix the SPI flash reboot issue,
385 * /CS signal of the chip which is using PF10 return to GPIO mode
386 */
387 p0.h = hi(PORTF_FER);
388 p0.l = lo(PORTF_FER);
389 r0.l = 0x0000;
390 w[p0] = r0.l;
391 SSYNC;
392
393/* /CS return to high */
394 p0.h = hi(PORTFIO);
395 p0.l = lo(PORTFIO);
396 r0.l = 0xFFFF;
397 w[p0] = r0.l;
398 SSYNC;
399
400/* Delay some time, This is necessary */
401 r1.h = 0;
402 r1.l = 0x400;
403 p1 = r1;
404 lsetup (_delay_lab1,_delay_lab1_end ) lc1 = p1;
405_delay_lab1:
406 r0.h = 0;
407 r0.l = 0x8000;
408 p0 = r0;
409 lsetup (_delay_lab0,_delay_lab0_end ) lc0 = p0;
410_delay_lab0:
411 nop;
412_delay_lab0_end:
413 nop;
414_delay_lab1_end:
415 nop;
416#endif
417
418 /* Clear the bits 13-15 in SWRST if they werent cleared */
419 p0.h = hi(SWRST);
420 p0.l = lo(SWRST);
421 csync;
422 r0.l = w[p0];
423
424 /* Clear the IMASK register */
425 p0.h = hi(IMASK);
426 p0.l = lo(IMASK);
427 r0 = 0x0;
428 [p0] = r0;
429
430 /* Clear the ILAT register */
431 p0.h = hi(ILAT);
432 p0.l = lo(ILAT);
433 r0 = [p0];
434 [p0] = r0;
435 SSYNC;
436
437 /* Disable the WDOG TIMER */
438 p0.h = hi(WDOG_CTL);
439 p0.l = lo(WDOG_CTL);
440 r0.l = 0xAD6;
441 w[p0] = r0.l;
442 SSYNC;
443
444 /* Clear the sticky bit incase it is already set */
445 p0.h = hi(WDOG_CTL);
446 p0.l = lo(WDOG_CTL);
447 r0.l = 0x8AD6;
448 w[p0] = r0.l;
449 SSYNC;
450
451 /* Program the count value */
452 R0.l = 0x100;
453 R0.h = 0x0;
454 P0.h = hi(WDOG_CNT);
455 P0.l = lo(WDOG_CNT);
456 [P0] = R0;
457 SSYNC;
458
459 /* Program WDOG_STAT if necessary */
460 P0.h = hi(WDOG_CTL);
461 P0.l = lo(WDOG_CTL);
462 R0 = W[P0](Z);
463 CC = BITTST(R0,1);
464 if !CC JUMP .LWRITESTAT;
465 CC = BITTST(R0,2);
466 if !CC JUMP .LWRITESTAT;
467 JUMP .LSKIP_WRITE;
468
469.LWRITESTAT:
470 /* When watch dog timer is enabled,
471 * a write to STAT will load the contents of CNT to STAT
472 */
473 R0 = 0x0000(z);
474 P0.h = hi(WDOG_STAT);
475 P0.l = lo(WDOG_STAT)
476 [P0] = R0;
477 SSYNC;
478
479.LSKIP_WRITE:
480 /* Enable the reset event */
481 P0.h = hi(WDOG_CTL);
482 P0.l = lo(WDOG_CTL);
483 R0 = W[P0](Z);
484 BITCLR(R0,1);
485 BITCLR(R0,2);
486 W[P0] = R0.L;
487 SSYNC;
488 NOP;
489
490 /* Enable the wdog counter */
491 R0 = W[P0](Z);
492 BITCLR(R0,4);
493 W[P0] = R0.L;
494 SSYNC;
495
496 IDLE;
497
498 RTS;
499
500.data
501
502/*
503 * Set up the usable of RAM stuff. Size of RAM is determined then
504 * an initial stack set up at the end.
505 */
506
507.align 4
508__rambase:
509.long 0
510__ramstart:
511.long 0
512__ramend:
513.long 0