2 * SPDX-License-Identifier: GPL-2.0 IBM-pibs
5 #include <asm/ppc4xx.h>
7 #include <ppc_asm.tmpl>
10 #include <asm/cache.h>
14 * ext_bus_cntlr_init - Initializes the External Bus Controller for the external peripherals
16 * IMPORTANT: For pass1 this code must run from cache since you can not
17 * reliably change a peripheral banks timing register (pbxap) while running
18 * code from that bank. For ex., since we are running from ROM on bank 0, we
19 * can NOT execute the code that modifies bank 0 timings from ROM, so
20 * we run it from cache.
25 * Bank 3 - Second Flash
26 * Bank 4 - USB controller
28 .globl ext_bus_cntlr_init
31 * We need the current boot up configuration to set correct
32 * timings into internal flash and external flash
34 mfdcr r24,CPC0_PSR /* xxxx xxxx xxxx xxx? ?xxx xxxx xxxx xxxx
35 0 0 -> 8 bit external ROM
36 0 1 -> 16 bit internal ROM */
38 srw r24,r24,r4 /* shift right r24 two positions */
41 * All calculations are based on 33MHz EBC clock.
43 * First, create a "very slow" timing (~250ns) with burst mode enabled
44 * This is need for the external flash access
47 /* 0000 1000 0xxx 0000 0000 0010 100x xxxx = 0x03800280 */
50 * Second, create a fast timing:
51 * 90ns first cycle - 3 clock access
52 * and 90ns burst cycle, plus 1 clock after the last access
53 * This is used for the internal access
56 /* 1000 1001 0xxx 0000 0000 0010 100x xxxx */
59 * We can't change settings on CS# if we currently use them.
60 * -> load a few instructions into cache and run this code from cache
62 mflr r4 /* save link register */
65 mflr r3 /* get address of ..getAddr */
66 mtlr r4 /* restore link register */
67 addi r4,0,14 /* set ctr to 10; used to prefetch */
68 mtctr r4 /* 10 cache lines to fit this function
69 in cache (gives us 8x10=80 instructions) */
71 icbt r0,r3 /* prefetch cache line for addr in r3 */
72 addi r3,r3,32 /* move to next cache line */
73 bdnz ..ebcloop /* continue for 10 cache lines */
75 * Delay to ensure all accesses to ROM are complete before changing
76 * bank 0 timings. 200usec should be enough.
77 * 200,000,000 (cycles/sec) X .000200 (sec) = 0x9C40 cycles
80 ori r3,r3,0xA000 /* ensure 200usec have passed since reset */
83 bdnz ..spinlp /* spin loop */
85 /*-----------------------------------------------------------------------
86 * Memory Bank 0 (BOOT-ROM) initialization
87 * 0xFFEF00000....0xFFFFFFF
88 * We only have to change the timing. Mapping is ok by boot-strapping
89 *----------------------------------------------------------------------- */
91 li r4,PB1AP /* PB0AP=Peripheral Bank 0 Access Parameters */
94 mr r4,r26 /* assume internal fast flash is boot flash */
95 cmpwi r24,0x2000 /* assumption true? ... */
97 mr r4,r25 /* ...no, use the slow variant */
98 mr r25,r26 /* use this for the other flash */
100 mtdcr EBC0_CFGDATA,r4 /* change timing now */
102 li r4,PB0CR /* PB0CR=Peripheral Bank 0 Control Register */
103 mtdcr EBC0_CFGADDR,r4
104 mfdcr r4,EBC0_CFGDATA
106 ori r3,r3,0x8000 /* allow reads and writes */
108 mtdcr EBC0_CFGDATA,r4
110 /*-----------------------------------------------------------------------
111 * Memory Bank 3 (Second-Flash) initialization
112 * 0xF0000000...0xF01FFFFF -> 2MB
113 *----------------------------------------------------------------------- */
115 li r4,PB3AP /* Peripheral Bank 1 Access Parameter */
116 mtdcr EBC0_CFGADDR,r4
117 mtdcr EBC0_CFGDATA,r2 /* change timing */
119 li r4,PB3CR /* Peripheral Bank 1 Configuration Registers */
120 mtdcr EBC0_CFGADDR,r4
125 * Consider boot configuration
127 xori r24,r24,0x2000 /* invert current bus width */
129 mtdcr EBC0_CFGDATA,r4
131 /*-----------------------------------------------------------------------
132 * Memory Bank 1 (NAND-Flash) initialization
133 * 0x77D00000...0x77DFFFFF -> 1MB
134 * - the write/read pulse to the NAND can be as short as 25ns, bus the cycle time is always 50ns
135 * - the setup time is 0ns
136 * - the hold time is 15ns
144 * ----> 2 clocks per cycle = 60ns cycle (30ns active, 30ns hold)
145 *----------------------------------------------------------------------- */
147 li r4,PB1AP /* Peripheral Bank 1 Access Parameter */
148 mtdcr EBC0_CFGADDR,r4
152 mtdcr EBC0_CFGDATA,r4
154 li r4,PB1CR /* Peripheral Bank 1 Configuration Registers */
155 mtdcr EBC0_CFGADDR,r4
159 mtdcr EBC0_CFGDATA,r4
162 /* USB init (without acceleration) */
163 #ifndef CONFIG_ISP1161_PRESENT
164 li r4,PB4AP /* PB4AP=Peripheral Bank 4 Access Parameters */
165 mtdcr EBC0_CFGADDR,r4
168 mtdcr EBC0_CFGDATA,r4
171 /*-----------------------------------------------------------------------
172 * Memory Bank 2 (ISA Access) initialization (plus memory bank 6 and 7)
173 * 0x78000000...0x7BFFFFFF -> 64 MB
174 * Wir arbeiten bei 33 MHz -> 30ns
175 *-----------------------------------------------------------------------
177 A7 (ppc notation) or A24 (standard notation) decides about
179 A7/A24=0 -> memory cycle
180 A7/ /A24=1 -> I/O cycle
182 li r4,PB2AP /* PB2AP=Peripheral Bank 2 Access Parameters */
183 mtdcr EBC0_CFGADDR,r4
185 We emulate an ISA access
188 2. wait 0 EBC clocks -> CSN=0
190 4. wait 0 EBC clock -> OEN/WBN=0
192 6. wait 4 clocks (ca. 90ns) and for Ready signal
193 7. hold for 4 clocks -> TH=4
197 /* faster access to isa-bus */
204 mtdcr EBC0_CFGDATA,r4
206 #ifdef IDE_USES_ISA_EMULATION
207 li r25,PB5AP /* PB5AP=Peripheral Bank 5 Access Parameters */
208 mtdcr EBC0_CFGADDR,r25
209 mtdcr EBC0_CFGDATA,r4
212 li r25,PB6AP /* PB6AP=Peripheral Bank 6 Access Parameters */
213 mtdcr EBC0_CFGADDR,r25
214 mtdcr EBC0_CFGDATA,r4
215 li r25,PB7AP /* PB7AP=Peripheral Bank 7 Access Parameters */
216 mtdcr EBC0_CFGADDR,r25
217 mtdcr EBC0_CFGDATA,r4
219 li r25,PB2CR /* PB2CR=Peripheral Bank 2 Configuration Register */
220 mtdcr EBC0_CFGADDR,r25
224 mtdcr EBC0_CFGDATA,r4
226 * the other areas are only 1MiB in size
231 li r25,PB6CR /* PB6CR=Peripheral Bank 6 Configuration Register */
232 mtdcr EBC0_CFGADDR,r25
235 mtdcr EBC0_CFGDATA,r4
237 li r25,PB7CR /* PB7CR=Peripheral Bank 7 Configuration Register */
238 mtdcr EBC0_CFGADDR,r25
241 mtdcr EBC0_CFGDATA,r4
243 #ifndef CONFIG_ISP1161_PRESENT
244 li r25,PB4CR /* PB4CR=Peripheral Bank 4 Configuration Register */
245 mtdcr EBC0_CFGADDR,r25
248 mtdcr EBC0_CFGDATA,r4
250 #ifdef IDE_USES_ISA_EMULATION
251 li r25,PB5CR /* PB5CR=Peripheral Bank 5 Configuration Register */
252 mtdcr EBC0_CFGADDR,r25
255 mtdcr EBC0_CFGDATA,r4
258 /*-----------------------------------------------------------------------
259 * Memory bank 4: USB controller Philips ISP6111
260 * 0x77C00000 ... 0x77CFFFFF
262 * The chip is connected to:
268 * - command to first data: 300ns. Software must ensure this timing!
269 * - Write pulse: 26ns
271 * - read cycle time: 150ns
272 * - write cycle time: 140ns
274 * Note: All calculations are based on 33MHz EBC clock. One '#' or '_' is 30ns
277 * |---- 420ns ---|---- 420ns ---| cycle
278 * CS ############:###____#######:###____#######
279 * OE ############:####___#######:####___#######
280 * WE ############:####__########:####__########
282 * ----> 2 clocks RD/WR pulses: 60ns
283 * ----> CSN: 3 clock, 90ns
284 * ----> OEN: 1 clocks (read cycle)
285 * ----> WBN: 1 clocks (write cycle)
286 * ----> WBE: 2 clocks
287 * ----> TH: 7 clock, 210ns
288 * ----> TWT: 7 clocks
289 *----------------------------------------------------------------------- */
291 #ifdef CONFIG_ISP1161_PRESENT
293 li r4,PB4AP /* PB4AP=Peripheral Bank 4 Access Parameters */
294 mtdcr EBC0_CFGADDR,r4
298 mtdcr EBC0_CFGDATA,r4
300 li r4,PB4CR /* PB2CR=Peripheral Bank 4 Configuration Register */
301 mtdcr EBC0_CFGADDR,r4
305 mtdcr EBC0_CFGDATA,r4
309 #ifndef IDE_USES_ISA_EMULATION
311 /*-----------------------------------------------------------------------
312 * Memory Bank 5 used for IDE access
314 * Timings for IDE Interface
316 * SETUP / LENGTH / HOLD - cycles valid for 33.3 MHz clk -> 30ns cycle time
317 * 70 165 30 PIO-Mode 0, [ns]
318 * 3 6 1 [Cycles] ----> AP=0x040C0200
319 * 50 125 20 PIO-Mode 1, [ns]
320 * 2 5 1 [Cycles] ----> AP=0x03080200
321 * 30 100 15 PIO-Mode 2, [ns]
322 * 1 4 1 [Cycles] ----> AP=0x02040200
323 * 30 80 10 PIO-Mode 3, [ns]
324 * 1 3 1 [Cycles] ----> AP=0x01840200
325 * 25 70 10 PIO-Mode 4, [ns]
326 * 1 3 1 [Cycles] ----> AP=0x01840200
328 *----------------------------------------------------------------------- */
331 mtdcr EBC0_CFGADDR,r4
334 mtdcr EBC0_CFGDATA,r4
336 li r4,PB5CR /* PB2CR=Peripheral Bank 2 Configuration Register */
337 mtdcr EBC0_CFGADDR,r4
341 mtdcr EBC0_CFGDATA,r4
344 * External Peripheral Control Register
347 mtdcr EBC0_CFGADDR,r4
351 mtdcr EBC0_CFGDATA,r4
358 stb r3,0(r4) /* 01 -> external bus controller is initialized */
359 nop /* pass2 DCR errata #8 */