193a686eeSJean-Christophe PLAGNIOL-VILLARD /* 293a686eeSJean-Christophe PLAGNIOL-VILLARD * Copyright 2007 Freescale Semiconductor, Inc. 393a686eeSJean-Christophe PLAGNIOL-VILLARD * 493a686eeSJean-Christophe PLAGNIOL-VILLARD * This program is free software; you can redistribute it and/or 593a686eeSJean-Christophe PLAGNIOL-VILLARD * modify it under the terms of the GNU General Public License 693a686eeSJean-Christophe PLAGNIOL-VILLARD * Version 2 as published by the Free Software Foundation. 793a686eeSJean-Christophe PLAGNIOL-VILLARD * 893a686eeSJean-Christophe PLAGNIOL-VILLARD * This program is distributed in the hope that it will be useful, 993a686eeSJean-Christophe PLAGNIOL-VILLARD * but WITHOUT ANY WARRANTY; without even the implied warranty of 1093a686eeSJean-Christophe PLAGNIOL-VILLARD * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1193a686eeSJean-Christophe PLAGNIOL-VILLARD * GNU General Public License for more details. 1293a686eeSJean-Christophe PLAGNIOL-VILLARD * 1393a686eeSJean-Christophe PLAGNIOL-VILLARD * You should have received a copy of the GNU General Public License 1493a686eeSJean-Christophe PLAGNIOL-VILLARD * along with this program; if not, write to the Free Software 1593a686eeSJean-Christophe PLAGNIOL-VILLARD * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 1693a686eeSJean-Christophe PLAGNIOL-VILLARD * MA 02111-1307 USA 1793a686eeSJean-Christophe PLAGNIOL-VILLARD */ 1893a686eeSJean-Christophe PLAGNIOL-VILLARD 1993a686eeSJean-Christophe PLAGNIOL-VILLARD #include <common.h> 2093a686eeSJean-Christophe PLAGNIOL-VILLARD 2193a686eeSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_FSL_PCI_INIT 2293a686eeSJean-Christophe PLAGNIOL-VILLARD 2393a686eeSJean-Christophe PLAGNIOL-VILLARD /* 2493a686eeSJean-Christophe PLAGNIOL-VILLARD * PCI/PCIE Controller initialization for mpc85xx/mpc86xx soc's 2593a686eeSJean-Christophe PLAGNIOL-VILLARD * 2693a686eeSJean-Christophe PLAGNIOL-VILLARD * Initialize controller and call the common driver/pci pci_hose_scan to 2793a686eeSJean-Christophe PLAGNIOL-VILLARD * scan for bridges and devices. 2893a686eeSJean-Christophe PLAGNIOL-VILLARD * 2993a686eeSJean-Christophe PLAGNIOL-VILLARD * Hose fields which need to be pre-initialized by board specific code: 3093a686eeSJean-Christophe PLAGNIOL-VILLARD * regions[] 3193a686eeSJean-Christophe PLAGNIOL-VILLARD * first_busno 3293a686eeSJean-Christophe PLAGNIOL-VILLARD * 3393a686eeSJean-Christophe PLAGNIOL-VILLARD * Fields updated: 3493a686eeSJean-Christophe PLAGNIOL-VILLARD * last_busno 3593a686eeSJean-Christophe PLAGNIOL-VILLARD */ 3693a686eeSJean-Christophe PLAGNIOL-VILLARD 3793a686eeSJean-Christophe PLAGNIOL-VILLARD #include <pci.h> 3893a686eeSJean-Christophe PLAGNIOL-VILLARD #include <asm/immap_fsl_pci.h> 3993a686eeSJean-Christophe PLAGNIOL-VILLARD 4093a686eeSJean-Christophe PLAGNIOL-VILLARD void pciauto_prescan_setup_bridge(struct pci_controller *hose, 4193a686eeSJean-Christophe PLAGNIOL-VILLARD pci_dev_t dev, int sub_bus); 4293a686eeSJean-Christophe PLAGNIOL-VILLARD void pciauto_postscan_setup_bridge(struct pci_controller *hose, 4393a686eeSJean-Christophe PLAGNIOL-VILLARD pci_dev_t dev, int sub_bus); 4493a686eeSJean-Christophe PLAGNIOL-VILLARD 4593a686eeSJean-Christophe PLAGNIOL-VILLARD void pciauto_config_init(struct pci_controller *hose); 4693a686eeSJean-Christophe PLAGNIOL-VILLARD void 4793a686eeSJean-Christophe PLAGNIOL-VILLARD fsl_pci_init(struct pci_controller *hose) 4893a686eeSJean-Christophe PLAGNIOL-VILLARD { 4993a686eeSJean-Christophe PLAGNIOL-VILLARD u16 temp16; 5093a686eeSJean-Christophe PLAGNIOL-VILLARD u32 temp32; 5193a686eeSJean-Christophe PLAGNIOL-VILLARD int busno = hose->first_busno; 5293a686eeSJean-Christophe PLAGNIOL-VILLARD int enabled; 5393a686eeSJean-Christophe PLAGNIOL-VILLARD u16 ltssm; 5493a686eeSJean-Christophe PLAGNIOL-VILLARD u8 temp8; 5593a686eeSJean-Christophe PLAGNIOL-VILLARD int r; 5693a686eeSJean-Christophe PLAGNIOL-VILLARD int bridge; 5793a686eeSJean-Christophe PLAGNIOL-VILLARD int inbound = 0; 5893a686eeSJean-Christophe PLAGNIOL-VILLARD volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) hose->cfg_addr; 5993a686eeSJean-Christophe PLAGNIOL-VILLARD pci_dev_t dev = PCI_BDF(busno,0,0); 6093a686eeSJean-Christophe PLAGNIOL-VILLARD 6193a686eeSJean-Christophe PLAGNIOL-VILLARD /* Initialize ATMU registers based on hose regions and flags */ 6293a686eeSJean-Christophe PLAGNIOL-VILLARD volatile pot_t *po=&pci->pot[1]; /* skip 0 */ 6393a686eeSJean-Christophe PLAGNIOL-VILLARD volatile pit_t *pi=&pci->pit[0]; /* ranges from: 3 to 1 */ 6493a686eeSJean-Christophe PLAGNIOL-VILLARD 6593a686eeSJean-Christophe PLAGNIOL-VILLARD #ifdef DEBUG 6693a686eeSJean-Christophe PLAGNIOL-VILLARD int neg_link_w; 6793a686eeSJean-Christophe PLAGNIOL-VILLARD #endif 6893a686eeSJean-Christophe PLAGNIOL-VILLARD 6993a686eeSJean-Christophe PLAGNIOL-VILLARD for (r=0; r<hose->region_count; r++) { 7093a686eeSJean-Christophe PLAGNIOL-VILLARD if (hose->regions[r].flags & PCI_REGION_MEMORY) { /* inbound */ 7193a686eeSJean-Christophe PLAGNIOL-VILLARD pi->pitar = (hose->regions[r].bus_start >> 12) & 0x000fffff; 7293a686eeSJean-Christophe PLAGNIOL-VILLARD pi->piwbar = (hose->regions[r].phys_start >> 12) & 0x000fffff; 7393a686eeSJean-Christophe PLAGNIOL-VILLARD pi->piwbear = 0; 7493a686eeSJean-Christophe PLAGNIOL-VILLARD pi->piwar = PIWAR_EN | PIWAR_PF | PIWAR_LOCAL | 7593a686eeSJean-Christophe PLAGNIOL-VILLARD PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP | 7693a686eeSJean-Christophe PLAGNIOL-VILLARD (__ilog2(hose->regions[r].size) - 1); 7793a686eeSJean-Christophe PLAGNIOL-VILLARD pi++; 7893a686eeSJean-Christophe PLAGNIOL-VILLARD inbound = hose->regions[r].size > 0; 7993a686eeSJean-Christophe PLAGNIOL-VILLARD } else { /* Outbound */ 8093a686eeSJean-Christophe PLAGNIOL-VILLARD po->powbar = (hose->regions[r].phys_start >> 12) & 0x000fffff; 8193a686eeSJean-Christophe PLAGNIOL-VILLARD po->potar = (hose->regions[r].bus_start >> 12) & 0x000fffff; 8293a686eeSJean-Christophe PLAGNIOL-VILLARD po->potear = 0; 8393a686eeSJean-Christophe PLAGNIOL-VILLARD if (hose->regions[r].flags & PCI_REGION_IO) 8493a686eeSJean-Christophe PLAGNIOL-VILLARD po->powar = POWAR_EN | POWAR_IO_READ | POWAR_IO_WRITE | 8593a686eeSJean-Christophe PLAGNIOL-VILLARD (__ilog2(hose->regions[r].size) - 1); 8693a686eeSJean-Christophe PLAGNIOL-VILLARD else 8793a686eeSJean-Christophe PLAGNIOL-VILLARD po->powar = POWAR_EN | POWAR_MEM_READ | POWAR_MEM_WRITE | 8893a686eeSJean-Christophe PLAGNIOL-VILLARD (__ilog2(hose->regions[r].size) - 1); 8993a686eeSJean-Christophe PLAGNIOL-VILLARD po++; 9093a686eeSJean-Christophe PLAGNIOL-VILLARD } 9193a686eeSJean-Christophe PLAGNIOL-VILLARD } 9293a686eeSJean-Christophe PLAGNIOL-VILLARD 9393a686eeSJean-Christophe PLAGNIOL-VILLARD pci_register_hose(hose); 9493a686eeSJean-Christophe PLAGNIOL-VILLARD pciauto_config_init(hose); /* grab pci_{mem,prefetch,io} */ 9593a686eeSJean-Christophe PLAGNIOL-VILLARD hose->current_busno = hose->first_busno; 9693a686eeSJean-Christophe PLAGNIOL-VILLARD 9793a686eeSJean-Christophe PLAGNIOL-VILLARD pci->pedr = 0xffffffff; /* Clear any errors */ 9893a686eeSJean-Christophe PLAGNIOL-VILLARD pci->peer = ~0x20140; /* Enable All Error Interupts except 9993a686eeSJean-Christophe PLAGNIOL-VILLARD * - Master abort (pci) 10093a686eeSJean-Christophe PLAGNIOL-VILLARD * - Master PERR (pci) 10193a686eeSJean-Christophe PLAGNIOL-VILLARD * - ICCA (PCIe) 10293a686eeSJean-Christophe PLAGNIOL-VILLARD */ 10393a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_read_config_dword (hose, dev, PCI_DCR, &temp32); 10493a686eeSJean-Christophe PLAGNIOL-VILLARD temp32 |= 0xf000e; /* set URR, FER, NFER (but not CER) */ 10593a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_write_config_dword(hose, dev, PCI_DCR, temp32); 10693a686eeSJean-Christophe PLAGNIOL-VILLARD 10793a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_read_config_byte (hose, dev, PCI_HEADER_TYPE, &temp8); 10893a686eeSJean-Christophe PLAGNIOL-VILLARD bridge = temp8 & PCI_HEADER_TYPE_BRIDGE; /* Bridge, such as pcie */ 10993a686eeSJean-Christophe PLAGNIOL-VILLARD 11093a686eeSJean-Christophe PLAGNIOL-VILLARD if ( bridge ) { 11193a686eeSJean-Christophe PLAGNIOL-VILLARD 11293a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_read_config_word(hose, dev, PCI_LTSSM, <ssm); 11393a686eeSJean-Christophe PLAGNIOL-VILLARD enabled = ltssm >= PCI_LTSSM_L0; 11493a686eeSJean-Christophe PLAGNIOL-VILLARD 115*8ff3de61SKumar Gala #ifdef CONFIG_FSL_PCIE_RESET 116*8ff3de61SKumar Gala if (ltssm == 1) { 117*8ff3de61SKumar Gala int i; 118*8ff3de61SKumar Gala debug("....PCIe link error. " 119*8ff3de61SKumar Gala "LTSSM=0x%02x.", ltssm); 120*8ff3de61SKumar Gala pci->pdb_stat |= 0x08000000; /* assert PCIe reset */ 121*8ff3de61SKumar Gala temp32 = pci->pdb_stat; 122*8ff3de61SKumar Gala udelay(100); 123*8ff3de61SKumar Gala debug(" Asserting PCIe reset @%x = %x\n", 124*8ff3de61SKumar Gala &pci->pdb_stat, pci->pdb_stat); 125*8ff3de61SKumar Gala pci->pdb_stat &= ~0x08000000; /* clear reset */ 126*8ff3de61SKumar Gala asm("sync;isync"); 127*8ff3de61SKumar Gala for (i=0; i<100 && ltssm < PCI_LTSSM_L0; i++) { 128*8ff3de61SKumar Gala pci_hose_read_config_word(hose, dev, PCI_LTSSM, 129*8ff3de61SKumar Gala <ssm); 130*8ff3de61SKumar Gala udelay(1000); 131*8ff3de61SKumar Gala debug("....PCIe link error. " 132*8ff3de61SKumar Gala "LTSSM=0x%02x.\n", ltssm); 133*8ff3de61SKumar Gala } 134*8ff3de61SKumar Gala enabled = ltssm >= PCI_LTSSM_L0; 135*8ff3de61SKumar Gala } 136*8ff3de61SKumar Gala #endif 137*8ff3de61SKumar Gala 13893a686eeSJean-Christophe PLAGNIOL-VILLARD if (!enabled) { 13993a686eeSJean-Christophe PLAGNIOL-VILLARD debug("....PCIE link error. Skipping scan." 14093a686eeSJean-Christophe PLAGNIOL-VILLARD "LTSSM=0x%02x\n", ltssm); 14193a686eeSJean-Christophe PLAGNIOL-VILLARD hose->last_busno = hose->first_busno; 14293a686eeSJean-Christophe PLAGNIOL-VILLARD return; 14393a686eeSJean-Christophe PLAGNIOL-VILLARD } 14493a686eeSJean-Christophe PLAGNIOL-VILLARD 14593a686eeSJean-Christophe PLAGNIOL-VILLARD pci->pme_msg_det = 0xffffffff; 14693a686eeSJean-Christophe PLAGNIOL-VILLARD pci->pme_msg_int_en = 0xffffffff; 14793a686eeSJean-Christophe PLAGNIOL-VILLARD #ifdef DEBUG 14893a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_read_config_word(hose, dev, PCI_LSR, &temp16); 14993a686eeSJean-Christophe PLAGNIOL-VILLARD neg_link_w = (temp16 & 0x3f0 ) >> 4; 15093a686eeSJean-Christophe PLAGNIOL-VILLARD printf("...PCIE LTSSM=0x%x, Negotiated link width=%d\n", 15193a686eeSJean-Christophe PLAGNIOL-VILLARD ltssm, neg_link_w); 15293a686eeSJean-Christophe PLAGNIOL-VILLARD #endif 15393a686eeSJean-Christophe PLAGNIOL-VILLARD hose->current_busno++; /* Start scan with secondary */ 15493a686eeSJean-Christophe PLAGNIOL-VILLARD pciauto_prescan_setup_bridge(hose, dev, hose->current_busno); 15593a686eeSJean-Christophe PLAGNIOL-VILLARD 15693a686eeSJean-Christophe PLAGNIOL-VILLARD } 15793a686eeSJean-Christophe PLAGNIOL-VILLARD 15893a686eeSJean-Christophe PLAGNIOL-VILLARD /* Use generic setup_device to initialize standard pci regs, 15993a686eeSJean-Christophe PLAGNIOL-VILLARD * but do not allocate any windows since any BAR found (such 16093a686eeSJean-Christophe PLAGNIOL-VILLARD * as PCSRBAR) is not in this cpu's memory space. 16193a686eeSJean-Christophe PLAGNIOL-VILLARD */ 16293a686eeSJean-Christophe PLAGNIOL-VILLARD 16393a686eeSJean-Christophe PLAGNIOL-VILLARD pciauto_setup_device(hose, dev, 0, hose->pci_mem, 16493a686eeSJean-Christophe PLAGNIOL-VILLARD hose->pci_prefetch, hose->pci_io); 16593a686eeSJean-Christophe PLAGNIOL-VILLARD 16693a686eeSJean-Christophe PLAGNIOL-VILLARD if (inbound) { 16793a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_read_config_word(hose, dev, PCI_COMMAND, &temp16); 16893a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_write_config_word(hose, dev, PCI_COMMAND, 16993a686eeSJean-Christophe PLAGNIOL-VILLARD temp16 | PCI_COMMAND_MEMORY); 17093a686eeSJean-Christophe PLAGNIOL-VILLARD } 17193a686eeSJean-Christophe PLAGNIOL-VILLARD 17293a686eeSJean-Christophe PLAGNIOL-VILLARD #ifndef CONFIG_PCI_NOSCAN 17393a686eeSJean-Christophe PLAGNIOL-VILLARD printf (" Scanning PCI bus %02x\n", hose->current_busno); 17493a686eeSJean-Christophe PLAGNIOL-VILLARD hose->last_busno = pci_hose_scan_bus(hose,hose->current_busno); 17593a686eeSJean-Christophe PLAGNIOL-VILLARD 17693a686eeSJean-Christophe PLAGNIOL-VILLARD if ( bridge ) { /* update limit regs and subordinate busno */ 17793a686eeSJean-Christophe PLAGNIOL-VILLARD pciauto_postscan_setup_bridge(hose, dev, hose->last_busno); 17893a686eeSJean-Christophe PLAGNIOL-VILLARD } 17993a686eeSJean-Christophe PLAGNIOL-VILLARD #else 18093a686eeSJean-Christophe PLAGNIOL-VILLARD hose->last_busno = hose->current_busno; 18193a686eeSJean-Christophe PLAGNIOL-VILLARD #endif 18293a686eeSJean-Christophe PLAGNIOL-VILLARD 18393a686eeSJean-Christophe PLAGNIOL-VILLARD /* Clear all error indications */ 18493a686eeSJean-Christophe PLAGNIOL-VILLARD 18593a686eeSJean-Christophe PLAGNIOL-VILLARD pci->pme_msg_det = 0xffffffff; 18693a686eeSJean-Christophe PLAGNIOL-VILLARD pci->pedr = 0xffffffff; 18793a686eeSJean-Christophe PLAGNIOL-VILLARD 18893a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_read_config_word (hose, dev, PCI_DSR, &temp16); 18993a686eeSJean-Christophe PLAGNIOL-VILLARD if (temp16) { 19093a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_write_config_word(hose, dev, 19193a686eeSJean-Christophe PLAGNIOL-VILLARD PCI_DSR, 0xffff); 19293a686eeSJean-Christophe PLAGNIOL-VILLARD } 19393a686eeSJean-Christophe PLAGNIOL-VILLARD 19493a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_read_config_word (hose, dev, PCI_SEC_STATUS, &temp16); 19593a686eeSJean-Christophe PLAGNIOL-VILLARD if (temp16) { 19693a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_write_config_word(hose, dev, PCI_SEC_STATUS, 0xffff); 19793a686eeSJean-Christophe PLAGNIOL-VILLARD } 19893a686eeSJean-Christophe PLAGNIOL-VILLARD } 19993a686eeSJean-Christophe PLAGNIOL-VILLARD 20093a686eeSJean-Christophe PLAGNIOL-VILLARD #endif /* CONFIG_FSL_PCI */ 201