Loading...
1/*
2 * Broadcom specific AMBA
3 * PCI Host
4 *
5 * Licensed under the GNU/GPL. See COPYING for details.
6 */
7
8#include "bcma_private.h"
9#include <linux/slab.h>
10#include <linux/bcma/bcma.h>
11#include <linux/pci.h>
12
13static void bcma_host_pci_switch_core(struct bcma_device *core)
14{
15 pci_write_config_dword(core->bus->host_pci, BCMA_PCI_BAR0_WIN,
16 core->addr);
17 pci_write_config_dword(core->bus->host_pci, BCMA_PCI_BAR0_WIN2,
18 core->wrap);
19 core->bus->mapped_core = core;
20 pr_debug("Switched to core: 0x%X\n", core->id.id);
21}
22
23static u8 bcma_host_pci_read8(struct bcma_device *core, u16 offset)
24{
25 if (core->bus->mapped_core != core)
26 bcma_host_pci_switch_core(core);
27 return ioread8(core->bus->mmio + offset);
28}
29
30static u16 bcma_host_pci_read16(struct bcma_device *core, u16 offset)
31{
32 if (core->bus->mapped_core != core)
33 bcma_host_pci_switch_core(core);
34 return ioread16(core->bus->mmio + offset);
35}
36
37static u32 bcma_host_pci_read32(struct bcma_device *core, u16 offset)
38{
39 if (core->bus->mapped_core != core)
40 bcma_host_pci_switch_core(core);
41 return ioread32(core->bus->mmio + offset);
42}
43
44static void bcma_host_pci_write8(struct bcma_device *core, u16 offset,
45 u8 value)
46{
47 if (core->bus->mapped_core != core)
48 bcma_host_pci_switch_core(core);
49 iowrite8(value, core->bus->mmio + offset);
50}
51
52static void bcma_host_pci_write16(struct bcma_device *core, u16 offset,
53 u16 value)
54{
55 if (core->bus->mapped_core != core)
56 bcma_host_pci_switch_core(core);
57 iowrite16(value, core->bus->mmio + offset);
58}
59
60static void bcma_host_pci_write32(struct bcma_device *core, u16 offset,
61 u32 value)
62{
63 if (core->bus->mapped_core != core)
64 bcma_host_pci_switch_core(core);
65 iowrite32(value, core->bus->mmio + offset);
66}
67
68#ifdef CONFIG_BCMA_BLOCKIO
69void bcma_host_pci_block_read(struct bcma_device *core, void *buffer,
70 size_t count, u16 offset, u8 reg_width)
71{
72 void __iomem *addr = core->bus->mmio + offset;
73 if (core->bus->mapped_core != core)
74 bcma_host_pci_switch_core(core);
75 switch (reg_width) {
76 case sizeof(u8):
77 ioread8_rep(addr, buffer, count);
78 break;
79 case sizeof(u16):
80 WARN_ON(count & 1);
81 ioread16_rep(addr, buffer, count >> 1);
82 break;
83 case sizeof(u32):
84 WARN_ON(count & 3);
85 ioread32_rep(addr, buffer, count >> 2);
86 break;
87 default:
88 WARN_ON(1);
89 }
90}
91
92void bcma_host_pci_block_write(struct bcma_device *core, const void *buffer,
93 size_t count, u16 offset, u8 reg_width)
94{
95 void __iomem *addr = core->bus->mmio + offset;
96 if (core->bus->mapped_core != core)
97 bcma_host_pci_switch_core(core);
98 switch (reg_width) {
99 case sizeof(u8):
100 iowrite8_rep(addr, buffer, count);
101 break;
102 case sizeof(u16):
103 WARN_ON(count & 1);
104 iowrite16_rep(addr, buffer, count >> 1);
105 break;
106 case sizeof(u32):
107 WARN_ON(count & 3);
108 iowrite32_rep(addr, buffer, count >> 2);
109 break;
110 default:
111 WARN_ON(1);
112 }
113}
114#endif
115
116static u32 bcma_host_pci_aread32(struct bcma_device *core, u16 offset)
117{
118 if (core->bus->mapped_core != core)
119 bcma_host_pci_switch_core(core);
120 return ioread32(core->bus->mmio + (1 * BCMA_CORE_SIZE) + offset);
121}
122
123static void bcma_host_pci_awrite32(struct bcma_device *core, u16 offset,
124 u32 value)
125{
126 if (core->bus->mapped_core != core)
127 bcma_host_pci_switch_core(core);
128 iowrite32(value, core->bus->mmio + (1 * BCMA_CORE_SIZE) + offset);
129}
130
131const struct bcma_host_ops bcma_host_pci_ops = {
132 .read8 = bcma_host_pci_read8,
133 .read16 = bcma_host_pci_read16,
134 .read32 = bcma_host_pci_read32,
135 .write8 = bcma_host_pci_write8,
136 .write16 = bcma_host_pci_write16,
137 .write32 = bcma_host_pci_write32,
138#ifdef CONFIG_BCMA_BLOCKIO
139 .block_read = bcma_host_pci_block_read,
140 .block_write = bcma_host_pci_block_write,
141#endif
142 .aread32 = bcma_host_pci_aread32,
143 .awrite32 = bcma_host_pci_awrite32,
144};
145
146static int bcma_host_pci_probe(struct pci_dev *dev,
147 const struct pci_device_id *id)
148{
149 struct bcma_bus *bus;
150 int err = -ENOMEM;
151 const char *name;
152 u32 val;
153
154 /* Alloc */
155 bus = kzalloc(sizeof(*bus), GFP_KERNEL);
156 if (!bus)
157 goto out;
158
159 /* Basic PCI configuration */
160 err = pci_enable_device(dev);
161 if (err)
162 goto err_kfree_bus;
163
164 name = dev_name(&dev->dev);
165 if (dev->driver && dev->driver->name)
166 name = dev->driver->name;
167 err = pci_request_regions(dev, name);
168 if (err)
169 goto err_pci_disable;
170 pci_set_master(dev);
171
172 /* Disable the RETRY_TIMEOUT register (0x41) to keep
173 * PCI Tx retries from interfering with C3 CPU state */
174 pci_read_config_dword(dev, 0x40, &val);
175 if ((val & 0x0000ff00) != 0)
176 pci_write_config_dword(dev, 0x40, val & 0xffff00ff);
177
178 /* SSB needed additional powering up, do we have any AMBA PCI cards? */
179 if (!pci_is_pcie(dev))
180 pr_err("PCI card detected, report problems.\n");
181
182 /* Map MMIO */
183 err = -ENOMEM;
184 bus->mmio = pci_iomap(dev, 0, ~0UL);
185 if (!bus->mmio)
186 goto err_pci_release_regions;
187
188 /* Host specific */
189 bus->host_pci = dev;
190 bus->hosttype = BCMA_HOSTTYPE_PCI;
191 bus->ops = &bcma_host_pci_ops;
192
193 /* Register */
194 err = bcma_bus_register(bus);
195 if (err)
196 goto err_pci_unmap_mmio;
197
198 pci_set_drvdata(dev, bus);
199
200out:
201 return err;
202
203err_pci_unmap_mmio:
204 pci_iounmap(dev, bus->mmio);
205err_pci_release_regions:
206 pci_release_regions(dev);
207err_pci_disable:
208 pci_disable_device(dev);
209err_kfree_bus:
210 kfree(bus);
211 return err;
212}
213
214static void bcma_host_pci_remove(struct pci_dev *dev)
215{
216 struct bcma_bus *bus = pci_get_drvdata(dev);
217
218 bcma_bus_unregister(bus);
219 pci_iounmap(dev, bus->mmio);
220 pci_release_regions(dev);
221 pci_disable_device(dev);
222 kfree(bus);
223 pci_set_drvdata(dev, NULL);
224}
225
226static DEFINE_PCI_DEVICE_TABLE(bcma_pci_bridge_tbl) = {
227 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x0576) },
228 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4331) },
229 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4353) },
230 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4357) },
231 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4727) },
232 { 0, },
233};
234MODULE_DEVICE_TABLE(pci, bcma_pci_bridge_tbl);
235
236static struct pci_driver bcma_pci_bridge_driver = {
237 .name = "bcma-pci-bridge",
238 .id_table = bcma_pci_bridge_tbl,
239 .probe = bcma_host_pci_probe,
240 .remove = bcma_host_pci_remove,
241};
242
243int __init bcma_host_pci_init(void)
244{
245 return pci_register_driver(&bcma_pci_bridge_driver);
246}
247
248void __exit bcma_host_pci_exit(void)
249{
250 pci_unregister_driver(&bcma_pci_bridge_driver);
251}
1/*
2 * Broadcom specific AMBA
3 * PCI Host
4 *
5 * Licensed under the GNU/GPL. See COPYING for details.
6 */
7
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>
13
14static void bcma_host_pci_switch_core(struct bcma_device *core)
15{
16 pci_write_config_dword(core->bus->host_pci, BCMA_PCI_BAR0_WIN,
17 core->addr);
18 pci_write_config_dword(core->bus->host_pci, BCMA_PCI_BAR0_WIN2,
19 core->wrap);
20 core->bus->mapped_core = core;
21 pr_debug("Switched to core: 0x%X\n", core->id.id);
22}
23
24/* Provides access to the requested core. Returns base offset that has to be
25 * used. It makes use of fixed windows when possible. */
26static u16 bcma_host_pci_provide_access_to_core(struct bcma_device *core)
27{
28 switch (core->id.id) {
29 case BCMA_CORE_CHIPCOMMON:
30 return 3 * BCMA_CORE_SIZE;
31 case BCMA_CORE_PCIE:
32 return 2 * BCMA_CORE_SIZE;
33 }
34
35 if (core->bus->mapped_core != core)
36 bcma_host_pci_switch_core(core);
37 return 0;
38}
39
40static u8 bcma_host_pci_read8(struct bcma_device *core, u16 offset)
41{
42 offset += bcma_host_pci_provide_access_to_core(core);
43 return ioread8(core->bus->mmio + offset);
44}
45
46static u16 bcma_host_pci_read16(struct bcma_device *core, u16 offset)
47{
48 offset += bcma_host_pci_provide_access_to_core(core);
49 return ioread16(core->bus->mmio + offset);
50}
51
52static u32 bcma_host_pci_read32(struct bcma_device *core, u16 offset)
53{
54 offset += bcma_host_pci_provide_access_to_core(core);
55 return ioread32(core->bus->mmio + offset);
56}
57
58static void bcma_host_pci_write8(struct bcma_device *core, u16 offset,
59 u8 value)
60{
61 offset += bcma_host_pci_provide_access_to_core(core);
62 iowrite8(value, core->bus->mmio + offset);
63}
64
65static void bcma_host_pci_write16(struct bcma_device *core, u16 offset,
66 u16 value)
67{
68 offset += bcma_host_pci_provide_access_to_core(core);
69 iowrite16(value, core->bus->mmio + offset);
70}
71
72static void bcma_host_pci_write32(struct bcma_device *core, u16 offset,
73 u32 value)
74{
75 offset += bcma_host_pci_provide_access_to_core(core);
76 iowrite32(value, core->bus->mmio + offset);
77}
78
79#ifdef CONFIG_BCMA_BLOCKIO
80void bcma_host_pci_block_read(struct bcma_device *core, void *buffer,
81 size_t count, u16 offset, u8 reg_width)
82{
83 void __iomem *addr = core->bus->mmio + offset;
84 if (core->bus->mapped_core != core)
85 bcma_host_pci_switch_core(core);
86 switch (reg_width) {
87 case sizeof(u8):
88 ioread8_rep(addr, buffer, count);
89 break;
90 case sizeof(u16):
91 WARN_ON(count & 1);
92 ioread16_rep(addr, buffer, count >> 1);
93 break;
94 case sizeof(u32):
95 WARN_ON(count & 3);
96 ioread32_rep(addr, buffer, count >> 2);
97 break;
98 default:
99 WARN_ON(1);
100 }
101}
102
103void bcma_host_pci_block_write(struct bcma_device *core, const void *buffer,
104 size_t count, u16 offset, u8 reg_width)
105{
106 void __iomem *addr = core->bus->mmio + offset;
107 if (core->bus->mapped_core != core)
108 bcma_host_pci_switch_core(core);
109 switch (reg_width) {
110 case sizeof(u8):
111 iowrite8_rep(addr, buffer, count);
112 break;
113 case sizeof(u16):
114 WARN_ON(count & 1);
115 iowrite16_rep(addr, buffer, count >> 1);
116 break;
117 case sizeof(u32):
118 WARN_ON(count & 3);
119 iowrite32_rep(addr, buffer, count >> 2);
120 break;
121 default:
122 WARN_ON(1);
123 }
124}
125#endif
126
127static u32 bcma_host_pci_aread32(struct bcma_device *core, u16 offset)
128{
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);
132}
133
134static void bcma_host_pci_awrite32(struct bcma_device *core, u16 offset,
135 u32 value)
136{
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);
140}
141
142const 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,
152#endif
153 .aread32 = bcma_host_pci_aread32,
154 .awrite32 = bcma_host_pci_awrite32,
155};
156
157static int __devinit bcma_host_pci_probe(struct pci_dev *dev,
158 const struct pci_device_id *id)
159{
160 struct bcma_bus *bus;
161 int err = -ENOMEM;
162 const char *name;
163 u32 val;
164
165 /* Alloc */
166 bus = kzalloc(sizeof(*bus), GFP_KERNEL);
167 if (!bus)
168 goto out;
169
170 /* Basic PCI configuration */
171 err = pci_enable_device(dev);
172 if (err)
173 goto err_kfree_bus;
174
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);
179 if (err)
180 goto err_pci_disable;
181 pci_set_master(dev);
182
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);
188
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");
192
193 /* Map MMIO */
194 err = -ENOMEM;
195 bus->mmio = pci_iomap(dev, 0, ~0UL);
196 if (!bus->mmio)
197 goto err_pci_release_regions;
198
199 /* Host specific */
200 bus->host_pci = dev;
201 bus->hosttype = BCMA_HOSTTYPE_PCI;
202 bus->ops = &bcma_host_pci_ops;
203
204 bus->boardinfo.vendor = bus->host_pci->subsystem_vendor;
205 bus->boardinfo.type = bus->host_pci->subsystem_device;
206
207 /* Register */
208 err = bcma_bus_register(bus);
209 if (err)
210 goto err_pci_unmap_mmio;
211
212 pci_set_drvdata(dev, bus);
213
214out:
215 return err;
216
217err_pci_unmap_mmio:
218 pci_iounmap(dev, bus->mmio);
219err_pci_release_regions:
220 pci_release_regions(dev);
221err_pci_disable:
222 pci_disable_device(dev);
223err_kfree_bus:
224 kfree(bus);
225 return err;
226}
227
228static void __devexit bcma_host_pci_remove(struct pci_dev *dev)
229{
230 struct bcma_bus *bus = pci_get_drvdata(dev);
231
232 bcma_bus_unregister(bus);
233 pci_iounmap(dev, bus->mmio);
234 pci_release_regions(dev);
235 pci_disable_device(dev);
236 kfree(bus);
237 pci_set_drvdata(dev, NULL);
238}
239
240#ifdef CONFIG_PM
241static int bcma_host_pci_suspend(struct device *dev)
242{
243 struct pci_dev *pdev = to_pci_dev(dev);
244 struct bcma_bus *bus = pci_get_drvdata(pdev);
245
246 bus->mapped_core = NULL;
247
248 return bcma_bus_suspend(bus);
249}
250
251static int bcma_host_pci_resume(struct device *dev)
252{
253 struct pci_dev *pdev = to_pci_dev(dev);
254 struct bcma_bus *bus = pci_get_drvdata(pdev);
255
256 return bcma_bus_resume(bus);
257}
258
259static SIMPLE_DEV_PM_OPS(bcma_pm_ops, bcma_host_pci_suspend,
260 bcma_host_pci_resume);
261#define BCMA_PM_OPS (&bcma_pm_ops)
262
263#else /* CONFIG_PM */
264
265#define BCMA_PM_OPS NULL
266
267#endif /* CONFIG_PM */
268
269static DEFINE_PCI_DEVICE_TABLE(bcma_pci_bridge_tbl) = {
270 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x0576) },
271 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4331) },
272 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4353) },
273 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4357) },
274 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4727) },
275 { 0, },
276};
277MODULE_DEVICE_TABLE(pci, bcma_pci_bridge_tbl);
278
279static struct pci_driver bcma_pci_bridge_driver = {
280 .name = "bcma-pci-bridge",
281 .id_table = bcma_pci_bridge_tbl,
282 .probe = bcma_host_pci_probe,
283 .remove = __devexit_p(bcma_host_pci_remove),
284 .driver.pm = BCMA_PM_OPS,
285};
286
287int __init bcma_host_pci_init(void)
288{
289 return pci_register_driver(&bcma_pci_bridge_driver);
290}
291
292void __exit bcma_host_pci_exit(void)
293{
294 pci_unregister_driver(&bcma_pci_bridge_driver);
295}