2 * (C) Copyright 2006 - 2008
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 /* define DEBUG for debugging output (obviously ;-)) */
31 #include <asm/processor.h>
32 #include <asm-ppc/io.h>
33 #include <asm/errno.h>
35 #if (defined(CONFIG_440SPE) || defined(CONFIG_405EX) || \
36 defined(CONFIG_460EX) || defined(CONFIG_460GT)) && \
37 defined(CONFIG_PCI) && !defined(CONFIG_PCI_DISABLE_PCIE)
39 #include <asm/4xx_pcie.h>
43 PTYPE_LEGACY_ENDPOINT = 0x1,
44 PTYPE_ROOT_PORT = 0x4,
51 static int validate_endpoint(struct pci_controller *hose)
53 if (hose->cfg_data == (u8 *)CONFIG_SYS_PCIE0_CFGBASE)
54 return (is_end_point(0));
55 else if (hose->cfg_data == (u8 *)CONFIG_SYS_PCIE1_CFGBASE)
56 return (is_end_point(1));
57 #if CONFIG_SYS_PCIE_NR_PORTS > 2
58 else if (hose->cfg_data == (u8 *)CONFIG_SYS_PCIE2_CFGBASE)
59 return (is_end_point(2));
65 static u8* pcie_get_base(struct pci_controller *hose, unsigned int devfn)
67 u8 *base = (u8*)hose->cfg_data;
69 /* use local configuration space for the first bus */
70 if (PCI_BUS(devfn) == 0) {
71 if (hose->cfg_data == (u8*)CONFIG_SYS_PCIE0_CFGBASE)
72 base = (u8*)CONFIG_SYS_PCIE0_XCFGBASE;
73 if (hose->cfg_data == (u8*)CONFIG_SYS_PCIE1_CFGBASE)
74 base = (u8*)CONFIG_SYS_PCIE1_XCFGBASE;
75 #if CONFIG_SYS_PCIE_NR_PORTS > 2
76 if (hose->cfg_data == (u8*)CONFIG_SYS_PCIE2_CFGBASE)
77 base = (u8*)CONFIG_SYS_PCIE2_XCFGBASE;
84 static void pcie_dmer_disable(void)
86 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE),
87 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE)) | GPL_DMER_MASK_DISA);
88 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE),
89 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE)) | GPL_DMER_MASK_DISA);
90 #if CONFIG_SYS_PCIE_NR_PORTS > 2
91 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE),
92 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE)) | GPL_DMER_MASK_DISA);
96 static void pcie_dmer_enable(void)
98 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE0_BASE),
99 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE)) & ~GPL_DMER_MASK_DISA);
100 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE1_BASE),
101 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE)) & ~GPL_DMER_MASK_DISA);
102 #if CONFIG_SYS_PCIE_NR_PORTS > 2
103 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE2_BASE),
104 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE)) & ~GPL_DMER_MASK_DISA);
108 static int pcie_read_config(struct pci_controller *hose, unsigned int devfn,
109 int offset, int len, u32 *val) {
114 if (validate_endpoint(hose))
115 return 0; /* No upstream config access */
118 * Bus numbers are relative to hose->first_busno
120 devfn -= PCI_BDF(hose->first_busno, 0, 0);
123 * NOTICE: configuration space ranges are currenlty mapped only for
124 * the first 16 buses, so such limit must be imposed. In case more
125 * buses are required the TLB settings in board/amcc/<board>/init.S
126 * need to be altered accordingly (one bus takes 1 MB of memory space).
128 if (PCI_BUS(devfn) >= 16)
132 * Only single device/single function is supported for the primary and
133 * secondary buses of the 440SPe host bridge.
135 if ((!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 0))) &&
136 ((PCI_BUS(devfn) == 0) || (PCI_BUS(devfn) == 1)))
139 address = pcie_get_base(hose, devfn);
140 offset += devfn << 4;
143 * Reading from configuration space of non-existing device can
144 * generate transaction errors. For the read duration we suppress
145 * assertion of machine check exceptions to avoid those.
147 pcie_dmer_disable ();
149 debug("%s: cfg_data=%08x offset=%08x\n", __func__, hose->cfg_data, offset);
152 *val = in_8(hose->cfg_data + offset);
155 *val = in_le16((u16 *)(hose->cfg_data + offset));
158 *val = in_le32((u32*)(hose->cfg_data + offset));
167 static int pcie_write_config(struct pci_controller *hose, unsigned int devfn,
168 int offset, int len, u32 val) {
172 if (validate_endpoint(hose))
173 return 0; /* No upstream config access */
176 * Bus numbers are relative to hose->first_busno
178 devfn -= PCI_BDF(hose->first_busno, 0, 0);
181 * Same constraints as in pcie_read_config().
183 if (PCI_BUS(devfn) >= 16)
186 if ((!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 0))) &&
187 ((PCI_BUS(devfn) == 0) || (PCI_BUS(devfn) == 1)))
190 address = pcie_get_base(hose, devfn);
191 offset += devfn << 4;
194 * Suppress MCK exceptions, similar to pcie_read_config()
196 pcie_dmer_disable ();
200 out_8(hose->cfg_data + offset, val);
203 out_le16((u16 *)(hose->cfg_data + offset), val);
206 out_le32((u32 *)(hose->cfg_data + offset), val);
215 int pcie_read_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 *val)
220 rv = pcie_read_config(hose, dev, offset, 1, &v);
225 int pcie_read_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 *val)
230 rv = pcie_read_config(hose, dev, offset, 2, &v);
235 int pcie_read_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 *val)
240 rv = pcie_read_config(hose, dev, offset, 3, &v);
245 int pcie_write_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 val)
247 return pcie_write_config(hose,(u32)dev,offset,1,val);
250 int pcie_write_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 val)
252 return pcie_write_config(hose,(u32)dev,offset,2,(u32 )val);
255 int pcie_write_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 val)
257 return pcie_write_config(hose,(u32)dev,offset,3,(u32 )val);
260 #if defined(CONFIG_440SPE)
261 static void ppc4xx_setup_utl(u32 port) {
263 volatile void *utl_base = NULL;
270 mtdcr(DCRN_PEGPL_REGBAH(PCIE0), 0x0000000c);
271 mtdcr(DCRN_PEGPL_REGBAL(PCIE0), 0x20000000);
272 mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001);
273 mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0x68782800);
277 mtdcr(DCRN_PEGPL_REGBAH(PCIE1), 0x0000000c);
278 mtdcr(DCRN_PEGPL_REGBAL(PCIE1), 0x20001000);
279 mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001);
280 mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0x68782800);
284 mtdcr(DCRN_PEGPL_REGBAH(PCIE2), 0x0000000c);
285 mtdcr(DCRN_PEGPL_REGBAL(PCIE2), 0x20002000);
286 mtdcr(DCRN_PEGPL_REGMSK(PCIE2), 0x00007001);
287 mtdcr(DCRN_PEGPL_SPECIAL(PCIE2), 0x68782800);
290 utl_base = (unsigned int *)(CONFIG_SYS_PCIE_BASE + 0x1000 * port);
293 * Set buffer allocations and then assert VRB and TXE.
295 out_be32(utl_base + PEUTL_OUTTR, 0x08000000);
296 out_be32(utl_base + PEUTL_INTR, 0x02000000);
297 out_be32(utl_base + PEUTL_OPDBSZ, 0x10000000);
298 out_be32(utl_base + PEUTL_PBBSZ, 0x53000000);
299 out_be32(utl_base + PEUTL_IPHBSZ, 0x08000000);
300 out_be32(utl_base + PEUTL_IPDBSZ, 0x10000000);
301 out_be32(utl_base + PEUTL_RCIRQEN, 0x00f00000);
302 out_be32(utl_base + PEUTL_PCTL, 0x80800066);
305 static int check_error(void)
307 u32 valPE0, valPE1, valPE2;
310 /* SDR0_PEGPLLLCT1 reset */
311 if (!(valPE0 = SDR_READ(PESDR0_PLLLCT1) & 0x01000000))
312 printf("PCIE: SDR0_PEGPLLLCT1 reset error 0x%x\n", valPE0);
314 valPE0 = SDR_READ(PESDR0_RCSSET);
315 valPE1 = SDR_READ(PESDR1_RCSSET);
316 valPE2 = SDR_READ(PESDR2_RCSSET);
318 /* SDR0_PExRCSSET rstgu */
319 if (!(valPE0 & 0x01000000) ||
320 !(valPE1 & 0x01000000) ||
321 !(valPE2 & 0x01000000)) {
322 printf("PCIE: SDR0_PExRCSSET rstgu error\n");
326 /* SDR0_PExRCSSET rstdl */
327 if (!(valPE0 & 0x00010000) ||
328 !(valPE1 & 0x00010000) ||
329 !(valPE2 & 0x00010000)) {
330 printf("PCIE: SDR0_PExRCSSET rstdl error\n");
334 /* SDR0_PExRCSSET rstpyn */
335 if ((valPE0 & 0x00001000) ||
336 (valPE1 & 0x00001000) ||
337 (valPE2 & 0x00001000)) {
338 printf("PCIE: SDR0_PExRCSSET rstpyn error\n");
342 /* SDR0_PExRCSSET hldplb */
343 if ((valPE0 & 0x10000000) ||
344 (valPE1 & 0x10000000) ||
345 (valPE2 & 0x10000000)) {
346 printf("PCIE: SDR0_PExRCSSET hldplb error\n");
350 /* SDR0_PExRCSSET rdy */
351 if ((valPE0 & 0x00100000) ||
352 (valPE1 & 0x00100000) ||
353 (valPE2 & 0x00100000)) {
354 printf("PCIE: SDR0_PExRCSSET rdy error\n");
358 /* SDR0_PExRCSSET shutdown */
359 if ((valPE0 & 0x00000100) ||
360 (valPE1 & 0x00000100) ||
361 (valPE2 & 0x00000100)) {
362 printf("PCIE: SDR0_PExRCSSET shutdown error\n");
369 * Initialize PCI Express core
371 int ppc4xx_init_pcie(void)
375 /* Set PLL clock receiver to LVPECL */
376 SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) | 1 << 28);
379 printf("ERROR: failed to set PCIe reference clock receiver --"
380 "PESDR0_PLLLCT1 = 0x%08x\n", SDR_READ(PESDR0_PLLLCT1));
385 /* Did resistance calibration work? */
386 if (!(SDR_READ(PESDR0_PLLLCT2) & 0x10000)) {
387 printf("ERROR: PCIe resistance calibration failed --"
388 "PESDR0_PLLLCT2 = 0x%08x\n", SDR_READ(PESDR0_PLLLCT2));
392 /* De-assert reset of PCIe PLL, wait for lock */
393 SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) & ~(1 << 24));
394 udelay(300); /* 300 uS is maximum time lock should take */
397 if (!(SDR_READ(PESDR0_PLLLCT3) & 0x10000000)) {
399 udelay(20); /* Wait 20 uS more if needed */
404 printf("ERROR: PCIe PLL VCO output not locked to ref clock --"
405 "PESDR0_PLLLCTS=0x%08x\n", SDR_READ(PESDR0_PLLLCT3));
413 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
414 static void ppc4xx_setup_utl(u32 port)
416 volatile void *utl_base = NULL;
419 * Map UTL registers at 0x0801_n000 (4K 0xfff mask) PEGPLn_REGMSK
423 mtdcr(DCRN_PEGPL_REGBAH(PCIE0), U64_TO_U32_HIGH(CONFIG_SYS_PCIE0_UTLBASE));
424 mtdcr(DCRN_PEGPL_REGBAL(PCIE0), U64_TO_U32_LOW(CONFIG_SYS_PCIE0_UTLBASE));
425 mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001); /* BAM 11100000=4KB */
426 mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0);
430 mtdcr(DCRN_PEGPL_REGBAH(PCIE1), U64_TO_U32_HIGH(CONFIG_SYS_PCIE0_UTLBASE));
431 mtdcr(DCRN_PEGPL_REGBAL(PCIE1), U64_TO_U32_LOW(CONFIG_SYS_PCIE0_UTLBASE)
433 mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001); /* BAM 11100000=4KB */
434 mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0);
437 utl_base = (unsigned int *)(CONFIG_SYS_PCIE_BASE + 0x1000 * port);
440 * Set buffer allocations and then assert VRB and TXE.
442 out_be32(utl_base + PEUTL_PBCTL, 0x0800000c); /* PLBME, CRRE */
443 out_be32(utl_base + PEUTL_OUTTR, 0x08000000);
444 out_be32(utl_base + PEUTL_INTR, 0x02000000);
445 out_be32(utl_base + PEUTL_OPDBSZ, 0x04000000); /* OPD = 512 Bytes */
446 out_be32(utl_base + PEUTL_PBBSZ, 0x00000000); /* Max 512 Bytes */
447 out_be32(utl_base + PEUTL_IPHBSZ, 0x02000000);
448 out_be32(utl_base + PEUTL_IPDBSZ, 0x04000000); /* IPD = 512 Bytes */
449 out_be32(utl_base + PEUTL_RCIRQEN, 0x00f00000);
450 out_be32(utl_base + PEUTL_PCTL, 0x80800066); /* VRB,TXE,timeout=default */
454 * TODO: double check PCI express SDR based on the latest user manual
455 * Some registers specified here no longer exist.. has to be
456 * updated based on the final EAS spec.
458 static int check_error(void)
463 valPE0 = SDR_READ(SDRN_PESDR_RCSSET(0));
464 valPE1 = SDR_READ(SDRN_PESDR_RCSSET(1));
466 /* SDR0_PExRCSSET rstgu */
467 if (!(valPE0 & PESDRx_RCSSET_RSTGU) || !(valPE1 & PESDRx_RCSSET_RSTGU)) {
468 printf("PCIE: SDR0_PExRCSSET rstgu error\n");
472 /* SDR0_PExRCSSET rstdl */
473 if (!(valPE0 & PESDRx_RCSSET_RSTDL) || !(valPE1 & PESDRx_RCSSET_RSTDL)) {
474 printf("PCIE: SDR0_PExRCSSET rstdl error\n");
478 /* SDR0_PExRCSSET rstpyn */
479 if ((valPE0 & PESDRx_RCSSET_RSTPYN) || (valPE1 & PESDRx_RCSSET_RSTPYN)) {
480 printf("PCIE: SDR0_PExRCSSET rstpyn error\n");
484 /* SDR0_PExRCSSET hldplb */
485 if ((valPE0 & PESDRx_RCSSET_HLDPLB) || (valPE1 & PESDRx_RCSSET_HLDPLB)) {
486 printf("PCIE: SDR0_PExRCSSET hldplb error\n");
490 /* SDR0_PExRCSSET rdy */
491 if ((valPE0 & PESDRx_RCSSET_RDY) || (valPE1 & PESDRx_RCSSET_RDY)) {
492 printf("PCIE: SDR0_PExRCSSET rdy error\n");
500 * Initialize PCI Express core as described in User Manual
501 * TODO: double check PE SDR PLL Register with the updated user manual.
503 int ppc4xx_init_pcie(void)
510 #endif /* CONFIG_460EX */
512 #if defined(CONFIG_405EX)
513 static void ppc4xx_setup_utl(u32 port)
518 * Map UTL registers at 0xef4f_n000 (4K 0xfff mask) PEGPLn_REGMSK
522 mtdcr(DCRN_PEGPL_REGBAH(PCIE0), 0x00000000);
523 mtdcr(DCRN_PEGPL_REGBAL(PCIE0), CONFIG_SYS_PCIE0_UTLBASE);
524 mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001); /* 4k region, valid */
525 mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0);
529 mtdcr(DCRN_PEGPL_REGBAH(PCIE1), 0x00000000);
530 mtdcr(DCRN_PEGPL_REGBAL(PCIE1), CONFIG_SYS_PCIE1_UTLBASE);
531 mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001); /* 4k region, valid */
532 mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0);
536 utl_base = (port==0) ? CONFIG_SYS_PCIE0_UTLBASE : CONFIG_SYS_PCIE1_UTLBASE;
539 * Set buffer allocations and then assert VRB and TXE.
541 out_be32((u32 *)(utl_base + PEUTL_OUTTR), 0x02000000);
542 out_be32((u32 *)(utl_base + PEUTL_INTR), 0x02000000);
543 out_be32((u32 *)(utl_base + PEUTL_OPDBSZ), 0x04000000);
544 out_be32((u32 *)(utl_base + PEUTL_PBBSZ), 0x21000000);
545 out_be32((u32 *)(utl_base + PEUTL_IPHBSZ), 0x02000000);
546 out_be32((u32 *)(utl_base + PEUTL_IPDBSZ), 0x04000000);
547 out_be32((u32 *)(utl_base + PEUTL_RCIRQEN), 0x00f00000);
548 out_be32((u32 *)(utl_base + PEUTL_PCTL), 0x80800066);
550 out_be32((u32 *)(utl_base + PEUTL_PBCTL), 0x0800000c);
551 out_be32((u32 *)(utl_base + PEUTL_RCSTA),
552 in_be32((u32 *)(utl_base + PEUTL_RCSTA)) | 0x000040000);
555 int ppc4xx_init_pcie(void)
558 * Nothing to do on 405EX
562 #endif /* CONFIG_405EX */
565 * Board-specific pcie initialization
566 * Platform code can reimplement ppc4xx_init_pcie_port_hw() if needed
570 * Initialize various parts of the PCI Express core for our port:
572 * - Set as a root port and enable max width
573 * (PXIE0 -> X8, PCIE1 and PCIE2 -> X4).
574 * - Set up UTL configuration.
575 * - Increase SERDES drive strength to levels suggested by AMCC.
576 * - De-assert RSTPYN, RSTDL and RSTGU.
578 * NOTICE for 440SPE revB chip: PESDRn_UTLSET2 is not set - we leave it
579 * with default setting 0x11310000. The register has new fields,
580 * PESDRn_UTLSET2[LKINE] in particular: clearing it leads to PCIE core
583 #if defined(CONFIG_440SPE)
584 int __ppc4xx_init_pcie_port_hw(int port, int rootport)
590 val = PTYPE_ROOT_PORT << 20;
591 utlset1 = 0x21222222;
593 val = PTYPE_LEGACY_ENDPOINT << 20;
594 utlset1 = 0x20222222;
598 val |= LNKW_X8 << 12;
600 val |= LNKW_X4 << 12;
602 SDR_WRITE(SDRN_PESDR_DLPSET(port), val);
603 SDR_WRITE(SDRN_PESDR_UTLSET1(port), utlset1);
604 if (!ppc440spe_revB())
605 SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x11000000);
606 SDR_WRITE(SDRN_PESDR_HSSL0SET1(port), 0x35000000);
607 SDR_WRITE(SDRN_PESDR_HSSL1SET1(port), 0x35000000);
608 SDR_WRITE(SDRN_PESDR_HSSL2SET1(port), 0x35000000);
609 SDR_WRITE(SDRN_PESDR_HSSL3SET1(port), 0x35000000);
611 SDR_WRITE(PESDR0_HSSL4SET1, 0x35000000);
612 SDR_WRITE(PESDR0_HSSL5SET1, 0x35000000);
613 SDR_WRITE(PESDR0_HSSL6SET1, 0x35000000);
614 SDR_WRITE(PESDR0_HSSL7SET1, 0x35000000);
616 SDR_WRITE(SDRN_PESDR_RCSSET(port), (SDR_READ(SDRN_PESDR_RCSSET(port)) &
617 ~(1 << 24 | 1 << 16)) | 1 << 12);
621 #endif /* CONFIG_440SPE */
623 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
624 int __ppc4xx_init_pcie_port_hw(int port, int rootport)
630 val = PTYPE_ROOT_PORT << 20;
632 val = PTYPE_LEGACY_ENDPOINT << 20;
635 val |= LNKW_X1 << 12;
636 utlset1 = 0x20000000;
638 val |= LNKW_X4 << 12;
639 utlset1 = 0x20101101;
642 SDR_WRITE(SDRN_PESDR_DLPSET(port), val);
643 SDR_WRITE(SDRN_PESDR_UTLSET1(port), utlset1);
644 SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x01210000);
648 SDR_WRITE(PESDR0_L0CDRCTL, 0x00003230);
649 SDR_WRITE(PESDR0_L0DRV, 0x00000130);
650 SDR_WRITE(PESDR0_L0CLK, 0x00000006);
652 SDR_WRITE(PESDR0_PHY_CTL_RST,0x10000000);
656 SDR_WRITE(PESDR1_L0CDRCTL, 0x00003230);
657 SDR_WRITE(PESDR1_L1CDRCTL, 0x00003230);
658 SDR_WRITE(PESDR1_L2CDRCTL, 0x00003230);
659 SDR_WRITE(PESDR1_L3CDRCTL, 0x00003230);
660 SDR_WRITE(PESDR1_L0DRV, 0x00000130);
661 SDR_WRITE(PESDR1_L1DRV, 0x00000130);
662 SDR_WRITE(PESDR1_L2DRV, 0x00000130);
663 SDR_WRITE(PESDR1_L3DRV, 0x00000130);
664 SDR_WRITE(PESDR1_L0CLK, 0x00000006);
665 SDR_WRITE(PESDR1_L1CLK, 0x00000006);
666 SDR_WRITE(PESDR1_L2CLK, 0x00000006);
667 SDR_WRITE(PESDR1_L3CLK, 0x00000006);
669 SDR_WRITE(PESDR1_PHY_CTL_RST,0x10000000);
673 SDR_WRITE(SDRN_PESDR_RCSSET(port), SDR_READ(SDRN_PESDR_RCSSET(port)) |
674 (PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTPYN));
676 /* Poll for PHY reset */
679 while (!(SDR_READ(PESDR0_RSTSTA) & 0x1))
683 while (!(SDR_READ(PESDR1_RSTSTA) & 0x1))
688 SDR_WRITE(SDRN_PESDR_RCSSET(port),
689 (SDR_READ(SDRN_PESDR_RCSSET(port)) &
690 ~(PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTDL)) |
691 PESDRx_RCSSET_RSTPYN);
695 #endif /* CONFIG_440SPE */
697 #if defined(CONFIG_405EX)
698 int __ppc4xx_init_pcie_port_hw(int port, int rootport)
707 SDR_WRITE(SDRN_PESDR_DLPSET(port), val);
708 SDR_WRITE(SDRN_PESDR_UTLSET1(port), 0x00000000);
709 SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x01010000);
710 SDR_WRITE(SDRN_PESDR_PHYSET1(port), 0x720F0000);
711 SDR_WRITE(SDRN_PESDR_PHYSET2(port), 0x70600003);
713 /* Assert the PE0_PHY reset */
714 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01010000);
717 /* deassert the PE0_hotreset */
718 if (is_end_point(port))
719 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01111000);
721 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01101000);
723 /* poll for phy !reset */
724 while (!(SDR_READ(SDRN_PESDR_PHYSTA(port)) & 0x00001000))
727 /* deassert the PE0_gpl_utl_reset */
728 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x00101000);
731 mtdcr(DCRN_PEGPL_CFG(PCIE0), 0x10000000); /* guarded on */
733 mtdcr(DCRN_PEGPL_CFG(PCIE1), 0x10000000); /* guarded on */
737 #endif /* CONFIG_405EX */
739 int ppc4xx_init_pcie_port_hw(int port, int rootport)
740 __attribute__((weak, alias("__ppc4xx_init_pcie_port_hw")));
743 * We map PCI Express configuration access into the 512MB regions
745 * NOTICE: revB is very strict about PLB real addressess and ranges to
746 * be mapped for config space; it seems to only work with d_nnnn_nnnn
747 * range (hangs the core upon config transaction attempts when set
748 * otherwise) while revA uses c_nnnn_nnnn.
751 * PCIE0: 0xc_4000_0000
752 * PCIE1: 0xc_8000_0000
753 * PCIE2: 0xc_c000_0000
756 * PCIE0: 0xd_0000_0000
757 * PCIE1: 0xd_2000_0000
758 * PCIE2: 0xd_4000_0000
765 * PCIE0: 0xd_0000_0000
766 * PCIE1: 0xd_2000_0000
768 static inline u64 ppc4xx_get_cfgaddr(int port)
770 #if defined(CONFIG_405EX)
772 return (u64)CONFIG_SYS_PCIE0_CFGBASE;
774 return (u64)CONFIG_SYS_PCIE1_CFGBASE;
776 #if defined(CONFIG_440SPE)
777 if (ppc440spe_revB()) {
779 default: /* to satisfy compiler */
781 return 0x0000000d00000000ULL;
783 return 0x0000000d20000000ULL;
785 return 0x0000000d40000000ULL;
789 default: /* to satisfy compiler */
791 return 0x0000000c40000000ULL;
793 return 0x0000000c80000000ULL;
795 return 0x0000000cc0000000ULL;
799 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
801 return 0x0000000d00000000ULL;
803 return 0x0000000d20000000ULL;
808 * 4xx boards as end point and root point setup
810 * testing inbound and out bound windows
812 * 4xx boards can be plugged into another 4xx boards or you can get PCI-E
813 * cable which can be used to setup loop back from one port to another port.
814 * Please rememeber that unless there is a endpoint plugged in to root port it
815 * will not initialize. It is the same in case of endpoint , unless there is
816 * root port attached it will not initialize.
818 * In this release of software all the PCI-E ports are configured as either
819 * endpoint or rootpoint.In future we will have support for selective ports
820 * setup as endpoint and root point in single board.
822 * Once your board came up as root point , you can verify by reading
823 * /proc/bus/pci/devices. Where you can see the configuration registers
824 * of end point device attached to the port.
826 * Enpoint cofiguration can be verified by connecting 4xx board to any
827 * host or another 4xx board. Then try to scan the device. In case of
828 * linux use "lspci" or appripriate os command.
830 * How do I verify the inbound and out bound windows ? (4xx to 4xx)
831 * in this configuration inbound and outbound windows are setup to access
832 * sram memroy area. SRAM is at 0x4 0000 0000 , on PLB bus. This address
833 * is mapped at 0x90000000. From u-boot prompt write data 0xb000 0000,
834 * This is waere your POM(PLB out bound memory window) mapped. then
835 * read the data from other 4xx board's u-boot prompt at address
836 * 0x9000 0000(SRAM). Data should match.
837 * In case of inbound , write data to u-boot command prompt at 0xb000 0000
838 * which is mapped to 0x4 0000 0000. Now on rootpoint yucca u-boot prompt check
839 * data at 0x9000 0000(SRAM).Data should match.
841 int ppc4xx_init_pcie_port(int port, int rootport)
843 static int core_init;
844 volatile u32 val = 0;
850 if (ppc4xx_init_pcie())
856 * Initialize various parts of the PCI Express core for our port
858 ppc4xx_init_pcie_port_hw(port, rootport);
861 * Notice: the following delay has critical impact on device
862 * initialization - if too short (<50ms) the link doesn't get up.
866 val = SDR_READ(SDRN_PESDR_RCSSTS(port));
867 if (val & (1 << 20)) {
868 printf("PCIE%d: PGRST failed %08x\n", port, val);
875 val = SDR_READ(SDRN_PESDR_LOOP(port));
876 if (!(val & 0x00001000)) {
877 printf("PCIE%d: link is not up.\n", port);
882 * Setup UTL registers - but only on revA!
883 * We use default settings for revB chip.
885 if (!ppc440spe_revB())
886 ppc4xx_setup_utl(port);
889 * We map PCI Express configuration access into the 512MB regions
891 addr = ppc4xx_get_cfgaddr(port);
892 low = U64_TO_U32_LOW(addr);
893 high = U64_TO_U32_HIGH(addr);
897 mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), high);
898 mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), low);
899 mtdcr(DCRN_PEGPL_CFGMSK(PCIE0), 0xe0000001); /* 512MB region, valid */
902 mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), high);
903 mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), low);
904 mtdcr(DCRN_PEGPL_CFGMSK(PCIE1), 0xe0000001); /* 512MB region, valid */
906 #if CONFIG_SYS_PCIE_NR_PORTS > 2
908 mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), high);
909 mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), low);
910 mtdcr(DCRN_PEGPL_CFGMSK(PCIE2), 0xe0000001); /* 512MB region, valid */
916 * Check for VC0 active and assert RDY.
919 while(!(SDR_READ(SDRN_PESDR_RCSSTS(port)) & (1 << 16))) {
921 printf("PCIE%d: VC0 not active\n", port);
926 SDR_WRITE(SDRN_PESDR_RCSSET(port),
927 SDR_READ(SDRN_PESDR_RCSSET(port)) | 1 << 20);
933 int ppc4xx_init_pcie_rootport(int port)
935 return ppc4xx_init_pcie_port(port, 1);
938 int ppc4xx_init_pcie_endport(int port)
940 return ppc4xx_init_pcie_port(port, 0);
943 void ppc4xx_setup_pcie_rootpoint(struct pci_controller *hose, int port)
945 volatile void *mbase = NULL;
946 volatile void *rmbase = NULL;
949 pcie_read_config_byte,
950 pcie_read_config_word,
951 pcie_read_config_dword,
952 pcie_write_config_byte,
953 pcie_write_config_word,
954 pcie_write_config_dword);
958 mbase = (u32 *)CONFIG_SYS_PCIE0_XCFGBASE;
959 rmbase = (u32 *)CONFIG_SYS_PCIE0_CFGBASE;
960 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE0_CFGBASE;
963 mbase = (u32 *)CONFIG_SYS_PCIE1_XCFGBASE;
964 rmbase = (u32 *)CONFIG_SYS_PCIE1_CFGBASE;
965 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE1_CFGBASE;
967 #if CONFIG_SYS_PCIE_NR_PORTS > 2
969 mbase = (u32 *)CONFIG_SYS_PCIE2_XCFGBASE;
970 rmbase = (u32 *)CONFIG_SYS_PCIE2_CFGBASE;
971 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE2_CFGBASE;
977 * Set bus numbers on our root port
979 out_8((u8 *)mbase + PCI_PRIMARY_BUS, 0);
980 out_8((u8 *)mbase + PCI_SECONDARY_BUS, 1);
981 out_8((u8 *)mbase + PCI_SUBORDINATE_BUS, 1);
984 * Set up outbound translation to hose->mem_space from PLB
985 * addresses at an offset of 0xd_0000_0000. We set the low
986 * bits of the mask to 11 to turn off splitting into 8
987 * subregions and to enable the outbound translation.
989 out_le32(mbase + PECFG_POM0LAH, 0x00000000);
990 out_le32(mbase + PECFG_POM0LAL, CONFIG_SYS_PCIE_MEMBASE +
991 port * CONFIG_SYS_PCIE_MEMSIZE);
992 debug("PECFG_POM0LA=%08x.%08x\n", in_le32(mbase + PECFG_POM0LAH),
993 in_le32(mbase + PECFG_POM0LAL));
997 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), CONFIG_SYS_PCIE_ADDR_HIGH);
998 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CONFIG_SYS_PCIE_MEMBASE +
999 port * CONFIG_SYS_PCIE_MEMSIZE);
1000 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
1001 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
1002 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
1003 debug("0:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n",
1004 mfdcr(DCRN_PEGPL_OMR1BAH(PCIE0)),
1005 mfdcr(DCRN_PEGPL_OMR1BAL(PCIE0)),
1006 mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE0)),
1007 mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE0)));
1010 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), CONFIG_SYS_PCIE_ADDR_HIGH);
1011 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), CONFIG_SYS_PCIE_MEMBASE +
1012 port * CONFIG_SYS_PCIE_MEMSIZE);
1013 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
1014 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
1015 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
1016 debug("1:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n",
1017 mfdcr(DCRN_PEGPL_OMR1BAH(PCIE1)),
1018 mfdcr(DCRN_PEGPL_OMR1BAL(PCIE1)),
1019 mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE1)),
1020 mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE1)));
1022 #if CONFIG_SYS_PCIE_NR_PORTS > 2
1024 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), CONFIG_SYS_PCIE_ADDR_HIGH);
1025 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), CONFIG_SYS_PCIE_MEMBASE +
1026 port * CONFIG_SYS_PCIE_MEMSIZE);
1027 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
1028 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
1029 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
1030 debug("2:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n",
1031 mfdcr(DCRN_PEGPL_OMR1BAH(PCIE2)),
1032 mfdcr(DCRN_PEGPL_OMR1BAL(PCIE2)),
1033 mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE2)),
1034 mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE2)));
1039 /* Set up 4GB inbound memory window at 0 */
1040 out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
1041 out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
1042 out_le32(mbase + PECFG_BAR0HMPA, 0x7ffffff);
1043 out_le32(mbase + PECFG_BAR0LMPA, 0);
1045 out_le32(mbase + PECFG_PIM01SAH, 0xffff0000);
1046 out_le32(mbase + PECFG_PIM01SAL, 0x00000000);
1047 out_le32(mbase + PECFG_PIM0LAL, 0);
1048 out_le32(mbase + PECFG_PIM0LAH, 0);
1049 out_le32(mbase + PECFG_PIM1LAL, 0x00000000);
1050 out_le32(mbase + PECFG_PIM1LAH, 0x00000004);
1051 out_le32(mbase + PECFG_PIMEN, 0x1);
1053 /* Enable I/O, Mem, and Busmaster cycles */
1054 out_le16((u16 *)(mbase + PCI_COMMAND),
1055 in_le16((u16 *)(mbase + PCI_COMMAND)) |
1056 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
1058 /* Set Device and Vendor Id */
1059 out_le16(mbase + 0x200, 0xaaa0 + port);
1060 out_le16(mbase + 0x202, 0xbed0 + port);
1062 /* Set Class Code to PCI-PCI bridge and Revision Id to 1 */
1063 out_le32(mbase + 0x208, 0x06040001);
1065 printf("PCIE%d: successfully set as root-complex\n", port);
1068 int ppc4xx_setup_pcie_endpoint(struct pci_controller *hose, int port)
1070 volatile void *mbase = NULL;
1074 pcie_read_config_byte,
1075 pcie_read_config_word,
1076 pcie_read_config_dword,
1077 pcie_write_config_byte,
1078 pcie_write_config_word,
1079 pcie_write_config_dword);
1083 mbase = (u32 *)CONFIG_SYS_PCIE0_XCFGBASE;
1084 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE0_CFGBASE;
1087 mbase = (u32 *)CONFIG_SYS_PCIE1_XCFGBASE;
1088 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE1_CFGBASE;
1090 #if defined(CONFIG_SYS_PCIE2_CFGBASE)
1092 mbase = (u32 *)CONFIG_SYS_PCIE2_XCFGBASE;
1093 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE2_CFGBASE;
1099 * Set up outbound translation to hose->mem_space from PLB
1100 * addresses at an offset of 0xd_0000_0000. We set the low
1101 * bits of the mask to 11 to turn off splitting into 8
1102 * subregions and to enable the outbound translation.
1104 out_le32(mbase + PECFG_POM0LAH, 0x00001ff8);
1105 out_le32(mbase + PECFG_POM0LAL, 0x00001000);
1109 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), CONFIG_SYS_PCIE_ADDR_HIGH);
1110 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CONFIG_SYS_PCIE_MEMBASE +
1111 port * CONFIG_SYS_PCIE_MEMSIZE);
1112 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
1113 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
1114 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
1117 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), CONFIG_SYS_PCIE_ADDR_HIGH);
1118 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), CONFIG_SYS_PCIE_MEMBASE +
1119 port * CONFIG_SYS_PCIE_MEMSIZE);
1120 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
1121 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
1122 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
1124 #if CONFIG_SYS_PCIE_NR_PORTS > 2
1126 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), CONFIG_SYS_PCIE_ADDR_HIGH);
1127 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), CONFIG_SYS_PCIE_MEMBASE +
1128 port * CONFIG_SYS_PCIE_MEMSIZE);
1129 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
1130 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
1131 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
1136 /* Set up 64MB inbound memory window at 0 */
1137 out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
1138 out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
1140 out_le32(mbase + PECFG_PIM01SAH, 0xffffffff);
1141 out_le32(mbase + PECFG_PIM01SAL, 0xfc000000);
1144 out_le32(mbase + PECFG_BAR0HMPA, 0x7fffffff);
1145 out_le32(mbase + PECFG_BAR0LMPA, 0xfc000000 | PCI_BASE_ADDRESS_MEM_TYPE_64);
1147 /* Disable BAR1 & BAR2 */
1148 out_le32(mbase + PECFG_BAR1MPA, 0);
1149 out_le32(mbase + PECFG_BAR2HMPA, 0);
1150 out_le32(mbase + PECFG_BAR2LMPA, 0);
1152 out_le32(mbase + PECFG_PIM0LAL, U64_TO_U32_LOW(CONFIG_SYS_PCIE_INBOUND_BASE));
1153 out_le32(mbase + PECFG_PIM0LAH, U64_TO_U32_HIGH(CONFIG_SYS_PCIE_INBOUND_BASE));
1154 out_le32(mbase + PECFG_PIMEN, 0x1);
1156 /* Enable I/O, Mem, and Busmaster cycles */
1157 out_le16((u16 *)(mbase + PCI_COMMAND),
1158 in_le16((u16 *)(mbase + PCI_COMMAND)) |
1159 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
1160 out_le16(mbase + 0x200, 0xcaad); /* Setting vendor ID */
1161 out_le16(mbase + 0x202, 0xfeed); /* Setting device ID */
1163 /* Set Class Code to Processor/PPC */
1164 out_le32(mbase + 0x208, 0x0b200001);
1167 while(!(SDR_READ(SDRN_PESDR_RCSSTS(port)) & (1 << 8))) {
1168 if (!(attempts--)) {
1169 printf("PCIE%d: BME not active\n", port);
1175 printf("PCIE%d: successfully set as endpoint\n", port);
1179 #endif /* CONFIG_440SPE && CONFIG_PCI */