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 void pcie_dmer_disable(void)
45 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE),
46 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE)) | GPL_DMER_MASK_DISA);
47 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE),
48 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE)) | GPL_DMER_MASK_DISA);
49 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE),
50 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE)) | GPL_DMER_MASK_DISA);
53 static void pcie_dmer_enable(void)
55 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE0_BASE),
56 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE)) & ~GPL_DMER_MASK_DISA);
57 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE1_BASE),
58 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE)) & ~GPL_DMER_MASK_DISA);
59 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE2_BASE),
60 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE)) & ~GPL_DMER_MASK_DISA);
64 static int pcie_read_config(struct pci_controller *hose, unsigned int devfn,
65 int offset, int len, u32 *val) {
69 * 440SPE implements only one function per port
71 if (!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 1)))
74 devfn = PCI_BDF(0,0,0);
78 * Reading from configuration space of non-existing device can
79 * generate transaction errors. For the read duration we suppress
80 * assertion of machine check exceptions to avoid those.
86 *val = in_8(hose->cfg_data + offset);
89 *val = in_le16((u16 *)(hose->cfg_data + offset));
92 *val = in_le32((u32*)(hose->cfg_data + offset));
101 static int pcie_write_config(struct pci_controller *hose, unsigned int devfn,
102 int offset, int len, u32 val) {
105 * 440SPE implements only one function per port
107 if (!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 1)))
110 devfn = PCI_BDF(0,0,0);
111 offset += devfn << 4;
114 * Suppress MCK exceptions, similar to pcie_read_config()
116 pcie_dmer_disable ();
120 out_8(hose->cfg_data + offset, val);
123 out_le16((u16 *)(hose->cfg_data + offset), val);
126 out_le32((u32 *)(hose->cfg_data + offset), val);
135 int pcie_read_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 *val)
140 rv = pcie_read_config(hose, dev, offset, 1, &v);
145 int pcie_read_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 *val)
150 rv = pcie_read_config(hose, dev, offset, 2, &v);
155 int pcie_read_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 *val)
160 rv = pcie_read_config(hose, dev, offset, 3, &v);
165 int pcie_write_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 val)
167 return pcie_write_config(hose,(u32)dev,offset,1,val);
170 int pcie_write_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 val)
172 return pcie_write_config(hose,(u32)dev,offset,2,(u32 )val);
175 int pcie_write_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 val)
177 return pcie_write_config(hose,(u32)dev,offset,3,(u32 )val);
180 static void ppc440spe_setup_utl(u32 port) {
182 volatile void *utl_base = NULL;
189 mtdcr(DCRN_PEGPL_REGBAH(PCIE0), 0x0000000c);
190 mtdcr(DCRN_PEGPL_REGBAL(PCIE0), 0x20000000);
191 mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001);
192 mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0x68782800);
196 mtdcr(DCRN_PEGPL_REGBAH(PCIE1), 0x0000000c);
197 mtdcr(DCRN_PEGPL_REGBAL(PCIE1), 0x20001000);
198 mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001);
199 mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0x68782800);
203 mtdcr(DCRN_PEGPL_REGBAH(PCIE2), 0x0000000c);
204 mtdcr(DCRN_PEGPL_REGBAL(PCIE2), 0x20002000);
205 mtdcr(DCRN_PEGPL_REGMSK(PCIE2), 0x00007001);
206 mtdcr(DCRN_PEGPL_SPECIAL(PCIE2), 0x68782800);
209 utl_base = (unsigned int *)(CFG_PCIE_BASE + 0x1000 * port);
212 * Set buffer allocations and then assert VRB and TXE.
214 out_be32(utl_base + PEUTL_OUTTR, 0x08000000);
215 out_be32(utl_base + PEUTL_INTR, 0x02000000);
216 out_be32(utl_base + PEUTL_OPDBSZ, 0x10000000);
217 out_be32(utl_base + PEUTL_PBBSZ, 0x53000000);
218 out_be32(utl_base + PEUTL_IPHBSZ, 0x08000000);
219 out_be32(utl_base + PEUTL_IPDBSZ, 0x10000000);
220 out_be32(utl_base + PEUTL_RCIRQEN, 0x00f00000);
221 out_be32(utl_base + PEUTL_PCTL, 0x80800066);
224 static int check_error(void)
226 u32 valPE0, valPE1, valPE2;
229 /* SDR0_PEGPLLLCT1 reset */
230 if (!(valPE0 = SDR_READ(PESDR0_PLLLCT1) & 0x01000000)) {
231 printf("PCIE: SDR0_PEGPLLLCT1 reset error 0x%x\n", valPE0);
234 valPE0 = SDR_READ(PESDR0_RCSSET);
235 valPE1 = SDR_READ(PESDR1_RCSSET);
236 valPE2 = SDR_READ(PESDR2_RCSSET);
238 /* SDR0_PExRCSSET rstgu */
239 if (!(valPE0 & 0x01000000) ||
240 !(valPE1 & 0x01000000) ||
241 !(valPE2 & 0x01000000)) {
242 printf("PCIE: SDR0_PExRCSSET rstgu error\n");
246 /* SDR0_PExRCSSET rstdl */
247 if (!(valPE0 & 0x00010000) ||
248 !(valPE1 & 0x00010000) ||
249 !(valPE2 & 0x00010000)) {
250 printf("PCIE: SDR0_PExRCSSET rstdl error\n");
254 /* SDR0_PExRCSSET rstpyn */
255 if ((valPE0 & 0x00001000) ||
256 (valPE1 & 0x00001000) ||
257 (valPE2 & 0x00001000)) {
258 printf("PCIE: SDR0_PExRCSSET rstpyn error\n");
262 /* SDR0_PExRCSSET hldplb */
263 if ((valPE0 & 0x10000000) ||
264 (valPE1 & 0x10000000) ||
265 (valPE2 & 0x10000000)) {
266 printf("PCIE: SDR0_PExRCSSET hldplb error\n");
270 /* SDR0_PExRCSSET rdy */
271 if ((valPE0 & 0x00100000) ||
272 (valPE1 & 0x00100000) ||
273 (valPE2 & 0x00100000)) {
274 printf("PCIE: SDR0_PExRCSSET rdy error\n");
278 /* SDR0_PExRCSSET shutdown */
279 if ((valPE0 & 0x00000100) ||
280 (valPE1 & 0x00000100) ||
281 (valPE2 & 0x00000100)) {
282 printf("PCIE: SDR0_PExRCSSET shutdown error\n");
289 * Initialize PCI Express core
291 int ppc440spe_init_pcie(void)
295 /* Set PLL clock receiver to LVPECL */
296 SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) | 1 << 28);
301 if (!(SDR_READ(PESDR0_PLLLCT2) & 0x10000))
303 printf("PCIE: PESDR_PLLCT2 resistance calibration failed (0x%08x)\n",
304 SDR_READ(PESDR0_PLLLCT2));
307 /* De-assert reset of PCIe PLL, wait for lock */
308 SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) & ~(1 << 24));
312 if (!(SDR_READ(PESDR0_PLLLCT3) & 0x10000000)) {
319 printf("PCIE: VCO output not locked\n");
326 * Yucca board as End point and root point setup
328 * testing inbound and out bound windows
330 * YUCCA board can be plugged into another yucca board or you can get PCI-E
331 * cable which can be used to setup loop back from one port to another port.
332 * Please rememeber that unless there is a endpoint plugged in to root port it
333 * will not initialize. It is the same in case of endpoint , unless there is
334 * root port attached it will not initialize.
336 * In this release of software all the PCI-E ports are configured as either
337 * endpoint or rootpoint.In future we will have support for selective ports
338 * setup as endpoint and root point in single board.
340 * Once your board came up as root point , you can verify by reading
341 * /proc/bus/pci/devices. Where you can see the configuration registers
342 * of end point device attached to the port.
344 * Enpoint cofiguration can be verified by connecting Yucca board to any
345 * host or another yucca board. Then try to scan the device. In case of
346 * linux use "lspci" or appripriate os command.
348 * How do I verify the inbound and out bound windows ?(yucca to yucca)
349 * in this configuration inbound and outbound windows are setup to access
350 * sram memroy area. SRAM is at 0x4 0000 0000 , on PLB bus. This address
351 * is mapped at 0x90000000. From u-boot prompt write data 0xb000 0000,
352 * This is waere your POM(PLB out bound memory window) mapped. then
353 * read the data from other yucca board's u-boot prompt at address
354 * 0x9000 0000(SRAM). Data should match.
355 * In case of inbound , write data to u-boot command prompt at 0xb000 0000
356 * which is mapped to 0x4 0000 0000. Now on rootpoint yucca u-boot prompt check
357 * data at 0x9000 0000(SRAM).Data should match.
359 int ppc440spe_init_pcie_rootport(int port)
361 static int core_init;
362 volatile u32 val = 0;
367 if (ppc440spe_init_pcie())
372 * Initialize various parts of the PCI Express core for our port:
374 * - Set as a root port and enable max width
375 * (PXIE0 -> X8, PCIE1 and PCIE2 -> X4).
376 * - Set up UTL configuration.
377 * - Increase SERDES drive strength to levels suggested by AMCC.
378 * - De-assert RSTPYN, RSTDL and RSTGU.
380 * NOTICE for revB chip: PESDRn_UTLSET2 is not set - we leave it with
381 * default setting 0x11310000. The register has new fields,
382 * PESDRn_UTLSET2[LKINE] in particular: clearing it leads to PCIE core
387 SDR_WRITE(PESDR0_DLPSET, 1 << 24 | PTYPE_ROOT_PORT << 20 | LNKW_X8 << 12);
389 SDR_WRITE(PESDR0_UTLSET1, 0x21222222);
390 if (!ppc440spe_revB())
391 SDR_WRITE(PESDR0_UTLSET2, 0x11000000);
392 SDR_WRITE(PESDR0_HSSL0SET1, 0x35000000);
393 SDR_WRITE(PESDR0_HSSL1SET1, 0x35000000);
394 SDR_WRITE(PESDR0_HSSL2SET1, 0x35000000);
395 SDR_WRITE(PESDR0_HSSL3SET1, 0x35000000);
396 SDR_WRITE(PESDR0_HSSL4SET1, 0x35000000);
397 SDR_WRITE(PESDR0_HSSL5SET1, 0x35000000);
398 SDR_WRITE(PESDR0_HSSL6SET1, 0x35000000);
399 SDR_WRITE(PESDR0_HSSL7SET1, 0x35000000);
400 SDR_WRITE(PESDR0_RCSSET,
401 (SDR_READ(PESDR0_RCSSET) & ~(1 << 24 | 1 << 16)) | 1 << 12);
405 SDR_WRITE(PESDR1_DLPSET, 1 << 24 | PTYPE_ROOT_PORT << 20 | LNKW_X4 << 12);
406 SDR_WRITE(PESDR1_UTLSET1, 0x21222222);
407 if (!ppc440spe_revB())
408 SDR_WRITE(PESDR1_UTLSET2, 0x11000000);
409 SDR_WRITE(PESDR1_HSSL0SET1, 0x35000000);
410 SDR_WRITE(PESDR1_HSSL1SET1, 0x35000000);
411 SDR_WRITE(PESDR1_HSSL2SET1, 0x35000000);
412 SDR_WRITE(PESDR1_HSSL3SET1, 0x35000000);
413 SDR_WRITE(PESDR1_RCSSET,
414 (SDR_READ(PESDR1_RCSSET) & ~(1 << 24 | 1 << 16)) | 1 << 12);
418 SDR_WRITE(PESDR2_DLPSET, 1 << 24 | PTYPE_ROOT_PORT << 20 | LNKW_X4 << 12);
419 SDR_WRITE(PESDR2_UTLSET1, 0x21222222);
420 if (!ppc440spe_revB())
421 SDR_WRITE(PESDR2_UTLSET2, 0x11000000);
422 SDR_WRITE(PESDR2_HSSL0SET1, 0x35000000);
423 SDR_WRITE(PESDR2_HSSL1SET1, 0x35000000);
424 SDR_WRITE(PESDR2_HSSL2SET1, 0x35000000);
425 SDR_WRITE(PESDR2_HSSL3SET1, 0x35000000);
426 SDR_WRITE(PESDR2_RCSSET,
427 (SDR_READ(PESDR2_RCSSET) & ~(1 << 24 | 1 << 16)) | 1 << 12);
431 * Notice: the following delay has critical impact on device
432 * initialization - if too short (<50ms) the link doesn't get up.
438 val = SDR_READ(PESDR0_RCSSTS);
441 val = SDR_READ(PESDR1_RCSSTS);
444 val = SDR_READ(PESDR2_RCSSTS);
448 if (val & (1 << 20)) {
449 printf("PCIE%d: PGRST failed %08x\n", port, val);
459 val = SDR_READ(PESDR0_LOOP);
462 val = SDR_READ(PESDR1_LOOP);
465 val = SDR_READ(PESDR2_LOOP);
468 if (!(val & 0x00001000)) {
469 printf("PCIE%d: link is not up.\n", port);
474 * Setup UTL registers - but only on revA!
475 * We use default settings for revB chip.
477 if (!ppc440spe_revB())
478 ppc440spe_setup_utl(port);
481 * We map PCI Express configuration access into the 512MB regions
483 * NOTICE: revB is very strict about PLB real addressess and ranges to
484 * be mapped for config space; it seems to only work with d_nnnn_nnnn
485 * range (hangs the core upon config transaction attempts when set
486 * otherwise) while revA uses c_nnnn_nnnn.
489 * PCIE0: 0xc_4000_0000
490 * PCIE1: 0xc_8000_0000
491 * PCIE2: 0xc_c000_0000
494 * PCIE0: 0xd_0000_0000
495 * PCIE1: 0xd_2000_0000
496 * PCIE2: 0xd_4000_0000
501 if (ppc440spe_revB()) {
502 mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), 0x0000000d);
503 mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), 0x00000000);
506 mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), 0x0000000c);
507 mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), 0x40000000);
509 mtdcr(DCRN_PEGPL_CFGMSK(PCIE0), 0xe0000001); /* 512MB region, valid */
513 if (ppc440spe_revB()) {
514 mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), 0x0000000d);
515 mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), 0x20000000);
517 mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), 0x0000000c);
518 mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), 0x80000000);
520 mtdcr(DCRN_PEGPL_CFGMSK(PCIE1), 0xe0000001); /* 512MB region, valid */
524 if (ppc440spe_revB()) {
525 mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), 0x0000000d);
526 mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), 0x40000000);
528 mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), 0x0000000c);
529 mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), 0xc0000000);
531 mtdcr(DCRN_PEGPL_CFGMSK(PCIE2), 0xe0000001); /* 512MB region, valid */
536 * Check for VC0 active and assert RDY.
541 while(!(SDR_READ(PESDR0_RCSSTS) & (1 << 16))) {
543 printf("PCIE0: VC0 not active\n");
548 SDR_WRITE(PESDR0_RCSSET, SDR_READ(PESDR0_RCSSET) | 1 << 20);
551 while(!(SDR_READ(PESDR1_RCSSTS) & (1 << 16))) {
553 printf("PCIE1: VC0 not active\n");
559 SDR_WRITE(PESDR1_RCSSET, SDR_READ(PESDR1_RCSSET) | 1 << 20);
562 while(!(SDR_READ(PESDR2_RCSSTS) & (1 << 16))) {
564 printf("PCIE2: VC0 not active\n");
570 SDR_WRITE(PESDR2_RCSSET, SDR_READ(PESDR2_RCSSET) | 1 << 20);
578 int ppc440spe_init_pcie_endport(int port)
580 static int core_init;
581 volatile u32 val = 0;
586 if (ppc440spe_init_pcie())
591 * Initialize various parts of the PCI Express core for our port:
593 * - Set as a end port and enable max width
594 * (PXIE0 -> X8, PCIE1 and PCIE2 -> X4).
595 * - Set up UTL configuration.
596 * - Increase SERDES drive strength to levels suggested by AMCC.
597 * - De-assert RSTPYN, RSTDL and RSTGU.
599 * NOTICE for revB chip: PESDRn_UTLSET2 is not set - we leave it with
600 * default setting 0x11310000. The register has new fields,
601 * PESDRn_UTLSET2[LKINE] in particular: clearing it leads to PCIE core
606 SDR_WRITE(PESDR0_DLPSET, 1 << 24 | PTYPE_LEGACY_ENDPOINT << 20 | LNKW_X8 << 12);
608 SDR_WRITE(PESDR0_UTLSET1, 0x20222222);
609 if (!ppc440spe_revB())
610 SDR_WRITE(PESDR0_UTLSET2, 0x11000000);
611 SDR_WRITE(PESDR0_HSSL0SET1, 0x35000000);
612 SDR_WRITE(PESDR0_HSSL1SET1, 0x35000000);
613 SDR_WRITE(PESDR0_HSSL2SET1, 0x35000000);
614 SDR_WRITE(PESDR0_HSSL3SET1, 0x35000000);
615 SDR_WRITE(PESDR0_HSSL4SET1, 0x35000000);
616 SDR_WRITE(PESDR0_HSSL5SET1, 0x35000000);
617 SDR_WRITE(PESDR0_HSSL6SET1, 0x35000000);
618 SDR_WRITE(PESDR0_HSSL7SET1, 0x35000000);
619 SDR_WRITE(PESDR0_RCSSET,
620 (SDR_READ(PESDR0_RCSSET) & ~(1 << 24 | 1 << 16)) | 1 << 12);
624 SDR_WRITE(PESDR1_DLPSET, 1 << 24 | PTYPE_LEGACY_ENDPOINT << 20 | LNKW_X4 << 12);
625 SDR_WRITE(PESDR1_UTLSET1, 0x20222222);
626 if (!ppc440spe_revB())
627 SDR_WRITE(PESDR1_UTLSET2, 0x11000000);
628 SDR_WRITE(PESDR1_HSSL0SET1, 0x35000000);
629 SDR_WRITE(PESDR1_HSSL1SET1, 0x35000000);
630 SDR_WRITE(PESDR1_HSSL2SET1, 0x35000000);
631 SDR_WRITE(PESDR1_HSSL3SET1, 0x35000000);
632 SDR_WRITE(PESDR1_RCSSET,
633 (SDR_READ(PESDR1_RCSSET) & ~(1 << 24 | 1 << 16)) | 1 << 12);
637 SDR_WRITE(PESDR2_DLPSET, 1 << 24 | PTYPE_LEGACY_ENDPOINT << 20 | LNKW_X4 << 12);
638 SDR_WRITE(PESDR2_UTLSET1, 0x20222222);
639 if (!ppc440spe_revB())
640 SDR_WRITE(PESDR2_UTLSET2, 0x11000000);
641 SDR_WRITE(PESDR2_HSSL0SET1, 0x35000000);
642 SDR_WRITE(PESDR2_HSSL1SET1, 0x35000000);
643 SDR_WRITE(PESDR2_HSSL2SET1, 0x35000000);
644 SDR_WRITE(PESDR2_HSSL3SET1, 0x35000000);
645 SDR_WRITE(PESDR2_RCSSET,
646 (SDR_READ(PESDR2_RCSSET) & ~(1 << 24 | 1 << 16)) | 1 << 12);
650 * Notice: the following delay has critical impact on device
651 * initialization - if too short (<50ms) the link doesn't get up.
656 case 0: val = SDR_READ(PESDR0_RCSSTS); break;
657 case 1: val = SDR_READ(PESDR1_RCSSTS); break;
658 case 2: val = SDR_READ(PESDR2_RCSSTS); break;
661 if (val & (1 << 20)) {
662 printf("PCIE%d: PGRST failed %08x\n", port, val);
673 val = SDR_READ(PESDR0_LOOP);
676 val = SDR_READ(PESDR1_LOOP);
679 val = SDR_READ(PESDR2_LOOP);
682 if (!(val & 0x00001000)) {
683 printf("PCIE%d: link is not up.\n", port);
688 * Setup UTL registers - but only on revA!
689 * We use default settings for revB chip.
691 if (!ppc440spe_revB())
692 ppc440spe_setup_utl(port);
695 * We map PCI Express configuration access into the 512MB regions
697 * NOTICE: revB is very strict about PLB real addressess and ranges to
698 * be mapped for config space; it seems to only work with d_nnnn_nnnn
699 * range (hangs the core upon config transaction attempts when set
700 * otherwise) while revA uses c_nnnn_nnnn.
703 * PCIE0: 0xc_4000_0000
704 * PCIE1: 0xc_8000_0000
705 * PCIE2: 0xc_c000_0000
708 * PCIE0: 0xd_0000_0000
709 * PCIE1: 0xd_2000_0000
710 * PCIE2: 0xd_4000_0000
714 if (ppc440spe_revB()) {
715 mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), 0x0000000d);
716 mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), 0x00000000);
719 mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), 0x0000000c);
720 mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), 0x40000000);
722 mtdcr(DCRN_PEGPL_CFGMSK(PCIE0), 0xe0000001); /* 512MB region, valid */
726 if (ppc440spe_revB()) {
727 mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), 0x0000000d);
728 mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), 0x20000000);
730 mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), 0x0000000c);
731 mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), 0x80000000);
733 mtdcr(DCRN_PEGPL_CFGMSK(PCIE1), 0xe0000001); /* 512MB region, valid */
737 if (ppc440spe_revB()) {
738 mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), 0x0000000d);
739 mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), 0x40000000);
741 mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), 0x0000000c);
742 mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), 0xc0000000);
744 mtdcr(DCRN_PEGPL_CFGMSK(PCIE2), 0xe0000001); /* 512MB region, valid */
749 * Check for VC0 active and assert RDY.
754 while(!(SDR_READ(PESDR0_RCSSTS) & (1 << 16))) {
756 printf("PCIE0: VC0 not active\n");
761 SDR_WRITE(PESDR0_RCSSET, SDR_READ(PESDR0_RCSSET) | 1 << 20);
764 while(!(SDR_READ(PESDR1_RCSSTS) & (1 << 16))) {
766 printf("PCIE1: VC0 not active\n");
772 SDR_WRITE(PESDR1_RCSSET, SDR_READ(PESDR1_RCSSET) | 1 << 20);
775 while(!(SDR_READ(PESDR2_RCSSTS) & (1 << 16))) {
777 printf("PCIE2: VC0 not active\n");
783 SDR_WRITE(PESDR2_RCSSET, SDR_READ(PESDR2_RCSSET) | 1 << 20);
791 void ppc440spe_setup_pcie_rootpoint(struct pci_controller *hose, int port)
793 volatile void *mbase = NULL;
794 volatile void *rmbase = NULL;
797 pcie_read_config_byte,
798 pcie_read_config_word,
799 pcie_read_config_dword,
800 pcie_write_config_byte,
801 pcie_write_config_word,
802 pcie_write_config_dword);
806 mbase = (u32 *)CFG_PCIE0_XCFGBASE;
807 rmbase = (u32 *)CFG_PCIE0_CFGBASE;
808 hose->cfg_data = (u8 *)CFG_PCIE0_CFGBASE;
811 mbase = (u32 *)CFG_PCIE1_XCFGBASE;
812 rmbase = (u32 *)CFG_PCIE1_CFGBASE;
813 hose->cfg_data = (u8 *)CFG_PCIE1_CFGBASE;
816 mbase = (u32 *)CFG_PCIE2_XCFGBASE;
817 rmbase = (u32 *)CFG_PCIE2_CFGBASE;
818 hose->cfg_data = (u8 *)CFG_PCIE2_CFGBASE;
823 * Set bus numbers on our root port
825 if (ppc440spe_revB()) {
826 out_8((u8 *)mbase + PCI_PRIMARY_BUS, 0);
827 out_8((u8 *)mbase + PCI_SECONDARY_BUS, 1);
828 out_8((u8 *)mbase + PCI_SUBORDINATE_BUS, 1);
830 out_8((u8 *)mbase + PCI_PRIMARY_BUS, 0);
831 out_8((u8 *)mbase + PCI_SECONDARY_BUS, 0);
835 * Set up outbound translation to hose->mem_space from PLB
836 * addresses at an offset of 0xd_0000_0000. We set the low
837 * bits of the mask to 11 to turn off splitting into 8
838 * subregions and to enable the outbound translation.
840 out_le32(mbase + PECFG_POM0LAH, 0x00000000);
841 out_le32(mbase + PECFG_POM0LAL, 0x00000000);
845 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), 0x0000000d);
846 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CFG_PCIE_MEMBASE +
847 port * CFG_PCIE_MEMSIZE);
848 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
849 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
850 ~(CFG_PCIE_MEMSIZE - 1) | 3);
853 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), 0x0000000d);
854 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), (CFG_PCIE_MEMBASE +
855 port * CFG_PCIE_MEMSIZE));
856 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
857 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
858 ~(CFG_PCIE_MEMSIZE - 1) | 3);
861 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), 0x0000000d);
862 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), (CFG_PCIE_MEMBASE +
863 port * CFG_PCIE_MEMSIZE));
864 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
865 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
866 ~(CFG_PCIE_MEMSIZE - 1) | 3);
870 /* Set up 16GB inbound memory window at 0 */
871 out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
872 out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
873 out_le32(mbase + PECFG_BAR0HMPA, 0x7fffffc);
874 out_le32(mbase + PECFG_BAR0LMPA, 0);
876 out_le32(mbase + PECFG_PIM01SAH, 0xffff0000);
877 out_le32(mbase + PECFG_PIM01SAL, 0x00000000);
878 out_le32(mbase + PECFG_PIM0LAL, 0);
879 out_le32(mbase + PECFG_PIM0LAH, 0);
880 out_le32(mbase + PECFG_PIM1LAL, 0x00000000);
881 out_le32(mbase + PECFG_PIM1LAH, 0x00000004);
882 out_le32(mbase + PECFG_PIMEN, 0x1);
884 /* Enable I/O, Mem, and Busmaster cycles */
885 out_le16((u16 *)(mbase + PCI_COMMAND),
886 in_le16((u16 *)(mbase + PCI_COMMAND)) |
887 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
888 printf("PCIE:%d successfully set as rootpoint\n",port);
891 int ppc440spe_setup_pcie_endpoint(struct pci_controller *hose, int port)
893 volatile void *mbase = NULL;
897 pcie_read_config_byte,
898 pcie_read_config_word,
899 pcie_read_config_dword,
900 pcie_write_config_byte,
901 pcie_write_config_word,
902 pcie_write_config_dword);
906 mbase = (u32 *)CFG_PCIE0_XCFGBASE;
907 hose->cfg_data = (u8 *)CFG_PCIE0_CFGBASE;
910 mbase = (u32 *)CFG_PCIE1_XCFGBASE;
911 hose->cfg_data = (u8 *)CFG_PCIE1_CFGBASE;
914 mbase = (u32 *)CFG_PCIE2_XCFGBASE;
915 hose->cfg_data = (u8 *)CFG_PCIE2_CFGBASE;
920 * Set up outbound translation to hose->mem_space from PLB
921 * addresses at an offset of 0xd_0000_0000. We set the low
922 * bits of the mask to 11 to turn off splitting into 8
923 * subregions and to enable the outbound translation.
925 out_le32(mbase + PECFG_POM0LAH, 0x00001ff8);
926 out_le32(mbase + PECFG_POM0LAL, 0x00001000);
930 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), 0x0000000d);
931 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CFG_PCIE_MEMBASE +
932 port * CFG_PCIE_MEMSIZE);
933 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
934 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
935 ~(CFG_PCIE_MEMSIZE - 1) | 3);
938 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), 0x0000000d);
939 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), (CFG_PCIE_MEMBASE +
940 port * CFG_PCIE_MEMSIZE));
941 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
942 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
943 ~(CFG_PCIE_MEMSIZE - 1) | 3);
946 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), 0x0000000d);
947 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), (CFG_PCIE_MEMBASE +
948 port * CFG_PCIE_MEMSIZE));
949 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
950 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
951 ~(CFG_PCIE_MEMSIZE - 1) | 3);
955 /* Set up 16GB inbound memory window at 0 */
956 out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
957 out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
958 out_le32(mbase + PECFG_BAR0HMPA, 0x7fffffc);
959 out_le32(mbase + PECFG_BAR0LMPA, 0);
960 out_le32(mbase + PECFG_PIM0LAL, 0x00000000);
961 out_le32(mbase + PECFG_PIM0LAH, 0x00000004); /* pointing to SRAM */
962 out_le32(mbase + PECFG_PIMEN, 0x1);
964 /* Enable I/O, Mem, and Busmaster cycles */
965 out_le16((u16 *)(mbase + PCI_COMMAND),
966 in_le16((u16 *)(mbase + PCI_COMMAND)) |
967 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
968 out_le16(mbase + 0x200,0xcaad); /* Setting vendor ID */
969 out_le16(mbase + 0x202,0xfeed); /* Setting device ID */
973 while (!(SDR_READ(PESDR0_RCSSTS) & (1 << 8))) {
975 printf("PCIE0: BMEN is not active\n");
982 while (!(SDR_READ(PESDR1_RCSSTS) & (1 << 8))) {
984 printf("PCIE1: BMEN is not active\n");
991 while (!(SDR_READ(PESDR2_RCSSTS) & (1 << 8))) {
993 printf("PCIE2: BMEN is not active\n");
1000 printf("PCIE:%d successfully set as endpoint\n",port);
1004 #endif /* CONFIG_440SPE && CONFIG_PCI */