blob: 3071c243d42672147e83bfe415ca602c5e2acbb9 [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
161 /* This section keeps the processor in supervisor mode
162 * during kernel boot. Switches to user mode at end of boot.
163 * See page 3-9 of Hardware Reference manual for documentation.
164 */
165
166 /* EVT15 = _real_start */
167
168 p0.l = lo(EVT15);
169 p0.h = hi(EVT15);
170 p1.l = _real_start;
171 p1.h = _real_start;
172 [p0] = p1;
173 csync;
174
175 p0.l = lo(IMASK);
176 p0.h = hi(IMASK);
177 p1.l = IMASK_IVG15;
178 p1.h = 0x0;
179 [p0] = p1;
180 csync;
181
182 raise 15;
183 p0.l = .LWAIT_HERE;
184 p0.h = .LWAIT_HERE;
185 reti = p0;
Mike Frysinger1aafd902007-07-25 11:19:14 +0800186#if ANOMALY_05000281
Roy Huang24a07a12007-07-12 22:41:45 +0800187 nop;
188 nop;
189 nop;
190#endif
191 rti;
192
193.LWAIT_HERE:
194 jump .LWAIT_HERE;
195
196ENTRY(_real_start)
197 [ -- sp ] = reti;
198 p0.l = lo(WDOG_CTL);
199 p0.h = hi(WDOG_CTL);
200 r0 = 0xAD6(z);
201 w[p0] = r0; /* watchdog off for now */
202 ssync;
203
204 /* Code update for BSS size == 0
205 * Zero out the bss region.
206 */
207
208 p1.l = ___bss_start;
209 p1.h = ___bss_start;
210 p2.l = ___bss_stop;
211 p2.h = ___bss_stop;
212 r0 = 0;
213 p2 -= p1;
214 lsetup (.L_clear_bss, .L_clear_bss ) lc0 = p2;
215.L_clear_bss:
216 B[p1++] = r0;
217
218 /* In case there is a NULL pointer reference
219 * Zero out region before stext
220 */
221
222 p1.l = 0x0;
223 p1.h = 0x0;
224 r0.l = __stext;
225 r0.h = __stext;
226 r0 = r0 >> 1;
227 p2 = r0;
228 r0 = 0;
229 lsetup (.L_clear_zero, .L_clear_zero ) lc0 = p2;
230.L_clear_zero:
231 W[p1++] = r0;
232
233 /* pass the uboot arguments to the global value command line */
234 R0 = R7;
235 call _cmdline_init;
236
237 p1.l = __rambase;
238 p1.h = __rambase;
239 r0.l = __sdata;
240 r0.h = __sdata;
241 [p1] = r0;
242
243 p1.l = __ramstart;
244 p1.h = __ramstart;
245 p3.l = ___bss_stop;
246 p3.h = ___bss_stop;
247
248 r1 = p3;
249 [p1] = r1;
250
251
252 /*
253 * load the current thread pointer and stack
254 */
255 r1.l = _init_thread_union;
256 r1.h = _init_thread_union;
257
258 r2.l = 0x2000;
259 r2.h = 0x0000;
260 r1 = r1 + r2;
261 sp = r1;
262 usp = sp;
263 fp = sp;
264 call _start_kernel;
265.L_exit:
266 jump.s .L_exit;
267
268.section .l1.text
269#if CONFIG_BFIN_KERNEL_CLOCK
270ENTRY(_start_dma_code)
271
272 /* Enable PHY CLK buffer output */
273 p0.h = hi(VR_CTL);
274 p0.l = lo(VR_CTL);
275 r0.l = w[p0];
276 bitset(r0, 14);
277 w[p0] = r0.l;
278 ssync;
279
280 p0.h = hi(SIC_IWR);
281 p0.l = lo(SIC_IWR);
282 r0.l = 0x1;
283 r0.h = 0x0;
284 [p0] = r0;
285 SSYNC;
286
287 /*
288 * Set PLL_CTL
289 * - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors
290 * - [8] = BYPASS : BYPASS the PLL, run CLKIN into CCLK/SCLK
291 * - [7] = output delay (add 200ps of delay to mem signals)
292 * - [6] = input delay (add 200ps of input delay to mem signals)
293 * - [5] = PDWN : 1=All Clocks off
294 * - [3] = STOPCK : 1=Core Clock off
295 * - [1] = PLL_OFF : 1=Disable Power to PLL
296 * - [0] = DF : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL
297 * all other bits set to zero
298 */
299
300 p0.h = hi(PLL_LOCKCNT);
301 p0.l = lo(PLL_LOCKCNT);
302 r0 = 0x300(Z);
303 w[p0] = r0.l;
304 ssync;
305
306 P2.H = hi(EBIU_SDGCTL);
307 P2.L = lo(EBIU_SDGCTL);
308 R0 = [P2];
309 BITSET (R0, 24);
310 [P2] = R0;
311 SSYNC;
312
313 r0 = CONFIG_VCO_MULT & 63; /* Load the VCO multiplier */
314 r0 = r0 << 9; /* Shift it over, */
315 r1 = CLKIN_HALF; /* Do we need to divide CLKIN by 2?*/
316 r0 = r1 | r0;
317 r1 = PLL_BYPASS; /* Bypass the PLL? */
318 r1 = r1 << 8; /* Shift it over */
319 r0 = r1 | r0; /* add them all together */
320
321 p0.h = hi(PLL_CTL);
322 p0.l = lo(PLL_CTL); /* Load the address */
323 cli r2; /* Disable interrupts */
324 ssync;
325 w[p0] = r0.l; /* Set the value */
326 idle; /* Wait for the PLL to stablize */
327 sti r2; /* Enable interrupts */
328
329.Lcheck_again:
330 p0.h = hi(PLL_STAT);
331 p0.l = lo(PLL_STAT);
332 R0 = W[P0](Z);
333 CC = BITTST(R0,5);
334 if ! CC jump .Lcheck_again;
335
336 /* Configure SCLK & CCLK Dividers */
337 r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
338 p0.h = hi(PLL_DIV);
339 p0.l = lo(PLL_DIV);
340 w[p0] = r0.l;
341 ssync;
342
343 p0.l = lo(EBIU_SDRRC);
344 p0.h = hi(EBIU_SDRRC);
345 r0 = mem_SDRRC;
346 w[p0] = r0.l;
347 ssync;
348
Mike Frysingere208f832007-07-25 10:11:42 +0800349 p0.l = LO(EBIU_SDBCTL);
350 p0.h = HI(EBIU_SDBCTL); /* SDRAM Memory Bank Control Register */
Roy Huang24a07a12007-07-12 22:41:45 +0800351 r0 = mem_SDBCTL;
352 w[p0] = r0.l;
353 ssync;
354
355 P2.H = hi(EBIU_SDGCTL);
356 P2.L = lo(EBIU_SDGCTL);
357 R0 = [P2];
358 BITCLR (R0, 24);
359 p0.h = hi(EBIU_SDSTAT);
360 p0.l = lo(EBIU_SDSTAT);
361 r2.l = w[p0];
362 cc = bittst(r2,3);
363 if !cc jump .Lskip;
364 NOP;
365 BITSET (R0, 23);
366.Lskip:
367 [P2] = R0;
368 SSYNC;
369
370 R0.L = lo(mem_SDGCTL);
371 R0.H = hi(mem_SDGCTL);
372 R1 = [p2];
373 R1 = R1 | R0;
374 [P2] = R1;
375 SSYNC;
376
377 p0.h = hi(SIC_IWR);
378 p0.l = lo(SIC_IWR);
379 r0.l = lo(IWR_ENABLE_ALL);
380 r0.h = hi(IWR_ENABLE_ALL);
381 [p0] = r0;
382 SSYNC;
383
384 RTS;
385#endif /* CONFIG_BFIN_KERNEL_CLOCK */
386
Roy Huang24a07a12007-07-12 22:41:45 +0800387.data
388
389/*
390 * Set up the usable of RAM stuff. Size of RAM is determined then
391 * an initial stack set up at the end.
392 */
393
394.align 4
395__rambase:
396.long 0
397__ramstart:
398.long 0
399__ramend:
400.long 0