2 Copyright (C) 2004 - 2007 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
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.
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.
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.
23 Abstract: rt2500usb device specific routines.
24 Supported chipsets: RT2570.
28 * Set enviroment defines for rt2x00.h
30 #define DRV_NAME "rt2500usb"
32 #include <linux/kernel.h>
33 #include <linux/module.h>
34 #include <linux/version.h>
35 #include <linux/init.h>
36 #include <linux/usb.h>
37 #include <linux/delay.h>
38 #include <linux/etherdevice.h>
41 #include "rt2x00lib.h"
42 #include "rt2x00usb.h"
43 #include "rt2500usb.h"
47 * All access to the CSR registers will go through the methods
48 * rt2500usb_register_read and rt2500usb_register_write.
49 * BBP and RF register require indirect register access,
50 * and use the CSR registers BBPCSR and RFCSR to achieve this.
51 * These indirect registers work with busy bits,
52 * and we will try maximal REGISTER_BUSY_COUNT times to access
53 * the register while taking a REGISTER_BUSY_DELAY us delay
54 * between each attampt. When the busy bit is still set at that time,
55 * the access attempt is considered to have failed,
56 * and we will print an error.
58 static inline void rt2500usb_register_read(
59 const struct rt2x00_dev
*rt2x00dev
,
60 const u16 offset
, u16
*value
)
63 rt2x00usb_vendor_request(
64 rt2x00dev
, USB_MULTI_READ
, USB_VENDOR_REQUEST_IN
,
65 offset
, 0x00, ®
, sizeof(u16
), REGISTER_TIMEOUT
);
66 *value
= le16_to_cpu(reg
);
69 static inline void rt2500usb_register_multiread(
70 const struct rt2x00_dev
*rt2x00dev
,
71 const u16 offset
, void *value
, const u16 length
)
73 rt2x00usb_vendor_request(
74 rt2x00dev
, USB_MULTI_READ
, USB_VENDOR_REQUEST_IN
,
75 offset
, 0x00, value
, length
,
76 REGISTER_TIMEOUT
* (length
/ sizeof(u16
)));
79 static inline void rt2500usb_register_write(
80 const struct rt2x00_dev
*rt2x00dev
,
81 const u16 offset
, u16 value
)
83 __le16 reg
= cpu_to_le16(value
);
84 rt2x00usb_vendor_request(
85 rt2x00dev
, USB_MULTI_WRITE
, USB_VENDOR_REQUEST_OUT
,
86 offset
, 0x00, ®
, sizeof(u16
), REGISTER_TIMEOUT
);
89 static inline void rt2500usb_register_multiwrite(
90 const struct rt2x00_dev
*rt2x00dev
,
91 const u16 offset
, void *value
, const u16 length
)
93 rt2x00usb_vendor_request(
94 rt2x00dev
, USB_MULTI_WRITE
, USB_VENDOR_REQUEST_OUT
,
95 offset
, 0x00, value
, length
,
96 REGISTER_TIMEOUT
* (length
/ sizeof(u16
)));
99 static u16
rt2500usb_bbp_check(const struct rt2x00_dev
*rt2x00dev
)
104 for (i
= 0; i
< REGISTER_BUSY_COUNT
; i
++) {
105 rt2500usb_register_read(rt2x00dev
, PHY_CSR8
, ®
);
106 if (!rt2x00_get_field16(reg
, PHY_CSR8_BUSY
))
108 udelay(REGISTER_BUSY_DELAY
);
114 static void rt2500usb_bbp_write(const struct rt2x00_dev
*rt2x00dev
,
115 const u8 reg_id
, const u8 value
)
120 * Wait until the BBP becomes ready.
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");
129 * Write the data into the BBP.
132 rt2x00_set_field16(®
, PHY_CSR7_DATA
, value
);
133 rt2x00_set_field16(®
, PHY_CSR7_REG_ID
, reg_id
);
134 rt2x00_set_field16(®
, PHY_CSR7_READ_CONTROL
, 0);
136 rt2500usb_register_write(rt2x00dev
, PHY_CSR7
, reg
);
139 static void rt2500usb_bbp_read(const struct rt2x00_dev
*rt2x00dev
,
140 const u8 reg_id
, u8
*value
)
145 * Wait until the BBP becomes ready.
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");
154 * Write the request into the BBP.
157 rt2x00_set_field16(®
, PHY_CSR7_REG_ID
, reg_id
);
158 rt2x00_set_field16(®
, PHY_CSR7_READ_CONTROL
, 1);
160 rt2500usb_register_write(rt2x00dev
, PHY_CSR7
, reg
);
163 * Wait until the BBP becomes ready.
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");
172 rt2500usb_register_read(rt2x00dev
, PHY_CSR7
, ®
);
173 *value
= rt2x00_get_field16(reg
, PHY_CSR7_DATA
);
176 static void rt2500usb_rf_write(const struct rt2x00_dev
*rt2x00dev
,
182 for (i
= 0; i
< REGISTER_BUSY_COUNT
; i
++) {
183 rt2500usb_register_read(rt2x00dev
, PHY_CSR10
, ®
);
184 if (!rt2x00_get_field16(reg
, PHY_CSR10_RF_BUSY
))
186 udelay(REGISTER_BUSY_DELAY
);
189 ERROR(rt2x00dev
, "PHY_CSR10 register busy. Write failed.\n");
194 rt2x00_set_field16(®
, PHY_CSR9_RF_VALUE
, value
);
195 rt2500usb_register_write(rt2x00dev
, PHY_CSR9
, reg
);
198 rt2x00_set_field16(®
, PHY_CSR10_RF_VALUE
, value
>> 16);
199 rt2x00_set_field16(®
, PHY_CSR10_RF_NUMBER_OF_BITS
, 20);
200 rt2x00_set_field16(®
, PHY_CSR10_RF_IF_SELECT
, 0);
201 rt2x00_set_field16(®
, PHY_CSR10_RF_BUSY
, 1);
203 rt2500usb_register_write(rt2x00dev
, PHY_CSR10
, reg
);
206 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
207 #define CSR_OFFSET(__word) ( CSR_REG_BASE + ((__word) * sizeof(u16)) )
209 static void rt2500usb_read_csr(struct rt2x00_dev
*rt2x00dev
,
210 const unsigned long word
, void *data
)
212 rt2500usb_register_read(rt2x00dev
, CSR_OFFSET(word
), data
);
215 static void rt2500usb_write_csr(struct rt2x00_dev
*rt2x00dev
,
216 const unsigned long word
, void *data
)
218 rt2500usb_register_write(rt2x00dev
, CSR_OFFSET(word
), *((u16
*)data
));
221 static void rt2500usb_read_eeprom(struct rt2x00_dev
*rt2x00dev
,
222 const unsigned long word
, void *data
)
224 rt2x00_eeprom_read(rt2x00dev
, word
, data
);
227 static void rt2500usb_write_eeprom(struct rt2x00_dev
*rt2x00dev
,
228 const unsigned long word
, void *data
)
230 rt2x00_eeprom_write(rt2x00dev
, word
, *((u16
*)data
));
233 static void rt2500usb_read_bbp(struct rt2x00_dev
*rt2x00dev
,
234 const unsigned long word
, void *data
)
236 rt2500usb_bbp_read(rt2x00dev
, word
, data
);
239 static void rt2500usb_write_bbp(struct rt2x00_dev
*rt2x00dev
,
240 const unsigned long word
, void *data
)
242 rt2500usb_bbp_write(rt2x00dev
, word
, *((u8
*)data
));
245 static const struct rt2x00debug rt2500usb_rt2x00debug
= {
246 .owner
= THIS_MODULE
,
248 .read
= rt2500usb_read_csr
,
249 .write
= rt2500usb_write_csr
,
250 .word_size
= sizeof(u16
),
251 .word_count
= CSR_REG_SIZE
/ sizeof(u16
),
254 .read
= rt2500usb_read_eeprom
,
255 .write
= rt2500usb_write_eeprom
,
256 .word_size
= sizeof(u16
),
257 .word_count
= EEPROM_SIZE
/ sizeof(u16
),
260 .read
= rt2500usb_read_bbp
,
261 .write
= rt2500usb_write_bbp
,
262 .word_size
= sizeof(u8
),
263 .word_count
= BBP_SIZE
/ sizeof(u8
),
266 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
269 * Configuration handlers.
271 static void rt2500usb_config_bssid(struct rt2x00_dev
*rt2x00dev
, u8
*bssid
)
275 memset(®
, 0, sizeof(reg
));
276 memcpy(®
, bssid
, ETH_ALEN
);
279 * The BSSID is passed to us as an array of bytes,
280 * that array is little endian, so no need for byte ordering.
282 rt2500usb_register_multiwrite(rt2x00dev
, MAC_CSR5
, ®
, sizeof(reg
));
285 static void rt2500usb_config_promisc(struct rt2x00_dev
*rt2x00dev
,
290 rt2500usb_register_read(rt2x00dev
, TXRX_CSR2
, ®
);
291 rt2x00_set_field16(®
, TXRX_CSR2_DROP_NOT_TO_ME
, !promisc
);
292 rt2500usb_register_write(rt2x00dev
, TXRX_CSR2
, reg
);
295 static void rt2500usb_config_type(struct rt2x00_dev
*rt2x00dev
,
300 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, 0);
303 * Apply hardware packet filter.
305 rt2500usb_register_read(rt2x00dev
, TXRX_CSR2
, ®
);
307 if (!is_monitor_present(&rt2x00dev
->interface
) &&
308 (type
== IEEE80211_IF_TYPE_IBSS
|| type
== IEEE80211_IF_TYPE_STA
))
309 rt2x00_set_field16(®
, TXRX_CSR2_DROP_TODS
, 1);
311 rt2x00_set_field16(®
, TXRX_CSR2_DROP_TODS
, 0);
313 rt2x00_set_field16(®
, TXRX_CSR2_DROP_CRC
, 1);
314 if (is_monitor_present(&rt2x00dev
->interface
)) {
315 rt2x00_set_field16(®
, TXRX_CSR2_DROP_PHYSICAL
, 0);
316 rt2x00_set_field16(®
, TXRX_CSR2_DROP_CONTROL
, 0);
317 rt2x00_set_field16(®
, TXRX_CSR2_DROP_VERSION_ERROR
, 0);
319 rt2x00_set_field16(®
, TXRX_CSR2_DROP_PHYSICAL
, 1);
320 rt2x00_set_field16(®
, TXRX_CSR2_DROP_CONTROL
, 1);
321 rt2x00_set_field16(®
, TXRX_CSR2_DROP_VERSION_ERROR
, 1);
324 rt2500usb_register_write(rt2x00dev
, TXRX_CSR2
, reg
);
327 * Enable beacon config
329 rt2500usb_register_read(rt2x00dev
, TXRX_CSR20
, ®
);
330 rt2x00_set_field16(®
, TXRX_CSR20_OFFSET
,
331 (PREAMBLE
+ get_duration(IEEE80211_HEADER
, 2)) >> 6);
332 if (type
== IEEE80211_IF_TYPE_STA
)
333 rt2x00_set_field16(®
, TXRX_CSR20_BCN_EXPECT_WINDOW
, 0);
335 rt2x00_set_field16(®
, TXRX_CSR20_BCN_EXPECT_WINDOW
, 2);
336 rt2500usb_register_write(rt2x00dev
, TXRX_CSR20
, reg
);
339 * Enable synchronisation.
341 rt2500usb_register_read(rt2x00dev
, TXRX_CSR18
, ®
);
342 rt2x00_set_field16(®
, TXRX_CSR18_OFFSET
, 0);
343 rt2500usb_register_write(rt2x00dev
, TXRX_CSR18
, reg
);
345 rt2500usb_register_read(rt2x00dev
, TXRX_CSR19
, ®
);
346 if (is_interface_present(&rt2x00dev
->interface
)) {
347 rt2x00_set_field16(®
, TXRX_CSR19_TSF_COUNT
, 1);
348 rt2x00_set_field16(®
, TXRX_CSR19_TBCN
, 1);
351 rt2x00_set_field16(®
, TXRX_CSR19_BEACON_GEN
, 0);
352 if (type
== IEEE80211_IF_TYPE_IBSS
|| type
== IEEE80211_IF_TYPE_AP
)
353 rt2x00_set_field16(®
, TXRX_CSR19_TSF_SYNC
, 2);
354 else if (type
== IEEE80211_IF_TYPE_STA
)
355 rt2x00_set_field16(®
, TXRX_CSR19_TSF_SYNC
, 1);
356 else if (is_monitor_present(&rt2x00dev
->interface
) &&
357 !is_interface_present(&rt2x00dev
->interface
))
358 rt2x00_set_field16(®
, TXRX_CSR19_TSF_SYNC
, 0);
360 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, reg
);
363 static void rt2500usb_config_channel(struct rt2x00_dev
*rt2x00dev
,
364 const int value
, const int channel
, const int txpower
)
366 u32 rf1
= rt2x00dev
->rf1
;
368 u32 rf3
= rt2x00dev
->rf3
;
369 u32 rf4
= rt2x00dev
->rf4
;
371 if (rt2x00_rf(&rt2x00dev
->chip
, RF2525
))
374 if ((rt2x00_rf(&rt2x00dev
->chip
, RF2523
) ||
375 rt2x00_rf(&rt2x00dev
->chip
, RF2524
) ||
376 rt2x00_rf(&rt2x00dev
->chip
, RF2525
)) &&
380 if (rt2x00_rf(&rt2x00dev
->chip
, RF2525E
)) {
389 if (rt2x00_rf(&rt2x00dev
->chip
, RF5222
)) {
393 } else if (channel
== 14) {
396 } else if (channel
< 64) {
399 } else if (channel
< 140) {
402 } else if (channel
< 161) {
411 rt2x00_set_field32(&rf3
, RF3_TXPOWER
, TXPOWER_TO_DEV(txpower
));
414 * For RT2525E we should first set the channel to half band higher.
416 if (rt2x00_rf(&rt2x00dev
->chip
, RF2525E
)) {
417 static const u32 vals
[] = {
418 0x000008aa, 0x000008ae, 0x000008ae, 0x000008b2,
419 0x000008b2, 0x000008b6, 0x000008b6, 0x000008ba,
420 0x000008ba, 0x000008be, 0x000008b7, 0x00000902,
421 0x00000902, 0x00000906
424 rt2500usb_rf_write(rt2x00dev
, vals
[channel
- 1]);
426 rt2500usb_rf_write(rt2x00dev
, rf4
);
429 rt2500usb_rf_write(rt2x00dev
, rf1
);
430 rt2500usb_rf_write(rt2x00dev
, rf2
);
431 rt2500usb_rf_write(rt2x00dev
, rf3
);
433 rt2500usb_rf_write(rt2x00dev
, rf4
);
438 rt2x00dev
->rf1
= rf1
;
439 rt2x00dev
->rf2
= rf2
;
440 rt2x00dev
->rf3
= rf3
;
441 rt2x00dev
->rf4
= rf4
;
442 rt2x00dev
->tx_power
= txpower
;
445 static void rt2500usb_config_txpower(struct rt2x00_dev
*rt2x00dev
,
448 rt2x00_set_field32(&rt2x00dev
->rf3
, RF3_TXPOWER
,
449 TXPOWER_TO_DEV(txpower
));
450 rt2500usb_rf_write(rt2x00dev
, rt2x00dev
->rf3
);
453 static void rt2500usb_config_antenna(struct rt2x00_dev
*rt2x00dev
,
454 const int antenna_tx
, const int antenna_rx
)
461 rt2500usb_bbp_read(rt2x00dev
, 2, &r2
);
462 rt2500usb_bbp_read(rt2x00dev
, 14, &r14
);
463 rt2500usb_register_read(rt2x00dev
, PHY_CSR5
, &csr5
);
464 rt2500usb_register_read(rt2x00dev
, PHY_CSR6
, &csr6
);
467 * Configure the TX antenna.
469 if (antenna_tx
== ANTENNA_DIVERSITY
) {
470 rt2x00_set_field8(&r2
, BBP_R2_TX_ANTENNA
, 1);
471 rt2x00_set_field16(&csr5
, PHY_CSR5_CCK
, 1);
472 rt2x00_set_field16(&csr6
, PHY_CSR6_OFDM
, 1);
473 } else if (antenna_tx
== ANTENNA_A
) {
474 rt2x00_set_field8(&r2
, BBP_R2_TX_ANTENNA
, 0);
475 rt2x00_set_field16(&csr5
, PHY_CSR5_CCK
, 0);
476 rt2x00_set_field16(&csr6
, PHY_CSR6_OFDM
, 0);
477 } else if (antenna_tx
== ANTENNA_B
) {
478 rt2x00_set_field8(&r2
, BBP_R2_TX_ANTENNA
, 2);
479 rt2x00_set_field16(&csr5
, PHY_CSR5_CCK
, 2);
480 rt2x00_set_field16(&csr6
, PHY_CSR6_OFDM
, 2);
484 * Configure the RX antenna.
486 if (antenna_rx
== ANTENNA_DIVERSITY
)
487 rt2x00_set_field8(&r14
, BBP_R14_RX_ANTENNA
, 1);
488 else if (antenna_rx
== ANTENNA_A
)
489 rt2x00_set_field8(&r14
, BBP_R14_RX_ANTENNA
, 0);
490 else if (antenna_rx
== ANTENNA_B
)
491 rt2x00_set_field8(&r14
, BBP_R14_RX_ANTENNA
, 2);
494 * RT2525E and RT5222 need to flip TX I/Q
496 if (rt2x00_rf(&rt2x00dev
->chip
, RF2525E
) ||
497 rt2x00_rf(&rt2x00dev
->chip
, RF5222
)) {
498 rt2x00_set_field8(&r2
, BBP_R2_TX_IQ_FLIP
, 1);
499 rt2x00_set_field16(&csr5
, PHY_CSR5_CCK_FLIP
, 1);
500 rt2x00_set_field16(&csr6
, PHY_CSR6_OFDM_FLIP
, 1);
503 * RT2525E does not need RX I/Q Flip.
505 if (rt2x00_rf(&rt2x00dev
->chip
, RF2525E
))
506 rt2x00_set_field8(&r14
, BBP_R14_RX_IQ_FLIP
, 0);
508 rt2x00_set_field16(&csr5
, PHY_CSR5_CCK_FLIP
, 0);
509 rt2x00_set_field16(&csr6
, PHY_CSR6_OFDM_FLIP
, 0);
512 rt2500usb_bbp_write(rt2x00dev
, 2, r2
);
513 rt2500usb_bbp_write(rt2x00dev
, 14, r14
);
514 rt2500usb_register_write(rt2x00dev
, PHY_CSR5
, csr5
);
515 rt2500usb_register_write(rt2x00dev
, PHY_CSR6
, csr6
);
518 static void rt2500usb_config_duration(struct rt2x00_dev
*rt2x00dev
,
519 const int short_slot_time
, const int beacon_int
)
523 rt2500usb_register_write(rt2x00dev
, MAC_CSR10
,
524 short_slot_time
? SHORT_SLOT_TIME
: SLOT_TIME
);
526 rt2500usb_register_read(rt2x00dev
, TXRX_CSR18
, ®
);
527 rt2x00_set_field16(®
, TXRX_CSR18_INTERVAL
, beacon_int
* 4);
528 rt2500usb_register_write(rt2x00dev
, TXRX_CSR18
, reg
);
531 static void rt2500usb_config_rate(struct rt2x00_dev
*rt2x00dev
, const int rate
)
533 struct ieee80211_conf
*conf
= &rt2x00dev
->hw
->conf
;
538 preamble
= DEVICE_GET_RATE_FIELD(rate
, PREAMBLE
)
539 ? SHORT_PREAMBLE
: PREAMBLE
;
541 reg
= DEVICE_GET_RATE_FIELD(rate
, RATEMASK
) & DEV_BASIC_RATE
;
543 rt2500usb_register_write(rt2x00dev
, TXRX_CSR11
, reg
);
545 rt2500usb_register_read(rt2x00dev
, TXRX_CSR1
, ®
);
546 value
= ((conf
->flags
& IEEE80211_CONF_SHORT_SLOT_TIME
) ?
548 PLCP
+ preamble
+ get_duration(ACK_SIZE
, 10);
549 rt2x00_set_field16(®
, TXRX_CSR1_ACK_TIMEOUT
, value
);
550 rt2500usb_register_write(rt2x00dev
, TXRX_CSR1
, reg
);
552 rt2500usb_register_read(rt2x00dev
, TXRX_CSR10
, ®
);
553 if (preamble
== SHORT_PREAMBLE
)
554 rt2x00_set_field16(®
, TXRX_CSR10_AUTORESPOND_PREAMBLE
, 1);
556 rt2x00_set_field16(®
, TXRX_CSR10_AUTORESPOND_PREAMBLE
, 0);
557 rt2500usb_register_write(rt2x00dev
, TXRX_CSR10
, reg
);
560 static void rt2500usb_config_phymode(struct rt2x00_dev
*rt2x00dev
,
563 struct ieee80211_hw_mode
*mode
;
564 struct ieee80211_rate
*rate
;
566 if (phymode
== MODE_IEEE80211A
)
567 rt2x00dev
->curr_hwmode
= HWMODE_A
;
568 else if (phymode
== MODE_IEEE80211B
)
569 rt2x00dev
->curr_hwmode
= HWMODE_B
;
571 rt2x00dev
->curr_hwmode
= HWMODE_G
;
573 mode
= &rt2x00dev
->hwmodes
[rt2x00dev
->curr_hwmode
];
574 rate
= &mode
->rates
[mode
->num_rates
- 1];
576 rt2500usb_config_rate(rt2x00dev
, rate
->val2
);
578 if (phymode
== MODE_IEEE80211B
) {
579 rt2500usb_register_write(rt2x00dev
, MAC_CSR11
, 0x000b);
580 rt2500usb_register_write(rt2x00dev
, MAC_CSR12
, 0x0040);
582 rt2500usb_register_write(rt2x00dev
, MAC_CSR11
, 0x0005);
583 rt2500usb_register_write(rt2x00dev
, MAC_CSR12
, 0x016c);
587 static void rt2500usb_config_mac_addr(struct rt2x00_dev
*rt2x00dev
, u8
*addr
)
591 memset(®
, 0, sizeof(reg
));
592 memcpy(®
, addr
, ETH_ALEN
);
595 * The MAC address is passed to us as an array of bytes,
596 * that array is little endian, so no need for byte ordering.
598 rt2500usb_register_multiwrite(rt2x00dev
, MAC_CSR2
, ®
, sizeof(reg
));
604 static void rt2500usb_enable_led(struct rt2x00_dev
*rt2x00dev
)
608 rt2500usb_register_read(rt2x00dev
, MAC_CSR21
, ®
);
609 rt2x00_set_field16(®
, MAC_CSR21_ON_PERIOD
, 70);
610 rt2x00_set_field16(®
, MAC_CSR21_OFF_PERIOD
, 30);
611 rt2500usb_register_write(rt2x00dev
, MAC_CSR21
, reg
);
613 rt2500usb_register_read(rt2x00dev
, MAC_CSR20
, ®
);
615 if (rt2x00dev
->led_mode
== LED_MODE_TXRX_ACTIVITY
) {
616 rt2x00_set_field16(®
, MAC_CSR20_LINK
, 1);
617 rt2x00_set_field16(®
, MAC_CSR20_ACTIVITY
, 0);
618 } else if (rt2x00dev
->led_mode
== LED_MODE_ASUS
) {
619 rt2x00_set_field16(®
, MAC_CSR20_LINK
, 0);
620 rt2x00_set_field16(®
, MAC_CSR20_ACTIVITY
, 1);
622 rt2x00_set_field16(®
, MAC_CSR20_LINK
, 1);
623 rt2x00_set_field16(®
, MAC_CSR20_ACTIVITY
, 1);
626 rt2500usb_register_write(rt2x00dev
, MAC_CSR20
, reg
);
629 static void rt2500usb_disable_led(struct rt2x00_dev
*rt2x00dev
)
633 rt2500usb_register_read(rt2x00dev
, MAC_CSR20
, ®
);
634 rt2x00_set_field16(®
, MAC_CSR20_LINK
, 0);
635 rt2x00_set_field16(®
, MAC_CSR20_ACTIVITY
, 0);
636 rt2500usb_register_write(rt2x00dev
, MAC_CSR20
, reg
);
642 static void rt2500usb_link_tuner(struct rt2x00_dev
*rt2x00dev
)
644 int rssi
= rt2x00_get_link_rssi(&rt2x00dev
->link
);
658 * Determine the BBP tuning threshold and correctly
659 * set BBP 24, 25 and 61.
661 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE
, &bbp_thresh
);
662 bbp_thresh
= rt2x00_get_field16(bbp_thresh
, EEPROM_BBPTUNE_THRESHOLD
);
664 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R24
, &r24
);
665 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R25
, &r25
);
666 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R61
, &r61
);
668 if ((rssi
+ bbp_thresh
) > 0) {
669 r24
= rt2x00_get_field16(r24
, EEPROM_BBPTUNE_R24_HIGH
);
670 r25
= rt2x00_get_field16(r25
, EEPROM_BBPTUNE_R25_HIGH
);
671 r61
= rt2x00_get_field16(r61
, EEPROM_BBPTUNE_R61_HIGH
);
673 r24
= rt2x00_get_field16(r24
, EEPROM_BBPTUNE_R24_LOW
);
674 r25
= rt2x00_get_field16(r25
, EEPROM_BBPTUNE_R25_LOW
);
675 r61
= rt2x00_get_field16(r61
, EEPROM_BBPTUNE_R61_LOW
);
678 rt2500usb_bbp_write(rt2x00dev
, 24, r24
);
679 rt2500usb_bbp_write(rt2x00dev
, 25, r25
);
680 rt2500usb_bbp_write(rt2x00dev
, 61, r61
);
683 * Read current r17 value, as well as the sensitivity values
684 * for the r17 register.
686 rt2500usb_bbp_read(rt2x00dev
, 17, &r17
);
687 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R17
, &r17_sens
);
690 * A too low RSSI will cause too much false CCA which will
691 * then corrupt the R17 tuning. To remidy this the tuning should
692 * be stopped (While making sure the R17 value will not exceed limits)
696 rt2500usb_bbp_write(rt2x00dev
, 17, 0x60);
701 * Special big-R17 for short distance
704 sens
= rt2x00_get_field16(r17_sens
, EEPROM_BBPTUNE_R17_LOW
);
706 rt2500usb_bbp_write(rt2x00dev
, 17, sens
);
711 * Special mid-R17 for middle distance
714 sens
= rt2x00_get_field16(r17_sens
, EEPROM_BBPTUNE_R17_HIGH
);
716 rt2500usb_bbp_write(rt2x00dev
, 17, sens
);
721 * Leave short or middle distance condition, restore r17
722 * to the dynamic tuning range.
724 rt2500usb_register_read(rt2x00dev
, STA_CSR3
, &cca_alarm
);
725 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_VGC
, &vgc_bound
);
726 vgc_bound
= rt2x00_get_field16(vgc_bound
, EEPROM_BBPTUNE_VGCUPPER
);
730 up_bound
= vgc_bound
;
732 up_bound
= vgc_bound
- (-77 - rssi
);
734 if (up_bound
< low_bound
)
735 up_bound
= low_bound
;
737 if (r17
> up_bound
) {
738 rt2500usb_bbp_write(rt2x00dev
, 17, up_bound
);
739 rt2x00dev
->rx_status
.noise
= up_bound
;
740 } else if (cca_alarm
> 512 && r17
< up_bound
) {
741 rt2500usb_bbp_write(rt2x00dev
, 17, ++r17
);
742 rt2x00dev
->rx_status
.noise
= r17
;
743 } else if (cca_alarm
< 100 && r17
> low_bound
) {
744 rt2500usb_bbp_write(rt2x00dev
, 17, --r17
);
745 rt2x00dev
->rx_status
.noise
= r17
;
750 * Initialization functions.
752 static int rt2500usb_init_registers(struct rt2x00_dev
*rt2x00dev
)
756 rt2x00usb_vendor_request(rt2x00dev
, USB_DEVICE_MODE
,
757 USB_VENDOR_REQUEST_OUT
, 0x0001, USB_MODE_TEST
, NULL
, 0,
759 rt2x00usb_vendor_request(rt2x00dev
, USB_SINGLE_WRITE
,
760 USB_VENDOR_REQUEST_OUT
, 0x0308, 0xf0, NULL
, 0,
763 rt2500usb_register_read(rt2x00dev
, TXRX_CSR2
, ®
);
764 rt2x00_set_field16(®
, TXRX_CSR2_DISABLE_RX
, 1);
765 rt2500usb_register_write(rt2x00dev
, TXRX_CSR2
, reg
);
767 rt2500usb_register_write(rt2x00dev
, MAC_CSR13
, 0x1111);
768 rt2500usb_register_write(rt2x00dev
, MAC_CSR14
, 0x1e11);
770 rt2500usb_register_write(rt2x00dev
, MAC_CSR1
, 0x0003);
771 rt2500usb_register_write(rt2x00dev
, MAC_CSR1
, 0x0000);
772 rt2500usb_register_write(rt2x00dev
, TXRX_CSR5
, 0x8c8d);
773 rt2500usb_register_write(rt2x00dev
, TXRX_CSR6
, 0x8b8a);
774 rt2500usb_register_write(rt2x00dev
, TXRX_CSR7
, 0x8687);
775 rt2500usb_register_write(rt2x00dev
, TXRX_CSR8
, 0x0085);
776 rt2500usb_register_write(rt2x00dev
, TXRX_CSR21
, 0xe78f);
777 rt2500usb_register_write(rt2x00dev
, MAC_CSR9
, 0xff1d);
779 if (rt2x00dev
->ops
->lib
->set_device_state(rt2x00dev
, STATE_AWAKE
))
782 rt2500usb_register_write(rt2x00dev
, MAC_CSR1
, 0x0004);
784 if (rt2x00_rev(&rt2x00dev
->chip
) >= RT2570_VERSION_C
) {
785 rt2500usb_register_read(rt2x00dev
, PHY_CSR2
, ®
);
790 rt2500usb_register_write(rt2x00dev
, PHY_CSR2
, reg
);
792 rt2500usb_register_write(rt2x00dev
, MAC_CSR11
, 0x0002);
793 rt2500usb_register_write(rt2x00dev
, MAC_CSR22
, 0x0053);
794 rt2500usb_register_write(rt2x00dev
, MAC_CSR15
, 0x01ee);
795 rt2500usb_register_write(rt2x00dev
, MAC_CSR16
, 0x0000);
797 rt2500usb_register_read(rt2x00dev
, TXRX_CSR0
, ®
);
798 rt2x00_set_field16(®
, TXRX_CSR0_IV_OFFSET
, IEEE80211_HEADER
);
799 rt2x00_set_field16(®
, TXRX_CSR0_KEY_ID
, 0xff);
800 rt2500usb_register_write(rt2x00dev
, TXRX_CSR0
, reg
);
802 rt2500usb_register_read(rt2x00dev
, MAC_CSR8
, ®
);
803 rt2x00_set_field16(®
, MAC_CSR8_MAX_FRAME_UNIT
,
804 rt2x00dev
->rx
->data_size
);
805 rt2500usb_register_write(rt2x00dev
, MAC_CSR8
, reg
);
807 rt2500usb_register_read(rt2x00dev
, MAC_CSR18
, ®
);
808 rt2x00_set_field16(®
, MAC_CSR18_DELAY_AFTER_BEACON
, 0x5a);
809 rt2500usb_register_write(rt2x00dev
, MAC_CSR18
, reg
);
811 rt2500usb_register_read(rt2x00dev
, TXRX_CSR1
, ®
);
812 rt2x00_set_field16(®
, TXRX_CSR1_AUTO_SEQUENCE
, 1);
813 rt2500usb_register_write(rt2x00dev
, TXRX_CSR1
, reg
);
815 rt2500usb_register_read(rt2x00dev
, PHY_CSR4
, ®
);
816 rt2500usb_register_write(rt2x00dev
, PHY_CSR4
, reg
| 0x0001);
821 static int rt2500usb_init_bbp(struct rt2x00_dev
*rt2x00dev
)
828 for (i
= 0; i
< REGISTER_BUSY_COUNT
; i
++) {
829 rt2500usb_bbp_read(rt2x00dev
, 0, &value
);
830 if ((value
!= 0xff) && (value
!= 0x00))
831 goto continue_csr_init
;
832 NOTICE(rt2x00dev
, "Waiting for BBP register.\n");
833 udelay(REGISTER_BUSY_DELAY
);
836 ERROR(rt2x00dev
, "BBP register access failed, aborting.\n");
840 rt2500usb_bbp_write(rt2x00dev
, 3, 0x02);
841 rt2500usb_bbp_write(rt2x00dev
, 4, 0x19);
842 rt2500usb_bbp_write(rt2x00dev
, 14, 0x1c);
843 rt2500usb_bbp_write(rt2x00dev
, 15, 0x30);
844 rt2500usb_bbp_write(rt2x00dev
, 16, 0xac);
845 rt2500usb_bbp_write(rt2x00dev
, 17, 0x48);
846 rt2500usb_bbp_write(rt2x00dev
, 18, 0x18);
847 rt2500usb_bbp_write(rt2x00dev
, 19, 0xff);
848 rt2500usb_bbp_write(rt2x00dev
, 20, 0x1e);
849 rt2500usb_bbp_write(rt2x00dev
, 21, 0x08);
850 rt2500usb_bbp_write(rt2x00dev
, 22, 0x08);
851 rt2500usb_bbp_write(rt2x00dev
, 23, 0x08);
852 rt2500usb_bbp_write(rt2x00dev
, 24, 0x80);
853 rt2500usb_bbp_write(rt2x00dev
, 25, 0x50);
854 rt2500usb_bbp_write(rt2x00dev
, 26, 0x08);
855 rt2500usb_bbp_write(rt2x00dev
, 27, 0x23);
856 rt2500usb_bbp_write(rt2x00dev
, 30, 0x10);
857 rt2500usb_bbp_write(rt2x00dev
, 31, 0x2b);
858 rt2500usb_bbp_write(rt2x00dev
, 32, 0xb9);
859 rt2500usb_bbp_write(rt2x00dev
, 34, 0x12);
860 rt2500usb_bbp_write(rt2x00dev
, 35, 0x50);
861 rt2500usb_bbp_write(rt2x00dev
, 39, 0xc4);
862 rt2500usb_bbp_write(rt2x00dev
, 40, 0x02);
863 rt2500usb_bbp_write(rt2x00dev
, 41, 0x60);
864 rt2500usb_bbp_write(rt2x00dev
, 53, 0x10);
865 rt2500usb_bbp_write(rt2x00dev
, 54, 0x18);
866 rt2500usb_bbp_write(rt2x00dev
, 56, 0x08);
867 rt2500usb_bbp_write(rt2x00dev
, 57, 0x10);
868 rt2500usb_bbp_write(rt2x00dev
, 58, 0x08);
869 rt2500usb_bbp_write(rt2x00dev
, 61, 0x60);
870 rt2500usb_bbp_write(rt2x00dev
, 62, 0x10);
871 rt2500usb_bbp_write(rt2x00dev
, 75, 0xff);
873 DEBUG(rt2x00dev
, "Start initialization from EEPROM...\n");
874 for (i
= 0; i
< EEPROM_BBP_SIZE
; i
++) {
875 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBP_START
+ i
, &eeprom
);
877 if (eeprom
!= 0xffff && eeprom
!= 0x0000) {
878 reg_id
= rt2x00_get_field16(eeprom
, EEPROM_BBP_REG_ID
);
879 value
= rt2x00_get_field16(eeprom
, EEPROM_BBP_VALUE
);
880 DEBUG(rt2x00dev
, "BBP: 0x%02x, value: 0x%02x.\n",
882 rt2500usb_bbp_write(rt2x00dev
, reg_id
, value
);
885 DEBUG(rt2x00dev
, "...End initialization from EEPROM.\n");
887 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R24
, &eeprom
);
888 value
= rt2x00_get_field16(eeprom
, EEPROM_BBPTUNE_R24_LOW
);
889 rt2500usb_bbp_write(rt2x00dev
, 24, value
);
891 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R25
, &eeprom
);
892 value
= rt2x00_get_field16(eeprom
, EEPROM_BBPTUNE_R25_LOW
);
893 rt2500usb_bbp_write(rt2x00dev
, 25, value
);
895 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R61
, &eeprom
);
896 value
= rt2x00_get_field16(eeprom
, EEPROM_BBPTUNE_R61_LOW
);
897 rt2500usb_bbp_write(rt2x00dev
, 61, value
);
899 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_VGC
, &eeprom
);
900 value
= rt2x00_get_field16(eeprom
, EEPROM_BBPTUNE_VGCUPPER
);
901 rt2500usb_bbp_write(rt2x00dev
, 17, value
);
907 * Device state switch handlers.
909 static void rt2500usb_toggle_rx(struct rt2x00_dev
*rt2x00dev
,
910 enum dev_state state
)
914 rt2500usb_register_read(rt2x00dev
, TXRX_CSR2
, ®
);
915 rt2x00_set_field16(®
, TXRX_CSR2_DISABLE_RX
,
916 state
== STATE_RADIO_RX_OFF
);
917 rt2500usb_register_write(rt2x00dev
, TXRX_CSR2
, reg
);
920 static int rt2500usb_enable_radio(struct rt2x00_dev
*rt2x00dev
)
923 * Initialize all registers.
925 if (rt2500usb_init_registers(rt2x00dev
) ||
926 rt2500usb_init_bbp(rt2x00dev
)) {
927 ERROR(rt2x00dev
, "Register initialization failed.\n");
931 rt2x00usb_enable_radio(rt2x00dev
);
936 rt2500usb_enable_led(rt2x00dev
);
941 static void rt2500usb_disable_radio(struct rt2x00_dev
*rt2x00dev
)
946 rt2500usb_disable_led(rt2x00dev
);
948 rt2500usb_register_write(rt2x00dev
, MAC_CSR13
, 0x2121);
949 rt2500usb_register_write(rt2x00dev
, MAC_CSR14
, 0x2121);
952 * Disable synchronisation.
954 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, 0);
956 rt2x00usb_disable_radio(rt2x00dev
);
959 static int rt2500usb_set_state(struct rt2x00_dev
*rt2x00dev
,
960 enum dev_state state
)
969 put_to_sleep
= (state
!= STATE_AWAKE
);
972 rt2x00_set_field16(®
, MAC_CSR17_BBP_DESIRE_STATE
, state
);
973 rt2x00_set_field16(®
, MAC_CSR17_RF_DESIRE_STATE
, state
);
974 rt2x00_set_field16(®
, MAC_CSR17_PUT_TO_SLEEP
, put_to_sleep
);
975 rt2500usb_register_write(rt2x00dev
, MAC_CSR17
, reg
);
976 rt2x00_set_field16(®
, MAC_CSR17_SET_STATE
, 1);
977 rt2500usb_register_write(rt2x00dev
, MAC_CSR17
, reg
);
980 * Device is not guaranteed to be in the requested state yet.
981 * We must wait until the register indicates that the
982 * device has entered the correct state.
984 for (i
= 0; i
< REGISTER_BUSY_COUNT
; i
++) {
985 rt2500usb_register_read(rt2x00dev
, MAC_CSR17
, ®2
);
986 bbp_state
= rt2x00_get_field16(reg2
, MAC_CSR17_BBP_CURR_STATE
);
987 rf_state
= rt2x00_get_field16(reg2
, MAC_CSR17_RF_CURR_STATE
);
988 if (bbp_state
== state
&& rf_state
== state
)
990 rt2500usb_register_write(rt2x00dev
, MAC_CSR17
, reg
);
994 NOTICE(rt2x00dev
, "Device failed to enter state %d, "
995 "current device state: bbp %d and rf %d.\n",
996 state
, bbp_state
, rf_state
);
1001 static int rt2500usb_set_device_state(struct rt2x00_dev
*rt2x00dev
,
1002 enum dev_state state
)
1007 case STATE_RADIO_ON
:
1008 retval
= rt2500usb_enable_radio(rt2x00dev
);
1010 case STATE_RADIO_OFF
:
1011 rt2500usb_disable_radio(rt2x00dev
);
1013 case STATE_RADIO_RX_ON
:
1014 case STATE_RADIO_RX_OFF
:
1015 rt2500usb_toggle_rx(rt2x00dev
, state
);
1017 case STATE_DEEP_SLEEP
:
1021 retval
= rt2500usb_set_state(rt2x00dev
, state
);
1032 * TX descriptor initialization
1034 static void rt2500usb_write_tx_desc(struct rt2x00_dev
*rt2x00dev
,
1035 struct data_entry
*entry
, struct data_desc
*txd
,
1036 struct data_entry_desc
*desc
, struct ieee80211_hdr
*ieee80211hdr
,
1037 unsigned int length
, struct ieee80211_tx_control
*control
)
1042 * Start writing the descriptor words.
1044 rt2x00_desc_read(txd
, 1, &word
);
1045 rt2x00_set_field32(&word
, TXD_W1_IV_OFFSET
, IEEE80211_HEADER
);
1046 rt2x00_set_field32(&word
, TXD_W1_AIFS
, entry
->ring
->tx_params
.aifs
);
1047 rt2x00_set_field32(&word
, TXD_W1_CWMIN
, entry
->ring
->tx_params
.cw_min
);
1048 rt2x00_set_field32(&word
, TXD_W1_CWMAX
, entry
->ring
->tx_params
.cw_max
);
1049 rt2x00_desc_write(txd
, 1, word
);
1051 rt2x00_desc_read(txd
, 2, &word
);
1052 rt2x00_set_field32(&word
, TXD_W2_PLCP_SIGNAL
, desc
->signal
);
1053 rt2x00_set_field32(&word
, TXD_W2_PLCP_SERVICE
, desc
->service
);
1054 rt2x00_set_field32(&word
, TXD_W2_PLCP_LENGTH_LOW
, desc
->length_low
);
1055 rt2x00_set_field32(&word
, TXD_W2_PLCP_LENGTH_HIGH
, desc
->length_high
);
1056 rt2x00_desc_write(txd
, 2, word
);
1058 rt2x00_desc_read(txd
, 0, &word
);
1059 rt2x00_set_field32(&word
, TXD_W0_RETRY_LIMIT
, control
->retry_limit
);
1060 rt2x00_set_field32(&word
, TXD_W0_MORE_FRAG
,
1061 test_bit(ENTRY_TXD_MORE_FRAG
, &entry
->flags
));
1062 rt2x00_set_field32(&word
, TXD_W0_ACK
,
1063 test_bit(ENTRY_TXD_REQ_ACK
, &entry
->flags
));
1064 rt2x00_set_field32(&word
, TXD_W0_TIMESTAMP
,
1065 test_bit(ENTRY_TXD_REQ_TIMESTAMP
, &entry
->flags
));
1066 rt2x00_set_field32(&word
, TXD_W0_OFDM
,
1067 test_bit(ENTRY_TXD_OFDM_RATE
, &entry
->flags
));
1068 rt2x00_set_field32(&word
, TXD_W0_NEW_SEQ
,
1069 control
->flags
& IEEE80211_TXCTL_FIRST_FRAGMENT
);
1070 rt2x00_set_field32(&word
, TXD_W0_IFS
, desc
->ifs
);
1071 rt2x00_set_field32(&word
, TXD_W0_DATABYTE_COUNT
, length
);
1072 rt2x00_set_field32(&word
, TXD_W0_CIPHER
, CIPHER_NONE
);
1073 rt2x00_desc_write(txd
, 0, word
);
1077 * TX data initialization
1079 static void rt2500usb_kick_tx_queue(struct rt2x00_dev
*rt2x00dev
, int queue
)
1083 if (queue
!= IEEE80211_TX_QUEUE_BEACON
)
1086 rt2500usb_register_read(rt2x00dev
, TXRX_CSR19
, ®
);
1087 if (!rt2x00_get_field16(reg
, TXRX_CSR19_BEACON_GEN
)) {
1088 rt2x00_set_field16(®
, TXRX_CSR19_BEACON_GEN
, 1);
1090 * Beacon generation will fail initially.
1091 * To prevent this we need to register the TXRX_CSR19
1092 * register several times.
1094 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, reg
);
1095 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, 0);
1096 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, reg
);
1097 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, 0);
1098 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, reg
);
1103 * RX control handlers
1105 static int rt2500usb_fill_rxdone(struct data_entry
*entry
,
1106 int *signal
, int *rssi
, int *ofdm
)
1108 struct urb
*urb
= entry
->priv
;
1109 struct data_desc
*rxd
= (struct data_desc
*)(entry
->skb
->data
+
1110 (urb
->actual_length
- entry
->ring
->desc_size
));
1114 rt2x00_desc_read(rxd
, 0, &word0
);
1115 rt2x00_desc_read(rxd
, 1, &word1
);
1118 * TODO: Don't we need to keep statistics
1119 * updated about these errors?
1121 if (rt2x00_get_field32(word0
, RXD_W0_CRC
) ||
1122 rt2x00_get_field32(word0
, RXD_W0_PHYSICAL_ERROR
))
1126 * Obtain the status about this packet.
1128 *signal
= rt2x00_get_field32(word1
, RXD_W1_SIGNAL
);
1129 *rssi
= rt2x00_get_field32(word1
, RXD_W1_RSSI
) -
1130 entry
->ring
->rt2x00dev
->rssi_offset
;
1131 *ofdm
= rt2x00_get_field32(word0
, RXD_W0_OFDM
);
1134 * rt2570 includes the FCS, so fix data length accordingly.
1136 return rt2x00_get_field32(word0
, RXD_W0_DATABYTE_COUNT
) - FCS_LEN
;
1140 * Device initialization functions.
1142 static int rt2500usb_alloc_eeprom(struct rt2x00_dev
*rt2x00dev
)
1148 * Allocate the eeprom memory, check the eeprom width
1149 * and copy the entire eeprom into this allocated memory.
1151 rt2x00dev
->eeprom
= kzalloc(EEPROM_SIZE
, GFP_KERNEL
);
1152 if (!rt2x00dev
->eeprom
)
1155 rt2x00usb_vendor_request(
1156 rt2x00dev
, USB_EEPROM_READ
, USB_VENDOR_REQUEST_IN
,
1157 EEPROM_BASE
, 0x00, rt2x00dev
->eeprom
, EEPROM_SIZE
,
1158 REGISTER_TIMEOUT
* (EEPROM_SIZE
/ sizeof(u16
)));
1161 * Start validation of the data that has been read.
1163 mac
= rt2x00_eeprom_addr(rt2x00dev
, EEPROM_MAC_ADDR_0
);
1164 if (!is_valid_ether_addr(mac
)) {
1165 random_ether_addr(mac
);
1166 EEPROM(rt2x00dev
, "MAC: " MAC_FMT
"\n", MAC_ARG(mac
));
1169 rt2x00_eeprom_read(rt2x00dev
, EEPROM_ANTENNA
, &word
);
1170 if (word
== 0xffff) {
1171 rt2x00_set_field16(&word
, EEPROM_ANTENNA_NUM
, 2);
1172 rt2x00_set_field16(&word
, EEPROM_ANTENNA_TX_DEFAULT
, 0);
1173 rt2x00_set_field16(&word
, EEPROM_ANTENNA_RX_DEFAULT
, 0);
1174 rt2x00_set_field16(&word
, EEPROM_ANTENNA_LED_MODE
, 0);
1175 rt2x00_set_field16(&word
, EEPROM_ANTENNA_DYN_TXAGC
, 0);
1176 rt2x00_set_field16(&word
, EEPROM_ANTENNA_HARDWARE_RADIO
, 0);
1177 rt2x00_set_field16(&word
, EEPROM_ANTENNA_RF_TYPE
, RF2522
);
1178 rt2x00_eeprom_write(rt2x00dev
, EEPROM_ANTENNA
, word
);
1179 EEPROM(rt2x00dev
, "Antenna: 0x%04x\n", word
);
1182 rt2x00_eeprom_read(rt2x00dev
, EEPROM_NIC
, &word
);
1183 if (word
== 0xffff) {
1184 rt2x00_set_field16(&word
, EEPROM_NIC_CARDBUS_ACCEL
, 0);
1185 rt2x00_set_field16(&word
, EEPROM_NIC_DYN_BBP_TUNE
, 0);
1186 rt2x00_set_field16(&word
, EEPROM_NIC_CCK_TX_POWER
, 0);
1187 rt2x00_eeprom_write(rt2x00dev
, EEPROM_NIC
, word
);
1188 EEPROM(rt2x00dev
, "NIC: 0x%04x\n", word
);
1191 rt2x00_eeprom_read(rt2x00dev
, EEPROM_CALIBRATE_OFFSET
, &word
);
1192 if (word
== 0xffff) {
1193 rt2x00_set_field16(&word
, EEPROM_CALIBRATE_OFFSET_RSSI
,
1194 DEFAULT_RSSI_OFFSET
);
1195 rt2x00_eeprom_write(rt2x00dev
, EEPROM_CALIBRATE_OFFSET
, word
);
1196 EEPROM(rt2x00dev
, "Calibrate offset: 0x%04x\n", word
);
1199 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE
, &word
);
1200 if (word
== 0xffff) {
1201 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_THRESHOLD
, 45);
1202 rt2x00_eeprom_write(rt2x00dev
, EEPROM_BBPTUNE
, word
);
1203 EEPROM(rt2x00dev
, "BBPtune: 0x%04x\n", word
);
1206 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_VGC
, &word
);
1207 if (word
== 0xffff) {
1208 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_VGCUPPER
, 0x40);
1209 rt2x00_eeprom_write(rt2x00dev
, EEPROM_BBPTUNE_VGC
, word
);
1210 EEPROM(rt2x00dev
, "BBPtune vgc: 0x%04x\n", word
);
1213 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R17
, &word
);
1214 if (word
== 0xffff) {
1215 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R17_LOW
, 0x48);
1216 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R17_HIGH
, 0x41);
1217 rt2x00_eeprom_write(rt2x00dev
, EEPROM_BBPTUNE_R17
, word
);
1218 EEPROM(rt2x00dev
, "BBPtune r17: 0x%04x\n", word
);
1221 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R24
, &word
);
1222 if (word
== 0xffff) {
1223 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R24_LOW
, 0x40);
1224 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R24_HIGH
, 0x80);
1225 rt2x00_eeprom_write(rt2x00dev
, EEPROM_BBPTUNE_R24
, word
);
1226 EEPROM(rt2x00dev
, "BBPtune r24: 0x%04x\n", word
);
1229 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R25
, &word
);
1230 if (word
== 0xffff) {
1231 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R25_LOW
, 0x40);
1232 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R25_HIGH
, 0x50);
1233 rt2x00_eeprom_write(rt2x00dev
, EEPROM_BBPTUNE_R25
, word
);
1234 EEPROM(rt2x00dev
, "BBPtune r25: 0x%04x\n", word
);
1237 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R61
, &word
);
1238 if (word
== 0xffff) {
1239 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R61_LOW
, 0x60);
1240 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R61_HIGH
, 0x6d);
1241 rt2x00_eeprom_write(rt2x00dev
, EEPROM_BBPTUNE_R61
, word
);
1242 EEPROM(rt2x00dev
, "BBPtune r61: 0x%04x\n", word
);
1248 static int rt2500usb_init_eeprom(struct rt2x00_dev
*rt2x00dev
)
1255 * Read EEPROM word for configuration.
1257 rt2x00_eeprom_read(rt2x00dev
, EEPROM_ANTENNA
, &eeprom
);
1260 * Identify RF chipset.
1262 value
= rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_RF_TYPE
);
1263 rt2500usb_register_read(rt2x00dev
, MAC_CSR0
, ®
);
1264 rt2x00_set_chip(rt2x00dev
, RT2570
, value
, reg
);
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");
1277 * Identify default antenna configuration.
1279 rt2x00dev
->hw
->conf
.antenna_sel_tx
= rt2x00_get_field16(eeprom
,
1280 EEPROM_ANTENNA_TX_DEFAULT
);
1281 rt2x00dev
->hw
->conf
.antenna_sel_rx
= rt2x00_get_field16(eeprom
,
1282 EEPROM_ANTENNA_RX_DEFAULT
);
1285 * Store led mode, for correct led behaviour.
1287 rt2x00dev
->led_mode
= rt2x00_get_field16(eeprom
,
1288 EEPROM_ANTENNA_LED_MODE
);
1291 * Check if the BBP tuning should be disabled.
1293 rt2x00_eeprom_read(rt2x00dev
, EEPROM_NIC
, &eeprom
);
1294 if (rt2x00_get_field16(eeprom
, EEPROM_NIC_DYN_BBP_TUNE
))
1295 __set_bit(CONFIG_DISABLE_LINK_TUNING
, &rt2x00dev
->flags
);
1298 * Read the RSSI <-> dBm offset information.
1300 rt2x00_eeprom_read(rt2x00dev
, EEPROM_CALIBRATE_OFFSET
, &eeprom
);
1301 rt2x00dev
->rssi_offset
=
1302 rt2x00_get_field16(eeprom
, EEPROM_CALIBRATE_OFFSET_RSSI
);
1307 static const struct {
1311 { RF2522
, { 0x00002050, 0x00000101, 0x00000000 } },
1312 { RF2523
, { 0x00022010, 0x000e0111, 0x00000a1b } },
1313 { RF2524
, { 0x00032020, 0x00000101, 0x00000a1b } },
1314 { RF2525
, { 0x00022020, 0x00060111, 0x00000a1b } },
1315 { RF2525E
, { 0x00022010, 0x00060111, 0x00000000 } },
1316 { RF5222
, { 0x00000000, 0x00000101, 0x00000000 } }
1320 * RF value list for RF2522
1323 static const u32 rf_vals_bg_2522
[] = {
1324 0x000c1fda, 0x000c1fee, 0x000c2002, 0x000c2016, 0x000c202a,
1325 0x000c203e, 0x000c2052, 0x000c2066, 0x000c207a, 0x000c208e,
1326 0x000c20a2, 0x000c20b6, 0x000c20ca, 0x000c20fa
1330 * RF value list for RF2523, RF2524 & RF2525
1333 static const u32 rf_vals_bg_252x
[] = {
1334 0x00000c9e, 0x00000ca2, 0x00000ca6, 0x00000caa, 0x00000cae,
1335 0x00000cb2, 0x00000cb6, 0x00000cba, 0x00000cbe, 0x00000d02,
1336 0x00000d06, 0x00000d0a, 0x00000d0e, 0x00000d1a
1340 * RF value list for RF2525E
1343 static const u32 rf_vals_bg_2525e
[] = {
1344 0x0000089a, 0x0000089e, 0x0000089e, 0x000008a2, 0x000008a2,
1345 0x000008a6, 0x000008a6, 0x000008aa, 0x000008aa, 0x000008ae,
1346 0x000008ae, 0x000008b2, 0x000008b2, 0x000008b6
1350 * RF value list for RF5222
1351 * Supports: 2.4 GHz & 5.2 GHz
1353 static const u32 rf_vals_abg_5222
[] = {
1354 0x00001136, 0x0000113a, 0x0000113e, 0x00001182, 0x00001186,
1355 0x0000118a, 0x0000118e, 0x00001192, 0x00001196, 0x0000119a,
1356 0x0000119e, 0x000011a2, 0x000011a6, 0x000011ae, 0x0001889a,
1357 0x0001889a, 0x0001889e, 0x000188a2, 0x000188a6, 0x000188aa,
1358 0x000188ae, 0x000188b2, 0x00008802, 0x00008806, 0x0000880a,
1359 0x0000880e, 0x00008812, 0x00008816, 0x0000881a, 0x0000881e,
1360 0x00008822, 0x00008826, 0x0000882a, 0x000090a6, 0x000090ae,
1361 0x000090b6, 0x000090be
1364 static void rt2500usb_init_hw_mode(struct rt2x00_dev
*rt2x00dev
)
1366 struct hw_mode_spec
*spec
= &rt2x00dev
->spec
;
1371 * Initialize all hw fields.
1373 rt2x00dev
->hw
->flags
= IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE
|
1374 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING
|
1375 IEEE80211_HW_WEP_INCLUDE_IV
|
1376 IEEE80211_HW_DATA_NULLFUNC_ACK
|
1377 IEEE80211_HW_NO_TKIP_WMM_HWACCEL
|
1378 IEEE80211_HW_MONITOR_DURING_OPER
|
1379 IEEE80211_HW_NO_PROBE_FILTERING
;
1380 rt2x00dev
->hw
->extra_tx_headroom
= TXD_DESC_SIZE
;
1381 rt2x00dev
->hw
->max_rssi
= MAX_RX_SSI
;
1382 rt2x00dev
->hw
->max_noise
= MAX_RX_NOISE
;
1383 rt2x00dev
->hw
->queues
= 2;
1385 SET_IEEE80211_DEV(rt2x00dev
->hw
, &rt2x00dev_usb(rt2x00dev
)->dev
);
1386 SET_IEEE80211_PERM_ADDR(rt2x00dev
->hw
,
1387 rt2x00_eeprom_addr(rt2x00dev
, EEPROM_MAC_ADDR_0
));
1390 * Set device specific, but channel independent RF values.
1392 for (i
= 0; i
< ARRAY_SIZE(rf_vals
); i
++) {
1393 if (rt2x00_rf(&rt2x00dev
->chip
, rf_vals
[i
].chip
)) {
1394 rt2x00dev
->rf1
= rf_vals
[i
].val
[0];
1395 rt2x00dev
->rf3
= rf_vals
[i
].val
[1];
1396 rt2x00dev
->rf4
= rf_vals
[i
].val
[2];
1401 * Convert tx_power array in eeprom.
1403 txpower
= rt2x00_eeprom_addr(rt2x00dev
, EEPROM_TXPOWER_START
);
1404 for (i
= 0; i
< 14; i
++)
1405 txpower
[i
] = TXPOWER_FROM_DEV(txpower
[i
]);
1408 * Initialize hw_mode information.
1410 spec
->num_modes
= 2;
1411 spec
->num_rates
= 12;
1412 spec
->num_channels
= 14;
1413 spec
->tx_power_a
= NULL
;
1414 spec
->tx_power_bg
= txpower
;
1415 spec
->tx_power_default
= DEFAULT_TXPOWER
;
1416 spec
->chan_val_a
= NULL
;
1418 if (rt2x00_rf(&rt2x00dev
->chip
, RF2522
))
1419 spec
->chan_val_bg
= rf_vals_bg_2522
;
1420 else if (rt2x00_rf(&rt2x00dev
->chip
, RF2523
) ||
1421 rt2x00_rf(&rt2x00dev
->chip
, RF2524
) ||
1422 rt2x00_rf(&rt2x00dev
->chip
, RF2525
))
1423 spec
->chan_val_bg
= rf_vals_bg_252x
;
1424 else if (rt2x00_rf(&rt2x00dev
->chip
, RF2525E
))
1425 spec
->chan_val_bg
= rf_vals_bg_2525e
;
1426 else if (rt2x00_rf(&rt2x00dev
->chip
, RF5222
))
1427 spec
->chan_val_bg
= rf_vals_abg_5222
;
1429 if (rt2x00_rf(&rt2x00dev
->chip
, RF5222
)) {
1430 spec
->num_modes
= 3;
1431 spec
->num_channels
+= 23;
1432 spec
->chan_val_a
= &rf_vals_abg_5222
[14];
1436 static int rt2500usb_init_hw(struct rt2x00_dev
*rt2x00dev
)
1441 * Allocate eeprom data.
1443 retval
= rt2500usb_alloc_eeprom(rt2x00dev
);
1447 retval
= rt2500usb_init_eeprom(rt2x00dev
);
1452 * Initialize hw specifications.
1454 rt2500usb_init_hw_mode(rt2x00dev
);
1457 * This device supports ATIM
1459 __set_bit(DEVICE_SUPPORT_ATIM
, &rt2x00dev
->flags
);
1465 * IEEE80211 stack callback functions.
1467 static int rt2500usb_get_stats(struct ieee80211_hw
*hw
,
1468 struct ieee80211_low_level_stats
*stats
)
1470 struct rt2x00_dev
*rt2x00dev
= hw
->priv
;
1474 * Update FCS error count from register.
1475 * The dot11ACKFailureCount, dot11RTSFailureCount and
1476 * dot11RTSSuccessCount are updated in interrupt time.
1478 rt2500usb_register_read(rt2x00dev
, STA_CSR0
, ®
);
1479 rt2x00dev
->low_level_stats
.dot11FCSErrorCount
+=
1480 rt2x00_get_field16(reg
, STA_CSR0_FCS_ERROR
);
1482 memcpy(stats
, &rt2x00dev
->low_level_stats
, sizeof(*stats
));
1487 static const struct ieee80211_ops rt2500usb_mac80211_ops
= {
1489 .reset
= rt2x00lib_reset
,
1490 .add_interface
= rt2x00lib_add_interface
,
1491 .remove_interface
= rt2x00lib_remove_interface
,
1492 .config
= rt2x00lib_config
,
1493 .config_interface
= rt2x00lib_config_interface
,
1494 .set_multicast_list
= rt2x00lib_set_multicast_list
,
1495 .get_stats
= rt2500usb_get_stats
,
1496 .conf_tx
= rt2x00lib_conf_tx
,
1497 .get_tx_stats
= rt2x00lib_get_tx_stats
,
1498 .beacon_update
= rt2x00usb_beacon_update
,
1501 static const struct rt2x00lib_ops rt2500usb_rt2x00_ops
= {
1502 .init_hw
= rt2500usb_init_hw
,
1503 .initialize
= rt2x00usb_initialize
,
1504 .uninitialize
= rt2x00usb_uninitialize
,
1505 .set_device_state
= rt2500usb_set_device_state
,
1506 .link_tuner
= rt2500usb_link_tuner
,
1507 .write_tx_desc
= rt2500usb_write_tx_desc
,
1508 .write_tx_data
= rt2x00usb_write_tx_data
,
1509 .kick_tx_queue
= rt2500usb_kick_tx_queue
,
1510 .fill_rxdone
= rt2500usb_fill_rxdone
,
1511 .config_type
= rt2500usb_config_type
,
1512 .config_phymode
= rt2500usb_config_phymode
,
1513 .config_channel
= rt2500usb_config_channel
,
1514 .config_mac_addr
= rt2500usb_config_mac_addr
,
1515 .config_bssid
= rt2500usb_config_bssid
,
1516 .config_promisc
= rt2500usb_config_promisc
,
1517 .config_txpower
= rt2500usb_config_txpower
,
1518 .config_antenna
= rt2500usb_config_antenna
,
1519 .config_duration
= rt2500usb_config_duration
,
1522 static const struct rt2x00_ops rt2500usb_ops
= {
1524 .rxd_size
= RXD_DESC_SIZE
,
1525 .txd_size
= TXD_DESC_SIZE
,
1526 .lib
= &rt2500usb_rt2x00_ops
,
1527 .hw
= &rt2500usb_mac80211_ops
,
1528 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
1529 .debugfs
= &rt2500usb_rt2x00debug
,
1530 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
1534 * rt2500usb module information.
1536 static struct usb_device_id rt2500usb_device_table
[] = {
1538 { USB_DEVICE(0x0b05, 0x1706), USB_DEVICE_DATA(&rt2500usb_ops
) },
1539 { USB_DEVICE(0x0b05, 0x1707), USB_DEVICE_DATA(&rt2500usb_ops
) },
1541 { USB_DEVICE(0x050d, 0x7050), USB_DEVICE_DATA(&rt2500usb_ops
) },
1542 { USB_DEVICE(0x050d, 0x7051), USB_DEVICE_DATA(&rt2500usb_ops
) },
1543 { USB_DEVICE(0x050d, 0x705a), USB_DEVICE_DATA(&rt2500usb_ops
) },
1545 { USB_DEVICE(0x13b1, 0x000d), USB_DEVICE_DATA(&rt2500usb_ops
) },
1546 { USB_DEVICE(0x13b1, 0x0011), USB_DEVICE_DATA(&rt2500usb_ops
) },
1547 { USB_DEVICE(0x13b1, 0x001a), USB_DEVICE_DATA(&rt2500usb_ops
) },
1549 { USB_DEVICE(0x14b2, 0x3c02), USB_DEVICE_DATA(&rt2500usb_ops
) },
1551 { USB_DEVICE(0x2001, 0x3c00), USB_DEVICE_DATA(&rt2500usb_ops
) },
1553 { USB_DEVICE(0x1044, 0x8001), USB_DEVICE_DATA(&rt2500usb_ops
) },
1554 { USB_DEVICE(0x1044, 0x8007), USB_DEVICE_DATA(&rt2500usb_ops
) },
1556 { USB_DEVICE(0x06f8, 0xe000), USB_DEVICE_DATA(&rt2500usb_ops
) },
1558 { USB_DEVICE(0x0411, 0x0066), USB_DEVICE_DATA(&rt2500usb_ops
) },
1559 { USB_DEVICE(0x0411, 0x0067), USB_DEVICE_DATA(&rt2500usb_ops
) },
1560 { USB_DEVICE(0x0411, 0x008b), USB_DEVICE_DATA(&rt2500usb_ops
) },
1562 { USB_DEVICE(0x0db0, 0x6861), USB_DEVICE_DATA(&rt2500usb_ops
) },
1563 { USB_DEVICE(0x0db0, 0x6865), USB_DEVICE_DATA(&rt2500usb_ops
) },
1564 { USB_DEVICE(0x0db0, 0x6869), USB_DEVICE_DATA(&rt2500usb_ops
) },
1566 { USB_DEVICE(0x148f, 0x1706), USB_DEVICE_DATA(&rt2500usb_ops
) },
1567 { USB_DEVICE(0x148f, 0x2570), USB_DEVICE_DATA(&rt2500usb_ops
) },
1568 { USB_DEVICE(0x148f, 0x2573), USB_DEVICE_DATA(&rt2500usb_ops
) },
1569 { USB_DEVICE(0x148f, 0x9020), USB_DEVICE_DATA(&rt2500usb_ops
) },
1571 { USB_DEVICE(0x0681, 0x3c06), USB_DEVICE_DATA(&rt2500usb_ops
) },
1573 { USB_DEVICE(0x0707, 0xee13), USB_DEVICE_DATA(&rt2500usb_ops
) },
1575 { USB_DEVICE(0x114b, 0x0110), USB_DEVICE_DATA(&rt2500usb_ops
) },
1577 { USB_DEVICE(0x0eb0, 0x9020), USB_DEVICE_DATA(&rt2500usb_ops
) },
1579 { USB_DEVICE(0x5a57, 0x0260), USB_DEVICE_DATA(&rt2500usb_ops
) },
1583 MODULE_AUTHOR(DRV_PROJECT
);
1584 MODULE_VERSION(DRV_VERSION
);
1585 MODULE_DESCRIPTION("Ralink RT2500 USB Wireless LAN driver.");
1586 MODULE_SUPPORTED_DEVICE("Ralink RT2570 USB chipset based cards");
1587 MODULE_DEVICE_TABLE(usb
, rt2500usb_device_table
);
1588 MODULE_LICENSE("GPL");
1590 static struct usb_driver rt2500usb_driver
= {
1592 .id_table
= rt2500usb_device_table
,
1593 .probe
= rt2x00usb_probe
,
1594 .disconnect
= rt2x00usb_disconnect
,
1596 .suspend
= rt2x00usb_suspend
,
1597 .resume
= rt2x00usb_resume
,
1598 #endif /* CONFIG_PM */
1601 static int __init
rt2500usb_init(void)
1603 return usb_register(&rt2500usb_driver
);
1606 static void __exit
rt2500usb_exit(void)
1608 usb_deregister(&rt2500usb_driver
);
1611 module_init(rt2500usb_init
);
1612 module_exit(rt2500usb_exit
);