blob: 344a73ddd3e50b98e9167b7301cf6795b9fa7e16 [file] [log] [blame]
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +02001/*
Ivo van Doorn96481b22010-08-06 20:47:57 +02002 Copyright (C) 2009 - 2010 Ivo van Doorn <IvDoorn@gmail.com>
Gertjan van Wingerde9c9a0d12009-11-08 16:39:55 +01003 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>
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +020010 <http://rt2x00.serialmonkey.com>
11
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.
16
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.
21
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.
26 */
27
28/*
29 Module: rt2800pci
30 Abstract: rt2800pci device specific routines.
31 Supported chipsets: RT2800E & RT2800ED.
32 */
33
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +020034#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/platform_device.h>
41#include <linux/eeprom_93cx6.h>
42
43#include "rt2x00.h"
Gabor Juhos69a2bac2013-03-29 15:52:27 +010044#include "rt2x00mmio.h"
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +020045#include "rt2x00pci.h"
46#include "rt2x00soc.h"
Bartlomiej Zolnierkiewicz7ef5cc92009-11-04 18:35:32 +010047#include "rt2800lib.h"
Gabor Juhos0bc202b2013-10-17 09:42:17 +020048#include "rt2800mmio.h"
Bartlomiej Zolnierkiewiczb54f78a2009-11-04 18:35:54 +010049#include "rt2800.h"
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +020050#include "rt2800pci.h"
51
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +020052/*
53 * Allow hardware encryption to be disabled.
54 */
Rusty Russelleb939922011-12-19 14:08:01 +000055static bool modparam_nohwcrypt = false;
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +020056module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
57MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
58
Gertjan van Wingerdead417a52012-09-03 03:25:51 +020059static bool rt2800pci_hwcrypt_disabled(struct rt2x00_dev *rt2x00dev)
60{
61 return modparam_nohwcrypt;
62}
63
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +020064static void rt2800pci_mcu_status(struct rt2x00_dev *rt2x00dev, const u8 token)
65{
66 unsigned int i;
67 u32 reg;
68
Luis Correiaf18d4462010-04-03 12:49:53 +010069 /*
70 * SOC devices don't support MCU requests.
71 */
72 if (rt2x00_is_soc(rt2x00dev))
73 return;
74
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +020075 for (i = 0; i < 200; i++) {
Gabor Juhosb9570b62013-04-05 08:27:04 +020076 rt2x00mmio_register_read(rt2x00dev, H2M_MAILBOX_CID, &reg);
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +020077
78 if ((rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD0) == token) ||
79 (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD1) == token) ||
80 (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD2) == token) ||
81 (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD3) == token))
82 break;
83
84 udelay(REGISTER_BUSY_DELAY);
85 }
86
87 if (i == 200)
Joe Perchesec9c4982013-04-19 08:33:40 -070088 rt2x00_err(rt2x00dev, "MCU request failed, no response from hardware\n");
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +020089
Gabor Juhosb9570b62013-04-05 08:27:04 +020090 rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
91 rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +020092}
93
John Crispin5818a462013-03-13 13:20:15 +010094#if defined(CONFIG_SOC_RT288X) || defined(CONFIG_SOC_RT305X)
Gabor Juhosa02308e2012-12-29 14:51:51 +010095static int rt2800pci_read_eeprom_soc(struct rt2x00_dev *rt2x00dev)
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +020096{
Gertjan van Wingerdeef8397c2010-11-13 19:11:22 +010097 void __iomem *base_addr = ioremap(0x1F040000, EEPROM_SIZE);
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +020098
Gabor Juhosa02308e2012-12-29 14:51:51 +010099 if (!base_addr)
100 return -ENOMEM;
101
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200102 memcpy_fromio(rt2x00dev->eeprom, base_addr, EEPROM_SIZE);
Gertjan van Wingerdeef8397c2010-11-13 19:11:22 +0100103
104 iounmap(base_addr);
Gabor Juhosa02308e2012-12-29 14:51:51 +0100105 return 0;
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200106}
107#else
Gabor Juhosa02308e2012-12-29 14:51:51 +0100108static inline int rt2800pci_read_eeprom_soc(struct rt2x00_dev *rt2x00dev)
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200109{
Gabor Juhosa02308e2012-12-29 14:51:51 +0100110 return -ENOMEM;
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200111}
John Crispin5818a462013-03-13 13:20:15 +0100112#endif /* CONFIG_SOC_RT288X || CONFIG_SOC_RT305X */
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200113
Gertjan van Wingerde72c72962010-11-13 19:10:54 +0100114#ifdef CONFIG_PCI
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200115static void rt2800pci_eepromregister_read(struct eeprom_93cx6 *eeprom)
116{
117 struct rt2x00_dev *rt2x00dev = eeprom->data;
118 u32 reg;
119
Gabor Juhosb9570b62013-04-05 08:27:04 +0200120 rt2x00mmio_register_read(rt2x00dev, E2PROM_CSR, &reg);
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200121
122 eeprom->reg_data_in = !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_IN);
123 eeprom->reg_data_out = !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_OUT);
124 eeprom->reg_data_clock =
125 !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_CLOCK);
126 eeprom->reg_chip_select =
127 !!rt2x00_get_field32(reg, E2PROM_CSR_CHIP_SELECT);
128}
129
130static void rt2800pci_eepromregister_write(struct eeprom_93cx6 *eeprom)
131{
132 struct rt2x00_dev *rt2x00dev = eeprom->data;
133 u32 reg = 0;
134
135 rt2x00_set_field32(&reg, E2PROM_CSR_DATA_IN, !!eeprom->reg_data_in);
136 rt2x00_set_field32(&reg, E2PROM_CSR_DATA_OUT, !!eeprom->reg_data_out);
137 rt2x00_set_field32(&reg, E2PROM_CSR_DATA_CLOCK,
138 !!eeprom->reg_data_clock);
139 rt2x00_set_field32(&reg, E2PROM_CSR_CHIP_SELECT,
140 !!eeprom->reg_chip_select);
141
Gabor Juhosb9570b62013-04-05 08:27:04 +0200142 rt2x00mmio_register_write(rt2x00dev, E2PROM_CSR, reg);
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200143}
144
Gabor Juhosa02308e2012-12-29 14:51:51 +0100145static int rt2800pci_read_eeprom_pci(struct rt2x00_dev *rt2x00dev)
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200146{
147 struct eeprom_93cx6 eeprom;
148 u32 reg;
149
Gabor Juhosb9570b62013-04-05 08:27:04 +0200150 rt2x00mmio_register_read(rt2x00dev, E2PROM_CSR, &reg);
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200151
152 eeprom.data = rt2x00dev;
153 eeprom.register_read = rt2800pci_eepromregister_read;
154 eeprom.register_write = rt2800pci_eepromregister_write;
Gertjan van Wingerde20f8b132010-06-29 21:44:18 +0200155 switch (rt2x00_get_field32(reg, E2PROM_CSR_TYPE))
156 {
157 case 0:
158 eeprom.width = PCI_EEPROM_WIDTH_93C46;
159 break;
160 case 1:
161 eeprom.width = PCI_EEPROM_WIDTH_93C66;
162 break;
163 default:
164 eeprom.width = PCI_EEPROM_WIDTH_93C86;
165 break;
166 }
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200167 eeprom.reg_data_in = 0;
168 eeprom.reg_data_out = 0;
169 eeprom.reg_data_clock = 0;
170 eeprom.reg_chip_select = 0;
171
172 eeprom_93cx6_multiread(&eeprom, EEPROM_BASE, rt2x00dev->eeprom,
173 EEPROM_SIZE / sizeof(u16));
Gabor Juhosa02308e2012-12-29 14:51:51 +0100174
175 return 0;
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200176}
177
Gertjan van Wingerdea6598682009-11-08 12:30:35 +0100178static int rt2800pci_efuse_detect(struct rt2x00_dev *rt2x00dev)
179{
Bartlomiej Zolnierkiewicz30e84032009-11-08 14:39:48 +0100180 return rt2800_efuse_detect(rt2x00dev);
Gertjan van Wingerdea6598682009-11-08 12:30:35 +0100181}
182
Gabor Juhosa02308e2012-12-29 14:51:51 +0100183static inline int rt2800pci_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev)
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200184{
Gabor Juhosa02308e2012-12-29 14:51:51 +0100185 return rt2800_read_eeprom_efuse(rt2x00dev);
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200186}
187#else
Gabor Juhosa02308e2012-12-29 14:51:51 +0100188static inline int rt2800pci_read_eeprom_pci(struct rt2x00_dev *rt2x00dev)
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200189{
Gabor Juhosa02308e2012-12-29 14:51:51 +0100190 return -EOPNOTSUPP;
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200191}
192
Gertjan van Wingerdea6598682009-11-08 12:30:35 +0100193static inline int rt2800pci_efuse_detect(struct rt2x00_dev *rt2x00dev)
194{
195 return 0;
196}
197
Gabor Juhosa02308e2012-12-29 14:51:51 +0100198static inline int rt2800pci_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev)
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200199{
Gabor Juhosa02308e2012-12-29 14:51:51 +0100200 return -EOPNOTSUPP;
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200201}
Gertjan van Wingerde72c72962010-11-13 19:10:54 +0100202#endif /* CONFIG_PCI */
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200203
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200204/*
205 * Firmware functions
206 */
207static char *rt2800pci_get_firmware_name(struct rt2x00_dev *rt2x00dev)
208{
Woody Hunga89534e2012-06-13 15:01:16 +0800209 /*
210 * Chip rt3290 use specific 4KB firmware named rt3290.bin.
211 */
212 if (rt2x00_rt(rt2x00dev, RT3290))
213 return FIRMWARE_RT3290;
214 else
215 return FIRMWARE_RT2860;
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200216}
217
Ivo van Doornf31c9a82010-07-11 12:30:37 +0200218static int rt2800pci_write_firmware(struct rt2x00_dev *rt2x00dev,
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200219 const u8 *data, const size_t len)
220{
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200221 u32 reg;
222
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200223 /*
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200224 * enable Host program ram write selection
225 */
226 reg = 0;
227 rt2x00_set_field32(&reg, PBF_SYS_CTRL_HOST_RAM_WRITE, 1);
Gabor Juhosb9570b62013-04-05 08:27:04 +0200228 rt2x00mmio_register_write(rt2x00dev, PBF_SYS_CTRL, reg);
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200229
230 /*
231 * Write firmware to device.
232 */
Gabor Juhosb9570b62013-04-05 08:27:04 +0200233 rt2x00mmio_register_multiwrite(rt2x00dev, FIRMWARE_IMAGE_BASE,
234 data, len);
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200235
Gabor Juhosb9570b62013-04-05 08:27:04 +0200236 rt2x00mmio_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000);
237 rt2x00mmio_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00001);
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200238
Gabor Juhosb9570b62013-04-05 08:27:04 +0200239 rt2x00mmio_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
240 rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200241
242 return 0;
243}
244
245/*
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200246 * Device state switch handlers.
247 */
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200248static int rt2800pci_enable_radio(struct rt2x00_dev *rt2x00dev)
249{
Jakub Kicinskie8b461c2012-02-22 21:58:58 +0100250 int retval;
251
Jakub Kicinski52b82432012-04-03 03:40:49 +0200252 /* Wait for DMA, ignore error until we initialize queues. */
253 rt2800_wait_wpdma_ready(rt2x00dev);
254
Gabor Juhos7573afd2013-10-17 09:42:24 +0200255 if (unlikely(rt2800mmio_init_queues(rt2x00dev)))
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200256 return -EIO;
257
Jakub Kicinskie8b461c2012-02-22 21:58:58 +0100258 retval = rt2800_enable_radio(rt2x00dev);
259 if (retval)
260 return retval;
261
262 /* After resume MCU_BOOT_SIGNAL will trash these. */
Gabor Juhosb9570b62013-04-05 08:27:04 +0200263 rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
264 rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
Jakub Kicinskie8b461c2012-02-22 21:58:58 +0100265
266 rt2800_mcu_request(rt2x00dev, MCU_SLEEP, TOKEN_RADIO_OFF, 0xff, 0x02);
267 rt2800pci_mcu_status(rt2x00dev, TOKEN_RADIO_OFF);
268
269 rt2800_mcu_request(rt2x00dev, MCU_WAKEUP, TOKEN_WAKEUP, 0, 0);
270 rt2800pci_mcu_status(rt2x00dev, TOKEN_WAKEUP);
271
272 return retval;
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200273}
274
275static void rt2800pci_disable_radio(struct rt2x00_dev *rt2x00dev)
276{
RA-Jay Hung7f6e1442011-01-10 11:27:43 +0100277 if (rt2x00_is_soc(rt2x00dev)) {
278 rt2800_disable_radio(rt2x00dev);
Gabor Juhosb9570b62013-04-05 08:27:04 +0200279 rt2x00mmio_register_write(rt2x00dev, PWR_PIN_CFG, 0);
280 rt2x00mmio_register_write(rt2x00dev, TX_PIN_CFG, 0);
RA-Jay Hung7f6e1442011-01-10 11:27:43 +0100281 }
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200282}
283
284static int rt2800pci_set_state(struct rt2x00_dev *rt2x00dev,
285 enum dev_state state)
286{
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200287 if (state == STATE_AWAKE) {
Jakub Kicinski09a33112012-02-22 21:58:57 +0100288 rt2800_mcu_request(rt2x00dev, MCU_WAKEUP, TOKEN_WAKEUP,
289 0, 0x02);
290 rt2800pci_mcu_status(rt2x00dev, TOKEN_WAKEUP);
RA-Jay Hung7f6e1442011-01-10 11:27:43 +0100291 } else if (state == STATE_SLEEP) {
Gabor Juhosb9570b62013-04-05 08:27:04 +0200292 rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_STATUS,
293 0xffffffff);
294 rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_CID,
295 0xffffffff);
Jakub Kicinski09a33112012-02-22 21:58:57 +0100296 rt2800_mcu_request(rt2x00dev, MCU_SLEEP, TOKEN_SLEEP,
297 0xff, 0x01);
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200298 }
299
300 return 0;
301}
302
303static int rt2800pci_set_device_state(struct rt2x00_dev *rt2x00dev,
304 enum dev_state state)
305{
306 int retval = 0;
307
308 switch (state) {
309 case STATE_RADIO_ON:
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200310 retval = rt2800pci_enable_radio(rt2x00dev);
311 break;
312 case STATE_RADIO_OFF:
313 /*
314 * After the radio has been disabled, the device should
315 * be put to sleep for powersaving.
316 */
317 rt2800pci_disable_radio(rt2x00dev);
318 rt2800pci_set_state(rt2x00dev, STATE_SLEEP);
319 break;
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200320 case STATE_RADIO_IRQ_ON:
321 case STATE_RADIO_IRQ_OFF:
Gabor Juhosb5cfde32013-10-17 09:42:20 +0200322 rt2800mmio_toggle_irq(rt2x00dev, state);
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200323 break;
324 case STATE_DEEP_SLEEP:
325 case STATE_SLEEP:
326 case STATE_STANDBY:
327 case STATE_AWAKE:
328 retval = rt2800pci_set_state(rt2x00dev, state);
329 break;
330 default:
331 retval = -ENOTSUPP;
332 break;
333 }
334
335 if (unlikely(retval))
Joe Perchesec9c4982013-04-19 08:33:40 -0700336 rt2x00_err(rt2x00dev, "Device failed to enter state %d (%d)\n",
337 state, retval);
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200338
339 return retval;
340}
341
342/*
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200343 * Device probe functions.
344 */
Gabor Juhosa02308e2012-12-29 14:51:51 +0100345static int rt2800pci_read_eeprom(struct rt2x00_dev *rt2x00dev)
Bartlomiej Zolnierkiewicz7ab71322009-11-08 14:38:54 +0100346{
Gabor Juhosa02308e2012-12-29 14:51:51 +0100347 int retval;
348
Gertjan van Wingerdecea90e52010-02-13 20:55:47 +0100349 if (rt2x00_is_soc(rt2x00dev))
Gabor Juhosa02308e2012-12-29 14:51:51 +0100350 retval = rt2800pci_read_eeprom_soc(rt2x00dev);
Gertjan van Wingerdecea90e52010-02-13 20:55:47 +0100351 else if (rt2800pci_efuse_detect(rt2x00dev))
Gabor Juhosa02308e2012-12-29 14:51:51 +0100352 retval = rt2800pci_read_eeprom_efuse(rt2x00dev);
Gertjan van Wingerdecea90e52010-02-13 20:55:47 +0100353 else
Gabor Juhosa02308e2012-12-29 14:51:51 +0100354 retval = rt2800pci_read_eeprom_pci(rt2x00dev);
355
356 return retval;
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200357}
358
Gabor Juhoseeea8632013-10-17 09:42:26 +0200359#ifdef CONFIG_PCI
Helmut Schaae7836192010-07-11 12:28:54 +0200360static const struct ieee80211_ops rt2800pci_mac80211_ops = {
361 .tx = rt2x00mac_tx,
362 .start = rt2x00mac_start,
363 .stop = rt2x00mac_stop,
364 .add_interface = rt2x00mac_add_interface,
365 .remove_interface = rt2x00mac_remove_interface,
366 .config = rt2x00mac_config,
367 .configure_filter = rt2x00mac_configure_filter,
Helmut Schaae7836192010-07-11 12:28:54 +0200368 .set_key = rt2x00mac_set_key,
369 .sw_scan_start = rt2x00mac_sw_scan_start,
370 .sw_scan_complete = rt2x00mac_sw_scan_complete,
371 .get_stats = rt2x00mac_get_stats,
372 .get_tkip_seq = rt2800_get_tkip_seq,
373 .set_rts_threshold = rt2800_set_rts_threshold,
Helmut Schaaa2b13282011-09-08 14:38:01 +0200374 .sta_add = rt2x00mac_sta_add,
375 .sta_remove = rt2x00mac_sta_remove,
Helmut Schaae7836192010-07-11 12:28:54 +0200376 .bss_info_changed = rt2x00mac_bss_info_changed,
377 .conf_tx = rt2800_conf_tx,
378 .get_tsf = rt2800_get_tsf,
379 .rfkill_poll = rt2x00mac_rfkill_poll,
380 .ampdu_action = rt2800_ampdu_action,
Ivo van Doornf44df182010-11-04 20:40:11 +0100381 .flush = rt2x00mac_flush,
Helmut Schaa977206d2010-12-13 12:31:58 +0100382 .get_survey = rt2800_get_survey,
Ivo van Doorne7dee442011-04-18 15:34:41 +0200383 .get_ringparam = rt2x00mac_get_ringparam,
Gertjan van Wingerde5f0dd292011-07-06 23:00:21 +0200384 .tx_frames_pending = rt2x00mac_tx_frames_pending,
Helmut Schaae7836192010-07-11 12:28:54 +0200385};
386
Ivo van Doorne7966432010-07-11 12:31:23 +0200387static const struct rt2800_ops rt2800pci_rt2800_ops = {
Gabor Juhosb9570b62013-04-05 08:27:04 +0200388 .register_read = rt2x00mmio_register_read,
389 .register_read_lock = rt2x00mmio_register_read, /* same for PCI */
390 .register_write = rt2x00mmio_register_write,
391 .register_write_lock = rt2x00mmio_register_write, /* same for PCI */
392 .register_multiread = rt2x00mmio_register_multiread,
393 .register_multiwrite = rt2x00mmio_register_multiwrite,
394 .regbusy_read = rt2x00mmio_regbusy_read,
Gertjan van Wingerdead417a52012-09-03 03:25:51 +0200395 .read_eeprom = rt2800pci_read_eeprom,
396 .hwcrypt_disabled = rt2800pci_hwcrypt_disabled,
Ivo van Doorne7966432010-07-11 12:31:23 +0200397 .drv_write_firmware = rt2800pci_write_firmware,
Gabor Juhos7573afd2013-10-17 09:42:24 +0200398 .drv_init_registers = rt2800mmio_init_registers,
Gabor Juhos45c67552013-10-17 09:42:16 +0200399 .drv_get_txwi = rt2800mmio_get_txwi,
Ivo van Doorne7966432010-07-11 12:31:23 +0200400};
401
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200402static const struct rt2x00lib_ops rt2800pci_rt2x00_ops = {
Gabor Juhosb5cfde32013-10-17 09:42:20 +0200403 .irq_handler = rt2800mmio_interrupt,
404 .txstatus_tasklet = rt2800mmio_txstatus_tasklet,
405 .pretbtt_tasklet = rt2800mmio_pretbtt_tasklet,
406 .tbtt_tasklet = rt2800mmio_tbtt_tasklet,
407 .rxdone_tasklet = rt2800mmio_rxdone_tasklet,
408 .autowake_tasklet = rt2800mmio_autowake_tasklet,
Gertjan van Wingerdead417a52012-09-03 03:25:51 +0200409 .probe_hw = rt2800_probe_hw,
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200410 .get_firmware_name = rt2800pci_get_firmware_name,
Ivo van Doornf31c9a82010-07-11 12:30:37 +0200411 .check_firmware = rt2800_check_firmware,
412 .load_firmware = rt2800_load_firmware,
Gabor Juhosb9570b62013-04-05 08:27:04 +0200413 .initialize = rt2x00mmio_initialize,
414 .uninitialize = rt2x00mmio_uninitialize,
Gabor Juhos7573afd2013-10-17 09:42:24 +0200415 .get_entry_state = rt2800mmio_get_entry_state,
416 .clear_entry = rt2800mmio_clear_entry,
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200417 .set_device_state = rt2800pci_set_device_state,
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +0100418 .rfkill_poll = rt2800_rfkill_poll,
419 .link_stats = rt2800_link_stats,
420 .reset_tuner = rt2800_reset_tuner,
421 .link_tuner = rt2800_link_tuner,
Helmut Schaa9e33a352011-03-28 13:33:40 +0200422 .gain_calibration = rt2800_gain_calibration,
John Li2e9c43d2012-02-16 21:40:57 +0800423 .vco_calibration = rt2800_vco_calibration,
Gabor Juhos51e62462013-10-17 09:42:22 +0200424 .start_queue = rt2800mmio_start_queue,
425 .kick_queue = rt2800mmio_kick_queue,
426 .stop_queue = rt2800mmio_stop_queue,
Gabor Juhosb9570b62013-04-05 08:27:04 +0200427 .flush_queue = rt2x00mmio_flush_queue,
Gabor Juhos45c67552013-10-17 09:42:16 +0200428 .write_tx_desc = rt2800mmio_write_tx_desc,
Ivo van Doorn0c5879b2010-08-06 20:47:20 +0200429 .write_tx_data = rt2800_write_tx_data,
Gertjan van Wingerdef0194b22010-06-03 10:51:53 +0200430 .write_beacon = rt2800_write_beacon,
Helmut Schaa69cf36a2011-01-30 13:16:03 +0100431 .clear_beacon = rt2800_clear_beacon,
Gabor Juhosd10b7542013-10-17 09:42:18 +0200432 .fill_rxdone = rt2800mmio_fill_rxdone,
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +0100433 .config_shared_key = rt2800_config_shared_key,
434 .config_pairwise_key = rt2800_config_pairwise_key,
435 .config_filter = rt2800_config_filter,
436 .config_intf = rt2800_config_intf,
437 .config_erp = rt2800_config_erp,
438 .config_ant = rt2800_config_ant,
439 .config = rt2800_config,
Helmut Schaaa2b13282011-09-08 14:38:01 +0200440 .sta_add = rt2800_sta_add,
441 .sta_remove = rt2800_sta_remove,
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200442};
443
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200444static const struct rt2x00_ops rt2800pci_ops = {
Gertjan van Wingerde04d03622009-11-23 22:44:51 +0100445 .name = KBUILD_MODNAME,
Gertjan van Wingerde3a1c0122012-02-06 23:45:07 +0100446 .drv_data_size = sizeof(struct rt2800_drv_data),
Gertjan van Wingerde04d03622009-11-23 22:44:51 +0100447 .max_ap_intf = 8,
448 .eeprom_size = EEPROM_SIZE,
449 .rf_size = RF_SIZE,
450 .tx_queues = NUM_TX_QUEUES,
Gabor Juhos51e62462013-10-17 09:42:22 +0200451 .queue_init = rt2800mmio_queue_init,
Gertjan van Wingerde04d03622009-11-23 22:44:51 +0100452 .lib = &rt2800pci_rt2x00_ops,
Ivo van Doorne7966432010-07-11 12:31:23 +0200453 .drv = &rt2800pci_rt2800_ops,
Helmut Schaae7836192010-07-11 12:28:54 +0200454 .hw = &rt2800pci_mac80211_ops,
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200455#ifdef CONFIG_RT2X00_LIB_DEBUGFS
Gertjan van Wingerde04d03622009-11-23 22:44:51 +0100456 .debugfs = &rt2800_rt2x00debug,
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200457#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
458};
459
460/*
461 * RT2800pci module information.
462 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +0000463static DEFINE_PCI_DEVICE_TABLE(rt2800pci_device_table) = {
Gertjan van Wingerdee01ae272011-04-18 15:32:13 +0200464 { PCI_DEVICE(0x1814, 0x0601) },
465 { PCI_DEVICE(0x1814, 0x0681) },
466 { PCI_DEVICE(0x1814, 0x0701) },
467 { PCI_DEVICE(0x1814, 0x0781) },
468 { PCI_DEVICE(0x1814, 0x3090) },
469 { PCI_DEVICE(0x1814, 0x3091) },
470 { PCI_DEVICE(0x1814, 0x3092) },
471 { PCI_DEVICE(0x1432, 0x7708) },
472 { PCI_DEVICE(0x1432, 0x7727) },
473 { PCI_DEVICE(0x1432, 0x7728) },
474 { PCI_DEVICE(0x1432, 0x7738) },
475 { PCI_DEVICE(0x1432, 0x7748) },
476 { PCI_DEVICE(0x1432, 0x7758) },
477 { PCI_DEVICE(0x1432, 0x7768) },
478 { PCI_DEVICE(0x1462, 0x891a) },
479 { PCI_DEVICE(0x1a3b, 0x1059) },
Woody Hunga89534e2012-06-13 15:01:16 +0800480#ifdef CONFIG_RT2800PCI_RT3290
481 { PCI_DEVICE(0x1814, 0x3290) },
482#endif
Gertjan van Wingerdef93bc9b2010-11-13 19:09:50 +0100483#ifdef CONFIG_RT2800PCI_RT33XX
Gertjan van Wingerdee01ae272011-04-18 15:32:13 +0200484 { PCI_DEVICE(0x1814, 0x3390) },
Gertjan van Wingerdef93bc9b2010-11-13 19:09:50 +0100485#endif
Gertjan van Wingerdede1ebdc2010-02-14 12:52:05 +0100486#ifdef CONFIG_RT2800PCI_RT35XX
Gertjan van Wingerdee01ae272011-04-18 15:32:13 +0200487 { PCI_DEVICE(0x1432, 0x7711) },
488 { PCI_DEVICE(0x1432, 0x7722) },
489 { PCI_DEVICE(0x1814, 0x3060) },
490 { PCI_DEVICE(0x1814, 0x3062) },
491 { PCI_DEVICE(0x1814, 0x3562) },
492 { PCI_DEVICE(0x1814, 0x3592) },
493 { PCI_DEVICE(0x1814, 0x3593) },
Xose Vazquez Perezc4806012013-02-01 14:28:49 +0100494 { PCI_DEVICE(0x1814, 0x359f) },
Gertjan van Wingerdede1ebdc2010-02-14 12:52:05 +0100495#endif
RA-Shiang Tu60687ba2011-02-20 13:57:46 +0100496#ifdef CONFIG_RT2800PCI_RT53XX
villacis@palosanto.comccf91bd2012-05-16 21:07:12 +0200497 { PCI_DEVICE(0x1814, 0x5360) },
Xose Vazquez Perezf57d7b62012-04-14 23:33:21 +0200498 { PCI_DEVICE(0x1814, 0x5362) },
Gertjan van Wingerdee01ae272011-04-18 15:32:13 +0200499 { PCI_DEVICE(0x1814, 0x5390) },
Xose Vazquez Perezf57d7b62012-04-14 23:33:21 +0200500 { PCI_DEVICE(0x1814, 0x5392) },
zero.lin5126d972011-08-31 20:43:52 +0200501 { PCI_DEVICE(0x1814, 0x539a) },
Zero.Lin2aed6912012-05-10 10:06:31 +0800502 { PCI_DEVICE(0x1814, 0x539b) },
Gertjan van Wingerde71e0b382011-07-06 22:58:55 +0200503 { PCI_DEVICE(0x1814, 0x539f) },
RA-Shiang Tu60687ba2011-02-20 13:57:46 +0100504#endif
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200505 { 0, }
506};
Gertjan van Wingerde72c72962010-11-13 19:10:54 +0100507#endif /* CONFIG_PCI */
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200508
509MODULE_AUTHOR(DRV_PROJECT);
510MODULE_VERSION(DRV_VERSION);
511MODULE_DESCRIPTION("Ralink RT2800 PCI & PCMCIA Wireless LAN driver.");
512MODULE_SUPPORTED_DEVICE("Ralink RT2860 PCI & PCMCIA chipset based cards");
Gertjan van Wingerde72c72962010-11-13 19:10:54 +0100513#ifdef CONFIG_PCI
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200514MODULE_FIRMWARE(FIRMWARE_RT2860);
515MODULE_DEVICE_TABLE(pci, rt2800pci_device_table);
Gertjan van Wingerde72c72962010-11-13 19:10:54 +0100516#endif /* CONFIG_PCI */
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200517MODULE_LICENSE("GPL");
518
John Crispin5818a462013-03-13 13:20:15 +0100519#if defined(CONFIG_SOC_RT288X) || defined(CONFIG_SOC_RT305X)
Gabor Juhoseeea8632013-10-17 09:42:26 +0200520static const struct ieee80211_ops rt2800soc_mac80211_ops = {
521 .tx = rt2x00mac_tx,
522 .start = rt2x00mac_start,
523 .stop = rt2x00mac_stop,
524 .add_interface = rt2x00mac_add_interface,
525 .remove_interface = rt2x00mac_remove_interface,
526 .config = rt2x00mac_config,
527 .configure_filter = rt2x00mac_configure_filter,
528 .set_key = rt2x00mac_set_key,
529 .sw_scan_start = rt2x00mac_sw_scan_start,
530 .sw_scan_complete = rt2x00mac_sw_scan_complete,
531 .get_stats = rt2x00mac_get_stats,
532 .get_tkip_seq = rt2800_get_tkip_seq,
533 .set_rts_threshold = rt2800_set_rts_threshold,
534 .sta_add = rt2x00mac_sta_add,
535 .sta_remove = rt2x00mac_sta_remove,
536 .bss_info_changed = rt2x00mac_bss_info_changed,
537 .conf_tx = rt2800_conf_tx,
538 .get_tsf = rt2800_get_tsf,
539 .rfkill_poll = rt2x00mac_rfkill_poll,
540 .ampdu_action = rt2800_ampdu_action,
541 .flush = rt2x00mac_flush,
542 .get_survey = rt2800_get_survey,
543 .get_ringparam = rt2x00mac_get_ringparam,
544 .tx_frames_pending = rt2x00mac_tx_frames_pending,
545};
546
547static const struct rt2800_ops rt2800soc_rt2800_ops = {
548 .register_read = rt2x00mmio_register_read,
549 .register_read_lock = rt2x00mmio_register_read, /* same for SoCs */
550 .register_write = rt2x00mmio_register_write,
551 .register_write_lock = rt2x00mmio_register_write, /* same for SoCs */
552 .register_multiread = rt2x00mmio_register_multiread,
553 .register_multiwrite = rt2x00mmio_register_multiwrite,
554 .regbusy_read = rt2x00mmio_regbusy_read,
555 .read_eeprom = rt2800pci_read_eeprom,
556 .hwcrypt_disabled = rt2800pci_hwcrypt_disabled,
557 .drv_write_firmware = rt2800pci_write_firmware,
558 .drv_init_registers = rt2800mmio_init_registers,
559 .drv_get_txwi = rt2800mmio_get_txwi,
560};
561
562static const struct rt2x00lib_ops rt2800soc_rt2x00_ops = {
563 .irq_handler = rt2800mmio_interrupt,
564 .txstatus_tasklet = rt2800mmio_txstatus_tasklet,
565 .pretbtt_tasklet = rt2800mmio_pretbtt_tasklet,
566 .tbtt_tasklet = rt2800mmio_tbtt_tasklet,
567 .rxdone_tasklet = rt2800mmio_rxdone_tasklet,
568 .autowake_tasklet = rt2800mmio_autowake_tasklet,
569 .probe_hw = rt2800_probe_hw,
570 .get_firmware_name = rt2800pci_get_firmware_name,
571 .check_firmware = rt2800_check_firmware,
572 .load_firmware = rt2800_load_firmware,
573 .initialize = rt2x00mmio_initialize,
574 .uninitialize = rt2x00mmio_uninitialize,
575 .get_entry_state = rt2800mmio_get_entry_state,
576 .clear_entry = rt2800mmio_clear_entry,
577 .set_device_state = rt2800pci_set_device_state,
578 .rfkill_poll = rt2800_rfkill_poll,
579 .link_stats = rt2800_link_stats,
580 .reset_tuner = rt2800_reset_tuner,
581 .link_tuner = rt2800_link_tuner,
582 .gain_calibration = rt2800_gain_calibration,
583 .vco_calibration = rt2800_vco_calibration,
584 .start_queue = rt2800mmio_start_queue,
585 .kick_queue = rt2800mmio_kick_queue,
586 .stop_queue = rt2800mmio_stop_queue,
587 .flush_queue = rt2x00mmio_flush_queue,
588 .write_tx_desc = rt2800mmio_write_tx_desc,
589 .write_tx_data = rt2800_write_tx_data,
590 .write_beacon = rt2800_write_beacon,
591 .clear_beacon = rt2800_clear_beacon,
592 .fill_rxdone = rt2800mmio_fill_rxdone,
593 .config_shared_key = rt2800_config_shared_key,
594 .config_pairwise_key = rt2800_config_pairwise_key,
595 .config_filter = rt2800_config_filter,
596 .config_intf = rt2800_config_intf,
597 .config_erp = rt2800_config_erp,
598 .config_ant = rt2800_config_ant,
599 .config = rt2800_config,
600 .sta_add = rt2800_sta_add,
601 .sta_remove = rt2800_sta_remove,
602};
603
604static const struct rt2x00_ops rt2800soc_ops = {
605 .name = KBUILD_MODNAME,
606 .drv_data_size = sizeof(struct rt2800_drv_data),
607 .max_ap_intf = 8,
608 .eeprom_size = EEPROM_SIZE,
609 .rf_size = RF_SIZE,
610 .tx_queues = NUM_TX_QUEUES,
611 .queue_init = rt2800mmio_queue_init,
612 .lib = &rt2800soc_rt2x00_ops,
613 .drv = &rt2800soc_rt2800_ops,
614 .hw = &rt2800soc_mac80211_ops,
615#ifdef CONFIG_RT2X00_LIB_DEBUGFS
616 .debugfs = &rt2800_rt2x00debug,
617#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
618};
619
Gertjan van Wingerde714fa662010-02-13 20:55:48 +0100620static int rt2800soc_probe(struct platform_device *pdev)
621{
Gabor Juhoseeea8632013-10-17 09:42:26 +0200622 return rt2x00soc_probe(pdev, &rt2800soc_ops);
Gertjan van Wingerde714fa662010-02-13 20:55:48 +0100623}
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200624
625static struct platform_driver rt2800soc_driver = {
626 .driver = {
627 .name = "rt2800_wmac",
628 .owner = THIS_MODULE,
629 .mod_name = KBUILD_MODNAME,
630 },
Gertjan van Wingerde714fa662010-02-13 20:55:48 +0100631 .probe = rt2800soc_probe,
Bill Pemberton69202352012-12-03 09:56:39 -0500632 .remove = rt2x00soc_remove,
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200633 .suspend = rt2x00soc_suspend,
634 .resume = rt2x00soc_resume,
635};
John Crispin5818a462013-03-13 13:20:15 +0100636#endif /* CONFIG_SOC_RT288X || CONFIG_SOC_RT305X */
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200637
Gertjan van Wingerde72c72962010-11-13 19:10:54 +0100638#ifdef CONFIG_PCI
Gertjan van Wingerdee01ae272011-04-18 15:32:13 +0200639static int rt2800pci_probe(struct pci_dev *pci_dev,
640 const struct pci_device_id *id)
641{
642 return rt2x00pci_probe(pci_dev, &rt2800pci_ops);
643}
644
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200645static struct pci_driver rt2800pci_driver = {
646 .name = KBUILD_MODNAME,
647 .id_table = rt2800pci_device_table,
Gertjan van Wingerdee01ae272011-04-18 15:32:13 +0200648 .probe = rt2800pci_probe,
Bill Pemberton69202352012-12-03 09:56:39 -0500649 .remove = rt2x00pci_remove,
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200650 .suspend = rt2x00pci_suspend,
651 .resume = rt2x00pci_resume,
652};
Gertjan van Wingerde72c72962010-11-13 19:10:54 +0100653#endif /* CONFIG_PCI */
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200654
655static int __init rt2800pci_init(void)
656{
657 int ret = 0;
658
John Crispin5818a462013-03-13 13:20:15 +0100659#if defined(CONFIG_SOC_RT288X) || defined(CONFIG_SOC_RT305X)
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200660 ret = platform_driver_register(&rt2800soc_driver);
661 if (ret)
662 return ret;
663#endif
Gertjan van Wingerde72c72962010-11-13 19:10:54 +0100664#ifdef CONFIG_PCI
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200665 ret = pci_register_driver(&rt2800pci_driver);
666 if (ret) {
John Crispin5818a462013-03-13 13:20:15 +0100667#if defined(CONFIG_SOC_RT288X) || defined(CONFIG_SOC_RT305X)
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200668 platform_driver_unregister(&rt2800soc_driver);
669#endif
670 return ret;
671 }
672#endif
673
674 return ret;
675}
676
677static void __exit rt2800pci_exit(void)
678{
Gertjan van Wingerde72c72962010-11-13 19:10:54 +0100679#ifdef CONFIG_PCI
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200680 pci_unregister_driver(&rt2800pci_driver);
681#endif
John Crispin5818a462013-03-13 13:20:15 +0100682#if defined(CONFIG_SOC_RT288X) || defined(CONFIG_SOC_RT305X)
Ivo van Doorna9b3a9f2009-10-15 22:04:14 +0200683 platform_driver_unregister(&rt2800soc_driver);
684#endif
685}
686
687module_init(rt2800pci_init);
688module_exit(rt2800pci_exit);