xref: /rk3399_rockchip-uboot/drivers/pci/fsl_pci_init.c (revision 35db1c6d34b57ae15e99cf03c8e8f8a6148d74f3)
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 
21b9a1fa97SKumar Gala DECLARE_GLOBAL_DATA_PTR;
22b9a1fa97SKumar Gala 
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 void pciauto_config_init(struct pci_controller *hose);
45612ea010SKumar Gala 
46b9a1fa97SKumar Gala #ifndef CONFIG_SYS_PCI_MEMORY_BUS
47b9a1fa97SKumar Gala #define CONFIG_SYS_PCI_MEMORY_BUS 0
48b9a1fa97SKumar Gala #endif
49b9a1fa97SKumar Gala 
50b9a1fa97SKumar Gala #ifndef CONFIG_SYS_PCI_MEMORY_PHYS
51b9a1fa97SKumar Gala #define CONFIG_SYS_PCI_MEMORY_PHYS 0
52b9a1fa97SKumar Gala #endif
53b9a1fa97SKumar Gala 
54b9a1fa97SKumar Gala #if defined(CONFIG_SYS_PCI_64BIT) && !defined(CONFIG_SYS_PCI64_MEMORY_BUS)
55b9a1fa97SKumar Gala #define CONFIG_SYS_PCI64_MEMORY_BUS (64ull*1024*1024*1024)
56b9a1fa97SKumar Gala #endif
57b9a1fa97SKumar Gala 
58b9a1fa97SKumar Gala int fsl_pci_setup_inbound_windows(struct pci_region *r)
59b9a1fa97SKumar Gala {
60b9a1fa97SKumar Gala 	struct pci_region *rgn_base = r;
61*35db1c6dSBecky Bruce 	u64 sz = min((u64)gd->ram_size, (1ull << 32) - 1);
62b9a1fa97SKumar Gala 
63b9a1fa97SKumar Gala 	phys_addr_t phys_start = CONFIG_SYS_PCI_MEMORY_PHYS;
64b9a1fa97SKumar Gala 	pci_addr_t bus_start = CONFIG_SYS_PCI_MEMORY_BUS;
65b9a1fa97SKumar Gala 	pci_size_t pci_sz = 1ull << __ilog2_u64(sz);
66b9a1fa97SKumar Gala 
67b9a1fa97SKumar Gala 	debug ("R0 bus_start: %llx phys_start: %llx size: %llx\n",
68b9a1fa97SKumar Gala 		(u64)bus_start, (u64)phys_start, (u64)pci_sz);
69b9a1fa97SKumar Gala 	pci_set_region(r++, bus_start, phys_start, pci_sz,
70219542a1SKumar Gala 			PCI_REGION_MEM | PCI_REGION_MEMORY |
71b9a1fa97SKumar Gala 			PCI_REGION_PREFETCH);
72b9a1fa97SKumar Gala 
73b9a1fa97SKumar Gala 	sz -= pci_sz;
74b9a1fa97SKumar Gala 	bus_start += pci_sz;
75b9a1fa97SKumar Gala 	phys_start += pci_sz;
76b9a1fa97SKumar Gala 
77b9a1fa97SKumar Gala 	pci_sz = 1ull << __ilog2_u64(sz);
78b9a1fa97SKumar Gala 	if (sz) {
79b9a1fa97SKumar Gala 		debug ("R1 bus_start: %llx phys_start: %llx size: %llx\n",
80b9a1fa97SKumar Gala 			(u64)bus_start, (u64)phys_start, (u64)pci_sz);
81b9a1fa97SKumar Gala 		pci_set_region(r++, bus_start, phys_start, pci_sz,
82219542a1SKumar Gala 				PCI_REGION_MEM | PCI_REGION_MEMORY |
83b9a1fa97SKumar Gala 				PCI_REGION_PREFETCH);
84b9a1fa97SKumar Gala 		sz -= pci_sz;
85b9a1fa97SKumar Gala 		bus_start += pci_sz;
86b9a1fa97SKumar Gala 		phys_start += pci_sz;
87b9a1fa97SKumar Gala 	}
88b9a1fa97SKumar Gala 
89b9a1fa97SKumar Gala #if defined(CONFIG_PHYS_64BIT) && defined(CONFIG_SYS_PCI_64BIT)
90cd425162SBecky Bruce 	/*
91cd425162SBecky Bruce 	 * On 64-bit capable systems, set up a mapping for all of DRAM
92cd425162SBecky Bruce 	 * in high pci address space.
93cd425162SBecky Bruce 	 */
94b9a1fa97SKumar Gala 	pci_sz = 1ull << __ilog2_u64(gd->ram_size);
95b9a1fa97SKumar Gala 	/* round up to the next largest power of two */
96b9a1fa97SKumar Gala 	if (gd->ram_size > pci_sz)
97cd425162SBecky Bruce 		pci_sz = 1ull << (__ilog2_u64(gd->ram_size) + 1);
98b9a1fa97SKumar Gala 	debug ("R64 bus_start: %llx phys_start: %llx size: %llx\n",
99cd425162SBecky Bruce 		(u64)CONFIG_SYS_PCI64_MEMORY_BUS,
100b9a1fa97SKumar Gala 		(u64)CONFIG_SYS_PCI_MEMORY_PHYS,
101b9a1fa97SKumar Gala 		(u64)pci_sz);
102b9a1fa97SKumar Gala 	pci_set_region(r++,
103cd425162SBecky Bruce 			CONFIG_SYS_PCI64_MEMORY_BUS,
104b9a1fa97SKumar Gala 			CONFIG_SYS_PCI_MEMORY_PHYS,
105b9a1fa97SKumar Gala 			pci_sz,
106219542a1SKumar Gala 			PCI_REGION_MEM | PCI_REGION_MEMORY |
107b9a1fa97SKumar Gala 			PCI_REGION_PREFETCH);
108b9a1fa97SKumar Gala #else
109b9a1fa97SKumar Gala 	pci_sz = 1ull << __ilog2_u64(sz);
110b9a1fa97SKumar Gala 	if (sz) {
111b9a1fa97SKumar Gala 		debug ("R2 bus_start: %llx phys_start: %llx size: %llx\n",
112b9a1fa97SKumar Gala 			(u64)bus_start, (u64)phys_start, (u64)pci_sz);
113b9a1fa97SKumar Gala 		pci_set_region(r++, bus_start, phys_start, pci_sz,
114219542a1SKumar Gala 				PCI_REGION_MEM | PCI_REGION_MEMORY |
115b9a1fa97SKumar Gala 				PCI_REGION_PREFETCH);
116b9a1fa97SKumar Gala 		sz -= pci_sz;
117b9a1fa97SKumar Gala 		bus_start += pci_sz;
118b9a1fa97SKumar Gala 		phys_start += pci_sz;
119b9a1fa97SKumar Gala 	}
120b9a1fa97SKumar Gala #endif
121b9a1fa97SKumar Gala 
122b9a1fa97SKumar Gala 	if (sz && (((u64)gd->ram_size) < (1ull << 32)))
123b9a1fa97SKumar Gala 		printf("Was not able to map all of memory via "
124b9a1fa97SKumar Gala 			"inbound windows -- %lld remaining\n", sz);
125b9a1fa97SKumar Gala 
126b9a1fa97SKumar Gala 	return r - rgn_base;
127b9a1fa97SKumar Gala }
128b9a1fa97SKumar Gala 
129612ea010SKumar Gala void fsl_pci_init(struct pci_controller *hose)
13093a686eeSJean-Christophe PLAGNIOL-VILLARD {
13193a686eeSJean-Christophe PLAGNIOL-VILLARD 	u16 temp16;
13293a686eeSJean-Christophe PLAGNIOL-VILLARD 	u32 temp32;
13393a686eeSJean-Christophe PLAGNIOL-VILLARD 	int busno = hose->first_busno;
13493a686eeSJean-Christophe PLAGNIOL-VILLARD 	int enabled;
13593a686eeSJean-Christophe PLAGNIOL-VILLARD 	u16 ltssm;
13693a686eeSJean-Christophe PLAGNIOL-VILLARD 	u8 temp8;
13793a686eeSJean-Christophe PLAGNIOL-VILLARD 	int r;
13893a686eeSJean-Christophe PLAGNIOL-VILLARD 	int bridge;
13993a686eeSJean-Christophe PLAGNIOL-VILLARD 	int inbound = 0;
14093a686eeSJean-Christophe PLAGNIOL-VILLARD 	volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) hose->cfg_addr;
14193a686eeSJean-Christophe PLAGNIOL-VILLARD 	pci_dev_t dev = PCI_BDF(busno,0,0);
14293a686eeSJean-Christophe PLAGNIOL-VILLARD 
14393a686eeSJean-Christophe PLAGNIOL-VILLARD 	/* Initialize ATMU registers based on hose regions and flags */
14493a686eeSJean-Christophe PLAGNIOL-VILLARD 	volatile pot_t *po = &pci->pot[1];	/* skip 0 */
14593a686eeSJean-Christophe PLAGNIOL-VILLARD 	volatile pit_t *pi = &pci->pit[0];	/* ranges from: 3 to 1 */
14693a686eeSJean-Christophe PLAGNIOL-VILLARD 
14793a686eeSJean-Christophe PLAGNIOL-VILLARD #ifdef DEBUG
14893a686eeSJean-Christophe PLAGNIOL-VILLARD 	int neg_link_w;
14993a686eeSJean-Christophe PLAGNIOL-VILLARD #endif
15093a686eeSJean-Christophe PLAGNIOL-VILLARD 
15193a686eeSJean-Christophe PLAGNIOL-VILLARD 	for (r=0; r<hose->region_count; r++) {
152612ea010SKumar Gala 		u32 sz = (__ilog2_u64((u64)hose->regions[r].size) - 1);
15393a686eeSJean-Christophe PLAGNIOL-VILLARD 		if (hose->regions[r].flags & PCI_REGION_MEMORY) { /* inbound */
154219542a1SKumar Gala 			u32 flag = PIWAR_EN | PIWAR_LOCAL |
155612ea010SKumar Gala 					PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP;
156612ea010SKumar Gala 			pi->pitar = (hose->regions[r].phys_start >> 12);
157612ea010SKumar Gala 			pi->piwbar = (hose->regions[r].bus_start >> 12);
158612ea010SKumar Gala #ifdef CONFIG_SYS_PCI_64BIT
159612ea010SKumar Gala 			pi->piwbear = (hose->regions[r].bus_start >> 44);
160612ea010SKumar Gala #else
16193a686eeSJean-Christophe PLAGNIOL-VILLARD 			pi->piwbear = 0;
162612ea010SKumar Gala #endif
163612ea010SKumar Gala 			if (hose->regions[r].flags & PCI_REGION_PREFETCH)
164612ea010SKumar Gala 				flag |= PIWAR_PF;
165612ea010SKumar Gala 			pi->piwar = flag | sz;
16693a686eeSJean-Christophe PLAGNIOL-VILLARD 			pi++;
16793a686eeSJean-Christophe PLAGNIOL-VILLARD 			inbound = hose->regions[r].size > 0;
16893a686eeSJean-Christophe PLAGNIOL-VILLARD 		} else { /* Outbound */
169612ea010SKumar Gala 			po->powbar = (hose->regions[r].phys_start >> 12);
170612ea010SKumar Gala 			po->potar = (hose->regions[r].bus_start >> 12);
171612ea010SKumar Gala #ifdef CONFIG_SYS_PCI_64BIT
172612ea010SKumar Gala 			po->potear = (hose->regions[r].bus_start >> 44);
173612ea010SKumar Gala #else
17493a686eeSJean-Christophe PLAGNIOL-VILLARD 			po->potear = 0;
175612ea010SKumar Gala #endif
17693a686eeSJean-Christophe PLAGNIOL-VILLARD 			if (hose->regions[r].flags & PCI_REGION_IO)
177219542a1SKumar Gala 				po->powar = POWAR_EN | sz |
178612ea010SKumar Gala 					POWAR_IO_READ | POWAR_IO_WRITE;
17993a686eeSJean-Christophe PLAGNIOL-VILLARD 			else
180219542a1SKumar Gala 				po->powar = POWAR_EN | sz |
181612ea010SKumar Gala 					POWAR_MEM_READ | POWAR_MEM_WRITE;
18293a686eeSJean-Christophe PLAGNIOL-VILLARD 			po++;
18393a686eeSJean-Christophe PLAGNIOL-VILLARD 		}
18493a686eeSJean-Christophe PLAGNIOL-VILLARD 	}
18593a686eeSJean-Christophe PLAGNIOL-VILLARD 
18693a686eeSJean-Christophe PLAGNIOL-VILLARD 	pci_register_hose(hose);
18793a686eeSJean-Christophe PLAGNIOL-VILLARD 	pciauto_config_init(hose);	/* grab pci_{mem,prefetch,io} */
18893a686eeSJean-Christophe PLAGNIOL-VILLARD 	hose->current_busno = hose->first_busno;
18993a686eeSJean-Christophe PLAGNIOL-VILLARD 
19093a686eeSJean-Christophe PLAGNIOL-VILLARD 	pci->pedr = 0xffffffff;		/* Clear any errors */
19193a686eeSJean-Christophe PLAGNIOL-VILLARD 	pci->peer = ~0x20140;		/* Enable All Error Interupts except
19293a686eeSJean-Christophe PLAGNIOL-VILLARD 					 * - Master abort (pci)
19393a686eeSJean-Christophe PLAGNIOL-VILLARD 					 * - Master PERR (pci)
19493a686eeSJean-Christophe PLAGNIOL-VILLARD 					 * - ICCA (PCIe)
19593a686eeSJean-Christophe PLAGNIOL-VILLARD 					 */
19693a686eeSJean-Christophe PLAGNIOL-VILLARD 	pci_hose_read_config_dword (hose, dev, PCI_DCR, &temp32);
19793a686eeSJean-Christophe PLAGNIOL-VILLARD 	temp32 |= 0xf000e;		/* set URR, FER, NFER (but not CER) */
19893a686eeSJean-Christophe PLAGNIOL-VILLARD 	pci_hose_write_config_dword(hose, dev, PCI_DCR, temp32);
19993a686eeSJean-Christophe PLAGNIOL-VILLARD 
20093a686eeSJean-Christophe PLAGNIOL-VILLARD 	pci_hose_read_config_byte (hose, dev, PCI_HEADER_TYPE, &temp8);
20193a686eeSJean-Christophe PLAGNIOL-VILLARD 	bridge = temp8 & PCI_HEADER_TYPE_BRIDGE; /* Bridge, such as pcie */
20293a686eeSJean-Christophe PLAGNIOL-VILLARD 
20393a686eeSJean-Christophe PLAGNIOL-VILLARD 	if ( bridge ) {
20493a686eeSJean-Christophe PLAGNIOL-VILLARD 
20593a686eeSJean-Christophe PLAGNIOL-VILLARD 		pci_hose_read_config_word(hose, dev, PCI_LTSSM, &ltssm);
20693a686eeSJean-Christophe PLAGNIOL-VILLARD 		enabled = ltssm >= PCI_LTSSM_L0;
20793a686eeSJean-Christophe PLAGNIOL-VILLARD 
2088ff3de61SKumar Gala #ifdef CONFIG_FSL_PCIE_RESET
2098ff3de61SKumar Gala 		if (ltssm == 1) {
2108ff3de61SKumar Gala 			int i;
2118ff3de61SKumar Gala 			debug("....PCIe link error. "
2128ff3de61SKumar Gala 			      "LTSSM=0x%02x.", ltssm);
2138ff3de61SKumar Gala 			pci->pdb_stat |= 0x08000000; /* assert PCIe reset */
2148ff3de61SKumar Gala 			temp32 = pci->pdb_stat;
2158ff3de61SKumar Gala 			udelay(100);
2168ff3de61SKumar Gala 			debug("  Asserting PCIe reset @%x = %x\n",
2178ff3de61SKumar Gala 			      &pci->pdb_stat, pci->pdb_stat);
2188ff3de61SKumar Gala 			pci->pdb_stat &= ~0x08000000; /* clear reset */
2198ff3de61SKumar Gala 			asm("sync;isync");
2208ff3de61SKumar Gala 			for (i=0; i<100 && ltssm < PCI_LTSSM_L0; i++) {
2218ff3de61SKumar Gala 				pci_hose_read_config_word(hose, dev, PCI_LTSSM,
2228ff3de61SKumar Gala 							&ltssm);
2238ff3de61SKumar Gala 				udelay(1000);
2248ff3de61SKumar Gala 				debug("....PCIe link error. "
2258ff3de61SKumar Gala 				      "LTSSM=0x%02x.\n", ltssm);
2268ff3de61SKumar Gala 			}
2278ff3de61SKumar Gala 			enabled = ltssm >= PCI_LTSSM_L0;
2288ff3de61SKumar Gala 		}
2298ff3de61SKumar Gala #endif
2308ff3de61SKumar Gala 
23193a686eeSJean-Christophe PLAGNIOL-VILLARD 		if (!enabled) {
23293a686eeSJean-Christophe PLAGNIOL-VILLARD 			debug("....PCIE link error.  Skipping scan."
23393a686eeSJean-Christophe PLAGNIOL-VILLARD 			      "LTSSM=0x%02x\n", ltssm);
23493a686eeSJean-Christophe PLAGNIOL-VILLARD 			hose->last_busno = hose->first_busno;
23593a686eeSJean-Christophe PLAGNIOL-VILLARD 			return;
23693a686eeSJean-Christophe PLAGNIOL-VILLARD 		}
23793a686eeSJean-Christophe PLAGNIOL-VILLARD 
23893a686eeSJean-Christophe PLAGNIOL-VILLARD 		pci->pme_msg_det = 0xffffffff;
23993a686eeSJean-Christophe PLAGNIOL-VILLARD 		pci->pme_msg_int_en = 0xffffffff;
24093a686eeSJean-Christophe PLAGNIOL-VILLARD #ifdef DEBUG
24193a686eeSJean-Christophe PLAGNIOL-VILLARD 		pci_hose_read_config_word(hose, dev, PCI_LSR, &temp16);
24293a686eeSJean-Christophe PLAGNIOL-VILLARD 		neg_link_w = (temp16 & 0x3f0 ) >> 4;
24393a686eeSJean-Christophe PLAGNIOL-VILLARD 		printf("...PCIE LTSSM=0x%x, Negotiated link width=%d\n",
24493a686eeSJean-Christophe PLAGNIOL-VILLARD 		      ltssm, neg_link_w);
24593a686eeSJean-Christophe PLAGNIOL-VILLARD #endif
24693a686eeSJean-Christophe PLAGNIOL-VILLARD 		hose->current_busno++; /* Start scan with secondary */
24793a686eeSJean-Christophe PLAGNIOL-VILLARD 		pciauto_prescan_setup_bridge(hose, dev, hose->current_busno);
24893a686eeSJean-Christophe PLAGNIOL-VILLARD 
24993a686eeSJean-Christophe PLAGNIOL-VILLARD 	}
25093a686eeSJean-Christophe PLAGNIOL-VILLARD 
25193a686eeSJean-Christophe PLAGNIOL-VILLARD 	/* Use generic setup_device to initialize standard pci regs,
25293a686eeSJean-Christophe PLAGNIOL-VILLARD 	 * but do not allocate any windows since any BAR found (such
25393a686eeSJean-Christophe PLAGNIOL-VILLARD 	 * as PCSRBAR) is not in this cpu's memory space.
25493a686eeSJean-Christophe PLAGNIOL-VILLARD 	 */
25593a686eeSJean-Christophe PLAGNIOL-VILLARD 
25693a686eeSJean-Christophe PLAGNIOL-VILLARD 	pciauto_setup_device(hose, dev, 0, hose->pci_mem,
25793a686eeSJean-Christophe PLAGNIOL-VILLARD 			     hose->pci_prefetch, hose->pci_io);
25893a686eeSJean-Christophe PLAGNIOL-VILLARD 
25993a686eeSJean-Christophe PLAGNIOL-VILLARD 	if (inbound) {
26093a686eeSJean-Christophe PLAGNIOL-VILLARD 		pci_hose_read_config_word(hose, dev, PCI_COMMAND, &temp16);
26193a686eeSJean-Christophe PLAGNIOL-VILLARD 		pci_hose_write_config_word(hose, dev, PCI_COMMAND,
26293a686eeSJean-Christophe PLAGNIOL-VILLARD 					   temp16 | PCI_COMMAND_MEMORY);
26393a686eeSJean-Christophe PLAGNIOL-VILLARD 	}
26493a686eeSJean-Christophe PLAGNIOL-VILLARD 
26593a686eeSJean-Christophe PLAGNIOL-VILLARD #ifndef CONFIG_PCI_NOSCAN
2666df0efd5SEd Swarthout 	pci_hose_read_config_byte(hose, dev, PCI_CLASS_PROG, &temp8);
2676df0efd5SEd Swarthout 
2686df0efd5SEd Swarthout 	/* Programming Interface (PCI_CLASS_PROG)
2696df0efd5SEd Swarthout 	 * 0 == pci host or pcie root-complex,
2706df0efd5SEd Swarthout 	 * 1 == pci agent or pcie end-point
2716df0efd5SEd Swarthout 	 */
2726df0efd5SEd Swarthout 	if (!temp8) {
2736df0efd5SEd Swarthout 		printf("               Scanning PCI bus %02x\n",
2746df0efd5SEd Swarthout 			hose->current_busno);
27593a686eeSJean-Christophe PLAGNIOL-VILLARD 		hose->last_busno = pci_hose_scan_bus(hose, hose->current_busno);
2766df0efd5SEd Swarthout 	} else {
2776df0efd5SEd Swarthout 		debug("               Not scanning PCI bus %02x. PI=%x\n",
2786df0efd5SEd Swarthout 			hose->current_busno, temp8);
2796df0efd5SEd Swarthout 		hose->last_busno = hose->current_busno;
2806df0efd5SEd Swarthout 	}
28193a686eeSJean-Christophe PLAGNIOL-VILLARD 
28293a686eeSJean-Christophe PLAGNIOL-VILLARD 	if ( bridge ) { /* update limit regs and subordinate busno */
28393a686eeSJean-Christophe PLAGNIOL-VILLARD 		pciauto_postscan_setup_bridge(hose, dev, hose->last_busno);
28493a686eeSJean-Christophe PLAGNIOL-VILLARD 	}
28593a686eeSJean-Christophe PLAGNIOL-VILLARD #else
28693a686eeSJean-Christophe PLAGNIOL-VILLARD 	hose->last_busno = hose->current_busno;
28793a686eeSJean-Christophe PLAGNIOL-VILLARD #endif
28893a686eeSJean-Christophe PLAGNIOL-VILLARD 
28993a686eeSJean-Christophe PLAGNIOL-VILLARD 	/* Clear all error indications */
29093a686eeSJean-Christophe PLAGNIOL-VILLARD 
291876b8f97SKumar Gala 	if (bridge)
29293a686eeSJean-Christophe PLAGNIOL-VILLARD 		pci->pme_msg_det = 0xffffffff;
29393a686eeSJean-Christophe PLAGNIOL-VILLARD 	pci->pedr = 0xffffffff;
29493a686eeSJean-Christophe PLAGNIOL-VILLARD 
29593a686eeSJean-Christophe PLAGNIOL-VILLARD 	pci_hose_read_config_word (hose, dev, PCI_DSR, &temp16);
29693a686eeSJean-Christophe PLAGNIOL-VILLARD 	if (temp16) {
29793a686eeSJean-Christophe PLAGNIOL-VILLARD 		pci_hose_write_config_word(hose, dev,
29893a686eeSJean-Christophe PLAGNIOL-VILLARD 					PCI_DSR, 0xffff);
29993a686eeSJean-Christophe PLAGNIOL-VILLARD 	}
30093a686eeSJean-Christophe PLAGNIOL-VILLARD 
30193a686eeSJean-Christophe PLAGNIOL-VILLARD 	pci_hose_read_config_word (hose, dev, PCI_SEC_STATUS, &temp16);
30293a686eeSJean-Christophe PLAGNIOL-VILLARD 	if (temp16) {
30393a686eeSJean-Christophe PLAGNIOL-VILLARD 		pci_hose_write_config_word(hose, dev, PCI_SEC_STATUS, 0xffff);
30493a686eeSJean-Christophe PLAGNIOL-VILLARD 	}
30593a686eeSJean-Christophe PLAGNIOL-VILLARD }
306a2aab460SKumar Gala 
307a2aab460SKumar Gala #ifdef CONFIG_OF_BOARD_SETUP
308a2aab460SKumar Gala #include <libfdt.h>
309a2aab460SKumar Gala #include <fdt_support.h>
310a2aab460SKumar Gala 
311a2aab460SKumar Gala void ft_fsl_pci_setup(void *blob, const char *pci_alias,
312a2aab460SKumar Gala 			struct pci_controller *hose)
313a2aab460SKumar Gala {
314a2aab460SKumar Gala 	int off = fdt_path_offset(blob, pci_alias);
315a2aab460SKumar Gala 
316a2aab460SKumar Gala 	if (off >= 0) {
317a2aab460SKumar Gala 		u32 bus_range[2];
318a2aab460SKumar Gala 
319a2aab460SKumar Gala 		bus_range[0] = 0;
320a2aab460SKumar Gala 		bus_range[1] = hose->last_busno - hose->first_busno;
321a2aab460SKumar Gala 		fdt_setprop(blob, off, "bus-range", &bus_range[0], 2*4);
322a2aab460SKumar Gala 		fdt_pci_dma_ranges(blob, off, hose);
323a2aab460SKumar Gala 	}
324a2aab460SKumar Gala }
325a2aab460SKumar Gala #endif
326