2 * (C) Copyright 2006 - 2007
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * Copyright (c) 2005 Cisco Systems. All rights reserved.
6 * Roland Dreier <rolandd@cisco.com>
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
23 #include <asm/processor.h>
24 #include <asm-ppc/io.h>
29 #if defined(CONFIG_440SPE) && defined(CONFIG_PCI)
31 #include "440spe_pcie.h"
35 PTYPE_LEGACY_ENDPOINT = 0x1,
36 PTYPE_ROOT_PORT = 0x4,
43 static u8* pcie_get_base(struct pci_controller *hose, unsigned int devfn)
45 u8 *base = (u8*)hose->cfg_data;
47 /* use local configuration space for the first bus */
48 if (PCI_BUS(devfn) == 0) {
49 if (hose->cfg_data == (u8*)CFG_PCIE0_CFGBASE)
50 base = (u8*)CFG_PCIE0_XCFGBASE;
51 if (hose->cfg_data == (u8*)CFG_PCIE1_CFGBASE)
52 base = (u8*)CFG_PCIE1_XCFGBASE;
53 if (hose->cfg_data == (u8*)CFG_PCIE2_CFGBASE)
54 base = (u8*)CFG_PCIE2_XCFGBASE;
60 static void pcie_dmer_disable(void)
62 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE),
63 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE)) | GPL_DMER_MASK_DISA);
64 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE),
65 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE)) | GPL_DMER_MASK_DISA);
66 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE),
67 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE)) | GPL_DMER_MASK_DISA);
70 static void pcie_dmer_enable(void)
72 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE0_BASE),
73 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE)) & ~GPL_DMER_MASK_DISA);
74 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE1_BASE),
75 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE)) & ~GPL_DMER_MASK_DISA);
76 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE2_BASE),
77 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE)) & ~GPL_DMER_MASK_DISA);
80 static int pcie_read_config(struct pci_controller *hose, unsigned int devfn,
81 int offset, int len, u32 *val) {
87 * Bus numbers are relative to hose->first_busno
89 devfn -= PCI_BDF(hose->first_busno, 0, 0);
92 * NOTICE: configuration space ranges are currenlty mapped only for
93 * the first 16 buses, so such limit must be imposed. In case more
94 * buses are required the TLB settings in board/amcc/<board>/init.S
95 * need to be altered accordingly (one bus takes 1 MB of memory space).
97 if (PCI_BUS(devfn) >= 16)
101 * Only single device/single function is supported for the primary and
102 * secondary buses of the 440SPe host bridge.
104 if ((!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 0))) &&
105 ((PCI_BUS(devfn) == 0) || (PCI_BUS(devfn) == 1)))
108 address = pcie_get_base(hose, devfn);
109 offset += devfn << 4;
112 * Reading from configuration space of non-existing device can
113 * generate transaction errors. For the read duration we suppress
114 * assertion of machine check exceptions to avoid those.
116 pcie_dmer_disable ();
120 *val = in_8(hose->cfg_data + offset);
123 *val = in_le16((u16 *)(hose->cfg_data + offset));
126 *val = in_le32((u32*)(hose->cfg_data + offset));
135 static int pcie_write_config(struct pci_controller *hose, unsigned int devfn,
136 int offset, int len, u32 val) {
141 * Bus numbers are relative to hose->first_busno
143 devfn -= PCI_BDF(hose->first_busno, 0, 0);
146 * Same constraints as in pcie_read_config().
148 if (PCI_BUS(devfn) >= 16)
151 if ((!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 0))) &&
152 ((PCI_BUS(devfn) == 0) || (PCI_BUS(devfn) == 1)))
155 address = pcie_get_base(hose, devfn);
156 offset += devfn << 4;
159 * Suppress MCK exceptions, similar to pcie_read_config()
161 pcie_dmer_disable ();
165 out_8(hose->cfg_data + offset, val);
168 out_le16((u16 *)(hose->cfg_data + offset), val);
171 out_le32((u32 *)(hose->cfg_data + offset), val);
180 int pcie_read_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 *val)
185 rv = pcie_read_config(hose, dev, offset, 1, &v);
190 int pcie_read_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 *val)
195 rv = pcie_read_config(hose, dev, offset, 2, &v);
200 int pcie_read_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 *val)
205 rv = pcie_read_config(hose, dev, offset, 3, &v);
210 int pcie_write_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 val)
212 return pcie_write_config(hose,(u32)dev,offset,1,val);
215 int pcie_write_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 val)
217 return pcie_write_config(hose,(u32)dev,offset,2,(u32 )val);
220 int pcie_write_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 val)
222 return pcie_write_config(hose,(u32)dev,offset,3,(u32 )val);
225 static void ppc440spe_setup_utl(u32 port) {
227 volatile void *utl_base = NULL;
234 mtdcr(DCRN_PEGPL_REGBAH(PCIE0), 0x0000000c);
235 mtdcr(DCRN_PEGPL_REGBAL(PCIE0), 0x20000000);
236 mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001);
237 mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0x68782800);
241 mtdcr(DCRN_PEGPL_REGBAH(PCIE1), 0x0000000c);
242 mtdcr(DCRN_PEGPL_REGBAL(PCIE1), 0x20001000);
243 mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001);
244 mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0x68782800);
248 mtdcr(DCRN_PEGPL_REGBAH(PCIE2), 0x0000000c);
249 mtdcr(DCRN_PEGPL_REGBAL(PCIE2), 0x20002000);
250 mtdcr(DCRN_PEGPL_REGMSK(PCIE2), 0x00007001);
251 mtdcr(DCRN_PEGPL_SPECIAL(PCIE2), 0x68782800);
254 utl_base = (unsigned int *)(CFG_PCIE_BASE + 0x1000 * port);
257 * Set buffer allocations and then assert VRB and TXE.
259 out_be32(utl_base + PEUTL_OUTTR, 0x08000000);
260 out_be32(utl_base + PEUTL_INTR, 0x02000000);
261 out_be32(utl_base + PEUTL_OPDBSZ, 0x10000000);
262 out_be32(utl_base + PEUTL_PBBSZ, 0x53000000);
263 out_be32(utl_base + PEUTL_IPHBSZ, 0x08000000);
264 out_be32(utl_base + PEUTL_IPDBSZ, 0x10000000);
265 out_be32(utl_base + PEUTL_RCIRQEN, 0x00f00000);
266 out_be32(utl_base + PEUTL_PCTL, 0x80800066);
269 static int check_error(void)
271 u32 valPE0, valPE1, valPE2;
274 /* SDR0_PEGPLLLCT1 reset */
275 if (!(valPE0 = SDR_READ(PESDR0_PLLLCT1) & 0x01000000)) {
276 printf("PCIE: SDR0_PEGPLLLCT1 reset error 0x%x\n", valPE0);
279 valPE0 = SDR_READ(PESDR0_RCSSET);
280 valPE1 = SDR_READ(PESDR1_RCSSET);
281 valPE2 = SDR_READ(PESDR2_RCSSET);
283 /* SDR0_PExRCSSET rstgu */
284 if (!(valPE0 & 0x01000000) ||
285 !(valPE1 & 0x01000000) ||
286 !(valPE2 & 0x01000000)) {
287 printf("PCIE: SDR0_PExRCSSET rstgu error\n");
291 /* SDR0_PExRCSSET rstdl */
292 if (!(valPE0 & 0x00010000) ||
293 !(valPE1 & 0x00010000) ||
294 !(valPE2 & 0x00010000)) {
295 printf("PCIE: SDR0_PExRCSSET rstdl error\n");
299 /* SDR0_PExRCSSET rstpyn */
300 if ((valPE0 & 0x00001000) ||
301 (valPE1 & 0x00001000) ||
302 (valPE2 & 0x00001000)) {
303 printf("PCIE: SDR0_PExRCSSET rstpyn error\n");
307 /* SDR0_PExRCSSET hldplb */
308 if ((valPE0 & 0x10000000) ||
309 (valPE1 & 0x10000000) ||
310 (valPE2 & 0x10000000)) {
311 printf("PCIE: SDR0_PExRCSSET hldplb error\n");
315 /* SDR0_PExRCSSET rdy */
316 if ((valPE0 & 0x00100000) ||
317 (valPE1 & 0x00100000) ||
318 (valPE2 & 0x00100000)) {
319 printf("PCIE: SDR0_PExRCSSET rdy error\n");
323 /* SDR0_PExRCSSET shutdown */
324 if ((valPE0 & 0x00000100) ||
325 (valPE1 & 0x00000100) ||
326 (valPE2 & 0x00000100)) {
327 printf("PCIE: SDR0_PExRCSSET shutdown error\n");
334 * Initialize PCI Express core
336 int ppc440spe_init_pcie(void)
340 /* Set PLL clock receiver to LVPECL */
341 SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) | 1 << 28);
346 if (!(SDR_READ(PESDR0_PLLLCT2) & 0x10000))
348 printf("PCIE: PESDR_PLLCT2 resistance calibration failed (0x%08x)\n",
349 SDR_READ(PESDR0_PLLLCT2));
352 /* De-assert reset of PCIe PLL, wait for lock */
353 SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) & ~(1 << 24));
357 if (!(SDR_READ(PESDR0_PLLLCT3) & 0x10000000)) {
364 printf("PCIE: VCO output not locked\n");
371 * Yucca board as End point and root point setup
373 * testing inbound and out bound windows
375 * YUCCA board can be plugged into another yucca board or you can get PCI-E
376 * cable which can be used to setup loop back from one port to another port.
377 * Please rememeber that unless there is a endpoint plugged in to root port it
378 * will not initialize. It is the same in case of endpoint , unless there is
379 * root port attached it will not initialize.
381 * In this release of software all the PCI-E ports are configured as either
382 * endpoint or rootpoint.In future we will have support for selective ports
383 * setup as endpoint and root point in single board.
385 * Once your board came up as root point , you can verify by reading
386 * /proc/bus/pci/devices. Where you can see the configuration registers
387 * of end point device attached to the port.
389 * Enpoint cofiguration can be verified by connecting Yucca board to any
390 * host or another yucca board. Then try to scan the device. In case of
391 * linux use "lspci" or appripriate os command.
393 * How do I verify the inbound and out bound windows ?(yucca to yucca)
394 * in this configuration inbound and outbound windows are setup to access
395 * sram memroy area. SRAM is at 0x4 0000 0000 , on PLB bus. This address
396 * is mapped at 0x90000000. From u-boot prompt write data 0xb000 0000,
397 * This is waere your POM(PLB out bound memory window) mapped. then
398 * read the data from other yucca board's u-boot prompt at address
399 * 0x9000 0000(SRAM). Data should match.
400 * In case of inbound , write data to u-boot command prompt at 0xb000 0000
401 * which is mapped to 0x4 0000 0000. Now on rootpoint yucca u-boot prompt check
402 * data at 0x9000 0000(SRAM).Data should match.
404 int ppc440spe_init_pcie_rootport(int port)
406 static int core_init;
407 volatile u32 val = 0;
412 if (ppc440spe_init_pcie())
417 * Initialize various parts of the PCI Express core for our port:
419 * - Set as a root port and enable max width
420 * (PXIE0 -> X8, PCIE1 and PCIE2 -> X4).
421 * - Set up UTL configuration.
422 * - Increase SERDES drive strength to levels suggested by AMCC.
423 * - De-assert RSTPYN, RSTDL and RSTGU.
425 * NOTICE for revB chip: PESDRn_UTLSET2 is not set - we leave it with
426 * default setting 0x11310000. The register has new fields,
427 * PESDRn_UTLSET2[LKINE] in particular: clearing it leads to PCIE core
432 SDR_WRITE(PESDR0_DLPSET, 1 << 24 | PTYPE_ROOT_PORT << 20 | LNKW_X8 << 12);
434 SDR_WRITE(PESDR0_UTLSET1, 0x21222222);
435 if (!ppc440spe_revB())
436 SDR_WRITE(PESDR0_UTLSET2, 0x11000000);
437 SDR_WRITE(PESDR0_HSSL0SET1, 0x35000000);
438 SDR_WRITE(PESDR0_HSSL1SET1, 0x35000000);
439 SDR_WRITE(PESDR0_HSSL2SET1, 0x35000000);
440 SDR_WRITE(PESDR0_HSSL3SET1, 0x35000000);
441 SDR_WRITE(PESDR0_HSSL4SET1, 0x35000000);
442 SDR_WRITE(PESDR0_HSSL5SET1, 0x35000000);
443 SDR_WRITE(PESDR0_HSSL6SET1, 0x35000000);
444 SDR_WRITE(PESDR0_HSSL7SET1, 0x35000000);
445 SDR_WRITE(PESDR0_RCSSET,
446 (SDR_READ(PESDR0_RCSSET) & ~(1 << 24 | 1 << 16)) | 1 << 12);
450 SDR_WRITE(PESDR1_DLPSET, 1 << 24 | PTYPE_ROOT_PORT << 20 | LNKW_X4 << 12);
451 SDR_WRITE(PESDR1_UTLSET1, 0x21222222);
452 if (!ppc440spe_revB())
453 SDR_WRITE(PESDR1_UTLSET2, 0x11000000);
454 SDR_WRITE(PESDR1_HSSL0SET1, 0x35000000);
455 SDR_WRITE(PESDR1_HSSL1SET1, 0x35000000);
456 SDR_WRITE(PESDR1_HSSL2SET1, 0x35000000);
457 SDR_WRITE(PESDR1_HSSL3SET1, 0x35000000);
458 SDR_WRITE(PESDR1_RCSSET,
459 (SDR_READ(PESDR1_RCSSET) & ~(1 << 24 | 1 << 16)) | 1 << 12);
463 SDR_WRITE(PESDR2_DLPSET, 1 << 24 | PTYPE_ROOT_PORT << 20 | LNKW_X4 << 12);
464 SDR_WRITE(PESDR2_UTLSET1, 0x21222222);
465 if (!ppc440spe_revB())
466 SDR_WRITE(PESDR2_UTLSET2, 0x11000000);
467 SDR_WRITE(PESDR2_HSSL0SET1, 0x35000000);
468 SDR_WRITE(PESDR2_HSSL1SET1, 0x35000000);
469 SDR_WRITE(PESDR2_HSSL2SET1, 0x35000000);
470 SDR_WRITE(PESDR2_HSSL3SET1, 0x35000000);
471 SDR_WRITE(PESDR2_RCSSET,
472 (SDR_READ(PESDR2_RCSSET) & ~(1 << 24 | 1 << 16)) | 1 << 12);
476 * Notice: the following delay has critical impact on device
477 * initialization - if too short (<50ms) the link doesn't get up.
483 val = SDR_READ(PESDR0_RCSSTS);
486 val = SDR_READ(PESDR1_RCSSTS);
489 val = SDR_READ(PESDR2_RCSSTS);
493 if (val & (1 << 20)) {
494 printf("PCIE%d: PGRST failed %08x\n", port, val);
504 val = SDR_READ(PESDR0_LOOP);
507 val = SDR_READ(PESDR1_LOOP);
510 val = SDR_READ(PESDR2_LOOP);
513 if (!(val & 0x00001000)) {
514 printf("PCIE%d: link is not up.\n", port);
519 * Setup UTL registers - but only on revA!
520 * We use default settings for revB chip.
522 if (!ppc440spe_revB())
523 ppc440spe_setup_utl(port);
526 * We map PCI Express configuration access into the 512MB regions
528 * NOTICE: revB is very strict about PLB real addressess and ranges to
529 * be mapped for config space; it seems to only work with d_nnnn_nnnn
530 * range (hangs the core upon config transaction attempts when set
531 * otherwise) while revA uses c_nnnn_nnnn.
534 * PCIE0: 0xc_4000_0000
535 * PCIE1: 0xc_8000_0000
536 * PCIE2: 0xc_c000_0000
539 * PCIE0: 0xd_0000_0000
540 * PCIE1: 0xd_2000_0000
541 * PCIE2: 0xd_4000_0000
546 if (ppc440spe_revB()) {
547 mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), 0x0000000d);
548 mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), 0x00000000);
551 mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), 0x0000000c);
552 mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), 0x40000000);
554 mtdcr(DCRN_PEGPL_CFGMSK(PCIE0), 0xe0000001); /* 512MB region, valid */
558 if (ppc440spe_revB()) {
559 mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), 0x0000000d);
560 mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), 0x20000000);
562 mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), 0x0000000c);
563 mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), 0x80000000);
565 mtdcr(DCRN_PEGPL_CFGMSK(PCIE1), 0xe0000001); /* 512MB region, valid */
569 if (ppc440spe_revB()) {
570 mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), 0x0000000d);
571 mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), 0x40000000);
573 mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), 0x0000000c);
574 mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), 0xc0000000);
576 mtdcr(DCRN_PEGPL_CFGMSK(PCIE2), 0xe0000001); /* 512MB region, valid */
581 * Check for VC0 active and assert RDY.
586 while(!(SDR_READ(PESDR0_RCSSTS) & (1 << 16))) {
588 printf("PCIE0: VC0 not active\n");
593 SDR_WRITE(PESDR0_RCSSET, SDR_READ(PESDR0_RCSSET) | 1 << 20);
596 while(!(SDR_READ(PESDR1_RCSSTS) & (1 << 16))) {
598 printf("PCIE1: VC0 not active\n");
604 SDR_WRITE(PESDR1_RCSSET, SDR_READ(PESDR1_RCSSET) | 1 << 20);
607 while(!(SDR_READ(PESDR2_RCSSTS) & (1 << 16))) {
609 printf("PCIE2: VC0 not active\n");
615 SDR_WRITE(PESDR2_RCSSET, SDR_READ(PESDR2_RCSSET) | 1 << 20);
623 int ppc440spe_init_pcie_endport(int port)
625 static int core_init;
626 volatile u32 val = 0;
631 if (ppc440spe_init_pcie())
636 * Initialize various parts of the PCI Express core for our port:
638 * - Set as a end port and enable max width
639 * (PXIE0 -> X8, PCIE1 and PCIE2 -> X4).
640 * - Set up UTL configuration.
641 * - Increase SERDES drive strength to levels suggested by AMCC.
642 * - De-assert RSTPYN, RSTDL and RSTGU.
644 * NOTICE for revB chip: PESDRn_UTLSET2 is not set - we leave it with
645 * default setting 0x11310000. The register has new fields,
646 * PESDRn_UTLSET2[LKINE] in particular: clearing it leads to PCIE core
651 SDR_WRITE(PESDR0_DLPSET, 1 << 24 | PTYPE_LEGACY_ENDPOINT << 20 | LNKW_X8 << 12);
653 SDR_WRITE(PESDR0_UTLSET1, 0x20222222);
654 if (!ppc440spe_revB())
655 SDR_WRITE(PESDR0_UTLSET2, 0x11000000);
656 SDR_WRITE(PESDR0_HSSL0SET1, 0x35000000);
657 SDR_WRITE(PESDR0_HSSL1SET1, 0x35000000);
658 SDR_WRITE(PESDR0_HSSL2SET1, 0x35000000);
659 SDR_WRITE(PESDR0_HSSL3SET1, 0x35000000);
660 SDR_WRITE(PESDR0_HSSL4SET1, 0x35000000);
661 SDR_WRITE(PESDR0_HSSL5SET1, 0x35000000);
662 SDR_WRITE(PESDR0_HSSL6SET1, 0x35000000);
663 SDR_WRITE(PESDR0_HSSL7SET1, 0x35000000);
664 SDR_WRITE(PESDR0_RCSSET,
665 (SDR_READ(PESDR0_RCSSET) & ~(1 << 24 | 1 << 16)) | 1 << 12);
669 SDR_WRITE(PESDR1_DLPSET, 1 << 24 | PTYPE_LEGACY_ENDPOINT << 20 | LNKW_X4 << 12);
670 SDR_WRITE(PESDR1_UTLSET1, 0x20222222);
671 if (!ppc440spe_revB())
672 SDR_WRITE(PESDR1_UTLSET2, 0x11000000);
673 SDR_WRITE(PESDR1_HSSL0SET1, 0x35000000);
674 SDR_WRITE(PESDR1_HSSL1SET1, 0x35000000);
675 SDR_WRITE(PESDR1_HSSL2SET1, 0x35000000);
676 SDR_WRITE(PESDR1_HSSL3SET1, 0x35000000);
677 SDR_WRITE(PESDR1_RCSSET,
678 (SDR_READ(PESDR1_RCSSET) & ~(1 << 24 | 1 << 16)) | 1 << 12);
682 SDR_WRITE(PESDR2_DLPSET, 1 << 24 | PTYPE_LEGACY_ENDPOINT << 20 | LNKW_X4 << 12);
683 SDR_WRITE(PESDR2_UTLSET1, 0x20222222);
684 if (!ppc440spe_revB())
685 SDR_WRITE(PESDR2_UTLSET2, 0x11000000);
686 SDR_WRITE(PESDR2_HSSL0SET1, 0x35000000);
687 SDR_WRITE(PESDR2_HSSL1SET1, 0x35000000);
688 SDR_WRITE(PESDR2_HSSL2SET1, 0x35000000);
689 SDR_WRITE(PESDR2_HSSL3SET1, 0x35000000);
690 SDR_WRITE(PESDR2_RCSSET,
691 (SDR_READ(PESDR2_RCSSET) & ~(1 << 24 | 1 << 16)) | 1 << 12);
695 * Notice: the following delay has critical impact on device
696 * initialization - if too short (<50ms) the link doesn't get up.
701 case 0: val = SDR_READ(PESDR0_RCSSTS); break;
702 case 1: val = SDR_READ(PESDR1_RCSSTS); break;
703 case 2: val = SDR_READ(PESDR2_RCSSTS); break;
706 if (val & (1 << 20)) {
707 printf("PCIE%d: PGRST failed %08x\n", port, val);
718 val = SDR_READ(PESDR0_LOOP);
721 val = SDR_READ(PESDR1_LOOP);
724 val = SDR_READ(PESDR2_LOOP);
727 if (!(val & 0x00001000)) {
728 printf("PCIE%d: link is not up.\n", port);
733 * Setup UTL registers - but only on revA!
734 * We use default settings for revB chip.
736 if (!ppc440spe_revB())
737 ppc440spe_setup_utl(port);
740 * We map PCI Express configuration access into the 512MB regions
742 * NOTICE: revB is very strict about PLB real addressess and ranges to
743 * be mapped for config space; it seems to only work with d_nnnn_nnnn
744 * range (hangs the core upon config transaction attempts when set
745 * otherwise) while revA uses c_nnnn_nnnn.
748 * PCIE0: 0xc_4000_0000
749 * PCIE1: 0xc_8000_0000
750 * PCIE2: 0xc_c000_0000
753 * PCIE0: 0xd_0000_0000
754 * PCIE1: 0xd_2000_0000
755 * PCIE2: 0xd_4000_0000
759 if (ppc440spe_revB()) {
760 mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), 0x0000000d);
761 mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), 0x00000000);
764 mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), 0x0000000c);
765 mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), 0x40000000);
767 mtdcr(DCRN_PEGPL_CFGMSK(PCIE0), 0xe0000001); /* 512MB region, valid */
771 if (ppc440spe_revB()) {
772 mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), 0x0000000d);
773 mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), 0x20000000);
775 mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), 0x0000000c);
776 mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), 0x80000000);
778 mtdcr(DCRN_PEGPL_CFGMSK(PCIE1), 0xe0000001); /* 512MB region, valid */
782 if (ppc440spe_revB()) {
783 mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), 0x0000000d);
784 mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), 0x40000000);
786 mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), 0x0000000c);
787 mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), 0xc0000000);
789 mtdcr(DCRN_PEGPL_CFGMSK(PCIE2), 0xe0000001); /* 512MB region, valid */
794 * Check for VC0 active and assert RDY.
799 while(!(SDR_READ(PESDR0_RCSSTS) & (1 << 16))) {
801 printf("PCIE0: VC0 not active\n");
806 SDR_WRITE(PESDR0_RCSSET, SDR_READ(PESDR0_RCSSET) | 1 << 20);
809 while(!(SDR_READ(PESDR1_RCSSTS) & (1 << 16))) {
811 printf("PCIE1: VC0 not active\n");
817 SDR_WRITE(PESDR1_RCSSET, SDR_READ(PESDR1_RCSSET) | 1 << 20);
820 while(!(SDR_READ(PESDR2_RCSSTS) & (1 << 16))) {
822 printf("PCIE2: VC0 not active\n");
828 SDR_WRITE(PESDR2_RCSSET, SDR_READ(PESDR2_RCSSET) | 1 << 20);
836 void ppc440spe_setup_pcie_rootpoint(struct pci_controller *hose, int port)
838 volatile void *mbase = NULL;
839 volatile void *rmbase = NULL;
842 pcie_read_config_byte,
843 pcie_read_config_word,
844 pcie_read_config_dword,
845 pcie_write_config_byte,
846 pcie_write_config_word,
847 pcie_write_config_dword);
851 mbase = (u32 *)CFG_PCIE0_XCFGBASE;
852 rmbase = (u32 *)CFG_PCIE0_CFGBASE;
853 hose->cfg_data = (u8 *)CFG_PCIE0_CFGBASE;
856 mbase = (u32 *)CFG_PCIE1_XCFGBASE;
857 rmbase = (u32 *)CFG_PCIE1_CFGBASE;
858 hose->cfg_data = (u8 *)CFG_PCIE1_CFGBASE;
861 mbase = (u32 *)CFG_PCIE2_XCFGBASE;
862 rmbase = (u32 *)CFG_PCIE2_CFGBASE;
863 hose->cfg_data = (u8 *)CFG_PCIE2_CFGBASE;
868 * Set bus numbers on our root port
870 out_8((u8 *)mbase + PCI_PRIMARY_BUS, 0);
871 out_8((u8 *)mbase + PCI_SECONDARY_BUS, 1);
872 out_8((u8 *)mbase + PCI_SUBORDINATE_BUS, 1);
875 * Set up outbound translation to hose->mem_space from PLB
876 * addresses at an offset of 0xd_0000_0000. We set the low
877 * bits of the mask to 11 to turn off splitting into 8
878 * subregions and to enable the outbound translation.
880 out_le32(mbase + PECFG_POM0LAH, 0x00000000);
881 out_le32(mbase + PECFG_POM0LAL, 0x00000000);
885 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), 0x0000000d);
886 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CFG_PCIE_MEMBASE +
887 port * CFG_PCIE_MEMSIZE);
888 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
889 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
890 ~(CFG_PCIE_MEMSIZE - 1) | 3);
893 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), 0x0000000d);
894 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), (CFG_PCIE_MEMBASE +
895 port * CFG_PCIE_MEMSIZE));
896 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
897 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
898 ~(CFG_PCIE_MEMSIZE - 1) | 3);
901 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), 0x0000000d);
902 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), (CFG_PCIE_MEMBASE +
903 port * CFG_PCIE_MEMSIZE));
904 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
905 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
906 ~(CFG_PCIE_MEMSIZE - 1) | 3);
910 /* Set up 16GB inbound memory window at 0 */
911 out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
912 out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
913 out_le32(mbase + PECFG_BAR0HMPA, 0x7fffffc);
914 out_le32(mbase + PECFG_BAR0LMPA, 0);
916 out_le32(mbase + PECFG_PIM01SAH, 0xffff0000);
917 out_le32(mbase + PECFG_PIM01SAL, 0x00000000);
918 out_le32(mbase + PECFG_PIM0LAL, 0);
919 out_le32(mbase + PECFG_PIM0LAH, 0);
920 out_le32(mbase + PECFG_PIM1LAL, 0x00000000);
921 out_le32(mbase + PECFG_PIM1LAH, 0x00000004);
922 out_le32(mbase + PECFG_PIMEN, 0x1);
924 /* Enable I/O, Mem, and Busmaster cycles */
925 out_le16((u16 *)(mbase + PCI_COMMAND),
926 in_le16((u16 *)(mbase + PCI_COMMAND)) |
927 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
928 printf("PCIE:%d successfully set as rootpoint\n",port);
930 /* Set Device and Vendor Id */
933 out_le16(mbase + 0x200, 0xaaa0);
934 out_le16(mbase + 0x202, 0xbed0);
937 out_le16(mbase + 0x200, 0xaaa1);
938 out_le16(mbase + 0x202, 0xbed1);
941 out_le16(mbase + 0x200, 0xaaa2);
942 out_le16(mbase + 0x202, 0xbed2);
945 out_le16(mbase + 0x200, 0xaaa3);
946 out_le16(mbase + 0x202, 0xbed3);
949 /* Set Class Code to PCI-PCI bridge and Revision Id to 1 */
950 out_le32(mbase + 0x208, 0x06040001);
954 int ppc440spe_setup_pcie_endpoint(struct pci_controller *hose, int port)
956 volatile void *mbase = NULL;
960 pcie_read_config_byte,
961 pcie_read_config_word,
962 pcie_read_config_dword,
963 pcie_write_config_byte,
964 pcie_write_config_word,
965 pcie_write_config_dword);
969 mbase = (u32 *)CFG_PCIE0_XCFGBASE;
970 hose->cfg_data = (u8 *)CFG_PCIE0_CFGBASE;
973 mbase = (u32 *)CFG_PCIE1_XCFGBASE;
974 hose->cfg_data = (u8 *)CFG_PCIE1_CFGBASE;
977 mbase = (u32 *)CFG_PCIE2_XCFGBASE;
978 hose->cfg_data = (u8 *)CFG_PCIE2_CFGBASE;
983 * Set up outbound translation to hose->mem_space from PLB
984 * addresses at an offset of 0xd_0000_0000. We set the low
985 * bits of the mask to 11 to turn off splitting into 8
986 * subregions and to enable the outbound translation.
988 out_le32(mbase + PECFG_POM0LAH, 0x00001ff8);
989 out_le32(mbase + PECFG_POM0LAL, 0x00001000);
993 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), 0x0000000d);
994 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CFG_PCIE_MEMBASE +
995 port * CFG_PCIE_MEMSIZE);
996 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
997 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
998 ~(CFG_PCIE_MEMSIZE - 1) | 3);
1001 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), 0x0000000d);
1002 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), (CFG_PCIE_MEMBASE +
1003 port * CFG_PCIE_MEMSIZE));
1004 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
1005 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
1006 ~(CFG_PCIE_MEMSIZE - 1) | 3);
1009 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), 0x0000000d);
1010 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), (CFG_PCIE_MEMBASE +
1011 port * CFG_PCIE_MEMSIZE));
1012 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
1013 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
1014 ~(CFG_PCIE_MEMSIZE - 1) | 3);
1018 /* Set up 16GB inbound memory window at 0 */
1019 out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
1020 out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
1021 out_le32(mbase + PECFG_BAR0HMPA, 0x7fffffc);
1022 out_le32(mbase + PECFG_BAR0LMPA, 0);
1023 out_le32(mbase + PECFG_PIM0LAL, 0x00000000);
1024 out_le32(mbase + PECFG_PIM0LAH, 0x00000004); /* pointing to SRAM */
1025 out_le32(mbase + PECFG_PIMEN, 0x1);
1027 /* Enable I/O, Mem, and Busmaster cycles */
1028 out_le16((u16 *)(mbase + PCI_COMMAND),
1029 in_le16((u16 *)(mbase + PCI_COMMAND)) |
1030 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
1031 out_le16(mbase + 0x200,0xcaad); /* Setting vendor ID */
1032 out_le16(mbase + 0x202,0xfeed); /* Setting device ID */
1036 while (!(SDR_READ(PESDR0_RCSSTS) & (1 << 8))) {
1037 if (!(attempts--)) {
1038 printf("PCIE0: BMEN is not active\n");
1045 while (!(SDR_READ(PESDR1_RCSSTS) & (1 << 8))) {
1046 if (!(attempts--)) {
1047 printf("PCIE1: BMEN is not active\n");
1054 while (!(SDR_READ(PESDR2_RCSSTS) & (1 << 8))) {
1055 if (!(attempts--)) {
1056 printf("PCIE2: BMEN is not active\n");
1063 printf("PCIE:%d successfully set as endpoint\n",port);
1067 #endif /* CONFIG_440SPE && CONFIG_PCI */