madwifi: fix the long standing bug that is triggered by nodes getting a timeout on...
[openwrt/svn-archive/archive.git] / package / mac80211 / patches / 327-rt2x00-Add-support-for-rt3070-rt2800usb.patch
1 From 84706fce3026650c49c6290e0e6525b45795027c Mon Sep 17 00:00:00 2001
2 From: Ivo van Doorn <IvDoorn@gmail.com>
3 Date: Thu, 22 Jan 2009 21:16:46 +0100
4 Subject: [PATCH] rt2x00: Add support for rt3070 (rt2800usb)
5
6 Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com>
7 ---
8 drivers/net/wireless/rt2x00/rt2800usb.c | 384 +++++++++++++++++++++++++++----
9 drivers/net/wireless/rt2x00/rt2800usb.h | 57 +++++-
10 drivers/net/wireless/rt2x00/rt2x00.h | 6 +
11 3 files changed, 404 insertions(+), 43 deletions(-)
12
13 --- a/drivers/net/wireless/rt2x00/rt2800usb.c
14 +++ b/drivers/net/wireless/rt2x00/rt2800usb.c
15 @@ -59,6 +59,8 @@ MODULE_PARM_DESC(nohwcrypt, "Disable har
16 */
17 #define WAIT_FOR_BBP(__dev, __reg) \
18 rt2x00usb_regbusy_read((__dev), BBP_CSR_CFG, BBP_CSR_CFG_BUSY, (__reg))
19 +#define WAIT_FOR_RFCSR(__dev, __reg) \
20 + rt2x00usb_regbusy_read((__dev), RF_CSR_CFG, RF_CSR_CFG_BUSY, (__reg))
21 #define WAIT_FOR_RF(__dev, __reg) \
22 rt2x00usb_regbusy_read((__dev), RF_CSR_CFG0, RF_CSR_CFG0_BUSY, (__reg))
23 #define WAIT_FOR_MCU(__dev, __reg) \
24 @@ -120,6 +122,61 @@ static void rt2800usb_bbp_read(struct rt
25 mutex_unlock(&rt2x00dev->csr_mutex);
26 }
27
28 +static void rt2800usb_rfcsr_write(struct rt2x00_dev *rt2x00dev,
29 + const unsigned int word, const u8 value)
30 +{
31 + u32 reg;
32 +
33 + mutex_lock(&rt2x00dev->csr_mutex);
34 +
35 + /*
36 + * Wait until the RFCSR becomes available, afterwards we
37 + * can safely write the new data into the register.
38 + */
39 + if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
40 + reg = 0;
41 + rt2x00_set_field32(&reg, RF_CSR_CFG_DATA, value);
42 + rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
43 + rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 1);
44 + rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
45 +
46 + rt2x00usb_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
47 + }
48 +
49 + mutex_unlock(&rt2x00dev->csr_mutex);
50 +}
51 +
52 +static void rt2800usb_rfcsr_read(struct rt2x00_dev *rt2x00dev,
53 + const unsigned int word, u8 *value)
54 +{
55 + u32 reg;
56 +
57 + mutex_lock(&rt2x00dev->csr_mutex);
58 +
59 + /*
60 + * Wait until the RFCSR becomes available, afterwards we
61 + * can safely write the read request into the register.
62 + * After the data has been written, we wait until hardware
63 + * returns the correct value, if at any time the register
64 + * doesn't become available in time, reg will be 0xffffffff
65 + * which means we return 0xff to the caller.
66 + */
67 + if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
68 + reg = 0;
69 + rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
70 + rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 0);
71 + rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
72 +
73 + rt2x00usb_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
74 +
75 + WAIT_FOR_RFCSR(rt2x00dev, &reg);
76 + }
77 +
78 + *value = rt2x00_get_field32(reg, RF_CSR_CFG_DATA);
79 +
80 + mutex_unlock(&rt2x00dev->csr_mutex);
81 +}
82 +
83 static void rt2800usb_rf_write(struct rt2x00_dev *rt2x00dev,
84 const unsigned int word, const u32 value)
85 {
86 @@ -635,42 +692,24 @@ static void rt2800usb_config_lna_gain(st
87 rt2x00dev->lna_gain = lna_gain;
88 }
89
90 -static void rt2800usb_config_channel(struct rt2x00_dev *rt2x00dev,
91 - struct rf_channel *rf,
92 - struct channel_info *info)
93 +static void rt2800usb_config_channel_rt2x(struct rt2x00_dev *rt2x00dev,
94 + struct rf_channel *rf,
95 + struct channel_info *info)
96 {
97 - u32 reg;
98 - unsigned int tx_pin;
99 u16 eeprom;
100
101 - tx_pin = 0;
102 - rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1);
103 - rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN, 1);
104 - rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN, 1);
105 - rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1);
106 - rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1);
107 - rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1);
108 - rt2x00_set_field32(&tx_pin, TX_PIN_CFG_TRSW_EN, 1);
109 -
110 rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
111
112 /*
113 * Determine antenna settings from EEPROM
114 */
115 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
116 - if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH) == 1) {
117 + if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH) == 1)
118 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_TX1, 1);
119 - /* Turn off unused PA or LNA when only 1T or 1R */
120 - rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 0);
121 - rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 0);
122 - }
123
124 if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH) == 1) {
125 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX1, 1);
126 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
127 - /* Turn off unused PA or LNA when only 1T or 1R */
128 - rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 0);
129 - rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 0);
130 } else if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH) == 2)
131 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
132
133 @@ -698,15 +737,11 @@ static void rt2800usb_config_channel(str
134
135 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A,
136 TXPOWER_A_TO_DEV(info->tx_power2));
137 -
138 - rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, 1);
139 } else {
140 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_G,
141 TXPOWER_G_TO_DEV(info->tx_power1));
142 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_G,
143 TXPOWER_G_TO_DEV(info->tx_power2));
144 -
145 - rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, 1);
146 }
147
148 rt2x00_set_field32(&rf->rf4, RF4_BW40,
149 @@ -730,6 +765,81 @@ static void rt2800usb_config_channel(str
150 rt2800usb_rf_write(rt2x00dev, 2, rf->rf2);
151 rt2800usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
152 rt2800usb_rf_write(rt2x00dev, 4, rf->rf4);
153 +}
154 +
155 +static void rt2800usb_config_channel_rt3x(struct rt2x00_dev *rt2x00dev,
156 + struct rf_channel *rf,
157 + struct channel_info *info)
158 +{
159 + u8 rfcsr;
160 +
161 + rt2800usb_rfcsr_write(rt2x00dev, 2, rf->rf1);
162 + rt2800usb_rfcsr_write(rt2x00dev, 2, rf->rf3);
163 +
164 + rt2800usb_rfcsr_read(rt2x00dev, 6, &rfcsr);
165 + rt2x00_set_field8(&rfcsr, RFCSR6_R, rf->rf2);
166 + rt2800usb_rfcsr_write(rt2x00dev, 6, rfcsr);
167 +
168 + rt2800usb_rfcsr_read(rt2x00dev, 12, &rfcsr);
169 + rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER,
170 + TXPOWER_G_TO_DEV(info->tx_power1));
171 + rt2800usb_rfcsr_write(rt2x00dev, 12, rfcsr);
172 +
173 + rt2800usb_rfcsr_read(rt2x00dev, 23, &rfcsr);
174 + rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset);
175 + rt2800usb_rfcsr_write(rt2x00dev, 23, rfcsr);
176 +
177 + if (test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
178 + rt2800usb_rfcsr_write(rt2x00dev, 24, rt2x00dev->calibration_bw40);
179 + else
180 + rt2800usb_rfcsr_write(rt2x00dev, 24, rt2x00dev->calibration_bw20);
181 +
182 + rt2800usb_rfcsr_read(rt2x00dev, 23, &rfcsr);
183 + rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
184 + rt2800usb_rfcsr_write(rt2x00dev, 23, rfcsr);
185 +}
186 +
187 +static void rt2800usb_config_channel(struct rt2x00_dev *rt2x00dev,
188 + struct rf_channel *rf,
189 + struct channel_info *info)
190 +{
191 + u32 reg;
192 + unsigned int tx_pin;
193 + u16 eeprom;
194 +
195 + if (rt2x00_rev(&rt2x00dev->chip) != RT3070_VERSION)
196 + rt2800usb_config_channel_rt2x(rt2x00dev, rf, info);
197 + else
198 + rt2800usb_config_channel_rt3x(rt2x00dev, rf, info);
199 +
200 + tx_pin = 0;
201 + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1);
202 + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN, 1);
203 + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN, 1);
204 + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1);
205 + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1);
206 + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1);
207 + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_TRSW_EN, 1);
208 +
209 + rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
210 +
211 + /* Turn off unused PA or LNA when only 1T or 1R */
212 + if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH) == 1) {
213 +
214 + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 0);
215 + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 0);
216 + }
217 +
218 + /* Turn off unused PA or LNA when only 1T or 1R */
219 + if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH) == 1) {
220 + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 0);
221 + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 0);
222 + }
223 +
224 + if (rf->channel > 14)
225 + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, 1);
226 + else
227 + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, 1);
228
229 /*
230 * Change BBP settings
231 @@ -935,8 +1045,12 @@ static void rt2800usb_link_stats(struct
232
233 static u8 rt2800usb_get_default_vgc(struct rt2x00_dev *rt2x00dev)
234 {
235 - if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ)
236 - return 0x2e + rt2x00dev->lna_gain;
237 + if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) {
238 + if (rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION)
239 + return 0x1c + (2 * rt2x00dev->lna_gain);
240 + else
241 + return 0x2e + rt2x00dev->lna_gain;
242 + }
243
244 if (!test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
245 return 0x32 + (rt2x00dev->lna_gain * 5) / 3;
246 @@ -964,7 +1078,7 @@ static void rt2800usb_reset_tuner(struct
247 static void rt2800usb_link_tuner(struct rt2x00_dev *rt2x00dev,
248 struct link_qual *qual, const u32 count)
249 {
250 - if (rt2x00_rev(&rt2x00dev->chip) == RT2870_VERSION_C)
251 + if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION)
252 return;
253
254 /*
255 @@ -1145,8 +1259,14 @@ static int rt2800usb_init_registers(stru
256 rt2x00_set_field32(&reg, BCN_TIME_CFG_TX_TIME_COMPENSATE, 0);
257 rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg);
258
259 - rt2x00usb_register_write(rt2x00dev, TX_SW_CFG0, 0x00040a06);
260 - rt2x00usb_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
261 + if (rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION) {
262 + rt2x00usb_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
263 + rt2x00usb_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
264 + rt2x00usb_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
265 + } else {
266 + rt2x00usb_register_write(rt2x00dev, TX_SW_CFG0, 0x00040a06);
267 + rt2x00usb_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
268 + }
269
270 rt2x00usb_register_read(rt2x00dev, TX_LINK_CFG, &reg);
271 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB_LIFETIME, 32);
272 @@ -1166,7 +1286,11 @@ static int rt2800usb_init_registers(stru
273
274 rt2x00usb_register_read(rt2x00dev, MAX_LEN_CFG, &reg);
275 rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_MPDU, AGGREGATION_SIZE);
276 - rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 1);
277 + if (rt2x00_rev(&rt2x00dev->chip) >= RT2880E_VERSION &&
278 + rt2x00_rev(&rt2x00dev->chip) < RT3070_VERSION)
279 + rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 2);
280 + else
281 + rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 1);
282 rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_PSDU, 0);
283 rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_MPDU, 0);
284 rt2x00usb_register_write(rt2x00dev, MAX_LEN_CFG, reg);
285 @@ -1427,13 +1551,16 @@ static int rt2800usb_init_bbp(struct rt2
286 rt2800usb_bbp_write(rt2x00dev, 103, 0x00);
287 rt2800usb_bbp_write(rt2x00dev, 105, 0x05);
288
289 - if (rt2x00_rev(&rt2x00dev->chip) == RT2870_VERSION_C) {
290 + if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION) {
291 rt2800usb_bbp_write(rt2x00dev, 69, 0x16);
292 rt2800usb_bbp_write(rt2x00dev, 73, 0x12);
293 }
294
295 - if (rt2x00_rev(&rt2x00dev->chip) != RT2870_VERSION_D)
296 - rt2800usb_bbp_write(rt2x00dev, 84, 0x19);
297 + if (rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION) {
298 + rt2800usb_bbp_write(rt2x00dev, 70, 0x0a);
299 + rt2800usb_bbp_write(rt2x00dev, 84, 0x99);
300 + rt2800usb_bbp_write(rt2x00dev, 105, 0x05);
301 + }
302
303 for (i = 0; i < EEPROM_BBP_SIZE; i++) {
304 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
305 @@ -1448,6 +1575,134 @@ static int rt2800usb_init_bbp(struct rt2
306 return 0;
307 }
308
309 +static u8 rt2800usb_init_rx_filter(struct rt2x00_dev *rt2x00dev,
310 + bool bw40, u8 rfcsr24, u8 filter_target)
311 +{
312 + unsigned int i;
313 + u8 bbp;
314 + u8 rfcsr;
315 + u8 passband;
316 + u8 stopband;
317 + u8 overtuned = 0;
318 +
319 + rt2800usb_rfcsr_write(rt2x00dev, 24, rfcsr24);
320 +
321 + if (bw40) {
322 + rt2800usb_bbp_read(rt2x00dev, 4, &bbp);
323 + rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0x10);
324 + rt2800usb_bbp_write(rt2x00dev, 4, bbp);
325 + }
326 +
327 + rt2800usb_rfcsr_read(rt2x00dev, 22, &rfcsr);
328 + rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 1);
329 + rt2800usb_rfcsr_write(rt2x00dev, 22, rfcsr);
330 +
331 + /*
332 + * Set power & frequency of passband test tone
333 + */
334 + rt2800usb_bbp_write(rt2x00dev, 24, 0);
335 +
336 + for (i = 0; i < 100; i++) {
337 + rt2800usb_bbp_write(rt2x00dev, 25, 0x90);
338 + msleep(1);
339 +
340 + rt2800usb_bbp_read(rt2x00dev, 55, &passband);
341 + if (passband)
342 + break;
343 + }
344 +
345 + /*
346 + * Set power & frequency of stopband test tone
347 + */
348 + rt2800usb_bbp_write(rt2x00dev, 24, 0x06);
349 +
350 + for (i = 0; i < 100; i++) {
351 + rt2800usb_bbp_write(rt2x00dev, 25, 0x90);
352 + msleep(1);
353 +
354 + rt2800usb_bbp_read(rt2x00dev, 55, &stopband);
355 +
356 + if ((passband - stopband) <= filter_target) {
357 + rfcsr24++;
358 + overtuned += ((passband - stopband) == filter_target);
359 + } else
360 + break;
361 +
362 + rt2800usb_rfcsr_write(rt2x00dev, 24, rfcsr24);
363 + }
364 +
365 + rfcsr24 -= !!overtuned;
366 +
367 + rt2800usb_rfcsr_write(rt2x00dev, 24, rfcsr24);
368 + return rfcsr24;
369 +}
370 +
371 +static int rt2800usb_init_rfcsr(struct rt2x00_dev *rt2x00dev)
372 +{
373 + u8 rfcsr;
374 + u8 bbp;
375 +
376 + if (rt2x00_rev(&rt2x00dev->chip) != RT3070_VERSION)
377 + return 0;
378 +
379 + /*
380 + * Init RF calibration.
381 + */
382 + rt2800usb_rfcsr_read(rt2x00dev, 30, &rfcsr);
383 + rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1);
384 + rt2800usb_rfcsr_write(rt2x00dev, 30, rfcsr);
385 + msleep(1);
386 + rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0);
387 + rt2800usb_rfcsr_write(rt2x00dev, 30, rfcsr);
388 +
389 + rt2800usb_rfcsr_write(rt2x00dev, 4, 0x40);
390 + rt2800usb_rfcsr_write(rt2x00dev, 5, 0x03);
391 + rt2800usb_rfcsr_write(rt2x00dev, 6, 0x02);
392 + rt2800usb_rfcsr_write(rt2x00dev, 7, 0x70);
393 + rt2800usb_rfcsr_write(rt2x00dev, 9, 0x0f);
394 + rt2800usb_rfcsr_write(rt2x00dev, 10, 0x71);
395 + rt2800usb_rfcsr_write(rt2x00dev, 11, 0x21);
396 + rt2800usb_rfcsr_write(rt2x00dev, 12, 0x7b);
397 + rt2800usb_rfcsr_write(rt2x00dev, 14, 0x90);
398 + rt2800usb_rfcsr_write(rt2x00dev, 15, 0x58);
399 + rt2800usb_rfcsr_write(rt2x00dev, 16, 0xb3);
400 + rt2800usb_rfcsr_write(rt2x00dev, 17, 0x92);
401 + rt2800usb_rfcsr_write(rt2x00dev, 18, 0x2c);
402 + rt2800usb_rfcsr_write(rt2x00dev, 19, 0x02);
403 + rt2800usb_rfcsr_write(rt2x00dev, 20, 0xba);
404 + rt2800usb_rfcsr_write(rt2x00dev, 21, 0xdb);
405 + rt2800usb_rfcsr_write(rt2x00dev, 24, 0x16);
406 + rt2800usb_rfcsr_write(rt2x00dev, 25, 0x01);
407 + rt2800usb_rfcsr_write(rt2x00dev, 27, 0x03);
408 + rt2800usb_rfcsr_write(rt2x00dev, 29, 0x1f);
409 +
410 + /*
411 + * Set RX Filter calibration for 20MHz and 40MHz
412 + */
413 + rt2x00dev->calibration_bw20 =
414 + rt2800usb_init_rx_filter(rt2x00dev, false, 0x07, 0x16);
415 + rt2x00dev->calibration_bw40 =
416 + rt2800usb_init_rx_filter(rt2x00dev, true, 0x27, 0x19);
417 +
418 + /*
419 + * Set back to initial state
420 + */
421 + rt2800usb_bbp_write(rt2x00dev, 24, 0);
422 +
423 + rt2800usb_rfcsr_read(rt2x00dev, 22, &rfcsr);
424 + rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 0);
425 + rt2800usb_rfcsr_write(rt2x00dev, 22, rfcsr);
426 +
427 + /*
428 + * set BBP back to BW20
429 + */
430 + rt2800usb_bbp_read(rt2x00dev, 4, &bbp);
431 + rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0);
432 + rt2800usb_bbp_write(rt2x00dev, 4, bbp);
433 +
434 + return 0;
435 +}
436 +
437 /*
438 * Device state switch handlers.
439 */
440 @@ -1491,7 +1746,8 @@ static int rt2800usb_enable_radio(struct
441 */
442 if (unlikely(rt2800usb_wait_wpdma_ready(rt2x00dev) ||
443 rt2800usb_init_registers(rt2x00dev) ||
444 - rt2800usb_init_bbp(rt2x00dev)))
445 + rt2800usb_init_bbp(rt2x00dev) ||
446 + rt2800usb_init_rfcsr(rt2x00dev)))
447 return -EIO;
448
449 rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
450 @@ -1982,7 +2238,6 @@ static int rt2800usb_validate_eeprom(str
451 static int rt2800usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
452 {
453 u32 reg;
454 - u16 rev;
455 u16 value;
456 u16 eeprom;
457
458 @@ -1996,8 +2251,7 @@ static int rt2800usb_init_eeprom(struct
459 */
460 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
461 rt2x00usb_register_read(rt2x00dev, MAC_CSR0, &reg);
462 - rev = rt2x00_get_field32(reg, MAC_CSR0_ASIC_REV);
463 - rt2x00_set_chip(rt2x00dev, RT2870, value, rev);
464 + rt2x00_set_chip(rt2x00dev, RT2870, value, reg);
465
466 /*
467 * The check for rt2860 is not a typo, some rt2870 hardware
468 @@ -2012,7 +2266,9 @@ static int rt2800usb_init_eeprom(struct
469 if (!rt2x00_rf(&rt2x00dev->chip, RF2820) &&
470 !rt2x00_rf(&rt2x00dev->chip, RF2850) &&
471 !rt2x00_rf(&rt2x00dev->chip, RF2720) &&
472 - !rt2x00_rf(&rt2x00dev->chip, RF2750)) {
473 + !rt2x00_rf(&rt2x00dev->chip, RF2750) &&
474 + !rt2x00_rf(&rt2x00dev->chip, RF3020) &&
475 + !rt2x00_rf(&rt2x00dev->chip, RF2020)) {
476 ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
477 return -ENODEV;
478 }
479 @@ -2127,6 +2383,27 @@ static const struct rf_channel rf_vals[]
480 { 216, 0x15002ccc, 0x15004982, 0x1509be55, 0x150c0a23 },
481 };
482
483 +/*
484 + * RF value list for rt3070
485 + * Supports: 2.4 GHz
486 + */
487 +static const struct rf_channel rf_vals_3070[] = {
488 + {1, 241, 2, 2 },
489 + {2, 241, 2, 7 },
490 + {3, 242, 2, 2 },
491 + {4, 242, 2, 7 },
492 + {5, 243, 2, 2 },
493 + {6, 243, 2, 7 },
494 + {7, 244, 2, 2 },
495 + {8, 244, 2, 7 },
496 + {9, 245, 2, 2 },
497 + {10, 245, 2, 7 },
498 + {11, 246, 2, 2 },
499 + {12, 246, 2, 7 },
500 + {13, 247, 2, 2 },
501 + {14, 248, 2, 4 },
502 +};
503 +
504 static int rt2800usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
505 {
506 struct hw_mode_spec *spec = &rt2x00dev->spec;
507 @@ -2184,6 +2461,10 @@ static int rt2800usb_probe_hw_mode(struc
508 spec->supported_bands |= SUPPORT_BAND_5GHZ;
509 spec->num_channels = ARRAY_SIZE(rf_vals);
510 spec->channels = rf_vals;
511 + } else if (rt2x00_rf(&rt2x00dev->chip, RF3020) ||
512 + rt2x00_rf(&rt2x00dev->chip, RF2020)) {
513 + spec->num_channels = ARRAY_SIZE(rf_vals_3070);
514 + spec->channels = rf_vals_3070;
515 }
516
517 /*
518 @@ -2473,6 +2754,12 @@ static const struct rt2x00_ops rt2800usb
519 * rt2800usb module information.
520 */
521 static struct usb_device_id rt2800usb_device_table[] = {
522 + /* Abocom */
523 + { USB_DEVICE(0x07b8, 0x3070), USB_DEVICE_DATA(&rt2800usb_ops) },
524 + { USB_DEVICE(0x07b8, 0x3071), USB_DEVICE_DATA(&rt2800usb_ops) },
525 + { USB_DEVICE(0x07b8, 0x2870), USB_DEVICE_DATA(&rt2800usb_ops) },
526 + { USB_DEVICE(0x07b8, 0x2770), USB_DEVICE_DATA(&rt2800usb_ops) },
527 + { USB_DEVICE(0x1482, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
528 /* Amit */
529 { USB_DEVICE(0x15c5, 0x0008), USB_DEVICE_DATA(&rt2800usb_ops) },
530 /* ASUS */
531 @@ -2483,9 +2770,12 @@ static struct usb_device_id rt2800usb_de
532 { USB_DEVICE(0x13d3, 0x3247), USB_DEVICE_DATA(&rt2800usb_ops) },
533 /* Belkin */
534 { USB_DEVICE(0x050d, 0x8053), USB_DEVICE_DATA(&rt2800usb_ops) },
535 + { USB_DEVICE(0x050d, 0x805c), USB_DEVICE_DATA(&rt2800usb_ops) },
536 /* Conceptronic */
537 { USB_DEVICE(0x14b2, 0x3c06), USB_DEVICE_DATA(&rt2800usb_ops) },
538 { USB_DEVICE(0x14b2, 0x3c07), USB_DEVICE_DATA(&rt2800usb_ops) },
539 + { USB_DEVICE(0x14b2, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
540 + { USB_DEVICE(0x14b2, 0x3c12), USB_DEVICE_DATA(&rt2800usb_ops) },
541 { USB_DEVICE(0x14b2, 0x3c23), USB_DEVICE_DATA(&rt2800usb_ops) },
542 { USB_DEVICE(0x14b2, 0x3c25), USB_DEVICE_DATA(&rt2800usb_ops) },
543 { USB_DEVICE(0x14b2, 0x3c27), USB_DEVICE_DATA(&rt2800usb_ops) },
544 @@ -2494,9 +2784,12 @@ static struct usb_device_id rt2800usb_de
545 { USB_DEVICE(0x07aa, 0x002f), USB_DEVICE_DATA(&rt2800usb_ops) },
546 { USB_DEVICE(0x07aa, 0x003c), USB_DEVICE_DATA(&rt2800usb_ops) },
547 { USB_DEVICE(0x07aa, 0x003f), USB_DEVICE_DATA(&rt2800usb_ops) },
548 + { USB_DEVICE(0x18c5, 0x0012), USB_DEVICE_DATA(&rt2800usb_ops) },
549 /* D-Link */
550 { USB_DEVICE(0x07d1, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
551 { USB_DEVICE(0x07d1, 0x3c11), USB_DEVICE_DATA(&rt2800usb_ops) },
552 + /* Edimax */
553 + { USB_DEVICE(0x7392, 0x7711), USB_DEVICE_DATA(&rt2800usb_ops) },
554 /* EnGenius */
555 { USB_DEVICE(0X1740, 0x9701), USB_DEVICE_DATA(&rt2800usb_ops) },
556 { USB_DEVICE(0x1740, 0x9702), USB_DEVICE_DATA(&rt2800usb_ops) },
557 @@ -2507,13 +2800,21 @@ static struct usb_device_id rt2800usb_de
558 { USB_DEVICE(0x0e66, 0x0003), USB_DEVICE_DATA(&rt2800usb_ops) },
559 /* Linksys */
560 { USB_DEVICE(0x1737, 0x0071), USB_DEVICE_DATA(&rt2800usb_ops) },
561 + /* Logitec */
562 + { USB_DEVICE(0x0789, 0x0162), USB_DEVICE_DATA(&rt2800usb_ops) },
563 + { USB_DEVICE(0x0789, 0x0163), USB_DEVICE_DATA(&rt2800usb_ops) },
564 + { USB_DEVICE(0x0789, 0x0164), USB_DEVICE_DATA(&rt2800usb_ops) },
565 /* Philips */
566 { USB_DEVICE(0x0471, 0x200f), USB_DEVICE_DATA(&rt2800usb_ops) },
567 /* Planex */
568 { USB_DEVICE(0x2019, 0xed06), USB_DEVICE_DATA(&rt2800usb_ops) },
569 + { USB_DEVICE(0x2019, 0xab25), USB_DEVICE_DATA(&rt2800usb_ops) },
570 /* Ralink */
571 { USB_DEVICE(0x148f, 0x2770), USB_DEVICE_DATA(&rt2800usb_ops) },
572 { USB_DEVICE(0x148f, 0x2870), USB_DEVICE_DATA(&rt2800usb_ops) },
573 + { USB_DEVICE(0x148f, 0x3070), USB_DEVICE_DATA(&rt2800usb_ops) },
574 + /* Samsung */
575 + { USB_DEVICE(0x04e8, 0x2018), USB_DEVICE_DATA(&rt2800usb_ops) },
576 /* Siemens */
577 { USB_DEVICE(0x129b, 0x1828), USB_DEVICE_DATA(&rt2800usb_ops) },
578 /* Sitecom */
579 @@ -2533,6 +2834,9 @@ static struct usb_device_id rt2800usb_de
580 /* ZCOM */
581 { USB_DEVICE(0x0cde, 0x0022), USB_DEVICE_DATA(&rt2800usb_ops) },
582 { USB_DEVICE(0x0cde, 0x0025), USB_DEVICE_DATA(&rt2800usb_ops) },
583 + /* Zinwell */
584 + { USB_DEVICE(0x5a57, 0x0280), USB_DEVICE_DATA(&rt2800usb_ops) },
585 + { USB_DEVICE(0x5a57, 0x0282), USB_DEVICE_DATA(&rt2800usb_ops) },
586 /* Zyxel */
587 { USB_DEVICE(0x0586, 0x3416), USB_DEVICE_DATA(&rt2800usb_ops) },
588 { 0, }
589 --- a/drivers/net/wireless/rt2x00/rt2800usb.h
590 +++ b/drivers/net/wireless/rt2x00/rt2800usb.h
591 @@ -47,9 +47,11 @@
592 /*
593 * RT2870 version
594 */
595 -#define RT2870_VERSION_C 0x0100
596 -#define RT2870_VERSION_D 0x0101
597 -#define RT2870_VERSION_E 0x0200
598 +#define RT2860C_VERSION 0x28600100
599 +#define RT2860D_VERSION 0x28600101
600 +#define RT2880E_VERSION 0x28720200
601 +#define RT2883_VERSION 0x28830300
602 +#define RT3070_VERSION 0x30700200
603
604 /*
605 * Signal information.
606 @@ -383,6 +385,15 @@
607 #define PBF_DBG 0x043c
608
609 /*
610 + * RF registers
611 + */
612 +#define RF_CSR_CFG 0x0500
613 +#define RF_CSR_CFG_DATA FIELD32(0x000000ff)
614 +#define RF_CSR_CFG_REGNUM FIELD32(0x00001f00)
615 +#define RF_CSR_CFG_WRITE FIELD32(0x00010000)
616 +#define RF_CSR_CFG_BUSY FIELD32(0x00020000)
617 +
618 +/*
619 * MAC Control/Status Registers(CSR).
620 * Some values are set in TU, whereas 1 TU == 1024 us.
621 */
622 @@ -1482,6 +1493,46 @@ struct hw_key_entry {
623 #define BBP3_RX_ANTENNA FIELD8(0x18)
624
625 /*
626 + * BBP 4: Bandwidth
627 + */
628 +#define BBP4_BANDWIDTH FIELD8(0x18)
629 +
630 +/*
631 + * RFCSR registers
632 + * The wordsize of the RFCSR is 8 bits.
633 + */
634 +
635 +/*
636 + * RFCSR 6:
637 + */
638 +#define RFCSR6_R FIELD8(0x03)
639 +
640 +/*
641 + * RFCSR 7:
642 + */
643 +#define RFCSR7_RF_TUNING FIELD8(0x01)
644 +
645 +/*
646 + * RFCSR 12:
647 + */
648 +#define RFCSR12_TX_POWER FIELD8(0x1f)
649 +
650 +/*
651 + * RFCSR 22:
652 + */
653 +#define RFCSR22_BASEBAND_LOOPBACK FIELD8(0x01)
654 +
655 +/*
656 + * RFCSR 23:
657 + */
658 +#define RFCSR23_FREQ_OFFSET FIELD8(0x7f)
659 +
660 +/*
661 + * RFCSR 30:
662 + */
663 +#define RFCSR30_RF_CALIBRATION FIELD8(0x80)
664 +
665 +/*
666 * RF registers
667 */
668
669 --- a/drivers/net/wireless/rt2x00/rt2x00.h
670 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
671 @@ -780,6 +780,12 @@ struct rt2x00_dev {
672 u8 freq_offset;
673
674 /*
675 + * Calibration information (for rt2800usb).
676 + */
677 + u8 calibration_bw20;
678 + u8 calibration_bw40;
679 +
680 + /*
681 * Low level statistics which will have
682 * to be kept up to date while device is running.
683 */