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, write to the
28 Free Software Foundation, Inc.,
29 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 Abstract: rt2800 generic device routines.
37 #include <linux/crc-ccitt.h>
38 #include <linux/kernel.h>
39 #include <linux/module.h>
40 #include <linux/slab.h>
43 #include "rt2800lib.h"
48 * All access to the CSR registers will go through the methods
49 * rt2800_register_read and rt2800_register_write.
50 * BBP and RF register require indirect register access,
51 * and use the CSR registers BBPCSR and RFCSR to achieve this.
52 * These indirect registers work with busy bits,
53 * and we will try maximal REGISTER_BUSY_COUNT times to access
54 * the register while taking a REGISTER_BUSY_DELAY us delay
55 * between each attampt. When the busy bit is still set at that time,
56 * the access attempt is considered to have failed,
57 * and we will print an error.
58 * The _lock versions must be used if you already hold the csr_mutex
60 #define WAIT_FOR_BBP(__dev, __reg) \
61 rt2800_regbusy_read((__dev), BBP_CSR_CFG, BBP_CSR_CFG_BUSY, (__reg))
62 #define WAIT_FOR_RFCSR(__dev, __reg) \
63 rt2800_regbusy_read((__dev), RF_CSR_CFG, RF_CSR_CFG_BUSY, (__reg))
64 #define WAIT_FOR_RF(__dev, __reg) \
65 rt2800_regbusy_read((__dev), RF_CSR_CFG0, RF_CSR_CFG0_BUSY, (__reg))
66 #define WAIT_FOR_MCU(__dev, __reg) \
67 rt2800_regbusy_read((__dev), H2M_MAILBOX_CSR, \
68 H2M_MAILBOX_CSR_OWNER, (__reg))
70 static inline bool rt2800_is_305x_soc(struct rt2x00_dev *rt2x00dev)
72 /* check for rt2872 on SoC */
73 if (!rt2x00_is_soc(rt2x00dev) ||
74 !rt2x00_rt(rt2x00dev, RT2872))
77 /* we know for sure that these rf chipsets are used on rt305x boards */
78 if (rt2x00_rf(rt2x00dev, RF3020) ||
79 rt2x00_rf(rt2x00dev, RF3021) ||
80 rt2x00_rf(rt2x00dev, RF3022))
83 rt2x00_warn(rt2x00dev, "Unknown RF chipset on rt305x\n");
87 static void rt2800_bbp_write(struct rt2x00_dev *rt2x00dev,
88 const unsigned int word, const u8 value)
92 mutex_lock(&rt2x00dev->csr_mutex);
95 * Wait until the BBP becomes available, afterwards we
96 * can safely write the new data into the register.
98 if (WAIT_FOR_BBP(rt2x00dev, ®)) {
100 rt2x00_set_field32(®, BBP_CSR_CFG_VALUE, value);
101 rt2x00_set_field32(®, BBP_CSR_CFG_REGNUM, word);
102 rt2x00_set_field32(®, BBP_CSR_CFG_BUSY, 1);
103 rt2x00_set_field32(®, BBP_CSR_CFG_READ_CONTROL, 0);
104 rt2x00_set_field32(®, BBP_CSR_CFG_BBP_RW_MODE, 1);
106 rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
109 mutex_unlock(&rt2x00dev->csr_mutex);
112 static void rt2800_bbp_read(struct rt2x00_dev *rt2x00dev,
113 const unsigned int word, u8 *value)
117 mutex_lock(&rt2x00dev->csr_mutex);
120 * Wait until the BBP becomes available, afterwards we
121 * can safely write the read request into the register.
122 * After the data has been written, we wait until hardware
123 * returns the correct value, if at any time the register
124 * doesn't become available in time, reg will be 0xffffffff
125 * which means we return 0xff to the caller.
127 if (WAIT_FOR_BBP(rt2x00dev, ®)) {
129 rt2x00_set_field32(®, BBP_CSR_CFG_REGNUM, word);
130 rt2x00_set_field32(®, BBP_CSR_CFG_BUSY, 1);
131 rt2x00_set_field32(®, BBP_CSR_CFG_READ_CONTROL, 1);
132 rt2x00_set_field32(®, BBP_CSR_CFG_BBP_RW_MODE, 1);
134 rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
136 WAIT_FOR_BBP(rt2x00dev, ®);
139 *value = rt2x00_get_field32(reg, BBP_CSR_CFG_VALUE);
141 mutex_unlock(&rt2x00dev->csr_mutex);
144 static void rt2800_rfcsr_write(struct rt2x00_dev *rt2x00dev,
145 const unsigned int word, const u8 value)
149 mutex_lock(&rt2x00dev->csr_mutex);
152 * Wait until the RFCSR becomes available, afterwards we
153 * can safely write the new data into the register.
155 if (WAIT_FOR_RFCSR(rt2x00dev, ®)) {
157 rt2x00_set_field32(®, RF_CSR_CFG_DATA, value);
158 rt2x00_set_field32(®, RF_CSR_CFG_REGNUM, word);
159 rt2x00_set_field32(®, RF_CSR_CFG_WRITE, 1);
160 rt2x00_set_field32(®, RF_CSR_CFG_BUSY, 1);
162 rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
165 mutex_unlock(&rt2x00dev->csr_mutex);
168 static void rt2800_rfcsr_read(struct rt2x00_dev *rt2x00dev,
169 const unsigned int word, u8 *value)
173 mutex_lock(&rt2x00dev->csr_mutex);
176 * Wait until the RFCSR becomes available, afterwards we
177 * can safely write the read request into the register.
178 * After the data has been written, we wait until hardware
179 * returns the correct value, if at any time the register
180 * doesn't become available in time, reg will be 0xffffffff
181 * which means we return 0xff to the caller.
183 if (WAIT_FOR_RFCSR(rt2x00dev, ®)) {
185 rt2x00_set_field32(®, RF_CSR_CFG_REGNUM, word);
186 rt2x00_set_field32(®, RF_CSR_CFG_WRITE, 0);
187 rt2x00_set_field32(®, RF_CSR_CFG_BUSY, 1);
189 rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
191 WAIT_FOR_RFCSR(rt2x00dev, ®);
194 *value = rt2x00_get_field32(reg, RF_CSR_CFG_DATA);
196 mutex_unlock(&rt2x00dev->csr_mutex);
199 static void rt2800_rf_write(struct rt2x00_dev *rt2x00dev,
200 const unsigned int word, const u32 value)
204 mutex_lock(&rt2x00dev->csr_mutex);
207 * Wait until the RF becomes available, afterwards we
208 * can safely write the new data into the register.
210 if (WAIT_FOR_RF(rt2x00dev, ®)) {
212 rt2x00_set_field32(®, RF_CSR_CFG0_REG_VALUE_BW, value);
213 rt2x00_set_field32(®, RF_CSR_CFG0_STANDBYMODE, 0);
214 rt2x00_set_field32(®, RF_CSR_CFG0_SEL, 0);
215 rt2x00_set_field32(®, RF_CSR_CFG0_BUSY, 1);
217 rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG0, reg);
218 rt2x00_rf_write(rt2x00dev, word, value);
221 mutex_unlock(&rt2x00dev->csr_mutex);
224 static const unsigned int rt2800_eeprom_map[EEPROM_WORD_COUNT] = {
225 [EEPROM_CHIP_ID] = 0x0000,
226 [EEPROM_VERSION] = 0x0001,
227 [EEPROM_MAC_ADDR_0] = 0x0002,
228 [EEPROM_MAC_ADDR_1] = 0x0003,
229 [EEPROM_MAC_ADDR_2] = 0x0004,
230 [EEPROM_NIC_CONF0] = 0x001a,
231 [EEPROM_NIC_CONF1] = 0x001b,
232 [EEPROM_FREQ] = 0x001d,
233 [EEPROM_LED_AG_CONF] = 0x001e,
234 [EEPROM_LED_ACT_CONF] = 0x001f,
235 [EEPROM_LED_POLARITY] = 0x0020,
236 [EEPROM_NIC_CONF2] = 0x0021,
237 [EEPROM_LNA] = 0x0022,
238 [EEPROM_RSSI_BG] = 0x0023,
239 [EEPROM_RSSI_BG2] = 0x0024,
240 [EEPROM_TXMIXER_GAIN_BG] = 0x0024, /* overlaps with RSSI_BG2 */
241 [EEPROM_RSSI_A] = 0x0025,
242 [EEPROM_RSSI_A2] = 0x0026,
243 [EEPROM_TXMIXER_GAIN_A] = 0x0026, /* overlaps with RSSI_A2 */
244 [EEPROM_EIRP_MAX_TX_POWER] = 0x0027,
245 [EEPROM_TXPOWER_DELTA] = 0x0028,
246 [EEPROM_TXPOWER_BG1] = 0x0029,
247 [EEPROM_TXPOWER_BG2] = 0x0030,
248 [EEPROM_TSSI_BOUND_BG1] = 0x0037,
249 [EEPROM_TSSI_BOUND_BG2] = 0x0038,
250 [EEPROM_TSSI_BOUND_BG3] = 0x0039,
251 [EEPROM_TSSI_BOUND_BG4] = 0x003a,
252 [EEPROM_TSSI_BOUND_BG5] = 0x003b,
253 [EEPROM_TXPOWER_A1] = 0x003c,
254 [EEPROM_TXPOWER_A2] = 0x0053,
255 [EEPROM_TSSI_BOUND_A1] = 0x006a,
256 [EEPROM_TSSI_BOUND_A2] = 0x006b,
257 [EEPROM_TSSI_BOUND_A3] = 0x006c,
258 [EEPROM_TSSI_BOUND_A4] = 0x006d,
259 [EEPROM_TSSI_BOUND_A5] = 0x006e,
260 [EEPROM_TXPOWER_BYRATE] = 0x006f,
261 [EEPROM_BBP_START] = 0x0078,
264 static const unsigned int rt2800_eeprom_map_ext[EEPROM_WORD_COUNT] = {
265 [EEPROM_CHIP_ID] = 0x0000,
266 [EEPROM_VERSION] = 0x0001,
267 [EEPROM_MAC_ADDR_0] = 0x0002,
268 [EEPROM_MAC_ADDR_1] = 0x0003,
269 [EEPROM_MAC_ADDR_2] = 0x0004,
270 [EEPROM_NIC_CONF0] = 0x001a,
271 [EEPROM_NIC_CONF1] = 0x001b,
272 [EEPROM_NIC_CONF2] = 0x001c,
273 [EEPROM_EIRP_MAX_TX_POWER] = 0x0020,
274 [EEPROM_FREQ] = 0x0022,
275 [EEPROM_LED_AG_CONF] = 0x0023,
276 [EEPROM_LED_ACT_CONF] = 0x0024,
277 [EEPROM_LED_POLARITY] = 0x0025,
278 [EEPROM_LNA] = 0x0026,
279 [EEPROM_EXT_LNA2] = 0x0027,
280 [EEPROM_RSSI_BG] = 0x0028,
281 [EEPROM_RSSI_BG2] = 0x0029,
282 [EEPROM_RSSI_A] = 0x002a,
283 [EEPROM_RSSI_A2] = 0x002b,
284 [EEPROM_TXPOWER_BG1] = 0x0030,
285 [EEPROM_TXPOWER_BG2] = 0x0037,
286 [EEPROM_EXT_TXPOWER_BG3] = 0x003e,
287 [EEPROM_TSSI_BOUND_BG1] = 0x0045,
288 [EEPROM_TSSI_BOUND_BG2] = 0x0046,
289 [EEPROM_TSSI_BOUND_BG3] = 0x0047,
290 [EEPROM_TSSI_BOUND_BG4] = 0x0048,
291 [EEPROM_TSSI_BOUND_BG5] = 0x0049,
292 [EEPROM_TXPOWER_A1] = 0x004b,
293 [EEPROM_TXPOWER_A2] = 0x0065,
294 [EEPROM_EXT_TXPOWER_A3] = 0x007f,
295 [EEPROM_TSSI_BOUND_A1] = 0x009a,
296 [EEPROM_TSSI_BOUND_A2] = 0x009b,
297 [EEPROM_TSSI_BOUND_A3] = 0x009c,
298 [EEPROM_TSSI_BOUND_A4] = 0x009d,
299 [EEPROM_TSSI_BOUND_A5] = 0x009e,
300 [EEPROM_TXPOWER_BYRATE] = 0x00a0,
303 static unsigned int rt2800_eeprom_word_index(struct rt2x00_dev *rt2x00dev,
304 const enum rt2800_eeprom_word word)
306 const unsigned int *map;
309 if (WARN_ONCE(word >= EEPROM_WORD_COUNT,
310 "%s: invalid EEPROM word %d\n",
311 wiphy_name(rt2x00dev->hw->wiphy), word))
314 if (rt2x00_rt(rt2x00dev, RT3593))
315 map = rt2800_eeprom_map_ext;
317 map = rt2800_eeprom_map;
321 /* Index 0 is valid only for EEPROM_CHIP_ID.
322 * Otherwise it means that the offset of the
323 * given word is not initialized in the map,
324 * or that the field is not usable on the
327 WARN_ONCE(word != EEPROM_CHIP_ID && index == 0,
328 "%s: invalid access of EEPROM word %d\n",
329 wiphy_name(rt2x00dev->hw->wiphy), word);
334 static void *rt2800_eeprom_addr(struct rt2x00_dev *rt2x00dev,
335 const enum rt2800_eeprom_word word)
339 index = rt2800_eeprom_word_index(rt2x00dev, word);
340 return rt2x00_eeprom_addr(rt2x00dev, index);
343 static void rt2800_eeprom_read(struct rt2x00_dev *rt2x00dev,
344 const enum rt2800_eeprom_word word, u16 *data)
348 index = rt2800_eeprom_word_index(rt2x00dev, word);
349 rt2x00_eeprom_read(rt2x00dev, index, data);
352 static void rt2800_eeprom_write(struct rt2x00_dev *rt2x00dev,
353 const enum rt2800_eeprom_word word, u16 data)
357 index = rt2800_eeprom_word_index(rt2x00dev, word);
358 rt2x00_eeprom_write(rt2x00dev, index, data);
361 static void rt2800_eeprom_read_from_array(struct rt2x00_dev *rt2x00dev,
362 const enum rt2800_eeprom_word array,
368 index = rt2800_eeprom_word_index(rt2x00dev, array);
369 rt2x00_eeprom_read(rt2x00dev, index + offset, data);
372 static int rt2800_enable_wlan_rt3290(struct rt2x00_dev *rt2x00dev)
377 rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, ®);
378 if (rt2x00_get_field32(reg, WLAN_EN))
381 rt2x00_set_field32(®, WLAN_GPIO_OUT_OE_BIT_ALL, 0xff);
382 rt2x00_set_field32(®, FRC_WL_ANT_SET, 1);
383 rt2x00_set_field32(®, WLAN_CLK_EN, 0);
384 rt2x00_set_field32(®, WLAN_EN, 1);
385 rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg);
387 udelay(REGISTER_BUSY_DELAY);
392 * Check PLL_LD & XTAL_RDY.
394 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
395 rt2800_register_read(rt2x00dev, CMB_CTRL, ®);
396 if (rt2x00_get_field32(reg, PLL_LD) &&
397 rt2x00_get_field32(reg, XTAL_RDY))
399 udelay(REGISTER_BUSY_DELAY);
402 if (i >= REGISTER_BUSY_COUNT) {
407 rt2800_register_write(rt2x00dev, 0x58, 0x018);
408 udelay(REGISTER_BUSY_DELAY);
409 rt2800_register_write(rt2x00dev, 0x58, 0x418);
410 udelay(REGISTER_BUSY_DELAY);
411 rt2800_register_write(rt2x00dev, 0x58, 0x618);
412 udelay(REGISTER_BUSY_DELAY);
418 rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, ®);
419 rt2x00_set_field32(®, PCIE_APP0_CLK_REQ, 0);
420 rt2x00_set_field32(®, WLAN_CLK_EN, 1);
421 rt2x00_set_field32(®, WLAN_RESET, 1);
422 rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg);
424 rt2x00_set_field32(®, WLAN_RESET, 0);
425 rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg);
427 rt2800_register_write(rt2x00dev, INT_SOURCE_CSR, 0x7fffffff);
428 } while (count != 0);
433 void rt2800_mcu_request(struct rt2x00_dev *rt2x00dev,
434 const u8 command, const u8 token,
435 const u8 arg0, const u8 arg1)
440 * SOC devices don't support MCU requests.
442 if (rt2x00_is_soc(rt2x00dev))
445 mutex_lock(&rt2x00dev->csr_mutex);
448 * Wait until the MCU becomes available, afterwards we
449 * can safely write the new data into the register.
451 if (WAIT_FOR_MCU(rt2x00dev, ®)) {
452 rt2x00_set_field32(®, H2M_MAILBOX_CSR_OWNER, 1);
453 rt2x00_set_field32(®, H2M_MAILBOX_CSR_CMD_TOKEN, token);
454 rt2x00_set_field32(®, H2M_MAILBOX_CSR_ARG0, arg0);
455 rt2x00_set_field32(®, H2M_MAILBOX_CSR_ARG1, arg1);
456 rt2800_register_write_lock(rt2x00dev, H2M_MAILBOX_CSR, reg);
459 rt2x00_set_field32(®, HOST_CMD_CSR_HOST_COMMAND, command);
460 rt2800_register_write_lock(rt2x00dev, HOST_CMD_CSR, reg);
463 mutex_unlock(&rt2x00dev->csr_mutex);
465 EXPORT_SYMBOL_GPL(rt2800_mcu_request);
467 int rt2800_wait_csr_ready(struct rt2x00_dev *rt2x00dev)
472 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
473 rt2800_register_read(rt2x00dev, MAC_CSR0, ®);
474 if (reg && reg != ~0)
479 rt2x00_err(rt2x00dev, "Unstable hardware\n");
482 EXPORT_SYMBOL_GPL(rt2800_wait_csr_ready);
484 int rt2800_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev)
490 * Some devices are really slow to respond here. Wait a whole second
493 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
494 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®);
495 if (!rt2x00_get_field32(reg, WPDMA_GLO_CFG_TX_DMA_BUSY) &&
496 !rt2x00_get_field32(reg, WPDMA_GLO_CFG_RX_DMA_BUSY))
502 rt2x00_err(rt2x00dev, "WPDMA TX/RX busy [0x%08x]\n", reg);
505 EXPORT_SYMBOL_GPL(rt2800_wait_wpdma_ready);
507 void rt2800_disable_wpdma(struct rt2x00_dev *rt2x00dev)
511 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®);
512 rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
513 rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
514 rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
515 rt2x00_set_field32(®, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
516 rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
517 rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
519 EXPORT_SYMBOL_GPL(rt2800_disable_wpdma);
521 void rt2800_get_txwi_rxwi_size(struct rt2x00_dev *rt2x00dev,
522 unsigned short *txwi_size,
523 unsigned short *rxwi_size)
525 switch (rt2x00dev->chip.rt) {
527 *txwi_size = TXWI_DESC_SIZE_4WORDS;
528 *rxwi_size = RXWI_DESC_SIZE_5WORDS;
532 *txwi_size = TXWI_DESC_SIZE_5WORDS;
533 *rxwi_size = RXWI_DESC_SIZE_6WORDS;
537 *txwi_size = TXWI_DESC_SIZE_4WORDS;
538 *rxwi_size = RXWI_DESC_SIZE_4WORDS;
542 EXPORT_SYMBOL_GPL(rt2800_get_txwi_rxwi_size);
544 static bool rt2800_check_firmware_crc(const u8 *data, const size_t len)
550 * The last 2 bytes in the firmware array are the crc checksum itself,
551 * this means that we should never pass those 2 bytes to the crc
554 fw_crc = (data[len - 2] << 8 | data[len - 1]);
557 * Use the crc ccitt algorithm.
558 * This will return the same value as the legacy driver which
559 * used bit ordering reversion on the both the firmware bytes
560 * before input input as well as on the final output.
561 * Obviously using crc ccitt directly is much more efficient.
563 crc = crc_ccitt(~0, data, len - 2);
566 * There is a small difference between the crc-itu-t + bitrev and
567 * the crc-ccitt crc calculation. In the latter method the 2 bytes
568 * will be swapped, use swab16 to convert the crc to the correct
573 return fw_crc == crc;
576 int rt2800_check_firmware(struct rt2x00_dev *rt2x00dev,
577 const u8 *data, const size_t len)
584 * PCI(e) & SOC devices require firmware with a length
585 * of 8kb. USB devices require firmware files with a length
586 * of 4kb. Certain USB chipsets however require different firmware,
587 * which Ralink only provides attached to the original firmware
588 * file. Thus for USB devices, firmware files have a length
589 * which is a multiple of 4kb. The firmware for rt3290 chip also
590 * have a length which is a multiple of 4kb.
592 if (rt2x00_is_usb(rt2x00dev) || rt2x00_rt(rt2x00dev, RT3290))
599 * Validate the firmware length
601 if (len != fw_len && (!multiple || (len % fw_len) != 0))
602 return FW_BAD_LENGTH;
605 * Check if the chipset requires one of the upper parts
608 if (rt2x00_is_usb(rt2x00dev) &&
609 !rt2x00_rt(rt2x00dev, RT2860) &&
610 !rt2x00_rt(rt2x00dev, RT2872) &&
611 !rt2x00_rt(rt2x00dev, RT3070) &&
612 ((len / fw_len) == 1))
613 return FW_BAD_VERSION;
616 * 8kb firmware files must be checked as if it were
617 * 2 separate firmware files.
619 while (offset < len) {
620 if (!rt2800_check_firmware_crc(data + offset, fw_len))
628 EXPORT_SYMBOL_GPL(rt2800_check_firmware);
630 int rt2800_load_firmware(struct rt2x00_dev *rt2x00dev,
631 const u8 *data, const size_t len)
637 if (rt2x00_rt(rt2x00dev, RT3290)) {
638 retval = rt2800_enable_wlan_rt3290(rt2x00dev);
644 * If driver doesn't wake up firmware here,
645 * rt2800_load_firmware will hang forever when interface is up again.
647 rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0x00000000);
650 * Wait for stable hardware.
652 if (rt2800_wait_csr_ready(rt2x00dev))
655 if (rt2x00_is_pci(rt2x00dev)) {
656 if (rt2x00_rt(rt2x00dev, RT3290) ||
657 rt2x00_rt(rt2x00dev, RT3572) ||
658 rt2x00_rt(rt2x00dev, RT5390) ||
659 rt2x00_rt(rt2x00dev, RT5392)) {
660 rt2800_register_read(rt2x00dev, AUX_CTRL, ®);
661 rt2x00_set_field32(®, AUX_CTRL_FORCE_PCIE_CLK, 1);
662 rt2x00_set_field32(®, AUX_CTRL_WAKE_PCIE_EN, 1);
663 rt2800_register_write(rt2x00dev, AUX_CTRL, reg);
665 rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000002);
668 rt2800_disable_wpdma(rt2x00dev);
671 * Write firmware to the device.
673 rt2800_drv_write_firmware(rt2x00dev, data, len);
676 * Wait for device to stabilize.
678 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
679 rt2800_register_read(rt2x00dev, PBF_SYS_CTRL, ®);
680 if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY))
685 if (i == REGISTER_BUSY_COUNT) {
686 rt2x00_err(rt2x00dev, "PBF system register not ready\n");
691 * Disable DMA, will be reenabled later when enabling
694 rt2800_disable_wpdma(rt2x00dev);
697 * Initialize firmware.
699 rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
700 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
701 if (rt2x00_is_usb(rt2x00dev)) {
702 rt2800_register_write(rt2x00dev, H2M_INT_SRC, 0);
703 rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0, 0, 0);
709 EXPORT_SYMBOL_GPL(rt2800_load_firmware);
711 void rt2800_write_tx_data(struct queue_entry *entry,
712 struct txentry_desc *txdesc)
714 __le32 *txwi = rt2800_drv_get_txwi(entry);
719 * Initialize TX Info descriptor
721 rt2x00_desc_read(txwi, 0, &word);
722 rt2x00_set_field32(&word, TXWI_W0_FRAG,
723 test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
724 rt2x00_set_field32(&word, TXWI_W0_MIMO_PS,
725 test_bit(ENTRY_TXD_HT_MIMO_PS, &txdesc->flags));
726 rt2x00_set_field32(&word, TXWI_W0_CF_ACK, 0);
727 rt2x00_set_field32(&word, TXWI_W0_TS,
728 test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
729 rt2x00_set_field32(&word, TXWI_W0_AMPDU,
730 test_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags));
731 rt2x00_set_field32(&word, TXWI_W0_MPDU_DENSITY,
732 txdesc->u.ht.mpdu_density);
733 rt2x00_set_field32(&word, TXWI_W0_TX_OP, txdesc->u.ht.txop);
734 rt2x00_set_field32(&word, TXWI_W0_MCS, txdesc->u.ht.mcs);
735 rt2x00_set_field32(&word, TXWI_W0_BW,
736 test_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags));
737 rt2x00_set_field32(&word, TXWI_W0_SHORT_GI,
738 test_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags));
739 rt2x00_set_field32(&word, TXWI_W0_STBC, txdesc->u.ht.stbc);
740 rt2x00_set_field32(&word, TXWI_W0_PHYMODE, txdesc->rate_mode);
741 rt2x00_desc_write(txwi, 0, word);
743 rt2x00_desc_read(txwi, 1, &word);
744 rt2x00_set_field32(&word, TXWI_W1_ACK,
745 test_bit(ENTRY_TXD_ACK, &txdesc->flags));
746 rt2x00_set_field32(&word, TXWI_W1_NSEQ,
747 test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags));
748 rt2x00_set_field32(&word, TXWI_W1_BW_WIN_SIZE, txdesc->u.ht.ba_size);
749 rt2x00_set_field32(&word, TXWI_W1_WIRELESS_CLI_ID,
750 test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags) ?
751 txdesc->key_idx : txdesc->u.ht.wcid);
752 rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT,
754 rt2x00_set_field32(&word, TXWI_W1_PACKETID_QUEUE, entry->queue->qid);
755 rt2x00_set_field32(&word, TXWI_W1_PACKETID_ENTRY, (entry->entry_idx % 3) + 1);
756 rt2x00_desc_write(txwi, 1, word);
759 * Always write 0 to IV/EIV fields (word 2 and 3), hardware will insert
760 * the IV from the IVEIV register when TXD_W3_WIV is set to 0.
761 * When TXD_W3_WIV is set to 1 it will use the IV data
762 * from the descriptor. The TXWI_W1_WIRELESS_CLI_ID indicates which
763 * crypto entry in the registers should be used to encrypt the frame.
765 * Nulify all remaining words as well, we don't know how to program them.
767 for (i = 2; i < entry->queue->winfo_size / sizeof(__le32); i++)
768 _rt2x00_desc_write(txwi, i, 0);
770 EXPORT_SYMBOL_GPL(rt2800_write_tx_data);
772 static int rt2800_agc_to_rssi(struct rt2x00_dev *rt2x00dev, u32 rxwi_w2)
774 s8 rssi0 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI0);
775 s8 rssi1 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI1);
776 s8 rssi2 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI2);
782 if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) {
783 rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &eeprom);
784 offset0 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG_OFFSET0);
785 offset1 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG_OFFSET1);
786 rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom);
787 offset2 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG2_OFFSET2);
789 rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &eeprom);
790 offset0 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A_OFFSET0);
791 offset1 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A_OFFSET1);
792 rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom);
793 offset2 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A2_OFFSET2);
797 * Convert the value from the descriptor into the RSSI value
798 * If the value in the descriptor is 0, it is considered invalid
799 * and the default (extremely low) rssi value is assumed
801 rssi0 = (rssi0) ? (-12 - offset0 - rt2x00dev->lna_gain - rssi0) : -128;
802 rssi1 = (rssi1) ? (-12 - offset1 - rt2x00dev->lna_gain - rssi1) : -128;
803 rssi2 = (rssi2) ? (-12 - offset2 - rt2x00dev->lna_gain - rssi2) : -128;
806 * mac80211 only accepts a single RSSI value. Calculating the
807 * average doesn't deliver a fair answer either since -60:-60 would
808 * be considered equally good as -50:-70 while the second is the one
809 * which gives less energy...
811 rssi0 = max(rssi0, rssi1);
812 return (int)max(rssi0, rssi2);
815 void rt2800_process_rxwi(struct queue_entry *entry,
816 struct rxdone_entry_desc *rxdesc)
818 __le32 *rxwi = (__le32 *) entry->skb->data;
821 rt2x00_desc_read(rxwi, 0, &word);
823 rxdesc->cipher = rt2x00_get_field32(word, RXWI_W0_UDF);
824 rxdesc->size = rt2x00_get_field32(word, RXWI_W0_MPDU_TOTAL_BYTE_COUNT);
826 rt2x00_desc_read(rxwi, 1, &word);
828 if (rt2x00_get_field32(word, RXWI_W1_SHORT_GI))
829 rxdesc->flags |= RX_FLAG_SHORT_GI;
831 if (rt2x00_get_field32(word, RXWI_W1_BW))
832 rxdesc->flags |= RX_FLAG_40MHZ;
835 * Detect RX rate, always use MCS as signal type.
837 rxdesc->dev_flags |= RXDONE_SIGNAL_MCS;
838 rxdesc->signal = rt2x00_get_field32(word, RXWI_W1_MCS);
839 rxdesc->rate_mode = rt2x00_get_field32(word, RXWI_W1_PHYMODE);
842 * Mask of 0x8 bit to remove the short preamble flag.
844 if (rxdesc->rate_mode == RATE_MODE_CCK)
845 rxdesc->signal &= ~0x8;
847 rt2x00_desc_read(rxwi, 2, &word);
850 * Convert descriptor AGC value to RSSI value.
852 rxdesc->rssi = rt2800_agc_to_rssi(entry->queue->rt2x00dev, word);
854 * Remove RXWI descriptor from start of the buffer.
856 skb_pull(entry->skb, entry->queue->winfo_size);
858 EXPORT_SYMBOL_GPL(rt2800_process_rxwi);
860 void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi)
862 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
863 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
864 struct txdone_entry_desc txdesc;
870 * Obtain the status about this packet.
873 rt2x00_desc_read(txwi, 0, &word);
875 mcs = rt2x00_get_field32(word, TXWI_W0_MCS);
876 ampdu = rt2x00_get_field32(word, TXWI_W0_AMPDU);
878 real_mcs = rt2x00_get_field32(status, TX_STA_FIFO_MCS);
879 aggr = rt2x00_get_field32(status, TX_STA_FIFO_TX_AGGRE);
882 * If a frame was meant to be sent as a single non-aggregated MPDU
883 * but ended up in an aggregate the used tx rate doesn't correlate
884 * with the one specified in the TXWI as the whole aggregate is sent
885 * with the same rate.
887 * For example: two frames are sent to rt2x00, the first one sets
888 * AMPDU=1 and requests MCS7 whereas the second frame sets AMDPU=0
889 * and requests MCS15. If the hw aggregates both frames into one
890 * AMDPU the tx status for both frames will contain MCS7 although
891 * the frame was sent successfully.
893 * Hence, replace the requested rate with the real tx rate to not
894 * confuse the rate control algortihm by providing clearly wrong
897 if (unlikely(aggr == 1 && ampdu == 0 && real_mcs != mcs)) {
898 skbdesc->tx_rate_idx = real_mcs;
902 if (aggr == 1 || ampdu == 1)
903 __set_bit(TXDONE_AMPDU, &txdesc.flags);
906 * Ralink has a retry mechanism using a global fallback
907 * table. We setup this fallback table to try the immediate
908 * lower rate for all rates. In the TX_STA_FIFO, the MCS field
909 * always contains the MCS used for the last transmission, be
910 * it successful or not.
912 if (rt2x00_get_field32(status, TX_STA_FIFO_TX_SUCCESS)) {
914 * Transmission succeeded. The number of retries is
917 __set_bit(TXDONE_SUCCESS, &txdesc.flags);
918 txdesc.retry = ((mcs > real_mcs) ? mcs - real_mcs : 0);
921 * Transmission failed. The number of retries is
922 * always 7 in this case (for a total number of 8
925 __set_bit(TXDONE_FAILURE, &txdesc.flags);
926 txdesc.retry = rt2x00dev->long_retry;
930 * the frame was retried at least once
931 * -> hw used fallback rates
934 __set_bit(TXDONE_FALLBACK, &txdesc.flags);
936 rt2x00lib_txdone(entry, &txdesc);
938 EXPORT_SYMBOL_GPL(rt2800_txdone_entry);
940 static unsigned int rt2800_hw_beacon_base(struct rt2x00_dev *rt2x00dev,
943 return HW_BEACON_BASE(index);
946 static inline u8 rt2800_get_beacon_offset(struct rt2x00_dev *rt2x00dev,
949 return BEACON_BASE_TO_OFFSET(rt2800_hw_beacon_base(rt2x00dev, index));
952 void rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc)
954 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
955 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
956 unsigned int beacon_base;
957 unsigned int padding_len;
959 const int txwi_desc_size = entry->queue->winfo_size;
962 * Disable beaconing while we are reloading the beacon data,
963 * otherwise we might be sending out invalid data.
965 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®);
967 rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 0);
968 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
971 * Add space for the TXWI in front of the skb.
973 memset(skb_push(entry->skb, txwi_desc_size), 0, txwi_desc_size);
976 * Register descriptor details in skb frame descriptor.
978 skbdesc->flags |= SKBDESC_DESC_IN_SKB;
979 skbdesc->desc = entry->skb->data;
980 skbdesc->desc_len = txwi_desc_size;
983 * Add the TXWI for the beacon to the skb.
985 rt2800_write_tx_data(entry, txdesc);
988 * Dump beacon to userspace through debugfs.
990 rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry->skb);
993 * Write entire beacon with TXWI and padding to register.
995 padding_len = roundup(entry->skb->len, 4) - entry->skb->len;
996 if (padding_len && skb_pad(entry->skb, padding_len)) {
997 rt2x00_err(rt2x00dev, "Failure padding beacon, aborting\n");
998 /* skb freed by skb_pad() on failure */
1000 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, orig_reg);
1004 beacon_base = rt2800_hw_beacon_base(rt2x00dev, entry->entry_idx);
1006 rt2800_register_multiwrite(rt2x00dev, beacon_base, entry->skb->data,
1007 entry->skb->len + padding_len);
1010 * Enable beaconing again.
1012 rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 1);
1013 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
1016 * Clean up beacon skb.
1018 dev_kfree_skb_any(entry->skb);
1021 EXPORT_SYMBOL_GPL(rt2800_write_beacon);
1023 static inline void rt2800_clear_beacon_register(struct rt2x00_dev *rt2x00dev,
1027 const int txwi_desc_size = rt2x00dev->bcn->winfo_size;
1028 unsigned int beacon_base;
1030 beacon_base = rt2800_hw_beacon_base(rt2x00dev, index);
1033 * For the Beacon base registers we only need to clear
1034 * the whole TXWI which (when set to 0) will invalidate
1035 * the entire beacon.
1037 for (i = 0; i < txwi_desc_size; i += sizeof(__le32))
1038 rt2800_register_write(rt2x00dev, beacon_base + i, 0);
1041 void rt2800_clear_beacon(struct queue_entry *entry)
1043 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
1047 * Disable beaconing while we are reloading the beacon data,
1048 * otherwise we might be sending out invalid data.
1050 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®);
1051 rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 0);
1052 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
1057 rt2800_clear_beacon_register(rt2x00dev, entry->entry_idx);
1060 * Enabled beaconing again.
1062 rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 1);
1063 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
1065 EXPORT_SYMBOL_GPL(rt2800_clear_beacon);
1067 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
1068 const struct rt2x00debug rt2800_rt2x00debug = {
1069 .owner = THIS_MODULE,
1071 .read = rt2800_register_read,
1072 .write = rt2800_register_write,
1073 .flags = RT2X00DEBUGFS_OFFSET,
1074 .word_base = CSR_REG_BASE,
1075 .word_size = sizeof(u32),
1076 .word_count = CSR_REG_SIZE / sizeof(u32),
1079 /* NOTE: The local EEPROM access functions can't
1080 * be used here, use the generic versions instead.
1082 .read = rt2x00_eeprom_read,
1083 .write = rt2x00_eeprom_write,
1084 .word_base = EEPROM_BASE,
1085 .word_size = sizeof(u16),
1086 .word_count = EEPROM_SIZE / sizeof(u16),
1089 .read = rt2800_bbp_read,
1090 .write = rt2800_bbp_write,
1091 .word_base = BBP_BASE,
1092 .word_size = sizeof(u8),
1093 .word_count = BBP_SIZE / sizeof(u8),
1096 .read = rt2x00_rf_read,
1097 .write = rt2800_rf_write,
1098 .word_base = RF_BASE,
1099 .word_size = sizeof(u32),
1100 .word_count = RF_SIZE / sizeof(u32),
1103 .read = rt2800_rfcsr_read,
1104 .write = rt2800_rfcsr_write,
1105 .word_base = RFCSR_BASE,
1106 .word_size = sizeof(u8),
1107 .word_count = RFCSR_SIZE / sizeof(u8),
1110 EXPORT_SYMBOL_GPL(rt2800_rt2x00debug);
1111 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
1113 int rt2800_rfkill_poll(struct rt2x00_dev *rt2x00dev)
1117 if (rt2x00_rt(rt2x00dev, RT3290)) {
1118 rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, ®);
1119 return rt2x00_get_field32(reg, WLAN_GPIO_IN_BIT0);
1121 rt2800_register_read(rt2x00dev, GPIO_CTRL, ®);
1122 return rt2x00_get_field32(reg, GPIO_CTRL_VAL2);
1125 EXPORT_SYMBOL_GPL(rt2800_rfkill_poll);
1127 #ifdef CONFIG_RT2X00_LIB_LEDS
1128 static void rt2800_brightness_set(struct led_classdev *led_cdev,
1129 enum led_brightness brightness)
1131 struct rt2x00_led *led =
1132 container_of(led_cdev, struct rt2x00_led, led_dev);
1133 unsigned int enabled = brightness != LED_OFF;
1134 unsigned int bg_mode =
1135 (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_2GHZ);
1136 unsigned int polarity =
1137 rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
1138 EEPROM_FREQ_LED_POLARITY);
1139 unsigned int ledmode =
1140 rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
1141 EEPROM_FREQ_LED_MODE);
1144 /* Check for SoC (SOC devices don't support MCU requests) */
1145 if (rt2x00_is_soc(led->rt2x00dev)) {
1146 rt2800_register_read(led->rt2x00dev, LED_CFG, ®);
1148 /* Set LED Polarity */
1149 rt2x00_set_field32(®, LED_CFG_LED_POLAR, polarity);
1152 if (led->type == LED_TYPE_RADIO) {
1153 rt2x00_set_field32(®, LED_CFG_G_LED_MODE,
1155 } else if (led->type == LED_TYPE_ASSOC) {
1156 rt2x00_set_field32(®, LED_CFG_Y_LED_MODE,
1158 } else if (led->type == LED_TYPE_QUALITY) {
1159 rt2x00_set_field32(®, LED_CFG_R_LED_MODE,
1163 rt2800_register_write(led->rt2x00dev, LED_CFG, reg);
1166 if (led->type == LED_TYPE_RADIO) {
1167 rt2800_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
1168 enabled ? 0x20 : 0);
1169 } else if (led->type == LED_TYPE_ASSOC) {
1170 rt2800_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
1171 enabled ? (bg_mode ? 0x60 : 0xa0) : 0x20);
1172 } else if (led->type == LED_TYPE_QUALITY) {
1174 * The brightness is divided into 6 levels (0 - 5),
1175 * The specs tell us the following levels:
1176 * 0, 1 ,3, 7, 15, 31
1177 * to determine the level in a simple way we can simply
1178 * work with bitshifting:
1181 rt2800_mcu_request(led->rt2x00dev, MCU_LED_STRENGTH, 0xff,
1182 (1 << brightness / (LED_FULL / 6)) - 1,
1188 static void rt2800_init_led(struct rt2x00_dev *rt2x00dev,
1189 struct rt2x00_led *led, enum led_type type)
1191 led->rt2x00dev = rt2x00dev;
1193 led->led_dev.brightness_set = rt2800_brightness_set;
1194 led->flags = LED_INITIALIZED;
1196 #endif /* CONFIG_RT2X00_LIB_LEDS */
1199 * Configuration handlers.
1201 static void rt2800_config_wcid(struct rt2x00_dev *rt2x00dev,
1205 struct mac_wcid_entry wcid_entry;
1208 offset = MAC_WCID_ENTRY(wcid);
1210 memset(&wcid_entry, 0xff, sizeof(wcid_entry));
1212 memcpy(wcid_entry.mac, address, ETH_ALEN);
1214 rt2800_register_multiwrite(rt2x00dev, offset,
1215 &wcid_entry, sizeof(wcid_entry));
1218 static void rt2800_delete_wcid_attr(struct rt2x00_dev *rt2x00dev, int wcid)
1221 offset = MAC_WCID_ATTR_ENTRY(wcid);
1222 rt2800_register_write(rt2x00dev, offset, 0);
1225 static void rt2800_config_wcid_attr_bssidx(struct rt2x00_dev *rt2x00dev,
1226 int wcid, u32 bssidx)
1228 u32 offset = MAC_WCID_ATTR_ENTRY(wcid);
1232 * The BSS Idx numbers is split in a main value of 3 bits,
1233 * and a extended field for adding one additional bit to the value.
1235 rt2800_register_read(rt2x00dev, offset, ®);
1236 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_BSS_IDX, (bssidx & 0x7));
1237 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_BSS_IDX_EXT,
1238 (bssidx & 0x8) >> 3);
1239 rt2800_register_write(rt2x00dev, offset, reg);
1242 static void rt2800_config_wcid_attr_cipher(struct rt2x00_dev *rt2x00dev,
1243 struct rt2x00lib_crypto *crypto,
1244 struct ieee80211_key_conf *key)
1246 struct mac_iveiv_entry iveiv_entry;
1250 offset = MAC_WCID_ATTR_ENTRY(key->hw_key_idx);
1252 if (crypto->cmd == SET_KEY) {
1253 rt2800_register_read(rt2x00dev, offset, ®);
1254 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_KEYTAB,
1255 !!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE));
1257 * Both the cipher as the BSS Idx numbers are split in a main
1258 * value of 3 bits, and a extended field for adding one additional
1261 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_CIPHER,
1262 (crypto->cipher & 0x7));
1263 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_CIPHER_EXT,
1264 (crypto->cipher & 0x8) >> 3);
1265 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_RX_WIUDF, crypto->cipher);
1266 rt2800_register_write(rt2x00dev, offset, reg);
1268 /* Delete the cipher without touching the bssidx */
1269 rt2800_register_read(rt2x00dev, offset, ®);
1270 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_KEYTAB, 0);
1271 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_CIPHER, 0);
1272 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_CIPHER_EXT, 0);
1273 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_RX_WIUDF, 0);
1274 rt2800_register_write(rt2x00dev, offset, reg);
1277 offset = MAC_IVEIV_ENTRY(key->hw_key_idx);
1279 memset(&iveiv_entry, 0, sizeof(iveiv_entry));
1280 if ((crypto->cipher == CIPHER_TKIP) ||
1281 (crypto->cipher == CIPHER_TKIP_NO_MIC) ||
1282 (crypto->cipher == CIPHER_AES))
1283 iveiv_entry.iv[3] |= 0x20;
1284 iveiv_entry.iv[3] |= key->keyidx << 6;
1285 rt2800_register_multiwrite(rt2x00dev, offset,
1286 &iveiv_entry, sizeof(iveiv_entry));
1289 int rt2800_config_shared_key(struct rt2x00_dev *rt2x00dev,
1290 struct rt2x00lib_crypto *crypto,
1291 struct ieee80211_key_conf *key)
1293 struct hw_key_entry key_entry;
1294 struct rt2x00_field32 field;
1298 if (crypto->cmd == SET_KEY) {
1299 key->hw_key_idx = (4 * crypto->bssidx) + key->keyidx;
1301 memcpy(key_entry.key, crypto->key,
1302 sizeof(key_entry.key));
1303 memcpy(key_entry.tx_mic, crypto->tx_mic,
1304 sizeof(key_entry.tx_mic));
1305 memcpy(key_entry.rx_mic, crypto->rx_mic,
1306 sizeof(key_entry.rx_mic));
1308 offset = SHARED_KEY_ENTRY(key->hw_key_idx);
1309 rt2800_register_multiwrite(rt2x00dev, offset,
1310 &key_entry, sizeof(key_entry));
1314 * The cipher types are stored over multiple registers
1315 * starting with SHARED_KEY_MODE_BASE each word will have
1316 * 32 bits and contains the cipher types for 2 bssidx each.
1317 * Using the correct defines correctly will cause overhead,
1318 * so just calculate the correct offset.
1320 field.bit_offset = 4 * (key->hw_key_idx % 8);
1321 field.bit_mask = 0x7 << field.bit_offset;
1323 offset = SHARED_KEY_MODE_ENTRY(key->hw_key_idx / 8);
1325 rt2800_register_read(rt2x00dev, offset, ®);
1326 rt2x00_set_field32(®, field,
1327 (crypto->cmd == SET_KEY) * crypto->cipher);
1328 rt2800_register_write(rt2x00dev, offset, reg);
1331 * Update WCID information
1333 rt2800_config_wcid(rt2x00dev, crypto->address, key->hw_key_idx);
1334 rt2800_config_wcid_attr_bssidx(rt2x00dev, key->hw_key_idx,
1336 rt2800_config_wcid_attr_cipher(rt2x00dev, crypto, key);
1340 EXPORT_SYMBOL_GPL(rt2800_config_shared_key);
1342 static inline int rt2800_find_wcid(struct rt2x00_dev *rt2x00dev)
1344 struct mac_wcid_entry wcid_entry;
1349 * Search for the first free WCID entry and return the corresponding
1352 * Make sure the WCID starts _after_ the last possible shared key
1355 * Since parts of the pairwise key table might be shared with
1356 * the beacon frame buffers 6 & 7 we should only write into the
1357 * first 222 entries.
1359 for (idx = 33; idx <= 222; idx++) {
1360 offset = MAC_WCID_ENTRY(idx);
1361 rt2800_register_multiread(rt2x00dev, offset, &wcid_entry,
1362 sizeof(wcid_entry));
1363 if (is_broadcast_ether_addr(wcid_entry.mac))
1368 * Use -1 to indicate that we don't have any more space in the WCID
1374 int rt2800_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
1375 struct rt2x00lib_crypto *crypto,
1376 struct ieee80211_key_conf *key)
1378 struct hw_key_entry key_entry;
1381 if (crypto->cmd == SET_KEY) {
1383 * Allow key configuration only for STAs that are
1386 if (crypto->wcid < 0)
1388 key->hw_key_idx = crypto->wcid;
1390 memcpy(key_entry.key, crypto->key,
1391 sizeof(key_entry.key));
1392 memcpy(key_entry.tx_mic, crypto->tx_mic,
1393 sizeof(key_entry.tx_mic));
1394 memcpy(key_entry.rx_mic, crypto->rx_mic,
1395 sizeof(key_entry.rx_mic));
1397 offset = PAIRWISE_KEY_ENTRY(key->hw_key_idx);
1398 rt2800_register_multiwrite(rt2x00dev, offset,
1399 &key_entry, sizeof(key_entry));
1403 * Update WCID information
1405 rt2800_config_wcid_attr_cipher(rt2x00dev, crypto, key);
1409 EXPORT_SYMBOL_GPL(rt2800_config_pairwise_key);
1411 int rt2800_sta_add(struct rt2x00_dev *rt2x00dev, struct ieee80211_vif *vif,
1412 struct ieee80211_sta *sta)
1415 struct rt2x00_sta *sta_priv = sta_to_rt2x00_sta(sta);
1418 * Find next free WCID.
1420 wcid = rt2800_find_wcid(rt2x00dev);
1423 * Store selected wcid even if it is invalid so that we can
1424 * later decide if the STA is uploaded into the hw.
1426 sta_priv->wcid = wcid;
1429 * No space left in the device, however, we can still communicate
1430 * with the STA -> No error.
1436 * Clean up WCID attributes and write STA address to the device.
1438 rt2800_delete_wcid_attr(rt2x00dev, wcid);
1439 rt2800_config_wcid(rt2x00dev, sta->addr, wcid);
1440 rt2800_config_wcid_attr_bssidx(rt2x00dev, wcid,
1441 rt2x00lib_get_bssidx(rt2x00dev, vif));
1444 EXPORT_SYMBOL_GPL(rt2800_sta_add);
1446 int rt2800_sta_remove(struct rt2x00_dev *rt2x00dev, int wcid)
1449 * Remove WCID entry, no need to clean the attributes as they will
1450 * get renewed when the WCID is reused.
1452 rt2800_config_wcid(rt2x00dev, NULL, wcid);
1456 EXPORT_SYMBOL_GPL(rt2800_sta_remove);
1458 void rt2800_config_filter(struct rt2x00_dev *rt2x00dev,
1459 const unsigned int filter_flags)
1464 * Start configuration steps.
1465 * Note that the version error will always be dropped
1466 * and broadcast frames will always be accepted since
1467 * there is no filter for it at this time.
1469 rt2800_register_read(rt2x00dev, RX_FILTER_CFG, ®);
1470 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CRC_ERROR,
1471 !(filter_flags & FIF_FCSFAIL));
1472 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_PHY_ERROR,
1473 !(filter_flags & FIF_PLCPFAIL));
1474 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_NOT_TO_ME,
1475 !(filter_flags & FIF_PROMISC_IN_BSS));
1476 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_NOT_MY_BSSD, 0);
1477 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_VER_ERROR, 1);
1478 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_MULTICAST,
1479 !(filter_flags & FIF_ALLMULTI));
1480 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_BROADCAST, 0);
1481 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_DUPLICATE, 1);
1482 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CF_END_ACK,
1483 !(filter_flags & FIF_CONTROL));
1484 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CF_END,
1485 !(filter_flags & FIF_CONTROL));
1486 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_ACK,
1487 !(filter_flags & FIF_CONTROL));
1488 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CTS,
1489 !(filter_flags & FIF_CONTROL));
1490 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_RTS,
1491 !(filter_flags & FIF_CONTROL));
1492 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_PSPOLL,
1493 !(filter_flags & FIF_PSPOLL));
1494 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_BA, 0);
1495 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_BAR,
1496 !(filter_flags & FIF_CONTROL));
1497 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CNTL,
1498 !(filter_flags & FIF_CONTROL));
1499 rt2800_register_write(rt2x00dev, RX_FILTER_CFG, reg);
1501 EXPORT_SYMBOL_GPL(rt2800_config_filter);
1503 void rt2800_config_intf(struct rt2x00_dev *rt2x00dev, struct rt2x00_intf *intf,
1504 struct rt2x00intf_conf *conf, const unsigned int flags)
1507 bool update_bssid = false;
1509 if (flags & CONFIG_UPDATE_TYPE) {
1511 * Enable synchronisation.
1513 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®);
1514 rt2x00_set_field32(®, BCN_TIME_CFG_TSF_SYNC, conf->sync);
1515 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
1517 if (conf->sync == TSF_SYNC_AP_NONE) {
1519 * Tune beacon queue transmit parameters for AP mode
1521 rt2800_register_read(rt2x00dev, TBTT_SYNC_CFG, ®);
1522 rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_CWMIN, 0);
1523 rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_AIFSN, 1);
1524 rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_EXP_WIN, 32);
1525 rt2x00_set_field32(®, TBTT_SYNC_CFG_TBTT_ADJUST, 0);
1526 rt2800_register_write(rt2x00dev, TBTT_SYNC_CFG, reg);
1528 rt2800_register_read(rt2x00dev, TBTT_SYNC_CFG, ®);
1529 rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_CWMIN, 4);
1530 rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_AIFSN, 2);
1531 rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_EXP_WIN, 32);
1532 rt2x00_set_field32(®, TBTT_SYNC_CFG_TBTT_ADJUST, 16);
1533 rt2800_register_write(rt2x00dev, TBTT_SYNC_CFG, reg);
1537 if (flags & CONFIG_UPDATE_MAC) {
1538 if (flags & CONFIG_UPDATE_TYPE &&
1539 conf->sync == TSF_SYNC_AP_NONE) {
1541 * The BSSID register has to be set to our own mac
1542 * address in AP mode.
1544 memcpy(conf->bssid, conf->mac, sizeof(conf->mac));
1545 update_bssid = true;
1548 if (!is_zero_ether_addr((const u8 *)conf->mac)) {
1549 reg = le32_to_cpu(conf->mac[1]);
1550 rt2x00_set_field32(®, MAC_ADDR_DW1_UNICAST_TO_ME_MASK, 0xff);
1551 conf->mac[1] = cpu_to_le32(reg);
1554 rt2800_register_multiwrite(rt2x00dev, MAC_ADDR_DW0,
1555 conf->mac, sizeof(conf->mac));
1558 if ((flags & CONFIG_UPDATE_BSSID) || update_bssid) {
1559 if (!is_zero_ether_addr((const u8 *)conf->bssid)) {
1560 reg = le32_to_cpu(conf->bssid[1]);
1561 rt2x00_set_field32(®, MAC_BSSID_DW1_BSS_ID_MASK, 3);
1562 rt2x00_set_field32(®, MAC_BSSID_DW1_BSS_BCN_NUM, 7);
1563 conf->bssid[1] = cpu_to_le32(reg);
1566 rt2800_register_multiwrite(rt2x00dev, MAC_BSSID_DW0,
1567 conf->bssid, sizeof(conf->bssid));
1570 EXPORT_SYMBOL_GPL(rt2800_config_intf);
1572 static void rt2800_config_ht_opmode(struct rt2x00_dev *rt2x00dev,
1573 struct rt2x00lib_erp *erp)
1575 bool any_sta_nongf = !!(erp->ht_opmode &
1576 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
1577 u8 protection = erp->ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION;
1578 u8 mm20_mode, mm40_mode, gf20_mode, gf40_mode;
1579 u16 mm20_rate, mm40_rate, gf20_rate, gf40_rate;
1582 /* default protection rate for HT20: OFDM 24M */
1583 mm20_rate = gf20_rate = 0x4004;
1585 /* default protection rate for HT40: duplicate OFDM 24M */
1586 mm40_rate = gf40_rate = 0x4084;
1588 switch (protection) {
1589 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
1591 * All STAs in this BSS are HT20/40 but there might be
1592 * STAs not supporting greenfield mode.
1593 * => Disable protection for HT transmissions.
1595 mm20_mode = mm40_mode = gf20_mode = gf40_mode = 0;
1598 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
1600 * All STAs in this BSS are HT20 or HT20/40 but there
1601 * might be STAs not supporting greenfield mode.
1602 * => Protect all HT40 transmissions.
1604 mm20_mode = gf20_mode = 0;
1605 mm40_mode = gf40_mode = 2;
1608 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
1610 * Nonmember protection:
1611 * According to 802.11n we _should_ protect all
1612 * HT transmissions (but we don't have to).
1614 * But if cts_protection is enabled we _shall_ protect
1615 * all HT transmissions using a CCK rate.
1617 * And if any station is non GF we _shall_ protect
1620 * We decide to protect everything
1621 * -> fall through to mixed mode.
1623 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
1625 * Legacy STAs are present
1626 * => Protect all HT transmissions.
1628 mm20_mode = mm40_mode = gf20_mode = gf40_mode = 2;
1631 * If erp protection is needed we have to protect HT
1632 * transmissions with CCK 11M long preamble.
1634 if (erp->cts_protection) {
1635 /* don't duplicate RTS/CTS in CCK mode */
1636 mm20_rate = mm40_rate = 0x0003;
1637 gf20_rate = gf40_rate = 0x0003;
1642 /* check for STAs not supporting greenfield mode */
1644 gf20_mode = gf40_mode = 2;
1646 /* Update HT protection config */
1647 rt2800_register_read(rt2x00dev, MM20_PROT_CFG, ®);
1648 rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_RATE, mm20_rate);
1649 rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_CTRL, mm20_mode);
1650 rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
1652 rt2800_register_read(rt2x00dev, MM40_PROT_CFG, ®);
1653 rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_RATE, mm40_rate);
1654 rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_CTRL, mm40_mode);
1655 rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
1657 rt2800_register_read(rt2x00dev, GF20_PROT_CFG, ®);
1658 rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_RATE, gf20_rate);
1659 rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_CTRL, gf20_mode);
1660 rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
1662 rt2800_register_read(rt2x00dev, GF40_PROT_CFG, ®);
1663 rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_RATE, gf40_rate);
1664 rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_CTRL, gf40_mode);
1665 rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
1668 void rt2800_config_erp(struct rt2x00_dev *rt2x00dev, struct rt2x00lib_erp *erp,
1673 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1674 rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, ®);
1675 rt2x00_set_field32(®, AUTO_RSP_CFG_BAC_ACK_POLICY,
1676 !!erp->short_preamble);
1677 rt2x00_set_field32(®, AUTO_RSP_CFG_AR_PREAMBLE,
1678 !!erp->short_preamble);
1679 rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
1682 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1683 rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, ®);
1684 rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_CTRL,
1685 erp->cts_protection ? 2 : 0);
1686 rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
1689 if (changed & BSS_CHANGED_BASIC_RATES) {
1690 rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE,
1692 rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
1695 if (changed & BSS_CHANGED_ERP_SLOT) {
1696 rt2800_register_read(rt2x00dev, BKOFF_SLOT_CFG, ®);
1697 rt2x00_set_field32(®, BKOFF_SLOT_CFG_SLOT_TIME,
1699 rt2800_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg);
1701 rt2800_register_read(rt2x00dev, XIFS_TIME_CFG, ®);
1702 rt2x00_set_field32(®, XIFS_TIME_CFG_EIFS, erp->eifs);
1703 rt2800_register_write(rt2x00dev, XIFS_TIME_CFG, reg);
1706 if (changed & BSS_CHANGED_BEACON_INT) {
1707 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®);
1708 rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_INTERVAL,
1709 erp->beacon_int * 16);
1710 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
1713 if (changed & BSS_CHANGED_HT)
1714 rt2800_config_ht_opmode(rt2x00dev, erp);
1716 EXPORT_SYMBOL_GPL(rt2800_config_erp);
1718 static void rt2800_config_3572bt_ant(struct rt2x00_dev *rt2x00dev)
1722 u8 led_ctrl, led_g_mode, led_r_mode;
1724 rt2800_register_read(rt2x00dev, GPIO_SWITCH, ®);
1725 if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ) {
1726 rt2x00_set_field32(®, GPIO_SWITCH_0, 1);
1727 rt2x00_set_field32(®, GPIO_SWITCH_1, 1);
1729 rt2x00_set_field32(®, GPIO_SWITCH_0, 0);
1730 rt2x00_set_field32(®, GPIO_SWITCH_1, 0);
1732 rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg);
1734 rt2800_register_read(rt2x00dev, LED_CFG, ®);
1735 led_g_mode = rt2x00_get_field32(reg, LED_CFG_LED_POLAR) ? 3 : 0;
1736 led_r_mode = rt2x00_get_field32(reg, LED_CFG_LED_POLAR) ? 0 : 3;
1737 if (led_g_mode != rt2x00_get_field32(reg, LED_CFG_G_LED_MODE) ||
1738 led_r_mode != rt2x00_get_field32(reg, LED_CFG_R_LED_MODE)) {
1739 rt2800_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
1740 led_ctrl = rt2x00_get_field16(eeprom, EEPROM_FREQ_LED_MODE);
1741 if (led_ctrl == 0 || led_ctrl > 0x40) {
1742 rt2x00_set_field32(®, LED_CFG_G_LED_MODE, led_g_mode);
1743 rt2x00_set_field32(®, LED_CFG_R_LED_MODE, led_r_mode);
1744 rt2800_register_write(rt2x00dev, LED_CFG, reg);
1746 rt2800_mcu_request(rt2x00dev, MCU_BAND_SELECT, 0xff,
1747 (led_g_mode << 2) | led_r_mode, 1);
1752 static void rt2800_set_ant_diversity(struct rt2x00_dev *rt2x00dev,
1756 u8 eesk_pin = (ant == ANTENNA_A) ? 1 : 0;
1757 u8 gpio_bit3 = (ant == ANTENNA_A) ? 0 : 1;
1759 if (rt2x00_is_pci(rt2x00dev)) {
1760 rt2800_register_read(rt2x00dev, E2PROM_CSR, ®);
1761 rt2x00_set_field32(®, E2PROM_CSR_DATA_CLOCK, eesk_pin);
1762 rt2800_register_write(rt2x00dev, E2PROM_CSR, reg);
1763 } else if (rt2x00_is_usb(rt2x00dev))
1764 rt2800_mcu_request(rt2x00dev, MCU_ANT_SELECT, 0xff,
1767 rt2800_register_read(rt2x00dev, GPIO_CTRL, ®);
1768 rt2x00_set_field32(®, GPIO_CTRL_DIR3, 0);
1769 rt2x00_set_field32(®, GPIO_CTRL_VAL3, gpio_bit3);
1770 rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
1773 void rt2800_config_ant(struct rt2x00_dev *rt2x00dev, struct antenna_setup *ant)
1779 rt2800_bbp_read(rt2x00dev, 1, &r1);
1780 rt2800_bbp_read(rt2x00dev, 3, &r3);
1782 if (rt2x00_rt(rt2x00dev, RT3572) &&
1783 test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags))
1784 rt2800_config_3572bt_ant(rt2x00dev);
1787 * Configure the TX antenna.
1789 switch (ant->tx_chain_num) {
1791 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0);
1794 if (rt2x00_rt(rt2x00dev, RT3572) &&
1795 test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags))
1796 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 1);
1798 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2);
1801 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2);
1806 * Configure the RX antenna.
1808 switch (ant->rx_chain_num) {
1810 if (rt2x00_rt(rt2x00dev, RT3070) ||
1811 rt2x00_rt(rt2x00dev, RT3090) ||
1812 rt2x00_rt(rt2x00dev, RT3352) ||
1813 rt2x00_rt(rt2x00dev, RT3390)) {
1814 rt2800_eeprom_read(rt2x00dev,
1815 EEPROM_NIC_CONF1, &eeprom);
1816 if (rt2x00_get_field16(eeprom,
1817 EEPROM_NIC_CONF1_ANT_DIVERSITY))
1818 rt2800_set_ant_diversity(rt2x00dev,
1819 rt2x00dev->default_ant.rx);
1821 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0);
1824 if (rt2x00_rt(rt2x00dev, RT3572) &&
1825 test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags)) {
1826 rt2x00_set_field8(&r3, BBP3_RX_ADC, 1);
1827 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA,
1828 rt2x00dev->curr_band == IEEE80211_BAND_5GHZ);
1829 rt2800_set_ant_diversity(rt2x00dev, ANTENNA_B);
1831 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 1);
1835 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 2);
1839 rt2800_bbp_write(rt2x00dev, 3, r3);
1840 rt2800_bbp_write(rt2x00dev, 1, r1);
1842 if (rt2x00_rt(rt2x00dev, RT3593)) {
1843 if (ant->rx_chain_num == 1)
1844 rt2800_bbp_write(rt2x00dev, 86, 0x00);
1846 rt2800_bbp_write(rt2x00dev, 86, 0x46);
1849 EXPORT_SYMBOL_GPL(rt2800_config_ant);
1851 static void rt2800_config_lna_gain(struct rt2x00_dev *rt2x00dev,
1852 struct rt2x00lib_conf *libconf)
1857 if (libconf->rf.channel <= 14) {
1858 rt2800_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
1859 lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_BG);
1860 } else if (libconf->rf.channel <= 64) {
1861 rt2800_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
1862 lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_A0);
1863 } else if (libconf->rf.channel <= 128) {
1864 if (rt2x00_rt(rt2x00dev, RT3593)) {
1865 rt2800_eeprom_read(rt2x00dev, EEPROM_EXT_LNA2, &eeprom);
1866 lna_gain = rt2x00_get_field16(eeprom,
1867 EEPROM_EXT_LNA2_A1);
1869 rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom);
1870 lna_gain = rt2x00_get_field16(eeprom,
1871 EEPROM_RSSI_BG2_LNA_A1);
1874 if (rt2x00_rt(rt2x00dev, RT3593)) {
1875 rt2800_eeprom_read(rt2x00dev, EEPROM_EXT_LNA2, &eeprom);
1876 lna_gain = rt2x00_get_field16(eeprom,
1877 EEPROM_EXT_LNA2_A2);
1879 rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom);
1880 lna_gain = rt2x00_get_field16(eeprom,
1881 EEPROM_RSSI_A2_LNA_A2);
1885 rt2x00dev->lna_gain = lna_gain;
1888 #define FREQ_OFFSET_BOUND 0x5f
1890 static void rt2800_adjust_freq_offset(struct rt2x00_dev *rt2x00dev)
1892 u8 freq_offset, prev_freq_offset;
1893 u8 rfcsr, prev_rfcsr;
1895 freq_offset = rt2x00_get_field8(rt2x00dev->freq_offset, RFCSR17_CODE);
1896 freq_offset = min_t(u8, freq_offset, FREQ_OFFSET_BOUND);
1898 rt2800_rfcsr_read(rt2x00dev, 17, &rfcsr);
1901 rt2x00_set_field8(&rfcsr, RFCSR17_CODE, freq_offset);
1902 if (rfcsr == prev_rfcsr)
1905 if (rt2x00_is_usb(rt2x00dev)) {
1906 rt2800_mcu_request(rt2x00dev, MCU_FREQ_OFFSET, 0xff,
1907 freq_offset, prev_rfcsr);
1911 prev_freq_offset = rt2x00_get_field8(prev_rfcsr, RFCSR17_CODE);
1912 while (prev_freq_offset != freq_offset) {
1913 if (prev_freq_offset < freq_offset)
1918 rt2x00_set_field8(&rfcsr, RFCSR17_CODE, prev_freq_offset);
1919 rt2800_rfcsr_write(rt2x00dev, 17, rfcsr);
1921 usleep_range(1000, 1500);
1925 static void rt2800_config_channel_rf2xxx(struct rt2x00_dev *rt2x00dev,
1926 struct ieee80211_conf *conf,
1927 struct rf_channel *rf,
1928 struct channel_info *info)
1930 rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
1932 if (rt2x00dev->default_ant.tx_chain_num == 1)
1933 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_TX1, 1);
1935 if (rt2x00dev->default_ant.rx_chain_num == 1) {
1936 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX1, 1);
1937 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
1938 } else if (rt2x00dev->default_ant.rx_chain_num == 2)
1939 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
1941 if (rf->channel > 14) {
1943 * When TX power is below 0, we should increase it by 7 to
1944 * make it a positive value (Minimum value is -7).
1945 * However this means that values between 0 and 7 have
1946 * double meaning, and we should set a 7DBm boost flag.
1948 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A_7DBM_BOOST,
1949 (info->default_power1 >= 0));
1951 if (info->default_power1 < 0)
1952 info->default_power1 += 7;
1954 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A, info->default_power1);
1956 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A_7DBM_BOOST,
1957 (info->default_power2 >= 0));
1959 if (info->default_power2 < 0)
1960 info->default_power2 += 7;
1962 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A, info->default_power2);
1964 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_G, info->default_power1);
1965 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_G, info->default_power2);
1968 rt2x00_set_field32(&rf->rf4, RF4_HT40, conf_is_ht40(conf));
1970 rt2800_rf_write(rt2x00dev, 1, rf->rf1);
1971 rt2800_rf_write(rt2x00dev, 2, rf->rf2);
1972 rt2800_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
1973 rt2800_rf_write(rt2x00dev, 4, rf->rf4);
1977 rt2800_rf_write(rt2x00dev, 1, rf->rf1);
1978 rt2800_rf_write(rt2x00dev, 2, rf->rf2);
1979 rt2800_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
1980 rt2800_rf_write(rt2x00dev, 4, rf->rf4);
1984 rt2800_rf_write(rt2x00dev, 1, rf->rf1);
1985 rt2800_rf_write(rt2x00dev, 2, rf->rf2);
1986 rt2800_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
1987 rt2800_rf_write(rt2x00dev, 4, rf->rf4);
1990 static void rt2800_config_channel_rf3xxx(struct rt2x00_dev *rt2x00dev,
1991 struct ieee80211_conf *conf,
1992 struct rf_channel *rf,
1993 struct channel_info *info)
1995 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
1996 u8 rfcsr, calib_tx, calib_rx;
1998 rt2800_rfcsr_write(rt2x00dev, 2, rf->rf1);
2000 rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr);
2001 rt2x00_set_field8(&rfcsr, RFCSR3_K, rf->rf3);
2002 rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
2004 rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr);
2005 rt2x00_set_field8(&rfcsr, RFCSR6_R1, rf->rf2);
2006 rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
2008 rt2800_rfcsr_read(rt2x00dev, 12, &rfcsr);
2009 rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER, info->default_power1);
2010 rt2800_rfcsr_write(rt2x00dev, 12, rfcsr);
2012 rt2800_rfcsr_read(rt2x00dev, 13, &rfcsr);
2013 rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER, info->default_power2);
2014 rt2800_rfcsr_write(rt2x00dev, 13, rfcsr);
2016 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
2017 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0);
2018 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD,
2019 rt2x00dev->default_ant.rx_chain_num <= 1);
2020 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD,
2021 rt2x00dev->default_ant.rx_chain_num <= 2);
2022 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0);
2023 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD,
2024 rt2x00dev->default_ant.tx_chain_num <= 1);
2025 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD,
2026 rt2x00dev->default_ant.tx_chain_num <= 2);
2027 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
2029 rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
2030 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1);
2031 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
2033 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0);
2034 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
2036 rt2800_rfcsr_read(rt2x00dev, 23, &rfcsr);
2037 rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset);
2038 rt2800_rfcsr_write(rt2x00dev, 23, rfcsr);
2040 if (rt2x00_rt(rt2x00dev, RT3390)) {
2041 calib_tx = conf_is_ht40(conf) ? 0x68 : 0x4f;
2042 calib_rx = conf_is_ht40(conf) ? 0x6f : 0x4f;
2044 if (conf_is_ht40(conf)) {
2045 calib_tx = drv_data->calibration_bw40;
2046 calib_rx = drv_data->calibration_bw40;
2048 calib_tx = drv_data->calibration_bw20;
2049 calib_rx = drv_data->calibration_bw20;
2053 rt2800_rfcsr_read(rt2x00dev, 24, &rfcsr);
2054 rt2x00_set_field8(&rfcsr, RFCSR24_TX_CALIB, calib_tx);
2055 rt2800_rfcsr_write(rt2x00dev, 24, rfcsr);
2057 rt2800_rfcsr_read(rt2x00dev, 31, &rfcsr);
2058 rt2x00_set_field8(&rfcsr, RFCSR31_RX_CALIB, calib_rx);
2059 rt2800_rfcsr_write(rt2x00dev, 31, rfcsr);
2061 rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr);
2062 rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
2063 rt2800_rfcsr_write(rt2x00dev, 7, rfcsr);
2065 rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
2066 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1);
2067 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
2069 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0);
2070 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
2073 static void rt2800_config_channel_rf3052(struct rt2x00_dev *rt2x00dev,
2074 struct ieee80211_conf *conf,
2075 struct rf_channel *rf,
2076 struct channel_info *info)
2078 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
2082 if (rf->channel <= 14) {
2083 rt2800_bbp_write(rt2x00dev, 25, drv_data->bbp25);
2084 rt2800_bbp_write(rt2x00dev, 26, drv_data->bbp26);
2086 rt2800_bbp_write(rt2x00dev, 25, 0x09);
2087 rt2800_bbp_write(rt2x00dev, 26, 0xff);
2090 rt2800_rfcsr_write(rt2x00dev, 2, rf->rf1);
2091 rt2800_rfcsr_write(rt2x00dev, 3, rf->rf3);
2093 rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr);
2094 rt2x00_set_field8(&rfcsr, RFCSR6_R1, rf->rf2);
2095 if (rf->channel <= 14)
2096 rt2x00_set_field8(&rfcsr, RFCSR6_TXDIV, 2);
2098 rt2x00_set_field8(&rfcsr, RFCSR6_TXDIV, 1);
2099 rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
2101 rt2800_rfcsr_read(rt2x00dev, 5, &rfcsr);
2102 if (rf->channel <= 14)
2103 rt2x00_set_field8(&rfcsr, RFCSR5_R1, 1);
2105 rt2x00_set_field8(&rfcsr, RFCSR5_R1, 2);
2106 rt2800_rfcsr_write(rt2x00dev, 5, rfcsr);
2108 rt2800_rfcsr_read(rt2x00dev, 12, &rfcsr);
2109 if (rf->channel <= 14) {
2110 rt2x00_set_field8(&rfcsr, RFCSR12_DR0, 3);
2111 rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER,
2112 info->default_power1);
2114 rt2x00_set_field8(&rfcsr, RFCSR12_DR0, 7);
2115 rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER,
2116 (info->default_power1 & 0x3) |
2117 ((info->default_power1 & 0xC) << 1));
2119 rt2800_rfcsr_write(rt2x00dev, 12, rfcsr);
2121 rt2800_rfcsr_read(rt2x00dev, 13, &rfcsr);
2122 if (rf->channel <= 14) {
2123 rt2x00_set_field8(&rfcsr, RFCSR13_DR0, 3);
2124 rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER,
2125 info->default_power2);
2127 rt2x00_set_field8(&rfcsr, RFCSR13_DR0, 7);
2128 rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER,
2129 (info->default_power2 & 0x3) |
2130 ((info->default_power2 & 0xC) << 1));
2132 rt2800_rfcsr_write(rt2x00dev, 13, rfcsr);
2134 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
2135 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0);
2136 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0);
2137 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 0);
2138 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 0);
2139 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0);
2140 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0);
2141 if (test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags)) {
2142 if (rf->channel <= 14) {
2143 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1);
2144 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1);
2146 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 1);
2147 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 1);
2149 switch (rt2x00dev->default_ant.tx_chain_num) {
2151 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
2153 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 1);
2157 switch (rt2x00dev->default_ant.rx_chain_num) {
2159 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
2161 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 1);
2165 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
2167 rt2800_rfcsr_read(rt2x00dev, 23, &rfcsr);
2168 rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset);
2169 rt2800_rfcsr_write(rt2x00dev, 23, rfcsr);
2171 if (conf_is_ht40(conf)) {
2172 rt2800_rfcsr_write(rt2x00dev, 24, drv_data->calibration_bw40);
2173 rt2800_rfcsr_write(rt2x00dev, 31, drv_data->calibration_bw40);
2175 rt2800_rfcsr_write(rt2x00dev, 24, drv_data->calibration_bw20);
2176 rt2800_rfcsr_write(rt2x00dev, 31, drv_data->calibration_bw20);
2179 if (rf->channel <= 14) {
2180 rt2800_rfcsr_write(rt2x00dev, 7, 0xd8);
2181 rt2800_rfcsr_write(rt2x00dev, 9, 0xc3);
2182 rt2800_rfcsr_write(rt2x00dev, 10, 0xf1);
2183 rt2800_rfcsr_write(rt2x00dev, 11, 0xb9);
2184 rt2800_rfcsr_write(rt2x00dev, 15, 0x53);
2186 rt2x00_set_field8(&rfcsr, RFCSR16_TXMIXER_GAIN,
2187 drv_data->txmixer_gain_24g);
2188 rt2800_rfcsr_write(rt2x00dev, 16, rfcsr);
2189 rt2800_rfcsr_write(rt2x00dev, 17, 0x23);
2190 rt2800_rfcsr_write(rt2x00dev, 19, 0x93);
2191 rt2800_rfcsr_write(rt2x00dev, 20, 0xb3);
2192 rt2800_rfcsr_write(rt2x00dev, 25, 0x15);
2193 rt2800_rfcsr_write(rt2x00dev, 26, 0x85);
2194 rt2800_rfcsr_write(rt2x00dev, 27, 0x00);
2195 rt2800_rfcsr_write(rt2x00dev, 29, 0x9b);
2197 rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr);
2198 rt2x00_set_field8(&rfcsr, RFCSR7_BIT2, 1);
2199 rt2x00_set_field8(&rfcsr, RFCSR7_BIT3, 0);
2200 rt2x00_set_field8(&rfcsr, RFCSR7_BIT4, 1);
2201 rt2x00_set_field8(&rfcsr, RFCSR7_BITS67, 0);
2202 rt2800_rfcsr_write(rt2x00dev, 7, rfcsr);
2203 rt2800_rfcsr_write(rt2x00dev, 9, 0xc0);
2204 rt2800_rfcsr_write(rt2x00dev, 10, 0xf1);
2205 rt2800_rfcsr_write(rt2x00dev, 11, 0x00);
2206 rt2800_rfcsr_write(rt2x00dev, 15, 0x43);
2208 rt2x00_set_field8(&rfcsr, RFCSR16_TXMIXER_GAIN,
2209 drv_data->txmixer_gain_5g);
2210 rt2800_rfcsr_write(rt2x00dev, 16, rfcsr);
2211 rt2800_rfcsr_write(rt2x00dev, 17, 0x23);
2212 if (rf->channel <= 64) {
2213 rt2800_rfcsr_write(rt2x00dev, 19, 0xb7);
2214 rt2800_rfcsr_write(rt2x00dev, 20, 0xf6);
2215 rt2800_rfcsr_write(rt2x00dev, 25, 0x3d);
2216 } else if (rf->channel <= 128) {
2217 rt2800_rfcsr_write(rt2x00dev, 19, 0x74);
2218 rt2800_rfcsr_write(rt2x00dev, 20, 0xf4);
2219 rt2800_rfcsr_write(rt2x00dev, 25, 0x01);
2221 rt2800_rfcsr_write(rt2x00dev, 19, 0x72);
2222 rt2800_rfcsr_write(rt2x00dev, 20, 0xf3);
2223 rt2800_rfcsr_write(rt2x00dev, 25, 0x01);
2225 rt2800_rfcsr_write(rt2x00dev, 26, 0x87);
2226 rt2800_rfcsr_write(rt2x00dev, 27, 0x01);
2227 rt2800_rfcsr_write(rt2x00dev, 29, 0x9f);
2230 rt2800_register_read(rt2x00dev, GPIO_CTRL, ®);
2231 rt2x00_set_field32(®, GPIO_CTRL_DIR7, 0);
2232 if (rf->channel <= 14)
2233 rt2x00_set_field32(®, GPIO_CTRL_VAL7, 1);
2235 rt2x00_set_field32(®, GPIO_CTRL_VAL7, 0);
2236 rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
2238 rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr);
2239 rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
2240 rt2800_rfcsr_write(rt2x00dev, 7, rfcsr);
2243 static void rt2800_config_channel_rf3053(struct rt2x00_dev *rt2x00dev,
2244 struct ieee80211_conf *conf,
2245 struct rf_channel *rf,
2246 struct channel_info *info)
2248 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
2253 const bool txbf_enabled = false; /* TODO */
2255 /* TODO: use TX{0,1,2}FinePowerControl values from EEPROM */
2256 rt2800_bbp_read(rt2x00dev, 109, &bbp);
2257 rt2x00_set_field8(&bbp, BBP109_TX0_POWER, 0);
2258 rt2x00_set_field8(&bbp, BBP109_TX1_POWER, 0);
2259 rt2800_bbp_write(rt2x00dev, 109, bbp);
2261 rt2800_bbp_read(rt2x00dev, 110, &bbp);
2262 rt2x00_set_field8(&bbp, BBP110_TX2_POWER, 0);
2263 rt2800_bbp_write(rt2x00dev, 110, bbp);
2265 if (rf->channel <= 14) {
2266 /* Restore BBP 25 & 26 for 2.4 GHz */
2267 rt2800_bbp_write(rt2x00dev, 25, drv_data->bbp25);
2268 rt2800_bbp_write(rt2x00dev, 26, drv_data->bbp26);
2270 /* Hard code BBP 25 & 26 for 5GHz */
2272 /* Enable IQ Phase correction */
2273 rt2800_bbp_write(rt2x00dev, 25, 0x09);
2274 /* Setup IQ Phase correction value */
2275 rt2800_bbp_write(rt2x00dev, 26, 0xff);
2278 rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1);
2279 rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3 & 0xf);
2281 rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr);
2282 rt2x00_set_field8(&rfcsr, RFCSR11_R, (rf->rf2 & 0x3));
2283 rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
2285 rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr);
2286 rt2x00_set_field8(&rfcsr, RFCSR11_PLL_IDOH, 1);
2287 if (rf->channel <= 14)
2288 rt2x00_set_field8(&rfcsr, RFCSR11_PLL_MOD, 1);
2290 rt2x00_set_field8(&rfcsr, RFCSR11_PLL_MOD, 2);
2291 rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
2293 rt2800_rfcsr_read(rt2x00dev, 53, &rfcsr);
2294 if (rf->channel <= 14) {
2296 rt2x00_set_field8(&rfcsr, RFCSR53_TX_POWER,
2297 info->default_power1 & 0x1f);
2299 if (rt2x00_is_usb(rt2x00dev))
2302 rt2x00_set_field8(&rfcsr, RFCSR53_TX_POWER,
2303 ((info->default_power1 & 0x18) << 1) |
2304 (info->default_power1 & 7));
2306 rt2800_rfcsr_write(rt2x00dev, 53, rfcsr);
2308 rt2800_rfcsr_read(rt2x00dev, 55, &rfcsr);
2309 if (rf->channel <= 14) {
2311 rt2x00_set_field8(&rfcsr, RFCSR55_TX_POWER,
2312 info->default_power2 & 0x1f);
2314 if (rt2x00_is_usb(rt2x00dev))
2317 rt2x00_set_field8(&rfcsr, RFCSR55_TX_POWER,
2318 ((info->default_power2 & 0x18) << 1) |
2319 (info->default_power2 & 7));
2321 rt2800_rfcsr_write(rt2x00dev, 55, rfcsr);
2323 rt2800_rfcsr_read(rt2x00dev, 54, &rfcsr);
2324 if (rf->channel <= 14) {
2326 rt2x00_set_field8(&rfcsr, RFCSR54_TX_POWER,
2327 info->default_power3 & 0x1f);
2329 if (rt2x00_is_usb(rt2x00dev))
2332 rt2x00_set_field8(&rfcsr, RFCSR54_TX_POWER,
2333 ((info->default_power3 & 0x18) << 1) |
2334 (info->default_power3 & 7));
2336 rt2800_rfcsr_write(rt2x00dev, 54, rfcsr);
2338 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
2339 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0);
2340 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0);
2341 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 0);
2342 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 0);
2343 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0);
2344 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0);
2345 rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
2346 rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1);
2348 switch (rt2x00dev->default_ant.tx_chain_num) {
2350 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 1);
2353 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
2356 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1);
2360 switch (rt2x00dev->default_ant.rx_chain_num) {
2362 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 1);
2365 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
2368 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1);
2371 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
2373 rt2800_adjust_freq_offset(rt2x00dev);
2375 if (conf_is_ht40(conf)) {
2376 txrx_agc_fc = rt2x00_get_field8(drv_data->calibration_bw40,
2378 txrx_h20m = rt2x00_get_field8(drv_data->calibration_bw40,
2381 txrx_agc_fc = rt2x00_get_field8(drv_data->calibration_bw20,
2383 txrx_h20m = rt2x00_get_field8(drv_data->calibration_bw20,
2387 /* NOTE: the reference driver does not writes the new value
2390 rt2800_rfcsr_read(rt2x00dev, 32, &rfcsr);
2391 rt2x00_set_field8(&rfcsr, RFCSR32_TX_AGC_FC, txrx_agc_fc);
2393 if (rf->channel <= 14)
2397 rt2800_rfcsr_write(rt2x00dev, 31, rfcsr);
2399 rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
2400 rt2x00_set_field8(&rfcsr, RFCSR30_TX_H20M, txrx_h20m);
2401 rt2x00_set_field8(&rfcsr, RFCSR30_RX_H20M, txrx_h20m);
2402 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
2404 /* Band selection */
2405 rt2800_rfcsr_read(rt2x00dev, 36, &rfcsr);
2406 if (rf->channel <= 14)
2407 rt2x00_set_field8(&rfcsr, RFCSR36_RF_BS, 1);
2409 rt2x00_set_field8(&rfcsr, RFCSR36_RF_BS, 0);
2410 rt2800_rfcsr_write(rt2x00dev, 36, rfcsr);
2412 rt2800_rfcsr_read(rt2x00dev, 34, &rfcsr);
2413 if (rf->channel <= 14)
2417 rt2800_rfcsr_write(rt2x00dev, 34, rfcsr);
2419 rt2800_rfcsr_read(rt2x00dev, 12, &rfcsr);
2420 if (rf->channel <= 14)
2424 rt2800_rfcsr_write(rt2x00dev, 12, rfcsr);
2426 rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr);
2427 if (rf->channel >= 1 && rf->channel <= 14)
2428 rt2x00_set_field8(&rfcsr, RFCSR6_VCO_IC, 1);
2429 else if (rf->channel >= 36 && rf->channel <= 64)
2430 rt2x00_set_field8(&rfcsr, RFCSR6_VCO_IC, 2);
2431 else if (rf->channel >= 100 && rf->channel <= 128)
2432 rt2x00_set_field8(&rfcsr, RFCSR6_VCO_IC, 2);
2434 rt2x00_set_field8(&rfcsr, RFCSR6_VCO_IC, 1);
2435 rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
2437 rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
2438 rt2x00_set_field8(&rfcsr, RFCSR30_RX_VCM, 2);
2439 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
2441 rt2800_rfcsr_write(rt2x00dev, 46, 0x60);
2443 if (rf->channel <= 14) {
2444 rt2800_rfcsr_write(rt2x00dev, 10, 0xd3);
2445 rt2800_rfcsr_write(rt2x00dev, 13, 0x12);
2447 rt2800_rfcsr_write(rt2x00dev, 10, 0xd8);
2448 rt2800_rfcsr_write(rt2x00dev, 13, 0x23);
2451 rt2800_rfcsr_read(rt2x00dev, 51, &rfcsr);
2452 rt2x00_set_field8(&rfcsr, RFCSR51_BITS01, 1);
2453 rt2800_rfcsr_write(rt2x00dev, 51, rfcsr);
2455 rt2800_rfcsr_read(rt2x00dev, 51, &rfcsr);
2456 if (rf->channel <= 14) {
2457 rt2x00_set_field8(&rfcsr, RFCSR51_BITS24, 5);
2458 rt2x00_set_field8(&rfcsr, RFCSR51_BITS57, 3);
2460 rt2x00_set_field8(&rfcsr, RFCSR51_BITS24, 4);
2461 rt2x00_set_field8(&rfcsr, RFCSR51_BITS57, 2);
2463 rt2800_rfcsr_write(rt2x00dev, 51, rfcsr);
2465 rt2800_rfcsr_read(rt2x00dev, 49, &rfcsr);
2466 if (rf->channel <= 14)
2467 rt2x00_set_field8(&rfcsr, RFCSR49_TX_LO1_IC, 3);
2469 rt2x00_set_field8(&rfcsr, RFCSR49_TX_LO1_IC, 2);
2472 rt2x00_set_field8(&rfcsr, RFCSR49_TX_DIV, 1);
2474 rt2800_rfcsr_write(rt2x00dev, 49, rfcsr);
2476 rt2800_rfcsr_read(rt2x00dev, 50, &rfcsr);
2477 rt2x00_set_field8(&rfcsr, RFCSR50_TX_LO1_EN, 0);
2478 rt2800_rfcsr_write(rt2x00dev, 50, rfcsr);
2480 rt2800_rfcsr_read(rt2x00dev, 57, &rfcsr);
2481 if (rf->channel <= 14)
2482 rt2x00_set_field8(&rfcsr, RFCSR57_DRV_CC, 0x1b);
2484 rt2x00_set_field8(&rfcsr, RFCSR57_DRV_CC, 0x0f);
2485 rt2800_rfcsr_write(rt2x00dev, 57, rfcsr);
2487 if (rf->channel <= 14) {
2488 rt2800_rfcsr_write(rt2x00dev, 44, 0x93);
2489 rt2800_rfcsr_write(rt2x00dev, 52, 0x45);
2491 rt2800_rfcsr_write(rt2x00dev, 44, 0x9b);
2492 rt2800_rfcsr_write(rt2x00dev, 52, 0x05);
2495 /* Initiate VCO calibration */
2496 rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr);
2497 if (rf->channel <= 14) {
2498 rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
2500 rt2x00_set_field8(&rfcsr, RFCSR3_BIT1, 1);
2501 rt2x00_set_field8(&rfcsr, RFCSR3_BIT2, 1);
2502 rt2x00_set_field8(&rfcsr, RFCSR3_BIT3, 1);
2503 rt2x00_set_field8(&rfcsr, RFCSR3_BIT4, 1);
2504 rt2x00_set_field8(&rfcsr, RFCSR3_BIT5, 1);
2505 rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
2507 rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
2509 if (rf->channel >= 1 && rf->channel <= 14) {
2512 rt2x00_set_field8(&rfcsr, RFCSR39_RX_DIV, 1);
2513 rt2800_rfcsr_write(rt2x00dev, 39, rfcsr);
2515 rt2800_rfcsr_write(rt2x00dev, 45, 0xbb);
2516 } else if (rf->channel >= 36 && rf->channel <= 64) {
2519 rt2x00_set_field8(&rfcsr, RFCSR39_RX_DIV, 1);
2520 rt2800_rfcsr_write(rt2x00dev, 39, 0x36);
2522 rt2800_rfcsr_write(rt2x00dev, 45, 0xeb);
2523 } else if (rf->channel >= 100 && rf->channel <= 128) {
2526 rt2x00_set_field8(&rfcsr, RFCSR39_RX_DIV, 1);
2527 rt2800_rfcsr_write(rt2x00dev, 39, rfcsr);
2529 rt2800_rfcsr_write(rt2x00dev, 45, 0xb3);
2533 rt2x00_set_field8(&rfcsr, RFCSR39_RX_DIV, 1);
2534 rt2800_rfcsr_write(rt2x00dev, 39, rfcsr);
2536 rt2800_rfcsr_write(rt2x00dev, 45, 0x9b);
2540 #define POWER_BOUND 0x27
2541 #define POWER_BOUND_5G 0x2b
2543 static void rt2800_config_channel_rf3290(struct rt2x00_dev *rt2x00dev,
2544 struct ieee80211_conf *conf,
2545 struct rf_channel *rf,
2546 struct channel_info *info)
2550 rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1);
2551 rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3);
2552 rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr);
2553 rt2x00_set_field8(&rfcsr, RFCSR11_R, rf->rf2);
2554 rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
2556 rt2800_rfcsr_read(rt2x00dev, 49, &rfcsr);
2557 if (info->default_power1 > POWER_BOUND)
2558 rt2x00_set_field8(&rfcsr, RFCSR49_TX, POWER_BOUND);
2560 rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1);
2561 rt2800_rfcsr_write(rt2x00dev, 49, rfcsr);
2563 rt2800_adjust_freq_offset(rt2x00dev);
2565 if (rf->channel <= 14) {
2566 if (rf->channel == 6)
2567 rt2800_bbp_write(rt2x00dev, 68, 0x0c);
2569 rt2800_bbp_write(rt2x00dev, 68, 0x0b);
2571 if (rf->channel >= 1 && rf->channel <= 6)
2572 rt2800_bbp_write(rt2x00dev, 59, 0x0f);
2573 else if (rf->channel >= 7 && rf->channel <= 11)
2574 rt2800_bbp_write(rt2x00dev, 59, 0x0e);
2575 else if (rf->channel >= 12 && rf->channel <= 14)
2576 rt2800_bbp_write(rt2x00dev, 59, 0x0d);
2580 static void rt2800_config_channel_rf3322(struct rt2x00_dev *rt2x00dev,
2581 struct ieee80211_conf *conf,
2582 struct rf_channel *rf,
2583 struct channel_info *info)
2587 rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1);
2588 rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3);
2590 rt2800_rfcsr_write(rt2x00dev, 11, 0x42);
2591 rt2800_rfcsr_write(rt2x00dev, 12, 0x1c);
2592 rt2800_rfcsr_write(rt2x00dev, 13, 0x00);
2594 if (info->default_power1 > POWER_BOUND)
2595 rt2800_rfcsr_write(rt2x00dev, 47, POWER_BOUND);
2597 rt2800_rfcsr_write(rt2x00dev, 47, info->default_power1);
2599 if (info->default_power2 > POWER_BOUND)
2600 rt2800_rfcsr_write(rt2x00dev, 48, POWER_BOUND);
2602 rt2800_rfcsr_write(rt2x00dev, 48, info->default_power2);
2604 rt2800_adjust_freq_offset(rt2x00dev);
2606 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
2607 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1);
2608 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1);
2610 if ( rt2x00dev->default_ant.tx_chain_num == 2 )
2611 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
2613 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 0);
2615 if ( rt2x00dev->default_ant.rx_chain_num == 2 )
2616 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
2618 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 0);
2620 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0);
2621 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0);
2623 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
2625 rt2800_rfcsr_write(rt2x00dev, 31, 80);
2628 static void rt2800_config_channel_rf53xx(struct rt2x00_dev *rt2x00dev,
2629 struct ieee80211_conf *conf,
2630 struct rf_channel *rf,
2631 struct channel_info *info)
2635 rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1);
2636 rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3);
2637 rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr);
2638 rt2x00_set_field8(&rfcsr, RFCSR11_R, rf->rf2);
2639 rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
2641 rt2800_rfcsr_read(rt2x00dev, 49, &rfcsr);
2642 if (info->default_power1 > POWER_BOUND)
2643 rt2x00_set_field8(&rfcsr, RFCSR49_TX, POWER_BOUND);
2645 rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1);
2646 rt2800_rfcsr_write(rt2x00dev, 49, rfcsr);
2648 if (rt2x00_rt(rt2x00dev, RT5392)) {
2649 rt2800_rfcsr_read(rt2x00dev, 50, &rfcsr);
2650 if (info->default_power1 > POWER_BOUND)
2651 rt2x00_set_field8(&rfcsr, RFCSR50_TX, POWER_BOUND);
2653 rt2x00_set_field8(&rfcsr, RFCSR50_TX,
2654 info->default_power2);
2655 rt2800_rfcsr_write(rt2x00dev, 50, rfcsr);
2658 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
2659 if (rt2x00_rt(rt2x00dev, RT5392)) {
2660 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
2661 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
2663 rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
2664 rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1);
2665 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1);
2666 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1);
2667 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
2669 rt2800_adjust_freq_offset(rt2x00dev);
2671 if (rf->channel <= 14) {
2672 int idx = rf->channel-1;
2674 if (test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags)) {
2675 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) {
2676 /* r55/r59 value array of channel 1~14 */
2677 static const char r55_bt_rev[] = {0x83, 0x83,
2678 0x83, 0x73, 0x73, 0x63, 0x53, 0x53,
2679 0x53, 0x43, 0x43, 0x43, 0x43, 0x43};
2680 static const char r59_bt_rev[] = {0x0e, 0x0e,
2681 0x0e, 0x0e, 0x0e, 0x0b, 0x0a, 0x09,
2682 0x07, 0x07, 0x07, 0x07, 0x07, 0x07};
2684 rt2800_rfcsr_write(rt2x00dev, 55,
2686 rt2800_rfcsr_write(rt2x00dev, 59,
2689 static const char r59_bt[] = {0x8b, 0x8b, 0x8b,
2690 0x8b, 0x8b, 0x8b, 0x8b, 0x8a, 0x89,
2691 0x88, 0x88, 0x86, 0x85, 0x84};
2693 rt2800_rfcsr_write(rt2x00dev, 59, r59_bt[idx]);
2696 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) {
2697 static const char r55_nonbt_rev[] = {0x23, 0x23,
2698 0x23, 0x23, 0x13, 0x13, 0x03, 0x03,
2699 0x03, 0x03, 0x03, 0x03, 0x03, 0x03};
2700 static const char r59_nonbt_rev[] = {0x07, 0x07,
2701 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
2702 0x07, 0x07, 0x06, 0x05, 0x04, 0x04};
2704 rt2800_rfcsr_write(rt2x00dev, 55,
2705 r55_nonbt_rev[idx]);
2706 rt2800_rfcsr_write(rt2x00dev, 59,
2707 r59_nonbt_rev[idx]);
2708 } else if (rt2x00_rt(rt2x00dev, RT5390) ||
2709 rt2x00_rt(rt2x00dev, RT5392)) {
2710 static const char r59_non_bt[] = {0x8f, 0x8f,
2711 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8d,
2712 0x8a, 0x88, 0x88, 0x87, 0x87, 0x86};
2714 rt2800_rfcsr_write(rt2x00dev, 59,
2721 static void rt2800_config_channel_rf55xx(struct rt2x00_dev *rt2x00dev,
2722 struct ieee80211_conf *conf,
2723 struct rf_channel *rf,
2724 struct channel_info *info)
2731 const bool is_11b = false;
2732 const bool is_type_ep = false;
2734 rt2800_register_read(rt2x00dev, LDO_CFG0, ®);
2735 rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL,
2736 (rf->channel > 14 || conf_is_ht40(conf)) ? 5 : 0);
2737 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
2739 /* Order of values on rf_channel entry: N, K, mod, R */
2740 rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1 & 0xff);
2742 rt2800_rfcsr_read(rt2x00dev, 9, &rfcsr);
2743 rt2x00_set_field8(&rfcsr, RFCSR9_K, rf->rf2 & 0xf);
2744 rt2x00_set_field8(&rfcsr, RFCSR9_N, (rf->rf1 & 0x100) >> 8);
2745 rt2x00_set_field8(&rfcsr, RFCSR9_MOD, ((rf->rf3 - 8) & 0x4) >> 2);
2746 rt2800_rfcsr_write(rt2x00dev, 9, rfcsr);
2748 rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr);
2749 rt2x00_set_field8(&rfcsr, RFCSR11_R, rf->rf4 - 1);
2750 rt2x00_set_field8(&rfcsr, RFCSR11_MOD, (rf->rf3 - 8) & 0x3);
2751 rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
2753 if (rf->channel <= 14) {
2754 rt2800_rfcsr_write(rt2x00dev, 10, 0x90);
2755 /* FIXME: RF11 owerwrite ? */
2756 rt2800_rfcsr_write(rt2x00dev, 11, 0x4A);
2757 rt2800_rfcsr_write(rt2x00dev, 12, 0x52);
2758 rt2800_rfcsr_write(rt2x00dev, 13, 0x42);
2759 rt2800_rfcsr_write(rt2x00dev, 22, 0x40);
2760 rt2800_rfcsr_write(rt2x00dev, 24, 0x4A);
2761 rt2800_rfcsr_write(rt2x00dev, 25, 0x80);
2762 rt2800_rfcsr_write(rt2x00dev, 27, 0x42);
2763 rt2800_rfcsr_write(rt2x00dev, 36, 0x80);
2764 rt2800_rfcsr_write(rt2x00dev, 37, 0x08);
2765 rt2800_rfcsr_write(rt2x00dev, 38, 0x89);
2766 rt2800_rfcsr_write(rt2x00dev, 39, 0x1B);
2767 rt2800_rfcsr_write(rt2x00dev, 40, 0x0D);
2768 rt2800_rfcsr_write(rt2x00dev, 41, 0x9B);
2769 rt2800_rfcsr_write(rt2x00dev, 42, 0xD5);
2770 rt2800_rfcsr_write(rt2x00dev, 43, 0x72);
2771 rt2800_rfcsr_write(rt2x00dev, 44, 0x0E);
2772 rt2800_rfcsr_write(rt2x00dev, 45, 0xA2);
2773 rt2800_rfcsr_write(rt2x00dev, 46, 0x6B);
2774 rt2800_rfcsr_write(rt2x00dev, 48, 0x10);
2775 rt2800_rfcsr_write(rt2x00dev, 51, 0x3E);
2776 rt2800_rfcsr_write(rt2x00dev, 52, 0x48);
2777 rt2800_rfcsr_write(rt2x00dev, 54, 0x38);
2778 rt2800_rfcsr_write(rt2x00dev, 56, 0xA1);
2779 rt2800_rfcsr_write(rt2x00dev, 57, 0x00);
2780 rt2800_rfcsr_write(rt2x00dev, 58, 0x39);
2781 rt2800_rfcsr_write(rt2x00dev, 60, 0x45);
2782 rt2800_rfcsr_write(rt2x00dev, 61, 0x91);
2783 rt2800_rfcsr_write(rt2x00dev, 62, 0x39);
2785 /* TODO RF27 <- tssi */
2787 rfcsr = rf->channel <= 10 ? 0x07 : 0x06;
2788 rt2800_rfcsr_write(rt2x00dev, 23, rfcsr);
2789 rt2800_rfcsr_write(rt2x00dev, 59, rfcsr);
2793 rt2800_rfcsr_write(rt2x00dev, 31, 0xF8);
2794 rt2800_rfcsr_write(rt2x00dev, 32, 0xC0);
2796 rt2800_rfcsr_write(rt2x00dev, 55, 0x06);
2798 rt2800_rfcsr_write(rt2x00dev, 55, 0x47);
2802 rt2800_rfcsr_write(rt2x00dev, 55, 0x03);
2804 rt2800_rfcsr_write(rt2x00dev, 55, 0x43);
2807 power_bound = POWER_BOUND;
2810 rt2800_rfcsr_write(rt2x00dev, 10, 0x97);
2811 /* FIMXE: RF11 overwrite */
2812 rt2800_rfcsr_write(rt2x00dev, 11, 0x40);
2813 rt2800_rfcsr_write(rt2x00dev, 25, 0xBF);
2814 rt2800_rfcsr_write(rt2x00dev, 27, 0x42);
2815 rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
2816 rt2800_rfcsr_write(rt2x00dev, 37, 0x04);
2817 rt2800_rfcsr_write(rt2x00dev, 38, 0x85);
2818 rt2800_rfcsr_write(rt2x00dev, 40, 0x42);
2819 rt2800_rfcsr_write(rt2x00dev, 41, 0xBB);
2820 rt2800_rfcsr_write(rt2x00dev, 42, 0xD7);
2821 rt2800_rfcsr_write(rt2x00dev, 45, 0x41);
2822 rt2800_rfcsr_write(rt2x00dev, 48, 0x00);
2823 rt2800_rfcsr_write(rt2x00dev, 57, 0x77);
2824 rt2800_rfcsr_write(rt2x00dev, 60, 0x05);
2825 rt2800_rfcsr_write(rt2x00dev, 61, 0x01);
2827 /* TODO RF27 <- tssi */
2829 if (rf->channel >= 36 && rf->channel <= 64) {
2831 rt2800_rfcsr_write(rt2x00dev, 12, 0x2E);
2832 rt2800_rfcsr_write(rt2x00dev, 13, 0x22);
2833 rt2800_rfcsr_write(rt2x00dev, 22, 0x60);
2834 rt2800_rfcsr_write(rt2x00dev, 23, 0x7F);
2835 if (rf->channel <= 50)
2836 rt2800_rfcsr_write(rt2x00dev, 24, 0x09);
2837 else if (rf->channel >= 52)
2838 rt2800_rfcsr_write(rt2x00dev, 24, 0x07);
2839 rt2800_rfcsr_write(rt2x00dev, 39, 0x1C);
2840 rt2800_rfcsr_write(rt2x00dev, 43, 0x5B);
2841 rt2800_rfcsr_write(rt2x00dev, 44, 0X40);
2842 rt2800_rfcsr_write(rt2x00dev, 46, 0X00);
2843 rt2800_rfcsr_write(rt2x00dev, 51, 0xFE);
2844 rt2800_rfcsr_write(rt2x00dev, 52, 0x0C);
2845 rt2800_rfcsr_write(rt2x00dev, 54, 0xF8);
2846 if (rf->channel <= 50) {
2847 rt2800_rfcsr_write(rt2x00dev, 55, 0x06),
2848 rt2800_rfcsr_write(rt2x00dev, 56, 0xD3);
2849 } else if (rf->channel >= 52) {
2850 rt2800_rfcsr_write(rt2x00dev, 55, 0x04);
2851 rt2800_rfcsr_write(rt2x00dev, 56, 0xBB);
2854 rt2800_rfcsr_write(rt2x00dev, 58, 0x15);
2855 rt2800_rfcsr_write(rt2x00dev, 59, 0x7F);
2856 rt2800_rfcsr_write(rt2x00dev, 62, 0x15);
2858 } else if (rf->channel >= 100 && rf->channel <= 165) {
2860 rt2800_rfcsr_write(rt2x00dev, 12, 0x0E);
2861 rt2800_rfcsr_write(rt2x00dev, 13, 0x42);
2862 rt2800_rfcsr_write(rt2x00dev, 22, 0x40);
2863 if (rf->channel <= 153) {
2864 rt2800_rfcsr_write(rt2x00dev, 23, 0x3C);
2865 rt2800_rfcsr_write(rt2x00dev, 24, 0x06);
2866 } else if (rf->channel >= 155) {
2867 rt2800_rfcsr_write(rt2x00dev, 23, 0x38);
2868 rt2800_rfcsr_write(rt2x00dev, 24, 0x05);
2870 if (rf->channel <= 138) {
2871 rt2800_rfcsr_write(rt2x00dev, 39, 0x1A);
2872 rt2800_rfcsr_write(rt2x00dev, 43, 0x3B);
2873 rt2800_rfcsr_write(rt2x00dev, 44, 0x20);
2874 rt2800_rfcsr_write(rt2x00dev, 46, 0x18);
2875 } else if (rf->channel >= 140) {
2876 rt2800_rfcsr_write(rt2x00dev, 39, 0x18);
2877 rt2800_rfcsr_write(rt2x00dev, 43, 0x1B);
2878 rt2800_rfcsr_write(rt2x00dev, 44, 0x10);
2879 rt2800_rfcsr_write(rt2x00dev, 46, 0X08);
2881 if (rf->channel <= 124)
2882 rt2800_rfcsr_write(rt2x00dev, 51, 0xFC);
2883 else if (rf->channel >= 126)
2884 rt2800_rfcsr_write(rt2x00dev, 51, 0xEC);
2885 if (rf->channel <= 138)
2886 rt2800_rfcsr_write(rt2x00dev, 52, 0x06);
2887 else if (rf->channel >= 140)
2888 rt2800_rfcsr_write(rt2x00dev, 52, 0x06);
2889 rt2800_rfcsr_write(rt2x00dev, 54, 0xEB);
2890 if (rf->channel <= 138)
2891 rt2800_rfcsr_write(rt2x00dev, 55, 0x01);
2892 else if (rf->channel >= 140)
2893 rt2800_rfcsr_write(rt2x00dev, 55, 0x00);
2894 if (rf->channel <= 128)
2895 rt2800_rfcsr_write(rt2x00dev, 56, 0xBB);
2896 else if (rf->channel >= 130)
2897 rt2800_rfcsr_write(rt2x00dev, 56, 0xAB);
2898 if (rf->channel <= 116)
2899 rt2800_rfcsr_write(rt2x00dev, 58, 0x1D);
2900 else if (rf->channel >= 118)
2901 rt2800_rfcsr_write(rt2x00dev, 58, 0x15);
2902 if (rf->channel <= 138)
2903 rt2800_rfcsr_write(rt2x00dev, 59, 0x3F);
2904 else if (rf->channel >= 140)
2905 rt2800_rfcsr_write(rt2x00dev, 59, 0x7C);
2906 if (rf->channel <= 116)
2907 rt2800_rfcsr_write(rt2x00dev, 62, 0x1D);
2908 else if (rf->channel >= 118)
2909 rt2800_rfcsr_write(rt2x00dev, 62, 0x15);
2912 power_bound = POWER_BOUND_5G;
2916 rt2800_rfcsr_read(rt2x00dev, 49, &rfcsr);
2917 if (info->default_power1 > power_bound)
2918 rt2x00_set_field8(&rfcsr, RFCSR49_TX, power_bound);
2920 rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1);
2922 rt2x00_set_field8(&rfcsr, RFCSR49_EP, ep_reg);
2923 rt2800_rfcsr_write(rt2x00dev, 49, rfcsr);
2925 rt2800_rfcsr_read(rt2x00dev, 50, &rfcsr);
2926 if (info->default_power2 > power_bound)
2927 rt2x00_set_field8(&rfcsr, RFCSR50_TX, power_bound);
2929 rt2x00_set_field8(&rfcsr, RFCSR50_TX, info->default_power2);
2931 rt2x00_set_field8(&rfcsr, RFCSR50_EP, ep_reg);
2932 rt2800_rfcsr_write(rt2x00dev, 50, rfcsr);
2934 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
2935 rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
2936 rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1);
2938 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD,
2939 rt2x00dev->default_ant.tx_chain_num >= 1);
2940 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD,
2941 rt2x00dev->default_ant.tx_chain_num == 2);
2942 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0);
2944 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD,
2945 rt2x00dev->default_ant.rx_chain_num >= 1);
2946 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD,
2947 rt2x00dev->default_ant.rx_chain_num == 2);
2948 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0);
2950 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
2951 rt2800_rfcsr_write(rt2x00dev, 6, 0xe4);
2953 if (conf_is_ht40(conf))
2954 rt2800_rfcsr_write(rt2x00dev, 30, 0x16);
2956 rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
2959 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
2960 rt2800_rfcsr_write(rt2x00dev, 32, 0x80);
2963 /* TODO proper frequency adjustment */
2964 rt2800_adjust_freq_offset(rt2x00dev);
2966 /* TODO merge with others */
2967 rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr);
2968 rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
2969 rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
2972 rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
2973 rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
2974 rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
2976 rt2800_bbp_write(rt2x00dev, 79, (rf->channel <= 14) ? 0x1C : 0x18);
2977 rt2800_bbp_write(rt2x00dev, 80, (rf->channel <= 14) ? 0x0E : 0x08);
2978 rt2800_bbp_write(rt2x00dev, 81, (rf->channel <= 14) ? 0x3A : 0x38);
2979 rt2800_bbp_write(rt2x00dev, 82, (rf->channel <= 14) ? 0x62 : 0x92);
2981 /* GLRT band configuration */
2982 rt2800_bbp_write(rt2x00dev, 195, 128);
2983 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0xE0 : 0xF0);
2984 rt2800_bbp_write(rt2x00dev, 195, 129);
2985 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x1F : 0x1E);
2986 rt2800_bbp_write(rt2x00dev, 195, 130);
2987 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x38 : 0x28);
2988 rt2800_bbp_write(rt2x00dev, 195, 131);
2989 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x32 : 0x20);
2990 rt2800_bbp_write(rt2x00dev, 195, 133);
2991 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x28 : 0x7F);
2992 rt2800_bbp_write(rt2x00dev, 195, 124);
2993 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x19 : 0x7F);
2996 static void rt2800_bbp_write_with_rx_chain(struct rt2x00_dev *rt2x00dev,
2997 const unsigned int word,
3002 for (chain = 0; chain < rt2x00dev->default_ant.rx_chain_num; chain++) {
3003 rt2800_bbp_read(rt2x00dev, 27, ®);
3004 rt2x00_set_field8(®, BBP27_RX_CHAIN_SEL, chain);
3005 rt2800_bbp_write(rt2x00dev, 27, reg);
3007 rt2800_bbp_write(rt2x00dev, word, value);
3011 static void rt2800_iq_calibrate(struct rt2x00_dev *rt2x00dev, int channel)
3016 rt2800_bbp_write(rt2x00dev, 158, 0x2c);
3018 cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_GAIN_CAL_TX0_2G);
3019 else if (channel >= 36 && channel <= 64)
3020 cal = rt2x00_eeprom_byte(rt2x00dev,
3021 EEPROM_IQ_GAIN_CAL_TX0_CH36_TO_CH64_5G);
3022 else if (channel >= 100 && channel <= 138)
3023 cal = rt2x00_eeprom_byte(rt2x00dev,
3024 EEPROM_IQ_GAIN_CAL_TX0_CH100_TO_CH138_5G);
3025 else if (channel >= 140 && channel <= 165)
3026 cal = rt2x00_eeprom_byte(rt2x00dev,
3027 EEPROM_IQ_GAIN_CAL_TX0_CH140_TO_CH165_5G);
3030 rt2800_bbp_write(rt2x00dev, 159, cal);
3033 rt2800_bbp_write(rt2x00dev, 158, 0x2d);
3035 cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_PHASE_CAL_TX0_2G);
3036 else if (channel >= 36 && channel <= 64)
3037 cal = rt2x00_eeprom_byte(rt2x00dev,
3038 EEPROM_IQ_PHASE_CAL_TX0_CH36_TO_CH64_5G);
3039 else if (channel >= 100 && channel <= 138)
3040 cal = rt2x00_eeprom_byte(rt2x00dev,
3041 EEPROM_IQ_PHASE_CAL_TX0_CH100_TO_CH138_5G);
3042 else if (channel >= 140 && channel <= 165)
3043 cal = rt2x00_eeprom_byte(rt2x00dev,
3044 EEPROM_IQ_PHASE_CAL_TX0_CH140_TO_CH165_5G);
3047 rt2800_bbp_write(rt2x00dev, 159, cal);
3050 rt2800_bbp_write(rt2x00dev, 158, 0x4a);
3052 cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_GAIN_CAL_TX1_2G);
3053 else if (channel >= 36 && channel <= 64)
3054 cal = rt2x00_eeprom_byte(rt2x00dev,
3055 EEPROM_IQ_GAIN_CAL_TX1_CH36_TO_CH64_5G);
3056 else if (channel >= 100 && channel <= 138)
3057 cal = rt2x00_eeprom_byte(rt2x00dev,
3058 EEPROM_IQ_GAIN_CAL_TX1_CH100_TO_CH138_5G);
3059 else if (channel >= 140 && channel <= 165)
3060 cal = rt2x00_eeprom_byte(rt2x00dev,
3061 EEPROM_IQ_GAIN_CAL_TX1_CH140_TO_CH165_5G);
3064 rt2800_bbp_write(rt2x00dev, 159, cal);
3067 rt2800_bbp_write(rt2x00dev, 158, 0x4b);
3069 cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_PHASE_CAL_TX1_2G);
3070 else if (channel >= 36 && channel <= 64)
3071 cal = rt2x00_eeprom_byte(rt2x00dev,
3072 EEPROM_IQ_PHASE_CAL_TX1_CH36_TO_CH64_5G);
3073 else if (channel >= 100 && channel <= 138)
3074 cal = rt2x00_eeprom_byte(rt2x00dev,
3075 EEPROM_IQ_PHASE_CAL_TX1_CH100_TO_CH138_5G);
3076 else if (channel >= 140 && channel <= 165)
3077 cal = rt2x00_eeprom_byte(rt2x00dev,
3078 EEPROM_IQ_PHASE_CAL_TX1_CH140_TO_CH165_5G);
3081 rt2800_bbp_write(rt2x00dev, 159, cal);
3083 /* FIXME: possible RX0, RX1 callibration ? */
3085 /* RF IQ compensation control */
3086 rt2800_bbp_write(rt2x00dev, 158, 0x04);
3087 cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_RF_IQ_COMPENSATION_CONTROL);
3088 rt2800_bbp_write(rt2x00dev, 159, cal != 0xff ? cal : 0);
3090 /* RF IQ imbalance compensation control */
3091 rt2800_bbp_write(rt2x00dev, 158, 0x03);
3092 cal = rt2x00_eeprom_byte(rt2x00dev,
3093 EEPROM_RF_IQ_IMBALANCE_COMPENSATION_CONTROL);
3094 rt2800_bbp_write(rt2x00dev, 159, cal != 0xff ? cal : 0);
3097 static char rt2800_txpower_to_dev(struct rt2x00_dev *rt2x00dev,
3098 unsigned int channel,
3101 if (rt2x00_rt(rt2x00dev, RT3593))
3102 txpower = rt2x00_get_field8(txpower, EEPROM_TXPOWER_ALC);
3105 return clamp_t(char, txpower, MIN_G_TXPOWER, MAX_G_TXPOWER);
3107 if (rt2x00_rt(rt2x00dev, RT3593))
3108 return clamp_t(char, txpower, MIN_A_TXPOWER_3593,
3109 MAX_A_TXPOWER_3593);
3111 return clamp_t(char, txpower, MIN_A_TXPOWER, MAX_A_TXPOWER);
3114 static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
3115 struct ieee80211_conf *conf,
3116 struct rf_channel *rf,
3117 struct channel_info *info)
3120 unsigned int tx_pin;
3123 info->default_power1 = rt2800_txpower_to_dev(rt2x00dev, rf->channel,
3124 info->default_power1);
3125 info->default_power2 = rt2800_txpower_to_dev(rt2x00dev, rf->channel,
3126 info->default_power2);
3127 if (rt2x00dev->default_ant.tx_chain_num > 2)
3128 info->default_power3 =
3129 rt2800_txpower_to_dev(rt2x00dev, rf->channel,
3130 info->default_power3);
3132 switch (rt2x00dev->chip.rf) {
3138 rt2800_config_channel_rf3xxx(rt2x00dev, conf, rf, info);
3141 rt2800_config_channel_rf3052(rt2x00dev, conf, rf, info);
3144 rt2800_config_channel_rf3053(rt2x00dev, conf, rf, info);
3147 rt2800_config_channel_rf3290(rt2x00dev, conf, rf, info);
3150 rt2800_config_channel_rf3322(rt2x00dev, conf, rf, info);
3158 rt2800_config_channel_rf53xx(rt2x00dev, conf, rf, info);
3161 rt2800_config_channel_rf55xx(rt2x00dev, conf, rf, info);
3164 rt2800_config_channel_rf2xxx(rt2x00dev, conf, rf, info);
3167 if (rt2x00_rf(rt2x00dev, RF3070) ||
3168 rt2x00_rf(rt2x00dev, RF3290) ||
3169 rt2x00_rf(rt2x00dev, RF3322) ||
3170 rt2x00_rf(rt2x00dev, RF5360) ||
3171 rt2x00_rf(rt2x00dev, RF5370) ||
3172 rt2x00_rf(rt2x00dev, RF5372) ||
3173 rt2x00_rf(rt2x00dev, RF5390) ||
3174 rt2x00_rf(rt2x00dev, RF5392)) {
3175 rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
3176 rt2x00_set_field8(&rfcsr, RFCSR30_TX_H20M, 0);
3177 rt2x00_set_field8(&rfcsr, RFCSR30_RX_H20M, 0);
3178 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
3180 rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr);
3181 rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
3182 rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
3186 * Change BBP settings
3188 if (rt2x00_rt(rt2x00dev, RT3352)) {
3189 rt2800_bbp_write(rt2x00dev, 27, 0x0);
3190 rt2800_bbp_write(rt2x00dev, 66, 0x26 + rt2x00dev->lna_gain);
3191 rt2800_bbp_write(rt2x00dev, 27, 0x20);
3192 rt2800_bbp_write(rt2x00dev, 66, 0x26 + rt2x00dev->lna_gain);
3193 } else if (rt2x00_rt(rt2x00dev, RT3593)) {
3194 if (rf->channel > 14) {
3195 /* Disable CCK Packet detection on 5GHz */
3196 rt2800_bbp_write(rt2x00dev, 70, 0x00);
3198 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
3201 if (conf_is_ht40(conf))
3202 rt2800_bbp_write(rt2x00dev, 105, 0x04);
3204 rt2800_bbp_write(rt2x00dev, 105, 0x34);
3206 rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
3207 rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
3208 rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
3209 rt2800_bbp_write(rt2x00dev, 77, 0x98);
3211 rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
3212 rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
3213 rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
3214 rt2800_bbp_write(rt2x00dev, 86, 0);
3217 if (rf->channel <= 14) {
3218 if (!rt2x00_rt(rt2x00dev, RT5390) &&
3219 !rt2x00_rt(rt2x00dev, RT5392)) {
3220 if (test_bit(CAPABILITY_EXTERNAL_LNA_BG,
3221 &rt2x00dev->cap_flags)) {
3222 rt2800_bbp_write(rt2x00dev, 82, 0x62);
3223 rt2800_bbp_write(rt2x00dev, 75, 0x46);
3225 if (rt2x00_rt(rt2x00dev, RT3593))
3226 rt2800_bbp_write(rt2x00dev, 82, 0x62);
3228 rt2800_bbp_write(rt2x00dev, 82, 0x84);
3229 rt2800_bbp_write(rt2x00dev, 75, 0x50);
3231 if (rt2x00_rt(rt2x00dev, RT3593))
3232 rt2800_bbp_write(rt2x00dev, 83, 0x8a);
3236 if (rt2x00_rt(rt2x00dev, RT3572))
3237 rt2800_bbp_write(rt2x00dev, 82, 0x94);
3238 else if (rt2x00_rt(rt2x00dev, RT3593))
3239 rt2800_bbp_write(rt2x00dev, 82, 0x82);
3241 rt2800_bbp_write(rt2x00dev, 82, 0xf2);
3243 if (rt2x00_rt(rt2x00dev, RT3593))
3244 rt2800_bbp_write(rt2x00dev, 83, 0x9a);
3246 if (test_bit(CAPABILITY_EXTERNAL_LNA_A, &rt2x00dev->cap_flags))
3247 rt2800_bbp_write(rt2x00dev, 75, 0x46);
3249 rt2800_bbp_write(rt2x00dev, 75, 0x50);
3252 rt2800_register_read(rt2x00dev, TX_BAND_CFG, ®);
3253 rt2x00_set_field32(®, TX_BAND_CFG_HT40_MINUS, conf_is_ht40_minus(conf));
3254 rt2x00_set_field32(®, TX_BAND_CFG_A, rf->channel > 14);
3255 rt2x00_set_field32(®, TX_BAND_CFG_BG, rf->channel <= 14);
3256 rt2800_register_write(rt2x00dev, TX_BAND_CFG, reg);
3258 if (rt2x00_rt(rt2x00dev, RT3572))
3259 rt2800_rfcsr_write(rt2x00dev, 8, 0);
3263 switch (rt2x00dev->default_ant.tx_chain_num) {
3265 /* Turn on tertiary PAs */
3266 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A2_EN,
3268 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G2_EN,
3272 /* Turn on secondary PAs */
3273 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN,
3275 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN,
3279 /* Turn on primary PAs */
3280 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN,
3282 if (test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags))
3283 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, 1);
3285 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN,
3290 switch (rt2x00dev->default_ant.rx_chain_num) {
3292 /* Turn on tertiary LNAs */
3293 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A2_EN, 1);
3294 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G2_EN, 1);
3297 /* Turn on secondary LNAs */
3298 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1);
3299 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1);
3302 /* Turn on primary LNAs */
3303 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN, 1);
3304 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN, 1);
3308 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1);
3309 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_TRSW_EN, 1);
3311 rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
3313 if (rt2x00_rt(rt2x00dev, RT3572))
3314 rt2800_rfcsr_write(rt2x00dev, 8, 0x80);
3316 if (rt2x00_rt(rt2x00dev, RT3593)) {
3317 rt2800_register_read(rt2x00dev, GPIO_CTRL, ®);
3319 /* Band selection */
3320 if (rt2x00_is_usb(rt2x00dev) ||
3321 rt2x00_is_pcie(rt2x00dev)) {
3322 /* GPIO #8 controls all paths */
3323 rt2x00_set_field32(®, GPIO_CTRL_DIR8, 0);
3324 if (rf->channel <= 14)
3325 rt2x00_set_field32(®, GPIO_CTRL_VAL8, 1);
3327 rt2x00_set_field32(®, GPIO_CTRL_VAL8, 0);
3330 /* LNA PE control. */
3331 if (rt2x00_is_usb(rt2x00dev)) {
3332 /* GPIO #4 controls PE0 and PE1,
3333 * GPIO #7 controls PE2
3335 rt2x00_set_field32(®, GPIO_CTRL_DIR4, 0);
3336 rt2x00_set_field32(®, GPIO_CTRL_DIR7, 0);
3338 rt2x00_set_field32(®, GPIO_CTRL_VAL4, 1);
3339 rt2x00_set_field32(®, GPIO_CTRL_VAL7, 1);
3340 } else if (rt2x00_is_pcie(rt2x00dev)) {
3341 /* GPIO #4 controls PE0, PE1 and PE2 */
3342 rt2x00_set_field32(®, GPIO_CTRL_DIR4, 0);
3343 rt2x00_set_field32(®, GPIO_CTRL_VAL4, 1);
3346 rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
3349 if (rf->channel <= 14)
3350 reg = 0x1c + 2 * rt2x00dev->lna_gain;
3352 reg = 0x22 + ((rt2x00dev->lna_gain * 5) / 3);
3354 rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, reg);
3356 usleep_range(1000, 1500);
3359 if (rt2x00_rt(rt2x00dev, RT5592)) {
3360 rt2800_bbp_write(rt2x00dev, 195, 141);
3361 rt2800_bbp_write(rt2x00dev, 196, conf_is_ht40(conf) ? 0x10 : 0x1a);
3364 reg = (rf->channel <= 14 ? 0x1c : 0x24) + 2 * rt2x00dev->lna_gain;
3365 rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, reg);
3367 rt2800_iq_calibrate(rt2x00dev, rf->channel);
3370 rt2800_bbp_read(rt2x00dev, 4, &bbp);
3371 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * conf_is_ht40(conf));
3372 rt2800_bbp_write(rt2x00dev, 4, bbp);
3374 rt2800_bbp_read(rt2x00dev, 3, &bbp);
3375 rt2x00_set_field8(&bbp, BBP3_HT40_MINUS, conf_is_ht40_minus(conf));
3376 rt2800_bbp_write(rt2x00dev, 3, bbp);
3378 if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) {
3379 if (conf_is_ht40(conf)) {
3380 rt2800_bbp_write(rt2x00dev, 69, 0x1a);
3381 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
3382 rt2800_bbp_write(rt2x00dev, 73, 0x16);
3384 rt2800_bbp_write(rt2x00dev, 69, 0x16);
3385 rt2800_bbp_write(rt2x00dev, 70, 0x08);
3386 rt2800_bbp_write(rt2x00dev, 73, 0x11);
3393 * Clear channel statistic counters
3395 rt2800_register_read(rt2x00dev, CH_IDLE_STA, ®);
3396 rt2800_register_read(rt2x00dev, CH_BUSY_STA, ®);
3397 rt2800_register_read(rt2x00dev, CH_BUSY_STA_SEC, ®);
3402 if (rt2x00_rt(rt2x00dev, RT3352)) {
3403 rt2800_bbp_read(rt2x00dev, 49, &bbp);
3404 rt2x00_set_field8(&bbp, BBP49_UPDATE_FLAG, 0);
3405 rt2800_bbp_write(rt2x00dev, 49, bbp);
3409 static int rt2800_get_gain_calibration_delta(struct rt2x00_dev *rt2x00dev)
3418 * First check if temperature compensation is supported.
3420 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
3421 if (!rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_EXTERNAL_TX_ALC))
3425 * Read TSSI boundaries for temperature compensation from
3428 * Array idx 0 1 2 3 4 5 6 7 8
3429 * Matching Delta value -4 -3 -2 -1 0 +1 +2 +3 +4
3430 * Example TSSI bounds 0xF0 0xD0 0xB5 0xA0 0x88 0x45 0x25 0x15 0x00
3432 if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) {
3433 rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG1, &eeprom);
3434 tssi_bounds[0] = rt2x00_get_field16(eeprom,
3435 EEPROM_TSSI_BOUND_BG1_MINUS4);
3436 tssi_bounds[1] = rt2x00_get_field16(eeprom,
3437 EEPROM_TSSI_BOUND_BG1_MINUS3);
3439 rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG2, &eeprom);
3440 tssi_bounds[2] = rt2x00_get_field16(eeprom,
3441 EEPROM_TSSI_BOUND_BG2_MINUS2);
3442 tssi_bounds[3] = rt2x00_get_field16(eeprom,
3443 EEPROM_TSSI_BOUND_BG2_MINUS1);
3445 rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG3, &eeprom);
3446 tssi_bounds[4] = rt2x00_get_field16(eeprom,
3447 EEPROM_TSSI_BOUND_BG3_REF);
3448 tssi_bounds[5] = rt2x00_get_field16(eeprom,
3449 EEPROM_TSSI_BOUND_BG3_PLUS1);
3451 rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG4, &eeprom);
3452 tssi_bounds[6] = rt2x00_get_field16(eeprom,
3453 EEPROM_TSSI_BOUND_BG4_PLUS2);
3454 tssi_bounds[7] = rt2x00_get_field16(eeprom,
3455 EEPROM_TSSI_BOUND_BG4_PLUS3);
3457 rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG5, &eeprom);
3458 tssi_bounds[8] = rt2x00_get_field16(eeprom,
3459 EEPROM_TSSI_BOUND_BG5_PLUS4);
3461 step = rt2x00_get_field16(eeprom,
3462 EEPROM_TSSI_BOUND_BG5_AGC_STEP);
3464 rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A1, &eeprom);
3465 tssi_bounds[0] = rt2x00_get_field16(eeprom,
3466 EEPROM_TSSI_BOUND_A1_MINUS4);
3467 tssi_bounds[1] = rt2x00_get_field16(eeprom,
3468 EEPROM_TSSI_BOUND_A1_MINUS3);
3470 rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A2, &eeprom);
3471 tssi_bounds[2] = rt2x00_get_field16(eeprom,
3472 EEPROM_TSSI_BOUND_A2_MINUS2);
3473 tssi_bounds[3] = rt2x00_get_field16(eeprom,
3474 EEPROM_TSSI_BOUND_A2_MINUS1);
3476 rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A3, &eeprom);
3477 tssi_bounds[4] = rt2x00_get_field16(eeprom,
3478 EEPROM_TSSI_BOUND_A3_REF);
3479 tssi_bounds[5] = rt2x00_get_field16(eeprom,
3480 EEPROM_TSSI_BOUND_A3_PLUS1);
3482 rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A4, &eeprom);
3483 tssi_bounds[6] = rt2x00_get_field16(eeprom,
3484 EEPROM_TSSI_BOUND_A4_PLUS2);
3485 tssi_bounds[7] = rt2x00_get_field16(eeprom,
3486 EEPROM_TSSI_BOUND_A4_PLUS3);
3488 rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A5, &eeprom);
3489 tssi_bounds[8] = rt2x00_get_field16(eeprom,
3490 EEPROM_TSSI_BOUND_A5_PLUS4);
3492 step = rt2x00_get_field16(eeprom,
3493 EEPROM_TSSI_BOUND_A5_AGC_STEP);
3497 * Check if temperature compensation is supported.
3499 if (tssi_bounds[4] == 0xff || step == 0xff)
3503 * Read current TSSI (BBP 49).
3505 rt2800_bbp_read(rt2x00dev, 49, ¤t_tssi);
3508 * Compare TSSI value (BBP49) with the compensation boundaries
3509 * from the EEPROM and increase or decrease tx power.
3511 for (i = 0; i <= 3; i++) {
3512 if (current_tssi > tssi_bounds[i])
3517 for (i = 8; i >= 5; i--) {
3518 if (current_tssi < tssi_bounds[i])
3523 return (i - 4) * step;
3526 static int rt2800_get_txpower_bw_comp(struct rt2x00_dev *rt2x00dev,
3527 enum ieee80211_band band)
3534 rt2800_eeprom_read(rt2x00dev, EEPROM_TXPOWER_DELTA, &eeprom);
3537 * HT40 compensation not required.
3539 if (eeprom == 0xffff ||
3540 !test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
3543 if (band == IEEE80211_BAND_2GHZ) {
3544 comp_en = rt2x00_get_field16(eeprom,
3545 EEPROM_TXPOWER_DELTA_ENABLE_2G);
3547 comp_type = rt2x00_get_field16(eeprom,
3548 EEPROM_TXPOWER_DELTA_TYPE_2G);
3549 comp_value = rt2x00_get_field16(eeprom,
3550 EEPROM_TXPOWER_DELTA_VALUE_2G);
3552 comp_value = -comp_value;
3555 comp_en = rt2x00_get_field16(eeprom,
3556 EEPROM_TXPOWER_DELTA_ENABLE_5G);
3558 comp_type = rt2x00_get_field16(eeprom,
3559 EEPROM_TXPOWER_DELTA_TYPE_5G);
3560 comp_value = rt2x00_get_field16(eeprom,
3561 EEPROM_TXPOWER_DELTA_VALUE_5G);
3563 comp_value = -comp_value;
3570 static int rt2800_get_txpower_reg_delta(struct rt2x00_dev *rt2x00dev,
3571 int power_level, int max_power)
3575 if (test_bit(CAPABILITY_POWER_LIMIT, &rt2x00dev->cap_flags))
3579 * XXX: We don't know the maximum transmit power of our hardware since
3580 * the EEPROM doesn't expose it. We only know that we are calibrated
3583 * Hence, we assume the regulatory limit that cfg80211 calulated for
3584 * the current channel is our maximum and if we are requested to lower
3585 * the value we just reduce our tx power accordingly.
3587 delta = power_level - max_power;
3588 return min(delta, 0);
3591 static u8 rt2800_compensate_txpower(struct rt2x00_dev *rt2x00dev, int is_rate_b,
3592 enum ieee80211_band band, int power_level,
3593 u8 txpower, int delta)
3598 u8 eirp_txpower_criterion;
3601 if (rt2x00_rt(rt2x00dev, RT3593))
3602 return min_t(u8, txpower, 0xc);
3604 if (test_bit(CAPABILITY_POWER_LIMIT, &rt2x00dev->cap_flags)) {
3606 * Check if eirp txpower exceed txpower_limit.
3607 * We use OFDM 6M as criterion and its eirp txpower
3608 * is stored at EEPROM_EIRP_MAX_TX_POWER.
3609 * .11b data rate need add additional 4dbm
3610 * when calculating eirp txpower.
3612 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
3614 criterion = rt2x00_get_field16(eeprom,
3615 EEPROM_TXPOWER_BYRATE_RATE0);
3617 rt2800_eeprom_read(rt2x00dev, EEPROM_EIRP_MAX_TX_POWER,
3620 if (band == IEEE80211_BAND_2GHZ)
3621 eirp_txpower_criterion = rt2x00_get_field16(eeprom,
3622 EEPROM_EIRP_MAX_TX_POWER_2GHZ);
3624 eirp_txpower_criterion = rt2x00_get_field16(eeprom,
3625 EEPROM_EIRP_MAX_TX_POWER_5GHZ);
3627 eirp_txpower = eirp_txpower_criterion + (txpower - criterion) +
3628 (is_rate_b ? 4 : 0) + delta;
3630 reg_limit = (eirp_txpower > power_level) ?
3631 (eirp_txpower - power_level) : 0;
3635 txpower = max(0, txpower + delta - reg_limit);
3636 return min_t(u8, txpower, 0xc);
3651 TX_PWR_CFG_0_EXT_IDX,
3652 TX_PWR_CFG_1_EXT_IDX,
3653 TX_PWR_CFG_2_EXT_IDX,
3654 TX_PWR_CFG_3_EXT_IDX,
3655 TX_PWR_CFG_4_EXT_IDX,
3656 TX_PWR_CFG_IDX_COUNT,
3659 static void rt2800_config_txpower_rt3593(struct rt2x00_dev *rt2x00dev,
3660 struct ieee80211_channel *chan,
3665 u32 regs[TX_PWR_CFG_IDX_COUNT];
3666 unsigned int offset;
3667 enum ieee80211_band band = chan->band;
3671 memset(regs, '\0', sizeof(regs));
3673 /* TODO: adapt TX power reduction from the rt28xx code */
3675 /* calculate temperature compensation delta */
3676 delta = rt2800_get_gain_calibration_delta(rt2x00dev);
3678 if (band == IEEE80211_BAND_5GHZ)
3683 if (test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
3686 /* read the next four txpower values */
3687 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
3691 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
3692 txpower = rt2800_compensate_txpower(rt2x00dev, 1, band, power_level,
3694 rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX],
3695 TX_PWR_CFG_0_CCK1_CH0, txpower);
3696 rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX],
3697 TX_PWR_CFG_0_CCK1_CH1, txpower);
3698 rt2x00_set_field32(®s[TX_PWR_CFG_0_EXT_IDX],
3699 TX_PWR_CFG_0_EXT_CCK1_CH2, txpower);
3701 /* CCK 5.5MBS,11MBS */
3702 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1);
3703 txpower = rt2800_compensate_txpower(rt2x00dev, 1, band, power_level,
3705 rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX],
3706 TX_PWR_CFG_0_CCK5_CH0, txpower);
3707 rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX],
3708 TX_PWR_CFG_0_CCK5_CH1, txpower);
3709 rt2x00_set_field32(®s[TX_PWR_CFG_0_EXT_IDX],
3710 TX_PWR_CFG_0_EXT_CCK5_CH2, txpower);
3712 /* OFDM 6MBS,9MBS */
3713 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2);
3714 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3716 rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX],
3717 TX_PWR_CFG_0_OFDM6_CH0, txpower);
3718 rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX],
3719 TX_PWR_CFG_0_OFDM6_CH1, txpower);
3720 rt2x00_set_field32(®s[TX_PWR_CFG_0_EXT_IDX],
3721 TX_PWR_CFG_0_EXT_OFDM6_CH2, txpower);
3723 /* OFDM 12MBS,18MBS */
3724 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3);
3725 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3727 rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX],
3728 TX_PWR_CFG_0_OFDM12_CH0, txpower);
3729 rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX],
3730 TX_PWR_CFG_0_OFDM12_CH1, txpower);
3731 rt2x00_set_field32(®s[TX_PWR_CFG_0_EXT_IDX],
3732 TX_PWR_CFG_0_EXT_OFDM12_CH2, txpower);
3734 /* read the next four txpower values */
3735 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
3736 offset + 1, &eeprom);
3738 /* OFDM 24MBS,36MBS */
3739 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
3740 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3742 rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX],
3743 TX_PWR_CFG_1_OFDM24_CH0, txpower);
3744 rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX],
3745 TX_PWR_CFG_1_OFDM24_CH1, txpower);
3746 rt2x00_set_field32(®s[TX_PWR_CFG_1_EXT_IDX],
3747 TX_PWR_CFG_1_EXT_OFDM24_CH2, txpower);
3750 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1);
3751 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3753 rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX],
3754 TX_PWR_CFG_1_OFDM48_CH0, txpower);
3755 rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX],
3756 TX_PWR_CFG_1_OFDM48_CH1, txpower);
3757 rt2x00_set_field32(®s[TX_PWR_CFG_1_EXT_IDX],
3758 TX_PWR_CFG_1_EXT_OFDM48_CH2, txpower);
3761 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2);
3762 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3764 rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX],
3765 TX_PWR_CFG_7_OFDM54_CH0, txpower);
3766 rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX],
3767 TX_PWR_CFG_7_OFDM54_CH1, txpower);
3768 rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX],
3769 TX_PWR_CFG_7_OFDM54_CH2, txpower);
3771 /* read the next four txpower values */
3772 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
3773 offset + 2, &eeprom);
3776 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
3777 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3779 rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX],
3780 TX_PWR_CFG_1_MCS0_CH0, txpower);
3781 rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX],
3782 TX_PWR_CFG_1_MCS0_CH1, txpower);
3783 rt2x00_set_field32(®s[TX_PWR_CFG_1_EXT_IDX],
3784 TX_PWR_CFG_1_EXT_MCS0_CH2, txpower);
3787 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1);
3788 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3790 rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX],
3791 TX_PWR_CFG_1_MCS2_CH0, txpower);
3792 rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX],
3793 TX_PWR_CFG_1_MCS2_CH1, txpower);
3794 rt2x00_set_field32(®s[TX_PWR_CFG_1_EXT_IDX],
3795 TX_PWR_CFG_1_EXT_MCS2_CH2, txpower);
3798 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2);
3799 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3801 rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX],
3802 TX_PWR_CFG_2_MCS4_CH0, txpower);
3803 rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX],
3804 TX_PWR_CFG_2_MCS4_CH1, txpower);
3805 rt2x00_set_field32(®s[TX_PWR_CFG_2_EXT_IDX],
3806 TX_PWR_CFG_2_EXT_MCS4_CH2, txpower);
3809 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3);
3810 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3812 rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX],
3813 TX_PWR_CFG_2_MCS6_CH0, txpower);
3814 rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX],
3815 TX_PWR_CFG_2_MCS6_CH1, txpower);
3816 rt2x00_set_field32(®s[TX_PWR_CFG_2_EXT_IDX],
3817 TX_PWR_CFG_2_EXT_MCS6_CH2, txpower);
3819 /* read the next four txpower values */
3820 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
3821 offset + 3, &eeprom);
3824 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
3825 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3827 rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX],
3828 TX_PWR_CFG_7_MCS7_CH0, txpower);
3829 rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX],
3830 TX_PWR_CFG_7_MCS7_CH1, txpower);
3831 rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX],
3832 TX_PWR_CFG_7_MCS7_CH2, txpower);
3835 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1);
3836 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3838 rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX],
3839 TX_PWR_CFG_2_MCS8_CH0, txpower);
3840 rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX],
3841 TX_PWR_CFG_2_MCS8_CH1, txpower);
3842 rt2x00_set_field32(®s[TX_PWR_CFG_2_EXT_IDX],
3843 TX_PWR_CFG_2_EXT_MCS8_CH2, txpower);
3846 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2);
3847 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3849 rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX],
3850 TX_PWR_CFG_2_MCS10_CH0, txpower);
3851 rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX],
3852 TX_PWR_CFG_2_MCS10_CH1, txpower);
3853 rt2x00_set_field32(®s[TX_PWR_CFG_2_EXT_IDX],
3854 TX_PWR_CFG_2_EXT_MCS10_CH2, txpower);
3857 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3);
3858 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3860 rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX],
3861 TX_PWR_CFG_3_MCS12_CH0, txpower);
3862 rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX],
3863 TX_PWR_CFG_3_MCS12_CH1, txpower);
3864 rt2x00_set_field32(®s[TX_PWR_CFG_3_EXT_IDX],
3865 TX_PWR_CFG_3_EXT_MCS12_CH2, txpower);
3867 /* read the next four txpower values */
3868 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
3869 offset + 4, &eeprom);
3872 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
3873 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3875 rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX],
3876 TX_PWR_CFG_3_MCS14_CH0, txpower);
3877 rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX],
3878 TX_PWR_CFG_3_MCS14_CH1, txpower);
3879 rt2x00_set_field32(®s[TX_PWR_CFG_3_EXT_IDX],
3880 TX_PWR_CFG_3_EXT_MCS14_CH2, txpower);
3883 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1);
3884 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3886 rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX],
3887 TX_PWR_CFG_8_MCS15_CH0, txpower);
3888 rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX],
3889 TX_PWR_CFG_8_MCS15_CH1, txpower);
3890 rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX],
3891 TX_PWR_CFG_8_MCS15_CH2, txpower);
3894 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2);
3895 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3897 rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX],
3898 TX_PWR_CFG_5_MCS16_CH0, txpower);
3899 rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX],
3900 TX_PWR_CFG_5_MCS16_CH1, txpower);
3901 rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX],
3902 TX_PWR_CFG_5_MCS16_CH2, txpower);
3905 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3);
3906 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3908 rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX],
3909 TX_PWR_CFG_5_MCS18_CH0, txpower);
3910 rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX],
3911 TX_PWR_CFG_5_MCS18_CH1, txpower);
3912 rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX],
3913 TX_PWR_CFG_5_MCS18_CH2, txpower);
3915 /* read the next four txpower values */
3916 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
3917 offset + 5, &eeprom);
3920 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
3921 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3923 rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX],
3924 TX_PWR_CFG_6_MCS20_CH0, txpower);
3925 rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX],
3926 TX_PWR_CFG_6_MCS20_CH1, txpower);
3927 rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX],
3928 TX_PWR_CFG_6_MCS20_CH2, txpower);
3931 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1);
3932 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3934 rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX],
3935 TX_PWR_CFG_6_MCS22_CH0, txpower);
3936 rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX],
3937 TX_PWR_CFG_6_MCS22_CH1, txpower);
3938 rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX],
3939 TX_PWR_CFG_6_MCS22_CH2, txpower);
3942 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2);
3943 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3945 rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX],
3946 TX_PWR_CFG_8_MCS23_CH0, txpower);
3947 rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX],
3948 TX_PWR_CFG_8_MCS23_CH1, txpower);
3949 rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX],
3950 TX_PWR_CFG_8_MCS23_CH2, txpower);
3952 /* read the next four txpower values */
3953 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
3954 offset + 6, &eeprom);
3957 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
3958 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3960 rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX],
3961 TX_PWR_CFG_3_STBC0_CH0, txpower);
3962 rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX],
3963 TX_PWR_CFG_3_STBC0_CH1, txpower);
3964 rt2x00_set_field32(®s[TX_PWR_CFG_3_EXT_IDX],
3965 TX_PWR_CFG_3_EXT_STBC0_CH2, txpower);
3968 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1);
3969 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3971 rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX],
3972 TX_PWR_CFG_3_STBC2_CH0, txpower);
3973 rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX],
3974 TX_PWR_CFG_3_STBC2_CH1, txpower);
3975 rt2x00_set_field32(®s[TX_PWR_CFG_3_EXT_IDX],
3976 TX_PWR_CFG_3_EXT_STBC2_CH2, txpower);
3979 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2);
3980 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3982 rt2x00_set_field32(®s[TX_PWR_CFG_4_IDX], TX_PWR_CFG_RATE0, txpower);
3983 rt2x00_set_field32(®s[TX_PWR_CFG_4_IDX], TX_PWR_CFG_RATE1, txpower);
3984 rt2x00_set_field32(®s[TX_PWR_CFG_4_EXT_IDX], TX_PWR_CFG_RATE0,
3988 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3);
3989 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3991 rt2x00_set_field32(®s[TX_PWR_CFG_4_IDX], TX_PWR_CFG_RATE2, txpower);
3992 rt2x00_set_field32(®s[TX_PWR_CFG_4_IDX], TX_PWR_CFG_RATE3, txpower);
3993 rt2x00_set_field32(®s[TX_PWR_CFG_4_EXT_IDX], TX_PWR_CFG_RATE2,
3996 /* read the next four txpower values */
3997 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
3998 offset + 7, &eeprom);
4001 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
4002 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4004 rt2x00_set_field32(®s[TX_PWR_CFG_9_IDX],
4005 TX_PWR_CFG_9_STBC7_CH0, txpower);
4006 rt2x00_set_field32(®s[TX_PWR_CFG_9_IDX],
4007 TX_PWR_CFG_9_STBC7_CH1, txpower);
4008 rt2x00_set_field32(®s[TX_PWR_CFG_9_IDX],
4009 TX_PWR_CFG_9_STBC7_CH2, txpower);
4011 rt2800_register_write(rt2x00dev, TX_PWR_CFG_0, regs[TX_PWR_CFG_0_IDX]);
4012 rt2800_register_write(rt2x00dev, TX_PWR_CFG_1, regs[TX_PWR_CFG_1_IDX]);
4013 rt2800_register_write(rt2x00dev, TX_PWR_CFG_2, regs[TX_PWR_CFG_2_IDX]);
4014 rt2800_register_write(rt2x00dev, TX_PWR_CFG_3, regs[TX_PWR_CFG_3_IDX]);
4015 rt2800_register_write(rt2x00dev, TX_PWR_CFG_4, regs[TX_PWR_CFG_4_IDX]);
4016 rt2800_register_write(rt2x00dev, TX_PWR_CFG_5, regs[TX_PWR_CFG_5_IDX]);
4017 rt2800_register_write(rt2x00dev, TX_PWR_CFG_6, regs[TX_PWR_CFG_6_IDX]);
4018 rt2800_register_write(rt2x00dev, TX_PWR_CFG_7, regs[TX_PWR_CFG_7_IDX]);
4019 rt2800_register_write(rt2x00dev, TX_PWR_CFG_8, regs[TX_PWR_CFG_8_IDX]);
4020 rt2800_register_write(rt2x00dev, TX_PWR_CFG_9, regs[TX_PWR_CFG_9_IDX]);
4022 rt2800_register_write(rt2x00dev, TX_PWR_CFG_0_EXT,
4023 regs[TX_PWR_CFG_0_EXT_IDX]);
4024 rt2800_register_write(rt2x00dev, TX_PWR_CFG_1_EXT,
4025 regs[TX_PWR_CFG_1_EXT_IDX]);
4026 rt2800_register_write(rt2x00dev, TX_PWR_CFG_2_EXT,
4027 regs[TX_PWR_CFG_2_EXT_IDX]);
4028 rt2800_register_write(rt2x00dev, TX_PWR_CFG_3_EXT,
4029 regs[TX_PWR_CFG_3_EXT_IDX]);
4030 rt2800_register_write(rt2x00dev, TX_PWR_CFG_4_EXT,
4031 regs[TX_PWR_CFG_4_EXT_IDX]);
4033 for (i = 0; i < TX_PWR_CFG_IDX_COUNT; i++)
4034 rt2x00_dbg(rt2x00dev,
4035 "band:%cGHz, BW:%c0MHz, TX_PWR_CFG_%d%s = %08lx\n",
4036 (band == IEEE80211_BAND_5GHZ) ? '5' : '2',
4037 (test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags)) ?
4039 (i > TX_PWR_CFG_9_IDX) ?
4040 (i - TX_PWR_CFG_9_IDX - 1) : i,
4041 (i > TX_PWR_CFG_9_IDX) ? "_EXT" : "",
4042 (unsigned long) regs[i]);
4046 * We configure transmit power using MAC TX_PWR_CFG_{0,...,N} registers and
4047 * BBP R1 register. TX_PWR_CFG_X allow to configure per rate TX power values,
4048 * 4 bits for each rate (tune from 0 to 15 dBm). BBP_R1 controls transmit power
4049 * for all rates, but allow to set only 4 discrete values: -12, -6, 0 and 6 dBm.
4050 * Reference per rate transmit power values are located in the EEPROM at
4051 * EEPROM_TXPOWER_BYRATE offset. We adjust them and BBP R1 settings according to
4052 * current conditions (i.e. band, bandwidth, temperature, user settings).
4054 static void rt2800_config_txpower_rt28xx(struct rt2x00_dev *rt2x00dev,
4055 struct ieee80211_channel *chan,
4061 int i, is_rate_b, delta, power_ctrl;
4062 enum ieee80211_band band = chan->band;
4065 * Calculate HT40 compensation. For 40MHz we need to add or subtract
4066 * value read from EEPROM (different for 2GHz and for 5GHz).
4068 delta = rt2800_get_txpower_bw_comp(rt2x00dev, band);
4071 * Calculate temperature compensation. Depends on measurement of current
4072 * TSSI (Transmitter Signal Strength Indication) we know TX power (due
4073 * to temperature or maybe other factors) is smaller or bigger than
4074 * expected. We adjust it, based on TSSI reference and boundaries values
4075 * provided in EEPROM.
4077 delta += rt2800_get_gain_calibration_delta(rt2x00dev);
4080 * Decrease power according to user settings, on devices with unknown
4081 * maximum tx power. For other devices we take user power_level into
4082 * consideration on rt2800_compensate_txpower().
4084 delta += rt2800_get_txpower_reg_delta(rt2x00dev, power_level,
4088 * BBP_R1 controls TX power for all rates, it allow to set the following
4089 * gains -12, -6, 0, +6 dBm by setting values 2, 1, 0, 3 respectively.
4091 * TODO: we do not use +6 dBm option to do not increase power beyond
4092 * regulatory limit, however this could be utilized for devices with
4093 * CAPABILITY_POWER_LIMIT.
4095 * TODO: add different temperature compensation code for RT3290 & RT5390
4096 * to allow to use BBP_R1 for those chips.
4098 if (!rt2x00_rt(rt2x00dev, RT3290) &&
4099 !rt2x00_rt(rt2x00dev, RT5390)) {
4100 rt2800_bbp_read(rt2x00dev, 1, &r1);
4104 } else if (delta <= -6) {
4110 rt2x00_set_field8(&r1, BBP1_TX_POWER_CTRL, power_ctrl);
4111 rt2800_bbp_write(rt2x00dev, 1, r1);
4114 offset = TX_PWR_CFG_0;
4116 for (i = 0; i < EEPROM_TXPOWER_BYRATE_SIZE; i += 2) {
4117 /* just to be safe */
4118 if (offset > TX_PWR_CFG_4)
4121 rt2800_register_read(rt2x00dev, offset, ®);
4123 /* read the next four txpower values */
4124 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
4127 is_rate_b = i ? 0 : 1;
4129 * TX_PWR_CFG_0: 1MBS, TX_PWR_CFG_1: 24MBS,
4130 * TX_PWR_CFG_2: MCS4, TX_PWR_CFG_3: MCS12,
4131 * TX_PWR_CFG_4: unknown
4133 txpower = rt2x00_get_field16(eeprom,
4134 EEPROM_TXPOWER_BYRATE_RATE0);
4135 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4136 power_level, txpower, delta);
4137 rt2x00_set_field32(®, TX_PWR_CFG_RATE0, txpower);
4140 * TX_PWR_CFG_0: 2MBS, TX_PWR_CFG_1: 36MBS,
4141 * TX_PWR_CFG_2: MCS5, TX_PWR_CFG_3: MCS13,
4142 * TX_PWR_CFG_4: unknown
4144 txpower = rt2x00_get_field16(eeprom,
4145 EEPROM_TXPOWER_BYRATE_RATE1);
4146 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4147 power_level, txpower, delta);
4148 rt2x00_set_field32(®, TX_PWR_CFG_RATE1, txpower);
4151 * TX_PWR_CFG_0: 5.5MBS, TX_PWR_CFG_1: 48MBS,
4152 * TX_PWR_CFG_2: MCS6, TX_PWR_CFG_3: MCS14,
4153 * TX_PWR_CFG_4: unknown
4155 txpower = rt2x00_get_field16(eeprom,
4156 EEPROM_TXPOWER_BYRATE_RATE2);
4157 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4158 power_level, txpower, delta);
4159 rt2x00_set_field32(®, TX_PWR_CFG_RATE2, txpower);
4162 * TX_PWR_CFG_0: 11MBS, TX_PWR_CFG_1: 54MBS,
4163 * TX_PWR_CFG_2: MCS7, TX_PWR_CFG_3: MCS15,
4164 * TX_PWR_CFG_4: unknown
4166 txpower = rt2x00_get_field16(eeprom,
4167 EEPROM_TXPOWER_BYRATE_RATE3);
4168 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4169 power_level, txpower, delta);
4170 rt2x00_set_field32(®, TX_PWR_CFG_RATE3, txpower);
4172 /* read the next four txpower values */
4173 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
4178 * TX_PWR_CFG_0: 6MBS, TX_PWR_CFG_1: MCS0,
4179 * TX_PWR_CFG_2: MCS8, TX_PWR_CFG_3: unknown,
4180 * TX_PWR_CFG_4: unknown
4182 txpower = rt2x00_get_field16(eeprom,
4183 EEPROM_TXPOWER_BYRATE_RATE0);
4184 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4185 power_level, txpower, delta);
4186 rt2x00_set_field32(®, TX_PWR_CFG_RATE4, txpower);
4189 * TX_PWR_CFG_0: 9MBS, TX_PWR_CFG_1: MCS1,
4190 * TX_PWR_CFG_2: MCS9, TX_PWR_CFG_3: unknown,
4191 * TX_PWR_CFG_4: unknown
4193 txpower = rt2x00_get_field16(eeprom,
4194 EEPROM_TXPOWER_BYRATE_RATE1);
4195 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4196 power_level, txpower, delta);
4197 rt2x00_set_field32(®, TX_PWR_CFG_RATE5, txpower);
4200 * TX_PWR_CFG_0: 12MBS, TX_PWR_CFG_1: MCS2,
4201 * TX_PWR_CFG_2: MCS10, TX_PWR_CFG_3: unknown,
4202 * TX_PWR_CFG_4: unknown
4204 txpower = rt2x00_get_field16(eeprom,
4205 EEPROM_TXPOWER_BYRATE_RATE2);
4206 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4207 power_level, txpower, delta);
4208 rt2x00_set_field32(®, TX_PWR_CFG_RATE6, txpower);
4211 * TX_PWR_CFG_0: 18MBS, TX_PWR_CFG_1: MCS3,
4212 * TX_PWR_CFG_2: MCS11, TX_PWR_CFG_3: unknown,
4213 * TX_PWR_CFG_4: unknown
4215 txpower = rt2x00_get_field16(eeprom,
4216 EEPROM_TXPOWER_BYRATE_RATE3);
4217 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4218 power_level, txpower, delta);
4219 rt2x00_set_field32(®, TX_PWR_CFG_RATE7, txpower);
4221 rt2800_register_write(rt2x00dev, offset, reg);
4223 /* next TX_PWR_CFG register */
4228 static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev,
4229 struct ieee80211_channel *chan,
4232 if (rt2x00_rt(rt2x00dev, RT3593))
4233 rt2800_config_txpower_rt3593(rt2x00dev, chan, power_level);
4235 rt2800_config_txpower_rt28xx(rt2x00dev, chan, power_level);
4238 void rt2800_gain_calibration(struct rt2x00_dev *rt2x00dev)
4240 rt2800_config_txpower(rt2x00dev, rt2x00dev->hw->conf.chandef.chan,
4241 rt2x00dev->tx_power);
4243 EXPORT_SYMBOL_GPL(rt2800_gain_calibration);
4245 void rt2800_vco_calibration(struct rt2x00_dev *rt2x00dev)
4251 * A voltage-controlled oscillator(VCO) is an electronic oscillator
4252 * designed to be controlled in oscillation frequency by a voltage
4253 * input. Maybe the temperature will affect the frequency of
4254 * oscillation to be shifted. The VCO calibration will be called
4255 * periodically to adjust the frequency to be precision.
4258 rt2800_register_read(rt2x00dev, TX_PIN_CFG, &tx_pin);
4259 tx_pin &= TX_PIN_CFG_PA_PE_DISABLE;
4260 rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
4262 switch (rt2x00dev->chip.rf) {
4269 rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr);
4270 rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
4271 rt2800_rfcsr_write(rt2x00dev, 7, rfcsr);
4281 rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr);
4282 rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
4283 rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
4291 rt2800_register_read(rt2x00dev, TX_PIN_CFG, &tx_pin);
4292 if (rt2x00dev->rf_channel <= 14) {
4293 switch (rt2x00dev->default_ant.tx_chain_num) {
4295 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G2_EN, 1);
4298 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1);
4302 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, 1);
4306 switch (rt2x00dev->default_ant.tx_chain_num) {
4308 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A2_EN, 1);
4311 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1);
4315 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, 1);
4319 rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
4322 EXPORT_SYMBOL_GPL(rt2800_vco_calibration);
4324 static void rt2800_config_retry_limit(struct rt2x00_dev *rt2x00dev,
4325 struct rt2x00lib_conf *libconf)
4329 rt2800_register_read(rt2x00dev, TX_RTY_CFG, ®);
4330 rt2x00_set_field32(®, TX_RTY_CFG_SHORT_RTY_LIMIT,
4331 libconf->conf->short_frame_max_tx_count);
4332 rt2x00_set_field32(®, TX_RTY_CFG_LONG_RTY_LIMIT,
4333 libconf->conf->long_frame_max_tx_count);
4334 rt2800_register_write(rt2x00dev, TX_RTY_CFG, reg);
4337 static void rt2800_config_ps(struct rt2x00_dev *rt2x00dev,
4338 struct rt2x00lib_conf *libconf)
4340 enum dev_state state =
4341 (libconf->conf->flags & IEEE80211_CONF_PS) ?
4342 STATE_SLEEP : STATE_AWAKE;
4345 if (state == STATE_SLEEP) {
4346 rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0);
4348 rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG, ®);
4349 rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 5);
4350 rt2x00_set_field32(®, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE,
4351 libconf->conf->listen_interval - 1);
4352 rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTOWAKE, 1);
4353 rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
4355 rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
4357 rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG, ®);
4358 rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 0);
4359 rt2x00_set_field32(®, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE, 0);
4360 rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTOWAKE, 0);
4361 rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
4363 rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
4367 void rt2800_config(struct rt2x00_dev *rt2x00dev,
4368 struct rt2x00lib_conf *libconf,
4369 const unsigned int flags)
4371 /* Always recalculate LNA gain before changing configuration */
4372 rt2800_config_lna_gain(rt2x00dev, libconf);
4374 if (flags & IEEE80211_CONF_CHANGE_CHANNEL) {
4375 rt2800_config_channel(rt2x00dev, libconf->conf,
4376 &libconf->rf, &libconf->channel);
4377 rt2800_config_txpower(rt2x00dev, libconf->conf->chandef.chan,
4378 libconf->conf->power_level);
4380 if (flags & IEEE80211_CONF_CHANGE_POWER)
4381 rt2800_config_txpower(rt2x00dev, libconf->conf->chandef.chan,
4382 libconf->conf->power_level);
4383 if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
4384 rt2800_config_retry_limit(rt2x00dev, libconf);
4385 if (flags & IEEE80211_CONF_CHANGE_PS)
4386 rt2800_config_ps(rt2x00dev, libconf);
4388 EXPORT_SYMBOL_GPL(rt2800_config);
4393 void rt2800_link_stats(struct rt2x00_dev *rt2x00dev, struct link_qual *qual)
4398 * Update FCS error count from register.
4400 rt2800_register_read(rt2x00dev, RX_STA_CNT0, ®);
4401 qual->rx_failed = rt2x00_get_field32(reg, RX_STA_CNT0_CRC_ERR);
4403 EXPORT_SYMBOL_GPL(rt2800_link_stats);
4405 static u8 rt2800_get_default_vgc(struct rt2x00_dev *rt2x00dev)
4409 if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) {
4410 if (rt2x00_rt(rt2x00dev, RT3070) ||
4411 rt2x00_rt(rt2x00dev, RT3071) ||
4412 rt2x00_rt(rt2x00dev, RT3090) ||
4413 rt2x00_rt(rt2x00dev, RT3290) ||
4414 rt2x00_rt(rt2x00dev, RT3390) ||
4415 rt2x00_rt(rt2x00dev, RT3572) ||
4416 rt2x00_rt(rt2x00dev, RT3593) ||
4417 rt2x00_rt(rt2x00dev, RT5390) ||
4418 rt2x00_rt(rt2x00dev, RT5392) ||
4419 rt2x00_rt(rt2x00dev, RT5592))
4420 vgc = 0x1c + (2 * rt2x00dev->lna_gain);
4422 vgc = 0x2e + rt2x00dev->lna_gain;
4423 } else { /* 5GHZ band */
4424 if (rt2x00_rt(rt2x00dev, RT3572))
4425 vgc = 0x22 + (rt2x00dev->lna_gain * 5) / 3;
4426 else if (rt2x00_rt(rt2x00dev, RT3593))
4427 vgc = 0x20 + (rt2x00dev->lna_gain * 5) / 3;
4428 else if (rt2x00_rt(rt2x00dev, RT5592))
4429 vgc = 0x24 + (2 * rt2x00dev->lna_gain);
4431 if (!test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
4432 vgc = 0x32 + (rt2x00dev->lna_gain * 5) / 3;
4434 vgc = 0x3a + (rt2x00dev->lna_gain * 5) / 3;
4441 static inline void rt2800_set_vgc(struct rt2x00_dev *rt2x00dev,
4442 struct link_qual *qual, u8 vgc_level)
4444 if (qual->vgc_level != vgc_level) {
4445 if (rt2x00_rt(rt2x00dev, RT5592)) {
4446 rt2800_bbp_write(rt2x00dev, 83, qual->rssi > -65 ? 0x4a : 0x7a);
4447 rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, vgc_level);
4449 rt2800_bbp_write(rt2x00dev, 66, vgc_level);
4450 qual->vgc_level = vgc_level;
4451 qual->vgc_level_reg = vgc_level;
4455 void rt2800_reset_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual)
4457 rt2800_set_vgc(rt2x00dev, qual, rt2800_get_default_vgc(rt2x00dev));
4459 EXPORT_SYMBOL_GPL(rt2800_reset_tuner);
4461 void rt2800_link_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual,
4466 if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C))
4469 * When RSSI is better then -80 increase VGC level with 0x10, except
4473 vgc = rt2800_get_default_vgc(rt2x00dev);
4475 if (rt2x00_rt(rt2x00dev, RT5592) && qual->rssi > -65)
4477 else if (qual->rssi > -80)
4480 rt2800_set_vgc(rt2x00dev, qual, vgc);
4482 EXPORT_SYMBOL_GPL(rt2800_link_tuner);
4485 * Initialization functions.
4487 static int rt2800_init_registers(struct rt2x00_dev *rt2x00dev)
4494 rt2800_disable_wpdma(rt2x00dev);
4496 ret = rt2800_drv_init_registers(rt2x00dev);
4500 rt2800_register_read(rt2x00dev, BCN_OFFSET0, ®);
4501 rt2x00_set_field32(®, BCN_OFFSET0_BCN0,
4502 rt2800_get_beacon_offset(rt2x00dev, 0));
4503 rt2x00_set_field32(®, BCN_OFFSET0_BCN1,
4504 rt2800_get_beacon_offset(rt2x00dev, 1));
4505 rt2x00_set_field32(®, BCN_OFFSET0_BCN2,
4506 rt2800_get_beacon_offset(rt2x00dev, 2));
4507 rt2x00_set_field32(®, BCN_OFFSET0_BCN3,
4508 rt2800_get_beacon_offset(rt2x00dev, 3));
4509 rt2800_register_write(rt2x00dev, BCN_OFFSET0, reg);
4511 rt2800_register_read(rt2x00dev, BCN_OFFSET1, ®);
4512 rt2x00_set_field32(®, BCN_OFFSET1_BCN4,
4513 rt2800_get_beacon_offset(rt2x00dev, 4));
4514 rt2x00_set_field32(®, BCN_OFFSET1_BCN5,
4515 rt2800_get_beacon_offset(rt2x00dev, 5));
4516 rt2x00_set_field32(®, BCN_OFFSET1_BCN6,
4517 rt2800_get_beacon_offset(rt2x00dev, 6));
4518 rt2x00_set_field32(®, BCN_OFFSET1_BCN7,
4519 rt2800_get_beacon_offset(rt2x00dev, 7));
4520 rt2800_register_write(rt2x00dev, BCN_OFFSET1, reg);
4522 rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE, 0x0000013f);
4523 rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
4525 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
4527 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®);
4528 rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_INTERVAL, 1600);
4529 rt2x00_set_field32(®, BCN_TIME_CFG_TSF_TICKING, 0);
4530 rt2x00_set_field32(®, BCN_TIME_CFG_TSF_SYNC, 0);
4531 rt2x00_set_field32(®, BCN_TIME_CFG_TBTT_ENABLE, 0);
4532 rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 0);
4533 rt2x00_set_field32(®, BCN_TIME_CFG_TX_TIME_COMPENSATE, 0);
4534 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
4536 rt2800_config_filter(rt2x00dev, FIF_ALLMULTI);
4538 rt2800_register_read(rt2x00dev, BKOFF_SLOT_CFG, ®);
4539 rt2x00_set_field32(®, BKOFF_SLOT_CFG_SLOT_TIME, 9);
4540 rt2x00_set_field32(®, BKOFF_SLOT_CFG_CC_DELAY_TIME, 2);
4541 rt2800_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg);
4543 if (rt2x00_rt(rt2x00dev, RT3290)) {
4544 rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, ®);
4545 if (rt2x00_get_field32(reg, WLAN_EN) == 1) {
4546 rt2x00_set_field32(®, PCIE_APP0_CLK_REQ, 1);
4547 rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg);
4550 rt2800_register_read(rt2x00dev, CMB_CTRL, ®);
4551 if (!(rt2x00_get_field32(reg, LDO0_EN) == 1)) {
4552 rt2x00_set_field32(®, LDO0_EN, 1);
4553 rt2x00_set_field32(®, LDO_BGSEL, 3);
4554 rt2800_register_write(rt2x00dev, CMB_CTRL, reg);
4557 rt2800_register_read(rt2x00dev, OSC_CTRL, ®);
4558 rt2x00_set_field32(®, OSC_ROSC_EN, 1);
4559 rt2x00_set_field32(®, OSC_CAL_REQ, 1);
4560 rt2x00_set_field32(®, OSC_REF_CYCLE, 0x27);
4561 rt2800_register_write(rt2x00dev, OSC_CTRL, reg);
4563 rt2800_register_read(rt2x00dev, COEX_CFG0, ®);
4564 rt2x00_set_field32(®, COEX_CFG_ANT, 0x5e);
4565 rt2800_register_write(rt2x00dev, COEX_CFG0, reg);
4567 rt2800_register_read(rt2x00dev, COEX_CFG2, ®);
4568 rt2x00_set_field32(®, BT_COEX_CFG1, 0x00);
4569 rt2x00_set_field32(®, BT_COEX_CFG0, 0x17);
4570 rt2x00_set_field32(®, WL_COEX_CFG1, 0x93);
4571 rt2x00_set_field32(®, WL_COEX_CFG0, 0x7f);
4572 rt2800_register_write(rt2x00dev, COEX_CFG2, reg);
4574 rt2800_register_read(rt2x00dev, PLL_CTRL, ®);
4575 rt2x00_set_field32(®, PLL_CONTROL, 1);
4576 rt2800_register_write(rt2x00dev, PLL_CTRL, reg);
4579 if (rt2x00_rt(rt2x00dev, RT3071) ||
4580 rt2x00_rt(rt2x00dev, RT3090) ||
4581 rt2x00_rt(rt2x00dev, RT3290) ||
4582 rt2x00_rt(rt2x00dev, RT3390)) {
4584 if (rt2x00_rt(rt2x00dev, RT3290))
4585 rt2800_register_write(rt2x00dev, TX_SW_CFG0,
4588 rt2800_register_write(rt2x00dev, TX_SW_CFG0,
4591 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
4592 if (rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) ||
4593 rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E) ||
4594 rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) {
4595 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1,
4597 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_DAC_TEST))
4598 rt2800_register_write(rt2x00dev, TX_SW_CFG2,
4601 rt2800_register_write(rt2x00dev, TX_SW_CFG2,
4604 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
4606 } else if (rt2x00_rt(rt2x00dev, RT3070)) {
4607 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
4609 if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) {
4610 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
4611 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x0000002c);
4613 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
4614 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
4616 } else if (rt2800_is_305x_soc(rt2x00dev)) {
4617 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
4618 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
4619 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000030);
4620 } else if (rt2x00_rt(rt2x00dev, RT3352)) {
4621 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000402);
4622 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
4623 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
4624 } else if (rt2x00_rt(rt2x00dev, RT3572)) {
4625 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
4626 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
4627 } else if (rt2x00_rt(rt2x00dev, RT3593)) {
4628 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000402);
4629 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
4630 if (rt2x00_rt_rev_lt(rt2x00dev, RT3593, REV_RT3593E)) {
4631 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1,
4633 if (rt2x00_get_field16(eeprom,
4634 EEPROM_NIC_CONF1_DAC_TEST))
4635 rt2800_register_write(rt2x00dev, TX_SW_CFG2,
4638 rt2800_register_write(rt2x00dev, TX_SW_CFG2,
4641 rt2800_register_write(rt2x00dev, TX_SW_CFG2,
4644 } else if (rt2x00_rt(rt2x00dev, RT5390) ||
4645 rt2x00_rt(rt2x00dev, RT5392) ||
4646 rt2x00_rt(rt2x00dev, RT5592)) {
4647 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000404);
4648 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
4649 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
4651 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000000);
4652 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
4655 rt2800_register_read(rt2x00dev, TX_LINK_CFG, ®);
4656 rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_MFB_LIFETIME, 32);
4657 rt2x00_set_field32(®, TX_LINK_CFG_MFB_ENABLE, 0);
4658 rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_UMFS_ENABLE, 0);
4659 rt2x00_set_field32(®, TX_LINK_CFG_TX_MRQ_EN, 0);
4660 rt2x00_set_field32(®, TX_LINK_CFG_TX_RDG_EN, 0);
4661 rt2x00_set_field32(®, TX_LINK_CFG_TX_CF_ACK_EN, 1);
4662 rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_MFB, 0);
4663 rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_MFS, 0);
4664 rt2800_register_write(rt2x00dev, TX_LINK_CFG, reg);
4666 rt2800_register_read(rt2x00dev, TX_TIMEOUT_CFG, ®);
4667 rt2x00_set_field32(®, TX_TIMEOUT_CFG_MPDU_LIFETIME, 9);
4668 rt2x00_set_field32(®, TX_TIMEOUT_CFG_RX_ACK_TIMEOUT, 32);
4669 rt2x00_set_field32(®, TX_TIMEOUT_CFG_TX_OP_TIMEOUT, 10);
4670 rt2800_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
4672 rt2800_register_read(rt2x00dev, MAX_LEN_CFG, ®);
4673 rt2x00_set_field32(®, MAX_LEN_CFG_MAX_MPDU, AGGREGATION_SIZE);
4674 if (rt2x00_rt_rev_gte(rt2x00dev, RT2872, REV_RT2872E) ||
4675 rt2x00_rt(rt2x00dev, RT2883) ||
4676 rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070E))
4677 rt2x00_set_field32(®, MAX_LEN_CFG_MAX_PSDU, 2);
4679 rt2x00_set_field32(®, MAX_LEN_CFG_MAX_PSDU, 1);
4680 rt2x00_set_field32(®, MAX_LEN_CFG_MIN_PSDU, 0);
4681 rt2x00_set_field32(®, MAX_LEN_CFG_MIN_MPDU, 0);
4682 rt2800_register_write(rt2x00dev, MAX_LEN_CFG, reg);
4684 rt2800_register_read(rt2x00dev, LED_CFG, ®);
4685 rt2x00_set_field32(®, LED_CFG_ON_PERIOD, 70);
4686 rt2x00_set_field32(®, LED_CFG_OFF_PERIOD, 30);
4687 rt2x00_set_field32(®, LED_CFG_SLOW_BLINK_PERIOD, 3);
4688 rt2x00_set_field32(®, LED_CFG_R_LED_MODE, 3);
4689 rt2x00_set_field32(®, LED_CFG_G_LED_MODE, 3);
4690 rt2x00_set_field32(®, LED_CFG_Y_LED_MODE, 3);
4691 rt2x00_set_field32(®, LED_CFG_LED_POLAR, 1);
4692 rt2800_register_write(rt2x00dev, LED_CFG, reg);
4694 rt2800_register_write(rt2x00dev, PBF_MAX_PCNT, 0x1f3fbf9f);
4696 rt2800_register_read(rt2x00dev, TX_RTY_CFG, ®);
4697 rt2x00_set_field32(®, TX_RTY_CFG_SHORT_RTY_LIMIT, 15);
4698 rt2x00_set_field32(®, TX_RTY_CFG_LONG_RTY_LIMIT, 31);
4699 rt2x00_set_field32(®, TX_RTY_CFG_LONG_RTY_THRE, 2000);
4700 rt2x00_set_field32(®, TX_RTY_CFG_NON_AGG_RTY_MODE, 0);
4701 rt2x00_set_field32(®, TX_RTY_CFG_AGG_RTY_MODE, 0);
4702 rt2x00_set_field32(®, TX_RTY_CFG_TX_AUTO_FB_ENABLE, 1);
4703 rt2800_register_write(rt2x00dev, TX_RTY_CFG, reg);
4705 rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, ®);
4706 rt2x00_set_field32(®, AUTO_RSP_CFG_AUTORESPONDER, 1);
4707 rt2x00_set_field32(®, AUTO_RSP_CFG_BAC_ACK_POLICY, 1);
4708 rt2x00_set_field32(®, AUTO_RSP_CFG_CTS_40_MMODE, 0);
4709 rt2x00_set_field32(®, AUTO_RSP_CFG_CTS_40_MREF, 0);
4710 rt2x00_set_field32(®, AUTO_RSP_CFG_AR_PREAMBLE, 1);
4711 rt2x00_set_field32(®, AUTO_RSP_CFG_DUAL_CTS_EN, 0);
4712 rt2x00_set_field32(®, AUTO_RSP_CFG_ACK_CTS_PSM_BIT, 0);
4713 rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
4715 rt2800_register_read(rt2x00dev, CCK_PROT_CFG, ®);
4716 rt2x00_set_field32(®, CCK_PROT_CFG_PROTECT_RATE, 3);
4717 rt2x00_set_field32(®, CCK_PROT_CFG_PROTECT_CTRL, 0);
4718 rt2x00_set_field32(®, CCK_PROT_CFG_PROTECT_NAV_SHORT, 1);
4719 rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_CCK, 1);
4720 rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
4721 rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_MM20, 1);
4722 rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_MM40, 0);
4723 rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_GF20, 1);
4724 rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_GF40, 0);
4725 rt2x00_set_field32(®, CCK_PROT_CFG_RTS_TH_EN, 1);
4726 rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg);
4728 rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, ®);
4729 rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_RATE, 3);
4730 rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_CTRL, 0);
4731 rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_NAV_SHORT, 1);
4732 rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_CCK, 1);
4733 rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
4734 rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_MM20, 1);
4735 rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_MM40, 0);
4736 rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_GF20, 1);
4737 rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_GF40, 0);
4738 rt2x00_set_field32(®, OFDM_PROT_CFG_RTS_TH_EN, 1);
4739 rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
4741 rt2800_register_read(rt2x00dev, MM20_PROT_CFG, ®);
4742 rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_RATE, 0x4004);
4743 rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_CTRL, 0);
4744 rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_NAV_SHORT, 1);
4745 rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
4746 rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
4747 rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
4748 rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
4749 rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
4750 rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
4751 rt2x00_set_field32(®, MM20_PROT_CFG_RTS_TH_EN, 0);
4752 rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
4754 rt2800_register_read(rt2x00dev, MM40_PROT_CFG, ®);
4755 rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_RATE, 0x4084);
4756 rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_CTRL, 0);
4757 rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_NAV_SHORT, 1);
4758 rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
4759 rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
4760 rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
4761 rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
4762 rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
4763 rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
4764 rt2x00_set_field32(®, MM40_PROT_CFG_RTS_TH_EN, 0);
4765 rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
4767 rt2800_register_read(rt2x00dev, GF20_PROT_CFG, ®);
4768 rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_RATE, 0x4004);
4769 rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_CTRL, 0);
4770 rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_NAV_SHORT, 1);
4771 rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
4772 rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
4773 rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
4774 rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
4775 rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
4776 rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
4777 rt2x00_set_field32(®, GF20_PROT_CFG_RTS_TH_EN, 0);
4778 rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
4780 rt2800_register_read(rt2x00dev, GF40_PROT_CFG, ®);
4781 rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_RATE, 0x4084);
4782 rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_CTRL, 0);
4783 rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_NAV_SHORT, 1);
4784 rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
4785 rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
4786 rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
4787 rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
4788 rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
4789 rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
4790 rt2x00_set_field32(®, GF40_PROT_CFG_RTS_TH_EN, 0);
4791 rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
4793 if (rt2x00_is_usb(rt2x00dev)) {
4794 rt2800_register_write(rt2x00dev, PBF_CFG, 0xf40006);
4796 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®);
4797 rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
4798 rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
4799 rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
4800 rt2x00_set_field32(®, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
4801 rt2x00_set_field32(®, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 3);
4802 rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 0);
4803 rt2x00_set_field32(®, WPDMA_GLO_CFG_BIG_ENDIAN, 0);
4804 rt2x00_set_field32(®, WPDMA_GLO_CFG_RX_HDR_SCATTER, 0);
4805 rt2x00_set_field32(®, WPDMA_GLO_CFG_HDR_SEG_LEN, 0);
4806 rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
4810 * The legacy driver also sets TXOP_CTRL_CFG_RESERVED_TRUN_EN to 1
4811 * although it is reserved.
4813 rt2800_register_read(rt2x00dev, TXOP_CTRL_CFG, ®);
4814 rt2x00_set_field32(®, TXOP_CTRL_CFG_TIMEOUT_TRUN_EN, 1);
4815 rt2x00_set_field32(®, TXOP_CTRL_CFG_AC_TRUN_EN, 1);
4816 rt2x00_set_field32(®, TXOP_CTRL_CFG_TXRATEGRP_TRUN_EN, 1);
4817 rt2x00_set_field32(®, TXOP_CTRL_CFG_USER_MODE_TRUN_EN, 1);
4818 rt2x00_set_field32(®, TXOP_CTRL_CFG_MIMO_PS_TRUN_EN, 1);
4819 rt2x00_set_field32(®, TXOP_CTRL_CFG_RESERVED_TRUN_EN, 1);
4820 rt2x00_set_field32(®, TXOP_CTRL_CFG_LSIG_TXOP_EN, 0);
4821 rt2x00_set_field32(®, TXOP_CTRL_CFG_EXT_CCA_EN, 0);
4822 rt2x00_set_field32(®, TXOP_CTRL_CFG_EXT_CCA_DLY, 88);
4823 rt2x00_set_field32(®, TXOP_CTRL_CFG_EXT_CWMIN, 0);
4824 rt2800_register_write(rt2x00dev, TXOP_CTRL_CFG, reg);
4826 reg = rt2x00_rt(rt2x00dev, RT5592) ? 0x00000082 : 0x00000002;
4827 rt2800_register_write(rt2x00dev, TXOP_HLDR_ET, reg);
4829 rt2800_register_read(rt2x00dev, TX_RTS_CFG, ®);
4830 rt2x00_set_field32(®, TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT, 32);
4831 rt2x00_set_field32(®, TX_RTS_CFG_RTS_THRES,
4832 IEEE80211_MAX_RTS_THRESHOLD);
4833 rt2x00_set_field32(®, TX_RTS_CFG_RTS_FBK_EN, 0);
4834 rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg);
4836 rt2800_register_write(rt2x00dev, EXP_ACK_TIME, 0x002400ca);
4839 * Usually the CCK SIFS time should be set to 10 and the OFDM SIFS
4840 * time should be set to 16. However, the original Ralink driver uses
4841 * 16 for both and indeed using a value of 10 for CCK SIFS results in
4842 * connection problems with 11g + CTS protection. Hence, use the same
4843 * defaults as the Ralink driver: 16 for both, CCK and OFDM SIFS.
4845 rt2800_register_read(rt2x00dev, XIFS_TIME_CFG, ®);
4846 rt2x00_set_field32(®, XIFS_TIME_CFG_CCKM_SIFS_TIME, 16);
4847 rt2x00_set_field32(®, XIFS_TIME_CFG_OFDM_SIFS_TIME, 16);
4848 rt2x00_set_field32(®, XIFS_TIME_CFG_OFDM_XIFS_TIME, 4);
4849 rt2x00_set_field32(®, XIFS_TIME_CFG_EIFS, 314);
4850 rt2x00_set_field32(®, XIFS_TIME_CFG_BB_RXEND_ENABLE, 1);
4851 rt2800_register_write(rt2x00dev, XIFS_TIME_CFG, reg);
4853 rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
4856 * ASIC will keep garbage value after boot, clear encryption keys.
4858 for (i = 0; i < 4; i++)
4859 rt2800_register_write(rt2x00dev,
4860 SHARED_KEY_MODE_ENTRY(i), 0);
4862 for (i = 0; i < 256; i++) {
4863 rt2800_config_wcid(rt2x00dev, NULL, i);
4864 rt2800_delete_wcid_attr(rt2x00dev, i);
4865 rt2800_register_write(rt2x00dev, MAC_IVEIV_ENTRY(i), 0);
4871 for (i = 0; i < 8; i++)
4872 rt2800_clear_beacon_register(rt2x00dev, i);
4874 if (rt2x00_is_usb(rt2x00dev)) {
4875 rt2800_register_read(rt2x00dev, US_CYC_CNT, ®);
4876 rt2x00_set_field32(®, US_CYC_CNT_CLOCK_CYCLE, 30);
4877 rt2800_register_write(rt2x00dev, US_CYC_CNT, reg);
4878 } else if (rt2x00_is_pcie(rt2x00dev)) {
4879 rt2800_register_read(rt2x00dev, US_CYC_CNT, ®);
4880 rt2x00_set_field32(®, US_CYC_CNT_CLOCK_CYCLE, 125);
4881 rt2800_register_write(rt2x00dev, US_CYC_CNT, reg);
4884 rt2800_register_read(rt2x00dev, HT_FBK_CFG0, ®);
4885 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS0FBK, 0);
4886 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS1FBK, 0);
4887 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS2FBK, 1);
4888 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS3FBK, 2);
4889 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS4FBK, 3);
4890 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS5FBK, 4);
4891 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS6FBK, 5);
4892 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS7FBK, 6);
4893 rt2800_register_write(rt2x00dev, HT_FBK_CFG0, reg);
4895 rt2800_register_read(rt2x00dev, HT_FBK_CFG1, ®);
4896 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS8FBK, 8);
4897 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS9FBK, 8);
4898 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS10FBK, 9);
4899 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS11FBK, 10);
4900 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS12FBK, 11);
4901 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS13FBK, 12);
4902 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS14FBK, 13);
4903 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS15FBK, 14);
4904 rt2800_register_write(rt2x00dev, HT_FBK_CFG1, reg);
4906 rt2800_register_read(rt2x00dev, LG_FBK_CFG0, ®);
4907 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS0FBK, 8);
4908 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS1FBK, 8);
4909 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS2FBK, 9);
4910 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS3FBK, 10);
4911 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS4FBK, 11);
4912 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS5FBK, 12);
4913 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS6FBK, 13);
4914 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS7FBK, 14);
4915 rt2800_register_write(rt2x00dev, LG_FBK_CFG0, reg);
4917 rt2800_register_read(rt2x00dev, LG_FBK_CFG1, ®);
4918 rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS0FBK, 0);
4919 rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS1FBK, 0);
4920 rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS2FBK, 1);
4921 rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS3FBK, 2);
4922 rt2800_register_write(rt2x00dev, LG_FBK_CFG1, reg);
4925 * Do not force the BA window size, we use the TXWI to set it
4927 rt2800_register_read(rt2x00dev, AMPDU_BA_WINSIZE, ®);
4928 rt2x00_set_field32(®, AMPDU_BA_WINSIZE_FORCE_WINSIZE_ENABLE, 0);
4929 rt2x00_set_field32(®, AMPDU_BA_WINSIZE_FORCE_WINSIZE, 0);
4930 rt2800_register_write(rt2x00dev, AMPDU_BA_WINSIZE, reg);
4933 * We must clear the error counters.
4934 * These registers are cleared on read,
4935 * so we may pass a useless variable to store the value.
4937 rt2800_register_read(rt2x00dev, RX_STA_CNT0, ®);
4938 rt2800_register_read(rt2x00dev, RX_STA_CNT1, ®);
4939 rt2800_register_read(rt2x00dev, RX_STA_CNT2, ®);
4940 rt2800_register_read(rt2x00dev, TX_STA_CNT0, ®);
4941 rt2800_register_read(rt2x00dev, TX_STA_CNT1, ®);
4942 rt2800_register_read(rt2x00dev, TX_STA_CNT2, ®);
4945 * Setup leadtime for pre tbtt interrupt to 6ms
4947 rt2800_register_read(rt2x00dev, INT_TIMER_CFG, ®);
4948 rt2x00_set_field32(®, INT_TIMER_CFG_PRE_TBTT_TIMER, 6 << 4);
4949 rt2800_register_write(rt2x00dev, INT_TIMER_CFG, reg);
4952 * Set up channel statistics timer
4954 rt2800_register_read(rt2x00dev, CH_TIME_CFG, ®);
4955 rt2x00_set_field32(®, CH_TIME_CFG_EIFS_BUSY, 1);
4956 rt2x00_set_field32(®, CH_TIME_CFG_NAV_BUSY, 1);
4957 rt2x00_set_field32(®, CH_TIME_CFG_RX_BUSY, 1);
4958 rt2x00_set_field32(®, CH_TIME_CFG_TX_BUSY, 1);
4959 rt2x00_set_field32(®, CH_TIME_CFG_TMR_EN, 1);
4960 rt2800_register_write(rt2x00dev, CH_TIME_CFG, reg);
4965 static int rt2800_wait_bbp_rf_ready(struct rt2x00_dev *rt2x00dev)
4970 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
4971 rt2800_register_read(rt2x00dev, MAC_STATUS_CFG, ®);
4972 if (!rt2x00_get_field32(reg, MAC_STATUS_CFG_BBP_RF_BUSY))
4975 udelay(REGISTER_BUSY_DELAY);
4978 rt2x00_err(rt2x00dev, "BBP/RF register access failed, aborting\n");
4982 static int rt2800_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
4988 * BBP was enabled after firmware was loaded,
4989 * but we need to reactivate it now.
4991 rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
4992 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
4995 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
4996 rt2800_bbp_read(rt2x00dev, 0, &value);
4997 if ((value != 0xff) && (value != 0x00))
4999 udelay(REGISTER_BUSY_DELAY);
5002 rt2x00_err(rt2x00dev, "BBP register access failed, aborting\n");
5006 static void rt2800_bbp4_mac_if_ctrl(struct rt2x00_dev *rt2x00dev)
5010 rt2800_bbp_read(rt2x00dev, 4, &value);
5011 rt2x00_set_field8(&value, BBP4_MAC_IF_CTRL, 1);
5012 rt2800_bbp_write(rt2x00dev, 4, value);
5015 static void rt2800_init_freq_calibration(struct rt2x00_dev *rt2x00dev)
5017 rt2800_bbp_write(rt2x00dev, 142, 1);
5018 rt2800_bbp_write(rt2x00dev, 143, 57);
5021 static void rt2800_init_bbp_5592_glrt(struct rt2x00_dev *rt2x00dev)
5023 const u8 glrt_table[] = {
5024 0xE0, 0x1F, 0X38, 0x32, 0x08, 0x28, 0x19, 0x0A, 0xFF, 0x00, /* 128 ~ 137 */
5025 0x16, 0x10, 0x10, 0x0B, 0x36, 0x2C, 0x26, 0x24, 0x42, 0x36, /* 138 ~ 147 */
5026 0x30, 0x2D, 0x4C, 0x46, 0x3D, 0x40, 0x3E, 0x42, 0x3D, 0x40, /* 148 ~ 157 */
5027 0X3C, 0x34, 0x2C, 0x2F, 0x3C, 0x35, 0x2E, 0x2A, 0x49, 0x41, /* 158 ~ 167 */
5028 0x36, 0x31, 0x30, 0x30, 0x0E, 0x0D, 0x28, 0x21, 0x1C, 0x16, /* 168 ~ 177 */
5029 0x50, 0x4A, 0x43, 0x40, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, /* 178 ~ 187 */
5030 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 188 ~ 197 */
5031 0x00, 0x00, 0x7D, 0x14, 0x32, 0x2C, 0x36, 0x4C, 0x43, 0x2C, /* 198 ~ 207 */
5032 0x2E, 0x36, 0x30, 0x6E, /* 208 ~ 211 */
5036 for (i = 0; i < ARRAY_SIZE(glrt_table); i++) {
5037 rt2800_bbp_write(rt2x00dev, 195, 128 + i);
5038 rt2800_bbp_write(rt2x00dev, 196, glrt_table[i]);
5042 static void rt2800_init_bbp_early(struct rt2x00_dev *rt2x00dev)
5044 rt2800_bbp_write(rt2x00dev, 65, 0x2C);
5045 rt2800_bbp_write(rt2x00dev, 66, 0x38);
5046 rt2800_bbp_write(rt2x00dev, 68, 0x0B);
5047 rt2800_bbp_write(rt2x00dev, 69, 0x12);
5048 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
5049 rt2800_bbp_write(rt2x00dev, 73, 0x10);
5050 rt2800_bbp_write(rt2x00dev, 81, 0x37);
5051 rt2800_bbp_write(rt2x00dev, 82, 0x62);
5052 rt2800_bbp_write(rt2x00dev, 83, 0x6A);
5053 rt2800_bbp_write(rt2x00dev, 84, 0x99);
5054 rt2800_bbp_write(rt2x00dev, 86, 0x00);
5055 rt2800_bbp_write(rt2x00dev, 91, 0x04);
5056 rt2800_bbp_write(rt2x00dev, 92, 0x00);
5057 rt2800_bbp_write(rt2x00dev, 103, 0x00);
5058 rt2800_bbp_write(rt2x00dev, 105, 0x05);
5059 rt2800_bbp_write(rt2x00dev, 106, 0x35);
5062 static void rt2800_disable_unused_dac_adc(struct rt2x00_dev *rt2x00dev)
5067 rt2800_bbp_read(rt2x00dev, 138, &value);
5068 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom);
5069 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) == 1)
5071 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) == 1)
5073 rt2800_bbp_write(rt2x00dev, 138, value);
5076 static void rt2800_init_bbp_305x_soc(struct rt2x00_dev *rt2x00dev)
5078 rt2800_bbp_write(rt2x00dev, 31, 0x08);
5080 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
5081 rt2800_bbp_write(rt2x00dev, 66, 0x38);
5083 rt2800_bbp_write(rt2x00dev, 69, 0x12);
5084 rt2800_bbp_write(rt2x00dev, 73, 0x10);
5086 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
5088 rt2800_bbp_write(rt2x00dev, 78, 0x0e);
5089 rt2800_bbp_write(rt2x00dev, 80, 0x08);
5091 rt2800_bbp_write(rt2x00dev, 82, 0x62);
5093 rt2800_bbp_write(rt2x00dev, 83, 0x6a);
5095 rt2800_bbp_write(rt2x00dev, 84, 0x99);
5097 rt2800_bbp_write(rt2x00dev, 86, 0x00);
5099 rt2800_bbp_write(rt2x00dev, 91, 0x04);
5101 rt2800_bbp_write(rt2x00dev, 92, 0x00);
5103 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
5105 rt2800_bbp_write(rt2x00dev, 105, 0x01);
5107 rt2800_bbp_write(rt2x00dev, 106, 0x35);
5110 static void rt2800_init_bbp_28xx(struct rt2x00_dev *rt2x00dev)
5112 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
5113 rt2800_bbp_write(rt2x00dev, 66, 0x38);
5115 if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) {
5116 rt2800_bbp_write(rt2x00dev, 69, 0x16);
5117 rt2800_bbp_write(rt2x00dev, 73, 0x12);
5119 rt2800_bbp_write(rt2x00dev, 69, 0x12);
5120 rt2800_bbp_write(rt2x00dev, 73, 0x10);
5123 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
5125 rt2800_bbp_write(rt2x00dev, 81, 0x37);
5127 rt2800_bbp_write(rt2x00dev, 82, 0x62);
5129 rt2800_bbp_write(rt2x00dev, 83, 0x6a);
5131 if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860D))
5132 rt2800_bbp_write(rt2x00dev, 84, 0x19);
5134 rt2800_bbp_write(rt2x00dev, 84, 0x99);
5136 rt2800_bbp_write(rt2x00dev, 86, 0x00);
5138 rt2800_bbp_write(rt2x00dev, 91, 0x04);
5140 rt2800_bbp_write(rt2x00dev, 92, 0x00);
5142 rt2800_bbp_write(rt2x00dev, 103, 0x00);
5144 rt2800_bbp_write(rt2x00dev, 105, 0x05);
5146 rt2800_bbp_write(rt2x00dev, 106, 0x35);
5149 static void rt2800_init_bbp_30xx(struct rt2x00_dev *rt2x00dev)
5151 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
5152 rt2800_bbp_write(rt2x00dev, 66, 0x38);
5154 rt2800_bbp_write(rt2x00dev, 69, 0x12);
5155 rt2800_bbp_write(rt2x00dev, 73, 0x10);
5157 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
5159 rt2800_bbp_write(rt2x00dev, 79, 0x13);
5160 rt2800_bbp_write(rt2x00dev, 80, 0x05);
5161 rt2800_bbp_write(rt2x00dev, 81, 0x33);
5163 rt2800_bbp_write(rt2x00dev, 82, 0x62);
5165 rt2800_bbp_write(rt2x00dev, 83, 0x6a);
5167 rt2800_bbp_write(rt2x00dev, 84, 0x99);
5169 rt2800_bbp_write(rt2x00dev, 86, 0x00);
5171 rt2800_bbp_write(rt2x00dev, 91, 0x04);
5173 rt2800_bbp_write(rt2x00dev, 92, 0x00);
5175 if (rt2x00_rt_rev_gte(rt2x00dev, RT3070, REV_RT3070F) ||
5176 rt2x00_rt_rev_gte(rt2x00dev, RT3071, REV_RT3071E) ||
5177 rt2x00_rt_rev_gte(rt2x00dev, RT3090, REV_RT3090E))
5178 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
5180 rt2800_bbp_write(rt2x00dev, 103, 0x00);
5182 rt2800_bbp_write(rt2x00dev, 105, 0x05);
5184 rt2800_bbp_write(rt2x00dev, 106, 0x35);
5186 if (rt2x00_rt(rt2x00dev, RT3071) ||
5187 rt2x00_rt(rt2x00dev, RT3090))
5188 rt2800_disable_unused_dac_adc(rt2x00dev);
5191 static void rt2800_init_bbp_3290(struct rt2x00_dev *rt2x00dev)
5195 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
5197 rt2800_bbp_write(rt2x00dev, 31, 0x08);
5199 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
5200 rt2800_bbp_write(rt2x00dev, 66, 0x38);
5202 rt2800_bbp_write(rt2x00dev, 68, 0x0b);
5204 rt2800_bbp_write(rt2x00dev, 69, 0x12);
5205 rt2800_bbp_write(rt2x00dev, 73, 0x13);
5206 rt2800_bbp_write(rt2x00dev, 75, 0x46);
5207 rt2800_bbp_write(rt2x00dev, 76, 0x28);
5209 rt2800_bbp_write(rt2x00dev, 77, 0x58);
5211 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
5213 rt2800_bbp_write(rt2x00dev, 74, 0x0b);
5214 rt2800_bbp_write(rt2x00dev, 79, 0x18);
5215 rt2800_bbp_write(rt2x00dev, 80, 0x09);
5216 rt2800_bbp_write(rt2x00dev, 81, 0x33);
5218 rt2800_bbp_write(rt2x00dev, 82, 0x62);
5220 rt2800_bbp_write(rt2x00dev, 83, 0x7a);
5222 rt2800_bbp_write(rt2x00dev, 84, 0x9a);
5224 rt2800_bbp_write(rt2x00dev, 86, 0x38);
5226 rt2800_bbp_write(rt2x00dev, 91, 0x04);
5228 rt2800_bbp_write(rt2x00dev, 92, 0x02);
5230 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
5232 rt2800_bbp_write(rt2x00dev, 104, 0x92);
5234 rt2800_bbp_write(rt2x00dev, 105, 0x1c);
5236 rt2800_bbp_write(rt2x00dev, 106, 0x03);
5238 rt2800_bbp_write(rt2x00dev, 128, 0x12);
5240 rt2800_bbp_write(rt2x00dev, 67, 0x24);
5241 rt2800_bbp_write(rt2x00dev, 143, 0x04);
5242 rt2800_bbp_write(rt2x00dev, 142, 0x99);
5243 rt2800_bbp_write(rt2x00dev, 150, 0x30);
5244 rt2800_bbp_write(rt2x00dev, 151, 0x2e);
5245 rt2800_bbp_write(rt2x00dev, 152, 0x20);
5246 rt2800_bbp_write(rt2x00dev, 153, 0x34);
5247 rt2800_bbp_write(rt2x00dev, 154, 0x40);
5248 rt2800_bbp_write(rt2x00dev, 155, 0x3b);
5249 rt2800_bbp_write(rt2x00dev, 253, 0x04);
5251 rt2800_bbp_read(rt2x00dev, 47, &value);
5252 rt2x00_set_field8(&value, BBP47_TSSI_ADC6, 1);
5253 rt2800_bbp_write(rt2x00dev, 47, value);
5255 /* Use 5-bit ADC for Acquisition and 8-bit ADC for data */
5256 rt2800_bbp_read(rt2x00dev, 3, &value);
5257 rt2x00_set_field8(&value, BBP3_ADC_MODE_SWITCH, 1);
5258 rt2x00_set_field8(&value, BBP3_ADC_INIT_MODE, 1);
5259 rt2800_bbp_write(rt2x00dev, 3, value);
5262 static void rt2800_init_bbp_3352(struct rt2x00_dev *rt2x00dev)
5264 rt2800_bbp_write(rt2x00dev, 3, 0x00);
5265 rt2800_bbp_write(rt2x00dev, 4, 0x50);
5267 rt2800_bbp_write(rt2x00dev, 31, 0x08);
5269 rt2800_bbp_write(rt2x00dev, 47, 0x48);
5271 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
5272 rt2800_bbp_write(rt2x00dev, 66, 0x38);
5274 rt2800_bbp_write(rt2x00dev, 68, 0x0b);
5276 rt2800_bbp_write(rt2x00dev, 69, 0x12);
5277 rt2800_bbp_write(rt2x00dev, 73, 0x13);
5278 rt2800_bbp_write(rt2x00dev, 75, 0x46);
5279 rt2800_bbp_write(rt2x00dev, 76, 0x28);
5281 rt2800_bbp_write(rt2x00dev, 77, 0x59);
5283 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
5285 rt2800_bbp_write(rt2x00dev, 78, 0x0e);
5286 rt2800_bbp_write(rt2x00dev, 80, 0x08);
5287 rt2800_bbp_write(rt2x00dev, 81, 0x37);
5289 rt2800_bbp_write(rt2x00dev, 82, 0x62);
5291 rt2800_bbp_write(rt2x00dev, 83, 0x6a);
5293 rt2800_bbp_write(rt2x00dev, 84, 0x99);
5295 rt2800_bbp_write(rt2x00dev, 86, 0x38);
5297 rt2800_bbp_write(rt2x00dev, 88, 0x90);
5299 rt2800_bbp_write(rt2x00dev, 91, 0x04);
5301 rt2800_bbp_write(rt2x00dev, 92, 0x02);
5303 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
5305 rt2800_bbp_write(rt2x00dev, 104, 0x92);
5307 rt2800_bbp_write(rt2x00dev, 105, 0x34);
5309 rt2800_bbp_write(rt2x00dev, 106, 0x05);
5311 rt2800_bbp_write(rt2x00dev, 120, 0x50);
5313 rt2800_bbp_write(rt2x00dev, 137, 0x0f);
5315 rt2800_bbp_write(rt2x00dev, 163, 0xbd);
5316 /* Set ITxBF timeout to 0x9c40=1000msec */
5317 rt2800_bbp_write(rt2x00dev, 179, 0x02);
5318 rt2800_bbp_write(rt2x00dev, 180, 0x00);
5319 rt2800_bbp_write(rt2x00dev, 182, 0x40);
5320 rt2800_bbp_write(rt2x00dev, 180, 0x01);
5321 rt2800_bbp_write(rt2x00dev, 182, 0x9c);
5322 rt2800_bbp_write(rt2x00dev, 179, 0x00);
5323 /* Reprogram the inband interface to put right values in RXWI */
5324 rt2800_bbp_write(rt2x00dev, 142, 0x04);
5325 rt2800_bbp_write(rt2x00dev, 143, 0x3b);
5326 rt2800_bbp_write(rt2x00dev, 142, 0x06);
5327 rt2800_bbp_write(rt2x00dev, 143, 0xa0);
5328 rt2800_bbp_write(rt2x00dev, 142, 0x07);
5329 rt2800_bbp_write(rt2x00dev, 143, 0xa1);
5330 rt2800_bbp_write(rt2x00dev, 142, 0x08);
5331 rt2800_bbp_write(rt2x00dev, 143, 0xa2);
5333 rt2800_bbp_write(rt2x00dev, 148, 0xc8);
5336 static void rt2800_init_bbp_3390(struct rt2x00_dev *rt2x00dev)
5338 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
5339 rt2800_bbp_write(rt2x00dev, 66, 0x38);
5341 rt2800_bbp_write(rt2x00dev, 69, 0x12);
5342 rt2800_bbp_write(rt2x00dev, 73, 0x10);
5344 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
5346 rt2800_bbp_write(rt2x00dev, 79, 0x13);
5347 rt2800_bbp_write(rt2x00dev, 80, 0x05);
5348 rt2800_bbp_write(rt2x00dev, 81, 0x33);
5350 rt2800_bbp_write(rt2x00dev, 82, 0x62);
5352 rt2800_bbp_write(rt2x00dev, 83, 0x6a);
5354 rt2800_bbp_write(rt2x00dev, 84, 0x99);
5356 rt2800_bbp_write(rt2x00dev, 86, 0x00);
5358 rt2800_bbp_write(rt2x00dev, 91, 0x04);
5360 rt2800_bbp_write(rt2x00dev, 92, 0x00);
5362 if (rt2x00_rt_rev_gte(rt2x00dev, RT3390, REV_RT3390E))
5363 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
5365 rt2800_bbp_write(rt2x00dev, 103, 0x00);
5367 rt2800_bbp_write(rt2x00dev, 105, 0x05);
5369 rt2800_bbp_write(rt2x00dev, 106, 0x35);
5371 rt2800_disable_unused_dac_adc(rt2x00dev);
5374 static void rt2800_init_bbp_3572(struct rt2x00_dev *rt2x00dev)
5376 rt2800_bbp_write(rt2x00dev, 31, 0x08);
5378 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
5379 rt2800_bbp_write(rt2x00dev, 66, 0x38);
5381 rt2800_bbp_write(rt2x00dev, 69, 0x12);
5382 rt2800_bbp_write(rt2x00dev, 73, 0x10);
5384 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
5386 rt2800_bbp_write(rt2x00dev, 79, 0x13);
5387 rt2800_bbp_write(rt2x00dev, 80, 0x05);
5388 rt2800_bbp_write(rt2x00dev, 81, 0x33);
5390 rt2800_bbp_write(rt2x00dev, 82, 0x62);
5392 rt2800_bbp_write(rt2x00dev, 83, 0x6a);
5394 rt2800_bbp_write(rt2x00dev, 84, 0x99);
5396 rt2800_bbp_write(rt2x00dev, 86, 0x00);
5398 rt2800_bbp_write(rt2x00dev, 91, 0x04);
5400 rt2800_bbp_write(rt2x00dev, 92, 0x00);
5402 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
5404 rt2800_bbp_write(rt2x00dev, 105, 0x05);
5406 rt2800_bbp_write(rt2x00dev, 106, 0x35);
5408 rt2800_disable_unused_dac_adc(rt2x00dev);
5411 static void rt2800_init_bbp_3593(struct rt2x00_dev *rt2x00dev)
5413 rt2800_init_bbp_early(rt2x00dev);
5415 rt2800_bbp_write(rt2x00dev, 79, 0x13);
5416 rt2800_bbp_write(rt2x00dev, 80, 0x05);
5417 rt2800_bbp_write(rt2x00dev, 81, 0x33);
5418 rt2800_bbp_write(rt2x00dev, 137, 0x0f);
5420 rt2800_bbp_write(rt2x00dev, 84, 0x19);
5422 /* Enable DC filter */
5423 if (rt2x00_rt_rev_gte(rt2x00dev, RT3593, REV_RT3593E))
5424 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
5427 static void rt2800_init_bbp_53xx(struct rt2x00_dev *rt2x00dev)
5433 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
5435 rt2800_bbp_write(rt2x00dev, 31, 0x08);
5437 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
5438 rt2800_bbp_write(rt2x00dev, 66, 0x38);
5440 rt2800_bbp_write(rt2x00dev, 68, 0x0b);
5442 rt2800_bbp_write(rt2x00dev, 69, 0x12);
5443 rt2800_bbp_write(rt2x00dev, 73, 0x13);
5444 rt2800_bbp_write(rt2x00dev, 75, 0x46);
5445 rt2800_bbp_write(rt2x00dev, 76, 0x28);
5447 rt2800_bbp_write(rt2x00dev, 77, 0x59);
5449 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
5451 rt2800_bbp_write(rt2x00dev, 79, 0x13);
5452 rt2800_bbp_write(rt2x00dev, 80, 0x05);
5453 rt2800_bbp_write(rt2x00dev, 81, 0x33);
5455 rt2800_bbp_write(rt2x00dev, 82, 0x62);
5457 rt2800_bbp_write(rt2x00dev, 83, 0x7a);
5459 rt2800_bbp_write(rt2x00dev, 84, 0x9a);
5461 rt2800_bbp_write(rt2x00dev, 86, 0x38);
5463 if (rt2x00_rt(rt2x00dev, RT5392))
5464 rt2800_bbp_write(rt2x00dev, 88, 0x90);
5466 rt2800_bbp_write(rt2x00dev, 91, 0x04);
5468 rt2800_bbp_write(rt2x00dev, 92, 0x02);
5470 if (rt2x00_rt(rt2x00dev, RT5392)) {
5471 rt2800_bbp_write(rt2x00dev, 95, 0x9a);
5472 rt2800_bbp_write(rt2x00dev, 98, 0x12);
5475 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
5477 rt2800_bbp_write(rt2x00dev, 104, 0x92);
5479 rt2800_bbp_write(rt2x00dev, 105, 0x3c);
5481 if (rt2x00_rt(rt2x00dev, RT5390))
5482 rt2800_bbp_write(rt2x00dev, 106, 0x03);
5483 else if (rt2x00_rt(rt2x00dev, RT5392))
5484 rt2800_bbp_write(rt2x00dev, 106, 0x12);
5488 rt2800_bbp_write(rt2x00dev, 128, 0x12);
5490 if (rt2x00_rt(rt2x00dev, RT5392)) {
5491 rt2800_bbp_write(rt2x00dev, 134, 0xd0);
5492 rt2800_bbp_write(rt2x00dev, 135, 0xf6);
5495 rt2800_disable_unused_dac_adc(rt2x00dev);
5497 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
5498 div_mode = rt2x00_get_field16(eeprom,
5499 EEPROM_NIC_CONF1_ANT_DIVERSITY);
5500 ant = (div_mode == 3) ? 1 : 0;
5502 /* check if this is a Bluetooth combo card */
5503 if (test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags)) {
5506 rt2800_register_read(rt2x00dev, GPIO_CTRL, ®);
5507 rt2x00_set_field32(®, GPIO_CTRL_DIR3, 0);
5508 rt2x00_set_field32(®, GPIO_CTRL_DIR6, 0);
5509 rt2x00_set_field32(®, GPIO_CTRL_VAL3, 0);
5510 rt2x00_set_field32(®, GPIO_CTRL_VAL6, 0);
5512 rt2x00_set_field32(®, GPIO_CTRL_VAL3, 1);
5514 rt2x00_set_field32(®, GPIO_CTRL_VAL6, 1);
5515 rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
5518 /* This chip has hardware antenna diversity*/
5519 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390R)) {
5520 rt2800_bbp_write(rt2x00dev, 150, 0); /* Disable Antenna Software OFDM */
5521 rt2800_bbp_write(rt2x00dev, 151, 0); /* Disable Antenna Software CCK */
5522 rt2800_bbp_write(rt2x00dev, 154, 0); /* Clear previously selected antenna */
5525 rt2800_bbp_read(rt2x00dev, 152, &value);
5527 rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 1);
5529 rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 0);
5530 rt2800_bbp_write(rt2x00dev, 152, value);
5532 rt2800_init_freq_calibration(rt2x00dev);
5535 static void rt2800_init_bbp_5592(struct rt2x00_dev *rt2x00dev)
5541 rt2800_init_bbp_early(rt2x00dev);
5543 rt2800_bbp_read(rt2x00dev, 105, &value);
5544 rt2x00_set_field8(&value, BBP105_MLD,
5545 rt2x00dev->default_ant.rx_chain_num == 2);
5546 rt2800_bbp_write(rt2x00dev, 105, value);
5548 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
5550 rt2800_bbp_write(rt2x00dev, 20, 0x06);
5551 rt2800_bbp_write(rt2x00dev, 31, 0x08);
5552 rt2800_bbp_write(rt2x00dev, 65, 0x2C);
5553 rt2800_bbp_write(rt2x00dev, 68, 0xDD);
5554 rt2800_bbp_write(rt2x00dev, 69, 0x1A);
5555 rt2800_bbp_write(rt2x00dev, 70, 0x05);
5556 rt2800_bbp_write(rt2x00dev, 73, 0x13);
5557 rt2800_bbp_write(rt2x00dev, 74, 0x0F);
5558 rt2800_bbp_write(rt2x00dev, 75, 0x4F);
5559 rt2800_bbp_write(rt2x00dev, 76, 0x28);
5560 rt2800_bbp_write(rt2x00dev, 77, 0x59);
5561 rt2800_bbp_write(rt2x00dev, 84, 0x9A);
5562 rt2800_bbp_write(rt2x00dev, 86, 0x38);
5563 rt2800_bbp_write(rt2x00dev, 88, 0x90);
5564 rt2800_bbp_write(rt2x00dev, 91, 0x04);
5565 rt2800_bbp_write(rt2x00dev, 92, 0x02);
5566 rt2800_bbp_write(rt2x00dev, 95, 0x9a);
5567 rt2800_bbp_write(rt2x00dev, 98, 0x12);
5568 rt2800_bbp_write(rt2x00dev, 103, 0xC0);
5569 rt2800_bbp_write(rt2x00dev, 104, 0x92);
5570 /* FIXME BBP105 owerwrite */
5571 rt2800_bbp_write(rt2x00dev, 105, 0x3C);
5572 rt2800_bbp_write(rt2x00dev, 106, 0x35);
5573 rt2800_bbp_write(rt2x00dev, 128, 0x12);
5574 rt2800_bbp_write(rt2x00dev, 134, 0xD0);
5575 rt2800_bbp_write(rt2x00dev, 135, 0xF6);
5576 rt2800_bbp_write(rt2x00dev, 137, 0x0F);
5578 /* Initialize GLRT (Generalized Likehood Radio Test) */
5579 rt2800_init_bbp_5592_glrt(rt2x00dev);
5581 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
5583 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
5584 div_mode = rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_ANT_DIVERSITY);
5585 ant = (div_mode == 3) ? 1 : 0;
5586 rt2800_bbp_read(rt2x00dev, 152, &value);
5589 rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 1);
5591 /* Auxiliary antenna */
5592 rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 0);
5594 rt2800_bbp_write(rt2x00dev, 152, value);
5596 if (rt2x00_rt_rev_gte(rt2x00dev, RT5592, REV_RT5592C)) {
5597 rt2800_bbp_read(rt2x00dev, 254, &value);
5598 rt2x00_set_field8(&value, BBP254_BIT7, 1);
5599 rt2800_bbp_write(rt2x00dev, 254, value);
5602 rt2800_init_freq_calibration(rt2x00dev);
5604 rt2800_bbp_write(rt2x00dev, 84, 0x19);
5605 if (rt2x00_rt_rev_gte(rt2x00dev, RT5592, REV_RT5592C))
5606 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
5609 static void rt2800_init_bbp(struct rt2x00_dev *rt2x00dev)
5616 if (rt2800_is_305x_soc(rt2x00dev))
5617 rt2800_init_bbp_305x_soc(rt2x00dev);
5619 switch (rt2x00dev->chip.rt) {
5623 rt2800_init_bbp_28xx(rt2x00dev);
5628 rt2800_init_bbp_30xx(rt2x00dev);
5631 rt2800_init_bbp_3290(rt2x00dev);
5634 rt2800_init_bbp_3352(rt2x00dev);
5637 rt2800_init_bbp_3390(rt2x00dev);
5640 rt2800_init_bbp_3572(rt2x00dev);
5643 rt2800_init_bbp_3593(rt2x00dev);
5647 rt2800_init_bbp_53xx(rt2x00dev);
5650 rt2800_init_bbp_5592(rt2x00dev);
5654 for (i = 0; i < EEPROM_BBP_SIZE; i++) {
5655 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_BBP_START, i,
5658 if (eeprom != 0xffff && eeprom != 0x0000) {
5659 reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
5660 value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
5661 rt2800_bbp_write(rt2x00dev, reg_id, value);
5666 static void rt2800_led_open_drain_enable(struct rt2x00_dev *rt2x00dev)
5670 rt2800_register_read(rt2x00dev, OPT_14_CSR, ®);
5671 rt2x00_set_field32(®, OPT_14_CSR_BIT0, 1);
5672 rt2800_register_write(rt2x00dev, OPT_14_CSR, reg);
5675 static u8 rt2800_init_rx_filter(struct rt2x00_dev *rt2x00dev, bool bw40,
5684 u8 rfcsr24 = (bw40) ? 0x27 : 0x07;
5686 rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
5688 rt2800_bbp_read(rt2x00dev, 4, &bbp);
5689 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * bw40);
5690 rt2800_bbp_write(rt2x00dev, 4, bbp);
5692 rt2800_rfcsr_read(rt2x00dev, 31, &rfcsr);
5693 rt2x00_set_field8(&rfcsr, RFCSR31_RX_H20M, bw40);
5694 rt2800_rfcsr_write(rt2x00dev, 31, rfcsr);
5696 rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr);
5697 rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 1);
5698 rt2800_rfcsr_write(rt2x00dev, 22, rfcsr);
5701 * Set power & frequency of passband test tone
5703 rt2800_bbp_write(rt2x00dev, 24, 0);
5705 for (i = 0; i < 100; i++) {
5706 rt2800_bbp_write(rt2x00dev, 25, 0x90);
5709 rt2800_bbp_read(rt2x00dev, 55, &passband);
5715 * Set power & frequency of stopband test tone
5717 rt2800_bbp_write(rt2x00dev, 24, 0x06);
5719 for (i = 0; i < 100; i++) {
5720 rt2800_bbp_write(rt2x00dev, 25, 0x90);
5723 rt2800_bbp_read(rt2x00dev, 55, &stopband);
5725 if ((passband - stopband) <= filter_target) {
5727 overtuned += ((passband - stopband) == filter_target);
5731 rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
5734 rfcsr24 -= !!overtuned;
5736 rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
5740 static void rt2800_rf_init_calibration(struct rt2x00_dev *rt2x00dev,
5741 const unsigned int rf_reg)
5745 rt2800_rfcsr_read(rt2x00dev, rf_reg, &rfcsr);
5746 rt2x00_set_field8(&rfcsr, FIELD8(0x80), 1);
5747 rt2800_rfcsr_write(rt2x00dev, rf_reg, rfcsr);
5749 rt2x00_set_field8(&rfcsr, FIELD8(0x80), 0);
5750 rt2800_rfcsr_write(rt2x00dev, rf_reg, rfcsr);
5753 static void rt2800_rx_filter_calibration(struct rt2x00_dev *rt2x00dev)
5755 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
5761 * TODO: sync filter_tgt values with vendor driver
5763 if (rt2x00_rt(rt2x00dev, RT3070)) {
5764 filter_tgt_bw20 = 0x16;
5765 filter_tgt_bw40 = 0x19;
5767 filter_tgt_bw20 = 0x13;
5768 filter_tgt_bw40 = 0x15;
5771 drv_data->calibration_bw20 =
5772 rt2800_init_rx_filter(rt2x00dev, false, filter_tgt_bw20);
5773 drv_data->calibration_bw40 =
5774 rt2800_init_rx_filter(rt2x00dev, true, filter_tgt_bw40);
5777 * Save BBP 25 & 26 values for later use in channel switching (for 3052)
5779 rt2800_bbp_read(rt2x00dev, 25, &drv_data->bbp25);
5780 rt2800_bbp_read(rt2x00dev, 26, &drv_data->bbp26);
5783 * Set back to initial state
5785 rt2800_bbp_write(rt2x00dev, 24, 0);
5787 rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr);
5788 rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 0);
5789 rt2800_rfcsr_write(rt2x00dev, 22, rfcsr);
5792 * Set BBP back to BW20
5794 rt2800_bbp_read(rt2x00dev, 4, &bbp);
5795 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0);
5796 rt2800_bbp_write(rt2x00dev, 4, bbp);
5799 static void rt2800_normal_mode_setup_3xxx(struct rt2x00_dev *rt2x00dev)
5801 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
5802 u8 min_gain, rfcsr, bbp;
5805 rt2800_rfcsr_read(rt2x00dev, 17, &rfcsr);
5807 rt2x00_set_field8(&rfcsr, RFCSR17_TX_LO1_EN, 0);
5808 if (rt2x00_rt(rt2x00dev, RT3070) ||
5809 rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) ||
5810 rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E) ||
5811 rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) {
5812 if (!test_bit(CAPABILITY_EXTERNAL_LNA_BG, &rt2x00dev->cap_flags))
5813 rt2x00_set_field8(&rfcsr, RFCSR17_R, 1);
5816 min_gain = rt2x00_rt(rt2x00dev, RT3070) ? 1 : 2;
5817 if (drv_data->txmixer_gain_24g >= min_gain) {
5818 rt2x00_set_field8(&rfcsr, RFCSR17_TXMIXER_GAIN,
5819 drv_data->txmixer_gain_24g);
5822 rt2800_rfcsr_write(rt2x00dev, 17, rfcsr);
5824 if (rt2x00_rt(rt2x00dev, RT3090)) {
5825 /* Turn off unused DAC1 and ADC1 to reduce power consumption */
5826 rt2800_bbp_read(rt2x00dev, 138, &bbp);
5827 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom);
5828 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) == 1)
5829 rt2x00_set_field8(&bbp, BBP138_RX_ADC1, 0);
5830 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) == 1)
5831 rt2x00_set_field8(&bbp, BBP138_TX_DAC1, 1);
5832 rt2800_bbp_write(rt2x00dev, 138, bbp);
5835 if (rt2x00_rt(rt2x00dev, RT3070)) {
5836 rt2800_rfcsr_read(rt2x00dev, 27, &rfcsr);
5837 if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F))
5838 rt2x00_set_field8(&rfcsr, RFCSR27_R1, 3);
5840 rt2x00_set_field8(&rfcsr, RFCSR27_R1, 0);
5841 rt2x00_set_field8(&rfcsr, RFCSR27_R2, 0);
5842 rt2x00_set_field8(&rfcsr, RFCSR27_R3, 0);
5843 rt2x00_set_field8(&rfcsr, RFCSR27_R4, 0);
5844 rt2800_rfcsr_write(rt2x00dev, 27, rfcsr);
5845 } else if (rt2x00_rt(rt2x00dev, RT3071) ||
5846 rt2x00_rt(rt2x00dev, RT3090) ||
5847 rt2x00_rt(rt2x00dev, RT3390)) {
5848 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
5849 rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
5850 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0);
5851 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0);
5852 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
5853 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
5854 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
5856 rt2800_rfcsr_read(rt2x00dev, 15, &rfcsr);
5857 rt2x00_set_field8(&rfcsr, RFCSR15_TX_LO2_EN, 0);
5858 rt2800_rfcsr_write(rt2x00dev, 15, rfcsr);
5860 rt2800_rfcsr_read(rt2x00dev, 20, &rfcsr);
5861 rt2x00_set_field8(&rfcsr, RFCSR20_RX_LO1_EN, 0);
5862 rt2800_rfcsr_write(rt2x00dev, 20, rfcsr);
5864 rt2800_rfcsr_read(rt2x00dev, 21, &rfcsr);
5865 rt2x00_set_field8(&rfcsr, RFCSR21_RX_LO2_EN, 0);
5866 rt2800_rfcsr_write(rt2x00dev, 21, rfcsr);
5870 static void rt2800_normal_mode_setup_3593(struct rt2x00_dev *rt2x00dev)
5872 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
5876 rt2800_rfcsr_read(rt2x00dev, 50, &rfcsr);
5877 rt2x00_set_field8(&rfcsr, RFCSR50_TX_LO2_EN, 0);
5878 rt2800_rfcsr_write(rt2x00dev, 50, rfcsr);
5880 rt2800_rfcsr_read(rt2x00dev, 51, &rfcsr);
5881 tx_gain = rt2x00_get_field8(drv_data->txmixer_gain_24g,
5882 RFCSR17_TXMIXER_GAIN);
5883 rt2x00_set_field8(&rfcsr, RFCSR51_BITS24, tx_gain);
5884 rt2800_rfcsr_write(rt2x00dev, 51, rfcsr);
5886 rt2800_rfcsr_read(rt2x00dev, 38, &rfcsr);
5887 rt2x00_set_field8(&rfcsr, RFCSR38_RX_LO1_EN, 0);
5888 rt2800_rfcsr_write(rt2x00dev, 38, rfcsr);
5890 rt2800_rfcsr_read(rt2x00dev, 39, &rfcsr);
5891 rt2x00_set_field8(&rfcsr, RFCSR39_RX_LO2_EN, 0);
5892 rt2800_rfcsr_write(rt2x00dev, 39, rfcsr);
5894 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
5895 rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
5896 rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1);
5897 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
5899 rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
5900 rt2x00_set_field8(&rfcsr, RFCSR30_RX_VCM, 2);
5901 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
5903 /* TODO: enable stream mode */
5906 static void rt2800_normal_mode_setup_5xxx(struct rt2x00_dev *rt2x00dev)
5911 /* Turn off unused DAC1 and ADC1 to reduce power consumption */
5912 rt2800_bbp_read(rt2x00dev, 138, ®);
5913 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom);
5914 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) == 1)
5915 rt2x00_set_field8(®, BBP138_RX_ADC1, 0);
5916 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) == 1)
5917 rt2x00_set_field8(®, BBP138_TX_DAC1, 1);
5918 rt2800_bbp_write(rt2x00dev, 138, reg);
5920 rt2800_rfcsr_read(rt2x00dev, 38, ®);
5921 rt2x00_set_field8(®, RFCSR38_RX_LO1_EN, 0);
5922 rt2800_rfcsr_write(rt2x00dev, 38, reg);
5924 rt2800_rfcsr_read(rt2x00dev, 39, ®);
5925 rt2x00_set_field8(®, RFCSR39_RX_LO2_EN, 0);
5926 rt2800_rfcsr_write(rt2x00dev, 39, reg);
5928 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
5930 rt2800_rfcsr_read(rt2x00dev, 30, ®);
5931 rt2x00_set_field8(®, RFCSR30_RX_VCM, 2);
5932 rt2800_rfcsr_write(rt2x00dev, 30, reg);
5935 static void rt2800_init_rfcsr_305x_soc(struct rt2x00_dev *rt2x00dev)
5937 rt2800_rf_init_calibration(rt2x00dev, 30);
5939 rt2800_rfcsr_write(rt2x00dev, 0, 0x50);
5940 rt2800_rfcsr_write(rt2x00dev, 1, 0x01);
5941 rt2800_rfcsr_write(rt2x00dev, 2, 0xf7);
5942 rt2800_rfcsr_write(rt2x00dev, 3, 0x75);
5943 rt2800_rfcsr_write(rt2x00dev, 4, 0x40);
5944 rt2800_rfcsr_write(rt2x00dev, 5, 0x03);
5945 rt2800_rfcsr_write(rt2x00dev, 6, 0x02);
5946 rt2800_rfcsr_write(rt2x00dev, 7, 0x50);
5947 rt2800_rfcsr_write(rt2x00dev, 8, 0x39);
5948 rt2800_rfcsr_write(rt2x00dev, 9, 0x0f);
5949 rt2800_rfcsr_write(rt2x00dev, 10, 0x60);
5950 rt2800_rfcsr_write(rt2x00dev, 11, 0x21);
5951 rt2800_rfcsr_write(rt2x00dev, 12, 0x75);
5952 rt2800_rfcsr_write(rt2x00dev, 13, 0x75);
5953 rt2800_rfcsr_write(rt2x00dev, 14, 0x90);
5954 rt2800_rfcsr_write(rt2x00dev, 15, 0x58);
5955 rt2800_rfcsr_write(rt2x00dev, 16, 0xb3);
5956 rt2800_rfcsr_write(rt2x00dev, 17, 0x92);
5957 rt2800_rfcsr_write(rt2x00dev, 18, 0x2c);
5958 rt2800_rfcsr_write(rt2x00dev, 19, 0x02);
5959 rt2800_rfcsr_write(rt2x00dev, 20, 0xba);
5960 rt2800_rfcsr_write(rt2x00dev, 21, 0xdb);
5961 rt2800_rfcsr_write(rt2x00dev, 22, 0x00);
5962 rt2800_rfcsr_write(rt2x00dev, 23, 0x31);
5963 rt2800_rfcsr_write(rt2x00dev, 24, 0x08);
5964 rt2800_rfcsr_write(rt2x00dev, 25, 0x01);
5965 rt2800_rfcsr_write(rt2x00dev, 26, 0x25);
5966 rt2800_rfcsr_write(rt2x00dev, 27, 0x23);
5967 rt2800_rfcsr_write(rt2x00dev, 28, 0x13);
5968 rt2800_rfcsr_write(rt2x00dev, 29, 0x83);
5969 rt2800_rfcsr_write(rt2x00dev, 30, 0x00);
5970 rt2800_rfcsr_write(rt2x00dev, 31, 0x00);
5973 static void rt2800_init_rfcsr_30xx(struct rt2x00_dev *rt2x00dev)
5979 /* XXX vendor driver do this only for 3070 */
5980 rt2800_rf_init_calibration(rt2x00dev, 30);
5982 rt2800_rfcsr_write(rt2x00dev, 4, 0x40);
5983 rt2800_rfcsr_write(rt2x00dev, 5, 0x03);
5984 rt2800_rfcsr_write(rt2x00dev, 6, 0x02);
5985 rt2800_rfcsr_write(rt2x00dev, 7, 0x60);
5986 rt2800_rfcsr_write(rt2x00dev, 9, 0x0f);
5987 rt2800_rfcsr_write(rt2x00dev, 10, 0x41);
5988 rt2800_rfcsr_write(rt2x00dev, 11, 0x21);
5989 rt2800_rfcsr_write(rt2x00dev, 12, 0x7b);
5990 rt2800_rfcsr_write(rt2x00dev, 14, 0x90);
5991 rt2800_rfcsr_write(rt2x00dev, 15, 0x58);
5992 rt2800_rfcsr_write(rt2x00dev, 16, 0xb3);
5993 rt2800_rfcsr_write(rt2x00dev, 17, 0x92);
5994 rt2800_rfcsr_write(rt2x00dev, 18, 0x2c);
5995 rt2800_rfcsr_write(rt2x00dev, 19, 0x02);
5996 rt2800_rfcsr_write(rt2x00dev, 20, 0xba);
5997 rt2800_rfcsr_write(rt2x00dev, 21, 0xdb);
5998 rt2800_rfcsr_write(rt2x00dev, 24, 0x16);
5999 rt2800_rfcsr_write(rt2x00dev, 25, 0x03);
6000 rt2800_rfcsr_write(rt2x00dev, 29, 0x1f);
6002 if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) {
6003 rt2800_register_read(rt2x00dev, LDO_CFG0, ®);
6004 rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1);
6005 rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 3);
6006 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
6007 } else if (rt2x00_rt(rt2x00dev, RT3071) ||
6008 rt2x00_rt(rt2x00dev, RT3090)) {
6009 rt2800_rfcsr_write(rt2x00dev, 31, 0x14);
6011 rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr);
6012 rt2x00_set_field8(&rfcsr, RFCSR6_R2, 1);
6013 rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
6015 rt2800_register_read(rt2x00dev, LDO_CFG0, ®);
6016 rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1);
6017 if (rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) ||
6018 rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E)) {
6019 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1,
6021 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_DAC_TEST))
6022 rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 3);
6024 rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 0);
6026 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
6028 rt2800_register_read(rt2x00dev, GPIO_SWITCH, ®);
6029 rt2x00_set_field32(®, GPIO_SWITCH_5, 0);
6030 rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg);
6033 rt2800_rx_filter_calibration(rt2x00dev);
6035 if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F) ||
6036 rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) ||
6037 rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E))
6038 rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
6040 rt2800_led_open_drain_enable(rt2x00dev);
6041 rt2800_normal_mode_setup_3xxx(rt2x00dev);
6044 static void rt2800_init_rfcsr_3290(struct rt2x00_dev *rt2x00dev)
6048 rt2800_rf_init_calibration(rt2x00dev, 2);
6050 rt2800_rfcsr_write(rt2x00dev, 1, 0x0f);
6051 rt2800_rfcsr_write(rt2x00dev, 2, 0x80);
6052 rt2800_rfcsr_write(rt2x00dev, 3, 0x08);
6053 rt2800_rfcsr_write(rt2x00dev, 4, 0x00);
6054 rt2800_rfcsr_write(rt2x00dev, 6, 0xa0);
6055 rt2800_rfcsr_write(rt2x00dev, 8, 0xf3);
6056 rt2800_rfcsr_write(rt2x00dev, 9, 0x02);
6057 rt2800_rfcsr_write(rt2x00dev, 10, 0x53);
6058 rt2800_rfcsr_write(rt2x00dev, 11, 0x4a);
6059 rt2800_rfcsr_write(rt2x00dev, 12, 0x46);
6060 rt2800_rfcsr_write(rt2x00dev, 13, 0x9f);
6061 rt2800_rfcsr_write(rt2x00dev, 18, 0x02);
6062 rt2800_rfcsr_write(rt2x00dev, 22, 0x20);
6063 rt2800_rfcsr_write(rt2x00dev, 25, 0x83);
6064 rt2800_rfcsr_write(rt2x00dev, 26, 0x82);
6065 rt2800_rfcsr_write(rt2x00dev, 27, 0x09);
6066 rt2800_rfcsr_write(rt2x00dev, 29, 0x10);
6067 rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
6068 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
6069 rt2800_rfcsr_write(rt2x00dev, 32, 0x80);
6070 rt2800_rfcsr_write(rt2x00dev, 33, 0x00);
6071 rt2800_rfcsr_write(rt2x00dev, 34, 0x05);
6072 rt2800_rfcsr_write(rt2x00dev, 35, 0x12);
6073 rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
6074 rt2800_rfcsr_write(rt2x00dev, 38, 0x85);
6075 rt2800_rfcsr_write(rt2x00dev, 39, 0x1b);
6076 rt2800_rfcsr_write(rt2x00dev, 40, 0x0b);
6077 rt2800_rfcsr_write(rt2x00dev, 41, 0xbb);
6078 rt2800_rfcsr_write(rt2x00dev, 42, 0xd5);
6079 rt2800_rfcsr_write(rt2x00dev, 43, 0x7b);
6080 rt2800_rfcsr_write(rt2x00dev, 44, 0x0e);
6081 rt2800_rfcsr_write(rt2x00dev, 45, 0xa2);
6082 rt2800_rfcsr_write(rt2x00dev, 46, 0x73);
6083 rt2800_rfcsr_write(rt2x00dev, 47, 0x00);
6084 rt2800_rfcsr_write(rt2x00dev, 48, 0x10);
6085 rt2800_rfcsr_write(rt2x00dev, 49, 0x98);
6086 rt2800_rfcsr_write(rt2x00dev, 52, 0x38);
6087 rt2800_rfcsr_write(rt2x00dev, 53, 0x00);
6088 rt2800_rfcsr_write(rt2x00dev, 54, 0x78);
6089 rt2800_rfcsr_write(rt2x00dev, 55, 0x43);
6090 rt2800_rfcsr_write(rt2x00dev, 56, 0x02);
6091 rt2800_rfcsr_write(rt2x00dev, 57, 0x80);
6092 rt2800_rfcsr_write(rt2x00dev, 58, 0x7f);
6093 rt2800_rfcsr_write(rt2x00dev, 59, 0x09);
6094 rt2800_rfcsr_write(rt2x00dev, 60, 0x45);
6095 rt2800_rfcsr_write(rt2x00dev, 61, 0xc1);
6097 rt2800_rfcsr_read(rt2x00dev, 29, &rfcsr);
6098 rt2x00_set_field8(&rfcsr, RFCSR29_RSSI_GAIN, 3);
6099 rt2800_rfcsr_write(rt2x00dev, 29, rfcsr);
6101 rt2800_led_open_drain_enable(rt2x00dev);
6102 rt2800_normal_mode_setup_3xxx(rt2x00dev);
6105 static void rt2800_init_rfcsr_3352(struct rt2x00_dev *rt2x00dev)
6107 rt2800_rf_init_calibration(rt2x00dev, 30);
6109 rt2800_rfcsr_write(rt2x00dev, 0, 0xf0);
6110 rt2800_rfcsr_write(rt2x00dev, 1, 0x23);
6111 rt2800_rfcsr_write(rt2x00dev, 2, 0x50);
6112 rt2800_rfcsr_write(rt2x00dev, 3, 0x18);
6113 rt2800_rfcsr_write(rt2x00dev, 4, 0x00);
6114 rt2800_rfcsr_write(rt2x00dev, 5, 0x00);
6115 rt2800_rfcsr_write(rt2x00dev, 6, 0x33);
6116 rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
6117 rt2800_rfcsr_write(rt2x00dev, 8, 0xf1);
6118 rt2800_rfcsr_write(rt2x00dev, 9, 0x02);
6119 rt2800_rfcsr_write(rt2x00dev, 10, 0xd2);
6120 rt2800_rfcsr_write(rt2x00dev, 11, 0x42);
6121 rt2800_rfcsr_write(rt2x00dev, 12, 0x1c);
6122 rt2800_rfcsr_write(rt2x00dev, 13, 0x00);
6123 rt2800_rfcsr_write(rt2x00dev, 14, 0x5a);
6124 rt2800_rfcsr_write(rt2x00dev, 15, 0x00);
6125 rt2800_rfcsr_write(rt2x00dev, 16, 0x01);
6126 rt2800_rfcsr_write(rt2x00dev, 18, 0x45);
6127 rt2800_rfcsr_write(rt2x00dev, 19, 0x02);
6128 rt2800_rfcsr_write(rt2x00dev, 20, 0x00);
6129 rt2800_rfcsr_write(rt2x00dev, 21, 0x00);
6130 rt2800_rfcsr_write(rt2x00dev, 22, 0x00);
6131 rt2800_rfcsr_write(rt2x00dev, 23, 0x00);
6132 rt2800_rfcsr_write(rt2x00dev, 24, 0x00);
6133 rt2800_rfcsr_write(rt2x00dev, 25, 0x80);
6134 rt2800_rfcsr_write(rt2x00dev, 26, 0x00);
6135 rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
6136 rt2800_rfcsr_write(rt2x00dev, 28, 0x03);
6137 rt2800_rfcsr_write(rt2x00dev, 29, 0x00);
6138 rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
6139 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
6140 rt2800_rfcsr_write(rt2x00dev, 32, 0x80);
6141 rt2800_rfcsr_write(rt2x00dev, 33, 0x00);
6142 rt2800_rfcsr_write(rt2x00dev, 34, 0x01);
6143 rt2800_rfcsr_write(rt2x00dev, 35, 0x03);
6144 rt2800_rfcsr_write(rt2x00dev, 36, 0xbd);
6145 rt2800_rfcsr_write(rt2x00dev, 37, 0x3c);
6146 rt2800_rfcsr_write(rt2x00dev, 38, 0x5f);
6147 rt2800_rfcsr_write(rt2x00dev, 39, 0xc5);
6148 rt2800_rfcsr_write(rt2x00dev, 40, 0x33);
6149 rt2800_rfcsr_write(rt2x00dev, 41, 0x5b);
6150 rt2800_rfcsr_write(rt2x00dev, 42, 0x5b);
6151 rt2800_rfcsr_write(rt2x00dev, 43, 0xdb);
6152 rt2800_rfcsr_write(rt2x00dev, 44, 0xdb);
6153 rt2800_rfcsr_write(rt2x00dev, 45, 0xdb);
6154 rt2800_rfcsr_write(rt2x00dev, 46, 0xdd);
6155 rt2800_rfcsr_write(rt2x00dev, 47, 0x0d);
6156 rt2800_rfcsr_write(rt2x00dev, 48, 0x14);
6157 rt2800_rfcsr_write(rt2x00dev, 49, 0x00);
6158 rt2800_rfcsr_write(rt2x00dev, 50, 0x2d);
6159 rt2800_rfcsr_write(rt2x00dev, 51, 0x7f);
6160 rt2800_rfcsr_write(rt2x00dev, 52, 0x00);
6161 rt2800_rfcsr_write(rt2x00dev, 53, 0x52);
6162 rt2800_rfcsr_write(rt2x00dev, 54, 0x1b);
6163 rt2800_rfcsr_write(rt2x00dev, 55, 0x7f);
6164 rt2800_rfcsr_write(rt2x00dev, 56, 0x00);
6165 rt2800_rfcsr_write(rt2x00dev, 57, 0x52);
6166 rt2800_rfcsr_write(rt2x00dev, 58, 0x1b);
6167 rt2800_rfcsr_write(rt2x00dev, 59, 0x00);
6168 rt2800_rfcsr_write(rt2x00dev, 60, 0x00);
6169 rt2800_rfcsr_write(rt2x00dev, 61, 0x00);
6170 rt2800_rfcsr_write(rt2x00dev, 62, 0x00);
6171 rt2800_rfcsr_write(rt2x00dev, 63, 0x00);
6173 rt2800_rx_filter_calibration(rt2x00dev);
6174 rt2800_led_open_drain_enable(rt2x00dev);
6175 rt2800_normal_mode_setup_3xxx(rt2x00dev);
6178 static void rt2800_init_rfcsr_3390(struct rt2x00_dev *rt2x00dev)
6182 rt2800_rf_init_calibration(rt2x00dev, 30);
6184 rt2800_rfcsr_write(rt2x00dev, 0, 0xa0);
6185 rt2800_rfcsr_write(rt2x00dev, 1, 0xe1);
6186 rt2800_rfcsr_write(rt2x00dev, 2, 0xf1);
6187 rt2800_rfcsr_write(rt2x00dev, 3, 0x62);
6188 rt2800_rfcsr_write(rt2x00dev, 4, 0x40);
6189 rt2800_rfcsr_write(rt2x00dev, 5, 0x8b);
6190 rt2800_rfcsr_write(rt2x00dev, 6, 0x42);
6191 rt2800_rfcsr_write(rt2x00dev, 7, 0x34);
6192 rt2800_rfcsr_write(rt2x00dev, 8, 0x00);
6193 rt2800_rfcsr_write(rt2x00dev, 9, 0xc0);
6194 rt2800_rfcsr_write(rt2x00dev, 10, 0x61);
6195 rt2800_rfcsr_write(rt2x00dev, 11, 0x21);
6196 rt2800_rfcsr_write(rt2x00dev, 12, 0x3b);
6197 rt2800_rfcsr_write(rt2x00dev, 13, 0xe0);
6198 rt2800_rfcsr_write(rt2x00dev, 14, 0x90);
6199 rt2800_rfcsr_write(rt2x00dev, 15, 0x53);
6200 rt2800_rfcsr_write(rt2x00dev, 16, 0xe0);
6201 rt2800_rfcsr_write(rt2x00dev, 17, 0x94);
6202 rt2800_rfcsr_write(rt2x00dev, 18, 0x5c);
6203 rt2800_rfcsr_write(rt2x00dev, 19, 0x4a);
6204 rt2800_rfcsr_write(rt2x00dev, 20, 0xb2);
6205 rt2800_rfcsr_write(rt2x00dev, 21, 0xf6);
6206 rt2800_rfcsr_write(rt2x00dev, 22, 0x00);
6207 rt2800_rfcsr_write(rt2x00dev, 23, 0x14);
6208 rt2800_rfcsr_write(rt2x00dev, 24, 0x08);
6209 rt2800_rfcsr_write(rt2x00dev, 25, 0x3d);
6210 rt2800_rfcsr_write(rt2x00dev, 26, 0x85);
6211 rt2800_rfcsr_write(rt2x00dev, 27, 0x00);
6212 rt2800_rfcsr_write(rt2x00dev, 28, 0x41);
6213 rt2800_rfcsr_write(rt2x00dev, 29, 0x8f);
6214 rt2800_rfcsr_write(rt2x00dev, 30, 0x20);
6215 rt2800_rfcsr_write(rt2x00dev, 31, 0x0f);
6217 rt2800_register_read(rt2x00dev, GPIO_SWITCH, ®);
6218 rt2x00_set_field32(®, GPIO_SWITCH_5, 0);
6219 rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg);
6221 rt2800_rx_filter_calibration(rt2x00dev);
6223 if (rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E))
6224 rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
6226 rt2800_led_open_drain_enable(rt2x00dev);
6227 rt2800_normal_mode_setup_3xxx(rt2x00dev);
6230 static void rt2800_init_rfcsr_3572(struct rt2x00_dev *rt2x00dev)
6235 rt2800_rf_init_calibration(rt2x00dev, 30);
6237 rt2800_rfcsr_write(rt2x00dev, 0, 0x70);
6238 rt2800_rfcsr_write(rt2x00dev, 1, 0x81);
6239 rt2800_rfcsr_write(rt2x00dev, 2, 0xf1);
6240 rt2800_rfcsr_write(rt2x00dev, 3, 0x02);
6241 rt2800_rfcsr_write(rt2x00dev, 4, 0x4c);
6242 rt2800_rfcsr_write(rt2x00dev, 5, 0x05);
6243 rt2800_rfcsr_write(rt2x00dev, 6, 0x4a);
6244 rt2800_rfcsr_write(rt2x00dev, 7, 0xd8);
6245 rt2800_rfcsr_write(rt2x00dev, 9, 0xc3);
6246 rt2800_rfcsr_write(rt2x00dev, 10, 0xf1);
6247 rt2800_rfcsr_write(rt2x00dev, 11, 0xb9);
6248 rt2800_rfcsr_write(rt2x00dev, 12, 0x70);
6249 rt2800_rfcsr_write(rt2x00dev, 13, 0x65);
6250 rt2800_rfcsr_write(rt2x00dev, 14, 0xa0);
6251 rt2800_rfcsr_write(rt2x00dev, 15, 0x53);
6252 rt2800_rfcsr_write(rt2x00dev, 16, 0x4c);
6253 rt2800_rfcsr_write(rt2x00dev, 17, 0x23);
6254 rt2800_rfcsr_write(rt2x00dev, 18, 0xac);
6255 rt2800_rfcsr_write(rt2x00dev, 19, 0x93);
6256 rt2800_rfcsr_write(rt2x00dev, 20, 0xb3);
6257 rt2800_rfcsr_write(rt2x00dev, 21, 0xd0);
6258 rt2800_rfcsr_write(rt2x00dev, 22, 0x00);
6259 rt2800_rfcsr_write(rt2x00dev, 23, 0x3c);
6260 rt2800_rfcsr_write(rt2x00dev, 24, 0x16);
6261 rt2800_rfcsr_write(rt2x00dev, 25, 0x15);
6262 rt2800_rfcsr_write(rt2x00dev, 26, 0x85);
6263 rt2800_rfcsr_write(rt2x00dev, 27, 0x00);
6264 rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
6265 rt2800_rfcsr_write(rt2x00dev, 29, 0x9b);
6266 rt2800_rfcsr_write(rt2x00dev, 30, 0x09);
6267 rt2800_rfcsr_write(rt2x00dev, 31, 0x10);
6269 rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr);
6270 rt2x00_set_field8(&rfcsr, RFCSR6_R2, 1);
6271 rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
6273 rt2800_register_read(rt2x00dev, LDO_CFG0, ®);
6274 rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 3);
6275 rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1);
6276 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
6278 rt2800_register_read(rt2x00dev, LDO_CFG0, ®);
6279 rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 0);
6280 rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1);
6281 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
6283 rt2800_rx_filter_calibration(rt2x00dev);
6284 rt2800_led_open_drain_enable(rt2x00dev);
6285 rt2800_normal_mode_setup_3xxx(rt2x00dev);
6288 static void rt3593_post_bbp_init(struct rt2x00_dev *rt2x00dev)
6291 bool txbf_enabled = false; /* FIXME */
6293 rt2800_bbp_read(rt2x00dev, 105, &bbp);
6294 if (rt2x00dev->default_ant.rx_chain_num == 1)
6295 rt2x00_set_field8(&bbp, BBP105_MLD, 0);
6297 rt2x00_set_field8(&bbp, BBP105_MLD, 1);
6298 rt2800_bbp_write(rt2x00dev, 105, bbp);
6300 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
6302 rt2800_bbp_write(rt2x00dev, 92, 0x02);
6303 rt2800_bbp_write(rt2x00dev, 82, 0x82);
6304 rt2800_bbp_write(rt2x00dev, 106, 0x05);
6305 rt2800_bbp_write(rt2x00dev, 104, 0x92);
6306 rt2800_bbp_write(rt2x00dev, 88, 0x90);
6307 rt2800_bbp_write(rt2x00dev, 148, 0xc8);
6308 rt2800_bbp_write(rt2x00dev, 47, 0x48);
6309 rt2800_bbp_write(rt2x00dev, 120, 0x50);
6312 rt2800_bbp_write(rt2x00dev, 163, 0xbd);
6314 rt2800_bbp_write(rt2x00dev, 163, 0x9d);
6317 rt2800_bbp_write(rt2x00dev, 142, 6);
6318 rt2800_bbp_write(rt2x00dev, 143, 160);
6319 rt2800_bbp_write(rt2x00dev, 142, 7);
6320 rt2800_bbp_write(rt2x00dev, 143, 161);
6321 rt2800_bbp_write(rt2x00dev, 142, 8);
6322 rt2800_bbp_write(rt2x00dev, 143, 162);
6324 /* ADC/DAC control */
6325 rt2800_bbp_write(rt2x00dev, 31, 0x08);
6327 /* RX AGC energy lower bound in log2 */
6328 rt2800_bbp_write(rt2x00dev, 68, 0x0b);
6330 /* FIXME: BBP 105 owerwrite? */
6331 rt2800_bbp_write(rt2x00dev, 105, 0x04);
6335 static void rt2800_init_rfcsr_3593(struct rt2x00_dev *rt2x00dev)
6337 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
6341 /* Disable GPIO #4 and #7 function for LAN PE control */
6342 rt2800_register_read(rt2x00dev, GPIO_SWITCH, ®);
6343 rt2x00_set_field32(®, GPIO_SWITCH_4, 0);
6344 rt2x00_set_field32(®, GPIO_SWITCH_7, 0);
6345 rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg);
6347 /* Initialize default register values */
6348 rt2800_rfcsr_write(rt2x00dev, 1, 0x03);
6349 rt2800_rfcsr_write(rt2x00dev, 3, 0x80);
6350 rt2800_rfcsr_write(rt2x00dev, 5, 0x00);
6351 rt2800_rfcsr_write(rt2x00dev, 6, 0x40);
6352 rt2800_rfcsr_write(rt2x00dev, 8, 0xf1);
6353 rt2800_rfcsr_write(rt2x00dev, 9, 0x02);
6354 rt2800_rfcsr_write(rt2x00dev, 10, 0xd3);
6355 rt2800_rfcsr_write(rt2x00dev, 11, 0x40);
6356 rt2800_rfcsr_write(rt2x00dev, 12, 0x4e);
6357 rt2800_rfcsr_write(rt2x00dev, 13, 0x12);
6358 rt2800_rfcsr_write(rt2x00dev, 18, 0x40);
6359 rt2800_rfcsr_write(rt2x00dev, 22, 0x20);
6360 rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
6361 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
6362 rt2800_rfcsr_write(rt2x00dev, 32, 0x78);
6363 rt2800_rfcsr_write(rt2x00dev, 33, 0x3b);
6364 rt2800_rfcsr_write(rt2x00dev, 34, 0x3c);
6365 rt2800_rfcsr_write(rt2x00dev, 35, 0xe0);
6366 rt2800_rfcsr_write(rt2x00dev, 38, 0x86);
6367 rt2800_rfcsr_write(rt2x00dev, 39, 0x23);
6368 rt2800_rfcsr_write(rt2x00dev, 44, 0xd3);
6369 rt2800_rfcsr_write(rt2x00dev, 45, 0xbb);
6370 rt2800_rfcsr_write(rt2x00dev, 46, 0x60);
6371 rt2800_rfcsr_write(rt2x00dev, 49, 0x8e);
6372 rt2800_rfcsr_write(rt2x00dev, 50, 0x86);
6373 rt2800_rfcsr_write(rt2x00dev, 51, 0x75);
6374 rt2800_rfcsr_write(rt2x00dev, 52, 0x45);
6375 rt2800_rfcsr_write(rt2x00dev, 53, 0x18);
6376 rt2800_rfcsr_write(rt2x00dev, 54, 0x18);
6377 rt2800_rfcsr_write(rt2x00dev, 55, 0x18);
6378 rt2800_rfcsr_write(rt2x00dev, 56, 0xdb);
6379 rt2800_rfcsr_write(rt2x00dev, 57, 0x6e);
6381 /* Initiate calibration */
6382 /* TODO: use rt2800_rf_init_calibration ? */
6383 rt2800_rfcsr_read(rt2x00dev, 2, &rfcsr);
6384 rt2x00_set_field8(&rfcsr, RFCSR2_RESCAL_EN, 1);
6385 rt2800_rfcsr_write(rt2x00dev, 2, rfcsr);
6387 rt2800_adjust_freq_offset(rt2x00dev);
6389 rt2800_rfcsr_read(rt2x00dev, 18, &rfcsr);
6390 rt2x00_set_field8(&rfcsr, RFCSR18_XO_TUNE_BYPASS, 1);
6391 rt2800_rfcsr_write(rt2x00dev, 18, rfcsr);
6393 rt2800_register_read(rt2x00dev, LDO_CFG0, ®);
6394 rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 3);
6395 rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1);
6396 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
6397 usleep_range(1000, 1500);
6398 rt2800_register_read(rt2x00dev, LDO_CFG0, ®);
6399 rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 0);
6400 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
6402 /* Set initial values for RX filter calibration */
6403 drv_data->calibration_bw20 = 0x1f;
6404 drv_data->calibration_bw40 = 0x2f;
6406 /* Save BBP 25 & 26 values for later use in channel switching */
6407 rt2800_bbp_read(rt2x00dev, 25, &drv_data->bbp25);
6408 rt2800_bbp_read(rt2x00dev, 26, &drv_data->bbp26);
6410 rt2800_led_open_drain_enable(rt2x00dev);
6411 rt2800_normal_mode_setup_3593(rt2x00dev);
6413 rt3593_post_bbp_init(rt2x00dev);
6415 /* TODO: enable stream mode support */
6418 static void rt2800_init_rfcsr_5390(struct rt2x00_dev *rt2x00dev)
6420 rt2800_rf_init_calibration(rt2x00dev, 2);
6422 rt2800_rfcsr_write(rt2x00dev, 1, 0x0f);
6423 rt2800_rfcsr_write(rt2x00dev, 2, 0x80);
6424 rt2800_rfcsr_write(rt2x00dev, 3, 0x88);
6425 rt2800_rfcsr_write(rt2x00dev, 5, 0x10);
6426 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
6427 rt2800_rfcsr_write(rt2x00dev, 6, 0xe0);
6429 rt2800_rfcsr_write(rt2x00dev, 6, 0xa0);
6430 rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
6431 rt2800_rfcsr_write(rt2x00dev, 10, 0x53);
6432 rt2800_rfcsr_write(rt2x00dev, 11, 0x4a);
6433 rt2800_rfcsr_write(rt2x00dev, 12, 0xc6);
6434 rt2800_rfcsr_write(rt2x00dev, 13, 0x9f);
6435 rt2800_rfcsr_write(rt2x00dev, 14, 0x00);
6436 rt2800_rfcsr_write(rt2x00dev, 15, 0x00);
6437 rt2800_rfcsr_write(rt2x00dev, 16, 0x00);
6438 rt2800_rfcsr_write(rt2x00dev, 18, 0x03);
6439 rt2800_rfcsr_write(rt2x00dev, 19, 0x00);
6441 rt2800_rfcsr_write(rt2x00dev, 20, 0x00);
6442 rt2800_rfcsr_write(rt2x00dev, 21, 0x00);
6443 rt2800_rfcsr_write(rt2x00dev, 22, 0x20);
6444 rt2800_rfcsr_write(rt2x00dev, 23, 0x00);
6445 rt2800_rfcsr_write(rt2x00dev, 24, 0x00);
6446 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
6447 rt2800_rfcsr_write(rt2x00dev, 25, 0x80);
6449 rt2800_rfcsr_write(rt2x00dev, 25, 0xc0);
6450 rt2800_rfcsr_write(rt2x00dev, 26, 0x00);
6451 rt2800_rfcsr_write(rt2x00dev, 27, 0x09);
6452 rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
6453 rt2800_rfcsr_write(rt2x00dev, 29, 0x10);
6455 rt2800_rfcsr_write(rt2x00dev, 30, 0x00);
6456 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
6457 rt2800_rfcsr_write(rt2x00dev, 32, 0x80);
6458 rt2800_rfcsr_write(rt2x00dev, 33, 0x00);
6459 rt2800_rfcsr_write(rt2x00dev, 34, 0x07);
6460 rt2800_rfcsr_write(rt2x00dev, 35, 0x12);
6461 rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
6462 rt2800_rfcsr_write(rt2x00dev, 37, 0x08);
6463 rt2800_rfcsr_write(rt2x00dev, 38, 0x85);
6464 rt2800_rfcsr_write(rt2x00dev, 39, 0x1b);
6466 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
6467 rt2800_rfcsr_write(rt2x00dev, 40, 0x0b);
6469 rt2800_rfcsr_write(rt2x00dev, 40, 0x4b);
6470 rt2800_rfcsr_write(rt2x00dev, 41, 0xbb);
6471 rt2800_rfcsr_write(rt2x00dev, 42, 0xd2);
6472 rt2800_rfcsr_write(rt2x00dev, 43, 0x9a);
6473 rt2800_rfcsr_write(rt2x00dev, 44, 0x0e);
6474 rt2800_rfcsr_write(rt2x00dev, 45, 0xa2);
6475 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
6476 rt2800_rfcsr_write(rt2x00dev, 46, 0x73);
6478 rt2800_rfcsr_write(rt2x00dev, 46, 0x7b);
6479 rt2800_rfcsr_write(rt2x00dev, 47, 0x00);
6480 rt2800_rfcsr_write(rt2x00dev, 48, 0x10);
6481 rt2800_rfcsr_write(rt2x00dev, 49, 0x94);
6483 rt2800_rfcsr_write(rt2x00dev, 52, 0x38);
6484 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
6485 rt2800_rfcsr_write(rt2x00dev, 53, 0x00);
6487 rt2800_rfcsr_write(rt2x00dev, 53, 0x84);
6488 rt2800_rfcsr_write(rt2x00dev, 54, 0x78);
6489 rt2800_rfcsr_write(rt2x00dev, 55, 0x44);
6490 rt2800_rfcsr_write(rt2x00dev, 56, 0x22);
6491 rt2800_rfcsr_write(rt2x00dev, 57, 0x80);
6492 rt2800_rfcsr_write(rt2x00dev, 58, 0x7f);
6493 rt2800_rfcsr_write(rt2x00dev, 59, 0x63);
6495 rt2800_rfcsr_write(rt2x00dev, 60, 0x45);
6496 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
6497 rt2800_rfcsr_write(rt2x00dev, 61, 0xd1);
6499 rt2800_rfcsr_write(rt2x00dev, 61, 0xdd);
6500 rt2800_rfcsr_write(rt2x00dev, 62, 0x00);
6501 rt2800_rfcsr_write(rt2x00dev, 63, 0x00);
6503 rt2800_normal_mode_setup_5xxx(rt2x00dev);
6505 rt2800_led_open_drain_enable(rt2x00dev);
6508 static void rt2800_init_rfcsr_5392(struct rt2x00_dev *rt2x00dev)
6510 rt2800_rf_init_calibration(rt2x00dev, 2);
6512 rt2800_rfcsr_write(rt2x00dev, 1, 0x17);
6513 rt2800_rfcsr_write(rt2x00dev, 2, 0x80);
6514 rt2800_rfcsr_write(rt2x00dev, 3, 0x88);
6515 rt2800_rfcsr_write(rt2x00dev, 5, 0x10);
6516 rt2800_rfcsr_write(rt2x00dev, 6, 0xe0);
6517 rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
6518 rt2800_rfcsr_write(rt2x00dev, 10, 0x53);
6519 rt2800_rfcsr_write(rt2x00dev, 11, 0x4a);
6520 rt2800_rfcsr_write(rt2x00dev, 12, 0x46);
6521 rt2800_rfcsr_write(rt2x00dev, 13, 0x9f);
6522 rt2800_rfcsr_write(rt2x00dev, 14, 0x00);
6523 rt2800_rfcsr_write(rt2x00dev, 15, 0x00);
6524 rt2800_rfcsr_write(rt2x00dev, 16, 0x00);
6525 rt2800_rfcsr_write(rt2x00dev, 18, 0x03);
6526 rt2800_rfcsr_write(rt2x00dev, 19, 0x4d);
6527 rt2800_rfcsr_write(rt2x00dev, 20, 0x00);
6528 rt2800_rfcsr_write(rt2x00dev, 21, 0x8d);
6529 rt2800_rfcsr_write(rt2x00dev, 22, 0x20);
6530 rt2800_rfcsr_write(rt2x00dev, 23, 0x0b);
6531 rt2800_rfcsr_write(rt2x00dev, 24, 0x44);
6532 rt2800_rfcsr_write(rt2x00dev, 25, 0x80);
6533 rt2800_rfcsr_write(rt2x00dev, 26, 0x82);
6534 rt2800_rfcsr_write(rt2x00dev, 27, 0x09);
6535 rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
6536 rt2800_rfcsr_write(rt2x00dev, 29, 0x10);
6537 rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
6538 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
6539 rt2800_rfcsr_write(rt2x00dev, 32, 0x20);
6540 rt2800_rfcsr_write(rt2x00dev, 33, 0xC0);
6541 rt2800_rfcsr_write(rt2x00dev, 34, 0x07);
6542 rt2800_rfcsr_write(rt2x00dev, 35, 0x12);
6543 rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
6544 rt2800_rfcsr_write(rt2x00dev, 37, 0x08);
6545 rt2800_rfcsr_write(rt2x00dev, 38, 0x89);
6546 rt2800_rfcsr_write(rt2x00dev, 39, 0x1b);
6547 rt2800_rfcsr_write(rt2x00dev, 40, 0x0f);
6548 rt2800_rfcsr_write(rt2x00dev, 41, 0xbb);
6549 rt2800_rfcsr_write(rt2x00dev, 42, 0xd5);
6550 rt2800_rfcsr_write(rt2x00dev, 43, 0x9b);
6551 rt2800_rfcsr_write(rt2x00dev, 44, 0x0e);
6552 rt2800_rfcsr_write(rt2x00dev, 45, 0xa2);
6553 rt2800_rfcsr_write(rt2x00dev, 46, 0x73);
6554 rt2800_rfcsr_write(rt2x00dev, 47, 0x0c);
6555 rt2800_rfcsr_write(rt2x00dev, 48, 0x10);
6556 rt2800_rfcsr_write(rt2x00dev, 49, 0x94);
6557 rt2800_rfcsr_write(rt2x00dev, 50, 0x94);
6558 rt2800_rfcsr_write(rt2x00dev, 51, 0x3a);
6559 rt2800_rfcsr_write(rt2x00dev, 52, 0x48);
6560 rt2800_rfcsr_write(rt2x00dev, 53, 0x44);
6561 rt2800_rfcsr_write(rt2x00dev, 54, 0x38);
6562 rt2800_rfcsr_write(rt2x00dev, 55, 0x43);
6563 rt2800_rfcsr_write(rt2x00dev, 56, 0xa1);
6564 rt2800_rfcsr_write(rt2x00dev, 57, 0x00);
6565 rt2800_rfcsr_write(rt2x00dev, 58, 0x39);
6566 rt2800_rfcsr_write(rt2x00dev, 59, 0x07);
6567 rt2800_rfcsr_write(rt2x00dev, 60, 0x45);
6568 rt2800_rfcsr_write(rt2x00dev, 61, 0x91);
6569 rt2800_rfcsr_write(rt2x00dev, 62, 0x39);
6570 rt2800_rfcsr_write(rt2x00dev, 63, 0x07);
6572 rt2800_normal_mode_setup_5xxx(rt2x00dev);
6574 rt2800_led_open_drain_enable(rt2x00dev);
6577 static void rt2800_init_rfcsr_5592(struct rt2x00_dev *rt2x00dev)
6579 rt2800_rf_init_calibration(rt2x00dev, 30);
6581 rt2800_rfcsr_write(rt2x00dev, 1, 0x3F);
6582 rt2800_rfcsr_write(rt2x00dev, 3, 0x08);
6583 rt2800_rfcsr_write(rt2x00dev, 3, 0x08);
6584 rt2800_rfcsr_write(rt2x00dev, 5, 0x10);
6585 rt2800_rfcsr_write(rt2x00dev, 6, 0xE4);
6586 rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
6587 rt2800_rfcsr_write(rt2x00dev, 14, 0x00);
6588 rt2800_rfcsr_write(rt2x00dev, 15, 0x00);
6589 rt2800_rfcsr_write(rt2x00dev, 16, 0x00);
6590 rt2800_rfcsr_write(rt2x00dev, 18, 0x03);
6591 rt2800_rfcsr_write(rt2x00dev, 19, 0x4D);
6592 rt2800_rfcsr_write(rt2x00dev, 20, 0x10);
6593 rt2800_rfcsr_write(rt2x00dev, 21, 0x8D);
6594 rt2800_rfcsr_write(rt2x00dev, 26, 0x82);
6595 rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
6596 rt2800_rfcsr_write(rt2x00dev, 29, 0x10);
6597 rt2800_rfcsr_write(rt2x00dev, 33, 0xC0);
6598 rt2800_rfcsr_write(rt2x00dev, 34, 0x07);
6599 rt2800_rfcsr_write(rt2x00dev, 35, 0x12);
6600 rt2800_rfcsr_write(rt2x00dev, 47, 0x0C);
6601 rt2800_rfcsr_write(rt2x00dev, 53, 0x22);
6602 rt2800_rfcsr_write(rt2x00dev, 63, 0x07);
6604 rt2800_rfcsr_write(rt2x00dev, 2, 0x80);
6607 rt2800_adjust_freq_offset(rt2x00dev);
6609 /* Enable DC filter */
6610 if (rt2x00_rt_rev_gte(rt2x00dev, RT5592, REV_RT5592C))
6611 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
6613 rt2800_normal_mode_setup_5xxx(rt2x00dev);
6615 if (rt2x00_rt_rev_lt(rt2x00dev, RT5592, REV_RT5592C))
6616 rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
6618 rt2800_led_open_drain_enable(rt2x00dev);
6621 static void rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev)
6623 if (rt2800_is_305x_soc(rt2x00dev)) {
6624 rt2800_init_rfcsr_305x_soc(rt2x00dev);
6628 switch (rt2x00dev->chip.rt) {
6632 rt2800_init_rfcsr_30xx(rt2x00dev);
6635 rt2800_init_rfcsr_3290(rt2x00dev);
6638 rt2800_init_rfcsr_3352(rt2x00dev);
6641 rt2800_init_rfcsr_3390(rt2x00dev);
6644 rt2800_init_rfcsr_3572(rt2x00dev);
6647 rt2800_init_rfcsr_3593(rt2x00dev);
6650 rt2800_init_rfcsr_5390(rt2x00dev);
6653 rt2800_init_rfcsr_5392(rt2x00dev);
6656 rt2800_init_rfcsr_5592(rt2x00dev);
6661 int rt2800_enable_radio(struct rt2x00_dev *rt2x00dev)
6667 * Initialize MAC registers.
6669 if (unlikely(rt2800_wait_wpdma_ready(rt2x00dev) ||
6670 rt2800_init_registers(rt2x00dev)))
6674 * Wait BBP/RF to wake up.
6676 if (unlikely(rt2800_wait_bbp_rf_ready(rt2x00dev)))
6680 * Send signal during boot time to initialize firmware.
6682 rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
6683 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
6684 if (rt2x00_is_usb(rt2x00dev))
6685 rt2800_register_write(rt2x00dev, H2M_INT_SRC, 0);
6686 rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0, 0, 0);
6690 * Make sure BBP is up and running.
6692 if (unlikely(rt2800_wait_bbp_ready(rt2x00dev)))
6696 * Initialize BBP/RF registers.
6698 rt2800_init_bbp(rt2x00dev);
6699 rt2800_init_rfcsr(rt2x00dev);
6701 if (rt2x00_is_usb(rt2x00dev) &&
6702 (rt2x00_rt(rt2x00dev, RT3070) ||
6703 rt2x00_rt(rt2x00dev, RT3071) ||
6704 rt2x00_rt(rt2x00dev, RT3572))) {
6706 rt2800_mcu_request(rt2x00dev, MCU_CURRENT, 0, 0, 0);
6713 rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, ®);
6714 rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_TX, 1);
6715 rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, 0);
6716 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
6720 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®);
6721 rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 1);
6722 rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 1);
6723 rt2x00_set_field32(®, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 2);
6724 rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
6725 rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
6727 rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, ®);
6728 rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_TX, 1);
6729 rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, 1);
6730 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
6733 * Initialize LED control
6735 rt2800_eeprom_read(rt2x00dev, EEPROM_LED_AG_CONF, &word);
6736 rt2800_mcu_request(rt2x00dev, MCU_LED_AG_CONF, 0xff,
6737 word & 0xff, (word >> 8) & 0xff);
6739 rt2800_eeprom_read(rt2x00dev, EEPROM_LED_ACT_CONF, &word);
6740 rt2800_mcu_request(rt2x00dev, MCU_LED_ACT_CONF, 0xff,
6741 word & 0xff, (word >> 8) & 0xff);
6743 rt2800_eeprom_read(rt2x00dev, EEPROM_LED_POLARITY, &word);
6744 rt2800_mcu_request(rt2x00dev, MCU_LED_LED_POLARITY, 0xff,
6745 word & 0xff, (word >> 8) & 0xff);
6749 EXPORT_SYMBOL_GPL(rt2800_enable_radio);
6751 void rt2800_disable_radio(struct rt2x00_dev *rt2x00dev)
6755 rt2800_disable_wpdma(rt2x00dev);
6757 /* Wait for DMA, ignore error */
6758 rt2800_wait_wpdma_ready(rt2x00dev);
6760 rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, ®);
6761 rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_TX, 0);
6762 rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, 0);
6763 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
6765 EXPORT_SYMBOL_GPL(rt2800_disable_radio);
6767 int rt2800_efuse_detect(struct rt2x00_dev *rt2x00dev)
6772 if (rt2x00_rt(rt2x00dev, RT3290))
6773 efuse_ctrl_reg = EFUSE_CTRL_3290;
6775 efuse_ctrl_reg = EFUSE_CTRL;
6777 rt2800_register_read(rt2x00dev, efuse_ctrl_reg, ®);
6778 return rt2x00_get_field32(reg, EFUSE_CTRL_PRESENT);
6780 EXPORT_SYMBOL_GPL(rt2800_efuse_detect);
6782 static void rt2800_efuse_read(struct rt2x00_dev *rt2x00dev, unsigned int i)
6786 u16 efuse_data0_reg;
6787 u16 efuse_data1_reg;
6788 u16 efuse_data2_reg;
6789 u16 efuse_data3_reg;
6791 if (rt2x00_rt(rt2x00dev, RT3290)) {
6792 efuse_ctrl_reg = EFUSE_CTRL_3290;
6793 efuse_data0_reg = EFUSE_DATA0_3290;
6794 efuse_data1_reg = EFUSE_DATA1_3290;
6795 efuse_data2_reg = EFUSE_DATA2_3290;
6796 efuse_data3_reg = EFUSE_DATA3_3290;
6798 efuse_ctrl_reg = EFUSE_CTRL;
6799 efuse_data0_reg = EFUSE_DATA0;
6800 efuse_data1_reg = EFUSE_DATA1;
6801 efuse_data2_reg = EFUSE_DATA2;
6802 efuse_data3_reg = EFUSE_DATA3;
6804 mutex_lock(&rt2x00dev->csr_mutex);
6806 rt2800_register_read_lock(rt2x00dev, efuse_ctrl_reg, ®);
6807 rt2x00_set_field32(®, EFUSE_CTRL_ADDRESS_IN, i);
6808 rt2x00_set_field32(®, EFUSE_CTRL_MODE, 0);
6809 rt2x00_set_field32(®, EFUSE_CTRL_KICK, 1);
6810 rt2800_register_write_lock(rt2x00dev, efuse_ctrl_reg, reg);
6812 /* Wait until the EEPROM has been loaded */
6813 rt2800_regbusy_read(rt2x00dev, efuse_ctrl_reg, EFUSE_CTRL_KICK, ®);
6814 /* Apparently the data is read from end to start */
6815 rt2800_register_read_lock(rt2x00dev, efuse_data3_reg, ®);
6816 /* The returned value is in CPU order, but eeprom is le */
6817 *(u32 *)&rt2x00dev->eeprom[i] = cpu_to_le32(reg);
6818 rt2800_register_read_lock(rt2x00dev, efuse_data2_reg, ®);
6819 *(u32 *)&rt2x00dev->eeprom[i + 2] = cpu_to_le32(reg);
6820 rt2800_register_read_lock(rt2x00dev, efuse_data1_reg, ®);
6821 *(u32 *)&rt2x00dev->eeprom[i + 4] = cpu_to_le32(reg);
6822 rt2800_register_read_lock(rt2x00dev, efuse_data0_reg, ®);
6823 *(u32 *)&rt2x00dev->eeprom[i + 6] = cpu_to_le32(reg);
6825 mutex_unlock(&rt2x00dev->csr_mutex);
6828 int rt2800_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev)
6832 for (i = 0; i < EEPROM_SIZE / sizeof(u16); i += 8)
6833 rt2800_efuse_read(rt2x00dev, i);
6837 EXPORT_SYMBOL_GPL(rt2800_read_eeprom_efuse);
6839 static u8 rt2800_get_txmixer_gain_24g(struct rt2x00_dev *rt2x00dev)
6843 if (rt2x00_rt(rt2x00dev, RT3593))
6846 rt2800_eeprom_read(rt2x00dev, EEPROM_TXMIXER_GAIN_BG, &word);
6847 if ((word & 0x00ff) != 0x00ff)
6848 return rt2x00_get_field16(word, EEPROM_TXMIXER_GAIN_BG_VAL);
6853 static u8 rt2800_get_txmixer_gain_5g(struct rt2x00_dev *rt2x00dev)
6857 if (rt2x00_rt(rt2x00dev, RT3593))
6860 rt2800_eeprom_read(rt2x00dev, EEPROM_TXMIXER_GAIN_A, &word);
6861 if ((word & 0x00ff) != 0x00ff)
6862 return rt2x00_get_field16(word, EEPROM_TXMIXER_GAIN_A_VAL);
6867 static int rt2800_validate_eeprom(struct rt2x00_dev *rt2x00dev)
6869 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
6872 u8 default_lna_gain;
6878 retval = rt2800_read_eeprom(rt2x00dev);
6883 * Start validation of the data that has been read.
6885 mac = rt2800_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
6886 if (!is_valid_ether_addr(mac)) {
6887 eth_random_addr(mac);
6888 rt2x00_eeprom_dbg(rt2x00dev, "MAC: %pM\n", mac);
6891 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &word);
6892 if (word == 0xffff) {
6893 rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RXPATH, 2);
6894 rt2x00_set_field16(&word, EEPROM_NIC_CONF0_TXPATH, 1);
6895 rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RF_TYPE, RF2820);
6896 rt2800_eeprom_write(rt2x00dev, EEPROM_NIC_CONF0, word);
6897 rt2x00_eeprom_dbg(rt2x00dev, "Antenna: 0x%04x\n", word);
6898 } else if (rt2x00_rt(rt2x00dev, RT2860) ||
6899 rt2x00_rt(rt2x00dev, RT2872)) {
6901 * There is a max of 2 RX streams for RT28x0 series
6903 if (rt2x00_get_field16(word, EEPROM_NIC_CONF0_RXPATH) > 2)
6904 rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RXPATH, 2);
6905 rt2800_eeprom_write(rt2x00dev, EEPROM_NIC_CONF0, word);
6908 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &word);
6909 if (word == 0xffff) {
6910 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_HW_RADIO, 0);
6911 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_TX_ALC, 0);
6912 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_LNA_2G, 0);
6913 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_LNA_5G, 0);
6914 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_CARDBUS_ACCEL, 0);
6915 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_SB_2G, 0);
6916 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_SB_5G, 0);
6917 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_WPS_PBC, 0);
6918 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_2G, 0);
6919 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_5G, 0);
6920 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BROADBAND_EXT_LNA, 0);
6921 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_ANT_DIVERSITY, 0);
6922 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_INTERNAL_TX_ALC, 0);
6923 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BT_COEXIST, 0);
6924 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_DAC_TEST, 0);
6925 rt2800_eeprom_write(rt2x00dev, EEPROM_NIC_CONF1, word);
6926 rt2x00_eeprom_dbg(rt2x00dev, "NIC: 0x%04x\n", word);
6929 rt2800_eeprom_read(rt2x00dev, EEPROM_FREQ, &word);
6930 if ((word & 0x00ff) == 0x00ff) {
6931 rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0);
6932 rt2800_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
6933 rt2x00_eeprom_dbg(rt2x00dev, "Freq: 0x%04x\n", word);
6935 if ((word & 0xff00) == 0xff00) {
6936 rt2x00_set_field16(&word, EEPROM_FREQ_LED_MODE,
6937 LED_MODE_TXRX_ACTIVITY);
6938 rt2x00_set_field16(&word, EEPROM_FREQ_LED_POLARITY, 0);
6939 rt2800_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
6940 rt2800_eeprom_write(rt2x00dev, EEPROM_LED_AG_CONF, 0x5555);
6941 rt2800_eeprom_write(rt2x00dev, EEPROM_LED_ACT_CONF, 0x2221);
6942 rt2800_eeprom_write(rt2x00dev, EEPROM_LED_POLARITY, 0xa9f8);
6943 rt2x00_eeprom_dbg(rt2x00dev, "Led Mode: 0x%04x\n", word);
6947 * During the LNA validation we are going to use
6948 * lna0 as correct value. Note that EEPROM_LNA
6949 * is never validated.
6951 rt2800_eeprom_read(rt2x00dev, EEPROM_LNA, &word);
6952 default_lna_gain = rt2x00_get_field16(word, EEPROM_LNA_A0);
6954 rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &word);
6955 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET0)) > 10)
6956 rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET0, 0);
6957 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET1)) > 10)
6958 rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET1, 0);
6959 rt2800_eeprom_write(rt2x00dev, EEPROM_RSSI_BG, word);
6961 drv_data->txmixer_gain_24g = rt2800_get_txmixer_gain_24g(rt2x00dev);
6963 rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &word);
6964 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG2_OFFSET2)) > 10)
6965 rt2x00_set_field16(&word, EEPROM_RSSI_BG2_OFFSET2, 0);
6966 if (!rt2x00_rt(rt2x00dev, RT3593)) {
6967 if (rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0x00 ||
6968 rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0xff)
6969 rt2x00_set_field16(&word, EEPROM_RSSI_BG2_LNA_A1,
6972 rt2800_eeprom_write(rt2x00dev, EEPROM_RSSI_BG2, word);
6974 drv_data->txmixer_gain_5g = rt2800_get_txmixer_gain_5g(rt2x00dev);
6976 rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &word);
6977 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET0)) > 10)
6978 rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET0, 0);
6979 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET1)) > 10)
6980 rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET1, 0);
6981 rt2800_eeprom_write(rt2x00dev, EEPROM_RSSI_A, word);
6983 rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &word);
6984 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A2_OFFSET2)) > 10)
6985 rt2x00_set_field16(&word, EEPROM_RSSI_A2_OFFSET2, 0);
6986 if (!rt2x00_rt(rt2x00dev, RT3593)) {
6987 if (rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0x00 ||
6988 rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0xff)
6989 rt2x00_set_field16(&word, EEPROM_RSSI_A2_LNA_A2,
6992 rt2800_eeprom_write(rt2x00dev, EEPROM_RSSI_A2, word);
6994 if (rt2x00_rt(rt2x00dev, RT3593)) {
6995 rt2800_eeprom_read(rt2x00dev, EEPROM_EXT_LNA2, &word);
6996 if (rt2x00_get_field16(word, EEPROM_EXT_LNA2_A1) == 0x00 ||
6997 rt2x00_get_field16(word, EEPROM_EXT_LNA2_A1) == 0xff)
6998 rt2x00_set_field16(&word, EEPROM_EXT_LNA2_A1,
7000 if (rt2x00_get_field16(word, EEPROM_EXT_LNA2_A2) == 0x00 ||
7001 rt2x00_get_field16(word, EEPROM_EXT_LNA2_A2) == 0xff)
7002 rt2x00_set_field16(&word, EEPROM_EXT_LNA2_A1,
7004 rt2800_eeprom_write(rt2x00dev, EEPROM_EXT_LNA2, word);
7010 static int rt2800_init_eeprom(struct rt2x00_dev *rt2x00dev)
7017 * Read EEPROM word for configuration.
7019 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom);
7022 * Identify RF chipset by EEPROM value
7023 * RT28xx/RT30xx: defined in "EEPROM_NIC_CONF0_RF_TYPE" field
7024 * RT53xx: defined in "EEPROM_CHIP_ID" field
7026 if (rt2x00_rt(rt2x00dev, RT3290) ||
7027 rt2x00_rt(rt2x00dev, RT5390) ||
7028 rt2x00_rt(rt2x00dev, RT5392))
7029 rt2800_eeprom_read(rt2x00dev, EEPROM_CHIP_ID, &rf);
7031 rf = rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RF_TYPE);
7056 rt2x00_err(rt2x00dev, "Invalid RF chipset 0x%04x detected\n",
7061 rt2x00_set_rf(rt2x00dev, rf);
7064 * Identify default antenna configuration.
7066 rt2x00dev->default_ant.tx_chain_num =
7067 rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH);
7068 rt2x00dev->default_ant.rx_chain_num =
7069 rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH);
7071 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
7073 if (rt2x00_rt(rt2x00dev, RT3070) ||
7074 rt2x00_rt(rt2x00dev, RT3090) ||
7075 rt2x00_rt(rt2x00dev, RT3352) ||
7076 rt2x00_rt(rt2x00dev, RT3390)) {
7077 value = rt2x00_get_field16(eeprom,
7078 EEPROM_NIC_CONF1_ANT_DIVERSITY);
7083 rt2x00dev->default_ant.tx = ANTENNA_A;
7084 rt2x00dev->default_ant.rx = ANTENNA_A;
7087 rt2x00dev->default_ant.tx = ANTENNA_A;
7088 rt2x00dev->default_ant.rx = ANTENNA_B;
7092 rt2x00dev->default_ant.tx = ANTENNA_A;
7093 rt2x00dev->default_ant.rx = ANTENNA_A;
7096 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390R)) {
7097 rt2x00dev->default_ant.tx = ANTENNA_HW_DIVERSITY; /* Unused */
7098 rt2x00dev->default_ant.rx = ANTENNA_HW_DIVERSITY; /* Unused */
7102 * Determine external LNA informations.
7104 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_EXTERNAL_LNA_5G))
7105 __set_bit(CAPABILITY_EXTERNAL_LNA_A, &rt2x00dev->cap_flags);
7106 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_EXTERNAL_LNA_2G))
7107 __set_bit(CAPABILITY_EXTERNAL_LNA_BG, &rt2x00dev->cap_flags);
7110 * Detect if this device has an hardware controlled radio.
7112 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_HW_RADIO))
7113 __set_bit(CAPABILITY_HW_BUTTON, &rt2x00dev->cap_flags);
7116 * Detect if this device has Bluetooth co-existence.
7118 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_BT_COEXIST))
7119 __set_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags);
7122 * Read frequency offset and RF programming sequence.
7124 rt2800_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
7125 rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET);
7128 * Store led settings, for correct led behaviour.
7130 #ifdef CONFIG_RT2X00_LIB_LEDS
7131 rt2800_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
7132 rt2800_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
7133 rt2800_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY);
7135 rt2x00dev->led_mcu_reg = eeprom;
7136 #endif /* CONFIG_RT2X00_LIB_LEDS */
7139 * Check if support EIRP tx power limit feature.
7141 rt2800_eeprom_read(rt2x00dev, EEPROM_EIRP_MAX_TX_POWER, &eeprom);
7143 if (rt2x00_get_field16(eeprom, EEPROM_EIRP_MAX_TX_POWER_2GHZ) <
7144 EIRP_MAX_TX_POWER_LIMIT)
7145 __set_bit(CAPABILITY_POWER_LIMIT, &rt2x00dev->cap_flags);
7151 * RF value list for rt28xx
7152 * Supports: 2.4 GHz (all) & 5.2 GHz (RF2850 & RF2750)
7154 static const struct rf_channel rf_vals[] = {
7155 { 1, 0x18402ecc, 0x184c0786, 0x1816b455, 0x1800510b },
7156 { 2, 0x18402ecc, 0x184c0786, 0x18168a55, 0x1800519f },
7157 { 3, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800518b },
7158 { 4, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800519f },
7159 { 5, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800518b },
7160 { 6, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800519f },
7161 { 7, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800518b },
7162 { 8, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800519f },
7163 { 9, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800518b },
7164 { 10, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800519f },
7165 { 11, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800518b },
7166 { 12, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800519f },
7167 { 13, 0x18402ecc, 0x184c079e, 0x18168a55, 0x1800518b },
7168 { 14, 0x18402ecc, 0x184c07a2, 0x18168a55, 0x18005193 },
7170 /* 802.11 UNI / HyperLan 2 */
7171 { 36, 0x18402ecc, 0x184c099a, 0x18158a55, 0x180ed1a3 },
7172 { 38, 0x18402ecc, 0x184c099e, 0x18158a55, 0x180ed193 },
7173 { 40, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed183 },
7174 { 44, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed1a3 },
7175 { 46, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed18b },
7176 { 48, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed19b },
7177 { 52, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed193 },
7178 { 54, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed1a3 },
7179 { 56, 0x18402ec8, 0x184c068e, 0x18158a55, 0x180ed18b },
7180 { 60, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed183 },
7181 { 62, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed193 },
7182 { 64, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed1a3 },
7184 /* 802.11 HyperLan 2 */
7185 { 100, 0x18402ec8, 0x184c06b2, 0x18178a55, 0x180ed783 },
7186 { 102, 0x18402ec8, 0x184c06b2, 0x18578a55, 0x180ed793 },
7187 { 104, 0x18402ec8, 0x185c06b2, 0x18578a55, 0x180ed1a3 },
7188 { 108, 0x18402ecc, 0x185c0a32, 0x18578a55, 0x180ed193 },
7189 { 110, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed183 },
7190 { 112, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed19b },
7191 { 116, 0x18402ecc, 0x184c0a3a, 0x18178a55, 0x180ed1a3 },
7192 { 118, 0x18402ecc, 0x184c0a3e, 0x18178a55, 0x180ed193 },
7193 { 120, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed183 },
7194 { 124, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed193 },
7195 { 126, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed15b },
7196 { 128, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed1a3 },
7197 { 132, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed18b },
7198 { 134, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed193 },
7199 { 136, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed19b },
7200 { 140, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed183 },
7203 { 149, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed1a7 },
7204 { 151, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed187 },
7205 { 153, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed18f },
7206 { 157, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed19f },
7207 { 159, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed1a7 },
7208 { 161, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed187 },
7209 { 165, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed197 },
7210 { 167, 0x18402ec4, 0x184c03d2, 0x18179855, 0x1815531f },
7211 { 169, 0x18402ec4, 0x184c03d2, 0x18179855, 0x18155327 },
7212 { 171, 0x18402ec4, 0x184c03d6, 0x18179855, 0x18155307 },
7213 { 173, 0x18402ec4, 0x184c03d6, 0x18179855, 0x1815530f },
7216 { 184, 0x15002ccc, 0x1500491e, 0x1509be55, 0x150c0a0b },
7217 { 188, 0x15002ccc, 0x15004922, 0x1509be55, 0x150c0a13 },
7218 { 192, 0x15002ccc, 0x15004926, 0x1509be55, 0x150c0a1b },
7219 { 196, 0x15002ccc, 0x1500492a, 0x1509be55, 0x150c0a23 },
7220 { 208, 0x15002ccc, 0x1500493a, 0x1509be55, 0x150c0a13 },
7221 { 212, 0x15002ccc, 0x1500493e, 0x1509be55, 0x150c0a1b },
7222 { 216, 0x15002ccc, 0x15004982, 0x1509be55, 0x150c0a23 },
7226 * RF value list for rt3xxx
7227 * Supports: 2.4 GHz (all) & 5.2 GHz (RF3052)
7229 static const struct rf_channel rf_vals_3x[] = {
7245 /* 802.11 UNI / HyperLan 2 */
7259 /* 802.11 HyperLan 2 */
7291 static const struct rf_channel rf_vals_5592_xtal20[] = {
7292 /* Channel, N, K, mod, R */
7302 {10, 491, 4, 10, 3},
7303 {11, 492, 4, 10, 3},
7304 {12, 493, 4, 10, 3},
7305 {13, 494, 4, 10, 3},
7306 {14, 496, 8, 10, 3},
7307 {36, 172, 8, 12, 1},
7308 {38, 173, 0, 12, 1},
7309 {40, 173, 4, 12, 1},
7310 {42, 173, 8, 12, 1},
7311 {44, 174, 0, 12, 1},
7312 {46, 174, 4, 12, 1},
7313 {48, 174, 8, 12, 1},
7314 {50, 175, 0, 12, 1},
7315 {52, 175, 4, 12, 1},
7316 {54, 175, 8, 12, 1},
7317 {56, 176, 0, 12, 1},
7318 {58, 176, 4, 12, 1},
7319 {60, 176, 8, 12, 1},
7320 {62, 177, 0, 12, 1},
7321 {64, 177, 4, 12, 1},
7322 {100, 183, 4, 12, 1},
7323 {102, 183, 8, 12, 1},
7324 {104, 184, 0, 12, 1},
7325 {106, 184, 4, 12, 1},
7326 {108, 184, 8, 12, 1},
7327 {110, 185, 0, 12, 1},
7328 {112, 185, 4, 12, 1},
7329 {114, 185, 8, 12, 1},
7330 {116, 186, 0, 12, 1},
7331 {118, 186, 4, 12, 1},
7332 {120, 186, 8, 12, 1},
7333 {122, 187, 0, 12, 1},
7334 {124, 187, 4, 12, 1},
7335 {126, 187, 8, 12, 1},
7336 {128, 188, 0, 12, 1},
7337 {130, 188, 4, 12, 1},
7338 {132, 188, 8, 12, 1},
7339 {134, 189, 0, 12, 1},
7340 {136, 189, 4, 12, 1},
7341 {138, 189, 8, 12, 1},
7342 {140, 190, 0, 12, 1},
7343 {149, 191, 6, 12, 1},
7344 {151, 191, 10, 12, 1},
7345 {153, 192, 2, 12, 1},
7346 {155, 192, 6, 12, 1},
7347 {157, 192, 10, 12, 1},
7348 {159, 193, 2, 12, 1},
7349 {161, 193, 6, 12, 1},
7350 {165, 194, 2, 12, 1},
7351 {184, 164, 0, 12, 1},
7352 {188, 164, 4, 12, 1},
7353 {192, 165, 8, 12, 1},
7354 {196, 166, 0, 12, 1},
7357 static const struct rf_channel rf_vals_5592_xtal40[] = {
7358 /* Channel, N, K, mod, R */
7368 {10, 245, 7, 10, 3},
7369 {11, 246, 2, 10, 3},
7370 {12, 246, 7, 10, 3},
7371 {13, 247, 2, 10, 3},
7372 {14, 248, 4, 10, 3},
7376 {42, 86, 10, 12, 1},
7382 {54, 87, 10, 12, 1},
7388 {100, 91, 8, 12, 1},
7389 {102, 91, 10, 12, 1},
7390 {104, 92, 0, 12, 1},
7391 {106, 92, 2, 12, 1},
7392 {108, 92, 4, 12, 1},
7393 {110, 92, 6, 12, 1},
7394 {112, 92, 8, 12, 1},
7395 {114, 92, 10, 12, 1},
7396 {116, 93, 0, 12, 1},
7397 {118, 93, 2, 12, 1},
7398 {120, 93, 4, 12, 1},
7399 {122, 93, 6, 12, 1},
7400 {124, 93, 8, 12, 1},
7401 {126, 93, 10, 12, 1},
7402 {128, 94, 0, 12, 1},
7403 {130, 94, 2, 12, 1},
7404 {132, 94, 4, 12, 1},
7405 {134, 94, 6, 12, 1},
7406 {136, 94, 8, 12, 1},
7407 {138, 94, 10, 12, 1},
7408 {140, 95, 0, 12, 1},
7409 {149, 95, 9, 12, 1},
7410 {151, 95, 11, 12, 1},
7411 {153, 96, 1, 12, 1},
7412 {155, 96, 3, 12, 1},
7413 {157, 96, 5, 12, 1},
7414 {159, 96, 7, 12, 1},
7415 {161, 96, 9, 12, 1},
7416 {165, 97, 1, 12, 1},
7417 {184, 82, 0, 12, 1},
7418 {188, 82, 4, 12, 1},
7419 {192, 82, 8, 12, 1},
7420 {196, 83, 0, 12, 1},
7423 static const struct rf_channel rf_vals_3053[] = {
7424 /* Channel, N, R, K */
7460 /* NOTE: Channel 114 has been removed intentionally.
7461 * The EEPROM contains no TX power values for that,
7462 * and it is disabled in the vendor driver as well.
7489 static int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
7491 struct hw_mode_spec *spec = &rt2x00dev->spec;
7492 struct channel_info *info;
7493 char *default_power1;
7494 char *default_power2;
7495 char *default_power3;
7501 * Disable powersaving as default on PCI devices.
7503 if (rt2x00_is_pci(rt2x00dev) || rt2x00_is_soc(rt2x00dev))
7504 rt2x00dev->hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
7507 * Initialize all hw fields.
7509 rt2x00dev->hw->flags =
7510 IEEE80211_HW_SIGNAL_DBM |
7511 IEEE80211_HW_SUPPORTS_PS |
7512 IEEE80211_HW_PS_NULLFUNC_STACK |
7513 IEEE80211_HW_AMPDU_AGGREGATION |
7514 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
7515 IEEE80211_HW_SUPPORTS_HT_CCK_RATES;
7518 * Don't set IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING for USB devices
7519 * unless we are capable of sending the buffered frames out after the
7520 * DTIM transmission using rt2x00lib_beacondone. This will send out
7521 * multicast and broadcast traffic immediately instead of buffering it
7522 * infinitly and thus dropping it after some time.
7524 if (!rt2x00_is_usb(rt2x00dev))
7525 rt2x00dev->hw->flags |=
7526 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING;
7528 SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
7529 SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
7530 rt2800_eeprom_addr(rt2x00dev,
7531 EEPROM_MAC_ADDR_0));
7534 * As rt2800 has a global fallback table we cannot specify
7535 * more then one tx rate per frame but since the hw will
7536 * try several rates (based on the fallback table) we should
7537 * initialize max_report_rates to the maximum number of rates
7538 * we are going to try. Otherwise mac80211 will truncate our
7539 * reported tx rates and the rc algortihm will end up with
7542 rt2x00dev->hw->max_rates = 1;
7543 rt2x00dev->hw->max_report_rates = 7;
7544 rt2x00dev->hw->max_rate_tries = 1;
7546 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom);
7549 * Initialize hw_mode information.
7551 spec->supported_bands = SUPPORT_BAND_2GHZ;
7552 spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
7554 if (rt2x00_rf(rt2x00dev, RF2820) ||
7555 rt2x00_rf(rt2x00dev, RF2720)) {
7556 spec->num_channels = 14;
7557 spec->channels = rf_vals;
7558 } else if (rt2x00_rf(rt2x00dev, RF2850) ||
7559 rt2x00_rf(rt2x00dev, RF2750)) {
7560 spec->supported_bands |= SUPPORT_BAND_5GHZ;
7561 spec->num_channels = ARRAY_SIZE(rf_vals);
7562 spec->channels = rf_vals;
7563 } else if (rt2x00_rf(rt2x00dev, RF3020) ||
7564 rt2x00_rf(rt2x00dev, RF2020) ||
7565 rt2x00_rf(rt2x00dev, RF3021) ||
7566 rt2x00_rf(rt2x00dev, RF3022) ||
7567 rt2x00_rf(rt2x00dev, RF3070) ||
7568 rt2x00_rf(rt2x00dev, RF3290) ||
7569 rt2x00_rf(rt2x00dev, RF3320) ||
7570 rt2x00_rf(rt2x00dev, RF3322) ||
7571 rt2x00_rf(rt2x00dev, RF5360) ||
7572 rt2x00_rf(rt2x00dev, RF5370) ||
7573 rt2x00_rf(rt2x00dev, RF5372) ||
7574 rt2x00_rf(rt2x00dev, RF5390) ||
7575 rt2x00_rf(rt2x00dev, RF5392)) {
7576 spec->num_channels = 14;
7577 spec->channels = rf_vals_3x;
7578 } else if (rt2x00_rf(rt2x00dev, RF3052)) {
7579 spec->supported_bands |= SUPPORT_BAND_5GHZ;
7580 spec->num_channels = ARRAY_SIZE(rf_vals_3x);
7581 spec->channels = rf_vals_3x;
7582 } else if (rt2x00_rf(rt2x00dev, RF3053)) {
7583 spec->supported_bands |= SUPPORT_BAND_5GHZ;
7584 spec->num_channels = ARRAY_SIZE(rf_vals_3053);
7585 spec->channels = rf_vals_3053;
7586 } else if (rt2x00_rf(rt2x00dev, RF5592)) {
7587 spec->supported_bands |= SUPPORT_BAND_5GHZ;
7589 rt2800_register_read(rt2x00dev, MAC_DEBUG_INDEX, ®);
7590 if (rt2x00_get_field32(reg, MAC_DEBUG_INDEX_XTAL)) {
7591 spec->num_channels = ARRAY_SIZE(rf_vals_5592_xtal40);
7592 spec->channels = rf_vals_5592_xtal40;
7594 spec->num_channels = ARRAY_SIZE(rf_vals_5592_xtal20);
7595 spec->channels = rf_vals_5592_xtal20;
7599 if (WARN_ON_ONCE(!spec->channels))
7603 * Initialize HT information.
7605 if (!rt2x00_rf(rt2x00dev, RF2020))
7606 spec->ht.ht_supported = true;
7608 spec->ht.ht_supported = false;
7611 IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
7612 IEEE80211_HT_CAP_GRN_FLD |
7613 IEEE80211_HT_CAP_SGI_20 |
7614 IEEE80211_HT_CAP_SGI_40;
7616 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) >= 2)
7617 spec->ht.cap |= IEEE80211_HT_CAP_TX_STBC;
7620 rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) <<
7621 IEEE80211_HT_CAP_RX_STBC_SHIFT;
7623 spec->ht.ampdu_factor = 3;
7624 spec->ht.ampdu_density = 4;
7625 spec->ht.mcs.tx_params =
7626 IEEE80211_HT_MCS_TX_DEFINED |
7627 IEEE80211_HT_MCS_TX_RX_DIFF |
7628 ((rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) - 1) <<
7629 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
7631 switch (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH)) {
7633 spec->ht.mcs.rx_mask[2] = 0xff;
7635 spec->ht.mcs.rx_mask[1] = 0xff;
7637 spec->ht.mcs.rx_mask[0] = 0xff;
7638 spec->ht.mcs.rx_mask[4] = 0x1; /* MCS32 */
7643 * Create channel information array
7645 info = kcalloc(spec->num_channels, sizeof(*info), GFP_KERNEL);
7649 spec->channels_info = info;
7651 default_power1 = rt2800_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG1);
7652 default_power2 = rt2800_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG2);
7654 if (rt2x00dev->default_ant.tx_chain_num > 2)
7655 default_power3 = rt2800_eeprom_addr(rt2x00dev,
7656 EEPROM_EXT_TXPOWER_BG3);
7658 default_power3 = NULL;
7660 for (i = 0; i < 14; i++) {
7661 info[i].default_power1 = default_power1[i];
7662 info[i].default_power2 = default_power2[i];
7664 info[i].default_power3 = default_power3[i];
7667 if (spec->num_channels > 14) {
7668 default_power1 = rt2800_eeprom_addr(rt2x00dev,
7670 default_power2 = rt2800_eeprom_addr(rt2x00dev,
7673 if (rt2x00dev->default_ant.tx_chain_num > 2)
7675 rt2800_eeprom_addr(rt2x00dev,
7676 EEPROM_EXT_TXPOWER_A3);
7678 default_power3 = NULL;
7680 for (i = 14; i < spec->num_channels; i++) {
7681 info[i].default_power1 = default_power1[i - 14];
7682 info[i].default_power2 = default_power2[i - 14];
7684 info[i].default_power3 = default_power3[i - 14];
7688 switch (rt2x00dev->chip.rf) {
7703 __set_bit(CAPABILITY_VCO_RECALIBRATION, &rt2x00dev->cap_flags);
7710 static int rt2800_probe_rt(struct rt2x00_dev *rt2x00dev)
7716 if (rt2x00_rt(rt2x00dev, RT3290))
7717 rt2800_register_read(rt2x00dev, MAC_CSR0_3290, ®);
7719 rt2800_register_read(rt2x00dev, MAC_CSR0, ®);
7721 rt = rt2x00_get_field32(reg, MAC_CSR0_CHIPSET);
7722 rev = rt2x00_get_field32(reg, MAC_CSR0_REVISION);
7741 rt2x00_err(rt2x00dev, "Invalid RT chipset 0x%04x, rev %04x detected\n",
7746 rt2x00_set_rt(rt2x00dev, rt, rev);
7751 int rt2800_probe_hw(struct rt2x00_dev *rt2x00dev)
7756 retval = rt2800_probe_rt(rt2x00dev);
7761 * Allocate eeprom data.
7763 retval = rt2800_validate_eeprom(rt2x00dev);
7767 retval = rt2800_init_eeprom(rt2x00dev);
7772 * Enable rfkill polling by setting GPIO direction of the
7773 * rfkill switch GPIO pin correctly.
7775 rt2800_register_read(rt2x00dev, GPIO_CTRL, ®);
7776 rt2x00_set_field32(®, GPIO_CTRL_DIR2, 1);
7777 rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
7780 * Initialize hw specifications.
7782 retval = rt2800_probe_hw_mode(rt2x00dev);
7787 * Set device capabilities.
7789 __set_bit(CAPABILITY_CONTROL_FILTERS, &rt2x00dev->cap_flags);
7790 __set_bit(CAPABILITY_CONTROL_FILTER_PSPOLL, &rt2x00dev->cap_flags);
7791 if (!rt2x00_is_usb(rt2x00dev))
7792 __set_bit(CAPABILITY_PRE_TBTT_INTERRUPT, &rt2x00dev->cap_flags);
7795 * Set device requirements.
7797 if (!rt2x00_is_soc(rt2x00dev))
7798 __set_bit(REQUIRE_FIRMWARE, &rt2x00dev->cap_flags);
7799 __set_bit(REQUIRE_L2PAD, &rt2x00dev->cap_flags);
7800 __set_bit(REQUIRE_TXSTATUS_FIFO, &rt2x00dev->cap_flags);
7801 if (!rt2800_hwcrypt_disabled(rt2x00dev))
7802 __set_bit(CAPABILITY_HW_CRYPTO, &rt2x00dev->cap_flags);
7803 __set_bit(CAPABILITY_LINK_TUNING, &rt2x00dev->cap_flags);
7804 __set_bit(REQUIRE_HT_TX_DESC, &rt2x00dev->cap_flags);
7805 if (rt2x00_is_usb(rt2x00dev))
7806 __set_bit(REQUIRE_PS_AUTOWAKE, &rt2x00dev->cap_flags);
7808 __set_bit(REQUIRE_DMA, &rt2x00dev->cap_flags);
7809 __set_bit(REQUIRE_TASKLET_CONTEXT, &rt2x00dev->cap_flags);
7813 * Set the rssi offset.
7815 rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
7819 EXPORT_SYMBOL_GPL(rt2800_probe_hw);
7822 * IEEE80211 stack callback functions.
7824 void rt2800_get_tkip_seq(struct ieee80211_hw *hw, u8 hw_key_idx, u32 *iv32,
7827 struct rt2x00_dev *rt2x00dev = hw->priv;
7828 struct mac_iveiv_entry iveiv_entry;
7831 offset = MAC_IVEIV_ENTRY(hw_key_idx);
7832 rt2800_register_multiread(rt2x00dev, offset,
7833 &iveiv_entry, sizeof(iveiv_entry));
7835 memcpy(iv16, &iveiv_entry.iv[0], sizeof(*iv16));
7836 memcpy(iv32, &iveiv_entry.iv[4], sizeof(*iv32));
7838 EXPORT_SYMBOL_GPL(rt2800_get_tkip_seq);
7840 int rt2800_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
7842 struct rt2x00_dev *rt2x00dev = hw->priv;
7844 bool enabled = (value < IEEE80211_MAX_RTS_THRESHOLD);
7846 rt2800_register_read(rt2x00dev, TX_RTS_CFG, ®);
7847 rt2x00_set_field32(®, TX_RTS_CFG_RTS_THRES, value);
7848 rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg);
7850 rt2800_register_read(rt2x00dev, CCK_PROT_CFG, ®);
7851 rt2x00_set_field32(®, CCK_PROT_CFG_RTS_TH_EN, enabled);
7852 rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg);
7854 rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, ®);
7855 rt2x00_set_field32(®, OFDM_PROT_CFG_RTS_TH_EN, enabled);
7856 rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
7858 rt2800_register_read(rt2x00dev, MM20_PROT_CFG, ®);
7859 rt2x00_set_field32(®, MM20_PROT_CFG_RTS_TH_EN, enabled);
7860 rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
7862 rt2800_register_read(rt2x00dev, MM40_PROT_CFG, ®);
7863 rt2x00_set_field32(®, MM40_PROT_CFG_RTS_TH_EN, enabled);
7864 rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
7866 rt2800_register_read(rt2x00dev, GF20_PROT_CFG, ®);
7867 rt2x00_set_field32(®, GF20_PROT_CFG_RTS_TH_EN, enabled);
7868 rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
7870 rt2800_register_read(rt2x00dev, GF40_PROT_CFG, ®);
7871 rt2x00_set_field32(®, GF40_PROT_CFG_RTS_TH_EN, enabled);
7872 rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
7876 EXPORT_SYMBOL_GPL(rt2800_set_rts_threshold);
7878 int rt2800_conf_tx(struct ieee80211_hw *hw,
7879 struct ieee80211_vif *vif, u16 queue_idx,
7880 const struct ieee80211_tx_queue_params *params)
7882 struct rt2x00_dev *rt2x00dev = hw->priv;
7883 struct data_queue *queue;
7884 struct rt2x00_field32 field;
7890 * First pass the configuration through rt2x00lib, that will
7891 * update the queue settings and validate the input. After that
7892 * we are free to update the registers based on the value
7893 * in the queue parameter.
7895 retval = rt2x00mac_conf_tx(hw, vif, queue_idx, params);
7900 * We only need to perform additional register initialization
7906 queue = rt2x00queue_get_tx_queue(rt2x00dev, queue_idx);
7908 /* Update WMM TXOP register */
7909 offset = WMM_TXOP0_CFG + (sizeof(u32) * (!!(queue_idx & 2)));
7910 field.bit_offset = (queue_idx & 1) * 16;
7911 field.bit_mask = 0xffff << field.bit_offset;
7913 rt2800_register_read(rt2x00dev, offset, ®);
7914 rt2x00_set_field32(®, field, queue->txop);
7915 rt2800_register_write(rt2x00dev, offset, reg);
7917 /* Update WMM registers */
7918 field.bit_offset = queue_idx * 4;
7919 field.bit_mask = 0xf << field.bit_offset;
7921 rt2800_register_read(rt2x00dev, WMM_AIFSN_CFG, ®);
7922 rt2x00_set_field32(®, field, queue->aifs);
7923 rt2800_register_write(rt2x00dev, WMM_AIFSN_CFG, reg);
7925 rt2800_register_read(rt2x00dev, WMM_CWMIN_CFG, ®);
7926 rt2x00_set_field32(®, field, queue->cw_min);
7927 rt2800_register_write(rt2x00dev, WMM_CWMIN_CFG, reg);
7929 rt2800_register_read(rt2x00dev, WMM_CWMAX_CFG, ®);
7930 rt2x00_set_field32(®, field, queue->cw_max);
7931 rt2800_register_write(rt2x00dev, WMM_CWMAX_CFG, reg);
7933 /* Update EDCA registers */
7934 offset = EDCA_AC0_CFG + (sizeof(u32) * queue_idx);
7936 rt2800_register_read(rt2x00dev, offset, ®);
7937 rt2x00_set_field32(®, EDCA_AC0_CFG_TX_OP, queue->txop);
7938 rt2x00_set_field32(®, EDCA_AC0_CFG_AIFSN, queue->aifs);
7939 rt2x00_set_field32(®, EDCA_AC0_CFG_CWMIN, queue->cw_min);
7940 rt2x00_set_field32(®, EDCA_AC0_CFG_CWMAX, queue->cw_max);
7941 rt2800_register_write(rt2x00dev, offset, reg);
7945 EXPORT_SYMBOL_GPL(rt2800_conf_tx);
7947 u64 rt2800_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
7949 struct rt2x00_dev *rt2x00dev = hw->priv;
7953 rt2800_register_read(rt2x00dev, TSF_TIMER_DW1, ®);
7954 tsf = (u64) rt2x00_get_field32(reg, TSF_TIMER_DW1_HIGH_WORD) << 32;
7955 rt2800_register_read(rt2x00dev, TSF_TIMER_DW0, ®);
7956 tsf |= rt2x00_get_field32(reg, TSF_TIMER_DW0_LOW_WORD);
7960 EXPORT_SYMBOL_GPL(rt2800_get_tsf);
7962 int rt2800_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
7963 enum ieee80211_ampdu_mlme_action action,
7964 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
7967 struct rt2x00_sta *sta_priv = (struct rt2x00_sta *)sta->drv_priv;
7971 * Don't allow aggregation for stations the hardware isn't aware
7972 * of because tx status reports for frames to an unknown station
7973 * always contain wcid=255 and thus we can't distinguish between
7974 * multiple stations which leads to unwanted situations when the
7975 * hw reorders frames due to aggregation.
7977 if (sta_priv->wcid < 0)
7981 case IEEE80211_AMPDU_RX_START:
7982 case IEEE80211_AMPDU_RX_STOP:
7984 * The hw itself takes care of setting up BlockAck mechanisms.
7985 * So, we only have to allow mac80211 to nagotiate a BlockAck
7986 * agreement. Once that is done, the hw will BlockAck incoming
7987 * AMPDUs without further setup.
7990 case IEEE80211_AMPDU_TX_START:
7991 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
7993 case IEEE80211_AMPDU_TX_STOP_CONT:
7994 case IEEE80211_AMPDU_TX_STOP_FLUSH:
7995 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
7996 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
7998 case IEEE80211_AMPDU_TX_OPERATIONAL:
8001 rt2x00_warn((struct rt2x00_dev *)hw->priv,
8002 "Unknown AMPDU action\n");
8007 EXPORT_SYMBOL_GPL(rt2800_ampdu_action);
8009 int rt2800_get_survey(struct ieee80211_hw *hw, int idx,
8010 struct survey_info *survey)
8012 struct rt2x00_dev *rt2x00dev = hw->priv;
8013 struct ieee80211_conf *conf = &hw->conf;
8014 u32 idle, busy, busy_ext;
8019 survey->channel = conf->chandef.chan;
8021 rt2800_register_read(rt2x00dev, CH_IDLE_STA, &idle);
8022 rt2800_register_read(rt2x00dev, CH_BUSY_STA, &busy);
8023 rt2800_register_read(rt2x00dev, CH_BUSY_STA_SEC, &busy_ext);
8026 survey->filled = SURVEY_INFO_CHANNEL_TIME |
8027 SURVEY_INFO_CHANNEL_TIME_BUSY |
8028 SURVEY_INFO_CHANNEL_TIME_EXT_BUSY;
8030 survey->channel_time = (idle + busy) / 1000;
8031 survey->channel_time_busy = busy / 1000;
8032 survey->channel_time_ext_busy = busy_ext / 1000;
8035 if (!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL))
8036 survey->filled |= SURVEY_INFO_IN_USE;
8041 EXPORT_SYMBOL_GPL(rt2800_get_survey);
8043 MODULE_AUTHOR(DRV_PROJECT ", Bartlomiej Zolnierkiewicz");
8044 MODULE_VERSION(DRV_VERSION);
8045 MODULE_DESCRIPTION("Ralink RT2800 library");
8046 MODULE_LICENSE("GPL");