1*93a686eeSJean-Christophe PLAGNIOL-VILLARD /* 2*93a686eeSJean-Christophe PLAGNIOL-VILLARD * Copyright 2007 Freescale Semiconductor, Inc. 3*93a686eeSJean-Christophe PLAGNIOL-VILLARD * 4*93a686eeSJean-Christophe PLAGNIOL-VILLARD * This program is free software; you can redistribute it and/or 5*93a686eeSJean-Christophe PLAGNIOL-VILLARD * modify it under the terms of the GNU General Public License 6*93a686eeSJean-Christophe PLAGNIOL-VILLARD * Version 2 as published by the Free Software Foundation. 7*93a686eeSJean-Christophe PLAGNIOL-VILLARD * 8*93a686eeSJean-Christophe PLAGNIOL-VILLARD * This program is distributed in the hope that it will be useful, 9*93a686eeSJean-Christophe PLAGNIOL-VILLARD * but WITHOUT ANY WARRANTY; without even the implied warranty of 10*93a686eeSJean-Christophe PLAGNIOL-VILLARD * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11*93a686eeSJean-Christophe PLAGNIOL-VILLARD * GNU General Public License for more details. 12*93a686eeSJean-Christophe PLAGNIOL-VILLARD * 13*93a686eeSJean-Christophe PLAGNIOL-VILLARD * You should have received a copy of the GNU General Public License 14*93a686eeSJean-Christophe PLAGNIOL-VILLARD * along with this program; if not, write to the Free Software 15*93a686eeSJean-Christophe PLAGNIOL-VILLARD * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 16*93a686eeSJean-Christophe PLAGNIOL-VILLARD * MA 02111-1307 USA 17*93a686eeSJean-Christophe PLAGNIOL-VILLARD */ 18*93a686eeSJean-Christophe PLAGNIOL-VILLARD 19*93a686eeSJean-Christophe PLAGNIOL-VILLARD #include <common.h> 20*93a686eeSJean-Christophe PLAGNIOL-VILLARD 21*93a686eeSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_FSL_PCI_INIT 22*93a686eeSJean-Christophe PLAGNIOL-VILLARD 23*93a686eeSJean-Christophe PLAGNIOL-VILLARD /* 24*93a686eeSJean-Christophe PLAGNIOL-VILLARD * PCI/PCIE Controller initialization for mpc85xx/mpc86xx soc's 25*93a686eeSJean-Christophe PLAGNIOL-VILLARD * 26*93a686eeSJean-Christophe PLAGNIOL-VILLARD * Initialize controller and call the common driver/pci pci_hose_scan to 27*93a686eeSJean-Christophe PLAGNIOL-VILLARD * scan for bridges and devices. 28*93a686eeSJean-Christophe PLAGNIOL-VILLARD * 29*93a686eeSJean-Christophe PLAGNIOL-VILLARD * Hose fields which need to be pre-initialized by board specific code: 30*93a686eeSJean-Christophe PLAGNIOL-VILLARD * regions[] 31*93a686eeSJean-Christophe PLAGNIOL-VILLARD * first_busno 32*93a686eeSJean-Christophe PLAGNIOL-VILLARD * 33*93a686eeSJean-Christophe PLAGNIOL-VILLARD * Fields updated: 34*93a686eeSJean-Christophe PLAGNIOL-VILLARD * last_busno 35*93a686eeSJean-Christophe PLAGNIOL-VILLARD */ 36*93a686eeSJean-Christophe PLAGNIOL-VILLARD 37*93a686eeSJean-Christophe PLAGNIOL-VILLARD #include <pci.h> 38*93a686eeSJean-Christophe PLAGNIOL-VILLARD #include <asm/immap_fsl_pci.h> 39*93a686eeSJean-Christophe PLAGNIOL-VILLARD 40*93a686eeSJean-Christophe PLAGNIOL-VILLARD void pciauto_prescan_setup_bridge(struct pci_controller *hose, 41*93a686eeSJean-Christophe PLAGNIOL-VILLARD pci_dev_t dev, int sub_bus); 42*93a686eeSJean-Christophe PLAGNIOL-VILLARD void pciauto_postscan_setup_bridge(struct pci_controller *hose, 43*93a686eeSJean-Christophe PLAGNIOL-VILLARD pci_dev_t dev, int sub_bus); 44*93a686eeSJean-Christophe PLAGNIOL-VILLARD 45*93a686eeSJean-Christophe PLAGNIOL-VILLARD void pciauto_config_init(struct pci_controller *hose); 46*93a686eeSJean-Christophe PLAGNIOL-VILLARD void 47*93a686eeSJean-Christophe PLAGNIOL-VILLARD fsl_pci_init(struct pci_controller *hose) 48*93a686eeSJean-Christophe PLAGNIOL-VILLARD { 49*93a686eeSJean-Christophe PLAGNIOL-VILLARD u16 temp16; 50*93a686eeSJean-Christophe PLAGNIOL-VILLARD u32 temp32; 51*93a686eeSJean-Christophe PLAGNIOL-VILLARD int busno = hose->first_busno; 52*93a686eeSJean-Christophe PLAGNIOL-VILLARD int enabled; 53*93a686eeSJean-Christophe PLAGNIOL-VILLARD u16 ltssm; 54*93a686eeSJean-Christophe PLAGNIOL-VILLARD u8 temp8; 55*93a686eeSJean-Christophe PLAGNIOL-VILLARD int r; 56*93a686eeSJean-Christophe PLAGNIOL-VILLARD int bridge; 57*93a686eeSJean-Christophe PLAGNIOL-VILLARD int inbound = 0; 58*93a686eeSJean-Christophe PLAGNIOL-VILLARD volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) hose->cfg_addr; 59*93a686eeSJean-Christophe PLAGNIOL-VILLARD pci_dev_t dev = PCI_BDF(busno,0,0); 60*93a686eeSJean-Christophe PLAGNIOL-VILLARD 61*93a686eeSJean-Christophe PLAGNIOL-VILLARD /* Initialize ATMU registers based on hose regions and flags */ 62*93a686eeSJean-Christophe PLAGNIOL-VILLARD volatile pot_t *po=&pci->pot[1]; /* skip 0 */ 63*93a686eeSJean-Christophe PLAGNIOL-VILLARD volatile pit_t *pi=&pci->pit[0]; /* ranges from: 3 to 1 */ 64*93a686eeSJean-Christophe PLAGNIOL-VILLARD 65*93a686eeSJean-Christophe PLAGNIOL-VILLARD #ifdef DEBUG 66*93a686eeSJean-Christophe PLAGNIOL-VILLARD int neg_link_w; 67*93a686eeSJean-Christophe PLAGNIOL-VILLARD #endif 68*93a686eeSJean-Christophe PLAGNIOL-VILLARD 69*93a686eeSJean-Christophe PLAGNIOL-VILLARD for (r=0; r<hose->region_count; r++) { 70*93a686eeSJean-Christophe PLAGNIOL-VILLARD if (hose->regions[r].flags & PCI_REGION_MEMORY) { /* inbound */ 71*93a686eeSJean-Christophe PLAGNIOL-VILLARD pi->pitar = (hose->regions[r].bus_start >> 12) & 0x000fffff; 72*93a686eeSJean-Christophe PLAGNIOL-VILLARD pi->piwbar = (hose->regions[r].phys_start >> 12) & 0x000fffff; 73*93a686eeSJean-Christophe PLAGNIOL-VILLARD pi->piwbear = 0; 74*93a686eeSJean-Christophe PLAGNIOL-VILLARD pi->piwar = PIWAR_EN | PIWAR_PF | PIWAR_LOCAL | 75*93a686eeSJean-Christophe PLAGNIOL-VILLARD PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP | 76*93a686eeSJean-Christophe PLAGNIOL-VILLARD (__ilog2(hose->regions[r].size) - 1); 77*93a686eeSJean-Christophe PLAGNIOL-VILLARD pi++; 78*93a686eeSJean-Christophe PLAGNIOL-VILLARD inbound = hose->regions[r].size > 0; 79*93a686eeSJean-Christophe PLAGNIOL-VILLARD } else { /* Outbound */ 80*93a686eeSJean-Christophe PLAGNIOL-VILLARD po->powbar = (hose->regions[r].phys_start >> 12) & 0x000fffff; 81*93a686eeSJean-Christophe PLAGNIOL-VILLARD po->potar = (hose->regions[r].bus_start >> 12) & 0x000fffff; 82*93a686eeSJean-Christophe PLAGNIOL-VILLARD po->potear = 0; 83*93a686eeSJean-Christophe PLAGNIOL-VILLARD if (hose->regions[r].flags & PCI_REGION_IO) 84*93a686eeSJean-Christophe PLAGNIOL-VILLARD po->powar = POWAR_EN | POWAR_IO_READ | POWAR_IO_WRITE | 85*93a686eeSJean-Christophe PLAGNIOL-VILLARD (__ilog2(hose->regions[r].size) - 1); 86*93a686eeSJean-Christophe PLAGNIOL-VILLARD else 87*93a686eeSJean-Christophe PLAGNIOL-VILLARD po->powar = POWAR_EN | POWAR_MEM_READ | POWAR_MEM_WRITE | 88*93a686eeSJean-Christophe PLAGNIOL-VILLARD (__ilog2(hose->regions[r].size) - 1); 89*93a686eeSJean-Christophe PLAGNIOL-VILLARD po++; 90*93a686eeSJean-Christophe PLAGNIOL-VILLARD } 91*93a686eeSJean-Christophe PLAGNIOL-VILLARD } 92*93a686eeSJean-Christophe PLAGNIOL-VILLARD 93*93a686eeSJean-Christophe PLAGNIOL-VILLARD pci_register_hose(hose); 94*93a686eeSJean-Christophe PLAGNIOL-VILLARD pciauto_config_init(hose); /* grab pci_{mem,prefetch,io} */ 95*93a686eeSJean-Christophe PLAGNIOL-VILLARD hose->current_busno = hose->first_busno; 96*93a686eeSJean-Christophe PLAGNIOL-VILLARD 97*93a686eeSJean-Christophe PLAGNIOL-VILLARD pci->pedr = 0xffffffff; /* Clear any errors */ 98*93a686eeSJean-Christophe PLAGNIOL-VILLARD pci->peer = ~0x20140; /* Enable All Error Interupts except 99*93a686eeSJean-Christophe PLAGNIOL-VILLARD * - Master abort (pci) 100*93a686eeSJean-Christophe PLAGNIOL-VILLARD * - Master PERR (pci) 101*93a686eeSJean-Christophe PLAGNIOL-VILLARD * - ICCA (PCIe) 102*93a686eeSJean-Christophe PLAGNIOL-VILLARD */ 103*93a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_read_config_dword (hose, dev, PCI_DCR, &temp32); 104*93a686eeSJean-Christophe PLAGNIOL-VILLARD temp32 |= 0xf000e; /* set URR, FER, NFER (but not CER) */ 105*93a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_write_config_dword(hose, dev, PCI_DCR, temp32); 106*93a686eeSJean-Christophe PLAGNIOL-VILLARD 107*93a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_read_config_byte (hose, dev, PCI_HEADER_TYPE, &temp8); 108*93a686eeSJean-Christophe PLAGNIOL-VILLARD bridge = temp8 & PCI_HEADER_TYPE_BRIDGE; /* Bridge, such as pcie */ 109*93a686eeSJean-Christophe PLAGNIOL-VILLARD 110*93a686eeSJean-Christophe PLAGNIOL-VILLARD if ( bridge ) { 111*93a686eeSJean-Christophe PLAGNIOL-VILLARD 112*93a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_read_config_word(hose, dev, PCI_LTSSM, <ssm); 113*93a686eeSJean-Christophe PLAGNIOL-VILLARD enabled = ltssm >= PCI_LTSSM_L0; 114*93a686eeSJean-Christophe PLAGNIOL-VILLARD 115*93a686eeSJean-Christophe PLAGNIOL-VILLARD if (!enabled) { 116*93a686eeSJean-Christophe PLAGNIOL-VILLARD debug("....PCIE link error. Skipping scan." 117*93a686eeSJean-Christophe PLAGNIOL-VILLARD "LTSSM=0x%02x\n", ltssm); 118*93a686eeSJean-Christophe PLAGNIOL-VILLARD hose->last_busno = hose->first_busno; 119*93a686eeSJean-Christophe PLAGNIOL-VILLARD return; 120*93a686eeSJean-Christophe PLAGNIOL-VILLARD } 121*93a686eeSJean-Christophe PLAGNIOL-VILLARD 122*93a686eeSJean-Christophe PLAGNIOL-VILLARD pci->pme_msg_det = 0xffffffff; 123*93a686eeSJean-Christophe PLAGNIOL-VILLARD pci->pme_msg_int_en = 0xffffffff; 124*93a686eeSJean-Christophe PLAGNIOL-VILLARD #ifdef DEBUG 125*93a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_read_config_word(hose, dev, PCI_LSR, &temp16); 126*93a686eeSJean-Christophe PLAGNIOL-VILLARD neg_link_w = (temp16 & 0x3f0 ) >> 4; 127*93a686eeSJean-Christophe PLAGNIOL-VILLARD printf("...PCIE LTSSM=0x%x, Negotiated link width=%d\n", 128*93a686eeSJean-Christophe PLAGNIOL-VILLARD ltssm, neg_link_w); 129*93a686eeSJean-Christophe PLAGNIOL-VILLARD #endif 130*93a686eeSJean-Christophe PLAGNIOL-VILLARD hose->current_busno++; /* Start scan with secondary */ 131*93a686eeSJean-Christophe PLAGNIOL-VILLARD pciauto_prescan_setup_bridge(hose, dev, hose->current_busno); 132*93a686eeSJean-Christophe PLAGNIOL-VILLARD 133*93a686eeSJean-Christophe PLAGNIOL-VILLARD } 134*93a686eeSJean-Christophe PLAGNIOL-VILLARD 135*93a686eeSJean-Christophe PLAGNIOL-VILLARD /* Use generic setup_device to initialize standard pci regs, 136*93a686eeSJean-Christophe PLAGNIOL-VILLARD * but do not allocate any windows since any BAR found (such 137*93a686eeSJean-Christophe PLAGNIOL-VILLARD * as PCSRBAR) is not in this cpu's memory space. 138*93a686eeSJean-Christophe PLAGNIOL-VILLARD */ 139*93a686eeSJean-Christophe PLAGNIOL-VILLARD 140*93a686eeSJean-Christophe PLAGNIOL-VILLARD pciauto_setup_device(hose, dev, 0, hose->pci_mem, 141*93a686eeSJean-Christophe PLAGNIOL-VILLARD hose->pci_prefetch, hose->pci_io); 142*93a686eeSJean-Christophe PLAGNIOL-VILLARD 143*93a686eeSJean-Christophe PLAGNIOL-VILLARD if (inbound) { 144*93a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_read_config_word(hose, dev, PCI_COMMAND, &temp16); 145*93a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_write_config_word(hose, dev, PCI_COMMAND, 146*93a686eeSJean-Christophe PLAGNIOL-VILLARD temp16 | PCI_COMMAND_MEMORY); 147*93a686eeSJean-Christophe PLAGNIOL-VILLARD } 148*93a686eeSJean-Christophe PLAGNIOL-VILLARD 149*93a686eeSJean-Christophe PLAGNIOL-VILLARD #ifndef CONFIG_PCI_NOSCAN 150*93a686eeSJean-Christophe PLAGNIOL-VILLARD printf (" Scanning PCI bus %02x\n", hose->current_busno); 151*93a686eeSJean-Christophe PLAGNIOL-VILLARD hose->last_busno = pci_hose_scan_bus(hose,hose->current_busno); 152*93a686eeSJean-Christophe PLAGNIOL-VILLARD 153*93a686eeSJean-Christophe PLAGNIOL-VILLARD if ( bridge ) { /* update limit regs and subordinate busno */ 154*93a686eeSJean-Christophe PLAGNIOL-VILLARD pciauto_postscan_setup_bridge(hose, dev, hose->last_busno); 155*93a686eeSJean-Christophe PLAGNIOL-VILLARD } 156*93a686eeSJean-Christophe PLAGNIOL-VILLARD #else 157*93a686eeSJean-Christophe PLAGNIOL-VILLARD hose->last_busno = hose->current_busno; 158*93a686eeSJean-Christophe PLAGNIOL-VILLARD #endif 159*93a686eeSJean-Christophe PLAGNIOL-VILLARD 160*93a686eeSJean-Christophe PLAGNIOL-VILLARD /* Clear all error indications */ 161*93a686eeSJean-Christophe PLAGNIOL-VILLARD 162*93a686eeSJean-Christophe PLAGNIOL-VILLARD pci->pme_msg_det = 0xffffffff; 163*93a686eeSJean-Christophe PLAGNIOL-VILLARD pci->pedr = 0xffffffff; 164*93a686eeSJean-Christophe PLAGNIOL-VILLARD 165*93a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_read_config_word (hose, dev, PCI_DSR, &temp16); 166*93a686eeSJean-Christophe PLAGNIOL-VILLARD if (temp16) { 167*93a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_write_config_word(hose, dev, 168*93a686eeSJean-Christophe PLAGNIOL-VILLARD PCI_DSR, 0xffff); 169*93a686eeSJean-Christophe PLAGNIOL-VILLARD } 170*93a686eeSJean-Christophe PLAGNIOL-VILLARD 171*93a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_read_config_word (hose, dev, PCI_SEC_STATUS, &temp16); 172*93a686eeSJean-Christophe PLAGNIOL-VILLARD if (temp16) { 173*93a686eeSJean-Christophe PLAGNIOL-VILLARD pci_hose_write_config_word(hose, dev, PCI_SEC_STATUS, 0xffff); 174*93a686eeSJean-Christophe PLAGNIOL-VILLARD } 175*93a686eeSJean-Christophe PLAGNIOL-VILLARD } 176*93a686eeSJean-Christophe PLAGNIOL-VILLARD 177*93a686eeSJean-Christophe PLAGNIOL-VILLARD #endif /* CONFIG_FSL_PCI */ 178