Blame view

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