blob: 95fed34fcc948580eb937a92eaa403ae34964625 [file] [log] [blame]
Wolfgang Denk52744b42013-07-28 22:12:45 +02001/*
Wolfgang Denk815c9672013-09-17 11:24:06 +02002 * SPDX-License-Identifier: GPL-2.0 IBM-pibs
Wolfgang Denk52744b42013-07-28 22:12:45 +02003 */
wdenkb573bf12002-07-16 18:49:25 +00004/*-----------------------------------------------------------------------------
5 * Function: ext_bus_cntlr_init
6 * Description: Initializes the External Bus Controller for the external
7 * peripherals. IMPORTANT: For pass1 this code must run from
8 * cache since you can not reliably change a peripheral banks
9 * timing register (pbxap) while running code from that bank.
10 * For ex., since we are running from ROM on bank 0, we can NOT
11 * execute the code that modifies bank 0 timings from ROM, so
12 * we run it from cache.
13 * Bank 0 - Flash or Multi Purpose Socket
14 * Bank 1 - Multi Purpose Socket or Flash
15 * Bank 2 - not used
16 * Bank 3 - not used
17 * Bank 4 - not used
18 * Bank 5 - not used
19 * Bank 6 - used to switch on the 12V for the Multipurpose socket
20 * Bank 7 - Config Register
21 *-----------------------------------------------------------------------------*/
wdenkb573bf12002-07-16 18:49:25 +000022#define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
23
wdenk2c9b05d2003-09-10 22:30:53 +000024#include <configs/PIP405.h>
wdenkb573bf12002-07-16 18:49:25 +000025#include <ppc_asm.tmpl>
26#include <ppc_defs.h>
27
28#include <asm/cache.h>
29#include <asm/mmu.h>
Stefan Roese8cb251a2010-09-12 06:21:37 +020030#include <asm/ppc4xx.h>
wdenk2c9b05d2003-09-10 22:30:53 +000031#include "pip405.h"
wdenkb573bf12002-07-16 18:49:25 +000032
wdenk2c9b05d2003-09-10 22:30:53 +000033 .globl ext_bus_cntlr_init
34 ext_bus_cntlr_init:
35 mflr r4 /* save link register */
Stefan Roese918010a2009-09-09 16:25:29 +020036 mfdcr r3,CPC0_PSR /* get strapping reg */
wdenk2c9b05d2003-09-10 22:30:53 +000037 andi. r0, r3, PSR_ROM_LOC /* mask out irrelevant bits */
38 bnelr /* jump back if PCI boot */
wdenkb573bf12002-07-16 18:49:25 +000039
wdenkb573bf12002-07-16 18:49:25 +000040 bl ..getAddr
41..getAddr:
42 mflr r3 /* get address of ..getAddr */
43 mtlr r4 /* restore link register */
44 addi r4,0,14 /* set ctr to 14; used to prefetch */
45 mtctr r4 /* 14 cache lines to fit this function */
wdenk57b2d802003-06-27 21:31:46 +000046 /* in cache (gives us 8x14=112 instrctns) */
wdenkb573bf12002-07-16 18:49:25 +000047..ebcloop:
48 icbt r0,r3 /* prefetch cache line for addr in r3 */
49 addi r3,r3,32 /* move to next cache line */
50 bdnz ..ebcloop /* continue for 14 cache lines */
51
52 /*-------------------------------------------------------------------
53 * Delay to ensure all accesses to ROM are complete before changing
54 * bank 0 timings.
55 *------------------------------------------------------------------- */
56 addis r3,0,0x0
57 ori r3,r3,0xA000
58 mtctr r3
59..spinlp:
60 bdnz ..spinlp /* spin loop */
61
62 /*-----------------------------------------------------------------------
63 * decide boot up mode
64 *----------------------------------------------------------------------- */
Stefan Roese918010a2009-09-09 16:25:29 +020065 addi r4,0,PB0CR
66 mtdcr EBC0_CFGADDR,r4
67 mfdcr r4,EBC0_CFGDATA
wdenkb573bf12002-07-16 18:49:25 +000068
69 andi. r0, r4, 0x2000 /* mask out irrelevant bits */
wdenk2c9b05d2003-09-10 22:30:53 +000070 beq 0f /* jump if 8 bit bus width */
wdenkb573bf12002-07-16 18:49:25 +000071
72 /* setup 16 bit things
73 *-----------------------------------------------------------------------
74 * Memory Bank 0 (16 Bit Flash) initialization
75 *---------------------------------------------------------------------- */
76
Stefan Roese918010a2009-09-09 16:25:29 +020077 addi r4,0,PB1AP
78 mtdcr EBC0_CFGADDR,r4
wdenk2c9b05d2003-09-10 22:30:53 +000079 addis r4,0,(FLASH_AP_B)@h
80 ori r4,r4,(FLASH_AP_B)@l
Stefan Roese918010a2009-09-09 16:25:29 +020081 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +000082
Stefan Roese918010a2009-09-09 16:25:29 +020083 addi r4,0,PB0CR
84 mtdcr EBC0_CFGADDR,r4
wdenk2c9b05d2003-09-10 22:30:53 +000085 /* BS=0x010(4MB),BU=0x3(R/W), */
86 addis r4,0,(FLASH_CR_B)@h
87 ori r4,r4,(FLASH_CR_B)@l
Stefan Roese918010a2009-09-09 16:25:29 +020088 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +000089 b 1f
90
910:
wdenk2c9b05d2003-09-10 22:30:53 +000092 /* 8Bit boot mode: */
wdenkb573bf12002-07-16 18:49:25 +000093 /*-----------------------------------------------------------------------
wdenk2c9b05d2003-09-10 22:30:53 +000094 * Memory Bank 0 Multi Purpose Socket initialization
95 *----------------------------------------------------------------------- */
96 /* 0x7F8FFE80 slowest boot */
Stefan Roese918010a2009-09-09 16:25:29 +020097 addi r4,0,PB1AP
98 mtdcr EBC0_CFGADDR,r4
wdenk2c9b05d2003-09-10 22:30:53 +000099 addis r4,0,(MPS_AP_B)@h
100 ori r4,r4,(MPS_AP_B)@l
Stefan Roese918010a2009-09-09 16:25:29 +0200101 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000102
Stefan Roese918010a2009-09-09 16:25:29 +0200103 addi r4,0,PB0CR
104 mtdcr EBC0_CFGADDR,r4
wdenk2c9b05d2003-09-10 22:30:53 +0000105 /* BS=0x010(4MB),BU=0x3(R/W), */
106 addis r4,0,(MPS_CR_B)@h
107 ori r4,r4,(MPS_CR_B)@l
Stefan Roese918010a2009-09-09 16:25:29 +0200108 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000109
wdenk2c9b05d2003-09-10 22:30:53 +0000110
1111:
wdenkb573bf12002-07-16 18:49:25 +0000112 /*-----------------------------------------------------------------------
wdenk2c9b05d2003-09-10 22:30:53 +0000113 * Memory Bank 2-3-4-5-6 (not used) initialization
wdenkb573bf12002-07-16 18:49:25 +0000114 *-----------------------------------------------------------------------*/
Stefan Roese918010a2009-09-09 16:25:29 +0200115 addi r4,0,PB1CR
116 mtdcr EBC0_CFGADDR,r4
wdenk2c9b05d2003-09-10 22:30:53 +0000117 addis r4,0,0x0000
118 ori r4,r4,0x0000
Stefan Roese918010a2009-09-09 16:25:29 +0200119 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000120
Stefan Roese918010a2009-09-09 16:25:29 +0200121 addi r4,0,PB2CR
122 mtdcr EBC0_CFGADDR,r4
wdenkb573bf12002-07-16 18:49:25 +0000123 addis r4,0,0x0000
124 ori r4,r4,0x0000
Stefan Roese918010a2009-09-09 16:25:29 +0200125 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000126
Stefan Roese918010a2009-09-09 16:25:29 +0200127 addi r4,0,PB3CR
128 mtdcr EBC0_CFGADDR,r4
wdenkb573bf12002-07-16 18:49:25 +0000129 addis r4,0,0x0000
130 ori r4,r4,0x0000
Stefan Roese918010a2009-09-09 16:25:29 +0200131 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000132
Stefan Roese918010a2009-09-09 16:25:29 +0200133 addi r4,0,PB4CR
134 mtdcr EBC0_CFGADDR,r4
wdenkb573bf12002-07-16 18:49:25 +0000135 addis r4,0,0x0000
136 ori r4,r4,0x0000
Stefan Roese918010a2009-09-09 16:25:29 +0200137 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000138
Stefan Roese918010a2009-09-09 16:25:29 +0200139 addi r4,0,PB5CR
140 mtdcr EBC0_CFGADDR,r4
wdenkb573bf12002-07-16 18:49:25 +0000141 addis r4,0,0x0000
142 ori r4,r4,0x0000
Stefan Roese918010a2009-09-09 16:25:29 +0200143 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000144
Stefan Roese918010a2009-09-09 16:25:29 +0200145 addi r4,0,PB6CR
146 mtdcr EBC0_CFGADDR,r4
wdenkb573bf12002-07-16 18:49:25 +0000147 addis r4,0,0x0000
148 ori r4,r4,0x0000
Stefan Roese918010a2009-09-09 16:25:29 +0200149 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000150
Stefan Roese918010a2009-09-09 16:25:29 +0200151 addi r4,0,PB7CR
152 mtdcr EBC0_CFGADDR,r4
wdenk2c9b05d2003-09-10 22:30:53 +0000153 addis r4,0,0x0000
154 ori r4,r4,0x0000
Stefan Roese918010a2009-09-09 16:25:29 +0200155 mtdcr EBC0_CFGDATA,r4
wdenk2c9b05d2003-09-10 22:30:53 +0000156 nop /* pass2 DCR errata #8 */
wdenkb573bf12002-07-16 18:49:25 +0000157 blr
158
wdenk2c9b05d2003-09-10 22:30:53 +0000159#if defined(CONFIG_BOOT_PCI)
160 .section .bootpg,"ax"
161 .globl _start_pci
162/*******************************************
163 */
164
165_start_pci:
166 /* first handle errata #68 / PCI_18 */
167 iccci r0, r0 /* invalidate I-cache */
168 lis r31, 0
169 mticcr r31 /* ICCR = 0 (all uncachable) */
170 isync
171
172 mfccr0 r28 /* set CCR0[24] = 1 */
173 ori r28, r28, 0x0080
174 mtccr0 r28
175
176 /* setup PMM0MA (0xEF400004) and PMM0PCIHA (0xEF40000C) */
177 lis r28, 0xEF40
178 addi r28, r28, 0x0004
179 stw r31, 0x0C(r28) /* clear PMM0PCIHA */
180 lis r29, 0xFFF8 /* open 512 kByte */
181 addi r29, r29, 0x0001/* and enable this region */
182 stwbrx r29, r0, r28 /* write PMM0MA */
183
184 lis r28, 0xEEC0 /* address of PCIC0_CFGADDR */
185 addi r29, r28, 4 /* add 4 to r29 -> PCIC0_CFGDATA */
186
187 lis r31, 0x8000 /* set en bit bus 0 */
188 ori r31, r31, 0x304C/* device 6 func 0 reg 4C (XBCS register) */
189 stwbrx r31, r0, r28 /* write it */
190
191 lwbrx r31, r0, r29 /* load XBCS register */
192 oris r31, r31, 0x02C4/* clear BIOSCS WPE, set lower, extended and 1M extended BIOS enable */
193 stwbrx r31, r0, r29 /* write back XBCS register */
194
195 nop
196 nop
197 b _start /* normal start */
198#endif