2 Copyright (C) 2009 - 2010 Ivo van Doorn <IvDoorn@gmail.com>
3 Copyright (C) 2009 Alban Browaeys <prahal@yahoo.com>
4 Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org>
5 Copyright (C) 2009 Luis Correia <luis.f.correia@gmail.com>
6 Copyright (C) 2009 Mattias Nissler <mattias.nissler@gmx.de>
7 Copyright (C) 2009 Mark Asselstine <asselsm@gmail.com>
8 Copyright (C) 2009 Xose Vazquez Perez <xose.vazquez@gmail.com>
9 Copyright (C) 2009 Bart Zolnierkiewicz <bzolnier@gmail.com>
10 <http://rt2x00.serialmonkey.com>
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the
24 Free Software Foundation, Inc.,
25 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 Abstract: rt2800pci device specific routines.
31 Supported chipsets: RT2800E & RT2800ED.
34 #include <linux/delay.h>
35 #include <linux/etherdevice.h>
36 #include <linux/init.h>
37 #include <linux/kernel.h>
38 #include <linux/module.h>
39 #include <linux/pci.h>
40 #include <linux/eeprom_93cx6.h>
43 #include "rt2x00mmio.h"
44 #include "rt2x00pci.h"
45 #include "rt2800lib.h"
46 #include "rt2800mmio.h"
48 #include "rt2800pci.h"
51 * Allow hardware encryption to be disabled.
53 static bool modparam_nohwcrypt = false;
54 module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
55 MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
57 static bool rt2800pci_hwcrypt_disabled(struct rt2x00_dev *rt2x00dev)
59 return modparam_nohwcrypt;
62 static void rt2800pci_mcu_status(struct rt2x00_dev *rt2x00dev, const u8 token)
68 * SOC devices don't support MCU requests.
70 if (rt2x00_is_soc(rt2x00dev))
73 for (i = 0; i < 200; i++) {
74 rt2x00mmio_register_read(rt2x00dev, H2M_MAILBOX_CID, ®);
76 if ((rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD0) == token) ||
77 (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD1) == token) ||
78 (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD2) == token) ||
79 (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD3) == token))
82 udelay(REGISTER_BUSY_DELAY);
86 rt2x00_err(rt2x00dev, "MCU request failed, no response from hardware\n");
88 rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
89 rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
92 static void rt2800pci_eepromregister_read(struct eeprom_93cx6 *eeprom)
94 struct rt2x00_dev *rt2x00dev = eeprom->data;
97 rt2x00mmio_register_read(rt2x00dev, E2PROM_CSR, ®);
99 eeprom->reg_data_in = !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_IN);
100 eeprom->reg_data_out = !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_OUT);
101 eeprom->reg_data_clock =
102 !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_CLOCK);
103 eeprom->reg_chip_select =
104 !!rt2x00_get_field32(reg, E2PROM_CSR_CHIP_SELECT);
107 static void rt2800pci_eepromregister_write(struct eeprom_93cx6 *eeprom)
109 struct rt2x00_dev *rt2x00dev = eeprom->data;
112 rt2x00_set_field32(®, E2PROM_CSR_DATA_IN, !!eeprom->reg_data_in);
113 rt2x00_set_field32(®, E2PROM_CSR_DATA_OUT, !!eeprom->reg_data_out);
114 rt2x00_set_field32(®, E2PROM_CSR_DATA_CLOCK,
115 !!eeprom->reg_data_clock);
116 rt2x00_set_field32(®, E2PROM_CSR_CHIP_SELECT,
117 !!eeprom->reg_chip_select);
119 rt2x00mmio_register_write(rt2x00dev, E2PROM_CSR, reg);
122 static int rt2800pci_read_eeprom_pci(struct rt2x00_dev *rt2x00dev)
124 struct eeprom_93cx6 eeprom;
127 rt2x00mmio_register_read(rt2x00dev, E2PROM_CSR, ®);
129 eeprom.data = rt2x00dev;
130 eeprom.register_read = rt2800pci_eepromregister_read;
131 eeprom.register_write = rt2800pci_eepromregister_write;
132 switch (rt2x00_get_field32(reg, E2PROM_CSR_TYPE))
135 eeprom.width = PCI_EEPROM_WIDTH_93C46;
138 eeprom.width = PCI_EEPROM_WIDTH_93C66;
141 eeprom.width = PCI_EEPROM_WIDTH_93C86;
144 eeprom.reg_data_in = 0;
145 eeprom.reg_data_out = 0;
146 eeprom.reg_data_clock = 0;
147 eeprom.reg_chip_select = 0;
149 eeprom_93cx6_multiread(&eeprom, EEPROM_BASE, rt2x00dev->eeprom,
150 EEPROM_SIZE / sizeof(u16));
155 static int rt2800pci_efuse_detect(struct rt2x00_dev *rt2x00dev)
157 return rt2800_efuse_detect(rt2x00dev);
160 static inline int rt2800pci_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev)
162 return rt2800_read_eeprom_efuse(rt2x00dev);
168 static char *rt2800pci_get_firmware_name(struct rt2x00_dev *rt2x00dev)
171 * Chip rt3290 use specific 4KB firmware named rt3290.bin.
173 if (rt2x00_rt(rt2x00dev, RT3290))
174 return FIRMWARE_RT3290;
176 return FIRMWARE_RT2860;
179 static int rt2800pci_write_firmware(struct rt2x00_dev *rt2x00dev,
180 const u8 *data, const size_t len)
185 * enable Host program ram write selection
188 rt2x00_set_field32(®, PBF_SYS_CTRL_HOST_RAM_WRITE, 1);
189 rt2x00mmio_register_write(rt2x00dev, PBF_SYS_CTRL, reg);
192 * Write firmware to device.
194 rt2x00mmio_register_multiwrite(rt2x00dev, FIRMWARE_IMAGE_BASE,
197 rt2x00mmio_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000);
198 rt2x00mmio_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00001);
200 rt2x00mmio_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
201 rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
207 * Device state switch handlers.
209 static int rt2800pci_enable_radio(struct rt2x00_dev *rt2x00dev)
213 retval = rt2800mmio_enable_radio(rt2x00dev);
217 /* After resume MCU_BOOT_SIGNAL will trash these. */
218 rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
219 rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
221 rt2800_mcu_request(rt2x00dev, MCU_SLEEP, TOKEN_RADIO_OFF, 0xff, 0x02);
222 rt2800pci_mcu_status(rt2x00dev, TOKEN_RADIO_OFF);
224 rt2800_mcu_request(rt2x00dev, MCU_WAKEUP, TOKEN_WAKEUP, 0, 0);
225 rt2800pci_mcu_status(rt2x00dev, TOKEN_WAKEUP);
230 static int rt2800pci_set_state(struct rt2x00_dev *rt2x00dev,
231 enum dev_state state)
233 if (state == STATE_AWAKE) {
234 rt2800_mcu_request(rt2x00dev, MCU_WAKEUP, TOKEN_WAKEUP,
236 rt2800pci_mcu_status(rt2x00dev, TOKEN_WAKEUP);
237 } else if (state == STATE_SLEEP) {
238 rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_STATUS,
240 rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_CID,
242 rt2800_mcu_request(rt2x00dev, MCU_SLEEP, TOKEN_SLEEP,
249 static int rt2800pci_set_device_state(struct rt2x00_dev *rt2x00dev,
250 enum dev_state state)
256 retval = rt2800pci_enable_radio(rt2x00dev);
258 case STATE_RADIO_OFF:
260 * After the radio has been disabled, the device should
261 * be put to sleep for powersaving.
263 rt2800pci_set_state(rt2x00dev, STATE_SLEEP);
265 case STATE_RADIO_IRQ_ON:
266 case STATE_RADIO_IRQ_OFF:
267 rt2800mmio_toggle_irq(rt2x00dev, state);
269 case STATE_DEEP_SLEEP:
273 retval = rt2800pci_set_state(rt2x00dev, state);
280 if (unlikely(retval))
281 rt2x00_err(rt2x00dev, "Device failed to enter state %d (%d)\n",
288 * Device probe functions.
290 static int rt2800pci_read_eeprom(struct rt2x00_dev *rt2x00dev)
294 if (rt2800pci_efuse_detect(rt2x00dev))
295 retval = rt2800pci_read_eeprom_efuse(rt2x00dev);
297 retval = rt2800pci_read_eeprom_pci(rt2x00dev);
302 static const struct ieee80211_ops rt2800pci_mac80211_ops = {
304 .start = rt2x00mac_start,
305 .stop = rt2x00mac_stop,
306 .add_interface = rt2x00mac_add_interface,
307 .remove_interface = rt2x00mac_remove_interface,
308 .config = rt2x00mac_config,
309 .configure_filter = rt2x00mac_configure_filter,
310 .set_key = rt2x00mac_set_key,
311 .sw_scan_start = rt2x00mac_sw_scan_start,
312 .sw_scan_complete = rt2x00mac_sw_scan_complete,
313 .get_stats = rt2x00mac_get_stats,
314 .get_tkip_seq = rt2800_get_tkip_seq,
315 .set_rts_threshold = rt2800_set_rts_threshold,
316 .sta_add = rt2x00mac_sta_add,
317 .sta_remove = rt2x00mac_sta_remove,
318 .bss_info_changed = rt2x00mac_bss_info_changed,
319 .conf_tx = rt2800_conf_tx,
320 .get_tsf = rt2800_get_tsf,
321 .rfkill_poll = rt2x00mac_rfkill_poll,
322 .ampdu_action = rt2800_ampdu_action,
323 .flush = rt2x00mac_flush,
324 .get_survey = rt2800_get_survey,
325 .get_ringparam = rt2x00mac_get_ringparam,
326 .tx_frames_pending = rt2x00mac_tx_frames_pending,
329 static const struct rt2800_ops rt2800pci_rt2800_ops = {
330 .register_read = rt2x00mmio_register_read,
331 .register_read_lock = rt2x00mmio_register_read, /* same for PCI */
332 .register_write = rt2x00mmio_register_write,
333 .register_write_lock = rt2x00mmio_register_write, /* same for PCI */
334 .register_multiread = rt2x00mmio_register_multiread,
335 .register_multiwrite = rt2x00mmio_register_multiwrite,
336 .regbusy_read = rt2x00mmio_regbusy_read,
337 .read_eeprom = rt2800pci_read_eeprom,
338 .hwcrypt_disabled = rt2800pci_hwcrypt_disabled,
339 .drv_write_firmware = rt2800pci_write_firmware,
340 .drv_init_registers = rt2800mmio_init_registers,
341 .drv_get_txwi = rt2800mmio_get_txwi,
344 static const struct rt2x00lib_ops rt2800pci_rt2x00_ops = {
345 .irq_handler = rt2800mmio_interrupt,
346 .txstatus_tasklet = rt2800mmio_txstatus_tasklet,
347 .pretbtt_tasklet = rt2800mmio_pretbtt_tasklet,
348 .tbtt_tasklet = rt2800mmio_tbtt_tasklet,
349 .rxdone_tasklet = rt2800mmio_rxdone_tasklet,
350 .autowake_tasklet = rt2800mmio_autowake_tasklet,
351 .probe_hw = rt2800_probe_hw,
352 .get_firmware_name = rt2800pci_get_firmware_name,
353 .check_firmware = rt2800_check_firmware,
354 .load_firmware = rt2800_load_firmware,
355 .initialize = rt2x00mmio_initialize,
356 .uninitialize = rt2x00mmio_uninitialize,
357 .get_entry_state = rt2800mmio_get_entry_state,
358 .clear_entry = rt2800mmio_clear_entry,
359 .set_device_state = rt2800pci_set_device_state,
360 .rfkill_poll = rt2800_rfkill_poll,
361 .link_stats = rt2800_link_stats,
362 .reset_tuner = rt2800_reset_tuner,
363 .link_tuner = rt2800_link_tuner,
364 .gain_calibration = rt2800_gain_calibration,
365 .vco_calibration = rt2800_vco_calibration,
366 .start_queue = rt2800mmio_start_queue,
367 .kick_queue = rt2800mmio_kick_queue,
368 .stop_queue = rt2800mmio_stop_queue,
369 .flush_queue = rt2x00mmio_flush_queue,
370 .write_tx_desc = rt2800mmio_write_tx_desc,
371 .write_tx_data = rt2800_write_tx_data,
372 .write_beacon = rt2800_write_beacon,
373 .clear_beacon = rt2800_clear_beacon,
374 .fill_rxdone = rt2800mmio_fill_rxdone,
375 .config_shared_key = rt2800_config_shared_key,
376 .config_pairwise_key = rt2800_config_pairwise_key,
377 .config_filter = rt2800_config_filter,
378 .config_intf = rt2800_config_intf,
379 .config_erp = rt2800_config_erp,
380 .config_ant = rt2800_config_ant,
381 .config = rt2800_config,
382 .sta_add = rt2800_sta_add,
383 .sta_remove = rt2800_sta_remove,
386 static const struct rt2x00_ops rt2800pci_ops = {
387 .name = KBUILD_MODNAME,
388 .drv_data_size = sizeof(struct rt2800_drv_data),
390 .eeprom_size = EEPROM_SIZE,
392 .tx_queues = NUM_TX_QUEUES,
393 .queue_init = rt2800mmio_queue_init,
394 .lib = &rt2800pci_rt2x00_ops,
395 .drv = &rt2800pci_rt2800_ops,
396 .hw = &rt2800pci_mac80211_ops,
397 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
398 .debugfs = &rt2800_rt2x00debug,
399 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
403 * RT2800pci module information.
405 static DEFINE_PCI_DEVICE_TABLE(rt2800pci_device_table) = {
406 { PCI_DEVICE(0x1814, 0x0601) },
407 { PCI_DEVICE(0x1814, 0x0681) },
408 { PCI_DEVICE(0x1814, 0x0701) },
409 { PCI_DEVICE(0x1814, 0x0781) },
410 { PCI_DEVICE(0x1814, 0x3090) },
411 { PCI_DEVICE(0x1814, 0x3091) },
412 { PCI_DEVICE(0x1814, 0x3092) },
413 { PCI_DEVICE(0x1432, 0x7708) },
414 { PCI_DEVICE(0x1432, 0x7727) },
415 { PCI_DEVICE(0x1432, 0x7728) },
416 { PCI_DEVICE(0x1432, 0x7738) },
417 { PCI_DEVICE(0x1432, 0x7748) },
418 { PCI_DEVICE(0x1432, 0x7758) },
419 { PCI_DEVICE(0x1432, 0x7768) },
420 { PCI_DEVICE(0x1462, 0x891a) },
421 { PCI_DEVICE(0x1a3b, 0x1059) },
422 #ifdef CONFIG_RT2800PCI_RT3290
423 { PCI_DEVICE(0x1814, 0x3290) },
425 #ifdef CONFIG_RT2800PCI_RT33XX
426 { PCI_DEVICE(0x1814, 0x3390) },
428 #ifdef CONFIG_RT2800PCI_RT35XX
429 { PCI_DEVICE(0x1432, 0x7711) },
430 { PCI_DEVICE(0x1432, 0x7722) },
431 { PCI_DEVICE(0x1814, 0x3060) },
432 { PCI_DEVICE(0x1814, 0x3062) },
433 { PCI_DEVICE(0x1814, 0x3562) },
434 { PCI_DEVICE(0x1814, 0x3592) },
435 { PCI_DEVICE(0x1814, 0x3593) },
436 { PCI_DEVICE(0x1814, 0x359f) },
438 #ifdef CONFIG_RT2800PCI_RT53XX
439 { PCI_DEVICE(0x1814, 0x5360) },
440 { PCI_DEVICE(0x1814, 0x5362) },
441 { PCI_DEVICE(0x1814, 0x5390) },
442 { PCI_DEVICE(0x1814, 0x5392) },
443 { PCI_DEVICE(0x1814, 0x539a) },
444 { PCI_DEVICE(0x1814, 0x539b) },
445 { PCI_DEVICE(0x1814, 0x539f) },
450 MODULE_AUTHOR(DRV_PROJECT);
451 MODULE_VERSION(DRV_VERSION);
452 MODULE_DESCRIPTION("Ralink RT2800 PCI & PCMCIA Wireless LAN driver.");
453 MODULE_SUPPORTED_DEVICE("Ralink RT2860 PCI & PCMCIA chipset based cards");
454 MODULE_FIRMWARE(FIRMWARE_RT2860);
455 MODULE_DEVICE_TABLE(pci, rt2800pci_device_table);
456 MODULE_LICENSE("GPL");
458 static int rt2800pci_probe(struct pci_dev *pci_dev,
459 const struct pci_device_id *id)
461 return rt2x00pci_probe(pci_dev, &rt2800pci_ops);
464 static struct pci_driver rt2800pci_driver = {
465 .name = KBUILD_MODNAME,
466 .id_table = rt2800pci_device_table,
467 .probe = rt2800pci_probe,
468 .remove = rt2x00pci_remove,
469 .suspend = rt2x00pci_suspend,
470 .resume = rt2x00pci_resume,
473 module_pci_driver(rt2800pci_driver);