blob: 582c781cacf66436b92d4597ddfb7a12f9e765a4 [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>
Peter Tyser62948502008-11-03 09:30:59 -060066#include <timestamp.h>
wdenk0442ed82002-11-03 10:24:00 +000067#include <version.h>
68
69#define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
70
71#include <ppc_asm.tmpl>
72#include <ppc_defs.h>
73
74#include <asm/cache.h>
75#include <asm/mmu.h>
Dave Mitchell3c3734172008-11-20 14:00:49 -060076#include <asm/ppc4xx-isram.h>
wdenk0442ed82002-11-03 10:24:00 +000077
78#ifndef CONFIG_IDENT_STRING
79#define CONFIG_IDENT_STRING ""
80#endif
81
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020082#ifdef CONFIG_SYS_INIT_DCACHE_CS
83# if (CONFIG_SYS_INIT_DCACHE_CS == 0)
wdenk0442ed82002-11-03 10:24:00 +000084# define PBxAP pb0ap
85# define PBxCR pb0cr
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020086# if (defined(CONFIG_SYS_EBC_PB0AP) && defined(CONFIG_SYS_EBC_PB0CR))
87# define PBxAP_VAL CONFIG_SYS_EBC_PB0AP
88# define PBxCR_VAL CONFIG_SYS_EBC_PB0CR
Grant Ericksonb6933412008-05-22 14:44:14 -070089# endif
wdenk0442ed82002-11-03 10:24:00 +000090# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020091# if (CONFIG_SYS_INIT_DCACHE_CS == 1)
wdenk0442ed82002-11-03 10:24:00 +000092# define PBxAP pb1ap
93# define PBxCR pb1cr
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020094# if (defined(CONFIG_SYS_EBC_PB1AP) && defined(CONFIG_SYS_EBC_PB1CR))
95# define PBxAP_VAL CONFIG_SYS_EBC_PB1AP
96# define PBxCR_VAL CONFIG_SYS_EBC_PB1CR
Grant Ericksonb6933412008-05-22 14:44:14 -070097# endif
wdenk0442ed82002-11-03 10:24:00 +000098# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020099# if (CONFIG_SYS_INIT_DCACHE_CS == 2)
wdenk0442ed82002-11-03 10:24:00 +0000100# define PBxAP pb2ap
101# define PBxCR pb2cr
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200102# if (defined(CONFIG_SYS_EBC_PB2AP) && defined(CONFIG_SYS_EBC_PB2CR))
103# define PBxAP_VAL CONFIG_SYS_EBC_PB2AP
104# define PBxCR_VAL CONFIG_SYS_EBC_PB2CR
Grant Ericksonb6933412008-05-22 14:44:14 -0700105# endif
wdenk0442ed82002-11-03 10:24:00 +0000106# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200107# if (CONFIG_SYS_INIT_DCACHE_CS == 3)
wdenk0442ed82002-11-03 10:24:00 +0000108# define PBxAP pb3ap
109# define PBxCR pb3cr
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200110# if (defined(CONFIG_SYS_EBC_PB3AP) && defined(CONFIG_SYS_EBC_PB3CR))
111# define PBxAP_VAL CONFIG_SYS_EBC_PB3AP
112# define PBxCR_VAL CONFIG_SYS_EBC_PB3CR
Grant Ericksonb6933412008-05-22 14:44:14 -0700113# endif
wdenk0442ed82002-11-03 10:24:00 +0000114# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200115# if (CONFIG_SYS_INIT_DCACHE_CS == 4)
wdenk0442ed82002-11-03 10:24:00 +0000116# define PBxAP pb4ap
117# define PBxCR pb4cr
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200118# if (defined(CONFIG_SYS_EBC_PB4AP) && defined(CONFIG_SYS_EBC_PB4CR))
119# define PBxAP_VAL CONFIG_SYS_EBC_PB4AP
120# define PBxCR_VAL CONFIG_SYS_EBC_PB4CR
Grant Ericksonb6933412008-05-22 14:44:14 -0700121# endif
wdenk0442ed82002-11-03 10:24:00 +0000122# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200123# if (CONFIG_SYS_INIT_DCACHE_CS == 5)
wdenk0442ed82002-11-03 10:24:00 +0000124# define PBxAP pb5ap
125# define PBxCR pb5cr
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200126# if (defined(CONFIG_SYS_EBC_PB5AP) && defined(CONFIG_SYS_EBC_PB5CR))
127# define PBxAP_VAL CONFIG_SYS_EBC_PB5AP
128# define PBxCR_VAL CONFIG_SYS_EBC_PB5CR
Grant Ericksonb6933412008-05-22 14:44:14 -0700129# endif
wdenk0442ed82002-11-03 10:24:00 +0000130# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200131# if (CONFIG_SYS_INIT_DCACHE_CS == 6)
wdenk0442ed82002-11-03 10:24:00 +0000132# define PBxAP pb6ap
133# define PBxCR pb6cr
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200134# if (defined(CONFIG_SYS_EBC_PB6AP) && defined(CONFIG_SYS_EBC_PB6CR))
135# define PBxAP_VAL CONFIG_SYS_EBC_PB6AP
136# define PBxCR_VAL CONFIG_SYS_EBC_PB6CR
Grant Ericksonb6933412008-05-22 14:44:14 -0700137# endif
wdenk0442ed82002-11-03 10:24:00 +0000138# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200139# if (CONFIG_SYS_INIT_DCACHE_CS == 7)
wdenk0442ed82002-11-03 10:24:00 +0000140# define PBxAP pb7ap
141# define PBxCR pb7cr
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200142# if (defined(CONFIG_SYS_EBC_PB7AP) && defined(CONFIG_SYS_EBC_PB7CR))
143# define PBxAP_VAL CONFIG_SYS_EBC_PB7AP
144# define PBxCR_VAL CONFIG_SYS_EBC_PB7CR
Grant Ericksonb6933412008-05-22 14:44:14 -0700145# endif
146# endif
147# ifndef PBxAP_VAL
148# define PBxAP_VAL 0
149# endif
150# ifndef PBxCR_VAL
151# define PBxCR_VAL 0
152# endif
153/*
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200154 * Memory Bank x (nothingness) initialization CONFIG_SYS_INIT_RAM_ADDR + 64 MiB
Grant Ericksonb6933412008-05-22 14:44:14 -0700155 * used as temporary stack pointer for the primordial stack
156 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200157# ifndef CONFIG_SYS_INIT_DCACHE_PBxAR
158# define CONFIG_SYS_INIT_DCACHE_PBxAR (EBC_BXAP_BME_DISABLED | \
Grant Ericksonb6933412008-05-22 14:44:14 -0700159 EBC_BXAP_TWT_ENCODE(7) | \
160 EBC_BXAP_BCE_DISABLE | \
161 EBC_BXAP_BCT_2TRANS | \
162 EBC_BXAP_CSN_ENCODE(0) | \
163 EBC_BXAP_OEN_ENCODE(0) | \
164 EBC_BXAP_WBN_ENCODE(0) | \
165 EBC_BXAP_WBF_ENCODE(0) | \
166 EBC_BXAP_TH_ENCODE(2) | \
167 EBC_BXAP_RE_DISABLED | \
168 EBC_BXAP_SOR_NONDELAYED | \
169 EBC_BXAP_BEM_WRITEONLY | \
170 EBC_BXAP_PEN_DISABLED)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200171# endif /* CONFIG_SYS_INIT_DCACHE_PBxAR */
172# ifndef CONFIG_SYS_INIT_DCACHE_PBxCR
173# define CONFIG_SYS_INIT_DCACHE_PBxCR (EBC_BXCR_BAS_ENCODE(CONFIG_SYS_INIT_RAM_ADDR) | \
Grant Ericksonb6933412008-05-22 14:44:14 -0700174 EBC_BXCR_BS_64MB | \
175 EBC_BXCR_BU_RW | \
176 EBC_BXCR_BW_16BIT)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200177# endif /* CONFIG_SYS_INIT_DCACHE_PBxCR */
178# ifndef CONFIG_SYS_INIT_RAM_PATTERN
179# define CONFIG_SYS_INIT_RAM_PATTERN 0xDEADDEAD
wdenk0442ed82002-11-03 10:24:00 +0000180# endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200181#endif /* CONFIG_SYS_INIT_DCACHE_CS */
wdenk0442ed82002-11-03 10:24:00 +0000182
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200183#if (defined(CONFIG_SYS_INIT_RAM_DCACHE) && (CONFIG_SYS_INIT_RAM_END > (4 << 10)))
184#error Only 4k of init-ram is supported - please adjust CONFIG_SYS_INIT_RAM_END!
Stefan Roese0fb8ab92008-01-30 14:48:28 +0100185#endif
186
Grant Ericksonb6933412008-05-22 14:44:14 -0700187/*
188 * Unless otherwise overriden, enable two 128MB cachable instruction regions
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200189 * at CONFIG_SYS_SDRAM_BASE and another 128MB cacheable instruction region covering
190 * NOR flash at CONFIG_SYS_FLASH_BASE. Disable all cacheable data regions.
Grant Ericksonb6933412008-05-22 14:44:14 -0700191 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200192#if !defined(CONFIG_SYS_FLASH_BASE)
Stefan Roese7d72e022008-06-02 14:35:44 +0200193/* If not already defined, set it to the "last" 128MByte region */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200194# define CONFIG_SYS_FLASH_BASE 0xf8000000
Stefan Roese7d72e022008-06-02 14:35:44 +0200195#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200196#if !defined(CONFIG_SYS_ICACHE_SACR_VALUE)
197# define CONFIG_SYS_ICACHE_SACR_VALUE \
198 (PPC_128MB_SACR_VALUE(CONFIG_SYS_SDRAM_BASE + ( 0 << 20)) | \
199 PPC_128MB_SACR_VALUE(CONFIG_SYS_SDRAM_BASE + (128 << 20)) | \
200 PPC_128MB_SACR_VALUE(CONFIG_SYS_FLASH_BASE))
201#endif /* !defined(CONFIG_SYS_ICACHE_SACR_VALUE) */
Grant Ericksonb6933412008-05-22 14:44:14 -0700202
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200203#if !defined(CONFIG_SYS_DCACHE_SACR_VALUE)
204# define CONFIG_SYS_DCACHE_SACR_VALUE \
Grant Ericksonb6933412008-05-22 14:44:14 -0700205 (0x00000000)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200206#endif /* !defined(CONFIG_SYS_DCACHE_SACR_VALUE) */
Grant Ericksonb6933412008-05-22 14:44:14 -0700207
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200208#define function_prolog(func_name) .text; \
Stefan Roese42743512007-06-01 15:27:11 +0200209 .align 2; \
210 .globl func_name; \
211 func_name:
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200212#define function_epilog(func_name) .type func_name,@function; \
Stefan Roese42743512007-06-01 15:27:11 +0200213 .size func_name,.-func_name
214
wdenk0442ed82002-11-03 10:24:00 +0000215/* We don't want the MMU yet.
216*/
217#undef MSR_KERNEL
218#define MSR_KERNEL ( MSR_ME ) /* Machine Check */
219
220
221 .extern ext_bus_cntlr_init
Stefan Roese42fbddd2006-09-07 11:51:23 +0200222#ifdef CONFIG_NAND_U_BOOT
223 .extern reconfig_tlb0
224#endif
wdenk0442ed82002-11-03 10:24:00 +0000225
226/*
227 * Set up GOT: Global Offset Table
228 *
229 * Use r14 to access the GOT
230 */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200231#if !defined(CONFIG_NAND_SPL)
wdenk0442ed82002-11-03 10:24:00 +0000232 START_GOT
233 GOT_ENTRY(_GOT2_TABLE_)
234 GOT_ENTRY(_FIXUP_TABLE_)
235
236 GOT_ENTRY(_start)
237 GOT_ENTRY(_start_of_vectors)
238 GOT_ENTRY(_end_of_vectors)
239 GOT_ENTRY(transfer_to_handler)
240
wdenkb9a83a92003-05-30 12:48:29 +0000241 GOT_ENTRY(__init_end)
wdenk0442ed82002-11-03 10:24:00 +0000242 GOT_ENTRY(_end)
wdenkbf2f8c92003-05-22 22:52:13 +0000243 GOT_ENTRY(__bss_start)
wdenk0442ed82002-11-03 10:24:00 +0000244 END_GOT
Stefan Roese42fbddd2006-09-07 11:51:23 +0200245#endif /* CONFIG_NAND_SPL */
246
247#if defined(CONFIG_NAND_U_BOOT) && !defined(CONFIG_NAND_SPL)
248 /*
249 * NAND U-Boot image is started from offset 0
250 */
251 .text
Stefan Roese23d8d342007-06-06 11:42:13 +0200252#if defined(CONFIG_440)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200253 bl reconfig_tlb0
Stefan Roese23d8d342007-06-06 11:42:13 +0200254#endif
Stefan Roese42fbddd2006-09-07 11:51:23 +0200255 GET_GOT
256 bl cpu_init_f /* run low-level CPU init code (from Flash) */
257 bl board_init_f
258#endif
wdenk0442ed82002-11-03 10:24:00 +0000259
Stefan Roesec20ef322009-05-11 13:46:14 +0200260#if defined(CONFIG_SYS_RAMBOOT)
261 /*
262 * 4xx RAM-booting U-Boot image is started from offset 0
263 */
264 .text
265 bl _start_440
266#endif
267
wdenk0442ed82002-11-03 10:24:00 +0000268/*
269 * 440 Startup -- on reset only the top 4k of the effective
270 * address space is mapped in by an entry in the instruction
271 * and data shadow TLB. The .bootpg section is located in the
272 * top 4k & does only what's necessary to map in the the rest
273 * of the boot rom. Once the boot rom is mapped in we can
274 * proceed with normal startup.
275 *
276 * NOTE: CS0 only covers the top 2MB of the effective address
277 * space after reset.
278 */
279
280#if defined(CONFIG_440)
Stefan Roese42fbddd2006-09-07 11:51:23 +0200281#if !defined(CONFIG_NAND_SPL)
wdenk0442ed82002-11-03 10:24:00 +0000282 .section .bootpg,"ax"
Stefan Roese42fbddd2006-09-07 11:51:23 +0200283#endif
wdenk0442ed82002-11-03 10:24:00 +0000284 .globl _start_440
285
286/**************************************************************************/
287_start_440:
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200288 /*--------------------------------------------------------------------+
289 | 440EPX BUP Change - Hardware team request
290 +--------------------------------------------------------------------*/
Stefan Roese42fbddd2006-09-07 11:51:23 +0200291#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
292 sync
293 nop
294 nop
295#endif
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200296 /*----------------------------------------------------------------+
297 | Core bug fix. Clear the esr
298 +-----------------------------------------------------------------*/
Marian Balakowiczbe9463b2006-07-06 21:17:24 +0200299 li r0,0
Wolfgang Denkba940932006-07-19 13:50:38 +0200300 mtspr esr,r0
wdenk0442ed82002-11-03 10:24:00 +0000301 /*----------------------------------------------------------------*/
302 /* Clear and set up some registers. */
303 /*----------------------------------------------------------------*/
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200304 iccci r0,r0 /* NOTE: operands not used for 440 */
305 dccci r0,r0 /* NOTE: operands not used for 440 */
wdenk0442ed82002-11-03 10:24:00 +0000306 sync
307 li r0,0
308 mtspr srr0,r0
309 mtspr srr1,r0
310 mtspr csrr0,r0
311 mtspr csrr1,r0
Stefan Roese42fbddd2006-09-07 11:51:23 +0200312 /* NOTE: 440GX adds machine check status regs */
313#if defined(CONFIG_440) && !defined(CONFIG_440GP)
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200314 mtspr mcsrr0,r0
315 mtspr mcsrr1,r0
Stefan Roese42fbddd2006-09-07 11:51:23 +0200316 mfspr r1,mcsr
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200317 mtspr mcsr,r1
wdenk544e9732004-02-06 23:19:44 +0000318#endif
Stefan Roese0100cc12006-11-22 13:20:50 +0100319
320 /*----------------------------------------------------------------*/
321 /* CCR0 init */
322 /*----------------------------------------------------------------*/
323 /* Disable store gathering & broadcast, guarantee inst/data
324 * cache block touch, force load/store alignment
325 * (see errata 1.12: 440_33)
326 */
327 lis r1,0x0030 /* store gathering & broadcast disable */
328 ori r1,r1,0x6000 /* cache touch */
329 mtspr ccr0,r1
330
wdenk0442ed82002-11-03 10:24:00 +0000331 /*----------------------------------------------------------------*/
332 /* Initialize debug */
333 /*----------------------------------------------------------------*/
Stefan Roese42fbddd2006-09-07 11:51:23 +0200334 mfspr r1,dbcr0
335 andis. r1, r1, 0x8000 /* test DBCR0[EDM] bit */
336 bne skip_debug_init /* if set, don't clear debug register */
wdenk0442ed82002-11-03 10:24:00 +0000337 mtspr dbcr0,r0
338 mtspr dbcr1,r0
339 mtspr dbcr2,r0
340 mtspr iac1,r0
341 mtspr iac2,r0
342 mtspr iac3,r0
343 mtspr dac1,r0
344 mtspr dac2,r0
345 mtspr dvc1,r0
346 mtspr dvc2,r0
347
348 mfspr r1,dbsr
349 mtspr dbsr,r1 /* Clear all valid bits */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200350skip_debug_init:
wdenk0442ed82002-11-03 10:24:00 +0000351
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200352#if defined (CONFIG_440SPE)
353 /*----------------------------------------------------------------+
354 | Initialize Core Configuration Reg1.
355 | a. ICDPEI: Record even parity. Normal operation.
356 | b. ICTPEI: Record even parity. Normal operation.
357 | c. DCTPEI: Record even parity. Normal operation.
358 | d. DCDPEI: Record even parity. Normal operation.
359 | e. DCUPEI: Record even parity. Normal operation.
360 | f. DCMPEI: Record even parity. Normal operation.
361 | g. FCOM: Normal operation
362 | h. MMUPEI: Record even parity. Normal operation.
363 | i. FFF: Flush only as much data as necessary.
Marian Balakowiczbe9463b2006-07-06 21:17:24 +0200364 | j. TCS: Timebase increments from CPU clock.
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200365 +-----------------------------------------------------------------*/
Marian Balakowiczbe9463b2006-07-06 21:17:24 +0200366 li r0,0
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200367 mtspr ccr1, r0
368
369 /*----------------------------------------------------------------+
370 | Reset the timebase.
371 | The previous write to CCR1 sets the timebase source.
372 +-----------------------------------------------------------------*/
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200373 mtspr tbl, r0
374 mtspr tbu, r0
375#endif
376
wdenk0442ed82002-11-03 10:24:00 +0000377 /*----------------------------------------------------------------*/
378 /* Setup interrupt vectors */
379 /*----------------------------------------------------------------*/
380 mtspr ivpr,r0 /* Vectors start at 0x0000_0000 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200381 li r1,0x0100
wdenk0442ed82002-11-03 10:24:00 +0000382 mtspr ivor0,r1 /* Critical input */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200383 li r1,0x0200
wdenk0442ed82002-11-03 10:24:00 +0000384 mtspr ivor1,r1 /* Machine check */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200385 li r1,0x0300
wdenk0442ed82002-11-03 10:24:00 +0000386 mtspr ivor2,r1 /* Data storage */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200387 li r1,0x0400
wdenk0442ed82002-11-03 10:24:00 +0000388 mtspr ivor3,r1 /* Instruction storage */
389 li r1,0x0500
390 mtspr ivor4,r1 /* External interrupt */
391 li r1,0x0600
392 mtspr ivor5,r1 /* Alignment */
393 li r1,0x0700
394 mtspr ivor6,r1 /* Program check */
395 li r1,0x0800
396 mtspr ivor7,r1 /* Floating point unavailable */
397 li r1,0x0c00
398 mtspr ivor8,r1 /* System call */
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200399 li r1,0x0a00
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200400 mtspr ivor9,r1 /* Auxiliary Processor unavailable */
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200401 li r1,0x0900
402 mtspr ivor10,r1 /* Decrementer */
wdenk0442ed82002-11-03 10:24:00 +0000403 li r1,0x1300
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200404 mtspr ivor13,r1 /* Data TLB error */
405 li r1,0x1400
wdenk0442ed82002-11-03 10:24:00 +0000406 mtspr ivor14,r1 /* Instr TLB error */
407 li r1,0x2000
408 mtspr ivor15,r1 /* Debug */
409
410 /*----------------------------------------------------------------*/
411 /* Configure cache regions */
412 /*----------------------------------------------------------------*/
413 mtspr inv0,r0
414 mtspr inv1,r0
415 mtspr inv2,r0
416 mtspr inv3,r0
417 mtspr dnv0,r0
418 mtspr dnv1,r0
419 mtspr dnv2,r0
420 mtspr dnv3,r0
421 mtspr itv0,r0
422 mtspr itv1,r0
423 mtspr itv2,r0
424 mtspr itv3,r0
425 mtspr dtv0,r0
426 mtspr dtv1,r0
427 mtspr dtv2,r0
428 mtspr dtv3,r0
429
430 /*----------------------------------------------------------------*/
431 /* Cache victim limits */
432 /*----------------------------------------------------------------*/
433 /* floors 0, ceiling max to use the entire cache -- nothing locked
434 */
435 lis r1,0x0001
436 ori r1,r1,0xf800
437 mtspr ivlim,r1
438 mtspr dvlim,r1
439
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200440 /*----------------------------------------------------------------+
441 |Initialize MMUCR[STID] = 0.
442 +-----------------------------------------------------------------*/
443 mfspr r0,mmucr
444 addis r1,0,0xFFFF
445 ori r1,r1,0xFF00
446 and r0,r0,r1
447 mtspr mmucr,r0
448
wdenk0442ed82002-11-03 10:24:00 +0000449 /*----------------------------------------------------------------*/
450 /* Clear all TLB entries -- TID = 0, TS = 0 */
451 /*----------------------------------------------------------------*/
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200452 addis r0,0,0x0000
wdenk0442ed82002-11-03 10:24:00 +0000453 li r1,0x003f /* 64 TLB entries */
454 mtctr r1
Stefan Roesec20ef322009-05-11 13:46:14 +0200455 li r4,0 /* Start with TLB #0 */
456rsttlb:
457#ifdef CONFIG_SYS_RAMBOOT
458 tlbre r3,r4,0 /* Read contents from TLB word #0 to get EPN */
459 rlwinm. r3,r3,0,0xfffffc00 /* Mask EPN */
460 beq tlbnxt /* Skip EPN=0 TLB, this is the SDRAM TLB */
461#endif
462 tlbwe r0,r4,0 /* Invalidate all entries (V=0)*/
463 tlbwe r0,r4,1
464 tlbwe r0,r4,2
465tlbnxt: addi r4,r4,1 /* Next TLB */
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200466 bdnz rsttlb
wdenk0442ed82002-11-03 10:24:00 +0000467
468 /*----------------------------------------------------------------*/
469 /* TLB entry setup -- step thru tlbtab */
470 /*----------------------------------------------------------------*/
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200471#if defined(CONFIG_440SPE)
472 /*----------------------------------------------------------------*/
473 /* We have different TLB tables for revA and rev B of 440SPe */
474 /*----------------------------------------------------------------*/
475 mfspr r1, PVR
476 lis r0,0x5342
477 ori r0,r0,0x1891
478 cmpw r7,r1,r0
479 bne r7,..revA
480 bl tlbtabB
481 b ..goon
482..revA:
483 bl tlbtabA
484..goon:
485#else
wdenk0442ed82002-11-03 10:24:00 +0000486 bl tlbtab /* Get tlbtab pointer */
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200487#endif
wdenk0442ed82002-11-03 10:24:00 +0000488 mr r5,r0
489 li r1,0x003f /* 64 TLB entries max */
490 mtctr r1
491 li r4,0 /* TLB # */
492
493 addi r5,r5,-4
Stefan Roesec20ef322009-05-11 13:46:14 +02004941:
495#ifdef CONFIG_SYS_RAMBOOT
496 tlbre r3,r4,0 /* Read contents from TLB word #0 */
497 rlwinm. r3,r3,0,0x00000200 /* Mask V (valid) bit */
498 bne tlbnx2 /* Skip V=1 TLB, this is the SDRAM TLB */
499#endif
500 lwzu r0,4(r5)
wdenk0442ed82002-11-03 10:24:00 +0000501 cmpwi r0,0
502 beq 2f /* 0 marks end */
503 lwzu r1,4(r5)
504 lwzu r2,4(r5)
505 tlbwe r0,r4,0 /* TLB Word 0 */
506 tlbwe r1,r4,1 /* TLB Word 1 */
507 tlbwe r2,r4,2 /* TLB Word 2 */
Stefan Roesec20ef322009-05-11 13:46:14 +0200508tlbnx2: addi r4,r4,1 /* Next TLB */
wdenk0442ed82002-11-03 10:24:00 +0000509 bdnz 1b
510
511 /*----------------------------------------------------------------*/
512 /* Continue from 'normal' start */
513 /*----------------------------------------------------------------*/
Stefan Roese42fbddd2006-09-07 11:51:23 +02005142:
Stefan Roese42fbddd2006-09-07 11:51:23 +0200515 bl 3f
wdenk0442ed82002-11-03 10:24:00 +0000516 b _start
517
5183: li r0,0
519 mtspr srr1,r0 /* Keep things disabled for now */
520 mflr r1
521 mtspr srr0,r1
522 rfi
stroese434979e2003-05-23 11:18:02 +0000523#endif /* CONFIG_440 */
wdenk0442ed82002-11-03 10:24:00 +0000524
525/*
526 * r3 - 1st arg to board_init(): IMMP pointer
527 * r4 - 2nd arg to board_init(): boot flag
528 */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200529#ifndef CONFIG_NAND_SPL
wdenk0442ed82002-11-03 10:24:00 +0000530 .text
531 .long 0x27051956 /* U-Boot Magic Number */
532 .globl version_string
533version_string:
534 .ascii U_BOOT_VERSION
Peter Tyser62948502008-11-03 09:30:59 -0600535 .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
wdenk0442ed82002-11-03 10:24:00 +0000536 .ascii CONFIG_IDENT_STRING, "\0"
537
wdenk0442ed82002-11-03 10:24:00 +0000538 . = EXC_OFF_SYS_RESET
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200539 .globl _start_of_vectors
540_start_of_vectors:
541
542/* Critical input. */
543 CRIT_EXCEPTION(0x100, CritcalInput, UnknownException)
544
545#ifdef CONFIG_440
546/* Machine check */
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200547 MCK_EXCEPTION(0x200, MachineCheck, MachineCheckException)
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200548#else
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200549 CRIT_EXCEPTION(0x200, MachineCheck, MachineCheckException)
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200550#endif /* CONFIG_440 */
551
552/* Data Storage exception. */
553 STD_EXCEPTION(0x300, DataStorage, UnknownException)
554
555/* Instruction Storage exception. */
556 STD_EXCEPTION(0x400, InstStorage, UnknownException)
557
558/* External Interrupt exception. */
559 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
560
561/* Alignment exception. */
562 . = 0x600
563Alignment:
564 EXCEPTION_PROLOG(SRR0, SRR1)
565 mfspr r4,DAR
566 stw r4,_DAR(r21)
567 mfspr r5,DSISR
568 stw r5,_DSISR(r21)
569 addi r3,r1,STACK_FRAME_OVERHEAD
570 li r20,MSR_KERNEL
571 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
572 lwz r6,GOT(transfer_to_handler)
573 mtlr r6
574 blrl
575.L_Alignment:
576 .long AlignmentException - _start + _START_OFFSET
577 .long int_return - _start + _START_OFFSET
578
579/* Program check exception */
580 . = 0x700
581ProgramCheck:
582 EXCEPTION_PROLOG(SRR0, SRR1)
583 addi r3,r1,STACK_FRAME_OVERHEAD
584 li r20,MSR_KERNEL
585 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
586 lwz r6,GOT(transfer_to_handler)
587 mtlr r6
588 blrl
589.L_ProgramCheck:
590 .long ProgramCheckException - _start + _START_OFFSET
591 .long int_return - _start + _START_OFFSET
592
593#ifdef CONFIG_440
594 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
595 STD_EXCEPTION(0x900, Decrementer, DecrementerPITException)
596 STD_EXCEPTION(0xa00, APU, UnknownException)
Stefan Roese80d99a42007-06-19 16:42:31 +0200597#endif
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200598 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
599
600#ifdef CONFIG_440
601 STD_EXCEPTION(0x1300, DataTLBError, UnknownException)
602 STD_EXCEPTION(0x1400, InstructionTLBError, UnknownException)
603#else
604 STD_EXCEPTION(0x1000, PIT, DecrementerPITException)
605 STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
606 STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
607#endif
608 CRIT_EXCEPTION(0x2000, DebugBreakpoint, DebugException )
609
610 .globl _end_of_vectors
611_end_of_vectors:
612 . = _START_OFFSET
Stefan Roese42fbddd2006-09-07 11:51:23 +0200613#endif
wdenk0442ed82002-11-03 10:24:00 +0000614 .globl _start
615_start:
616
617/*****************************************************************************/
618#if defined(CONFIG_440)
619
620 /*----------------------------------------------------------------*/
621 /* Clear and set up some registers. */
622 /*----------------------------------------------------------------*/
623 li r0,0x0000
624 lis r1,0xffff
625 mtspr dec,r0 /* prevent dec exceptions */
626 mtspr tbl,r0 /* prevent fit & wdt exceptions */
627 mtspr tbu,r0
628 mtspr tsr,r1 /* clear all timer exception status */
629 mtspr tcr,r0 /* disable all */
630 mtspr esr,r0 /* clear exception syndrome register */
631 mtxer r0 /* clear integer exception register */
wdenk0442ed82002-11-03 10:24:00 +0000632
633 /*----------------------------------------------------------------*/
634 /* Debug setup -- some (not very good) ice's need an event*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200635 /* to establish control :-( Define CONFIG_SYS_INIT_DBCR to the dbsr */
wdenk0442ed82002-11-03 10:24:00 +0000636 /* value you need in this case 0x8cff 0000 should do the trick */
637 /*----------------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200638#if defined(CONFIG_SYS_INIT_DBCR)
wdenk0442ed82002-11-03 10:24:00 +0000639 lis r1,0xffff
640 ori r1,r1,0xffff
641 mtspr dbsr,r1 /* Clear all status bits */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200642 lis r0,CONFIG_SYS_INIT_DBCR@h
643 ori r0,r0,CONFIG_SYS_INIT_DBCR@l
wdenk0442ed82002-11-03 10:24:00 +0000644 mtspr dbcr0,r0
645 isync
646#endif
647
648 /*----------------------------------------------------------------*/
649 /* Setup the internal SRAM */
650 /*----------------------------------------------------------------*/
651 li r0,0
Stefan Roese42fbddd2006-09-07 11:51:23 +0200652
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200653#ifdef CONFIG_SYS_INIT_RAM_DCACHE
Stefan Roese326c9712005-08-01 16:41:48 +0200654 /* Clear Dcache to use as RAM */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200655 addis r3,r0,CONFIG_SYS_INIT_RAM_ADDR@h
656 ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
657 addis r4,r0,CONFIG_SYS_INIT_RAM_END@h
658 ori r4,r4,CONFIG_SYS_INIT_RAM_END@l
Stefan Roese326c9712005-08-01 16:41:48 +0200659 rlwinm. r5,r4,0,27,31
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200660 rlwinm r5,r4,27,5,31
661 beq ..d_ran
662 addi r5,r5,0x0001
Stefan Roese326c9712005-08-01 16:41:48 +0200663..d_ran:
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200664 mtctr r5
Stefan Roese326c9712005-08-01 16:41:48 +0200665..d_ag:
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200666 dcbz r0,r3
667 addi r3,r3,32
668 bdnz ..d_ag
Stefan Roesea86bde32008-01-09 10:23:16 +0100669
670 /*
671 * Lock the init-ram/stack in d-cache, so that other regions
672 * may use d-cache as well
673 * Note, that this current implementation locks exactly 4k
674 * of d-cache, so please make sure that you don't define a
675 * bigger init-ram area. Take a look at the lwmon5 440EPx
676 * implementation as a reference.
677 */
678 msync
679 isync
680 /* 8. set TFLOOR/NFLOOR to 8 (-> 8*16*32 bytes locked -> 4k) */
681 lis r1,0x0201
682 ori r1,r1,0xf808
683 mtspr dvlim,r1
684 lis r1,0x0808
685 ori r1,r1,0x0808
686 mtspr dnv0,r1
687 mtspr dnv1,r1
688 mtspr dnv2,r1
689 mtspr dnv3,r1
690 mtspr dtv0,r1
691 mtspr dtv1,r1
692 mtspr dtv2,r1
693 mtspr dtv3,r1
694 msync
695 isync
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200696#endif /* CONFIG_SYS_INIT_RAM_DCACHE */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200697
698 /* 440EP & 440GR are only 440er PPC's without internal SRAM */
699#if !defined(CONFIG_440EP) && !defined(CONFIG_440GR)
700 /* not all PPC's have internal SRAM usable as L2-cache */
Stefan Roesecc019d12008-03-11 15:05:50 +0100701#if defined(CONFIG_440GX) || \
702 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Feng Kan224bc962008-07-08 22:47:31 -0700703 defined(CONFIG_460SX)
Dave Mitchell3c3734172008-11-20 14:00:49 -0600704 mtdcr L2_CACHE_CFG,r0 /* Ensure L2 Cache is off */
Dave Mitchell5c057592008-11-20 14:09:50 -0600705#elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
706 lis r1, 0x0000
707 ori r1,r1,0x0008 /* Set L2_CACHE_CFG[RDBW]=1 */
708 mtdcr L2_CACHE_CFG,r1
wdenk544e9732004-02-06 23:19:44 +0000709#endif
wdenk0442ed82002-11-03 10:24:00 +0000710
Stefan Roese42fbddd2006-09-07 11:51:23 +0200711 lis r2,0x7fff
wdenk0442ed82002-11-03 10:24:00 +0000712 ori r2,r2,0xffff
Dave Mitchell3c3734172008-11-20 14:00:49 -0600713 mfdcr r1,ISRAM0_DPC
wdenk0442ed82002-11-03 10:24:00 +0000714 and r1,r1,r2 /* Disable parity check */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600715 mtdcr ISRAM0_DPC,r1
716 mfdcr r1,ISRAM0_PMEG
Stefan Roese42fbddd2006-09-07 11:51:23 +0200717 and r1,r1,r2 /* Disable pwr mgmt */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600718 mtdcr ISRAM0_PMEG,r1
wdenk0442ed82002-11-03 10:24:00 +0000719
720 lis r1,0x8000 /* BAS = 8000_0000 */
Stefan Roese99644742005-11-29 18:18:21 +0100721#if defined(CONFIG_440GX) || defined(CONFIG_440SP)
wdenk544e9732004-02-06 23:19:44 +0000722 ori r1,r1,0x0980 /* first 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600723 mtdcr ISRAM0_SB0CR,r1
wdenk544e9732004-02-06 23:19:44 +0000724 lis r1,0x8001
725 ori r1,r1,0x0980 /* second 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600726 mtdcr ISRAM0_SB1CR,r1
wdenk544e9732004-02-06 23:19:44 +0000727 lis r1, 0x8002
728 ori r1,r1, 0x0980 /* third 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600729 mtdcr ISRAM0_SB2CR,r1
wdenk544e9732004-02-06 23:19:44 +0000730 lis r1, 0x8003
731 ori r1,r1, 0x0980 /* fourth 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600732 mtdcr ISRAM0_SB3CR,r1
Dave Mitchell5c057592008-11-20 14:09:50 -0600733#elif defined(CONFIG_440SPE) || defined(CONFIG_460EX) || defined(CONFIG_460GT)
734 lis r1,0x0000 /* BAS = X_0000_0000 */
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200735 ori r1,r1,0x0984 /* first 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600736 mtdcr ISRAM0_SB0CR,r1
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200737 lis r1,0x0001
738 ori r1,r1,0x0984 /* second 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600739 mtdcr ISRAM0_SB1CR,r1
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200740 lis r1, 0x0002
741 ori r1,r1, 0x0984 /* third 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600742 mtdcr ISRAM0_SB2CR,r1
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200743 lis r1, 0x0003
744 ori r1,r1, 0x0984 /* fourth 64k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600745 mtdcr ISRAM0_SB3CR,r1
Dave Mitchell5c057592008-11-20 14:09:50 -0600746#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
747 lis r2,0x7fff
748 ori r2,r2,0xffff
749 mfdcr r1,ISRAM1_DPC
750 and r1,r1,r2 /* Disable parity check */
Wolfgang Denk55334c72008-12-16 01:02:17 +0100751 mtdcr ISRAM1_DPC,r1
Dave Mitchell5c057592008-11-20 14:09:50 -0600752 mfdcr r1,ISRAM1_PMEG
753 and r1,r1,r2 /* Disable pwr mgmt */
754 mtdcr ISRAM1_PMEG,r1
755
756 lis r1,0x0004 /* BAS = 4_0004_0000 */
757 ori r1,r1,0x0984 /* 64k */
758 mtdcr ISRAM1_SB0CR,r1
759#endif
Feng Kan224bc962008-07-08 22:47:31 -0700760#elif defined(CONFIG_460SX)
761 lis r1,0x0000 /* BAS = 0000_0000 */
762 ori r1,r1,0x0B84 /* first 128k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600763 mtdcr ISRAM0_SB0CR,r1
Feng Kan224bc962008-07-08 22:47:31 -0700764 lis r1,0x0001
765 ori r1,r1,0x0B84 /* second 128k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600766 mtdcr ISRAM0_SB1CR,r1
Feng Kan224bc962008-07-08 22:47:31 -0700767 lis r1, 0x0002
768 ori r1,r1, 0x0B84 /* third 128k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600769 mtdcr ISRAM0_SB2CR,r1
Feng Kan224bc962008-07-08 22:47:31 -0700770 lis r1, 0x0003
771 ori r1,r1, 0x0B84 /* fourth 128k */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600772 mtdcr ISRAM0_SB3CR,r1
Stefan Roese42fbddd2006-09-07 11:51:23 +0200773#elif defined(CONFIG_440GP)
wdenk0442ed82002-11-03 10:24:00 +0000774 ori r1,r1,0x0380 /* 8k rw */
Dave Mitchell3c3734172008-11-20 14:00:49 -0600775 mtdcr ISRAM0_SB0CR,r1
776 mtdcr ISRAM0_SB1CR,r0 /* Disable bank 1 */
Stefan Roese326c9712005-08-01 16:41:48 +0200777#endif
Stefan Roese42fbddd2006-09-07 11:51:23 +0200778#endif /* #if !defined(CONFIG_440EP) && !defined(CONFIG_440GR) */
wdenk0442ed82002-11-03 10:24:00 +0000779
780 /*----------------------------------------------------------------*/
781 /* Setup the stack in internal SRAM */
782 /*----------------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200783 lis r1,CONFIG_SYS_INIT_RAM_ADDR@h
784 ori r1,r1,CONFIG_SYS_INIT_SP_OFFSET@l
wdenk0442ed82002-11-03 10:24:00 +0000785 li r0,0
786 stwu r0,-4(r1)
787 stwu r0,-4(r1) /* Terminate call chain */
788
789 stwu r1,-8(r1) /* Save back chain and move SP */
790 lis r0,RESET_VECTOR@h /* Address of reset vector */
791 ori r0,r0, RESET_VECTOR@l
792 stwu r1,-8(r1) /* Save back chain and move SP */
793 stw r0,+12(r1) /* Save return addr (underflow vect) */
794
Stefan Roese42fbddd2006-09-07 11:51:23 +0200795#ifdef CONFIG_NAND_SPL
Stefan Roese7d72e022008-06-02 14:35:44 +0200796 bl nand_boot_common /* will not return */
Stefan Roese42fbddd2006-09-07 11:51:23 +0200797#else
wdenk0442ed82002-11-03 10:24:00 +0000798 GET_GOT
Stefan Roesec443fe92005-11-22 13:20:42 +0100799
800 bl cpu_init_f /* run low-level CPU init code (from Flash) */
wdenk0442ed82002-11-03 10:24:00 +0000801 bl board_init_f
Stefan Roese42fbddd2006-09-07 11:51:23 +0200802#endif
wdenk0442ed82002-11-03 10:24:00 +0000803
804#endif /* CONFIG_440 */
805
806/*****************************************************************************/
807#ifdef CONFIG_IOP480
808 /*----------------------------------------------------------------------- */
809 /* Set up some machine state registers. */
810 /*----------------------------------------------------------------------- */
811 addi r0,r0,0x0000 /* initialize r0 to zero */
812 mtspr esr,r0 /* clear Exception Syndrome Reg */
813 mttcr r0 /* timer control register */
814 mtexier r0 /* disable all interrupts */
wdenk0442ed82002-11-03 10:24:00 +0000815 addis r4,r0,0xFFFF /* set r4 to 0xFFFFFFFF (status in the */
816 ori r4,r4,0xFFFF /* dbsr is cleared by setting bits to 1) */
817 mtdbsr r4 /* clear/reset the dbsr */
818 mtexisr r4 /* clear all pending interrupts */
819 addis r4,r0,0x8000
820 mtexier r4 /* enable critical exceptions */
821 addis r4,r0,0x0000 /* assume 403GCX - enable core clk */
822 ori r4,r4,0x4020 /* dbling (no harm done on GA and GC */
823 mtiocr r4 /* since bit not used) & DRC to latch */
824 /* data bus on rising edge of CAS */
825 /*----------------------------------------------------------------------- */
826 /* Clear XER. */
827 /*----------------------------------------------------------------------- */
828 mtxer r0
829 /*----------------------------------------------------------------------- */
830 /* Invalidate i-cache and d-cache TAG arrays. */
831 /*----------------------------------------------------------------------- */
832 addi r3,0,1024 /* 1/4 of I-cache size, half of D-cache */
833 addi r4,0,1024 /* 1/4 of I-cache */
834..cloop:
835 iccci 0,r3
836 iccci r4,r3
837 dccci 0,r3
838 addic. r3,r3,-16 /* move back one cache line */
839 bne ..cloop /* loop back to do rest until r3 = 0 */
840
841 /* */
842 /* initialize IOP480 so it can read 1 MB code area for SRAM spaces */
843 /* this requires enabling MA[17..0], by default only MA[12..0] are enabled. */
844 /* */
845
846 /* first copy IOP480 register base address into r3 */
847 addis r3,0,0x5000 /* IOP480 register base address hi */
848/* ori r3,r3,0x0000 / IOP480 register base address lo */
849
850#ifdef CONFIG_ADCIOP
851 /* use r4 as the working variable */
852 /* turn on CS3 (LOCCTL.7) */
853 lwz r4,0x84(r3) /* LOCTL is at offset 0x84 */
854 andi. r4,r4,0xff7f /* make bit 7 = 0 -- CS3 mode */
855 stw r4,0x84(r3) /* LOCTL is at offset 0x84 */
856#endif
857
858#ifdef CONFIG_DASA_SIM
859 /* use r4 as the working variable */
860 /* turn on MA17 (LOCCTL.7) */
861 lwz r4,0x84(r3) /* LOCTL is at offset 0x84 */
862 ori r4,r4,0x80 /* make bit 7 = 1 -- MA17 mode */
863 stw r4,0x84(r3) /* LOCTL is at offset 0x84 */
864#endif
865
866 /* turn on MA16..13 (LCS0BRD.12 = 0) */
867 lwz r4,0x100(r3) /* LCS0BRD is at offset 0x100 */
868 andi. r4,r4,0xefff /* make bit 12 = 0 */
869 stw r4,0x100(r3) /* LCS0BRD is at offset 0x100 */
870
871 /* make sure above stores all comlete before going on */
872 sync
873
874 /* last thing, set local init status done bit (DEVINIT.31) */
875 lwz r4,0x80(r3) /* DEVINIT is at offset 0x80 */
876 oris r4,r4,0x8000 /* make bit 31 = 1 */
877 stw r4,0x80(r3) /* DEVINIT is at offset 0x80 */
878
879 /* clear all pending interrupts and disable all interrupts */
880 li r4,-1 /* set p1 to 0xffffffff */
881 stw r4,0x1b0(r3) /* clear all pending interrupts */
882 stw r4,0x1b8(r3) /* clear all pending interrupts */
883 li r4,0 /* set r4 to 0 */
884 stw r4,0x1b4(r3) /* disable all interrupts */
885 stw r4,0x1bc(r3) /* disable all interrupts */
886
887 /* make sure above stores all comlete before going on */
888 sync
889
Grant Ericksonb6933412008-05-22 14:44:14 -0700890 /* Set-up icache cacheability. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200891 lis r1, CONFIG_SYS_ICACHE_SACR_VALUE@h
892 ori r1, r1, CONFIG_SYS_ICACHE_SACR_VALUE@l
Grant Ericksonb6933412008-05-22 14:44:14 -0700893 mticcr r1
894 isync
wdenk0442ed82002-11-03 10:24:00 +0000895
Grant Ericksonb6933412008-05-22 14:44:14 -0700896 /* Set-up dcache cacheability. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200897 lis r1, CONFIG_SYS_DCACHE_SACR_VALUE@h
898 ori r1, r1, CONFIG_SYS_DCACHE_SACR_VALUE@l
Grant Ericksonb6933412008-05-22 14:44:14 -0700899 mtdccr r1
wdenk0442ed82002-11-03 10:24:00 +0000900
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200901 addis r1,r0,CONFIG_SYS_INIT_RAM_ADDR@h
902 ori r1,r1,CONFIG_SYS_INIT_SP_OFFSET /* set up the stack to SDRAM */
wdenk0442ed82002-11-03 10:24:00 +0000903 li r0, 0 /* Make room for stack frame header and */
904 stwu r0, -4(r1) /* clear final stack frame so that */
905 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
906
907 GET_GOT /* initialize GOT access */
908
909 bl board_init_f /* run first part of init code (from Flash) */
910
911#endif /* CONFIG_IOP480 */
912
913/*****************************************************************************/
Stefan Roese17ffbc82007-03-21 13:38:59 +0100914#if defined(CONFIG_405GP) || defined(CONFIG_405CR) || \
915 defined(CONFIG_405EP) || defined(CONFIG_405EZ) || \
Stefan Roese153b3e22007-10-05 17:10:59 +0200916 defined(CONFIG_405EX) || defined(CONFIG_405)
wdenk0442ed82002-11-03 10:24:00 +0000917 /*----------------------------------------------------------------------- */
918 /* Clear and set up some registers. */
919 /*----------------------------------------------------------------------- */
920 addi r4,r0,0x0000
Stefan Roese153b3e22007-10-05 17:10:59 +0200921#if !defined(CONFIG_405EX)
wdenk0442ed82002-11-03 10:24:00 +0000922 mtspr sgr,r4
Stefan Roese153b3e22007-10-05 17:10:59 +0200923#else
924 /*
925 * On 405EX, completely clearing the SGR leads to PPC hangup
926 * upon PCIe configuration access. The PCIe memory regions
927 * need to be guarded!
928 */
929 lis r3,0x0000
930 ori r3,r3,0x7FFC
931 mtspr sgr,r3
932#endif
wdenk0442ed82002-11-03 10:24:00 +0000933 mtspr dcwr,r4
934 mtesr r4 /* clear Exception Syndrome Reg */
935 mttcr r4 /* clear Timer Control Reg */
936 mtxer r4 /* clear Fixed-Point Exception Reg */
937 mtevpr r4 /* clear Exception Vector Prefix Reg */
wdenk0442ed82002-11-03 10:24:00 +0000938 addi r4,r0,(0xFFFF-0x10000) /* set r4 to 0xFFFFFFFF (status in the */
939 /* dbsr is cleared by setting bits to 1) */
940 mtdbsr r4 /* clear/reset the dbsr */
941
Grant Ericksonb6933412008-05-22 14:44:14 -0700942 /* Invalidate the i- and d-caches. */
wdenk0442ed82002-11-03 10:24:00 +0000943 bl invalidate_icache
944 bl invalidate_dcache
945
Grant Ericksonb6933412008-05-22 14:44:14 -0700946 /* Set-up icache cacheability. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200947 lis r4, CONFIG_SYS_ICACHE_SACR_VALUE@h
948 ori r4, r4, CONFIG_SYS_ICACHE_SACR_VALUE@l
Grant Ericksonb6933412008-05-22 14:44:14 -0700949 mticcr r4
wdenk0442ed82002-11-03 10:24:00 +0000950 isync
951
Grant Ericksonb6933412008-05-22 14:44:14 -0700952 /* Set-up dcache cacheability. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200953 lis r4, CONFIG_SYS_DCACHE_SACR_VALUE@h
954 ori r4, r4, CONFIG_SYS_DCACHE_SACR_VALUE@l
Grant Ericksonb6933412008-05-22 14:44:14 -0700955 mtdccr r4
wdenk0442ed82002-11-03 10:24:00 +0000956
Ricardo Ribalda Delgado78ea77e2008-10-21 18:29:46 +0200957#if !(defined(CONFIG_SYS_EBC_PB0AP) && defined(CONFIG_SYS_EBC_PB0CR))\
958 && !defined (CONFIG_XILINX_405)
wdenk0442ed82002-11-03 10:24:00 +0000959 /*----------------------------------------------------------------------- */
960 /* Tune the speed and size for flash CS0 */
961 /*----------------------------------------------------------------------- */
962 bl ext_bus_cntlr_init
963#endif
Stefan Roese7d72e022008-06-02 14:35:44 +0200964
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200965#if !(defined(CONFIG_SYS_INIT_DCACHE_CS) || defined(CONFIG_SYS_TEMP_STACK_OCM))
Stefan Roese153b3e22007-10-05 17:10:59 +0200966 /*
Grant Ericksonb6933412008-05-22 14:44:14 -0700967 * For boards that don't have OCM and can't use the data cache
968 * for their primordial stack, setup stack here directly after the
969 * SDRAM is initialized in ext_bus_cntlr_init.
Stefan Roese153b3e22007-10-05 17:10:59 +0200970 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200971 lis r1, CONFIG_SYS_INIT_RAM_ADDR@h
972 ori r1,r1,CONFIG_SYS_INIT_SP_OFFSET /* set up the stack in SDRAM */
Stefan Roese153b3e22007-10-05 17:10:59 +0200973
974 li r0, 0 /* Make room for stack frame header and */
975 stwu r0, -4(r1) /* clear final stack frame so that */
976 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
977 /*
978 * Set up a dummy frame to store reset vector as return address.
979 * this causes stack underflow to reset board.
980 */
981 stwu r1, -8(r1) /* Save back chain and move SP */
982 lis r0, RESET_VECTOR@h /* Address of reset vector */
983 ori r0, r0, RESET_VECTOR@l
984 stwu r1, -8(r1) /* Save back chain and move SP */
985 stw r0, +12(r1) /* Save return addr (underflow vect) */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200986#endif /* !(CONFIG_SYS_INIT_DCACHE_CS || !CONFIG_SYS_TEM_STACK_OCM) */
wdenk0442ed82002-11-03 10:24:00 +0000987
stroese434979e2003-05-23 11:18:02 +0000988#if defined(CONFIG_405EP)
989 /*----------------------------------------------------------------------- */
990 /* DMA Status, clear to come up clean */
991 /*----------------------------------------------------------------------- */
Wolfgang Denka1be4762008-05-20 16:00:29 +0200992 addis r3,r0, 0xFFFF /* Clear all existing DMA status */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +0200993 ori r3,r3, 0xFFFF
994 mtdcr dmasr, r3
stroese434979e2003-05-23 11:18:02 +0000995
Wolfgang Denka1be4762008-05-20 16:00:29 +0200996 bl ppc405ep_init /* do ppc405ep specific init */
stroese434979e2003-05-23 11:18:02 +0000997#endif /* CONFIG_405EP */
998
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200999#if defined(CONFIG_SYS_OCM_DATA_ADDR) && defined(CONFIG_SYS_OCM_DATA_SIZE)
Stefan Roese17ffbc82007-03-21 13:38:59 +01001000#if defined(CONFIG_405EZ)
1001 /********************************************************************
1002 * Setup OCM - On Chip Memory - PPC405EZ uses OCM Controller V2
1003 *******************************************************************/
1004 /*
1005 * We can map the OCM on the PLB3, so map it at
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001006 * CONFIG_SYS_OCM_DATA_ADDR + 0x8000
Stefan Roese17ffbc82007-03-21 13:38:59 +01001007 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001008 lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
1009 ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
Stefan Roese80d99a42007-06-19 16:42:31 +02001010 ori r3,r3,0x0270 /* 16K for Bank 1, R/W/Enable */
Stefan Roese17ffbc82007-03-21 13:38:59 +01001011 mtdcr ocmplb3cr1,r3 /* Set PLB Access */
1012 ori r3,r3,0x4000 /* Add 0x4000 for bank 2 */
1013 mtdcr ocmplb3cr2,r3 /* Set PLB Access */
1014 isync
1015
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001016 lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
1017 ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001018 ori r3,r3,0x0270 /* 16K for Bank 1, R/W/Enable */
1019 mtdcr ocmdscr1, r3 /* Set Data Side */
1020 mtdcr ocmiscr1, r3 /* Set Instruction Side */
Stefan Roese17ffbc82007-03-21 13:38:59 +01001021 ori r3,r3,0x4000 /* Add 0x4000 for bank 2 */
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001022 mtdcr ocmdscr2, r3 /* Set Data Side */
1023 mtdcr ocmiscr2, r3 /* Set Instruction Side */
1024 addis r3,0,0x0800 /* OCM Data Parity Disable - 1 Wait State */
Stefan Roesed85f5d72007-05-24 09:49:00 +02001025 mtdcr ocmdsisdpc,r3
Stefan Roese17ffbc82007-03-21 13:38:59 +01001026
1027 isync
Stefan Roesef6c7b762007-03-24 15:45:34 +01001028#else /* CONFIG_405EZ */
wdenk0442ed82002-11-03 10:24:00 +00001029 /********************************************************************
1030 * Setup OCM - On Chip Memory
1031 *******************************************************************/
1032 /* Setup OCM */
wdenk57b2d802003-06-27 21:31:46 +00001033 lis r0, 0x7FFF
1034 ori r0, r0, 0xFFFF
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001035 mfdcr r3, ocmiscntl /* get instr-side IRAM config */
Stefan Roesef6c7b762007-03-24 15:45:34 +01001036 mfdcr r4, ocmdscntl /* get data-side IRAM config */
1037 and r3, r3, r0 /* disable data-side IRAM */
1038 and r4, r4, r0 /* disable data-side IRAM */
1039 mtdcr ocmiscntl, r3 /* set instr-side IRAM config */
1040 mtdcr ocmdscntl, r4 /* set data-side IRAM config */
wdenk57b2d802003-06-27 21:31:46 +00001041 isync
wdenk0442ed82002-11-03 10:24:00 +00001042
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001043 lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
1044 ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
wdenk0442ed82002-11-03 10:24:00 +00001045 mtdcr ocmdsarc, r3
1046 addis r4, 0, 0xC000 /* OCM data area enabled */
1047 mtdcr ocmdscntl, r4
wdenk57b2d802003-06-27 21:31:46 +00001048 isync
Stefan Roese17ffbc82007-03-21 13:38:59 +01001049#endif /* CONFIG_405EZ */
wdenk0442ed82002-11-03 10:24:00 +00001050#endif
1051
1052 /*----------------------------------------------------------------------- */
1053 /* Setup temporary stack in DCACHE or OCM if needed for SDRAM SPD. */
1054 /*----------------------------------------------------------------------- */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001055#ifdef CONFIG_SYS_INIT_DCACHE_CS
Grant Ericksonb6933412008-05-22 14:44:14 -07001056 li r4, PBxAP
1057 mtdcr ebccfga, r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001058 lis r4, CONFIG_SYS_INIT_DCACHE_PBxAR@h
1059 ori r4, r4, CONFIG_SYS_INIT_DCACHE_PBxAR@l
Grant Ericksonb6933412008-05-22 14:44:14 -07001060 mtdcr ebccfgd, r4
wdenk0442ed82002-11-03 10:24:00 +00001061
Grant Ericksonb6933412008-05-22 14:44:14 -07001062 addi r4, 0, PBxCR
1063 mtdcr ebccfga, r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001064 lis r4, CONFIG_SYS_INIT_DCACHE_PBxCR@h
1065 ori r4, r4, CONFIG_SYS_INIT_DCACHE_PBxCR@l
Grant Ericksonb6933412008-05-22 14:44:14 -07001066 mtdcr ebccfgd, r4
wdenk0442ed82002-11-03 10:24:00 +00001067
Grant Ericksonb6933412008-05-22 14:44:14 -07001068 /*
1069 * Enable the data cache for the 128MB storage access control region
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001070 * at CONFIG_SYS_INIT_RAM_ADDR.
Grant Ericksonb6933412008-05-22 14:44:14 -07001071 */
1072 mfdccr r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001073 oris r4, r4, PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@h
1074 ori r4, r4, PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@l
wdenk0442ed82002-11-03 10:24:00 +00001075 mtdccr r4
1076
Grant Ericksonb6933412008-05-22 14:44:14 -07001077 /*
1078 * Preallocate data cache lines to be used to avoid a subsequent
1079 * cache miss and an ensuing machine check exception when exceptions
1080 * are enabled.
1081 */
1082 li r0, 0
1083
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001084 lis r3, CONFIG_SYS_INIT_RAM_ADDR@h
1085 ori r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
wdenk0442ed82002-11-03 10:24:00 +00001086
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001087 lis r4, CONFIG_SYS_INIT_RAM_END@h
1088 ori r4, r4, CONFIG_SYS_INIT_RAM_END@l
wdenk0442ed82002-11-03 10:24:00 +00001089
Grant Ericksonb6933412008-05-22 14:44:14 -07001090 /*
1091 * Convert the size, in bytes, to the number of cache lines/blocks
1092 * to preallocate.
1093 */
1094 clrlwi. r5, r4, (32 - L1_CACHE_SHIFT)
1095 srwi r5, r4, L1_CACHE_SHIFT
1096 beq ..load_counter
1097 addi r5, r5, 0x0001
1098..load_counter:
1099 mtctr r5
1100
1101 /* Preallocate the computed number of cache blocks. */
1102..alloc_dcache_block:
1103 dcba r0, r3
1104 addi r3, r3, L1_CACHE_BYTES
1105 bdnz ..alloc_dcache_block
1106 sync
1107
1108 /*
1109 * Load the initial stack pointer and data area and convert the size,
1110 * in bytes, to the number of words to initialize to a known value.
1111 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001112 lis r1, CONFIG_SYS_INIT_RAM_ADDR@h
1113 ori r1, r1, CONFIG_SYS_INIT_SP_OFFSET@l
Grant Ericksonb6933412008-05-22 14:44:14 -07001114
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001115 lis r4, (CONFIG_SYS_INIT_RAM_END >> 2)@h
1116 ori r4, r4, (CONFIG_SYS_INIT_RAM_END >> 2)@l
wdenk0442ed82002-11-03 10:24:00 +00001117 mtctr r4
1118
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001119 lis r2, CONFIG_SYS_INIT_RAM_ADDR@h
1120 ori r2, r2, CONFIG_SYS_INIT_RAM_END@l
wdenk0442ed82002-11-03 10:24:00 +00001121
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001122 lis r4, CONFIG_SYS_INIT_RAM_PATTERN@h
1123 ori r4, r4, CONFIG_SYS_INIT_RAM_PATTERN@l
wdenk0442ed82002-11-03 10:24:00 +00001124
1125..stackloop:
Grant Ericksonb6933412008-05-22 14:44:14 -07001126 stwu r4, -4(r2)
wdenk0442ed82002-11-03 10:24:00 +00001127 bdnz ..stackloop
1128
Grant Ericksonb6933412008-05-22 14:44:14 -07001129 /*
1130 * Make room for stack frame header and clear final stack frame so
1131 * that stack backtraces terminate cleanly.
1132 */
1133 stwu r0, -4(r1)
1134 stwu r0, -4(r1)
1135
wdenk0442ed82002-11-03 10:24:00 +00001136 /*
1137 * Set up a dummy frame to store reset vector as return address.
1138 * this causes stack underflow to reset board.
1139 */
1140 stwu r1, -8(r1) /* Save back chain and move SP */
1141 addis r0, 0, RESET_VECTOR@h /* Address of reset vector */
1142 ori r0, r0, RESET_VECTOR@l
1143 stwu r1, -8(r1) /* Save back chain and move SP */
1144 stw r0, +12(r1) /* Save return addr (underflow vect) */
1145
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001146#elif defined(CONFIG_SYS_TEMP_STACK_OCM) && \
1147 (defined(CONFIG_SYS_OCM_DATA_ADDR) && defined(CONFIG_SYS_OCM_DATA_SIZE))
wdenk0442ed82002-11-03 10:24:00 +00001148 /*
1149 * Stack in OCM.
1150 */
1151
1152 /* Set up Stack at top of OCM */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001153 lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET)@h
1154 ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET)@l
wdenk0442ed82002-11-03 10:24:00 +00001155
1156 /* Set up a zeroized stack frame so that backtrace works right */
1157 li r0, 0
1158 stwu r0, -4(r1)
1159 stwu r0, -4(r1)
1160
1161 /*
1162 * Set up a dummy frame to store reset vector as return address.
1163 * this causes stack underflow to reset board.
1164 */
1165 stwu r1, -8(r1) /* Save back chain and move SP */
1166 lis r0, RESET_VECTOR@h /* Address of reset vector */
1167 ori r0, r0, RESET_VECTOR@l
1168 stwu r1, -8(r1) /* Save back chain and move SP */
1169 stw r0, +12(r1) /* Save return addr (underflow vect) */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001170#endif /* CONFIG_SYS_INIT_DCACHE_CS */
wdenk0442ed82002-11-03 10:24:00 +00001171
Stefan Roese23d8d342007-06-06 11:42:13 +02001172#ifdef CONFIG_NAND_SPL
Stefan Roese7d72e022008-06-02 14:35:44 +02001173 bl nand_boot_common /* will not return */
Stefan Roese23d8d342007-06-06 11:42:13 +02001174#else
wdenk0442ed82002-11-03 10:24:00 +00001175 GET_GOT /* initialize GOT access */
1176
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001177 bl cpu_init_f /* run low-level CPU init code (from Flash) */
wdenk0442ed82002-11-03 10:24:00 +00001178
1179 /* NEVER RETURNS! */
1180 bl board_init_f /* run first part of init code (from Flash) */
Stefan Roese23d8d342007-06-06 11:42:13 +02001181#endif /* CONFIG_NAND_SPL */
wdenk0442ed82002-11-03 10:24:00 +00001182
wdenk232fe0b2003-09-02 22:48:03 +00001183#endif /* CONFIG_405GP || CONFIG_405CR || CONFIG_405 || CONFIG_405EP */
1184 /*----------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001185
1186
Stefan Roese42fbddd2006-09-07 11:51:23 +02001187#ifndef CONFIG_NAND_SPL
wdenk0442ed82002-11-03 10:24:00 +00001188/*
1189 * This code finishes saving the registers to the exception frame
1190 * and jumps to the appropriate handler for the exception.
1191 * Register r21 is pointer into trap frame, r1 has new stack pointer.
1192 */
1193 .globl transfer_to_handler
1194transfer_to_handler:
1195 stw r22,_NIP(r21)
1196 lis r22,MSR_POW@h
1197 andc r23,r23,r22
1198 stw r23,_MSR(r21)
1199 SAVE_GPR(7, r21)
1200 SAVE_4GPRS(8, r21)
1201 SAVE_8GPRS(12, r21)
1202 SAVE_8GPRS(24, r21)
wdenk0442ed82002-11-03 10:24:00 +00001203 mflr r23
1204 andi. r24,r23,0x3f00 /* get vector offset */
1205 stw r24,TRAP(r21)
1206 li r22,0
1207 stw r22,RESULT(r21)
1208 mtspr SPRG2,r22 /* r1 is now kernel sp */
wdenk0442ed82002-11-03 10:24:00 +00001209 lwz r24,0(r23) /* virtual address of handler */
1210 lwz r23,4(r23) /* where to go when done */
1211 mtspr SRR0,r24
1212 mtspr SRR1,r20
1213 mtlr r23
1214 SYNC
1215 rfi /* jump to handler, enable MMU */
1216
1217int_return:
1218 mfmsr r28 /* Disable interrupts */
1219 li r4,0
1220 ori r4,r4,MSR_EE
1221 andc r28,r28,r4
1222 SYNC /* Some chip revs need this... */
1223 mtmsr r28
1224 SYNC
1225 lwz r2,_CTR(r1)
1226 lwz r0,_LINK(r1)
1227 mtctr r2
1228 mtlr r0
1229 lwz r2,_XER(r1)
1230 lwz r0,_CCR(r1)
1231 mtspr XER,r2
1232 mtcrf 0xFF,r0
1233 REST_10GPRS(3, r1)
1234 REST_10GPRS(13, r1)
1235 REST_8GPRS(23, r1)
1236 REST_GPR(31, r1)
1237 lwz r2,_NIP(r1) /* Restore environment */
1238 lwz r0,_MSR(r1)
1239 mtspr SRR0,r2
1240 mtspr SRR1,r0
1241 lwz r0,GPR0(r1)
1242 lwz r2,GPR2(r1)
1243 lwz r1,GPR1(r1)
1244 SYNC
1245 rfi
1246
1247crit_return:
1248 mfmsr r28 /* Disable interrupts */
1249 li r4,0
1250 ori r4,r4,MSR_EE
1251 andc r28,r28,r4
1252 SYNC /* Some chip revs need this... */
1253 mtmsr r28
1254 SYNC
1255 lwz r2,_CTR(r1)
1256 lwz r0,_LINK(r1)
1257 mtctr r2
1258 mtlr r0
1259 lwz r2,_XER(r1)
1260 lwz r0,_CCR(r1)
1261 mtspr XER,r2
1262 mtcrf 0xFF,r0
1263 REST_10GPRS(3, r1)
1264 REST_10GPRS(13, r1)
1265 REST_8GPRS(23, r1)
1266 REST_GPR(31, r1)
1267 lwz r2,_NIP(r1) /* Restore environment */
1268 lwz r0,_MSR(r1)
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001269 mtspr csrr0,r2
1270 mtspr csrr1,r0
wdenk0442ed82002-11-03 10:24:00 +00001271 lwz r0,GPR0(r1)
1272 lwz r2,GPR2(r1)
1273 lwz r1,GPR1(r1)
1274 SYNC
1275 rfci
1276
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001277#ifdef CONFIG_440
1278mck_return:
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001279 mfmsr r28 /* Disable interrupts */
1280 li r4,0
1281 ori r4,r4,MSR_EE
1282 andc r28,r28,r4
1283 SYNC /* Some chip revs need this... */
1284 mtmsr r28
1285 SYNC
1286 lwz r2,_CTR(r1)
1287 lwz r0,_LINK(r1)
1288 mtctr r2
1289 mtlr r0
1290 lwz r2,_XER(r1)
1291 lwz r0,_CCR(r1)
1292 mtspr XER,r2
1293 mtcrf 0xFF,r0
1294 REST_10GPRS(3, r1)
1295 REST_10GPRS(13, r1)
1296 REST_8GPRS(23, r1)
1297 REST_GPR(31, r1)
1298 lwz r2,_NIP(r1) /* Restore environment */
1299 lwz r0,_MSR(r1)
1300 mtspr mcsrr0,r2
1301 mtspr mcsrr1,r0
1302 lwz r0,GPR0(r1)
1303 lwz r2,GPR2(r1)
1304 lwz r1,GPR1(r1)
1305 SYNC
1306 rfmci
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001307#endif /* CONFIG_440 */
1308
1309
wdenk0442ed82002-11-03 10:24:00 +00001310 .globl get_pvr
1311get_pvr:
1312 mfspr r3, PVR
1313 blr
1314
wdenk0442ed82002-11-03 10:24:00 +00001315/*------------------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001316/* Function: out16 */
1317/* Description: Output 16 bits */
1318/*------------------------------------------------------------------------------- */
1319 .globl out16
1320out16:
1321 sth r4,0x0000(r3)
1322 blr
1323
1324/*------------------------------------------------------------------------------- */
1325/* Function: out16r */
1326/* Description: Byte reverse and output 16 bits */
1327/*------------------------------------------------------------------------------- */
1328 .globl out16r
1329out16r:
1330 sthbrx r4,r0,r3
1331 blr
1332
1333/*------------------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001334/* Function: out32r */
1335/* Description: Byte reverse and output 32 bits */
1336/*------------------------------------------------------------------------------- */
1337 .globl out32r
1338out32r:
1339 stwbrx r4,r0,r3
1340 blr
1341
1342/*------------------------------------------------------------------------------- */
1343/* Function: in16 */
1344/* Description: Input 16 bits */
1345/*------------------------------------------------------------------------------- */
1346 .globl in16
1347in16:
1348 lhz r3,0x0000(r3)
1349 blr
1350
1351/*------------------------------------------------------------------------------- */
1352/* Function: in16r */
1353/* Description: Input 16 bits and byte reverse */
1354/*------------------------------------------------------------------------------- */
1355 .globl in16r
1356in16r:
1357 lhbrx r3,r0,r3
1358 blr
1359
1360/*------------------------------------------------------------------------------- */
wdenk0442ed82002-11-03 10:24:00 +00001361/* Function: in32r */
1362/* Description: Input 32 bits and byte reverse */
1363/*------------------------------------------------------------------------------- */
1364 .globl in32r
1365in32r:
1366 lwbrx r3,r0,r3
1367 blr
1368
wdenk0442ed82002-11-03 10:24:00 +00001369/*
1370 * void relocate_code (addr_sp, gd, addr_moni)
1371 *
1372 * This "function" does not return, instead it continues in RAM
1373 * after relocating the monitor code.
1374 *
Grant Ericksonb6933412008-05-22 14:44:14 -07001375 * r3 = Relocated stack pointer
1376 * r4 = Relocated global data pointer
1377 * r5 = Relocated text pointer
wdenk0442ed82002-11-03 10:24:00 +00001378 */
1379 .globl relocate_code
1380relocate_code:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001381#if defined(CONFIG_4xx_DCACHE) || defined(CONFIG_SYS_INIT_DCACHE_CS)
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001382 /*
Grant Ericksonb6933412008-05-22 14:44:14 -07001383 * We need to flush the initial global data (gd_t) before the dcache
1384 * will be invalidated.
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001385 */
1386
Grant Ericksonb6933412008-05-22 14:44:14 -07001387 /* Save registers */
1388 mr r9, r3
1389 mr r10, r4
1390 mr r11, r5
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001391
Grant Ericksonb6933412008-05-22 14:44:14 -07001392 /* Flush initial global data range */
1393 mr r3, r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001394 addi r4, r4, CONFIG_SYS_GBL_DATA_SIZE@l
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001395 bl flush_dcache_range
1396
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001397#if defined(CONFIG_SYS_INIT_DCACHE_CS)
Grant Ericksonb6933412008-05-22 14:44:14 -07001398 /*
1399 * Undo the earlier data cache set-up for the primordial stack and
1400 * data area. First, invalidate the data cache and then disable data
1401 * cacheability for that area. Finally, restore the EBC values, if
1402 * any.
1403 */
1404
1405 /* Invalidate the primordial stack and data area in cache */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001406 lis r3, CONFIG_SYS_INIT_RAM_ADDR@h
1407 ori r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
Grant Ericksonb6933412008-05-22 14:44:14 -07001408
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001409 lis r4, CONFIG_SYS_INIT_RAM_END@h
1410 ori r4, r4, CONFIG_SYS_INIT_RAM_END@l
Grant Ericksonb6933412008-05-22 14:44:14 -07001411 add r4, r4, r3
1412
1413 bl invalidate_dcache_range
1414
1415 /* Disable cacheability for the region */
1416 mfdccr r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001417 lis r4, ~PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@h
1418 ori r4, r4, ~PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@l
Grant Ericksonb6933412008-05-22 14:44:14 -07001419 and r3, r3, r4
1420 mtdccr r3
1421
1422 /* Restore the EBC parameters */
1423 li r3, PBxAP
1424 mtdcr ebccfga, r3
1425 lis r3, PBxAP_VAL@h
1426 ori r3, r3, PBxAP_VAL@l
1427 mtdcr ebccfgd, r3
1428
1429 li r3, PBxCR
1430 mtdcr ebccfga, r3
1431 lis r3, PBxCR_VAL@h
1432 ori r3, r3, PBxCR_VAL@l
1433 mtdcr ebccfgd, r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001434#endif /* defined(CONFIG_SYS_INIT_DCACHE_CS) */
Grant Ericksonb6933412008-05-22 14:44:14 -07001435
1436 /* Restore registers */
1437 mr r3, r9
1438 mr r4, r10
1439 mr r5, r11
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001440#endif /* defined(CONFIG_4xx_DCACHE) || defined(CONFIG_SYS_INIT_DCACHE_CS) */
Stefan Roesea86bde32008-01-09 10:23:16 +01001441
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001442#ifdef CONFIG_SYS_INIT_RAM_DCACHE
Stefan Roesea86bde32008-01-09 10:23:16 +01001443 /*
1444 * Unlock the previously locked d-cache
1445 */
1446 msync
1447 isync
1448 /* set TFLOOR/NFLOOR to 0 again */
1449 lis r6,0x0001
1450 ori r6,r6,0xf800
1451 mtspr dvlim,r6
1452 lis r6,0x0000
1453 ori r6,r6,0x0000
1454 mtspr dnv0,r6
1455 mtspr dnv1,r6
1456 mtspr dnv2,r6
1457 mtspr dnv3,r6
1458 mtspr dtv0,r6
1459 mtspr dtv1,r6
1460 mtspr dtv2,r6
1461 mtspr dtv3,r6
1462 msync
1463 isync
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001464#endif /* CONFIG_SYS_INIT_RAM_DCACHE */
Stefan Roesea86bde32008-01-09 10:23:16 +01001465
Stefan Roese42fbddd2006-09-07 11:51:23 +02001466#if defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
1467 defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
Stefan Roesecc019d12008-03-11 15:05:50 +01001468 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
Feng Kan224bc962008-07-08 22:47:31 -07001469 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
1470 defined(CONFIG_460SX)
Stefan Roese9eba0c82006-06-02 16:18:04 +02001471 /*
1472 * On some 440er platforms the cache is enabled in the first TLB (Boot-CS)
1473 * to speed up the boot process. Now this cache needs to be disabled.
1474 */
1475 iccci 0,0 /* Invalidate inst cache */
1476 dccci 0,0 /* Invalidate data cache, now no longer our stack */
Stefan Roese326c9712005-08-01 16:41:48 +02001477 sync
Stefan Roese9eba0c82006-06-02 16:18:04 +02001478 isync
Stefan Roesefe05a022008-11-20 11:46:20 +01001479
1480 /* Clear all potential pending exceptions */
1481 mfspr r1,mcsr
1482 mtspr mcsr,r1
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001483#ifdef CONFIG_SYS_TLB_FOR_BOOT_FLASH
1484 addi r1,r0,CONFIG_SYS_TLB_FOR_BOOT_FLASH /* Use defined TLB */
Niklaus Giger86cb27b2007-11-30 18:35:11 +01001485#else
1486 addi r1,r0,0x0000 /* Default TLB entry is #0 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001487#endif /* CONFIG_SYS_TLB_FOR_BOOT_FLASH */
Stefan Roese326c9712005-08-01 16:41:48 +02001488 tlbre r0,r1,0x0002 /* Read contents */
Stefan Roese99644742005-11-29 18:18:21 +01001489 ori r0,r0,0x0c00 /* Or in the inhibit, write through bit */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001490 tlbwe r0,r1,0x0002 /* Save it out */
Stefan Roese9eba0c82006-06-02 16:18:04 +02001491 sync
Stefan Roese326c9712005-08-01 16:41:48 +02001492 isync
Grant Ericksonb6933412008-05-22 14:44:14 -07001493#endif /* defined(CONFIG_440EP) || ... || defined(CONFIG_460GT) */
wdenk0442ed82002-11-03 10:24:00 +00001494 mr r1, r3 /* Set new stack pointer */
1495 mr r9, r4 /* Save copy of Init Data pointer */
1496 mr r10, r5 /* Save copy of Destination Address */
1497
1498 mr r3, r5 /* Destination Address */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001499 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
1500 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
wdenkb9a83a92003-05-30 12:48:29 +00001501 lwz r5, GOT(__init_end)
1502 sub r5, r5, r4
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01001503 li r6, L1_CACHE_BYTES /* Cache Line Size */
wdenk0442ed82002-11-03 10:24:00 +00001504
1505 /*
1506 * Fix GOT pointer:
1507 *
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001508 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
wdenk0442ed82002-11-03 10:24:00 +00001509 *
1510 * Offset:
1511 */
1512 sub r15, r10, r4
1513
1514 /* First our own GOT */
1515 add r14, r14, r15
Grant Ericksonb6933412008-05-22 14:44:14 -07001516 /* then the one used by the C code */
wdenk0442ed82002-11-03 10:24:00 +00001517 add r30, r30, r15
1518
1519 /*
1520 * Now relocate code
1521 */
1522
1523 cmplw cr1,r3,r4
1524 addi r0,r5,3
1525 srwi. r0,r0,2
1526 beq cr1,4f /* In place copy is not necessary */
1527 beq 7f /* Protect against 0 count */
1528 mtctr r0
1529 bge cr1,2f
1530
1531 la r8,-4(r4)
1532 la r7,-4(r3)
15331: lwzu r0,4(r8)
1534 stwu r0,4(r7)
1535 bdnz 1b
1536 b 4f
1537
15382: slwi r0,r0,2
1539 add r8,r4,r0
1540 add r7,r3,r0
15413: lwzu r0,-4(r8)
1542 stwu r0,-4(r7)
1543 bdnz 3b
1544
1545/*
1546 * Now flush the cache: note that we must start from a cache aligned
1547 * address. Otherwise we might miss one cache line.
1548 */
15494: cmpwi r6,0
1550 add r5,r3,r5
1551 beq 7f /* Always flush prefetch queue in any case */
1552 subi r0,r6,1
1553 andc r3,r3,r0
1554 mr r4,r3
15555: dcbst 0,r4
1556 add r4,r4,r6
1557 cmplw r4,r5
1558 blt 5b
1559 sync /* Wait for all dcbst to complete on bus */
1560 mr r4,r3
15616: icbi 0,r4
1562 add r4,r4,r6
1563 cmplw r4,r5
1564 blt 6b
15657: sync /* Wait for all icbi to complete on bus */
1566 isync
1567
1568/*
1569 * We are done. Do not return, instead branch to second part of board
1570 * initialization, now running from RAM.
1571 */
1572
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001573 addi r0, r10, in_ram - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +00001574 mtlr r0
1575 blr /* NEVER RETURNS! */
1576
1577in_ram:
1578
1579 /*
1580 * Relocation Function, r14 point to got2+0x8000
1581 *
1582 * Adjust got2 pointers, no need to check for 0, this code
1583 * already puts a few entries in the table.
1584 */
1585 li r0,__got2_entries@sectoff@l
1586 la r3,GOT(_GOT2_TABLE_)
1587 lwz r11,GOT(_GOT2_TABLE_)
1588 mtctr r0
1589 sub r11,r3,r11
1590 addi r3,r3,-4
15911: lwzu r0,4(r3)
1592 add r0,r0,r11
1593 stw r0,0(r3)
1594 bdnz 1b
1595
1596 /*
1597 * Now adjust the fixups and the pointers to the fixups
1598 * in case we need to move ourselves again.
1599 */
16002: li r0,__fixup_entries@sectoff@l
1601 lwz r3,GOT(_FIXUP_TABLE_)
1602 cmpwi r0,0
1603 mtctr r0
1604 addi r3,r3,-4
1605 beq 4f
16063: lwzu r4,4(r3)
1607 lwzux r0,r4,r11
1608 add r0,r0,r11
1609 stw r10,0(r3)
1610 stw r0,0(r4)
1611 bdnz 3b
16124:
1613clear_bss:
1614 /*
1615 * Now clear BSS segment
1616 */
wdenkbf2f8c92003-05-22 22:52:13 +00001617 lwz r3,GOT(__bss_start)
wdenk0442ed82002-11-03 10:24:00 +00001618 lwz r4,GOT(_end)
1619
1620 cmplw 0, r3, r4
Anatolij Gustschin720025b2007-12-05 17:43:20 +01001621 beq 7f
wdenk0442ed82002-11-03 10:24:00 +00001622
1623 li r0, 0
Anatolij Gustschin720025b2007-12-05 17:43:20 +01001624
1625 andi. r5, r4, 3
1626 beq 6f
1627 sub r4, r4, r5
1628 mtctr r5
1629 mr r5, r4
16305: stb r0, 0(r5)
1631 addi r5, r5, 1
1632 bdnz 5b
16336:
wdenk0442ed82002-11-03 10:24:00 +00001634 stw r0, 0(r3)
1635 addi r3, r3, 4
1636 cmplw 0, r3, r4
Anatolij Gustschin720025b2007-12-05 17:43:20 +01001637 bne 6b
wdenk0442ed82002-11-03 10:24:00 +00001638
Anatolij Gustschin720025b2007-12-05 17:43:20 +010016397:
wdenk0442ed82002-11-03 10:24:00 +00001640 mr r3, r9 /* Init Data pointer */
1641 mr r4, r10 /* Destination Address */
1642 bl board_init_r
1643
wdenk0442ed82002-11-03 10:24:00 +00001644 /*
1645 * Copy exception vector code to low memory
1646 *
1647 * r3: dest_addr
1648 * r7: source address, r8: end address, r9: target address
1649 */
1650 .globl trap_init
1651trap_init:
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001652 lwz r7, GOT(_start_of_vectors)
wdenk0442ed82002-11-03 10:24:00 +00001653 lwz r8, GOT(_end_of_vectors)
1654
wdenk4e112c12003-06-03 23:54:09 +00001655 li r9, 0x100 /* reset vector always at 0x100 */
wdenk0442ed82002-11-03 10:24:00 +00001656
1657 cmplw 0, r7, r8
1658 bgelr /* return if r7>=r8 - just in case */
1659
1660 mflr r4 /* save link register */
16611:
1662 lwz r0, 0(r7)
1663 stw r0, 0(r9)
1664 addi r7, r7, 4
1665 addi r9, r9, 4
1666 cmplw 0, r7, r8
1667 bne 1b
1668
1669 /*
1670 * relocate `hdlr' and `int_return' entries
1671 */
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001672 li r7, .L_MachineCheck - _start + _START_OFFSET
1673 li r8, Alignment - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +000016742:
1675 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001676 addi r7, r7, 0x100 /* next exception vector */
wdenk0442ed82002-11-03 10:24:00 +00001677 cmplw 0, r7, r8
1678 blt 2b
1679
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001680 li r7, .L_Alignment - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +00001681 bl trap_reloc
1682
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001683 li r7, .L_ProgramCheck - _start + _START_OFFSET
wdenk0442ed82002-11-03 10:24:00 +00001684 bl trap_reloc
1685
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001686#ifdef CONFIG_440
1687 li r7, .L_FPUnavailable - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001688 bl trap_reloc
wdenk0442ed82002-11-03 10:24:00 +00001689
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001690 li r7, .L_Decrementer - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001691 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001692
1693 li r7, .L_APU - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001694 bl trap_reloc
Stefan Roese80d99a42007-06-19 16:42:31 +02001695
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001696 li r7, .L_InstructionTLBError - _start + _START_OFFSET
1697 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001698
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001699 li r7, .L_DataTLBError - _start + _START_OFFSET
1700 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001701#else /* CONFIG_440 */
1702 li r7, .L_PIT - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001703 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001704
1705 li r7, .L_InstructionTLBMiss - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001706 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001707
1708 li r7, .L_DataTLBMiss - _start + _START_OFFSET
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001709 bl trap_reloc
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +02001710#endif /* CONFIG_440 */
1711
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001712 li r7, .L_DebugBreakpoint - _start + _START_OFFSET
1713 bl trap_reloc
wdenk0442ed82002-11-03 10:24:00 +00001714
Stefan Roese42fbddd2006-09-07 11:51:23 +02001715#if !defined(CONFIG_440)
Stefan Roese7b12aa82006-03-13 09:42:28 +01001716 addi r7,r0,0x1000 /* set ME bit (Machine Exceptions) */
1717 oris r7,r7,0x0002 /* set CE bit (Critical Exceptions) */
1718 mtmsr r7 /* change MSR */
1719#else
Stefan Roese42fbddd2006-09-07 11:51:23 +02001720 bl __440_msr_set
1721 b __440_msr_continue
Stefan Roese7b12aa82006-03-13 09:42:28 +01001722
Stefan Roese42fbddd2006-09-07 11:51:23 +02001723__440_msr_set:
Stefan Roese7b12aa82006-03-13 09:42:28 +01001724 addi r7,r0,0x1000 /* set ME bit (Machine Exceptions) */
1725 oris r7,r7,0x0002 /* set CE bit (Critical Exceptions) */
1726 mtspr srr1,r7
1727 mflr r7
1728 mtspr srr0,r7
1729 rfi
Stefan Roese42fbddd2006-09-07 11:51:23 +02001730__440_msr_continue:
Stefan Roese7b12aa82006-03-13 09:42:28 +01001731#endif
1732
wdenk0442ed82002-11-03 10:24:00 +00001733 mtlr r4 /* restore link register */
1734 blr
1735
1736 /*
1737 * Function: relocate entries for one exception vector
1738 */
1739trap_reloc:
1740 lwz r0, 0(r7) /* hdlr ... */
1741 add r0, r0, r3 /* ... += dest_addr */
1742 stw r0, 0(r7)
1743
1744 lwz r0, 4(r7) /* int_return ... */
1745 add r0, r0, r3 /* ... += dest_addr */
1746 stw r0, 4(r7)
1747
1748 blr
Stefan Roese42743512007-06-01 15:27:11 +02001749
1750#if defined(CONFIG_440)
1751/*----------------------------------------------------------------------------+
1752| dcbz_area.
1753+----------------------------------------------------------------------------*/
1754 function_prolog(dcbz_area)
1755 rlwinm. r5,r4,0,27,31
Wolfgang Denk09675ef2007-06-20 18:14:24 +02001756 rlwinm r5,r4,27,5,31
1757 beq ..d_ra2
1758 addi r5,r5,0x0001
1759..d_ra2:mtctr r5
1760..d_ag2:dcbz r0,r3
1761 addi r3,r3,32
1762 bdnz ..d_ag2
Stefan Roese42743512007-06-01 15:27:11 +02001763 sync
1764 blr
1765 function_epilog(dcbz_area)
Stefan Roese42743512007-06-01 15:27:11 +02001766#endif /* CONFIG_440 */
Stefan Roese42fbddd2006-09-07 11:51:23 +02001767#endif /* CONFIG_NAND_SPL */
stroese434979e2003-05-23 11:18:02 +00001768
Stefan Roese42743512007-06-01 15:27:11 +02001769/*------------------------------------------------------------------------------- */
1770/* Function: in8 */
1771/* Description: Input 8 bits */
1772/*------------------------------------------------------------------------------- */
1773 .globl in8
1774in8:
1775 lbz r3,0x0000(r3)
1776 blr
1777
1778/*------------------------------------------------------------------------------- */
1779/* Function: out8 */
1780/* Description: Output 8 bits */
1781/*------------------------------------------------------------------------------- */
1782 .globl out8
1783out8:
1784 stb r4,0x0000(r3)
1785 blr
1786
1787/*------------------------------------------------------------------------------- */
1788/* Function: out32 */
1789/* Description: Output 32 bits */
1790/*------------------------------------------------------------------------------- */
1791 .globl out32
1792out32:
1793 stw r4,0x0000(r3)
1794 blr
1795
1796/*------------------------------------------------------------------------------- */
1797/* Function: in32 */
1798/* Description: Input 32 bits */
1799/*------------------------------------------------------------------------------- */
1800 .globl in32
1801in32:
1802 lwz 3,0x0000(3)
1803 blr
stroese434979e2003-05-23 11:18:02 +00001804
1805/**************************************************************************/
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001806/* PPC405EP specific stuff */
stroese434979e2003-05-23 11:18:02 +00001807/**************************************************************************/
1808#ifdef CONFIG_405EP
1809ppc405ep_init:
stroese5ad6d4d2003-12-09 14:54:43 +00001810
Stefan Roese326c9712005-08-01 16:41:48 +02001811#ifdef CONFIG_BUBINGA
stroese5ad6d4d2003-12-09 14:54:43 +00001812 /*
1813 * Initialize EBC chip selects 1 & 4 and GPIO pins (for alternate
1814 * function) to support FPGA and NVRAM accesses below.
1815 */
1816
1817 lis r3,GPIO0_OSRH@h /* config GPIO output select */
1818 ori r3,r3,GPIO0_OSRH@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001819 lis r4,CONFIG_SYS_GPIO0_OSRH@h
1820 ori r4,r4,CONFIG_SYS_GPIO0_OSRH@l
stroese5ad6d4d2003-12-09 14:54:43 +00001821 stw r4,0(r3)
1822 lis r3,GPIO0_OSRL@h
1823 ori r3,r3,GPIO0_OSRL@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001824 lis r4,CONFIG_SYS_GPIO0_OSRL@h
1825 ori r4,r4,CONFIG_SYS_GPIO0_OSRL@l
stroese5ad6d4d2003-12-09 14:54:43 +00001826 stw r4,0(r3)
1827
1828 lis r3,GPIO0_ISR1H@h /* config GPIO input select */
1829 ori r3,r3,GPIO0_ISR1H@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001830 lis r4,CONFIG_SYS_GPIO0_ISR1H@h
1831 ori r4,r4,CONFIG_SYS_GPIO0_ISR1H@l
stroese5ad6d4d2003-12-09 14:54:43 +00001832 stw r4,0(r3)
1833 lis r3,GPIO0_ISR1L@h
1834 ori r3,r3,GPIO0_ISR1L@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001835 lis r4,CONFIG_SYS_GPIO0_ISR1L@h
1836 ori r4,r4,CONFIG_SYS_GPIO0_ISR1L@l
stroese5ad6d4d2003-12-09 14:54:43 +00001837 stw r4,0(r3)
1838
1839 lis r3,GPIO0_TSRH@h /* config GPIO three-state select */
1840 ori r3,r3,GPIO0_TSRH@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001841 lis r4,CONFIG_SYS_GPIO0_TSRH@h
1842 ori r4,r4,CONFIG_SYS_GPIO0_TSRH@l
stroese5ad6d4d2003-12-09 14:54:43 +00001843 stw r4,0(r3)
1844 lis r3,GPIO0_TSRL@h
1845 ori r3,r3,GPIO0_TSRL@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001846 lis r4,CONFIG_SYS_GPIO0_TSRL@h
1847 ori r4,r4,CONFIG_SYS_GPIO0_TSRL@l
stroese5ad6d4d2003-12-09 14:54:43 +00001848 stw r4,0(r3)
1849
1850 lis r3,GPIO0_TCR@h /* config GPIO driver output enables */
1851 ori r3,r3,GPIO0_TCR@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001852 lis r4,CONFIG_SYS_GPIO0_TCR@h
1853 ori r4,r4,CONFIG_SYS_GPIO0_TCR@l
stroese5ad6d4d2003-12-09 14:54:43 +00001854 stw r4,0(r3)
1855
1856 li r3,pb1ap /* program EBC bank 1 for RTC access */
1857 mtdcr ebccfga,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001858 lis r3,CONFIG_SYS_EBC_PB1AP@h
1859 ori r3,r3,CONFIG_SYS_EBC_PB1AP@l
stroese5ad6d4d2003-12-09 14:54:43 +00001860 mtdcr ebccfgd,r3
1861 li r3,pb1cr
1862 mtdcr ebccfga,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001863 lis r3,CONFIG_SYS_EBC_PB1CR@h
1864 ori r3,r3,CONFIG_SYS_EBC_PB1CR@l
stroese5ad6d4d2003-12-09 14:54:43 +00001865 mtdcr ebccfgd,r3
1866
1867 li r3,pb1ap /* program EBC bank 1 for RTC access */
1868 mtdcr ebccfga,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001869 lis r3,CONFIG_SYS_EBC_PB1AP@h
1870 ori r3,r3,CONFIG_SYS_EBC_PB1AP@l
stroese5ad6d4d2003-12-09 14:54:43 +00001871 mtdcr ebccfgd,r3
1872 li r3,pb1cr
1873 mtdcr ebccfga,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001874 lis r3,CONFIG_SYS_EBC_PB1CR@h
1875 ori r3,r3,CONFIG_SYS_EBC_PB1CR@l
stroese5ad6d4d2003-12-09 14:54:43 +00001876 mtdcr ebccfgd,r3
1877
1878 li r3,pb4ap /* program EBC bank 4 for FPGA access */
1879 mtdcr ebccfga,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001880 lis r3,CONFIG_SYS_EBC_PB4AP@h
1881 ori r3,r3,CONFIG_SYS_EBC_PB4AP@l
stroese5ad6d4d2003-12-09 14:54:43 +00001882 mtdcr ebccfgd,r3
1883 li r3,pb4cr
1884 mtdcr ebccfga,r3
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001885 lis r3,CONFIG_SYS_EBC_PB4CR@h
1886 ori r3,r3,CONFIG_SYS_EBC_PB4CR@l
stroese5ad6d4d2003-12-09 14:54:43 +00001887 mtdcr ebccfgd,r3
1888#endif
stroese434979e2003-05-23 11:18:02 +00001889
wdenk57b2d802003-06-27 21:31:46 +00001890 /*
1891 !-----------------------------------------------------------------------
1892 ! Check to see if chip is in bypass mode.
1893 ! If so, write stored CPC0_PLLMR0 and CPC0_PLLMR1 values and perform a
1894 ! CPU reset Otherwise, skip this step and keep going.
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001895 ! Note: Running BIOS in bypass mode is not supported since PLB speed
1896 ! will not be fast enough for the SDRAM (min 66MHz)
wdenk57b2d802003-06-27 21:31:46 +00001897 !-----------------------------------------------------------------------
stroese434979e2003-05-23 11:18:02 +00001898 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001899 mfdcr r5, CPC0_PLLMR1
Wolfgang Denka1be4762008-05-20 16:00:29 +02001900 rlwinm r4,r5,1,0x1 /* get system clock source (SSCS) */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001901 cmpi cr0,0,r4,0x1
stroese434979e2003-05-23 11:18:02 +00001902
Wolfgang Denka1be4762008-05-20 16:00:29 +02001903 beq pll_done /* if SSCS =b'1' then PLL has */
1904 /* already been set */
1905 /* and CPU has been reset */
1906 /* so skip to next section */
stroese434979e2003-05-23 11:18:02 +00001907
Stefan Roese326c9712005-08-01 16:41:48 +02001908#ifdef CONFIG_BUBINGA
stroese434979e2003-05-23 11:18:02 +00001909 /*
wdenk57b2d802003-06-27 21:31:46 +00001910 !-----------------------------------------------------------------------
1911 ! Read NVRAM to get value to write in PLLMR.
1912 ! If value has not been correctly saved, write default value
1913 ! Default config values (assuming on-board 33MHz SYS_CLK) are above.
1914 ! See CPU_DEFAULT_200 and CPU_DEFAULT_266 above.
1915 !
1916 ! WARNING: This code assumes the first three words in the nvram_t
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001917 ! structure in openbios.h. Changing the beginning of
1918 ! the structure will break this code.
wdenk57b2d802003-06-27 21:31:46 +00001919 !
1920 !-----------------------------------------------------------------------
stroese434979e2003-05-23 11:18:02 +00001921 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001922 addis r3,0,NVRAM_BASE@h
1923 addi r3,r3,NVRAM_BASE@l
stroese434979e2003-05-23 11:18:02 +00001924
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001925 lwz r4, 0(r3)
1926 addis r5,0,NVRVFY1@h
1927 addi r5,r5,NVRVFY1@l
Wolfgang Denka1be4762008-05-20 16:00:29 +02001928 cmp cr0,0,r4,r5 /* Compare 1st NVRAM Magic number*/
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001929 bne ..no_pllset
1930 addi r3,r3,4
1931 lwz r4, 0(r3)
1932 addis r5,0,NVRVFY2@h
1933 addi r5,r5,NVRVFY2@l
Wolfgang Denka1be4762008-05-20 16:00:29 +02001934 cmp cr0,0,r4,r5 /* Compare 2 NVRAM Magic number */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001935 bne ..no_pllset
1936 addi r3,r3,8 /* Skip over conf_size */
1937 lwz r4, 4(r3) /* Load PLLMR1 value from NVRAM */
1938 lwz r3, 0(r3) /* Load PLLMR0 value from NVRAM */
1939 rlwinm r5,r4,1,0x1 /* get system clock source (SSCS) */
1940 cmpi cr0,0,r5,1 /* See if PLL is locked */
1941 beq pll_write
stroese434979e2003-05-23 11:18:02 +00001942..no_pllset:
Stefan Roese326c9712005-08-01 16:41:48 +02001943#endif /* CONFIG_BUBINGA */
stroese434979e2003-05-23 11:18:02 +00001944
John Otken9aa36772007-07-26 17:49:11 +02001945#ifdef CONFIG_TAIHU
1946 mfdcr r4, CPC0_BOOT
1947 andi. r5, r4, CPC0_BOOT_SEP@l
1948 bne strap_1 /* serial eeprom present */
1949 addis r5,0,CPLD_REG0_ADDR@h
1950 ori r5,r5,CPLD_REG0_ADDR@l
1951 andi. r5, r5, 0x10
1952 bne _pci_66mhz
1953#endif /* CONFIG_TAIHU */
1954
Stefan Roesea5d182e2007-08-14 14:44:41 +02001955#if defined(CONFIG_ZEUS)
1956 mfdcr r4, CPC0_BOOT
1957 andi. r5, r4, CPC0_BOOT_SEP@l
Wolfgang Denka1be4762008-05-20 16:00:29 +02001958 bne strap_1 /* serial eeprom present */
Stefan Roesea5d182e2007-08-14 14:44:41 +02001959 lis r3,0x0000
1960 addi r3,r3,0x3030
1961 lis r4,0x8042
1962 addi r4,r4,0x223e
1963 b 1f
1964strap_1:
1965 mfdcr r3, CPC0_PLLMR0
1966 mfdcr r4, CPC0_PLLMR1
1967 b 1f
1968#endif
1969
Wolfgang Denka1be4762008-05-20 16:00:29 +02001970 addis r3,0,PLLMR0_DEFAULT@h /* PLLMR0 default value */
1971 ori r3,r3,PLLMR0_DEFAULT@l /* */
1972 addis r4,0,PLLMR1_DEFAULT@h /* PLLMR1 default value */
1973 ori r4,r4,PLLMR1_DEFAULT@l /* */
stroese434979e2003-05-23 11:18:02 +00001974
John Otken9aa36772007-07-26 17:49:11 +02001975#ifdef CONFIG_TAIHU
1976 b 1f
1977_pci_66mhz:
1978 addis r3,0,PLLMR0_DEFAULT_PCI66@h
1979 ori r3,r3,PLLMR0_DEFAULT_PCI66@l
1980 addis r4,0,PLLMR1_DEFAULT_PCI66@h
1981 ori r4,r4,PLLMR1_DEFAULT_PCI66@l
1982 b 1f
1983strap_1:
1984 mfdcr r3, CPC0_PLLMR0
1985 mfdcr r4, CPC0_PLLMR1
John Otken9aa36772007-07-26 17:49:11 +02001986#endif /* CONFIG_TAIHU */
1987
Stefan Roesea5d182e2007-08-14 14:44:41 +020019881:
Wolfgang Denka1be4762008-05-20 16:00:29 +02001989 b pll_write /* Write the CPC0_PLLMR with new value */
stroese434979e2003-05-23 11:18:02 +00001990
1991pll_done:
wdenk57b2d802003-06-27 21:31:46 +00001992 /*
1993 !-----------------------------------------------------------------------
1994 ! Clear Soft Reset Register
1995 ! This is needed to enable PCI if not booting from serial EPROM
1996 !-----------------------------------------------------------------------
stroese434979e2003-05-23 11:18:02 +00001997 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02001998 addi r3, 0, 0x0
1999 mtdcr CPC0_SRR, r3
stroese434979e2003-05-23 11:18:02 +00002000
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02002001 addis r3,0,0x0010
2002 mtctr r3
stroese434979e2003-05-23 11:18:02 +00002003pci_wait:
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02002004 bdnz pci_wait
stroese434979e2003-05-23 11:18:02 +00002005
Wolfgang Denka1be4762008-05-20 16:00:29 +02002006 blr /* return to main code */
stroese434979e2003-05-23 11:18:02 +00002007
2008/*
2009!-----------------------------------------------------------------------------
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02002010! Function: pll_write
2011! Description: Updates the value of the CPC0_PLLMR according to CMOS27E documentation
2012! That is:
2013! 1. Pll is first disabled (de-activated by putting in bypass mode)
2014! 2. PLL is reset
2015! 3. Clock dividers are set while PLL is held in reset and bypassed
2016! 4. PLL Reset is cleared
2017! 5. Wait 100us for PLL to lock
2018! 6. A core reset is performed
stroese434979e2003-05-23 11:18:02 +00002019! Input: r3 = Value to write to CPC0_PLLMR0
2020! Input: r4 = Value to write to CPC0_PLLMR1
2021! Output r3 = none
2022!-----------------------------------------------------------------------------
2023*/
Matthias Fuchsd8079162009-07-06 16:27:33 +02002024 .globl pll_write
stroese434979e2003-05-23 11:18:02 +00002025pll_write:
wdenk57b2d802003-06-27 21:31:46 +00002026 mfdcr r5, CPC0_UCR
2027 andis. r5,r5,0xFFFF
Wolfgang Denka1be4762008-05-20 16:00:29 +02002028 ori r5,r5,0x0101 /* Stop the UART clocks */
2029 mtdcr CPC0_UCR,r5 /* Before changing PLL */
stroese434979e2003-05-23 11:18:02 +00002030
wdenk57b2d802003-06-27 21:31:46 +00002031 mfdcr r5, CPC0_PLLMR1
Wolfgang Denka1be4762008-05-20 16:00:29 +02002032 rlwinm r5,r5,0,0x7FFFFFFF /* Disable PLL */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02002033 mtdcr CPC0_PLLMR1,r5
Wolfgang Denka1be4762008-05-20 16:00:29 +02002034 oris r5,r5,0x4000 /* Set PLL Reset */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02002035 mtdcr CPC0_PLLMR1,r5
stroese434979e2003-05-23 11:18:02 +00002036
Wolfgang Denka1be4762008-05-20 16:00:29 +02002037 mtdcr CPC0_PLLMR0,r3 /* Set clock dividers */
2038 rlwinm r5,r4,0,0x3FFFFFFF /* Reset & Bypass new PLL dividers */
2039 oris r5,r5,0x4000 /* Set PLL Reset */
2040 mtdcr CPC0_PLLMR1,r5 /* Set clock dividers */
2041 rlwinm r5,r5,0,0xBFFFFFFF /* Clear PLL Reset */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02002042 mtdcr CPC0_PLLMR1,r5
stroese434979e2003-05-23 11:18:02 +00002043
2044 /*
wdenk57b2d802003-06-27 21:31:46 +00002045 ! Wait min of 100us for PLL to lock.
2046 ! See CMOS 27E databook for more info.
2047 ! At 200MHz, that means waiting 20,000 instructions
stroese434979e2003-05-23 11:18:02 +00002048 */
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02002049 addi r3,0,20000 /* 2000 = 0x4e20 */
2050 mtctr r3
stroese434979e2003-05-23 11:18:02 +00002051pll_wait:
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02002052 bdnz pll_wait
stroese434979e2003-05-23 11:18:02 +00002053
Wolfgang Denk8dd4d332005-08-06 01:42:58 +02002054 oris r5,r5,0x8000 /* Enable PLL */
2055 mtdcr CPC0_PLLMR1,r5 /* Engage */
stroese434979e2003-05-23 11:18:02 +00002056
wdenk57b2d802003-06-27 21:31:46 +00002057 /*
2058 * Reset CPU to guarantee timings are OK
2059 * Not sure if this is needed...
2060 */
2061 addis r3,0,0x1000
Wolfgang Denka1be4762008-05-20 16:00:29 +02002062 mtspr dbcr0,r3 /* This will cause a CPU core reset, and */
2063 /* execution will continue from the poweron */
2064 /* vector of 0xfffffffc */
stroese434979e2003-05-23 11:18:02 +00002065#endif /* CONFIG_405EP */
Stefan Roesea8856e32007-02-20 10:57:08 +01002066
2067#if defined(CONFIG_440)
Stefan Roesea8856e32007-02-20 10:57:08 +01002068/*----------------------------------------------------------------------------+
2069| mttlb3.
2070+----------------------------------------------------------------------------*/
2071 function_prolog(mttlb3)
2072 TLBWE(4,3,2)
2073 blr
2074 function_epilog(mttlb3)
2075
2076/*----------------------------------------------------------------------------+
2077| mftlb3.
2078+----------------------------------------------------------------------------*/
2079 function_prolog(mftlb3)
Wolfgang Denk52232fd2007-02-27 14:26:04 +01002080 TLBRE(3,3,2)
Stefan Roesea8856e32007-02-20 10:57:08 +01002081 blr
2082 function_epilog(mftlb3)
2083
2084/*----------------------------------------------------------------------------+
2085| mttlb2.
2086+----------------------------------------------------------------------------*/
2087 function_prolog(mttlb2)
2088 TLBWE(4,3,1)
2089 blr
2090 function_epilog(mttlb2)
2091
2092/*----------------------------------------------------------------------------+
2093| mftlb2.
2094+----------------------------------------------------------------------------*/
2095 function_prolog(mftlb2)
Wolfgang Denk52232fd2007-02-27 14:26:04 +01002096 TLBRE(3,3,1)
Stefan Roesea8856e32007-02-20 10:57:08 +01002097 blr
2098 function_epilog(mftlb2)
2099
2100/*----------------------------------------------------------------------------+
2101| mttlb1.
2102+----------------------------------------------------------------------------*/
2103 function_prolog(mttlb1)
2104 TLBWE(4,3,0)
2105 blr
2106 function_epilog(mttlb1)
2107
2108/*----------------------------------------------------------------------------+
2109| mftlb1.
2110+----------------------------------------------------------------------------*/
2111 function_prolog(mftlb1)
Wolfgang Denk52232fd2007-02-27 14:26:04 +01002112 TLBRE(3,3,0)
Stefan Roesea8856e32007-02-20 10:57:08 +01002113 blr
2114 function_epilog(mftlb1)
2115#endif /* CONFIG_440 */
Stefan Roese7d72e022008-06-02 14:35:44 +02002116
2117#if defined(CONFIG_NAND_SPL)
2118/*
2119 * void nand_boot_relocate(dst, src, bytes)
2120 *
2121 * r3 = Destination address to copy code to (in SDRAM)
2122 * r4 = Source address to copy code from
2123 * r5 = size to copy in bytes
2124 */
2125nand_boot_relocate:
2126 mr r6,r3
2127 mr r7,r4
2128 mflr r8
2129
2130 /*
2131 * Copy SPL from icache into SDRAM
2132 */
2133 subi r3,r3,4
2134 subi r4,r4,4
2135 srwi r5,r5,2
2136 mtctr r5
2137..spl_loop:
2138 lwzu r0,4(r4)
2139 stwu r0,4(r3)
2140 bdnz ..spl_loop
2141
2142 /*
2143 * Calculate "corrected" link register, so that we "continue"
2144 * in execution in destination range
2145 */
2146 sub r3,r7,r6 /* r3 = src - dst */
2147 sub r8,r8,r3 /* r8 = link-reg - (src - dst) */
2148 mtlr r8
2149 blr
2150
2151nand_boot_common:
2152 /*
2153 * First initialize SDRAM. It has to be available *before* calling
2154 * nand_boot().
2155 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02002156 lis r3,CONFIG_SYS_SDRAM_BASE@h
2157 ori r3,r3,CONFIG_SYS_SDRAM_BASE@l
Stefan Roese7d72e022008-06-02 14:35:44 +02002158 bl initdram
2159
2160 /*
2161 * Now copy the 4k SPL code into SDRAM and continue execution
2162 * from there.
2163 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02002164 lis r3,CONFIG_SYS_NAND_BOOT_SPL_DST@h
2165 ori r3,r3,CONFIG_SYS_NAND_BOOT_SPL_DST@l
2166 lis r4,CONFIG_SYS_NAND_BOOT_SPL_SRC@h
2167 ori r4,r4,CONFIG_SYS_NAND_BOOT_SPL_SRC@l
2168 lis r5,CONFIG_SYS_NAND_BOOT_SPL_SIZE@h
2169 ori r5,r5,CONFIG_SYS_NAND_BOOT_SPL_SIZE@l
Stefan Roese7d72e022008-06-02 14:35:44 +02002170 bl nand_boot_relocate
2171
2172 /*
2173 * We're running from SDRAM now!!!
2174 *
2175 * It is necessary for 4xx systems to relocate from running at
2176 * the original location (0xfffffxxx) to somewhere else (SDRAM
2177 * preferably). This is because CS0 needs to be reconfigured for
2178 * NAND access. And we can't reconfigure this CS when currently
2179 * "running" from it.
2180 */
2181
2182 /*
2183 * Finally call nand_boot() to load main NAND U-Boot image from
2184 * NAND and jump to it.
2185 */
2186 bl nand_boot /* will not return */
2187#endif /* CONFIG_NAND_SPL */