xref: /OK3568_Linux_fs/kernel/arch/mips/pci/pci-bcm63xx.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * This file is subject to the terms and conditions of the GNU General Public
3*4882a593Smuzhiyun  * License.  See the file "COPYING" in the main directory of this archive
4*4882a593Smuzhiyun  * for more details.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <linux/types.h>
10*4882a593Smuzhiyun #include <linux/pci.h>
11*4882a593Smuzhiyun #include <linux/kernel.h>
12*4882a593Smuzhiyun #include <linux/init.h>
13*4882a593Smuzhiyun #include <linux/delay.h>
14*4882a593Smuzhiyun #include <linux/clk.h>
15*4882a593Smuzhiyun #include <asm/bootinfo.h>
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #include <bcm63xx_reset.h>
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #include "pci-bcm63xx.h"
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun /*
22*4882a593Smuzhiyun  * Allow PCI to be disabled at runtime depending on board nvram
23*4882a593Smuzhiyun  * configuration
24*4882a593Smuzhiyun  */
25*4882a593Smuzhiyun int bcm63xx_pci_enabled;
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun static struct resource bcm_pci_mem_resource = {
28*4882a593Smuzhiyun 	.name	= "bcm63xx PCI memory space",
29*4882a593Smuzhiyun 	.start	= BCM_PCI_MEM_BASE_PA,
30*4882a593Smuzhiyun 	.end	= BCM_PCI_MEM_END_PA,
31*4882a593Smuzhiyun 	.flags	= IORESOURCE_MEM
32*4882a593Smuzhiyun };
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun static struct resource bcm_pci_io_resource = {
35*4882a593Smuzhiyun 	.name	= "bcm63xx PCI IO space",
36*4882a593Smuzhiyun 	.start	= BCM_PCI_IO_BASE_PA,
37*4882a593Smuzhiyun #ifdef CONFIG_CARDBUS
38*4882a593Smuzhiyun 	.end	= BCM_PCI_IO_HALF_PA,
39*4882a593Smuzhiyun #else
40*4882a593Smuzhiyun 	.end	= BCM_PCI_IO_END_PA,
41*4882a593Smuzhiyun #endif
42*4882a593Smuzhiyun 	.flags	= IORESOURCE_IO
43*4882a593Smuzhiyun };
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun struct pci_controller bcm63xx_controller = {
46*4882a593Smuzhiyun 	.pci_ops	= &bcm63xx_pci_ops,
47*4882a593Smuzhiyun 	.io_resource	= &bcm_pci_io_resource,
48*4882a593Smuzhiyun 	.mem_resource	= &bcm_pci_mem_resource,
49*4882a593Smuzhiyun };
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun /*
52*4882a593Smuzhiyun  * We handle cardbus  via a fake Cardbus bridge,  memory and io spaces
53*4882a593Smuzhiyun  * have to be  clearly separated from PCI one  since we have different
54*4882a593Smuzhiyun  * memory decoder.
55*4882a593Smuzhiyun  */
56*4882a593Smuzhiyun #ifdef CONFIG_CARDBUS
57*4882a593Smuzhiyun static struct resource bcm_cb_mem_resource = {
58*4882a593Smuzhiyun 	.name	= "bcm63xx Cardbus memory space",
59*4882a593Smuzhiyun 	.start	= BCM_CB_MEM_BASE_PA,
60*4882a593Smuzhiyun 	.end	= BCM_CB_MEM_END_PA,
61*4882a593Smuzhiyun 	.flags	= IORESOURCE_MEM
62*4882a593Smuzhiyun };
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun static struct resource bcm_cb_io_resource = {
65*4882a593Smuzhiyun 	.name	= "bcm63xx Cardbus IO space",
66*4882a593Smuzhiyun 	.start	= BCM_PCI_IO_HALF_PA + 1,
67*4882a593Smuzhiyun 	.end	= BCM_PCI_IO_END_PA,
68*4882a593Smuzhiyun 	.flags	= IORESOURCE_IO
69*4882a593Smuzhiyun };
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun struct pci_controller bcm63xx_cb_controller = {
72*4882a593Smuzhiyun 	.pci_ops	= &bcm63xx_cb_ops,
73*4882a593Smuzhiyun 	.io_resource	= &bcm_cb_io_resource,
74*4882a593Smuzhiyun 	.mem_resource	= &bcm_cb_mem_resource,
75*4882a593Smuzhiyun };
76*4882a593Smuzhiyun #endif
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun static struct resource bcm_pcie_mem_resource = {
79*4882a593Smuzhiyun 	.name	= "bcm63xx PCIe memory space",
80*4882a593Smuzhiyun 	.start	= BCM_PCIE_MEM_BASE_PA,
81*4882a593Smuzhiyun 	.end	= BCM_PCIE_MEM_END_PA,
82*4882a593Smuzhiyun 	.flags	= IORESOURCE_MEM,
83*4882a593Smuzhiyun };
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun static struct resource bcm_pcie_io_resource = {
86*4882a593Smuzhiyun 	.name	= "bcm63xx PCIe IO space",
87*4882a593Smuzhiyun 	.start	= 0,
88*4882a593Smuzhiyun 	.end	= 0,
89*4882a593Smuzhiyun 	.flags	= 0,
90*4882a593Smuzhiyun };
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun struct pci_controller bcm63xx_pcie_controller = {
93*4882a593Smuzhiyun 	.pci_ops	= &bcm63xx_pcie_ops,
94*4882a593Smuzhiyun 	.io_resource	= &bcm_pcie_io_resource,
95*4882a593Smuzhiyun 	.mem_resource	= &bcm_pcie_mem_resource,
96*4882a593Smuzhiyun };
97*4882a593Smuzhiyun 
bcm63xx_int_cfg_readl(u32 reg)98*4882a593Smuzhiyun static u32 bcm63xx_int_cfg_readl(u32 reg)
99*4882a593Smuzhiyun {
100*4882a593Smuzhiyun 	u32 tmp;
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun 	tmp = reg & MPI_PCICFGCTL_CFGADDR_MASK;
103*4882a593Smuzhiyun 	tmp |= MPI_PCICFGCTL_WRITEEN_MASK;
104*4882a593Smuzhiyun 	bcm_mpi_writel(tmp, MPI_PCICFGCTL_REG);
105*4882a593Smuzhiyun 	iob();
106*4882a593Smuzhiyun 	return bcm_mpi_readl(MPI_PCICFGDATA_REG);
107*4882a593Smuzhiyun }
108*4882a593Smuzhiyun 
bcm63xx_int_cfg_writel(u32 val,u32 reg)109*4882a593Smuzhiyun static void bcm63xx_int_cfg_writel(u32 val, u32 reg)
110*4882a593Smuzhiyun {
111*4882a593Smuzhiyun 	u32 tmp;
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun 	tmp = reg & MPI_PCICFGCTL_CFGADDR_MASK;
114*4882a593Smuzhiyun 	tmp |=	MPI_PCICFGCTL_WRITEEN_MASK;
115*4882a593Smuzhiyun 	bcm_mpi_writel(tmp, MPI_PCICFGCTL_REG);
116*4882a593Smuzhiyun 	bcm_mpi_writel(val, MPI_PCICFGDATA_REG);
117*4882a593Smuzhiyun }
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun void __iomem *pci_iospace_start;
120*4882a593Smuzhiyun 
bcm63xx_reset_pcie(void)121*4882a593Smuzhiyun static void __init bcm63xx_reset_pcie(void)
122*4882a593Smuzhiyun {
123*4882a593Smuzhiyun 	u32 val;
124*4882a593Smuzhiyun 	u32 reg;
125*4882a593Smuzhiyun 
126*4882a593Smuzhiyun 	/* enable SERDES */
127*4882a593Smuzhiyun 	if (BCMCPU_IS_6328())
128*4882a593Smuzhiyun 		reg = MISC_SERDES_CTRL_6328_REG;
129*4882a593Smuzhiyun 	else
130*4882a593Smuzhiyun 		reg = MISC_SERDES_CTRL_6362_REG;
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun 	val = bcm_misc_readl(reg);
133*4882a593Smuzhiyun 	val |= SERDES_PCIE_EN | SERDES_PCIE_EXD_EN;
134*4882a593Smuzhiyun 	bcm_misc_writel(val, reg);
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun 	/* reset the PCIe core */
137*4882a593Smuzhiyun 	bcm63xx_core_set_reset(BCM63XX_RESET_PCIE, 1);
138*4882a593Smuzhiyun 	bcm63xx_core_set_reset(BCM63XX_RESET_PCIE_EXT, 1);
139*4882a593Smuzhiyun 	mdelay(10);
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun 	bcm63xx_core_set_reset(BCM63XX_RESET_PCIE, 0);
142*4882a593Smuzhiyun 	mdelay(10);
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun 	bcm63xx_core_set_reset(BCM63XX_RESET_PCIE_EXT, 0);
145*4882a593Smuzhiyun 	mdelay(200);
146*4882a593Smuzhiyun }
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun static struct clk *pcie_clk;
149*4882a593Smuzhiyun 
bcm63xx_register_pcie(void)150*4882a593Smuzhiyun static int __init bcm63xx_register_pcie(void)
151*4882a593Smuzhiyun {
152*4882a593Smuzhiyun 	u32 val;
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun 	/* enable clock */
155*4882a593Smuzhiyun 	pcie_clk = clk_get(NULL, "pcie");
156*4882a593Smuzhiyun 	if (IS_ERR_OR_NULL(pcie_clk))
157*4882a593Smuzhiyun 		return -ENODEV;
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun 	clk_prepare_enable(pcie_clk);
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun 	bcm63xx_reset_pcie();
162*4882a593Smuzhiyun 
163*4882a593Smuzhiyun 	/* configure the PCIe bridge */
164*4882a593Smuzhiyun 	val = bcm_pcie_readl(PCIE_BRIDGE_OPT1_REG);
165*4882a593Smuzhiyun 	val |= OPT1_RD_BE_OPT_EN;
166*4882a593Smuzhiyun 	val |= OPT1_RD_REPLY_BE_FIX_EN;
167*4882a593Smuzhiyun 	val |= OPT1_PCIE_BRIDGE_HOLE_DET_EN;
168*4882a593Smuzhiyun 	val |= OPT1_L1_INT_STATUS_MASK_POL;
169*4882a593Smuzhiyun 	bcm_pcie_writel(val, PCIE_BRIDGE_OPT1_REG);
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun 	/* setup the interrupts */
172*4882a593Smuzhiyun 	val = bcm_pcie_readl(PCIE_BRIDGE_RC_INT_MASK_REG);
173*4882a593Smuzhiyun 	val |= PCIE_RC_INT_A | PCIE_RC_INT_B | PCIE_RC_INT_C | PCIE_RC_INT_D;
174*4882a593Smuzhiyun 	bcm_pcie_writel(val, PCIE_BRIDGE_RC_INT_MASK_REG);
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun 	val = bcm_pcie_readl(PCIE_BRIDGE_OPT2_REG);
177*4882a593Smuzhiyun 	/* enable credit checking and error checking */
178*4882a593Smuzhiyun 	val |= OPT2_TX_CREDIT_CHK_EN;
179*4882a593Smuzhiyun 	val |= OPT2_UBUS_UR_DECODE_DIS;
180*4882a593Smuzhiyun 
181*4882a593Smuzhiyun 	/* set device bus/func for the pcie device */
182*4882a593Smuzhiyun 	val |= (PCIE_BUS_DEVICE << OPT2_CFG_TYPE1_BUS_NO_SHIFT);
183*4882a593Smuzhiyun 	val |= OPT2_CFG_TYPE1_BD_SEL;
184*4882a593Smuzhiyun 	bcm_pcie_writel(val, PCIE_BRIDGE_OPT2_REG);
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun 	/* setup class code as bridge */
187*4882a593Smuzhiyun 	val = bcm_pcie_readl(PCIE_IDVAL3_REG);
188*4882a593Smuzhiyun 	val &= ~IDVAL3_CLASS_CODE_MASK;
189*4882a593Smuzhiyun 	val |= (PCI_CLASS_BRIDGE_PCI << IDVAL3_SUBCLASS_SHIFT);
190*4882a593Smuzhiyun 	bcm_pcie_writel(val, PCIE_IDVAL3_REG);
191*4882a593Smuzhiyun 
192*4882a593Smuzhiyun 	/* disable bar1 size */
193*4882a593Smuzhiyun 	val = bcm_pcie_readl(PCIE_CONFIG2_REG);
194*4882a593Smuzhiyun 	val &= ~CONFIG2_BAR1_SIZE_MASK;
195*4882a593Smuzhiyun 	bcm_pcie_writel(val, PCIE_CONFIG2_REG);
196*4882a593Smuzhiyun 
197*4882a593Smuzhiyun 	/* set bar0 to little endian */
198*4882a593Smuzhiyun 	val = (BCM_PCIE_MEM_BASE_PA >> 20) << BASEMASK_BASE_SHIFT;
199*4882a593Smuzhiyun 	val |= (BCM_PCIE_MEM_BASE_PA >> 20) << BASEMASK_MASK_SHIFT;
200*4882a593Smuzhiyun 	val |= BASEMASK_REMAP_EN;
201*4882a593Smuzhiyun 	bcm_pcie_writel(val, PCIE_BRIDGE_BAR0_BASEMASK_REG);
202*4882a593Smuzhiyun 
203*4882a593Smuzhiyun 	val = (BCM_PCIE_MEM_BASE_PA >> 20) << REBASE_ADDR_BASE_SHIFT;
204*4882a593Smuzhiyun 	bcm_pcie_writel(val, PCIE_BRIDGE_BAR0_REBASE_ADDR_REG);
205*4882a593Smuzhiyun 
206*4882a593Smuzhiyun 	register_pci_controller(&bcm63xx_pcie_controller);
207*4882a593Smuzhiyun 
208*4882a593Smuzhiyun 	return 0;
209*4882a593Smuzhiyun }
210*4882a593Smuzhiyun 
bcm63xx_register_pci(void)211*4882a593Smuzhiyun static int __init bcm63xx_register_pci(void)
212*4882a593Smuzhiyun {
213*4882a593Smuzhiyun 	unsigned int mem_size;
214*4882a593Smuzhiyun 	u32 val;
215*4882a593Smuzhiyun 	/*
216*4882a593Smuzhiyun 	 * configuration  access are  done through  IO space,  remap 4
217*4882a593Smuzhiyun 	 * first bytes to access it from CPU.
218*4882a593Smuzhiyun 	 *
219*4882a593Smuzhiyun 	 * this means that  no io access from CPU  should happen while
220*4882a593Smuzhiyun 	 * we do a configuration cycle,	 but there's no way we can add
221*4882a593Smuzhiyun 	 * a spinlock for each io access, so this is currently kind of
222*4882a593Smuzhiyun 	 * broken on SMP.
223*4882a593Smuzhiyun 	 */
224*4882a593Smuzhiyun 	pci_iospace_start = ioremap(BCM_PCI_IO_BASE_PA, 4);
225*4882a593Smuzhiyun 	if (!pci_iospace_start)
226*4882a593Smuzhiyun 		return -ENOMEM;
227*4882a593Smuzhiyun 
228*4882a593Smuzhiyun 	/* setup local bus to PCI access (PCI memory) */
229*4882a593Smuzhiyun 	val = BCM_PCI_MEM_BASE_PA & MPI_L2P_BASE_MASK;
230*4882a593Smuzhiyun 	bcm_mpi_writel(val, MPI_L2PMEMBASE1_REG);
231*4882a593Smuzhiyun 	bcm_mpi_writel(~(BCM_PCI_MEM_SIZE - 1), MPI_L2PMEMRANGE1_REG);
232*4882a593Smuzhiyun 	bcm_mpi_writel(val | MPI_L2PREMAP_ENABLED_MASK, MPI_L2PMEMREMAP1_REG);
233*4882a593Smuzhiyun 
234*4882a593Smuzhiyun 	/* set Cardbus IDSEL (type 0 cfg access on primary bus for
235*4882a593Smuzhiyun 	 * this IDSEL will be done on Cardbus instead) */
236*4882a593Smuzhiyun 	val = bcm_pcmcia_readl(PCMCIA_C1_REG);
237*4882a593Smuzhiyun 	val &= ~PCMCIA_C1_CBIDSEL_MASK;
238*4882a593Smuzhiyun 	val |= (CARDBUS_PCI_IDSEL << PCMCIA_C1_CBIDSEL_SHIFT);
239*4882a593Smuzhiyun 	bcm_pcmcia_writel(val, PCMCIA_C1_REG);
240*4882a593Smuzhiyun 
241*4882a593Smuzhiyun #ifdef CONFIG_CARDBUS
242*4882a593Smuzhiyun 	/* setup local bus to PCI access (Cardbus memory) */
243*4882a593Smuzhiyun 	val = BCM_CB_MEM_BASE_PA & MPI_L2P_BASE_MASK;
244*4882a593Smuzhiyun 	bcm_mpi_writel(val, MPI_L2PMEMBASE2_REG);
245*4882a593Smuzhiyun 	bcm_mpi_writel(~(BCM_CB_MEM_SIZE - 1), MPI_L2PMEMRANGE2_REG);
246*4882a593Smuzhiyun 	val |= MPI_L2PREMAP_ENABLED_MASK | MPI_L2PREMAP_IS_CARDBUS_MASK;
247*4882a593Smuzhiyun 	bcm_mpi_writel(val, MPI_L2PMEMREMAP2_REG);
248*4882a593Smuzhiyun #else
249*4882a593Smuzhiyun 	/* disable second access windows */
250*4882a593Smuzhiyun 	bcm_mpi_writel(0, MPI_L2PMEMREMAP2_REG);
251*4882a593Smuzhiyun #endif
252*4882a593Smuzhiyun 
253*4882a593Smuzhiyun 	/* setup local bus  to PCI access (IO memory),	we have only 1
254*4882a593Smuzhiyun 	 * IO window  for both PCI  and cardbus, but it	 cannot handle
255*4882a593Smuzhiyun 	 * both	 at the	 same time,  assume standard  PCI for  now, if
256*4882a593Smuzhiyun 	 * cardbus card has  IO zone, PCI fixup will  change window to
257*4882a593Smuzhiyun 	 * cardbus */
258*4882a593Smuzhiyun 	val = BCM_PCI_IO_BASE_PA & MPI_L2P_BASE_MASK;
259*4882a593Smuzhiyun 	bcm_mpi_writel(val, MPI_L2PIOBASE_REG);
260*4882a593Smuzhiyun 	bcm_mpi_writel(~(BCM_PCI_IO_SIZE - 1), MPI_L2PIORANGE_REG);
261*4882a593Smuzhiyun 	bcm_mpi_writel(val | MPI_L2PREMAP_ENABLED_MASK, MPI_L2PIOREMAP_REG);
262*4882a593Smuzhiyun 
263*4882a593Smuzhiyun 	/* enable PCI related GPIO pins */
264*4882a593Smuzhiyun 	bcm_mpi_writel(MPI_LOCBUSCTL_EN_PCI_GPIO_MASK, MPI_LOCBUSCTL_REG);
265*4882a593Smuzhiyun 
266*4882a593Smuzhiyun 	/* setup PCI to local bus access, used by PCI device to target
267*4882a593Smuzhiyun 	 * local RAM while bus mastering */
268*4882a593Smuzhiyun 	bcm63xx_int_cfg_writel(0, PCI_BASE_ADDRESS_3);
269*4882a593Smuzhiyun 	if (BCMCPU_IS_3368() || BCMCPU_IS_6358() || BCMCPU_IS_6368())
270*4882a593Smuzhiyun 		val = MPI_SP0_REMAP_ENABLE_MASK;
271*4882a593Smuzhiyun 	else
272*4882a593Smuzhiyun 		val = 0;
273*4882a593Smuzhiyun 	bcm_mpi_writel(val, MPI_SP0_REMAP_REG);
274*4882a593Smuzhiyun 
275*4882a593Smuzhiyun 	bcm63xx_int_cfg_writel(0x0, PCI_BASE_ADDRESS_4);
276*4882a593Smuzhiyun 	bcm_mpi_writel(0, MPI_SP1_REMAP_REG);
277*4882a593Smuzhiyun 
278*4882a593Smuzhiyun 	mem_size = bcm63xx_get_memory_size();
279*4882a593Smuzhiyun 
280*4882a593Smuzhiyun 	/* 6348 before rev b0 exposes only 16 MB of RAM memory through
281*4882a593Smuzhiyun 	 * PCI, throw a warning if we have more memory */
282*4882a593Smuzhiyun 	if (BCMCPU_IS_6348() && (bcm63xx_get_cpu_rev() & 0xf0) == 0xa0) {
283*4882a593Smuzhiyun 		if (mem_size > (16 * 1024 * 1024))
284*4882a593Smuzhiyun 			printk(KERN_WARNING "bcm63xx: this CPU "
285*4882a593Smuzhiyun 			       "revision cannot handle more than 16MB "
286*4882a593Smuzhiyun 			       "of RAM for PCI bus mastering\n");
287*4882a593Smuzhiyun 	} else {
288*4882a593Smuzhiyun 		/* setup sp0 range to local RAM size */
289*4882a593Smuzhiyun 		bcm_mpi_writel(~(mem_size - 1), MPI_SP0_RANGE_REG);
290*4882a593Smuzhiyun 		bcm_mpi_writel(0, MPI_SP1_RANGE_REG);
291*4882a593Smuzhiyun 	}
292*4882a593Smuzhiyun 
293*4882a593Smuzhiyun 	/* change  host bridge	retry  counter to  infinite number  of
294*4882a593Smuzhiyun 	 * retry,  needed for  some broadcom  wifi cards  with Silicon
295*4882a593Smuzhiyun 	 * Backplane bus where access to srom seems very slow  */
296*4882a593Smuzhiyun 	val = bcm63xx_int_cfg_readl(BCMPCI_REG_TIMERS);
297*4882a593Smuzhiyun 	val &= ~REG_TIMER_RETRY_MASK;
298*4882a593Smuzhiyun 	bcm63xx_int_cfg_writel(val, BCMPCI_REG_TIMERS);
299*4882a593Smuzhiyun 
300*4882a593Smuzhiyun 	/* enable memory decoder and bus mastering */
301*4882a593Smuzhiyun 	val = bcm63xx_int_cfg_readl(PCI_COMMAND);
302*4882a593Smuzhiyun 	val |= (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
303*4882a593Smuzhiyun 	bcm63xx_int_cfg_writel(val, PCI_COMMAND);
304*4882a593Smuzhiyun 
305*4882a593Smuzhiyun 	/* enable read prefetching & disable byte swapping for bus
306*4882a593Smuzhiyun 	 * mastering transfers */
307*4882a593Smuzhiyun 	val = bcm_mpi_readl(MPI_PCIMODESEL_REG);
308*4882a593Smuzhiyun 	val &= ~MPI_PCIMODESEL_BAR1_NOSWAP_MASK;
309*4882a593Smuzhiyun 	val &= ~MPI_PCIMODESEL_BAR2_NOSWAP_MASK;
310*4882a593Smuzhiyun 	val &= ~MPI_PCIMODESEL_PREFETCH_MASK;
311*4882a593Smuzhiyun 	val |= (8 << MPI_PCIMODESEL_PREFETCH_SHIFT);
312*4882a593Smuzhiyun 	bcm_mpi_writel(val, MPI_PCIMODESEL_REG);
313*4882a593Smuzhiyun 
314*4882a593Smuzhiyun 	/* enable pci interrupt */
315*4882a593Smuzhiyun 	val = bcm_mpi_readl(MPI_LOCINT_REG);
316*4882a593Smuzhiyun 	val |= MPI_LOCINT_MASK(MPI_LOCINT_EXT_PCI_INT);
317*4882a593Smuzhiyun 	bcm_mpi_writel(val, MPI_LOCINT_REG);
318*4882a593Smuzhiyun 
319*4882a593Smuzhiyun 	register_pci_controller(&bcm63xx_controller);
320*4882a593Smuzhiyun 
321*4882a593Smuzhiyun #ifdef CONFIG_CARDBUS
322*4882a593Smuzhiyun 	register_pci_controller(&bcm63xx_cb_controller);
323*4882a593Smuzhiyun #endif
324*4882a593Smuzhiyun 
325*4882a593Smuzhiyun 	/* mark memory space used for IO mapping as reserved */
326*4882a593Smuzhiyun 	request_mem_region(BCM_PCI_IO_BASE_PA, BCM_PCI_IO_SIZE,
327*4882a593Smuzhiyun 			   "bcm63xx PCI IO space");
328*4882a593Smuzhiyun 	return 0;
329*4882a593Smuzhiyun }
330*4882a593Smuzhiyun 
331*4882a593Smuzhiyun 
bcm63xx_pci_init(void)332*4882a593Smuzhiyun static int __init bcm63xx_pci_init(void)
333*4882a593Smuzhiyun {
334*4882a593Smuzhiyun 	if (!bcm63xx_pci_enabled)
335*4882a593Smuzhiyun 		return -ENODEV;
336*4882a593Smuzhiyun 
337*4882a593Smuzhiyun 	switch (bcm63xx_get_cpu_id()) {
338*4882a593Smuzhiyun 	case BCM6328_CPU_ID:
339*4882a593Smuzhiyun 	case BCM6362_CPU_ID:
340*4882a593Smuzhiyun 		return bcm63xx_register_pcie();
341*4882a593Smuzhiyun 	case BCM3368_CPU_ID:
342*4882a593Smuzhiyun 	case BCM6348_CPU_ID:
343*4882a593Smuzhiyun 	case BCM6358_CPU_ID:
344*4882a593Smuzhiyun 	case BCM6368_CPU_ID:
345*4882a593Smuzhiyun 		return bcm63xx_register_pci();
346*4882a593Smuzhiyun 	default:
347*4882a593Smuzhiyun 		return -ENODEV;
348*4882a593Smuzhiyun 	}
349*4882a593Smuzhiyun }
350*4882a593Smuzhiyun 
351*4882a593Smuzhiyun arch_initcall(bcm63xx_pci_init);
352