blob: ba38678be3c1e79dc757df78f99ea960db513957 [file] [log] [blame]
TsiChungLiew8ae158c2007-08-16 15:05:11 -05001/*
2 * Copyright (C) 2003 Josef Baumgartner <josef.baumgartner@telex.de>
3 * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com>
4 *
Alison Wang45370e12012-10-18 19:25:51 +00005 * Copyright 2010-2012 Freescale Semiconductor, Inc.
6 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
7 *
Wolfgang Denk3765b3e2013-10-07 13:07:26 +02008 * SPDX-License-Identifier: GPL-2.0+
TsiChungLiew8ae158c2007-08-16 15:05:11 -05009 */
10
Alison Wang45370e12012-10-18 19:25:51 +000011#include <common.h>
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +020012#include <asm-offsets.h>
TsiChungLiew8ae158c2007-08-16 15:05:11 -050013#include <config.h>
Alison Wang45370e12012-10-18 19:25:51 +000014#include <timestamp.h>
TsiChungLiew8ae158c2007-08-16 15:05:11 -050015#include "version.h"
TsiChung Liewdd9f0542010-03-11 22:12:53 -060016#include <asm/cache.h>
TsiChungLiew8ae158c2007-08-16 15:05:11 -050017
18#ifndef CONFIG_IDENT_STRING
19#define CONFIG_IDENT_STRING ""
20#endif
21
TsiChungLiew8ae158c2007-08-16 15:05:11 -050022#define _START _start
23#define _FAULT _fault
24
25#define SAVE_ALL \
26 move.w #0x2700,%sr; /* disable intrs */ \
27 subl #60,%sp; /* space for 15 regs */ \
28 moveml %d0-%d7/%a0-%a6,%sp@;
29
30#define RESTORE_ALL \
31 moveml %sp@,%d0-%d7/%a0-%a6; \
32 addl #60,%sp; /* space for 15 regs */ \
33 rte;
34
Alison Wang45370e12012-10-18 19:25:51 +000035#if defined(CONFIG_SERIAL_BOOT)
Wolfgang Denk14d0a022010-10-07 21:51:12 +020036#define ASM_DRAMINIT (asm_dram_init - CONFIG_SYS_TEXT_BASE + CONFIG_SYS_INIT_RAM_ADDR)
Masahiro Yamada61a43922015-12-11 12:22:25 +090037#define ASM_DRAMINIT_N (asm_dram_init - CONFIG_SYS_TEXT_BASE)
Wolfgang Denk14d0a022010-10-07 21:51:12 +020038#define ASM_SBF_IMG_HDR (asm_sbf_img_hdr - CONFIG_SYS_TEXT_BASE + CONFIG_SYS_INIT_RAM_ADDR)
TsiChung Liew9f751552008-07-23 20:38:53 -050039#endif
40
TsiChungLiew8ae158c2007-08-16 15:05:11 -050041.text
TsiChung Liew9f751552008-07-23 20:38:53 -050042
TsiChungLiew8ae158c2007-08-16 15:05:11 -050043/*
44 * Vector table. This is used for initial platform startup.
45 * These vectors are to catch any un-intended traps.
46 */
47_vectors:
Alison Wang45370e12012-10-18 19:25:51 +000048#if defined(CONFIG_SERIAL_BOOT)
TsiChungLiew8ae158c2007-08-16 15:05:11 -050049
TsiChung Liew9f751552008-07-23 20:38:53 -050050INITSP: .long 0 /* Initial SP */
Alison Wang45370e12012-10-18 19:25:51 +000051#ifdef CONFIG_CF_SBF
TsiChung Liew9f751552008-07-23 20:38:53 -050052INITPC: .long ASM_DRAMINIT /* Initial PC */
Alison Wang45370e12012-10-18 19:25:51 +000053#endif
54#ifdef CONFIG_SYS_NAND_BOOT
55INITPC: .long ASM_DRAMINIT_N /* Initial PC */
56#endif
TsiChung Liew9f751552008-07-23 20:38:53 -050057
58#else
59
60INITSP: .long 0 /* Initial SP */
61INITPC: .long _START /* Initial PC */
62
63#endif
64
TsiChungLiew8ae158c2007-08-16 15:05:11 -050065vector02: .long _FAULT /* Access Error */
66vector03: .long _FAULT /* Address Error */
67vector04: .long _FAULT /* Illegal Instruction */
68vector05: .long _FAULT /* Reserved */
69vector06: .long _FAULT /* Reserved */
70vector07: .long _FAULT /* Reserved */
71vector08: .long _FAULT /* Privilege Violation */
72vector09: .long _FAULT /* Trace */
73vector0A: .long _FAULT /* Unimplemented A-Line */
74vector0B: .long _FAULT /* Unimplemented F-Line */
75vector0C: .long _FAULT /* Debug Interrupt */
76vector0D: .long _FAULT /* Reserved */
77vector0E: .long _FAULT /* Format Error */
78vector0F: .long _FAULT /* Unitialized Int. */
79
80/* Reserved */
81vector10_17:
82.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
83
84vector18: .long _FAULT /* Spurious Interrupt */
85vector19: .long _FAULT /* Autovector Level 1 */
86vector1A: .long _FAULT /* Autovector Level 2 */
87vector1B: .long _FAULT /* Autovector Level 3 */
88vector1C: .long _FAULT /* Autovector Level 4 */
89vector1D: .long _FAULT /* Autovector Level 5 */
90vector1E: .long _FAULT /* Autovector Level 6 */
91vector1F: .long _FAULT /* Autovector Level 7 */
92
Alison Wang45370e12012-10-18 19:25:51 +000093#if !defined(CONFIG_SERIAL_BOOT)
TsiChung Liew9f751552008-07-23 20:38:53 -050094
TsiChungLiew8ae158c2007-08-16 15:05:11 -050095/* TRAP #0 - #15 */
96vector20_2F:
97.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
98.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
99
100/* Reserved */
101vector30_3F:
102.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
103.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
104
105vector64_127:
106.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
107.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
108.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
109.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
110.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
111.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
112.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
113.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
114
115vector128_191:
116.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
117.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
118.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
119.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
120.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
121.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
122.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
123.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
124
125vector192_255:
126.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
127.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
128.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
129.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
130.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
131.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
132.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
133.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
TsiChung Liew9f751552008-07-23 20:38:53 -0500134#endif
135
Alison Wang45370e12012-10-18 19:25:51 +0000136#if defined(CONFIG_SERIAL_BOOT)
TsiChung Liew9f751552008-07-23 20:38:53 -0500137 /* Image header: chksum 4 bytes, len 4 bytes, img dest 4 bytes */
138asm_sbf_img_hdr:
139 .long 0x00000000 /* checksum, not yet implemented */
Alison Wang45370e12012-10-18 19:25:51 +0000140 .long 0x00040000 /* image length */
Wolfgang Denk14d0a022010-10-07 21:51:12 +0200141 .long CONFIG_SYS_TEXT_BASE /* image to be relocated at */
TsiChung Liew9f751552008-07-23 20:38:53 -0500142
143asm_dram_init:
TsiChung Liew709b3842009-06-11 15:39:57 +0000144 move.w #0x2700,%sr /* Mask off Interrupt */
145
Alison Wang45370e12012-10-18 19:25:51 +0000146#ifdef CONFIG_SYS_NAND_BOOT
147 /* for assembly stack */
148 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
149 movec %d0, %RAMBAR1
150
151 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
152 clr.l %sp@-
153#endif
154
155#ifdef CONFIG_CF_SBF
TsiChung Liew709b3842009-06-11 15:39:57 +0000156 move.l #CONFIG_SYS_INIT_RAM_ADDR, %d0
157 movec %d0, %VBR
158
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200159 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
TsiChung Liew709b3842009-06-11 15:39:57 +0000160 movec %d0, %RAMBAR1
161
162 /* initialize general use internal ram */
163 move.l #0, %d0
TsiChung Liewdd9f0542010-03-11 22:12:53 -0600164 move.l #(ICACHE_STATUS), %a1 /* icache */
165 move.l #(DCACHE_STATUS), %a2 /* dcache */
TsiChung Liew709b3842009-06-11 15:39:57 +0000166 move.l %d0, (%a1)
167 move.l %d0, (%a2)
TsiChung Liew709b3842009-06-11 15:39:57 +0000168
169 /* invalidate and disable cache */
TsiChung Liewdd9f0542010-03-11 22:12:53 -0600170 move.l #(CONFIG_SYS_ICACHE_INV + CONFIG_SYS_DCACHE_INV), %d0
TsiChung Liew709b3842009-06-11 15:39:57 +0000171 movec %d0, %CACR /* Invalidate cache */
172 move.l #0, %d0
173 movec %d0, %ACR0
174 movec %d0, %ACR1
175 movec %d0, %ACR2
176 movec %d0, %ACR3
177
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200178 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
TsiChung Liew9f751552008-07-23 20:38:53 -0500179 clr.l %sp@-
180
181 /* Must disable global address */
182 move.l #0xFC008000, %a1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200183 move.l #(CONFIG_SYS_CS0_BASE), (%a1)
TsiChung Liew9f751552008-07-23 20:38:53 -0500184 move.l #0xFC008008, %a1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200185 move.l #(CONFIG_SYS_CS0_CTRL), (%a1)
TsiChung Liew9f751552008-07-23 20:38:53 -0500186 move.l #0xFC008004, %a1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200187 move.l #(CONFIG_SYS_CS0_MASK), (%a1)
Alison Wang45370e12012-10-18 19:25:51 +0000188#endif /* CONFIG_CF_SBF */
TsiChung Liew9f751552008-07-23 20:38:53 -0500189
Alison Wang45370e12012-10-18 19:25:51 +0000190#ifdef CONFIG_MCF5441x
191 /* TC: enable all peripherals,
192 in the future only enable certain peripherals */
193 move.l #0xFC04002D, %a1
194
195#if defined(CONFIG_CF_SBF)
196 move.b #23, (%a1) /* dspi */
197#endif
198 move.b #46, (%a1) /* DDR */
199
200 /* slew settings */
201 move.l #0xEC094060, %a1
202 move.b #0, (%a1)
203
204 /* use vco instead of cpu*2 clock for ddr clock */
205 move.l #0xEC09001A, %a1
206 move.w #0xE01D, (%a1)
207
208 /* DDR settings */
209 move.l #0xFC0B8180, %a1
210 move.l #0x00000000, (%a1)
211 move.l #0x40000000, (%a1)
212
213 move.l #0xFC0B81AC, %a1
214 move.l #0x01030203, (%a1)
215
216 move.l #0xFC0B8000, %a1
217 move.l #0x01010101, (%a1)+ /* 0x00 */
218 move.l #0x00000101, (%a1)+ /* 0x04 */
219 move.l #0x01010100, (%a1)+ /* 0x08 */
220 move.l #0x01010000, (%a1)+ /* 0x0C */
221 move.l #0x00010101, (%a1)+ /* 0x10 */
222 move.l #0xFC0B8018, %a1
223 move.l #0x00010100, (%a1)+ /* 0x18 */
224 move.l #0x00000001, (%a1)+ /* 0x1C */
225 move.l #0x01000001, (%a1)+ /* 0x20 */
226 move.l #0x00000100, (%a1)+ /* 0x24 */
227 move.l #0x00010001, (%a1)+ /* 0x28 */
228 move.l #0x00000200, (%a1)+ /* 0x2C */
229 move.l #0x01000002, (%a1)+ /* 0x30 */
230 move.l #0x00000000, (%a1)+ /* 0x34 */
231 move.l #0x00000100, (%a1)+ /* 0x38 */
232 move.l #0x02000100, (%a1)+ /* 0x3C */
233 move.l #0x02000407, (%a1)+ /* 0x40 */
234 move.l #0x02030007, (%a1)+ /* 0x44 */
235 move.l #0x02000100, (%a1)+ /* 0x48 */
236 move.l #0x0A030203, (%a1)+ /* 0x4C */
237 move.l #0x00020708, (%a1)+ /* 0x50 */
238 move.l #0x00050008, (%a1)+ /* 0x54 */
239 move.l #0x04030002, (%a1)+ /* 0x58 */
240 move.l #0x00000004, (%a1)+ /* 0x5C */
241 move.l #0x020A0000, (%a1)+ /* 0x60 */
242 move.l #0x0C00000E, (%a1)+ /* 0x64 */
243 move.l #0x00002004, (%a1)+ /* 0x68 */
244 move.l #0x00000000, (%a1)+ /* 0x6C */
245 move.l #0x00100010, (%a1)+ /* 0x70 */
246 move.l #0x00100010, (%a1)+ /* 0x74 */
247 move.l #0x00000000, (%a1)+ /* 0x78 */
248 move.l #0x07990000, (%a1)+ /* 0x7C */
249 move.l #0xFC0B80A0, %a1
250 move.l #0x00000000, (%a1)+ /* 0xA0 */
251 move.l #0x00C80064, (%a1)+ /* 0xA4 */
252 move.l #0x44520002, (%a1)+ /* 0xA8 */
253 move.l #0x00C80023, (%a1)+ /* 0xAC */
254 move.l #0xFC0B80B4, %a1
255 move.l #0x0000C350, (%a1) /* 0xB4 */
256 move.l #0xFC0B80E0, %a1
257 move.l #0x04000000, (%a1)+ /* 0xE0 */
258 move.l #0x03000304, (%a1)+ /* 0xE4 */
259 move.l #0x40040000, (%a1)+ /* 0xE8 */
260 move.l #0xC0004004, (%a1)+ /* 0xEC */
261 move.l #0x0642C000, (%a1)+ /* 0xF0 */
262 move.l #0x00000642, (%a1)+ /* 0xF4 */
263 move.l #0xFC0B8024, %a1
264 tpf
265 move.l #0x01000100, (%a1) /* 0x24 */
266
267 move.l #0x2000, %d1
268 jsr asm_delay
269#endif /* CONFIG_MCF5441x */
270
271#ifdef CONFIG_MCF5445x
TsiChung Liew709b3842009-06-11 15:39:57 +0000272 /* Dram Initialization a1, a2, and d0 */
TsiChung Liew9f751552008-07-23 20:38:53 -0500273 /* mscr sdram */
274 move.l #0xFC0A4074, %a1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200275 move.b #(CONFIG_SYS_SDRAM_DRV_STRENGTH), (%a1)
TsiChung Liew9f751552008-07-23 20:38:53 -0500276 nop
277
278 /* SDRAM Chip 0 and 1 */
279 move.l #0xFC0B8110, %a1
280 move.l #0xFC0B8114, %a2
281
282 /* calculate the size */
283 move.l #0x13, %d1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200284 move.l #(CONFIG_SYS_SDRAM_SIZE), %d2
285#ifdef CONFIG_SYS_SDRAM_BASE1
TsiChung Liew9f751552008-07-23 20:38:53 -0500286 lsr.l #1, %d2
287#endif
288
289dramsz_loop:
290 lsr.l #1, %d2
291 add.l #1, %d1
292 cmp.l #1, %d2
293 bne dramsz_loop
Alison Wang45370e12012-10-18 19:25:51 +0000294#ifdef CONFIG_SYS_NAND_BOOT
295 beq asm_nand_chk_status
296#endif
TsiChung Liew9f751552008-07-23 20:38:53 -0500297 /* SDRAM Chip 0 and 1 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200298 move.l #(CONFIG_SYS_SDRAM_BASE), (%a1)
TsiChung Liew9f751552008-07-23 20:38:53 -0500299 or.l %d1, (%a1)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200300#ifdef CONFIG_SYS_SDRAM_BASE1
301 move.l #(CONFIG_SYS_SDRAM_BASE1), (%a2)
TsiChung Liew9f751552008-07-23 20:38:53 -0500302 or.l %d1, (%a2)
303#endif
304 nop
305
306 /* dram cfg1 and cfg2 */
307 move.l #0xFC0B8008, %a1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200308 move.l #(CONFIG_SYS_SDRAM_CFG1), (%a1)
TsiChung Liew9f751552008-07-23 20:38:53 -0500309 nop
310 move.l #0xFC0B800C, %a2
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200311 move.l #(CONFIG_SYS_SDRAM_CFG2), (%a2)
TsiChung Liew9f751552008-07-23 20:38:53 -0500312 nop
313
314 move.l #0xFC0B8000, %a1 /* Mode */
315 move.l #0xFC0B8004, %a2 /* Ctrl */
316
TsiChung Liew9f751552008-07-23 20:38:53 -0500317 /* Issue PALL */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200318 move.l #(CONFIG_SYS_SDRAM_CTRL + 2), (%a2)
TsiChung Liew9f751552008-07-23 20:38:53 -0500319 nop
320
TsiChung Liew709b3842009-06-11 15:39:57 +0000321#ifdef CONFIG_M54455EVB
TsiChung Liew9f751552008-07-23 20:38:53 -0500322 /* Issue LEMR */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200323 move.l #(CONFIG_SYS_SDRAM_EMOD + 0x408), (%a1)
TsiChung Liew9f751552008-07-23 20:38:53 -0500324 nop
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200325 move.l #(CONFIG_SYS_SDRAM_MODE + 0x300), (%a1)
TsiChung Liew9f751552008-07-23 20:38:53 -0500326 nop
TsiChung Liew9f751552008-07-23 20:38:53 -0500327#endif
328
TsiChung Liew709b3842009-06-11 15:39:57 +0000329 move.l #1000, %d1
330 jsr asm_delay
331
TsiChung Liew9f751552008-07-23 20:38:53 -0500332 /* Issue PALL */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200333 move.l #(CONFIG_SYS_SDRAM_CTRL + 2), (%a2)
TsiChung Liew9f751552008-07-23 20:38:53 -0500334 nop
335
336 /* Perform two refresh cycles */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200337 move.l #(CONFIG_SYS_SDRAM_CTRL + 4), %d0
TsiChung Liew9f751552008-07-23 20:38:53 -0500338 nop
339 move.l %d0, (%a2)
340 move.l %d0, (%a2)
341 nop
342
343#ifdef CONFIG_M54455EVB
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200344 move.l #(CONFIG_SYS_SDRAM_MODE + 0x200), (%a1)
TsiChung Liew9f751552008-07-23 20:38:53 -0500345 nop
346#elif defined(CONFIG_M54451EVB)
347 /* Issue LEMR */
TsiChung Liewc3a9e632009-02-18 11:49:31 +0000348 move.l #(CONFIG_SYS_SDRAM_MODE), (%a1)
TsiChung Liew9f751552008-07-23 20:38:53 -0500349 nop
TsiChung Liewc3a9e632009-02-18 11:49:31 +0000350 move.l #(CONFIG_SYS_SDRAM_EMOD), (%a1)
TsiChung Liew9f751552008-07-23 20:38:53 -0500351#endif
352
TsiChung Liew709b3842009-06-11 15:39:57 +0000353 move.l #500, %d1
354 jsr asm_delay
TsiChung Liew9f751552008-07-23 20:38:53 -0500355
TsiChung Liew709b3842009-06-11 15:39:57 +0000356 move.l #(CONFIG_SYS_SDRAM_CTRL), %d1
357 and.l #0x7FFFFFFF, %d1
TsiChung Liew9f751552008-07-23 20:38:53 -0500358#ifdef CONFIG_M54455EVB
TsiChung Liew709b3842009-06-11 15:39:57 +0000359 or.l #0x10000C00, %d1
TsiChung Liew9f751552008-07-23 20:38:53 -0500360#elif defined(CONFIG_M54451EVB)
TsiChung Liew709b3842009-06-11 15:39:57 +0000361 or.l #0x10000C00, %d1
TsiChung Liew9f751552008-07-23 20:38:53 -0500362#endif
TsiChung Liew709b3842009-06-11 15:39:57 +0000363 move.l %d1, (%a2)
TsiChung Liew9f751552008-07-23 20:38:53 -0500364 nop
365
TsiChung Liew709b3842009-06-11 15:39:57 +0000366 move.l #2000, %d1
367 jsr asm_delay
Alison Wang45370e12012-10-18 19:25:51 +0000368#endif /* CONFIG_MCF5445x */
TsiChung Liew709b3842009-06-11 15:39:57 +0000369
Alison Wang45370e12012-10-18 19:25:51 +0000370#ifdef CONFIG_CF_SBF
TsiChung Liew9f751552008-07-23 20:38:53 -0500371 /*
372 * DSPI Initialization
373 * a0 - general, sram - 0x80008000 - 32, see M54455EVB.h
374 * a1 - dspi status
375 * a2 - dtfr
376 * a3 - drfr
377 * a4 - Dst addr
378 */
379 /* Enable pins for DSPI mode - chip-selects are enabled later */
TsiChung Liew709b3842009-06-11 15:39:57 +0000380asm_dspi_init:
Alison Wang45370e12012-10-18 19:25:51 +0000381#ifdef CONFIG_MCF5441x
382 move.l #0xEC09404E, %a1
383 move.l #0xEC09404F, %a2
384 move.b #0xFF, (%a1)
385 move.b #0x80, (%a2)
386#endif
387
388#ifdef CONFIG_MCF5445x
TsiChung Liew9f751552008-07-23 20:38:53 -0500389 move.l #0xFC0A4063, %a0
390 move.b #0x7F, (%a0)
Alison Wang45370e12012-10-18 19:25:51 +0000391#endif
TsiChung Liew9f751552008-07-23 20:38:53 -0500392 /* Configure DSPI module */
393 move.l #0xFC05C000, %a0
394 move.l #0x80FF0C00, (%a0) /* Master, clear TX/RX FIFO */
395
396 move.l #0xFC05C00C, %a0
Alison Wang45370e12012-10-18 19:25:51 +0000397#ifdef CONFIG_MCF5441x
398 move.l #0x3E000016, (%a0)
399#endif
400#ifdef CONFIG_MCF5445x
TsiChung Liew9f751552008-07-23 20:38:53 -0500401 move.l #0x3E000011, (%a0)
Alison Wang45370e12012-10-18 19:25:51 +0000402#endif
TsiChung Liew9f751552008-07-23 20:38:53 -0500403
404 move.l #0xFC05C034, %a2 /* dtfr */
405 move.l #0xFC05C03B, %a3 /* drfr */
406
407 move.l #(ASM_SBF_IMG_HDR + 4), %a1
408 move.l (%a1)+, %d5
409 move.l (%a1), %a4
410
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200411 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_SBFHDR_DATA_OFFSET), %a0
412 move.l #(CONFIG_SYS_SBFHDR_SIZE), %d4
TsiChung Liew9f751552008-07-23 20:38:53 -0500413
414 move.l #0xFC05C02C, %a1 /* dspi status */
415
416 /* Issue commands and address */
417 move.l #0x8002000B, %d2 /* Fast Read Cmd */
418 jsr asm_dspi_wr_status
419 jsr asm_dspi_rd_status
420
421 move.l #0x80020000, %d2 /* Address byte 2 */
422 jsr asm_dspi_wr_status
423 jsr asm_dspi_rd_status
424
425 move.l #0x80020000, %d2 /* Address byte 1 */
426 jsr asm_dspi_wr_status
427 jsr asm_dspi_rd_status
428
429 move.l #0x80020000, %d2 /* Address byte 0 */
430 jsr asm_dspi_wr_status
431 jsr asm_dspi_rd_status
432
433 move.l #0x80020000, %d2 /* Dummy Wr and Rd */
434 jsr asm_dspi_wr_status
435 jsr asm_dspi_rd_status
436
437 /* Transfer serial boot header to sram */
438asm_dspi_rd_loop1:
439 move.l #0x80020000, %d2
440 jsr asm_dspi_wr_status
441 jsr asm_dspi_rd_status
442
443 move.b %d1, (%a0) /* read, copy to dst */
444
445 add.l #1, %a0 /* inc dst by 1 */
446 sub.l #1, %d4 /* dec cnt by 1 */
447 bne asm_dspi_rd_loop1
448
449 /* Transfer u-boot from serial flash to memory */
450asm_dspi_rd_loop2:
451 move.l #0x80020000, %d2
452 jsr asm_dspi_wr_status
453 jsr asm_dspi_rd_status
454
455 move.b %d1, (%a4) /* read, copy to dst */
456
457 add.l #1, %a4 /* inc dst by 1 */
458 sub.l #1, %d5 /* dec cnt by 1 */
459 bne asm_dspi_rd_loop2
460
461 move.l #0x00020000, %d2 /* Terminate */
462 jsr asm_dspi_wr_status
463 jsr asm_dspi_rd_status
464
465 /* jump to memory and execute */
Wolfgang Denk14d0a022010-10-07 21:51:12 +0200466 move.l #(CONFIG_SYS_TEXT_BASE + 0x400), %a0
TsiChung Liew9f751552008-07-23 20:38:53 -0500467 jmp (%a0)
468
469asm_dspi_wr_status:
470 move.l (%a1), %d0 /* status */
471 and.l #0x0000F000, %d0
472 cmp.l #0x00003000, %d0
473 bgt asm_dspi_wr_status
474
475 move.l %d2, (%a2)
476 rts
477
478asm_dspi_rd_status:
479 move.l (%a1), %d0 /* status */
480 and.l #0x000000F0, %d0
481 lsr.l #4, %d0
482 cmp.l #0, %d0
483 beq asm_dspi_rd_status
484
485 move.b (%a3), %d1
486 rts
Alison Wang45370e12012-10-18 19:25:51 +0000487#endif /* CONFIG_CF_SBF */
488
489#ifdef CONFIG_SYS_NAND_BOOT
490 /* copy 4 boot pages to dram as soon as possible */
491 /* each page is 996 bytes (1056 total with 60 ECC bytes */
492 move.l #0x00000000, %a1 /* src */
Masahiro Yamada61a43922015-12-11 12:22:25 +0900493 move.l #CONFIG_SYS_TEXT_BASE, %a2 /* dst */
Alison Wang45370e12012-10-18 19:25:51 +0000494 move.l #0x3E0, %d0 /* sz in long */
495
496asm_boot_nand_copy:
497 move.l (%a1)+, (%a2)+
498 subq.l #1, %d0
499 bne asm_boot_nand_copy
500
501 /* jump to memory and execute */
502 move.l #(asm_nand_init), %a0
503 jmp (%a0)
504
505asm_nand_init:
506 /* exit nand boot-mode */
507 move.l #0xFC0FFF30, %a1
508 or.l #0x00000040, %d1
509 move.l %d1, (%a1)
510
511 /* initialize general use internal ram */
512 move.l #0, %d0
513 move.l #(CACR_STATUS), %a1 /* CACR */
514 move.l #(ICACHE_STATUS), %a2 /* icache */
515 move.l #(DCACHE_STATUS), %a3 /* dcache */
516 move.l %d0, (%a1)
517 move.l %d0, (%a2)
518 move.l %d0, (%a3)
519
520 /* invalidate and disable cache */
521 move.l #0x01004100, %d0 /* Invalidate cache cmd */
522 movec %d0, %CACR /* Invalidate cache */
523 move.l #0, %d0
524 movec %d0, %ACR0
525 movec %d0, %ACR1
526 movec %d0, %ACR2
527 movec %d0, %ACR3
528
529 /* Must disable global address */
530 move.l #0xFC008000, %a1
531 move.l #(CONFIG_SYS_CS0_BASE), (%a1)
532 move.l #0xFC008008, %a1
533 move.l #(CONFIG_SYS_CS0_CTRL), (%a1)
534 move.l #0xFC008004, %a1
535 move.l #(CONFIG_SYS_CS0_MASK), (%a1)
536
537 /* NAND port configuration */
538 move.l #0xEC094048, %a1
539 move.b #0xFD, (%a1)+
540 move.b #0x5F, (%a1)+
541 move.b #0x04, (%a1)+
542
543 /* reset nand */
544 move.l #0xFC0FFF38, %a1 /* isr */
545 move.l #0x000e0000, (%a1)
546 move.l #0xFC0FFF08, %a2
547 move.l #0x00000000, (%a2)+ /* car */
548 move.l #0x11000000, (%a2)+ /* rar */
549 move.l #0x00000000, (%a2)+ /* rpt */
550 move.l #0x00000000, (%a2)+ /* rai */
551 move.l #0xFC0FFF2c, %a2 /* cfg */
552 move.l #0x00000000, (%a2)+ /* secsz */
553 move.l #0x000e0681, (%a2)+
554 move.l #0xFC0FFF04, %a2 /* cmd2 */
555 move.l #0xFF404001, (%a2)
556 move.l #0x000e0000, (%a1)
557
558 move.l #0x2000, %d1
559 jsr asm_delay
560
561 /* setup nand */
562 move.l #0xFC0FFF00, %a1
563 move.l #0x30700000, (%a1)+ /* cmd1 */
564 move.l #0x007EF000, (%a1)+ /* cmd2 */
565
566 move.l #0xFC0FFF2C, %a1
567 move.l #0x00000841, (%a1)+ /* secsz */
568 move.l #0x000e0681, (%a1)+ /* cfg */
569
570 move.l #100, %d4 /* 100 pages ~200KB */
571 move.l #4, %d2 /* start at 4 */
572 move.l #0xFC0FFF04, %a0 /* cmd2 */
573 move.l #0xFC0FFF0C, %a1 /* rar */
Masahiro Yamada61a43922015-12-11 12:22:25 +0900574 move.l #(CONFIG_SYS_TEXT_BASE + 0xF80), %a2 /* dst */
Alison Wang45370e12012-10-18 19:25:51 +0000575
576asm_nand_read:
577 move.l #0x11000000, %d0 /* rar */
578 or.l %d2, %d0
579 move.l %d0, (%a1)
580 add.l #1, %d2
581
582 move.l (%a0), %d0 /* cmd2 */
583 or.l #1, %d0
584 move.l %d0, (%a0)
585
586 move.l #0x200, %d1
587 jsr asm_delay
588
589asm_nand_chk_status:
590 move.l #0xFC0FFF38, %a4 /* isr */
591 move.l (%a4), %d0
592 and.l #0x40000000, %d0
593 tst.l %d0
594 beq asm_nand_chk_status
595
596 move.l #0xFC0FFF38, %a4 /* isr */
597 move.l (%a4), %d0
598 or.l #0x000E0000, %d0
599 move.l %d0, (%a4)
600
601 move.l #0x200, %d3
602 move.l #0xFC0FC000, %a3 /* buf 1 */
603asm_nand_copy:
604 move.l (%a3)+, (%a2)+
605 subq.l #1, %d3
606 bgt asm_nand_copy
607
608 subq.l #1, %d4
609 bgt asm_nand_read
610
611 /* jump to memory and execute */
Masahiro Yamada61a43922015-12-11 12:22:25 +0900612 move.l #(CONFIG_SYS_TEXT_BASE + 0x400), %a0
Alison Wang45370e12012-10-18 19:25:51 +0000613 jmp (%a0)
614
615#endif /* CONFIG_SYS_NAND_BOOT */
TsiChung Liew709b3842009-06-11 15:39:57 +0000616
617asm_delay:
618 nop
619 subq.l #1, %d1
620 bne asm_delay
621 rts
Alison Wang45370e12012-10-18 19:25:51 +0000622#endif /* CONFIG_CF_SBF || CONFIG_NAND_U_BOOT */
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500623
624 .text
TsiChung Liew9f751552008-07-23 20:38:53 -0500625 . = 0x400
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500626 .globl _start
627_start:
Alison Wang45370e12012-10-18 19:25:51 +0000628#if !defined(CONFIG_SERIAL_BOOT)
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500629 nop
630 nop
631 move.w #0x2700,%sr /* Mask off Interrupt */
632
633 /* Set vector base register at the beginning of the Flash */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200634 move.l #CONFIG_SYS_FLASH_BASE, %d0
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500635 movec %d0, %VBR
636
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200637 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
TsiChungLiew225a24b2007-11-07 18:00:54 -0600638 movec %d0, %RAMBAR1
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500639
640 /* initialize general use internal ram */
641 move.l #0, %d0
TsiChung Liewdd9f0542010-03-11 22:12:53 -0600642 move.l #(ICACHE_STATUS), %a1 /* icache */
643 move.l #(DCACHE_STATUS), %a2 /* dcache */
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500644 move.l %d0, (%a1)
645 move.l %d0, (%a2)
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500646
647 /* invalidate and disable cache */
TsiChung Liewdd9f0542010-03-11 22:12:53 -0600648 move.l #(CONFIG_SYS_ICACHE_INV + CONFIG_SYS_DCACHE_INV), %d0
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500649 movec %d0, %CACR /* Invalidate cache */
650 move.l #0, %d0
651 movec %d0, %ACR0
652 movec %d0, %ACR1
653 movec %d0, %ACR2
654 movec %d0, %ACR3
Alison Wang45370e12012-10-18 19:25:51 +0000655#else
656 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
657 movec %d0, %RAMBAR1
658#endif
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500659
angelo@sysam.it5044c9c2016-04-27 21:50:44 +0200660 /* put relocation table address to a5 */
661 move.l #__got_start, %a5
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500662
angelo@sysam.it5044c9c2016-04-27 21:50:44 +0200663 /* setup stack initially on top of internal static ram */
664 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp
665
666 /*
667 * if configured, malloc_f arena will be reserved first,
668 * then (and always) gd struct space will be reserved
669 */
670 move.l %sp, -(%sp)
671 move.l #board_init_f_alloc_reserve, %a1
672 jsr (%a1)
673
674 /* update stack and frame-pointers */
675 move.l %d0, %sp
676 move.l %sp, %fp
677
678 /* initialize reserved area */
679 move.l %d0, -(%sp)
680 move.l #board_init_f_init_reserve, %a1
681 jsr (%a1)
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500682
angelo@sysam.it55ac54c2016-04-12 00:30:59 +0200683 /* run low-level CPU init code (from flash) */
684 move.l #cpu_init_f, %a1
685 jsr (%a1)
686 /* run low-level board init code (from flash) */
angelo@sysam.it5044c9c2016-04-27 21:50:44 +0200687 clr.l %sp@-
angelo@sysam.it55ac54c2016-04-12 00:30:59 +0200688 move.l #board_init_f, %a1
689 jsr (%a1)
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500690
691 /* board_init_f() does not return */
692
693/*------------------------------------------------------------------------------*/
694
695/*
696 * void relocate_code (addr_sp, gd, addr_moni)
697 *
698 * This "function" does not return, instead it continues in RAM
699 * after relocating the monitor code.
700 *
701 * r3 = dest
702 * r4 = src
703 * r5 = length in bytes
704 * r6 = cachelinesize
705 */
706 .globl relocate_code
707relocate_code:
708 link.w %a6,#0
709 move.l 8(%a6), %sp /* set new stack pointer */
710
711 move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
712 move.l 16(%a6), %a0 /* Save copy of Destination Address */
713
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200714 move.l #CONFIG_SYS_MONITOR_BASE, %a1
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500715 move.l #__init_end, %a2
716 move.l %a0, %a3
717
718 /* copy the code to RAM */
7191:
720 move.l (%a1)+, (%a3)+
721 cmp.l %a1,%a2
722 bgt.s 1b
723
724/*
725 * We are done. Do not return, instead branch to second part of board
726 * initialization, now running from RAM.
727 */
728 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200729 add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500730 jmp (%a1)
731
732in_ram:
733
734clear_bss:
735 /*
736 * Now clear BSS segment
737 */
738 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200739 add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500740 move.l %a0, %d1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200741 add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
TsiChungLiew8ae158c2007-08-16 15:05:11 -05007426:
743 clr.l (%a1)+
744 cmp.l %a1,%d1
745 bgt.s 6b
746
747 /*
748 * fix got table in RAM
749 */
750 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200751 add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500752 move.l %a1,%a5 /* * fix got pointer register a5 */
753
754 move.l %a0, %a2
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200755 add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500756
7577:
758 move.l (%a1),%d1
759 sub.l #_start,%d1
760 add.l %a0,%d1
761 move.l %d1,(%a1)+
762 cmp.l %a2, %a1
763 bne 7b
764
765 /* calculate relative jump to board_init_r in ram */
766 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200767 add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500768
769 /* set parameters for board_init_r */
770 move.l %a0,-(%sp) /* dest_addr */
771 move.l %d0,-(%sp) /* gd */
772 jsr (%a1)
773
774/*------------------------------------------------------------------------------*/
775/* exception code */
776 .globl _fault
777_fault:
TsiChung Liew3b1e8ac2008-06-18 19:12:13 -0500778 bra _fault
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500779 .globl _exc_handler
780
781_exc_handler:
782 SAVE_ALL
783 movel %sp,%sp@-
784 bsr exc_handler
785 addql #4,%sp
786 RESTORE_ALL
787
788 .globl _int_handler
789_int_handler:
790 SAVE_ALL
791 movel %sp,%sp@-
792 bsr int_handler
793 addql #4,%sp
794 RESTORE_ALL
795
796/*------------------------------------------------------------------------------*/
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500797
798 .globl version_string
799version_string:
Andreas Bießmann09c2e902011-07-18 20:24:04 +0200800 .ascii U_BOOT_VERSION_STRING, "\0"
TsiChung Liew9b464322008-03-28 08:47:45 -0500801 .align 4