dt-bindings: mtd: ingenic: Use standard ecc-engine property
[linux/fpc-iii.git] / drivers / net / wireless / ralink / rt2x00 / rt2800lib.c
bloba03b5284a050952448f806d3e74cc164bea5a4a1
1 /*
2 Copyright (C) 2010 Willow Garage <http://www.willowgarage.com>
3 Copyright (C) 2010 Ivo van Doorn <IvDoorn@gmail.com>
4 Copyright (C) 2009 Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
5 Copyright (C) 2009 Gertjan van Wingerde <gwingerde@gmail.com>
7 Based on the original rt2800pci.c and rt2800usb.c.
8 Copyright (C) 2009 Alban Browaeys <prahal@yahoo.com>
9 Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org>
10 Copyright (C) 2009 Luis Correia <luis.f.correia@gmail.com>
11 Copyright (C) 2009 Mattias Nissler <mattias.nissler@gmx.de>
12 Copyright (C) 2009 Mark Asselstine <asselsm@gmail.com>
13 Copyright (C) 2009 Xose Vazquez Perez <xose.vazquez@gmail.com>
14 <http://rt2x00.serialmonkey.com>
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, see <http://www.gnu.org/licenses/>.
31 Module: rt2800lib
32 Abstract: rt2800 generic device routines.
35 #include <linux/crc-ccitt.h>
36 #include <linux/kernel.h>
37 #include <linux/module.h>
38 #include <linux/slab.h>
40 #include "rt2x00.h"
41 #include "rt2800lib.h"
42 #include "rt2800.h"
45 * Register access.
46 * All access to the CSR registers will go through the methods
47 * rt2800_register_read and rt2800_register_write.
48 * BBP and RF register require indirect register access,
49 * and use the CSR registers BBPCSR and RFCSR to achieve this.
50 * These indirect registers work with busy bits,
51 * and we will try maximal REGISTER_BUSY_COUNT times to access
52 * the register while taking a REGISTER_BUSY_DELAY us delay
53 * between each attampt. When the busy bit is still set at that time,
54 * the access attempt is considered to have failed,
55 * and we will print an error.
56 * The _lock versions must be used if you already hold the csr_mutex
58 #define WAIT_FOR_BBP(__dev, __reg) \
59 rt2800_regbusy_read((__dev), BBP_CSR_CFG, BBP_CSR_CFG_BUSY, (__reg))
60 #define WAIT_FOR_RFCSR(__dev, __reg) \
61 rt2800_regbusy_read((__dev), RF_CSR_CFG, RF_CSR_CFG_BUSY, (__reg))
62 #define WAIT_FOR_RFCSR_MT7620(__dev, __reg) \
63 rt2800_regbusy_read((__dev), RF_CSR_CFG, RF_CSR_CFG_BUSY_MT7620, \
64 (__reg))
65 #define WAIT_FOR_RF(__dev, __reg) \
66 rt2800_regbusy_read((__dev), RF_CSR_CFG0, RF_CSR_CFG0_BUSY, (__reg))
67 #define WAIT_FOR_MCU(__dev, __reg) \
68 rt2800_regbusy_read((__dev), H2M_MAILBOX_CSR, \
69 H2M_MAILBOX_CSR_OWNER, (__reg))
71 static inline bool rt2800_is_305x_soc(struct rt2x00_dev *rt2x00dev)
73 /* check for rt2872 on SoC */
74 if (!rt2x00_is_soc(rt2x00dev) ||
75 !rt2x00_rt(rt2x00dev, RT2872))
76 return false;
78 /* we know for sure that these rf chipsets are used on rt305x boards */
79 if (rt2x00_rf(rt2x00dev, RF3020) ||
80 rt2x00_rf(rt2x00dev, RF3021) ||
81 rt2x00_rf(rt2x00dev, RF3022))
82 return true;
84 rt2x00_warn(rt2x00dev, "Unknown RF chipset on rt305x\n");
85 return false;
88 static void rt2800_bbp_write(struct rt2x00_dev *rt2x00dev,
89 const unsigned int word, const u8 value)
91 u32 reg;
93 mutex_lock(&rt2x00dev->csr_mutex);
96 * Wait until the BBP becomes available, afterwards we
97 * can safely write the new data into the register.
99 if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
100 reg = 0;
101 rt2x00_set_field32(&reg, BBP_CSR_CFG_VALUE, value);
102 rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
103 rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
104 rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 0);
105 rt2x00_set_field32(&reg, BBP_CSR_CFG_BBP_RW_MODE, 1);
107 rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
110 mutex_unlock(&rt2x00dev->csr_mutex);
113 static u8 rt2800_bbp_read(struct rt2x00_dev *rt2x00dev, const unsigned int word)
115 u32 reg;
116 u8 value;
118 mutex_lock(&rt2x00dev->csr_mutex);
121 * Wait until the BBP becomes available, afterwards we
122 * can safely write the read request into the register.
123 * After the data has been written, we wait until hardware
124 * returns the correct value, if at any time the register
125 * doesn't become available in time, reg will be 0xffffffff
126 * which means we return 0xff to the caller.
128 if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
129 reg = 0;
130 rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
131 rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
132 rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 1);
133 rt2x00_set_field32(&reg, BBP_CSR_CFG_BBP_RW_MODE, 1);
135 rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
137 WAIT_FOR_BBP(rt2x00dev, &reg);
140 value = rt2x00_get_field32(reg, BBP_CSR_CFG_VALUE);
142 mutex_unlock(&rt2x00dev->csr_mutex);
144 return value;
147 static void rt2800_rfcsr_write(struct rt2x00_dev *rt2x00dev,
148 const unsigned int word, const u8 value)
150 u32 reg;
152 mutex_lock(&rt2x00dev->csr_mutex);
155 * Wait until the RFCSR becomes available, afterwards we
156 * can safely write the new data into the register.
158 switch (rt2x00dev->chip.rt) {
159 case RT6352:
160 if (WAIT_FOR_RFCSR_MT7620(rt2x00dev, &reg)) {
161 reg = 0;
162 rt2x00_set_field32(&reg, RF_CSR_CFG_DATA_MT7620, value);
163 rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM_MT7620,
164 word);
165 rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE_MT7620, 1);
166 rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY_MT7620, 1);
168 rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
170 break;
172 default:
173 if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
174 reg = 0;
175 rt2x00_set_field32(&reg, RF_CSR_CFG_DATA, value);
176 rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
177 rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 1);
178 rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
180 rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
182 break;
185 mutex_unlock(&rt2x00dev->csr_mutex);
188 static void rt2800_rfcsr_write_bank(struct rt2x00_dev *rt2x00dev, const u8 bank,
189 const unsigned int reg, const u8 value)
191 rt2800_rfcsr_write(rt2x00dev, (reg | (bank << 6)), value);
194 static void rt2800_rfcsr_write_chanreg(struct rt2x00_dev *rt2x00dev,
195 const unsigned int reg, const u8 value)
197 rt2800_rfcsr_write_bank(rt2x00dev, 4, reg, value);
198 rt2800_rfcsr_write_bank(rt2x00dev, 6, reg, value);
201 static void rt2800_rfcsr_write_dccal(struct rt2x00_dev *rt2x00dev,
202 const unsigned int reg, const u8 value)
204 rt2800_rfcsr_write_bank(rt2x00dev, 5, reg, value);
205 rt2800_rfcsr_write_bank(rt2x00dev, 7, reg, value);
208 static u8 rt2800_rfcsr_read(struct rt2x00_dev *rt2x00dev,
209 const unsigned int word)
211 u32 reg;
212 u8 value;
214 mutex_lock(&rt2x00dev->csr_mutex);
217 * Wait until the RFCSR becomes available, afterwards we
218 * can safely write the read request into the register.
219 * After the data has been written, we wait until hardware
220 * returns the correct value, if at any time the register
221 * doesn't become available in time, reg will be 0xffffffff
222 * which means we return 0xff to the caller.
224 switch (rt2x00dev->chip.rt) {
225 case RT6352:
226 if (WAIT_FOR_RFCSR_MT7620(rt2x00dev, &reg)) {
227 reg = 0;
228 rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM_MT7620,
229 word);
230 rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE_MT7620, 0);
231 rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY_MT7620, 1);
233 rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
235 WAIT_FOR_RFCSR_MT7620(rt2x00dev, &reg);
238 value = rt2x00_get_field32(reg, RF_CSR_CFG_DATA_MT7620);
239 break;
241 default:
242 if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
243 reg = 0;
244 rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
245 rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 0);
246 rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
248 rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
250 WAIT_FOR_RFCSR(rt2x00dev, &reg);
253 value = rt2x00_get_field32(reg, RF_CSR_CFG_DATA);
254 break;
257 mutex_unlock(&rt2x00dev->csr_mutex);
259 return value;
262 static u8 rt2800_rfcsr_read_bank(struct rt2x00_dev *rt2x00dev, const u8 bank,
263 const unsigned int reg)
265 return rt2800_rfcsr_read(rt2x00dev, (reg | (bank << 6)));
268 static void rt2800_rf_write(struct rt2x00_dev *rt2x00dev,
269 const unsigned int word, const u32 value)
271 u32 reg;
273 mutex_lock(&rt2x00dev->csr_mutex);
276 * Wait until the RF becomes available, afterwards we
277 * can safely write the new data into the register.
279 if (WAIT_FOR_RF(rt2x00dev, &reg)) {
280 reg = 0;
281 rt2x00_set_field32(&reg, RF_CSR_CFG0_REG_VALUE_BW, value);
282 rt2x00_set_field32(&reg, RF_CSR_CFG0_STANDBYMODE, 0);
283 rt2x00_set_field32(&reg, RF_CSR_CFG0_SEL, 0);
284 rt2x00_set_field32(&reg, RF_CSR_CFG0_BUSY, 1);
286 rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG0, reg);
287 rt2x00_rf_write(rt2x00dev, word, value);
290 mutex_unlock(&rt2x00dev->csr_mutex);
293 static const unsigned int rt2800_eeprom_map[EEPROM_WORD_COUNT] = {
294 [EEPROM_CHIP_ID] = 0x0000,
295 [EEPROM_VERSION] = 0x0001,
296 [EEPROM_MAC_ADDR_0] = 0x0002,
297 [EEPROM_MAC_ADDR_1] = 0x0003,
298 [EEPROM_MAC_ADDR_2] = 0x0004,
299 [EEPROM_NIC_CONF0] = 0x001a,
300 [EEPROM_NIC_CONF1] = 0x001b,
301 [EEPROM_FREQ] = 0x001d,
302 [EEPROM_LED_AG_CONF] = 0x001e,
303 [EEPROM_LED_ACT_CONF] = 0x001f,
304 [EEPROM_LED_POLARITY] = 0x0020,
305 [EEPROM_NIC_CONF2] = 0x0021,
306 [EEPROM_LNA] = 0x0022,
307 [EEPROM_RSSI_BG] = 0x0023,
308 [EEPROM_RSSI_BG2] = 0x0024,
309 [EEPROM_TXMIXER_GAIN_BG] = 0x0024, /* overlaps with RSSI_BG2 */
310 [EEPROM_RSSI_A] = 0x0025,
311 [EEPROM_RSSI_A2] = 0x0026,
312 [EEPROM_TXMIXER_GAIN_A] = 0x0026, /* overlaps with RSSI_A2 */
313 [EEPROM_EIRP_MAX_TX_POWER] = 0x0027,
314 [EEPROM_TXPOWER_DELTA] = 0x0028,
315 [EEPROM_TXPOWER_BG1] = 0x0029,
316 [EEPROM_TXPOWER_BG2] = 0x0030,
317 [EEPROM_TSSI_BOUND_BG1] = 0x0037,
318 [EEPROM_TSSI_BOUND_BG2] = 0x0038,
319 [EEPROM_TSSI_BOUND_BG3] = 0x0039,
320 [EEPROM_TSSI_BOUND_BG4] = 0x003a,
321 [EEPROM_TSSI_BOUND_BG5] = 0x003b,
322 [EEPROM_TXPOWER_A1] = 0x003c,
323 [EEPROM_TXPOWER_A2] = 0x0053,
324 [EEPROM_TXPOWER_INIT] = 0x0068,
325 [EEPROM_TSSI_BOUND_A1] = 0x006a,
326 [EEPROM_TSSI_BOUND_A2] = 0x006b,
327 [EEPROM_TSSI_BOUND_A3] = 0x006c,
328 [EEPROM_TSSI_BOUND_A4] = 0x006d,
329 [EEPROM_TSSI_BOUND_A5] = 0x006e,
330 [EEPROM_TXPOWER_BYRATE] = 0x006f,
331 [EEPROM_BBP_START] = 0x0078,
334 static const unsigned int rt2800_eeprom_map_ext[EEPROM_WORD_COUNT] = {
335 [EEPROM_CHIP_ID] = 0x0000,
336 [EEPROM_VERSION] = 0x0001,
337 [EEPROM_MAC_ADDR_0] = 0x0002,
338 [EEPROM_MAC_ADDR_1] = 0x0003,
339 [EEPROM_MAC_ADDR_2] = 0x0004,
340 [EEPROM_NIC_CONF0] = 0x001a,
341 [EEPROM_NIC_CONF1] = 0x001b,
342 [EEPROM_NIC_CONF2] = 0x001c,
343 [EEPROM_EIRP_MAX_TX_POWER] = 0x0020,
344 [EEPROM_FREQ] = 0x0022,
345 [EEPROM_LED_AG_CONF] = 0x0023,
346 [EEPROM_LED_ACT_CONF] = 0x0024,
347 [EEPROM_LED_POLARITY] = 0x0025,
348 [EEPROM_LNA] = 0x0026,
349 [EEPROM_EXT_LNA2] = 0x0027,
350 [EEPROM_RSSI_BG] = 0x0028,
351 [EEPROM_RSSI_BG2] = 0x0029,
352 [EEPROM_RSSI_A] = 0x002a,
353 [EEPROM_RSSI_A2] = 0x002b,
354 [EEPROM_TXPOWER_BG1] = 0x0030,
355 [EEPROM_TXPOWER_BG2] = 0x0037,
356 [EEPROM_EXT_TXPOWER_BG3] = 0x003e,
357 [EEPROM_TSSI_BOUND_BG1] = 0x0045,
358 [EEPROM_TSSI_BOUND_BG2] = 0x0046,
359 [EEPROM_TSSI_BOUND_BG3] = 0x0047,
360 [EEPROM_TSSI_BOUND_BG4] = 0x0048,
361 [EEPROM_TSSI_BOUND_BG5] = 0x0049,
362 [EEPROM_TXPOWER_A1] = 0x004b,
363 [EEPROM_TXPOWER_A2] = 0x0065,
364 [EEPROM_EXT_TXPOWER_A3] = 0x007f,
365 [EEPROM_TSSI_BOUND_A1] = 0x009a,
366 [EEPROM_TSSI_BOUND_A2] = 0x009b,
367 [EEPROM_TSSI_BOUND_A3] = 0x009c,
368 [EEPROM_TSSI_BOUND_A4] = 0x009d,
369 [EEPROM_TSSI_BOUND_A5] = 0x009e,
370 [EEPROM_TXPOWER_BYRATE] = 0x00a0,
373 static unsigned int rt2800_eeprom_word_index(struct rt2x00_dev *rt2x00dev,
374 const enum rt2800_eeprom_word word)
376 const unsigned int *map;
377 unsigned int index;
379 if (WARN_ONCE(word >= EEPROM_WORD_COUNT,
380 "%s: invalid EEPROM word %d\n",
381 wiphy_name(rt2x00dev->hw->wiphy), word))
382 return 0;
384 if (rt2x00_rt(rt2x00dev, RT3593))
385 map = rt2800_eeprom_map_ext;
386 else
387 map = rt2800_eeprom_map;
389 index = map[word];
391 /* Index 0 is valid only for EEPROM_CHIP_ID.
392 * Otherwise it means that the offset of the
393 * given word is not initialized in the map,
394 * or that the field is not usable on the
395 * actual chipset.
397 WARN_ONCE(word != EEPROM_CHIP_ID && index == 0,
398 "%s: invalid access of EEPROM word %d\n",
399 wiphy_name(rt2x00dev->hw->wiphy), word);
401 return index;
404 static void *rt2800_eeprom_addr(struct rt2x00_dev *rt2x00dev,
405 const enum rt2800_eeprom_word word)
407 unsigned int index;
409 index = rt2800_eeprom_word_index(rt2x00dev, word);
410 return rt2x00_eeprom_addr(rt2x00dev, index);
413 static u16 rt2800_eeprom_read(struct rt2x00_dev *rt2x00dev,
414 const enum rt2800_eeprom_word word)
416 unsigned int index;
418 index = rt2800_eeprom_word_index(rt2x00dev, word);
419 return rt2x00_eeprom_read(rt2x00dev, index);
422 static void rt2800_eeprom_write(struct rt2x00_dev *rt2x00dev,
423 const enum rt2800_eeprom_word word, u16 data)
425 unsigned int index;
427 index = rt2800_eeprom_word_index(rt2x00dev, word);
428 rt2x00_eeprom_write(rt2x00dev, index, data);
431 static u16 rt2800_eeprom_read_from_array(struct rt2x00_dev *rt2x00dev,
432 const enum rt2800_eeprom_word array,
433 unsigned int offset)
435 unsigned int index;
437 index = rt2800_eeprom_word_index(rt2x00dev, array);
438 return rt2x00_eeprom_read(rt2x00dev, index + offset);
441 static int rt2800_enable_wlan_rt3290(struct rt2x00_dev *rt2x00dev)
443 u32 reg;
444 int i, count;
446 reg = rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL);
447 rt2x00_set_field32(&reg, WLAN_GPIO_OUT_OE_BIT_ALL, 0xff);
448 rt2x00_set_field32(&reg, FRC_WL_ANT_SET, 1);
449 rt2x00_set_field32(&reg, WLAN_CLK_EN, 0);
450 rt2x00_set_field32(&reg, WLAN_EN, 1);
451 rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg);
453 udelay(REGISTER_BUSY_DELAY);
455 count = 0;
456 do {
458 * Check PLL_LD & XTAL_RDY.
460 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
461 reg = rt2800_register_read(rt2x00dev, CMB_CTRL);
462 if (rt2x00_get_field32(reg, PLL_LD) &&
463 rt2x00_get_field32(reg, XTAL_RDY))
464 break;
465 udelay(REGISTER_BUSY_DELAY);
468 if (i >= REGISTER_BUSY_COUNT) {
470 if (count >= 10)
471 return -EIO;
473 rt2800_register_write(rt2x00dev, 0x58, 0x018);
474 udelay(REGISTER_BUSY_DELAY);
475 rt2800_register_write(rt2x00dev, 0x58, 0x418);
476 udelay(REGISTER_BUSY_DELAY);
477 rt2800_register_write(rt2x00dev, 0x58, 0x618);
478 udelay(REGISTER_BUSY_DELAY);
479 count++;
480 } else {
481 count = 0;
484 reg = rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL);
485 rt2x00_set_field32(&reg, PCIE_APP0_CLK_REQ, 0);
486 rt2x00_set_field32(&reg, WLAN_CLK_EN, 1);
487 rt2x00_set_field32(&reg, WLAN_RESET, 1);
488 rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg);
489 udelay(10);
490 rt2x00_set_field32(&reg, WLAN_RESET, 0);
491 rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg);
492 udelay(10);
493 rt2800_register_write(rt2x00dev, INT_SOURCE_CSR, 0x7fffffff);
494 } while (count != 0);
496 return 0;
499 void rt2800_mcu_request(struct rt2x00_dev *rt2x00dev,
500 const u8 command, const u8 token,
501 const u8 arg0, const u8 arg1)
503 u32 reg;
506 * SOC devices don't support MCU requests.
508 if (rt2x00_is_soc(rt2x00dev))
509 return;
511 mutex_lock(&rt2x00dev->csr_mutex);
514 * Wait until the MCU becomes available, afterwards we
515 * can safely write the new data into the register.
517 if (WAIT_FOR_MCU(rt2x00dev, &reg)) {
518 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_OWNER, 1);
519 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_CMD_TOKEN, token);
520 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG0, arg0);
521 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG1, arg1);
522 rt2800_register_write_lock(rt2x00dev, H2M_MAILBOX_CSR, reg);
524 reg = 0;
525 rt2x00_set_field32(&reg, HOST_CMD_CSR_HOST_COMMAND, command);
526 rt2800_register_write_lock(rt2x00dev, HOST_CMD_CSR, reg);
529 mutex_unlock(&rt2x00dev->csr_mutex);
531 EXPORT_SYMBOL_GPL(rt2800_mcu_request);
533 int rt2800_wait_csr_ready(struct rt2x00_dev *rt2x00dev)
535 unsigned int i = 0;
536 u32 reg;
538 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
539 reg = rt2800_register_read(rt2x00dev, MAC_CSR0);
540 if (reg && reg != ~0)
541 return 0;
542 msleep(1);
545 rt2x00_err(rt2x00dev, "Unstable hardware\n");
546 return -EBUSY;
548 EXPORT_SYMBOL_GPL(rt2800_wait_csr_ready);
550 int rt2800_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev)
552 unsigned int i;
553 u32 reg;
556 * Some devices are really slow to respond here. Wait a whole second
557 * before timing out.
559 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
560 reg = rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG);
561 if (!rt2x00_get_field32(reg, WPDMA_GLO_CFG_TX_DMA_BUSY) &&
562 !rt2x00_get_field32(reg, WPDMA_GLO_CFG_RX_DMA_BUSY))
563 return 0;
565 msleep(10);
568 rt2x00_err(rt2x00dev, "WPDMA TX/RX busy [0x%08x]\n", reg);
569 return -EACCES;
571 EXPORT_SYMBOL_GPL(rt2800_wait_wpdma_ready);
573 void rt2800_disable_wpdma(struct rt2x00_dev *rt2x00dev)
575 u32 reg;
577 reg = rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG);
578 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
579 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
580 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
581 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
582 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
583 rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
585 EXPORT_SYMBOL_GPL(rt2800_disable_wpdma);
587 void rt2800_get_txwi_rxwi_size(struct rt2x00_dev *rt2x00dev,
588 unsigned short *txwi_size,
589 unsigned short *rxwi_size)
591 switch (rt2x00dev->chip.rt) {
592 case RT3593:
593 *txwi_size = TXWI_DESC_SIZE_4WORDS;
594 *rxwi_size = RXWI_DESC_SIZE_5WORDS;
595 break;
597 case RT5592:
598 case RT6352:
599 *txwi_size = TXWI_DESC_SIZE_5WORDS;
600 *rxwi_size = RXWI_DESC_SIZE_6WORDS;
601 break;
603 default:
604 *txwi_size = TXWI_DESC_SIZE_4WORDS;
605 *rxwi_size = RXWI_DESC_SIZE_4WORDS;
606 break;
609 EXPORT_SYMBOL_GPL(rt2800_get_txwi_rxwi_size);
611 static bool rt2800_check_firmware_crc(const u8 *data, const size_t len)
613 u16 fw_crc;
614 u16 crc;
617 * The last 2 bytes in the firmware array are the crc checksum itself,
618 * this means that we should never pass those 2 bytes to the crc
619 * algorithm.
621 fw_crc = (data[len - 2] << 8 | data[len - 1]);
624 * Use the crc ccitt algorithm.
625 * This will return the same value as the legacy driver which
626 * used bit ordering reversion on the both the firmware bytes
627 * before input input as well as on the final output.
628 * Obviously using crc ccitt directly is much more efficient.
630 crc = crc_ccitt(~0, data, len - 2);
633 * There is a small difference between the crc-itu-t + bitrev and
634 * the crc-ccitt crc calculation. In the latter method the 2 bytes
635 * will be swapped, use swab16 to convert the crc to the correct
636 * value.
638 crc = swab16(crc);
640 return fw_crc == crc;
643 int rt2800_check_firmware(struct rt2x00_dev *rt2x00dev,
644 const u8 *data, const size_t len)
646 size_t offset = 0;
647 size_t fw_len;
648 bool multiple;
651 * PCI(e) & SOC devices require firmware with a length
652 * of 8kb. USB devices require firmware files with a length
653 * of 4kb. Certain USB chipsets however require different firmware,
654 * which Ralink only provides attached to the original firmware
655 * file. Thus for USB devices, firmware files have a length
656 * which is a multiple of 4kb. The firmware for rt3290 chip also
657 * have a length which is a multiple of 4kb.
659 if (rt2x00_is_usb(rt2x00dev) || rt2x00_rt(rt2x00dev, RT3290))
660 fw_len = 4096;
661 else
662 fw_len = 8192;
664 multiple = true;
666 * Validate the firmware length
668 if (len != fw_len && (!multiple || (len % fw_len) != 0))
669 return FW_BAD_LENGTH;
672 * Check if the chipset requires one of the upper parts
673 * of the firmware.
675 if (rt2x00_is_usb(rt2x00dev) &&
676 !rt2x00_rt(rt2x00dev, RT2860) &&
677 !rt2x00_rt(rt2x00dev, RT2872) &&
678 !rt2x00_rt(rt2x00dev, RT3070) &&
679 ((len / fw_len) == 1))
680 return FW_BAD_VERSION;
683 * 8kb firmware files must be checked as if it were
684 * 2 separate firmware files.
686 while (offset < len) {
687 if (!rt2800_check_firmware_crc(data + offset, fw_len))
688 return FW_BAD_CRC;
690 offset += fw_len;
693 return FW_OK;
695 EXPORT_SYMBOL_GPL(rt2800_check_firmware);
697 int rt2800_load_firmware(struct rt2x00_dev *rt2x00dev,
698 const u8 *data, const size_t len)
700 unsigned int i;
701 u32 reg;
702 int retval;
704 if (rt2x00_rt(rt2x00dev, RT3290)) {
705 retval = rt2800_enable_wlan_rt3290(rt2x00dev);
706 if (retval)
707 return -EBUSY;
711 * If driver doesn't wake up firmware here,
712 * rt2800_load_firmware will hang forever when interface is up again.
714 rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0x00000000);
717 * Wait for stable hardware.
719 if (rt2800_wait_csr_ready(rt2x00dev))
720 return -EBUSY;
722 if (rt2x00_is_pci(rt2x00dev)) {
723 if (rt2x00_rt(rt2x00dev, RT3290) ||
724 rt2x00_rt(rt2x00dev, RT3572) ||
725 rt2x00_rt(rt2x00dev, RT5390) ||
726 rt2x00_rt(rt2x00dev, RT5392)) {
727 reg = rt2800_register_read(rt2x00dev, AUX_CTRL);
728 rt2x00_set_field32(&reg, AUX_CTRL_FORCE_PCIE_CLK, 1);
729 rt2x00_set_field32(&reg, AUX_CTRL_WAKE_PCIE_EN, 1);
730 rt2800_register_write(rt2x00dev, AUX_CTRL, reg);
732 rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000002);
735 rt2800_disable_wpdma(rt2x00dev);
738 * Write firmware to the device.
740 rt2800_drv_write_firmware(rt2x00dev, data, len);
743 * Wait for device to stabilize.
745 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
746 reg = rt2800_register_read(rt2x00dev, PBF_SYS_CTRL);
747 if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY))
748 break;
749 msleep(1);
752 if (i == REGISTER_BUSY_COUNT) {
753 rt2x00_err(rt2x00dev, "PBF system register not ready\n");
754 return -EBUSY;
758 * Disable DMA, will be reenabled later when enabling
759 * the radio.
761 rt2800_disable_wpdma(rt2x00dev);
764 * Initialize firmware.
766 rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
767 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
768 if (rt2x00_is_usb(rt2x00dev)) {
769 rt2800_register_write(rt2x00dev, H2M_INT_SRC, 0);
770 rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0, 0, 0);
772 msleep(1);
774 return 0;
776 EXPORT_SYMBOL_GPL(rt2800_load_firmware);
778 void rt2800_write_tx_data(struct queue_entry *entry,
779 struct txentry_desc *txdesc)
781 __le32 *txwi = rt2800_drv_get_txwi(entry);
782 u32 word;
783 int i;
786 * Initialize TX Info descriptor
788 word = rt2x00_desc_read(txwi, 0);
789 rt2x00_set_field32(&word, TXWI_W0_FRAG,
790 test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
791 rt2x00_set_field32(&word, TXWI_W0_MIMO_PS,
792 test_bit(ENTRY_TXD_HT_MIMO_PS, &txdesc->flags));
793 rt2x00_set_field32(&word, TXWI_W0_CF_ACK, 0);
794 rt2x00_set_field32(&word, TXWI_W0_TS,
795 test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
796 rt2x00_set_field32(&word, TXWI_W0_AMPDU,
797 test_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags));
798 rt2x00_set_field32(&word, TXWI_W0_MPDU_DENSITY,
799 txdesc->u.ht.mpdu_density);
800 rt2x00_set_field32(&word, TXWI_W0_TX_OP, txdesc->u.ht.txop);
801 rt2x00_set_field32(&word, TXWI_W0_MCS, txdesc->u.ht.mcs);
802 rt2x00_set_field32(&word, TXWI_W0_BW,
803 test_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags));
804 rt2x00_set_field32(&word, TXWI_W0_SHORT_GI,
805 test_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags));
806 rt2x00_set_field32(&word, TXWI_W0_STBC, txdesc->u.ht.stbc);
807 rt2x00_set_field32(&word, TXWI_W0_PHYMODE, txdesc->rate_mode);
808 rt2x00_desc_write(txwi, 0, word);
810 word = rt2x00_desc_read(txwi, 1);
811 rt2x00_set_field32(&word, TXWI_W1_ACK,
812 test_bit(ENTRY_TXD_ACK, &txdesc->flags));
813 rt2x00_set_field32(&word, TXWI_W1_NSEQ,
814 test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags));
815 rt2x00_set_field32(&word, TXWI_W1_BW_WIN_SIZE, txdesc->u.ht.ba_size);
816 rt2x00_set_field32(&word, TXWI_W1_WIRELESS_CLI_ID,
817 test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags) ?
818 txdesc->key_idx : txdesc->u.ht.wcid);
819 rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT,
820 txdesc->length);
821 rt2x00_set_field32(&word, TXWI_W1_PACKETID_QUEUE, entry->queue->qid);
822 rt2x00_set_field32(&word, TXWI_W1_PACKETID_ENTRY, (entry->entry_idx % 3) + 1);
823 rt2x00_desc_write(txwi, 1, word);
826 * Always write 0 to IV/EIV fields (word 2 and 3), hardware will insert
827 * the IV from the IVEIV register when TXD_W3_WIV is set to 0.
828 * When TXD_W3_WIV is set to 1 it will use the IV data
829 * from the descriptor. The TXWI_W1_WIRELESS_CLI_ID indicates which
830 * crypto entry in the registers should be used to encrypt the frame.
832 * Nulify all remaining words as well, we don't know how to program them.
834 for (i = 2; i < entry->queue->winfo_size / sizeof(__le32); i++)
835 _rt2x00_desc_write(txwi, i, 0);
837 EXPORT_SYMBOL_GPL(rt2800_write_tx_data);
839 static int rt2800_agc_to_rssi(struct rt2x00_dev *rt2x00dev, u32 rxwi_w2)
841 s8 rssi0 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI0);
842 s8 rssi1 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI1);
843 s8 rssi2 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI2);
844 u16 eeprom;
845 u8 offset0;
846 u8 offset1;
847 u8 offset2;
849 if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
850 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG);
851 offset0 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG_OFFSET0);
852 offset1 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG_OFFSET1);
853 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2);
854 offset2 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG2_OFFSET2);
855 } else {
856 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A);
857 offset0 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A_OFFSET0);
858 offset1 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A_OFFSET1);
859 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A2);
860 offset2 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A2_OFFSET2);
864 * Convert the value from the descriptor into the RSSI value
865 * If the value in the descriptor is 0, it is considered invalid
866 * and the default (extremely low) rssi value is assumed
868 rssi0 = (rssi0) ? (-12 - offset0 - rt2x00dev->lna_gain - rssi0) : -128;
869 rssi1 = (rssi1) ? (-12 - offset1 - rt2x00dev->lna_gain - rssi1) : -128;
870 rssi2 = (rssi2) ? (-12 - offset2 - rt2x00dev->lna_gain - rssi2) : -128;
873 * mac80211 only accepts a single RSSI value. Calculating the
874 * average doesn't deliver a fair answer either since -60:-60 would
875 * be considered equally good as -50:-70 while the second is the one
876 * which gives less energy...
878 rssi0 = max(rssi0, rssi1);
879 return (int)max(rssi0, rssi2);
882 void rt2800_process_rxwi(struct queue_entry *entry,
883 struct rxdone_entry_desc *rxdesc)
885 __le32 *rxwi = (__le32 *) entry->skb->data;
886 u32 word;
888 word = rt2x00_desc_read(rxwi, 0);
890 rxdesc->cipher = rt2x00_get_field32(word, RXWI_W0_UDF);
891 rxdesc->size = rt2x00_get_field32(word, RXWI_W0_MPDU_TOTAL_BYTE_COUNT);
893 word = rt2x00_desc_read(rxwi, 1);
895 if (rt2x00_get_field32(word, RXWI_W1_SHORT_GI))
896 rxdesc->enc_flags |= RX_ENC_FLAG_SHORT_GI;
898 if (rt2x00_get_field32(word, RXWI_W1_BW))
899 rxdesc->bw = RATE_INFO_BW_40;
902 * Detect RX rate, always use MCS as signal type.
904 rxdesc->dev_flags |= RXDONE_SIGNAL_MCS;
905 rxdesc->signal = rt2x00_get_field32(word, RXWI_W1_MCS);
906 rxdesc->rate_mode = rt2x00_get_field32(word, RXWI_W1_PHYMODE);
909 * Mask of 0x8 bit to remove the short preamble flag.
911 if (rxdesc->rate_mode == RATE_MODE_CCK)
912 rxdesc->signal &= ~0x8;
914 word = rt2x00_desc_read(rxwi, 2);
917 * Convert descriptor AGC value to RSSI value.
919 rxdesc->rssi = rt2800_agc_to_rssi(entry->queue->rt2x00dev, word);
921 * Remove RXWI descriptor from start of the buffer.
923 skb_pull(entry->skb, entry->queue->winfo_size);
925 EXPORT_SYMBOL_GPL(rt2800_process_rxwi);
927 static void rt2800_rate_from_status(struct skb_frame_desc *skbdesc,
928 u32 status, enum nl80211_band band)
930 u8 flags = 0;
931 u8 idx = rt2x00_get_field32(status, TX_STA_FIFO_MCS);
933 switch (rt2x00_get_field32(status, TX_STA_FIFO_PHYMODE)) {
934 case RATE_MODE_HT_GREENFIELD:
935 flags |= IEEE80211_TX_RC_GREEN_FIELD;
936 /* fall through */
937 case RATE_MODE_HT_MIX:
938 flags |= IEEE80211_TX_RC_MCS;
939 break;
940 case RATE_MODE_OFDM:
941 if (band == NL80211_BAND_2GHZ)
942 idx += 4;
943 break;
944 case RATE_MODE_CCK:
945 if (idx >= 8)
946 idx -= 8;
947 break;
950 if (rt2x00_get_field32(status, TX_STA_FIFO_BW))
951 flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
953 if (rt2x00_get_field32(status, TX_STA_FIFO_SGI))
954 flags |= IEEE80211_TX_RC_SHORT_GI;
956 skbdesc->tx_rate_idx = idx;
957 skbdesc->tx_rate_flags = flags;
960 static bool rt2800_txdone_entry_check(struct queue_entry *entry, u32 reg)
962 __le32 *txwi;
963 u32 word;
964 int wcid, ack, pid;
965 int tx_wcid, tx_ack, tx_pid, is_agg;
968 * This frames has returned with an IO error,
969 * so the status report is not intended for this
970 * frame.
972 if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags))
973 return false;
975 wcid = rt2x00_get_field32(reg, TX_STA_FIFO_WCID);
976 ack = rt2x00_get_field32(reg, TX_STA_FIFO_TX_ACK_REQUIRED);
977 pid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_TYPE);
978 is_agg = rt2x00_get_field32(reg, TX_STA_FIFO_TX_AGGRE);
981 * Validate if this TX status report is intended for
982 * this entry by comparing the WCID/ACK/PID fields.
984 txwi = rt2800_drv_get_txwi(entry);
986 word = rt2x00_desc_read(txwi, 1);
987 tx_wcid = rt2x00_get_field32(word, TXWI_W1_WIRELESS_CLI_ID);
988 tx_ack = rt2x00_get_field32(word, TXWI_W1_ACK);
989 tx_pid = rt2x00_get_field32(word, TXWI_W1_PACKETID);
991 if (wcid != tx_wcid || ack != tx_ack || (!is_agg && pid != tx_pid)) {
992 rt2x00_dbg(entry->queue->rt2x00dev,
993 "TX status report missed for queue %d entry %d\n",
994 entry->queue->qid, entry->entry_idx);
995 return false;
998 return true;
1001 void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
1002 bool match)
1004 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
1005 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
1006 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
1007 struct txdone_entry_desc txdesc;
1008 u32 word;
1009 u16 mcs, real_mcs;
1010 int aggr, ampdu, wcid, ack_req;
1013 * Obtain the status about this packet.
1015 txdesc.flags = 0;
1016 word = rt2x00_desc_read(txwi, 0);
1018 mcs = rt2x00_get_field32(word, TXWI_W0_MCS);
1019 ampdu = rt2x00_get_field32(word, TXWI_W0_AMPDU);
1021 real_mcs = rt2x00_get_field32(status, TX_STA_FIFO_MCS);
1022 aggr = rt2x00_get_field32(status, TX_STA_FIFO_TX_AGGRE);
1023 wcid = rt2x00_get_field32(status, TX_STA_FIFO_WCID);
1024 ack_req = rt2x00_get_field32(status, TX_STA_FIFO_TX_ACK_REQUIRED);
1027 * If a frame was meant to be sent as a single non-aggregated MPDU
1028 * but ended up in an aggregate the used tx rate doesn't correlate
1029 * with the one specified in the TXWI as the whole aggregate is sent
1030 * with the same rate.
1032 * For example: two frames are sent to rt2x00, the first one sets
1033 * AMPDU=1 and requests MCS7 whereas the second frame sets AMDPU=0
1034 * and requests MCS15. If the hw aggregates both frames into one
1035 * AMDPU the tx status for both frames will contain MCS7 although
1036 * the frame was sent successfully.
1038 * Hence, replace the requested rate with the real tx rate to not
1039 * confuse the rate control algortihm by providing clearly wrong
1040 * data.
1042 * FIXME: if we do not find matching entry, we tell that frame was
1043 * posted without any retries. We need to find a way to fix that
1044 * and provide retry count.
1046 if (unlikely((aggr == 1 && ampdu == 0 && real_mcs != mcs)) || !match) {
1047 rt2800_rate_from_status(skbdesc, status, rt2x00dev->curr_band);
1048 mcs = real_mcs;
1051 if (aggr == 1 || ampdu == 1)
1052 __set_bit(TXDONE_AMPDU, &txdesc.flags);
1054 if (!ack_req)
1055 __set_bit(TXDONE_NO_ACK_REQ, &txdesc.flags);
1058 * Ralink has a retry mechanism using a global fallback
1059 * table. We setup this fallback table to try the immediate
1060 * lower rate for all rates. In the TX_STA_FIFO, the MCS field
1061 * always contains the MCS used for the last transmission, be
1062 * it successful or not.
1064 if (rt2x00_get_field32(status, TX_STA_FIFO_TX_SUCCESS)) {
1066 * Transmission succeeded. The number of retries is
1067 * mcs - real_mcs
1069 __set_bit(TXDONE_SUCCESS, &txdesc.flags);
1070 txdesc.retry = ((mcs > real_mcs) ? mcs - real_mcs : 0);
1071 } else {
1073 * Transmission failed. The number of retries is
1074 * always 7 in this case (for a total number of 8
1075 * frames sent).
1077 __set_bit(TXDONE_FAILURE, &txdesc.flags);
1078 txdesc.retry = rt2x00dev->long_retry;
1082 * the frame was retried at least once
1083 * -> hw used fallback rates
1085 if (txdesc.retry)
1086 __set_bit(TXDONE_FALLBACK, &txdesc.flags);
1088 if (!match) {
1089 /* RCU assures non-null sta will not be freed by mac80211. */
1090 rcu_read_lock();
1091 if (likely(wcid >= WCID_START && wcid <= WCID_END))
1092 skbdesc->sta = drv_data->wcid_to_sta[wcid - WCID_START];
1093 else
1094 skbdesc->sta = NULL;
1095 rt2x00lib_txdone_nomatch(entry, &txdesc);
1096 rcu_read_unlock();
1097 } else {
1098 rt2x00lib_txdone(entry, &txdesc);
1101 EXPORT_SYMBOL_GPL(rt2800_txdone_entry);
1103 void rt2800_txdone(struct rt2x00_dev *rt2x00dev)
1105 struct data_queue *queue;
1106 struct queue_entry *entry;
1107 u32 reg;
1108 u8 qid;
1109 bool match;
1111 while (kfifo_get(&rt2x00dev->txstatus_fifo, &reg)) {
1113 * TX_STA_FIFO_PID_QUEUE is a 2-bit field, thus qid is
1114 * guaranteed to be one of the TX QIDs .
1116 qid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_QUEUE);
1117 queue = rt2x00queue_get_tx_queue(rt2x00dev, qid);
1119 if (unlikely(rt2x00queue_empty(queue))) {
1120 rt2x00_dbg(rt2x00dev, "Got TX status for an empty queue %u, dropping\n",
1121 qid);
1122 break;
1125 entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
1127 if (unlikely(test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
1128 !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))) {
1129 rt2x00_warn(rt2x00dev, "Data pending for entry %u in queue %u\n",
1130 entry->entry_idx, qid);
1131 break;
1134 match = rt2800_txdone_entry_check(entry, reg);
1135 rt2800_txdone_entry(entry, reg, rt2800_drv_get_txwi(entry), match);
1138 EXPORT_SYMBOL_GPL(rt2800_txdone);
1140 static inline bool rt2800_entry_txstatus_timeout(struct rt2x00_dev *rt2x00dev,
1141 struct queue_entry *entry)
1143 bool ret;
1144 unsigned long tout;
1146 if (!test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
1147 return false;
1149 if (test_bit(DEVICE_STATE_FLUSHING, &rt2x00dev->flags))
1150 tout = msecs_to_jiffies(50);
1151 else
1152 tout = msecs_to_jiffies(2000);
1154 ret = time_after(jiffies, entry->last_action + tout);
1155 if (unlikely(ret))
1156 rt2x00_dbg(entry->queue->rt2x00dev,
1157 "TX status timeout for entry %d in queue %d\n",
1158 entry->entry_idx, entry->queue->qid);
1159 return ret;
1162 bool rt2800_txstatus_timeout(struct rt2x00_dev *rt2x00dev)
1164 struct data_queue *queue;
1165 struct queue_entry *entry;
1167 if (!test_bit(DEVICE_STATE_FLUSHING, &rt2x00dev->flags)) {
1168 unsigned long tout = msecs_to_jiffies(1000);
1170 if (time_before(jiffies, rt2x00dev->last_nostatus_check + tout))
1171 return false;
1174 rt2x00dev->last_nostatus_check = jiffies;
1176 tx_queue_for_each(rt2x00dev, queue) {
1177 entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
1178 if (rt2800_entry_txstatus_timeout(rt2x00dev, entry))
1179 return true;
1182 return false;
1184 EXPORT_SYMBOL_GPL(rt2800_txstatus_timeout);
1186 void rt2800_txdone_nostatus(struct rt2x00_dev *rt2x00dev)
1188 struct data_queue *queue;
1189 struct queue_entry *entry;
1192 * Process any trailing TX status reports for IO failures,
1193 * we loop until we find the first non-IO error entry. This
1194 * can either be a frame which is free, is being uploaded,
1195 * or has completed the upload but didn't have an entry
1196 * in the TX_STAT_FIFO register yet.
1198 tx_queue_for_each(rt2x00dev, queue) {
1199 while (!rt2x00queue_empty(queue)) {
1200 entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
1202 if (test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
1203 !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags))
1204 break;
1206 if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags) ||
1207 rt2800_entry_txstatus_timeout(rt2x00dev, entry))
1208 rt2x00lib_txdone_noinfo(entry, TXDONE_FAILURE);
1209 else
1210 break;
1214 EXPORT_SYMBOL_GPL(rt2800_txdone_nostatus);
1216 static unsigned int rt2800_hw_beacon_base(struct rt2x00_dev *rt2x00dev,
1217 unsigned int index)
1219 return HW_BEACON_BASE(index);
1222 static inline u8 rt2800_get_beacon_offset(struct rt2x00_dev *rt2x00dev,
1223 unsigned int index)
1225 return BEACON_BASE_TO_OFFSET(rt2800_hw_beacon_base(rt2x00dev, index));
1228 static void rt2800_update_beacons_setup(struct rt2x00_dev *rt2x00dev)
1230 struct data_queue *queue = rt2x00dev->bcn;
1231 struct queue_entry *entry;
1232 int i, bcn_num = 0;
1233 u64 off, reg = 0;
1234 u32 bssid_dw1;
1237 * Setup offsets of all active beacons in BCN_OFFSET{0,1} registers.
1239 for (i = 0; i < queue->limit; i++) {
1240 entry = &queue->entries[i];
1241 if (!test_bit(ENTRY_BCN_ENABLED, &entry->flags))
1242 continue;
1243 off = rt2800_get_beacon_offset(rt2x00dev, entry->entry_idx);
1244 reg |= off << (8 * bcn_num);
1245 bcn_num++;
1248 rt2800_register_write(rt2x00dev, BCN_OFFSET0, (u32) reg);
1249 rt2800_register_write(rt2x00dev, BCN_OFFSET1, (u32) (reg >> 32));
1252 * H/W sends up to MAC_BSSID_DW1_BSS_BCN_NUM + 1 consecutive beacons.
1254 bssid_dw1 = rt2800_register_read(rt2x00dev, MAC_BSSID_DW1);
1255 rt2x00_set_field32(&bssid_dw1, MAC_BSSID_DW1_BSS_BCN_NUM,
1256 bcn_num > 0 ? bcn_num - 1 : 0);
1257 rt2800_register_write(rt2x00dev, MAC_BSSID_DW1, bssid_dw1);
1260 void rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc)
1262 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
1263 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
1264 unsigned int beacon_base;
1265 unsigned int padding_len;
1266 u32 orig_reg, reg;
1267 const int txwi_desc_size = entry->queue->winfo_size;
1270 * Disable beaconing while we are reloading the beacon data,
1271 * otherwise we might be sending out invalid data.
1273 reg = rt2800_register_read(rt2x00dev, BCN_TIME_CFG);
1274 orig_reg = reg;
1275 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
1276 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
1279 * Add space for the TXWI in front of the skb.
1281 memset(skb_push(entry->skb, txwi_desc_size), 0, txwi_desc_size);
1284 * Register descriptor details in skb frame descriptor.
1286 skbdesc->flags |= SKBDESC_DESC_IN_SKB;
1287 skbdesc->desc = entry->skb->data;
1288 skbdesc->desc_len = txwi_desc_size;
1291 * Add the TXWI for the beacon to the skb.
1293 rt2800_write_tx_data(entry, txdesc);
1296 * Dump beacon to userspace through debugfs.
1298 rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry);
1301 * Write entire beacon with TXWI and padding to register.
1303 padding_len = roundup(entry->skb->len, 4) - entry->skb->len;
1304 if (padding_len && skb_pad(entry->skb, padding_len)) {
1305 rt2x00_err(rt2x00dev, "Failure padding beacon, aborting\n");
1306 /* skb freed by skb_pad() on failure */
1307 entry->skb = NULL;
1308 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, orig_reg);
1309 return;
1312 beacon_base = rt2800_hw_beacon_base(rt2x00dev, entry->entry_idx);
1314 rt2800_register_multiwrite(rt2x00dev, beacon_base, entry->skb->data,
1315 entry->skb->len + padding_len);
1316 __set_bit(ENTRY_BCN_ENABLED, &entry->flags);
1319 * Change global beacons settings.
1321 rt2800_update_beacons_setup(rt2x00dev);
1324 * Restore beaconing state.
1326 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, orig_reg);
1329 * Clean up beacon skb.
1331 dev_kfree_skb_any(entry->skb);
1332 entry->skb = NULL;
1334 EXPORT_SYMBOL_GPL(rt2800_write_beacon);
1336 static inline void rt2800_clear_beacon_register(struct rt2x00_dev *rt2x00dev,
1337 unsigned int index)
1339 int i;
1340 const int txwi_desc_size = rt2x00dev->bcn->winfo_size;
1341 unsigned int beacon_base;
1343 beacon_base = rt2800_hw_beacon_base(rt2x00dev, index);
1346 * For the Beacon base registers we only need to clear
1347 * the whole TXWI which (when set to 0) will invalidate
1348 * the entire beacon.
1350 for (i = 0; i < txwi_desc_size; i += sizeof(__le32))
1351 rt2800_register_write(rt2x00dev, beacon_base + i, 0);
1354 void rt2800_clear_beacon(struct queue_entry *entry)
1356 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
1357 u32 orig_reg, reg;
1360 * Disable beaconing while we are reloading the beacon data,
1361 * otherwise we might be sending out invalid data.
1363 orig_reg = rt2800_register_read(rt2x00dev, BCN_TIME_CFG);
1364 reg = orig_reg;
1365 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
1366 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
1369 * Clear beacon.
1371 rt2800_clear_beacon_register(rt2x00dev, entry->entry_idx);
1372 __clear_bit(ENTRY_BCN_ENABLED, &entry->flags);
1375 * Change global beacons settings.
1377 rt2800_update_beacons_setup(rt2x00dev);
1379 * Restore beaconing state.
1381 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, orig_reg);
1383 EXPORT_SYMBOL_GPL(rt2800_clear_beacon);
1385 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
1386 const struct rt2x00debug rt2800_rt2x00debug = {
1387 .owner = THIS_MODULE,
1388 .csr = {
1389 .read = rt2800_register_read,
1390 .write = rt2800_register_write,
1391 .flags = RT2X00DEBUGFS_OFFSET,
1392 .word_base = CSR_REG_BASE,
1393 .word_size = sizeof(u32),
1394 .word_count = CSR_REG_SIZE / sizeof(u32),
1396 .eeprom = {
1397 /* NOTE: The local EEPROM access functions can't
1398 * be used here, use the generic versions instead.
1400 .read = rt2x00_eeprom_read,
1401 .write = rt2x00_eeprom_write,
1402 .word_base = EEPROM_BASE,
1403 .word_size = sizeof(u16),
1404 .word_count = EEPROM_SIZE / sizeof(u16),
1406 .bbp = {
1407 .read = rt2800_bbp_read,
1408 .write = rt2800_bbp_write,
1409 .word_base = BBP_BASE,
1410 .word_size = sizeof(u8),
1411 .word_count = BBP_SIZE / sizeof(u8),
1413 .rf = {
1414 .read = rt2x00_rf_read,
1415 .write = rt2800_rf_write,
1416 .word_base = RF_BASE,
1417 .word_size = sizeof(u32),
1418 .word_count = RF_SIZE / sizeof(u32),
1420 .rfcsr = {
1421 .read = rt2800_rfcsr_read,
1422 .write = rt2800_rfcsr_write,
1423 .word_base = RFCSR_BASE,
1424 .word_size = sizeof(u8),
1425 .word_count = RFCSR_SIZE / sizeof(u8),
1428 EXPORT_SYMBOL_GPL(rt2800_rt2x00debug);
1429 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
1431 int rt2800_rfkill_poll(struct rt2x00_dev *rt2x00dev)
1433 u32 reg;
1435 if (rt2x00_rt(rt2x00dev, RT3290)) {
1436 reg = rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL);
1437 return rt2x00_get_field32(reg, WLAN_GPIO_IN_BIT0);
1438 } else {
1439 reg = rt2800_register_read(rt2x00dev, GPIO_CTRL);
1440 return rt2x00_get_field32(reg, GPIO_CTRL_VAL2);
1443 EXPORT_SYMBOL_GPL(rt2800_rfkill_poll);
1445 #ifdef CONFIG_RT2X00_LIB_LEDS
1446 static void rt2800_brightness_set(struct led_classdev *led_cdev,
1447 enum led_brightness brightness)
1449 struct rt2x00_led *led =
1450 container_of(led_cdev, struct rt2x00_led, led_dev);
1451 unsigned int enabled = brightness != LED_OFF;
1452 unsigned int bg_mode =
1453 (enabled && led->rt2x00dev->curr_band == NL80211_BAND_2GHZ);
1454 unsigned int polarity =
1455 rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
1456 EEPROM_FREQ_LED_POLARITY);
1457 unsigned int ledmode =
1458 rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
1459 EEPROM_FREQ_LED_MODE);
1460 u32 reg;
1462 /* Check for SoC (SOC devices don't support MCU requests) */
1463 if (rt2x00_is_soc(led->rt2x00dev)) {
1464 reg = rt2800_register_read(led->rt2x00dev, LED_CFG);
1466 /* Set LED Polarity */
1467 rt2x00_set_field32(&reg, LED_CFG_LED_POLAR, polarity);
1469 /* Set LED Mode */
1470 if (led->type == LED_TYPE_RADIO) {
1471 rt2x00_set_field32(&reg, LED_CFG_G_LED_MODE,
1472 enabled ? 3 : 0);
1473 } else if (led->type == LED_TYPE_ASSOC) {
1474 rt2x00_set_field32(&reg, LED_CFG_Y_LED_MODE,
1475 enabled ? 3 : 0);
1476 } else if (led->type == LED_TYPE_QUALITY) {
1477 rt2x00_set_field32(&reg, LED_CFG_R_LED_MODE,
1478 enabled ? 3 : 0);
1481 rt2800_register_write(led->rt2x00dev, LED_CFG, reg);
1483 } else {
1484 if (led->type == LED_TYPE_RADIO) {
1485 rt2800_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
1486 enabled ? 0x20 : 0);
1487 } else if (led->type == LED_TYPE_ASSOC) {
1488 rt2800_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
1489 enabled ? (bg_mode ? 0x60 : 0xa0) : 0x20);
1490 } else if (led->type == LED_TYPE_QUALITY) {
1492 * The brightness is divided into 6 levels (0 - 5),
1493 * The specs tell us the following levels:
1494 * 0, 1 ,3, 7, 15, 31
1495 * to determine the level in a simple way we can simply
1496 * work with bitshifting:
1497 * (1 << level) - 1
1499 rt2800_mcu_request(led->rt2x00dev, MCU_LED_STRENGTH, 0xff,
1500 (1 << brightness / (LED_FULL / 6)) - 1,
1501 polarity);
1506 static void rt2800_init_led(struct rt2x00_dev *rt2x00dev,
1507 struct rt2x00_led *led, enum led_type type)
1509 led->rt2x00dev = rt2x00dev;
1510 led->type = type;
1511 led->led_dev.brightness_set = rt2800_brightness_set;
1512 led->flags = LED_INITIALIZED;
1514 #endif /* CONFIG_RT2X00_LIB_LEDS */
1517 * Configuration handlers.
1519 static void rt2800_config_wcid(struct rt2x00_dev *rt2x00dev,
1520 const u8 *address,
1521 int wcid)
1523 struct mac_wcid_entry wcid_entry;
1524 u32 offset;
1526 offset = MAC_WCID_ENTRY(wcid);
1528 memset(&wcid_entry, 0xff, sizeof(wcid_entry));
1529 if (address)
1530 memcpy(wcid_entry.mac, address, ETH_ALEN);
1532 rt2800_register_multiwrite(rt2x00dev, offset,
1533 &wcid_entry, sizeof(wcid_entry));
1536 static void rt2800_delete_wcid_attr(struct rt2x00_dev *rt2x00dev, int wcid)
1538 u32 offset;
1539 offset = MAC_WCID_ATTR_ENTRY(wcid);
1540 rt2800_register_write(rt2x00dev, offset, 0);
1543 static void rt2800_config_wcid_attr_bssidx(struct rt2x00_dev *rt2x00dev,
1544 int wcid, u32 bssidx)
1546 u32 offset = MAC_WCID_ATTR_ENTRY(wcid);
1547 u32 reg;
1550 * The BSS Idx numbers is split in a main value of 3 bits,
1551 * and a extended field for adding one additional bit to the value.
1553 reg = rt2800_register_read(rt2x00dev, offset);
1554 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_BSS_IDX, (bssidx & 0x7));
1555 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_BSS_IDX_EXT,
1556 (bssidx & 0x8) >> 3);
1557 rt2800_register_write(rt2x00dev, offset, reg);
1560 static void rt2800_config_wcid_attr_cipher(struct rt2x00_dev *rt2x00dev,
1561 struct rt2x00lib_crypto *crypto,
1562 struct ieee80211_key_conf *key)
1564 struct mac_iveiv_entry iveiv_entry;
1565 u32 offset;
1566 u32 reg;
1568 offset = MAC_WCID_ATTR_ENTRY(key->hw_key_idx);
1570 if (crypto->cmd == SET_KEY) {
1571 reg = rt2800_register_read(rt2x00dev, offset);
1572 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_KEYTAB,
1573 !!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE));
1575 * Both the cipher as the BSS Idx numbers are split in a main
1576 * value of 3 bits, and a extended field for adding one additional
1577 * bit to the value.
1579 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_CIPHER,
1580 (crypto->cipher & 0x7));
1581 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_CIPHER_EXT,
1582 (crypto->cipher & 0x8) >> 3);
1583 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_RX_WIUDF, crypto->cipher);
1584 rt2800_register_write(rt2x00dev, offset, reg);
1585 } else {
1586 /* Delete the cipher without touching the bssidx */
1587 reg = rt2800_register_read(rt2x00dev, offset);
1588 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_KEYTAB, 0);
1589 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_CIPHER, 0);
1590 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_CIPHER_EXT, 0);
1591 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_RX_WIUDF, 0);
1592 rt2800_register_write(rt2x00dev, offset, reg);
1595 offset = MAC_IVEIV_ENTRY(key->hw_key_idx);
1597 memset(&iveiv_entry, 0, sizeof(iveiv_entry));
1598 if ((crypto->cipher == CIPHER_TKIP) ||
1599 (crypto->cipher == CIPHER_TKIP_NO_MIC) ||
1600 (crypto->cipher == CIPHER_AES))
1601 iveiv_entry.iv[3] |= 0x20;
1602 iveiv_entry.iv[3] |= key->keyidx << 6;
1603 rt2800_register_multiwrite(rt2x00dev, offset,
1604 &iveiv_entry, sizeof(iveiv_entry));
1607 int rt2800_config_shared_key(struct rt2x00_dev *rt2x00dev,
1608 struct rt2x00lib_crypto *crypto,
1609 struct ieee80211_key_conf *key)
1611 struct hw_key_entry key_entry;
1612 struct rt2x00_field32 field;
1613 u32 offset;
1614 u32 reg;
1616 if (crypto->cmd == SET_KEY) {
1617 key->hw_key_idx = (4 * crypto->bssidx) + key->keyidx;
1619 memcpy(key_entry.key, crypto->key,
1620 sizeof(key_entry.key));
1621 memcpy(key_entry.tx_mic, crypto->tx_mic,
1622 sizeof(key_entry.tx_mic));
1623 memcpy(key_entry.rx_mic, crypto->rx_mic,
1624 sizeof(key_entry.rx_mic));
1626 offset = SHARED_KEY_ENTRY(key->hw_key_idx);
1627 rt2800_register_multiwrite(rt2x00dev, offset,
1628 &key_entry, sizeof(key_entry));
1632 * The cipher types are stored over multiple registers
1633 * starting with SHARED_KEY_MODE_BASE each word will have
1634 * 32 bits and contains the cipher types for 2 bssidx each.
1635 * Using the correct defines correctly will cause overhead,
1636 * so just calculate the correct offset.
1638 field.bit_offset = 4 * (key->hw_key_idx % 8);
1639 field.bit_mask = 0x7 << field.bit_offset;
1641 offset = SHARED_KEY_MODE_ENTRY(key->hw_key_idx / 8);
1643 reg = rt2800_register_read(rt2x00dev, offset);
1644 rt2x00_set_field32(&reg, field,
1645 (crypto->cmd == SET_KEY) * crypto->cipher);
1646 rt2800_register_write(rt2x00dev, offset, reg);
1649 * Update WCID information
1651 rt2800_config_wcid(rt2x00dev, crypto->address, key->hw_key_idx);
1652 rt2800_config_wcid_attr_bssidx(rt2x00dev, key->hw_key_idx,
1653 crypto->bssidx);
1654 rt2800_config_wcid_attr_cipher(rt2x00dev, crypto, key);
1656 return 0;
1658 EXPORT_SYMBOL_GPL(rt2800_config_shared_key);
1660 int rt2800_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
1661 struct rt2x00lib_crypto *crypto,
1662 struct ieee80211_key_conf *key)
1664 struct hw_key_entry key_entry;
1665 u32 offset;
1667 if (crypto->cmd == SET_KEY) {
1669 * Allow key configuration only for STAs that are
1670 * known by the hw.
1672 if (crypto->wcid > WCID_END)
1673 return -ENOSPC;
1674 key->hw_key_idx = crypto->wcid;
1676 memcpy(key_entry.key, crypto->key,
1677 sizeof(key_entry.key));
1678 memcpy(key_entry.tx_mic, crypto->tx_mic,
1679 sizeof(key_entry.tx_mic));
1680 memcpy(key_entry.rx_mic, crypto->rx_mic,
1681 sizeof(key_entry.rx_mic));
1683 offset = PAIRWISE_KEY_ENTRY(key->hw_key_idx);
1684 rt2800_register_multiwrite(rt2x00dev, offset,
1685 &key_entry, sizeof(key_entry));
1689 * Update WCID information
1691 rt2800_config_wcid_attr_cipher(rt2x00dev, crypto, key);
1693 return 0;
1695 EXPORT_SYMBOL_GPL(rt2800_config_pairwise_key);
1697 static void rt2800_set_max_psdu_len(struct rt2x00_dev *rt2x00dev)
1699 u8 i, max_psdu;
1700 u32 reg;
1701 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
1703 for (i = 0; i < 3; i++)
1704 if (drv_data->ampdu_factor_cnt[i] > 0)
1705 break;
1707 max_psdu = min(drv_data->max_psdu, i);
1709 reg = rt2800_register_read(rt2x00dev, MAX_LEN_CFG);
1710 rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, max_psdu);
1711 rt2800_register_write(rt2x00dev, MAX_LEN_CFG, reg);
1714 int rt2800_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1715 struct ieee80211_sta *sta)
1717 struct rt2x00_dev *rt2x00dev = hw->priv;
1718 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
1719 struct rt2x00_sta *sta_priv = sta_to_rt2x00_sta(sta);
1720 int wcid;
1723 * Limit global maximum TX AMPDU length to smallest value of all
1724 * connected stations. In AP mode this can be suboptimal, but we
1725 * do not have a choice if some connected STA is not capable to
1726 * receive the same amount of data like the others.
1728 if (sta->ht_cap.ht_supported) {
1729 drv_data->ampdu_factor_cnt[sta->ht_cap.ampdu_factor & 3]++;
1730 rt2800_set_max_psdu_len(rt2x00dev);
1734 * Search for the first free WCID entry and return the corresponding
1735 * index.
1737 wcid = find_first_zero_bit(drv_data->sta_ids, STA_IDS_SIZE) + WCID_START;
1740 * Store selected wcid even if it is invalid so that we can
1741 * later decide if the STA is uploaded into the hw.
1743 sta_priv->wcid = wcid;
1746 * No space left in the device, however, we can still communicate
1747 * with the STA -> No error.
1749 if (wcid > WCID_END)
1750 return 0;
1752 __set_bit(wcid - WCID_START, drv_data->sta_ids);
1753 drv_data->wcid_to_sta[wcid - WCID_START] = sta;
1756 * Clean up WCID attributes and write STA address to the device.
1758 rt2800_delete_wcid_attr(rt2x00dev, wcid);
1759 rt2800_config_wcid(rt2x00dev, sta->addr, wcid);
1760 rt2800_config_wcid_attr_bssidx(rt2x00dev, wcid,
1761 rt2x00lib_get_bssidx(rt2x00dev, vif));
1762 return 0;
1764 EXPORT_SYMBOL_GPL(rt2800_sta_add);
1766 int rt2800_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1767 struct ieee80211_sta *sta)
1769 struct rt2x00_dev *rt2x00dev = hw->priv;
1770 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
1771 struct rt2x00_sta *sta_priv = sta_to_rt2x00_sta(sta);
1772 int wcid = sta_priv->wcid;
1774 if (sta->ht_cap.ht_supported) {
1775 drv_data->ampdu_factor_cnt[sta->ht_cap.ampdu_factor & 3]--;
1776 rt2800_set_max_psdu_len(rt2x00dev);
1779 if (wcid > WCID_END)
1780 return 0;
1782 * Remove WCID entry, no need to clean the attributes as they will
1783 * get renewed when the WCID is reused.
1785 rt2800_config_wcid(rt2x00dev, NULL, wcid);
1786 drv_data->wcid_to_sta[wcid - WCID_START] = NULL;
1787 __clear_bit(wcid - WCID_START, drv_data->sta_ids);
1789 return 0;
1791 EXPORT_SYMBOL_GPL(rt2800_sta_remove);
1793 void rt2800_config_filter(struct rt2x00_dev *rt2x00dev,
1794 const unsigned int filter_flags)
1796 u32 reg;
1799 * Start configuration steps.
1800 * Note that the version error will always be dropped
1801 * and broadcast frames will always be accepted since
1802 * there is no filter for it at this time.
1804 reg = rt2800_register_read(rt2x00dev, RX_FILTER_CFG);
1805 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CRC_ERROR,
1806 !(filter_flags & FIF_FCSFAIL));
1807 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_PHY_ERROR,
1808 !(filter_flags & FIF_PLCPFAIL));
1809 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_NOT_TO_ME,
1810 !test_bit(CONFIG_MONITORING, &rt2x00dev->flags));
1811 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_NOT_MY_BSSD, 0);
1812 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_VER_ERROR, 1);
1813 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_MULTICAST,
1814 !(filter_flags & FIF_ALLMULTI));
1815 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BROADCAST, 0);
1816 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_DUPLICATE, 1);
1817 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CF_END_ACK,
1818 !(filter_flags & FIF_CONTROL));
1819 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CF_END,
1820 !(filter_flags & FIF_CONTROL));
1821 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_ACK,
1822 !(filter_flags & FIF_CONTROL));
1823 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CTS,
1824 !(filter_flags & FIF_CONTROL));
1825 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_RTS,
1826 !(filter_flags & FIF_CONTROL));
1827 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_PSPOLL,
1828 !(filter_flags & FIF_PSPOLL));
1829 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BA, 0);
1830 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BAR,
1831 !(filter_flags & FIF_CONTROL));
1832 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CNTL,
1833 !(filter_flags & FIF_CONTROL));
1834 rt2800_register_write(rt2x00dev, RX_FILTER_CFG, reg);
1836 EXPORT_SYMBOL_GPL(rt2800_config_filter);
1838 void rt2800_config_intf(struct rt2x00_dev *rt2x00dev, struct rt2x00_intf *intf,
1839 struct rt2x00intf_conf *conf, const unsigned int flags)
1841 u32 reg;
1842 bool update_bssid = false;
1844 if (flags & CONFIG_UPDATE_TYPE) {
1846 * Enable synchronisation.
1848 reg = rt2800_register_read(rt2x00dev, BCN_TIME_CFG);
1849 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, conf->sync);
1850 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
1852 if (conf->sync == TSF_SYNC_AP_NONE) {
1854 * Tune beacon queue transmit parameters for AP mode
1856 reg = rt2800_register_read(rt2x00dev, TBTT_SYNC_CFG);
1857 rt2x00_set_field32(&reg, TBTT_SYNC_CFG_BCN_CWMIN, 0);
1858 rt2x00_set_field32(&reg, TBTT_SYNC_CFG_BCN_AIFSN, 1);
1859 rt2x00_set_field32(&reg, TBTT_SYNC_CFG_BCN_EXP_WIN, 32);
1860 rt2x00_set_field32(&reg, TBTT_SYNC_CFG_TBTT_ADJUST, 0);
1861 rt2800_register_write(rt2x00dev, TBTT_SYNC_CFG, reg);
1862 } else {
1863 reg = rt2800_register_read(rt2x00dev, TBTT_SYNC_CFG);
1864 rt2x00_set_field32(&reg, TBTT_SYNC_CFG_BCN_CWMIN, 4);
1865 rt2x00_set_field32(&reg, TBTT_SYNC_CFG_BCN_AIFSN, 2);
1866 rt2x00_set_field32(&reg, TBTT_SYNC_CFG_BCN_EXP_WIN, 32);
1867 rt2x00_set_field32(&reg, TBTT_SYNC_CFG_TBTT_ADJUST, 16);
1868 rt2800_register_write(rt2x00dev, TBTT_SYNC_CFG, reg);
1872 if (flags & CONFIG_UPDATE_MAC) {
1873 if (flags & CONFIG_UPDATE_TYPE &&
1874 conf->sync == TSF_SYNC_AP_NONE) {
1876 * The BSSID register has to be set to our own mac
1877 * address in AP mode.
1879 memcpy(conf->bssid, conf->mac, sizeof(conf->mac));
1880 update_bssid = true;
1883 if (!is_zero_ether_addr((const u8 *)conf->mac)) {
1884 reg = le32_to_cpu(conf->mac[1]);
1885 rt2x00_set_field32(&reg, MAC_ADDR_DW1_UNICAST_TO_ME_MASK, 0xff);
1886 conf->mac[1] = cpu_to_le32(reg);
1889 rt2800_register_multiwrite(rt2x00dev, MAC_ADDR_DW0,
1890 conf->mac, sizeof(conf->mac));
1893 if ((flags & CONFIG_UPDATE_BSSID) || update_bssid) {
1894 if (!is_zero_ether_addr((const u8 *)conf->bssid)) {
1895 reg = le32_to_cpu(conf->bssid[1]);
1896 rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_ID_MASK, 3);
1897 rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_BCN_NUM, 0);
1898 conf->bssid[1] = cpu_to_le32(reg);
1901 rt2800_register_multiwrite(rt2x00dev, MAC_BSSID_DW0,
1902 conf->bssid, sizeof(conf->bssid));
1905 EXPORT_SYMBOL_GPL(rt2800_config_intf);
1907 static void rt2800_config_ht_opmode(struct rt2x00_dev *rt2x00dev,
1908 struct rt2x00lib_erp *erp)
1910 bool any_sta_nongf = !!(erp->ht_opmode &
1911 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
1912 u8 protection = erp->ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION;
1913 u8 mm20_mode, mm40_mode, gf20_mode, gf40_mode;
1914 u16 mm20_rate, mm40_rate, gf20_rate, gf40_rate;
1915 u32 reg;
1917 /* default protection rate for HT20: OFDM 24M */
1918 mm20_rate = gf20_rate = 0x4004;
1920 /* default protection rate for HT40: duplicate OFDM 24M */
1921 mm40_rate = gf40_rate = 0x4084;
1923 switch (protection) {
1924 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
1926 * All STAs in this BSS are HT20/40 but there might be
1927 * STAs not supporting greenfield mode.
1928 * => Disable protection for HT transmissions.
1930 mm20_mode = mm40_mode = gf20_mode = gf40_mode = 0;
1932 break;
1933 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
1935 * All STAs in this BSS are HT20 or HT20/40 but there
1936 * might be STAs not supporting greenfield mode.
1937 * => Protect all HT40 transmissions.
1939 mm20_mode = gf20_mode = 0;
1940 mm40_mode = gf40_mode = 1;
1942 break;
1943 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
1945 * Nonmember protection:
1946 * According to 802.11n we _should_ protect all
1947 * HT transmissions (but we don't have to).
1949 * But if cts_protection is enabled we _shall_ protect
1950 * all HT transmissions using a CCK rate.
1952 * And if any station is non GF we _shall_ protect
1953 * GF transmissions.
1955 * We decide to protect everything
1956 * -> fall through to mixed mode.
1958 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
1960 * Legacy STAs are present
1961 * => Protect all HT transmissions.
1963 mm20_mode = mm40_mode = gf20_mode = gf40_mode = 1;
1966 * If erp protection is needed we have to protect HT
1967 * transmissions with CCK 11M long preamble.
1969 if (erp->cts_protection) {
1970 /* don't duplicate RTS/CTS in CCK mode */
1971 mm20_rate = mm40_rate = 0x0003;
1972 gf20_rate = gf40_rate = 0x0003;
1974 break;
1977 /* check for STAs not supporting greenfield mode */
1978 if (any_sta_nongf)
1979 gf20_mode = gf40_mode = 1;
1981 /* Update HT protection config */
1982 reg = rt2800_register_read(rt2x00dev, MM20_PROT_CFG);
1983 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_RATE, mm20_rate);
1984 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_CTRL, mm20_mode);
1985 rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
1987 reg = rt2800_register_read(rt2x00dev, MM40_PROT_CFG);
1988 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_RATE, mm40_rate);
1989 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_CTRL, mm40_mode);
1990 rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
1992 reg = rt2800_register_read(rt2x00dev, GF20_PROT_CFG);
1993 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_RATE, gf20_rate);
1994 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_CTRL, gf20_mode);
1995 rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
1997 reg = rt2800_register_read(rt2x00dev, GF40_PROT_CFG);
1998 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_RATE, gf40_rate);
1999 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_CTRL, gf40_mode);
2000 rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
2003 void rt2800_config_erp(struct rt2x00_dev *rt2x00dev, struct rt2x00lib_erp *erp,
2004 u32 changed)
2006 u32 reg;
2008 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2009 reg = rt2800_register_read(rt2x00dev, AUTO_RSP_CFG);
2010 rt2x00_set_field32(&reg, AUTO_RSP_CFG_AR_PREAMBLE,
2011 !!erp->short_preamble);
2012 rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
2015 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2016 reg = rt2800_register_read(rt2x00dev, OFDM_PROT_CFG);
2017 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL,
2018 erp->cts_protection ? 2 : 0);
2019 rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
2022 if (changed & BSS_CHANGED_BASIC_RATES) {
2023 rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE,
2024 0xff0 | erp->basic_rates);
2025 rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
2028 if (changed & BSS_CHANGED_ERP_SLOT) {
2029 reg = rt2800_register_read(rt2x00dev, BKOFF_SLOT_CFG);
2030 rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_SLOT_TIME,
2031 erp->slot_time);
2032 rt2800_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg);
2034 reg = rt2800_register_read(rt2x00dev, XIFS_TIME_CFG);
2035 rt2x00_set_field32(&reg, XIFS_TIME_CFG_EIFS, erp->eifs);
2036 rt2800_register_write(rt2x00dev, XIFS_TIME_CFG, reg);
2039 if (changed & BSS_CHANGED_BEACON_INT) {
2040 reg = rt2800_register_read(rt2x00dev, BCN_TIME_CFG);
2041 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL,
2042 erp->beacon_int * 16);
2043 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
2046 if (changed & BSS_CHANGED_HT)
2047 rt2800_config_ht_opmode(rt2x00dev, erp);
2049 EXPORT_SYMBOL_GPL(rt2800_config_erp);
2051 static void rt2800_config_3572bt_ant(struct rt2x00_dev *rt2x00dev)
2053 u32 reg;
2054 u16 eeprom;
2055 u8 led_ctrl, led_g_mode, led_r_mode;
2057 reg = rt2800_register_read(rt2x00dev, GPIO_SWITCH);
2058 if (rt2x00dev->curr_band == NL80211_BAND_5GHZ) {
2059 rt2x00_set_field32(&reg, GPIO_SWITCH_0, 1);
2060 rt2x00_set_field32(&reg, GPIO_SWITCH_1, 1);
2061 } else {
2062 rt2x00_set_field32(&reg, GPIO_SWITCH_0, 0);
2063 rt2x00_set_field32(&reg, GPIO_SWITCH_1, 0);
2065 rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg);
2067 reg = rt2800_register_read(rt2x00dev, LED_CFG);
2068 led_g_mode = rt2x00_get_field32(reg, LED_CFG_LED_POLAR) ? 3 : 0;
2069 led_r_mode = rt2x00_get_field32(reg, LED_CFG_LED_POLAR) ? 0 : 3;
2070 if (led_g_mode != rt2x00_get_field32(reg, LED_CFG_G_LED_MODE) ||
2071 led_r_mode != rt2x00_get_field32(reg, LED_CFG_R_LED_MODE)) {
2072 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_FREQ);
2073 led_ctrl = rt2x00_get_field16(eeprom, EEPROM_FREQ_LED_MODE);
2074 if (led_ctrl == 0 || led_ctrl > 0x40) {
2075 rt2x00_set_field32(&reg, LED_CFG_G_LED_MODE, led_g_mode);
2076 rt2x00_set_field32(&reg, LED_CFG_R_LED_MODE, led_r_mode);
2077 rt2800_register_write(rt2x00dev, LED_CFG, reg);
2078 } else {
2079 rt2800_mcu_request(rt2x00dev, MCU_BAND_SELECT, 0xff,
2080 (led_g_mode << 2) | led_r_mode, 1);
2085 static void rt2800_set_ant_diversity(struct rt2x00_dev *rt2x00dev,
2086 enum antenna ant)
2088 u32 reg;
2089 u8 eesk_pin = (ant == ANTENNA_A) ? 1 : 0;
2090 u8 gpio_bit3 = (ant == ANTENNA_A) ? 0 : 1;
2092 if (rt2x00_is_pci(rt2x00dev)) {
2093 reg = rt2800_register_read(rt2x00dev, E2PROM_CSR);
2094 rt2x00_set_field32(&reg, E2PROM_CSR_DATA_CLOCK, eesk_pin);
2095 rt2800_register_write(rt2x00dev, E2PROM_CSR, reg);
2096 } else if (rt2x00_is_usb(rt2x00dev))
2097 rt2800_mcu_request(rt2x00dev, MCU_ANT_SELECT, 0xff,
2098 eesk_pin, 0);
2100 reg = rt2800_register_read(rt2x00dev, GPIO_CTRL);
2101 rt2x00_set_field32(&reg, GPIO_CTRL_DIR3, 0);
2102 rt2x00_set_field32(&reg, GPIO_CTRL_VAL3, gpio_bit3);
2103 rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
2106 void rt2800_config_ant(struct rt2x00_dev *rt2x00dev, struct antenna_setup *ant)
2108 u8 r1;
2109 u8 r3;
2110 u16 eeprom;
2112 r1 = rt2800_bbp_read(rt2x00dev, 1);
2113 r3 = rt2800_bbp_read(rt2x00dev, 3);
2115 if (rt2x00_rt(rt2x00dev, RT3572) &&
2116 rt2x00_has_cap_bt_coexist(rt2x00dev))
2117 rt2800_config_3572bt_ant(rt2x00dev);
2120 * Configure the TX antenna.
2122 switch (ant->tx_chain_num) {
2123 case 1:
2124 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0);
2125 break;
2126 case 2:
2127 if (rt2x00_rt(rt2x00dev, RT3572) &&
2128 rt2x00_has_cap_bt_coexist(rt2x00dev))
2129 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 1);
2130 else
2131 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2);
2132 break;
2133 case 3:
2134 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2);
2135 break;
2139 * Configure the RX antenna.
2141 switch (ant->rx_chain_num) {
2142 case 1:
2143 if (rt2x00_rt(rt2x00dev, RT3070) ||
2144 rt2x00_rt(rt2x00dev, RT3090) ||
2145 rt2x00_rt(rt2x00dev, RT3352) ||
2146 rt2x00_rt(rt2x00dev, RT3390)) {
2147 eeprom = rt2800_eeprom_read(rt2x00dev,
2148 EEPROM_NIC_CONF1);
2149 if (rt2x00_get_field16(eeprom,
2150 EEPROM_NIC_CONF1_ANT_DIVERSITY))
2151 rt2800_set_ant_diversity(rt2x00dev,
2152 rt2x00dev->default_ant.rx);
2154 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0);
2155 break;
2156 case 2:
2157 if (rt2x00_rt(rt2x00dev, RT3572) &&
2158 rt2x00_has_cap_bt_coexist(rt2x00dev)) {
2159 rt2x00_set_field8(&r3, BBP3_RX_ADC, 1);
2160 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA,
2161 rt2x00dev->curr_band == NL80211_BAND_5GHZ);
2162 rt2800_set_ant_diversity(rt2x00dev, ANTENNA_B);
2163 } else {
2164 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 1);
2166 break;
2167 case 3:
2168 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 2);
2169 break;
2172 rt2800_bbp_write(rt2x00dev, 3, r3);
2173 rt2800_bbp_write(rt2x00dev, 1, r1);
2175 if (rt2x00_rt(rt2x00dev, RT3593)) {
2176 if (ant->rx_chain_num == 1)
2177 rt2800_bbp_write(rt2x00dev, 86, 0x00);
2178 else
2179 rt2800_bbp_write(rt2x00dev, 86, 0x46);
2182 EXPORT_SYMBOL_GPL(rt2800_config_ant);
2184 static void rt2800_config_lna_gain(struct rt2x00_dev *rt2x00dev,
2185 struct rt2x00lib_conf *libconf)
2187 u16 eeprom;
2188 short lna_gain;
2190 if (libconf->rf.channel <= 14) {
2191 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_LNA);
2192 lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_BG);
2193 } else if (libconf->rf.channel <= 64) {
2194 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_LNA);
2195 lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_A0);
2196 } else if (libconf->rf.channel <= 128) {
2197 if (rt2x00_rt(rt2x00dev, RT3593)) {
2198 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_EXT_LNA2);
2199 lna_gain = rt2x00_get_field16(eeprom,
2200 EEPROM_EXT_LNA2_A1);
2201 } else {
2202 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2);
2203 lna_gain = rt2x00_get_field16(eeprom,
2204 EEPROM_RSSI_BG2_LNA_A1);
2206 } else {
2207 if (rt2x00_rt(rt2x00dev, RT3593)) {
2208 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_EXT_LNA2);
2209 lna_gain = rt2x00_get_field16(eeprom,
2210 EEPROM_EXT_LNA2_A2);
2211 } else {
2212 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A2);
2213 lna_gain = rt2x00_get_field16(eeprom,
2214 EEPROM_RSSI_A2_LNA_A2);
2218 rt2x00dev->lna_gain = lna_gain;
2221 static inline bool rt2800_clk_is_20mhz(struct rt2x00_dev *rt2x00dev)
2223 return clk_get_rate(rt2x00dev->clk) == 20000000;
2226 #define FREQ_OFFSET_BOUND 0x5f
2228 static void rt2800_freq_cal_mode1(struct rt2x00_dev *rt2x00dev)
2230 u8 freq_offset, prev_freq_offset;
2231 u8 rfcsr, prev_rfcsr;
2233 freq_offset = rt2x00_get_field8(rt2x00dev->freq_offset, RFCSR17_CODE);
2234 freq_offset = min_t(u8, freq_offset, FREQ_OFFSET_BOUND);
2236 rfcsr = rt2800_rfcsr_read(rt2x00dev, 17);
2237 prev_rfcsr = rfcsr;
2239 rt2x00_set_field8(&rfcsr, RFCSR17_CODE, freq_offset);
2240 if (rfcsr == prev_rfcsr)
2241 return;
2243 if (rt2x00_is_usb(rt2x00dev)) {
2244 rt2800_mcu_request(rt2x00dev, MCU_FREQ_OFFSET, 0xff,
2245 freq_offset, prev_rfcsr);
2246 return;
2249 prev_freq_offset = rt2x00_get_field8(prev_rfcsr, RFCSR17_CODE);
2250 while (prev_freq_offset != freq_offset) {
2251 if (prev_freq_offset < freq_offset)
2252 prev_freq_offset++;
2253 else
2254 prev_freq_offset--;
2256 rt2x00_set_field8(&rfcsr, RFCSR17_CODE, prev_freq_offset);
2257 rt2800_rfcsr_write(rt2x00dev, 17, rfcsr);
2259 usleep_range(1000, 1500);
2263 static void rt2800_config_channel_rf2xxx(struct rt2x00_dev *rt2x00dev,
2264 struct ieee80211_conf *conf,
2265 struct rf_channel *rf,
2266 struct channel_info *info)
2268 rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
2270 if (rt2x00dev->default_ant.tx_chain_num == 1)
2271 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_TX1, 1);
2273 if (rt2x00dev->default_ant.rx_chain_num == 1) {
2274 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX1, 1);
2275 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
2276 } else if (rt2x00dev->default_ant.rx_chain_num == 2)
2277 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
2279 if (rf->channel > 14) {
2281 * When TX power is below 0, we should increase it by 7 to
2282 * make it a positive value (Minimum value is -7).
2283 * However this means that values between 0 and 7 have
2284 * double meaning, and we should set a 7DBm boost flag.
2286 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A_7DBM_BOOST,
2287 (info->default_power1 >= 0));
2289 if (info->default_power1 < 0)
2290 info->default_power1 += 7;
2292 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A, info->default_power1);
2294 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A_7DBM_BOOST,
2295 (info->default_power2 >= 0));
2297 if (info->default_power2 < 0)
2298 info->default_power2 += 7;
2300 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A, info->default_power2);
2301 } else {
2302 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_G, info->default_power1);
2303 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_G, info->default_power2);
2306 rt2x00_set_field32(&rf->rf4, RF4_HT40, conf_is_ht40(conf));
2308 rt2800_rf_write(rt2x00dev, 1, rf->rf1);
2309 rt2800_rf_write(rt2x00dev, 2, rf->rf2);
2310 rt2800_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
2311 rt2800_rf_write(rt2x00dev, 4, rf->rf4);
2313 udelay(200);
2315 rt2800_rf_write(rt2x00dev, 1, rf->rf1);
2316 rt2800_rf_write(rt2x00dev, 2, rf->rf2);
2317 rt2800_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
2318 rt2800_rf_write(rt2x00dev, 4, rf->rf4);
2320 udelay(200);
2322 rt2800_rf_write(rt2x00dev, 1, rf->rf1);
2323 rt2800_rf_write(rt2x00dev, 2, rf->rf2);
2324 rt2800_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
2325 rt2800_rf_write(rt2x00dev, 4, rf->rf4);
2328 static void rt2800_config_channel_rf3xxx(struct rt2x00_dev *rt2x00dev,
2329 struct ieee80211_conf *conf,
2330 struct rf_channel *rf,
2331 struct channel_info *info)
2333 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
2334 u8 rfcsr, calib_tx, calib_rx;
2336 rt2800_rfcsr_write(rt2x00dev, 2, rf->rf1);
2338 rfcsr = rt2800_rfcsr_read(rt2x00dev, 3);
2339 rt2x00_set_field8(&rfcsr, RFCSR3_K, rf->rf3);
2340 rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
2342 rfcsr = rt2800_rfcsr_read(rt2x00dev, 6);
2343 rt2x00_set_field8(&rfcsr, RFCSR6_R1, rf->rf2);
2344 rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
2346 rfcsr = rt2800_rfcsr_read(rt2x00dev, 12);
2347 rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER, info->default_power1);
2348 rt2800_rfcsr_write(rt2x00dev, 12, rfcsr);
2350 rfcsr = rt2800_rfcsr_read(rt2x00dev, 13);
2351 rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER, info->default_power2);
2352 rt2800_rfcsr_write(rt2x00dev, 13, rfcsr);
2354 rfcsr = rt2800_rfcsr_read(rt2x00dev, 1);
2355 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0);
2356 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD,
2357 rt2x00dev->default_ant.rx_chain_num <= 1);
2358 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD,
2359 rt2x00dev->default_ant.rx_chain_num <= 2);
2360 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0);
2361 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD,
2362 rt2x00dev->default_ant.tx_chain_num <= 1);
2363 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD,
2364 rt2x00dev->default_ant.tx_chain_num <= 2);
2365 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
2367 rfcsr = rt2800_rfcsr_read(rt2x00dev, 23);
2368 rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset);
2369 rt2800_rfcsr_write(rt2x00dev, 23, rfcsr);
2371 if (rt2x00_rt(rt2x00dev, RT3390)) {
2372 calib_tx = conf_is_ht40(conf) ? 0x68 : 0x4f;
2373 calib_rx = conf_is_ht40(conf) ? 0x6f : 0x4f;
2374 } else {
2375 if (conf_is_ht40(conf)) {
2376 calib_tx = drv_data->calibration_bw40;
2377 calib_rx = drv_data->calibration_bw40;
2378 } else {
2379 calib_tx = drv_data->calibration_bw20;
2380 calib_rx = drv_data->calibration_bw20;
2384 rfcsr = rt2800_rfcsr_read(rt2x00dev, 24);
2385 rt2x00_set_field8(&rfcsr, RFCSR24_TX_CALIB, calib_tx);
2386 rt2800_rfcsr_write(rt2x00dev, 24, rfcsr);
2388 rfcsr = rt2800_rfcsr_read(rt2x00dev, 31);
2389 rt2x00_set_field8(&rfcsr, RFCSR31_RX_CALIB, calib_rx);
2390 rt2800_rfcsr_write(rt2x00dev, 31, rfcsr);
2392 rfcsr = rt2800_rfcsr_read(rt2x00dev, 7);
2393 rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
2394 rt2800_rfcsr_write(rt2x00dev, 7, rfcsr);
2396 rfcsr = rt2800_rfcsr_read(rt2x00dev, 30);
2397 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1);
2398 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
2400 usleep_range(1000, 1500);
2402 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0);
2403 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
2406 static void rt2800_config_channel_rf3052(struct rt2x00_dev *rt2x00dev,
2407 struct ieee80211_conf *conf,
2408 struct rf_channel *rf,
2409 struct channel_info *info)
2411 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
2412 u8 rfcsr;
2413 u32 reg;
2415 if (rf->channel <= 14) {
2416 rt2800_bbp_write(rt2x00dev, 25, drv_data->bbp25);
2417 rt2800_bbp_write(rt2x00dev, 26, drv_data->bbp26);
2418 } else {
2419 rt2800_bbp_write(rt2x00dev, 25, 0x09);
2420 rt2800_bbp_write(rt2x00dev, 26, 0xff);
2423 rt2800_rfcsr_write(rt2x00dev, 2, rf->rf1);
2424 rt2800_rfcsr_write(rt2x00dev, 3, rf->rf3);
2426 rfcsr = rt2800_rfcsr_read(rt2x00dev, 6);
2427 rt2x00_set_field8(&rfcsr, RFCSR6_R1, rf->rf2);
2428 if (rf->channel <= 14)
2429 rt2x00_set_field8(&rfcsr, RFCSR6_TXDIV, 2);
2430 else
2431 rt2x00_set_field8(&rfcsr, RFCSR6_TXDIV, 1);
2432 rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
2434 rfcsr = rt2800_rfcsr_read(rt2x00dev, 5);
2435 if (rf->channel <= 14)
2436 rt2x00_set_field8(&rfcsr, RFCSR5_R1, 1);
2437 else
2438 rt2x00_set_field8(&rfcsr, RFCSR5_R1, 2);
2439 rt2800_rfcsr_write(rt2x00dev, 5, rfcsr);
2441 rfcsr = rt2800_rfcsr_read(rt2x00dev, 12);
2442 if (rf->channel <= 14) {
2443 rt2x00_set_field8(&rfcsr, RFCSR12_DR0, 3);
2444 rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER,
2445 info->default_power1);
2446 } else {
2447 rt2x00_set_field8(&rfcsr, RFCSR12_DR0, 7);
2448 rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER,
2449 (info->default_power1 & 0x3) |
2450 ((info->default_power1 & 0xC) << 1));
2452 rt2800_rfcsr_write(rt2x00dev, 12, rfcsr);
2454 rfcsr = rt2800_rfcsr_read(rt2x00dev, 13);
2455 if (rf->channel <= 14) {
2456 rt2x00_set_field8(&rfcsr, RFCSR13_DR0, 3);
2457 rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER,
2458 info->default_power2);
2459 } else {
2460 rt2x00_set_field8(&rfcsr, RFCSR13_DR0, 7);
2461 rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER,
2462 (info->default_power2 & 0x3) |
2463 ((info->default_power2 & 0xC) << 1));
2465 rt2800_rfcsr_write(rt2x00dev, 13, rfcsr);
2467 rfcsr = rt2800_rfcsr_read(rt2x00dev, 1);
2468 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0);
2469 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0);
2470 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 0);
2471 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 0);
2472 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0);
2473 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0);
2474 if (rt2x00_has_cap_bt_coexist(rt2x00dev)) {
2475 if (rf->channel <= 14) {
2476 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1);
2477 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1);
2479 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 1);
2480 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 1);
2481 } else {
2482 switch (rt2x00dev->default_ant.tx_chain_num) {
2483 case 1:
2484 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
2485 /* fall through */
2486 case 2:
2487 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 1);
2488 break;
2491 switch (rt2x00dev->default_ant.rx_chain_num) {
2492 case 1:
2493 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
2494 /* fall through */
2495 case 2:
2496 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 1);
2497 break;
2500 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
2502 rfcsr = rt2800_rfcsr_read(rt2x00dev, 23);
2503 rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset);
2504 rt2800_rfcsr_write(rt2x00dev, 23, rfcsr);
2506 if (conf_is_ht40(conf)) {
2507 rt2800_rfcsr_write(rt2x00dev, 24, drv_data->calibration_bw40);
2508 rt2800_rfcsr_write(rt2x00dev, 31, drv_data->calibration_bw40);
2509 } else {
2510 rt2800_rfcsr_write(rt2x00dev, 24, drv_data->calibration_bw20);
2511 rt2800_rfcsr_write(rt2x00dev, 31, drv_data->calibration_bw20);
2514 if (rf->channel <= 14) {
2515 rt2800_rfcsr_write(rt2x00dev, 7, 0xd8);
2516 rt2800_rfcsr_write(rt2x00dev, 9, 0xc3);
2517 rt2800_rfcsr_write(rt2x00dev, 10, 0xf1);
2518 rt2800_rfcsr_write(rt2x00dev, 11, 0xb9);
2519 rt2800_rfcsr_write(rt2x00dev, 15, 0x53);
2520 rfcsr = 0x4c;
2521 rt2x00_set_field8(&rfcsr, RFCSR16_TXMIXER_GAIN,
2522 drv_data->txmixer_gain_24g);
2523 rt2800_rfcsr_write(rt2x00dev, 16, rfcsr);
2524 rt2800_rfcsr_write(rt2x00dev, 17, 0x23);
2525 rt2800_rfcsr_write(rt2x00dev, 19, 0x93);
2526 rt2800_rfcsr_write(rt2x00dev, 20, 0xb3);
2527 rt2800_rfcsr_write(rt2x00dev, 25, 0x15);
2528 rt2800_rfcsr_write(rt2x00dev, 26, 0x85);
2529 rt2800_rfcsr_write(rt2x00dev, 27, 0x00);
2530 rt2800_rfcsr_write(rt2x00dev, 29, 0x9b);
2531 } else {
2532 rfcsr = rt2800_rfcsr_read(rt2x00dev, 7);
2533 rt2x00_set_field8(&rfcsr, RFCSR7_BIT2, 1);
2534 rt2x00_set_field8(&rfcsr, RFCSR7_BIT3, 0);
2535 rt2x00_set_field8(&rfcsr, RFCSR7_BIT4, 1);
2536 rt2x00_set_field8(&rfcsr, RFCSR7_BITS67, 0);
2537 rt2800_rfcsr_write(rt2x00dev, 7, rfcsr);
2538 rt2800_rfcsr_write(rt2x00dev, 9, 0xc0);
2539 rt2800_rfcsr_write(rt2x00dev, 10, 0xf1);
2540 rt2800_rfcsr_write(rt2x00dev, 11, 0x00);
2541 rt2800_rfcsr_write(rt2x00dev, 15, 0x43);
2542 rfcsr = 0x7a;
2543 rt2x00_set_field8(&rfcsr, RFCSR16_TXMIXER_GAIN,
2544 drv_data->txmixer_gain_5g);
2545 rt2800_rfcsr_write(rt2x00dev, 16, rfcsr);
2546 rt2800_rfcsr_write(rt2x00dev, 17, 0x23);
2547 if (rf->channel <= 64) {
2548 rt2800_rfcsr_write(rt2x00dev, 19, 0xb7);
2549 rt2800_rfcsr_write(rt2x00dev, 20, 0xf6);
2550 rt2800_rfcsr_write(rt2x00dev, 25, 0x3d);
2551 } else if (rf->channel <= 128) {
2552 rt2800_rfcsr_write(rt2x00dev, 19, 0x74);
2553 rt2800_rfcsr_write(rt2x00dev, 20, 0xf4);
2554 rt2800_rfcsr_write(rt2x00dev, 25, 0x01);
2555 } else {
2556 rt2800_rfcsr_write(rt2x00dev, 19, 0x72);
2557 rt2800_rfcsr_write(rt2x00dev, 20, 0xf3);
2558 rt2800_rfcsr_write(rt2x00dev, 25, 0x01);
2560 rt2800_rfcsr_write(rt2x00dev, 26, 0x87);
2561 rt2800_rfcsr_write(rt2x00dev, 27, 0x01);
2562 rt2800_rfcsr_write(rt2x00dev, 29, 0x9f);
2565 reg = rt2800_register_read(rt2x00dev, GPIO_CTRL);
2566 rt2x00_set_field32(&reg, GPIO_CTRL_DIR7, 0);
2567 if (rf->channel <= 14)
2568 rt2x00_set_field32(&reg, GPIO_CTRL_VAL7, 1);
2569 else
2570 rt2x00_set_field32(&reg, GPIO_CTRL_VAL7, 0);
2571 rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
2573 rfcsr = rt2800_rfcsr_read(rt2x00dev, 7);
2574 rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
2575 rt2800_rfcsr_write(rt2x00dev, 7, rfcsr);
2578 static void rt2800_config_channel_rf3053(struct rt2x00_dev *rt2x00dev,
2579 struct ieee80211_conf *conf,
2580 struct rf_channel *rf,
2581 struct channel_info *info)
2583 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
2584 u8 txrx_agc_fc;
2585 u8 txrx_h20m;
2586 u8 rfcsr;
2587 u8 bbp;
2588 const bool txbf_enabled = false; /* TODO */
2590 /* TODO: use TX{0,1,2}FinePowerControl values from EEPROM */
2591 bbp = rt2800_bbp_read(rt2x00dev, 109);
2592 rt2x00_set_field8(&bbp, BBP109_TX0_POWER, 0);
2593 rt2x00_set_field8(&bbp, BBP109_TX1_POWER, 0);
2594 rt2800_bbp_write(rt2x00dev, 109, bbp);
2596 bbp = rt2800_bbp_read(rt2x00dev, 110);
2597 rt2x00_set_field8(&bbp, BBP110_TX2_POWER, 0);
2598 rt2800_bbp_write(rt2x00dev, 110, bbp);
2600 if (rf->channel <= 14) {
2601 /* Restore BBP 25 & 26 for 2.4 GHz */
2602 rt2800_bbp_write(rt2x00dev, 25, drv_data->bbp25);
2603 rt2800_bbp_write(rt2x00dev, 26, drv_data->bbp26);
2604 } else {
2605 /* Hard code BBP 25 & 26 for 5GHz */
2607 /* Enable IQ Phase correction */
2608 rt2800_bbp_write(rt2x00dev, 25, 0x09);
2609 /* Setup IQ Phase correction value */
2610 rt2800_bbp_write(rt2x00dev, 26, 0xff);
2613 rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1);
2614 rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3 & 0xf);
2616 rfcsr = rt2800_rfcsr_read(rt2x00dev, 11);
2617 rt2x00_set_field8(&rfcsr, RFCSR11_R, (rf->rf2 & 0x3));
2618 rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
2620 rfcsr = rt2800_rfcsr_read(rt2x00dev, 11);
2621 rt2x00_set_field8(&rfcsr, RFCSR11_PLL_IDOH, 1);
2622 if (rf->channel <= 14)
2623 rt2x00_set_field8(&rfcsr, RFCSR11_PLL_MOD, 1);
2624 else
2625 rt2x00_set_field8(&rfcsr, RFCSR11_PLL_MOD, 2);
2626 rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
2628 rfcsr = rt2800_rfcsr_read(rt2x00dev, 53);
2629 if (rf->channel <= 14) {
2630 rfcsr = 0;
2631 rt2x00_set_field8(&rfcsr, RFCSR53_TX_POWER,
2632 info->default_power1 & 0x1f);
2633 } else {
2634 if (rt2x00_is_usb(rt2x00dev))
2635 rfcsr = 0x40;
2637 rt2x00_set_field8(&rfcsr, RFCSR53_TX_POWER,
2638 ((info->default_power1 & 0x18) << 1) |
2639 (info->default_power1 & 7));
2641 rt2800_rfcsr_write(rt2x00dev, 53, rfcsr);
2643 rfcsr = rt2800_rfcsr_read(rt2x00dev, 55);
2644 if (rf->channel <= 14) {
2645 rfcsr = 0;
2646 rt2x00_set_field8(&rfcsr, RFCSR55_TX_POWER,
2647 info->default_power2 & 0x1f);
2648 } else {
2649 if (rt2x00_is_usb(rt2x00dev))
2650 rfcsr = 0x40;
2652 rt2x00_set_field8(&rfcsr, RFCSR55_TX_POWER,
2653 ((info->default_power2 & 0x18) << 1) |
2654 (info->default_power2 & 7));
2656 rt2800_rfcsr_write(rt2x00dev, 55, rfcsr);
2658 rfcsr = rt2800_rfcsr_read(rt2x00dev, 54);
2659 if (rf->channel <= 14) {
2660 rfcsr = 0;
2661 rt2x00_set_field8(&rfcsr, RFCSR54_TX_POWER,
2662 info->default_power3 & 0x1f);
2663 } else {
2664 if (rt2x00_is_usb(rt2x00dev))
2665 rfcsr = 0x40;
2667 rt2x00_set_field8(&rfcsr, RFCSR54_TX_POWER,
2668 ((info->default_power3 & 0x18) << 1) |
2669 (info->default_power3 & 7));
2671 rt2800_rfcsr_write(rt2x00dev, 54, rfcsr);
2673 rfcsr = rt2800_rfcsr_read(rt2x00dev, 1);
2674 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0);
2675 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0);
2676 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 0);
2677 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 0);
2678 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0);
2679 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0);
2680 rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
2681 rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1);
2683 switch (rt2x00dev->default_ant.tx_chain_num) {
2684 case 3:
2685 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 1);
2686 /* fallthrough */
2687 case 2:
2688 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
2689 /* fallthrough */
2690 case 1:
2691 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1);
2692 break;
2695 switch (rt2x00dev->default_ant.rx_chain_num) {
2696 case 3:
2697 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 1);
2698 /* fallthrough */
2699 case 2:
2700 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
2701 /* fallthrough */
2702 case 1:
2703 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1);
2704 break;
2706 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
2708 rt2800_freq_cal_mode1(rt2x00dev);
2710 if (conf_is_ht40(conf)) {
2711 txrx_agc_fc = rt2x00_get_field8(drv_data->calibration_bw40,
2712 RFCSR24_TX_AGC_FC);
2713 txrx_h20m = rt2x00_get_field8(drv_data->calibration_bw40,
2714 RFCSR24_TX_H20M);
2715 } else {
2716 txrx_agc_fc = rt2x00_get_field8(drv_data->calibration_bw20,
2717 RFCSR24_TX_AGC_FC);
2718 txrx_h20m = rt2x00_get_field8(drv_data->calibration_bw20,
2719 RFCSR24_TX_H20M);
2722 /* NOTE: the reference driver does not writes the new value
2723 * back to RFCSR 32
2725 rfcsr = rt2800_rfcsr_read(rt2x00dev, 32);
2726 rt2x00_set_field8(&rfcsr, RFCSR32_TX_AGC_FC, txrx_agc_fc);
2728 if (rf->channel <= 14)
2729 rfcsr = 0xa0;
2730 else
2731 rfcsr = 0x80;
2732 rt2800_rfcsr_write(rt2x00dev, 31, rfcsr);
2734 rfcsr = rt2800_rfcsr_read(rt2x00dev, 30);
2735 rt2x00_set_field8(&rfcsr, RFCSR30_TX_H20M, txrx_h20m);
2736 rt2x00_set_field8(&rfcsr, RFCSR30_RX_H20M, txrx_h20m);
2737 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
2739 /* Band selection */
2740 rfcsr = rt2800_rfcsr_read(rt2x00dev, 36);
2741 if (rf->channel <= 14)
2742 rt2x00_set_field8(&rfcsr, RFCSR36_RF_BS, 1);
2743 else
2744 rt2x00_set_field8(&rfcsr, RFCSR36_RF_BS, 0);
2745 rt2800_rfcsr_write(rt2x00dev, 36, rfcsr);
2747 rfcsr = rt2800_rfcsr_read(rt2x00dev, 34);
2748 if (rf->channel <= 14)
2749 rfcsr = 0x3c;
2750 else
2751 rfcsr = 0x20;
2752 rt2800_rfcsr_write(rt2x00dev, 34, rfcsr);
2754 rfcsr = rt2800_rfcsr_read(rt2x00dev, 12);
2755 if (rf->channel <= 14)
2756 rfcsr = 0x1a;
2757 else
2758 rfcsr = 0x12;
2759 rt2800_rfcsr_write(rt2x00dev, 12, rfcsr);
2761 rfcsr = rt2800_rfcsr_read(rt2x00dev, 6);
2762 if (rf->channel >= 1 && rf->channel <= 14)
2763 rt2x00_set_field8(&rfcsr, RFCSR6_VCO_IC, 1);
2764 else if (rf->channel >= 36 && rf->channel <= 64)
2765 rt2x00_set_field8(&rfcsr, RFCSR6_VCO_IC, 2);
2766 else if (rf->channel >= 100 && rf->channel <= 128)
2767 rt2x00_set_field8(&rfcsr, RFCSR6_VCO_IC, 2);
2768 else
2769 rt2x00_set_field8(&rfcsr, RFCSR6_VCO_IC, 1);
2770 rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
2772 rfcsr = rt2800_rfcsr_read(rt2x00dev, 30);
2773 rt2x00_set_field8(&rfcsr, RFCSR30_RX_VCM, 2);
2774 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
2776 rt2800_rfcsr_write(rt2x00dev, 46, 0x60);
2778 if (rf->channel <= 14) {
2779 rt2800_rfcsr_write(rt2x00dev, 10, 0xd3);
2780 rt2800_rfcsr_write(rt2x00dev, 13, 0x12);
2781 } else {
2782 rt2800_rfcsr_write(rt2x00dev, 10, 0xd8);
2783 rt2800_rfcsr_write(rt2x00dev, 13, 0x23);
2786 rfcsr = rt2800_rfcsr_read(rt2x00dev, 51);
2787 rt2x00_set_field8(&rfcsr, RFCSR51_BITS01, 1);
2788 rt2800_rfcsr_write(rt2x00dev, 51, rfcsr);
2790 rfcsr = rt2800_rfcsr_read(rt2x00dev, 51);
2791 if (rf->channel <= 14) {
2792 rt2x00_set_field8(&rfcsr, RFCSR51_BITS24, 5);
2793 rt2x00_set_field8(&rfcsr, RFCSR51_BITS57, 3);
2794 } else {
2795 rt2x00_set_field8(&rfcsr, RFCSR51_BITS24, 4);
2796 rt2x00_set_field8(&rfcsr, RFCSR51_BITS57, 2);
2798 rt2800_rfcsr_write(rt2x00dev, 51, rfcsr);
2800 rfcsr = rt2800_rfcsr_read(rt2x00dev, 49);
2801 if (rf->channel <= 14)
2802 rt2x00_set_field8(&rfcsr, RFCSR49_TX_LO1_IC, 3);
2803 else
2804 rt2x00_set_field8(&rfcsr, RFCSR49_TX_LO1_IC, 2);
2806 if (txbf_enabled)
2807 rt2x00_set_field8(&rfcsr, RFCSR49_TX_DIV, 1);
2809 rt2800_rfcsr_write(rt2x00dev, 49, rfcsr);
2811 rfcsr = rt2800_rfcsr_read(rt2x00dev, 50);
2812 rt2x00_set_field8(&rfcsr, RFCSR50_TX_LO1_EN, 0);
2813 rt2800_rfcsr_write(rt2x00dev, 50, rfcsr);
2815 rfcsr = rt2800_rfcsr_read(rt2x00dev, 57);
2816 if (rf->channel <= 14)
2817 rt2x00_set_field8(&rfcsr, RFCSR57_DRV_CC, 0x1b);
2818 else
2819 rt2x00_set_field8(&rfcsr, RFCSR57_DRV_CC, 0x0f);
2820 rt2800_rfcsr_write(rt2x00dev, 57, rfcsr);
2822 if (rf->channel <= 14) {
2823 rt2800_rfcsr_write(rt2x00dev, 44, 0x93);
2824 rt2800_rfcsr_write(rt2x00dev, 52, 0x45);
2825 } else {
2826 rt2800_rfcsr_write(rt2x00dev, 44, 0x9b);
2827 rt2800_rfcsr_write(rt2x00dev, 52, 0x05);
2830 /* Initiate VCO calibration */
2831 rfcsr = rt2800_rfcsr_read(rt2x00dev, 3);
2832 if (rf->channel <= 14) {
2833 rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
2834 } else {
2835 rt2x00_set_field8(&rfcsr, RFCSR3_BIT1, 1);
2836 rt2x00_set_field8(&rfcsr, RFCSR3_BIT2, 1);
2837 rt2x00_set_field8(&rfcsr, RFCSR3_BIT3, 1);
2838 rt2x00_set_field8(&rfcsr, RFCSR3_BIT4, 1);
2839 rt2x00_set_field8(&rfcsr, RFCSR3_BIT5, 1);
2840 rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
2842 rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
2844 if (rf->channel >= 1 && rf->channel <= 14) {
2845 rfcsr = 0x23;
2846 if (txbf_enabled)
2847 rt2x00_set_field8(&rfcsr, RFCSR39_RX_DIV, 1);
2848 rt2800_rfcsr_write(rt2x00dev, 39, rfcsr);
2850 rt2800_rfcsr_write(rt2x00dev, 45, 0xbb);
2851 } else if (rf->channel >= 36 && rf->channel <= 64) {
2852 rfcsr = 0x36;
2853 if (txbf_enabled)
2854 rt2x00_set_field8(&rfcsr, RFCSR39_RX_DIV, 1);
2855 rt2800_rfcsr_write(rt2x00dev, 39, 0x36);
2857 rt2800_rfcsr_write(rt2x00dev, 45, 0xeb);
2858 } else if (rf->channel >= 100 && rf->channel <= 128) {
2859 rfcsr = 0x32;
2860 if (txbf_enabled)
2861 rt2x00_set_field8(&rfcsr, RFCSR39_RX_DIV, 1);
2862 rt2800_rfcsr_write(rt2x00dev, 39, rfcsr);
2864 rt2800_rfcsr_write(rt2x00dev, 45, 0xb3);
2865 } else {
2866 rfcsr = 0x30;
2867 if (txbf_enabled)
2868 rt2x00_set_field8(&rfcsr, RFCSR39_RX_DIV, 1);
2869 rt2800_rfcsr_write(rt2x00dev, 39, rfcsr);
2871 rt2800_rfcsr_write(rt2x00dev, 45, 0x9b);
2875 #define POWER_BOUND 0x27
2876 #define POWER_BOUND_5G 0x2b
2878 static void rt2800_config_channel_rf3290(struct rt2x00_dev *rt2x00dev,
2879 struct ieee80211_conf *conf,
2880 struct rf_channel *rf,
2881 struct channel_info *info)
2883 u8 rfcsr;
2885 rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1);
2886 rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3);
2887 rfcsr = rt2800_rfcsr_read(rt2x00dev, 11);
2888 rt2x00_set_field8(&rfcsr, RFCSR11_R, rf->rf2);
2889 rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
2891 rfcsr = rt2800_rfcsr_read(rt2x00dev, 49);
2892 if (info->default_power1 > POWER_BOUND)
2893 rt2x00_set_field8(&rfcsr, RFCSR49_TX, POWER_BOUND);
2894 else
2895 rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1);
2896 rt2800_rfcsr_write(rt2x00dev, 49, rfcsr);
2898 rt2800_freq_cal_mode1(rt2x00dev);
2900 if (rf->channel <= 14) {
2901 if (rf->channel == 6)
2902 rt2800_bbp_write(rt2x00dev, 68, 0x0c);
2903 else
2904 rt2800_bbp_write(rt2x00dev, 68, 0x0b);
2906 if (rf->channel >= 1 && rf->channel <= 6)
2907 rt2800_bbp_write(rt2x00dev, 59, 0x0f);
2908 else if (rf->channel >= 7 && rf->channel <= 11)
2909 rt2800_bbp_write(rt2x00dev, 59, 0x0e);
2910 else if (rf->channel >= 12 && rf->channel <= 14)
2911 rt2800_bbp_write(rt2x00dev, 59, 0x0d);
2915 static void rt2800_config_channel_rf3322(struct rt2x00_dev *rt2x00dev,
2916 struct ieee80211_conf *conf,
2917 struct rf_channel *rf,
2918 struct channel_info *info)
2920 u8 rfcsr;
2922 rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1);
2923 rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3);
2925 rt2800_rfcsr_write(rt2x00dev, 11, 0x42);
2926 rt2800_rfcsr_write(rt2x00dev, 12, 0x1c);
2927 rt2800_rfcsr_write(rt2x00dev, 13, 0x00);
2929 if (info->default_power1 > POWER_BOUND)
2930 rt2800_rfcsr_write(rt2x00dev, 47, POWER_BOUND);
2931 else
2932 rt2800_rfcsr_write(rt2x00dev, 47, info->default_power1);
2934 if (info->default_power2 > POWER_BOUND)
2935 rt2800_rfcsr_write(rt2x00dev, 48, POWER_BOUND);
2936 else
2937 rt2800_rfcsr_write(rt2x00dev, 48, info->default_power2);
2939 rt2800_freq_cal_mode1(rt2x00dev);
2941 rfcsr = rt2800_rfcsr_read(rt2x00dev, 1);
2942 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1);
2943 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1);
2945 if ( rt2x00dev->default_ant.tx_chain_num == 2 )
2946 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
2947 else
2948 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 0);
2950 if ( rt2x00dev->default_ant.rx_chain_num == 2 )
2951 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
2952 else
2953 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 0);
2955 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0);
2956 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0);
2958 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
2960 rt2800_rfcsr_write(rt2x00dev, 31, 80);
2963 static void rt2800_config_channel_rf53xx(struct rt2x00_dev *rt2x00dev,
2964 struct ieee80211_conf *conf,
2965 struct rf_channel *rf,
2966 struct channel_info *info)
2968 u8 rfcsr;
2969 int idx = rf->channel-1;
2971 rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1);
2972 rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3);
2973 rfcsr = rt2800_rfcsr_read(rt2x00dev, 11);
2974 rt2x00_set_field8(&rfcsr, RFCSR11_R, rf->rf2);
2975 rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
2977 rfcsr = rt2800_rfcsr_read(rt2x00dev, 49);
2978 if (info->default_power1 > POWER_BOUND)
2979 rt2x00_set_field8(&rfcsr, RFCSR49_TX, POWER_BOUND);
2980 else
2981 rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1);
2982 rt2800_rfcsr_write(rt2x00dev, 49, rfcsr);
2984 if (rt2x00_rt(rt2x00dev, RT5392)) {
2985 rfcsr = rt2800_rfcsr_read(rt2x00dev, 50);
2986 if (info->default_power2 > POWER_BOUND)
2987 rt2x00_set_field8(&rfcsr, RFCSR50_TX, POWER_BOUND);
2988 else
2989 rt2x00_set_field8(&rfcsr, RFCSR50_TX,
2990 info->default_power2);
2991 rt2800_rfcsr_write(rt2x00dev, 50, rfcsr);
2994 rfcsr = rt2800_rfcsr_read(rt2x00dev, 1);
2995 if (rt2x00_rt(rt2x00dev, RT5392)) {
2996 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
2997 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
2999 rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
3000 rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1);
3001 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1);
3002 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1);
3003 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
3005 rt2800_freq_cal_mode1(rt2x00dev);
3007 if (rt2x00_has_cap_bt_coexist(rt2x00dev)) {
3008 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) {
3009 /* r55/r59 value array of channel 1~14 */
3010 static const char r55_bt_rev[] = {0x83, 0x83,
3011 0x83, 0x73, 0x73, 0x63, 0x53, 0x53,
3012 0x53, 0x43, 0x43, 0x43, 0x43, 0x43};
3013 static const char r59_bt_rev[] = {0x0e, 0x0e,
3014 0x0e, 0x0e, 0x0e, 0x0b, 0x0a, 0x09,
3015 0x07, 0x07, 0x07, 0x07, 0x07, 0x07};
3017 rt2800_rfcsr_write(rt2x00dev, 55,
3018 r55_bt_rev[idx]);
3019 rt2800_rfcsr_write(rt2x00dev, 59,
3020 r59_bt_rev[idx]);
3021 } else {
3022 static const char r59_bt[] = {0x8b, 0x8b, 0x8b,
3023 0x8b, 0x8b, 0x8b, 0x8b, 0x8a, 0x89,
3024 0x88, 0x88, 0x86, 0x85, 0x84};
3026 rt2800_rfcsr_write(rt2x00dev, 59, r59_bt[idx]);
3028 } else {
3029 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) {
3030 static const char r55_nonbt_rev[] = {0x23, 0x23,
3031 0x23, 0x23, 0x13, 0x13, 0x03, 0x03,
3032 0x03, 0x03, 0x03, 0x03, 0x03, 0x03};
3033 static const char r59_nonbt_rev[] = {0x07, 0x07,
3034 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
3035 0x07, 0x07, 0x06, 0x05, 0x04, 0x04};
3037 rt2800_rfcsr_write(rt2x00dev, 55,
3038 r55_nonbt_rev[idx]);
3039 rt2800_rfcsr_write(rt2x00dev, 59,
3040 r59_nonbt_rev[idx]);
3041 } else if (rt2x00_rt(rt2x00dev, RT5390) ||
3042 rt2x00_rt(rt2x00dev, RT5392) ||
3043 rt2x00_rt(rt2x00dev, RT6352)) {
3044 static const char r59_non_bt[] = {0x8f, 0x8f,
3045 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8d,
3046 0x8a, 0x88, 0x88, 0x87, 0x87, 0x86};
3048 rt2800_rfcsr_write(rt2x00dev, 59,
3049 r59_non_bt[idx]);
3050 } else if (rt2x00_rt(rt2x00dev, RT5350)) {
3051 static const char r59_non_bt[] = {0x0b, 0x0b,
3052 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0a,
3053 0x0a, 0x09, 0x08, 0x07, 0x07, 0x06};
3055 rt2800_rfcsr_write(rt2x00dev, 59,
3056 r59_non_bt[idx]);
3061 static void rt2800_config_channel_rf55xx(struct rt2x00_dev *rt2x00dev,
3062 struct ieee80211_conf *conf,
3063 struct rf_channel *rf,
3064 struct channel_info *info)
3066 u8 rfcsr, ep_reg;
3067 u32 reg;
3068 int power_bound;
3070 /* TODO */
3071 const bool is_11b = false;
3072 const bool is_type_ep = false;
3074 reg = rt2800_register_read(rt2x00dev, LDO_CFG0);
3075 rt2x00_set_field32(&reg, LDO_CFG0_LDO_CORE_VLEVEL,
3076 (rf->channel > 14 || conf_is_ht40(conf)) ? 5 : 0);
3077 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
3079 /* Order of values on rf_channel entry: N, K, mod, R */
3080 rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1 & 0xff);
3082 rfcsr = rt2800_rfcsr_read(rt2x00dev, 9);
3083 rt2x00_set_field8(&rfcsr, RFCSR9_K, rf->rf2 & 0xf);
3084 rt2x00_set_field8(&rfcsr, RFCSR9_N, (rf->rf1 & 0x100) >> 8);
3085 rt2x00_set_field8(&rfcsr, RFCSR9_MOD, ((rf->rf3 - 8) & 0x4) >> 2);
3086 rt2800_rfcsr_write(rt2x00dev, 9, rfcsr);
3088 rfcsr = rt2800_rfcsr_read(rt2x00dev, 11);
3089 rt2x00_set_field8(&rfcsr, RFCSR11_R, rf->rf4 - 1);
3090 rt2x00_set_field8(&rfcsr, RFCSR11_MOD, (rf->rf3 - 8) & 0x3);
3091 rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
3093 if (rf->channel <= 14) {
3094 rt2800_rfcsr_write(rt2x00dev, 10, 0x90);
3095 /* FIXME: RF11 owerwrite ? */
3096 rt2800_rfcsr_write(rt2x00dev, 11, 0x4A);
3097 rt2800_rfcsr_write(rt2x00dev, 12, 0x52);
3098 rt2800_rfcsr_write(rt2x00dev, 13, 0x42);
3099 rt2800_rfcsr_write(rt2x00dev, 22, 0x40);
3100 rt2800_rfcsr_write(rt2x00dev, 24, 0x4A);
3101 rt2800_rfcsr_write(rt2x00dev, 25, 0x80);
3102 rt2800_rfcsr_write(rt2x00dev, 27, 0x42);
3103 rt2800_rfcsr_write(rt2x00dev, 36, 0x80);
3104 rt2800_rfcsr_write(rt2x00dev, 37, 0x08);
3105 rt2800_rfcsr_write(rt2x00dev, 38, 0x89);
3106 rt2800_rfcsr_write(rt2x00dev, 39, 0x1B);
3107 rt2800_rfcsr_write(rt2x00dev, 40, 0x0D);
3108 rt2800_rfcsr_write(rt2x00dev, 41, 0x9B);
3109 rt2800_rfcsr_write(rt2x00dev, 42, 0xD5);
3110 rt2800_rfcsr_write(rt2x00dev, 43, 0x72);
3111 rt2800_rfcsr_write(rt2x00dev, 44, 0x0E);
3112 rt2800_rfcsr_write(rt2x00dev, 45, 0xA2);
3113 rt2800_rfcsr_write(rt2x00dev, 46, 0x6B);
3114 rt2800_rfcsr_write(rt2x00dev, 48, 0x10);
3115 rt2800_rfcsr_write(rt2x00dev, 51, 0x3E);
3116 rt2800_rfcsr_write(rt2x00dev, 52, 0x48);
3117 rt2800_rfcsr_write(rt2x00dev, 54, 0x38);
3118 rt2800_rfcsr_write(rt2x00dev, 56, 0xA1);
3119 rt2800_rfcsr_write(rt2x00dev, 57, 0x00);
3120 rt2800_rfcsr_write(rt2x00dev, 58, 0x39);
3121 rt2800_rfcsr_write(rt2x00dev, 60, 0x45);
3122 rt2800_rfcsr_write(rt2x00dev, 61, 0x91);
3123 rt2800_rfcsr_write(rt2x00dev, 62, 0x39);
3125 /* TODO RF27 <- tssi */
3127 rfcsr = rf->channel <= 10 ? 0x07 : 0x06;
3128 rt2800_rfcsr_write(rt2x00dev, 23, rfcsr);
3129 rt2800_rfcsr_write(rt2x00dev, 59, rfcsr);
3131 if (is_11b) {
3132 /* CCK */
3133 rt2800_rfcsr_write(rt2x00dev, 31, 0xF8);
3134 rt2800_rfcsr_write(rt2x00dev, 32, 0xC0);
3135 if (is_type_ep)
3136 rt2800_rfcsr_write(rt2x00dev, 55, 0x06);
3137 else
3138 rt2800_rfcsr_write(rt2x00dev, 55, 0x47);
3139 } else {
3140 /* OFDM */
3141 if (is_type_ep)
3142 rt2800_rfcsr_write(rt2x00dev, 55, 0x03);
3143 else
3144 rt2800_rfcsr_write(rt2x00dev, 55, 0x43);
3147 power_bound = POWER_BOUND;
3148 ep_reg = 0x2;
3149 } else {
3150 rt2800_rfcsr_write(rt2x00dev, 10, 0x97);
3151 /* FIMXE: RF11 overwrite */
3152 rt2800_rfcsr_write(rt2x00dev, 11, 0x40);
3153 rt2800_rfcsr_write(rt2x00dev, 25, 0xBF);
3154 rt2800_rfcsr_write(rt2x00dev, 27, 0x42);
3155 rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
3156 rt2800_rfcsr_write(rt2x00dev, 37, 0x04);
3157 rt2800_rfcsr_write(rt2x00dev, 38, 0x85);
3158 rt2800_rfcsr_write(rt2x00dev, 40, 0x42);
3159 rt2800_rfcsr_write(rt2x00dev, 41, 0xBB);
3160 rt2800_rfcsr_write(rt2x00dev, 42, 0xD7);
3161 rt2800_rfcsr_write(rt2x00dev, 45, 0x41);
3162 rt2800_rfcsr_write(rt2x00dev, 48, 0x00);
3163 rt2800_rfcsr_write(rt2x00dev, 57, 0x77);
3164 rt2800_rfcsr_write(rt2x00dev, 60, 0x05);
3165 rt2800_rfcsr_write(rt2x00dev, 61, 0x01);
3167 /* TODO RF27 <- tssi */
3169 if (rf->channel >= 36 && rf->channel <= 64) {
3171 rt2800_rfcsr_write(rt2x00dev, 12, 0x2E);
3172 rt2800_rfcsr_write(rt2x00dev, 13, 0x22);
3173 rt2800_rfcsr_write(rt2x00dev, 22, 0x60);
3174 rt2800_rfcsr_write(rt2x00dev, 23, 0x7F);
3175 if (rf->channel <= 50)
3176 rt2800_rfcsr_write(rt2x00dev, 24, 0x09);
3177 else if (rf->channel >= 52)
3178 rt2800_rfcsr_write(rt2x00dev, 24, 0x07);
3179 rt2800_rfcsr_write(rt2x00dev, 39, 0x1C);
3180 rt2800_rfcsr_write(rt2x00dev, 43, 0x5B);
3181 rt2800_rfcsr_write(rt2x00dev, 44, 0X40);
3182 rt2800_rfcsr_write(rt2x00dev, 46, 0X00);
3183 rt2800_rfcsr_write(rt2x00dev, 51, 0xFE);
3184 rt2800_rfcsr_write(rt2x00dev, 52, 0x0C);
3185 rt2800_rfcsr_write(rt2x00dev, 54, 0xF8);
3186 if (rf->channel <= 50) {
3187 rt2800_rfcsr_write(rt2x00dev, 55, 0x06),
3188 rt2800_rfcsr_write(rt2x00dev, 56, 0xD3);
3189 } else if (rf->channel >= 52) {
3190 rt2800_rfcsr_write(rt2x00dev, 55, 0x04);
3191 rt2800_rfcsr_write(rt2x00dev, 56, 0xBB);
3194 rt2800_rfcsr_write(rt2x00dev, 58, 0x15);
3195 rt2800_rfcsr_write(rt2x00dev, 59, 0x7F);
3196 rt2800_rfcsr_write(rt2x00dev, 62, 0x15);
3198 } else if (rf->channel >= 100 && rf->channel <= 165) {
3200 rt2800_rfcsr_write(rt2x00dev, 12, 0x0E);
3201 rt2800_rfcsr_write(rt2x00dev, 13, 0x42);
3202 rt2800_rfcsr_write(rt2x00dev, 22, 0x40);
3203 if (rf->channel <= 153) {
3204 rt2800_rfcsr_write(rt2x00dev, 23, 0x3C);
3205 rt2800_rfcsr_write(rt2x00dev, 24, 0x06);
3206 } else if (rf->channel >= 155) {
3207 rt2800_rfcsr_write(rt2x00dev, 23, 0x38);
3208 rt2800_rfcsr_write(rt2x00dev, 24, 0x05);
3210 if (rf->channel <= 138) {
3211 rt2800_rfcsr_write(rt2x00dev, 39, 0x1A);
3212 rt2800_rfcsr_write(rt2x00dev, 43, 0x3B);
3213 rt2800_rfcsr_write(rt2x00dev, 44, 0x20);
3214 rt2800_rfcsr_write(rt2x00dev, 46, 0x18);
3215 } else if (rf->channel >= 140) {
3216 rt2800_rfcsr_write(rt2x00dev, 39, 0x18);
3217 rt2800_rfcsr_write(rt2x00dev, 43, 0x1B);
3218 rt2800_rfcsr_write(rt2x00dev, 44, 0x10);
3219 rt2800_rfcsr_write(rt2x00dev, 46, 0X08);
3221 if (rf->channel <= 124)
3222 rt2800_rfcsr_write(rt2x00dev, 51, 0xFC);
3223 else if (rf->channel >= 126)
3224 rt2800_rfcsr_write(rt2x00dev, 51, 0xEC);
3225 if (rf->channel <= 138)
3226 rt2800_rfcsr_write(rt2x00dev, 52, 0x06);
3227 else if (rf->channel >= 140)
3228 rt2800_rfcsr_write(rt2x00dev, 52, 0x06);
3229 rt2800_rfcsr_write(rt2x00dev, 54, 0xEB);
3230 if (rf->channel <= 138)
3231 rt2800_rfcsr_write(rt2x00dev, 55, 0x01);
3232 else if (rf->channel >= 140)
3233 rt2800_rfcsr_write(rt2x00dev, 55, 0x00);
3234 if (rf->channel <= 128)
3235 rt2800_rfcsr_write(rt2x00dev, 56, 0xBB);
3236 else if (rf->channel >= 130)
3237 rt2800_rfcsr_write(rt2x00dev, 56, 0xAB);
3238 if (rf->channel <= 116)
3239 rt2800_rfcsr_write(rt2x00dev, 58, 0x1D);
3240 else if (rf->channel >= 118)
3241 rt2800_rfcsr_write(rt2x00dev, 58, 0x15);
3242 if (rf->channel <= 138)
3243 rt2800_rfcsr_write(rt2x00dev, 59, 0x3F);
3244 else if (rf->channel >= 140)
3245 rt2800_rfcsr_write(rt2x00dev, 59, 0x7C);
3246 if (rf->channel <= 116)
3247 rt2800_rfcsr_write(rt2x00dev, 62, 0x1D);
3248 else if (rf->channel >= 118)
3249 rt2800_rfcsr_write(rt2x00dev, 62, 0x15);
3252 power_bound = POWER_BOUND_5G;
3253 ep_reg = 0x3;
3256 rfcsr = rt2800_rfcsr_read(rt2x00dev, 49);
3257 if (info->default_power1 > power_bound)
3258 rt2x00_set_field8(&rfcsr, RFCSR49_TX, power_bound);
3259 else
3260 rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1);
3261 if (is_type_ep)
3262 rt2x00_set_field8(&rfcsr, RFCSR49_EP, ep_reg);
3263 rt2800_rfcsr_write(rt2x00dev, 49, rfcsr);
3265 rfcsr = rt2800_rfcsr_read(rt2x00dev, 50);
3266 if (info->default_power2 > power_bound)
3267 rt2x00_set_field8(&rfcsr, RFCSR50_TX, power_bound);
3268 else
3269 rt2x00_set_field8(&rfcsr, RFCSR50_TX, info->default_power2);
3270 if (is_type_ep)
3271 rt2x00_set_field8(&rfcsr, RFCSR50_EP, ep_reg);
3272 rt2800_rfcsr_write(rt2x00dev, 50, rfcsr);
3274 rfcsr = rt2800_rfcsr_read(rt2x00dev, 1);
3275 rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
3276 rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1);
3278 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD,
3279 rt2x00dev->default_ant.tx_chain_num >= 1);
3280 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD,
3281 rt2x00dev->default_ant.tx_chain_num == 2);
3282 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0);
3284 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD,
3285 rt2x00dev->default_ant.rx_chain_num >= 1);
3286 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD,
3287 rt2x00dev->default_ant.rx_chain_num == 2);
3288 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0);
3290 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
3291 rt2800_rfcsr_write(rt2x00dev, 6, 0xe4);
3293 if (conf_is_ht40(conf))
3294 rt2800_rfcsr_write(rt2x00dev, 30, 0x16);
3295 else
3296 rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
3298 if (!is_11b) {
3299 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
3300 rt2800_rfcsr_write(rt2x00dev, 32, 0x80);
3303 /* TODO proper frequency adjustment */
3304 rt2800_freq_cal_mode1(rt2x00dev);
3306 /* TODO merge with others */
3307 rfcsr = rt2800_rfcsr_read(rt2x00dev, 3);
3308 rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
3309 rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
3311 /* BBP settings */
3312 rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
3313 rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
3314 rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
3316 rt2800_bbp_write(rt2x00dev, 79, (rf->channel <= 14) ? 0x1C : 0x18);
3317 rt2800_bbp_write(rt2x00dev, 80, (rf->channel <= 14) ? 0x0E : 0x08);
3318 rt2800_bbp_write(rt2x00dev, 81, (rf->channel <= 14) ? 0x3A : 0x38);
3319 rt2800_bbp_write(rt2x00dev, 82, (rf->channel <= 14) ? 0x62 : 0x92);
3321 /* GLRT band configuration */
3322 rt2800_bbp_write(rt2x00dev, 195, 128);
3323 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0xE0 : 0xF0);
3324 rt2800_bbp_write(rt2x00dev, 195, 129);
3325 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x1F : 0x1E);
3326 rt2800_bbp_write(rt2x00dev, 195, 130);
3327 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x38 : 0x28);
3328 rt2800_bbp_write(rt2x00dev, 195, 131);
3329 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x32 : 0x20);
3330 rt2800_bbp_write(rt2x00dev, 195, 133);
3331 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x28 : 0x7F);
3332 rt2800_bbp_write(rt2x00dev, 195, 124);
3333 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x19 : 0x7F);
3336 static void rt2800_config_channel_rf7620(struct rt2x00_dev *rt2x00dev,
3337 struct ieee80211_conf *conf,
3338 struct rf_channel *rf,
3339 struct channel_info *info)
3341 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
3342 u8 rx_agc_fc, tx_agc_fc;
3343 u8 rfcsr;
3345 /* Frequeny plan setting */
3346 /* Rdiv setting (set 0x03 if Xtal==20)
3347 * R13[1:0]
3349 rfcsr = rt2800_rfcsr_read(rt2x00dev, 13);
3350 rt2x00_set_field8(&rfcsr, RFCSR13_RDIV_MT7620,
3351 rt2800_clk_is_20mhz(rt2x00dev) ? 3 : 0);
3352 rt2800_rfcsr_write(rt2x00dev, 13, rfcsr);
3354 /* N setting
3355 * R20[7:0] in rf->rf1
3356 * R21[0] always 0
3358 rfcsr = rt2800_rfcsr_read(rt2x00dev, 20);
3359 rfcsr = (rf->rf1 & 0x00ff);
3360 rt2800_rfcsr_write(rt2x00dev, 20, rfcsr);
3362 rfcsr = rt2800_rfcsr_read(rt2x00dev, 21);
3363 rt2x00_set_field8(&rfcsr, RFCSR21_BIT1, 0);
3364 rt2800_rfcsr_write(rt2x00dev, 21, rfcsr);
3366 /* K setting (always 0)
3367 * R16[3:0] (RF PLL freq selection)
3369 rfcsr = rt2800_rfcsr_read(rt2x00dev, 16);
3370 rt2x00_set_field8(&rfcsr, RFCSR16_RF_PLL_FREQ_SEL_MT7620, 0);
3371 rt2800_rfcsr_write(rt2x00dev, 16, rfcsr);
3373 /* D setting (always 0)
3374 * R22[2:0] (D=15, R22[2:0]=<111>)
3376 rfcsr = rt2800_rfcsr_read(rt2x00dev, 22);
3377 rt2x00_set_field8(&rfcsr, RFCSR22_FREQPLAN_D_MT7620, 0);
3378 rt2800_rfcsr_write(rt2x00dev, 22, rfcsr);
3380 /* Ksd setting
3381 * Ksd: R17<7:0> in rf->rf2
3382 * R18<7:0> in rf->rf3
3383 * R19<1:0> in rf->rf4
3385 rfcsr = rt2800_rfcsr_read(rt2x00dev, 17);
3386 rfcsr = rf->rf2;
3387 rt2800_rfcsr_write(rt2x00dev, 17, rfcsr);
3389 rfcsr = rt2800_rfcsr_read(rt2x00dev, 18);
3390 rfcsr = rf->rf3;
3391 rt2800_rfcsr_write(rt2x00dev, 18, rfcsr);
3393 rfcsr = rt2800_rfcsr_read(rt2x00dev, 19);
3394 rt2x00_set_field8(&rfcsr, RFCSR19_K, rf->rf4);
3395 rt2800_rfcsr_write(rt2x00dev, 19, rfcsr);
3397 /* Default: XO=20MHz , SDM mode */
3398 rfcsr = rt2800_rfcsr_read(rt2x00dev, 16);
3399 rt2x00_set_field8(&rfcsr, RFCSR16_SDM_MODE_MT7620, 0x80);
3400 rt2800_rfcsr_write(rt2x00dev, 16, rfcsr);
3402 rfcsr = rt2800_rfcsr_read(rt2x00dev, 21);
3403 rt2x00_set_field8(&rfcsr, RFCSR21_BIT8, 1);
3404 rt2800_rfcsr_write(rt2x00dev, 21, rfcsr);
3406 rfcsr = rt2800_rfcsr_read(rt2x00dev, 1);
3407 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_EN_MT7620,
3408 rt2x00dev->default_ant.tx_chain_num != 1);
3409 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
3411 rfcsr = rt2800_rfcsr_read(rt2x00dev, 2);
3412 rt2x00_set_field8(&rfcsr, RFCSR2_TX2_EN_MT7620,
3413 rt2x00dev->default_ant.tx_chain_num != 1);
3414 rt2x00_set_field8(&rfcsr, RFCSR2_RX2_EN_MT7620,
3415 rt2x00dev->default_ant.rx_chain_num != 1);
3416 rt2800_rfcsr_write(rt2x00dev, 2, rfcsr);
3418 rfcsr = rt2800_rfcsr_read(rt2x00dev, 42);
3419 rt2x00_set_field8(&rfcsr, RFCSR42_TX2_EN_MT7620,
3420 rt2x00dev->default_ant.tx_chain_num != 1);
3421 rt2800_rfcsr_write(rt2x00dev, 42, rfcsr);
3423 /* RF for DC Cal BW */
3424 if (conf_is_ht40(conf)) {
3425 rt2800_rfcsr_write_dccal(rt2x00dev, 6, 0x10);
3426 rt2800_rfcsr_write_dccal(rt2x00dev, 7, 0x10);
3427 rt2800_rfcsr_write_dccal(rt2x00dev, 8, 0x04);
3428 rt2800_rfcsr_write_dccal(rt2x00dev, 58, 0x10);
3429 rt2800_rfcsr_write_dccal(rt2x00dev, 59, 0x10);
3430 } else {
3431 rt2800_rfcsr_write_dccal(rt2x00dev, 6, 0x20);
3432 rt2800_rfcsr_write_dccal(rt2x00dev, 7, 0x20);
3433 rt2800_rfcsr_write_dccal(rt2x00dev, 8, 0x00);
3434 rt2800_rfcsr_write_dccal(rt2x00dev, 58, 0x20);
3435 rt2800_rfcsr_write_dccal(rt2x00dev, 59, 0x20);
3438 if (conf_is_ht40(conf)) {
3439 rt2800_rfcsr_write_dccal(rt2x00dev, 58, 0x08);
3440 rt2800_rfcsr_write_dccal(rt2x00dev, 59, 0x08);
3441 } else {
3442 rt2800_rfcsr_write_dccal(rt2x00dev, 58, 0x28);
3443 rt2800_rfcsr_write_dccal(rt2x00dev, 59, 0x28);
3446 rfcsr = rt2800_rfcsr_read(rt2x00dev, 28);
3447 rt2x00_set_field8(&rfcsr, RFCSR28_CH11_HT40,
3448 conf_is_ht40(conf) && (rf->channel == 11));
3449 rt2800_rfcsr_write(rt2x00dev, 28, rfcsr);
3451 if (!test_bit(DEVICE_STATE_SCANNING, &rt2x00dev->flags)) {
3452 if (conf_is_ht40(conf)) {
3453 rx_agc_fc = drv_data->rx_calibration_bw40;
3454 tx_agc_fc = drv_data->tx_calibration_bw40;
3455 } else {
3456 rx_agc_fc = drv_data->rx_calibration_bw20;
3457 tx_agc_fc = drv_data->tx_calibration_bw20;
3459 rfcsr = rt2800_rfcsr_read_bank(rt2x00dev, 5, 6);
3460 rfcsr &= (~0x3F);
3461 rfcsr |= rx_agc_fc;
3462 rt2800_rfcsr_write_bank(rt2x00dev, 5, 6, rfcsr);
3463 rfcsr = rt2800_rfcsr_read_bank(rt2x00dev, 5, 7);
3464 rfcsr &= (~0x3F);
3465 rfcsr |= rx_agc_fc;
3466 rt2800_rfcsr_write_bank(rt2x00dev, 5, 7, rfcsr);
3467 rfcsr = rt2800_rfcsr_read_bank(rt2x00dev, 7, 6);
3468 rfcsr &= (~0x3F);
3469 rfcsr |= rx_agc_fc;
3470 rt2800_rfcsr_write_bank(rt2x00dev, 7, 6, rfcsr);
3471 rfcsr = rt2800_rfcsr_read_bank(rt2x00dev, 7, 7);
3472 rfcsr &= (~0x3F);
3473 rfcsr |= rx_agc_fc;
3474 rt2800_rfcsr_write_bank(rt2x00dev, 7, 7, rfcsr);
3476 rfcsr = rt2800_rfcsr_read_bank(rt2x00dev, 5, 58);
3477 rfcsr &= (~0x3F);
3478 rfcsr |= tx_agc_fc;
3479 rt2800_rfcsr_write_bank(rt2x00dev, 5, 58, rfcsr);
3480 rfcsr = rt2800_rfcsr_read_bank(rt2x00dev, 5, 59);
3481 rfcsr &= (~0x3F);
3482 rfcsr |= tx_agc_fc;
3483 rt2800_rfcsr_write_bank(rt2x00dev, 5, 59, rfcsr);
3484 rfcsr = rt2800_rfcsr_read_bank(rt2x00dev, 7, 58);
3485 rfcsr &= (~0x3F);
3486 rfcsr |= tx_agc_fc;
3487 rt2800_rfcsr_write_bank(rt2x00dev, 7, 58, rfcsr);
3488 rfcsr = rt2800_rfcsr_read_bank(rt2x00dev, 7, 59);
3489 rfcsr &= (~0x3F);
3490 rfcsr |= tx_agc_fc;
3491 rt2800_rfcsr_write_bank(rt2x00dev, 7, 59, rfcsr);
3495 static void rt2800_config_alc(struct rt2x00_dev *rt2x00dev,
3496 struct ieee80211_channel *chan,
3497 int power_level) {
3498 u16 eeprom, target_power, max_power;
3499 u32 mac_sys_ctrl, mac_status;
3500 u32 reg;
3501 u8 bbp;
3502 int i;
3504 /* hardware unit is 0.5dBm, limited to 23.5dBm */
3505 power_level *= 2;
3506 if (power_level > 0x2f)
3507 power_level = 0x2f;
3509 max_power = chan->max_power * 2;
3510 if (max_power > 0x2f)
3511 max_power = 0x2f;
3513 reg = rt2800_register_read(rt2x00dev, TX_ALC_CFG_0);
3514 rt2x00_set_field32(&reg, TX_ALC_CFG_0_CH_INIT_0, power_level);
3515 rt2x00_set_field32(&reg, TX_ALC_CFG_0_CH_INIT_1, power_level);
3516 rt2x00_set_field32(&reg, TX_ALC_CFG_0_LIMIT_0, max_power);
3517 rt2x00_set_field32(&reg, TX_ALC_CFG_0_LIMIT_1, max_power);
3519 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1);
3520 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_INTERNAL_TX_ALC)) {
3521 /* init base power by eeprom target power */
3522 target_power = rt2800_eeprom_read(rt2x00dev,
3523 EEPROM_TXPOWER_INIT);
3524 rt2x00_set_field32(&reg, TX_ALC_CFG_0_CH_INIT_0, target_power);
3525 rt2x00_set_field32(&reg, TX_ALC_CFG_0_CH_INIT_1, target_power);
3527 rt2800_register_write(rt2x00dev, TX_ALC_CFG_0, reg);
3529 reg = rt2800_register_read(rt2x00dev, TX_ALC_CFG_1);
3530 rt2x00_set_field32(&reg, TX_ALC_CFG_1_TX_TEMP_COMP, 0);
3531 rt2800_register_write(rt2x00dev, TX_ALC_CFG_1, reg);
3533 /* Save MAC SYS CTRL registers */
3534 mac_sys_ctrl = rt2800_register_read(rt2x00dev, MAC_SYS_CTRL);
3535 /* Disable Tx/Rx */
3536 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0);
3537 /* Check MAC Tx/Rx idle */
3538 for (i = 0; i < 10000; i++) {
3539 mac_status = rt2800_register_read(rt2x00dev, MAC_STATUS_CFG);
3540 if (mac_status & 0x3)
3541 usleep_range(50, 200);
3542 else
3543 break;
3546 if (i == 10000)
3547 rt2x00_warn(rt2x00dev, "Wait MAC Status to MAX !!!\n");
3549 if (chan->center_freq > 2457) {
3550 bbp = rt2800_bbp_read(rt2x00dev, 30);
3551 bbp = 0x40;
3552 rt2800_bbp_write(rt2x00dev, 30, bbp);
3553 rt2800_rfcsr_write(rt2x00dev, 39, 0);
3554 if (rt2x00_has_cap_external_lna_bg(rt2x00dev))
3555 rt2800_rfcsr_write(rt2x00dev, 42, 0xfb);
3556 else
3557 rt2800_rfcsr_write(rt2x00dev, 42, 0x7b);
3558 } else {
3559 bbp = rt2800_bbp_read(rt2x00dev, 30);
3560 bbp = 0x1f;
3561 rt2800_bbp_write(rt2x00dev, 30, bbp);
3562 rt2800_rfcsr_write(rt2x00dev, 39, 0x80);
3563 if (rt2x00_has_cap_external_lna_bg(rt2x00dev))
3564 rt2800_rfcsr_write(rt2x00dev, 42, 0xdb);
3565 else
3566 rt2800_rfcsr_write(rt2x00dev, 42, 0x5b);
3568 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, mac_sys_ctrl);
3570 rt2800_vco_calibration(rt2x00dev);
3573 static void rt2800_bbp_write_with_rx_chain(struct rt2x00_dev *rt2x00dev,
3574 const unsigned int word,
3575 const u8 value)
3577 u8 chain, reg;
3579 for (chain = 0; chain < rt2x00dev->default_ant.rx_chain_num; chain++) {
3580 reg = rt2800_bbp_read(rt2x00dev, 27);
3581 rt2x00_set_field8(&reg, BBP27_RX_CHAIN_SEL, chain);
3582 rt2800_bbp_write(rt2x00dev, 27, reg);
3584 rt2800_bbp_write(rt2x00dev, word, value);
3588 static void rt2800_iq_calibrate(struct rt2x00_dev *rt2x00dev, int channel)
3590 u8 cal;
3592 /* TX0 IQ Gain */
3593 rt2800_bbp_write(rt2x00dev, 158, 0x2c);
3594 if (channel <= 14)
3595 cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_GAIN_CAL_TX0_2G);
3596 else if (channel >= 36 && channel <= 64)
3597 cal = rt2x00_eeprom_byte(rt2x00dev,
3598 EEPROM_IQ_GAIN_CAL_TX0_CH36_TO_CH64_5G);
3599 else if (channel >= 100 && channel <= 138)
3600 cal = rt2x00_eeprom_byte(rt2x00dev,
3601 EEPROM_IQ_GAIN_CAL_TX0_CH100_TO_CH138_5G);
3602 else if (channel >= 140 && channel <= 165)
3603 cal = rt2x00_eeprom_byte(rt2x00dev,
3604 EEPROM_IQ_GAIN_CAL_TX0_CH140_TO_CH165_5G);
3605 else
3606 cal = 0;
3607 rt2800_bbp_write(rt2x00dev, 159, cal);
3609 /* TX0 IQ Phase */
3610 rt2800_bbp_write(rt2x00dev, 158, 0x2d);
3611 if (channel <= 14)
3612 cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_PHASE_CAL_TX0_2G);
3613 else if (channel >= 36 && channel <= 64)
3614 cal = rt2x00_eeprom_byte(rt2x00dev,
3615 EEPROM_IQ_PHASE_CAL_TX0_CH36_TO_CH64_5G);
3616 else if (channel >= 100 && channel <= 138)
3617 cal = rt2x00_eeprom_byte(rt2x00dev,
3618 EEPROM_IQ_PHASE_CAL_TX0_CH100_TO_CH138_5G);
3619 else if (channel >= 140 && channel <= 165)
3620 cal = rt2x00_eeprom_byte(rt2x00dev,
3621 EEPROM_IQ_PHASE_CAL_TX0_CH140_TO_CH165_5G);
3622 else
3623 cal = 0;
3624 rt2800_bbp_write(rt2x00dev, 159, cal);
3626 /* TX1 IQ Gain */
3627 rt2800_bbp_write(rt2x00dev, 158, 0x4a);
3628 if (channel <= 14)
3629 cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_GAIN_CAL_TX1_2G);
3630 else if (channel >= 36 && channel <= 64)
3631 cal = rt2x00_eeprom_byte(rt2x00dev,
3632 EEPROM_IQ_GAIN_CAL_TX1_CH36_TO_CH64_5G);
3633 else if (channel >= 100 && channel <= 138)
3634 cal = rt2x00_eeprom_byte(rt2x00dev,
3635 EEPROM_IQ_GAIN_CAL_TX1_CH100_TO_CH138_5G);
3636 else if (channel >= 140 && channel <= 165)
3637 cal = rt2x00_eeprom_byte(rt2x00dev,
3638 EEPROM_IQ_GAIN_CAL_TX1_CH140_TO_CH165_5G);
3639 else
3640 cal = 0;
3641 rt2800_bbp_write(rt2x00dev, 159, cal);
3643 /* TX1 IQ Phase */
3644 rt2800_bbp_write(rt2x00dev, 158, 0x4b);
3645 if (channel <= 14)
3646 cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_PHASE_CAL_TX1_2G);
3647 else if (channel >= 36 && channel <= 64)
3648 cal = rt2x00_eeprom_byte(rt2x00dev,
3649 EEPROM_IQ_PHASE_CAL_TX1_CH36_TO_CH64_5G);
3650 else if (channel >= 100 && channel <= 138)
3651 cal = rt2x00_eeprom_byte(rt2x00dev,
3652 EEPROM_IQ_PHASE_CAL_TX1_CH100_TO_CH138_5G);
3653 else if (channel >= 140 && channel <= 165)
3654 cal = rt2x00_eeprom_byte(rt2x00dev,
3655 EEPROM_IQ_PHASE_CAL_TX1_CH140_TO_CH165_5G);
3656 else
3657 cal = 0;
3658 rt2800_bbp_write(rt2x00dev, 159, cal);
3660 /* FIXME: possible RX0, RX1 callibration ? */
3662 /* RF IQ compensation control */
3663 rt2800_bbp_write(rt2x00dev, 158, 0x04);
3664 cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_RF_IQ_COMPENSATION_CONTROL);
3665 rt2800_bbp_write(rt2x00dev, 159, cal != 0xff ? cal : 0);
3667 /* RF IQ imbalance compensation control */
3668 rt2800_bbp_write(rt2x00dev, 158, 0x03);
3669 cal = rt2x00_eeprom_byte(rt2x00dev,
3670 EEPROM_RF_IQ_IMBALANCE_COMPENSATION_CONTROL);
3671 rt2800_bbp_write(rt2x00dev, 159, cal != 0xff ? cal : 0);
3674 static char rt2800_txpower_to_dev(struct rt2x00_dev *rt2x00dev,
3675 unsigned int channel,
3676 char txpower)
3678 if (rt2x00_rt(rt2x00dev, RT3593))
3679 txpower = rt2x00_get_field8(txpower, EEPROM_TXPOWER_ALC);
3681 if (channel <= 14)
3682 return clamp_t(char, txpower, MIN_G_TXPOWER, MAX_G_TXPOWER);
3684 if (rt2x00_rt(rt2x00dev, RT3593))
3685 return clamp_t(char, txpower, MIN_A_TXPOWER_3593,
3686 MAX_A_TXPOWER_3593);
3687 else
3688 return clamp_t(char, txpower, MIN_A_TXPOWER, MAX_A_TXPOWER);
3691 static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
3692 struct ieee80211_conf *conf,
3693 struct rf_channel *rf,
3694 struct channel_info *info)
3696 u32 reg;
3697 u32 tx_pin;
3698 u8 bbp, rfcsr;
3700 info->default_power1 = rt2800_txpower_to_dev(rt2x00dev, rf->channel,
3701 info->default_power1);
3702 info->default_power2 = rt2800_txpower_to_dev(rt2x00dev, rf->channel,
3703 info->default_power2);
3704 if (rt2x00dev->default_ant.tx_chain_num > 2)
3705 info->default_power3 =
3706 rt2800_txpower_to_dev(rt2x00dev, rf->channel,
3707 info->default_power3);
3709 switch (rt2x00dev->chip.rf) {
3710 case RF2020:
3711 case RF3020:
3712 case RF3021:
3713 case RF3022:
3714 case RF3320:
3715 rt2800_config_channel_rf3xxx(rt2x00dev, conf, rf, info);
3716 break;
3717 case RF3052:
3718 rt2800_config_channel_rf3052(rt2x00dev, conf, rf, info);
3719 break;
3720 case RF3053:
3721 rt2800_config_channel_rf3053(rt2x00dev, conf, rf, info);
3722 break;
3723 case RF3290:
3724 rt2800_config_channel_rf3290(rt2x00dev, conf, rf, info);
3725 break;
3726 case RF3322:
3727 rt2800_config_channel_rf3322(rt2x00dev, conf, rf, info);
3728 break;
3729 case RF3070:
3730 case RF5350:
3731 case RF5360:
3732 case RF5362:
3733 case RF5370:
3734 case RF5372:
3735 case RF5390:
3736 case RF5392:
3737 rt2800_config_channel_rf53xx(rt2x00dev, conf, rf, info);
3738 break;
3739 case RF5592:
3740 rt2800_config_channel_rf55xx(rt2x00dev, conf, rf, info);
3741 break;
3742 case RF7620:
3743 rt2800_config_channel_rf7620(rt2x00dev, conf, rf, info);
3744 break;
3745 default:
3746 rt2800_config_channel_rf2xxx(rt2x00dev, conf, rf, info);
3749 if (rt2x00_rf(rt2x00dev, RF3070) ||
3750 rt2x00_rf(rt2x00dev, RF3290) ||
3751 rt2x00_rf(rt2x00dev, RF3322) ||
3752 rt2x00_rf(rt2x00dev, RF5350) ||
3753 rt2x00_rf(rt2x00dev, RF5360) ||
3754 rt2x00_rf(rt2x00dev, RF5362) ||
3755 rt2x00_rf(rt2x00dev, RF5370) ||
3756 rt2x00_rf(rt2x00dev, RF5372) ||
3757 rt2x00_rf(rt2x00dev, RF5390) ||
3758 rt2x00_rf(rt2x00dev, RF5392)) {
3759 rfcsr = rt2800_rfcsr_read(rt2x00dev, 30);
3760 if (rt2x00_rf(rt2x00dev, RF3322)) {
3761 rt2x00_set_field8(&rfcsr, RF3322_RFCSR30_TX_H20M,
3762 conf_is_ht40(conf));
3763 rt2x00_set_field8(&rfcsr, RF3322_RFCSR30_RX_H20M,
3764 conf_is_ht40(conf));
3765 } else {
3766 rt2x00_set_field8(&rfcsr, RFCSR30_TX_H20M,
3767 conf_is_ht40(conf));
3768 rt2x00_set_field8(&rfcsr, RFCSR30_RX_H20M,
3769 conf_is_ht40(conf));
3771 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
3773 rfcsr = rt2800_rfcsr_read(rt2x00dev, 3);
3774 rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
3775 rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
3779 * Change BBP settings
3782 if (rt2x00_rt(rt2x00dev, RT3352)) {
3783 rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
3784 rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
3785 rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
3787 rt2800_bbp_write(rt2x00dev, 27, 0x0);
3788 rt2800_bbp_write(rt2x00dev, 66, 0x26 + rt2x00dev->lna_gain);
3789 rt2800_bbp_write(rt2x00dev, 27, 0x20);
3790 rt2800_bbp_write(rt2x00dev, 66, 0x26 + rt2x00dev->lna_gain);
3791 rt2800_bbp_write(rt2x00dev, 86, 0x38);
3792 rt2800_bbp_write(rt2x00dev, 83, 0x6a);
3793 } else if (rt2x00_rt(rt2x00dev, RT3593)) {
3794 if (rf->channel > 14) {
3795 /* Disable CCK Packet detection on 5GHz */
3796 rt2800_bbp_write(rt2x00dev, 70, 0x00);
3797 } else {
3798 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
3801 if (conf_is_ht40(conf))
3802 rt2800_bbp_write(rt2x00dev, 105, 0x04);
3803 else
3804 rt2800_bbp_write(rt2x00dev, 105, 0x34);
3806 rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
3807 rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
3808 rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
3809 rt2800_bbp_write(rt2x00dev, 77, 0x98);
3810 } else {
3811 rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
3812 rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
3813 rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
3814 rt2800_bbp_write(rt2x00dev, 86, 0);
3817 if (rf->channel <= 14) {
3818 if (!rt2x00_rt(rt2x00dev, RT5390) &&
3819 !rt2x00_rt(rt2x00dev, RT5392) &&
3820 !rt2x00_rt(rt2x00dev, RT6352)) {
3821 if (rt2x00_has_cap_external_lna_bg(rt2x00dev)) {
3822 rt2800_bbp_write(rt2x00dev, 82, 0x62);
3823 rt2800_bbp_write(rt2x00dev, 75, 0x46);
3824 } else {
3825 if (rt2x00_rt(rt2x00dev, RT3593))
3826 rt2800_bbp_write(rt2x00dev, 82, 0x62);
3827 else
3828 rt2800_bbp_write(rt2x00dev, 82, 0x84);
3829 rt2800_bbp_write(rt2x00dev, 75, 0x50);
3831 if (rt2x00_rt(rt2x00dev, RT3593))
3832 rt2800_bbp_write(rt2x00dev, 83, 0x8a);
3835 } else {
3836 if (rt2x00_rt(rt2x00dev, RT3572))
3837 rt2800_bbp_write(rt2x00dev, 82, 0x94);
3838 else if (rt2x00_rt(rt2x00dev, RT3593))
3839 rt2800_bbp_write(rt2x00dev, 82, 0x82);
3840 else if (!rt2x00_rt(rt2x00dev, RT6352))
3841 rt2800_bbp_write(rt2x00dev, 82, 0xf2);
3843 if (rt2x00_rt(rt2x00dev, RT3593))
3844 rt2800_bbp_write(rt2x00dev, 83, 0x9a);
3846 if (rt2x00_has_cap_external_lna_a(rt2x00dev))
3847 rt2800_bbp_write(rt2x00dev, 75, 0x46);
3848 else
3849 rt2800_bbp_write(rt2x00dev, 75, 0x50);
3852 reg = rt2800_register_read(rt2x00dev, TX_BAND_CFG);
3853 rt2x00_set_field32(&reg, TX_BAND_CFG_HT40_MINUS, conf_is_ht40_minus(conf));
3854 rt2x00_set_field32(&reg, TX_BAND_CFG_A, rf->channel > 14);
3855 rt2x00_set_field32(&reg, TX_BAND_CFG_BG, rf->channel <= 14);
3856 rt2800_register_write(rt2x00dev, TX_BAND_CFG, reg);
3858 if (rt2x00_rt(rt2x00dev, RT3572))
3859 rt2800_rfcsr_write(rt2x00dev, 8, 0);
3861 if (rt2x00_rt(rt2x00dev, RT6352)) {
3862 tx_pin = rt2800_register_read(rt2x00dev, TX_PIN_CFG);
3863 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFRX_EN, 1);
3864 } else {
3865 tx_pin = 0;
3868 switch (rt2x00dev->default_ant.tx_chain_num) {
3869 case 3:
3870 /* Turn on tertiary PAs */
3871 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A2_EN,
3872 rf->channel > 14);
3873 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G2_EN,
3874 rf->channel <= 14);
3875 /* fall-through */
3876 case 2:
3877 /* Turn on secondary PAs */
3878 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN,
3879 rf->channel > 14);
3880 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN,
3881 rf->channel <= 14);
3882 /* fall-through */
3883 case 1:
3884 /* Turn on primary PAs */
3885 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN,
3886 rf->channel > 14);
3887 if (rt2x00_has_cap_bt_coexist(rt2x00dev))
3888 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, 1);
3889 else
3890 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN,
3891 rf->channel <= 14);
3892 break;
3895 switch (rt2x00dev->default_ant.rx_chain_num) {
3896 case 3:
3897 /* Turn on tertiary LNAs */
3898 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A2_EN,
3899 rf->channel > 14);
3900 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G2_EN,
3901 rf->channel <= 14);
3902 /* fall-through */
3903 case 2:
3904 /* Turn on secondary LNAs */
3905 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN,
3906 rf->channel > 14);
3907 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN,
3908 rf->channel <= 14);
3909 /* fall-through */
3910 case 1:
3911 /* Turn on primary LNAs */
3912 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN,
3913 rf->channel > 14);
3914 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN,
3915 rf->channel <= 14);
3916 break;
3919 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1);
3920 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_TRSW_EN, 1);
3922 rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
3924 if (rt2x00_rt(rt2x00dev, RT3572)) {
3925 rt2800_rfcsr_write(rt2x00dev, 8, 0x80);
3927 /* AGC init */
3928 if (rf->channel <= 14)
3929 reg = 0x1c + (2 * rt2x00dev->lna_gain);
3930 else
3931 reg = 0x22 + ((rt2x00dev->lna_gain * 5) / 3);
3933 rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, reg);
3936 if (rt2x00_rt(rt2x00dev, RT3593)) {
3937 reg = rt2800_register_read(rt2x00dev, GPIO_CTRL);
3939 /* Band selection */
3940 if (rt2x00_is_usb(rt2x00dev) ||
3941 rt2x00_is_pcie(rt2x00dev)) {
3942 /* GPIO #8 controls all paths */
3943 rt2x00_set_field32(&reg, GPIO_CTRL_DIR8, 0);
3944 if (rf->channel <= 14)
3945 rt2x00_set_field32(&reg, GPIO_CTRL_VAL8, 1);
3946 else
3947 rt2x00_set_field32(&reg, GPIO_CTRL_VAL8, 0);
3950 /* LNA PE control. */
3951 if (rt2x00_is_usb(rt2x00dev)) {
3952 /* GPIO #4 controls PE0 and PE1,
3953 * GPIO #7 controls PE2
3955 rt2x00_set_field32(&reg, GPIO_CTRL_DIR4, 0);
3956 rt2x00_set_field32(&reg, GPIO_CTRL_DIR7, 0);
3958 rt2x00_set_field32(&reg, GPIO_CTRL_VAL4, 1);
3959 rt2x00_set_field32(&reg, GPIO_CTRL_VAL7, 1);
3960 } else if (rt2x00_is_pcie(rt2x00dev)) {
3961 /* GPIO #4 controls PE0, PE1 and PE2 */
3962 rt2x00_set_field32(&reg, GPIO_CTRL_DIR4, 0);
3963 rt2x00_set_field32(&reg, GPIO_CTRL_VAL4, 1);
3966 rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
3968 /* AGC init */
3969 if (rf->channel <= 14)
3970 reg = 0x1c + 2 * rt2x00dev->lna_gain;
3971 else
3972 reg = 0x22 + ((rt2x00dev->lna_gain * 5) / 3);
3974 rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, reg);
3976 usleep_range(1000, 1500);
3979 if (rt2x00_rt(rt2x00dev, RT5592) || rt2x00_rt(rt2x00dev, RT6352)) {
3980 reg = 0x10;
3981 if (!conf_is_ht40(conf)) {
3982 if (rt2x00_rt(rt2x00dev, RT6352) &&
3983 rt2x00_has_cap_external_lna_bg(rt2x00dev)) {
3984 reg |= 0x5;
3985 } else {
3986 reg |= 0xa;
3989 rt2800_bbp_write(rt2x00dev, 195, 141);
3990 rt2800_bbp_write(rt2x00dev, 196, reg);
3992 /* AGC init.
3993 * Despite the vendor driver using different values here for
3994 * RT6352 chip, we use 0x1c for now. This may have to be changed
3995 * once TSSI got implemented.
3997 reg = (rf->channel <= 14 ? 0x1c : 0x24) + 2*rt2x00dev->lna_gain;
3998 rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, reg);
4000 rt2800_iq_calibrate(rt2x00dev, rf->channel);
4003 bbp = rt2800_bbp_read(rt2x00dev, 4);
4004 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * conf_is_ht40(conf));
4005 rt2800_bbp_write(rt2x00dev, 4, bbp);
4007 bbp = rt2800_bbp_read(rt2x00dev, 3);
4008 rt2x00_set_field8(&bbp, BBP3_HT40_MINUS, conf_is_ht40_minus(conf));
4009 rt2800_bbp_write(rt2x00dev, 3, bbp);
4011 if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) {
4012 if (conf_is_ht40(conf)) {
4013 rt2800_bbp_write(rt2x00dev, 69, 0x1a);
4014 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
4015 rt2800_bbp_write(rt2x00dev, 73, 0x16);
4016 } else {
4017 rt2800_bbp_write(rt2x00dev, 69, 0x16);
4018 rt2800_bbp_write(rt2x00dev, 70, 0x08);
4019 rt2800_bbp_write(rt2x00dev, 73, 0x11);
4023 usleep_range(1000, 1500);
4026 * Clear channel statistic counters
4028 reg = rt2800_register_read(rt2x00dev, CH_IDLE_STA);
4029 reg = rt2800_register_read(rt2x00dev, CH_BUSY_STA);
4030 reg = rt2800_register_read(rt2x00dev, CH_BUSY_STA_SEC);
4033 * Clear update flag
4035 if (rt2x00_rt(rt2x00dev, RT3352) ||
4036 rt2x00_rt(rt2x00dev, RT5350)) {
4037 bbp = rt2800_bbp_read(rt2x00dev, 49);
4038 rt2x00_set_field8(&bbp, BBP49_UPDATE_FLAG, 0);
4039 rt2800_bbp_write(rt2x00dev, 49, bbp);
4043 static int rt2800_get_gain_calibration_delta(struct rt2x00_dev *rt2x00dev)
4045 u8 tssi_bounds[9];
4046 u8 current_tssi;
4047 u16 eeprom;
4048 u8 step;
4049 int i;
4052 * First check if temperature compensation is supported.
4054 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1);
4055 if (!rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_EXTERNAL_TX_ALC))
4056 return 0;
4059 * Read TSSI boundaries for temperature compensation from
4060 * the EEPROM.
4062 * Array idx 0 1 2 3 4 5 6 7 8
4063 * Matching Delta value -4 -3 -2 -1 0 +1 +2 +3 +4
4064 * Example TSSI bounds 0xF0 0xD0 0xB5 0xA0 0x88 0x45 0x25 0x15 0x00
4066 if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
4067 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG1);
4068 tssi_bounds[0] = rt2x00_get_field16(eeprom,
4069 EEPROM_TSSI_BOUND_BG1_MINUS4);
4070 tssi_bounds[1] = rt2x00_get_field16(eeprom,
4071 EEPROM_TSSI_BOUND_BG1_MINUS3);
4073 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG2);
4074 tssi_bounds[2] = rt2x00_get_field16(eeprom,
4075 EEPROM_TSSI_BOUND_BG2_MINUS2);
4076 tssi_bounds[3] = rt2x00_get_field16(eeprom,
4077 EEPROM_TSSI_BOUND_BG2_MINUS1);
4079 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG3);
4080 tssi_bounds[4] = rt2x00_get_field16(eeprom,
4081 EEPROM_TSSI_BOUND_BG3_REF);
4082 tssi_bounds[5] = rt2x00_get_field16(eeprom,
4083 EEPROM_TSSI_BOUND_BG3_PLUS1);
4085 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG4);
4086 tssi_bounds[6] = rt2x00_get_field16(eeprom,
4087 EEPROM_TSSI_BOUND_BG4_PLUS2);
4088 tssi_bounds[7] = rt2x00_get_field16(eeprom,
4089 EEPROM_TSSI_BOUND_BG4_PLUS3);
4091 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG5);
4092 tssi_bounds[8] = rt2x00_get_field16(eeprom,
4093 EEPROM_TSSI_BOUND_BG5_PLUS4);
4095 step = rt2x00_get_field16(eeprom,
4096 EEPROM_TSSI_BOUND_BG5_AGC_STEP);
4097 } else {
4098 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A1);
4099 tssi_bounds[0] = rt2x00_get_field16(eeprom,
4100 EEPROM_TSSI_BOUND_A1_MINUS4);
4101 tssi_bounds[1] = rt2x00_get_field16(eeprom,
4102 EEPROM_TSSI_BOUND_A1_MINUS3);
4104 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A2);
4105 tssi_bounds[2] = rt2x00_get_field16(eeprom,
4106 EEPROM_TSSI_BOUND_A2_MINUS2);
4107 tssi_bounds[3] = rt2x00_get_field16(eeprom,
4108 EEPROM_TSSI_BOUND_A2_MINUS1);
4110 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A3);
4111 tssi_bounds[4] = rt2x00_get_field16(eeprom,
4112 EEPROM_TSSI_BOUND_A3_REF);
4113 tssi_bounds[5] = rt2x00_get_field16(eeprom,
4114 EEPROM_TSSI_BOUND_A3_PLUS1);
4116 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A4);
4117 tssi_bounds[6] = rt2x00_get_field16(eeprom,
4118 EEPROM_TSSI_BOUND_A4_PLUS2);
4119 tssi_bounds[7] = rt2x00_get_field16(eeprom,
4120 EEPROM_TSSI_BOUND_A4_PLUS3);
4122 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A5);
4123 tssi_bounds[8] = rt2x00_get_field16(eeprom,
4124 EEPROM_TSSI_BOUND_A5_PLUS4);
4126 step = rt2x00_get_field16(eeprom,
4127 EEPROM_TSSI_BOUND_A5_AGC_STEP);
4131 * Check if temperature compensation is supported.
4133 if (tssi_bounds[4] == 0xff || step == 0xff)
4134 return 0;
4137 * Read current TSSI (BBP 49).
4139 current_tssi = rt2800_bbp_read(rt2x00dev, 49);
4142 * Compare TSSI value (BBP49) with the compensation boundaries
4143 * from the EEPROM and increase or decrease tx power.
4145 for (i = 0; i <= 3; i++) {
4146 if (current_tssi > tssi_bounds[i])
4147 break;
4150 if (i == 4) {
4151 for (i = 8; i >= 5; i--) {
4152 if (current_tssi < tssi_bounds[i])
4153 break;
4157 return (i - 4) * step;
4160 static int rt2800_get_txpower_bw_comp(struct rt2x00_dev *rt2x00dev,
4161 enum nl80211_band band)
4163 u16 eeprom;
4164 u8 comp_en;
4165 u8 comp_type;
4166 int comp_value = 0;
4168 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_TXPOWER_DELTA);
4171 * HT40 compensation not required.
4173 if (eeprom == 0xffff ||
4174 !test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
4175 return 0;
4177 if (band == NL80211_BAND_2GHZ) {
4178 comp_en = rt2x00_get_field16(eeprom,
4179 EEPROM_TXPOWER_DELTA_ENABLE_2G);
4180 if (comp_en) {
4181 comp_type = rt2x00_get_field16(eeprom,
4182 EEPROM_TXPOWER_DELTA_TYPE_2G);
4183 comp_value = rt2x00_get_field16(eeprom,
4184 EEPROM_TXPOWER_DELTA_VALUE_2G);
4185 if (!comp_type)
4186 comp_value = -comp_value;
4188 } else {
4189 comp_en = rt2x00_get_field16(eeprom,
4190 EEPROM_TXPOWER_DELTA_ENABLE_5G);
4191 if (comp_en) {
4192 comp_type = rt2x00_get_field16(eeprom,
4193 EEPROM_TXPOWER_DELTA_TYPE_5G);
4194 comp_value = rt2x00_get_field16(eeprom,
4195 EEPROM_TXPOWER_DELTA_VALUE_5G);
4196 if (!comp_type)
4197 comp_value = -comp_value;
4201 return comp_value;
4204 static int rt2800_get_txpower_reg_delta(struct rt2x00_dev *rt2x00dev,
4205 int power_level, int max_power)
4207 int delta;
4209 if (rt2x00_has_cap_power_limit(rt2x00dev))
4210 return 0;
4213 * XXX: We don't know the maximum transmit power of our hardware since
4214 * the EEPROM doesn't expose it. We only know that we are calibrated
4215 * to 100% tx power.
4217 * Hence, we assume the regulatory limit that cfg80211 calulated for
4218 * the current channel is our maximum and if we are requested to lower
4219 * the value we just reduce our tx power accordingly.
4221 delta = power_level - max_power;
4222 return min(delta, 0);
4225 static u8 rt2800_compensate_txpower(struct rt2x00_dev *rt2x00dev, int is_rate_b,
4226 enum nl80211_band band, int power_level,
4227 u8 txpower, int delta)
4229 u16 eeprom;
4230 u8 criterion;
4231 u8 eirp_txpower;
4232 u8 eirp_txpower_criterion;
4233 u8 reg_limit;
4235 if (rt2x00_rt(rt2x00dev, RT3593))
4236 return min_t(u8, txpower, 0xc);
4238 if (rt2x00_has_cap_power_limit(rt2x00dev)) {
4240 * Check if eirp txpower exceed txpower_limit.
4241 * We use OFDM 6M as criterion and its eirp txpower
4242 * is stored at EEPROM_EIRP_MAX_TX_POWER.
4243 * .11b data rate need add additional 4dbm
4244 * when calculating eirp txpower.
4246 eeprom = rt2800_eeprom_read_from_array(rt2x00dev,
4247 EEPROM_TXPOWER_BYRATE,
4249 criterion = rt2x00_get_field16(eeprom,
4250 EEPROM_TXPOWER_BYRATE_RATE0);
4252 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_EIRP_MAX_TX_POWER);
4254 if (band == NL80211_BAND_2GHZ)
4255 eirp_txpower_criterion = rt2x00_get_field16(eeprom,
4256 EEPROM_EIRP_MAX_TX_POWER_2GHZ);
4257 else
4258 eirp_txpower_criterion = rt2x00_get_field16(eeprom,
4259 EEPROM_EIRP_MAX_TX_POWER_5GHZ);
4261 eirp_txpower = eirp_txpower_criterion + (txpower - criterion) +
4262 (is_rate_b ? 4 : 0) + delta;
4264 reg_limit = (eirp_txpower > power_level) ?
4265 (eirp_txpower - power_level) : 0;
4266 } else
4267 reg_limit = 0;
4269 txpower = max(0, txpower + delta - reg_limit);
4270 return min_t(u8, txpower, 0xc);
4274 enum {
4275 TX_PWR_CFG_0_IDX,
4276 TX_PWR_CFG_1_IDX,
4277 TX_PWR_CFG_2_IDX,
4278 TX_PWR_CFG_3_IDX,
4279 TX_PWR_CFG_4_IDX,
4280 TX_PWR_CFG_5_IDX,
4281 TX_PWR_CFG_6_IDX,
4282 TX_PWR_CFG_7_IDX,
4283 TX_PWR_CFG_8_IDX,
4284 TX_PWR_CFG_9_IDX,
4285 TX_PWR_CFG_0_EXT_IDX,
4286 TX_PWR_CFG_1_EXT_IDX,
4287 TX_PWR_CFG_2_EXT_IDX,
4288 TX_PWR_CFG_3_EXT_IDX,
4289 TX_PWR_CFG_4_EXT_IDX,
4290 TX_PWR_CFG_IDX_COUNT,
4293 static void rt2800_config_txpower_rt3593(struct rt2x00_dev *rt2x00dev,
4294 struct ieee80211_channel *chan,
4295 int power_level)
4297 u8 txpower;
4298 u16 eeprom;
4299 u32 regs[TX_PWR_CFG_IDX_COUNT];
4300 unsigned int offset;
4301 enum nl80211_band band = chan->band;
4302 int delta;
4303 int i;
4305 memset(regs, '\0', sizeof(regs));
4307 /* TODO: adapt TX power reduction from the rt28xx code */
4309 /* calculate temperature compensation delta */
4310 delta = rt2800_get_gain_calibration_delta(rt2x00dev);
4312 if (band == NL80211_BAND_5GHZ)
4313 offset = 16;
4314 else
4315 offset = 0;
4317 if (test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
4318 offset += 8;
4320 /* read the next four txpower values */
4321 eeprom = rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
4322 offset);
4324 /* CCK 1MBS,2MBS */
4325 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
4326 txpower = rt2800_compensate_txpower(rt2x00dev, 1, band, power_level,
4327 txpower, delta);
4328 rt2x00_set_field32(&regs[TX_PWR_CFG_0_IDX],
4329 TX_PWR_CFG_0_CCK1_CH0, txpower);
4330 rt2x00_set_field32(&regs[TX_PWR_CFG_0_IDX],
4331 TX_PWR_CFG_0_CCK1_CH1, txpower);
4332 rt2x00_set_field32(&regs[TX_PWR_CFG_0_EXT_IDX],
4333 TX_PWR_CFG_0_EXT_CCK1_CH2, txpower);
4335 /* CCK 5.5MBS,11MBS */
4336 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1);
4337 txpower = rt2800_compensate_txpower(rt2x00dev, 1, band, power_level,
4338 txpower, delta);
4339 rt2x00_set_field32(&regs[TX_PWR_CFG_0_IDX],
4340 TX_PWR_CFG_0_CCK5_CH0, txpower);
4341 rt2x00_set_field32(&regs[TX_PWR_CFG_0_IDX],
4342 TX_PWR_CFG_0_CCK5_CH1, txpower);
4343 rt2x00_set_field32(&regs[TX_PWR_CFG_0_EXT_IDX],
4344 TX_PWR_CFG_0_EXT_CCK5_CH2, txpower);
4346 /* OFDM 6MBS,9MBS */
4347 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2);
4348 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4349 txpower, delta);
4350 rt2x00_set_field32(&regs[TX_PWR_CFG_0_IDX],
4351 TX_PWR_CFG_0_OFDM6_CH0, txpower);
4352 rt2x00_set_field32(&regs[TX_PWR_CFG_0_IDX],
4353 TX_PWR_CFG_0_OFDM6_CH1, txpower);
4354 rt2x00_set_field32(&regs[TX_PWR_CFG_0_EXT_IDX],
4355 TX_PWR_CFG_0_EXT_OFDM6_CH2, txpower);
4357 /* OFDM 12MBS,18MBS */
4358 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3);
4359 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4360 txpower, delta);
4361 rt2x00_set_field32(&regs[TX_PWR_CFG_0_IDX],
4362 TX_PWR_CFG_0_OFDM12_CH0, txpower);
4363 rt2x00_set_field32(&regs[TX_PWR_CFG_0_IDX],
4364 TX_PWR_CFG_0_OFDM12_CH1, txpower);
4365 rt2x00_set_field32(&regs[TX_PWR_CFG_0_EXT_IDX],
4366 TX_PWR_CFG_0_EXT_OFDM12_CH2, txpower);
4368 /* read the next four txpower values */
4369 eeprom = rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
4370 offset + 1);
4372 /* OFDM 24MBS,36MBS */
4373 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
4374 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4375 txpower, delta);
4376 rt2x00_set_field32(&regs[TX_PWR_CFG_1_IDX],
4377 TX_PWR_CFG_1_OFDM24_CH0, txpower);
4378 rt2x00_set_field32(&regs[TX_PWR_CFG_1_IDX],
4379 TX_PWR_CFG_1_OFDM24_CH1, txpower);
4380 rt2x00_set_field32(&regs[TX_PWR_CFG_1_EXT_IDX],
4381 TX_PWR_CFG_1_EXT_OFDM24_CH2, txpower);
4383 /* OFDM 48MBS */
4384 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1);
4385 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4386 txpower, delta);
4387 rt2x00_set_field32(&regs[TX_PWR_CFG_1_IDX],
4388 TX_PWR_CFG_1_OFDM48_CH0, txpower);
4389 rt2x00_set_field32(&regs[TX_PWR_CFG_1_IDX],
4390 TX_PWR_CFG_1_OFDM48_CH1, txpower);
4391 rt2x00_set_field32(&regs[TX_PWR_CFG_1_EXT_IDX],
4392 TX_PWR_CFG_1_EXT_OFDM48_CH2, txpower);
4394 /* OFDM 54MBS */
4395 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2);
4396 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4397 txpower, delta);
4398 rt2x00_set_field32(&regs[TX_PWR_CFG_7_IDX],
4399 TX_PWR_CFG_7_OFDM54_CH0, txpower);
4400 rt2x00_set_field32(&regs[TX_PWR_CFG_7_IDX],
4401 TX_PWR_CFG_7_OFDM54_CH1, txpower);
4402 rt2x00_set_field32(&regs[TX_PWR_CFG_7_IDX],
4403 TX_PWR_CFG_7_OFDM54_CH2, txpower);
4405 /* read the next four txpower values */
4406 eeprom = rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
4407 offset + 2);
4409 /* MCS 0,1 */
4410 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
4411 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4412 txpower, delta);
4413 rt2x00_set_field32(&regs[TX_PWR_CFG_1_IDX],
4414 TX_PWR_CFG_1_MCS0_CH0, txpower);
4415 rt2x00_set_field32(&regs[TX_PWR_CFG_1_IDX],
4416 TX_PWR_CFG_1_MCS0_CH1, txpower);
4417 rt2x00_set_field32(&regs[TX_PWR_CFG_1_EXT_IDX],
4418 TX_PWR_CFG_1_EXT_MCS0_CH2, txpower);
4420 /* MCS 2,3 */
4421 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1);
4422 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4423 txpower, delta);
4424 rt2x00_set_field32(&regs[TX_PWR_CFG_1_IDX],
4425 TX_PWR_CFG_1_MCS2_CH0, txpower);
4426 rt2x00_set_field32(&regs[TX_PWR_CFG_1_IDX],
4427 TX_PWR_CFG_1_MCS2_CH1, txpower);
4428 rt2x00_set_field32(&regs[TX_PWR_CFG_1_EXT_IDX],
4429 TX_PWR_CFG_1_EXT_MCS2_CH2, txpower);
4431 /* MCS 4,5 */
4432 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2);
4433 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4434 txpower, delta);
4435 rt2x00_set_field32(&regs[TX_PWR_CFG_2_IDX],
4436 TX_PWR_CFG_2_MCS4_CH0, txpower);
4437 rt2x00_set_field32(&regs[TX_PWR_CFG_2_IDX],
4438 TX_PWR_CFG_2_MCS4_CH1, txpower);
4439 rt2x00_set_field32(&regs[TX_PWR_CFG_2_EXT_IDX],
4440 TX_PWR_CFG_2_EXT_MCS4_CH2, txpower);
4442 /* MCS 6 */
4443 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3);
4444 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4445 txpower, delta);
4446 rt2x00_set_field32(&regs[TX_PWR_CFG_2_IDX],
4447 TX_PWR_CFG_2_MCS6_CH0, txpower);
4448 rt2x00_set_field32(&regs[TX_PWR_CFG_2_IDX],
4449 TX_PWR_CFG_2_MCS6_CH1, txpower);
4450 rt2x00_set_field32(&regs[TX_PWR_CFG_2_EXT_IDX],
4451 TX_PWR_CFG_2_EXT_MCS6_CH2, txpower);
4453 /* read the next four txpower values */
4454 eeprom = rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
4455 offset + 3);
4457 /* MCS 7 */
4458 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
4459 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4460 txpower, delta);
4461 rt2x00_set_field32(&regs[TX_PWR_CFG_7_IDX],
4462 TX_PWR_CFG_7_MCS7_CH0, txpower);
4463 rt2x00_set_field32(&regs[TX_PWR_CFG_7_IDX],
4464 TX_PWR_CFG_7_MCS7_CH1, txpower);
4465 rt2x00_set_field32(&regs[TX_PWR_CFG_7_IDX],
4466 TX_PWR_CFG_7_MCS7_CH2, txpower);
4468 /* MCS 8,9 */
4469 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1);
4470 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4471 txpower, delta);
4472 rt2x00_set_field32(&regs[TX_PWR_CFG_2_IDX],
4473 TX_PWR_CFG_2_MCS8_CH0, txpower);
4474 rt2x00_set_field32(&regs[TX_PWR_CFG_2_IDX],
4475 TX_PWR_CFG_2_MCS8_CH1, txpower);
4476 rt2x00_set_field32(&regs[TX_PWR_CFG_2_EXT_IDX],
4477 TX_PWR_CFG_2_EXT_MCS8_CH2, txpower);
4479 /* MCS 10,11 */
4480 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2);
4481 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4482 txpower, delta);
4483 rt2x00_set_field32(&regs[TX_PWR_CFG_2_IDX],
4484 TX_PWR_CFG_2_MCS10_CH0, txpower);
4485 rt2x00_set_field32(&regs[TX_PWR_CFG_2_IDX],
4486 TX_PWR_CFG_2_MCS10_CH1, txpower);
4487 rt2x00_set_field32(&regs[TX_PWR_CFG_2_EXT_IDX],
4488 TX_PWR_CFG_2_EXT_MCS10_CH2, txpower);
4490 /* MCS 12,13 */
4491 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3);
4492 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4493 txpower, delta);
4494 rt2x00_set_field32(&regs[TX_PWR_CFG_3_IDX],
4495 TX_PWR_CFG_3_MCS12_CH0, txpower);
4496 rt2x00_set_field32(&regs[TX_PWR_CFG_3_IDX],
4497 TX_PWR_CFG_3_MCS12_CH1, txpower);
4498 rt2x00_set_field32(&regs[TX_PWR_CFG_3_EXT_IDX],
4499 TX_PWR_CFG_3_EXT_MCS12_CH2, txpower);
4501 /* read the next four txpower values */
4502 eeprom = rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
4503 offset + 4);
4505 /* MCS 14 */
4506 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
4507 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4508 txpower, delta);
4509 rt2x00_set_field32(&regs[TX_PWR_CFG_3_IDX],
4510 TX_PWR_CFG_3_MCS14_CH0, txpower);
4511 rt2x00_set_field32(&regs[TX_PWR_CFG_3_IDX],
4512 TX_PWR_CFG_3_MCS14_CH1, txpower);
4513 rt2x00_set_field32(&regs[TX_PWR_CFG_3_EXT_IDX],
4514 TX_PWR_CFG_3_EXT_MCS14_CH2, txpower);
4516 /* MCS 15 */
4517 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1);
4518 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4519 txpower, delta);
4520 rt2x00_set_field32(&regs[TX_PWR_CFG_8_IDX],
4521 TX_PWR_CFG_8_MCS15_CH0, txpower);
4522 rt2x00_set_field32(&regs[TX_PWR_CFG_8_IDX],
4523 TX_PWR_CFG_8_MCS15_CH1, txpower);
4524 rt2x00_set_field32(&regs[TX_PWR_CFG_8_IDX],
4525 TX_PWR_CFG_8_MCS15_CH2, txpower);
4527 /* MCS 16,17 */
4528 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2);
4529 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4530 txpower, delta);
4531 rt2x00_set_field32(&regs[TX_PWR_CFG_5_IDX],
4532 TX_PWR_CFG_5_MCS16_CH0, txpower);
4533 rt2x00_set_field32(&regs[TX_PWR_CFG_5_IDX],
4534 TX_PWR_CFG_5_MCS16_CH1, txpower);
4535 rt2x00_set_field32(&regs[TX_PWR_CFG_5_IDX],
4536 TX_PWR_CFG_5_MCS16_CH2, txpower);
4538 /* MCS 18,19 */
4539 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3);
4540 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4541 txpower, delta);
4542 rt2x00_set_field32(&regs[TX_PWR_CFG_5_IDX],
4543 TX_PWR_CFG_5_MCS18_CH0, txpower);
4544 rt2x00_set_field32(&regs[TX_PWR_CFG_5_IDX],
4545 TX_PWR_CFG_5_MCS18_CH1, txpower);
4546 rt2x00_set_field32(&regs[TX_PWR_CFG_5_IDX],
4547 TX_PWR_CFG_5_MCS18_CH2, txpower);
4549 /* read the next four txpower values */
4550 eeprom = rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
4551 offset + 5);
4553 /* MCS 20,21 */
4554 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
4555 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4556 txpower, delta);
4557 rt2x00_set_field32(&regs[TX_PWR_CFG_6_IDX],
4558 TX_PWR_CFG_6_MCS20_CH0, txpower);
4559 rt2x00_set_field32(&regs[TX_PWR_CFG_6_IDX],
4560 TX_PWR_CFG_6_MCS20_CH1, txpower);
4561 rt2x00_set_field32(&regs[TX_PWR_CFG_6_IDX],
4562 TX_PWR_CFG_6_MCS20_CH2, txpower);
4564 /* MCS 22 */
4565 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1);
4566 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4567 txpower, delta);
4568 rt2x00_set_field32(&regs[TX_PWR_CFG_6_IDX],
4569 TX_PWR_CFG_6_MCS22_CH0, txpower);
4570 rt2x00_set_field32(&regs[TX_PWR_CFG_6_IDX],
4571 TX_PWR_CFG_6_MCS22_CH1, txpower);
4572 rt2x00_set_field32(&regs[TX_PWR_CFG_6_IDX],
4573 TX_PWR_CFG_6_MCS22_CH2, txpower);
4575 /* MCS 23 */
4576 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2);
4577 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4578 txpower, delta);
4579 rt2x00_set_field32(&regs[TX_PWR_CFG_8_IDX],
4580 TX_PWR_CFG_8_MCS23_CH0, txpower);
4581 rt2x00_set_field32(&regs[TX_PWR_CFG_8_IDX],
4582 TX_PWR_CFG_8_MCS23_CH1, txpower);
4583 rt2x00_set_field32(&regs[TX_PWR_CFG_8_IDX],
4584 TX_PWR_CFG_8_MCS23_CH2, txpower);
4586 /* read the next four txpower values */
4587 eeprom = rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
4588 offset + 6);
4590 /* STBC, MCS 0,1 */
4591 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
4592 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4593 txpower, delta);
4594 rt2x00_set_field32(&regs[TX_PWR_CFG_3_IDX],
4595 TX_PWR_CFG_3_STBC0_CH0, txpower);
4596 rt2x00_set_field32(&regs[TX_PWR_CFG_3_IDX],
4597 TX_PWR_CFG_3_STBC0_CH1, txpower);
4598 rt2x00_set_field32(&regs[TX_PWR_CFG_3_EXT_IDX],
4599 TX_PWR_CFG_3_EXT_STBC0_CH2, txpower);
4601 /* STBC, MCS 2,3 */
4602 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1);
4603 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4604 txpower, delta);
4605 rt2x00_set_field32(&regs[TX_PWR_CFG_3_IDX],
4606 TX_PWR_CFG_3_STBC2_CH0, txpower);
4607 rt2x00_set_field32(&regs[TX_PWR_CFG_3_IDX],
4608 TX_PWR_CFG_3_STBC2_CH1, txpower);
4609 rt2x00_set_field32(&regs[TX_PWR_CFG_3_EXT_IDX],
4610 TX_PWR_CFG_3_EXT_STBC2_CH2, txpower);
4612 /* STBC, MCS 4,5 */
4613 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2);
4614 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4615 txpower, delta);
4616 rt2x00_set_field32(&regs[TX_PWR_CFG_4_IDX], TX_PWR_CFG_RATE0, txpower);
4617 rt2x00_set_field32(&regs[TX_PWR_CFG_4_IDX], TX_PWR_CFG_RATE1, txpower);
4618 rt2x00_set_field32(&regs[TX_PWR_CFG_4_EXT_IDX], TX_PWR_CFG_RATE0,
4619 txpower);
4621 /* STBC, MCS 6 */
4622 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3);
4623 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4624 txpower, delta);
4625 rt2x00_set_field32(&regs[TX_PWR_CFG_4_IDX], TX_PWR_CFG_RATE2, txpower);
4626 rt2x00_set_field32(&regs[TX_PWR_CFG_4_IDX], TX_PWR_CFG_RATE3, txpower);
4627 rt2x00_set_field32(&regs[TX_PWR_CFG_4_EXT_IDX], TX_PWR_CFG_RATE2,
4628 txpower);
4630 /* read the next four txpower values */
4631 eeprom = rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
4632 offset + 7);
4634 /* STBC, MCS 7 */
4635 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
4636 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4637 txpower, delta);
4638 rt2x00_set_field32(&regs[TX_PWR_CFG_9_IDX],
4639 TX_PWR_CFG_9_STBC7_CH0, txpower);
4640 rt2x00_set_field32(&regs[TX_PWR_CFG_9_IDX],
4641 TX_PWR_CFG_9_STBC7_CH1, txpower);
4642 rt2x00_set_field32(&regs[TX_PWR_CFG_9_IDX],
4643 TX_PWR_CFG_9_STBC7_CH2, txpower);
4645 rt2800_register_write(rt2x00dev, TX_PWR_CFG_0, regs[TX_PWR_CFG_0_IDX]);
4646 rt2800_register_write(rt2x00dev, TX_PWR_CFG_1, regs[TX_PWR_CFG_1_IDX]);
4647 rt2800_register_write(rt2x00dev, TX_PWR_CFG_2, regs[TX_PWR_CFG_2_IDX]);
4648 rt2800_register_write(rt2x00dev, TX_PWR_CFG_3, regs[TX_PWR_CFG_3_IDX]);
4649 rt2800_register_write(rt2x00dev, TX_PWR_CFG_4, regs[TX_PWR_CFG_4_IDX]);
4650 rt2800_register_write(rt2x00dev, TX_PWR_CFG_5, regs[TX_PWR_CFG_5_IDX]);
4651 rt2800_register_write(rt2x00dev, TX_PWR_CFG_6, regs[TX_PWR_CFG_6_IDX]);
4652 rt2800_register_write(rt2x00dev, TX_PWR_CFG_7, regs[TX_PWR_CFG_7_IDX]);
4653 rt2800_register_write(rt2x00dev, TX_PWR_CFG_8, regs[TX_PWR_CFG_8_IDX]);
4654 rt2800_register_write(rt2x00dev, TX_PWR_CFG_9, regs[TX_PWR_CFG_9_IDX]);
4656 rt2800_register_write(rt2x00dev, TX_PWR_CFG_0_EXT,
4657 regs[TX_PWR_CFG_0_EXT_IDX]);
4658 rt2800_register_write(rt2x00dev, TX_PWR_CFG_1_EXT,
4659 regs[TX_PWR_CFG_1_EXT_IDX]);
4660 rt2800_register_write(rt2x00dev, TX_PWR_CFG_2_EXT,
4661 regs[TX_PWR_CFG_2_EXT_IDX]);
4662 rt2800_register_write(rt2x00dev, TX_PWR_CFG_3_EXT,
4663 regs[TX_PWR_CFG_3_EXT_IDX]);
4664 rt2800_register_write(rt2x00dev, TX_PWR_CFG_4_EXT,
4665 regs[TX_PWR_CFG_4_EXT_IDX]);
4667 for (i = 0; i < TX_PWR_CFG_IDX_COUNT; i++)
4668 rt2x00_dbg(rt2x00dev,
4669 "band:%cGHz, BW:%c0MHz, TX_PWR_CFG_%d%s = %08lx\n",
4670 (band == NL80211_BAND_5GHZ) ? '5' : '2',
4671 (test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags)) ?
4672 '4' : '2',
4673 (i > TX_PWR_CFG_9_IDX) ?
4674 (i - TX_PWR_CFG_9_IDX - 1) : i,
4675 (i > TX_PWR_CFG_9_IDX) ? "_EXT" : "",
4676 (unsigned long) regs[i]);
4679 static void rt2800_config_txpower_rt6352(struct rt2x00_dev *rt2x00dev,
4680 struct ieee80211_channel *chan,
4681 int power_level)
4683 u32 reg, pwreg;
4684 u16 eeprom;
4685 u32 data, gdata;
4686 u8 t, i;
4687 enum nl80211_band band = chan->band;
4688 int delta;
4690 /* Warn user if bw_comp is set in EEPROM */
4691 delta = rt2800_get_txpower_bw_comp(rt2x00dev, band);
4693 if (delta)
4694 rt2x00_warn(rt2x00dev, "ignoring EEPROM HT40 power delta: %d\n",
4695 delta);
4697 /* populate TX_PWR_CFG_0 up to TX_PWR_CFG_4 from EEPROM for HT20, limit
4698 * value to 0x3f and replace 0x20 by 0x21 as this is what the vendor
4699 * driver does as well, though it looks kinda wrong.
4700 * Maybe some misunderstanding of what a signed 8-bit value is? Maybe
4701 * the hardware has a problem handling 0x20, and as the code initially
4702 * used a fixed offset between HT20 and HT40 rates they had to work-
4703 * around that issue and most likely just forgot about it later on.
4704 * Maybe we should use rt2800_get_txpower_bw_comp() here as well,
4705 * however, the corresponding EEPROM value is not respected by the
4706 * vendor driver, so maybe this is rather being taken care of the
4707 * TXALC and the driver doesn't need to handle it...?
4708 * Though this is all very awkward, just do as they did, as that's what
4709 * board vendors expected when they populated the EEPROM...
4711 for (i = 0; i < 5; i++) {
4712 eeprom = rt2800_eeprom_read_from_array(rt2x00dev,
4713 EEPROM_TXPOWER_BYRATE,
4714 i * 2);
4716 data = eeprom;
4718 t = eeprom & 0x3f;
4719 if (t == 32)
4720 t++;
4722 gdata = t;
4724 t = (eeprom & 0x3f00) >> 8;
4725 if (t == 32)
4726 t++;
4728 gdata |= (t << 8);
4730 eeprom = rt2800_eeprom_read_from_array(rt2x00dev,
4731 EEPROM_TXPOWER_BYRATE,
4732 (i * 2) + 1);
4734 t = eeprom & 0x3f;
4735 if (t == 32)
4736 t++;
4738 gdata |= (t << 16);
4740 t = (eeprom & 0x3f00) >> 8;
4741 if (t == 32)
4742 t++;
4744 gdata |= (t << 24);
4745 data |= (eeprom << 16);
4747 if (!test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags)) {
4748 /* HT20 */
4749 if (data != 0xffffffff)
4750 rt2800_register_write(rt2x00dev,
4751 TX_PWR_CFG_0 + (i * 4),
4752 data);
4753 } else {
4754 /* HT40 */
4755 if (gdata != 0xffffffff)
4756 rt2800_register_write(rt2x00dev,
4757 TX_PWR_CFG_0 + (i * 4),
4758 gdata);
4762 /* Aparently Ralink ran out of space in the BYRATE calibration section
4763 * of the EERPOM which is copied to the corresponding TX_PWR_CFG_x
4764 * registers. As recent 2T chips use 8-bit instead of 4-bit values for
4765 * power-offsets more space would be needed. Ralink decided to keep the
4766 * EEPROM layout untouched and rather have some shared values covering
4767 * multiple bitrates.
4768 * Populate the registers not covered by the EEPROM in the same way the
4769 * vendor driver does.
4772 /* For OFDM 54MBS use value from OFDM 48MBS */
4773 pwreg = 0;
4774 reg = rt2800_register_read(rt2x00dev, TX_PWR_CFG_1);
4775 t = rt2x00_get_field32(reg, TX_PWR_CFG_1B_48MBS);
4776 rt2x00_set_field32(&pwreg, TX_PWR_CFG_7B_54MBS, t);
4778 /* For MCS 7 use value from MCS 6 */
4779 reg = rt2800_register_read(rt2x00dev, TX_PWR_CFG_2);
4780 t = rt2x00_get_field32(reg, TX_PWR_CFG_2B_MCS6_MCS7);
4781 rt2x00_set_field32(&pwreg, TX_PWR_CFG_7B_MCS7, t);
4782 rt2800_register_write(rt2x00dev, TX_PWR_CFG_7, pwreg);
4784 /* For MCS 15 use value from MCS 14 */
4785 pwreg = 0;
4786 reg = rt2800_register_read(rt2x00dev, TX_PWR_CFG_3);
4787 t = rt2x00_get_field32(reg, TX_PWR_CFG_3B_MCS14);
4788 rt2x00_set_field32(&pwreg, TX_PWR_CFG_8B_MCS15, t);
4789 rt2800_register_write(rt2x00dev, TX_PWR_CFG_8, pwreg);
4791 /* For STBC MCS 7 use value from STBC MCS 6 */
4792 pwreg = 0;
4793 reg = rt2800_register_read(rt2x00dev, TX_PWR_CFG_4);
4794 t = rt2x00_get_field32(reg, TX_PWR_CFG_4B_STBC_MCS6);
4795 rt2x00_set_field32(&pwreg, TX_PWR_CFG_9B_STBC_MCS7, t);
4796 rt2800_register_write(rt2x00dev, TX_PWR_CFG_9, pwreg);
4798 rt2800_config_alc(rt2x00dev, chan, power_level);
4800 /* TODO: temperature compensation code! */
4804 * We configure transmit power using MAC TX_PWR_CFG_{0,...,N} registers and
4805 * BBP R1 register. TX_PWR_CFG_X allow to configure per rate TX power values,
4806 * 4 bits for each rate (tune from 0 to 15 dBm). BBP_R1 controls transmit power
4807 * for all rates, but allow to set only 4 discrete values: -12, -6, 0 and 6 dBm.
4808 * Reference per rate transmit power values are located in the EEPROM at
4809 * EEPROM_TXPOWER_BYRATE offset. We adjust them and BBP R1 settings according to
4810 * current conditions (i.e. band, bandwidth, temperature, user settings).
4812 static void rt2800_config_txpower_rt28xx(struct rt2x00_dev *rt2x00dev,
4813 struct ieee80211_channel *chan,
4814 int power_level)
4816 u8 txpower, r1;
4817 u16 eeprom;
4818 u32 reg, offset;
4819 int i, is_rate_b, delta, power_ctrl;
4820 enum nl80211_band band = chan->band;
4823 * Calculate HT40 compensation. For 40MHz we need to add or subtract
4824 * value read from EEPROM (different for 2GHz and for 5GHz).
4826 delta = rt2800_get_txpower_bw_comp(rt2x00dev, band);
4829 * Calculate temperature compensation. Depends on measurement of current
4830 * TSSI (Transmitter Signal Strength Indication) we know TX power (due
4831 * to temperature or maybe other factors) is smaller or bigger than
4832 * expected. We adjust it, based on TSSI reference and boundaries values
4833 * provided in EEPROM.
4835 switch (rt2x00dev->chip.rt) {
4836 case RT2860:
4837 case RT2872:
4838 case RT2883:
4839 case RT3070:
4840 case RT3071:
4841 case RT3090:
4842 case RT3572:
4843 delta += rt2800_get_gain_calibration_delta(rt2x00dev);
4844 break;
4845 default:
4846 /* TODO: temperature compensation code for other chips. */
4847 break;
4851 * Decrease power according to user settings, on devices with unknown
4852 * maximum tx power. For other devices we take user power_level into
4853 * consideration on rt2800_compensate_txpower().
4855 delta += rt2800_get_txpower_reg_delta(rt2x00dev, power_level,
4856 chan->max_power);
4859 * BBP_R1 controls TX power for all rates, it allow to set the following
4860 * gains -12, -6, 0, +6 dBm by setting values 2, 1, 0, 3 respectively.
4862 * TODO: we do not use +6 dBm option to do not increase power beyond
4863 * regulatory limit, however this could be utilized for devices with
4864 * CAPABILITY_POWER_LIMIT.
4866 if (delta <= -12) {
4867 power_ctrl = 2;
4868 delta += 12;
4869 } else if (delta <= -6) {
4870 power_ctrl = 1;
4871 delta += 6;
4872 } else {
4873 power_ctrl = 0;
4875 r1 = rt2800_bbp_read(rt2x00dev, 1);
4876 rt2x00_set_field8(&r1, BBP1_TX_POWER_CTRL, power_ctrl);
4877 rt2800_bbp_write(rt2x00dev, 1, r1);
4879 offset = TX_PWR_CFG_0;
4881 for (i = 0; i < EEPROM_TXPOWER_BYRATE_SIZE; i += 2) {
4882 /* just to be safe */
4883 if (offset > TX_PWR_CFG_4)
4884 break;
4886 reg = rt2800_register_read(rt2x00dev, offset);
4888 /* read the next four txpower values */
4889 eeprom = rt2800_eeprom_read_from_array(rt2x00dev,
4890 EEPROM_TXPOWER_BYRATE,
4893 is_rate_b = i ? 0 : 1;
4895 * TX_PWR_CFG_0: 1MBS, TX_PWR_CFG_1: 24MBS,
4896 * TX_PWR_CFG_2: MCS4, TX_PWR_CFG_3: MCS12,
4897 * TX_PWR_CFG_4: unknown
4899 txpower = rt2x00_get_field16(eeprom,
4900 EEPROM_TXPOWER_BYRATE_RATE0);
4901 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4902 power_level, txpower, delta);
4903 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE0, txpower);
4906 * TX_PWR_CFG_0: 2MBS, TX_PWR_CFG_1: 36MBS,
4907 * TX_PWR_CFG_2: MCS5, TX_PWR_CFG_3: MCS13,
4908 * TX_PWR_CFG_4: unknown
4910 txpower = rt2x00_get_field16(eeprom,
4911 EEPROM_TXPOWER_BYRATE_RATE1);
4912 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4913 power_level, txpower, delta);
4914 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE1, txpower);
4917 * TX_PWR_CFG_0: 5.5MBS, TX_PWR_CFG_1: 48MBS,
4918 * TX_PWR_CFG_2: MCS6, TX_PWR_CFG_3: MCS14,
4919 * TX_PWR_CFG_4: unknown
4921 txpower = rt2x00_get_field16(eeprom,
4922 EEPROM_TXPOWER_BYRATE_RATE2);
4923 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4924 power_level, txpower, delta);
4925 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE2, txpower);
4928 * TX_PWR_CFG_0: 11MBS, TX_PWR_CFG_1: 54MBS,
4929 * TX_PWR_CFG_2: MCS7, TX_PWR_CFG_3: MCS15,
4930 * TX_PWR_CFG_4: unknown
4932 txpower = rt2x00_get_field16(eeprom,
4933 EEPROM_TXPOWER_BYRATE_RATE3);
4934 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4935 power_level, txpower, delta);
4936 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE3, txpower);
4938 /* read the next four txpower values */
4939 eeprom = rt2800_eeprom_read_from_array(rt2x00dev,
4940 EEPROM_TXPOWER_BYRATE,
4941 i + 1);
4943 is_rate_b = 0;
4945 * TX_PWR_CFG_0: 6MBS, TX_PWR_CFG_1: MCS0,
4946 * TX_PWR_CFG_2: MCS8, TX_PWR_CFG_3: unknown,
4947 * TX_PWR_CFG_4: unknown
4949 txpower = rt2x00_get_field16(eeprom,
4950 EEPROM_TXPOWER_BYRATE_RATE0);
4951 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4952 power_level, txpower, delta);
4953 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE4, txpower);
4956 * TX_PWR_CFG_0: 9MBS, TX_PWR_CFG_1: MCS1,
4957 * TX_PWR_CFG_2: MCS9, TX_PWR_CFG_3: unknown,
4958 * TX_PWR_CFG_4: unknown
4960 txpower = rt2x00_get_field16(eeprom,
4961 EEPROM_TXPOWER_BYRATE_RATE1);
4962 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4963 power_level, txpower, delta);
4964 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE5, txpower);
4967 * TX_PWR_CFG_0: 12MBS, TX_PWR_CFG_1: MCS2,
4968 * TX_PWR_CFG_2: MCS10, TX_PWR_CFG_3: unknown,
4969 * TX_PWR_CFG_4: unknown
4971 txpower = rt2x00_get_field16(eeprom,
4972 EEPROM_TXPOWER_BYRATE_RATE2);
4973 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4974 power_level, txpower, delta);
4975 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE6, txpower);
4978 * TX_PWR_CFG_0: 18MBS, TX_PWR_CFG_1: MCS3,
4979 * TX_PWR_CFG_2: MCS11, TX_PWR_CFG_3: unknown,
4980 * TX_PWR_CFG_4: unknown
4982 txpower = rt2x00_get_field16(eeprom,
4983 EEPROM_TXPOWER_BYRATE_RATE3);
4984 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4985 power_level, txpower, delta);
4986 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE7, txpower);
4988 rt2800_register_write(rt2x00dev, offset, reg);
4990 /* next TX_PWR_CFG register */
4991 offset += 4;
4995 static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev,
4996 struct ieee80211_channel *chan,
4997 int power_level)
4999 if (rt2x00_rt(rt2x00dev, RT3593))
5000 rt2800_config_txpower_rt3593(rt2x00dev, chan, power_level);
5001 else if (rt2x00_rt(rt2x00dev, RT6352))
5002 rt2800_config_txpower_rt6352(rt2x00dev, chan, power_level);
5003 else
5004 rt2800_config_txpower_rt28xx(rt2x00dev, chan, power_level);
5007 void rt2800_gain_calibration(struct rt2x00_dev *rt2x00dev)
5009 rt2800_config_txpower(rt2x00dev, rt2x00dev->hw->conf.chandef.chan,
5010 rt2x00dev->tx_power);
5012 EXPORT_SYMBOL_GPL(rt2800_gain_calibration);
5014 void rt2800_vco_calibration(struct rt2x00_dev *rt2x00dev)
5016 u32 tx_pin;
5017 u8 rfcsr;
5018 unsigned long min_sleep = 0;
5021 * A voltage-controlled oscillator(VCO) is an electronic oscillator
5022 * designed to be controlled in oscillation frequency by a voltage
5023 * input. Maybe the temperature will affect the frequency of
5024 * oscillation to be shifted. The VCO calibration will be called
5025 * periodically to adjust the frequency to be precision.
5028 tx_pin = rt2800_register_read(rt2x00dev, TX_PIN_CFG);
5029 tx_pin &= TX_PIN_CFG_PA_PE_DISABLE;
5030 rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
5032 switch (rt2x00dev->chip.rf) {
5033 case RF2020:
5034 case RF3020:
5035 case RF3021:
5036 case RF3022:
5037 case RF3320:
5038 case RF3052:
5039 rfcsr = rt2800_rfcsr_read(rt2x00dev, 7);
5040 rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
5041 rt2800_rfcsr_write(rt2x00dev, 7, rfcsr);
5042 break;
5043 case RF3053:
5044 case RF3070:
5045 case RF3290:
5046 case RF5350:
5047 case RF5360:
5048 case RF5362:
5049 case RF5370:
5050 case RF5372:
5051 case RF5390:
5052 case RF5392:
5053 case RF5592:
5054 rfcsr = rt2800_rfcsr_read(rt2x00dev, 3);
5055 rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
5056 rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
5057 min_sleep = 1000;
5058 break;
5059 case RF7620:
5060 rt2800_rfcsr_write(rt2x00dev, 5, 0x40);
5061 rt2800_rfcsr_write(rt2x00dev, 4, 0x0C);
5062 rfcsr = rt2800_rfcsr_read(rt2x00dev, 4);
5063 rt2x00_set_field8(&rfcsr, RFCSR4_VCOCAL_EN, 1);
5064 rt2800_rfcsr_write(rt2x00dev, 4, rfcsr);
5065 min_sleep = 2000;
5066 break;
5067 default:
5068 WARN_ONCE(1, "Not supported RF chipset %x for VCO recalibration",
5069 rt2x00dev->chip.rf);
5070 return;
5073 if (min_sleep > 0)
5074 usleep_range(min_sleep, min_sleep * 2);
5076 tx_pin = rt2800_register_read(rt2x00dev, TX_PIN_CFG);
5077 if (rt2x00dev->rf_channel <= 14) {
5078 switch (rt2x00dev->default_ant.tx_chain_num) {
5079 case 3:
5080 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G2_EN, 1);
5081 /* fall through */
5082 case 2:
5083 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1);
5084 /* fall through */
5085 case 1:
5086 default:
5087 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, 1);
5088 break;
5090 } else {
5091 switch (rt2x00dev->default_ant.tx_chain_num) {
5092 case 3:
5093 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A2_EN, 1);
5094 /* fall through */
5095 case 2:
5096 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1);
5097 /* fall through */
5098 case 1:
5099 default:
5100 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, 1);
5101 break;
5104 rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
5106 if (rt2x00_rt(rt2x00dev, RT6352)) {
5107 if (rt2x00dev->default_ant.rx_chain_num == 1) {
5108 rt2800_bbp_write(rt2x00dev, 91, 0x07);
5109 rt2800_bbp_write(rt2x00dev, 95, 0x1A);
5110 rt2800_bbp_write(rt2x00dev, 195, 128);
5111 rt2800_bbp_write(rt2x00dev, 196, 0xA0);
5112 rt2800_bbp_write(rt2x00dev, 195, 170);
5113 rt2800_bbp_write(rt2x00dev, 196, 0x12);
5114 rt2800_bbp_write(rt2x00dev, 195, 171);
5115 rt2800_bbp_write(rt2x00dev, 196, 0x10);
5116 } else {
5117 rt2800_bbp_write(rt2x00dev, 91, 0x06);
5118 rt2800_bbp_write(rt2x00dev, 95, 0x9A);
5119 rt2800_bbp_write(rt2x00dev, 195, 128);
5120 rt2800_bbp_write(rt2x00dev, 196, 0xE0);
5121 rt2800_bbp_write(rt2x00dev, 195, 170);
5122 rt2800_bbp_write(rt2x00dev, 196, 0x30);
5123 rt2800_bbp_write(rt2x00dev, 195, 171);
5124 rt2800_bbp_write(rt2x00dev, 196, 0x30);
5127 if (rt2x00_has_cap_external_lna_bg(rt2x00dev)) {
5128 rt2800_bbp_write(rt2x00dev, 75, 0x68);
5129 rt2800_bbp_write(rt2x00dev, 76, 0x4C);
5130 rt2800_bbp_write(rt2x00dev, 79, 0x1C);
5131 rt2800_bbp_write(rt2x00dev, 80, 0x0C);
5132 rt2800_bbp_write(rt2x00dev, 82, 0xB6);
5135 /* On 11A, We should delay and wait RF/BBP to be stable
5136 * and the appropriate time should be 1000 micro seconds
5137 * 2005/06/05 - On 11G, we also need this delay time.
5138 * Otherwise it's difficult to pass the WHQL.
5140 usleep_range(1000, 1500);
5143 EXPORT_SYMBOL_GPL(rt2800_vco_calibration);
5145 static void rt2800_config_retry_limit(struct rt2x00_dev *rt2x00dev,
5146 struct rt2x00lib_conf *libconf)
5148 u32 reg;
5150 reg = rt2800_register_read(rt2x00dev, TX_RTY_CFG);
5151 rt2x00_set_field32(&reg, TX_RTY_CFG_SHORT_RTY_LIMIT,
5152 libconf->conf->short_frame_max_tx_count);
5153 rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_LIMIT,
5154 libconf->conf->long_frame_max_tx_count);
5155 rt2800_register_write(rt2x00dev, TX_RTY_CFG, reg);
5158 static void rt2800_config_ps(struct rt2x00_dev *rt2x00dev,
5159 struct rt2x00lib_conf *libconf)
5161 enum dev_state state =
5162 (libconf->conf->flags & IEEE80211_CONF_PS) ?
5163 STATE_SLEEP : STATE_AWAKE;
5164 u32 reg;
5166 if (state == STATE_SLEEP) {
5167 rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0);
5169 reg = rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG);
5170 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 5);
5171 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE,
5172 libconf->conf->listen_interval - 1);
5173 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTOWAKE, 1);
5174 rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
5176 rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
5177 } else {
5178 reg = rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG);
5179 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 0);
5180 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE, 0);
5181 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTOWAKE, 0);
5182 rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
5184 rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
5188 void rt2800_config(struct rt2x00_dev *rt2x00dev,
5189 struct rt2x00lib_conf *libconf,
5190 const unsigned int flags)
5192 /* Always recalculate LNA gain before changing configuration */
5193 rt2800_config_lna_gain(rt2x00dev, libconf);
5195 if (flags & IEEE80211_CONF_CHANGE_CHANNEL) {
5196 rt2800_config_channel(rt2x00dev, libconf->conf,
5197 &libconf->rf, &libconf->channel);
5198 rt2800_config_txpower(rt2x00dev, libconf->conf->chandef.chan,
5199 libconf->conf->power_level);
5201 if (flags & IEEE80211_CONF_CHANGE_POWER)
5202 rt2800_config_txpower(rt2x00dev, libconf->conf->chandef.chan,
5203 libconf->conf->power_level);
5204 if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
5205 rt2800_config_retry_limit(rt2x00dev, libconf);
5206 if (flags & IEEE80211_CONF_CHANGE_PS)
5207 rt2800_config_ps(rt2x00dev, libconf);
5209 EXPORT_SYMBOL_GPL(rt2800_config);
5212 * Link tuning
5214 void rt2800_link_stats(struct rt2x00_dev *rt2x00dev, struct link_qual *qual)
5216 u32 reg;
5219 * Update FCS error count from register.
5221 reg = rt2800_register_read(rt2x00dev, RX_STA_CNT0);
5222 qual->rx_failed = rt2x00_get_field32(reg, RX_STA_CNT0_CRC_ERR);
5224 EXPORT_SYMBOL_GPL(rt2800_link_stats);
5226 static u8 rt2800_get_default_vgc(struct rt2x00_dev *rt2x00dev)
5228 u8 vgc;
5230 if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
5231 if (rt2x00_rt(rt2x00dev, RT3070) ||
5232 rt2x00_rt(rt2x00dev, RT3071) ||
5233 rt2x00_rt(rt2x00dev, RT3090) ||
5234 rt2x00_rt(rt2x00dev, RT3290) ||
5235 rt2x00_rt(rt2x00dev, RT3390) ||
5236 rt2x00_rt(rt2x00dev, RT3572) ||
5237 rt2x00_rt(rt2x00dev, RT3593) ||
5238 rt2x00_rt(rt2x00dev, RT5390) ||
5239 rt2x00_rt(rt2x00dev, RT5392) ||
5240 rt2x00_rt(rt2x00dev, RT5592) ||
5241 rt2x00_rt(rt2x00dev, RT6352))
5242 vgc = 0x1c + (2 * rt2x00dev->lna_gain);
5243 else
5244 vgc = 0x2e + rt2x00dev->lna_gain;
5245 } else { /* 5GHZ band */
5246 if (rt2x00_rt(rt2x00dev, RT3593))
5247 vgc = 0x20 + (rt2x00dev->lna_gain * 5) / 3;
5248 else if (rt2x00_rt(rt2x00dev, RT5592))
5249 vgc = 0x24 + (2 * rt2x00dev->lna_gain);
5250 else {
5251 if (!test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
5252 vgc = 0x32 + (rt2x00dev->lna_gain * 5) / 3;
5253 else
5254 vgc = 0x3a + (rt2x00dev->lna_gain * 5) / 3;
5258 return vgc;
5261 static inline void rt2800_set_vgc(struct rt2x00_dev *rt2x00dev,
5262 struct link_qual *qual, u8 vgc_level)
5264 if (qual->vgc_level != vgc_level) {
5265 if (rt2x00_rt(rt2x00dev, RT3572) ||
5266 rt2x00_rt(rt2x00dev, RT3593)) {
5267 rt2800_bbp_write_with_rx_chain(rt2x00dev, 66,
5268 vgc_level);
5269 } else if (rt2x00_rt(rt2x00dev, RT5592)) {
5270 rt2800_bbp_write(rt2x00dev, 83, qual->rssi > -65 ? 0x4a : 0x7a);
5271 rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, vgc_level);
5272 } else {
5273 rt2800_bbp_write(rt2x00dev, 66, vgc_level);
5276 qual->vgc_level = vgc_level;
5277 qual->vgc_level_reg = vgc_level;
5281 void rt2800_reset_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual)
5283 rt2800_set_vgc(rt2x00dev, qual, rt2800_get_default_vgc(rt2x00dev));
5285 EXPORT_SYMBOL_GPL(rt2800_reset_tuner);
5287 void rt2800_link_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual,
5288 const u32 count)
5290 u8 vgc;
5292 if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C))
5293 return;
5295 /* When RSSI is better than a certain threshold, increase VGC
5296 * with a chip specific value in order to improve the balance
5297 * between sensibility and noise isolation.
5300 vgc = rt2800_get_default_vgc(rt2x00dev);
5302 switch (rt2x00dev->chip.rt) {
5303 case RT3572:
5304 case RT3593:
5305 if (qual->rssi > -65) {
5306 if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
5307 vgc += 0x20;
5308 else
5309 vgc += 0x10;
5311 break;
5313 case RT5592:
5314 if (qual->rssi > -65)
5315 vgc += 0x20;
5316 break;
5318 default:
5319 if (qual->rssi > -80)
5320 vgc += 0x10;
5321 break;
5324 rt2800_set_vgc(rt2x00dev, qual, vgc);
5326 EXPORT_SYMBOL_GPL(rt2800_link_tuner);
5329 * Initialization functions.
5331 static int rt2800_init_registers(struct rt2x00_dev *rt2x00dev)
5333 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
5334 u32 reg;
5335 u16 eeprom;
5336 unsigned int i;
5337 int ret;
5339 rt2800_disable_wpdma(rt2x00dev);
5341 ret = rt2800_drv_init_registers(rt2x00dev);
5342 if (ret)
5343 return ret;
5345 rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE, 0x0000013f);
5346 rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
5348 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
5350 reg = rt2800_register_read(rt2x00dev, BCN_TIME_CFG);
5351 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL, 1600);
5352 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 0);
5353 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, 0);
5354 rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 0);
5355 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
5356 rt2x00_set_field32(&reg, BCN_TIME_CFG_TX_TIME_COMPENSATE, 0);
5357 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
5359 rt2800_config_filter(rt2x00dev, FIF_ALLMULTI);
5361 reg = rt2800_register_read(rt2x00dev, BKOFF_SLOT_CFG);
5362 rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_SLOT_TIME, 9);
5363 rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_CC_DELAY_TIME, 2);
5364 rt2800_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg);
5366 if (rt2x00_rt(rt2x00dev, RT3290)) {
5367 reg = rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL);
5368 if (rt2x00_get_field32(reg, WLAN_EN) == 1) {
5369 rt2x00_set_field32(&reg, PCIE_APP0_CLK_REQ, 1);
5370 rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg);
5373 reg = rt2800_register_read(rt2x00dev, CMB_CTRL);
5374 if (!(rt2x00_get_field32(reg, LDO0_EN) == 1)) {
5375 rt2x00_set_field32(&reg, LDO0_EN, 1);
5376 rt2x00_set_field32(&reg, LDO_BGSEL, 3);
5377 rt2800_register_write(rt2x00dev, CMB_CTRL, reg);
5380 reg = rt2800_register_read(rt2x00dev, OSC_CTRL);
5381 rt2x00_set_field32(&reg, OSC_ROSC_EN, 1);
5382 rt2x00_set_field32(&reg, OSC_CAL_REQ, 1);
5383 rt2x00_set_field32(&reg, OSC_REF_CYCLE, 0x27);
5384 rt2800_register_write(rt2x00dev, OSC_CTRL, reg);
5386 reg = rt2800_register_read(rt2x00dev, COEX_CFG0);
5387 rt2x00_set_field32(&reg, COEX_CFG_ANT, 0x5e);
5388 rt2800_register_write(rt2x00dev, COEX_CFG0, reg);
5390 reg = rt2800_register_read(rt2x00dev, COEX_CFG2);
5391 rt2x00_set_field32(&reg, BT_COEX_CFG1, 0x00);
5392 rt2x00_set_field32(&reg, BT_COEX_CFG0, 0x17);
5393 rt2x00_set_field32(&reg, WL_COEX_CFG1, 0x93);
5394 rt2x00_set_field32(&reg, WL_COEX_CFG0, 0x7f);
5395 rt2800_register_write(rt2x00dev, COEX_CFG2, reg);
5397 reg = rt2800_register_read(rt2x00dev, PLL_CTRL);
5398 rt2x00_set_field32(&reg, PLL_CONTROL, 1);
5399 rt2800_register_write(rt2x00dev, PLL_CTRL, reg);
5402 if (rt2x00_rt(rt2x00dev, RT3071) ||
5403 rt2x00_rt(rt2x00dev, RT3090) ||
5404 rt2x00_rt(rt2x00dev, RT3290) ||
5405 rt2x00_rt(rt2x00dev, RT3390)) {
5407 if (rt2x00_rt(rt2x00dev, RT3290))
5408 rt2800_register_write(rt2x00dev, TX_SW_CFG0,
5409 0x00000404);
5410 else
5411 rt2800_register_write(rt2x00dev, TX_SW_CFG0,
5412 0x00000400);
5414 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
5415 if (rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) ||
5416 rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E) ||
5417 rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) {
5418 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1);
5419 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_DAC_TEST))
5420 rt2800_register_write(rt2x00dev, TX_SW_CFG2,
5421 0x0000002c);
5422 else
5423 rt2800_register_write(rt2x00dev, TX_SW_CFG2,
5424 0x0000000f);
5425 } else {
5426 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
5428 } else if (rt2x00_rt(rt2x00dev, RT3070)) {
5429 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
5431 if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) {
5432 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
5433 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x0000002c);
5434 } else {
5435 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
5436 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
5438 } else if (rt2800_is_305x_soc(rt2x00dev)) {
5439 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
5440 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
5441 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000030);
5442 } else if (rt2x00_rt(rt2x00dev, RT3352)) {
5443 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000402);
5444 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
5445 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
5446 } else if (rt2x00_rt(rt2x00dev, RT3572)) {
5447 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
5448 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
5449 } else if (rt2x00_rt(rt2x00dev, RT3593)) {
5450 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000402);
5451 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
5452 if (rt2x00_rt_rev_lt(rt2x00dev, RT3593, REV_RT3593E)) {
5453 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1);
5454 if (rt2x00_get_field16(eeprom,
5455 EEPROM_NIC_CONF1_DAC_TEST))
5456 rt2800_register_write(rt2x00dev, TX_SW_CFG2,
5457 0x0000001f);
5458 else
5459 rt2800_register_write(rt2x00dev, TX_SW_CFG2,
5460 0x0000000f);
5461 } else {
5462 rt2800_register_write(rt2x00dev, TX_SW_CFG2,
5463 0x00000000);
5465 } else if (rt2x00_rt(rt2x00dev, RT5390) ||
5466 rt2x00_rt(rt2x00dev, RT5392) ||
5467 rt2x00_rt(rt2x00dev, RT6352)) {
5468 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000404);
5469 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
5470 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
5471 } else if (rt2x00_rt(rt2x00dev, RT5592)) {
5472 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000404);
5473 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
5474 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
5475 } else if (rt2x00_rt(rt2x00dev, RT5350)) {
5476 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000404);
5477 } else if (rt2x00_rt(rt2x00dev, RT6352)) {
5478 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000401);
5479 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x000C0000);
5480 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
5481 rt2800_register_write(rt2x00dev, MIMO_PS_CFG, 0x00000002);
5482 rt2800_register_write(rt2x00dev, TX_PIN_CFG, 0x00150F0F);
5483 rt2800_register_write(rt2x00dev, TX_ALC_VGA3, 0x00000000);
5484 rt2800_register_write(rt2x00dev, TX0_BB_GAIN_ATTEN, 0x0);
5485 rt2800_register_write(rt2x00dev, TX1_BB_GAIN_ATTEN, 0x0);
5486 rt2800_register_write(rt2x00dev, TX0_RF_GAIN_ATTEN, 0x6C6C666C);
5487 rt2800_register_write(rt2x00dev, TX1_RF_GAIN_ATTEN, 0x6C6C666C);
5488 rt2800_register_write(rt2x00dev, TX0_RF_GAIN_CORRECT,
5489 0x3630363A);
5490 rt2800_register_write(rt2x00dev, TX1_RF_GAIN_CORRECT,
5491 0x3630363A);
5492 reg = rt2800_register_read(rt2x00dev, TX_ALC_CFG_1);
5493 rt2x00_set_field32(&reg, TX_ALC_CFG_1_ROS_BUSY_EN, 0);
5494 rt2800_register_write(rt2x00dev, TX_ALC_CFG_1, reg);
5495 } else {
5496 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000000);
5497 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
5500 reg = rt2800_register_read(rt2x00dev, TX_LINK_CFG);
5501 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB_LIFETIME, 32);
5502 rt2x00_set_field32(&reg, TX_LINK_CFG_MFB_ENABLE, 0);
5503 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_UMFS_ENABLE, 0);
5504 rt2x00_set_field32(&reg, TX_LINK_CFG_TX_MRQ_EN, 0);
5505 rt2x00_set_field32(&reg, TX_LINK_CFG_TX_RDG_EN, 0);
5506 rt2x00_set_field32(&reg, TX_LINK_CFG_TX_CF_ACK_EN, 1);
5507 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB, 0);
5508 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFS, 0);
5509 rt2800_register_write(rt2x00dev, TX_LINK_CFG, reg);
5511 reg = rt2800_register_read(rt2x00dev, TX_TIMEOUT_CFG);
5512 rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_MPDU_LIFETIME, 9);
5513 rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_RX_ACK_TIMEOUT, 32);
5514 rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_TX_OP_TIMEOUT, 10);
5515 rt2800_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
5517 reg = rt2800_register_read(rt2x00dev, MAX_LEN_CFG);
5518 rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_MPDU, AGGREGATION_SIZE);
5519 if (rt2x00_is_usb(rt2x00dev)) {
5520 drv_data->max_psdu = 3;
5521 } else if (rt2x00_rt_rev_gte(rt2x00dev, RT2872, REV_RT2872E) ||
5522 rt2x00_rt(rt2x00dev, RT2883) ||
5523 rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070E)) {
5524 drv_data->max_psdu = 2;
5525 } else {
5526 drv_data->max_psdu = 1;
5528 rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, drv_data->max_psdu);
5529 rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_PSDU, 10);
5530 rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_MPDU, 10);
5531 rt2800_register_write(rt2x00dev, MAX_LEN_CFG, reg);
5533 reg = rt2800_register_read(rt2x00dev, LED_CFG);
5534 rt2x00_set_field32(&reg, LED_CFG_ON_PERIOD, 70);
5535 rt2x00_set_field32(&reg, LED_CFG_OFF_PERIOD, 30);
5536 rt2x00_set_field32(&reg, LED_CFG_SLOW_BLINK_PERIOD, 3);
5537 rt2x00_set_field32(&reg, LED_CFG_R_LED_MODE, 3);
5538 rt2x00_set_field32(&reg, LED_CFG_G_LED_MODE, 3);
5539 rt2x00_set_field32(&reg, LED_CFG_Y_LED_MODE, 3);
5540 rt2x00_set_field32(&reg, LED_CFG_LED_POLAR, 1);
5541 rt2800_register_write(rt2x00dev, LED_CFG, reg);
5543 rt2800_register_write(rt2x00dev, PBF_MAX_PCNT, 0x1f3fbf9f);
5545 reg = rt2800_register_read(rt2x00dev, TX_RTY_CFG);
5546 rt2x00_set_field32(&reg, TX_RTY_CFG_SHORT_RTY_LIMIT, 2);
5547 rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_LIMIT, 2);
5548 rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_THRE, 2000);
5549 rt2x00_set_field32(&reg, TX_RTY_CFG_NON_AGG_RTY_MODE, 0);
5550 rt2x00_set_field32(&reg, TX_RTY_CFG_AGG_RTY_MODE, 0);
5551 rt2x00_set_field32(&reg, TX_RTY_CFG_TX_AUTO_FB_ENABLE, 1);
5552 rt2800_register_write(rt2x00dev, TX_RTY_CFG, reg);
5554 reg = rt2800_register_read(rt2x00dev, AUTO_RSP_CFG);
5555 rt2x00_set_field32(&reg, AUTO_RSP_CFG_AUTORESPONDER, 1);
5556 rt2x00_set_field32(&reg, AUTO_RSP_CFG_BAC_ACK_POLICY, 1);
5557 rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MMODE, 1);
5558 rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MREF, 0);
5559 rt2x00_set_field32(&reg, AUTO_RSP_CFG_AR_PREAMBLE, 0);
5560 rt2x00_set_field32(&reg, AUTO_RSP_CFG_DUAL_CTS_EN, 0);
5561 rt2x00_set_field32(&reg, AUTO_RSP_CFG_ACK_CTS_PSM_BIT, 0);
5562 rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
5564 reg = rt2800_register_read(rt2x00dev, CCK_PROT_CFG);
5565 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_RATE, 3);
5566 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_CTRL, 0);
5567 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_NAV_SHORT, 1);
5568 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_CCK, 1);
5569 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
5570 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM20, 1);
5571 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM40, 0);
5572 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF20, 1);
5573 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF40, 0);
5574 rt2x00_set_field32(&reg, CCK_PROT_CFG_RTS_TH_EN, 1);
5575 rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg);
5577 reg = rt2800_register_read(rt2x00dev, OFDM_PROT_CFG);
5578 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_RATE, 3);
5579 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL, 0);
5580 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_NAV_SHORT, 1);
5581 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_CCK, 1);
5582 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
5583 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM20, 1);
5584 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM40, 0);
5585 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF20, 1);
5586 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF40, 0);
5587 rt2x00_set_field32(&reg, OFDM_PROT_CFG_RTS_TH_EN, 1);
5588 rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
5590 reg = rt2800_register_read(rt2x00dev, MM20_PROT_CFG);
5591 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_RATE, 0x4004);
5592 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_CTRL, 1);
5593 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_NAV_SHORT, 1);
5594 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_CCK, 0);
5595 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
5596 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
5597 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
5598 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
5599 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
5600 rt2x00_set_field32(&reg, MM20_PROT_CFG_RTS_TH_EN, 0);
5601 rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
5603 reg = rt2800_register_read(rt2x00dev, MM40_PROT_CFG);
5604 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_RATE, 0x4084);
5605 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_CTRL, 1);
5606 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_NAV_SHORT, 1);
5607 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_CCK, 0);
5608 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
5609 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
5610 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
5611 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
5612 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
5613 rt2x00_set_field32(&reg, MM40_PROT_CFG_RTS_TH_EN, 0);
5614 rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
5616 reg = rt2800_register_read(rt2x00dev, GF20_PROT_CFG);
5617 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_RATE, 0x4004);
5618 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_CTRL, 1);
5619 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_NAV_SHORT, 1);
5620 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_CCK, 0);
5621 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
5622 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
5623 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
5624 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
5625 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
5626 rt2x00_set_field32(&reg, GF20_PROT_CFG_RTS_TH_EN, 0);
5627 rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
5629 reg = rt2800_register_read(rt2x00dev, GF40_PROT_CFG);
5630 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_RATE, 0x4084);
5631 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_CTRL, 1);
5632 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_NAV_SHORT, 1);
5633 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_CCK, 0);
5634 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
5635 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
5636 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
5637 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
5638 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
5639 rt2x00_set_field32(&reg, GF40_PROT_CFG_RTS_TH_EN, 0);
5640 rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
5642 if (rt2x00_is_usb(rt2x00dev)) {
5643 rt2800_register_write(rt2x00dev, PBF_CFG, 0xf40006);
5645 reg = rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG);
5646 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
5647 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
5648 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
5649 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
5650 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 3);
5651 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 0);
5652 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_BIG_ENDIAN, 0);
5653 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_HDR_SCATTER, 0);
5654 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_HDR_SEG_LEN, 0);
5655 rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
5659 * The legacy driver also sets TXOP_CTRL_CFG_RESERVED_TRUN_EN to 1
5660 * although it is reserved.
5662 reg = rt2800_register_read(rt2x00dev, TXOP_CTRL_CFG);
5663 rt2x00_set_field32(&reg, TXOP_CTRL_CFG_TIMEOUT_TRUN_EN, 1);
5664 rt2x00_set_field32(&reg, TXOP_CTRL_CFG_AC_TRUN_EN, 1);
5665 rt2x00_set_field32(&reg, TXOP_CTRL_CFG_TXRATEGRP_TRUN_EN, 1);
5666 rt2x00_set_field32(&reg, TXOP_CTRL_CFG_USER_MODE_TRUN_EN, 1);
5667 rt2x00_set_field32(&reg, TXOP_CTRL_CFG_MIMO_PS_TRUN_EN, 1);
5668 rt2x00_set_field32(&reg, TXOP_CTRL_CFG_RESERVED_TRUN_EN, 1);
5669 rt2x00_set_field32(&reg, TXOP_CTRL_CFG_LSIG_TXOP_EN, 0);
5670 rt2x00_set_field32(&reg, TXOP_CTRL_CFG_EXT_CCA_EN, 0);
5671 rt2x00_set_field32(&reg, TXOP_CTRL_CFG_EXT_CCA_DLY, 88);
5672 rt2x00_set_field32(&reg, TXOP_CTRL_CFG_EXT_CWMIN, 0);
5673 rt2800_register_write(rt2x00dev, TXOP_CTRL_CFG, reg);
5675 reg = rt2x00_rt(rt2x00dev, RT5592) ? 0x00000082 : 0x00000002;
5676 rt2800_register_write(rt2x00dev, TXOP_HLDR_ET, reg);
5678 reg = rt2800_register_read(rt2x00dev, TX_RTS_CFG);
5679 rt2x00_set_field32(&reg, TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT, 7);
5680 rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES,
5681 IEEE80211_MAX_RTS_THRESHOLD);
5682 rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_FBK_EN, 1);
5683 rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg);
5685 rt2800_register_write(rt2x00dev, EXP_ACK_TIME, 0x002400ca);
5688 * Usually the CCK SIFS time should be set to 10 and the OFDM SIFS
5689 * time should be set to 16. However, the original Ralink driver uses
5690 * 16 for both and indeed using a value of 10 for CCK SIFS results in
5691 * connection problems with 11g + CTS protection. Hence, use the same
5692 * defaults as the Ralink driver: 16 for both, CCK and OFDM SIFS.
5694 reg = rt2800_register_read(rt2x00dev, XIFS_TIME_CFG);
5695 rt2x00_set_field32(&reg, XIFS_TIME_CFG_CCKM_SIFS_TIME, 16);
5696 rt2x00_set_field32(&reg, XIFS_TIME_CFG_OFDM_SIFS_TIME, 16);
5697 rt2x00_set_field32(&reg, XIFS_TIME_CFG_OFDM_XIFS_TIME, 4);
5698 rt2x00_set_field32(&reg, XIFS_TIME_CFG_EIFS, 314);
5699 rt2x00_set_field32(&reg, XIFS_TIME_CFG_BB_RXEND_ENABLE, 1);
5700 rt2800_register_write(rt2x00dev, XIFS_TIME_CFG, reg);
5702 rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
5705 * ASIC will keep garbage value after boot, clear encryption keys.
5707 for (i = 0; i < 4; i++)
5708 rt2800_register_write(rt2x00dev,
5709 SHARED_KEY_MODE_ENTRY(i), 0);
5711 for (i = 0; i < 256; i++) {
5712 rt2800_config_wcid(rt2x00dev, NULL, i);
5713 rt2800_delete_wcid_attr(rt2x00dev, i);
5714 rt2800_register_write(rt2x00dev, MAC_IVEIV_ENTRY(i), 0);
5718 * Clear all beacons
5720 for (i = 0; i < 8; i++)
5721 rt2800_clear_beacon_register(rt2x00dev, i);
5723 if (rt2x00_is_usb(rt2x00dev)) {
5724 reg = rt2800_register_read(rt2x00dev, US_CYC_CNT);
5725 rt2x00_set_field32(&reg, US_CYC_CNT_CLOCK_CYCLE, 30);
5726 rt2800_register_write(rt2x00dev, US_CYC_CNT, reg);
5727 } else if (rt2x00_is_pcie(rt2x00dev)) {
5728 reg = rt2800_register_read(rt2x00dev, US_CYC_CNT);
5729 rt2x00_set_field32(&reg, US_CYC_CNT_CLOCK_CYCLE, 125);
5730 rt2800_register_write(rt2x00dev, US_CYC_CNT, reg);
5733 reg = rt2800_register_read(rt2x00dev, HT_FBK_CFG0);
5734 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS0FBK, 0);
5735 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS1FBK, 0);
5736 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS2FBK, 1);
5737 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS3FBK, 2);
5738 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS4FBK, 3);
5739 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS5FBK, 4);
5740 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS6FBK, 5);
5741 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS7FBK, 6);
5742 rt2800_register_write(rt2x00dev, HT_FBK_CFG0, reg);
5744 reg = rt2800_register_read(rt2x00dev, HT_FBK_CFG1);
5745 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS8FBK, 8);
5746 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS9FBK, 8);
5747 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS10FBK, 9);
5748 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS11FBK, 10);
5749 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS12FBK, 11);
5750 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS13FBK, 12);
5751 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS14FBK, 13);
5752 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS15FBK, 14);
5753 rt2800_register_write(rt2x00dev, HT_FBK_CFG1, reg);
5755 reg = rt2800_register_read(rt2x00dev, LG_FBK_CFG0);
5756 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS0FBK, 8);
5757 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS1FBK, 8);
5758 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS2FBK, 9);
5759 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS3FBK, 10);
5760 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS4FBK, 11);
5761 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS5FBK, 12);
5762 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS6FBK, 13);
5763 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS7FBK, 14);
5764 rt2800_register_write(rt2x00dev, LG_FBK_CFG0, reg);
5766 reg = rt2800_register_read(rt2x00dev, LG_FBK_CFG1);
5767 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS0FBK, 0);
5768 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS1FBK, 0);
5769 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS2FBK, 1);
5770 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS3FBK, 2);
5771 rt2800_register_write(rt2x00dev, LG_FBK_CFG1, reg);
5774 * Do not force the BA window size, we use the TXWI to set it
5776 reg = rt2800_register_read(rt2x00dev, AMPDU_BA_WINSIZE);
5777 rt2x00_set_field32(&reg, AMPDU_BA_WINSIZE_FORCE_WINSIZE_ENABLE, 0);
5778 rt2x00_set_field32(&reg, AMPDU_BA_WINSIZE_FORCE_WINSIZE, 0);
5779 rt2800_register_write(rt2x00dev, AMPDU_BA_WINSIZE, reg);
5782 * We must clear the error counters.
5783 * These registers are cleared on read,
5784 * so we may pass a useless variable to store the value.
5786 reg = rt2800_register_read(rt2x00dev, RX_STA_CNT0);
5787 reg = rt2800_register_read(rt2x00dev, RX_STA_CNT1);
5788 reg = rt2800_register_read(rt2x00dev, RX_STA_CNT2);
5789 reg = rt2800_register_read(rt2x00dev, TX_STA_CNT0);
5790 reg = rt2800_register_read(rt2x00dev, TX_STA_CNT1);
5791 reg = rt2800_register_read(rt2x00dev, TX_STA_CNT2);
5794 * Setup leadtime for pre tbtt interrupt to 6ms
5796 reg = rt2800_register_read(rt2x00dev, INT_TIMER_CFG);
5797 rt2x00_set_field32(&reg, INT_TIMER_CFG_PRE_TBTT_TIMER, 6 << 4);
5798 rt2800_register_write(rt2x00dev, INT_TIMER_CFG, reg);
5801 * Set up channel statistics timer
5803 reg = rt2800_register_read(rt2x00dev, CH_TIME_CFG);
5804 rt2x00_set_field32(&reg, CH_TIME_CFG_EIFS_BUSY, 1);
5805 rt2x00_set_field32(&reg, CH_TIME_CFG_NAV_BUSY, 1);
5806 rt2x00_set_field32(&reg, CH_TIME_CFG_RX_BUSY, 1);
5807 rt2x00_set_field32(&reg, CH_TIME_CFG_TX_BUSY, 1);
5808 rt2x00_set_field32(&reg, CH_TIME_CFG_TMR_EN, 1);
5809 rt2800_register_write(rt2x00dev, CH_TIME_CFG, reg);
5811 return 0;
5814 static int rt2800_wait_bbp_rf_ready(struct rt2x00_dev *rt2x00dev)
5816 unsigned int i;
5817 u32 reg;
5819 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
5820 reg = rt2800_register_read(rt2x00dev, MAC_STATUS_CFG);
5821 if (!rt2x00_get_field32(reg, MAC_STATUS_CFG_BBP_RF_BUSY))
5822 return 0;
5824 udelay(REGISTER_BUSY_DELAY);
5827 rt2x00_err(rt2x00dev, "BBP/RF register access failed, aborting\n");
5828 return -EACCES;
5831 static int rt2800_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
5833 unsigned int i;
5834 u8 value;
5837 * BBP was enabled after firmware was loaded,
5838 * but we need to reactivate it now.
5840 rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
5841 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
5842 msleep(1);
5844 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
5845 value = rt2800_bbp_read(rt2x00dev, 0);
5846 if ((value != 0xff) && (value != 0x00))
5847 return 0;
5848 udelay(REGISTER_BUSY_DELAY);
5851 rt2x00_err(rt2x00dev, "BBP register access failed, aborting\n");
5852 return -EACCES;
5855 static void rt2800_bbp4_mac_if_ctrl(struct rt2x00_dev *rt2x00dev)
5857 u8 value;
5859 value = rt2800_bbp_read(rt2x00dev, 4);
5860 rt2x00_set_field8(&value, BBP4_MAC_IF_CTRL, 1);
5861 rt2800_bbp_write(rt2x00dev, 4, value);
5864 static void rt2800_init_freq_calibration(struct rt2x00_dev *rt2x00dev)
5866 rt2800_bbp_write(rt2x00dev, 142, 1);
5867 rt2800_bbp_write(rt2x00dev, 143, 57);
5870 static void rt2800_init_bbp_5592_glrt(struct rt2x00_dev *rt2x00dev)
5872 static const u8 glrt_table[] = {
5873 0xE0, 0x1F, 0X38, 0x32, 0x08, 0x28, 0x19, 0x0A, 0xFF, 0x00, /* 128 ~ 137 */
5874 0x16, 0x10, 0x10, 0x0B, 0x36, 0x2C, 0x26, 0x24, 0x42, 0x36, /* 138 ~ 147 */
5875 0x30, 0x2D, 0x4C, 0x46, 0x3D, 0x40, 0x3E, 0x42, 0x3D, 0x40, /* 148 ~ 157 */
5876 0X3C, 0x34, 0x2C, 0x2F, 0x3C, 0x35, 0x2E, 0x2A, 0x49, 0x41, /* 158 ~ 167 */
5877 0x36, 0x31, 0x30, 0x30, 0x0E, 0x0D, 0x28, 0x21, 0x1C, 0x16, /* 168 ~ 177 */
5878 0x50, 0x4A, 0x43, 0x40, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, /* 178 ~ 187 */
5879 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 188 ~ 197 */
5880 0x00, 0x00, 0x7D, 0x14, 0x32, 0x2C, 0x36, 0x4C, 0x43, 0x2C, /* 198 ~ 207 */
5881 0x2E, 0x36, 0x30, 0x6E, /* 208 ~ 211 */
5883 int i;
5885 for (i = 0; i < ARRAY_SIZE(glrt_table); i++) {
5886 rt2800_bbp_write(rt2x00dev, 195, 128 + i);
5887 rt2800_bbp_write(rt2x00dev, 196, glrt_table[i]);
5891 static void rt2800_init_bbp_early(struct rt2x00_dev *rt2x00dev)
5893 rt2800_bbp_write(rt2x00dev, 65, 0x2C);
5894 rt2800_bbp_write(rt2x00dev, 66, 0x38);
5895 rt2800_bbp_write(rt2x00dev, 68, 0x0B);
5896 rt2800_bbp_write(rt2x00dev, 69, 0x12);
5897 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
5898 rt2800_bbp_write(rt2x00dev, 73, 0x10);
5899 rt2800_bbp_write(rt2x00dev, 81, 0x37);
5900 rt2800_bbp_write(rt2x00dev, 82, 0x62);
5901 rt2800_bbp_write(rt2x00dev, 83, 0x6A);
5902 rt2800_bbp_write(rt2x00dev, 84, 0x99);
5903 rt2800_bbp_write(rt2x00dev, 86, 0x00);
5904 rt2800_bbp_write(rt2x00dev, 91, 0x04);
5905 rt2800_bbp_write(rt2x00dev, 92, 0x00);
5906 rt2800_bbp_write(rt2x00dev, 103, 0x00);
5907 rt2800_bbp_write(rt2x00dev, 105, 0x05);
5908 rt2800_bbp_write(rt2x00dev, 106, 0x35);
5911 static void rt2800_disable_unused_dac_adc(struct rt2x00_dev *rt2x00dev)
5913 u16 eeprom;
5914 u8 value;
5916 value = rt2800_bbp_read(rt2x00dev, 138);
5917 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0);
5918 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) == 1)
5919 value |= 0x20;
5920 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) == 1)
5921 value &= ~0x02;
5922 rt2800_bbp_write(rt2x00dev, 138, value);
5925 static void rt2800_init_bbp_305x_soc(struct rt2x00_dev *rt2x00dev)
5927 rt2800_bbp_write(rt2x00dev, 31, 0x08);
5929 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
5930 rt2800_bbp_write(rt2x00dev, 66, 0x38);
5932 rt2800_bbp_write(rt2x00dev, 69, 0x12);
5933 rt2800_bbp_write(rt2x00dev, 73, 0x10);
5935 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
5937 rt2800_bbp_write(rt2x00dev, 78, 0x0e);
5938 rt2800_bbp_write(rt2x00dev, 80, 0x08);
5940 rt2800_bbp_write(rt2x00dev, 82, 0x62);
5942 rt2800_bbp_write(rt2x00dev, 83, 0x6a);
5944 rt2800_bbp_write(rt2x00dev, 84, 0x99);
5946 rt2800_bbp_write(rt2x00dev, 86, 0x00);
5948 rt2800_bbp_write(rt2x00dev, 91, 0x04);
5950 rt2800_bbp_write(rt2x00dev, 92, 0x00);
5952 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
5954 rt2800_bbp_write(rt2x00dev, 105, 0x01);
5956 rt2800_bbp_write(rt2x00dev, 106, 0x35);
5959 static void rt2800_init_bbp_28xx(struct rt2x00_dev *rt2x00dev)
5961 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
5962 rt2800_bbp_write(rt2x00dev, 66, 0x38);
5964 if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) {
5965 rt2800_bbp_write(rt2x00dev, 69, 0x16);
5966 rt2800_bbp_write(rt2x00dev, 73, 0x12);
5967 } else {
5968 rt2800_bbp_write(rt2x00dev, 69, 0x12);
5969 rt2800_bbp_write(rt2x00dev, 73, 0x10);
5972 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
5974 rt2800_bbp_write(rt2x00dev, 81, 0x37);
5976 rt2800_bbp_write(rt2x00dev, 82, 0x62);
5978 rt2800_bbp_write(rt2x00dev, 83, 0x6a);
5980 if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860D))
5981 rt2800_bbp_write(rt2x00dev, 84, 0x19);
5982 else
5983 rt2800_bbp_write(rt2x00dev, 84, 0x99);
5985 rt2800_bbp_write(rt2x00dev, 86, 0x00);
5987 rt2800_bbp_write(rt2x00dev, 91, 0x04);
5989 rt2800_bbp_write(rt2x00dev, 92, 0x00);
5991 rt2800_bbp_write(rt2x00dev, 103, 0x00);
5993 rt2800_bbp_write(rt2x00dev, 105, 0x05);
5995 rt2800_bbp_write(rt2x00dev, 106, 0x35);
5998 static void rt2800_init_bbp_30xx(struct rt2x00_dev *rt2x00dev)
6000 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
6001 rt2800_bbp_write(rt2x00dev, 66, 0x38);
6003 rt2800_bbp_write(rt2x00dev, 69, 0x12);
6004 rt2800_bbp_write(rt2x00dev, 73, 0x10);
6006 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
6008 rt2800_bbp_write(rt2x00dev, 79, 0x13);
6009 rt2800_bbp_write(rt2x00dev, 80, 0x05);
6010 rt2800_bbp_write(rt2x00dev, 81, 0x33);
6012 rt2800_bbp_write(rt2x00dev, 82, 0x62);
6014 rt2800_bbp_write(rt2x00dev, 83, 0x6a);
6016 rt2800_bbp_write(rt2x00dev, 84, 0x99);
6018 rt2800_bbp_write(rt2x00dev, 86, 0x00);
6020 rt2800_bbp_write(rt2x00dev, 91, 0x04);
6022 rt2800_bbp_write(rt2x00dev, 92, 0x00);
6024 if (rt2x00_rt_rev_gte(rt2x00dev, RT3070, REV_RT3070F) ||
6025 rt2x00_rt_rev_gte(rt2x00dev, RT3071, REV_RT3071E) ||
6026 rt2x00_rt_rev_gte(rt2x00dev, RT3090, REV_RT3090E))
6027 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
6028 else
6029 rt2800_bbp_write(rt2x00dev, 103, 0x00);
6031 rt2800_bbp_write(rt2x00dev, 105, 0x05);
6033 rt2800_bbp_write(rt2x00dev, 106, 0x35);
6035 if (rt2x00_rt(rt2x00dev, RT3071) ||
6036 rt2x00_rt(rt2x00dev, RT3090))
6037 rt2800_disable_unused_dac_adc(rt2x00dev);
6040 static void rt2800_init_bbp_3290(struct rt2x00_dev *rt2x00dev)
6042 u8 value;
6044 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
6046 rt2800_bbp_write(rt2x00dev, 31, 0x08);
6048 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
6049 rt2800_bbp_write(rt2x00dev, 66, 0x38);
6051 rt2800_bbp_write(rt2x00dev, 68, 0x0b);
6053 rt2800_bbp_write(rt2x00dev, 69, 0x12);
6054 rt2800_bbp_write(rt2x00dev, 73, 0x13);
6055 rt2800_bbp_write(rt2x00dev, 75, 0x46);
6056 rt2800_bbp_write(rt2x00dev, 76, 0x28);
6058 rt2800_bbp_write(rt2x00dev, 77, 0x58);
6060 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
6062 rt2800_bbp_write(rt2x00dev, 74, 0x0b);
6063 rt2800_bbp_write(rt2x00dev, 79, 0x18);
6064 rt2800_bbp_write(rt2x00dev, 80, 0x09);
6065 rt2800_bbp_write(rt2x00dev, 81, 0x33);
6067 rt2800_bbp_write(rt2x00dev, 82, 0x62);
6069 rt2800_bbp_write(rt2x00dev, 83, 0x7a);
6071 rt2800_bbp_write(rt2x00dev, 84, 0x9a);
6073 rt2800_bbp_write(rt2x00dev, 86, 0x38);
6075 rt2800_bbp_write(rt2x00dev, 91, 0x04);
6077 rt2800_bbp_write(rt2x00dev, 92, 0x02);
6079 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
6081 rt2800_bbp_write(rt2x00dev, 104, 0x92);
6083 rt2800_bbp_write(rt2x00dev, 105, 0x1c);
6085 rt2800_bbp_write(rt2x00dev, 106, 0x03);
6087 rt2800_bbp_write(rt2x00dev, 128, 0x12);
6089 rt2800_bbp_write(rt2x00dev, 67, 0x24);
6090 rt2800_bbp_write(rt2x00dev, 143, 0x04);
6091 rt2800_bbp_write(rt2x00dev, 142, 0x99);
6092 rt2800_bbp_write(rt2x00dev, 150, 0x30);
6093 rt2800_bbp_write(rt2x00dev, 151, 0x2e);
6094 rt2800_bbp_write(rt2x00dev, 152, 0x20);
6095 rt2800_bbp_write(rt2x00dev, 153, 0x34);
6096 rt2800_bbp_write(rt2x00dev, 154, 0x40);
6097 rt2800_bbp_write(rt2x00dev, 155, 0x3b);
6098 rt2800_bbp_write(rt2x00dev, 253, 0x04);
6100 value = rt2800_bbp_read(rt2x00dev, 47);
6101 rt2x00_set_field8(&value, BBP47_TSSI_ADC6, 1);
6102 rt2800_bbp_write(rt2x00dev, 47, value);
6104 /* Use 5-bit ADC for Acquisition and 8-bit ADC for data */
6105 value = rt2800_bbp_read(rt2x00dev, 3);
6106 rt2x00_set_field8(&value, BBP3_ADC_MODE_SWITCH, 1);
6107 rt2x00_set_field8(&value, BBP3_ADC_INIT_MODE, 1);
6108 rt2800_bbp_write(rt2x00dev, 3, value);
6111 static void rt2800_init_bbp_3352(struct rt2x00_dev *rt2x00dev)
6113 rt2800_bbp_write(rt2x00dev, 3, 0x00);
6114 rt2800_bbp_write(rt2x00dev, 4, 0x50);
6116 rt2800_bbp_write(rt2x00dev, 31, 0x08);
6118 rt2800_bbp_write(rt2x00dev, 47, 0x48);
6120 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
6121 rt2800_bbp_write(rt2x00dev, 66, 0x38);
6123 rt2800_bbp_write(rt2x00dev, 68, 0x0b);
6125 rt2800_bbp_write(rt2x00dev, 69, 0x12);
6126 rt2800_bbp_write(rt2x00dev, 73, 0x13);
6127 rt2800_bbp_write(rt2x00dev, 75, 0x46);
6128 rt2800_bbp_write(rt2x00dev, 76, 0x28);
6130 rt2800_bbp_write(rt2x00dev, 77, 0x59);
6132 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
6134 rt2800_bbp_write(rt2x00dev, 78, 0x0e);
6135 rt2800_bbp_write(rt2x00dev, 80, 0x08);
6136 rt2800_bbp_write(rt2x00dev, 81, 0x37);
6138 rt2800_bbp_write(rt2x00dev, 82, 0x62);
6140 if (rt2x00_rt(rt2x00dev, RT5350)) {
6141 rt2800_bbp_write(rt2x00dev, 83, 0x7a);
6142 rt2800_bbp_write(rt2x00dev, 84, 0x9a);
6143 } else {
6144 rt2800_bbp_write(rt2x00dev, 83, 0x6a);
6145 rt2800_bbp_write(rt2x00dev, 84, 0x99);
6148 rt2800_bbp_write(rt2x00dev, 86, 0x38);
6150 rt2800_bbp_write(rt2x00dev, 88, 0x90);
6152 rt2800_bbp_write(rt2x00dev, 91, 0x04);
6154 rt2800_bbp_write(rt2x00dev, 92, 0x02);
6156 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
6158 rt2800_bbp_write(rt2x00dev, 104, 0x92);
6160 if (rt2x00_rt(rt2x00dev, RT5350)) {
6161 rt2800_bbp_write(rt2x00dev, 105, 0x3c);
6162 rt2800_bbp_write(rt2x00dev, 106, 0x03);
6163 } else {
6164 rt2800_bbp_write(rt2x00dev, 105, 0x34);
6165 rt2800_bbp_write(rt2x00dev, 106, 0x05);
6168 rt2800_bbp_write(rt2x00dev, 120, 0x50);
6170 rt2800_bbp_write(rt2x00dev, 137, 0x0f);
6172 rt2800_bbp_write(rt2x00dev, 163, 0xbd);
6173 /* Set ITxBF timeout to 0x9c40=1000msec */
6174 rt2800_bbp_write(rt2x00dev, 179, 0x02);
6175 rt2800_bbp_write(rt2x00dev, 180, 0x00);
6176 rt2800_bbp_write(rt2x00dev, 182, 0x40);
6177 rt2800_bbp_write(rt2x00dev, 180, 0x01);
6178 rt2800_bbp_write(rt2x00dev, 182, 0x9c);
6179 rt2800_bbp_write(rt2x00dev, 179, 0x00);
6180 /* Reprogram the inband interface to put right values in RXWI */
6181 rt2800_bbp_write(rt2x00dev, 142, 0x04);
6182 rt2800_bbp_write(rt2x00dev, 143, 0x3b);
6183 rt2800_bbp_write(rt2x00dev, 142, 0x06);
6184 rt2800_bbp_write(rt2x00dev, 143, 0xa0);
6185 rt2800_bbp_write(rt2x00dev, 142, 0x07);
6186 rt2800_bbp_write(rt2x00dev, 143, 0xa1);
6187 rt2800_bbp_write(rt2x00dev, 142, 0x08);
6188 rt2800_bbp_write(rt2x00dev, 143, 0xa2);
6190 rt2800_bbp_write(rt2x00dev, 148, 0xc8);
6192 if (rt2x00_rt(rt2x00dev, RT5350)) {
6193 /* Antenna Software OFDM */
6194 rt2800_bbp_write(rt2x00dev, 150, 0x40);
6195 /* Antenna Software CCK */
6196 rt2800_bbp_write(rt2x00dev, 151, 0x30);
6197 rt2800_bbp_write(rt2x00dev, 152, 0xa3);
6198 /* Clear previously selected antenna */
6199 rt2800_bbp_write(rt2x00dev, 154, 0);
6203 static void rt2800_init_bbp_3390(struct rt2x00_dev *rt2x00dev)
6205 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
6206 rt2800_bbp_write(rt2x00dev, 66, 0x38);
6208 rt2800_bbp_write(rt2x00dev, 69, 0x12);
6209 rt2800_bbp_write(rt2x00dev, 73, 0x10);
6211 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
6213 rt2800_bbp_write(rt2x00dev, 79, 0x13);
6214 rt2800_bbp_write(rt2x00dev, 80, 0x05);
6215 rt2800_bbp_write(rt2x00dev, 81, 0x33);
6217 rt2800_bbp_write(rt2x00dev, 82, 0x62);
6219 rt2800_bbp_write(rt2x00dev, 83, 0x6a);
6221 rt2800_bbp_write(rt2x00dev, 84, 0x99);
6223 rt2800_bbp_write(rt2x00dev, 86, 0x00);
6225 rt2800_bbp_write(rt2x00dev, 91, 0x04);
6227 rt2800_bbp_write(rt2x00dev, 92, 0x00);
6229 if (rt2x00_rt_rev_gte(rt2x00dev, RT3390, REV_RT3390E))
6230 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
6231 else
6232 rt2800_bbp_write(rt2x00dev, 103, 0x00);
6234 rt2800_bbp_write(rt2x00dev, 105, 0x05);
6236 rt2800_bbp_write(rt2x00dev, 106, 0x35);
6238 rt2800_disable_unused_dac_adc(rt2x00dev);
6241 static void rt2800_init_bbp_3572(struct rt2x00_dev *rt2x00dev)
6243 rt2800_bbp_write(rt2x00dev, 31, 0x08);
6245 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
6246 rt2800_bbp_write(rt2x00dev, 66, 0x38);
6248 rt2800_bbp_write(rt2x00dev, 69, 0x12);
6249 rt2800_bbp_write(rt2x00dev, 73, 0x10);
6251 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
6253 rt2800_bbp_write(rt2x00dev, 79, 0x13);
6254 rt2800_bbp_write(rt2x00dev, 80, 0x05);
6255 rt2800_bbp_write(rt2x00dev, 81, 0x33);
6257 rt2800_bbp_write(rt2x00dev, 82, 0x62);
6259 rt2800_bbp_write(rt2x00dev, 83, 0x6a);
6261 rt2800_bbp_write(rt2x00dev, 84, 0x99);
6263 rt2800_bbp_write(rt2x00dev, 86, 0x00);
6265 rt2800_bbp_write(rt2x00dev, 91, 0x04);
6267 rt2800_bbp_write(rt2x00dev, 92, 0x00);
6269 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
6271 rt2800_bbp_write(rt2x00dev, 105, 0x05);
6273 rt2800_bbp_write(rt2x00dev, 106, 0x35);
6275 rt2800_disable_unused_dac_adc(rt2x00dev);
6278 static void rt2800_init_bbp_3593(struct rt2x00_dev *rt2x00dev)
6280 rt2800_init_bbp_early(rt2x00dev);
6282 rt2800_bbp_write(rt2x00dev, 79, 0x13);
6283 rt2800_bbp_write(rt2x00dev, 80, 0x05);
6284 rt2800_bbp_write(rt2x00dev, 81, 0x33);
6285 rt2800_bbp_write(rt2x00dev, 137, 0x0f);
6287 rt2800_bbp_write(rt2x00dev, 84, 0x19);
6289 /* Enable DC filter */
6290 if (rt2x00_rt_rev_gte(rt2x00dev, RT3593, REV_RT3593E))
6291 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
6294 static void rt2800_init_bbp_53xx(struct rt2x00_dev *rt2x00dev)
6296 int ant, div_mode;
6297 u16 eeprom;
6298 u8 value;
6300 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
6302 rt2800_bbp_write(rt2x00dev, 31, 0x08);
6304 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
6305 rt2800_bbp_write(rt2x00dev, 66, 0x38);
6307 rt2800_bbp_write(rt2x00dev, 68, 0x0b);
6309 rt2800_bbp_write(rt2x00dev, 69, 0x12);
6310 rt2800_bbp_write(rt2x00dev, 73, 0x13);
6311 rt2800_bbp_write(rt2x00dev, 75, 0x46);
6312 rt2800_bbp_write(rt2x00dev, 76, 0x28);
6314 rt2800_bbp_write(rt2x00dev, 77, 0x59);
6316 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
6318 rt2800_bbp_write(rt2x00dev, 79, 0x13);
6319 rt2800_bbp_write(rt2x00dev, 80, 0x05);
6320 rt2800_bbp_write(rt2x00dev, 81, 0x33);
6322 rt2800_bbp_write(rt2x00dev, 82, 0x62);
6324 rt2800_bbp_write(rt2x00dev, 83, 0x7a);
6326 rt2800_bbp_write(rt2x00dev, 84, 0x9a);
6328 rt2800_bbp_write(rt2x00dev, 86, 0x38);
6330 if (rt2x00_rt(rt2x00dev, RT5392))
6331 rt2800_bbp_write(rt2x00dev, 88, 0x90);
6333 rt2800_bbp_write(rt2x00dev, 91, 0x04);
6335 rt2800_bbp_write(rt2x00dev, 92, 0x02);
6337 if (rt2x00_rt(rt2x00dev, RT5392)) {
6338 rt2800_bbp_write(rt2x00dev, 95, 0x9a);
6339 rt2800_bbp_write(rt2x00dev, 98, 0x12);
6342 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
6344 rt2800_bbp_write(rt2x00dev, 104, 0x92);
6346 rt2800_bbp_write(rt2x00dev, 105, 0x3c);
6348 if (rt2x00_rt(rt2x00dev, RT5390))
6349 rt2800_bbp_write(rt2x00dev, 106, 0x03);
6350 else if (rt2x00_rt(rt2x00dev, RT5392))
6351 rt2800_bbp_write(rt2x00dev, 106, 0x12);
6352 else
6353 WARN_ON(1);
6355 rt2800_bbp_write(rt2x00dev, 128, 0x12);
6357 if (rt2x00_rt(rt2x00dev, RT5392)) {
6358 rt2800_bbp_write(rt2x00dev, 134, 0xd0);
6359 rt2800_bbp_write(rt2x00dev, 135, 0xf6);
6362 rt2800_disable_unused_dac_adc(rt2x00dev);
6364 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1);
6365 div_mode = rt2x00_get_field16(eeprom,
6366 EEPROM_NIC_CONF1_ANT_DIVERSITY);
6367 ant = (div_mode == 3) ? 1 : 0;
6369 /* check if this is a Bluetooth combo card */
6370 if (rt2x00_has_cap_bt_coexist(rt2x00dev)) {
6371 u32 reg;
6373 reg = rt2800_register_read(rt2x00dev, GPIO_CTRL);
6374 rt2x00_set_field32(&reg, GPIO_CTRL_DIR3, 0);
6375 rt2x00_set_field32(&reg, GPIO_CTRL_DIR6, 0);
6376 rt2x00_set_field32(&reg, GPIO_CTRL_VAL3, 0);
6377 rt2x00_set_field32(&reg, GPIO_CTRL_VAL6, 0);
6378 if (ant == 0)
6379 rt2x00_set_field32(&reg, GPIO_CTRL_VAL3, 1);
6380 else if (ant == 1)
6381 rt2x00_set_field32(&reg, GPIO_CTRL_VAL6, 1);
6382 rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
6385 /* These chips have hardware RX antenna diversity */
6386 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390R) ||
6387 rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5370G)) {
6388 rt2800_bbp_write(rt2x00dev, 150, 0); /* Disable Antenna Software OFDM */
6389 rt2800_bbp_write(rt2x00dev, 151, 0); /* Disable Antenna Software CCK */
6390 rt2800_bbp_write(rt2x00dev, 154, 0); /* Clear previously selected antenna */
6393 value = rt2800_bbp_read(rt2x00dev, 152);
6394 if (ant == 0)
6395 rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 1);
6396 else
6397 rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 0);
6398 rt2800_bbp_write(rt2x00dev, 152, value);
6400 rt2800_init_freq_calibration(rt2x00dev);
6403 static void rt2800_init_bbp_5592(struct rt2x00_dev *rt2x00dev)
6405 int ant, div_mode;
6406 u16 eeprom;
6407 u8 value;
6409 rt2800_init_bbp_early(rt2x00dev);
6411 value = rt2800_bbp_read(rt2x00dev, 105);
6412 rt2x00_set_field8(&value, BBP105_MLD,
6413 rt2x00dev->default_ant.rx_chain_num == 2);
6414 rt2800_bbp_write(rt2x00dev, 105, value);
6416 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
6418 rt2800_bbp_write(rt2x00dev, 20, 0x06);
6419 rt2800_bbp_write(rt2x00dev, 31, 0x08);
6420 rt2800_bbp_write(rt2x00dev, 65, 0x2C);
6421 rt2800_bbp_write(rt2x00dev, 68, 0xDD);
6422 rt2800_bbp_write(rt2x00dev, 69, 0x1A);
6423 rt2800_bbp_write(rt2x00dev, 70, 0x05);
6424 rt2800_bbp_write(rt2x00dev, 73, 0x13);
6425 rt2800_bbp_write(rt2x00dev, 74, 0x0F);
6426 rt2800_bbp_write(rt2x00dev, 75, 0x4F);
6427 rt2800_bbp_write(rt2x00dev, 76, 0x28);
6428 rt2800_bbp_write(rt2x00dev, 77, 0x59);
6429 rt2800_bbp_write(rt2x00dev, 84, 0x9A);
6430 rt2800_bbp_write(rt2x00dev, 86, 0x38);
6431 rt2800_bbp_write(rt2x00dev, 88, 0x90);
6432 rt2800_bbp_write(rt2x00dev, 91, 0x04);
6433 rt2800_bbp_write(rt2x00dev, 92, 0x02);
6434 rt2800_bbp_write(rt2x00dev, 95, 0x9a);
6435 rt2800_bbp_write(rt2x00dev, 98, 0x12);
6436 rt2800_bbp_write(rt2x00dev, 103, 0xC0);
6437 rt2800_bbp_write(rt2x00dev, 104, 0x92);
6438 /* FIXME BBP105 owerwrite */
6439 rt2800_bbp_write(rt2x00dev, 105, 0x3C);
6440 rt2800_bbp_write(rt2x00dev, 106, 0x35);
6441 rt2800_bbp_write(rt2x00dev, 128, 0x12);
6442 rt2800_bbp_write(rt2x00dev, 134, 0xD0);
6443 rt2800_bbp_write(rt2x00dev, 135, 0xF6);
6444 rt2800_bbp_write(rt2x00dev, 137, 0x0F);
6446 /* Initialize GLRT (Generalized Likehood Radio Test) */
6447 rt2800_init_bbp_5592_glrt(rt2x00dev);
6449 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
6451 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1);
6452 div_mode = rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_ANT_DIVERSITY);
6453 ant = (div_mode == 3) ? 1 : 0;
6454 value = rt2800_bbp_read(rt2x00dev, 152);
6455 if (ant == 0) {
6456 /* Main antenna */
6457 rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 1);
6458 } else {
6459 /* Auxiliary antenna */
6460 rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 0);
6462 rt2800_bbp_write(rt2x00dev, 152, value);
6464 if (rt2x00_rt_rev_gte(rt2x00dev, RT5592, REV_RT5592C)) {
6465 value = rt2800_bbp_read(rt2x00dev, 254);
6466 rt2x00_set_field8(&value, BBP254_BIT7, 1);
6467 rt2800_bbp_write(rt2x00dev, 254, value);
6470 rt2800_init_freq_calibration(rt2x00dev);
6472 rt2800_bbp_write(rt2x00dev, 84, 0x19);
6473 if (rt2x00_rt_rev_gte(rt2x00dev, RT5592, REV_RT5592C))
6474 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
6477 static void rt2800_bbp_glrt_write(struct rt2x00_dev *rt2x00dev,
6478 const u8 reg, const u8 value)
6480 rt2800_bbp_write(rt2x00dev, 195, reg);
6481 rt2800_bbp_write(rt2x00dev, 196, value);
6484 static void rt2800_bbp_dcoc_write(struct rt2x00_dev *rt2x00dev,
6485 const u8 reg, const u8 value)
6487 rt2800_bbp_write(rt2x00dev, 158, reg);
6488 rt2800_bbp_write(rt2x00dev, 159, value);
6491 static u8 rt2800_bbp_dcoc_read(struct rt2x00_dev *rt2x00dev, const u8 reg)
6493 rt2800_bbp_write(rt2x00dev, 158, reg);
6494 return rt2800_bbp_read(rt2x00dev, 159);
6497 static void rt2800_init_bbp_6352(struct rt2x00_dev *rt2x00dev)
6499 u8 bbp;
6501 /* Apply Maximum Likelihood Detection (MLD) for 2 stream case */
6502 bbp = rt2800_bbp_read(rt2x00dev, 105);
6503 rt2x00_set_field8(&bbp, BBP105_MLD,
6504 rt2x00dev->default_ant.rx_chain_num == 2);
6505 rt2800_bbp_write(rt2x00dev, 105, bbp);
6507 /* Avoid data loss and CRC errors */
6508 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
6510 /* Fix I/Q swap issue */
6511 bbp = rt2800_bbp_read(rt2x00dev, 1);
6512 bbp |= 0x04;
6513 rt2800_bbp_write(rt2x00dev, 1, bbp);
6515 /* BBP for G band */
6516 rt2800_bbp_write(rt2x00dev, 3, 0x08);
6517 rt2800_bbp_write(rt2x00dev, 4, 0x00); /* rt2800_bbp4_mac_if_ctrl? */
6518 rt2800_bbp_write(rt2x00dev, 6, 0x08);
6519 rt2800_bbp_write(rt2x00dev, 14, 0x09);
6520 rt2800_bbp_write(rt2x00dev, 15, 0xFF);
6521 rt2800_bbp_write(rt2x00dev, 16, 0x01);
6522 rt2800_bbp_write(rt2x00dev, 20, 0x06);
6523 rt2800_bbp_write(rt2x00dev, 21, 0x00);
6524 rt2800_bbp_write(rt2x00dev, 22, 0x00);
6525 rt2800_bbp_write(rt2x00dev, 27, 0x00);
6526 rt2800_bbp_write(rt2x00dev, 28, 0x00);
6527 rt2800_bbp_write(rt2x00dev, 30, 0x00);
6528 rt2800_bbp_write(rt2x00dev, 31, 0x48);
6529 rt2800_bbp_write(rt2x00dev, 47, 0x40);
6530 rt2800_bbp_write(rt2x00dev, 62, 0x00);
6531 rt2800_bbp_write(rt2x00dev, 63, 0x00);
6532 rt2800_bbp_write(rt2x00dev, 64, 0x00);
6533 rt2800_bbp_write(rt2x00dev, 65, 0x2C);
6534 rt2800_bbp_write(rt2x00dev, 66, 0x1C);
6535 rt2800_bbp_write(rt2x00dev, 67, 0x20);
6536 rt2800_bbp_write(rt2x00dev, 68, 0xDD);
6537 rt2800_bbp_write(rt2x00dev, 69, 0x10);
6538 rt2800_bbp_write(rt2x00dev, 70, 0x05);
6539 rt2800_bbp_write(rt2x00dev, 73, 0x18);
6540 rt2800_bbp_write(rt2x00dev, 74, 0x0F);
6541 rt2800_bbp_write(rt2x00dev, 75, 0x60);
6542 rt2800_bbp_write(rt2x00dev, 76, 0x44);
6543 rt2800_bbp_write(rt2x00dev, 77, 0x59);
6544 rt2800_bbp_write(rt2x00dev, 78, 0x1E);
6545 rt2800_bbp_write(rt2x00dev, 79, 0x1C);
6546 rt2800_bbp_write(rt2x00dev, 80, 0x0C);
6547 rt2800_bbp_write(rt2x00dev, 81, 0x3A);
6548 rt2800_bbp_write(rt2x00dev, 82, 0xB6);
6549 rt2800_bbp_write(rt2x00dev, 83, 0x9A);
6550 rt2800_bbp_write(rt2x00dev, 84, 0x9A);
6551 rt2800_bbp_write(rt2x00dev, 86, 0x38);
6552 rt2800_bbp_write(rt2x00dev, 88, 0x90);
6553 rt2800_bbp_write(rt2x00dev, 91, 0x04);
6554 rt2800_bbp_write(rt2x00dev, 92, 0x02);
6555 rt2800_bbp_write(rt2x00dev, 95, 0x9A);
6556 rt2800_bbp_write(rt2x00dev, 96, 0x00);
6557 rt2800_bbp_write(rt2x00dev, 103, 0xC0);
6558 rt2800_bbp_write(rt2x00dev, 104, 0x92);
6559 /* FIXME BBP105 owerwrite */
6560 rt2800_bbp_write(rt2x00dev, 105, 0x3C);
6561 rt2800_bbp_write(rt2x00dev, 106, 0x12);
6562 rt2800_bbp_write(rt2x00dev, 109, 0x00);
6563 rt2800_bbp_write(rt2x00dev, 134, 0x10);
6564 rt2800_bbp_write(rt2x00dev, 135, 0xA6);
6565 rt2800_bbp_write(rt2x00dev, 137, 0x04);
6566 rt2800_bbp_write(rt2x00dev, 142, 0x30);
6567 rt2800_bbp_write(rt2x00dev, 143, 0xF7);
6568 rt2800_bbp_write(rt2x00dev, 160, 0xEC);
6569 rt2800_bbp_write(rt2x00dev, 161, 0xC4);
6570 rt2800_bbp_write(rt2x00dev, 162, 0x77);
6571 rt2800_bbp_write(rt2x00dev, 163, 0xF9);
6572 rt2800_bbp_write(rt2x00dev, 164, 0x00);
6573 rt2800_bbp_write(rt2x00dev, 165, 0x00);
6574 rt2800_bbp_write(rt2x00dev, 186, 0x00);
6575 rt2800_bbp_write(rt2x00dev, 187, 0x00);
6576 rt2800_bbp_write(rt2x00dev, 188, 0x00);
6577 rt2800_bbp_write(rt2x00dev, 186, 0x00);
6578 rt2800_bbp_write(rt2x00dev, 187, 0x01);
6579 rt2800_bbp_write(rt2x00dev, 188, 0x00);
6580 rt2800_bbp_write(rt2x00dev, 189, 0x00);
6582 rt2800_bbp_write(rt2x00dev, 91, 0x06);
6583 rt2800_bbp_write(rt2x00dev, 92, 0x04);
6584 rt2800_bbp_write(rt2x00dev, 93, 0x54);
6585 rt2800_bbp_write(rt2x00dev, 99, 0x50);
6586 rt2800_bbp_write(rt2x00dev, 148, 0x84);
6587 rt2800_bbp_write(rt2x00dev, 167, 0x80);
6588 rt2800_bbp_write(rt2x00dev, 178, 0xFF);
6589 rt2800_bbp_write(rt2x00dev, 106, 0x13);
6591 /* BBP for G band GLRT function (BBP_128 ~ BBP_221) */
6592 rt2800_bbp_glrt_write(rt2x00dev, 0, 0x00);
6593 rt2800_bbp_glrt_write(rt2x00dev, 1, 0x14);
6594 rt2800_bbp_glrt_write(rt2x00dev, 2, 0x20);
6595 rt2800_bbp_glrt_write(rt2x00dev, 3, 0x0A);
6596 rt2800_bbp_glrt_write(rt2x00dev, 10, 0x16);
6597 rt2800_bbp_glrt_write(rt2x00dev, 11, 0x06);
6598 rt2800_bbp_glrt_write(rt2x00dev, 12, 0x02);
6599 rt2800_bbp_glrt_write(rt2x00dev, 13, 0x07);
6600 rt2800_bbp_glrt_write(rt2x00dev, 14, 0x05);
6601 rt2800_bbp_glrt_write(rt2x00dev, 15, 0x09);
6602 rt2800_bbp_glrt_write(rt2x00dev, 16, 0x20);
6603 rt2800_bbp_glrt_write(rt2x00dev, 17, 0x08);
6604 rt2800_bbp_glrt_write(rt2x00dev, 18, 0x4A);
6605 rt2800_bbp_glrt_write(rt2x00dev, 19, 0x00);
6606 rt2800_bbp_glrt_write(rt2x00dev, 20, 0x00);
6607 rt2800_bbp_glrt_write(rt2x00dev, 128, 0xE0);
6608 rt2800_bbp_glrt_write(rt2x00dev, 129, 0x1F);
6609 rt2800_bbp_glrt_write(rt2x00dev, 130, 0x4F);
6610 rt2800_bbp_glrt_write(rt2x00dev, 131, 0x32);
6611 rt2800_bbp_glrt_write(rt2x00dev, 132, 0x08);
6612 rt2800_bbp_glrt_write(rt2x00dev, 133, 0x28);
6613 rt2800_bbp_glrt_write(rt2x00dev, 134, 0x19);
6614 rt2800_bbp_glrt_write(rt2x00dev, 135, 0x0A);
6615 rt2800_bbp_glrt_write(rt2x00dev, 138, 0x16);
6616 rt2800_bbp_glrt_write(rt2x00dev, 139, 0x10);
6617 rt2800_bbp_glrt_write(rt2x00dev, 140, 0x10);
6618 rt2800_bbp_glrt_write(rt2x00dev, 141, 0x1A);
6619 rt2800_bbp_glrt_write(rt2x00dev, 142, 0x36);
6620 rt2800_bbp_glrt_write(rt2x00dev, 143, 0x2C);
6621 rt2800_bbp_glrt_write(rt2x00dev, 144, 0x26);
6622 rt2800_bbp_glrt_write(rt2x00dev, 145, 0x24);
6623 rt2800_bbp_glrt_write(rt2x00dev, 146, 0x42);
6624 rt2800_bbp_glrt_write(rt2x00dev, 147, 0x40);
6625 rt2800_bbp_glrt_write(rt2x00dev, 148, 0x30);
6626 rt2800_bbp_glrt_write(rt2x00dev, 149, 0x29);
6627 rt2800_bbp_glrt_write(rt2x00dev, 150, 0x4C);
6628 rt2800_bbp_glrt_write(rt2x00dev, 151, 0x46);
6629 rt2800_bbp_glrt_write(rt2x00dev, 152, 0x3D);
6630 rt2800_bbp_glrt_write(rt2x00dev, 153, 0x40);
6631 rt2800_bbp_glrt_write(rt2x00dev, 154, 0x3E);
6632 rt2800_bbp_glrt_write(rt2x00dev, 155, 0x38);
6633 rt2800_bbp_glrt_write(rt2x00dev, 156, 0x3D);
6634 rt2800_bbp_glrt_write(rt2x00dev, 157, 0x2F);
6635 rt2800_bbp_glrt_write(rt2x00dev, 158, 0x3C);
6636 rt2800_bbp_glrt_write(rt2x00dev, 159, 0x34);
6637 rt2800_bbp_glrt_write(rt2x00dev, 160, 0x2C);
6638 rt2800_bbp_glrt_write(rt2x00dev, 161, 0x2F);
6639 rt2800_bbp_glrt_write(rt2x00dev, 162, 0x3C);
6640 rt2800_bbp_glrt_write(rt2x00dev, 163, 0x35);
6641 rt2800_bbp_glrt_write(rt2x00dev, 164, 0x2E);
6642 rt2800_bbp_glrt_write(rt2x00dev, 165, 0x2F);
6643 rt2800_bbp_glrt_write(rt2x00dev, 166, 0x49);
6644 rt2800_bbp_glrt_write(rt2x00dev, 167, 0x41);
6645 rt2800_bbp_glrt_write(rt2x00dev, 168, 0x36);
6646 rt2800_bbp_glrt_write(rt2x00dev, 169, 0x39);
6647 rt2800_bbp_glrt_write(rt2x00dev, 170, 0x30);
6648 rt2800_bbp_glrt_write(rt2x00dev, 171, 0x30);
6649 rt2800_bbp_glrt_write(rt2x00dev, 172, 0x0E);
6650 rt2800_bbp_glrt_write(rt2x00dev, 173, 0x0D);
6651 rt2800_bbp_glrt_write(rt2x00dev, 174, 0x28);
6652 rt2800_bbp_glrt_write(rt2x00dev, 175, 0x21);
6653 rt2800_bbp_glrt_write(rt2x00dev, 176, 0x1C);
6654 rt2800_bbp_glrt_write(rt2x00dev, 177, 0x16);
6655 rt2800_bbp_glrt_write(rt2x00dev, 178, 0x50);
6656 rt2800_bbp_glrt_write(rt2x00dev, 179, 0x4A);
6657 rt2800_bbp_glrt_write(rt2x00dev, 180, 0x43);
6658 rt2800_bbp_glrt_write(rt2x00dev, 181, 0x50);
6659 rt2800_bbp_glrt_write(rt2x00dev, 182, 0x10);
6660 rt2800_bbp_glrt_write(rt2x00dev, 183, 0x10);
6661 rt2800_bbp_glrt_write(rt2x00dev, 184, 0x10);
6662 rt2800_bbp_glrt_write(rt2x00dev, 185, 0x10);
6663 rt2800_bbp_glrt_write(rt2x00dev, 200, 0x7D);
6664 rt2800_bbp_glrt_write(rt2x00dev, 201, 0x14);
6665 rt2800_bbp_glrt_write(rt2x00dev, 202, 0x32);
6666 rt2800_bbp_glrt_write(rt2x00dev, 203, 0x2C);
6667 rt2800_bbp_glrt_write(rt2x00dev, 204, 0x36);
6668 rt2800_bbp_glrt_write(rt2x00dev, 205, 0x4C);
6669 rt2800_bbp_glrt_write(rt2x00dev, 206, 0x43);
6670 rt2800_bbp_glrt_write(rt2x00dev, 207, 0x2C);
6671 rt2800_bbp_glrt_write(rt2x00dev, 208, 0x2E);
6672 rt2800_bbp_glrt_write(rt2x00dev, 209, 0x36);
6673 rt2800_bbp_glrt_write(rt2x00dev, 210, 0x30);
6674 rt2800_bbp_glrt_write(rt2x00dev, 211, 0x6E);
6676 /* BBP for G band DCOC function */
6677 rt2800_bbp_dcoc_write(rt2x00dev, 140, 0x0C);
6678 rt2800_bbp_dcoc_write(rt2x00dev, 141, 0x00);
6679 rt2800_bbp_dcoc_write(rt2x00dev, 142, 0x10);
6680 rt2800_bbp_dcoc_write(rt2x00dev, 143, 0x10);
6681 rt2800_bbp_dcoc_write(rt2x00dev, 144, 0x10);
6682 rt2800_bbp_dcoc_write(rt2x00dev, 145, 0x10);
6683 rt2800_bbp_dcoc_write(rt2x00dev, 146, 0x08);
6684 rt2800_bbp_dcoc_write(rt2x00dev, 147, 0x40);
6685 rt2800_bbp_dcoc_write(rt2x00dev, 148, 0x04);
6686 rt2800_bbp_dcoc_write(rt2x00dev, 149, 0x04);
6687 rt2800_bbp_dcoc_write(rt2x00dev, 150, 0x08);
6688 rt2800_bbp_dcoc_write(rt2x00dev, 151, 0x08);
6689 rt2800_bbp_dcoc_write(rt2x00dev, 152, 0x03);
6690 rt2800_bbp_dcoc_write(rt2x00dev, 153, 0x03);
6691 rt2800_bbp_dcoc_write(rt2x00dev, 154, 0x03);
6692 rt2800_bbp_dcoc_write(rt2x00dev, 155, 0x02);
6693 rt2800_bbp_dcoc_write(rt2x00dev, 156, 0x40);
6694 rt2800_bbp_dcoc_write(rt2x00dev, 157, 0x40);
6695 rt2800_bbp_dcoc_write(rt2x00dev, 158, 0x64);
6696 rt2800_bbp_dcoc_write(rt2x00dev, 159, 0x64);
6698 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
6701 static void rt2800_init_bbp(struct rt2x00_dev *rt2x00dev)
6703 unsigned int i;
6704 u16 eeprom;
6705 u8 reg_id;
6706 u8 value;
6708 if (rt2800_is_305x_soc(rt2x00dev))
6709 rt2800_init_bbp_305x_soc(rt2x00dev);
6711 switch (rt2x00dev->chip.rt) {
6712 case RT2860:
6713 case RT2872:
6714 case RT2883:
6715 rt2800_init_bbp_28xx(rt2x00dev);
6716 break;
6717 case RT3070:
6718 case RT3071:
6719 case RT3090:
6720 rt2800_init_bbp_30xx(rt2x00dev);
6721 break;
6722 case RT3290:
6723 rt2800_init_bbp_3290(rt2x00dev);
6724 break;
6725 case RT3352:
6726 case RT5350:
6727 rt2800_init_bbp_3352(rt2x00dev);
6728 break;
6729 case RT3390:
6730 rt2800_init_bbp_3390(rt2x00dev);
6731 break;
6732 case RT3572:
6733 rt2800_init_bbp_3572(rt2x00dev);
6734 break;
6735 case RT3593:
6736 rt2800_init_bbp_3593(rt2x00dev);
6737 return;
6738 case RT5390:
6739 case RT5392:
6740 rt2800_init_bbp_53xx(rt2x00dev);
6741 break;
6742 case RT5592:
6743 rt2800_init_bbp_5592(rt2x00dev);
6744 return;
6745 case RT6352:
6746 rt2800_init_bbp_6352(rt2x00dev);
6747 break;
6750 for (i = 0; i < EEPROM_BBP_SIZE; i++) {
6751 eeprom = rt2800_eeprom_read_from_array(rt2x00dev,
6752 EEPROM_BBP_START, i);
6754 if (eeprom != 0xffff && eeprom != 0x0000) {
6755 reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
6756 value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
6757 rt2800_bbp_write(rt2x00dev, reg_id, value);
6762 static void rt2800_led_open_drain_enable(struct rt2x00_dev *rt2x00dev)
6764 u32 reg;
6766 reg = rt2800_register_read(rt2x00dev, OPT_14_CSR);
6767 rt2x00_set_field32(&reg, OPT_14_CSR_BIT0, 1);
6768 rt2800_register_write(rt2x00dev, OPT_14_CSR, reg);
6771 static u8 rt2800_init_rx_filter(struct rt2x00_dev *rt2x00dev, bool bw40,
6772 u8 filter_target)
6774 unsigned int i;
6775 u8 bbp;
6776 u8 rfcsr;
6777 u8 passband;
6778 u8 stopband;
6779 u8 overtuned = 0;
6780 u8 rfcsr24 = (bw40) ? 0x27 : 0x07;
6782 rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
6784 bbp = rt2800_bbp_read(rt2x00dev, 4);
6785 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * bw40);
6786 rt2800_bbp_write(rt2x00dev, 4, bbp);
6788 rfcsr = rt2800_rfcsr_read(rt2x00dev, 31);
6789 rt2x00_set_field8(&rfcsr, RFCSR31_RX_H20M, bw40);
6790 rt2800_rfcsr_write(rt2x00dev, 31, rfcsr);
6792 rfcsr = rt2800_rfcsr_read(rt2x00dev, 22);
6793 rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 1);
6794 rt2800_rfcsr_write(rt2x00dev, 22, rfcsr);
6797 * Set power & frequency of passband test tone
6799 rt2800_bbp_write(rt2x00dev, 24, 0);
6801 for (i = 0; i < 100; i++) {
6802 rt2800_bbp_write(rt2x00dev, 25, 0x90);
6803 msleep(1);
6805 passband = rt2800_bbp_read(rt2x00dev, 55);
6806 if (passband)
6807 break;
6811 * Set power & frequency of stopband test tone
6813 rt2800_bbp_write(rt2x00dev, 24, 0x06);
6815 for (i = 0; i < 100; i++) {
6816 rt2800_bbp_write(rt2x00dev, 25, 0x90);
6817 msleep(1);
6819 stopband = rt2800_bbp_read(rt2x00dev, 55);
6821 if ((passband - stopband) <= filter_target) {
6822 rfcsr24++;
6823 overtuned += ((passband - stopband) == filter_target);
6824 } else
6825 break;
6827 rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
6830 rfcsr24 -= !!overtuned;
6832 rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
6833 return rfcsr24;
6836 static void rt2800_rf_init_calibration(struct rt2x00_dev *rt2x00dev,
6837 const unsigned int rf_reg)
6839 u8 rfcsr;
6841 rfcsr = rt2800_rfcsr_read(rt2x00dev, rf_reg);
6842 rt2x00_set_field8(&rfcsr, FIELD8(0x80), 1);
6843 rt2800_rfcsr_write(rt2x00dev, rf_reg, rfcsr);
6844 msleep(1);
6845 rt2x00_set_field8(&rfcsr, FIELD8(0x80), 0);
6846 rt2800_rfcsr_write(rt2x00dev, rf_reg, rfcsr);
6849 static void rt2800_rx_filter_calibration(struct rt2x00_dev *rt2x00dev)
6851 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
6852 u8 filter_tgt_bw20;
6853 u8 filter_tgt_bw40;
6854 u8 rfcsr, bbp;
6857 * TODO: sync filter_tgt values with vendor driver
6859 if (rt2x00_rt(rt2x00dev, RT3070)) {
6860 filter_tgt_bw20 = 0x16;
6861 filter_tgt_bw40 = 0x19;
6862 } else {
6863 filter_tgt_bw20 = 0x13;
6864 filter_tgt_bw40 = 0x15;
6867 drv_data->calibration_bw20 =
6868 rt2800_init_rx_filter(rt2x00dev, false, filter_tgt_bw20);
6869 drv_data->calibration_bw40 =
6870 rt2800_init_rx_filter(rt2x00dev, true, filter_tgt_bw40);
6873 * Save BBP 25 & 26 values for later use in channel switching (for 3052)
6875 drv_data->bbp25 = rt2800_bbp_read(rt2x00dev, 25);
6876 drv_data->bbp26 = rt2800_bbp_read(rt2x00dev, 26);
6879 * Set back to initial state
6881 rt2800_bbp_write(rt2x00dev, 24, 0);
6883 rfcsr = rt2800_rfcsr_read(rt2x00dev, 22);
6884 rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 0);
6885 rt2800_rfcsr_write(rt2x00dev, 22, rfcsr);
6888 * Set BBP back to BW20
6890 bbp = rt2800_bbp_read(rt2x00dev, 4);
6891 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0);
6892 rt2800_bbp_write(rt2x00dev, 4, bbp);
6895 static void rt2800_normal_mode_setup_3xxx(struct rt2x00_dev *rt2x00dev)
6897 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
6898 u8 min_gain, rfcsr, bbp;
6899 u16 eeprom;
6901 rfcsr = rt2800_rfcsr_read(rt2x00dev, 17);
6903 rt2x00_set_field8(&rfcsr, RFCSR17_TX_LO1_EN, 0);
6904 if (rt2x00_rt(rt2x00dev, RT3070) ||
6905 rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) ||
6906 rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E) ||
6907 rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) {
6908 if (!rt2x00_has_cap_external_lna_bg(rt2x00dev))
6909 rt2x00_set_field8(&rfcsr, RFCSR17_R, 1);
6912 min_gain = rt2x00_rt(rt2x00dev, RT3070) ? 1 : 2;
6913 if (drv_data->txmixer_gain_24g >= min_gain) {
6914 rt2x00_set_field8(&rfcsr, RFCSR17_TXMIXER_GAIN,
6915 drv_data->txmixer_gain_24g);
6918 rt2800_rfcsr_write(rt2x00dev, 17, rfcsr);
6920 if (rt2x00_rt(rt2x00dev, RT3090)) {
6921 /* Turn off unused DAC1 and ADC1 to reduce power consumption */
6922 bbp = rt2800_bbp_read(rt2x00dev, 138);
6923 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0);
6924 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) == 1)
6925 rt2x00_set_field8(&bbp, BBP138_RX_ADC1, 0);
6926 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) == 1)
6927 rt2x00_set_field8(&bbp, BBP138_TX_DAC1, 1);
6928 rt2800_bbp_write(rt2x00dev, 138, bbp);
6931 if (rt2x00_rt(rt2x00dev, RT3070)) {
6932 rfcsr = rt2800_rfcsr_read(rt2x00dev, 27);
6933 if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F))
6934 rt2x00_set_field8(&rfcsr, RFCSR27_R1, 3);
6935 else
6936 rt2x00_set_field8(&rfcsr, RFCSR27_R1, 0);
6937 rt2x00_set_field8(&rfcsr, RFCSR27_R2, 0);
6938 rt2x00_set_field8(&rfcsr, RFCSR27_R3, 0);
6939 rt2x00_set_field8(&rfcsr, RFCSR27_R4, 0);
6940 rt2800_rfcsr_write(rt2x00dev, 27, rfcsr);
6941 } else if (rt2x00_rt(rt2x00dev, RT3071) ||
6942 rt2x00_rt(rt2x00dev, RT3090) ||
6943 rt2x00_rt(rt2x00dev, RT3390)) {
6944 rfcsr = rt2800_rfcsr_read(rt2x00dev, 1);
6945 rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
6946 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0);
6947 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0);
6948 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
6949 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
6950 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
6952 rfcsr = rt2800_rfcsr_read(rt2x00dev, 15);
6953 rt2x00_set_field8(&rfcsr, RFCSR15_TX_LO2_EN, 0);
6954 rt2800_rfcsr_write(rt2x00dev, 15, rfcsr);
6956 rfcsr = rt2800_rfcsr_read(rt2x00dev, 20);
6957 rt2x00_set_field8(&rfcsr, RFCSR20_RX_LO1_EN, 0);
6958 rt2800_rfcsr_write(rt2x00dev, 20, rfcsr);
6960 rfcsr = rt2800_rfcsr_read(rt2x00dev, 21);
6961 rt2x00_set_field8(&rfcsr, RFCSR21_RX_LO2_EN, 0);
6962 rt2800_rfcsr_write(rt2x00dev, 21, rfcsr);
6966 static void rt2800_normal_mode_setup_3593(struct rt2x00_dev *rt2x00dev)
6968 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
6969 u8 rfcsr;
6970 u8 tx_gain;
6972 rfcsr = rt2800_rfcsr_read(rt2x00dev, 50);
6973 rt2x00_set_field8(&rfcsr, RFCSR50_TX_LO2_EN, 0);
6974 rt2800_rfcsr_write(rt2x00dev, 50, rfcsr);
6976 rfcsr = rt2800_rfcsr_read(rt2x00dev, 51);
6977 tx_gain = rt2x00_get_field8(drv_data->txmixer_gain_24g,
6978 RFCSR17_TXMIXER_GAIN);
6979 rt2x00_set_field8(&rfcsr, RFCSR51_BITS24, tx_gain);
6980 rt2800_rfcsr_write(rt2x00dev, 51, rfcsr);
6982 rfcsr = rt2800_rfcsr_read(rt2x00dev, 38);
6983 rt2x00_set_field8(&rfcsr, RFCSR38_RX_LO1_EN, 0);
6984 rt2800_rfcsr_write(rt2x00dev, 38, rfcsr);
6986 rfcsr = rt2800_rfcsr_read(rt2x00dev, 39);
6987 rt2x00_set_field8(&rfcsr, RFCSR39_RX_LO2_EN, 0);
6988 rt2800_rfcsr_write(rt2x00dev, 39, rfcsr);
6990 rfcsr = rt2800_rfcsr_read(rt2x00dev, 1);
6991 rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
6992 rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1);
6993 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
6995 rfcsr = rt2800_rfcsr_read(rt2x00dev, 30);
6996 rt2x00_set_field8(&rfcsr, RFCSR30_RX_VCM, 2);
6997 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
6999 /* TODO: enable stream mode */
7002 static void rt2800_normal_mode_setup_5xxx(struct rt2x00_dev *rt2x00dev)
7004 u8 reg;
7005 u16 eeprom;
7007 /* Turn off unused DAC1 and ADC1 to reduce power consumption */
7008 reg = rt2800_bbp_read(rt2x00dev, 138);
7009 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0);
7010 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) == 1)
7011 rt2x00_set_field8(&reg, BBP138_RX_ADC1, 0);
7012 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) == 1)
7013 rt2x00_set_field8(&reg, BBP138_TX_DAC1, 1);
7014 rt2800_bbp_write(rt2x00dev, 138, reg);
7016 reg = rt2800_rfcsr_read(rt2x00dev, 38);
7017 rt2x00_set_field8(&reg, RFCSR38_RX_LO1_EN, 0);
7018 rt2800_rfcsr_write(rt2x00dev, 38, reg);
7020 reg = rt2800_rfcsr_read(rt2x00dev, 39);
7021 rt2x00_set_field8(&reg, RFCSR39_RX_LO2_EN, 0);
7022 rt2800_rfcsr_write(rt2x00dev, 39, reg);
7024 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
7026 reg = rt2800_rfcsr_read(rt2x00dev, 30);
7027 rt2x00_set_field8(&reg, RFCSR30_RX_VCM, 2);
7028 rt2800_rfcsr_write(rt2x00dev, 30, reg);
7031 static void rt2800_init_rfcsr_305x_soc(struct rt2x00_dev *rt2x00dev)
7033 rt2800_rf_init_calibration(rt2x00dev, 30);
7035 rt2800_rfcsr_write(rt2x00dev, 0, 0x50);
7036 rt2800_rfcsr_write(rt2x00dev, 1, 0x01);
7037 rt2800_rfcsr_write(rt2x00dev, 2, 0xf7);
7038 rt2800_rfcsr_write(rt2x00dev, 3, 0x75);
7039 rt2800_rfcsr_write(rt2x00dev, 4, 0x40);
7040 rt2800_rfcsr_write(rt2x00dev, 5, 0x03);
7041 rt2800_rfcsr_write(rt2x00dev, 6, 0x02);
7042 rt2800_rfcsr_write(rt2x00dev, 7, 0x50);
7043 rt2800_rfcsr_write(rt2x00dev, 8, 0x39);
7044 rt2800_rfcsr_write(rt2x00dev, 9, 0x0f);
7045 rt2800_rfcsr_write(rt2x00dev, 10, 0x60);
7046 rt2800_rfcsr_write(rt2x00dev, 11, 0x21);
7047 rt2800_rfcsr_write(rt2x00dev, 12, 0x75);
7048 rt2800_rfcsr_write(rt2x00dev, 13, 0x75);
7049 rt2800_rfcsr_write(rt2x00dev, 14, 0x90);
7050 rt2800_rfcsr_write(rt2x00dev, 15, 0x58);
7051 rt2800_rfcsr_write(rt2x00dev, 16, 0xb3);
7052 rt2800_rfcsr_write(rt2x00dev, 17, 0x92);
7053 rt2800_rfcsr_write(rt2x00dev, 18, 0x2c);
7054 rt2800_rfcsr_write(rt2x00dev, 19, 0x02);
7055 rt2800_rfcsr_write(rt2x00dev, 20, 0xba);
7056 rt2800_rfcsr_write(rt2x00dev, 21, 0xdb);
7057 rt2800_rfcsr_write(rt2x00dev, 22, 0x00);
7058 rt2800_rfcsr_write(rt2x00dev, 23, 0x31);
7059 rt2800_rfcsr_write(rt2x00dev, 24, 0x08);
7060 rt2800_rfcsr_write(rt2x00dev, 25, 0x01);
7061 rt2800_rfcsr_write(rt2x00dev, 26, 0x25);
7062 rt2800_rfcsr_write(rt2x00dev, 27, 0x23);
7063 rt2800_rfcsr_write(rt2x00dev, 28, 0x13);
7064 rt2800_rfcsr_write(rt2x00dev, 29, 0x83);
7065 rt2800_rfcsr_write(rt2x00dev, 30, 0x00);
7066 rt2800_rfcsr_write(rt2x00dev, 31, 0x00);
7069 static void rt2800_init_rfcsr_30xx(struct rt2x00_dev *rt2x00dev)
7071 u8 rfcsr;
7072 u16 eeprom;
7073 u32 reg;
7075 /* XXX vendor driver do this only for 3070 */
7076 rt2800_rf_init_calibration(rt2x00dev, 30);
7078 rt2800_rfcsr_write(rt2x00dev, 4, 0x40);
7079 rt2800_rfcsr_write(rt2x00dev, 5, 0x03);
7080 rt2800_rfcsr_write(rt2x00dev, 6, 0x02);
7081 rt2800_rfcsr_write(rt2x00dev, 7, 0x60);
7082 rt2800_rfcsr_write(rt2x00dev, 9, 0x0f);
7083 rt2800_rfcsr_write(rt2x00dev, 10, 0x41);
7084 rt2800_rfcsr_write(rt2x00dev, 11, 0x21);
7085 rt2800_rfcsr_write(rt2x00dev, 12, 0x7b);
7086 rt2800_rfcsr_write(rt2x00dev, 14, 0x90);
7087 rt2800_rfcsr_write(rt2x00dev, 15, 0x58);
7088 rt2800_rfcsr_write(rt2x00dev, 16, 0xb3);
7089 rt2800_rfcsr_write(rt2x00dev, 17, 0x92);
7090 rt2800_rfcsr_write(rt2x00dev, 18, 0x2c);
7091 rt2800_rfcsr_write(rt2x00dev, 19, 0x02);
7092 rt2800_rfcsr_write(rt2x00dev, 20, 0xba);
7093 rt2800_rfcsr_write(rt2x00dev, 21, 0xdb);
7094 rt2800_rfcsr_write(rt2x00dev, 24, 0x16);
7095 rt2800_rfcsr_write(rt2x00dev, 25, 0x03);
7096 rt2800_rfcsr_write(rt2x00dev, 29, 0x1f);
7098 if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) {
7099 reg = rt2800_register_read(rt2x00dev, LDO_CFG0);
7100 rt2x00_set_field32(&reg, LDO_CFG0_BGSEL, 1);
7101 rt2x00_set_field32(&reg, LDO_CFG0_LDO_CORE_VLEVEL, 3);
7102 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
7103 } else if (rt2x00_rt(rt2x00dev, RT3071) ||
7104 rt2x00_rt(rt2x00dev, RT3090)) {
7105 rt2800_rfcsr_write(rt2x00dev, 31, 0x14);
7107 rfcsr = rt2800_rfcsr_read(rt2x00dev, 6);
7108 rt2x00_set_field8(&rfcsr, RFCSR6_R2, 1);
7109 rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
7111 reg = rt2800_register_read(rt2x00dev, LDO_CFG0);
7112 rt2x00_set_field32(&reg, LDO_CFG0_BGSEL, 1);
7113 if (rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) ||
7114 rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E)) {
7115 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1);
7116 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_DAC_TEST))
7117 rt2x00_set_field32(&reg, LDO_CFG0_LDO_CORE_VLEVEL, 3);
7118 else
7119 rt2x00_set_field32(&reg, LDO_CFG0_LDO_CORE_VLEVEL, 0);
7121 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
7123 reg = rt2800_register_read(rt2x00dev, GPIO_SWITCH);
7124 rt2x00_set_field32(&reg, GPIO_SWITCH_5, 0);
7125 rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg);
7128 rt2800_rx_filter_calibration(rt2x00dev);
7130 if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F) ||
7131 rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) ||
7132 rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E))
7133 rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
7135 rt2800_led_open_drain_enable(rt2x00dev);
7136 rt2800_normal_mode_setup_3xxx(rt2x00dev);
7139 static void rt2800_init_rfcsr_3290(struct rt2x00_dev *rt2x00dev)
7141 u8 rfcsr;
7143 rt2800_rf_init_calibration(rt2x00dev, 2);
7145 rt2800_rfcsr_write(rt2x00dev, 1, 0x0f);
7146 rt2800_rfcsr_write(rt2x00dev, 2, 0x80);
7147 rt2800_rfcsr_write(rt2x00dev, 3, 0x08);
7148 rt2800_rfcsr_write(rt2x00dev, 4, 0x00);
7149 rt2800_rfcsr_write(rt2x00dev, 6, 0xa0);
7150 rt2800_rfcsr_write(rt2x00dev, 8, 0xf3);
7151 rt2800_rfcsr_write(rt2x00dev, 9, 0x02);
7152 rt2800_rfcsr_write(rt2x00dev, 10, 0x53);
7153 rt2800_rfcsr_write(rt2x00dev, 11, 0x4a);
7154 rt2800_rfcsr_write(rt2x00dev, 12, 0x46);
7155 rt2800_rfcsr_write(rt2x00dev, 13, 0x9f);
7156 rt2800_rfcsr_write(rt2x00dev, 18, 0x02);
7157 rt2800_rfcsr_write(rt2x00dev, 22, 0x20);
7158 rt2800_rfcsr_write(rt2x00dev, 25, 0x83);
7159 rt2800_rfcsr_write(rt2x00dev, 26, 0x82);
7160 rt2800_rfcsr_write(rt2x00dev, 27, 0x09);
7161 rt2800_rfcsr_write(rt2x00dev, 29, 0x10);
7162 rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
7163 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
7164 rt2800_rfcsr_write(rt2x00dev, 32, 0x80);
7165 rt2800_rfcsr_write(rt2x00dev, 33, 0x00);
7166 rt2800_rfcsr_write(rt2x00dev, 34, 0x05);
7167 rt2800_rfcsr_write(rt2x00dev, 35, 0x12);
7168 rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
7169 rt2800_rfcsr_write(rt2x00dev, 38, 0x85);
7170 rt2800_rfcsr_write(rt2x00dev, 39, 0x1b);
7171 rt2800_rfcsr_write(rt2x00dev, 40, 0x0b);
7172 rt2800_rfcsr_write(rt2x00dev, 41, 0xbb);
7173 rt2800_rfcsr_write(rt2x00dev, 42, 0xd5);
7174 rt2800_rfcsr_write(rt2x00dev, 43, 0x7b);
7175 rt2800_rfcsr_write(rt2x00dev, 44, 0x0e);
7176 rt2800_rfcsr_write(rt2x00dev, 45, 0xa2);
7177 rt2800_rfcsr_write(rt2x00dev, 46, 0x73);
7178 rt2800_rfcsr_write(rt2x00dev, 47, 0x00);
7179 rt2800_rfcsr_write(rt2x00dev, 48, 0x10);
7180 rt2800_rfcsr_write(rt2x00dev, 49, 0x98);
7181 rt2800_rfcsr_write(rt2x00dev, 52, 0x38);
7182 rt2800_rfcsr_write(rt2x00dev, 53, 0x00);
7183 rt2800_rfcsr_write(rt2x00dev, 54, 0x78);
7184 rt2800_rfcsr_write(rt2x00dev, 55, 0x43);
7185 rt2800_rfcsr_write(rt2x00dev, 56, 0x02);
7186 rt2800_rfcsr_write(rt2x00dev, 57, 0x80);
7187 rt2800_rfcsr_write(rt2x00dev, 58, 0x7f);
7188 rt2800_rfcsr_write(rt2x00dev, 59, 0x09);
7189 rt2800_rfcsr_write(rt2x00dev, 60, 0x45);
7190 rt2800_rfcsr_write(rt2x00dev, 61, 0xc1);
7192 rfcsr = rt2800_rfcsr_read(rt2x00dev, 29);
7193 rt2x00_set_field8(&rfcsr, RFCSR29_RSSI_GAIN, 3);
7194 rt2800_rfcsr_write(rt2x00dev, 29, rfcsr);
7196 rt2800_led_open_drain_enable(rt2x00dev);
7197 rt2800_normal_mode_setup_3xxx(rt2x00dev);
7200 static void rt2800_init_rfcsr_3352(struct rt2x00_dev *rt2x00dev)
7202 int tx0_ext_pa = test_bit(CAPABILITY_EXTERNAL_PA_TX0,
7203 &rt2x00dev->cap_flags);
7204 int tx1_ext_pa = test_bit(CAPABILITY_EXTERNAL_PA_TX1,
7205 &rt2x00dev->cap_flags);
7206 u8 rfcsr;
7208 rt2800_rf_init_calibration(rt2x00dev, 30);
7210 rt2800_rfcsr_write(rt2x00dev, 0, 0xf0);
7211 rt2800_rfcsr_write(rt2x00dev, 1, 0x23);
7212 rt2800_rfcsr_write(rt2x00dev, 2, 0x50);
7213 rt2800_rfcsr_write(rt2x00dev, 3, 0x18);
7214 rt2800_rfcsr_write(rt2x00dev, 4, 0x00);
7215 rt2800_rfcsr_write(rt2x00dev, 5, 0x00);
7216 rt2800_rfcsr_write(rt2x00dev, 6, 0x33);
7217 rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
7218 rt2800_rfcsr_write(rt2x00dev, 8, 0xf1);
7219 rt2800_rfcsr_write(rt2x00dev, 9, 0x02);
7220 rt2800_rfcsr_write(rt2x00dev, 10, 0xd2);
7221 rt2800_rfcsr_write(rt2x00dev, 11, 0x42);
7222 rt2800_rfcsr_write(rt2x00dev, 12, 0x1c);
7223 rt2800_rfcsr_write(rt2x00dev, 13, 0x00);
7224 rt2800_rfcsr_write(rt2x00dev, 14, 0x5a);
7225 rt2800_rfcsr_write(rt2x00dev, 15, 0x00);
7226 rt2800_rfcsr_write(rt2x00dev, 16, 0x01);
7227 rt2800_rfcsr_write(rt2x00dev, 18, 0x45);
7228 rt2800_rfcsr_write(rt2x00dev, 19, 0x02);
7229 rt2800_rfcsr_write(rt2x00dev, 20, 0x00);
7230 rt2800_rfcsr_write(rt2x00dev, 21, 0x00);
7231 rt2800_rfcsr_write(rt2x00dev, 22, 0x00);
7232 rt2800_rfcsr_write(rt2x00dev, 23, 0x00);
7233 rt2800_rfcsr_write(rt2x00dev, 24, 0x00);
7234 rt2800_rfcsr_write(rt2x00dev, 25, 0x80);
7235 rt2800_rfcsr_write(rt2x00dev, 26, 0x00);
7236 rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
7237 rt2800_rfcsr_write(rt2x00dev, 28, 0x03);
7238 rt2800_rfcsr_write(rt2x00dev, 29, 0x00);
7239 rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
7240 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
7241 rt2800_rfcsr_write(rt2x00dev, 32, 0x80);
7242 rt2800_rfcsr_write(rt2x00dev, 33, 0x00);
7243 rfcsr = 0x01;
7244 if (tx0_ext_pa)
7245 rt2x00_set_field8(&rfcsr, RFCSR34_TX0_EXT_PA, 1);
7246 if (tx1_ext_pa)
7247 rt2x00_set_field8(&rfcsr, RFCSR34_TX1_EXT_PA, 1);
7248 rt2800_rfcsr_write(rt2x00dev, 34, rfcsr);
7249 rt2800_rfcsr_write(rt2x00dev, 35, 0x03);
7250 rt2800_rfcsr_write(rt2x00dev, 36, 0xbd);
7251 rt2800_rfcsr_write(rt2x00dev, 37, 0x3c);
7252 rt2800_rfcsr_write(rt2x00dev, 38, 0x5f);
7253 rt2800_rfcsr_write(rt2x00dev, 39, 0xc5);
7254 rt2800_rfcsr_write(rt2x00dev, 40, 0x33);
7255 rfcsr = 0x52;
7256 if (!tx0_ext_pa) {
7257 rt2x00_set_field8(&rfcsr, RFCSR41_BIT1, 1);
7258 rt2x00_set_field8(&rfcsr, RFCSR41_BIT4, 1);
7260 rt2800_rfcsr_write(rt2x00dev, 41, rfcsr);
7261 rfcsr = 0x52;
7262 if (!tx1_ext_pa) {
7263 rt2x00_set_field8(&rfcsr, RFCSR42_BIT1, 1);
7264 rt2x00_set_field8(&rfcsr, RFCSR42_BIT4, 1);
7266 rt2800_rfcsr_write(rt2x00dev, 42, rfcsr);
7267 rt2800_rfcsr_write(rt2x00dev, 43, 0xdb);
7268 rt2800_rfcsr_write(rt2x00dev, 44, 0xdb);
7269 rt2800_rfcsr_write(rt2x00dev, 45, 0xdb);
7270 rt2800_rfcsr_write(rt2x00dev, 46, 0xdd);
7271 rt2800_rfcsr_write(rt2x00dev, 47, 0x0d);
7272 rt2800_rfcsr_write(rt2x00dev, 48, 0x14);
7273 rt2800_rfcsr_write(rt2x00dev, 49, 0x00);
7274 rfcsr = 0x2d;
7275 if (tx0_ext_pa)
7276 rt2x00_set_field8(&rfcsr, RFCSR50_TX0_EXT_PA, 1);
7277 if (tx1_ext_pa)
7278 rt2x00_set_field8(&rfcsr, RFCSR50_TX1_EXT_PA, 1);
7279 rt2800_rfcsr_write(rt2x00dev, 50, rfcsr);
7280 rt2800_rfcsr_write(rt2x00dev, 51, (tx0_ext_pa ? 0x52 : 0x7f));
7281 rt2800_rfcsr_write(rt2x00dev, 52, (tx0_ext_pa ? 0xc0 : 0x00));
7282 rt2800_rfcsr_write(rt2x00dev, 53, (tx0_ext_pa ? 0xd2 : 0x52));
7283 rt2800_rfcsr_write(rt2x00dev, 54, (tx0_ext_pa ? 0xc0 : 0x1b));
7284 rt2800_rfcsr_write(rt2x00dev, 55, (tx1_ext_pa ? 0x52 : 0x7f));
7285 rt2800_rfcsr_write(rt2x00dev, 56, (tx1_ext_pa ? 0xc0 : 0x00));
7286 rt2800_rfcsr_write(rt2x00dev, 57, (tx0_ext_pa ? 0x49 : 0x52));
7287 rt2800_rfcsr_write(rt2x00dev, 58, (tx1_ext_pa ? 0xc0 : 0x1b));
7288 rt2800_rfcsr_write(rt2x00dev, 59, 0x00);
7289 rt2800_rfcsr_write(rt2x00dev, 60, 0x00);
7290 rt2800_rfcsr_write(rt2x00dev, 61, 0x00);
7291 rt2800_rfcsr_write(rt2x00dev, 62, 0x00);
7292 rt2800_rfcsr_write(rt2x00dev, 63, 0x00);
7294 rt2800_rx_filter_calibration(rt2x00dev);
7295 rt2800_led_open_drain_enable(rt2x00dev);
7296 rt2800_normal_mode_setup_3xxx(rt2x00dev);
7299 static void rt2800_init_rfcsr_3390(struct rt2x00_dev *rt2x00dev)
7301 u32 reg;
7303 rt2800_rf_init_calibration(rt2x00dev, 30);
7305 rt2800_rfcsr_write(rt2x00dev, 0, 0xa0);
7306 rt2800_rfcsr_write(rt2x00dev, 1, 0xe1);
7307 rt2800_rfcsr_write(rt2x00dev, 2, 0xf1);
7308 rt2800_rfcsr_write(rt2x00dev, 3, 0x62);
7309 rt2800_rfcsr_write(rt2x00dev, 4, 0x40);
7310 rt2800_rfcsr_write(rt2x00dev, 5, 0x8b);
7311 rt2800_rfcsr_write(rt2x00dev, 6, 0x42);
7312 rt2800_rfcsr_write(rt2x00dev, 7, 0x34);
7313 rt2800_rfcsr_write(rt2x00dev, 8, 0x00);
7314 rt2800_rfcsr_write(rt2x00dev, 9, 0xc0);
7315 rt2800_rfcsr_write(rt2x00dev, 10, 0x61);
7316 rt2800_rfcsr_write(rt2x00dev, 11, 0x21);
7317 rt2800_rfcsr_write(rt2x00dev, 12, 0x3b);
7318 rt2800_rfcsr_write(rt2x00dev, 13, 0xe0);
7319 rt2800_rfcsr_write(rt2x00dev, 14, 0x90);
7320 rt2800_rfcsr_write(rt2x00dev, 15, 0x53);
7321 rt2800_rfcsr_write(rt2x00dev, 16, 0xe0);
7322 rt2800_rfcsr_write(rt2x00dev, 17, 0x94);
7323 rt2800_rfcsr_write(rt2x00dev, 18, 0x5c);
7324 rt2800_rfcsr_write(rt2x00dev, 19, 0x4a);
7325 rt2800_rfcsr_write(rt2x00dev, 20, 0xb2);
7326 rt2800_rfcsr_write(rt2x00dev, 21, 0xf6);
7327 rt2800_rfcsr_write(rt2x00dev, 22, 0x00);
7328 rt2800_rfcsr_write(rt2x00dev, 23, 0x14);
7329 rt2800_rfcsr_write(rt2x00dev, 24, 0x08);
7330 rt2800_rfcsr_write(rt2x00dev, 25, 0x3d);
7331 rt2800_rfcsr_write(rt2x00dev, 26, 0x85);
7332 rt2800_rfcsr_write(rt2x00dev, 27, 0x00);
7333 rt2800_rfcsr_write(rt2x00dev, 28, 0x41);
7334 rt2800_rfcsr_write(rt2x00dev, 29, 0x8f);
7335 rt2800_rfcsr_write(rt2x00dev, 30, 0x20);
7336 rt2800_rfcsr_write(rt2x00dev, 31, 0x0f);
7338 reg = rt2800_register_read(rt2x00dev, GPIO_SWITCH);
7339 rt2x00_set_field32(&reg, GPIO_SWITCH_5, 0);
7340 rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg);
7342 rt2800_rx_filter_calibration(rt2x00dev);
7344 if (rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E))
7345 rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
7347 rt2800_led_open_drain_enable(rt2x00dev);
7348 rt2800_normal_mode_setup_3xxx(rt2x00dev);
7351 static void rt2800_init_rfcsr_3572(struct rt2x00_dev *rt2x00dev)
7353 u8 rfcsr;
7354 u32 reg;
7356 rt2800_rf_init_calibration(rt2x00dev, 30);
7358 rt2800_rfcsr_write(rt2x00dev, 0, 0x70);
7359 rt2800_rfcsr_write(rt2x00dev, 1, 0x81);
7360 rt2800_rfcsr_write(rt2x00dev, 2, 0xf1);
7361 rt2800_rfcsr_write(rt2x00dev, 3, 0x02);
7362 rt2800_rfcsr_write(rt2x00dev, 4, 0x4c);
7363 rt2800_rfcsr_write(rt2x00dev, 5, 0x05);
7364 rt2800_rfcsr_write(rt2x00dev, 6, 0x4a);
7365 rt2800_rfcsr_write(rt2x00dev, 7, 0xd8);
7366 rt2800_rfcsr_write(rt2x00dev, 9, 0xc3);
7367 rt2800_rfcsr_write(rt2x00dev, 10, 0xf1);
7368 rt2800_rfcsr_write(rt2x00dev, 11, 0xb9);
7369 rt2800_rfcsr_write(rt2x00dev, 12, 0x70);
7370 rt2800_rfcsr_write(rt2x00dev, 13, 0x65);
7371 rt2800_rfcsr_write(rt2x00dev, 14, 0xa0);
7372 rt2800_rfcsr_write(rt2x00dev, 15, 0x53);
7373 rt2800_rfcsr_write(rt2x00dev, 16, 0x4c);
7374 rt2800_rfcsr_write(rt2x00dev, 17, 0x23);
7375 rt2800_rfcsr_write(rt2x00dev, 18, 0xac);
7376 rt2800_rfcsr_write(rt2x00dev, 19, 0x93);
7377 rt2800_rfcsr_write(rt2x00dev, 20, 0xb3);
7378 rt2800_rfcsr_write(rt2x00dev, 21, 0xd0);
7379 rt2800_rfcsr_write(rt2x00dev, 22, 0x00);
7380 rt2800_rfcsr_write(rt2x00dev, 23, 0x3c);
7381 rt2800_rfcsr_write(rt2x00dev, 24, 0x16);
7382 rt2800_rfcsr_write(rt2x00dev, 25, 0x15);
7383 rt2800_rfcsr_write(rt2x00dev, 26, 0x85);
7384 rt2800_rfcsr_write(rt2x00dev, 27, 0x00);
7385 rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
7386 rt2800_rfcsr_write(rt2x00dev, 29, 0x9b);
7387 rt2800_rfcsr_write(rt2x00dev, 30, 0x09);
7388 rt2800_rfcsr_write(rt2x00dev, 31, 0x10);
7390 rfcsr = rt2800_rfcsr_read(rt2x00dev, 6);
7391 rt2x00_set_field8(&rfcsr, RFCSR6_R2, 1);
7392 rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
7394 reg = rt2800_register_read(rt2x00dev, LDO_CFG0);
7395 rt2x00_set_field32(&reg, LDO_CFG0_LDO_CORE_VLEVEL, 3);
7396 rt2x00_set_field32(&reg, LDO_CFG0_BGSEL, 1);
7397 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
7398 msleep(1);
7399 reg = rt2800_register_read(rt2x00dev, LDO_CFG0);
7400 rt2x00_set_field32(&reg, LDO_CFG0_LDO_CORE_VLEVEL, 0);
7401 rt2x00_set_field32(&reg, LDO_CFG0_BGSEL, 1);
7402 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
7404 rt2800_rx_filter_calibration(rt2x00dev);
7405 rt2800_led_open_drain_enable(rt2x00dev);
7406 rt2800_normal_mode_setup_3xxx(rt2x00dev);
7409 static void rt3593_post_bbp_init(struct rt2x00_dev *rt2x00dev)
7411 u8 bbp;
7412 bool txbf_enabled = false; /* FIXME */
7414 bbp = rt2800_bbp_read(rt2x00dev, 105);
7415 if (rt2x00dev->default_ant.rx_chain_num == 1)
7416 rt2x00_set_field8(&bbp, BBP105_MLD, 0);
7417 else
7418 rt2x00_set_field8(&bbp, BBP105_MLD, 1);
7419 rt2800_bbp_write(rt2x00dev, 105, bbp);
7421 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
7423 rt2800_bbp_write(rt2x00dev, 92, 0x02);
7424 rt2800_bbp_write(rt2x00dev, 82, 0x82);
7425 rt2800_bbp_write(rt2x00dev, 106, 0x05);
7426 rt2800_bbp_write(rt2x00dev, 104, 0x92);
7427 rt2800_bbp_write(rt2x00dev, 88, 0x90);
7428 rt2800_bbp_write(rt2x00dev, 148, 0xc8);
7429 rt2800_bbp_write(rt2x00dev, 47, 0x48);
7430 rt2800_bbp_write(rt2x00dev, 120, 0x50);
7432 if (txbf_enabled)
7433 rt2800_bbp_write(rt2x00dev, 163, 0xbd);
7434 else
7435 rt2800_bbp_write(rt2x00dev, 163, 0x9d);
7437 /* SNR mapping */
7438 rt2800_bbp_write(rt2x00dev, 142, 6);
7439 rt2800_bbp_write(rt2x00dev, 143, 160);
7440 rt2800_bbp_write(rt2x00dev, 142, 7);
7441 rt2800_bbp_write(rt2x00dev, 143, 161);
7442 rt2800_bbp_write(rt2x00dev, 142, 8);
7443 rt2800_bbp_write(rt2x00dev, 143, 162);
7445 /* ADC/DAC control */
7446 rt2800_bbp_write(rt2x00dev, 31, 0x08);
7448 /* RX AGC energy lower bound in log2 */
7449 rt2800_bbp_write(rt2x00dev, 68, 0x0b);
7451 /* FIXME: BBP 105 owerwrite? */
7452 rt2800_bbp_write(rt2x00dev, 105, 0x04);
7456 static void rt2800_init_rfcsr_3593(struct rt2x00_dev *rt2x00dev)
7458 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
7459 u32 reg;
7460 u8 rfcsr;
7462 /* Disable GPIO #4 and #7 function for LAN PE control */
7463 reg = rt2800_register_read(rt2x00dev, GPIO_SWITCH);
7464 rt2x00_set_field32(&reg, GPIO_SWITCH_4, 0);
7465 rt2x00_set_field32(&reg, GPIO_SWITCH_7, 0);
7466 rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg);
7468 /* Initialize default register values */
7469 rt2800_rfcsr_write(rt2x00dev, 1, 0x03);
7470 rt2800_rfcsr_write(rt2x00dev, 3, 0x80);
7471 rt2800_rfcsr_write(rt2x00dev, 5, 0x00);
7472 rt2800_rfcsr_write(rt2x00dev, 6, 0x40);
7473 rt2800_rfcsr_write(rt2x00dev, 8, 0xf1);
7474 rt2800_rfcsr_write(rt2x00dev, 9, 0x02);
7475 rt2800_rfcsr_write(rt2x00dev, 10, 0xd3);
7476 rt2800_rfcsr_write(rt2x00dev, 11, 0x40);
7477 rt2800_rfcsr_write(rt2x00dev, 12, 0x4e);
7478 rt2800_rfcsr_write(rt2x00dev, 13, 0x12);
7479 rt2800_rfcsr_write(rt2x00dev, 18, 0x40);
7480 rt2800_rfcsr_write(rt2x00dev, 22, 0x20);
7481 rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
7482 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
7483 rt2800_rfcsr_write(rt2x00dev, 32, 0x78);
7484 rt2800_rfcsr_write(rt2x00dev, 33, 0x3b);
7485 rt2800_rfcsr_write(rt2x00dev, 34, 0x3c);
7486 rt2800_rfcsr_write(rt2x00dev, 35, 0xe0);
7487 rt2800_rfcsr_write(rt2x00dev, 38, 0x86);
7488 rt2800_rfcsr_write(rt2x00dev, 39, 0x23);
7489 rt2800_rfcsr_write(rt2x00dev, 44, 0xd3);
7490 rt2800_rfcsr_write(rt2x00dev, 45, 0xbb);
7491 rt2800_rfcsr_write(rt2x00dev, 46, 0x60);
7492 rt2800_rfcsr_write(rt2x00dev, 49, 0x8e);
7493 rt2800_rfcsr_write(rt2x00dev, 50, 0x86);
7494 rt2800_rfcsr_write(rt2x00dev, 51, 0x75);
7495 rt2800_rfcsr_write(rt2x00dev, 52, 0x45);
7496 rt2800_rfcsr_write(rt2x00dev, 53, 0x18);
7497 rt2800_rfcsr_write(rt2x00dev, 54, 0x18);
7498 rt2800_rfcsr_write(rt2x00dev, 55, 0x18);
7499 rt2800_rfcsr_write(rt2x00dev, 56, 0xdb);
7500 rt2800_rfcsr_write(rt2x00dev, 57, 0x6e);
7502 /* Initiate calibration */
7503 /* TODO: use rt2800_rf_init_calibration ? */
7504 rfcsr = rt2800_rfcsr_read(rt2x00dev, 2);
7505 rt2x00_set_field8(&rfcsr, RFCSR2_RESCAL_EN, 1);
7506 rt2800_rfcsr_write(rt2x00dev, 2, rfcsr);
7508 rt2800_freq_cal_mode1(rt2x00dev);
7510 rfcsr = rt2800_rfcsr_read(rt2x00dev, 18);
7511 rt2x00_set_field8(&rfcsr, RFCSR18_XO_TUNE_BYPASS, 1);
7512 rt2800_rfcsr_write(rt2x00dev, 18, rfcsr);
7514 reg = rt2800_register_read(rt2x00dev, LDO_CFG0);
7515 rt2x00_set_field32(&reg, LDO_CFG0_LDO_CORE_VLEVEL, 3);
7516 rt2x00_set_field32(&reg, LDO_CFG0_BGSEL, 1);
7517 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
7518 usleep_range(1000, 1500);
7519 reg = rt2800_register_read(rt2x00dev, LDO_CFG0);
7520 rt2x00_set_field32(&reg, LDO_CFG0_LDO_CORE_VLEVEL, 0);
7521 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
7523 /* Set initial values for RX filter calibration */
7524 drv_data->calibration_bw20 = 0x1f;
7525 drv_data->calibration_bw40 = 0x2f;
7527 /* Save BBP 25 & 26 values for later use in channel switching */
7528 drv_data->bbp25 = rt2800_bbp_read(rt2x00dev, 25);
7529 drv_data->bbp26 = rt2800_bbp_read(rt2x00dev, 26);
7531 rt2800_led_open_drain_enable(rt2x00dev);
7532 rt2800_normal_mode_setup_3593(rt2x00dev);
7534 rt3593_post_bbp_init(rt2x00dev);
7536 /* TODO: enable stream mode support */
7539 static void rt2800_init_rfcsr_5350(struct rt2x00_dev *rt2x00dev)
7541 rt2800_rfcsr_write(rt2x00dev, 0, 0xf0);
7542 rt2800_rfcsr_write(rt2x00dev, 1, 0x23);
7543 rt2800_rfcsr_write(rt2x00dev, 2, 0x50);
7544 rt2800_rfcsr_write(rt2x00dev, 3, 0x08);
7545 rt2800_rfcsr_write(rt2x00dev, 4, 0x49);
7546 rt2800_rfcsr_write(rt2x00dev, 5, 0x10);
7547 rt2800_rfcsr_write(rt2x00dev, 6, 0xe0);
7548 rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
7549 rt2800_rfcsr_write(rt2x00dev, 8, 0xf1);
7550 rt2800_rfcsr_write(rt2x00dev, 9, 0x02);
7551 rt2800_rfcsr_write(rt2x00dev, 10, 0x53);
7552 rt2800_rfcsr_write(rt2x00dev, 11, 0x4a);
7553 rt2800_rfcsr_write(rt2x00dev, 12, 0x46);
7554 if (rt2800_clk_is_20mhz(rt2x00dev))
7555 rt2800_rfcsr_write(rt2x00dev, 13, 0x1f);
7556 else
7557 rt2800_rfcsr_write(rt2x00dev, 13, 0x9f);
7558 rt2800_rfcsr_write(rt2x00dev, 14, 0x00);
7559 rt2800_rfcsr_write(rt2x00dev, 15, 0x00);
7560 rt2800_rfcsr_write(rt2x00dev, 16, 0xc0);
7561 rt2800_rfcsr_write(rt2x00dev, 18, 0x03);
7562 rt2800_rfcsr_write(rt2x00dev, 19, 0x00);
7563 rt2800_rfcsr_write(rt2x00dev, 20, 0x00);
7564 rt2800_rfcsr_write(rt2x00dev, 21, 0x00);
7565 rt2800_rfcsr_write(rt2x00dev, 22, 0x20);
7566 rt2800_rfcsr_write(rt2x00dev, 23, 0x00);
7567 rt2800_rfcsr_write(rt2x00dev, 24, 0x00);
7568 rt2800_rfcsr_write(rt2x00dev, 25, 0x80);
7569 rt2800_rfcsr_write(rt2x00dev, 26, 0x00);
7570 rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
7571 rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
7572 rt2800_rfcsr_write(rt2x00dev, 29, 0xd0);
7573 rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
7574 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
7575 rt2800_rfcsr_write(rt2x00dev, 32, 0x80);
7576 rt2800_rfcsr_write(rt2x00dev, 33, 0x00);
7577 rt2800_rfcsr_write(rt2x00dev, 34, 0x07);
7578 rt2800_rfcsr_write(rt2x00dev, 35, 0x12);
7579 rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
7580 rt2800_rfcsr_write(rt2x00dev, 37, 0x08);
7581 rt2800_rfcsr_write(rt2x00dev, 38, 0x85);
7582 rt2800_rfcsr_write(rt2x00dev, 39, 0x1b);
7583 rt2800_rfcsr_write(rt2x00dev, 40, 0x0b);
7584 rt2800_rfcsr_write(rt2x00dev, 41, 0xbb);
7585 rt2800_rfcsr_write(rt2x00dev, 42, 0xd5);
7586 rt2800_rfcsr_write(rt2x00dev, 43, 0x9b);
7587 rt2800_rfcsr_write(rt2x00dev, 44, 0x0c);
7588 rt2800_rfcsr_write(rt2x00dev, 45, 0xa6);
7589 rt2800_rfcsr_write(rt2x00dev, 46, 0x73);
7590 rt2800_rfcsr_write(rt2x00dev, 47, 0x00);
7591 rt2800_rfcsr_write(rt2x00dev, 48, 0x10);
7592 rt2800_rfcsr_write(rt2x00dev, 49, 0x80);
7593 rt2800_rfcsr_write(rt2x00dev, 50, 0x00);
7594 rt2800_rfcsr_write(rt2x00dev, 51, 0x00);
7595 rt2800_rfcsr_write(rt2x00dev, 52, 0x38);
7596 rt2800_rfcsr_write(rt2x00dev, 53, 0x00);
7597 rt2800_rfcsr_write(rt2x00dev, 54, 0x38);
7598 rt2800_rfcsr_write(rt2x00dev, 55, 0x43);
7599 rt2800_rfcsr_write(rt2x00dev, 56, 0x82);
7600 rt2800_rfcsr_write(rt2x00dev, 57, 0x00);
7601 rt2800_rfcsr_write(rt2x00dev, 58, 0x39);
7602 rt2800_rfcsr_write(rt2x00dev, 59, 0x0b);
7603 rt2800_rfcsr_write(rt2x00dev, 60, 0x45);
7604 rt2800_rfcsr_write(rt2x00dev, 61, 0xd1);
7605 rt2800_rfcsr_write(rt2x00dev, 62, 0x00);
7606 rt2800_rfcsr_write(rt2x00dev, 63, 0x00);
7609 static void rt2800_init_rfcsr_5390(struct rt2x00_dev *rt2x00dev)
7611 rt2800_rf_init_calibration(rt2x00dev, 2);
7613 rt2800_rfcsr_write(rt2x00dev, 1, 0x0f);
7614 rt2800_rfcsr_write(rt2x00dev, 2, 0x80);
7615 rt2800_rfcsr_write(rt2x00dev, 3, 0x88);
7616 rt2800_rfcsr_write(rt2x00dev, 5, 0x10);
7617 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
7618 rt2800_rfcsr_write(rt2x00dev, 6, 0xe0);
7619 else
7620 rt2800_rfcsr_write(rt2x00dev, 6, 0xa0);
7621 rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
7622 rt2800_rfcsr_write(rt2x00dev, 10, 0x53);
7623 rt2800_rfcsr_write(rt2x00dev, 11, 0x4a);
7624 rt2800_rfcsr_write(rt2x00dev, 12, 0x46);
7625 rt2800_rfcsr_write(rt2x00dev, 13, 0x9f);
7626 rt2800_rfcsr_write(rt2x00dev, 14, 0x00);
7627 rt2800_rfcsr_write(rt2x00dev, 15, 0x00);
7628 rt2800_rfcsr_write(rt2x00dev, 16, 0x00);
7629 rt2800_rfcsr_write(rt2x00dev, 18, 0x03);
7630 rt2800_rfcsr_write(rt2x00dev, 19, 0x00);
7632 rt2800_rfcsr_write(rt2x00dev, 20, 0x00);
7633 rt2800_rfcsr_write(rt2x00dev, 21, 0x00);
7634 rt2800_rfcsr_write(rt2x00dev, 22, 0x20);
7635 rt2800_rfcsr_write(rt2x00dev, 23, 0x00);
7636 rt2800_rfcsr_write(rt2x00dev, 24, 0x00);
7637 if (rt2x00_is_usb(rt2x00dev) &&
7638 rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
7639 rt2800_rfcsr_write(rt2x00dev, 25, 0x80);
7640 else
7641 rt2800_rfcsr_write(rt2x00dev, 25, 0xc0);
7642 rt2800_rfcsr_write(rt2x00dev, 26, 0x00);
7643 rt2800_rfcsr_write(rt2x00dev, 27, 0x09);
7644 rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
7645 rt2800_rfcsr_write(rt2x00dev, 29, 0x10);
7647 rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
7648 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
7649 rt2800_rfcsr_write(rt2x00dev, 32, 0x80);
7650 rt2800_rfcsr_write(rt2x00dev, 33, 0x00);
7651 rt2800_rfcsr_write(rt2x00dev, 34, 0x07);
7652 rt2800_rfcsr_write(rt2x00dev, 35, 0x12);
7653 rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
7654 rt2800_rfcsr_write(rt2x00dev, 37, 0x08);
7655 rt2800_rfcsr_write(rt2x00dev, 38, 0x85);
7656 rt2800_rfcsr_write(rt2x00dev, 39, 0x1b);
7658 rt2800_rfcsr_write(rt2x00dev, 40, 0x0b);
7659 rt2800_rfcsr_write(rt2x00dev, 41, 0xbb);
7660 rt2800_rfcsr_write(rt2x00dev, 42, 0xd2);
7661 rt2800_rfcsr_write(rt2x00dev, 43, 0x9a);
7662 rt2800_rfcsr_write(rt2x00dev, 44, 0x0e);
7663 rt2800_rfcsr_write(rt2x00dev, 45, 0xa2);
7664 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
7665 rt2800_rfcsr_write(rt2x00dev, 46, 0x73);
7666 else
7667 rt2800_rfcsr_write(rt2x00dev, 46, 0x7b);
7668 rt2800_rfcsr_write(rt2x00dev, 47, 0x00);
7669 rt2800_rfcsr_write(rt2x00dev, 48, 0x10);
7670 rt2800_rfcsr_write(rt2x00dev, 49, 0x94);
7672 rt2800_rfcsr_write(rt2x00dev, 52, 0x38);
7673 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
7674 rt2800_rfcsr_write(rt2x00dev, 53, 0x00);
7675 else
7676 rt2800_rfcsr_write(rt2x00dev, 53, 0x84);
7677 rt2800_rfcsr_write(rt2x00dev, 54, 0x78);
7678 rt2800_rfcsr_write(rt2x00dev, 55, 0x44);
7679 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
7680 rt2800_rfcsr_write(rt2x00dev, 56, 0x42);
7681 else
7682 rt2800_rfcsr_write(rt2x00dev, 56, 0x22);
7683 rt2800_rfcsr_write(rt2x00dev, 57, 0x80);
7684 rt2800_rfcsr_write(rt2x00dev, 58, 0x7f);
7685 rt2800_rfcsr_write(rt2x00dev, 59, 0x8f);
7687 rt2800_rfcsr_write(rt2x00dev, 60, 0x45);
7688 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) {
7689 if (rt2x00_is_usb(rt2x00dev))
7690 rt2800_rfcsr_write(rt2x00dev, 61, 0xd1);
7691 else
7692 rt2800_rfcsr_write(rt2x00dev, 61, 0xd5);
7693 } else {
7694 if (rt2x00_is_usb(rt2x00dev))
7695 rt2800_rfcsr_write(rt2x00dev, 61, 0xdd);
7696 else
7697 rt2800_rfcsr_write(rt2x00dev, 61, 0xb5);
7699 rt2800_rfcsr_write(rt2x00dev, 62, 0x00);
7700 rt2800_rfcsr_write(rt2x00dev, 63, 0x00);
7702 rt2800_normal_mode_setup_5xxx(rt2x00dev);
7704 rt2800_led_open_drain_enable(rt2x00dev);
7707 static void rt2800_init_rfcsr_5392(struct rt2x00_dev *rt2x00dev)
7709 rt2800_rf_init_calibration(rt2x00dev, 2);
7711 rt2800_rfcsr_write(rt2x00dev, 1, 0x17);
7712 rt2800_rfcsr_write(rt2x00dev, 3, 0x88);
7713 rt2800_rfcsr_write(rt2x00dev, 5, 0x10);
7714 rt2800_rfcsr_write(rt2x00dev, 6, 0xe0);
7715 rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
7716 rt2800_rfcsr_write(rt2x00dev, 10, 0x53);
7717 rt2800_rfcsr_write(rt2x00dev, 11, 0x4a);
7718 rt2800_rfcsr_write(rt2x00dev, 12, 0x46);
7719 rt2800_rfcsr_write(rt2x00dev, 13, 0x9f);
7720 rt2800_rfcsr_write(rt2x00dev, 14, 0x00);
7721 rt2800_rfcsr_write(rt2x00dev, 15, 0x00);
7722 rt2800_rfcsr_write(rt2x00dev, 16, 0x00);
7723 rt2800_rfcsr_write(rt2x00dev, 18, 0x03);
7724 rt2800_rfcsr_write(rt2x00dev, 19, 0x4d);
7725 rt2800_rfcsr_write(rt2x00dev, 20, 0x00);
7726 rt2800_rfcsr_write(rt2x00dev, 21, 0x8d);
7727 rt2800_rfcsr_write(rt2x00dev, 22, 0x20);
7728 rt2800_rfcsr_write(rt2x00dev, 23, 0x0b);
7729 rt2800_rfcsr_write(rt2x00dev, 24, 0x44);
7730 rt2800_rfcsr_write(rt2x00dev, 25, 0x80);
7731 rt2800_rfcsr_write(rt2x00dev, 26, 0x82);
7732 rt2800_rfcsr_write(rt2x00dev, 27, 0x09);
7733 rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
7734 rt2800_rfcsr_write(rt2x00dev, 29, 0x10);
7735 rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
7736 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
7737 rt2800_rfcsr_write(rt2x00dev, 32, 0x20);
7738 rt2800_rfcsr_write(rt2x00dev, 33, 0xC0);
7739 rt2800_rfcsr_write(rt2x00dev, 34, 0x07);
7740 rt2800_rfcsr_write(rt2x00dev, 35, 0x12);
7741 rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
7742 rt2800_rfcsr_write(rt2x00dev, 37, 0x08);
7743 rt2800_rfcsr_write(rt2x00dev, 38, 0x89);
7744 rt2800_rfcsr_write(rt2x00dev, 39, 0x1b);
7745 rt2800_rfcsr_write(rt2x00dev, 40, 0x0f);
7746 rt2800_rfcsr_write(rt2x00dev, 41, 0xbb);
7747 rt2800_rfcsr_write(rt2x00dev, 42, 0xd5);
7748 rt2800_rfcsr_write(rt2x00dev, 43, 0x9b);
7749 rt2800_rfcsr_write(rt2x00dev, 44, 0x0e);
7750 rt2800_rfcsr_write(rt2x00dev, 45, 0xa2);
7751 rt2800_rfcsr_write(rt2x00dev, 46, 0x73);
7752 rt2800_rfcsr_write(rt2x00dev, 47, 0x0c);
7753 rt2800_rfcsr_write(rt2x00dev, 48, 0x10);
7754 rt2800_rfcsr_write(rt2x00dev, 49, 0x94);
7755 rt2800_rfcsr_write(rt2x00dev, 50, 0x94);
7756 rt2800_rfcsr_write(rt2x00dev, 51, 0x3a);
7757 rt2800_rfcsr_write(rt2x00dev, 52, 0x48);
7758 rt2800_rfcsr_write(rt2x00dev, 53, 0x44);
7759 rt2800_rfcsr_write(rt2x00dev, 54, 0x38);
7760 rt2800_rfcsr_write(rt2x00dev, 55, 0x43);
7761 rt2800_rfcsr_write(rt2x00dev, 56, 0xa1);
7762 rt2800_rfcsr_write(rt2x00dev, 57, 0x00);
7763 rt2800_rfcsr_write(rt2x00dev, 58, 0x39);
7764 rt2800_rfcsr_write(rt2x00dev, 59, 0x07);
7765 rt2800_rfcsr_write(rt2x00dev, 60, 0x45);
7766 rt2800_rfcsr_write(rt2x00dev, 61, 0x91);
7767 rt2800_rfcsr_write(rt2x00dev, 62, 0x39);
7768 rt2800_rfcsr_write(rt2x00dev, 63, 0x07);
7770 rt2800_normal_mode_setup_5xxx(rt2x00dev);
7772 rt2800_led_open_drain_enable(rt2x00dev);
7775 static void rt2800_init_rfcsr_5592(struct rt2x00_dev *rt2x00dev)
7777 rt2800_rf_init_calibration(rt2x00dev, 30);
7779 rt2800_rfcsr_write(rt2x00dev, 1, 0x3F);
7780 rt2800_rfcsr_write(rt2x00dev, 3, 0x08);
7781 rt2800_rfcsr_write(rt2x00dev, 5, 0x10);
7782 rt2800_rfcsr_write(rt2x00dev, 6, 0xE4);
7783 rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
7784 rt2800_rfcsr_write(rt2x00dev, 14, 0x00);
7785 rt2800_rfcsr_write(rt2x00dev, 15, 0x00);
7786 rt2800_rfcsr_write(rt2x00dev, 16, 0x00);
7787 rt2800_rfcsr_write(rt2x00dev, 18, 0x03);
7788 rt2800_rfcsr_write(rt2x00dev, 19, 0x4D);
7789 rt2800_rfcsr_write(rt2x00dev, 20, 0x10);
7790 rt2800_rfcsr_write(rt2x00dev, 21, 0x8D);
7791 rt2800_rfcsr_write(rt2x00dev, 26, 0x82);
7792 rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
7793 rt2800_rfcsr_write(rt2x00dev, 29, 0x10);
7794 rt2800_rfcsr_write(rt2x00dev, 33, 0xC0);
7795 rt2800_rfcsr_write(rt2x00dev, 34, 0x07);
7796 rt2800_rfcsr_write(rt2x00dev, 35, 0x12);
7797 rt2800_rfcsr_write(rt2x00dev, 47, 0x0C);
7798 rt2800_rfcsr_write(rt2x00dev, 53, 0x22);
7799 rt2800_rfcsr_write(rt2x00dev, 63, 0x07);
7801 rt2800_rfcsr_write(rt2x00dev, 2, 0x80);
7802 msleep(1);
7804 rt2800_freq_cal_mode1(rt2x00dev);
7806 /* Enable DC filter */
7807 if (rt2x00_rt_rev_gte(rt2x00dev, RT5592, REV_RT5592C))
7808 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
7810 rt2800_normal_mode_setup_5xxx(rt2x00dev);
7812 if (rt2x00_rt_rev_lt(rt2x00dev, RT5592, REV_RT5592C))
7813 rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
7815 rt2800_led_open_drain_enable(rt2x00dev);
7818 static void rt2800_bbp_core_soft_reset(struct rt2x00_dev *rt2x00dev,
7819 bool set_bw, bool is_ht40)
7821 u8 bbp_val;
7823 bbp_val = rt2800_bbp_read(rt2x00dev, 21);
7824 bbp_val |= 0x1;
7825 rt2800_bbp_write(rt2x00dev, 21, bbp_val);
7826 usleep_range(100, 200);
7828 if (set_bw) {
7829 bbp_val = rt2800_bbp_read(rt2x00dev, 4);
7830 rt2x00_set_field8(&bbp_val, BBP4_BANDWIDTH, 2 * is_ht40);
7831 rt2800_bbp_write(rt2x00dev, 4, bbp_val);
7832 usleep_range(100, 200);
7835 bbp_val = rt2800_bbp_read(rt2x00dev, 21);
7836 bbp_val &= (~0x1);
7837 rt2800_bbp_write(rt2x00dev, 21, bbp_val);
7838 usleep_range(100, 200);
7841 static int rt2800_rf_lp_config(struct rt2x00_dev *rt2x00dev, bool btxcal)
7843 u8 rf_val;
7845 if (btxcal)
7846 rt2800_register_write(rt2x00dev, RF_CONTROL0, 0x04);
7847 else
7848 rt2800_register_write(rt2x00dev, RF_CONTROL0, 0x02);
7850 rt2800_register_write(rt2x00dev, RF_BYPASS0, 0x06);
7852 rf_val = rt2800_rfcsr_read_bank(rt2x00dev, 5, 17);
7853 rf_val |= 0x80;
7854 rt2800_rfcsr_write_bank(rt2x00dev, 5, 17, rf_val);
7856 if (btxcal) {
7857 rt2800_rfcsr_write_bank(rt2x00dev, 5, 18, 0xC1);
7858 rt2800_rfcsr_write_bank(rt2x00dev, 5, 19, 0x20);
7859 rt2800_rfcsr_write_bank(rt2x00dev, 5, 20, 0x02);
7860 rf_val = rt2800_rfcsr_read_bank(rt2x00dev, 5, 3);
7861 rf_val &= (~0x3F);
7862 rf_val |= 0x3F;
7863 rt2800_rfcsr_write_bank(rt2x00dev, 5, 3, rf_val);
7864 rf_val = rt2800_rfcsr_read_bank(rt2x00dev, 5, 4);
7865 rf_val &= (~0x3F);
7866 rf_val |= 0x3F;
7867 rt2800_rfcsr_write_bank(rt2x00dev, 5, 4, rf_val);
7868 rt2800_rfcsr_write_bank(rt2x00dev, 5, 5, 0x31);
7869 } else {
7870 rt2800_rfcsr_write_bank(rt2x00dev, 5, 18, 0xF1);
7871 rt2800_rfcsr_write_bank(rt2x00dev, 5, 19, 0x18);
7872 rt2800_rfcsr_write_bank(rt2x00dev, 5, 20, 0x02);
7873 rf_val = rt2800_rfcsr_read_bank(rt2x00dev, 5, 3);
7874 rf_val &= (~0x3F);
7875 rf_val |= 0x34;
7876 rt2800_rfcsr_write_bank(rt2x00dev, 5, 3, rf_val);
7877 rf_val = rt2800_rfcsr_read_bank(rt2x00dev, 5, 4);
7878 rf_val &= (~0x3F);
7879 rf_val |= 0x34;
7880 rt2800_rfcsr_write_bank(rt2x00dev, 5, 4, rf_val);
7883 return 0;
7886 static char rt2800_lp_tx_filter_bw_cal(struct rt2x00_dev *rt2x00dev)
7888 unsigned int cnt;
7889 u8 bbp_val;
7890 char cal_val;
7892 rt2800_bbp_dcoc_write(rt2x00dev, 0, 0x82);
7894 cnt = 0;
7895 do {
7896 usleep_range(500, 2000);
7897 bbp_val = rt2800_bbp_read(rt2x00dev, 159);
7898 if (bbp_val == 0x02 || cnt == 20)
7899 break;
7901 cnt++;
7902 } while (cnt < 20);
7904 bbp_val = rt2800_bbp_dcoc_read(rt2x00dev, 0x39);
7905 cal_val = bbp_val & 0x7F;
7906 if (cal_val >= 0x40)
7907 cal_val -= 128;
7909 return cal_val;
7912 static void rt2800_bw_filter_calibration(struct rt2x00_dev *rt2x00dev,
7913 bool btxcal)
7915 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
7916 u8 tx_agc_fc = 0, rx_agc_fc = 0, cmm_agc_fc;
7917 u8 filter_target;
7918 u8 tx_filter_target_20m = 0x09, tx_filter_target_40m = 0x02;
7919 u8 rx_filter_target_20m = 0x27, rx_filter_target_40m = 0x31;
7920 int loop = 0, is_ht40, cnt;
7921 u8 bbp_val, rf_val;
7922 char cal_r32_init, cal_r32_val, cal_diff;
7923 u8 saverfb5r00, saverfb5r01, saverfb5r03, saverfb5r04, saverfb5r05;
7924 u8 saverfb5r06, saverfb5r07;
7925 u8 saverfb5r08, saverfb5r17, saverfb5r18, saverfb5r19, saverfb5r20;
7926 u8 saverfb5r37, saverfb5r38, saverfb5r39, saverfb5r40, saverfb5r41;
7927 u8 saverfb5r42, saverfb5r43, saverfb5r44, saverfb5r45, saverfb5r46;
7928 u8 saverfb5r58, saverfb5r59;
7929 u8 savebbp159r0, savebbp159r2, savebbpr23;
7930 u32 MAC_RF_CONTROL0, MAC_RF_BYPASS0;
7932 /* Save MAC registers */
7933 MAC_RF_CONTROL0 = rt2800_register_read(rt2x00dev, RF_CONTROL0);
7934 MAC_RF_BYPASS0 = rt2800_register_read(rt2x00dev, RF_BYPASS0);
7936 /* save BBP registers */
7937 savebbpr23 = rt2800_bbp_read(rt2x00dev, 23);
7939 savebbp159r0 = rt2800_bbp_dcoc_read(rt2x00dev, 0);
7940 savebbp159r2 = rt2800_bbp_dcoc_read(rt2x00dev, 2);
7942 /* Save RF registers */
7943 saverfb5r00 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 0);
7944 saverfb5r01 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 1);
7945 saverfb5r03 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 3);
7946 saverfb5r04 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 4);
7947 saverfb5r05 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 5);
7948 saverfb5r06 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 6);
7949 saverfb5r07 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 7);
7950 saverfb5r08 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 8);
7951 saverfb5r17 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 17);
7952 saverfb5r18 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 18);
7953 saverfb5r19 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 19);
7954 saverfb5r20 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 20);
7956 saverfb5r37 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 37);
7957 saverfb5r38 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 38);
7958 saverfb5r39 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 39);
7959 saverfb5r40 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 40);
7960 saverfb5r41 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 41);
7961 saverfb5r42 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 42);
7962 saverfb5r43 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 43);
7963 saverfb5r44 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 44);
7964 saverfb5r45 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 45);
7965 saverfb5r46 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 46);
7967 saverfb5r58 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 58);
7968 saverfb5r59 = rt2800_rfcsr_read_bank(rt2x00dev, 5, 59);
7970 rf_val = rt2800_rfcsr_read_bank(rt2x00dev, 5, 0);
7971 rf_val |= 0x3;
7972 rt2800_rfcsr_write_bank(rt2x00dev, 5, 0, rf_val);
7974 rf_val = rt2800_rfcsr_read_bank(rt2x00dev, 5, 1);
7975 rf_val |= 0x1;
7976 rt2800_rfcsr_write_bank(rt2x00dev, 5, 1, rf_val);
7978 cnt = 0;
7979 do {
7980 usleep_range(500, 2000);
7981 rf_val = rt2800_rfcsr_read_bank(rt2x00dev, 5, 1);
7982 if (((rf_val & 0x1) == 0x00) || (cnt == 40))
7983 break;
7984 cnt++;
7985 } while (cnt < 40);
7987 rf_val = rt2800_rfcsr_read_bank(rt2x00dev, 5, 0);
7988 rf_val &= (~0x3);
7989 rf_val |= 0x1;
7990 rt2800_rfcsr_write_bank(rt2x00dev, 5, 0, rf_val);
7992 /* I-3 */
7993 bbp_val = rt2800_bbp_read(rt2x00dev, 23);
7994 bbp_val &= (~0x1F);
7995 bbp_val |= 0x10;
7996 rt2800_bbp_write(rt2x00dev, 23, bbp_val);
7998 do {
7999 /* I-4,5,6,7,8,9 */
8000 if (loop == 0) {
8001 is_ht40 = false;
8003 if (btxcal)
8004 filter_target = tx_filter_target_20m;
8005 else
8006 filter_target = rx_filter_target_20m;
8007 } else {
8008 is_ht40 = true;
8010 if (btxcal)
8011 filter_target = tx_filter_target_40m;
8012 else
8013 filter_target = rx_filter_target_40m;
8016 rf_val = rt2800_rfcsr_read_bank(rt2x00dev, 5, 8);
8017 rf_val &= (~0x04);
8018 if (loop == 1)
8019 rf_val |= 0x4;
8021 rt2800_rfcsr_write_bank(rt2x00dev, 5, 8, rf_val);
8023 rt2800_bbp_core_soft_reset(rt2x00dev, true, is_ht40);
8025 rt2800_rf_lp_config(rt2x00dev, btxcal);
8026 if (btxcal) {
8027 tx_agc_fc = 0;
8028 rf_val = rt2800_rfcsr_read_bank(rt2x00dev, 5, 58);
8029 rf_val &= (~0x7F);
8030 rt2800_rfcsr_write_bank(rt2x00dev, 5, 58, rf_val);
8031 rf_val = rt2800_rfcsr_read_bank(rt2x00dev, 5, 59);
8032 rf_val &= (~0x7F);
8033 rt2800_rfcsr_write_bank(rt2x00dev, 5, 59, rf_val);
8034 } else {
8035 rx_agc_fc = 0;
8036 rf_val = rt2800_rfcsr_read_bank(rt2x00dev, 5, 6);
8037 rf_val &= (~0x7F);
8038 rt2800_rfcsr_write_bank(rt2x00dev, 5, 6, rf_val);
8039 rf_val = rt2800_rfcsr_read_bank(rt2x00dev, 5, 7);
8040 rf_val &= (~0x7F);
8041 rt2800_rfcsr_write_bank(rt2x00dev, 5, 7, rf_val);
8044 usleep_range(1000, 2000);
8046 bbp_val = rt2800_bbp_dcoc_read(rt2x00dev, 2);
8047 bbp_val &= (~0x6);
8048 rt2800_bbp_dcoc_write(rt2x00dev, 2, bbp_val);
8050 rt2800_bbp_core_soft_reset(rt2x00dev, false, is_ht40);
8052 cal_r32_init = rt2800_lp_tx_filter_bw_cal(rt2x00dev);
8054 bbp_val = rt2800_bbp_dcoc_read(rt2x00dev, 2);
8055 bbp_val |= 0x6;
8056 rt2800_bbp_dcoc_write(rt2x00dev, 2, bbp_val);
8057 do_cal:
8058 if (btxcal) {
8059 rf_val = rt2800_rfcsr_read_bank(rt2x00dev, 5, 58);
8060 rf_val &= (~0x7F);
8061 rf_val |= tx_agc_fc;
8062 rt2800_rfcsr_write_bank(rt2x00dev, 5, 58, rf_val);
8063 rf_val = rt2800_rfcsr_read_bank(rt2x00dev, 5, 59);
8064 rf_val &= (~0x7F);
8065 rf_val |= tx_agc_fc;
8066 rt2800_rfcsr_write_bank(rt2x00dev, 5, 59, rf_val);
8067 } else {
8068 rf_val = rt2800_rfcsr_read_bank(rt2x00dev, 5, 6);
8069 rf_val &= (~0x7F);
8070 rf_val |= rx_agc_fc;
8071 rt2800_rfcsr_write_bank(rt2x00dev, 5, 6, rf_val);
8072 rf_val = rt2800_rfcsr_read_bank(rt2x00dev, 5, 7);
8073 rf_val &= (~0x7F);
8074 rf_val |= rx_agc_fc;
8075 rt2800_rfcsr_write_bank(rt2x00dev, 5, 7, rf_val);
8078 usleep_range(500, 1000);
8080 rt2800_bbp_core_soft_reset(rt2x00dev, false, is_ht40);
8082 cal_r32_val = rt2800_lp_tx_filter_bw_cal(rt2x00dev);
8084 cal_diff = cal_r32_init - cal_r32_val;
8086 if (btxcal)
8087 cmm_agc_fc = tx_agc_fc;
8088 else
8089 cmm_agc_fc = rx_agc_fc;
8091 if (((cal_diff > filter_target) && (cmm_agc_fc == 0)) ||
8092 ((cal_diff < filter_target) && (cmm_agc_fc == 0x3f))) {
8093 if (btxcal)
8094 tx_agc_fc = 0;
8095 else
8096 rx_agc_fc = 0;
8097 } else if ((cal_diff <= filter_target) && (cmm_agc_fc < 0x3f)) {
8098 if (btxcal)
8099 tx_agc_fc++;
8100 else
8101 rx_agc_fc++;
8102 goto do_cal;
8105 if (btxcal) {
8106 if (loop == 0)
8107 drv_data->tx_calibration_bw20 = tx_agc_fc;
8108 else
8109 drv_data->tx_calibration_bw40 = tx_agc_fc;
8110 } else {
8111 if (loop == 0)
8112 drv_data->rx_calibration_bw20 = rx_agc_fc;
8113 else
8114 drv_data->rx_calibration_bw40 = rx_agc_fc;
8117 loop++;
8118 } while (loop <= 1);
8120 rt2800_rfcsr_write_bank(rt2x00dev, 5, 0, saverfb5r00);
8121 rt2800_rfcsr_write_bank(rt2x00dev, 5, 1, saverfb5r01);
8122 rt2800_rfcsr_write_bank(rt2x00dev, 5, 3, saverfb5r03);
8123 rt2800_rfcsr_write_bank(rt2x00dev, 5, 4, saverfb5r04);
8124 rt2800_rfcsr_write_bank(rt2x00dev, 5, 5, saverfb5r05);
8125 rt2800_rfcsr_write_bank(rt2x00dev, 5, 6, saverfb5r06);
8126 rt2800_rfcsr_write_bank(rt2x00dev, 5, 7, saverfb5r07);
8127 rt2800_rfcsr_write_bank(rt2x00dev, 5, 8, saverfb5r08);
8128 rt2800_rfcsr_write_bank(rt2x00dev, 5, 17, saverfb5r17);
8129 rt2800_rfcsr_write_bank(rt2x00dev, 5, 18, saverfb5r18);
8130 rt2800_rfcsr_write_bank(rt2x00dev, 5, 19, saverfb5r19);
8131 rt2800_rfcsr_write_bank(rt2x00dev, 5, 20, saverfb5r20);
8133 rt2800_rfcsr_write_bank(rt2x00dev, 5, 37, saverfb5r37);
8134 rt2800_rfcsr_write_bank(rt2x00dev, 5, 38, saverfb5r38);
8135 rt2800_rfcsr_write_bank(rt2x00dev, 5, 39, saverfb5r39);
8136 rt2800_rfcsr_write_bank(rt2x00dev, 5, 40, saverfb5r40);
8137 rt2800_rfcsr_write_bank(rt2x00dev, 5, 41, saverfb5r41);
8138 rt2800_rfcsr_write_bank(rt2x00dev, 5, 42, saverfb5r42);
8139 rt2800_rfcsr_write_bank(rt2x00dev, 5, 43, saverfb5r43);
8140 rt2800_rfcsr_write_bank(rt2x00dev, 5, 44, saverfb5r44);
8141 rt2800_rfcsr_write_bank(rt2x00dev, 5, 45, saverfb5r45);
8142 rt2800_rfcsr_write_bank(rt2x00dev, 5, 46, saverfb5r46);
8144 rt2800_rfcsr_write_bank(rt2x00dev, 5, 58, saverfb5r58);
8145 rt2800_rfcsr_write_bank(rt2x00dev, 5, 59, saverfb5r59);
8147 rt2800_bbp_write(rt2x00dev, 23, savebbpr23);
8149 rt2800_bbp_dcoc_write(rt2x00dev, 0, savebbp159r0);
8150 rt2800_bbp_dcoc_write(rt2x00dev, 2, savebbp159r2);
8152 bbp_val = rt2800_bbp_read(rt2x00dev, 4);
8153 rt2x00_set_field8(&bbp_val, BBP4_BANDWIDTH,
8154 2 * test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags));
8155 rt2800_bbp_write(rt2x00dev, 4, bbp_val);
8157 rt2800_register_write(rt2x00dev, RF_CONTROL0, MAC_RF_CONTROL0);
8158 rt2800_register_write(rt2x00dev, RF_BYPASS0, MAC_RF_BYPASS0);
8161 static void rt2800_init_rfcsr_6352(struct rt2x00_dev *rt2x00dev)
8163 /* Initialize RF central register to default value */
8164 rt2800_rfcsr_write(rt2x00dev, 0, 0x02);
8165 rt2800_rfcsr_write(rt2x00dev, 1, 0x03);
8166 rt2800_rfcsr_write(rt2x00dev, 2, 0x33);
8167 rt2800_rfcsr_write(rt2x00dev, 3, 0xFF);
8168 rt2800_rfcsr_write(rt2x00dev, 4, 0x0C);
8169 rt2800_rfcsr_write(rt2x00dev, 5, 0x40);
8170 rt2800_rfcsr_write(rt2x00dev, 6, 0x00);
8171 rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
8172 rt2800_rfcsr_write(rt2x00dev, 8, 0x00);
8173 rt2800_rfcsr_write(rt2x00dev, 9, 0x00);
8174 rt2800_rfcsr_write(rt2x00dev, 10, 0x00);
8175 rt2800_rfcsr_write(rt2x00dev, 11, 0x00);
8176 rt2800_rfcsr_write(rt2x00dev, 12, rt2x00dev->freq_offset);
8177 rt2800_rfcsr_write(rt2x00dev, 13, 0x00);
8178 rt2800_rfcsr_write(rt2x00dev, 14, 0x40);
8179 rt2800_rfcsr_write(rt2x00dev, 15, 0x22);
8180 rt2800_rfcsr_write(rt2x00dev, 16, 0x4C);
8181 rt2800_rfcsr_write(rt2x00dev, 17, 0x00);
8182 rt2800_rfcsr_write(rt2x00dev, 18, 0x00);
8183 rt2800_rfcsr_write(rt2x00dev, 19, 0x00);
8184 rt2800_rfcsr_write(rt2x00dev, 20, 0xA0);
8185 rt2800_rfcsr_write(rt2x00dev, 21, 0x12);
8186 rt2800_rfcsr_write(rt2x00dev, 22, 0x07);
8187 rt2800_rfcsr_write(rt2x00dev, 23, 0x13);
8188 rt2800_rfcsr_write(rt2x00dev, 24, 0xFE);
8189 rt2800_rfcsr_write(rt2x00dev, 25, 0x24);
8190 rt2800_rfcsr_write(rt2x00dev, 26, 0x7A);
8191 rt2800_rfcsr_write(rt2x00dev, 27, 0x00);
8192 rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
8193 rt2800_rfcsr_write(rt2x00dev, 29, 0x05);
8194 rt2800_rfcsr_write(rt2x00dev, 30, 0x00);
8195 rt2800_rfcsr_write(rt2x00dev, 31, 0x00);
8196 rt2800_rfcsr_write(rt2x00dev, 32, 0x00);
8197 rt2800_rfcsr_write(rt2x00dev, 33, 0x00);
8198 rt2800_rfcsr_write(rt2x00dev, 34, 0x00);
8199 rt2800_rfcsr_write(rt2x00dev, 35, 0x00);
8200 rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
8201 rt2800_rfcsr_write(rt2x00dev, 37, 0x00);
8202 rt2800_rfcsr_write(rt2x00dev, 38, 0x00);
8203 rt2800_rfcsr_write(rt2x00dev, 39, 0x00);
8204 rt2800_rfcsr_write(rt2x00dev, 40, 0x00);
8205 rt2800_rfcsr_write(rt2x00dev, 41, 0xD0);
8206 rt2800_rfcsr_write(rt2x00dev, 42, 0x5B);
8207 rt2800_rfcsr_write(rt2x00dev, 43, 0x00);
8209 rt2800_rfcsr_write(rt2x00dev, 11, 0x21);
8210 if (rt2800_clk_is_20mhz(rt2x00dev))
8211 rt2800_rfcsr_write(rt2x00dev, 13, 0x03);
8212 else
8213 rt2800_rfcsr_write(rt2x00dev, 13, 0x00);
8214 rt2800_rfcsr_write(rt2x00dev, 14, 0x7C);
8215 rt2800_rfcsr_write(rt2x00dev, 16, 0x80);
8216 rt2800_rfcsr_write(rt2x00dev, 17, 0x99);
8217 rt2800_rfcsr_write(rt2x00dev, 18, 0x99);
8218 rt2800_rfcsr_write(rt2x00dev, 19, 0x09);
8219 rt2800_rfcsr_write(rt2x00dev, 20, 0x50);
8220 rt2800_rfcsr_write(rt2x00dev, 21, 0xB0);
8221 rt2800_rfcsr_write(rt2x00dev, 22, 0x00);
8222 rt2800_rfcsr_write(rt2x00dev, 23, 0x06);
8223 rt2800_rfcsr_write(rt2x00dev, 24, 0x00);
8224 rt2800_rfcsr_write(rt2x00dev, 25, 0x00);
8225 rt2800_rfcsr_write(rt2x00dev, 26, 0x5D);
8226 rt2800_rfcsr_write(rt2x00dev, 27, 0x00);
8227 rt2800_rfcsr_write(rt2x00dev, 28, 0x61);
8228 rt2800_rfcsr_write(rt2x00dev, 29, 0xB5);
8229 rt2800_rfcsr_write(rt2x00dev, 43, 0x02);
8231 rt2800_rfcsr_write(rt2x00dev, 28, 0x62);
8232 rt2800_rfcsr_write(rt2x00dev, 29, 0xAD);
8233 rt2800_rfcsr_write(rt2x00dev, 39, 0x80);
8235 /* Initialize RF channel register to default value */
8236 rt2800_rfcsr_write_chanreg(rt2x00dev, 0, 0x03);
8237 rt2800_rfcsr_write_chanreg(rt2x00dev, 1, 0x00);
8238 rt2800_rfcsr_write_chanreg(rt2x00dev, 2, 0x00);
8239 rt2800_rfcsr_write_chanreg(rt2x00dev, 3, 0x00);
8240 rt2800_rfcsr_write_chanreg(rt2x00dev, 4, 0x00);
8241 rt2800_rfcsr_write_chanreg(rt2x00dev, 5, 0x08);
8242 rt2800_rfcsr_write_chanreg(rt2x00dev, 6, 0x00);
8243 rt2800_rfcsr_write_chanreg(rt2x00dev, 7, 0x51);
8244 rt2800_rfcsr_write_chanreg(rt2x00dev, 8, 0x53);
8245 rt2800_rfcsr_write_chanreg(rt2x00dev, 9, 0x16);
8246 rt2800_rfcsr_write_chanreg(rt2x00dev, 10, 0x61);
8247 rt2800_rfcsr_write_chanreg(rt2x00dev, 11, 0x53);
8248 rt2800_rfcsr_write_chanreg(rt2x00dev, 12, 0x22);
8249 rt2800_rfcsr_write_chanreg(rt2x00dev, 13, 0x3D);
8250 rt2800_rfcsr_write_chanreg(rt2x00dev, 14, 0x06);
8251 rt2800_rfcsr_write_chanreg(rt2x00dev, 15, 0x13);
8252 rt2800_rfcsr_write_chanreg(rt2x00dev, 16, 0x22);
8253 rt2800_rfcsr_write_chanreg(rt2x00dev, 17, 0x27);
8254 rt2800_rfcsr_write_chanreg(rt2x00dev, 18, 0x02);
8255 rt2800_rfcsr_write_chanreg(rt2x00dev, 19, 0xA7);
8256 rt2800_rfcsr_write_chanreg(rt2x00dev, 20, 0x01);
8257 rt2800_rfcsr_write_chanreg(rt2x00dev, 21, 0x52);
8258 rt2800_rfcsr_write_chanreg(rt2x00dev, 22, 0x80);
8259 rt2800_rfcsr_write_chanreg(rt2x00dev, 23, 0xB3);
8260 rt2800_rfcsr_write_chanreg(rt2x00dev, 24, 0x00);
8261 rt2800_rfcsr_write_chanreg(rt2x00dev, 25, 0x00);
8262 rt2800_rfcsr_write_chanreg(rt2x00dev, 26, 0x00);
8263 rt2800_rfcsr_write_chanreg(rt2x00dev, 27, 0x00);
8264 rt2800_rfcsr_write_chanreg(rt2x00dev, 28, 0x5C);
8265 rt2800_rfcsr_write_chanreg(rt2x00dev, 29, 0x6B);
8266 rt2800_rfcsr_write_chanreg(rt2x00dev, 30, 0x6B);
8267 rt2800_rfcsr_write_chanreg(rt2x00dev, 31, 0x31);
8268 rt2800_rfcsr_write_chanreg(rt2x00dev, 32, 0x5D);
8269 rt2800_rfcsr_write_chanreg(rt2x00dev, 33, 0x00);
8270 rt2800_rfcsr_write_chanreg(rt2x00dev, 34, 0xE6);
8271 rt2800_rfcsr_write_chanreg(rt2x00dev, 35, 0x55);
8272 rt2800_rfcsr_write_chanreg(rt2x00dev, 36, 0x00);
8273 rt2800_rfcsr_write_chanreg(rt2x00dev, 37, 0xBB);
8274 rt2800_rfcsr_write_chanreg(rt2x00dev, 38, 0xB3);
8275 rt2800_rfcsr_write_chanreg(rt2x00dev, 39, 0xB3);
8276 rt2800_rfcsr_write_chanreg(rt2x00dev, 40, 0x03);
8277 rt2800_rfcsr_write_chanreg(rt2x00dev, 41, 0x00);
8278 rt2800_rfcsr_write_chanreg(rt2x00dev, 42, 0x00);
8279 rt2800_rfcsr_write_chanreg(rt2x00dev, 43, 0xB3);
8280 rt2800_rfcsr_write_chanreg(rt2x00dev, 44, 0xD3);
8281 rt2800_rfcsr_write_chanreg(rt2x00dev, 45, 0xD5);
8282 rt2800_rfcsr_write_chanreg(rt2x00dev, 46, 0x07);
8283 rt2800_rfcsr_write_chanreg(rt2x00dev, 47, 0x68);
8284 rt2800_rfcsr_write_chanreg(rt2x00dev, 48, 0xEF);
8285 rt2800_rfcsr_write_chanreg(rt2x00dev, 49, 0x1C);
8286 rt2800_rfcsr_write_chanreg(rt2x00dev, 54, 0x07);
8287 rt2800_rfcsr_write_chanreg(rt2x00dev, 55, 0xA8);
8288 rt2800_rfcsr_write_chanreg(rt2x00dev, 56, 0x85);
8289 rt2800_rfcsr_write_chanreg(rt2x00dev, 57, 0x10);
8290 rt2800_rfcsr_write_chanreg(rt2x00dev, 58, 0x07);
8291 rt2800_rfcsr_write_chanreg(rt2x00dev, 59, 0x6A);
8292 rt2800_rfcsr_write_chanreg(rt2x00dev, 60, 0x85);
8293 rt2800_rfcsr_write_chanreg(rt2x00dev, 61, 0x10);
8294 rt2800_rfcsr_write_chanreg(rt2x00dev, 62, 0x1C);
8295 rt2800_rfcsr_write_chanreg(rt2x00dev, 63, 0x00);
8297 rt2800_rfcsr_write_bank(rt2x00dev, 6, 45, 0xC5);
8299 rt2800_rfcsr_write_chanreg(rt2x00dev, 9, 0x47);
8300 rt2800_rfcsr_write_chanreg(rt2x00dev, 10, 0x71);
8301 rt2800_rfcsr_write_chanreg(rt2x00dev, 11, 0x33);
8302 rt2800_rfcsr_write_chanreg(rt2x00dev, 14, 0x0E);
8303 rt2800_rfcsr_write_chanreg(rt2x00dev, 17, 0x23);
8304 rt2800_rfcsr_write_chanreg(rt2x00dev, 19, 0xA4);
8305 rt2800_rfcsr_write_chanreg(rt2x00dev, 20, 0x02);
8306 rt2800_rfcsr_write_chanreg(rt2x00dev, 21, 0x12);
8307 rt2800_rfcsr_write_chanreg(rt2x00dev, 28, 0x1C);
8308 rt2800_rfcsr_write_chanreg(rt2x00dev, 29, 0xEB);
8309 rt2800_rfcsr_write_chanreg(rt2x00dev, 32, 0x7D);
8310 rt2800_rfcsr_write_chanreg(rt2x00dev, 34, 0xD6);
8311 rt2800_rfcsr_write_chanreg(rt2x00dev, 36, 0x08);
8312 rt2800_rfcsr_write_chanreg(rt2x00dev, 38, 0xB4);
8313 rt2800_rfcsr_write_chanreg(rt2x00dev, 43, 0xD3);
8314 rt2800_rfcsr_write_chanreg(rt2x00dev, 44, 0xB3);
8315 rt2800_rfcsr_write_chanreg(rt2x00dev, 45, 0xD5);
8316 rt2800_rfcsr_write_chanreg(rt2x00dev, 46, 0x27);
8317 rt2800_rfcsr_write_bank(rt2x00dev, 4, 47, 0x67);
8318 rt2800_rfcsr_write_bank(rt2x00dev, 6, 47, 0x69);
8319 rt2800_rfcsr_write_chanreg(rt2x00dev, 48, 0xFF);
8320 rt2800_rfcsr_write_bank(rt2x00dev, 4, 54, 0x27);
8321 rt2800_rfcsr_write_bank(rt2x00dev, 6, 54, 0x20);
8322 rt2800_rfcsr_write_chanreg(rt2x00dev, 55, 0x66);
8323 rt2800_rfcsr_write_chanreg(rt2x00dev, 56, 0xFF);
8324 rt2800_rfcsr_write_chanreg(rt2x00dev, 57, 0x1C);
8325 rt2800_rfcsr_write_chanreg(rt2x00dev, 58, 0x20);
8326 rt2800_rfcsr_write_chanreg(rt2x00dev, 59, 0x6B);
8327 rt2800_rfcsr_write_chanreg(rt2x00dev, 60, 0xF7);
8328 rt2800_rfcsr_write_chanreg(rt2x00dev, 61, 0x09);
8330 rt2800_rfcsr_write_chanreg(rt2x00dev, 10, 0x51);
8331 rt2800_rfcsr_write_chanreg(rt2x00dev, 14, 0x06);
8332 rt2800_rfcsr_write_chanreg(rt2x00dev, 19, 0xA7);
8333 rt2800_rfcsr_write_chanreg(rt2x00dev, 28, 0x2C);
8334 rt2800_rfcsr_write_chanreg(rt2x00dev, 55, 0x64);
8335 rt2800_rfcsr_write_chanreg(rt2x00dev, 8, 0x51);
8336 rt2800_rfcsr_write_chanreg(rt2x00dev, 9, 0x36);
8337 rt2800_rfcsr_write_chanreg(rt2x00dev, 11, 0x53);
8338 rt2800_rfcsr_write_chanreg(rt2x00dev, 14, 0x16);
8340 rt2800_rfcsr_write_chanreg(rt2x00dev, 47, 0x6C);
8341 rt2800_rfcsr_write_chanreg(rt2x00dev, 48, 0xFC);
8342 rt2800_rfcsr_write_chanreg(rt2x00dev, 49, 0x1F);
8343 rt2800_rfcsr_write_chanreg(rt2x00dev, 54, 0x27);
8344 rt2800_rfcsr_write_chanreg(rt2x00dev, 55, 0x66);
8345 rt2800_rfcsr_write_chanreg(rt2x00dev, 59, 0x6B);
8347 /* Initialize RF channel register for DRQFN */
8348 rt2800_rfcsr_write_chanreg(rt2x00dev, 43, 0xD3);
8349 rt2800_rfcsr_write_chanreg(rt2x00dev, 44, 0xE3);
8350 rt2800_rfcsr_write_chanreg(rt2x00dev, 45, 0xE5);
8351 rt2800_rfcsr_write_chanreg(rt2x00dev, 47, 0x28);
8352 rt2800_rfcsr_write_chanreg(rt2x00dev, 55, 0x68);
8353 rt2800_rfcsr_write_chanreg(rt2x00dev, 56, 0xF7);
8354 rt2800_rfcsr_write_chanreg(rt2x00dev, 58, 0x02);
8355 rt2800_rfcsr_write_chanreg(rt2x00dev, 60, 0xC7);
8357 /* Initialize RF DC calibration register to default value */
8358 rt2800_rfcsr_write_dccal(rt2x00dev, 0, 0x47);
8359 rt2800_rfcsr_write_dccal(rt2x00dev, 1, 0x00);
8360 rt2800_rfcsr_write_dccal(rt2x00dev, 2, 0x00);
8361 rt2800_rfcsr_write_dccal(rt2x00dev, 3, 0x00);
8362 rt2800_rfcsr_write_dccal(rt2x00dev, 4, 0x00);
8363 rt2800_rfcsr_write_dccal(rt2x00dev, 5, 0x00);
8364 rt2800_rfcsr_write_dccal(rt2x00dev, 6, 0x10);
8365 rt2800_rfcsr_write_dccal(rt2x00dev, 7, 0x10);
8366 rt2800_rfcsr_write_dccal(rt2x00dev, 8, 0x04);
8367 rt2800_rfcsr_write_dccal(rt2x00dev, 9, 0x00);
8368 rt2800_rfcsr_write_dccal(rt2x00dev, 10, 0x07);
8369 rt2800_rfcsr_write_dccal(rt2x00dev, 11, 0x01);
8370 rt2800_rfcsr_write_dccal(rt2x00dev, 12, 0x07);
8371 rt2800_rfcsr_write_dccal(rt2x00dev, 13, 0x07);
8372 rt2800_rfcsr_write_dccal(rt2x00dev, 14, 0x07);
8373 rt2800_rfcsr_write_dccal(rt2x00dev, 15, 0x20);
8374 rt2800_rfcsr_write_dccal(rt2x00dev, 16, 0x22);
8375 rt2800_rfcsr_write_dccal(rt2x00dev, 17, 0x00);
8376 rt2800_rfcsr_write_dccal(rt2x00dev, 18, 0x00);
8377 rt2800_rfcsr_write_dccal(rt2x00dev, 19, 0x00);
8378 rt2800_rfcsr_write_dccal(rt2x00dev, 20, 0x00);
8379 rt2800_rfcsr_write_dccal(rt2x00dev, 21, 0xF1);
8380 rt2800_rfcsr_write_dccal(rt2x00dev, 22, 0x11);
8381 rt2800_rfcsr_write_dccal(rt2x00dev, 23, 0x02);
8382 rt2800_rfcsr_write_dccal(rt2x00dev, 24, 0x41);
8383 rt2800_rfcsr_write_dccal(rt2x00dev, 25, 0x20);
8384 rt2800_rfcsr_write_dccal(rt2x00dev, 26, 0x00);
8385 rt2800_rfcsr_write_dccal(rt2x00dev, 27, 0xD7);
8386 rt2800_rfcsr_write_dccal(rt2x00dev, 28, 0xA2);
8387 rt2800_rfcsr_write_dccal(rt2x00dev, 29, 0x20);
8388 rt2800_rfcsr_write_dccal(rt2x00dev, 30, 0x49);
8389 rt2800_rfcsr_write_dccal(rt2x00dev, 31, 0x20);
8390 rt2800_rfcsr_write_dccal(rt2x00dev, 32, 0x04);
8391 rt2800_rfcsr_write_dccal(rt2x00dev, 33, 0xF1);
8392 rt2800_rfcsr_write_dccal(rt2x00dev, 34, 0xA1);
8393 rt2800_rfcsr_write_dccal(rt2x00dev, 35, 0x01);
8394 rt2800_rfcsr_write_dccal(rt2x00dev, 41, 0x00);
8395 rt2800_rfcsr_write_dccal(rt2x00dev, 42, 0x00);
8396 rt2800_rfcsr_write_dccal(rt2x00dev, 43, 0x00);
8397 rt2800_rfcsr_write_dccal(rt2x00dev, 44, 0x00);
8398 rt2800_rfcsr_write_dccal(rt2x00dev, 45, 0x00);
8399 rt2800_rfcsr_write_dccal(rt2x00dev, 46, 0x00);
8400 rt2800_rfcsr_write_dccal(rt2x00dev, 47, 0x3E);
8401 rt2800_rfcsr_write_dccal(rt2x00dev, 48, 0x3D);
8402 rt2800_rfcsr_write_dccal(rt2x00dev, 49, 0x3E);
8403 rt2800_rfcsr_write_dccal(rt2x00dev, 50, 0x3D);
8404 rt2800_rfcsr_write_dccal(rt2x00dev, 51, 0x3E);
8405 rt2800_rfcsr_write_dccal(rt2x00dev, 52, 0x3D);
8406 rt2800_rfcsr_write_dccal(rt2x00dev, 53, 0x00);
8407 rt2800_rfcsr_write_dccal(rt2x00dev, 54, 0x00);
8408 rt2800_rfcsr_write_dccal(rt2x00dev, 55, 0x00);
8409 rt2800_rfcsr_write_dccal(rt2x00dev, 56, 0x00);
8410 rt2800_rfcsr_write_dccal(rt2x00dev, 57, 0x00);
8411 rt2800_rfcsr_write_dccal(rt2x00dev, 58, 0x10);
8412 rt2800_rfcsr_write_dccal(rt2x00dev, 59, 0x10);
8413 rt2800_rfcsr_write_dccal(rt2x00dev, 60, 0x0A);
8414 rt2800_rfcsr_write_dccal(rt2x00dev, 61, 0x00);
8415 rt2800_rfcsr_write_dccal(rt2x00dev, 62, 0x00);
8416 rt2800_rfcsr_write_dccal(rt2x00dev, 63, 0x00);
8418 rt2800_rfcsr_write_dccal(rt2x00dev, 3, 0x08);
8419 rt2800_rfcsr_write_dccal(rt2x00dev, 4, 0x04);
8420 rt2800_rfcsr_write_dccal(rt2x00dev, 5, 0x20);
8422 rt2800_rfcsr_write_dccal(rt2x00dev, 5, 0x00);
8423 rt2800_rfcsr_write_dccal(rt2x00dev, 17, 0x7C);
8425 rt2800_bw_filter_calibration(rt2x00dev, true);
8426 rt2800_bw_filter_calibration(rt2x00dev, false);
8429 static void rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev)
8431 if (rt2800_is_305x_soc(rt2x00dev)) {
8432 rt2800_init_rfcsr_305x_soc(rt2x00dev);
8433 return;
8436 switch (rt2x00dev->chip.rt) {
8437 case RT3070:
8438 case RT3071:
8439 case RT3090:
8440 rt2800_init_rfcsr_30xx(rt2x00dev);
8441 break;
8442 case RT3290:
8443 rt2800_init_rfcsr_3290(rt2x00dev);
8444 break;
8445 case RT3352:
8446 rt2800_init_rfcsr_3352(rt2x00dev);
8447 break;
8448 case RT3390:
8449 rt2800_init_rfcsr_3390(rt2x00dev);
8450 break;
8451 case RT3572:
8452 rt2800_init_rfcsr_3572(rt2x00dev);
8453 break;
8454 case RT3593:
8455 rt2800_init_rfcsr_3593(rt2x00dev);
8456 break;
8457 case RT5350:
8458 rt2800_init_rfcsr_5350(rt2x00dev);
8459 break;
8460 case RT5390:
8461 rt2800_init_rfcsr_5390(rt2x00dev);
8462 break;
8463 case RT5392:
8464 rt2800_init_rfcsr_5392(rt2x00dev);
8465 break;
8466 case RT5592:
8467 rt2800_init_rfcsr_5592(rt2x00dev);
8468 break;
8469 case RT6352:
8470 rt2800_init_rfcsr_6352(rt2x00dev);
8471 break;
8475 int rt2800_enable_radio(struct rt2x00_dev *rt2x00dev)
8477 u32 reg;
8478 u16 word;
8481 * Initialize MAC registers.
8483 if (unlikely(rt2800_wait_wpdma_ready(rt2x00dev) ||
8484 rt2800_init_registers(rt2x00dev)))
8485 return -EIO;
8488 * Wait BBP/RF to wake up.
8490 if (unlikely(rt2800_wait_bbp_rf_ready(rt2x00dev)))
8491 return -EIO;
8494 * Send signal during boot time to initialize firmware.
8496 rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
8497 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
8498 if (rt2x00_is_usb(rt2x00dev))
8499 rt2800_register_write(rt2x00dev, H2M_INT_SRC, 0);
8500 rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0, 0, 0);
8501 msleep(1);
8504 * Make sure BBP is up and running.
8506 if (unlikely(rt2800_wait_bbp_ready(rt2x00dev)))
8507 return -EIO;
8510 * Initialize BBP/RF registers.
8512 rt2800_init_bbp(rt2x00dev);
8513 rt2800_init_rfcsr(rt2x00dev);
8515 if (rt2x00_is_usb(rt2x00dev) &&
8516 (rt2x00_rt(rt2x00dev, RT3070) ||
8517 rt2x00_rt(rt2x00dev, RT3071) ||
8518 rt2x00_rt(rt2x00dev, RT3572))) {
8519 udelay(200);
8520 rt2800_mcu_request(rt2x00dev, MCU_CURRENT, 0, 0, 0);
8521 udelay(10);
8525 * Enable RX.
8527 reg = rt2800_register_read(rt2x00dev, MAC_SYS_CTRL);
8528 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
8529 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 0);
8530 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
8532 udelay(50);
8534 reg = rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG);
8535 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 1);
8536 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 1);
8537 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
8538 rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
8540 reg = rt2800_register_read(rt2x00dev, MAC_SYS_CTRL);
8541 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
8542 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 1);
8543 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
8546 * Initialize LED control
8548 word = rt2800_eeprom_read(rt2x00dev, EEPROM_LED_AG_CONF);
8549 rt2800_mcu_request(rt2x00dev, MCU_LED_AG_CONF, 0xff,
8550 word & 0xff, (word >> 8) & 0xff);
8552 word = rt2800_eeprom_read(rt2x00dev, EEPROM_LED_ACT_CONF);
8553 rt2800_mcu_request(rt2x00dev, MCU_LED_ACT_CONF, 0xff,
8554 word & 0xff, (word >> 8) & 0xff);
8556 word = rt2800_eeprom_read(rt2x00dev, EEPROM_LED_POLARITY);
8557 rt2800_mcu_request(rt2x00dev, MCU_LED_LED_POLARITY, 0xff,
8558 word & 0xff, (word >> 8) & 0xff);
8560 return 0;
8562 EXPORT_SYMBOL_GPL(rt2800_enable_radio);
8564 void rt2800_disable_radio(struct rt2x00_dev *rt2x00dev)
8566 u32 reg;
8568 rt2800_disable_wpdma(rt2x00dev);
8570 /* Wait for DMA, ignore error */
8571 rt2800_wait_wpdma_ready(rt2x00dev);
8573 reg = rt2800_register_read(rt2x00dev, MAC_SYS_CTRL);
8574 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 0);
8575 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 0);
8576 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
8578 EXPORT_SYMBOL_GPL(rt2800_disable_radio);
8580 int rt2800_efuse_detect(struct rt2x00_dev *rt2x00dev)
8582 u32 reg;
8583 u16 efuse_ctrl_reg;
8585 if (rt2x00_rt(rt2x00dev, RT3290))
8586 efuse_ctrl_reg = EFUSE_CTRL_3290;
8587 else
8588 efuse_ctrl_reg = EFUSE_CTRL;
8590 reg = rt2800_register_read(rt2x00dev, efuse_ctrl_reg);
8591 return rt2x00_get_field32(reg, EFUSE_CTRL_PRESENT);
8593 EXPORT_SYMBOL_GPL(rt2800_efuse_detect);
8595 static void rt2800_efuse_read(struct rt2x00_dev *rt2x00dev, unsigned int i)
8597 u32 reg;
8598 u16 efuse_ctrl_reg;
8599 u16 efuse_data0_reg;
8600 u16 efuse_data1_reg;
8601 u16 efuse_data2_reg;
8602 u16 efuse_data3_reg;
8604 if (rt2x00_rt(rt2x00dev, RT3290)) {
8605 efuse_ctrl_reg = EFUSE_CTRL_3290;
8606 efuse_data0_reg = EFUSE_DATA0_3290;
8607 efuse_data1_reg = EFUSE_DATA1_3290;
8608 efuse_data2_reg = EFUSE_DATA2_3290;
8609 efuse_data3_reg = EFUSE_DATA3_3290;
8610 } else {
8611 efuse_ctrl_reg = EFUSE_CTRL;
8612 efuse_data0_reg = EFUSE_DATA0;
8613 efuse_data1_reg = EFUSE_DATA1;
8614 efuse_data2_reg = EFUSE_DATA2;
8615 efuse_data3_reg = EFUSE_DATA3;
8617 mutex_lock(&rt2x00dev->csr_mutex);
8619 reg = rt2800_register_read_lock(rt2x00dev, efuse_ctrl_reg);
8620 rt2x00_set_field32(&reg, EFUSE_CTRL_ADDRESS_IN, i);
8621 rt2x00_set_field32(&reg, EFUSE_CTRL_MODE, 0);
8622 rt2x00_set_field32(&reg, EFUSE_CTRL_KICK, 1);
8623 rt2800_register_write_lock(rt2x00dev, efuse_ctrl_reg, reg);
8625 /* Wait until the EEPROM has been loaded */
8626 rt2800_regbusy_read(rt2x00dev, efuse_ctrl_reg, EFUSE_CTRL_KICK, &reg);
8627 /* Apparently the data is read from end to start */
8628 reg = rt2800_register_read_lock(rt2x00dev, efuse_data3_reg);
8629 /* The returned value is in CPU order, but eeprom is le */
8630 *(u32 *)&rt2x00dev->eeprom[i] = cpu_to_le32(reg);
8631 reg = rt2800_register_read_lock(rt2x00dev, efuse_data2_reg);
8632 *(u32 *)&rt2x00dev->eeprom[i + 2] = cpu_to_le32(reg);
8633 reg = rt2800_register_read_lock(rt2x00dev, efuse_data1_reg);
8634 *(u32 *)&rt2x00dev->eeprom[i + 4] = cpu_to_le32(reg);
8635 reg = rt2800_register_read_lock(rt2x00dev, efuse_data0_reg);
8636 *(u32 *)&rt2x00dev->eeprom[i + 6] = cpu_to_le32(reg);
8638 mutex_unlock(&rt2x00dev->csr_mutex);
8641 int rt2800_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev)
8643 unsigned int i;
8645 for (i = 0; i < EEPROM_SIZE / sizeof(u16); i += 8)
8646 rt2800_efuse_read(rt2x00dev, i);
8648 return 0;
8650 EXPORT_SYMBOL_GPL(rt2800_read_eeprom_efuse);
8652 static u8 rt2800_get_txmixer_gain_24g(struct rt2x00_dev *rt2x00dev)
8654 u16 word;
8656 if (rt2x00_rt(rt2x00dev, RT3593))
8657 return 0;
8659 word = rt2800_eeprom_read(rt2x00dev, EEPROM_TXMIXER_GAIN_BG);
8660 if ((word & 0x00ff) != 0x00ff)
8661 return rt2x00_get_field16(word, EEPROM_TXMIXER_GAIN_BG_VAL);
8663 return 0;
8666 static u8 rt2800_get_txmixer_gain_5g(struct rt2x00_dev *rt2x00dev)
8668 u16 word;
8670 if (rt2x00_rt(rt2x00dev, RT3593))
8671 return 0;
8673 word = rt2800_eeprom_read(rt2x00dev, EEPROM_TXMIXER_GAIN_A);
8674 if ((word & 0x00ff) != 0x00ff)
8675 return rt2x00_get_field16(word, EEPROM_TXMIXER_GAIN_A_VAL);
8677 return 0;
8680 static int rt2800_validate_eeprom(struct rt2x00_dev *rt2x00dev)
8682 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
8683 u16 word;
8684 u8 *mac;
8685 u8 default_lna_gain;
8686 int retval;
8689 * Read the EEPROM.
8691 retval = rt2800_read_eeprom(rt2x00dev);
8692 if (retval)
8693 return retval;
8696 * Start validation of the data that has been read.
8698 mac = rt2800_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
8699 rt2x00lib_set_mac_address(rt2x00dev, mac);
8701 word = rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0);
8702 if (word == 0xffff) {
8703 rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RXPATH, 2);
8704 rt2x00_set_field16(&word, EEPROM_NIC_CONF0_TXPATH, 1);
8705 rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RF_TYPE, RF2820);
8706 rt2800_eeprom_write(rt2x00dev, EEPROM_NIC_CONF0, word);
8707 rt2x00_eeprom_dbg(rt2x00dev, "Antenna: 0x%04x\n", word);
8708 } else if (rt2x00_rt(rt2x00dev, RT2860) ||
8709 rt2x00_rt(rt2x00dev, RT2872)) {
8711 * There is a max of 2 RX streams for RT28x0 series
8713 if (rt2x00_get_field16(word, EEPROM_NIC_CONF0_RXPATH) > 2)
8714 rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RXPATH, 2);
8715 rt2800_eeprom_write(rt2x00dev, EEPROM_NIC_CONF0, word);
8718 word = rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1);
8719 if (word == 0xffff) {
8720 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_HW_RADIO, 0);
8721 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_TX_ALC, 0);
8722 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_LNA_2G, 0);
8723 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_LNA_5G, 0);
8724 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_CARDBUS_ACCEL, 0);
8725 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_SB_2G, 0);
8726 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_SB_5G, 0);
8727 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_WPS_PBC, 0);
8728 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_2G, 0);
8729 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_5G, 0);
8730 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BROADBAND_EXT_LNA, 0);
8731 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_ANT_DIVERSITY, 0);
8732 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_INTERNAL_TX_ALC, 0);
8733 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BT_COEXIST, 0);
8734 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_DAC_TEST, 0);
8735 rt2800_eeprom_write(rt2x00dev, EEPROM_NIC_CONF1, word);
8736 rt2x00_eeprom_dbg(rt2x00dev, "NIC: 0x%04x\n", word);
8739 word = rt2800_eeprom_read(rt2x00dev, EEPROM_FREQ);
8740 if ((word & 0x00ff) == 0x00ff) {
8741 rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0);
8742 rt2800_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
8743 rt2x00_eeprom_dbg(rt2x00dev, "Freq: 0x%04x\n", word);
8745 if ((word & 0xff00) == 0xff00) {
8746 rt2x00_set_field16(&word, EEPROM_FREQ_LED_MODE,
8747 LED_MODE_TXRX_ACTIVITY);
8748 rt2x00_set_field16(&word, EEPROM_FREQ_LED_POLARITY, 0);
8749 rt2800_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
8750 rt2800_eeprom_write(rt2x00dev, EEPROM_LED_AG_CONF, 0x5555);
8751 rt2800_eeprom_write(rt2x00dev, EEPROM_LED_ACT_CONF, 0x2221);
8752 rt2800_eeprom_write(rt2x00dev, EEPROM_LED_POLARITY, 0xa9f8);
8753 rt2x00_eeprom_dbg(rt2x00dev, "Led Mode: 0x%04x\n", word);
8757 * During the LNA validation we are going to use
8758 * lna0 as correct value. Note that EEPROM_LNA
8759 * is never validated.
8761 word = rt2800_eeprom_read(rt2x00dev, EEPROM_LNA);
8762 default_lna_gain = rt2x00_get_field16(word, EEPROM_LNA_A0);
8764 word = rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG);
8765 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET0)) > 10)
8766 rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET0, 0);
8767 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET1)) > 10)
8768 rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET1, 0);
8769 rt2800_eeprom_write(rt2x00dev, EEPROM_RSSI_BG, word);
8771 drv_data->txmixer_gain_24g = rt2800_get_txmixer_gain_24g(rt2x00dev);
8773 word = rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2);
8774 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG2_OFFSET2)) > 10)
8775 rt2x00_set_field16(&word, EEPROM_RSSI_BG2_OFFSET2, 0);
8776 if (!rt2x00_rt(rt2x00dev, RT3593)) {
8777 if (rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0x00 ||
8778 rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0xff)
8779 rt2x00_set_field16(&word, EEPROM_RSSI_BG2_LNA_A1,
8780 default_lna_gain);
8782 rt2800_eeprom_write(rt2x00dev, EEPROM_RSSI_BG2, word);
8784 drv_data->txmixer_gain_5g = rt2800_get_txmixer_gain_5g(rt2x00dev);
8786 word = rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A);
8787 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET0)) > 10)
8788 rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET0, 0);
8789 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET1)) > 10)
8790 rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET1, 0);
8791 rt2800_eeprom_write(rt2x00dev, EEPROM_RSSI_A, word);
8793 word = rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A2);
8794 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A2_OFFSET2)) > 10)
8795 rt2x00_set_field16(&word, EEPROM_RSSI_A2_OFFSET2, 0);
8796 if (!rt2x00_rt(rt2x00dev, RT3593)) {
8797 if (rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0x00 ||
8798 rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0xff)
8799 rt2x00_set_field16(&word, EEPROM_RSSI_A2_LNA_A2,
8800 default_lna_gain);
8802 rt2800_eeprom_write(rt2x00dev, EEPROM_RSSI_A2, word);
8804 if (rt2x00_rt(rt2x00dev, RT3593)) {
8805 word = rt2800_eeprom_read(rt2x00dev, EEPROM_EXT_LNA2);
8806 if (rt2x00_get_field16(word, EEPROM_EXT_LNA2_A1) == 0x00 ||
8807 rt2x00_get_field16(word, EEPROM_EXT_LNA2_A1) == 0xff)
8808 rt2x00_set_field16(&word, EEPROM_EXT_LNA2_A1,
8809 default_lna_gain);
8810 if (rt2x00_get_field16(word, EEPROM_EXT_LNA2_A2) == 0x00 ||
8811 rt2x00_get_field16(word, EEPROM_EXT_LNA2_A2) == 0xff)
8812 rt2x00_set_field16(&word, EEPROM_EXT_LNA2_A1,
8813 default_lna_gain);
8814 rt2800_eeprom_write(rt2x00dev, EEPROM_EXT_LNA2, word);
8817 return 0;
8820 static int rt2800_init_eeprom(struct rt2x00_dev *rt2x00dev)
8822 u16 value;
8823 u16 eeprom;
8824 u16 rf;
8827 * Read EEPROM word for configuration.
8829 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0);
8832 * Identify RF chipset by EEPROM value
8833 * RT28xx/RT30xx: defined in "EEPROM_NIC_CONF0_RF_TYPE" field
8834 * RT53xx: defined in "EEPROM_CHIP_ID" field
8836 if (rt2x00_rt(rt2x00dev, RT3290) ||
8837 rt2x00_rt(rt2x00dev, RT5390) ||
8838 rt2x00_rt(rt2x00dev, RT5392) ||
8839 rt2x00_rt(rt2x00dev, RT6352))
8840 rf = rt2800_eeprom_read(rt2x00dev, EEPROM_CHIP_ID);
8841 else if (rt2x00_rt(rt2x00dev, RT3352))
8842 rf = RF3322;
8843 else if (rt2x00_rt(rt2x00dev, RT5350))
8844 rf = RF5350;
8845 else
8846 rf = rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RF_TYPE);
8848 switch (rf) {
8849 case RF2820:
8850 case RF2850:
8851 case RF2720:
8852 case RF2750:
8853 case RF3020:
8854 case RF2020:
8855 case RF3021:
8856 case RF3022:
8857 case RF3052:
8858 case RF3053:
8859 case RF3070:
8860 case RF3290:
8861 case RF3320:
8862 case RF3322:
8863 case RF5350:
8864 case RF5360:
8865 case RF5362:
8866 case RF5370:
8867 case RF5372:
8868 case RF5390:
8869 case RF5392:
8870 case RF5592:
8871 case RF7620:
8872 break;
8873 default:
8874 rt2x00_err(rt2x00dev, "Invalid RF chipset 0x%04x detected\n",
8875 rf);
8876 return -ENODEV;
8879 rt2x00_set_rf(rt2x00dev, rf);
8882 * Identify default antenna configuration.
8884 rt2x00dev->default_ant.tx_chain_num =
8885 rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH);
8886 rt2x00dev->default_ant.rx_chain_num =
8887 rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH);
8889 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1);
8891 if (rt2x00_rt(rt2x00dev, RT3070) ||
8892 rt2x00_rt(rt2x00dev, RT3090) ||
8893 rt2x00_rt(rt2x00dev, RT3352) ||
8894 rt2x00_rt(rt2x00dev, RT3390)) {
8895 value = rt2x00_get_field16(eeprom,
8896 EEPROM_NIC_CONF1_ANT_DIVERSITY);
8897 switch (value) {
8898 case 0:
8899 case 1:
8900 case 2:
8901 rt2x00dev->default_ant.tx = ANTENNA_A;
8902 rt2x00dev->default_ant.rx = ANTENNA_A;
8903 break;
8904 case 3:
8905 rt2x00dev->default_ant.tx = ANTENNA_A;
8906 rt2x00dev->default_ant.rx = ANTENNA_B;
8907 break;
8909 } else {
8910 rt2x00dev->default_ant.tx = ANTENNA_A;
8911 rt2x00dev->default_ant.rx = ANTENNA_A;
8914 /* These chips have hardware RX antenna diversity */
8915 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390R) ||
8916 rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5370G)) {
8917 rt2x00dev->default_ant.tx = ANTENNA_HW_DIVERSITY; /* Unused */
8918 rt2x00dev->default_ant.rx = ANTENNA_HW_DIVERSITY; /* Unused */
8922 * Determine external LNA informations.
8924 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_EXTERNAL_LNA_5G))
8925 __set_bit(CAPABILITY_EXTERNAL_LNA_A, &rt2x00dev->cap_flags);
8926 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_EXTERNAL_LNA_2G))
8927 __set_bit(CAPABILITY_EXTERNAL_LNA_BG, &rt2x00dev->cap_flags);
8930 * Detect if this device has an hardware controlled radio.
8932 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_HW_RADIO))
8933 __set_bit(CAPABILITY_HW_BUTTON, &rt2x00dev->cap_flags);
8936 * Detect if this device has Bluetooth co-existence.
8938 if (!rt2x00_rt(rt2x00dev, RT3352) &&
8939 rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_BT_COEXIST))
8940 __set_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags);
8943 * Read frequency offset and RF programming sequence.
8945 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_FREQ);
8946 rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET);
8949 * Store led settings, for correct led behaviour.
8951 #ifdef CONFIG_RT2X00_LIB_LEDS
8952 rt2800_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
8953 rt2800_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
8954 rt2800_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY);
8956 rt2x00dev->led_mcu_reg = eeprom;
8957 #endif /* CONFIG_RT2X00_LIB_LEDS */
8960 * Check if support EIRP tx power limit feature.
8962 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_EIRP_MAX_TX_POWER);
8964 if (rt2x00_get_field16(eeprom, EEPROM_EIRP_MAX_TX_POWER_2GHZ) <
8965 EIRP_MAX_TX_POWER_LIMIT)
8966 __set_bit(CAPABILITY_POWER_LIMIT, &rt2x00dev->cap_flags);
8969 * Detect if device uses internal or external PA
8971 eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1);
8973 if (rt2x00_rt(rt2x00dev, RT3352)) {
8974 if (rt2x00_get_field16(eeprom,
8975 EEPROM_NIC_CONF1_EXTERNAL_TX0_PA_3352))
8976 __set_bit(CAPABILITY_EXTERNAL_PA_TX0,
8977 &rt2x00dev->cap_flags);
8978 if (rt2x00_get_field16(eeprom,
8979 EEPROM_NIC_CONF1_EXTERNAL_TX1_PA_3352))
8980 __set_bit(CAPABILITY_EXTERNAL_PA_TX1,
8981 &rt2x00dev->cap_flags);
8984 return 0;
8988 * RF value list for rt28xx
8989 * Supports: 2.4 GHz (all) & 5.2 GHz (RF2850 & RF2750)
8991 static const struct rf_channel rf_vals[] = {
8992 { 1, 0x18402ecc, 0x184c0786, 0x1816b455, 0x1800510b },
8993 { 2, 0x18402ecc, 0x184c0786, 0x18168a55, 0x1800519f },
8994 { 3, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800518b },
8995 { 4, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800519f },
8996 { 5, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800518b },
8997 { 6, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800519f },
8998 { 7, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800518b },
8999 { 8, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800519f },
9000 { 9, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800518b },
9001 { 10, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800519f },
9002 { 11, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800518b },
9003 { 12, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800519f },
9004 { 13, 0x18402ecc, 0x184c079e, 0x18168a55, 0x1800518b },
9005 { 14, 0x18402ecc, 0x184c07a2, 0x18168a55, 0x18005193 },
9007 /* 802.11 UNI / HyperLan 2 */
9008 { 36, 0x18402ecc, 0x184c099a, 0x18158a55, 0x180ed1a3 },
9009 { 38, 0x18402ecc, 0x184c099e, 0x18158a55, 0x180ed193 },
9010 { 40, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed183 },
9011 { 44, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed1a3 },
9012 { 46, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed18b },
9013 { 48, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed19b },
9014 { 52, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed193 },
9015 { 54, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed1a3 },
9016 { 56, 0x18402ec8, 0x184c068e, 0x18158a55, 0x180ed18b },
9017 { 60, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed183 },
9018 { 62, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed193 },
9019 { 64, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed1a3 },
9021 /* 802.11 HyperLan 2 */
9022 { 100, 0x18402ec8, 0x184c06b2, 0x18178a55, 0x180ed783 },
9023 { 102, 0x18402ec8, 0x184c06b2, 0x18578a55, 0x180ed793 },
9024 { 104, 0x18402ec8, 0x185c06b2, 0x18578a55, 0x180ed1a3 },
9025 { 108, 0x18402ecc, 0x185c0a32, 0x18578a55, 0x180ed193 },
9026 { 110, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed183 },
9027 { 112, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed19b },
9028 { 116, 0x18402ecc, 0x184c0a3a, 0x18178a55, 0x180ed1a3 },
9029 { 118, 0x18402ecc, 0x184c0a3e, 0x18178a55, 0x180ed193 },
9030 { 120, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed183 },
9031 { 124, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed193 },
9032 { 126, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed15b },
9033 { 128, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed1a3 },
9034 { 132, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed18b },
9035 { 134, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed193 },
9036 { 136, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed19b },
9037 { 140, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed183 },
9039 /* 802.11 UNII */
9040 { 149, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed1a7 },
9041 { 151, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed187 },
9042 { 153, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed18f },
9043 { 157, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed19f },
9044 { 159, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed1a7 },
9045 { 161, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed187 },
9046 { 165, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed197 },
9047 { 167, 0x18402ec4, 0x184c03d2, 0x18179855, 0x1815531f },
9048 { 169, 0x18402ec4, 0x184c03d2, 0x18179855, 0x18155327 },
9049 { 171, 0x18402ec4, 0x184c03d6, 0x18179855, 0x18155307 },
9050 { 173, 0x18402ec4, 0x184c03d6, 0x18179855, 0x1815530f },
9052 /* 802.11 Japan */
9053 { 184, 0x15002ccc, 0x1500491e, 0x1509be55, 0x150c0a0b },
9054 { 188, 0x15002ccc, 0x15004922, 0x1509be55, 0x150c0a13 },
9055 { 192, 0x15002ccc, 0x15004926, 0x1509be55, 0x150c0a1b },
9056 { 196, 0x15002ccc, 0x1500492a, 0x1509be55, 0x150c0a23 },
9057 { 208, 0x15002ccc, 0x1500493a, 0x1509be55, 0x150c0a13 },
9058 { 212, 0x15002ccc, 0x1500493e, 0x1509be55, 0x150c0a1b },
9059 { 216, 0x15002ccc, 0x15004982, 0x1509be55, 0x150c0a23 },
9063 * RF value list for rt3xxx
9064 * Supports: 2.4 GHz (all) & 5.2 GHz (RF3052 & RF3053)
9066 static const struct rf_channel rf_vals_3x[] = {
9067 {1, 241, 2, 2 },
9068 {2, 241, 2, 7 },
9069 {3, 242, 2, 2 },
9070 {4, 242, 2, 7 },
9071 {5, 243, 2, 2 },
9072 {6, 243, 2, 7 },
9073 {7, 244, 2, 2 },
9074 {8, 244, 2, 7 },
9075 {9, 245, 2, 2 },
9076 {10, 245, 2, 7 },
9077 {11, 246, 2, 2 },
9078 {12, 246, 2, 7 },
9079 {13, 247, 2, 2 },
9080 {14, 248, 2, 4 },
9082 /* 802.11 UNI / HyperLan 2 */
9083 {36, 0x56, 0, 4},
9084 {38, 0x56, 0, 6},
9085 {40, 0x56, 0, 8},
9086 {44, 0x57, 0, 0},
9087 {46, 0x57, 0, 2},
9088 {48, 0x57, 0, 4},
9089 {52, 0x57, 0, 8},
9090 {54, 0x57, 0, 10},
9091 {56, 0x58, 0, 0},
9092 {60, 0x58, 0, 4},
9093 {62, 0x58, 0, 6},
9094 {64, 0x58, 0, 8},
9096 /* 802.11 HyperLan 2 */
9097 {100, 0x5b, 0, 8},
9098 {102, 0x5b, 0, 10},
9099 {104, 0x5c, 0, 0},
9100 {108, 0x5c, 0, 4},
9101 {110, 0x5c, 0, 6},
9102 {112, 0x5c, 0, 8},
9103 {116, 0x5d, 0, 0},
9104 {118, 0x5d, 0, 2},
9105 {120, 0x5d, 0, 4},
9106 {124, 0x5d, 0, 8},
9107 {126, 0x5d, 0, 10},
9108 {128, 0x5e, 0, 0},
9109 {132, 0x5e, 0, 4},
9110 {134, 0x5e, 0, 6},
9111 {136, 0x5e, 0, 8},
9112 {140, 0x5f, 0, 0},
9114 /* 802.11 UNII */
9115 {149, 0x5f, 0, 9},
9116 {151, 0x5f, 0, 11},
9117 {153, 0x60, 0, 1},
9118 {157, 0x60, 0, 5},
9119 {159, 0x60, 0, 7},
9120 {161, 0x60, 0, 9},
9121 {165, 0x61, 0, 1},
9122 {167, 0x61, 0, 3},
9123 {169, 0x61, 0, 5},
9124 {171, 0x61, 0, 7},
9125 {173, 0x61, 0, 9},
9129 * RF value list for rt3xxx with Xtal20MHz
9130 * Supports: 2.4 GHz (all) (RF3322)
9132 static const struct rf_channel rf_vals_3x_xtal20[] = {
9133 {1, 0xE2, 2, 0x14},
9134 {2, 0xE3, 2, 0x14},
9135 {3, 0xE4, 2, 0x14},
9136 {4, 0xE5, 2, 0x14},
9137 {5, 0xE6, 2, 0x14},
9138 {6, 0xE7, 2, 0x14},
9139 {7, 0xE8, 2, 0x14},
9140 {8, 0xE9, 2, 0x14},
9141 {9, 0xEA, 2, 0x14},
9142 {10, 0xEB, 2, 0x14},
9143 {11, 0xEC, 2, 0x14},
9144 {12, 0xED, 2, 0x14},
9145 {13, 0xEE, 2, 0x14},
9146 {14, 0xF0, 2, 0x18},
9149 static const struct rf_channel rf_vals_5592_xtal20[] = {
9150 /* Channel, N, K, mod, R */
9151 {1, 482, 4, 10, 3},
9152 {2, 483, 4, 10, 3},
9153 {3, 484, 4, 10, 3},
9154 {4, 485, 4, 10, 3},
9155 {5, 486, 4, 10, 3},
9156 {6, 487, 4, 10, 3},
9157 {7, 488, 4, 10, 3},
9158 {8, 489, 4, 10, 3},
9159 {9, 490, 4, 10, 3},
9160 {10, 491, 4, 10, 3},
9161 {11, 492, 4, 10, 3},
9162 {12, 493, 4, 10, 3},
9163 {13, 494, 4, 10, 3},
9164 {14, 496, 8, 10, 3},
9165 {36, 172, 8, 12, 1},
9166 {38, 173, 0, 12, 1},
9167 {40, 173, 4, 12, 1},
9168 {42, 173, 8, 12, 1},
9169 {44, 174, 0, 12, 1},
9170 {46, 174, 4, 12, 1},
9171 {48, 174, 8, 12, 1},
9172 {50, 175, 0, 12, 1},
9173 {52, 175, 4, 12, 1},
9174 {54, 175, 8, 12, 1},
9175 {56, 176, 0, 12, 1},
9176 {58, 176, 4, 12, 1},
9177 {60, 176, 8, 12, 1},
9178 {62, 177, 0, 12, 1},
9179 {64, 177, 4, 12, 1},
9180 {100, 183, 4, 12, 1},
9181 {102, 183, 8, 12, 1},
9182 {104, 184, 0, 12, 1},
9183 {106, 184, 4, 12, 1},
9184 {108, 184, 8, 12, 1},
9185 {110, 185, 0, 12, 1},
9186 {112, 185, 4, 12, 1},
9187 {114, 185, 8, 12, 1},
9188 {116, 186, 0, 12, 1},
9189 {118, 186, 4, 12, 1},
9190 {120, 186, 8, 12, 1},
9191 {122, 187, 0, 12, 1},
9192 {124, 187, 4, 12, 1},
9193 {126, 187, 8, 12, 1},
9194 {128, 188, 0, 12, 1},
9195 {130, 188, 4, 12, 1},
9196 {132, 188, 8, 12, 1},
9197 {134, 189, 0, 12, 1},
9198 {136, 189, 4, 12, 1},
9199 {138, 189, 8, 12, 1},
9200 {140, 190, 0, 12, 1},
9201 {149, 191, 6, 12, 1},
9202 {151, 191, 10, 12, 1},
9203 {153, 192, 2, 12, 1},
9204 {155, 192, 6, 12, 1},
9205 {157, 192, 10, 12, 1},
9206 {159, 193, 2, 12, 1},
9207 {161, 193, 6, 12, 1},
9208 {165, 194, 2, 12, 1},
9209 {184, 164, 0, 12, 1},
9210 {188, 164, 4, 12, 1},
9211 {192, 165, 8, 12, 1},
9212 {196, 166, 0, 12, 1},
9215 static const struct rf_channel rf_vals_5592_xtal40[] = {
9216 /* Channel, N, K, mod, R */
9217 {1, 241, 2, 10, 3},
9218 {2, 241, 7, 10, 3},
9219 {3, 242, 2, 10, 3},
9220 {4, 242, 7, 10, 3},
9221 {5, 243, 2, 10, 3},
9222 {6, 243, 7, 10, 3},
9223 {7, 244, 2, 10, 3},
9224 {8, 244, 7, 10, 3},
9225 {9, 245, 2, 10, 3},
9226 {10, 245, 7, 10, 3},
9227 {11, 246, 2, 10, 3},
9228 {12, 246, 7, 10, 3},
9229 {13, 247, 2, 10, 3},
9230 {14, 248, 4, 10, 3},
9231 {36, 86, 4, 12, 1},
9232 {38, 86, 6, 12, 1},
9233 {40, 86, 8, 12, 1},
9234 {42, 86, 10, 12, 1},
9235 {44, 87, 0, 12, 1},
9236 {46, 87, 2, 12, 1},
9237 {48, 87, 4, 12, 1},
9238 {50, 87, 6, 12, 1},
9239 {52, 87, 8, 12, 1},
9240 {54, 87, 10, 12, 1},
9241 {56, 88, 0, 12, 1},
9242 {58, 88, 2, 12, 1},
9243 {60, 88, 4, 12, 1},
9244 {62, 88, 6, 12, 1},
9245 {64, 88, 8, 12, 1},
9246 {100, 91, 8, 12, 1},
9247 {102, 91, 10, 12, 1},
9248 {104, 92, 0, 12, 1},
9249 {106, 92, 2, 12, 1},
9250 {108, 92, 4, 12, 1},
9251 {110, 92, 6, 12, 1},
9252 {112, 92, 8, 12, 1},
9253 {114, 92, 10, 12, 1},
9254 {116, 93, 0, 12, 1},
9255 {118, 93, 2, 12, 1},
9256 {120, 93, 4, 12, 1},
9257 {122, 93, 6, 12, 1},
9258 {124, 93, 8, 12, 1},
9259 {126, 93, 10, 12, 1},
9260 {128, 94, 0, 12, 1},
9261 {130, 94, 2, 12, 1},
9262 {132, 94, 4, 12, 1},
9263 {134, 94, 6, 12, 1},
9264 {136, 94, 8, 12, 1},
9265 {138, 94, 10, 12, 1},
9266 {140, 95, 0, 12, 1},
9267 {149, 95, 9, 12, 1},
9268 {151, 95, 11, 12, 1},
9269 {153, 96, 1, 12, 1},
9270 {155, 96, 3, 12, 1},
9271 {157, 96, 5, 12, 1},
9272 {159, 96, 7, 12, 1},
9273 {161, 96, 9, 12, 1},
9274 {165, 97, 1, 12, 1},
9275 {184, 82, 0, 12, 1},
9276 {188, 82, 4, 12, 1},
9277 {192, 82, 8, 12, 1},
9278 {196, 83, 0, 12, 1},
9281 static const struct rf_channel rf_vals_7620[] = {
9282 {1, 0x50, 0x99, 0x99, 1},
9283 {2, 0x50, 0x44, 0x44, 2},
9284 {3, 0x50, 0xEE, 0xEE, 2},
9285 {4, 0x50, 0x99, 0x99, 3},
9286 {5, 0x51, 0x44, 0x44, 0},
9287 {6, 0x51, 0xEE, 0xEE, 0},
9288 {7, 0x51, 0x99, 0x99, 1},
9289 {8, 0x51, 0x44, 0x44, 2},
9290 {9, 0x51, 0xEE, 0xEE, 2},
9291 {10, 0x51, 0x99, 0x99, 3},
9292 {11, 0x52, 0x44, 0x44, 0},
9293 {12, 0x52, 0xEE, 0xEE, 0},
9294 {13, 0x52, 0x99, 0x99, 1},
9295 {14, 0x52, 0x33, 0x33, 3},
9298 static int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
9300 struct hw_mode_spec *spec = &rt2x00dev->spec;
9301 struct channel_info *info;
9302 char *default_power1;
9303 char *default_power2;
9304 char *default_power3;
9305 unsigned int i, tx_chains, rx_chains;
9306 u32 reg;
9309 * Disable powersaving as default.
9311 rt2x00dev->hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
9314 * Change default retry settings to values corresponding more closely
9315 * to rate[0].count setting of minstrel rate control algorithm.
9317 rt2x00dev->hw->wiphy->retry_short = 2;
9318 rt2x00dev->hw->wiphy->retry_long = 2;
9321 * Initialize all hw fields.
9323 ieee80211_hw_set(rt2x00dev->hw, REPORTS_TX_ACK_STATUS);
9324 ieee80211_hw_set(rt2x00dev->hw, AMPDU_AGGREGATION);
9325 ieee80211_hw_set(rt2x00dev->hw, PS_NULLFUNC_STACK);
9326 ieee80211_hw_set(rt2x00dev->hw, SIGNAL_DBM);
9327 ieee80211_hw_set(rt2x00dev->hw, SUPPORTS_PS);
9330 * Don't set IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING for USB devices
9331 * unless we are capable of sending the buffered frames out after the
9332 * DTIM transmission using rt2x00lib_beacondone. This will send out
9333 * multicast and broadcast traffic immediately instead of buffering it
9334 * infinitly and thus dropping it after some time.
9336 if (!rt2x00_is_usb(rt2x00dev))
9337 ieee80211_hw_set(rt2x00dev->hw, HOST_BROADCAST_PS_BUFFERING);
9339 /* Set MFP if HW crypto is disabled. */
9340 if (rt2800_hwcrypt_disabled(rt2x00dev))
9341 ieee80211_hw_set(rt2x00dev->hw, MFP_CAPABLE);
9343 SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
9344 SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
9345 rt2800_eeprom_addr(rt2x00dev,
9346 EEPROM_MAC_ADDR_0));
9349 * As rt2800 has a global fallback table we cannot specify
9350 * more then one tx rate per frame but since the hw will
9351 * try several rates (based on the fallback table) we should
9352 * initialize max_report_rates to the maximum number of rates
9353 * we are going to try. Otherwise mac80211 will truncate our
9354 * reported tx rates and the rc algortihm will end up with
9355 * incorrect data.
9357 rt2x00dev->hw->max_rates = 1;
9358 rt2x00dev->hw->max_report_rates = 7;
9359 rt2x00dev->hw->max_rate_tries = 1;
9362 * Initialize hw_mode information.
9364 spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
9366 switch (rt2x00dev->chip.rf) {
9367 case RF2720:
9368 case RF2820:
9369 spec->num_channels = 14;
9370 spec->channels = rf_vals;
9371 break;
9373 case RF2750:
9374 case RF2850:
9375 spec->num_channels = ARRAY_SIZE(rf_vals);
9376 spec->channels = rf_vals;
9377 break;
9379 case RF2020:
9380 case RF3020:
9381 case RF3021:
9382 case RF3022:
9383 case RF3070:
9384 case RF3290:
9385 case RF3320:
9386 case RF3322:
9387 case RF5350:
9388 case RF5360:
9389 case RF5362:
9390 case RF5370:
9391 case RF5372:
9392 case RF5390:
9393 case RF5392:
9394 spec->num_channels = 14;
9395 if (rt2800_clk_is_20mhz(rt2x00dev))
9396 spec->channels = rf_vals_3x_xtal20;
9397 else
9398 spec->channels = rf_vals_3x;
9399 break;
9401 case RF7620:
9402 spec->num_channels = ARRAY_SIZE(rf_vals_7620);
9403 spec->channels = rf_vals_7620;
9404 break;
9406 case RF3052:
9407 case RF3053:
9408 spec->num_channels = ARRAY_SIZE(rf_vals_3x);
9409 spec->channels = rf_vals_3x;
9410 break;
9412 case RF5592:
9413 reg = rt2800_register_read(rt2x00dev, MAC_DEBUG_INDEX);
9414 if (rt2x00_get_field32(reg, MAC_DEBUG_INDEX_XTAL)) {
9415 spec->num_channels = ARRAY_SIZE(rf_vals_5592_xtal40);
9416 spec->channels = rf_vals_5592_xtal40;
9417 } else {
9418 spec->num_channels = ARRAY_SIZE(rf_vals_5592_xtal20);
9419 spec->channels = rf_vals_5592_xtal20;
9421 break;
9424 if (WARN_ON_ONCE(!spec->channels))
9425 return -ENODEV;
9427 spec->supported_bands = SUPPORT_BAND_2GHZ;
9428 if (spec->num_channels > 14)
9429 spec->supported_bands |= SUPPORT_BAND_5GHZ;
9432 * Initialize HT information.
9434 if (!rt2x00_rf(rt2x00dev, RF2020))
9435 spec->ht.ht_supported = true;
9436 else
9437 spec->ht.ht_supported = false;
9439 spec->ht.cap =
9440 IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
9441 IEEE80211_HT_CAP_GRN_FLD |
9442 IEEE80211_HT_CAP_SGI_20 |
9443 IEEE80211_HT_CAP_SGI_40;
9445 tx_chains = rt2x00dev->default_ant.tx_chain_num;
9446 rx_chains = rt2x00dev->default_ant.rx_chain_num;
9448 if (tx_chains >= 2)
9449 spec->ht.cap |= IEEE80211_HT_CAP_TX_STBC;
9451 spec->ht.cap |= rx_chains << IEEE80211_HT_CAP_RX_STBC_SHIFT;
9453 spec->ht.ampdu_factor = (rx_chains > 1) ? 3 : 2;
9454 spec->ht.ampdu_density = 4;
9455 spec->ht.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
9456 if (tx_chains != rx_chains) {
9457 spec->ht.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
9458 spec->ht.mcs.tx_params |=
9459 (tx_chains - 1) << IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
9462 switch (rx_chains) {
9463 case 3:
9464 spec->ht.mcs.rx_mask[2] = 0xff;
9465 /* fall through */
9466 case 2:
9467 spec->ht.mcs.rx_mask[1] = 0xff;
9468 /* fall through */
9469 case 1:
9470 spec->ht.mcs.rx_mask[0] = 0xff;
9471 spec->ht.mcs.rx_mask[4] = 0x1; /* MCS32 */
9472 break;
9476 * Create channel information array
9478 info = kcalloc(spec->num_channels, sizeof(*info), GFP_KERNEL);
9479 if (!info)
9480 return -ENOMEM;
9482 spec->channels_info = info;
9484 default_power1 = rt2800_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG1);
9485 default_power2 = rt2800_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG2);
9487 if (rt2x00dev->default_ant.tx_chain_num > 2)
9488 default_power3 = rt2800_eeprom_addr(rt2x00dev,
9489 EEPROM_EXT_TXPOWER_BG3);
9490 else
9491 default_power3 = NULL;
9493 for (i = 0; i < 14; i++) {
9494 info[i].default_power1 = default_power1[i];
9495 info[i].default_power2 = default_power2[i];
9496 if (default_power3)
9497 info[i].default_power3 = default_power3[i];
9500 if (spec->num_channels > 14) {
9501 default_power1 = rt2800_eeprom_addr(rt2x00dev,
9502 EEPROM_TXPOWER_A1);
9503 default_power2 = rt2800_eeprom_addr(rt2x00dev,
9504 EEPROM_TXPOWER_A2);
9506 if (rt2x00dev->default_ant.tx_chain_num > 2)
9507 default_power3 =
9508 rt2800_eeprom_addr(rt2x00dev,
9509 EEPROM_EXT_TXPOWER_A3);
9510 else
9511 default_power3 = NULL;
9513 for (i = 14; i < spec->num_channels; i++) {
9514 info[i].default_power1 = default_power1[i - 14];
9515 info[i].default_power2 = default_power2[i - 14];
9516 if (default_power3)
9517 info[i].default_power3 = default_power3[i - 14];
9521 switch (rt2x00dev->chip.rf) {
9522 case RF2020:
9523 case RF3020:
9524 case RF3021:
9525 case RF3022:
9526 case RF3320:
9527 case RF3052:
9528 case RF3053:
9529 case RF3070:
9530 case RF3290:
9531 case RF5350:
9532 case RF5360:
9533 case RF5362:
9534 case RF5370:
9535 case RF5372:
9536 case RF5390:
9537 case RF5392:
9538 case RF5592:
9539 case RF7620:
9540 __set_bit(CAPABILITY_VCO_RECALIBRATION, &rt2x00dev->cap_flags);
9541 break;
9544 return 0;
9547 static int rt2800_probe_rt(struct rt2x00_dev *rt2x00dev)
9549 u32 reg;
9550 u32 rt;
9551 u32 rev;
9553 if (rt2x00_rt(rt2x00dev, RT3290))
9554 reg = rt2800_register_read(rt2x00dev, MAC_CSR0_3290);
9555 else
9556 reg = rt2800_register_read(rt2x00dev, MAC_CSR0);
9558 rt = rt2x00_get_field32(reg, MAC_CSR0_CHIPSET);
9559 rev = rt2x00_get_field32(reg, MAC_CSR0_REVISION);
9561 switch (rt) {
9562 case RT2860:
9563 case RT2872:
9564 case RT2883:
9565 case RT3070:
9566 case RT3071:
9567 case RT3090:
9568 case RT3290:
9569 case RT3352:
9570 case RT3390:
9571 case RT3572:
9572 case RT3593:
9573 case RT5350:
9574 case RT5390:
9575 case RT5392:
9576 case RT5592:
9577 break;
9578 default:
9579 rt2x00_err(rt2x00dev, "Invalid RT chipset 0x%04x, rev %04x detected\n",
9580 rt, rev);
9581 return -ENODEV;
9584 if (rt == RT5390 && rt2x00_is_soc(rt2x00dev))
9585 rt = RT6352;
9587 rt2x00_set_rt(rt2x00dev, rt, rev);
9589 return 0;
9592 int rt2800_probe_hw(struct rt2x00_dev *rt2x00dev)
9594 int retval;
9595 u32 reg;
9597 retval = rt2800_probe_rt(rt2x00dev);
9598 if (retval)
9599 return retval;
9602 * Allocate eeprom data.
9604 retval = rt2800_validate_eeprom(rt2x00dev);
9605 if (retval)
9606 return retval;
9608 retval = rt2800_init_eeprom(rt2x00dev);
9609 if (retval)
9610 return retval;
9613 * Enable rfkill polling by setting GPIO direction of the
9614 * rfkill switch GPIO pin correctly.
9616 reg = rt2800_register_read(rt2x00dev, GPIO_CTRL);
9617 rt2x00_set_field32(&reg, GPIO_CTRL_DIR2, 1);
9618 rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
9621 * Initialize hw specifications.
9623 retval = rt2800_probe_hw_mode(rt2x00dev);
9624 if (retval)
9625 return retval;
9628 * Set device capabilities.
9630 __set_bit(CAPABILITY_CONTROL_FILTERS, &rt2x00dev->cap_flags);
9631 __set_bit(CAPABILITY_CONTROL_FILTER_PSPOLL, &rt2x00dev->cap_flags);
9632 if (!rt2x00_is_usb(rt2x00dev))
9633 __set_bit(CAPABILITY_PRE_TBTT_INTERRUPT, &rt2x00dev->cap_flags);
9636 * Set device requirements.
9638 if (!rt2x00_is_soc(rt2x00dev))
9639 __set_bit(REQUIRE_FIRMWARE, &rt2x00dev->cap_flags);
9640 __set_bit(REQUIRE_L2PAD, &rt2x00dev->cap_flags);
9641 __set_bit(REQUIRE_TXSTATUS_FIFO, &rt2x00dev->cap_flags);
9642 if (!rt2800_hwcrypt_disabled(rt2x00dev))
9643 __set_bit(CAPABILITY_HW_CRYPTO, &rt2x00dev->cap_flags);
9644 __set_bit(CAPABILITY_LINK_TUNING, &rt2x00dev->cap_flags);
9645 __set_bit(REQUIRE_HT_TX_DESC, &rt2x00dev->cap_flags);
9646 if (rt2x00_is_usb(rt2x00dev))
9647 __set_bit(REQUIRE_PS_AUTOWAKE, &rt2x00dev->cap_flags);
9648 else {
9649 __set_bit(REQUIRE_DMA, &rt2x00dev->cap_flags);
9650 __set_bit(REQUIRE_TASKLET_CONTEXT, &rt2x00dev->cap_flags);
9654 * Set the rssi offset.
9656 rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
9658 return 0;
9660 EXPORT_SYMBOL_GPL(rt2800_probe_hw);
9663 * IEEE80211 stack callback functions.
9665 void rt2800_get_key_seq(struct ieee80211_hw *hw,
9666 struct ieee80211_key_conf *key,
9667 struct ieee80211_key_seq *seq)
9669 struct rt2x00_dev *rt2x00dev = hw->priv;
9670 struct mac_iveiv_entry iveiv_entry;
9671 u32 offset;
9673 if (key->cipher != WLAN_CIPHER_SUITE_TKIP)
9674 return;
9676 offset = MAC_IVEIV_ENTRY(key->hw_key_idx);
9677 rt2800_register_multiread(rt2x00dev, offset,
9678 &iveiv_entry, sizeof(iveiv_entry));
9680 memcpy(&seq->tkip.iv16, &iveiv_entry.iv[0], 2);
9681 memcpy(&seq->tkip.iv32, &iveiv_entry.iv[4], 4);
9683 EXPORT_SYMBOL_GPL(rt2800_get_key_seq);
9685 int rt2800_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
9687 struct rt2x00_dev *rt2x00dev = hw->priv;
9688 u32 reg;
9689 bool enabled = (value < IEEE80211_MAX_RTS_THRESHOLD);
9691 reg = rt2800_register_read(rt2x00dev, TX_RTS_CFG);
9692 rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES, value);
9693 rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg);
9695 reg = rt2800_register_read(rt2x00dev, CCK_PROT_CFG);
9696 rt2x00_set_field32(&reg, CCK_PROT_CFG_RTS_TH_EN, enabled);
9697 rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg);
9699 reg = rt2800_register_read(rt2x00dev, OFDM_PROT_CFG);
9700 rt2x00_set_field32(&reg, OFDM_PROT_CFG_RTS_TH_EN, enabled);
9701 rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
9703 reg = rt2800_register_read(rt2x00dev, MM20_PROT_CFG);
9704 rt2x00_set_field32(&reg, MM20_PROT_CFG_RTS_TH_EN, enabled);
9705 rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
9707 reg = rt2800_register_read(rt2x00dev, MM40_PROT_CFG);
9708 rt2x00_set_field32(&reg, MM40_PROT_CFG_RTS_TH_EN, enabled);
9709 rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
9711 reg = rt2800_register_read(rt2x00dev, GF20_PROT_CFG);
9712 rt2x00_set_field32(&reg, GF20_PROT_CFG_RTS_TH_EN, enabled);
9713 rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
9715 reg = rt2800_register_read(rt2x00dev, GF40_PROT_CFG);
9716 rt2x00_set_field32(&reg, GF40_PROT_CFG_RTS_TH_EN, enabled);
9717 rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
9719 return 0;
9721 EXPORT_SYMBOL_GPL(rt2800_set_rts_threshold);
9723 int rt2800_conf_tx(struct ieee80211_hw *hw,
9724 struct ieee80211_vif *vif, u16 queue_idx,
9725 const struct ieee80211_tx_queue_params *params)
9727 struct rt2x00_dev *rt2x00dev = hw->priv;
9728 struct data_queue *queue;
9729 struct rt2x00_field32 field;
9730 int retval;
9731 u32 reg;
9732 u32 offset;
9735 * First pass the configuration through rt2x00lib, that will
9736 * update the queue settings and validate the input. After that
9737 * we are free to update the registers based on the value
9738 * in the queue parameter.
9740 retval = rt2x00mac_conf_tx(hw, vif, queue_idx, params);
9741 if (retval)
9742 return retval;
9745 * We only need to perform additional register initialization
9746 * for WMM queues/
9748 if (queue_idx >= 4)
9749 return 0;
9751 queue = rt2x00queue_get_tx_queue(rt2x00dev, queue_idx);
9753 /* Update WMM TXOP register */
9754 offset = WMM_TXOP0_CFG + (sizeof(u32) * (!!(queue_idx & 2)));
9755 field.bit_offset = (queue_idx & 1) * 16;
9756 field.bit_mask = 0xffff << field.bit_offset;
9758 reg = rt2800_register_read(rt2x00dev, offset);
9759 rt2x00_set_field32(&reg, field, queue->txop);
9760 rt2800_register_write(rt2x00dev, offset, reg);
9762 /* Update WMM registers */
9763 field.bit_offset = queue_idx * 4;
9764 field.bit_mask = 0xf << field.bit_offset;
9766 reg = rt2800_register_read(rt2x00dev, WMM_AIFSN_CFG);
9767 rt2x00_set_field32(&reg, field, queue->aifs);
9768 rt2800_register_write(rt2x00dev, WMM_AIFSN_CFG, reg);
9770 reg = rt2800_register_read(rt2x00dev, WMM_CWMIN_CFG);
9771 rt2x00_set_field32(&reg, field, queue->cw_min);
9772 rt2800_register_write(rt2x00dev, WMM_CWMIN_CFG, reg);
9774 reg = rt2800_register_read(rt2x00dev, WMM_CWMAX_CFG);
9775 rt2x00_set_field32(&reg, field, queue->cw_max);
9776 rt2800_register_write(rt2x00dev, WMM_CWMAX_CFG, reg);
9778 /* Update EDCA registers */
9779 offset = EDCA_AC0_CFG + (sizeof(u32) * queue_idx);
9781 reg = rt2800_register_read(rt2x00dev, offset);
9782 rt2x00_set_field32(&reg, EDCA_AC0_CFG_TX_OP, queue->txop);
9783 rt2x00_set_field32(&reg, EDCA_AC0_CFG_AIFSN, queue->aifs);
9784 rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMIN, queue->cw_min);
9785 rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMAX, queue->cw_max);
9786 rt2800_register_write(rt2x00dev, offset, reg);
9788 return 0;
9790 EXPORT_SYMBOL_GPL(rt2800_conf_tx);
9792 u64 rt2800_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
9794 struct rt2x00_dev *rt2x00dev = hw->priv;
9795 u64 tsf;
9796 u32 reg;
9798 reg = rt2800_register_read(rt2x00dev, TSF_TIMER_DW1);
9799 tsf = (u64) rt2x00_get_field32(reg, TSF_TIMER_DW1_HIGH_WORD) << 32;
9800 reg = rt2800_register_read(rt2x00dev, TSF_TIMER_DW0);
9801 tsf |= rt2x00_get_field32(reg, TSF_TIMER_DW0_LOW_WORD);
9803 return tsf;
9805 EXPORT_SYMBOL_GPL(rt2800_get_tsf);
9807 int rt2800_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
9808 struct ieee80211_ampdu_params *params)
9810 struct ieee80211_sta *sta = params->sta;
9811 enum ieee80211_ampdu_mlme_action action = params->action;
9812 u16 tid = params->tid;
9813 struct rt2x00_sta *sta_priv = (struct rt2x00_sta *)sta->drv_priv;
9814 int ret = 0;
9817 * Don't allow aggregation for stations the hardware isn't aware
9818 * of because tx status reports for frames to an unknown station
9819 * always contain wcid=WCID_END+1 and thus we can't distinguish
9820 * between multiple stations which leads to unwanted situations
9821 * when the hw reorders frames due to aggregation.
9823 if (sta_priv->wcid > WCID_END)
9824 return 1;
9826 switch (action) {
9827 case IEEE80211_AMPDU_RX_START:
9828 case IEEE80211_AMPDU_RX_STOP:
9830 * The hw itself takes care of setting up BlockAck mechanisms.
9831 * So, we only have to allow mac80211 to nagotiate a BlockAck
9832 * agreement. Once that is done, the hw will BlockAck incoming
9833 * AMPDUs without further setup.
9835 break;
9836 case IEEE80211_AMPDU_TX_START:
9837 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
9838 break;
9839 case IEEE80211_AMPDU_TX_STOP_CONT:
9840 case IEEE80211_AMPDU_TX_STOP_FLUSH:
9841 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
9842 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
9843 break;
9844 case IEEE80211_AMPDU_TX_OPERATIONAL:
9845 break;
9846 default:
9847 rt2x00_warn((struct rt2x00_dev *)hw->priv,
9848 "Unknown AMPDU action\n");
9851 return ret;
9853 EXPORT_SYMBOL_GPL(rt2800_ampdu_action);
9855 int rt2800_get_survey(struct ieee80211_hw *hw, int idx,
9856 struct survey_info *survey)
9858 struct rt2x00_dev *rt2x00dev = hw->priv;
9859 struct ieee80211_conf *conf = &hw->conf;
9860 u32 idle, busy, busy_ext;
9862 if (idx != 0)
9863 return -ENOENT;
9865 survey->channel = conf->chandef.chan;
9867 idle = rt2800_register_read(rt2x00dev, CH_IDLE_STA);
9868 busy = rt2800_register_read(rt2x00dev, CH_BUSY_STA);
9869 busy_ext = rt2800_register_read(rt2x00dev, CH_BUSY_STA_SEC);
9871 if (idle || busy) {
9872 survey->filled = SURVEY_INFO_TIME |
9873 SURVEY_INFO_TIME_BUSY |
9874 SURVEY_INFO_TIME_EXT_BUSY;
9876 survey->time = (idle + busy) / 1000;
9877 survey->time_busy = busy / 1000;
9878 survey->time_ext_busy = busy_ext / 1000;
9881 if (!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL))
9882 survey->filled |= SURVEY_INFO_IN_USE;
9884 return 0;
9887 EXPORT_SYMBOL_GPL(rt2800_get_survey);
9889 MODULE_AUTHOR(DRV_PROJECT ", Bartlomiej Zolnierkiewicz");
9890 MODULE_VERSION(DRV_VERSION);
9891 MODULE_DESCRIPTION("Ralink RT2800 library");
9892 MODULE_LICENSE("GPL");