2 * Broadcom specific AMBA
5 * Licensed under the GNU/GPL. See COPYING for details.
8 #include "bcma_private.h"
9 #include <linux/slab.h>
10 #include <linux/bcma/bcma.h>
11 #include <linux/pci.h>
12 #include <linux/module.h>
14 static void bcma_host_pci_switch_core(struct bcma_device
*core
)
16 pci_write_config_dword(core
->bus
->host_pci
, BCMA_PCI_BAR0_WIN
,
18 pci_write_config_dword(core
->bus
->host_pci
, BCMA_PCI_BAR0_WIN2
,
20 core
->bus
->mapped_core
= core
;
21 pr_debug("Switched to core: 0x%X\n", core
->id
.id
);
24 /* Provides access to the requested core. Returns base offset that has to be
25 * used. It makes use of fixed windows when possible. */
26 static u16
bcma_host_pci_provide_access_to_core(struct bcma_device
*core
)
28 switch (core
->id
.id
) {
29 case BCMA_CORE_CHIPCOMMON
:
30 return 3 * BCMA_CORE_SIZE
;
32 return 2 * BCMA_CORE_SIZE
;
35 if (core
->bus
->mapped_core
!= core
)
36 bcma_host_pci_switch_core(core
);
40 static u8
bcma_host_pci_read8(struct bcma_device
*core
, u16 offset
)
42 offset
+= bcma_host_pci_provide_access_to_core(core
);
43 return ioread8(core
->bus
->mmio
+ offset
);
46 static u16
bcma_host_pci_read16(struct bcma_device
*core
, u16 offset
)
48 offset
+= bcma_host_pci_provide_access_to_core(core
);
49 return ioread16(core
->bus
->mmio
+ offset
);
52 static u32
bcma_host_pci_read32(struct bcma_device
*core
, u16 offset
)
54 offset
+= bcma_host_pci_provide_access_to_core(core
);
55 return ioread32(core
->bus
->mmio
+ offset
);
58 static void bcma_host_pci_write8(struct bcma_device
*core
, u16 offset
,
61 offset
+= bcma_host_pci_provide_access_to_core(core
);
62 iowrite8(value
, core
->bus
->mmio
+ offset
);
65 static void bcma_host_pci_write16(struct bcma_device
*core
, u16 offset
,
68 offset
+= bcma_host_pci_provide_access_to_core(core
);
69 iowrite16(value
, core
->bus
->mmio
+ offset
);
72 static void bcma_host_pci_write32(struct bcma_device
*core
, u16 offset
,
75 offset
+= bcma_host_pci_provide_access_to_core(core
);
76 iowrite32(value
, core
->bus
->mmio
+ offset
);
79 #ifdef CONFIG_BCMA_BLOCKIO
80 void bcma_host_pci_block_read(struct bcma_device
*core
, void *buffer
,
81 size_t count
, u16 offset
, u8 reg_width
)
83 void __iomem
*addr
= core
->bus
->mmio
+ offset
;
84 if (core
->bus
->mapped_core
!= core
)
85 bcma_host_pci_switch_core(core
);
88 ioread8_rep(addr
, buffer
, count
);
92 ioread16_rep(addr
, buffer
, count
>> 1);
96 ioread32_rep(addr
, buffer
, count
>> 2);
103 void bcma_host_pci_block_write(struct bcma_device
*core
, const void *buffer
,
104 size_t count
, u16 offset
, u8 reg_width
)
106 void __iomem
*addr
= core
->bus
->mmio
+ offset
;
107 if (core
->bus
->mapped_core
!= core
)
108 bcma_host_pci_switch_core(core
);
111 iowrite8_rep(addr
, buffer
, count
);
115 iowrite16_rep(addr
, buffer
, count
>> 1);
119 iowrite32_rep(addr
, buffer
, count
>> 2);
127 static u32
bcma_host_pci_aread32(struct bcma_device
*core
, u16 offset
)
129 if (core
->bus
->mapped_core
!= core
)
130 bcma_host_pci_switch_core(core
);
131 return ioread32(core
->bus
->mmio
+ (1 * BCMA_CORE_SIZE
) + offset
);
134 static void bcma_host_pci_awrite32(struct bcma_device
*core
, u16 offset
,
137 if (core
->bus
->mapped_core
!= core
)
138 bcma_host_pci_switch_core(core
);
139 iowrite32(value
, core
->bus
->mmio
+ (1 * BCMA_CORE_SIZE
) + offset
);
142 const struct bcma_host_ops bcma_host_pci_ops
= {
143 .read8
= bcma_host_pci_read8
,
144 .read16
= bcma_host_pci_read16
,
145 .read32
= bcma_host_pci_read32
,
146 .write8
= bcma_host_pci_write8
,
147 .write16
= bcma_host_pci_write16
,
148 .write32
= bcma_host_pci_write32
,
149 #ifdef CONFIG_BCMA_BLOCKIO
150 .block_read
= bcma_host_pci_block_read
,
151 .block_write
= bcma_host_pci_block_write
,
153 .aread32
= bcma_host_pci_aread32
,
154 .awrite32
= bcma_host_pci_awrite32
,
157 static int bcma_host_pci_probe(struct pci_dev
*dev
,
158 const struct pci_device_id
*id
)
160 struct bcma_bus
*bus
;
166 bus
= kzalloc(sizeof(*bus
), GFP_KERNEL
);
170 /* Basic PCI configuration */
171 err
= pci_enable_device(dev
);
175 name
= dev_name(&dev
->dev
);
176 if (dev
->driver
&& dev
->driver
->name
)
177 name
= dev
->driver
->name
;
178 err
= pci_request_regions(dev
, name
);
180 goto err_pci_disable
;
183 /* Disable the RETRY_TIMEOUT register (0x41) to keep
184 * PCI Tx retries from interfering with C3 CPU state */
185 pci_read_config_dword(dev
, 0x40, &val
);
186 if ((val
& 0x0000ff00) != 0)
187 pci_write_config_dword(dev
, 0x40, val
& 0xffff00ff);
189 /* SSB needed additional powering up, do we have any AMBA PCI cards? */
190 if (!pci_is_pcie(dev
))
191 pr_err("PCI card detected, report problems.\n");
195 bus
->mmio
= pci_iomap(dev
, 0, ~0UL);
197 goto err_pci_release_regions
;
201 bus
->hosttype
= BCMA_HOSTTYPE_PCI
;
202 bus
->ops
= &bcma_host_pci_ops
;
205 err
= bcma_bus_register(bus
);
207 goto err_pci_unmap_mmio
;
209 pci_set_drvdata(dev
, bus
);
215 pci_iounmap(dev
, bus
->mmio
);
216 err_pci_release_regions
:
217 pci_release_regions(dev
);
219 pci_disable_device(dev
);
225 static void bcma_host_pci_remove(struct pci_dev
*dev
)
227 struct bcma_bus
*bus
= pci_get_drvdata(dev
);
229 bcma_bus_unregister(bus
);
230 pci_iounmap(dev
, bus
->mmio
);
231 pci_release_regions(dev
);
232 pci_disable_device(dev
);
234 pci_set_drvdata(dev
, NULL
);
238 static int bcma_host_pci_suspend(struct device
*dev
)
240 struct pci_dev
*pdev
= to_pci_dev(dev
);
241 struct bcma_bus
*bus
= pci_get_drvdata(pdev
);
243 bus
->mapped_core
= NULL
;
245 return bcma_bus_suspend(bus
);
248 static int bcma_host_pci_resume(struct device
*dev
)
250 struct pci_dev
*pdev
= to_pci_dev(dev
);
251 struct bcma_bus
*bus
= pci_get_drvdata(pdev
);
253 return bcma_bus_resume(bus
);
256 static SIMPLE_DEV_PM_OPS(bcma_pm_ops
, bcma_host_pci_suspend
,
257 bcma_host_pci_resume
);
258 #define BCMA_PM_OPS (&bcma_pm_ops)
260 #else /* CONFIG_PM */
262 #define BCMA_PM_OPS NULL
264 #endif /* CONFIG_PM */
266 static DEFINE_PCI_DEVICE_TABLE(bcma_pci_bridge_tbl
) = {
267 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, 0x0576) },
268 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, 0x4331) },
269 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, 0x4353) },
270 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, 0x4357) },
271 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, 0x4727) },
274 MODULE_DEVICE_TABLE(pci
, bcma_pci_bridge_tbl
);
276 static struct pci_driver bcma_pci_bridge_driver
= {
277 .name
= "bcma-pci-bridge",
278 .id_table
= bcma_pci_bridge_tbl
,
279 .probe
= bcma_host_pci_probe
,
280 .remove
= bcma_host_pci_remove
,
281 .driver
.pm
= BCMA_PM_OPS
,
284 int __init
bcma_host_pci_init(void)
286 return pci_register_driver(&bcma_pci_bridge_driver
);
289 void __exit
bcma_host_pci_exit(void)
291 pci_unregister_driver(&bcma_pci_bridge_driver
);