xref: /rk3399_rockchip-uboot/drivers/pci/fsl_pci_init.c (revision ff4e66e93c1ad47644be3b4ffd6a46e1ce9b6612)
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 
407a897959SPeter Tyser /* Freescale-specific PCI config registers */
417a897959SPeter Tyser #define FSL_PCI_PBFR		0x44
427a897959SPeter Tyser #define FSL_PCIE_CAP_ID		0x4c
437a897959SPeter Tyser #define FSL_PCIE_CFG_RDY	0x4b0
447a897959SPeter Tyser 
4593a686eeSJean-Christophe PLAGNIOL-VILLARD void pciauto_prescan_setup_bridge(struct pci_controller *hose,
4693a686eeSJean-Christophe PLAGNIOL-VILLARD 				pci_dev_t dev, int sub_bus);
4793a686eeSJean-Christophe PLAGNIOL-VILLARD void pciauto_postscan_setup_bridge(struct pci_controller *hose,
4893a686eeSJean-Christophe PLAGNIOL-VILLARD 				pci_dev_t dev, int sub_bus);
4993a686eeSJean-Christophe PLAGNIOL-VILLARD void pciauto_config_init(struct pci_controller *hose);
50612ea010SKumar Gala 
51b9a1fa97SKumar Gala #ifndef CONFIG_SYS_PCI_MEMORY_BUS
52b9a1fa97SKumar Gala #define CONFIG_SYS_PCI_MEMORY_BUS 0
53b9a1fa97SKumar Gala #endif
54b9a1fa97SKumar Gala 
55b9a1fa97SKumar Gala #ifndef CONFIG_SYS_PCI_MEMORY_PHYS
56b9a1fa97SKumar Gala #define CONFIG_SYS_PCI_MEMORY_PHYS 0
57b9a1fa97SKumar Gala #endif
58b9a1fa97SKumar Gala 
59b9a1fa97SKumar Gala #if defined(CONFIG_SYS_PCI_64BIT) && !defined(CONFIG_SYS_PCI64_MEMORY_BUS)
60b9a1fa97SKumar Gala #define CONFIG_SYS_PCI64_MEMORY_BUS (64ull*1024*1024*1024)
61b9a1fa97SKumar Gala #endif
62b9a1fa97SKumar Gala 
63b9a1fa97SKumar Gala int fsl_pci_setup_inbound_windows(struct pci_region *r)
64b9a1fa97SKumar Gala {
65b9a1fa97SKumar Gala 	struct pci_region *rgn_base = r;
6635db1c6dSBecky Bruce 	u64 sz = min((u64)gd->ram_size, (1ull << 32) - 1);
67b9a1fa97SKumar Gala 
68b9a1fa97SKumar Gala 	phys_addr_t phys_start = CONFIG_SYS_PCI_MEMORY_PHYS;
69b9a1fa97SKumar Gala 	pci_addr_t bus_start = CONFIG_SYS_PCI_MEMORY_BUS;
70b9a1fa97SKumar Gala 	pci_size_t pci_sz = 1ull << __ilog2_u64(sz);
71b9a1fa97SKumar Gala 
72b9a1fa97SKumar Gala 	debug ("R0 bus_start: %llx phys_start: %llx size: %llx\n",
73b9a1fa97SKumar Gala 		(u64)bus_start, (u64)phys_start, (u64)pci_sz);
74b9a1fa97SKumar Gala 	pci_set_region(r++, bus_start, phys_start, pci_sz,
75*ff4e66e9SKumar Gala 			PCI_REGION_MEM | PCI_REGION_SYS_MEMORY |
76b9a1fa97SKumar Gala 			PCI_REGION_PREFETCH);
77b9a1fa97SKumar Gala 
78b9a1fa97SKumar Gala 	sz -= pci_sz;
79b9a1fa97SKumar Gala 	bus_start += pci_sz;
80b9a1fa97SKumar Gala 	phys_start += pci_sz;
81b9a1fa97SKumar Gala 
82b9a1fa97SKumar Gala 	pci_sz = 1ull << __ilog2_u64(sz);
83b9a1fa97SKumar Gala 	if (sz) {
84b9a1fa97SKumar Gala 		debug ("R1 bus_start: %llx phys_start: %llx size: %llx\n",
85b9a1fa97SKumar Gala 			(u64)bus_start, (u64)phys_start, (u64)pci_sz);
86b9a1fa97SKumar Gala 		pci_set_region(r++, bus_start, phys_start, pci_sz,
87*ff4e66e9SKumar Gala 				PCI_REGION_MEM | PCI_REGION_SYS_MEMORY |
88b9a1fa97SKumar Gala 				PCI_REGION_PREFETCH);
89b9a1fa97SKumar Gala 		sz -= pci_sz;
90b9a1fa97SKumar Gala 		bus_start += pci_sz;
91b9a1fa97SKumar Gala 		phys_start += pci_sz;
92b9a1fa97SKumar Gala 	}
93b9a1fa97SKumar Gala 
94b9a1fa97SKumar Gala #if defined(CONFIG_PHYS_64BIT) && defined(CONFIG_SYS_PCI_64BIT)
95cd425162SBecky Bruce 	/*
96cd425162SBecky Bruce 	 * On 64-bit capable systems, set up a mapping for all of DRAM
97cd425162SBecky Bruce 	 * in high pci address space.
98cd425162SBecky Bruce 	 */
99b9a1fa97SKumar Gala 	pci_sz = 1ull << __ilog2_u64(gd->ram_size);
100b9a1fa97SKumar Gala 	/* round up to the next largest power of two */
101b9a1fa97SKumar Gala 	if (gd->ram_size > pci_sz)
102cd425162SBecky Bruce 		pci_sz = 1ull << (__ilog2_u64(gd->ram_size) + 1);
103b9a1fa97SKumar Gala 	debug ("R64 bus_start: %llx phys_start: %llx size: %llx\n",
104cd425162SBecky Bruce 		(u64)CONFIG_SYS_PCI64_MEMORY_BUS,
105b9a1fa97SKumar Gala 		(u64)CONFIG_SYS_PCI_MEMORY_PHYS,
106b9a1fa97SKumar Gala 		(u64)pci_sz);
107b9a1fa97SKumar Gala 	pci_set_region(r++,
108cd425162SBecky Bruce 			CONFIG_SYS_PCI64_MEMORY_BUS,
109b9a1fa97SKumar Gala 			CONFIG_SYS_PCI_MEMORY_PHYS,
110b9a1fa97SKumar Gala 			pci_sz,
111*ff4e66e9SKumar Gala 			PCI_REGION_MEM | PCI_REGION_SYS_MEMORY |
112b9a1fa97SKumar Gala 			PCI_REGION_PREFETCH);
113b9a1fa97SKumar Gala #else
114b9a1fa97SKumar Gala 	pci_sz = 1ull << __ilog2_u64(sz);
115b9a1fa97SKumar Gala 	if (sz) {
116b9a1fa97SKumar Gala 		debug ("R2 bus_start: %llx phys_start: %llx size: %llx\n",
117b9a1fa97SKumar Gala 			(u64)bus_start, (u64)phys_start, (u64)pci_sz);
118b9a1fa97SKumar Gala 		pci_set_region(r++, bus_start, phys_start, pci_sz,
119*ff4e66e9SKumar Gala 				PCI_REGION_MEM | PCI_REGION_SYS_MEMORY |
120b9a1fa97SKumar Gala 				PCI_REGION_PREFETCH);
121b9a1fa97SKumar Gala 		sz -= pci_sz;
122b9a1fa97SKumar Gala 		bus_start += pci_sz;
123b9a1fa97SKumar Gala 		phys_start += pci_sz;
124b9a1fa97SKumar Gala 	}
125b9a1fa97SKumar Gala #endif
126b9a1fa97SKumar Gala 
1274c253fdbSKumar Gala #ifdef CONFIG_PHYS_64BIT
128b9a1fa97SKumar Gala 	if (sz && (((u64)gd->ram_size) < (1ull << 32)))
129b9a1fa97SKumar Gala 		printf("Was not able to map all of memory via "
130b9a1fa97SKumar Gala 			"inbound windows -- %lld remaining\n", sz);
1314c253fdbSKumar Gala #endif
132b9a1fa97SKumar Gala 
133b9a1fa97SKumar Gala 	return r - rgn_base;
134b9a1fa97SKumar Gala }
135b9a1fa97SKumar Gala 
136612ea010SKumar Gala void fsl_pci_init(struct pci_controller *hose)
13793a686eeSJean-Christophe PLAGNIOL-VILLARD {
13893a686eeSJean-Christophe PLAGNIOL-VILLARD 	u16 temp16;
13993a686eeSJean-Christophe PLAGNIOL-VILLARD 	u32 temp32;
14093a686eeSJean-Christophe PLAGNIOL-VILLARD 	int busno = hose->first_busno;
14193a686eeSJean-Christophe PLAGNIOL-VILLARD 	int enabled;
14293a686eeSJean-Christophe PLAGNIOL-VILLARD 	u16 ltssm;
14393a686eeSJean-Christophe PLAGNIOL-VILLARD 	u8 temp8;
14493a686eeSJean-Christophe PLAGNIOL-VILLARD 	int r;
14593a686eeSJean-Christophe PLAGNIOL-VILLARD 	int bridge;
14693a686eeSJean-Christophe PLAGNIOL-VILLARD 	int inbound = 0;
14793a686eeSJean-Christophe PLAGNIOL-VILLARD 	volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) hose->cfg_addr;
14893a686eeSJean-Christophe PLAGNIOL-VILLARD 	pci_dev_t dev = PCI_BDF(busno,0,0);
14993a686eeSJean-Christophe PLAGNIOL-VILLARD 
15093a686eeSJean-Christophe PLAGNIOL-VILLARD 	/* Initialize ATMU registers based on hose regions and flags */
15193a686eeSJean-Christophe PLAGNIOL-VILLARD 	volatile pot_t *po = &pci->pot[1];	/* skip 0 */
15293a686eeSJean-Christophe PLAGNIOL-VILLARD 	volatile pit_t *pi = &pci->pit[0];	/* ranges from: 3 to 1 */
15393a686eeSJean-Christophe PLAGNIOL-VILLARD 
15493a686eeSJean-Christophe PLAGNIOL-VILLARD #ifdef DEBUG
15593a686eeSJean-Christophe PLAGNIOL-VILLARD 	int neg_link_w;
15693a686eeSJean-Christophe PLAGNIOL-VILLARD #endif
15793a686eeSJean-Christophe PLAGNIOL-VILLARD 
15893a686eeSJean-Christophe PLAGNIOL-VILLARD 	for (r=0; r<hose->region_count; r++) {
159612ea010SKumar Gala 		u32 sz = (__ilog2_u64((u64)hose->regions[r].size) - 1);
160*ff4e66e9SKumar Gala 		if (hose->regions[r].flags & PCI_REGION_SYS_MEMORY) { /* inbound */
161219542a1SKumar Gala 			u32 flag = PIWAR_EN | PIWAR_LOCAL |
162612ea010SKumar Gala 					PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP;
163612ea010SKumar Gala 			pi->pitar = (hose->regions[r].phys_start >> 12);
164612ea010SKumar Gala 			pi->piwbar = (hose->regions[r].bus_start >> 12);
165612ea010SKumar Gala #ifdef CONFIG_SYS_PCI_64BIT
166612ea010SKumar Gala 			pi->piwbear = (hose->regions[r].bus_start >> 44);
167612ea010SKumar Gala #else
16893a686eeSJean-Christophe PLAGNIOL-VILLARD 			pi->piwbear = 0;
169612ea010SKumar Gala #endif
170612ea010SKumar Gala 			if (hose->regions[r].flags & PCI_REGION_PREFETCH)
171612ea010SKumar Gala 				flag |= PIWAR_PF;
172612ea010SKumar Gala 			pi->piwar = flag | sz;
17393a686eeSJean-Christophe PLAGNIOL-VILLARD 			pi++;
17493a686eeSJean-Christophe PLAGNIOL-VILLARD 			inbound = hose->regions[r].size > 0;
17593a686eeSJean-Christophe PLAGNIOL-VILLARD 		} else { /* Outbound */
176612ea010SKumar Gala 			po->powbar = (hose->regions[r].phys_start >> 12);
177612ea010SKumar Gala 			po->potar = (hose->regions[r].bus_start >> 12);
178612ea010SKumar Gala #ifdef CONFIG_SYS_PCI_64BIT
179612ea010SKumar Gala 			po->potear = (hose->regions[r].bus_start >> 44);
180612ea010SKumar Gala #else
18193a686eeSJean-Christophe PLAGNIOL-VILLARD 			po->potear = 0;
182612ea010SKumar Gala #endif
18393a686eeSJean-Christophe PLAGNIOL-VILLARD 			if (hose->regions[r].flags & PCI_REGION_IO)
184219542a1SKumar Gala 				po->powar = POWAR_EN | sz |
185612ea010SKumar Gala 					POWAR_IO_READ | POWAR_IO_WRITE;
18693a686eeSJean-Christophe PLAGNIOL-VILLARD 			else
187219542a1SKumar Gala 				po->powar = POWAR_EN | sz |
188612ea010SKumar Gala 					POWAR_MEM_READ | POWAR_MEM_WRITE;
18993a686eeSJean-Christophe PLAGNIOL-VILLARD 			po++;
19093a686eeSJean-Christophe PLAGNIOL-VILLARD 		}
19193a686eeSJean-Christophe PLAGNIOL-VILLARD 	}
19293a686eeSJean-Christophe PLAGNIOL-VILLARD 
19393a686eeSJean-Christophe PLAGNIOL-VILLARD 	pci_register_hose(hose);
19493a686eeSJean-Christophe PLAGNIOL-VILLARD 	pciauto_config_init(hose);	/* grab pci_{mem,prefetch,io} */
19593a686eeSJean-Christophe PLAGNIOL-VILLARD 	hose->current_busno = hose->first_busno;
19693a686eeSJean-Christophe PLAGNIOL-VILLARD 
19793a686eeSJean-Christophe PLAGNIOL-VILLARD 	pci->pedr = 0xffffffff;		/* Clear any errors */
19893a686eeSJean-Christophe PLAGNIOL-VILLARD 	pci->peer = ~0x20140;		/* Enable All Error Interupts except
19993a686eeSJean-Christophe PLAGNIOL-VILLARD 					 * - Master abort (pci)
20093a686eeSJean-Christophe PLAGNIOL-VILLARD 					 * - Master PERR (pci)
20193a686eeSJean-Christophe PLAGNIOL-VILLARD 					 * - ICCA (PCIe)
20293a686eeSJean-Christophe PLAGNIOL-VILLARD 					 */
20393a686eeSJean-Christophe PLAGNIOL-VILLARD 	pci_hose_read_config_dword (hose, dev, PCI_DCR, &temp32);
20493a686eeSJean-Christophe PLAGNIOL-VILLARD 	temp32 |= 0xf000e;		/* set URR, FER, NFER (but not CER) */
20593a686eeSJean-Christophe PLAGNIOL-VILLARD 	pci_hose_write_config_dword(hose, dev, PCI_DCR, temp32);
20693a686eeSJean-Christophe PLAGNIOL-VILLARD 
20793a686eeSJean-Christophe PLAGNIOL-VILLARD 	pci_hose_read_config_byte (hose, dev, PCI_HEADER_TYPE, &temp8);
20893a686eeSJean-Christophe PLAGNIOL-VILLARD 	bridge = temp8 & PCI_HEADER_TYPE_BRIDGE; /* Bridge, such as pcie */
20993a686eeSJean-Christophe PLAGNIOL-VILLARD 
21093a686eeSJean-Christophe PLAGNIOL-VILLARD 	if ( bridge ) {
21193a686eeSJean-Christophe PLAGNIOL-VILLARD 
21293a686eeSJean-Christophe PLAGNIOL-VILLARD 		pci_hose_read_config_word(hose, dev, PCI_LTSSM, &ltssm);
21393a686eeSJean-Christophe PLAGNIOL-VILLARD 		enabled = ltssm >= PCI_LTSSM_L0;
21493a686eeSJean-Christophe PLAGNIOL-VILLARD 
2158ff3de61SKumar Gala #ifdef CONFIG_FSL_PCIE_RESET
2168ff3de61SKumar Gala 		if (ltssm == 1) {
2178ff3de61SKumar Gala 			int i;
2188ff3de61SKumar Gala 			debug("....PCIe link error. "
2198ff3de61SKumar Gala 			      "LTSSM=0x%02x.", ltssm);
2208ff3de61SKumar Gala 			pci->pdb_stat |= 0x08000000; /* assert PCIe reset */
2218ff3de61SKumar Gala 			temp32 = pci->pdb_stat;
2228ff3de61SKumar Gala 			udelay(100);
2238ff3de61SKumar Gala 			debug("  Asserting PCIe reset @%x = %x\n",
2248ff3de61SKumar Gala 			      &pci->pdb_stat, pci->pdb_stat);
2258ff3de61SKumar Gala 			pci->pdb_stat &= ~0x08000000; /* clear reset */
2268ff3de61SKumar Gala 			asm("sync;isync");
2278ff3de61SKumar Gala 			for (i=0; i<100 && ltssm < PCI_LTSSM_L0; i++) {
2288ff3de61SKumar Gala 				pci_hose_read_config_word(hose, dev, PCI_LTSSM,
2298ff3de61SKumar Gala 							&ltssm);
2308ff3de61SKumar Gala 				udelay(1000);
2318ff3de61SKumar Gala 				debug("....PCIe link error. "
2328ff3de61SKumar Gala 				      "LTSSM=0x%02x.\n", ltssm);
2338ff3de61SKumar Gala 			}
2348ff3de61SKumar Gala 			enabled = ltssm >= PCI_LTSSM_L0;
2358ff3de61SKumar Gala 		}
2368ff3de61SKumar Gala #endif
2378ff3de61SKumar Gala 
23893a686eeSJean-Christophe PLAGNIOL-VILLARD 		if (!enabled) {
23993a686eeSJean-Christophe PLAGNIOL-VILLARD 			debug("....PCIE link error.  Skipping scan."
24093a686eeSJean-Christophe PLAGNIOL-VILLARD 			      "LTSSM=0x%02x\n", ltssm);
24193a686eeSJean-Christophe PLAGNIOL-VILLARD 			hose->last_busno = hose->first_busno;
24293a686eeSJean-Christophe PLAGNIOL-VILLARD 			return;
24393a686eeSJean-Christophe PLAGNIOL-VILLARD 		}
24493a686eeSJean-Christophe PLAGNIOL-VILLARD 
24593a686eeSJean-Christophe PLAGNIOL-VILLARD 		pci->pme_msg_det = 0xffffffff;
24693a686eeSJean-Christophe PLAGNIOL-VILLARD 		pci->pme_msg_int_en = 0xffffffff;
24793a686eeSJean-Christophe PLAGNIOL-VILLARD #ifdef DEBUG
24893a686eeSJean-Christophe PLAGNIOL-VILLARD 		pci_hose_read_config_word(hose, dev, PCI_LSR, &temp16);
24993a686eeSJean-Christophe PLAGNIOL-VILLARD 		neg_link_w = (temp16 & 0x3f0 ) >> 4;
25093a686eeSJean-Christophe PLAGNIOL-VILLARD 		printf("...PCIE LTSSM=0x%x, Negotiated link width=%d\n",
25193a686eeSJean-Christophe PLAGNIOL-VILLARD 		      ltssm, neg_link_w);
25293a686eeSJean-Christophe PLAGNIOL-VILLARD #endif
25393a686eeSJean-Christophe PLAGNIOL-VILLARD 		hose->current_busno++; /* Start scan with secondary */
25493a686eeSJean-Christophe PLAGNIOL-VILLARD 		pciauto_prescan_setup_bridge(hose, dev, hose->current_busno);
25593a686eeSJean-Christophe PLAGNIOL-VILLARD 
25693a686eeSJean-Christophe PLAGNIOL-VILLARD 	}
25793a686eeSJean-Christophe PLAGNIOL-VILLARD 
25893a686eeSJean-Christophe PLAGNIOL-VILLARD 	/* Use generic setup_device to initialize standard pci regs,
25993a686eeSJean-Christophe PLAGNIOL-VILLARD 	 * but do not allocate any windows since any BAR found (such
26093a686eeSJean-Christophe PLAGNIOL-VILLARD 	 * as PCSRBAR) is not in this cpu's memory space.
26193a686eeSJean-Christophe PLAGNIOL-VILLARD 	 */
26293a686eeSJean-Christophe PLAGNIOL-VILLARD 
26393a686eeSJean-Christophe PLAGNIOL-VILLARD 	pciauto_setup_device(hose, dev, 0, hose->pci_mem,
26493a686eeSJean-Christophe PLAGNIOL-VILLARD 			     hose->pci_prefetch, hose->pci_io);
26593a686eeSJean-Christophe PLAGNIOL-VILLARD 
26693a686eeSJean-Christophe PLAGNIOL-VILLARD 	if (inbound) {
26793a686eeSJean-Christophe PLAGNIOL-VILLARD 		pci_hose_read_config_word(hose, dev, PCI_COMMAND, &temp16);
26893a686eeSJean-Christophe PLAGNIOL-VILLARD 		pci_hose_write_config_word(hose, dev, PCI_COMMAND,
26993a686eeSJean-Christophe PLAGNIOL-VILLARD 					   temp16 | PCI_COMMAND_MEMORY);
27093a686eeSJean-Christophe PLAGNIOL-VILLARD 	}
27193a686eeSJean-Christophe PLAGNIOL-VILLARD 
27293a686eeSJean-Christophe PLAGNIOL-VILLARD #ifndef CONFIG_PCI_NOSCAN
2736df0efd5SEd Swarthout 	pci_hose_read_config_byte(hose, dev, PCI_CLASS_PROG, &temp8);
2746df0efd5SEd Swarthout 
2756df0efd5SEd Swarthout 	/* Programming Interface (PCI_CLASS_PROG)
2766df0efd5SEd Swarthout 	 * 0 == pci host or pcie root-complex,
2776df0efd5SEd Swarthout 	 * 1 == pci agent or pcie end-point
2786df0efd5SEd Swarthout 	 */
2796df0efd5SEd Swarthout 	if (!temp8) {
2806df0efd5SEd Swarthout 		printf("               Scanning PCI bus %02x\n",
2816df0efd5SEd Swarthout 			hose->current_busno);
28293a686eeSJean-Christophe PLAGNIOL-VILLARD 		hose->last_busno = pci_hose_scan_bus(hose, hose->current_busno);
2836df0efd5SEd Swarthout 	} else {
2846df0efd5SEd Swarthout 		debug("               Not scanning PCI bus %02x. PI=%x\n",
2856df0efd5SEd Swarthout 			hose->current_busno, temp8);
2866df0efd5SEd Swarthout 		hose->last_busno = hose->current_busno;
2876df0efd5SEd Swarthout 	}
28893a686eeSJean-Christophe PLAGNIOL-VILLARD 
28993a686eeSJean-Christophe PLAGNIOL-VILLARD 	if ( bridge ) { /* update limit regs and subordinate busno */
29093a686eeSJean-Christophe PLAGNIOL-VILLARD 		pciauto_postscan_setup_bridge(hose, dev, hose->last_busno);
29193a686eeSJean-Christophe PLAGNIOL-VILLARD 	}
29293a686eeSJean-Christophe PLAGNIOL-VILLARD #else
29393a686eeSJean-Christophe PLAGNIOL-VILLARD 	hose->last_busno = hose->current_busno;
29493a686eeSJean-Christophe PLAGNIOL-VILLARD #endif
29593a686eeSJean-Christophe PLAGNIOL-VILLARD 
29693a686eeSJean-Christophe PLAGNIOL-VILLARD 	/* Clear all error indications */
29793a686eeSJean-Christophe PLAGNIOL-VILLARD 
298876b8f97SKumar Gala 	if (bridge)
29993a686eeSJean-Christophe PLAGNIOL-VILLARD 		pci->pme_msg_det = 0xffffffff;
30093a686eeSJean-Christophe PLAGNIOL-VILLARD 	pci->pedr = 0xffffffff;
30193a686eeSJean-Christophe PLAGNIOL-VILLARD 
30293a686eeSJean-Christophe PLAGNIOL-VILLARD 	pci_hose_read_config_word (hose, dev, PCI_DSR, &temp16);
30393a686eeSJean-Christophe PLAGNIOL-VILLARD 	if (temp16) {
30493a686eeSJean-Christophe PLAGNIOL-VILLARD 		pci_hose_write_config_word(hose, dev,
30593a686eeSJean-Christophe PLAGNIOL-VILLARD 					PCI_DSR, 0xffff);
30693a686eeSJean-Christophe PLAGNIOL-VILLARD 	}
30793a686eeSJean-Christophe PLAGNIOL-VILLARD 
30893a686eeSJean-Christophe PLAGNIOL-VILLARD 	pci_hose_read_config_word (hose, dev, PCI_SEC_STATUS, &temp16);
30993a686eeSJean-Christophe PLAGNIOL-VILLARD 	if (temp16) {
31093a686eeSJean-Christophe PLAGNIOL-VILLARD 		pci_hose_write_config_word(hose, dev, PCI_SEC_STATUS, 0xffff);
31193a686eeSJean-Christophe PLAGNIOL-VILLARD 	}
31293a686eeSJean-Christophe PLAGNIOL-VILLARD }
313a2aab460SKumar Gala 
3147a897959SPeter Tyser /* Enable inbound PCI config cycles for agent/endpoint interface */
3157a897959SPeter Tyser void fsl_pci_config_unlock(struct pci_controller *hose)
3167a897959SPeter Tyser {
3177a897959SPeter Tyser 	pci_dev_t dev = PCI_BDF(hose->first_busno,0,0);
3187a897959SPeter Tyser 	u8 agent;
3197a897959SPeter Tyser 	u8 pcie_cap;
3207a897959SPeter Tyser 	u16 pbfr;
3217a897959SPeter Tyser 
3227a897959SPeter Tyser 	pci_hose_read_config_byte(hose, dev, PCI_CLASS_PROG, &agent);
3237a897959SPeter Tyser 	if (!agent)
3247a897959SPeter Tyser 		return;
3257a897959SPeter Tyser 
3267a897959SPeter Tyser 	pci_hose_read_config_byte(hose, dev, FSL_PCIE_CAP_ID, &pcie_cap);
3277a897959SPeter Tyser 	if (pcie_cap != 0x0) {
3287a897959SPeter Tyser 		/* PCIe - set CFG_READY bit of Configuration Ready Register */
3297a897959SPeter Tyser 		pci_hose_write_config_byte(hose, dev, FSL_PCIE_CFG_RDY, 0x1);
3307a897959SPeter Tyser 	} else {
3317a897959SPeter Tyser 		/* PCI - clear ACL bit of PBFR */
3327a897959SPeter Tyser 		pci_hose_read_config_word(hose, dev, FSL_PCI_PBFR, &pbfr);
3337a897959SPeter Tyser 		pbfr &= ~0x20;
3347a897959SPeter Tyser 		pci_hose_write_config_word(hose, dev, FSL_PCI_PBFR, pbfr);
3357a897959SPeter Tyser 	}
3367a897959SPeter Tyser }
3377a897959SPeter Tyser 
338a2aab460SKumar Gala #ifdef CONFIG_OF_BOARD_SETUP
339a2aab460SKumar Gala #include <libfdt.h>
340a2aab460SKumar Gala #include <fdt_support.h>
341a2aab460SKumar Gala 
342a2aab460SKumar Gala void ft_fsl_pci_setup(void *blob, const char *pci_alias,
343a2aab460SKumar Gala 			struct pci_controller *hose)
344a2aab460SKumar Gala {
345a2aab460SKumar Gala 	int off = fdt_path_offset(blob, pci_alias);
346a2aab460SKumar Gala 
347a2aab460SKumar Gala 	if (off >= 0) {
348a2aab460SKumar Gala 		u32 bus_range[2];
349a2aab460SKumar Gala 
350a2aab460SKumar Gala 		bus_range[0] = 0;
351a2aab460SKumar Gala 		bus_range[1] = hose->last_busno - hose->first_busno;
352a2aab460SKumar Gala 		fdt_setprop(blob, off, "bus-range", &bus_range[0], 2*4);
353a2aab460SKumar Gala 		fdt_pci_dma_ranges(blob, off, hose);
354a2aab460SKumar Gala 	}
355a2aab460SKumar Gala }
356a2aab460SKumar Gala #endif
357