blob: 292393ec43e3fed949a8b0a935f5786bf5462a56 [file] [log] [blame]
Wolfgang Denk46263f22013-07-28 22:12:45 +02001/*
Wolfgang Denk1b387ef2013-09-17 11:24:06 +02002 * SPDX-License-Identifier: GPL-2.0 IBM-pibs
Wolfgang Denk46263f22013-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
wdenk7205e402003-09-10 22:30:53 +000023#include <configs/PIP405.h>
wdenkb573bf12002-07-16 18:49:25 +000024#include <ppc_asm.tmpl>
25#include <ppc_defs.h>
26
27#include <asm/cache.h>
28#include <asm/mmu.h>
Stefan Roeseafabb492010-09-12 06:21:37 +020029#include <asm/ppc4xx.h>
wdenk7205e402003-09-10 22:30:53 +000030#include "pip405.h"
wdenkb573bf12002-07-16 18:49:25 +000031
wdenk7205e402003-09-10 22:30:53 +000032 .globl ext_bus_cntlr_init
33 ext_bus_cntlr_init:
34 mflr r4 /* save link register */
Stefan Roesed1c3b272009-09-09 16:25:29 +020035 mfdcr r3,CPC0_PSR /* get strapping reg */
wdenk7205e402003-09-10 22:30:53 +000036 andi. r0, r3, PSR_ROM_LOC /* mask out irrelevant bits */
37 bnelr /* jump back if PCI boot */
wdenkb573bf12002-07-16 18:49:25 +000038
wdenkb573bf12002-07-16 18:49:25 +000039 bl ..getAddr
40..getAddr:
41 mflr r3 /* get address of ..getAddr */
42 mtlr r4 /* restore link register */
43 addi r4,0,14 /* set ctr to 14; used to prefetch */
44 mtctr r4 /* 14 cache lines to fit this function */
wdenk8bde7f72003-06-27 21:31:46 +000045 /* in cache (gives us 8x14=112 instrctns) */
wdenkb573bf12002-07-16 18:49:25 +000046..ebcloop:
47 icbt r0,r3 /* prefetch cache line for addr in r3 */
48 addi r3,r3,32 /* move to next cache line */
49 bdnz ..ebcloop /* continue for 14 cache lines */
50
51 /*-------------------------------------------------------------------
52 * Delay to ensure all accesses to ROM are complete before changing
53 * bank 0 timings.
54 *------------------------------------------------------------------- */
55 addis r3,0,0x0
56 ori r3,r3,0xA000
57 mtctr r3
58..spinlp:
59 bdnz ..spinlp /* spin loop */
60
61 /*-----------------------------------------------------------------------
62 * decide boot up mode
63 *----------------------------------------------------------------------- */
Stefan Roesed1c3b272009-09-09 16:25:29 +020064 addi r4,0,PB0CR
65 mtdcr EBC0_CFGADDR,r4
66 mfdcr r4,EBC0_CFGDATA
wdenkb573bf12002-07-16 18:49:25 +000067
68 andi. r0, r4, 0x2000 /* mask out irrelevant bits */
wdenk7205e402003-09-10 22:30:53 +000069 beq 0f /* jump if 8 bit bus width */
wdenkb573bf12002-07-16 18:49:25 +000070
71 /* setup 16 bit things
72 *-----------------------------------------------------------------------
73 * Memory Bank 0 (16 Bit Flash) initialization
74 *---------------------------------------------------------------------- */
75
Stefan Roesed1c3b272009-09-09 16:25:29 +020076 addi r4,0,PB1AP
77 mtdcr EBC0_CFGADDR,r4
wdenk7205e402003-09-10 22:30:53 +000078 addis r4,0,(FLASH_AP_B)@h
79 ori r4,r4,(FLASH_AP_B)@l
Stefan Roesed1c3b272009-09-09 16:25:29 +020080 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +000081
Stefan Roesed1c3b272009-09-09 16:25:29 +020082 addi r4,0,PB0CR
83 mtdcr EBC0_CFGADDR,r4
wdenk7205e402003-09-10 22:30:53 +000084 /* BS=0x010(4MB),BU=0x3(R/W), */
85 addis r4,0,(FLASH_CR_B)@h
86 ori r4,r4,(FLASH_CR_B)@l
Stefan Roesed1c3b272009-09-09 16:25:29 +020087 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +000088 b 1f
89
900:
wdenk7205e402003-09-10 22:30:53 +000091 /* 8Bit boot mode: */
wdenkb573bf12002-07-16 18:49:25 +000092 /*-----------------------------------------------------------------------
wdenk7205e402003-09-10 22:30:53 +000093 * Memory Bank 0 Multi Purpose Socket initialization
94 *----------------------------------------------------------------------- */
95 /* 0x7F8FFE80 slowest boot */
Stefan Roesed1c3b272009-09-09 16:25:29 +020096 addi r4,0,PB1AP
97 mtdcr EBC0_CFGADDR,r4
wdenk7205e402003-09-10 22:30:53 +000098 addis r4,0,(MPS_AP_B)@h
99 ori r4,r4,(MPS_AP_B)@l
Stefan Roesed1c3b272009-09-09 16:25:29 +0200100 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000101
Stefan Roesed1c3b272009-09-09 16:25:29 +0200102 addi r4,0,PB0CR
103 mtdcr EBC0_CFGADDR,r4
wdenk7205e402003-09-10 22:30:53 +0000104 /* BS=0x010(4MB),BU=0x3(R/W), */
105 addis r4,0,(MPS_CR_B)@h
106 ori r4,r4,(MPS_CR_B)@l
Stefan Roesed1c3b272009-09-09 16:25:29 +0200107 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000108
wdenkb573bf12002-07-16 18:49:25 +0000109
1101:
111 /*-----------------------------------------------------------------------
112 * Memory Bank 2-3-4-5-6 (not used) initialization
113 *-----------------------------------------------------------------------*/
Stefan Roesed1c3b272009-09-09 16:25:29 +0200114 addi r4,0,PB1CR
115 mtdcr EBC0_CFGADDR,r4
wdenk7205e402003-09-10 22:30:53 +0000116 addis r4,0,0x0000
117 ori r4,r4,0x0000
Stefan Roesed1c3b272009-09-09 16:25:29 +0200118 mtdcr EBC0_CFGDATA,r4
wdenk7205e402003-09-10 22:30:53 +0000119
Stefan Roesed1c3b272009-09-09 16:25:29 +0200120 addi r4,0,PB2CR
121 mtdcr EBC0_CFGADDR,r4
wdenkb573bf12002-07-16 18:49:25 +0000122 addis r4,0,0x0000
123 ori r4,r4,0x0000
Stefan Roesed1c3b272009-09-09 16:25:29 +0200124 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000125
Stefan Roesed1c3b272009-09-09 16:25:29 +0200126 addi r4,0,PB3CR
127 mtdcr EBC0_CFGADDR,r4
wdenkb573bf12002-07-16 18:49:25 +0000128 addis r4,0,0x0000
129 ori r4,r4,0x0000
Stefan Roesed1c3b272009-09-09 16:25:29 +0200130 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000131
Stefan Roesed1c3b272009-09-09 16:25:29 +0200132 addi r4,0,PB4CR
133 mtdcr EBC0_CFGADDR,r4
wdenkb573bf12002-07-16 18:49:25 +0000134 addis r4,0,0x0000
135 ori r4,r4,0x0000
Stefan Roesed1c3b272009-09-09 16:25:29 +0200136 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000137
Stefan Roesed1c3b272009-09-09 16:25:29 +0200138 addi r4,0,PB5CR
139 mtdcr EBC0_CFGADDR,r4
wdenkb573bf12002-07-16 18:49:25 +0000140 addis r4,0,0x0000
141 ori r4,r4,0x0000
Stefan Roesed1c3b272009-09-09 16:25:29 +0200142 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000143
Stefan Roesed1c3b272009-09-09 16:25:29 +0200144 addi r4,0,PB6CR
145 mtdcr EBC0_CFGADDR,r4
wdenkb573bf12002-07-16 18:49:25 +0000146 addis r4,0,0x0000
147 ori r4,r4,0x0000
Stefan Roesed1c3b272009-09-09 16:25:29 +0200148 mtdcr EBC0_CFGDATA,r4
wdenkb573bf12002-07-16 18:49:25 +0000149
Stefan Roesed1c3b272009-09-09 16:25:29 +0200150 addi r4,0,PB7CR
151 mtdcr EBC0_CFGADDR,r4
wdenk7205e402003-09-10 22:30:53 +0000152 addis r4,0,0x0000
153 ori r4,r4,0x0000
Stefan Roesed1c3b272009-09-09 16:25:29 +0200154 mtdcr EBC0_CFGDATA,r4
wdenk7205e402003-09-10 22:30:53 +0000155 nop /* pass2 DCR errata #8 */
wdenkb573bf12002-07-16 18:49:25 +0000156 blr
157
wdenk7205e402003-09-10 22:30:53 +0000158#if defined(CONFIG_BOOT_PCI)
159 .section .bootpg,"ax"
160 .globl _start_pci
161/*******************************************
162 */
163
164_start_pci:
165 /* first handle errata #68 / PCI_18 */
166 iccci r0, r0 /* invalidate I-cache */
167 lis r31, 0
168 mticcr r31 /* ICCR = 0 (all uncachable) */
169 isync
170
171 mfccr0 r28 /* set CCR0[24] = 1 */
172 ori r28, r28, 0x0080
173 mtccr0 r28
174
175 /* setup PMM0MA (0xEF400004) and PMM0PCIHA (0xEF40000C) */
176 lis r28, 0xEF40
177 addi r28, r28, 0x0004
178 stw r31, 0x0C(r28) /* clear PMM0PCIHA */
179 lis r29, 0xFFF8 /* open 512 kByte */
180 addi r29, r29, 0x0001/* and enable this region */
181 stwbrx r29, r0, r28 /* write PMM0MA */
182
183 lis r28, 0xEEC0 /* address of PCIC0_CFGADDR */
184 addi r29, r28, 4 /* add 4 to r29 -> PCIC0_CFGDATA */
185
186 lis r31, 0x8000 /* set en bit bus 0 */
187 ori r31, r31, 0x304C/* device 6 func 0 reg 4C (XBCS register) */
188 stwbrx r31, r0, r28 /* write it */
189
190 lwbrx r31, r0, r29 /* load XBCS register */
191 oris r31, r31, 0x02C4/* clear BIOSCS WPE, set lower, extended and 1M extended BIOS enable */
192 stwbrx r31, r0, r29 /* write back XBCS register */
193
194 nop
195 nop
196 b _start /* normal start */
197#endif