Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 1 | /* |
Ivo van Doorn | 96481b2 | 2010-08-06 20:47:57 +0200 | [diff] [blame] | 2 | Copyright (C) 2010 Willow Garage <http://www.willowgarage.com> |
Ivo van Doorn | a5ea2f0 | 2010-06-14 22:13:15 +0200 | [diff] [blame] | 3 | Copyright (C) 2010 Ivo van Doorn <IvDoorn@gmail.com> |
Gertjan van Wingerde | 9c9a0d1 | 2009-11-08 16:39:55 +0100 | [diff] [blame] | 4 | Copyright (C) 2009 Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> |
Gertjan van Wingerde | cce5fc4 | 2009-11-10 22:42:40 +0100 | [diff] [blame] | 5 | Copyright (C) 2009 Gertjan van Wingerde <gwingerde@gmail.com> |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 6 | |
Gertjan van Wingerde | 9c9a0d1 | 2009-11-08 16:39:55 +0100 | [diff] [blame] | 7 | Based on the original rt2800pci.c and rt2800usb.c. |
Gertjan van Wingerde | 9c9a0d1 | 2009-11-08 16:39:55 +0100 | [diff] [blame] | 8 | Copyright (C) 2009 Alban Browaeys <prahal@yahoo.com> |
| 9 | Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org> |
| 10 | Copyright (C) 2009 Luis Correia <luis.f.correia@gmail.com> |
| 11 | Copyright (C) 2009 Mattias Nissler <mattias.nissler@gmx.de> |
| 12 | Copyright (C) 2009 Mark Asselstine <asselsm@gmail.com> |
| 13 | Copyright (C) 2009 Xose Vazquez Perez <xose.vazquez@gmail.com> |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 14 | <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 Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 37 | #include <linux/crc-ccitt.h> |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 38 | #include <linux/kernel.h> |
| 39 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 40 | #include <linux/slab.h> |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 41 | |
| 42 | #include "rt2x00.h" |
| 43 | #include "rt2800lib.h" |
| 44 | #include "rt2800.h" |
| 45 | |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 46 | /* |
| 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 Schaa | baff800 | 2010-04-28 09:58:59 +0200 | [diff] [blame] | 70 | static 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 | |
| 83 | NOTICE(rt2x00dev, "Unknown RF chipset on rt305x\n"); |
| 84 | return false; |
| 85 | } |
| 86 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 87 | static void rt2800_bbp_write(struct rt2x00_dev *rt2x00dev, |
| 88 | const unsigned int word, const u8 value) |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 89 | { |
| 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, ®)) { |
| 99 | reg = 0; |
| 100 | rt2x00_set_field32(®, BBP_CSR_CFG_VALUE, value); |
| 101 | rt2x00_set_field32(®, BBP_CSR_CFG_REGNUM, word); |
| 102 | rt2x00_set_field32(®, BBP_CSR_CFG_BUSY, 1); |
| 103 | rt2x00_set_field32(®, BBP_CSR_CFG_READ_CONTROL, 0); |
Ivo van Doorn | efc7d36 | 2010-06-29 21:49:26 +0200 | [diff] [blame] | 104 | rt2x00_set_field32(®, BBP_CSR_CFG_BBP_RW_MODE, 1); |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 105 | |
| 106 | rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg); |
| 107 | } |
| 108 | |
| 109 | mutex_unlock(&rt2x00dev->csr_mutex); |
| 110 | } |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 111 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 112 | static void rt2800_bbp_read(struct rt2x00_dev *rt2x00dev, |
| 113 | const unsigned int word, u8 *value) |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 114 | { |
| 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, ®)) { |
| 128 | reg = 0; |
| 129 | rt2x00_set_field32(®, BBP_CSR_CFG_REGNUM, word); |
| 130 | rt2x00_set_field32(®, BBP_CSR_CFG_BUSY, 1); |
| 131 | rt2x00_set_field32(®, BBP_CSR_CFG_READ_CONTROL, 1); |
Ivo van Doorn | efc7d36 | 2010-06-29 21:49:26 +0200 | [diff] [blame] | 132 | rt2x00_set_field32(®, BBP_CSR_CFG_BBP_RW_MODE, 1); |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 133 | |
| 134 | rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg); |
| 135 | |
| 136 | WAIT_FOR_BBP(rt2x00dev, ®); |
| 137 | } |
| 138 | |
| 139 | *value = rt2x00_get_field32(reg, BBP_CSR_CFG_VALUE); |
| 140 | |
| 141 | mutex_unlock(&rt2x00dev->csr_mutex); |
| 142 | } |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 143 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 144 | static void rt2800_rfcsr_write(struct rt2x00_dev *rt2x00dev, |
| 145 | const unsigned int word, const u8 value) |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 146 | { |
| 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, ®)) { |
| 156 | reg = 0; |
| 157 | rt2x00_set_field32(®, RF_CSR_CFG_DATA, value); |
| 158 | rt2x00_set_field32(®, RF_CSR_CFG_REGNUM, word); |
| 159 | rt2x00_set_field32(®, RF_CSR_CFG_WRITE, 1); |
| 160 | rt2x00_set_field32(®, RF_CSR_CFG_BUSY, 1); |
| 161 | |
| 162 | rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg); |
| 163 | } |
| 164 | |
| 165 | mutex_unlock(&rt2x00dev->csr_mutex); |
| 166 | } |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 167 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 168 | static void rt2800_rfcsr_read(struct rt2x00_dev *rt2x00dev, |
| 169 | const unsigned int word, u8 *value) |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 170 | { |
| 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, ®)) { |
| 184 | reg = 0; |
| 185 | rt2x00_set_field32(®, RF_CSR_CFG_REGNUM, word); |
| 186 | rt2x00_set_field32(®, RF_CSR_CFG_WRITE, 0); |
| 187 | rt2x00_set_field32(®, RF_CSR_CFG_BUSY, 1); |
| 188 | |
| 189 | rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg); |
| 190 | |
| 191 | WAIT_FOR_RFCSR(rt2x00dev, ®); |
| 192 | } |
| 193 | |
| 194 | *value = rt2x00_get_field32(reg, RF_CSR_CFG_DATA); |
| 195 | |
| 196 | mutex_unlock(&rt2x00dev->csr_mutex); |
| 197 | } |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 198 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 199 | static void rt2800_rf_write(struct rt2x00_dev *rt2x00dev, |
| 200 | const unsigned int word, const u32 value) |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 201 | { |
| 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, ®)) { |
| 211 | reg = 0; |
| 212 | rt2x00_set_field32(®, RF_CSR_CFG0_REG_VALUE_BW, value); |
| 213 | rt2x00_set_field32(®, RF_CSR_CFG0_STANDBYMODE, 0); |
| 214 | rt2x00_set_field32(®, RF_CSR_CFG0_SEL, 0); |
| 215 | rt2x00_set_field32(®, RF_CSR_CFG0_BUSY, 1); |
| 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 Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 223 | |
| 224 | void rt2800_mcu_request(struct rt2x00_dev *rt2x00dev, |
| 225 | const u8 command, const u8 token, |
| 226 | const u8 arg0, const u8 arg1) |
| 227 | { |
| 228 | u32 reg; |
| 229 | |
Gertjan van Wingerde | ee303e5 | 2009-11-23 22:44:49 +0100 | [diff] [blame] | 230 | /* |
Gertjan van Wingerde | cea90e5 | 2010-02-13 20:55:47 +0100 | [diff] [blame] | 231 | * SOC devices don't support MCU requests. |
Gertjan van Wingerde | ee303e5 | 2009-11-23 22:44:49 +0100 | [diff] [blame] | 232 | */ |
Gertjan van Wingerde | cea90e5 | 2010-02-13 20:55:47 +0100 | [diff] [blame] | 233 | if (rt2x00_is_soc(rt2x00dev)) |
Gertjan van Wingerde | ee303e5 | 2009-11-23 22:44:49 +0100 | [diff] [blame] | 234 | return; |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 235 | |
| 236 | mutex_lock(&rt2x00dev->csr_mutex); |
| 237 | |
| 238 | /* |
| 239 | * Wait until the MCU becomes available, afterwards we |
| 240 | * can safely write the new data into the register. |
| 241 | */ |
| 242 | if (WAIT_FOR_MCU(rt2x00dev, ®)) { |
| 243 | rt2x00_set_field32(®, H2M_MAILBOX_CSR_OWNER, 1); |
| 244 | rt2x00_set_field32(®, H2M_MAILBOX_CSR_CMD_TOKEN, token); |
| 245 | rt2x00_set_field32(®, H2M_MAILBOX_CSR_ARG0, arg0); |
| 246 | rt2x00_set_field32(®, H2M_MAILBOX_CSR_ARG1, arg1); |
| 247 | rt2800_register_write_lock(rt2x00dev, H2M_MAILBOX_CSR, reg); |
| 248 | |
| 249 | reg = 0; |
| 250 | rt2x00_set_field32(®, HOST_CMD_CSR_HOST_COMMAND, command); |
| 251 | rt2800_register_write_lock(rt2x00dev, HOST_CMD_CSR, reg); |
| 252 | } |
| 253 | |
| 254 | mutex_unlock(&rt2x00dev->csr_mutex); |
| 255 | } |
| 256 | EXPORT_SYMBOL_GPL(rt2800_mcu_request); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 257 | |
Ivo van Doorn | 5ffddc4 | 2010-08-30 21:13:08 +0200 | [diff] [blame] | 258 | int rt2800_wait_csr_ready(struct rt2x00_dev *rt2x00dev) |
| 259 | { |
| 260 | unsigned int i = 0; |
| 261 | u32 reg; |
| 262 | |
| 263 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
| 264 | rt2800_register_read(rt2x00dev, MAC_CSR0, ®); |
| 265 | if (reg && reg != ~0) |
| 266 | return 0; |
| 267 | msleep(1); |
| 268 | } |
| 269 | |
| 270 | ERROR(rt2x00dev, "Unstable hardware.\n"); |
| 271 | return -EBUSY; |
| 272 | } |
| 273 | EXPORT_SYMBOL_GPL(rt2800_wait_csr_ready); |
| 274 | |
Gertjan van Wingerde | 67a4c1e | 2009-12-30 11:36:32 +0100 | [diff] [blame] | 275 | int rt2800_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev) |
| 276 | { |
| 277 | unsigned int i; |
| 278 | u32 reg; |
| 279 | |
Helmut Schaa | 08e5310 | 2010-11-04 20:37:47 +0100 | [diff] [blame] | 280 | /* |
| 281 | * Some devices are really slow to respond here. Wait a whole second |
| 282 | * before timing out. |
| 283 | */ |
Gertjan van Wingerde | 67a4c1e | 2009-12-30 11:36:32 +0100 | [diff] [blame] | 284 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
| 285 | rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®); |
| 286 | if (!rt2x00_get_field32(reg, WPDMA_GLO_CFG_TX_DMA_BUSY) && |
| 287 | !rt2x00_get_field32(reg, WPDMA_GLO_CFG_RX_DMA_BUSY)) |
| 288 | return 0; |
| 289 | |
Helmut Schaa | 08e5310 | 2010-11-04 20:37:47 +0100 | [diff] [blame] | 290 | msleep(10); |
Gertjan van Wingerde | 67a4c1e | 2009-12-30 11:36:32 +0100 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | ERROR(rt2x00dev, "WPDMA TX/RX busy, aborting.\n"); |
| 294 | return -EACCES; |
| 295 | } |
| 296 | EXPORT_SYMBOL_GPL(rt2800_wait_wpdma_ready); |
| 297 | |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 298 | static bool rt2800_check_firmware_crc(const u8 *data, const size_t len) |
| 299 | { |
| 300 | u16 fw_crc; |
| 301 | u16 crc; |
| 302 | |
| 303 | /* |
| 304 | * The last 2 bytes in the firmware array are the crc checksum itself, |
| 305 | * this means that we should never pass those 2 bytes to the crc |
| 306 | * algorithm. |
| 307 | */ |
| 308 | fw_crc = (data[len - 2] << 8 | data[len - 1]); |
| 309 | |
| 310 | /* |
| 311 | * Use the crc ccitt algorithm. |
| 312 | * This will return the same value as the legacy driver which |
| 313 | * used bit ordering reversion on the both the firmware bytes |
| 314 | * before input input as well as on the final output. |
| 315 | * Obviously using crc ccitt directly is much more efficient. |
| 316 | */ |
| 317 | crc = crc_ccitt(~0, data, len - 2); |
| 318 | |
| 319 | /* |
| 320 | * There is a small difference between the crc-itu-t + bitrev and |
| 321 | * the crc-ccitt crc calculation. In the latter method the 2 bytes |
| 322 | * will be swapped, use swab16 to convert the crc to the correct |
| 323 | * value. |
| 324 | */ |
| 325 | crc = swab16(crc); |
| 326 | |
| 327 | return fw_crc == crc; |
| 328 | } |
| 329 | |
| 330 | int rt2800_check_firmware(struct rt2x00_dev *rt2x00dev, |
| 331 | const u8 *data, const size_t len) |
| 332 | { |
| 333 | size_t offset = 0; |
| 334 | size_t fw_len; |
| 335 | bool multiple; |
| 336 | |
| 337 | /* |
| 338 | * PCI(e) & SOC devices require firmware with a length |
| 339 | * of 8kb. USB devices require firmware files with a length |
| 340 | * of 4kb. Certain USB chipsets however require different firmware, |
| 341 | * which Ralink only provides attached to the original firmware |
| 342 | * file. Thus for USB devices, firmware files have a length |
| 343 | * which is a multiple of 4kb. |
| 344 | */ |
| 345 | if (rt2x00_is_usb(rt2x00dev)) { |
| 346 | fw_len = 4096; |
| 347 | multiple = true; |
| 348 | } else { |
| 349 | fw_len = 8192; |
| 350 | multiple = true; |
| 351 | } |
| 352 | |
| 353 | /* |
| 354 | * Validate the firmware length |
| 355 | */ |
| 356 | if (len != fw_len && (!multiple || (len % fw_len) != 0)) |
| 357 | return FW_BAD_LENGTH; |
| 358 | |
| 359 | /* |
| 360 | * Check if the chipset requires one of the upper parts |
| 361 | * of the firmware. |
| 362 | */ |
| 363 | if (rt2x00_is_usb(rt2x00dev) && |
| 364 | !rt2x00_rt(rt2x00dev, RT2860) && |
| 365 | !rt2x00_rt(rt2x00dev, RT2872) && |
| 366 | !rt2x00_rt(rt2x00dev, RT3070) && |
| 367 | ((len / fw_len) == 1)) |
| 368 | return FW_BAD_VERSION; |
| 369 | |
| 370 | /* |
| 371 | * 8kb firmware files must be checked as if it were |
| 372 | * 2 separate firmware files. |
| 373 | */ |
| 374 | while (offset < len) { |
| 375 | if (!rt2800_check_firmware_crc(data + offset, fw_len)) |
| 376 | return FW_BAD_CRC; |
| 377 | |
| 378 | offset += fw_len; |
| 379 | } |
| 380 | |
| 381 | return FW_OK; |
| 382 | } |
| 383 | EXPORT_SYMBOL_GPL(rt2800_check_firmware); |
| 384 | |
| 385 | int rt2800_load_firmware(struct rt2x00_dev *rt2x00dev, |
| 386 | const u8 *data, const size_t len) |
| 387 | { |
| 388 | unsigned int i; |
| 389 | u32 reg; |
| 390 | |
| 391 | /* |
Ivo van Doorn | b9eca24 | 2010-08-30 21:13:54 +0200 | [diff] [blame] | 392 | * If driver doesn't wake up firmware here, |
| 393 | * rt2800_load_firmware will hang forever when interface is up again. |
| 394 | */ |
| 395 | rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0x00000000); |
| 396 | |
| 397 | /* |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 398 | * Wait for stable hardware. |
| 399 | */ |
Ivo van Doorn | 5ffddc4 | 2010-08-30 21:13:08 +0200 | [diff] [blame] | 400 | if (rt2800_wait_csr_ready(rt2x00dev)) |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 401 | return -EBUSY; |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 402 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 403 | if (rt2x00_is_pci(rt2x00dev)) { |
| 404 | if (rt2x00_rt(rt2x00dev, RT5390)) { |
| 405 | rt2800_register_read(rt2x00dev, AUX_CTRL, ®); |
| 406 | rt2x00_set_field32(®, AUX_CTRL_FORCE_PCIE_CLK, 1); |
| 407 | rt2x00_set_field32(®, AUX_CTRL_WAKE_PCIE_EN, 1); |
| 408 | rt2800_register_write(rt2x00dev, AUX_CTRL, reg); |
| 409 | } |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 410 | rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000002); |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 411 | } |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 412 | |
| 413 | /* |
| 414 | * Disable DMA, will be reenabled later when enabling |
| 415 | * the radio. |
| 416 | */ |
| 417 | rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®); |
| 418 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0); |
| 419 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_DMA_BUSY, 0); |
| 420 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0); |
| 421 | rt2x00_set_field32(®, WPDMA_GLO_CFG_RX_DMA_BUSY, 0); |
| 422 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1); |
| 423 | rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg); |
| 424 | |
| 425 | /* |
| 426 | * Write firmware to the device. |
| 427 | */ |
| 428 | rt2800_drv_write_firmware(rt2x00dev, data, len); |
| 429 | |
| 430 | /* |
| 431 | * Wait for device to stabilize. |
| 432 | */ |
| 433 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
| 434 | rt2800_register_read(rt2x00dev, PBF_SYS_CTRL, ®); |
| 435 | if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY)) |
| 436 | break; |
| 437 | msleep(1); |
| 438 | } |
| 439 | |
| 440 | if (i == REGISTER_BUSY_COUNT) { |
| 441 | ERROR(rt2x00dev, "PBF system register not ready.\n"); |
| 442 | return -EBUSY; |
| 443 | } |
| 444 | |
| 445 | /* |
| 446 | * Initialize firmware. |
| 447 | */ |
| 448 | rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0); |
| 449 | rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0); |
| 450 | msleep(1); |
| 451 | |
| 452 | return 0; |
| 453 | } |
| 454 | EXPORT_SYMBOL_GPL(rt2800_load_firmware); |
| 455 | |
Ivo van Doorn | 0c5879b | 2010-08-06 20:47:20 +0200 | [diff] [blame] | 456 | void rt2800_write_tx_data(struct queue_entry *entry, |
| 457 | struct txentry_desc *txdesc) |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 458 | { |
Ivo van Doorn | 0c5879b | 2010-08-06 20:47:20 +0200 | [diff] [blame] | 459 | __le32 *txwi = rt2800_drv_get_txwi(entry); |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 460 | u32 word; |
| 461 | |
| 462 | /* |
| 463 | * Initialize TX Info descriptor |
| 464 | */ |
| 465 | rt2x00_desc_read(txwi, 0, &word); |
| 466 | rt2x00_set_field32(&word, TXWI_W0_FRAG, |
| 467 | test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags)); |
Ivo van Doorn | 84804cd | 2010-08-06 20:46:19 +0200 | [diff] [blame] | 468 | rt2x00_set_field32(&word, TXWI_W0_MIMO_PS, |
| 469 | test_bit(ENTRY_TXD_HT_MIMO_PS, &txdesc->flags)); |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 470 | rt2x00_set_field32(&word, TXWI_W0_CF_ACK, 0); |
| 471 | rt2x00_set_field32(&word, TXWI_W0_TS, |
| 472 | test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags)); |
| 473 | rt2x00_set_field32(&word, TXWI_W0_AMPDU, |
| 474 | test_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags)); |
Helmut Schaa | 26a1d07 | 2011-03-03 19:42:35 +0100 | [diff] [blame] | 475 | rt2x00_set_field32(&word, TXWI_W0_MPDU_DENSITY, |
| 476 | txdesc->u.ht.mpdu_density); |
| 477 | rt2x00_set_field32(&word, TXWI_W0_TX_OP, txdesc->u.ht.txop); |
| 478 | rt2x00_set_field32(&word, TXWI_W0_MCS, txdesc->u.ht.mcs); |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 479 | rt2x00_set_field32(&word, TXWI_W0_BW, |
| 480 | test_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags)); |
| 481 | rt2x00_set_field32(&word, TXWI_W0_SHORT_GI, |
| 482 | test_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags)); |
Helmut Schaa | 26a1d07 | 2011-03-03 19:42:35 +0100 | [diff] [blame] | 483 | rt2x00_set_field32(&word, TXWI_W0_STBC, txdesc->u.ht.stbc); |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 484 | rt2x00_set_field32(&word, TXWI_W0_PHYMODE, txdesc->rate_mode); |
| 485 | rt2x00_desc_write(txwi, 0, word); |
| 486 | |
| 487 | rt2x00_desc_read(txwi, 1, &word); |
| 488 | rt2x00_set_field32(&word, TXWI_W1_ACK, |
| 489 | test_bit(ENTRY_TXD_ACK, &txdesc->flags)); |
| 490 | rt2x00_set_field32(&word, TXWI_W1_NSEQ, |
| 491 | test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags)); |
Helmut Schaa | 26a1d07 | 2011-03-03 19:42:35 +0100 | [diff] [blame] | 492 | rt2x00_set_field32(&word, TXWI_W1_BW_WIN_SIZE, txdesc->u.ht.ba_size); |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 493 | rt2x00_set_field32(&word, TXWI_W1_WIRELESS_CLI_ID, |
| 494 | test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags) ? |
| 495 | txdesc->key_idx : 0xff); |
| 496 | rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT, |
| 497 | txdesc->length); |
Helmut Schaa | 2b23cda | 2010-11-04 20:38:15 +0100 | [diff] [blame] | 498 | rt2x00_set_field32(&word, TXWI_W1_PACKETID_QUEUE, entry->queue->qid); |
Ivo van Doorn | bc8a979 | 2010-10-02 11:32:43 +0200 | [diff] [blame] | 499 | rt2x00_set_field32(&word, TXWI_W1_PACKETID_ENTRY, (entry->entry_idx % 3) + 1); |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 500 | rt2x00_desc_write(txwi, 1, word); |
| 501 | |
| 502 | /* |
| 503 | * Always write 0 to IV/EIV fields, hardware will insert the IV |
| 504 | * from the IVEIV register when TXD_W3_WIV is set to 0. |
| 505 | * When TXD_W3_WIV is set to 1 it will use the IV data |
| 506 | * from the descriptor. The TXWI_W1_WIRELESS_CLI_ID indicates which |
| 507 | * crypto entry in the registers should be used to encrypt the frame. |
| 508 | */ |
| 509 | _rt2x00_desc_write(txwi, 2, 0 /* skbdesc->iv[0] */); |
| 510 | _rt2x00_desc_write(txwi, 3, 0 /* skbdesc->iv[1] */); |
| 511 | } |
Ivo van Doorn | 0c5879b | 2010-08-06 20:47:20 +0200 | [diff] [blame] | 512 | EXPORT_SYMBOL_GPL(rt2800_write_tx_data); |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 513 | |
Helmut Schaa | ff6133b | 2010-10-09 13:34:11 +0200 | [diff] [blame] | 514 | static int rt2800_agc_to_rssi(struct rt2x00_dev *rt2x00dev, u32 rxwi_w2) |
Gertjan van Wingerde | 2de64dd | 2010-05-08 23:40:22 +0200 | [diff] [blame] | 515 | { |
Ivo van Doorn | 7486192 | 2010-07-11 12:23:50 +0200 | [diff] [blame] | 516 | int rssi0 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI0); |
| 517 | int rssi1 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI1); |
| 518 | int rssi2 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI2); |
| 519 | u16 eeprom; |
| 520 | u8 offset0; |
| 521 | u8 offset1; |
| 522 | u8 offset2; |
| 523 | |
Ivo van Doorn | e5ef5ba | 2010-08-06 20:49:27 +0200 | [diff] [blame] | 524 | if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) { |
Ivo van Doorn | 7486192 | 2010-07-11 12:23:50 +0200 | [diff] [blame] | 525 | rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &eeprom); |
| 526 | offset0 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG_OFFSET0); |
| 527 | offset1 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG_OFFSET1); |
| 528 | rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom); |
| 529 | offset2 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG2_OFFSET2); |
| 530 | } else { |
| 531 | rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &eeprom); |
| 532 | offset0 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A_OFFSET0); |
| 533 | offset1 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A_OFFSET1); |
| 534 | rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom); |
| 535 | offset2 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A2_OFFSET2); |
| 536 | } |
| 537 | |
| 538 | /* |
| 539 | * Convert the value from the descriptor into the RSSI value |
| 540 | * If the value in the descriptor is 0, it is considered invalid |
| 541 | * and the default (extremely low) rssi value is assumed |
| 542 | */ |
| 543 | rssi0 = (rssi0) ? (-12 - offset0 - rt2x00dev->lna_gain - rssi0) : -128; |
| 544 | rssi1 = (rssi1) ? (-12 - offset1 - rt2x00dev->lna_gain - rssi1) : -128; |
| 545 | rssi2 = (rssi2) ? (-12 - offset2 - rt2x00dev->lna_gain - rssi2) : -128; |
| 546 | |
| 547 | /* |
| 548 | * mac80211 only accepts a single RSSI value. Calculating the |
| 549 | * average doesn't deliver a fair answer either since -60:-60 would |
| 550 | * be considered equally good as -50:-70 while the second is the one |
| 551 | * which gives less energy... |
| 552 | */ |
| 553 | rssi0 = max(rssi0, rssi1); |
| 554 | return max(rssi0, rssi2); |
| 555 | } |
| 556 | |
| 557 | void rt2800_process_rxwi(struct queue_entry *entry, |
| 558 | struct rxdone_entry_desc *rxdesc) |
| 559 | { |
| 560 | __le32 *rxwi = (__le32 *) entry->skb->data; |
Gertjan van Wingerde | 2de64dd | 2010-05-08 23:40:22 +0200 | [diff] [blame] | 561 | u32 word; |
| 562 | |
| 563 | rt2x00_desc_read(rxwi, 0, &word); |
| 564 | |
| 565 | rxdesc->cipher = rt2x00_get_field32(word, RXWI_W0_UDF); |
| 566 | rxdesc->size = rt2x00_get_field32(word, RXWI_W0_MPDU_TOTAL_BYTE_COUNT); |
| 567 | |
| 568 | rt2x00_desc_read(rxwi, 1, &word); |
| 569 | |
| 570 | if (rt2x00_get_field32(word, RXWI_W1_SHORT_GI)) |
| 571 | rxdesc->flags |= RX_FLAG_SHORT_GI; |
| 572 | |
| 573 | if (rt2x00_get_field32(word, RXWI_W1_BW)) |
| 574 | rxdesc->flags |= RX_FLAG_40MHZ; |
| 575 | |
| 576 | /* |
| 577 | * Detect RX rate, always use MCS as signal type. |
| 578 | */ |
| 579 | rxdesc->dev_flags |= RXDONE_SIGNAL_MCS; |
| 580 | rxdesc->signal = rt2x00_get_field32(word, RXWI_W1_MCS); |
| 581 | rxdesc->rate_mode = rt2x00_get_field32(word, RXWI_W1_PHYMODE); |
| 582 | |
| 583 | /* |
| 584 | * Mask of 0x8 bit to remove the short preamble flag. |
| 585 | */ |
| 586 | if (rxdesc->rate_mode == RATE_MODE_CCK) |
| 587 | rxdesc->signal &= ~0x8; |
| 588 | |
| 589 | rt2x00_desc_read(rxwi, 2, &word); |
| 590 | |
Ivo van Doorn | 7486192 | 2010-07-11 12:23:50 +0200 | [diff] [blame] | 591 | /* |
| 592 | * Convert descriptor AGC value to RSSI value. |
| 593 | */ |
| 594 | rxdesc->rssi = rt2800_agc_to_rssi(entry->queue->rt2x00dev, word); |
Gertjan van Wingerde | 2de64dd | 2010-05-08 23:40:22 +0200 | [diff] [blame] | 595 | |
| 596 | /* |
| 597 | * Remove RXWI descriptor from start of buffer. |
| 598 | */ |
Ivo van Doorn | 7486192 | 2010-07-11 12:23:50 +0200 | [diff] [blame] | 599 | skb_pull(entry->skb, RXWI_DESC_SIZE); |
Gertjan van Wingerde | 2de64dd | 2010-05-08 23:40:22 +0200 | [diff] [blame] | 600 | } |
| 601 | EXPORT_SYMBOL_GPL(rt2800_process_rxwi); |
| 602 | |
Ivo van Doorn | 3613884 | 2010-08-30 21:13:30 +0200 | [diff] [blame] | 603 | static bool rt2800_txdone_entry_check(struct queue_entry *entry, u32 reg) |
| 604 | { |
| 605 | __le32 *txwi; |
| 606 | u32 word; |
| 607 | int wcid, ack, pid; |
| 608 | int tx_wcid, tx_ack, tx_pid; |
| 609 | |
| 610 | wcid = rt2x00_get_field32(reg, TX_STA_FIFO_WCID); |
| 611 | ack = rt2x00_get_field32(reg, TX_STA_FIFO_TX_ACK_REQUIRED); |
| 612 | pid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_TYPE); |
| 613 | |
| 614 | /* |
| 615 | * This frames has returned with an IO error, |
| 616 | * so the status report is not intended for this |
| 617 | * frame. |
| 618 | */ |
| 619 | if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags)) { |
| 620 | rt2x00lib_txdone_noinfo(entry, TXDONE_FAILURE); |
| 621 | return false; |
| 622 | } |
| 623 | |
| 624 | /* |
| 625 | * Validate if this TX status report is intended for |
| 626 | * this entry by comparing the WCID/ACK/PID fields. |
| 627 | */ |
| 628 | txwi = rt2800_drv_get_txwi(entry); |
| 629 | |
| 630 | rt2x00_desc_read(txwi, 1, &word); |
| 631 | tx_wcid = rt2x00_get_field32(word, TXWI_W1_WIRELESS_CLI_ID); |
| 632 | tx_ack = rt2x00_get_field32(word, TXWI_W1_ACK); |
| 633 | tx_pid = rt2x00_get_field32(word, TXWI_W1_PACKETID); |
| 634 | |
| 635 | if ((wcid != tx_wcid) || (ack != tx_ack) || (pid != tx_pid)) { |
| 636 | WARNING(entry->queue->rt2x00dev, |
| 637 | "TX status report missed for queue %d entry %d\n", |
| 638 | entry->queue->qid, entry->entry_idx); |
| 639 | rt2x00lib_txdone_noinfo(entry, TXDONE_UNKNOWN); |
| 640 | return false; |
| 641 | } |
| 642 | |
| 643 | return true; |
| 644 | } |
| 645 | |
Helmut Schaa | 1443333 | 2010-10-02 11:27:03 +0200 | [diff] [blame] | 646 | void rt2800_txdone_entry(struct queue_entry *entry, u32 status) |
| 647 | { |
| 648 | struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; |
Helmut Schaa | b34793e | 2010-10-02 11:34:56 +0200 | [diff] [blame] | 649 | struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); |
Helmut Schaa | 1443333 | 2010-10-02 11:27:03 +0200 | [diff] [blame] | 650 | struct txdone_entry_desc txdesc; |
| 651 | u32 word; |
| 652 | u16 mcs, real_mcs; |
Helmut Schaa | b34793e | 2010-10-02 11:34:56 +0200 | [diff] [blame] | 653 | int aggr, ampdu; |
Helmut Schaa | 1443333 | 2010-10-02 11:27:03 +0200 | [diff] [blame] | 654 | __le32 *txwi; |
| 655 | |
| 656 | /* |
| 657 | * Obtain the status about this packet. |
| 658 | */ |
| 659 | txdesc.flags = 0; |
| 660 | txwi = rt2800_drv_get_txwi(entry); |
| 661 | rt2x00_desc_read(txwi, 0, &word); |
Helmut Schaa | b34793e | 2010-10-02 11:34:56 +0200 | [diff] [blame] | 662 | |
Helmut Schaa | 1443333 | 2010-10-02 11:27:03 +0200 | [diff] [blame] | 663 | mcs = rt2x00_get_field32(word, TXWI_W0_MCS); |
Helmut Schaa | b34793e | 2010-10-02 11:34:56 +0200 | [diff] [blame] | 664 | ampdu = rt2x00_get_field32(word, TXWI_W0_AMPDU); |
| 665 | |
Helmut Schaa | 1443333 | 2010-10-02 11:27:03 +0200 | [diff] [blame] | 666 | real_mcs = rt2x00_get_field32(status, TX_STA_FIFO_MCS); |
Helmut Schaa | b34793e | 2010-10-02 11:34:56 +0200 | [diff] [blame] | 667 | aggr = rt2x00_get_field32(status, TX_STA_FIFO_TX_AGGRE); |
| 668 | |
| 669 | /* |
| 670 | * If a frame was meant to be sent as a single non-aggregated MPDU |
| 671 | * but ended up in an aggregate the used tx rate doesn't correlate |
| 672 | * with the one specified in the TXWI as the whole aggregate is sent |
| 673 | * with the same rate. |
| 674 | * |
| 675 | * For example: two frames are sent to rt2x00, the first one sets |
| 676 | * AMPDU=1 and requests MCS7 whereas the second frame sets AMDPU=0 |
| 677 | * and requests MCS15. If the hw aggregates both frames into one |
| 678 | * AMDPU the tx status for both frames will contain MCS7 although |
| 679 | * the frame was sent successfully. |
| 680 | * |
| 681 | * Hence, replace the requested rate with the real tx rate to not |
| 682 | * confuse the rate control algortihm by providing clearly wrong |
| 683 | * data. |
| 684 | */ |
Helmut Schaa | 5356d96 | 2011-03-03 19:40:33 +0100 | [diff] [blame] | 685 | if (unlikely(aggr == 1 && ampdu == 0 && real_mcs != mcs)) { |
Helmut Schaa | b34793e | 2010-10-02 11:34:56 +0200 | [diff] [blame] | 686 | skbdesc->tx_rate_idx = real_mcs; |
| 687 | mcs = real_mcs; |
| 688 | } |
Helmut Schaa | 1443333 | 2010-10-02 11:27:03 +0200 | [diff] [blame] | 689 | |
| 690 | /* |
| 691 | * Ralink has a retry mechanism using a global fallback |
| 692 | * table. We setup this fallback table to try the immediate |
| 693 | * lower rate for all rates. In the TX_STA_FIFO, the MCS field |
| 694 | * always contains the MCS used for the last transmission, be |
| 695 | * it successful or not. |
| 696 | */ |
| 697 | if (rt2x00_get_field32(status, TX_STA_FIFO_TX_SUCCESS)) { |
| 698 | /* |
| 699 | * Transmission succeeded. The number of retries is |
| 700 | * mcs - real_mcs |
| 701 | */ |
| 702 | __set_bit(TXDONE_SUCCESS, &txdesc.flags); |
| 703 | txdesc.retry = ((mcs > real_mcs) ? mcs - real_mcs : 0); |
| 704 | } else { |
| 705 | /* |
| 706 | * Transmission failed. The number of retries is |
| 707 | * always 7 in this case (for a total number of 8 |
| 708 | * frames sent). |
| 709 | */ |
| 710 | __set_bit(TXDONE_FAILURE, &txdesc.flags); |
| 711 | txdesc.retry = rt2x00dev->long_retry; |
| 712 | } |
| 713 | |
| 714 | /* |
| 715 | * the frame was retried at least once |
| 716 | * -> hw used fallback rates |
| 717 | */ |
| 718 | if (txdesc.retry) |
| 719 | __set_bit(TXDONE_FALLBACK, &txdesc.flags); |
| 720 | |
| 721 | rt2x00lib_txdone(entry, &txdesc); |
| 722 | } |
| 723 | EXPORT_SYMBOL_GPL(rt2800_txdone_entry); |
| 724 | |
Ivo van Doorn | 96481b2 | 2010-08-06 20:47:57 +0200 | [diff] [blame] | 725 | void rt2800_txdone(struct rt2x00_dev *rt2x00dev) |
| 726 | { |
| 727 | struct data_queue *queue; |
| 728 | struct queue_entry *entry; |
Ivo van Doorn | 96481b2 | 2010-08-06 20:47:57 +0200 | [diff] [blame] | 729 | u32 reg; |
Ivo van Doorn | 3613884 | 2010-08-30 21:13:30 +0200 | [diff] [blame] | 730 | u8 pid; |
Ivo van Doorn | 96481b2 | 2010-08-06 20:47:57 +0200 | [diff] [blame] | 731 | int i; |
| 732 | |
| 733 | /* |
| 734 | * TX_STA_FIFO is a stack of X entries, hence read TX_STA_FIFO |
| 735 | * at most X times and also stop processing once the TX_STA_FIFO_VALID |
| 736 | * flag is not set anymore. |
| 737 | * |
| 738 | * The legacy drivers use X=TX_RING_SIZE but state in a comment |
| 739 | * that the TX_STA_FIFO stack has a size of 16. We stick to our |
| 740 | * tx ring size for now. |
| 741 | */ |
Helmut Schaa | efd2f27 | 2010-11-04 20:37:22 +0100 | [diff] [blame] | 742 | for (i = 0; i < rt2x00dev->ops->tx->entry_num; i++) { |
Ivo van Doorn | 96481b2 | 2010-08-06 20:47:57 +0200 | [diff] [blame] | 743 | rt2800_register_read(rt2x00dev, TX_STA_FIFO, ®); |
| 744 | if (!rt2x00_get_field32(reg, TX_STA_FIFO_VALID)) |
| 745 | break; |
| 746 | |
Ivo van Doorn | 96481b2 | 2010-08-06 20:47:57 +0200 | [diff] [blame] | 747 | /* |
| 748 | * Skip this entry when it contains an invalid |
| 749 | * queue identication number. |
| 750 | */ |
Ivo van Doorn | bc8a979 | 2010-10-02 11:32:43 +0200 | [diff] [blame] | 751 | pid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_QUEUE); |
Ivo van Doorn | 3613884 | 2010-08-30 21:13:30 +0200 | [diff] [blame] | 752 | if (pid >= QID_RX) |
Ivo van Doorn | 96481b2 | 2010-08-06 20:47:57 +0200 | [diff] [blame] | 753 | continue; |
| 754 | |
Helmut Schaa | 11f818e | 2011-03-03 19:38:55 +0100 | [diff] [blame] | 755 | queue = rt2x00queue_get_tx_queue(rt2x00dev, pid); |
Ivo van Doorn | 96481b2 | 2010-08-06 20:47:57 +0200 | [diff] [blame] | 756 | if (unlikely(!queue)) |
| 757 | continue; |
| 758 | |
| 759 | /* |
| 760 | * Inside each queue, we process each entry in a chronological |
| 761 | * order. We first check that the queue is not empty. |
| 762 | */ |
| 763 | entry = NULL; |
| 764 | while (!rt2x00queue_empty(queue)) { |
| 765 | entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE); |
Ivo van Doorn | 3613884 | 2010-08-30 21:13:30 +0200 | [diff] [blame] | 766 | if (rt2800_txdone_entry_check(entry, reg)) |
Ivo van Doorn | 96481b2 | 2010-08-06 20:47:57 +0200 | [diff] [blame] | 767 | break; |
Ivo van Doorn | 96481b2 | 2010-08-06 20:47:57 +0200 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | if (!entry || rt2x00queue_empty(queue)) |
| 771 | break; |
| 772 | |
Helmut Schaa | 1443333 | 2010-10-02 11:27:03 +0200 | [diff] [blame] | 773 | rt2800_txdone_entry(entry, reg); |
Ivo van Doorn | 96481b2 | 2010-08-06 20:47:57 +0200 | [diff] [blame] | 774 | } |
| 775 | } |
| 776 | EXPORT_SYMBOL_GPL(rt2800_txdone); |
| 777 | |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 778 | void rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc) |
| 779 | { |
| 780 | struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; |
| 781 | struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); |
| 782 | unsigned int beacon_base; |
Wolfgang Kufner | 739fd94 | 2010-12-13 12:39:12 +0100 | [diff] [blame] | 783 | unsigned int padding_len; |
Seth Forshee | d76dfc6 | 2011-02-14 08:52:25 -0600 | [diff] [blame] | 784 | u32 orig_reg, reg; |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 785 | |
| 786 | /* |
| 787 | * Disable beaconing while we are reloading the beacon data, |
| 788 | * otherwise we might be sending out invalid data. |
| 789 | */ |
| 790 | rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®); |
Seth Forshee | d76dfc6 | 2011-02-14 08:52:25 -0600 | [diff] [blame] | 791 | orig_reg = reg; |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 792 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 0); |
| 793 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
| 794 | |
| 795 | /* |
| 796 | * Add space for the TXWI in front of the skb. |
| 797 | */ |
| 798 | skb_push(entry->skb, TXWI_DESC_SIZE); |
| 799 | memset(entry->skb, 0, TXWI_DESC_SIZE); |
| 800 | |
| 801 | /* |
| 802 | * Register descriptor details in skb frame descriptor. |
| 803 | */ |
| 804 | skbdesc->flags |= SKBDESC_DESC_IN_SKB; |
| 805 | skbdesc->desc = entry->skb->data; |
| 806 | skbdesc->desc_len = TXWI_DESC_SIZE; |
| 807 | |
| 808 | /* |
| 809 | * Add the TXWI for the beacon to the skb. |
| 810 | */ |
Ivo van Doorn | 0c5879b | 2010-08-06 20:47:20 +0200 | [diff] [blame] | 811 | rt2800_write_tx_data(entry, txdesc); |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 812 | |
| 813 | /* |
| 814 | * Dump beacon to userspace through debugfs. |
| 815 | */ |
| 816 | rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry->skb); |
| 817 | |
| 818 | /* |
Wolfgang Kufner | 739fd94 | 2010-12-13 12:39:12 +0100 | [diff] [blame] | 819 | * Write entire beacon with TXWI and padding to register. |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 820 | */ |
Wolfgang Kufner | 739fd94 | 2010-12-13 12:39:12 +0100 | [diff] [blame] | 821 | padding_len = roundup(entry->skb->len, 4) - entry->skb->len; |
Seth Forshee | d76dfc6 | 2011-02-14 08:52:25 -0600 | [diff] [blame] | 822 | if (padding_len && skb_pad(entry->skb, padding_len)) { |
| 823 | ERROR(rt2x00dev, "Failure padding beacon, aborting\n"); |
| 824 | /* skb freed by skb_pad() on failure */ |
| 825 | entry->skb = NULL; |
| 826 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, orig_reg); |
| 827 | return; |
| 828 | } |
| 829 | |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 830 | beacon_base = HW_BEACON_OFFSET(entry->entry_idx); |
Wolfgang Kufner | 739fd94 | 2010-12-13 12:39:12 +0100 | [diff] [blame] | 831 | rt2800_register_multiwrite(rt2x00dev, beacon_base, entry->skb->data, |
| 832 | entry->skb->len + padding_len); |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 833 | |
| 834 | /* |
| 835 | * Enable beaconing again. |
| 836 | */ |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 837 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 1); |
| 838 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
| 839 | |
| 840 | /* |
| 841 | * Clean up beacon skb. |
| 842 | */ |
| 843 | dev_kfree_skb_any(entry->skb); |
| 844 | entry->skb = NULL; |
| 845 | } |
Ivo van Doorn | 50e888e | 2010-07-11 12:26:12 +0200 | [diff] [blame] | 846 | EXPORT_SYMBOL_GPL(rt2800_write_beacon); |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 847 | |
Helmut Schaa | 69cf36a | 2011-01-30 13:16:03 +0100 | [diff] [blame] | 848 | static inline void rt2800_clear_beacon_register(struct rt2x00_dev *rt2x00dev, |
| 849 | unsigned int beacon_base) |
Helmut Schaa | fdb8725 | 2010-06-29 21:48:06 +0200 | [diff] [blame] | 850 | { |
| 851 | int i; |
| 852 | |
| 853 | /* |
| 854 | * For the Beacon base registers we only need to clear |
| 855 | * the whole TXWI which (when set to 0) will invalidate |
| 856 | * the entire beacon. |
| 857 | */ |
| 858 | for (i = 0; i < TXWI_DESC_SIZE; i += sizeof(__le32)) |
| 859 | rt2800_register_write(rt2x00dev, beacon_base + i, 0); |
| 860 | } |
| 861 | |
Helmut Schaa | 69cf36a | 2011-01-30 13:16:03 +0100 | [diff] [blame] | 862 | void rt2800_clear_beacon(struct queue_entry *entry) |
| 863 | { |
| 864 | struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; |
| 865 | u32 reg; |
| 866 | |
| 867 | /* |
| 868 | * Disable beaconing while we are reloading the beacon data, |
| 869 | * otherwise we might be sending out invalid data. |
| 870 | */ |
| 871 | rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®); |
| 872 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 0); |
| 873 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
| 874 | |
| 875 | /* |
| 876 | * Clear beacon. |
| 877 | */ |
| 878 | rt2800_clear_beacon_register(rt2x00dev, |
| 879 | HW_BEACON_OFFSET(entry->entry_idx)); |
| 880 | |
| 881 | /* |
| 882 | * Enabled beaconing again. |
| 883 | */ |
| 884 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 1); |
| 885 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
| 886 | } |
| 887 | EXPORT_SYMBOL_GPL(rt2800_clear_beacon); |
| 888 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 889 | #ifdef CONFIG_RT2X00_LIB_DEBUGFS |
| 890 | const struct rt2x00debug rt2800_rt2x00debug = { |
| 891 | .owner = THIS_MODULE, |
| 892 | .csr = { |
| 893 | .read = rt2800_register_read, |
| 894 | .write = rt2800_register_write, |
| 895 | .flags = RT2X00DEBUGFS_OFFSET, |
| 896 | .word_base = CSR_REG_BASE, |
| 897 | .word_size = sizeof(u32), |
| 898 | .word_count = CSR_REG_SIZE / sizeof(u32), |
| 899 | }, |
| 900 | .eeprom = { |
| 901 | .read = rt2x00_eeprom_read, |
| 902 | .write = rt2x00_eeprom_write, |
| 903 | .word_base = EEPROM_BASE, |
| 904 | .word_size = sizeof(u16), |
| 905 | .word_count = EEPROM_SIZE / sizeof(u16), |
| 906 | }, |
| 907 | .bbp = { |
| 908 | .read = rt2800_bbp_read, |
| 909 | .write = rt2800_bbp_write, |
| 910 | .word_base = BBP_BASE, |
| 911 | .word_size = sizeof(u8), |
| 912 | .word_count = BBP_SIZE / sizeof(u8), |
| 913 | }, |
| 914 | .rf = { |
| 915 | .read = rt2x00_rf_read, |
| 916 | .write = rt2800_rf_write, |
| 917 | .word_base = RF_BASE, |
| 918 | .word_size = sizeof(u32), |
| 919 | .word_count = RF_SIZE / sizeof(u32), |
| 920 | }, |
| 921 | }; |
| 922 | EXPORT_SYMBOL_GPL(rt2800_rt2x00debug); |
| 923 | #endif /* CONFIG_RT2X00_LIB_DEBUGFS */ |
| 924 | |
| 925 | int rt2800_rfkill_poll(struct rt2x00_dev *rt2x00dev) |
| 926 | { |
| 927 | u32 reg; |
| 928 | |
| 929 | rt2800_register_read(rt2x00dev, GPIO_CTRL_CFG, ®); |
| 930 | return rt2x00_get_field32(reg, GPIO_CTRL_CFG_BIT2); |
| 931 | } |
| 932 | EXPORT_SYMBOL_GPL(rt2800_rfkill_poll); |
| 933 | |
| 934 | #ifdef CONFIG_RT2X00_LIB_LEDS |
| 935 | static void rt2800_brightness_set(struct led_classdev *led_cdev, |
| 936 | enum led_brightness brightness) |
| 937 | { |
| 938 | struct rt2x00_led *led = |
| 939 | container_of(led_cdev, struct rt2x00_led, led_dev); |
| 940 | unsigned int enabled = brightness != LED_OFF; |
| 941 | unsigned int bg_mode = |
| 942 | (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_2GHZ); |
| 943 | unsigned int polarity = |
| 944 | rt2x00_get_field16(led->rt2x00dev->led_mcu_reg, |
| 945 | EEPROM_FREQ_LED_POLARITY); |
| 946 | unsigned int ledmode = |
| 947 | rt2x00_get_field16(led->rt2x00dev->led_mcu_reg, |
| 948 | EEPROM_FREQ_LED_MODE); |
| 949 | |
| 950 | if (led->type == LED_TYPE_RADIO) { |
| 951 | rt2800_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode, |
| 952 | enabled ? 0x20 : 0); |
| 953 | } else if (led->type == LED_TYPE_ASSOC) { |
| 954 | rt2800_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode, |
| 955 | enabled ? (bg_mode ? 0x60 : 0xa0) : 0x20); |
| 956 | } else if (led->type == LED_TYPE_QUALITY) { |
| 957 | /* |
| 958 | * The brightness is divided into 6 levels (0 - 5), |
| 959 | * The specs tell us the following levels: |
| 960 | * 0, 1 ,3, 7, 15, 31 |
| 961 | * to determine the level in a simple way we can simply |
| 962 | * work with bitshifting: |
| 963 | * (1 << level) - 1 |
| 964 | */ |
| 965 | rt2800_mcu_request(led->rt2x00dev, MCU_LED_STRENGTH, 0xff, |
| 966 | (1 << brightness / (LED_FULL / 6)) - 1, |
| 967 | polarity); |
| 968 | } |
| 969 | } |
| 970 | |
| 971 | static int rt2800_blink_set(struct led_classdev *led_cdev, |
| 972 | unsigned long *delay_on, unsigned long *delay_off) |
| 973 | { |
| 974 | struct rt2x00_led *led = |
| 975 | container_of(led_cdev, struct rt2x00_led, led_dev); |
| 976 | u32 reg; |
| 977 | |
| 978 | rt2800_register_read(led->rt2x00dev, LED_CFG, ®); |
| 979 | rt2x00_set_field32(®, LED_CFG_ON_PERIOD, *delay_on); |
| 980 | rt2x00_set_field32(®, LED_CFG_OFF_PERIOD, *delay_off); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 981 | rt2800_register_write(led->rt2x00dev, LED_CFG, reg); |
| 982 | |
| 983 | return 0; |
| 984 | } |
| 985 | |
Gertjan van Wingerde | b3579d6 | 2009-12-30 11:36:34 +0100 | [diff] [blame] | 986 | static void rt2800_init_led(struct rt2x00_dev *rt2x00dev, |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 987 | struct rt2x00_led *led, enum led_type type) |
| 988 | { |
| 989 | led->rt2x00dev = rt2x00dev; |
| 990 | led->type = type; |
| 991 | led->led_dev.brightness_set = rt2800_brightness_set; |
| 992 | led->led_dev.blink_set = rt2800_blink_set; |
| 993 | led->flags = LED_INITIALIZED; |
| 994 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 995 | #endif /* CONFIG_RT2X00_LIB_LEDS */ |
| 996 | |
| 997 | /* |
| 998 | * Configuration handlers. |
| 999 | */ |
| 1000 | static void rt2800_config_wcid_attr(struct rt2x00_dev *rt2x00dev, |
| 1001 | struct rt2x00lib_crypto *crypto, |
| 1002 | struct ieee80211_key_conf *key) |
| 1003 | { |
| 1004 | struct mac_wcid_entry wcid_entry; |
| 1005 | struct mac_iveiv_entry iveiv_entry; |
| 1006 | u32 offset; |
| 1007 | u32 reg; |
| 1008 | |
| 1009 | offset = MAC_WCID_ATTR_ENTRY(key->hw_key_idx); |
| 1010 | |
Ivo van Doorn | e4a0ab3 | 2010-06-14 22:14:19 +0200 | [diff] [blame] | 1011 | if (crypto->cmd == SET_KEY) { |
| 1012 | rt2800_register_read(rt2x00dev, offset, ®); |
| 1013 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_KEYTAB, |
| 1014 | !!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)); |
| 1015 | /* |
| 1016 | * Both the cipher as the BSS Idx numbers are split in a main |
| 1017 | * value of 3 bits, and a extended field for adding one additional |
| 1018 | * bit to the value. |
| 1019 | */ |
| 1020 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_CIPHER, |
| 1021 | (crypto->cipher & 0x7)); |
| 1022 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_CIPHER_EXT, |
| 1023 | (crypto->cipher & 0x8) >> 3); |
| 1024 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_BSS_IDX, |
| 1025 | (crypto->bssidx & 0x7)); |
| 1026 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_BSS_IDX_EXT, |
| 1027 | (crypto->bssidx & 0x8) >> 3); |
| 1028 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_RX_WIUDF, crypto->cipher); |
| 1029 | rt2800_register_write(rt2x00dev, offset, reg); |
| 1030 | } else { |
| 1031 | rt2800_register_write(rt2x00dev, offset, 0); |
| 1032 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1033 | |
| 1034 | offset = MAC_IVEIV_ENTRY(key->hw_key_idx); |
| 1035 | |
| 1036 | memset(&iveiv_entry, 0, sizeof(iveiv_entry)); |
| 1037 | if ((crypto->cipher == CIPHER_TKIP) || |
| 1038 | (crypto->cipher == CIPHER_TKIP_NO_MIC) || |
| 1039 | (crypto->cipher == CIPHER_AES)) |
| 1040 | iveiv_entry.iv[3] |= 0x20; |
| 1041 | iveiv_entry.iv[3] |= key->keyidx << 6; |
| 1042 | rt2800_register_multiwrite(rt2x00dev, offset, |
| 1043 | &iveiv_entry, sizeof(iveiv_entry)); |
| 1044 | |
| 1045 | offset = MAC_WCID_ENTRY(key->hw_key_idx); |
| 1046 | |
| 1047 | memset(&wcid_entry, 0, sizeof(wcid_entry)); |
| 1048 | if (crypto->cmd == SET_KEY) |
Gertjan van Wingerde | 10026f7 | 2011-01-30 13:23:03 +0100 | [diff] [blame] | 1049 | memcpy(wcid_entry.mac, crypto->address, ETH_ALEN); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1050 | rt2800_register_multiwrite(rt2x00dev, offset, |
| 1051 | &wcid_entry, sizeof(wcid_entry)); |
| 1052 | } |
| 1053 | |
| 1054 | int rt2800_config_shared_key(struct rt2x00_dev *rt2x00dev, |
| 1055 | struct rt2x00lib_crypto *crypto, |
| 1056 | struct ieee80211_key_conf *key) |
| 1057 | { |
| 1058 | struct hw_key_entry key_entry; |
| 1059 | struct rt2x00_field32 field; |
| 1060 | u32 offset; |
| 1061 | u32 reg; |
| 1062 | |
| 1063 | if (crypto->cmd == SET_KEY) { |
| 1064 | key->hw_key_idx = (4 * crypto->bssidx) + key->keyidx; |
| 1065 | |
| 1066 | memcpy(key_entry.key, crypto->key, |
| 1067 | sizeof(key_entry.key)); |
| 1068 | memcpy(key_entry.tx_mic, crypto->tx_mic, |
| 1069 | sizeof(key_entry.tx_mic)); |
| 1070 | memcpy(key_entry.rx_mic, crypto->rx_mic, |
| 1071 | sizeof(key_entry.rx_mic)); |
| 1072 | |
| 1073 | offset = SHARED_KEY_ENTRY(key->hw_key_idx); |
| 1074 | rt2800_register_multiwrite(rt2x00dev, offset, |
| 1075 | &key_entry, sizeof(key_entry)); |
| 1076 | } |
| 1077 | |
| 1078 | /* |
| 1079 | * The cipher types are stored over multiple registers |
| 1080 | * starting with SHARED_KEY_MODE_BASE each word will have |
| 1081 | * 32 bits and contains the cipher types for 2 bssidx each. |
| 1082 | * Using the correct defines correctly will cause overhead, |
| 1083 | * so just calculate the correct offset. |
| 1084 | */ |
| 1085 | field.bit_offset = 4 * (key->hw_key_idx % 8); |
| 1086 | field.bit_mask = 0x7 << field.bit_offset; |
| 1087 | |
| 1088 | offset = SHARED_KEY_MODE_ENTRY(key->hw_key_idx / 8); |
| 1089 | |
| 1090 | rt2800_register_read(rt2x00dev, offset, ®); |
| 1091 | rt2x00_set_field32(®, field, |
| 1092 | (crypto->cmd == SET_KEY) * crypto->cipher); |
| 1093 | rt2800_register_write(rt2x00dev, offset, reg); |
| 1094 | |
| 1095 | /* |
| 1096 | * Update WCID information |
| 1097 | */ |
| 1098 | rt2800_config_wcid_attr(rt2x00dev, crypto, key); |
| 1099 | |
| 1100 | return 0; |
| 1101 | } |
| 1102 | EXPORT_SYMBOL_GPL(rt2800_config_shared_key); |
| 1103 | |
Helmut Schaa | 1ed3811 | 2011-03-03 19:44:33 +0100 | [diff] [blame] | 1104 | static inline int rt2800_find_pairwise_keyslot(struct rt2x00_dev *rt2x00dev) |
| 1105 | { |
| 1106 | int idx; |
| 1107 | u32 offset, reg; |
| 1108 | |
| 1109 | /* |
| 1110 | * Search for the first free pairwise key entry and return the |
| 1111 | * corresponding index. |
| 1112 | * |
| 1113 | * Make sure the WCID starts _after_ the last possible shared key |
| 1114 | * entry (>32). |
| 1115 | * |
| 1116 | * Since parts of the pairwise key table might be shared with |
| 1117 | * the beacon frame buffers 6 & 7 we should only write into the |
| 1118 | * first 222 entries. |
| 1119 | */ |
| 1120 | for (idx = 33; idx <= 222; idx++) { |
| 1121 | offset = MAC_WCID_ATTR_ENTRY(idx); |
| 1122 | rt2800_register_read(rt2x00dev, offset, ®); |
| 1123 | if (!reg) |
| 1124 | return idx; |
| 1125 | } |
| 1126 | return -1; |
| 1127 | } |
| 1128 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1129 | int rt2800_config_pairwise_key(struct rt2x00_dev *rt2x00dev, |
| 1130 | struct rt2x00lib_crypto *crypto, |
| 1131 | struct ieee80211_key_conf *key) |
| 1132 | { |
| 1133 | struct hw_key_entry key_entry; |
| 1134 | u32 offset; |
Helmut Schaa | 1ed3811 | 2011-03-03 19:44:33 +0100 | [diff] [blame] | 1135 | int idx; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1136 | |
| 1137 | if (crypto->cmd == SET_KEY) { |
Helmut Schaa | 1ed3811 | 2011-03-03 19:44:33 +0100 | [diff] [blame] | 1138 | idx = rt2800_find_pairwise_keyslot(rt2x00dev); |
| 1139 | if (idx < 0) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1140 | return -ENOSPC; |
Helmut Schaa | 1ed3811 | 2011-03-03 19:44:33 +0100 | [diff] [blame] | 1141 | key->hw_key_idx = idx; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1142 | |
| 1143 | memcpy(key_entry.key, crypto->key, |
| 1144 | sizeof(key_entry.key)); |
| 1145 | memcpy(key_entry.tx_mic, crypto->tx_mic, |
| 1146 | sizeof(key_entry.tx_mic)); |
| 1147 | memcpy(key_entry.rx_mic, crypto->rx_mic, |
| 1148 | sizeof(key_entry.rx_mic)); |
| 1149 | |
| 1150 | offset = PAIRWISE_KEY_ENTRY(key->hw_key_idx); |
| 1151 | rt2800_register_multiwrite(rt2x00dev, offset, |
| 1152 | &key_entry, sizeof(key_entry)); |
| 1153 | } |
| 1154 | |
| 1155 | /* |
| 1156 | * Update WCID information |
| 1157 | */ |
| 1158 | rt2800_config_wcid_attr(rt2x00dev, crypto, key); |
| 1159 | |
| 1160 | return 0; |
| 1161 | } |
| 1162 | EXPORT_SYMBOL_GPL(rt2800_config_pairwise_key); |
| 1163 | |
| 1164 | void rt2800_config_filter(struct rt2x00_dev *rt2x00dev, |
| 1165 | const unsigned int filter_flags) |
| 1166 | { |
| 1167 | u32 reg; |
| 1168 | |
| 1169 | /* |
| 1170 | * Start configuration steps. |
| 1171 | * Note that the version error will always be dropped |
| 1172 | * and broadcast frames will always be accepted since |
| 1173 | * there is no filter for it at this time. |
| 1174 | */ |
| 1175 | rt2800_register_read(rt2x00dev, RX_FILTER_CFG, ®); |
| 1176 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CRC_ERROR, |
| 1177 | !(filter_flags & FIF_FCSFAIL)); |
| 1178 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_PHY_ERROR, |
| 1179 | !(filter_flags & FIF_PLCPFAIL)); |
| 1180 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_NOT_TO_ME, |
| 1181 | !(filter_flags & FIF_PROMISC_IN_BSS)); |
| 1182 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_NOT_MY_BSSD, 0); |
| 1183 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_VER_ERROR, 1); |
| 1184 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_MULTICAST, |
| 1185 | !(filter_flags & FIF_ALLMULTI)); |
| 1186 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_BROADCAST, 0); |
| 1187 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_DUPLICATE, 1); |
| 1188 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CF_END_ACK, |
| 1189 | !(filter_flags & FIF_CONTROL)); |
| 1190 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CF_END, |
| 1191 | !(filter_flags & FIF_CONTROL)); |
| 1192 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_ACK, |
| 1193 | !(filter_flags & FIF_CONTROL)); |
| 1194 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CTS, |
| 1195 | !(filter_flags & FIF_CONTROL)); |
| 1196 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_RTS, |
| 1197 | !(filter_flags & FIF_CONTROL)); |
| 1198 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_PSPOLL, |
| 1199 | !(filter_flags & FIF_PSPOLL)); |
| 1200 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_BA, 1); |
| 1201 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_BAR, 0); |
| 1202 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CNTL, |
| 1203 | !(filter_flags & FIF_CONTROL)); |
| 1204 | rt2800_register_write(rt2x00dev, RX_FILTER_CFG, reg); |
| 1205 | } |
| 1206 | EXPORT_SYMBOL_GPL(rt2800_config_filter); |
| 1207 | |
| 1208 | void rt2800_config_intf(struct rt2x00_dev *rt2x00dev, struct rt2x00_intf *intf, |
| 1209 | struct rt2x00intf_conf *conf, const unsigned int flags) |
| 1210 | { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1211 | u32 reg; |
Helmut Schaa | fa8b4b2 | 2010-11-04 20:42:36 +0100 | [diff] [blame] | 1212 | bool update_bssid = false; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1213 | |
| 1214 | if (flags & CONFIG_UPDATE_TYPE) { |
| 1215 | /* |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1216 | * Enable synchronisation. |
| 1217 | */ |
| 1218 | rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1219 | rt2x00_set_field32(®, BCN_TIME_CFG_TSF_SYNC, conf->sync); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1220 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
| 1221 | } |
| 1222 | |
| 1223 | if (flags & CONFIG_UPDATE_MAC) { |
Helmut Schaa | fa8b4b2 | 2010-11-04 20:42:36 +0100 | [diff] [blame] | 1224 | if (flags & CONFIG_UPDATE_TYPE && |
| 1225 | conf->sync == TSF_SYNC_AP_NONE) { |
| 1226 | /* |
| 1227 | * The BSSID register has to be set to our own mac |
| 1228 | * address in AP mode. |
| 1229 | */ |
| 1230 | memcpy(conf->bssid, conf->mac, sizeof(conf->mac)); |
| 1231 | update_bssid = true; |
| 1232 | } |
| 1233 | |
Ivo van Doorn | c600c82 | 2010-08-30 21:14:15 +0200 | [diff] [blame] | 1234 | if (!is_zero_ether_addr((const u8 *)conf->mac)) { |
| 1235 | reg = le32_to_cpu(conf->mac[1]); |
| 1236 | rt2x00_set_field32(®, MAC_ADDR_DW1_UNICAST_TO_ME_MASK, 0xff); |
| 1237 | conf->mac[1] = cpu_to_le32(reg); |
| 1238 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1239 | |
| 1240 | rt2800_register_multiwrite(rt2x00dev, MAC_ADDR_DW0, |
| 1241 | conf->mac, sizeof(conf->mac)); |
| 1242 | } |
| 1243 | |
Helmut Schaa | fa8b4b2 | 2010-11-04 20:42:36 +0100 | [diff] [blame] | 1244 | if ((flags & CONFIG_UPDATE_BSSID) || update_bssid) { |
Ivo van Doorn | c600c82 | 2010-08-30 21:14:15 +0200 | [diff] [blame] | 1245 | if (!is_zero_ether_addr((const u8 *)conf->bssid)) { |
| 1246 | reg = le32_to_cpu(conf->bssid[1]); |
| 1247 | rt2x00_set_field32(®, MAC_BSSID_DW1_BSS_ID_MASK, 3); |
| 1248 | rt2x00_set_field32(®, MAC_BSSID_DW1_BSS_BCN_NUM, 7); |
| 1249 | conf->bssid[1] = cpu_to_le32(reg); |
| 1250 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1251 | |
| 1252 | rt2800_register_multiwrite(rt2x00dev, MAC_BSSID_DW0, |
| 1253 | conf->bssid, sizeof(conf->bssid)); |
| 1254 | } |
| 1255 | } |
| 1256 | EXPORT_SYMBOL_GPL(rt2800_config_intf); |
| 1257 | |
Helmut Schaa | 87c1915 | 2010-10-02 11:28:34 +0200 | [diff] [blame] | 1258 | static void rt2800_config_ht_opmode(struct rt2x00_dev *rt2x00dev, |
| 1259 | struct rt2x00lib_erp *erp) |
| 1260 | { |
| 1261 | bool any_sta_nongf = !!(erp->ht_opmode & |
| 1262 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT); |
| 1263 | u8 protection = erp->ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION; |
| 1264 | u8 mm20_mode, mm40_mode, gf20_mode, gf40_mode; |
| 1265 | u16 mm20_rate, mm40_rate, gf20_rate, gf40_rate; |
| 1266 | u32 reg; |
| 1267 | |
| 1268 | /* default protection rate for HT20: OFDM 24M */ |
| 1269 | mm20_rate = gf20_rate = 0x4004; |
| 1270 | |
| 1271 | /* default protection rate for HT40: duplicate OFDM 24M */ |
| 1272 | mm40_rate = gf40_rate = 0x4084; |
| 1273 | |
| 1274 | switch (protection) { |
| 1275 | case IEEE80211_HT_OP_MODE_PROTECTION_NONE: |
| 1276 | /* |
| 1277 | * All STAs in this BSS are HT20/40 but there might be |
| 1278 | * STAs not supporting greenfield mode. |
| 1279 | * => Disable protection for HT transmissions. |
| 1280 | */ |
| 1281 | mm20_mode = mm40_mode = gf20_mode = gf40_mode = 0; |
| 1282 | |
| 1283 | break; |
| 1284 | case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ: |
| 1285 | /* |
| 1286 | * All STAs in this BSS are HT20 or HT20/40 but there |
| 1287 | * might be STAs not supporting greenfield mode. |
| 1288 | * => Protect all HT40 transmissions. |
| 1289 | */ |
| 1290 | mm20_mode = gf20_mode = 0; |
| 1291 | mm40_mode = gf40_mode = 2; |
| 1292 | |
| 1293 | break; |
| 1294 | case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER: |
| 1295 | /* |
| 1296 | * Nonmember protection: |
| 1297 | * According to 802.11n we _should_ protect all |
| 1298 | * HT transmissions (but we don't have to). |
| 1299 | * |
| 1300 | * But if cts_protection is enabled we _shall_ protect |
| 1301 | * all HT transmissions using a CCK rate. |
| 1302 | * |
| 1303 | * And if any station is non GF we _shall_ protect |
| 1304 | * GF transmissions. |
| 1305 | * |
| 1306 | * We decide to protect everything |
| 1307 | * -> fall through to mixed mode. |
| 1308 | */ |
| 1309 | case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED: |
| 1310 | /* |
| 1311 | * Legacy STAs are present |
| 1312 | * => Protect all HT transmissions. |
| 1313 | */ |
| 1314 | mm20_mode = mm40_mode = gf20_mode = gf40_mode = 2; |
| 1315 | |
| 1316 | /* |
| 1317 | * If erp protection is needed we have to protect HT |
| 1318 | * transmissions with CCK 11M long preamble. |
| 1319 | */ |
| 1320 | if (erp->cts_protection) { |
| 1321 | /* don't duplicate RTS/CTS in CCK mode */ |
| 1322 | mm20_rate = mm40_rate = 0x0003; |
| 1323 | gf20_rate = gf40_rate = 0x0003; |
| 1324 | } |
| 1325 | break; |
| 1326 | }; |
| 1327 | |
| 1328 | /* check for STAs not supporting greenfield mode */ |
| 1329 | if (any_sta_nongf) |
| 1330 | gf20_mode = gf40_mode = 2; |
| 1331 | |
| 1332 | /* Update HT protection config */ |
| 1333 | rt2800_register_read(rt2x00dev, MM20_PROT_CFG, ®); |
| 1334 | rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_RATE, mm20_rate); |
| 1335 | rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_CTRL, mm20_mode); |
| 1336 | rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg); |
| 1337 | |
| 1338 | rt2800_register_read(rt2x00dev, MM40_PROT_CFG, ®); |
| 1339 | rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_RATE, mm40_rate); |
| 1340 | rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_CTRL, mm40_mode); |
| 1341 | rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg); |
| 1342 | |
| 1343 | rt2800_register_read(rt2x00dev, GF20_PROT_CFG, ®); |
| 1344 | rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_RATE, gf20_rate); |
| 1345 | rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_CTRL, gf20_mode); |
| 1346 | rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg); |
| 1347 | |
| 1348 | rt2800_register_read(rt2x00dev, GF40_PROT_CFG, ®); |
| 1349 | rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_RATE, gf40_rate); |
| 1350 | rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_CTRL, gf40_mode); |
| 1351 | rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg); |
| 1352 | } |
| 1353 | |
Helmut Schaa | 0204464 | 2010-09-08 20:56:32 +0200 | [diff] [blame] | 1354 | void rt2800_config_erp(struct rt2x00_dev *rt2x00dev, struct rt2x00lib_erp *erp, |
| 1355 | u32 changed) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1356 | { |
| 1357 | u32 reg; |
| 1358 | |
Helmut Schaa | 0204464 | 2010-09-08 20:56:32 +0200 | [diff] [blame] | 1359 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
| 1360 | rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, ®); |
| 1361 | rt2x00_set_field32(®, AUTO_RSP_CFG_BAC_ACK_POLICY, |
| 1362 | !!erp->short_preamble); |
| 1363 | rt2x00_set_field32(®, AUTO_RSP_CFG_AR_PREAMBLE, |
| 1364 | !!erp->short_preamble); |
| 1365 | rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg); |
| 1366 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1367 | |
Helmut Schaa | 0204464 | 2010-09-08 20:56:32 +0200 | [diff] [blame] | 1368 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
| 1369 | rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, ®); |
| 1370 | rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_CTRL, |
| 1371 | erp->cts_protection ? 2 : 0); |
| 1372 | rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg); |
| 1373 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1374 | |
Helmut Schaa | 0204464 | 2010-09-08 20:56:32 +0200 | [diff] [blame] | 1375 | if (changed & BSS_CHANGED_BASIC_RATES) { |
| 1376 | rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE, |
| 1377 | erp->basic_rates); |
| 1378 | rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003); |
| 1379 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1380 | |
Helmut Schaa | 0204464 | 2010-09-08 20:56:32 +0200 | [diff] [blame] | 1381 | if (changed & BSS_CHANGED_ERP_SLOT) { |
| 1382 | rt2800_register_read(rt2x00dev, BKOFF_SLOT_CFG, ®); |
| 1383 | rt2x00_set_field32(®, BKOFF_SLOT_CFG_SLOT_TIME, |
| 1384 | erp->slot_time); |
| 1385 | rt2800_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1386 | |
Helmut Schaa | 0204464 | 2010-09-08 20:56:32 +0200 | [diff] [blame] | 1387 | rt2800_register_read(rt2x00dev, XIFS_TIME_CFG, ®); |
| 1388 | rt2x00_set_field32(®, XIFS_TIME_CFG_EIFS, erp->eifs); |
| 1389 | rt2800_register_write(rt2x00dev, XIFS_TIME_CFG, reg); |
| 1390 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1391 | |
Helmut Schaa | 0204464 | 2010-09-08 20:56:32 +0200 | [diff] [blame] | 1392 | if (changed & BSS_CHANGED_BEACON_INT) { |
| 1393 | rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®); |
| 1394 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_INTERVAL, |
| 1395 | erp->beacon_int * 16); |
| 1396 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
| 1397 | } |
Helmut Schaa | 87c1915 | 2010-10-02 11:28:34 +0200 | [diff] [blame] | 1398 | |
| 1399 | if (changed & BSS_CHANGED_HT) |
| 1400 | rt2800_config_ht_opmode(rt2x00dev, erp); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1401 | } |
| 1402 | EXPORT_SYMBOL_GPL(rt2800_config_erp); |
| 1403 | |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1404 | static void rt2800_set_ant_diversity(struct rt2x00_dev *rt2x00dev, |
| 1405 | enum antenna ant) |
| 1406 | { |
| 1407 | u32 reg; |
| 1408 | u8 eesk_pin = (ant == ANTENNA_A) ? 1 : 0; |
| 1409 | u8 gpio_bit3 = (ant == ANTENNA_A) ? 0 : 1; |
| 1410 | |
| 1411 | if (rt2x00_is_pci(rt2x00dev)) { |
| 1412 | rt2800_register_read(rt2x00dev, E2PROM_CSR, ®); |
| 1413 | rt2x00_set_field32(®, E2PROM_CSR_DATA_CLOCK, eesk_pin); |
| 1414 | rt2800_register_write(rt2x00dev, E2PROM_CSR, reg); |
| 1415 | } else if (rt2x00_is_usb(rt2x00dev)) |
| 1416 | rt2800_mcu_request(rt2x00dev, MCU_ANT_SELECT, 0xff, |
| 1417 | eesk_pin, 0); |
| 1418 | |
| 1419 | rt2800_register_read(rt2x00dev, GPIO_CTRL_CFG, ®); |
Shiang Tu | fe59147 | 2011-02-20 13:57:22 +0100 | [diff] [blame] | 1420 | rt2x00_set_field32(®, GPIO_CTRL_CFG_GPIOD_BIT3, 0); |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1421 | rt2x00_set_field32(®, GPIO_CTRL_CFG_BIT3, gpio_bit3); |
| 1422 | rt2800_register_write(rt2x00dev, GPIO_CTRL_CFG, reg); |
| 1423 | } |
| 1424 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1425 | void rt2800_config_ant(struct rt2x00_dev *rt2x00dev, struct antenna_setup *ant) |
| 1426 | { |
| 1427 | u8 r1; |
| 1428 | u8 r3; |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1429 | u16 eeprom; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1430 | |
| 1431 | rt2800_bbp_read(rt2x00dev, 1, &r1); |
| 1432 | rt2800_bbp_read(rt2x00dev, 3, &r3); |
| 1433 | |
| 1434 | /* |
| 1435 | * Configure the TX antenna. |
| 1436 | */ |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1437 | switch (ant->tx_chain_num) { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1438 | case 1: |
| 1439 | rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1440 | break; |
| 1441 | case 2: |
| 1442 | rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2); |
| 1443 | break; |
| 1444 | case 3: |
Ivo van Doorn | e22557f | 2010-06-29 21:49:05 +0200 | [diff] [blame] | 1445 | rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1446 | break; |
| 1447 | } |
| 1448 | |
| 1449 | /* |
| 1450 | * Configure the RX antenna. |
| 1451 | */ |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1452 | switch (ant->rx_chain_num) { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1453 | case 1: |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1454 | if (rt2x00_rt(rt2x00dev, RT3070) || |
| 1455 | rt2x00_rt(rt2x00dev, RT3090) || |
| 1456 | rt2x00_rt(rt2x00dev, RT3390)) { |
| 1457 | rt2x00_eeprom_read(rt2x00dev, |
| 1458 | EEPROM_NIC_CONF1, &eeprom); |
| 1459 | if (rt2x00_get_field16(eeprom, |
| 1460 | EEPROM_NIC_CONF1_ANT_DIVERSITY)) |
| 1461 | rt2800_set_ant_diversity(rt2x00dev, |
| 1462 | rt2x00dev->default_ant.rx); |
| 1463 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1464 | rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0); |
| 1465 | break; |
| 1466 | case 2: |
| 1467 | rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 1); |
| 1468 | break; |
| 1469 | case 3: |
| 1470 | rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 2); |
| 1471 | break; |
| 1472 | } |
| 1473 | |
| 1474 | rt2800_bbp_write(rt2x00dev, 3, r3); |
| 1475 | rt2800_bbp_write(rt2x00dev, 1, r1); |
| 1476 | } |
| 1477 | EXPORT_SYMBOL_GPL(rt2800_config_ant); |
| 1478 | |
| 1479 | static void rt2800_config_lna_gain(struct rt2x00_dev *rt2x00dev, |
| 1480 | struct rt2x00lib_conf *libconf) |
| 1481 | { |
| 1482 | u16 eeprom; |
| 1483 | short lna_gain; |
| 1484 | |
| 1485 | if (libconf->rf.channel <= 14) { |
| 1486 | rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom); |
| 1487 | lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_BG); |
| 1488 | } else if (libconf->rf.channel <= 64) { |
| 1489 | rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom); |
| 1490 | lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_A0); |
| 1491 | } else if (libconf->rf.channel <= 128) { |
| 1492 | rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom); |
| 1493 | lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG2_LNA_A1); |
| 1494 | } else { |
| 1495 | rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom); |
| 1496 | lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_A2_LNA_A2); |
| 1497 | } |
| 1498 | |
| 1499 | rt2x00dev->lna_gain = lna_gain; |
| 1500 | } |
| 1501 | |
Gertjan van Wingerde | 06855ef | 2010-04-11 14:31:07 +0200 | [diff] [blame] | 1502 | static void rt2800_config_channel_rf2xxx(struct rt2x00_dev *rt2x00dev, |
| 1503 | struct ieee80211_conf *conf, |
| 1504 | struct rf_channel *rf, |
| 1505 | struct channel_info *info) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1506 | { |
| 1507 | rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset); |
| 1508 | |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1509 | if (rt2x00dev->default_ant.tx_chain_num == 1) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1510 | rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_TX1, 1); |
| 1511 | |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1512 | if (rt2x00dev->default_ant.rx_chain_num == 1) { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1513 | rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX1, 1); |
| 1514 | rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1); |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1515 | } else if (rt2x00dev->default_ant.rx_chain_num == 2) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1516 | rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1); |
| 1517 | |
| 1518 | if (rf->channel > 14) { |
| 1519 | /* |
| 1520 | * When TX power is below 0, we should increase it by 7 to |
| 1521 | * make it a positive value (Minumum value is -7). |
| 1522 | * However this means that values between 0 and 7 have |
| 1523 | * double meaning, and we should set a 7DBm boost flag. |
| 1524 | */ |
| 1525 | rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A_7DBM_BOOST, |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1526 | (info->default_power1 >= 0)); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1527 | |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1528 | if (info->default_power1 < 0) |
| 1529 | info->default_power1 += 7; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1530 | |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1531 | rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A, info->default_power1); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1532 | |
| 1533 | rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A_7DBM_BOOST, |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1534 | (info->default_power2 >= 0)); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1535 | |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1536 | if (info->default_power2 < 0) |
| 1537 | info->default_power2 += 7; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1538 | |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1539 | rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A, info->default_power2); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1540 | } else { |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1541 | rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_G, info->default_power1); |
| 1542 | rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_G, info->default_power2); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | rt2x00_set_field32(&rf->rf4, RF4_HT40, conf_is_ht40(conf)); |
| 1546 | |
| 1547 | rt2800_rf_write(rt2x00dev, 1, rf->rf1); |
| 1548 | rt2800_rf_write(rt2x00dev, 2, rf->rf2); |
| 1549 | rt2800_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004); |
| 1550 | rt2800_rf_write(rt2x00dev, 4, rf->rf4); |
| 1551 | |
| 1552 | udelay(200); |
| 1553 | |
| 1554 | rt2800_rf_write(rt2x00dev, 1, rf->rf1); |
| 1555 | rt2800_rf_write(rt2x00dev, 2, rf->rf2); |
| 1556 | rt2800_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004); |
| 1557 | rt2800_rf_write(rt2x00dev, 4, rf->rf4); |
| 1558 | |
| 1559 | udelay(200); |
| 1560 | |
| 1561 | rt2800_rf_write(rt2x00dev, 1, rf->rf1); |
| 1562 | rt2800_rf_write(rt2x00dev, 2, rf->rf2); |
| 1563 | rt2800_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004); |
| 1564 | rt2800_rf_write(rt2x00dev, 4, rf->rf4); |
| 1565 | } |
| 1566 | |
Gertjan van Wingerde | 06855ef | 2010-04-11 14:31:07 +0200 | [diff] [blame] | 1567 | static void rt2800_config_channel_rf3xxx(struct rt2x00_dev *rt2x00dev, |
| 1568 | struct ieee80211_conf *conf, |
| 1569 | struct rf_channel *rf, |
| 1570 | struct channel_info *info) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1571 | { |
| 1572 | u8 rfcsr; |
| 1573 | |
| 1574 | rt2800_rfcsr_write(rt2x00dev, 2, rf->rf1); |
Gertjan van Wingerde | 41a2617 | 2009-11-09 22:59:04 +0100 | [diff] [blame] | 1575 | rt2800_rfcsr_write(rt2x00dev, 3, rf->rf3); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1576 | |
| 1577 | rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr); |
Gertjan van Wingerde | fab799c | 2010-04-11 14:31:08 +0200 | [diff] [blame] | 1578 | rt2x00_set_field8(&rfcsr, RFCSR6_R1, rf->rf2); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1579 | rt2800_rfcsr_write(rt2x00dev, 6, rfcsr); |
| 1580 | |
| 1581 | rt2800_rfcsr_read(rt2x00dev, 12, &rfcsr); |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1582 | rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER, info->default_power1); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1583 | rt2800_rfcsr_write(rt2x00dev, 12, rfcsr); |
| 1584 | |
Helmut Schaa | 5a67396 | 2010-04-23 15:54:43 +0200 | [diff] [blame] | 1585 | rt2800_rfcsr_read(rt2x00dev, 13, &rfcsr); |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1586 | rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER, info->default_power2); |
Helmut Schaa | 5a67396 | 2010-04-23 15:54:43 +0200 | [diff] [blame] | 1587 | rt2800_rfcsr_write(rt2x00dev, 13, rfcsr); |
| 1588 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1589 | rt2800_rfcsr_read(rt2x00dev, 23, &rfcsr); |
| 1590 | rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset); |
| 1591 | rt2800_rfcsr_write(rt2x00dev, 23, rfcsr); |
| 1592 | |
| 1593 | rt2800_rfcsr_write(rt2x00dev, 24, |
| 1594 | rt2x00dev->calibration[conf_is_ht40(conf)]); |
| 1595 | |
Gertjan van Wingerde | 7197690 | 2010-03-24 21:42:36 +0100 | [diff] [blame] | 1596 | rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1597 | rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1); |
Gertjan van Wingerde | 7197690 | 2010-03-24 21:42:36 +0100 | [diff] [blame] | 1598 | rt2800_rfcsr_write(rt2x00dev, 7, rfcsr); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1599 | } |
| 1600 | |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 1601 | |
| 1602 | #define RT5390_POWER_BOUND 0x27 |
| 1603 | #define RT5390_FREQ_OFFSET_BOUND 0x5f |
| 1604 | |
| 1605 | static void rt2800_config_channel_rf53xx(struct rt2x00_dev *rt2x00dev, |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 1606 | struct ieee80211_conf *conf, |
| 1607 | struct rf_channel *rf, |
| 1608 | struct channel_info *info) |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 1609 | { |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 1610 | u8 rfcsr; |
| 1611 | u16 eeprom; |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 1612 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 1613 | rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1); |
| 1614 | rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3); |
| 1615 | rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr); |
| 1616 | rt2x00_set_field8(&rfcsr, RFCSR11_R, rf->rf2); |
| 1617 | rt2800_rfcsr_write(rt2x00dev, 11, rfcsr); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 1618 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 1619 | rt2800_rfcsr_read(rt2x00dev, 49, &rfcsr); |
| 1620 | if (info->default_power1 > RT5390_POWER_BOUND) |
| 1621 | rt2x00_set_field8(&rfcsr, RFCSR49_TX, RT5390_POWER_BOUND); |
| 1622 | else |
| 1623 | rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1); |
| 1624 | rt2800_rfcsr_write(rt2x00dev, 49, rfcsr); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 1625 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 1626 | rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr); |
| 1627 | rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1); |
| 1628 | rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1); |
| 1629 | rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1); |
| 1630 | rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1); |
| 1631 | rt2800_rfcsr_write(rt2x00dev, 1, rfcsr); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 1632 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 1633 | rt2800_rfcsr_read(rt2x00dev, 17, &rfcsr); |
| 1634 | if (rt2x00dev->freq_offset > RT5390_FREQ_OFFSET_BOUND) |
| 1635 | rt2x00_set_field8(&rfcsr, RFCSR17_CODE, |
| 1636 | RT5390_FREQ_OFFSET_BOUND); |
| 1637 | else |
| 1638 | rt2x00_set_field8(&rfcsr, RFCSR17_CODE, rt2x00dev->freq_offset); |
| 1639 | rt2800_rfcsr_write(rt2x00dev, 17, rfcsr); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 1640 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 1641 | rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom); |
| 1642 | if (rf->channel <= 14) { |
| 1643 | int idx = rf->channel-1; |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 1644 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 1645 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_BT_COEXIST)) { |
| 1646 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) { |
| 1647 | /* r55/r59 value array of channel 1~14 */ |
| 1648 | static const char r55_bt_rev[] = {0x83, 0x83, |
| 1649 | 0x83, 0x73, 0x73, 0x63, 0x53, 0x53, |
| 1650 | 0x53, 0x43, 0x43, 0x43, 0x43, 0x43}; |
| 1651 | static const char r59_bt_rev[] = {0x0e, 0x0e, |
| 1652 | 0x0e, 0x0e, 0x0e, 0x0b, 0x0a, 0x09, |
| 1653 | 0x07, 0x07, 0x07, 0x07, 0x07, 0x07}; |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 1654 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 1655 | rt2800_rfcsr_write(rt2x00dev, 55, |
| 1656 | r55_bt_rev[idx]); |
| 1657 | rt2800_rfcsr_write(rt2x00dev, 59, |
| 1658 | r59_bt_rev[idx]); |
| 1659 | } else { |
| 1660 | static const char r59_bt[] = {0x8b, 0x8b, 0x8b, |
| 1661 | 0x8b, 0x8b, 0x8b, 0x8b, 0x8a, 0x89, |
| 1662 | 0x88, 0x88, 0x86, 0x85, 0x84}; |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 1663 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 1664 | rt2800_rfcsr_write(rt2x00dev, 59, r59_bt[idx]); |
| 1665 | } |
| 1666 | } else { |
| 1667 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) { |
| 1668 | static const char r55_nonbt_rev[] = {0x23, 0x23, |
| 1669 | 0x23, 0x23, 0x13, 0x13, 0x03, 0x03, |
| 1670 | 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}; |
| 1671 | static const char r59_nonbt_rev[] = {0x07, 0x07, |
| 1672 | 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, |
| 1673 | 0x07, 0x07, 0x06, 0x05, 0x04, 0x04}; |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 1674 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 1675 | rt2800_rfcsr_write(rt2x00dev, 55, |
| 1676 | r55_nonbt_rev[idx]); |
| 1677 | rt2800_rfcsr_write(rt2x00dev, 59, |
| 1678 | r59_nonbt_rev[idx]); |
| 1679 | } else if (rt2x00_rt(rt2x00dev, RT5390)) { |
| 1680 | static const char r59_non_bt[] = {0x8f, 0x8f, |
| 1681 | 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8d, |
| 1682 | 0x8a, 0x88, 0x88, 0x87, 0x87, 0x86}; |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 1683 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 1684 | rt2800_rfcsr_write(rt2x00dev, 59, |
| 1685 | r59_non_bt[idx]); |
| 1686 | } |
| 1687 | } |
| 1688 | } |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 1689 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 1690 | rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr); |
| 1691 | rt2x00_set_field8(&rfcsr, RFCSR30_TX_H20M, 0); |
| 1692 | rt2x00_set_field8(&rfcsr, RFCSR30_RX_H20M, 0); |
| 1693 | rt2800_rfcsr_write(rt2x00dev, 30, rfcsr); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 1694 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 1695 | rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr); |
| 1696 | rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1); |
| 1697 | rt2800_rfcsr_write(rt2x00dev, 3, rfcsr); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 1698 | } |
| 1699 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1700 | static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev, |
| 1701 | struct ieee80211_conf *conf, |
| 1702 | struct rf_channel *rf, |
| 1703 | struct channel_info *info) |
| 1704 | { |
| 1705 | u32 reg; |
| 1706 | unsigned int tx_pin; |
| 1707 | u8 bbp; |
| 1708 | |
Ivo van Doorn | 46323e1 | 2010-08-23 19:55:43 +0200 | [diff] [blame] | 1709 | if (rf->channel <= 14) { |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1710 | info->default_power1 = TXPOWER_G_TO_DEV(info->default_power1); |
| 1711 | info->default_power2 = TXPOWER_G_TO_DEV(info->default_power2); |
Ivo van Doorn | 46323e1 | 2010-08-23 19:55:43 +0200 | [diff] [blame] | 1712 | } else { |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1713 | info->default_power1 = TXPOWER_A_TO_DEV(info->default_power1); |
| 1714 | info->default_power2 = TXPOWER_A_TO_DEV(info->default_power2); |
Ivo van Doorn | 46323e1 | 2010-08-23 19:55:43 +0200 | [diff] [blame] | 1715 | } |
| 1716 | |
Gertjan van Wingerde | 06855ef | 2010-04-11 14:31:07 +0200 | [diff] [blame] | 1717 | if (rt2x00_rf(rt2x00dev, RF2020) || |
| 1718 | rt2x00_rf(rt2x00dev, RF3020) || |
| 1719 | rt2x00_rf(rt2x00dev, RF3021) || |
Ivo van Doorn | 46323e1 | 2010-08-23 19:55:43 +0200 | [diff] [blame] | 1720 | rt2x00_rf(rt2x00dev, RF3022) || |
Gertjan van Wingerde | f93bc9b | 2010-11-13 19:09:50 +0100 | [diff] [blame] | 1721 | rt2x00_rf(rt2x00dev, RF3052) || |
| 1722 | rt2x00_rf(rt2x00dev, RF3320)) |
Gertjan van Wingerde | 06855ef | 2010-04-11 14:31:07 +0200 | [diff] [blame] | 1723 | rt2800_config_channel_rf3xxx(rt2x00dev, conf, rf, info); |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 1724 | else if (rt2x00_rf(rt2x00dev, RF5390)) |
| 1725 | rt2800_config_channel_rf53xx(rt2x00dev, conf, rf, info); |
Gertjan van Wingerde | fa6f632 | 2009-11-09 22:59:58 +0100 | [diff] [blame] | 1726 | else |
Gertjan van Wingerde | 06855ef | 2010-04-11 14:31:07 +0200 | [diff] [blame] | 1727 | rt2800_config_channel_rf2xxx(rt2x00dev, conf, rf, info); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1728 | |
| 1729 | /* |
| 1730 | * Change BBP settings |
| 1731 | */ |
| 1732 | rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain); |
| 1733 | rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain); |
| 1734 | rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain); |
| 1735 | rt2800_bbp_write(rt2x00dev, 86, 0); |
| 1736 | |
| 1737 | if (rf->channel <= 14) { |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 1738 | if (!rt2x00_rt(rt2x00dev, RT5390)) { |
| 1739 | if (test_bit(CONFIG_EXTERNAL_LNA_BG, |
| 1740 | &rt2x00dev->flags)) { |
| 1741 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
| 1742 | rt2800_bbp_write(rt2x00dev, 75, 0x46); |
| 1743 | } else { |
| 1744 | rt2800_bbp_write(rt2x00dev, 82, 0x84); |
| 1745 | rt2800_bbp_write(rt2x00dev, 75, 0x50); |
| 1746 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1747 | } |
| 1748 | } else { |
| 1749 | rt2800_bbp_write(rt2x00dev, 82, 0xf2); |
| 1750 | |
| 1751 | if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags)) |
| 1752 | rt2800_bbp_write(rt2x00dev, 75, 0x46); |
| 1753 | else |
| 1754 | rt2800_bbp_write(rt2x00dev, 75, 0x50); |
| 1755 | } |
| 1756 | |
| 1757 | rt2800_register_read(rt2x00dev, TX_BAND_CFG, ®); |
Gertjan van Wingerde | a21ee72 | 2010-05-03 22:43:04 +0200 | [diff] [blame] | 1758 | rt2x00_set_field32(®, TX_BAND_CFG_HT40_MINUS, conf_is_ht40_minus(conf)); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1759 | rt2x00_set_field32(®, TX_BAND_CFG_A, rf->channel > 14); |
| 1760 | rt2x00_set_field32(®, TX_BAND_CFG_BG, rf->channel <= 14); |
| 1761 | rt2800_register_write(rt2x00dev, TX_BAND_CFG, reg); |
| 1762 | |
| 1763 | tx_pin = 0; |
| 1764 | |
| 1765 | /* Turn on unused PA or LNA when not using 1T or 1R */ |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1766 | if (rt2x00dev->default_ant.tx_chain_num == 2) { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1767 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1); |
| 1768 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1); |
| 1769 | } |
| 1770 | |
| 1771 | /* Turn on unused PA or LNA when not using 1T or 1R */ |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1772 | if (rt2x00dev->default_ant.rx_chain_num == 2) { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1773 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1); |
| 1774 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1); |
| 1775 | } |
| 1776 | |
| 1777 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN, 1); |
| 1778 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN, 1); |
| 1779 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1); |
| 1780 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_TRSW_EN, 1); |
| 1781 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, rf->channel <= 14); |
| 1782 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, rf->channel > 14); |
| 1783 | |
| 1784 | rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin); |
| 1785 | |
| 1786 | rt2800_bbp_read(rt2x00dev, 4, &bbp); |
| 1787 | rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * conf_is_ht40(conf)); |
| 1788 | rt2800_bbp_write(rt2x00dev, 4, bbp); |
| 1789 | |
| 1790 | rt2800_bbp_read(rt2x00dev, 3, &bbp); |
Gertjan van Wingerde | a21ee72 | 2010-05-03 22:43:04 +0200 | [diff] [blame] | 1791 | rt2x00_set_field8(&bbp, BBP3_HT40_MINUS, conf_is_ht40_minus(conf)); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1792 | rt2800_bbp_write(rt2x00dev, 3, bbp); |
| 1793 | |
Gertjan van Wingerde | 8d0c9b6 | 2010-04-11 14:31:10 +0200 | [diff] [blame] | 1794 | if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1795 | if (conf_is_ht40(conf)) { |
| 1796 | rt2800_bbp_write(rt2x00dev, 69, 0x1a); |
| 1797 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
| 1798 | rt2800_bbp_write(rt2x00dev, 73, 0x16); |
| 1799 | } else { |
| 1800 | rt2800_bbp_write(rt2x00dev, 69, 0x16); |
| 1801 | rt2800_bbp_write(rt2x00dev, 70, 0x08); |
| 1802 | rt2800_bbp_write(rt2x00dev, 73, 0x11); |
| 1803 | } |
| 1804 | } |
| 1805 | |
| 1806 | msleep(1); |
Helmut Schaa | 977206d | 2010-12-13 12:31:58 +0100 | [diff] [blame] | 1807 | |
| 1808 | /* |
| 1809 | * Clear channel statistic counters |
| 1810 | */ |
| 1811 | rt2800_register_read(rt2x00dev, CH_IDLE_STA, ®); |
| 1812 | rt2800_register_read(rt2x00dev, CH_BUSY_STA, ®); |
| 1813 | rt2800_register_read(rt2x00dev, CH_BUSY_STA_SEC, ®); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1814 | } |
| 1815 | |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 1816 | static int rt2800_get_gain_calibration_delta(struct rt2x00_dev *rt2x00dev) |
| 1817 | { |
| 1818 | u8 tssi_bounds[9]; |
| 1819 | u8 current_tssi; |
| 1820 | u16 eeprom; |
| 1821 | u8 step; |
| 1822 | int i; |
| 1823 | |
| 1824 | /* |
| 1825 | * Read TSSI boundaries for temperature compensation from |
| 1826 | * the EEPROM. |
| 1827 | * |
| 1828 | * Array idx 0 1 2 3 4 5 6 7 8 |
| 1829 | * Matching Delta value -4 -3 -2 -1 0 +1 +2 +3 +4 |
| 1830 | * Example TSSI bounds 0xF0 0xD0 0xB5 0xA0 0x88 0x45 0x25 0x15 0x00 |
| 1831 | */ |
| 1832 | if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) { |
| 1833 | rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG1, &eeprom); |
| 1834 | tssi_bounds[0] = rt2x00_get_field16(eeprom, |
| 1835 | EEPROM_TSSI_BOUND_BG1_MINUS4); |
| 1836 | tssi_bounds[1] = rt2x00_get_field16(eeprom, |
| 1837 | EEPROM_TSSI_BOUND_BG1_MINUS3); |
| 1838 | |
| 1839 | rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG2, &eeprom); |
| 1840 | tssi_bounds[2] = rt2x00_get_field16(eeprom, |
| 1841 | EEPROM_TSSI_BOUND_BG2_MINUS2); |
| 1842 | tssi_bounds[3] = rt2x00_get_field16(eeprom, |
| 1843 | EEPROM_TSSI_BOUND_BG2_MINUS1); |
| 1844 | |
| 1845 | rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG3, &eeprom); |
| 1846 | tssi_bounds[4] = rt2x00_get_field16(eeprom, |
| 1847 | EEPROM_TSSI_BOUND_BG3_REF); |
| 1848 | tssi_bounds[5] = rt2x00_get_field16(eeprom, |
| 1849 | EEPROM_TSSI_BOUND_BG3_PLUS1); |
| 1850 | |
| 1851 | rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG4, &eeprom); |
| 1852 | tssi_bounds[6] = rt2x00_get_field16(eeprom, |
| 1853 | EEPROM_TSSI_BOUND_BG4_PLUS2); |
| 1854 | tssi_bounds[7] = rt2x00_get_field16(eeprom, |
| 1855 | EEPROM_TSSI_BOUND_BG4_PLUS3); |
| 1856 | |
| 1857 | rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG5, &eeprom); |
| 1858 | tssi_bounds[8] = rt2x00_get_field16(eeprom, |
| 1859 | EEPROM_TSSI_BOUND_BG5_PLUS4); |
| 1860 | |
| 1861 | step = rt2x00_get_field16(eeprom, |
| 1862 | EEPROM_TSSI_BOUND_BG5_AGC_STEP); |
| 1863 | } else { |
| 1864 | rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A1, &eeprom); |
| 1865 | tssi_bounds[0] = rt2x00_get_field16(eeprom, |
| 1866 | EEPROM_TSSI_BOUND_A1_MINUS4); |
| 1867 | tssi_bounds[1] = rt2x00_get_field16(eeprom, |
| 1868 | EEPROM_TSSI_BOUND_A1_MINUS3); |
| 1869 | |
| 1870 | rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A2, &eeprom); |
| 1871 | tssi_bounds[2] = rt2x00_get_field16(eeprom, |
| 1872 | EEPROM_TSSI_BOUND_A2_MINUS2); |
| 1873 | tssi_bounds[3] = rt2x00_get_field16(eeprom, |
| 1874 | EEPROM_TSSI_BOUND_A2_MINUS1); |
| 1875 | |
| 1876 | rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A3, &eeprom); |
| 1877 | tssi_bounds[4] = rt2x00_get_field16(eeprom, |
| 1878 | EEPROM_TSSI_BOUND_A3_REF); |
| 1879 | tssi_bounds[5] = rt2x00_get_field16(eeprom, |
| 1880 | EEPROM_TSSI_BOUND_A3_PLUS1); |
| 1881 | |
| 1882 | rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A4, &eeprom); |
| 1883 | tssi_bounds[6] = rt2x00_get_field16(eeprom, |
| 1884 | EEPROM_TSSI_BOUND_A4_PLUS2); |
| 1885 | tssi_bounds[7] = rt2x00_get_field16(eeprom, |
| 1886 | EEPROM_TSSI_BOUND_A4_PLUS3); |
| 1887 | |
| 1888 | rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A5, &eeprom); |
| 1889 | tssi_bounds[8] = rt2x00_get_field16(eeprom, |
| 1890 | EEPROM_TSSI_BOUND_A5_PLUS4); |
| 1891 | |
| 1892 | step = rt2x00_get_field16(eeprom, |
| 1893 | EEPROM_TSSI_BOUND_A5_AGC_STEP); |
| 1894 | } |
| 1895 | |
| 1896 | /* |
| 1897 | * Check if temperature compensation is supported. |
| 1898 | */ |
| 1899 | if (tssi_bounds[4] == 0xff) |
| 1900 | return 0; |
| 1901 | |
| 1902 | /* |
| 1903 | * Read current TSSI (BBP 49). |
| 1904 | */ |
| 1905 | rt2800_bbp_read(rt2x00dev, 49, ¤t_tssi); |
| 1906 | |
| 1907 | /* |
| 1908 | * Compare TSSI value (BBP49) with the compensation boundaries |
| 1909 | * from the EEPROM and increase or decrease tx power. |
| 1910 | */ |
| 1911 | for (i = 0; i <= 3; i++) { |
| 1912 | if (current_tssi > tssi_bounds[i]) |
| 1913 | break; |
| 1914 | } |
| 1915 | |
| 1916 | if (i == 4) { |
| 1917 | for (i = 8; i >= 5; i--) { |
| 1918 | if (current_tssi < tssi_bounds[i]) |
| 1919 | break; |
| 1920 | } |
| 1921 | } |
| 1922 | |
| 1923 | return (i - 4) * step; |
| 1924 | } |
| 1925 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 1926 | static int rt2800_get_txpower_bw_comp(struct rt2x00_dev *rt2x00dev, |
| 1927 | enum ieee80211_band band) |
| 1928 | { |
| 1929 | u16 eeprom; |
| 1930 | u8 comp_en; |
| 1931 | u8 comp_type; |
Helmut Schaa | 75faae8 | 2011-03-28 13:31:30 +0200 | [diff] [blame] | 1932 | int comp_value = 0; |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 1933 | |
| 1934 | rt2x00_eeprom_read(rt2x00dev, EEPROM_TXPOWER_DELTA, &eeprom); |
| 1935 | |
Helmut Schaa | 75faae8 | 2011-03-28 13:31:30 +0200 | [diff] [blame] | 1936 | /* |
| 1937 | * HT40 compensation not required. |
| 1938 | */ |
| 1939 | if (eeprom == 0xffff || |
| 1940 | !test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags)) |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 1941 | return 0; |
| 1942 | |
| 1943 | if (band == IEEE80211_BAND_2GHZ) { |
| 1944 | comp_en = rt2x00_get_field16(eeprom, |
| 1945 | EEPROM_TXPOWER_DELTA_ENABLE_2G); |
| 1946 | if (comp_en) { |
| 1947 | comp_type = rt2x00_get_field16(eeprom, |
| 1948 | EEPROM_TXPOWER_DELTA_TYPE_2G); |
| 1949 | comp_value = rt2x00_get_field16(eeprom, |
| 1950 | EEPROM_TXPOWER_DELTA_VALUE_2G); |
| 1951 | if (!comp_type) |
| 1952 | comp_value = -comp_value; |
| 1953 | } |
| 1954 | } else { |
| 1955 | comp_en = rt2x00_get_field16(eeprom, |
| 1956 | EEPROM_TXPOWER_DELTA_ENABLE_5G); |
| 1957 | if (comp_en) { |
| 1958 | comp_type = rt2x00_get_field16(eeprom, |
| 1959 | EEPROM_TXPOWER_DELTA_TYPE_5G); |
| 1960 | comp_value = rt2x00_get_field16(eeprom, |
| 1961 | EEPROM_TXPOWER_DELTA_VALUE_5G); |
| 1962 | if (!comp_type) |
| 1963 | comp_value = -comp_value; |
| 1964 | } |
| 1965 | } |
| 1966 | |
| 1967 | return comp_value; |
| 1968 | } |
| 1969 | |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 1970 | static u8 rt2800_compensate_txpower(struct rt2x00_dev *rt2x00dev, int is_rate_b, |
| 1971 | enum ieee80211_band band, int power_level, |
| 1972 | u8 txpower, int delta) |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 1973 | { |
| 1974 | u32 reg; |
| 1975 | u16 eeprom; |
| 1976 | u8 criterion; |
| 1977 | u8 eirp_txpower; |
| 1978 | u8 eirp_txpower_criterion; |
| 1979 | u8 reg_limit; |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 1980 | |
| 1981 | if (!((band == IEEE80211_BAND_5GHZ) && is_rate_b)) |
| 1982 | return txpower; |
| 1983 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 1984 | if (test_bit(CONFIG_SUPPORT_POWER_LIMIT, &rt2x00dev->flags)) { |
| 1985 | /* |
| 1986 | * Check if eirp txpower exceed txpower_limit. |
| 1987 | * We use OFDM 6M as criterion and its eirp txpower |
| 1988 | * is stored at EEPROM_EIRP_MAX_TX_POWER. |
| 1989 | * .11b data rate need add additional 4dbm |
| 1990 | * when calculating eirp txpower. |
| 1991 | */ |
| 1992 | rt2800_register_read(rt2x00dev, TX_PWR_CFG_0, ®); |
| 1993 | criterion = rt2x00_get_field32(reg, TX_PWR_CFG_0_6MBS); |
| 1994 | |
| 1995 | rt2x00_eeprom_read(rt2x00dev, |
| 1996 | EEPROM_EIRP_MAX_TX_POWER, &eeprom); |
| 1997 | |
| 1998 | if (band == IEEE80211_BAND_2GHZ) |
| 1999 | eirp_txpower_criterion = rt2x00_get_field16(eeprom, |
| 2000 | EEPROM_EIRP_MAX_TX_POWER_2GHZ); |
| 2001 | else |
| 2002 | eirp_txpower_criterion = rt2x00_get_field16(eeprom, |
| 2003 | EEPROM_EIRP_MAX_TX_POWER_5GHZ); |
| 2004 | |
| 2005 | eirp_txpower = eirp_txpower_criterion + (txpower - criterion) + |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 2006 | (is_rate_b ? 4 : 0) + delta; |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2007 | |
| 2008 | reg_limit = (eirp_txpower > power_level) ? |
| 2009 | (eirp_txpower - power_level) : 0; |
| 2010 | } else |
| 2011 | reg_limit = 0; |
| 2012 | |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 2013 | return txpower + delta - reg_limit; |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2014 | } |
| 2015 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2016 | static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev, |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 2017 | enum ieee80211_band band, |
| 2018 | int power_level) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2019 | { |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2020 | u8 txpower; |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2021 | u16 eeprom; |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2022 | int i, is_rate_b; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2023 | u32 reg; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2024 | u8 r1; |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2025 | u32 offset; |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 2026 | int delta; |
| 2027 | |
| 2028 | /* |
| 2029 | * Calculate HT40 compensation delta |
| 2030 | */ |
| 2031 | delta = rt2800_get_txpower_bw_comp(rt2x00dev, band); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2032 | |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2033 | /* |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 2034 | * calculate temperature compensation delta |
| 2035 | */ |
| 2036 | delta += rt2800_get_gain_calibration_delta(rt2x00dev); |
| 2037 | |
| 2038 | /* |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2039 | * set to normal bbp tx power control mode: +/- 0dBm |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2040 | */ |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2041 | rt2800_bbp_read(rt2x00dev, 1, &r1); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2042 | rt2x00_set_field8(&r1, BBP1_TX_POWER_CTRL, 0); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2043 | rt2800_bbp_write(rt2x00dev, 1, r1); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2044 | offset = TX_PWR_CFG_0; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2045 | |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2046 | for (i = 0; i < EEPROM_TXPOWER_BYRATE_SIZE; i += 2) { |
| 2047 | /* just to be safe */ |
| 2048 | if (offset > TX_PWR_CFG_4) |
| 2049 | break; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2050 | |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2051 | rt2800_register_read(rt2x00dev, offset, ®); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2052 | |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2053 | /* read the next four txpower values */ |
| 2054 | rt2x00_eeprom_read(rt2x00dev, EEPROM_TXPOWER_BYRATE + i, |
| 2055 | &eeprom); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2056 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2057 | is_rate_b = i ? 0 : 1; |
| 2058 | /* |
| 2059 | * TX_PWR_CFG_0: 1MBS, TX_PWR_CFG_1: 24MBS, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2060 | * TX_PWR_CFG_2: MCS4, TX_PWR_CFG_3: MCS12, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2061 | * TX_PWR_CFG_4: unknown |
| 2062 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2063 | txpower = rt2x00_get_field16(eeprom, |
| 2064 | EEPROM_TXPOWER_BYRATE_RATE0); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 2065 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 2066 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2067 | rt2x00_set_field32(®, TX_PWR_CFG_RATE0, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2068 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2069 | /* |
| 2070 | * TX_PWR_CFG_0: 2MBS, TX_PWR_CFG_1: 36MBS, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2071 | * TX_PWR_CFG_2: MCS5, TX_PWR_CFG_3: MCS13, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2072 | * TX_PWR_CFG_4: unknown |
| 2073 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2074 | txpower = rt2x00_get_field16(eeprom, |
| 2075 | EEPROM_TXPOWER_BYRATE_RATE1); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 2076 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 2077 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2078 | rt2x00_set_field32(®, TX_PWR_CFG_RATE1, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2079 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2080 | /* |
| 2081 | * TX_PWR_CFG_0: 5.5MBS, TX_PWR_CFG_1: 48MBS, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2082 | * TX_PWR_CFG_2: MCS6, TX_PWR_CFG_3: MCS14, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2083 | * TX_PWR_CFG_4: unknown |
| 2084 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2085 | txpower = rt2x00_get_field16(eeprom, |
| 2086 | EEPROM_TXPOWER_BYRATE_RATE2); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 2087 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 2088 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2089 | rt2x00_set_field32(®, TX_PWR_CFG_RATE2, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2090 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2091 | /* |
| 2092 | * TX_PWR_CFG_0: 11MBS, TX_PWR_CFG_1: 54MBS, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2093 | * TX_PWR_CFG_2: MCS7, TX_PWR_CFG_3: MCS15, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2094 | * TX_PWR_CFG_4: unknown |
| 2095 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2096 | txpower = rt2x00_get_field16(eeprom, |
| 2097 | EEPROM_TXPOWER_BYRATE_RATE3); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 2098 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 2099 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2100 | rt2x00_set_field32(®, TX_PWR_CFG_RATE3, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2101 | |
| 2102 | /* read the next four txpower values */ |
| 2103 | rt2x00_eeprom_read(rt2x00dev, EEPROM_TXPOWER_BYRATE + i + 1, |
| 2104 | &eeprom); |
| 2105 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2106 | is_rate_b = 0; |
| 2107 | /* |
| 2108 | * TX_PWR_CFG_0: 6MBS, TX_PWR_CFG_1: MCS0, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2109 | * TX_PWR_CFG_2: MCS8, TX_PWR_CFG_3: unknown, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2110 | * TX_PWR_CFG_4: unknown |
| 2111 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2112 | txpower = rt2x00_get_field16(eeprom, |
| 2113 | EEPROM_TXPOWER_BYRATE_RATE0); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 2114 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 2115 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2116 | rt2x00_set_field32(®, TX_PWR_CFG_RATE4, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2117 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2118 | /* |
| 2119 | * TX_PWR_CFG_0: 9MBS, TX_PWR_CFG_1: MCS1, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2120 | * TX_PWR_CFG_2: MCS9, TX_PWR_CFG_3: unknown, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2121 | * TX_PWR_CFG_4: unknown |
| 2122 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2123 | txpower = rt2x00_get_field16(eeprom, |
| 2124 | EEPROM_TXPOWER_BYRATE_RATE1); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 2125 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 2126 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2127 | rt2x00_set_field32(®, TX_PWR_CFG_RATE5, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2128 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2129 | /* |
| 2130 | * TX_PWR_CFG_0: 12MBS, TX_PWR_CFG_1: MCS2, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2131 | * TX_PWR_CFG_2: MCS10, TX_PWR_CFG_3: unknown, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2132 | * TX_PWR_CFG_4: unknown |
| 2133 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2134 | txpower = rt2x00_get_field16(eeprom, |
| 2135 | EEPROM_TXPOWER_BYRATE_RATE2); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 2136 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 2137 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2138 | rt2x00_set_field32(®, TX_PWR_CFG_RATE6, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2139 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2140 | /* |
| 2141 | * TX_PWR_CFG_0: 18MBS, TX_PWR_CFG_1: MCS3, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2142 | * TX_PWR_CFG_2: MCS11, TX_PWR_CFG_3: unknown, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2143 | * TX_PWR_CFG_4: unknown |
| 2144 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2145 | txpower = rt2x00_get_field16(eeprom, |
| 2146 | EEPROM_TXPOWER_BYRATE_RATE3); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 2147 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 2148 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2149 | rt2x00_set_field32(®, TX_PWR_CFG_RATE7, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 2150 | |
| 2151 | rt2800_register_write(rt2x00dev, offset, reg); |
| 2152 | |
| 2153 | /* next TX_PWR_CFG register */ |
| 2154 | offset += 4; |
| 2155 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2156 | } |
| 2157 | |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 2158 | void rt2800_gain_calibration(struct rt2x00_dev *rt2x00dev) |
| 2159 | { |
| 2160 | rt2800_config_txpower(rt2x00dev, rt2x00dev->curr_band, |
| 2161 | rt2x00dev->tx_power); |
| 2162 | } |
| 2163 | EXPORT_SYMBOL_GPL(rt2800_gain_calibration); |
| 2164 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2165 | static void rt2800_config_retry_limit(struct rt2x00_dev *rt2x00dev, |
| 2166 | struct rt2x00lib_conf *libconf) |
| 2167 | { |
| 2168 | u32 reg; |
| 2169 | |
| 2170 | rt2800_register_read(rt2x00dev, TX_RTY_CFG, ®); |
| 2171 | rt2x00_set_field32(®, TX_RTY_CFG_SHORT_RTY_LIMIT, |
| 2172 | libconf->conf->short_frame_max_tx_count); |
| 2173 | rt2x00_set_field32(®, TX_RTY_CFG_LONG_RTY_LIMIT, |
| 2174 | libconf->conf->long_frame_max_tx_count); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2175 | rt2800_register_write(rt2x00dev, TX_RTY_CFG, reg); |
| 2176 | } |
| 2177 | |
| 2178 | static void rt2800_config_ps(struct rt2x00_dev *rt2x00dev, |
| 2179 | struct rt2x00lib_conf *libconf) |
| 2180 | { |
| 2181 | enum dev_state state = |
| 2182 | (libconf->conf->flags & IEEE80211_CONF_PS) ? |
| 2183 | STATE_SLEEP : STATE_AWAKE; |
| 2184 | u32 reg; |
| 2185 | |
| 2186 | if (state == STATE_SLEEP) { |
| 2187 | rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0); |
| 2188 | |
| 2189 | rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG, ®); |
| 2190 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 5); |
| 2191 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE, |
| 2192 | libconf->conf->listen_interval - 1); |
| 2193 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTOWAKE, 1); |
| 2194 | rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg); |
| 2195 | |
| 2196 | rt2x00dev->ops->lib->set_device_state(rt2x00dev, state); |
| 2197 | } else { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2198 | rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG, ®); |
| 2199 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 0); |
| 2200 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE, 0); |
| 2201 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTOWAKE, 0); |
| 2202 | rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg); |
Gertjan van Wingerde | 5731858 | 2010-03-30 23:50:23 +0200 | [diff] [blame] | 2203 | |
| 2204 | rt2x00dev->ops->lib->set_device_state(rt2x00dev, state); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2205 | } |
| 2206 | } |
| 2207 | |
| 2208 | void rt2800_config(struct rt2x00_dev *rt2x00dev, |
| 2209 | struct rt2x00lib_conf *libconf, |
| 2210 | const unsigned int flags) |
| 2211 | { |
| 2212 | /* Always recalculate LNA gain before changing configuration */ |
| 2213 | rt2800_config_lna_gain(rt2x00dev, libconf); |
| 2214 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2215 | if (flags & IEEE80211_CONF_CHANGE_CHANNEL) { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2216 | rt2800_config_channel(rt2x00dev, libconf->conf, |
| 2217 | &libconf->rf, &libconf->channel); |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 2218 | rt2800_config_txpower(rt2x00dev, libconf->conf->channel->band, |
| 2219 | libconf->conf->power_level); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 2220 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2221 | if (flags & IEEE80211_CONF_CHANGE_POWER) |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 2222 | rt2800_config_txpower(rt2x00dev, libconf->conf->channel->band, |
| 2223 | libconf->conf->power_level); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2224 | if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS) |
| 2225 | rt2800_config_retry_limit(rt2x00dev, libconf); |
| 2226 | if (flags & IEEE80211_CONF_CHANGE_PS) |
| 2227 | rt2800_config_ps(rt2x00dev, libconf); |
| 2228 | } |
| 2229 | EXPORT_SYMBOL_GPL(rt2800_config); |
| 2230 | |
| 2231 | /* |
| 2232 | * Link tuning |
| 2233 | */ |
| 2234 | void rt2800_link_stats(struct rt2x00_dev *rt2x00dev, struct link_qual *qual) |
| 2235 | { |
| 2236 | u32 reg; |
| 2237 | |
| 2238 | /* |
| 2239 | * Update FCS error count from register. |
| 2240 | */ |
| 2241 | rt2800_register_read(rt2x00dev, RX_STA_CNT0, ®); |
| 2242 | qual->rx_failed = rt2x00_get_field32(reg, RX_STA_CNT0_CRC_ERR); |
| 2243 | } |
| 2244 | EXPORT_SYMBOL_GPL(rt2800_link_stats); |
| 2245 | |
| 2246 | static u8 rt2800_get_default_vgc(struct rt2x00_dev *rt2x00dev) |
| 2247 | { |
| 2248 | if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) { |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 2249 | if (rt2x00_rt(rt2x00dev, RT3070) || |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 2250 | rt2x00_rt(rt2x00dev, RT3071) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 2251 | rt2x00_rt(rt2x00dev, RT3090) || |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2252 | rt2x00_rt(rt2x00dev, RT3390) || |
| 2253 | rt2x00_rt(rt2x00dev, RT5390)) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2254 | return 0x1c + (2 * rt2x00dev->lna_gain); |
| 2255 | else |
| 2256 | return 0x2e + rt2x00dev->lna_gain; |
| 2257 | } |
| 2258 | |
| 2259 | if (!test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags)) |
| 2260 | return 0x32 + (rt2x00dev->lna_gain * 5) / 3; |
| 2261 | else |
| 2262 | return 0x3a + (rt2x00dev->lna_gain * 5) / 3; |
| 2263 | } |
| 2264 | |
| 2265 | static inline void rt2800_set_vgc(struct rt2x00_dev *rt2x00dev, |
| 2266 | struct link_qual *qual, u8 vgc_level) |
| 2267 | { |
| 2268 | if (qual->vgc_level != vgc_level) { |
| 2269 | rt2800_bbp_write(rt2x00dev, 66, vgc_level); |
| 2270 | qual->vgc_level = vgc_level; |
| 2271 | qual->vgc_level_reg = vgc_level; |
| 2272 | } |
| 2273 | } |
| 2274 | |
| 2275 | void rt2800_reset_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual) |
| 2276 | { |
| 2277 | rt2800_set_vgc(rt2x00dev, qual, rt2800_get_default_vgc(rt2x00dev)); |
| 2278 | } |
| 2279 | EXPORT_SYMBOL_GPL(rt2800_reset_tuner); |
| 2280 | |
| 2281 | void rt2800_link_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual, |
| 2282 | const u32 count) |
| 2283 | { |
Gertjan van Wingerde | 8d0c9b6 | 2010-04-11 14:31:10 +0200 | [diff] [blame] | 2284 | if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2285 | return; |
| 2286 | |
| 2287 | /* |
| 2288 | * When RSSI is better then -80 increase VGC level with 0x10 |
| 2289 | */ |
| 2290 | rt2800_set_vgc(rt2x00dev, qual, |
| 2291 | rt2800_get_default_vgc(rt2x00dev) + |
| 2292 | ((qual->rssi > -80) * 0x10)); |
| 2293 | } |
| 2294 | EXPORT_SYMBOL_GPL(rt2800_link_tuner); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2295 | |
| 2296 | /* |
| 2297 | * Initialization functions. |
| 2298 | */ |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 2299 | static int rt2800_init_registers(struct rt2x00_dev *rt2x00dev) |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2300 | { |
| 2301 | u32 reg; |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 2302 | u16 eeprom; |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2303 | unsigned int i; |
Gertjan van Wingerde | e3a896b | 2010-06-03 10:52:04 +0200 | [diff] [blame] | 2304 | int ret; |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2305 | |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2306 | rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®); |
| 2307 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0); |
| 2308 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_DMA_BUSY, 0); |
| 2309 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0); |
| 2310 | rt2x00_set_field32(®, WPDMA_GLO_CFG_RX_DMA_BUSY, 0); |
| 2311 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1); |
| 2312 | rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg); |
| 2313 | |
Gertjan van Wingerde | e3a896b | 2010-06-03 10:52:04 +0200 | [diff] [blame] | 2314 | ret = rt2800_drv_init_registers(rt2x00dev); |
| 2315 | if (ret) |
| 2316 | return ret; |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2317 | |
| 2318 | rt2800_register_read(rt2x00dev, BCN_OFFSET0, ®); |
| 2319 | rt2x00_set_field32(®, BCN_OFFSET0_BCN0, 0xe0); /* 0x3800 */ |
| 2320 | rt2x00_set_field32(®, BCN_OFFSET0_BCN1, 0xe8); /* 0x3a00 */ |
| 2321 | rt2x00_set_field32(®, BCN_OFFSET0_BCN2, 0xf0); /* 0x3c00 */ |
| 2322 | rt2x00_set_field32(®, BCN_OFFSET0_BCN3, 0xf8); /* 0x3e00 */ |
| 2323 | rt2800_register_write(rt2x00dev, BCN_OFFSET0, reg); |
| 2324 | |
| 2325 | rt2800_register_read(rt2x00dev, BCN_OFFSET1, ®); |
| 2326 | rt2x00_set_field32(®, BCN_OFFSET1_BCN4, 0xc8); /* 0x3200 */ |
| 2327 | rt2x00_set_field32(®, BCN_OFFSET1_BCN5, 0xd0); /* 0x3400 */ |
| 2328 | rt2x00_set_field32(®, BCN_OFFSET1_BCN6, 0x77); /* 0x1dc0 */ |
| 2329 | rt2x00_set_field32(®, BCN_OFFSET1_BCN7, 0x6f); /* 0x1bc0 */ |
| 2330 | rt2800_register_write(rt2x00dev, BCN_OFFSET1, reg); |
| 2331 | |
| 2332 | rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE, 0x0000013f); |
| 2333 | rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003); |
| 2334 | |
| 2335 | rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000); |
| 2336 | |
| 2337 | rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®); |
Helmut Schaa | 8544df3 | 2010-07-11 12:29:49 +0200 | [diff] [blame] | 2338 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_INTERVAL, 1600); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2339 | rt2x00_set_field32(®, BCN_TIME_CFG_TSF_TICKING, 0); |
| 2340 | rt2x00_set_field32(®, BCN_TIME_CFG_TSF_SYNC, 0); |
| 2341 | rt2x00_set_field32(®, BCN_TIME_CFG_TBTT_ENABLE, 0); |
| 2342 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 0); |
| 2343 | rt2x00_set_field32(®, BCN_TIME_CFG_TX_TIME_COMPENSATE, 0); |
| 2344 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
| 2345 | |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2346 | rt2800_config_filter(rt2x00dev, FIF_ALLMULTI); |
| 2347 | |
| 2348 | rt2800_register_read(rt2x00dev, BKOFF_SLOT_CFG, ®); |
| 2349 | rt2x00_set_field32(®, BKOFF_SLOT_CFG_SLOT_TIME, 9); |
| 2350 | rt2x00_set_field32(®, BKOFF_SLOT_CFG_CC_DELAY_TIME, 2); |
| 2351 | rt2800_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg); |
| 2352 | |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 2353 | if (rt2x00_rt(rt2x00dev, RT3071) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 2354 | rt2x00_rt(rt2x00dev, RT3090) || |
| 2355 | rt2x00_rt(rt2x00dev, RT3390)) { |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2356 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400); |
| 2357 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000); |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 2358 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 2359 | rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E) || |
| 2360 | rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) { |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 2361 | rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom); |
| 2362 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_DAC_TEST)) |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 2363 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, |
| 2364 | 0x0000002c); |
| 2365 | else |
| 2366 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, |
| 2367 | 0x0000000f); |
| 2368 | } else { |
| 2369 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000); |
| 2370 | } |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 2371 | } else if (rt2x00_rt(rt2x00dev, RT3070)) { |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2372 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400); |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 2373 | |
| 2374 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) { |
| 2375 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000); |
| 2376 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x0000002c); |
| 2377 | } else { |
| 2378 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606); |
| 2379 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000); |
| 2380 | } |
Helmut Schaa | c295a81 | 2010-06-03 10:52:13 +0200 | [diff] [blame] | 2381 | } else if (rt2800_is_305x_soc(rt2x00dev)) { |
| 2382 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400); |
| 2383 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000); |
| 2384 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x0000001f); |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2385 | } else if (rt2x00_rt(rt2x00dev, RT5390)) { |
| 2386 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000404); |
| 2387 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606); |
| 2388 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2389 | } else { |
| 2390 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000000); |
| 2391 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606); |
| 2392 | } |
| 2393 | |
| 2394 | rt2800_register_read(rt2x00dev, TX_LINK_CFG, ®); |
| 2395 | rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_MFB_LIFETIME, 32); |
| 2396 | rt2x00_set_field32(®, TX_LINK_CFG_MFB_ENABLE, 0); |
| 2397 | rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_UMFS_ENABLE, 0); |
| 2398 | rt2x00_set_field32(®, TX_LINK_CFG_TX_MRQ_EN, 0); |
| 2399 | rt2x00_set_field32(®, TX_LINK_CFG_TX_RDG_EN, 0); |
| 2400 | rt2x00_set_field32(®, TX_LINK_CFG_TX_CF_ACK_EN, 1); |
| 2401 | rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_MFB, 0); |
| 2402 | rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_MFS, 0); |
| 2403 | rt2800_register_write(rt2x00dev, TX_LINK_CFG, reg); |
| 2404 | |
| 2405 | rt2800_register_read(rt2x00dev, TX_TIMEOUT_CFG, ®); |
| 2406 | rt2x00_set_field32(®, TX_TIMEOUT_CFG_MPDU_LIFETIME, 9); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2407 | rt2x00_set_field32(®, TX_TIMEOUT_CFG_RX_ACK_TIMEOUT, 32); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2408 | rt2x00_set_field32(®, TX_TIMEOUT_CFG_TX_OP_TIMEOUT, 10); |
| 2409 | rt2800_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg); |
| 2410 | |
| 2411 | rt2800_register_read(rt2x00dev, MAX_LEN_CFG, ®); |
| 2412 | rt2x00_set_field32(®, MAX_LEN_CFG_MAX_MPDU, AGGREGATION_SIZE); |
Gertjan van Wingerde | 8d0c9b6 | 2010-04-11 14:31:10 +0200 | [diff] [blame] | 2413 | if (rt2x00_rt_rev_gte(rt2x00dev, RT2872, REV_RT2872E) || |
Gertjan van Wingerde | 49e721e | 2010-02-13 20:55:49 +0100 | [diff] [blame] | 2414 | rt2x00_rt(rt2x00dev, RT2883) || |
Gertjan van Wingerde | 8d0c9b6 | 2010-04-11 14:31:10 +0200 | [diff] [blame] | 2415 | rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070E)) |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2416 | rt2x00_set_field32(®, MAX_LEN_CFG_MAX_PSDU, 2); |
| 2417 | else |
| 2418 | rt2x00_set_field32(®, MAX_LEN_CFG_MAX_PSDU, 1); |
| 2419 | rt2x00_set_field32(®, MAX_LEN_CFG_MIN_PSDU, 0); |
| 2420 | rt2x00_set_field32(®, MAX_LEN_CFG_MIN_MPDU, 0); |
| 2421 | rt2800_register_write(rt2x00dev, MAX_LEN_CFG, reg); |
| 2422 | |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2423 | rt2800_register_read(rt2x00dev, LED_CFG, ®); |
| 2424 | rt2x00_set_field32(®, LED_CFG_ON_PERIOD, 70); |
| 2425 | rt2x00_set_field32(®, LED_CFG_OFF_PERIOD, 30); |
| 2426 | rt2x00_set_field32(®, LED_CFG_SLOW_BLINK_PERIOD, 3); |
| 2427 | rt2x00_set_field32(®, LED_CFG_R_LED_MODE, 3); |
| 2428 | rt2x00_set_field32(®, LED_CFG_G_LED_MODE, 3); |
| 2429 | rt2x00_set_field32(®, LED_CFG_Y_LED_MODE, 3); |
| 2430 | rt2x00_set_field32(®, LED_CFG_LED_POLAR, 1); |
| 2431 | rt2800_register_write(rt2x00dev, LED_CFG, reg); |
| 2432 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2433 | rt2800_register_write(rt2x00dev, PBF_MAX_PCNT, 0x1f3fbf9f); |
| 2434 | |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2435 | rt2800_register_read(rt2x00dev, TX_RTY_CFG, ®); |
| 2436 | rt2x00_set_field32(®, TX_RTY_CFG_SHORT_RTY_LIMIT, 15); |
| 2437 | rt2x00_set_field32(®, TX_RTY_CFG_LONG_RTY_LIMIT, 31); |
| 2438 | rt2x00_set_field32(®, TX_RTY_CFG_LONG_RTY_THRE, 2000); |
| 2439 | rt2x00_set_field32(®, TX_RTY_CFG_NON_AGG_RTY_MODE, 0); |
| 2440 | rt2x00_set_field32(®, TX_RTY_CFG_AGG_RTY_MODE, 0); |
| 2441 | rt2x00_set_field32(®, TX_RTY_CFG_TX_AUTO_FB_ENABLE, 1); |
| 2442 | rt2800_register_write(rt2x00dev, TX_RTY_CFG, reg); |
| 2443 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2444 | rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, ®); |
| 2445 | rt2x00_set_field32(®, AUTO_RSP_CFG_AUTORESPONDER, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2446 | rt2x00_set_field32(®, AUTO_RSP_CFG_BAC_ACK_POLICY, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2447 | rt2x00_set_field32(®, AUTO_RSP_CFG_CTS_40_MMODE, 0); |
| 2448 | rt2x00_set_field32(®, AUTO_RSP_CFG_CTS_40_MREF, 0); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2449 | rt2x00_set_field32(®, AUTO_RSP_CFG_AR_PREAMBLE, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2450 | rt2x00_set_field32(®, AUTO_RSP_CFG_DUAL_CTS_EN, 0); |
| 2451 | rt2x00_set_field32(®, AUTO_RSP_CFG_ACK_CTS_PSM_BIT, 0); |
| 2452 | rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg); |
| 2453 | |
| 2454 | rt2800_register_read(rt2x00dev, CCK_PROT_CFG, ®); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2455 | rt2x00_set_field32(®, CCK_PROT_CFG_PROTECT_RATE, 3); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2456 | rt2x00_set_field32(®, CCK_PROT_CFG_PROTECT_CTRL, 0); |
Shiang Tu | 6f492b6 | 2011-02-20 13:56:54 +0100 | [diff] [blame] | 2457 | rt2x00_set_field32(®, CCK_PROT_CFG_PROTECT_NAV_SHORT, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2458 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 2459 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 2460 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2461 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_MM40, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2462 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2463 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_GF40, 0); |
| 2464 | rt2x00_set_field32(®, CCK_PROT_CFG_RTS_TH_EN, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2465 | rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg); |
| 2466 | |
| 2467 | rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, ®); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2468 | rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_RATE, 3); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2469 | rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_CTRL, 0); |
Shiang Tu | 6f492b6 | 2011-02-20 13:56:54 +0100 | [diff] [blame] | 2470 | rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_NAV_SHORT, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2471 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 2472 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 2473 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2474 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_MM40, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2475 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2476 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_GF40, 0); |
| 2477 | rt2x00_set_field32(®, OFDM_PROT_CFG_RTS_TH_EN, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2478 | rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg); |
| 2479 | |
| 2480 | rt2800_register_read(rt2x00dev, MM20_PROT_CFG, ®); |
| 2481 | rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_RATE, 0x4004); |
| 2482 | rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_CTRL, 0); |
Shiang Tu | 6f492b6 | 2011-02-20 13:56:54 +0100 | [diff] [blame] | 2483 | rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_NAV_SHORT, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2484 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 2485 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 2486 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
| 2487 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_MM40, 0); |
| 2488 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
| 2489 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_GF40, 0); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2490 | rt2x00_set_field32(®, MM20_PROT_CFG_RTS_TH_EN, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2491 | rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg); |
| 2492 | |
| 2493 | rt2800_register_read(rt2x00dev, MM40_PROT_CFG, ®); |
| 2494 | rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_RATE, 0x4084); |
Helmut Schaa | d13a97f | 2010-10-02 11:29:08 +0200 | [diff] [blame] | 2495 | rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_CTRL, 0); |
Shiang Tu | 6f492b6 | 2011-02-20 13:56:54 +0100 | [diff] [blame] | 2496 | rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_NAV_SHORT, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2497 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 2498 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 2499 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
| 2500 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_MM40, 1); |
| 2501 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
| 2502 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_GF40, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2503 | rt2x00_set_field32(®, MM40_PROT_CFG_RTS_TH_EN, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2504 | rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg); |
| 2505 | |
| 2506 | rt2800_register_read(rt2x00dev, GF20_PROT_CFG, ®); |
| 2507 | rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_RATE, 0x4004); |
| 2508 | rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_CTRL, 0); |
Shiang Tu | 6f492b6 | 2011-02-20 13:56:54 +0100 | [diff] [blame] | 2509 | rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_NAV_SHORT, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2510 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 2511 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 2512 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
| 2513 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_MM40, 0); |
| 2514 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
| 2515 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_GF40, 0); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2516 | rt2x00_set_field32(®, GF20_PROT_CFG_RTS_TH_EN, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2517 | rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg); |
| 2518 | |
| 2519 | rt2800_register_read(rt2x00dev, GF40_PROT_CFG, ®); |
| 2520 | rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_RATE, 0x4084); |
| 2521 | rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_CTRL, 0); |
Shiang Tu | 6f492b6 | 2011-02-20 13:56:54 +0100 | [diff] [blame] | 2522 | rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_NAV_SHORT, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2523 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 2524 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 2525 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
| 2526 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_MM40, 1); |
| 2527 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
| 2528 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_GF40, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2529 | rt2x00_set_field32(®, GF40_PROT_CFG_RTS_TH_EN, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2530 | rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg); |
| 2531 | |
Gertjan van Wingerde | cea90e5 | 2010-02-13 20:55:47 +0100 | [diff] [blame] | 2532 | if (rt2x00_is_usb(rt2x00dev)) { |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2533 | rt2800_register_write(rt2x00dev, PBF_CFG, 0xf40006); |
| 2534 | |
| 2535 | rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®); |
| 2536 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0); |
| 2537 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_DMA_BUSY, 0); |
| 2538 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0); |
| 2539 | rt2x00_set_field32(®, WPDMA_GLO_CFG_RX_DMA_BUSY, 0); |
| 2540 | rt2x00_set_field32(®, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 3); |
| 2541 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 0); |
| 2542 | rt2x00_set_field32(®, WPDMA_GLO_CFG_BIG_ENDIAN, 0); |
| 2543 | rt2x00_set_field32(®, WPDMA_GLO_CFG_RX_HDR_SCATTER, 0); |
| 2544 | rt2x00_set_field32(®, WPDMA_GLO_CFG_HDR_SEG_LEN, 0); |
| 2545 | rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg); |
| 2546 | } |
| 2547 | |
Helmut Schaa | 961621a | 2010-11-04 20:36:59 +0100 | [diff] [blame] | 2548 | /* |
| 2549 | * The legacy driver also sets TXOP_CTRL_CFG_RESERVED_TRUN_EN to 1 |
| 2550 | * although it is reserved. |
| 2551 | */ |
| 2552 | rt2800_register_read(rt2x00dev, TXOP_CTRL_CFG, ®); |
| 2553 | rt2x00_set_field32(®, TXOP_CTRL_CFG_TIMEOUT_TRUN_EN, 1); |
| 2554 | rt2x00_set_field32(®, TXOP_CTRL_CFG_AC_TRUN_EN, 1); |
| 2555 | rt2x00_set_field32(®, TXOP_CTRL_CFG_TXRATEGRP_TRUN_EN, 1); |
| 2556 | rt2x00_set_field32(®, TXOP_CTRL_CFG_USER_MODE_TRUN_EN, 1); |
| 2557 | rt2x00_set_field32(®, TXOP_CTRL_CFG_MIMO_PS_TRUN_EN, 1); |
| 2558 | rt2x00_set_field32(®, TXOP_CTRL_CFG_RESERVED_TRUN_EN, 1); |
| 2559 | rt2x00_set_field32(®, TXOP_CTRL_CFG_LSIG_TXOP_EN, 0); |
| 2560 | rt2x00_set_field32(®, TXOP_CTRL_CFG_EXT_CCA_EN, 0); |
| 2561 | rt2x00_set_field32(®, TXOP_CTRL_CFG_EXT_CCA_DLY, 88); |
| 2562 | rt2x00_set_field32(®, TXOP_CTRL_CFG_EXT_CWMIN, 0); |
| 2563 | rt2800_register_write(rt2x00dev, TXOP_CTRL_CFG, reg); |
| 2564 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2565 | rt2800_register_write(rt2x00dev, TXOP_HLDR_ET, 0x00000002); |
| 2566 | |
| 2567 | rt2800_register_read(rt2x00dev, TX_RTS_CFG, ®); |
| 2568 | rt2x00_set_field32(®, TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT, 32); |
| 2569 | rt2x00_set_field32(®, TX_RTS_CFG_RTS_THRES, |
| 2570 | IEEE80211_MAX_RTS_THRESHOLD); |
| 2571 | rt2x00_set_field32(®, TX_RTS_CFG_RTS_FBK_EN, 0); |
| 2572 | rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg); |
| 2573 | |
| 2574 | rt2800_register_write(rt2x00dev, EXP_ACK_TIME, 0x002400ca); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2575 | |
Helmut Schaa | a21c2ab | 2010-05-06 12:29:04 +0200 | [diff] [blame] | 2576 | /* |
| 2577 | * Usually the CCK SIFS time should be set to 10 and the OFDM SIFS |
| 2578 | * time should be set to 16. However, the original Ralink driver uses |
| 2579 | * 16 for both and indeed using a value of 10 for CCK SIFS results in |
| 2580 | * connection problems with 11g + CTS protection. Hence, use the same |
| 2581 | * defaults as the Ralink driver: 16 for both, CCK and OFDM SIFS. |
| 2582 | */ |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2583 | rt2800_register_read(rt2x00dev, XIFS_TIME_CFG, ®); |
Helmut Schaa | a21c2ab | 2010-05-06 12:29:04 +0200 | [diff] [blame] | 2584 | rt2x00_set_field32(®, XIFS_TIME_CFG_CCKM_SIFS_TIME, 16); |
| 2585 | rt2x00_set_field32(®, XIFS_TIME_CFG_OFDM_SIFS_TIME, 16); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2586 | rt2x00_set_field32(®, XIFS_TIME_CFG_OFDM_XIFS_TIME, 4); |
| 2587 | rt2x00_set_field32(®, XIFS_TIME_CFG_EIFS, 314); |
| 2588 | rt2x00_set_field32(®, XIFS_TIME_CFG_BB_RXEND_ENABLE, 1); |
| 2589 | rt2800_register_write(rt2x00dev, XIFS_TIME_CFG, reg); |
| 2590 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2591 | rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003); |
| 2592 | |
| 2593 | /* |
| 2594 | * ASIC will keep garbage value after boot, clear encryption keys. |
| 2595 | */ |
| 2596 | for (i = 0; i < 4; i++) |
| 2597 | rt2800_register_write(rt2x00dev, |
| 2598 | SHARED_KEY_MODE_ENTRY(i), 0); |
| 2599 | |
| 2600 | for (i = 0; i < 256; i++) { |
Joe Perches | f4e16e4 | 2010-11-20 18:39:01 -0800 | [diff] [blame] | 2601 | static const u32 wcid[2] = { 0xffffffff, 0x00ffffff }; |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2602 | rt2800_register_multiwrite(rt2x00dev, MAC_WCID_ENTRY(i), |
| 2603 | wcid, sizeof(wcid)); |
| 2604 | |
Helmut Schaa | 1ed3811 | 2011-03-03 19:44:33 +0100 | [diff] [blame] | 2605 | rt2800_register_write(rt2x00dev, MAC_WCID_ATTR_ENTRY(i), 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2606 | rt2800_register_write(rt2x00dev, MAC_IVEIV_ENTRY(i), 0); |
| 2607 | } |
| 2608 | |
| 2609 | /* |
| 2610 | * Clear all beacons |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2611 | */ |
Helmut Schaa | 69cf36a | 2011-01-30 13:16:03 +0100 | [diff] [blame] | 2612 | rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE0); |
| 2613 | rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE1); |
| 2614 | rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE2); |
| 2615 | rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE3); |
| 2616 | rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE4); |
| 2617 | rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE5); |
| 2618 | rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE6); |
| 2619 | rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE7); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2620 | |
Gertjan van Wingerde | cea90e5 | 2010-02-13 20:55:47 +0100 | [diff] [blame] | 2621 | if (rt2x00_is_usb(rt2x00dev)) { |
Gertjan van Wingerde | 785c3c0 | 2010-06-03 10:51:59 +0200 | [diff] [blame] | 2622 | rt2800_register_read(rt2x00dev, US_CYC_CNT, ®); |
| 2623 | rt2x00_set_field32(®, US_CYC_CNT_CLOCK_CYCLE, 30); |
| 2624 | rt2800_register_write(rt2x00dev, US_CYC_CNT, reg); |
RA-Jay Hung | c6fcc0e | 2011-01-30 13:21:22 +0100 | [diff] [blame] | 2625 | } else if (rt2x00_is_pcie(rt2x00dev)) { |
| 2626 | rt2800_register_read(rt2x00dev, US_CYC_CNT, ®); |
| 2627 | rt2x00_set_field32(®, US_CYC_CNT_CLOCK_CYCLE, 125); |
| 2628 | rt2800_register_write(rt2x00dev, US_CYC_CNT, reg); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2629 | } |
| 2630 | |
| 2631 | rt2800_register_read(rt2x00dev, HT_FBK_CFG0, ®); |
| 2632 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS0FBK, 0); |
| 2633 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS1FBK, 0); |
| 2634 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS2FBK, 1); |
| 2635 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS3FBK, 2); |
| 2636 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS4FBK, 3); |
| 2637 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS5FBK, 4); |
| 2638 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS6FBK, 5); |
| 2639 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS7FBK, 6); |
| 2640 | rt2800_register_write(rt2x00dev, HT_FBK_CFG0, reg); |
| 2641 | |
| 2642 | rt2800_register_read(rt2x00dev, HT_FBK_CFG1, ®); |
| 2643 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS8FBK, 8); |
| 2644 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS9FBK, 8); |
| 2645 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS10FBK, 9); |
| 2646 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS11FBK, 10); |
| 2647 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS12FBK, 11); |
| 2648 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS13FBK, 12); |
| 2649 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS14FBK, 13); |
| 2650 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS15FBK, 14); |
| 2651 | rt2800_register_write(rt2x00dev, HT_FBK_CFG1, reg); |
| 2652 | |
| 2653 | rt2800_register_read(rt2x00dev, LG_FBK_CFG0, ®); |
| 2654 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS0FBK, 8); |
| 2655 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS1FBK, 8); |
| 2656 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS2FBK, 9); |
| 2657 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS3FBK, 10); |
| 2658 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS4FBK, 11); |
| 2659 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS5FBK, 12); |
| 2660 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS6FBK, 13); |
| 2661 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS7FBK, 14); |
| 2662 | rt2800_register_write(rt2x00dev, LG_FBK_CFG0, reg); |
| 2663 | |
| 2664 | rt2800_register_read(rt2x00dev, LG_FBK_CFG1, ®); |
| 2665 | rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS0FBK, 0); |
| 2666 | rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS1FBK, 0); |
| 2667 | rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS2FBK, 1); |
| 2668 | rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS3FBK, 2); |
| 2669 | rt2800_register_write(rt2x00dev, LG_FBK_CFG1, reg); |
| 2670 | |
| 2671 | /* |
Helmut Schaa | 47ee3eb | 2010-09-08 20:56:04 +0200 | [diff] [blame] | 2672 | * Do not force the BA window size, we use the TXWI to set it |
| 2673 | */ |
| 2674 | rt2800_register_read(rt2x00dev, AMPDU_BA_WINSIZE, ®); |
| 2675 | rt2x00_set_field32(®, AMPDU_BA_WINSIZE_FORCE_WINSIZE_ENABLE, 0); |
| 2676 | rt2x00_set_field32(®, AMPDU_BA_WINSIZE_FORCE_WINSIZE, 0); |
| 2677 | rt2800_register_write(rt2x00dev, AMPDU_BA_WINSIZE, reg); |
| 2678 | |
| 2679 | /* |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2680 | * We must clear the error counters. |
| 2681 | * These registers are cleared on read, |
| 2682 | * so we may pass a useless variable to store the value. |
| 2683 | */ |
| 2684 | rt2800_register_read(rt2x00dev, RX_STA_CNT0, ®); |
| 2685 | rt2800_register_read(rt2x00dev, RX_STA_CNT1, ®); |
| 2686 | rt2800_register_read(rt2x00dev, RX_STA_CNT2, ®); |
| 2687 | rt2800_register_read(rt2x00dev, TX_STA_CNT0, ®); |
| 2688 | rt2800_register_read(rt2x00dev, TX_STA_CNT1, ®); |
| 2689 | rt2800_register_read(rt2x00dev, TX_STA_CNT2, ®); |
| 2690 | |
Helmut Schaa | 9f926fb | 2010-07-11 12:28:23 +0200 | [diff] [blame] | 2691 | /* |
| 2692 | * Setup leadtime for pre tbtt interrupt to 6ms |
| 2693 | */ |
| 2694 | rt2800_register_read(rt2x00dev, INT_TIMER_CFG, ®); |
| 2695 | rt2x00_set_field32(®, INT_TIMER_CFG_PRE_TBTT_TIMER, 6 << 4); |
| 2696 | rt2800_register_write(rt2x00dev, INT_TIMER_CFG, reg); |
| 2697 | |
Helmut Schaa | 977206d | 2010-12-13 12:31:58 +0100 | [diff] [blame] | 2698 | /* |
| 2699 | * Set up channel statistics timer |
| 2700 | */ |
| 2701 | rt2800_register_read(rt2x00dev, CH_TIME_CFG, ®); |
| 2702 | rt2x00_set_field32(®, CH_TIME_CFG_EIFS_BUSY, 1); |
| 2703 | rt2x00_set_field32(®, CH_TIME_CFG_NAV_BUSY, 1); |
| 2704 | rt2x00_set_field32(®, CH_TIME_CFG_RX_BUSY, 1); |
| 2705 | rt2x00_set_field32(®, CH_TIME_CFG_TX_BUSY, 1); |
| 2706 | rt2x00_set_field32(®, CH_TIME_CFG_TMR_EN, 1); |
| 2707 | rt2800_register_write(rt2x00dev, CH_TIME_CFG, reg); |
| 2708 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2709 | return 0; |
| 2710 | } |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2711 | |
| 2712 | static int rt2800_wait_bbp_rf_ready(struct rt2x00_dev *rt2x00dev) |
| 2713 | { |
| 2714 | unsigned int i; |
| 2715 | u32 reg; |
| 2716 | |
| 2717 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
| 2718 | rt2800_register_read(rt2x00dev, MAC_STATUS_CFG, ®); |
| 2719 | if (!rt2x00_get_field32(reg, MAC_STATUS_CFG_BBP_RF_BUSY)) |
| 2720 | return 0; |
| 2721 | |
| 2722 | udelay(REGISTER_BUSY_DELAY); |
| 2723 | } |
| 2724 | |
| 2725 | ERROR(rt2x00dev, "BBP/RF register access failed, aborting.\n"); |
| 2726 | return -EACCES; |
| 2727 | } |
| 2728 | |
| 2729 | static int rt2800_wait_bbp_ready(struct rt2x00_dev *rt2x00dev) |
| 2730 | { |
| 2731 | unsigned int i; |
| 2732 | u8 value; |
| 2733 | |
| 2734 | /* |
| 2735 | * BBP was enabled after firmware was loaded, |
| 2736 | * but we need to reactivate it now. |
| 2737 | */ |
| 2738 | rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0); |
| 2739 | rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0); |
| 2740 | msleep(1); |
| 2741 | |
| 2742 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
| 2743 | rt2800_bbp_read(rt2x00dev, 0, &value); |
| 2744 | if ((value != 0xff) && (value != 0x00)) |
| 2745 | return 0; |
| 2746 | udelay(REGISTER_BUSY_DELAY); |
| 2747 | } |
| 2748 | |
| 2749 | ERROR(rt2x00dev, "BBP register access failed, aborting.\n"); |
| 2750 | return -EACCES; |
| 2751 | } |
| 2752 | |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 2753 | static int rt2800_init_bbp(struct rt2x00_dev *rt2x00dev) |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2754 | { |
| 2755 | unsigned int i; |
| 2756 | u16 eeprom; |
| 2757 | u8 reg_id; |
| 2758 | u8 value; |
| 2759 | |
| 2760 | if (unlikely(rt2800_wait_bbp_rf_ready(rt2x00dev) || |
| 2761 | rt2800_wait_bbp_ready(rt2x00dev))) |
| 2762 | return -EACCES; |
| 2763 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2764 | if (rt2x00_rt(rt2x00dev, RT5390)) { |
| 2765 | rt2800_bbp_read(rt2x00dev, 4, &value); |
| 2766 | rt2x00_set_field8(&value, BBP4_MAC_IF_CTRL, 1); |
| 2767 | rt2800_bbp_write(rt2x00dev, 4, value); |
| 2768 | } |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2769 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2770 | if (rt2800_is_305x_soc(rt2x00dev) || |
| 2771 | rt2x00_rt(rt2x00dev, RT5390)) |
Helmut Schaa | baff800 | 2010-04-28 09:58:59 +0200 | [diff] [blame] | 2772 | rt2800_bbp_write(rt2x00dev, 31, 0x08); |
| 2773 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2774 | rt2800_bbp_write(rt2x00dev, 65, 0x2c); |
| 2775 | rt2800_bbp_write(rt2x00dev, 66, 0x38); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2776 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2777 | if (rt2x00_rt(rt2x00dev, RT5390)) |
| 2778 | rt2800_bbp_write(rt2x00dev, 68, 0x0b); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2779 | |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2780 | if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) { |
| 2781 | rt2800_bbp_write(rt2x00dev, 69, 0x16); |
| 2782 | rt2800_bbp_write(rt2x00dev, 73, 0x12); |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2783 | } else if (rt2x00_rt(rt2x00dev, RT5390)) { |
| 2784 | rt2800_bbp_write(rt2x00dev, 69, 0x12); |
| 2785 | rt2800_bbp_write(rt2x00dev, 73, 0x13); |
| 2786 | rt2800_bbp_write(rt2x00dev, 75, 0x46); |
| 2787 | rt2800_bbp_write(rt2x00dev, 76, 0x28); |
| 2788 | rt2800_bbp_write(rt2x00dev, 77, 0x59); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2789 | } else { |
| 2790 | rt2800_bbp_write(rt2x00dev, 69, 0x12); |
| 2791 | rt2800_bbp_write(rt2x00dev, 73, 0x10); |
| 2792 | } |
| 2793 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2794 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 2795 | |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 2796 | if (rt2x00_rt(rt2x00dev, RT3070) || |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 2797 | rt2x00_rt(rt2x00dev, RT3071) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 2798 | rt2x00_rt(rt2x00dev, RT3090) || |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2799 | rt2x00_rt(rt2x00dev, RT3390) || |
| 2800 | rt2x00_rt(rt2x00dev, RT5390)) { |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 2801 | rt2800_bbp_write(rt2x00dev, 79, 0x13); |
| 2802 | rt2800_bbp_write(rt2x00dev, 80, 0x05); |
| 2803 | rt2800_bbp_write(rt2x00dev, 81, 0x33); |
Helmut Schaa | baff800 | 2010-04-28 09:58:59 +0200 | [diff] [blame] | 2804 | } else if (rt2800_is_305x_soc(rt2x00dev)) { |
| 2805 | rt2800_bbp_write(rt2x00dev, 78, 0x0e); |
| 2806 | rt2800_bbp_write(rt2x00dev, 80, 0x08); |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 2807 | } else { |
| 2808 | rt2800_bbp_write(rt2x00dev, 81, 0x37); |
| 2809 | } |
| 2810 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2811 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2812 | if (rt2x00_rt(rt2x00dev, RT5390)) |
| 2813 | rt2800_bbp_write(rt2x00dev, 83, 0x7a); |
| 2814 | else |
| 2815 | rt2800_bbp_write(rt2x00dev, 83, 0x6a); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2816 | |
Gertjan van Wingerde | 5ed8f45 | 2010-06-03 10:51:57 +0200 | [diff] [blame] | 2817 | if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860D)) |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2818 | rt2800_bbp_write(rt2x00dev, 84, 0x19); |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2819 | else if (rt2x00_rt(rt2x00dev, RT5390)) |
| 2820 | rt2800_bbp_write(rt2x00dev, 84, 0x9a); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 2821 | else |
| 2822 | rt2800_bbp_write(rt2x00dev, 84, 0x99); |
| 2823 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2824 | if (rt2x00_rt(rt2x00dev, RT5390)) |
| 2825 | rt2800_bbp_write(rt2x00dev, 86, 0x38); |
| 2826 | else |
| 2827 | rt2800_bbp_write(rt2x00dev, 86, 0x00); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2828 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2829 | rt2800_bbp_write(rt2x00dev, 91, 0x04); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2830 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2831 | if (rt2x00_rt(rt2x00dev, RT5390)) |
| 2832 | rt2800_bbp_write(rt2x00dev, 92, 0x02); |
| 2833 | else |
| 2834 | rt2800_bbp_write(rt2x00dev, 92, 0x00); |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 2835 | |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 2836 | if (rt2x00_rt_rev_gte(rt2x00dev, RT3070, REV_RT3070F) || |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 2837 | rt2x00_rt_rev_gte(rt2x00dev, RT3071, REV_RT3071E) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 2838 | rt2x00_rt_rev_gte(rt2x00dev, RT3090, REV_RT3090E) || |
Helmut Schaa | baff800 | 2010-04-28 09:58:59 +0200 | [diff] [blame] | 2839 | rt2x00_rt_rev_gte(rt2x00dev, RT3390, REV_RT3390E) || |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2840 | rt2x00_rt(rt2x00dev, RT5390) || |
Helmut Schaa | baff800 | 2010-04-28 09:58:59 +0200 | [diff] [blame] | 2841 | rt2800_is_305x_soc(rt2x00dev)) |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 2842 | rt2800_bbp_write(rt2x00dev, 103, 0xc0); |
| 2843 | else |
| 2844 | rt2800_bbp_write(rt2x00dev, 103, 0x00); |
| 2845 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2846 | if (rt2x00_rt(rt2x00dev, RT5390)) |
| 2847 | rt2800_bbp_write(rt2x00dev, 104, 0x92); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2848 | |
Helmut Schaa | baff800 | 2010-04-28 09:58:59 +0200 | [diff] [blame] | 2849 | if (rt2800_is_305x_soc(rt2x00dev)) |
| 2850 | rt2800_bbp_write(rt2x00dev, 105, 0x01); |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2851 | else if (rt2x00_rt(rt2x00dev, RT5390)) |
| 2852 | rt2800_bbp_write(rt2x00dev, 105, 0x3c); |
Helmut Schaa | baff800 | 2010-04-28 09:58:59 +0200 | [diff] [blame] | 2853 | else |
| 2854 | rt2800_bbp_write(rt2x00dev, 105, 0x05); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2855 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2856 | if (rt2x00_rt(rt2x00dev, RT5390)) |
| 2857 | rt2800_bbp_write(rt2x00dev, 106, 0x03); |
| 2858 | else |
| 2859 | rt2800_bbp_write(rt2x00dev, 106, 0x35); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2860 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2861 | if (rt2x00_rt(rt2x00dev, RT5390)) |
| 2862 | rt2800_bbp_write(rt2x00dev, 128, 0x12); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2863 | |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 2864 | if (rt2x00_rt(rt2x00dev, RT3071) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 2865 | rt2x00_rt(rt2x00dev, RT3090) || |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2866 | rt2x00_rt(rt2x00dev, RT3390) || |
| 2867 | rt2x00_rt(rt2x00dev, RT5390)) { |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 2868 | rt2800_bbp_read(rt2x00dev, 138, &value); |
| 2869 | |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 2870 | rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom); |
| 2871 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) == 1) |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 2872 | value |= 0x20; |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 2873 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) == 1) |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 2874 | value &= ~0x02; |
| 2875 | |
| 2876 | rt2800_bbp_write(rt2x00dev, 138, value); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2877 | } |
| 2878 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2879 | if (rt2x00_rt(rt2x00dev, RT5390)) { |
| 2880 | int ant, div_mode; |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2881 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2882 | rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom); |
| 2883 | div_mode = rt2x00_get_field16(eeprom, |
| 2884 | EEPROM_NIC_CONF1_ANT_DIVERSITY); |
| 2885 | ant = (div_mode == 3) ? 1 : 0; |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2886 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2887 | /* check if this is a Bluetooth combo card */ |
| 2888 | rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom); |
| 2889 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_BT_COEXIST)) { |
| 2890 | u32 reg; |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2891 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2892 | rt2800_register_read(rt2x00dev, GPIO_CTRL_CFG, ®); |
| 2893 | rt2x00_set_field32(®, GPIO_CTRL_CFG_GPIOD_BIT3, 0); |
| 2894 | rt2x00_set_field32(®, GPIO_CTRL_CFG_GPIOD_BIT6, 0); |
| 2895 | rt2x00_set_field32(®, GPIO_CTRL_CFG_BIT3, 0); |
| 2896 | rt2x00_set_field32(®, GPIO_CTRL_CFG_BIT6, 0); |
| 2897 | if (ant == 0) |
| 2898 | rt2x00_set_field32(®, GPIO_CTRL_CFG_BIT3, 1); |
| 2899 | else if (ant == 1) |
| 2900 | rt2x00_set_field32(®, GPIO_CTRL_CFG_BIT6, 1); |
| 2901 | rt2800_register_write(rt2x00dev, GPIO_CTRL_CFG, reg); |
| 2902 | } |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2903 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2904 | rt2800_bbp_read(rt2x00dev, 152, &value); |
| 2905 | if (ant == 0) |
| 2906 | rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 1); |
| 2907 | else |
| 2908 | rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 0); |
| 2909 | rt2800_bbp_write(rt2x00dev, 152, value); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2910 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2911 | /* Init frequency calibration */ |
| 2912 | rt2800_bbp_write(rt2x00dev, 142, 1); |
| 2913 | rt2800_bbp_write(rt2x00dev, 143, 57); |
| 2914 | } |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2915 | |
| 2916 | for (i = 0; i < EEPROM_BBP_SIZE; i++) { |
| 2917 | rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom); |
| 2918 | |
| 2919 | if (eeprom != 0xffff && eeprom != 0x0000) { |
| 2920 | reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID); |
| 2921 | value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE); |
| 2922 | rt2800_bbp_write(rt2x00dev, reg_id, value); |
| 2923 | } |
| 2924 | } |
| 2925 | |
| 2926 | return 0; |
| 2927 | } |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2928 | |
| 2929 | static u8 rt2800_init_rx_filter(struct rt2x00_dev *rt2x00dev, |
| 2930 | bool bw40, u8 rfcsr24, u8 filter_target) |
| 2931 | { |
| 2932 | unsigned int i; |
| 2933 | u8 bbp; |
| 2934 | u8 rfcsr; |
| 2935 | u8 passband; |
| 2936 | u8 stopband; |
| 2937 | u8 overtuned = 0; |
| 2938 | |
| 2939 | rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24); |
| 2940 | |
| 2941 | rt2800_bbp_read(rt2x00dev, 4, &bbp); |
| 2942 | rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * bw40); |
| 2943 | rt2800_bbp_write(rt2x00dev, 4, bbp); |
| 2944 | |
RA-Jay Hung | 80d184e | 2011-01-10 11:28:10 +0100 | [diff] [blame] | 2945 | rt2800_rfcsr_read(rt2x00dev, 31, &rfcsr); |
| 2946 | rt2x00_set_field8(&rfcsr, RFCSR31_RX_H20M, bw40); |
| 2947 | rt2800_rfcsr_write(rt2x00dev, 31, rfcsr); |
| 2948 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2949 | rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr); |
| 2950 | rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 1); |
| 2951 | rt2800_rfcsr_write(rt2x00dev, 22, rfcsr); |
| 2952 | |
| 2953 | /* |
| 2954 | * Set power & frequency of passband test tone |
| 2955 | */ |
| 2956 | rt2800_bbp_write(rt2x00dev, 24, 0); |
| 2957 | |
| 2958 | for (i = 0; i < 100; i++) { |
| 2959 | rt2800_bbp_write(rt2x00dev, 25, 0x90); |
| 2960 | msleep(1); |
| 2961 | |
| 2962 | rt2800_bbp_read(rt2x00dev, 55, &passband); |
| 2963 | if (passband) |
| 2964 | break; |
| 2965 | } |
| 2966 | |
| 2967 | /* |
| 2968 | * Set power & frequency of stopband test tone |
| 2969 | */ |
| 2970 | rt2800_bbp_write(rt2x00dev, 24, 0x06); |
| 2971 | |
| 2972 | for (i = 0; i < 100; i++) { |
| 2973 | rt2800_bbp_write(rt2x00dev, 25, 0x90); |
| 2974 | msleep(1); |
| 2975 | |
| 2976 | rt2800_bbp_read(rt2x00dev, 55, &stopband); |
| 2977 | |
| 2978 | if ((passband - stopband) <= filter_target) { |
| 2979 | rfcsr24++; |
| 2980 | overtuned += ((passband - stopband) == filter_target); |
| 2981 | } else |
| 2982 | break; |
| 2983 | |
| 2984 | rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24); |
| 2985 | } |
| 2986 | |
| 2987 | rfcsr24 -= !!overtuned; |
| 2988 | |
| 2989 | rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24); |
| 2990 | return rfcsr24; |
| 2991 | } |
| 2992 | |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 2993 | static int rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev) |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2994 | { |
| 2995 | u8 rfcsr; |
| 2996 | u8 bbp; |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 2997 | u32 reg; |
| 2998 | u16 eeprom; |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2999 | |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 3000 | if (!rt2x00_rt(rt2x00dev, RT3070) && |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 3001 | !rt2x00_rt(rt2x00dev, RT3071) && |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 3002 | !rt2x00_rt(rt2x00dev, RT3090) && |
Helmut Schaa | 2381238 | 2010-04-26 13:48:45 +0200 | [diff] [blame] | 3003 | !rt2x00_rt(rt2x00dev, RT3390) && |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3004 | !rt2x00_rt(rt2x00dev, RT5390) && |
Helmut Schaa | baff800 | 2010-04-28 09:58:59 +0200 | [diff] [blame] | 3005 | !rt2800_is_305x_soc(rt2x00dev)) |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 3006 | return 0; |
| 3007 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 3008 | /* |
| 3009 | * Init RF calibration. |
| 3010 | */ |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3011 | if (rt2x00_rt(rt2x00dev, RT5390)) { |
| 3012 | rt2800_rfcsr_read(rt2x00dev, 2, &rfcsr); |
| 3013 | rt2x00_set_field8(&rfcsr, RFCSR2_RESCAL_EN, 1); |
| 3014 | rt2800_rfcsr_write(rt2x00dev, 2, rfcsr); |
| 3015 | msleep(1); |
| 3016 | rt2x00_set_field8(&rfcsr, RFCSR2_RESCAL_EN, 0); |
| 3017 | rt2800_rfcsr_write(rt2x00dev, 2, rfcsr); |
| 3018 | } else { |
| 3019 | rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr); |
| 3020 | rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1); |
| 3021 | rt2800_rfcsr_write(rt2x00dev, 30, rfcsr); |
| 3022 | msleep(1); |
| 3023 | rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0); |
| 3024 | rt2800_rfcsr_write(rt2x00dev, 30, rfcsr); |
| 3025 | } |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 3026 | |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 3027 | if (rt2x00_rt(rt2x00dev, RT3070) || |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 3028 | rt2x00_rt(rt2x00dev, RT3071) || |
| 3029 | rt2x00_rt(rt2x00dev, RT3090)) { |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 3030 | rt2800_rfcsr_write(rt2x00dev, 4, 0x40); |
| 3031 | rt2800_rfcsr_write(rt2x00dev, 5, 0x03); |
| 3032 | rt2800_rfcsr_write(rt2x00dev, 6, 0x02); |
RA-Jay Hung | 80d184e | 2011-01-10 11:28:10 +0100 | [diff] [blame] | 3033 | rt2800_rfcsr_write(rt2x00dev, 7, 0x60); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 3034 | rt2800_rfcsr_write(rt2x00dev, 9, 0x0f); |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 3035 | rt2800_rfcsr_write(rt2x00dev, 10, 0x41); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 3036 | rt2800_rfcsr_write(rt2x00dev, 11, 0x21); |
| 3037 | rt2800_rfcsr_write(rt2x00dev, 12, 0x7b); |
| 3038 | rt2800_rfcsr_write(rt2x00dev, 14, 0x90); |
| 3039 | rt2800_rfcsr_write(rt2x00dev, 15, 0x58); |
| 3040 | rt2800_rfcsr_write(rt2x00dev, 16, 0xb3); |
| 3041 | rt2800_rfcsr_write(rt2x00dev, 17, 0x92); |
| 3042 | rt2800_rfcsr_write(rt2x00dev, 18, 0x2c); |
| 3043 | rt2800_rfcsr_write(rt2x00dev, 19, 0x02); |
| 3044 | rt2800_rfcsr_write(rt2x00dev, 20, 0xba); |
| 3045 | rt2800_rfcsr_write(rt2x00dev, 21, 0xdb); |
| 3046 | rt2800_rfcsr_write(rt2x00dev, 24, 0x16); |
| 3047 | rt2800_rfcsr_write(rt2x00dev, 25, 0x01); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 3048 | rt2800_rfcsr_write(rt2x00dev, 29, 0x1f); |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 3049 | } else if (rt2x00_rt(rt2x00dev, RT3390)) { |
| 3050 | rt2800_rfcsr_write(rt2x00dev, 0, 0xa0); |
| 3051 | rt2800_rfcsr_write(rt2x00dev, 1, 0xe1); |
| 3052 | rt2800_rfcsr_write(rt2x00dev, 2, 0xf1); |
| 3053 | rt2800_rfcsr_write(rt2x00dev, 3, 0x62); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 3054 | rt2800_rfcsr_write(rt2x00dev, 4, 0x40); |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 3055 | rt2800_rfcsr_write(rt2x00dev, 5, 0x8b); |
| 3056 | rt2800_rfcsr_write(rt2x00dev, 6, 0x42); |
| 3057 | rt2800_rfcsr_write(rt2x00dev, 7, 0x34); |
| 3058 | rt2800_rfcsr_write(rt2x00dev, 8, 0x00); |
| 3059 | rt2800_rfcsr_write(rt2x00dev, 9, 0xc0); |
| 3060 | rt2800_rfcsr_write(rt2x00dev, 10, 0x61); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 3061 | rt2800_rfcsr_write(rt2x00dev, 11, 0x21); |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 3062 | rt2800_rfcsr_write(rt2x00dev, 12, 0x3b); |
| 3063 | rt2800_rfcsr_write(rt2x00dev, 13, 0xe0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 3064 | rt2800_rfcsr_write(rt2x00dev, 14, 0x90); |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 3065 | rt2800_rfcsr_write(rt2x00dev, 15, 0x53); |
| 3066 | rt2800_rfcsr_write(rt2x00dev, 16, 0xe0); |
| 3067 | rt2800_rfcsr_write(rt2x00dev, 17, 0x94); |
| 3068 | rt2800_rfcsr_write(rt2x00dev, 18, 0x5c); |
| 3069 | rt2800_rfcsr_write(rt2x00dev, 19, 0x4a); |
| 3070 | rt2800_rfcsr_write(rt2x00dev, 20, 0xb2); |
| 3071 | rt2800_rfcsr_write(rt2x00dev, 21, 0xf6); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 3072 | rt2800_rfcsr_write(rt2x00dev, 22, 0x00); |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 3073 | rt2800_rfcsr_write(rt2x00dev, 23, 0x14); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 3074 | rt2800_rfcsr_write(rt2x00dev, 24, 0x08); |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 3075 | rt2800_rfcsr_write(rt2x00dev, 25, 0x3d); |
| 3076 | rt2800_rfcsr_write(rt2x00dev, 26, 0x85); |
| 3077 | rt2800_rfcsr_write(rt2x00dev, 27, 0x00); |
| 3078 | rt2800_rfcsr_write(rt2x00dev, 28, 0x41); |
| 3079 | rt2800_rfcsr_write(rt2x00dev, 29, 0x8f); |
| 3080 | rt2800_rfcsr_write(rt2x00dev, 30, 0x20); |
| 3081 | rt2800_rfcsr_write(rt2x00dev, 31, 0x0f); |
Helmut Schaa | baff800 | 2010-04-28 09:58:59 +0200 | [diff] [blame] | 3082 | } else if (rt2800_is_305x_soc(rt2x00dev)) { |
Helmut Schaa | 2381238 | 2010-04-26 13:48:45 +0200 | [diff] [blame] | 3083 | rt2800_rfcsr_write(rt2x00dev, 0, 0x50); |
| 3084 | rt2800_rfcsr_write(rt2x00dev, 1, 0x01); |
| 3085 | rt2800_rfcsr_write(rt2x00dev, 2, 0xf7); |
| 3086 | rt2800_rfcsr_write(rt2x00dev, 3, 0x75); |
| 3087 | rt2800_rfcsr_write(rt2x00dev, 4, 0x40); |
| 3088 | rt2800_rfcsr_write(rt2x00dev, 5, 0x03); |
| 3089 | rt2800_rfcsr_write(rt2x00dev, 6, 0x02); |
| 3090 | rt2800_rfcsr_write(rt2x00dev, 7, 0x50); |
| 3091 | rt2800_rfcsr_write(rt2x00dev, 8, 0x39); |
| 3092 | rt2800_rfcsr_write(rt2x00dev, 9, 0x0f); |
| 3093 | rt2800_rfcsr_write(rt2x00dev, 10, 0x60); |
| 3094 | rt2800_rfcsr_write(rt2x00dev, 11, 0x21); |
| 3095 | rt2800_rfcsr_write(rt2x00dev, 12, 0x75); |
| 3096 | rt2800_rfcsr_write(rt2x00dev, 13, 0x75); |
| 3097 | rt2800_rfcsr_write(rt2x00dev, 14, 0x90); |
| 3098 | rt2800_rfcsr_write(rt2x00dev, 15, 0x58); |
| 3099 | rt2800_rfcsr_write(rt2x00dev, 16, 0xb3); |
| 3100 | rt2800_rfcsr_write(rt2x00dev, 17, 0x92); |
| 3101 | rt2800_rfcsr_write(rt2x00dev, 18, 0x2c); |
| 3102 | rt2800_rfcsr_write(rt2x00dev, 19, 0x02); |
| 3103 | rt2800_rfcsr_write(rt2x00dev, 20, 0xba); |
| 3104 | rt2800_rfcsr_write(rt2x00dev, 21, 0xdb); |
| 3105 | rt2800_rfcsr_write(rt2x00dev, 22, 0x00); |
| 3106 | rt2800_rfcsr_write(rt2x00dev, 23, 0x31); |
| 3107 | rt2800_rfcsr_write(rt2x00dev, 24, 0x08); |
| 3108 | rt2800_rfcsr_write(rt2x00dev, 25, 0x01); |
| 3109 | rt2800_rfcsr_write(rt2x00dev, 26, 0x25); |
| 3110 | rt2800_rfcsr_write(rt2x00dev, 27, 0x23); |
| 3111 | rt2800_rfcsr_write(rt2x00dev, 28, 0x13); |
| 3112 | rt2800_rfcsr_write(rt2x00dev, 29, 0x83); |
Helmut Schaa | baff800 | 2010-04-28 09:58:59 +0200 | [diff] [blame] | 3113 | rt2800_rfcsr_write(rt2x00dev, 30, 0x00); |
| 3114 | rt2800_rfcsr_write(rt2x00dev, 31, 0x00); |
| 3115 | return 0; |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3116 | } else if (rt2x00_rt(rt2x00dev, RT5390)) { |
| 3117 | rt2800_rfcsr_write(rt2x00dev, 1, 0x0f); |
| 3118 | rt2800_rfcsr_write(rt2x00dev, 2, 0x80); |
| 3119 | rt2800_rfcsr_write(rt2x00dev, 3, 0x88); |
| 3120 | rt2800_rfcsr_write(rt2x00dev, 5, 0x10); |
| 3121 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) |
| 3122 | rt2800_rfcsr_write(rt2x00dev, 6, 0xe0); |
| 3123 | else |
| 3124 | rt2800_rfcsr_write(rt2x00dev, 6, 0xa0); |
| 3125 | rt2800_rfcsr_write(rt2x00dev, 7, 0x00); |
| 3126 | rt2800_rfcsr_write(rt2x00dev, 10, 0x53); |
| 3127 | rt2800_rfcsr_write(rt2x00dev, 11, 0x4a); |
| 3128 | rt2800_rfcsr_write(rt2x00dev, 12, 0xc6); |
| 3129 | rt2800_rfcsr_write(rt2x00dev, 13, 0x9f); |
| 3130 | rt2800_rfcsr_write(rt2x00dev, 14, 0x00); |
| 3131 | rt2800_rfcsr_write(rt2x00dev, 15, 0x00); |
| 3132 | rt2800_rfcsr_write(rt2x00dev, 16, 0x00); |
| 3133 | rt2800_rfcsr_write(rt2x00dev, 18, 0x03); |
| 3134 | rt2800_rfcsr_write(rt2x00dev, 19, 0x00); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 3135 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3136 | rt2800_rfcsr_write(rt2x00dev, 20, 0x00); |
| 3137 | rt2800_rfcsr_write(rt2x00dev, 21, 0x00); |
| 3138 | rt2800_rfcsr_write(rt2x00dev, 22, 0x20); |
| 3139 | rt2800_rfcsr_write(rt2x00dev, 23, 0x00); |
| 3140 | rt2800_rfcsr_write(rt2x00dev, 24, 0x00); |
| 3141 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) |
| 3142 | rt2800_rfcsr_write(rt2x00dev, 25, 0x80); |
| 3143 | else |
| 3144 | rt2800_rfcsr_write(rt2x00dev, 25, 0xc0); |
| 3145 | rt2800_rfcsr_write(rt2x00dev, 26, 0x00); |
| 3146 | rt2800_rfcsr_write(rt2x00dev, 27, 0x09); |
| 3147 | rt2800_rfcsr_write(rt2x00dev, 28, 0x00); |
| 3148 | rt2800_rfcsr_write(rt2x00dev, 29, 0x10); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 3149 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3150 | rt2800_rfcsr_write(rt2x00dev, 30, 0x00); |
| 3151 | rt2800_rfcsr_write(rt2x00dev, 31, 0x80); |
| 3152 | rt2800_rfcsr_write(rt2x00dev, 32, 0x80); |
| 3153 | rt2800_rfcsr_write(rt2x00dev, 33, 0x00); |
| 3154 | rt2800_rfcsr_write(rt2x00dev, 34, 0x07); |
| 3155 | rt2800_rfcsr_write(rt2x00dev, 35, 0x12); |
| 3156 | rt2800_rfcsr_write(rt2x00dev, 36, 0x00); |
| 3157 | rt2800_rfcsr_write(rt2x00dev, 37, 0x08); |
| 3158 | rt2800_rfcsr_write(rt2x00dev, 38, 0x85); |
| 3159 | rt2800_rfcsr_write(rt2x00dev, 39, 0x1b); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 3160 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3161 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) |
| 3162 | rt2800_rfcsr_write(rt2x00dev, 40, 0x0b); |
| 3163 | else |
| 3164 | rt2800_rfcsr_write(rt2x00dev, 40, 0x4b); |
| 3165 | rt2800_rfcsr_write(rt2x00dev, 41, 0xbb); |
| 3166 | rt2800_rfcsr_write(rt2x00dev, 42, 0xd2); |
| 3167 | rt2800_rfcsr_write(rt2x00dev, 43, 0x9a); |
| 3168 | rt2800_rfcsr_write(rt2x00dev, 44, 0x0e); |
| 3169 | rt2800_rfcsr_write(rt2x00dev, 45, 0xa2); |
| 3170 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) |
| 3171 | rt2800_rfcsr_write(rt2x00dev, 46, 0x73); |
| 3172 | else |
| 3173 | rt2800_rfcsr_write(rt2x00dev, 46, 0x7b); |
| 3174 | rt2800_rfcsr_write(rt2x00dev, 47, 0x00); |
| 3175 | rt2800_rfcsr_write(rt2x00dev, 48, 0x10); |
| 3176 | rt2800_rfcsr_write(rt2x00dev, 49, 0x94); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 3177 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3178 | rt2800_rfcsr_write(rt2x00dev, 52, 0x38); |
| 3179 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) |
| 3180 | rt2800_rfcsr_write(rt2x00dev, 53, 0x00); |
| 3181 | else |
| 3182 | rt2800_rfcsr_write(rt2x00dev, 53, 0x84); |
| 3183 | rt2800_rfcsr_write(rt2x00dev, 54, 0x78); |
| 3184 | rt2800_rfcsr_write(rt2x00dev, 55, 0x44); |
| 3185 | rt2800_rfcsr_write(rt2x00dev, 56, 0x22); |
| 3186 | rt2800_rfcsr_write(rt2x00dev, 57, 0x80); |
| 3187 | rt2800_rfcsr_write(rt2x00dev, 58, 0x7f); |
| 3188 | rt2800_rfcsr_write(rt2x00dev, 59, 0x63); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 3189 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3190 | rt2800_rfcsr_write(rt2x00dev, 60, 0x45); |
| 3191 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) |
| 3192 | rt2800_rfcsr_write(rt2x00dev, 61, 0xd1); |
| 3193 | else |
| 3194 | rt2800_rfcsr_write(rt2x00dev, 61, 0xdd); |
| 3195 | rt2800_rfcsr_write(rt2x00dev, 62, 0x00); |
| 3196 | rt2800_rfcsr_write(rt2x00dev, 63, 0x00); |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 3197 | } |
| 3198 | |
| 3199 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) { |
| 3200 | rt2800_register_read(rt2x00dev, LDO_CFG0, ®); |
| 3201 | rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1); |
| 3202 | rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 3); |
| 3203 | rt2800_register_write(rt2x00dev, LDO_CFG0, reg); |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 3204 | } else if (rt2x00_rt(rt2x00dev, RT3071) || |
| 3205 | rt2x00_rt(rt2x00dev, RT3090)) { |
RA-Jay Hung | 80d184e | 2011-01-10 11:28:10 +0100 | [diff] [blame] | 3206 | rt2800_rfcsr_write(rt2x00dev, 31, 0x14); |
| 3207 | |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 3208 | rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr); |
| 3209 | rt2x00_set_field8(&rfcsr, RFCSR6_R2, 1); |
| 3210 | rt2800_rfcsr_write(rt2x00dev, 6, rfcsr); |
| 3211 | |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 3212 | rt2800_register_read(rt2x00dev, LDO_CFG0, ®); |
| 3213 | rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1); |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 3214 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) || |
| 3215 | rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E)) { |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3216 | rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom); |
| 3217 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_DAC_TEST)) |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 3218 | rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 3); |
| 3219 | else |
| 3220 | rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 0); |
| 3221 | } |
| 3222 | rt2800_register_write(rt2x00dev, LDO_CFG0, reg); |
RA-Jay Hung | 80d184e | 2011-01-10 11:28:10 +0100 | [diff] [blame] | 3223 | |
| 3224 | rt2800_register_read(rt2x00dev, GPIO_SWITCH, ®); |
| 3225 | rt2x00_set_field32(®, GPIO_SWITCH_5, 0); |
| 3226 | rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg); |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 3227 | } else if (rt2x00_rt(rt2x00dev, RT3390)) { |
| 3228 | rt2800_register_read(rt2x00dev, GPIO_SWITCH, ®); |
| 3229 | rt2x00_set_field32(®, GPIO_SWITCH_5, 0); |
| 3230 | rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 3231 | } |
| 3232 | |
| 3233 | /* |
| 3234 | * Set RX Filter calibration for 20MHz and 40MHz |
| 3235 | */ |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 3236 | if (rt2x00_rt(rt2x00dev, RT3070)) { |
| 3237 | rt2x00dev->calibration[0] = |
| 3238 | rt2800_init_rx_filter(rt2x00dev, false, 0x07, 0x16); |
| 3239 | rt2x00dev->calibration[1] = |
| 3240 | rt2800_init_rx_filter(rt2x00dev, true, 0x27, 0x19); |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 3241 | } else if (rt2x00_rt(rt2x00dev, RT3071) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 3242 | rt2x00_rt(rt2x00dev, RT3090) || |
| 3243 | rt2x00_rt(rt2x00dev, RT3390)) { |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 3244 | rt2x00dev->calibration[0] = |
| 3245 | rt2800_init_rx_filter(rt2x00dev, false, 0x07, 0x13); |
| 3246 | rt2x00dev->calibration[1] = |
| 3247 | rt2800_init_rx_filter(rt2x00dev, true, 0x27, 0x15); |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 3248 | } |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 3249 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3250 | if (!rt2x00_rt(rt2x00dev, RT5390)) { |
| 3251 | /* |
| 3252 | * Set back to initial state |
| 3253 | */ |
| 3254 | rt2800_bbp_write(rt2x00dev, 24, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 3255 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3256 | rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr); |
| 3257 | rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 0); |
| 3258 | rt2800_rfcsr_write(rt2x00dev, 22, rfcsr); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 3259 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3260 | /* |
| 3261 | * Set BBP back to BW20 |
| 3262 | */ |
| 3263 | rt2800_bbp_read(rt2x00dev, 4, &bbp); |
| 3264 | rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0); |
| 3265 | rt2800_bbp_write(rt2x00dev, 4, bbp); |
| 3266 | } |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 3267 | |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 3268 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F) || |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 3269 | rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 3270 | rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E) || |
| 3271 | rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 3272 | rt2800_rfcsr_write(rt2x00dev, 27, 0x03); |
| 3273 | |
| 3274 | rt2800_register_read(rt2x00dev, OPT_14_CSR, ®); |
| 3275 | rt2x00_set_field32(®, OPT_14_CSR_BIT0, 1); |
| 3276 | rt2800_register_write(rt2x00dev, OPT_14_CSR, reg); |
| 3277 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3278 | if (!rt2x00_rt(rt2x00dev, RT5390)) { |
| 3279 | rt2800_rfcsr_read(rt2x00dev, 17, &rfcsr); |
| 3280 | rt2x00_set_field8(&rfcsr, RFCSR17_TX_LO1_EN, 0); |
| 3281 | if (rt2x00_rt(rt2x00dev, RT3070) || |
| 3282 | rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) || |
| 3283 | rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E) || |
| 3284 | rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) { |
| 3285 | if (!test_bit(CONFIG_EXTERNAL_LNA_BG, |
| 3286 | &rt2x00dev->flags)) |
| 3287 | rt2x00_set_field8(&rfcsr, RFCSR17_R, 1); |
| 3288 | } |
| 3289 | rt2x00_eeprom_read(rt2x00dev, EEPROM_TXMIXER_GAIN_BG, &eeprom); |
| 3290 | if (rt2x00_get_field16(eeprom, EEPROM_TXMIXER_GAIN_BG_VAL) >= 1) |
| 3291 | rt2x00_set_field8(&rfcsr, RFCSR17_TXMIXER_GAIN, |
| 3292 | rt2x00_get_field16(eeprom, |
| 3293 | EEPROM_TXMIXER_GAIN_BG_VAL)); |
| 3294 | rt2800_rfcsr_write(rt2x00dev, 17, rfcsr); |
| 3295 | } |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 3296 | |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 3297 | if (rt2x00_rt(rt2x00dev, RT3090)) { |
| 3298 | rt2800_bbp_read(rt2x00dev, 138, &bbp); |
| 3299 | |
RA-Jay Hung | 80d184e | 2011-01-10 11:28:10 +0100 | [diff] [blame] | 3300 | /* Turn off unused DAC1 and ADC1 to reduce power consumption */ |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3301 | rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom); |
| 3302 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) == 1) |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 3303 | rt2x00_set_field8(&bbp, BBP138_RX_ADC1, 0); |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3304 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) == 1) |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 3305 | rt2x00_set_field8(&bbp, BBP138_TX_DAC1, 1); |
| 3306 | |
| 3307 | rt2800_bbp_write(rt2x00dev, 138, bbp); |
| 3308 | } |
| 3309 | |
| 3310 | if (rt2x00_rt(rt2x00dev, RT3071) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 3311 | rt2x00_rt(rt2x00dev, RT3090) || |
| 3312 | rt2x00_rt(rt2x00dev, RT3390)) { |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 3313 | rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr); |
| 3314 | rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1); |
| 3315 | rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0); |
| 3316 | rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0); |
| 3317 | rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1); |
| 3318 | rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1); |
| 3319 | rt2800_rfcsr_write(rt2x00dev, 1, rfcsr); |
| 3320 | |
| 3321 | rt2800_rfcsr_read(rt2x00dev, 15, &rfcsr); |
| 3322 | rt2x00_set_field8(&rfcsr, RFCSR15_TX_LO2_EN, 0); |
| 3323 | rt2800_rfcsr_write(rt2x00dev, 15, rfcsr); |
| 3324 | |
| 3325 | rt2800_rfcsr_read(rt2x00dev, 20, &rfcsr); |
| 3326 | rt2x00_set_field8(&rfcsr, RFCSR20_RX_LO1_EN, 0); |
| 3327 | rt2800_rfcsr_write(rt2x00dev, 20, rfcsr); |
| 3328 | |
| 3329 | rt2800_rfcsr_read(rt2x00dev, 21, &rfcsr); |
| 3330 | rt2x00_set_field8(&rfcsr, RFCSR21_RX_LO2_EN, 0); |
| 3331 | rt2800_rfcsr_write(rt2x00dev, 21, rfcsr); |
| 3332 | } |
| 3333 | |
RA-Jay Hung | 80d184e | 2011-01-10 11:28:10 +0100 | [diff] [blame] | 3334 | if (rt2x00_rt(rt2x00dev, RT3070)) { |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 3335 | rt2800_rfcsr_read(rt2x00dev, 27, &rfcsr); |
RA-Jay Hung | 80d184e | 2011-01-10 11:28:10 +0100 | [diff] [blame] | 3336 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 3337 | rt2x00_set_field8(&rfcsr, RFCSR27_R1, 3); |
| 3338 | else |
| 3339 | rt2x00_set_field8(&rfcsr, RFCSR27_R1, 0); |
| 3340 | rt2x00_set_field8(&rfcsr, RFCSR27_R2, 0); |
| 3341 | rt2x00_set_field8(&rfcsr, RFCSR27_R3, 0); |
| 3342 | rt2x00_set_field8(&rfcsr, RFCSR27_R4, 0); |
| 3343 | rt2800_rfcsr_write(rt2x00dev, 27, rfcsr); |
| 3344 | } |
| 3345 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3346 | if (rt2x00_rt(rt2x00dev, RT5390)) { |
| 3347 | rt2800_rfcsr_read(rt2x00dev, 38, &rfcsr); |
| 3348 | rt2x00_set_field8(&rfcsr, RFCSR38_RX_LO1_EN, 0); |
| 3349 | rt2800_rfcsr_write(rt2x00dev, 38, rfcsr); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 3350 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3351 | rt2800_rfcsr_read(rt2x00dev, 39, &rfcsr); |
| 3352 | rt2x00_set_field8(&rfcsr, RFCSR39_RX_LO2_EN, 0); |
| 3353 | rt2800_rfcsr_write(rt2x00dev, 39, rfcsr); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 3354 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3355 | rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr); |
| 3356 | rt2x00_set_field8(&rfcsr, RFCSR30_RX_VCM, 2); |
| 3357 | rt2800_rfcsr_write(rt2x00dev, 30, rfcsr); |
| 3358 | } |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 3359 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 3360 | return 0; |
| 3361 | } |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 3362 | |
| 3363 | int rt2800_enable_radio(struct rt2x00_dev *rt2x00dev) |
| 3364 | { |
| 3365 | u32 reg; |
| 3366 | u16 word; |
| 3367 | |
| 3368 | /* |
| 3369 | * Initialize all registers. |
| 3370 | */ |
| 3371 | if (unlikely(rt2800_wait_wpdma_ready(rt2x00dev) || |
| 3372 | rt2800_init_registers(rt2x00dev) || |
| 3373 | rt2800_init_bbp(rt2x00dev) || |
| 3374 | rt2800_init_rfcsr(rt2x00dev))) |
| 3375 | return -EIO; |
| 3376 | |
| 3377 | /* |
| 3378 | * Send signal to firmware during boot time. |
| 3379 | */ |
| 3380 | rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0, 0, 0); |
| 3381 | |
| 3382 | if (rt2x00_is_usb(rt2x00dev) && |
| 3383 | (rt2x00_rt(rt2x00dev, RT3070) || |
| 3384 | rt2x00_rt(rt2x00dev, RT3071) || |
| 3385 | rt2x00_rt(rt2x00dev, RT3572))) { |
| 3386 | udelay(200); |
| 3387 | rt2800_mcu_request(rt2x00dev, MCU_CURRENT, 0, 0, 0); |
| 3388 | udelay(10); |
| 3389 | } |
| 3390 | |
| 3391 | /* |
| 3392 | * Enable RX. |
| 3393 | */ |
| 3394 | rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, ®); |
| 3395 | rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_TX, 1); |
| 3396 | rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, 0); |
| 3397 | rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg); |
| 3398 | |
| 3399 | udelay(50); |
| 3400 | |
| 3401 | rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®); |
| 3402 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 1); |
| 3403 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 1); |
| 3404 | rt2x00_set_field32(®, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 2); |
| 3405 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1); |
| 3406 | rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg); |
| 3407 | |
| 3408 | rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, ®); |
| 3409 | rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_TX, 1); |
| 3410 | rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, 1); |
| 3411 | rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg); |
| 3412 | |
| 3413 | /* |
| 3414 | * Initialize LED control |
| 3415 | */ |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3416 | rt2x00_eeprom_read(rt2x00dev, EEPROM_LED_AG_CONF, &word); |
| 3417 | rt2800_mcu_request(rt2x00dev, MCU_LED_AG_CONF, 0xff, |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 3418 | word & 0xff, (word >> 8) & 0xff); |
| 3419 | |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3420 | rt2x00_eeprom_read(rt2x00dev, EEPROM_LED_ACT_CONF, &word); |
| 3421 | rt2800_mcu_request(rt2x00dev, MCU_LED_ACT_CONF, 0xff, |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 3422 | word & 0xff, (word >> 8) & 0xff); |
| 3423 | |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3424 | rt2x00_eeprom_read(rt2x00dev, EEPROM_LED_POLARITY, &word); |
| 3425 | rt2800_mcu_request(rt2x00dev, MCU_LED_LED_POLARITY, 0xff, |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 3426 | word & 0xff, (word >> 8) & 0xff); |
| 3427 | |
| 3428 | return 0; |
| 3429 | } |
| 3430 | EXPORT_SYMBOL_GPL(rt2800_enable_radio); |
| 3431 | |
| 3432 | void rt2800_disable_radio(struct rt2x00_dev *rt2x00dev) |
| 3433 | { |
| 3434 | u32 reg; |
| 3435 | |
| 3436 | rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®); |
| 3437 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0); |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 3438 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0); |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 3439 | rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg); |
| 3440 | |
| 3441 | /* Wait for DMA, ignore error */ |
| 3442 | rt2800_wait_wpdma_ready(rt2x00dev); |
| 3443 | |
| 3444 | rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, ®); |
| 3445 | rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_TX, 0); |
| 3446 | rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, 0); |
| 3447 | rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg); |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 3448 | } |
| 3449 | EXPORT_SYMBOL_GPL(rt2800_disable_radio); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 3450 | |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 3451 | int rt2800_efuse_detect(struct rt2x00_dev *rt2x00dev) |
| 3452 | { |
| 3453 | u32 reg; |
| 3454 | |
| 3455 | rt2800_register_read(rt2x00dev, EFUSE_CTRL, ®); |
| 3456 | |
| 3457 | return rt2x00_get_field32(reg, EFUSE_CTRL_PRESENT); |
| 3458 | } |
| 3459 | EXPORT_SYMBOL_GPL(rt2800_efuse_detect); |
| 3460 | |
| 3461 | static void rt2800_efuse_read(struct rt2x00_dev *rt2x00dev, unsigned int i) |
| 3462 | { |
| 3463 | u32 reg; |
| 3464 | |
Gertjan van Wingerde | 31a4cf1 | 2009-11-14 20:20:36 +0100 | [diff] [blame] | 3465 | mutex_lock(&rt2x00dev->csr_mutex); |
| 3466 | |
| 3467 | rt2800_register_read_lock(rt2x00dev, EFUSE_CTRL, ®); |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 3468 | rt2x00_set_field32(®, EFUSE_CTRL_ADDRESS_IN, i); |
| 3469 | rt2x00_set_field32(®, EFUSE_CTRL_MODE, 0); |
| 3470 | rt2x00_set_field32(®, EFUSE_CTRL_KICK, 1); |
Gertjan van Wingerde | 31a4cf1 | 2009-11-14 20:20:36 +0100 | [diff] [blame] | 3471 | rt2800_register_write_lock(rt2x00dev, EFUSE_CTRL, reg); |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 3472 | |
| 3473 | /* Wait until the EEPROM has been loaded */ |
| 3474 | rt2800_regbusy_read(rt2x00dev, EFUSE_CTRL, EFUSE_CTRL_KICK, ®); |
| 3475 | |
| 3476 | /* Apparently the data is read from end to start */ |
Gertjan van Wingerde | 31a4cf1 | 2009-11-14 20:20:36 +0100 | [diff] [blame] | 3477 | rt2800_register_read_lock(rt2x00dev, EFUSE_DATA3, |
| 3478 | (u32 *)&rt2x00dev->eeprom[i]); |
| 3479 | rt2800_register_read_lock(rt2x00dev, EFUSE_DATA2, |
| 3480 | (u32 *)&rt2x00dev->eeprom[i + 2]); |
| 3481 | rt2800_register_read_lock(rt2x00dev, EFUSE_DATA1, |
| 3482 | (u32 *)&rt2x00dev->eeprom[i + 4]); |
| 3483 | rt2800_register_read_lock(rt2x00dev, EFUSE_DATA0, |
| 3484 | (u32 *)&rt2x00dev->eeprom[i + 6]); |
| 3485 | |
| 3486 | mutex_unlock(&rt2x00dev->csr_mutex); |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 3487 | } |
| 3488 | |
| 3489 | void rt2800_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev) |
| 3490 | { |
| 3491 | unsigned int i; |
| 3492 | |
| 3493 | for (i = 0; i < EEPROM_SIZE / sizeof(u16); i += 8) |
| 3494 | rt2800_efuse_read(rt2x00dev, i); |
| 3495 | } |
| 3496 | EXPORT_SYMBOL_GPL(rt2800_read_eeprom_efuse); |
| 3497 | |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 3498 | int rt2800_validate_eeprom(struct rt2x00_dev *rt2x00dev) |
| 3499 | { |
| 3500 | u16 word; |
| 3501 | u8 *mac; |
| 3502 | u8 default_lna_gain; |
| 3503 | |
| 3504 | /* |
| 3505 | * Start validation of the data that has been read. |
| 3506 | */ |
| 3507 | mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0); |
| 3508 | if (!is_valid_ether_addr(mac)) { |
| 3509 | random_ether_addr(mac); |
| 3510 | EEPROM(rt2x00dev, "MAC: %pM\n", mac); |
| 3511 | } |
| 3512 | |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3513 | rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 3514 | if (word == 0xffff) { |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3515 | rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RXPATH, 2); |
| 3516 | rt2x00_set_field16(&word, EEPROM_NIC_CONF0_TXPATH, 1); |
| 3517 | rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RF_TYPE, RF2820); |
| 3518 | rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC_CONF0, word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 3519 | EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word); |
Gertjan van Wingerde | 49e721e | 2010-02-13 20:55:49 +0100 | [diff] [blame] | 3520 | } else if (rt2x00_rt(rt2x00dev, RT2860) || |
Gertjan van Wingerde | e148b4c | 2010-04-11 14:31:09 +0200 | [diff] [blame] | 3521 | rt2x00_rt(rt2x00dev, RT2872)) { |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 3522 | /* |
| 3523 | * There is a max of 2 RX streams for RT28x0 series |
| 3524 | */ |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3525 | if (rt2x00_get_field16(word, EEPROM_NIC_CONF0_RXPATH) > 2) |
| 3526 | rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RXPATH, 2); |
| 3527 | rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC_CONF0, word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 3528 | } |
| 3529 | |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3530 | rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 3531 | if (word == 0xffff) { |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3532 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_HW_RADIO, 0); |
| 3533 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_TX_ALC, 0); |
| 3534 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_LNA_2G, 0); |
| 3535 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_LNA_5G, 0); |
| 3536 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_CARDBUS_ACCEL, 0); |
| 3537 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_SB_2G, 0); |
| 3538 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_SB_5G, 0); |
| 3539 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_WPS_PBC, 0); |
| 3540 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_2G, 0); |
| 3541 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_5G, 0); |
| 3542 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BROADBAND_EXT_LNA, 0); |
| 3543 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_ANT_DIVERSITY, 0); |
| 3544 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_INTERNAL_TX_ALC, 0); |
| 3545 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BT_COEXIST, 0); |
| 3546 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_DAC_TEST, 0); |
| 3547 | rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC_CONF1, word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 3548 | EEPROM(rt2x00dev, "NIC: 0x%04x\n", word); |
| 3549 | } |
| 3550 | |
| 3551 | rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &word); |
| 3552 | if ((word & 0x00ff) == 0x00ff) { |
| 3553 | rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0); |
Gertjan van Wingerde | ec2d179 | 2010-06-29 21:44:50 +0200 | [diff] [blame] | 3554 | rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word); |
| 3555 | EEPROM(rt2x00dev, "Freq: 0x%04x\n", word); |
| 3556 | } |
| 3557 | if ((word & 0xff00) == 0xff00) { |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 3558 | rt2x00_set_field16(&word, EEPROM_FREQ_LED_MODE, |
| 3559 | LED_MODE_TXRX_ACTIVITY); |
| 3560 | rt2x00_set_field16(&word, EEPROM_FREQ_LED_POLARITY, 0); |
| 3561 | rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word); |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3562 | rt2x00_eeprom_write(rt2x00dev, EEPROM_LED_AG_CONF, 0x5555); |
| 3563 | rt2x00_eeprom_write(rt2x00dev, EEPROM_LED_ACT_CONF, 0x2221); |
| 3564 | rt2x00_eeprom_write(rt2x00dev, EEPROM_LED_POLARITY, 0xa9f8); |
Gertjan van Wingerde | ec2d179 | 2010-06-29 21:44:50 +0200 | [diff] [blame] | 3565 | EEPROM(rt2x00dev, "Led Mode: 0x%04x\n", word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 3566 | } |
| 3567 | |
| 3568 | /* |
| 3569 | * During the LNA validation we are going to use |
| 3570 | * lna0 as correct value. Note that EEPROM_LNA |
| 3571 | * is never validated. |
| 3572 | */ |
| 3573 | rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &word); |
| 3574 | default_lna_gain = rt2x00_get_field16(word, EEPROM_LNA_A0); |
| 3575 | |
| 3576 | rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &word); |
| 3577 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET0)) > 10) |
| 3578 | rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET0, 0); |
| 3579 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET1)) > 10) |
| 3580 | rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET1, 0); |
| 3581 | rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG, word); |
| 3582 | |
| 3583 | rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &word); |
| 3584 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG2_OFFSET2)) > 10) |
| 3585 | rt2x00_set_field16(&word, EEPROM_RSSI_BG2_OFFSET2, 0); |
| 3586 | if (rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0x00 || |
| 3587 | rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0xff) |
| 3588 | rt2x00_set_field16(&word, EEPROM_RSSI_BG2_LNA_A1, |
| 3589 | default_lna_gain); |
| 3590 | rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG2, word); |
| 3591 | |
| 3592 | rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &word); |
| 3593 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET0)) > 10) |
| 3594 | rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET0, 0); |
| 3595 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET1)) > 10) |
| 3596 | rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET1, 0); |
| 3597 | rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A, word); |
| 3598 | |
| 3599 | rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &word); |
| 3600 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A2_OFFSET2)) > 10) |
| 3601 | rt2x00_set_field16(&word, EEPROM_RSSI_A2_OFFSET2, 0); |
| 3602 | if (rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0x00 || |
| 3603 | rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0xff) |
| 3604 | rt2x00_set_field16(&word, EEPROM_RSSI_A2_LNA_A2, |
| 3605 | default_lna_gain); |
| 3606 | rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A2, word); |
| 3607 | |
| 3608 | return 0; |
| 3609 | } |
| 3610 | EXPORT_SYMBOL_GPL(rt2800_validate_eeprom); |
| 3611 | |
| 3612 | int rt2800_init_eeprom(struct rt2x00_dev *rt2x00dev) |
| 3613 | { |
| 3614 | u32 reg; |
| 3615 | u16 value; |
| 3616 | u16 eeprom; |
| 3617 | |
| 3618 | /* |
| 3619 | * Read EEPROM word for configuration. |
| 3620 | */ |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3621 | rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 3622 | |
| 3623 | /* |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3624 | * Identify RF chipset by EEPROM value |
| 3625 | * RT28xx/RT30xx: defined in "EEPROM_NIC_CONF0_RF_TYPE" field |
| 3626 | * RT53xx: defined in "EEPROM_CHIP_ID" field |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 3627 | */ |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 3628 | rt2800_register_read(rt2x00dev, MAC_CSR0, ®); |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3629 | if (rt2x00_get_field32(reg, MAC_CSR0_CHIPSET) == RT5390) |
| 3630 | rt2x00_eeprom_read(rt2x00dev, EEPROM_CHIP_ID, &value); |
| 3631 | else |
| 3632 | value = rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RF_TYPE); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 3633 | |
Gertjan van Wingerde | 49e721e | 2010-02-13 20:55:49 +0100 | [diff] [blame] | 3634 | rt2x00_set_chip(rt2x00dev, rt2x00_get_field32(reg, MAC_CSR0_CHIPSET), |
| 3635 | value, rt2x00_get_field32(reg, MAC_CSR0_REVISION)); |
Gertjan van Wingerde | 714fa66 | 2010-02-13 20:55:48 +0100 | [diff] [blame] | 3636 | |
Gertjan van Wingerde | 49e721e | 2010-02-13 20:55:49 +0100 | [diff] [blame] | 3637 | if (!rt2x00_rt(rt2x00dev, RT2860) && |
Gertjan van Wingerde | 49e721e | 2010-02-13 20:55:49 +0100 | [diff] [blame] | 3638 | !rt2x00_rt(rt2x00dev, RT2872) && |
Gertjan van Wingerde | 49e721e | 2010-02-13 20:55:49 +0100 | [diff] [blame] | 3639 | !rt2x00_rt(rt2x00dev, RT2883) && |
Gertjan van Wingerde | 49e721e | 2010-02-13 20:55:49 +0100 | [diff] [blame] | 3640 | !rt2x00_rt(rt2x00dev, RT3070) && |
| 3641 | !rt2x00_rt(rt2x00dev, RT3071) && |
| 3642 | !rt2x00_rt(rt2x00dev, RT3090) && |
| 3643 | !rt2x00_rt(rt2x00dev, RT3390) && |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3644 | !rt2x00_rt(rt2x00dev, RT3572) && |
| 3645 | !rt2x00_rt(rt2x00dev, RT5390)) { |
Gertjan van Wingerde | 49e721e | 2010-02-13 20:55:49 +0100 | [diff] [blame] | 3646 | ERROR(rt2x00dev, "Invalid RT chipset detected.\n"); |
| 3647 | return -ENODEV; |
| 3648 | } |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 3649 | |
Gertjan van Wingerde | 5122d89 | 2009-12-23 00:03:25 +0100 | [diff] [blame] | 3650 | if (!rt2x00_rf(rt2x00dev, RF2820) && |
| 3651 | !rt2x00_rf(rt2x00dev, RF2850) && |
| 3652 | !rt2x00_rf(rt2x00dev, RF2720) && |
| 3653 | !rt2x00_rf(rt2x00dev, RF2750) && |
| 3654 | !rt2x00_rf(rt2x00dev, RF3020) && |
| 3655 | !rt2x00_rf(rt2x00dev, RF2020) && |
| 3656 | !rt2x00_rf(rt2x00dev, RF3021) && |
Gertjan van Wingerde | 6c0fe26 | 2009-12-30 11:36:31 +0100 | [diff] [blame] | 3657 | !rt2x00_rf(rt2x00dev, RF3022) && |
Gertjan van Wingerde | f93bc9b | 2010-11-13 19:09:50 +0100 | [diff] [blame] | 3658 | !rt2x00_rf(rt2x00dev, RF3052) && |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3659 | !rt2x00_rf(rt2x00dev, RF3320) && |
| 3660 | !rt2x00_rf(rt2x00dev, RF5390)) { |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 3661 | ERROR(rt2x00dev, "Invalid RF chipset detected.\n"); |
| 3662 | return -ENODEV; |
| 3663 | } |
| 3664 | |
| 3665 | /* |
| 3666 | * Identify default antenna configuration. |
| 3667 | */ |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 3668 | rt2x00dev->default_ant.tx_chain_num = |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3669 | rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH); |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 3670 | rt2x00dev->default_ant.rx_chain_num = |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3671 | rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 3672 | |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 3673 | rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom); |
| 3674 | |
| 3675 | if (rt2x00_rt(rt2x00dev, RT3070) || |
| 3676 | rt2x00_rt(rt2x00dev, RT3090) || |
| 3677 | rt2x00_rt(rt2x00dev, RT3390)) { |
| 3678 | value = rt2x00_get_field16(eeprom, |
| 3679 | EEPROM_NIC_CONF1_ANT_DIVERSITY); |
| 3680 | switch (value) { |
| 3681 | case 0: |
| 3682 | case 1: |
| 3683 | case 2: |
| 3684 | rt2x00dev->default_ant.tx = ANTENNA_A; |
| 3685 | rt2x00dev->default_ant.rx = ANTENNA_A; |
| 3686 | break; |
| 3687 | case 3: |
| 3688 | rt2x00dev->default_ant.tx = ANTENNA_A; |
| 3689 | rt2x00dev->default_ant.rx = ANTENNA_B; |
| 3690 | break; |
| 3691 | } |
| 3692 | } else { |
| 3693 | rt2x00dev->default_ant.tx = ANTENNA_A; |
| 3694 | rt2x00dev->default_ant.rx = ANTENNA_A; |
| 3695 | } |
| 3696 | |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 3697 | /* |
| 3698 | * Read frequency offset and RF programming sequence. |
| 3699 | */ |
| 3700 | rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom); |
| 3701 | rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET); |
| 3702 | |
| 3703 | /* |
| 3704 | * Read external LNA informations. |
| 3705 | */ |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3706 | rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 3707 | |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3708 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_EXTERNAL_LNA_5G)) |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 3709 | __set_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags); |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3710 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_EXTERNAL_LNA_2G)) |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 3711 | __set_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags); |
| 3712 | |
| 3713 | /* |
| 3714 | * Detect if this device has an hardware controlled radio. |
| 3715 | */ |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3716 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_HW_RADIO)) |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 3717 | __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags); |
| 3718 | |
| 3719 | /* |
| 3720 | * Store led settings, for correct led behaviour. |
| 3721 | */ |
| 3722 | #ifdef CONFIG_RT2X00_LIB_LEDS |
| 3723 | rt2800_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO); |
| 3724 | rt2800_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC); |
| 3725 | rt2800_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY); |
| 3726 | |
| 3727 | rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &rt2x00dev->led_mcu_reg); |
| 3728 | #endif /* CONFIG_RT2X00_LIB_LEDS */ |
| 3729 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3730 | /* |
| 3731 | * Check if support EIRP tx power limit feature. |
| 3732 | */ |
| 3733 | rt2x00_eeprom_read(rt2x00dev, EEPROM_EIRP_MAX_TX_POWER, &eeprom); |
| 3734 | |
| 3735 | if (rt2x00_get_field16(eeprom, EEPROM_EIRP_MAX_TX_POWER_2GHZ) < |
| 3736 | EIRP_MAX_TX_POWER_LIMIT) |
| 3737 | __set_bit(CONFIG_SUPPORT_POWER_LIMIT, &rt2x00dev->flags); |
| 3738 | |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 3739 | return 0; |
| 3740 | } |
| 3741 | EXPORT_SYMBOL_GPL(rt2800_init_eeprom); |
| 3742 | |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 3743 | /* |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 3744 | * RF value list for rt28xx |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 3745 | * Supports: 2.4 GHz (all) & 5.2 GHz (RF2850 & RF2750) |
| 3746 | */ |
| 3747 | static const struct rf_channel rf_vals[] = { |
| 3748 | { 1, 0x18402ecc, 0x184c0786, 0x1816b455, 0x1800510b }, |
| 3749 | { 2, 0x18402ecc, 0x184c0786, 0x18168a55, 0x1800519f }, |
| 3750 | { 3, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800518b }, |
| 3751 | { 4, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800519f }, |
| 3752 | { 5, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800518b }, |
| 3753 | { 6, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800519f }, |
| 3754 | { 7, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800518b }, |
| 3755 | { 8, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800519f }, |
| 3756 | { 9, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800518b }, |
| 3757 | { 10, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800519f }, |
| 3758 | { 11, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800518b }, |
| 3759 | { 12, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800519f }, |
| 3760 | { 13, 0x18402ecc, 0x184c079e, 0x18168a55, 0x1800518b }, |
| 3761 | { 14, 0x18402ecc, 0x184c07a2, 0x18168a55, 0x18005193 }, |
| 3762 | |
| 3763 | /* 802.11 UNI / HyperLan 2 */ |
| 3764 | { 36, 0x18402ecc, 0x184c099a, 0x18158a55, 0x180ed1a3 }, |
| 3765 | { 38, 0x18402ecc, 0x184c099e, 0x18158a55, 0x180ed193 }, |
| 3766 | { 40, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed183 }, |
| 3767 | { 44, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed1a3 }, |
| 3768 | { 46, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed18b }, |
| 3769 | { 48, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed19b }, |
| 3770 | { 52, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed193 }, |
| 3771 | { 54, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed1a3 }, |
| 3772 | { 56, 0x18402ec8, 0x184c068e, 0x18158a55, 0x180ed18b }, |
| 3773 | { 60, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed183 }, |
| 3774 | { 62, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed193 }, |
| 3775 | { 64, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed1a3 }, |
| 3776 | |
| 3777 | /* 802.11 HyperLan 2 */ |
| 3778 | { 100, 0x18402ec8, 0x184c06b2, 0x18178a55, 0x180ed783 }, |
| 3779 | { 102, 0x18402ec8, 0x184c06b2, 0x18578a55, 0x180ed793 }, |
| 3780 | { 104, 0x18402ec8, 0x185c06b2, 0x18578a55, 0x180ed1a3 }, |
| 3781 | { 108, 0x18402ecc, 0x185c0a32, 0x18578a55, 0x180ed193 }, |
| 3782 | { 110, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed183 }, |
| 3783 | { 112, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed19b }, |
| 3784 | { 116, 0x18402ecc, 0x184c0a3a, 0x18178a55, 0x180ed1a3 }, |
| 3785 | { 118, 0x18402ecc, 0x184c0a3e, 0x18178a55, 0x180ed193 }, |
| 3786 | { 120, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed183 }, |
| 3787 | { 124, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed193 }, |
| 3788 | { 126, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed15b }, |
| 3789 | { 128, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed1a3 }, |
| 3790 | { 132, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed18b }, |
| 3791 | { 134, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed193 }, |
| 3792 | { 136, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed19b }, |
| 3793 | { 140, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed183 }, |
| 3794 | |
| 3795 | /* 802.11 UNII */ |
| 3796 | { 149, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed1a7 }, |
| 3797 | { 151, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed187 }, |
| 3798 | { 153, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed18f }, |
| 3799 | { 157, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed19f }, |
| 3800 | { 159, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed1a7 }, |
| 3801 | { 161, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed187 }, |
| 3802 | { 165, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed197 }, |
| 3803 | { 167, 0x18402ec4, 0x184c03d2, 0x18179855, 0x1815531f }, |
| 3804 | { 169, 0x18402ec4, 0x184c03d2, 0x18179855, 0x18155327 }, |
| 3805 | { 171, 0x18402ec4, 0x184c03d6, 0x18179855, 0x18155307 }, |
| 3806 | { 173, 0x18402ec4, 0x184c03d6, 0x18179855, 0x1815530f }, |
| 3807 | |
| 3808 | /* 802.11 Japan */ |
| 3809 | { 184, 0x15002ccc, 0x1500491e, 0x1509be55, 0x150c0a0b }, |
| 3810 | { 188, 0x15002ccc, 0x15004922, 0x1509be55, 0x150c0a13 }, |
| 3811 | { 192, 0x15002ccc, 0x15004926, 0x1509be55, 0x150c0a1b }, |
| 3812 | { 196, 0x15002ccc, 0x1500492a, 0x1509be55, 0x150c0a23 }, |
| 3813 | { 208, 0x15002ccc, 0x1500493a, 0x1509be55, 0x150c0a13 }, |
| 3814 | { 212, 0x15002ccc, 0x1500493e, 0x1509be55, 0x150c0a1b }, |
| 3815 | { 216, 0x15002ccc, 0x15004982, 0x1509be55, 0x150c0a23 }, |
| 3816 | }; |
| 3817 | |
| 3818 | /* |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 3819 | * RF value list for rt3xxx |
| 3820 | * Supports: 2.4 GHz (all) & 5.2 GHz (RF3052) |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 3821 | */ |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 3822 | static const struct rf_channel rf_vals_3x[] = { |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 3823 | {1, 241, 2, 2 }, |
| 3824 | {2, 241, 2, 7 }, |
| 3825 | {3, 242, 2, 2 }, |
| 3826 | {4, 242, 2, 7 }, |
| 3827 | {5, 243, 2, 2 }, |
| 3828 | {6, 243, 2, 7 }, |
| 3829 | {7, 244, 2, 2 }, |
| 3830 | {8, 244, 2, 7 }, |
| 3831 | {9, 245, 2, 2 }, |
| 3832 | {10, 245, 2, 7 }, |
| 3833 | {11, 246, 2, 2 }, |
| 3834 | {12, 246, 2, 7 }, |
| 3835 | {13, 247, 2, 2 }, |
| 3836 | {14, 248, 2, 4 }, |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 3837 | |
| 3838 | /* 802.11 UNI / HyperLan 2 */ |
| 3839 | {36, 0x56, 0, 4}, |
| 3840 | {38, 0x56, 0, 6}, |
| 3841 | {40, 0x56, 0, 8}, |
| 3842 | {44, 0x57, 0, 0}, |
| 3843 | {46, 0x57, 0, 2}, |
| 3844 | {48, 0x57, 0, 4}, |
| 3845 | {52, 0x57, 0, 8}, |
| 3846 | {54, 0x57, 0, 10}, |
| 3847 | {56, 0x58, 0, 0}, |
| 3848 | {60, 0x58, 0, 4}, |
| 3849 | {62, 0x58, 0, 6}, |
| 3850 | {64, 0x58, 0, 8}, |
| 3851 | |
| 3852 | /* 802.11 HyperLan 2 */ |
| 3853 | {100, 0x5b, 0, 8}, |
| 3854 | {102, 0x5b, 0, 10}, |
| 3855 | {104, 0x5c, 0, 0}, |
| 3856 | {108, 0x5c, 0, 4}, |
| 3857 | {110, 0x5c, 0, 6}, |
| 3858 | {112, 0x5c, 0, 8}, |
| 3859 | {116, 0x5d, 0, 0}, |
| 3860 | {118, 0x5d, 0, 2}, |
| 3861 | {120, 0x5d, 0, 4}, |
| 3862 | {124, 0x5d, 0, 8}, |
| 3863 | {126, 0x5d, 0, 10}, |
| 3864 | {128, 0x5e, 0, 0}, |
| 3865 | {132, 0x5e, 0, 4}, |
| 3866 | {134, 0x5e, 0, 6}, |
| 3867 | {136, 0x5e, 0, 8}, |
| 3868 | {140, 0x5f, 0, 0}, |
| 3869 | |
| 3870 | /* 802.11 UNII */ |
| 3871 | {149, 0x5f, 0, 9}, |
| 3872 | {151, 0x5f, 0, 11}, |
| 3873 | {153, 0x60, 0, 1}, |
| 3874 | {157, 0x60, 0, 5}, |
| 3875 | {159, 0x60, 0, 7}, |
| 3876 | {161, 0x60, 0, 9}, |
| 3877 | {165, 0x61, 0, 1}, |
| 3878 | {167, 0x61, 0, 3}, |
| 3879 | {169, 0x61, 0, 5}, |
| 3880 | {171, 0x61, 0, 7}, |
| 3881 | {173, 0x61, 0, 9}, |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 3882 | }; |
| 3883 | |
| 3884 | int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev) |
| 3885 | { |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 3886 | struct hw_mode_spec *spec = &rt2x00dev->spec; |
| 3887 | struct channel_info *info; |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 3888 | char *default_power1; |
| 3889 | char *default_power2; |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 3890 | unsigned int i; |
| 3891 | u16 eeprom; |
| 3892 | |
| 3893 | /* |
Gertjan van Wingerde | 93b6bd2 | 2009-12-14 20:33:55 +0100 | [diff] [blame] | 3894 | * Disable powersaving as default on PCI devices. |
| 3895 | */ |
Gertjan van Wingerde | cea90e5 | 2010-02-13 20:55:47 +0100 | [diff] [blame] | 3896 | if (rt2x00_is_pci(rt2x00dev) || rt2x00_is_soc(rt2x00dev)) |
Gertjan van Wingerde | 93b6bd2 | 2009-12-14 20:33:55 +0100 | [diff] [blame] | 3897 | rt2x00dev->hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; |
| 3898 | |
| 3899 | /* |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 3900 | * Initialize all hw fields. |
| 3901 | */ |
| 3902 | rt2x00dev->hw->flags = |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 3903 | IEEE80211_HW_SIGNAL_DBM | |
| 3904 | IEEE80211_HW_SUPPORTS_PS | |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 3905 | IEEE80211_HW_PS_NULLFUNC_STACK | |
| 3906 | IEEE80211_HW_AMPDU_AGGREGATION; |
Helmut Schaa | 5a5b6ed | 2010-10-02 11:31:33 +0200 | [diff] [blame] | 3907 | /* |
| 3908 | * Don't set IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING for USB devices |
| 3909 | * unless we are capable of sending the buffered frames out after the |
| 3910 | * DTIM transmission using rt2x00lib_beacondone. This will send out |
| 3911 | * multicast and broadcast traffic immediately instead of buffering it |
| 3912 | * infinitly and thus dropping it after some time. |
| 3913 | */ |
| 3914 | if (!rt2x00_is_usb(rt2x00dev)) |
| 3915 | rt2x00dev->hw->flags |= |
| 3916 | IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING; |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 3917 | |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 3918 | SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev); |
| 3919 | SET_IEEE80211_PERM_ADDR(rt2x00dev->hw, |
| 3920 | rt2x00_eeprom_addr(rt2x00dev, |
| 3921 | EEPROM_MAC_ADDR_0)); |
| 3922 | |
Helmut Schaa | 3f2bee2 | 2010-06-14 22:12:01 +0200 | [diff] [blame] | 3923 | /* |
| 3924 | * As rt2800 has a global fallback table we cannot specify |
| 3925 | * more then one tx rate per frame but since the hw will |
| 3926 | * try several rates (based on the fallback table) we should |
Helmut Schaa | ba3b9e5 | 2010-10-02 11:32:16 +0200 | [diff] [blame] | 3927 | * initialize max_report_rates to the maximum number of rates |
Helmut Schaa | 3f2bee2 | 2010-06-14 22:12:01 +0200 | [diff] [blame] | 3928 | * we are going to try. Otherwise mac80211 will truncate our |
| 3929 | * reported tx rates and the rc algortihm will end up with |
| 3930 | * incorrect data. |
| 3931 | */ |
Helmut Schaa | ba3b9e5 | 2010-10-02 11:32:16 +0200 | [diff] [blame] | 3932 | rt2x00dev->hw->max_rates = 1; |
| 3933 | rt2x00dev->hw->max_report_rates = 7; |
Helmut Schaa | 3f2bee2 | 2010-06-14 22:12:01 +0200 | [diff] [blame] | 3934 | rt2x00dev->hw->max_rate_tries = 1; |
| 3935 | |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3936 | rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom); |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 3937 | |
| 3938 | /* |
| 3939 | * Initialize hw_mode information. |
| 3940 | */ |
| 3941 | spec->supported_bands = SUPPORT_BAND_2GHZ; |
| 3942 | spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM; |
| 3943 | |
Gertjan van Wingerde | 5122d89 | 2009-12-23 00:03:25 +0100 | [diff] [blame] | 3944 | if (rt2x00_rf(rt2x00dev, RF2820) || |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 3945 | rt2x00_rf(rt2x00dev, RF2720)) { |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 3946 | spec->num_channels = 14; |
| 3947 | spec->channels = rf_vals; |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 3948 | } else if (rt2x00_rf(rt2x00dev, RF2850) || |
| 3949 | rt2x00_rf(rt2x00dev, RF2750)) { |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 3950 | spec->supported_bands |= SUPPORT_BAND_5GHZ; |
| 3951 | spec->num_channels = ARRAY_SIZE(rf_vals); |
| 3952 | spec->channels = rf_vals; |
Gertjan van Wingerde | 5122d89 | 2009-12-23 00:03:25 +0100 | [diff] [blame] | 3953 | } else if (rt2x00_rf(rt2x00dev, RF3020) || |
| 3954 | rt2x00_rf(rt2x00dev, RF2020) || |
| 3955 | rt2x00_rf(rt2x00dev, RF3021) || |
Gertjan van Wingerde | f93bc9b | 2010-11-13 19:09:50 +0100 | [diff] [blame] | 3956 | rt2x00_rf(rt2x00dev, RF3022) || |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3957 | rt2x00_rf(rt2x00dev, RF3320) || |
| 3958 | rt2x00_rf(rt2x00dev, RF5390)) { |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 3959 | spec->num_channels = 14; |
| 3960 | spec->channels = rf_vals_3x; |
| 3961 | } else if (rt2x00_rf(rt2x00dev, RF3052)) { |
| 3962 | spec->supported_bands |= SUPPORT_BAND_5GHZ; |
| 3963 | spec->num_channels = ARRAY_SIZE(rf_vals_3x); |
| 3964 | spec->channels = rf_vals_3x; |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 3965 | } |
| 3966 | |
| 3967 | /* |
| 3968 | * Initialize HT information. |
| 3969 | */ |
Gertjan van Wingerde | 5122d89 | 2009-12-23 00:03:25 +0100 | [diff] [blame] | 3970 | if (!rt2x00_rf(rt2x00dev, RF2020)) |
Gertjan van Wingerde | 38a522e | 2009-11-23 22:44:47 +0100 | [diff] [blame] | 3971 | spec->ht.ht_supported = true; |
| 3972 | else |
| 3973 | spec->ht.ht_supported = false; |
| 3974 | |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 3975 | spec->ht.cap = |
Gertjan van Wingerde | 06443e4 | 2010-06-03 10:52:08 +0200 | [diff] [blame] | 3976 | IEEE80211_HT_CAP_SUP_WIDTH_20_40 | |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 3977 | IEEE80211_HT_CAP_GRN_FLD | |
| 3978 | IEEE80211_HT_CAP_SGI_20 | |
Ivo van Doorn | aa67463 | 2010-06-29 21:48:37 +0200 | [diff] [blame] | 3979 | IEEE80211_HT_CAP_SGI_40; |
Helmut Schaa | 22cabaa | 2010-06-03 10:52:10 +0200 | [diff] [blame] | 3980 | |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3981 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) >= 2) |
Helmut Schaa | 22cabaa | 2010-06-03 10:52:10 +0200 | [diff] [blame] | 3982 | spec->ht.cap |= IEEE80211_HT_CAP_TX_STBC; |
| 3983 | |
Ivo van Doorn | aa67463 | 2010-06-29 21:48:37 +0200 | [diff] [blame] | 3984 | spec->ht.cap |= |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3985 | rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) << |
Ivo van Doorn | aa67463 | 2010-06-29 21:48:37 +0200 | [diff] [blame] | 3986 | IEEE80211_HT_CAP_RX_STBC_SHIFT; |
| 3987 | |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 3988 | spec->ht.ampdu_factor = 3; |
| 3989 | spec->ht.ampdu_density = 4; |
| 3990 | spec->ht.mcs.tx_params = |
| 3991 | IEEE80211_HT_MCS_TX_DEFINED | |
| 3992 | IEEE80211_HT_MCS_TX_RX_DIFF | |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3993 | ((rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) - 1) << |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 3994 | IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT); |
| 3995 | |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 3996 | switch (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH)) { |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 3997 | case 3: |
| 3998 | spec->ht.mcs.rx_mask[2] = 0xff; |
| 3999 | case 2: |
| 4000 | spec->ht.mcs.rx_mask[1] = 0xff; |
| 4001 | case 1: |
| 4002 | spec->ht.mcs.rx_mask[0] = 0xff; |
| 4003 | spec->ht.mcs.rx_mask[4] = 0x1; /* MCS32 */ |
| 4004 | break; |
| 4005 | } |
| 4006 | |
| 4007 | /* |
| 4008 | * Create channel information array |
| 4009 | */ |
Joe Perches | baeb2ff | 2010-08-11 07:02:48 +0000 | [diff] [blame] | 4010 | info = kcalloc(spec->num_channels, sizeof(*info), GFP_KERNEL); |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 4011 | if (!info) |
| 4012 | return -ENOMEM; |
| 4013 | |
| 4014 | spec->channels_info = info; |
| 4015 | |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 4016 | default_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG1); |
| 4017 | default_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG2); |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 4018 | |
| 4019 | for (i = 0; i < 14; i++) { |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4020 | info[i].default_power1 = default_power1[i]; |
| 4021 | info[i].default_power2 = default_power2[i]; |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 4022 | } |
| 4023 | |
| 4024 | if (spec->num_channels > 14) { |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 4025 | default_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A1); |
| 4026 | default_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A2); |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 4027 | |
| 4028 | for (i = 14; i < spec->num_channels; i++) { |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4029 | info[i].default_power1 = default_power1[i]; |
| 4030 | info[i].default_power2 = default_power2[i]; |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 4031 | } |
| 4032 | } |
| 4033 | |
| 4034 | return 0; |
| 4035 | } |
| 4036 | EXPORT_SYMBOL_GPL(rt2800_probe_hw_mode); |
| 4037 | |
| 4038 | /* |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 4039 | * IEEE80211 stack callback functions. |
| 4040 | */ |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 4041 | void rt2800_get_tkip_seq(struct ieee80211_hw *hw, u8 hw_key_idx, u32 *iv32, |
| 4042 | u16 *iv16) |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 4043 | { |
| 4044 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 4045 | struct mac_iveiv_entry iveiv_entry; |
| 4046 | u32 offset; |
| 4047 | |
| 4048 | offset = MAC_IVEIV_ENTRY(hw_key_idx); |
| 4049 | rt2800_register_multiread(rt2x00dev, offset, |
| 4050 | &iveiv_entry, sizeof(iveiv_entry)); |
| 4051 | |
Julia Lawall | 855da5e | 2009-12-13 17:07:45 +0100 | [diff] [blame] | 4052 | memcpy(iv16, &iveiv_entry.iv[0], sizeof(*iv16)); |
| 4053 | memcpy(iv32, &iveiv_entry.iv[4], sizeof(*iv32)); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 4054 | } |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 4055 | EXPORT_SYMBOL_GPL(rt2800_get_tkip_seq); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 4056 | |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 4057 | int rt2800_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 4058 | { |
| 4059 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 4060 | u32 reg; |
| 4061 | bool enabled = (value < IEEE80211_MAX_RTS_THRESHOLD); |
| 4062 | |
| 4063 | rt2800_register_read(rt2x00dev, TX_RTS_CFG, ®); |
| 4064 | rt2x00_set_field32(®, TX_RTS_CFG_RTS_THRES, value); |
| 4065 | rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg); |
| 4066 | |
| 4067 | rt2800_register_read(rt2x00dev, CCK_PROT_CFG, ®); |
| 4068 | rt2x00_set_field32(®, CCK_PROT_CFG_RTS_TH_EN, enabled); |
| 4069 | rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg); |
| 4070 | |
| 4071 | rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, ®); |
| 4072 | rt2x00_set_field32(®, OFDM_PROT_CFG_RTS_TH_EN, enabled); |
| 4073 | rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg); |
| 4074 | |
| 4075 | rt2800_register_read(rt2x00dev, MM20_PROT_CFG, ®); |
| 4076 | rt2x00_set_field32(®, MM20_PROT_CFG_RTS_TH_EN, enabled); |
| 4077 | rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg); |
| 4078 | |
| 4079 | rt2800_register_read(rt2x00dev, MM40_PROT_CFG, ®); |
| 4080 | rt2x00_set_field32(®, MM40_PROT_CFG_RTS_TH_EN, enabled); |
| 4081 | rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg); |
| 4082 | |
| 4083 | rt2800_register_read(rt2x00dev, GF20_PROT_CFG, ®); |
| 4084 | rt2x00_set_field32(®, GF20_PROT_CFG_RTS_TH_EN, enabled); |
| 4085 | rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg); |
| 4086 | |
| 4087 | rt2800_register_read(rt2x00dev, GF40_PROT_CFG, ®); |
| 4088 | rt2x00_set_field32(®, GF40_PROT_CFG_RTS_TH_EN, enabled); |
| 4089 | rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg); |
| 4090 | |
| 4091 | return 0; |
| 4092 | } |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 4093 | EXPORT_SYMBOL_GPL(rt2800_set_rts_threshold); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 4094 | |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 4095 | int rt2800_conf_tx(struct ieee80211_hw *hw, u16 queue_idx, |
| 4096 | const struct ieee80211_tx_queue_params *params) |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 4097 | { |
| 4098 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 4099 | struct data_queue *queue; |
| 4100 | struct rt2x00_field32 field; |
| 4101 | int retval; |
| 4102 | u32 reg; |
| 4103 | u32 offset; |
| 4104 | |
| 4105 | /* |
| 4106 | * First pass the configuration through rt2x00lib, that will |
| 4107 | * update the queue settings and validate the input. After that |
| 4108 | * we are free to update the registers based on the value |
| 4109 | * in the queue parameter. |
| 4110 | */ |
| 4111 | retval = rt2x00mac_conf_tx(hw, queue_idx, params); |
| 4112 | if (retval) |
| 4113 | return retval; |
| 4114 | |
| 4115 | /* |
| 4116 | * We only need to perform additional register initialization |
| 4117 | * for WMM queues/ |
| 4118 | */ |
| 4119 | if (queue_idx >= 4) |
| 4120 | return 0; |
| 4121 | |
Helmut Schaa | 11f818e | 2011-03-03 19:38:55 +0100 | [diff] [blame] | 4122 | queue = rt2x00queue_get_tx_queue(rt2x00dev, queue_idx); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 4123 | |
| 4124 | /* Update WMM TXOP register */ |
| 4125 | offset = WMM_TXOP0_CFG + (sizeof(u32) * (!!(queue_idx & 2))); |
| 4126 | field.bit_offset = (queue_idx & 1) * 16; |
| 4127 | field.bit_mask = 0xffff << field.bit_offset; |
| 4128 | |
| 4129 | rt2800_register_read(rt2x00dev, offset, ®); |
| 4130 | rt2x00_set_field32(®, field, queue->txop); |
| 4131 | rt2800_register_write(rt2x00dev, offset, reg); |
| 4132 | |
| 4133 | /* Update WMM registers */ |
| 4134 | field.bit_offset = queue_idx * 4; |
| 4135 | field.bit_mask = 0xf << field.bit_offset; |
| 4136 | |
| 4137 | rt2800_register_read(rt2x00dev, WMM_AIFSN_CFG, ®); |
| 4138 | rt2x00_set_field32(®, field, queue->aifs); |
| 4139 | rt2800_register_write(rt2x00dev, WMM_AIFSN_CFG, reg); |
| 4140 | |
| 4141 | rt2800_register_read(rt2x00dev, WMM_CWMIN_CFG, ®); |
| 4142 | rt2x00_set_field32(®, field, queue->cw_min); |
| 4143 | rt2800_register_write(rt2x00dev, WMM_CWMIN_CFG, reg); |
| 4144 | |
| 4145 | rt2800_register_read(rt2x00dev, WMM_CWMAX_CFG, ®); |
| 4146 | rt2x00_set_field32(®, field, queue->cw_max); |
| 4147 | rt2800_register_write(rt2x00dev, WMM_CWMAX_CFG, reg); |
| 4148 | |
| 4149 | /* Update EDCA registers */ |
| 4150 | offset = EDCA_AC0_CFG + (sizeof(u32) * queue_idx); |
| 4151 | |
| 4152 | rt2800_register_read(rt2x00dev, offset, ®); |
| 4153 | rt2x00_set_field32(®, EDCA_AC0_CFG_TX_OP, queue->txop); |
| 4154 | rt2x00_set_field32(®, EDCA_AC0_CFG_AIFSN, queue->aifs); |
| 4155 | rt2x00_set_field32(®, EDCA_AC0_CFG_CWMIN, queue->cw_min); |
| 4156 | rt2x00_set_field32(®, EDCA_AC0_CFG_CWMAX, queue->cw_max); |
| 4157 | rt2800_register_write(rt2x00dev, offset, reg); |
| 4158 | |
| 4159 | return 0; |
| 4160 | } |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 4161 | EXPORT_SYMBOL_GPL(rt2800_conf_tx); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 4162 | |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 4163 | u64 rt2800_get_tsf(struct ieee80211_hw *hw) |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 4164 | { |
| 4165 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 4166 | u64 tsf; |
| 4167 | u32 reg; |
| 4168 | |
| 4169 | rt2800_register_read(rt2x00dev, TSF_TIMER_DW1, ®); |
| 4170 | tsf = (u64) rt2x00_get_field32(reg, TSF_TIMER_DW1_HIGH_WORD) << 32; |
| 4171 | rt2800_register_read(rt2x00dev, TSF_TIMER_DW0, ®); |
| 4172 | tsf |= rt2x00_get_field32(reg, TSF_TIMER_DW0_LOW_WORD); |
| 4173 | |
| 4174 | return tsf; |
| 4175 | } |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 4176 | EXPORT_SYMBOL_GPL(rt2800_get_tsf); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 4177 | |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 4178 | int rt2800_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 4179 | enum ieee80211_ampdu_mlme_action action, |
Johannes Berg | 0b01f03 | 2011-01-18 13:51:05 +0100 | [diff] [blame] | 4180 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, |
| 4181 | u8 buf_size) |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 4182 | { |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 4183 | int ret = 0; |
| 4184 | |
| 4185 | switch (action) { |
| 4186 | case IEEE80211_AMPDU_RX_START: |
| 4187 | case IEEE80211_AMPDU_RX_STOP: |
Helmut Schaa | 58ed826 | 2010-10-02 11:33:17 +0200 | [diff] [blame] | 4188 | /* |
| 4189 | * The hw itself takes care of setting up BlockAck mechanisms. |
| 4190 | * So, we only have to allow mac80211 to nagotiate a BlockAck |
| 4191 | * agreement. Once that is done, the hw will BlockAck incoming |
| 4192 | * AMPDUs without further setup. |
| 4193 | */ |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 4194 | break; |
| 4195 | case IEEE80211_AMPDU_TX_START: |
| 4196 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 4197 | break; |
| 4198 | case IEEE80211_AMPDU_TX_STOP: |
| 4199 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 4200 | break; |
| 4201 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 4202 | break; |
| 4203 | default: |
Ivo van Doorn | 4e9e58c | 2010-06-29 21:49:50 +0200 | [diff] [blame] | 4204 | WARNING((struct rt2x00_dev *)hw->priv, "Unknown AMPDU action\n"); |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 4205 | } |
| 4206 | |
| 4207 | return ret; |
| 4208 | } |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 4209 | EXPORT_SYMBOL_GPL(rt2800_ampdu_action); |
Ivo van Doorn | a5ea2f0 | 2010-06-14 22:13:15 +0200 | [diff] [blame] | 4210 | |
Helmut Schaa | 977206d | 2010-12-13 12:31:58 +0100 | [diff] [blame] | 4211 | int rt2800_get_survey(struct ieee80211_hw *hw, int idx, |
| 4212 | struct survey_info *survey) |
| 4213 | { |
| 4214 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 4215 | struct ieee80211_conf *conf = &hw->conf; |
| 4216 | u32 idle, busy, busy_ext; |
| 4217 | |
| 4218 | if (idx != 0) |
| 4219 | return -ENOENT; |
| 4220 | |
| 4221 | survey->channel = conf->channel; |
| 4222 | |
| 4223 | rt2800_register_read(rt2x00dev, CH_IDLE_STA, &idle); |
| 4224 | rt2800_register_read(rt2x00dev, CH_BUSY_STA, &busy); |
| 4225 | rt2800_register_read(rt2x00dev, CH_BUSY_STA_SEC, &busy_ext); |
| 4226 | |
| 4227 | if (idle || busy) { |
| 4228 | survey->filled = SURVEY_INFO_CHANNEL_TIME | |
| 4229 | SURVEY_INFO_CHANNEL_TIME_BUSY | |
| 4230 | SURVEY_INFO_CHANNEL_TIME_EXT_BUSY; |
| 4231 | |
| 4232 | survey->channel_time = (idle + busy) / 1000; |
| 4233 | survey->channel_time_busy = busy / 1000; |
| 4234 | survey->channel_time_ext_busy = busy_ext / 1000; |
| 4235 | } |
| 4236 | |
| 4237 | return 0; |
| 4238 | |
| 4239 | } |
| 4240 | EXPORT_SYMBOL_GPL(rt2800_get_survey); |
| 4241 | |
Ivo van Doorn | a5ea2f0 | 2010-06-14 22:13:15 +0200 | [diff] [blame] | 4242 | MODULE_AUTHOR(DRV_PROJECT ", Bartlomiej Zolnierkiewicz"); |
| 4243 | MODULE_VERSION(DRV_VERSION); |
| 4244 | MODULE_DESCRIPTION("Ralink RT2800 library"); |
| 4245 | MODULE_LICENSE("GPL"); |