blob: 31531f7cc125452d5b25dd90e3e0fd485d7c5675 [file] [log] [blame]
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001/*
2 Copyright (C) 2004 - 2007 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21/*
22 Module: rt2500usb
23 Abstract: rt2500usb device specific routines.
24 Supported chipsets: RT2570.
25 */
26
27/*
28 * Set enviroment defines for rt2x00.h
29 */
30#define DRV_NAME "rt2500usb"
31
32#include <linux/delay.h>
33#include <linux/etherdevice.h>
34#include <linux/init.h>
35#include <linux/kernel.h>
36#include <linux/module.h>
37#include <linux/usb.h>
38
39#include "rt2x00.h"
40#include "rt2x00usb.h"
41#include "rt2500usb.h"
42
43/*
44 * Register access.
45 * All access to the CSR registers will go through the methods
46 * rt2500usb_register_read and rt2500usb_register_write.
47 * BBP and RF register require indirect register access,
48 * and use the CSR registers BBPCSR and RFCSR to achieve this.
49 * These indirect registers work with busy bits,
50 * and we will try maximal REGISTER_BUSY_COUNT times to access
51 * the register while taking a REGISTER_BUSY_DELAY us delay
52 * between each attampt. When the busy bit is still set at that time,
53 * the access attempt is considered to have failed,
54 * and we will print an error.
55 */
56static inline void rt2500usb_register_read(const struct rt2x00_dev *rt2x00dev,
57 const unsigned int offset,
58 u16 *value)
59{
60 __le16 reg;
61 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
62 USB_VENDOR_REQUEST_IN, offset,
63 &reg, sizeof(u16), REGISTER_TIMEOUT);
64 *value = le16_to_cpu(reg);
65}
66
67static inline void rt2500usb_register_multiread(const struct rt2x00_dev
68 *rt2x00dev,
69 const unsigned int offset,
70 void *value, const u16 length)
71{
72 int timeout = REGISTER_TIMEOUT * (length / sizeof(u16));
73 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
74 USB_VENDOR_REQUEST_IN, offset,
75 value, length, timeout);
76}
77
78static inline void rt2500usb_register_write(const struct rt2x00_dev *rt2x00dev,
79 const unsigned int offset,
80 u16 value)
81{
82 __le16 reg = cpu_to_le16(value);
83 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
84 USB_VENDOR_REQUEST_OUT, offset,
85 &reg, sizeof(u16), REGISTER_TIMEOUT);
86}
87
88static inline void rt2500usb_register_multiwrite(const struct rt2x00_dev
89 *rt2x00dev,
90 const unsigned int offset,
91 void *value, const u16 length)
92{
93 int timeout = REGISTER_TIMEOUT * (length / sizeof(u16));
94 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
95 USB_VENDOR_REQUEST_OUT, offset,
96 value, length, timeout);
97}
98
99static u16 rt2500usb_bbp_check(const struct rt2x00_dev *rt2x00dev)
100{
101 u16 reg;
102 unsigned int i;
103
104 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
105 rt2500usb_register_read(rt2x00dev, PHY_CSR8, &reg);
106 if (!rt2x00_get_field16(reg, PHY_CSR8_BUSY))
107 break;
108 udelay(REGISTER_BUSY_DELAY);
109 }
110
111 return reg;
112}
113
114static void rt2500usb_bbp_write(const struct rt2x00_dev *rt2x00dev,
115 const unsigned int word, const u8 value)
116{
117 u16 reg;
118
119 /*
120 * Wait until the BBP becomes ready.
121 */
122 reg = rt2500usb_bbp_check(rt2x00dev);
123 if (rt2x00_get_field16(reg, PHY_CSR8_BUSY)) {
124 ERROR(rt2x00dev, "PHY_CSR8 register busy. Write failed.\n");
125 return;
126 }
127
128 /*
129 * Write the data into the BBP.
130 */
131 reg = 0;
132 rt2x00_set_field16(&reg, PHY_CSR7_DATA, value);
133 rt2x00_set_field16(&reg, PHY_CSR7_REG_ID, word);
134 rt2x00_set_field16(&reg, PHY_CSR7_READ_CONTROL, 0);
135
136 rt2500usb_register_write(rt2x00dev, PHY_CSR7, reg);
137}
138
139static void rt2500usb_bbp_read(const struct rt2x00_dev *rt2x00dev,
140 const unsigned int word, u8 *value)
141{
142 u16 reg;
143
144 /*
145 * Wait until the BBP becomes ready.
146 */
147 reg = rt2500usb_bbp_check(rt2x00dev);
148 if (rt2x00_get_field16(reg, PHY_CSR8_BUSY)) {
149 ERROR(rt2x00dev, "PHY_CSR8 register busy. Read failed.\n");
150 return;
151 }
152
153 /*
154 * Write the request into the BBP.
155 */
156 reg = 0;
157 rt2x00_set_field16(&reg, PHY_CSR7_REG_ID, word);
158 rt2x00_set_field16(&reg, PHY_CSR7_READ_CONTROL, 1);
159
160 rt2500usb_register_write(rt2x00dev, PHY_CSR7, reg);
161
162 /*
163 * Wait until the BBP becomes ready.
164 */
165 reg = rt2500usb_bbp_check(rt2x00dev);
166 if (rt2x00_get_field16(reg, PHY_CSR8_BUSY)) {
167 ERROR(rt2x00dev, "PHY_CSR8 register busy. Read failed.\n");
168 *value = 0xff;
169 return;
170 }
171
172 rt2500usb_register_read(rt2x00dev, PHY_CSR7, &reg);
173 *value = rt2x00_get_field16(reg, PHY_CSR7_DATA);
174}
175
176static void rt2500usb_rf_write(const struct rt2x00_dev *rt2x00dev,
177 const unsigned int word, const u32 value)
178{
179 u16 reg;
180 unsigned int i;
181
182 if (!word)
183 return;
184
185 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
186 rt2500usb_register_read(rt2x00dev, PHY_CSR10, &reg);
187 if (!rt2x00_get_field16(reg, PHY_CSR10_RF_BUSY))
188 goto rf_write;
189 udelay(REGISTER_BUSY_DELAY);
190 }
191
192 ERROR(rt2x00dev, "PHY_CSR10 register busy. Write failed.\n");
193 return;
194
195rf_write:
196 reg = 0;
197 rt2x00_set_field16(&reg, PHY_CSR9_RF_VALUE, value);
198 rt2500usb_register_write(rt2x00dev, PHY_CSR9, reg);
199
200 reg = 0;
201 rt2x00_set_field16(&reg, PHY_CSR10_RF_VALUE, value >> 16);
202 rt2x00_set_field16(&reg, PHY_CSR10_RF_NUMBER_OF_BITS, 20);
203 rt2x00_set_field16(&reg, PHY_CSR10_RF_IF_SELECT, 0);
204 rt2x00_set_field16(&reg, PHY_CSR10_RF_BUSY, 1);
205
206 rt2500usb_register_write(rt2x00dev, PHY_CSR10, reg);
207 rt2x00_rf_write(rt2x00dev, word, value);
208}
209
210#ifdef CONFIG_RT2X00_LIB_DEBUGFS
211#define CSR_OFFSET(__word) ( CSR_REG_BASE + ((__word) * sizeof(u16)) )
212
213static void rt2500usb_read_csr(const struct rt2x00_dev *rt2x00dev,
214 const unsigned int word, u32 *data)
215{
216 rt2500usb_register_read(rt2x00dev, CSR_OFFSET(word), (u16 *) data);
217}
218
219static void rt2500usb_write_csr(const struct rt2x00_dev *rt2x00dev,
220 const unsigned int word, u32 data)
221{
222 rt2500usb_register_write(rt2x00dev, CSR_OFFSET(word), data);
223}
224
225static const struct rt2x00debug rt2500usb_rt2x00debug = {
226 .owner = THIS_MODULE,
227 .csr = {
228 .read = rt2500usb_read_csr,
229 .write = rt2500usb_write_csr,
230 .word_size = sizeof(u16),
231 .word_count = CSR_REG_SIZE / sizeof(u16),
232 },
233 .eeprom = {
234 .read = rt2x00_eeprom_read,
235 .write = rt2x00_eeprom_write,
236 .word_size = sizeof(u16),
237 .word_count = EEPROM_SIZE / sizeof(u16),
238 },
239 .bbp = {
240 .read = rt2500usb_bbp_read,
241 .write = rt2500usb_bbp_write,
242 .word_size = sizeof(u8),
243 .word_count = BBP_SIZE / sizeof(u8),
244 },
245 .rf = {
246 .read = rt2x00_rf_read,
247 .write = rt2500usb_rf_write,
248 .word_size = sizeof(u32),
249 .word_count = RF_SIZE / sizeof(u32),
250 },
251};
252#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
253
254/*
255 * Configuration handlers.
256 */
Ivo van Doorn4abee4b2007-10-06 14:11:46 +0200257static void rt2500usb_config_mac_addr(struct rt2x00_dev *rt2x00dev,
258 __le32 *mac)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700259{
Ivo van Doorndd871452008-01-09 19:18:25 +0100260 rt2500usb_register_multiwrite(rt2x00dev, MAC_CSR2, mac,
Ivo van Doorn4abee4b2007-10-06 14:11:46 +0200261 (3 * sizeof(__le16)));
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700262}
263
Ivo van Doorn4abee4b2007-10-06 14:11:46 +0200264static void rt2500usb_config_bssid(struct rt2x00_dev *rt2x00dev,
265 __le32 *bssid)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700266{
Ivo van Doorn4abee4b2007-10-06 14:11:46 +0200267 rt2500usb_register_multiwrite(rt2x00dev, MAC_CSR5, bssid,
268 (3 * sizeof(__le16)));
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700269}
270
Ivo van Doornfeb24692007-10-06 14:14:29 +0200271static void rt2500usb_config_type(struct rt2x00_dev *rt2x00dev, const int type,
272 const int tsf_sync)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700273{
274 u16 reg;
275
276 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
277
278 /*
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700279 * Enable beacon config
280 */
281 rt2500usb_register_read(rt2x00dev, TXRX_CSR20, &reg);
282 rt2x00_set_field16(&reg, TXRX_CSR20_OFFSET,
Ivo van Doorna137e202007-10-06 14:14:58 +0200283 (PREAMBLE + get_duration(IEEE80211_HEADER, 20)) >> 6);
Ivo van Doornfeb24692007-10-06 14:14:29 +0200284 if (type == IEEE80211_IF_TYPE_STA)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700285 rt2x00_set_field16(&reg, TXRX_CSR20_BCN_EXPECT_WINDOW, 0);
286 else
287 rt2x00_set_field16(&reg, TXRX_CSR20_BCN_EXPECT_WINDOW, 2);
288 rt2500usb_register_write(rt2x00dev, TXRX_CSR20, reg);
289
290 /*
291 * Enable synchronisation.
292 */
293 rt2500usb_register_read(rt2x00dev, TXRX_CSR18, &reg);
294 rt2x00_set_field16(&reg, TXRX_CSR18_OFFSET, 0);
295 rt2500usb_register_write(rt2x00dev, TXRX_CSR18, reg);
296
297 rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg);
Johannes Berg4150c572007-09-17 01:29:23 -0400298 rt2x00_set_field16(&reg, TXRX_CSR19_TSF_COUNT, 1);
299 rt2x00_set_field16(&reg, TXRX_CSR19_TBCN, 1);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700300 rt2x00_set_field16(&reg, TXRX_CSR19_BEACON_GEN, 0);
Ivo van Doornfeb24692007-10-06 14:14:29 +0200301 rt2x00_set_field16(&reg, TXRX_CSR19_TSF_SYNC, tsf_sync);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700302 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
303}
304
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200305static void rt2500usb_config_preamble(struct rt2x00_dev *rt2x00dev,
306 const int short_preamble,
307 const int ack_timeout,
308 const int ack_consume_time)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700309{
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700310 u16 reg;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700311
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200312 /*
313 * When in atomic context, reschedule and let rt2x00lib
314 * call this function again.
315 */
316 if (in_atomic()) {
317 queue_work(rt2x00dev->hw->workqueue, &rt2x00dev->config_work);
318 return;
319 }
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700320
321 rt2500usb_register_read(rt2x00dev, TXRX_CSR1, &reg);
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200322 rt2x00_set_field16(&reg, TXRX_CSR1_ACK_TIMEOUT, ack_timeout);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700323 rt2500usb_register_write(rt2x00dev, TXRX_CSR1, reg);
324
325 rt2500usb_register_read(rt2x00dev, TXRX_CSR10, &reg);
Ivo van Doorn4f5af6eb2007-10-06 14:16:30 +0200326 rt2x00_set_field16(&reg, TXRX_CSR10_AUTORESPOND_PREAMBLE,
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200327 !!short_preamble);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700328 rt2500usb_register_write(rt2x00dev, TXRX_CSR10, reg);
329}
330
331static void rt2500usb_config_phymode(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200332 const int phymode,
333 const int basic_rate_mask)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700334{
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200335 rt2500usb_register_write(rt2x00dev, TXRX_CSR11, basic_rate_mask);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700336
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200337 if (phymode == HWMODE_B) {
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700338 rt2500usb_register_write(rt2x00dev, MAC_CSR11, 0x000b);
339 rt2500usb_register_write(rt2x00dev, MAC_CSR12, 0x0040);
340 } else {
341 rt2500usb_register_write(rt2x00dev, MAC_CSR11, 0x0005);
342 rt2500usb_register_write(rt2x00dev, MAC_CSR12, 0x016c);
343 }
344}
345
346static void rt2500usb_config_channel(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200347 struct rf_channel *rf, const int txpower)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700348{
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700349 /*
350 * Set TXpower.
351 */
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200352 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700353
354 /*
355 * For RT2525E we should first set the channel to half band higher.
356 */
357 if (rt2x00_rf(&rt2x00dev->chip, RF2525E)) {
358 static const u32 vals[] = {
359 0x000008aa, 0x000008ae, 0x000008ae, 0x000008b2,
360 0x000008b2, 0x000008b6, 0x000008b6, 0x000008ba,
361 0x000008ba, 0x000008be, 0x000008b7, 0x00000902,
362 0x00000902, 0x00000906
363 };
364
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200365 rt2500usb_rf_write(rt2x00dev, 2, vals[rf->channel - 1]);
366 if (rf->rf4)
367 rt2500usb_rf_write(rt2x00dev, 4, rf->rf4);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700368 }
369
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200370 rt2500usb_rf_write(rt2x00dev, 1, rf->rf1);
371 rt2500usb_rf_write(rt2x00dev, 2, rf->rf2);
372 rt2500usb_rf_write(rt2x00dev, 3, rf->rf3);
373 if (rf->rf4)
374 rt2500usb_rf_write(rt2x00dev, 4, rf->rf4);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700375}
376
377static void rt2500usb_config_txpower(struct rt2x00_dev *rt2x00dev,
378 const int txpower)
379{
380 u32 rf3;
381
382 rt2x00_rf_read(rt2x00dev, 3, &rf3);
383 rt2x00_set_field32(&rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
384 rt2500usb_rf_write(rt2x00dev, 3, rf3);
385}
386
387static void rt2500usb_config_antenna(struct rt2x00_dev *rt2x00dev,
Ivo van Doornaddc81bd2007-10-13 16:26:23 +0200388 struct antenna_setup *ant)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700389{
390 u8 r2;
391 u8 r14;
392 u16 csr5;
393 u16 csr6;
394
395 rt2500usb_bbp_read(rt2x00dev, 2, &r2);
396 rt2500usb_bbp_read(rt2x00dev, 14, &r14);
397 rt2500usb_register_read(rt2x00dev, PHY_CSR5, &csr5);
398 rt2500usb_register_read(rt2x00dev, PHY_CSR6, &csr6);
399
400 /*
401 * Configure the TX antenna.
402 */
Ivo van Doornaddc81bd2007-10-13 16:26:23 +0200403 switch (ant->tx) {
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700404 case ANTENNA_SW_DIVERSITY:
405 case ANTENNA_HW_DIVERSITY:
406 rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 1);
407 rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 1);
408 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 1);
409 break;
410 case ANTENNA_A:
411 rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 0);
412 rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 0);
413 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 0);
414 break;
415 case ANTENNA_B:
416 rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 2);
417 rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 2);
418 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 2);
419 break;
420 }
421
422 /*
423 * Configure the RX antenna.
424 */
Ivo van Doornaddc81bd2007-10-13 16:26:23 +0200425 switch (ant->rx) {
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700426 case ANTENNA_SW_DIVERSITY:
427 case ANTENNA_HW_DIVERSITY:
428 rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 1);
429 break;
430 case ANTENNA_A:
431 rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 0);
432 break;
433 case ANTENNA_B:
434 rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 2);
435 break;
436 }
437
438 /*
439 * RT2525E and RT5222 need to flip TX I/Q
440 */
441 if (rt2x00_rf(&rt2x00dev->chip, RF2525E) ||
442 rt2x00_rf(&rt2x00dev->chip, RF5222)) {
443 rt2x00_set_field8(&r2, BBP_R2_TX_IQ_FLIP, 1);
444 rt2x00_set_field16(&csr5, PHY_CSR5_CCK_FLIP, 1);
445 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM_FLIP, 1);
446
447 /*
448 * RT2525E does not need RX I/Q Flip.
449 */
450 if (rt2x00_rf(&rt2x00dev->chip, RF2525E))
451 rt2x00_set_field8(&r14, BBP_R14_RX_IQ_FLIP, 0);
452 } else {
453 rt2x00_set_field16(&csr5, PHY_CSR5_CCK_FLIP, 0);
454 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM_FLIP, 0);
455 }
456
457 rt2500usb_bbp_write(rt2x00dev, 2, r2);
458 rt2500usb_bbp_write(rt2x00dev, 14, r14);
459 rt2500usb_register_write(rt2x00dev, PHY_CSR5, csr5);
460 rt2500usb_register_write(rt2x00dev, PHY_CSR6, csr6);
461}
462
463static void rt2500usb_config_duration(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200464 struct rt2x00lib_conf *libconf)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700465{
466 u16 reg;
467
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200468 rt2500usb_register_write(rt2x00dev, MAC_CSR10, libconf->slot_time);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700469
470 rt2500usb_register_read(rt2x00dev, TXRX_CSR18, &reg);
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200471 rt2x00_set_field16(&reg, TXRX_CSR18_INTERVAL,
472 libconf->conf->beacon_int * 4);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700473 rt2500usb_register_write(rt2x00dev, TXRX_CSR18, reg);
474}
475
476static void rt2500usb_config(struct rt2x00_dev *rt2x00dev,
477 const unsigned int flags,
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200478 struct rt2x00lib_conf *libconf)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700479{
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700480 if (flags & CONFIG_UPDATE_PHYMODE)
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200481 rt2500usb_config_phymode(rt2x00dev, libconf->phymode,
482 libconf->basic_rates);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700483 if (flags & CONFIG_UPDATE_CHANNEL)
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200484 rt2500usb_config_channel(rt2x00dev, &libconf->rf,
485 libconf->conf->power_level);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700486 if ((flags & CONFIG_UPDATE_TXPOWER) && !(flags & CONFIG_UPDATE_CHANNEL))
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200487 rt2500usb_config_txpower(rt2x00dev,
488 libconf->conf->power_level);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700489 if (flags & CONFIG_UPDATE_ANTENNA)
Ivo van Doornaddc81bd2007-10-13 16:26:23 +0200490 rt2500usb_config_antenna(rt2x00dev, &libconf->ant);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700491 if (flags & (CONFIG_UPDATE_SLOT_TIME | CONFIG_UPDATE_BEACON_INT))
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200492 rt2500usb_config_duration(rt2x00dev, libconf);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700493}
494
495/*
496 * LED functions.
497 */
498static void rt2500usb_enable_led(struct rt2x00_dev *rt2x00dev)
499{
500 u16 reg;
501
502 rt2500usb_register_read(rt2x00dev, MAC_CSR21, &reg);
503 rt2x00_set_field16(&reg, MAC_CSR21_ON_PERIOD, 70);
504 rt2x00_set_field16(&reg, MAC_CSR21_OFF_PERIOD, 30);
505 rt2500usb_register_write(rt2x00dev, MAC_CSR21, reg);
506
507 rt2500usb_register_read(rt2x00dev, MAC_CSR20, &reg);
508
509 if (rt2x00dev->led_mode == LED_MODE_TXRX_ACTIVITY) {
510 rt2x00_set_field16(&reg, MAC_CSR20_LINK, 1);
511 rt2x00_set_field16(&reg, MAC_CSR20_ACTIVITY, 0);
512 } else if (rt2x00dev->led_mode == LED_MODE_ASUS) {
513 rt2x00_set_field16(&reg, MAC_CSR20_LINK, 0);
514 rt2x00_set_field16(&reg, MAC_CSR20_ACTIVITY, 1);
515 } else {
516 rt2x00_set_field16(&reg, MAC_CSR20_LINK, 1);
517 rt2x00_set_field16(&reg, MAC_CSR20_ACTIVITY, 1);
518 }
519
520 rt2500usb_register_write(rt2x00dev, MAC_CSR20, reg);
521}
522
523static void rt2500usb_disable_led(struct rt2x00_dev *rt2x00dev)
524{
525 u16 reg;
526
527 rt2500usb_register_read(rt2x00dev, MAC_CSR20, &reg);
528 rt2x00_set_field16(&reg, MAC_CSR20_LINK, 0);
529 rt2x00_set_field16(&reg, MAC_CSR20_ACTIVITY, 0);
530 rt2500usb_register_write(rt2x00dev, MAC_CSR20, reg);
531}
532
533/*
534 * Link tuning
535 */
Ivo van Doornebcf26d2007-10-13 16:26:12 +0200536static void rt2500usb_link_stats(struct rt2x00_dev *rt2x00dev,
537 struct link_qual *qual)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700538{
539 u16 reg;
540
541 /*
542 * Update FCS error count from register.
543 */
544 rt2500usb_register_read(rt2x00dev, STA_CSR0, &reg);
Ivo van Doornebcf26d2007-10-13 16:26:12 +0200545 qual->rx_failed = rt2x00_get_field16(reg, STA_CSR0_FCS_ERROR);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700546
547 /*
548 * Update False CCA count from register.
549 */
550 rt2500usb_register_read(rt2x00dev, STA_CSR3, &reg);
Ivo van Doornebcf26d2007-10-13 16:26:12 +0200551 qual->false_cca = rt2x00_get_field16(reg, STA_CSR3_FALSE_CCA_ERROR);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700552}
553
554static void rt2500usb_reset_tuner(struct rt2x00_dev *rt2x00dev)
555{
556 u16 eeprom;
557 u16 value;
558
559 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &eeprom);
560 value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R24_LOW);
561 rt2500usb_bbp_write(rt2x00dev, 24, value);
562
563 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &eeprom);
564 value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R25_LOW);
565 rt2500usb_bbp_write(rt2x00dev, 25, value);
566
567 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &eeprom);
568 value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R61_LOW);
569 rt2500usb_bbp_write(rt2x00dev, 61, value);
570
571 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &eeprom);
572 value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_VGCUPPER);
573 rt2500usb_bbp_write(rt2x00dev, 17, value);
574
575 rt2x00dev->link.vgc_level = value;
576}
577
578static void rt2500usb_link_tuner(struct rt2x00_dev *rt2x00dev)
579{
580 int rssi = rt2x00_get_link_rssi(&rt2x00dev->link);
581 u16 bbp_thresh;
582 u16 vgc_bound;
583 u16 sens;
584 u16 r24;
585 u16 r25;
586 u16 r61;
587 u16 r17_sens;
588 u8 r17;
589 u8 up_bound;
590 u8 low_bound;
591
592 /*
593 * Determine the BBP tuning threshold and correctly
594 * set BBP 24, 25 and 61.
595 */
596 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE, &bbp_thresh);
597 bbp_thresh = rt2x00_get_field16(bbp_thresh, EEPROM_BBPTUNE_THRESHOLD);
598
599 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &r24);
600 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &r25);
601 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &r61);
602
603 if ((rssi + bbp_thresh) > 0) {
604 r24 = rt2x00_get_field16(r24, EEPROM_BBPTUNE_R24_HIGH);
605 r25 = rt2x00_get_field16(r25, EEPROM_BBPTUNE_R25_HIGH);
606 r61 = rt2x00_get_field16(r61, EEPROM_BBPTUNE_R61_HIGH);
607 } else {
608 r24 = rt2x00_get_field16(r24, EEPROM_BBPTUNE_R24_LOW);
609 r25 = rt2x00_get_field16(r25, EEPROM_BBPTUNE_R25_LOW);
610 r61 = rt2x00_get_field16(r61, EEPROM_BBPTUNE_R61_LOW);
611 }
612
613 rt2500usb_bbp_write(rt2x00dev, 24, r24);
614 rt2500usb_bbp_write(rt2x00dev, 25, r25);
615 rt2500usb_bbp_write(rt2x00dev, 61, r61);
616
617 /*
618 * Read current r17 value, as well as the sensitivity values
619 * for the r17 register.
620 */
621 rt2500usb_bbp_read(rt2x00dev, 17, &r17);
622 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R17, &r17_sens);
623
624 /*
625 * A too low RSSI will cause too much false CCA which will
626 * then corrupt the R17 tuning. To remidy this the tuning should
627 * be stopped (While making sure the R17 value will not exceed limits)
628 */
629 if (rssi >= -40) {
630 if (r17 != 0x60)
631 rt2500usb_bbp_write(rt2x00dev, 17, 0x60);
632 return;
633 }
634
635 /*
636 * Special big-R17 for short distance
637 */
638 if (rssi >= -58) {
639 sens = rt2x00_get_field16(r17_sens, EEPROM_BBPTUNE_R17_LOW);
640 if (r17 != sens)
641 rt2500usb_bbp_write(rt2x00dev, 17, sens);
642 return;
643 }
644
645 /*
646 * Special mid-R17 for middle distance
647 */
648 if (rssi >= -74) {
649 sens = rt2x00_get_field16(r17_sens, EEPROM_BBPTUNE_R17_HIGH);
650 if (r17 != sens)
651 rt2500usb_bbp_write(rt2x00dev, 17, sens);
652 return;
653 }
654
655 /*
656 * Leave short or middle distance condition, restore r17
657 * to the dynamic tuning range.
658 */
659 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &vgc_bound);
660 vgc_bound = rt2x00_get_field16(vgc_bound, EEPROM_BBPTUNE_VGCUPPER);
661
662 low_bound = 0x32;
663 if (rssi >= -77)
664 up_bound = vgc_bound;
665 else
666 up_bound = vgc_bound - (-77 - rssi);
667
668 if (up_bound < low_bound)
669 up_bound = low_bound;
670
671 if (r17 > up_bound) {
672 rt2500usb_bbp_write(rt2x00dev, 17, up_bound);
673 rt2x00dev->link.vgc_level = up_bound;
Ivo van Doornebcf26d2007-10-13 16:26:12 +0200674 } else if (rt2x00dev->link.qual.false_cca > 512 && r17 < up_bound) {
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700675 rt2500usb_bbp_write(rt2x00dev, 17, ++r17);
676 rt2x00dev->link.vgc_level = r17;
Ivo van Doornebcf26d2007-10-13 16:26:12 +0200677 } else if (rt2x00dev->link.qual.false_cca < 100 && r17 > low_bound) {
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700678 rt2500usb_bbp_write(rt2x00dev, 17, --r17);
679 rt2x00dev->link.vgc_level = r17;
680 }
681}
682
683/*
684 * Initialization functions.
685 */
686static int rt2500usb_init_registers(struct rt2x00_dev *rt2x00dev)
687{
688 u16 reg;
689
690 rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0x0001,
691 USB_MODE_TEST, REGISTER_TIMEOUT);
692 rt2x00usb_vendor_request_sw(rt2x00dev, USB_SINGLE_WRITE, 0x0308,
693 0x00f0, REGISTER_TIMEOUT);
694
695 rt2500usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
696 rt2x00_set_field16(&reg, TXRX_CSR2_DISABLE_RX, 1);
697 rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
698
699 rt2500usb_register_write(rt2x00dev, MAC_CSR13, 0x1111);
700 rt2500usb_register_write(rt2x00dev, MAC_CSR14, 0x1e11);
701
702 rt2500usb_register_read(rt2x00dev, MAC_CSR1, &reg);
703 rt2x00_set_field16(&reg, MAC_CSR1_SOFT_RESET, 1);
704 rt2x00_set_field16(&reg, MAC_CSR1_BBP_RESET, 1);
705 rt2x00_set_field16(&reg, MAC_CSR1_HOST_READY, 0);
706 rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
707
708 rt2500usb_register_read(rt2x00dev, MAC_CSR1, &reg);
709 rt2x00_set_field16(&reg, MAC_CSR1_SOFT_RESET, 0);
710 rt2x00_set_field16(&reg, MAC_CSR1_BBP_RESET, 0);
711 rt2x00_set_field16(&reg, MAC_CSR1_HOST_READY, 0);
712 rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
713
714 rt2500usb_register_read(rt2x00dev, TXRX_CSR5, &reg);
715 rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID0, 13);
716 rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID0_VALID, 1);
717 rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID1, 12);
718 rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID1_VALID, 1);
719 rt2500usb_register_write(rt2x00dev, TXRX_CSR5, reg);
720
721 rt2500usb_register_read(rt2x00dev, TXRX_CSR6, &reg);
722 rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID0, 10);
723 rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID0_VALID, 1);
724 rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID1, 11);
725 rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID1_VALID, 1);
726 rt2500usb_register_write(rt2x00dev, TXRX_CSR6, reg);
727
728 rt2500usb_register_read(rt2x00dev, TXRX_CSR7, &reg);
729 rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID0, 7);
730 rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID0_VALID, 1);
731 rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID1, 6);
732 rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID1_VALID, 1);
733 rt2500usb_register_write(rt2x00dev, TXRX_CSR7, reg);
734
735 rt2500usb_register_read(rt2x00dev, TXRX_CSR8, &reg);
736 rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID0, 5);
737 rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID0_VALID, 1);
738 rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID1, 0);
739 rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID1_VALID, 0);
740 rt2500usb_register_write(rt2x00dev, TXRX_CSR8, reg);
741
742 rt2500usb_register_write(rt2x00dev, TXRX_CSR21, 0xe78f);
743 rt2500usb_register_write(rt2x00dev, MAC_CSR9, 0xff1d);
744
745 if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE))
746 return -EBUSY;
747
748 rt2500usb_register_read(rt2x00dev, MAC_CSR1, &reg);
749 rt2x00_set_field16(&reg, MAC_CSR1_SOFT_RESET, 0);
750 rt2x00_set_field16(&reg, MAC_CSR1_BBP_RESET, 0);
751 rt2x00_set_field16(&reg, MAC_CSR1_HOST_READY, 1);
752 rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
753
Ivo van Doorn755a9572007-11-12 15:02:22 +0100754 if (rt2x00_rev(&rt2x00dev->chip) >= RT2570_VERSION_C) {
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700755 rt2500usb_register_read(rt2x00dev, PHY_CSR2, &reg);
756 reg &= ~0x0002;
757 } else {
758 reg = 0x3002;
759 }
760 rt2500usb_register_write(rt2x00dev, PHY_CSR2, reg);
761
762 rt2500usb_register_write(rt2x00dev, MAC_CSR11, 0x0002);
763 rt2500usb_register_write(rt2x00dev, MAC_CSR22, 0x0053);
764 rt2500usb_register_write(rt2x00dev, MAC_CSR15, 0x01ee);
765 rt2500usb_register_write(rt2x00dev, MAC_CSR16, 0x0000);
766
767 rt2500usb_register_read(rt2x00dev, MAC_CSR8, &reg);
768 rt2x00_set_field16(&reg, MAC_CSR8_MAX_FRAME_UNIT,
769 rt2x00dev->rx->data_size);
770 rt2500usb_register_write(rt2x00dev, MAC_CSR8, reg);
771
772 rt2500usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
773 rt2x00_set_field16(&reg, TXRX_CSR0_IV_OFFSET, IEEE80211_HEADER);
774 rt2x00_set_field16(&reg, TXRX_CSR0_KEY_ID, 0xff);
775 rt2500usb_register_write(rt2x00dev, TXRX_CSR0, reg);
776
777 rt2500usb_register_read(rt2x00dev, MAC_CSR18, &reg);
778 rt2x00_set_field16(&reg, MAC_CSR18_DELAY_AFTER_BEACON, 90);
779 rt2500usb_register_write(rt2x00dev, MAC_CSR18, reg);
780
781 rt2500usb_register_read(rt2x00dev, PHY_CSR4, &reg);
782 rt2x00_set_field16(&reg, PHY_CSR4_LOW_RF_LE, 1);
783 rt2500usb_register_write(rt2x00dev, PHY_CSR4, reg);
784
785 rt2500usb_register_read(rt2x00dev, TXRX_CSR1, &reg);
786 rt2x00_set_field16(&reg, TXRX_CSR1_AUTO_SEQUENCE, 1);
787 rt2500usb_register_write(rt2x00dev, TXRX_CSR1, reg);
788
789 return 0;
790}
791
792static int rt2500usb_init_bbp(struct rt2x00_dev *rt2x00dev)
793{
794 unsigned int i;
795 u16 eeprom;
796 u8 value;
797 u8 reg_id;
798
799 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
800 rt2500usb_bbp_read(rt2x00dev, 0, &value);
801 if ((value != 0xff) && (value != 0x00))
802 goto continue_csr_init;
803 NOTICE(rt2x00dev, "Waiting for BBP register.\n");
804 udelay(REGISTER_BUSY_DELAY);
805 }
806
807 ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
808 return -EACCES;
809
810continue_csr_init:
811 rt2500usb_bbp_write(rt2x00dev, 3, 0x02);
812 rt2500usb_bbp_write(rt2x00dev, 4, 0x19);
813 rt2500usb_bbp_write(rt2x00dev, 14, 0x1c);
814 rt2500usb_bbp_write(rt2x00dev, 15, 0x30);
815 rt2500usb_bbp_write(rt2x00dev, 16, 0xac);
816 rt2500usb_bbp_write(rt2x00dev, 18, 0x18);
817 rt2500usb_bbp_write(rt2x00dev, 19, 0xff);
818 rt2500usb_bbp_write(rt2x00dev, 20, 0x1e);
819 rt2500usb_bbp_write(rt2x00dev, 21, 0x08);
820 rt2500usb_bbp_write(rt2x00dev, 22, 0x08);
821 rt2500usb_bbp_write(rt2x00dev, 23, 0x08);
822 rt2500usb_bbp_write(rt2x00dev, 24, 0x80);
823 rt2500usb_bbp_write(rt2x00dev, 25, 0x50);
824 rt2500usb_bbp_write(rt2x00dev, 26, 0x08);
825 rt2500usb_bbp_write(rt2x00dev, 27, 0x23);
826 rt2500usb_bbp_write(rt2x00dev, 30, 0x10);
827 rt2500usb_bbp_write(rt2x00dev, 31, 0x2b);
828 rt2500usb_bbp_write(rt2x00dev, 32, 0xb9);
829 rt2500usb_bbp_write(rt2x00dev, 34, 0x12);
830 rt2500usb_bbp_write(rt2x00dev, 35, 0x50);
831 rt2500usb_bbp_write(rt2x00dev, 39, 0xc4);
832 rt2500usb_bbp_write(rt2x00dev, 40, 0x02);
833 rt2500usb_bbp_write(rt2x00dev, 41, 0x60);
834 rt2500usb_bbp_write(rt2x00dev, 53, 0x10);
835 rt2500usb_bbp_write(rt2x00dev, 54, 0x18);
836 rt2500usb_bbp_write(rt2x00dev, 56, 0x08);
837 rt2500usb_bbp_write(rt2x00dev, 57, 0x10);
838 rt2500usb_bbp_write(rt2x00dev, 58, 0x08);
839 rt2500usb_bbp_write(rt2x00dev, 61, 0x60);
840 rt2500usb_bbp_write(rt2x00dev, 62, 0x10);
841 rt2500usb_bbp_write(rt2x00dev, 75, 0xff);
842
843 DEBUG(rt2x00dev, "Start initialization from EEPROM...\n");
844 for (i = 0; i < EEPROM_BBP_SIZE; i++) {
845 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
846
847 if (eeprom != 0xffff && eeprom != 0x0000) {
848 reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
849 value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
850 DEBUG(rt2x00dev, "BBP: 0x%02x, value: 0x%02x.\n",
851 reg_id, value);
852 rt2500usb_bbp_write(rt2x00dev, reg_id, value);
853 }
854 }
855 DEBUG(rt2x00dev, "...End initialization from EEPROM.\n");
856
857 return 0;
858}
859
860/*
861 * Device state switch handlers.
862 */
863static void rt2500usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
864 enum dev_state state)
865{
866 u16 reg;
867
868 rt2500usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
869 rt2x00_set_field16(&reg, TXRX_CSR2_DISABLE_RX,
870 state == STATE_RADIO_RX_OFF);
871 rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
872}
873
874static int rt2500usb_enable_radio(struct rt2x00_dev *rt2x00dev)
875{
876 /*
877 * Initialize all registers.
878 */
879 if (rt2500usb_init_registers(rt2x00dev) ||
880 rt2500usb_init_bbp(rt2x00dev)) {
881 ERROR(rt2x00dev, "Register initialization failed.\n");
882 return -EIO;
883 }
884
885 rt2x00usb_enable_radio(rt2x00dev);
886
887 /*
888 * Enable LED
889 */
890 rt2500usb_enable_led(rt2x00dev);
891
892 return 0;
893}
894
895static void rt2500usb_disable_radio(struct rt2x00_dev *rt2x00dev)
896{
897 /*
898 * Disable LED
899 */
900 rt2500usb_disable_led(rt2x00dev);
901
902 rt2500usb_register_write(rt2x00dev, MAC_CSR13, 0x2121);
903 rt2500usb_register_write(rt2x00dev, MAC_CSR14, 0x2121);
904
905 /*
906 * Disable synchronisation.
907 */
908 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
909
910 rt2x00usb_disable_radio(rt2x00dev);
911}
912
913static int rt2500usb_set_state(struct rt2x00_dev *rt2x00dev,
914 enum dev_state state)
915{
916 u16 reg;
917 u16 reg2;
918 unsigned int i;
919 char put_to_sleep;
920 char bbp_state;
921 char rf_state;
922
923 put_to_sleep = (state != STATE_AWAKE);
924
925 reg = 0;
926 rt2x00_set_field16(&reg, MAC_CSR17_BBP_DESIRE_STATE, state);
927 rt2x00_set_field16(&reg, MAC_CSR17_RF_DESIRE_STATE, state);
928 rt2x00_set_field16(&reg, MAC_CSR17_PUT_TO_SLEEP, put_to_sleep);
929 rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
930 rt2x00_set_field16(&reg, MAC_CSR17_SET_STATE, 1);
931 rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
932
933 /*
934 * Device is not guaranteed to be in the requested state yet.
935 * We must wait until the register indicates that the
936 * device has entered the correct state.
937 */
938 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
939 rt2500usb_register_read(rt2x00dev, MAC_CSR17, &reg2);
940 bbp_state = rt2x00_get_field16(reg2, MAC_CSR17_BBP_CURR_STATE);
941 rf_state = rt2x00_get_field16(reg2, MAC_CSR17_RF_CURR_STATE);
942 if (bbp_state == state && rf_state == state)
943 return 0;
944 rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
945 msleep(30);
946 }
947
948 NOTICE(rt2x00dev, "Device failed to enter state %d, "
949 "current device state: bbp %d and rf %d.\n",
950 state, bbp_state, rf_state);
951
952 return -EBUSY;
953}
954
955static int rt2500usb_set_device_state(struct rt2x00_dev *rt2x00dev,
956 enum dev_state state)
957{
958 int retval = 0;
959
960 switch (state) {
961 case STATE_RADIO_ON:
962 retval = rt2500usb_enable_radio(rt2x00dev);
963 break;
964 case STATE_RADIO_OFF:
965 rt2500usb_disable_radio(rt2x00dev);
966 break;
967 case STATE_RADIO_RX_ON:
968 case STATE_RADIO_RX_OFF:
969 rt2500usb_toggle_rx(rt2x00dev, state);
970 break;
971 case STATE_DEEP_SLEEP:
972 case STATE_SLEEP:
973 case STATE_STANDBY:
974 case STATE_AWAKE:
975 retval = rt2500usb_set_state(rt2x00dev, state);
976 break;
977 default:
978 retval = -ENOTSUPP;
979 break;
980 }
981
982 return retval;
983}
984
985/*
986 * TX descriptor initialization
987 */
988static void rt2500usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
989 struct data_desc *txd,
Johannes Berg4150c572007-09-17 01:29:23 -0400990 struct txdata_entry_desc *desc,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700991 struct ieee80211_hdr *ieee80211hdr,
992 unsigned int length,
993 struct ieee80211_tx_control *control)
994{
995 u32 word;
996
997 /*
998 * Start writing the descriptor words.
999 */
1000 rt2x00_desc_read(txd, 1, &word);
1001 rt2x00_set_field32(&word, TXD_W1_IV_OFFSET, IEEE80211_HEADER);
1002 rt2x00_set_field32(&word, TXD_W1_AIFS, desc->aifs);
1003 rt2x00_set_field32(&word, TXD_W1_CWMIN, desc->cw_min);
1004 rt2x00_set_field32(&word, TXD_W1_CWMAX, desc->cw_max);
1005 rt2x00_desc_write(txd, 1, word);
1006
1007 rt2x00_desc_read(txd, 2, &word);
1008 rt2x00_set_field32(&word, TXD_W2_PLCP_SIGNAL, desc->signal);
1009 rt2x00_set_field32(&word, TXD_W2_PLCP_SERVICE, desc->service);
1010 rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_LOW, desc->length_low);
1011 rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_HIGH, desc->length_high);
1012 rt2x00_desc_write(txd, 2, word);
1013
1014 rt2x00_desc_read(txd, 0, &word);
1015 rt2x00_set_field32(&word, TXD_W0_RETRY_LIMIT, control->retry_limit);
1016 rt2x00_set_field32(&word, TXD_W0_MORE_FRAG,
1017 test_bit(ENTRY_TXD_MORE_FRAG, &desc->flags));
1018 rt2x00_set_field32(&word, TXD_W0_ACK,
1019 !(control->flags & IEEE80211_TXCTL_NO_ACK));
1020 rt2x00_set_field32(&word, TXD_W0_TIMESTAMP,
1021 test_bit(ENTRY_TXD_REQ_TIMESTAMP, &desc->flags));
1022 rt2x00_set_field32(&word, TXD_W0_OFDM,
1023 test_bit(ENTRY_TXD_OFDM_RATE, &desc->flags));
1024 rt2x00_set_field32(&word, TXD_W0_NEW_SEQ,
1025 !!(control->flags & IEEE80211_TXCTL_FIRST_FRAGMENT));
1026 rt2x00_set_field32(&word, TXD_W0_IFS, desc->ifs);
1027 rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, length);
1028 rt2x00_set_field32(&word, TXD_W0_CIPHER, CIPHER_NONE);
1029 rt2x00_desc_write(txd, 0, word);
1030}
1031
Ivo van Doorndd9fa2d2007-10-06 14:15:46 +02001032static int rt2500usb_get_tx_data_len(struct rt2x00_dev *rt2x00dev,
Ivo van Doornb242e892007-11-15 23:41:31 +01001033 struct sk_buff *skb)
Ivo van Doorndd9fa2d2007-10-06 14:15:46 +02001034{
1035 int length;
1036
1037 /*
1038 * The length _must_ be a multiple of 2,
1039 * but it must _not_ be a multiple of the USB packet size.
1040 */
1041 length = roundup(skb->len, 2);
Ivo van Doornb242e892007-11-15 23:41:31 +01001042 length += (2 * !(length % rt2x00dev->usb_maxpacket));
Ivo van Doorndd9fa2d2007-10-06 14:15:46 +02001043
1044 return length;
1045}
1046
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001047/*
1048 * TX data initialization
1049 */
1050static void rt2500usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
1051 unsigned int queue)
1052{
1053 u16 reg;
1054
1055 if (queue != IEEE80211_TX_QUEUE_BEACON)
1056 return;
1057
1058 rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg);
1059 if (!rt2x00_get_field16(reg, TXRX_CSR19_BEACON_GEN)) {
1060 rt2x00_set_field16(&reg, TXRX_CSR19_BEACON_GEN, 1);
1061 /*
1062 * Beacon generation will fail initially.
1063 * To prevent this we need to register the TXRX_CSR19
1064 * register several times.
1065 */
1066 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
1067 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
1068 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
1069 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
1070 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
1071 }
1072}
1073
1074/*
1075 * RX control handlers
1076 */
Johannes Berg4150c572007-09-17 01:29:23 -04001077static void rt2500usb_fill_rxdone(struct data_entry *entry,
1078 struct rxdata_entry_desc *desc)
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001079{
1080 struct urb *urb = entry->priv;
1081 struct data_desc *rxd = (struct data_desc *)(entry->skb->data +
1082 (urb->actual_length -
1083 entry->ring->desc_size));
1084 u32 word0;
1085 u32 word1;
1086
1087 rt2x00_desc_read(rxd, 0, &word0);
1088 rt2x00_desc_read(rxd, 1, &word1);
1089
Johannes Berg4150c572007-09-17 01:29:23 -04001090 desc->flags = 0;
1091 if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR))
1092 desc->flags |= RX_FLAG_FAILED_FCS_CRC;
1093 if (rt2x00_get_field32(word0, RXD_W0_PHYSICAL_ERROR))
1094 desc->flags |= RX_FLAG_FAILED_PLCP_CRC;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001095
1096 /*
1097 * Obtain the status about this packet.
1098 */
Johannes Berg4150c572007-09-17 01:29:23 -04001099 desc->signal = rt2x00_get_field32(word1, RXD_W1_SIGNAL);
1100 desc->rssi = rt2x00_get_field32(word1, RXD_W1_RSSI) -
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001101 entry->ring->rt2x00dev->rssi_offset;
Johannes Berg4150c572007-09-17 01:29:23 -04001102 desc->ofdm = rt2x00_get_field32(word0, RXD_W0_OFDM);
1103 desc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001104
Johannes Berg4150c572007-09-17 01:29:23 -04001105 return;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001106}
1107
1108/*
1109 * Interrupt functions.
1110 */
1111static void rt2500usb_beacondone(struct urb *urb)
1112{
1113 struct data_entry *entry = (struct data_entry *)urb->context;
1114 struct data_ring *ring = entry->ring;
1115
1116 if (!test_bit(DEVICE_ENABLED_RADIO, &ring->rt2x00dev->flags))
1117 return;
1118
1119 /*
1120 * Check if this was the guardian beacon,
1121 * if that was the case we need to send the real beacon now.
1122 * Otherwise we should free the sk_buffer, the device
1123 * should be doing the rest of the work now.
1124 */
1125 if (ring->index == 1) {
1126 rt2x00_ring_index_done_inc(ring);
1127 entry = rt2x00_get_data_entry(ring);
1128 usb_submit_urb(entry->priv, GFP_ATOMIC);
1129 rt2x00_ring_index_inc(ring);
1130 } else if (ring->index_done == 1) {
1131 entry = rt2x00_get_data_entry_done(ring);
1132 if (entry->skb) {
1133 dev_kfree_skb(entry->skb);
1134 entry->skb = NULL;
1135 }
1136 rt2x00_ring_index_done_inc(ring);
1137 }
1138}
1139
1140/*
1141 * Device probe functions.
1142 */
1143static int rt2500usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
1144{
1145 u16 word;
1146 u8 *mac;
1147
1148 rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
1149
1150 /*
1151 * Start validation of the data that has been read.
1152 */
1153 mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
1154 if (!is_valid_ether_addr(mac)) {
Joe Perches0795af52007-10-03 17:59:30 -07001155 DECLARE_MAC_BUF(macbuf);
1156
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001157 random_ether_addr(mac);
Joe Perches0795af52007-10-03 17:59:30 -07001158 EEPROM(rt2x00dev, "MAC: %s\n", print_mac(macbuf, mac));
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001159 }
1160
1161 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
1162 if (word == 0xffff) {
1163 rt2x00_set_field16(&word, EEPROM_ANTENNA_NUM, 2);
Ivo van Doorn362f3b62007-10-13 16:26:18 +02001164 rt2x00_set_field16(&word, EEPROM_ANTENNA_TX_DEFAULT,
1165 ANTENNA_SW_DIVERSITY);
1166 rt2x00_set_field16(&word, EEPROM_ANTENNA_RX_DEFAULT,
1167 ANTENNA_SW_DIVERSITY);
1168 rt2x00_set_field16(&word, EEPROM_ANTENNA_LED_MODE,
1169 LED_MODE_DEFAULT);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001170 rt2x00_set_field16(&word, EEPROM_ANTENNA_DYN_TXAGC, 0);
1171 rt2x00_set_field16(&word, EEPROM_ANTENNA_HARDWARE_RADIO, 0);
1172 rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF2522);
1173 rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
1174 EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
1175 }
1176
1177 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
1178 if (word == 0xffff) {
1179 rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0);
1180 rt2x00_set_field16(&word, EEPROM_NIC_DYN_BBP_TUNE, 0);
1181 rt2x00_set_field16(&word, EEPROM_NIC_CCK_TX_POWER, 0);
1182 rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
1183 EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
1184 }
1185
1186 rt2x00_eeprom_read(rt2x00dev, EEPROM_CALIBRATE_OFFSET, &word);
1187 if (word == 0xffff) {
1188 rt2x00_set_field16(&word, EEPROM_CALIBRATE_OFFSET_RSSI,
1189 DEFAULT_RSSI_OFFSET);
1190 rt2x00_eeprom_write(rt2x00dev, EEPROM_CALIBRATE_OFFSET, word);
1191 EEPROM(rt2x00dev, "Calibrate offset: 0x%04x\n", word);
1192 }
1193
1194 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE, &word);
1195 if (word == 0xffff) {
1196 rt2x00_set_field16(&word, EEPROM_BBPTUNE_THRESHOLD, 45);
1197 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE, word);
1198 EEPROM(rt2x00dev, "BBPtune: 0x%04x\n", word);
1199 }
1200
1201 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &word);
1202 if (word == 0xffff) {
1203 rt2x00_set_field16(&word, EEPROM_BBPTUNE_VGCUPPER, 0x40);
1204 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_VGC, word);
1205 EEPROM(rt2x00dev, "BBPtune vgc: 0x%04x\n", word);
1206 }
1207
1208 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R17, &word);
1209 if (word == 0xffff) {
1210 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R17_LOW, 0x48);
1211 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R17_HIGH, 0x41);
1212 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R17, word);
1213 EEPROM(rt2x00dev, "BBPtune r17: 0x%04x\n", word);
1214 }
1215
1216 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &word);
1217 if (word == 0xffff) {
1218 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R24_LOW, 0x40);
1219 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R24_HIGH, 0x80);
1220 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R24, word);
1221 EEPROM(rt2x00dev, "BBPtune r24: 0x%04x\n", word);
1222 }
1223
1224 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &word);
1225 if (word == 0xffff) {
1226 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R25_LOW, 0x40);
1227 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R25_HIGH, 0x50);
1228 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R25, word);
1229 EEPROM(rt2x00dev, "BBPtune r25: 0x%04x\n", word);
1230 }
1231
1232 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &word);
1233 if (word == 0xffff) {
1234 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R61_LOW, 0x60);
1235 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R61_HIGH, 0x6d);
1236 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R61, word);
1237 EEPROM(rt2x00dev, "BBPtune r61: 0x%04x\n", word);
1238 }
1239
1240 return 0;
1241}
1242
1243static int rt2500usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
1244{
1245 u16 reg;
1246 u16 value;
1247 u16 eeprom;
1248
1249 /*
1250 * Read EEPROM word for configuration.
1251 */
1252 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
1253
1254 /*
1255 * Identify RF chipset.
1256 */
1257 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
1258 rt2500usb_register_read(rt2x00dev, MAC_CSR0, &reg);
1259 rt2x00_set_chip(rt2x00dev, RT2570, value, reg);
1260
Ivo van Doorn755a9572007-11-12 15:02:22 +01001261 if (!rt2x00_check_rev(&rt2x00dev->chip, 0)) {
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001262 ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
1263 return -ENODEV;
1264 }
1265
1266 if (!rt2x00_rf(&rt2x00dev->chip, RF2522) &&
1267 !rt2x00_rf(&rt2x00dev->chip, RF2523) &&
1268 !rt2x00_rf(&rt2x00dev->chip, RF2524) &&
1269 !rt2x00_rf(&rt2x00dev->chip, RF2525) &&
1270 !rt2x00_rf(&rt2x00dev->chip, RF2525E) &&
1271 !rt2x00_rf(&rt2x00dev->chip, RF5222)) {
1272 ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
1273 return -ENODEV;
1274 }
1275
1276 /*
1277 * Identify default antenna configuration.
1278 */
Ivo van Doornaddc81bd2007-10-13 16:26:23 +02001279 rt2x00dev->default_ant.tx =
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001280 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TX_DEFAULT);
Ivo van Doornaddc81bd2007-10-13 16:26:23 +02001281 rt2x00dev->default_ant.rx =
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001282 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_DEFAULT);
1283
1284 /*
Ivo van Doornaddc81bd2007-10-13 16:26:23 +02001285 * When the eeprom indicates SW_DIVERSITY use HW_DIVERSITY instead.
1286 * I am not 100% sure about this, but the legacy drivers do not
1287 * indicate antenna swapping in software is required when
1288 * diversity is enabled.
1289 */
1290 if (rt2x00dev->default_ant.tx == ANTENNA_SW_DIVERSITY)
1291 rt2x00dev->default_ant.tx = ANTENNA_HW_DIVERSITY;
1292 if (rt2x00dev->default_ant.rx == ANTENNA_SW_DIVERSITY)
1293 rt2x00dev->default_ant.rx = ANTENNA_HW_DIVERSITY;
1294
1295 /*
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001296 * Store led mode, for correct led behaviour.
1297 */
1298 rt2x00dev->led_mode =
1299 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_LED_MODE);
1300
1301 /*
1302 * Check if the BBP tuning should be disabled.
1303 */
1304 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
1305 if (rt2x00_get_field16(eeprom, EEPROM_NIC_DYN_BBP_TUNE))
1306 __set_bit(CONFIG_DISABLE_LINK_TUNING, &rt2x00dev->flags);
1307
1308 /*
1309 * Read the RSSI <-> dBm offset information.
1310 */
1311 rt2x00_eeprom_read(rt2x00dev, EEPROM_CALIBRATE_OFFSET, &eeprom);
1312 rt2x00dev->rssi_offset =
1313 rt2x00_get_field16(eeprom, EEPROM_CALIBRATE_OFFSET_RSSI);
1314
1315 return 0;
1316}
1317
1318/*
1319 * RF value list for RF2522
1320 * Supports: 2.4 GHz
1321 */
1322static const struct rf_channel rf_vals_bg_2522[] = {
1323 { 1, 0x00002050, 0x000c1fda, 0x00000101, 0 },
1324 { 2, 0x00002050, 0x000c1fee, 0x00000101, 0 },
1325 { 3, 0x00002050, 0x000c2002, 0x00000101, 0 },
1326 { 4, 0x00002050, 0x000c2016, 0x00000101, 0 },
1327 { 5, 0x00002050, 0x000c202a, 0x00000101, 0 },
1328 { 6, 0x00002050, 0x000c203e, 0x00000101, 0 },
1329 { 7, 0x00002050, 0x000c2052, 0x00000101, 0 },
1330 { 8, 0x00002050, 0x000c2066, 0x00000101, 0 },
1331 { 9, 0x00002050, 0x000c207a, 0x00000101, 0 },
1332 { 10, 0x00002050, 0x000c208e, 0x00000101, 0 },
1333 { 11, 0x00002050, 0x000c20a2, 0x00000101, 0 },
1334 { 12, 0x00002050, 0x000c20b6, 0x00000101, 0 },
1335 { 13, 0x00002050, 0x000c20ca, 0x00000101, 0 },
1336 { 14, 0x00002050, 0x000c20fa, 0x00000101, 0 },
1337};
1338
1339/*
1340 * RF value list for RF2523
1341 * Supports: 2.4 GHz
1342 */
1343static const struct rf_channel rf_vals_bg_2523[] = {
1344 { 1, 0x00022010, 0x00000c9e, 0x000e0111, 0x00000a1b },
1345 { 2, 0x00022010, 0x00000ca2, 0x000e0111, 0x00000a1b },
1346 { 3, 0x00022010, 0x00000ca6, 0x000e0111, 0x00000a1b },
1347 { 4, 0x00022010, 0x00000caa, 0x000e0111, 0x00000a1b },
1348 { 5, 0x00022010, 0x00000cae, 0x000e0111, 0x00000a1b },
1349 { 6, 0x00022010, 0x00000cb2, 0x000e0111, 0x00000a1b },
1350 { 7, 0x00022010, 0x00000cb6, 0x000e0111, 0x00000a1b },
1351 { 8, 0x00022010, 0x00000cba, 0x000e0111, 0x00000a1b },
1352 { 9, 0x00022010, 0x00000cbe, 0x000e0111, 0x00000a1b },
1353 { 10, 0x00022010, 0x00000d02, 0x000e0111, 0x00000a1b },
1354 { 11, 0x00022010, 0x00000d06, 0x000e0111, 0x00000a1b },
1355 { 12, 0x00022010, 0x00000d0a, 0x000e0111, 0x00000a1b },
1356 { 13, 0x00022010, 0x00000d0e, 0x000e0111, 0x00000a1b },
1357 { 14, 0x00022010, 0x00000d1a, 0x000e0111, 0x00000a03 },
1358};
1359
1360/*
1361 * RF value list for RF2524
1362 * Supports: 2.4 GHz
1363 */
1364static const struct rf_channel rf_vals_bg_2524[] = {
1365 { 1, 0x00032020, 0x00000c9e, 0x00000101, 0x00000a1b },
1366 { 2, 0x00032020, 0x00000ca2, 0x00000101, 0x00000a1b },
1367 { 3, 0x00032020, 0x00000ca6, 0x00000101, 0x00000a1b },
1368 { 4, 0x00032020, 0x00000caa, 0x00000101, 0x00000a1b },
1369 { 5, 0x00032020, 0x00000cae, 0x00000101, 0x00000a1b },
1370 { 6, 0x00032020, 0x00000cb2, 0x00000101, 0x00000a1b },
1371 { 7, 0x00032020, 0x00000cb6, 0x00000101, 0x00000a1b },
1372 { 8, 0x00032020, 0x00000cba, 0x00000101, 0x00000a1b },
1373 { 9, 0x00032020, 0x00000cbe, 0x00000101, 0x00000a1b },
1374 { 10, 0x00032020, 0x00000d02, 0x00000101, 0x00000a1b },
1375 { 11, 0x00032020, 0x00000d06, 0x00000101, 0x00000a1b },
1376 { 12, 0x00032020, 0x00000d0a, 0x00000101, 0x00000a1b },
1377 { 13, 0x00032020, 0x00000d0e, 0x00000101, 0x00000a1b },
1378 { 14, 0x00032020, 0x00000d1a, 0x00000101, 0x00000a03 },
1379};
1380
1381/*
1382 * RF value list for RF2525
1383 * Supports: 2.4 GHz
1384 */
1385static const struct rf_channel rf_vals_bg_2525[] = {
1386 { 1, 0x00022020, 0x00080c9e, 0x00060111, 0x00000a1b },
1387 { 2, 0x00022020, 0x00080ca2, 0x00060111, 0x00000a1b },
1388 { 3, 0x00022020, 0x00080ca6, 0x00060111, 0x00000a1b },
1389 { 4, 0x00022020, 0x00080caa, 0x00060111, 0x00000a1b },
1390 { 5, 0x00022020, 0x00080cae, 0x00060111, 0x00000a1b },
1391 { 6, 0x00022020, 0x00080cb2, 0x00060111, 0x00000a1b },
1392 { 7, 0x00022020, 0x00080cb6, 0x00060111, 0x00000a1b },
1393 { 8, 0x00022020, 0x00080cba, 0x00060111, 0x00000a1b },
1394 { 9, 0x00022020, 0x00080cbe, 0x00060111, 0x00000a1b },
1395 { 10, 0x00022020, 0x00080d02, 0x00060111, 0x00000a1b },
1396 { 11, 0x00022020, 0x00080d06, 0x00060111, 0x00000a1b },
1397 { 12, 0x00022020, 0x00080d0a, 0x00060111, 0x00000a1b },
1398 { 13, 0x00022020, 0x00080d0e, 0x00060111, 0x00000a1b },
1399 { 14, 0x00022020, 0x00080d1a, 0x00060111, 0x00000a03 },
1400};
1401
1402/*
1403 * RF value list for RF2525e
1404 * Supports: 2.4 GHz
1405 */
1406static const struct rf_channel rf_vals_bg_2525e[] = {
1407 { 1, 0x00022010, 0x0000089a, 0x00060111, 0x00000e1b },
1408 { 2, 0x00022010, 0x0000089e, 0x00060111, 0x00000e07 },
1409 { 3, 0x00022010, 0x0000089e, 0x00060111, 0x00000e1b },
1410 { 4, 0x00022010, 0x000008a2, 0x00060111, 0x00000e07 },
1411 { 5, 0x00022010, 0x000008a2, 0x00060111, 0x00000e1b },
1412 { 6, 0x00022010, 0x000008a6, 0x00060111, 0x00000e07 },
1413 { 7, 0x00022010, 0x000008a6, 0x00060111, 0x00000e1b },
1414 { 8, 0x00022010, 0x000008aa, 0x00060111, 0x00000e07 },
1415 { 9, 0x00022010, 0x000008aa, 0x00060111, 0x00000e1b },
1416 { 10, 0x00022010, 0x000008ae, 0x00060111, 0x00000e07 },
1417 { 11, 0x00022010, 0x000008ae, 0x00060111, 0x00000e1b },
1418 { 12, 0x00022010, 0x000008b2, 0x00060111, 0x00000e07 },
1419 { 13, 0x00022010, 0x000008b2, 0x00060111, 0x00000e1b },
1420 { 14, 0x00022010, 0x000008b6, 0x00060111, 0x00000e23 },
1421};
1422
1423/*
1424 * RF value list for RF5222
1425 * Supports: 2.4 GHz & 5.2 GHz
1426 */
1427static const struct rf_channel rf_vals_5222[] = {
1428 { 1, 0x00022020, 0x00001136, 0x00000101, 0x00000a0b },
1429 { 2, 0x00022020, 0x0000113a, 0x00000101, 0x00000a0b },
1430 { 3, 0x00022020, 0x0000113e, 0x00000101, 0x00000a0b },
1431 { 4, 0x00022020, 0x00001182, 0x00000101, 0x00000a0b },
1432 { 5, 0x00022020, 0x00001186, 0x00000101, 0x00000a0b },
1433 { 6, 0x00022020, 0x0000118a, 0x00000101, 0x00000a0b },
1434 { 7, 0x00022020, 0x0000118e, 0x00000101, 0x00000a0b },
1435 { 8, 0x00022020, 0x00001192, 0x00000101, 0x00000a0b },
1436 { 9, 0x00022020, 0x00001196, 0x00000101, 0x00000a0b },
1437 { 10, 0x00022020, 0x0000119a, 0x00000101, 0x00000a0b },
1438 { 11, 0x00022020, 0x0000119e, 0x00000101, 0x00000a0b },
1439 { 12, 0x00022020, 0x000011a2, 0x00000101, 0x00000a0b },
1440 { 13, 0x00022020, 0x000011a6, 0x00000101, 0x00000a0b },
1441 { 14, 0x00022020, 0x000011ae, 0x00000101, 0x00000a1b },
1442
1443 /* 802.11 UNI / HyperLan 2 */
1444 { 36, 0x00022010, 0x00018896, 0x00000101, 0x00000a1f },
1445 { 40, 0x00022010, 0x0001889a, 0x00000101, 0x00000a1f },
1446 { 44, 0x00022010, 0x0001889e, 0x00000101, 0x00000a1f },
1447 { 48, 0x00022010, 0x000188a2, 0x00000101, 0x00000a1f },
1448 { 52, 0x00022010, 0x000188a6, 0x00000101, 0x00000a1f },
1449 { 66, 0x00022010, 0x000188aa, 0x00000101, 0x00000a1f },
1450 { 60, 0x00022010, 0x000188ae, 0x00000101, 0x00000a1f },
1451 { 64, 0x00022010, 0x000188b2, 0x00000101, 0x00000a1f },
1452
1453 /* 802.11 HyperLan 2 */
1454 { 100, 0x00022010, 0x00008802, 0x00000101, 0x00000a0f },
1455 { 104, 0x00022010, 0x00008806, 0x00000101, 0x00000a0f },
1456 { 108, 0x00022010, 0x0000880a, 0x00000101, 0x00000a0f },
1457 { 112, 0x00022010, 0x0000880e, 0x00000101, 0x00000a0f },
1458 { 116, 0x00022010, 0x00008812, 0x00000101, 0x00000a0f },
1459 { 120, 0x00022010, 0x00008816, 0x00000101, 0x00000a0f },
1460 { 124, 0x00022010, 0x0000881a, 0x00000101, 0x00000a0f },
1461 { 128, 0x00022010, 0x0000881e, 0x00000101, 0x00000a0f },
1462 { 132, 0x00022010, 0x00008822, 0x00000101, 0x00000a0f },
1463 { 136, 0x00022010, 0x00008826, 0x00000101, 0x00000a0f },
1464
1465 /* 802.11 UNII */
1466 { 140, 0x00022010, 0x0000882a, 0x00000101, 0x00000a0f },
1467 { 149, 0x00022020, 0x000090a6, 0x00000101, 0x00000a07 },
1468 { 153, 0x00022020, 0x000090ae, 0x00000101, 0x00000a07 },
1469 { 157, 0x00022020, 0x000090b6, 0x00000101, 0x00000a07 },
1470 { 161, 0x00022020, 0x000090be, 0x00000101, 0x00000a07 },
1471};
1472
1473static void rt2500usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
1474{
1475 struct hw_mode_spec *spec = &rt2x00dev->spec;
1476 u8 *txpower;
1477 unsigned int i;
1478
1479 /*
1480 * Initialize all hw fields.
1481 */
1482 rt2x00dev->hw->flags =
1483 IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE |
1484 IEEE80211_HW_RX_INCLUDES_FCS |
Johannes Berg4150c572007-09-17 01:29:23 -04001485 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING;
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001486 rt2x00dev->hw->extra_tx_headroom = TXD_DESC_SIZE;
1487 rt2x00dev->hw->max_signal = MAX_SIGNAL;
1488 rt2x00dev->hw->max_rssi = MAX_RX_SSI;
1489 rt2x00dev->hw->queues = 2;
1490
1491 SET_IEEE80211_DEV(rt2x00dev->hw, &rt2x00dev_usb(rt2x00dev)->dev);
1492 SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
1493 rt2x00_eeprom_addr(rt2x00dev,
1494 EEPROM_MAC_ADDR_0));
1495
1496 /*
1497 * Convert tx_power array in eeprom.
1498 */
1499 txpower = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_START);
1500 for (i = 0; i < 14; i++)
1501 txpower[i] = TXPOWER_FROM_DEV(txpower[i]);
1502
1503 /*
1504 * Initialize hw_mode information.
1505 */
1506 spec->num_modes = 2;
1507 spec->num_rates = 12;
1508 spec->tx_power_a = NULL;
1509 spec->tx_power_bg = txpower;
1510 spec->tx_power_default = DEFAULT_TXPOWER;
1511
1512 if (rt2x00_rf(&rt2x00dev->chip, RF2522)) {
1513 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2522);
1514 spec->channels = rf_vals_bg_2522;
1515 } else if (rt2x00_rf(&rt2x00dev->chip, RF2523)) {
1516 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2523);
1517 spec->channels = rf_vals_bg_2523;
1518 } else if (rt2x00_rf(&rt2x00dev->chip, RF2524)) {
1519 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2524);
1520 spec->channels = rf_vals_bg_2524;
1521 } else if (rt2x00_rf(&rt2x00dev->chip, RF2525)) {
1522 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2525);
1523 spec->channels = rf_vals_bg_2525;
1524 } else if (rt2x00_rf(&rt2x00dev->chip, RF2525E)) {
1525 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2525e);
1526 spec->channels = rf_vals_bg_2525e;
1527 } else if (rt2x00_rf(&rt2x00dev->chip, RF5222)) {
1528 spec->num_channels = ARRAY_SIZE(rf_vals_5222);
1529 spec->channels = rf_vals_5222;
1530 spec->num_modes = 3;
1531 }
1532}
1533
1534static int rt2500usb_probe_hw(struct rt2x00_dev *rt2x00dev)
1535{
1536 int retval;
1537
1538 /*
1539 * Allocate eeprom data.
1540 */
1541 retval = rt2500usb_validate_eeprom(rt2x00dev);
1542 if (retval)
1543 return retval;
1544
1545 retval = rt2500usb_init_eeprom(rt2x00dev);
1546 if (retval)
1547 return retval;
1548
1549 /*
1550 * Initialize hw specifications.
1551 */
1552 rt2500usb_probe_hw_mode(rt2x00dev);
1553
1554 /*
Johannes Berg4150c572007-09-17 01:29:23 -04001555 * This device requires the beacon ring
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001556 */
Ivo van Doorn066cb632007-09-25 20:55:39 +02001557 __set_bit(DRIVER_REQUIRE_BEACON_RING, &rt2x00dev->flags);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001558
1559 /*
1560 * Set the rssi offset.
1561 */
1562 rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
1563
1564 return 0;
1565}
1566
1567/*
1568 * IEEE80211 stack callback functions.
1569 */
Johannes Berg4150c572007-09-17 01:29:23 -04001570static void rt2500usb_configure_filter(struct ieee80211_hw *hw,
1571 unsigned int changed_flags,
1572 unsigned int *total_flags,
1573 int mc_count,
1574 struct dev_addr_list *mc_list)
1575{
1576 struct rt2x00_dev *rt2x00dev = hw->priv;
1577 struct interface *intf = &rt2x00dev->interface;
1578 u16 reg;
1579
1580 /*
1581 * Mask off any flags we are going to ignore from
1582 * the total_flags field.
1583 */
1584 *total_flags &=
1585 FIF_ALLMULTI |
1586 FIF_FCSFAIL |
1587 FIF_PLCPFAIL |
1588 FIF_CONTROL |
1589 FIF_OTHER_BSS |
1590 FIF_PROMISC_IN_BSS;
1591
1592 /*
1593 * Apply some rules to the filters:
1594 * - Some filters imply different filters to be set.
1595 * - Some things we can't filter out at all.
1596 * - Some filters are set based on interface type.
1597 */
1598 if (mc_count)
1599 *total_flags |= FIF_ALLMULTI;
Ivo van Doorn5886d0d2007-10-06 14:13:38 +02001600 if (*total_flags & FIF_OTHER_BSS ||
1601 *total_flags & FIF_PROMISC_IN_BSS)
Johannes Berg4150c572007-09-17 01:29:23 -04001602 *total_flags |= FIF_PROMISC_IN_BSS | FIF_OTHER_BSS;
1603 if (is_interface_type(intf, IEEE80211_IF_TYPE_AP))
1604 *total_flags |= FIF_PROMISC_IN_BSS;
1605
1606 /*
1607 * Check if there is any work left for us.
1608 */
1609 if (intf->filter == *total_flags)
1610 return;
1611 intf->filter = *total_flags;
1612
1613 /*
1614 * When in atomic context, reschedule and let rt2x00lib
1615 * call this function again.
1616 */
1617 if (in_atomic()) {
1618 queue_work(rt2x00dev->hw->workqueue, &rt2x00dev->filter_work);
1619 return;
1620 }
1621
1622 /*
1623 * Start configuration steps.
1624 * Note that the version error will always be dropped
1625 * and broadcast frames will always be accepted since
1626 * there is no filter for it at this time.
1627 */
1628 rt2500usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
1629 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_CRC,
1630 !(*total_flags & FIF_FCSFAIL));
1631 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_PHYSICAL,
1632 !(*total_flags & FIF_PLCPFAIL));
1633 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_CONTROL,
1634 !(*total_flags & FIF_CONTROL));
1635 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_NOT_TO_ME,
1636 !(*total_flags & FIF_PROMISC_IN_BSS));
1637 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_TODS,
1638 !(*total_flags & FIF_PROMISC_IN_BSS));
1639 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_VERSION_ERROR, 1);
1640 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_MULTICAST,
1641 !(*total_flags & FIF_ALLMULTI));
1642 rt2x00_set_field16(&reg, TXRX_CSR2_DROP_BROADCAST, 0);
1643 rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
1644}
1645
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001646static int rt2500usb_beacon_update(struct ieee80211_hw *hw,
1647 struct sk_buff *skb,
1648 struct ieee80211_tx_control *control)
1649{
1650 struct rt2x00_dev *rt2x00dev = hw->priv;
1651 struct usb_device *usb_dev =
1652 interface_to_usbdev(rt2x00dev_usb(rt2x00dev));
1653 struct data_ring *ring =
1654 rt2x00lib_get_ring(rt2x00dev, IEEE80211_TX_QUEUE_BEACON);
1655 struct data_entry *beacon;
1656 struct data_entry *guardian;
Ivo van Doorndd9fa2d2007-10-06 14:15:46 +02001657 int pipe = usb_sndbulkpipe(usb_dev, 1);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001658 int length;
1659
1660 /*
1661 * Just in case the ieee80211 doesn't set this,
1662 * but we need this queue set for the descriptor
1663 * initialization.
1664 */
1665 control->queue = IEEE80211_TX_QUEUE_BEACON;
1666
1667 /*
1668 * Obtain 2 entries, one for the guardian byte,
1669 * the second for the actual beacon.
1670 */
1671 guardian = rt2x00_get_data_entry(ring);
1672 rt2x00_ring_index_inc(ring);
1673 beacon = rt2x00_get_data_entry(ring);
1674
1675 /*
1676 * First we create the beacon.
1677 */
1678 skb_push(skb, ring->desc_size);
Ivo van Doornc22eb872007-10-06 14:18:22 +02001679 memset(skb->data, 0, ring->desc_size);
1680
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001681 rt2x00lib_write_tx_desc(rt2x00dev, (struct data_desc *)skb->data,
1682 (struct ieee80211_hdr *)(skb->data +
1683 ring->desc_size),
1684 skb->len - ring->desc_size, control);
1685
Ivo van Doornb242e892007-11-15 23:41:31 +01001686 length = rt2500usb_get_tx_data_len(rt2x00dev, skb);
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001687
Ivo van Doorndd9fa2d2007-10-06 14:15:46 +02001688 usb_fill_bulk_urb(beacon->priv, usb_dev, pipe,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001689 skb->data, length, rt2500usb_beacondone, beacon);
1690
1691 beacon->skb = skb;
1692
1693 /*
1694 * Second we need to create the guardian byte.
1695 * We only need a single byte, so lets recycle
1696 * the 'flags' field we are not using for beacons.
1697 */
1698 guardian->flags = 0;
Ivo van Doorndd9fa2d2007-10-06 14:15:46 +02001699 usb_fill_bulk_urb(guardian->priv, usb_dev, pipe,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001700 &guardian->flags, 1, rt2500usb_beacondone, guardian);
1701
1702 /*
1703 * Send out the guardian byte.
1704 */
1705 usb_submit_urb(guardian->priv, GFP_ATOMIC);
1706
1707 /*
1708 * Enable beacon generation.
1709 */
1710 rt2500usb_kick_tx_queue(rt2x00dev, IEEE80211_TX_QUEUE_BEACON);
1711
1712 return 0;
1713}
1714
1715static const struct ieee80211_ops rt2500usb_mac80211_ops = {
1716 .tx = rt2x00mac_tx,
Johannes Berg4150c572007-09-17 01:29:23 -04001717 .start = rt2x00mac_start,
1718 .stop = rt2x00mac_stop,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001719 .add_interface = rt2x00mac_add_interface,
1720 .remove_interface = rt2x00mac_remove_interface,
1721 .config = rt2x00mac_config,
1722 .config_interface = rt2x00mac_config_interface,
Johannes Berg4150c572007-09-17 01:29:23 -04001723 .configure_filter = rt2500usb_configure_filter,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001724 .get_stats = rt2x00mac_get_stats,
Ivo van Doorn5c58ee52007-10-06 13:34:52 +02001725 .erp_ie_changed = rt2x00mac_erp_ie_changed,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001726 .conf_tx = rt2x00mac_conf_tx,
1727 .get_tx_stats = rt2x00mac_get_tx_stats,
1728 .beacon_update = rt2500usb_beacon_update,
1729};
1730
1731static const struct rt2x00lib_ops rt2500usb_rt2x00_ops = {
1732 .probe_hw = rt2500usb_probe_hw,
1733 .initialize = rt2x00usb_initialize,
1734 .uninitialize = rt2x00usb_uninitialize,
1735 .set_device_state = rt2500usb_set_device_state,
1736 .link_stats = rt2500usb_link_stats,
1737 .reset_tuner = rt2500usb_reset_tuner,
1738 .link_tuner = rt2500usb_link_tuner,
1739 .write_tx_desc = rt2500usb_write_tx_desc,
1740 .write_tx_data = rt2x00usb_write_tx_data,
Ivo van Doorndd9fa2d2007-10-06 14:15:46 +02001741 .get_tx_data_len = rt2500usb_get_tx_data_len,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001742 .kick_tx_queue = rt2500usb_kick_tx_queue,
1743 .fill_rxdone = rt2500usb_fill_rxdone,
1744 .config_mac_addr = rt2500usb_config_mac_addr,
1745 .config_bssid = rt2500usb_config_bssid,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001746 .config_type = rt2500usb_config_type,
Ivo van Doorn5c58ee52007-10-06 13:34:52 +02001747 .config_preamble = rt2500usb_config_preamble,
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001748 .config = rt2500usb_config,
1749};
1750
1751static const struct rt2x00_ops rt2500usb_ops = {
1752 .name = DRV_NAME,
1753 .rxd_size = RXD_DESC_SIZE,
1754 .txd_size = TXD_DESC_SIZE,
1755 .eeprom_size = EEPROM_SIZE,
1756 .rf_size = RF_SIZE,
1757 .lib = &rt2500usb_rt2x00_ops,
1758 .hw = &rt2500usb_mac80211_ops,
1759#ifdef CONFIG_RT2X00_LIB_DEBUGFS
1760 .debugfs = &rt2500usb_rt2x00debug,
1761#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
1762};
1763
1764/*
1765 * rt2500usb module information.
1766 */
1767static struct usb_device_id rt2500usb_device_table[] = {
1768 /* ASUS */
1769 { USB_DEVICE(0x0b05, 0x1706), USB_DEVICE_DATA(&rt2500usb_ops) },
1770 { USB_DEVICE(0x0b05, 0x1707), USB_DEVICE_DATA(&rt2500usb_ops) },
1771 /* Belkin */
1772 { USB_DEVICE(0x050d, 0x7050), USB_DEVICE_DATA(&rt2500usb_ops) },
1773 { USB_DEVICE(0x050d, 0x7051), USB_DEVICE_DATA(&rt2500usb_ops) },
1774 { USB_DEVICE(0x050d, 0x705a), USB_DEVICE_DATA(&rt2500usb_ops) },
1775 /* Cisco Systems */
1776 { USB_DEVICE(0x13b1, 0x000d), USB_DEVICE_DATA(&rt2500usb_ops) },
1777 { USB_DEVICE(0x13b1, 0x0011), USB_DEVICE_DATA(&rt2500usb_ops) },
1778 { USB_DEVICE(0x13b1, 0x001a), USB_DEVICE_DATA(&rt2500usb_ops) },
1779 /* Conceptronic */
1780 { USB_DEVICE(0x14b2, 0x3c02), USB_DEVICE_DATA(&rt2500usb_ops) },
1781 /* D-LINK */
1782 { USB_DEVICE(0x2001, 0x3c00), USB_DEVICE_DATA(&rt2500usb_ops) },
1783 /* Gigabyte */
1784 { USB_DEVICE(0x1044, 0x8001), USB_DEVICE_DATA(&rt2500usb_ops) },
1785 { USB_DEVICE(0x1044, 0x8007), USB_DEVICE_DATA(&rt2500usb_ops) },
1786 /* Hercules */
1787 { USB_DEVICE(0x06f8, 0xe000), USB_DEVICE_DATA(&rt2500usb_ops) },
1788 /* Melco */
1789 { USB_DEVICE(0x0411, 0x0066), USB_DEVICE_DATA(&rt2500usb_ops) },
1790 { USB_DEVICE(0x0411, 0x0067), USB_DEVICE_DATA(&rt2500usb_ops) },
1791 { USB_DEVICE(0x0411, 0x008b), USB_DEVICE_DATA(&rt2500usb_ops) },
1792 { USB_DEVICE(0x0411, 0x0097), USB_DEVICE_DATA(&rt2500usb_ops) },
1793
1794 /* MSI */
1795 { USB_DEVICE(0x0db0, 0x6861), USB_DEVICE_DATA(&rt2500usb_ops) },
1796 { USB_DEVICE(0x0db0, 0x6865), USB_DEVICE_DATA(&rt2500usb_ops) },
1797 { USB_DEVICE(0x0db0, 0x6869), USB_DEVICE_DATA(&rt2500usb_ops) },
1798 /* Ralink */
1799 { USB_DEVICE(0x148f, 0x1706), USB_DEVICE_DATA(&rt2500usb_ops) },
1800 { USB_DEVICE(0x148f, 0x2570), USB_DEVICE_DATA(&rt2500usb_ops) },
1801 { USB_DEVICE(0x148f, 0x2573), USB_DEVICE_DATA(&rt2500usb_ops) },
1802 { USB_DEVICE(0x148f, 0x9020), USB_DEVICE_DATA(&rt2500usb_ops) },
1803 /* Siemens */
1804 { USB_DEVICE(0x0681, 0x3c06), USB_DEVICE_DATA(&rt2500usb_ops) },
1805 /* SMC */
1806 { USB_DEVICE(0x0707, 0xee13), USB_DEVICE_DATA(&rt2500usb_ops) },
1807 /* Spairon */
1808 { USB_DEVICE(0x114b, 0x0110), USB_DEVICE_DATA(&rt2500usb_ops) },
1809 /* Trust */
1810 { USB_DEVICE(0x0eb0, 0x9020), USB_DEVICE_DATA(&rt2500usb_ops) },
1811 /* Zinwell */
1812 { USB_DEVICE(0x5a57, 0x0260), USB_DEVICE_DATA(&rt2500usb_ops) },
1813 { 0, }
1814};
1815
1816MODULE_AUTHOR(DRV_PROJECT);
1817MODULE_VERSION(DRV_VERSION);
1818MODULE_DESCRIPTION("Ralink RT2500 USB Wireless LAN driver.");
1819MODULE_SUPPORTED_DEVICE("Ralink RT2570 USB chipset based cards");
1820MODULE_DEVICE_TABLE(usb, rt2500usb_device_table);
1821MODULE_LICENSE("GPL");
1822
1823static struct usb_driver rt2500usb_driver = {
1824 .name = DRV_NAME,
1825 .id_table = rt2500usb_device_table,
1826 .probe = rt2x00usb_probe,
1827 .disconnect = rt2x00usb_disconnect,
1828 .suspend = rt2x00usb_suspend,
1829 .resume = rt2x00usb_resume,
1830};
1831
1832static int __init rt2500usb_init(void)
1833{
1834 return usb_register(&rt2500usb_driver);
1835}
1836
1837static void __exit rt2500usb_exit(void)
1838{
1839 usb_deregister(&rt2500usb_driver);
1840}
1841
1842module_init(rt2500usb_init);
1843module_exit(rt2500usb_exit);