blob: a2b6d55a249227f228b6880f270c563b9b0927a0 [file] [log] [blame]
Maxime Bizone7300d02009-08-18 13:23:37 +01001/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
7 */
8
9#include <linux/types.h>
10#include <linux/pci.h>
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <asm/bootinfo.h>
14
15#include "pci-bcm63xx.h"
16
17/*
18 * Allow PCI to be disabled at runtime depending on board nvram
19 * configuration
20 */
21int bcm63xx_pci_enabled;
22
23static struct resource bcm_pci_mem_resource = {
24 .name = "bcm63xx PCI memory space",
25 .start = BCM_PCI_MEM_BASE_PA,
26 .end = BCM_PCI_MEM_END_PA,
27 .flags = IORESOURCE_MEM
28};
29
30static struct resource bcm_pci_io_resource = {
31 .name = "bcm63xx PCI IO space",
32 .start = BCM_PCI_IO_BASE_PA,
33#ifdef CONFIG_CARDBUS
34 .end = BCM_PCI_IO_HALF_PA,
35#else
36 .end = BCM_PCI_IO_END_PA,
37#endif
38 .flags = IORESOURCE_IO
39};
40
41struct pci_controller bcm63xx_controller = {
42 .pci_ops = &bcm63xx_pci_ops,
43 .io_resource = &bcm_pci_io_resource,
44 .mem_resource = &bcm_pci_mem_resource,
45};
46
47/*
48 * We handle cardbus via a fake Cardbus bridge, memory and io spaces
49 * have to be clearly separated from PCI one since we have different
50 * memory decoder.
51 */
52#ifdef CONFIG_CARDBUS
53static struct resource bcm_cb_mem_resource = {
54 .name = "bcm63xx Cardbus memory space",
55 .start = BCM_CB_MEM_BASE_PA,
56 .end = BCM_CB_MEM_END_PA,
57 .flags = IORESOURCE_MEM
58};
59
60static struct resource bcm_cb_io_resource = {
61 .name = "bcm63xx Cardbus IO space",
62 .start = BCM_PCI_IO_HALF_PA + 1,
63 .end = BCM_PCI_IO_END_PA,
64 .flags = IORESOURCE_IO
65};
66
67struct pci_controller bcm63xx_cb_controller = {
68 .pci_ops = &bcm63xx_cb_ops,
69 .io_resource = &bcm_cb_io_resource,
70 .mem_resource = &bcm_cb_mem_resource,
71};
72#endif
73
74static u32 bcm63xx_int_cfg_readl(u32 reg)
75{
76 u32 tmp;
77
78 tmp = reg & MPI_PCICFGCTL_CFGADDR_MASK;
79 tmp |= MPI_PCICFGCTL_WRITEEN_MASK;
80 bcm_mpi_writel(tmp, MPI_PCICFGCTL_REG);
81 iob();
82 return bcm_mpi_readl(MPI_PCICFGDATA_REG);
83}
84
85static void bcm63xx_int_cfg_writel(u32 val, u32 reg)
86{
87 u32 tmp;
88
89 tmp = reg & MPI_PCICFGCTL_CFGADDR_MASK;
90 tmp |= MPI_PCICFGCTL_WRITEEN_MASK;
91 bcm_mpi_writel(tmp, MPI_PCICFGCTL_REG);
92 bcm_mpi_writel(val, MPI_PCICFGDATA_REG);
93}
94
95void __iomem *pci_iospace_start;
96
Jonas Gorski76f42fe2012-07-24 16:33:13 +020097static int __init bcm63xx_register_pci(void)
Maxime Bizone7300d02009-08-18 13:23:37 +010098{
99 unsigned int mem_size;
100 u32 val;
Maxime Bizone7300d02009-08-18 13:23:37 +0100101 /*
102 * configuration access are done through IO space, remap 4
103 * first bytes to access it from CPU.
104 *
105 * this means that no io access from CPU should happen while
106 * we do a configuration cycle, but there's no way we can add
107 * a spinlock for each io access, so this is currently kind of
108 * broken on SMP.
109 */
110 pci_iospace_start = ioremap_nocache(BCM_PCI_IO_BASE_PA, 4);
111 if (!pci_iospace_start)
112 return -ENOMEM;
113
114 /* setup local bus to PCI access (PCI memory) */
115 val = BCM_PCI_MEM_BASE_PA & MPI_L2P_BASE_MASK;
116 bcm_mpi_writel(val, MPI_L2PMEMBASE1_REG);
117 bcm_mpi_writel(~(BCM_PCI_MEM_SIZE - 1), MPI_L2PMEMRANGE1_REG);
118 bcm_mpi_writel(val | MPI_L2PREMAP_ENABLED_MASK, MPI_L2PMEMREMAP1_REG);
119
120 /* set Cardbus IDSEL (type 0 cfg access on primary bus for
121 * this IDSEL will be done on Cardbus instead) */
122 val = bcm_pcmcia_readl(PCMCIA_C1_REG);
123 val &= ~PCMCIA_C1_CBIDSEL_MASK;
124 val |= (CARDBUS_PCI_IDSEL << PCMCIA_C1_CBIDSEL_SHIFT);
125 bcm_pcmcia_writel(val, PCMCIA_C1_REG);
126
127#ifdef CONFIG_CARDBUS
128 /* setup local bus to PCI access (Cardbus memory) */
129 val = BCM_CB_MEM_BASE_PA & MPI_L2P_BASE_MASK;
130 bcm_mpi_writel(val, MPI_L2PMEMBASE2_REG);
131 bcm_mpi_writel(~(BCM_CB_MEM_SIZE - 1), MPI_L2PMEMRANGE2_REG);
132 val |= MPI_L2PREMAP_ENABLED_MASK | MPI_L2PREMAP_IS_CARDBUS_MASK;
133 bcm_mpi_writel(val, MPI_L2PMEMREMAP2_REG);
134#else
135 /* disable second access windows */
136 bcm_mpi_writel(0, MPI_L2PMEMREMAP2_REG);
137#endif
138
139 /* setup local bus to PCI access (IO memory), we have only 1
140 * IO window for both PCI and cardbus, but it cannot handle
141 * both at the same time, assume standard PCI for now, if
142 * cardbus card has IO zone, PCI fixup will change window to
143 * cardbus */
144 val = BCM_PCI_IO_BASE_PA & MPI_L2P_BASE_MASK;
145 bcm_mpi_writel(val, MPI_L2PIOBASE_REG);
146 bcm_mpi_writel(~(BCM_PCI_IO_SIZE - 1), MPI_L2PIORANGE_REG);
147 bcm_mpi_writel(val | MPI_L2PREMAP_ENABLED_MASK, MPI_L2PIOREMAP_REG);
148
149 /* enable PCI related GPIO pins */
150 bcm_mpi_writel(MPI_LOCBUSCTL_EN_PCI_GPIO_MASK, MPI_LOCBUSCTL_REG);
151
152 /* setup PCI to local bus access, used by PCI device to target
153 * local RAM while bus mastering */
154 bcm63xx_int_cfg_writel(0, PCI_BASE_ADDRESS_3);
Maxime Bizon04712f32011-11-04 19:09:35 +0100155 if (BCMCPU_IS_6358() || BCMCPU_IS_6368())
Maxime Bizone7300d02009-08-18 13:23:37 +0100156 val = MPI_SP0_REMAP_ENABLE_MASK;
157 else
158 val = 0;
159 bcm_mpi_writel(val, MPI_SP0_REMAP_REG);
160
161 bcm63xx_int_cfg_writel(0x0, PCI_BASE_ADDRESS_4);
162 bcm_mpi_writel(0, MPI_SP1_REMAP_REG);
163
164 mem_size = bcm63xx_get_memory_size();
165
166 /* 6348 before rev b0 exposes only 16 MB of RAM memory through
167 * PCI, throw a warning if we have more memory */
168 if (BCMCPU_IS_6348() && (bcm63xx_get_cpu_rev() & 0xf0) == 0xa0) {
169 if (mem_size > (16 * 1024 * 1024))
170 printk(KERN_WARNING "bcm63xx: this CPU "
171 "revision cannot handle more than 16MB "
172 "of RAM for PCI bus mastering\n");
173 } else {
174 /* setup sp0 range to local RAM size */
175 bcm_mpi_writel(~(mem_size - 1), MPI_SP0_RANGE_REG);
176 bcm_mpi_writel(0, MPI_SP1_RANGE_REG);
177 }
178
179 /* change host bridge retry counter to infinite number of
180 * retry, needed for some broadcom wifi cards with Silicon
181 * Backplane bus where access to srom seems very slow */
182 val = bcm63xx_int_cfg_readl(BCMPCI_REG_TIMERS);
183 val &= ~REG_TIMER_RETRY_MASK;
184 bcm63xx_int_cfg_writel(val, BCMPCI_REG_TIMERS);
185
186 /* enable memory decoder and bus mastering */
187 val = bcm63xx_int_cfg_readl(PCI_COMMAND);
188 val |= (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
189 bcm63xx_int_cfg_writel(val, PCI_COMMAND);
190
191 /* enable read prefetching & disable byte swapping for bus
192 * mastering transfers */
193 val = bcm_mpi_readl(MPI_PCIMODESEL_REG);
194 val &= ~MPI_PCIMODESEL_BAR1_NOSWAP_MASK;
195 val &= ~MPI_PCIMODESEL_BAR2_NOSWAP_MASK;
196 val &= ~MPI_PCIMODESEL_PREFETCH_MASK;
197 val |= (8 << MPI_PCIMODESEL_PREFETCH_SHIFT);
198 bcm_mpi_writel(val, MPI_PCIMODESEL_REG);
199
200 /* enable pci interrupt */
201 val = bcm_mpi_readl(MPI_LOCINT_REG);
202 val |= MPI_LOCINT_MASK(MPI_LOCINT_EXT_PCI_INT);
203 bcm_mpi_writel(val, MPI_LOCINT_REG);
204
205 register_pci_controller(&bcm63xx_controller);
206
207#ifdef CONFIG_CARDBUS
208 register_pci_controller(&bcm63xx_cb_controller);
209#endif
210
211 /* mark memory space used for IO mapping as reserved */
212 request_mem_region(BCM_PCI_IO_BASE_PA, BCM_PCI_IO_SIZE,
213 "bcm63xx PCI IO space");
214 return 0;
215}
216
Jonas Gorski76f42fe2012-07-24 16:33:13 +0200217
218static int __init bcm63xx_pci_init(void)
219{
220 if (!bcm63xx_pci_enabled)
221 return -ENODEV;
222
223 switch (bcm63xx_get_cpu_id()) {
224 case BCM6348_CPU_ID:
225 case BCM6358_CPU_ID:
226 case BCM6368_CPU_ID:
227 return bcm63xx_register_pci();
228 default:
229 return -ENODEV;
230 }
231}
232
Maxime Bizone7300d02009-08-18 13:23:37 +0100233arch_initcall(bcm63xx_pci_init);