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 ;-)) */
30 #include <asm/ppc4xx.h>
31 #include <asm/processor.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 struct pci_controller pcie_hose[CONFIG_SYS_PCIE_NR_PORTS];
54 * Per default, all cards are present, so we need to check if the
57 int __board_pcie_card_present(int port)
61 int board_pcie_card_present(int port)
62 __attribute__((weak, alias("__board_pcie_card_present")));
65 * Some boards have runtime detection of the first and last PCIe
66 * slot used, so let's provide weak default functions for the
69 int __board_pcie_first(void)
73 int board_pcie_first(void)
74 __attribute__((weak, alias("__board_pcie_first")));
76 int __board_pcie_last(void)
78 return CONFIG_SYS_PCIE_NR_PORTS - 1;
80 int board_pcie_last(void)
81 __attribute__((weak, alias("__board_pcie_last")));
83 void __board_pcie_setup_port(int port, int rootpoint)
85 /* noting in this weak default implementation */
87 void board_pcie_setup_port(int port, int rootpoint)
88 __attribute__((weak, alias("__board_pcie_setup_port")));
90 void pcie_setup_hoses(int busno)
92 struct pci_controller *hose;
97 int first = board_pcie_first();
98 int last = board_pcie_last();
101 * Assume we're called after the PCI(X) hose(s) are initialized,
102 * which takes bus ID 0... and therefore start numbering PCIe's
103 * from the next number.
107 for (i = first; i <= last; i++) {
109 * Some boards (e.g. Katmai) can detects via hardware
110 * if a PCIe card is plugged, so let's check this.
112 if (!board_pcie_card_present(i))
115 if (is_end_point(i)) {
116 board_pcie_setup_port(i, 0);
117 ret = ppc4xx_init_pcie_endport(i);
119 board_pcie_setup_port(i, 1);
120 ret = ppc4xx_init_pcie_rootport(i);
125 printf("PCIE%d: initialization as %s failed\n", i,
126 is_end_point(i) ? "endpoint" : "root-complex");
130 hose = &pcie_hose[i];
131 hose->first_busno = bus;
132 hose->last_busno = bus;
133 hose->current_busno = bus;
135 /* setup mem resource */
136 pci_set_region(hose->regions + 0,
137 CONFIG_SYS_PCIE_MEMBASE + i * CONFIG_SYS_PCIE_MEMSIZE,
138 CONFIG_SYS_PCIE_MEMBASE + i * CONFIG_SYS_PCIE_MEMSIZE,
139 CONFIG_SYS_PCIE_MEMSIZE,
141 hose->region_count = 1;
142 pci_register_hose(hose);
144 if (is_end_point(i)) {
145 ppc4xx_setup_pcie_endpoint(hose, i);
147 * Reson for no scanning is endpoint can not generate
148 * upstream configuration accesses.
151 ppc4xx_setup_pcie_rootpoint(hose, i);
152 env = getenv ("pciscandelay");
154 delay = simple_strtoul(env, NULL, 10);
156 printf("Warning, expect noticable delay before "
157 "PCIe scan due to 'pciscandelay' value!\n");
158 mdelay(delay * 1000);
162 * Config access can only go down stream
164 hose->last_busno = pci_hose_scan(hose);
165 bus = hose->last_busno + 1;
170 static int validate_endpoint(struct pci_controller *hose)
172 if (hose->cfg_data == (u8 *)CONFIG_SYS_PCIE0_CFGBASE)
173 return (is_end_point(0));
174 else if (hose->cfg_data == (u8 *)CONFIG_SYS_PCIE1_CFGBASE)
175 return (is_end_point(1));
176 #if CONFIG_SYS_PCIE_NR_PORTS > 2
177 else if (hose->cfg_data == (u8 *)CONFIG_SYS_PCIE2_CFGBASE)
178 return (is_end_point(2));
184 static u8* pcie_get_base(struct pci_controller *hose, unsigned int devfn)
186 u8 *base = (u8*)hose->cfg_data;
188 /* use local configuration space for the first bus */
189 if (PCI_BUS(devfn) == 0) {
190 if (hose->cfg_data == (u8*)CONFIG_SYS_PCIE0_CFGBASE)
191 base = (u8*)CONFIG_SYS_PCIE0_XCFGBASE;
192 if (hose->cfg_data == (u8*)CONFIG_SYS_PCIE1_CFGBASE)
193 base = (u8*)CONFIG_SYS_PCIE1_XCFGBASE;
194 #if CONFIG_SYS_PCIE_NR_PORTS > 2
195 if (hose->cfg_data == (u8*)CONFIG_SYS_PCIE2_CFGBASE)
196 base = (u8*)CONFIG_SYS_PCIE2_XCFGBASE;
203 static void pcie_dmer_disable(void)
205 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE),
206 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE)) | GPL_DMER_MASK_DISA);
207 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE),
208 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE)) | GPL_DMER_MASK_DISA);
209 #if CONFIG_SYS_PCIE_NR_PORTS > 2
210 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE),
211 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE)) | GPL_DMER_MASK_DISA);
215 static void pcie_dmer_enable(void)
217 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE0_BASE),
218 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE)) & ~GPL_DMER_MASK_DISA);
219 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE1_BASE),
220 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE)) & ~GPL_DMER_MASK_DISA);
221 #if CONFIG_SYS_PCIE_NR_PORTS > 2
222 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE2_BASE),
223 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE)) & ~GPL_DMER_MASK_DISA);
227 static int pcie_read_config(struct pci_controller *hose, unsigned int devfn,
228 int offset, int len, u32 *val) {
233 if (validate_endpoint(hose))
234 return 0; /* No upstream config access */
237 * Bus numbers are relative to hose->first_busno
239 devfn -= PCI_BDF(hose->first_busno, 0, 0);
242 * NOTICE: configuration space ranges are currenlty mapped only for
243 * the first 16 buses, so such limit must be imposed. In case more
244 * buses are required the TLB settings in board/amcc/<board>/init.S
245 * need to be altered accordingly (one bus takes 1 MB of memory space).
247 if (PCI_BUS(devfn) >= 16)
251 * Only single device/single function is supported for the primary and
252 * secondary buses of the 440SPe host bridge.
254 if ((!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 0))) &&
255 ((PCI_BUS(devfn) == 0) || (PCI_BUS(devfn) == 1)))
258 address = pcie_get_base(hose, devfn);
259 offset += devfn << 4;
262 * Reading from configuration space of non-existing device can
263 * generate transaction errors. For the read duration we suppress
264 * assertion of machine check exceptions to avoid those.
266 pcie_dmer_disable ();
268 debug("%s: cfg_data=%p offset=%08x\n", __func__,
269 hose->cfg_data, offset);
272 *val = in_8(hose->cfg_data + offset);
275 *val = in_le16((u16 *)(hose->cfg_data + offset));
278 *val = in_le32((u32*)(hose->cfg_data + offset));
287 static int pcie_write_config(struct pci_controller *hose, unsigned int devfn,
288 int offset, int len, u32 val) {
292 if (validate_endpoint(hose))
293 return 0; /* No upstream config access */
296 * Bus numbers are relative to hose->first_busno
298 devfn -= PCI_BDF(hose->first_busno, 0, 0);
301 * Same constraints as in pcie_read_config().
303 if (PCI_BUS(devfn) >= 16)
306 if ((!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 0))) &&
307 ((PCI_BUS(devfn) == 0) || (PCI_BUS(devfn) == 1)))
310 address = pcie_get_base(hose, devfn);
311 offset += devfn << 4;
314 * Suppress MCK exceptions, similar to pcie_read_config()
316 pcie_dmer_disable ();
320 out_8(hose->cfg_data + offset, val);
323 out_le16((u16 *)(hose->cfg_data + offset), val);
326 out_le32((u32 *)(hose->cfg_data + offset), val);
335 int pcie_read_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 *val)
340 rv = pcie_read_config(hose, dev, offset, 1, &v);
345 int pcie_read_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 *val)
350 rv = pcie_read_config(hose, dev, offset, 2, &v);
355 int pcie_read_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 *val)
360 rv = pcie_read_config(hose, dev, offset, 3, &v);
365 int pcie_write_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 val)
367 return pcie_write_config(hose,(u32)dev,offset,1,val);
370 int pcie_write_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 val)
372 return pcie_write_config(hose,(u32)dev,offset,2,(u32 )val);
375 int pcie_write_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 val)
377 return pcie_write_config(hose,(u32)dev,offset,3,(u32 )val);
380 #if defined(CONFIG_440SPE)
381 static void ppc4xx_setup_utl(u32 port) {
383 volatile void *utl_base = NULL;
390 mtdcr(DCRN_PEGPL_REGBAH(PCIE0), 0x0000000c);
391 mtdcr(DCRN_PEGPL_REGBAL(PCIE0), 0x20000000);
392 mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001);
393 mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0x68782800);
397 mtdcr(DCRN_PEGPL_REGBAH(PCIE1), 0x0000000c);
398 mtdcr(DCRN_PEGPL_REGBAL(PCIE1), 0x20001000);
399 mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001);
400 mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0x68782800);
404 mtdcr(DCRN_PEGPL_REGBAH(PCIE2), 0x0000000c);
405 mtdcr(DCRN_PEGPL_REGBAL(PCIE2), 0x20002000);
406 mtdcr(DCRN_PEGPL_REGMSK(PCIE2), 0x00007001);
407 mtdcr(DCRN_PEGPL_SPECIAL(PCIE2), 0x68782800);
410 utl_base = (unsigned int *)(CONFIG_SYS_PCIE_BASE + 0x1000 * port);
413 * Set buffer allocations and then assert VRB and TXE.
415 out_be32(utl_base + PEUTL_OUTTR, 0x08000000);
416 out_be32(utl_base + PEUTL_INTR, 0x02000000);
417 out_be32(utl_base + PEUTL_OPDBSZ, 0x10000000);
418 out_be32(utl_base + PEUTL_PBBSZ, 0x53000000);
419 out_be32(utl_base + PEUTL_IPHBSZ, 0x08000000);
420 out_be32(utl_base + PEUTL_IPDBSZ, 0x10000000);
421 out_be32(utl_base + PEUTL_RCIRQEN, 0x00f00000);
422 out_be32(utl_base + PEUTL_PCTL, 0x80800066);
425 static int check_error(void)
427 u32 valPE0, valPE1, valPE2;
430 /* SDR0_PEGPLLLCT1 reset */
431 if (!(valPE0 = SDR_READ(PESDR0_PLLLCT1) & 0x01000000))
432 printf("PCIE: SDR0_PEGPLLLCT1 reset error 0x%x\n", valPE0);
434 valPE0 = SDR_READ(PESDR0_RCSSET);
435 valPE1 = SDR_READ(PESDR1_RCSSET);
436 valPE2 = SDR_READ(PESDR2_RCSSET);
438 /* SDR0_PExRCSSET rstgu */
439 if (!(valPE0 & 0x01000000) ||
440 !(valPE1 & 0x01000000) ||
441 !(valPE2 & 0x01000000)) {
442 printf("PCIE: SDR0_PExRCSSET rstgu error\n");
446 /* SDR0_PExRCSSET rstdl */
447 if (!(valPE0 & 0x00010000) ||
448 !(valPE1 & 0x00010000) ||
449 !(valPE2 & 0x00010000)) {
450 printf("PCIE: SDR0_PExRCSSET rstdl error\n");
454 /* SDR0_PExRCSSET rstpyn */
455 if ((valPE0 & 0x00001000) ||
456 (valPE1 & 0x00001000) ||
457 (valPE2 & 0x00001000)) {
458 printf("PCIE: SDR0_PExRCSSET rstpyn error\n");
462 /* SDR0_PExRCSSET hldplb */
463 if ((valPE0 & 0x10000000) ||
464 (valPE1 & 0x10000000) ||
465 (valPE2 & 0x10000000)) {
466 printf("PCIE: SDR0_PExRCSSET hldplb error\n");
470 /* SDR0_PExRCSSET rdy */
471 if ((valPE0 & 0x00100000) ||
472 (valPE1 & 0x00100000) ||
473 (valPE2 & 0x00100000)) {
474 printf("PCIE: SDR0_PExRCSSET rdy error\n");
478 /* SDR0_PExRCSSET shutdown */
479 if ((valPE0 & 0x00000100) ||
480 (valPE1 & 0x00000100) ||
481 (valPE2 & 0x00000100)) {
482 printf("PCIE: SDR0_PExRCSSET shutdown error\n");
489 * Initialize PCI Express core
491 int ppc4xx_init_pcie(void)
495 /* Set PLL clock receiver to LVPECL */
496 SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) | 1 << 28);
499 printf("ERROR: failed to set PCIe reference clock receiver --"
500 "PESDR0_PLLLCT1 = 0x%08x\n", SDR_READ(PESDR0_PLLLCT1));
505 /* Did resistance calibration work? */
506 if (!(SDR_READ(PESDR0_PLLLCT2) & 0x10000)) {
507 printf("ERROR: PCIe resistance calibration failed --"
508 "PESDR0_PLLLCT2 = 0x%08x\n", SDR_READ(PESDR0_PLLLCT2));
512 /* De-assert reset of PCIe PLL, wait for lock */
513 SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) & ~(1 << 24));
514 udelay(300); /* 300 uS is maximum time lock should take */
517 if (!(SDR_READ(PESDR0_PLLLCT3) & 0x10000000)) {
519 udelay(20); /* Wait 20 uS more if needed */
524 printf("ERROR: PCIe PLL VCO output not locked to ref clock --"
525 "PESDR0_PLLLCTS=0x%08x\n", SDR_READ(PESDR0_PLLLCT3));
533 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
534 static void ppc4xx_setup_utl(u32 port)
536 volatile void *utl_base = NULL;
539 * Map UTL registers at 0x0801_n000 (4K 0xfff mask) PEGPLn_REGMSK
543 mtdcr(DCRN_PEGPL_REGBAH(PCIE0), U64_TO_U32_HIGH(CONFIG_SYS_PCIE0_UTLBASE));
544 mtdcr(DCRN_PEGPL_REGBAL(PCIE0), U64_TO_U32_LOW(CONFIG_SYS_PCIE0_UTLBASE));
545 mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001); /* BAM 11100000=4KB */
546 mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0);
550 mtdcr(DCRN_PEGPL_REGBAH(PCIE1), U64_TO_U32_HIGH(CONFIG_SYS_PCIE0_UTLBASE));
551 mtdcr(DCRN_PEGPL_REGBAL(PCIE1), U64_TO_U32_LOW(CONFIG_SYS_PCIE0_UTLBASE)
553 mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001); /* BAM 11100000=4KB */
554 mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0);
557 utl_base = (unsigned int *)(CONFIG_SYS_PCIE_BASE + 0x1000 * port);
560 * Set buffer allocations and then assert VRB and TXE.
562 out_be32(utl_base + PEUTL_PBCTL, 0x0800000c); /* PLBME, CRRE */
563 out_be32(utl_base + PEUTL_OUTTR, 0x08000000);
564 out_be32(utl_base + PEUTL_INTR, 0x02000000);
565 out_be32(utl_base + PEUTL_OPDBSZ, 0x04000000); /* OPD = 512 Bytes */
566 out_be32(utl_base + PEUTL_PBBSZ, 0x00000000); /* Max 512 Bytes */
567 out_be32(utl_base + PEUTL_IPHBSZ, 0x02000000);
568 out_be32(utl_base + PEUTL_IPDBSZ, 0x04000000); /* IPD = 512 Bytes */
569 out_be32(utl_base + PEUTL_RCIRQEN, 0x00f00000);
570 out_be32(utl_base + PEUTL_PCTL, 0x80800066); /* VRB,TXE,timeout=default */
574 * TODO: double check PCI express SDR based on the latest user manual
575 * Some registers specified here no longer exist.. has to be
576 * updated based on the final EAS spec.
578 static int check_error(void)
583 valPE0 = SDR_READ(SDRN_PESDR_RCSSET(0));
584 valPE1 = SDR_READ(SDRN_PESDR_RCSSET(1));
586 /* SDR0_PExRCSSET rstgu */
587 if (!(valPE0 & PESDRx_RCSSET_RSTGU) || !(valPE1 & PESDRx_RCSSET_RSTGU)) {
588 printf("PCIE: SDR0_PExRCSSET rstgu error\n");
592 /* SDR0_PExRCSSET rstdl */
593 if (!(valPE0 & PESDRx_RCSSET_RSTDL) || !(valPE1 & PESDRx_RCSSET_RSTDL)) {
594 printf("PCIE: SDR0_PExRCSSET rstdl error\n");
598 /* SDR0_PExRCSSET rstpyn */
599 if ((valPE0 & PESDRx_RCSSET_RSTPYN) || (valPE1 & PESDRx_RCSSET_RSTPYN)) {
600 printf("PCIE: SDR0_PExRCSSET rstpyn error\n");
604 /* SDR0_PExRCSSET hldplb */
605 if ((valPE0 & PESDRx_RCSSET_HLDPLB) || (valPE1 & PESDRx_RCSSET_HLDPLB)) {
606 printf("PCIE: SDR0_PExRCSSET hldplb error\n");
610 /* SDR0_PExRCSSET rdy */
611 if ((valPE0 & PESDRx_RCSSET_RDY) || (valPE1 & PESDRx_RCSSET_RDY)) {
612 printf("PCIE: SDR0_PExRCSSET rdy error\n");
620 * Initialize PCI Express core as described in User Manual
621 * TODO: double check PE SDR PLL Register with the updated user manual.
623 int ppc4xx_init_pcie(void)
630 #endif /* CONFIG_460EX */
632 #if defined(CONFIG_405EX)
633 static void ppc4xx_setup_utl(u32 port)
638 * Map UTL registers at 0xef4f_n000 (4K 0xfff mask) PEGPLn_REGMSK
642 mtdcr(DCRN_PEGPL_REGBAH(PCIE0), 0x00000000);
643 mtdcr(DCRN_PEGPL_REGBAL(PCIE0), CONFIG_SYS_PCIE0_UTLBASE);
644 mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001); /* 4k region, valid */
645 mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0);
649 mtdcr(DCRN_PEGPL_REGBAH(PCIE1), 0x00000000);
650 mtdcr(DCRN_PEGPL_REGBAL(PCIE1), CONFIG_SYS_PCIE1_UTLBASE);
651 mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001); /* 4k region, valid */
652 mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0);
656 utl_base = (port==0) ? CONFIG_SYS_PCIE0_UTLBASE : CONFIG_SYS_PCIE1_UTLBASE;
659 * Set buffer allocations and then assert VRB and TXE.
661 out_be32((u32 *)(utl_base + PEUTL_OUTTR), 0x02000000);
662 out_be32((u32 *)(utl_base + PEUTL_INTR), 0x02000000);
663 out_be32((u32 *)(utl_base + PEUTL_OPDBSZ), 0x04000000);
664 out_be32((u32 *)(utl_base + PEUTL_PBBSZ), 0x21000000);
665 out_be32((u32 *)(utl_base + PEUTL_IPHBSZ), 0x02000000);
666 out_be32((u32 *)(utl_base + PEUTL_IPDBSZ), 0x04000000);
667 out_be32((u32 *)(utl_base + PEUTL_RCIRQEN), 0x00f00000);
668 out_be32((u32 *)(utl_base + PEUTL_PCTL), 0x80800066);
670 out_be32((u32 *)(utl_base + PEUTL_PBCTL), 0x0800000c);
671 out_be32((u32 *)(utl_base + PEUTL_RCSTA),
672 in_be32((u32 *)(utl_base + PEUTL_RCSTA)) | 0x000040000);
675 int ppc4xx_init_pcie(void)
678 * Nothing to do on 405EX
682 #endif /* CONFIG_405EX */
685 * Board-specific pcie initialization
686 * Platform code can reimplement ppc4xx_init_pcie_port_hw() if needed
690 * Initialize various parts of the PCI Express core for our port:
692 * - Set as a root port and enable max width
693 * (PXIE0 -> X8, PCIE1 and PCIE2 -> X4).
694 * - Set up UTL configuration.
695 * - Increase SERDES drive strength to levels suggested by AMCC.
696 * - De-assert RSTPYN, RSTDL and RSTGU.
698 * NOTICE for 440SPE revB chip: PESDRn_UTLSET2 is not set - we leave it
699 * with default setting 0x11310000. The register has new fields,
700 * PESDRn_UTLSET2[LKINE] in particular: clearing it leads to PCIE core
703 #if defined(CONFIG_440SPE)
704 int __ppc4xx_init_pcie_port_hw(int port, int rootport)
710 val = PTYPE_ROOT_PORT << 20;
711 utlset1 = 0x21222222;
713 val = PTYPE_LEGACY_ENDPOINT << 20;
714 utlset1 = 0x20222222;
718 val |= LNKW_X8 << 12;
720 val |= LNKW_X4 << 12;
722 SDR_WRITE(SDRN_PESDR_DLPSET(port), val);
723 SDR_WRITE(SDRN_PESDR_UTLSET1(port), utlset1);
724 if (!ppc440spe_revB())
725 SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x11000000);
726 SDR_WRITE(SDRN_PESDR_HSSL0SET1(port), 0x35000000);
727 SDR_WRITE(SDRN_PESDR_HSSL1SET1(port), 0x35000000);
728 SDR_WRITE(SDRN_PESDR_HSSL2SET1(port), 0x35000000);
729 SDR_WRITE(SDRN_PESDR_HSSL3SET1(port), 0x35000000);
731 SDR_WRITE(PESDR0_HSSL4SET1, 0x35000000);
732 SDR_WRITE(PESDR0_HSSL5SET1, 0x35000000);
733 SDR_WRITE(PESDR0_HSSL6SET1, 0x35000000);
734 SDR_WRITE(PESDR0_HSSL7SET1, 0x35000000);
736 SDR_WRITE(SDRN_PESDR_RCSSET(port), (SDR_READ(SDRN_PESDR_RCSSET(port)) &
737 ~(1 << 24 | 1 << 16)) | 1 << 12);
741 #endif /* CONFIG_440SPE */
743 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
744 int __ppc4xx_init_pcie_port_hw(int port, int rootport)
750 val = PTYPE_ROOT_PORT << 20;
752 val = PTYPE_LEGACY_ENDPOINT << 20;
755 val |= LNKW_X1 << 12;
756 utlset1 = 0x20000000;
758 val |= LNKW_X4 << 12;
759 utlset1 = 0x20101101;
762 SDR_WRITE(SDRN_PESDR_DLPSET(port), val);
763 SDR_WRITE(SDRN_PESDR_UTLSET1(port), utlset1);
764 SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x01210000);
768 SDR_WRITE(PESDR0_L0CDRCTL, 0x00003230);
769 SDR_WRITE(PESDR0_L0DRV, 0x00000130);
770 SDR_WRITE(PESDR0_L0CLK, 0x00000006);
772 SDR_WRITE(PESDR0_PHY_CTL_RST,0x10000000);
776 SDR_WRITE(PESDR1_L0CDRCTL, 0x00003230);
777 SDR_WRITE(PESDR1_L1CDRCTL, 0x00003230);
778 SDR_WRITE(PESDR1_L2CDRCTL, 0x00003230);
779 SDR_WRITE(PESDR1_L3CDRCTL, 0x00003230);
780 SDR_WRITE(PESDR1_L0DRV, 0x00000130);
781 SDR_WRITE(PESDR1_L1DRV, 0x00000130);
782 SDR_WRITE(PESDR1_L2DRV, 0x00000130);
783 SDR_WRITE(PESDR1_L3DRV, 0x00000130);
784 SDR_WRITE(PESDR1_L0CLK, 0x00000006);
785 SDR_WRITE(PESDR1_L1CLK, 0x00000006);
786 SDR_WRITE(PESDR1_L2CLK, 0x00000006);
787 SDR_WRITE(PESDR1_L3CLK, 0x00000006);
789 SDR_WRITE(PESDR1_PHY_CTL_RST,0x10000000);
793 SDR_WRITE(SDRN_PESDR_RCSSET(port), SDR_READ(SDRN_PESDR_RCSSET(port)) |
794 (PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTPYN));
796 /* Poll for PHY reset */
799 while (!(SDR_READ(PESDR0_RSTSTA) & 0x1))
803 while (!(SDR_READ(PESDR1_RSTSTA) & 0x1))
808 SDR_WRITE(SDRN_PESDR_RCSSET(port),
809 (SDR_READ(SDRN_PESDR_RCSSET(port)) &
810 ~(PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTDL)) |
811 PESDRx_RCSSET_RSTPYN);
815 #endif /* CONFIG_440SPE */
817 #if defined(CONFIG_405EX)
818 int __ppc4xx_init_pcie_port_hw(int port, int rootport)
827 SDR_WRITE(SDRN_PESDR_DLPSET(port), val);
828 SDR_WRITE(SDRN_PESDR_UTLSET1(port), 0x00000000);
829 SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x01010000);
830 SDR_WRITE(SDRN_PESDR_PHYSET1(port), 0x720F0000);
831 SDR_WRITE(SDRN_PESDR_PHYSET2(port), 0x70600003);
833 /* Assert the PE0_PHY reset */
834 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01010000);
837 /* deassert the PE0_hotreset */
838 if (is_end_point(port))
839 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01111000);
841 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01101000);
843 /* poll for phy !reset */
844 while (!(SDR_READ(SDRN_PESDR_PHYSTA(port)) & 0x00001000))
847 /* deassert the PE0_gpl_utl_reset */
848 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x00101000);
851 mtdcr(DCRN_PEGPL_CFG(PCIE0), 0x10000000); /* guarded on */
853 mtdcr(DCRN_PEGPL_CFG(PCIE1), 0x10000000); /* guarded on */
857 #endif /* CONFIG_405EX */
859 int ppc4xx_init_pcie_port_hw(int port, int rootport)
860 __attribute__((weak, alias("__ppc4xx_init_pcie_port_hw")));
863 * We map PCI Express configuration access into the 512MB regions
865 * NOTICE: revB is very strict about PLB real addressess and ranges to
866 * be mapped for config space; it seems to only work with d_nnnn_nnnn
867 * range (hangs the core upon config transaction attempts when set
868 * otherwise) while revA uses c_nnnn_nnnn.
871 * PCIE0: 0xc_4000_0000
872 * PCIE1: 0xc_8000_0000
873 * PCIE2: 0xc_c000_0000
876 * PCIE0: 0xd_0000_0000
877 * PCIE1: 0xd_2000_0000
878 * PCIE2: 0xd_4000_0000
885 * PCIE0: 0xd_0000_0000
886 * PCIE1: 0xd_2000_0000
888 static inline u64 ppc4xx_get_cfgaddr(int port)
890 #if defined(CONFIG_405EX)
892 return (u64)CONFIG_SYS_PCIE0_CFGBASE;
894 return (u64)CONFIG_SYS_PCIE1_CFGBASE;
896 #if defined(CONFIG_440SPE)
897 if (ppc440spe_revB()) {
899 default: /* to satisfy compiler */
901 return 0x0000000d00000000ULL;
903 return 0x0000000d20000000ULL;
905 return 0x0000000d40000000ULL;
909 default: /* to satisfy compiler */
911 return 0x0000000c40000000ULL;
913 return 0x0000000c80000000ULL;
915 return 0x0000000cc0000000ULL;
919 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
921 return 0x0000000d00000000ULL;
923 return 0x0000000d20000000ULL;
928 * 4xx boards as endpoint and root point setup
930 * testing inbound and out bound windows
932 * 4xx boards can be plugged into another 4xx boards or you can get PCI-E
933 * cable which can be used to setup loop back from one port to another port.
934 * Please rememeber that unless there is a endpoint plugged in to root port it
935 * will not initialize. It is the same in case of endpoint , unless there is
936 * root port attached it will not initialize.
938 * In this release of software all the PCI-E ports are configured as either
939 * endpoint or rootpoint.In future we will have support for selective ports
940 * setup as endpoint and root point in single board.
942 * Once your board came up as root point , you can verify by reading
943 * /proc/bus/pci/devices. Where you can see the configuration registers
944 * of endpoint device attached to the port.
946 * Enpoint cofiguration can be verified by connecting 4xx board to any
947 * host or another 4xx board. Then try to scan the device. In case of
948 * linux use "lspci" or appripriate os command.
950 * How do I verify the inbound and out bound windows ? (4xx to 4xx)
951 * in this configuration inbound and outbound windows are setup to access
952 * sram memroy area. SRAM is at 0x4 0000 0000 , on PLB bus. This address
953 * is mapped at 0x90000000. From u-boot prompt write data 0xb000 0000,
954 * This is waere your POM(PLB out bound memory window) mapped. then
955 * read the data from other 4xx board's u-boot prompt at address
956 * 0x9000 0000(SRAM). Data should match.
957 * In case of inbound , write data to u-boot command prompt at 0xb000 0000
958 * which is mapped to 0x4 0000 0000. Now on rootpoint yucca u-boot prompt check
959 * data at 0x9000 0000(SRAM).Data should match.
961 int ppc4xx_init_pcie_port(int port, int rootport)
963 static int core_init;
964 volatile u32 val = 0;
970 if (ppc4xx_init_pcie())
976 * Initialize various parts of the PCI Express core for our port
978 ppc4xx_init_pcie_port_hw(port, rootport);
981 * Notice: the following delay has critical impact on device
982 * initialization - if too short (<50ms) the link doesn't get up.
986 val = SDR_READ(SDRN_PESDR_RCSSTS(port));
987 if (val & (1 << 20)) {
988 printf("PCIE%d: PGRST failed %08x\n", port, val);
995 val = SDR_READ(SDRN_PESDR_LOOP(port));
996 if (!(val & 0x00001000)) {
997 printf("PCIE%d: link is not up.\n", port);
1002 * Setup UTL registers - but only on revA!
1003 * We use default settings for revB chip.
1005 if (!ppc440spe_revB())
1006 ppc4xx_setup_utl(port);
1009 * We map PCI Express configuration access into the 512MB regions
1011 addr = ppc4xx_get_cfgaddr(port);
1012 low = U64_TO_U32_LOW(addr);
1013 high = U64_TO_U32_HIGH(addr);
1017 mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), high);
1018 mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), low);
1019 mtdcr(DCRN_PEGPL_CFGMSK(PCIE0), 0xe0000001); /* 512MB region, valid */
1022 mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), high);
1023 mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), low);
1024 mtdcr(DCRN_PEGPL_CFGMSK(PCIE1), 0xe0000001); /* 512MB region, valid */
1026 #if CONFIG_SYS_PCIE_NR_PORTS > 2
1028 mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), high);
1029 mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), low);
1030 mtdcr(DCRN_PEGPL_CFGMSK(PCIE2), 0xe0000001); /* 512MB region, valid */
1036 * Check for VC0 active and assert RDY.
1039 while(!(SDR_READ(SDRN_PESDR_RCSSTS(port)) & (1 << 16))) {
1040 if (!(attempts--)) {
1041 printf("PCIE%d: VC0 not active\n", port);
1046 SDR_WRITE(SDRN_PESDR_RCSSET(port),
1047 SDR_READ(SDRN_PESDR_RCSSET(port)) | 1 << 20);
1053 int ppc4xx_init_pcie_rootport(int port)
1055 return ppc4xx_init_pcie_port(port, 1);
1058 int ppc4xx_init_pcie_endport(int port)
1060 return ppc4xx_init_pcie_port(port, 0);
1063 void ppc4xx_setup_pcie_rootpoint(struct pci_controller *hose, int port)
1065 volatile void *mbase = NULL;
1066 volatile void *rmbase = NULL;
1069 pcie_read_config_byte,
1070 pcie_read_config_word,
1071 pcie_read_config_dword,
1072 pcie_write_config_byte,
1073 pcie_write_config_word,
1074 pcie_write_config_dword);
1078 mbase = (u32 *)CONFIG_SYS_PCIE0_XCFGBASE;
1079 rmbase = (u32 *)CONFIG_SYS_PCIE0_CFGBASE;
1080 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE0_CFGBASE;
1083 mbase = (u32 *)CONFIG_SYS_PCIE1_XCFGBASE;
1084 rmbase = (u32 *)CONFIG_SYS_PCIE1_CFGBASE;
1085 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE1_CFGBASE;
1087 #if CONFIG_SYS_PCIE_NR_PORTS > 2
1089 mbase = (u32 *)CONFIG_SYS_PCIE2_XCFGBASE;
1090 rmbase = (u32 *)CONFIG_SYS_PCIE2_CFGBASE;
1091 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE2_CFGBASE;
1097 * Set bus numbers on our root port
1099 out_8((u8 *)mbase + PCI_PRIMARY_BUS, 0);
1100 out_8((u8 *)mbase + PCI_SECONDARY_BUS, 1);
1101 out_8((u8 *)mbase + PCI_SUBORDINATE_BUS, 1);
1104 * Set up outbound translation to hose->mem_space from PLB
1105 * addresses at an offset of 0xd_0000_0000. We set the low
1106 * bits of the mask to 11 to turn off splitting into 8
1107 * subregions and to enable the outbound translation.
1109 out_le32(mbase + PECFG_POM0LAH, 0x00000000);
1110 out_le32(mbase + PECFG_POM0LAL, CONFIG_SYS_PCIE_MEMBASE +
1111 port * CONFIG_SYS_PCIE_MEMSIZE);
1112 debug("PECFG_POM0LA=%08x.%08x\n", in_le32(mbase + PECFG_POM0LAH),
1113 in_le32(mbase + PECFG_POM0LAL));
1117 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), CONFIG_SYS_PCIE_ADDR_HIGH);
1118 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CONFIG_SYS_PCIE_MEMBASE +
1119 port * CONFIG_SYS_PCIE_MEMSIZE);
1120 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
1121 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
1122 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
1123 debug("0:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n",
1124 mfdcr(DCRN_PEGPL_OMR1BAH(PCIE0)),
1125 mfdcr(DCRN_PEGPL_OMR1BAL(PCIE0)),
1126 mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE0)),
1127 mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE0)));
1130 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), CONFIG_SYS_PCIE_ADDR_HIGH);
1131 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), CONFIG_SYS_PCIE_MEMBASE +
1132 port * CONFIG_SYS_PCIE_MEMSIZE);
1133 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
1134 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
1135 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
1136 debug("1:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n",
1137 mfdcr(DCRN_PEGPL_OMR1BAH(PCIE1)),
1138 mfdcr(DCRN_PEGPL_OMR1BAL(PCIE1)),
1139 mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE1)),
1140 mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE1)));
1142 #if CONFIG_SYS_PCIE_NR_PORTS > 2
1144 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), CONFIG_SYS_PCIE_ADDR_HIGH);
1145 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), CONFIG_SYS_PCIE_MEMBASE +
1146 port * CONFIG_SYS_PCIE_MEMSIZE);
1147 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
1148 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
1149 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
1150 debug("2:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n",
1151 mfdcr(DCRN_PEGPL_OMR1BAH(PCIE2)),
1152 mfdcr(DCRN_PEGPL_OMR1BAL(PCIE2)),
1153 mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE2)),
1154 mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE2)));
1159 /* Set up 4GB inbound memory window at 0 */
1160 out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
1161 out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
1162 out_le32(mbase + PECFG_BAR0HMPA, 0x7ffffff);
1163 out_le32(mbase + PECFG_BAR0LMPA, 0);
1165 out_le32(mbase + PECFG_PIM01SAH, 0xffff0000);
1166 out_le32(mbase + PECFG_PIM01SAL, 0x00000000);
1167 out_le32(mbase + PECFG_PIM0LAL, 0);
1168 out_le32(mbase + PECFG_PIM0LAH, 0);
1169 out_le32(mbase + PECFG_PIM1LAL, 0x00000000);
1170 out_le32(mbase + PECFG_PIM1LAH, 0x00000004);
1171 out_le32(mbase + PECFG_PIMEN, 0x1);
1173 /* Enable I/O, Mem, and Busmaster cycles */
1174 out_le16((u16 *)(mbase + PCI_COMMAND),
1175 in_le16((u16 *)(mbase + PCI_COMMAND)) |
1176 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
1178 /* Set Device and Vendor Id */
1179 out_le16(mbase + 0x200, 0xaaa0 + port);
1180 out_le16(mbase + 0x202, 0xbed0 + port);
1182 /* Set Class Code to PCI-PCI bridge and Revision Id to 1 */
1183 out_le32(mbase + 0x208, 0x06040001);
1185 printf("PCIE%d: successfully set as root-complex\n", port);
1188 int ppc4xx_setup_pcie_endpoint(struct pci_controller *hose, int port)
1190 volatile void *mbase = NULL;
1194 pcie_read_config_byte,
1195 pcie_read_config_word,
1196 pcie_read_config_dword,
1197 pcie_write_config_byte,
1198 pcie_write_config_word,
1199 pcie_write_config_dword);
1203 mbase = (u32 *)CONFIG_SYS_PCIE0_XCFGBASE;
1204 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE0_CFGBASE;
1207 mbase = (u32 *)CONFIG_SYS_PCIE1_XCFGBASE;
1208 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE1_CFGBASE;
1210 #if defined(CONFIG_SYS_PCIE2_CFGBASE)
1212 mbase = (u32 *)CONFIG_SYS_PCIE2_XCFGBASE;
1213 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE2_CFGBASE;
1219 * Set up outbound translation to hose->mem_space from PLB
1220 * addresses at an offset of 0xd_0000_0000. We set the low
1221 * bits of the mask to 11 to turn off splitting into 8
1222 * subregions and to enable the outbound translation.
1224 out_le32(mbase + PECFG_POM0LAH, 0x00001ff8);
1225 out_le32(mbase + PECFG_POM0LAL, 0x00001000);
1229 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), CONFIG_SYS_PCIE_ADDR_HIGH);
1230 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CONFIG_SYS_PCIE_MEMBASE +
1231 port * CONFIG_SYS_PCIE_MEMSIZE);
1232 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
1233 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
1234 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
1237 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), CONFIG_SYS_PCIE_ADDR_HIGH);
1238 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), CONFIG_SYS_PCIE_MEMBASE +
1239 port * CONFIG_SYS_PCIE_MEMSIZE);
1240 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
1241 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
1242 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
1244 #if CONFIG_SYS_PCIE_NR_PORTS > 2
1246 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), CONFIG_SYS_PCIE_ADDR_HIGH);
1247 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), CONFIG_SYS_PCIE_MEMBASE +
1248 port * CONFIG_SYS_PCIE_MEMSIZE);
1249 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
1250 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
1251 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
1256 /* Set up 64MB inbound memory window at 0 */
1257 out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
1258 out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
1260 out_le32(mbase + PECFG_PIM01SAH, 0xffffffff);
1261 out_le32(mbase + PECFG_PIM01SAL, 0xfc000000);
1264 out_le32(mbase + PECFG_BAR0HMPA, 0x7fffffff);
1265 out_le32(mbase + PECFG_BAR0LMPA, 0xfc000000 | PCI_BASE_ADDRESS_MEM_TYPE_64);
1267 /* Disable BAR1 & BAR2 */
1268 out_le32(mbase + PECFG_BAR1MPA, 0);
1269 out_le32(mbase + PECFG_BAR2HMPA, 0);
1270 out_le32(mbase + PECFG_BAR2LMPA, 0);
1272 out_le32(mbase + PECFG_PIM0LAL, U64_TO_U32_LOW(CONFIG_SYS_PCIE_INBOUND_BASE));
1273 out_le32(mbase + PECFG_PIM0LAH, U64_TO_U32_HIGH(CONFIG_SYS_PCIE_INBOUND_BASE));
1274 out_le32(mbase + PECFG_PIMEN, 0x1);
1276 /* Enable I/O, Mem, and Busmaster cycles */
1277 out_le16((u16 *)(mbase + PCI_COMMAND),
1278 in_le16((u16 *)(mbase + PCI_COMMAND)) |
1279 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
1280 out_le16(mbase + 0x200, 0xcaad); /* Setting vendor ID */
1281 out_le16(mbase + 0x202, 0xfeed); /* Setting device ID */
1283 /* Set Class Code to Processor/PPC */
1284 out_le32(mbase + 0x208, 0x0b200001);
1287 while(!(SDR_READ(SDRN_PESDR_RCSSTS(port)) & (1 << 8))) {
1288 if (!(attempts--)) {
1289 printf("PCIE%d: BME not active\n", port);
1295 printf("PCIE%d: successfully set as endpoint\n", port);
1299 #endif /* CONFIG_440SPE && CONFIG_PCI */