ath9k: use PS wakeup before REG_READ
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / bcma / host_pci.c
blobffd8797faf4f0d3a10bcd49dbef7264e399347dd
1 /*
2 * Broadcom specific AMBA
3 * PCI Host
5 * Licensed under the GNU/GPL. See COPYING for details.
6 */
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,
15 core->addr);
16 pci_write_config_dword(core->bus->host_pci, BCMA_PCI_BAR0_WIN2,
17 core->wrap);
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,
44 u8 value)
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,
52 u16 value)
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,
60 u32 value)
62 if (core->bus->mapped_core != core)
63 bcma_host_pci_switch_core(core);
64 iowrite32(value, core->bus->mmio + offset);
67 static u32 bcma_host_pci_aread32(struct bcma_device *core, u16 offset)
69 if (core->bus->mapped_core != core)
70 bcma_host_pci_switch_core(core);
71 return ioread32(core->bus->mmio + (1 * BCMA_CORE_SIZE) + offset);
74 static void bcma_host_pci_awrite32(struct bcma_device *core, u16 offset,
75 u32 value)
77 if (core->bus->mapped_core != core)
78 bcma_host_pci_switch_core(core);
79 iowrite32(value, core->bus->mmio + (1 * BCMA_CORE_SIZE) + offset);
82 const struct bcma_host_ops bcma_host_pci_ops = {
83 .read8 = bcma_host_pci_read8,
84 .read16 = bcma_host_pci_read16,
85 .read32 = bcma_host_pci_read32,
86 .write8 = bcma_host_pci_write8,
87 .write16 = bcma_host_pci_write16,
88 .write32 = bcma_host_pci_write32,
89 .aread32 = bcma_host_pci_aread32,
90 .awrite32 = bcma_host_pci_awrite32,
93 static int bcma_host_pci_probe(struct pci_dev *dev,
94 const struct pci_device_id *id)
96 struct bcma_bus *bus;
97 int err = -ENOMEM;
98 const char *name;
99 u32 val;
101 /* Alloc */
102 bus = kzalloc(sizeof(*bus), GFP_KERNEL);
103 if (!bus)
104 goto out;
106 /* Basic PCI configuration */
107 err = pci_enable_device(dev);
108 if (err)
109 goto err_kfree_bus;
111 name = dev_name(&dev->dev);
112 if (dev->driver && dev->driver->name)
113 name = dev->driver->name;
114 err = pci_request_regions(dev, name);
115 if (err)
116 goto err_pci_disable;
117 pci_set_master(dev);
119 /* Disable the RETRY_TIMEOUT register (0x41) to keep
120 * PCI Tx retries from interfering with C3 CPU state */
121 pci_read_config_dword(dev, 0x40, &val);
122 if ((val & 0x0000ff00) != 0)
123 pci_write_config_dword(dev, 0x40, val & 0xffff00ff);
125 /* SSB needed additional powering up, do we have any AMBA PCI cards? */
126 if (!pci_is_pcie(dev))
127 pr_err("PCI card detected, report problems.\n");
129 /* Map MMIO */
130 err = -ENOMEM;
131 bus->mmio = pci_iomap(dev, 0, ~0UL);
132 if (!bus->mmio)
133 goto err_pci_release_regions;
135 /* Host specific */
136 bus->host_pci = dev;
137 bus->hosttype = BCMA_HOSTTYPE_PCI;
138 bus->ops = &bcma_host_pci_ops;
140 /* Register */
141 err = bcma_bus_register(bus);
142 if (err)
143 goto err_pci_unmap_mmio;
145 pci_set_drvdata(dev, bus);
147 out:
148 return err;
150 err_pci_unmap_mmio:
151 pci_iounmap(dev, bus->mmio);
152 err_pci_release_regions:
153 pci_release_regions(dev);
154 err_pci_disable:
155 pci_disable_device(dev);
156 err_kfree_bus:
157 kfree(bus);
158 return err;
161 static void bcma_host_pci_remove(struct pci_dev *dev)
163 struct bcma_bus *bus = pci_get_drvdata(dev);
165 bcma_bus_unregister(bus);
166 pci_iounmap(dev, bus->mmio);
167 pci_release_regions(dev);
168 pci_disable_device(dev);
169 kfree(bus);
170 pci_set_drvdata(dev, NULL);
173 static DEFINE_PCI_DEVICE_TABLE(bcma_pci_bridge_tbl) = {
174 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x0576) },
175 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4331) },
176 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4353) },
177 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4727) },
178 { 0, },
180 MODULE_DEVICE_TABLE(pci, bcma_pci_bridge_tbl);
182 static struct pci_driver bcma_pci_bridge_driver = {
183 .name = "bcma-pci-bridge",
184 .id_table = bcma_pci_bridge_tbl,
185 .probe = bcma_host_pci_probe,
186 .remove = bcma_host_pci_remove,
189 int __init bcma_host_pci_init(void)
191 return pci_register_driver(&bcma_pci_bridge_driver);
194 void __exit bcma_host_pci_exit(void)
196 pci_unregister_driver(&bcma_pci_bridge_driver);