2 Copyright (C) 2010 Willow Garage <http://www.willowgarage.com>
3 Copyright (C) 2010 Ivo van Doorn <IvDoorn@gmail.com>
4 Copyright (C) 2009 Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
5 Copyright (C) 2009 Gertjan van Wingerde <gwingerde@gmail.com>
7 Based on the original rt2800pci.c and rt2800usb.c.
8 Copyright (C) 2009 Alban Browaeys <prahal@yahoo.com>
9 Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org>
10 Copyright (C) 2009 Luis Correia <luis.f.correia@gmail.com>
11 Copyright (C) 2009 Mattias Nissler <mattias.nissler@gmx.de>
12 Copyright (C) 2009 Mark Asselstine <asselsm@gmail.com>
13 Copyright (C) 2009 Xose Vazquez Perez <xose.vazquez@gmail.com>
14 <http://rt2x00.serialmonkey.com>
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, see <http://www.gnu.org/licenses/>.
32 Abstract: rt2800 generic device routines.
35 #include <linux/crc-ccitt.h>
36 #include <linux/kernel.h>
37 #include <linux/module.h>
38 #include <linux/slab.h>
41 #include "rt2800lib.h"
46 * All access to the CSR registers will go through the methods
47 * rt2800_register_read and rt2800_register_write.
48 * BBP and RF register require indirect register access,
49 * and use the CSR registers BBPCSR and RFCSR to achieve this.
50 * These indirect registers work with busy bits,
51 * and we will try maximal REGISTER_BUSY_COUNT times to access
52 * the register while taking a REGISTER_BUSY_DELAY us delay
53 * between each attampt. When the busy bit is still set at that time,
54 * the access attempt is considered to have failed,
55 * and we will print an error.
56 * The _lock versions must be used if you already hold the csr_mutex
58 #define WAIT_FOR_BBP(__dev, __reg) \
59 rt2800_regbusy_read((__dev), BBP_CSR_CFG, BBP_CSR_CFG_BUSY, (__reg))
60 #define WAIT_FOR_RFCSR(__dev, __reg) \
61 rt2800_regbusy_read((__dev), RF_CSR_CFG, RF_CSR_CFG_BUSY, (__reg))
62 #define WAIT_FOR_RF(__dev, __reg) \
63 rt2800_regbusy_read((__dev), RF_CSR_CFG0, RF_CSR_CFG0_BUSY, (__reg))
64 #define WAIT_FOR_MCU(__dev, __reg) \
65 rt2800_regbusy_read((__dev), H2M_MAILBOX_CSR, \
66 H2M_MAILBOX_CSR_OWNER, (__reg))
68 static inline bool rt2800_is_305x_soc(struct rt2x00_dev *rt2x00dev)
70 /* check for rt2872 on SoC */
71 if (!rt2x00_is_soc(rt2x00dev) ||
72 !rt2x00_rt(rt2x00dev, RT2872))
75 /* we know for sure that these rf chipsets are used on rt305x boards */
76 if (rt2x00_rf(rt2x00dev, RF3020) ||
77 rt2x00_rf(rt2x00dev, RF3021) ||
78 rt2x00_rf(rt2x00dev, RF3022))
81 rt2x00_warn(rt2x00dev, "Unknown RF chipset on rt305x\n");
85 static void rt2800_bbp_write(struct rt2x00_dev *rt2x00dev,
86 const unsigned int word, const u8 value)
90 mutex_lock(&rt2x00dev->csr_mutex);
93 * Wait until the BBP becomes available, afterwards we
94 * can safely write the new data into the register.
96 if (WAIT_FOR_BBP(rt2x00dev, ®)) {
98 rt2x00_set_field32(®, BBP_CSR_CFG_VALUE, value);
99 rt2x00_set_field32(®, BBP_CSR_CFG_REGNUM, word);
100 rt2x00_set_field32(®, BBP_CSR_CFG_BUSY, 1);
101 rt2x00_set_field32(®, BBP_CSR_CFG_READ_CONTROL, 0);
102 rt2x00_set_field32(®, BBP_CSR_CFG_BBP_RW_MODE, 1);
104 rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
107 mutex_unlock(&rt2x00dev->csr_mutex);
110 static void rt2800_bbp_read(struct rt2x00_dev *rt2x00dev,
111 const unsigned int word, u8 *value)
115 mutex_lock(&rt2x00dev->csr_mutex);
118 * Wait until the BBP becomes available, afterwards we
119 * can safely write the read request into the register.
120 * After the data has been written, we wait until hardware
121 * returns the correct value, if at any time the register
122 * doesn't become available in time, reg will be 0xffffffff
123 * which means we return 0xff to the caller.
125 if (WAIT_FOR_BBP(rt2x00dev, ®)) {
127 rt2x00_set_field32(®, BBP_CSR_CFG_REGNUM, word);
128 rt2x00_set_field32(®, BBP_CSR_CFG_BUSY, 1);
129 rt2x00_set_field32(®, BBP_CSR_CFG_READ_CONTROL, 1);
130 rt2x00_set_field32(®, BBP_CSR_CFG_BBP_RW_MODE, 1);
132 rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
134 WAIT_FOR_BBP(rt2x00dev, ®);
137 *value = rt2x00_get_field32(reg, BBP_CSR_CFG_VALUE);
139 mutex_unlock(&rt2x00dev->csr_mutex);
142 static void rt2800_rfcsr_write(struct rt2x00_dev *rt2x00dev,
143 const unsigned int word, const u8 value)
147 mutex_lock(&rt2x00dev->csr_mutex);
150 * Wait until the RFCSR becomes available, afterwards we
151 * can safely write the new data into the register.
153 if (WAIT_FOR_RFCSR(rt2x00dev, ®)) {
155 rt2x00_set_field32(®, RF_CSR_CFG_DATA, value);
156 rt2x00_set_field32(®, RF_CSR_CFG_REGNUM, word);
157 rt2x00_set_field32(®, RF_CSR_CFG_WRITE, 1);
158 rt2x00_set_field32(®, RF_CSR_CFG_BUSY, 1);
160 rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
163 mutex_unlock(&rt2x00dev->csr_mutex);
166 static void rt2800_rfcsr_read(struct rt2x00_dev *rt2x00dev,
167 const unsigned int word, u8 *value)
171 mutex_lock(&rt2x00dev->csr_mutex);
174 * Wait until the RFCSR becomes available, afterwards we
175 * can safely write the read request into the register.
176 * After the data has been written, we wait until hardware
177 * returns the correct value, if at any time the register
178 * doesn't become available in time, reg will be 0xffffffff
179 * which means we return 0xff to the caller.
181 if (WAIT_FOR_RFCSR(rt2x00dev, ®)) {
183 rt2x00_set_field32(®, RF_CSR_CFG_REGNUM, word);
184 rt2x00_set_field32(®, RF_CSR_CFG_WRITE, 0);
185 rt2x00_set_field32(®, RF_CSR_CFG_BUSY, 1);
187 rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
189 WAIT_FOR_RFCSR(rt2x00dev, ®);
192 *value = rt2x00_get_field32(reg, RF_CSR_CFG_DATA);
194 mutex_unlock(&rt2x00dev->csr_mutex);
197 static void rt2800_rf_write(struct rt2x00_dev *rt2x00dev,
198 const unsigned int word, const u32 value)
202 mutex_lock(&rt2x00dev->csr_mutex);
205 * Wait until the RF becomes available, afterwards we
206 * can safely write the new data into the register.
208 if (WAIT_FOR_RF(rt2x00dev, ®)) {
210 rt2x00_set_field32(®, RF_CSR_CFG0_REG_VALUE_BW, value);
211 rt2x00_set_field32(®, RF_CSR_CFG0_STANDBYMODE, 0);
212 rt2x00_set_field32(®, RF_CSR_CFG0_SEL, 0);
213 rt2x00_set_field32(®, RF_CSR_CFG0_BUSY, 1);
215 rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG0, reg);
216 rt2x00_rf_write(rt2x00dev, word, value);
219 mutex_unlock(&rt2x00dev->csr_mutex);
222 static const unsigned int rt2800_eeprom_map[EEPROM_WORD_COUNT] = {
223 [EEPROM_CHIP_ID] = 0x0000,
224 [EEPROM_VERSION] = 0x0001,
225 [EEPROM_MAC_ADDR_0] = 0x0002,
226 [EEPROM_MAC_ADDR_1] = 0x0003,
227 [EEPROM_MAC_ADDR_2] = 0x0004,
228 [EEPROM_NIC_CONF0] = 0x001a,
229 [EEPROM_NIC_CONF1] = 0x001b,
230 [EEPROM_FREQ] = 0x001d,
231 [EEPROM_LED_AG_CONF] = 0x001e,
232 [EEPROM_LED_ACT_CONF] = 0x001f,
233 [EEPROM_LED_POLARITY] = 0x0020,
234 [EEPROM_NIC_CONF2] = 0x0021,
235 [EEPROM_LNA] = 0x0022,
236 [EEPROM_RSSI_BG] = 0x0023,
237 [EEPROM_RSSI_BG2] = 0x0024,
238 [EEPROM_TXMIXER_GAIN_BG] = 0x0024, /* overlaps with RSSI_BG2 */
239 [EEPROM_RSSI_A] = 0x0025,
240 [EEPROM_RSSI_A2] = 0x0026,
241 [EEPROM_TXMIXER_GAIN_A] = 0x0026, /* overlaps with RSSI_A2 */
242 [EEPROM_EIRP_MAX_TX_POWER] = 0x0027,
243 [EEPROM_TXPOWER_DELTA] = 0x0028,
244 [EEPROM_TXPOWER_BG1] = 0x0029,
245 [EEPROM_TXPOWER_BG2] = 0x0030,
246 [EEPROM_TSSI_BOUND_BG1] = 0x0037,
247 [EEPROM_TSSI_BOUND_BG2] = 0x0038,
248 [EEPROM_TSSI_BOUND_BG3] = 0x0039,
249 [EEPROM_TSSI_BOUND_BG4] = 0x003a,
250 [EEPROM_TSSI_BOUND_BG5] = 0x003b,
251 [EEPROM_TXPOWER_A1] = 0x003c,
252 [EEPROM_TXPOWER_A2] = 0x0053,
253 [EEPROM_TSSI_BOUND_A1] = 0x006a,
254 [EEPROM_TSSI_BOUND_A2] = 0x006b,
255 [EEPROM_TSSI_BOUND_A3] = 0x006c,
256 [EEPROM_TSSI_BOUND_A4] = 0x006d,
257 [EEPROM_TSSI_BOUND_A5] = 0x006e,
258 [EEPROM_TXPOWER_BYRATE] = 0x006f,
259 [EEPROM_BBP_START] = 0x0078,
262 static const unsigned int rt2800_eeprom_map_ext[EEPROM_WORD_COUNT] = {
263 [EEPROM_CHIP_ID] = 0x0000,
264 [EEPROM_VERSION] = 0x0001,
265 [EEPROM_MAC_ADDR_0] = 0x0002,
266 [EEPROM_MAC_ADDR_1] = 0x0003,
267 [EEPROM_MAC_ADDR_2] = 0x0004,
268 [EEPROM_NIC_CONF0] = 0x001a,
269 [EEPROM_NIC_CONF1] = 0x001b,
270 [EEPROM_NIC_CONF2] = 0x001c,
271 [EEPROM_EIRP_MAX_TX_POWER] = 0x0020,
272 [EEPROM_FREQ] = 0x0022,
273 [EEPROM_LED_AG_CONF] = 0x0023,
274 [EEPROM_LED_ACT_CONF] = 0x0024,
275 [EEPROM_LED_POLARITY] = 0x0025,
276 [EEPROM_LNA] = 0x0026,
277 [EEPROM_EXT_LNA2] = 0x0027,
278 [EEPROM_RSSI_BG] = 0x0028,
279 [EEPROM_RSSI_BG2] = 0x0029,
280 [EEPROM_RSSI_A] = 0x002a,
281 [EEPROM_RSSI_A2] = 0x002b,
282 [EEPROM_TXPOWER_BG1] = 0x0030,
283 [EEPROM_TXPOWER_BG2] = 0x0037,
284 [EEPROM_EXT_TXPOWER_BG3] = 0x003e,
285 [EEPROM_TSSI_BOUND_BG1] = 0x0045,
286 [EEPROM_TSSI_BOUND_BG2] = 0x0046,
287 [EEPROM_TSSI_BOUND_BG3] = 0x0047,
288 [EEPROM_TSSI_BOUND_BG4] = 0x0048,
289 [EEPROM_TSSI_BOUND_BG5] = 0x0049,
290 [EEPROM_TXPOWER_A1] = 0x004b,
291 [EEPROM_TXPOWER_A2] = 0x0065,
292 [EEPROM_EXT_TXPOWER_A3] = 0x007f,
293 [EEPROM_TSSI_BOUND_A1] = 0x009a,
294 [EEPROM_TSSI_BOUND_A2] = 0x009b,
295 [EEPROM_TSSI_BOUND_A3] = 0x009c,
296 [EEPROM_TSSI_BOUND_A4] = 0x009d,
297 [EEPROM_TSSI_BOUND_A5] = 0x009e,
298 [EEPROM_TXPOWER_BYRATE] = 0x00a0,
301 static unsigned int rt2800_eeprom_word_index(struct rt2x00_dev *rt2x00dev,
302 const enum rt2800_eeprom_word word)
304 const unsigned int *map;
307 if (WARN_ONCE(word >= EEPROM_WORD_COUNT,
308 "%s: invalid EEPROM word %d\n",
309 wiphy_name(rt2x00dev->hw->wiphy), word))
312 if (rt2x00_rt(rt2x00dev, RT3593))
313 map = rt2800_eeprom_map_ext;
315 map = rt2800_eeprom_map;
319 /* Index 0 is valid only for EEPROM_CHIP_ID.
320 * Otherwise it means that the offset of the
321 * given word is not initialized in the map,
322 * or that the field is not usable on the
325 WARN_ONCE(word != EEPROM_CHIP_ID && index == 0,
326 "%s: invalid access of EEPROM word %d\n",
327 wiphy_name(rt2x00dev->hw->wiphy), word);
332 static void *rt2800_eeprom_addr(struct rt2x00_dev *rt2x00dev,
333 const enum rt2800_eeprom_word word)
337 index = rt2800_eeprom_word_index(rt2x00dev, word);
338 return rt2x00_eeprom_addr(rt2x00dev, index);
341 static void rt2800_eeprom_read(struct rt2x00_dev *rt2x00dev,
342 const enum rt2800_eeprom_word word, u16 *data)
346 index = rt2800_eeprom_word_index(rt2x00dev, word);
347 rt2x00_eeprom_read(rt2x00dev, index, data);
350 static void rt2800_eeprom_write(struct rt2x00_dev *rt2x00dev,
351 const enum rt2800_eeprom_word word, u16 data)
355 index = rt2800_eeprom_word_index(rt2x00dev, word);
356 rt2x00_eeprom_write(rt2x00dev, index, data);
359 static void rt2800_eeprom_read_from_array(struct rt2x00_dev *rt2x00dev,
360 const enum rt2800_eeprom_word array,
366 index = rt2800_eeprom_word_index(rt2x00dev, array);
367 rt2x00_eeprom_read(rt2x00dev, index + offset, data);
370 static int rt2800_enable_wlan_rt3290(struct rt2x00_dev *rt2x00dev)
375 rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, ®);
376 if (rt2x00_get_field32(reg, WLAN_EN))
379 rt2x00_set_field32(®, WLAN_GPIO_OUT_OE_BIT_ALL, 0xff);
380 rt2x00_set_field32(®, FRC_WL_ANT_SET, 1);
381 rt2x00_set_field32(®, WLAN_CLK_EN, 0);
382 rt2x00_set_field32(®, WLAN_EN, 1);
383 rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg);
385 udelay(REGISTER_BUSY_DELAY);
390 * Check PLL_LD & XTAL_RDY.
392 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
393 rt2800_register_read(rt2x00dev, CMB_CTRL, ®);
394 if (rt2x00_get_field32(reg, PLL_LD) &&
395 rt2x00_get_field32(reg, XTAL_RDY))
397 udelay(REGISTER_BUSY_DELAY);
400 if (i >= REGISTER_BUSY_COUNT) {
405 rt2800_register_write(rt2x00dev, 0x58, 0x018);
406 udelay(REGISTER_BUSY_DELAY);
407 rt2800_register_write(rt2x00dev, 0x58, 0x418);
408 udelay(REGISTER_BUSY_DELAY);
409 rt2800_register_write(rt2x00dev, 0x58, 0x618);
410 udelay(REGISTER_BUSY_DELAY);
416 rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, ®);
417 rt2x00_set_field32(®, PCIE_APP0_CLK_REQ, 0);
418 rt2x00_set_field32(®, WLAN_CLK_EN, 1);
419 rt2x00_set_field32(®, WLAN_RESET, 1);
420 rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg);
422 rt2x00_set_field32(®, WLAN_RESET, 0);
423 rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg);
425 rt2800_register_write(rt2x00dev, INT_SOURCE_CSR, 0x7fffffff);
426 } while (count != 0);
431 void rt2800_mcu_request(struct rt2x00_dev *rt2x00dev,
432 const u8 command, const u8 token,
433 const u8 arg0, const u8 arg1)
438 * SOC devices don't support MCU requests.
440 if (rt2x00_is_soc(rt2x00dev))
443 mutex_lock(&rt2x00dev->csr_mutex);
446 * Wait until the MCU becomes available, afterwards we
447 * can safely write the new data into the register.
449 if (WAIT_FOR_MCU(rt2x00dev, ®)) {
450 rt2x00_set_field32(®, H2M_MAILBOX_CSR_OWNER, 1);
451 rt2x00_set_field32(®, H2M_MAILBOX_CSR_CMD_TOKEN, token);
452 rt2x00_set_field32(®, H2M_MAILBOX_CSR_ARG0, arg0);
453 rt2x00_set_field32(®, H2M_MAILBOX_CSR_ARG1, arg1);
454 rt2800_register_write_lock(rt2x00dev, H2M_MAILBOX_CSR, reg);
457 rt2x00_set_field32(®, HOST_CMD_CSR_HOST_COMMAND, command);
458 rt2800_register_write_lock(rt2x00dev, HOST_CMD_CSR, reg);
461 mutex_unlock(&rt2x00dev->csr_mutex);
463 EXPORT_SYMBOL_GPL(rt2800_mcu_request);
465 int rt2800_wait_csr_ready(struct rt2x00_dev *rt2x00dev)
470 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
471 rt2800_register_read(rt2x00dev, MAC_CSR0, ®);
472 if (reg && reg != ~0)
477 rt2x00_err(rt2x00dev, "Unstable hardware\n");
480 EXPORT_SYMBOL_GPL(rt2800_wait_csr_ready);
482 int rt2800_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev)
488 * Some devices are really slow to respond here. Wait a whole second
491 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
492 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®);
493 if (!rt2x00_get_field32(reg, WPDMA_GLO_CFG_TX_DMA_BUSY) &&
494 !rt2x00_get_field32(reg, WPDMA_GLO_CFG_RX_DMA_BUSY))
500 rt2x00_err(rt2x00dev, "WPDMA TX/RX busy [0x%08x]\n", reg);
503 EXPORT_SYMBOL_GPL(rt2800_wait_wpdma_ready);
505 void rt2800_disable_wpdma(struct rt2x00_dev *rt2x00dev)
509 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®);
510 rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
511 rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
512 rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
513 rt2x00_set_field32(®, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
514 rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
515 rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
517 EXPORT_SYMBOL_GPL(rt2800_disable_wpdma);
519 void rt2800_get_txwi_rxwi_size(struct rt2x00_dev *rt2x00dev,
520 unsigned short *txwi_size,
521 unsigned short *rxwi_size)
523 switch (rt2x00dev->chip.rt) {
525 *txwi_size = TXWI_DESC_SIZE_4WORDS;
526 *rxwi_size = RXWI_DESC_SIZE_5WORDS;
530 *txwi_size = TXWI_DESC_SIZE_5WORDS;
531 *rxwi_size = RXWI_DESC_SIZE_6WORDS;
535 *txwi_size = TXWI_DESC_SIZE_4WORDS;
536 *rxwi_size = RXWI_DESC_SIZE_4WORDS;
540 EXPORT_SYMBOL_GPL(rt2800_get_txwi_rxwi_size);
542 static bool rt2800_check_firmware_crc(const u8 *data, const size_t len)
548 * The last 2 bytes in the firmware array are the crc checksum itself,
549 * this means that we should never pass those 2 bytes to the crc
552 fw_crc = (data[len - 2] << 8 | data[len - 1]);
555 * Use the crc ccitt algorithm.
556 * This will return the same value as the legacy driver which
557 * used bit ordering reversion on the both the firmware bytes
558 * before input input as well as on the final output.
559 * Obviously using crc ccitt directly is much more efficient.
561 crc = crc_ccitt(~0, data, len - 2);
564 * There is a small difference between the crc-itu-t + bitrev and
565 * the crc-ccitt crc calculation. In the latter method the 2 bytes
566 * will be swapped, use swab16 to convert the crc to the correct
571 return fw_crc == crc;
574 int rt2800_check_firmware(struct rt2x00_dev *rt2x00dev,
575 const u8 *data, const size_t len)
582 * PCI(e) & SOC devices require firmware with a length
583 * of 8kb. USB devices require firmware files with a length
584 * of 4kb. Certain USB chipsets however require different firmware,
585 * which Ralink only provides attached to the original firmware
586 * file. Thus for USB devices, firmware files have a length
587 * which is a multiple of 4kb. The firmware for rt3290 chip also
588 * have a length which is a multiple of 4kb.
590 if (rt2x00_is_usb(rt2x00dev) || rt2x00_rt(rt2x00dev, RT3290))
597 * Validate the firmware length
599 if (len != fw_len && (!multiple || (len % fw_len) != 0))
600 return FW_BAD_LENGTH;
603 * Check if the chipset requires one of the upper parts
606 if (rt2x00_is_usb(rt2x00dev) &&
607 !rt2x00_rt(rt2x00dev, RT2860) &&
608 !rt2x00_rt(rt2x00dev, RT2872) &&
609 !rt2x00_rt(rt2x00dev, RT3070) &&
610 ((len / fw_len) == 1))
611 return FW_BAD_VERSION;
614 * 8kb firmware files must be checked as if it were
615 * 2 separate firmware files.
617 while (offset < len) {
618 if (!rt2800_check_firmware_crc(data + offset, fw_len))
626 EXPORT_SYMBOL_GPL(rt2800_check_firmware);
628 int rt2800_load_firmware(struct rt2x00_dev *rt2x00dev,
629 const u8 *data, const size_t len)
635 if (rt2x00_rt(rt2x00dev, RT3290)) {
636 retval = rt2800_enable_wlan_rt3290(rt2x00dev);
642 * If driver doesn't wake up firmware here,
643 * rt2800_load_firmware will hang forever when interface is up again.
645 rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0x00000000);
648 * Wait for stable hardware.
650 if (rt2800_wait_csr_ready(rt2x00dev))
653 if (rt2x00_is_pci(rt2x00dev)) {
654 if (rt2x00_rt(rt2x00dev, RT3290) ||
655 rt2x00_rt(rt2x00dev, RT3572) ||
656 rt2x00_rt(rt2x00dev, RT5390) ||
657 rt2x00_rt(rt2x00dev, RT5392)) {
658 rt2800_register_read(rt2x00dev, AUX_CTRL, ®);
659 rt2x00_set_field32(®, AUX_CTRL_FORCE_PCIE_CLK, 1);
660 rt2x00_set_field32(®, AUX_CTRL_WAKE_PCIE_EN, 1);
661 rt2800_register_write(rt2x00dev, AUX_CTRL, reg);
663 rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000002);
666 rt2800_disable_wpdma(rt2x00dev);
669 * Write firmware to the device.
671 rt2800_drv_write_firmware(rt2x00dev, data, len);
674 * Wait for device to stabilize.
676 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
677 rt2800_register_read(rt2x00dev, PBF_SYS_CTRL, ®);
678 if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY))
683 if (i == REGISTER_BUSY_COUNT) {
684 rt2x00_err(rt2x00dev, "PBF system register not ready\n");
689 * Disable DMA, will be reenabled later when enabling
692 rt2800_disable_wpdma(rt2x00dev);
695 * Initialize firmware.
697 rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
698 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
699 if (rt2x00_is_usb(rt2x00dev)) {
700 rt2800_register_write(rt2x00dev, H2M_INT_SRC, 0);
701 rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0, 0, 0);
707 EXPORT_SYMBOL_GPL(rt2800_load_firmware);
709 void rt2800_write_tx_data(struct queue_entry *entry,
710 struct txentry_desc *txdesc)
712 __le32 *txwi = rt2800_drv_get_txwi(entry);
717 * Initialize TX Info descriptor
719 rt2x00_desc_read(txwi, 0, &word);
720 rt2x00_set_field32(&word, TXWI_W0_FRAG,
721 test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
722 rt2x00_set_field32(&word, TXWI_W0_MIMO_PS,
723 test_bit(ENTRY_TXD_HT_MIMO_PS, &txdesc->flags));
724 rt2x00_set_field32(&word, TXWI_W0_CF_ACK, 0);
725 rt2x00_set_field32(&word, TXWI_W0_TS,
726 test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
727 rt2x00_set_field32(&word, TXWI_W0_AMPDU,
728 test_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags));
729 rt2x00_set_field32(&word, TXWI_W0_MPDU_DENSITY,
730 txdesc->u.ht.mpdu_density);
731 rt2x00_set_field32(&word, TXWI_W0_TX_OP, txdesc->u.ht.txop);
732 rt2x00_set_field32(&word, TXWI_W0_MCS, txdesc->u.ht.mcs);
733 rt2x00_set_field32(&word, TXWI_W0_BW,
734 test_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags));
735 rt2x00_set_field32(&word, TXWI_W0_SHORT_GI,
736 test_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags));
737 rt2x00_set_field32(&word, TXWI_W0_STBC, txdesc->u.ht.stbc);
738 rt2x00_set_field32(&word, TXWI_W0_PHYMODE, txdesc->rate_mode);
739 rt2x00_desc_write(txwi, 0, word);
741 rt2x00_desc_read(txwi, 1, &word);
742 rt2x00_set_field32(&word, TXWI_W1_ACK,
743 test_bit(ENTRY_TXD_ACK, &txdesc->flags));
744 rt2x00_set_field32(&word, TXWI_W1_NSEQ,
745 test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags));
746 rt2x00_set_field32(&word, TXWI_W1_BW_WIN_SIZE, txdesc->u.ht.ba_size);
747 rt2x00_set_field32(&word, TXWI_W1_WIRELESS_CLI_ID,
748 test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags) ?
749 txdesc->key_idx : txdesc->u.ht.wcid);
750 rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT,
752 rt2x00_set_field32(&word, TXWI_W1_PACKETID_QUEUE, entry->queue->qid);
753 rt2x00_set_field32(&word, TXWI_W1_PACKETID_ENTRY, (entry->entry_idx % 3) + 1);
754 rt2x00_desc_write(txwi, 1, word);
757 * Always write 0 to IV/EIV fields (word 2 and 3), hardware will insert
758 * the IV from the IVEIV register when TXD_W3_WIV is set to 0.
759 * When TXD_W3_WIV is set to 1 it will use the IV data
760 * from the descriptor. The TXWI_W1_WIRELESS_CLI_ID indicates which
761 * crypto entry in the registers should be used to encrypt the frame.
763 * Nulify all remaining words as well, we don't know how to program them.
765 for (i = 2; i < entry->queue->winfo_size / sizeof(__le32); i++)
766 _rt2x00_desc_write(txwi, i, 0);
768 EXPORT_SYMBOL_GPL(rt2800_write_tx_data);
770 static int rt2800_agc_to_rssi(struct rt2x00_dev *rt2x00dev, u32 rxwi_w2)
772 s8 rssi0 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI0);
773 s8 rssi1 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI1);
774 s8 rssi2 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI2);
780 if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
781 rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &eeprom);
782 offset0 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG_OFFSET0);
783 offset1 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG_OFFSET1);
784 rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom);
785 offset2 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG2_OFFSET2);
787 rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &eeprom);
788 offset0 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A_OFFSET0);
789 offset1 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A_OFFSET1);
790 rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom);
791 offset2 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A2_OFFSET2);
795 * Convert the value from the descriptor into the RSSI value
796 * If the value in the descriptor is 0, it is considered invalid
797 * and the default (extremely low) rssi value is assumed
799 rssi0 = (rssi0) ? (-12 - offset0 - rt2x00dev->lna_gain - rssi0) : -128;
800 rssi1 = (rssi1) ? (-12 - offset1 - rt2x00dev->lna_gain - rssi1) : -128;
801 rssi2 = (rssi2) ? (-12 - offset2 - rt2x00dev->lna_gain - rssi2) : -128;
804 * mac80211 only accepts a single RSSI value. Calculating the
805 * average doesn't deliver a fair answer either since -60:-60 would
806 * be considered equally good as -50:-70 while the second is the one
807 * which gives less energy...
809 rssi0 = max(rssi0, rssi1);
810 return (int)max(rssi0, rssi2);
813 void rt2800_process_rxwi(struct queue_entry *entry,
814 struct rxdone_entry_desc *rxdesc)
816 __le32 *rxwi = (__le32 *) entry->skb->data;
819 rt2x00_desc_read(rxwi, 0, &word);
821 rxdesc->cipher = rt2x00_get_field32(word, RXWI_W0_UDF);
822 rxdesc->size = rt2x00_get_field32(word, RXWI_W0_MPDU_TOTAL_BYTE_COUNT);
824 rt2x00_desc_read(rxwi, 1, &word);
826 if (rt2x00_get_field32(word, RXWI_W1_SHORT_GI))
827 rxdesc->flags |= RX_FLAG_SHORT_GI;
829 if (rt2x00_get_field32(word, RXWI_W1_BW))
830 rxdesc->flags |= RX_FLAG_40MHZ;
833 * Detect RX rate, always use MCS as signal type.
835 rxdesc->dev_flags |= RXDONE_SIGNAL_MCS;
836 rxdesc->signal = rt2x00_get_field32(word, RXWI_W1_MCS);
837 rxdesc->rate_mode = rt2x00_get_field32(word, RXWI_W1_PHYMODE);
840 * Mask of 0x8 bit to remove the short preamble flag.
842 if (rxdesc->rate_mode == RATE_MODE_CCK)
843 rxdesc->signal &= ~0x8;
845 rt2x00_desc_read(rxwi, 2, &word);
848 * Convert descriptor AGC value to RSSI value.
850 rxdesc->rssi = rt2800_agc_to_rssi(entry->queue->rt2x00dev, word);
852 * Remove RXWI descriptor from start of the buffer.
854 skb_pull(entry->skb, entry->queue->winfo_size);
856 EXPORT_SYMBOL_GPL(rt2800_process_rxwi);
858 void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi)
860 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
861 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
862 struct txdone_entry_desc txdesc;
868 * Obtain the status about this packet.
871 rt2x00_desc_read(txwi, 0, &word);
873 mcs = rt2x00_get_field32(word, TXWI_W0_MCS);
874 ampdu = rt2x00_get_field32(word, TXWI_W0_AMPDU);
876 real_mcs = rt2x00_get_field32(status, TX_STA_FIFO_MCS);
877 aggr = rt2x00_get_field32(status, TX_STA_FIFO_TX_AGGRE);
880 * If a frame was meant to be sent as a single non-aggregated MPDU
881 * but ended up in an aggregate the used tx rate doesn't correlate
882 * with the one specified in the TXWI as the whole aggregate is sent
883 * with the same rate.
885 * For example: two frames are sent to rt2x00, the first one sets
886 * AMPDU=1 and requests MCS7 whereas the second frame sets AMDPU=0
887 * and requests MCS15. If the hw aggregates both frames into one
888 * AMDPU the tx status for both frames will contain MCS7 although
889 * the frame was sent successfully.
891 * Hence, replace the requested rate with the real tx rate to not
892 * confuse the rate control algortihm by providing clearly wrong
895 if (unlikely(aggr == 1 && ampdu == 0 && real_mcs != mcs)) {
896 skbdesc->tx_rate_idx = real_mcs;
900 if (aggr == 1 || ampdu == 1)
901 __set_bit(TXDONE_AMPDU, &txdesc.flags);
904 * Ralink has a retry mechanism using a global fallback
905 * table. We setup this fallback table to try the immediate
906 * lower rate for all rates. In the TX_STA_FIFO, the MCS field
907 * always contains the MCS used for the last transmission, be
908 * it successful or not.
910 if (rt2x00_get_field32(status, TX_STA_FIFO_TX_SUCCESS)) {
912 * Transmission succeeded. The number of retries is
915 __set_bit(TXDONE_SUCCESS, &txdesc.flags);
916 txdesc.retry = ((mcs > real_mcs) ? mcs - real_mcs : 0);
919 * Transmission failed. The number of retries is
920 * always 7 in this case (for a total number of 8
923 __set_bit(TXDONE_FAILURE, &txdesc.flags);
924 txdesc.retry = rt2x00dev->long_retry;
928 * the frame was retried at least once
929 * -> hw used fallback rates
932 __set_bit(TXDONE_FALLBACK, &txdesc.flags);
934 rt2x00lib_txdone(entry, &txdesc);
936 EXPORT_SYMBOL_GPL(rt2800_txdone_entry);
938 static unsigned int rt2800_hw_beacon_base(struct rt2x00_dev *rt2x00dev,
941 return HW_BEACON_BASE(index);
944 static inline u8 rt2800_get_beacon_offset(struct rt2x00_dev *rt2x00dev,
947 return BEACON_BASE_TO_OFFSET(rt2800_hw_beacon_base(rt2x00dev, index));
950 static void rt2800_update_beacons_setup(struct rt2x00_dev *rt2x00dev)
952 struct data_queue *queue = rt2x00dev->bcn;
953 struct queue_entry *entry;
959 * Setup offsets of all active beacons in BCN_OFFSET{0,1} registers.
961 for (i = 0; i < queue->limit; i++) {
962 entry = &queue->entries[i];
963 if (!test_bit(ENTRY_BCN_ENABLED, &entry->flags))
965 off = rt2800_get_beacon_offset(rt2x00dev, entry->entry_idx);
966 reg |= off << (8 * bcn_num);
970 WARN_ON_ONCE(bcn_num != rt2x00dev->intf_beaconing);
972 rt2800_register_write(rt2x00dev, BCN_OFFSET0, (u32) reg);
973 rt2800_register_write(rt2x00dev, BCN_OFFSET1, (u32) (reg >> 32));
976 * H/W sends up to MAC_BSSID_DW1_BSS_BCN_NUM + 1 consecutive beacons.
978 rt2800_register_read(rt2x00dev, MAC_BSSID_DW1, &bssid_dw1);
979 rt2x00_set_field32(&bssid_dw1, MAC_BSSID_DW1_BSS_BCN_NUM,
980 bcn_num > 0 ? bcn_num - 1 : 0);
981 rt2800_register_write(rt2x00dev, MAC_BSSID_DW1, bssid_dw1);
984 void rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc)
986 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
987 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
988 unsigned int beacon_base;
989 unsigned int padding_len;
991 const int txwi_desc_size = entry->queue->winfo_size;
994 * Disable beaconing while we are reloading the beacon data,
995 * otherwise we might be sending out invalid data.
997 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®);
999 rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 0);
1000 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
1003 * Add space for the TXWI in front of the skb.
1005 memset(skb_push(entry->skb, txwi_desc_size), 0, txwi_desc_size);
1008 * Register descriptor details in skb frame descriptor.
1010 skbdesc->flags |= SKBDESC_DESC_IN_SKB;
1011 skbdesc->desc = entry->skb->data;
1012 skbdesc->desc_len = txwi_desc_size;
1015 * Add the TXWI for the beacon to the skb.
1017 rt2800_write_tx_data(entry, txdesc);
1020 * Dump beacon to userspace through debugfs.
1022 rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry->skb);
1025 * Write entire beacon with TXWI and padding to register.
1027 padding_len = roundup(entry->skb->len, 4) - entry->skb->len;
1028 if (padding_len && skb_pad(entry->skb, padding_len)) {
1029 rt2x00_err(rt2x00dev, "Failure padding beacon, aborting\n");
1030 /* skb freed by skb_pad() on failure */
1032 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, orig_reg);
1036 beacon_base = rt2800_hw_beacon_base(rt2x00dev, entry->entry_idx);
1038 rt2800_register_multiwrite(rt2x00dev, beacon_base, entry->skb->data,
1039 entry->skb->len + padding_len);
1040 __set_bit(ENTRY_BCN_ENABLED, &entry->flags);
1043 * Change global beacons settings.
1045 rt2800_update_beacons_setup(rt2x00dev);
1048 * Restore beaconing state.
1050 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, orig_reg);
1053 * Clean up beacon skb.
1055 dev_kfree_skb_any(entry->skb);
1058 EXPORT_SYMBOL_GPL(rt2800_write_beacon);
1060 static inline void rt2800_clear_beacon_register(struct rt2x00_dev *rt2x00dev,
1064 const int txwi_desc_size = rt2x00dev->bcn->winfo_size;
1065 unsigned int beacon_base;
1067 beacon_base = rt2800_hw_beacon_base(rt2x00dev, index);
1070 * For the Beacon base registers we only need to clear
1071 * the whole TXWI which (when set to 0) will invalidate
1072 * the entire beacon.
1074 for (i = 0; i < txwi_desc_size; i += sizeof(__le32))
1075 rt2800_register_write(rt2x00dev, beacon_base + i, 0);
1078 void rt2800_clear_beacon(struct queue_entry *entry)
1080 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
1084 * Disable beaconing while we are reloading the beacon data,
1085 * otherwise we might be sending out invalid data.
1087 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &orig_reg);
1089 rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 0);
1090 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
1095 rt2800_clear_beacon_register(rt2x00dev, entry->entry_idx);
1096 __clear_bit(ENTRY_BCN_ENABLED, &entry->flags);
1099 * Change global beacons settings.
1101 rt2800_update_beacons_setup(rt2x00dev);
1103 * Restore beaconing state.
1105 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, orig_reg);
1107 EXPORT_SYMBOL_GPL(rt2800_clear_beacon);
1109 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
1110 const struct rt2x00debug rt2800_rt2x00debug = {
1111 .owner = THIS_MODULE,
1113 .read = rt2800_register_read,
1114 .write = rt2800_register_write,
1115 .flags = RT2X00DEBUGFS_OFFSET,
1116 .word_base = CSR_REG_BASE,
1117 .word_size = sizeof(u32),
1118 .word_count = CSR_REG_SIZE / sizeof(u32),
1121 /* NOTE: The local EEPROM access functions can't
1122 * be used here, use the generic versions instead.
1124 .read = rt2x00_eeprom_read,
1125 .write = rt2x00_eeprom_write,
1126 .word_base = EEPROM_BASE,
1127 .word_size = sizeof(u16),
1128 .word_count = EEPROM_SIZE / sizeof(u16),
1131 .read = rt2800_bbp_read,
1132 .write = rt2800_bbp_write,
1133 .word_base = BBP_BASE,
1134 .word_size = sizeof(u8),
1135 .word_count = BBP_SIZE / sizeof(u8),
1138 .read = rt2x00_rf_read,
1139 .write = rt2800_rf_write,
1140 .word_base = RF_BASE,
1141 .word_size = sizeof(u32),
1142 .word_count = RF_SIZE / sizeof(u32),
1145 .read = rt2800_rfcsr_read,
1146 .write = rt2800_rfcsr_write,
1147 .word_base = RFCSR_BASE,
1148 .word_size = sizeof(u8),
1149 .word_count = RFCSR_SIZE / sizeof(u8),
1152 EXPORT_SYMBOL_GPL(rt2800_rt2x00debug);
1153 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
1155 int rt2800_rfkill_poll(struct rt2x00_dev *rt2x00dev)
1159 if (rt2x00_rt(rt2x00dev, RT3290)) {
1160 rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, ®);
1161 return rt2x00_get_field32(reg, WLAN_GPIO_IN_BIT0);
1163 rt2800_register_read(rt2x00dev, GPIO_CTRL, ®);
1164 return rt2x00_get_field32(reg, GPIO_CTRL_VAL2);
1167 EXPORT_SYMBOL_GPL(rt2800_rfkill_poll);
1169 #ifdef CONFIG_RT2X00_LIB_LEDS
1170 static void rt2800_brightness_set(struct led_classdev *led_cdev,
1171 enum led_brightness brightness)
1173 struct rt2x00_led *led =
1174 container_of(led_cdev, struct rt2x00_led, led_dev);
1175 unsigned int enabled = brightness != LED_OFF;
1176 unsigned int bg_mode =
1177 (enabled && led->rt2x00dev->curr_band == NL80211_BAND_2GHZ);
1178 unsigned int polarity =
1179 rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
1180 EEPROM_FREQ_LED_POLARITY);
1181 unsigned int ledmode =
1182 rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
1183 EEPROM_FREQ_LED_MODE);
1186 /* Check for SoC (SOC devices don't support MCU requests) */
1187 if (rt2x00_is_soc(led->rt2x00dev)) {
1188 rt2800_register_read(led->rt2x00dev, LED_CFG, ®);
1190 /* Set LED Polarity */
1191 rt2x00_set_field32(®, LED_CFG_LED_POLAR, polarity);
1194 if (led->type == LED_TYPE_RADIO) {
1195 rt2x00_set_field32(®, LED_CFG_G_LED_MODE,
1197 } else if (led->type == LED_TYPE_ASSOC) {
1198 rt2x00_set_field32(®, LED_CFG_Y_LED_MODE,
1200 } else if (led->type == LED_TYPE_QUALITY) {
1201 rt2x00_set_field32(®, LED_CFG_R_LED_MODE,
1205 rt2800_register_write(led->rt2x00dev, LED_CFG, reg);
1208 if (led->type == LED_TYPE_RADIO) {
1209 rt2800_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
1210 enabled ? 0x20 : 0);
1211 } else if (led->type == LED_TYPE_ASSOC) {
1212 rt2800_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
1213 enabled ? (bg_mode ? 0x60 : 0xa0) : 0x20);
1214 } else if (led->type == LED_TYPE_QUALITY) {
1216 * The brightness is divided into 6 levels (0 - 5),
1217 * The specs tell us the following levels:
1218 * 0, 1 ,3, 7, 15, 31
1219 * to determine the level in a simple way we can simply
1220 * work with bitshifting:
1223 rt2800_mcu_request(led->rt2x00dev, MCU_LED_STRENGTH, 0xff,
1224 (1 << brightness / (LED_FULL / 6)) - 1,
1230 static void rt2800_init_led(struct rt2x00_dev *rt2x00dev,
1231 struct rt2x00_led *led, enum led_type type)
1233 led->rt2x00dev = rt2x00dev;
1235 led->led_dev.brightness_set = rt2800_brightness_set;
1236 led->flags = LED_INITIALIZED;
1238 #endif /* CONFIG_RT2X00_LIB_LEDS */
1241 * Configuration handlers.
1243 static void rt2800_config_wcid(struct rt2x00_dev *rt2x00dev,
1247 struct mac_wcid_entry wcid_entry;
1250 offset = MAC_WCID_ENTRY(wcid);
1252 memset(&wcid_entry, 0xff, sizeof(wcid_entry));
1254 memcpy(wcid_entry.mac, address, ETH_ALEN);
1256 rt2800_register_multiwrite(rt2x00dev, offset,
1257 &wcid_entry, sizeof(wcid_entry));
1260 static void rt2800_delete_wcid_attr(struct rt2x00_dev *rt2x00dev, int wcid)
1263 offset = MAC_WCID_ATTR_ENTRY(wcid);
1264 rt2800_register_write(rt2x00dev, offset, 0);
1267 static void rt2800_config_wcid_attr_bssidx(struct rt2x00_dev *rt2x00dev,
1268 int wcid, u32 bssidx)
1270 u32 offset = MAC_WCID_ATTR_ENTRY(wcid);
1274 * The BSS Idx numbers is split in a main value of 3 bits,
1275 * and a extended field for adding one additional bit to the value.
1277 rt2800_register_read(rt2x00dev, offset, ®);
1278 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_BSS_IDX, (bssidx & 0x7));
1279 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_BSS_IDX_EXT,
1280 (bssidx & 0x8) >> 3);
1281 rt2800_register_write(rt2x00dev, offset, reg);
1284 static void rt2800_config_wcid_attr_cipher(struct rt2x00_dev *rt2x00dev,
1285 struct rt2x00lib_crypto *crypto,
1286 struct ieee80211_key_conf *key)
1288 struct mac_iveiv_entry iveiv_entry;
1292 offset = MAC_WCID_ATTR_ENTRY(key->hw_key_idx);
1294 if (crypto->cmd == SET_KEY) {
1295 rt2800_register_read(rt2x00dev, offset, ®);
1296 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_KEYTAB,
1297 !!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE));
1299 * Both the cipher as the BSS Idx numbers are split in a main
1300 * value of 3 bits, and a extended field for adding one additional
1303 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_CIPHER,
1304 (crypto->cipher & 0x7));
1305 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_CIPHER_EXT,
1306 (crypto->cipher & 0x8) >> 3);
1307 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_RX_WIUDF, crypto->cipher);
1308 rt2800_register_write(rt2x00dev, offset, reg);
1310 /* Delete the cipher without touching the bssidx */
1311 rt2800_register_read(rt2x00dev, offset, ®);
1312 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_KEYTAB, 0);
1313 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_CIPHER, 0);
1314 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_CIPHER_EXT, 0);
1315 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_RX_WIUDF, 0);
1316 rt2800_register_write(rt2x00dev, offset, reg);
1319 offset = MAC_IVEIV_ENTRY(key->hw_key_idx);
1321 memset(&iveiv_entry, 0, sizeof(iveiv_entry));
1322 if ((crypto->cipher == CIPHER_TKIP) ||
1323 (crypto->cipher == CIPHER_TKIP_NO_MIC) ||
1324 (crypto->cipher == CIPHER_AES))
1325 iveiv_entry.iv[3] |= 0x20;
1326 iveiv_entry.iv[3] |= key->keyidx << 6;
1327 rt2800_register_multiwrite(rt2x00dev, offset,
1328 &iveiv_entry, sizeof(iveiv_entry));
1331 int rt2800_config_shared_key(struct rt2x00_dev *rt2x00dev,
1332 struct rt2x00lib_crypto *crypto,
1333 struct ieee80211_key_conf *key)
1335 struct hw_key_entry key_entry;
1336 struct rt2x00_field32 field;
1340 if (crypto->cmd == SET_KEY) {
1341 key->hw_key_idx = (4 * crypto->bssidx) + key->keyidx;
1343 memcpy(key_entry.key, crypto->key,
1344 sizeof(key_entry.key));
1345 memcpy(key_entry.tx_mic, crypto->tx_mic,
1346 sizeof(key_entry.tx_mic));
1347 memcpy(key_entry.rx_mic, crypto->rx_mic,
1348 sizeof(key_entry.rx_mic));
1350 offset = SHARED_KEY_ENTRY(key->hw_key_idx);
1351 rt2800_register_multiwrite(rt2x00dev, offset,
1352 &key_entry, sizeof(key_entry));
1356 * The cipher types are stored over multiple registers
1357 * starting with SHARED_KEY_MODE_BASE each word will have
1358 * 32 bits and contains the cipher types for 2 bssidx each.
1359 * Using the correct defines correctly will cause overhead,
1360 * so just calculate the correct offset.
1362 field.bit_offset = 4 * (key->hw_key_idx % 8);
1363 field.bit_mask = 0x7 << field.bit_offset;
1365 offset = SHARED_KEY_MODE_ENTRY(key->hw_key_idx / 8);
1367 rt2800_register_read(rt2x00dev, offset, ®);
1368 rt2x00_set_field32(®, field,
1369 (crypto->cmd == SET_KEY) * crypto->cipher);
1370 rt2800_register_write(rt2x00dev, offset, reg);
1373 * Update WCID information
1375 rt2800_config_wcid(rt2x00dev, crypto->address, key->hw_key_idx);
1376 rt2800_config_wcid_attr_bssidx(rt2x00dev, key->hw_key_idx,
1378 rt2800_config_wcid_attr_cipher(rt2x00dev, crypto, key);
1382 EXPORT_SYMBOL_GPL(rt2800_config_shared_key);
1384 int rt2800_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
1385 struct rt2x00lib_crypto *crypto,
1386 struct ieee80211_key_conf *key)
1388 struct hw_key_entry key_entry;
1391 if (crypto->cmd == SET_KEY) {
1393 * Allow key configuration only for STAs that are
1396 if (crypto->wcid > WCID_END)
1398 key->hw_key_idx = crypto->wcid;
1400 memcpy(key_entry.key, crypto->key,
1401 sizeof(key_entry.key));
1402 memcpy(key_entry.tx_mic, crypto->tx_mic,
1403 sizeof(key_entry.tx_mic));
1404 memcpy(key_entry.rx_mic, crypto->rx_mic,
1405 sizeof(key_entry.rx_mic));
1407 offset = PAIRWISE_KEY_ENTRY(key->hw_key_idx);
1408 rt2800_register_multiwrite(rt2x00dev, offset,
1409 &key_entry, sizeof(key_entry));
1413 * Update WCID information
1415 rt2800_config_wcid_attr_cipher(rt2x00dev, crypto, key);
1419 EXPORT_SYMBOL_GPL(rt2800_config_pairwise_key);
1421 static void rt2800_set_max_psdu_len(struct rt2x00_dev *rt2x00dev)
1425 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
1427 for (i = 0; i < 3; i++)
1428 if (drv_data->ampdu_factor_cnt[i] > 0)
1431 max_psdu = min(drv_data->max_psdu, i);
1433 rt2800_register_read(rt2x00dev, MAX_LEN_CFG, ®);
1434 rt2x00_set_field32(®, MAX_LEN_CFG_MAX_PSDU, max_psdu);
1435 rt2800_register_write(rt2x00dev, MAX_LEN_CFG, reg);
1438 int rt2800_sta_add(struct rt2x00_dev *rt2x00dev, struct ieee80211_vif *vif,
1439 struct ieee80211_sta *sta)
1442 struct rt2x00_sta *sta_priv = sta_to_rt2x00_sta(sta);
1443 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
1446 * Limit global maximum TX AMPDU length to smallest value of all
1447 * connected stations. In AP mode this can be suboptimal, but we
1448 * do not have a choice if some connected STA is not capable to
1449 * receive the same amount of data like the others.
1451 if (sta->ht_cap.ht_supported) {
1452 drv_data->ampdu_factor_cnt[sta->ht_cap.ampdu_factor & 3]++;
1453 rt2800_set_max_psdu_len(rt2x00dev);
1457 * Search for the first free WCID entry and return the corresponding
1460 wcid = find_first_zero_bit(drv_data->sta_ids, STA_IDS_SIZE) + WCID_START;
1463 * Store selected wcid even if it is invalid so that we can
1464 * later decide if the STA is uploaded into the hw.
1466 sta_priv->wcid = wcid;
1469 * No space left in the device, however, we can still communicate
1470 * with the STA -> No error.
1472 if (wcid > WCID_END)
1475 __set_bit(wcid - WCID_START, drv_data->sta_ids);
1478 * Clean up WCID attributes and write STA address to the device.
1480 rt2800_delete_wcid_attr(rt2x00dev, wcid);
1481 rt2800_config_wcid(rt2x00dev, sta->addr, wcid);
1482 rt2800_config_wcid_attr_bssidx(rt2x00dev, wcid,
1483 rt2x00lib_get_bssidx(rt2x00dev, vif));
1486 EXPORT_SYMBOL_GPL(rt2800_sta_add);
1488 int rt2800_sta_remove(struct rt2x00_dev *rt2x00dev, struct ieee80211_sta *sta)
1490 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
1491 struct rt2x00_sta *sta_priv = sta_to_rt2x00_sta(sta);
1492 int wcid = sta_priv->wcid;
1494 if (sta->ht_cap.ht_supported) {
1495 drv_data->ampdu_factor_cnt[sta->ht_cap.ampdu_factor & 3]--;
1496 rt2800_set_max_psdu_len(rt2x00dev);
1499 if (wcid > WCID_END)
1502 * Remove WCID entry, no need to clean the attributes as they will
1503 * get renewed when the WCID is reused.
1505 rt2800_config_wcid(rt2x00dev, NULL, wcid);
1506 __clear_bit(wcid - WCID_START, drv_data->sta_ids);
1510 EXPORT_SYMBOL_GPL(rt2800_sta_remove);
1512 void rt2800_config_filter(struct rt2x00_dev *rt2x00dev,
1513 const unsigned int filter_flags)
1518 * Start configuration steps.
1519 * Note that the version error will always be dropped
1520 * and broadcast frames will always be accepted since
1521 * there is no filter for it at this time.
1523 rt2800_register_read(rt2x00dev, RX_FILTER_CFG, ®);
1524 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CRC_ERROR,
1525 !(filter_flags & FIF_FCSFAIL));
1526 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_PHY_ERROR,
1527 !(filter_flags & FIF_PLCPFAIL));
1528 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_NOT_TO_ME,
1529 !test_bit(CONFIG_MONITORING, &rt2x00dev->flags));
1530 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_NOT_MY_BSSD, 0);
1531 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_VER_ERROR, 1);
1532 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_MULTICAST,
1533 !(filter_flags & FIF_ALLMULTI));
1534 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_BROADCAST, 0);
1535 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_DUPLICATE, 1);
1536 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CF_END_ACK,
1537 !(filter_flags & FIF_CONTROL));
1538 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CF_END,
1539 !(filter_flags & FIF_CONTROL));
1540 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_ACK,
1541 !(filter_flags & FIF_CONTROL));
1542 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CTS,
1543 !(filter_flags & FIF_CONTROL));
1544 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_RTS,
1545 !(filter_flags & FIF_CONTROL));
1546 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_PSPOLL,
1547 !(filter_flags & FIF_PSPOLL));
1548 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_BA, 0);
1549 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_BAR,
1550 !(filter_flags & FIF_CONTROL));
1551 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CNTL,
1552 !(filter_flags & FIF_CONTROL));
1553 rt2800_register_write(rt2x00dev, RX_FILTER_CFG, reg);
1555 EXPORT_SYMBOL_GPL(rt2800_config_filter);
1557 void rt2800_config_intf(struct rt2x00_dev *rt2x00dev, struct rt2x00_intf *intf,
1558 struct rt2x00intf_conf *conf, const unsigned int flags)
1561 bool update_bssid = false;
1563 if (flags & CONFIG_UPDATE_TYPE) {
1565 * Enable synchronisation.
1567 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®);
1568 rt2x00_set_field32(®, BCN_TIME_CFG_TSF_SYNC, conf->sync);
1569 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
1571 if (conf->sync == TSF_SYNC_AP_NONE) {
1573 * Tune beacon queue transmit parameters for AP mode
1575 rt2800_register_read(rt2x00dev, TBTT_SYNC_CFG, ®);
1576 rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_CWMIN, 0);
1577 rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_AIFSN, 1);
1578 rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_EXP_WIN, 32);
1579 rt2x00_set_field32(®, TBTT_SYNC_CFG_TBTT_ADJUST, 0);
1580 rt2800_register_write(rt2x00dev, TBTT_SYNC_CFG, reg);
1582 rt2800_register_read(rt2x00dev, TBTT_SYNC_CFG, ®);
1583 rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_CWMIN, 4);
1584 rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_AIFSN, 2);
1585 rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_EXP_WIN, 32);
1586 rt2x00_set_field32(®, TBTT_SYNC_CFG_TBTT_ADJUST, 16);
1587 rt2800_register_write(rt2x00dev, TBTT_SYNC_CFG, reg);
1591 if (flags & CONFIG_UPDATE_MAC) {
1592 if (flags & CONFIG_UPDATE_TYPE &&
1593 conf->sync == TSF_SYNC_AP_NONE) {
1595 * The BSSID register has to be set to our own mac
1596 * address in AP mode.
1598 memcpy(conf->bssid, conf->mac, sizeof(conf->mac));
1599 update_bssid = true;
1602 if (!is_zero_ether_addr((const u8 *)conf->mac)) {
1603 reg = le32_to_cpu(conf->mac[1]);
1604 rt2x00_set_field32(®, MAC_ADDR_DW1_UNICAST_TO_ME_MASK, 0xff);
1605 conf->mac[1] = cpu_to_le32(reg);
1608 rt2800_register_multiwrite(rt2x00dev, MAC_ADDR_DW0,
1609 conf->mac, sizeof(conf->mac));
1612 if ((flags & CONFIG_UPDATE_BSSID) || update_bssid) {
1613 if (!is_zero_ether_addr((const u8 *)conf->bssid)) {
1614 reg = le32_to_cpu(conf->bssid[1]);
1615 rt2x00_set_field32(®, MAC_BSSID_DW1_BSS_ID_MASK, 3);
1616 rt2x00_set_field32(®, MAC_BSSID_DW1_BSS_BCN_NUM, 0);
1617 conf->bssid[1] = cpu_to_le32(reg);
1620 rt2800_register_multiwrite(rt2x00dev, MAC_BSSID_DW0,
1621 conf->bssid, sizeof(conf->bssid));
1624 EXPORT_SYMBOL_GPL(rt2800_config_intf);
1626 static void rt2800_config_ht_opmode(struct rt2x00_dev *rt2x00dev,
1627 struct rt2x00lib_erp *erp)
1629 bool any_sta_nongf = !!(erp->ht_opmode &
1630 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
1631 u8 protection = erp->ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION;
1632 u8 mm20_mode, mm40_mode, gf20_mode, gf40_mode;
1633 u16 mm20_rate, mm40_rate, gf20_rate, gf40_rate;
1636 /* default protection rate for HT20: OFDM 24M */
1637 mm20_rate = gf20_rate = 0x4004;
1639 /* default protection rate for HT40: duplicate OFDM 24M */
1640 mm40_rate = gf40_rate = 0x4084;
1642 switch (protection) {
1643 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
1645 * All STAs in this BSS are HT20/40 but there might be
1646 * STAs not supporting greenfield mode.
1647 * => Disable protection for HT transmissions.
1649 mm20_mode = mm40_mode = gf20_mode = gf40_mode = 0;
1652 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
1654 * All STAs in this BSS are HT20 or HT20/40 but there
1655 * might be STAs not supporting greenfield mode.
1656 * => Protect all HT40 transmissions.
1658 mm20_mode = gf20_mode = 0;
1659 mm40_mode = gf40_mode = 1;
1662 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
1664 * Nonmember protection:
1665 * According to 802.11n we _should_ protect all
1666 * HT transmissions (but we don't have to).
1668 * But if cts_protection is enabled we _shall_ protect
1669 * all HT transmissions using a CCK rate.
1671 * And if any station is non GF we _shall_ protect
1674 * We decide to protect everything
1675 * -> fall through to mixed mode.
1677 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
1679 * Legacy STAs are present
1680 * => Protect all HT transmissions.
1682 mm20_mode = mm40_mode = gf20_mode = gf40_mode = 1;
1685 * If erp protection is needed we have to protect HT
1686 * transmissions with CCK 11M long preamble.
1688 if (erp->cts_protection) {
1689 /* don't duplicate RTS/CTS in CCK mode */
1690 mm20_rate = mm40_rate = 0x0003;
1691 gf20_rate = gf40_rate = 0x0003;
1696 /* check for STAs not supporting greenfield mode */
1698 gf20_mode = gf40_mode = 1;
1700 /* Update HT protection config */
1701 rt2800_register_read(rt2x00dev, MM20_PROT_CFG, ®);
1702 rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_RATE, mm20_rate);
1703 rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_CTRL, mm20_mode);
1704 rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
1706 rt2800_register_read(rt2x00dev, MM40_PROT_CFG, ®);
1707 rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_RATE, mm40_rate);
1708 rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_CTRL, mm40_mode);
1709 rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
1711 rt2800_register_read(rt2x00dev, GF20_PROT_CFG, ®);
1712 rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_RATE, gf20_rate);
1713 rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_CTRL, gf20_mode);
1714 rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
1716 rt2800_register_read(rt2x00dev, GF40_PROT_CFG, ®);
1717 rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_RATE, gf40_rate);
1718 rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_CTRL, gf40_mode);
1719 rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
1722 void rt2800_config_erp(struct rt2x00_dev *rt2x00dev, struct rt2x00lib_erp *erp,
1727 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1728 rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, ®);
1729 rt2x00_set_field32(®, AUTO_RSP_CFG_AR_PREAMBLE,
1730 !!erp->short_preamble);
1731 rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
1734 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1735 rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, ®);
1736 rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_CTRL,
1737 erp->cts_protection ? 2 : 0);
1738 rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
1741 if (changed & BSS_CHANGED_BASIC_RATES) {
1742 rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE,
1743 0xff0 | erp->basic_rates);
1744 rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
1747 if (changed & BSS_CHANGED_ERP_SLOT) {
1748 rt2800_register_read(rt2x00dev, BKOFF_SLOT_CFG, ®);
1749 rt2x00_set_field32(®, BKOFF_SLOT_CFG_SLOT_TIME,
1751 rt2800_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg);
1753 rt2800_register_read(rt2x00dev, XIFS_TIME_CFG, ®);
1754 rt2x00_set_field32(®, XIFS_TIME_CFG_EIFS, erp->eifs);
1755 rt2800_register_write(rt2x00dev, XIFS_TIME_CFG, reg);
1758 if (changed & BSS_CHANGED_BEACON_INT) {
1759 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®);
1760 rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_INTERVAL,
1761 erp->beacon_int * 16);
1762 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
1765 if (changed & BSS_CHANGED_HT)
1766 rt2800_config_ht_opmode(rt2x00dev, erp);
1768 EXPORT_SYMBOL_GPL(rt2800_config_erp);
1770 static void rt2800_config_3572bt_ant(struct rt2x00_dev *rt2x00dev)
1774 u8 led_ctrl, led_g_mode, led_r_mode;
1776 rt2800_register_read(rt2x00dev, GPIO_SWITCH, ®);
1777 if (rt2x00dev->curr_band == NL80211_BAND_5GHZ) {
1778 rt2x00_set_field32(®, GPIO_SWITCH_0, 1);
1779 rt2x00_set_field32(®, GPIO_SWITCH_1, 1);
1781 rt2x00_set_field32(®, GPIO_SWITCH_0, 0);
1782 rt2x00_set_field32(®, GPIO_SWITCH_1, 0);
1784 rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg);
1786 rt2800_register_read(rt2x00dev, LED_CFG, ®);
1787 led_g_mode = rt2x00_get_field32(reg, LED_CFG_LED_POLAR) ? 3 : 0;
1788 led_r_mode = rt2x00_get_field32(reg, LED_CFG_LED_POLAR) ? 0 : 3;
1789 if (led_g_mode != rt2x00_get_field32(reg, LED_CFG_G_LED_MODE) ||
1790 led_r_mode != rt2x00_get_field32(reg, LED_CFG_R_LED_MODE)) {
1791 rt2800_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
1792 led_ctrl = rt2x00_get_field16(eeprom, EEPROM_FREQ_LED_MODE);
1793 if (led_ctrl == 0 || led_ctrl > 0x40) {
1794 rt2x00_set_field32(®, LED_CFG_G_LED_MODE, led_g_mode);
1795 rt2x00_set_field32(®, LED_CFG_R_LED_MODE, led_r_mode);
1796 rt2800_register_write(rt2x00dev, LED_CFG, reg);
1798 rt2800_mcu_request(rt2x00dev, MCU_BAND_SELECT, 0xff,
1799 (led_g_mode << 2) | led_r_mode, 1);
1804 static void rt2800_set_ant_diversity(struct rt2x00_dev *rt2x00dev,
1808 u8 eesk_pin = (ant == ANTENNA_A) ? 1 : 0;
1809 u8 gpio_bit3 = (ant == ANTENNA_A) ? 0 : 1;
1811 if (rt2x00_is_pci(rt2x00dev)) {
1812 rt2800_register_read(rt2x00dev, E2PROM_CSR, ®);
1813 rt2x00_set_field32(®, E2PROM_CSR_DATA_CLOCK, eesk_pin);
1814 rt2800_register_write(rt2x00dev, E2PROM_CSR, reg);
1815 } else if (rt2x00_is_usb(rt2x00dev))
1816 rt2800_mcu_request(rt2x00dev, MCU_ANT_SELECT, 0xff,
1819 rt2800_register_read(rt2x00dev, GPIO_CTRL, ®);
1820 rt2x00_set_field32(®, GPIO_CTRL_DIR3, 0);
1821 rt2x00_set_field32(®, GPIO_CTRL_VAL3, gpio_bit3);
1822 rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
1825 void rt2800_config_ant(struct rt2x00_dev *rt2x00dev, struct antenna_setup *ant)
1831 rt2800_bbp_read(rt2x00dev, 1, &r1);
1832 rt2800_bbp_read(rt2x00dev, 3, &r3);
1834 if (rt2x00_rt(rt2x00dev, RT3572) &&
1835 rt2x00_has_cap_bt_coexist(rt2x00dev))
1836 rt2800_config_3572bt_ant(rt2x00dev);
1839 * Configure the TX antenna.
1841 switch (ant->tx_chain_num) {
1843 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0);
1846 if (rt2x00_rt(rt2x00dev, RT3572) &&
1847 rt2x00_has_cap_bt_coexist(rt2x00dev))
1848 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 1);
1850 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2);
1853 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2);
1858 * Configure the RX antenna.
1860 switch (ant->rx_chain_num) {
1862 if (rt2x00_rt(rt2x00dev, RT3070) ||
1863 rt2x00_rt(rt2x00dev, RT3090) ||
1864 rt2x00_rt(rt2x00dev, RT3352) ||
1865 rt2x00_rt(rt2x00dev, RT3390)) {
1866 rt2800_eeprom_read(rt2x00dev,
1867 EEPROM_NIC_CONF1, &eeprom);
1868 if (rt2x00_get_field16(eeprom,
1869 EEPROM_NIC_CONF1_ANT_DIVERSITY))
1870 rt2800_set_ant_diversity(rt2x00dev,
1871 rt2x00dev->default_ant.rx);
1873 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0);
1876 if (rt2x00_rt(rt2x00dev, RT3572) &&
1877 rt2x00_has_cap_bt_coexist(rt2x00dev)) {
1878 rt2x00_set_field8(&r3, BBP3_RX_ADC, 1);
1879 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA,
1880 rt2x00dev->curr_band == NL80211_BAND_5GHZ);
1881 rt2800_set_ant_diversity(rt2x00dev, ANTENNA_B);
1883 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 1);
1887 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 2);
1891 rt2800_bbp_write(rt2x00dev, 3, r3);
1892 rt2800_bbp_write(rt2x00dev, 1, r1);
1894 if (rt2x00_rt(rt2x00dev, RT3593)) {
1895 if (ant->rx_chain_num == 1)
1896 rt2800_bbp_write(rt2x00dev, 86, 0x00);
1898 rt2800_bbp_write(rt2x00dev, 86, 0x46);
1901 EXPORT_SYMBOL_GPL(rt2800_config_ant);
1903 static void rt2800_config_lna_gain(struct rt2x00_dev *rt2x00dev,
1904 struct rt2x00lib_conf *libconf)
1909 if (libconf->rf.channel <= 14) {
1910 rt2800_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
1911 lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_BG);
1912 } else if (libconf->rf.channel <= 64) {
1913 rt2800_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
1914 lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_A0);
1915 } else if (libconf->rf.channel <= 128) {
1916 if (rt2x00_rt(rt2x00dev, RT3593)) {
1917 rt2800_eeprom_read(rt2x00dev, EEPROM_EXT_LNA2, &eeprom);
1918 lna_gain = rt2x00_get_field16(eeprom,
1919 EEPROM_EXT_LNA2_A1);
1921 rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom);
1922 lna_gain = rt2x00_get_field16(eeprom,
1923 EEPROM_RSSI_BG2_LNA_A1);
1926 if (rt2x00_rt(rt2x00dev, RT3593)) {
1927 rt2800_eeprom_read(rt2x00dev, EEPROM_EXT_LNA2, &eeprom);
1928 lna_gain = rt2x00_get_field16(eeprom,
1929 EEPROM_EXT_LNA2_A2);
1931 rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom);
1932 lna_gain = rt2x00_get_field16(eeprom,
1933 EEPROM_RSSI_A2_LNA_A2);
1937 rt2x00dev->lna_gain = lna_gain;
1940 #define FREQ_OFFSET_BOUND 0x5f
1942 static void rt2800_freq_cal_mode1(struct rt2x00_dev *rt2x00dev)
1944 u8 freq_offset, prev_freq_offset;
1945 u8 rfcsr, prev_rfcsr;
1947 freq_offset = rt2x00_get_field8(rt2x00dev->freq_offset, RFCSR17_CODE);
1948 freq_offset = min_t(u8, freq_offset, FREQ_OFFSET_BOUND);
1950 rt2800_rfcsr_read(rt2x00dev, 17, &rfcsr);
1953 rt2x00_set_field8(&rfcsr, RFCSR17_CODE, freq_offset);
1954 if (rfcsr == prev_rfcsr)
1957 if (rt2x00_is_usb(rt2x00dev)) {
1958 rt2800_mcu_request(rt2x00dev, MCU_FREQ_OFFSET, 0xff,
1959 freq_offset, prev_rfcsr);
1963 prev_freq_offset = rt2x00_get_field8(prev_rfcsr, RFCSR17_CODE);
1964 while (prev_freq_offset != freq_offset) {
1965 if (prev_freq_offset < freq_offset)
1970 rt2x00_set_field8(&rfcsr, RFCSR17_CODE, prev_freq_offset);
1971 rt2800_rfcsr_write(rt2x00dev, 17, rfcsr);
1973 usleep_range(1000, 1500);
1977 static void rt2800_config_channel_rf2xxx(struct rt2x00_dev *rt2x00dev,
1978 struct ieee80211_conf *conf,
1979 struct rf_channel *rf,
1980 struct channel_info *info)
1982 rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
1984 if (rt2x00dev->default_ant.tx_chain_num == 1)
1985 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_TX1, 1);
1987 if (rt2x00dev->default_ant.rx_chain_num == 1) {
1988 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX1, 1);
1989 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
1990 } else if (rt2x00dev->default_ant.rx_chain_num == 2)
1991 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
1993 if (rf->channel > 14) {
1995 * When TX power is below 0, we should increase it by 7 to
1996 * make it a positive value (Minimum value is -7).
1997 * However this means that values between 0 and 7 have
1998 * double meaning, and we should set a 7DBm boost flag.
2000 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A_7DBM_BOOST,
2001 (info->default_power1 >= 0));
2003 if (info->default_power1 < 0)
2004 info->default_power1 += 7;
2006 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A, info->default_power1);
2008 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A_7DBM_BOOST,
2009 (info->default_power2 >= 0));
2011 if (info->default_power2 < 0)
2012 info->default_power2 += 7;
2014 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A, info->default_power2);
2016 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_G, info->default_power1);
2017 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_G, info->default_power2);
2020 rt2x00_set_field32(&rf->rf4, RF4_HT40, conf_is_ht40(conf));
2022 rt2800_rf_write(rt2x00dev, 1, rf->rf1);
2023 rt2800_rf_write(rt2x00dev, 2, rf->rf2);
2024 rt2800_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
2025 rt2800_rf_write(rt2x00dev, 4, rf->rf4);
2029 rt2800_rf_write(rt2x00dev, 1, rf->rf1);
2030 rt2800_rf_write(rt2x00dev, 2, rf->rf2);
2031 rt2800_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
2032 rt2800_rf_write(rt2x00dev, 4, rf->rf4);
2036 rt2800_rf_write(rt2x00dev, 1, rf->rf1);
2037 rt2800_rf_write(rt2x00dev, 2, rf->rf2);
2038 rt2800_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
2039 rt2800_rf_write(rt2x00dev, 4, rf->rf4);
2042 static void rt2800_config_channel_rf3xxx(struct rt2x00_dev *rt2x00dev,
2043 struct ieee80211_conf *conf,
2044 struct rf_channel *rf,
2045 struct channel_info *info)
2047 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
2048 u8 rfcsr, calib_tx, calib_rx;
2050 rt2800_rfcsr_write(rt2x00dev, 2, rf->rf1);
2052 rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr);
2053 rt2x00_set_field8(&rfcsr, RFCSR3_K, rf->rf3);
2054 rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
2056 rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr);
2057 rt2x00_set_field8(&rfcsr, RFCSR6_R1, rf->rf2);
2058 rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
2060 rt2800_rfcsr_read(rt2x00dev, 12, &rfcsr);
2061 rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER, info->default_power1);
2062 rt2800_rfcsr_write(rt2x00dev, 12, rfcsr);
2064 rt2800_rfcsr_read(rt2x00dev, 13, &rfcsr);
2065 rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER, info->default_power2);
2066 rt2800_rfcsr_write(rt2x00dev, 13, rfcsr);
2068 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
2069 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0);
2070 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD,
2071 rt2x00dev->default_ant.rx_chain_num <= 1);
2072 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD,
2073 rt2x00dev->default_ant.rx_chain_num <= 2);
2074 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0);
2075 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD,
2076 rt2x00dev->default_ant.tx_chain_num <= 1);
2077 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD,
2078 rt2x00dev->default_ant.tx_chain_num <= 2);
2079 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
2081 rt2800_rfcsr_read(rt2x00dev, 23, &rfcsr);
2082 rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset);
2083 rt2800_rfcsr_write(rt2x00dev, 23, rfcsr);
2085 if (rt2x00_rt(rt2x00dev, RT3390)) {
2086 calib_tx = conf_is_ht40(conf) ? 0x68 : 0x4f;
2087 calib_rx = conf_is_ht40(conf) ? 0x6f : 0x4f;
2089 if (conf_is_ht40(conf)) {
2090 calib_tx = drv_data->calibration_bw40;
2091 calib_rx = drv_data->calibration_bw40;
2093 calib_tx = drv_data->calibration_bw20;
2094 calib_rx = drv_data->calibration_bw20;
2098 rt2800_rfcsr_read(rt2x00dev, 24, &rfcsr);
2099 rt2x00_set_field8(&rfcsr, RFCSR24_TX_CALIB, calib_tx);
2100 rt2800_rfcsr_write(rt2x00dev, 24, rfcsr);
2102 rt2800_rfcsr_read(rt2x00dev, 31, &rfcsr);
2103 rt2x00_set_field8(&rfcsr, RFCSR31_RX_CALIB, calib_rx);
2104 rt2800_rfcsr_write(rt2x00dev, 31, rfcsr);
2106 rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr);
2107 rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
2108 rt2800_rfcsr_write(rt2x00dev, 7, rfcsr);
2110 rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
2111 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1);
2112 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
2114 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0);
2115 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
2118 static void rt2800_config_channel_rf3052(struct rt2x00_dev *rt2x00dev,
2119 struct ieee80211_conf *conf,
2120 struct rf_channel *rf,
2121 struct channel_info *info)
2123 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
2127 if (rf->channel <= 14) {
2128 rt2800_bbp_write(rt2x00dev, 25, drv_data->bbp25);
2129 rt2800_bbp_write(rt2x00dev, 26, drv_data->bbp26);
2131 rt2800_bbp_write(rt2x00dev, 25, 0x09);
2132 rt2800_bbp_write(rt2x00dev, 26, 0xff);
2135 rt2800_rfcsr_write(rt2x00dev, 2, rf->rf1);
2136 rt2800_rfcsr_write(rt2x00dev, 3, rf->rf3);
2138 rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr);
2139 rt2x00_set_field8(&rfcsr, RFCSR6_R1, rf->rf2);
2140 if (rf->channel <= 14)
2141 rt2x00_set_field8(&rfcsr, RFCSR6_TXDIV, 2);
2143 rt2x00_set_field8(&rfcsr, RFCSR6_TXDIV, 1);
2144 rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
2146 rt2800_rfcsr_read(rt2x00dev, 5, &rfcsr);
2147 if (rf->channel <= 14)
2148 rt2x00_set_field8(&rfcsr, RFCSR5_R1, 1);
2150 rt2x00_set_field8(&rfcsr, RFCSR5_R1, 2);
2151 rt2800_rfcsr_write(rt2x00dev, 5, rfcsr);
2153 rt2800_rfcsr_read(rt2x00dev, 12, &rfcsr);
2154 if (rf->channel <= 14) {
2155 rt2x00_set_field8(&rfcsr, RFCSR12_DR0, 3);
2156 rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER,
2157 info->default_power1);
2159 rt2x00_set_field8(&rfcsr, RFCSR12_DR0, 7);
2160 rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER,
2161 (info->default_power1 & 0x3) |
2162 ((info->default_power1 & 0xC) << 1));
2164 rt2800_rfcsr_write(rt2x00dev, 12, rfcsr);
2166 rt2800_rfcsr_read(rt2x00dev, 13, &rfcsr);
2167 if (rf->channel <= 14) {
2168 rt2x00_set_field8(&rfcsr, RFCSR13_DR0, 3);
2169 rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER,
2170 info->default_power2);
2172 rt2x00_set_field8(&rfcsr, RFCSR13_DR0, 7);
2173 rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER,
2174 (info->default_power2 & 0x3) |
2175 ((info->default_power2 & 0xC) << 1));
2177 rt2800_rfcsr_write(rt2x00dev, 13, rfcsr);
2179 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
2180 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0);
2181 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0);
2182 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 0);
2183 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 0);
2184 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0);
2185 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0);
2186 if (rt2x00_has_cap_bt_coexist(rt2x00dev)) {
2187 if (rf->channel <= 14) {
2188 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1);
2189 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1);
2191 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 1);
2192 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 1);
2194 switch (rt2x00dev->default_ant.tx_chain_num) {
2196 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
2198 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 1);
2202 switch (rt2x00dev->default_ant.rx_chain_num) {
2204 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
2206 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 1);
2210 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
2212 rt2800_rfcsr_read(rt2x00dev, 23, &rfcsr);
2213 rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset);
2214 rt2800_rfcsr_write(rt2x00dev, 23, rfcsr);
2216 if (conf_is_ht40(conf)) {
2217 rt2800_rfcsr_write(rt2x00dev, 24, drv_data->calibration_bw40);
2218 rt2800_rfcsr_write(rt2x00dev, 31, drv_data->calibration_bw40);
2220 rt2800_rfcsr_write(rt2x00dev, 24, drv_data->calibration_bw20);
2221 rt2800_rfcsr_write(rt2x00dev, 31, drv_data->calibration_bw20);
2224 if (rf->channel <= 14) {
2225 rt2800_rfcsr_write(rt2x00dev, 7, 0xd8);
2226 rt2800_rfcsr_write(rt2x00dev, 9, 0xc3);
2227 rt2800_rfcsr_write(rt2x00dev, 10, 0xf1);
2228 rt2800_rfcsr_write(rt2x00dev, 11, 0xb9);
2229 rt2800_rfcsr_write(rt2x00dev, 15, 0x53);
2231 rt2x00_set_field8(&rfcsr, RFCSR16_TXMIXER_GAIN,
2232 drv_data->txmixer_gain_24g);
2233 rt2800_rfcsr_write(rt2x00dev, 16, rfcsr);
2234 rt2800_rfcsr_write(rt2x00dev, 17, 0x23);
2235 rt2800_rfcsr_write(rt2x00dev, 19, 0x93);
2236 rt2800_rfcsr_write(rt2x00dev, 20, 0xb3);
2237 rt2800_rfcsr_write(rt2x00dev, 25, 0x15);
2238 rt2800_rfcsr_write(rt2x00dev, 26, 0x85);
2239 rt2800_rfcsr_write(rt2x00dev, 27, 0x00);
2240 rt2800_rfcsr_write(rt2x00dev, 29, 0x9b);
2242 rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr);
2243 rt2x00_set_field8(&rfcsr, RFCSR7_BIT2, 1);
2244 rt2x00_set_field8(&rfcsr, RFCSR7_BIT3, 0);
2245 rt2x00_set_field8(&rfcsr, RFCSR7_BIT4, 1);
2246 rt2x00_set_field8(&rfcsr, RFCSR7_BITS67, 0);
2247 rt2800_rfcsr_write(rt2x00dev, 7, rfcsr);
2248 rt2800_rfcsr_write(rt2x00dev, 9, 0xc0);
2249 rt2800_rfcsr_write(rt2x00dev, 10, 0xf1);
2250 rt2800_rfcsr_write(rt2x00dev, 11, 0x00);
2251 rt2800_rfcsr_write(rt2x00dev, 15, 0x43);
2253 rt2x00_set_field8(&rfcsr, RFCSR16_TXMIXER_GAIN,
2254 drv_data->txmixer_gain_5g);
2255 rt2800_rfcsr_write(rt2x00dev, 16, rfcsr);
2256 rt2800_rfcsr_write(rt2x00dev, 17, 0x23);
2257 if (rf->channel <= 64) {
2258 rt2800_rfcsr_write(rt2x00dev, 19, 0xb7);
2259 rt2800_rfcsr_write(rt2x00dev, 20, 0xf6);
2260 rt2800_rfcsr_write(rt2x00dev, 25, 0x3d);
2261 } else if (rf->channel <= 128) {
2262 rt2800_rfcsr_write(rt2x00dev, 19, 0x74);
2263 rt2800_rfcsr_write(rt2x00dev, 20, 0xf4);
2264 rt2800_rfcsr_write(rt2x00dev, 25, 0x01);
2266 rt2800_rfcsr_write(rt2x00dev, 19, 0x72);
2267 rt2800_rfcsr_write(rt2x00dev, 20, 0xf3);
2268 rt2800_rfcsr_write(rt2x00dev, 25, 0x01);
2270 rt2800_rfcsr_write(rt2x00dev, 26, 0x87);
2271 rt2800_rfcsr_write(rt2x00dev, 27, 0x01);
2272 rt2800_rfcsr_write(rt2x00dev, 29, 0x9f);
2275 rt2800_register_read(rt2x00dev, GPIO_CTRL, ®);
2276 rt2x00_set_field32(®, GPIO_CTRL_DIR7, 0);
2277 if (rf->channel <= 14)
2278 rt2x00_set_field32(®, GPIO_CTRL_VAL7, 1);
2280 rt2x00_set_field32(®, GPIO_CTRL_VAL7, 0);
2281 rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
2283 rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr);
2284 rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
2285 rt2800_rfcsr_write(rt2x00dev, 7, rfcsr);
2288 static void rt2800_config_channel_rf3053(struct rt2x00_dev *rt2x00dev,
2289 struct ieee80211_conf *conf,
2290 struct rf_channel *rf,
2291 struct channel_info *info)
2293 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
2298 const bool txbf_enabled = false; /* TODO */
2300 /* TODO: use TX{0,1,2}FinePowerControl values from EEPROM */
2301 rt2800_bbp_read(rt2x00dev, 109, &bbp);
2302 rt2x00_set_field8(&bbp, BBP109_TX0_POWER, 0);
2303 rt2x00_set_field8(&bbp, BBP109_TX1_POWER, 0);
2304 rt2800_bbp_write(rt2x00dev, 109, bbp);
2306 rt2800_bbp_read(rt2x00dev, 110, &bbp);
2307 rt2x00_set_field8(&bbp, BBP110_TX2_POWER, 0);
2308 rt2800_bbp_write(rt2x00dev, 110, bbp);
2310 if (rf->channel <= 14) {
2311 /* Restore BBP 25 & 26 for 2.4 GHz */
2312 rt2800_bbp_write(rt2x00dev, 25, drv_data->bbp25);
2313 rt2800_bbp_write(rt2x00dev, 26, drv_data->bbp26);
2315 /* Hard code BBP 25 & 26 for 5GHz */
2317 /* Enable IQ Phase correction */
2318 rt2800_bbp_write(rt2x00dev, 25, 0x09);
2319 /* Setup IQ Phase correction value */
2320 rt2800_bbp_write(rt2x00dev, 26, 0xff);
2323 rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1);
2324 rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3 & 0xf);
2326 rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr);
2327 rt2x00_set_field8(&rfcsr, RFCSR11_R, (rf->rf2 & 0x3));
2328 rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
2330 rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr);
2331 rt2x00_set_field8(&rfcsr, RFCSR11_PLL_IDOH, 1);
2332 if (rf->channel <= 14)
2333 rt2x00_set_field8(&rfcsr, RFCSR11_PLL_MOD, 1);
2335 rt2x00_set_field8(&rfcsr, RFCSR11_PLL_MOD, 2);
2336 rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
2338 rt2800_rfcsr_read(rt2x00dev, 53, &rfcsr);
2339 if (rf->channel <= 14) {
2341 rt2x00_set_field8(&rfcsr, RFCSR53_TX_POWER,
2342 info->default_power1 & 0x1f);
2344 if (rt2x00_is_usb(rt2x00dev))
2347 rt2x00_set_field8(&rfcsr, RFCSR53_TX_POWER,
2348 ((info->default_power1 & 0x18) << 1) |
2349 (info->default_power1 & 7));
2351 rt2800_rfcsr_write(rt2x00dev, 53, rfcsr);
2353 rt2800_rfcsr_read(rt2x00dev, 55, &rfcsr);
2354 if (rf->channel <= 14) {
2356 rt2x00_set_field8(&rfcsr, RFCSR55_TX_POWER,
2357 info->default_power2 & 0x1f);
2359 if (rt2x00_is_usb(rt2x00dev))
2362 rt2x00_set_field8(&rfcsr, RFCSR55_TX_POWER,
2363 ((info->default_power2 & 0x18) << 1) |
2364 (info->default_power2 & 7));
2366 rt2800_rfcsr_write(rt2x00dev, 55, rfcsr);
2368 rt2800_rfcsr_read(rt2x00dev, 54, &rfcsr);
2369 if (rf->channel <= 14) {
2371 rt2x00_set_field8(&rfcsr, RFCSR54_TX_POWER,
2372 info->default_power3 & 0x1f);
2374 if (rt2x00_is_usb(rt2x00dev))
2377 rt2x00_set_field8(&rfcsr, RFCSR54_TX_POWER,
2378 ((info->default_power3 & 0x18) << 1) |
2379 (info->default_power3 & 7));
2381 rt2800_rfcsr_write(rt2x00dev, 54, rfcsr);
2383 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
2384 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0);
2385 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0);
2386 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 0);
2387 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 0);
2388 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0);
2389 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0);
2390 rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
2391 rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1);
2393 switch (rt2x00dev->default_ant.tx_chain_num) {
2395 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 1);
2398 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
2401 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1);
2405 switch (rt2x00dev->default_ant.rx_chain_num) {
2407 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 1);
2410 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
2413 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1);
2416 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
2418 rt2800_freq_cal_mode1(rt2x00dev);
2420 if (conf_is_ht40(conf)) {
2421 txrx_agc_fc = rt2x00_get_field8(drv_data->calibration_bw40,
2423 txrx_h20m = rt2x00_get_field8(drv_data->calibration_bw40,
2426 txrx_agc_fc = rt2x00_get_field8(drv_data->calibration_bw20,
2428 txrx_h20m = rt2x00_get_field8(drv_data->calibration_bw20,
2432 /* NOTE: the reference driver does not writes the new value
2435 rt2800_rfcsr_read(rt2x00dev, 32, &rfcsr);
2436 rt2x00_set_field8(&rfcsr, RFCSR32_TX_AGC_FC, txrx_agc_fc);
2438 if (rf->channel <= 14)
2442 rt2800_rfcsr_write(rt2x00dev, 31, rfcsr);
2444 rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
2445 rt2x00_set_field8(&rfcsr, RFCSR30_TX_H20M, txrx_h20m);
2446 rt2x00_set_field8(&rfcsr, RFCSR30_RX_H20M, txrx_h20m);
2447 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
2449 /* Band selection */
2450 rt2800_rfcsr_read(rt2x00dev, 36, &rfcsr);
2451 if (rf->channel <= 14)
2452 rt2x00_set_field8(&rfcsr, RFCSR36_RF_BS, 1);
2454 rt2x00_set_field8(&rfcsr, RFCSR36_RF_BS, 0);
2455 rt2800_rfcsr_write(rt2x00dev, 36, rfcsr);
2457 rt2800_rfcsr_read(rt2x00dev, 34, &rfcsr);
2458 if (rf->channel <= 14)
2462 rt2800_rfcsr_write(rt2x00dev, 34, rfcsr);
2464 rt2800_rfcsr_read(rt2x00dev, 12, &rfcsr);
2465 if (rf->channel <= 14)
2469 rt2800_rfcsr_write(rt2x00dev, 12, rfcsr);
2471 rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr);
2472 if (rf->channel >= 1 && rf->channel <= 14)
2473 rt2x00_set_field8(&rfcsr, RFCSR6_VCO_IC, 1);
2474 else if (rf->channel >= 36 && rf->channel <= 64)
2475 rt2x00_set_field8(&rfcsr, RFCSR6_VCO_IC, 2);
2476 else if (rf->channel >= 100 && rf->channel <= 128)
2477 rt2x00_set_field8(&rfcsr, RFCSR6_VCO_IC, 2);
2479 rt2x00_set_field8(&rfcsr, RFCSR6_VCO_IC, 1);
2480 rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
2482 rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
2483 rt2x00_set_field8(&rfcsr, RFCSR30_RX_VCM, 2);
2484 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
2486 rt2800_rfcsr_write(rt2x00dev, 46, 0x60);
2488 if (rf->channel <= 14) {
2489 rt2800_rfcsr_write(rt2x00dev, 10, 0xd3);
2490 rt2800_rfcsr_write(rt2x00dev, 13, 0x12);
2492 rt2800_rfcsr_write(rt2x00dev, 10, 0xd8);
2493 rt2800_rfcsr_write(rt2x00dev, 13, 0x23);
2496 rt2800_rfcsr_read(rt2x00dev, 51, &rfcsr);
2497 rt2x00_set_field8(&rfcsr, RFCSR51_BITS01, 1);
2498 rt2800_rfcsr_write(rt2x00dev, 51, rfcsr);
2500 rt2800_rfcsr_read(rt2x00dev, 51, &rfcsr);
2501 if (rf->channel <= 14) {
2502 rt2x00_set_field8(&rfcsr, RFCSR51_BITS24, 5);
2503 rt2x00_set_field8(&rfcsr, RFCSR51_BITS57, 3);
2505 rt2x00_set_field8(&rfcsr, RFCSR51_BITS24, 4);
2506 rt2x00_set_field8(&rfcsr, RFCSR51_BITS57, 2);
2508 rt2800_rfcsr_write(rt2x00dev, 51, rfcsr);
2510 rt2800_rfcsr_read(rt2x00dev, 49, &rfcsr);
2511 if (rf->channel <= 14)
2512 rt2x00_set_field8(&rfcsr, RFCSR49_TX_LO1_IC, 3);
2514 rt2x00_set_field8(&rfcsr, RFCSR49_TX_LO1_IC, 2);
2517 rt2x00_set_field8(&rfcsr, RFCSR49_TX_DIV, 1);
2519 rt2800_rfcsr_write(rt2x00dev, 49, rfcsr);
2521 rt2800_rfcsr_read(rt2x00dev, 50, &rfcsr);
2522 rt2x00_set_field8(&rfcsr, RFCSR50_TX_LO1_EN, 0);
2523 rt2800_rfcsr_write(rt2x00dev, 50, rfcsr);
2525 rt2800_rfcsr_read(rt2x00dev, 57, &rfcsr);
2526 if (rf->channel <= 14)
2527 rt2x00_set_field8(&rfcsr, RFCSR57_DRV_CC, 0x1b);
2529 rt2x00_set_field8(&rfcsr, RFCSR57_DRV_CC, 0x0f);
2530 rt2800_rfcsr_write(rt2x00dev, 57, rfcsr);
2532 if (rf->channel <= 14) {
2533 rt2800_rfcsr_write(rt2x00dev, 44, 0x93);
2534 rt2800_rfcsr_write(rt2x00dev, 52, 0x45);
2536 rt2800_rfcsr_write(rt2x00dev, 44, 0x9b);
2537 rt2800_rfcsr_write(rt2x00dev, 52, 0x05);
2540 /* Initiate VCO calibration */
2541 rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr);
2542 if (rf->channel <= 14) {
2543 rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
2545 rt2x00_set_field8(&rfcsr, RFCSR3_BIT1, 1);
2546 rt2x00_set_field8(&rfcsr, RFCSR3_BIT2, 1);
2547 rt2x00_set_field8(&rfcsr, RFCSR3_BIT3, 1);
2548 rt2x00_set_field8(&rfcsr, RFCSR3_BIT4, 1);
2549 rt2x00_set_field8(&rfcsr, RFCSR3_BIT5, 1);
2550 rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
2552 rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
2554 if (rf->channel >= 1 && rf->channel <= 14) {
2557 rt2x00_set_field8(&rfcsr, RFCSR39_RX_DIV, 1);
2558 rt2800_rfcsr_write(rt2x00dev, 39, rfcsr);
2560 rt2800_rfcsr_write(rt2x00dev, 45, 0xbb);
2561 } else if (rf->channel >= 36 && rf->channel <= 64) {
2564 rt2x00_set_field8(&rfcsr, RFCSR39_RX_DIV, 1);
2565 rt2800_rfcsr_write(rt2x00dev, 39, 0x36);
2567 rt2800_rfcsr_write(rt2x00dev, 45, 0xeb);
2568 } else if (rf->channel >= 100 && rf->channel <= 128) {
2571 rt2x00_set_field8(&rfcsr, RFCSR39_RX_DIV, 1);
2572 rt2800_rfcsr_write(rt2x00dev, 39, rfcsr);
2574 rt2800_rfcsr_write(rt2x00dev, 45, 0xb3);
2578 rt2x00_set_field8(&rfcsr, RFCSR39_RX_DIV, 1);
2579 rt2800_rfcsr_write(rt2x00dev, 39, rfcsr);
2581 rt2800_rfcsr_write(rt2x00dev, 45, 0x9b);
2585 #define POWER_BOUND 0x27
2586 #define POWER_BOUND_5G 0x2b
2588 static void rt2800_config_channel_rf3290(struct rt2x00_dev *rt2x00dev,
2589 struct ieee80211_conf *conf,
2590 struct rf_channel *rf,
2591 struct channel_info *info)
2595 rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1);
2596 rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3);
2597 rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr);
2598 rt2x00_set_field8(&rfcsr, RFCSR11_R, rf->rf2);
2599 rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
2601 rt2800_rfcsr_read(rt2x00dev, 49, &rfcsr);
2602 if (info->default_power1 > POWER_BOUND)
2603 rt2x00_set_field8(&rfcsr, RFCSR49_TX, POWER_BOUND);
2605 rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1);
2606 rt2800_rfcsr_write(rt2x00dev, 49, rfcsr);
2608 rt2800_freq_cal_mode1(rt2x00dev);
2610 if (rf->channel <= 14) {
2611 if (rf->channel == 6)
2612 rt2800_bbp_write(rt2x00dev, 68, 0x0c);
2614 rt2800_bbp_write(rt2x00dev, 68, 0x0b);
2616 if (rf->channel >= 1 && rf->channel <= 6)
2617 rt2800_bbp_write(rt2x00dev, 59, 0x0f);
2618 else if (rf->channel >= 7 && rf->channel <= 11)
2619 rt2800_bbp_write(rt2x00dev, 59, 0x0e);
2620 else if (rf->channel >= 12 && rf->channel <= 14)
2621 rt2800_bbp_write(rt2x00dev, 59, 0x0d);
2625 static void rt2800_config_channel_rf3322(struct rt2x00_dev *rt2x00dev,
2626 struct ieee80211_conf *conf,
2627 struct rf_channel *rf,
2628 struct channel_info *info)
2632 rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1);
2633 rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3);
2635 rt2800_rfcsr_write(rt2x00dev, 11, 0x42);
2636 rt2800_rfcsr_write(rt2x00dev, 12, 0x1c);
2637 rt2800_rfcsr_write(rt2x00dev, 13, 0x00);
2639 if (info->default_power1 > POWER_BOUND)
2640 rt2800_rfcsr_write(rt2x00dev, 47, POWER_BOUND);
2642 rt2800_rfcsr_write(rt2x00dev, 47, info->default_power1);
2644 if (info->default_power2 > POWER_BOUND)
2645 rt2800_rfcsr_write(rt2x00dev, 48, POWER_BOUND);
2647 rt2800_rfcsr_write(rt2x00dev, 48, info->default_power2);
2649 rt2800_freq_cal_mode1(rt2x00dev);
2651 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
2652 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1);
2653 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1);
2655 if ( rt2x00dev->default_ant.tx_chain_num == 2 )
2656 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
2658 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 0);
2660 if ( rt2x00dev->default_ant.rx_chain_num == 2 )
2661 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
2663 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 0);
2665 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0);
2666 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0);
2668 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
2670 rt2800_rfcsr_write(rt2x00dev, 31, 80);
2673 static void rt2800_config_channel_rf53xx(struct rt2x00_dev *rt2x00dev,
2674 struct ieee80211_conf *conf,
2675 struct rf_channel *rf,
2676 struct channel_info *info)
2680 rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1);
2681 rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3);
2682 rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr);
2683 rt2x00_set_field8(&rfcsr, RFCSR11_R, rf->rf2);
2684 rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
2686 rt2800_rfcsr_read(rt2x00dev, 49, &rfcsr);
2687 if (info->default_power1 > POWER_BOUND)
2688 rt2x00_set_field8(&rfcsr, RFCSR49_TX, POWER_BOUND);
2690 rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1);
2691 rt2800_rfcsr_write(rt2x00dev, 49, rfcsr);
2693 if (rt2x00_rt(rt2x00dev, RT5392)) {
2694 rt2800_rfcsr_read(rt2x00dev, 50, &rfcsr);
2695 if (info->default_power2 > POWER_BOUND)
2696 rt2x00_set_field8(&rfcsr, RFCSR50_TX, POWER_BOUND);
2698 rt2x00_set_field8(&rfcsr, RFCSR50_TX,
2699 info->default_power2);
2700 rt2800_rfcsr_write(rt2x00dev, 50, rfcsr);
2703 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
2704 if (rt2x00_rt(rt2x00dev, RT5392)) {
2705 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
2706 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
2708 rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
2709 rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1);
2710 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1);
2711 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1);
2712 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
2714 rt2800_freq_cal_mode1(rt2x00dev);
2716 if (rf->channel <= 14) {
2717 int idx = rf->channel-1;
2719 if (rt2x00_has_cap_bt_coexist(rt2x00dev)) {
2720 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) {
2721 /* r55/r59 value array of channel 1~14 */
2722 static const char r55_bt_rev[] = {0x83, 0x83,
2723 0x83, 0x73, 0x73, 0x63, 0x53, 0x53,
2724 0x53, 0x43, 0x43, 0x43, 0x43, 0x43};
2725 static const char r59_bt_rev[] = {0x0e, 0x0e,
2726 0x0e, 0x0e, 0x0e, 0x0b, 0x0a, 0x09,
2727 0x07, 0x07, 0x07, 0x07, 0x07, 0x07};
2729 rt2800_rfcsr_write(rt2x00dev, 55,
2731 rt2800_rfcsr_write(rt2x00dev, 59,
2734 static const char r59_bt[] = {0x8b, 0x8b, 0x8b,
2735 0x8b, 0x8b, 0x8b, 0x8b, 0x8a, 0x89,
2736 0x88, 0x88, 0x86, 0x85, 0x84};
2738 rt2800_rfcsr_write(rt2x00dev, 59, r59_bt[idx]);
2741 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) {
2742 static const char r55_nonbt_rev[] = {0x23, 0x23,
2743 0x23, 0x23, 0x13, 0x13, 0x03, 0x03,
2744 0x03, 0x03, 0x03, 0x03, 0x03, 0x03};
2745 static const char r59_nonbt_rev[] = {0x07, 0x07,
2746 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
2747 0x07, 0x07, 0x06, 0x05, 0x04, 0x04};
2749 rt2800_rfcsr_write(rt2x00dev, 55,
2750 r55_nonbt_rev[idx]);
2751 rt2800_rfcsr_write(rt2x00dev, 59,
2752 r59_nonbt_rev[idx]);
2753 } else if (rt2x00_rt(rt2x00dev, RT5390) ||
2754 rt2x00_rt(rt2x00dev, RT5392)) {
2755 static const char r59_non_bt[] = {0x8f, 0x8f,
2756 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8d,
2757 0x8a, 0x88, 0x88, 0x87, 0x87, 0x86};
2759 rt2800_rfcsr_write(rt2x00dev, 59,
2766 static void rt2800_config_channel_rf55xx(struct rt2x00_dev *rt2x00dev,
2767 struct ieee80211_conf *conf,
2768 struct rf_channel *rf,
2769 struct channel_info *info)
2776 const bool is_11b = false;
2777 const bool is_type_ep = false;
2779 rt2800_register_read(rt2x00dev, LDO_CFG0, ®);
2780 rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL,
2781 (rf->channel > 14 || conf_is_ht40(conf)) ? 5 : 0);
2782 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
2784 /* Order of values on rf_channel entry: N, K, mod, R */
2785 rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1 & 0xff);
2787 rt2800_rfcsr_read(rt2x00dev, 9, &rfcsr);
2788 rt2x00_set_field8(&rfcsr, RFCSR9_K, rf->rf2 & 0xf);
2789 rt2x00_set_field8(&rfcsr, RFCSR9_N, (rf->rf1 & 0x100) >> 8);
2790 rt2x00_set_field8(&rfcsr, RFCSR9_MOD, ((rf->rf3 - 8) & 0x4) >> 2);
2791 rt2800_rfcsr_write(rt2x00dev, 9, rfcsr);
2793 rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr);
2794 rt2x00_set_field8(&rfcsr, RFCSR11_R, rf->rf4 - 1);
2795 rt2x00_set_field8(&rfcsr, RFCSR11_MOD, (rf->rf3 - 8) & 0x3);
2796 rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
2798 if (rf->channel <= 14) {
2799 rt2800_rfcsr_write(rt2x00dev, 10, 0x90);
2800 /* FIXME: RF11 owerwrite ? */
2801 rt2800_rfcsr_write(rt2x00dev, 11, 0x4A);
2802 rt2800_rfcsr_write(rt2x00dev, 12, 0x52);
2803 rt2800_rfcsr_write(rt2x00dev, 13, 0x42);
2804 rt2800_rfcsr_write(rt2x00dev, 22, 0x40);
2805 rt2800_rfcsr_write(rt2x00dev, 24, 0x4A);
2806 rt2800_rfcsr_write(rt2x00dev, 25, 0x80);
2807 rt2800_rfcsr_write(rt2x00dev, 27, 0x42);
2808 rt2800_rfcsr_write(rt2x00dev, 36, 0x80);
2809 rt2800_rfcsr_write(rt2x00dev, 37, 0x08);
2810 rt2800_rfcsr_write(rt2x00dev, 38, 0x89);
2811 rt2800_rfcsr_write(rt2x00dev, 39, 0x1B);
2812 rt2800_rfcsr_write(rt2x00dev, 40, 0x0D);
2813 rt2800_rfcsr_write(rt2x00dev, 41, 0x9B);
2814 rt2800_rfcsr_write(rt2x00dev, 42, 0xD5);
2815 rt2800_rfcsr_write(rt2x00dev, 43, 0x72);
2816 rt2800_rfcsr_write(rt2x00dev, 44, 0x0E);
2817 rt2800_rfcsr_write(rt2x00dev, 45, 0xA2);
2818 rt2800_rfcsr_write(rt2x00dev, 46, 0x6B);
2819 rt2800_rfcsr_write(rt2x00dev, 48, 0x10);
2820 rt2800_rfcsr_write(rt2x00dev, 51, 0x3E);
2821 rt2800_rfcsr_write(rt2x00dev, 52, 0x48);
2822 rt2800_rfcsr_write(rt2x00dev, 54, 0x38);
2823 rt2800_rfcsr_write(rt2x00dev, 56, 0xA1);
2824 rt2800_rfcsr_write(rt2x00dev, 57, 0x00);
2825 rt2800_rfcsr_write(rt2x00dev, 58, 0x39);
2826 rt2800_rfcsr_write(rt2x00dev, 60, 0x45);
2827 rt2800_rfcsr_write(rt2x00dev, 61, 0x91);
2828 rt2800_rfcsr_write(rt2x00dev, 62, 0x39);
2830 /* TODO RF27 <- tssi */
2832 rfcsr = rf->channel <= 10 ? 0x07 : 0x06;
2833 rt2800_rfcsr_write(rt2x00dev, 23, rfcsr);
2834 rt2800_rfcsr_write(rt2x00dev, 59, rfcsr);
2838 rt2800_rfcsr_write(rt2x00dev, 31, 0xF8);
2839 rt2800_rfcsr_write(rt2x00dev, 32, 0xC0);
2841 rt2800_rfcsr_write(rt2x00dev, 55, 0x06);
2843 rt2800_rfcsr_write(rt2x00dev, 55, 0x47);
2847 rt2800_rfcsr_write(rt2x00dev, 55, 0x03);
2849 rt2800_rfcsr_write(rt2x00dev, 55, 0x43);
2852 power_bound = POWER_BOUND;
2855 rt2800_rfcsr_write(rt2x00dev, 10, 0x97);
2856 /* FIMXE: RF11 overwrite */
2857 rt2800_rfcsr_write(rt2x00dev, 11, 0x40);
2858 rt2800_rfcsr_write(rt2x00dev, 25, 0xBF);
2859 rt2800_rfcsr_write(rt2x00dev, 27, 0x42);
2860 rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
2861 rt2800_rfcsr_write(rt2x00dev, 37, 0x04);
2862 rt2800_rfcsr_write(rt2x00dev, 38, 0x85);
2863 rt2800_rfcsr_write(rt2x00dev, 40, 0x42);
2864 rt2800_rfcsr_write(rt2x00dev, 41, 0xBB);
2865 rt2800_rfcsr_write(rt2x00dev, 42, 0xD7);
2866 rt2800_rfcsr_write(rt2x00dev, 45, 0x41);
2867 rt2800_rfcsr_write(rt2x00dev, 48, 0x00);
2868 rt2800_rfcsr_write(rt2x00dev, 57, 0x77);
2869 rt2800_rfcsr_write(rt2x00dev, 60, 0x05);
2870 rt2800_rfcsr_write(rt2x00dev, 61, 0x01);
2872 /* TODO RF27 <- tssi */
2874 if (rf->channel >= 36 && rf->channel <= 64) {
2876 rt2800_rfcsr_write(rt2x00dev, 12, 0x2E);
2877 rt2800_rfcsr_write(rt2x00dev, 13, 0x22);
2878 rt2800_rfcsr_write(rt2x00dev, 22, 0x60);
2879 rt2800_rfcsr_write(rt2x00dev, 23, 0x7F);
2880 if (rf->channel <= 50)
2881 rt2800_rfcsr_write(rt2x00dev, 24, 0x09);
2882 else if (rf->channel >= 52)
2883 rt2800_rfcsr_write(rt2x00dev, 24, 0x07);
2884 rt2800_rfcsr_write(rt2x00dev, 39, 0x1C);
2885 rt2800_rfcsr_write(rt2x00dev, 43, 0x5B);
2886 rt2800_rfcsr_write(rt2x00dev, 44, 0X40);
2887 rt2800_rfcsr_write(rt2x00dev, 46, 0X00);
2888 rt2800_rfcsr_write(rt2x00dev, 51, 0xFE);
2889 rt2800_rfcsr_write(rt2x00dev, 52, 0x0C);
2890 rt2800_rfcsr_write(rt2x00dev, 54, 0xF8);
2891 if (rf->channel <= 50) {
2892 rt2800_rfcsr_write(rt2x00dev, 55, 0x06),
2893 rt2800_rfcsr_write(rt2x00dev, 56, 0xD3);
2894 } else if (rf->channel >= 52) {
2895 rt2800_rfcsr_write(rt2x00dev, 55, 0x04);
2896 rt2800_rfcsr_write(rt2x00dev, 56, 0xBB);
2899 rt2800_rfcsr_write(rt2x00dev, 58, 0x15);
2900 rt2800_rfcsr_write(rt2x00dev, 59, 0x7F);
2901 rt2800_rfcsr_write(rt2x00dev, 62, 0x15);
2903 } else if (rf->channel >= 100 && rf->channel <= 165) {
2905 rt2800_rfcsr_write(rt2x00dev, 12, 0x0E);
2906 rt2800_rfcsr_write(rt2x00dev, 13, 0x42);
2907 rt2800_rfcsr_write(rt2x00dev, 22, 0x40);
2908 if (rf->channel <= 153) {
2909 rt2800_rfcsr_write(rt2x00dev, 23, 0x3C);
2910 rt2800_rfcsr_write(rt2x00dev, 24, 0x06);
2911 } else if (rf->channel >= 155) {
2912 rt2800_rfcsr_write(rt2x00dev, 23, 0x38);
2913 rt2800_rfcsr_write(rt2x00dev, 24, 0x05);
2915 if (rf->channel <= 138) {
2916 rt2800_rfcsr_write(rt2x00dev, 39, 0x1A);
2917 rt2800_rfcsr_write(rt2x00dev, 43, 0x3B);
2918 rt2800_rfcsr_write(rt2x00dev, 44, 0x20);
2919 rt2800_rfcsr_write(rt2x00dev, 46, 0x18);
2920 } else if (rf->channel >= 140) {
2921 rt2800_rfcsr_write(rt2x00dev, 39, 0x18);
2922 rt2800_rfcsr_write(rt2x00dev, 43, 0x1B);
2923 rt2800_rfcsr_write(rt2x00dev, 44, 0x10);
2924 rt2800_rfcsr_write(rt2x00dev, 46, 0X08);
2926 if (rf->channel <= 124)
2927 rt2800_rfcsr_write(rt2x00dev, 51, 0xFC);
2928 else if (rf->channel >= 126)
2929 rt2800_rfcsr_write(rt2x00dev, 51, 0xEC);
2930 if (rf->channel <= 138)
2931 rt2800_rfcsr_write(rt2x00dev, 52, 0x06);
2932 else if (rf->channel >= 140)
2933 rt2800_rfcsr_write(rt2x00dev, 52, 0x06);
2934 rt2800_rfcsr_write(rt2x00dev, 54, 0xEB);
2935 if (rf->channel <= 138)
2936 rt2800_rfcsr_write(rt2x00dev, 55, 0x01);
2937 else if (rf->channel >= 140)
2938 rt2800_rfcsr_write(rt2x00dev, 55, 0x00);
2939 if (rf->channel <= 128)
2940 rt2800_rfcsr_write(rt2x00dev, 56, 0xBB);
2941 else if (rf->channel >= 130)
2942 rt2800_rfcsr_write(rt2x00dev, 56, 0xAB);
2943 if (rf->channel <= 116)
2944 rt2800_rfcsr_write(rt2x00dev, 58, 0x1D);
2945 else if (rf->channel >= 118)
2946 rt2800_rfcsr_write(rt2x00dev, 58, 0x15);
2947 if (rf->channel <= 138)
2948 rt2800_rfcsr_write(rt2x00dev, 59, 0x3F);
2949 else if (rf->channel >= 140)
2950 rt2800_rfcsr_write(rt2x00dev, 59, 0x7C);
2951 if (rf->channel <= 116)
2952 rt2800_rfcsr_write(rt2x00dev, 62, 0x1D);
2953 else if (rf->channel >= 118)
2954 rt2800_rfcsr_write(rt2x00dev, 62, 0x15);
2957 power_bound = POWER_BOUND_5G;
2961 rt2800_rfcsr_read(rt2x00dev, 49, &rfcsr);
2962 if (info->default_power1 > power_bound)
2963 rt2x00_set_field8(&rfcsr, RFCSR49_TX, power_bound);
2965 rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1);
2967 rt2x00_set_field8(&rfcsr, RFCSR49_EP, ep_reg);
2968 rt2800_rfcsr_write(rt2x00dev, 49, rfcsr);
2970 rt2800_rfcsr_read(rt2x00dev, 50, &rfcsr);
2971 if (info->default_power2 > power_bound)
2972 rt2x00_set_field8(&rfcsr, RFCSR50_TX, power_bound);
2974 rt2x00_set_field8(&rfcsr, RFCSR50_TX, info->default_power2);
2976 rt2x00_set_field8(&rfcsr, RFCSR50_EP, ep_reg);
2977 rt2800_rfcsr_write(rt2x00dev, 50, rfcsr);
2979 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
2980 rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
2981 rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1);
2983 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD,
2984 rt2x00dev->default_ant.tx_chain_num >= 1);
2985 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD,
2986 rt2x00dev->default_ant.tx_chain_num == 2);
2987 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0);
2989 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD,
2990 rt2x00dev->default_ant.rx_chain_num >= 1);
2991 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD,
2992 rt2x00dev->default_ant.rx_chain_num == 2);
2993 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0);
2995 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
2996 rt2800_rfcsr_write(rt2x00dev, 6, 0xe4);
2998 if (conf_is_ht40(conf))
2999 rt2800_rfcsr_write(rt2x00dev, 30, 0x16);
3001 rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
3004 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
3005 rt2800_rfcsr_write(rt2x00dev, 32, 0x80);
3008 /* TODO proper frequency adjustment */
3009 rt2800_freq_cal_mode1(rt2x00dev);
3011 /* TODO merge with others */
3012 rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr);
3013 rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
3014 rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
3017 rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
3018 rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
3019 rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
3021 rt2800_bbp_write(rt2x00dev, 79, (rf->channel <= 14) ? 0x1C : 0x18);
3022 rt2800_bbp_write(rt2x00dev, 80, (rf->channel <= 14) ? 0x0E : 0x08);
3023 rt2800_bbp_write(rt2x00dev, 81, (rf->channel <= 14) ? 0x3A : 0x38);
3024 rt2800_bbp_write(rt2x00dev, 82, (rf->channel <= 14) ? 0x62 : 0x92);
3026 /* GLRT band configuration */
3027 rt2800_bbp_write(rt2x00dev, 195, 128);
3028 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0xE0 : 0xF0);
3029 rt2800_bbp_write(rt2x00dev, 195, 129);
3030 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x1F : 0x1E);
3031 rt2800_bbp_write(rt2x00dev, 195, 130);
3032 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x38 : 0x28);
3033 rt2800_bbp_write(rt2x00dev, 195, 131);
3034 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x32 : 0x20);
3035 rt2800_bbp_write(rt2x00dev, 195, 133);
3036 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x28 : 0x7F);
3037 rt2800_bbp_write(rt2x00dev, 195, 124);
3038 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x19 : 0x7F);
3041 static void rt2800_bbp_write_with_rx_chain(struct rt2x00_dev *rt2x00dev,
3042 const unsigned int word,
3047 for (chain = 0; chain < rt2x00dev->default_ant.rx_chain_num; chain++) {
3048 rt2800_bbp_read(rt2x00dev, 27, ®);
3049 rt2x00_set_field8(®, BBP27_RX_CHAIN_SEL, chain);
3050 rt2800_bbp_write(rt2x00dev, 27, reg);
3052 rt2800_bbp_write(rt2x00dev, word, value);
3056 static void rt2800_iq_calibrate(struct rt2x00_dev *rt2x00dev, int channel)
3061 rt2800_bbp_write(rt2x00dev, 158, 0x2c);
3063 cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_GAIN_CAL_TX0_2G);
3064 else if (channel >= 36 && channel <= 64)
3065 cal = rt2x00_eeprom_byte(rt2x00dev,
3066 EEPROM_IQ_GAIN_CAL_TX0_CH36_TO_CH64_5G);
3067 else if (channel >= 100 && channel <= 138)
3068 cal = rt2x00_eeprom_byte(rt2x00dev,
3069 EEPROM_IQ_GAIN_CAL_TX0_CH100_TO_CH138_5G);
3070 else if (channel >= 140 && channel <= 165)
3071 cal = rt2x00_eeprom_byte(rt2x00dev,
3072 EEPROM_IQ_GAIN_CAL_TX0_CH140_TO_CH165_5G);
3075 rt2800_bbp_write(rt2x00dev, 159, cal);
3078 rt2800_bbp_write(rt2x00dev, 158, 0x2d);
3080 cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_PHASE_CAL_TX0_2G);
3081 else if (channel >= 36 && channel <= 64)
3082 cal = rt2x00_eeprom_byte(rt2x00dev,
3083 EEPROM_IQ_PHASE_CAL_TX0_CH36_TO_CH64_5G);
3084 else if (channel >= 100 && channel <= 138)
3085 cal = rt2x00_eeprom_byte(rt2x00dev,
3086 EEPROM_IQ_PHASE_CAL_TX0_CH100_TO_CH138_5G);
3087 else if (channel >= 140 && channel <= 165)
3088 cal = rt2x00_eeprom_byte(rt2x00dev,
3089 EEPROM_IQ_PHASE_CAL_TX0_CH140_TO_CH165_5G);
3092 rt2800_bbp_write(rt2x00dev, 159, cal);
3095 rt2800_bbp_write(rt2x00dev, 158, 0x4a);
3097 cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_GAIN_CAL_TX1_2G);
3098 else if (channel >= 36 && channel <= 64)
3099 cal = rt2x00_eeprom_byte(rt2x00dev,
3100 EEPROM_IQ_GAIN_CAL_TX1_CH36_TO_CH64_5G);
3101 else if (channel >= 100 && channel <= 138)
3102 cal = rt2x00_eeprom_byte(rt2x00dev,
3103 EEPROM_IQ_GAIN_CAL_TX1_CH100_TO_CH138_5G);
3104 else if (channel >= 140 && channel <= 165)
3105 cal = rt2x00_eeprom_byte(rt2x00dev,
3106 EEPROM_IQ_GAIN_CAL_TX1_CH140_TO_CH165_5G);
3109 rt2800_bbp_write(rt2x00dev, 159, cal);
3112 rt2800_bbp_write(rt2x00dev, 158, 0x4b);
3114 cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_PHASE_CAL_TX1_2G);
3115 else if (channel >= 36 && channel <= 64)
3116 cal = rt2x00_eeprom_byte(rt2x00dev,
3117 EEPROM_IQ_PHASE_CAL_TX1_CH36_TO_CH64_5G);
3118 else if (channel >= 100 && channel <= 138)
3119 cal = rt2x00_eeprom_byte(rt2x00dev,
3120 EEPROM_IQ_PHASE_CAL_TX1_CH100_TO_CH138_5G);
3121 else if (channel >= 140 && channel <= 165)
3122 cal = rt2x00_eeprom_byte(rt2x00dev,
3123 EEPROM_IQ_PHASE_CAL_TX1_CH140_TO_CH165_5G);
3126 rt2800_bbp_write(rt2x00dev, 159, cal);
3128 /* FIXME: possible RX0, RX1 callibration ? */
3130 /* RF IQ compensation control */
3131 rt2800_bbp_write(rt2x00dev, 158, 0x04);
3132 cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_RF_IQ_COMPENSATION_CONTROL);
3133 rt2800_bbp_write(rt2x00dev, 159, cal != 0xff ? cal : 0);
3135 /* RF IQ imbalance compensation control */
3136 rt2800_bbp_write(rt2x00dev, 158, 0x03);
3137 cal = rt2x00_eeprom_byte(rt2x00dev,
3138 EEPROM_RF_IQ_IMBALANCE_COMPENSATION_CONTROL);
3139 rt2800_bbp_write(rt2x00dev, 159, cal != 0xff ? cal : 0);
3142 static char rt2800_txpower_to_dev(struct rt2x00_dev *rt2x00dev,
3143 unsigned int channel,
3146 if (rt2x00_rt(rt2x00dev, RT3593))
3147 txpower = rt2x00_get_field8(txpower, EEPROM_TXPOWER_ALC);
3150 return clamp_t(char, txpower, MIN_G_TXPOWER, MAX_G_TXPOWER);
3152 if (rt2x00_rt(rt2x00dev, RT3593))
3153 return clamp_t(char, txpower, MIN_A_TXPOWER_3593,
3154 MAX_A_TXPOWER_3593);
3156 return clamp_t(char, txpower, MIN_A_TXPOWER, MAX_A_TXPOWER);
3159 static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
3160 struct ieee80211_conf *conf,
3161 struct rf_channel *rf,
3162 struct channel_info *info)
3165 unsigned int tx_pin;
3168 info->default_power1 = rt2800_txpower_to_dev(rt2x00dev, rf->channel,
3169 info->default_power1);
3170 info->default_power2 = rt2800_txpower_to_dev(rt2x00dev, rf->channel,
3171 info->default_power2);
3172 if (rt2x00dev->default_ant.tx_chain_num > 2)
3173 info->default_power3 =
3174 rt2800_txpower_to_dev(rt2x00dev, rf->channel,
3175 info->default_power3);
3177 switch (rt2x00dev->chip.rf) {
3183 rt2800_config_channel_rf3xxx(rt2x00dev, conf, rf, info);
3186 rt2800_config_channel_rf3052(rt2x00dev, conf, rf, info);
3189 rt2800_config_channel_rf3053(rt2x00dev, conf, rf, info);
3192 rt2800_config_channel_rf3290(rt2x00dev, conf, rf, info);
3195 rt2800_config_channel_rf3322(rt2x00dev, conf, rf, info);
3204 rt2800_config_channel_rf53xx(rt2x00dev, conf, rf, info);
3207 rt2800_config_channel_rf55xx(rt2x00dev, conf, rf, info);
3210 rt2800_config_channel_rf2xxx(rt2x00dev, conf, rf, info);
3213 if (rt2x00_rf(rt2x00dev, RF3070) ||
3214 rt2x00_rf(rt2x00dev, RF3290) ||
3215 rt2x00_rf(rt2x00dev, RF3322) ||
3216 rt2x00_rf(rt2x00dev, RF5360) ||
3217 rt2x00_rf(rt2x00dev, RF5362) ||
3218 rt2x00_rf(rt2x00dev, RF5370) ||
3219 rt2x00_rf(rt2x00dev, RF5372) ||
3220 rt2x00_rf(rt2x00dev, RF5390) ||
3221 rt2x00_rf(rt2x00dev, RF5392)) {
3222 rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
3223 rt2x00_set_field8(&rfcsr, RFCSR30_TX_H20M, 0);
3224 rt2x00_set_field8(&rfcsr, RFCSR30_RX_H20M, 0);
3225 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
3227 rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr);
3228 rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
3229 rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
3233 * Change BBP settings
3235 if (rt2x00_rt(rt2x00dev, RT3352)) {
3236 rt2800_bbp_write(rt2x00dev, 27, 0x0);
3237 rt2800_bbp_write(rt2x00dev, 66, 0x26 + rt2x00dev->lna_gain);
3238 rt2800_bbp_write(rt2x00dev, 27, 0x20);
3239 rt2800_bbp_write(rt2x00dev, 66, 0x26 + rt2x00dev->lna_gain);
3240 } else if (rt2x00_rt(rt2x00dev, RT3593)) {
3241 if (rf->channel > 14) {
3242 /* Disable CCK Packet detection on 5GHz */
3243 rt2800_bbp_write(rt2x00dev, 70, 0x00);
3245 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
3248 if (conf_is_ht40(conf))
3249 rt2800_bbp_write(rt2x00dev, 105, 0x04);
3251 rt2800_bbp_write(rt2x00dev, 105, 0x34);
3253 rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
3254 rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
3255 rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
3256 rt2800_bbp_write(rt2x00dev, 77, 0x98);
3258 rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
3259 rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
3260 rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
3261 rt2800_bbp_write(rt2x00dev, 86, 0);
3264 if (rf->channel <= 14) {
3265 if (!rt2x00_rt(rt2x00dev, RT5390) &&
3266 !rt2x00_rt(rt2x00dev, RT5392)) {
3267 if (rt2x00_has_cap_external_lna_bg(rt2x00dev)) {
3268 rt2800_bbp_write(rt2x00dev, 82, 0x62);
3269 rt2800_bbp_write(rt2x00dev, 75, 0x46);
3271 if (rt2x00_rt(rt2x00dev, RT3593))
3272 rt2800_bbp_write(rt2x00dev, 82, 0x62);
3274 rt2800_bbp_write(rt2x00dev, 82, 0x84);
3275 rt2800_bbp_write(rt2x00dev, 75, 0x50);
3277 if (rt2x00_rt(rt2x00dev, RT3593))
3278 rt2800_bbp_write(rt2x00dev, 83, 0x8a);
3282 if (rt2x00_rt(rt2x00dev, RT3572))
3283 rt2800_bbp_write(rt2x00dev, 82, 0x94);
3284 else if (rt2x00_rt(rt2x00dev, RT3593))
3285 rt2800_bbp_write(rt2x00dev, 82, 0x82);
3287 rt2800_bbp_write(rt2x00dev, 82, 0xf2);
3289 if (rt2x00_rt(rt2x00dev, RT3593))
3290 rt2800_bbp_write(rt2x00dev, 83, 0x9a);
3292 if (rt2x00_has_cap_external_lna_a(rt2x00dev))
3293 rt2800_bbp_write(rt2x00dev, 75, 0x46);
3295 rt2800_bbp_write(rt2x00dev, 75, 0x50);
3298 rt2800_register_read(rt2x00dev, TX_BAND_CFG, ®);
3299 rt2x00_set_field32(®, TX_BAND_CFG_HT40_MINUS, conf_is_ht40_minus(conf));
3300 rt2x00_set_field32(®, TX_BAND_CFG_A, rf->channel > 14);
3301 rt2x00_set_field32(®, TX_BAND_CFG_BG, rf->channel <= 14);
3302 rt2800_register_write(rt2x00dev, TX_BAND_CFG, reg);
3304 if (rt2x00_rt(rt2x00dev, RT3572))
3305 rt2800_rfcsr_write(rt2x00dev, 8, 0);
3309 switch (rt2x00dev->default_ant.tx_chain_num) {
3311 /* Turn on tertiary PAs */
3312 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A2_EN,
3314 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G2_EN,
3318 /* Turn on secondary PAs */
3319 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN,
3321 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN,
3325 /* Turn on primary PAs */
3326 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN,
3328 if (rt2x00_has_cap_bt_coexist(rt2x00dev))
3329 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, 1);
3331 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN,
3336 switch (rt2x00dev->default_ant.rx_chain_num) {
3338 /* Turn on tertiary LNAs */
3339 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A2_EN, 1);
3340 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G2_EN, 1);
3343 /* Turn on secondary LNAs */
3344 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1);
3345 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1);
3348 /* Turn on primary LNAs */
3349 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN, 1);
3350 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN, 1);
3354 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1);
3355 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_TRSW_EN, 1);
3357 rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
3359 if (rt2x00_rt(rt2x00dev, RT3572)) {
3360 rt2800_rfcsr_write(rt2x00dev, 8, 0x80);
3363 if (rf->channel <= 14)
3364 reg = 0x1c + (2 * rt2x00dev->lna_gain);
3366 reg = 0x22 + ((rt2x00dev->lna_gain * 5) / 3);
3368 rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, reg);
3371 if (rt2x00_rt(rt2x00dev, RT3593)) {
3372 rt2800_register_read(rt2x00dev, GPIO_CTRL, ®);
3374 /* Band selection */
3375 if (rt2x00_is_usb(rt2x00dev) ||
3376 rt2x00_is_pcie(rt2x00dev)) {
3377 /* GPIO #8 controls all paths */
3378 rt2x00_set_field32(®, GPIO_CTRL_DIR8, 0);
3379 if (rf->channel <= 14)
3380 rt2x00_set_field32(®, GPIO_CTRL_VAL8, 1);
3382 rt2x00_set_field32(®, GPIO_CTRL_VAL8, 0);
3385 /* LNA PE control. */
3386 if (rt2x00_is_usb(rt2x00dev)) {
3387 /* GPIO #4 controls PE0 and PE1,
3388 * GPIO #7 controls PE2
3390 rt2x00_set_field32(®, GPIO_CTRL_DIR4, 0);
3391 rt2x00_set_field32(®, GPIO_CTRL_DIR7, 0);
3393 rt2x00_set_field32(®, GPIO_CTRL_VAL4, 1);
3394 rt2x00_set_field32(®, GPIO_CTRL_VAL7, 1);
3395 } else if (rt2x00_is_pcie(rt2x00dev)) {
3396 /* GPIO #4 controls PE0, PE1 and PE2 */
3397 rt2x00_set_field32(®, GPIO_CTRL_DIR4, 0);
3398 rt2x00_set_field32(®, GPIO_CTRL_VAL4, 1);
3401 rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
3404 if (rf->channel <= 14)
3405 reg = 0x1c + 2 * rt2x00dev->lna_gain;
3407 reg = 0x22 + ((rt2x00dev->lna_gain * 5) / 3);
3409 rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, reg);
3411 usleep_range(1000, 1500);
3414 if (rt2x00_rt(rt2x00dev, RT5592)) {
3415 rt2800_bbp_write(rt2x00dev, 195, 141);
3416 rt2800_bbp_write(rt2x00dev, 196, conf_is_ht40(conf) ? 0x10 : 0x1a);
3419 reg = (rf->channel <= 14 ? 0x1c : 0x24) + 2 * rt2x00dev->lna_gain;
3420 rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, reg);
3422 rt2800_iq_calibrate(rt2x00dev, rf->channel);
3425 rt2800_bbp_read(rt2x00dev, 4, &bbp);
3426 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * conf_is_ht40(conf));
3427 rt2800_bbp_write(rt2x00dev, 4, bbp);
3429 rt2800_bbp_read(rt2x00dev, 3, &bbp);
3430 rt2x00_set_field8(&bbp, BBP3_HT40_MINUS, conf_is_ht40_minus(conf));
3431 rt2800_bbp_write(rt2x00dev, 3, bbp);
3433 if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) {
3434 if (conf_is_ht40(conf)) {
3435 rt2800_bbp_write(rt2x00dev, 69, 0x1a);
3436 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
3437 rt2800_bbp_write(rt2x00dev, 73, 0x16);
3439 rt2800_bbp_write(rt2x00dev, 69, 0x16);
3440 rt2800_bbp_write(rt2x00dev, 70, 0x08);
3441 rt2800_bbp_write(rt2x00dev, 73, 0x11);
3448 * Clear channel statistic counters
3450 rt2800_register_read(rt2x00dev, CH_IDLE_STA, ®);
3451 rt2800_register_read(rt2x00dev, CH_BUSY_STA, ®);
3452 rt2800_register_read(rt2x00dev, CH_BUSY_STA_SEC, ®);
3457 if (rt2x00_rt(rt2x00dev, RT3352)) {
3458 rt2800_bbp_read(rt2x00dev, 49, &bbp);
3459 rt2x00_set_field8(&bbp, BBP49_UPDATE_FLAG, 0);
3460 rt2800_bbp_write(rt2x00dev, 49, bbp);
3464 static int rt2800_get_gain_calibration_delta(struct rt2x00_dev *rt2x00dev)
3473 * First check if temperature compensation is supported.
3475 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
3476 if (!rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_EXTERNAL_TX_ALC))
3480 * Read TSSI boundaries for temperature compensation from
3483 * Array idx 0 1 2 3 4 5 6 7 8
3484 * Matching Delta value -4 -3 -2 -1 0 +1 +2 +3 +4
3485 * Example TSSI bounds 0xF0 0xD0 0xB5 0xA0 0x88 0x45 0x25 0x15 0x00
3487 if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
3488 rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG1, &eeprom);
3489 tssi_bounds[0] = rt2x00_get_field16(eeprom,
3490 EEPROM_TSSI_BOUND_BG1_MINUS4);
3491 tssi_bounds[1] = rt2x00_get_field16(eeprom,
3492 EEPROM_TSSI_BOUND_BG1_MINUS3);
3494 rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG2, &eeprom);
3495 tssi_bounds[2] = rt2x00_get_field16(eeprom,
3496 EEPROM_TSSI_BOUND_BG2_MINUS2);
3497 tssi_bounds[3] = rt2x00_get_field16(eeprom,
3498 EEPROM_TSSI_BOUND_BG2_MINUS1);
3500 rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG3, &eeprom);
3501 tssi_bounds[4] = rt2x00_get_field16(eeprom,
3502 EEPROM_TSSI_BOUND_BG3_REF);
3503 tssi_bounds[5] = rt2x00_get_field16(eeprom,
3504 EEPROM_TSSI_BOUND_BG3_PLUS1);
3506 rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG4, &eeprom);
3507 tssi_bounds[6] = rt2x00_get_field16(eeprom,
3508 EEPROM_TSSI_BOUND_BG4_PLUS2);
3509 tssi_bounds[7] = rt2x00_get_field16(eeprom,
3510 EEPROM_TSSI_BOUND_BG4_PLUS3);
3512 rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG5, &eeprom);
3513 tssi_bounds[8] = rt2x00_get_field16(eeprom,
3514 EEPROM_TSSI_BOUND_BG5_PLUS4);
3516 step = rt2x00_get_field16(eeprom,
3517 EEPROM_TSSI_BOUND_BG5_AGC_STEP);
3519 rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A1, &eeprom);
3520 tssi_bounds[0] = rt2x00_get_field16(eeprom,
3521 EEPROM_TSSI_BOUND_A1_MINUS4);
3522 tssi_bounds[1] = rt2x00_get_field16(eeprom,
3523 EEPROM_TSSI_BOUND_A1_MINUS3);
3525 rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A2, &eeprom);
3526 tssi_bounds[2] = rt2x00_get_field16(eeprom,
3527 EEPROM_TSSI_BOUND_A2_MINUS2);
3528 tssi_bounds[3] = rt2x00_get_field16(eeprom,
3529 EEPROM_TSSI_BOUND_A2_MINUS1);
3531 rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A3, &eeprom);
3532 tssi_bounds[4] = rt2x00_get_field16(eeprom,
3533 EEPROM_TSSI_BOUND_A3_REF);
3534 tssi_bounds[5] = rt2x00_get_field16(eeprom,
3535 EEPROM_TSSI_BOUND_A3_PLUS1);
3537 rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A4, &eeprom);
3538 tssi_bounds[6] = rt2x00_get_field16(eeprom,
3539 EEPROM_TSSI_BOUND_A4_PLUS2);
3540 tssi_bounds[7] = rt2x00_get_field16(eeprom,
3541 EEPROM_TSSI_BOUND_A4_PLUS3);
3543 rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A5, &eeprom);
3544 tssi_bounds[8] = rt2x00_get_field16(eeprom,
3545 EEPROM_TSSI_BOUND_A5_PLUS4);
3547 step = rt2x00_get_field16(eeprom,
3548 EEPROM_TSSI_BOUND_A5_AGC_STEP);
3552 * Check if temperature compensation is supported.
3554 if (tssi_bounds[4] == 0xff || step == 0xff)
3558 * Read current TSSI (BBP 49).
3560 rt2800_bbp_read(rt2x00dev, 49, ¤t_tssi);
3563 * Compare TSSI value (BBP49) with the compensation boundaries
3564 * from the EEPROM and increase or decrease tx power.
3566 for (i = 0; i <= 3; i++) {
3567 if (current_tssi > tssi_bounds[i])
3572 for (i = 8; i >= 5; i--) {
3573 if (current_tssi < tssi_bounds[i])
3578 return (i - 4) * step;
3581 static int rt2800_get_txpower_bw_comp(struct rt2x00_dev *rt2x00dev,
3582 enum nl80211_band band)
3589 rt2800_eeprom_read(rt2x00dev, EEPROM_TXPOWER_DELTA, &eeprom);
3592 * HT40 compensation not required.
3594 if (eeprom == 0xffff ||
3595 !test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
3598 if (band == NL80211_BAND_2GHZ) {
3599 comp_en = rt2x00_get_field16(eeprom,
3600 EEPROM_TXPOWER_DELTA_ENABLE_2G);
3602 comp_type = rt2x00_get_field16(eeprom,
3603 EEPROM_TXPOWER_DELTA_TYPE_2G);
3604 comp_value = rt2x00_get_field16(eeprom,
3605 EEPROM_TXPOWER_DELTA_VALUE_2G);
3607 comp_value = -comp_value;
3610 comp_en = rt2x00_get_field16(eeprom,
3611 EEPROM_TXPOWER_DELTA_ENABLE_5G);
3613 comp_type = rt2x00_get_field16(eeprom,
3614 EEPROM_TXPOWER_DELTA_TYPE_5G);
3615 comp_value = rt2x00_get_field16(eeprom,
3616 EEPROM_TXPOWER_DELTA_VALUE_5G);
3618 comp_value = -comp_value;
3625 static int rt2800_get_txpower_reg_delta(struct rt2x00_dev *rt2x00dev,
3626 int power_level, int max_power)
3630 if (rt2x00_has_cap_power_limit(rt2x00dev))
3634 * XXX: We don't know the maximum transmit power of our hardware since
3635 * the EEPROM doesn't expose it. We only know that we are calibrated
3638 * Hence, we assume the regulatory limit that cfg80211 calulated for
3639 * the current channel is our maximum and if we are requested to lower
3640 * the value we just reduce our tx power accordingly.
3642 delta = power_level - max_power;
3643 return min(delta, 0);
3646 static u8 rt2800_compensate_txpower(struct rt2x00_dev *rt2x00dev, int is_rate_b,
3647 enum nl80211_band band, int power_level,
3648 u8 txpower, int delta)
3653 u8 eirp_txpower_criterion;
3656 if (rt2x00_rt(rt2x00dev, RT3593))
3657 return min_t(u8, txpower, 0xc);
3659 if (rt2x00_has_cap_power_limit(rt2x00dev)) {
3661 * Check if eirp txpower exceed txpower_limit.
3662 * We use OFDM 6M as criterion and its eirp txpower
3663 * is stored at EEPROM_EIRP_MAX_TX_POWER.
3664 * .11b data rate need add additional 4dbm
3665 * when calculating eirp txpower.
3667 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
3669 criterion = rt2x00_get_field16(eeprom,
3670 EEPROM_TXPOWER_BYRATE_RATE0);
3672 rt2800_eeprom_read(rt2x00dev, EEPROM_EIRP_MAX_TX_POWER,
3675 if (band == NL80211_BAND_2GHZ)
3676 eirp_txpower_criterion = rt2x00_get_field16(eeprom,
3677 EEPROM_EIRP_MAX_TX_POWER_2GHZ);
3679 eirp_txpower_criterion = rt2x00_get_field16(eeprom,
3680 EEPROM_EIRP_MAX_TX_POWER_5GHZ);
3682 eirp_txpower = eirp_txpower_criterion + (txpower - criterion) +
3683 (is_rate_b ? 4 : 0) + delta;
3685 reg_limit = (eirp_txpower > power_level) ?
3686 (eirp_txpower - power_level) : 0;
3690 txpower = max(0, txpower + delta - reg_limit);
3691 return min_t(u8, txpower, 0xc);
3706 TX_PWR_CFG_0_EXT_IDX,
3707 TX_PWR_CFG_1_EXT_IDX,
3708 TX_PWR_CFG_2_EXT_IDX,
3709 TX_PWR_CFG_3_EXT_IDX,
3710 TX_PWR_CFG_4_EXT_IDX,
3711 TX_PWR_CFG_IDX_COUNT,
3714 static void rt2800_config_txpower_rt3593(struct rt2x00_dev *rt2x00dev,
3715 struct ieee80211_channel *chan,
3720 u32 regs[TX_PWR_CFG_IDX_COUNT];
3721 unsigned int offset;
3722 enum nl80211_band band = chan->band;
3726 memset(regs, '\0', sizeof(regs));
3728 /* TODO: adapt TX power reduction from the rt28xx code */
3730 /* calculate temperature compensation delta */
3731 delta = rt2800_get_gain_calibration_delta(rt2x00dev);
3733 if (band == NL80211_BAND_5GHZ)
3738 if (test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
3741 /* read the next four txpower values */
3742 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
3746 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
3747 txpower = rt2800_compensate_txpower(rt2x00dev, 1, band, power_level,
3749 rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX],
3750 TX_PWR_CFG_0_CCK1_CH0, txpower);
3751 rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX],
3752 TX_PWR_CFG_0_CCK1_CH1, txpower);
3753 rt2x00_set_field32(®s[TX_PWR_CFG_0_EXT_IDX],
3754 TX_PWR_CFG_0_EXT_CCK1_CH2, txpower);
3756 /* CCK 5.5MBS,11MBS */
3757 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1);
3758 txpower = rt2800_compensate_txpower(rt2x00dev, 1, band, power_level,
3760 rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX],
3761 TX_PWR_CFG_0_CCK5_CH0, txpower);
3762 rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX],
3763 TX_PWR_CFG_0_CCK5_CH1, txpower);
3764 rt2x00_set_field32(®s[TX_PWR_CFG_0_EXT_IDX],
3765 TX_PWR_CFG_0_EXT_CCK5_CH2, txpower);
3767 /* OFDM 6MBS,9MBS */
3768 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2);
3769 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3771 rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX],
3772 TX_PWR_CFG_0_OFDM6_CH0, txpower);
3773 rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX],
3774 TX_PWR_CFG_0_OFDM6_CH1, txpower);
3775 rt2x00_set_field32(®s[TX_PWR_CFG_0_EXT_IDX],
3776 TX_PWR_CFG_0_EXT_OFDM6_CH2, txpower);
3778 /* OFDM 12MBS,18MBS */
3779 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3);
3780 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3782 rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX],
3783 TX_PWR_CFG_0_OFDM12_CH0, txpower);
3784 rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX],
3785 TX_PWR_CFG_0_OFDM12_CH1, txpower);
3786 rt2x00_set_field32(®s[TX_PWR_CFG_0_EXT_IDX],
3787 TX_PWR_CFG_0_EXT_OFDM12_CH2, txpower);
3789 /* read the next four txpower values */
3790 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
3791 offset + 1, &eeprom);
3793 /* OFDM 24MBS,36MBS */
3794 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
3795 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3797 rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX],
3798 TX_PWR_CFG_1_OFDM24_CH0, txpower);
3799 rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX],
3800 TX_PWR_CFG_1_OFDM24_CH1, txpower);
3801 rt2x00_set_field32(®s[TX_PWR_CFG_1_EXT_IDX],
3802 TX_PWR_CFG_1_EXT_OFDM24_CH2, txpower);
3805 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1);
3806 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3808 rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX],
3809 TX_PWR_CFG_1_OFDM48_CH0, txpower);
3810 rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX],
3811 TX_PWR_CFG_1_OFDM48_CH1, txpower);
3812 rt2x00_set_field32(®s[TX_PWR_CFG_1_EXT_IDX],
3813 TX_PWR_CFG_1_EXT_OFDM48_CH2, txpower);
3816 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2);
3817 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3819 rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX],
3820 TX_PWR_CFG_7_OFDM54_CH0, txpower);
3821 rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX],
3822 TX_PWR_CFG_7_OFDM54_CH1, txpower);
3823 rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX],
3824 TX_PWR_CFG_7_OFDM54_CH2, txpower);
3826 /* read the next four txpower values */
3827 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
3828 offset + 2, &eeprom);
3831 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
3832 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3834 rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX],
3835 TX_PWR_CFG_1_MCS0_CH0, txpower);
3836 rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX],
3837 TX_PWR_CFG_1_MCS0_CH1, txpower);
3838 rt2x00_set_field32(®s[TX_PWR_CFG_1_EXT_IDX],
3839 TX_PWR_CFG_1_EXT_MCS0_CH2, txpower);
3842 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1);
3843 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3845 rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX],
3846 TX_PWR_CFG_1_MCS2_CH0, txpower);
3847 rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX],
3848 TX_PWR_CFG_1_MCS2_CH1, txpower);
3849 rt2x00_set_field32(®s[TX_PWR_CFG_1_EXT_IDX],
3850 TX_PWR_CFG_1_EXT_MCS2_CH2, txpower);
3853 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2);
3854 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3856 rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX],
3857 TX_PWR_CFG_2_MCS4_CH0, txpower);
3858 rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX],
3859 TX_PWR_CFG_2_MCS4_CH1, txpower);
3860 rt2x00_set_field32(®s[TX_PWR_CFG_2_EXT_IDX],
3861 TX_PWR_CFG_2_EXT_MCS4_CH2, txpower);
3864 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3);
3865 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3867 rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX],
3868 TX_PWR_CFG_2_MCS6_CH0, txpower);
3869 rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX],
3870 TX_PWR_CFG_2_MCS6_CH1, txpower);
3871 rt2x00_set_field32(®s[TX_PWR_CFG_2_EXT_IDX],
3872 TX_PWR_CFG_2_EXT_MCS6_CH2, txpower);
3874 /* read the next four txpower values */
3875 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
3876 offset + 3, &eeprom);
3879 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
3880 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3882 rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX],
3883 TX_PWR_CFG_7_MCS7_CH0, txpower);
3884 rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX],
3885 TX_PWR_CFG_7_MCS7_CH1, txpower);
3886 rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX],
3887 TX_PWR_CFG_7_MCS7_CH2, txpower);
3890 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1);
3891 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3893 rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX],
3894 TX_PWR_CFG_2_MCS8_CH0, txpower);
3895 rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX],
3896 TX_PWR_CFG_2_MCS8_CH1, txpower);
3897 rt2x00_set_field32(®s[TX_PWR_CFG_2_EXT_IDX],
3898 TX_PWR_CFG_2_EXT_MCS8_CH2, txpower);
3901 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2);
3902 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3904 rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX],
3905 TX_PWR_CFG_2_MCS10_CH0, txpower);
3906 rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX],
3907 TX_PWR_CFG_2_MCS10_CH1, txpower);
3908 rt2x00_set_field32(®s[TX_PWR_CFG_2_EXT_IDX],
3909 TX_PWR_CFG_2_EXT_MCS10_CH2, txpower);
3912 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3);
3913 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3915 rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX],
3916 TX_PWR_CFG_3_MCS12_CH0, txpower);
3917 rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX],
3918 TX_PWR_CFG_3_MCS12_CH1, txpower);
3919 rt2x00_set_field32(®s[TX_PWR_CFG_3_EXT_IDX],
3920 TX_PWR_CFG_3_EXT_MCS12_CH2, txpower);
3922 /* read the next four txpower values */
3923 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
3924 offset + 4, &eeprom);
3927 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
3928 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3930 rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX],
3931 TX_PWR_CFG_3_MCS14_CH0, txpower);
3932 rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX],
3933 TX_PWR_CFG_3_MCS14_CH1, txpower);
3934 rt2x00_set_field32(®s[TX_PWR_CFG_3_EXT_IDX],
3935 TX_PWR_CFG_3_EXT_MCS14_CH2, txpower);
3938 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1);
3939 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3941 rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX],
3942 TX_PWR_CFG_8_MCS15_CH0, txpower);
3943 rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX],
3944 TX_PWR_CFG_8_MCS15_CH1, txpower);
3945 rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX],
3946 TX_PWR_CFG_8_MCS15_CH2, txpower);
3949 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2);
3950 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3952 rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX],
3953 TX_PWR_CFG_5_MCS16_CH0, txpower);
3954 rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX],
3955 TX_PWR_CFG_5_MCS16_CH1, txpower);
3956 rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX],
3957 TX_PWR_CFG_5_MCS16_CH2, txpower);
3960 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3);
3961 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3963 rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX],
3964 TX_PWR_CFG_5_MCS18_CH0, txpower);
3965 rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX],
3966 TX_PWR_CFG_5_MCS18_CH1, txpower);
3967 rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX],
3968 TX_PWR_CFG_5_MCS18_CH2, txpower);
3970 /* read the next four txpower values */
3971 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
3972 offset + 5, &eeprom);
3975 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
3976 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3978 rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX],
3979 TX_PWR_CFG_6_MCS20_CH0, txpower);
3980 rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX],
3981 TX_PWR_CFG_6_MCS20_CH1, txpower);
3982 rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX],
3983 TX_PWR_CFG_6_MCS20_CH2, txpower);
3986 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1);
3987 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
3989 rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX],
3990 TX_PWR_CFG_6_MCS22_CH0, txpower);
3991 rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX],
3992 TX_PWR_CFG_6_MCS22_CH1, txpower);
3993 rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX],
3994 TX_PWR_CFG_6_MCS22_CH2, txpower);
3997 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2);
3998 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4000 rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX],
4001 TX_PWR_CFG_8_MCS23_CH0, txpower);
4002 rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX],
4003 TX_PWR_CFG_8_MCS23_CH1, txpower);
4004 rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX],
4005 TX_PWR_CFG_8_MCS23_CH2, txpower);
4007 /* read the next four txpower values */
4008 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
4009 offset + 6, &eeprom);
4012 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
4013 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4015 rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX],
4016 TX_PWR_CFG_3_STBC0_CH0, txpower);
4017 rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX],
4018 TX_PWR_CFG_3_STBC0_CH1, txpower);
4019 rt2x00_set_field32(®s[TX_PWR_CFG_3_EXT_IDX],
4020 TX_PWR_CFG_3_EXT_STBC0_CH2, txpower);
4023 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1);
4024 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4026 rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX],
4027 TX_PWR_CFG_3_STBC2_CH0, txpower);
4028 rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX],
4029 TX_PWR_CFG_3_STBC2_CH1, txpower);
4030 rt2x00_set_field32(®s[TX_PWR_CFG_3_EXT_IDX],
4031 TX_PWR_CFG_3_EXT_STBC2_CH2, txpower);
4034 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2);
4035 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4037 rt2x00_set_field32(®s[TX_PWR_CFG_4_IDX], TX_PWR_CFG_RATE0, txpower);
4038 rt2x00_set_field32(®s[TX_PWR_CFG_4_IDX], TX_PWR_CFG_RATE1, txpower);
4039 rt2x00_set_field32(®s[TX_PWR_CFG_4_EXT_IDX], TX_PWR_CFG_RATE0,
4043 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3);
4044 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4046 rt2x00_set_field32(®s[TX_PWR_CFG_4_IDX], TX_PWR_CFG_RATE2, txpower);
4047 rt2x00_set_field32(®s[TX_PWR_CFG_4_IDX], TX_PWR_CFG_RATE3, txpower);
4048 rt2x00_set_field32(®s[TX_PWR_CFG_4_EXT_IDX], TX_PWR_CFG_RATE2,
4051 /* read the next four txpower values */
4052 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
4053 offset + 7, &eeprom);
4056 txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0);
4057 txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level,
4059 rt2x00_set_field32(®s[TX_PWR_CFG_9_IDX],
4060 TX_PWR_CFG_9_STBC7_CH0, txpower);
4061 rt2x00_set_field32(®s[TX_PWR_CFG_9_IDX],
4062 TX_PWR_CFG_9_STBC7_CH1, txpower);
4063 rt2x00_set_field32(®s[TX_PWR_CFG_9_IDX],
4064 TX_PWR_CFG_9_STBC7_CH2, txpower);
4066 rt2800_register_write(rt2x00dev, TX_PWR_CFG_0, regs[TX_PWR_CFG_0_IDX]);
4067 rt2800_register_write(rt2x00dev, TX_PWR_CFG_1, regs[TX_PWR_CFG_1_IDX]);
4068 rt2800_register_write(rt2x00dev, TX_PWR_CFG_2, regs[TX_PWR_CFG_2_IDX]);
4069 rt2800_register_write(rt2x00dev, TX_PWR_CFG_3, regs[TX_PWR_CFG_3_IDX]);
4070 rt2800_register_write(rt2x00dev, TX_PWR_CFG_4, regs[TX_PWR_CFG_4_IDX]);
4071 rt2800_register_write(rt2x00dev, TX_PWR_CFG_5, regs[TX_PWR_CFG_5_IDX]);
4072 rt2800_register_write(rt2x00dev, TX_PWR_CFG_6, regs[TX_PWR_CFG_6_IDX]);
4073 rt2800_register_write(rt2x00dev, TX_PWR_CFG_7, regs[TX_PWR_CFG_7_IDX]);
4074 rt2800_register_write(rt2x00dev, TX_PWR_CFG_8, regs[TX_PWR_CFG_8_IDX]);
4075 rt2800_register_write(rt2x00dev, TX_PWR_CFG_9, regs[TX_PWR_CFG_9_IDX]);
4077 rt2800_register_write(rt2x00dev, TX_PWR_CFG_0_EXT,
4078 regs[TX_PWR_CFG_0_EXT_IDX]);
4079 rt2800_register_write(rt2x00dev, TX_PWR_CFG_1_EXT,
4080 regs[TX_PWR_CFG_1_EXT_IDX]);
4081 rt2800_register_write(rt2x00dev, TX_PWR_CFG_2_EXT,
4082 regs[TX_PWR_CFG_2_EXT_IDX]);
4083 rt2800_register_write(rt2x00dev, TX_PWR_CFG_3_EXT,
4084 regs[TX_PWR_CFG_3_EXT_IDX]);
4085 rt2800_register_write(rt2x00dev, TX_PWR_CFG_4_EXT,
4086 regs[TX_PWR_CFG_4_EXT_IDX]);
4088 for (i = 0; i < TX_PWR_CFG_IDX_COUNT; i++)
4089 rt2x00_dbg(rt2x00dev,
4090 "band:%cGHz, BW:%c0MHz, TX_PWR_CFG_%d%s = %08lx\n",
4091 (band == NL80211_BAND_5GHZ) ? '5' : '2',
4092 (test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags)) ?
4094 (i > TX_PWR_CFG_9_IDX) ?
4095 (i - TX_PWR_CFG_9_IDX - 1) : i,
4096 (i > TX_PWR_CFG_9_IDX) ? "_EXT" : "",
4097 (unsigned long) regs[i]);
4101 * We configure transmit power using MAC TX_PWR_CFG_{0,...,N} registers and
4102 * BBP R1 register. TX_PWR_CFG_X allow to configure per rate TX power values,
4103 * 4 bits for each rate (tune from 0 to 15 dBm). BBP_R1 controls transmit power
4104 * for all rates, but allow to set only 4 discrete values: -12, -6, 0 and 6 dBm.
4105 * Reference per rate transmit power values are located in the EEPROM at
4106 * EEPROM_TXPOWER_BYRATE offset. We adjust them and BBP R1 settings according to
4107 * current conditions (i.e. band, bandwidth, temperature, user settings).
4109 static void rt2800_config_txpower_rt28xx(struct rt2x00_dev *rt2x00dev,
4110 struct ieee80211_channel *chan,
4116 int i, is_rate_b, delta, power_ctrl;
4117 enum nl80211_band band = chan->band;
4120 * Calculate HT40 compensation. For 40MHz we need to add or subtract
4121 * value read from EEPROM (different for 2GHz and for 5GHz).
4123 delta = rt2800_get_txpower_bw_comp(rt2x00dev, band);
4126 * Calculate temperature compensation. Depends on measurement of current
4127 * TSSI (Transmitter Signal Strength Indication) we know TX power (due
4128 * to temperature or maybe other factors) is smaller or bigger than
4129 * expected. We adjust it, based on TSSI reference and boundaries values
4130 * provided in EEPROM.
4132 switch (rt2x00dev->chip.rt) {
4140 delta += rt2800_get_gain_calibration_delta(rt2x00dev);
4143 /* TODO: temperature compensation code for other chips. */
4148 * Decrease power according to user settings, on devices with unknown
4149 * maximum tx power. For other devices we take user power_level into
4150 * consideration on rt2800_compensate_txpower().
4152 delta += rt2800_get_txpower_reg_delta(rt2x00dev, power_level,
4156 * BBP_R1 controls TX power for all rates, it allow to set the following
4157 * gains -12, -6, 0, +6 dBm by setting values 2, 1, 0, 3 respectively.
4159 * TODO: we do not use +6 dBm option to do not increase power beyond
4160 * regulatory limit, however this could be utilized for devices with
4161 * CAPABILITY_POWER_LIMIT.
4166 } else if (delta <= -6) {
4172 rt2800_bbp_read(rt2x00dev, 1, &r1);
4173 rt2x00_set_field8(&r1, BBP1_TX_POWER_CTRL, power_ctrl);
4174 rt2800_bbp_write(rt2x00dev, 1, r1);
4176 offset = TX_PWR_CFG_0;
4178 for (i = 0; i < EEPROM_TXPOWER_BYRATE_SIZE; i += 2) {
4179 /* just to be safe */
4180 if (offset > TX_PWR_CFG_4)
4183 rt2800_register_read(rt2x00dev, offset, ®);
4185 /* read the next four txpower values */
4186 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
4189 is_rate_b = i ? 0 : 1;
4191 * TX_PWR_CFG_0: 1MBS, TX_PWR_CFG_1: 24MBS,
4192 * TX_PWR_CFG_2: MCS4, TX_PWR_CFG_3: MCS12,
4193 * TX_PWR_CFG_4: unknown
4195 txpower = rt2x00_get_field16(eeprom,
4196 EEPROM_TXPOWER_BYRATE_RATE0);
4197 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4198 power_level, txpower, delta);
4199 rt2x00_set_field32(®, TX_PWR_CFG_RATE0, txpower);
4202 * TX_PWR_CFG_0: 2MBS, TX_PWR_CFG_1: 36MBS,
4203 * TX_PWR_CFG_2: MCS5, TX_PWR_CFG_3: MCS13,
4204 * TX_PWR_CFG_4: unknown
4206 txpower = rt2x00_get_field16(eeprom,
4207 EEPROM_TXPOWER_BYRATE_RATE1);
4208 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4209 power_level, txpower, delta);
4210 rt2x00_set_field32(®, TX_PWR_CFG_RATE1, txpower);
4213 * TX_PWR_CFG_0: 5.5MBS, TX_PWR_CFG_1: 48MBS,
4214 * TX_PWR_CFG_2: MCS6, TX_PWR_CFG_3: MCS14,
4215 * TX_PWR_CFG_4: unknown
4217 txpower = rt2x00_get_field16(eeprom,
4218 EEPROM_TXPOWER_BYRATE_RATE2);
4219 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4220 power_level, txpower, delta);
4221 rt2x00_set_field32(®, TX_PWR_CFG_RATE2, txpower);
4224 * TX_PWR_CFG_0: 11MBS, TX_PWR_CFG_1: 54MBS,
4225 * TX_PWR_CFG_2: MCS7, TX_PWR_CFG_3: MCS15,
4226 * TX_PWR_CFG_4: unknown
4228 txpower = rt2x00_get_field16(eeprom,
4229 EEPROM_TXPOWER_BYRATE_RATE3);
4230 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4231 power_level, txpower, delta);
4232 rt2x00_set_field32(®, TX_PWR_CFG_RATE3, txpower);
4234 /* read the next four txpower values */
4235 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE,
4240 * TX_PWR_CFG_0: 6MBS, TX_PWR_CFG_1: MCS0,
4241 * TX_PWR_CFG_2: MCS8, TX_PWR_CFG_3: unknown,
4242 * TX_PWR_CFG_4: unknown
4244 txpower = rt2x00_get_field16(eeprom,
4245 EEPROM_TXPOWER_BYRATE_RATE0);
4246 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4247 power_level, txpower, delta);
4248 rt2x00_set_field32(®, TX_PWR_CFG_RATE4, txpower);
4251 * TX_PWR_CFG_0: 9MBS, TX_PWR_CFG_1: MCS1,
4252 * TX_PWR_CFG_2: MCS9, TX_PWR_CFG_3: unknown,
4253 * TX_PWR_CFG_4: unknown
4255 txpower = rt2x00_get_field16(eeprom,
4256 EEPROM_TXPOWER_BYRATE_RATE1);
4257 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4258 power_level, txpower, delta);
4259 rt2x00_set_field32(®, TX_PWR_CFG_RATE5, txpower);
4262 * TX_PWR_CFG_0: 12MBS, TX_PWR_CFG_1: MCS2,
4263 * TX_PWR_CFG_2: MCS10, TX_PWR_CFG_3: unknown,
4264 * TX_PWR_CFG_4: unknown
4266 txpower = rt2x00_get_field16(eeprom,
4267 EEPROM_TXPOWER_BYRATE_RATE2);
4268 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4269 power_level, txpower, delta);
4270 rt2x00_set_field32(®, TX_PWR_CFG_RATE6, txpower);
4273 * TX_PWR_CFG_0: 18MBS, TX_PWR_CFG_1: MCS3,
4274 * TX_PWR_CFG_2: MCS11, TX_PWR_CFG_3: unknown,
4275 * TX_PWR_CFG_4: unknown
4277 txpower = rt2x00_get_field16(eeprom,
4278 EEPROM_TXPOWER_BYRATE_RATE3);
4279 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
4280 power_level, txpower, delta);
4281 rt2x00_set_field32(®, TX_PWR_CFG_RATE7, txpower);
4283 rt2800_register_write(rt2x00dev, offset, reg);
4285 /* next TX_PWR_CFG register */
4290 static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev,
4291 struct ieee80211_channel *chan,
4294 if (rt2x00_rt(rt2x00dev, RT3593))
4295 rt2800_config_txpower_rt3593(rt2x00dev, chan, power_level);
4297 rt2800_config_txpower_rt28xx(rt2x00dev, chan, power_level);
4300 void rt2800_gain_calibration(struct rt2x00_dev *rt2x00dev)
4302 rt2800_config_txpower(rt2x00dev, rt2x00dev->hw->conf.chandef.chan,
4303 rt2x00dev->tx_power);
4305 EXPORT_SYMBOL_GPL(rt2800_gain_calibration);
4307 void rt2800_vco_calibration(struct rt2x00_dev *rt2x00dev)
4313 * A voltage-controlled oscillator(VCO) is an electronic oscillator
4314 * designed to be controlled in oscillation frequency by a voltage
4315 * input. Maybe the temperature will affect the frequency of
4316 * oscillation to be shifted. The VCO calibration will be called
4317 * periodically to adjust the frequency to be precision.
4320 rt2800_register_read(rt2x00dev, TX_PIN_CFG, &tx_pin);
4321 tx_pin &= TX_PIN_CFG_PA_PE_DISABLE;
4322 rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
4324 switch (rt2x00dev->chip.rf) {
4331 rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr);
4332 rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
4333 rt2800_rfcsr_write(rt2x00dev, 7, rfcsr);
4344 rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr);
4345 rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
4346 rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
4354 rt2800_register_read(rt2x00dev, TX_PIN_CFG, &tx_pin);
4355 if (rt2x00dev->rf_channel <= 14) {
4356 switch (rt2x00dev->default_ant.tx_chain_num) {
4358 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G2_EN, 1);
4361 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1);
4365 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, 1);
4369 switch (rt2x00dev->default_ant.tx_chain_num) {
4371 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A2_EN, 1);
4374 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1);
4378 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, 1);
4382 rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
4385 EXPORT_SYMBOL_GPL(rt2800_vco_calibration);
4387 static void rt2800_config_retry_limit(struct rt2x00_dev *rt2x00dev,
4388 struct rt2x00lib_conf *libconf)
4392 rt2800_register_read(rt2x00dev, TX_RTY_CFG, ®);
4393 rt2x00_set_field32(®, TX_RTY_CFG_SHORT_RTY_LIMIT,
4394 libconf->conf->short_frame_max_tx_count);
4395 rt2x00_set_field32(®, TX_RTY_CFG_LONG_RTY_LIMIT,
4396 libconf->conf->long_frame_max_tx_count);
4397 rt2800_register_write(rt2x00dev, TX_RTY_CFG, reg);
4400 static void rt2800_config_ps(struct rt2x00_dev *rt2x00dev,
4401 struct rt2x00lib_conf *libconf)
4403 enum dev_state state =
4404 (libconf->conf->flags & IEEE80211_CONF_PS) ?
4405 STATE_SLEEP : STATE_AWAKE;
4408 if (state == STATE_SLEEP) {
4409 rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0);
4411 rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG, ®);
4412 rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 5);
4413 rt2x00_set_field32(®, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE,
4414 libconf->conf->listen_interval - 1);
4415 rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTOWAKE, 1);
4416 rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
4418 rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
4420 rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG, ®);
4421 rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 0);
4422 rt2x00_set_field32(®, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE, 0);
4423 rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTOWAKE, 0);
4424 rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
4426 rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
4430 void rt2800_config(struct rt2x00_dev *rt2x00dev,
4431 struct rt2x00lib_conf *libconf,
4432 const unsigned int flags)
4434 /* Always recalculate LNA gain before changing configuration */
4435 rt2800_config_lna_gain(rt2x00dev, libconf);
4437 if (flags & IEEE80211_CONF_CHANGE_CHANNEL) {
4438 rt2800_config_channel(rt2x00dev, libconf->conf,
4439 &libconf->rf, &libconf->channel);
4440 rt2800_config_txpower(rt2x00dev, libconf->conf->chandef.chan,
4441 libconf->conf->power_level);
4443 if (flags & IEEE80211_CONF_CHANGE_POWER)
4444 rt2800_config_txpower(rt2x00dev, libconf->conf->chandef.chan,
4445 libconf->conf->power_level);
4446 if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
4447 rt2800_config_retry_limit(rt2x00dev, libconf);
4448 if (flags & IEEE80211_CONF_CHANGE_PS)
4449 rt2800_config_ps(rt2x00dev, libconf);
4451 EXPORT_SYMBOL_GPL(rt2800_config);
4456 void rt2800_link_stats(struct rt2x00_dev *rt2x00dev, struct link_qual *qual)
4461 * Update FCS error count from register.
4463 rt2800_register_read(rt2x00dev, RX_STA_CNT0, ®);
4464 qual->rx_failed = rt2x00_get_field32(reg, RX_STA_CNT0_CRC_ERR);
4466 EXPORT_SYMBOL_GPL(rt2800_link_stats);
4468 static u8 rt2800_get_default_vgc(struct rt2x00_dev *rt2x00dev)
4472 if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
4473 if (rt2x00_rt(rt2x00dev, RT3070) ||
4474 rt2x00_rt(rt2x00dev, RT3071) ||
4475 rt2x00_rt(rt2x00dev, RT3090) ||
4476 rt2x00_rt(rt2x00dev, RT3290) ||
4477 rt2x00_rt(rt2x00dev, RT3390) ||
4478 rt2x00_rt(rt2x00dev, RT3572) ||
4479 rt2x00_rt(rt2x00dev, RT3593) ||
4480 rt2x00_rt(rt2x00dev, RT5390) ||
4481 rt2x00_rt(rt2x00dev, RT5392) ||
4482 rt2x00_rt(rt2x00dev, RT5592))
4483 vgc = 0x1c + (2 * rt2x00dev->lna_gain);
4485 vgc = 0x2e + rt2x00dev->lna_gain;
4486 } else { /* 5GHZ band */
4487 if (rt2x00_rt(rt2x00dev, RT3593))
4488 vgc = 0x20 + (rt2x00dev->lna_gain * 5) / 3;
4489 else if (rt2x00_rt(rt2x00dev, RT5592))
4490 vgc = 0x24 + (2 * rt2x00dev->lna_gain);
4492 if (!test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
4493 vgc = 0x32 + (rt2x00dev->lna_gain * 5) / 3;
4495 vgc = 0x3a + (rt2x00dev->lna_gain * 5) / 3;
4502 static inline void rt2800_set_vgc(struct rt2x00_dev *rt2x00dev,
4503 struct link_qual *qual, u8 vgc_level)
4505 if (qual->vgc_level != vgc_level) {
4506 if (rt2x00_rt(rt2x00dev, RT3572) ||
4507 rt2x00_rt(rt2x00dev, RT3593)) {
4508 rt2800_bbp_write_with_rx_chain(rt2x00dev, 66,
4510 } else if (rt2x00_rt(rt2x00dev, RT5592)) {
4511 rt2800_bbp_write(rt2x00dev, 83, qual->rssi > -65 ? 0x4a : 0x7a);
4512 rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, vgc_level);
4514 rt2800_bbp_write(rt2x00dev, 66, vgc_level);
4517 qual->vgc_level = vgc_level;
4518 qual->vgc_level_reg = vgc_level;
4522 void rt2800_reset_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual)
4524 rt2800_set_vgc(rt2x00dev, qual, rt2800_get_default_vgc(rt2x00dev));
4526 EXPORT_SYMBOL_GPL(rt2800_reset_tuner);
4528 void rt2800_link_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual,
4533 if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C))
4536 /* When RSSI is better than a certain threshold, increase VGC
4537 * with a chip specific value in order to improve the balance
4538 * between sensibility and noise isolation.
4541 vgc = rt2800_get_default_vgc(rt2x00dev);
4543 switch (rt2x00dev->chip.rt) {
4546 if (qual->rssi > -65) {
4547 if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
4555 if (qual->rssi > -65)
4560 if (qual->rssi > -80)
4565 rt2800_set_vgc(rt2x00dev, qual, vgc);
4567 EXPORT_SYMBOL_GPL(rt2800_link_tuner);
4570 * Initialization functions.
4572 static int rt2800_init_registers(struct rt2x00_dev *rt2x00dev)
4574 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
4580 rt2800_disable_wpdma(rt2x00dev);
4582 ret = rt2800_drv_init_registers(rt2x00dev);
4586 rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE, 0x0000013f);
4587 rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
4589 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
4591 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®);
4592 rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_INTERVAL, 1600);
4593 rt2x00_set_field32(®, BCN_TIME_CFG_TSF_TICKING, 0);
4594 rt2x00_set_field32(®, BCN_TIME_CFG_TSF_SYNC, 0);
4595 rt2x00_set_field32(®, BCN_TIME_CFG_TBTT_ENABLE, 0);
4596 rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 0);
4597 rt2x00_set_field32(®, BCN_TIME_CFG_TX_TIME_COMPENSATE, 0);
4598 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
4600 rt2800_config_filter(rt2x00dev, FIF_ALLMULTI);
4602 rt2800_register_read(rt2x00dev, BKOFF_SLOT_CFG, ®);
4603 rt2x00_set_field32(®, BKOFF_SLOT_CFG_SLOT_TIME, 9);
4604 rt2x00_set_field32(®, BKOFF_SLOT_CFG_CC_DELAY_TIME, 2);
4605 rt2800_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg);
4607 if (rt2x00_rt(rt2x00dev, RT3290)) {
4608 rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, ®);
4609 if (rt2x00_get_field32(reg, WLAN_EN) == 1) {
4610 rt2x00_set_field32(®, PCIE_APP0_CLK_REQ, 1);
4611 rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg);
4614 rt2800_register_read(rt2x00dev, CMB_CTRL, ®);
4615 if (!(rt2x00_get_field32(reg, LDO0_EN) == 1)) {
4616 rt2x00_set_field32(®, LDO0_EN, 1);
4617 rt2x00_set_field32(®, LDO_BGSEL, 3);
4618 rt2800_register_write(rt2x00dev, CMB_CTRL, reg);
4621 rt2800_register_read(rt2x00dev, OSC_CTRL, ®);
4622 rt2x00_set_field32(®, OSC_ROSC_EN, 1);
4623 rt2x00_set_field32(®, OSC_CAL_REQ, 1);
4624 rt2x00_set_field32(®, OSC_REF_CYCLE, 0x27);
4625 rt2800_register_write(rt2x00dev, OSC_CTRL, reg);
4627 rt2800_register_read(rt2x00dev, COEX_CFG0, ®);
4628 rt2x00_set_field32(®, COEX_CFG_ANT, 0x5e);
4629 rt2800_register_write(rt2x00dev, COEX_CFG0, reg);
4631 rt2800_register_read(rt2x00dev, COEX_CFG2, ®);
4632 rt2x00_set_field32(®, BT_COEX_CFG1, 0x00);
4633 rt2x00_set_field32(®, BT_COEX_CFG0, 0x17);
4634 rt2x00_set_field32(®, WL_COEX_CFG1, 0x93);
4635 rt2x00_set_field32(®, WL_COEX_CFG0, 0x7f);
4636 rt2800_register_write(rt2x00dev, COEX_CFG2, reg);
4638 rt2800_register_read(rt2x00dev, PLL_CTRL, ®);
4639 rt2x00_set_field32(®, PLL_CONTROL, 1);
4640 rt2800_register_write(rt2x00dev, PLL_CTRL, reg);
4643 if (rt2x00_rt(rt2x00dev, RT3071) ||
4644 rt2x00_rt(rt2x00dev, RT3090) ||
4645 rt2x00_rt(rt2x00dev, RT3290) ||
4646 rt2x00_rt(rt2x00dev, RT3390)) {
4648 if (rt2x00_rt(rt2x00dev, RT3290))
4649 rt2800_register_write(rt2x00dev, TX_SW_CFG0,
4652 rt2800_register_write(rt2x00dev, TX_SW_CFG0,
4655 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
4656 if (rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) ||
4657 rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E) ||
4658 rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) {
4659 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1,
4661 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_DAC_TEST))
4662 rt2800_register_write(rt2x00dev, TX_SW_CFG2,
4665 rt2800_register_write(rt2x00dev, TX_SW_CFG2,
4668 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
4670 } else if (rt2x00_rt(rt2x00dev, RT3070)) {
4671 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
4673 if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) {
4674 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
4675 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x0000002c);
4677 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
4678 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
4680 } else if (rt2800_is_305x_soc(rt2x00dev)) {
4681 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
4682 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
4683 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000030);
4684 } else if (rt2x00_rt(rt2x00dev, RT3352)) {
4685 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000402);
4686 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
4687 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
4688 } else if (rt2x00_rt(rt2x00dev, RT3572)) {
4689 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
4690 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
4691 } else if (rt2x00_rt(rt2x00dev, RT3593)) {
4692 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000402);
4693 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
4694 if (rt2x00_rt_rev_lt(rt2x00dev, RT3593, REV_RT3593E)) {
4695 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1,
4697 if (rt2x00_get_field16(eeprom,
4698 EEPROM_NIC_CONF1_DAC_TEST))
4699 rt2800_register_write(rt2x00dev, TX_SW_CFG2,
4702 rt2800_register_write(rt2x00dev, TX_SW_CFG2,
4705 rt2800_register_write(rt2x00dev, TX_SW_CFG2,
4708 } else if (rt2x00_rt(rt2x00dev, RT5390) ||
4709 rt2x00_rt(rt2x00dev, RT5392)) {
4710 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000404);
4711 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
4712 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
4713 } else if (rt2x00_rt(rt2x00dev, RT5592)) {
4714 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000404);
4715 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
4716 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
4718 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000000);
4719 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
4722 rt2800_register_read(rt2x00dev, TX_LINK_CFG, ®);
4723 rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_MFB_LIFETIME, 32);
4724 rt2x00_set_field32(®, TX_LINK_CFG_MFB_ENABLE, 0);
4725 rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_UMFS_ENABLE, 0);
4726 rt2x00_set_field32(®, TX_LINK_CFG_TX_MRQ_EN, 0);
4727 rt2x00_set_field32(®, TX_LINK_CFG_TX_RDG_EN, 0);
4728 rt2x00_set_field32(®, TX_LINK_CFG_TX_CF_ACK_EN, 1);
4729 rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_MFB, 0);
4730 rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_MFS, 0);
4731 rt2800_register_write(rt2x00dev, TX_LINK_CFG, reg);
4733 rt2800_register_read(rt2x00dev, TX_TIMEOUT_CFG, ®);
4734 rt2x00_set_field32(®, TX_TIMEOUT_CFG_MPDU_LIFETIME, 9);
4735 rt2x00_set_field32(®, TX_TIMEOUT_CFG_RX_ACK_TIMEOUT, 32);
4736 rt2x00_set_field32(®, TX_TIMEOUT_CFG_TX_OP_TIMEOUT, 10);
4737 rt2800_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
4739 rt2800_register_read(rt2x00dev, MAX_LEN_CFG, ®);
4740 rt2x00_set_field32(®, MAX_LEN_CFG_MAX_MPDU, AGGREGATION_SIZE);
4741 if (rt2x00_rt_rev_gte(rt2x00dev, RT2872, REV_RT2872E) ||
4742 rt2x00_rt(rt2x00dev, RT2883) ||
4743 rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070E)) {
4744 drv_data->max_psdu = 2;
4745 rt2x00_set_field32(®, MAX_LEN_CFG_MAX_PSDU, 2);
4747 drv_data->max_psdu = 1;
4748 rt2x00_set_field32(®, MAX_LEN_CFG_MAX_PSDU, 1);
4750 rt2x00_set_field32(®, MAX_LEN_CFG_MIN_PSDU, 10);
4751 rt2x00_set_field32(®, MAX_LEN_CFG_MIN_MPDU, 10);
4752 rt2800_register_write(rt2x00dev, MAX_LEN_CFG, reg);
4754 rt2800_register_read(rt2x00dev, LED_CFG, ®);
4755 rt2x00_set_field32(®, LED_CFG_ON_PERIOD, 70);
4756 rt2x00_set_field32(®, LED_CFG_OFF_PERIOD, 30);
4757 rt2x00_set_field32(®, LED_CFG_SLOW_BLINK_PERIOD, 3);
4758 rt2x00_set_field32(®, LED_CFG_R_LED_MODE, 3);
4759 rt2x00_set_field32(®, LED_CFG_G_LED_MODE, 3);
4760 rt2x00_set_field32(®, LED_CFG_Y_LED_MODE, 3);
4761 rt2x00_set_field32(®, LED_CFG_LED_POLAR, 1);
4762 rt2800_register_write(rt2x00dev, LED_CFG, reg);
4764 rt2800_register_write(rt2x00dev, PBF_MAX_PCNT, 0x1f3fbf9f);
4766 rt2800_register_read(rt2x00dev, TX_RTY_CFG, ®);
4767 rt2x00_set_field32(®, TX_RTY_CFG_SHORT_RTY_LIMIT, 15);
4768 rt2x00_set_field32(®, TX_RTY_CFG_LONG_RTY_LIMIT, 31);
4769 rt2x00_set_field32(®, TX_RTY_CFG_LONG_RTY_THRE, 2000);
4770 rt2x00_set_field32(®, TX_RTY_CFG_NON_AGG_RTY_MODE, 0);
4771 rt2x00_set_field32(®, TX_RTY_CFG_AGG_RTY_MODE, 0);
4772 rt2x00_set_field32(®, TX_RTY_CFG_TX_AUTO_FB_ENABLE, 1);
4773 rt2800_register_write(rt2x00dev, TX_RTY_CFG, reg);
4775 rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, ®);
4776 rt2x00_set_field32(®, AUTO_RSP_CFG_AUTORESPONDER, 1);
4777 rt2x00_set_field32(®, AUTO_RSP_CFG_BAC_ACK_POLICY, 1);
4778 rt2x00_set_field32(®, AUTO_RSP_CFG_CTS_40_MMODE, 1);
4779 rt2x00_set_field32(®, AUTO_RSP_CFG_CTS_40_MREF, 0);
4780 rt2x00_set_field32(®, AUTO_RSP_CFG_AR_PREAMBLE, 0);
4781 rt2x00_set_field32(®, AUTO_RSP_CFG_DUAL_CTS_EN, 0);
4782 rt2x00_set_field32(®, AUTO_RSP_CFG_ACK_CTS_PSM_BIT, 0);
4783 rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
4785 rt2800_register_read(rt2x00dev, CCK_PROT_CFG, ®);
4786 rt2x00_set_field32(®, CCK_PROT_CFG_PROTECT_RATE, 3);
4787 rt2x00_set_field32(®, CCK_PROT_CFG_PROTECT_CTRL, 0);
4788 rt2x00_set_field32(®, CCK_PROT_CFG_PROTECT_NAV_SHORT, 1);
4789 rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_CCK, 1);
4790 rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
4791 rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_MM20, 1);
4792 rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_MM40, 0);
4793 rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_GF20, 1);
4794 rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_GF40, 0);
4795 rt2x00_set_field32(®, CCK_PROT_CFG_RTS_TH_EN, 1);
4796 rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg);
4798 rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, ®);
4799 rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_RATE, 3);
4800 rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_CTRL, 0);
4801 rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_NAV_SHORT, 1);
4802 rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_CCK, 1);
4803 rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
4804 rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_MM20, 1);
4805 rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_MM40, 0);
4806 rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_GF20, 1);
4807 rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_GF40, 0);
4808 rt2x00_set_field32(®, OFDM_PROT_CFG_RTS_TH_EN, 1);
4809 rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
4811 rt2800_register_read(rt2x00dev, MM20_PROT_CFG, ®);
4812 rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_RATE, 0x4004);
4813 rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_CTRL, 1);
4814 rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_NAV_SHORT, 1);
4815 rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_CCK, 0);
4816 rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
4817 rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
4818 rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
4819 rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
4820 rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
4821 rt2x00_set_field32(®, MM20_PROT_CFG_RTS_TH_EN, 0);
4822 rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
4824 rt2800_register_read(rt2x00dev, MM40_PROT_CFG, ®);
4825 rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_RATE, 0x4084);
4826 rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_CTRL, 1);
4827 rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_NAV_SHORT, 1);
4828 rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_CCK, 0);
4829 rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
4830 rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
4831 rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
4832 rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
4833 rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
4834 rt2x00_set_field32(®, MM40_PROT_CFG_RTS_TH_EN, 0);
4835 rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
4837 rt2800_register_read(rt2x00dev, GF20_PROT_CFG, ®);
4838 rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_RATE, 0x4004);
4839 rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_CTRL, 1);
4840 rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_NAV_SHORT, 1);
4841 rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_CCK, 0);
4842 rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
4843 rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
4844 rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
4845 rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
4846 rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
4847 rt2x00_set_field32(®, GF20_PROT_CFG_RTS_TH_EN, 0);
4848 rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
4850 rt2800_register_read(rt2x00dev, GF40_PROT_CFG, ®);
4851 rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_RATE, 0x4084);
4852 rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_CTRL, 1);
4853 rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_NAV_SHORT, 1);
4854 rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_CCK, 0);
4855 rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
4856 rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
4857 rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
4858 rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
4859 rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
4860 rt2x00_set_field32(®, GF40_PROT_CFG_RTS_TH_EN, 0);
4861 rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
4863 if (rt2x00_is_usb(rt2x00dev)) {
4864 rt2800_register_write(rt2x00dev, PBF_CFG, 0xf40006);
4866 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®);
4867 rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
4868 rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
4869 rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
4870 rt2x00_set_field32(®, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
4871 rt2x00_set_field32(®, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 3);
4872 rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 0);
4873 rt2x00_set_field32(®, WPDMA_GLO_CFG_BIG_ENDIAN, 0);
4874 rt2x00_set_field32(®, WPDMA_GLO_CFG_RX_HDR_SCATTER, 0);
4875 rt2x00_set_field32(®, WPDMA_GLO_CFG_HDR_SEG_LEN, 0);
4876 rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
4880 * The legacy driver also sets TXOP_CTRL_CFG_RESERVED_TRUN_EN to 1
4881 * although it is reserved.
4883 rt2800_register_read(rt2x00dev, TXOP_CTRL_CFG, ®);
4884 rt2x00_set_field32(®, TXOP_CTRL_CFG_TIMEOUT_TRUN_EN, 1);
4885 rt2x00_set_field32(®, TXOP_CTRL_CFG_AC_TRUN_EN, 1);
4886 rt2x00_set_field32(®, TXOP_CTRL_CFG_TXRATEGRP_TRUN_EN, 1);
4887 rt2x00_set_field32(®, TXOP_CTRL_CFG_USER_MODE_TRUN_EN, 1);
4888 rt2x00_set_field32(®, TXOP_CTRL_CFG_MIMO_PS_TRUN_EN, 1);
4889 rt2x00_set_field32(®, TXOP_CTRL_CFG_RESERVED_TRUN_EN, 1);
4890 rt2x00_set_field32(®, TXOP_CTRL_CFG_LSIG_TXOP_EN, 0);
4891 rt2x00_set_field32(®, TXOP_CTRL_CFG_EXT_CCA_EN, 0);
4892 rt2x00_set_field32(®, TXOP_CTRL_CFG_EXT_CCA_DLY, 88);
4893 rt2x00_set_field32(®, TXOP_CTRL_CFG_EXT_CWMIN, 0);
4894 rt2800_register_write(rt2x00dev, TXOP_CTRL_CFG, reg);
4896 reg = rt2x00_rt(rt2x00dev, RT5592) ? 0x00000082 : 0x00000002;
4897 rt2800_register_write(rt2x00dev, TXOP_HLDR_ET, reg);
4899 rt2800_register_read(rt2x00dev, TX_RTS_CFG, ®);
4900 rt2x00_set_field32(®, TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT, 32);
4901 rt2x00_set_field32(®, TX_RTS_CFG_RTS_THRES,
4902 IEEE80211_MAX_RTS_THRESHOLD);
4903 rt2x00_set_field32(®, TX_RTS_CFG_RTS_FBK_EN, 0);
4904 rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg);
4906 rt2800_register_write(rt2x00dev, EXP_ACK_TIME, 0x002400ca);
4909 * Usually the CCK SIFS time should be set to 10 and the OFDM SIFS
4910 * time should be set to 16. However, the original Ralink driver uses
4911 * 16 for both and indeed using a value of 10 for CCK SIFS results in
4912 * connection problems with 11g + CTS protection. Hence, use the same
4913 * defaults as the Ralink driver: 16 for both, CCK and OFDM SIFS.
4915 rt2800_register_read(rt2x00dev, XIFS_TIME_CFG, ®);
4916 rt2x00_set_field32(®, XIFS_TIME_CFG_CCKM_SIFS_TIME, 16);
4917 rt2x00_set_field32(®, XIFS_TIME_CFG_OFDM_SIFS_TIME, 16);
4918 rt2x00_set_field32(®, XIFS_TIME_CFG_OFDM_XIFS_TIME, 4);
4919 rt2x00_set_field32(®, XIFS_TIME_CFG_EIFS, 314);
4920 rt2x00_set_field32(®, XIFS_TIME_CFG_BB_RXEND_ENABLE, 1);
4921 rt2800_register_write(rt2x00dev, XIFS_TIME_CFG, reg);
4923 rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
4926 * ASIC will keep garbage value after boot, clear encryption keys.
4928 for (i = 0; i < 4; i++)
4929 rt2800_register_write(rt2x00dev,
4930 SHARED_KEY_MODE_ENTRY(i), 0);
4932 for (i = 0; i < 256; i++) {
4933 rt2800_config_wcid(rt2x00dev, NULL, i);
4934 rt2800_delete_wcid_attr(rt2x00dev, i);
4935 rt2800_register_write(rt2x00dev, MAC_IVEIV_ENTRY(i), 0);
4941 for (i = 0; i < 8; i++)
4942 rt2800_clear_beacon_register(rt2x00dev, i);
4944 if (rt2x00_is_usb(rt2x00dev)) {
4945 rt2800_register_read(rt2x00dev, US_CYC_CNT, ®);
4946 rt2x00_set_field32(®, US_CYC_CNT_CLOCK_CYCLE, 30);
4947 rt2800_register_write(rt2x00dev, US_CYC_CNT, reg);
4948 } else if (rt2x00_is_pcie(rt2x00dev)) {
4949 rt2800_register_read(rt2x00dev, US_CYC_CNT, ®);
4950 rt2x00_set_field32(®, US_CYC_CNT_CLOCK_CYCLE, 125);
4951 rt2800_register_write(rt2x00dev, US_CYC_CNT, reg);
4954 rt2800_register_read(rt2x00dev, HT_FBK_CFG0, ®);
4955 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS0FBK, 0);
4956 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS1FBK, 0);
4957 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS2FBK, 1);
4958 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS3FBK, 2);
4959 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS4FBK, 3);
4960 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS5FBK, 4);
4961 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS6FBK, 5);
4962 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS7FBK, 6);
4963 rt2800_register_write(rt2x00dev, HT_FBK_CFG0, reg);
4965 rt2800_register_read(rt2x00dev, HT_FBK_CFG1, ®);
4966 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS8FBK, 8);
4967 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS9FBK, 8);
4968 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS10FBK, 9);
4969 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS11FBK, 10);
4970 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS12FBK, 11);
4971 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS13FBK, 12);
4972 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS14FBK, 13);
4973 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS15FBK, 14);
4974 rt2800_register_write(rt2x00dev, HT_FBK_CFG1, reg);
4976 rt2800_register_read(rt2x00dev, LG_FBK_CFG0, ®);
4977 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS0FBK, 8);
4978 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS1FBK, 8);
4979 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS2FBK, 9);
4980 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS3FBK, 10);
4981 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS4FBK, 11);
4982 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS5FBK, 12);
4983 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS6FBK, 13);
4984 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS7FBK, 14);
4985 rt2800_register_write(rt2x00dev, LG_FBK_CFG0, reg);
4987 rt2800_register_read(rt2x00dev, LG_FBK_CFG1, ®);
4988 rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS0FBK, 0);
4989 rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS1FBK, 0);
4990 rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS2FBK, 1);
4991 rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS3FBK, 2);
4992 rt2800_register_write(rt2x00dev, LG_FBK_CFG1, reg);
4995 * Do not force the BA window size, we use the TXWI to set it
4997 rt2800_register_read(rt2x00dev, AMPDU_BA_WINSIZE, ®);
4998 rt2x00_set_field32(®, AMPDU_BA_WINSIZE_FORCE_WINSIZE_ENABLE, 0);
4999 rt2x00_set_field32(®, AMPDU_BA_WINSIZE_FORCE_WINSIZE, 0);
5000 rt2800_register_write(rt2x00dev, AMPDU_BA_WINSIZE, reg);
5003 * We must clear the error counters.
5004 * These registers are cleared on read,
5005 * so we may pass a useless variable to store the value.
5007 rt2800_register_read(rt2x00dev, RX_STA_CNT0, ®);
5008 rt2800_register_read(rt2x00dev, RX_STA_CNT1, ®);
5009 rt2800_register_read(rt2x00dev, RX_STA_CNT2, ®);
5010 rt2800_register_read(rt2x00dev, TX_STA_CNT0, ®);
5011 rt2800_register_read(rt2x00dev, TX_STA_CNT1, ®);
5012 rt2800_register_read(rt2x00dev, TX_STA_CNT2, ®);
5015 * Setup leadtime for pre tbtt interrupt to 6ms
5017 rt2800_register_read(rt2x00dev, INT_TIMER_CFG, ®);
5018 rt2x00_set_field32(®, INT_TIMER_CFG_PRE_TBTT_TIMER, 6 << 4);
5019 rt2800_register_write(rt2x00dev, INT_TIMER_CFG, reg);
5022 * Set up channel statistics timer
5024 rt2800_register_read(rt2x00dev, CH_TIME_CFG, ®);
5025 rt2x00_set_field32(®, CH_TIME_CFG_EIFS_BUSY, 1);
5026 rt2x00_set_field32(®, CH_TIME_CFG_NAV_BUSY, 1);
5027 rt2x00_set_field32(®, CH_TIME_CFG_RX_BUSY, 1);
5028 rt2x00_set_field32(®, CH_TIME_CFG_TX_BUSY, 1);
5029 rt2x00_set_field32(®, CH_TIME_CFG_TMR_EN, 1);
5030 rt2800_register_write(rt2x00dev, CH_TIME_CFG, reg);
5035 static int rt2800_wait_bbp_rf_ready(struct rt2x00_dev *rt2x00dev)
5040 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
5041 rt2800_register_read(rt2x00dev, MAC_STATUS_CFG, ®);
5042 if (!rt2x00_get_field32(reg, MAC_STATUS_CFG_BBP_RF_BUSY))
5045 udelay(REGISTER_BUSY_DELAY);
5048 rt2x00_err(rt2x00dev, "BBP/RF register access failed, aborting\n");
5052 static int rt2800_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
5058 * BBP was enabled after firmware was loaded,
5059 * but we need to reactivate it now.
5061 rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
5062 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
5065 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
5066 rt2800_bbp_read(rt2x00dev, 0, &value);
5067 if ((value != 0xff) && (value != 0x00))
5069 udelay(REGISTER_BUSY_DELAY);
5072 rt2x00_err(rt2x00dev, "BBP register access failed, aborting\n");
5076 static void rt2800_bbp4_mac_if_ctrl(struct rt2x00_dev *rt2x00dev)
5080 rt2800_bbp_read(rt2x00dev, 4, &value);
5081 rt2x00_set_field8(&value, BBP4_MAC_IF_CTRL, 1);
5082 rt2800_bbp_write(rt2x00dev, 4, value);
5085 static void rt2800_init_freq_calibration(struct rt2x00_dev *rt2x00dev)
5087 rt2800_bbp_write(rt2x00dev, 142, 1);
5088 rt2800_bbp_write(rt2x00dev, 143, 57);
5091 static void rt2800_init_bbp_5592_glrt(struct rt2x00_dev *rt2x00dev)
5093 const u8 glrt_table[] = {
5094 0xE0, 0x1F, 0X38, 0x32, 0x08, 0x28, 0x19, 0x0A, 0xFF, 0x00, /* 128 ~ 137 */
5095 0x16, 0x10, 0x10, 0x0B, 0x36, 0x2C, 0x26, 0x24, 0x42, 0x36, /* 138 ~ 147 */
5096 0x30, 0x2D, 0x4C, 0x46, 0x3D, 0x40, 0x3E, 0x42, 0x3D, 0x40, /* 148 ~ 157 */
5097 0X3C, 0x34, 0x2C, 0x2F, 0x3C, 0x35, 0x2E, 0x2A, 0x49, 0x41, /* 158 ~ 167 */
5098 0x36, 0x31, 0x30, 0x30, 0x0E, 0x0D, 0x28, 0x21, 0x1C, 0x16, /* 168 ~ 177 */
5099 0x50, 0x4A, 0x43, 0x40, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, /* 178 ~ 187 */
5100 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 188 ~ 197 */
5101 0x00, 0x00, 0x7D, 0x14, 0x32, 0x2C, 0x36, 0x4C, 0x43, 0x2C, /* 198 ~ 207 */
5102 0x2E, 0x36, 0x30, 0x6E, /* 208 ~ 211 */
5106 for (i = 0; i < ARRAY_SIZE(glrt_table); i++) {
5107 rt2800_bbp_write(rt2x00dev, 195, 128 + i);
5108 rt2800_bbp_write(rt2x00dev, 196, glrt_table[i]);
5112 static void rt2800_init_bbp_early(struct rt2x00_dev *rt2x00dev)
5114 rt2800_bbp_write(rt2x00dev, 65, 0x2C);
5115 rt2800_bbp_write(rt2x00dev, 66, 0x38);
5116 rt2800_bbp_write(rt2x00dev, 68, 0x0B);
5117 rt2800_bbp_write(rt2x00dev, 69, 0x12);
5118 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
5119 rt2800_bbp_write(rt2x00dev, 73, 0x10);
5120 rt2800_bbp_write(rt2x00dev, 81, 0x37);
5121 rt2800_bbp_write(rt2x00dev, 82, 0x62);
5122 rt2800_bbp_write(rt2x00dev, 83, 0x6A);
5123 rt2800_bbp_write(rt2x00dev, 84, 0x99);
5124 rt2800_bbp_write(rt2x00dev, 86, 0x00);
5125 rt2800_bbp_write(rt2x00dev, 91, 0x04);
5126 rt2800_bbp_write(rt2x00dev, 92, 0x00);
5127 rt2800_bbp_write(rt2x00dev, 103, 0x00);
5128 rt2800_bbp_write(rt2x00dev, 105, 0x05);
5129 rt2800_bbp_write(rt2x00dev, 106, 0x35);
5132 static void rt2800_disable_unused_dac_adc(struct rt2x00_dev *rt2x00dev)
5137 rt2800_bbp_read(rt2x00dev, 138, &value);
5138 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom);
5139 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) == 1)
5141 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) == 1)
5143 rt2800_bbp_write(rt2x00dev, 138, value);
5146 static void rt2800_init_bbp_305x_soc(struct rt2x00_dev *rt2x00dev)
5148 rt2800_bbp_write(rt2x00dev, 31, 0x08);
5150 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
5151 rt2800_bbp_write(rt2x00dev, 66, 0x38);
5153 rt2800_bbp_write(rt2x00dev, 69, 0x12);
5154 rt2800_bbp_write(rt2x00dev, 73, 0x10);
5156 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
5158 rt2800_bbp_write(rt2x00dev, 78, 0x0e);
5159 rt2800_bbp_write(rt2x00dev, 80, 0x08);
5161 rt2800_bbp_write(rt2x00dev, 82, 0x62);
5163 rt2800_bbp_write(rt2x00dev, 83, 0x6a);
5165 rt2800_bbp_write(rt2x00dev, 84, 0x99);
5167 rt2800_bbp_write(rt2x00dev, 86, 0x00);
5169 rt2800_bbp_write(rt2x00dev, 91, 0x04);
5171 rt2800_bbp_write(rt2x00dev, 92, 0x00);
5173 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
5175 rt2800_bbp_write(rt2x00dev, 105, 0x01);
5177 rt2800_bbp_write(rt2x00dev, 106, 0x35);
5180 static void rt2800_init_bbp_28xx(struct rt2x00_dev *rt2x00dev)
5182 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
5183 rt2800_bbp_write(rt2x00dev, 66, 0x38);
5185 if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) {
5186 rt2800_bbp_write(rt2x00dev, 69, 0x16);
5187 rt2800_bbp_write(rt2x00dev, 73, 0x12);
5189 rt2800_bbp_write(rt2x00dev, 69, 0x12);
5190 rt2800_bbp_write(rt2x00dev, 73, 0x10);
5193 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
5195 rt2800_bbp_write(rt2x00dev, 81, 0x37);
5197 rt2800_bbp_write(rt2x00dev, 82, 0x62);
5199 rt2800_bbp_write(rt2x00dev, 83, 0x6a);
5201 if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860D))
5202 rt2800_bbp_write(rt2x00dev, 84, 0x19);
5204 rt2800_bbp_write(rt2x00dev, 84, 0x99);
5206 rt2800_bbp_write(rt2x00dev, 86, 0x00);
5208 rt2800_bbp_write(rt2x00dev, 91, 0x04);
5210 rt2800_bbp_write(rt2x00dev, 92, 0x00);
5212 rt2800_bbp_write(rt2x00dev, 103, 0x00);
5214 rt2800_bbp_write(rt2x00dev, 105, 0x05);
5216 rt2800_bbp_write(rt2x00dev, 106, 0x35);
5219 static void rt2800_init_bbp_30xx(struct rt2x00_dev *rt2x00dev)
5221 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
5222 rt2800_bbp_write(rt2x00dev, 66, 0x38);
5224 rt2800_bbp_write(rt2x00dev, 69, 0x12);
5225 rt2800_bbp_write(rt2x00dev, 73, 0x10);
5227 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
5229 rt2800_bbp_write(rt2x00dev, 79, 0x13);
5230 rt2800_bbp_write(rt2x00dev, 80, 0x05);
5231 rt2800_bbp_write(rt2x00dev, 81, 0x33);
5233 rt2800_bbp_write(rt2x00dev, 82, 0x62);
5235 rt2800_bbp_write(rt2x00dev, 83, 0x6a);
5237 rt2800_bbp_write(rt2x00dev, 84, 0x99);
5239 rt2800_bbp_write(rt2x00dev, 86, 0x00);
5241 rt2800_bbp_write(rt2x00dev, 91, 0x04);
5243 rt2800_bbp_write(rt2x00dev, 92, 0x00);
5245 if (rt2x00_rt_rev_gte(rt2x00dev, RT3070, REV_RT3070F) ||
5246 rt2x00_rt_rev_gte(rt2x00dev, RT3071, REV_RT3071E) ||
5247 rt2x00_rt_rev_gte(rt2x00dev, RT3090, REV_RT3090E))
5248 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
5250 rt2800_bbp_write(rt2x00dev, 103, 0x00);
5252 rt2800_bbp_write(rt2x00dev, 105, 0x05);
5254 rt2800_bbp_write(rt2x00dev, 106, 0x35);
5256 if (rt2x00_rt(rt2x00dev, RT3071) ||
5257 rt2x00_rt(rt2x00dev, RT3090))
5258 rt2800_disable_unused_dac_adc(rt2x00dev);
5261 static void rt2800_init_bbp_3290(struct rt2x00_dev *rt2x00dev)
5265 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
5267 rt2800_bbp_write(rt2x00dev, 31, 0x08);
5269 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
5270 rt2800_bbp_write(rt2x00dev, 66, 0x38);
5272 rt2800_bbp_write(rt2x00dev, 68, 0x0b);
5274 rt2800_bbp_write(rt2x00dev, 69, 0x12);
5275 rt2800_bbp_write(rt2x00dev, 73, 0x13);
5276 rt2800_bbp_write(rt2x00dev, 75, 0x46);
5277 rt2800_bbp_write(rt2x00dev, 76, 0x28);
5279 rt2800_bbp_write(rt2x00dev, 77, 0x58);
5281 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
5283 rt2800_bbp_write(rt2x00dev, 74, 0x0b);
5284 rt2800_bbp_write(rt2x00dev, 79, 0x18);
5285 rt2800_bbp_write(rt2x00dev, 80, 0x09);
5286 rt2800_bbp_write(rt2x00dev, 81, 0x33);
5288 rt2800_bbp_write(rt2x00dev, 82, 0x62);
5290 rt2800_bbp_write(rt2x00dev, 83, 0x7a);
5292 rt2800_bbp_write(rt2x00dev, 84, 0x9a);
5294 rt2800_bbp_write(rt2x00dev, 86, 0x38);
5296 rt2800_bbp_write(rt2x00dev, 91, 0x04);
5298 rt2800_bbp_write(rt2x00dev, 92, 0x02);
5300 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
5302 rt2800_bbp_write(rt2x00dev, 104, 0x92);
5304 rt2800_bbp_write(rt2x00dev, 105, 0x1c);
5306 rt2800_bbp_write(rt2x00dev, 106, 0x03);
5308 rt2800_bbp_write(rt2x00dev, 128, 0x12);
5310 rt2800_bbp_write(rt2x00dev, 67, 0x24);
5311 rt2800_bbp_write(rt2x00dev, 143, 0x04);
5312 rt2800_bbp_write(rt2x00dev, 142, 0x99);
5313 rt2800_bbp_write(rt2x00dev, 150, 0x30);
5314 rt2800_bbp_write(rt2x00dev, 151, 0x2e);
5315 rt2800_bbp_write(rt2x00dev, 152, 0x20);
5316 rt2800_bbp_write(rt2x00dev, 153, 0x34);
5317 rt2800_bbp_write(rt2x00dev, 154, 0x40);
5318 rt2800_bbp_write(rt2x00dev, 155, 0x3b);
5319 rt2800_bbp_write(rt2x00dev, 253, 0x04);
5321 rt2800_bbp_read(rt2x00dev, 47, &value);
5322 rt2x00_set_field8(&value, BBP47_TSSI_ADC6, 1);
5323 rt2800_bbp_write(rt2x00dev, 47, value);
5325 /* Use 5-bit ADC for Acquisition and 8-bit ADC for data */
5326 rt2800_bbp_read(rt2x00dev, 3, &value);
5327 rt2x00_set_field8(&value, BBP3_ADC_MODE_SWITCH, 1);
5328 rt2x00_set_field8(&value, BBP3_ADC_INIT_MODE, 1);
5329 rt2800_bbp_write(rt2x00dev, 3, value);
5332 static void rt2800_init_bbp_3352(struct rt2x00_dev *rt2x00dev)
5334 rt2800_bbp_write(rt2x00dev, 3, 0x00);
5335 rt2800_bbp_write(rt2x00dev, 4, 0x50);
5337 rt2800_bbp_write(rt2x00dev, 31, 0x08);
5339 rt2800_bbp_write(rt2x00dev, 47, 0x48);
5341 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
5342 rt2800_bbp_write(rt2x00dev, 66, 0x38);
5344 rt2800_bbp_write(rt2x00dev, 68, 0x0b);
5346 rt2800_bbp_write(rt2x00dev, 69, 0x12);
5347 rt2800_bbp_write(rt2x00dev, 73, 0x13);
5348 rt2800_bbp_write(rt2x00dev, 75, 0x46);
5349 rt2800_bbp_write(rt2x00dev, 76, 0x28);
5351 rt2800_bbp_write(rt2x00dev, 77, 0x59);
5353 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
5355 rt2800_bbp_write(rt2x00dev, 78, 0x0e);
5356 rt2800_bbp_write(rt2x00dev, 80, 0x08);
5357 rt2800_bbp_write(rt2x00dev, 81, 0x37);
5359 rt2800_bbp_write(rt2x00dev, 82, 0x62);
5361 rt2800_bbp_write(rt2x00dev, 83, 0x6a);
5363 rt2800_bbp_write(rt2x00dev, 84, 0x99);
5365 rt2800_bbp_write(rt2x00dev, 86, 0x38);
5367 rt2800_bbp_write(rt2x00dev, 88, 0x90);
5369 rt2800_bbp_write(rt2x00dev, 91, 0x04);
5371 rt2800_bbp_write(rt2x00dev, 92, 0x02);
5373 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
5375 rt2800_bbp_write(rt2x00dev, 104, 0x92);
5377 rt2800_bbp_write(rt2x00dev, 105, 0x34);
5379 rt2800_bbp_write(rt2x00dev, 106, 0x05);
5381 rt2800_bbp_write(rt2x00dev, 120, 0x50);
5383 rt2800_bbp_write(rt2x00dev, 137, 0x0f);
5385 rt2800_bbp_write(rt2x00dev, 163, 0xbd);
5386 /* Set ITxBF timeout to 0x9c40=1000msec */
5387 rt2800_bbp_write(rt2x00dev, 179, 0x02);
5388 rt2800_bbp_write(rt2x00dev, 180, 0x00);
5389 rt2800_bbp_write(rt2x00dev, 182, 0x40);
5390 rt2800_bbp_write(rt2x00dev, 180, 0x01);
5391 rt2800_bbp_write(rt2x00dev, 182, 0x9c);
5392 rt2800_bbp_write(rt2x00dev, 179, 0x00);
5393 /* Reprogram the inband interface to put right values in RXWI */
5394 rt2800_bbp_write(rt2x00dev, 142, 0x04);
5395 rt2800_bbp_write(rt2x00dev, 143, 0x3b);
5396 rt2800_bbp_write(rt2x00dev, 142, 0x06);
5397 rt2800_bbp_write(rt2x00dev, 143, 0xa0);
5398 rt2800_bbp_write(rt2x00dev, 142, 0x07);
5399 rt2800_bbp_write(rt2x00dev, 143, 0xa1);
5400 rt2800_bbp_write(rt2x00dev, 142, 0x08);
5401 rt2800_bbp_write(rt2x00dev, 143, 0xa2);
5403 rt2800_bbp_write(rt2x00dev, 148, 0xc8);
5406 static void rt2800_init_bbp_3390(struct rt2x00_dev *rt2x00dev)
5408 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
5409 rt2800_bbp_write(rt2x00dev, 66, 0x38);
5411 rt2800_bbp_write(rt2x00dev, 69, 0x12);
5412 rt2800_bbp_write(rt2x00dev, 73, 0x10);
5414 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
5416 rt2800_bbp_write(rt2x00dev, 79, 0x13);
5417 rt2800_bbp_write(rt2x00dev, 80, 0x05);
5418 rt2800_bbp_write(rt2x00dev, 81, 0x33);
5420 rt2800_bbp_write(rt2x00dev, 82, 0x62);
5422 rt2800_bbp_write(rt2x00dev, 83, 0x6a);
5424 rt2800_bbp_write(rt2x00dev, 84, 0x99);
5426 rt2800_bbp_write(rt2x00dev, 86, 0x00);
5428 rt2800_bbp_write(rt2x00dev, 91, 0x04);
5430 rt2800_bbp_write(rt2x00dev, 92, 0x00);
5432 if (rt2x00_rt_rev_gte(rt2x00dev, RT3390, REV_RT3390E))
5433 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
5435 rt2800_bbp_write(rt2x00dev, 103, 0x00);
5437 rt2800_bbp_write(rt2x00dev, 105, 0x05);
5439 rt2800_bbp_write(rt2x00dev, 106, 0x35);
5441 rt2800_disable_unused_dac_adc(rt2x00dev);
5444 static void rt2800_init_bbp_3572(struct rt2x00_dev *rt2x00dev)
5446 rt2800_bbp_write(rt2x00dev, 31, 0x08);
5448 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
5449 rt2800_bbp_write(rt2x00dev, 66, 0x38);
5451 rt2800_bbp_write(rt2x00dev, 69, 0x12);
5452 rt2800_bbp_write(rt2x00dev, 73, 0x10);
5454 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
5456 rt2800_bbp_write(rt2x00dev, 79, 0x13);
5457 rt2800_bbp_write(rt2x00dev, 80, 0x05);
5458 rt2800_bbp_write(rt2x00dev, 81, 0x33);
5460 rt2800_bbp_write(rt2x00dev, 82, 0x62);
5462 rt2800_bbp_write(rt2x00dev, 83, 0x6a);
5464 rt2800_bbp_write(rt2x00dev, 84, 0x99);
5466 rt2800_bbp_write(rt2x00dev, 86, 0x00);
5468 rt2800_bbp_write(rt2x00dev, 91, 0x04);
5470 rt2800_bbp_write(rt2x00dev, 92, 0x00);
5472 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
5474 rt2800_bbp_write(rt2x00dev, 105, 0x05);
5476 rt2800_bbp_write(rt2x00dev, 106, 0x35);
5478 rt2800_disable_unused_dac_adc(rt2x00dev);
5481 static void rt2800_init_bbp_3593(struct rt2x00_dev *rt2x00dev)
5483 rt2800_init_bbp_early(rt2x00dev);
5485 rt2800_bbp_write(rt2x00dev, 79, 0x13);
5486 rt2800_bbp_write(rt2x00dev, 80, 0x05);
5487 rt2800_bbp_write(rt2x00dev, 81, 0x33);
5488 rt2800_bbp_write(rt2x00dev, 137, 0x0f);
5490 rt2800_bbp_write(rt2x00dev, 84, 0x19);
5492 /* Enable DC filter */
5493 if (rt2x00_rt_rev_gte(rt2x00dev, RT3593, REV_RT3593E))
5494 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
5497 static void rt2800_init_bbp_53xx(struct rt2x00_dev *rt2x00dev)
5503 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
5505 rt2800_bbp_write(rt2x00dev, 31, 0x08);
5507 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
5508 rt2800_bbp_write(rt2x00dev, 66, 0x38);
5510 rt2800_bbp_write(rt2x00dev, 68, 0x0b);
5512 rt2800_bbp_write(rt2x00dev, 69, 0x12);
5513 rt2800_bbp_write(rt2x00dev, 73, 0x13);
5514 rt2800_bbp_write(rt2x00dev, 75, 0x46);
5515 rt2800_bbp_write(rt2x00dev, 76, 0x28);
5517 rt2800_bbp_write(rt2x00dev, 77, 0x59);
5519 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
5521 rt2800_bbp_write(rt2x00dev, 79, 0x13);
5522 rt2800_bbp_write(rt2x00dev, 80, 0x05);
5523 rt2800_bbp_write(rt2x00dev, 81, 0x33);
5525 rt2800_bbp_write(rt2x00dev, 82, 0x62);
5527 rt2800_bbp_write(rt2x00dev, 83, 0x7a);
5529 rt2800_bbp_write(rt2x00dev, 84, 0x9a);
5531 rt2800_bbp_write(rt2x00dev, 86, 0x38);
5533 if (rt2x00_rt(rt2x00dev, RT5392))
5534 rt2800_bbp_write(rt2x00dev, 88, 0x90);
5536 rt2800_bbp_write(rt2x00dev, 91, 0x04);
5538 rt2800_bbp_write(rt2x00dev, 92, 0x02);
5540 if (rt2x00_rt(rt2x00dev, RT5392)) {
5541 rt2800_bbp_write(rt2x00dev, 95, 0x9a);
5542 rt2800_bbp_write(rt2x00dev, 98, 0x12);
5545 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
5547 rt2800_bbp_write(rt2x00dev, 104, 0x92);
5549 rt2800_bbp_write(rt2x00dev, 105, 0x3c);
5551 if (rt2x00_rt(rt2x00dev, RT5390))
5552 rt2800_bbp_write(rt2x00dev, 106, 0x03);
5553 else if (rt2x00_rt(rt2x00dev, RT5392))
5554 rt2800_bbp_write(rt2x00dev, 106, 0x12);
5558 rt2800_bbp_write(rt2x00dev, 128, 0x12);
5560 if (rt2x00_rt(rt2x00dev, RT5392)) {
5561 rt2800_bbp_write(rt2x00dev, 134, 0xd0);
5562 rt2800_bbp_write(rt2x00dev, 135, 0xf6);
5565 rt2800_disable_unused_dac_adc(rt2x00dev);
5567 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
5568 div_mode = rt2x00_get_field16(eeprom,
5569 EEPROM_NIC_CONF1_ANT_DIVERSITY);
5570 ant = (div_mode == 3) ? 1 : 0;
5572 /* check if this is a Bluetooth combo card */
5573 if (rt2x00_has_cap_bt_coexist(rt2x00dev)) {
5576 rt2800_register_read(rt2x00dev, GPIO_CTRL, ®);
5577 rt2x00_set_field32(®, GPIO_CTRL_DIR3, 0);
5578 rt2x00_set_field32(®, GPIO_CTRL_DIR6, 0);
5579 rt2x00_set_field32(®, GPIO_CTRL_VAL3, 0);
5580 rt2x00_set_field32(®, GPIO_CTRL_VAL6, 0);
5582 rt2x00_set_field32(®, GPIO_CTRL_VAL3, 1);
5584 rt2x00_set_field32(®, GPIO_CTRL_VAL6, 1);
5585 rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
5588 /* This chip has hardware antenna diversity*/
5589 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390R)) {
5590 rt2800_bbp_write(rt2x00dev, 150, 0); /* Disable Antenna Software OFDM */
5591 rt2800_bbp_write(rt2x00dev, 151, 0); /* Disable Antenna Software CCK */
5592 rt2800_bbp_write(rt2x00dev, 154, 0); /* Clear previously selected antenna */
5595 rt2800_bbp_read(rt2x00dev, 152, &value);
5597 rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 1);
5599 rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 0);
5600 rt2800_bbp_write(rt2x00dev, 152, value);
5602 rt2800_init_freq_calibration(rt2x00dev);
5605 static void rt2800_init_bbp_5592(struct rt2x00_dev *rt2x00dev)
5611 rt2800_init_bbp_early(rt2x00dev);
5613 rt2800_bbp_read(rt2x00dev, 105, &value);
5614 rt2x00_set_field8(&value, BBP105_MLD,
5615 rt2x00dev->default_ant.rx_chain_num == 2);
5616 rt2800_bbp_write(rt2x00dev, 105, value);
5618 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
5620 rt2800_bbp_write(rt2x00dev, 20, 0x06);
5621 rt2800_bbp_write(rt2x00dev, 31, 0x08);
5622 rt2800_bbp_write(rt2x00dev, 65, 0x2C);
5623 rt2800_bbp_write(rt2x00dev, 68, 0xDD);
5624 rt2800_bbp_write(rt2x00dev, 69, 0x1A);
5625 rt2800_bbp_write(rt2x00dev, 70, 0x05);
5626 rt2800_bbp_write(rt2x00dev, 73, 0x13);
5627 rt2800_bbp_write(rt2x00dev, 74, 0x0F);
5628 rt2800_bbp_write(rt2x00dev, 75, 0x4F);
5629 rt2800_bbp_write(rt2x00dev, 76, 0x28);
5630 rt2800_bbp_write(rt2x00dev, 77, 0x59);
5631 rt2800_bbp_write(rt2x00dev, 84, 0x9A);
5632 rt2800_bbp_write(rt2x00dev, 86, 0x38);
5633 rt2800_bbp_write(rt2x00dev, 88, 0x90);
5634 rt2800_bbp_write(rt2x00dev, 91, 0x04);
5635 rt2800_bbp_write(rt2x00dev, 92, 0x02);
5636 rt2800_bbp_write(rt2x00dev, 95, 0x9a);
5637 rt2800_bbp_write(rt2x00dev, 98, 0x12);
5638 rt2800_bbp_write(rt2x00dev, 103, 0xC0);
5639 rt2800_bbp_write(rt2x00dev, 104, 0x92);
5640 /* FIXME BBP105 owerwrite */
5641 rt2800_bbp_write(rt2x00dev, 105, 0x3C);
5642 rt2800_bbp_write(rt2x00dev, 106, 0x35);
5643 rt2800_bbp_write(rt2x00dev, 128, 0x12);
5644 rt2800_bbp_write(rt2x00dev, 134, 0xD0);
5645 rt2800_bbp_write(rt2x00dev, 135, 0xF6);
5646 rt2800_bbp_write(rt2x00dev, 137, 0x0F);
5648 /* Initialize GLRT (Generalized Likehood Radio Test) */
5649 rt2800_init_bbp_5592_glrt(rt2x00dev);
5651 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
5653 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
5654 div_mode = rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_ANT_DIVERSITY);
5655 ant = (div_mode == 3) ? 1 : 0;
5656 rt2800_bbp_read(rt2x00dev, 152, &value);
5659 rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 1);
5661 /* Auxiliary antenna */
5662 rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 0);
5664 rt2800_bbp_write(rt2x00dev, 152, value);
5666 if (rt2x00_rt_rev_gte(rt2x00dev, RT5592, REV_RT5592C)) {
5667 rt2800_bbp_read(rt2x00dev, 254, &value);
5668 rt2x00_set_field8(&value, BBP254_BIT7, 1);
5669 rt2800_bbp_write(rt2x00dev, 254, value);
5672 rt2800_init_freq_calibration(rt2x00dev);
5674 rt2800_bbp_write(rt2x00dev, 84, 0x19);
5675 if (rt2x00_rt_rev_gte(rt2x00dev, RT5592, REV_RT5592C))
5676 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
5679 static void rt2800_init_bbp(struct rt2x00_dev *rt2x00dev)
5686 if (rt2800_is_305x_soc(rt2x00dev))
5687 rt2800_init_bbp_305x_soc(rt2x00dev);
5689 switch (rt2x00dev->chip.rt) {
5693 rt2800_init_bbp_28xx(rt2x00dev);
5698 rt2800_init_bbp_30xx(rt2x00dev);
5701 rt2800_init_bbp_3290(rt2x00dev);
5704 rt2800_init_bbp_3352(rt2x00dev);
5707 rt2800_init_bbp_3390(rt2x00dev);
5710 rt2800_init_bbp_3572(rt2x00dev);
5713 rt2800_init_bbp_3593(rt2x00dev);
5717 rt2800_init_bbp_53xx(rt2x00dev);
5720 rt2800_init_bbp_5592(rt2x00dev);
5724 for (i = 0; i < EEPROM_BBP_SIZE; i++) {
5725 rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_BBP_START, i,
5728 if (eeprom != 0xffff && eeprom != 0x0000) {
5729 reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
5730 value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
5731 rt2800_bbp_write(rt2x00dev, reg_id, value);
5736 static void rt2800_led_open_drain_enable(struct rt2x00_dev *rt2x00dev)
5740 rt2800_register_read(rt2x00dev, OPT_14_CSR, ®);
5741 rt2x00_set_field32(®, OPT_14_CSR_BIT0, 1);
5742 rt2800_register_write(rt2x00dev, OPT_14_CSR, reg);
5745 static u8 rt2800_init_rx_filter(struct rt2x00_dev *rt2x00dev, bool bw40,
5754 u8 rfcsr24 = (bw40) ? 0x27 : 0x07;
5756 rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
5758 rt2800_bbp_read(rt2x00dev, 4, &bbp);
5759 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * bw40);
5760 rt2800_bbp_write(rt2x00dev, 4, bbp);
5762 rt2800_rfcsr_read(rt2x00dev, 31, &rfcsr);
5763 rt2x00_set_field8(&rfcsr, RFCSR31_RX_H20M, bw40);
5764 rt2800_rfcsr_write(rt2x00dev, 31, rfcsr);
5766 rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr);
5767 rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 1);
5768 rt2800_rfcsr_write(rt2x00dev, 22, rfcsr);
5771 * Set power & frequency of passband test tone
5773 rt2800_bbp_write(rt2x00dev, 24, 0);
5775 for (i = 0; i < 100; i++) {
5776 rt2800_bbp_write(rt2x00dev, 25, 0x90);
5779 rt2800_bbp_read(rt2x00dev, 55, &passband);
5785 * Set power & frequency of stopband test tone
5787 rt2800_bbp_write(rt2x00dev, 24, 0x06);
5789 for (i = 0; i < 100; i++) {
5790 rt2800_bbp_write(rt2x00dev, 25, 0x90);
5793 rt2800_bbp_read(rt2x00dev, 55, &stopband);
5795 if ((passband - stopband) <= filter_target) {
5797 overtuned += ((passband - stopband) == filter_target);
5801 rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
5804 rfcsr24 -= !!overtuned;
5806 rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
5810 static void rt2800_rf_init_calibration(struct rt2x00_dev *rt2x00dev,
5811 const unsigned int rf_reg)
5815 rt2800_rfcsr_read(rt2x00dev, rf_reg, &rfcsr);
5816 rt2x00_set_field8(&rfcsr, FIELD8(0x80), 1);
5817 rt2800_rfcsr_write(rt2x00dev, rf_reg, rfcsr);
5819 rt2x00_set_field8(&rfcsr, FIELD8(0x80), 0);
5820 rt2800_rfcsr_write(rt2x00dev, rf_reg, rfcsr);
5823 static void rt2800_rx_filter_calibration(struct rt2x00_dev *rt2x00dev)
5825 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
5831 * TODO: sync filter_tgt values with vendor driver
5833 if (rt2x00_rt(rt2x00dev, RT3070)) {
5834 filter_tgt_bw20 = 0x16;
5835 filter_tgt_bw40 = 0x19;
5837 filter_tgt_bw20 = 0x13;
5838 filter_tgt_bw40 = 0x15;
5841 drv_data->calibration_bw20 =
5842 rt2800_init_rx_filter(rt2x00dev, false, filter_tgt_bw20);
5843 drv_data->calibration_bw40 =
5844 rt2800_init_rx_filter(rt2x00dev, true, filter_tgt_bw40);
5847 * Save BBP 25 & 26 values for later use in channel switching (for 3052)
5849 rt2800_bbp_read(rt2x00dev, 25, &drv_data->bbp25);
5850 rt2800_bbp_read(rt2x00dev, 26, &drv_data->bbp26);
5853 * Set back to initial state
5855 rt2800_bbp_write(rt2x00dev, 24, 0);
5857 rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr);
5858 rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 0);
5859 rt2800_rfcsr_write(rt2x00dev, 22, rfcsr);
5862 * Set BBP back to BW20
5864 rt2800_bbp_read(rt2x00dev, 4, &bbp);
5865 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0);
5866 rt2800_bbp_write(rt2x00dev, 4, bbp);
5869 static void rt2800_normal_mode_setup_3xxx(struct rt2x00_dev *rt2x00dev)
5871 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
5872 u8 min_gain, rfcsr, bbp;
5875 rt2800_rfcsr_read(rt2x00dev, 17, &rfcsr);
5877 rt2x00_set_field8(&rfcsr, RFCSR17_TX_LO1_EN, 0);
5878 if (rt2x00_rt(rt2x00dev, RT3070) ||
5879 rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) ||
5880 rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E) ||
5881 rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) {
5882 if (!rt2x00_has_cap_external_lna_bg(rt2x00dev))
5883 rt2x00_set_field8(&rfcsr, RFCSR17_R, 1);
5886 min_gain = rt2x00_rt(rt2x00dev, RT3070) ? 1 : 2;
5887 if (drv_data->txmixer_gain_24g >= min_gain) {
5888 rt2x00_set_field8(&rfcsr, RFCSR17_TXMIXER_GAIN,
5889 drv_data->txmixer_gain_24g);
5892 rt2800_rfcsr_write(rt2x00dev, 17, rfcsr);
5894 if (rt2x00_rt(rt2x00dev, RT3090)) {
5895 /* Turn off unused DAC1 and ADC1 to reduce power consumption */
5896 rt2800_bbp_read(rt2x00dev, 138, &bbp);
5897 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom);
5898 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) == 1)
5899 rt2x00_set_field8(&bbp, BBP138_RX_ADC1, 0);
5900 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) == 1)
5901 rt2x00_set_field8(&bbp, BBP138_TX_DAC1, 1);
5902 rt2800_bbp_write(rt2x00dev, 138, bbp);
5905 if (rt2x00_rt(rt2x00dev, RT3070)) {
5906 rt2800_rfcsr_read(rt2x00dev, 27, &rfcsr);
5907 if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F))
5908 rt2x00_set_field8(&rfcsr, RFCSR27_R1, 3);
5910 rt2x00_set_field8(&rfcsr, RFCSR27_R1, 0);
5911 rt2x00_set_field8(&rfcsr, RFCSR27_R2, 0);
5912 rt2x00_set_field8(&rfcsr, RFCSR27_R3, 0);
5913 rt2x00_set_field8(&rfcsr, RFCSR27_R4, 0);
5914 rt2800_rfcsr_write(rt2x00dev, 27, rfcsr);
5915 } else if (rt2x00_rt(rt2x00dev, RT3071) ||
5916 rt2x00_rt(rt2x00dev, RT3090) ||
5917 rt2x00_rt(rt2x00dev, RT3390)) {
5918 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
5919 rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
5920 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0);
5921 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0);
5922 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
5923 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
5924 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
5926 rt2800_rfcsr_read(rt2x00dev, 15, &rfcsr);
5927 rt2x00_set_field8(&rfcsr, RFCSR15_TX_LO2_EN, 0);
5928 rt2800_rfcsr_write(rt2x00dev, 15, rfcsr);
5930 rt2800_rfcsr_read(rt2x00dev, 20, &rfcsr);
5931 rt2x00_set_field8(&rfcsr, RFCSR20_RX_LO1_EN, 0);
5932 rt2800_rfcsr_write(rt2x00dev, 20, rfcsr);
5934 rt2800_rfcsr_read(rt2x00dev, 21, &rfcsr);
5935 rt2x00_set_field8(&rfcsr, RFCSR21_RX_LO2_EN, 0);
5936 rt2800_rfcsr_write(rt2x00dev, 21, rfcsr);
5940 static void rt2800_normal_mode_setup_3593(struct rt2x00_dev *rt2x00dev)
5942 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
5946 rt2800_rfcsr_read(rt2x00dev, 50, &rfcsr);
5947 rt2x00_set_field8(&rfcsr, RFCSR50_TX_LO2_EN, 0);
5948 rt2800_rfcsr_write(rt2x00dev, 50, rfcsr);
5950 rt2800_rfcsr_read(rt2x00dev, 51, &rfcsr);
5951 tx_gain = rt2x00_get_field8(drv_data->txmixer_gain_24g,
5952 RFCSR17_TXMIXER_GAIN);
5953 rt2x00_set_field8(&rfcsr, RFCSR51_BITS24, tx_gain);
5954 rt2800_rfcsr_write(rt2x00dev, 51, rfcsr);
5956 rt2800_rfcsr_read(rt2x00dev, 38, &rfcsr);
5957 rt2x00_set_field8(&rfcsr, RFCSR38_RX_LO1_EN, 0);
5958 rt2800_rfcsr_write(rt2x00dev, 38, rfcsr);
5960 rt2800_rfcsr_read(rt2x00dev, 39, &rfcsr);
5961 rt2x00_set_field8(&rfcsr, RFCSR39_RX_LO2_EN, 0);
5962 rt2800_rfcsr_write(rt2x00dev, 39, rfcsr);
5964 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
5965 rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
5966 rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1);
5967 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
5969 rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
5970 rt2x00_set_field8(&rfcsr, RFCSR30_RX_VCM, 2);
5971 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
5973 /* TODO: enable stream mode */
5976 static void rt2800_normal_mode_setup_5xxx(struct rt2x00_dev *rt2x00dev)
5981 /* Turn off unused DAC1 and ADC1 to reduce power consumption */
5982 rt2800_bbp_read(rt2x00dev, 138, ®);
5983 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom);
5984 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) == 1)
5985 rt2x00_set_field8(®, BBP138_RX_ADC1, 0);
5986 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) == 1)
5987 rt2x00_set_field8(®, BBP138_TX_DAC1, 1);
5988 rt2800_bbp_write(rt2x00dev, 138, reg);
5990 rt2800_rfcsr_read(rt2x00dev, 38, ®);
5991 rt2x00_set_field8(®, RFCSR38_RX_LO1_EN, 0);
5992 rt2800_rfcsr_write(rt2x00dev, 38, reg);
5994 rt2800_rfcsr_read(rt2x00dev, 39, ®);
5995 rt2x00_set_field8(®, RFCSR39_RX_LO2_EN, 0);
5996 rt2800_rfcsr_write(rt2x00dev, 39, reg);
5998 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
6000 rt2800_rfcsr_read(rt2x00dev, 30, ®);
6001 rt2x00_set_field8(®, RFCSR30_RX_VCM, 2);
6002 rt2800_rfcsr_write(rt2x00dev, 30, reg);
6005 static void rt2800_init_rfcsr_305x_soc(struct rt2x00_dev *rt2x00dev)
6007 rt2800_rf_init_calibration(rt2x00dev, 30);
6009 rt2800_rfcsr_write(rt2x00dev, 0, 0x50);
6010 rt2800_rfcsr_write(rt2x00dev, 1, 0x01);
6011 rt2800_rfcsr_write(rt2x00dev, 2, 0xf7);
6012 rt2800_rfcsr_write(rt2x00dev, 3, 0x75);
6013 rt2800_rfcsr_write(rt2x00dev, 4, 0x40);
6014 rt2800_rfcsr_write(rt2x00dev, 5, 0x03);
6015 rt2800_rfcsr_write(rt2x00dev, 6, 0x02);
6016 rt2800_rfcsr_write(rt2x00dev, 7, 0x50);
6017 rt2800_rfcsr_write(rt2x00dev, 8, 0x39);
6018 rt2800_rfcsr_write(rt2x00dev, 9, 0x0f);
6019 rt2800_rfcsr_write(rt2x00dev, 10, 0x60);
6020 rt2800_rfcsr_write(rt2x00dev, 11, 0x21);
6021 rt2800_rfcsr_write(rt2x00dev, 12, 0x75);
6022 rt2800_rfcsr_write(rt2x00dev, 13, 0x75);
6023 rt2800_rfcsr_write(rt2x00dev, 14, 0x90);
6024 rt2800_rfcsr_write(rt2x00dev, 15, 0x58);
6025 rt2800_rfcsr_write(rt2x00dev, 16, 0xb3);
6026 rt2800_rfcsr_write(rt2x00dev, 17, 0x92);
6027 rt2800_rfcsr_write(rt2x00dev, 18, 0x2c);
6028 rt2800_rfcsr_write(rt2x00dev, 19, 0x02);
6029 rt2800_rfcsr_write(rt2x00dev, 20, 0xba);
6030 rt2800_rfcsr_write(rt2x00dev, 21, 0xdb);
6031 rt2800_rfcsr_write(rt2x00dev, 22, 0x00);
6032 rt2800_rfcsr_write(rt2x00dev, 23, 0x31);
6033 rt2800_rfcsr_write(rt2x00dev, 24, 0x08);
6034 rt2800_rfcsr_write(rt2x00dev, 25, 0x01);
6035 rt2800_rfcsr_write(rt2x00dev, 26, 0x25);
6036 rt2800_rfcsr_write(rt2x00dev, 27, 0x23);
6037 rt2800_rfcsr_write(rt2x00dev, 28, 0x13);
6038 rt2800_rfcsr_write(rt2x00dev, 29, 0x83);
6039 rt2800_rfcsr_write(rt2x00dev, 30, 0x00);
6040 rt2800_rfcsr_write(rt2x00dev, 31, 0x00);
6043 static void rt2800_init_rfcsr_30xx(struct rt2x00_dev *rt2x00dev)
6049 /* XXX vendor driver do this only for 3070 */
6050 rt2800_rf_init_calibration(rt2x00dev, 30);
6052 rt2800_rfcsr_write(rt2x00dev, 4, 0x40);
6053 rt2800_rfcsr_write(rt2x00dev, 5, 0x03);
6054 rt2800_rfcsr_write(rt2x00dev, 6, 0x02);
6055 rt2800_rfcsr_write(rt2x00dev, 7, 0x60);
6056 rt2800_rfcsr_write(rt2x00dev, 9, 0x0f);
6057 rt2800_rfcsr_write(rt2x00dev, 10, 0x41);
6058 rt2800_rfcsr_write(rt2x00dev, 11, 0x21);
6059 rt2800_rfcsr_write(rt2x00dev, 12, 0x7b);
6060 rt2800_rfcsr_write(rt2x00dev, 14, 0x90);
6061 rt2800_rfcsr_write(rt2x00dev, 15, 0x58);
6062 rt2800_rfcsr_write(rt2x00dev, 16, 0xb3);
6063 rt2800_rfcsr_write(rt2x00dev, 17, 0x92);
6064 rt2800_rfcsr_write(rt2x00dev, 18, 0x2c);
6065 rt2800_rfcsr_write(rt2x00dev, 19, 0x02);
6066 rt2800_rfcsr_write(rt2x00dev, 20, 0xba);
6067 rt2800_rfcsr_write(rt2x00dev, 21, 0xdb);
6068 rt2800_rfcsr_write(rt2x00dev, 24, 0x16);
6069 rt2800_rfcsr_write(rt2x00dev, 25, 0x03);
6070 rt2800_rfcsr_write(rt2x00dev, 29, 0x1f);
6072 if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) {
6073 rt2800_register_read(rt2x00dev, LDO_CFG0, ®);
6074 rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1);
6075 rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 3);
6076 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
6077 } else if (rt2x00_rt(rt2x00dev, RT3071) ||
6078 rt2x00_rt(rt2x00dev, RT3090)) {
6079 rt2800_rfcsr_write(rt2x00dev, 31, 0x14);
6081 rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr);
6082 rt2x00_set_field8(&rfcsr, RFCSR6_R2, 1);
6083 rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
6085 rt2800_register_read(rt2x00dev, LDO_CFG0, ®);
6086 rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1);
6087 if (rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) ||
6088 rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E)) {
6089 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1,
6091 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_DAC_TEST))
6092 rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 3);
6094 rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 0);
6096 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
6098 rt2800_register_read(rt2x00dev, GPIO_SWITCH, ®);
6099 rt2x00_set_field32(®, GPIO_SWITCH_5, 0);
6100 rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg);
6103 rt2800_rx_filter_calibration(rt2x00dev);
6105 if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F) ||
6106 rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) ||
6107 rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E))
6108 rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
6110 rt2800_led_open_drain_enable(rt2x00dev);
6111 rt2800_normal_mode_setup_3xxx(rt2x00dev);
6114 static void rt2800_init_rfcsr_3290(struct rt2x00_dev *rt2x00dev)
6118 rt2800_rf_init_calibration(rt2x00dev, 2);
6120 rt2800_rfcsr_write(rt2x00dev, 1, 0x0f);
6121 rt2800_rfcsr_write(rt2x00dev, 2, 0x80);
6122 rt2800_rfcsr_write(rt2x00dev, 3, 0x08);
6123 rt2800_rfcsr_write(rt2x00dev, 4, 0x00);
6124 rt2800_rfcsr_write(rt2x00dev, 6, 0xa0);
6125 rt2800_rfcsr_write(rt2x00dev, 8, 0xf3);
6126 rt2800_rfcsr_write(rt2x00dev, 9, 0x02);
6127 rt2800_rfcsr_write(rt2x00dev, 10, 0x53);
6128 rt2800_rfcsr_write(rt2x00dev, 11, 0x4a);
6129 rt2800_rfcsr_write(rt2x00dev, 12, 0x46);
6130 rt2800_rfcsr_write(rt2x00dev, 13, 0x9f);
6131 rt2800_rfcsr_write(rt2x00dev, 18, 0x02);
6132 rt2800_rfcsr_write(rt2x00dev, 22, 0x20);
6133 rt2800_rfcsr_write(rt2x00dev, 25, 0x83);
6134 rt2800_rfcsr_write(rt2x00dev, 26, 0x82);
6135 rt2800_rfcsr_write(rt2x00dev, 27, 0x09);
6136 rt2800_rfcsr_write(rt2x00dev, 29, 0x10);
6137 rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
6138 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
6139 rt2800_rfcsr_write(rt2x00dev, 32, 0x80);
6140 rt2800_rfcsr_write(rt2x00dev, 33, 0x00);
6141 rt2800_rfcsr_write(rt2x00dev, 34, 0x05);
6142 rt2800_rfcsr_write(rt2x00dev, 35, 0x12);
6143 rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
6144 rt2800_rfcsr_write(rt2x00dev, 38, 0x85);
6145 rt2800_rfcsr_write(rt2x00dev, 39, 0x1b);
6146 rt2800_rfcsr_write(rt2x00dev, 40, 0x0b);
6147 rt2800_rfcsr_write(rt2x00dev, 41, 0xbb);
6148 rt2800_rfcsr_write(rt2x00dev, 42, 0xd5);
6149 rt2800_rfcsr_write(rt2x00dev, 43, 0x7b);
6150 rt2800_rfcsr_write(rt2x00dev, 44, 0x0e);
6151 rt2800_rfcsr_write(rt2x00dev, 45, 0xa2);
6152 rt2800_rfcsr_write(rt2x00dev, 46, 0x73);
6153 rt2800_rfcsr_write(rt2x00dev, 47, 0x00);
6154 rt2800_rfcsr_write(rt2x00dev, 48, 0x10);
6155 rt2800_rfcsr_write(rt2x00dev, 49, 0x98);
6156 rt2800_rfcsr_write(rt2x00dev, 52, 0x38);
6157 rt2800_rfcsr_write(rt2x00dev, 53, 0x00);
6158 rt2800_rfcsr_write(rt2x00dev, 54, 0x78);
6159 rt2800_rfcsr_write(rt2x00dev, 55, 0x43);
6160 rt2800_rfcsr_write(rt2x00dev, 56, 0x02);
6161 rt2800_rfcsr_write(rt2x00dev, 57, 0x80);
6162 rt2800_rfcsr_write(rt2x00dev, 58, 0x7f);
6163 rt2800_rfcsr_write(rt2x00dev, 59, 0x09);
6164 rt2800_rfcsr_write(rt2x00dev, 60, 0x45);
6165 rt2800_rfcsr_write(rt2x00dev, 61, 0xc1);
6167 rt2800_rfcsr_read(rt2x00dev, 29, &rfcsr);
6168 rt2x00_set_field8(&rfcsr, RFCSR29_RSSI_GAIN, 3);
6169 rt2800_rfcsr_write(rt2x00dev, 29, rfcsr);
6171 rt2800_led_open_drain_enable(rt2x00dev);
6172 rt2800_normal_mode_setup_3xxx(rt2x00dev);
6175 static void rt2800_init_rfcsr_3352(struct rt2x00_dev *rt2x00dev)
6177 rt2800_rf_init_calibration(rt2x00dev, 30);
6179 rt2800_rfcsr_write(rt2x00dev, 0, 0xf0);
6180 rt2800_rfcsr_write(rt2x00dev, 1, 0x23);
6181 rt2800_rfcsr_write(rt2x00dev, 2, 0x50);
6182 rt2800_rfcsr_write(rt2x00dev, 3, 0x18);
6183 rt2800_rfcsr_write(rt2x00dev, 4, 0x00);
6184 rt2800_rfcsr_write(rt2x00dev, 5, 0x00);
6185 rt2800_rfcsr_write(rt2x00dev, 6, 0x33);
6186 rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
6187 rt2800_rfcsr_write(rt2x00dev, 8, 0xf1);
6188 rt2800_rfcsr_write(rt2x00dev, 9, 0x02);
6189 rt2800_rfcsr_write(rt2x00dev, 10, 0xd2);
6190 rt2800_rfcsr_write(rt2x00dev, 11, 0x42);
6191 rt2800_rfcsr_write(rt2x00dev, 12, 0x1c);
6192 rt2800_rfcsr_write(rt2x00dev, 13, 0x00);
6193 rt2800_rfcsr_write(rt2x00dev, 14, 0x5a);
6194 rt2800_rfcsr_write(rt2x00dev, 15, 0x00);
6195 rt2800_rfcsr_write(rt2x00dev, 16, 0x01);
6196 rt2800_rfcsr_write(rt2x00dev, 18, 0x45);
6197 rt2800_rfcsr_write(rt2x00dev, 19, 0x02);
6198 rt2800_rfcsr_write(rt2x00dev, 20, 0x00);
6199 rt2800_rfcsr_write(rt2x00dev, 21, 0x00);
6200 rt2800_rfcsr_write(rt2x00dev, 22, 0x00);
6201 rt2800_rfcsr_write(rt2x00dev, 23, 0x00);
6202 rt2800_rfcsr_write(rt2x00dev, 24, 0x00);
6203 rt2800_rfcsr_write(rt2x00dev, 25, 0x80);
6204 rt2800_rfcsr_write(rt2x00dev, 26, 0x00);
6205 rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
6206 rt2800_rfcsr_write(rt2x00dev, 28, 0x03);
6207 rt2800_rfcsr_write(rt2x00dev, 29, 0x00);
6208 rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
6209 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
6210 rt2800_rfcsr_write(rt2x00dev, 32, 0x80);
6211 rt2800_rfcsr_write(rt2x00dev, 33, 0x00);
6212 rt2800_rfcsr_write(rt2x00dev, 34, 0x01);
6213 rt2800_rfcsr_write(rt2x00dev, 35, 0x03);
6214 rt2800_rfcsr_write(rt2x00dev, 36, 0xbd);
6215 rt2800_rfcsr_write(rt2x00dev, 37, 0x3c);
6216 rt2800_rfcsr_write(rt2x00dev, 38, 0x5f);
6217 rt2800_rfcsr_write(rt2x00dev, 39, 0xc5);
6218 rt2800_rfcsr_write(rt2x00dev, 40, 0x33);
6219 rt2800_rfcsr_write(rt2x00dev, 41, 0x5b);
6220 rt2800_rfcsr_write(rt2x00dev, 42, 0x5b);
6221 rt2800_rfcsr_write(rt2x00dev, 43, 0xdb);
6222 rt2800_rfcsr_write(rt2x00dev, 44, 0xdb);
6223 rt2800_rfcsr_write(rt2x00dev, 45, 0xdb);
6224 rt2800_rfcsr_write(rt2x00dev, 46, 0xdd);
6225 rt2800_rfcsr_write(rt2x00dev, 47, 0x0d);
6226 rt2800_rfcsr_write(rt2x00dev, 48, 0x14);
6227 rt2800_rfcsr_write(rt2x00dev, 49, 0x00);
6228 rt2800_rfcsr_write(rt2x00dev, 50, 0x2d);
6229 rt2800_rfcsr_write(rt2x00dev, 51, 0x7f);
6230 rt2800_rfcsr_write(rt2x00dev, 52, 0x00);
6231 rt2800_rfcsr_write(rt2x00dev, 53, 0x52);
6232 rt2800_rfcsr_write(rt2x00dev, 54, 0x1b);
6233 rt2800_rfcsr_write(rt2x00dev, 55, 0x7f);
6234 rt2800_rfcsr_write(rt2x00dev, 56, 0x00);
6235 rt2800_rfcsr_write(rt2x00dev, 57, 0x52);
6236 rt2800_rfcsr_write(rt2x00dev, 58, 0x1b);
6237 rt2800_rfcsr_write(rt2x00dev, 59, 0x00);
6238 rt2800_rfcsr_write(rt2x00dev, 60, 0x00);
6239 rt2800_rfcsr_write(rt2x00dev, 61, 0x00);
6240 rt2800_rfcsr_write(rt2x00dev, 62, 0x00);
6241 rt2800_rfcsr_write(rt2x00dev, 63, 0x00);
6243 rt2800_rx_filter_calibration(rt2x00dev);
6244 rt2800_led_open_drain_enable(rt2x00dev);
6245 rt2800_normal_mode_setup_3xxx(rt2x00dev);
6248 static void rt2800_init_rfcsr_3390(struct rt2x00_dev *rt2x00dev)
6252 rt2800_rf_init_calibration(rt2x00dev, 30);
6254 rt2800_rfcsr_write(rt2x00dev, 0, 0xa0);
6255 rt2800_rfcsr_write(rt2x00dev, 1, 0xe1);
6256 rt2800_rfcsr_write(rt2x00dev, 2, 0xf1);
6257 rt2800_rfcsr_write(rt2x00dev, 3, 0x62);
6258 rt2800_rfcsr_write(rt2x00dev, 4, 0x40);
6259 rt2800_rfcsr_write(rt2x00dev, 5, 0x8b);
6260 rt2800_rfcsr_write(rt2x00dev, 6, 0x42);
6261 rt2800_rfcsr_write(rt2x00dev, 7, 0x34);
6262 rt2800_rfcsr_write(rt2x00dev, 8, 0x00);
6263 rt2800_rfcsr_write(rt2x00dev, 9, 0xc0);
6264 rt2800_rfcsr_write(rt2x00dev, 10, 0x61);
6265 rt2800_rfcsr_write(rt2x00dev, 11, 0x21);
6266 rt2800_rfcsr_write(rt2x00dev, 12, 0x3b);
6267 rt2800_rfcsr_write(rt2x00dev, 13, 0xe0);
6268 rt2800_rfcsr_write(rt2x00dev, 14, 0x90);
6269 rt2800_rfcsr_write(rt2x00dev, 15, 0x53);
6270 rt2800_rfcsr_write(rt2x00dev, 16, 0xe0);
6271 rt2800_rfcsr_write(rt2x00dev, 17, 0x94);
6272 rt2800_rfcsr_write(rt2x00dev, 18, 0x5c);
6273 rt2800_rfcsr_write(rt2x00dev, 19, 0x4a);
6274 rt2800_rfcsr_write(rt2x00dev, 20, 0xb2);
6275 rt2800_rfcsr_write(rt2x00dev, 21, 0xf6);
6276 rt2800_rfcsr_write(rt2x00dev, 22, 0x00);
6277 rt2800_rfcsr_write(rt2x00dev, 23, 0x14);
6278 rt2800_rfcsr_write(rt2x00dev, 24, 0x08);
6279 rt2800_rfcsr_write(rt2x00dev, 25, 0x3d);
6280 rt2800_rfcsr_write(rt2x00dev, 26, 0x85);
6281 rt2800_rfcsr_write(rt2x00dev, 27, 0x00);
6282 rt2800_rfcsr_write(rt2x00dev, 28, 0x41);
6283 rt2800_rfcsr_write(rt2x00dev, 29, 0x8f);
6284 rt2800_rfcsr_write(rt2x00dev, 30, 0x20);
6285 rt2800_rfcsr_write(rt2x00dev, 31, 0x0f);
6287 rt2800_register_read(rt2x00dev, GPIO_SWITCH, ®);
6288 rt2x00_set_field32(®, GPIO_SWITCH_5, 0);
6289 rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg);
6291 rt2800_rx_filter_calibration(rt2x00dev);
6293 if (rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E))
6294 rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
6296 rt2800_led_open_drain_enable(rt2x00dev);
6297 rt2800_normal_mode_setup_3xxx(rt2x00dev);
6300 static void rt2800_init_rfcsr_3572(struct rt2x00_dev *rt2x00dev)
6305 rt2800_rf_init_calibration(rt2x00dev, 30);
6307 rt2800_rfcsr_write(rt2x00dev, 0, 0x70);
6308 rt2800_rfcsr_write(rt2x00dev, 1, 0x81);
6309 rt2800_rfcsr_write(rt2x00dev, 2, 0xf1);
6310 rt2800_rfcsr_write(rt2x00dev, 3, 0x02);
6311 rt2800_rfcsr_write(rt2x00dev, 4, 0x4c);
6312 rt2800_rfcsr_write(rt2x00dev, 5, 0x05);
6313 rt2800_rfcsr_write(rt2x00dev, 6, 0x4a);
6314 rt2800_rfcsr_write(rt2x00dev, 7, 0xd8);
6315 rt2800_rfcsr_write(rt2x00dev, 9, 0xc3);
6316 rt2800_rfcsr_write(rt2x00dev, 10, 0xf1);
6317 rt2800_rfcsr_write(rt2x00dev, 11, 0xb9);
6318 rt2800_rfcsr_write(rt2x00dev, 12, 0x70);
6319 rt2800_rfcsr_write(rt2x00dev, 13, 0x65);
6320 rt2800_rfcsr_write(rt2x00dev, 14, 0xa0);
6321 rt2800_rfcsr_write(rt2x00dev, 15, 0x53);
6322 rt2800_rfcsr_write(rt2x00dev, 16, 0x4c);
6323 rt2800_rfcsr_write(rt2x00dev, 17, 0x23);
6324 rt2800_rfcsr_write(rt2x00dev, 18, 0xac);
6325 rt2800_rfcsr_write(rt2x00dev, 19, 0x93);
6326 rt2800_rfcsr_write(rt2x00dev, 20, 0xb3);
6327 rt2800_rfcsr_write(rt2x00dev, 21, 0xd0);
6328 rt2800_rfcsr_write(rt2x00dev, 22, 0x00);
6329 rt2800_rfcsr_write(rt2x00dev, 23, 0x3c);
6330 rt2800_rfcsr_write(rt2x00dev, 24, 0x16);
6331 rt2800_rfcsr_write(rt2x00dev, 25, 0x15);
6332 rt2800_rfcsr_write(rt2x00dev, 26, 0x85);
6333 rt2800_rfcsr_write(rt2x00dev, 27, 0x00);
6334 rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
6335 rt2800_rfcsr_write(rt2x00dev, 29, 0x9b);
6336 rt2800_rfcsr_write(rt2x00dev, 30, 0x09);
6337 rt2800_rfcsr_write(rt2x00dev, 31, 0x10);
6339 rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr);
6340 rt2x00_set_field8(&rfcsr, RFCSR6_R2, 1);
6341 rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
6343 rt2800_register_read(rt2x00dev, LDO_CFG0, ®);
6344 rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 3);
6345 rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1);
6346 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
6348 rt2800_register_read(rt2x00dev, LDO_CFG0, ®);
6349 rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 0);
6350 rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1);
6351 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
6353 rt2800_rx_filter_calibration(rt2x00dev);
6354 rt2800_led_open_drain_enable(rt2x00dev);
6355 rt2800_normal_mode_setup_3xxx(rt2x00dev);
6358 static void rt3593_post_bbp_init(struct rt2x00_dev *rt2x00dev)
6361 bool txbf_enabled = false; /* FIXME */
6363 rt2800_bbp_read(rt2x00dev, 105, &bbp);
6364 if (rt2x00dev->default_ant.rx_chain_num == 1)
6365 rt2x00_set_field8(&bbp, BBP105_MLD, 0);
6367 rt2x00_set_field8(&bbp, BBP105_MLD, 1);
6368 rt2800_bbp_write(rt2x00dev, 105, bbp);
6370 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
6372 rt2800_bbp_write(rt2x00dev, 92, 0x02);
6373 rt2800_bbp_write(rt2x00dev, 82, 0x82);
6374 rt2800_bbp_write(rt2x00dev, 106, 0x05);
6375 rt2800_bbp_write(rt2x00dev, 104, 0x92);
6376 rt2800_bbp_write(rt2x00dev, 88, 0x90);
6377 rt2800_bbp_write(rt2x00dev, 148, 0xc8);
6378 rt2800_bbp_write(rt2x00dev, 47, 0x48);
6379 rt2800_bbp_write(rt2x00dev, 120, 0x50);
6382 rt2800_bbp_write(rt2x00dev, 163, 0xbd);
6384 rt2800_bbp_write(rt2x00dev, 163, 0x9d);
6387 rt2800_bbp_write(rt2x00dev, 142, 6);
6388 rt2800_bbp_write(rt2x00dev, 143, 160);
6389 rt2800_bbp_write(rt2x00dev, 142, 7);
6390 rt2800_bbp_write(rt2x00dev, 143, 161);
6391 rt2800_bbp_write(rt2x00dev, 142, 8);
6392 rt2800_bbp_write(rt2x00dev, 143, 162);
6394 /* ADC/DAC control */
6395 rt2800_bbp_write(rt2x00dev, 31, 0x08);
6397 /* RX AGC energy lower bound in log2 */
6398 rt2800_bbp_write(rt2x00dev, 68, 0x0b);
6400 /* FIXME: BBP 105 owerwrite? */
6401 rt2800_bbp_write(rt2x00dev, 105, 0x04);
6405 static void rt2800_init_rfcsr_3593(struct rt2x00_dev *rt2x00dev)
6407 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
6411 /* Disable GPIO #4 and #7 function for LAN PE control */
6412 rt2800_register_read(rt2x00dev, GPIO_SWITCH, ®);
6413 rt2x00_set_field32(®, GPIO_SWITCH_4, 0);
6414 rt2x00_set_field32(®, GPIO_SWITCH_7, 0);
6415 rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg);
6417 /* Initialize default register values */
6418 rt2800_rfcsr_write(rt2x00dev, 1, 0x03);
6419 rt2800_rfcsr_write(rt2x00dev, 3, 0x80);
6420 rt2800_rfcsr_write(rt2x00dev, 5, 0x00);
6421 rt2800_rfcsr_write(rt2x00dev, 6, 0x40);
6422 rt2800_rfcsr_write(rt2x00dev, 8, 0xf1);
6423 rt2800_rfcsr_write(rt2x00dev, 9, 0x02);
6424 rt2800_rfcsr_write(rt2x00dev, 10, 0xd3);
6425 rt2800_rfcsr_write(rt2x00dev, 11, 0x40);
6426 rt2800_rfcsr_write(rt2x00dev, 12, 0x4e);
6427 rt2800_rfcsr_write(rt2x00dev, 13, 0x12);
6428 rt2800_rfcsr_write(rt2x00dev, 18, 0x40);
6429 rt2800_rfcsr_write(rt2x00dev, 22, 0x20);
6430 rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
6431 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
6432 rt2800_rfcsr_write(rt2x00dev, 32, 0x78);
6433 rt2800_rfcsr_write(rt2x00dev, 33, 0x3b);
6434 rt2800_rfcsr_write(rt2x00dev, 34, 0x3c);
6435 rt2800_rfcsr_write(rt2x00dev, 35, 0xe0);
6436 rt2800_rfcsr_write(rt2x00dev, 38, 0x86);
6437 rt2800_rfcsr_write(rt2x00dev, 39, 0x23);
6438 rt2800_rfcsr_write(rt2x00dev, 44, 0xd3);
6439 rt2800_rfcsr_write(rt2x00dev, 45, 0xbb);
6440 rt2800_rfcsr_write(rt2x00dev, 46, 0x60);
6441 rt2800_rfcsr_write(rt2x00dev, 49, 0x8e);
6442 rt2800_rfcsr_write(rt2x00dev, 50, 0x86);
6443 rt2800_rfcsr_write(rt2x00dev, 51, 0x75);
6444 rt2800_rfcsr_write(rt2x00dev, 52, 0x45);
6445 rt2800_rfcsr_write(rt2x00dev, 53, 0x18);
6446 rt2800_rfcsr_write(rt2x00dev, 54, 0x18);
6447 rt2800_rfcsr_write(rt2x00dev, 55, 0x18);
6448 rt2800_rfcsr_write(rt2x00dev, 56, 0xdb);
6449 rt2800_rfcsr_write(rt2x00dev, 57, 0x6e);
6451 /* Initiate calibration */
6452 /* TODO: use rt2800_rf_init_calibration ? */
6453 rt2800_rfcsr_read(rt2x00dev, 2, &rfcsr);
6454 rt2x00_set_field8(&rfcsr, RFCSR2_RESCAL_EN, 1);
6455 rt2800_rfcsr_write(rt2x00dev, 2, rfcsr);
6457 rt2800_freq_cal_mode1(rt2x00dev);
6459 rt2800_rfcsr_read(rt2x00dev, 18, &rfcsr);
6460 rt2x00_set_field8(&rfcsr, RFCSR18_XO_TUNE_BYPASS, 1);
6461 rt2800_rfcsr_write(rt2x00dev, 18, rfcsr);
6463 rt2800_register_read(rt2x00dev, LDO_CFG0, ®);
6464 rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 3);
6465 rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1);
6466 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
6467 usleep_range(1000, 1500);
6468 rt2800_register_read(rt2x00dev, LDO_CFG0, ®);
6469 rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 0);
6470 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
6472 /* Set initial values for RX filter calibration */
6473 drv_data->calibration_bw20 = 0x1f;
6474 drv_data->calibration_bw40 = 0x2f;
6476 /* Save BBP 25 & 26 values for later use in channel switching */
6477 rt2800_bbp_read(rt2x00dev, 25, &drv_data->bbp25);
6478 rt2800_bbp_read(rt2x00dev, 26, &drv_data->bbp26);
6480 rt2800_led_open_drain_enable(rt2x00dev);
6481 rt2800_normal_mode_setup_3593(rt2x00dev);
6483 rt3593_post_bbp_init(rt2x00dev);
6485 /* TODO: enable stream mode support */
6488 static void rt2800_init_rfcsr_5390(struct rt2x00_dev *rt2x00dev)
6490 rt2800_rf_init_calibration(rt2x00dev, 2);
6492 rt2800_rfcsr_write(rt2x00dev, 1, 0x0f);
6493 rt2800_rfcsr_write(rt2x00dev, 2, 0x80);
6494 rt2800_rfcsr_write(rt2x00dev, 3, 0x88);
6495 rt2800_rfcsr_write(rt2x00dev, 5, 0x10);
6496 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
6497 rt2800_rfcsr_write(rt2x00dev, 6, 0xe0);
6499 rt2800_rfcsr_write(rt2x00dev, 6, 0xa0);
6500 rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
6501 rt2800_rfcsr_write(rt2x00dev, 10, 0x53);
6502 rt2800_rfcsr_write(rt2x00dev, 11, 0x4a);
6503 rt2800_rfcsr_write(rt2x00dev, 12, 0x46);
6504 rt2800_rfcsr_write(rt2x00dev, 13, 0x9f);
6505 rt2800_rfcsr_write(rt2x00dev, 14, 0x00);
6506 rt2800_rfcsr_write(rt2x00dev, 15, 0x00);
6507 rt2800_rfcsr_write(rt2x00dev, 16, 0x00);
6508 rt2800_rfcsr_write(rt2x00dev, 18, 0x03);
6509 rt2800_rfcsr_write(rt2x00dev, 19, 0x00);
6511 rt2800_rfcsr_write(rt2x00dev, 20, 0x00);
6512 rt2800_rfcsr_write(rt2x00dev, 21, 0x00);
6513 rt2800_rfcsr_write(rt2x00dev, 22, 0x20);
6514 rt2800_rfcsr_write(rt2x00dev, 23, 0x00);
6515 rt2800_rfcsr_write(rt2x00dev, 24, 0x00);
6516 if (rt2x00_is_usb(rt2x00dev) &&
6517 rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
6518 rt2800_rfcsr_write(rt2x00dev, 25, 0x80);
6520 rt2800_rfcsr_write(rt2x00dev, 25, 0xc0);
6521 rt2800_rfcsr_write(rt2x00dev, 26, 0x00);
6522 rt2800_rfcsr_write(rt2x00dev, 27, 0x09);
6523 rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
6524 rt2800_rfcsr_write(rt2x00dev, 29, 0x10);
6526 rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
6527 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
6528 rt2800_rfcsr_write(rt2x00dev, 32, 0x80);
6529 rt2800_rfcsr_write(rt2x00dev, 33, 0x00);
6530 rt2800_rfcsr_write(rt2x00dev, 34, 0x07);
6531 rt2800_rfcsr_write(rt2x00dev, 35, 0x12);
6532 rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
6533 rt2800_rfcsr_write(rt2x00dev, 37, 0x08);
6534 rt2800_rfcsr_write(rt2x00dev, 38, 0x85);
6535 rt2800_rfcsr_write(rt2x00dev, 39, 0x1b);
6537 rt2800_rfcsr_write(rt2x00dev, 40, 0x0b);
6538 rt2800_rfcsr_write(rt2x00dev, 41, 0xbb);
6539 rt2800_rfcsr_write(rt2x00dev, 42, 0xd2);
6540 rt2800_rfcsr_write(rt2x00dev, 43, 0x9a);
6541 rt2800_rfcsr_write(rt2x00dev, 44, 0x0e);
6542 rt2800_rfcsr_write(rt2x00dev, 45, 0xa2);
6543 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
6544 rt2800_rfcsr_write(rt2x00dev, 46, 0x73);
6546 rt2800_rfcsr_write(rt2x00dev, 46, 0x7b);
6547 rt2800_rfcsr_write(rt2x00dev, 47, 0x00);
6548 rt2800_rfcsr_write(rt2x00dev, 48, 0x10);
6549 rt2800_rfcsr_write(rt2x00dev, 49, 0x94);
6551 rt2800_rfcsr_write(rt2x00dev, 52, 0x38);
6552 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
6553 rt2800_rfcsr_write(rt2x00dev, 53, 0x00);
6555 rt2800_rfcsr_write(rt2x00dev, 53, 0x84);
6556 rt2800_rfcsr_write(rt2x00dev, 54, 0x78);
6557 rt2800_rfcsr_write(rt2x00dev, 55, 0x44);
6558 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
6559 rt2800_rfcsr_write(rt2x00dev, 56, 0x42);
6561 rt2800_rfcsr_write(rt2x00dev, 56, 0x22);
6562 rt2800_rfcsr_write(rt2x00dev, 57, 0x80);
6563 rt2800_rfcsr_write(rt2x00dev, 58, 0x7f);
6564 rt2800_rfcsr_write(rt2x00dev, 59, 0x8f);
6566 rt2800_rfcsr_write(rt2x00dev, 60, 0x45);
6567 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) {
6568 if (rt2x00_is_usb(rt2x00dev))
6569 rt2800_rfcsr_write(rt2x00dev, 61, 0xd1);
6571 rt2800_rfcsr_write(rt2x00dev, 61, 0xd5);
6573 if (rt2x00_is_usb(rt2x00dev))
6574 rt2800_rfcsr_write(rt2x00dev, 61, 0xdd);
6576 rt2800_rfcsr_write(rt2x00dev, 61, 0xb5);
6578 rt2800_rfcsr_write(rt2x00dev, 62, 0x00);
6579 rt2800_rfcsr_write(rt2x00dev, 63, 0x00);
6581 rt2800_normal_mode_setup_5xxx(rt2x00dev);
6583 rt2800_led_open_drain_enable(rt2x00dev);
6586 static void rt2800_init_rfcsr_5392(struct rt2x00_dev *rt2x00dev)
6588 rt2800_rf_init_calibration(rt2x00dev, 2);
6590 rt2800_rfcsr_write(rt2x00dev, 1, 0x17);
6591 rt2800_rfcsr_write(rt2x00dev, 3, 0x88);
6592 rt2800_rfcsr_write(rt2x00dev, 5, 0x10);
6593 rt2800_rfcsr_write(rt2x00dev, 6, 0xe0);
6594 rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
6595 rt2800_rfcsr_write(rt2x00dev, 10, 0x53);
6596 rt2800_rfcsr_write(rt2x00dev, 11, 0x4a);
6597 rt2800_rfcsr_write(rt2x00dev, 12, 0x46);
6598 rt2800_rfcsr_write(rt2x00dev, 13, 0x9f);
6599 rt2800_rfcsr_write(rt2x00dev, 14, 0x00);
6600 rt2800_rfcsr_write(rt2x00dev, 15, 0x00);
6601 rt2800_rfcsr_write(rt2x00dev, 16, 0x00);
6602 rt2800_rfcsr_write(rt2x00dev, 18, 0x03);
6603 rt2800_rfcsr_write(rt2x00dev, 19, 0x4d);
6604 rt2800_rfcsr_write(rt2x00dev, 20, 0x00);
6605 rt2800_rfcsr_write(rt2x00dev, 21, 0x8d);
6606 rt2800_rfcsr_write(rt2x00dev, 22, 0x20);
6607 rt2800_rfcsr_write(rt2x00dev, 23, 0x0b);
6608 rt2800_rfcsr_write(rt2x00dev, 24, 0x44);
6609 rt2800_rfcsr_write(rt2x00dev, 25, 0x80);
6610 rt2800_rfcsr_write(rt2x00dev, 26, 0x82);
6611 rt2800_rfcsr_write(rt2x00dev, 27, 0x09);
6612 rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
6613 rt2800_rfcsr_write(rt2x00dev, 29, 0x10);
6614 rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
6615 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
6616 rt2800_rfcsr_write(rt2x00dev, 32, 0x20);
6617 rt2800_rfcsr_write(rt2x00dev, 33, 0xC0);
6618 rt2800_rfcsr_write(rt2x00dev, 34, 0x07);
6619 rt2800_rfcsr_write(rt2x00dev, 35, 0x12);
6620 rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
6621 rt2800_rfcsr_write(rt2x00dev, 37, 0x08);
6622 rt2800_rfcsr_write(rt2x00dev, 38, 0x89);
6623 rt2800_rfcsr_write(rt2x00dev, 39, 0x1b);
6624 rt2800_rfcsr_write(rt2x00dev, 40, 0x0f);
6625 rt2800_rfcsr_write(rt2x00dev, 41, 0xbb);
6626 rt2800_rfcsr_write(rt2x00dev, 42, 0xd5);
6627 rt2800_rfcsr_write(rt2x00dev, 43, 0x9b);
6628 rt2800_rfcsr_write(rt2x00dev, 44, 0x0e);
6629 rt2800_rfcsr_write(rt2x00dev, 45, 0xa2);
6630 rt2800_rfcsr_write(rt2x00dev, 46, 0x73);
6631 rt2800_rfcsr_write(rt2x00dev, 47, 0x0c);
6632 rt2800_rfcsr_write(rt2x00dev, 48, 0x10);
6633 rt2800_rfcsr_write(rt2x00dev, 49, 0x94);
6634 rt2800_rfcsr_write(rt2x00dev, 50, 0x94);
6635 rt2800_rfcsr_write(rt2x00dev, 51, 0x3a);
6636 rt2800_rfcsr_write(rt2x00dev, 52, 0x48);
6637 rt2800_rfcsr_write(rt2x00dev, 53, 0x44);
6638 rt2800_rfcsr_write(rt2x00dev, 54, 0x38);
6639 rt2800_rfcsr_write(rt2x00dev, 55, 0x43);
6640 rt2800_rfcsr_write(rt2x00dev, 56, 0xa1);
6641 rt2800_rfcsr_write(rt2x00dev, 57, 0x00);
6642 rt2800_rfcsr_write(rt2x00dev, 58, 0x39);
6643 rt2800_rfcsr_write(rt2x00dev, 59, 0x07);
6644 rt2800_rfcsr_write(rt2x00dev, 60, 0x45);
6645 rt2800_rfcsr_write(rt2x00dev, 61, 0x91);
6646 rt2800_rfcsr_write(rt2x00dev, 62, 0x39);
6647 rt2800_rfcsr_write(rt2x00dev, 63, 0x07);
6649 rt2800_normal_mode_setup_5xxx(rt2x00dev);
6651 rt2800_led_open_drain_enable(rt2x00dev);
6654 static void rt2800_init_rfcsr_5592(struct rt2x00_dev *rt2x00dev)
6656 rt2800_rf_init_calibration(rt2x00dev, 30);
6658 rt2800_rfcsr_write(rt2x00dev, 1, 0x3F);
6659 rt2800_rfcsr_write(rt2x00dev, 3, 0x08);
6660 rt2800_rfcsr_write(rt2x00dev, 5, 0x10);
6661 rt2800_rfcsr_write(rt2x00dev, 6, 0xE4);
6662 rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
6663 rt2800_rfcsr_write(rt2x00dev, 14, 0x00);
6664 rt2800_rfcsr_write(rt2x00dev, 15, 0x00);
6665 rt2800_rfcsr_write(rt2x00dev, 16, 0x00);
6666 rt2800_rfcsr_write(rt2x00dev, 18, 0x03);
6667 rt2800_rfcsr_write(rt2x00dev, 19, 0x4D);
6668 rt2800_rfcsr_write(rt2x00dev, 20, 0x10);
6669 rt2800_rfcsr_write(rt2x00dev, 21, 0x8D);
6670 rt2800_rfcsr_write(rt2x00dev, 26, 0x82);
6671 rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
6672 rt2800_rfcsr_write(rt2x00dev, 29, 0x10);
6673 rt2800_rfcsr_write(rt2x00dev, 33, 0xC0);
6674 rt2800_rfcsr_write(rt2x00dev, 34, 0x07);
6675 rt2800_rfcsr_write(rt2x00dev, 35, 0x12);
6676 rt2800_rfcsr_write(rt2x00dev, 47, 0x0C);
6677 rt2800_rfcsr_write(rt2x00dev, 53, 0x22);
6678 rt2800_rfcsr_write(rt2x00dev, 63, 0x07);
6680 rt2800_rfcsr_write(rt2x00dev, 2, 0x80);
6683 rt2800_freq_cal_mode1(rt2x00dev);
6685 /* Enable DC filter */
6686 if (rt2x00_rt_rev_gte(rt2x00dev, RT5592, REV_RT5592C))
6687 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
6689 rt2800_normal_mode_setup_5xxx(rt2x00dev);
6691 if (rt2x00_rt_rev_lt(rt2x00dev, RT5592, REV_RT5592C))
6692 rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
6694 rt2800_led_open_drain_enable(rt2x00dev);
6697 static void rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev)
6699 if (rt2800_is_305x_soc(rt2x00dev)) {
6700 rt2800_init_rfcsr_305x_soc(rt2x00dev);
6704 switch (rt2x00dev->chip.rt) {
6708 rt2800_init_rfcsr_30xx(rt2x00dev);
6711 rt2800_init_rfcsr_3290(rt2x00dev);
6714 rt2800_init_rfcsr_3352(rt2x00dev);
6717 rt2800_init_rfcsr_3390(rt2x00dev);
6720 rt2800_init_rfcsr_3572(rt2x00dev);
6723 rt2800_init_rfcsr_3593(rt2x00dev);
6726 rt2800_init_rfcsr_5390(rt2x00dev);
6729 rt2800_init_rfcsr_5392(rt2x00dev);
6732 rt2800_init_rfcsr_5592(rt2x00dev);
6737 int rt2800_enable_radio(struct rt2x00_dev *rt2x00dev)
6743 * Initialize MAC registers.
6745 if (unlikely(rt2800_wait_wpdma_ready(rt2x00dev) ||
6746 rt2800_init_registers(rt2x00dev)))
6750 * Wait BBP/RF to wake up.
6752 if (unlikely(rt2800_wait_bbp_rf_ready(rt2x00dev)))
6756 * Send signal during boot time to initialize firmware.
6758 rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
6759 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
6760 if (rt2x00_is_usb(rt2x00dev))
6761 rt2800_register_write(rt2x00dev, H2M_INT_SRC, 0);
6762 rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0, 0, 0);
6766 * Make sure BBP is up and running.
6768 if (unlikely(rt2800_wait_bbp_ready(rt2x00dev)))
6772 * Initialize BBP/RF registers.
6774 rt2800_init_bbp(rt2x00dev);
6775 rt2800_init_rfcsr(rt2x00dev);
6777 if (rt2x00_is_usb(rt2x00dev) &&
6778 (rt2x00_rt(rt2x00dev, RT3070) ||
6779 rt2x00_rt(rt2x00dev, RT3071) ||
6780 rt2x00_rt(rt2x00dev, RT3572))) {
6782 rt2800_mcu_request(rt2x00dev, MCU_CURRENT, 0, 0, 0);
6789 rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, ®);
6790 rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_TX, 1);
6791 rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, 0);
6792 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
6796 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®);
6797 rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 1);
6798 rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 1);
6799 rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
6800 rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
6802 rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, ®);
6803 rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_TX, 1);
6804 rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, 1);
6805 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
6808 * Initialize LED control
6810 rt2800_eeprom_read(rt2x00dev, EEPROM_LED_AG_CONF, &word);
6811 rt2800_mcu_request(rt2x00dev, MCU_LED_AG_CONF, 0xff,
6812 word & 0xff, (word >> 8) & 0xff);
6814 rt2800_eeprom_read(rt2x00dev, EEPROM_LED_ACT_CONF, &word);
6815 rt2800_mcu_request(rt2x00dev, MCU_LED_ACT_CONF, 0xff,
6816 word & 0xff, (word >> 8) & 0xff);
6818 rt2800_eeprom_read(rt2x00dev, EEPROM_LED_POLARITY, &word);
6819 rt2800_mcu_request(rt2x00dev, MCU_LED_LED_POLARITY, 0xff,
6820 word & 0xff, (word >> 8) & 0xff);
6824 EXPORT_SYMBOL_GPL(rt2800_enable_radio);
6826 void rt2800_disable_radio(struct rt2x00_dev *rt2x00dev)
6830 rt2800_disable_wpdma(rt2x00dev);
6832 /* Wait for DMA, ignore error */
6833 rt2800_wait_wpdma_ready(rt2x00dev);
6835 rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, ®);
6836 rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_TX, 0);
6837 rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, 0);
6838 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
6840 EXPORT_SYMBOL_GPL(rt2800_disable_radio);
6842 int rt2800_efuse_detect(struct rt2x00_dev *rt2x00dev)
6847 if (rt2x00_rt(rt2x00dev, RT3290))
6848 efuse_ctrl_reg = EFUSE_CTRL_3290;
6850 efuse_ctrl_reg = EFUSE_CTRL;
6852 rt2800_register_read(rt2x00dev, efuse_ctrl_reg, ®);
6853 return rt2x00_get_field32(reg, EFUSE_CTRL_PRESENT);
6855 EXPORT_SYMBOL_GPL(rt2800_efuse_detect);
6857 static void rt2800_efuse_read(struct rt2x00_dev *rt2x00dev, unsigned int i)
6861 u16 efuse_data0_reg;
6862 u16 efuse_data1_reg;
6863 u16 efuse_data2_reg;
6864 u16 efuse_data3_reg;
6866 if (rt2x00_rt(rt2x00dev, RT3290)) {
6867 efuse_ctrl_reg = EFUSE_CTRL_3290;
6868 efuse_data0_reg = EFUSE_DATA0_3290;
6869 efuse_data1_reg = EFUSE_DATA1_3290;
6870 efuse_data2_reg = EFUSE_DATA2_3290;
6871 efuse_data3_reg = EFUSE_DATA3_3290;
6873 efuse_ctrl_reg = EFUSE_CTRL;
6874 efuse_data0_reg = EFUSE_DATA0;
6875 efuse_data1_reg = EFUSE_DATA1;
6876 efuse_data2_reg = EFUSE_DATA2;
6877 efuse_data3_reg = EFUSE_DATA3;
6879 mutex_lock(&rt2x00dev->csr_mutex);
6881 rt2800_register_read_lock(rt2x00dev, efuse_ctrl_reg, ®);
6882 rt2x00_set_field32(®, EFUSE_CTRL_ADDRESS_IN, i);
6883 rt2x00_set_field32(®, EFUSE_CTRL_MODE, 0);
6884 rt2x00_set_field32(®, EFUSE_CTRL_KICK, 1);
6885 rt2800_register_write_lock(rt2x00dev, efuse_ctrl_reg, reg);
6887 /* Wait until the EEPROM has been loaded */
6888 rt2800_regbusy_read(rt2x00dev, efuse_ctrl_reg, EFUSE_CTRL_KICK, ®);
6889 /* Apparently the data is read from end to start */
6890 rt2800_register_read_lock(rt2x00dev, efuse_data3_reg, ®);
6891 /* The returned value is in CPU order, but eeprom is le */
6892 *(u32 *)&rt2x00dev->eeprom[i] = cpu_to_le32(reg);
6893 rt2800_register_read_lock(rt2x00dev, efuse_data2_reg, ®);
6894 *(u32 *)&rt2x00dev->eeprom[i + 2] = cpu_to_le32(reg);
6895 rt2800_register_read_lock(rt2x00dev, efuse_data1_reg, ®);
6896 *(u32 *)&rt2x00dev->eeprom[i + 4] = cpu_to_le32(reg);
6897 rt2800_register_read_lock(rt2x00dev, efuse_data0_reg, ®);
6898 *(u32 *)&rt2x00dev->eeprom[i + 6] = cpu_to_le32(reg);
6900 mutex_unlock(&rt2x00dev->csr_mutex);
6903 int rt2800_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev)
6907 for (i = 0; i < EEPROM_SIZE / sizeof(u16); i += 8)
6908 rt2800_efuse_read(rt2x00dev, i);
6912 EXPORT_SYMBOL_GPL(rt2800_read_eeprom_efuse);
6914 static u8 rt2800_get_txmixer_gain_24g(struct rt2x00_dev *rt2x00dev)
6918 if (rt2x00_rt(rt2x00dev, RT3593))
6921 rt2800_eeprom_read(rt2x00dev, EEPROM_TXMIXER_GAIN_BG, &word);
6922 if ((word & 0x00ff) != 0x00ff)
6923 return rt2x00_get_field16(word, EEPROM_TXMIXER_GAIN_BG_VAL);
6928 static u8 rt2800_get_txmixer_gain_5g(struct rt2x00_dev *rt2x00dev)
6932 if (rt2x00_rt(rt2x00dev, RT3593))
6935 rt2800_eeprom_read(rt2x00dev, EEPROM_TXMIXER_GAIN_A, &word);
6936 if ((word & 0x00ff) != 0x00ff)
6937 return rt2x00_get_field16(word, EEPROM_TXMIXER_GAIN_A_VAL);
6942 static int rt2800_validate_eeprom(struct rt2x00_dev *rt2x00dev)
6944 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
6947 u8 default_lna_gain;
6953 retval = rt2800_read_eeprom(rt2x00dev);
6958 * Start validation of the data that has been read.
6960 mac = rt2800_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
6961 rt2x00lib_set_mac_address(rt2x00dev, mac);
6963 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &word);
6964 if (word == 0xffff) {
6965 rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RXPATH, 2);
6966 rt2x00_set_field16(&word, EEPROM_NIC_CONF0_TXPATH, 1);
6967 rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RF_TYPE, RF2820);
6968 rt2800_eeprom_write(rt2x00dev, EEPROM_NIC_CONF0, word);
6969 rt2x00_eeprom_dbg(rt2x00dev, "Antenna: 0x%04x\n", word);
6970 } else if (rt2x00_rt(rt2x00dev, RT2860) ||
6971 rt2x00_rt(rt2x00dev, RT2872)) {
6973 * There is a max of 2 RX streams for RT28x0 series
6975 if (rt2x00_get_field16(word, EEPROM_NIC_CONF0_RXPATH) > 2)
6976 rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RXPATH, 2);
6977 rt2800_eeprom_write(rt2x00dev, EEPROM_NIC_CONF0, word);
6980 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &word);
6981 if (word == 0xffff) {
6982 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_HW_RADIO, 0);
6983 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_TX_ALC, 0);
6984 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_LNA_2G, 0);
6985 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_LNA_5G, 0);
6986 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_CARDBUS_ACCEL, 0);
6987 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_SB_2G, 0);
6988 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_SB_5G, 0);
6989 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_WPS_PBC, 0);
6990 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_2G, 0);
6991 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_5G, 0);
6992 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BROADBAND_EXT_LNA, 0);
6993 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_ANT_DIVERSITY, 0);
6994 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_INTERNAL_TX_ALC, 0);
6995 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BT_COEXIST, 0);
6996 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_DAC_TEST, 0);
6997 rt2800_eeprom_write(rt2x00dev, EEPROM_NIC_CONF1, word);
6998 rt2x00_eeprom_dbg(rt2x00dev, "NIC: 0x%04x\n", word);
7001 rt2800_eeprom_read(rt2x00dev, EEPROM_FREQ, &word);
7002 if ((word & 0x00ff) == 0x00ff) {
7003 rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0);
7004 rt2800_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
7005 rt2x00_eeprom_dbg(rt2x00dev, "Freq: 0x%04x\n", word);
7007 if ((word & 0xff00) == 0xff00) {
7008 rt2x00_set_field16(&word, EEPROM_FREQ_LED_MODE,
7009 LED_MODE_TXRX_ACTIVITY);
7010 rt2x00_set_field16(&word, EEPROM_FREQ_LED_POLARITY, 0);
7011 rt2800_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
7012 rt2800_eeprom_write(rt2x00dev, EEPROM_LED_AG_CONF, 0x5555);
7013 rt2800_eeprom_write(rt2x00dev, EEPROM_LED_ACT_CONF, 0x2221);
7014 rt2800_eeprom_write(rt2x00dev, EEPROM_LED_POLARITY, 0xa9f8);
7015 rt2x00_eeprom_dbg(rt2x00dev, "Led Mode: 0x%04x\n", word);
7019 * During the LNA validation we are going to use
7020 * lna0 as correct value. Note that EEPROM_LNA
7021 * is never validated.
7023 rt2800_eeprom_read(rt2x00dev, EEPROM_LNA, &word);
7024 default_lna_gain = rt2x00_get_field16(word, EEPROM_LNA_A0);
7026 rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &word);
7027 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET0)) > 10)
7028 rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET0, 0);
7029 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET1)) > 10)
7030 rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET1, 0);
7031 rt2800_eeprom_write(rt2x00dev, EEPROM_RSSI_BG, word);
7033 drv_data->txmixer_gain_24g = rt2800_get_txmixer_gain_24g(rt2x00dev);
7035 rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &word);
7036 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG2_OFFSET2)) > 10)
7037 rt2x00_set_field16(&word, EEPROM_RSSI_BG2_OFFSET2, 0);
7038 if (!rt2x00_rt(rt2x00dev, RT3593)) {
7039 if (rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0x00 ||
7040 rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0xff)
7041 rt2x00_set_field16(&word, EEPROM_RSSI_BG2_LNA_A1,
7044 rt2800_eeprom_write(rt2x00dev, EEPROM_RSSI_BG2, word);
7046 drv_data->txmixer_gain_5g = rt2800_get_txmixer_gain_5g(rt2x00dev);
7048 rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &word);
7049 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET0)) > 10)
7050 rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET0, 0);
7051 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET1)) > 10)
7052 rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET1, 0);
7053 rt2800_eeprom_write(rt2x00dev, EEPROM_RSSI_A, word);
7055 rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &word);
7056 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A2_OFFSET2)) > 10)
7057 rt2x00_set_field16(&word, EEPROM_RSSI_A2_OFFSET2, 0);
7058 if (!rt2x00_rt(rt2x00dev, RT3593)) {
7059 if (rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0x00 ||
7060 rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0xff)
7061 rt2x00_set_field16(&word, EEPROM_RSSI_A2_LNA_A2,
7064 rt2800_eeprom_write(rt2x00dev, EEPROM_RSSI_A2, word);
7066 if (rt2x00_rt(rt2x00dev, RT3593)) {
7067 rt2800_eeprom_read(rt2x00dev, EEPROM_EXT_LNA2, &word);
7068 if (rt2x00_get_field16(word, EEPROM_EXT_LNA2_A1) == 0x00 ||
7069 rt2x00_get_field16(word, EEPROM_EXT_LNA2_A1) == 0xff)
7070 rt2x00_set_field16(&word, EEPROM_EXT_LNA2_A1,
7072 if (rt2x00_get_field16(word, EEPROM_EXT_LNA2_A2) == 0x00 ||
7073 rt2x00_get_field16(word, EEPROM_EXT_LNA2_A2) == 0xff)
7074 rt2x00_set_field16(&word, EEPROM_EXT_LNA2_A1,
7076 rt2800_eeprom_write(rt2x00dev, EEPROM_EXT_LNA2, word);
7082 static int rt2800_init_eeprom(struct rt2x00_dev *rt2x00dev)
7089 * Read EEPROM word for configuration.
7091 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom);
7094 * Identify RF chipset by EEPROM value
7095 * RT28xx/RT30xx: defined in "EEPROM_NIC_CONF0_RF_TYPE" field
7096 * RT53xx: defined in "EEPROM_CHIP_ID" field
7098 if (rt2x00_rt(rt2x00dev, RT3290) ||
7099 rt2x00_rt(rt2x00dev, RT5390) ||
7100 rt2x00_rt(rt2x00dev, RT5392))
7101 rt2800_eeprom_read(rt2x00dev, EEPROM_CHIP_ID, &rf);
7103 rf = rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RF_TYPE);
7129 rt2x00_err(rt2x00dev, "Invalid RF chipset 0x%04x detected\n",
7134 rt2x00_set_rf(rt2x00dev, rf);
7137 * Identify default antenna configuration.
7139 rt2x00dev->default_ant.tx_chain_num =
7140 rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH);
7141 rt2x00dev->default_ant.rx_chain_num =
7142 rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH);
7144 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
7146 if (rt2x00_rt(rt2x00dev, RT3070) ||
7147 rt2x00_rt(rt2x00dev, RT3090) ||
7148 rt2x00_rt(rt2x00dev, RT3352) ||
7149 rt2x00_rt(rt2x00dev, RT3390)) {
7150 value = rt2x00_get_field16(eeprom,
7151 EEPROM_NIC_CONF1_ANT_DIVERSITY);
7156 rt2x00dev->default_ant.tx = ANTENNA_A;
7157 rt2x00dev->default_ant.rx = ANTENNA_A;
7160 rt2x00dev->default_ant.tx = ANTENNA_A;
7161 rt2x00dev->default_ant.rx = ANTENNA_B;
7165 rt2x00dev->default_ant.tx = ANTENNA_A;
7166 rt2x00dev->default_ant.rx = ANTENNA_A;
7169 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390R)) {
7170 rt2x00dev->default_ant.tx = ANTENNA_HW_DIVERSITY; /* Unused */
7171 rt2x00dev->default_ant.rx = ANTENNA_HW_DIVERSITY; /* Unused */
7175 * Determine external LNA informations.
7177 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_EXTERNAL_LNA_5G))
7178 __set_bit(CAPABILITY_EXTERNAL_LNA_A, &rt2x00dev->cap_flags);
7179 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_EXTERNAL_LNA_2G))
7180 __set_bit(CAPABILITY_EXTERNAL_LNA_BG, &rt2x00dev->cap_flags);
7183 * Detect if this device has an hardware controlled radio.
7185 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_HW_RADIO))
7186 __set_bit(CAPABILITY_HW_BUTTON, &rt2x00dev->cap_flags);
7189 * Detect if this device has Bluetooth co-existence.
7191 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_BT_COEXIST))
7192 __set_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags);
7195 * Read frequency offset and RF programming sequence.
7197 rt2800_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
7198 rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET);
7201 * Store led settings, for correct led behaviour.
7203 #ifdef CONFIG_RT2X00_LIB_LEDS
7204 rt2800_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
7205 rt2800_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
7206 rt2800_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY);
7208 rt2x00dev->led_mcu_reg = eeprom;
7209 #endif /* CONFIG_RT2X00_LIB_LEDS */
7212 * Check if support EIRP tx power limit feature.
7214 rt2800_eeprom_read(rt2x00dev, EEPROM_EIRP_MAX_TX_POWER, &eeprom);
7216 if (rt2x00_get_field16(eeprom, EEPROM_EIRP_MAX_TX_POWER_2GHZ) <
7217 EIRP_MAX_TX_POWER_LIMIT)
7218 __set_bit(CAPABILITY_POWER_LIMIT, &rt2x00dev->cap_flags);
7224 * RF value list for rt28xx
7225 * Supports: 2.4 GHz (all) & 5.2 GHz (RF2850 & RF2750)
7227 static const struct rf_channel rf_vals[] = {
7228 { 1, 0x18402ecc, 0x184c0786, 0x1816b455, 0x1800510b },
7229 { 2, 0x18402ecc, 0x184c0786, 0x18168a55, 0x1800519f },
7230 { 3, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800518b },
7231 { 4, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800519f },
7232 { 5, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800518b },
7233 { 6, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800519f },
7234 { 7, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800518b },
7235 { 8, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800519f },
7236 { 9, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800518b },
7237 { 10, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800519f },
7238 { 11, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800518b },
7239 { 12, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800519f },
7240 { 13, 0x18402ecc, 0x184c079e, 0x18168a55, 0x1800518b },
7241 { 14, 0x18402ecc, 0x184c07a2, 0x18168a55, 0x18005193 },
7243 /* 802.11 UNI / HyperLan 2 */
7244 { 36, 0x18402ecc, 0x184c099a, 0x18158a55, 0x180ed1a3 },
7245 { 38, 0x18402ecc, 0x184c099e, 0x18158a55, 0x180ed193 },
7246 { 40, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed183 },
7247 { 44, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed1a3 },
7248 { 46, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed18b },
7249 { 48, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed19b },
7250 { 52, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed193 },
7251 { 54, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed1a3 },
7252 { 56, 0x18402ec8, 0x184c068e, 0x18158a55, 0x180ed18b },
7253 { 60, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed183 },
7254 { 62, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed193 },
7255 { 64, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed1a3 },
7257 /* 802.11 HyperLan 2 */
7258 { 100, 0x18402ec8, 0x184c06b2, 0x18178a55, 0x180ed783 },
7259 { 102, 0x18402ec8, 0x184c06b2, 0x18578a55, 0x180ed793 },
7260 { 104, 0x18402ec8, 0x185c06b2, 0x18578a55, 0x180ed1a3 },
7261 { 108, 0x18402ecc, 0x185c0a32, 0x18578a55, 0x180ed193 },
7262 { 110, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed183 },
7263 { 112, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed19b },
7264 { 116, 0x18402ecc, 0x184c0a3a, 0x18178a55, 0x180ed1a3 },
7265 { 118, 0x18402ecc, 0x184c0a3e, 0x18178a55, 0x180ed193 },
7266 { 120, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed183 },
7267 { 124, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed193 },
7268 { 126, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed15b },
7269 { 128, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed1a3 },
7270 { 132, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed18b },
7271 { 134, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed193 },
7272 { 136, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed19b },
7273 { 140, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed183 },
7276 { 149, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed1a7 },
7277 { 151, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed187 },
7278 { 153, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed18f },
7279 { 157, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed19f },
7280 { 159, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed1a7 },
7281 { 161, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed187 },
7282 { 165, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed197 },
7283 { 167, 0x18402ec4, 0x184c03d2, 0x18179855, 0x1815531f },
7284 { 169, 0x18402ec4, 0x184c03d2, 0x18179855, 0x18155327 },
7285 { 171, 0x18402ec4, 0x184c03d6, 0x18179855, 0x18155307 },
7286 { 173, 0x18402ec4, 0x184c03d6, 0x18179855, 0x1815530f },
7289 { 184, 0x15002ccc, 0x1500491e, 0x1509be55, 0x150c0a0b },
7290 { 188, 0x15002ccc, 0x15004922, 0x1509be55, 0x150c0a13 },
7291 { 192, 0x15002ccc, 0x15004926, 0x1509be55, 0x150c0a1b },
7292 { 196, 0x15002ccc, 0x1500492a, 0x1509be55, 0x150c0a23 },
7293 { 208, 0x15002ccc, 0x1500493a, 0x1509be55, 0x150c0a13 },
7294 { 212, 0x15002ccc, 0x1500493e, 0x1509be55, 0x150c0a1b },
7295 { 216, 0x15002ccc, 0x15004982, 0x1509be55, 0x150c0a23 },
7299 * RF value list for rt3xxx
7300 * Supports: 2.4 GHz (all) & 5.2 GHz (RF3052 & RF3053)
7302 static const struct rf_channel rf_vals_3x[] = {
7318 /* 802.11 UNI / HyperLan 2 */
7332 /* 802.11 HyperLan 2 */
7364 static const struct rf_channel rf_vals_5592_xtal20[] = {
7365 /* Channel, N, K, mod, R */
7375 {10, 491, 4, 10, 3},
7376 {11, 492, 4, 10, 3},
7377 {12, 493, 4, 10, 3},
7378 {13, 494, 4, 10, 3},
7379 {14, 496, 8, 10, 3},
7380 {36, 172, 8, 12, 1},
7381 {38, 173, 0, 12, 1},
7382 {40, 173, 4, 12, 1},
7383 {42, 173, 8, 12, 1},
7384 {44, 174, 0, 12, 1},
7385 {46, 174, 4, 12, 1},
7386 {48, 174, 8, 12, 1},
7387 {50, 175, 0, 12, 1},
7388 {52, 175, 4, 12, 1},
7389 {54, 175, 8, 12, 1},
7390 {56, 176, 0, 12, 1},
7391 {58, 176, 4, 12, 1},
7392 {60, 176, 8, 12, 1},
7393 {62, 177, 0, 12, 1},
7394 {64, 177, 4, 12, 1},
7395 {100, 183, 4, 12, 1},
7396 {102, 183, 8, 12, 1},
7397 {104, 184, 0, 12, 1},
7398 {106, 184, 4, 12, 1},
7399 {108, 184, 8, 12, 1},
7400 {110, 185, 0, 12, 1},
7401 {112, 185, 4, 12, 1},
7402 {114, 185, 8, 12, 1},
7403 {116, 186, 0, 12, 1},
7404 {118, 186, 4, 12, 1},
7405 {120, 186, 8, 12, 1},
7406 {122, 187, 0, 12, 1},
7407 {124, 187, 4, 12, 1},
7408 {126, 187, 8, 12, 1},
7409 {128, 188, 0, 12, 1},
7410 {130, 188, 4, 12, 1},
7411 {132, 188, 8, 12, 1},
7412 {134, 189, 0, 12, 1},
7413 {136, 189, 4, 12, 1},
7414 {138, 189, 8, 12, 1},
7415 {140, 190, 0, 12, 1},
7416 {149, 191, 6, 12, 1},
7417 {151, 191, 10, 12, 1},
7418 {153, 192, 2, 12, 1},
7419 {155, 192, 6, 12, 1},
7420 {157, 192, 10, 12, 1},
7421 {159, 193, 2, 12, 1},
7422 {161, 193, 6, 12, 1},
7423 {165, 194, 2, 12, 1},
7424 {184, 164, 0, 12, 1},
7425 {188, 164, 4, 12, 1},
7426 {192, 165, 8, 12, 1},
7427 {196, 166, 0, 12, 1},
7430 static const struct rf_channel rf_vals_5592_xtal40[] = {
7431 /* Channel, N, K, mod, R */
7441 {10, 245, 7, 10, 3},
7442 {11, 246, 2, 10, 3},
7443 {12, 246, 7, 10, 3},
7444 {13, 247, 2, 10, 3},
7445 {14, 248, 4, 10, 3},
7449 {42, 86, 10, 12, 1},
7455 {54, 87, 10, 12, 1},
7461 {100, 91, 8, 12, 1},
7462 {102, 91, 10, 12, 1},
7463 {104, 92, 0, 12, 1},
7464 {106, 92, 2, 12, 1},
7465 {108, 92, 4, 12, 1},
7466 {110, 92, 6, 12, 1},
7467 {112, 92, 8, 12, 1},
7468 {114, 92, 10, 12, 1},
7469 {116, 93, 0, 12, 1},
7470 {118, 93, 2, 12, 1},
7471 {120, 93, 4, 12, 1},
7472 {122, 93, 6, 12, 1},
7473 {124, 93, 8, 12, 1},
7474 {126, 93, 10, 12, 1},
7475 {128, 94, 0, 12, 1},
7476 {130, 94, 2, 12, 1},
7477 {132, 94, 4, 12, 1},
7478 {134, 94, 6, 12, 1},
7479 {136, 94, 8, 12, 1},
7480 {138, 94, 10, 12, 1},
7481 {140, 95, 0, 12, 1},
7482 {149, 95, 9, 12, 1},
7483 {151, 95, 11, 12, 1},
7484 {153, 96, 1, 12, 1},
7485 {155, 96, 3, 12, 1},
7486 {157, 96, 5, 12, 1},
7487 {159, 96, 7, 12, 1},
7488 {161, 96, 9, 12, 1},
7489 {165, 97, 1, 12, 1},
7490 {184, 82, 0, 12, 1},
7491 {188, 82, 4, 12, 1},
7492 {192, 82, 8, 12, 1},
7493 {196, 83, 0, 12, 1},
7496 static int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
7498 struct hw_mode_spec *spec = &rt2x00dev->spec;
7499 struct channel_info *info;
7500 char *default_power1;
7501 char *default_power2;
7502 char *default_power3;
7503 unsigned int i, tx_chains, rx_chains;
7507 * Disable powersaving as default.
7509 rt2x00dev->hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
7512 * Initialize all hw fields.
7514 ieee80211_hw_set(rt2x00dev->hw, REPORTS_TX_ACK_STATUS);
7515 ieee80211_hw_set(rt2x00dev->hw, AMPDU_AGGREGATION);
7516 ieee80211_hw_set(rt2x00dev->hw, PS_NULLFUNC_STACK);
7517 ieee80211_hw_set(rt2x00dev->hw, SIGNAL_DBM);
7518 ieee80211_hw_set(rt2x00dev->hw, SUPPORTS_PS);
7521 * Don't set IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING for USB devices
7522 * unless we are capable of sending the buffered frames out after the
7523 * DTIM transmission using rt2x00lib_beacondone. This will send out
7524 * multicast and broadcast traffic immediately instead of buffering it
7525 * infinitly and thus dropping it after some time.
7527 if (!rt2x00_is_usb(rt2x00dev))
7528 ieee80211_hw_set(rt2x00dev->hw, HOST_BROADCAST_PS_BUFFERING);
7530 /* Set MFP if HW crypto is disabled. */
7531 if (rt2800_hwcrypt_disabled(rt2x00dev))
7532 ieee80211_hw_set(rt2x00dev->hw, MFP_CAPABLE);
7534 SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
7535 SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
7536 rt2800_eeprom_addr(rt2x00dev,
7537 EEPROM_MAC_ADDR_0));
7540 * As rt2800 has a global fallback table we cannot specify
7541 * more then one tx rate per frame but since the hw will
7542 * try several rates (based on the fallback table) we should
7543 * initialize max_report_rates to the maximum number of rates
7544 * we are going to try. Otherwise mac80211 will truncate our
7545 * reported tx rates and the rc algortihm will end up with
7548 rt2x00dev->hw->max_rates = 1;
7549 rt2x00dev->hw->max_report_rates = 7;
7550 rt2x00dev->hw->max_rate_tries = 1;
7553 * Initialize hw_mode information.
7555 spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
7557 switch (rt2x00dev->chip.rf) {
7560 spec->num_channels = 14;
7561 spec->channels = rf_vals;
7566 spec->num_channels = ARRAY_SIZE(rf_vals);
7567 spec->channels = rf_vals;
7584 spec->num_channels = 14;
7585 spec->channels = rf_vals_3x;
7590 spec->num_channels = ARRAY_SIZE(rf_vals_3x);
7591 spec->channels = rf_vals_3x;
7595 rt2800_register_read(rt2x00dev, MAC_DEBUG_INDEX, ®);
7596 if (rt2x00_get_field32(reg, MAC_DEBUG_INDEX_XTAL)) {
7597 spec->num_channels = ARRAY_SIZE(rf_vals_5592_xtal40);
7598 spec->channels = rf_vals_5592_xtal40;
7600 spec->num_channels = ARRAY_SIZE(rf_vals_5592_xtal20);
7601 spec->channels = rf_vals_5592_xtal20;
7606 if (WARN_ON_ONCE(!spec->channels))
7609 spec->supported_bands = SUPPORT_BAND_2GHZ;
7610 if (spec->num_channels > 14)
7611 spec->supported_bands |= SUPPORT_BAND_5GHZ;
7614 * Initialize HT information.
7616 if (!rt2x00_rf(rt2x00dev, RF2020))
7617 spec->ht.ht_supported = true;
7619 spec->ht.ht_supported = false;
7622 IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
7623 IEEE80211_HT_CAP_GRN_FLD |
7624 IEEE80211_HT_CAP_SGI_20 |
7625 IEEE80211_HT_CAP_SGI_40;
7627 tx_chains = rt2x00dev->default_ant.tx_chain_num;
7628 rx_chains = rt2x00dev->default_ant.rx_chain_num;
7631 spec->ht.cap |= IEEE80211_HT_CAP_TX_STBC;
7633 spec->ht.cap |= rx_chains << IEEE80211_HT_CAP_RX_STBC_SHIFT;
7635 spec->ht.ampdu_factor = (rx_chains > 1) ? 3 : 2;
7636 spec->ht.ampdu_density = 4;
7637 spec->ht.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
7638 if (tx_chains != rx_chains) {
7639 spec->ht.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
7640 spec->ht.mcs.tx_params |=
7641 (tx_chains - 1) << IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
7644 switch (rx_chains) {
7646 spec->ht.mcs.rx_mask[2] = 0xff;
7648 spec->ht.mcs.rx_mask[1] = 0xff;
7650 spec->ht.mcs.rx_mask[0] = 0xff;
7651 spec->ht.mcs.rx_mask[4] = 0x1; /* MCS32 */
7656 * Create channel information array
7658 info = kcalloc(spec->num_channels, sizeof(*info), GFP_KERNEL);
7662 spec->channels_info = info;
7664 default_power1 = rt2800_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG1);
7665 default_power2 = rt2800_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG2);
7667 if (rt2x00dev->default_ant.tx_chain_num > 2)
7668 default_power3 = rt2800_eeprom_addr(rt2x00dev,
7669 EEPROM_EXT_TXPOWER_BG3);
7671 default_power3 = NULL;
7673 for (i = 0; i < 14; i++) {
7674 info[i].default_power1 = default_power1[i];
7675 info[i].default_power2 = default_power2[i];
7677 info[i].default_power3 = default_power3[i];
7680 if (spec->num_channels > 14) {
7681 default_power1 = rt2800_eeprom_addr(rt2x00dev,
7683 default_power2 = rt2800_eeprom_addr(rt2x00dev,
7686 if (rt2x00dev->default_ant.tx_chain_num > 2)
7688 rt2800_eeprom_addr(rt2x00dev,
7689 EEPROM_EXT_TXPOWER_A3);
7691 default_power3 = NULL;
7693 for (i = 14; i < spec->num_channels; i++) {
7694 info[i].default_power1 = default_power1[i - 14];
7695 info[i].default_power2 = default_power2[i - 14];
7697 info[i].default_power3 = default_power3[i - 14];
7701 switch (rt2x00dev->chip.rf) {
7717 __set_bit(CAPABILITY_VCO_RECALIBRATION, &rt2x00dev->cap_flags);
7724 static int rt2800_probe_rt(struct rt2x00_dev *rt2x00dev)
7730 if (rt2x00_rt(rt2x00dev, RT3290))
7731 rt2800_register_read(rt2x00dev, MAC_CSR0_3290, ®);
7733 rt2800_register_read(rt2x00dev, MAC_CSR0, ®);
7735 rt = rt2x00_get_field32(reg, MAC_CSR0_CHIPSET);
7736 rev = rt2x00_get_field32(reg, MAC_CSR0_REVISION);
7755 rt2x00_err(rt2x00dev, "Invalid RT chipset 0x%04x, rev %04x detected\n",
7760 rt2x00_set_rt(rt2x00dev, rt, rev);
7765 int rt2800_probe_hw(struct rt2x00_dev *rt2x00dev)
7770 retval = rt2800_probe_rt(rt2x00dev);
7775 * Allocate eeprom data.
7777 retval = rt2800_validate_eeprom(rt2x00dev);
7781 retval = rt2800_init_eeprom(rt2x00dev);
7786 * Enable rfkill polling by setting GPIO direction of the
7787 * rfkill switch GPIO pin correctly.
7789 rt2800_register_read(rt2x00dev, GPIO_CTRL, ®);
7790 rt2x00_set_field32(®, GPIO_CTRL_DIR2, 1);
7791 rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
7794 * Initialize hw specifications.
7796 retval = rt2800_probe_hw_mode(rt2x00dev);
7801 * Set device capabilities.
7803 __set_bit(CAPABILITY_CONTROL_FILTERS, &rt2x00dev->cap_flags);
7804 __set_bit(CAPABILITY_CONTROL_FILTER_PSPOLL, &rt2x00dev->cap_flags);
7805 if (!rt2x00_is_usb(rt2x00dev))
7806 __set_bit(CAPABILITY_PRE_TBTT_INTERRUPT, &rt2x00dev->cap_flags);
7809 * Set device requirements.
7811 if (!rt2x00_is_soc(rt2x00dev))
7812 __set_bit(REQUIRE_FIRMWARE, &rt2x00dev->cap_flags);
7813 __set_bit(REQUIRE_L2PAD, &rt2x00dev->cap_flags);
7814 __set_bit(REQUIRE_TXSTATUS_FIFO, &rt2x00dev->cap_flags);
7815 if (!rt2800_hwcrypt_disabled(rt2x00dev))
7816 __set_bit(CAPABILITY_HW_CRYPTO, &rt2x00dev->cap_flags);
7817 __set_bit(CAPABILITY_LINK_TUNING, &rt2x00dev->cap_flags);
7818 __set_bit(REQUIRE_HT_TX_DESC, &rt2x00dev->cap_flags);
7819 if (rt2x00_is_usb(rt2x00dev))
7820 __set_bit(REQUIRE_PS_AUTOWAKE, &rt2x00dev->cap_flags);
7822 __set_bit(REQUIRE_DMA, &rt2x00dev->cap_flags);
7823 __set_bit(REQUIRE_TASKLET_CONTEXT, &rt2x00dev->cap_flags);
7827 * Set the rssi offset.
7829 rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
7833 EXPORT_SYMBOL_GPL(rt2800_probe_hw);
7836 * IEEE80211 stack callback functions.
7838 void rt2800_get_key_seq(struct ieee80211_hw *hw,
7839 struct ieee80211_key_conf *key,
7840 struct ieee80211_key_seq *seq)
7842 struct rt2x00_dev *rt2x00dev = hw->priv;
7843 struct mac_iveiv_entry iveiv_entry;
7846 if (key->cipher != WLAN_CIPHER_SUITE_TKIP)
7849 offset = MAC_IVEIV_ENTRY(key->hw_key_idx);
7850 rt2800_register_multiread(rt2x00dev, offset,
7851 &iveiv_entry, sizeof(iveiv_entry));
7853 memcpy(&seq->tkip.iv16, &iveiv_entry.iv[0], 2);
7854 memcpy(&seq->tkip.iv32, &iveiv_entry.iv[4], 4);
7856 EXPORT_SYMBOL_GPL(rt2800_get_key_seq);
7858 int rt2800_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
7860 struct rt2x00_dev *rt2x00dev = hw->priv;
7862 bool enabled = (value < IEEE80211_MAX_RTS_THRESHOLD);
7864 rt2800_register_read(rt2x00dev, TX_RTS_CFG, ®);
7865 rt2x00_set_field32(®, TX_RTS_CFG_RTS_THRES, value);
7866 rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg);
7868 rt2800_register_read(rt2x00dev, CCK_PROT_CFG, ®);
7869 rt2x00_set_field32(®, CCK_PROT_CFG_RTS_TH_EN, enabled);
7870 rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg);
7872 rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, ®);
7873 rt2x00_set_field32(®, OFDM_PROT_CFG_RTS_TH_EN, enabled);
7874 rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
7876 rt2800_register_read(rt2x00dev, MM20_PROT_CFG, ®);
7877 rt2x00_set_field32(®, MM20_PROT_CFG_RTS_TH_EN, enabled);
7878 rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
7880 rt2800_register_read(rt2x00dev, MM40_PROT_CFG, ®);
7881 rt2x00_set_field32(®, MM40_PROT_CFG_RTS_TH_EN, enabled);
7882 rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
7884 rt2800_register_read(rt2x00dev, GF20_PROT_CFG, ®);
7885 rt2x00_set_field32(®, GF20_PROT_CFG_RTS_TH_EN, enabled);
7886 rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
7888 rt2800_register_read(rt2x00dev, GF40_PROT_CFG, ®);
7889 rt2x00_set_field32(®, GF40_PROT_CFG_RTS_TH_EN, enabled);
7890 rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
7894 EXPORT_SYMBOL_GPL(rt2800_set_rts_threshold);
7896 int rt2800_conf_tx(struct ieee80211_hw *hw,
7897 struct ieee80211_vif *vif, u16 queue_idx,
7898 const struct ieee80211_tx_queue_params *params)
7900 struct rt2x00_dev *rt2x00dev = hw->priv;
7901 struct data_queue *queue;
7902 struct rt2x00_field32 field;
7908 * First pass the configuration through rt2x00lib, that will
7909 * update the queue settings and validate the input. After that
7910 * we are free to update the registers based on the value
7911 * in the queue parameter.
7913 retval = rt2x00mac_conf_tx(hw, vif, queue_idx, params);
7918 * We only need to perform additional register initialization
7924 queue = rt2x00queue_get_tx_queue(rt2x00dev, queue_idx);
7926 /* Update WMM TXOP register */
7927 offset = WMM_TXOP0_CFG + (sizeof(u32) * (!!(queue_idx & 2)));
7928 field.bit_offset = (queue_idx & 1) * 16;
7929 field.bit_mask = 0xffff << field.bit_offset;
7931 rt2800_register_read(rt2x00dev, offset, ®);
7932 rt2x00_set_field32(®, field, queue->txop);
7933 rt2800_register_write(rt2x00dev, offset, reg);
7935 /* Update WMM registers */
7936 field.bit_offset = queue_idx * 4;
7937 field.bit_mask = 0xf << field.bit_offset;
7939 rt2800_register_read(rt2x00dev, WMM_AIFSN_CFG, ®);
7940 rt2x00_set_field32(®, field, queue->aifs);
7941 rt2800_register_write(rt2x00dev, WMM_AIFSN_CFG, reg);
7943 rt2800_register_read(rt2x00dev, WMM_CWMIN_CFG, ®);
7944 rt2x00_set_field32(®, field, queue->cw_min);
7945 rt2800_register_write(rt2x00dev, WMM_CWMIN_CFG, reg);
7947 rt2800_register_read(rt2x00dev, WMM_CWMAX_CFG, ®);
7948 rt2x00_set_field32(®, field, queue->cw_max);
7949 rt2800_register_write(rt2x00dev, WMM_CWMAX_CFG, reg);
7951 /* Update EDCA registers */
7952 offset = EDCA_AC0_CFG + (sizeof(u32) * queue_idx);
7954 rt2800_register_read(rt2x00dev, offset, ®);
7955 rt2x00_set_field32(®, EDCA_AC0_CFG_TX_OP, queue->txop);
7956 rt2x00_set_field32(®, EDCA_AC0_CFG_AIFSN, queue->aifs);
7957 rt2x00_set_field32(®, EDCA_AC0_CFG_CWMIN, queue->cw_min);
7958 rt2x00_set_field32(®, EDCA_AC0_CFG_CWMAX, queue->cw_max);
7959 rt2800_register_write(rt2x00dev, offset, reg);
7963 EXPORT_SYMBOL_GPL(rt2800_conf_tx);
7965 u64 rt2800_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
7967 struct rt2x00_dev *rt2x00dev = hw->priv;
7971 rt2800_register_read(rt2x00dev, TSF_TIMER_DW1, ®);
7972 tsf = (u64) rt2x00_get_field32(reg, TSF_TIMER_DW1_HIGH_WORD) << 32;
7973 rt2800_register_read(rt2x00dev, TSF_TIMER_DW0, ®);
7974 tsf |= rt2x00_get_field32(reg, TSF_TIMER_DW0_LOW_WORD);
7978 EXPORT_SYMBOL_GPL(rt2800_get_tsf);
7980 int rt2800_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
7981 struct ieee80211_ampdu_params *params)
7983 struct ieee80211_sta *sta = params->sta;
7984 enum ieee80211_ampdu_mlme_action action = params->action;
7985 u16 tid = params->tid;
7986 struct rt2x00_sta *sta_priv = (struct rt2x00_sta *)sta->drv_priv;
7990 * Don't allow aggregation for stations the hardware isn't aware
7991 * of because tx status reports for frames to an unknown station
7992 * always contain wcid=WCID_END+1 and thus we can't distinguish
7993 * between multiple stations which leads to unwanted situations
7994 * when the hw reorders frames due to aggregation.
7996 if (sta_priv->wcid > WCID_END)
8000 case IEEE80211_AMPDU_RX_START:
8001 case IEEE80211_AMPDU_RX_STOP:
8003 * The hw itself takes care of setting up BlockAck mechanisms.
8004 * So, we only have to allow mac80211 to nagotiate a BlockAck
8005 * agreement. Once that is done, the hw will BlockAck incoming
8006 * AMPDUs without further setup.
8009 case IEEE80211_AMPDU_TX_START:
8010 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
8012 case IEEE80211_AMPDU_TX_STOP_CONT:
8013 case IEEE80211_AMPDU_TX_STOP_FLUSH:
8014 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
8015 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
8017 case IEEE80211_AMPDU_TX_OPERATIONAL:
8020 rt2x00_warn((struct rt2x00_dev *)hw->priv,
8021 "Unknown AMPDU action\n");
8026 EXPORT_SYMBOL_GPL(rt2800_ampdu_action);
8028 int rt2800_get_survey(struct ieee80211_hw *hw, int idx,
8029 struct survey_info *survey)
8031 struct rt2x00_dev *rt2x00dev = hw->priv;
8032 struct ieee80211_conf *conf = &hw->conf;
8033 u32 idle, busy, busy_ext;
8038 survey->channel = conf->chandef.chan;
8040 rt2800_register_read(rt2x00dev, CH_IDLE_STA, &idle);
8041 rt2800_register_read(rt2x00dev, CH_BUSY_STA, &busy);
8042 rt2800_register_read(rt2x00dev, CH_BUSY_STA_SEC, &busy_ext);
8045 survey->filled = SURVEY_INFO_TIME |
8046 SURVEY_INFO_TIME_BUSY |
8047 SURVEY_INFO_TIME_EXT_BUSY;
8049 survey->time = (idle + busy) / 1000;
8050 survey->time_busy = busy / 1000;
8051 survey->time_ext_busy = busy_ext / 1000;
8054 if (!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL))
8055 survey->filled |= SURVEY_INFO_IN_USE;
8060 EXPORT_SYMBOL_GPL(rt2800_get_survey);
8062 MODULE_AUTHOR(DRV_PROJECT ", Bartlomiej Zolnierkiewicz");
8063 MODULE_VERSION(DRV_VERSION);
8064 MODULE_DESCRIPTION("Ralink RT2800 library");
8065 MODULE_LICENSE("GPL");