blob: b77517fd5a80b2c4adc3a5ac8a5f2588be36c695 [file] [log] [blame]
wdenkb573bf12002-07-16 18:49:25 +00001/*------------------------------------------------------------------------------+
Josh Boyer31773492009-08-07 13:53:20 -04002 * This source code is dual-licensed. You may use it under the terms of
3 * the GNU General Public License version 2, or under the license below.
wdenkb573bf12002-07-16 18:49:25 +00004 *
5 * This source code has been made available to you by IBM on an AS-IS
6 * basis. Anyone receiving this source is licensed under IBM
7 * copyrights to use it in any way he or she deems fit, including
8 * copying it, modifying it, compiling it, and redistributing it either
9 * with or without modifications. No license under IBM patents or
10 * patent applications is to be implied by the copyright license.
11 *
12 * Any user of this software should understand that IBM cannot provide
13 * technical support for this software and will not be responsible for
14 * any consequences resulting from the use of this software.
15 *
16 * Any person who transfers this source code or any derivative work
17 * must include the IBM copyright notice, this paragraph, and the
18 * preceding two paragraphs in the transferred software.
19 *
20 * COPYRIGHT I B M CORPORATION 1995
21 * LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
22 *-------------------------------------------------------------------------------*/
23
24/*-----------------------------------------------------------------------------
25 * Function: ext_bus_cntlr_init
26 * Description: Initializes the External Bus Controller for the external
27 * peripherals. IMPORTANT: For pass1 this code must run from
28 * cache since you can not reliably change a peripheral banks
29 * timing register (pbxap) while running code from that bank.
30 * For ex., since we are running from ROM on bank 0, we can NOT
31 * execute the code that modifies bank 0 timings from ROM, so
32 * we run it from cache.
33 * Bank 0 - Flash or Multi Purpose Socket
34 * Bank 1 - Multi Purpose Socket or Flash
35 * Bank 2 - not used
36 * Bank 3 - not used
37 * Bank 4 - not used
38 * Bank 5 - not used
39 * Bank 6 - used to switch on the 12V for the Multipurpose socket
40 * Bank 7 - Config Register
41 *-----------------------------------------------------------------------------*/
wdenkb573bf12002-07-16 18:49:25 +000042#define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
43
wdenk7205e402003-09-10 22:30:53 +000044#include <configs/PIP405.h>
wdenkb573bf12002-07-16 18:49:25 +000045#include <ppc_asm.tmpl>
46#include <ppc_defs.h>
47
48#include <asm/cache.h>
49#include <asm/mmu.h>
Stefan Roeseafabb492010-09-12 06:21:37 +020050#include <asm/ppc4xx.h>
wdenk7205e402003-09-10 22:30:53 +000051#include "pip405.h"
wdenkb573bf12002-07-16 18:49:25 +000052
wdenk7205e402003-09-10 22:30:53 +000053 .globl ext_bus_cntlr_init
54 ext_bus_cntlr_init:
55 mflr r4 /* save link register */
Stefan Roesed1c3b272009-09-09 16:25:29 +020056 mfdcr r3,CPC0_PSR /* get strapping reg */
wdenk7205e402003-09-10 22:30:53 +000057 andi. r0, r3, PSR_ROM_LOC /* mask out irrelevant bits */
58 bnelr /* jump back if PCI boot */
wdenkb573bf12002-07-16 18:49:25 +000059
wdenkb573bf12002-07-16 18:49:25 +000060 bl ..getAddr
61..getAddr:
62 mflr r3 /* get address of ..getAddr */
63 mtlr r4 /* restore link register */
64 addi r4,0,14 /* set ctr to 14; used to prefetch */
65 mtctr r4 /* 14 cache lines to fit this function */
wdenk8bde7f72003-06-27 21:31:46 +000066 /* in cache (gives us 8x14=112 instrctns) */
wdenkb573bf12002-07-16 18:49:25 +000067..ebcloop:
68 icbt r0,r3 /* prefetch cache line for addr in r3 */
69 addi r3,r3,32 /* move to next cache line */
70 bdnz ..ebcloop /* continue for 14 cache lines */
71
72 /*-------------------------------------------------------------------
73 * Delay to ensure all accesses to ROM are complete before changing
74 * bank 0 timings.
75 *------------------------------------------------------------------- */
76 addis r3,0,0x0
77 ori r3,r3,0xA000
78 mtctr r3
79..spinlp:
80 bdnz ..spinlp /* spin loop */
81
82 /*-----------------------------------------------------------------------
83 * decide boot up mode
84 *----------------------------------------------------------------------- */
Stefan Roesed1c3b272009-09-09 16:25:29 +020085 addi r4,0,PB0CR
86 mtdcr EBC0_CFGADDR,r4
87 mfdcr r4,EBC0_CFGDATA
wdenkb573bf12002-07-16 18:49:25 +000088
89 andi. r0, r4, 0x2000 /* mask out irrelevant bits */
wdenk7205e402003-09-10 22:30:53 +000090 beq 0f /* jump if 8 bit bus width */
wdenkb573bf12002-07-16 18:49:25 +000091
92 /* setup 16 bit things
93 *-----------------------------------------------------------------------
94 * Memory Bank 0 (16 Bit Flash) initialization
95 *---------------------------------------------------------------------- */
96
Stefan Roesed1c3b272009-09-09 16:25:29 +020097 addi r4,0,PB1AP
98 mtdcr EBC0_CFGADDR,r4
wdenk7205e402003-09-10 22:30:53 +000099 addis r4,0,(FLASH_AP_B)@h
100 ori r4,r4,(FLASH_AP_B)@l
Stefan Roesed1c3b272009-09-09 16:25:29 +0200101 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000102
Stefan Roesed1c3b272009-09-09 16:25:29 +0200103 addi r4,0,PB0CR
104 mtdcr EBC0_CFGADDR,r4
wdenk7205e402003-09-10 22:30:53 +0000105 /* BS=0x010(4MB),BU=0x3(R/W), */
106 addis r4,0,(FLASH_CR_B)@h
107 ori r4,r4,(FLASH_CR_B)@l
Stefan Roesed1c3b272009-09-09 16:25:29 +0200108 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000109 b 1f
110
1110:
wdenk7205e402003-09-10 22:30:53 +0000112 /* 8Bit boot mode: */
wdenkb573bf12002-07-16 18:49:25 +0000113 /*-----------------------------------------------------------------------
wdenk7205e402003-09-10 22:30:53 +0000114 * Memory Bank 0 Multi Purpose Socket initialization
115 *----------------------------------------------------------------------- */
116 /* 0x7F8FFE80 slowest boot */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200117 addi r4,0,PB1AP
118 mtdcr EBC0_CFGADDR,r4
wdenk7205e402003-09-10 22:30:53 +0000119 addis r4,0,(MPS_AP_B)@h
120 ori r4,r4,(MPS_AP_B)@l
Stefan Roesed1c3b272009-09-09 16:25:29 +0200121 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000122
Stefan Roesed1c3b272009-09-09 16:25:29 +0200123 addi r4,0,PB0CR
124 mtdcr EBC0_CFGADDR,r4
wdenk7205e402003-09-10 22:30:53 +0000125 /* BS=0x010(4MB),BU=0x3(R/W), */
126 addis r4,0,(MPS_CR_B)@h
127 ori r4,r4,(MPS_CR_B)@l
Stefan Roesed1c3b272009-09-09 16:25:29 +0200128 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000129
wdenkb573bf12002-07-16 18:49:25 +0000130
1311:
132 /*-----------------------------------------------------------------------
133 * Memory Bank 2-3-4-5-6 (not used) initialization
134 *-----------------------------------------------------------------------*/
Stefan Roesed1c3b272009-09-09 16:25:29 +0200135 addi r4,0,PB1CR
136 mtdcr EBC0_CFGADDR,r4
wdenk7205e402003-09-10 22:30:53 +0000137 addis r4,0,0x0000
138 ori r4,r4,0x0000
Stefan Roesed1c3b272009-09-09 16:25:29 +0200139 mtdcr EBC0_CFGDATA,r4
wdenk7205e402003-09-10 22:30:53 +0000140
Stefan Roesed1c3b272009-09-09 16:25:29 +0200141 addi r4,0,PB2CR
142 mtdcr EBC0_CFGADDR,r4
wdenkb573bf12002-07-16 18:49:25 +0000143 addis r4,0,0x0000
144 ori r4,r4,0x0000
Stefan Roesed1c3b272009-09-09 16:25:29 +0200145 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000146
Stefan Roesed1c3b272009-09-09 16:25:29 +0200147 addi r4,0,PB3CR
148 mtdcr EBC0_CFGADDR,r4
wdenkb573bf12002-07-16 18:49:25 +0000149 addis r4,0,0x0000
150 ori r4,r4,0x0000
Stefan Roesed1c3b272009-09-09 16:25:29 +0200151 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000152
Stefan Roesed1c3b272009-09-09 16:25:29 +0200153 addi r4,0,PB4CR
154 mtdcr EBC0_CFGADDR,r4
wdenkb573bf12002-07-16 18:49:25 +0000155 addis r4,0,0x0000
156 ori r4,r4,0x0000
Stefan Roesed1c3b272009-09-09 16:25:29 +0200157 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000158
Stefan Roesed1c3b272009-09-09 16:25:29 +0200159 addi r4,0,PB5CR
160 mtdcr EBC0_CFGADDR,r4
wdenkb573bf12002-07-16 18:49:25 +0000161 addis r4,0,0x0000
162 ori r4,r4,0x0000
Stefan Roesed1c3b272009-09-09 16:25:29 +0200163 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000164
Stefan Roesed1c3b272009-09-09 16:25:29 +0200165 addi r4,0,PB6CR
166 mtdcr EBC0_CFGADDR,r4
wdenkb573bf12002-07-16 18:49:25 +0000167 addis r4,0,0x0000
168 ori r4,r4,0x0000
Stefan Roesed1c3b272009-09-09 16:25:29 +0200169 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000170
Stefan Roesed1c3b272009-09-09 16:25:29 +0200171 addi r4,0,PB7CR
172 mtdcr EBC0_CFGADDR,r4
wdenk7205e402003-09-10 22:30:53 +0000173 addis r4,0,0x0000
174 ori r4,r4,0x0000
Stefan Roesed1c3b272009-09-09 16:25:29 +0200175 mtdcr EBC0_CFGDATA,r4
wdenk7205e402003-09-10 22:30:53 +0000176 nop /* pass2 DCR errata #8 */
wdenkb573bf12002-07-16 18:49:25 +0000177 blr
178
wdenk7205e402003-09-10 22:30:53 +0000179#if defined(CONFIG_BOOT_PCI)
180 .section .bootpg,"ax"
181 .globl _start_pci
182/*******************************************
183 */
184
185_start_pci:
186 /* first handle errata #68 / PCI_18 */
187 iccci r0, r0 /* invalidate I-cache */
188 lis r31, 0
189 mticcr r31 /* ICCR = 0 (all uncachable) */
190 isync
191
192 mfccr0 r28 /* set CCR0[24] = 1 */
193 ori r28, r28, 0x0080
194 mtccr0 r28
195
196 /* setup PMM0MA (0xEF400004) and PMM0PCIHA (0xEF40000C) */
197 lis r28, 0xEF40
198 addi r28, r28, 0x0004
199 stw r31, 0x0C(r28) /* clear PMM0PCIHA */
200 lis r29, 0xFFF8 /* open 512 kByte */
201 addi r29, r29, 0x0001/* and enable this region */
202 stwbrx r29, r0, r28 /* write PMM0MA */
203
204 lis r28, 0xEEC0 /* address of PCIC0_CFGADDR */
205 addi r29, r28, 4 /* add 4 to r29 -> PCIC0_CFGDATA */
206
207 lis r31, 0x8000 /* set en bit bus 0 */
208 ori r31, r31, 0x304C/* device 6 func 0 reg 4C (XBCS register) */
209 stwbrx r31, r0, r28 /* write it */
210
211 lwbrx r31, r0, r29 /* load XBCS register */
212 oris r31, r31, 0x02C4/* clear BIOSCS WPE, set lower, extended and 1M extended BIOS enable */
213 stwbrx r31, r0, r29 /* write back XBCS register */
214
215 nop
216 nop
217 b _start /* normal start */
218#endif