blob: 1ded945a6fa0212973a122b24d022bd79751cd2c [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
2 * File: arch/blackfin/mach-bf533/head.S
3 * Based on:
4 * Author: Jeff Dionne <jeff@uclinux.org> COPYRIGHT 1998 D. Jeff Dionne
5 *
6 * Created: 1998
7 * Description: bf533 startup file
8 *
9 * Modified:
10 * Copyright 2004-2006 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>
Mike Frysinger52a07812007-06-11 15:31:30 +080031#include <linux/init.h>
Bryan Wu1394f032007-05-06 14:50:22 -070032#include <asm/blackfin.h>
Robin Getz669b7922007-06-21 16:34:08 +080033#include <asm/trace.h>
Bryan Wu1394f032007-05-06 14:50:22 -070034#if CONFIG_BFIN_KERNEL_CLOCK
Robin Getzf16295e2007-08-03 18:07:17 +080035#include <asm/mach-common/clocks.h>
Bryan Wu1394f032007-05-06 14:50:22 -070036#include <asm/mach/mem_init.h>
37#endif
Bryan Wu1394f032007-05-06 14:50:22 -070038
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
Mike Frysinger52a07812007-06-11 15:31:30 +080048__INIT
Bryan Wu1394f032007-05-06 14:50:22 -070049
50ENTRY(__start)
Bryan Wu1394f032007-05-06 14:50:22 -070051 /* 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
Bryan Wu1394f032007-05-06 14:50:22 -070059 SYSCFG = R0;
60 R0 = 0;
61
Mike Frysinger83a5c3e2007-06-11 15:31:30 +080062 /* Clear Out All the data and pointer Registers */
Bryan Wu1394f032007-05-06 14:50:22 -070063 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
Mike Frysinger83a5c3e2007-06-11 15:31:30 +080084 /* Clear Out All the DAG Registers */
Bryan Wu1394f032007-05-06 14:50:22 -070085 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
Bryan Wu1394f032007-05-06 14:50:22 -0700104 p0.h = hi(FIO_MASKA_C);
105 p0.l = lo(FIO_MASKA_C);
106 r0 = 0xFFFF(Z);
107 w[p0] = r0.L; /* Disable all interrupts */
108 ssync;
109
110 p0.h = hi(FIO_MASKB_C);
111 p0.l = lo(FIO_MASKB_C);
112 r0 = 0xFFFF(Z);
113 w[p0] = r0.L; /* Disable all interrupts */
114 ssync;
115
116 /* Turn off the icache */
Mike Frysingere208f832007-07-25 10:11:42 +0800117 p0.l = LO(IMEM_CONTROL);
118 p0.h = HI(IMEM_CONTROL);
Bryan Wu1394f032007-05-06 14:50:22 -0700119 R1 = [p0];
120 R0 = ~ENICPLB;
121 R0 = R0 & R1;
122
123 /* Anomaly 05000125 */
Mike Frysinger1aafd902007-07-25 11:19:14 +0800124#if ANOMALY_05000125
Bryan Wu1394f032007-05-06 14:50:22 -0700125 CLI R2;
126 SSYNC;
127#endif
128 [p0] = R0;
129 SSYNC;
Mike Frysinger1aafd902007-07-25 11:19:14 +0800130#if ANOMALY_05000125
Bryan Wu1394f032007-05-06 14:50:22 -0700131 STI R2;
132#endif
133
134 /* Turn off the dcache */
Mike Frysingere208f832007-07-25 10:11:42 +0800135 p0.l = LO(DMEM_CONTROL);
136 p0.h = HI(DMEM_CONTROL);
Bryan Wu1394f032007-05-06 14:50:22 -0700137 R1 = [p0];
138 R0 = ~ENDCPLB;
139 R0 = R0 & R1;
140
141 /* Anomaly 05000125 */
Mike Frysinger1aafd902007-07-25 11:19:14 +0800142#if ANOMALY_05000125
Bryan Wu1394f032007-05-06 14:50:22 -0700143 CLI R2;
144 SSYNC;
145#endif
146 [p0] = R0;
147 SSYNC;
Mike Frysinger1aafd902007-07-25 11:19:14 +0800148#if ANOMALY_05000125
Bryan Wu1394f032007-05-06 14:50:22 -0700149 STI R2;
150#endif
151
Mike Frysinger5079df92007-05-21 18:09:27 +0800152 /* Initialise UART - when booting from u-boot, the UART is not disabled
153 * so if we dont initalize here, our serial console gets hosed */
Bryan Wu1394f032007-05-06 14:50:22 -0700154 p0.h = hi(UART_LCR);
155 p0.l = lo(UART_LCR);
156 r0 = 0x0(Z);
157 w[p0] = r0.L; /* To enable DLL writes */
158 ssync;
159
160 p0.h = hi(UART_DLL);
161 p0.l = lo(UART_DLL);
162 r0 = 0x0(Z);
163 w[p0] = r0.L;
164 ssync;
165
166 p0.h = hi(UART_DLH);
167 p0.l = lo(UART_DLH);
168 r0 = 0x00(Z);
169 w[p0] = r0.L;
170 ssync;
171
172 p0.h = hi(UART_GCTL);
173 p0.l = lo(UART_GCTL);
174 r0 = 0x0(Z);
175 w[p0] = r0.L; /* To enable UART clock */
176 ssync;
177
178 /* Initialize stack pointer */
179 sp.l = lo(INITIAL_STACK);
180 sp.h = hi(INITIAL_STACK);
181 fp = sp;
182 usp = sp;
183
Robin Getz337d3902007-10-09 17:31:46 +0800184#ifdef CONFIG_EARLY_PRINTK
185 SP += -12;
186 call _init_early_exception_vectors;
187 SP += 12;
188#endif
189
Bryan Wu1394f032007-05-06 14:50:22 -0700190 /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */
191 call _bf53x_relocate_l1_mem;
192#if CONFIG_BFIN_KERNEL_CLOCK
193 call _start_dma_code;
194#endif
195
196 /* Code for initializing Async memory banks */
197
198 p2.h = hi(EBIU_AMBCTL1);
199 p2.l = lo(EBIU_AMBCTL1);
200 r0.h = hi(AMBCTL1VAL);
201 r0.l = lo(AMBCTL1VAL);
202 [p2] = r0;
203 ssync;
204
205 p2.h = hi(EBIU_AMBCTL0);
206 p2.l = lo(EBIU_AMBCTL0);
207 r0.h = hi(AMBCTL0VAL);
208 r0.l = lo(AMBCTL0VAL);
209 [p2] = r0;
210 ssync;
211
212 p2.h = hi(EBIU_AMGCTL);
213 p2.l = lo(EBIU_AMGCTL);
214 r0 = AMGCTLVAL;
215 w[p2] = r0;
216 ssync;
217
218 /* This section keeps the processor in supervisor mode
219 * during kernel boot. Switches to user mode at end of boot.
220 * See page 3-9 of Hardware Reference manual for documentation.
221 */
222
223 /* EVT15 = _real_start */
224
225 p0.l = lo(EVT15);
226 p0.h = hi(EVT15);
227 p1.l = _real_start;
228 p1.h = _real_start;
229 [p0] = p1;
230 csync;
231
232 p0.l = lo(IMASK);
233 p0.h = hi(IMASK);
234 p1.l = IMASK_IVG15;
235 p1.h = 0x0;
236 [p0] = p1;
237 csync;
238
239 raise 15;
240 p0.l = .LWAIT_HERE;
241 p0.h = .LWAIT_HERE;
242 reti = p0;
Mike Frysinger1aafd902007-07-25 11:19:14 +0800243#if ANOMALY_05000281
Bryan Wu1394f032007-05-06 14:50:22 -0700244 nop; nop; nop;
245#endif
246 rti;
247
248.LWAIT_HERE:
249 jump .LWAIT_HERE;
Mike Frysinger52a07812007-06-11 15:31:30 +0800250ENDPROC(__start)
Bryan Wu1394f032007-05-06 14:50:22 -0700251
252ENTRY(_real_start)
253 [ -- sp ] = reti;
254 p0.l = lo(WDOG_CTL);
255 p0.h = hi(WDOG_CTL);
256 r0 = 0xAD6(z);
257 w[p0] = r0; /* watchdog off for now */
258 ssync;
259
260 /* Code update for BSS size == 0
261 * Zero out the bss region.
262 */
263
264 p1.l = ___bss_start;
265 p1.h = ___bss_start;
266 p2.l = ___bss_stop;
267 p2.h = ___bss_stop;
268 r0 = 0;
269 p2 -= p1;
270 lsetup (.L_clear_bss, .L_clear_bss) lc0 = p2;
271.L_clear_bss:
272 B[p1++] = r0;
273
274 /* In case there is a NULL pointer reference
275 * Zero out region before stext
276 */
277
278 p1.l = 0x0;
279 p1.h = 0x0;
280 r0.l = __stext;
281 r0.h = __stext;
282 r0 = r0 >> 1;
283 p2 = r0;
284 r0 = 0;
285 lsetup (.L_clear_zero, .L_clear_zero) lc0 = p2;
286.L_clear_zero:
287 W[p1++] = r0;
288
Mike Frysinger83a5c3e2007-06-11 15:31:30 +0800289 /* pass the uboot arguments to the global value command line */
Bryan Wu1394f032007-05-06 14:50:22 -0700290 R0 = R7;
291 call _cmdline_init;
292
293 p1.l = __rambase;
294 p1.h = __rambase;
295 r0.l = __sdata;
296 r0.h = __sdata;
297 [p1] = r0;
298
299 p1.l = __ramstart;
300 p1.h = __ramstart;
301 p3.l = ___bss_stop;
302 p3.h = ___bss_stop;
303
304 r1 = p3;
305 [p1] = r1;
306
307 /*
Mike Frysinger83a5c3e2007-06-11 15:31:30 +0800308 * load the current thread pointer and stack
Bryan Wu1394f032007-05-06 14:50:22 -0700309 */
310 r1.l = _init_thread_union;
311 r1.h = _init_thread_union;
312
313 r2.l = 0x2000;
314 r2.h = 0x0000;
315 r1 = r1 + r2;
316 sp = r1;
317 usp = sp;
318 fp = sp;
Mike Frysinger52a07812007-06-11 15:31:30 +0800319 jump.l _start_kernel;
320ENDPROC(_real_start)
321
322__FINIT
Bryan Wu1394f032007-05-06 14:50:22 -0700323
324.section .l1.text
325#if CONFIG_BFIN_KERNEL_CLOCK
326ENTRY(_start_dma_code)
327 p0.h = hi(SIC_IWR);
328 p0.l = lo(SIC_IWR);
329 r0.l = 0x1;
330 r0.h = 0x0;
331 [p0] = r0;
332 SSYNC;
333
334 /*
335 * Set PLL_CTL
336 * - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors
337 * - [8] = BYPASS : BYPASS the PLL, run CLKIN into CCLK/SCLK
338 * - [7] = output delay (add 200ps of delay to mem signals)
339 * - [6] = input delay (add 200ps of input delay to mem signals)
340 * - [5] = PDWN : 1=All Clocks off
341 * - [3] = STOPCK : 1=Core Clock off
342 * - [1] = PLL_OFF : 1=Disable Power to PLL
343 * - [0] = DF : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL
344 * all other bits set to zero
345 */
346
347 p0.h = hi(PLL_LOCKCNT);
348 p0.l = lo(PLL_LOCKCNT);
349 r0 = 0x300(Z);
350 w[p0] = r0.l;
351 ssync;
352
353 P2.H = hi(EBIU_SDGCTL);
354 P2.L = lo(EBIU_SDGCTL);
355 R0 = [P2];
356 BITSET (R0, 24);
357 [P2] = R0;
358 SSYNC;
359
360 r0 = CONFIG_VCO_MULT & 63; /* Load the VCO multiplier */
361 r0 = r0 << 9; /* Shift it over, */
362 r1 = CLKIN_HALF; /* Do we need to divide CLKIN by 2?*/
363 r0 = r1 | r0;
364 r1 = PLL_BYPASS; /* Bypass the PLL? */
365 r1 = r1 << 8; /* Shift it over */
366 r0 = r1 | r0; /* add them all together */
367
368 p0.h = hi(PLL_CTL);
369 p0.l = lo(PLL_CTL); /* Load the address */
370 cli r2; /* Disable interrupts */
371 ssync;
372 w[p0] = r0.l; /* Set the value */
373 idle; /* Wait for the PLL to stablize */
374 sti r2; /* Enable interrupts */
375
376.Lcheck_again:
377 p0.h = hi(PLL_STAT);
378 p0.l = lo(PLL_STAT);
379 R0 = W[P0](Z);
380 CC = BITTST(R0,5);
381 if ! CC jump .Lcheck_again;
382
383 /* Configure SCLK & CCLK Dividers */
384 r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
385 p0.h = hi(PLL_DIV);
386 p0.l = lo(PLL_DIV);
387 w[p0] = r0.l;
388 ssync;
389
390 p0.l = lo(EBIU_SDRRC);
391 p0.h = hi(EBIU_SDRRC);
392 r0 = mem_SDRRC;
393 w[p0] = r0.l;
394 ssync;
395
Mike Frysingere208f832007-07-25 10:11:42 +0800396 p0.l = LO(EBIU_SDBCTL);
397 p0.h = HI(EBIU_SDBCTL); /* SDRAM Memory Bank Control Register */
Bryan Wu1394f032007-05-06 14:50:22 -0700398 r0 = mem_SDBCTL;
399 w[p0] = r0.l;
400 ssync;
401
402 P2.H = hi(EBIU_SDGCTL);
403 P2.L = lo(EBIU_SDGCTL);
404 R0 = [P2];
405 BITCLR (R0, 24);
406 p0.h = hi(EBIU_SDSTAT);
407 p0.l = lo(EBIU_SDSTAT);
408 r2.l = w[p0];
409 cc = bittst(r2,3);
410 if !cc jump .Lskip;
411 NOP;
412 BITSET (R0, 23);
413.Lskip:
414 [P2] = R0;
415 SSYNC;
416
417 R0.L = lo(mem_SDGCTL);
418 R0.H = hi(mem_SDGCTL);
419 R1 = [p2];
420 R1 = R1 | R0;
421 [P2] = R1;
422 SSYNC;
423
424 p0.h = hi(SIC_IWR);
425 p0.l = lo(SIC_IWR);
Mike Frysinger83a5c3e2007-06-11 15:31:30 +0800426 r0.l = lo(IWR_ENABLE_ALL);
427 r0.h = hi(IWR_ENABLE_ALL);
Bryan Wu1394f032007-05-06 14:50:22 -0700428 [p0] = r0;
429 SSYNC;
430
431 RTS;
Mike Frysinger52a07812007-06-11 15:31:30 +0800432ENDPROC(_start_dma_code)
Bryan Wu1394f032007-05-06 14:50:22 -0700433#endif /* CONFIG_BFIN_KERNEL_CLOCK */
434
Bryan Wu1394f032007-05-06 14:50:22 -0700435.data
436
437/*
438 * Set up the usable of RAM stuff. Size of RAM is determined then
439 * an initial stack set up at the end.
440 */
441
442.align 4
443__rambase:
444.long 0
445__ramstart:
446.long 0
447__ramend:
448.long 0