blob: 20e134b63e9ddb9cf3033eaa9675fd2cd398f16f [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +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.
wdenkc6097192002-11-03 00:24:07 +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 * File Name: 405gp_pci.c
26 *
27 * Function: Initialization code for the 405GP PCI Configuration regs.
28 *
29 * Author: Mark Game
30 *
31 * Change Activity-
32 *
33 * Date Description of Change BY
34 * --------- --------------------- ---
35 * 09-Sep-98 Created MCG
36 * 02-Nov-98 Removed External arbiter selected message JWB
37 * 27-Nov-98 Zero out PTMBAR2 and disable in PTM2MS JWB
38 * 04-Jan-99 Zero out other unused PMM and PTM regs. Change bus scan MCG
39 * from (0 to n) to (1 to n).
40 * 17-May-99 Port to Walnut JWB
41 * 17-Jun-99 Updated for VGA support JWB
42 * 21-Jun-99 Updated to allow SRAM region to be a target from PCI bus JWB
43 * 19-Jul-99 Updated for 405GP pass 1 errata #26 (Low PCI subsequent MCG
44 * target latency timer values are not supported).
45 * Should be fixed in pass 2.
46 * 09-Sep-99 Removed use of PTM2 since the SRAM region no longer needs JWB
47 * to be a PCI target. Zero out PTMBAR2 and disable in PTM2MS.
48 * 10-Dec-99 Updated PCI_Write_CFG_Reg for pass2 errata #6 JWB
49 * 11-Jan-00 Ensure PMMxMAs disabled before setting PMMxLAs. This is not
50 * really required after a reset since PMMxMAs are already
Wolfgang Denk53677ef2008-05-20 16:00:29 +020051 * disabled but is a good practice nonetheless. JWB
wdenkc6097192002-11-03 00:24:07 +000052 * 12-Jun-01 stefan.roese@esd-electronics.com
53 * - PCI host/adapter handling reworked
54 * 09-Jul-01 stefan.roese@esd-electronics.com
55 * - PCI host now configures from device 0 (not 1) to max_dev,
56 * (host configures itself)
57 * - On CPCI-405 pci base address and size is generated from
58 * SDRAM and FLASH size (CFG regs not used anymore)
59 * - Some minor changes for CPCI-405-A (adapter version)
60 * 14-Sep-01 stefan.roese@esd-electronics.com
61 * - CONFIG_PCI_SCAN_SHOW added to print pci devices upon startup
62 * 28-Sep-01 stefan.roese@esd-electronics.com
63 * - Changed pci master configuration for linux compatibility
64 * (no need for bios_fixup() anymore)
65 * 26-Feb-02 stefan.roese@esd-electronics.com
66 * - Bug fixed in pci configuration (Andrew May)
67 * - Removed pci class code init for CPCI405 board
68 * 15-May-02 stefan.roese@esd-electronics.com
69 * - New vga device handling
70 * 29-May-02 stefan.roese@esd-electronics.com
71 * - PCI class code init added (if defined)
72 *----------------------------------------------------------------------------*/
73
74#include <common.h>
75#include <command.h>
wdenkc6097192002-11-03 00:24:07 +000076#if !defined(CONFIG_440)
Stefan Roese3048bcb2007-10-03 15:01:02 +020077#include <asm/4xx_pci.h>
wdenkc6097192002-11-03 00:24:07 +000078#endif
79#include <asm/processor.h>
Stefan Roese10954932009-11-12 12:00:49 +010080#include <asm/io.h>
wdenkc6097192002-11-03 00:24:07 +000081#include <pci.h>
82
Matthias Fuchs5a1c9ff2007-06-24 17:23:41 +020083#ifdef CONFIG_PCI
84
Wolfgang Denkd87080b2006-03-31 18:32:53 +020085DECLARE_GLOBAL_DATA_PTR;
86
Matthias Fuchs5a1c9ff2007-06-24 17:23:41 +020087/*
88 * Board-specific pci initialization
89 * Platform code can reimplement pci_pre_init() if needed
90 */
91int __pci_pre_init(struct pci_controller *hose)
92{
Matthias Fuchs123f1022009-07-08 13:43:55 +020093#if defined (CONFIG_405EP)
94 /*
95 * Enable the internal PCI arbiter by default.
96 *
97 * On 405EP CPUs the internal arbiter can be controlled
98 * by the I2C strapping EEPROM. If you want to do so
99 * or if you want to disable the arbiter pci_pre_init()
100 * must be reimplemented without enabling the arbiter.
101 * The arbiter is enabled in this place because of
102 * compatibility reasons.
103 */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200104 mtdcr(CPC0_PCI, mfdcr(CPC0_PCI) | CPC0_PCI_ARBIT_EN);
Matthias Fuchs123f1022009-07-08 13:43:55 +0200105#endif /* CONFIG_405EP */
106
Matthias Fuchs5a1c9ff2007-06-24 17:23:41 +0200107 return 1;
108}
109int pci_pre_init(struct pci_controller *hose) __attribute__((weak, alias("__pci_pre_init")));
wdenkc6097192002-11-03 00:24:07 +0000110
Matthias Fuchs5a1c9ff2007-06-24 17:23:41 +0200111#if defined(CONFIG_405GP) || defined(CONFIG_405EP)
wdenkc6097192002-11-03 00:24:07 +0000112
Stefan Roese2076d0a2006-01-18 20:03:15 +0100113#if defined(CONFIG_PMC405)
114ushort pmc405_pci_subsys_deviceid(void);
115#endif
116
wdenkc6097192002-11-03 00:24:07 +0000117/*#define DEBUG*/
118
Matthias Fuchsd0a13642009-07-03 16:06:06 +0200119int __is_pci_host(struct pci_controller *hose)
120{
121#if defined(CONFIG_405GP)
Stefan Roesed1c3b272009-09-09 16:25:29 +0200122 if (mfdcr(CPC0_PSR) & PSR_PCI_ARBIT_EN)
Matthias Fuchsd0a13642009-07-03 16:06:06 +0200123 return 1;
124#elif defined (CONFIG_405EP)
Stefan Roesed1c3b272009-09-09 16:25:29 +0200125 if (mfdcr(CPC0_PCI) & CPC0_PCI_ARBIT_EN)
Matthias Fuchsd0a13642009-07-03 16:06:06 +0200126 return 1;
127#endif
128 return 0;
129}
130int is_pci_host(struct pci_controller *hose) __attribute__((weak, alias("__is_pci_host")));
131
wdenkc6097192002-11-03 00:24:07 +0000132/*-----------------------------------------------------------------------------+
133 * pci_init. Initializes the 405GP PCI Configuration regs.
134 *-----------------------------------------------------------------------------*/
135void pci_405gp_init(struct pci_controller *hose)
136{
wdenkc6097192002-11-03 00:24:07 +0000137 int i, reg_num = 0;
138 bd_t *bd = gd->bd;
139
140 unsigned short temp_short;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200141 unsigned long ptmpcila[2] = {CONFIG_SYS_PCI_PTM1PCI, CONFIG_SYS_PCI_PTM2PCI};
Matthias Fuchs99bcf142009-09-07 17:00:40 +0200142#if defined(CONFIG_PCI_4xx_PTM_OVERWRITE)
stroesefddae7b2005-04-20 06:52:40 +0000143 char *ptmla_str, *ptmms_str;
Stefan Roese2076d0a2006-01-18 20:03:15 +0100144#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200145 unsigned long ptmla[2] = {CONFIG_SYS_PCI_PTM1LA, CONFIG_SYS_PCI_PTM2LA};
146 unsigned long ptmms[2] = {CONFIG_SYS_PCI_PTM1MS, CONFIG_SYS_PCI_PTM2MS};
wdenkc6097192002-11-03 00:24:07 +0000147#if defined(CONFIG_PIP405) || defined (CONFIG_MIP405)
148 unsigned long pmmla[3] = {0x80000000, 0xA0000000, 0};
149 unsigned long pmmma[3] = {0xE0000001, 0xE0000001, 0};
150 unsigned long pmmpcila[3] = {0x80000000, 0x00000000, 0};
151 unsigned long pmmpciha[3] = {0x00000000, 0x00000000, 0};
152#else
153 unsigned long pmmla[3] = {0x80000000, 0,0};
154 unsigned long pmmma[3] = {0xC0000001, 0,0};
155 unsigned long pmmpcila[3] = {0x80000000, 0,0};
156 unsigned long pmmpciha[3] = {0x00000000, 0,0};
157#endif
stroese5e746fc2004-12-16 18:15:52 +0000158#ifdef CONFIG_PCI_PNP
159#if (CONFIG_PCI_HOST == PCI_HOST_AUTO)
160 char *s;
161#endif
162#endif
wdenkc6097192002-11-03 00:24:07 +0000163
Matthias Fuchs99bcf142009-09-07 17:00:40 +0200164#if defined(CONFIG_PCI_4xx_PTM_OVERWRITE)
stroesefddae7b2005-04-20 06:52:40 +0000165 ptmla_str = getenv("ptm1la");
166 ptmms_str = getenv("ptm1ms");
167 if(NULL != ptmla_str && NULL != ptmms_str ) {
168 ptmla[0] = simple_strtoul (ptmla_str, NULL, 16);
169 ptmms[0] = simple_strtoul (ptmms_str, NULL, 16);
170 }
171
172 ptmla_str = getenv("ptm2la");
173 ptmms_str = getenv("ptm2ms");
174 if(NULL != ptmla_str && NULL != ptmms_str ) {
175 ptmla[1] = simple_strtoul (ptmla_str, NULL, 16);
176 ptmms[1] = simple_strtoul (ptmms_str, NULL, 16);
177 }
178#endif
179
wdenkc6097192002-11-03 00:24:07 +0000180 /*
181 * Register the hose
182 */
183 hose->first_busno = 0;
184 hose->last_busno = 0xff;
185
186 /* ISA/PCI I/O space */
187 pci_set_region(hose->regions + reg_num++,
188 MIN_PCI_PCI_IOADDR,
189 MIN_PLB_PCI_IOADDR,
190 0x10000,
191 PCI_REGION_IO);
192
193 /* PCI I/O space */
194 pci_set_region(hose->regions + reg_num++,
195 0x00800000,
196 0xe8800000,
197 0x03800000,
198 PCI_REGION_IO);
199
200 reg_num = 2;
201
202 /* Memory spaces */
203 for (i=0; i<2; i++)
204 if (ptmms[i] & 1)
205 {
206 if (!i) hose->pci_fb = hose->regions + reg_num;
207
208 pci_set_region(hose->regions + reg_num++,
209 ptmpcila[i], ptmla[i],
210 ~(ptmms[i] & 0xfffff000) + 1,
211 PCI_REGION_MEM |
Kumar Galaff4e66e2009-02-06 09:49:31 -0600212 PCI_REGION_SYS_MEMORY);
wdenkc6097192002-11-03 00:24:07 +0000213 }
214
215 /* PCI memory spaces */
216 for (i=0; i<3; i++)
217 if (pmmma[i] & 1)
218 {
219 pci_set_region(hose->regions + reg_num++,
220 pmmpcila[i], pmmla[i],
221 ~(pmmma[i] & 0xfffff000) + 1,
222 PCI_REGION_MEM);
223 }
224
225 hose->region_count = reg_num;
226
227 pci_setup_indirect(hose,
228 PCICFGADR,
229 PCICFGDATA);
230
231 if (hose->pci_fb)
232 pciauto_region_init(hose->pci_fb);
233
Matthias Fuchs5a1c9ff2007-06-24 17:23:41 +0200234 /* Let board change/modify hose & do initial checks */
235 if (pci_pre_init (hose) == 0) {
236 printf("PCI: Board-specific initialization failed.\n");
237 printf("PCI: Configuration aborted.\n");
238 return;
239 }
240
wdenkc6097192002-11-03 00:24:07 +0000241 pci_register_hose(hose);
242
243 /*--------------------------------------------------------------------------+
244 * 405GP PCI Master configuration.
245 * Map one 512 MB range of PLB/processor addresses to PCI memory space.
246 * PLB address 0x80000000-0xBFFFFFFF ==> PCI address 0x80000000-0xBFFFFFFF
247 * Use byte reversed out routines to handle endianess.
248 *--------------------------------------------------------------------------*/
wdenkf3e0de62003-06-04 15:05:30 +0000249 out32r(PMM0MA, (pmmma[0]&~0x1)); /* disable, configure PMMxLA, PMMxPCILA first */
wdenkc6097192002-11-03 00:24:07 +0000250 out32r(PMM0LA, pmmla[0]);
251 out32r(PMM0PCILA, pmmpcila[0]);
252 out32r(PMM0PCIHA, pmmpciha[0]);
253 out32r(PMM0MA, pmmma[0]);
254
255 /*--------------------------------------------------------------------------+
256 * PMM1 is not used. Initialize them to zero.
257 *--------------------------------------------------------------------------*/
wdenkf3e0de62003-06-04 15:05:30 +0000258 out32r(PMM1MA, (pmmma[1]&~0x1));
wdenkc6097192002-11-03 00:24:07 +0000259 out32r(PMM1LA, pmmla[1]);
260 out32r(PMM1PCILA, pmmpcila[1]);
261 out32r(PMM1PCIHA, pmmpciha[1]);
262 out32r(PMM1MA, pmmma[1]);
263
264 /*--------------------------------------------------------------------------+
265 * PMM2 is not used. Initialize them to zero.
266 *--------------------------------------------------------------------------*/
wdenk8bde7f72003-06-27 21:31:46 +0000267 out32r(PMM2MA, (pmmma[2]&~0x1));
wdenkc6097192002-11-03 00:24:07 +0000268 out32r(PMM2LA, pmmla[2]);
269 out32r(PMM2PCILA, pmmpcila[2]);
270 out32r(PMM2PCIHA, pmmpciha[2]);
271 out32r(PMM2MA, pmmma[2]);
272
273 /*--------------------------------------------------------------------------+
274 * 405GP PCI Target configuration. (PTM1)
275 * Note: PTM1MS is hardwire enabled but we set the enable bit anyway.
276 *--------------------------------------------------------------------------*/
277 out32r(PTM1LA, ptmla[0]); /* insert address */
278 out32r(PTM1MS, ptmms[0]); /* insert size, enable bit is 1 */
wdenk4654af22003-10-22 09:00:28 +0000279 pci_write_config_dword(PCIDEVID_405GP, PCI_BASE_ADDRESS_1, ptmpcila[0]);
wdenkc6097192002-11-03 00:24:07 +0000280
281 /*--------------------------------------------------------------------------+
282 * 405GP PCI Target configuration. (PTM2)
283 *--------------------------------------------------------------------------*/
284 out32r(PTM2LA, ptmla[1]); /* insert address */
wdenk4654af22003-10-22 09:00:28 +0000285 pci_write_config_dword(PCIDEVID_405GP, PCI_BASE_ADDRESS_2, ptmpcila[1]);
286
wdenkc6097192002-11-03 00:24:07 +0000287 if (ptmms[1] == 0)
288 {
289 out32r(PTM2MS, 0x00000001); /* set enable bit */
290 pci_write_config_dword(PCIDEVID_405GP, PCI_BASE_ADDRESS_2, 0x00000000);
291 out32r(PTM2MS, 0x00000000); /* disable */
292 }
293 else
294 {
295 out32r(PTM2MS, ptmms[1]); /* insert size, enable bit is 1 */
296 }
297
298 /*
299 * Insert Subsystem Vendor and Device ID
300 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200301 pci_write_config_word(PCIDEVID_405GP, PCI_SUBSYSTEM_VENDOR_ID, CONFIG_SYS_PCI_SUBSYS_VENDORID);
wdenkc6097192002-11-03 00:24:07 +0000302#ifdef CONFIG_CPCI405
Matthias Fuchsd0a13642009-07-03 16:06:06 +0200303 if (is_pci_host(hose))
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200304 pci_write_config_word(PCIDEVID_405GP, PCI_SUBSYSTEM_ID, CONFIG_SYS_PCI_SUBSYS_DEVICEID);
wdenkc6097192002-11-03 00:24:07 +0000305 else
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200306 pci_write_config_word(PCIDEVID_405GP, PCI_SUBSYSTEM_ID, CONFIG_SYS_PCI_SUBSYS_DEVICEID2);
wdenkc6097192002-11-03 00:24:07 +0000307#else
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200308 pci_write_config_word(PCIDEVID_405GP, PCI_SUBSYSTEM_ID, CONFIG_SYS_PCI_SUBSYS_DEVICEID);
wdenkc6097192002-11-03 00:24:07 +0000309#endif
310
311 /*
312 * Insert Class-code
313 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200314#ifdef CONFIG_SYS_PCI_CLASSCODE
315 pci_write_config_word(PCIDEVID_405GP, PCI_CLASS_SUB_CODE, CONFIG_SYS_PCI_CLASSCODE);
316#endif /* CONFIG_SYS_PCI_CLASSCODE */
wdenkc6097192002-11-03 00:24:07 +0000317
318 /*--------------------------------------------------------------------------+
Wolfgang Denk8ed44d92008-10-19 02:35:50 +0200319 * If PCI speed = 66MHz, set 66MHz capable bit.
wdenkc6097192002-11-03 00:24:07 +0000320 *--------------------------------------------------------------------------*/
321 if (bd->bi_pci_busfreq >= 66000000) {
322 pci_read_config_word(PCIDEVID_405GP, PCI_STATUS, &temp_short);
323 pci_write_config_word(PCIDEVID_405GP,PCI_STATUS,(temp_short|PCI_STATUS_66MHZ));
324 }
325
326#if (CONFIG_PCI_HOST != PCI_HOST_ADAPTER)
wdenk4654af22003-10-22 09:00:28 +0000327#if (CONFIG_PCI_HOST == PCI_HOST_AUTO)
Matthias Fuchsd0a13642009-07-03 16:06:06 +0200328 if (is_pci_host(hose) ||
stroese5e746fc2004-12-16 18:15:52 +0000329 (((s = getenv("pciscan")) != NULL) && (strcmp(s, "yes") == 0)))
wdenkc6097192002-11-03 00:24:07 +0000330#endif
331 {
332 /*--------------------------------------------------------------------------+
333 * Write the 405GP PCI Configuration regs.
334 * Enable 405GP to be a master on the PCI bus (PMM).
335 * Enable 405GP to act as a PCI memory target (PTM).
336 *--------------------------------------------------------------------------*/
337 pci_read_config_word(PCIDEVID_405GP, PCI_COMMAND, &temp_short);
338 pci_write_config_word(PCIDEVID_405GP, PCI_COMMAND, temp_short |
339 PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
340 }
341#endif
342
Matthias Fuchs632e9b62009-07-08 15:31:57 +0200343#if defined(CONFIG_405EP)
344 /*
345 * on ppc405ep vendor/device id is not set
346 * The user manual says 0x1014 (IBM) / 0x0156 (405GP!)
347 * are the correct values.
348 */
349 pci_write_config_word(PCIDEVID_405GP, PCI_VENDOR_ID, PCI_VENDOR_ID_IBM);
350 pci_write_config_word(PCIDEVID_405GP,
351 PCI_DEVICE_ID, PCI_DEVICE_ID_IBM_405GP);
stroese428c5632003-09-12 08:52:09 +0000352#endif
353
wdenkc6097192002-11-03 00:24:07 +0000354 /*
355 * Set HCE bit (Host Configuration Enabled)
356 */
357 pci_read_config_word(PCIDEVID_405GP, PCIBRDGOPT2, &temp_short);
358 pci_write_config_word(PCIDEVID_405GP, PCIBRDGOPT2, (temp_short | 0x0001));
359
360#ifdef CONFIG_PCI_PNP
361 /*--------------------------------------------------------------------------+
362 * Scan the PCI bus and configure devices found.
363 *--------------------------------------------------------------------------*/
364#if (CONFIG_PCI_HOST == PCI_HOST_AUTO)
Matthias Fuchsd0a13642009-07-03 16:06:06 +0200365 if (is_pci_host(hose) ||
stroese5e746fc2004-12-16 18:15:52 +0000366 (((s = getenv("pciscan")) != NULL) && (strcmp(s, "yes") == 0)))
wdenkc6097192002-11-03 00:24:07 +0000367#endif
368 {
369#ifdef CONFIG_PCI_SCAN_SHOW
370 printf("PCI: Bus Dev VenId DevId Class Int\n");
371#endif
wdenkc6097192002-11-03 00:24:07 +0000372 hose->last_busno = pci_hose_scan(hose);
373 }
374#endif /* CONFIG_PCI_PNP */
375
376}
377
378/*
Marcel Ziswiler7817cb22007-12-30 03:30:46 +0100379 * drivers/pci/pci.c skips every host bridge but the 405GP since it could
wdenkc6097192002-11-03 00:24:07 +0000380 * be set as an Adapter.
381 *
382 * I (Andrew May) don't know what we should do here, but I don't want
383 * the auto setup of a PCI device disabling what is done pci_405gp_init
384 * as has happened before.
385 */
386void pci_405gp_setup_bridge(struct pci_controller *hose, pci_dev_t dev,
387 struct pci_config_table *entry)
388{
389#ifdef DEBUG
wdenk8bde7f72003-06-27 21:31:46 +0000390 printf("405gp_setup_bridge\n");
wdenkc6097192002-11-03 00:24:07 +0000391#endif
392}
393
394/*
395 *
396 */
397
398void pci_405gp_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
399{
400 unsigned char int_line = 0xff;
401
402 /*
403 * Write pci interrupt line register (cpci405 specific)
404 */
405 switch (PCI_DEV(dev) & 0x03)
406 {
407 case 0:
408 int_line = 27 + 2;
409 break;
410 case 1:
411 int_line = 27 + 3;
412 break;
413 case 2:
414 int_line = 27 + 0;
415 break;
416 case 3:
417 int_line = 27 + 1;
418 break;
419 }
420
421 pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, int_line);
422}
423
424void pci_405gp_setup_vga(struct pci_controller *hose, pci_dev_t dev,
425 struct pci_config_table *entry)
426{
427 unsigned int cmdstat = 0;
428
Stefan Roesef3fecfe2006-03-13 09:43:01 +0100429 pciauto_setup_device(hose, dev, 6, hose->pci_mem, hose->pci_prefetch, hose->pci_io);
wdenkc6097192002-11-03 00:24:07 +0000430
431 /* always enable io space on vga boards */
432 pci_hose_read_config_dword(hose, dev, PCI_COMMAND, &cmdstat);
433 cmdstat |= PCI_COMMAND_IO;
434 pci_hose_write_config_dword(hose, dev, PCI_COMMAND, cmdstat);
435}
436
Wolfgang Denk9045f332007-06-08 10:24:58 +0200437#if !(defined(CONFIG_PIP405) || defined (CONFIG_MIP405)) && !(defined (CONFIG_SC3))
wdenkc6097192002-11-03 00:24:07 +0000438
439/*
440 *As is these functs get called out of flash Not a horrible
441 *thing, but something to keep in mind. (no statics?)
442 */
443static struct pci_config_table pci_405gp_config_table[] = {
444/*if VendID is 0 it terminates the table search (ie Walnut)*/
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200445#ifdef CONFIG_SYS_PCI_SUBSYS_VENDORID
446 {CONFIG_SYS_PCI_SUBSYS_VENDORID, PCI_ANY_ID, PCI_CLASS_BRIDGE_HOST,
wdenkc6097192002-11-03 00:24:07 +0000447 PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, pci_405gp_setup_bridge},
448#endif
449 {PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA,
450 PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, pci_405gp_setup_vga},
451
452 {PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NOT_DEFINED_VGA,
453 PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, pci_405gp_setup_vga},
454
455 { }
456};
457
458static struct pci_controller hose = {
459 fixup_irq: pci_405gp_fixup_irq,
460 config_table: pci_405gp_config_table,
461};
462
stroesead10dd92003-02-14 11:21:23 +0000463void pci_init_board(void)
wdenkc6097192002-11-03 00:24:07 +0000464{
465 /*we want the ptrs to RAM not flash (ie don't use init list)*/
466 hose.fixup_irq = pci_405gp_fixup_irq;
467 hose.config_table = pci_405gp_config_table;
468 pci_405gp_init(&hose);
469}
470
471#endif
472
wdenkc6097192002-11-03 00:24:07 +0000473#endif /* CONFIG_405GP */
474
475/*-----------------------------------------------------------------------------+
476 * CONFIG_440
477 *-----------------------------------------------------------------------------*/
Matthias Fuchs5a1c9ff2007-06-24 17:23:41 +0200478#if defined(CONFIG_440)
wdenkc6097192002-11-03 00:24:07 +0000479
480static struct pci_controller ppc440_hose = {0};
481
Stefan Roese9a81c612009-10-29 16:54:52 +0100482/*
483 * This routine is called to determine if a pci scan should be
484 * performed. With various hardware environments (especially cPCI and
485 * PPMC) it's insufficient to depend on the state of the arbiter enable
486 * bit in the strap register, or generic host/adapter assumptions.
487 *
488 * Rather than hard-code a bad assumption in the general 440 code, the
489 * 440 pci code requires the board to decide at runtime.
490 *
491 * Return 0 for adapter mode, non-zero for host (monarch) mode.
492 *
493 * Weak default implementation: "Normal" boards implement the PCI
494 * host functionality. This can be overridden for PCI adapter boards.
495 */
496int __is_pci_host(struct pci_controller *hose)
497{
498 return 1;
499}
500int is_pci_host(struct pci_controller *hose)
501 __attribute__((weak, alias("__is_pci_host")));
wdenkc6097192002-11-03 00:24:07 +0000502
Stefan Roese10954932009-11-12 12:00:49 +0100503/*
504 * pci_target_init
505 *
506 * The bootstrap configuration provides default settings for the pci
507 * inbound map (PIM). But the bootstrap config choices are limited and
508 * may not be sufficient for a given board.
509 */
510#if defined(CONFIG_SYS_PCI_TARGET_INIT)
511#if defined(CONFIG_440EP) || defined(CONFIG_440EPX) || \
512 defined(CONFIG_440GR) || defined(CONFIG_440GRX)
513void __pci_target_init(struct pci_controller *hose)
514{
515 /*
516 * Set up Direct MMIO registers
517 */
518
519 /*
520 * PowerPC440 EP PCI Master configuration.
521 * Map one 1Gig range of PLB/processor addresses to PCI memory space.
522 * PLB address 0xA0000000-0xDFFFFFFF ==> PCI address 0xA0000000-0xDFFFFFFF
523 * Use byte reversed out routines to handle endianess.
524 * Make this region non-prefetchable.
525 */
526 /* PMM0 Mask/Attribute - disabled b4 setting */
527 out_le32((void *)PCIL0_PMM0MA, 0x00000000);
528 /* PMM0 Local Address */
529 out_le32((void *)PCIL0_PMM0LA, CONFIG_SYS_PCI_MEMBASE);
530 /* PMM0 PCI Low Address */
531 out_le32((void *)PCIL0_PMM0PCILA, CONFIG_SYS_PCI_MEMBASE);
532 /* PMM0 PCI High Address */
533 out_le32((void *)PCIL0_PMM0PCIHA, 0x00000000);
534 /* 512M + No prefetching, and enable region */
535 out_le32((void *)PCIL0_PMM0MA, 0xE0000001);
536
537 /* PMM1 Mask/Attribute - disabled b4 setting */
538 out_le32((void *)PCIL0_PMM1MA, 0x00000000);
539 /* PMM1 Local Address */
540 out_le32((void *)PCIL0_PMM1LA, CONFIG_SYS_PCI_MEMBASE2);
541 /* PMM1 PCI Low Address */
542 out_le32((void *)PCIL0_PMM1PCILA, CONFIG_SYS_PCI_MEMBASE2);
543 /* PMM1 PCI High Address */
544 out_le32((void *)PCIL0_PMM1PCIHA, 0x00000000);
545 /* 512M + No prefetching, and enable region */
546 out_le32((void *)PCIL0_PMM1MA, 0xE0000001);
547
548 out_le32((void *)PCIL0_PTM1MS, 0x00000001); /* Memory Size/Attribute */
549 out_le32((void *)PCIL0_PTM1LA, 0); /* Local Addr. Reg */
550 out_le32((void *)PCIL0_PTM2MS, 0); /* Memory Size/Attribute */
551 out_le32((void *)PCIL0_PTM2LA, 0); /* Local Addr. Reg */
552
553 /*
554 * Set up Configuration registers
555 */
556
557 /* Program the board's subsystem id/vendor id */
558 pci_write_config_word(0, PCI_SUBSYSTEM_VENDOR_ID,
559 CONFIG_SYS_PCI_SUBSYS_VENDORID);
560 pci_write_config_word(0, PCI_SUBSYSTEM_ID, CONFIG_SYS_PCI_SUBSYS_ID);
561
562 /* Configure command register as bus master */
563 pci_write_config_word(0, PCI_COMMAND, PCI_COMMAND_MASTER);
564
565 /* 240nS PCI clock */
566 pci_write_config_word(0, PCI_LATENCY_TIMER, 1);
567
568 /* No error reporting */
569 pci_write_config_word(0, PCI_ERREN, 0);
570
571 pci_write_config_dword(0, PCI_BRDGOPT2, 0x00000101);
572}
573#else /* defined(CONFIG_440EP) ... */
574void __pci_target_init(struct pci_controller * hose)
575{
576 /*
577 * Disable everything
578 */
579 out_le32((void *)PCIL0_PIM0SA, 0); /* disable */
580 out_le32((void *)PCIL0_PIM1SA, 0); /* disable */
581 out_le32((void *)PCIL0_PIM2SA, 0); /* disable */
582 out_le32((void *)PCIL0_EROMBA, 0); /* disable expansion rom */
583
584 /*
585 * Map all of SDRAM to PCI address 0x0000_0000. Note that the 440
586 * strapping options do not support sizes such as 128/256 MB.
587 */
588 out_le32((void *)PCIL0_PIM0LAL, CONFIG_SYS_SDRAM_BASE);
589 out_le32((void *)PCIL0_PIM0LAH, 0);
590 out_le32((void *)PCIL0_PIM0SA, ~(gd->ram_size - 1) | 1);
591 out_le32((void *)PCIL0_BAR0, 0);
592
593 /*
594 * Program the board's subsystem id/vendor id
595 */
596 out_le16((void *)PCIL0_SBSYSVID, CONFIG_SYS_PCI_SUBSYS_VENDORID);
597 out_le16((void *)PCIL0_SBSYSID, CONFIG_SYS_PCI_SUBSYS_DEVICEID);
598
599 out_le16((void *)PCIL0_CMD, in_le16((void *)PCIL0_CMD) |
600 PCI_COMMAND_MEMORY);
601}
602#endif /* defined(CONFIG_440EP) ... */
603void pci_target_init(struct pci_controller * hose)
604 __attribute__((weak, alias("__pci_target_init")));
605
606#endif /* defined(CONFIG_SYS_PCI_TARGET_INIT) */
607
Grzegorz Bernacki7f191392007-09-07 18:20:23 +0200608int pci_440_init (struct pci_controller *hose)
wdenkc6097192002-11-03 00:24:07 +0000609{
610 int reg_num = 0;
wdenkc6097192002-11-03 00:24:07 +0000611
Stefan Roese5568e612005-11-22 13:20:42 +0100612#ifndef CONFIG_DISABLE_PISE_TEST
wdenkc6097192002-11-03 00:24:07 +0000613 /*--------------------------------------------------------------------------+
614 * The PCI initialization sequence enable bit must be set ... if not abort
wdenk3c74e322004-02-22 23:46:08 +0000615 * pci setup since updating the bit requires chip reset.
wdenkc6097192002-11-03 00:24:07 +0000616 *--------------------------------------------------------------------------*/
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200617#if defined(CONFIG_440GX) || defined(CONFIG_440SP) || defined(CONFIG_440SPE)
Stefan Roese5568e612005-11-22 13:20:42 +0100618 unsigned long strap;
619
Stefan Roesed1c3b272009-09-09 16:25:29 +0200620 mfsdr(SDR0_SDSTP1,strap);
Stefan Roese6e7fb6e2005-11-29 18:18:21 +0100621 if ((strap & SDR0_SDSTP1_PISE_MASK) == 0) {
wdenk3c74e322004-02-22 23:46:08 +0000622 printf("PCI: SDR0_STRP1[PISE] not set.\n");
623 printf("PCI: Configuration aborted.\n");
Grzegorz Bernacki7f191392007-09-07 18:20:23 +0200624 return -1;
wdenk3c74e322004-02-22 23:46:08 +0000625 }
Stefan Roese5568e612005-11-22 13:20:42 +0100626#elif defined(CONFIG_440GP)
627 unsigned long strap;
628
Stefan Roesed1c3b272009-09-09 16:25:29 +0200629 strap = mfdcr(CPC0_STRP1);
Stefan Roese6e7fb6e2005-11-29 18:18:21 +0100630 if ((strap & CPC0_STRP1_PISE_MASK) == 0) {
wdenk3c74e322004-02-22 23:46:08 +0000631 printf("PCI: CPC0_STRP1[PISE] not set.\n");
632 printf("PCI: Configuration aborted.\n");
Grzegorz Bernacki7f191392007-09-07 18:20:23 +0200633 return -1;
wdenk3c74e322004-02-22 23:46:08 +0000634 }
635#endif
Stefan Roese5568e612005-11-22 13:20:42 +0100636#endif /* CONFIG_DISABLE_PISE_TEST */
637
wdenkc6097192002-11-03 00:24:07 +0000638 /*--------------------------------------------------------------------------+
639 * PCI controller init
640 *--------------------------------------------------------------------------*/
641 hose->first_busno = 0;
Grzegorz Bernacki7f191392007-09-07 18:20:23 +0200642 hose->last_busno = 0;
wdenkc6097192002-11-03 00:24:07 +0000643
Marian Balakowiczfbb0b552006-07-04 00:55:47 +0200644 /* PCI I/O space */
wdenkc6097192002-11-03 00:24:07 +0000645 pci_set_region(hose->regions + reg_num++,
646 0x00000000,
Niklaus Gigerddc922f2009-10-04 20:04:20 +0200647 PCIL0_IOBASE,
Stefan Roese6e7fb6e2005-11-29 18:18:21 +0100648 0x10000,
649 PCI_REGION_IO);
wdenkc6097192002-11-03 00:24:07 +0000650
Marian Balakowiczfbb0b552006-07-04 00:55:47 +0200651 /* PCI memory space */
wdenkc6097192002-11-03 00:24:07 +0000652 pci_set_region(hose->regions + reg_num++,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200653 CONFIG_SYS_PCI_TARGBASE,
654 CONFIG_SYS_PCI_MEMBASE,
655#ifdef CONFIG_SYS_PCI_MEMSIZE
656 CONFIG_SYS_PCI_MEMSIZE,
Stefan Roese899620c2006-08-15 14:22:35 +0200657#else
Stefan Roese6e7fb6e2005-11-29 18:18:21 +0100658 0x10000000,
Stefan Roese899620c2006-08-15 14:22:35 +0200659#endif
Stefan Roese6e7fb6e2005-11-29 18:18:21 +0100660 PCI_REGION_MEM );
Marian Balakowiczfbb0b552006-07-04 00:55:47 +0200661
662#if defined(CONFIG_PCI_SYS_MEM_BUS) && defined(CONFIG_PCI_SYS_MEM_PHYS) && \
663 defined(CONFIG_PCI_SYS_MEM_SIZE)
664 /* System memory space */
665 pci_set_region(hose->regions + reg_num++,
666 CONFIG_PCI_SYS_MEM_BUS,
667 CONFIG_PCI_SYS_MEM_PHYS,
668 CONFIG_PCI_SYS_MEM_SIZE,
Kumar Galaff4e66e2009-02-06 09:49:31 -0600669 PCI_REGION_MEM | PCI_REGION_SYS_MEMORY );
Marian Balakowiczfbb0b552006-07-04 00:55:47 +0200670#endif
671
wdenkc6097192002-11-03 00:24:07 +0000672 hose->region_count = reg_num;
673
Niklaus Gigerddc922f2009-10-04 20:04:20 +0200674 pci_setup_indirect(hose, PCIL0_CFGADR, PCIL0_CFGDATA);
wdenkc6097192002-11-03 00:24:07 +0000675
Stefan Roese6e7fb6e2005-11-29 18:18:21 +0100676 /* Let board change/modify hose & do initial checks */
677 if (pci_pre_init (hose) == 0) {
678 printf("PCI: Board-specific initialization failed.\n");
679 printf("PCI: Configuration aborted.\n");
Grzegorz Bernacki7f191392007-09-07 18:20:23 +0200680 return -1;
Stefan Roese6e7fb6e2005-11-29 18:18:21 +0100681 }
wdenkc6097192002-11-03 00:24:07 +0000682
683 pci_register_hose( hose );
684
685 /*--------------------------------------------------------------------------+
686 * PCI target init
687 *--------------------------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200688#if defined(CONFIG_SYS_PCI_TARGET_INIT)
wdenkc6097192002-11-03 00:24:07 +0000689 pci_target_init(hose); /* Let board setup pci target */
690#else
Niklaus Gigerddc922f2009-10-04 20:04:20 +0200691 out16r( PCIL0_SBSYSVID, CONFIG_SYS_PCI_SUBSYS_VENDORID );
692 out16r( PCIL0_SBSYSID, CONFIG_SYS_PCI_SUBSYS_ID );
693 out16r( PCIL0_CLS, 0x00060000 ); /* Bridge, host bridge */
wdenkc6097192002-11-03 00:24:07 +0000694#endif
695
Stefan Roese8ac41e32008-03-11 15:05:26 +0100696#if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \
697 defined(CONFIG_460EX) || defined(CONFIG_460GT)
Niklaus Gigerddc922f2009-10-04 20:04:20 +0200698 out32r( PCIL0_BRDGOPT1, 0x04000060 ); /* PLB Rq pri highest */
699 out32r( PCIL0_BRDGOPT2, in32(PCIL0_BRDGOPT2) | 0x83 ); /* Enable host config, clear Timeout, ensure int src1 */
700#elif defined(PCIL0_BRDGOPT1)
701 out32r( PCIL0_BRDGOPT1, 0x10000060 ); /* PLB Rq pri highest */
702 out32r( PCIL0_BRDGOPT2, in32(PCIL0_BRDGOPT2) | 1 ); /* Enable host config */
wdenk3c74e322004-02-22 23:46:08 +0000703#endif
wdenkc6097192002-11-03 00:24:07 +0000704
705 /*--------------------------------------------------------------------------+
706 * PCI master init: default is one 256MB region for PCI memory:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200707 * 0x3_00000000 - 0x3_0FFFFFFF ==> CONFIG_SYS_PCI_MEMBASE
wdenkc6097192002-11-03 00:24:07 +0000708 *--------------------------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200709#if defined(CONFIG_SYS_PCI_MASTER_INIT)
wdenkc6097192002-11-03 00:24:07 +0000710 pci_master_init(hose); /* Let board setup pci master */
711#else
Niklaus Gigerddc922f2009-10-04 20:04:20 +0200712 out32r( PCIL0_POM0SA, 0 ); /* disable */
713 out32r( PCIL0_POM1SA, 0 ); /* disable */
714 out32r( PCIL0_POM2SA, 0 ); /* disable */
Anatolij Gustschinf8853d12009-03-20 12:45:50 +0100715#if defined(CONFIG_440SPE)
Niklaus Gigerddc922f2009-10-04 20:04:20 +0200716 out32r( PCIL0_POM0LAL, 0x10000000 );
717 out32r( PCIL0_POM0LAH, 0x0000000c );
Anatolij Gustschinf8853d12009-03-20 12:45:50 +0100718#elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
Niklaus Gigerddc922f2009-10-04 20:04:20 +0200719 out32r( PCIL0_POM0LAL, 0x20000000 );
720 out32r( PCIL0_POM0LAH, 0x0000000c );
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200721#else
Niklaus Gigerddc922f2009-10-04 20:04:20 +0200722 out32r( PCIL0_POM0LAL, 0x00000000 );
723 out32r( PCIL0_POM0LAH, 0x00000003 );
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200724#endif
Niklaus Gigerddc922f2009-10-04 20:04:20 +0200725 out32r( PCIL0_POM0PCIAL, CONFIG_SYS_PCI_MEMBASE );
726 out32r( PCIL0_POM0PCIAH, 0x00000000 );
727 out32r( PCIL0_POM0SA, 0xf0000001 ); /* 256MB, enabled */
728 out32r( PCIL0_STS, in32r( PCIL0_STS ) & ~0x0000fff8 );
wdenkc6097192002-11-03 00:24:07 +0000729#endif
730
731 /*--------------------------------------------------------------------------+
732 * PCI host configuration -- we don't make any assumptions here ... the
Stefan Roese6e7fb6e2005-11-29 18:18:21 +0100733 * _board_must_indicate_ what to do -- there's just too many runtime
734 * scenarios in environments like cPCI, PPMC, etc. to make a determination
735 * based on hard-coded values or state of arbiter enable.
wdenkc6097192002-11-03 00:24:07 +0000736 *--------------------------------------------------------------------------*/
Stefan Roese6e7fb6e2005-11-29 18:18:21 +0100737 if (is_pci_host(hose)) {
wdenkc6097192002-11-03 00:24:07 +0000738#ifdef CONFIG_PCI_SCAN_SHOW
Stefan Roese6e7fb6e2005-11-29 18:18:21 +0100739 printf("PCI: Bus Dev VenId DevId Class Int\n");
wdenkc6097192002-11-03 00:24:07 +0000740#endif
Stefan Roese887e2ec2006-09-07 11:51:23 +0200741#if !defined(CONFIG_440EP) && !defined(CONFIG_440GR) && \
742 !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX)
Niklaus Gigerddc922f2009-10-04 20:04:20 +0200743 out16r( PCIL0_CMD, in16r( PCIL0_CMD ) | PCI_COMMAND_MASTER);
Stefan Roesec157d8e2005-08-01 16:41:48 +0200744#endif
Stefan Roese6e7fb6e2005-11-29 18:18:21 +0100745 hose->last_busno = pci_hose_scan(hose);
746 }
Grzegorz Bernacki7f191392007-09-07 18:20:23 +0200747 return hose->last_busno;
wdenkc6097192002-11-03 00:24:07 +0000748}
749
stroesead10dd92003-02-14 11:21:23 +0000750void pci_init_board(void)
wdenkc6097192002-11-03 00:24:07 +0000751{
Grzegorz Bernacki7f191392007-09-07 18:20:23 +0200752 int busno;
753
754 busno = pci_440_init (&ppc440_hose);
Dirk Eibach59d1bda2009-02-03 15:15:21 +0100755#if (defined(CONFIG_440SPE) || \
756 defined(CONFIG_460EX) || defined(CONFIG_460GT)) && \
757 !defined(CONFIG_PCI_DISABLE_PCIE)
Grzegorz Bernacki7f191392007-09-07 18:20:23 +0200758 pcie_setup_hoses(busno + 1);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200759#endif
wdenkc6097192002-11-03 00:24:07 +0000760}
761
Matthias Fuchs5a1c9ff2007-06-24 17:23:41 +0200762#endif /* CONFIG_440 */
Stefan Roese1d7b8742007-10-05 17:09:36 +0200763
764#if defined(CONFIG_405EX)
765void pci_init_board(void)
766{
767#ifdef CONFIG_PCI_SCAN_SHOW
768 printf("PCI: Bus Dev VenId DevId Class Int\n");
769#endif
770 pcie_setup_hoses(0);
771}
772#endif /* CONFIG_405EX */
773
Matthias Fuchs5a1c9ff2007-06-24 17:23:41 +0200774#endif /* CONFIG_PCI */