blob: e68cf9b6db1856d8efaa8c0921e357ad785386cb [file] [log] [blame]
wdenk0442ed82002-11-03 10:24:00 +00001/*
2 * Copyright (C) 1998 Dan Malek <dmalek@jlc.net>
3 * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
4 * Copyright (C) 2000,2001,2002 Wolfgang Denk <wd@denx.de>
Stefan Roesef6c7b762007-03-24 15:45:34 +01005 * Copyright (C) 2007 Stefan Roese <sr@denx.de>, DENX Software Engineering
Grant Ericksonb6933412008-05-22 14:44:14 -07006 * Copyright (c) 2008 Nuovation System Designs, LLC
7 * Grant Erickson <gerickson@nuovations.com>
wdenk0442ed82002-11-03 10:24:00 +00008 *
9 * See file CREDITS for list of people who contributed to this
10 * project.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307 USA
26 */
Wolfgang Denk09675ef2007-06-20 18:14:24 +020027/*------------------------------------------------------------------------------+
28 *
29 * This source code has been made available to you by IBM on an AS-IS
30 * basis. Anyone receiving this source is licensed under IBM
31 * copyrights to use it in any way he or she deems fit, including
32 * copying it, modifying it, compiling it, and redistributing it either
33 * with or without modifications. No license under IBM patents or
34 * patent applications is to be implied by the copyright license.
35 *
36 * Any user of this software should understand that IBM cannot provide
37 * technical support for this software and will not be responsible for
38 * any consequences resulting from the use of this software.
39 *
40 * Any person who transfers this source code or any derivative work
41 * must include the IBM copyright notice, this paragraph, and the
42 * preceding two paragraphs in the transferred software.
43 *
44 * COPYRIGHT I B M CORPORATION 1995
45 * LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
46 *-------------------------------------------------------------------------------
47 */
wdenk0442ed82002-11-03 10:24:00 +000048
Wolfgang Denk0ee70772005-09-23 11:05:55 +020049/* U-Boot - Startup Code for AMCC 4xx PowerPC based Embedded Boards
wdenk0442ed82002-11-03 10:24:00 +000050 *
51 *
52 * The processor starts at 0xfffffffc and the code is executed
53 * from flash/rom.
54 * in memory, but as long we don't jump around before relocating.
55 * board_init lies at a quite high address and when the cpu has
56 * jumped there, everything is ok.
57 * This works because the cpu gives the FLASH (CS0) the whole
58 * address space at startup, and board_init lies as a echo of
59 * the flash somewhere up there in the memorymap.
60 *
61 * board_init will change CS0 to be positioned at the correct
62 * address and (s)dram will be positioned at address 0
63 */
64#include <config.h>
wdenk0442ed82002-11-03 10:24:00 +000065#include <ppc4xx.h>
66#include <version.h>
67
68#define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
69
70#include <ppc_asm.tmpl>
71#include <ppc_defs.h>
72
73#include <asm/cache.h>
74#include <asm/mmu.h>
Dave Mitchell3c3734172008-11-20 14:00:49 -060075#include <asm/ppc4xx-isram.h>
wdenk0442ed82002-11-03 10:24:00 +000076
77#ifndef CONFIG_IDENT_STRING
78#define CONFIG_IDENT_STRING ""
79#endif
80
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020081#ifdef CONFIG_SYS_INIT_DCACHE_CS
82# if (CONFIG_SYS_INIT_DCACHE_CS == 0)
wdenk0442ed82002-11-03 10:24:00 +000083# define PBxAP pb0ap
84# define PBxCR pb0cr
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020085# if (defined(CONFIG_SYS_EBC_PB0AP) && defined(CONFIG_SYS_EBC_PB0CR))
86# define PBxAP_VAL CONFIG_SYS_EBC_PB0AP
87# define PBxCR_VAL CONFIG_SYS_EBC_PB0CR
Grant Ericksonb6933412008-05-22 14:44:14 -070088# endif
wdenk0442ed82002-11-03 10:24:00 +000089# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020090# if (CONFIG_SYS_INIT_DCACHE_CS == 1)
wdenk0442ed82002-11-03 10:24:00 +000091# define PBxAP pb1ap
92# define PBxCR pb1cr
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020093# if (defined(CONFIG_SYS_EBC_PB1AP) && defined(CONFIG_SYS_EBC_PB1CR))
94# define PBxAP_VAL CONFIG_SYS_EBC_PB1AP
95# define PBxCR_VAL CONFIG_SYS_EBC_PB1CR
Grant Ericksonb6933412008-05-22 14:44:14 -070096# endif
wdenk0442ed82002-11-03 10:24:00 +000097# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020098# if (CONFIG_SYS_INIT_DCACHE_CS == 2)
wdenk0442ed82002-11-03 10:24:00 +000099# define PBxAP pb2ap
100# define PBxCR pb2cr
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200101# if (defined(CONFIG_SYS_EBC_PB2AP) && defined(CONFIG_SYS_EBC_PB2CR))
102# define PBxAP_VAL CONFIG_SYS_EBC_PB2AP
103# define PBxCR_VAL CONFIG_SYS_EBC_PB2CR
Grant Ericksonb6933412008-05-22 14:44:14 -0700104# endif
wdenk0442ed82002-11-03 10:24:00 +0000105# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200106# if (CONFIG_SYS_INIT_DCACHE_CS == 3)
wdenk0442ed82002-11-03 10:24:00 +0000107# define PBxAP pb3ap
108# define PBxCR pb3cr
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200109# if (defined(CONFIG_SYS_EBC_PB3AP) && defined(CONFIG_SYS_EBC_PB3CR))
110# define PBxAP_VAL CONFIG_SYS_EBC_PB3AP
111# define PBxCR_VAL CONFIG_SYS_EBC_PB3CR
Grant Ericksonb6933412008-05-22 14:44:14 -0700112# endif
wdenk0442ed82002-11-03 10:24:00 +0000113# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200114# if (CONFIG_SYS_INIT_DCACHE_CS == 4)
wdenk0442ed82002-11-03 10:24:00 +0000115# define PBxAP pb4ap
116# define PBxCR pb4cr
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200117# if (defined(CONFIG_SYS_EBC_PB4AP) && defined(CONFIG_SYS_EBC_PB4CR))
118# define PBxAP_VAL CONFIG_SYS_EBC_PB4AP
119# define PBxCR_VAL CONFIG_SYS_EBC_PB4CR
Grant Ericksonb6933412008-05-22 14:44:14 -0700120# endif
wdenk0442ed82002-11-03 10:24:00 +0000121# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200122# if (CONFIG_SYS_INIT_DCACHE_CS == 5)
wdenk0442ed82002-11-03 10:24:00 +0000123# define PBxAP pb5ap
124# define PBxCR pb5cr
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200125# if (defined(CONFIG_SYS_EBC_PB5AP) && defined(CONFIG_SYS_EBC_PB5CR))
126# define PBxAP_VAL CONFIG_SYS_EBC_PB5AP
127# define PBxCR_VAL CONFIG_SYS_EBC_PB5CR
Grant Ericksonb6933412008-05-22 14:44:14 -0700128# endif
wdenk0442ed82002-11-03 10:24:00 +0000129# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200130# if (CONFIG_SYS_INIT_DCACHE_CS == 6)
wdenk0442ed82002-11-03 10:24:00 +0000131# define PBxAP pb6ap
132# define PBxCR pb6cr
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200133# if (defined(CONFIG_SYS_EBC_PB6AP) && defined(CONFIG_SYS_EBC_PB6CR))
134# define PBxAP_VAL CONFIG_SYS_EBC_PB6AP
135# define PBxCR_VAL CONFIG_SYS_EBC_PB6CR
Grant Ericksonb6933412008-05-22 14:44:14 -0700136# endif
wdenk0442ed82002-11-03 10:24:00 +0000137# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200138# if (CONFIG_SYS_INIT_DCACHE_CS == 7)
wdenk0442ed82002-11-03 10:24:00 +0000139# define PBxAP pb7ap
140# define PBxCR pb7cr
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200141# if (defined(CONFIG_SYS_EBC_PB7AP) && defined(CONFIG_SYS_EBC_PB7CR))
142# define PBxAP_VAL CONFIG_SYS_EBC_PB7AP
143# define PBxCR_VAL CONFIG_SYS_EBC_PB7CR
Grant Ericksonb6933412008-05-22 14:44:14 -0700144# endif
145# endif
146# ifndef PBxAP_VAL
147# define PBxAP_VAL 0
148# endif
149# ifndef PBxCR_VAL
150# define PBxCR_VAL 0
151# endif
152/*
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200153 * Memory Bank x (nothingness) initialization CONFIG_SYS_INIT_RAM_ADDR + 64 MiB
Grant Ericksonb6933412008-05-22 14:44:14 -0700154 * used as temporary stack pointer for the primordial stack
155 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200156# ifndef CONFIG_SYS_INIT_DCACHE_PBxAR
157# define CONFIG_SYS_INIT_DCACHE_PBxAR (EBC_BXAP_BME_DISABLED | \
Grant Ericksonb6933412008-05-22 14:44:14 -0700158 EBC_BXAP_TWT_ENCODE(7) | \
159 EBC_BXAP_BCE_DISABLE | \
160 EBC_BXAP_BCT_2TRANS | \
161 EBC_BXAP_CSN_ENCODE(0) | \
162 EBC_BXAP_OEN_ENCODE(0) | \
163 EBC_BXAP_WBN_ENCODE(0) | \
164 EBC_BXAP_WBF_ENCODE(0) | \
165 EBC_BXAP_TH_ENCODE(2) | \
166 EBC_BXAP_RE_DISABLED | \
167 EBC_BXAP_SOR_NONDELAYED | \
168 EBC_BXAP_BEM_WRITEONLY | \
169 EBC_BXAP_PEN_DISABLED)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200170# endif /* CONFIG_SYS_INIT_DCACHE_PBxAR */
171# ifndef CONFIG_SYS_INIT_DCACHE_PBxCR
172# define CONFIG_SYS_INIT_DCACHE_PBxCR (EBC_BXCR_BAS_ENCODE(CONFIG_SYS_INIT_RAM_ADDR) | \
Grant Ericksonb6933412008-05-22 14:44:14 -0700173 EBC_BXCR_BS_64MB | \
174 EBC_BXCR_BU_RW | \
175 EBC_BXCR_BW_16BIT)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200176# endif /* CONFIG_SYS_INIT_DCACHE_PBxCR */
177# ifndef CONFIG_SYS_INIT_RAM_PATTERN
178# define CONFIG_SYS_INIT_RAM_PATTERN 0xDEADDEAD
wdenk0442ed82002-11-03 10:24:00 +0000179# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200180#endif /* CONFIG_SYS_INIT_DCACHE_CS */
wdenk0442ed82002-11-03 10:24:00 +0000181
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200182#if (defined(CONFIG_SYS_INIT_RAM_DCACHE) && (CONFIG_SYS_INIT_RAM_END > (4 << 10)))
183#error Only 4k of init-ram is supported - please adjust CONFIG_SYS_INIT_RAM_END!
Stefan Roese0fb8ab92008-01-30 14:48:28 +0100184#endif
185
Grant Ericksonb6933412008-05-22 14:44:14 -0700186/*
187 * Unless otherwise overriden, enable two 128MB cachable instruction regions
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200188 * at CONFIG_SYS_SDRAM_BASE and another 128MB cacheable instruction region covering
189 * NOR flash at CONFIG_SYS_FLASH_BASE. Disable all cacheable data regions.
Grant Ericksonb6933412008-05-22 14:44:14 -0700190 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200191#if !defined(CONFIG_SYS_FLASH_BASE)
Stefan Roese7d72e022008-06-02 14:35:44 +0200192/* If not already defined, set it to the "last" 128MByte region */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200193# define CONFIG_SYS_FLASH_BASE 0xf8000000
Stefan Roese7d72e022008-06-02 14:35:44 +0200194#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200195#if !defined(CONFIG_SYS_ICACHE_SACR_VALUE)
196# define CONFIG_SYS_ICACHE_SACR_VALUE \
197 (PPC_128MB_SACR_VALUE(CONFIG_SYS_SDRAM_BASE + ( 0 << 20)) | \
198 PPC_128MB_SACR_VALUE(CONFIG_SYS_SDRAM_BASE + (128 << 20)) | \
199 PPC_128MB_SACR_VALUE(CONFIG_SYS_FLASH_BASE))
200#endif /* !defined(CONFIG_SYS_ICACHE_SACR_VALUE) */
Grant Ericksonb6933412008-05-22 14:44:14 -0700201
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200202#if !defined(CONFIG_SYS_DCACHE_SACR_VALUE)
203# define CONFIG_SYS_DCACHE_SACR_VALUE \
Grant Ericksonb6933412008-05-22 14:44:14 -0700204 (0x00000000)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200205#endif /* !defined(CONFIG_SYS_DCACHE_SACR_VALUE) */
Grant Ericksonb6933412008-05-22 14:44:14 -0700206
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200207#define function_prolog(func_name) .text; \
Stefan Roese42743512007-06-01 15:27:11 +0200208 .align 2; \
209 .globl func_name; \
210 func_name:
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200211#define function_epilog(func_name) .type func_name,@function; \
Stefan Roese42743512007-06-01 15:27:11 +0200212 .size func_name,.-func_name
213
wdenk0442ed82002-11-03 10:24:00 +0000214/* We don't want the MMU yet.
215*/
216#undef MSR_KERNEL
217#define MSR_KERNEL ( MSR_ME ) /* Machine Check */
218
219
220 .extern ext_bus_cntlr_init
Stefan Roese42fbddd2006-09-07 11:51:23 +0200221#ifdef CONFIG_NAND_U_BOOT
222 .extern reconfig_tlb0
223#endif
wdenk0442ed82002-11-03 10:24:00 +0000224
225/*
226 * Set up GOT: Global Offset Table
227 *
228 * Use r14 to access the GOT
229 */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200230#if !defined(CONFIG_NAND_SPL)
wdenk0442ed82002-11-03 10:24:00 +0000231 START_GOT
232 GOT_ENTRY(_GOT2_TABLE_)
233 GOT_ENTRY(_FIXUP_TABLE_)
234
235 GOT_ENTRY(_start)
236 GOT_ENTRY(_start_of_vectors)
237 GOT_ENTRY(_end_of_vectors)
238 GOT_ENTRY(transfer_to_handler)
239
wdenkb9a83a92003-05-30 12:48:29 +0000240 GOT_ENTRY(__init_end)
wdenk0442ed82002-11-03 10:24:00 +0000241 GOT_ENTRY(_end)
wdenkbf2f8c92003-05-22 22:52:13 +0000242 GOT_ENTRY(__bss_start)
wdenk0442ed82002-11-03 10:24:00 +0000243 END_GOT
Stefan Roese42fbddd2006-09-07 11:51:23 +0200244#endif /* CONFIG_NAND_SPL */
245
246#if defined(CONFIG_NAND_U_BOOT) && !defined(CONFIG_NAND_SPL)
247 /*
248 * NAND U-Boot image is started from offset 0
249 */
250 .text
Stefan Roese23d8d342007-06-06 11:42:13 +0200251#if defined(CONFIG_440)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200252 bl reconfig_tlb0
Stefan Roese23d8d342007-06-06 11:42:13 +0200253#endif
Stefan Roese42fbddd2006-09-07 11:51:23 +0200254 GET_GOT
255 bl cpu_init_f /* run low-level CPU init code (from Flash) */
256 bl board_init_f
257#endif
wdenk0442ed82002-11-03 10:24:00 +0000258
259/*
260 * 440 Startup -- on reset only the top 4k of the effective
261 * address space is mapped in by an entry in the instruction
262 * and data shadow TLB. The .bootpg section is located in the
263 * top 4k & does only what's necessary to map in the the rest
264 * of the boot rom. Once the boot rom is mapped in we can
265 * proceed with normal startup.
266 *
267 * NOTE: CS0 only covers the top 2MB of the effective address
268 * space after reset.
269 */
270
271#if defined(CONFIG_440)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200272#if !defined(CONFIG_NAND_SPL)
wdenk0442ed82002-11-03 10:24:00 +0000273 .section .bootpg,"ax"
Stefan Roese42fbddd2006-09-07 11:51:23 +0200274#endif
wdenk0442ed82002-11-03 10:24:00 +0000275 .globl _start_440
276
277/**************************************************************************/
278_start_440:
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200279 /*--------------------------------------------------------------------+
280 | 440EPX BUP Change - Hardware team request
281 +--------------------------------------------------------------------*/
Stefan Roese42fbddd2006-09-07 11:51:23 +0200282#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
283 sync
284 nop
285 nop
286#endif
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200287 /*----------------------------------------------------------------+
288 | Core bug fix. Clear the esr
289 +-----------------------------------------------------------------*/
Marian Balakowiczbe9463b2006-07-06 21:17:24 +0200290 li r0,0
Wolfgang Denkba940932006-07-19 13:50:38 +0200291 mtspr esr,r0
wdenk0442ed82002-11-03 10:24:00 +0000292 /*----------------------------------------------------------------*/
293 /* Clear and set up some registers. */
294 /*----------------------------------------------------------------*/
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200295 iccci r0,r0 /* NOTE: operands not used for 440 */
296 dccci r0,r0 /* NOTE: operands not used for 440 */
wdenk0442ed82002-11-03 10:24:00 +0000297 sync
298 li r0,0
299 mtspr srr0,r0
300 mtspr srr1,r0
301 mtspr csrr0,r0
302 mtspr csrr1,r0
Stefan Roese42fbddd2006-09-07 11:51:23 +0200303 /* NOTE: 440GX adds machine check status regs */
304#if defined(CONFIG_440) && !defined(CONFIG_440GP)
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200305 mtspr mcsrr0,r0
306 mtspr mcsrr1,r0
Stefan Roese42fbddd2006-09-07 11:51:23 +0200307 mfspr r1,mcsr
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200308 mtspr mcsr,r1
wdenk544e9732004-02-06 23:19:44 +0000309#endif
Stefan Roese0100cc12006-11-22 13:20:50 +0100310
311 /*----------------------------------------------------------------*/
312 /* CCR0 init */
313 /*----------------------------------------------------------------*/
314 /* Disable store gathering & broadcast, guarantee inst/data
315 * cache block touch, force load/store alignment
316 * (see errata 1.12: 440_33)
317 */
318 lis r1,0x0030 /* store gathering & broadcast disable */
319 ori r1,r1,0x6000 /* cache touch */
320 mtspr ccr0,r1
321
wdenk0442ed82002-11-03 10:24:00 +0000322 /*----------------------------------------------------------------*/
323 /* Initialize debug */
324 /*----------------------------------------------------------------*/
Stefan Roese42fbddd2006-09-07 11:51:23 +0200325 mfspr r1,dbcr0
326 andis. r1, r1, 0x8000 /* test DBCR0[EDM] bit */
327 bne skip_debug_init /* if set, don't clear debug register */
wdenk0442ed82002-11-03 10:24:00 +0000328 mtspr dbcr0,r0
329 mtspr dbcr1,r0
330 mtspr dbcr2,r0
331 mtspr iac1,r0
332 mtspr iac2,r0
333 mtspr iac3,r0
334 mtspr dac1,r0
335 mtspr dac2,r0
336 mtspr dvc1,r0
337 mtspr dvc2,r0
338
339 mfspr r1,dbsr
340 mtspr dbsr,r1 /* Clear all valid bits */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200341skip_debug_init:
wdenk0442ed82002-11-03 10:24:00 +0000342
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200343#if defined (CONFIG_440SPE)
344 /*----------------------------------------------------------------+
345 | Initialize Core Configuration Reg1.
346 | a. ICDPEI: Record even parity. Normal operation.
347 | b. ICTPEI: Record even parity. Normal operation.
348 | c. DCTPEI: Record even parity. Normal operation.
349 | d. DCDPEI: Record even parity. Normal operation.
350 | e. DCUPEI: Record even parity. Normal operation.
351 | f. DCMPEI: Record even parity. Normal operation.
352 | g. FCOM: Normal operation
353 | h. MMUPEI: Record even parity. Normal operation.
354 | i. FFF: Flush only as much data as necessary.
Marian Balakowiczbe9463b2006-07-06 21:17:24 +0200355 | j. TCS: Timebase increments from CPU clock.
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200356 +-----------------------------------------------------------------*/
Marian Balakowiczbe9463b2006-07-06 21:17:24 +0200357 li r0,0
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200358 mtspr ccr1, r0
359
360 /*----------------------------------------------------------------+
361 | Reset the timebase.
362 | The previous write to CCR1 sets the timebase source.
363 +-----------------------------------------------------------------*/
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200364 mtspr tbl, r0
365 mtspr tbu, r0
366#endif
367
wdenk0442ed82002-11-03 10:24:00 +0000368 /*----------------------------------------------------------------*/
369 /* Setup interrupt vectors */
370 /*----------------------------------------------------------------*/
371 mtspr ivpr,r0 /* Vectors start at 0x0000_0000 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200372 li r1,0x0100
wdenk0442ed82002-11-03 10:24:00 +0000373 mtspr ivor0,r1 /* Critical input */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200374 li r1,0x0200
wdenk0442ed82002-11-03 10:24:00 +0000375 mtspr ivor1,r1 /* Machine check */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200376 li r1,0x0300
wdenk0442ed82002-11-03 10:24:00 +0000377 mtspr ivor2,r1 /* Data storage */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200378 li r1,0x0400
wdenk0442ed82002-11-03 10:24:00 +0000379 mtspr ivor3,r1 /* Instruction storage */
380 li r1,0x0500
381 mtspr ivor4,r1 /* External interrupt */
382 li r1,0x0600
383 mtspr ivor5,r1 /* Alignment */
384 li r1,0x0700
385 mtspr ivor6,r1 /* Program check */
386 li r1,0x0800
387 mtspr ivor7,r1 /* Floating point unavailable */
388 li r1,0x0c00
389 mtspr ivor8,r1 /* System call */
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200390 li r1,0x0a00
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200391 mtspr ivor9,r1 /* Auxiliary Processor unavailable */
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200392 li r1,0x0900
393 mtspr ivor10,r1 /* Decrementer */
wdenk0442ed82002-11-03 10:24:00 +0000394 li r1,0x1300
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200395 mtspr ivor13,r1 /* Data TLB error */
396 li r1,0x1400
wdenk0442ed82002-11-03 10:24:00 +0000397 mtspr ivor14,r1 /* Instr TLB error */
398 li r1,0x2000
399 mtspr ivor15,r1 /* Debug */
400
401 /*----------------------------------------------------------------*/
402 /* Configure cache regions */
403 /*----------------------------------------------------------------*/
404 mtspr inv0,r0
405 mtspr inv1,r0
406 mtspr inv2,r0
407 mtspr inv3,r0
408 mtspr dnv0,r0
409 mtspr dnv1,r0
410 mtspr dnv2,r0
411 mtspr dnv3,r0
412 mtspr itv0,r0
413 mtspr itv1,r0
414 mtspr itv2,r0
415 mtspr itv3,r0
416 mtspr dtv0,r0
417 mtspr dtv1,r0
418 mtspr dtv2,r0
419 mtspr dtv3,r0
420
421 /*----------------------------------------------------------------*/
422 /* Cache victim limits */
423 /*----------------------------------------------------------------*/
424 /* floors 0, ceiling max to use the entire cache -- nothing locked
425 */
426 lis r1,0x0001
427 ori r1,r1,0xf800
428 mtspr ivlim,r1
429 mtspr dvlim,r1
430
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200431 /*----------------------------------------------------------------+
432 |Initialize MMUCR[STID] = 0.
433 +-----------------------------------------------------------------*/
434 mfspr r0,mmucr
435 addis r1,0,0xFFFF
436 ori r1,r1,0xFF00
437 and r0,r0,r1
438 mtspr mmucr,r0
439
wdenk0442ed82002-11-03 10:24:00 +0000440 /*----------------------------------------------------------------*/
441 /* Clear all TLB entries -- TID = 0, TS = 0 */
442 /*----------------------------------------------------------------*/
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200443 addis r0,0,0x0000
wdenk0442ed82002-11-03 10:24:00 +0000444 li r1,0x003f /* 64 TLB entries */
445 mtctr r1
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200446rsttlb: tlbwe r0,r1,0x0000 /* Invalidate all entries (V=0)*/
447 tlbwe r0,r1,0x0001
448 tlbwe r0,r1,0x0002
wdenk0442ed82002-11-03 10:24:00 +0000449 subi r1,r1,0x0001
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200450 bdnz rsttlb
wdenk0442ed82002-11-03 10:24:00 +0000451
452 /*----------------------------------------------------------------*/
453 /* TLB entry setup -- step thru tlbtab */
454 /*----------------------------------------------------------------*/
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200455#if defined(CONFIG_440SPE)
456 /*----------------------------------------------------------------*/
457 /* We have different TLB tables for revA and rev B of 440SPe */
458 /*----------------------------------------------------------------*/
459 mfspr r1, PVR
460 lis r0,0x5342
461 ori r0,r0,0x1891
462 cmpw r7,r1,r0
463 bne r7,..revA
464 bl tlbtabB
465 b ..goon
466..revA:
467 bl tlbtabA
468..goon:
469#else
wdenk0442ed82002-11-03 10:24:00 +0000470 bl tlbtab /* Get tlbtab pointer */
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200471#endif
wdenk0442ed82002-11-03 10:24:00 +0000472 mr r5,r0
473 li r1,0x003f /* 64 TLB entries max */
474 mtctr r1
475 li r4,0 /* TLB # */
476
477 addi r5,r5,-4
4781: lwzu r0,4(r5)
479 cmpwi r0,0
480 beq 2f /* 0 marks end */
481 lwzu r1,4(r5)
482 lwzu r2,4(r5)
483 tlbwe r0,r4,0 /* TLB Word 0 */
484 tlbwe r1,r4,1 /* TLB Word 1 */
485 tlbwe r2,r4,2 /* TLB Word 2 */
486 addi r4,r4,1 /* Next TLB */
487 bdnz 1b
488
489 /*----------------------------------------------------------------*/
490 /* Continue from 'normal' start */
491 /*----------------------------------------------------------------*/
Stefan Roese42fbddd2006-09-07 11:51:23 +02004922:
Stefan Roese42fbddd2006-09-07 11:51:23 +0200493 bl 3f
wdenk0442ed82002-11-03 10:24:00 +0000494 b _start
495
4963: li r0,0
497 mtspr srr1,r0 /* Keep things disabled for now */
498 mflr r1
499 mtspr srr0,r1
500 rfi
stroese434979e2003-05-23 11:18:02 +0000501#endif /* CONFIG_440 */
wdenk0442ed82002-11-03 10:24:00 +0000502
503/*
504 * r3 - 1st arg to board_init(): IMMP pointer
505 * r4 - 2nd arg to board_init(): boot flag
506 */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200507#ifndef CONFIG_NAND_SPL
wdenk0442ed82002-11-03 10:24:00 +0000508 .text
509 .long 0x27051956 /* U-Boot Magic Number */
510 .globl version_string
511version_string:
512 .ascii U_BOOT_VERSION
513 .ascii " (", __DATE__, " - ", __TIME__, ")"
514 .ascii CONFIG_IDENT_STRING, "\0"
515
wdenk0442ed82002-11-03 10:24:00 +0000516 . = EXC_OFF_SYS_RESET
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200517 .globl _start_of_vectors
518_start_of_vectors:
519
520/* Critical input. */
521 CRIT_EXCEPTION(0x100, CritcalInput, UnknownException)
522
523#ifdef CONFIG_440
524/* Machine check */
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200525 MCK_EXCEPTION(0x200, MachineCheck, MachineCheckException)
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200526#else
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200527 CRIT_EXCEPTION(0x200, MachineCheck, MachineCheckException)
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200528#endif /* CONFIG_440 */
529
530/* Data Storage exception. */
531 STD_EXCEPTION(0x300, DataStorage, UnknownException)
532
533/* Instruction Storage exception. */
534 STD_EXCEPTION(0x400, InstStorage, UnknownException)
535
536/* External Interrupt exception. */
537 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
538
539/* Alignment exception. */
540 . = 0x600
541Alignment:
542 EXCEPTION_PROLOG(SRR0, SRR1)
543 mfspr r4,DAR
544 stw r4,_DAR(r21)
545 mfspr r5,DSISR
546 stw r5,_DSISR(r21)
547 addi r3,r1,STACK_FRAME_OVERHEAD
548 li r20,MSR_KERNEL
549 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
550 lwz r6,GOT(transfer_to_handler)
551 mtlr r6
552 blrl
553.L_Alignment:
554 .long AlignmentException - _start + _START_OFFSET
555 .long int_return - _start + _START_OFFSET
556
557/* Program check exception */
558 . = 0x700
559ProgramCheck:
560 EXCEPTION_PROLOG(SRR0, SRR1)
561 addi r3,r1,STACK_FRAME_OVERHEAD
562 li r20,MSR_KERNEL
563 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
564 lwz r6,GOT(transfer_to_handler)
565 mtlr r6
566 blrl
567.L_ProgramCheck:
568 .long ProgramCheckException - _start + _START_OFFSET
569 .long int_return - _start + _START_OFFSET
570
571#ifdef CONFIG_440
572 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
573 STD_EXCEPTION(0x900, Decrementer, DecrementerPITException)
574 STD_EXCEPTION(0xa00, APU, UnknownException)
Stefan Roese80d99a42007-06-19 16:42:31 +0200575#endif
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200576 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
577
578#ifdef CONFIG_440
579 STD_EXCEPTION(0x1300, DataTLBError, UnknownException)
580 STD_EXCEPTION(0x1400, InstructionTLBError, UnknownException)
581#else
582 STD_EXCEPTION(0x1000, PIT, DecrementerPITException)
583 STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
584 STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
585#endif
586 CRIT_EXCEPTION(0x2000, DebugBreakpoint, DebugException )
587
588 .globl _end_of_vectors
589_end_of_vectors:
590 . = _START_OFFSET
Stefan Roese42fbddd2006-09-07 11:51:23 +0200591#endif
wdenk0442ed82002-11-03 10:24:00 +0000592 .globl _start
593_start:
594
595/*****************************************************************************/
596#if defined(CONFIG_440)
597
598 /*----------------------------------------------------------------*/
599 /* Clear and set up some registers. */
600 /*----------------------------------------------------------------*/
601 li r0,0x0000
602 lis r1,0xffff
603 mtspr dec,r0 /* prevent dec exceptions */
604 mtspr tbl,r0 /* prevent fit & wdt exceptions */
605 mtspr tbu,r0
606 mtspr tsr,r1 /* clear all timer exception status */
607 mtspr tcr,r0 /* disable all */
608 mtspr esr,r0 /* clear exception syndrome register */
609 mtxer r0 /* clear integer exception register */
wdenk0442ed82002-11-03 10:24:00 +0000610
611 /*----------------------------------------------------------------*/
612 /* Debug setup -- some (not very good) ice's need an event*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200613 /* to establish control :-( Define CONFIG_SYS_INIT_DBCR to the dbsr */
wdenk0442ed82002-11-03 10:24:00 +0000614 /* value you need in this case 0x8cff 0000 should do the trick */
615 /*----------------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200616#if defined(CONFIG_SYS_INIT_DBCR)
wdenk0442ed82002-11-03 10:24:00 +0000617 lis r1,0xffff
618 ori r1,r1,0xffff
619 mtspr dbsr,r1 /* Clear all status bits */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200620 lis r0,CONFIG_SYS_INIT_DBCR@h
621 ori r0,r0,CONFIG_SYS_INIT_DBCR@l
wdenk0442ed82002-11-03 10:24:00 +0000622 mtspr dbcr0,r0
623 isync
624#endif
625
626 /*----------------------------------------------------------------*/
627 /* Setup the internal SRAM */
628 /*----------------------------------------------------------------*/
629 li r0,0
Stefan Roese42fbddd2006-09-07 11:51:23 +0200630
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200631#ifdef CONFIG_SYS_INIT_RAM_DCACHE
Stefan Roese326c9712005-08-01 16:41:48 +0200632 /* Clear Dcache to use as RAM */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200633 addis r3,r0,CONFIG_SYS_INIT_RAM_ADDR@h
634 ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
635 addis r4,r0,CONFIG_SYS_INIT_RAM_END@h
636 ori r4,r4,CONFIG_SYS_INIT_RAM_END@l
Stefan Roese326c9712005-08-01 16:41:48 +0200637 rlwinm. r5,r4,0,27,31
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200638 rlwinm r5,r4,27,5,31
639 beq ..d_ran
640 addi r5,r5,0x0001
Stefan Roese326c9712005-08-01 16:41:48 +0200641..d_ran:
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200642 mtctr r5
Stefan Roese326c9712005-08-01 16:41:48 +0200643..d_ag:
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200644 dcbz r0,r3
645 addi r3,r3,32
646 bdnz ..d_ag
Stefan Roesea86bde32008-01-09 10:23:16 +0100647
648 /*
649 * Lock the init-ram/stack in d-cache, so that other regions
650 * may use d-cache as well
651 * Note, that this current implementation locks exactly 4k
652 * of d-cache, so please make sure that you don't define a
653 * bigger init-ram area. Take a look at the lwmon5 440EPx
654 * implementation as a reference.
655 */
656 msync
657 isync
658 /* 8. set TFLOOR/NFLOOR to 8 (-> 8*16*32 bytes locked -> 4k) */
659 lis r1,0x0201
660 ori r1,r1,0xf808
661 mtspr dvlim,r1
662 lis r1,0x0808
663 ori r1,r1,0x0808
664 mtspr dnv0,r1
665 mtspr dnv1,r1
666 mtspr dnv2,r1
667 mtspr dnv3,r1
668 mtspr dtv0,r1
669 mtspr dtv1,r1
670 mtspr dtv2,r1
671 mtspr dtv3,r1
672 msync
673 isync
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200674#endif /* CONFIG_SYS_INIT_RAM_DCACHE */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200675
676 /* 440EP & 440GR are only 440er PPC's without internal SRAM */
677#if !defined(CONFIG_440EP) && !defined(CONFIG_440GR)
678 /* not all PPC's have internal SRAM usable as L2-cache */
Stefan Roesecc019d12008-03-11 15:05:50 +0100679#if defined(CONFIG_440GX) || \
680 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Feng Kan224bc962008-07-08 22:47:31 -0700681 defined(CONFIG_460SX)
Dave Mitchell3c3734172008-11-20 14:00:49 -0600682 mtdcr L2_CACHE_CFG,r0 /* Ensure L2 Cache is off */
Dave Mitchell5c057592008-11-20 14:09:50 -0600683#elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
684 lis r1, 0x0000
685 ori r1,r1,0x0008 /* Set L2_CACHE_CFG[RDBW]=1 */
686 mtdcr L2_CACHE_CFG,r1
wdenk544e9732004-02-06 23:19:44 +0000687#endif
wdenk0442ed82002-11-03 10:24:00 +0000688
Stefan Roese42fbddd2006-09-07 11:51:23 +0200689 lis r2,0x7fff
wdenk0442ed82002-11-03 10:24:00 +0000690 ori r2,r2,0xffff
Dave Mitchell3c3734172008-11-20 14:00:49 -0600691 mfdcr r1,ISRAM0_DPC
wdenk0442ed82002-11-03 10:24:00 +0000692 and r1,r1,r2 /* Disable parity check */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600693 mtdcr ISRAM0_DPC,r1
694 mfdcr r1,ISRAM0_PMEG
Stefan Roese42fbddd2006-09-07 11:51:23 +0200695 and r1,r1,r2 /* Disable pwr mgmt */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600696 mtdcr ISRAM0_PMEG,r1
wdenk0442ed82002-11-03 10:24:00 +0000697
698 lis r1,0x8000 /* BAS = 8000_0000 */
Stefan Roese99644742005-11-29 18:18:21 +0100699#if defined(CONFIG_440GX) || defined(CONFIG_440SP)
wdenk544e9732004-02-06 23:19:44 +0000700 ori r1,r1,0x0980 /* first 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600701 mtdcr ISRAM0_SB0CR,r1
wdenk544e9732004-02-06 23:19:44 +0000702 lis r1,0x8001
703 ori r1,r1,0x0980 /* second 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600704 mtdcr ISRAM0_SB1CR,r1
wdenk544e9732004-02-06 23:19:44 +0000705 lis r1, 0x8002
706 ori r1,r1, 0x0980 /* third 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600707 mtdcr ISRAM0_SB2CR,r1
wdenk544e9732004-02-06 23:19:44 +0000708 lis r1, 0x8003
709 ori r1,r1, 0x0980 /* fourth 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600710 mtdcr ISRAM0_SB3CR,r1
Dave Mitchell5c057592008-11-20 14:09:50 -0600711#elif defined(CONFIG_440SPE) || defined(CONFIG_460EX) || defined(CONFIG_460GT)
712 lis r1,0x0000 /* BAS = X_0000_0000 */
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200713 ori r1,r1,0x0984 /* first 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600714 mtdcr ISRAM0_SB0CR,r1
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200715 lis r1,0x0001
716 ori r1,r1,0x0984 /* second 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600717 mtdcr ISRAM0_SB1CR,r1
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200718 lis r1, 0x0002
719 ori r1,r1, 0x0984 /* third 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600720 mtdcr ISRAM0_SB2CR,r1
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200721 lis r1, 0x0003
722 ori r1,r1, 0x0984 /* fourth 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600723 mtdcr ISRAM0_SB3CR,r1
Dave Mitchell5c057592008-11-20 14:09:50 -0600724#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
725 lis r2,0x7fff
726 ori r2,r2,0xffff
727 mfdcr r1,ISRAM1_DPC
728 and r1,r1,r2 /* Disable parity check */
729 mtdcr ISRAM1_DPC,r1
730 mfdcr r1,ISRAM1_PMEG
731 and r1,r1,r2 /* Disable pwr mgmt */
732 mtdcr ISRAM1_PMEG,r1
733
734 lis r1,0x0004 /* BAS = 4_0004_0000 */
735 ori r1,r1,0x0984 /* 64k */
736 mtdcr ISRAM1_SB0CR,r1
737#endif
Feng Kan224bc962008-07-08 22:47:31 -0700738#elif defined(CONFIG_460SX)
739 lis r1,0x0000 /* BAS = 0000_0000 */
740 ori r1,r1,0x0B84 /* first 128k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600741 mtdcr ISRAM0_SB0CR,r1
Feng Kan224bc962008-07-08 22:47:31 -0700742 lis r1,0x0001
743 ori r1,r1,0x0B84 /* second 128k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600744 mtdcr ISRAM0_SB1CR,r1
Feng Kan224bc962008-07-08 22:47:31 -0700745 lis r1, 0x0002
746 ori r1,r1, 0x0B84 /* third 128k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600747 mtdcr ISRAM0_SB2CR,r1
Feng Kan224bc962008-07-08 22:47:31 -0700748 lis r1, 0x0003
749 ori r1,r1, 0x0B84 /* fourth 128k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600750 mtdcr ISRAM0_SB3CR,r1
Stefan Roese42fbddd2006-09-07 11:51:23 +0200751#elif defined(CONFIG_440GP)
wdenk0442ed82002-11-03 10:24:00 +0000752 ori r1,r1,0x0380 /* 8k rw */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600753 mtdcr ISRAM0_SB0CR,r1
754 mtdcr ISRAM0_SB1CR,r0 /* Disable bank 1 */
Stefan Roese326c9712005-08-01 16:41:48 +0200755#endif
Stefan Roese42fbddd2006-09-07 11:51:23 +0200756#endif /* #if !defined(CONFIG_440EP) && !defined(CONFIG_440GR) */
wdenk0442ed82002-11-03 10:24:00 +0000757
758 /*----------------------------------------------------------------*/
759 /* Setup the stack in internal SRAM */
760 /*----------------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200761 lis r1,CONFIG_SYS_INIT_RAM_ADDR@h
762 ori r1,r1,CONFIG_SYS_INIT_SP_OFFSET@l
wdenk0442ed82002-11-03 10:24:00 +0000763 li r0,0
764 stwu r0,-4(r1)
765 stwu r0,-4(r1) /* Terminate call chain */
766
767 stwu r1,-8(r1) /* Save back chain and move SP */
768 lis r0,RESET_VECTOR@h /* Address of reset vector */
769 ori r0,r0, RESET_VECTOR@l
770 stwu r1,-8(r1) /* Save back chain and move SP */
771 stw r0,+12(r1) /* Save return addr (underflow vect) */
772
Stefan Roese42fbddd2006-09-07 11:51:23 +0200773#ifdef CONFIG_NAND_SPL
Stefan Roese7d72e022008-06-02 14:35:44 +0200774 bl nand_boot_common /* will not return */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200775#else
wdenk0442ed82002-11-03 10:24:00 +0000776 GET_GOT
Stefan Roesec443fe92005-11-22 13:20:42 +0100777
778 bl cpu_init_f /* run low-level CPU init code (from Flash) */
wdenk0442ed82002-11-03 10:24:00 +0000779 bl board_init_f
Stefan Roese42fbddd2006-09-07 11:51:23 +0200780#endif
wdenk0442ed82002-11-03 10:24:00 +0000781
782#endif /* CONFIG_440 */
783
784/*****************************************************************************/
785#ifdef CONFIG_IOP480
786 /*----------------------------------------------------------------------- */
787 /* Set up some machine state registers. */
788 /*----------------------------------------------------------------------- */
789 addi r0,r0,0x0000 /* initialize r0 to zero */
790 mtspr esr,r0 /* clear Exception Syndrome Reg */
791 mttcr r0 /* timer control register */
792 mtexier r0 /* disable all interrupts */
wdenk0442ed82002-11-03 10:24:00 +0000793 addis r4,r0,0xFFFF /* set r4 to 0xFFFFFFFF (status in the */
794 ori r4,r4,0xFFFF /* dbsr is cleared by setting bits to 1) */
795 mtdbsr r4 /* clear/reset the dbsr */
796 mtexisr r4 /* clear all pending interrupts */
797 addis r4,r0,0x8000
798 mtexier r4 /* enable critical exceptions */
799 addis r4,r0,0x0000 /* assume 403GCX - enable core clk */
800 ori r4,r4,0x4020 /* dbling (no harm done on GA and GC */
801 mtiocr r4 /* since bit not used) & DRC to latch */
802 /* data bus on rising edge of CAS */
803 /*----------------------------------------------------------------------- */
804 /* Clear XER. */
805 /*----------------------------------------------------------------------- */
806 mtxer r0
807 /*----------------------------------------------------------------------- */
808 /* Invalidate i-cache and d-cache TAG arrays. */
809 /*----------------------------------------------------------------------- */
810 addi r3,0,1024 /* 1/4 of I-cache size, half of D-cache */
811 addi r4,0,1024 /* 1/4 of I-cache */
812..cloop:
813 iccci 0,r3
814 iccci r4,r3
815 dccci 0,r3
816 addic. r3,r3,-16 /* move back one cache line */
817 bne ..cloop /* loop back to do rest until r3 = 0 */
818
819 /* */
820 /* initialize IOP480 so it can read 1 MB code area for SRAM spaces */
821 /* this requires enabling MA[17..0], by default only MA[12..0] are enabled. */
822 /* */
823
824 /* first copy IOP480 register base address into r3 */
825 addis r3,0,0x5000 /* IOP480 register base address hi */
826/* ori r3,r3,0x0000 / IOP480 register base address lo */
827
828#ifdef CONFIG_ADCIOP
829 /* use r4 as the working variable */
830 /* turn on CS3 (LOCCTL.7) */
831 lwz r4,0x84(r3) /* LOCTL is at offset 0x84 */
832 andi. r4,r4,0xff7f /* make bit 7 = 0 -- CS3 mode */
833 stw r4,0x84(r3) /* LOCTL is at offset 0x84 */
834#endif
835
836#ifdef CONFIG_DASA_SIM
837 /* use r4 as the working variable */
838 /* turn on MA17 (LOCCTL.7) */
839 lwz r4,0x84(r3) /* LOCTL is at offset 0x84 */
840 ori r4,r4,0x80 /* make bit 7 = 1 -- MA17 mode */
841 stw r4,0x84(r3) /* LOCTL is at offset 0x84 */
842#endif
843
844 /* turn on MA16..13 (LCS0BRD.12 = 0) */
845 lwz r4,0x100(r3) /* LCS0BRD is at offset 0x100 */
846 andi. r4,r4,0xefff /* make bit 12 = 0 */
847 stw r4,0x100(r3) /* LCS0BRD is at offset 0x100 */
848
849 /* make sure above stores all comlete before going on */
850 sync
851
852 /* last thing, set local init status done bit (DEVINIT.31) */
853 lwz r4,0x80(r3) /* DEVINIT is at offset 0x80 */
854 oris r4,r4,0x8000 /* make bit 31 = 1 */
855 stw r4,0x80(r3) /* DEVINIT is at offset 0x80 */
856
857 /* clear all pending interrupts and disable all interrupts */
858 li r4,-1 /* set p1 to 0xffffffff */
859 stw r4,0x1b0(r3) /* clear all pending interrupts */
860 stw r4,0x1b8(r3) /* clear all pending interrupts */
861 li r4,0 /* set r4 to 0 */
862 stw r4,0x1b4(r3) /* disable all interrupts */
863 stw r4,0x1bc(r3) /* disable all interrupts */
864
865 /* make sure above stores all comlete before going on */
866 sync
867
Grant Ericksonb6933412008-05-22 14:44:14 -0700868 /* Set-up icache cacheability. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200869 lis r1, CONFIG_SYS_ICACHE_SACR_VALUE@h
870 ori r1, r1, CONFIG_SYS_ICACHE_SACR_VALUE@l
Grant Ericksonb6933412008-05-22 14:44:14 -0700871 mticcr r1
872 isync
wdenk0442ed82002-11-03 10:24:00 +0000873
Grant Ericksonb6933412008-05-22 14:44:14 -0700874 /* Set-up dcache cacheability. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200875 lis r1, CONFIG_SYS_DCACHE_SACR_VALUE@h
876 ori r1, r1, CONFIG_SYS_DCACHE_SACR_VALUE@l
Grant Ericksonb6933412008-05-22 14:44:14 -0700877 mtdccr r1
wdenk0442ed82002-11-03 10:24:00 +0000878
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200879 addis r1,r0,CONFIG_SYS_INIT_RAM_ADDR@h
880 ori r1,r1,CONFIG_SYS_INIT_SP_OFFSET /* set up the stack to SDRAM */
wdenk0442ed82002-11-03 10:24:00 +0000881 li r0, 0 /* Make room for stack frame header and */
882 stwu r0, -4(r1) /* clear final stack frame so that */
883 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
884
885 GET_GOT /* initialize GOT access */
886
887 bl board_init_f /* run first part of init code (from Flash) */
888
889#endif /* CONFIG_IOP480 */
890
891/*****************************************************************************/
Stefan Roese17ffbc82007-03-21 13:38:59 +0100892#if defined(CONFIG_405GP) || defined(CONFIG_405CR) || \
893 defined(CONFIG_405EP) || defined(CONFIG_405EZ) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200894 defined(CONFIG_405EX) || defined(CONFIG_405)
wdenk0442ed82002-11-03 10:24:00 +0000895 /*----------------------------------------------------------------------- */
896 /* Clear and set up some registers. */
897 /*----------------------------------------------------------------------- */
898 addi r4,r0,0x0000
Stefan Roese153b3e22007-10-05 17:10:59 +0200899#if !defined(CONFIG_405EX)
wdenk0442ed82002-11-03 10:24:00 +0000900 mtspr sgr,r4
Stefan Roese153b3e22007-10-05 17:10:59 +0200901#else
902 /*
903 * On 405EX, completely clearing the SGR leads to PPC hangup
904 * upon PCIe configuration access. The PCIe memory regions
905 * need to be guarded!
906 */
907 lis r3,0x0000
908 ori r3,r3,0x7FFC
909 mtspr sgr,r3
910#endif
wdenk0442ed82002-11-03 10:24:00 +0000911 mtspr dcwr,r4
912 mtesr r4 /* clear Exception Syndrome Reg */
913 mttcr r4 /* clear Timer Control Reg */
914 mtxer r4 /* clear Fixed-Point Exception Reg */
915 mtevpr r4 /* clear Exception Vector Prefix Reg */
wdenk0442ed82002-11-03 10:24:00 +0000916 addi r4,r0,(0xFFFF-0x10000) /* set r4 to 0xFFFFFFFF (status in the */
917 /* dbsr is cleared by setting bits to 1) */
918 mtdbsr r4 /* clear/reset the dbsr */
919
Grant Ericksonb6933412008-05-22 14:44:14 -0700920 /* Invalidate the i- and d-caches. */
wdenk0442ed82002-11-03 10:24:00 +0000921 bl invalidate_icache
922 bl invalidate_dcache
923
Grant Ericksonb6933412008-05-22 14:44:14 -0700924 /* Set-up icache cacheability. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200925 lis r4, CONFIG_SYS_ICACHE_SACR_VALUE@h
926 ori r4, r4, CONFIG_SYS_ICACHE_SACR_VALUE@l
Grant Ericksonb6933412008-05-22 14:44:14 -0700927 mticcr r4
wdenk0442ed82002-11-03 10:24:00 +0000928 isync
929
Grant Ericksonb6933412008-05-22 14:44:14 -0700930 /* Set-up dcache cacheability. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200931 lis r4, CONFIG_SYS_DCACHE_SACR_VALUE@h
932 ori r4, r4, CONFIG_SYS_DCACHE_SACR_VALUE@l
Grant Ericksonb6933412008-05-22 14:44:14 -0700933 mtdccr r4
wdenk0442ed82002-11-03 10:24:00 +0000934
Ricardo Ribalda Delgado78ea77e2008-10-21 18:29:46 +0200935#if !(defined(CONFIG_SYS_EBC_PB0AP) && defined(CONFIG_SYS_EBC_PB0CR))\
936 && !defined (CONFIG_XILINX_405)
wdenk0442ed82002-11-03 10:24:00 +0000937 /*----------------------------------------------------------------------- */
938 /* Tune the speed and size for flash CS0 */
939 /*----------------------------------------------------------------------- */
940 bl ext_bus_cntlr_init
941#endif
Stefan Roese7d72e022008-06-02 14:35:44 +0200942
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200943#if !(defined(CONFIG_SYS_INIT_DCACHE_CS) || defined(CONFIG_SYS_TEMP_STACK_OCM))
Stefan Roese153b3e22007-10-05 17:10:59 +0200944 /*
Grant Ericksonb6933412008-05-22 14:44:14 -0700945 * For boards that don't have OCM and can't use the data cache
946 * for their primordial stack, setup stack here directly after the
947 * SDRAM is initialized in ext_bus_cntlr_init.
Stefan Roese153b3e22007-10-05 17:10:59 +0200948 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200949 lis r1, CONFIG_SYS_INIT_RAM_ADDR@h
950 ori r1,r1,CONFIG_SYS_INIT_SP_OFFSET /* set up the stack in SDRAM */
Stefan Roese153b3e22007-10-05 17:10:59 +0200951
952 li r0, 0 /* Make room for stack frame header and */
953 stwu r0, -4(r1) /* clear final stack frame so that */
954 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
955 /*
956 * Set up a dummy frame to store reset vector as return address.
957 * this causes stack underflow to reset board.
958 */
959 stwu r1, -8(r1) /* Save back chain and move SP */
960 lis r0, RESET_VECTOR@h /* Address of reset vector */
961 ori r0, r0, RESET_VECTOR@l
962 stwu r1, -8(r1) /* Save back chain and move SP */
963 stw r0, +12(r1) /* Save return addr (underflow vect) */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200964#endif /* !(CONFIG_SYS_INIT_DCACHE_CS || !CONFIG_SYS_TEM_STACK_OCM) */
wdenk0442ed82002-11-03 10:24:00 +0000965
stroese434979e2003-05-23 11:18:02 +0000966#if defined(CONFIG_405EP)
967 /*----------------------------------------------------------------------- */
968 /* DMA Status, clear to come up clean */
969 /*----------------------------------------------------------------------- */
Wolfgang Denka1be4762008-05-20 16:00:29 +0200970 addis r3,r0, 0xFFFF /* Clear all existing DMA status */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200971 ori r3,r3, 0xFFFF
972 mtdcr dmasr, r3
stroese434979e2003-05-23 11:18:02 +0000973
Wolfgang Denka1be4762008-05-20 16:00:29 +0200974 bl ppc405ep_init /* do ppc405ep specific init */
stroese434979e2003-05-23 11:18:02 +0000975#endif /* CONFIG_405EP */
976
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200977#if defined(CONFIG_SYS_OCM_DATA_ADDR) && defined(CONFIG_SYS_OCM_DATA_SIZE)
Stefan Roese17ffbc82007-03-21 13:38:59 +0100978#if defined(CONFIG_405EZ)
979 /********************************************************************
980 * Setup OCM - On Chip Memory - PPC405EZ uses OCM Controller V2
981 *******************************************************************/
982 /*
983 * We can map the OCM on the PLB3, so map it at
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200984 * CONFIG_SYS_OCM_DATA_ADDR + 0x8000
Stefan Roese17ffbc82007-03-21 13:38:59 +0100985 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200986 lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
987 ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
Stefan Roese80d99a42007-06-19 16:42:31 +0200988 ori r3,r3,0x0270 /* 16K for Bank 1, R/W/Enable */
Stefan Roese17ffbc82007-03-21 13:38:59 +0100989 mtdcr ocmplb3cr1,r3 /* Set PLB Access */
990 ori r3,r3,0x4000 /* Add 0x4000 for bank 2 */
991 mtdcr ocmplb3cr2,r3 /* Set PLB Access */
992 isync
993
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200994 lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
995 ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200996 ori r3,r3,0x0270 /* 16K for Bank 1, R/W/Enable */
997 mtdcr ocmdscr1, r3 /* Set Data Side */
998 mtdcr ocmiscr1, r3 /* Set Instruction Side */
Stefan Roese17ffbc82007-03-21 13:38:59 +0100999 ori r3,r3,0x4000 /* Add 0x4000 for bank 2 */
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001000 mtdcr ocmdscr2, r3 /* Set Data Side */
1001 mtdcr ocmiscr2, r3 /* Set Instruction Side */
1002 addis r3,0,0x0800 /* OCM Data Parity Disable - 1 Wait State */
Stefan Roesed85f5d72007-05-24 09:49:00 +02001003 mtdcr ocmdsisdpc,r3
Stefan Roese17ffbc82007-03-21 13:38:59 +01001004
1005 isync
Stefan Roesef6c7b762007-03-24 15:45:34 +01001006#else /* CONFIG_405EZ */
wdenk0442ed82002-11-03 10:24:00 +00001007 /********************************************************************
1008 * Setup OCM - On Chip Memory
1009 *******************************************************************/
1010 /* Setup OCM */
wdenk57b2d802003-06-27 21:31:46 +00001011 lis r0, 0x7FFF
1012 ori r0, r0, 0xFFFF
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001013 mfdcr r3, ocmiscntl /* get instr-side IRAM config */
Stefan Roesef6c7b762007-03-24 15:45:34 +01001014 mfdcr r4, ocmdscntl /* get data-side IRAM config */
1015 and r3, r3, r0 /* disable data-side IRAM */
1016 and r4, r4, r0 /* disable data-side IRAM */
1017 mtdcr ocmiscntl, r3 /* set instr-side IRAM config */
1018 mtdcr ocmdscntl, r4 /* set data-side IRAM config */
wdenk57b2d802003-06-27 21:31:46 +00001019 isync
wdenk0442ed82002-11-03 10:24:00 +00001020
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001021 lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
1022 ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
wdenk0442ed82002-11-03 10:24:00 +00001023 mtdcr ocmdsarc, r3
1024 addis r4, 0, 0xC000 /* OCM data area enabled */
1025 mtdcr ocmdscntl, r4
wdenk57b2d802003-06-27 21:31:46 +00001026 isync
Stefan Roese17ffbc82007-03-21 13:38:59 +01001027#endif /* CONFIG_405EZ */
wdenk0442ed82002-11-03 10:24:00 +00001028#endif
1029
1030 /*----------------------------------------------------------------------- */
1031 /* Setup temporary stack in DCACHE or OCM if needed for SDRAM SPD. */
1032 /*----------------------------------------------------------------------- */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001033#ifdef CONFIG_SYS_INIT_DCACHE_CS
Grant Ericksonb6933412008-05-22 14:44:14 -07001034 li r4, PBxAP
1035 mtdcr ebccfga, r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001036 lis r4, CONFIG_SYS_INIT_DCACHE_PBxAR@h
1037 ori r4, r4, CONFIG_SYS_INIT_DCACHE_PBxAR@l
Grant Ericksonb6933412008-05-22 14:44:14 -07001038 mtdcr ebccfgd, r4
wdenk0442ed82002-11-03 10:24:00 +00001039
Grant Ericksonb6933412008-05-22 14:44:14 -07001040 addi r4, 0, PBxCR
1041 mtdcr ebccfga, r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001042 lis r4, CONFIG_SYS_INIT_DCACHE_PBxCR@h
1043 ori r4, r4, CONFIG_SYS_INIT_DCACHE_PBxCR@l
Grant Ericksonb6933412008-05-22 14:44:14 -07001044 mtdcr ebccfgd, r4
wdenk0442ed82002-11-03 10:24:00 +00001045
Grant Ericksonb6933412008-05-22 14:44:14 -07001046 /*
1047 * Enable the data cache for the 128MB storage access control region
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001048 * at CONFIG_SYS_INIT_RAM_ADDR.
Grant Ericksonb6933412008-05-22 14:44:14 -07001049 */
1050 mfdccr r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001051 oris r4, r4, PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@h
1052 ori r4, r4, PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@l
wdenk0442ed82002-11-03 10:24:00 +00001053 mtdccr r4
1054
Grant Ericksonb6933412008-05-22 14:44:14 -07001055 /*
1056 * Preallocate data cache lines to be used to avoid a subsequent
1057 * cache miss and an ensuing machine check exception when exceptions
1058 * are enabled.
1059 */
1060 li r0, 0
1061
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001062 lis r3, CONFIG_SYS_INIT_RAM_ADDR@h
1063 ori r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
wdenk0442ed82002-11-03 10:24:00 +00001064
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001065 lis r4, CONFIG_SYS_INIT_RAM_END@h
1066 ori r4, r4, CONFIG_SYS_INIT_RAM_END@l
wdenk0442ed82002-11-03 10:24:00 +00001067
Grant Ericksonb6933412008-05-22 14:44:14 -07001068 /*
1069 * Convert the size, in bytes, to the number of cache lines/blocks
1070 * to preallocate.
1071 */
1072 clrlwi. r5, r4, (32 - L1_CACHE_SHIFT)
1073 srwi r5, r4, L1_CACHE_SHIFT
1074 beq ..load_counter
1075 addi r5, r5, 0x0001
1076..load_counter:
1077 mtctr r5
1078
1079 /* Preallocate the computed number of cache blocks. */
1080..alloc_dcache_block:
1081 dcba r0, r3
1082 addi r3, r3, L1_CACHE_BYTES
1083 bdnz ..alloc_dcache_block
1084 sync
1085
1086 /*
1087 * Load the initial stack pointer and data area and convert the size,
1088 * in bytes, to the number of words to initialize to a known value.
1089 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001090 lis r1, CONFIG_SYS_INIT_RAM_ADDR@h
1091 ori r1, r1, CONFIG_SYS_INIT_SP_OFFSET@l
Grant Ericksonb6933412008-05-22 14:44:14 -07001092
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001093 lis r4, (CONFIG_SYS_INIT_RAM_END >> 2)@h
1094 ori r4, r4, (CONFIG_SYS_INIT_RAM_END >> 2)@l
wdenk0442ed82002-11-03 10:24:00 +00001095 mtctr r4
1096
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001097 lis r2, CONFIG_SYS_INIT_RAM_ADDR@h
1098 ori r2, r2, CONFIG_SYS_INIT_RAM_END@l
wdenk0442ed82002-11-03 10:24:00 +00001099
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001100 lis r4, CONFIG_SYS_INIT_RAM_PATTERN@h
1101 ori r4, r4, CONFIG_SYS_INIT_RAM_PATTERN@l
wdenk0442ed82002-11-03 10:24:00 +00001102
1103..stackloop:
Grant Ericksonb6933412008-05-22 14:44:14 -07001104 stwu r4, -4(r2)
wdenk0442ed82002-11-03 10:24:00 +00001105 bdnz ..stackloop
1106
Grant Ericksonb6933412008-05-22 14:44:14 -07001107 /*
1108 * Make room for stack frame header and clear final stack frame so
1109 * that stack backtraces terminate cleanly.
1110 */
1111 stwu r0, -4(r1)
1112 stwu r0, -4(r1)
1113
wdenk0442ed82002-11-03 10:24:00 +00001114 /*
1115 * Set up a dummy frame to store reset vector as return address.
1116 * this causes stack underflow to reset board.
1117 */
1118 stwu r1, -8(r1) /* Save back chain and move SP */
1119 addis r0, 0, RESET_VECTOR@h /* Address of reset vector */
1120 ori r0, r0, RESET_VECTOR@l
1121 stwu r1, -8(r1) /* Save back chain and move SP */
1122 stw r0, +12(r1) /* Save return addr (underflow vect) */
1123
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001124#elif defined(CONFIG_SYS_TEMP_STACK_OCM) && \
1125 (defined(CONFIG_SYS_OCM_DATA_ADDR) && defined(CONFIG_SYS_OCM_DATA_SIZE))
wdenk0442ed82002-11-03 10:24:00 +00001126 /*
1127 * Stack in OCM.
1128 */
1129
1130 /* Set up Stack at top of OCM */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001131 lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET)@h
1132 ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET)@l
wdenk0442ed82002-11-03 10:24:00 +00001133
1134 /* Set up a zeroized stack frame so that backtrace works right */
1135 li r0, 0
1136 stwu r0, -4(r1)
1137 stwu r0, -4(r1)
1138
1139 /*
1140 * Set up a dummy frame to store reset vector as return address.
1141 * this causes stack underflow to reset board.
1142 */
1143 stwu r1, -8(r1) /* Save back chain and move SP */
1144 lis r0, RESET_VECTOR@h /* Address of reset vector */
1145 ori r0, r0, RESET_VECTOR@l
1146 stwu r1, -8(r1) /* Save back chain and move SP */
1147 stw r0, +12(r1) /* Save return addr (underflow vect) */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001148#endif /* CONFIG_SYS_INIT_DCACHE_CS */
wdenk0442ed82002-11-03 10:24:00 +00001149
Stefan Roese23d8d342007-06-06 11:42:13 +02001150#ifdef CONFIG_NAND_SPL
Stefan Roese7d72e022008-06-02 14:35:44 +02001151 bl nand_boot_common /* will not return */
Stefan Roese23d8d342007-06-06 11:42:13 +02001152#else
wdenk0442ed82002-11-03 10:24:00 +00001153 GET_GOT /* initialize GOT access */
1154
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001155 bl cpu_init_f /* run low-level CPU init code (from Flash) */
wdenk0442ed82002-11-03 10:24:00 +00001156
1157 /* NEVER RETURNS! */
1158 bl board_init_f /* run first part of init code (from Flash) */
Stefan Roese23d8d342007-06-06 11:42:13 +02001159#endif /* CONFIG_NAND_SPL */
wdenk0442ed82002-11-03 10:24:00 +00001160
wdenk232fe0b2003-09-02 22:48:03 +00001161#endif /* CONFIG_405GP || CONFIG_405CR || CONFIG_405 || CONFIG_405EP */
1162 /*----------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001163
1164
Stefan Roese42fbddd2006-09-07 11:51:23 +02001165#ifndef CONFIG_NAND_SPL
wdenk0442ed82002-11-03 10:24:00 +00001166/*
1167 * This code finishes saving the registers to the exception frame
1168 * and jumps to the appropriate handler for the exception.
1169 * Register r21 is pointer into trap frame, r1 has new stack pointer.
1170 */
1171 .globl transfer_to_handler
1172transfer_to_handler:
1173 stw r22,_NIP(r21)
1174 lis r22,MSR_POW@h
1175 andc r23,r23,r22
1176 stw r23,_MSR(r21)
1177 SAVE_GPR(7, r21)
1178 SAVE_4GPRS(8, r21)
1179 SAVE_8GPRS(12, r21)
1180 SAVE_8GPRS(24, r21)
wdenk0442ed82002-11-03 10:24:00 +00001181 mflr r23
1182 andi. r24,r23,0x3f00 /* get vector offset */
1183 stw r24,TRAP(r21)
1184 li r22,0
1185 stw r22,RESULT(r21)
1186 mtspr SPRG2,r22 /* r1 is now kernel sp */
wdenk0442ed82002-11-03 10:24:00 +00001187 lwz r24,0(r23) /* virtual address of handler */
1188 lwz r23,4(r23) /* where to go when done */
1189 mtspr SRR0,r24
1190 mtspr SRR1,r20
1191 mtlr r23
1192 SYNC
1193 rfi /* jump to handler, enable MMU */
1194
1195int_return:
1196 mfmsr r28 /* Disable interrupts */
1197 li r4,0
1198 ori r4,r4,MSR_EE
1199 andc r28,r28,r4
1200 SYNC /* Some chip revs need this... */
1201 mtmsr r28
1202 SYNC
1203 lwz r2,_CTR(r1)
1204 lwz r0,_LINK(r1)
1205 mtctr r2
1206 mtlr r0
1207 lwz r2,_XER(r1)
1208 lwz r0,_CCR(r1)
1209 mtspr XER,r2
1210 mtcrf 0xFF,r0
1211 REST_10GPRS(3, r1)
1212 REST_10GPRS(13, r1)
1213 REST_8GPRS(23, r1)
1214 REST_GPR(31, r1)
1215 lwz r2,_NIP(r1) /* Restore environment */
1216 lwz r0,_MSR(r1)
1217 mtspr SRR0,r2
1218 mtspr SRR1,r0
1219 lwz r0,GPR0(r1)
1220 lwz r2,GPR2(r1)
1221 lwz r1,GPR1(r1)
1222 SYNC
1223 rfi
1224
1225crit_return:
1226 mfmsr r28 /* Disable interrupts */
1227 li r4,0
1228 ori r4,r4,MSR_EE
1229 andc r28,r28,r4
1230 SYNC /* Some chip revs need this... */
1231 mtmsr r28
1232 SYNC
1233 lwz r2,_CTR(r1)
1234 lwz r0,_LINK(r1)
1235 mtctr r2
1236 mtlr r0
1237 lwz r2,_XER(r1)
1238 lwz r0,_CCR(r1)
1239 mtspr XER,r2
1240 mtcrf 0xFF,r0
1241 REST_10GPRS(3, r1)
1242 REST_10GPRS(13, r1)
1243 REST_8GPRS(23, r1)
1244 REST_GPR(31, r1)
1245 lwz r2,_NIP(r1) /* Restore environment */
1246 lwz r0,_MSR(r1)
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001247 mtspr csrr0,r2
1248 mtspr csrr1,r0
wdenk0442ed82002-11-03 10:24:00 +00001249 lwz r0,GPR0(r1)
1250 lwz r2,GPR2(r1)
1251 lwz r1,GPR1(r1)
1252 SYNC
1253 rfci
1254
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001255#ifdef CONFIG_440
1256mck_return:
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001257 mfmsr r28 /* Disable interrupts */
1258 li r4,0
1259 ori r4,r4,MSR_EE
1260 andc r28,r28,r4
1261 SYNC /* Some chip revs need this... */
1262 mtmsr r28
1263 SYNC
1264 lwz r2,_CTR(r1)
1265 lwz r0,_LINK(r1)
1266 mtctr r2
1267 mtlr r0
1268 lwz r2,_XER(r1)
1269 lwz r0,_CCR(r1)
1270 mtspr XER,r2
1271 mtcrf 0xFF,r0
1272 REST_10GPRS(3, r1)
1273 REST_10GPRS(13, r1)
1274 REST_8GPRS(23, r1)
1275 REST_GPR(31, r1)
1276 lwz r2,_NIP(r1) /* Restore environment */
1277 lwz r0,_MSR(r1)
1278 mtspr mcsrr0,r2
1279 mtspr mcsrr1,r0
1280 lwz r0,GPR0(r1)
1281 lwz r2,GPR2(r1)
1282 lwz r1,GPR1(r1)
1283 SYNC
1284 rfmci
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001285#endif /* CONFIG_440 */
1286
1287
wdenk0442ed82002-11-03 10:24:00 +00001288 .globl get_pvr
1289get_pvr:
1290 mfspr r3, PVR
1291 blr
1292
wdenk0442ed82002-11-03 10:24:00 +00001293/*------------------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001294/* Function: out16 */
1295/* Description: Output 16 bits */
1296/*------------------------------------------------------------------------------- */
1297 .globl out16
1298out16:
1299 sth r4,0x0000(r3)
1300 blr
1301
1302/*------------------------------------------------------------------------------- */
1303/* Function: out16r */
1304/* Description: Byte reverse and output 16 bits */
1305/*------------------------------------------------------------------------------- */
1306 .globl out16r
1307out16r:
1308 sthbrx r4,r0,r3
1309 blr
1310
1311/*------------------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001312/* Function: out32r */
1313/* Description: Byte reverse and output 32 bits */
1314/*------------------------------------------------------------------------------- */
1315 .globl out32r
1316out32r:
1317 stwbrx r4,r0,r3
1318 blr
1319
1320/*------------------------------------------------------------------------------- */
1321/* Function: in16 */
1322/* Description: Input 16 bits */
1323/*------------------------------------------------------------------------------- */
1324 .globl in16
1325in16:
1326 lhz r3,0x0000(r3)
1327 blr
1328
1329/*------------------------------------------------------------------------------- */
1330/* Function: in16r */
1331/* Description: Input 16 bits and byte reverse */
1332/*------------------------------------------------------------------------------- */
1333 .globl in16r
1334in16r:
1335 lhbrx r3,r0,r3
1336 blr
1337
1338/*------------------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001339/* Function: in32r */
1340/* Description: Input 32 bits and byte reverse */
1341/*------------------------------------------------------------------------------- */
1342 .globl in32r
1343in32r:
1344 lwbrx r3,r0,r3
1345 blr
1346
wdenk0442ed82002-11-03 10:24:00 +00001347/*
1348 * void relocate_code (addr_sp, gd, addr_moni)
1349 *
1350 * This "function" does not return, instead it continues in RAM
1351 * after relocating the monitor code.
1352 *
Grant Ericksonb6933412008-05-22 14:44:14 -07001353 * r3 = Relocated stack pointer
1354 * r4 = Relocated global data pointer
1355 * r5 = Relocated text pointer
wdenk0442ed82002-11-03 10:24:00 +00001356 */
1357 .globl relocate_code
1358relocate_code:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001359#if defined(CONFIG_4xx_DCACHE) || defined(CONFIG_SYS_INIT_DCACHE_CS)
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001360 /*
Grant Ericksonb6933412008-05-22 14:44:14 -07001361 * We need to flush the initial global data (gd_t) before the dcache
1362 * will be invalidated.
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001363 */
1364
Grant Ericksonb6933412008-05-22 14:44:14 -07001365 /* Save registers */
1366 mr r9, r3
1367 mr r10, r4
1368 mr r11, r5
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001369
Grant Ericksonb6933412008-05-22 14:44:14 -07001370 /* Flush initial global data range */
1371 mr r3, r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001372 addi r4, r4, CONFIG_SYS_GBL_DATA_SIZE@l
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001373 bl flush_dcache_range
1374
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001375#if defined(CONFIG_SYS_INIT_DCACHE_CS)
Grant Ericksonb6933412008-05-22 14:44:14 -07001376 /*
1377 * Undo the earlier data cache set-up for the primordial stack and
1378 * data area. First, invalidate the data cache and then disable data
1379 * cacheability for that area. Finally, restore the EBC values, if
1380 * any.
1381 */
1382
1383 /* Invalidate the primordial stack and data area in cache */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001384 lis r3, CONFIG_SYS_INIT_RAM_ADDR@h
1385 ori r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
Grant Ericksonb6933412008-05-22 14:44:14 -07001386
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001387 lis r4, CONFIG_SYS_INIT_RAM_END@h
1388 ori r4, r4, CONFIG_SYS_INIT_RAM_END@l
Grant Ericksonb6933412008-05-22 14:44:14 -07001389 add r4, r4, r3
1390
1391 bl invalidate_dcache_range
1392
1393 /* Disable cacheability for the region */
1394 mfdccr r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001395 lis r4, ~PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@h
1396 ori r4, r4, ~PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@l
Grant Ericksonb6933412008-05-22 14:44:14 -07001397 and r3, r3, r4
1398 mtdccr r3
1399
1400 /* Restore the EBC parameters */
1401 li r3, PBxAP
1402 mtdcr ebccfga, r3
1403 lis r3, PBxAP_VAL@h
1404 ori r3, r3, PBxAP_VAL@l
1405 mtdcr ebccfgd, r3
1406
1407 li r3, PBxCR
1408 mtdcr ebccfga, r3
1409 lis r3, PBxCR_VAL@h
1410 ori r3, r3, PBxCR_VAL@l
1411 mtdcr ebccfgd, r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001412#endif /* defined(CONFIG_SYS_INIT_DCACHE_CS) */
Grant Ericksonb6933412008-05-22 14:44:14 -07001413
1414 /* Restore registers */
1415 mr r3, r9
1416 mr r4, r10
1417 mr r5, r11
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001418#endif /* defined(CONFIG_4xx_DCACHE) || defined(CONFIG_SYS_INIT_DCACHE_CS) */
Stefan Roesea86bde32008-01-09 10:23:16 +01001419
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001420#ifdef CONFIG_SYS_INIT_RAM_DCACHE
Stefan Roesea86bde32008-01-09 10:23:16 +01001421 /*
1422 * Unlock the previously locked d-cache
1423 */
1424 msync
1425 isync
1426 /* set TFLOOR/NFLOOR to 0 again */
1427 lis r6,0x0001
1428 ori r6,r6,0xf800
1429 mtspr dvlim,r6
1430 lis r6,0x0000
1431 ori r6,r6,0x0000
1432 mtspr dnv0,r6
1433 mtspr dnv1,r6
1434 mtspr dnv2,r6
1435 mtspr dnv3,r6
1436 mtspr dtv0,r6
1437 mtspr dtv1,r6
1438 mtspr dtv2,r6
1439 mtspr dtv3,r6
1440 msync
1441 isync
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001442#endif /* CONFIG_SYS_INIT_RAM_DCACHE */
Stefan Roesea86bde32008-01-09 10:23:16 +01001443
Stefan Roese42fbddd2006-09-07 11:51:23 +02001444#if defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
1445 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesecc019d12008-03-11 15:05:50 +01001446 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Feng Kan224bc962008-07-08 22:47:31 -07001447 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
1448 defined(CONFIG_460SX)
Stefan Roese9eba0c82006-06-02 16:18:04 +02001449 /*
1450 * On some 440er platforms the cache is enabled in the first TLB (Boot-CS)
1451 * to speed up the boot process. Now this cache needs to be disabled.
1452 */
1453 iccci 0,0 /* Invalidate inst cache */
1454 dccci 0,0 /* Invalidate data cache, now no longer our stack */
Stefan Roese326c9712005-08-01 16:41:48 +02001455 sync
Stefan Roese9eba0c82006-06-02 16:18:04 +02001456 isync
Stefan Roesefe05a022008-11-20 11:46:20 +01001457
1458 /* Clear all potential pending exceptions */
1459 mfspr r1,mcsr
1460 mtspr mcsr,r1
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001461#ifdef CONFIG_SYS_TLB_FOR_BOOT_FLASH
1462 addi r1,r0,CONFIG_SYS_TLB_FOR_BOOT_FLASH /* Use defined TLB */
Niklaus Giger86cb27b2007-11-30 18:35:11 +01001463#else
1464 addi r1,r0,0x0000 /* Default TLB entry is #0 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001465#endif /* CONFIG_SYS_TLB_FOR_BOOT_FLASH */
Stefan Roese326c9712005-08-01 16:41:48 +02001466 tlbre r0,r1,0x0002 /* Read contents */
Stefan Roese99644742005-11-29 18:18:21 +01001467 ori r0,r0,0x0c00 /* Or in the inhibit, write through bit */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001468 tlbwe r0,r1,0x0002 /* Save it out */
Stefan Roese9eba0c82006-06-02 16:18:04 +02001469 sync
Stefan Roese326c9712005-08-01 16:41:48 +02001470 isync
Grant Ericksonb6933412008-05-22 14:44:14 -07001471#endif /* defined(CONFIG_440EP) || ... || defined(CONFIG_460GT) */
wdenk0442ed82002-11-03 10:24:00 +00001472 mr r1, r3 /* Set new stack pointer */
1473 mr r9, r4 /* Save copy of Init Data pointer */
1474 mr r10, r5 /* Save copy of Destination Address */
1475
1476 mr r3, r5 /* Destination Address */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001477 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
1478 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
wdenkb9a83a92003-05-30 12:48:29 +00001479 lwz r5, GOT(__init_end)
1480 sub r5, r5, r4
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001481 li r6, L1_CACHE_BYTES /* Cache Line Size */
wdenk0442ed82002-11-03 10:24:00 +00001482
1483 /*
1484 * Fix GOT pointer:
1485 *
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001486 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
wdenk0442ed82002-11-03 10:24:00 +00001487 *
1488 * Offset:
1489 */
1490 sub r15, r10, r4
1491
1492 /* First our own GOT */
1493 add r14, r14, r15
Grant Ericksonb6933412008-05-22 14:44:14 -07001494 /* then the one used by the C code */
wdenk0442ed82002-11-03 10:24:00 +00001495 add r30, r30, r15
1496
1497 /*
1498 * Now relocate code
1499 */
1500
1501 cmplw cr1,r3,r4
1502 addi r0,r5,3
1503 srwi. r0,r0,2
1504 beq cr1,4f /* In place copy is not necessary */
1505 beq 7f /* Protect against 0 count */
1506 mtctr r0
1507 bge cr1,2f
1508
1509 la r8,-4(r4)
1510 la r7,-4(r3)
15111: lwzu r0,4(r8)
1512 stwu r0,4(r7)
1513 bdnz 1b
1514 b 4f
1515
15162: slwi r0,r0,2
1517 add r8,r4,r0
1518 add r7,r3,r0
15193: lwzu r0,-4(r8)
1520 stwu r0,-4(r7)
1521 bdnz 3b
1522
1523/*
1524 * Now flush the cache: note that we must start from a cache aligned
1525 * address. Otherwise we might miss one cache line.
1526 */
15274: cmpwi r6,0
1528 add r5,r3,r5
1529 beq 7f /* Always flush prefetch queue in any case */
1530 subi r0,r6,1
1531 andc r3,r3,r0
1532 mr r4,r3
15335: dcbst 0,r4
1534 add r4,r4,r6
1535 cmplw r4,r5
1536 blt 5b
1537 sync /* Wait for all dcbst to complete on bus */
1538 mr r4,r3
15396: icbi 0,r4
1540 add r4,r4,r6
1541 cmplw r4,r5
1542 blt 6b
15437: sync /* Wait for all icbi to complete on bus */
1544 isync
1545
1546/*
1547 * We are done. Do not return, instead branch to second part of board
1548 * initialization, now running from RAM.
1549 */
1550
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001551 addi r0, r10, in_ram - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +00001552 mtlr r0
1553 blr /* NEVER RETURNS! */
1554
1555in_ram:
1556
1557 /*
1558 * Relocation Function, r14 point to got2+0x8000
1559 *
1560 * Adjust got2 pointers, no need to check for 0, this code
1561 * already puts a few entries in the table.
1562 */
1563 li r0,__got2_entries@sectoff@l
1564 la r3,GOT(_GOT2_TABLE_)
1565 lwz r11,GOT(_GOT2_TABLE_)
1566 mtctr r0
1567 sub r11,r3,r11
1568 addi r3,r3,-4
15691: lwzu r0,4(r3)
1570 add r0,r0,r11
1571 stw r0,0(r3)
1572 bdnz 1b
1573
1574 /*
1575 * Now adjust the fixups and the pointers to the fixups
1576 * in case we need to move ourselves again.
1577 */
15782: li r0,__fixup_entries@sectoff@l
1579 lwz r3,GOT(_FIXUP_TABLE_)
1580 cmpwi r0,0
1581 mtctr r0
1582 addi r3,r3,-4
1583 beq 4f
15843: lwzu r4,4(r3)
1585 lwzux r0,r4,r11
1586 add r0,r0,r11
1587 stw r10,0(r3)
1588 stw r0,0(r4)
1589 bdnz 3b
15904:
1591clear_bss:
1592 /*
1593 * Now clear BSS segment
1594 */
wdenkbf2f8c92003-05-22 22:52:13 +00001595 lwz r3,GOT(__bss_start)
wdenk0442ed82002-11-03 10:24:00 +00001596 lwz r4,GOT(_end)
1597
1598 cmplw 0, r3, r4
Anatolij Gustschin720025b2007-12-05 17:43:20 +01001599 beq 7f
wdenk0442ed82002-11-03 10:24:00 +00001600
1601 li r0, 0
Anatolij Gustschin720025b2007-12-05 17:43:20 +01001602
1603 andi. r5, r4, 3
1604 beq 6f
1605 sub r4, r4, r5
1606 mtctr r5
1607 mr r5, r4
16085: stb r0, 0(r5)
1609 addi r5, r5, 1
1610 bdnz 5b
16116:
wdenk0442ed82002-11-03 10:24:00 +00001612 stw r0, 0(r3)
1613 addi r3, r3, 4
1614 cmplw 0, r3, r4
Anatolij Gustschin720025b2007-12-05 17:43:20 +01001615 bne 6b
wdenk0442ed82002-11-03 10:24:00 +00001616
Anatolij Gustschin720025b2007-12-05 17:43:20 +010016177:
wdenk0442ed82002-11-03 10:24:00 +00001618 mr r3, r9 /* Init Data pointer */
1619 mr r4, r10 /* Destination Address */
1620 bl board_init_r
1621
wdenk0442ed82002-11-03 10:24:00 +00001622 /*
1623 * Copy exception vector code to low memory
1624 *
1625 * r3: dest_addr
1626 * r7: source address, r8: end address, r9: target address
1627 */
1628 .globl trap_init
1629trap_init:
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001630 lwz r7, GOT(_start_of_vectors)
wdenk0442ed82002-11-03 10:24:00 +00001631 lwz r8, GOT(_end_of_vectors)
1632
wdenk4e112c12003-06-03 23:54:09 +00001633 li r9, 0x100 /* reset vector always at 0x100 */
wdenk0442ed82002-11-03 10:24:00 +00001634
1635 cmplw 0, r7, r8
1636 bgelr /* return if r7>=r8 - just in case */
1637
1638 mflr r4 /* save link register */
16391:
1640 lwz r0, 0(r7)
1641 stw r0, 0(r9)
1642 addi r7, r7, 4
1643 addi r9, r9, 4
1644 cmplw 0, r7, r8
1645 bne 1b
1646
1647 /*
1648 * relocate `hdlr' and `int_return' entries
1649 */
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001650 li r7, .L_MachineCheck - _start + _START_OFFSET
1651 li r8, Alignment - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +000016522:
1653 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001654 addi r7, r7, 0x100 /* next exception vector */
wdenk0442ed82002-11-03 10:24:00 +00001655 cmplw 0, r7, r8
1656 blt 2b
1657
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001658 li r7, .L_Alignment - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +00001659 bl trap_reloc
1660
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001661 li r7, .L_ProgramCheck - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +00001662 bl trap_reloc
1663
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001664#ifdef CONFIG_440
1665 li r7, .L_FPUnavailable - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001666 bl trap_reloc
wdenk0442ed82002-11-03 10:24:00 +00001667
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001668 li r7, .L_Decrementer - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001669 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001670
1671 li r7, .L_APU - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001672 bl trap_reloc
Stefan Roese80d99a42007-06-19 16:42:31 +02001673
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001674 li r7, .L_InstructionTLBError - _start + _START_OFFSET
1675 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001676
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001677 li r7, .L_DataTLBError - _start + _START_OFFSET
1678 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001679#else /* CONFIG_440 */
1680 li r7, .L_PIT - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001681 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001682
1683 li r7, .L_InstructionTLBMiss - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001684 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001685
1686 li r7, .L_DataTLBMiss - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001687 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001688#endif /* CONFIG_440 */
1689
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001690 li r7, .L_DebugBreakpoint - _start + _START_OFFSET
1691 bl trap_reloc
wdenk0442ed82002-11-03 10:24:00 +00001692
Stefan Roese42fbddd2006-09-07 11:51:23 +02001693#if !defined(CONFIG_440)
Stefan Roese7b12aa82006-03-13 09:42:28 +01001694 addi r7,r0,0x1000 /* set ME bit (Machine Exceptions) */
1695 oris r7,r7,0x0002 /* set CE bit (Critical Exceptions) */
1696 mtmsr r7 /* change MSR */
1697#else
Stefan Roese42fbddd2006-09-07 11:51:23 +02001698 bl __440_msr_set
1699 b __440_msr_continue
Stefan Roese7b12aa82006-03-13 09:42:28 +01001700
Stefan Roese42fbddd2006-09-07 11:51:23 +02001701__440_msr_set:
Stefan Roese7b12aa82006-03-13 09:42:28 +01001702 addi r7,r0,0x1000 /* set ME bit (Machine Exceptions) */
1703 oris r7,r7,0x0002 /* set CE bit (Critical Exceptions) */
1704 mtspr srr1,r7
1705 mflr r7
1706 mtspr srr0,r7
1707 rfi
Stefan Roese42fbddd2006-09-07 11:51:23 +02001708__440_msr_continue:
Stefan Roese7b12aa82006-03-13 09:42:28 +01001709#endif
1710
wdenk0442ed82002-11-03 10:24:00 +00001711 mtlr r4 /* restore link register */
1712 blr
1713
1714 /*
1715 * Function: relocate entries for one exception vector
1716 */
1717trap_reloc:
1718 lwz r0, 0(r7) /* hdlr ... */
1719 add r0, r0, r3 /* ... += dest_addr */
1720 stw r0, 0(r7)
1721
1722 lwz r0, 4(r7) /* int_return ... */
1723 add r0, r0, r3 /* ... += dest_addr */
1724 stw r0, 4(r7)
1725
1726 blr
Stefan Roese42743512007-06-01 15:27:11 +02001727
1728#if defined(CONFIG_440)
1729/*----------------------------------------------------------------------------+
1730| dcbz_area.
1731+----------------------------------------------------------------------------*/
1732 function_prolog(dcbz_area)
1733 rlwinm. r5,r4,0,27,31
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001734 rlwinm r5,r4,27,5,31
1735 beq ..d_ra2
1736 addi r5,r5,0x0001
1737..d_ra2:mtctr r5
1738..d_ag2:dcbz r0,r3
1739 addi r3,r3,32
1740 bdnz ..d_ag2
Stefan Roese42743512007-06-01 15:27:11 +02001741 sync
1742 blr
1743 function_epilog(dcbz_area)
Stefan Roese42743512007-06-01 15:27:11 +02001744#endif /* CONFIG_440 */
Stefan Roese42fbddd2006-09-07 11:51:23 +02001745#endif /* CONFIG_NAND_SPL */
stroese434979e2003-05-23 11:18:02 +00001746
Stefan Roese42743512007-06-01 15:27:11 +02001747/*------------------------------------------------------------------------------- */
1748/* Function: in8 */
1749/* Description: Input 8 bits */
1750/*------------------------------------------------------------------------------- */
1751 .globl in8
1752in8:
1753 lbz r3,0x0000(r3)
1754 blr
1755
1756/*------------------------------------------------------------------------------- */
1757/* Function: out8 */
1758/* Description: Output 8 bits */
1759/*------------------------------------------------------------------------------- */
1760 .globl out8
1761out8:
1762 stb r4,0x0000(r3)
1763 blr
1764
1765/*------------------------------------------------------------------------------- */
1766/* Function: out32 */
1767/* Description: Output 32 bits */
1768/*------------------------------------------------------------------------------- */
1769 .globl out32
1770out32:
1771 stw r4,0x0000(r3)
1772 blr
1773
1774/*------------------------------------------------------------------------------- */
1775/* Function: in32 */
1776/* Description: Input 32 bits */
1777/*------------------------------------------------------------------------------- */
1778 .globl in32
1779in32:
1780 lwz 3,0x0000(3)
1781 blr
stroese434979e2003-05-23 11:18:02 +00001782
1783/**************************************************************************/
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001784/* PPC405EP specific stuff */
stroese434979e2003-05-23 11:18:02 +00001785/**************************************************************************/
1786#ifdef CONFIG_405EP
1787ppc405ep_init:
stroese5ad6d4d2003-12-09 14:54:43 +00001788
Stefan Roese326c9712005-08-01 16:41:48 +02001789#ifdef CONFIG_BUBINGA
stroese5ad6d4d2003-12-09 14:54:43 +00001790 /*
1791 * Initialize EBC chip selects 1 & 4 and GPIO pins (for alternate
1792 * function) to support FPGA and NVRAM accesses below.
1793 */
1794
1795 lis r3,GPIO0_OSRH@h /* config GPIO output select */
1796 ori r3,r3,GPIO0_OSRH@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001797 lis r4,CONFIG_SYS_GPIO0_OSRH@h
1798 ori r4,r4,CONFIG_SYS_GPIO0_OSRH@l
stroese5ad6d4d2003-12-09 14:54:43 +00001799 stw r4,0(r3)
1800 lis r3,GPIO0_OSRL@h
1801 ori r3,r3,GPIO0_OSRL@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001802 lis r4,CONFIG_SYS_GPIO0_OSRL@h
1803 ori r4,r4,CONFIG_SYS_GPIO0_OSRL@l
stroese5ad6d4d2003-12-09 14:54:43 +00001804 stw r4,0(r3)
1805
1806 lis r3,GPIO0_ISR1H@h /* config GPIO input select */
1807 ori r3,r3,GPIO0_ISR1H@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001808 lis r4,CONFIG_SYS_GPIO0_ISR1H@h
1809 ori r4,r4,CONFIG_SYS_GPIO0_ISR1H@l
stroese5ad6d4d2003-12-09 14:54:43 +00001810 stw r4,0(r3)
1811 lis r3,GPIO0_ISR1L@h
1812 ori r3,r3,GPIO0_ISR1L@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001813 lis r4,CONFIG_SYS_GPIO0_ISR1L@h
1814 ori r4,r4,CONFIG_SYS_GPIO0_ISR1L@l
stroese5ad6d4d2003-12-09 14:54:43 +00001815 stw r4,0(r3)
1816
1817 lis r3,GPIO0_TSRH@h /* config GPIO three-state select */
1818 ori r3,r3,GPIO0_TSRH@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001819 lis r4,CONFIG_SYS_GPIO0_TSRH@h
1820 ori r4,r4,CONFIG_SYS_GPIO0_TSRH@l
stroese5ad6d4d2003-12-09 14:54:43 +00001821 stw r4,0(r3)
1822 lis r3,GPIO0_TSRL@h
1823 ori r3,r3,GPIO0_TSRL@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001824 lis r4,CONFIG_SYS_GPIO0_TSRL@h
1825 ori r4,r4,CONFIG_SYS_GPIO0_TSRL@l
stroese5ad6d4d2003-12-09 14:54:43 +00001826 stw r4,0(r3)
1827
1828 lis r3,GPIO0_TCR@h /* config GPIO driver output enables */
1829 ori r3,r3,GPIO0_TCR@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001830 lis r4,CONFIG_SYS_GPIO0_TCR@h
1831 ori r4,r4,CONFIG_SYS_GPIO0_TCR@l
stroese5ad6d4d2003-12-09 14:54:43 +00001832 stw r4,0(r3)
1833
1834 li r3,pb1ap /* program EBC bank 1 for RTC access */
1835 mtdcr ebccfga,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001836 lis r3,CONFIG_SYS_EBC_PB1AP@h
1837 ori r3,r3,CONFIG_SYS_EBC_PB1AP@l
stroese5ad6d4d2003-12-09 14:54:43 +00001838 mtdcr ebccfgd,r3
1839 li r3,pb1cr
1840 mtdcr ebccfga,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001841 lis r3,CONFIG_SYS_EBC_PB1CR@h
1842 ori r3,r3,CONFIG_SYS_EBC_PB1CR@l
stroese5ad6d4d2003-12-09 14:54:43 +00001843 mtdcr ebccfgd,r3
1844
1845 li r3,pb1ap /* program EBC bank 1 for RTC access */
1846 mtdcr ebccfga,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001847 lis r3,CONFIG_SYS_EBC_PB1AP@h
1848 ori r3,r3,CONFIG_SYS_EBC_PB1AP@l
stroese5ad6d4d2003-12-09 14:54:43 +00001849 mtdcr ebccfgd,r3
1850 li r3,pb1cr
1851 mtdcr ebccfga,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001852 lis r3,CONFIG_SYS_EBC_PB1CR@h
1853 ori r3,r3,CONFIG_SYS_EBC_PB1CR@l
stroese5ad6d4d2003-12-09 14:54:43 +00001854 mtdcr ebccfgd,r3
1855
1856 li r3,pb4ap /* program EBC bank 4 for FPGA access */
1857 mtdcr ebccfga,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001858 lis r3,CONFIG_SYS_EBC_PB4AP@h
1859 ori r3,r3,CONFIG_SYS_EBC_PB4AP@l
stroese5ad6d4d2003-12-09 14:54:43 +00001860 mtdcr ebccfgd,r3
1861 li r3,pb4cr
1862 mtdcr ebccfga,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001863 lis r3,CONFIG_SYS_EBC_PB4CR@h
1864 ori r3,r3,CONFIG_SYS_EBC_PB4CR@l
stroese5ad6d4d2003-12-09 14:54:43 +00001865 mtdcr ebccfgd,r3
1866#endif
stroese434979e2003-05-23 11:18:02 +00001867
wdenk57b2d802003-06-27 21:31:46 +00001868 /*
1869 !-----------------------------------------------------------------------
1870 ! Check to see if chip is in bypass mode.
1871 ! If so, write stored CPC0_PLLMR0 and CPC0_PLLMR1 values and perform a
1872 ! CPU reset Otherwise, skip this step and keep going.
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001873 ! Note: Running BIOS in bypass mode is not supported since PLB speed
1874 ! will not be fast enough for the SDRAM (min 66MHz)
wdenk57b2d802003-06-27 21:31:46 +00001875 !-----------------------------------------------------------------------
stroese434979e2003-05-23 11:18:02 +00001876 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001877 mfdcr r5, CPC0_PLLMR1
Wolfgang Denka1be4762008-05-20 16:00:29 +02001878 rlwinm r4,r5,1,0x1 /* get system clock source (SSCS) */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001879 cmpi cr0,0,r4,0x1
stroese434979e2003-05-23 11:18:02 +00001880
Wolfgang Denka1be4762008-05-20 16:00:29 +02001881 beq pll_done /* if SSCS =b'1' then PLL has */
1882 /* already been set */
1883 /* and CPU has been reset */
1884 /* so skip to next section */
stroese434979e2003-05-23 11:18:02 +00001885
Stefan Roese326c9712005-08-01 16:41:48 +02001886#ifdef CONFIG_BUBINGA
stroese434979e2003-05-23 11:18:02 +00001887 /*
wdenk57b2d802003-06-27 21:31:46 +00001888 !-----------------------------------------------------------------------
1889 ! Read NVRAM to get value to write in PLLMR.
1890 ! If value has not been correctly saved, write default value
1891 ! Default config values (assuming on-board 33MHz SYS_CLK) are above.
1892 ! See CPU_DEFAULT_200 and CPU_DEFAULT_266 above.
1893 !
1894 ! WARNING: This code assumes the first three words in the nvram_t
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001895 ! structure in openbios.h. Changing the beginning of
1896 ! the structure will break this code.
wdenk57b2d802003-06-27 21:31:46 +00001897 !
1898 !-----------------------------------------------------------------------
stroese434979e2003-05-23 11:18:02 +00001899 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001900 addis r3,0,NVRAM_BASE@h
1901 addi r3,r3,NVRAM_BASE@l
stroese434979e2003-05-23 11:18:02 +00001902
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001903 lwz r4, 0(r3)
1904 addis r5,0,NVRVFY1@h
1905 addi r5,r5,NVRVFY1@l
Wolfgang Denka1be4762008-05-20 16:00:29 +02001906 cmp cr0,0,r4,r5 /* Compare 1st NVRAM Magic number*/
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001907 bne ..no_pllset
1908 addi r3,r3,4
1909 lwz r4, 0(r3)
1910 addis r5,0,NVRVFY2@h
1911 addi r5,r5,NVRVFY2@l
Wolfgang Denka1be4762008-05-20 16:00:29 +02001912 cmp cr0,0,r4,r5 /* Compare 2 NVRAM Magic number */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001913 bne ..no_pllset
1914 addi r3,r3,8 /* Skip over conf_size */
1915 lwz r4, 4(r3) /* Load PLLMR1 value from NVRAM */
1916 lwz r3, 0(r3) /* Load PLLMR0 value from NVRAM */
1917 rlwinm r5,r4,1,0x1 /* get system clock source (SSCS) */
1918 cmpi cr0,0,r5,1 /* See if PLL is locked */
1919 beq pll_write
stroese434979e2003-05-23 11:18:02 +00001920..no_pllset:
Stefan Roese326c9712005-08-01 16:41:48 +02001921#endif /* CONFIG_BUBINGA */
stroese434979e2003-05-23 11:18:02 +00001922
John Otken9aa36772007-07-26 17:49:11 +02001923#ifdef CONFIG_TAIHU
1924 mfdcr r4, CPC0_BOOT
1925 andi. r5, r4, CPC0_BOOT_SEP@l
1926 bne strap_1 /* serial eeprom present */
1927 addis r5,0,CPLD_REG0_ADDR@h
1928 ori r5,r5,CPLD_REG0_ADDR@l
1929 andi. r5, r5, 0x10
1930 bne _pci_66mhz
1931#endif /* CONFIG_TAIHU */
1932
Stefan Roesea5d182e2007-08-14 14:44:41 +02001933#if defined(CONFIG_ZEUS)
1934 mfdcr r4, CPC0_BOOT
1935 andi. r5, r4, CPC0_BOOT_SEP@l
Wolfgang Denka1be4762008-05-20 16:00:29 +02001936 bne strap_1 /* serial eeprom present */
Stefan Roesea5d182e2007-08-14 14:44:41 +02001937 lis r3,0x0000
1938 addi r3,r3,0x3030
1939 lis r4,0x8042
1940 addi r4,r4,0x223e
1941 b 1f
1942strap_1:
1943 mfdcr r3, CPC0_PLLMR0
1944 mfdcr r4, CPC0_PLLMR1
1945 b 1f
1946#endif
1947
Wolfgang Denka1be4762008-05-20 16:00:29 +02001948 addis r3,0,PLLMR0_DEFAULT@h /* PLLMR0 default value */
1949 ori r3,r3,PLLMR0_DEFAULT@l /* */
1950 addis r4,0,PLLMR1_DEFAULT@h /* PLLMR1 default value */
1951 ori r4,r4,PLLMR1_DEFAULT@l /* */
stroese434979e2003-05-23 11:18:02 +00001952
John Otken9aa36772007-07-26 17:49:11 +02001953#ifdef CONFIG_TAIHU
1954 b 1f
1955_pci_66mhz:
1956 addis r3,0,PLLMR0_DEFAULT_PCI66@h
1957 ori r3,r3,PLLMR0_DEFAULT_PCI66@l
1958 addis r4,0,PLLMR1_DEFAULT_PCI66@h
1959 ori r4,r4,PLLMR1_DEFAULT_PCI66@l
1960 b 1f
1961strap_1:
1962 mfdcr r3, CPC0_PLLMR0
1963 mfdcr r4, CPC0_PLLMR1
John Otken9aa36772007-07-26 17:49:11 +02001964#endif /* CONFIG_TAIHU */
1965
Stefan Roesea5d182e2007-08-14 14:44:41 +020019661:
Wolfgang Denka1be4762008-05-20 16:00:29 +02001967 b pll_write /* Write the CPC0_PLLMR with new value */
stroese434979e2003-05-23 11:18:02 +00001968
1969pll_done:
wdenk57b2d802003-06-27 21:31:46 +00001970 /*
1971 !-----------------------------------------------------------------------
1972 ! Clear Soft Reset Register
1973 ! This is needed to enable PCI if not booting from serial EPROM
1974 !-----------------------------------------------------------------------
stroese434979e2003-05-23 11:18:02 +00001975 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001976 addi r3, 0, 0x0
1977 mtdcr CPC0_SRR, r3
stroese434979e2003-05-23 11:18:02 +00001978
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001979 addis r3,0,0x0010
1980 mtctr r3
stroese434979e2003-05-23 11:18:02 +00001981pci_wait:
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001982 bdnz pci_wait
stroese434979e2003-05-23 11:18:02 +00001983
Wolfgang Denka1be4762008-05-20 16:00:29 +02001984 blr /* return to main code */
stroese434979e2003-05-23 11:18:02 +00001985
1986/*
1987!-----------------------------------------------------------------------------
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001988! Function: pll_write
1989! Description: Updates the value of the CPC0_PLLMR according to CMOS27E documentation
1990! That is:
1991! 1. Pll is first disabled (de-activated by putting in bypass mode)
1992! 2. PLL is reset
1993! 3. Clock dividers are set while PLL is held in reset and bypassed
1994! 4. PLL Reset is cleared
1995! 5. Wait 100us for PLL to lock
1996! 6. A core reset is performed
stroese434979e2003-05-23 11:18:02 +00001997! Input: r3 = Value to write to CPC0_PLLMR0
1998! Input: r4 = Value to write to CPC0_PLLMR1
1999! Output r3 = none
2000!-----------------------------------------------------------------------------
2001*/
2002pll_write:
wdenk57b2d802003-06-27 21:31:46 +00002003 mfdcr r5, CPC0_UCR
2004 andis. r5,r5,0xFFFF
Wolfgang Denka1be4762008-05-20 16:00:29 +02002005 ori r5,r5,0x0101 /* Stop the UART clocks */
2006 mtdcr CPC0_UCR,r5 /* Before changing PLL */
stroese434979e2003-05-23 11:18:02 +00002007
wdenk57b2d802003-06-27 21:31:46 +00002008 mfdcr r5, CPC0_PLLMR1
Wolfgang Denka1be4762008-05-20 16:00:29 +02002009 rlwinm r5,r5,0,0x7FFFFFFF /* Disable PLL */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02002010 mtdcr CPC0_PLLMR1,r5
Wolfgang Denka1be4762008-05-20 16:00:29 +02002011 oris r5,r5,0x4000 /* Set PLL Reset */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02002012 mtdcr CPC0_PLLMR1,r5
stroese434979e2003-05-23 11:18:02 +00002013
Wolfgang Denka1be4762008-05-20 16:00:29 +02002014 mtdcr CPC0_PLLMR0,r3 /* Set clock dividers */
2015 rlwinm r5,r4,0,0x3FFFFFFF /* Reset & Bypass new PLL dividers */
2016 oris r5,r5,0x4000 /* Set PLL Reset */
2017 mtdcr CPC0_PLLMR1,r5 /* Set clock dividers */
2018 rlwinm r5,r5,0,0xBFFFFFFF /* Clear PLL Reset */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02002019 mtdcr CPC0_PLLMR1,r5
stroese434979e2003-05-23 11:18:02 +00002020
2021 /*
wdenk57b2d802003-06-27 21:31:46 +00002022 ! Wait min of 100us for PLL to lock.
2023 ! See CMOS 27E databook for more info.
2024 ! At 200MHz, that means waiting 20,000 instructions
stroese434979e2003-05-23 11:18:02 +00002025 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02002026 addi r3,0,20000 /* 2000 = 0x4e20 */
2027 mtctr r3
stroese434979e2003-05-23 11:18:02 +00002028pll_wait:
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02002029 bdnz pll_wait
stroese434979e2003-05-23 11:18:02 +00002030
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02002031 oris r5,r5,0x8000 /* Enable PLL */
2032 mtdcr CPC0_PLLMR1,r5 /* Engage */
stroese434979e2003-05-23 11:18:02 +00002033
wdenk57b2d802003-06-27 21:31:46 +00002034 /*
2035 * Reset CPU to guarantee timings are OK
2036 * Not sure if this is needed...
2037 */
2038 addis r3,0,0x1000
Wolfgang Denka1be4762008-05-20 16:00:29 +02002039 mtspr dbcr0,r3 /* This will cause a CPU core reset, and */
2040 /* execution will continue from the poweron */
2041 /* vector of 0xfffffffc */
stroese434979e2003-05-23 11:18:02 +00002042#endif /* CONFIG_405EP */
Stefan Roesea8856e32007-02-20 10:57:08 +01002043
2044#if defined(CONFIG_440)
Stefan Roesea8856e32007-02-20 10:57:08 +01002045/*----------------------------------------------------------------------------+
2046| mttlb3.
2047+----------------------------------------------------------------------------*/
2048 function_prolog(mttlb3)
2049 TLBWE(4,3,2)
2050 blr
2051 function_epilog(mttlb3)
2052
2053/*----------------------------------------------------------------------------+
2054| mftlb3.
2055+----------------------------------------------------------------------------*/
2056 function_prolog(mftlb3)
Wolfgang Denk52232fd2007-02-27 14:26:04 +01002057 TLBRE(3,3,2)
Stefan Roesea8856e32007-02-20 10:57:08 +01002058 blr
2059 function_epilog(mftlb3)
2060
2061/*----------------------------------------------------------------------------+
2062| mttlb2.
2063+----------------------------------------------------------------------------*/
2064 function_prolog(mttlb2)
2065 TLBWE(4,3,1)
2066 blr
2067 function_epilog(mttlb2)
2068
2069/*----------------------------------------------------------------------------+
2070| mftlb2.
2071+----------------------------------------------------------------------------*/
2072 function_prolog(mftlb2)
Wolfgang Denk52232fd2007-02-27 14:26:04 +01002073 TLBRE(3,3,1)
Stefan Roesea8856e32007-02-20 10:57:08 +01002074 blr
2075 function_epilog(mftlb2)
2076
2077/*----------------------------------------------------------------------------+
2078| mttlb1.
2079+----------------------------------------------------------------------------*/
2080 function_prolog(mttlb1)
2081 TLBWE(4,3,0)
2082 blr
2083 function_epilog(mttlb1)
2084
2085/*----------------------------------------------------------------------------+
2086| mftlb1.
2087+----------------------------------------------------------------------------*/
2088 function_prolog(mftlb1)
Wolfgang Denk52232fd2007-02-27 14:26:04 +01002089 TLBRE(3,3,0)
Stefan Roesea8856e32007-02-20 10:57:08 +01002090 blr
2091 function_epilog(mftlb1)
2092#endif /* CONFIG_440 */
Stefan Roese7d72e022008-06-02 14:35:44 +02002093
2094#if defined(CONFIG_NAND_SPL)
2095/*
2096 * void nand_boot_relocate(dst, src, bytes)
2097 *
2098 * r3 = Destination address to copy code to (in SDRAM)
2099 * r4 = Source address to copy code from
2100 * r5 = size to copy in bytes
2101 */
2102nand_boot_relocate:
2103 mr r6,r3
2104 mr r7,r4
2105 mflr r8
2106
2107 /*
2108 * Copy SPL from icache into SDRAM
2109 */
2110 subi r3,r3,4
2111 subi r4,r4,4
2112 srwi r5,r5,2
2113 mtctr r5
2114..spl_loop:
2115 lwzu r0,4(r4)
2116 stwu r0,4(r3)
2117 bdnz ..spl_loop
2118
2119 /*
2120 * Calculate "corrected" link register, so that we "continue"
2121 * in execution in destination range
2122 */
2123 sub r3,r7,r6 /* r3 = src - dst */
2124 sub r8,r8,r3 /* r8 = link-reg - (src - dst) */
2125 mtlr r8
2126 blr
2127
2128nand_boot_common:
2129 /*
2130 * First initialize SDRAM. It has to be available *before* calling
2131 * nand_boot().
2132 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02002133 lis r3,CONFIG_SYS_SDRAM_BASE@h
2134 ori r3,r3,CONFIG_SYS_SDRAM_BASE@l
Stefan Roese7d72e022008-06-02 14:35:44 +02002135 bl initdram
2136
2137 /*
2138 * Now copy the 4k SPL code into SDRAM and continue execution
2139 * from there.
2140 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02002141 lis r3,CONFIG_SYS_NAND_BOOT_SPL_DST@h
2142 ori r3,r3,CONFIG_SYS_NAND_BOOT_SPL_DST@l
2143 lis r4,CONFIG_SYS_NAND_BOOT_SPL_SRC@h
2144 ori r4,r4,CONFIG_SYS_NAND_BOOT_SPL_SRC@l
2145 lis r5,CONFIG_SYS_NAND_BOOT_SPL_SIZE@h
2146 ori r5,r5,CONFIG_SYS_NAND_BOOT_SPL_SIZE@l
Stefan Roese7d72e022008-06-02 14:35:44 +02002147 bl nand_boot_relocate
2148
2149 /*
2150 * We're running from SDRAM now!!!
2151 *
2152 * It is necessary for 4xx systems to relocate from running at
2153 * the original location (0xfffffxxx) to somewhere else (SDRAM
2154 * preferably). This is because CS0 needs to be reconfigured for
2155 * NAND access. And we can't reconfigure this CS when currently
2156 * "running" from it.
2157 */
2158
2159 /*
2160 * Finally call nand_boot() to load main NAND U-Boot image from
2161 * NAND and jump to it.
2162 */
2163 bl nand_boot /* will not return */
2164#endif /* CONFIG_NAND_SPL */