2 * Broadcom specific AMBA
5 * Licensed under the GNU/GPL. See COPYING for details.
8 #include "bcma_private.h"
9 #include <linux/bcma/bcma.h>
10 #include <linux/pci.h>
12 static void bcma_host_pci_switch_core(struct bcma_device *core)
14 pci_write_config_dword(core->bus->host_pci, BCMA_PCI_BAR0_WIN,
16 pci_write_config_dword(core->bus->host_pci, BCMA_PCI_BAR0_WIN2,
18 core->bus->mapped_core = core;
19 pr_debug("Switched to core: 0x%X\n", core->id.id);
22 static u8 bcma_host_pci_read8(struct bcma_device *core, u16 offset)
24 if (core->bus->mapped_core != core)
25 bcma_host_pci_switch_core(core);
26 return ioread8(core->bus->mmio + offset);
29 static u16 bcma_host_pci_read16(struct bcma_device *core, u16 offset)
31 if (core->bus->mapped_core != core)
32 bcma_host_pci_switch_core(core);
33 return ioread16(core->bus->mmio + offset);
36 static u32 bcma_host_pci_read32(struct bcma_device *core, u16 offset)
38 if (core->bus->mapped_core != core)
39 bcma_host_pci_switch_core(core);
40 return ioread32(core->bus->mmio + offset);
43 static void bcma_host_pci_write8(struct bcma_device *core, u16 offset,
46 if (core->bus->mapped_core != core)
47 bcma_host_pci_switch_core(core);
48 iowrite8(value, core->bus->mmio + offset);
51 static void bcma_host_pci_write16(struct bcma_device *core, u16 offset,
54 if (core->bus->mapped_core != core)
55 bcma_host_pci_switch_core(core);
56 iowrite16(value, core->bus->mmio + offset);
59 static void bcma_host_pci_write32(struct bcma_device *core, u16 offset,
62 if (core->bus->mapped_core != core)
63 bcma_host_pci_switch_core(core);
64 iowrite32(value, core->bus->mmio + offset);
67 #ifdef CONFIG_BCMA_BLOCKIO
68 void bcma_host_pci_block_read(struct bcma_device *core, void *buffer,
69 size_t count, u16 offset, u8 reg_width)
71 void __iomem *addr = core->bus->mmio + offset;
72 if (core->bus->mapped_core != core)
73 bcma_host_pci_switch_core(core);
76 ioread8_rep(addr, buffer, count);
80 ioread16_rep(addr, buffer, count >> 1);
84 ioread32_rep(addr, buffer, count >> 2);
91 void bcma_host_pci_block_write(struct bcma_device *core, const void *buffer,
92 size_t count, u16 offset, u8 reg_width)
94 void __iomem *addr = core->bus->mmio + offset;
95 if (core->bus->mapped_core != core)
96 bcma_host_pci_switch_core(core);
99 iowrite8_rep(addr, buffer, count);
103 iowrite16_rep(addr, buffer, count >> 1);
107 iowrite32_rep(addr, buffer, count >> 2);
115 static u32 bcma_host_pci_aread32(struct bcma_device *core, u16 offset)
117 if (core->bus->mapped_core != core)
118 bcma_host_pci_switch_core(core);
119 return ioread32(core->bus->mmio + (1 * BCMA_CORE_SIZE) + offset);
122 static void bcma_host_pci_awrite32(struct bcma_device *core, u16 offset,
125 if (core->bus->mapped_core != core)
126 bcma_host_pci_switch_core(core);
127 iowrite32(value, core->bus->mmio + (1 * BCMA_CORE_SIZE) + offset);
130 const struct bcma_host_ops bcma_host_pci_ops = {
131 .read8 = bcma_host_pci_read8,
132 .read16 = bcma_host_pci_read16,
133 .read32 = bcma_host_pci_read32,
134 .write8 = bcma_host_pci_write8,
135 .write16 = bcma_host_pci_write16,
136 .write32 = bcma_host_pci_write32,
137 #ifdef CONFIG_BCMA_BLOCKIO
138 .block_read = bcma_host_pci_block_read,
139 .block_write = bcma_host_pci_block_write,
141 .aread32 = bcma_host_pci_aread32,
142 .awrite32 = bcma_host_pci_awrite32,
145 static int bcma_host_pci_probe(struct pci_dev *dev,
146 const struct pci_device_id *id)
148 struct bcma_bus *bus;
154 bus = kzalloc(sizeof(*bus), GFP_KERNEL);
158 /* Basic PCI configuration */
159 err = pci_enable_device(dev);
163 name = dev_name(&dev->dev);
164 if (dev->driver && dev->driver->name)
165 name = dev->driver->name;
166 err = pci_request_regions(dev, name);
168 goto err_pci_disable;
171 /* Disable the RETRY_TIMEOUT register (0x41) to keep
172 * PCI Tx retries from interfering with C3 CPU state */
173 pci_read_config_dword(dev, 0x40, &val);
174 if ((val & 0x0000ff00) != 0)
175 pci_write_config_dword(dev, 0x40, val & 0xffff00ff);
177 /* SSB needed additional powering up, do we have any AMBA PCI cards? */
178 if (!pci_is_pcie(dev))
179 pr_err("PCI card detected, report problems.\n");
183 bus->mmio = pci_iomap(dev, 0, ~0UL);
185 goto err_pci_release_regions;
189 bus->hosttype = BCMA_HOSTTYPE_PCI;
190 bus->ops = &bcma_host_pci_ops;
193 err = bcma_bus_register(bus);
195 goto err_pci_unmap_mmio;
197 pci_set_drvdata(dev, bus);
203 pci_iounmap(dev, bus->mmio);
204 err_pci_release_regions:
205 pci_release_regions(dev);
207 pci_disable_device(dev);
213 static void bcma_host_pci_remove(struct pci_dev *dev)
215 struct bcma_bus *bus = pci_get_drvdata(dev);
217 bcma_bus_unregister(bus);
218 pci_iounmap(dev, bus->mmio);
219 pci_release_regions(dev);
220 pci_disable_device(dev);
222 pci_set_drvdata(dev, NULL);
225 static DEFINE_PCI_DEVICE_TABLE(bcma_pci_bridge_tbl) = {
226 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x0576) },
227 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4331) },
228 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4353) },
229 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4357) },
230 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4727) },
233 MODULE_DEVICE_TABLE(pci, bcma_pci_bridge_tbl);
235 static struct pci_driver bcma_pci_bridge_driver = {
236 .name = "bcma-pci-bridge",
237 .id_table = bcma_pci_bridge_tbl,
238 .probe = bcma_host_pci_probe,
239 .remove = bcma_host_pci_remove,
242 int __init bcma_host_pci_init(void)
244 return pci_register_driver(&bcma_pci_bridge_driver);
247 void __exit bcma_host_pci_exit(void)
249 pci_unregister_driver(&bcma_pci_bridge_driver);