Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 1 | /* |
Ivo van Doorn | a5ea2f0 | 2010-06-14 22:13:15 +0200 | [diff] [blame] | 2 | Copyright (C) 2010 Ivo van Doorn <IvDoorn@gmail.com> |
Gertjan van Wingerde | 9c9a0d1 | 2009-11-08 16:39:55 +0100 | [diff] [blame] | 3 | Copyright (C) 2009 Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> |
Gertjan van Wingerde | cce5fc4 | 2009-11-10 22:42:40 +0100 | [diff] [blame] | 4 | Copyright (C) 2009 Gertjan van Wingerde <gwingerde@gmail.com> |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 5 | |
Gertjan van Wingerde | 9c9a0d1 | 2009-11-08 16:39:55 +0100 | [diff] [blame] | 6 | Based on the original rt2800pci.c and rt2800usb.c. |
Gertjan van Wingerde | 9c9a0d1 | 2009-11-08 16:39:55 +0100 | [diff] [blame] | 7 | Copyright (C) 2009 Alban Browaeys <prahal@yahoo.com> |
| 8 | Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org> |
| 9 | Copyright (C) 2009 Luis Correia <luis.f.correia@gmail.com> |
| 10 | Copyright (C) 2009 Mattias Nissler <mattias.nissler@gmx.de> |
| 11 | Copyright (C) 2009 Mark Asselstine <asselsm@gmail.com> |
| 12 | Copyright (C) 2009 Xose Vazquez Perez <xose.vazquez@gmail.com> |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 13 | <http://rt2x00.serialmonkey.com> |
| 14 | |
| 15 | This program is free software; you can redistribute it and/or modify |
| 16 | it under the terms of the GNU General Public License as published by |
| 17 | the Free Software Foundation; either version 2 of the License, or |
| 18 | (at your option) any later version. |
| 19 | |
| 20 | This program is distributed in the hope that it will be useful, |
| 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | GNU General Public License for more details. |
| 24 | |
| 25 | You should have received a copy of the GNU General Public License |
| 26 | along with this program; if not, write to the |
| 27 | Free Software Foundation, Inc., |
| 28 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 29 | */ |
| 30 | |
| 31 | /* |
| 32 | Module: rt2800lib |
| 33 | Abstract: rt2800 generic device routines. |
| 34 | */ |
| 35 | |
| 36 | #include <linux/kernel.h> |
| 37 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 38 | #include <linux/slab.h> |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 39 | |
| 40 | #include "rt2x00.h" |
| 41 | #include "rt2800lib.h" |
| 42 | #include "rt2800.h" |
| 43 | |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 44 | /* |
| 45 | * Register access. |
| 46 | * All access to the CSR registers will go through the methods |
| 47 | * rt2800_register_read and rt2800_register_write. |
| 48 | * BBP and RF register require indirect register access, |
| 49 | * and use the CSR registers BBPCSR and RFCSR to achieve this. |
| 50 | * These indirect registers work with busy bits, |
| 51 | * and we will try maximal REGISTER_BUSY_COUNT times to access |
| 52 | * the register while taking a REGISTER_BUSY_DELAY us delay |
| 53 | * between each attampt. When the busy bit is still set at that time, |
| 54 | * the access attempt is considered to have failed, |
| 55 | * and we will print an error. |
| 56 | * The _lock versions must be used if you already hold the csr_mutex |
| 57 | */ |
| 58 | #define WAIT_FOR_BBP(__dev, __reg) \ |
| 59 | rt2800_regbusy_read((__dev), BBP_CSR_CFG, BBP_CSR_CFG_BUSY, (__reg)) |
| 60 | #define WAIT_FOR_RFCSR(__dev, __reg) \ |
| 61 | rt2800_regbusy_read((__dev), RF_CSR_CFG, RF_CSR_CFG_BUSY, (__reg)) |
| 62 | #define WAIT_FOR_RF(__dev, __reg) \ |
| 63 | rt2800_regbusy_read((__dev), RF_CSR_CFG0, RF_CSR_CFG0_BUSY, (__reg)) |
| 64 | #define WAIT_FOR_MCU(__dev, __reg) \ |
| 65 | rt2800_regbusy_read((__dev), H2M_MAILBOX_CSR, \ |
| 66 | H2M_MAILBOX_CSR_OWNER, (__reg)) |
| 67 | |
Helmut Schaa | baff800 | 2010-04-28 09:58:59 +0200 | [diff] [blame] | 68 | static inline bool rt2800_is_305x_soc(struct rt2x00_dev *rt2x00dev) |
| 69 | { |
| 70 | /* check for rt2872 on SoC */ |
| 71 | if (!rt2x00_is_soc(rt2x00dev) || |
| 72 | !rt2x00_rt(rt2x00dev, RT2872)) |
| 73 | return false; |
| 74 | |
| 75 | /* we know for sure that these rf chipsets are used on rt305x boards */ |
| 76 | if (rt2x00_rf(rt2x00dev, RF3020) || |
| 77 | rt2x00_rf(rt2x00dev, RF3021) || |
| 78 | rt2x00_rf(rt2x00dev, RF3022)) |
| 79 | return true; |
| 80 | |
| 81 | NOTICE(rt2x00dev, "Unknown RF chipset on rt305x\n"); |
| 82 | return false; |
| 83 | } |
| 84 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 85 | static void rt2800_bbp_write(struct rt2x00_dev *rt2x00dev, |
| 86 | const unsigned int word, const u8 value) |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 87 | { |
| 88 | u32 reg; |
| 89 | |
| 90 | mutex_lock(&rt2x00dev->csr_mutex); |
| 91 | |
| 92 | /* |
| 93 | * Wait until the BBP becomes available, afterwards we |
| 94 | * can safely write the new data into the register. |
| 95 | */ |
| 96 | if (WAIT_FOR_BBP(rt2x00dev, ®)) { |
| 97 | reg = 0; |
| 98 | rt2x00_set_field32(®, BBP_CSR_CFG_VALUE, value); |
| 99 | rt2x00_set_field32(®, BBP_CSR_CFG_REGNUM, word); |
| 100 | rt2x00_set_field32(®, BBP_CSR_CFG_BUSY, 1); |
| 101 | rt2x00_set_field32(®, BBP_CSR_CFG_READ_CONTROL, 0); |
Ivo van Doorn | efc7d36 | 2010-06-29 21:49:26 +0200 | [diff] [blame] | 102 | rt2x00_set_field32(®, BBP_CSR_CFG_BBP_RW_MODE, 1); |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 103 | |
| 104 | rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg); |
| 105 | } |
| 106 | |
| 107 | mutex_unlock(&rt2x00dev->csr_mutex); |
| 108 | } |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 109 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 110 | static void rt2800_bbp_read(struct rt2x00_dev *rt2x00dev, |
| 111 | const unsigned int word, u8 *value) |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 112 | { |
| 113 | u32 reg; |
| 114 | |
| 115 | mutex_lock(&rt2x00dev->csr_mutex); |
| 116 | |
| 117 | /* |
| 118 | * Wait until the BBP becomes available, afterwards we |
| 119 | * can safely write the read request into the register. |
| 120 | * After the data has been written, we wait until hardware |
| 121 | * returns the correct value, if at any time the register |
| 122 | * doesn't become available in time, reg will be 0xffffffff |
| 123 | * which means we return 0xff to the caller. |
| 124 | */ |
| 125 | if (WAIT_FOR_BBP(rt2x00dev, ®)) { |
| 126 | reg = 0; |
| 127 | rt2x00_set_field32(®, BBP_CSR_CFG_REGNUM, word); |
| 128 | rt2x00_set_field32(®, BBP_CSR_CFG_BUSY, 1); |
| 129 | rt2x00_set_field32(®, BBP_CSR_CFG_READ_CONTROL, 1); |
Ivo van Doorn | efc7d36 | 2010-06-29 21:49:26 +0200 | [diff] [blame] | 130 | rt2x00_set_field32(®, BBP_CSR_CFG_BBP_RW_MODE, 1); |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 131 | |
| 132 | rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg); |
| 133 | |
| 134 | WAIT_FOR_BBP(rt2x00dev, ®); |
| 135 | } |
| 136 | |
| 137 | *value = rt2x00_get_field32(reg, BBP_CSR_CFG_VALUE); |
| 138 | |
| 139 | mutex_unlock(&rt2x00dev->csr_mutex); |
| 140 | } |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 141 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 142 | static void rt2800_rfcsr_write(struct rt2x00_dev *rt2x00dev, |
| 143 | const unsigned int word, const u8 value) |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 144 | { |
| 145 | u32 reg; |
| 146 | |
| 147 | mutex_lock(&rt2x00dev->csr_mutex); |
| 148 | |
| 149 | /* |
| 150 | * Wait until the RFCSR becomes available, afterwards we |
| 151 | * can safely write the new data into the register. |
| 152 | */ |
| 153 | if (WAIT_FOR_RFCSR(rt2x00dev, ®)) { |
| 154 | reg = 0; |
| 155 | rt2x00_set_field32(®, RF_CSR_CFG_DATA, value); |
| 156 | rt2x00_set_field32(®, RF_CSR_CFG_REGNUM, word); |
| 157 | rt2x00_set_field32(®, RF_CSR_CFG_WRITE, 1); |
| 158 | rt2x00_set_field32(®, RF_CSR_CFG_BUSY, 1); |
| 159 | |
| 160 | rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg); |
| 161 | } |
| 162 | |
| 163 | mutex_unlock(&rt2x00dev->csr_mutex); |
| 164 | } |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 165 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 166 | static void rt2800_rfcsr_read(struct rt2x00_dev *rt2x00dev, |
| 167 | const unsigned int word, u8 *value) |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 168 | { |
| 169 | u32 reg; |
| 170 | |
| 171 | mutex_lock(&rt2x00dev->csr_mutex); |
| 172 | |
| 173 | /* |
| 174 | * Wait until the RFCSR becomes available, afterwards we |
| 175 | * can safely write the read request into the register. |
| 176 | * After the data has been written, we wait until hardware |
| 177 | * returns the correct value, if at any time the register |
| 178 | * doesn't become available in time, reg will be 0xffffffff |
| 179 | * which means we return 0xff to the caller. |
| 180 | */ |
| 181 | if (WAIT_FOR_RFCSR(rt2x00dev, ®)) { |
| 182 | reg = 0; |
| 183 | rt2x00_set_field32(®, RF_CSR_CFG_REGNUM, word); |
| 184 | rt2x00_set_field32(®, RF_CSR_CFG_WRITE, 0); |
| 185 | rt2x00_set_field32(®, RF_CSR_CFG_BUSY, 1); |
| 186 | |
| 187 | rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg); |
| 188 | |
| 189 | WAIT_FOR_RFCSR(rt2x00dev, ®); |
| 190 | } |
| 191 | |
| 192 | *value = rt2x00_get_field32(reg, RF_CSR_CFG_DATA); |
| 193 | |
| 194 | mutex_unlock(&rt2x00dev->csr_mutex); |
| 195 | } |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 196 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 197 | static void rt2800_rf_write(struct rt2x00_dev *rt2x00dev, |
| 198 | const unsigned int word, const u32 value) |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 199 | { |
| 200 | u32 reg; |
| 201 | |
| 202 | mutex_lock(&rt2x00dev->csr_mutex); |
| 203 | |
| 204 | /* |
| 205 | * Wait until the RF becomes available, afterwards we |
| 206 | * can safely write the new data into the register. |
| 207 | */ |
| 208 | if (WAIT_FOR_RF(rt2x00dev, ®)) { |
| 209 | reg = 0; |
| 210 | rt2x00_set_field32(®, RF_CSR_CFG0_REG_VALUE_BW, value); |
| 211 | rt2x00_set_field32(®, RF_CSR_CFG0_STANDBYMODE, 0); |
| 212 | rt2x00_set_field32(®, RF_CSR_CFG0_SEL, 0); |
| 213 | rt2x00_set_field32(®, RF_CSR_CFG0_BUSY, 1); |
| 214 | |
| 215 | rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG0, reg); |
| 216 | rt2x00_rf_write(rt2x00dev, word, value); |
| 217 | } |
| 218 | |
| 219 | mutex_unlock(&rt2x00dev->csr_mutex); |
| 220 | } |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 221 | |
| 222 | void rt2800_mcu_request(struct rt2x00_dev *rt2x00dev, |
| 223 | const u8 command, const u8 token, |
| 224 | const u8 arg0, const u8 arg1) |
| 225 | { |
| 226 | u32 reg; |
| 227 | |
Gertjan van Wingerde | ee303e5 | 2009-11-23 22:44:49 +0100 | [diff] [blame] | 228 | /* |
Gertjan van Wingerde | cea90e5 | 2010-02-13 20:55:47 +0100 | [diff] [blame] | 229 | * SOC devices don't support MCU requests. |
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 | if (rt2x00_is_soc(rt2x00dev)) |
Gertjan van Wingerde | ee303e5 | 2009-11-23 22:44:49 +0100 | [diff] [blame] | 232 | return; |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 233 | |
| 234 | mutex_lock(&rt2x00dev->csr_mutex); |
| 235 | |
| 236 | /* |
| 237 | * Wait until the MCU becomes available, afterwards we |
| 238 | * can safely write the new data into the register. |
| 239 | */ |
| 240 | if (WAIT_FOR_MCU(rt2x00dev, ®)) { |
| 241 | rt2x00_set_field32(®, H2M_MAILBOX_CSR_OWNER, 1); |
| 242 | rt2x00_set_field32(®, H2M_MAILBOX_CSR_CMD_TOKEN, token); |
| 243 | rt2x00_set_field32(®, H2M_MAILBOX_CSR_ARG0, arg0); |
| 244 | rt2x00_set_field32(®, H2M_MAILBOX_CSR_ARG1, arg1); |
| 245 | rt2800_register_write_lock(rt2x00dev, H2M_MAILBOX_CSR, reg); |
| 246 | |
| 247 | reg = 0; |
| 248 | rt2x00_set_field32(®, HOST_CMD_CSR_HOST_COMMAND, command); |
| 249 | rt2800_register_write_lock(rt2x00dev, HOST_CMD_CSR, reg); |
| 250 | } |
| 251 | |
| 252 | mutex_unlock(&rt2x00dev->csr_mutex); |
| 253 | } |
| 254 | EXPORT_SYMBOL_GPL(rt2800_mcu_request); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 255 | |
Gertjan van Wingerde | 67a4c1e | 2009-12-30 11:36:32 +0100 | [diff] [blame] | 256 | int rt2800_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev) |
| 257 | { |
| 258 | unsigned int i; |
| 259 | u32 reg; |
| 260 | |
| 261 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
| 262 | rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®); |
| 263 | if (!rt2x00_get_field32(reg, WPDMA_GLO_CFG_TX_DMA_BUSY) && |
| 264 | !rt2x00_get_field32(reg, WPDMA_GLO_CFG_RX_DMA_BUSY)) |
| 265 | return 0; |
| 266 | |
| 267 | msleep(1); |
| 268 | } |
| 269 | |
| 270 | ERROR(rt2x00dev, "WPDMA TX/RX busy, aborting.\n"); |
| 271 | return -EACCES; |
| 272 | } |
| 273 | EXPORT_SYMBOL_GPL(rt2800_wait_wpdma_ready); |
| 274 | |
Gertjan van Wingerde | 0b8004a | 2010-06-03 10:51:45 +0200 | [diff] [blame] | 275 | void rt2800_write_txwi(__le32 *txwi, struct txentry_desc *txdesc) |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 276 | { |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 277 | u32 word; |
| 278 | |
| 279 | /* |
| 280 | * Initialize TX Info descriptor |
| 281 | */ |
| 282 | rt2x00_desc_read(txwi, 0, &word); |
| 283 | rt2x00_set_field32(&word, TXWI_W0_FRAG, |
| 284 | test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags)); |
| 285 | rt2x00_set_field32(&word, TXWI_W0_MIMO_PS, 0); |
| 286 | rt2x00_set_field32(&word, TXWI_W0_CF_ACK, 0); |
| 287 | rt2x00_set_field32(&word, TXWI_W0_TS, |
| 288 | test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags)); |
| 289 | rt2x00_set_field32(&word, TXWI_W0_AMPDU, |
| 290 | test_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags)); |
| 291 | rt2x00_set_field32(&word, TXWI_W0_MPDU_DENSITY, txdesc->mpdu_density); |
| 292 | rt2x00_set_field32(&word, TXWI_W0_TX_OP, txdesc->txop); |
| 293 | rt2x00_set_field32(&word, TXWI_W0_MCS, txdesc->mcs); |
| 294 | rt2x00_set_field32(&word, TXWI_W0_BW, |
| 295 | test_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags)); |
| 296 | rt2x00_set_field32(&word, TXWI_W0_SHORT_GI, |
| 297 | test_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags)); |
| 298 | rt2x00_set_field32(&word, TXWI_W0_STBC, txdesc->stbc); |
| 299 | rt2x00_set_field32(&word, TXWI_W0_PHYMODE, txdesc->rate_mode); |
| 300 | rt2x00_desc_write(txwi, 0, word); |
| 301 | |
| 302 | rt2x00_desc_read(txwi, 1, &word); |
| 303 | rt2x00_set_field32(&word, TXWI_W1_ACK, |
| 304 | test_bit(ENTRY_TXD_ACK, &txdesc->flags)); |
| 305 | rt2x00_set_field32(&word, TXWI_W1_NSEQ, |
| 306 | test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags)); |
| 307 | rt2x00_set_field32(&word, TXWI_W1_BW_WIN_SIZE, txdesc->ba_size); |
| 308 | rt2x00_set_field32(&word, TXWI_W1_WIRELESS_CLI_ID, |
| 309 | test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags) ? |
| 310 | txdesc->key_idx : 0xff); |
| 311 | rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT, |
| 312 | txdesc->length); |
| 313 | rt2x00_set_field32(&word, TXWI_W1_PACKETID, txdesc->queue + 1); |
| 314 | rt2x00_desc_write(txwi, 1, word); |
| 315 | |
| 316 | /* |
| 317 | * Always write 0 to IV/EIV fields, hardware will insert the IV |
| 318 | * from the IVEIV register when TXD_W3_WIV is set to 0. |
| 319 | * When TXD_W3_WIV is set to 1 it will use the IV data |
| 320 | * from the descriptor. The TXWI_W1_WIRELESS_CLI_ID indicates which |
| 321 | * crypto entry in the registers should be used to encrypt the frame. |
| 322 | */ |
| 323 | _rt2x00_desc_write(txwi, 2, 0 /* skbdesc->iv[0] */); |
| 324 | _rt2x00_desc_write(txwi, 3, 0 /* skbdesc->iv[1] */); |
| 325 | } |
| 326 | EXPORT_SYMBOL_GPL(rt2800_write_txwi); |
| 327 | |
Gertjan van Wingerde | 2de64dd | 2010-05-08 23:40:22 +0200 | [diff] [blame] | 328 | void rt2800_process_rxwi(struct sk_buff *skb, struct rxdone_entry_desc *rxdesc) |
| 329 | { |
| 330 | __le32 *rxwi = (__le32 *) skb->data; |
| 331 | u32 word; |
| 332 | |
| 333 | rt2x00_desc_read(rxwi, 0, &word); |
| 334 | |
| 335 | rxdesc->cipher = rt2x00_get_field32(word, RXWI_W0_UDF); |
| 336 | rxdesc->size = rt2x00_get_field32(word, RXWI_W0_MPDU_TOTAL_BYTE_COUNT); |
| 337 | |
| 338 | rt2x00_desc_read(rxwi, 1, &word); |
| 339 | |
| 340 | if (rt2x00_get_field32(word, RXWI_W1_SHORT_GI)) |
| 341 | rxdesc->flags |= RX_FLAG_SHORT_GI; |
| 342 | |
| 343 | if (rt2x00_get_field32(word, RXWI_W1_BW)) |
| 344 | rxdesc->flags |= RX_FLAG_40MHZ; |
| 345 | |
| 346 | /* |
| 347 | * Detect RX rate, always use MCS as signal type. |
| 348 | */ |
| 349 | rxdesc->dev_flags |= RXDONE_SIGNAL_MCS; |
| 350 | rxdesc->signal = rt2x00_get_field32(word, RXWI_W1_MCS); |
| 351 | rxdesc->rate_mode = rt2x00_get_field32(word, RXWI_W1_PHYMODE); |
| 352 | |
| 353 | /* |
| 354 | * Mask of 0x8 bit to remove the short preamble flag. |
| 355 | */ |
| 356 | if (rxdesc->rate_mode == RATE_MODE_CCK) |
| 357 | rxdesc->signal &= ~0x8; |
| 358 | |
| 359 | rt2x00_desc_read(rxwi, 2, &word); |
| 360 | |
| 361 | rxdesc->rssi = |
| 362 | (rt2x00_get_field32(word, RXWI_W2_RSSI0) + |
| 363 | rt2x00_get_field32(word, RXWI_W2_RSSI1)) / 2; |
| 364 | |
| 365 | /* |
| 366 | * Remove RXWI descriptor from start of buffer. |
| 367 | */ |
| 368 | skb_pull(skb, RXWI_DESC_SIZE); |
| 369 | } |
| 370 | EXPORT_SYMBOL_GPL(rt2800_process_rxwi); |
| 371 | |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 372 | void rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc) |
| 373 | { |
| 374 | struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; |
| 375 | struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); |
| 376 | unsigned int beacon_base; |
| 377 | u32 reg; |
| 378 | |
| 379 | /* |
| 380 | * Disable beaconing while we are reloading the beacon data, |
| 381 | * otherwise we might be sending out invalid data. |
| 382 | */ |
| 383 | rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®); |
| 384 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 0); |
| 385 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
| 386 | |
| 387 | /* |
| 388 | * Add space for the TXWI in front of the skb. |
| 389 | */ |
| 390 | skb_push(entry->skb, TXWI_DESC_SIZE); |
| 391 | memset(entry->skb, 0, TXWI_DESC_SIZE); |
| 392 | |
| 393 | /* |
| 394 | * Register descriptor details in skb frame descriptor. |
| 395 | */ |
| 396 | skbdesc->flags |= SKBDESC_DESC_IN_SKB; |
| 397 | skbdesc->desc = entry->skb->data; |
| 398 | skbdesc->desc_len = TXWI_DESC_SIZE; |
| 399 | |
| 400 | /* |
| 401 | * Add the TXWI for the beacon to the skb. |
| 402 | */ |
| 403 | rt2800_write_txwi((__le32 *)entry->skb->data, txdesc); |
| 404 | |
| 405 | /* |
| 406 | * Dump beacon to userspace through debugfs. |
| 407 | */ |
| 408 | rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry->skb); |
| 409 | |
| 410 | /* |
| 411 | * Write entire beacon with TXWI to register. |
| 412 | */ |
| 413 | beacon_base = HW_BEACON_OFFSET(entry->entry_idx); |
| 414 | rt2800_register_multiwrite(rt2x00dev, beacon_base, |
| 415 | entry->skb->data, entry->skb->len); |
| 416 | |
| 417 | /* |
| 418 | * Enable beaconing again. |
| 419 | */ |
| 420 | rt2x00_set_field32(®, BCN_TIME_CFG_TSF_TICKING, 1); |
| 421 | rt2x00_set_field32(®, BCN_TIME_CFG_TBTT_ENABLE, 1); |
| 422 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 1); |
| 423 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
| 424 | |
| 425 | /* |
| 426 | * Clean up beacon skb. |
| 427 | */ |
| 428 | dev_kfree_skb_any(entry->skb); |
| 429 | entry->skb = NULL; |
| 430 | } |
| 431 | EXPORT_SYMBOL(rt2800_write_beacon); |
| 432 | |
Helmut Schaa | fdb8725 | 2010-06-29 21:48:06 +0200 | [diff] [blame] | 433 | static void inline rt2800_clear_beacon(struct rt2x00_dev *rt2x00dev, |
| 434 | unsigned int beacon_base) |
| 435 | { |
| 436 | int i; |
| 437 | |
| 438 | /* |
| 439 | * For the Beacon base registers we only need to clear |
| 440 | * the whole TXWI which (when set to 0) will invalidate |
| 441 | * the entire beacon. |
| 442 | */ |
| 443 | for (i = 0; i < TXWI_DESC_SIZE; i += sizeof(__le32)) |
| 444 | rt2800_register_write(rt2x00dev, beacon_base + i, 0); |
| 445 | } |
| 446 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 447 | #ifdef CONFIG_RT2X00_LIB_DEBUGFS |
| 448 | const struct rt2x00debug rt2800_rt2x00debug = { |
| 449 | .owner = THIS_MODULE, |
| 450 | .csr = { |
| 451 | .read = rt2800_register_read, |
| 452 | .write = rt2800_register_write, |
| 453 | .flags = RT2X00DEBUGFS_OFFSET, |
| 454 | .word_base = CSR_REG_BASE, |
| 455 | .word_size = sizeof(u32), |
| 456 | .word_count = CSR_REG_SIZE / sizeof(u32), |
| 457 | }, |
| 458 | .eeprom = { |
| 459 | .read = rt2x00_eeprom_read, |
| 460 | .write = rt2x00_eeprom_write, |
| 461 | .word_base = EEPROM_BASE, |
| 462 | .word_size = sizeof(u16), |
| 463 | .word_count = EEPROM_SIZE / sizeof(u16), |
| 464 | }, |
| 465 | .bbp = { |
| 466 | .read = rt2800_bbp_read, |
| 467 | .write = rt2800_bbp_write, |
| 468 | .word_base = BBP_BASE, |
| 469 | .word_size = sizeof(u8), |
| 470 | .word_count = BBP_SIZE / sizeof(u8), |
| 471 | }, |
| 472 | .rf = { |
| 473 | .read = rt2x00_rf_read, |
| 474 | .write = rt2800_rf_write, |
| 475 | .word_base = RF_BASE, |
| 476 | .word_size = sizeof(u32), |
| 477 | .word_count = RF_SIZE / sizeof(u32), |
| 478 | }, |
| 479 | }; |
| 480 | EXPORT_SYMBOL_GPL(rt2800_rt2x00debug); |
| 481 | #endif /* CONFIG_RT2X00_LIB_DEBUGFS */ |
| 482 | |
| 483 | int rt2800_rfkill_poll(struct rt2x00_dev *rt2x00dev) |
| 484 | { |
| 485 | u32 reg; |
| 486 | |
| 487 | rt2800_register_read(rt2x00dev, GPIO_CTRL_CFG, ®); |
| 488 | return rt2x00_get_field32(reg, GPIO_CTRL_CFG_BIT2); |
| 489 | } |
| 490 | EXPORT_SYMBOL_GPL(rt2800_rfkill_poll); |
| 491 | |
| 492 | #ifdef CONFIG_RT2X00_LIB_LEDS |
| 493 | static void rt2800_brightness_set(struct led_classdev *led_cdev, |
| 494 | enum led_brightness brightness) |
| 495 | { |
| 496 | struct rt2x00_led *led = |
| 497 | container_of(led_cdev, struct rt2x00_led, led_dev); |
| 498 | unsigned int enabled = brightness != LED_OFF; |
| 499 | unsigned int bg_mode = |
| 500 | (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_2GHZ); |
| 501 | unsigned int polarity = |
| 502 | rt2x00_get_field16(led->rt2x00dev->led_mcu_reg, |
| 503 | EEPROM_FREQ_LED_POLARITY); |
| 504 | unsigned int ledmode = |
| 505 | rt2x00_get_field16(led->rt2x00dev->led_mcu_reg, |
| 506 | EEPROM_FREQ_LED_MODE); |
| 507 | |
| 508 | if (led->type == LED_TYPE_RADIO) { |
| 509 | rt2800_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode, |
| 510 | enabled ? 0x20 : 0); |
| 511 | } else if (led->type == LED_TYPE_ASSOC) { |
| 512 | rt2800_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode, |
| 513 | enabled ? (bg_mode ? 0x60 : 0xa0) : 0x20); |
| 514 | } else if (led->type == LED_TYPE_QUALITY) { |
| 515 | /* |
| 516 | * The brightness is divided into 6 levels (0 - 5), |
| 517 | * The specs tell us the following levels: |
| 518 | * 0, 1 ,3, 7, 15, 31 |
| 519 | * to determine the level in a simple way we can simply |
| 520 | * work with bitshifting: |
| 521 | * (1 << level) - 1 |
| 522 | */ |
| 523 | rt2800_mcu_request(led->rt2x00dev, MCU_LED_STRENGTH, 0xff, |
| 524 | (1 << brightness / (LED_FULL / 6)) - 1, |
| 525 | polarity); |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | static int rt2800_blink_set(struct led_classdev *led_cdev, |
| 530 | unsigned long *delay_on, unsigned long *delay_off) |
| 531 | { |
| 532 | struct rt2x00_led *led = |
| 533 | container_of(led_cdev, struct rt2x00_led, led_dev); |
| 534 | u32 reg; |
| 535 | |
| 536 | rt2800_register_read(led->rt2x00dev, LED_CFG, ®); |
| 537 | rt2x00_set_field32(®, LED_CFG_ON_PERIOD, *delay_on); |
| 538 | rt2x00_set_field32(®, LED_CFG_OFF_PERIOD, *delay_off); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 539 | rt2800_register_write(led->rt2x00dev, LED_CFG, reg); |
| 540 | |
| 541 | return 0; |
| 542 | } |
| 543 | |
Gertjan van Wingerde | b3579d6 | 2009-12-30 11:36:34 +0100 | [diff] [blame] | 544 | static void rt2800_init_led(struct rt2x00_dev *rt2x00dev, |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 545 | struct rt2x00_led *led, enum led_type type) |
| 546 | { |
| 547 | led->rt2x00dev = rt2x00dev; |
| 548 | led->type = type; |
| 549 | led->led_dev.brightness_set = rt2800_brightness_set; |
| 550 | led->led_dev.blink_set = rt2800_blink_set; |
| 551 | led->flags = LED_INITIALIZED; |
| 552 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 553 | #endif /* CONFIG_RT2X00_LIB_LEDS */ |
| 554 | |
| 555 | /* |
| 556 | * Configuration handlers. |
| 557 | */ |
| 558 | static void rt2800_config_wcid_attr(struct rt2x00_dev *rt2x00dev, |
| 559 | struct rt2x00lib_crypto *crypto, |
| 560 | struct ieee80211_key_conf *key) |
| 561 | { |
| 562 | struct mac_wcid_entry wcid_entry; |
| 563 | struct mac_iveiv_entry iveiv_entry; |
| 564 | u32 offset; |
| 565 | u32 reg; |
| 566 | |
| 567 | offset = MAC_WCID_ATTR_ENTRY(key->hw_key_idx); |
| 568 | |
Ivo van Doorn | e4a0ab3 | 2010-06-14 22:14:19 +0200 | [diff] [blame] | 569 | if (crypto->cmd == SET_KEY) { |
| 570 | rt2800_register_read(rt2x00dev, offset, ®); |
| 571 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_KEYTAB, |
| 572 | !!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)); |
| 573 | /* |
| 574 | * Both the cipher as the BSS Idx numbers are split in a main |
| 575 | * value of 3 bits, and a extended field for adding one additional |
| 576 | * bit to the value. |
| 577 | */ |
| 578 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_CIPHER, |
| 579 | (crypto->cipher & 0x7)); |
| 580 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_CIPHER_EXT, |
| 581 | (crypto->cipher & 0x8) >> 3); |
| 582 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_BSS_IDX, |
| 583 | (crypto->bssidx & 0x7)); |
| 584 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_BSS_IDX_EXT, |
| 585 | (crypto->bssidx & 0x8) >> 3); |
| 586 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_RX_WIUDF, crypto->cipher); |
| 587 | rt2800_register_write(rt2x00dev, offset, reg); |
| 588 | } else { |
| 589 | rt2800_register_write(rt2x00dev, offset, 0); |
| 590 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 591 | |
| 592 | offset = MAC_IVEIV_ENTRY(key->hw_key_idx); |
| 593 | |
| 594 | memset(&iveiv_entry, 0, sizeof(iveiv_entry)); |
| 595 | if ((crypto->cipher == CIPHER_TKIP) || |
| 596 | (crypto->cipher == CIPHER_TKIP_NO_MIC) || |
| 597 | (crypto->cipher == CIPHER_AES)) |
| 598 | iveiv_entry.iv[3] |= 0x20; |
| 599 | iveiv_entry.iv[3] |= key->keyidx << 6; |
| 600 | rt2800_register_multiwrite(rt2x00dev, offset, |
| 601 | &iveiv_entry, sizeof(iveiv_entry)); |
| 602 | |
| 603 | offset = MAC_WCID_ENTRY(key->hw_key_idx); |
| 604 | |
| 605 | memset(&wcid_entry, 0, sizeof(wcid_entry)); |
| 606 | if (crypto->cmd == SET_KEY) |
| 607 | memcpy(&wcid_entry, crypto->address, ETH_ALEN); |
| 608 | rt2800_register_multiwrite(rt2x00dev, offset, |
| 609 | &wcid_entry, sizeof(wcid_entry)); |
| 610 | } |
| 611 | |
| 612 | int rt2800_config_shared_key(struct rt2x00_dev *rt2x00dev, |
| 613 | struct rt2x00lib_crypto *crypto, |
| 614 | struct ieee80211_key_conf *key) |
| 615 | { |
| 616 | struct hw_key_entry key_entry; |
| 617 | struct rt2x00_field32 field; |
| 618 | u32 offset; |
| 619 | u32 reg; |
| 620 | |
| 621 | if (crypto->cmd == SET_KEY) { |
| 622 | key->hw_key_idx = (4 * crypto->bssidx) + key->keyidx; |
| 623 | |
| 624 | memcpy(key_entry.key, crypto->key, |
| 625 | sizeof(key_entry.key)); |
| 626 | memcpy(key_entry.tx_mic, crypto->tx_mic, |
| 627 | sizeof(key_entry.tx_mic)); |
| 628 | memcpy(key_entry.rx_mic, crypto->rx_mic, |
| 629 | sizeof(key_entry.rx_mic)); |
| 630 | |
| 631 | offset = SHARED_KEY_ENTRY(key->hw_key_idx); |
| 632 | rt2800_register_multiwrite(rt2x00dev, offset, |
| 633 | &key_entry, sizeof(key_entry)); |
| 634 | } |
| 635 | |
| 636 | /* |
| 637 | * The cipher types are stored over multiple registers |
| 638 | * starting with SHARED_KEY_MODE_BASE each word will have |
| 639 | * 32 bits and contains the cipher types for 2 bssidx each. |
| 640 | * Using the correct defines correctly will cause overhead, |
| 641 | * so just calculate the correct offset. |
| 642 | */ |
| 643 | field.bit_offset = 4 * (key->hw_key_idx % 8); |
| 644 | field.bit_mask = 0x7 << field.bit_offset; |
| 645 | |
| 646 | offset = SHARED_KEY_MODE_ENTRY(key->hw_key_idx / 8); |
| 647 | |
| 648 | rt2800_register_read(rt2x00dev, offset, ®); |
| 649 | rt2x00_set_field32(®, field, |
| 650 | (crypto->cmd == SET_KEY) * crypto->cipher); |
| 651 | rt2800_register_write(rt2x00dev, offset, reg); |
| 652 | |
| 653 | /* |
| 654 | * Update WCID information |
| 655 | */ |
| 656 | rt2800_config_wcid_attr(rt2x00dev, crypto, key); |
| 657 | |
| 658 | return 0; |
| 659 | } |
| 660 | EXPORT_SYMBOL_GPL(rt2800_config_shared_key); |
| 661 | |
| 662 | int rt2800_config_pairwise_key(struct rt2x00_dev *rt2x00dev, |
| 663 | struct rt2x00lib_crypto *crypto, |
| 664 | struct ieee80211_key_conf *key) |
| 665 | { |
| 666 | struct hw_key_entry key_entry; |
| 667 | u32 offset; |
| 668 | |
| 669 | if (crypto->cmd == SET_KEY) { |
| 670 | /* |
| 671 | * 1 pairwise key is possible per AID, this means that the AID |
| 672 | * equals our hw_key_idx. Make sure the WCID starts _after_ the |
| 673 | * last possible shared key entry. |
| 674 | */ |
| 675 | if (crypto->aid > (256 - 32)) |
| 676 | return -ENOSPC; |
| 677 | |
| 678 | key->hw_key_idx = 32 + crypto->aid; |
| 679 | |
| 680 | memcpy(key_entry.key, crypto->key, |
| 681 | sizeof(key_entry.key)); |
| 682 | memcpy(key_entry.tx_mic, crypto->tx_mic, |
| 683 | sizeof(key_entry.tx_mic)); |
| 684 | memcpy(key_entry.rx_mic, crypto->rx_mic, |
| 685 | sizeof(key_entry.rx_mic)); |
| 686 | |
| 687 | offset = PAIRWISE_KEY_ENTRY(key->hw_key_idx); |
| 688 | rt2800_register_multiwrite(rt2x00dev, offset, |
| 689 | &key_entry, sizeof(key_entry)); |
| 690 | } |
| 691 | |
| 692 | /* |
| 693 | * Update WCID information |
| 694 | */ |
| 695 | rt2800_config_wcid_attr(rt2x00dev, crypto, key); |
| 696 | |
| 697 | return 0; |
| 698 | } |
| 699 | EXPORT_SYMBOL_GPL(rt2800_config_pairwise_key); |
| 700 | |
| 701 | void rt2800_config_filter(struct rt2x00_dev *rt2x00dev, |
| 702 | const unsigned int filter_flags) |
| 703 | { |
| 704 | u32 reg; |
| 705 | |
| 706 | /* |
| 707 | * Start configuration steps. |
| 708 | * Note that the version error will always be dropped |
| 709 | * and broadcast frames will always be accepted since |
| 710 | * there is no filter for it at this time. |
| 711 | */ |
| 712 | rt2800_register_read(rt2x00dev, RX_FILTER_CFG, ®); |
| 713 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CRC_ERROR, |
| 714 | !(filter_flags & FIF_FCSFAIL)); |
| 715 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_PHY_ERROR, |
| 716 | !(filter_flags & FIF_PLCPFAIL)); |
| 717 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_NOT_TO_ME, |
| 718 | !(filter_flags & FIF_PROMISC_IN_BSS)); |
| 719 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_NOT_MY_BSSD, 0); |
| 720 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_VER_ERROR, 1); |
| 721 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_MULTICAST, |
| 722 | !(filter_flags & FIF_ALLMULTI)); |
| 723 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_BROADCAST, 0); |
| 724 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_DUPLICATE, 1); |
| 725 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CF_END_ACK, |
| 726 | !(filter_flags & FIF_CONTROL)); |
| 727 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CF_END, |
| 728 | !(filter_flags & FIF_CONTROL)); |
| 729 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_ACK, |
| 730 | !(filter_flags & FIF_CONTROL)); |
| 731 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CTS, |
| 732 | !(filter_flags & FIF_CONTROL)); |
| 733 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_RTS, |
| 734 | !(filter_flags & FIF_CONTROL)); |
| 735 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_PSPOLL, |
| 736 | !(filter_flags & FIF_PSPOLL)); |
| 737 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_BA, 1); |
| 738 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_BAR, 0); |
| 739 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CNTL, |
| 740 | !(filter_flags & FIF_CONTROL)); |
| 741 | rt2800_register_write(rt2x00dev, RX_FILTER_CFG, reg); |
| 742 | } |
| 743 | EXPORT_SYMBOL_GPL(rt2800_config_filter); |
| 744 | |
| 745 | void rt2800_config_intf(struct rt2x00_dev *rt2x00dev, struct rt2x00_intf *intf, |
| 746 | struct rt2x00intf_conf *conf, const unsigned int flags) |
| 747 | { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 748 | u32 reg; |
| 749 | |
| 750 | if (flags & CONFIG_UPDATE_TYPE) { |
| 751 | /* |
| 752 | * Clear current synchronisation setup. |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 753 | */ |
Helmut Schaa | fdb8725 | 2010-06-29 21:48:06 +0200 | [diff] [blame] | 754 | rt2800_clear_beacon(rt2x00dev, |
| 755 | HW_BEACON_OFFSET(intf->beacon->entry_idx)); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 756 | /* |
| 757 | * Enable synchronisation. |
| 758 | */ |
| 759 | rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®); |
| 760 | rt2x00_set_field32(®, BCN_TIME_CFG_TSF_TICKING, 1); |
| 761 | rt2x00_set_field32(®, BCN_TIME_CFG_TSF_SYNC, conf->sync); |
Josef Bacik | 6a62e5e | 2009-11-15 21:33:18 -0500 | [diff] [blame] | 762 | rt2x00_set_field32(®, BCN_TIME_CFG_TBTT_ENABLE, |
| 763 | (conf->sync == TSF_SYNC_BEACON)); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 764 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
| 765 | } |
| 766 | |
| 767 | if (flags & CONFIG_UPDATE_MAC) { |
| 768 | reg = le32_to_cpu(conf->mac[1]); |
| 769 | rt2x00_set_field32(®, MAC_ADDR_DW1_UNICAST_TO_ME_MASK, 0xff); |
| 770 | conf->mac[1] = cpu_to_le32(reg); |
| 771 | |
| 772 | rt2800_register_multiwrite(rt2x00dev, MAC_ADDR_DW0, |
| 773 | conf->mac, sizeof(conf->mac)); |
| 774 | } |
| 775 | |
| 776 | if (flags & CONFIG_UPDATE_BSSID) { |
| 777 | reg = le32_to_cpu(conf->bssid[1]); |
Ivo van Doorn | d440cb9 | 2010-06-29 21:45:31 +0200 | [diff] [blame] | 778 | rt2x00_set_field32(®, MAC_BSSID_DW1_BSS_ID_MASK, 3); |
| 779 | rt2x00_set_field32(®, MAC_BSSID_DW1_BSS_BCN_NUM, 7); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 780 | conf->bssid[1] = cpu_to_le32(reg); |
| 781 | |
| 782 | rt2800_register_multiwrite(rt2x00dev, MAC_BSSID_DW0, |
| 783 | conf->bssid, sizeof(conf->bssid)); |
| 784 | } |
| 785 | } |
| 786 | EXPORT_SYMBOL_GPL(rt2800_config_intf); |
| 787 | |
| 788 | void rt2800_config_erp(struct rt2x00_dev *rt2x00dev, struct rt2x00lib_erp *erp) |
| 789 | { |
| 790 | u32 reg; |
| 791 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 792 | rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, ®); |
| 793 | rt2x00_set_field32(®, AUTO_RSP_CFG_BAC_ACK_POLICY, |
| 794 | !!erp->short_preamble); |
| 795 | rt2x00_set_field32(®, AUTO_RSP_CFG_AR_PREAMBLE, |
| 796 | !!erp->short_preamble); |
| 797 | rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg); |
| 798 | |
| 799 | rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, ®); |
| 800 | rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_CTRL, |
| 801 | erp->cts_protection ? 2 : 0); |
| 802 | rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg); |
| 803 | |
| 804 | rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE, |
| 805 | erp->basic_rates); |
| 806 | rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003); |
| 807 | |
| 808 | rt2800_register_read(rt2x00dev, BKOFF_SLOT_CFG, ®); |
| 809 | rt2x00_set_field32(®, BKOFF_SLOT_CFG_SLOT_TIME, erp->slot_time); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 810 | rt2800_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg); |
| 811 | |
| 812 | rt2800_register_read(rt2x00dev, XIFS_TIME_CFG, ®); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 813 | rt2x00_set_field32(®, XIFS_TIME_CFG_EIFS, erp->eifs); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 814 | rt2800_register_write(rt2x00dev, XIFS_TIME_CFG, reg); |
| 815 | |
| 816 | rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®); |
| 817 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_INTERVAL, |
| 818 | erp->beacon_int * 16); |
| 819 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
| 820 | } |
| 821 | EXPORT_SYMBOL_GPL(rt2800_config_erp); |
| 822 | |
| 823 | void rt2800_config_ant(struct rt2x00_dev *rt2x00dev, struct antenna_setup *ant) |
| 824 | { |
| 825 | u8 r1; |
| 826 | u8 r3; |
| 827 | |
| 828 | rt2800_bbp_read(rt2x00dev, 1, &r1); |
| 829 | rt2800_bbp_read(rt2x00dev, 3, &r3); |
| 830 | |
| 831 | /* |
| 832 | * Configure the TX antenna. |
| 833 | */ |
| 834 | switch ((int)ant->tx) { |
| 835 | case 1: |
| 836 | rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 837 | break; |
| 838 | case 2: |
| 839 | rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2); |
| 840 | break; |
| 841 | case 3: |
Ivo van Doorn | e22557f | 2010-06-29 21:49:05 +0200 | [diff] [blame] | 842 | rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 843 | break; |
| 844 | } |
| 845 | |
| 846 | /* |
| 847 | * Configure the RX antenna. |
| 848 | */ |
| 849 | switch ((int)ant->rx) { |
| 850 | case 1: |
| 851 | rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0); |
| 852 | break; |
| 853 | case 2: |
| 854 | rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 1); |
| 855 | break; |
| 856 | case 3: |
| 857 | rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 2); |
| 858 | break; |
| 859 | } |
| 860 | |
| 861 | rt2800_bbp_write(rt2x00dev, 3, r3); |
| 862 | rt2800_bbp_write(rt2x00dev, 1, r1); |
| 863 | } |
| 864 | EXPORT_SYMBOL_GPL(rt2800_config_ant); |
| 865 | |
| 866 | static void rt2800_config_lna_gain(struct rt2x00_dev *rt2x00dev, |
| 867 | struct rt2x00lib_conf *libconf) |
| 868 | { |
| 869 | u16 eeprom; |
| 870 | short lna_gain; |
| 871 | |
| 872 | if (libconf->rf.channel <= 14) { |
| 873 | rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom); |
| 874 | lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_BG); |
| 875 | } else if (libconf->rf.channel <= 64) { |
| 876 | rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom); |
| 877 | lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_A0); |
| 878 | } else if (libconf->rf.channel <= 128) { |
| 879 | rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom); |
| 880 | lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG2_LNA_A1); |
| 881 | } else { |
| 882 | rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom); |
| 883 | lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_A2_LNA_A2); |
| 884 | } |
| 885 | |
| 886 | rt2x00dev->lna_gain = lna_gain; |
| 887 | } |
| 888 | |
Gertjan van Wingerde | 06855ef | 2010-04-11 14:31:07 +0200 | [diff] [blame] | 889 | static void rt2800_config_channel_rf2xxx(struct rt2x00_dev *rt2x00dev, |
| 890 | struct ieee80211_conf *conf, |
| 891 | struct rf_channel *rf, |
| 892 | struct channel_info *info) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 893 | { |
| 894 | rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset); |
| 895 | |
| 896 | if (rt2x00dev->default_ant.tx == 1) |
| 897 | rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_TX1, 1); |
| 898 | |
| 899 | if (rt2x00dev->default_ant.rx == 1) { |
| 900 | rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX1, 1); |
| 901 | rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1); |
| 902 | } else if (rt2x00dev->default_ant.rx == 2) |
| 903 | rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1); |
| 904 | |
| 905 | if (rf->channel > 14) { |
| 906 | /* |
| 907 | * When TX power is below 0, we should increase it by 7 to |
| 908 | * make it a positive value (Minumum value is -7). |
| 909 | * However this means that values between 0 and 7 have |
| 910 | * double meaning, and we should set a 7DBm boost flag. |
| 911 | */ |
| 912 | rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A_7DBM_BOOST, |
| 913 | (info->tx_power1 >= 0)); |
| 914 | |
| 915 | if (info->tx_power1 < 0) |
| 916 | info->tx_power1 += 7; |
| 917 | |
| 918 | rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A, |
| 919 | TXPOWER_A_TO_DEV(info->tx_power1)); |
| 920 | |
| 921 | rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A_7DBM_BOOST, |
| 922 | (info->tx_power2 >= 0)); |
| 923 | |
| 924 | if (info->tx_power2 < 0) |
| 925 | info->tx_power2 += 7; |
| 926 | |
| 927 | rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A, |
| 928 | TXPOWER_A_TO_DEV(info->tx_power2)); |
| 929 | } else { |
| 930 | rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_G, |
| 931 | TXPOWER_G_TO_DEV(info->tx_power1)); |
| 932 | rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_G, |
| 933 | TXPOWER_G_TO_DEV(info->tx_power2)); |
| 934 | } |
| 935 | |
| 936 | rt2x00_set_field32(&rf->rf4, RF4_HT40, conf_is_ht40(conf)); |
| 937 | |
| 938 | rt2800_rf_write(rt2x00dev, 1, rf->rf1); |
| 939 | rt2800_rf_write(rt2x00dev, 2, rf->rf2); |
| 940 | rt2800_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004); |
| 941 | rt2800_rf_write(rt2x00dev, 4, rf->rf4); |
| 942 | |
| 943 | udelay(200); |
| 944 | |
| 945 | rt2800_rf_write(rt2x00dev, 1, rf->rf1); |
| 946 | rt2800_rf_write(rt2x00dev, 2, rf->rf2); |
| 947 | rt2800_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004); |
| 948 | rt2800_rf_write(rt2x00dev, 4, rf->rf4); |
| 949 | |
| 950 | udelay(200); |
| 951 | |
| 952 | rt2800_rf_write(rt2x00dev, 1, rf->rf1); |
| 953 | rt2800_rf_write(rt2x00dev, 2, rf->rf2); |
| 954 | rt2800_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004); |
| 955 | rt2800_rf_write(rt2x00dev, 4, rf->rf4); |
| 956 | } |
| 957 | |
Gertjan van Wingerde | 06855ef | 2010-04-11 14:31:07 +0200 | [diff] [blame] | 958 | static void rt2800_config_channel_rf3xxx(struct rt2x00_dev *rt2x00dev, |
| 959 | struct ieee80211_conf *conf, |
| 960 | struct rf_channel *rf, |
| 961 | struct channel_info *info) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 962 | { |
| 963 | u8 rfcsr; |
| 964 | |
| 965 | rt2800_rfcsr_write(rt2x00dev, 2, rf->rf1); |
Gertjan van Wingerde | 41a2617 | 2009-11-09 22:59:04 +0100 | [diff] [blame] | 966 | rt2800_rfcsr_write(rt2x00dev, 3, rf->rf3); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 967 | |
| 968 | rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr); |
Gertjan van Wingerde | fab799c | 2010-04-11 14:31:08 +0200 | [diff] [blame] | 969 | rt2x00_set_field8(&rfcsr, RFCSR6_R1, rf->rf2); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 970 | rt2800_rfcsr_write(rt2x00dev, 6, rfcsr); |
| 971 | |
| 972 | rt2800_rfcsr_read(rt2x00dev, 12, &rfcsr); |
| 973 | rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER, |
| 974 | TXPOWER_G_TO_DEV(info->tx_power1)); |
| 975 | rt2800_rfcsr_write(rt2x00dev, 12, rfcsr); |
| 976 | |
Helmut Schaa | 5a67396 | 2010-04-23 15:54:43 +0200 | [diff] [blame] | 977 | rt2800_rfcsr_read(rt2x00dev, 13, &rfcsr); |
| 978 | rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER, |
| 979 | TXPOWER_G_TO_DEV(info->tx_power2)); |
| 980 | rt2800_rfcsr_write(rt2x00dev, 13, rfcsr); |
| 981 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 982 | rt2800_rfcsr_read(rt2x00dev, 23, &rfcsr); |
| 983 | rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset); |
| 984 | rt2800_rfcsr_write(rt2x00dev, 23, rfcsr); |
| 985 | |
| 986 | rt2800_rfcsr_write(rt2x00dev, 24, |
| 987 | rt2x00dev->calibration[conf_is_ht40(conf)]); |
| 988 | |
Gertjan van Wingerde | 7197690 | 2010-03-24 21:42:36 +0100 | [diff] [blame] | 989 | rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 990 | rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1); |
Gertjan van Wingerde | 7197690 | 2010-03-24 21:42:36 +0100 | [diff] [blame] | 991 | rt2800_rfcsr_write(rt2x00dev, 7, rfcsr); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev, |
| 995 | struct ieee80211_conf *conf, |
| 996 | struct rf_channel *rf, |
| 997 | struct channel_info *info) |
| 998 | { |
| 999 | u32 reg; |
| 1000 | unsigned int tx_pin; |
| 1001 | u8 bbp; |
| 1002 | |
Gertjan van Wingerde | 06855ef | 2010-04-11 14:31:07 +0200 | [diff] [blame] | 1003 | if (rt2x00_rf(rt2x00dev, RF2020) || |
| 1004 | rt2x00_rf(rt2x00dev, RF3020) || |
| 1005 | rt2x00_rf(rt2x00dev, RF3021) || |
| 1006 | rt2x00_rf(rt2x00dev, RF3022)) |
| 1007 | rt2800_config_channel_rf3xxx(rt2x00dev, conf, rf, info); |
Gertjan van Wingerde | fa6f632 | 2009-11-09 22:59:58 +0100 | [diff] [blame] | 1008 | else |
Gertjan van Wingerde | 06855ef | 2010-04-11 14:31:07 +0200 | [diff] [blame] | 1009 | rt2800_config_channel_rf2xxx(rt2x00dev, conf, rf, info); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1010 | |
| 1011 | /* |
| 1012 | * Change BBP settings |
| 1013 | */ |
| 1014 | rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain); |
| 1015 | rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain); |
| 1016 | rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain); |
| 1017 | rt2800_bbp_write(rt2x00dev, 86, 0); |
| 1018 | |
| 1019 | if (rf->channel <= 14) { |
| 1020 | if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags)) { |
| 1021 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
| 1022 | rt2800_bbp_write(rt2x00dev, 75, 0x46); |
| 1023 | } else { |
| 1024 | rt2800_bbp_write(rt2x00dev, 82, 0x84); |
| 1025 | rt2800_bbp_write(rt2x00dev, 75, 0x50); |
| 1026 | } |
| 1027 | } else { |
| 1028 | rt2800_bbp_write(rt2x00dev, 82, 0xf2); |
| 1029 | |
| 1030 | if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags)) |
| 1031 | rt2800_bbp_write(rt2x00dev, 75, 0x46); |
| 1032 | else |
| 1033 | rt2800_bbp_write(rt2x00dev, 75, 0x50); |
| 1034 | } |
| 1035 | |
| 1036 | rt2800_register_read(rt2x00dev, TX_BAND_CFG, ®); |
Gertjan van Wingerde | a21ee72 | 2010-05-03 22:43:04 +0200 | [diff] [blame] | 1037 | 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] | 1038 | rt2x00_set_field32(®, TX_BAND_CFG_A, rf->channel > 14); |
| 1039 | rt2x00_set_field32(®, TX_BAND_CFG_BG, rf->channel <= 14); |
| 1040 | rt2800_register_write(rt2x00dev, TX_BAND_CFG, reg); |
| 1041 | |
| 1042 | tx_pin = 0; |
| 1043 | |
| 1044 | /* Turn on unused PA or LNA when not using 1T or 1R */ |
| 1045 | if (rt2x00dev->default_ant.tx != 1) { |
| 1046 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1); |
| 1047 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1); |
| 1048 | } |
| 1049 | |
| 1050 | /* Turn on unused PA or LNA when not using 1T or 1R */ |
| 1051 | if (rt2x00dev->default_ant.rx != 1) { |
| 1052 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1); |
| 1053 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1); |
| 1054 | } |
| 1055 | |
| 1056 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN, 1); |
| 1057 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN, 1); |
| 1058 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1); |
| 1059 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_TRSW_EN, 1); |
| 1060 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, rf->channel <= 14); |
| 1061 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, rf->channel > 14); |
| 1062 | |
| 1063 | rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin); |
| 1064 | |
| 1065 | rt2800_bbp_read(rt2x00dev, 4, &bbp); |
| 1066 | rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * conf_is_ht40(conf)); |
| 1067 | rt2800_bbp_write(rt2x00dev, 4, bbp); |
| 1068 | |
| 1069 | rt2800_bbp_read(rt2x00dev, 3, &bbp); |
Gertjan van Wingerde | a21ee72 | 2010-05-03 22:43:04 +0200 | [diff] [blame] | 1070 | rt2x00_set_field8(&bbp, BBP3_HT40_MINUS, conf_is_ht40_minus(conf)); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1071 | rt2800_bbp_write(rt2x00dev, 3, bbp); |
| 1072 | |
Gertjan van Wingerde | 8d0c9b6 | 2010-04-11 14:31:10 +0200 | [diff] [blame] | 1073 | if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1074 | if (conf_is_ht40(conf)) { |
| 1075 | rt2800_bbp_write(rt2x00dev, 69, 0x1a); |
| 1076 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
| 1077 | rt2800_bbp_write(rt2x00dev, 73, 0x16); |
| 1078 | } else { |
| 1079 | rt2800_bbp_write(rt2x00dev, 69, 0x16); |
| 1080 | rt2800_bbp_write(rt2x00dev, 70, 0x08); |
| 1081 | rt2800_bbp_write(rt2x00dev, 73, 0x11); |
| 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | msleep(1); |
| 1086 | } |
| 1087 | |
| 1088 | static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev, |
| 1089 | const int txpower) |
| 1090 | { |
| 1091 | u32 reg; |
| 1092 | u32 value = TXPOWER_G_TO_DEV(txpower); |
| 1093 | u8 r1; |
| 1094 | |
| 1095 | rt2800_bbp_read(rt2x00dev, 1, &r1); |
Helmut Schaa | a3f84ca | 2010-06-14 22:11:32 +0200 | [diff] [blame] | 1096 | rt2x00_set_field8(&r1, BBP1_TX_POWER, 0); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1097 | rt2800_bbp_write(rt2x00dev, 1, r1); |
| 1098 | |
| 1099 | rt2800_register_read(rt2x00dev, TX_PWR_CFG_0, ®); |
| 1100 | rt2x00_set_field32(®, TX_PWR_CFG_0_1MBS, value); |
| 1101 | rt2x00_set_field32(®, TX_PWR_CFG_0_2MBS, value); |
| 1102 | rt2x00_set_field32(®, TX_PWR_CFG_0_55MBS, value); |
| 1103 | rt2x00_set_field32(®, TX_PWR_CFG_0_11MBS, value); |
| 1104 | rt2x00_set_field32(®, TX_PWR_CFG_0_6MBS, value); |
| 1105 | rt2x00_set_field32(®, TX_PWR_CFG_0_9MBS, value); |
| 1106 | rt2x00_set_field32(®, TX_PWR_CFG_0_12MBS, value); |
| 1107 | rt2x00_set_field32(®, TX_PWR_CFG_0_18MBS, value); |
| 1108 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_0, reg); |
| 1109 | |
| 1110 | rt2800_register_read(rt2x00dev, TX_PWR_CFG_1, ®); |
| 1111 | rt2x00_set_field32(®, TX_PWR_CFG_1_24MBS, value); |
| 1112 | rt2x00_set_field32(®, TX_PWR_CFG_1_36MBS, value); |
| 1113 | rt2x00_set_field32(®, TX_PWR_CFG_1_48MBS, value); |
| 1114 | rt2x00_set_field32(®, TX_PWR_CFG_1_54MBS, value); |
| 1115 | rt2x00_set_field32(®, TX_PWR_CFG_1_MCS0, value); |
| 1116 | rt2x00_set_field32(®, TX_PWR_CFG_1_MCS1, value); |
| 1117 | rt2x00_set_field32(®, TX_PWR_CFG_1_MCS2, value); |
| 1118 | rt2x00_set_field32(®, TX_PWR_CFG_1_MCS3, value); |
| 1119 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_1, reg); |
| 1120 | |
| 1121 | rt2800_register_read(rt2x00dev, TX_PWR_CFG_2, ®); |
| 1122 | rt2x00_set_field32(®, TX_PWR_CFG_2_MCS4, value); |
| 1123 | rt2x00_set_field32(®, TX_PWR_CFG_2_MCS5, value); |
| 1124 | rt2x00_set_field32(®, TX_PWR_CFG_2_MCS6, value); |
| 1125 | rt2x00_set_field32(®, TX_PWR_CFG_2_MCS7, value); |
| 1126 | rt2x00_set_field32(®, TX_PWR_CFG_2_MCS8, value); |
| 1127 | rt2x00_set_field32(®, TX_PWR_CFG_2_MCS9, value); |
| 1128 | rt2x00_set_field32(®, TX_PWR_CFG_2_MCS10, value); |
| 1129 | rt2x00_set_field32(®, TX_PWR_CFG_2_MCS11, value); |
| 1130 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_2, reg); |
| 1131 | |
| 1132 | rt2800_register_read(rt2x00dev, TX_PWR_CFG_3, ®); |
| 1133 | rt2x00_set_field32(®, TX_PWR_CFG_3_MCS12, value); |
| 1134 | rt2x00_set_field32(®, TX_PWR_CFG_3_MCS13, value); |
| 1135 | rt2x00_set_field32(®, TX_PWR_CFG_3_MCS14, value); |
| 1136 | rt2x00_set_field32(®, TX_PWR_CFG_3_MCS15, value); |
| 1137 | rt2x00_set_field32(®, TX_PWR_CFG_3_UKNOWN1, value); |
| 1138 | rt2x00_set_field32(®, TX_PWR_CFG_3_UKNOWN2, value); |
| 1139 | rt2x00_set_field32(®, TX_PWR_CFG_3_UKNOWN3, value); |
| 1140 | rt2x00_set_field32(®, TX_PWR_CFG_3_UKNOWN4, value); |
| 1141 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_3, reg); |
| 1142 | |
| 1143 | rt2800_register_read(rt2x00dev, TX_PWR_CFG_4, ®); |
| 1144 | rt2x00_set_field32(®, TX_PWR_CFG_4_UKNOWN5, value); |
| 1145 | rt2x00_set_field32(®, TX_PWR_CFG_4_UKNOWN6, value); |
| 1146 | rt2x00_set_field32(®, TX_PWR_CFG_4_UKNOWN7, value); |
| 1147 | rt2x00_set_field32(®, TX_PWR_CFG_4_UKNOWN8, value); |
| 1148 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_4, reg); |
| 1149 | } |
| 1150 | |
| 1151 | static void rt2800_config_retry_limit(struct rt2x00_dev *rt2x00dev, |
| 1152 | struct rt2x00lib_conf *libconf) |
| 1153 | { |
| 1154 | u32 reg; |
| 1155 | |
| 1156 | rt2800_register_read(rt2x00dev, TX_RTY_CFG, ®); |
| 1157 | rt2x00_set_field32(®, TX_RTY_CFG_SHORT_RTY_LIMIT, |
| 1158 | libconf->conf->short_frame_max_tx_count); |
| 1159 | rt2x00_set_field32(®, TX_RTY_CFG_LONG_RTY_LIMIT, |
| 1160 | libconf->conf->long_frame_max_tx_count); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1161 | rt2800_register_write(rt2x00dev, TX_RTY_CFG, reg); |
| 1162 | } |
| 1163 | |
| 1164 | static void rt2800_config_ps(struct rt2x00_dev *rt2x00dev, |
| 1165 | struct rt2x00lib_conf *libconf) |
| 1166 | { |
| 1167 | enum dev_state state = |
| 1168 | (libconf->conf->flags & IEEE80211_CONF_PS) ? |
| 1169 | STATE_SLEEP : STATE_AWAKE; |
| 1170 | u32 reg; |
| 1171 | |
| 1172 | if (state == STATE_SLEEP) { |
| 1173 | rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0); |
| 1174 | |
| 1175 | rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG, ®); |
| 1176 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 5); |
| 1177 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE, |
| 1178 | libconf->conf->listen_interval - 1); |
| 1179 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTOWAKE, 1); |
| 1180 | rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg); |
| 1181 | |
| 1182 | rt2x00dev->ops->lib->set_device_state(rt2x00dev, state); |
| 1183 | } else { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1184 | rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG, ®); |
| 1185 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 0); |
| 1186 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE, 0); |
| 1187 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTOWAKE, 0); |
| 1188 | rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg); |
Gertjan van Wingerde | 5731858 | 2010-03-30 23:50:23 +0200 | [diff] [blame] | 1189 | |
| 1190 | rt2x00dev->ops->lib->set_device_state(rt2x00dev, state); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | void rt2800_config(struct rt2x00_dev *rt2x00dev, |
| 1195 | struct rt2x00lib_conf *libconf, |
| 1196 | const unsigned int flags) |
| 1197 | { |
| 1198 | /* Always recalculate LNA gain before changing configuration */ |
| 1199 | rt2800_config_lna_gain(rt2x00dev, libconf); |
| 1200 | |
| 1201 | if (flags & IEEE80211_CONF_CHANGE_CHANNEL) |
| 1202 | rt2800_config_channel(rt2x00dev, libconf->conf, |
| 1203 | &libconf->rf, &libconf->channel); |
| 1204 | if (flags & IEEE80211_CONF_CHANGE_POWER) |
| 1205 | rt2800_config_txpower(rt2x00dev, libconf->conf->power_level); |
| 1206 | if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS) |
| 1207 | rt2800_config_retry_limit(rt2x00dev, libconf); |
| 1208 | if (flags & IEEE80211_CONF_CHANGE_PS) |
| 1209 | rt2800_config_ps(rt2x00dev, libconf); |
| 1210 | } |
| 1211 | EXPORT_SYMBOL_GPL(rt2800_config); |
| 1212 | |
| 1213 | /* |
| 1214 | * Link tuning |
| 1215 | */ |
| 1216 | void rt2800_link_stats(struct rt2x00_dev *rt2x00dev, struct link_qual *qual) |
| 1217 | { |
| 1218 | u32 reg; |
| 1219 | |
| 1220 | /* |
| 1221 | * Update FCS error count from register. |
| 1222 | */ |
| 1223 | rt2800_register_read(rt2x00dev, RX_STA_CNT0, ®); |
| 1224 | qual->rx_failed = rt2x00_get_field32(reg, RX_STA_CNT0_CRC_ERR); |
| 1225 | } |
| 1226 | EXPORT_SYMBOL_GPL(rt2800_link_stats); |
| 1227 | |
| 1228 | static u8 rt2800_get_default_vgc(struct rt2x00_dev *rt2x00dev) |
| 1229 | { |
| 1230 | if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) { |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 1231 | if (rt2x00_rt(rt2x00dev, RT3070) || |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 1232 | rt2x00_rt(rt2x00dev, RT3071) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 1233 | rt2x00_rt(rt2x00dev, RT3090) || |
| 1234 | rt2x00_rt(rt2x00dev, RT3390)) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1235 | return 0x1c + (2 * rt2x00dev->lna_gain); |
| 1236 | else |
| 1237 | return 0x2e + rt2x00dev->lna_gain; |
| 1238 | } |
| 1239 | |
| 1240 | if (!test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags)) |
| 1241 | return 0x32 + (rt2x00dev->lna_gain * 5) / 3; |
| 1242 | else |
| 1243 | return 0x3a + (rt2x00dev->lna_gain * 5) / 3; |
| 1244 | } |
| 1245 | |
| 1246 | static inline void rt2800_set_vgc(struct rt2x00_dev *rt2x00dev, |
| 1247 | struct link_qual *qual, u8 vgc_level) |
| 1248 | { |
| 1249 | if (qual->vgc_level != vgc_level) { |
| 1250 | rt2800_bbp_write(rt2x00dev, 66, vgc_level); |
| 1251 | qual->vgc_level = vgc_level; |
| 1252 | qual->vgc_level_reg = vgc_level; |
| 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | void rt2800_reset_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual) |
| 1257 | { |
| 1258 | rt2800_set_vgc(rt2x00dev, qual, rt2800_get_default_vgc(rt2x00dev)); |
| 1259 | } |
| 1260 | EXPORT_SYMBOL_GPL(rt2800_reset_tuner); |
| 1261 | |
| 1262 | void rt2800_link_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual, |
| 1263 | const u32 count) |
| 1264 | { |
Gertjan van Wingerde | 8d0c9b6 | 2010-04-11 14:31:10 +0200 | [diff] [blame] | 1265 | if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1266 | return; |
| 1267 | |
| 1268 | /* |
| 1269 | * When RSSI is better then -80 increase VGC level with 0x10 |
| 1270 | */ |
| 1271 | rt2800_set_vgc(rt2x00dev, qual, |
| 1272 | rt2800_get_default_vgc(rt2x00dev) + |
| 1273 | ((qual->rssi > -80) * 0x10)); |
| 1274 | } |
| 1275 | EXPORT_SYMBOL_GPL(rt2800_link_tuner); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1276 | |
| 1277 | /* |
| 1278 | * Initialization functions. |
| 1279 | */ |
| 1280 | int rt2800_init_registers(struct rt2x00_dev *rt2x00dev) |
| 1281 | { |
| 1282 | u32 reg; |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 1283 | u16 eeprom; |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1284 | unsigned int i; |
Gertjan van Wingerde | e3a896b | 2010-06-03 10:52:04 +0200 | [diff] [blame] | 1285 | int ret; |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1286 | |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1287 | rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®); |
| 1288 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0); |
| 1289 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_DMA_BUSY, 0); |
| 1290 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0); |
| 1291 | rt2x00_set_field32(®, WPDMA_GLO_CFG_RX_DMA_BUSY, 0); |
| 1292 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1); |
| 1293 | rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg); |
| 1294 | |
Gertjan van Wingerde | e3a896b | 2010-06-03 10:52:04 +0200 | [diff] [blame] | 1295 | ret = rt2800_drv_init_registers(rt2x00dev); |
| 1296 | if (ret) |
| 1297 | return ret; |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1298 | |
| 1299 | rt2800_register_read(rt2x00dev, BCN_OFFSET0, ®); |
| 1300 | rt2x00_set_field32(®, BCN_OFFSET0_BCN0, 0xe0); /* 0x3800 */ |
| 1301 | rt2x00_set_field32(®, BCN_OFFSET0_BCN1, 0xe8); /* 0x3a00 */ |
| 1302 | rt2x00_set_field32(®, BCN_OFFSET0_BCN2, 0xf0); /* 0x3c00 */ |
| 1303 | rt2x00_set_field32(®, BCN_OFFSET0_BCN3, 0xf8); /* 0x3e00 */ |
| 1304 | rt2800_register_write(rt2x00dev, BCN_OFFSET0, reg); |
| 1305 | |
| 1306 | rt2800_register_read(rt2x00dev, BCN_OFFSET1, ®); |
| 1307 | rt2x00_set_field32(®, BCN_OFFSET1_BCN4, 0xc8); /* 0x3200 */ |
| 1308 | rt2x00_set_field32(®, BCN_OFFSET1_BCN5, 0xd0); /* 0x3400 */ |
| 1309 | rt2x00_set_field32(®, BCN_OFFSET1_BCN6, 0x77); /* 0x1dc0 */ |
| 1310 | rt2x00_set_field32(®, BCN_OFFSET1_BCN7, 0x6f); /* 0x1bc0 */ |
| 1311 | rt2800_register_write(rt2x00dev, BCN_OFFSET1, reg); |
| 1312 | |
| 1313 | rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE, 0x0000013f); |
| 1314 | rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003); |
| 1315 | |
| 1316 | rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000); |
| 1317 | |
| 1318 | rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®); |
| 1319 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_INTERVAL, 0); |
| 1320 | rt2x00_set_field32(®, BCN_TIME_CFG_TSF_TICKING, 0); |
| 1321 | rt2x00_set_field32(®, BCN_TIME_CFG_TSF_SYNC, 0); |
| 1322 | rt2x00_set_field32(®, BCN_TIME_CFG_TBTT_ENABLE, 0); |
| 1323 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 0); |
| 1324 | rt2x00_set_field32(®, BCN_TIME_CFG_TX_TIME_COMPENSATE, 0); |
| 1325 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
| 1326 | |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1327 | rt2800_config_filter(rt2x00dev, FIF_ALLMULTI); |
| 1328 | |
| 1329 | rt2800_register_read(rt2x00dev, BKOFF_SLOT_CFG, ®); |
| 1330 | rt2x00_set_field32(®, BKOFF_SLOT_CFG_SLOT_TIME, 9); |
| 1331 | rt2x00_set_field32(®, BKOFF_SLOT_CFG_CC_DELAY_TIME, 2); |
| 1332 | rt2800_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg); |
| 1333 | |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 1334 | if (rt2x00_rt(rt2x00dev, RT3071) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 1335 | rt2x00_rt(rt2x00dev, RT3090) || |
| 1336 | rt2x00_rt(rt2x00dev, RT3390)) { |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1337 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400); |
| 1338 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000); |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 1339 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 1340 | rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E) || |
| 1341 | rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) { |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 1342 | rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom); |
| 1343 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_DAC_TEST)) |
| 1344 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, |
| 1345 | 0x0000002c); |
| 1346 | else |
| 1347 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, |
| 1348 | 0x0000000f); |
| 1349 | } else { |
| 1350 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000); |
| 1351 | } |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 1352 | } else if (rt2x00_rt(rt2x00dev, RT3070)) { |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1353 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400); |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 1354 | |
| 1355 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) { |
| 1356 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000); |
| 1357 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x0000002c); |
| 1358 | } else { |
| 1359 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606); |
| 1360 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000); |
| 1361 | } |
Helmut Schaa | c295a81 | 2010-06-03 10:52:13 +0200 | [diff] [blame] | 1362 | } else if (rt2800_is_305x_soc(rt2x00dev)) { |
| 1363 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400); |
| 1364 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000); |
| 1365 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x0000001f); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1366 | } else { |
| 1367 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000000); |
| 1368 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606); |
| 1369 | } |
| 1370 | |
| 1371 | rt2800_register_read(rt2x00dev, TX_LINK_CFG, ®); |
| 1372 | rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_MFB_LIFETIME, 32); |
| 1373 | rt2x00_set_field32(®, TX_LINK_CFG_MFB_ENABLE, 0); |
| 1374 | rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_UMFS_ENABLE, 0); |
| 1375 | rt2x00_set_field32(®, TX_LINK_CFG_TX_MRQ_EN, 0); |
| 1376 | rt2x00_set_field32(®, TX_LINK_CFG_TX_RDG_EN, 0); |
| 1377 | rt2x00_set_field32(®, TX_LINK_CFG_TX_CF_ACK_EN, 1); |
| 1378 | rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_MFB, 0); |
| 1379 | rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_MFS, 0); |
| 1380 | rt2800_register_write(rt2x00dev, TX_LINK_CFG, reg); |
| 1381 | |
| 1382 | rt2800_register_read(rt2x00dev, TX_TIMEOUT_CFG, ®); |
| 1383 | rt2x00_set_field32(®, TX_TIMEOUT_CFG_MPDU_LIFETIME, 9); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1384 | rt2x00_set_field32(®, TX_TIMEOUT_CFG_RX_ACK_TIMEOUT, 32); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1385 | rt2x00_set_field32(®, TX_TIMEOUT_CFG_TX_OP_TIMEOUT, 10); |
| 1386 | rt2800_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg); |
| 1387 | |
| 1388 | rt2800_register_read(rt2x00dev, MAX_LEN_CFG, ®); |
| 1389 | rt2x00_set_field32(®, MAX_LEN_CFG_MAX_MPDU, AGGREGATION_SIZE); |
Gertjan van Wingerde | 8d0c9b6 | 2010-04-11 14:31:10 +0200 | [diff] [blame] | 1390 | if (rt2x00_rt_rev_gte(rt2x00dev, RT2872, REV_RT2872E) || |
Gertjan van Wingerde | 49e721e | 2010-02-13 20:55:49 +0100 | [diff] [blame] | 1391 | rt2x00_rt(rt2x00dev, RT2883) || |
Gertjan van Wingerde | 8d0c9b6 | 2010-04-11 14:31:10 +0200 | [diff] [blame] | 1392 | rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070E)) |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1393 | rt2x00_set_field32(®, MAX_LEN_CFG_MAX_PSDU, 2); |
| 1394 | else |
| 1395 | rt2x00_set_field32(®, MAX_LEN_CFG_MAX_PSDU, 1); |
| 1396 | rt2x00_set_field32(®, MAX_LEN_CFG_MIN_PSDU, 0); |
| 1397 | rt2x00_set_field32(®, MAX_LEN_CFG_MIN_MPDU, 0); |
| 1398 | rt2800_register_write(rt2x00dev, MAX_LEN_CFG, reg); |
| 1399 | |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1400 | rt2800_register_read(rt2x00dev, LED_CFG, ®); |
| 1401 | rt2x00_set_field32(®, LED_CFG_ON_PERIOD, 70); |
| 1402 | rt2x00_set_field32(®, LED_CFG_OFF_PERIOD, 30); |
| 1403 | rt2x00_set_field32(®, LED_CFG_SLOW_BLINK_PERIOD, 3); |
| 1404 | rt2x00_set_field32(®, LED_CFG_R_LED_MODE, 3); |
| 1405 | rt2x00_set_field32(®, LED_CFG_G_LED_MODE, 3); |
| 1406 | rt2x00_set_field32(®, LED_CFG_Y_LED_MODE, 3); |
| 1407 | rt2x00_set_field32(®, LED_CFG_LED_POLAR, 1); |
| 1408 | rt2800_register_write(rt2x00dev, LED_CFG, reg); |
| 1409 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1410 | rt2800_register_write(rt2x00dev, PBF_MAX_PCNT, 0x1f3fbf9f); |
| 1411 | |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1412 | rt2800_register_read(rt2x00dev, TX_RTY_CFG, ®); |
| 1413 | rt2x00_set_field32(®, TX_RTY_CFG_SHORT_RTY_LIMIT, 15); |
| 1414 | rt2x00_set_field32(®, TX_RTY_CFG_LONG_RTY_LIMIT, 31); |
| 1415 | rt2x00_set_field32(®, TX_RTY_CFG_LONG_RTY_THRE, 2000); |
| 1416 | rt2x00_set_field32(®, TX_RTY_CFG_NON_AGG_RTY_MODE, 0); |
| 1417 | rt2x00_set_field32(®, TX_RTY_CFG_AGG_RTY_MODE, 0); |
| 1418 | rt2x00_set_field32(®, TX_RTY_CFG_TX_AUTO_FB_ENABLE, 1); |
| 1419 | rt2800_register_write(rt2x00dev, TX_RTY_CFG, reg); |
| 1420 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1421 | rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, ®); |
| 1422 | rt2x00_set_field32(®, AUTO_RSP_CFG_AUTORESPONDER, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1423 | rt2x00_set_field32(®, AUTO_RSP_CFG_BAC_ACK_POLICY, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1424 | rt2x00_set_field32(®, AUTO_RSP_CFG_CTS_40_MMODE, 0); |
| 1425 | rt2x00_set_field32(®, AUTO_RSP_CFG_CTS_40_MREF, 0); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1426 | rt2x00_set_field32(®, AUTO_RSP_CFG_AR_PREAMBLE, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1427 | rt2x00_set_field32(®, AUTO_RSP_CFG_DUAL_CTS_EN, 0); |
| 1428 | rt2x00_set_field32(®, AUTO_RSP_CFG_ACK_CTS_PSM_BIT, 0); |
| 1429 | rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg); |
| 1430 | |
| 1431 | rt2800_register_read(rt2x00dev, CCK_PROT_CFG, ®); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1432 | rt2x00_set_field32(®, CCK_PROT_CFG_PROTECT_RATE, 3); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1433 | rt2x00_set_field32(®, CCK_PROT_CFG_PROTECT_CTRL, 0); |
| 1434 | rt2x00_set_field32(®, CCK_PROT_CFG_PROTECT_NAV, 1); |
| 1435 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 1436 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 1437 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1438 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_MM40, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1439 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1440 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_GF40, 0); |
| 1441 | rt2x00_set_field32(®, CCK_PROT_CFG_RTS_TH_EN, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1442 | rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg); |
| 1443 | |
| 1444 | rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, ®); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1445 | rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_RATE, 3); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1446 | rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_CTRL, 0); |
| 1447 | rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_NAV, 1); |
| 1448 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 1449 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 1450 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1451 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_MM40, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1452 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1453 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_GF40, 0); |
| 1454 | rt2x00_set_field32(®, OFDM_PROT_CFG_RTS_TH_EN, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1455 | rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg); |
| 1456 | |
| 1457 | rt2800_register_read(rt2x00dev, MM20_PROT_CFG, ®); |
| 1458 | rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_RATE, 0x4004); |
| 1459 | rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_CTRL, 0); |
| 1460 | rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_NAV, 1); |
| 1461 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 1462 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 1463 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
| 1464 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_MM40, 0); |
| 1465 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
| 1466 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_GF40, 0); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1467 | rt2x00_set_field32(®, MM20_PROT_CFG_RTS_TH_EN, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1468 | rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg); |
| 1469 | |
| 1470 | rt2800_register_read(rt2x00dev, MM40_PROT_CFG, ®); |
| 1471 | rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_RATE, 0x4084); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1472 | rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_CTRL, |
| 1473 | !rt2x00_is_usb(rt2x00dev)); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1474 | rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_NAV, 1); |
| 1475 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 1476 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 1477 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
| 1478 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_MM40, 1); |
| 1479 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
| 1480 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_GF40, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1481 | rt2x00_set_field32(®, MM40_PROT_CFG_RTS_TH_EN, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1482 | rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg); |
| 1483 | |
| 1484 | rt2800_register_read(rt2x00dev, GF20_PROT_CFG, ®); |
| 1485 | rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_RATE, 0x4004); |
| 1486 | rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_CTRL, 0); |
| 1487 | rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_NAV, 1); |
| 1488 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 1489 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 1490 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
| 1491 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_MM40, 0); |
| 1492 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
| 1493 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_GF40, 0); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1494 | rt2x00_set_field32(®, GF20_PROT_CFG_RTS_TH_EN, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1495 | rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg); |
| 1496 | |
| 1497 | rt2800_register_read(rt2x00dev, GF40_PROT_CFG, ®); |
| 1498 | rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_RATE, 0x4084); |
| 1499 | rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_CTRL, 0); |
| 1500 | rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_NAV, 1); |
| 1501 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 1502 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 1503 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
| 1504 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_MM40, 1); |
| 1505 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
| 1506 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_GF40, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1507 | rt2x00_set_field32(®, GF40_PROT_CFG_RTS_TH_EN, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1508 | rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg); |
| 1509 | |
Gertjan van Wingerde | cea90e5 | 2010-02-13 20:55:47 +0100 | [diff] [blame] | 1510 | if (rt2x00_is_usb(rt2x00dev)) { |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1511 | rt2800_register_write(rt2x00dev, PBF_CFG, 0xf40006); |
| 1512 | |
| 1513 | rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®); |
| 1514 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0); |
| 1515 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_DMA_BUSY, 0); |
| 1516 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0); |
| 1517 | rt2x00_set_field32(®, WPDMA_GLO_CFG_RX_DMA_BUSY, 0); |
| 1518 | rt2x00_set_field32(®, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 3); |
| 1519 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 0); |
| 1520 | rt2x00_set_field32(®, WPDMA_GLO_CFG_BIG_ENDIAN, 0); |
| 1521 | rt2x00_set_field32(®, WPDMA_GLO_CFG_RX_HDR_SCATTER, 0); |
| 1522 | rt2x00_set_field32(®, WPDMA_GLO_CFG_HDR_SEG_LEN, 0); |
| 1523 | rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg); |
| 1524 | } |
| 1525 | |
| 1526 | rt2800_register_write(rt2x00dev, TXOP_CTRL_CFG, 0x0000583f); |
| 1527 | rt2800_register_write(rt2x00dev, TXOP_HLDR_ET, 0x00000002); |
| 1528 | |
| 1529 | rt2800_register_read(rt2x00dev, TX_RTS_CFG, ®); |
| 1530 | rt2x00_set_field32(®, TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT, 32); |
| 1531 | rt2x00_set_field32(®, TX_RTS_CFG_RTS_THRES, |
| 1532 | IEEE80211_MAX_RTS_THRESHOLD); |
| 1533 | rt2x00_set_field32(®, TX_RTS_CFG_RTS_FBK_EN, 0); |
| 1534 | rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg); |
| 1535 | |
| 1536 | rt2800_register_write(rt2x00dev, EXP_ACK_TIME, 0x002400ca); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1537 | |
Helmut Schaa | a21c2ab | 2010-05-06 12:29:04 +0200 | [diff] [blame] | 1538 | /* |
| 1539 | * Usually the CCK SIFS time should be set to 10 and the OFDM SIFS |
| 1540 | * time should be set to 16. However, the original Ralink driver uses |
| 1541 | * 16 for both and indeed using a value of 10 for CCK SIFS results in |
| 1542 | * connection problems with 11g + CTS protection. Hence, use the same |
| 1543 | * defaults as the Ralink driver: 16 for both, CCK and OFDM SIFS. |
| 1544 | */ |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1545 | rt2800_register_read(rt2x00dev, XIFS_TIME_CFG, ®); |
Helmut Schaa | a21c2ab | 2010-05-06 12:29:04 +0200 | [diff] [blame] | 1546 | rt2x00_set_field32(®, XIFS_TIME_CFG_CCKM_SIFS_TIME, 16); |
| 1547 | rt2x00_set_field32(®, XIFS_TIME_CFG_OFDM_SIFS_TIME, 16); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1548 | rt2x00_set_field32(®, XIFS_TIME_CFG_OFDM_XIFS_TIME, 4); |
| 1549 | rt2x00_set_field32(®, XIFS_TIME_CFG_EIFS, 314); |
| 1550 | rt2x00_set_field32(®, XIFS_TIME_CFG_BB_RXEND_ENABLE, 1); |
| 1551 | rt2800_register_write(rt2x00dev, XIFS_TIME_CFG, reg); |
| 1552 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1553 | rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003); |
| 1554 | |
| 1555 | /* |
| 1556 | * ASIC will keep garbage value after boot, clear encryption keys. |
| 1557 | */ |
| 1558 | for (i = 0; i < 4; i++) |
| 1559 | rt2800_register_write(rt2x00dev, |
| 1560 | SHARED_KEY_MODE_ENTRY(i), 0); |
| 1561 | |
| 1562 | for (i = 0; i < 256; i++) { |
| 1563 | u32 wcid[2] = { 0xffffffff, 0x00ffffff }; |
| 1564 | rt2800_register_multiwrite(rt2x00dev, MAC_WCID_ENTRY(i), |
| 1565 | wcid, sizeof(wcid)); |
| 1566 | |
| 1567 | rt2800_register_write(rt2x00dev, MAC_WCID_ATTR_ENTRY(i), 1); |
| 1568 | rt2800_register_write(rt2x00dev, MAC_IVEIV_ENTRY(i), 0); |
| 1569 | } |
| 1570 | |
| 1571 | /* |
| 1572 | * Clear all beacons |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1573 | */ |
Helmut Schaa | fdb8725 | 2010-06-29 21:48:06 +0200 | [diff] [blame] | 1574 | rt2800_clear_beacon(rt2x00dev, HW_BEACON_BASE0); |
| 1575 | rt2800_clear_beacon(rt2x00dev, HW_BEACON_BASE1); |
| 1576 | rt2800_clear_beacon(rt2x00dev, HW_BEACON_BASE2); |
| 1577 | rt2800_clear_beacon(rt2x00dev, HW_BEACON_BASE3); |
| 1578 | rt2800_clear_beacon(rt2x00dev, HW_BEACON_BASE4); |
| 1579 | rt2800_clear_beacon(rt2x00dev, HW_BEACON_BASE5); |
| 1580 | rt2800_clear_beacon(rt2x00dev, HW_BEACON_BASE6); |
| 1581 | rt2800_clear_beacon(rt2x00dev, HW_BEACON_BASE7); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1582 | |
Gertjan van Wingerde | cea90e5 | 2010-02-13 20:55:47 +0100 | [diff] [blame] | 1583 | if (rt2x00_is_usb(rt2x00dev)) { |
Gertjan van Wingerde | 785c3c0 | 2010-06-03 10:51:59 +0200 | [diff] [blame] | 1584 | rt2800_register_read(rt2x00dev, US_CYC_CNT, ®); |
| 1585 | rt2x00_set_field32(®, US_CYC_CNT_CLOCK_CYCLE, 30); |
| 1586 | rt2800_register_write(rt2x00dev, US_CYC_CNT, reg); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | rt2800_register_read(rt2x00dev, HT_FBK_CFG0, ®); |
| 1590 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS0FBK, 0); |
| 1591 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS1FBK, 0); |
| 1592 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS2FBK, 1); |
| 1593 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS3FBK, 2); |
| 1594 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS4FBK, 3); |
| 1595 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS5FBK, 4); |
| 1596 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS6FBK, 5); |
| 1597 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS7FBK, 6); |
| 1598 | rt2800_register_write(rt2x00dev, HT_FBK_CFG0, reg); |
| 1599 | |
| 1600 | rt2800_register_read(rt2x00dev, HT_FBK_CFG1, ®); |
| 1601 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS8FBK, 8); |
| 1602 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS9FBK, 8); |
| 1603 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS10FBK, 9); |
| 1604 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS11FBK, 10); |
| 1605 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS12FBK, 11); |
| 1606 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS13FBK, 12); |
| 1607 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS14FBK, 13); |
| 1608 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS15FBK, 14); |
| 1609 | rt2800_register_write(rt2x00dev, HT_FBK_CFG1, reg); |
| 1610 | |
| 1611 | rt2800_register_read(rt2x00dev, LG_FBK_CFG0, ®); |
| 1612 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS0FBK, 8); |
| 1613 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS1FBK, 8); |
| 1614 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS2FBK, 9); |
| 1615 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS3FBK, 10); |
| 1616 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS4FBK, 11); |
| 1617 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS5FBK, 12); |
| 1618 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS6FBK, 13); |
| 1619 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS7FBK, 14); |
| 1620 | rt2800_register_write(rt2x00dev, LG_FBK_CFG0, reg); |
| 1621 | |
| 1622 | rt2800_register_read(rt2x00dev, LG_FBK_CFG1, ®); |
| 1623 | rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS0FBK, 0); |
| 1624 | rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS1FBK, 0); |
| 1625 | rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS2FBK, 1); |
| 1626 | rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS3FBK, 2); |
| 1627 | rt2800_register_write(rt2x00dev, LG_FBK_CFG1, reg); |
| 1628 | |
| 1629 | /* |
| 1630 | * We must clear the error counters. |
| 1631 | * These registers are cleared on read, |
| 1632 | * so we may pass a useless variable to store the value. |
| 1633 | */ |
| 1634 | rt2800_register_read(rt2x00dev, RX_STA_CNT0, ®); |
| 1635 | rt2800_register_read(rt2x00dev, RX_STA_CNT1, ®); |
| 1636 | rt2800_register_read(rt2x00dev, RX_STA_CNT2, ®); |
| 1637 | rt2800_register_read(rt2x00dev, TX_STA_CNT0, ®); |
| 1638 | rt2800_register_read(rt2x00dev, TX_STA_CNT1, ®); |
| 1639 | rt2800_register_read(rt2x00dev, TX_STA_CNT2, ®); |
| 1640 | |
| 1641 | return 0; |
| 1642 | } |
| 1643 | EXPORT_SYMBOL_GPL(rt2800_init_registers); |
| 1644 | |
| 1645 | static int rt2800_wait_bbp_rf_ready(struct rt2x00_dev *rt2x00dev) |
| 1646 | { |
| 1647 | unsigned int i; |
| 1648 | u32 reg; |
| 1649 | |
| 1650 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
| 1651 | rt2800_register_read(rt2x00dev, MAC_STATUS_CFG, ®); |
| 1652 | if (!rt2x00_get_field32(reg, MAC_STATUS_CFG_BBP_RF_BUSY)) |
| 1653 | return 0; |
| 1654 | |
| 1655 | udelay(REGISTER_BUSY_DELAY); |
| 1656 | } |
| 1657 | |
| 1658 | ERROR(rt2x00dev, "BBP/RF register access failed, aborting.\n"); |
| 1659 | return -EACCES; |
| 1660 | } |
| 1661 | |
| 1662 | static int rt2800_wait_bbp_ready(struct rt2x00_dev *rt2x00dev) |
| 1663 | { |
| 1664 | unsigned int i; |
| 1665 | u8 value; |
| 1666 | |
| 1667 | /* |
| 1668 | * BBP was enabled after firmware was loaded, |
| 1669 | * but we need to reactivate it now. |
| 1670 | */ |
| 1671 | rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0); |
| 1672 | rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0); |
| 1673 | msleep(1); |
| 1674 | |
| 1675 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
| 1676 | rt2800_bbp_read(rt2x00dev, 0, &value); |
| 1677 | if ((value != 0xff) && (value != 0x00)) |
| 1678 | return 0; |
| 1679 | udelay(REGISTER_BUSY_DELAY); |
| 1680 | } |
| 1681 | |
| 1682 | ERROR(rt2x00dev, "BBP register access failed, aborting.\n"); |
| 1683 | return -EACCES; |
| 1684 | } |
| 1685 | |
| 1686 | int rt2800_init_bbp(struct rt2x00_dev *rt2x00dev) |
| 1687 | { |
| 1688 | unsigned int i; |
| 1689 | u16 eeprom; |
| 1690 | u8 reg_id; |
| 1691 | u8 value; |
| 1692 | |
| 1693 | if (unlikely(rt2800_wait_bbp_rf_ready(rt2x00dev) || |
| 1694 | rt2800_wait_bbp_ready(rt2x00dev))) |
| 1695 | return -EACCES; |
| 1696 | |
Helmut Schaa | baff800 | 2010-04-28 09:58:59 +0200 | [diff] [blame] | 1697 | if (rt2800_is_305x_soc(rt2x00dev)) |
| 1698 | rt2800_bbp_write(rt2x00dev, 31, 0x08); |
| 1699 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1700 | rt2800_bbp_write(rt2x00dev, 65, 0x2c); |
| 1701 | rt2800_bbp_write(rt2x00dev, 66, 0x38); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1702 | |
| 1703 | if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) { |
| 1704 | rt2800_bbp_write(rt2x00dev, 69, 0x16); |
| 1705 | rt2800_bbp_write(rt2x00dev, 73, 0x12); |
| 1706 | } else { |
| 1707 | rt2800_bbp_write(rt2x00dev, 69, 0x12); |
| 1708 | rt2800_bbp_write(rt2x00dev, 73, 0x10); |
| 1709 | } |
| 1710 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1711 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 1712 | |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 1713 | if (rt2x00_rt(rt2x00dev, RT3070) || |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 1714 | rt2x00_rt(rt2x00dev, RT3071) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 1715 | rt2x00_rt(rt2x00dev, RT3090) || |
| 1716 | rt2x00_rt(rt2x00dev, RT3390)) { |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 1717 | rt2800_bbp_write(rt2x00dev, 79, 0x13); |
| 1718 | rt2800_bbp_write(rt2x00dev, 80, 0x05); |
| 1719 | rt2800_bbp_write(rt2x00dev, 81, 0x33); |
Helmut Schaa | baff800 | 2010-04-28 09:58:59 +0200 | [diff] [blame] | 1720 | } else if (rt2800_is_305x_soc(rt2x00dev)) { |
| 1721 | rt2800_bbp_write(rt2x00dev, 78, 0x0e); |
| 1722 | rt2800_bbp_write(rt2x00dev, 80, 0x08); |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 1723 | } else { |
| 1724 | rt2800_bbp_write(rt2x00dev, 81, 0x37); |
| 1725 | } |
| 1726 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1727 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
| 1728 | rt2800_bbp_write(rt2x00dev, 83, 0x6a); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1729 | |
Gertjan van Wingerde | 5ed8f45 | 2010-06-03 10:51:57 +0200 | [diff] [blame] | 1730 | if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860D)) |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1731 | rt2800_bbp_write(rt2x00dev, 84, 0x19); |
| 1732 | else |
| 1733 | rt2800_bbp_write(rt2x00dev, 84, 0x99); |
| 1734 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1735 | rt2800_bbp_write(rt2x00dev, 86, 0x00); |
| 1736 | rt2800_bbp_write(rt2x00dev, 91, 0x04); |
| 1737 | rt2800_bbp_write(rt2x00dev, 92, 0x00); |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 1738 | |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 1739 | if (rt2x00_rt_rev_gte(rt2x00dev, RT3070, REV_RT3070F) || |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 1740 | rt2x00_rt_rev_gte(rt2x00dev, RT3071, REV_RT3071E) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 1741 | rt2x00_rt_rev_gte(rt2x00dev, RT3090, REV_RT3090E) || |
Helmut Schaa | baff800 | 2010-04-28 09:58:59 +0200 | [diff] [blame] | 1742 | rt2x00_rt_rev_gte(rt2x00dev, RT3390, REV_RT3390E) || |
| 1743 | rt2800_is_305x_soc(rt2x00dev)) |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 1744 | rt2800_bbp_write(rt2x00dev, 103, 0xc0); |
| 1745 | else |
| 1746 | rt2800_bbp_write(rt2x00dev, 103, 0x00); |
| 1747 | |
Helmut Schaa | baff800 | 2010-04-28 09:58:59 +0200 | [diff] [blame] | 1748 | if (rt2800_is_305x_soc(rt2x00dev)) |
| 1749 | rt2800_bbp_write(rt2x00dev, 105, 0x01); |
| 1750 | else |
| 1751 | rt2800_bbp_write(rt2x00dev, 105, 0x05); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 1752 | rt2800_bbp_write(rt2x00dev, 106, 0x35); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1753 | |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 1754 | if (rt2x00_rt(rt2x00dev, RT3071) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 1755 | rt2x00_rt(rt2x00dev, RT3090) || |
| 1756 | rt2x00_rt(rt2x00dev, RT3390)) { |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 1757 | rt2800_bbp_read(rt2x00dev, 138, &value); |
| 1758 | |
| 1759 | rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom); |
| 1760 | if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH) == 1) |
| 1761 | value |= 0x20; |
| 1762 | if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH) == 1) |
| 1763 | value &= ~0x02; |
| 1764 | |
| 1765 | rt2800_bbp_write(rt2x00dev, 138, value); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1766 | } |
| 1767 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1768 | |
| 1769 | for (i = 0; i < EEPROM_BBP_SIZE; i++) { |
| 1770 | rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom); |
| 1771 | |
| 1772 | if (eeprom != 0xffff && eeprom != 0x0000) { |
| 1773 | reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID); |
| 1774 | value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE); |
| 1775 | rt2800_bbp_write(rt2x00dev, reg_id, value); |
| 1776 | } |
| 1777 | } |
| 1778 | |
| 1779 | return 0; |
| 1780 | } |
| 1781 | EXPORT_SYMBOL_GPL(rt2800_init_bbp); |
| 1782 | |
| 1783 | static u8 rt2800_init_rx_filter(struct rt2x00_dev *rt2x00dev, |
| 1784 | bool bw40, u8 rfcsr24, u8 filter_target) |
| 1785 | { |
| 1786 | unsigned int i; |
| 1787 | u8 bbp; |
| 1788 | u8 rfcsr; |
| 1789 | u8 passband; |
| 1790 | u8 stopband; |
| 1791 | u8 overtuned = 0; |
| 1792 | |
| 1793 | rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24); |
| 1794 | |
| 1795 | rt2800_bbp_read(rt2x00dev, 4, &bbp); |
| 1796 | rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * bw40); |
| 1797 | rt2800_bbp_write(rt2x00dev, 4, bbp); |
| 1798 | |
| 1799 | rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr); |
| 1800 | rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 1); |
| 1801 | rt2800_rfcsr_write(rt2x00dev, 22, rfcsr); |
| 1802 | |
| 1803 | /* |
| 1804 | * Set power & frequency of passband test tone |
| 1805 | */ |
| 1806 | rt2800_bbp_write(rt2x00dev, 24, 0); |
| 1807 | |
| 1808 | for (i = 0; i < 100; i++) { |
| 1809 | rt2800_bbp_write(rt2x00dev, 25, 0x90); |
| 1810 | msleep(1); |
| 1811 | |
| 1812 | rt2800_bbp_read(rt2x00dev, 55, &passband); |
| 1813 | if (passband) |
| 1814 | break; |
| 1815 | } |
| 1816 | |
| 1817 | /* |
| 1818 | * Set power & frequency of stopband test tone |
| 1819 | */ |
| 1820 | rt2800_bbp_write(rt2x00dev, 24, 0x06); |
| 1821 | |
| 1822 | for (i = 0; i < 100; i++) { |
| 1823 | rt2800_bbp_write(rt2x00dev, 25, 0x90); |
| 1824 | msleep(1); |
| 1825 | |
| 1826 | rt2800_bbp_read(rt2x00dev, 55, &stopband); |
| 1827 | |
| 1828 | if ((passband - stopband) <= filter_target) { |
| 1829 | rfcsr24++; |
| 1830 | overtuned += ((passband - stopband) == filter_target); |
| 1831 | } else |
| 1832 | break; |
| 1833 | |
| 1834 | rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24); |
| 1835 | } |
| 1836 | |
| 1837 | rfcsr24 -= !!overtuned; |
| 1838 | |
| 1839 | rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24); |
| 1840 | return rfcsr24; |
| 1841 | } |
| 1842 | |
| 1843 | int rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev) |
| 1844 | { |
| 1845 | u8 rfcsr; |
| 1846 | u8 bbp; |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 1847 | u32 reg; |
| 1848 | u16 eeprom; |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1849 | |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 1850 | if (!rt2x00_rt(rt2x00dev, RT3070) && |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 1851 | !rt2x00_rt(rt2x00dev, RT3071) && |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 1852 | !rt2x00_rt(rt2x00dev, RT3090) && |
Helmut Schaa | 2381238 | 2010-04-26 13:48:45 +0200 | [diff] [blame] | 1853 | !rt2x00_rt(rt2x00dev, RT3390) && |
Helmut Schaa | baff800 | 2010-04-28 09:58:59 +0200 | [diff] [blame] | 1854 | !rt2800_is_305x_soc(rt2x00dev)) |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1855 | return 0; |
| 1856 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1857 | /* |
| 1858 | * Init RF calibration. |
| 1859 | */ |
| 1860 | rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr); |
| 1861 | rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1); |
| 1862 | rt2800_rfcsr_write(rt2x00dev, 30, rfcsr); |
| 1863 | msleep(1); |
| 1864 | rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0); |
| 1865 | rt2800_rfcsr_write(rt2x00dev, 30, rfcsr); |
| 1866 | |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 1867 | if (rt2x00_rt(rt2x00dev, RT3070) || |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 1868 | rt2x00_rt(rt2x00dev, RT3071) || |
| 1869 | rt2x00_rt(rt2x00dev, RT3090)) { |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1870 | rt2800_rfcsr_write(rt2x00dev, 4, 0x40); |
| 1871 | rt2800_rfcsr_write(rt2x00dev, 5, 0x03); |
| 1872 | rt2800_rfcsr_write(rt2x00dev, 6, 0x02); |
| 1873 | rt2800_rfcsr_write(rt2x00dev, 7, 0x70); |
| 1874 | rt2800_rfcsr_write(rt2x00dev, 9, 0x0f); |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 1875 | rt2800_rfcsr_write(rt2x00dev, 10, 0x41); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1876 | rt2800_rfcsr_write(rt2x00dev, 11, 0x21); |
| 1877 | rt2800_rfcsr_write(rt2x00dev, 12, 0x7b); |
| 1878 | rt2800_rfcsr_write(rt2x00dev, 14, 0x90); |
| 1879 | rt2800_rfcsr_write(rt2x00dev, 15, 0x58); |
| 1880 | rt2800_rfcsr_write(rt2x00dev, 16, 0xb3); |
| 1881 | rt2800_rfcsr_write(rt2x00dev, 17, 0x92); |
| 1882 | rt2800_rfcsr_write(rt2x00dev, 18, 0x2c); |
| 1883 | rt2800_rfcsr_write(rt2x00dev, 19, 0x02); |
| 1884 | rt2800_rfcsr_write(rt2x00dev, 20, 0xba); |
| 1885 | rt2800_rfcsr_write(rt2x00dev, 21, 0xdb); |
| 1886 | rt2800_rfcsr_write(rt2x00dev, 24, 0x16); |
| 1887 | rt2800_rfcsr_write(rt2x00dev, 25, 0x01); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1888 | rt2800_rfcsr_write(rt2x00dev, 29, 0x1f); |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 1889 | } else if (rt2x00_rt(rt2x00dev, RT3390)) { |
| 1890 | rt2800_rfcsr_write(rt2x00dev, 0, 0xa0); |
| 1891 | rt2800_rfcsr_write(rt2x00dev, 1, 0xe1); |
| 1892 | rt2800_rfcsr_write(rt2x00dev, 2, 0xf1); |
| 1893 | rt2800_rfcsr_write(rt2x00dev, 3, 0x62); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1894 | rt2800_rfcsr_write(rt2x00dev, 4, 0x40); |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 1895 | rt2800_rfcsr_write(rt2x00dev, 5, 0x8b); |
| 1896 | rt2800_rfcsr_write(rt2x00dev, 6, 0x42); |
| 1897 | rt2800_rfcsr_write(rt2x00dev, 7, 0x34); |
| 1898 | rt2800_rfcsr_write(rt2x00dev, 8, 0x00); |
| 1899 | rt2800_rfcsr_write(rt2x00dev, 9, 0xc0); |
| 1900 | rt2800_rfcsr_write(rt2x00dev, 10, 0x61); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1901 | rt2800_rfcsr_write(rt2x00dev, 11, 0x21); |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 1902 | rt2800_rfcsr_write(rt2x00dev, 12, 0x3b); |
| 1903 | rt2800_rfcsr_write(rt2x00dev, 13, 0xe0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1904 | rt2800_rfcsr_write(rt2x00dev, 14, 0x90); |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 1905 | rt2800_rfcsr_write(rt2x00dev, 15, 0x53); |
| 1906 | rt2800_rfcsr_write(rt2x00dev, 16, 0xe0); |
| 1907 | rt2800_rfcsr_write(rt2x00dev, 17, 0x94); |
| 1908 | rt2800_rfcsr_write(rt2x00dev, 18, 0x5c); |
| 1909 | rt2800_rfcsr_write(rt2x00dev, 19, 0x4a); |
| 1910 | rt2800_rfcsr_write(rt2x00dev, 20, 0xb2); |
| 1911 | rt2800_rfcsr_write(rt2x00dev, 21, 0xf6); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1912 | rt2800_rfcsr_write(rt2x00dev, 22, 0x00); |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 1913 | rt2800_rfcsr_write(rt2x00dev, 23, 0x14); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1914 | rt2800_rfcsr_write(rt2x00dev, 24, 0x08); |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 1915 | rt2800_rfcsr_write(rt2x00dev, 25, 0x3d); |
| 1916 | rt2800_rfcsr_write(rt2x00dev, 26, 0x85); |
| 1917 | rt2800_rfcsr_write(rt2x00dev, 27, 0x00); |
| 1918 | rt2800_rfcsr_write(rt2x00dev, 28, 0x41); |
| 1919 | rt2800_rfcsr_write(rt2x00dev, 29, 0x8f); |
| 1920 | rt2800_rfcsr_write(rt2x00dev, 30, 0x20); |
| 1921 | rt2800_rfcsr_write(rt2x00dev, 31, 0x0f); |
Helmut Schaa | baff800 | 2010-04-28 09:58:59 +0200 | [diff] [blame] | 1922 | } else if (rt2800_is_305x_soc(rt2x00dev)) { |
Helmut Schaa | 2381238 | 2010-04-26 13:48:45 +0200 | [diff] [blame] | 1923 | rt2800_rfcsr_write(rt2x00dev, 0, 0x50); |
| 1924 | rt2800_rfcsr_write(rt2x00dev, 1, 0x01); |
| 1925 | rt2800_rfcsr_write(rt2x00dev, 2, 0xf7); |
| 1926 | rt2800_rfcsr_write(rt2x00dev, 3, 0x75); |
| 1927 | rt2800_rfcsr_write(rt2x00dev, 4, 0x40); |
| 1928 | rt2800_rfcsr_write(rt2x00dev, 5, 0x03); |
| 1929 | rt2800_rfcsr_write(rt2x00dev, 6, 0x02); |
| 1930 | rt2800_rfcsr_write(rt2x00dev, 7, 0x50); |
| 1931 | rt2800_rfcsr_write(rt2x00dev, 8, 0x39); |
| 1932 | rt2800_rfcsr_write(rt2x00dev, 9, 0x0f); |
| 1933 | rt2800_rfcsr_write(rt2x00dev, 10, 0x60); |
| 1934 | rt2800_rfcsr_write(rt2x00dev, 11, 0x21); |
| 1935 | rt2800_rfcsr_write(rt2x00dev, 12, 0x75); |
| 1936 | rt2800_rfcsr_write(rt2x00dev, 13, 0x75); |
| 1937 | rt2800_rfcsr_write(rt2x00dev, 14, 0x90); |
| 1938 | rt2800_rfcsr_write(rt2x00dev, 15, 0x58); |
| 1939 | rt2800_rfcsr_write(rt2x00dev, 16, 0xb3); |
| 1940 | rt2800_rfcsr_write(rt2x00dev, 17, 0x92); |
| 1941 | rt2800_rfcsr_write(rt2x00dev, 18, 0x2c); |
| 1942 | rt2800_rfcsr_write(rt2x00dev, 19, 0x02); |
| 1943 | rt2800_rfcsr_write(rt2x00dev, 20, 0xba); |
| 1944 | rt2800_rfcsr_write(rt2x00dev, 21, 0xdb); |
| 1945 | rt2800_rfcsr_write(rt2x00dev, 22, 0x00); |
| 1946 | rt2800_rfcsr_write(rt2x00dev, 23, 0x31); |
| 1947 | rt2800_rfcsr_write(rt2x00dev, 24, 0x08); |
| 1948 | rt2800_rfcsr_write(rt2x00dev, 25, 0x01); |
| 1949 | rt2800_rfcsr_write(rt2x00dev, 26, 0x25); |
| 1950 | rt2800_rfcsr_write(rt2x00dev, 27, 0x23); |
| 1951 | rt2800_rfcsr_write(rt2x00dev, 28, 0x13); |
| 1952 | rt2800_rfcsr_write(rt2x00dev, 29, 0x83); |
Helmut Schaa | baff800 | 2010-04-28 09:58:59 +0200 | [diff] [blame] | 1953 | rt2800_rfcsr_write(rt2x00dev, 30, 0x00); |
| 1954 | rt2800_rfcsr_write(rt2x00dev, 31, 0x00); |
| 1955 | return 0; |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) { |
| 1959 | rt2800_register_read(rt2x00dev, LDO_CFG0, ®); |
| 1960 | rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1); |
| 1961 | rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 3); |
| 1962 | rt2800_register_write(rt2x00dev, LDO_CFG0, reg); |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 1963 | } else if (rt2x00_rt(rt2x00dev, RT3071) || |
| 1964 | rt2x00_rt(rt2x00dev, RT3090)) { |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 1965 | rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr); |
| 1966 | rt2x00_set_field8(&rfcsr, RFCSR6_R2, 1); |
| 1967 | rt2800_rfcsr_write(rt2x00dev, 6, rfcsr); |
| 1968 | |
| 1969 | rt2800_rfcsr_write(rt2x00dev, 31, 0x14); |
| 1970 | |
| 1971 | rt2800_register_read(rt2x00dev, LDO_CFG0, ®); |
| 1972 | rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1); |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 1973 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) || |
| 1974 | rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E)) { |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 1975 | rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom); |
| 1976 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_DAC_TEST)) |
| 1977 | rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 3); |
| 1978 | else |
| 1979 | rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 0); |
| 1980 | } |
| 1981 | rt2800_register_write(rt2x00dev, LDO_CFG0, reg); |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 1982 | } else if (rt2x00_rt(rt2x00dev, RT3390)) { |
| 1983 | rt2800_register_read(rt2x00dev, GPIO_SWITCH, ®); |
| 1984 | rt2x00_set_field32(®, GPIO_SWITCH_5, 0); |
| 1985 | rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 1986 | } |
| 1987 | |
| 1988 | /* |
| 1989 | * Set RX Filter calibration for 20MHz and 40MHz |
| 1990 | */ |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 1991 | if (rt2x00_rt(rt2x00dev, RT3070)) { |
| 1992 | rt2x00dev->calibration[0] = |
| 1993 | rt2800_init_rx_filter(rt2x00dev, false, 0x07, 0x16); |
| 1994 | rt2x00dev->calibration[1] = |
| 1995 | rt2800_init_rx_filter(rt2x00dev, true, 0x27, 0x19); |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 1996 | } else if (rt2x00_rt(rt2x00dev, RT3071) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 1997 | rt2x00_rt(rt2x00dev, RT3090) || |
| 1998 | rt2x00_rt(rt2x00dev, RT3390)) { |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 1999 | rt2x00dev->calibration[0] = |
| 2000 | rt2800_init_rx_filter(rt2x00dev, false, 0x07, 0x13); |
| 2001 | rt2x00dev->calibration[1] = |
| 2002 | rt2800_init_rx_filter(rt2x00dev, true, 0x27, 0x15); |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 2003 | } |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2004 | |
| 2005 | /* |
| 2006 | * Set back to initial state |
| 2007 | */ |
| 2008 | rt2800_bbp_write(rt2x00dev, 24, 0); |
| 2009 | |
| 2010 | rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr); |
| 2011 | rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 0); |
| 2012 | rt2800_rfcsr_write(rt2x00dev, 22, rfcsr); |
| 2013 | |
| 2014 | /* |
| 2015 | * set BBP back to BW20 |
| 2016 | */ |
| 2017 | rt2800_bbp_read(rt2x00dev, 4, &bbp); |
| 2018 | rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0); |
| 2019 | rt2800_bbp_write(rt2x00dev, 4, bbp); |
| 2020 | |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 2021 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F) || |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 2022 | rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 2023 | rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E) || |
| 2024 | rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 2025 | rt2800_rfcsr_write(rt2x00dev, 27, 0x03); |
| 2026 | |
| 2027 | rt2800_register_read(rt2x00dev, OPT_14_CSR, ®); |
| 2028 | rt2x00_set_field32(®, OPT_14_CSR_BIT0, 1); |
| 2029 | rt2800_register_write(rt2x00dev, OPT_14_CSR, reg); |
| 2030 | |
| 2031 | rt2800_rfcsr_read(rt2x00dev, 17, &rfcsr); |
| 2032 | rt2x00_set_field8(&rfcsr, RFCSR17_TX_LO1_EN, 0); |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 2033 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 2034 | rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E) || |
| 2035 | rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) { |
Gertjan van Wingerde | 8440c29 | 2010-06-03 10:52:02 +0200 | [diff] [blame] | 2036 | if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags)) |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 2037 | rt2x00_set_field8(&rfcsr, RFCSR17_R, 1); |
| 2038 | } |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 2039 | rt2x00_eeprom_read(rt2x00dev, EEPROM_TXMIXER_GAIN_BG, &eeprom); |
| 2040 | if (rt2x00_get_field16(eeprom, EEPROM_TXMIXER_GAIN_BG_VAL) >= 1) |
| 2041 | rt2x00_set_field8(&rfcsr, RFCSR17_TXMIXER_GAIN, |
| 2042 | rt2x00_get_field16(eeprom, |
| 2043 | EEPROM_TXMIXER_GAIN_BG_VAL)); |
| 2044 | rt2800_rfcsr_write(rt2x00dev, 17, rfcsr); |
| 2045 | |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 2046 | if (rt2x00_rt(rt2x00dev, RT3090)) { |
| 2047 | rt2800_bbp_read(rt2x00dev, 138, &bbp); |
| 2048 | |
| 2049 | rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom); |
| 2050 | if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH) == 1) |
| 2051 | rt2x00_set_field8(&bbp, BBP138_RX_ADC1, 0); |
| 2052 | if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH) == 1) |
| 2053 | rt2x00_set_field8(&bbp, BBP138_TX_DAC1, 1); |
| 2054 | |
| 2055 | rt2800_bbp_write(rt2x00dev, 138, bbp); |
| 2056 | } |
| 2057 | |
| 2058 | if (rt2x00_rt(rt2x00dev, RT3071) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 2059 | rt2x00_rt(rt2x00dev, RT3090) || |
| 2060 | rt2x00_rt(rt2x00dev, RT3390)) { |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 2061 | rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr); |
| 2062 | rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1); |
| 2063 | rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0); |
| 2064 | rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0); |
| 2065 | rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1); |
| 2066 | rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1); |
| 2067 | rt2800_rfcsr_write(rt2x00dev, 1, rfcsr); |
| 2068 | |
| 2069 | rt2800_rfcsr_read(rt2x00dev, 15, &rfcsr); |
| 2070 | rt2x00_set_field8(&rfcsr, RFCSR15_TX_LO2_EN, 0); |
| 2071 | rt2800_rfcsr_write(rt2x00dev, 15, rfcsr); |
| 2072 | |
| 2073 | rt2800_rfcsr_read(rt2x00dev, 20, &rfcsr); |
| 2074 | rt2x00_set_field8(&rfcsr, RFCSR20_RX_LO1_EN, 0); |
| 2075 | rt2800_rfcsr_write(rt2x00dev, 20, rfcsr); |
| 2076 | |
| 2077 | rt2800_rfcsr_read(rt2x00dev, 21, &rfcsr); |
| 2078 | rt2x00_set_field8(&rfcsr, RFCSR21_RX_LO2_EN, 0); |
| 2079 | rt2800_rfcsr_write(rt2x00dev, 21, rfcsr); |
| 2080 | } |
| 2081 | |
| 2082 | if (rt2x00_rt(rt2x00dev, RT3070) || rt2x00_rt(rt2x00dev, RT3071)) { |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 2083 | rt2800_rfcsr_read(rt2x00dev, 27, &rfcsr); |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 2084 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F) || |
| 2085 | rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E)) |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 2086 | rt2x00_set_field8(&rfcsr, RFCSR27_R1, 3); |
| 2087 | else |
| 2088 | rt2x00_set_field8(&rfcsr, RFCSR27_R1, 0); |
| 2089 | rt2x00_set_field8(&rfcsr, RFCSR27_R2, 0); |
| 2090 | rt2x00_set_field8(&rfcsr, RFCSR27_R3, 0); |
| 2091 | rt2x00_set_field8(&rfcsr, RFCSR27_R4, 0); |
| 2092 | rt2800_rfcsr_write(rt2x00dev, 27, rfcsr); |
| 2093 | } |
| 2094 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 2095 | return 0; |
| 2096 | } |
| 2097 | EXPORT_SYMBOL_GPL(rt2800_init_rfcsr); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 2098 | |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 2099 | int rt2800_efuse_detect(struct rt2x00_dev *rt2x00dev) |
| 2100 | { |
| 2101 | u32 reg; |
| 2102 | |
| 2103 | rt2800_register_read(rt2x00dev, EFUSE_CTRL, ®); |
| 2104 | |
| 2105 | return rt2x00_get_field32(reg, EFUSE_CTRL_PRESENT); |
| 2106 | } |
| 2107 | EXPORT_SYMBOL_GPL(rt2800_efuse_detect); |
| 2108 | |
| 2109 | static void rt2800_efuse_read(struct rt2x00_dev *rt2x00dev, unsigned int i) |
| 2110 | { |
| 2111 | u32 reg; |
| 2112 | |
Gertjan van Wingerde | 31a4cf1 | 2009-11-14 20:20:36 +0100 | [diff] [blame] | 2113 | mutex_lock(&rt2x00dev->csr_mutex); |
| 2114 | |
| 2115 | rt2800_register_read_lock(rt2x00dev, EFUSE_CTRL, ®); |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 2116 | rt2x00_set_field32(®, EFUSE_CTRL_ADDRESS_IN, i); |
| 2117 | rt2x00_set_field32(®, EFUSE_CTRL_MODE, 0); |
| 2118 | rt2x00_set_field32(®, EFUSE_CTRL_KICK, 1); |
Gertjan van Wingerde | 31a4cf1 | 2009-11-14 20:20:36 +0100 | [diff] [blame] | 2119 | rt2800_register_write_lock(rt2x00dev, EFUSE_CTRL, reg); |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 2120 | |
| 2121 | /* Wait until the EEPROM has been loaded */ |
| 2122 | rt2800_regbusy_read(rt2x00dev, EFUSE_CTRL, EFUSE_CTRL_KICK, ®); |
| 2123 | |
| 2124 | /* Apparently the data is read from end to start */ |
Gertjan van Wingerde | 31a4cf1 | 2009-11-14 20:20:36 +0100 | [diff] [blame] | 2125 | rt2800_register_read_lock(rt2x00dev, EFUSE_DATA3, |
| 2126 | (u32 *)&rt2x00dev->eeprom[i]); |
| 2127 | rt2800_register_read_lock(rt2x00dev, EFUSE_DATA2, |
| 2128 | (u32 *)&rt2x00dev->eeprom[i + 2]); |
| 2129 | rt2800_register_read_lock(rt2x00dev, EFUSE_DATA1, |
| 2130 | (u32 *)&rt2x00dev->eeprom[i + 4]); |
| 2131 | rt2800_register_read_lock(rt2x00dev, EFUSE_DATA0, |
| 2132 | (u32 *)&rt2x00dev->eeprom[i + 6]); |
| 2133 | |
| 2134 | mutex_unlock(&rt2x00dev->csr_mutex); |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | void rt2800_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev) |
| 2138 | { |
| 2139 | unsigned int i; |
| 2140 | |
| 2141 | for (i = 0; i < EEPROM_SIZE / sizeof(u16); i += 8) |
| 2142 | rt2800_efuse_read(rt2x00dev, i); |
| 2143 | } |
| 2144 | EXPORT_SYMBOL_GPL(rt2800_read_eeprom_efuse); |
| 2145 | |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 2146 | int rt2800_validate_eeprom(struct rt2x00_dev *rt2x00dev) |
| 2147 | { |
| 2148 | u16 word; |
| 2149 | u8 *mac; |
| 2150 | u8 default_lna_gain; |
| 2151 | |
| 2152 | /* |
| 2153 | * Start validation of the data that has been read. |
| 2154 | */ |
| 2155 | mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0); |
| 2156 | if (!is_valid_ether_addr(mac)) { |
| 2157 | random_ether_addr(mac); |
| 2158 | EEPROM(rt2x00dev, "MAC: %pM\n", mac); |
| 2159 | } |
| 2160 | |
| 2161 | rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word); |
| 2162 | if (word == 0xffff) { |
| 2163 | rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2); |
| 2164 | rt2x00_set_field16(&word, EEPROM_ANTENNA_TXPATH, 1); |
| 2165 | rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF2820); |
| 2166 | rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word); |
| 2167 | EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word); |
Gertjan van Wingerde | 49e721e | 2010-02-13 20:55:49 +0100 | [diff] [blame] | 2168 | } else if (rt2x00_rt(rt2x00dev, RT2860) || |
Gertjan van Wingerde | e148b4c | 2010-04-11 14:31:09 +0200 | [diff] [blame] | 2169 | rt2x00_rt(rt2x00dev, RT2872)) { |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 2170 | /* |
| 2171 | * There is a max of 2 RX streams for RT28x0 series |
| 2172 | */ |
| 2173 | if (rt2x00_get_field16(word, EEPROM_ANTENNA_RXPATH) > 2) |
| 2174 | rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2); |
| 2175 | rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word); |
| 2176 | } |
| 2177 | |
| 2178 | rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word); |
| 2179 | if (word == 0xffff) { |
| 2180 | rt2x00_set_field16(&word, EEPROM_NIC_HW_RADIO, 0); |
| 2181 | rt2x00_set_field16(&word, EEPROM_NIC_DYNAMIC_TX_AGC, 0); |
| 2182 | rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_BG, 0); |
| 2183 | rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_A, 0); |
| 2184 | rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0); |
| 2185 | rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_BG, 0); |
| 2186 | rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_A, 0); |
| 2187 | rt2x00_set_field16(&word, EEPROM_NIC_WPS_PBC, 0); |
| 2188 | rt2x00_set_field16(&word, EEPROM_NIC_BW40M_BG, 0); |
| 2189 | rt2x00_set_field16(&word, EEPROM_NIC_BW40M_A, 0); |
Gertjan van Wingerde | ec2d179 | 2010-06-29 21:44:50 +0200 | [diff] [blame] | 2190 | rt2x00_set_field16(&word, EEPROM_NIC_ANT_DIVERSITY, 0); |
| 2191 | rt2x00_set_field16(&word, EEPROM_NIC_DAC_TEST, 0); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 2192 | rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word); |
| 2193 | EEPROM(rt2x00dev, "NIC: 0x%04x\n", word); |
| 2194 | } |
| 2195 | |
| 2196 | rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &word); |
| 2197 | if ((word & 0x00ff) == 0x00ff) { |
| 2198 | rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0); |
Gertjan van Wingerde | ec2d179 | 2010-06-29 21:44:50 +0200 | [diff] [blame] | 2199 | rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word); |
| 2200 | EEPROM(rt2x00dev, "Freq: 0x%04x\n", word); |
| 2201 | } |
| 2202 | if ((word & 0xff00) == 0xff00) { |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 2203 | rt2x00_set_field16(&word, EEPROM_FREQ_LED_MODE, |
| 2204 | LED_MODE_TXRX_ACTIVITY); |
| 2205 | rt2x00_set_field16(&word, EEPROM_FREQ_LED_POLARITY, 0); |
| 2206 | rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word); |
| 2207 | rt2x00_eeprom_write(rt2x00dev, EEPROM_LED1, 0x5555); |
| 2208 | rt2x00_eeprom_write(rt2x00dev, EEPROM_LED2, 0x2221); |
| 2209 | rt2x00_eeprom_write(rt2x00dev, EEPROM_LED3, 0xa9f8); |
Gertjan van Wingerde | ec2d179 | 2010-06-29 21:44:50 +0200 | [diff] [blame] | 2210 | EEPROM(rt2x00dev, "Led Mode: 0x%04x\n", word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 2211 | } |
| 2212 | |
| 2213 | /* |
| 2214 | * During the LNA validation we are going to use |
| 2215 | * lna0 as correct value. Note that EEPROM_LNA |
| 2216 | * is never validated. |
| 2217 | */ |
| 2218 | rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &word); |
| 2219 | default_lna_gain = rt2x00_get_field16(word, EEPROM_LNA_A0); |
| 2220 | |
| 2221 | rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &word); |
| 2222 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET0)) > 10) |
| 2223 | rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET0, 0); |
| 2224 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET1)) > 10) |
| 2225 | rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET1, 0); |
| 2226 | rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG, word); |
| 2227 | |
| 2228 | rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &word); |
| 2229 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG2_OFFSET2)) > 10) |
| 2230 | rt2x00_set_field16(&word, EEPROM_RSSI_BG2_OFFSET2, 0); |
| 2231 | if (rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0x00 || |
| 2232 | rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0xff) |
| 2233 | rt2x00_set_field16(&word, EEPROM_RSSI_BG2_LNA_A1, |
| 2234 | default_lna_gain); |
| 2235 | rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG2, word); |
| 2236 | |
| 2237 | rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &word); |
| 2238 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET0)) > 10) |
| 2239 | rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET0, 0); |
| 2240 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET1)) > 10) |
| 2241 | rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET1, 0); |
| 2242 | rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A, word); |
| 2243 | |
| 2244 | rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &word); |
| 2245 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A2_OFFSET2)) > 10) |
| 2246 | rt2x00_set_field16(&word, EEPROM_RSSI_A2_OFFSET2, 0); |
| 2247 | if (rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0x00 || |
| 2248 | rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0xff) |
| 2249 | rt2x00_set_field16(&word, EEPROM_RSSI_A2_LNA_A2, |
| 2250 | default_lna_gain); |
| 2251 | rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A2, word); |
| 2252 | |
| 2253 | return 0; |
| 2254 | } |
| 2255 | EXPORT_SYMBOL_GPL(rt2800_validate_eeprom); |
| 2256 | |
| 2257 | int rt2800_init_eeprom(struct rt2x00_dev *rt2x00dev) |
| 2258 | { |
| 2259 | u32 reg; |
| 2260 | u16 value; |
| 2261 | u16 eeprom; |
| 2262 | |
| 2263 | /* |
| 2264 | * Read EEPROM word for configuration. |
| 2265 | */ |
| 2266 | rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom); |
| 2267 | |
| 2268 | /* |
| 2269 | * Identify RF chipset. |
| 2270 | */ |
| 2271 | value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE); |
| 2272 | rt2800_register_read(rt2x00dev, MAC_CSR0, ®); |
| 2273 | |
Gertjan van Wingerde | 49e721e | 2010-02-13 20:55:49 +0100 | [diff] [blame] | 2274 | rt2x00_set_chip(rt2x00dev, rt2x00_get_field32(reg, MAC_CSR0_CHIPSET), |
| 2275 | value, rt2x00_get_field32(reg, MAC_CSR0_REVISION)); |
Gertjan van Wingerde | 714fa663 | 2010-02-13 20:55:48 +0100 | [diff] [blame] | 2276 | |
Gertjan van Wingerde | 49e721e | 2010-02-13 20:55:49 +0100 | [diff] [blame] | 2277 | if (!rt2x00_rt(rt2x00dev, RT2860) && |
Gertjan van Wingerde | 49e721e | 2010-02-13 20:55:49 +0100 | [diff] [blame] | 2278 | !rt2x00_rt(rt2x00dev, RT2872) && |
Gertjan van Wingerde | 49e721e | 2010-02-13 20:55:49 +0100 | [diff] [blame] | 2279 | !rt2x00_rt(rt2x00dev, RT2883) && |
Gertjan van Wingerde | 49e721e | 2010-02-13 20:55:49 +0100 | [diff] [blame] | 2280 | !rt2x00_rt(rt2x00dev, RT3070) && |
| 2281 | !rt2x00_rt(rt2x00dev, RT3071) && |
| 2282 | !rt2x00_rt(rt2x00dev, RT3090) && |
| 2283 | !rt2x00_rt(rt2x00dev, RT3390) && |
| 2284 | !rt2x00_rt(rt2x00dev, RT3572)) { |
| 2285 | ERROR(rt2x00dev, "Invalid RT chipset detected.\n"); |
| 2286 | return -ENODEV; |
| 2287 | } |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 2288 | |
Gertjan van Wingerde | 5122d89 | 2009-12-23 00:03:25 +0100 | [diff] [blame] | 2289 | if (!rt2x00_rf(rt2x00dev, RF2820) && |
| 2290 | !rt2x00_rf(rt2x00dev, RF2850) && |
| 2291 | !rt2x00_rf(rt2x00dev, RF2720) && |
| 2292 | !rt2x00_rf(rt2x00dev, RF2750) && |
| 2293 | !rt2x00_rf(rt2x00dev, RF3020) && |
| 2294 | !rt2x00_rf(rt2x00dev, RF2020) && |
| 2295 | !rt2x00_rf(rt2x00dev, RF3021) && |
Gertjan van Wingerde | 6c0fe26 | 2009-12-30 11:36:31 +0100 | [diff] [blame] | 2296 | !rt2x00_rf(rt2x00dev, RF3022) && |
| 2297 | !rt2x00_rf(rt2x00dev, RF3052)) { |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 2298 | ERROR(rt2x00dev, "Invalid RF chipset detected.\n"); |
| 2299 | return -ENODEV; |
| 2300 | } |
| 2301 | |
| 2302 | /* |
| 2303 | * Identify default antenna configuration. |
| 2304 | */ |
| 2305 | rt2x00dev->default_ant.tx = |
| 2306 | rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH); |
| 2307 | rt2x00dev->default_ant.rx = |
| 2308 | rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH); |
| 2309 | |
| 2310 | /* |
| 2311 | * Read frequency offset and RF programming sequence. |
| 2312 | */ |
| 2313 | rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom); |
| 2314 | rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET); |
| 2315 | |
| 2316 | /* |
| 2317 | * Read external LNA informations. |
| 2318 | */ |
| 2319 | rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom); |
| 2320 | |
| 2321 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_A)) |
| 2322 | __set_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags); |
| 2323 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_BG)) |
| 2324 | __set_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags); |
| 2325 | |
| 2326 | /* |
| 2327 | * Detect if this device has an hardware controlled radio. |
| 2328 | */ |
| 2329 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_HW_RADIO)) |
| 2330 | __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags); |
| 2331 | |
| 2332 | /* |
| 2333 | * Store led settings, for correct led behaviour. |
| 2334 | */ |
| 2335 | #ifdef CONFIG_RT2X00_LIB_LEDS |
| 2336 | rt2800_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO); |
| 2337 | rt2800_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC); |
| 2338 | rt2800_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY); |
| 2339 | |
| 2340 | rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &rt2x00dev->led_mcu_reg); |
| 2341 | #endif /* CONFIG_RT2X00_LIB_LEDS */ |
| 2342 | |
| 2343 | return 0; |
| 2344 | } |
| 2345 | EXPORT_SYMBOL_GPL(rt2800_init_eeprom); |
| 2346 | |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 2347 | /* |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 2348 | * RF value list for rt28xx |
Bartlomiej Zolnierkiewicz | 4da2933f | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 2349 | * Supports: 2.4 GHz (all) & 5.2 GHz (RF2850 & RF2750) |
| 2350 | */ |
| 2351 | static const struct rf_channel rf_vals[] = { |
| 2352 | { 1, 0x18402ecc, 0x184c0786, 0x1816b455, 0x1800510b }, |
| 2353 | { 2, 0x18402ecc, 0x184c0786, 0x18168a55, 0x1800519f }, |
| 2354 | { 3, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800518b }, |
| 2355 | { 4, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800519f }, |
| 2356 | { 5, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800518b }, |
| 2357 | { 6, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800519f }, |
| 2358 | { 7, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800518b }, |
| 2359 | { 8, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800519f }, |
| 2360 | { 9, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800518b }, |
| 2361 | { 10, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800519f }, |
| 2362 | { 11, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800518b }, |
| 2363 | { 12, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800519f }, |
| 2364 | { 13, 0x18402ecc, 0x184c079e, 0x18168a55, 0x1800518b }, |
| 2365 | { 14, 0x18402ecc, 0x184c07a2, 0x18168a55, 0x18005193 }, |
| 2366 | |
| 2367 | /* 802.11 UNI / HyperLan 2 */ |
| 2368 | { 36, 0x18402ecc, 0x184c099a, 0x18158a55, 0x180ed1a3 }, |
| 2369 | { 38, 0x18402ecc, 0x184c099e, 0x18158a55, 0x180ed193 }, |
| 2370 | { 40, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed183 }, |
| 2371 | { 44, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed1a3 }, |
| 2372 | { 46, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed18b }, |
| 2373 | { 48, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed19b }, |
| 2374 | { 52, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed193 }, |
| 2375 | { 54, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed1a3 }, |
| 2376 | { 56, 0x18402ec8, 0x184c068e, 0x18158a55, 0x180ed18b }, |
| 2377 | { 60, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed183 }, |
| 2378 | { 62, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed193 }, |
| 2379 | { 64, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed1a3 }, |
| 2380 | |
| 2381 | /* 802.11 HyperLan 2 */ |
| 2382 | { 100, 0x18402ec8, 0x184c06b2, 0x18178a55, 0x180ed783 }, |
| 2383 | { 102, 0x18402ec8, 0x184c06b2, 0x18578a55, 0x180ed793 }, |
| 2384 | { 104, 0x18402ec8, 0x185c06b2, 0x18578a55, 0x180ed1a3 }, |
| 2385 | { 108, 0x18402ecc, 0x185c0a32, 0x18578a55, 0x180ed193 }, |
| 2386 | { 110, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed183 }, |
| 2387 | { 112, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed19b }, |
| 2388 | { 116, 0x18402ecc, 0x184c0a3a, 0x18178a55, 0x180ed1a3 }, |
| 2389 | { 118, 0x18402ecc, 0x184c0a3e, 0x18178a55, 0x180ed193 }, |
| 2390 | { 120, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed183 }, |
| 2391 | { 124, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed193 }, |
| 2392 | { 126, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed15b }, |
| 2393 | { 128, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed1a3 }, |
| 2394 | { 132, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed18b }, |
| 2395 | { 134, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed193 }, |
| 2396 | { 136, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed19b }, |
| 2397 | { 140, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed183 }, |
| 2398 | |
| 2399 | /* 802.11 UNII */ |
| 2400 | { 149, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed1a7 }, |
| 2401 | { 151, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed187 }, |
| 2402 | { 153, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed18f }, |
| 2403 | { 157, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed19f }, |
| 2404 | { 159, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed1a7 }, |
| 2405 | { 161, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed187 }, |
| 2406 | { 165, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed197 }, |
| 2407 | { 167, 0x18402ec4, 0x184c03d2, 0x18179855, 0x1815531f }, |
| 2408 | { 169, 0x18402ec4, 0x184c03d2, 0x18179855, 0x18155327 }, |
| 2409 | { 171, 0x18402ec4, 0x184c03d6, 0x18179855, 0x18155307 }, |
| 2410 | { 173, 0x18402ec4, 0x184c03d6, 0x18179855, 0x1815530f }, |
| 2411 | |
| 2412 | /* 802.11 Japan */ |
| 2413 | { 184, 0x15002ccc, 0x1500491e, 0x1509be55, 0x150c0a0b }, |
| 2414 | { 188, 0x15002ccc, 0x15004922, 0x1509be55, 0x150c0a13 }, |
| 2415 | { 192, 0x15002ccc, 0x15004926, 0x1509be55, 0x150c0a1b }, |
| 2416 | { 196, 0x15002ccc, 0x1500492a, 0x1509be55, 0x150c0a23 }, |
| 2417 | { 208, 0x15002ccc, 0x1500493a, 0x1509be55, 0x150c0a13 }, |
| 2418 | { 212, 0x15002ccc, 0x1500493e, 0x1509be55, 0x150c0a1b }, |
| 2419 | { 216, 0x15002ccc, 0x15004982, 0x1509be55, 0x150c0a23 }, |
| 2420 | }; |
| 2421 | |
| 2422 | /* |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 2423 | * RF value list for rt3xxx |
| 2424 | * Supports: 2.4 GHz (all) & 5.2 GHz (RF3052) |
Bartlomiej Zolnierkiewicz | 4da2933f | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 2425 | */ |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 2426 | static const struct rf_channel rf_vals_3x[] = { |
Bartlomiej Zolnierkiewicz | 4da2933f | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 2427 | {1, 241, 2, 2 }, |
| 2428 | {2, 241, 2, 7 }, |
| 2429 | {3, 242, 2, 2 }, |
| 2430 | {4, 242, 2, 7 }, |
| 2431 | {5, 243, 2, 2 }, |
| 2432 | {6, 243, 2, 7 }, |
| 2433 | {7, 244, 2, 2 }, |
| 2434 | {8, 244, 2, 7 }, |
| 2435 | {9, 245, 2, 2 }, |
| 2436 | {10, 245, 2, 7 }, |
| 2437 | {11, 246, 2, 2 }, |
| 2438 | {12, 246, 2, 7 }, |
| 2439 | {13, 247, 2, 2 }, |
| 2440 | {14, 248, 2, 4 }, |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 2441 | |
| 2442 | /* 802.11 UNI / HyperLan 2 */ |
| 2443 | {36, 0x56, 0, 4}, |
| 2444 | {38, 0x56, 0, 6}, |
| 2445 | {40, 0x56, 0, 8}, |
| 2446 | {44, 0x57, 0, 0}, |
| 2447 | {46, 0x57, 0, 2}, |
| 2448 | {48, 0x57, 0, 4}, |
| 2449 | {52, 0x57, 0, 8}, |
| 2450 | {54, 0x57, 0, 10}, |
| 2451 | {56, 0x58, 0, 0}, |
| 2452 | {60, 0x58, 0, 4}, |
| 2453 | {62, 0x58, 0, 6}, |
| 2454 | {64, 0x58, 0, 8}, |
| 2455 | |
| 2456 | /* 802.11 HyperLan 2 */ |
| 2457 | {100, 0x5b, 0, 8}, |
| 2458 | {102, 0x5b, 0, 10}, |
| 2459 | {104, 0x5c, 0, 0}, |
| 2460 | {108, 0x5c, 0, 4}, |
| 2461 | {110, 0x5c, 0, 6}, |
| 2462 | {112, 0x5c, 0, 8}, |
| 2463 | {116, 0x5d, 0, 0}, |
| 2464 | {118, 0x5d, 0, 2}, |
| 2465 | {120, 0x5d, 0, 4}, |
| 2466 | {124, 0x5d, 0, 8}, |
| 2467 | {126, 0x5d, 0, 10}, |
| 2468 | {128, 0x5e, 0, 0}, |
| 2469 | {132, 0x5e, 0, 4}, |
| 2470 | {134, 0x5e, 0, 6}, |
| 2471 | {136, 0x5e, 0, 8}, |
| 2472 | {140, 0x5f, 0, 0}, |
| 2473 | |
| 2474 | /* 802.11 UNII */ |
| 2475 | {149, 0x5f, 0, 9}, |
| 2476 | {151, 0x5f, 0, 11}, |
| 2477 | {153, 0x60, 0, 1}, |
| 2478 | {157, 0x60, 0, 5}, |
| 2479 | {159, 0x60, 0, 7}, |
| 2480 | {161, 0x60, 0, 9}, |
| 2481 | {165, 0x61, 0, 1}, |
| 2482 | {167, 0x61, 0, 3}, |
| 2483 | {169, 0x61, 0, 5}, |
| 2484 | {171, 0x61, 0, 7}, |
| 2485 | {173, 0x61, 0, 9}, |
Bartlomiej Zolnierkiewicz | 4da2933f | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 2486 | }; |
| 2487 | |
| 2488 | int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev) |
| 2489 | { |
Bartlomiej Zolnierkiewicz | 4da2933f | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 2490 | struct hw_mode_spec *spec = &rt2x00dev->spec; |
| 2491 | struct channel_info *info; |
| 2492 | char *tx_power1; |
| 2493 | char *tx_power2; |
| 2494 | unsigned int i; |
| 2495 | u16 eeprom; |
| 2496 | |
| 2497 | /* |
Gertjan van Wingerde | 93b6bd2 | 2009-12-14 20:33:55 +0100 | [diff] [blame] | 2498 | * Disable powersaving as default on PCI devices. |
| 2499 | */ |
Gertjan van Wingerde | cea90e5 | 2010-02-13 20:55:47 +0100 | [diff] [blame] | 2500 | if (rt2x00_is_pci(rt2x00dev) || rt2x00_is_soc(rt2x00dev)) |
Gertjan van Wingerde | 93b6bd2 | 2009-12-14 20:33:55 +0100 | [diff] [blame] | 2501 | rt2x00dev->hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; |
| 2502 | |
| 2503 | /* |
Bartlomiej Zolnierkiewicz | 4da2933f | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 2504 | * Initialize all hw fields. |
| 2505 | */ |
| 2506 | rt2x00dev->hw->flags = |
| 2507 | IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING | |
| 2508 | IEEE80211_HW_SIGNAL_DBM | |
| 2509 | IEEE80211_HW_SUPPORTS_PS | |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 2510 | IEEE80211_HW_PS_NULLFUNC_STACK | |
| 2511 | IEEE80211_HW_AMPDU_AGGREGATION; |
Bartlomiej Zolnierkiewicz | 4da2933f | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 2512 | |
Bartlomiej Zolnierkiewicz | 4da2933f | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 2513 | SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev); |
| 2514 | SET_IEEE80211_PERM_ADDR(rt2x00dev->hw, |
| 2515 | rt2x00_eeprom_addr(rt2x00dev, |
| 2516 | EEPROM_MAC_ADDR_0)); |
| 2517 | |
Helmut Schaa | 3f2bee2 | 2010-06-14 22:12:01 +0200 | [diff] [blame] | 2518 | /* |
| 2519 | * As rt2800 has a global fallback table we cannot specify |
| 2520 | * more then one tx rate per frame but since the hw will |
| 2521 | * try several rates (based on the fallback table) we should |
| 2522 | * still initialize max_rates to the maximum number of rates |
| 2523 | * we are going to try. Otherwise mac80211 will truncate our |
| 2524 | * reported tx rates and the rc algortihm will end up with |
| 2525 | * incorrect data. |
| 2526 | */ |
| 2527 | rt2x00dev->hw->max_rates = 7; |
| 2528 | rt2x00dev->hw->max_rate_tries = 1; |
| 2529 | |
Bartlomiej Zolnierkiewicz | 4da2933f | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 2530 | rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom); |
| 2531 | |
| 2532 | /* |
| 2533 | * Initialize hw_mode information. |
| 2534 | */ |
| 2535 | spec->supported_bands = SUPPORT_BAND_2GHZ; |
| 2536 | spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM; |
| 2537 | |
Gertjan van Wingerde | 5122d89 | 2009-12-23 00:03:25 +0100 | [diff] [blame] | 2538 | if (rt2x00_rf(rt2x00dev, RF2820) || |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 2539 | rt2x00_rf(rt2x00dev, RF2720)) { |
Bartlomiej Zolnierkiewicz | 4da2933f | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 2540 | spec->num_channels = 14; |
| 2541 | spec->channels = rf_vals; |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 2542 | } else if (rt2x00_rf(rt2x00dev, RF2850) || |
| 2543 | rt2x00_rf(rt2x00dev, RF2750)) { |
Bartlomiej Zolnierkiewicz | 4da2933f | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 2544 | spec->supported_bands |= SUPPORT_BAND_5GHZ; |
| 2545 | spec->num_channels = ARRAY_SIZE(rf_vals); |
| 2546 | spec->channels = rf_vals; |
Gertjan van Wingerde | 5122d89 | 2009-12-23 00:03:25 +0100 | [diff] [blame] | 2547 | } else if (rt2x00_rf(rt2x00dev, RF3020) || |
| 2548 | rt2x00_rf(rt2x00dev, RF2020) || |
| 2549 | rt2x00_rf(rt2x00dev, RF3021) || |
| 2550 | rt2x00_rf(rt2x00dev, RF3022)) { |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 2551 | spec->num_channels = 14; |
| 2552 | spec->channels = rf_vals_3x; |
| 2553 | } else if (rt2x00_rf(rt2x00dev, RF3052)) { |
| 2554 | spec->supported_bands |= SUPPORT_BAND_5GHZ; |
| 2555 | spec->num_channels = ARRAY_SIZE(rf_vals_3x); |
| 2556 | spec->channels = rf_vals_3x; |
Bartlomiej Zolnierkiewicz | 4da2933f | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | /* |
| 2560 | * Initialize HT information. |
| 2561 | */ |
Gertjan van Wingerde | 5122d89 | 2009-12-23 00:03:25 +0100 | [diff] [blame] | 2562 | if (!rt2x00_rf(rt2x00dev, RF2020)) |
Gertjan van Wingerde | 38a522e | 2009-11-23 22:44:47 +0100 | [diff] [blame] | 2563 | spec->ht.ht_supported = true; |
| 2564 | else |
| 2565 | spec->ht.ht_supported = false; |
| 2566 | |
Bartlomiej Zolnierkiewicz | 4da2933f | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 2567 | spec->ht.cap = |
Gertjan van Wingerde | 06443e4 | 2010-06-03 10:52:08 +0200 | [diff] [blame] | 2568 | IEEE80211_HT_CAP_SUP_WIDTH_20_40 | |
Bartlomiej Zolnierkiewicz | 4da2933f | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 2569 | IEEE80211_HT_CAP_GRN_FLD | |
| 2570 | IEEE80211_HT_CAP_SGI_20 | |
Ivo van Doorn | aa67463 | 2010-06-29 21:48:37 +0200 | [diff] [blame] | 2571 | IEEE80211_HT_CAP_SGI_40; |
Helmut Schaa | 22cabaa | 2010-06-03 10:52:10 +0200 | [diff] [blame] | 2572 | |
| 2573 | if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH) >= 2) |
| 2574 | spec->ht.cap |= IEEE80211_HT_CAP_TX_STBC; |
| 2575 | |
Ivo van Doorn | aa67463 | 2010-06-29 21:48:37 +0200 | [diff] [blame] | 2576 | spec->ht.cap |= |
| 2577 | rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH) << |
| 2578 | IEEE80211_HT_CAP_RX_STBC_SHIFT; |
| 2579 | |
Bartlomiej Zolnierkiewicz | 4da2933f | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 2580 | spec->ht.ampdu_factor = 3; |
| 2581 | spec->ht.ampdu_density = 4; |
| 2582 | spec->ht.mcs.tx_params = |
| 2583 | IEEE80211_HT_MCS_TX_DEFINED | |
| 2584 | IEEE80211_HT_MCS_TX_RX_DIFF | |
| 2585 | ((rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH) - 1) << |
| 2586 | IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT); |
| 2587 | |
| 2588 | switch (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH)) { |
| 2589 | case 3: |
| 2590 | spec->ht.mcs.rx_mask[2] = 0xff; |
| 2591 | case 2: |
| 2592 | spec->ht.mcs.rx_mask[1] = 0xff; |
| 2593 | case 1: |
| 2594 | spec->ht.mcs.rx_mask[0] = 0xff; |
| 2595 | spec->ht.mcs.rx_mask[4] = 0x1; /* MCS32 */ |
| 2596 | break; |
| 2597 | } |
| 2598 | |
| 2599 | /* |
| 2600 | * Create channel information array |
| 2601 | */ |
| 2602 | info = kzalloc(spec->num_channels * sizeof(*info), GFP_KERNEL); |
| 2603 | if (!info) |
| 2604 | return -ENOMEM; |
| 2605 | |
| 2606 | spec->channels_info = info; |
| 2607 | |
| 2608 | tx_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG1); |
| 2609 | tx_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG2); |
| 2610 | |
| 2611 | for (i = 0; i < 14; i++) { |
| 2612 | info[i].tx_power1 = TXPOWER_G_FROM_DEV(tx_power1[i]); |
| 2613 | info[i].tx_power2 = TXPOWER_G_FROM_DEV(tx_power2[i]); |
| 2614 | } |
| 2615 | |
| 2616 | if (spec->num_channels > 14) { |
| 2617 | tx_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A1); |
| 2618 | tx_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A2); |
| 2619 | |
| 2620 | for (i = 14; i < spec->num_channels; i++) { |
| 2621 | info[i].tx_power1 = TXPOWER_A_FROM_DEV(tx_power1[i]); |
| 2622 | info[i].tx_power2 = TXPOWER_A_FROM_DEV(tx_power2[i]); |
| 2623 | } |
| 2624 | } |
| 2625 | |
| 2626 | return 0; |
| 2627 | } |
| 2628 | EXPORT_SYMBOL_GPL(rt2800_probe_hw_mode); |
| 2629 | |
| 2630 | /* |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 2631 | * IEEE80211 stack callback functions. |
| 2632 | */ |
| 2633 | static void rt2800_get_tkip_seq(struct ieee80211_hw *hw, u8 hw_key_idx, |
| 2634 | u32 *iv32, u16 *iv16) |
| 2635 | { |
| 2636 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 2637 | struct mac_iveiv_entry iveiv_entry; |
| 2638 | u32 offset; |
| 2639 | |
| 2640 | offset = MAC_IVEIV_ENTRY(hw_key_idx); |
| 2641 | rt2800_register_multiread(rt2x00dev, offset, |
| 2642 | &iveiv_entry, sizeof(iveiv_entry)); |
| 2643 | |
Julia Lawall | 855da5e | 2009-12-13 17:07:45 +0100 | [diff] [blame] | 2644 | memcpy(iv16, &iveiv_entry.iv[0], sizeof(*iv16)); |
| 2645 | memcpy(iv32, &iveiv_entry.iv[4], sizeof(*iv32)); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 2646 | } |
| 2647 | |
| 2648 | static int rt2800_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 2649 | { |
| 2650 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 2651 | u32 reg; |
| 2652 | bool enabled = (value < IEEE80211_MAX_RTS_THRESHOLD); |
| 2653 | |
| 2654 | rt2800_register_read(rt2x00dev, TX_RTS_CFG, ®); |
| 2655 | rt2x00_set_field32(®, TX_RTS_CFG_RTS_THRES, value); |
| 2656 | rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg); |
| 2657 | |
| 2658 | rt2800_register_read(rt2x00dev, CCK_PROT_CFG, ®); |
| 2659 | rt2x00_set_field32(®, CCK_PROT_CFG_RTS_TH_EN, enabled); |
| 2660 | rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg); |
| 2661 | |
| 2662 | rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, ®); |
| 2663 | rt2x00_set_field32(®, OFDM_PROT_CFG_RTS_TH_EN, enabled); |
| 2664 | rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg); |
| 2665 | |
| 2666 | rt2800_register_read(rt2x00dev, MM20_PROT_CFG, ®); |
| 2667 | rt2x00_set_field32(®, MM20_PROT_CFG_RTS_TH_EN, enabled); |
| 2668 | rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg); |
| 2669 | |
| 2670 | rt2800_register_read(rt2x00dev, MM40_PROT_CFG, ®); |
| 2671 | rt2x00_set_field32(®, MM40_PROT_CFG_RTS_TH_EN, enabled); |
| 2672 | rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg); |
| 2673 | |
| 2674 | rt2800_register_read(rt2x00dev, GF20_PROT_CFG, ®); |
| 2675 | rt2x00_set_field32(®, GF20_PROT_CFG_RTS_TH_EN, enabled); |
| 2676 | rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg); |
| 2677 | |
| 2678 | rt2800_register_read(rt2x00dev, GF40_PROT_CFG, ®); |
| 2679 | rt2x00_set_field32(®, GF40_PROT_CFG_RTS_TH_EN, enabled); |
| 2680 | rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg); |
| 2681 | |
| 2682 | return 0; |
| 2683 | } |
| 2684 | |
| 2685 | static int rt2800_conf_tx(struct ieee80211_hw *hw, u16 queue_idx, |
| 2686 | const struct ieee80211_tx_queue_params *params) |
| 2687 | { |
| 2688 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 2689 | struct data_queue *queue; |
| 2690 | struct rt2x00_field32 field; |
| 2691 | int retval; |
| 2692 | u32 reg; |
| 2693 | u32 offset; |
| 2694 | |
| 2695 | /* |
| 2696 | * First pass the configuration through rt2x00lib, that will |
| 2697 | * update the queue settings and validate the input. After that |
| 2698 | * we are free to update the registers based on the value |
| 2699 | * in the queue parameter. |
| 2700 | */ |
| 2701 | retval = rt2x00mac_conf_tx(hw, queue_idx, params); |
| 2702 | if (retval) |
| 2703 | return retval; |
| 2704 | |
| 2705 | /* |
| 2706 | * We only need to perform additional register initialization |
| 2707 | * for WMM queues/ |
| 2708 | */ |
| 2709 | if (queue_idx >= 4) |
| 2710 | return 0; |
| 2711 | |
| 2712 | queue = rt2x00queue_get_queue(rt2x00dev, queue_idx); |
| 2713 | |
| 2714 | /* Update WMM TXOP register */ |
| 2715 | offset = WMM_TXOP0_CFG + (sizeof(u32) * (!!(queue_idx & 2))); |
| 2716 | field.bit_offset = (queue_idx & 1) * 16; |
| 2717 | field.bit_mask = 0xffff << field.bit_offset; |
| 2718 | |
| 2719 | rt2800_register_read(rt2x00dev, offset, ®); |
| 2720 | rt2x00_set_field32(®, field, queue->txop); |
| 2721 | rt2800_register_write(rt2x00dev, offset, reg); |
| 2722 | |
| 2723 | /* Update WMM registers */ |
| 2724 | field.bit_offset = queue_idx * 4; |
| 2725 | field.bit_mask = 0xf << field.bit_offset; |
| 2726 | |
| 2727 | rt2800_register_read(rt2x00dev, WMM_AIFSN_CFG, ®); |
| 2728 | rt2x00_set_field32(®, field, queue->aifs); |
| 2729 | rt2800_register_write(rt2x00dev, WMM_AIFSN_CFG, reg); |
| 2730 | |
| 2731 | rt2800_register_read(rt2x00dev, WMM_CWMIN_CFG, ®); |
| 2732 | rt2x00_set_field32(®, field, queue->cw_min); |
| 2733 | rt2800_register_write(rt2x00dev, WMM_CWMIN_CFG, reg); |
| 2734 | |
| 2735 | rt2800_register_read(rt2x00dev, WMM_CWMAX_CFG, ®); |
| 2736 | rt2x00_set_field32(®, field, queue->cw_max); |
| 2737 | rt2800_register_write(rt2x00dev, WMM_CWMAX_CFG, reg); |
| 2738 | |
| 2739 | /* Update EDCA registers */ |
| 2740 | offset = EDCA_AC0_CFG + (sizeof(u32) * queue_idx); |
| 2741 | |
| 2742 | rt2800_register_read(rt2x00dev, offset, ®); |
| 2743 | rt2x00_set_field32(®, EDCA_AC0_CFG_TX_OP, queue->txop); |
| 2744 | rt2x00_set_field32(®, EDCA_AC0_CFG_AIFSN, queue->aifs); |
| 2745 | rt2x00_set_field32(®, EDCA_AC0_CFG_CWMIN, queue->cw_min); |
| 2746 | rt2x00_set_field32(®, EDCA_AC0_CFG_CWMAX, queue->cw_max); |
| 2747 | rt2800_register_write(rt2x00dev, offset, reg); |
| 2748 | |
| 2749 | return 0; |
| 2750 | } |
| 2751 | |
| 2752 | static u64 rt2800_get_tsf(struct ieee80211_hw *hw) |
| 2753 | { |
| 2754 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 2755 | u64 tsf; |
| 2756 | u32 reg; |
| 2757 | |
| 2758 | rt2800_register_read(rt2x00dev, TSF_TIMER_DW1, ®); |
| 2759 | tsf = (u64) rt2x00_get_field32(reg, TSF_TIMER_DW1_HIGH_WORD) << 32; |
| 2760 | rt2800_register_read(rt2x00dev, TSF_TIMER_DW0, ®); |
| 2761 | tsf |= rt2x00_get_field32(reg, TSF_TIMER_DW0_LOW_WORD); |
| 2762 | |
| 2763 | return tsf; |
| 2764 | } |
| 2765 | |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 2766 | static int rt2800_ampdu_action(struct ieee80211_hw *hw, |
| 2767 | struct ieee80211_vif *vif, |
| 2768 | enum ieee80211_ampdu_mlme_action action, |
| 2769 | struct ieee80211_sta *sta, |
| 2770 | u16 tid, u16 *ssn) |
| 2771 | { |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 2772 | int ret = 0; |
| 2773 | |
| 2774 | switch (action) { |
| 2775 | case IEEE80211_AMPDU_RX_START: |
| 2776 | case IEEE80211_AMPDU_RX_STOP: |
| 2777 | /* we don't support RX aggregation yet */ |
| 2778 | ret = -ENOTSUPP; |
| 2779 | break; |
| 2780 | case IEEE80211_AMPDU_TX_START: |
| 2781 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2782 | break; |
| 2783 | case IEEE80211_AMPDU_TX_STOP: |
| 2784 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2785 | break; |
| 2786 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 2787 | break; |
| 2788 | default: |
Ivo van Doorn | 4e9e58c | 2010-06-29 21:49:50 +0200 | [diff] [blame^] | 2789 | WARNING((struct rt2x00_dev *)hw->priv, "Unknown AMPDU action\n"); |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 2790 | } |
| 2791 | |
| 2792 | return ret; |
| 2793 | } |
| 2794 | |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 2795 | const struct ieee80211_ops rt2800_mac80211_ops = { |
| 2796 | .tx = rt2x00mac_tx, |
| 2797 | .start = rt2x00mac_start, |
| 2798 | .stop = rt2x00mac_stop, |
| 2799 | .add_interface = rt2x00mac_add_interface, |
| 2800 | .remove_interface = rt2x00mac_remove_interface, |
| 2801 | .config = rt2x00mac_config, |
| 2802 | .configure_filter = rt2x00mac_configure_filter, |
| 2803 | .set_tim = rt2x00mac_set_tim, |
| 2804 | .set_key = rt2x00mac_set_key, |
| 2805 | .get_stats = rt2x00mac_get_stats, |
| 2806 | .get_tkip_seq = rt2800_get_tkip_seq, |
| 2807 | .set_rts_threshold = rt2800_set_rts_threshold, |
| 2808 | .bss_info_changed = rt2x00mac_bss_info_changed, |
| 2809 | .conf_tx = rt2800_conf_tx, |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 2810 | .get_tsf = rt2800_get_tsf, |
| 2811 | .rfkill_poll = rt2x00mac_rfkill_poll, |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 2812 | .ampdu_action = rt2800_ampdu_action, |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 2813 | }; |
| 2814 | EXPORT_SYMBOL_GPL(rt2800_mac80211_ops); |
Ivo van Doorn | a5ea2f0 | 2010-06-14 22:13:15 +0200 | [diff] [blame] | 2815 | |
| 2816 | MODULE_AUTHOR(DRV_PROJECT ", Bartlomiej Zolnierkiewicz"); |
| 2817 | MODULE_VERSION(DRV_VERSION); |
| 2818 | MODULE_DESCRIPTION("Ralink RT2800 library"); |
| 2819 | MODULE_LICENSE("GPL"); |