blob: 5c20e98b48081c9c3374691696f25dee4a5f3dfb [file] [log] [blame]
Bartlomiej Zolnierkiewicz89297422009-11-04 18:36:24 +01001/*
Ivo van Doorn96481b22010-08-06 20:47:57 +02002 Copyright (C) 2010 Willow Garage <http://www.willowgarage.com>
Ivo van Doorna5ea2f02010-06-14 22:13:15 +02003 Copyright (C) 2010 Ivo van Doorn <IvDoorn@gmail.com>
Gertjan van Wingerde9c9a0d12009-11-08 16:39:55 +01004 Copyright (C) 2009 Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Gertjan van Wingerdecce5fc42009-11-10 22:42:40 +01005 Copyright (C) 2009 Gertjan van Wingerde <gwingerde@gmail.com>
Bartlomiej Zolnierkiewicz89297422009-11-04 18:36:24 +01006
Gertjan van Wingerde9c9a0d12009-11-08 16:39:55 +01007 Based on the original rt2800pci.c and rt2800usb.c.
Gertjan van Wingerde9c9a0d12009-11-08 16:39:55 +01008 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>
Bartlomiej Zolnierkiewicz89297422009-11-04 18:36:24 +010014 <http://rt2x00.serialmonkey.com>
15
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.
20
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.
25
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the
28 Free Software Foundation, Inc.,
29 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 */
31
32/*
33 Module: rt2800lib
34 Abstract: rt2800 generic device routines.
35 */
36
Ivo van Doornf31c9a82010-07-11 12:30:37 +020037#include <linux/crc-ccitt.h>
Bartlomiej Zolnierkiewicz89297422009-11-04 18:36:24 +010038#include <linux/kernel.h>
39#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090040#include <linux/slab.h>
Bartlomiej Zolnierkiewicz89297422009-11-04 18:36:24 +010041
42#include "rt2x00.h"
43#include "rt2800lib.h"
44#include "rt2800.h"
45
Bartlomiej Zolnierkiewicz89297422009-11-04 18:36:24 +010046/*
47 * Register access.
48 * All access to the CSR registers will go through the methods
49 * rt2800_register_read and rt2800_register_write.
50 * BBP and RF register require indirect register access,
51 * and use the CSR registers BBPCSR and RFCSR to achieve this.
52 * These indirect registers work with busy bits,
53 * and we will try maximal REGISTER_BUSY_COUNT times to access
54 * the register while taking a REGISTER_BUSY_DELAY us delay
55 * between each attampt. When the busy bit is still set at that time,
56 * the access attempt is considered to have failed,
57 * and we will print an error.
58 * The _lock versions must be used if you already hold the csr_mutex
59 */
60#define WAIT_FOR_BBP(__dev, __reg) \
61 rt2800_regbusy_read((__dev), BBP_CSR_CFG, BBP_CSR_CFG_BUSY, (__reg))
62#define WAIT_FOR_RFCSR(__dev, __reg) \
63 rt2800_regbusy_read((__dev), RF_CSR_CFG, RF_CSR_CFG_BUSY, (__reg))
64#define WAIT_FOR_RF(__dev, __reg) \
65 rt2800_regbusy_read((__dev), RF_CSR_CFG0, RF_CSR_CFG0_BUSY, (__reg))
66#define WAIT_FOR_MCU(__dev, __reg) \
67 rt2800_regbusy_read((__dev), H2M_MAILBOX_CSR, \
68 H2M_MAILBOX_CSR_OWNER, (__reg))
69
Helmut Schaabaff8002010-04-28 09:58:59 +020070static inline bool rt2800_is_305x_soc(struct rt2x00_dev *rt2x00dev)
71{
72 /* check for rt2872 on SoC */
73 if (!rt2x00_is_soc(rt2x00dev) ||
74 !rt2x00_rt(rt2x00dev, RT2872))
75 return false;
76
77 /* we know for sure that these rf chipsets are used on rt305x boards */
78 if (rt2x00_rf(rt2x00dev, RF3020) ||
79 rt2x00_rf(rt2x00dev, RF3021) ||
80 rt2x00_rf(rt2x00dev, RF3022))
81 return true;
82
Stanislaw Gruszka92941382013-01-26 18:13:50 +010083 WARNING(rt2x00dev, "Unknown RF chipset on rt305x\n");
Helmut Schaabaff8002010-04-28 09:58:59 +020084 return false;
85}
86
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +010087static void rt2800_bbp_write(struct rt2x00_dev *rt2x00dev,
88 const unsigned int word, const u8 value)
Bartlomiej Zolnierkiewicz89297422009-11-04 18:36:24 +010089{
90 u32 reg;
91
92 mutex_lock(&rt2x00dev->csr_mutex);
93
94 /*
95 * Wait until the BBP becomes available, afterwards we
96 * can safely write the new data into the register.
97 */
98 if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
99 reg = 0;
100 rt2x00_set_field32(&reg, BBP_CSR_CFG_VALUE, value);
101 rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
102 rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
103 rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 0);
Ivo van Doornefc7d362010-06-29 21:49:26 +0200104 rt2x00_set_field32(&reg, BBP_CSR_CFG_BBP_RW_MODE, 1);
Bartlomiej Zolnierkiewicz89297422009-11-04 18:36:24 +0100105
106 rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
107 }
108
109 mutex_unlock(&rt2x00dev->csr_mutex);
110}
Bartlomiej Zolnierkiewicz89297422009-11-04 18:36:24 +0100111
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +0100112static void rt2800_bbp_read(struct rt2x00_dev *rt2x00dev,
113 const unsigned int word, u8 *value)
Bartlomiej Zolnierkiewicz89297422009-11-04 18:36:24 +0100114{
115 u32 reg;
116
117 mutex_lock(&rt2x00dev->csr_mutex);
118
119 /*
120 * Wait until the BBP becomes available, afterwards we
121 * can safely write the read request into the register.
122 * After the data has been written, we wait until hardware
123 * returns the correct value, if at any time the register
124 * doesn't become available in time, reg will be 0xffffffff
125 * which means we return 0xff to the caller.
126 */
127 if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
128 reg = 0;
129 rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
130 rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
131 rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 1);
Ivo van Doornefc7d362010-06-29 21:49:26 +0200132 rt2x00_set_field32(&reg, BBP_CSR_CFG_BBP_RW_MODE, 1);
Bartlomiej Zolnierkiewicz89297422009-11-04 18:36:24 +0100133
134 rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
135
136 WAIT_FOR_BBP(rt2x00dev, &reg);
137 }
138
139 *value = rt2x00_get_field32(reg, BBP_CSR_CFG_VALUE);
140
141 mutex_unlock(&rt2x00dev->csr_mutex);
142}
Bartlomiej Zolnierkiewicz89297422009-11-04 18:36:24 +0100143
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +0100144static void rt2800_rfcsr_write(struct rt2x00_dev *rt2x00dev,
145 const unsigned int word, const u8 value)
Bartlomiej Zolnierkiewicz89297422009-11-04 18:36:24 +0100146{
147 u32 reg;
148
149 mutex_lock(&rt2x00dev->csr_mutex);
150
151 /*
152 * Wait until the RFCSR becomes available, afterwards we
153 * can safely write the new data into the register.
154 */
155 if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
156 reg = 0;
157 rt2x00_set_field32(&reg, RF_CSR_CFG_DATA, value);
158 rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
159 rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 1);
160 rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
161
162 rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
163 }
164
165 mutex_unlock(&rt2x00dev->csr_mutex);
166}
Bartlomiej Zolnierkiewicz89297422009-11-04 18:36:24 +0100167
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +0100168static void rt2800_rfcsr_read(struct rt2x00_dev *rt2x00dev,
169 const unsigned int word, u8 *value)
Bartlomiej Zolnierkiewicz89297422009-11-04 18:36:24 +0100170{
171 u32 reg;
172
173 mutex_lock(&rt2x00dev->csr_mutex);
174
175 /*
176 * Wait until the RFCSR becomes available, afterwards we
177 * can safely write the read request into the register.
178 * After the data has been written, we wait until hardware
179 * returns the correct value, if at any time the register
180 * doesn't become available in time, reg will be 0xffffffff
181 * which means we return 0xff to the caller.
182 */
183 if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
184 reg = 0;
185 rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
186 rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 0);
187 rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
188
189 rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
190
191 WAIT_FOR_RFCSR(rt2x00dev, &reg);
192 }
193
194 *value = rt2x00_get_field32(reg, RF_CSR_CFG_DATA);
195
196 mutex_unlock(&rt2x00dev->csr_mutex);
197}
Bartlomiej Zolnierkiewicz89297422009-11-04 18:36:24 +0100198
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +0100199static void rt2800_rf_write(struct rt2x00_dev *rt2x00dev,
200 const unsigned int word, const u32 value)
Bartlomiej Zolnierkiewicz89297422009-11-04 18:36:24 +0100201{
202 u32 reg;
203
204 mutex_lock(&rt2x00dev->csr_mutex);
205
206 /*
207 * Wait until the RF becomes available, afterwards we
208 * can safely write the new data into the register.
209 */
210 if (WAIT_FOR_RF(rt2x00dev, &reg)) {
211 reg = 0;
212 rt2x00_set_field32(&reg, RF_CSR_CFG0_REG_VALUE_BW, value);
213 rt2x00_set_field32(&reg, RF_CSR_CFG0_STANDBYMODE, 0);
214 rt2x00_set_field32(&reg, RF_CSR_CFG0_SEL, 0);
215 rt2x00_set_field32(&reg, RF_CSR_CFG0_BUSY, 1);
216
217 rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG0, reg);
218 rt2x00_rf_write(rt2x00dev, word, value);
219 }
220
221 mutex_unlock(&rt2x00dev->csr_mutex);
222}
Bartlomiej Zolnierkiewicz89297422009-11-04 18:36:24 +0100223
Woody Hung16ebd602012-07-31 21:53:33 +0800224static int rt2800_enable_wlan_rt3290(struct rt2x00_dev *rt2x00dev)
225{
226 u32 reg;
227 int i, count;
228
229 rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, &reg);
230 if (rt2x00_get_field32(reg, WLAN_EN))
231 return 0;
232
233 rt2x00_set_field32(&reg, WLAN_GPIO_OUT_OE_BIT_ALL, 0xff);
234 rt2x00_set_field32(&reg, FRC_WL_ANT_SET, 1);
235 rt2x00_set_field32(&reg, WLAN_CLK_EN, 0);
236 rt2x00_set_field32(&reg, WLAN_EN, 1);
237 rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg);
238
239 udelay(REGISTER_BUSY_DELAY);
240
241 count = 0;
242 do {
243 /*
244 * Check PLL_LD & XTAL_RDY.
245 */
246 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
247 rt2800_register_read(rt2x00dev, CMB_CTRL, &reg);
248 if (rt2x00_get_field32(reg, PLL_LD) &&
249 rt2x00_get_field32(reg, XTAL_RDY))
250 break;
251 udelay(REGISTER_BUSY_DELAY);
252 }
253
254 if (i >= REGISTER_BUSY_COUNT) {
255
256 if (count >= 10)
257 return -EIO;
258
259 rt2800_register_write(rt2x00dev, 0x58, 0x018);
260 udelay(REGISTER_BUSY_DELAY);
261 rt2800_register_write(rt2x00dev, 0x58, 0x418);
262 udelay(REGISTER_BUSY_DELAY);
263 rt2800_register_write(rt2x00dev, 0x58, 0x618);
264 udelay(REGISTER_BUSY_DELAY);
265 count++;
266 } else {
267 count = 0;
268 }
269
270 rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, &reg);
271 rt2x00_set_field32(&reg, PCIE_APP0_CLK_REQ, 0);
272 rt2x00_set_field32(&reg, WLAN_CLK_EN, 1);
273 rt2x00_set_field32(&reg, WLAN_RESET, 1);
274 rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg);
275 udelay(10);
276 rt2x00_set_field32(&reg, WLAN_RESET, 0);
277 rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg);
278 udelay(10);
279 rt2800_register_write(rt2x00dev, INT_SOURCE_CSR, 0x7fffffff);
280 } while (count != 0);
281
282 return 0;
283}
284
Bartlomiej Zolnierkiewicz89297422009-11-04 18:36:24 +0100285void rt2800_mcu_request(struct rt2x00_dev *rt2x00dev,
286 const u8 command, const u8 token,
287 const u8 arg0, const u8 arg1)
288{
289 u32 reg;
290
Gertjan van Wingerdeee303e52009-11-23 22:44:49 +0100291 /*
Gertjan van Wingerdecea90e52010-02-13 20:55:47 +0100292 * SOC devices don't support MCU requests.
Gertjan van Wingerdeee303e52009-11-23 22:44:49 +0100293 */
Gertjan van Wingerdecea90e52010-02-13 20:55:47 +0100294 if (rt2x00_is_soc(rt2x00dev))
Gertjan van Wingerdeee303e52009-11-23 22:44:49 +0100295 return;
Bartlomiej Zolnierkiewicz89297422009-11-04 18:36:24 +0100296
297 mutex_lock(&rt2x00dev->csr_mutex);
298
299 /*
300 * Wait until the MCU becomes available, afterwards we
301 * can safely write the new data into the register.
302 */
303 if (WAIT_FOR_MCU(rt2x00dev, &reg)) {
304 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_OWNER, 1);
305 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_CMD_TOKEN, token);
306 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG0, arg0);
307 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG1, arg1);
308 rt2800_register_write_lock(rt2x00dev, H2M_MAILBOX_CSR, reg);
309
310 reg = 0;
311 rt2x00_set_field32(&reg, HOST_CMD_CSR_HOST_COMMAND, command);
312 rt2800_register_write_lock(rt2x00dev, HOST_CMD_CSR, reg);
313 }
314
315 mutex_unlock(&rt2x00dev->csr_mutex);
316}
317EXPORT_SYMBOL_GPL(rt2800_mcu_request);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +0100318
Ivo van Doorn5ffddc42010-08-30 21:13:08 +0200319int rt2800_wait_csr_ready(struct rt2x00_dev *rt2x00dev)
320{
321 unsigned int i = 0;
322 u32 reg;
323
324 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
325 rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
326 if (reg && reg != ~0)
327 return 0;
328 msleep(1);
329 }
330
331 ERROR(rt2x00dev, "Unstable hardware.\n");
332 return -EBUSY;
333}
334EXPORT_SYMBOL_GPL(rt2800_wait_csr_ready);
335
Gertjan van Wingerde67a4c1e2009-12-30 11:36:32 +0100336int rt2800_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev)
337{
338 unsigned int i;
339 u32 reg;
340
Helmut Schaa08e53102010-11-04 20:37:47 +0100341 /*
342 * Some devices are really slow to respond here. Wait a whole second
343 * before timing out.
344 */
Gertjan van Wingerde67a4c1e2009-12-30 11:36:32 +0100345 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
346 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
347 if (!rt2x00_get_field32(reg, WPDMA_GLO_CFG_TX_DMA_BUSY) &&
348 !rt2x00_get_field32(reg, WPDMA_GLO_CFG_RX_DMA_BUSY))
349 return 0;
350
Helmut Schaa08e53102010-11-04 20:37:47 +0100351 msleep(10);
Gertjan van Wingerde67a4c1e2009-12-30 11:36:32 +0100352 }
353
Jakub Kicinski52b82432012-04-03 03:40:49 +0200354 ERROR(rt2x00dev, "WPDMA TX/RX busy [0x%08x].\n", reg);
Gertjan van Wingerde67a4c1e2009-12-30 11:36:32 +0100355 return -EACCES;
356}
357EXPORT_SYMBOL_GPL(rt2800_wait_wpdma_ready);
358
Jakub Kicinskif7b395e2012-04-03 03:40:47 +0200359void rt2800_disable_wpdma(struct rt2x00_dev *rt2x00dev)
360{
361 u32 reg;
362
363 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
364 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
365 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
366 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
367 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
368 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
369 rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
370}
371EXPORT_SYMBOL_GPL(rt2800_disable_wpdma);
372
Ivo van Doornf31c9a82010-07-11 12:30:37 +0200373static bool rt2800_check_firmware_crc(const u8 *data, const size_t len)
374{
375 u16 fw_crc;
376 u16 crc;
377
378 /*
379 * The last 2 bytes in the firmware array are the crc checksum itself,
380 * this means that we should never pass those 2 bytes to the crc
381 * algorithm.
382 */
383 fw_crc = (data[len - 2] << 8 | data[len - 1]);
384
385 /*
386 * Use the crc ccitt algorithm.
387 * This will return the same value as the legacy driver which
388 * used bit ordering reversion on the both the firmware bytes
389 * before input input as well as on the final output.
390 * Obviously using crc ccitt directly is much more efficient.
391 */
392 crc = crc_ccitt(~0, data, len - 2);
393
394 /*
395 * There is a small difference between the crc-itu-t + bitrev and
396 * the crc-ccitt crc calculation. In the latter method the 2 bytes
397 * will be swapped, use swab16 to convert the crc to the correct
398 * value.
399 */
400 crc = swab16(crc);
401
402 return fw_crc == crc;
403}
404
405int rt2800_check_firmware(struct rt2x00_dev *rt2x00dev,
406 const u8 *data, const size_t len)
407{
408 size_t offset = 0;
409 size_t fw_len;
410 bool multiple;
411
412 /*
413 * PCI(e) & SOC devices require firmware with a length
414 * of 8kb. USB devices require firmware files with a length
415 * of 4kb. Certain USB chipsets however require different firmware,
416 * which Ralink only provides attached to the original firmware
417 * file. Thus for USB devices, firmware files have a length
Woody Hunga89534e2012-06-13 15:01:16 +0800418 * which is a multiple of 4kb. The firmware for rt3290 chip also
419 * have a length which is a multiple of 4kb.
Ivo van Doornf31c9a82010-07-11 12:30:37 +0200420 */
Woody Hunga89534e2012-06-13 15:01:16 +0800421 if (rt2x00_is_usb(rt2x00dev) || rt2x00_rt(rt2x00dev, RT3290))
Ivo van Doornf31c9a82010-07-11 12:30:37 +0200422 fw_len = 4096;
Woody Hunga89534e2012-06-13 15:01:16 +0800423 else
Ivo van Doornf31c9a82010-07-11 12:30:37 +0200424 fw_len = 8192;
Ivo van Doornf31c9a82010-07-11 12:30:37 +0200425
Woody Hunga89534e2012-06-13 15:01:16 +0800426 multiple = true;
Ivo van Doornf31c9a82010-07-11 12:30:37 +0200427 /*
428 * Validate the firmware length
429 */
430 if (len != fw_len && (!multiple || (len % fw_len) != 0))
431 return FW_BAD_LENGTH;
432
433 /*
434 * Check if the chipset requires one of the upper parts
435 * of the firmware.
436 */
437 if (rt2x00_is_usb(rt2x00dev) &&
438 !rt2x00_rt(rt2x00dev, RT2860) &&
439 !rt2x00_rt(rt2x00dev, RT2872) &&
440 !rt2x00_rt(rt2x00dev, RT3070) &&
441 ((len / fw_len) == 1))
442 return FW_BAD_VERSION;
443
444 /*
445 * 8kb firmware files must be checked as if it were
446 * 2 separate firmware files.
447 */
448 while (offset < len) {
449 if (!rt2800_check_firmware_crc(data + offset, fw_len))
450 return FW_BAD_CRC;
451
452 offset += fw_len;
453 }
454
455 return FW_OK;
456}
457EXPORT_SYMBOL_GPL(rt2800_check_firmware);
458
459int rt2800_load_firmware(struct rt2x00_dev *rt2x00dev,
460 const u8 *data, const size_t len)
461{
462 unsigned int i;
463 u32 reg;
Woody Hung16ebd602012-07-31 21:53:33 +0800464 int retval;
465
466 if (rt2x00_rt(rt2x00dev, RT3290)) {
467 retval = rt2800_enable_wlan_rt3290(rt2x00dev);
468 if (retval)
469 return -EBUSY;
470 }
Ivo van Doornf31c9a82010-07-11 12:30:37 +0200471
472 /*
Ivo van Doornb9eca242010-08-30 21:13:54 +0200473 * If driver doesn't wake up firmware here,
474 * rt2800_load_firmware will hang forever when interface is up again.
475 */
476 rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0x00000000);
477
478 /*
Ivo van Doornf31c9a82010-07-11 12:30:37 +0200479 * Wait for stable hardware.
480 */
Ivo van Doorn5ffddc42010-08-30 21:13:08 +0200481 if (rt2800_wait_csr_ready(rt2x00dev))
Ivo van Doornf31c9a82010-07-11 12:30:37 +0200482 return -EBUSY;
Ivo van Doornf31c9a82010-07-11 12:30:37 +0200483
Gabor Juhosadde5882011-03-03 11:46:45 +0100484 if (rt2x00_is_pci(rt2x00dev)) {
Woody Hunga89534e2012-06-13 15:01:16 +0800485 if (rt2x00_rt(rt2x00dev, RT3290) ||
486 rt2x00_rt(rt2x00dev, RT3572) ||
John Li2ed71882012-02-17 17:33:06 +0800487 rt2x00_rt(rt2x00dev, RT5390) ||
488 rt2x00_rt(rt2x00dev, RT5392)) {
Gabor Juhosadde5882011-03-03 11:46:45 +0100489 rt2800_register_read(rt2x00dev, AUX_CTRL, &reg);
490 rt2x00_set_field32(&reg, AUX_CTRL_FORCE_PCIE_CLK, 1);
491 rt2x00_set_field32(&reg, AUX_CTRL_WAKE_PCIE_EN, 1);
492 rt2800_register_write(rt2x00dev, AUX_CTRL, reg);
493 }
Ivo van Doornf31c9a82010-07-11 12:30:37 +0200494 rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000002);
Gabor Juhosadde5882011-03-03 11:46:45 +0100495 }
Ivo van Doornf31c9a82010-07-11 12:30:37 +0200496
Jakub Kicinskib7e1d222012-04-03 03:40:48 +0200497 rt2800_disable_wpdma(rt2x00dev);
498
Ivo van Doornf31c9a82010-07-11 12:30:37 +0200499 /*
Ivo van Doornf31c9a82010-07-11 12:30:37 +0200500 * Write firmware to the device.
501 */
502 rt2800_drv_write_firmware(rt2x00dev, data, len);
503
504 /*
505 * Wait for device to stabilize.
506 */
507 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
508 rt2800_register_read(rt2x00dev, PBF_SYS_CTRL, &reg);
509 if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY))
510 break;
511 msleep(1);
512 }
513
514 if (i == REGISTER_BUSY_COUNT) {
515 ERROR(rt2x00dev, "PBF system register not ready.\n");
516 return -EBUSY;
517 }
518
519 /*
Stanislaw Gruszka4ed1dd22012-01-24 14:09:07 +0100520 * Disable DMA, will be reenabled later when enabling
521 * the radio.
522 */
Jakub Kicinskif7b395e2012-04-03 03:40:47 +0200523 rt2800_disable_wpdma(rt2x00dev);
Stanislaw Gruszka4ed1dd22012-01-24 14:09:07 +0100524
525 /*
Ivo van Doornf31c9a82010-07-11 12:30:37 +0200526 * Initialize firmware.
527 */
528 rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
529 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
Stanislaw Gruszka87561302013-03-16 19:19:45 +0100530 if (rt2x00_is_usb(rt2x00dev)) {
Stanislaw Gruszka0c17cf92012-01-24 14:09:06 +0100531 rt2800_register_write(rt2x00dev, H2M_INT_SRC, 0);
Stanislaw Gruszka87561302013-03-16 19:19:45 +0100532 rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0, 0, 0);
533 }
Ivo van Doornf31c9a82010-07-11 12:30:37 +0200534 msleep(1);
535
536 return 0;
537}
538EXPORT_SYMBOL_GPL(rt2800_load_firmware);
539
Ivo van Doorn0c5879b2010-08-06 20:47:20 +0200540void rt2800_write_tx_data(struct queue_entry *entry,
541 struct txentry_desc *txdesc)
Gertjan van Wingerde59679b92010-05-08 23:40:21 +0200542{
Ivo van Doorn0c5879b2010-08-06 20:47:20 +0200543 __le32 *txwi = rt2800_drv_get_txwi(entry);
Gertjan van Wingerde59679b92010-05-08 23:40:21 +0200544 u32 word;
545
546 /*
547 * Initialize TX Info descriptor
548 */
549 rt2x00_desc_read(txwi, 0, &word);
550 rt2x00_set_field32(&word, TXWI_W0_FRAG,
551 test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
Ivo van Doorn84804cd2010-08-06 20:46:19 +0200552 rt2x00_set_field32(&word, TXWI_W0_MIMO_PS,
553 test_bit(ENTRY_TXD_HT_MIMO_PS, &txdesc->flags));
Gertjan van Wingerde59679b92010-05-08 23:40:21 +0200554 rt2x00_set_field32(&word, TXWI_W0_CF_ACK, 0);
555 rt2x00_set_field32(&word, TXWI_W0_TS,
556 test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
557 rt2x00_set_field32(&word, TXWI_W0_AMPDU,
558 test_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags));
Helmut Schaa26a1d072011-03-03 19:42:35 +0100559 rt2x00_set_field32(&word, TXWI_W0_MPDU_DENSITY,
560 txdesc->u.ht.mpdu_density);
561 rt2x00_set_field32(&word, TXWI_W0_TX_OP, txdesc->u.ht.txop);
562 rt2x00_set_field32(&word, TXWI_W0_MCS, txdesc->u.ht.mcs);
Gertjan van Wingerde59679b92010-05-08 23:40:21 +0200563 rt2x00_set_field32(&word, TXWI_W0_BW,
564 test_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags));
565 rt2x00_set_field32(&word, TXWI_W0_SHORT_GI,
566 test_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags));
Helmut Schaa26a1d072011-03-03 19:42:35 +0100567 rt2x00_set_field32(&word, TXWI_W0_STBC, txdesc->u.ht.stbc);
Gertjan van Wingerde59679b92010-05-08 23:40:21 +0200568 rt2x00_set_field32(&word, TXWI_W0_PHYMODE, txdesc->rate_mode);
569 rt2x00_desc_write(txwi, 0, word);
570
571 rt2x00_desc_read(txwi, 1, &word);
572 rt2x00_set_field32(&word, TXWI_W1_ACK,
573 test_bit(ENTRY_TXD_ACK, &txdesc->flags));
574 rt2x00_set_field32(&word, TXWI_W1_NSEQ,
575 test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags));
Helmut Schaa26a1d072011-03-03 19:42:35 +0100576 rt2x00_set_field32(&word, TXWI_W1_BW_WIN_SIZE, txdesc->u.ht.ba_size);
Gertjan van Wingerde59679b92010-05-08 23:40:21 +0200577 rt2x00_set_field32(&word, TXWI_W1_WIRELESS_CLI_ID,
578 test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags) ?
Helmut Schaaa2b13282011-09-08 14:38:01 +0200579 txdesc->key_idx : txdesc->u.ht.wcid);
Gertjan van Wingerde59679b92010-05-08 23:40:21 +0200580 rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT,
581 txdesc->length);
Helmut Schaa2b23cda2010-11-04 20:38:15 +0100582 rt2x00_set_field32(&word, TXWI_W1_PACKETID_QUEUE, entry->queue->qid);
Ivo van Doornbc8a9792010-10-02 11:32:43 +0200583 rt2x00_set_field32(&word, TXWI_W1_PACKETID_ENTRY, (entry->entry_idx % 3) + 1);
Gertjan van Wingerde59679b92010-05-08 23:40:21 +0200584 rt2x00_desc_write(txwi, 1, word);
585
586 /*
587 * Always write 0 to IV/EIV fields, hardware will insert the IV
588 * from the IVEIV register when TXD_W3_WIV is set to 0.
589 * When TXD_W3_WIV is set to 1 it will use the IV data
590 * from the descriptor. The TXWI_W1_WIRELESS_CLI_ID indicates which
591 * crypto entry in the registers should be used to encrypt the frame.
592 */
593 _rt2x00_desc_write(txwi, 2, 0 /* skbdesc->iv[0] */);
594 _rt2x00_desc_write(txwi, 3, 0 /* skbdesc->iv[1] */);
595}
Ivo van Doorn0c5879b2010-08-06 20:47:20 +0200596EXPORT_SYMBOL_GPL(rt2800_write_tx_data);
Gertjan van Wingerde59679b92010-05-08 23:40:21 +0200597
Helmut Schaaff6133b2010-10-09 13:34:11 +0200598static int rt2800_agc_to_rssi(struct rt2x00_dev *rt2x00dev, u32 rxwi_w2)
Gertjan van Wingerde2de64dd2010-05-08 23:40:22 +0200599{
Luigi Tarenga7fc41752012-01-31 18:51:23 +0100600 s8 rssi0 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI0);
601 s8 rssi1 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI1);
602 s8 rssi2 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI2);
Ivo van Doorn74861922010-07-11 12:23:50 +0200603 u16 eeprom;
604 u8 offset0;
605 u8 offset1;
606 u8 offset2;
607
Ivo van Doorne5ef5ba2010-08-06 20:49:27 +0200608 if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) {
Ivo van Doorn74861922010-07-11 12:23:50 +0200609 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &eeprom);
610 offset0 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG_OFFSET0);
611 offset1 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG_OFFSET1);
612 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom);
613 offset2 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG2_OFFSET2);
614 } else {
615 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &eeprom);
616 offset0 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A_OFFSET0);
617 offset1 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A_OFFSET1);
618 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom);
619 offset2 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A2_OFFSET2);
620 }
621
622 /*
623 * Convert the value from the descriptor into the RSSI value
624 * If the value in the descriptor is 0, it is considered invalid
625 * and the default (extremely low) rssi value is assumed
626 */
627 rssi0 = (rssi0) ? (-12 - offset0 - rt2x00dev->lna_gain - rssi0) : -128;
628 rssi1 = (rssi1) ? (-12 - offset1 - rt2x00dev->lna_gain - rssi1) : -128;
629 rssi2 = (rssi2) ? (-12 - offset2 - rt2x00dev->lna_gain - rssi2) : -128;
630
631 /*
632 * mac80211 only accepts a single RSSI value. Calculating the
633 * average doesn't deliver a fair answer either since -60:-60 would
634 * be considered equally good as -50:-70 while the second is the one
635 * which gives less energy...
636 */
637 rssi0 = max(rssi0, rssi1);
Luigi Tarenga7fc41752012-01-31 18:51:23 +0100638 return (int)max(rssi0, rssi2);
Ivo van Doorn74861922010-07-11 12:23:50 +0200639}
640
641void rt2800_process_rxwi(struct queue_entry *entry,
642 struct rxdone_entry_desc *rxdesc)
643{
644 __le32 *rxwi = (__le32 *) entry->skb->data;
Gertjan van Wingerde2de64dd2010-05-08 23:40:22 +0200645 u32 word;
646
647 rt2x00_desc_read(rxwi, 0, &word);
648
649 rxdesc->cipher = rt2x00_get_field32(word, RXWI_W0_UDF);
650 rxdesc->size = rt2x00_get_field32(word, RXWI_W0_MPDU_TOTAL_BYTE_COUNT);
651
652 rt2x00_desc_read(rxwi, 1, &word);
653
654 if (rt2x00_get_field32(word, RXWI_W1_SHORT_GI))
655 rxdesc->flags |= RX_FLAG_SHORT_GI;
656
657 if (rt2x00_get_field32(word, RXWI_W1_BW))
658 rxdesc->flags |= RX_FLAG_40MHZ;
659
660 /*
661 * Detect RX rate, always use MCS as signal type.
662 */
663 rxdesc->dev_flags |= RXDONE_SIGNAL_MCS;
664 rxdesc->signal = rt2x00_get_field32(word, RXWI_W1_MCS);
665 rxdesc->rate_mode = rt2x00_get_field32(word, RXWI_W1_PHYMODE);
666
667 /*
668 * Mask of 0x8 bit to remove the short preamble flag.
669 */
670 if (rxdesc->rate_mode == RATE_MODE_CCK)
671 rxdesc->signal &= ~0x8;
672
673 rt2x00_desc_read(rxwi, 2, &word);
674
Ivo van Doorn74861922010-07-11 12:23:50 +0200675 /*
676 * Convert descriptor AGC value to RSSI value.
677 */
678 rxdesc->rssi = rt2800_agc_to_rssi(entry->queue->rt2x00dev, word);
Stanislaw Gruszkaf0bda572013-04-17 14:30:47 +0200679 /*
680 * Remove RXWI descriptor from start of the buffer.
681 */
682 skb_pull(entry->skb, entry->queue->winfo_size);
Gertjan van Wingerde2de64dd2010-05-08 23:40:22 +0200683}
684EXPORT_SYMBOL_GPL(rt2800_process_rxwi);
685
Helmut Schaa31937c42011-09-07 20:10:02 +0200686void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi)
Helmut Schaa14433332010-10-02 11:27:03 +0200687{
688 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
Helmut Schaab34793e2010-10-02 11:34:56 +0200689 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
Helmut Schaa14433332010-10-02 11:27:03 +0200690 struct txdone_entry_desc txdesc;
691 u32 word;
692 u16 mcs, real_mcs;
Helmut Schaab34793e2010-10-02 11:34:56 +0200693 int aggr, ampdu;
Helmut Schaa14433332010-10-02 11:27:03 +0200694
695 /*
696 * Obtain the status about this packet.
697 */
698 txdesc.flags = 0;
Helmut Schaa14433332010-10-02 11:27:03 +0200699 rt2x00_desc_read(txwi, 0, &word);
Helmut Schaab34793e2010-10-02 11:34:56 +0200700
Helmut Schaa14433332010-10-02 11:27:03 +0200701 mcs = rt2x00_get_field32(word, TXWI_W0_MCS);
Helmut Schaab34793e2010-10-02 11:34:56 +0200702 ampdu = rt2x00_get_field32(word, TXWI_W0_AMPDU);
703
Helmut Schaa14433332010-10-02 11:27:03 +0200704 real_mcs = rt2x00_get_field32(status, TX_STA_FIFO_MCS);
Helmut Schaab34793e2010-10-02 11:34:56 +0200705 aggr = rt2x00_get_field32(status, TX_STA_FIFO_TX_AGGRE);
706
707 /*
708 * If a frame was meant to be sent as a single non-aggregated MPDU
709 * but ended up in an aggregate the used tx rate doesn't correlate
710 * with the one specified in the TXWI as the whole aggregate is sent
711 * with the same rate.
712 *
713 * For example: two frames are sent to rt2x00, the first one sets
714 * AMPDU=1 and requests MCS7 whereas the second frame sets AMDPU=0
715 * and requests MCS15. If the hw aggregates both frames into one
716 * AMDPU the tx status for both frames will contain MCS7 although
717 * the frame was sent successfully.
718 *
719 * Hence, replace the requested rate with the real tx rate to not
720 * confuse the rate control algortihm by providing clearly wrong
721 * data.
722 */
Helmut Schaa5356d962011-03-03 19:40:33 +0100723 if (unlikely(aggr == 1 && ampdu == 0 && real_mcs != mcs)) {
Helmut Schaab34793e2010-10-02 11:34:56 +0200724 skbdesc->tx_rate_idx = real_mcs;
725 mcs = real_mcs;
726 }
Helmut Schaa14433332010-10-02 11:27:03 +0200727
Helmut Schaaf16d2db2011-03-28 13:35:21 +0200728 if (aggr == 1 || ampdu == 1)
729 __set_bit(TXDONE_AMPDU, &txdesc.flags);
730
Helmut Schaa14433332010-10-02 11:27:03 +0200731 /*
732 * Ralink has a retry mechanism using a global fallback
733 * table. We setup this fallback table to try the immediate
734 * lower rate for all rates. In the TX_STA_FIFO, the MCS field
735 * always contains the MCS used for the last transmission, be
736 * it successful or not.
737 */
738 if (rt2x00_get_field32(status, TX_STA_FIFO_TX_SUCCESS)) {
739 /*
740 * Transmission succeeded. The number of retries is
741 * mcs - real_mcs
742 */
743 __set_bit(TXDONE_SUCCESS, &txdesc.flags);
744 txdesc.retry = ((mcs > real_mcs) ? mcs - real_mcs : 0);
745 } else {
746 /*
747 * Transmission failed. The number of retries is
748 * always 7 in this case (for a total number of 8
749 * frames sent).
750 */
751 __set_bit(TXDONE_FAILURE, &txdesc.flags);
752 txdesc.retry = rt2x00dev->long_retry;
753 }
754
755 /*
756 * the frame was retried at least once
757 * -> hw used fallback rates
758 */
759 if (txdesc.retry)
760 __set_bit(TXDONE_FALLBACK, &txdesc.flags);
761
762 rt2x00lib_txdone(entry, &txdesc);
763}
764EXPORT_SYMBOL_GPL(rt2800_txdone_entry);
765
Gertjan van Wingerdef0194b22010-06-03 10:51:53 +0200766void rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc)
767{
768 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
769 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
770 unsigned int beacon_base;
Wolfgang Kufner739fd942010-12-13 12:39:12 +0100771 unsigned int padding_len;
Seth Forsheed76dfc62011-02-14 08:52:25 -0600772 u32 orig_reg, reg;
Stanislaw Gruszkaf0bda572013-04-17 14:30:47 +0200773 const int txwi_desc_size = entry->queue->winfo_size;
Gertjan van Wingerdef0194b22010-06-03 10:51:53 +0200774
775 /*
776 * Disable beaconing while we are reloading the beacon data,
777 * otherwise we might be sending out invalid data.
778 */
779 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
Seth Forsheed76dfc62011-02-14 08:52:25 -0600780 orig_reg = reg;
Gertjan van Wingerdef0194b22010-06-03 10:51:53 +0200781 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
782 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
783
784 /*
785 * Add space for the TXWI in front of the skb.
786 */
Stanislaw Gruszkaf0bda572013-04-17 14:30:47 +0200787 memset(skb_push(entry->skb, txwi_desc_size), 0, txwi_desc_size);
Gertjan van Wingerdef0194b22010-06-03 10:51:53 +0200788
789 /*
790 * Register descriptor details in skb frame descriptor.
791 */
792 skbdesc->flags |= SKBDESC_DESC_IN_SKB;
793 skbdesc->desc = entry->skb->data;
Stanislaw Gruszkaf0bda572013-04-17 14:30:47 +0200794 skbdesc->desc_len = txwi_desc_size;
Gertjan van Wingerdef0194b22010-06-03 10:51:53 +0200795
796 /*
797 * Add the TXWI for the beacon to the skb.
798 */
Ivo van Doorn0c5879b2010-08-06 20:47:20 +0200799 rt2800_write_tx_data(entry, txdesc);
Gertjan van Wingerdef0194b22010-06-03 10:51:53 +0200800
801 /*
802 * Dump beacon to userspace through debugfs.
803 */
804 rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry->skb);
805
806 /*
Wolfgang Kufner739fd942010-12-13 12:39:12 +0100807 * Write entire beacon with TXWI and padding to register.
Gertjan van Wingerdef0194b22010-06-03 10:51:53 +0200808 */
Wolfgang Kufner739fd942010-12-13 12:39:12 +0100809 padding_len = roundup(entry->skb->len, 4) - entry->skb->len;
Seth Forsheed76dfc62011-02-14 08:52:25 -0600810 if (padding_len && skb_pad(entry->skb, padding_len)) {
811 ERROR(rt2x00dev, "Failure padding beacon, aborting\n");
812 /* skb freed by skb_pad() on failure */
813 entry->skb = NULL;
814 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, orig_reg);
815 return;
816 }
817
Gertjan van Wingerdef0194b22010-06-03 10:51:53 +0200818 beacon_base = HW_BEACON_OFFSET(entry->entry_idx);
Wolfgang Kufner739fd942010-12-13 12:39:12 +0100819 rt2800_register_multiwrite(rt2x00dev, beacon_base, entry->skb->data,
820 entry->skb->len + padding_len);
Gertjan van Wingerdef0194b22010-06-03 10:51:53 +0200821
822 /*
823 * Enable beaconing again.
824 */
Gertjan van Wingerdef0194b22010-06-03 10:51:53 +0200825 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 1);
826 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
827
828 /*
829 * Clean up beacon skb.
830 */
831 dev_kfree_skb_any(entry->skb);
832 entry->skb = NULL;
833}
Ivo van Doorn50e888e2010-07-11 12:26:12 +0200834EXPORT_SYMBOL_GPL(rt2800_write_beacon);
Gertjan van Wingerdef0194b22010-06-03 10:51:53 +0200835
Helmut Schaa69cf36a2011-01-30 13:16:03 +0100836static inline void rt2800_clear_beacon_register(struct rt2x00_dev *rt2x00dev,
837 unsigned int beacon_base)
Helmut Schaafdb87252010-06-29 21:48:06 +0200838{
839 int i;
Stanislaw Gruszkaf0bda572013-04-17 14:30:47 +0200840 const int txwi_desc_size = rt2x00dev->ops->bcn->winfo_size;
Helmut Schaafdb87252010-06-29 21:48:06 +0200841
842 /*
843 * For the Beacon base registers we only need to clear
844 * the whole TXWI which (when set to 0) will invalidate
845 * the entire beacon.
846 */
Stanislaw Gruszkaf0bda572013-04-17 14:30:47 +0200847 for (i = 0; i < txwi_desc_size; i += sizeof(__le32))
Helmut Schaafdb87252010-06-29 21:48:06 +0200848 rt2800_register_write(rt2x00dev, beacon_base + i, 0);
849}
850
Helmut Schaa69cf36a2011-01-30 13:16:03 +0100851void rt2800_clear_beacon(struct queue_entry *entry)
852{
853 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
854 u32 reg;
855
856 /*
857 * Disable beaconing while we are reloading the beacon data,
858 * otherwise we might be sending out invalid data.
859 */
860 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
861 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
862 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
863
864 /*
865 * Clear beacon.
866 */
867 rt2800_clear_beacon_register(rt2x00dev,
868 HW_BEACON_OFFSET(entry->entry_idx));
869
870 /*
871 * Enabled beaconing again.
872 */
873 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 1);
874 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
875}
876EXPORT_SYMBOL_GPL(rt2800_clear_beacon);
877
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +0100878#ifdef CONFIG_RT2X00_LIB_DEBUGFS
879const struct rt2x00debug rt2800_rt2x00debug = {
880 .owner = THIS_MODULE,
881 .csr = {
882 .read = rt2800_register_read,
883 .write = rt2800_register_write,
884 .flags = RT2X00DEBUGFS_OFFSET,
885 .word_base = CSR_REG_BASE,
886 .word_size = sizeof(u32),
887 .word_count = CSR_REG_SIZE / sizeof(u32),
888 },
889 .eeprom = {
890 .read = rt2x00_eeprom_read,
891 .write = rt2x00_eeprom_write,
892 .word_base = EEPROM_BASE,
893 .word_size = sizeof(u16),
894 .word_count = EEPROM_SIZE / sizeof(u16),
895 },
896 .bbp = {
897 .read = rt2800_bbp_read,
898 .write = rt2800_bbp_write,
899 .word_base = BBP_BASE,
900 .word_size = sizeof(u8),
901 .word_count = BBP_SIZE / sizeof(u8),
902 },
903 .rf = {
904 .read = rt2x00_rf_read,
905 .write = rt2800_rf_write,
906 .word_base = RF_BASE,
907 .word_size = sizeof(u32),
908 .word_count = RF_SIZE / sizeof(u32),
909 },
Anisse Astierf2bd7f12012-04-19 15:53:10 +0200910 .rfcsr = {
911 .read = rt2800_rfcsr_read,
912 .write = rt2800_rfcsr_write,
913 .word_base = RFCSR_BASE,
914 .word_size = sizeof(u8),
915 .word_count = RFCSR_SIZE / sizeof(u8),
916 },
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +0100917};
918EXPORT_SYMBOL_GPL(rt2800_rt2x00debug);
919#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
920
921int rt2800_rfkill_poll(struct rt2x00_dev *rt2x00dev)
922{
923 u32 reg;
924
Woody Hunga89534e2012-06-13 15:01:16 +0800925 if (rt2x00_rt(rt2x00dev, RT3290)) {
926 rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, &reg);
927 return rt2x00_get_field32(reg, WLAN_GPIO_IN_BIT0);
928 } else {
Gertjan van Wingerde99bdf512012-08-31 19:22:13 +0200929 rt2800_register_read(rt2x00dev, GPIO_CTRL, &reg);
930 return rt2x00_get_field32(reg, GPIO_CTRL_VAL2);
Woody Hunga89534e2012-06-13 15:01:16 +0800931 }
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +0100932}
933EXPORT_SYMBOL_GPL(rt2800_rfkill_poll);
934
935#ifdef CONFIG_RT2X00_LIB_LEDS
936static void rt2800_brightness_set(struct led_classdev *led_cdev,
937 enum led_brightness brightness)
938{
939 struct rt2x00_led *led =
940 container_of(led_cdev, struct rt2x00_led, led_dev);
941 unsigned int enabled = brightness != LED_OFF;
942 unsigned int bg_mode =
943 (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_2GHZ);
944 unsigned int polarity =
945 rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
946 EEPROM_FREQ_LED_POLARITY);
947 unsigned int ledmode =
948 rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
949 EEPROM_FREQ_LED_MODE);
Layne Edwards44704e52011-04-18 15:26:00 +0200950 u32 reg;
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +0100951
Layne Edwards44704e52011-04-18 15:26:00 +0200952 /* Check for SoC (SOC devices don't support MCU requests) */
953 if (rt2x00_is_soc(led->rt2x00dev)) {
954 rt2800_register_read(led->rt2x00dev, LED_CFG, &reg);
955
956 /* Set LED Polarity */
957 rt2x00_set_field32(&reg, LED_CFG_LED_POLAR, polarity);
958
959 /* Set LED Mode */
960 if (led->type == LED_TYPE_RADIO) {
961 rt2x00_set_field32(&reg, LED_CFG_G_LED_MODE,
962 enabled ? 3 : 0);
963 } else if (led->type == LED_TYPE_ASSOC) {
964 rt2x00_set_field32(&reg, LED_CFG_Y_LED_MODE,
965 enabled ? 3 : 0);
966 } else if (led->type == LED_TYPE_QUALITY) {
967 rt2x00_set_field32(&reg, LED_CFG_R_LED_MODE,
968 enabled ? 3 : 0);
969 }
970
971 rt2800_register_write(led->rt2x00dev, LED_CFG, reg);
972
973 } else {
974 if (led->type == LED_TYPE_RADIO) {
975 rt2800_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
976 enabled ? 0x20 : 0);
977 } else if (led->type == LED_TYPE_ASSOC) {
978 rt2800_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
979 enabled ? (bg_mode ? 0x60 : 0xa0) : 0x20);
980 } else if (led->type == LED_TYPE_QUALITY) {
981 /*
982 * The brightness is divided into 6 levels (0 - 5),
983 * The specs tell us the following levels:
984 * 0, 1 ,3, 7, 15, 31
985 * to determine the level in a simple way we can simply
986 * work with bitshifting:
987 * (1 << level) - 1
988 */
989 rt2800_mcu_request(led->rt2x00dev, MCU_LED_STRENGTH, 0xff,
990 (1 << brightness / (LED_FULL / 6)) - 1,
991 polarity);
992 }
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +0100993 }
994}
995
Gertjan van Wingerdeb3579d62009-12-30 11:36:34 +0100996static void rt2800_init_led(struct rt2x00_dev *rt2x00dev,
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +0100997 struct rt2x00_led *led, enum led_type type)
998{
999 led->rt2x00dev = rt2x00dev;
1000 led->type = type;
1001 led->led_dev.brightness_set = rt2800_brightness_set;
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001002 led->flags = LED_INITIALIZED;
1003}
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001004#endif /* CONFIG_RT2X00_LIB_LEDS */
1005
1006/*
1007 * Configuration handlers.
1008 */
Helmut Schaaa2b13282011-09-08 14:38:01 +02001009static void rt2800_config_wcid(struct rt2x00_dev *rt2x00dev,
1010 const u8 *address,
1011 int wcid)
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001012{
1013 struct mac_wcid_entry wcid_entry;
Helmut Schaaa2b13282011-09-08 14:38:01 +02001014 u32 offset;
1015
1016 offset = MAC_WCID_ENTRY(wcid);
1017
1018 memset(&wcid_entry, 0xff, sizeof(wcid_entry));
1019 if (address)
1020 memcpy(wcid_entry.mac, address, ETH_ALEN);
1021
1022 rt2800_register_multiwrite(rt2x00dev, offset,
1023 &wcid_entry, sizeof(wcid_entry));
1024}
1025
1026static void rt2800_delete_wcid_attr(struct rt2x00_dev *rt2x00dev, int wcid)
1027{
1028 u32 offset;
1029 offset = MAC_WCID_ATTR_ENTRY(wcid);
1030 rt2800_register_write(rt2x00dev, offset, 0);
1031}
1032
1033static void rt2800_config_wcid_attr_bssidx(struct rt2x00_dev *rt2x00dev,
1034 int wcid, u32 bssidx)
1035{
1036 u32 offset = MAC_WCID_ATTR_ENTRY(wcid);
1037 u32 reg;
1038
1039 /*
1040 * The BSS Idx numbers is split in a main value of 3 bits,
1041 * and a extended field for adding one additional bit to the value.
1042 */
1043 rt2800_register_read(rt2x00dev, offset, &reg);
1044 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_BSS_IDX, (bssidx & 0x7));
1045 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_BSS_IDX_EXT,
1046 (bssidx & 0x8) >> 3);
1047 rt2800_register_write(rt2x00dev, offset, reg);
1048}
1049
1050static void rt2800_config_wcid_attr_cipher(struct rt2x00_dev *rt2x00dev,
1051 struct rt2x00lib_crypto *crypto,
1052 struct ieee80211_key_conf *key)
1053{
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001054 struct mac_iveiv_entry iveiv_entry;
1055 u32 offset;
1056 u32 reg;
1057
1058 offset = MAC_WCID_ATTR_ENTRY(key->hw_key_idx);
1059
Ivo van Doorne4a0ab32010-06-14 22:14:19 +02001060 if (crypto->cmd == SET_KEY) {
1061 rt2800_register_read(rt2x00dev, offset, &reg);
1062 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_KEYTAB,
1063 !!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE));
1064 /*
1065 * Both the cipher as the BSS Idx numbers are split in a main
1066 * value of 3 bits, and a extended field for adding one additional
1067 * bit to the value.
1068 */
1069 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_CIPHER,
1070 (crypto->cipher & 0x7));
1071 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_CIPHER_EXT,
1072 (crypto->cipher & 0x8) >> 3);
Ivo van Doorne4a0ab32010-06-14 22:14:19 +02001073 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_RX_WIUDF, crypto->cipher);
1074 rt2800_register_write(rt2x00dev, offset, reg);
1075 } else {
Helmut Schaaa2b13282011-09-08 14:38:01 +02001076 /* Delete the cipher without touching the bssidx */
1077 rt2800_register_read(rt2x00dev, offset, &reg);
1078 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_KEYTAB, 0);
1079 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_CIPHER, 0);
1080 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_CIPHER_EXT, 0);
1081 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_RX_WIUDF, 0);
1082 rt2800_register_write(rt2x00dev, offset, reg);
Ivo van Doorne4a0ab32010-06-14 22:14:19 +02001083 }
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001084
1085 offset = MAC_IVEIV_ENTRY(key->hw_key_idx);
1086
1087 memset(&iveiv_entry, 0, sizeof(iveiv_entry));
1088 if ((crypto->cipher == CIPHER_TKIP) ||
1089 (crypto->cipher == CIPHER_TKIP_NO_MIC) ||
1090 (crypto->cipher == CIPHER_AES))
1091 iveiv_entry.iv[3] |= 0x20;
1092 iveiv_entry.iv[3] |= key->keyidx << 6;
1093 rt2800_register_multiwrite(rt2x00dev, offset,
1094 &iveiv_entry, sizeof(iveiv_entry));
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001095}
1096
1097int rt2800_config_shared_key(struct rt2x00_dev *rt2x00dev,
1098 struct rt2x00lib_crypto *crypto,
1099 struct ieee80211_key_conf *key)
1100{
1101 struct hw_key_entry key_entry;
1102 struct rt2x00_field32 field;
1103 u32 offset;
1104 u32 reg;
1105
1106 if (crypto->cmd == SET_KEY) {
1107 key->hw_key_idx = (4 * crypto->bssidx) + key->keyidx;
1108
1109 memcpy(key_entry.key, crypto->key,
1110 sizeof(key_entry.key));
1111 memcpy(key_entry.tx_mic, crypto->tx_mic,
1112 sizeof(key_entry.tx_mic));
1113 memcpy(key_entry.rx_mic, crypto->rx_mic,
1114 sizeof(key_entry.rx_mic));
1115
1116 offset = SHARED_KEY_ENTRY(key->hw_key_idx);
1117 rt2800_register_multiwrite(rt2x00dev, offset,
1118 &key_entry, sizeof(key_entry));
1119 }
1120
1121 /*
1122 * The cipher types are stored over multiple registers
1123 * starting with SHARED_KEY_MODE_BASE each word will have
1124 * 32 bits and contains the cipher types for 2 bssidx each.
1125 * Using the correct defines correctly will cause overhead,
1126 * so just calculate the correct offset.
1127 */
1128 field.bit_offset = 4 * (key->hw_key_idx % 8);
1129 field.bit_mask = 0x7 << field.bit_offset;
1130
1131 offset = SHARED_KEY_MODE_ENTRY(key->hw_key_idx / 8);
1132
1133 rt2800_register_read(rt2x00dev, offset, &reg);
1134 rt2x00_set_field32(&reg, field,
1135 (crypto->cmd == SET_KEY) * crypto->cipher);
1136 rt2800_register_write(rt2x00dev, offset, reg);
1137
1138 /*
1139 * Update WCID information
1140 */
Helmut Schaaa2b13282011-09-08 14:38:01 +02001141 rt2800_config_wcid(rt2x00dev, crypto->address, key->hw_key_idx);
1142 rt2800_config_wcid_attr_bssidx(rt2x00dev, key->hw_key_idx,
1143 crypto->bssidx);
1144 rt2800_config_wcid_attr_cipher(rt2x00dev, crypto, key);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001145
1146 return 0;
1147}
1148EXPORT_SYMBOL_GPL(rt2800_config_shared_key);
1149
Helmut Schaaa2b13282011-09-08 14:38:01 +02001150static inline int rt2800_find_wcid(struct rt2x00_dev *rt2x00dev)
Helmut Schaa1ed38112011-03-03 19:44:33 +01001151{
Helmut Schaaa2b13282011-09-08 14:38:01 +02001152 struct mac_wcid_entry wcid_entry;
Helmut Schaa1ed38112011-03-03 19:44:33 +01001153 int idx;
Helmut Schaaa2b13282011-09-08 14:38:01 +02001154 u32 offset;
Helmut Schaa1ed38112011-03-03 19:44:33 +01001155
1156 /*
Helmut Schaaa2b13282011-09-08 14:38:01 +02001157 * Search for the first free WCID entry and return the corresponding
1158 * index.
Helmut Schaa1ed38112011-03-03 19:44:33 +01001159 *
1160 * Make sure the WCID starts _after_ the last possible shared key
1161 * entry (>32).
1162 *
1163 * Since parts of the pairwise key table might be shared with
1164 * the beacon frame buffers 6 & 7 we should only write into the
1165 * first 222 entries.
1166 */
1167 for (idx = 33; idx <= 222; idx++) {
Helmut Schaaa2b13282011-09-08 14:38:01 +02001168 offset = MAC_WCID_ENTRY(idx);
1169 rt2800_register_multiread(rt2x00dev, offset, &wcid_entry,
1170 sizeof(wcid_entry));
1171 if (is_broadcast_ether_addr(wcid_entry.mac))
Helmut Schaa1ed38112011-03-03 19:44:33 +01001172 return idx;
1173 }
Helmut Schaaa2b13282011-09-08 14:38:01 +02001174
1175 /*
1176 * Use -1 to indicate that we don't have any more space in the WCID
1177 * table.
1178 */
Helmut Schaa1ed38112011-03-03 19:44:33 +01001179 return -1;
1180}
1181
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001182int rt2800_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
1183 struct rt2x00lib_crypto *crypto,
1184 struct ieee80211_key_conf *key)
1185{
1186 struct hw_key_entry key_entry;
1187 u32 offset;
1188
1189 if (crypto->cmd == SET_KEY) {
Helmut Schaaa2b13282011-09-08 14:38:01 +02001190 /*
1191 * Allow key configuration only for STAs that are
1192 * known by the hw.
1193 */
1194 if (crypto->wcid < 0)
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001195 return -ENOSPC;
Helmut Schaaa2b13282011-09-08 14:38:01 +02001196 key->hw_key_idx = crypto->wcid;
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001197
1198 memcpy(key_entry.key, crypto->key,
1199 sizeof(key_entry.key));
1200 memcpy(key_entry.tx_mic, crypto->tx_mic,
1201 sizeof(key_entry.tx_mic));
1202 memcpy(key_entry.rx_mic, crypto->rx_mic,
1203 sizeof(key_entry.rx_mic));
1204
1205 offset = PAIRWISE_KEY_ENTRY(key->hw_key_idx);
1206 rt2800_register_multiwrite(rt2x00dev, offset,
1207 &key_entry, sizeof(key_entry));
1208 }
1209
1210 /*
1211 * Update WCID information
1212 */
Helmut Schaaa2b13282011-09-08 14:38:01 +02001213 rt2800_config_wcid_attr_cipher(rt2x00dev, crypto, key);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001214
1215 return 0;
1216}
1217EXPORT_SYMBOL_GPL(rt2800_config_pairwise_key);
1218
Helmut Schaaa2b13282011-09-08 14:38:01 +02001219int rt2800_sta_add(struct rt2x00_dev *rt2x00dev, struct ieee80211_vif *vif,
1220 struct ieee80211_sta *sta)
1221{
1222 int wcid;
1223 struct rt2x00_sta *sta_priv = sta_to_rt2x00_sta(sta);
1224
1225 /*
1226 * Find next free WCID.
1227 */
1228 wcid = rt2800_find_wcid(rt2x00dev);
1229
1230 /*
1231 * Store selected wcid even if it is invalid so that we can
1232 * later decide if the STA is uploaded into the hw.
1233 */
1234 sta_priv->wcid = wcid;
1235
1236 /*
1237 * No space left in the device, however, we can still communicate
1238 * with the STA -> No error.
1239 */
1240 if (wcid < 0)
1241 return 0;
1242
1243 /*
1244 * Clean up WCID attributes and write STA address to the device.
1245 */
1246 rt2800_delete_wcid_attr(rt2x00dev, wcid);
1247 rt2800_config_wcid(rt2x00dev, sta->addr, wcid);
1248 rt2800_config_wcid_attr_bssidx(rt2x00dev, wcid,
1249 rt2x00lib_get_bssidx(rt2x00dev, vif));
1250 return 0;
1251}
1252EXPORT_SYMBOL_GPL(rt2800_sta_add);
1253
1254int rt2800_sta_remove(struct rt2x00_dev *rt2x00dev, int wcid)
1255{
1256 /*
1257 * Remove WCID entry, no need to clean the attributes as they will
1258 * get renewed when the WCID is reused.
1259 */
1260 rt2800_config_wcid(rt2x00dev, NULL, wcid);
1261
1262 return 0;
1263}
1264EXPORT_SYMBOL_GPL(rt2800_sta_remove);
1265
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001266void rt2800_config_filter(struct rt2x00_dev *rt2x00dev,
1267 const unsigned int filter_flags)
1268{
1269 u32 reg;
1270
1271 /*
1272 * Start configuration steps.
1273 * Note that the version error will always be dropped
1274 * and broadcast frames will always be accepted since
1275 * there is no filter for it at this time.
1276 */
1277 rt2800_register_read(rt2x00dev, RX_FILTER_CFG, &reg);
1278 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CRC_ERROR,
1279 !(filter_flags & FIF_FCSFAIL));
1280 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_PHY_ERROR,
1281 !(filter_flags & FIF_PLCPFAIL));
1282 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_NOT_TO_ME,
1283 !(filter_flags & FIF_PROMISC_IN_BSS));
1284 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_NOT_MY_BSSD, 0);
1285 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_VER_ERROR, 1);
1286 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_MULTICAST,
1287 !(filter_flags & FIF_ALLMULTI));
1288 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BROADCAST, 0);
1289 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_DUPLICATE, 1);
1290 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CF_END_ACK,
1291 !(filter_flags & FIF_CONTROL));
1292 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CF_END,
1293 !(filter_flags & FIF_CONTROL));
1294 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_ACK,
1295 !(filter_flags & FIF_CONTROL));
1296 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CTS,
1297 !(filter_flags & FIF_CONTROL));
1298 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_RTS,
1299 !(filter_flags & FIF_CONTROL));
1300 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_PSPOLL,
1301 !(filter_flags & FIF_PSPOLL));
Helmut Schaa84e9e8ebd2013-01-17 17:34:32 +01001302 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BA, 0);
Helmut Schaa48839932011-11-24 09:13:26 +01001303 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BAR,
1304 !(filter_flags & FIF_CONTROL));
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001305 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CNTL,
1306 !(filter_flags & FIF_CONTROL));
1307 rt2800_register_write(rt2x00dev, RX_FILTER_CFG, reg);
1308}
1309EXPORT_SYMBOL_GPL(rt2800_config_filter);
1310
1311void rt2800_config_intf(struct rt2x00_dev *rt2x00dev, struct rt2x00_intf *intf,
1312 struct rt2x00intf_conf *conf, const unsigned int flags)
1313{
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001314 u32 reg;
Helmut Schaafa8b4b22010-11-04 20:42:36 +01001315 bool update_bssid = false;
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001316
1317 if (flags & CONFIG_UPDATE_TYPE) {
1318 /*
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001319 * Enable synchronisation.
1320 */
1321 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001322 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, conf->sync);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001323 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
Helmut Schaa15a533c2011-04-18 15:28:04 +02001324
1325 if (conf->sync == TSF_SYNC_AP_NONE) {
1326 /*
1327 * Tune beacon queue transmit parameters for AP mode
1328 */
1329 rt2800_register_read(rt2x00dev, TBTT_SYNC_CFG, &reg);
1330 rt2x00_set_field32(&reg, TBTT_SYNC_CFG_BCN_CWMIN, 0);
1331 rt2x00_set_field32(&reg, TBTT_SYNC_CFG_BCN_AIFSN, 1);
1332 rt2x00_set_field32(&reg, TBTT_SYNC_CFG_BCN_EXP_WIN, 32);
1333 rt2x00_set_field32(&reg, TBTT_SYNC_CFG_TBTT_ADJUST, 0);
1334 rt2800_register_write(rt2x00dev, TBTT_SYNC_CFG, reg);
1335 } else {
1336 rt2800_register_read(rt2x00dev, TBTT_SYNC_CFG, &reg);
1337 rt2x00_set_field32(&reg, TBTT_SYNC_CFG_BCN_CWMIN, 4);
1338 rt2x00_set_field32(&reg, TBTT_SYNC_CFG_BCN_AIFSN, 2);
1339 rt2x00_set_field32(&reg, TBTT_SYNC_CFG_BCN_EXP_WIN, 32);
1340 rt2x00_set_field32(&reg, TBTT_SYNC_CFG_TBTT_ADJUST, 16);
1341 rt2800_register_write(rt2x00dev, TBTT_SYNC_CFG, reg);
1342 }
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001343 }
1344
1345 if (flags & CONFIG_UPDATE_MAC) {
Helmut Schaafa8b4b22010-11-04 20:42:36 +01001346 if (flags & CONFIG_UPDATE_TYPE &&
1347 conf->sync == TSF_SYNC_AP_NONE) {
1348 /*
1349 * The BSSID register has to be set to our own mac
1350 * address in AP mode.
1351 */
1352 memcpy(conf->bssid, conf->mac, sizeof(conf->mac));
1353 update_bssid = true;
1354 }
1355
Ivo van Doornc600c8262010-08-30 21:14:15 +02001356 if (!is_zero_ether_addr((const u8 *)conf->mac)) {
1357 reg = le32_to_cpu(conf->mac[1]);
1358 rt2x00_set_field32(&reg, MAC_ADDR_DW1_UNICAST_TO_ME_MASK, 0xff);
1359 conf->mac[1] = cpu_to_le32(reg);
1360 }
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001361
1362 rt2800_register_multiwrite(rt2x00dev, MAC_ADDR_DW0,
1363 conf->mac, sizeof(conf->mac));
1364 }
1365
Helmut Schaafa8b4b22010-11-04 20:42:36 +01001366 if ((flags & CONFIG_UPDATE_BSSID) || update_bssid) {
Ivo van Doornc600c8262010-08-30 21:14:15 +02001367 if (!is_zero_ether_addr((const u8 *)conf->bssid)) {
1368 reg = le32_to_cpu(conf->bssid[1]);
1369 rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_ID_MASK, 3);
1370 rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_BCN_NUM, 7);
1371 conf->bssid[1] = cpu_to_le32(reg);
1372 }
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001373
1374 rt2800_register_multiwrite(rt2x00dev, MAC_BSSID_DW0,
1375 conf->bssid, sizeof(conf->bssid));
1376 }
1377}
1378EXPORT_SYMBOL_GPL(rt2800_config_intf);
1379
Helmut Schaa87c19152010-10-02 11:28:34 +02001380static void rt2800_config_ht_opmode(struct rt2x00_dev *rt2x00dev,
1381 struct rt2x00lib_erp *erp)
1382{
1383 bool any_sta_nongf = !!(erp->ht_opmode &
1384 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
1385 u8 protection = erp->ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION;
1386 u8 mm20_mode, mm40_mode, gf20_mode, gf40_mode;
1387 u16 mm20_rate, mm40_rate, gf20_rate, gf40_rate;
1388 u32 reg;
1389
1390 /* default protection rate for HT20: OFDM 24M */
1391 mm20_rate = gf20_rate = 0x4004;
1392
1393 /* default protection rate for HT40: duplicate OFDM 24M */
1394 mm40_rate = gf40_rate = 0x4084;
1395
1396 switch (protection) {
1397 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
1398 /*
1399 * All STAs in this BSS are HT20/40 but there might be
1400 * STAs not supporting greenfield mode.
1401 * => Disable protection for HT transmissions.
1402 */
1403 mm20_mode = mm40_mode = gf20_mode = gf40_mode = 0;
1404
1405 break;
1406 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
1407 /*
1408 * All STAs in this BSS are HT20 or HT20/40 but there
1409 * might be STAs not supporting greenfield mode.
1410 * => Protect all HT40 transmissions.
1411 */
1412 mm20_mode = gf20_mode = 0;
1413 mm40_mode = gf40_mode = 2;
1414
1415 break;
1416 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
1417 /*
1418 * Nonmember protection:
1419 * According to 802.11n we _should_ protect all
1420 * HT transmissions (but we don't have to).
1421 *
1422 * But if cts_protection is enabled we _shall_ protect
1423 * all HT transmissions using a CCK rate.
1424 *
1425 * And if any station is non GF we _shall_ protect
1426 * GF transmissions.
1427 *
1428 * We decide to protect everything
1429 * -> fall through to mixed mode.
1430 */
1431 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
1432 /*
1433 * Legacy STAs are present
1434 * => Protect all HT transmissions.
1435 */
1436 mm20_mode = mm40_mode = gf20_mode = gf40_mode = 2;
1437
1438 /*
1439 * If erp protection is needed we have to protect HT
1440 * transmissions with CCK 11M long preamble.
1441 */
1442 if (erp->cts_protection) {
1443 /* don't duplicate RTS/CTS in CCK mode */
1444 mm20_rate = mm40_rate = 0x0003;
1445 gf20_rate = gf40_rate = 0x0003;
1446 }
1447 break;
Joe Perches6403eab2011-06-03 11:51:20 +00001448 }
Helmut Schaa87c19152010-10-02 11:28:34 +02001449
1450 /* check for STAs not supporting greenfield mode */
1451 if (any_sta_nongf)
1452 gf20_mode = gf40_mode = 2;
1453
1454 /* Update HT protection config */
1455 rt2800_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
1456 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_RATE, mm20_rate);
1457 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_CTRL, mm20_mode);
1458 rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
1459
1460 rt2800_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
1461 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_RATE, mm40_rate);
1462 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_CTRL, mm40_mode);
1463 rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
1464
1465 rt2800_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
1466 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_RATE, gf20_rate);
1467 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_CTRL, gf20_mode);
1468 rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
1469
1470 rt2800_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
1471 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_RATE, gf40_rate);
1472 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_CTRL, gf40_mode);
1473 rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
1474}
1475
Helmut Schaa02044642010-09-08 20:56:32 +02001476void rt2800_config_erp(struct rt2x00_dev *rt2x00dev, struct rt2x00lib_erp *erp,
1477 u32 changed)
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001478{
1479 u32 reg;
1480
Helmut Schaa02044642010-09-08 20:56:32 +02001481 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1482 rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, &reg);
1483 rt2x00_set_field32(&reg, AUTO_RSP_CFG_BAC_ACK_POLICY,
1484 !!erp->short_preamble);
1485 rt2x00_set_field32(&reg, AUTO_RSP_CFG_AR_PREAMBLE,
1486 !!erp->short_preamble);
1487 rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
1488 }
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001489
Helmut Schaa02044642010-09-08 20:56:32 +02001490 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1491 rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
1492 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL,
1493 erp->cts_protection ? 2 : 0);
1494 rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
1495 }
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001496
Helmut Schaa02044642010-09-08 20:56:32 +02001497 if (changed & BSS_CHANGED_BASIC_RATES) {
1498 rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE,
1499 erp->basic_rates);
1500 rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
1501 }
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001502
Helmut Schaa02044642010-09-08 20:56:32 +02001503 if (changed & BSS_CHANGED_ERP_SLOT) {
1504 rt2800_register_read(rt2x00dev, BKOFF_SLOT_CFG, &reg);
1505 rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_SLOT_TIME,
1506 erp->slot_time);
1507 rt2800_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001508
Helmut Schaa02044642010-09-08 20:56:32 +02001509 rt2800_register_read(rt2x00dev, XIFS_TIME_CFG, &reg);
1510 rt2x00_set_field32(&reg, XIFS_TIME_CFG_EIFS, erp->eifs);
1511 rt2800_register_write(rt2x00dev, XIFS_TIME_CFG, reg);
1512 }
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001513
Helmut Schaa02044642010-09-08 20:56:32 +02001514 if (changed & BSS_CHANGED_BEACON_INT) {
1515 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
1516 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL,
1517 erp->beacon_int * 16);
1518 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
1519 }
Helmut Schaa87c19152010-10-02 11:28:34 +02001520
1521 if (changed & BSS_CHANGED_HT)
1522 rt2800_config_ht_opmode(rt2x00dev, erp);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001523}
1524EXPORT_SYMBOL_GPL(rt2800_config_erp);
1525
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02001526static void rt2800_config_3572bt_ant(struct rt2x00_dev *rt2x00dev)
1527{
1528 u32 reg;
1529 u16 eeprom;
1530 u8 led_ctrl, led_g_mode, led_r_mode;
1531
1532 rt2800_register_read(rt2x00dev, GPIO_SWITCH, &reg);
1533 if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ) {
1534 rt2x00_set_field32(&reg, GPIO_SWITCH_0, 1);
1535 rt2x00_set_field32(&reg, GPIO_SWITCH_1, 1);
1536 } else {
1537 rt2x00_set_field32(&reg, GPIO_SWITCH_0, 0);
1538 rt2x00_set_field32(&reg, GPIO_SWITCH_1, 0);
1539 }
1540 rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg);
1541
1542 rt2800_register_read(rt2x00dev, LED_CFG, &reg);
1543 led_g_mode = rt2x00_get_field32(reg, LED_CFG_LED_POLAR) ? 3 : 0;
1544 led_r_mode = rt2x00_get_field32(reg, LED_CFG_LED_POLAR) ? 0 : 3;
1545 if (led_g_mode != rt2x00_get_field32(reg, LED_CFG_G_LED_MODE) ||
1546 led_r_mode != rt2x00_get_field32(reg, LED_CFG_R_LED_MODE)) {
1547 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
1548 led_ctrl = rt2x00_get_field16(eeprom, EEPROM_FREQ_LED_MODE);
1549 if (led_ctrl == 0 || led_ctrl > 0x40) {
1550 rt2x00_set_field32(&reg, LED_CFG_G_LED_MODE, led_g_mode);
1551 rt2x00_set_field32(&reg, LED_CFG_R_LED_MODE, led_r_mode);
1552 rt2800_register_write(rt2x00dev, LED_CFG, reg);
1553 } else {
1554 rt2800_mcu_request(rt2x00dev, MCU_BAND_SELECT, 0xff,
1555 (led_g_mode << 2) | led_r_mode, 1);
1556 }
1557 }
1558}
1559
RA-Jay Hungd96aa642011-02-20 13:54:52 +01001560static void rt2800_set_ant_diversity(struct rt2x00_dev *rt2x00dev,
1561 enum antenna ant)
1562{
1563 u32 reg;
1564 u8 eesk_pin = (ant == ANTENNA_A) ? 1 : 0;
1565 u8 gpio_bit3 = (ant == ANTENNA_A) ? 0 : 1;
1566
1567 if (rt2x00_is_pci(rt2x00dev)) {
1568 rt2800_register_read(rt2x00dev, E2PROM_CSR, &reg);
1569 rt2x00_set_field32(&reg, E2PROM_CSR_DATA_CLOCK, eesk_pin);
1570 rt2800_register_write(rt2x00dev, E2PROM_CSR, reg);
1571 } else if (rt2x00_is_usb(rt2x00dev))
1572 rt2800_mcu_request(rt2x00dev, MCU_ANT_SELECT, 0xff,
1573 eesk_pin, 0);
1574
Gertjan van Wingerde99bdf512012-08-31 19:22:13 +02001575 rt2800_register_read(rt2x00dev, GPIO_CTRL, &reg);
1576 rt2x00_set_field32(&reg, GPIO_CTRL_DIR3, 0);
1577 rt2x00_set_field32(&reg, GPIO_CTRL_VAL3, gpio_bit3);
1578 rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
RA-Jay Hungd96aa642011-02-20 13:54:52 +01001579}
1580
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001581void rt2800_config_ant(struct rt2x00_dev *rt2x00dev, struct antenna_setup *ant)
1582{
1583 u8 r1;
1584 u8 r3;
RA-Jay Hungd96aa642011-02-20 13:54:52 +01001585 u16 eeprom;
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001586
1587 rt2800_bbp_read(rt2x00dev, 1, &r1);
1588 rt2800_bbp_read(rt2x00dev, 3, &r3);
1589
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02001590 if (rt2x00_rt(rt2x00dev, RT3572) &&
1591 test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags))
1592 rt2800_config_3572bt_ant(rt2x00dev);
1593
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001594 /*
1595 * Configure the TX antenna.
1596 */
RA-Jay Hungd96aa642011-02-20 13:54:52 +01001597 switch (ant->tx_chain_num) {
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001598 case 1:
1599 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001600 break;
1601 case 2:
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02001602 if (rt2x00_rt(rt2x00dev, RT3572) &&
1603 test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags))
1604 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 1);
1605 else
1606 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001607 break;
1608 case 3:
Ivo van Doorne22557f2010-06-29 21:49:05 +02001609 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001610 break;
1611 }
1612
1613 /*
1614 * Configure the RX antenna.
1615 */
RA-Jay Hungd96aa642011-02-20 13:54:52 +01001616 switch (ant->rx_chain_num) {
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001617 case 1:
RA-Jay Hungd96aa642011-02-20 13:54:52 +01001618 if (rt2x00_rt(rt2x00dev, RT3070) ||
1619 rt2x00_rt(rt2x00dev, RT3090) ||
Daniel Golle03839952012-09-09 14:24:39 +03001620 rt2x00_rt(rt2x00dev, RT3352) ||
RA-Jay Hungd96aa642011-02-20 13:54:52 +01001621 rt2x00_rt(rt2x00dev, RT3390)) {
1622 rt2x00_eeprom_read(rt2x00dev,
1623 EEPROM_NIC_CONF1, &eeprom);
1624 if (rt2x00_get_field16(eeprom,
1625 EEPROM_NIC_CONF1_ANT_DIVERSITY))
1626 rt2800_set_ant_diversity(rt2x00dev,
1627 rt2x00dev->default_ant.rx);
1628 }
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001629 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0);
1630 break;
1631 case 2:
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02001632 if (rt2x00_rt(rt2x00dev, RT3572) &&
1633 test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags)) {
1634 rt2x00_set_field8(&r3, BBP3_RX_ADC, 1);
1635 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA,
1636 rt2x00dev->curr_band == IEEE80211_BAND_5GHZ);
1637 rt2800_set_ant_diversity(rt2x00dev, ANTENNA_B);
1638 } else {
1639 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 1);
1640 }
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001641 break;
1642 case 3:
1643 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 2);
1644 break;
1645 }
1646
1647 rt2800_bbp_write(rt2x00dev, 3, r3);
1648 rt2800_bbp_write(rt2x00dev, 1, r1);
1649}
1650EXPORT_SYMBOL_GPL(rt2800_config_ant);
1651
1652static void rt2800_config_lna_gain(struct rt2x00_dev *rt2x00dev,
1653 struct rt2x00lib_conf *libconf)
1654{
1655 u16 eeprom;
1656 short lna_gain;
1657
1658 if (libconf->rf.channel <= 14) {
1659 rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
1660 lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_BG);
1661 } else if (libconf->rf.channel <= 64) {
1662 rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
1663 lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_A0);
1664 } else if (libconf->rf.channel <= 128) {
1665 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom);
1666 lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG2_LNA_A1);
1667 } else {
1668 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom);
1669 lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_A2_LNA_A2);
1670 }
1671
1672 rt2x00dev->lna_gain = lna_gain;
1673}
1674
Gertjan van Wingerde06855ef2010-04-11 14:31:07 +02001675static void rt2800_config_channel_rf2xxx(struct rt2x00_dev *rt2x00dev,
1676 struct ieee80211_conf *conf,
1677 struct rf_channel *rf,
1678 struct channel_info *info)
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001679{
1680 rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
1681
RA-Jay Hungd96aa642011-02-20 13:54:52 +01001682 if (rt2x00dev->default_ant.tx_chain_num == 1)
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001683 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_TX1, 1);
1684
RA-Jay Hungd96aa642011-02-20 13:54:52 +01001685 if (rt2x00dev->default_ant.rx_chain_num == 1) {
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001686 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX1, 1);
1687 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
RA-Jay Hungd96aa642011-02-20 13:54:52 +01001688 } else if (rt2x00dev->default_ant.rx_chain_num == 2)
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001689 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
1690
1691 if (rf->channel > 14) {
1692 /*
1693 * When TX power is below 0, we should increase it by 7 to
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001694 * make it a positive value (Minimum value is -7).
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001695 * However this means that values between 0 and 7 have
1696 * double meaning, and we should set a 7DBm boost flag.
1697 */
1698 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A_7DBM_BOOST,
Ivo van Doorn8d1331b2010-08-23 19:56:07 +02001699 (info->default_power1 >= 0));
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001700
Ivo van Doorn8d1331b2010-08-23 19:56:07 +02001701 if (info->default_power1 < 0)
1702 info->default_power1 += 7;
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001703
Ivo van Doorn8d1331b2010-08-23 19:56:07 +02001704 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A, info->default_power1);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001705
1706 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A_7DBM_BOOST,
Ivo van Doorn8d1331b2010-08-23 19:56:07 +02001707 (info->default_power2 >= 0));
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001708
Ivo van Doorn8d1331b2010-08-23 19:56:07 +02001709 if (info->default_power2 < 0)
1710 info->default_power2 += 7;
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001711
Ivo van Doorn8d1331b2010-08-23 19:56:07 +02001712 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A, info->default_power2);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001713 } else {
Ivo van Doorn8d1331b2010-08-23 19:56:07 +02001714 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_G, info->default_power1);
1715 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_G, info->default_power2);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001716 }
1717
1718 rt2x00_set_field32(&rf->rf4, RF4_HT40, conf_is_ht40(conf));
1719
1720 rt2800_rf_write(rt2x00dev, 1, rf->rf1);
1721 rt2800_rf_write(rt2x00dev, 2, rf->rf2);
1722 rt2800_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
1723 rt2800_rf_write(rt2x00dev, 4, rf->rf4);
1724
1725 udelay(200);
1726
1727 rt2800_rf_write(rt2x00dev, 1, rf->rf1);
1728 rt2800_rf_write(rt2x00dev, 2, rf->rf2);
1729 rt2800_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
1730 rt2800_rf_write(rt2x00dev, 4, rf->rf4);
1731
1732 udelay(200);
1733
1734 rt2800_rf_write(rt2x00dev, 1, rf->rf1);
1735 rt2800_rf_write(rt2x00dev, 2, rf->rf2);
1736 rt2800_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
1737 rt2800_rf_write(rt2x00dev, 4, rf->rf4);
1738}
1739
Gertjan van Wingerde06855ef2010-04-11 14:31:07 +02001740static void rt2800_config_channel_rf3xxx(struct rt2x00_dev *rt2x00dev,
1741 struct ieee80211_conf *conf,
1742 struct rf_channel *rf,
1743 struct channel_info *info)
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001744{
Gertjan van Wingerde3a1c0122012-02-06 23:45:07 +01001745 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
Stanislaw Gruszkaf1f12f92012-01-30 16:17:59 +01001746 u8 rfcsr, calib_tx, calib_rx;
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001747
1748 rt2800_rfcsr_write(rt2x00dev, 2, rf->rf1);
Stanislaw Gruszka7f4666a2012-01-30 16:17:56 +01001749
1750 rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr);
1751 rt2x00_set_field8(&rfcsr, RFCSR3_K, rf->rf3);
1752 rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001753
1754 rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr);
Gertjan van Wingerdefab799c2010-04-11 14:31:08 +02001755 rt2x00_set_field8(&rfcsr, RFCSR6_R1, rf->rf2);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001756 rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
1757
1758 rt2800_rfcsr_read(rt2x00dev, 12, &rfcsr);
Ivo van Doorn8d1331b2010-08-23 19:56:07 +02001759 rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER, info->default_power1);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001760 rt2800_rfcsr_write(rt2x00dev, 12, rfcsr);
1761
Helmut Schaa5a673962010-04-23 15:54:43 +02001762 rt2800_rfcsr_read(rt2x00dev, 13, &rfcsr);
Ivo van Doorn8d1331b2010-08-23 19:56:07 +02001763 rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER, info->default_power2);
Helmut Schaa5a673962010-04-23 15:54:43 +02001764 rt2800_rfcsr_write(rt2x00dev, 13, rfcsr);
1765
Stanislaw Gruszkae3bab192012-01-30 16:17:57 +01001766 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
1767 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0);
Gertjan van Wingerde7ad63032012-09-16 22:29:53 +02001768 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD,
1769 rt2x00dev->default_ant.rx_chain_num <= 1);
1770 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD,
1771 rt2x00dev->default_ant.rx_chain_num <= 2);
Stanislaw Gruszkae3bab192012-01-30 16:17:57 +01001772 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0);
Gertjan van Wingerde7ad63032012-09-16 22:29:53 +02001773 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD,
1774 rt2x00dev->default_ant.tx_chain_num <= 1);
1775 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD,
1776 rt2x00dev->default_ant.tx_chain_num <= 2);
Stanislaw Gruszkae3bab192012-01-30 16:17:57 +01001777 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
1778
Stanislaw Gruszka3e0c7642012-01-30 16:17:58 +01001779 rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
1780 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1);
1781 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
1782 msleep(1);
1783 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0);
1784 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
1785
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001786 rt2800_rfcsr_read(rt2x00dev, 23, &rfcsr);
1787 rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset);
1788 rt2800_rfcsr_write(rt2x00dev, 23, rfcsr);
1789
Stanislaw Gruszkaf1f12f92012-01-30 16:17:59 +01001790 if (rt2x00_rt(rt2x00dev, RT3390)) {
1791 calib_tx = conf_is_ht40(conf) ? 0x68 : 0x4f;
1792 calib_rx = conf_is_ht40(conf) ? 0x6f : 0x4f;
1793 } else {
Gertjan van Wingerde3a1c0122012-02-06 23:45:07 +01001794 if (conf_is_ht40(conf)) {
1795 calib_tx = drv_data->calibration_bw40;
1796 calib_rx = drv_data->calibration_bw40;
1797 } else {
1798 calib_tx = drv_data->calibration_bw20;
1799 calib_rx = drv_data->calibration_bw20;
1800 }
Stanislaw Gruszkaf1f12f92012-01-30 16:17:59 +01001801 }
1802
1803 rt2800_rfcsr_read(rt2x00dev, 24, &rfcsr);
1804 rt2x00_set_field8(&rfcsr, RFCSR24_TX_CALIB, calib_tx);
1805 rt2800_rfcsr_write(rt2x00dev, 24, rfcsr);
1806
1807 rt2800_rfcsr_read(rt2x00dev, 31, &rfcsr);
1808 rt2x00_set_field8(&rfcsr, RFCSR31_RX_CALIB, calib_rx);
1809 rt2800_rfcsr_write(rt2x00dev, 31, rfcsr);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001810
Gertjan van Wingerde71976902010-03-24 21:42:36 +01001811 rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001812 rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
Gertjan van Wingerde71976902010-03-24 21:42:36 +01001813 rt2800_rfcsr_write(rt2x00dev, 7, rfcsr);
Stanislaw Gruszka3e0c7642012-01-30 16:17:58 +01001814
1815 rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
1816 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1);
1817 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
1818 msleep(1);
1819 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0);
1820 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01001821}
1822
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02001823static void rt2800_config_channel_rf3052(struct rt2x00_dev *rt2x00dev,
1824 struct ieee80211_conf *conf,
1825 struct rf_channel *rf,
1826 struct channel_info *info)
1827{
Gertjan van Wingerde3a1c0122012-02-06 23:45:07 +01001828 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02001829 u8 rfcsr;
1830 u32 reg;
1831
1832 if (rf->channel <= 14) {
Gertjan van Wingerde5d137df2012-02-06 23:45:09 +01001833 rt2800_bbp_write(rt2x00dev, 25, drv_data->bbp25);
1834 rt2800_bbp_write(rt2x00dev, 26, drv_data->bbp26);
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02001835 } else {
1836 rt2800_bbp_write(rt2x00dev, 25, 0x09);
1837 rt2800_bbp_write(rt2x00dev, 26, 0xff);
1838 }
1839
1840 rt2800_rfcsr_write(rt2x00dev, 2, rf->rf1);
1841 rt2800_rfcsr_write(rt2x00dev, 3, rf->rf3);
1842
1843 rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr);
1844 rt2x00_set_field8(&rfcsr, RFCSR6_R1, rf->rf2);
1845 if (rf->channel <= 14)
1846 rt2x00_set_field8(&rfcsr, RFCSR6_TXDIV, 2);
1847 else
1848 rt2x00_set_field8(&rfcsr, RFCSR6_TXDIV, 1);
1849 rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
1850
1851 rt2800_rfcsr_read(rt2x00dev, 5, &rfcsr);
1852 if (rf->channel <= 14)
1853 rt2x00_set_field8(&rfcsr, RFCSR5_R1, 1);
1854 else
1855 rt2x00_set_field8(&rfcsr, RFCSR5_R1, 2);
1856 rt2800_rfcsr_write(rt2x00dev, 5, rfcsr);
1857
1858 rt2800_rfcsr_read(rt2x00dev, 12, &rfcsr);
1859 if (rf->channel <= 14) {
1860 rt2x00_set_field8(&rfcsr, RFCSR12_DR0, 3);
1861 rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER,
Gertjan van Wingerde569ffa52012-02-06 23:45:10 +01001862 info->default_power1);
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02001863 } else {
1864 rt2x00_set_field8(&rfcsr, RFCSR12_DR0, 7);
1865 rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER,
1866 (info->default_power1 & 0x3) |
1867 ((info->default_power1 & 0xC) << 1));
1868 }
1869 rt2800_rfcsr_write(rt2x00dev, 12, rfcsr);
1870
1871 rt2800_rfcsr_read(rt2x00dev, 13, &rfcsr);
1872 if (rf->channel <= 14) {
1873 rt2x00_set_field8(&rfcsr, RFCSR13_DR0, 3);
1874 rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER,
Gertjan van Wingerde569ffa52012-02-06 23:45:10 +01001875 info->default_power2);
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02001876 } else {
1877 rt2x00_set_field8(&rfcsr, RFCSR13_DR0, 7);
1878 rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER,
1879 (info->default_power2 & 0x3) |
1880 ((info->default_power2 & 0xC) << 1));
1881 }
1882 rt2800_rfcsr_write(rt2x00dev, 13, rfcsr);
1883
1884 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02001885 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0);
1886 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0);
1887 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 0);
1888 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 0);
Gertjan van Wingerde0cd461e2012-02-06 23:45:11 +01001889 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0);
1890 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0);
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02001891 if (test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags)) {
1892 if (rf->channel <= 14) {
1893 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1);
1894 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1);
1895 }
1896 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 1);
1897 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 1);
1898 } else {
1899 switch (rt2x00dev->default_ant.tx_chain_num) {
1900 case 1:
1901 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
1902 case 2:
1903 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 1);
1904 break;
1905 }
1906
1907 switch (rt2x00dev->default_ant.rx_chain_num) {
1908 case 1:
1909 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
1910 case 2:
1911 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 1);
1912 break;
1913 }
1914 }
1915 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
1916
1917 rt2800_rfcsr_read(rt2x00dev, 23, &rfcsr);
1918 rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset);
1919 rt2800_rfcsr_write(rt2x00dev, 23, rfcsr);
1920
Gertjan van Wingerde3a1c0122012-02-06 23:45:07 +01001921 if (conf_is_ht40(conf)) {
1922 rt2800_rfcsr_write(rt2x00dev, 24, drv_data->calibration_bw40);
1923 rt2800_rfcsr_write(rt2x00dev, 31, drv_data->calibration_bw40);
1924 } else {
1925 rt2800_rfcsr_write(rt2x00dev, 24, drv_data->calibration_bw20);
1926 rt2800_rfcsr_write(rt2x00dev, 31, drv_data->calibration_bw20);
1927 }
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02001928
1929 if (rf->channel <= 14) {
1930 rt2800_rfcsr_write(rt2x00dev, 7, 0xd8);
1931 rt2800_rfcsr_write(rt2x00dev, 9, 0xc3);
1932 rt2800_rfcsr_write(rt2x00dev, 10, 0xf1);
1933 rt2800_rfcsr_write(rt2x00dev, 11, 0xb9);
1934 rt2800_rfcsr_write(rt2x00dev, 15, 0x53);
Gertjan van Wingerde77c06c22012-02-06 23:45:13 +01001935 rfcsr = 0x4c;
1936 rt2x00_set_field8(&rfcsr, RFCSR16_TXMIXER_GAIN,
1937 drv_data->txmixer_gain_24g);
1938 rt2800_rfcsr_write(rt2x00dev, 16, rfcsr);
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02001939 rt2800_rfcsr_write(rt2x00dev, 17, 0x23);
1940 rt2800_rfcsr_write(rt2x00dev, 19, 0x93);
1941 rt2800_rfcsr_write(rt2x00dev, 20, 0xb3);
1942 rt2800_rfcsr_write(rt2x00dev, 25, 0x15);
1943 rt2800_rfcsr_write(rt2x00dev, 26, 0x85);
1944 rt2800_rfcsr_write(rt2x00dev, 27, 0x00);
1945 rt2800_rfcsr_write(rt2x00dev, 29, 0x9b);
1946 } else {
Gertjan van Wingerde58b8ae12012-02-06 23:45:12 +01001947 rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr);
1948 rt2x00_set_field8(&rfcsr, RFCSR7_BIT2, 1);
1949 rt2x00_set_field8(&rfcsr, RFCSR7_BIT3, 0);
1950 rt2x00_set_field8(&rfcsr, RFCSR7_BIT4, 1);
1951 rt2x00_set_field8(&rfcsr, RFCSR7_BITS67, 0);
1952 rt2800_rfcsr_write(rt2x00dev, 7, rfcsr);
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02001953 rt2800_rfcsr_write(rt2x00dev, 9, 0xc0);
1954 rt2800_rfcsr_write(rt2x00dev, 10, 0xf1);
1955 rt2800_rfcsr_write(rt2x00dev, 11, 0x00);
1956 rt2800_rfcsr_write(rt2x00dev, 15, 0x43);
Gertjan van Wingerde77c06c22012-02-06 23:45:13 +01001957 rfcsr = 0x7a;
1958 rt2x00_set_field8(&rfcsr, RFCSR16_TXMIXER_GAIN,
1959 drv_data->txmixer_gain_5g);
1960 rt2800_rfcsr_write(rt2x00dev, 16, rfcsr);
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02001961 rt2800_rfcsr_write(rt2x00dev, 17, 0x23);
1962 if (rf->channel <= 64) {
1963 rt2800_rfcsr_write(rt2x00dev, 19, 0xb7);
1964 rt2800_rfcsr_write(rt2x00dev, 20, 0xf6);
1965 rt2800_rfcsr_write(rt2x00dev, 25, 0x3d);
1966 } else if (rf->channel <= 128) {
1967 rt2800_rfcsr_write(rt2x00dev, 19, 0x74);
1968 rt2800_rfcsr_write(rt2x00dev, 20, 0xf4);
1969 rt2800_rfcsr_write(rt2x00dev, 25, 0x01);
1970 } else {
1971 rt2800_rfcsr_write(rt2x00dev, 19, 0x72);
1972 rt2800_rfcsr_write(rt2x00dev, 20, 0xf3);
1973 rt2800_rfcsr_write(rt2x00dev, 25, 0x01);
1974 }
1975 rt2800_rfcsr_write(rt2x00dev, 26, 0x87);
1976 rt2800_rfcsr_write(rt2x00dev, 27, 0x01);
1977 rt2800_rfcsr_write(rt2x00dev, 29, 0x9f);
1978 }
1979
Gertjan van Wingerde99bdf512012-08-31 19:22:13 +02001980 rt2800_register_read(rt2x00dev, GPIO_CTRL, &reg);
1981 rt2x00_set_field32(&reg, GPIO_CTRL_DIR7, 0);
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02001982 if (rf->channel <= 14)
Gertjan van Wingerde99bdf512012-08-31 19:22:13 +02001983 rt2x00_set_field32(&reg, GPIO_CTRL_VAL7, 1);
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02001984 else
Gertjan van Wingerde99bdf512012-08-31 19:22:13 +02001985 rt2x00_set_field32(&reg, GPIO_CTRL_VAL7, 0);
1986 rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02001987
1988 rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr);
1989 rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
1990 rt2800_rfcsr_write(rt2x00dev, 7, rfcsr);
1991}
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01001992
Stanislaw Gruszka7573cb5b2012-07-09 14:41:48 +02001993#define POWER_BOUND 0x27
Stanislaw Gruszka8f821092013-03-16 19:19:32 +01001994#define POWER_BOUND_5G 0x2b
Stanislaw Gruszka7573cb5b2012-07-09 14:41:48 +02001995#define FREQ_OFFSET_BOUND 0x5f
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01001996
Stanislaw Gruszka0c9e5fb2013-03-16 19:19:36 +01001997static void rt2800_adjust_freq_offset(struct rt2x00_dev *rt2x00dev)
1998{
1999 u8 rfcsr;
2000
2001 rt2800_rfcsr_read(rt2x00dev, 17, &rfcsr);
2002 if (rt2x00dev->freq_offset > FREQ_OFFSET_BOUND)
2003 rt2x00_set_field8(&rfcsr, RFCSR17_CODE, FREQ_OFFSET_BOUND);
2004 else
2005 rt2x00_set_field8(&rfcsr, RFCSR17_CODE, rt2x00dev->freq_offset);
2006 rt2800_rfcsr_write(rt2x00dev, 17, rfcsr);
2007}
2008
Woody Hunga89534e2012-06-13 15:01:16 +08002009static void rt2800_config_channel_rf3290(struct rt2x00_dev *rt2x00dev,
2010 struct ieee80211_conf *conf,
2011 struct rf_channel *rf,
2012 struct channel_info *info)
2013{
2014 u8 rfcsr;
2015
2016 rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1);
2017 rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3);
2018 rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr);
2019 rt2x00_set_field8(&rfcsr, RFCSR11_R, rf->rf2);
2020 rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
2021
2022 rt2800_rfcsr_read(rt2x00dev, 49, &rfcsr);
Stanislaw Gruszka7573cb5b2012-07-09 14:41:48 +02002023 if (info->default_power1 > POWER_BOUND)
2024 rt2x00_set_field8(&rfcsr, RFCSR49_TX, POWER_BOUND);
Woody Hunga89534e2012-06-13 15:01:16 +08002025 else
2026 rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1);
2027 rt2800_rfcsr_write(rt2x00dev, 49, rfcsr);
2028
Stanislaw Gruszka0c9e5fb2013-03-16 19:19:36 +01002029 rt2800_adjust_freq_offset(rt2x00dev);
Woody Hunga89534e2012-06-13 15:01:16 +08002030
2031 if (rf->channel <= 14) {
2032 if (rf->channel == 6)
2033 rt2800_bbp_write(rt2x00dev, 68, 0x0c);
2034 else
2035 rt2800_bbp_write(rt2x00dev, 68, 0x0b);
2036
2037 if (rf->channel >= 1 && rf->channel <= 6)
2038 rt2800_bbp_write(rt2x00dev, 59, 0x0f);
2039 else if (rf->channel >= 7 && rf->channel <= 11)
2040 rt2800_bbp_write(rt2x00dev, 59, 0x0e);
2041 else if (rf->channel >= 12 && rf->channel <= 14)
2042 rt2800_bbp_write(rt2x00dev, 59, 0x0d);
2043 }
2044}
2045
Daniel Golle03839952012-09-09 14:24:39 +03002046static void rt2800_config_channel_rf3322(struct rt2x00_dev *rt2x00dev,
2047 struct ieee80211_conf *conf,
2048 struct rf_channel *rf,
2049 struct channel_info *info)
2050{
2051 u8 rfcsr;
2052
2053 rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1);
2054 rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3);
2055
2056 rt2800_rfcsr_write(rt2x00dev, 11, 0x42);
2057 rt2800_rfcsr_write(rt2x00dev, 12, 0x1c);
2058 rt2800_rfcsr_write(rt2x00dev, 13, 0x00);
2059
2060 if (info->default_power1 > POWER_BOUND)
2061 rt2800_rfcsr_write(rt2x00dev, 47, POWER_BOUND);
2062 else
2063 rt2800_rfcsr_write(rt2x00dev, 47, info->default_power1);
2064
2065 if (info->default_power2 > POWER_BOUND)
2066 rt2800_rfcsr_write(rt2x00dev, 48, POWER_BOUND);
2067 else
2068 rt2800_rfcsr_write(rt2x00dev, 48, info->default_power2);
2069
Stanislaw Gruszka0c9e5fb2013-03-16 19:19:36 +01002070 rt2800_adjust_freq_offset(rt2x00dev);
Daniel Golle03839952012-09-09 14:24:39 +03002071
2072 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
2073 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1);
2074 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1);
2075
2076 if ( rt2x00dev->default_ant.tx_chain_num == 2 )
2077 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
2078 else
2079 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 0);
2080
2081 if ( rt2x00dev->default_ant.rx_chain_num == 2 )
2082 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
2083 else
2084 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 0);
2085
2086 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0);
2087 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0);
2088
2089 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
2090
2091 rt2800_rfcsr_write(rt2x00dev, 31, 80);
2092}
2093
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01002094static void rt2800_config_channel_rf53xx(struct rt2x00_dev *rt2x00dev,
Gabor Juhosadde5882011-03-03 11:46:45 +01002095 struct ieee80211_conf *conf,
2096 struct rf_channel *rf,
2097 struct channel_info *info)
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01002098{
Gabor Juhosadde5882011-03-03 11:46:45 +01002099 u8 rfcsr;
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01002100
Gabor Juhosadde5882011-03-03 11:46:45 +01002101 rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1);
2102 rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3);
2103 rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr);
2104 rt2x00_set_field8(&rfcsr, RFCSR11_R, rf->rf2);
2105 rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01002106
Gabor Juhosadde5882011-03-03 11:46:45 +01002107 rt2800_rfcsr_read(rt2x00dev, 49, &rfcsr);
Stanislaw Gruszka7573cb5b2012-07-09 14:41:48 +02002108 if (info->default_power1 > POWER_BOUND)
2109 rt2x00_set_field8(&rfcsr, RFCSR49_TX, POWER_BOUND);
Gabor Juhosadde5882011-03-03 11:46:45 +01002110 else
2111 rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1);
2112 rt2800_rfcsr_write(rt2x00dev, 49, rfcsr);
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01002113
Zero.Lincff3d1f2012-05-29 16:11:09 +08002114 if (rt2x00_rt(rt2x00dev, RT5392)) {
2115 rt2800_rfcsr_read(rt2x00dev, 50, &rfcsr);
Stanislaw Gruszka7573cb5b2012-07-09 14:41:48 +02002116 if (info->default_power1 > POWER_BOUND)
2117 rt2x00_set_field8(&rfcsr, RFCSR50_TX, POWER_BOUND);
Zero.Lincff3d1f2012-05-29 16:11:09 +08002118 else
2119 rt2x00_set_field8(&rfcsr, RFCSR50_TX,
2120 info->default_power2);
2121 rt2800_rfcsr_write(rt2x00dev, 50, rfcsr);
2122 }
2123
Gabor Juhosadde5882011-03-03 11:46:45 +01002124 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
Zero.Lincff3d1f2012-05-29 16:11:09 +08002125 if (rt2x00_rt(rt2x00dev, RT5392)) {
2126 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
2127 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
2128 }
Gabor Juhosadde5882011-03-03 11:46:45 +01002129 rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
2130 rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1);
2131 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1);
2132 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1);
2133 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01002134
Stanislaw Gruszka0c9e5fb2013-03-16 19:19:36 +01002135 rt2800_adjust_freq_offset(rt2x00dev);
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01002136
Gabor Juhosadde5882011-03-03 11:46:45 +01002137 if (rf->channel <= 14) {
2138 int idx = rf->channel-1;
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01002139
Gertjan van Wingerdefdbc7b02011-04-30 17:15:37 +02002140 if (test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags)) {
Gabor Juhosadde5882011-03-03 11:46:45 +01002141 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) {
2142 /* r55/r59 value array of channel 1~14 */
2143 static const char r55_bt_rev[] = {0x83, 0x83,
2144 0x83, 0x73, 0x73, 0x63, 0x53, 0x53,
2145 0x53, 0x43, 0x43, 0x43, 0x43, 0x43};
2146 static const char r59_bt_rev[] = {0x0e, 0x0e,
2147 0x0e, 0x0e, 0x0e, 0x0b, 0x0a, 0x09,
2148 0x07, 0x07, 0x07, 0x07, 0x07, 0x07};
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01002149
Gabor Juhosadde5882011-03-03 11:46:45 +01002150 rt2800_rfcsr_write(rt2x00dev, 55,
2151 r55_bt_rev[idx]);
2152 rt2800_rfcsr_write(rt2x00dev, 59,
2153 r59_bt_rev[idx]);
2154 } else {
2155 static const char r59_bt[] = {0x8b, 0x8b, 0x8b,
2156 0x8b, 0x8b, 0x8b, 0x8b, 0x8a, 0x89,
2157 0x88, 0x88, 0x86, 0x85, 0x84};
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01002158
Gabor Juhosadde5882011-03-03 11:46:45 +01002159 rt2800_rfcsr_write(rt2x00dev, 59, r59_bt[idx]);
2160 }
2161 } else {
2162 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) {
2163 static const char r55_nonbt_rev[] = {0x23, 0x23,
2164 0x23, 0x23, 0x13, 0x13, 0x03, 0x03,
2165 0x03, 0x03, 0x03, 0x03, 0x03, 0x03};
2166 static const char r59_nonbt_rev[] = {0x07, 0x07,
2167 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
2168 0x07, 0x07, 0x06, 0x05, 0x04, 0x04};
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01002169
Gabor Juhosadde5882011-03-03 11:46:45 +01002170 rt2800_rfcsr_write(rt2x00dev, 55,
2171 r55_nonbt_rev[idx]);
2172 rt2800_rfcsr_write(rt2x00dev, 59,
2173 r59_nonbt_rev[idx]);
John Li2ed71882012-02-17 17:33:06 +08002174 } else if (rt2x00_rt(rt2x00dev, RT5390) ||
Gabor Juhose6d227b2012-12-02 15:53:28 +01002175 rt2x00_rt(rt2x00dev, RT5392)) {
Gabor Juhosadde5882011-03-03 11:46:45 +01002176 static const char r59_non_bt[] = {0x8f, 0x8f,
2177 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8d,
2178 0x8a, 0x88, 0x88, 0x87, 0x87, 0x86};
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01002179
Gabor Juhosadde5882011-03-03 11:46:45 +01002180 rt2800_rfcsr_write(rt2x00dev, 59,
2181 r59_non_bt[idx]);
2182 }
2183 }
2184 }
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01002185}
2186
Stanislaw Gruszka8f821092013-03-16 19:19:32 +01002187static void rt2800_config_channel_rf55xx(struct rt2x00_dev *rt2x00dev,
2188 struct ieee80211_conf *conf,
2189 struct rf_channel *rf,
2190 struct channel_info *info)
2191{
2192 u8 rfcsr, ep_reg;
Stanislaw Gruszkad5ae7a62013-03-16 19:19:42 +01002193 u32 reg;
Stanislaw Gruszka8f821092013-03-16 19:19:32 +01002194 int power_bound;
2195
2196 /* TODO */
2197 const bool is_11b = false;
2198 const bool is_type_ep = false;
2199
Stanislaw Gruszkad5ae7a62013-03-16 19:19:42 +01002200 rt2800_register_read(rt2x00dev, LDO_CFG0, &reg);
2201 rt2x00_set_field32(&reg, LDO_CFG0_LDO_CORE_VLEVEL,
2202 (rf->channel > 14 || conf_is_ht40(conf)) ? 5 : 0);
2203 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
Stanislaw Gruszka8f821092013-03-16 19:19:32 +01002204
2205 /* Order of values on rf_channel entry: N, K, mod, R */
2206 rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1 & 0xff);
2207
2208 rt2800_rfcsr_read(rt2x00dev, 9, &rfcsr);
2209 rt2x00_set_field8(&rfcsr, RFCSR9_K, rf->rf2 & 0xf);
2210 rt2x00_set_field8(&rfcsr, RFCSR9_N, (rf->rf1 & 0x100) >> 8);
2211 rt2x00_set_field8(&rfcsr, RFCSR9_MOD, ((rf->rf3 - 8) & 0x4) >> 2);
2212 rt2800_rfcsr_write(rt2x00dev, 9, rfcsr);
2213
2214 rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr);
2215 rt2x00_set_field8(&rfcsr, RFCSR11_R, rf->rf4 - 1);
2216 rt2x00_set_field8(&rfcsr, RFCSR11_MOD, (rf->rf3 - 8) & 0x3);
2217 rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
2218
2219 if (rf->channel <= 14) {
2220 rt2800_rfcsr_write(rt2x00dev, 10, 0x90);
2221 /* FIXME: RF11 owerwrite ? */
2222 rt2800_rfcsr_write(rt2x00dev, 11, 0x4A);
2223 rt2800_rfcsr_write(rt2x00dev, 12, 0x52);
2224 rt2800_rfcsr_write(rt2x00dev, 13, 0x42);
2225 rt2800_rfcsr_write(rt2x00dev, 22, 0x40);
2226 rt2800_rfcsr_write(rt2x00dev, 24, 0x4A);
2227 rt2800_rfcsr_write(rt2x00dev, 25, 0x80);
2228 rt2800_rfcsr_write(rt2x00dev, 27, 0x42);
2229 rt2800_rfcsr_write(rt2x00dev, 36, 0x80);
2230 rt2800_rfcsr_write(rt2x00dev, 37, 0x08);
2231 rt2800_rfcsr_write(rt2x00dev, 38, 0x89);
2232 rt2800_rfcsr_write(rt2x00dev, 39, 0x1B);
2233 rt2800_rfcsr_write(rt2x00dev, 40, 0x0D);
2234 rt2800_rfcsr_write(rt2x00dev, 41, 0x9B);
2235 rt2800_rfcsr_write(rt2x00dev, 42, 0xD5);
2236 rt2800_rfcsr_write(rt2x00dev, 43, 0x72);
2237 rt2800_rfcsr_write(rt2x00dev, 44, 0x0E);
2238 rt2800_rfcsr_write(rt2x00dev, 45, 0xA2);
2239 rt2800_rfcsr_write(rt2x00dev, 46, 0x6B);
2240 rt2800_rfcsr_write(rt2x00dev, 48, 0x10);
2241 rt2800_rfcsr_write(rt2x00dev, 51, 0x3E);
2242 rt2800_rfcsr_write(rt2x00dev, 52, 0x48);
2243 rt2800_rfcsr_write(rt2x00dev, 54, 0x38);
2244 rt2800_rfcsr_write(rt2x00dev, 56, 0xA1);
2245 rt2800_rfcsr_write(rt2x00dev, 57, 0x00);
2246 rt2800_rfcsr_write(rt2x00dev, 58, 0x39);
2247 rt2800_rfcsr_write(rt2x00dev, 60, 0x45);
2248 rt2800_rfcsr_write(rt2x00dev, 61, 0x91);
2249 rt2800_rfcsr_write(rt2x00dev, 62, 0x39);
2250
2251 /* TODO RF27 <- tssi */
2252
2253 rfcsr = rf->channel <= 10 ? 0x07 : 0x06;
2254 rt2800_rfcsr_write(rt2x00dev, 23, rfcsr);
2255 rt2800_rfcsr_write(rt2x00dev, 59, rfcsr);
2256
2257 if (is_11b) {
2258 /* CCK */
2259 rt2800_rfcsr_write(rt2x00dev, 31, 0xF8);
2260 rt2800_rfcsr_write(rt2x00dev, 32, 0xC0);
2261 if (is_type_ep)
2262 rt2800_rfcsr_write(rt2x00dev, 55, 0x06);
2263 else
2264 rt2800_rfcsr_write(rt2x00dev, 55, 0x47);
2265 } else {
2266 /* OFDM */
2267 if (is_type_ep)
2268 rt2800_rfcsr_write(rt2x00dev, 55, 0x03);
2269 else
2270 rt2800_rfcsr_write(rt2x00dev, 55, 0x43);
2271 }
2272
2273 power_bound = POWER_BOUND;
2274 ep_reg = 0x2;
2275 } else {
2276 rt2800_rfcsr_write(rt2x00dev, 10, 0x97);
2277 /* FIMXE: RF11 overwrite */
2278 rt2800_rfcsr_write(rt2x00dev, 11, 0x40);
2279 rt2800_rfcsr_write(rt2x00dev, 25, 0xBF);
2280 rt2800_rfcsr_write(rt2x00dev, 27, 0x42);
2281 rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
2282 rt2800_rfcsr_write(rt2x00dev, 37, 0x04);
2283 rt2800_rfcsr_write(rt2x00dev, 38, 0x85);
2284 rt2800_rfcsr_write(rt2x00dev, 40, 0x42);
2285 rt2800_rfcsr_write(rt2x00dev, 41, 0xBB);
2286 rt2800_rfcsr_write(rt2x00dev, 42, 0xD7);
2287 rt2800_rfcsr_write(rt2x00dev, 45, 0x41);
2288 rt2800_rfcsr_write(rt2x00dev, 48, 0x00);
2289 rt2800_rfcsr_write(rt2x00dev, 57, 0x77);
2290 rt2800_rfcsr_write(rt2x00dev, 60, 0x05);
2291 rt2800_rfcsr_write(rt2x00dev, 61, 0x01);
2292
2293 /* TODO RF27 <- tssi */
2294
2295 if (rf->channel >= 36 && rf->channel <= 64) {
2296
2297 rt2800_rfcsr_write(rt2x00dev, 12, 0x2E);
2298 rt2800_rfcsr_write(rt2x00dev, 13, 0x22);
2299 rt2800_rfcsr_write(rt2x00dev, 22, 0x60);
2300 rt2800_rfcsr_write(rt2x00dev, 23, 0x7F);
2301 if (rf->channel <= 50)
2302 rt2800_rfcsr_write(rt2x00dev, 24, 0x09);
2303 else if (rf->channel >= 52)
2304 rt2800_rfcsr_write(rt2x00dev, 24, 0x07);
2305 rt2800_rfcsr_write(rt2x00dev, 39, 0x1C);
2306 rt2800_rfcsr_write(rt2x00dev, 43, 0x5B);
2307 rt2800_rfcsr_write(rt2x00dev, 44, 0X40);
2308 rt2800_rfcsr_write(rt2x00dev, 46, 0X00);
2309 rt2800_rfcsr_write(rt2x00dev, 51, 0xFE);
2310 rt2800_rfcsr_write(rt2x00dev, 52, 0x0C);
2311 rt2800_rfcsr_write(rt2x00dev, 54, 0xF8);
2312 if (rf->channel <= 50) {
2313 rt2800_rfcsr_write(rt2x00dev, 55, 0x06),
2314 rt2800_rfcsr_write(rt2x00dev, 56, 0xD3);
2315 } else if (rf->channel >= 52) {
2316 rt2800_rfcsr_write(rt2x00dev, 55, 0x04);
2317 rt2800_rfcsr_write(rt2x00dev, 56, 0xBB);
2318 }
2319
2320 rt2800_rfcsr_write(rt2x00dev, 58, 0x15);
2321 rt2800_rfcsr_write(rt2x00dev, 59, 0x7F);
2322 rt2800_rfcsr_write(rt2x00dev, 62, 0x15);
2323
2324 } else if (rf->channel >= 100 && rf->channel <= 165) {
2325
2326 rt2800_rfcsr_write(rt2x00dev, 12, 0x0E);
2327 rt2800_rfcsr_write(rt2x00dev, 13, 0x42);
2328 rt2800_rfcsr_write(rt2x00dev, 22, 0x40);
2329 if (rf->channel <= 153) {
2330 rt2800_rfcsr_write(rt2x00dev, 23, 0x3C);
2331 rt2800_rfcsr_write(rt2x00dev, 24, 0x06);
2332 } else if (rf->channel >= 155) {
2333 rt2800_rfcsr_write(rt2x00dev, 23, 0x38);
2334 rt2800_rfcsr_write(rt2x00dev, 24, 0x05);
2335 }
2336 if (rf->channel <= 138) {
2337 rt2800_rfcsr_write(rt2x00dev, 39, 0x1A);
2338 rt2800_rfcsr_write(rt2x00dev, 43, 0x3B);
2339 rt2800_rfcsr_write(rt2x00dev, 44, 0x20);
2340 rt2800_rfcsr_write(rt2x00dev, 46, 0x18);
2341 } else if (rf->channel >= 140) {
2342 rt2800_rfcsr_write(rt2x00dev, 39, 0x18);
2343 rt2800_rfcsr_write(rt2x00dev, 43, 0x1B);
2344 rt2800_rfcsr_write(rt2x00dev, 44, 0x10);
2345 rt2800_rfcsr_write(rt2x00dev, 46, 0X08);
2346 }
2347 if (rf->channel <= 124)
2348 rt2800_rfcsr_write(rt2x00dev, 51, 0xFC);
2349 else if (rf->channel >= 126)
2350 rt2800_rfcsr_write(rt2x00dev, 51, 0xEC);
2351 if (rf->channel <= 138)
2352 rt2800_rfcsr_write(rt2x00dev, 52, 0x06);
2353 else if (rf->channel >= 140)
2354 rt2800_rfcsr_write(rt2x00dev, 52, 0x06);
2355 rt2800_rfcsr_write(rt2x00dev, 54, 0xEB);
2356 if (rf->channel <= 138)
2357 rt2800_rfcsr_write(rt2x00dev, 55, 0x01);
2358 else if (rf->channel >= 140)
2359 rt2800_rfcsr_write(rt2x00dev, 55, 0x00);
2360 if (rf->channel <= 128)
2361 rt2800_rfcsr_write(rt2x00dev, 56, 0xBB);
2362 else if (rf->channel >= 130)
2363 rt2800_rfcsr_write(rt2x00dev, 56, 0xAB);
2364 if (rf->channel <= 116)
2365 rt2800_rfcsr_write(rt2x00dev, 58, 0x1D);
2366 else if (rf->channel >= 118)
2367 rt2800_rfcsr_write(rt2x00dev, 58, 0x15);
2368 if (rf->channel <= 138)
2369 rt2800_rfcsr_write(rt2x00dev, 59, 0x3F);
2370 else if (rf->channel >= 140)
2371 rt2800_rfcsr_write(rt2x00dev, 59, 0x7C);
2372 if (rf->channel <= 116)
2373 rt2800_rfcsr_write(rt2x00dev, 62, 0x1D);
2374 else if (rf->channel >= 118)
2375 rt2800_rfcsr_write(rt2x00dev, 62, 0x15);
2376 }
2377
2378 power_bound = POWER_BOUND_5G;
2379 ep_reg = 0x3;
2380 }
2381
2382 rt2800_rfcsr_read(rt2x00dev, 49, &rfcsr);
2383 if (info->default_power1 > power_bound)
2384 rt2x00_set_field8(&rfcsr, RFCSR49_TX, power_bound);
2385 else
2386 rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1);
2387 if (is_type_ep)
2388 rt2x00_set_field8(&rfcsr, RFCSR49_EP, ep_reg);
2389 rt2800_rfcsr_write(rt2x00dev, 49, rfcsr);
2390
2391 rt2800_rfcsr_read(rt2x00dev, 50, &rfcsr);
2392 if (info->default_power1 > power_bound)
2393 rt2x00_set_field8(&rfcsr, RFCSR50_TX, power_bound);
2394 else
2395 rt2x00_set_field8(&rfcsr, RFCSR50_TX, info->default_power2);
2396 if (is_type_ep)
2397 rt2x00_set_field8(&rfcsr, RFCSR50_EP, ep_reg);
2398 rt2800_rfcsr_write(rt2x00dev, 50, rfcsr);
2399
2400 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
2401 rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
2402 rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1);
2403
2404 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD,
2405 rt2x00dev->default_ant.tx_chain_num >= 1);
2406 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD,
2407 rt2x00dev->default_ant.tx_chain_num == 2);
2408 rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0);
2409
2410 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD,
2411 rt2x00dev->default_ant.rx_chain_num >= 1);
2412 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD,
2413 rt2x00dev->default_ant.rx_chain_num == 2);
2414 rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0);
2415
2416 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
2417 rt2800_rfcsr_write(rt2x00dev, 6, 0xe4);
2418
2419 if (conf_is_ht40(conf))
2420 rt2800_rfcsr_write(rt2x00dev, 30, 0x16);
2421 else
2422 rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
2423
2424 if (!is_11b) {
2425 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
2426 rt2800_rfcsr_write(rt2x00dev, 32, 0x80);
2427 }
2428
2429 /* TODO proper frequency adjustment */
Stanislaw Gruszka0c9e5fb2013-03-16 19:19:36 +01002430 rt2800_adjust_freq_offset(rt2x00dev);
Stanislaw Gruszka8f821092013-03-16 19:19:32 +01002431
2432 /* TODO merge with others */
2433 rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr);
2434 rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
2435 rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
Stanislaw Gruszka68031412013-03-16 19:19:44 +01002436
2437 /* BBP settings */
2438 rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
2439 rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
2440 rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
2441
2442 rt2800_bbp_write(rt2x00dev, 79, (rf->channel <= 14) ? 0x1C : 0x18);
2443 rt2800_bbp_write(rt2x00dev, 80, (rf->channel <= 14) ? 0x0E : 0x08);
2444 rt2800_bbp_write(rt2x00dev, 81, (rf->channel <= 14) ? 0x3A : 0x38);
2445 rt2800_bbp_write(rt2x00dev, 82, (rf->channel <= 14) ? 0x62 : 0x92);
2446
2447 /* GLRT band configuration */
2448 rt2800_bbp_write(rt2x00dev, 195, 128);
2449 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0xE0 : 0xF0);
2450 rt2800_bbp_write(rt2x00dev, 195, 129);
2451 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x1F : 0x1E);
2452 rt2800_bbp_write(rt2x00dev, 195, 130);
2453 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x38 : 0x28);
2454 rt2800_bbp_write(rt2x00dev, 195, 131);
2455 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x32 : 0x20);
2456 rt2800_bbp_write(rt2x00dev, 195, 133);
2457 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x28 : 0x7F);
2458 rt2800_bbp_write(rt2x00dev, 195, 124);
2459 rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x19 : 0x7F);
Stanislaw Gruszka8f821092013-03-16 19:19:32 +01002460}
2461
Stanislaw Gruszka5bc2dd02013-03-16 19:19:47 +01002462static void rt2800_bbp_write_with_rx_chain(struct rt2x00_dev *rt2x00dev,
2463 const unsigned int word,
2464 const u8 value)
2465{
2466 u8 chain, reg;
2467
2468 for (chain = 0; chain < rt2x00dev->default_ant.rx_chain_num; chain++) {
2469 rt2800_bbp_read(rt2x00dev, 27, &reg);
2470 rt2x00_set_field8(&reg, BBP27_RX_CHAIN_SEL, chain);
2471 rt2800_bbp_write(rt2x00dev, 27, reg);
2472
2473 rt2800_bbp_write(rt2x00dev, word, value);
2474 }
2475}
2476
Stanislaw Gruszka87561302013-03-16 19:19:45 +01002477static void rt2800_iq_calibrate(struct rt2x00_dev *rt2x00dev, int channel)
2478{
2479 u8 cal;
2480
Stanislaw Gruszka415e3f22013-03-16 19:19:52 +01002481 /* TX0 IQ Gain */
Stanislaw Gruszka87561302013-03-16 19:19:45 +01002482 rt2800_bbp_write(rt2x00dev, 158, 0x2c);
Stanislaw Gruszka415e3f22013-03-16 19:19:52 +01002483 if (channel <= 14)
2484 cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_GAIN_CAL_TX0_2G);
2485 else if (channel >= 36 && channel <= 64)
2486 cal = rt2x00_eeprom_byte(rt2x00dev,
2487 EEPROM_IQ_GAIN_CAL_TX0_CH36_TO_CH64_5G);
2488 else if (channel >= 100 && channel <= 138)
2489 cal = rt2x00_eeprom_byte(rt2x00dev,
2490 EEPROM_IQ_GAIN_CAL_TX0_CH100_TO_CH138_5G);
2491 else if (channel >= 140 && channel <= 165)
2492 cal = rt2x00_eeprom_byte(rt2x00dev,
2493 EEPROM_IQ_GAIN_CAL_TX0_CH140_TO_CH165_5G);
2494 else
2495 cal = 0;
Stanislaw Gruszka87561302013-03-16 19:19:45 +01002496 rt2800_bbp_write(rt2x00dev, 159, cal);
2497
Stanislaw Gruszka415e3f22013-03-16 19:19:52 +01002498 /* TX0 IQ Phase */
Stanislaw Gruszka87561302013-03-16 19:19:45 +01002499 rt2800_bbp_write(rt2x00dev, 158, 0x2d);
Stanislaw Gruszka415e3f22013-03-16 19:19:52 +01002500 if (channel <= 14)
2501 cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_PHASE_CAL_TX0_2G);
2502 else if (channel >= 36 && channel <= 64)
2503 cal = rt2x00_eeprom_byte(rt2x00dev,
2504 EEPROM_IQ_PHASE_CAL_TX0_CH36_TO_CH64_5G);
2505 else if (channel >= 100 && channel <= 138)
2506 cal = rt2x00_eeprom_byte(rt2x00dev,
2507 EEPROM_IQ_PHASE_CAL_TX0_CH100_TO_CH138_5G);
2508 else if (channel >= 140 && channel <= 165)
2509 cal = rt2x00_eeprom_byte(rt2x00dev,
2510 EEPROM_IQ_PHASE_CAL_TX0_CH140_TO_CH165_5G);
2511 else
2512 cal = 0;
Stanislaw Gruszka87561302013-03-16 19:19:45 +01002513 rt2800_bbp_write(rt2x00dev, 159, cal);
2514
Stanislaw Gruszka415e3f22013-03-16 19:19:52 +01002515 /* TX1 IQ Gain */
Stanislaw Gruszka87561302013-03-16 19:19:45 +01002516 rt2800_bbp_write(rt2x00dev, 158, 0x4a);
Stanislaw Gruszka415e3f22013-03-16 19:19:52 +01002517 if (channel <= 14)
2518 cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_GAIN_CAL_TX1_2G);
2519 else if (channel >= 36 && channel <= 64)
2520 cal = rt2x00_eeprom_byte(rt2x00dev,
2521 EEPROM_IQ_GAIN_CAL_TX1_CH36_TO_CH64_5G);
2522 else if (channel >= 100 && channel <= 138)
2523 cal = rt2x00_eeprom_byte(rt2x00dev,
2524 EEPROM_IQ_GAIN_CAL_TX1_CH100_TO_CH138_5G);
2525 else if (channel >= 140 && channel <= 165)
2526 cal = rt2x00_eeprom_byte(rt2x00dev,
2527 EEPROM_IQ_GAIN_CAL_TX1_CH140_TO_CH165_5G);
2528 else
2529 cal = 0;
Stanislaw Gruszka87561302013-03-16 19:19:45 +01002530 rt2800_bbp_write(rt2x00dev, 159, cal);
2531
Stanislaw Gruszka415e3f22013-03-16 19:19:52 +01002532 /* TX1 IQ Phase */
Stanislaw Gruszka87561302013-03-16 19:19:45 +01002533 rt2800_bbp_write(rt2x00dev, 158, 0x4b);
Stanislaw Gruszka415e3f22013-03-16 19:19:52 +01002534 if (channel <= 14)
2535 cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_PHASE_CAL_TX1_2G);
2536 else if (channel >= 36 && channel <= 64)
2537 cal = rt2x00_eeprom_byte(rt2x00dev,
2538 EEPROM_IQ_PHASE_CAL_TX1_CH36_TO_CH64_5G);
2539 else if (channel >= 100 && channel <= 138)
2540 cal = rt2x00_eeprom_byte(rt2x00dev,
2541 EEPROM_IQ_PHASE_CAL_TX1_CH100_TO_CH138_5G);
2542 else if (channel >= 140 && channel <= 165)
2543 cal = rt2x00_eeprom_byte(rt2x00dev,
2544 EEPROM_IQ_PHASE_CAL_TX1_CH140_TO_CH165_5G);
2545 else
2546 cal = 0;
Stanislaw Gruszka87561302013-03-16 19:19:45 +01002547 rt2800_bbp_write(rt2x00dev, 159, cal);
2548
Stanislaw Gruszka415e3f22013-03-16 19:19:52 +01002549 /* FIXME: possible RX0, RX1 callibration ? */
2550
Stanislaw Gruszka87561302013-03-16 19:19:45 +01002551 /* RF IQ compensation control */
2552 rt2800_bbp_write(rt2x00dev, 158, 0x04);
2553 cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_RF_IQ_COMPENSATION_CONTROL);
2554 rt2800_bbp_write(rt2x00dev, 159, cal != 0xff ? cal : 0);
2555
2556 /* RF IQ imbalance compensation control */
2557 rt2800_bbp_write(rt2x00dev, 158, 0x03);
Stanislaw Gruszka415e3f22013-03-16 19:19:52 +01002558 cal = rt2x00_eeprom_byte(rt2x00dev,
2559 EEPROM_RF_IQ_IMBALANCE_COMPENSATION_CONTROL);
Stanislaw Gruszka87561302013-03-16 19:19:45 +01002560 rt2800_bbp_write(rt2x00dev, 159, cal != 0xff ? cal : 0);
2561}
2562
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01002563static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
2564 struct ieee80211_conf *conf,
2565 struct rf_channel *rf,
2566 struct channel_info *info)
2567{
2568 u32 reg;
2569 unsigned int tx_pin;
Woody Hunga89534e2012-06-13 15:01:16 +08002570 u8 bbp, rfcsr;
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01002571
Ivo van Doorn46323e12010-08-23 19:55:43 +02002572 if (rf->channel <= 14) {
Ivo van Doorn8d1331b2010-08-23 19:56:07 +02002573 info->default_power1 = TXPOWER_G_TO_DEV(info->default_power1);
2574 info->default_power2 = TXPOWER_G_TO_DEV(info->default_power2);
Ivo van Doorn46323e12010-08-23 19:55:43 +02002575 } else {
Ivo van Doorn8d1331b2010-08-23 19:56:07 +02002576 info->default_power1 = TXPOWER_A_TO_DEV(info->default_power1);
2577 info->default_power2 = TXPOWER_A_TO_DEV(info->default_power2);
Ivo van Doorn46323e12010-08-23 19:55:43 +02002578 }
2579
Gertjan van Wingerde5aa57012011-12-28 01:53:20 +01002580 switch (rt2x00dev->chip.rf) {
2581 case RF2020:
2582 case RF3020:
2583 case RF3021:
2584 case RF3022:
2585 case RF3320:
Gertjan van Wingerde06855ef2010-04-11 14:31:07 +02002586 rt2800_config_channel_rf3xxx(rt2x00dev, conf, rf, info);
Gertjan van Wingerde5aa57012011-12-28 01:53:20 +01002587 break;
2588 case RF3052:
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02002589 rt2800_config_channel_rf3052(rt2x00dev, conf, rf, info);
Gertjan van Wingerde5aa57012011-12-28 01:53:20 +01002590 break;
Woody Hunga89534e2012-06-13 15:01:16 +08002591 case RF3290:
2592 rt2800_config_channel_rf3290(rt2x00dev, conf, rf, info);
2593 break;
Daniel Golle03839952012-09-09 14:24:39 +03002594 case RF3322:
2595 rt2800_config_channel_rf3322(rt2x00dev, conf, rf, info);
2596 break;
villacis@palosanto.comccf91bd2012-05-16 21:07:12 +02002597 case RF5360:
Gertjan van Wingerde5aa57012011-12-28 01:53:20 +01002598 case RF5370:
John Li2ed71882012-02-17 17:33:06 +08002599 case RF5372:
Gertjan van Wingerde5aa57012011-12-28 01:53:20 +01002600 case RF5390:
Zero.Lincff3d1f2012-05-29 16:11:09 +08002601 case RF5392:
Gabor Juhosadde5882011-03-03 11:46:45 +01002602 rt2800_config_channel_rf53xx(rt2x00dev, conf, rf, info);
Gertjan van Wingerde5aa57012011-12-28 01:53:20 +01002603 break;
Stanislaw Gruszka8f821092013-03-16 19:19:32 +01002604 case RF5592:
2605 rt2800_config_channel_rf55xx(rt2x00dev, conf, rf, info);
2606 break;
Gertjan van Wingerde5aa57012011-12-28 01:53:20 +01002607 default:
Gertjan van Wingerde06855ef2010-04-11 14:31:07 +02002608 rt2800_config_channel_rf2xxx(rt2x00dev, conf, rf, info);
Gertjan van Wingerde5aa57012011-12-28 01:53:20 +01002609 }
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01002610
Woody Hunga89534e2012-06-13 15:01:16 +08002611 if (rt2x00_rf(rt2x00dev, RF3290) ||
Daniel Golle03839952012-09-09 14:24:39 +03002612 rt2x00_rf(rt2x00dev, RF3322) ||
Woody Hunga89534e2012-06-13 15:01:16 +08002613 rt2x00_rf(rt2x00dev, RF5360) ||
2614 rt2x00_rf(rt2x00dev, RF5370) ||
2615 rt2x00_rf(rt2x00dev, RF5372) ||
2616 rt2x00_rf(rt2x00dev, RF5390) ||
2617 rt2x00_rf(rt2x00dev, RF5392)) {
2618 rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
2619 rt2x00_set_field8(&rfcsr, RFCSR30_TX_H20M, 0);
2620 rt2x00_set_field8(&rfcsr, RFCSR30_RX_H20M, 0);
2621 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
2622
2623 rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr);
Gabor Juhosd6d82022012-12-02 18:34:47 +01002624 rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
Woody Hunga89534e2012-06-13 15:01:16 +08002625 rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
2626 }
2627
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01002628 /*
2629 * Change BBP settings
2630 */
Daniel Golle03839952012-09-09 14:24:39 +03002631 if (rt2x00_rt(rt2x00dev, RT3352)) {
2632 rt2800_bbp_write(rt2x00dev, 27, 0x0);
Daniel Gollecf193f62012-10-04 01:20:41 +02002633 rt2800_bbp_write(rt2x00dev, 66, 0x26 + rt2x00dev->lna_gain);
Daniel Golle03839952012-09-09 14:24:39 +03002634 rt2800_bbp_write(rt2x00dev, 27, 0x20);
Daniel Gollecf193f62012-10-04 01:20:41 +02002635 rt2800_bbp_write(rt2x00dev, 66, 0x26 + rt2x00dev->lna_gain);
Daniel Golle03839952012-09-09 14:24:39 +03002636 } else {
2637 rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
2638 rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
2639 rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
2640 rt2800_bbp_write(rt2x00dev, 86, 0);
2641 }
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01002642
2643 if (rf->channel <= 14) {
John Li2ed71882012-02-17 17:33:06 +08002644 if (!rt2x00_rt(rt2x00dev, RT5390) &&
Gabor Juhose6d227b2012-12-02 15:53:28 +01002645 !rt2x00_rt(rt2x00dev, RT5392)) {
Ivo van Doorn7dab73b2011-04-18 15:27:06 +02002646 if (test_bit(CAPABILITY_EXTERNAL_LNA_BG,
2647 &rt2x00dev->cap_flags)) {
Gabor Juhosadde5882011-03-03 11:46:45 +01002648 rt2800_bbp_write(rt2x00dev, 82, 0x62);
2649 rt2800_bbp_write(rt2x00dev, 75, 0x46);
2650 } else {
2651 rt2800_bbp_write(rt2x00dev, 82, 0x84);
2652 rt2800_bbp_write(rt2x00dev, 75, 0x50);
2653 }
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01002654 }
2655 } else {
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02002656 if (rt2x00_rt(rt2x00dev, RT3572))
2657 rt2800_bbp_write(rt2x00dev, 82, 0x94);
2658 else
2659 rt2800_bbp_write(rt2x00dev, 82, 0xf2);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01002660
Ivo van Doorn7dab73b2011-04-18 15:27:06 +02002661 if (test_bit(CAPABILITY_EXTERNAL_LNA_A, &rt2x00dev->cap_flags))
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01002662 rt2800_bbp_write(rt2x00dev, 75, 0x46);
2663 else
2664 rt2800_bbp_write(rt2x00dev, 75, 0x50);
2665 }
2666
2667 rt2800_register_read(rt2x00dev, TX_BAND_CFG, &reg);
Gertjan van Wingerdea21ee722010-05-03 22:43:04 +02002668 rt2x00_set_field32(&reg, TX_BAND_CFG_HT40_MINUS, conf_is_ht40_minus(conf));
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01002669 rt2x00_set_field32(&reg, TX_BAND_CFG_A, rf->channel > 14);
2670 rt2x00_set_field32(&reg, TX_BAND_CFG_BG, rf->channel <= 14);
2671 rt2800_register_write(rt2x00dev, TX_BAND_CFG, reg);
2672
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02002673 if (rt2x00_rt(rt2x00dev, RT3572))
2674 rt2800_rfcsr_write(rt2x00dev, 8, 0);
2675
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01002676 tx_pin = 0;
2677
2678 /* Turn on unused PA or LNA when not using 1T or 1R */
RA-Jay Hungd96aa642011-02-20 13:54:52 +01002679 if (rt2x00dev->default_ant.tx_chain_num == 2) {
Gertjan van Wingerde65f31b52011-05-18 20:25:05 +02002680 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN,
2681 rf->channel > 14);
2682 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN,
2683 rf->channel <= 14);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01002684 }
2685
2686 /* Turn on unused PA or LNA when not using 1T or 1R */
RA-Jay Hungd96aa642011-02-20 13:54:52 +01002687 if (rt2x00dev->default_ant.rx_chain_num == 2) {
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01002688 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1);
2689 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1);
2690 }
2691
2692 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN, 1);
2693 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN, 1);
2694 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1);
2695 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_TRSW_EN, 1);
Gertjan van Wingerde8f96e912011-05-18 20:25:18 +02002696 if (test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags))
2697 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, 1);
2698 else
2699 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN,
2700 rf->channel <= 14);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01002701 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, rf->channel > 14);
2702
2703 rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
2704
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02002705 if (rt2x00_rt(rt2x00dev, RT3572))
2706 rt2800_rfcsr_write(rt2x00dev, 8, 0x80);
2707
Stanislaw Gruszka68031412013-03-16 19:19:44 +01002708 if (rt2x00_rt(rt2x00dev, RT5592)) {
2709 rt2800_bbp_write(rt2x00dev, 195, 141);
2710 rt2800_bbp_write(rt2x00dev, 196, conf_is_ht40(conf) ? 0x10 : 0x1a);
2711
Stanislaw Gruszka8ba0ebf2013-03-16 19:19:48 +01002712 /* AGC init */
2713 reg = (rf->channel <= 14 ? 0x1c : 0x24) + 2 * rt2x00dev->lna_gain;
2714 rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, reg);
2715
Stanislaw Gruszka87561302013-03-16 19:19:45 +01002716 rt2800_iq_calibrate(rt2x00dev, rf->channel);
Stanislaw Gruszka68031412013-03-16 19:19:44 +01002717 }
2718
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01002719 rt2800_bbp_read(rt2x00dev, 4, &bbp);
2720 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * conf_is_ht40(conf));
2721 rt2800_bbp_write(rt2x00dev, 4, bbp);
2722
2723 rt2800_bbp_read(rt2x00dev, 3, &bbp);
Gertjan van Wingerdea21ee722010-05-03 22:43:04 +02002724 rt2x00_set_field8(&bbp, BBP3_HT40_MINUS, conf_is_ht40_minus(conf));
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01002725 rt2800_bbp_write(rt2x00dev, 3, bbp);
2726
Gertjan van Wingerde8d0c9b62010-04-11 14:31:10 +02002727 if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) {
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01002728 if (conf_is_ht40(conf)) {
2729 rt2800_bbp_write(rt2x00dev, 69, 0x1a);
2730 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
2731 rt2800_bbp_write(rt2x00dev, 73, 0x16);
2732 } else {
2733 rt2800_bbp_write(rt2x00dev, 69, 0x16);
2734 rt2800_bbp_write(rt2x00dev, 70, 0x08);
2735 rt2800_bbp_write(rt2x00dev, 73, 0x11);
2736 }
2737 }
2738
2739 msleep(1);
Helmut Schaa977206d2010-12-13 12:31:58 +01002740
2741 /*
2742 * Clear channel statistic counters
2743 */
2744 rt2800_register_read(rt2x00dev, CH_IDLE_STA, &reg);
2745 rt2800_register_read(rt2x00dev, CH_BUSY_STA, &reg);
2746 rt2800_register_read(rt2x00dev, CH_BUSY_STA_SEC, &reg);
Daniel Golle03839952012-09-09 14:24:39 +03002747
2748 /*
2749 * Clear update flag
2750 */
2751 if (rt2x00_rt(rt2x00dev, RT3352)) {
2752 rt2800_bbp_read(rt2x00dev, 49, &bbp);
2753 rt2x00_set_field8(&bbp, BBP49_UPDATE_FLAG, 0);
2754 rt2800_bbp_write(rt2x00dev, 49, bbp);
2755 }
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01002756}
2757
Helmut Schaa9e33a352011-03-28 13:33:40 +02002758static int rt2800_get_gain_calibration_delta(struct rt2x00_dev *rt2x00dev)
2759{
2760 u8 tssi_bounds[9];
2761 u8 current_tssi;
2762 u16 eeprom;
2763 u8 step;
2764 int i;
2765
2766 /*
2767 * Read TSSI boundaries for temperature compensation from
2768 * the EEPROM.
2769 *
2770 * Array idx 0 1 2 3 4 5 6 7 8
2771 * Matching Delta value -4 -3 -2 -1 0 +1 +2 +3 +4
2772 * Example TSSI bounds 0xF0 0xD0 0xB5 0xA0 0x88 0x45 0x25 0x15 0x00
2773 */
2774 if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) {
2775 rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG1, &eeprom);
2776 tssi_bounds[0] = rt2x00_get_field16(eeprom,
2777 EEPROM_TSSI_BOUND_BG1_MINUS4);
2778 tssi_bounds[1] = rt2x00_get_field16(eeprom,
2779 EEPROM_TSSI_BOUND_BG1_MINUS3);
2780
2781 rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG2, &eeprom);
2782 tssi_bounds[2] = rt2x00_get_field16(eeprom,
2783 EEPROM_TSSI_BOUND_BG2_MINUS2);
2784 tssi_bounds[3] = rt2x00_get_field16(eeprom,
2785 EEPROM_TSSI_BOUND_BG2_MINUS1);
2786
2787 rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG3, &eeprom);
2788 tssi_bounds[4] = rt2x00_get_field16(eeprom,
2789 EEPROM_TSSI_BOUND_BG3_REF);
2790 tssi_bounds[5] = rt2x00_get_field16(eeprom,
2791 EEPROM_TSSI_BOUND_BG3_PLUS1);
2792
2793 rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG4, &eeprom);
2794 tssi_bounds[6] = rt2x00_get_field16(eeprom,
2795 EEPROM_TSSI_BOUND_BG4_PLUS2);
2796 tssi_bounds[7] = rt2x00_get_field16(eeprom,
2797 EEPROM_TSSI_BOUND_BG4_PLUS3);
2798
2799 rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG5, &eeprom);
2800 tssi_bounds[8] = rt2x00_get_field16(eeprom,
2801 EEPROM_TSSI_BOUND_BG5_PLUS4);
2802
2803 step = rt2x00_get_field16(eeprom,
2804 EEPROM_TSSI_BOUND_BG5_AGC_STEP);
2805 } else {
2806 rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A1, &eeprom);
2807 tssi_bounds[0] = rt2x00_get_field16(eeprom,
2808 EEPROM_TSSI_BOUND_A1_MINUS4);
2809 tssi_bounds[1] = rt2x00_get_field16(eeprom,
2810 EEPROM_TSSI_BOUND_A1_MINUS3);
2811
2812 rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A2, &eeprom);
2813 tssi_bounds[2] = rt2x00_get_field16(eeprom,
2814 EEPROM_TSSI_BOUND_A2_MINUS2);
2815 tssi_bounds[3] = rt2x00_get_field16(eeprom,
2816 EEPROM_TSSI_BOUND_A2_MINUS1);
2817
2818 rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A3, &eeprom);
2819 tssi_bounds[4] = rt2x00_get_field16(eeprom,
2820 EEPROM_TSSI_BOUND_A3_REF);
2821 tssi_bounds[5] = rt2x00_get_field16(eeprom,
2822 EEPROM_TSSI_BOUND_A3_PLUS1);
2823
2824 rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A4, &eeprom);
2825 tssi_bounds[6] = rt2x00_get_field16(eeprom,
2826 EEPROM_TSSI_BOUND_A4_PLUS2);
2827 tssi_bounds[7] = rt2x00_get_field16(eeprom,
2828 EEPROM_TSSI_BOUND_A4_PLUS3);
2829
2830 rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A5, &eeprom);
2831 tssi_bounds[8] = rt2x00_get_field16(eeprom,
2832 EEPROM_TSSI_BOUND_A5_PLUS4);
2833
2834 step = rt2x00_get_field16(eeprom,
2835 EEPROM_TSSI_BOUND_A5_AGC_STEP);
2836 }
2837
2838 /*
2839 * Check if temperature compensation is supported.
2840 */
Stanislaw Gruszkabf7e1ab2012-10-25 09:51:39 +02002841 if (tssi_bounds[4] == 0xff || step == 0xff)
Helmut Schaa9e33a352011-03-28 13:33:40 +02002842 return 0;
2843
2844 /*
2845 * Read current TSSI (BBP 49).
2846 */
2847 rt2800_bbp_read(rt2x00dev, 49, &current_tssi);
2848
2849 /*
2850 * Compare TSSI value (BBP49) with the compensation boundaries
2851 * from the EEPROM and increase or decrease tx power.
2852 */
2853 for (i = 0; i <= 3; i++) {
2854 if (current_tssi > tssi_bounds[i])
2855 break;
2856 }
2857
2858 if (i == 4) {
2859 for (i = 8; i >= 5; i--) {
2860 if (current_tssi < tssi_bounds[i])
2861 break;
2862 }
2863 }
2864
2865 return (i - 4) * step;
2866}
2867
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01002868static int rt2800_get_txpower_bw_comp(struct rt2x00_dev *rt2x00dev,
2869 enum ieee80211_band band)
2870{
2871 u16 eeprom;
2872 u8 comp_en;
2873 u8 comp_type;
Helmut Schaa75faae82011-03-28 13:31:30 +02002874 int comp_value = 0;
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01002875
2876 rt2x00_eeprom_read(rt2x00dev, EEPROM_TXPOWER_DELTA, &eeprom);
2877
Helmut Schaa75faae82011-03-28 13:31:30 +02002878 /*
2879 * HT40 compensation not required.
2880 */
2881 if (eeprom == 0xffff ||
2882 !test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01002883 return 0;
2884
2885 if (band == IEEE80211_BAND_2GHZ) {
2886 comp_en = rt2x00_get_field16(eeprom,
2887 EEPROM_TXPOWER_DELTA_ENABLE_2G);
2888 if (comp_en) {
2889 comp_type = rt2x00_get_field16(eeprom,
2890 EEPROM_TXPOWER_DELTA_TYPE_2G);
2891 comp_value = rt2x00_get_field16(eeprom,
2892 EEPROM_TXPOWER_DELTA_VALUE_2G);
2893 if (!comp_type)
2894 comp_value = -comp_value;
2895 }
2896 } else {
2897 comp_en = rt2x00_get_field16(eeprom,
2898 EEPROM_TXPOWER_DELTA_ENABLE_5G);
2899 if (comp_en) {
2900 comp_type = rt2x00_get_field16(eeprom,
2901 EEPROM_TXPOWER_DELTA_TYPE_5G);
2902 comp_value = rt2x00_get_field16(eeprom,
2903 EEPROM_TXPOWER_DELTA_VALUE_5G);
2904 if (!comp_type)
2905 comp_value = -comp_value;
2906 }
2907 }
2908
2909 return comp_value;
2910}
2911
Stanislaw Gruszka1e4cf242012-10-05 13:44:14 +02002912static int rt2800_get_txpower_reg_delta(struct rt2x00_dev *rt2x00dev,
2913 int power_level, int max_power)
2914{
2915 int delta;
2916
2917 if (test_bit(CAPABILITY_POWER_LIMIT, &rt2x00dev->cap_flags))
2918 return 0;
2919
2920 /*
2921 * XXX: We don't know the maximum transmit power of our hardware since
2922 * the EEPROM doesn't expose it. We only know that we are calibrated
2923 * to 100% tx power.
2924 *
2925 * Hence, we assume the regulatory limit that cfg80211 calulated for
2926 * the current channel is our maximum and if we are requested to lower
2927 * the value we just reduce our tx power accordingly.
2928 */
2929 delta = power_level - max_power;
2930 return min(delta, 0);
2931}
2932
Helmut Schaafa71a162011-03-28 13:32:32 +02002933static u8 rt2800_compensate_txpower(struct rt2x00_dev *rt2x00dev, int is_rate_b,
2934 enum ieee80211_band band, int power_level,
2935 u8 txpower, int delta)
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01002936{
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01002937 u16 eeprom;
2938 u8 criterion;
2939 u8 eirp_txpower;
2940 u8 eirp_txpower_criterion;
2941 u8 reg_limit;
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01002942
Ivo van Doorn7dab73b2011-04-18 15:27:06 +02002943 if (test_bit(CAPABILITY_POWER_LIMIT, &rt2x00dev->cap_flags)) {
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01002944 /*
2945 * Check if eirp txpower exceed txpower_limit.
2946 * We use OFDM 6M as criterion and its eirp txpower
2947 * is stored at EEPROM_EIRP_MAX_TX_POWER.
2948 * .11b data rate need add additional 4dbm
2949 * when calculating eirp txpower.
2950 */
Stanislaw Gruszkad9bceae2012-10-05 13:44:12 +02002951 rt2x00_eeprom_read(rt2x00dev, EEPROM_TXPOWER_BYRATE + 1,
2952 &eeprom);
2953 criterion = rt2x00_get_field16(eeprom,
2954 EEPROM_TXPOWER_BYRATE_RATE0);
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01002955
Stanislaw Gruszkad9bceae2012-10-05 13:44:12 +02002956 rt2x00_eeprom_read(rt2x00dev, EEPROM_EIRP_MAX_TX_POWER,
2957 &eeprom);
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01002958
2959 if (band == IEEE80211_BAND_2GHZ)
2960 eirp_txpower_criterion = rt2x00_get_field16(eeprom,
2961 EEPROM_EIRP_MAX_TX_POWER_2GHZ);
2962 else
2963 eirp_txpower_criterion = rt2x00_get_field16(eeprom,
2964 EEPROM_EIRP_MAX_TX_POWER_5GHZ);
2965
2966 eirp_txpower = eirp_txpower_criterion + (txpower - criterion) +
Helmut Schaa2af242e2011-03-28 13:32:01 +02002967 (is_rate_b ? 4 : 0) + delta;
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01002968
2969 reg_limit = (eirp_txpower > power_level) ?
2970 (eirp_txpower - power_level) : 0;
2971 } else
2972 reg_limit = 0;
2973
Stanislaw Gruszka19f3fa22012-10-05 13:44:10 +02002974 txpower = max(0, txpower + delta - reg_limit);
2975 return min_t(u8, txpower, 0xc);
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01002976}
2977
Stanislaw Gruszka7a662052012-10-05 13:44:15 +02002978/*
2979 * We configure transmit power using MAC TX_PWR_CFG_{0,...,N} registers and
2980 * BBP R1 register. TX_PWR_CFG_X allow to configure per rate TX power values,
2981 * 4 bits for each rate (tune from 0 to 15 dBm). BBP_R1 controls transmit power
2982 * for all rates, but allow to set only 4 discrete values: -12, -6, 0 and 6 dBm.
2983 * Reference per rate transmit power values are located in the EEPROM at
2984 * EEPROM_TXPOWER_BYRATE offset. We adjust them and BBP R1 settings according to
2985 * current conditions (i.e. band, bandwidth, temperature, user settings).
2986 */
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01002987static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev,
Stanislaw Gruszka146c3b02012-10-05 13:44:13 +02002988 struct ieee80211_channel *chan,
Helmut Schaa9e33a352011-03-28 13:33:40 +02002989 int power_level)
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01002990{
Stanislaw Gruszkacee2c732012-10-05 13:44:09 +02002991 u8 txpower, r1;
Helmut Schaa5e846002010-07-11 12:23:09 +02002992 u16 eeprom;
Stanislaw Gruszkacee2c732012-10-05 13:44:09 +02002993 u32 reg, offset;
2994 int i, is_rate_b, delta, power_ctrl;
Stanislaw Gruszka146c3b02012-10-05 13:44:13 +02002995 enum ieee80211_band band = chan->band;
Helmut Schaa2af242e2011-03-28 13:32:01 +02002996
2997 /*
Stanislaw Gruszka7a662052012-10-05 13:44:15 +02002998 * Calculate HT40 compensation. For 40MHz we need to add or subtract
2999 * value read from EEPROM (different for 2GHz and for 5GHz).
Helmut Schaa2af242e2011-03-28 13:32:01 +02003000 */
3001 delta = rt2800_get_txpower_bw_comp(rt2x00dev, band);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003002
Helmut Schaa5e846002010-07-11 12:23:09 +02003003 /*
Stanislaw Gruszka7a662052012-10-05 13:44:15 +02003004 * Calculate temperature compensation. Depends on measurement of current
3005 * TSSI (Transmitter Signal Strength Indication) we know TX power (due
3006 * to temperature or maybe other factors) is smaller or bigger than
3007 * expected. We adjust it, based on TSSI reference and boundaries values
3008 * provided in EEPROM.
Helmut Schaa9e33a352011-03-28 13:33:40 +02003009 */
3010 delta += rt2800_get_gain_calibration_delta(rt2x00dev);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003011
Helmut Schaa5e846002010-07-11 12:23:09 +02003012 /*
Stanislaw Gruszka7a662052012-10-05 13:44:15 +02003013 * Decrease power according to user settings, on devices with unknown
3014 * maximum tx power. For other devices we take user power_level into
3015 * consideration on rt2800_compensate_txpower().
Stanislaw Gruszka1e4cf242012-10-05 13:44:14 +02003016 */
3017 delta += rt2800_get_txpower_reg_delta(rt2x00dev, power_level,
3018 chan->max_power);
3019
3020 /*
Stanislaw Gruszkacee2c732012-10-05 13:44:09 +02003021 * BBP_R1 controls TX power for all rates, it allow to set the following
3022 * gains -12, -6, 0, +6 dBm by setting values 2, 1, 0, 3 respectively.
3023 *
3024 * TODO: we do not use +6 dBm option to do not increase power beyond
3025 * regulatory limit, however this could be utilized for devices with
3026 * CAPABILITY_POWER_LIMIT.
Helmut Schaa5e846002010-07-11 12:23:09 +02003027 */
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003028 rt2800_bbp_read(rt2x00dev, 1, &r1);
Stanislaw Gruszkacee2c732012-10-05 13:44:09 +02003029 if (delta <= -12) {
3030 power_ctrl = 2;
3031 delta += 12;
3032 } else if (delta <= -6) {
3033 power_ctrl = 1;
3034 delta += 6;
3035 } else {
3036 power_ctrl = 0;
3037 }
3038 rt2x00_set_field8(&r1, BBP1_TX_POWER_CTRL, power_ctrl);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003039 rt2800_bbp_write(rt2x00dev, 1, r1);
Helmut Schaa5e846002010-07-11 12:23:09 +02003040 offset = TX_PWR_CFG_0;
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003041
Helmut Schaa5e846002010-07-11 12:23:09 +02003042 for (i = 0; i < EEPROM_TXPOWER_BYRATE_SIZE; i += 2) {
3043 /* just to be safe */
3044 if (offset > TX_PWR_CFG_4)
3045 break;
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003046
Helmut Schaa5e846002010-07-11 12:23:09 +02003047 rt2800_register_read(rt2x00dev, offset, &reg);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003048
Helmut Schaa5e846002010-07-11 12:23:09 +02003049 /* read the next four txpower values */
3050 rt2x00_eeprom_read(rt2x00dev, EEPROM_TXPOWER_BYRATE + i,
3051 &eeprom);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003052
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003053 is_rate_b = i ? 0 : 1;
3054 /*
3055 * TX_PWR_CFG_0: 1MBS, TX_PWR_CFG_1: 24MBS,
Helmut Schaa5e846002010-07-11 12:23:09 +02003056 * TX_PWR_CFG_2: MCS4, TX_PWR_CFG_3: MCS12,
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003057 * TX_PWR_CFG_4: unknown
3058 */
Helmut Schaa5e846002010-07-11 12:23:09 +02003059 txpower = rt2x00_get_field16(eeprom,
3060 EEPROM_TXPOWER_BYRATE_RATE0);
Helmut Schaafa71a162011-03-28 13:32:32 +02003061 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
Helmut Schaa2af242e2011-03-28 13:32:01 +02003062 power_level, txpower, delta);
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003063 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE0, txpower);
Helmut Schaa5e846002010-07-11 12:23:09 +02003064
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003065 /*
3066 * TX_PWR_CFG_0: 2MBS, TX_PWR_CFG_1: 36MBS,
Helmut Schaa5e846002010-07-11 12:23:09 +02003067 * TX_PWR_CFG_2: MCS5, TX_PWR_CFG_3: MCS13,
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003068 * TX_PWR_CFG_4: unknown
3069 */
Helmut Schaa5e846002010-07-11 12:23:09 +02003070 txpower = rt2x00_get_field16(eeprom,
3071 EEPROM_TXPOWER_BYRATE_RATE1);
Helmut Schaafa71a162011-03-28 13:32:32 +02003072 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
Helmut Schaa2af242e2011-03-28 13:32:01 +02003073 power_level, txpower, delta);
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003074 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE1, txpower);
Helmut Schaa5e846002010-07-11 12:23:09 +02003075
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003076 /*
3077 * TX_PWR_CFG_0: 5.5MBS, TX_PWR_CFG_1: 48MBS,
Helmut Schaa5e846002010-07-11 12:23:09 +02003078 * TX_PWR_CFG_2: MCS6, TX_PWR_CFG_3: MCS14,
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003079 * TX_PWR_CFG_4: unknown
3080 */
Helmut Schaa5e846002010-07-11 12:23:09 +02003081 txpower = rt2x00_get_field16(eeprom,
3082 EEPROM_TXPOWER_BYRATE_RATE2);
Helmut Schaafa71a162011-03-28 13:32:32 +02003083 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
Helmut Schaa2af242e2011-03-28 13:32:01 +02003084 power_level, txpower, delta);
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003085 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE2, txpower);
Helmut Schaa5e846002010-07-11 12:23:09 +02003086
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003087 /*
3088 * TX_PWR_CFG_0: 11MBS, TX_PWR_CFG_1: 54MBS,
Helmut Schaa5e846002010-07-11 12:23:09 +02003089 * TX_PWR_CFG_2: MCS7, TX_PWR_CFG_3: MCS15,
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003090 * TX_PWR_CFG_4: unknown
3091 */
Helmut Schaa5e846002010-07-11 12:23:09 +02003092 txpower = rt2x00_get_field16(eeprom,
3093 EEPROM_TXPOWER_BYRATE_RATE3);
Helmut Schaafa71a162011-03-28 13:32:32 +02003094 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
Helmut Schaa2af242e2011-03-28 13:32:01 +02003095 power_level, txpower, delta);
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003096 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE3, txpower);
Helmut Schaa5e846002010-07-11 12:23:09 +02003097
3098 /* read the next four txpower values */
3099 rt2x00_eeprom_read(rt2x00dev, EEPROM_TXPOWER_BYRATE + i + 1,
3100 &eeprom);
3101
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003102 is_rate_b = 0;
3103 /*
3104 * TX_PWR_CFG_0: 6MBS, TX_PWR_CFG_1: MCS0,
Helmut Schaa5e846002010-07-11 12:23:09 +02003105 * TX_PWR_CFG_2: MCS8, TX_PWR_CFG_3: unknown,
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003106 * TX_PWR_CFG_4: unknown
3107 */
Helmut Schaa5e846002010-07-11 12:23:09 +02003108 txpower = rt2x00_get_field16(eeprom,
3109 EEPROM_TXPOWER_BYRATE_RATE0);
Helmut Schaafa71a162011-03-28 13:32:32 +02003110 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
Helmut Schaa2af242e2011-03-28 13:32:01 +02003111 power_level, txpower, delta);
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003112 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE4, txpower);
Helmut Schaa5e846002010-07-11 12:23:09 +02003113
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003114 /*
3115 * TX_PWR_CFG_0: 9MBS, TX_PWR_CFG_1: MCS1,
Helmut Schaa5e846002010-07-11 12:23:09 +02003116 * TX_PWR_CFG_2: MCS9, TX_PWR_CFG_3: unknown,
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003117 * TX_PWR_CFG_4: unknown
3118 */
Helmut Schaa5e846002010-07-11 12:23:09 +02003119 txpower = rt2x00_get_field16(eeprom,
3120 EEPROM_TXPOWER_BYRATE_RATE1);
Helmut Schaafa71a162011-03-28 13:32:32 +02003121 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
Helmut Schaa2af242e2011-03-28 13:32:01 +02003122 power_level, txpower, delta);
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003123 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE5, txpower);
Helmut Schaa5e846002010-07-11 12:23:09 +02003124
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003125 /*
3126 * TX_PWR_CFG_0: 12MBS, TX_PWR_CFG_1: MCS2,
Helmut Schaa5e846002010-07-11 12:23:09 +02003127 * TX_PWR_CFG_2: MCS10, TX_PWR_CFG_3: unknown,
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003128 * TX_PWR_CFG_4: unknown
3129 */
Helmut Schaa5e846002010-07-11 12:23:09 +02003130 txpower = rt2x00_get_field16(eeprom,
3131 EEPROM_TXPOWER_BYRATE_RATE2);
Helmut Schaafa71a162011-03-28 13:32:32 +02003132 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
Helmut Schaa2af242e2011-03-28 13:32:01 +02003133 power_level, txpower, delta);
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003134 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE6, txpower);
Helmut Schaa5e846002010-07-11 12:23:09 +02003135
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003136 /*
3137 * TX_PWR_CFG_0: 18MBS, TX_PWR_CFG_1: MCS3,
Helmut Schaa5e846002010-07-11 12:23:09 +02003138 * TX_PWR_CFG_2: MCS11, TX_PWR_CFG_3: unknown,
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003139 * TX_PWR_CFG_4: unknown
3140 */
Helmut Schaa5e846002010-07-11 12:23:09 +02003141 txpower = rt2x00_get_field16(eeprom,
3142 EEPROM_TXPOWER_BYRATE_RATE3);
Helmut Schaafa71a162011-03-28 13:32:32 +02003143 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
Helmut Schaa2af242e2011-03-28 13:32:01 +02003144 power_level, txpower, delta);
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003145 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE7, txpower);
Helmut Schaa5e846002010-07-11 12:23:09 +02003146
3147 rt2800_register_write(rt2x00dev, offset, reg);
3148
3149 /* next TX_PWR_CFG register */
3150 offset += 4;
3151 }
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003152}
3153
Helmut Schaa9e33a352011-03-28 13:33:40 +02003154void rt2800_gain_calibration(struct rt2x00_dev *rt2x00dev)
3155{
Karl Beldan675a0b02013-03-25 16:26:57 +01003156 rt2800_config_txpower(rt2x00dev, rt2x00dev->hw->conf.chandef.chan,
Helmut Schaa9e33a352011-03-28 13:33:40 +02003157 rt2x00dev->tx_power);
3158}
3159EXPORT_SYMBOL_GPL(rt2800_gain_calibration);
3160
John Li2e9c43d2012-02-16 21:40:57 +08003161void rt2800_vco_calibration(struct rt2x00_dev *rt2x00dev)
3162{
3163 u32 tx_pin;
3164 u8 rfcsr;
3165
3166 /*
3167 * A voltage-controlled oscillator(VCO) is an electronic oscillator
3168 * designed to be controlled in oscillation frequency by a voltage
3169 * input. Maybe the temperature will affect the frequency of
3170 * oscillation to be shifted. The VCO calibration will be called
3171 * periodically to adjust the frequency to be precision.
3172 */
3173
3174 rt2800_register_read(rt2x00dev, TX_PIN_CFG, &tx_pin);
3175 tx_pin &= TX_PIN_CFG_PA_PE_DISABLE;
3176 rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
3177
3178 switch (rt2x00dev->chip.rf) {
3179 case RF2020:
3180 case RF3020:
3181 case RF3021:
3182 case RF3022:
3183 case RF3320:
3184 case RF3052:
3185 rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr);
3186 rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
3187 rt2800_rfcsr_write(rt2x00dev, 7, rfcsr);
3188 break;
Woody Hunga89534e2012-06-13 15:01:16 +08003189 case RF3290:
villacis@palosanto.comccf91bd2012-05-16 21:07:12 +02003190 case RF5360:
John Li2e9c43d2012-02-16 21:40:57 +08003191 case RF5370:
3192 case RF5372:
3193 case RF5390:
Zero.Lincff3d1f2012-05-29 16:11:09 +08003194 case RF5392:
John Li2e9c43d2012-02-16 21:40:57 +08003195 rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr);
Gabor Juhosd6d82022012-12-02 18:34:47 +01003196 rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
John Li2e9c43d2012-02-16 21:40:57 +08003197 rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
3198 break;
3199 default:
3200 return;
3201 }
3202
3203 mdelay(1);
3204
3205 rt2800_register_read(rt2x00dev, TX_PIN_CFG, &tx_pin);
3206 if (rt2x00dev->rf_channel <= 14) {
3207 switch (rt2x00dev->default_ant.tx_chain_num) {
3208 case 3:
3209 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G2_EN, 1);
3210 /* fall through */
3211 case 2:
3212 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1);
3213 /* fall through */
3214 case 1:
3215 default:
3216 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, 1);
3217 break;
3218 }
3219 } else {
3220 switch (rt2x00dev->default_ant.tx_chain_num) {
3221 case 3:
3222 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A2_EN, 1);
3223 /* fall through */
3224 case 2:
3225 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1);
3226 /* fall through */
3227 case 1:
3228 default:
3229 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, 1);
3230 break;
3231 }
3232 }
3233 rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
3234
3235}
3236EXPORT_SYMBOL_GPL(rt2800_vco_calibration);
3237
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003238static void rt2800_config_retry_limit(struct rt2x00_dev *rt2x00dev,
3239 struct rt2x00lib_conf *libconf)
3240{
3241 u32 reg;
3242
3243 rt2800_register_read(rt2x00dev, TX_RTY_CFG, &reg);
3244 rt2x00_set_field32(&reg, TX_RTY_CFG_SHORT_RTY_LIMIT,
3245 libconf->conf->short_frame_max_tx_count);
3246 rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_LIMIT,
3247 libconf->conf->long_frame_max_tx_count);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003248 rt2800_register_write(rt2x00dev, TX_RTY_CFG, reg);
3249}
3250
3251static void rt2800_config_ps(struct rt2x00_dev *rt2x00dev,
3252 struct rt2x00lib_conf *libconf)
3253{
3254 enum dev_state state =
3255 (libconf->conf->flags & IEEE80211_CONF_PS) ?
3256 STATE_SLEEP : STATE_AWAKE;
3257 u32 reg;
3258
3259 if (state == STATE_SLEEP) {
3260 rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0);
3261
3262 rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG, &reg);
3263 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 5);
3264 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE,
3265 libconf->conf->listen_interval - 1);
3266 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTOWAKE, 1);
3267 rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
3268
3269 rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
3270 } else {
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003271 rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG, &reg);
3272 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 0);
3273 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE, 0);
3274 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTOWAKE, 0);
3275 rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
Gertjan van Wingerde57318582010-03-30 23:50:23 +02003276
3277 rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003278 }
3279}
3280
3281void rt2800_config(struct rt2x00_dev *rt2x00dev,
3282 struct rt2x00lib_conf *libconf,
3283 const unsigned int flags)
3284{
3285 /* Always recalculate LNA gain before changing configuration */
3286 rt2800_config_lna_gain(rt2x00dev, libconf);
3287
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003288 if (flags & IEEE80211_CONF_CHANGE_CHANNEL) {
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003289 rt2800_config_channel(rt2x00dev, libconf->conf,
3290 &libconf->rf, &libconf->channel);
Karl Beldan675a0b02013-03-25 16:26:57 +01003291 rt2800_config_txpower(rt2x00dev, libconf->conf->chandef.chan,
Helmut Schaa9e33a352011-03-28 13:33:40 +02003292 libconf->conf->power_level);
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01003293 }
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003294 if (flags & IEEE80211_CONF_CHANGE_POWER)
Karl Beldan675a0b02013-03-25 16:26:57 +01003295 rt2800_config_txpower(rt2x00dev, libconf->conf->chandef.chan,
Helmut Schaa9e33a352011-03-28 13:33:40 +02003296 libconf->conf->power_level);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003297 if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
3298 rt2800_config_retry_limit(rt2x00dev, libconf);
3299 if (flags & IEEE80211_CONF_CHANGE_PS)
3300 rt2800_config_ps(rt2x00dev, libconf);
3301}
3302EXPORT_SYMBOL_GPL(rt2800_config);
3303
3304/*
3305 * Link tuning
3306 */
3307void rt2800_link_stats(struct rt2x00_dev *rt2x00dev, struct link_qual *qual)
3308{
3309 u32 reg;
3310
3311 /*
3312 * Update FCS error count from register.
3313 */
3314 rt2800_register_read(rt2x00dev, RX_STA_CNT0, &reg);
3315 qual->rx_failed = rt2x00_get_field32(reg, RX_STA_CNT0_CRC_ERR);
3316}
3317EXPORT_SYMBOL_GPL(rt2800_link_stats);
3318
3319static u8 rt2800_get_default_vgc(struct rt2x00_dev *rt2x00dev)
3320{
Gertjan van Wingerde8c6728b2012-09-16 22:29:49 +02003321 u8 vgc;
3322
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003323 if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) {
Gertjan van Wingerded5385bf2010-04-11 14:31:13 +02003324 if (rt2x00_rt(rt2x00dev, RT3070) ||
Gertjan van Wingerde64522952010-04-11 14:31:14 +02003325 rt2x00_rt(rt2x00dev, RT3071) ||
Gertjan van Wingerdecc78e902010-04-11 14:31:15 +02003326 rt2x00_rt(rt2x00dev, RT3090) ||
Woody Hunga89534e2012-06-13 15:01:16 +08003327 rt2x00_rt(rt2x00dev, RT3290) ||
Gabor Juhosadde5882011-03-03 11:46:45 +01003328 rt2x00_rt(rt2x00dev, RT3390) ||
Gertjan van Wingerded961e442012-09-16 22:29:50 +02003329 rt2x00_rt(rt2x00dev, RT3572) ||
John Li2ed71882012-02-17 17:33:06 +08003330 rt2x00_rt(rt2x00dev, RT5390) ||
Stanislaw Gruszka3d815352013-03-16 19:19:49 +01003331 rt2x00_rt(rt2x00dev, RT5392) ||
3332 rt2x00_rt(rt2x00dev, RT5592))
Gertjan van Wingerde8c6728b2012-09-16 22:29:49 +02003333 vgc = 0x1c + (2 * rt2x00dev->lna_gain);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003334 else
Gertjan van Wingerde8c6728b2012-09-16 22:29:49 +02003335 vgc = 0x2e + rt2x00dev->lna_gain;
3336 } else { /* 5GHZ band */
Gertjan van Wingerded961e442012-09-16 22:29:50 +02003337 if (rt2x00_rt(rt2x00dev, RT3572))
3338 vgc = 0x22 + (rt2x00dev->lna_gain * 5) / 3;
Stanislaw Gruszka3d815352013-03-16 19:19:49 +01003339 else if (rt2x00_rt(rt2x00dev, RT5592))
3340 vgc = 0x24 + (2 * rt2x00dev->lna_gain);
Gertjan van Wingerded961e442012-09-16 22:29:50 +02003341 else {
3342 if (!test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
3343 vgc = 0x32 + (rt2x00dev->lna_gain * 5) / 3;
3344 else
3345 vgc = 0x3a + (rt2x00dev->lna_gain * 5) / 3;
3346 }
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003347 }
3348
Gertjan van Wingerde8c6728b2012-09-16 22:29:49 +02003349 return vgc;
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003350}
3351
3352static inline void rt2800_set_vgc(struct rt2x00_dev *rt2x00dev,
3353 struct link_qual *qual, u8 vgc_level)
3354{
3355 if (qual->vgc_level != vgc_level) {
Stanislaw Gruszka3d815352013-03-16 19:19:49 +01003356 if (rt2x00_rt(rt2x00dev, RT5592)) {
3357 rt2800_bbp_write(rt2x00dev, 83, qual->rssi > -65 ? 0x4a : 0x7a);
3358 rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, vgc_level);
3359 } else
3360 rt2800_bbp_write(rt2x00dev, 66, vgc_level);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003361 qual->vgc_level = vgc_level;
3362 qual->vgc_level_reg = vgc_level;
3363 }
3364}
3365
3366void rt2800_reset_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual)
3367{
3368 rt2800_set_vgc(rt2x00dev, qual, rt2800_get_default_vgc(rt2x00dev));
3369}
3370EXPORT_SYMBOL_GPL(rt2800_reset_tuner);
3371
3372void rt2800_link_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual,
3373 const u32 count)
3374{
Stanislaw Gruszka3d815352013-03-16 19:19:49 +01003375 u8 vgc;
3376
Gertjan van Wingerde8d0c9b62010-04-11 14:31:10 +02003377 if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C))
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003378 return;
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003379 /*
Stanislaw Gruszka3d815352013-03-16 19:19:49 +01003380 * When RSSI is better then -80 increase VGC level with 0x10, except
3381 * for rt5592 chip.
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003382 */
Stanislaw Gruszka3d815352013-03-16 19:19:49 +01003383
3384 vgc = rt2800_get_default_vgc(rt2x00dev);
3385
3386 if (rt2x00_rt(rt2x00dev, RT5592) && qual->rssi > -65)
3387 vgc += 0x20;
3388 else if (qual->rssi > -80)
3389 vgc += 0x10;
3390
3391 rt2800_set_vgc(rt2x00dev, qual, vgc);
Bartlomiej Zolnierkiewiczf4450612009-11-04 18:36:40 +01003392}
3393EXPORT_SYMBOL_GPL(rt2800_link_tuner);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003394
3395/*
3396 * Initialization functions.
3397 */
Ivo van Doornb9a07ae2010-08-23 19:55:22 +02003398static int rt2800_init_registers(struct rt2x00_dev *rt2x00dev)
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003399{
3400 u32 reg;
Gertjan van Wingerded5385bf2010-04-11 14:31:13 +02003401 u16 eeprom;
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003402 unsigned int i;
Gertjan van Wingerdee3a896b2010-06-03 10:52:04 +02003403 int ret;
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003404
Jakub Kicinskif7b395e2012-04-03 03:40:47 +02003405 rt2800_disable_wpdma(rt2x00dev);
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02003406
Gertjan van Wingerdee3a896b2010-06-03 10:52:04 +02003407 ret = rt2800_drv_init_registers(rt2x00dev);
3408 if (ret)
3409 return ret;
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003410
3411 rt2800_register_read(rt2x00dev, BCN_OFFSET0, &reg);
3412 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN0, 0xe0); /* 0x3800 */
3413 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN1, 0xe8); /* 0x3a00 */
3414 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN2, 0xf0); /* 0x3c00 */
3415 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN3, 0xf8); /* 0x3e00 */
3416 rt2800_register_write(rt2x00dev, BCN_OFFSET0, reg);
3417
3418 rt2800_register_read(rt2x00dev, BCN_OFFSET1, &reg);
3419 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN4, 0xc8); /* 0x3200 */
3420 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN5, 0xd0); /* 0x3400 */
3421 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN6, 0x77); /* 0x1dc0 */
3422 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN7, 0x6f); /* 0x1bc0 */
3423 rt2800_register_write(rt2x00dev, BCN_OFFSET1, reg);
3424
3425 rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE, 0x0000013f);
3426 rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
3427
3428 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
3429
3430 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
Helmut Schaa8544df32010-07-11 12:29:49 +02003431 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL, 1600);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003432 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 0);
3433 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, 0);
3434 rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 0);
3435 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
3436 rt2x00_set_field32(&reg, BCN_TIME_CFG_TX_TIME_COMPENSATE, 0);
3437 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
3438
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02003439 rt2800_config_filter(rt2x00dev, FIF_ALLMULTI);
3440
3441 rt2800_register_read(rt2x00dev, BKOFF_SLOT_CFG, &reg);
3442 rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_SLOT_TIME, 9);
3443 rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_CC_DELAY_TIME, 2);
3444 rt2800_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg);
3445
Woody Hunga89534e2012-06-13 15:01:16 +08003446 if (rt2x00_rt(rt2x00dev, RT3290)) {
3447 rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, &reg);
3448 if (rt2x00_get_field32(reg, WLAN_EN) == 1) {
3449 rt2x00_set_field32(&reg, PCIE_APP0_CLK_REQ, 1);
3450 rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg);
3451 }
3452
3453 rt2800_register_read(rt2x00dev, CMB_CTRL, &reg);
3454 if (!(rt2x00_get_field32(reg, LDO0_EN) == 1)) {
3455 rt2x00_set_field32(&reg, LDO0_EN, 1);
3456 rt2x00_set_field32(&reg, LDO_BGSEL, 3);
3457 rt2800_register_write(rt2x00dev, CMB_CTRL, reg);
3458 }
3459
3460 rt2800_register_read(rt2x00dev, OSC_CTRL, &reg);
3461 rt2x00_set_field32(&reg, OSC_ROSC_EN, 1);
3462 rt2x00_set_field32(&reg, OSC_CAL_REQ, 1);
3463 rt2x00_set_field32(&reg, OSC_REF_CYCLE, 0x27);
3464 rt2800_register_write(rt2x00dev, OSC_CTRL, reg);
3465
3466 rt2800_register_read(rt2x00dev, COEX_CFG0, &reg);
3467 rt2x00_set_field32(&reg, COEX_CFG_ANT, 0x5e);
3468 rt2800_register_write(rt2x00dev, COEX_CFG0, reg);
3469
3470 rt2800_register_read(rt2x00dev, COEX_CFG2, &reg);
3471 rt2x00_set_field32(&reg, BT_COEX_CFG1, 0x00);
3472 rt2x00_set_field32(&reg, BT_COEX_CFG0, 0x17);
3473 rt2x00_set_field32(&reg, WL_COEX_CFG1, 0x93);
3474 rt2x00_set_field32(&reg, WL_COEX_CFG0, 0x7f);
3475 rt2800_register_write(rt2x00dev, COEX_CFG2, reg);
3476
3477 rt2800_register_read(rt2x00dev, PLL_CTRL, &reg);
3478 rt2x00_set_field32(&reg, PLL_CONTROL, 1);
3479 rt2800_register_write(rt2x00dev, PLL_CTRL, reg);
3480 }
3481
Gertjan van Wingerde64522952010-04-11 14:31:14 +02003482 if (rt2x00_rt(rt2x00dev, RT3071) ||
Gertjan van Wingerdecc78e902010-04-11 14:31:15 +02003483 rt2x00_rt(rt2x00dev, RT3090) ||
Woody Hunga89534e2012-06-13 15:01:16 +08003484 rt2x00_rt(rt2x00dev, RT3290) ||
Gertjan van Wingerdecc78e902010-04-11 14:31:15 +02003485 rt2x00_rt(rt2x00dev, RT3390)) {
Woody Hunga89534e2012-06-13 15:01:16 +08003486
3487 if (rt2x00_rt(rt2x00dev, RT3290))
3488 rt2800_register_write(rt2x00dev, TX_SW_CFG0,
3489 0x00000404);
3490 else
3491 rt2800_register_write(rt2x00dev, TX_SW_CFG0,
3492 0x00000400);
3493
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003494 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
Gertjan van Wingerde64522952010-04-11 14:31:14 +02003495 if (rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) ||
Gertjan van Wingerdecc78e902010-04-11 14:31:15 +02003496 rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E) ||
3497 rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) {
RA-Jay Hung38c8a562010-12-13 12:31:27 +01003498 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
3499 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_DAC_TEST))
Gertjan van Wingerded5385bf2010-04-11 14:31:13 +02003500 rt2800_register_write(rt2x00dev, TX_SW_CFG2,
3501 0x0000002c);
3502 else
3503 rt2800_register_write(rt2x00dev, TX_SW_CFG2,
3504 0x0000000f);
3505 } else {
3506 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
3507 }
Gertjan van Wingerded5385bf2010-04-11 14:31:13 +02003508 } else if (rt2x00_rt(rt2x00dev, RT3070)) {
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003509 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
Gertjan van Wingerde8cdd15e2010-04-11 14:31:12 +02003510
3511 if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) {
3512 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
3513 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x0000002c);
3514 } else {
3515 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
3516 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
3517 }
Helmut Schaac295a812010-06-03 10:52:13 +02003518 } else if (rt2800_is_305x_soc(rt2x00dev)) {
3519 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
3520 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
Helmut Schaa961636b2011-04-18 15:28:27 +02003521 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000030);
Daniel Golle03839952012-09-09 14:24:39 +03003522 } else if (rt2x00_rt(rt2x00dev, RT3352)) {
3523 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000402);
3524 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
3525 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02003526 } else if (rt2x00_rt(rt2x00dev, RT3572)) {
3527 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
3528 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
John Li2ed71882012-02-17 17:33:06 +08003529 } else if (rt2x00_rt(rt2x00dev, RT5390) ||
Stanislaw Gruszka76413282013-03-16 19:19:33 +01003530 rt2x00_rt(rt2x00dev, RT5392) ||
3531 rt2x00_rt(rt2x00dev, RT5592)) {
Gabor Juhosadde5882011-03-03 11:46:45 +01003532 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000404);
3533 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
3534 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003535 } else {
3536 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000000);
3537 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
3538 }
3539
3540 rt2800_register_read(rt2x00dev, TX_LINK_CFG, &reg);
3541 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB_LIFETIME, 32);
3542 rt2x00_set_field32(&reg, TX_LINK_CFG_MFB_ENABLE, 0);
3543 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_UMFS_ENABLE, 0);
3544 rt2x00_set_field32(&reg, TX_LINK_CFG_TX_MRQ_EN, 0);
3545 rt2x00_set_field32(&reg, TX_LINK_CFG_TX_RDG_EN, 0);
3546 rt2x00_set_field32(&reg, TX_LINK_CFG_TX_CF_ACK_EN, 1);
3547 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB, 0);
3548 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFS, 0);
3549 rt2800_register_write(rt2x00dev, TX_LINK_CFG, reg);
3550
3551 rt2800_register_read(rt2x00dev, TX_TIMEOUT_CFG, &reg);
3552 rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_MPDU_LIFETIME, 9);
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02003553 rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_RX_ACK_TIMEOUT, 32);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003554 rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_TX_OP_TIMEOUT, 10);
3555 rt2800_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
3556
3557 rt2800_register_read(rt2x00dev, MAX_LEN_CFG, &reg);
3558 rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_MPDU, AGGREGATION_SIZE);
Gertjan van Wingerde8d0c9b62010-04-11 14:31:10 +02003559 if (rt2x00_rt_rev_gte(rt2x00dev, RT2872, REV_RT2872E) ||
Gertjan van Wingerde49e721e2010-02-13 20:55:49 +01003560 rt2x00_rt(rt2x00dev, RT2883) ||
Gertjan van Wingerde8d0c9b62010-04-11 14:31:10 +02003561 rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070E))
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003562 rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 2);
3563 else
3564 rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 1);
3565 rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_PSDU, 0);
3566 rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_MPDU, 0);
3567 rt2800_register_write(rt2x00dev, MAX_LEN_CFG, reg);
3568
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02003569 rt2800_register_read(rt2x00dev, LED_CFG, &reg);
3570 rt2x00_set_field32(&reg, LED_CFG_ON_PERIOD, 70);
3571 rt2x00_set_field32(&reg, LED_CFG_OFF_PERIOD, 30);
3572 rt2x00_set_field32(&reg, LED_CFG_SLOW_BLINK_PERIOD, 3);
3573 rt2x00_set_field32(&reg, LED_CFG_R_LED_MODE, 3);
3574 rt2x00_set_field32(&reg, LED_CFG_G_LED_MODE, 3);
3575 rt2x00_set_field32(&reg, LED_CFG_Y_LED_MODE, 3);
3576 rt2x00_set_field32(&reg, LED_CFG_LED_POLAR, 1);
3577 rt2800_register_write(rt2x00dev, LED_CFG, reg);
3578
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003579 rt2800_register_write(rt2x00dev, PBF_MAX_PCNT, 0x1f3fbf9f);
3580
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02003581 rt2800_register_read(rt2x00dev, TX_RTY_CFG, &reg);
3582 rt2x00_set_field32(&reg, TX_RTY_CFG_SHORT_RTY_LIMIT, 15);
3583 rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_LIMIT, 31);
3584 rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_THRE, 2000);
3585 rt2x00_set_field32(&reg, TX_RTY_CFG_NON_AGG_RTY_MODE, 0);
3586 rt2x00_set_field32(&reg, TX_RTY_CFG_AGG_RTY_MODE, 0);
3587 rt2x00_set_field32(&reg, TX_RTY_CFG_TX_AUTO_FB_ENABLE, 1);
3588 rt2800_register_write(rt2x00dev, TX_RTY_CFG, reg);
3589
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003590 rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, &reg);
3591 rt2x00_set_field32(&reg, AUTO_RSP_CFG_AUTORESPONDER, 1);
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02003592 rt2x00_set_field32(&reg, AUTO_RSP_CFG_BAC_ACK_POLICY, 1);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003593 rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MMODE, 0);
3594 rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MREF, 0);
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02003595 rt2x00_set_field32(&reg, AUTO_RSP_CFG_AR_PREAMBLE, 1);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003596 rt2x00_set_field32(&reg, AUTO_RSP_CFG_DUAL_CTS_EN, 0);
3597 rt2x00_set_field32(&reg, AUTO_RSP_CFG_ACK_CTS_PSM_BIT, 0);
3598 rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
3599
3600 rt2800_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02003601 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_RATE, 3);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003602 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_CTRL, 0);
Shiang Tu6f492b62011-02-20 13:56:54 +01003603 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_NAV_SHORT, 1);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003604 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_CCK, 1);
3605 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
3606 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM20, 1);
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02003607 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM40, 0);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003608 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF20, 1);
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02003609 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF40, 0);
3610 rt2x00_set_field32(&reg, CCK_PROT_CFG_RTS_TH_EN, 1);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003611 rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg);
3612
3613 rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02003614 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_RATE, 3);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003615 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL, 0);
Shiang Tu6f492b62011-02-20 13:56:54 +01003616 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_NAV_SHORT, 1);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003617 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_CCK, 1);
3618 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
3619 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM20, 1);
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02003620 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM40, 0);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003621 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF20, 1);
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02003622 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF40, 0);
3623 rt2x00_set_field32(&reg, OFDM_PROT_CFG_RTS_TH_EN, 1);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003624 rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
3625
3626 rt2800_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
3627 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_RATE, 0x4004);
3628 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_CTRL, 0);
Shiang Tu6f492b62011-02-20 13:56:54 +01003629 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_NAV_SHORT, 1);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003630 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
3631 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
3632 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
3633 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
3634 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
3635 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02003636 rt2x00_set_field32(&reg, MM20_PROT_CFG_RTS_TH_EN, 0);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003637 rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
3638
3639 rt2800_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
3640 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_RATE, 0x4084);
Helmut Schaad13a97f2010-10-02 11:29:08 +02003641 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_CTRL, 0);
Shiang Tu6f492b62011-02-20 13:56:54 +01003642 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_NAV_SHORT, 1);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003643 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
3644 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
3645 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
3646 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
3647 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
3648 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02003649 rt2x00_set_field32(&reg, MM40_PROT_CFG_RTS_TH_EN, 0);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003650 rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
3651
3652 rt2800_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
3653 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_RATE, 0x4004);
3654 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_CTRL, 0);
Shiang Tu6f492b62011-02-20 13:56:54 +01003655 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_NAV_SHORT, 1);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003656 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
3657 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
3658 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
3659 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
3660 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
3661 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02003662 rt2x00_set_field32(&reg, GF20_PROT_CFG_RTS_TH_EN, 0);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003663 rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
3664
3665 rt2800_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
3666 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_RATE, 0x4084);
3667 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_CTRL, 0);
Shiang Tu6f492b62011-02-20 13:56:54 +01003668 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_NAV_SHORT, 1);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003669 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
3670 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
3671 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
3672 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
3673 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
3674 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02003675 rt2x00_set_field32(&reg, GF40_PROT_CFG_RTS_TH_EN, 0);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003676 rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
3677
Gertjan van Wingerdecea90e52010-02-13 20:55:47 +01003678 if (rt2x00_is_usb(rt2x00dev)) {
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003679 rt2800_register_write(rt2x00dev, PBF_CFG, 0xf40006);
3680
3681 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
3682 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
3683 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
3684 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
3685 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
3686 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 3);
3687 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 0);
3688 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_BIG_ENDIAN, 0);
3689 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_HDR_SCATTER, 0);
3690 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_HDR_SEG_LEN, 0);
3691 rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
3692 }
3693
Helmut Schaa961621a2010-11-04 20:36:59 +01003694 /*
3695 * The legacy driver also sets TXOP_CTRL_CFG_RESERVED_TRUN_EN to 1
3696 * although it is reserved.
3697 */
3698 rt2800_register_read(rt2x00dev, TXOP_CTRL_CFG, &reg);
3699 rt2x00_set_field32(&reg, TXOP_CTRL_CFG_TIMEOUT_TRUN_EN, 1);
3700 rt2x00_set_field32(&reg, TXOP_CTRL_CFG_AC_TRUN_EN, 1);
3701 rt2x00_set_field32(&reg, TXOP_CTRL_CFG_TXRATEGRP_TRUN_EN, 1);
3702 rt2x00_set_field32(&reg, TXOP_CTRL_CFG_USER_MODE_TRUN_EN, 1);
3703 rt2x00_set_field32(&reg, TXOP_CTRL_CFG_MIMO_PS_TRUN_EN, 1);
3704 rt2x00_set_field32(&reg, TXOP_CTRL_CFG_RESERVED_TRUN_EN, 1);
3705 rt2x00_set_field32(&reg, TXOP_CTRL_CFG_LSIG_TXOP_EN, 0);
3706 rt2x00_set_field32(&reg, TXOP_CTRL_CFG_EXT_CCA_EN, 0);
3707 rt2x00_set_field32(&reg, TXOP_CTRL_CFG_EXT_CCA_DLY, 88);
3708 rt2x00_set_field32(&reg, TXOP_CTRL_CFG_EXT_CWMIN, 0);
3709 rt2800_register_write(rt2x00dev, TXOP_CTRL_CFG, reg);
3710
Stanislaw Gruszka76413282013-03-16 19:19:33 +01003711 reg = rt2x00_rt(rt2x00dev, RT5592) ? 0x00000082 : 0x00000002;
3712 rt2800_register_write(rt2x00dev, TXOP_HLDR_ET, reg);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003713
3714 rt2800_register_read(rt2x00dev, TX_RTS_CFG, &reg);
3715 rt2x00_set_field32(&reg, TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT, 32);
3716 rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES,
3717 IEEE80211_MAX_RTS_THRESHOLD);
3718 rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_FBK_EN, 0);
3719 rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg);
3720
3721 rt2800_register_write(rt2x00dev, EXP_ACK_TIME, 0x002400ca);
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02003722
Helmut Schaaa21c2ab2010-05-06 12:29:04 +02003723 /*
3724 * Usually the CCK SIFS time should be set to 10 and the OFDM SIFS
3725 * time should be set to 16. However, the original Ralink driver uses
3726 * 16 for both and indeed using a value of 10 for CCK SIFS results in
3727 * connection problems with 11g + CTS protection. Hence, use the same
3728 * defaults as the Ralink driver: 16 for both, CCK and OFDM SIFS.
3729 */
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02003730 rt2800_register_read(rt2x00dev, XIFS_TIME_CFG, &reg);
Helmut Schaaa21c2ab2010-05-06 12:29:04 +02003731 rt2x00_set_field32(&reg, XIFS_TIME_CFG_CCKM_SIFS_TIME, 16);
3732 rt2x00_set_field32(&reg, XIFS_TIME_CFG_OFDM_SIFS_TIME, 16);
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02003733 rt2x00_set_field32(&reg, XIFS_TIME_CFG_OFDM_XIFS_TIME, 4);
3734 rt2x00_set_field32(&reg, XIFS_TIME_CFG_EIFS, 314);
3735 rt2x00_set_field32(&reg, XIFS_TIME_CFG_BB_RXEND_ENABLE, 1);
3736 rt2800_register_write(rt2x00dev, XIFS_TIME_CFG, reg);
3737
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003738 rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
3739
3740 /*
3741 * ASIC will keep garbage value after boot, clear encryption keys.
3742 */
3743 for (i = 0; i < 4; i++)
3744 rt2800_register_write(rt2x00dev,
3745 SHARED_KEY_MODE_ENTRY(i), 0);
3746
3747 for (i = 0; i < 256; i++) {
Helmut Schaad7d259d2011-09-08 14:39:04 +02003748 rt2800_config_wcid(rt2x00dev, NULL, i);
3749 rt2800_delete_wcid_attr(rt2x00dev, i);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003750 rt2800_register_write(rt2x00dev, MAC_IVEIV_ENTRY(i), 0);
3751 }
3752
3753 /*
3754 * Clear all beacons
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003755 */
Helmut Schaa69cf36a2011-01-30 13:16:03 +01003756 rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE0);
3757 rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE1);
3758 rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE2);
3759 rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE3);
3760 rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE4);
3761 rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE5);
3762 rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE6);
3763 rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE7);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003764
Gertjan van Wingerdecea90e52010-02-13 20:55:47 +01003765 if (rt2x00_is_usb(rt2x00dev)) {
Gertjan van Wingerde785c3c02010-06-03 10:51:59 +02003766 rt2800_register_read(rt2x00dev, US_CYC_CNT, &reg);
3767 rt2x00_set_field32(&reg, US_CYC_CNT_CLOCK_CYCLE, 30);
3768 rt2800_register_write(rt2x00dev, US_CYC_CNT, reg);
RA-Jay Hungc6fcc0e2011-01-30 13:21:22 +01003769 } else if (rt2x00_is_pcie(rt2x00dev)) {
3770 rt2800_register_read(rt2x00dev, US_CYC_CNT, &reg);
3771 rt2x00_set_field32(&reg, US_CYC_CNT_CLOCK_CYCLE, 125);
3772 rt2800_register_write(rt2x00dev, US_CYC_CNT, reg);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003773 }
3774
3775 rt2800_register_read(rt2x00dev, HT_FBK_CFG0, &reg);
3776 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS0FBK, 0);
3777 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS1FBK, 0);
3778 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS2FBK, 1);
3779 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS3FBK, 2);
3780 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS4FBK, 3);
3781 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS5FBK, 4);
3782 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS6FBK, 5);
3783 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS7FBK, 6);
3784 rt2800_register_write(rt2x00dev, HT_FBK_CFG0, reg);
3785
3786 rt2800_register_read(rt2x00dev, HT_FBK_CFG1, &reg);
3787 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS8FBK, 8);
3788 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS9FBK, 8);
3789 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS10FBK, 9);
3790 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS11FBK, 10);
3791 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS12FBK, 11);
3792 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS13FBK, 12);
3793 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS14FBK, 13);
3794 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS15FBK, 14);
3795 rt2800_register_write(rt2x00dev, HT_FBK_CFG1, reg);
3796
3797 rt2800_register_read(rt2x00dev, LG_FBK_CFG0, &reg);
3798 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS0FBK, 8);
3799 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS1FBK, 8);
3800 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS2FBK, 9);
3801 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS3FBK, 10);
3802 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS4FBK, 11);
3803 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS5FBK, 12);
3804 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS6FBK, 13);
3805 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS7FBK, 14);
3806 rt2800_register_write(rt2x00dev, LG_FBK_CFG0, reg);
3807
3808 rt2800_register_read(rt2x00dev, LG_FBK_CFG1, &reg);
3809 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS0FBK, 0);
3810 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS1FBK, 0);
3811 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS2FBK, 1);
3812 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS3FBK, 2);
3813 rt2800_register_write(rt2x00dev, LG_FBK_CFG1, reg);
3814
3815 /*
Helmut Schaa47ee3eb2010-09-08 20:56:04 +02003816 * Do not force the BA window size, we use the TXWI to set it
3817 */
3818 rt2800_register_read(rt2x00dev, AMPDU_BA_WINSIZE, &reg);
3819 rt2x00_set_field32(&reg, AMPDU_BA_WINSIZE_FORCE_WINSIZE_ENABLE, 0);
3820 rt2x00_set_field32(&reg, AMPDU_BA_WINSIZE_FORCE_WINSIZE, 0);
3821 rt2800_register_write(rt2x00dev, AMPDU_BA_WINSIZE, reg);
3822
3823 /*
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003824 * We must clear the error counters.
3825 * These registers are cleared on read,
3826 * so we may pass a useless variable to store the value.
3827 */
3828 rt2800_register_read(rt2x00dev, RX_STA_CNT0, &reg);
3829 rt2800_register_read(rt2x00dev, RX_STA_CNT1, &reg);
3830 rt2800_register_read(rt2x00dev, RX_STA_CNT2, &reg);
3831 rt2800_register_read(rt2x00dev, TX_STA_CNT0, &reg);
3832 rt2800_register_read(rt2x00dev, TX_STA_CNT1, &reg);
3833 rt2800_register_read(rt2x00dev, TX_STA_CNT2, &reg);
3834
Helmut Schaa9f926fb2010-07-11 12:28:23 +02003835 /*
3836 * Setup leadtime for pre tbtt interrupt to 6ms
3837 */
3838 rt2800_register_read(rt2x00dev, INT_TIMER_CFG, &reg);
3839 rt2x00_set_field32(&reg, INT_TIMER_CFG_PRE_TBTT_TIMER, 6 << 4);
3840 rt2800_register_write(rt2x00dev, INT_TIMER_CFG, reg);
3841
Helmut Schaa977206d2010-12-13 12:31:58 +01003842 /*
3843 * Set up channel statistics timer
3844 */
3845 rt2800_register_read(rt2x00dev, CH_TIME_CFG, &reg);
3846 rt2x00_set_field32(&reg, CH_TIME_CFG_EIFS_BUSY, 1);
3847 rt2x00_set_field32(&reg, CH_TIME_CFG_NAV_BUSY, 1);
3848 rt2x00_set_field32(&reg, CH_TIME_CFG_RX_BUSY, 1);
3849 rt2x00_set_field32(&reg, CH_TIME_CFG_TX_BUSY, 1);
3850 rt2x00_set_field32(&reg, CH_TIME_CFG_TMR_EN, 1);
3851 rt2800_register_write(rt2x00dev, CH_TIME_CFG, reg);
3852
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003853 return 0;
3854}
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01003855
3856static int rt2800_wait_bbp_rf_ready(struct rt2x00_dev *rt2x00dev)
3857{
3858 unsigned int i;
3859 u32 reg;
3860
3861 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
3862 rt2800_register_read(rt2x00dev, MAC_STATUS_CFG, &reg);
3863 if (!rt2x00_get_field32(reg, MAC_STATUS_CFG_BBP_RF_BUSY))
3864 return 0;
3865
3866 udelay(REGISTER_BUSY_DELAY);
3867 }
3868
3869 ERROR(rt2x00dev, "BBP/RF register access failed, aborting.\n");
3870 return -EACCES;
3871}
3872
3873static int rt2800_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
3874{
3875 unsigned int i;
3876 u8 value;
3877
3878 /*
3879 * BBP was enabled after firmware was loaded,
3880 * but we need to reactivate it now.
3881 */
3882 rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
3883 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
3884 msleep(1);
3885
3886 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
3887 rt2800_bbp_read(rt2x00dev, 0, &value);
3888 if ((value != 0xff) && (value != 0x00))
3889 return 0;
3890 udelay(REGISTER_BUSY_DELAY);
3891 }
3892
3893 ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
3894 return -EACCES;
3895}
3896
Stanislaw Gruszkaa7bbbe52013-03-16 19:19:34 +01003897static void rt2800_bbp4_mac_if_ctrl(struct rt2x00_dev *rt2x00dev)
3898{
3899 u8 value;
3900
3901 rt2800_bbp_read(rt2x00dev, 4, &value);
3902 rt2x00_set_field8(&value, BBP4_MAC_IF_CTRL, 1);
3903 rt2800_bbp_write(rt2x00dev, 4, value);
3904}
3905
Stanislaw Gruszkac2675482013-03-16 19:19:41 +01003906static void rt2800_init_freq_calibration(struct rt2x00_dev *rt2x00dev)
3907{
3908 rt2800_bbp_write(rt2x00dev, 142, 1);
3909 rt2800_bbp_write(rt2x00dev, 143, 57);
3910}
3911
Stanislaw Gruszkaa7bbbe52013-03-16 19:19:34 +01003912static void rt2800_init_bbp_5592_glrt(struct rt2x00_dev *rt2x00dev)
3913{
3914 const u8 glrt_table[] = {
3915 0xE0, 0x1F, 0X38, 0x32, 0x08, 0x28, 0x19, 0x0A, 0xFF, 0x00, /* 128 ~ 137 */
3916 0x16, 0x10, 0x10, 0x0B, 0x36, 0x2C, 0x26, 0x24, 0x42, 0x36, /* 138 ~ 147 */
3917 0x30, 0x2D, 0x4C, 0x46, 0x3D, 0x40, 0x3E, 0x42, 0x3D, 0x40, /* 148 ~ 157 */
3918 0X3C, 0x34, 0x2C, 0x2F, 0x3C, 0x35, 0x2E, 0x2A, 0x49, 0x41, /* 158 ~ 167 */
3919 0x36, 0x31, 0x30, 0x30, 0x0E, 0x0D, 0x28, 0x21, 0x1C, 0x16, /* 168 ~ 177 */
3920 0x50, 0x4A, 0x43, 0x40, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, /* 178 ~ 187 */
3921 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 188 ~ 197 */
3922 0x00, 0x00, 0x7D, 0x14, 0x32, 0x2C, 0x36, 0x4C, 0x43, 0x2C, /* 198 ~ 207 */
3923 0x2E, 0x36, 0x30, 0x6E, /* 208 ~ 211 */
3924 };
3925 int i;
3926
3927 for (i = 0; i < ARRAY_SIZE(glrt_table); i++) {
3928 rt2800_bbp_write(rt2x00dev, 195, 128 + i);
3929 rt2800_bbp_write(rt2x00dev, 196, glrt_table[i]);
3930 }
3931};
3932
Stanislaw Gruszkaa4969d02013-03-16 19:19:35 +01003933static void rt2800_init_bbb_early(struct rt2x00_dev *rt2x00dev)
3934{
3935 rt2800_bbp_write(rt2x00dev, 65, 0x2C);
3936 rt2800_bbp_write(rt2x00dev, 66, 0x38);
3937 rt2800_bbp_write(rt2x00dev, 68, 0x0B);
3938 rt2800_bbp_write(rt2x00dev, 69, 0x12);
3939 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
3940 rt2800_bbp_write(rt2x00dev, 73, 0x10);
3941 rt2800_bbp_write(rt2x00dev, 81, 0x37);
3942 rt2800_bbp_write(rt2x00dev, 82, 0x62);
3943 rt2800_bbp_write(rt2x00dev, 83, 0x6A);
3944 rt2800_bbp_write(rt2x00dev, 84, 0x99);
3945 rt2800_bbp_write(rt2x00dev, 86, 0x00);
3946 rt2800_bbp_write(rt2x00dev, 91, 0x04);
3947 rt2800_bbp_write(rt2x00dev, 92, 0x00);
3948 rt2800_bbp_write(rt2x00dev, 103, 0x00);
3949 rt2800_bbp_write(rt2x00dev, 105, 0x05);
3950 rt2800_bbp_write(rt2x00dev, 106, 0x35);
3951}
3952
Stanislaw Gruszkaa7bbbe52013-03-16 19:19:34 +01003953static void rt2800_init_bbp_5592(struct rt2x00_dev *rt2x00dev)
3954{
3955 int ant, div_mode;
3956 u16 eeprom;
3957 u8 value;
3958
Stanislaw Gruszkaa4969d02013-03-16 19:19:35 +01003959 rt2800_init_bbb_early(rt2x00dev);
3960
Stanislaw Gruszkaa7bbbe52013-03-16 19:19:34 +01003961 rt2800_bbp_read(rt2x00dev, 105, &value);
3962 rt2x00_set_field8(&value, BBP105_MLD,
3963 rt2x00dev->default_ant.rx_chain_num == 2);
3964 rt2800_bbp_write(rt2x00dev, 105, value);
3965
3966 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
3967
3968 rt2800_bbp_write(rt2x00dev, 20, 0x06);
3969 rt2800_bbp_write(rt2x00dev, 31, 0x08);
3970 rt2800_bbp_write(rt2x00dev, 65, 0x2C);
3971 rt2800_bbp_write(rt2x00dev, 68, 0xDD);
3972 rt2800_bbp_write(rt2x00dev, 69, 0x1A);
3973 rt2800_bbp_write(rt2x00dev, 70, 0x05);
3974 rt2800_bbp_write(rt2x00dev, 73, 0x13);
3975 rt2800_bbp_write(rt2x00dev, 74, 0x0F);
3976 rt2800_bbp_write(rt2x00dev, 75, 0x4F);
3977 rt2800_bbp_write(rt2x00dev, 76, 0x28);
3978 rt2800_bbp_write(rt2x00dev, 77, 0x59);
3979 rt2800_bbp_write(rt2x00dev, 84, 0x9A);
3980 rt2800_bbp_write(rt2x00dev, 86, 0x38);
3981 rt2800_bbp_write(rt2x00dev, 88, 0x90);
3982 rt2800_bbp_write(rt2x00dev, 91, 0x04);
3983 rt2800_bbp_write(rt2x00dev, 92, 0x02);
3984 rt2800_bbp_write(rt2x00dev, 95, 0x9a);
3985 rt2800_bbp_write(rt2x00dev, 98, 0x12);
3986 rt2800_bbp_write(rt2x00dev, 103, 0xC0);
3987 rt2800_bbp_write(rt2x00dev, 104, 0x92);
3988 /* FIXME BBP105 owerwrite */
3989 rt2800_bbp_write(rt2x00dev, 105, 0x3C);
3990 rt2800_bbp_write(rt2x00dev, 106, 0x35);
3991 rt2800_bbp_write(rt2x00dev, 128, 0x12);
3992 rt2800_bbp_write(rt2x00dev, 134, 0xD0);
3993 rt2800_bbp_write(rt2x00dev, 135, 0xF6);
3994 rt2800_bbp_write(rt2x00dev, 137, 0x0F);
3995
3996 /* Initialize GLRT (Generalized Likehood Radio Test) */
3997 rt2800_init_bbp_5592_glrt(rt2x00dev);
3998
3999 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
4000
4001 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
4002 div_mode = rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_ANT_DIVERSITY);
4003 ant = (div_mode == 3) ? 1 : 0;
4004 rt2800_bbp_read(rt2x00dev, 152, &value);
4005 if (ant == 0) {
4006 /* Main antenna */
4007 rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 1);
4008 } else {
4009 /* Auxiliary antenna */
4010 rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 0);
4011 }
4012 rt2800_bbp_write(rt2x00dev, 152, value);
4013
4014 if (rt2x00_rt_rev_gte(rt2x00dev, RT5592, REV_RT5592C)) {
4015 rt2800_bbp_read(rt2x00dev, 254, &value);
4016 rt2x00_set_field8(&value, BBP254_BIT7, 1);
4017 rt2800_bbp_write(rt2x00dev, 254, value);
4018 }
4019
Stanislaw Gruszkac2675482013-03-16 19:19:41 +01004020 rt2800_init_freq_calibration(rt2x00dev);
4021
Stanislaw Gruszkaa7bbbe52013-03-16 19:19:34 +01004022 rt2800_bbp_write(rt2x00dev, 84, 0x19);
Stanislaw Gruszka6e04f252013-03-16 19:19:38 +01004023 if (rt2x00_rt_rev_gte(rt2x00dev, RT5592, REV_RT5592C))
4024 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
Stanislaw Gruszkaa7bbbe52013-03-16 19:19:34 +01004025}
4026
Ivo van Doornb9a07ae2010-08-23 19:55:22 +02004027static int rt2800_init_bbp(struct rt2x00_dev *rt2x00dev)
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01004028{
4029 unsigned int i;
4030 u16 eeprom;
4031 u8 reg_id;
4032 u8 value;
4033
4034 if (unlikely(rt2800_wait_bbp_rf_ready(rt2x00dev) ||
4035 rt2800_wait_bbp_ready(rt2x00dev)))
4036 return -EACCES;
4037
Stanislaw Gruszkaa7bbbe52013-03-16 19:19:34 +01004038 if (rt2x00_rt(rt2x00dev, RT5592)) {
4039 rt2800_init_bbp_5592(rt2x00dev);
4040 return 0;
4041 }
4042
Daniel Golle03839952012-09-09 14:24:39 +03004043 if (rt2x00_rt(rt2x00dev, RT3352)) {
4044 rt2800_bbp_write(rt2x00dev, 3, 0x00);
4045 rt2800_bbp_write(rt2x00dev, 4, 0x50);
4046 }
4047
Woody Hunga89534e2012-06-13 15:01:16 +08004048 if (rt2x00_rt(rt2x00dev, RT3290) ||
4049 rt2x00_rt(rt2x00dev, RT5390) ||
Stanislaw Gruszkaa7bbbe52013-03-16 19:19:34 +01004050 rt2x00_rt(rt2x00dev, RT5392))
4051 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01004052
Gabor Juhosadde5882011-03-03 11:46:45 +01004053 if (rt2800_is_305x_soc(rt2x00dev) ||
Woody Hunga89534e2012-06-13 15:01:16 +08004054 rt2x00_rt(rt2x00dev, RT3290) ||
Daniel Golle03839952012-09-09 14:24:39 +03004055 rt2x00_rt(rt2x00dev, RT3352) ||
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02004056 rt2x00_rt(rt2x00dev, RT3572) ||
John Li2ed71882012-02-17 17:33:06 +08004057 rt2x00_rt(rt2x00dev, RT5390) ||
4058 rt2x00_rt(rt2x00dev, RT5392))
Helmut Schaabaff8002010-04-28 09:58:59 +02004059 rt2800_bbp_write(rt2x00dev, 31, 0x08);
4060
Daniel Golle03839952012-09-09 14:24:39 +03004061 if (rt2x00_rt(rt2x00dev, RT3352))
4062 rt2800_bbp_write(rt2x00dev, 47, 0x48);
4063
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01004064 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
4065 rt2800_bbp_write(rt2x00dev, 66, 0x38);
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02004066
Woody Hunga89534e2012-06-13 15:01:16 +08004067 if (rt2x00_rt(rt2x00dev, RT3290) ||
Daniel Golle03839952012-09-09 14:24:39 +03004068 rt2x00_rt(rt2x00dev, RT3352) ||
Woody Hunga89534e2012-06-13 15:01:16 +08004069 rt2x00_rt(rt2x00dev, RT5390) ||
4070 rt2x00_rt(rt2x00dev, RT5392))
Gabor Juhosadde5882011-03-03 11:46:45 +01004071 rt2800_bbp_write(rt2x00dev, 68, 0x0b);
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01004072
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02004073 if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) {
4074 rt2800_bbp_write(rt2x00dev, 69, 0x16);
4075 rt2800_bbp_write(rt2x00dev, 73, 0x12);
Woody Hunga89534e2012-06-13 15:01:16 +08004076 } else if (rt2x00_rt(rt2x00dev, RT3290) ||
Daniel Golle03839952012-09-09 14:24:39 +03004077 rt2x00_rt(rt2x00dev, RT3352) ||
Woody Hunga89534e2012-06-13 15:01:16 +08004078 rt2x00_rt(rt2x00dev, RT5390) ||
4079 rt2x00_rt(rt2x00dev, RT5392)) {
Gabor Juhosadde5882011-03-03 11:46:45 +01004080 rt2800_bbp_write(rt2x00dev, 69, 0x12);
4081 rt2800_bbp_write(rt2x00dev, 73, 0x13);
4082 rt2800_bbp_write(rt2x00dev, 75, 0x46);
4083 rt2800_bbp_write(rt2x00dev, 76, 0x28);
Woody Hunga89534e2012-06-13 15:01:16 +08004084
4085 if (rt2x00_rt(rt2x00dev, RT3290))
4086 rt2800_bbp_write(rt2x00dev, 77, 0x58);
4087 else
4088 rt2800_bbp_write(rt2x00dev, 77, 0x59);
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02004089 } else {
4090 rt2800_bbp_write(rt2x00dev, 69, 0x12);
4091 rt2800_bbp_write(rt2x00dev, 73, 0x10);
4092 }
4093
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01004094 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
Gertjan van Wingerde8cdd15e2010-04-11 14:31:12 +02004095
Gertjan van Wingerded5385bf2010-04-11 14:31:13 +02004096 if (rt2x00_rt(rt2x00dev, RT3070) ||
Gertjan van Wingerde64522952010-04-11 14:31:14 +02004097 rt2x00_rt(rt2x00dev, RT3071) ||
Gertjan van Wingerdecc78e902010-04-11 14:31:15 +02004098 rt2x00_rt(rt2x00dev, RT3090) ||
Gabor Juhosadde5882011-03-03 11:46:45 +01004099 rt2x00_rt(rt2x00dev, RT3390) ||
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02004100 rt2x00_rt(rt2x00dev, RT3572) ||
John Li2ed71882012-02-17 17:33:06 +08004101 rt2x00_rt(rt2x00dev, RT5390) ||
4102 rt2x00_rt(rt2x00dev, RT5392)) {
Gertjan van Wingerde8cdd15e2010-04-11 14:31:12 +02004103 rt2800_bbp_write(rt2x00dev, 79, 0x13);
4104 rt2800_bbp_write(rt2x00dev, 80, 0x05);
4105 rt2800_bbp_write(rt2x00dev, 81, 0x33);
Helmut Schaabaff8002010-04-28 09:58:59 +02004106 } else if (rt2800_is_305x_soc(rt2x00dev)) {
4107 rt2800_bbp_write(rt2x00dev, 78, 0x0e);
4108 rt2800_bbp_write(rt2x00dev, 80, 0x08);
Gertjan van Wingerde59d12872012-09-16 22:29:51 +02004109 } else if (rt2x00_rt(rt2x00dev, RT3290)) {
4110 rt2800_bbp_write(rt2x00dev, 74, 0x0b);
4111 rt2800_bbp_write(rt2x00dev, 79, 0x18);
4112 rt2800_bbp_write(rt2x00dev, 80, 0x09);
4113 rt2800_bbp_write(rt2x00dev, 81, 0x33);
Daniel Golle03839952012-09-09 14:24:39 +03004114 } else if (rt2x00_rt(rt2x00dev, RT3352)) {
4115 rt2800_bbp_write(rt2x00dev, 78, 0x0e);
4116 rt2800_bbp_write(rt2x00dev, 80, 0x08);
4117 rt2800_bbp_write(rt2x00dev, 81, 0x37);
Gertjan van Wingerde8cdd15e2010-04-11 14:31:12 +02004118 } else {
4119 rt2800_bbp_write(rt2x00dev, 81, 0x37);
4120 }
4121
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01004122 rt2800_bbp_write(rt2x00dev, 82, 0x62);
Woody Hunga89534e2012-06-13 15:01:16 +08004123 if (rt2x00_rt(rt2x00dev, RT3290) ||
4124 rt2x00_rt(rt2x00dev, RT5390) ||
4125 rt2x00_rt(rt2x00dev, RT5392))
Gabor Juhosadde5882011-03-03 11:46:45 +01004126 rt2800_bbp_write(rt2x00dev, 83, 0x7a);
4127 else
4128 rt2800_bbp_write(rt2x00dev, 83, 0x6a);
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02004129
Gertjan van Wingerde5ed8f452010-06-03 10:51:57 +02004130 if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860D))
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02004131 rt2800_bbp_write(rt2x00dev, 84, 0x19);
Woody Hunga89534e2012-06-13 15:01:16 +08004132 else if (rt2x00_rt(rt2x00dev, RT3290) ||
Gabor Juhose6d227b2012-12-02 15:53:28 +01004133 rt2x00_rt(rt2x00dev, RT5390) ||
4134 rt2x00_rt(rt2x00dev, RT5392))
Gabor Juhosadde5882011-03-03 11:46:45 +01004135 rt2800_bbp_write(rt2x00dev, 84, 0x9a);
Gertjan van Wingerdea9dce142010-04-11 14:31:11 +02004136 else
4137 rt2800_bbp_write(rt2x00dev, 84, 0x99);
4138
Woody Hunga89534e2012-06-13 15:01:16 +08004139 if (rt2x00_rt(rt2x00dev, RT3290) ||
Daniel Golle03839952012-09-09 14:24:39 +03004140 rt2x00_rt(rt2x00dev, RT3352) ||
Woody Hunga89534e2012-06-13 15:01:16 +08004141 rt2x00_rt(rt2x00dev, RT5390) ||
4142 rt2x00_rt(rt2x00dev, RT5392))
Gabor Juhosadde5882011-03-03 11:46:45 +01004143 rt2800_bbp_write(rt2x00dev, 86, 0x38);
4144 else
4145 rt2800_bbp_write(rt2x00dev, 86, 0x00);
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01004146
Daniel Golle03839952012-09-09 14:24:39 +03004147 if (rt2x00_rt(rt2x00dev, RT3352) ||
4148 rt2x00_rt(rt2x00dev, RT5392))
John Li2ed71882012-02-17 17:33:06 +08004149 rt2800_bbp_write(rt2x00dev, 88, 0x90);
4150
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01004151 rt2800_bbp_write(rt2x00dev, 91, 0x04);
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01004152
Woody Hunga89534e2012-06-13 15:01:16 +08004153 if (rt2x00_rt(rt2x00dev, RT3290) ||
Daniel Golle03839952012-09-09 14:24:39 +03004154 rt2x00_rt(rt2x00dev, RT3352) ||
Woody Hunga89534e2012-06-13 15:01:16 +08004155 rt2x00_rt(rt2x00dev, RT5390) ||
4156 rt2x00_rt(rt2x00dev, RT5392))
Gabor Juhosadde5882011-03-03 11:46:45 +01004157 rt2800_bbp_write(rt2x00dev, 92, 0x02);
4158 else
4159 rt2800_bbp_write(rt2x00dev, 92, 0x00);
Gertjan van Wingerde8cdd15e2010-04-11 14:31:12 +02004160
John Li2ed71882012-02-17 17:33:06 +08004161 if (rt2x00_rt(rt2x00dev, RT5392)) {
4162 rt2800_bbp_write(rt2x00dev, 95, 0x9a);
4163 rt2800_bbp_write(rt2x00dev, 98, 0x12);
4164 }
4165
Gertjan van Wingerded5385bf2010-04-11 14:31:13 +02004166 if (rt2x00_rt_rev_gte(rt2x00dev, RT3070, REV_RT3070F) ||
Gertjan van Wingerde64522952010-04-11 14:31:14 +02004167 rt2x00_rt_rev_gte(rt2x00dev, RT3071, REV_RT3071E) ||
Gertjan van Wingerdecc78e902010-04-11 14:31:15 +02004168 rt2x00_rt_rev_gte(rt2x00dev, RT3090, REV_RT3090E) ||
Helmut Schaabaff8002010-04-28 09:58:59 +02004169 rt2x00_rt_rev_gte(rt2x00dev, RT3390, REV_RT3390E) ||
Woody Hunga89534e2012-06-13 15:01:16 +08004170 rt2x00_rt(rt2x00dev, RT3290) ||
Daniel Golle03839952012-09-09 14:24:39 +03004171 rt2x00_rt(rt2x00dev, RT3352) ||
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02004172 rt2x00_rt(rt2x00dev, RT3572) ||
Gabor Juhosadde5882011-03-03 11:46:45 +01004173 rt2x00_rt(rt2x00dev, RT5390) ||
John Li2ed71882012-02-17 17:33:06 +08004174 rt2x00_rt(rt2x00dev, RT5392) ||
Helmut Schaabaff8002010-04-28 09:58:59 +02004175 rt2800_is_305x_soc(rt2x00dev))
Gertjan van Wingerde8cdd15e2010-04-11 14:31:12 +02004176 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
4177 else
4178 rt2800_bbp_write(rt2x00dev, 103, 0x00);
4179
Woody Hunga89534e2012-06-13 15:01:16 +08004180 if (rt2x00_rt(rt2x00dev, RT3290) ||
Daniel Golle03839952012-09-09 14:24:39 +03004181 rt2x00_rt(rt2x00dev, RT3352) ||
Woody Hunga89534e2012-06-13 15:01:16 +08004182 rt2x00_rt(rt2x00dev, RT5390) ||
4183 rt2x00_rt(rt2x00dev, RT5392))
Gabor Juhosadde5882011-03-03 11:46:45 +01004184 rt2800_bbp_write(rt2x00dev, 104, 0x92);
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01004185
Helmut Schaabaff8002010-04-28 09:58:59 +02004186 if (rt2800_is_305x_soc(rt2x00dev))
4187 rt2800_bbp_write(rt2x00dev, 105, 0x01);
Woody Hunga89534e2012-06-13 15:01:16 +08004188 else if (rt2x00_rt(rt2x00dev, RT3290))
4189 rt2800_bbp_write(rt2x00dev, 105, 0x1c);
Daniel Golle03839952012-09-09 14:24:39 +03004190 else if (rt2x00_rt(rt2x00dev, RT3352))
4191 rt2800_bbp_write(rt2x00dev, 105, 0x34);
John Li2ed71882012-02-17 17:33:06 +08004192 else if (rt2x00_rt(rt2x00dev, RT5390) ||
Gabor Juhose6d227b2012-12-02 15:53:28 +01004193 rt2x00_rt(rt2x00dev, RT5392))
Gabor Juhosadde5882011-03-03 11:46:45 +01004194 rt2800_bbp_write(rt2x00dev, 105, 0x3c);
Helmut Schaabaff8002010-04-28 09:58:59 +02004195 else
4196 rt2800_bbp_write(rt2x00dev, 105, 0x05);
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01004197
Woody Hunga89534e2012-06-13 15:01:16 +08004198 if (rt2x00_rt(rt2x00dev, RT3290) ||
4199 rt2x00_rt(rt2x00dev, RT5390))
Gabor Juhosadde5882011-03-03 11:46:45 +01004200 rt2800_bbp_write(rt2x00dev, 106, 0x03);
Daniel Golle03839952012-09-09 14:24:39 +03004201 else if (rt2x00_rt(rt2x00dev, RT3352))
4202 rt2800_bbp_write(rt2x00dev, 106, 0x05);
John Li2ed71882012-02-17 17:33:06 +08004203 else if (rt2x00_rt(rt2x00dev, RT5392))
4204 rt2800_bbp_write(rt2x00dev, 106, 0x12);
Gabor Juhosadde5882011-03-03 11:46:45 +01004205 else
4206 rt2800_bbp_write(rt2x00dev, 106, 0x35);
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01004207
Daniel Golle03839952012-09-09 14:24:39 +03004208 if (rt2x00_rt(rt2x00dev, RT3352))
4209 rt2800_bbp_write(rt2x00dev, 120, 0x50);
4210
Woody Hunga89534e2012-06-13 15:01:16 +08004211 if (rt2x00_rt(rt2x00dev, RT3290) ||
4212 rt2x00_rt(rt2x00dev, RT5390) ||
4213 rt2x00_rt(rt2x00dev, RT5392))
Gabor Juhosadde5882011-03-03 11:46:45 +01004214 rt2800_bbp_write(rt2x00dev, 128, 0x12);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01004215
John Li2ed71882012-02-17 17:33:06 +08004216 if (rt2x00_rt(rt2x00dev, RT5392)) {
4217 rt2800_bbp_write(rt2x00dev, 134, 0xd0);
4218 rt2800_bbp_write(rt2x00dev, 135, 0xf6);
4219 }
4220
Daniel Golle03839952012-09-09 14:24:39 +03004221 if (rt2x00_rt(rt2x00dev, RT3352))
4222 rt2800_bbp_write(rt2x00dev, 137, 0x0f);
4223
Gertjan van Wingerde64522952010-04-11 14:31:14 +02004224 if (rt2x00_rt(rt2x00dev, RT3071) ||
Gertjan van Wingerdecc78e902010-04-11 14:31:15 +02004225 rt2x00_rt(rt2x00dev, RT3090) ||
Gabor Juhosadde5882011-03-03 11:46:45 +01004226 rt2x00_rt(rt2x00dev, RT3390) ||
Gertjan van Wingerde872834d2011-05-18 20:25:31 +02004227 rt2x00_rt(rt2x00dev, RT3572) ||
John Li2ed71882012-02-17 17:33:06 +08004228 rt2x00_rt(rt2x00dev, RT5390) ||
4229 rt2x00_rt(rt2x00dev, RT5392)) {
Gertjan van Wingerded5385bf2010-04-11 14:31:13 +02004230 rt2800_bbp_read(rt2x00dev, 138, &value);
4231
RA-Jay Hung38c8a562010-12-13 12:31:27 +01004232 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom);
4233 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) == 1)
Gertjan van Wingerded5385bf2010-04-11 14:31:13 +02004234 value |= 0x20;
RA-Jay Hung38c8a562010-12-13 12:31:27 +01004235 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) == 1)
Gertjan van Wingerded5385bf2010-04-11 14:31:13 +02004236 value &= ~0x02;
4237
4238 rt2800_bbp_write(rt2x00dev, 138, value);
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01004239 }
4240
Woody Hunga89534e2012-06-13 15:01:16 +08004241 if (rt2x00_rt(rt2x00dev, RT3290)) {
4242 rt2800_bbp_write(rt2x00dev, 67, 0x24);
4243 rt2800_bbp_write(rt2x00dev, 143, 0x04);
4244 rt2800_bbp_write(rt2x00dev, 142, 0x99);
4245 rt2800_bbp_write(rt2x00dev, 150, 0x30);
4246 rt2800_bbp_write(rt2x00dev, 151, 0x2e);
4247 rt2800_bbp_write(rt2x00dev, 152, 0x20);
4248 rt2800_bbp_write(rt2x00dev, 153, 0x34);
4249 rt2800_bbp_write(rt2x00dev, 154, 0x40);
4250 rt2800_bbp_write(rt2x00dev, 155, 0x3b);
4251 rt2800_bbp_write(rt2x00dev, 253, 0x04);
4252
4253 rt2800_bbp_read(rt2x00dev, 47, &value);
4254 rt2x00_set_field8(&value, BBP47_TSSI_ADC6, 1);
4255 rt2800_bbp_write(rt2x00dev, 47, value);
4256
4257 /* Use 5-bit ADC for Acquisition and 8-bit ADC for data */
4258 rt2800_bbp_read(rt2x00dev, 3, &value);
4259 rt2x00_set_field8(&value, BBP3_ADC_MODE_SWITCH, 1);
4260 rt2x00_set_field8(&value, BBP3_ADC_INIT_MODE, 1);
4261 rt2800_bbp_write(rt2x00dev, 3, value);
4262 }
4263
Daniel Golle03839952012-09-09 14:24:39 +03004264 if (rt2x00_rt(rt2x00dev, RT3352)) {
4265 rt2800_bbp_write(rt2x00dev, 163, 0xbd);
4266 /* Set ITxBF timeout to 0x9c40=1000msec */
4267 rt2800_bbp_write(rt2x00dev, 179, 0x02);
4268 rt2800_bbp_write(rt2x00dev, 180, 0x00);
4269 rt2800_bbp_write(rt2x00dev, 182, 0x40);
4270 rt2800_bbp_write(rt2x00dev, 180, 0x01);
4271 rt2800_bbp_write(rt2x00dev, 182, 0x9c);
4272 rt2800_bbp_write(rt2x00dev, 179, 0x00);
4273 /* Reprogram the inband interface to put right values in RXWI */
4274 rt2800_bbp_write(rt2x00dev, 142, 0x04);
4275 rt2800_bbp_write(rt2x00dev, 143, 0x3b);
4276 rt2800_bbp_write(rt2x00dev, 142, 0x06);
4277 rt2800_bbp_write(rt2x00dev, 143, 0xa0);
4278 rt2800_bbp_write(rt2x00dev, 142, 0x07);
4279 rt2800_bbp_write(rt2x00dev, 143, 0xa1);
4280 rt2800_bbp_write(rt2x00dev, 142, 0x08);
4281 rt2800_bbp_write(rt2x00dev, 143, 0xa2);
4282
4283 rt2800_bbp_write(rt2x00dev, 148, 0xc8);
4284 }
4285
John Li2ed71882012-02-17 17:33:06 +08004286 if (rt2x00_rt(rt2x00dev, RT5390) ||
Gabor Juhose6d227b2012-12-02 15:53:28 +01004287 rt2x00_rt(rt2x00dev, RT5392)) {
Gabor Juhosadde5882011-03-03 11:46:45 +01004288 int ant, div_mode;
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01004289
Gabor Juhosadde5882011-03-03 11:46:45 +01004290 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
4291 div_mode = rt2x00_get_field16(eeprom,
4292 EEPROM_NIC_CONF1_ANT_DIVERSITY);
4293 ant = (div_mode == 3) ? 1 : 0;
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01004294
Gabor Juhosadde5882011-03-03 11:46:45 +01004295 /* check if this is a Bluetooth combo card */
Gertjan van Wingerdefdbc7b02011-04-30 17:15:37 +02004296 if (test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags)) {
Gabor Juhosadde5882011-03-03 11:46:45 +01004297 u32 reg;
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01004298
Gertjan van Wingerde99bdf512012-08-31 19:22:13 +02004299 rt2800_register_read(rt2x00dev, GPIO_CTRL, &reg);
4300 rt2x00_set_field32(&reg, GPIO_CTRL_DIR3, 0);
4301 rt2x00_set_field32(&reg, GPIO_CTRL_DIR6, 0);
4302 rt2x00_set_field32(&reg, GPIO_CTRL_VAL3, 0);
4303 rt2x00_set_field32(&reg, GPIO_CTRL_VAL6, 0);
Gabor Juhosadde5882011-03-03 11:46:45 +01004304 if (ant == 0)
Gertjan van Wingerde99bdf512012-08-31 19:22:13 +02004305 rt2x00_set_field32(&reg, GPIO_CTRL_VAL3, 1);
Gabor Juhosadde5882011-03-03 11:46:45 +01004306 else if (ant == 1)
Gertjan van Wingerde99bdf512012-08-31 19:22:13 +02004307 rt2x00_set_field32(&reg, GPIO_CTRL_VAL6, 1);
4308 rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
Gabor Juhosadde5882011-03-03 11:46:45 +01004309 }
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01004310
Anisse Astier0586a112012-04-23 12:33:11 +02004311 /* This chip has hardware antenna diversity*/
4312 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390R)) {
4313 rt2800_bbp_write(rt2x00dev, 150, 0); /* Disable Antenna Software OFDM */
4314 rt2800_bbp_write(rt2x00dev, 151, 0); /* Disable Antenna Software CCK */
4315 rt2800_bbp_write(rt2x00dev, 154, 0); /* Clear previously selected antenna */
4316 }
4317
Gabor Juhosadde5882011-03-03 11:46:45 +01004318 rt2800_bbp_read(rt2x00dev, 152, &value);
4319 if (ant == 0)
4320 rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 1);
4321 else
4322 rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 0);
4323 rt2800_bbp_write(rt2x00dev, 152, value);
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01004324
Stanislaw Gruszkac2675482013-03-16 19:19:41 +01004325 rt2800_init_freq_calibration(rt2x00dev);
Gabor Juhosadde5882011-03-03 11:46:45 +01004326 }
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01004327
4328 for (i = 0; i < EEPROM_BBP_SIZE; i++) {
4329 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
4330
4331 if (eeprom != 0xffff && eeprom != 0x0000) {
4332 reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
4333 value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
4334 rt2800_bbp_write(rt2x00dev, reg_id, value);
4335 }
4336 }
4337
4338 return 0;
4339}
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01004340
Stanislaw Gruszkad9517f22013-04-17 14:08:18 +02004341static void rt2800_led_open_drain_enable(struct rt2x00_dev *rt2x00dev)
4342{
4343 u32 reg;
4344
4345 rt2800_register_read(rt2x00dev, OPT_14_CSR, &reg);
4346 rt2x00_set_field32(&reg, OPT_14_CSR_BIT0, 1);
4347 rt2800_register_write(rt2x00dev, OPT_14_CSR, reg);
4348}
4349
Stanislaw Gruszkac5b3c352013-04-17 14:08:16 +02004350static u8 rt2800_init_rx_filter(struct rt2x00_dev *rt2x00dev, bool bw40,
4351 u8 filter_target)
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01004352{
4353 unsigned int i;
4354 u8 bbp;
4355 u8 rfcsr;
4356 u8 passband;
4357 u8 stopband;
4358 u8 overtuned = 0;
Stanislaw Gruszkac5b3c352013-04-17 14:08:16 +02004359 u8 rfcsr24 = (bw40) ? 0x27 : 0x07;
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01004360
4361 rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
4362
4363 rt2800_bbp_read(rt2x00dev, 4, &bbp);
4364 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * bw40);
4365 rt2800_bbp_write(rt2x00dev, 4, bbp);
4366
RA-Jay Hung80d184e2011-01-10 11:28:10 +01004367 rt2800_rfcsr_read(rt2x00dev, 31, &rfcsr);
4368 rt2x00_set_field8(&rfcsr, RFCSR31_RX_H20M, bw40);
4369 rt2800_rfcsr_write(rt2x00dev, 31, rfcsr);
4370
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01004371 rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr);
4372 rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 1);
4373 rt2800_rfcsr_write(rt2x00dev, 22, rfcsr);
4374
4375 /*
4376 * Set power & frequency of passband test tone
4377 */
4378 rt2800_bbp_write(rt2x00dev, 24, 0);
4379
4380 for (i = 0; i < 100; i++) {
4381 rt2800_bbp_write(rt2x00dev, 25, 0x90);
4382 msleep(1);
4383
4384 rt2800_bbp_read(rt2x00dev, 55, &passband);
4385 if (passband)
4386 break;
4387 }
4388
4389 /*
4390 * Set power & frequency of stopband test tone
4391 */
4392 rt2800_bbp_write(rt2x00dev, 24, 0x06);
4393
4394 for (i = 0; i < 100; i++) {
4395 rt2800_bbp_write(rt2x00dev, 25, 0x90);
4396 msleep(1);
4397
4398 rt2800_bbp_read(rt2x00dev, 55, &stopband);
4399
4400 if ((passband - stopband) <= filter_target) {
4401 rfcsr24++;
4402 overtuned += ((passband - stopband) == filter_target);
4403 } else
4404 break;
4405
4406 rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
4407 }
4408
4409 rfcsr24 -= !!overtuned;
4410
4411 rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
4412 return rfcsr24;
4413}
4414
Stanislaw Gruszkace94ede92013-04-17 14:08:11 +02004415static void rt2800_rf_init_calibration(struct rt2x00_dev *rt2x00dev,
4416 const unsigned int rf_reg)
4417{
4418 u8 rfcsr;
4419
4420 rt2800_rfcsr_read(rt2x00dev, rf_reg, &rfcsr);
4421 rt2x00_set_field8(&rfcsr, FIELD8(0x80), 1);
4422 rt2800_rfcsr_write(rt2x00dev, rf_reg, rfcsr);
4423 msleep(1);
4424 rt2x00_set_field8(&rfcsr, FIELD8(0x80), 0);
4425 rt2800_rfcsr_write(rt2x00dev, rf_reg, rfcsr);
4426}
4427
Stanislaw Gruszkac5b3c352013-04-17 14:08:16 +02004428static void rt2800_rx_filter_calibration(struct rt2x00_dev *rt2x00dev)
4429{
4430 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
4431 u8 filter_tgt_bw20;
4432 u8 filter_tgt_bw40;
4433 u8 rfcsr, bbp;
4434
4435 /*
4436 * TODO: sync filter_tgt values with vendor driver
4437 */
4438 if (rt2x00_rt(rt2x00dev, RT3070)) {
4439 filter_tgt_bw20 = 0x16;
4440 filter_tgt_bw40 = 0x19;
4441 } else {
4442 filter_tgt_bw20 = 0x13;
4443 filter_tgt_bw40 = 0x15;
4444 }
4445
4446 drv_data->calibration_bw20 =
4447 rt2800_init_rx_filter(rt2x00dev, false, filter_tgt_bw20);
4448 drv_data->calibration_bw40 =
4449 rt2800_init_rx_filter(rt2x00dev, true, filter_tgt_bw40);
4450
4451 /*
4452 * Save BBP 25 & 26 values for later use in channel switching (for 3052)
4453 */
4454 rt2800_bbp_read(rt2x00dev, 25, &drv_data->bbp25);
4455 rt2800_bbp_read(rt2x00dev, 26, &drv_data->bbp26);
4456
4457 /*
4458 * Set back to initial state
4459 */
4460 rt2800_bbp_write(rt2x00dev, 24, 0);
4461
4462 rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr);
4463 rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 0);
4464 rt2800_rfcsr_write(rt2x00dev, 22, rfcsr);
4465
4466 /*
4467 * Set BBP back to BW20
4468 */
4469 rt2800_bbp_read(rt2x00dev, 4, &bbp);
4470 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0);
4471 rt2800_bbp_write(rt2x00dev, 4, bbp);
4472}
4473
Stanislaw Gruszkada8064c2013-04-17 14:08:19 +02004474static void rt2800_normal_mode_setup_3xxx(struct rt2x00_dev *rt2x00dev)
4475{
4476 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
4477 u8 min_gain, rfcsr, bbp;
4478 u16 eeprom;
4479
4480 rt2800_rfcsr_read(rt2x00dev, 17, &rfcsr);
4481
4482 rt2x00_set_field8(&rfcsr, RFCSR17_TX_LO1_EN, 0);
4483 if (rt2x00_rt(rt2x00dev, RT3070) ||
4484 rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) ||
4485 rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E) ||
4486 rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) {
4487 if (!test_bit(CAPABILITY_EXTERNAL_LNA_BG, &rt2x00dev->cap_flags))
4488 rt2x00_set_field8(&rfcsr, RFCSR17_R, 1);
4489 }
4490
4491 min_gain = rt2x00_rt(rt2x00dev, RT3070) ? 1 : 2;
4492 if (drv_data->txmixer_gain_24g >= min_gain) {
4493 rt2x00_set_field8(&rfcsr, RFCSR17_TXMIXER_GAIN,
4494 drv_data->txmixer_gain_24g);
4495 }
4496
4497 rt2800_rfcsr_write(rt2x00dev, 17, rfcsr);
4498
4499 if (rt2x00_rt(rt2x00dev, RT3090)) {
4500 /* Turn off unused DAC1 and ADC1 to reduce power consumption */
4501 rt2800_bbp_read(rt2x00dev, 138, &bbp);
4502 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom);
4503 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) == 1)
4504 rt2x00_set_field8(&bbp, BBP138_RX_ADC1, 0);
4505 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) == 1)
4506 rt2x00_set_field8(&bbp, BBP138_TX_DAC1, 1);
4507 rt2800_bbp_write(rt2x00dev, 138, bbp);
4508 }
4509
4510 if (rt2x00_rt(rt2x00dev, RT3070)) {
4511 rt2800_rfcsr_read(rt2x00dev, 27, &rfcsr);
4512 if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F))
4513 rt2x00_set_field8(&rfcsr, RFCSR27_R1, 3);
4514 else
4515 rt2x00_set_field8(&rfcsr, RFCSR27_R1, 0);
4516 rt2x00_set_field8(&rfcsr, RFCSR27_R2, 0);
4517 rt2x00_set_field8(&rfcsr, RFCSR27_R3, 0);
4518 rt2x00_set_field8(&rfcsr, RFCSR27_R4, 0);
4519 rt2800_rfcsr_write(rt2x00dev, 27, rfcsr);
4520 } else if (rt2x00_rt(rt2x00dev, RT3071) ||
4521 rt2x00_rt(rt2x00dev, RT3090) ||
4522 rt2x00_rt(rt2x00dev, RT3390)) {
4523 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
4524 rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
4525 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0);
4526 rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0);
4527 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
4528 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
4529 rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
4530
4531 rt2800_rfcsr_read(rt2x00dev, 15, &rfcsr);
4532 rt2x00_set_field8(&rfcsr, RFCSR15_TX_LO2_EN, 0);
4533 rt2800_rfcsr_write(rt2x00dev, 15, rfcsr);
4534
4535 rt2800_rfcsr_read(rt2x00dev, 20, &rfcsr);
4536 rt2x00_set_field8(&rfcsr, RFCSR20_RX_LO1_EN, 0);
4537 rt2800_rfcsr_write(rt2x00dev, 20, rfcsr);
4538
4539 rt2800_rfcsr_read(rt2x00dev, 21, &rfcsr);
4540 rt2x00_set_field8(&rfcsr, RFCSR21_RX_LO2_EN, 0);
4541 rt2800_rfcsr_write(rt2x00dev, 21, rfcsr);
4542 }
4543}
4544
Stanislaw Gruszkaf7df8fe2013-04-17 14:08:10 +02004545static void rt2800_normal_mode_setup_5xxx(struct rt2x00_dev *rt2x00dev)
4546{
4547 u8 reg;
4548 u16 eeprom;
4549
4550 /* Turn off unused DAC1 and ADC1 to reduce power consumption */
4551 rt2800_bbp_read(rt2x00dev, 138, &reg);
4552 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom);
4553 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) == 1)
4554 rt2x00_set_field8(&reg, BBP138_RX_ADC1, 0);
4555 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) == 1)
4556 rt2x00_set_field8(&reg, BBP138_TX_DAC1, 1);
4557 rt2800_bbp_write(rt2x00dev, 138, reg);
4558
4559 rt2800_rfcsr_read(rt2x00dev, 38, &reg);
4560 rt2x00_set_field8(&reg, RFCSR38_RX_LO1_EN, 0);
4561 rt2800_rfcsr_write(rt2x00dev, 38, reg);
4562
4563 rt2800_rfcsr_read(rt2x00dev, 39, &reg);
4564 rt2x00_set_field8(&reg, RFCSR39_RX_LO2_EN, 0);
4565 rt2800_rfcsr_write(rt2x00dev, 39, reg);
4566
4567 rt2800_bbp4_mac_if_ctrl(rt2x00dev);
4568
4569 rt2800_rfcsr_read(rt2x00dev, 30, &reg);
4570 rt2x00_set_field8(&reg, RFCSR30_RX_VCM, 2);
4571 rt2800_rfcsr_write(rt2x00dev, 30, reg);
4572}
4573
Stanislaw Gruszkad5374ef2012-12-12 06:30:55 +01004574static void rt2800_init_rfcsr_305x_soc(struct rt2x00_dev *rt2x00dev)
4575{
Stanislaw Gruszkace94ede92013-04-17 14:08:11 +02004576 rt2800_rf_init_calibration(rt2x00dev, 30);
4577
Stanislaw Gruszkad5374ef2012-12-12 06:30:55 +01004578 rt2800_rfcsr_write(rt2x00dev, 0, 0x50);
4579 rt2800_rfcsr_write(rt2x00dev, 1, 0x01);
4580 rt2800_rfcsr_write(rt2x00dev, 2, 0xf7);
4581 rt2800_rfcsr_write(rt2x00dev, 3, 0x75);
4582 rt2800_rfcsr_write(rt2x00dev, 4, 0x40);
4583 rt2800_rfcsr_write(rt2x00dev, 5, 0x03);
4584 rt2800_rfcsr_write(rt2x00dev, 6, 0x02);
4585 rt2800_rfcsr_write(rt2x00dev, 7, 0x50);
4586 rt2800_rfcsr_write(rt2x00dev, 8, 0x39);
4587 rt2800_rfcsr_write(rt2x00dev, 9, 0x0f);
4588 rt2800_rfcsr_write(rt2x00dev, 10, 0x60);
4589 rt2800_rfcsr_write(rt2x00dev, 11, 0x21);
4590 rt2800_rfcsr_write(rt2x00dev, 12, 0x75);
4591 rt2800_rfcsr_write(rt2x00dev, 13, 0x75);
4592 rt2800_rfcsr_write(rt2x00dev, 14, 0x90);
4593 rt2800_rfcsr_write(rt2x00dev, 15, 0x58);
4594 rt2800_rfcsr_write(rt2x00dev, 16, 0xb3);
4595 rt2800_rfcsr_write(rt2x00dev, 17, 0x92);
4596 rt2800_rfcsr_write(rt2x00dev, 18, 0x2c);
4597 rt2800_rfcsr_write(rt2x00dev, 19, 0x02);
4598 rt2800_rfcsr_write(rt2x00dev, 20, 0xba);
4599 rt2800_rfcsr_write(rt2x00dev, 21, 0xdb);
4600 rt2800_rfcsr_write(rt2x00dev, 22, 0x00);
4601 rt2800_rfcsr_write(rt2x00dev, 23, 0x31);
4602 rt2800_rfcsr_write(rt2x00dev, 24, 0x08);
4603 rt2800_rfcsr_write(rt2x00dev, 25, 0x01);
4604 rt2800_rfcsr_write(rt2x00dev, 26, 0x25);
4605 rt2800_rfcsr_write(rt2x00dev, 27, 0x23);
4606 rt2800_rfcsr_write(rt2x00dev, 28, 0x13);
4607 rt2800_rfcsr_write(rt2x00dev, 29, 0x83);
4608 rt2800_rfcsr_write(rt2x00dev, 30, 0x00);
4609 rt2800_rfcsr_write(rt2x00dev, 31, 0x00);
4610}
4611
4612static void rt2800_init_rfcsr_30xx(struct rt2x00_dev *rt2x00dev)
4613{
Stanislaw Gruszkac9a221b2013-04-17 14:08:13 +02004614 u8 rfcsr;
4615 u16 eeprom;
4616 u32 reg;
4617
Stanislaw Gruszkace94ede92013-04-17 14:08:11 +02004618 /* XXX vendor driver do this only for 3070 */
4619 rt2800_rf_init_calibration(rt2x00dev, 30);
4620
Stanislaw Gruszkad5374ef2012-12-12 06:30:55 +01004621 rt2800_rfcsr_write(rt2x00dev, 4, 0x40);
4622 rt2800_rfcsr_write(rt2x00dev, 5, 0x03);
4623 rt2800_rfcsr_write(rt2x00dev, 6, 0x02);
4624 rt2800_rfcsr_write(rt2x00dev, 7, 0x60);
4625 rt2800_rfcsr_write(rt2x00dev, 9, 0x0f);
4626 rt2800_rfcsr_write(rt2x00dev, 10, 0x41);
4627 rt2800_rfcsr_write(rt2x00dev, 11, 0x21);
4628 rt2800_rfcsr_write(rt2x00dev, 12, 0x7b);
4629 rt2800_rfcsr_write(rt2x00dev, 14, 0x90);
4630 rt2800_rfcsr_write(rt2x00dev, 15, 0x58);
4631 rt2800_rfcsr_write(rt2x00dev, 16, 0xb3);
4632 rt2800_rfcsr_write(rt2x00dev, 17, 0x92);
4633 rt2800_rfcsr_write(rt2x00dev, 18, 0x2c);
4634 rt2800_rfcsr_write(rt2x00dev, 19, 0x02);
4635 rt2800_rfcsr_write(rt2x00dev, 20, 0xba);
4636 rt2800_rfcsr_write(rt2x00dev, 21, 0xdb);
4637 rt2800_rfcsr_write(rt2x00dev, 24, 0x16);
4638 rt2800_rfcsr_write(rt2x00dev, 25, 0x01);
4639 rt2800_rfcsr_write(rt2x00dev, 29, 0x1f);
Stanislaw Gruszkac9a221b2013-04-17 14:08:13 +02004640
4641 if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) {
4642 rt2800_register_read(rt2x00dev, LDO_CFG0, &reg);
4643 rt2x00_set_field32(&reg, LDO_CFG0_BGSEL, 1);
4644 rt2x00_set_field32(&reg, LDO_CFG0_LDO_CORE_VLEVEL, 3);
4645 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
4646 } else if (rt2x00_rt(rt2x00dev, RT3071) ||
4647 rt2x00_rt(rt2x00dev, RT3090)) {
4648 rt2800_rfcsr_write(rt2x00dev, 31, 0x14);
4649
4650 rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr);
4651 rt2x00_set_field8(&rfcsr, RFCSR6_R2, 1);
4652 rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
4653
4654 rt2800_register_read(rt2x00dev, LDO_CFG0, &reg);
4655 rt2x00_set_field32(&reg, LDO_CFG0_BGSEL, 1);
4656 if (rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) ||
4657 rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E)) {
4658 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
4659 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_DAC_TEST))
4660 rt2x00_set_field32(&reg, LDO_CFG0_LDO_CORE_VLEVEL, 3);
4661 else
4662 rt2x00_set_field32(&reg, LDO_CFG0_LDO_CORE_VLEVEL, 0);
4663 }
4664 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
4665
4666 rt2800_register_read(rt2x00dev, GPIO_SWITCH, &reg);
4667 rt2x00_set_field32(&reg, GPIO_SWITCH_5, 0);
4668 rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg);
4669 }
Stanislaw Gruszkac5b3c352013-04-17 14:08:16 +02004670
4671 rt2800_rx_filter_calibration(rt2x00dev);
Stanislaw Gruszka5de5a1f2013-04-17 14:08:17 +02004672
4673 if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F) ||
4674 rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) ||
4675 rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E))
4676 rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
Stanislaw Gruszkad9517f22013-04-17 14:08:18 +02004677
4678 rt2800_led_open_drain_enable(rt2x00dev);
Stanislaw Gruszkada8064c2013-04-17 14:08:19 +02004679 rt2800_normal_mode_setup_3xxx(rt2x00dev);
Stanislaw Gruszkad5374ef2012-12-12 06:30:55 +01004680}
4681
4682static void rt2800_init_rfcsr_3290(struct rt2x00_dev *rt2x00dev)
4683{
Stanislaw Gruszkaf9cdcbb2013-04-17 14:08:12 +02004684 u8 rfcsr;
4685
Stanislaw Gruszkace94ede92013-04-17 14:08:11 +02004686 rt2800_rf_init_calibration(rt2x00dev, 2);
4687
Stanislaw Gruszkad5374ef2012-12-12 06:30:55 +01004688 rt2800_rfcsr_write(rt2x00dev, 1, 0x0f);
4689 rt2800_rfcsr_write(rt2x00dev, 2, 0x80);
4690 rt2800_rfcsr_write(rt2x00dev, 3, 0x08);
4691 rt2800_rfcsr_write(rt2x00dev, 4, 0x00);
4692 rt2800_rfcsr_write(rt2x00dev, 6, 0xa0);
4693 rt2800_rfcsr_write(rt2x00dev, 8, 0xf3);
4694 rt2800_rfcsr_write(rt2x00dev, 9, 0x02);
4695 rt2800_rfcsr_write(rt2x00dev, 10, 0x53);
4696 rt2800_rfcsr_write(rt2x00dev, 11, 0x4a);
4697 rt2800_rfcsr_write(rt2x00dev, 12, 0x46);
4698 rt2800_rfcsr_write(rt2x00dev, 13, 0x9f);
4699 rt2800_rfcsr_write(rt2x00dev, 18, 0x02);
4700 rt2800_rfcsr_write(rt2x00dev, 22, 0x20);
4701 rt2800_rfcsr_write(rt2x00dev, 25, 0x83);
4702 rt2800_rfcsr_write(rt2x00dev, 26, 0x82);
4703 rt2800_rfcsr_write(rt2x00dev, 27, 0x09);
4704 rt2800_rfcsr_write(rt2x00dev, 29, 0x10);
4705 rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
4706 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
4707 rt2800_rfcsr_write(rt2x00dev, 32, 0x80);
4708 rt2800_rfcsr_write(rt2x00dev, 33, 0x00);
4709 rt2800_rfcsr_write(rt2x00dev, 34, 0x05);
4710 rt2800_rfcsr_write(rt2x00dev, 35, 0x12);
4711 rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
4712 rt2800_rfcsr_write(rt2x00dev, 38, 0x85);
4713 rt2800_rfcsr_write(rt2x00dev, 39, 0x1b);
4714 rt2800_rfcsr_write(rt2x00dev, 40, 0x0b);
4715 rt2800_rfcsr_write(rt2x00dev, 41, 0xbb);
4716 rt2800_rfcsr_write(rt2x00dev, 42, 0xd5);
4717 rt2800_rfcsr_write(rt2x00dev, 43, 0x7b);
4718 rt2800_rfcsr_write(rt2x00dev, 44, 0x0e);
4719 rt2800_rfcsr_write(rt2x00dev, 45, 0xa2);
4720 rt2800_rfcsr_write(rt2x00dev, 46, 0x73);
4721 rt2800_rfcsr_write(rt2x00dev, 47, 0x00);
4722 rt2800_rfcsr_write(rt2x00dev, 48, 0x10);
4723 rt2800_rfcsr_write(rt2x00dev, 49, 0x98);
4724 rt2800_rfcsr_write(rt2x00dev, 52, 0x38);
4725 rt2800_rfcsr_write(rt2x00dev, 53, 0x00);
4726 rt2800_rfcsr_write(rt2x00dev, 54, 0x78);
4727 rt2800_rfcsr_write(rt2x00dev, 55, 0x43);
4728 rt2800_rfcsr_write(rt2x00dev, 56, 0x02);
4729 rt2800_rfcsr_write(rt2x00dev, 57, 0x80);
4730 rt2800_rfcsr_write(rt2x00dev, 58, 0x7f);
4731 rt2800_rfcsr_write(rt2x00dev, 59, 0x09);
4732 rt2800_rfcsr_write(rt2x00dev, 60, 0x45);
4733 rt2800_rfcsr_write(rt2x00dev, 61, 0xc1);
Stanislaw Gruszkaf9cdcbb2013-04-17 14:08:12 +02004734
4735 rt2800_rfcsr_read(rt2x00dev, 29, &rfcsr);
4736 rt2x00_set_field8(&rfcsr, RFCSR29_RSSI_GAIN, 3);
4737 rt2800_rfcsr_write(rt2x00dev, 29, rfcsr);
Stanislaw Gruszkad9517f22013-04-17 14:08:18 +02004738
4739 rt2800_led_open_drain_enable(rt2x00dev);
Stanislaw Gruszkada8064c2013-04-17 14:08:19 +02004740 rt2800_normal_mode_setup_3xxx(rt2x00dev);
Stanislaw Gruszkad5374ef2012-12-12 06:30:55 +01004741}
4742
4743static void rt2800_init_rfcsr_3352(struct rt2x00_dev *rt2x00dev)
4744{
Stanislaw Gruszkace94ede92013-04-17 14:08:11 +02004745 rt2800_rf_init_calibration(rt2x00dev, 30);
4746
Stanislaw Gruszkad5374ef2012-12-12 06:30:55 +01004747 rt2800_rfcsr_write(rt2x00dev, 0, 0xf0);
4748 rt2800_rfcsr_write(rt2x00dev, 1, 0x23);
4749 rt2800_rfcsr_write(rt2x00dev, 2, 0x50);
4750 rt2800_rfcsr_write(rt2x00dev, 3, 0x18);
4751 rt2800_rfcsr_write(rt2x00dev, 4, 0x00);
4752 rt2800_rfcsr_write(rt2x00dev, 5, 0x00);
4753 rt2800_rfcsr_write(rt2x00dev, 6, 0x33);
4754 rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
4755 rt2800_rfcsr_write(rt2x00dev, 8, 0xf1);
4756 rt2800_rfcsr_write(rt2x00dev, 9, 0x02);
4757 rt2800_rfcsr_write(rt2x00dev, 10, 0xd2);
4758 rt2800_rfcsr_write(rt2x00dev, 11, 0x42);
4759 rt2800_rfcsr_write(rt2x00dev, 12, 0x1c);
4760 rt2800_rfcsr_write(rt2x00dev, 13, 0x00);
4761 rt2800_rfcsr_write(rt2x00dev, 14, 0x5a);
4762 rt2800_rfcsr_write(rt2x00dev, 15, 0x00);
4763 rt2800_rfcsr_write(rt2x00dev, 16, 0x01);
4764 rt2800_rfcsr_write(rt2x00dev, 18, 0x45);
4765 rt2800_rfcsr_write(rt2x00dev, 19, 0x02);
4766 rt2800_rfcsr_write(rt2x00dev, 20, 0x00);
4767 rt2800_rfcsr_write(rt2x00dev, 21, 0x00);
4768 rt2800_rfcsr_write(rt2x00dev, 22, 0x00);
4769 rt2800_rfcsr_write(rt2x00dev, 23, 0x00);
4770 rt2800_rfcsr_write(rt2x00dev, 24, 0x00);
4771 rt2800_rfcsr_write(rt2x00dev, 25, 0x80);
4772 rt2800_rfcsr_write(rt2x00dev, 26, 0x00);
4773 rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
4774 rt2800_rfcsr_write(rt2x00dev, 28, 0x03);
4775 rt2800_rfcsr_write(rt2x00dev, 29, 0x00);
4776 rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
4777 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
4778 rt2800_rfcsr_write(rt2x00dev, 32, 0x80);
4779 rt2800_rfcsr_write(rt2x00dev, 33, 0x00);
4780 rt2800_rfcsr_write(rt2x00dev, 34, 0x01);
4781 rt2800_rfcsr_write(rt2x00dev, 35, 0x03);
4782 rt2800_rfcsr_write(rt2x00dev, 36, 0xbd);
4783 rt2800_rfcsr_write(rt2x00dev, 37, 0x3c);
4784 rt2800_rfcsr_write(rt2x00dev, 38, 0x5f);
4785 rt2800_rfcsr_write(rt2x00dev, 39, 0xc5);
4786 rt2800_rfcsr_write(rt2x00dev, 40, 0x33);
4787 rt2800_rfcsr_write(rt2x00dev, 41, 0x5b);
4788 rt2800_rfcsr_write(rt2x00dev, 42, 0x5b);
4789 rt2800_rfcsr_write(rt2x00dev, 43, 0xdb);
4790 rt2800_rfcsr_write(rt2x00dev, 44, 0xdb);
4791 rt2800_rfcsr_write(rt2x00dev, 45, 0xdb);
4792 rt2800_rfcsr_write(rt2x00dev, 46, 0xdd);
4793 rt2800_rfcsr_write(rt2x00dev, 47, 0x0d);
4794 rt2800_rfcsr_write(rt2x00dev, 48, 0x14);
4795 rt2800_rfcsr_write(rt2x00dev, 49, 0x00);
4796 rt2800_rfcsr_write(rt2x00dev, 50, 0x2d);
4797 rt2800_rfcsr_write(rt2x00dev, 51, 0x7f);
4798 rt2800_rfcsr_write(rt2x00dev, 52, 0x00);
4799 rt2800_rfcsr_write(rt2x00dev, 53, 0x52);
4800 rt2800_rfcsr_write(rt2x00dev, 54, 0x1b);
4801 rt2800_rfcsr_write(rt2x00dev, 55, 0x7f);
4802 rt2800_rfcsr_write(rt2x00dev, 56, 0x00);
4803 rt2800_rfcsr_write(rt2x00dev, 57, 0x52);
4804 rt2800_rfcsr_write(rt2x00dev, 58, 0x1b);
4805 rt2800_rfcsr_write(rt2x00dev, 59, 0x00);
4806 rt2800_rfcsr_write(rt2x00dev, 60, 0x00);
4807 rt2800_rfcsr_write(rt2x00dev, 61, 0x00);
4808 rt2800_rfcsr_write(rt2x00dev, 62, 0x00);
4809 rt2800_rfcsr_write(rt2x00dev, 63, 0x00);
Stanislaw Gruszkac5b3c352013-04-17 14:08:16 +02004810
4811 rt2800_rx_filter_calibration(rt2x00dev);
Stanislaw Gruszkad9517f22013-04-17 14:08:18 +02004812 rt2800_led_open_drain_enable(rt2x00dev);
Stanislaw Gruszkada8064c2013-04-17 14:08:19 +02004813 rt2800_normal_mode_setup_3xxx(rt2x00dev);
Stanislaw Gruszkad5374ef2012-12-12 06:30:55 +01004814}
4815
4816static void rt2800_init_rfcsr_3390(struct rt2x00_dev *rt2x00dev)
4817{
Stanislaw Gruszka2971e662013-04-17 14:08:14 +02004818 u32 reg;
4819
Stanislaw Gruszkace94ede92013-04-17 14:08:11 +02004820 rt2800_rf_init_calibration(rt2x00dev, 30);
4821
Stanislaw Gruszkad5374ef2012-12-12 06:30:55 +01004822 rt2800_rfcsr_write(rt2x00dev, 0, 0xa0);
4823 rt2800_rfcsr_write(rt2x00dev, 1, 0xe1);
4824 rt2800_rfcsr_write(rt2x00dev, 2, 0xf1);
4825 rt2800_rfcsr_write(rt2x00dev, 3, 0x62);
4826 rt2800_rfcsr_write(rt2x00dev, 4, 0x40);
4827 rt2800_rfcsr_write(rt2x00dev, 5, 0x8b);
4828 rt2800_rfcsr_write(rt2x00dev, 6, 0x42);
4829 rt2800_rfcsr_write(rt2x00dev, 7, 0x34);
4830 rt2800_rfcsr_write(rt2x00dev, 8, 0x00);
4831 rt2800_rfcsr_write(rt2x00dev, 9, 0xc0);
4832 rt2800_rfcsr_write(rt2x00dev, 10, 0x61);
4833 rt2800_rfcsr_write(rt2x00dev, 11, 0x21);
4834 rt2800_rfcsr_write(rt2x00dev, 12, 0x3b);
4835 rt2800_rfcsr_write(rt2x00dev, 13, 0xe0);
4836 rt2800_rfcsr_write(rt2x00dev, 14, 0x90);
4837 rt2800_rfcsr_write(rt2x00dev, 15, 0x53);
4838 rt2800_rfcsr_write(rt2x00dev, 16, 0xe0);
4839 rt2800_rfcsr_write(rt2x00dev, 17, 0x94);
4840 rt2800_rfcsr_write(rt2x00dev, 18, 0x5c);
4841 rt2800_rfcsr_write(rt2x00dev, 19, 0x4a);
4842 rt2800_rfcsr_write(rt2x00dev, 20, 0xb2);
4843 rt2800_rfcsr_write(rt2x00dev, 21, 0xf6);
4844 rt2800_rfcsr_write(rt2x00dev, 22, 0x00);
4845 rt2800_rfcsr_write(rt2x00dev, 23, 0x14);
4846 rt2800_rfcsr_write(rt2x00dev, 24, 0x08);
4847 rt2800_rfcsr_write(rt2x00dev, 25, 0x3d);
4848 rt2800_rfcsr_write(rt2x00dev, 26, 0x85);
4849 rt2800_rfcsr_write(rt2x00dev, 27, 0x00);
4850 rt2800_rfcsr_write(rt2x00dev, 28, 0x41);
4851 rt2800_rfcsr_write(rt2x00dev, 29, 0x8f);
4852 rt2800_rfcsr_write(rt2x00dev, 30, 0x20);
4853 rt2800_rfcsr_write(rt2x00dev, 31, 0x0f);
Stanislaw Gruszka2971e662013-04-17 14:08:14 +02004854
4855 rt2800_register_read(rt2x00dev, GPIO_SWITCH, &reg);
4856 rt2x00_set_field32(&reg, GPIO_SWITCH_5, 0);
4857 rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg);
Stanislaw Gruszkac5b3c352013-04-17 14:08:16 +02004858
4859 rt2800_rx_filter_calibration(rt2x00dev);
Stanislaw Gruszka5de5a1f2013-04-17 14:08:17 +02004860
4861 if (rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E))
4862 rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
Stanislaw Gruszkad9517f22013-04-17 14:08:18 +02004863
4864 rt2800_led_open_drain_enable(rt2x00dev);
Stanislaw Gruszkada8064c2013-04-17 14:08:19 +02004865 rt2800_normal_mode_setup_3xxx(rt2x00dev);
Stanislaw Gruszkad5374ef2012-12-12 06:30:55 +01004866}
4867
4868static void rt2800_init_rfcsr_3572(struct rt2x00_dev *rt2x00dev)
4869{
Stanislaw Gruszka87d91db2013-04-17 14:08:15 +02004870 u8 rfcsr;
4871 u32 reg;
4872
Stanislaw Gruszkace94ede92013-04-17 14:08:11 +02004873 rt2800_rf_init_calibration(rt2x00dev, 30);
4874
Stanislaw Gruszkad5374ef2012-12-12 06:30:55 +01004875 rt2800_rfcsr_write(rt2x00dev, 0, 0x70);
4876 rt2800_rfcsr_write(rt2x00dev, 1, 0x81);
4877 rt2800_rfcsr_write(rt2x00dev, 2, 0xf1);
4878 rt2800_rfcsr_write(rt2x00dev, 3, 0x02);
4879 rt2800_rfcsr_write(rt2x00dev, 4, 0x4c);
4880 rt2800_rfcsr_write(rt2x00dev, 5, 0x05);
4881 rt2800_rfcsr_write(rt2x00dev, 6, 0x4a);
4882 rt2800_rfcsr_write(rt2x00dev, 7, 0xd8);
4883 rt2800_rfcsr_write(rt2x00dev, 9, 0xc3);
4884 rt2800_rfcsr_write(rt2x00dev, 10, 0xf1);
4885 rt2800_rfcsr_write(rt2x00dev, 11, 0xb9);
4886 rt2800_rfcsr_write(rt2x00dev, 12, 0x70);
4887 rt2800_rfcsr_write(rt2x00dev, 13, 0x65);
4888 rt2800_rfcsr_write(rt2x00dev, 14, 0xa0);
4889 rt2800_rfcsr_write(rt2x00dev, 15, 0x53);
4890 rt2800_rfcsr_write(rt2x00dev, 16, 0x4c);
4891 rt2800_rfcsr_write(rt2x00dev, 17, 0x23);
4892 rt2800_rfcsr_write(rt2x00dev, 18, 0xac);
4893 rt2800_rfcsr_write(rt2x00dev, 19, 0x93);
4894 rt2800_rfcsr_write(rt2x00dev, 20, 0xb3);
4895 rt2800_rfcsr_write(rt2x00dev, 21, 0xd0);
4896 rt2800_rfcsr_write(rt2x00dev, 22, 0x00);
4897 rt2800_rfcsr_write(rt2x00dev, 23, 0x3c);
4898 rt2800_rfcsr_write(rt2x00dev, 24, 0x16);
4899 rt2800_rfcsr_write(rt2x00dev, 25, 0x15);
4900 rt2800_rfcsr_write(rt2x00dev, 26, 0x85);
4901 rt2800_rfcsr_write(rt2x00dev, 27, 0x00);
4902 rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
4903 rt2800_rfcsr_write(rt2x00dev, 29, 0x9b);
4904 rt2800_rfcsr_write(rt2x00dev, 30, 0x09);
4905 rt2800_rfcsr_write(rt2x00dev, 31, 0x10);
Stanislaw Gruszka87d91db2013-04-17 14:08:15 +02004906
4907 rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr);
4908 rt2x00_set_field8(&rfcsr, RFCSR6_R2, 1);
4909 rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
4910
4911 rt2800_register_read(rt2x00dev, LDO_CFG0, &reg);
4912 rt2x00_set_field32(&reg, LDO_CFG0_LDO_CORE_VLEVEL, 3);
4913 rt2x00_set_field32(&reg, LDO_CFG0_BGSEL, 1);
4914 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
4915 msleep(1);
4916 rt2800_register_read(rt2x00dev, LDO_CFG0, &reg);
4917 rt2x00_set_field32(&reg, LDO_CFG0_LDO_CORE_VLEVEL, 0);
4918 rt2x00_set_field32(&reg, LDO_CFG0_BGSEL, 1);
4919 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
Stanislaw Gruszkac5b3c352013-04-17 14:08:16 +02004920
4921 rt2800_rx_filter_calibration(rt2x00dev);
Stanislaw Gruszkad9517f22013-04-17 14:08:18 +02004922 rt2800_led_open_drain_enable(rt2x00dev);
Stanislaw Gruszkada8064c2013-04-17 14:08:19 +02004923 rt2800_normal_mode_setup_3xxx(rt2x00dev);
Stanislaw Gruszkad5374ef2012-12-12 06:30:55 +01004924}
4925
4926static void rt2800_init_rfcsr_5390(struct rt2x00_dev *rt2x00dev)
4927{
Stanislaw Gruszkace94ede92013-04-17 14:08:11 +02004928 rt2800_rf_init_calibration(rt2x00dev, 2);
4929
Stanislaw Gruszkad5374ef2012-12-12 06:30:55 +01004930 rt2800_rfcsr_write(rt2x00dev, 1, 0x0f);
4931 rt2800_rfcsr_write(rt2x00dev, 2, 0x80);
4932 rt2800_rfcsr_write(rt2x00dev, 3, 0x88);
4933 rt2800_rfcsr_write(rt2x00dev, 5, 0x10);
4934 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
4935 rt2800_rfcsr_write(rt2x00dev, 6, 0xe0);
4936 else
4937 rt2800_rfcsr_write(rt2x00dev, 6, 0xa0);
4938 rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
4939 rt2800_rfcsr_write(rt2x00dev, 10, 0x53);
4940 rt2800_rfcsr_write(rt2x00dev, 11, 0x4a);
4941 rt2800_rfcsr_write(rt2x00dev, 12, 0xc6);
4942 rt2800_rfcsr_write(rt2x00dev, 13, 0x9f);
4943 rt2800_rfcsr_write(rt2x00dev, 14, 0x00);
4944 rt2800_rfcsr_write(rt2x00dev, 15, 0x00);
4945 rt2800_rfcsr_write(rt2x00dev, 16, 0x00);
4946 rt2800_rfcsr_write(rt2x00dev, 18, 0x03);
4947 rt2800_rfcsr_write(rt2x00dev, 19, 0x00);
4948
4949 rt2800_rfcsr_write(rt2x00dev, 20, 0x00);
4950 rt2800_rfcsr_write(rt2x00dev, 21, 0x00);
4951 rt2800_rfcsr_write(rt2x00dev, 22, 0x20);
4952 rt2800_rfcsr_write(rt2x00dev, 23, 0x00);
4953 rt2800_rfcsr_write(rt2x00dev, 24, 0x00);
4954 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
4955 rt2800_rfcsr_write(rt2x00dev, 25, 0x80);
4956 else
4957 rt2800_rfcsr_write(rt2x00dev, 25, 0xc0);
4958 rt2800_rfcsr_write(rt2x00dev, 26, 0x00);
4959 rt2800_rfcsr_write(rt2x00dev, 27, 0x09);
4960 rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
4961 rt2800_rfcsr_write(rt2x00dev, 29, 0x10);
4962
4963 rt2800_rfcsr_write(rt2x00dev, 30, 0x00);
4964 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
4965 rt2800_rfcsr_write(rt2x00dev, 32, 0x80);
4966 rt2800_rfcsr_write(rt2x00dev, 33, 0x00);
4967 rt2800_rfcsr_write(rt2x00dev, 34, 0x07);
4968 rt2800_rfcsr_write(rt2x00dev, 35, 0x12);
4969 rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
4970 rt2800_rfcsr_write(rt2x00dev, 37, 0x08);
4971 rt2800_rfcsr_write(rt2x00dev, 38, 0x85);
4972 rt2800_rfcsr_write(rt2x00dev, 39, 0x1b);
4973
4974 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
4975 rt2800_rfcsr_write(rt2x00dev, 40, 0x0b);
4976 else
4977 rt2800_rfcsr_write(rt2x00dev, 40, 0x4b);
4978 rt2800_rfcsr_write(rt2x00dev, 41, 0xbb);
4979 rt2800_rfcsr_write(rt2x00dev, 42, 0xd2);
4980 rt2800_rfcsr_write(rt2x00dev, 43, 0x9a);
4981 rt2800_rfcsr_write(rt2x00dev, 44, 0x0e);
4982 rt2800_rfcsr_write(rt2x00dev, 45, 0xa2);
4983 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
4984 rt2800_rfcsr_write(rt2x00dev, 46, 0x73);
4985 else
4986 rt2800_rfcsr_write(rt2x00dev, 46, 0x7b);
4987 rt2800_rfcsr_write(rt2x00dev, 47, 0x00);
4988 rt2800_rfcsr_write(rt2x00dev, 48, 0x10);
4989 rt2800_rfcsr_write(rt2x00dev, 49, 0x94);
4990
4991 rt2800_rfcsr_write(rt2x00dev, 52, 0x38);
4992 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
4993 rt2800_rfcsr_write(rt2x00dev, 53, 0x00);
4994 else
4995 rt2800_rfcsr_write(rt2x00dev, 53, 0x84);
4996 rt2800_rfcsr_write(rt2x00dev, 54, 0x78);
4997 rt2800_rfcsr_write(rt2x00dev, 55, 0x44);
4998 rt2800_rfcsr_write(rt2x00dev, 56, 0x22);
4999 rt2800_rfcsr_write(rt2x00dev, 57, 0x80);
5000 rt2800_rfcsr_write(rt2x00dev, 58, 0x7f);
5001 rt2800_rfcsr_write(rt2x00dev, 59, 0x63);
5002
5003 rt2800_rfcsr_write(rt2x00dev, 60, 0x45);
5004 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
5005 rt2800_rfcsr_write(rt2x00dev, 61, 0xd1);
5006 else
5007 rt2800_rfcsr_write(rt2x00dev, 61, 0xdd);
5008 rt2800_rfcsr_write(rt2x00dev, 62, 0x00);
5009 rt2800_rfcsr_write(rt2x00dev, 63, 0x00);
Stanislaw Gruszkaf7df8fe2013-04-17 14:08:10 +02005010
5011 rt2800_normal_mode_setup_5xxx(rt2x00dev);
Stanislaw Gruszkad9517f22013-04-17 14:08:18 +02005012
5013 rt2800_led_open_drain_enable(rt2x00dev);
Stanislaw Gruszkad5374ef2012-12-12 06:30:55 +01005014}
5015
5016static void rt2800_init_rfcsr_5392(struct rt2x00_dev *rt2x00dev)
5017{
Stanislaw Gruszkace94ede92013-04-17 14:08:11 +02005018 rt2800_rf_init_calibration(rt2x00dev, 2);
5019
Stanislaw Gruszkad5374ef2012-12-12 06:30:55 +01005020 rt2800_rfcsr_write(rt2x00dev, 1, 0x17);
5021 rt2800_rfcsr_write(rt2x00dev, 2, 0x80);
5022 rt2800_rfcsr_write(rt2x00dev, 3, 0x88);
5023 rt2800_rfcsr_write(rt2x00dev, 5, 0x10);
5024 rt2800_rfcsr_write(rt2x00dev, 6, 0xe0);
5025 rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
5026 rt2800_rfcsr_write(rt2x00dev, 10, 0x53);
5027 rt2800_rfcsr_write(rt2x00dev, 11, 0x4a);
5028 rt2800_rfcsr_write(rt2x00dev, 12, 0x46);
5029 rt2800_rfcsr_write(rt2x00dev, 13, 0x9f);
5030 rt2800_rfcsr_write(rt2x00dev, 14, 0x00);
5031 rt2800_rfcsr_write(rt2x00dev, 15, 0x00);
5032 rt2800_rfcsr_write(rt2x00dev, 16, 0x00);
5033 rt2800_rfcsr_write(rt2x00dev, 18, 0x03);
5034 rt2800_rfcsr_write(rt2x00dev, 19, 0x4d);
5035 rt2800_rfcsr_write(rt2x00dev, 20, 0x00);
5036 rt2800_rfcsr_write(rt2x00dev, 21, 0x8d);
5037 rt2800_rfcsr_write(rt2x00dev, 22, 0x20);
5038 rt2800_rfcsr_write(rt2x00dev, 23, 0x0b);
5039 rt2800_rfcsr_write(rt2x00dev, 24, 0x44);
5040 rt2800_rfcsr_write(rt2x00dev, 25, 0x80);
5041 rt2800_rfcsr_write(rt2x00dev, 26, 0x82);
5042 rt2800_rfcsr_write(rt2x00dev, 27, 0x09);
5043 rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
5044 rt2800_rfcsr_write(rt2x00dev, 29, 0x10);
5045 rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
5046 rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
5047 rt2800_rfcsr_write(rt2x00dev, 32, 0x20);
5048 rt2800_rfcsr_write(rt2x00dev, 33, 0xC0);
5049 rt2800_rfcsr_write(rt2x00dev, 34, 0x07);
5050 rt2800_rfcsr_write(rt2x00dev, 35, 0x12);
5051 rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
5052 rt2800_rfcsr_write(rt2x00dev, 37, 0x08);
5053 rt2800_rfcsr_write(rt2x00dev, 38, 0x89);
5054 rt2800_rfcsr_write(rt2x00dev, 39, 0x1b);
5055 rt2800_rfcsr_write(rt2x00dev, 40, 0x0f);
5056 rt2800_rfcsr_write(rt2x00dev, 41, 0xbb);
5057 rt2800_rfcsr_write(rt2x00dev, 42, 0xd5);
5058 rt2800_rfcsr_write(rt2x00dev, 43, 0x9b);
5059 rt2800_rfcsr_write(rt2x00dev, 44, 0x0e);
5060 rt2800_rfcsr_write(rt2x00dev, 45, 0xa2);
5061 rt2800_rfcsr_write(rt2x00dev, 46, 0x73);
5062 rt2800_rfcsr_write(rt2x00dev, 47, 0x0c);
5063 rt2800_rfcsr_write(rt2x00dev, 48, 0x10);
5064 rt2800_rfcsr_write(rt2x00dev, 49, 0x94);
5065 rt2800_rfcsr_write(rt2x00dev, 50, 0x94);
5066 rt2800_rfcsr_write(rt2x00dev, 51, 0x3a);
5067 rt2800_rfcsr_write(rt2x00dev, 52, 0x48);
5068 rt2800_rfcsr_write(rt2x00dev, 53, 0x44);
5069 rt2800_rfcsr_write(rt2x00dev, 54, 0x38);
5070 rt2800_rfcsr_write(rt2x00dev, 55, 0x43);
5071 rt2800_rfcsr_write(rt2x00dev, 56, 0xa1);
5072 rt2800_rfcsr_write(rt2x00dev, 57, 0x00);
5073 rt2800_rfcsr_write(rt2x00dev, 58, 0x39);
5074 rt2800_rfcsr_write(rt2x00dev, 59, 0x07);
5075 rt2800_rfcsr_write(rt2x00dev, 60, 0x45);
5076 rt2800_rfcsr_write(rt2x00dev, 61, 0x91);
5077 rt2800_rfcsr_write(rt2x00dev, 62, 0x39);
5078 rt2800_rfcsr_write(rt2x00dev, 63, 0x07);
Stanislaw Gruszkaf7df8fe2013-04-17 14:08:10 +02005079
5080 rt2800_normal_mode_setup_5xxx(rt2x00dev);
Stanislaw Gruszkad9517f22013-04-17 14:08:18 +02005081
5082 rt2800_led_open_drain_enable(rt2x00dev);
Stanislaw Gruszkad5374ef2012-12-12 06:30:55 +01005083}
5084
Stanislaw Gruszka0c9e5fb2013-03-16 19:19:36 +01005085static void rt2800_init_rfcsr_5592(struct rt2x00_dev *rt2x00dev)
5086{
Stanislaw Gruszkace94ede92013-04-17 14:08:11 +02005087 rt2800_rf_init_calibration(rt2x00dev, 30);
5088
Stanislaw Gruszka0c9e5fb2013-03-16 19:19:36 +01005089 rt2800_rfcsr_write(rt2x00dev, 1, 0x3F);
5090 rt2800_rfcsr_write(rt2x00dev, 3, 0x08);
5091 rt2800_rfcsr_write(rt2x00dev, 3, 0x08);
5092 rt2800_rfcsr_write(rt2x00dev, 5, 0x10);
5093 rt2800_rfcsr_write(rt2x00dev, 6, 0xE4);
5094 rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
5095 rt2800_rfcsr_write(rt2x00dev, 14, 0x00);
5096 rt2800_rfcsr_write(rt2x00dev, 15, 0x00);
5097 rt2800_rfcsr_write(rt2x00dev, 16, 0x00);
5098 rt2800_rfcsr_write(rt2x00dev, 18, 0x03);
5099 rt2800_rfcsr_write(rt2x00dev, 19, 0x4D);
5100 rt2800_rfcsr_write(rt2x00dev, 20, 0x10);
5101 rt2800_rfcsr_write(rt2x00dev, 21, 0x8D);
5102 rt2800_rfcsr_write(rt2x00dev, 26, 0x82);
5103 rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
5104 rt2800_rfcsr_write(rt2x00dev, 29, 0x10);
5105 rt2800_rfcsr_write(rt2x00dev, 33, 0xC0);
5106 rt2800_rfcsr_write(rt2x00dev, 34, 0x07);
5107 rt2800_rfcsr_write(rt2x00dev, 35, 0x12);
5108 rt2800_rfcsr_write(rt2x00dev, 47, 0x0C);
5109 rt2800_rfcsr_write(rt2x00dev, 53, 0x22);
5110 rt2800_rfcsr_write(rt2x00dev, 63, 0x07);
5111
5112 rt2800_rfcsr_write(rt2x00dev, 2, 0x80);
5113 msleep(1);
5114
5115 rt2800_adjust_freq_offset(rt2x00dev);
Stanislaw Gruszkac630ccf2013-03-16 19:19:46 +01005116
Stanislaw Gruszkac630ccf2013-03-16 19:19:46 +01005117 /* Enable DC filter */
5118 if (rt2x00_rt_rev_gte(rt2x00dev, RT5592, REV_RT5592C))
5119 rt2800_bbp_write(rt2x00dev, 103, 0xc0);
5120
Stanislaw Gruszkaf7df8fe2013-04-17 14:08:10 +02005121 rt2800_normal_mode_setup_5xxx(rt2x00dev);
Stanislaw Gruszka5de5a1f2013-04-17 14:08:17 +02005122
5123 if (rt2x00_rt_rev_lt(rt2x00dev, RT5592, REV_RT5592C))
5124 rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
Stanislaw Gruszkad9517f22013-04-17 14:08:18 +02005125
5126 rt2800_led_open_drain_enable(rt2x00dev);
Stanislaw Gruszka0c9e5fb2013-03-16 19:19:36 +01005127}
5128
Stanislaw Gruszka074f2522013-04-17 14:08:20 +02005129static void rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev)
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01005130{
Stanislaw Gruszkad5374ef2012-12-12 06:30:55 +01005131 if (rt2800_is_305x_soc(rt2x00dev)) {
5132 rt2800_init_rfcsr_305x_soc(rt2x00dev);
Stanislaw Gruszka074f2522013-04-17 14:08:20 +02005133 return;
Stanislaw Gruszkad5374ef2012-12-12 06:30:55 +01005134 }
RA-Shiang Tu60687ba2011-02-20 13:57:46 +01005135
Stanislaw Gruszkad5374ef2012-12-12 06:30:55 +01005136 switch (rt2x00dev->chip.rt) {
5137 case RT3070:
5138 case RT3071:
5139 case RT3090:
5140 rt2800_init_rfcsr_30xx(rt2x00dev);
5141 break;
5142 case RT3290:
5143 rt2800_init_rfcsr_3290(rt2x00dev);
5144 break;
5145 case RT3352:
5146 rt2800_init_rfcsr_3352(rt2x00dev);
5147 break;
5148 case RT3390:
5149 rt2800_init_rfcsr_3390(rt2x00dev);
5150 break;
5151 case RT3572:
5152 rt2800_init_rfcsr_3572(rt2x00dev);
5153 break;
5154 case RT5390:
5155 rt2800_init_rfcsr_5390(rt2x00dev);
5156 break;
5157 case RT5392:
5158 rt2800_init_rfcsr_5392(rt2x00dev);
5159 break;
Stanislaw Gruszka0c9e5fb2013-03-16 19:19:36 +01005160 case RT5592:
5161 rt2800_init_rfcsr_5592(rt2x00dev);
Stanislaw Gruszka074f2522013-04-17 14:08:20 +02005162 break;
Gertjan van Wingerde8cdd15e2010-04-11 14:31:12 +02005163 }
Bartlomiej Zolnierkiewiczfcf51542009-11-04 18:36:57 +01005164}
Ivo van Doornb9a07ae2010-08-23 19:55:22 +02005165
5166int rt2800_enable_radio(struct rt2x00_dev *rt2x00dev)
5167{
5168 u32 reg;
5169 u16 word;
5170
5171 /*
5172 * Initialize all registers.
5173 */
5174 if (unlikely(rt2800_wait_wpdma_ready(rt2x00dev) ||
Stanislaw Gruszkac630ccf2013-03-16 19:19:46 +01005175 rt2800_init_registers(rt2x00dev)))
Ivo van Doornb9a07ae2010-08-23 19:55:22 +02005176 return -EIO;
5177
5178 /*
5179 * Send signal to firmware during boot time.
5180 */
Stanislaw Gruszkac630ccf2013-03-16 19:19:46 +01005181 rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
5182 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
5183 if (rt2x00_is_usb(rt2x00dev)) {
5184 rt2800_register_write(rt2x00dev, H2M_INT_SRC, 0);
5185 rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0, 0, 0);
5186 }
5187 msleep(1);
5188
Stanislaw Gruszka074f2522013-04-17 14:08:20 +02005189 if (unlikely(rt2800_init_bbp(rt2x00dev)))
Stanislaw Gruszkac630ccf2013-03-16 19:19:46 +01005190 return -EIO;
Ivo van Doornb9a07ae2010-08-23 19:55:22 +02005191
Stanislaw Gruszka074f2522013-04-17 14:08:20 +02005192 rt2800_init_rfcsr(rt2x00dev);
5193
Ivo van Doornb9a07ae2010-08-23 19:55:22 +02005194 if (rt2x00_is_usb(rt2x00dev) &&
5195 (rt2x00_rt(rt2x00dev, RT3070) ||
5196 rt2x00_rt(rt2x00dev, RT3071) ||
5197 rt2x00_rt(rt2x00dev, RT3572))) {
5198 udelay(200);
5199 rt2800_mcu_request(rt2x00dev, MCU_CURRENT, 0, 0, 0);
5200 udelay(10);
5201 }
5202
5203 /*
5204 * Enable RX.
5205 */
5206 rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
5207 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
5208 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 0);
5209 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
5210
5211 udelay(50);
5212
5213 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
5214 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 1);
5215 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 1);
5216 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 2);
5217 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
5218 rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
5219
5220 rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
5221 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
5222 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 1);
5223 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
5224
5225 /*
5226 * Initialize LED control
5227 */
RA-Jay Hung38c8a562010-12-13 12:31:27 +01005228 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED_AG_CONF, &word);
5229 rt2800_mcu_request(rt2x00dev, MCU_LED_AG_CONF, 0xff,
Ivo van Doornb9a07ae2010-08-23 19:55:22 +02005230 word & 0xff, (word >> 8) & 0xff);
5231
RA-Jay Hung38c8a562010-12-13 12:31:27 +01005232 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED_ACT_CONF, &word);
5233 rt2800_mcu_request(rt2x00dev, MCU_LED_ACT_CONF, 0xff,
Ivo van Doornb9a07ae2010-08-23 19:55:22 +02005234 word & 0xff, (word >> 8) & 0xff);
5235
RA-Jay Hung38c8a562010-12-13 12:31:27 +01005236 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED_POLARITY, &word);
5237 rt2800_mcu_request(rt2x00dev, MCU_LED_LED_POLARITY, 0xff,
Ivo van Doornb9a07ae2010-08-23 19:55:22 +02005238 word & 0xff, (word >> 8) & 0xff);
5239
5240 return 0;
5241}
5242EXPORT_SYMBOL_GPL(rt2800_enable_radio);
5243
5244void rt2800_disable_radio(struct rt2x00_dev *rt2x00dev)
5245{
5246 u32 reg;
5247
Jakub Kicinskif7b395e2012-04-03 03:40:47 +02005248 rt2800_disable_wpdma(rt2x00dev);
Ivo van Doornb9a07ae2010-08-23 19:55:22 +02005249
5250 /* Wait for DMA, ignore error */
5251 rt2800_wait_wpdma_ready(rt2x00dev);
5252
5253 rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
5254 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 0);
5255 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 0);
5256 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
Ivo van Doornb9a07ae2010-08-23 19:55:22 +02005257}
5258EXPORT_SYMBOL_GPL(rt2800_disable_radio);
Bartlomiej Zolnierkiewicz2ce33992009-11-04 18:37:05 +01005259
Bartlomiej Zolnierkiewicz30e84032009-11-08 14:39:48 +01005260int rt2800_efuse_detect(struct rt2x00_dev *rt2x00dev)
5261{
5262 u32 reg;
Woody Hunga89534e2012-06-13 15:01:16 +08005263 u16 efuse_ctrl_reg;
Bartlomiej Zolnierkiewicz30e84032009-11-08 14:39:48 +01005264
Woody Hunga89534e2012-06-13 15:01:16 +08005265 if (rt2x00_rt(rt2x00dev, RT3290))
5266 efuse_ctrl_reg = EFUSE_CTRL_3290;
5267 else
5268 efuse_ctrl_reg = EFUSE_CTRL;
Bartlomiej Zolnierkiewicz30e84032009-11-08 14:39:48 +01005269
Woody Hunga89534e2012-06-13 15:01:16 +08005270 rt2800_register_read(rt2x00dev, efuse_ctrl_reg, &reg);
Bartlomiej Zolnierkiewicz30e84032009-11-08 14:39:48 +01005271 return rt2x00_get_field32(reg, EFUSE_CTRL_PRESENT);
5272}
5273EXPORT_SYMBOL_GPL(rt2800_efuse_detect);
5274
5275static void rt2800_efuse_read(struct rt2x00_dev *rt2x00dev, unsigned int i)
5276{
5277 u32 reg;
Woody Hunga89534e2012-06-13 15:01:16 +08005278 u16 efuse_ctrl_reg;
5279 u16 efuse_data0_reg;
5280 u16 efuse_data1_reg;
5281 u16 efuse_data2_reg;
5282 u16 efuse_data3_reg;
Bartlomiej Zolnierkiewicz30e84032009-11-08 14:39:48 +01005283
Woody Hunga89534e2012-06-13 15:01:16 +08005284 if (rt2x00_rt(rt2x00dev, RT3290)) {
5285 efuse_ctrl_reg = EFUSE_CTRL_3290;
5286 efuse_data0_reg = EFUSE_DATA0_3290;
5287 efuse_data1_reg = EFUSE_DATA1_3290;
5288 efuse_data2_reg = EFUSE_DATA2_3290;
5289 efuse_data3_reg = EFUSE_DATA3_3290;
5290 } else {
5291 efuse_ctrl_reg = EFUSE_CTRL;
5292 efuse_data0_reg = EFUSE_DATA0;
5293 efuse_data1_reg = EFUSE_DATA1;
5294 efuse_data2_reg = EFUSE_DATA2;
5295 efuse_data3_reg = EFUSE_DATA3;
5296 }
Gertjan van Wingerde31a4cf12009-11-14 20:20:36 +01005297 mutex_lock(&rt2x00dev->csr_mutex);
5298
Woody Hunga89534e2012-06-13 15:01:16 +08005299 rt2800_register_read_lock(rt2x00dev, efuse_ctrl_reg, &reg);
Bartlomiej Zolnierkiewicz30e84032009-11-08 14:39:48 +01005300 rt2x00_set_field32(&reg, EFUSE_CTRL_ADDRESS_IN, i);
5301 rt2x00_set_field32(&reg, EFUSE_CTRL_MODE, 0);
5302 rt2x00_set_field32(&reg, EFUSE_CTRL_KICK, 1);
Woody Hunga89534e2012-06-13 15:01:16 +08005303 rt2800_register_write_lock(rt2x00dev, efuse_ctrl_reg, reg);
Bartlomiej Zolnierkiewicz30e84032009-11-08 14:39:48 +01005304
5305 /* Wait until the EEPROM has been loaded */
Woody Hunga89534e2012-06-13 15:01:16 +08005306 rt2800_regbusy_read(rt2x00dev, efuse_ctrl_reg, EFUSE_CTRL_KICK, &reg);
Bartlomiej Zolnierkiewicz30e84032009-11-08 14:39:48 +01005307 /* Apparently the data is read from end to start */
Woody Hunga89534e2012-06-13 15:01:16 +08005308 rt2800_register_read_lock(rt2x00dev, efuse_data3_reg, &reg);
Larry Fingerdaabead2011-09-14 16:50:23 -05005309 /* The returned value is in CPU order, but eeprom is le */
Gertjan van Wingerde68fa64e2011-11-16 23:16:15 +01005310 *(u32 *)&rt2x00dev->eeprom[i] = cpu_to_le32(reg);
Woody Hunga89534e2012-06-13 15:01:16 +08005311 rt2800_register_read_lock(rt2x00dev, efuse_data2_reg, &reg);
Larry Fingerdaabead2011-09-14 16:50:23 -05005312 *(u32 *)&rt2x00dev->eeprom[i + 2] = cpu_to_le32(reg);
Woody Hunga89534e2012-06-13 15:01:16 +08005313 rt2800_register_read_lock(rt2x00dev, efuse_data1_reg, &reg);
Larry Fingerdaabead2011-09-14 16:50:23 -05005314 *(u32 *)&rt2x00dev->eeprom[i + 4] = cpu_to_le32(reg);
Woody Hunga89534e2012-06-13 15:01:16 +08005315 rt2800_register_read_lock(rt2x00dev, efuse_data0_reg, &reg);
Larry Fingerdaabead2011-09-14 16:50:23 -05005316 *(u32 *)&rt2x00dev->eeprom[i + 6] = cpu_to_le32(reg);
Gertjan van Wingerde31a4cf12009-11-14 20:20:36 +01005317
5318 mutex_unlock(&rt2x00dev->csr_mutex);
Bartlomiej Zolnierkiewicz30e84032009-11-08 14:39:48 +01005319}
5320
Gabor Juhosa02308e2012-12-29 14:51:51 +01005321int rt2800_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev)
Bartlomiej Zolnierkiewicz30e84032009-11-08 14:39:48 +01005322{
5323 unsigned int i;
5324
5325 for (i = 0; i < EEPROM_SIZE / sizeof(u16); i += 8)
5326 rt2800_efuse_read(rt2x00dev, i);
Gabor Juhosa02308e2012-12-29 14:51:51 +01005327
5328 return 0;
Bartlomiej Zolnierkiewicz30e84032009-11-08 14:39:48 +01005329}
5330EXPORT_SYMBOL_GPL(rt2800_read_eeprom_efuse);
5331
Gertjan van Wingerdead417a52012-09-03 03:25:51 +02005332static int rt2800_validate_eeprom(struct rt2x00_dev *rt2x00dev)
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005333{
Gertjan van Wingerde77c06c22012-02-06 23:45:13 +01005334 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005335 u16 word;
5336 u8 *mac;
5337 u8 default_lna_gain;
Gabor Juhosa02308e2012-12-29 14:51:51 +01005338 int retval;
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005339
5340 /*
Gertjan van Wingerdead417a52012-09-03 03:25:51 +02005341 * Read the EEPROM.
5342 */
Gabor Juhosa02308e2012-12-29 14:51:51 +01005343 retval = rt2800_read_eeprom(rt2x00dev);
5344 if (retval)
5345 return retval;
Gertjan van Wingerdead417a52012-09-03 03:25:51 +02005346
5347 /*
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005348 * Start validation of the data that has been read.
5349 */
5350 mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
5351 if (!is_valid_ether_addr(mac)) {
Joe Perchesf4f7f4142012-07-12 19:33:08 +00005352 eth_random_addr(mac);
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005353 EEPROM(rt2x00dev, "MAC: %pM\n", mac);
5354 }
5355
RA-Jay Hung38c8a562010-12-13 12:31:27 +01005356 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &word);
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005357 if (word == 0xffff) {
RA-Jay Hung38c8a562010-12-13 12:31:27 +01005358 rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RXPATH, 2);
5359 rt2x00_set_field16(&word, EEPROM_NIC_CONF0_TXPATH, 1);
5360 rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RF_TYPE, RF2820);
5361 rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC_CONF0, word);
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005362 EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
Gertjan van Wingerde49e721e2010-02-13 20:55:49 +01005363 } else if (rt2x00_rt(rt2x00dev, RT2860) ||
Gertjan van Wingerdee148b4c2010-04-11 14:31:09 +02005364 rt2x00_rt(rt2x00dev, RT2872)) {
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005365 /*
5366 * There is a max of 2 RX streams for RT28x0 series
5367 */
RA-Jay Hung38c8a562010-12-13 12:31:27 +01005368 if (rt2x00_get_field16(word, EEPROM_NIC_CONF0_RXPATH) > 2)
5369 rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RXPATH, 2);
5370 rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC_CONF0, word);
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005371 }
5372
RA-Jay Hung38c8a562010-12-13 12:31:27 +01005373 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &word);
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005374 if (word == 0xffff) {
RA-Jay Hung38c8a562010-12-13 12:31:27 +01005375 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_HW_RADIO, 0);
5376 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_TX_ALC, 0);
5377 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_LNA_2G, 0);
5378 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_LNA_5G, 0);
5379 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_CARDBUS_ACCEL, 0);
5380 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_SB_2G, 0);
5381 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_SB_5G, 0);
5382 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_WPS_PBC, 0);
5383 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_2G, 0);
5384 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_5G, 0);
5385 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BROADBAND_EXT_LNA, 0);
5386 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_ANT_DIVERSITY, 0);
5387 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_INTERNAL_TX_ALC, 0);
5388 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BT_COEXIST, 0);
5389 rt2x00_set_field16(&word, EEPROM_NIC_CONF1_DAC_TEST, 0);
5390 rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC_CONF1, word);
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005391 EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
5392 }
5393
5394 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &word);
5395 if ((word & 0x00ff) == 0x00ff) {
5396 rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0);
Gertjan van Wingerdeec2d1792010-06-29 21:44:50 +02005397 rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
5398 EEPROM(rt2x00dev, "Freq: 0x%04x\n", word);
5399 }
5400 if ((word & 0xff00) == 0xff00) {
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005401 rt2x00_set_field16(&word, EEPROM_FREQ_LED_MODE,
5402 LED_MODE_TXRX_ACTIVITY);
5403 rt2x00_set_field16(&word, EEPROM_FREQ_LED_POLARITY, 0);
5404 rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
RA-Jay Hung38c8a562010-12-13 12:31:27 +01005405 rt2x00_eeprom_write(rt2x00dev, EEPROM_LED_AG_CONF, 0x5555);
5406 rt2x00_eeprom_write(rt2x00dev, EEPROM_LED_ACT_CONF, 0x2221);
5407 rt2x00_eeprom_write(rt2x00dev, EEPROM_LED_POLARITY, 0xa9f8);
Gertjan van Wingerdeec2d1792010-06-29 21:44:50 +02005408 EEPROM(rt2x00dev, "Led Mode: 0x%04x\n", word);
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005409 }
5410
5411 /*
5412 * During the LNA validation we are going to use
5413 * lna0 as correct value. Note that EEPROM_LNA
5414 * is never validated.
5415 */
5416 rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &word);
5417 default_lna_gain = rt2x00_get_field16(word, EEPROM_LNA_A0);
5418
5419 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &word);
5420 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET0)) > 10)
5421 rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET0, 0);
5422 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET1)) > 10)
5423 rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET1, 0);
5424 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG, word);
5425
Gertjan van Wingerde77c06c22012-02-06 23:45:13 +01005426 rt2x00_eeprom_read(rt2x00dev, EEPROM_TXMIXER_GAIN_BG, &word);
5427 if ((word & 0x00ff) != 0x00ff) {
5428 drv_data->txmixer_gain_24g =
5429 rt2x00_get_field16(word, EEPROM_TXMIXER_GAIN_BG_VAL);
5430 } else {
5431 drv_data->txmixer_gain_24g = 0;
5432 }
5433
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005434 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &word);
5435 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG2_OFFSET2)) > 10)
5436 rt2x00_set_field16(&word, EEPROM_RSSI_BG2_OFFSET2, 0);
5437 if (rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0x00 ||
5438 rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0xff)
5439 rt2x00_set_field16(&word, EEPROM_RSSI_BG2_LNA_A1,
5440 default_lna_gain);
5441 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG2, word);
5442
Gertjan van Wingerde77c06c22012-02-06 23:45:13 +01005443 rt2x00_eeprom_read(rt2x00dev, EEPROM_TXMIXER_GAIN_A, &word);
5444 if ((word & 0x00ff) != 0x00ff) {
5445 drv_data->txmixer_gain_5g =
5446 rt2x00_get_field16(word, EEPROM_TXMIXER_GAIN_A_VAL);
5447 } else {
5448 drv_data->txmixer_gain_5g = 0;
5449 }
5450
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005451 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &word);
5452 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET0)) > 10)
5453 rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET0, 0);
5454 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET1)) > 10)
5455 rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET1, 0);
5456 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A, word);
5457
5458 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &word);
5459 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A2_OFFSET2)) > 10)
5460 rt2x00_set_field16(&word, EEPROM_RSSI_A2_OFFSET2, 0);
5461 if (rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0x00 ||
5462 rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0xff)
5463 rt2x00_set_field16(&word, EEPROM_RSSI_A2_LNA_A2,
5464 default_lna_gain);
5465 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A2, word);
5466
5467 return 0;
5468}
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005469
Gertjan van Wingerdead417a52012-09-03 03:25:51 +02005470static int rt2800_init_eeprom(struct rt2x00_dev *rt2x00dev)
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005471{
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005472 u16 value;
5473 u16 eeprom;
Gabor Juhos86868b22013-03-30 14:53:09 +01005474 u16 rf;
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005475
Gabor Juhos86868b22013-03-30 14:53:09 +01005476 /*
5477 * Read EEPROM word for configuration.
5478 */
5479 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom);
5480
5481 /*
5482 * Identify RF chipset by EEPROM value
5483 * RT28xx/RT30xx: defined in "EEPROM_NIC_CONF0_RF_TYPE" field
5484 * RT53xx: defined in "EEPROM_CHIP_ID" field
5485 */
5486 if (rt2x00_rt(rt2x00dev, RT3290) ||
5487 rt2x00_rt(rt2x00dev, RT5390) ||
5488 rt2x00_rt(rt2x00dev, RT5392))
5489 rt2x00_eeprom_read(rt2x00dev, EEPROM_CHIP_ID, &rf);
5490 else
5491 rf = rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RF_TYPE);
5492
5493 switch (rf) {
Larry Fingerd331eb52011-09-14 16:50:22 -05005494 case RF2820:
5495 case RF2850:
5496 case RF2720:
5497 case RF2750:
5498 case RF3020:
5499 case RF2020:
5500 case RF3021:
5501 case RF3022:
5502 case RF3052:
Woody Hunga89534e2012-06-13 15:01:16 +08005503 case RF3290:
Larry Fingerd331eb52011-09-14 16:50:22 -05005504 case RF3320:
Daniel Golle03839952012-09-09 14:24:39 +03005505 case RF3322:
villacis@palosanto.comccf91bd2012-05-16 21:07:12 +02005506 case RF5360:
Larry Fingerd331eb52011-09-14 16:50:22 -05005507 case RF5370:
John Li2ed71882012-02-17 17:33:06 +08005508 case RF5372:
Larry Fingerd331eb52011-09-14 16:50:22 -05005509 case RF5390:
Zero.Lincff3d1f2012-05-29 16:11:09 +08005510 case RF5392:
Stanislaw Gruszkab8863f82013-03-16 19:19:30 +01005511 case RF5592:
Larry Fingerd331eb52011-09-14 16:50:22 -05005512 break;
5513 default:
Gabor Juhos86868b22013-03-30 14:53:09 +01005514 ERROR(rt2x00dev, "Invalid RF chipset 0x%04x detected.\n", rf);
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005515 return -ENODEV;
5516 }
5517
Gabor Juhos86868b22013-03-30 14:53:09 +01005518 rt2x00_set_rf(rt2x00dev, rf);
5519
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005520 /*
5521 * Identify default antenna configuration.
5522 */
RA-Jay Hungd96aa642011-02-20 13:54:52 +01005523 rt2x00dev->default_ant.tx_chain_num =
RA-Jay Hung38c8a562010-12-13 12:31:27 +01005524 rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH);
RA-Jay Hungd96aa642011-02-20 13:54:52 +01005525 rt2x00dev->default_ant.rx_chain_num =
RA-Jay Hung38c8a562010-12-13 12:31:27 +01005526 rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH);
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005527
RA-Jay Hungd96aa642011-02-20 13:54:52 +01005528 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
5529
5530 if (rt2x00_rt(rt2x00dev, RT3070) ||
5531 rt2x00_rt(rt2x00dev, RT3090) ||
Daniel Golle03839952012-09-09 14:24:39 +03005532 rt2x00_rt(rt2x00dev, RT3352) ||
RA-Jay Hungd96aa642011-02-20 13:54:52 +01005533 rt2x00_rt(rt2x00dev, RT3390)) {
5534 value = rt2x00_get_field16(eeprom,
5535 EEPROM_NIC_CONF1_ANT_DIVERSITY);
5536 switch (value) {
5537 case 0:
5538 case 1:
5539 case 2:
5540 rt2x00dev->default_ant.tx = ANTENNA_A;
5541 rt2x00dev->default_ant.rx = ANTENNA_A;
5542 break;
5543 case 3:
5544 rt2x00dev->default_ant.tx = ANTENNA_A;
5545 rt2x00dev->default_ant.rx = ANTENNA_B;
5546 break;
5547 }
5548 } else {
5549 rt2x00dev->default_ant.tx = ANTENNA_A;
5550 rt2x00dev->default_ant.rx = ANTENNA_A;
5551 }
5552
Anisse Astier0586a112012-04-23 12:33:11 +02005553 if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390R)) {
5554 rt2x00dev->default_ant.tx = ANTENNA_HW_DIVERSITY; /* Unused */
5555 rt2x00dev->default_ant.rx = ANTENNA_HW_DIVERSITY; /* Unused */
5556 }
5557
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005558 /*
Gertjan van Wingerde9328fda2011-04-30 17:15:13 +02005559 * Determine external LNA informations.
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005560 */
RA-Jay Hung38c8a562010-12-13 12:31:27 +01005561 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_EXTERNAL_LNA_5G))
Ivo van Doorn7dab73b2011-04-18 15:27:06 +02005562 __set_bit(CAPABILITY_EXTERNAL_LNA_A, &rt2x00dev->cap_flags);
RA-Jay Hung38c8a562010-12-13 12:31:27 +01005563 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_EXTERNAL_LNA_2G))
Ivo van Doorn7dab73b2011-04-18 15:27:06 +02005564 __set_bit(CAPABILITY_EXTERNAL_LNA_BG, &rt2x00dev->cap_flags);
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005565
5566 /*
5567 * Detect if this device has an hardware controlled radio.
5568 */
RA-Jay Hung38c8a562010-12-13 12:31:27 +01005569 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_HW_RADIO))
Ivo van Doorn7dab73b2011-04-18 15:27:06 +02005570 __set_bit(CAPABILITY_HW_BUTTON, &rt2x00dev->cap_flags);
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005571
5572 /*
Gertjan van Wingerdefdbc7b02011-04-30 17:15:37 +02005573 * Detect if this device has Bluetooth co-existence.
5574 */
5575 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_BT_COEXIST))
5576 __set_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags);
5577
5578 /*
Gertjan van Wingerde9328fda2011-04-30 17:15:13 +02005579 * Read frequency offset and RF programming sequence.
5580 */
5581 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
5582 rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET);
5583
5584 /*
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005585 * Store led settings, for correct led behaviour.
5586 */
5587#ifdef CONFIG_RT2X00_LIB_LEDS
5588 rt2800_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
5589 rt2800_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
5590 rt2800_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY);
5591
Gertjan van Wingerde9328fda2011-04-30 17:15:13 +02005592 rt2x00dev->led_mcu_reg = eeprom;
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005593#endif /* CONFIG_RT2X00_LIB_LEDS */
5594
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01005595 /*
5596 * Check if support EIRP tx power limit feature.
5597 */
5598 rt2x00_eeprom_read(rt2x00dev, EEPROM_EIRP_MAX_TX_POWER, &eeprom);
5599
5600 if (rt2x00_get_field16(eeprom, EEPROM_EIRP_MAX_TX_POWER_2GHZ) <
5601 EIRP_MAX_TX_POWER_LIMIT)
Ivo van Doorn7dab73b2011-04-18 15:27:06 +02005602 __set_bit(CAPABILITY_POWER_LIMIT, &rt2x00dev->cap_flags);
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01005603
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005604 return 0;
5605}
Bartlomiej Zolnierkiewicz38bd7b82009-11-08 14:39:01 +01005606
Bartlomiej Zolnierkiewicz2ce33992009-11-04 18:37:05 +01005607/*
Ivo van Doorn55f93212010-05-06 14:45:46 +02005608 * RF value list for rt28xx
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01005609 * Supports: 2.4 GHz (all) & 5.2 GHz (RF2850 & RF2750)
5610 */
5611static const struct rf_channel rf_vals[] = {
5612 { 1, 0x18402ecc, 0x184c0786, 0x1816b455, 0x1800510b },
5613 { 2, 0x18402ecc, 0x184c0786, 0x18168a55, 0x1800519f },
5614 { 3, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800518b },
5615 { 4, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800519f },
5616 { 5, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800518b },
5617 { 6, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800519f },
5618 { 7, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800518b },
5619 { 8, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800519f },
5620 { 9, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800518b },
5621 { 10, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800519f },
5622 { 11, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800518b },
5623 { 12, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800519f },
5624 { 13, 0x18402ecc, 0x184c079e, 0x18168a55, 0x1800518b },
5625 { 14, 0x18402ecc, 0x184c07a2, 0x18168a55, 0x18005193 },
5626
5627 /* 802.11 UNI / HyperLan 2 */
5628 { 36, 0x18402ecc, 0x184c099a, 0x18158a55, 0x180ed1a3 },
5629 { 38, 0x18402ecc, 0x184c099e, 0x18158a55, 0x180ed193 },
5630 { 40, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed183 },
5631 { 44, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed1a3 },
5632 { 46, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed18b },
5633 { 48, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed19b },
5634 { 52, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed193 },
5635 { 54, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed1a3 },
5636 { 56, 0x18402ec8, 0x184c068e, 0x18158a55, 0x180ed18b },
5637 { 60, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed183 },
5638 { 62, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed193 },
5639 { 64, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed1a3 },
5640
5641 /* 802.11 HyperLan 2 */
5642 { 100, 0x18402ec8, 0x184c06b2, 0x18178a55, 0x180ed783 },
5643 { 102, 0x18402ec8, 0x184c06b2, 0x18578a55, 0x180ed793 },
5644 { 104, 0x18402ec8, 0x185c06b2, 0x18578a55, 0x180ed1a3 },
5645 { 108, 0x18402ecc, 0x185c0a32, 0x18578a55, 0x180ed193 },
5646 { 110, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed183 },
5647 { 112, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed19b },
5648 { 116, 0x18402ecc, 0x184c0a3a, 0x18178a55, 0x180ed1a3 },
5649 { 118, 0x18402ecc, 0x184c0a3e, 0x18178a55, 0x180ed193 },
5650 { 120, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed183 },
5651 { 124, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed193 },
5652 { 126, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed15b },
5653 { 128, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed1a3 },
5654 { 132, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed18b },
5655 { 134, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed193 },
5656 { 136, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed19b },
5657 { 140, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed183 },
5658
5659 /* 802.11 UNII */
5660 { 149, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed1a7 },
5661 { 151, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed187 },
5662 { 153, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed18f },
5663 { 157, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed19f },
5664 { 159, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed1a7 },
5665 { 161, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed187 },
5666 { 165, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed197 },
5667 { 167, 0x18402ec4, 0x184c03d2, 0x18179855, 0x1815531f },
5668 { 169, 0x18402ec4, 0x184c03d2, 0x18179855, 0x18155327 },
5669 { 171, 0x18402ec4, 0x184c03d6, 0x18179855, 0x18155307 },
5670 { 173, 0x18402ec4, 0x184c03d6, 0x18179855, 0x1815530f },
5671
5672 /* 802.11 Japan */
5673 { 184, 0x15002ccc, 0x1500491e, 0x1509be55, 0x150c0a0b },
5674 { 188, 0x15002ccc, 0x15004922, 0x1509be55, 0x150c0a13 },
5675 { 192, 0x15002ccc, 0x15004926, 0x1509be55, 0x150c0a1b },
5676 { 196, 0x15002ccc, 0x1500492a, 0x1509be55, 0x150c0a23 },
5677 { 208, 0x15002ccc, 0x1500493a, 0x1509be55, 0x150c0a13 },
5678 { 212, 0x15002ccc, 0x1500493e, 0x1509be55, 0x150c0a1b },
5679 { 216, 0x15002ccc, 0x15004982, 0x1509be55, 0x150c0a23 },
5680};
5681
5682/*
Ivo van Doorn55f93212010-05-06 14:45:46 +02005683 * RF value list for rt3xxx
5684 * Supports: 2.4 GHz (all) & 5.2 GHz (RF3052)
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01005685 */
Ivo van Doorn55f93212010-05-06 14:45:46 +02005686static const struct rf_channel rf_vals_3x[] = {
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01005687 {1, 241, 2, 2 },
5688 {2, 241, 2, 7 },
5689 {3, 242, 2, 2 },
5690 {4, 242, 2, 7 },
5691 {5, 243, 2, 2 },
5692 {6, 243, 2, 7 },
5693 {7, 244, 2, 2 },
5694 {8, 244, 2, 7 },
5695 {9, 245, 2, 2 },
5696 {10, 245, 2, 7 },
5697 {11, 246, 2, 2 },
5698 {12, 246, 2, 7 },
5699 {13, 247, 2, 2 },
5700 {14, 248, 2, 4 },
Ivo van Doorn55f93212010-05-06 14:45:46 +02005701
5702 /* 802.11 UNI / HyperLan 2 */
5703 {36, 0x56, 0, 4},
5704 {38, 0x56, 0, 6},
5705 {40, 0x56, 0, 8},
5706 {44, 0x57, 0, 0},
5707 {46, 0x57, 0, 2},
5708 {48, 0x57, 0, 4},
5709 {52, 0x57, 0, 8},
5710 {54, 0x57, 0, 10},
5711 {56, 0x58, 0, 0},
5712 {60, 0x58, 0, 4},
5713 {62, 0x58, 0, 6},
5714 {64, 0x58, 0, 8},
5715
5716 /* 802.11 HyperLan 2 */
5717 {100, 0x5b, 0, 8},
5718 {102, 0x5b, 0, 10},
5719 {104, 0x5c, 0, 0},
5720 {108, 0x5c, 0, 4},
5721 {110, 0x5c, 0, 6},
5722 {112, 0x5c, 0, 8},
5723 {116, 0x5d, 0, 0},
5724 {118, 0x5d, 0, 2},
5725 {120, 0x5d, 0, 4},
5726 {124, 0x5d, 0, 8},
5727 {126, 0x5d, 0, 10},
5728 {128, 0x5e, 0, 0},
5729 {132, 0x5e, 0, 4},
5730 {134, 0x5e, 0, 6},
5731 {136, 0x5e, 0, 8},
5732 {140, 0x5f, 0, 0},
5733
5734 /* 802.11 UNII */
5735 {149, 0x5f, 0, 9},
5736 {151, 0x5f, 0, 11},
5737 {153, 0x60, 0, 1},
5738 {157, 0x60, 0, 5},
5739 {159, 0x60, 0, 7},
5740 {161, 0x60, 0, 9},
5741 {165, 0x61, 0, 1},
5742 {167, 0x61, 0, 3},
5743 {169, 0x61, 0, 5},
5744 {171, 0x61, 0, 7},
5745 {173, 0x61, 0, 9},
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01005746};
5747
Stanislaw Gruszka7848b232013-03-16 19:19:31 +01005748static const struct rf_channel rf_vals_5592_xtal20[] = {
5749 /* Channel, N, K, mod, R */
5750 {1, 482, 4, 10, 3},
5751 {2, 483, 4, 10, 3},
5752 {3, 484, 4, 10, 3},
5753 {4, 485, 4, 10, 3},
5754 {5, 486, 4, 10, 3},
5755 {6, 487, 4, 10, 3},
5756 {7, 488, 4, 10, 3},
5757 {8, 489, 4, 10, 3},
5758 {9, 490, 4, 10, 3},
5759 {10, 491, 4, 10, 3},
5760 {11, 492, 4, 10, 3},
5761 {12, 493, 4, 10, 3},
5762 {13, 494, 4, 10, 3},
5763 {14, 496, 8, 10, 3},
5764 {36, 172, 8, 12, 1},
5765 {38, 173, 0, 12, 1},
5766 {40, 173, 4, 12, 1},
5767 {42, 173, 8, 12, 1},
5768 {44, 174, 0, 12, 1},
5769 {46, 174, 4, 12, 1},
5770 {48, 174, 8, 12, 1},
5771 {50, 175, 0, 12, 1},
5772 {52, 175, 4, 12, 1},
5773 {54, 175, 8, 12, 1},
5774 {56, 176, 0, 12, 1},
5775 {58, 176, 4, 12, 1},
5776 {60, 176, 8, 12, 1},
5777 {62, 177, 0, 12, 1},
5778 {64, 177, 4, 12, 1},
5779 {100, 183, 4, 12, 1},
5780 {102, 183, 8, 12, 1},
5781 {104, 184, 0, 12, 1},
5782 {106, 184, 4, 12, 1},
5783 {108, 184, 8, 12, 1},
5784 {110, 185, 0, 12, 1},
5785 {112, 185, 4, 12, 1},
5786 {114, 185, 8, 12, 1},
5787 {116, 186, 0, 12, 1},
5788 {118, 186, 4, 12, 1},
5789 {120, 186, 8, 12, 1},
5790 {122, 187, 0, 12, 1},
5791 {124, 187, 4, 12, 1},
5792 {126, 187, 8, 12, 1},
5793 {128, 188, 0, 12, 1},
5794 {130, 188, 4, 12, 1},
5795 {132, 188, 8, 12, 1},
5796 {134, 189, 0, 12, 1},
5797 {136, 189, 4, 12, 1},
5798 {138, 189, 8, 12, 1},
5799 {140, 190, 0, 12, 1},
5800 {149, 191, 6, 12, 1},
5801 {151, 191, 10, 12, 1},
5802 {153, 192, 2, 12, 1},
5803 {155, 192, 6, 12, 1},
5804 {157, 192, 10, 12, 1},
5805 {159, 193, 2, 12, 1},
5806 {161, 193, 6, 12, 1},
5807 {165, 194, 2, 12, 1},
5808 {184, 164, 0, 12, 1},
5809 {188, 164, 4, 12, 1},
5810 {192, 165, 8, 12, 1},
5811 {196, 166, 0, 12, 1},
5812};
5813
5814static const struct rf_channel rf_vals_5592_xtal40[] = {
5815 /* Channel, N, K, mod, R */
5816 {1, 241, 2, 10, 3},
5817 {2, 241, 7, 10, 3},
5818 {3, 242, 2, 10, 3},
5819 {4, 242, 7, 10, 3},
5820 {5, 243, 2, 10, 3},
5821 {6, 243, 7, 10, 3},
5822 {7, 244, 2, 10, 3},
5823 {8, 244, 7, 10, 3},
5824 {9, 245, 2, 10, 3},
5825 {10, 245, 7, 10, 3},
5826 {11, 246, 2, 10, 3},
5827 {12, 246, 7, 10, 3},
5828 {13, 247, 2, 10, 3},
5829 {14, 248, 4, 10, 3},
5830 {36, 86, 4, 12, 1},
5831 {38, 86, 6, 12, 1},
5832 {40, 86, 8, 12, 1},
5833 {42, 86, 10, 12, 1},
5834 {44, 87, 0, 12, 1},
5835 {46, 87, 2, 12, 1},
5836 {48, 87, 4, 12, 1},
5837 {50, 87, 6, 12, 1},
5838 {52, 87, 8, 12, 1},
5839 {54, 87, 10, 12, 1},
5840 {56, 88, 0, 12, 1},
5841 {58, 88, 2, 12, 1},
5842 {60, 88, 4, 12, 1},
5843 {62, 88, 6, 12, 1},
5844 {64, 88, 8, 12, 1},
5845 {100, 91, 8, 12, 1},
5846 {102, 91, 10, 12, 1},
5847 {104, 92, 0, 12, 1},
5848 {106, 92, 2, 12, 1},
5849 {108, 92, 4, 12, 1},
5850 {110, 92, 6, 12, 1},
5851 {112, 92, 8, 12, 1},
5852 {114, 92, 10, 12, 1},
5853 {116, 93, 0, 12, 1},
5854 {118, 93, 2, 12, 1},
5855 {120, 93, 4, 12, 1},
5856 {122, 93, 6, 12, 1},
5857 {124, 93, 8, 12, 1},
5858 {126, 93, 10, 12, 1},
5859 {128, 94, 0, 12, 1},
5860 {130, 94, 2, 12, 1},
5861 {132, 94, 4, 12, 1},
5862 {134, 94, 6, 12, 1},
5863 {136, 94, 8, 12, 1},
5864 {138, 94, 10, 12, 1},
5865 {140, 95, 0, 12, 1},
5866 {149, 95, 9, 12, 1},
5867 {151, 95, 11, 12, 1},
5868 {153, 96, 1, 12, 1},
5869 {155, 96, 3, 12, 1},
5870 {157, 96, 5, 12, 1},
5871 {159, 96, 7, 12, 1},
5872 {161, 96, 9, 12, 1},
5873 {165, 97, 1, 12, 1},
5874 {184, 82, 0, 12, 1},
5875 {188, 82, 4, 12, 1},
5876 {192, 82, 8, 12, 1},
5877 {196, 83, 0, 12, 1},
5878};
5879
Gertjan van Wingerdead417a52012-09-03 03:25:51 +02005880static int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01005881{
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01005882 struct hw_mode_spec *spec = &rt2x00dev->spec;
5883 struct channel_info *info;
Ivo van Doorn8d1331b2010-08-23 19:56:07 +02005884 char *default_power1;
5885 char *default_power2;
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01005886 unsigned int i;
5887 u16 eeprom;
Stanislaw Gruszka7848b232013-03-16 19:19:31 +01005888 u32 reg;
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01005889
5890 /*
Gertjan van Wingerde93b6bd22009-12-14 20:33:55 +01005891 * Disable powersaving as default on PCI devices.
5892 */
Gertjan van Wingerdecea90e52010-02-13 20:55:47 +01005893 if (rt2x00_is_pci(rt2x00dev) || rt2x00_is_soc(rt2x00dev))
Gertjan van Wingerde93b6bd22009-12-14 20:33:55 +01005894 rt2x00dev->hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
5895
5896 /*
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01005897 * Initialize all hw fields.
5898 */
5899 rt2x00dev->hw->flags =
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01005900 IEEE80211_HW_SIGNAL_DBM |
5901 IEEE80211_HW_SUPPORTS_PS |
Helmut Schaa1df90802010-06-29 21:38:12 +02005902 IEEE80211_HW_PS_NULLFUNC_STACK |
Helmut Schaa9d4f09b2012-03-14 08:56:47 +01005903 IEEE80211_HW_AMPDU_AGGREGATION |
Helmut Schaa84e9e8ebd2013-01-17 17:34:32 +01005904 IEEE80211_HW_REPORTS_TX_ACK_STATUS;
Helmut Schaa9d4f09b2012-03-14 08:56:47 +01005905
Helmut Schaa5a5b6ed2010-10-02 11:31:33 +02005906 /*
5907 * Don't set IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING for USB devices
5908 * unless we are capable of sending the buffered frames out after the
5909 * DTIM transmission using rt2x00lib_beacondone. This will send out
5910 * multicast and broadcast traffic immediately instead of buffering it
5911 * infinitly and thus dropping it after some time.
5912 */
5913 if (!rt2x00_is_usb(rt2x00dev))
5914 rt2x00dev->hw->flags |=
5915 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING;
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01005916
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01005917 SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
5918 SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
5919 rt2x00_eeprom_addr(rt2x00dev,
5920 EEPROM_MAC_ADDR_0));
5921
Helmut Schaa3f2bee22010-06-14 22:12:01 +02005922 /*
5923 * As rt2800 has a global fallback table we cannot specify
5924 * more then one tx rate per frame but since the hw will
5925 * try several rates (based on the fallback table) we should
Helmut Schaaba3b9e52010-10-02 11:32:16 +02005926 * initialize max_report_rates to the maximum number of rates
Helmut Schaa3f2bee22010-06-14 22:12:01 +02005927 * we are going to try. Otherwise mac80211 will truncate our
5928 * reported tx rates and the rc algortihm will end up with
5929 * incorrect data.
5930 */
Helmut Schaaba3b9e52010-10-02 11:32:16 +02005931 rt2x00dev->hw->max_rates = 1;
5932 rt2x00dev->hw->max_report_rates = 7;
Helmut Schaa3f2bee22010-06-14 22:12:01 +02005933 rt2x00dev->hw->max_rate_tries = 1;
5934
RA-Jay Hung38c8a562010-12-13 12:31:27 +01005935 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom);
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01005936
5937 /*
5938 * Initialize hw_mode information.
5939 */
5940 spec->supported_bands = SUPPORT_BAND_2GHZ;
5941 spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
5942
Gertjan van Wingerde5122d892009-12-23 00:03:25 +01005943 if (rt2x00_rf(rt2x00dev, RF2820) ||
Ivo van Doorn55f93212010-05-06 14:45:46 +02005944 rt2x00_rf(rt2x00dev, RF2720)) {
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01005945 spec->num_channels = 14;
5946 spec->channels = rf_vals;
Ivo van Doorn55f93212010-05-06 14:45:46 +02005947 } else if (rt2x00_rf(rt2x00dev, RF2850) ||
5948 rt2x00_rf(rt2x00dev, RF2750)) {
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01005949 spec->supported_bands |= SUPPORT_BAND_5GHZ;
5950 spec->num_channels = ARRAY_SIZE(rf_vals);
5951 spec->channels = rf_vals;
Gertjan van Wingerde5122d892009-12-23 00:03:25 +01005952 } else if (rt2x00_rf(rt2x00dev, RF3020) ||
5953 rt2x00_rf(rt2x00dev, RF2020) ||
5954 rt2x00_rf(rt2x00dev, RF3021) ||
Gertjan van Wingerdef93bc9b2010-11-13 19:09:50 +01005955 rt2x00_rf(rt2x00dev, RF3022) ||
Woody Hunga89534e2012-06-13 15:01:16 +08005956 rt2x00_rf(rt2x00dev, RF3290) ||
Gabor Juhosadde5882011-03-03 11:46:45 +01005957 rt2x00_rf(rt2x00dev, RF3320) ||
Daniel Golle03839952012-09-09 14:24:39 +03005958 rt2x00_rf(rt2x00dev, RF3322) ||
villacis@palosanto.comccf91bd2012-05-16 21:07:12 +02005959 rt2x00_rf(rt2x00dev, RF5360) ||
Gertjan van Wingerdeaca355b2011-05-04 21:41:36 +02005960 rt2x00_rf(rt2x00dev, RF5370) ||
John Li2ed71882012-02-17 17:33:06 +08005961 rt2x00_rf(rt2x00dev, RF5372) ||
Zero.Lincff3d1f2012-05-29 16:11:09 +08005962 rt2x00_rf(rt2x00dev, RF5390) ||
5963 rt2x00_rf(rt2x00dev, RF5392)) {
Ivo van Doorn55f93212010-05-06 14:45:46 +02005964 spec->num_channels = 14;
5965 spec->channels = rf_vals_3x;
5966 } else if (rt2x00_rf(rt2x00dev, RF3052)) {
5967 spec->supported_bands |= SUPPORT_BAND_5GHZ;
5968 spec->num_channels = ARRAY_SIZE(rf_vals_3x);
5969 spec->channels = rf_vals_3x;
Stanislaw Gruszka7848b232013-03-16 19:19:31 +01005970 } else if (rt2x00_rf(rt2x00dev, RF5592)) {
5971 spec->supported_bands |= SUPPORT_BAND_5GHZ;
5972
5973 rt2800_register_read(rt2x00dev, MAC_DEBUG_INDEX, &reg);
5974 if (rt2x00_get_field32(reg, MAC_DEBUG_INDEX_XTAL)) {
5975 spec->num_channels = ARRAY_SIZE(rf_vals_5592_xtal40);
5976 spec->channels = rf_vals_5592_xtal40;
5977 } else {
5978 spec->num_channels = ARRAY_SIZE(rf_vals_5592_xtal20);
5979 spec->channels = rf_vals_5592_xtal20;
5980 }
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01005981 }
5982
Stanislaw Gruszka53216d62013-03-16 19:19:29 +01005983 if (WARN_ON_ONCE(!spec->channels))
5984 return -ENODEV;
5985
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01005986 /*
5987 * Initialize HT information.
5988 */
Gertjan van Wingerde5122d892009-12-23 00:03:25 +01005989 if (!rt2x00_rf(rt2x00dev, RF2020))
Gertjan van Wingerde38a522e2009-11-23 22:44:47 +01005990 spec->ht.ht_supported = true;
5991 else
5992 spec->ht.ht_supported = false;
5993
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01005994 spec->ht.cap =
Gertjan van Wingerde06443e42010-06-03 10:52:08 +02005995 IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01005996 IEEE80211_HT_CAP_GRN_FLD |
5997 IEEE80211_HT_CAP_SGI_20 |
Ivo van Doornaa674632010-06-29 21:48:37 +02005998 IEEE80211_HT_CAP_SGI_40;
Helmut Schaa22cabaa2010-06-03 10:52:10 +02005999
RA-Jay Hung38c8a562010-12-13 12:31:27 +01006000 if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) >= 2)
Helmut Schaa22cabaa2010-06-03 10:52:10 +02006001 spec->ht.cap |= IEEE80211_HT_CAP_TX_STBC;
6002
Ivo van Doornaa674632010-06-29 21:48:37 +02006003 spec->ht.cap |=
RA-Jay Hung38c8a562010-12-13 12:31:27 +01006004 rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) <<
Ivo van Doornaa674632010-06-29 21:48:37 +02006005 IEEE80211_HT_CAP_RX_STBC_SHIFT;
6006
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01006007 spec->ht.ampdu_factor = 3;
6008 spec->ht.ampdu_density = 4;
6009 spec->ht.mcs.tx_params =
6010 IEEE80211_HT_MCS_TX_DEFINED |
6011 IEEE80211_HT_MCS_TX_RX_DIFF |
RA-Jay Hung38c8a562010-12-13 12:31:27 +01006012 ((rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) - 1) <<
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01006013 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
6014
RA-Jay Hung38c8a562010-12-13 12:31:27 +01006015 switch (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH)) {
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01006016 case 3:
6017 spec->ht.mcs.rx_mask[2] = 0xff;
6018 case 2:
6019 spec->ht.mcs.rx_mask[1] = 0xff;
6020 case 1:
6021 spec->ht.mcs.rx_mask[0] = 0xff;
6022 spec->ht.mcs.rx_mask[4] = 0x1; /* MCS32 */
6023 break;
6024 }
6025
6026 /*
6027 * Create channel information array
6028 */
Joe Perchesbaeb2ff2010-08-11 07:02:48 +00006029 info = kcalloc(spec->num_channels, sizeof(*info), GFP_KERNEL);
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01006030 if (!info)
6031 return -ENOMEM;
6032
6033 spec->channels_info = info;
6034
Ivo van Doorn8d1331b2010-08-23 19:56:07 +02006035 default_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG1);
6036 default_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG2);
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01006037
6038 for (i = 0; i < 14; i++) {
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01006039 info[i].default_power1 = default_power1[i];
6040 info[i].default_power2 = default_power2[i];
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01006041 }
6042
6043 if (spec->num_channels > 14) {
Ivo van Doorn8d1331b2010-08-23 19:56:07 +02006044 default_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A1);
6045 default_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A2);
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01006046
6047 for (i = 14; i < spec->num_channels; i++) {
RA-Jay Hunge90c54b2011-02-20 13:55:25 +01006048 info[i].default_power1 = default_power1[i];
6049 info[i].default_power2 = default_power2[i];
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01006050 }
6051 }
6052
John Li2e9c43d2012-02-16 21:40:57 +08006053 switch (rt2x00dev->chip.rf) {
6054 case RF2020:
6055 case RF3020:
6056 case RF3021:
6057 case RF3022:
6058 case RF3320:
6059 case RF3052:
Woody Hunga89534e2012-06-13 15:01:16 +08006060 case RF3290:
villacis@palosanto.comccf91bd2012-05-16 21:07:12 +02006061 case RF5360:
John Li2e9c43d2012-02-16 21:40:57 +08006062 case RF5370:
6063 case RF5372:
6064 case RF5390:
Zero.Lincff3d1f2012-05-29 16:11:09 +08006065 case RF5392:
John Li2e9c43d2012-02-16 21:40:57 +08006066 __set_bit(CAPABILITY_VCO_RECALIBRATION, &rt2x00dev->cap_flags);
6067 break;
6068 }
6069
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01006070 return 0;
6071}
Gertjan van Wingerdead417a52012-09-03 03:25:51 +02006072
Gabor Juhoscbafb602013-03-30 14:53:10 +01006073static int rt2800_probe_rt(struct rt2x00_dev *rt2x00dev)
6074{
6075 u32 reg;
6076 u32 rt;
6077 u32 rev;
6078
6079 if (rt2x00_rt(rt2x00dev, RT3290))
6080 rt2800_register_read(rt2x00dev, MAC_CSR0_3290, &reg);
6081 else
6082 rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
6083
6084 rt = rt2x00_get_field32(reg, MAC_CSR0_CHIPSET);
6085 rev = rt2x00_get_field32(reg, MAC_CSR0_REVISION);
6086
6087 switch (rt) {
6088 case RT2860:
6089 case RT2872:
6090 case RT2883:
6091 case RT3070:
6092 case RT3071:
6093 case RT3090:
6094 case RT3290:
6095 case RT3352:
6096 case RT3390:
6097 case RT3572:
6098 case RT5390:
6099 case RT5392:
6100 case RT5592:
6101 break;
6102 default:
6103 ERROR(rt2x00dev,
6104 "Invalid RT chipset 0x%04x, rev %04x detected.\n",
6105 rt, rev);
6106 return -ENODEV;
6107 }
6108
6109 rt2x00_set_rt(rt2x00dev, rt, rev);
6110
6111 return 0;
6112}
6113
Gertjan van Wingerdead417a52012-09-03 03:25:51 +02006114int rt2800_probe_hw(struct rt2x00_dev *rt2x00dev)
6115{
6116 int retval;
6117 u32 reg;
6118
Gabor Juhoscbafb602013-03-30 14:53:10 +01006119 retval = rt2800_probe_rt(rt2x00dev);
6120 if (retval)
6121 return retval;
6122
Gertjan van Wingerdead417a52012-09-03 03:25:51 +02006123 /*
6124 * Allocate eeprom data.
6125 */
6126 retval = rt2800_validate_eeprom(rt2x00dev);
6127 if (retval)
6128 return retval;
6129
6130 retval = rt2800_init_eeprom(rt2x00dev);
6131 if (retval)
6132 return retval;
6133
6134 /*
6135 * Enable rfkill polling by setting GPIO direction of the
6136 * rfkill switch GPIO pin correctly.
6137 */
6138 rt2800_register_read(rt2x00dev, GPIO_CTRL, &reg);
6139 rt2x00_set_field32(&reg, GPIO_CTRL_DIR2, 1);
6140 rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
6141
6142 /*
6143 * Initialize hw specifications.
6144 */
6145 retval = rt2800_probe_hw_mode(rt2x00dev);
6146 if (retval)
6147 return retval;
6148
6149 /*
6150 * Set device capabilities.
6151 */
6152 __set_bit(CAPABILITY_CONTROL_FILTERS, &rt2x00dev->cap_flags);
6153 __set_bit(CAPABILITY_CONTROL_FILTER_PSPOLL, &rt2x00dev->cap_flags);
6154 if (!rt2x00_is_usb(rt2x00dev))
6155 __set_bit(CAPABILITY_PRE_TBTT_INTERRUPT, &rt2x00dev->cap_flags);
6156
6157 /*
6158 * Set device requirements.
6159 */
6160 if (!rt2x00_is_soc(rt2x00dev))
6161 __set_bit(REQUIRE_FIRMWARE, &rt2x00dev->cap_flags);
6162 __set_bit(REQUIRE_L2PAD, &rt2x00dev->cap_flags);
6163 __set_bit(REQUIRE_TXSTATUS_FIFO, &rt2x00dev->cap_flags);
6164 if (!rt2800_hwcrypt_disabled(rt2x00dev))
6165 __set_bit(CAPABILITY_HW_CRYPTO, &rt2x00dev->cap_flags);
6166 __set_bit(CAPABILITY_LINK_TUNING, &rt2x00dev->cap_flags);
6167 __set_bit(REQUIRE_HT_TX_DESC, &rt2x00dev->cap_flags);
6168 if (rt2x00_is_usb(rt2x00dev))
6169 __set_bit(REQUIRE_PS_AUTOWAKE, &rt2x00dev->cap_flags);
6170 else {
6171 __set_bit(REQUIRE_DMA, &rt2x00dev->cap_flags);
6172 __set_bit(REQUIRE_TASKLET_CONTEXT, &rt2x00dev->cap_flags);
6173 }
6174
6175 /*
6176 * Set the rssi offset.
6177 */
6178 rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
6179
6180 return 0;
6181}
6182EXPORT_SYMBOL_GPL(rt2800_probe_hw);
Bartlomiej Zolnierkiewicz4da29332009-11-08 14:39:32 +01006183
6184/*
Bartlomiej Zolnierkiewicz2ce33992009-11-04 18:37:05 +01006185 * IEEE80211 stack callback functions.
6186 */
Helmut Schaae7836192010-07-11 12:28:54 +02006187void rt2800_get_tkip_seq(struct ieee80211_hw *hw, u8 hw_key_idx, u32 *iv32,
6188 u16 *iv16)
Bartlomiej Zolnierkiewicz2ce33992009-11-04 18:37:05 +01006189{
6190 struct rt2x00_dev *rt2x00dev = hw->priv;
6191 struct mac_iveiv_entry iveiv_entry;
6192 u32 offset;
6193
6194 offset = MAC_IVEIV_ENTRY(hw_key_idx);
6195 rt2800_register_multiread(rt2x00dev, offset,
6196 &iveiv_entry, sizeof(iveiv_entry));
6197
Julia Lawall855da5e2009-12-13 17:07:45 +01006198 memcpy(iv16, &iveiv_entry.iv[0], sizeof(*iv16));
6199 memcpy(iv32, &iveiv_entry.iv[4], sizeof(*iv32));
Bartlomiej Zolnierkiewicz2ce33992009-11-04 18:37:05 +01006200}
Helmut Schaae7836192010-07-11 12:28:54 +02006201EXPORT_SYMBOL_GPL(rt2800_get_tkip_seq);
Bartlomiej Zolnierkiewicz2ce33992009-11-04 18:37:05 +01006202
Helmut Schaae7836192010-07-11 12:28:54 +02006203int rt2800_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
Bartlomiej Zolnierkiewicz2ce33992009-11-04 18:37:05 +01006204{
6205 struct rt2x00_dev *rt2x00dev = hw->priv;
6206 u32 reg;
6207 bool enabled = (value < IEEE80211_MAX_RTS_THRESHOLD);
6208
6209 rt2800_register_read(rt2x00dev, TX_RTS_CFG, &reg);
6210 rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES, value);
6211 rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg);
6212
6213 rt2800_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
6214 rt2x00_set_field32(&reg, CCK_PROT_CFG_RTS_TH_EN, enabled);
6215 rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg);
6216
6217 rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
6218 rt2x00_set_field32(&reg, OFDM_PROT_CFG_RTS_TH_EN, enabled);
6219 rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
6220
6221 rt2800_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
6222 rt2x00_set_field32(&reg, MM20_PROT_CFG_RTS_TH_EN, enabled);
6223 rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
6224
6225 rt2800_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
6226 rt2x00_set_field32(&reg, MM40_PROT_CFG_RTS_TH_EN, enabled);
6227 rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
6228
6229 rt2800_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
6230 rt2x00_set_field32(&reg, GF20_PROT_CFG_RTS_TH_EN, enabled);
6231 rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
6232
6233 rt2800_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
6234 rt2x00_set_field32(&reg, GF40_PROT_CFG_RTS_TH_EN, enabled);
6235 rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
6236
6237 return 0;
6238}
Helmut Schaae7836192010-07-11 12:28:54 +02006239EXPORT_SYMBOL_GPL(rt2800_set_rts_threshold);
Bartlomiej Zolnierkiewicz2ce33992009-11-04 18:37:05 +01006240
Eliad Peller8a3a3c82011-10-02 10:15:52 +02006241int rt2800_conf_tx(struct ieee80211_hw *hw,
6242 struct ieee80211_vif *vif, u16 queue_idx,
Helmut Schaae7836192010-07-11 12:28:54 +02006243 const struct ieee80211_tx_queue_params *params)
Bartlomiej Zolnierkiewicz2ce33992009-11-04 18:37:05 +01006244{
6245 struct rt2x00_dev *rt2x00dev = hw->priv;
6246 struct data_queue *queue;
6247 struct rt2x00_field32 field;
6248 int retval;
6249 u32 reg;
6250 u32 offset;
6251
6252 /*
6253 * First pass the configuration through rt2x00lib, that will
6254 * update the queue settings and validate the input. After that
6255 * we are free to update the registers based on the value
6256 * in the queue parameter.
6257 */
Eliad Peller8a3a3c82011-10-02 10:15:52 +02006258 retval = rt2x00mac_conf_tx(hw, vif, queue_idx, params);
Bartlomiej Zolnierkiewicz2ce33992009-11-04 18:37:05 +01006259 if (retval)
6260 return retval;
6261
6262 /*
6263 * We only need to perform additional register initialization
6264 * for WMM queues/
6265 */
6266 if (queue_idx >= 4)
6267 return 0;
6268
Helmut Schaa11f818e2011-03-03 19:38:55 +01006269 queue = rt2x00queue_get_tx_queue(rt2x00dev, queue_idx);
Bartlomiej Zolnierkiewicz2ce33992009-11-04 18:37:05 +01006270
6271 /* Update WMM TXOP register */
6272 offset = WMM_TXOP0_CFG + (sizeof(u32) * (!!(queue_idx & 2)));
6273 field.bit_offset = (queue_idx & 1) * 16;
6274 field.bit_mask = 0xffff << field.bit_offset;
6275
6276 rt2800_register_read(rt2x00dev, offset, &reg);
6277 rt2x00_set_field32(&reg, field, queue->txop);
6278 rt2800_register_write(rt2x00dev, offset, reg);
6279
6280 /* Update WMM registers */
6281 field.bit_offset = queue_idx * 4;
6282 field.bit_mask = 0xf << field.bit_offset;
6283
6284 rt2800_register_read(rt2x00dev, WMM_AIFSN_CFG, &reg);
6285 rt2x00_set_field32(&reg, field, queue->aifs);
6286 rt2800_register_write(rt2x00dev, WMM_AIFSN_CFG, reg);
6287
6288 rt2800_register_read(rt2x00dev, WMM_CWMIN_CFG, &reg);
6289 rt2x00_set_field32(&reg, field, queue->cw_min);
6290 rt2800_register_write(rt2x00dev, WMM_CWMIN_CFG, reg);
6291
6292 rt2800_register_read(rt2x00dev, WMM_CWMAX_CFG, &reg);
6293 rt2x00_set_field32(&reg, field, queue->cw_max);
6294 rt2800_register_write(rt2x00dev, WMM_CWMAX_CFG, reg);
6295
6296 /* Update EDCA registers */
6297 offset = EDCA_AC0_CFG + (sizeof(u32) * queue_idx);
6298
6299 rt2800_register_read(rt2x00dev, offset, &reg);
6300 rt2x00_set_field32(&reg, EDCA_AC0_CFG_TX_OP, queue->txop);
6301 rt2x00_set_field32(&reg, EDCA_AC0_CFG_AIFSN, queue->aifs);
6302 rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMIN, queue->cw_min);
6303 rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMAX, queue->cw_max);
6304 rt2800_register_write(rt2x00dev, offset, reg);
6305
6306 return 0;
6307}
Helmut Schaae7836192010-07-11 12:28:54 +02006308EXPORT_SYMBOL_GPL(rt2800_conf_tx);
Bartlomiej Zolnierkiewicz2ce33992009-11-04 18:37:05 +01006309
Eliad Peller37a41b42011-09-21 14:06:11 +03006310u64 rt2800_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
Bartlomiej Zolnierkiewicz2ce33992009-11-04 18:37:05 +01006311{
6312 struct rt2x00_dev *rt2x00dev = hw->priv;
6313 u64 tsf;
6314 u32 reg;
6315
6316 rt2800_register_read(rt2x00dev, TSF_TIMER_DW1, &reg);
6317 tsf = (u64) rt2x00_get_field32(reg, TSF_TIMER_DW1_HIGH_WORD) << 32;
6318 rt2800_register_read(rt2x00dev, TSF_TIMER_DW0, &reg);
6319 tsf |= rt2x00_get_field32(reg, TSF_TIMER_DW0_LOW_WORD);
6320
6321 return tsf;
6322}
Helmut Schaae7836192010-07-11 12:28:54 +02006323EXPORT_SYMBOL_GPL(rt2800_get_tsf);
Bartlomiej Zolnierkiewicz2ce33992009-11-04 18:37:05 +01006324
Helmut Schaae7836192010-07-11 12:28:54 +02006325int rt2800_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6326 enum ieee80211_ampdu_mlme_action action,
Johannes Berg0b01f032011-01-18 13:51:05 +01006327 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
6328 u8 buf_size)
Helmut Schaa1df90802010-06-29 21:38:12 +02006329{
Helmut Schaaaf353232011-09-08 14:38:36 +02006330 struct rt2x00_sta *sta_priv = (struct rt2x00_sta *)sta->drv_priv;
Helmut Schaa1df90802010-06-29 21:38:12 +02006331 int ret = 0;
6332
Helmut Schaaaf353232011-09-08 14:38:36 +02006333 /*
6334 * Don't allow aggregation for stations the hardware isn't aware
6335 * of because tx status reports for frames to an unknown station
6336 * always contain wcid=255 and thus we can't distinguish between
6337 * multiple stations which leads to unwanted situations when the
6338 * hw reorders frames due to aggregation.
6339 */
6340 if (sta_priv->wcid < 0)
6341 return 1;
6342
Helmut Schaa1df90802010-06-29 21:38:12 +02006343 switch (action) {
6344 case IEEE80211_AMPDU_RX_START:
6345 case IEEE80211_AMPDU_RX_STOP:
Helmut Schaa58ed8262010-10-02 11:33:17 +02006346 /*
6347 * The hw itself takes care of setting up BlockAck mechanisms.
6348 * So, we only have to allow mac80211 to nagotiate a BlockAck
6349 * agreement. Once that is done, the hw will BlockAck incoming
6350 * AMPDUs without further setup.
6351 */
Helmut Schaa1df90802010-06-29 21:38:12 +02006352 break;
6353 case IEEE80211_AMPDU_TX_START:
6354 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
6355 break;
Johannes Berg18b559d2012-07-18 13:51:25 +02006356 case IEEE80211_AMPDU_TX_STOP_CONT:
6357 case IEEE80211_AMPDU_TX_STOP_FLUSH:
6358 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Helmut Schaa1df90802010-06-29 21:38:12 +02006359 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
6360 break;
6361 case IEEE80211_AMPDU_TX_OPERATIONAL:
6362 break;
6363 default:
Ivo van Doorn4e9e58c2010-06-29 21:49:50 +02006364 WARNING((struct rt2x00_dev *)hw->priv, "Unknown AMPDU action\n");
Helmut Schaa1df90802010-06-29 21:38:12 +02006365 }
6366
6367 return ret;
6368}
Helmut Schaae7836192010-07-11 12:28:54 +02006369EXPORT_SYMBOL_GPL(rt2800_ampdu_action);
Ivo van Doorna5ea2f02010-06-14 22:13:15 +02006370
Helmut Schaa977206d2010-12-13 12:31:58 +01006371int rt2800_get_survey(struct ieee80211_hw *hw, int idx,
6372 struct survey_info *survey)
6373{
6374 struct rt2x00_dev *rt2x00dev = hw->priv;
6375 struct ieee80211_conf *conf = &hw->conf;
6376 u32 idle, busy, busy_ext;
6377
6378 if (idx != 0)
6379 return -ENOENT;
6380
Karl Beldan675a0b02013-03-25 16:26:57 +01006381 survey->channel = conf->chandef.chan;
Helmut Schaa977206d2010-12-13 12:31:58 +01006382
6383 rt2800_register_read(rt2x00dev, CH_IDLE_STA, &idle);
6384 rt2800_register_read(rt2x00dev, CH_BUSY_STA, &busy);
6385 rt2800_register_read(rt2x00dev, CH_BUSY_STA_SEC, &busy_ext);
6386
6387 if (idle || busy) {
6388 survey->filled = SURVEY_INFO_CHANNEL_TIME |
6389 SURVEY_INFO_CHANNEL_TIME_BUSY |
6390 SURVEY_INFO_CHANNEL_TIME_EXT_BUSY;
6391
6392 survey->channel_time = (idle + busy) / 1000;
6393 survey->channel_time_busy = busy / 1000;
6394 survey->channel_time_ext_busy = busy_ext / 1000;
6395 }
6396
Helmut Schaa9931df22011-12-22 09:36:29 +01006397 if (!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL))
6398 survey->filled |= SURVEY_INFO_IN_USE;
6399
Helmut Schaa977206d2010-12-13 12:31:58 +01006400 return 0;
6401
6402}
6403EXPORT_SYMBOL_GPL(rt2800_get_survey);
6404
Ivo van Doorna5ea2f02010-06-14 22:13:15 +02006405MODULE_AUTHOR(DRV_PROJECT ", Bartlomiej Zolnierkiewicz");
6406MODULE_VERSION(DRV_VERSION);
6407MODULE_DESCRIPTION("Ralink RT2800 library");
6408MODULE_LICENSE("GPL");