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 /* 2293a686eeSJean-Christophe PLAGNIOL-VILLARD * PCI/PCIE Controller initialization for mpc85xx/mpc86xx soc's 2393a686eeSJean-Christophe PLAGNIOL-VILLARD * 2493a686eeSJean-Christophe PLAGNIOL-VILLARD * Initialize controller and call the common driver/pci pci_hose_scan to 2593a686eeSJean-Christophe PLAGNIOL-VILLARD * scan for bridges and devices. 2693a686eeSJean-Christophe PLAGNIOL-VILLARD * 2793a686eeSJean-Christophe PLAGNIOL-VILLARD * Hose fields which need to be pre-initialized by board specific code: 2893a686eeSJean-Christophe PLAGNIOL-VILLARD * regions[] 2993a686eeSJean-Christophe PLAGNIOL-VILLARD * first_busno 3093a686eeSJean-Christophe PLAGNIOL-VILLARD * 3193a686eeSJean-Christophe PLAGNIOL-VILLARD * Fields updated: 3293a686eeSJean-Christophe PLAGNIOL-VILLARD * last_busno 3393a686eeSJean-Christophe PLAGNIOL-VILLARD */ 3493a686eeSJean-Christophe PLAGNIOL-VILLARD 3593a686eeSJean-Christophe PLAGNIOL-VILLARD #include <pci.h> 3693a686eeSJean-Christophe PLAGNIOL-VILLARD #include <asm/immap_fsl_pci.h> 3793a686eeSJean-Christophe PLAGNIOL-VILLARD 3893a686eeSJean-Christophe PLAGNIOL-VILLARD void pciauto_prescan_setup_bridge(struct pci_controller *hose, 3993a686eeSJean-Christophe PLAGNIOL-VILLARD pci_dev_t dev, int sub_bus); 4093a686eeSJean-Christophe PLAGNIOL-VILLARD void pciauto_postscan_setup_bridge(struct pci_controller *hose, 4193a686eeSJean-Christophe PLAGNIOL-VILLARD pci_dev_t dev, int sub_bus); 4293a686eeSJean-Christophe PLAGNIOL-VILLARD 4393a686eeSJean-Christophe PLAGNIOL-VILLARD void pciauto_config_init(struct pci_controller *hose); 4493a686eeSJean-Christophe PLAGNIOL-VILLARD void 4593a686eeSJean-Christophe PLAGNIOL-VILLARD fsl_pci_init(struct pci_controller *hose) 4693a686eeSJean-Christophe PLAGNIOL-VILLARD { 4793a686eeSJean-Christophe PLAGNIOL-VILLARD u16 temp16; 4893a686eeSJean-Christophe PLAGNIOL-VILLARD u32 temp32; 4993a686eeSJean-Christophe PLAGNIOL-VILLARD int busno = hose->first_busno; 5093a686eeSJean-Christophe PLAGNIOL-VILLARD int enabled; 5193a686eeSJean-Christophe PLAGNIOL-VILLARD u16 ltssm; 5293a686eeSJean-Christophe PLAGNIOL-VILLARD u8 temp8; 5393a686eeSJean-Christophe PLAGNIOL-VILLARD int r; 5493a686eeSJean-Christophe PLAGNIOL-VILLARD int bridge; 5593a686eeSJean-Christophe PLAGNIOL-VILLARD int inbound = 0; 5693a686eeSJean-Christophe PLAGNIOL-VILLARD volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) hose->cfg_addr; 5793a686eeSJean-Christophe PLAGNIOL-VILLARD pci_dev_t dev = PCI_BDF(busno,0,0); 5893a686eeSJean-Christophe PLAGNIOL-VILLARD 5993a686eeSJean-Christophe PLAGNIOL-VILLARD /* Initialize ATMU registers based on hose regions and flags */ 6093a686eeSJean-Christophe PLAGNIOL-VILLARD volatile pot_t *po = &pci->pot[1]; /* skip 0 */ 6193a686eeSJean-Christophe PLAGNIOL-VILLARD volatile pit_t *pi = &pci->pit[0]; /* ranges from: 3 to 1 */ 6293a686eeSJean-Christophe PLAGNIOL-VILLARD 6393a686eeSJean-Christophe PLAGNIOL-VILLARD #ifdef DEBUG 6493a686eeSJean-Christophe PLAGNIOL-VILLARD int neg_link_w; 6593a686eeSJean-Christophe PLAGNIOL-VILLARD #endif 6693a686eeSJean-Christophe PLAGNIOL-VILLARD 6793a686eeSJean-Christophe PLAGNIOL-VILLARD for (r=0; r<hose->region_count; r++) { 6893a686eeSJean-Christophe PLAGNIOL-VILLARD if (hose->regions[r].flags & PCI_REGION_MEMORY) { /* inbound */ 6993a686eeSJean-Christophe PLAGNIOL-VILLARD pi->pitar = (hose->regions[r].bus_start >> 12) & 0x000fffff; 7093a686eeSJean-Christophe PLAGNIOL-VILLARD pi->piwbar = (hose->regions[r].phys_start >> 12) & 0x000fffff; 7193a686eeSJean-Christophe PLAGNIOL-VILLARD pi->piwbear = 0; 7293a686eeSJean-Christophe PLAGNIOL-VILLARD pi->piwar = PIWAR_EN | PIWAR_PF | PIWAR_LOCAL | 7393a686eeSJean-Christophe PLAGNIOL-VILLARD PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP | 7493a686eeSJean-Christophe PLAGNIOL-VILLARD (__ilog2(hose->regions[r].size) - 1); 7593a686eeSJean-Christophe PLAGNIOL-VILLARD pi++; 7693a686eeSJean-Christophe PLAGNIOL-VILLARD inbound = hose->regions[r].size > 0; 7793a686eeSJean-Christophe PLAGNIOL-VILLARD } else { /* Outbound */ 7893a686eeSJean-Christophe PLAGNIOL-VILLARD po->powbar = (hose->regions[r].phys_start >> 12) & 0x000fffff; 7993a686eeSJean-Christophe PLAGNIOL-VILLARD po->potar = (hose->regions[r].bus_start >> 12) & 0x000fffff; 8093a686eeSJean-Christophe PLAGNIOL-VILLARD po->potear = 0; 8193a686eeSJean-Christophe PLAGNIOL-VILLARD if (hose->regions[r].flags & PCI_REGION_IO) 8293a686eeSJean-Christophe PLAGNIOL-VILLARD po->powar = POWAR_EN | POWAR_IO_READ | POWAR_IO_WRITE | 8393a686eeSJean-Christophe PLAGNIOL-VILLARD (__ilog2(hose->regions[r].size) - 1); 8493a686eeSJean-Christophe PLAGNIOL-VILLARD else 8593a686eeSJean-Christophe PLAGNIOL-VILLARD po->powar = POWAR_EN | POWAR_MEM_READ | POWAR_MEM_WRITE | 8693a686eeSJean-Christophe PLAGNIOL-VILLARD (__ilog2(hose->regions[r].size) - 1); 8793a686eeSJean-Christophe PLAGNIOL-VILLARD po++; 8893a686eeSJean-Christophe PLAGNIOL-VILLARD } 8993a686eeSJean-Christophe PLAGNIOL-VILLARD } 9093a686eeSJean-Christophe PLAGNIOL-VILLARD 9193a686eeSJean-Christophe PLAGNIOL-VILLARD pci_register_hose(hose); 9293a686eeSJean-Christophe PLAGNIOL-VILLARD pciauto_config_init(hose); /* grab pci_{mem,prefetch,io} */ 9393a686eeSJean-Christophe PLAGNIOL-VILLARD hose->current_busno = hose->first_busno; 9493a686eeSJean-Christophe PLAGNIOL-VILLARD 9593a686eeSJean-Christophe PLAGNIOL-VILLARD pci->pedr = 0xffffffff; /* Clear any errors */ 9693a686eeSJean-Christophe PLAGNIOL-VILLARD pci->peer = ~0x20140; /* Enable All Error Interupts except 9793a686eeSJean-Christophe PLAGNIOL-VILLARD * - Master abort (pci) 9893a686eeSJean-Christophe PLAGNIOL-VILLARD * - Master PERR (pci) 9993a686eeSJean-Christophe PLAGNIOL-VILLARD * - ICCA (PCIe) 10093a686eeSJean-Christophe PLAGNIOL-VILLARD */ 10193a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_read_config_dword (hose, dev, PCI_DCR, &temp32); 10293a686eeSJean-Christophe PLAGNIOL-VILLARD temp32 |= 0xf000e; /* set URR, FER, NFER (but not CER) */ 10393a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_write_config_dword(hose, dev, PCI_DCR, temp32); 10493a686eeSJean-Christophe PLAGNIOL-VILLARD 10593a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_read_config_byte (hose, dev, PCI_HEADER_TYPE, &temp8); 10693a686eeSJean-Christophe PLAGNIOL-VILLARD bridge = temp8 & PCI_HEADER_TYPE_BRIDGE; /* Bridge, such as pcie */ 10793a686eeSJean-Christophe PLAGNIOL-VILLARD 10893a686eeSJean-Christophe PLAGNIOL-VILLARD if ( bridge ) { 10993a686eeSJean-Christophe PLAGNIOL-VILLARD 11093a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_read_config_word(hose, dev, PCI_LTSSM, <ssm); 11193a686eeSJean-Christophe PLAGNIOL-VILLARD enabled = ltssm >= PCI_LTSSM_L0; 11293a686eeSJean-Christophe PLAGNIOL-VILLARD 1138ff3de61SKumar Gala #ifdef CONFIG_FSL_PCIE_RESET 1148ff3de61SKumar Gala if (ltssm == 1) { 1158ff3de61SKumar Gala int i; 1168ff3de61SKumar Gala debug("....PCIe link error. " 1178ff3de61SKumar Gala "LTSSM=0x%02x.", ltssm); 1188ff3de61SKumar Gala pci->pdb_stat |= 0x08000000; /* assert PCIe reset */ 1198ff3de61SKumar Gala temp32 = pci->pdb_stat; 1208ff3de61SKumar Gala udelay(100); 1218ff3de61SKumar Gala debug(" Asserting PCIe reset @%x = %x\n", 1228ff3de61SKumar Gala &pci->pdb_stat, pci->pdb_stat); 1238ff3de61SKumar Gala pci->pdb_stat &= ~0x08000000; /* clear reset */ 1248ff3de61SKumar Gala asm("sync;isync"); 1258ff3de61SKumar Gala for (i=0; i<100 && ltssm < PCI_LTSSM_L0; i++) { 1268ff3de61SKumar Gala pci_hose_read_config_word(hose, dev, PCI_LTSSM, 1278ff3de61SKumar Gala <ssm); 1288ff3de61SKumar Gala udelay(1000); 1298ff3de61SKumar Gala debug("....PCIe link error. " 1308ff3de61SKumar Gala "LTSSM=0x%02x.\n", ltssm); 1318ff3de61SKumar Gala } 1328ff3de61SKumar Gala enabled = ltssm >= PCI_LTSSM_L0; 1338ff3de61SKumar Gala } 1348ff3de61SKumar Gala #endif 1358ff3de61SKumar Gala 13693a686eeSJean-Christophe PLAGNIOL-VILLARD if (!enabled) { 13793a686eeSJean-Christophe PLAGNIOL-VILLARD debug("....PCIE link error. Skipping scan." 13893a686eeSJean-Christophe PLAGNIOL-VILLARD "LTSSM=0x%02x\n", ltssm); 13993a686eeSJean-Christophe PLAGNIOL-VILLARD hose->last_busno = hose->first_busno; 14093a686eeSJean-Christophe PLAGNIOL-VILLARD return; 14193a686eeSJean-Christophe PLAGNIOL-VILLARD } 14293a686eeSJean-Christophe PLAGNIOL-VILLARD 14393a686eeSJean-Christophe PLAGNIOL-VILLARD pci->pme_msg_det = 0xffffffff; 14493a686eeSJean-Christophe PLAGNIOL-VILLARD pci->pme_msg_int_en = 0xffffffff; 14593a686eeSJean-Christophe PLAGNIOL-VILLARD #ifdef DEBUG 14693a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_read_config_word(hose, dev, PCI_LSR, &temp16); 14793a686eeSJean-Christophe PLAGNIOL-VILLARD neg_link_w = (temp16 & 0x3f0 ) >> 4; 14893a686eeSJean-Christophe PLAGNIOL-VILLARD printf("...PCIE LTSSM=0x%x, Negotiated link width=%d\n", 14993a686eeSJean-Christophe PLAGNIOL-VILLARD ltssm, neg_link_w); 15093a686eeSJean-Christophe PLAGNIOL-VILLARD #endif 15193a686eeSJean-Christophe PLAGNIOL-VILLARD hose->current_busno++; /* Start scan with secondary */ 15293a686eeSJean-Christophe PLAGNIOL-VILLARD pciauto_prescan_setup_bridge(hose, dev, hose->current_busno); 15393a686eeSJean-Christophe PLAGNIOL-VILLARD 15493a686eeSJean-Christophe PLAGNIOL-VILLARD } 15593a686eeSJean-Christophe PLAGNIOL-VILLARD 15693a686eeSJean-Christophe PLAGNIOL-VILLARD /* Use generic setup_device to initialize standard pci regs, 15793a686eeSJean-Christophe PLAGNIOL-VILLARD * but do not allocate any windows since any BAR found (such 15893a686eeSJean-Christophe PLAGNIOL-VILLARD * as PCSRBAR) is not in this cpu's memory space. 15993a686eeSJean-Christophe PLAGNIOL-VILLARD */ 16093a686eeSJean-Christophe PLAGNIOL-VILLARD 16193a686eeSJean-Christophe PLAGNIOL-VILLARD pciauto_setup_device(hose, dev, 0, hose->pci_mem, 16293a686eeSJean-Christophe PLAGNIOL-VILLARD hose->pci_prefetch, hose->pci_io); 16393a686eeSJean-Christophe PLAGNIOL-VILLARD 16493a686eeSJean-Christophe PLAGNIOL-VILLARD if (inbound) { 16593a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_read_config_word(hose, dev, PCI_COMMAND, &temp16); 16693a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_write_config_word(hose, dev, PCI_COMMAND, 16793a686eeSJean-Christophe PLAGNIOL-VILLARD temp16 | PCI_COMMAND_MEMORY); 16893a686eeSJean-Christophe PLAGNIOL-VILLARD } 16993a686eeSJean-Christophe PLAGNIOL-VILLARD 17093a686eeSJean-Christophe PLAGNIOL-VILLARD #ifndef CONFIG_PCI_NOSCAN 171*6df0efd5SEd Swarthout pci_hose_read_config_byte(hose, dev, PCI_CLASS_PROG, &temp8); 172*6df0efd5SEd Swarthout 173*6df0efd5SEd Swarthout /* Programming Interface (PCI_CLASS_PROG) 174*6df0efd5SEd Swarthout * 0 == pci host or pcie root-complex, 175*6df0efd5SEd Swarthout * 1 == pci agent or pcie end-point 176*6df0efd5SEd Swarthout */ 177*6df0efd5SEd Swarthout if (!temp8) { 178*6df0efd5SEd Swarthout printf(" Scanning PCI bus %02x\n", 179*6df0efd5SEd Swarthout hose->current_busno); 18093a686eeSJean-Christophe PLAGNIOL-VILLARD hose->last_busno = pci_hose_scan_bus(hose, hose->current_busno); 181*6df0efd5SEd Swarthout } else { 182*6df0efd5SEd Swarthout debug(" Not scanning PCI bus %02x. PI=%x\n", 183*6df0efd5SEd Swarthout hose->current_busno, temp8); 184*6df0efd5SEd Swarthout hose->last_busno = hose->current_busno; 185*6df0efd5SEd Swarthout } 18693a686eeSJean-Christophe PLAGNIOL-VILLARD 18793a686eeSJean-Christophe PLAGNIOL-VILLARD if ( bridge ) { /* update limit regs and subordinate busno */ 18893a686eeSJean-Christophe PLAGNIOL-VILLARD pciauto_postscan_setup_bridge(hose, dev, hose->last_busno); 18993a686eeSJean-Christophe PLAGNIOL-VILLARD } 19093a686eeSJean-Christophe PLAGNIOL-VILLARD #else 19193a686eeSJean-Christophe PLAGNIOL-VILLARD hose->last_busno = hose->current_busno; 19293a686eeSJean-Christophe PLAGNIOL-VILLARD #endif 19393a686eeSJean-Christophe PLAGNIOL-VILLARD 19493a686eeSJean-Christophe PLAGNIOL-VILLARD /* Clear all error indications */ 19593a686eeSJean-Christophe PLAGNIOL-VILLARD 196876b8f97SKumar Gala if (bridge) 19793a686eeSJean-Christophe PLAGNIOL-VILLARD pci->pme_msg_det = 0xffffffff; 19893a686eeSJean-Christophe PLAGNIOL-VILLARD pci->pedr = 0xffffffff; 19993a686eeSJean-Christophe PLAGNIOL-VILLARD 20093a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_read_config_word (hose, dev, PCI_DSR, &temp16); 20193a686eeSJean-Christophe PLAGNIOL-VILLARD if (temp16) { 20293a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_write_config_word(hose, dev, 20393a686eeSJean-Christophe PLAGNIOL-VILLARD PCI_DSR, 0xffff); 20493a686eeSJean-Christophe PLAGNIOL-VILLARD } 20593a686eeSJean-Christophe PLAGNIOL-VILLARD 20693a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_read_config_word (hose, dev, PCI_SEC_STATUS, &temp16); 20793a686eeSJean-Christophe PLAGNIOL-VILLARD if (temp16) { 20893a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_write_config_word(hose, dev, PCI_SEC_STATUS, 0xffff); 20993a686eeSJean-Christophe PLAGNIOL-VILLARD } 21093a686eeSJean-Christophe PLAGNIOL-VILLARD } 211