This source file includes following definitions.
- ath5k_pci_read_cachesize
- ath5k_pci_eeprom_read
- ath5k_hw_read_srev
- ath5k_pci_eeprom_read_mac
- ath5k_pci_probe
- ath5k_pci_remove
- ath5k_pci_suspend
- ath5k_pci_resume
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18
19 #include <linux/nl80211.h>
20 #include <linux/pci.h>
21 #include <linux/etherdevice.h>
22 #include <linux/module.h>
23 #include "../ath.h"
24 #include "ath5k.h"
25 #include "debug.h"
26 #include "base.h"
27 #include "reg.h"
28
29
30 static const struct pci_device_id ath5k_pci_id_table[] = {
31 { PCI_VDEVICE(ATHEROS, 0x0207) },
32 { PCI_VDEVICE(ATHEROS, 0x0007) },
33 { PCI_VDEVICE(ATHEROS, 0x0011) },
34 { PCI_VDEVICE(ATHEROS, 0x0012) },
35 { PCI_VDEVICE(ATHEROS, 0x0013) },
36 { PCI_VDEVICE(3COM_2, 0x0013) },
37 { PCI_VDEVICE(3COM, 0x0013) },
38 { PCI_VDEVICE(ATHEROS, 0x1014) },
39 { PCI_VDEVICE(ATHEROS, 0x0014) },
40 { PCI_VDEVICE(ATHEROS, 0x0015) },
41 { PCI_VDEVICE(ATHEROS, 0x0016) },
42 { PCI_VDEVICE(ATHEROS, 0x0017) },
43 { PCI_VDEVICE(ATHEROS, 0x0018) },
44 { PCI_VDEVICE(ATHEROS, 0x0019) },
45 { PCI_VDEVICE(ATHEROS, 0x001a) },
46 { PCI_VDEVICE(ATHEROS, 0x001b) },
47 { PCI_VDEVICE(ATHEROS, 0x001c) },
48 { PCI_VDEVICE(ATHEROS, 0x001d) },
49 { PCI_VDEVICE(ATHEROS, 0xff1b) },
50 { 0 }
51 };
52 MODULE_DEVICE_TABLE(pci, ath5k_pci_id_table);
53
54
55 static void ath5k_pci_read_cachesize(struct ath_common *common, int *csz)
56 {
57 struct ath5k_hw *ah = (struct ath5k_hw *) common->priv;
58 u8 u8tmp;
59
60 pci_read_config_byte(ah->pdev, PCI_CACHE_LINE_SIZE, &u8tmp);
61 *csz = (int)u8tmp;
62
63
64
65
66
67
68
69 if (*csz == 0)
70 *csz = L1_CACHE_BYTES >> 2;
71 }
72
73
74
75
76 static bool
77 ath5k_pci_eeprom_read(struct ath_common *common, u32 offset, u16 *data)
78 {
79 struct ath5k_hw *ah = (struct ath5k_hw *) common->ah;
80 u32 status, timeout;
81
82
83
84
85 if (ah->ah_version == AR5K_AR5210) {
86 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
87 (void)ath5k_hw_reg_read(ah, AR5K_EEPROM_BASE + (4 * offset));
88 } else {
89 ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
90 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
91 AR5K_EEPROM_CMD_READ);
92 }
93
94 for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
95 status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
96 if (status & AR5K_EEPROM_STAT_RDDONE) {
97 if (status & AR5K_EEPROM_STAT_RDERR)
98 return false;
99 *data = (u16)(ath5k_hw_reg_read(ah, AR5K_EEPROM_DATA) &
100 0xffff);
101 return true;
102 }
103 usleep_range(15, 20);
104 }
105
106 return false;
107 }
108
109 int ath5k_hw_read_srev(struct ath5k_hw *ah)
110 {
111 ah->ah_mac_srev = ath5k_hw_reg_read(ah, AR5K_SREV);
112 return 0;
113 }
114
115
116
117
118 static int ath5k_pci_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
119 {
120 u8 mac_d[ETH_ALEN] = {};
121 u32 total, offset;
122 u16 data;
123 int octet;
124
125 AR5K_EEPROM_READ(0x20, data);
126
127 for (offset = 0x1f, octet = 0, total = 0; offset >= 0x1d; offset--) {
128 AR5K_EEPROM_READ(offset, data);
129
130 total += data;
131 mac_d[octet + 1] = data & 0xff;
132 mac_d[octet] = data >> 8;
133 octet += 2;
134 }
135
136 if (!total || total == 3 * 0xffff)
137 return -EINVAL;
138
139 memcpy(mac, mac_d, ETH_ALEN);
140
141 return 0;
142 }
143
144
145
146 static const struct ath_bus_ops ath_pci_bus_ops = {
147 .ath_bus_type = ATH_PCI,
148 .read_cachesize = ath5k_pci_read_cachesize,
149 .eeprom_read = ath5k_pci_eeprom_read,
150 .eeprom_read_mac = ath5k_pci_eeprom_read_mac,
151 };
152
153
154
155
156
157 static int
158 ath5k_pci_probe(struct pci_dev *pdev,
159 const struct pci_device_id *id)
160 {
161 void __iomem *mem;
162 struct ath5k_hw *ah;
163 struct ieee80211_hw *hw;
164 int ret;
165 u8 csz;
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S);
186
187 ret = pci_enable_device(pdev);
188 if (ret) {
189 dev_err(&pdev->dev, "can't enable device\n");
190 goto err;
191 }
192
193
194 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
195 if (ret) {
196 dev_err(&pdev->dev, "32-bit DMA not available\n");
197 goto err_dis;
198 }
199
200
201
202
203
204 pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &csz);
205 if (csz == 0) {
206
207
208
209
210
211
212
213 csz = L1_CACHE_BYTES >> 2;
214 pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, csz);
215 }
216
217
218
219
220
221 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0xa8);
222
223
224 pci_set_master(pdev);
225
226
227
228
229
230 pci_write_config_byte(pdev, 0x41, 0);
231
232 ret = pci_request_region(pdev, 0, "ath5k");
233 if (ret) {
234 dev_err(&pdev->dev, "cannot reserve PCI memory region\n");
235 goto err_dis;
236 }
237
238 mem = pci_iomap(pdev, 0, 0);
239 if (!mem) {
240 dev_err(&pdev->dev, "cannot remap PCI memory region\n");
241 ret = -EIO;
242 goto err_reg;
243 }
244
245
246
247
248
249 hw = ieee80211_alloc_hw(sizeof(*ah), &ath5k_hw_ops);
250 if (hw == NULL) {
251 dev_err(&pdev->dev, "cannot allocate ieee80211_hw\n");
252 ret = -ENOMEM;
253 goto err_map;
254 }
255
256 dev_info(&pdev->dev, "registered as '%s'\n", wiphy_name(hw->wiphy));
257
258 ah = hw->priv;
259 ah->hw = hw;
260 ah->pdev = pdev;
261 ah->dev = &pdev->dev;
262 ah->irq = pdev->irq;
263 ah->devid = id->device;
264 ah->iobase = mem;
265
266
267 ret = ath5k_init_ah(ah, &ath_pci_bus_ops);
268 if (ret)
269 goto err_free;
270
271
272 pci_set_drvdata(pdev, hw);
273
274 return 0;
275 err_free:
276 ieee80211_free_hw(hw);
277 err_map:
278 pci_iounmap(pdev, mem);
279 err_reg:
280 pci_release_region(pdev, 0);
281 err_dis:
282 pci_disable_device(pdev);
283 err:
284 return ret;
285 }
286
287 static void
288 ath5k_pci_remove(struct pci_dev *pdev)
289 {
290 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
291 struct ath5k_hw *ah = hw->priv;
292
293 ath5k_deinit_ah(ah);
294 pci_iounmap(pdev, ah->iobase);
295 pci_release_region(pdev, 0);
296 pci_disable_device(pdev);
297 ieee80211_free_hw(hw);
298 }
299
300 #ifdef CONFIG_PM_SLEEP
301 static int ath5k_pci_suspend(struct device *dev)
302 {
303 struct pci_dev *pdev = to_pci_dev(dev);
304 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
305 struct ath5k_hw *ah = hw->priv;
306
307 ath5k_led_off(ah);
308 return 0;
309 }
310
311 static int ath5k_pci_resume(struct device *dev)
312 {
313 struct pci_dev *pdev = to_pci_dev(dev);
314 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
315 struct ath5k_hw *ah = hw->priv;
316
317
318
319
320
321
322 pci_write_config_byte(pdev, 0x41, 0);
323
324 ath5k_led_enable(ah);
325 return 0;
326 }
327
328 static SIMPLE_DEV_PM_OPS(ath5k_pm_ops, ath5k_pci_suspend, ath5k_pci_resume);
329 #define ATH5K_PM_OPS (&ath5k_pm_ops)
330 #else
331 #define ATH5K_PM_OPS NULL
332 #endif
333
334 static struct pci_driver ath5k_pci_driver = {
335 .name = KBUILD_MODNAME,
336 .id_table = ath5k_pci_id_table,
337 .probe = ath5k_pci_probe,
338 .remove = ath5k_pci_remove,
339 .driver.pm = ATH5K_PM_OPS,
340 };
341
342 module_pci_driver(ath5k_pci_driver);