blob: d3f6b2379455730aff58bca8d181fa086369dbed [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*-----------------------------------------------------------------------------+
2 *
3 * This source code has been made available to you by IBM on an AS-IS
4 * basis. Anyone receiving this source is licensed under IBM
5 * copyrights to use it in any way he or she deems fit, including
6 * copying it, modifying it, compiling it, and redistributing it either
7 * with or without modifications. No license under IBM patents or
8 * patent applications is to be implied by the copyright license.
9 *
10 * Any user of this software should understand that IBM cannot provide
11 * technical support for this software and will not be responsible for
12 * any consequences resulting from the use of this software.
13 *
14 * Any person who transfers this source code or any derivative work
15 * must include the IBM copyright notice, this paragraph, and the
16 * preceding two paragraphs in the transferred software.
17 *
18 * COPYRIGHT I B M CORPORATION 1995
19 * LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
20 *-----------------------------------------------------------------------------*/
21/*----------------------------------------------------------------------------+
22 *
23 * File Name: 405gp_pci.c
24 *
25 * Function: Initialization code for the 405GP PCI Configuration regs.
26 *
27 * Author: Mark Game
28 *
29 * Change Activity-
30 *
31 * Date Description of Change BY
32 * --------- --------------------- ---
33 * 09-Sep-98 Created MCG
34 * 02-Nov-98 Removed External arbiter selected message JWB
35 * 27-Nov-98 Zero out PTMBAR2 and disable in PTM2MS JWB
36 * 04-Jan-99 Zero out other unused PMM and PTM regs. Change bus scan MCG
37 * from (0 to n) to (1 to n).
38 * 17-May-99 Port to Walnut JWB
39 * 17-Jun-99 Updated for VGA support JWB
40 * 21-Jun-99 Updated to allow SRAM region to be a target from PCI bus JWB
41 * 19-Jul-99 Updated for 405GP pass 1 errata #26 (Low PCI subsequent MCG
42 * target latency timer values are not supported).
43 * Should be fixed in pass 2.
44 * 09-Sep-99 Removed use of PTM2 since the SRAM region no longer needs JWB
45 * to be a PCI target. Zero out PTMBAR2 and disable in PTM2MS.
46 * 10-Dec-99 Updated PCI_Write_CFG_Reg for pass2 errata #6 JWB
47 * 11-Jan-00 Ensure PMMxMAs disabled before setting PMMxLAs. This is not
48 * really required after a reset since PMMxMAs are already
49 * disabled but is a good practice nonetheless. JWB
50 * 12-Jun-01 stefan.roese@esd-electronics.com
51 * - PCI host/adapter handling reworked
52 * 09-Jul-01 stefan.roese@esd-electronics.com
53 * - PCI host now configures from device 0 (not 1) to max_dev,
54 * (host configures itself)
55 * - On CPCI-405 pci base address and size is generated from
56 * SDRAM and FLASH size (CFG regs not used anymore)
57 * - Some minor changes for CPCI-405-A (adapter version)
58 * 14-Sep-01 stefan.roese@esd-electronics.com
59 * - CONFIG_PCI_SCAN_SHOW added to print pci devices upon startup
60 * 28-Sep-01 stefan.roese@esd-electronics.com
61 * - Changed pci master configuration for linux compatibility
62 * (no need for bios_fixup() anymore)
63 * 26-Feb-02 stefan.roese@esd-electronics.com
64 * - Bug fixed in pci configuration (Andrew May)
65 * - Removed pci class code init for CPCI405 board
66 * 15-May-02 stefan.roese@esd-electronics.com
67 * - New vga device handling
68 * 29-May-02 stefan.roese@esd-electronics.com
69 * - PCI class code init added (if defined)
70 *----------------------------------------------------------------------------*/
71
72#include <common.h>
73#include <command.h>
wdenkc6097192002-11-03 00:24:07 +000074#if !defined(CONFIG_440)
75#include <405gp_pci.h>
76#endif
77#include <asm/processor.h>
78#include <pci.h>
79
stroese434979e2003-05-23 11:18:02 +000080#if defined(CONFIG_405GP) || defined(CONFIG_405EP)
wdenkc6097192002-11-03 00:24:07 +000081
82#ifdef CONFIG_PCI
83
84/*#define DEBUG*/
85
86/*-----------------------------------------------------------------------------+
87 * pci_init. Initializes the 405GP PCI Configuration regs.
88 *-----------------------------------------------------------------------------*/
89void pci_405gp_init(struct pci_controller *hose)
90{
91 DECLARE_GLOBAL_DATA_PTR;
92
93 int i, reg_num = 0;
94 bd_t *bd = gd->bd;
95
96 unsigned short temp_short;
97 unsigned long ptmpcila[2] = {CFG_PCI_PTM1PCI, CFG_PCI_PTM2PCI};
98#if defined(CONFIG_CPCI405)
99 unsigned long ptmla[2] = {bd->bi_memstart, bd->bi_flashstart};
100 unsigned long ptmms[2] = {~(bd->bi_memsize - 1) | 1, ~(bd->bi_flashsize - 1) | 1};
101#else
102 unsigned long ptmla[2] = {CFG_PCI_PTM1LA, CFG_PCI_PTM2LA};
103 unsigned long ptmms[2] = {CFG_PCI_PTM1MS, CFG_PCI_PTM2MS};
104#endif
105#if defined(CONFIG_PIP405) || defined (CONFIG_MIP405)
106 unsigned long pmmla[3] = {0x80000000, 0xA0000000, 0};
107 unsigned long pmmma[3] = {0xE0000001, 0xE0000001, 0};
108 unsigned long pmmpcila[3] = {0x80000000, 0x00000000, 0};
109 unsigned long pmmpciha[3] = {0x00000000, 0x00000000, 0};
110#else
111 unsigned long pmmla[3] = {0x80000000, 0,0};
112 unsigned long pmmma[3] = {0xC0000001, 0,0};
113 unsigned long pmmpcila[3] = {0x80000000, 0,0};
114 unsigned long pmmpciha[3] = {0x00000000, 0,0};
115#endif
116
117 /*
118 * Register the hose
119 */
120 hose->first_busno = 0;
121 hose->last_busno = 0xff;
122
123 /* ISA/PCI I/O space */
124 pci_set_region(hose->regions + reg_num++,
125 MIN_PCI_PCI_IOADDR,
126 MIN_PLB_PCI_IOADDR,
127 0x10000,
128 PCI_REGION_IO);
129
130 /* PCI I/O space */
131 pci_set_region(hose->regions + reg_num++,
132 0x00800000,
133 0xe8800000,
134 0x03800000,
135 PCI_REGION_IO);
136
137 reg_num = 2;
138
139 /* Memory spaces */
140 for (i=0; i<2; i++)
141 if (ptmms[i] & 1)
142 {
143 if (!i) hose->pci_fb = hose->regions + reg_num;
144
145 pci_set_region(hose->regions + reg_num++,
146 ptmpcila[i], ptmla[i],
147 ~(ptmms[i] & 0xfffff000) + 1,
148 PCI_REGION_MEM |
149 PCI_REGION_MEMORY);
150 }
151
152 /* PCI memory spaces */
153 for (i=0; i<3; i++)
154 if (pmmma[i] & 1)
155 {
156 pci_set_region(hose->regions + reg_num++,
157 pmmpcila[i], pmmla[i],
158 ~(pmmma[i] & 0xfffff000) + 1,
159 PCI_REGION_MEM);
160 }
161
162 hose->region_count = reg_num;
163
164 pci_setup_indirect(hose,
165 PCICFGADR,
166 PCICFGDATA);
167
168 if (hose->pci_fb)
169 pciauto_region_init(hose->pci_fb);
170
171 pci_register_hose(hose);
172
173 /*--------------------------------------------------------------------------+
174 * 405GP PCI Master configuration.
175 * Map one 512 MB range of PLB/processor addresses to PCI memory space.
176 * PLB address 0x80000000-0xBFFFFFFF ==> PCI address 0x80000000-0xBFFFFFFF
177 * Use byte reversed out routines to handle endianess.
178 *--------------------------------------------------------------------------*/
wdenke39c2842003-06-04 15:05:30 +0000179 out32r(PMM0MA, (pmmma[0]&~0x1)); /* disable, configure PMMxLA, PMMxPCILA first */
wdenkc6097192002-11-03 00:24:07 +0000180 out32r(PMM0LA, pmmla[0]);
181 out32r(PMM0PCILA, pmmpcila[0]);
182 out32r(PMM0PCIHA, pmmpciha[0]);
183 out32r(PMM0MA, pmmma[0]);
184
185 /*--------------------------------------------------------------------------+
186 * PMM1 is not used. Initialize them to zero.
187 *--------------------------------------------------------------------------*/
wdenke39c2842003-06-04 15:05:30 +0000188 out32r(PMM1MA, (pmmma[1]&~0x1));
wdenkc6097192002-11-03 00:24:07 +0000189 out32r(PMM1LA, pmmla[1]);
190 out32r(PMM1PCILA, pmmpcila[1]);
191 out32r(PMM1PCIHA, pmmpciha[1]);
192 out32r(PMM1MA, pmmma[1]);
193
194 /*--------------------------------------------------------------------------+
195 * PMM2 is not used. Initialize them to zero.
196 *--------------------------------------------------------------------------*/
wdenk57b2d802003-06-27 21:31:46 +0000197 out32r(PMM2MA, (pmmma[2]&~0x1));
wdenkc6097192002-11-03 00:24:07 +0000198 out32r(PMM2LA, pmmla[2]);
199 out32r(PMM2PCILA, pmmpcila[2]);
200 out32r(PMM2PCIHA, pmmpciha[2]);
201 out32r(PMM2MA, pmmma[2]);
202
203 /*--------------------------------------------------------------------------+
204 * 405GP PCI Target configuration. (PTM1)
205 * Note: PTM1MS is hardwire enabled but we set the enable bit anyway.
206 *--------------------------------------------------------------------------*/
207 out32r(PTM1LA, ptmla[0]); /* insert address */
208 out32r(PTM1MS, ptmms[0]); /* insert size, enable bit is 1 */
wdenk6fcda222003-10-22 09:00:28 +0000209 pci_write_config_dword(PCIDEVID_405GP, PCI_BASE_ADDRESS_1, ptmpcila[0]);
wdenkc6097192002-11-03 00:24:07 +0000210
211 /*--------------------------------------------------------------------------+
212 * 405GP PCI Target configuration. (PTM2)
213 *--------------------------------------------------------------------------*/
214 out32r(PTM2LA, ptmla[1]); /* insert address */
wdenk6fcda222003-10-22 09:00:28 +0000215 pci_write_config_dword(PCIDEVID_405GP, PCI_BASE_ADDRESS_2, ptmpcila[1]);
216
wdenkc6097192002-11-03 00:24:07 +0000217 if (ptmms[1] == 0)
218 {
219 out32r(PTM2MS, 0x00000001); /* set enable bit */
220 pci_write_config_dword(PCIDEVID_405GP, PCI_BASE_ADDRESS_2, 0x00000000);
221 out32r(PTM2MS, 0x00000000); /* disable */
222 }
223 else
224 {
225 out32r(PTM2MS, ptmms[1]); /* insert size, enable bit is 1 */
226 }
227
228 /*
229 * Insert Subsystem Vendor and Device ID
230 */
231 pci_write_config_word(PCIDEVID_405GP, PCI_SUBSYSTEM_VENDOR_ID, CFG_PCI_SUBSYS_VENDORID);
232#ifdef CONFIG_CPCI405
233 if (mfdcr(strap) & PSR_PCI_ARBIT_EN)
234 pci_write_config_word(PCIDEVID_405GP, PCI_SUBSYSTEM_ID, CFG_PCI_SUBSYS_DEVICEID);
235 else
236 pci_write_config_word(PCIDEVID_405GP, PCI_SUBSYSTEM_ID, CFG_PCI_SUBSYS_DEVICEID2);
237#else
238 pci_write_config_word(PCIDEVID_405GP, PCI_SUBSYSTEM_ID, CFG_PCI_SUBSYS_DEVICEID);
239#endif
240
241 /*
242 * Insert Class-code
243 */
244#ifdef CFG_PCI_CLASSCODE
245 pci_write_config_word(PCIDEVID_405GP, PCI_CLASS_SUB_CODE, CFG_PCI_CLASSCODE);
246#endif /* CFG_PCI_CLASSCODE */
247
248 /*--------------------------------------------------------------------------+
249 * If PCI speed = 66Mhz, set 66Mhz capable bit.
250 *--------------------------------------------------------------------------*/
251 if (bd->bi_pci_busfreq >= 66000000) {
252 pci_read_config_word(PCIDEVID_405GP, PCI_STATUS, &temp_short);
253 pci_write_config_word(PCIDEVID_405GP,PCI_STATUS,(temp_short|PCI_STATUS_66MHZ));
254 }
255
256#if (CONFIG_PCI_HOST != PCI_HOST_ADAPTER)
wdenk6fcda222003-10-22 09:00:28 +0000257#if (CONFIG_PCI_HOST == PCI_HOST_AUTO)
wdenkc6097192002-11-03 00:24:07 +0000258 if (mfdcr(strap) & PSR_PCI_ARBIT_EN)
259#endif
260 {
261 /*--------------------------------------------------------------------------+
262 * Write the 405GP PCI Configuration regs.
263 * Enable 405GP to be a master on the PCI bus (PMM).
264 * Enable 405GP to act as a PCI memory target (PTM).
265 *--------------------------------------------------------------------------*/
266 pci_read_config_word(PCIDEVID_405GP, PCI_COMMAND, &temp_short);
267 pci_write_config_word(PCIDEVID_405GP, PCI_COMMAND, temp_short |
268 PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
269 }
270#endif
271
stroese79435e32003-09-12 08:52:09 +0000272#if defined(CONFIG_405EP) /* on ppc405ep vendor id is not set */
273 pci_write_config_word(PCIDEVID_405GP, PCI_VENDOR_ID, 0x1014); /* IBM */
274#endif
275
wdenkc6097192002-11-03 00:24:07 +0000276 /*
277 * Set HCE bit (Host Configuration Enabled)
278 */
279 pci_read_config_word(PCIDEVID_405GP, PCIBRDGOPT2, &temp_short);
280 pci_write_config_word(PCIDEVID_405GP, PCIBRDGOPT2, (temp_short | 0x0001));
281
282#ifdef CONFIG_PCI_PNP
283 /*--------------------------------------------------------------------------+
284 * Scan the PCI bus and configure devices found.
285 *--------------------------------------------------------------------------*/
286#if (CONFIG_PCI_HOST == PCI_HOST_AUTO)
287 if (mfdcr(strap) & PSR_PCI_ARBIT_EN)
288#endif
289 {
290#ifdef CONFIG_PCI_SCAN_SHOW
291 printf("PCI: Bus Dev VenId DevId Class Int\n");
292#endif
293
294 hose->last_busno = pci_hose_scan(hose);
295 }
296#endif /* CONFIG_PCI_PNP */
297
298}
299
300/*
301 * drivers/pci.c skips every host bridge but the 405GP since it could
302 * be set as an Adapter.
303 *
304 * I (Andrew May) don't know what we should do here, but I don't want
305 * the auto setup of a PCI device disabling what is done pci_405gp_init
306 * as has happened before.
307 */
308void pci_405gp_setup_bridge(struct pci_controller *hose, pci_dev_t dev,
309 struct pci_config_table *entry)
310{
311#ifdef DEBUG
wdenk57b2d802003-06-27 21:31:46 +0000312 printf("405gp_setup_bridge\n");
wdenkc6097192002-11-03 00:24:07 +0000313#endif
314}
315
316/*
317 *
318 */
319
320void pci_405gp_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
321{
322 unsigned char int_line = 0xff;
323
324 /*
325 * Write pci interrupt line register (cpci405 specific)
326 */
327 switch (PCI_DEV(dev) & 0x03)
328 {
329 case 0:
330 int_line = 27 + 2;
331 break;
332 case 1:
333 int_line = 27 + 3;
334 break;
335 case 2:
336 int_line = 27 + 0;
337 break;
338 case 3:
339 int_line = 27 + 1;
340 break;
341 }
342
343 pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, int_line);
344}
345
346void pci_405gp_setup_vga(struct pci_controller *hose, pci_dev_t dev,
347 struct pci_config_table *entry)
348{
349 unsigned int cmdstat = 0;
350
351 pciauto_setup_device(hose, dev, 6, hose->pci_mem, hose->pci_io);
352
353 /* always enable io space on vga boards */
354 pci_hose_read_config_dword(hose, dev, PCI_COMMAND, &cmdstat);
355 cmdstat |= PCI_COMMAND_IO;
356 pci_hose_write_config_dword(hose, dev, PCI_COMMAND, cmdstat);
357}
358
359#if !(defined(CONFIG_PIP405) || defined (CONFIG_MIP405))
360
361/*
362 *As is these functs get called out of flash Not a horrible
363 *thing, but something to keep in mind. (no statics?)
364 */
365static struct pci_config_table pci_405gp_config_table[] = {
366/*if VendID is 0 it terminates the table search (ie Walnut)*/
367#if CFG_PCI_SUBSYS_VENDORID
368 {CFG_PCI_SUBSYS_VENDORID, PCI_ANY_ID, PCI_CLASS_BRIDGE_HOST,
369 PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, pci_405gp_setup_bridge},
370#endif
371 {PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA,
372 PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, pci_405gp_setup_vga},
373
374 {PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NOT_DEFINED_VGA,
375 PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, pci_405gp_setup_vga},
376
377 { }
378};
379
380static struct pci_controller hose = {
381 fixup_irq: pci_405gp_fixup_irq,
382 config_table: pci_405gp_config_table,
383};
384
stroesef5dd4102003-02-14 11:21:23 +0000385void pci_init_board(void)
wdenkc6097192002-11-03 00:24:07 +0000386{
387 /*we want the ptrs to RAM not flash (ie don't use init list)*/
388 hose.fixup_irq = pci_405gp_fixup_irq;
389 hose.config_table = pci_405gp_config_table;
390 pci_405gp_init(&hose);
391}
392
393#endif
394
395#endif /* CONFIG_PCI */
396
397#endif /* CONFIG_405GP */
398
399/*-----------------------------------------------------------------------------+
400 * CONFIG_440
401 *-----------------------------------------------------------------------------*/
402#if defined(CONFIG_440) && defined(CONFIG_PCI)
403
404static struct pci_controller ppc440_hose = {0};
405
406
407void pci_440_init (struct pci_controller *hose)
408{
409 int reg_num = 0;
410 unsigned long strap;
411
412 /*--------------------------------------------------------------------------+
413 * The PCI initialization sequence enable bit must be set ... if not abort
414 * pci setup since updating the bit requires chip reset.
415 *--------------------------------------------------------------------------*/
416 strap = mfdcr(cpc0_strp1);
417 if( (strap & 0x00040000) == 0 ){
wdenk57b2d802003-06-27 21:31:46 +0000418 printf("PCI: CPC0_STRP1[PISE] not set.\n");
419 printf("PCI: Configuration aborted.\n");
420 return;
wdenkc6097192002-11-03 00:24:07 +0000421 }
422
423 /*--------------------------------------------------------------------------+
424 * PCI controller init
425 *--------------------------------------------------------------------------*/
426 hose->first_busno = 0;
427 hose->last_busno = 0xff;
428
429 pci_set_region(hose->regions + reg_num++,
430 0x00000000,
431 PCIX0_IOBASE,
432 0x10000,
433 PCI_REGION_IO);
434
435 pci_set_region(hose->regions + reg_num++,
436 CFG_PCI_TARGBASE,
437 CFG_PCI_MEMBASE,
438 0x10000000,
439 PCI_REGION_MEM );
440 hose->region_count = reg_num;
441
442 pci_setup_indirect(hose, PCIX0_CFGADR, PCIX0_CFGDATA);
443
444#if defined(CFG_PCI_PRE_INIT)
445 /* Let board change/modify hose & do initial checks */
446 if( pci_pre_init (hose) == 0 ){
wdenk57b2d802003-06-27 21:31:46 +0000447 printf("PCI: Board-specific initialization failed.\n");
448 printf("PCI: Configuration aborted.\n");
449 return;
wdenkc6097192002-11-03 00:24:07 +0000450 }
451#endif
452
453 pci_register_hose( hose );
454
455 /*--------------------------------------------------------------------------+
456 * PCI target init
457 *--------------------------------------------------------------------------*/
458#if defined(CFG_PCI_TARGET_INIT)
459 pci_target_init(hose); /* Let board setup pci target */
460#else
461 out16r( PCIX0_SBSYSVID, CFG_PCI_SUBSYS_VENDORID );
462 out16r( PCIX0_SBSYSID, CFG_PCI_SUBSYS_ID );
463 out16r( PCIX0_CLS, 0x00060000 ); /* Bridge, host bridge */
464#endif
465
466 out32r( PCIX0_BRDGOPT1, 0x10000060 ); /* PLB Rq pri highest */
467 out32r( PCIX0_BRDGOPT2, in32(PCIX0_BRDGOPT2) | 1 ); /* Enable host config */
468
469 /*--------------------------------------------------------------------------+
470 * PCI master init: default is one 256MB region for PCI memory:
471 * 0x3_00000000 - 0x3_0FFFFFFF ==> CFG_PCI_MEMBASE
472 *--------------------------------------------------------------------------*/
473#if defined(CFG_PCI_MASTER_INIT)
474 pci_master_init(hose); /* Let board setup pci master */
475#else
476 out32r( PCIX0_POM0SA, 0 ); /* disable */
477 out32r( PCIX0_POM1SA, 0 ); /* disable */
478 out32r( PCIX0_POM2SA, 0 ); /* disable */
479 out32r( PCIX0_POM0LAL, 0x00000000 );
480 out32r( PCIX0_POM0LAH, 0x00000003 );
481 out32r( PCIX0_POM0PCIAL, CFG_PCI_MEMBASE );
482 out32r( PCIX0_POM0PCIAH, 0x00000000 );
483 out32r( PCIX0_POM0SA, 0xf0000001 ); /* 256MB, enabled */
484 out32r( PCIX0_STS, in32r( PCIX0_STS ) & ~0x0000fff8 );
485#endif
486
487 /*--------------------------------------------------------------------------+
488 * PCI host configuration -- we don't make any assumptions here ... the
489 * _board_must_indicate_ what to do -- there's just too many runtime
490 * scenarios in environments like cPCI, PPMC, etc. to make a determination
491 * based on hard-coded values or state of arbiter enable.
492 *--------------------------------------------------------------------------*/
493 if( is_pci_host(hose) ){
494#ifdef CONFIG_PCI_SCAN_SHOW
wdenk57b2d802003-06-27 21:31:46 +0000495 printf("PCI: Bus Dev VenId DevId Class Int\n");
wdenkc6097192002-11-03 00:24:07 +0000496#endif
wdenk57b2d802003-06-27 21:31:46 +0000497 out16r( PCIX0_CMD, in16r( PCIX0_CMD ) | PCI_COMMAND_MASTER);
498 hose->last_busno = pci_hose_scan(hose);
wdenkc6097192002-11-03 00:24:07 +0000499 }
500}
501
502
stroesef5dd4102003-02-14 11:21:23 +0000503void pci_init_board(void)
wdenkc6097192002-11-03 00:24:07 +0000504{
505 pci_440_init (&ppc440_hose);
506}
507
508#endif /* CONFIG_440 & CONFIG_PCI */