Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 1 | /* |
Ivo van Doorn | 96481b2 | 2010-08-06 20:47:57 +0200 | [diff] [blame] | 2 | Copyright (C) 2010 Willow Garage <http://www.willowgarage.com> |
Ivo van Doorn | a5ea2f0 | 2010-06-14 22:13:15 +0200 | [diff] [blame] | 3 | Copyright (C) 2010 Ivo van Doorn <IvDoorn@gmail.com> |
Gertjan van Wingerde | 9c9a0d1 | 2009-11-08 16:39:55 +0100 | [diff] [blame] | 4 | Copyright (C) 2009 Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> |
Gertjan van Wingerde | cce5fc4 | 2009-11-10 22:42:40 +0100 | [diff] [blame] | 5 | Copyright (C) 2009 Gertjan van Wingerde <gwingerde@gmail.com> |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 6 | |
Gertjan van Wingerde | 9c9a0d1 | 2009-11-08 16:39:55 +0100 | [diff] [blame] | 7 | Based on the original rt2800pci.c and rt2800usb.c. |
Gertjan van Wingerde | 9c9a0d1 | 2009-11-08 16:39:55 +0100 | [diff] [blame] | 8 | Copyright (C) 2009 Alban Browaeys <prahal@yahoo.com> |
| 9 | Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org> |
| 10 | Copyright (C) 2009 Luis Correia <luis.f.correia@gmail.com> |
| 11 | Copyright (C) 2009 Mattias Nissler <mattias.nissler@gmx.de> |
| 12 | Copyright (C) 2009 Mark Asselstine <asselsm@gmail.com> |
| 13 | Copyright (C) 2009 Xose Vazquez Perez <xose.vazquez@gmail.com> |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 14 | <http://rt2x00.serialmonkey.com> |
| 15 | |
| 16 | This program is free software; you can redistribute it and/or modify |
| 17 | it under the terms of the GNU General Public License as published by |
| 18 | the Free Software Foundation; either version 2 of the License, or |
| 19 | (at your option) any later version. |
| 20 | |
| 21 | This program is distributed in the hope that it will be useful, |
| 22 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | GNU General Public License for more details. |
| 25 | |
| 26 | You should have received a copy of the GNU General Public License |
Jeff Kirsher | a05b8c5 | 2013-12-06 03:32:11 -0800 | [diff] [blame] | 27 | along with this program; if not, see <http://www.gnu.org/licenses/>. |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 28 | */ |
| 29 | |
| 30 | /* |
| 31 | Module: rt2800lib |
| 32 | Abstract: rt2800 generic device routines. |
| 33 | */ |
| 34 | |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 35 | #include <linux/crc-ccitt.h> |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 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 | |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 81 | rt2x00_warn(rt2x00dev, "Unknown RF chipset on rt305x\n"); |
Helmut Schaa | baff800 | 2010-04-28 09:58:59 +0200 | [diff] [blame] | 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 | |
Gabor Juhos | 379448f | 2013-07-08 11:25:55 +0200 | [diff] [blame] | 222 | static const unsigned int rt2800_eeprom_map[EEPROM_WORD_COUNT] = { |
| 223 | [EEPROM_CHIP_ID] = 0x0000, |
| 224 | [EEPROM_VERSION] = 0x0001, |
| 225 | [EEPROM_MAC_ADDR_0] = 0x0002, |
| 226 | [EEPROM_MAC_ADDR_1] = 0x0003, |
| 227 | [EEPROM_MAC_ADDR_2] = 0x0004, |
| 228 | [EEPROM_NIC_CONF0] = 0x001a, |
| 229 | [EEPROM_NIC_CONF1] = 0x001b, |
| 230 | [EEPROM_FREQ] = 0x001d, |
| 231 | [EEPROM_LED_AG_CONF] = 0x001e, |
| 232 | [EEPROM_LED_ACT_CONF] = 0x001f, |
| 233 | [EEPROM_LED_POLARITY] = 0x0020, |
| 234 | [EEPROM_NIC_CONF2] = 0x0021, |
| 235 | [EEPROM_LNA] = 0x0022, |
| 236 | [EEPROM_RSSI_BG] = 0x0023, |
| 237 | [EEPROM_RSSI_BG2] = 0x0024, |
| 238 | [EEPROM_TXMIXER_GAIN_BG] = 0x0024, /* overlaps with RSSI_BG2 */ |
| 239 | [EEPROM_RSSI_A] = 0x0025, |
| 240 | [EEPROM_RSSI_A2] = 0x0026, |
| 241 | [EEPROM_TXMIXER_GAIN_A] = 0x0026, /* overlaps with RSSI_A2 */ |
| 242 | [EEPROM_EIRP_MAX_TX_POWER] = 0x0027, |
| 243 | [EEPROM_TXPOWER_DELTA] = 0x0028, |
| 244 | [EEPROM_TXPOWER_BG1] = 0x0029, |
| 245 | [EEPROM_TXPOWER_BG2] = 0x0030, |
| 246 | [EEPROM_TSSI_BOUND_BG1] = 0x0037, |
| 247 | [EEPROM_TSSI_BOUND_BG2] = 0x0038, |
| 248 | [EEPROM_TSSI_BOUND_BG3] = 0x0039, |
| 249 | [EEPROM_TSSI_BOUND_BG4] = 0x003a, |
| 250 | [EEPROM_TSSI_BOUND_BG5] = 0x003b, |
| 251 | [EEPROM_TXPOWER_A1] = 0x003c, |
| 252 | [EEPROM_TXPOWER_A2] = 0x0053, |
| 253 | [EEPROM_TSSI_BOUND_A1] = 0x006a, |
| 254 | [EEPROM_TSSI_BOUND_A2] = 0x006b, |
| 255 | [EEPROM_TSSI_BOUND_A3] = 0x006c, |
| 256 | [EEPROM_TSSI_BOUND_A4] = 0x006d, |
| 257 | [EEPROM_TSSI_BOUND_A5] = 0x006e, |
| 258 | [EEPROM_TXPOWER_BYRATE] = 0x006f, |
| 259 | [EEPROM_BBP_START] = 0x0078, |
| 260 | }; |
| 261 | |
Gabor Juhos | fa31d15 | 2013-07-08 11:25:56 +0200 | [diff] [blame] | 262 | static const unsigned int rt2800_eeprom_map_ext[EEPROM_WORD_COUNT] = { |
| 263 | [EEPROM_CHIP_ID] = 0x0000, |
| 264 | [EEPROM_VERSION] = 0x0001, |
| 265 | [EEPROM_MAC_ADDR_0] = 0x0002, |
| 266 | [EEPROM_MAC_ADDR_1] = 0x0003, |
| 267 | [EEPROM_MAC_ADDR_2] = 0x0004, |
| 268 | [EEPROM_NIC_CONF0] = 0x001a, |
| 269 | [EEPROM_NIC_CONF1] = 0x001b, |
| 270 | [EEPROM_NIC_CONF2] = 0x001c, |
| 271 | [EEPROM_EIRP_MAX_TX_POWER] = 0x0020, |
| 272 | [EEPROM_FREQ] = 0x0022, |
| 273 | [EEPROM_LED_AG_CONF] = 0x0023, |
| 274 | [EEPROM_LED_ACT_CONF] = 0x0024, |
| 275 | [EEPROM_LED_POLARITY] = 0x0025, |
| 276 | [EEPROM_LNA] = 0x0026, |
| 277 | [EEPROM_EXT_LNA2] = 0x0027, |
| 278 | [EEPROM_RSSI_BG] = 0x0028, |
Gabor Juhos | fa31d15 | 2013-07-08 11:25:56 +0200 | [diff] [blame] | 279 | [EEPROM_RSSI_BG2] = 0x0029, |
Gabor Juhos | fa31d15 | 2013-07-08 11:25:56 +0200 | [diff] [blame] | 280 | [EEPROM_RSSI_A] = 0x002a, |
| 281 | [EEPROM_RSSI_A2] = 0x002b, |
Gabor Juhos | fa31d15 | 2013-07-08 11:25:56 +0200 | [diff] [blame] | 282 | [EEPROM_TXPOWER_BG1] = 0x0030, |
| 283 | [EEPROM_TXPOWER_BG2] = 0x0037, |
| 284 | [EEPROM_EXT_TXPOWER_BG3] = 0x003e, |
| 285 | [EEPROM_TSSI_BOUND_BG1] = 0x0045, |
| 286 | [EEPROM_TSSI_BOUND_BG2] = 0x0046, |
| 287 | [EEPROM_TSSI_BOUND_BG3] = 0x0047, |
| 288 | [EEPROM_TSSI_BOUND_BG4] = 0x0048, |
| 289 | [EEPROM_TSSI_BOUND_BG5] = 0x0049, |
| 290 | [EEPROM_TXPOWER_A1] = 0x004b, |
| 291 | [EEPROM_TXPOWER_A2] = 0x0065, |
| 292 | [EEPROM_EXT_TXPOWER_A3] = 0x007f, |
| 293 | [EEPROM_TSSI_BOUND_A1] = 0x009a, |
| 294 | [EEPROM_TSSI_BOUND_A2] = 0x009b, |
| 295 | [EEPROM_TSSI_BOUND_A3] = 0x009c, |
| 296 | [EEPROM_TSSI_BOUND_A4] = 0x009d, |
| 297 | [EEPROM_TSSI_BOUND_A5] = 0x009e, |
| 298 | [EEPROM_TXPOWER_BYRATE] = 0x00a0, |
| 299 | }; |
| 300 | |
Gabor Juhos | 379448f | 2013-07-08 11:25:55 +0200 | [diff] [blame] | 301 | static unsigned int rt2800_eeprom_word_index(struct rt2x00_dev *rt2x00dev, |
| 302 | const enum rt2800_eeprom_word word) |
| 303 | { |
| 304 | const unsigned int *map; |
| 305 | unsigned int index; |
| 306 | |
| 307 | if (WARN_ONCE(word >= EEPROM_WORD_COUNT, |
| 308 | "%s: invalid EEPROM word %d\n", |
| 309 | wiphy_name(rt2x00dev->hw->wiphy), word)) |
| 310 | return 0; |
| 311 | |
Gabor Juhos | fa31d15 | 2013-07-08 11:25:56 +0200 | [diff] [blame] | 312 | if (rt2x00_rt(rt2x00dev, RT3593)) |
| 313 | map = rt2800_eeprom_map_ext; |
| 314 | else |
| 315 | map = rt2800_eeprom_map; |
| 316 | |
Gabor Juhos | 379448f | 2013-07-08 11:25:55 +0200 | [diff] [blame] | 317 | index = map[word]; |
| 318 | |
| 319 | /* Index 0 is valid only for EEPROM_CHIP_ID. |
| 320 | * Otherwise it means that the offset of the |
| 321 | * given word is not initialized in the map, |
| 322 | * or that the field is not usable on the |
| 323 | * actual chipset. |
| 324 | */ |
| 325 | WARN_ONCE(word != EEPROM_CHIP_ID && index == 0, |
| 326 | "%s: invalid access of EEPROM word %d\n", |
| 327 | wiphy_name(rt2x00dev->hw->wiphy), word); |
| 328 | |
| 329 | return index; |
| 330 | } |
| 331 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 332 | static void *rt2800_eeprom_addr(struct rt2x00_dev *rt2x00dev, |
| 333 | const enum rt2800_eeprom_word word) |
| 334 | { |
Gabor Juhos | 379448f | 2013-07-08 11:25:55 +0200 | [diff] [blame] | 335 | unsigned int index; |
| 336 | |
| 337 | index = rt2800_eeprom_word_index(rt2x00dev, word); |
| 338 | return rt2x00_eeprom_addr(rt2x00dev, index); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | static void rt2800_eeprom_read(struct rt2x00_dev *rt2x00dev, |
| 342 | const enum rt2800_eeprom_word word, u16 *data) |
| 343 | { |
Gabor Juhos | 379448f | 2013-07-08 11:25:55 +0200 | [diff] [blame] | 344 | unsigned int index; |
| 345 | |
| 346 | index = rt2800_eeprom_word_index(rt2x00dev, word); |
| 347 | rt2x00_eeprom_read(rt2x00dev, index, data); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | static void rt2800_eeprom_write(struct rt2x00_dev *rt2x00dev, |
| 351 | const enum rt2800_eeprom_word word, u16 data) |
| 352 | { |
Gabor Juhos | 379448f | 2013-07-08 11:25:55 +0200 | [diff] [blame] | 353 | unsigned int index; |
| 354 | |
| 355 | index = rt2800_eeprom_word_index(rt2x00dev, word); |
| 356 | rt2x00_eeprom_write(rt2x00dev, index, data); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 357 | } |
| 358 | |
Gabor Juhos | 022138c | 2013-07-08 11:25:54 +0200 | [diff] [blame] | 359 | static void rt2800_eeprom_read_from_array(struct rt2x00_dev *rt2x00dev, |
| 360 | const enum rt2800_eeprom_word array, |
| 361 | unsigned int offset, |
| 362 | u16 *data) |
| 363 | { |
Gabor Juhos | 379448f | 2013-07-08 11:25:55 +0200 | [diff] [blame] | 364 | unsigned int index; |
| 365 | |
| 366 | index = rt2800_eeprom_word_index(rt2x00dev, array); |
| 367 | rt2x00_eeprom_read(rt2x00dev, index + offset, data); |
Gabor Juhos | 022138c | 2013-07-08 11:25:54 +0200 | [diff] [blame] | 368 | } |
| 369 | |
Woody Hung | 16ebd60 | 2012-07-31 21:53:33 +0800 | [diff] [blame] | 370 | static int rt2800_enable_wlan_rt3290(struct rt2x00_dev *rt2x00dev) |
| 371 | { |
| 372 | u32 reg; |
| 373 | int i, count; |
| 374 | |
| 375 | rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, ®); |
| 376 | if (rt2x00_get_field32(reg, WLAN_EN)) |
| 377 | return 0; |
| 378 | |
| 379 | rt2x00_set_field32(®, WLAN_GPIO_OUT_OE_BIT_ALL, 0xff); |
| 380 | rt2x00_set_field32(®, FRC_WL_ANT_SET, 1); |
| 381 | rt2x00_set_field32(®, WLAN_CLK_EN, 0); |
| 382 | rt2x00_set_field32(®, WLAN_EN, 1); |
| 383 | rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg); |
| 384 | |
| 385 | udelay(REGISTER_BUSY_DELAY); |
| 386 | |
| 387 | count = 0; |
| 388 | do { |
| 389 | /* |
| 390 | * Check PLL_LD & XTAL_RDY. |
| 391 | */ |
| 392 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
| 393 | rt2800_register_read(rt2x00dev, CMB_CTRL, ®); |
| 394 | if (rt2x00_get_field32(reg, PLL_LD) && |
| 395 | rt2x00_get_field32(reg, XTAL_RDY)) |
| 396 | break; |
| 397 | udelay(REGISTER_BUSY_DELAY); |
| 398 | } |
| 399 | |
| 400 | if (i >= REGISTER_BUSY_COUNT) { |
| 401 | |
| 402 | if (count >= 10) |
| 403 | return -EIO; |
| 404 | |
| 405 | rt2800_register_write(rt2x00dev, 0x58, 0x018); |
| 406 | udelay(REGISTER_BUSY_DELAY); |
| 407 | rt2800_register_write(rt2x00dev, 0x58, 0x418); |
| 408 | udelay(REGISTER_BUSY_DELAY); |
| 409 | rt2800_register_write(rt2x00dev, 0x58, 0x618); |
| 410 | udelay(REGISTER_BUSY_DELAY); |
| 411 | count++; |
| 412 | } else { |
| 413 | count = 0; |
| 414 | } |
| 415 | |
| 416 | rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, ®); |
| 417 | rt2x00_set_field32(®, PCIE_APP0_CLK_REQ, 0); |
| 418 | rt2x00_set_field32(®, WLAN_CLK_EN, 1); |
| 419 | rt2x00_set_field32(®, WLAN_RESET, 1); |
| 420 | rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg); |
| 421 | udelay(10); |
| 422 | rt2x00_set_field32(®, WLAN_RESET, 0); |
| 423 | rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg); |
| 424 | udelay(10); |
| 425 | rt2800_register_write(rt2x00dev, INT_SOURCE_CSR, 0x7fffffff); |
| 426 | } while (count != 0); |
| 427 | |
| 428 | return 0; |
| 429 | } |
| 430 | |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 431 | void rt2800_mcu_request(struct rt2x00_dev *rt2x00dev, |
| 432 | const u8 command, const u8 token, |
| 433 | const u8 arg0, const u8 arg1) |
| 434 | { |
| 435 | u32 reg; |
| 436 | |
Gertjan van Wingerde | ee303e5 | 2009-11-23 22:44:49 +0100 | [diff] [blame] | 437 | /* |
Gertjan van Wingerde | cea90e5 | 2010-02-13 20:55:47 +0100 | [diff] [blame] | 438 | * SOC devices don't support MCU requests. |
Gertjan van Wingerde | ee303e5 | 2009-11-23 22:44:49 +0100 | [diff] [blame] | 439 | */ |
Gertjan van Wingerde | cea90e5 | 2010-02-13 20:55:47 +0100 | [diff] [blame] | 440 | if (rt2x00_is_soc(rt2x00dev)) |
Gertjan van Wingerde | ee303e5 | 2009-11-23 22:44:49 +0100 | [diff] [blame] | 441 | return; |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 442 | |
| 443 | mutex_lock(&rt2x00dev->csr_mutex); |
| 444 | |
| 445 | /* |
| 446 | * Wait until the MCU becomes available, afterwards we |
| 447 | * can safely write the new data into the register. |
| 448 | */ |
| 449 | if (WAIT_FOR_MCU(rt2x00dev, ®)) { |
| 450 | rt2x00_set_field32(®, H2M_MAILBOX_CSR_OWNER, 1); |
| 451 | rt2x00_set_field32(®, H2M_MAILBOX_CSR_CMD_TOKEN, token); |
| 452 | rt2x00_set_field32(®, H2M_MAILBOX_CSR_ARG0, arg0); |
| 453 | rt2x00_set_field32(®, H2M_MAILBOX_CSR_ARG1, arg1); |
| 454 | rt2800_register_write_lock(rt2x00dev, H2M_MAILBOX_CSR, reg); |
| 455 | |
| 456 | reg = 0; |
| 457 | rt2x00_set_field32(®, HOST_CMD_CSR_HOST_COMMAND, command); |
| 458 | rt2800_register_write_lock(rt2x00dev, HOST_CMD_CSR, reg); |
| 459 | } |
| 460 | |
| 461 | mutex_unlock(&rt2x00dev->csr_mutex); |
| 462 | } |
| 463 | EXPORT_SYMBOL_GPL(rt2800_mcu_request); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 464 | |
Ivo van Doorn | 5ffddc4 | 2010-08-30 21:13:08 +0200 | [diff] [blame] | 465 | int rt2800_wait_csr_ready(struct rt2x00_dev *rt2x00dev) |
| 466 | { |
| 467 | unsigned int i = 0; |
| 468 | u32 reg; |
| 469 | |
| 470 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
| 471 | rt2800_register_read(rt2x00dev, MAC_CSR0, ®); |
| 472 | if (reg && reg != ~0) |
| 473 | return 0; |
| 474 | msleep(1); |
| 475 | } |
| 476 | |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 477 | rt2x00_err(rt2x00dev, "Unstable hardware\n"); |
Ivo van Doorn | 5ffddc4 | 2010-08-30 21:13:08 +0200 | [diff] [blame] | 478 | return -EBUSY; |
| 479 | } |
| 480 | EXPORT_SYMBOL_GPL(rt2800_wait_csr_ready); |
| 481 | |
Gertjan van Wingerde | 67a4c1e | 2009-12-30 11:36:32 +0100 | [diff] [blame] | 482 | int rt2800_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev) |
| 483 | { |
| 484 | unsigned int i; |
| 485 | u32 reg; |
| 486 | |
Helmut Schaa | 08e5310 | 2010-11-04 20:37:47 +0100 | [diff] [blame] | 487 | /* |
| 488 | * Some devices are really slow to respond here. Wait a whole second |
| 489 | * before timing out. |
| 490 | */ |
Gertjan van Wingerde | 67a4c1e | 2009-12-30 11:36:32 +0100 | [diff] [blame] | 491 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
| 492 | rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®); |
| 493 | if (!rt2x00_get_field32(reg, WPDMA_GLO_CFG_TX_DMA_BUSY) && |
| 494 | !rt2x00_get_field32(reg, WPDMA_GLO_CFG_RX_DMA_BUSY)) |
| 495 | return 0; |
| 496 | |
Helmut Schaa | 08e5310 | 2010-11-04 20:37:47 +0100 | [diff] [blame] | 497 | msleep(10); |
Gertjan van Wingerde | 67a4c1e | 2009-12-30 11:36:32 +0100 | [diff] [blame] | 498 | } |
| 499 | |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 500 | rt2x00_err(rt2x00dev, "WPDMA TX/RX busy [0x%08x]\n", reg); |
Gertjan van Wingerde | 67a4c1e | 2009-12-30 11:36:32 +0100 | [diff] [blame] | 501 | return -EACCES; |
| 502 | } |
| 503 | EXPORT_SYMBOL_GPL(rt2800_wait_wpdma_ready); |
| 504 | |
Jakub Kicinski | f7b395e | 2012-04-03 03:40:47 +0200 | [diff] [blame] | 505 | void rt2800_disable_wpdma(struct rt2x00_dev *rt2x00dev) |
| 506 | { |
| 507 | u32 reg; |
| 508 | |
| 509 | rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®); |
| 510 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0); |
| 511 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_DMA_BUSY, 0); |
| 512 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0); |
| 513 | rt2x00_set_field32(®, WPDMA_GLO_CFG_RX_DMA_BUSY, 0); |
| 514 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1); |
| 515 | rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg); |
| 516 | } |
| 517 | EXPORT_SYMBOL_GPL(rt2800_disable_wpdma); |
| 518 | |
Gabor Juhos | ae1b1c5 | 2013-08-16 10:23:29 +0200 | [diff] [blame] | 519 | void rt2800_get_txwi_rxwi_size(struct rt2x00_dev *rt2x00dev, |
| 520 | unsigned short *txwi_size, |
| 521 | unsigned short *rxwi_size) |
| 522 | { |
| 523 | switch (rt2x00dev->chip.rt) { |
| 524 | case RT3593: |
| 525 | *txwi_size = TXWI_DESC_SIZE_4WORDS; |
| 526 | *rxwi_size = RXWI_DESC_SIZE_5WORDS; |
| 527 | break; |
| 528 | |
| 529 | case RT5592: |
| 530 | *txwi_size = TXWI_DESC_SIZE_5WORDS; |
| 531 | *rxwi_size = RXWI_DESC_SIZE_6WORDS; |
| 532 | break; |
| 533 | |
| 534 | default: |
| 535 | *txwi_size = TXWI_DESC_SIZE_4WORDS; |
| 536 | *rxwi_size = RXWI_DESC_SIZE_4WORDS; |
| 537 | break; |
| 538 | } |
| 539 | } |
| 540 | EXPORT_SYMBOL_GPL(rt2800_get_txwi_rxwi_size); |
| 541 | |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 542 | static bool rt2800_check_firmware_crc(const u8 *data, const size_t len) |
| 543 | { |
| 544 | u16 fw_crc; |
| 545 | u16 crc; |
| 546 | |
| 547 | /* |
| 548 | * The last 2 bytes in the firmware array are the crc checksum itself, |
| 549 | * this means that we should never pass those 2 bytes to the crc |
| 550 | * algorithm. |
| 551 | */ |
| 552 | fw_crc = (data[len - 2] << 8 | data[len - 1]); |
| 553 | |
| 554 | /* |
| 555 | * Use the crc ccitt algorithm. |
| 556 | * This will return the same value as the legacy driver which |
| 557 | * used bit ordering reversion on the both the firmware bytes |
| 558 | * before input input as well as on the final output. |
| 559 | * Obviously using crc ccitt directly is much more efficient. |
| 560 | */ |
| 561 | crc = crc_ccitt(~0, data, len - 2); |
| 562 | |
| 563 | /* |
| 564 | * There is a small difference between the crc-itu-t + bitrev and |
| 565 | * the crc-ccitt crc calculation. In the latter method the 2 bytes |
| 566 | * will be swapped, use swab16 to convert the crc to the correct |
| 567 | * value. |
| 568 | */ |
| 569 | crc = swab16(crc); |
| 570 | |
| 571 | return fw_crc == crc; |
| 572 | } |
| 573 | |
| 574 | int rt2800_check_firmware(struct rt2x00_dev *rt2x00dev, |
| 575 | const u8 *data, const size_t len) |
| 576 | { |
| 577 | size_t offset = 0; |
| 578 | size_t fw_len; |
| 579 | bool multiple; |
| 580 | |
| 581 | /* |
| 582 | * PCI(e) & SOC devices require firmware with a length |
| 583 | * of 8kb. USB devices require firmware files with a length |
| 584 | * of 4kb. Certain USB chipsets however require different firmware, |
| 585 | * which Ralink only provides attached to the original firmware |
| 586 | * file. Thus for USB devices, firmware files have a length |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 587 | * which is a multiple of 4kb. The firmware for rt3290 chip also |
| 588 | * have a length which is a multiple of 4kb. |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 589 | */ |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 590 | if (rt2x00_is_usb(rt2x00dev) || rt2x00_rt(rt2x00dev, RT3290)) |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 591 | fw_len = 4096; |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 592 | else |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 593 | fw_len = 8192; |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 594 | |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 595 | multiple = true; |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 596 | /* |
| 597 | * Validate the firmware length |
| 598 | */ |
| 599 | if (len != fw_len && (!multiple || (len % fw_len) != 0)) |
| 600 | return FW_BAD_LENGTH; |
| 601 | |
| 602 | /* |
| 603 | * Check if the chipset requires one of the upper parts |
| 604 | * of the firmware. |
| 605 | */ |
| 606 | if (rt2x00_is_usb(rt2x00dev) && |
| 607 | !rt2x00_rt(rt2x00dev, RT2860) && |
| 608 | !rt2x00_rt(rt2x00dev, RT2872) && |
| 609 | !rt2x00_rt(rt2x00dev, RT3070) && |
| 610 | ((len / fw_len) == 1)) |
| 611 | return FW_BAD_VERSION; |
| 612 | |
| 613 | /* |
| 614 | * 8kb firmware files must be checked as if it were |
| 615 | * 2 separate firmware files. |
| 616 | */ |
| 617 | while (offset < len) { |
| 618 | if (!rt2800_check_firmware_crc(data + offset, fw_len)) |
| 619 | return FW_BAD_CRC; |
| 620 | |
| 621 | offset += fw_len; |
| 622 | } |
| 623 | |
| 624 | return FW_OK; |
| 625 | } |
| 626 | EXPORT_SYMBOL_GPL(rt2800_check_firmware); |
| 627 | |
| 628 | int rt2800_load_firmware(struct rt2x00_dev *rt2x00dev, |
| 629 | const u8 *data, const size_t len) |
| 630 | { |
| 631 | unsigned int i; |
| 632 | u32 reg; |
Woody Hung | 16ebd60 | 2012-07-31 21:53:33 +0800 | [diff] [blame] | 633 | int retval; |
| 634 | |
| 635 | if (rt2x00_rt(rt2x00dev, RT3290)) { |
| 636 | retval = rt2800_enable_wlan_rt3290(rt2x00dev); |
| 637 | if (retval) |
| 638 | return -EBUSY; |
| 639 | } |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 640 | |
| 641 | /* |
Ivo van Doorn | b9eca24 | 2010-08-30 21:13:54 +0200 | [diff] [blame] | 642 | * If driver doesn't wake up firmware here, |
| 643 | * rt2800_load_firmware will hang forever when interface is up again. |
| 644 | */ |
| 645 | rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0x00000000); |
| 646 | |
| 647 | /* |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 648 | * Wait for stable hardware. |
| 649 | */ |
Ivo van Doorn | 5ffddc4 | 2010-08-30 21:13:08 +0200 | [diff] [blame] | 650 | if (rt2800_wait_csr_ready(rt2x00dev)) |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 651 | return -EBUSY; |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 652 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 653 | if (rt2x00_is_pci(rt2x00dev)) { |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 654 | if (rt2x00_rt(rt2x00dev, RT3290) || |
| 655 | rt2x00_rt(rt2x00dev, RT3572) || |
John Li | 2ed7188 | 2012-02-17 17:33:06 +0800 | [diff] [blame] | 656 | rt2x00_rt(rt2x00dev, RT5390) || |
| 657 | rt2x00_rt(rt2x00dev, RT5392)) { |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 658 | rt2800_register_read(rt2x00dev, AUX_CTRL, ®); |
| 659 | rt2x00_set_field32(®, AUX_CTRL_FORCE_PCIE_CLK, 1); |
| 660 | rt2x00_set_field32(®, AUX_CTRL_WAKE_PCIE_EN, 1); |
| 661 | rt2800_register_write(rt2x00dev, AUX_CTRL, reg); |
| 662 | } |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 663 | rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000002); |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 664 | } |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 665 | |
Jakub Kicinski | b7e1d22 | 2012-04-03 03:40:48 +0200 | [diff] [blame] | 666 | rt2800_disable_wpdma(rt2x00dev); |
| 667 | |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 668 | /* |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 669 | * Write firmware to the device. |
| 670 | */ |
| 671 | rt2800_drv_write_firmware(rt2x00dev, data, len); |
| 672 | |
| 673 | /* |
| 674 | * Wait for device to stabilize. |
| 675 | */ |
| 676 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
| 677 | rt2800_register_read(rt2x00dev, PBF_SYS_CTRL, ®); |
| 678 | if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY)) |
| 679 | break; |
| 680 | msleep(1); |
| 681 | } |
| 682 | |
| 683 | if (i == REGISTER_BUSY_COUNT) { |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 684 | rt2x00_err(rt2x00dev, "PBF system register not ready\n"); |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 685 | return -EBUSY; |
| 686 | } |
| 687 | |
| 688 | /* |
Stanislaw Gruszka | 4ed1dd2 | 2012-01-24 14:09:07 +0100 | [diff] [blame] | 689 | * Disable DMA, will be reenabled later when enabling |
| 690 | * the radio. |
| 691 | */ |
Jakub Kicinski | f7b395e | 2012-04-03 03:40:47 +0200 | [diff] [blame] | 692 | rt2800_disable_wpdma(rt2x00dev); |
Stanislaw Gruszka | 4ed1dd2 | 2012-01-24 14:09:07 +0100 | [diff] [blame] | 693 | |
| 694 | /* |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 695 | * Initialize firmware. |
| 696 | */ |
| 697 | rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0); |
| 698 | rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0); |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 699 | if (rt2x00_is_usb(rt2x00dev)) { |
Stanislaw Gruszka | 0c17cf9 | 2012-01-24 14:09:06 +0100 | [diff] [blame] | 700 | rt2800_register_write(rt2x00dev, H2M_INT_SRC, 0); |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 701 | rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0, 0, 0); |
| 702 | } |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 703 | msleep(1); |
| 704 | |
| 705 | return 0; |
| 706 | } |
| 707 | EXPORT_SYMBOL_GPL(rt2800_load_firmware); |
| 708 | |
Ivo van Doorn | 0c5879b | 2010-08-06 20:47:20 +0200 | [diff] [blame] | 709 | void rt2800_write_tx_data(struct queue_entry *entry, |
| 710 | struct txentry_desc *txdesc) |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 711 | { |
Ivo van Doorn | 0c5879b | 2010-08-06 20:47:20 +0200 | [diff] [blame] | 712 | __le32 *txwi = rt2800_drv_get_txwi(entry); |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 713 | u32 word; |
Stanislaw Gruszka | 557985a | 2013-04-17 14:30:48 +0200 | [diff] [blame] | 714 | int i; |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 715 | |
| 716 | /* |
| 717 | * Initialize TX Info descriptor |
| 718 | */ |
| 719 | rt2x00_desc_read(txwi, 0, &word); |
| 720 | rt2x00_set_field32(&word, TXWI_W0_FRAG, |
| 721 | test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags)); |
Ivo van Doorn | 84804cd | 2010-08-06 20:46:19 +0200 | [diff] [blame] | 722 | rt2x00_set_field32(&word, TXWI_W0_MIMO_PS, |
| 723 | test_bit(ENTRY_TXD_HT_MIMO_PS, &txdesc->flags)); |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 724 | rt2x00_set_field32(&word, TXWI_W0_CF_ACK, 0); |
| 725 | rt2x00_set_field32(&word, TXWI_W0_TS, |
| 726 | test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags)); |
| 727 | rt2x00_set_field32(&word, TXWI_W0_AMPDU, |
| 728 | test_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags)); |
Helmut Schaa | 26a1d07 | 2011-03-03 19:42:35 +0100 | [diff] [blame] | 729 | rt2x00_set_field32(&word, TXWI_W0_MPDU_DENSITY, |
| 730 | txdesc->u.ht.mpdu_density); |
| 731 | rt2x00_set_field32(&word, TXWI_W0_TX_OP, txdesc->u.ht.txop); |
| 732 | rt2x00_set_field32(&word, TXWI_W0_MCS, txdesc->u.ht.mcs); |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 733 | rt2x00_set_field32(&word, TXWI_W0_BW, |
| 734 | test_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags)); |
| 735 | rt2x00_set_field32(&word, TXWI_W0_SHORT_GI, |
| 736 | test_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags)); |
Helmut Schaa | 26a1d07 | 2011-03-03 19:42:35 +0100 | [diff] [blame] | 737 | rt2x00_set_field32(&word, TXWI_W0_STBC, txdesc->u.ht.stbc); |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 738 | rt2x00_set_field32(&word, TXWI_W0_PHYMODE, txdesc->rate_mode); |
| 739 | rt2x00_desc_write(txwi, 0, word); |
| 740 | |
| 741 | rt2x00_desc_read(txwi, 1, &word); |
| 742 | rt2x00_set_field32(&word, TXWI_W1_ACK, |
| 743 | test_bit(ENTRY_TXD_ACK, &txdesc->flags)); |
| 744 | rt2x00_set_field32(&word, TXWI_W1_NSEQ, |
| 745 | test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags)); |
Helmut Schaa | 26a1d07 | 2011-03-03 19:42:35 +0100 | [diff] [blame] | 746 | rt2x00_set_field32(&word, TXWI_W1_BW_WIN_SIZE, txdesc->u.ht.ba_size); |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 747 | rt2x00_set_field32(&word, TXWI_W1_WIRELESS_CLI_ID, |
| 748 | test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags) ? |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 749 | txdesc->key_idx : txdesc->u.ht.wcid); |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 750 | rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT, |
| 751 | txdesc->length); |
Helmut Schaa | 2b23cda | 2010-11-04 20:38:15 +0100 | [diff] [blame] | 752 | rt2x00_set_field32(&word, TXWI_W1_PACKETID_QUEUE, entry->queue->qid); |
Ivo van Doorn | bc8a979 | 2010-10-02 11:32:43 +0200 | [diff] [blame] | 753 | rt2x00_set_field32(&word, TXWI_W1_PACKETID_ENTRY, (entry->entry_idx % 3) + 1); |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 754 | rt2x00_desc_write(txwi, 1, word); |
| 755 | |
| 756 | /* |
Stanislaw Gruszka | 557985a | 2013-04-17 14:30:48 +0200 | [diff] [blame] | 757 | * Always write 0 to IV/EIV fields (word 2 and 3), hardware will insert |
| 758 | * the IV from the IVEIV register when TXD_W3_WIV is set to 0. |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 759 | * When TXD_W3_WIV is set to 1 it will use the IV data |
| 760 | * from the descriptor. The TXWI_W1_WIRELESS_CLI_ID indicates which |
| 761 | * crypto entry in the registers should be used to encrypt the frame. |
Stanislaw Gruszka | 557985a | 2013-04-17 14:30:48 +0200 | [diff] [blame] | 762 | * |
| 763 | * Nulify all remaining words as well, we don't know how to program them. |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 764 | */ |
Stanislaw Gruszka | 557985a | 2013-04-17 14:30:48 +0200 | [diff] [blame] | 765 | for (i = 2; i < entry->queue->winfo_size / sizeof(__le32); i++) |
| 766 | _rt2x00_desc_write(txwi, i, 0); |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 767 | } |
Ivo van Doorn | 0c5879b | 2010-08-06 20:47:20 +0200 | [diff] [blame] | 768 | EXPORT_SYMBOL_GPL(rt2800_write_tx_data); |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 769 | |
Helmut Schaa | ff6133b | 2010-10-09 13:34:11 +0200 | [diff] [blame] | 770 | static int rt2800_agc_to_rssi(struct rt2x00_dev *rt2x00dev, u32 rxwi_w2) |
Gertjan van Wingerde | 2de64dd | 2010-05-08 23:40:22 +0200 | [diff] [blame] | 771 | { |
Luigi Tarenga | 7fc4175 | 2012-01-31 18:51:23 +0100 | [diff] [blame] | 772 | s8 rssi0 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI0); |
| 773 | s8 rssi1 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI1); |
| 774 | s8 rssi2 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI2); |
Ivo van Doorn | 7486192 | 2010-07-11 12:23:50 +0200 | [diff] [blame] | 775 | u16 eeprom; |
| 776 | u8 offset0; |
| 777 | u8 offset1; |
| 778 | u8 offset2; |
| 779 | |
Ivo van Doorn | e5ef5ba | 2010-08-06 20:49:27 +0200 | [diff] [blame] | 780 | if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 781 | rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &eeprom); |
Ivo van Doorn | 7486192 | 2010-07-11 12:23:50 +0200 | [diff] [blame] | 782 | offset0 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG_OFFSET0); |
| 783 | offset1 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG_OFFSET1); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 784 | rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom); |
Ivo van Doorn | 7486192 | 2010-07-11 12:23:50 +0200 | [diff] [blame] | 785 | offset2 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG2_OFFSET2); |
| 786 | } else { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 787 | rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &eeprom); |
Ivo van Doorn | 7486192 | 2010-07-11 12:23:50 +0200 | [diff] [blame] | 788 | offset0 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A_OFFSET0); |
| 789 | offset1 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A_OFFSET1); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 790 | rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom); |
Ivo van Doorn | 7486192 | 2010-07-11 12:23:50 +0200 | [diff] [blame] | 791 | offset2 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A2_OFFSET2); |
| 792 | } |
| 793 | |
| 794 | /* |
| 795 | * Convert the value from the descriptor into the RSSI value |
| 796 | * If the value in the descriptor is 0, it is considered invalid |
| 797 | * and the default (extremely low) rssi value is assumed |
| 798 | */ |
| 799 | rssi0 = (rssi0) ? (-12 - offset0 - rt2x00dev->lna_gain - rssi0) : -128; |
| 800 | rssi1 = (rssi1) ? (-12 - offset1 - rt2x00dev->lna_gain - rssi1) : -128; |
| 801 | rssi2 = (rssi2) ? (-12 - offset2 - rt2x00dev->lna_gain - rssi2) : -128; |
| 802 | |
| 803 | /* |
| 804 | * mac80211 only accepts a single RSSI value. Calculating the |
| 805 | * average doesn't deliver a fair answer either since -60:-60 would |
| 806 | * be considered equally good as -50:-70 while the second is the one |
| 807 | * which gives less energy... |
| 808 | */ |
| 809 | rssi0 = max(rssi0, rssi1); |
Luigi Tarenga | 7fc4175 | 2012-01-31 18:51:23 +0100 | [diff] [blame] | 810 | return (int)max(rssi0, rssi2); |
Ivo van Doorn | 7486192 | 2010-07-11 12:23:50 +0200 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | void rt2800_process_rxwi(struct queue_entry *entry, |
| 814 | struct rxdone_entry_desc *rxdesc) |
| 815 | { |
| 816 | __le32 *rxwi = (__le32 *) entry->skb->data; |
Gertjan van Wingerde | 2de64dd | 2010-05-08 23:40:22 +0200 | [diff] [blame] | 817 | u32 word; |
| 818 | |
| 819 | rt2x00_desc_read(rxwi, 0, &word); |
| 820 | |
| 821 | rxdesc->cipher = rt2x00_get_field32(word, RXWI_W0_UDF); |
| 822 | rxdesc->size = rt2x00_get_field32(word, RXWI_W0_MPDU_TOTAL_BYTE_COUNT); |
| 823 | |
| 824 | rt2x00_desc_read(rxwi, 1, &word); |
| 825 | |
| 826 | if (rt2x00_get_field32(word, RXWI_W1_SHORT_GI)) |
| 827 | rxdesc->flags |= RX_FLAG_SHORT_GI; |
| 828 | |
| 829 | if (rt2x00_get_field32(word, RXWI_W1_BW)) |
| 830 | rxdesc->flags |= RX_FLAG_40MHZ; |
| 831 | |
| 832 | /* |
| 833 | * Detect RX rate, always use MCS as signal type. |
| 834 | */ |
| 835 | rxdesc->dev_flags |= RXDONE_SIGNAL_MCS; |
| 836 | rxdesc->signal = rt2x00_get_field32(word, RXWI_W1_MCS); |
| 837 | rxdesc->rate_mode = rt2x00_get_field32(word, RXWI_W1_PHYMODE); |
| 838 | |
| 839 | /* |
| 840 | * Mask of 0x8 bit to remove the short preamble flag. |
| 841 | */ |
| 842 | if (rxdesc->rate_mode == RATE_MODE_CCK) |
| 843 | rxdesc->signal &= ~0x8; |
| 844 | |
| 845 | rt2x00_desc_read(rxwi, 2, &word); |
| 846 | |
Ivo van Doorn | 7486192 | 2010-07-11 12:23:50 +0200 | [diff] [blame] | 847 | /* |
| 848 | * Convert descriptor AGC value to RSSI value. |
| 849 | */ |
| 850 | rxdesc->rssi = rt2800_agc_to_rssi(entry->queue->rt2x00dev, word); |
Stanislaw Gruszka | f0bda57 | 2013-04-17 14:30:47 +0200 | [diff] [blame] | 851 | /* |
| 852 | * Remove RXWI descriptor from start of the buffer. |
| 853 | */ |
| 854 | skb_pull(entry->skb, entry->queue->winfo_size); |
Gertjan van Wingerde | 2de64dd | 2010-05-08 23:40:22 +0200 | [diff] [blame] | 855 | } |
| 856 | EXPORT_SYMBOL_GPL(rt2800_process_rxwi); |
| 857 | |
Helmut Schaa | 31937c4 | 2011-09-07 20:10:02 +0200 | [diff] [blame] | 858 | void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi) |
Helmut Schaa | 1443333 | 2010-10-02 11:27:03 +0200 | [diff] [blame] | 859 | { |
| 860 | struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; |
Helmut Schaa | b34793e | 2010-10-02 11:34:56 +0200 | [diff] [blame] | 861 | struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); |
Helmut Schaa | 1443333 | 2010-10-02 11:27:03 +0200 | [diff] [blame] | 862 | struct txdone_entry_desc txdesc; |
| 863 | u32 word; |
| 864 | u16 mcs, real_mcs; |
Helmut Schaa | b34793e | 2010-10-02 11:34:56 +0200 | [diff] [blame] | 865 | int aggr, ampdu; |
Helmut Schaa | 1443333 | 2010-10-02 11:27:03 +0200 | [diff] [blame] | 866 | |
| 867 | /* |
| 868 | * Obtain the status about this packet. |
| 869 | */ |
| 870 | txdesc.flags = 0; |
Helmut Schaa | 1443333 | 2010-10-02 11:27:03 +0200 | [diff] [blame] | 871 | rt2x00_desc_read(txwi, 0, &word); |
Helmut Schaa | b34793e | 2010-10-02 11:34:56 +0200 | [diff] [blame] | 872 | |
Helmut Schaa | 1443333 | 2010-10-02 11:27:03 +0200 | [diff] [blame] | 873 | mcs = rt2x00_get_field32(word, TXWI_W0_MCS); |
Helmut Schaa | b34793e | 2010-10-02 11:34:56 +0200 | [diff] [blame] | 874 | ampdu = rt2x00_get_field32(word, TXWI_W0_AMPDU); |
| 875 | |
Helmut Schaa | 1443333 | 2010-10-02 11:27:03 +0200 | [diff] [blame] | 876 | real_mcs = rt2x00_get_field32(status, TX_STA_FIFO_MCS); |
Helmut Schaa | b34793e | 2010-10-02 11:34:56 +0200 | [diff] [blame] | 877 | aggr = rt2x00_get_field32(status, TX_STA_FIFO_TX_AGGRE); |
| 878 | |
| 879 | /* |
| 880 | * If a frame was meant to be sent as a single non-aggregated MPDU |
| 881 | * but ended up in an aggregate the used tx rate doesn't correlate |
| 882 | * with the one specified in the TXWI as the whole aggregate is sent |
| 883 | * with the same rate. |
| 884 | * |
| 885 | * For example: two frames are sent to rt2x00, the first one sets |
| 886 | * AMPDU=1 and requests MCS7 whereas the second frame sets AMDPU=0 |
| 887 | * and requests MCS15. If the hw aggregates both frames into one |
| 888 | * AMDPU the tx status for both frames will contain MCS7 although |
| 889 | * the frame was sent successfully. |
| 890 | * |
| 891 | * Hence, replace the requested rate with the real tx rate to not |
| 892 | * confuse the rate control algortihm by providing clearly wrong |
| 893 | * data. |
| 894 | */ |
Helmut Schaa | 5356d96 | 2011-03-03 19:40:33 +0100 | [diff] [blame] | 895 | if (unlikely(aggr == 1 && ampdu == 0 && real_mcs != mcs)) { |
Helmut Schaa | b34793e | 2010-10-02 11:34:56 +0200 | [diff] [blame] | 896 | skbdesc->tx_rate_idx = real_mcs; |
| 897 | mcs = real_mcs; |
| 898 | } |
Helmut Schaa | 1443333 | 2010-10-02 11:27:03 +0200 | [diff] [blame] | 899 | |
Helmut Schaa | f16d2db | 2011-03-28 13:35:21 +0200 | [diff] [blame] | 900 | if (aggr == 1 || ampdu == 1) |
| 901 | __set_bit(TXDONE_AMPDU, &txdesc.flags); |
| 902 | |
Helmut Schaa | 1443333 | 2010-10-02 11:27:03 +0200 | [diff] [blame] | 903 | /* |
| 904 | * Ralink has a retry mechanism using a global fallback |
| 905 | * table. We setup this fallback table to try the immediate |
| 906 | * lower rate for all rates. In the TX_STA_FIFO, the MCS field |
| 907 | * always contains the MCS used for the last transmission, be |
| 908 | * it successful or not. |
| 909 | */ |
| 910 | if (rt2x00_get_field32(status, TX_STA_FIFO_TX_SUCCESS)) { |
| 911 | /* |
| 912 | * Transmission succeeded. The number of retries is |
| 913 | * mcs - real_mcs |
| 914 | */ |
| 915 | __set_bit(TXDONE_SUCCESS, &txdesc.flags); |
| 916 | txdesc.retry = ((mcs > real_mcs) ? mcs - real_mcs : 0); |
| 917 | } else { |
| 918 | /* |
| 919 | * Transmission failed. The number of retries is |
| 920 | * always 7 in this case (for a total number of 8 |
| 921 | * frames sent). |
| 922 | */ |
| 923 | __set_bit(TXDONE_FAILURE, &txdesc.flags); |
| 924 | txdesc.retry = rt2x00dev->long_retry; |
| 925 | } |
| 926 | |
| 927 | /* |
| 928 | * the frame was retried at least once |
| 929 | * -> hw used fallback rates |
| 930 | */ |
| 931 | if (txdesc.retry) |
| 932 | __set_bit(TXDONE_FALLBACK, &txdesc.flags); |
| 933 | |
| 934 | rt2x00lib_txdone(entry, &txdesc); |
| 935 | } |
| 936 | EXPORT_SYMBOL_GPL(rt2800_txdone_entry); |
| 937 | |
Gabor Juhos | 21c6af6 | 2013-08-22 20:53:21 +0200 | [diff] [blame] | 938 | static unsigned int rt2800_hw_beacon_base(struct rt2x00_dev *rt2x00dev, |
| 939 | unsigned int index) |
| 940 | { |
| 941 | return HW_BEACON_BASE(index); |
| 942 | } |
| 943 | |
Gabor Juhos | 634b805 | 2013-08-22 20:53:22 +0200 | [diff] [blame] | 944 | static inline u8 rt2800_get_beacon_offset(struct rt2x00_dev *rt2x00dev, |
| 945 | unsigned int index) |
| 946 | { |
| 947 | return BEACON_BASE_TO_OFFSET(rt2800_hw_beacon_base(rt2x00dev, index)); |
| 948 | } |
| 949 | |
Stanislaw Gruszka | ba08910 | 2014-06-05 13:52:24 +0200 | [diff] [blame] | 950 | static void rt2800_update_beacons_setup(struct rt2x00_dev *rt2x00dev) |
| 951 | { |
| 952 | struct data_queue *queue = rt2x00dev->bcn; |
| 953 | struct queue_entry *entry; |
| 954 | int i, bcn_num = 0; |
| 955 | u64 off, reg = 0; |
| 956 | u32 bssid_dw1; |
| 957 | |
| 958 | /* |
| 959 | * Setup offsets of all active beacons in BCN_OFFSET{0,1} registers. |
| 960 | */ |
| 961 | for (i = 0; i < queue->limit; i++) { |
| 962 | entry = &queue->entries[i]; |
| 963 | if (!test_bit(ENTRY_BCN_ENABLED, &entry->flags)) |
| 964 | continue; |
| 965 | off = rt2800_get_beacon_offset(rt2x00dev, entry->entry_idx); |
| 966 | reg |= off << (8 * bcn_num); |
| 967 | bcn_num++; |
| 968 | } |
| 969 | |
| 970 | WARN_ON_ONCE(bcn_num != rt2x00dev->intf_beaconing); |
| 971 | |
| 972 | rt2800_register_write(rt2x00dev, BCN_OFFSET0, (u32) reg); |
| 973 | rt2800_register_write(rt2x00dev, BCN_OFFSET1, (u32) (reg >> 32)); |
| 974 | |
| 975 | /* |
| 976 | * H/W sends up to MAC_BSSID_DW1_BSS_BCN_NUM + 1 consecutive beacons. |
| 977 | */ |
| 978 | rt2800_register_read(rt2x00dev, MAC_BSSID_DW1, &bssid_dw1); |
| 979 | rt2x00_set_field32(&bssid_dw1, MAC_BSSID_DW1_BSS_BCN_NUM, |
| 980 | bcn_num > 0 ? bcn_num - 1 : 0); |
| 981 | rt2800_register_write(rt2x00dev, MAC_BSSID_DW1, bssid_dw1); |
| 982 | } |
| 983 | |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 984 | void rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc) |
| 985 | { |
| 986 | struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; |
| 987 | struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); |
| 988 | unsigned int beacon_base; |
Wolfgang Kufner | 739fd94 | 2010-12-13 12:39:12 +0100 | [diff] [blame] | 989 | unsigned int padding_len; |
Seth Forshee | d76dfc6 | 2011-02-14 08:52:25 -0600 | [diff] [blame] | 990 | u32 orig_reg, reg; |
Stanislaw Gruszka | f0bda57 | 2013-04-17 14:30:47 +0200 | [diff] [blame] | 991 | const int txwi_desc_size = entry->queue->winfo_size; |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 992 | |
| 993 | /* |
| 994 | * Disable beaconing while we are reloading the beacon data, |
| 995 | * otherwise we might be sending out invalid data. |
| 996 | */ |
| 997 | rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®); |
Seth Forshee | d76dfc6 | 2011-02-14 08:52:25 -0600 | [diff] [blame] | 998 | orig_reg = reg; |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 999 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 0); |
| 1000 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
| 1001 | |
| 1002 | /* |
| 1003 | * Add space for the TXWI in front of the skb. |
| 1004 | */ |
Stanislaw Gruszka | f0bda57 | 2013-04-17 14:30:47 +0200 | [diff] [blame] | 1005 | memset(skb_push(entry->skb, txwi_desc_size), 0, txwi_desc_size); |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 1006 | |
| 1007 | /* |
| 1008 | * Register descriptor details in skb frame descriptor. |
| 1009 | */ |
| 1010 | skbdesc->flags |= SKBDESC_DESC_IN_SKB; |
| 1011 | skbdesc->desc = entry->skb->data; |
Stanislaw Gruszka | f0bda57 | 2013-04-17 14:30:47 +0200 | [diff] [blame] | 1012 | skbdesc->desc_len = txwi_desc_size; |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 1013 | |
| 1014 | /* |
| 1015 | * Add the TXWI for the beacon to the skb. |
| 1016 | */ |
Ivo van Doorn | 0c5879b | 2010-08-06 20:47:20 +0200 | [diff] [blame] | 1017 | rt2800_write_tx_data(entry, txdesc); |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 1018 | |
| 1019 | /* |
| 1020 | * Dump beacon to userspace through debugfs. |
| 1021 | */ |
| 1022 | rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry->skb); |
| 1023 | |
| 1024 | /* |
Wolfgang Kufner | 739fd94 | 2010-12-13 12:39:12 +0100 | [diff] [blame] | 1025 | * Write entire beacon with TXWI and padding to register. |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 1026 | */ |
Wolfgang Kufner | 739fd94 | 2010-12-13 12:39:12 +0100 | [diff] [blame] | 1027 | padding_len = roundup(entry->skb->len, 4) - entry->skb->len; |
Seth Forshee | d76dfc6 | 2011-02-14 08:52:25 -0600 | [diff] [blame] | 1028 | if (padding_len && skb_pad(entry->skb, padding_len)) { |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 1029 | rt2x00_err(rt2x00dev, "Failure padding beacon, aborting\n"); |
Seth Forshee | d76dfc6 | 2011-02-14 08:52:25 -0600 | [diff] [blame] | 1030 | /* skb freed by skb_pad() on failure */ |
| 1031 | entry->skb = NULL; |
| 1032 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, orig_reg); |
| 1033 | return; |
| 1034 | } |
| 1035 | |
Gabor Juhos | 21c6af6 | 2013-08-22 20:53:21 +0200 | [diff] [blame] | 1036 | beacon_base = rt2800_hw_beacon_base(rt2x00dev, entry->entry_idx); |
| 1037 | |
Wolfgang Kufner | 739fd94 | 2010-12-13 12:39:12 +0100 | [diff] [blame] | 1038 | rt2800_register_multiwrite(rt2x00dev, beacon_base, entry->skb->data, |
| 1039 | entry->skb->len + padding_len); |
Stanislaw Gruszka | ba08910 | 2014-06-05 13:52:24 +0200 | [diff] [blame] | 1040 | __set_bit(ENTRY_BCN_ENABLED, &entry->flags); |
| 1041 | |
| 1042 | /* |
| 1043 | * Change global beacons settings. |
| 1044 | */ |
| 1045 | rt2800_update_beacons_setup(rt2x00dev); |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 1046 | |
| 1047 | /* |
Stanislaw Gruszka | bc0df75a | 2014-04-17 11:08:48 +0200 | [diff] [blame] | 1048 | * Restore beaconing state. |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 1049 | */ |
Stanislaw Gruszka | bc0df75a | 2014-04-17 11:08:48 +0200 | [diff] [blame] | 1050 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, orig_reg); |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 1051 | |
| 1052 | /* |
| 1053 | * Clean up beacon skb. |
| 1054 | */ |
| 1055 | dev_kfree_skb_any(entry->skb); |
| 1056 | entry->skb = NULL; |
| 1057 | } |
Ivo van Doorn | 50e888e | 2010-07-11 12:26:12 +0200 | [diff] [blame] | 1058 | EXPORT_SYMBOL_GPL(rt2800_write_beacon); |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 1059 | |
Helmut Schaa | 69cf36a | 2011-01-30 13:16:03 +0100 | [diff] [blame] | 1060 | static inline void rt2800_clear_beacon_register(struct rt2x00_dev *rt2x00dev, |
Gabor Juhos | 77f7c0f | 2013-08-17 00:15:50 +0200 | [diff] [blame] | 1061 | unsigned int index) |
Helmut Schaa | fdb8725 | 2010-06-29 21:48:06 +0200 | [diff] [blame] | 1062 | { |
| 1063 | int i; |
Gabor Juhos | 0879f87 | 2013-05-01 17:17:33 +0200 | [diff] [blame] | 1064 | const int txwi_desc_size = rt2x00dev->bcn->winfo_size; |
Gabor Juhos | 77f7c0f | 2013-08-17 00:15:50 +0200 | [diff] [blame] | 1065 | unsigned int beacon_base; |
| 1066 | |
Gabor Juhos | 21c6af6 | 2013-08-22 20:53:21 +0200 | [diff] [blame] | 1067 | beacon_base = rt2800_hw_beacon_base(rt2x00dev, index); |
Helmut Schaa | fdb8725 | 2010-06-29 21:48:06 +0200 | [diff] [blame] | 1068 | |
| 1069 | /* |
| 1070 | * For the Beacon base registers we only need to clear |
| 1071 | * the whole TXWI which (when set to 0) will invalidate |
| 1072 | * the entire beacon. |
| 1073 | */ |
Stanislaw Gruszka | f0bda57 | 2013-04-17 14:30:47 +0200 | [diff] [blame] | 1074 | for (i = 0; i < txwi_desc_size; i += sizeof(__le32)) |
Helmut Schaa | fdb8725 | 2010-06-29 21:48:06 +0200 | [diff] [blame] | 1075 | rt2800_register_write(rt2x00dev, beacon_base + i, 0); |
| 1076 | } |
| 1077 | |
Helmut Schaa | 69cf36a | 2011-01-30 13:16:03 +0100 | [diff] [blame] | 1078 | void rt2800_clear_beacon(struct queue_entry *entry) |
| 1079 | { |
| 1080 | struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; |
Stanislaw Gruszka | bc0df75a | 2014-04-17 11:08:48 +0200 | [diff] [blame] | 1081 | u32 orig_reg, reg; |
Helmut Schaa | 69cf36a | 2011-01-30 13:16:03 +0100 | [diff] [blame] | 1082 | |
| 1083 | /* |
| 1084 | * Disable beaconing while we are reloading the beacon data, |
| 1085 | * otherwise we might be sending out invalid data. |
| 1086 | */ |
Stanislaw Gruszka | bc0df75a | 2014-04-17 11:08:48 +0200 | [diff] [blame] | 1087 | rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &orig_reg); |
| 1088 | reg = orig_reg; |
Helmut Schaa | 69cf36a | 2011-01-30 13:16:03 +0100 | [diff] [blame] | 1089 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 0); |
| 1090 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
| 1091 | |
| 1092 | /* |
| 1093 | * Clear beacon. |
| 1094 | */ |
Gabor Juhos | 77f7c0f | 2013-08-17 00:15:50 +0200 | [diff] [blame] | 1095 | rt2800_clear_beacon_register(rt2x00dev, entry->entry_idx); |
Stanislaw Gruszka | ba08910 | 2014-06-05 13:52:24 +0200 | [diff] [blame] | 1096 | __clear_bit(ENTRY_BCN_ENABLED, &entry->flags); |
Helmut Schaa | 69cf36a | 2011-01-30 13:16:03 +0100 | [diff] [blame] | 1097 | |
| 1098 | /* |
Stanislaw Gruszka | ba08910 | 2014-06-05 13:52:24 +0200 | [diff] [blame] | 1099 | * Change global beacons settings. |
| 1100 | */ |
| 1101 | rt2800_update_beacons_setup(rt2x00dev); |
| 1102 | /* |
Stanislaw Gruszka | bc0df75a | 2014-04-17 11:08:48 +0200 | [diff] [blame] | 1103 | * Restore beaconing state. |
Helmut Schaa | 69cf36a | 2011-01-30 13:16:03 +0100 | [diff] [blame] | 1104 | */ |
Stanislaw Gruszka | bc0df75a | 2014-04-17 11:08:48 +0200 | [diff] [blame] | 1105 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, orig_reg); |
Helmut Schaa | 69cf36a | 2011-01-30 13:16:03 +0100 | [diff] [blame] | 1106 | } |
| 1107 | EXPORT_SYMBOL_GPL(rt2800_clear_beacon); |
| 1108 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1109 | #ifdef CONFIG_RT2X00_LIB_DEBUGFS |
| 1110 | const struct rt2x00debug rt2800_rt2x00debug = { |
| 1111 | .owner = THIS_MODULE, |
| 1112 | .csr = { |
| 1113 | .read = rt2800_register_read, |
| 1114 | .write = rt2800_register_write, |
| 1115 | .flags = RT2X00DEBUGFS_OFFSET, |
| 1116 | .word_base = CSR_REG_BASE, |
| 1117 | .word_size = sizeof(u32), |
| 1118 | .word_count = CSR_REG_SIZE / sizeof(u32), |
| 1119 | }, |
| 1120 | .eeprom = { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 1121 | /* NOTE: The local EEPROM access functions can't |
| 1122 | * be used here, use the generic versions instead. |
| 1123 | */ |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1124 | .read = rt2x00_eeprom_read, |
| 1125 | .write = rt2x00_eeprom_write, |
| 1126 | .word_base = EEPROM_BASE, |
| 1127 | .word_size = sizeof(u16), |
| 1128 | .word_count = EEPROM_SIZE / sizeof(u16), |
| 1129 | }, |
| 1130 | .bbp = { |
| 1131 | .read = rt2800_bbp_read, |
| 1132 | .write = rt2800_bbp_write, |
| 1133 | .word_base = BBP_BASE, |
| 1134 | .word_size = sizeof(u8), |
| 1135 | .word_count = BBP_SIZE / sizeof(u8), |
| 1136 | }, |
| 1137 | .rf = { |
| 1138 | .read = rt2x00_rf_read, |
| 1139 | .write = rt2800_rf_write, |
| 1140 | .word_base = RF_BASE, |
| 1141 | .word_size = sizeof(u32), |
| 1142 | .word_count = RF_SIZE / sizeof(u32), |
| 1143 | }, |
Anisse Astier | f2bd7f1 | 2012-04-19 15:53:10 +0200 | [diff] [blame] | 1144 | .rfcsr = { |
| 1145 | .read = rt2800_rfcsr_read, |
| 1146 | .write = rt2800_rfcsr_write, |
| 1147 | .word_base = RFCSR_BASE, |
| 1148 | .word_size = sizeof(u8), |
| 1149 | .word_count = RFCSR_SIZE / sizeof(u8), |
| 1150 | }, |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1151 | }; |
| 1152 | EXPORT_SYMBOL_GPL(rt2800_rt2x00debug); |
| 1153 | #endif /* CONFIG_RT2X00_LIB_DEBUGFS */ |
| 1154 | |
| 1155 | int rt2800_rfkill_poll(struct rt2x00_dev *rt2x00dev) |
| 1156 | { |
| 1157 | u32 reg; |
| 1158 | |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 1159 | if (rt2x00_rt(rt2x00dev, RT3290)) { |
| 1160 | rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, ®); |
| 1161 | return rt2x00_get_field32(reg, WLAN_GPIO_IN_BIT0); |
| 1162 | } else { |
Gertjan van Wingerde | 99bdf51 | 2012-08-31 19:22:13 +0200 | [diff] [blame] | 1163 | rt2800_register_read(rt2x00dev, GPIO_CTRL, ®); |
| 1164 | return rt2x00_get_field32(reg, GPIO_CTRL_VAL2); |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 1165 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1166 | } |
| 1167 | EXPORT_SYMBOL_GPL(rt2800_rfkill_poll); |
| 1168 | |
| 1169 | #ifdef CONFIG_RT2X00_LIB_LEDS |
| 1170 | static void rt2800_brightness_set(struct led_classdev *led_cdev, |
| 1171 | enum led_brightness brightness) |
| 1172 | { |
| 1173 | struct rt2x00_led *led = |
| 1174 | container_of(led_cdev, struct rt2x00_led, led_dev); |
| 1175 | unsigned int enabled = brightness != LED_OFF; |
| 1176 | unsigned int bg_mode = |
| 1177 | (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_2GHZ); |
| 1178 | unsigned int polarity = |
| 1179 | rt2x00_get_field16(led->rt2x00dev->led_mcu_reg, |
| 1180 | EEPROM_FREQ_LED_POLARITY); |
| 1181 | unsigned int ledmode = |
| 1182 | rt2x00_get_field16(led->rt2x00dev->led_mcu_reg, |
| 1183 | EEPROM_FREQ_LED_MODE); |
Layne Edwards | 44704e5 | 2011-04-18 15:26:00 +0200 | [diff] [blame] | 1184 | u32 reg; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1185 | |
Layne Edwards | 44704e5 | 2011-04-18 15:26:00 +0200 | [diff] [blame] | 1186 | /* Check for SoC (SOC devices don't support MCU requests) */ |
| 1187 | if (rt2x00_is_soc(led->rt2x00dev)) { |
| 1188 | rt2800_register_read(led->rt2x00dev, LED_CFG, ®); |
| 1189 | |
| 1190 | /* Set LED Polarity */ |
| 1191 | rt2x00_set_field32(®, LED_CFG_LED_POLAR, polarity); |
| 1192 | |
| 1193 | /* Set LED Mode */ |
| 1194 | if (led->type == LED_TYPE_RADIO) { |
| 1195 | rt2x00_set_field32(®, LED_CFG_G_LED_MODE, |
| 1196 | enabled ? 3 : 0); |
| 1197 | } else if (led->type == LED_TYPE_ASSOC) { |
| 1198 | rt2x00_set_field32(®, LED_CFG_Y_LED_MODE, |
| 1199 | enabled ? 3 : 0); |
| 1200 | } else if (led->type == LED_TYPE_QUALITY) { |
| 1201 | rt2x00_set_field32(®, LED_CFG_R_LED_MODE, |
| 1202 | enabled ? 3 : 0); |
| 1203 | } |
| 1204 | |
| 1205 | rt2800_register_write(led->rt2x00dev, LED_CFG, reg); |
| 1206 | |
| 1207 | } else { |
| 1208 | if (led->type == LED_TYPE_RADIO) { |
| 1209 | rt2800_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode, |
| 1210 | enabled ? 0x20 : 0); |
| 1211 | } else if (led->type == LED_TYPE_ASSOC) { |
| 1212 | rt2800_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode, |
| 1213 | enabled ? (bg_mode ? 0x60 : 0xa0) : 0x20); |
| 1214 | } else if (led->type == LED_TYPE_QUALITY) { |
| 1215 | /* |
| 1216 | * The brightness is divided into 6 levels (0 - 5), |
| 1217 | * The specs tell us the following levels: |
| 1218 | * 0, 1 ,3, 7, 15, 31 |
| 1219 | * to determine the level in a simple way we can simply |
| 1220 | * work with bitshifting: |
| 1221 | * (1 << level) - 1 |
| 1222 | */ |
| 1223 | rt2800_mcu_request(led->rt2x00dev, MCU_LED_STRENGTH, 0xff, |
| 1224 | (1 << brightness / (LED_FULL / 6)) - 1, |
| 1225 | polarity); |
| 1226 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1227 | } |
| 1228 | } |
| 1229 | |
Gertjan van Wingerde | b3579d6 | 2009-12-30 11:36:34 +0100 | [diff] [blame] | 1230 | static void rt2800_init_led(struct rt2x00_dev *rt2x00dev, |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1231 | struct rt2x00_led *led, enum led_type type) |
| 1232 | { |
| 1233 | led->rt2x00dev = rt2x00dev; |
| 1234 | led->type = type; |
| 1235 | led->led_dev.brightness_set = rt2800_brightness_set; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1236 | led->flags = LED_INITIALIZED; |
| 1237 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1238 | #endif /* CONFIG_RT2X00_LIB_LEDS */ |
| 1239 | |
| 1240 | /* |
| 1241 | * Configuration handlers. |
| 1242 | */ |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1243 | static void rt2800_config_wcid(struct rt2x00_dev *rt2x00dev, |
| 1244 | const u8 *address, |
| 1245 | int wcid) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1246 | { |
| 1247 | struct mac_wcid_entry wcid_entry; |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1248 | u32 offset; |
| 1249 | |
| 1250 | offset = MAC_WCID_ENTRY(wcid); |
| 1251 | |
| 1252 | memset(&wcid_entry, 0xff, sizeof(wcid_entry)); |
| 1253 | if (address) |
| 1254 | memcpy(wcid_entry.mac, address, ETH_ALEN); |
| 1255 | |
| 1256 | rt2800_register_multiwrite(rt2x00dev, offset, |
| 1257 | &wcid_entry, sizeof(wcid_entry)); |
| 1258 | } |
| 1259 | |
| 1260 | static void rt2800_delete_wcid_attr(struct rt2x00_dev *rt2x00dev, int wcid) |
| 1261 | { |
| 1262 | u32 offset; |
| 1263 | offset = MAC_WCID_ATTR_ENTRY(wcid); |
| 1264 | rt2800_register_write(rt2x00dev, offset, 0); |
| 1265 | } |
| 1266 | |
| 1267 | static void rt2800_config_wcid_attr_bssidx(struct rt2x00_dev *rt2x00dev, |
| 1268 | int wcid, u32 bssidx) |
| 1269 | { |
| 1270 | u32 offset = MAC_WCID_ATTR_ENTRY(wcid); |
| 1271 | u32 reg; |
| 1272 | |
| 1273 | /* |
| 1274 | * The BSS Idx numbers is split in a main value of 3 bits, |
| 1275 | * and a extended field for adding one additional bit to the value. |
| 1276 | */ |
| 1277 | rt2800_register_read(rt2x00dev, offset, ®); |
| 1278 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_BSS_IDX, (bssidx & 0x7)); |
| 1279 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_BSS_IDX_EXT, |
| 1280 | (bssidx & 0x8) >> 3); |
| 1281 | rt2800_register_write(rt2x00dev, offset, reg); |
| 1282 | } |
| 1283 | |
| 1284 | static void rt2800_config_wcid_attr_cipher(struct rt2x00_dev *rt2x00dev, |
| 1285 | struct rt2x00lib_crypto *crypto, |
| 1286 | struct ieee80211_key_conf *key) |
| 1287 | { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1288 | struct mac_iveiv_entry iveiv_entry; |
| 1289 | u32 offset; |
| 1290 | u32 reg; |
| 1291 | |
| 1292 | offset = MAC_WCID_ATTR_ENTRY(key->hw_key_idx); |
| 1293 | |
Ivo van Doorn | e4a0ab3 | 2010-06-14 22:14:19 +0200 | [diff] [blame] | 1294 | if (crypto->cmd == SET_KEY) { |
| 1295 | rt2800_register_read(rt2x00dev, offset, ®); |
| 1296 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_KEYTAB, |
| 1297 | !!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)); |
| 1298 | /* |
| 1299 | * Both the cipher as the BSS Idx numbers are split in a main |
| 1300 | * value of 3 bits, and a extended field for adding one additional |
| 1301 | * bit to the value. |
| 1302 | */ |
| 1303 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_CIPHER, |
| 1304 | (crypto->cipher & 0x7)); |
| 1305 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_CIPHER_EXT, |
| 1306 | (crypto->cipher & 0x8) >> 3); |
Ivo van Doorn | e4a0ab3 | 2010-06-14 22:14:19 +0200 | [diff] [blame] | 1307 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_RX_WIUDF, crypto->cipher); |
| 1308 | rt2800_register_write(rt2x00dev, offset, reg); |
| 1309 | } else { |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1310 | /* Delete the cipher without touching the bssidx */ |
| 1311 | rt2800_register_read(rt2x00dev, offset, ®); |
| 1312 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_KEYTAB, 0); |
| 1313 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_CIPHER, 0); |
| 1314 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_CIPHER_EXT, 0); |
| 1315 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_RX_WIUDF, 0); |
| 1316 | rt2800_register_write(rt2x00dev, offset, reg); |
Ivo van Doorn | e4a0ab3 | 2010-06-14 22:14:19 +0200 | [diff] [blame] | 1317 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1318 | |
| 1319 | offset = MAC_IVEIV_ENTRY(key->hw_key_idx); |
| 1320 | |
| 1321 | memset(&iveiv_entry, 0, sizeof(iveiv_entry)); |
| 1322 | if ((crypto->cipher == CIPHER_TKIP) || |
| 1323 | (crypto->cipher == CIPHER_TKIP_NO_MIC) || |
| 1324 | (crypto->cipher == CIPHER_AES)) |
| 1325 | iveiv_entry.iv[3] |= 0x20; |
| 1326 | iveiv_entry.iv[3] |= key->keyidx << 6; |
| 1327 | rt2800_register_multiwrite(rt2x00dev, offset, |
| 1328 | &iveiv_entry, sizeof(iveiv_entry)); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | int rt2800_config_shared_key(struct rt2x00_dev *rt2x00dev, |
| 1332 | struct rt2x00lib_crypto *crypto, |
| 1333 | struct ieee80211_key_conf *key) |
| 1334 | { |
| 1335 | struct hw_key_entry key_entry; |
| 1336 | struct rt2x00_field32 field; |
| 1337 | u32 offset; |
| 1338 | u32 reg; |
| 1339 | |
| 1340 | if (crypto->cmd == SET_KEY) { |
| 1341 | key->hw_key_idx = (4 * crypto->bssidx) + key->keyidx; |
| 1342 | |
| 1343 | memcpy(key_entry.key, crypto->key, |
| 1344 | sizeof(key_entry.key)); |
| 1345 | memcpy(key_entry.tx_mic, crypto->tx_mic, |
| 1346 | sizeof(key_entry.tx_mic)); |
| 1347 | memcpy(key_entry.rx_mic, crypto->rx_mic, |
| 1348 | sizeof(key_entry.rx_mic)); |
| 1349 | |
| 1350 | offset = SHARED_KEY_ENTRY(key->hw_key_idx); |
| 1351 | rt2800_register_multiwrite(rt2x00dev, offset, |
| 1352 | &key_entry, sizeof(key_entry)); |
| 1353 | } |
| 1354 | |
| 1355 | /* |
| 1356 | * The cipher types are stored over multiple registers |
| 1357 | * starting with SHARED_KEY_MODE_BASE each word will have |
| 1358 | * 32 bits and contains the cipher types for 2 bssidx each. |
| 1359 | * Using the correct defines correctly will cause overhead, |
| 1360 | * so just calculate the correct offset. |
| 1361 | */ |
| 1362 | field.bit_offset = 4 * (key->hw_key_idx % 8); |
| 1363 | field.bit_mask = 0x7 << field.bit_offset; |
| 1364 | |
| 1365 | offset = SHARED_KEY_MODE_ENTRY(key->hw_key_idx / 8); |
| 1366 | |
| 1367 | rt2800_register_read(rt2x00dev, offset, ®); |
| 1368 | rt2x00_set_field32(®, field, |
| 1369 | (crypto->cmd == SET_KEY) * crypto->cipher); |
| 1370 | rt2800_register_write(rt2x00dev, offset, reg); |
| 1371 | |
| 1372 | /* |
| 1373 | * Update WCID information |
| 1374 | */ |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1375 | rt2800_config_wcid(rt2x00dev, crypto->address, key->hw_key_idx); |
| 1376 | rt2800_config_wcid_attr_bssidx(rt2x00dev, key->hw_key_idx, |
| 1377 | crypto->bssidx); |
| 1378 | rt2800_config_wcid_attr_cipher(rt2x00dev, crypto, key); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1379 | |
| 1380 | return 0; |
| 1381 | } |
| 1382 | EXPORT_SYMBOL_GPL(rt2800_config_shared_key); |
| 1383 | |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1384 | static inline int rt2800_find_wcid(struct rt2x00_dev *rt2x00dev) |
Helmut Schaa | 1ed3811 | 2011-03-03 19:44:33 +0100 | [diff] [blame] | 1385 | { |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1386 | struct mac_wcid_entry wcid_entry; |
Helmut Schaa | 1ed3811 | 2011-03-03 19:44:33 +0100 | [diff] [blame] | 1387 | int idx; |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1388 | u32 offset; |
Helmut Schaa | 1ed3811 | 2011-03-03 19:44:33 +0100 | [diff] [blame] | 1389 | |
| 1390 | /* |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1391 | * Search for the first free WCID entry and return the corresponding |
| 1392 | * index. |
Helmut Schaa | 1ed3811 | 2011-03-03 19:44:33 +0100 | [diff] [blame] | 1393 | * |
| 1394 | * Make sure the WCID starts _after_ the last possible shared key |
| 1395 | * entry (>32). |
| 1396 | * |
| 1397 | * Since parts of the pairwise key table might be shared with |
| 1398 | * the beacon frame buffers 6 & 7 we should only write into the |
| 1399 | * first 222 entries. |
| 1400 | */ |
| 1401 | for (idx = 33; idx <= 222; idx++) { |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1402 | offset = MAC_WCID_ENTRY(idx); |
| 1403 | rt2800_register_multiread(rt2x00dev, offset, &wcid_entry, |
| 1404 | sizeof(wcid_entry)); |
| 1405 | if (is_broadcast_ether_addr(wcid_entry.mac)) |
Helmut Schaa | 1ed3811 | 2011-03-03 19:44:33 +0100 | [diff] [blame] | 1406 | return idx; |
| 1407 | } |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1408 | |
| 1409 | /* |
| 1410 | * Use -1 to indicate that we don't have any more space in the WCID |
| 1411 | * table. |
| 1412 | */ |
Helmut Schaa | 1ed3811 | 2011-03-03 19:44:33 +0100 | [diff] [blame] | 1413 | return -1; |
| 1414 | } |
| 1415 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1416 | int rt2800_config_pairwise_key(struct rt2x00_dev *rt2x00dev, |
| 1417 | struct rt2x00lib_crypto *crypto, |
| 1418 | struct ieee80211_key_conf *key) |
| 1419 | { |
| 1420 | struct hw_key_entry key_entry; |
| 1421 | u32 offset; |
| 1422 | |
| 1423 | if (crypto->cmd == SET_KEY) { |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1424 | /* |
| 1425 | * Allow key configuration only for STAs that are |
| 1426 | * known by the hw. |
| 1427 | */ |
| 1428 | if (crypto->wcid < 0) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1429 | return -ENOSPC; |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1430 | key->hw_key_idx = crypto->wcid; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1431 | |
| 1432 | memcpy(key_entry.key, crypto->key, |
| 1433 | sizeof(key_entry.key)); |
| 1434 | memcpy(key_entry.tx_mic, crypto->tx_mic, |
| 1435 | sizeof(key_entry.tx_mic)); |
| 1436 | memcpy(key_entry.rx_mic, crypto->rx_mic, |
| 1437 | sizeof(key_entry.rx_mic)); |
| 1438 | |
| 1439 | offset = PAIRWISE_KEY_ENTRY(key->hw_key_idx); |
| 1440 | rt2800_register_multiwrite(rt2x00dev, offset, |
| 1441 | &key_entry, sizeof(key_entry)); |
| 1442 | } |
| 1443 | |
| 1444 | /* |
| 1445 | * Update WCID information |
| 1446 | */ |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1447 | rt2800_config_wcid_attr_cipher(rt2x00dev, crypto, key); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1448 | |
| 1449 | return 0; |
| 1450 | } |
| 1451 | EXPORT_SYMBOL_GPL(rt2800_config_pairwise_key); |
| 1452 | |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1453 | int rt2800_sta_add(struct rt2x00_dev *rt2x00dev, struct ieee80211_vif *vif, |
| 1454 | struct ieee80211_sta *sta) |
| 1455 | { |
| 1456 | int wcid; |
| 1457 | struct rt2x00_sta *sta_priv = sta_to_rt2x00_sta(sta); |
| 1458 | |
| 1459 | /* |
| 1460 | * Find next free WCID. |
| 1461 | */ |
| 1462 | wcid = rt2800_find_wcid(rt2x00dev); |
| 1463 | |
| 1464 | /* |
| 1465 | * Store selected wcid even if it is invalid so that we can |
| 1466 | * later decide if the STA is uploaded into the hw. |
| 1467 | */ |
| 1468 | sta_priv->wcid = wcid; |
| 1469 | |
| 1470 | /* |
| 1471 | * No space left in the device, however, we can still communicate |
| 1472 | * with the STA -> No error. |
| 1473 | */ |
| 1474 | if (wcid < 0) |
| 1475 | return 0; |
| 1476 | |
| 1477 | /* |
| 1478 | * Clean up WCID attributes and write STA address to the device. |
| 1479 | */ |
| 1480 | rt2800_delete_wcid_attr(rt2x00dev, wcid); |
| 1481 | rt2800_config_wcid(rt2x00dev, sta->addr, wcid); |
| 1482 | rt2800_config_wcid_attr_bssidx(rt2x00dev, wcid, |
| 1483 | rt2x00lib_get_bssidx(rt2x00dev, vif)); |
| 1484 | return 0; |
| 1485 | } |
| 1486 | EXPORT_SYMBOL_GPL(rt2800_sta_add); |
| 1487 | |
| 1488 | int rt2800_sta_remove(struct rt2x00_dev *rt2x00dev, int wcid) |
| 1489 | { |
| 1490 | /* |
| 1491 | * Remove WCID entry, no need to clean the attributes as they will |
| 1492 | * get renewed when the WCID is reused. |
| 1493 | */ |
| 1494 | rt2800_config_wcid(rt2x00dev, NULL, wcid); |
| 1495 | |
| 1496 | return 0; |
| 1497 | } |
| 1498 | EXPORT_SYMBOL_GPL(rt2800_sta_remove); |
| 1499 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1500 | void rt2800_config_filter(struct rt2x00_dev *rt2x00dev, |
| 1501 | const unsigned int filter_flags) |
| 1502 | { |
| 1503 | u32 reg; |
| 1504 | |
| 1505 | /* |
| 1506 | * Start configuration steps. |
| 1507 | * Note that the version error will always be dropped |
| 1508 | * and broadcast frames will always be accepted since |
| 1509 | * there is no filter for it at this time. |
| 1510 | */ |
| 1511 | rt2800_register_read(rt2x00dev, RX_FILTER_CFG, ®); |
| 1512 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CRC_ERROR, |
| 1513 | !(filter_flags & FIF_FCSFAIL)); |
| 1514 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_PHY_ERROR, |
| 1515 | !(filter_flags & FIF_PLCPFAIL)); |
Johannes Berg | df14046 | 2015-04-22 14:40:58 +0200 | [diff] [blame] | 1516 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_NOT_TO_ME, 1); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1517 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_NOT_MY_BSSD, 0); |
| 1518 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_VER_ERROR, 1); |
| 1519 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_MULTICAST, |
| 1520 | !(filter_flags & FIF_ALLMULTI)); |
| 1521 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_BROADCAST, 0); |
| 1522 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_DUPLICATE, 1); |
| 1523 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CF_END_ACK, |
| 1524 | !(filter_flags & FIF_CONTROL)); |
| 1525 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CF_END, |
| 1526 | !(filter_flags & FIF_CONTROL)); |
| 1527 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_ACK, |
| 1528 | !(filter_flags & FIF_CONTROL)); |
| 1529 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CTS, |
| 1530 | !(filter_flags & FIF_CONTROL)); |
| 1531 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_RTS, |
| 1532 | !(filter_flags & FIF_CONTROL)); |
| 1533 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_PSPOLL, |
| 1534 | !(filter_flags & FIF_PSPOLL)); |
Helmut Schaa | 84e9e8ebd | 2013-01-17 17:34:32 +0100 | [diff] [blame] | 1535 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_BA, 0); |
Helmut Schaa | 4883993 | 2011-11-24 09:13:26 +0100 | [diff] [blame] | 1536 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_BAR, |
| 1537 | !(filter_flags & FIF_CONTROL)); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1538 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CNTL, |
| 1539 | !(filter_flags & FIF_CONTROL)); |
| 1540 | rt2800_register_write(rt2x00dev, RX_FILTER_CFG, reg); |
| 1541 | } |
| 1542 | EXPORT_SYMBOL_GPL(rt2800_config_filter); |
| 1543 | |
| 1544 | void rt2800_config_intf(struct rt2x00_dev *rt2x00dev, struct rt2x00_intf *intf, |
| 1545 | struct rt2x00intf_conf *conf, const unsigned int flags) |
| 1546 | { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1547 | u32 reg; |
Helmut Schaa | fa8b4b2 | 2010-11-04 20:42:36 +0100 | [diff] [blame] | 1548 | bool update_bssid = false; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1549 | |
| 1550 | if (flags & CONFIG_UPDATE_TYPE) { |
| 1551 | /* |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1552 | * Enable synchronisation. |
| 1553 | */ |
| 1554 | rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1555 | rt2x00_set_field32(®, BCN_TIME_CFG_TSF_SYNC, conf->sync); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1556 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
Helmut Schaa | 15a533c | 2011-04-18 15:28:04 +0200 | [diff] [blame] | 1557 | |
| 1558 | if (conf->sync == TSF_SYNC_AP_NONE) { |
| 1559 | /* |
| 1560 | * Tune beacon queue transmit parameters for AP mode |
| 1561 | */ |
| 1562 | rt2800_register_read(rt2x00dev, TBTT_SYNC_CFG, ®); |
| 1563 | rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_CWMIN, 0); |
| 1564 | rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_AIFSN, 1); |
| 1565 | rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_EXP_WIN, 32); |
| 1566 | rt2x00_set_field32(®, TBTT_SYNC_CFG_TBTT_ADJUST, 0); |
| 1567 | rt2800_register_write(rt2x00dev, TBTT_SYNC_CFG, reg); |
| 1568 | } else { |
| 1569 | rt2800_register_read(rt2x00dev, TBTT_SYNC_CFG, ®); |
| 1570 | rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_CWMIN, 4); |
| 1571 | rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_AIFSN, 2); |
| 1572 | rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_EXP_WIN, 32); |
| 1573 | rt2x00_set_field32(®, TBTT_SYNC_CFG_TBTT_ADJUST, 16); |
| 1574 | rt2800_register_write(rt2x00dev, TBTT_SYNC_CFG, reg); |
| 1575 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | if (flags & CONFIG_UPDATE_MAC) { |
Helmut Schaa | fa8b4b2 | 2010-11-04 20:42:36 +0100 | [diff] [blame] | 1579 | if (flags & CONFIG_UPDATE_TYPE && |
| 1580 | conf->sync == TSF_SYNC_AP_NONE) { |
| 1581 | /* |
| 1582 | * The BSSID register has to be set to our own mac |
| 1583 | * address in AP mode. |
| 1584 | */ |
| 1585 | memcpy(conf->bssid, conf->mac, sizeof(conf->mac)); |
| 1586 | update_bssid = true; |
| 1587 | } |
| 1588 | |
Ivo van Doorn | c600c82 | 2010-08-30 21:14:15 +0200 | [diff] [blame] | 1589 | if (!is_zero_ether_addr((const u8 *)conf->mac)) { |
| 1590 | reg = le32_to_cpu(conf->mac[1]); |
| 1591 | rt2x00_set_field32(®, MAC_ADDR_DW1_UNICAST_TO_ME_MASK, 0xff); |
| 1592 | conf->mac[1] = cpu_to_le32(reg); |
| 1593 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1594 | |
| 1595 | rt2800_register_multiwrite(rt2x00dev, MAC_ADDR_DW0, |
| 1596 | conf->mac, sizeof(conf->mac)); |
| 1597 | } |
| 1598 | |
Helmut Schaa | fa8b4b2 | 2010-11-04 20:42:36 +0100 | [diff] [blame] | 1599 | if ((flags & CONFIG_UPDATE_BSSID) || update_bssid) { |
Ivo van Doorn | c600c82 | 2010-08-30 21:14:15 +0200 | [diff] [blame] | 1600 | if (!is_zero_ether_addr((const u8 *)conf->bssid)) { |
| 1601 | reg = le32_to_cpu(conf->bssid[1]); |
| 1602 | rt2x00_set_field32(®, MAC_BSSID_DW1_BSS_ID_MASK, 3); |
Stanislaw Gruszka | 88ff2f4 | 2014-06-05 13:52:25 +0200 | [diff] [blame] | 1603 | rt2x00_set_field32(®, MAC_BSSID_DW1_BSS_BCN_NUM, 0); |
Ivo van Doorn | c600c82 | 2010-08-30 21:14:15 +0200 | [diff] [blame] | 1604 | conf->bssid[1] = cpu_to_le32(reg); |
| 1605 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1606 | |
| 1607 | rt2800_register_multiwrite(rt2x00dev, MAC_BSSID_DW0, |
| 1608 | conf->bssid, sizeof(conf->bssid)); |
| 1609 | } |
| 1610 | } |
| 1611 | EXPORT_SYMBOL_GPL(rt2800_config_intf); |
| 1612 | |
Helmut Schaa | 87c1915 | 2010-10-02 11:28:34 +0200 | [diff] [blame] | 1613 | static void rt2800_config_ht_opmode(struct rt2x00_dev *rt2x00dev, |
| 1614 | struct rt2x00lib_erp *erp) |
| 1615 | { |
| 1616 | bool any_sta_nongf = !!(erp->ht_opmode & |
| 1617 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT); |
| 1618 | u8 protection = erp->ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION; |
| 1619 | u8 mm20_mode, mm40_mode, gf20_mode, gf40_mode; |
| 1620 | u16 mm20_rate, mm40_rate, gf20_rate, gf40_rate; |
| 1621 | u32 reg; |
| 1622 | |
| 1623 | /* default protection rate for HT20: OFDM 24M */ |
| 1624 | mm20_rate = gf20_rate = 0x4004; |
| 1625 | |
| 1626 | /* default protection rate for HT40: duplicate OFDM 24M */ |
| 1627 | mm40_rate = gf40_rate = 0x4084; |
| 1628 | |
| 1629 | switch (protection) { |
| 1630 | case IEEE80211_HT_OP_MODE_PROTECTION_NONE: |
| 1631 | /* |
| 1632 | * All STAs in this BSS are HT20/40 but there might be |
| 1633 | * STAs not supporting greenfield mode. |
| 1634 | * => Disable protection for HT transmissions. |
| 1635 | */ |
| 1636 | mm20_mode = mm40_mode = gf20_mode = gf40_mode = 0; |
| 1637 | |
| 1638 | break; |
| 1639 | case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ: |
| 1640 | /* |
| 1641 | * All STAs in this BSS are HT20 or HT20/40 but there |
| 1642 | * might be STAs not supporting greenfield mode. |
| 1643 | * => Protect all HT40 transmissions. |
| 1644 | */ |
| 1645 | mm20_mode = gf20_mode = 0; |
| 1646 | mm40_mode = gf40_mode = 2; |
| 1647 | |
| 1648 | break; |
| 1649 | case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER: |
| 1650 | /* |
| 1651 | * Nonmember protection: |
| 1652 | * According to 802.11n we _should_ protect all |
| 1653 | * HT transmissions (but we don't have to). |
| 1654 | * |
| 1655 | * But if cts_protection is enabled we _shall_ protect |
| 1656 | * all HT transmissions using a CCK rate. |
| 1657 | * |
| 1658 | * And if any station is non GF we _shall_ protect |
| 1659 | * GF transmissions. |
| 1660 | * |
| 1661 | * We decide to protect everything |
| 1662 | * -> fall through to mixed mode. |
| 1663 | */ |
| 1664 | case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED: |
| 1665 | /* |
| 1666 | * Legacy STAs are present |
| 1667 | * => Protect all HT transmissions. |
| 1668 | */ |
| 1669 | mm20_mode = mm40_mode = gf20_mode = gf40_mode = 2; |
| 1670 | |
| 1671 | /* |
| 1672 | * If erp protection is needed we have to protect HT |
| 1673 | * transmissions with CCK 11M long preamble. |
| 1674 | */ |
| 1675 | if (erp->cts_protection) { |
| 1676 | /* don't duplicate RTS/CTS in CCK mode */ |
| 1677 | mm20_rate = mm40_rate = 0x0003; |
| 1678 | gf20_rate = gf40_rate = 0x0003; |
| 1679 | } |
| 1680 | break; |
Joe Perches | 6403eab | 2011-06-03 11:51:20 +0000 | [diff] [blame] | 1681 | } |
Helmut Schaa | 87c1915 | 2010-10-02 11:28:34 +0200 | [diff] [blame] | 1682 | |
| 1683 | /* check for STAs not supporting greenfield mode */ |
| 1684 | if (any_sta_nongf) |
| 1685 | gf20_mode = gf40_mode = 2; |
| 1686 | |
| 1687 | /* Update HT protection config */ |
| 1688 | rt2800_register_read(rt2x00dev, MM20_PROT_CFG, ®); |
| 1689 | rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_RATE, mm20_rate); |
| 1690 | rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_CTRL, mm20_mode); |
| 1691 | rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg); |
| 1692 | |
| 1693 | rt2800_register_read(rt2x00dev, MM40_PROT_CFG, ®); |
| 1694 | rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_RATE, mm40_rate); |
| 1695 | rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_CTRL, mm40_mode); |
| 1696 | rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg); |
| 1697 | |
| 1698 | rt2800_register_read(rt2x00dev, GF20_PROT_CFG, ®); |
| 1699 | rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_RATE, gf20_rate); |
| 1700 | rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_CTRL, gf20_mode); |
| 1701 | rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg); |
| 1702 | |
| 1703 | rt2800_register_read(rt2x00dev, GF40_PROT_CFG, ®); |
| 1704 | rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_RATE, gf40_rate); |
| 1705 | rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_CTRL, gf40_mode); |
| 1706 | rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg); |
| 1707 | } |
| 1708 | |
Helmut Schaa | 0204464 | 2010-09-08 20:56:32 +0200 | [diff] [blame] | 1709 | void rt2800_config_erp(struct rt2x00_dev *rt2x00dev, struct rt2x00lib_erp *erp, |
| 1710 | u32 changed) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1711 | { |
| 1712 | u32 reg; |
| 1713 | |
Helmut Schaa | 0204464 | 2010-09-08 20:56:32 +0200 | [diff] [blame] | 1714 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
| 1715 | rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, ®); |
| 1716 | rt2x00_set_field32(®, AUTO_RSP_CFG_BAC_ACK_POLICY, |
| 1717 | !!erp->short_preamble); |
| 1718 | rt2x00_set_field32(®, AUTO_RSP_CFG_AR_PREAMBLE, |
| 1719 | !!erp->short_preamble); |
| 1720 | rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg); |
| 1721 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1722 | |
Helmut Schaa | 0204464 | 2010-09-08 20:56:32 +0200 | [diff] [blame] | 1723 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
| 1724 | rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, ®); |
| 1725 | rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_CTRL, |
| 1726 | erp->cts_protection ? 2 : 0); |
| 1727 | rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg); |
| 1728 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1729 | |
Helmut Schaa | 0204464 | 2010-09-08 20:56:32 +0200 | [diff] [blame] | 1730 | if (changed & BSS_CHANGED_BASIC_RATES) { |
| 1731 | rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE, |
| 1732 | erp->basic_rates); |
| 1733 | rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003); |
| 1734 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1735 | |
Helmut Schaa | 0204464 | 2010-09-08 20:56:32 +0200 | [diff] [blame] | 1736 | if (changed & BSS_CHANGED_ERP_SLOT) { |
| 1737 | rt2800_register_read(rt2x00dev, BKOFF_SLOT_CFG, ®); |
| 1738 | rt2x00_set_field32(®, BKOFF_SLOT_CFG_SLOT_TIME, |
| 1739 | erp->slot_time); |
| 1740 | rt2800_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1741 | |
Helmut Schaa | 0204464 | 2010-09-08 20:56:32 +0200 | [diff] [blame] | 1742 | rt2800_register_read(rt2x00dev, XIFS_TIME_CFG, ®); |
| 1743 | rt2x00_set_field32(®, XIFS_TIME_CFG_EIFS, erp->eifs); |
| 1744 | rt2800_register_write(rt2x00dev, XIFS_TIME_CFG, reg); |
| 1745 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1746 | |
Helmut Schaa | 0204464 | 2010-09-08 20:56:32 +0200 | [diff] [blame] | 1747 | if (changed & BSS_CHANGED_BEACON_INT) { |
| 1748 | rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®); |
| 1749 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_INTERVAL, |
| 1750 | erp->beacon_int * 16); |
| 1751 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
| 1752 | } |
Helmut Schaa | 87c1915 | 2010-10-02 11:28:34 +0200 | [diff] [blame] | 1753 | |
| 1754 | if (changed & BSS_CHANGED_HT) |
| 1755 | rt2800_config_ht_opmode(rt2x00dev, erp); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1756 | } |
| 1757 | EXPORT_SYMBOL_GPL(rt2800_config_erp); |
| 1758 | |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 1759 | static void rt2800_config_3572bt_ant(struct rt2x00_dev *rt2x00dev) |
| 1760 | { |
| 1761 | u32 reg; |
| 1762 | u16 eeprom; |
| 1763 | u8 led_ctrl, led_g_mode, led_r_mode; |
| 1764 | |
| 1765 | rt2800_register_read(rt2x00dev, GPIO_SWITCH, ®); |
| 1766 | if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ) { |
| 1767 | rt2x00_set_field32(®, GPIO_SWITCH_0, 1); |
| 1768 | rt2x00_set_field32(®, GPIO_SWITCH_1, 1); |
| 1769 | } else { |
| 1770 | rt2x00_set_field32(®, GPIO_SWITCH_0, 0); |
| 1771 | rt2x00_set_field32(®, GPIO_SWITCH_1, 0); |
| 1772 | } |
| 1773 | rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg); |
| 1774 | |
| 1775 | rt2800_register_read(rt2x00dev, LED_CFG, ®); |
| 1776 | led_g_mode = rt2x00_get_field32(reg, LED_CFG_LED_POLAR) ? 3 : 0; |
| 1777 | led_r_mode = rt2x00_get_field32(reg, LED_CFG_LED_POLAR) ? 0 : 3; |
| 1778 | if (led_g_mode != rt2x00_get_field32(reg, LED_CFG_G_LED_MODE) || |
| 1779 | led_r_mode != rt2x00_get_field32(reg, LED_CFG_R_LED_MODE)) { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 1780 | rt2800_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 1781 | led_ctrl = rt2x00_get_field16(eeprom, EEPROM_FREQ_LED_MODE); |
| 1782 | if (led_ctrl == 0 || led_ctrl > 0x40) { |
| 1783 | rt2x00_set_field32(®, LED_CFG_G_LED_MODE, led_g_mode); |
| 1784 | rt2x00_set_field32(®, LED_CFG_R_LED_MODE, led_r_mode); |
| 1785 | rt2800_register_write(rt2x00dev, LED_CFG, reg); |
| 1786 | } else { |
| 1787 | rt2800_mcu_request(rt2x00dev, MCU_BAND_SELECT, 0xff, |
| 1788 | (led_g_mode << 2) | led_r_mode, 1); |
| 1789 | } |
| 1790 | } |
| 1791 | } |
| 1792 | |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1793 | static void rt2800_set_ant_diversity(struct rt2x00_dev *rt2x00dev, |
| 1794 | enum antenna ant) |
| 1795 | { |
| 1796 | u32 reg; |
| 1797 | u8 eesk_pin = (ant == ANTENNA_A) ? 1 : 0; |
| 1798 | u8 gpio_bit3 = (ant == ANTENNA_A) ? 0 : 1; |
| 1799 | |
| 1800 | if (rt2x00_is_pci(rt2x00dev)) { |
| 1801 | rt2800_register_read(rt2x00dev, E2PROM_CSR, ®); |
| 1802 | rt2x00_set_field32(®, E2PROM_CSR_DATA_CLOCK, eesk_pin); |
| 1803 | rt2800_register_write(rt2x00dev, E2PROM_CSR, reg); |
| 1804 | } else if (rt2x00_is_usb(rt2x00dev)) |
| 1805 | rt2800_mcu_request(rt2x00dev, MCU_ANT_SELECT, 0xff, |
| 1806 | eesk_pin, 0); |
| 1807 | |
Gertjan van Wingerde | 99bdf51 | 2012-08-31 19:22:13 +0200 | [diff] [blame] | 1808 | rt2800_register_read(rt2x00dev, GPIO_CTRL, ®); |
| 1809 | rt2x00_set_field32(®, GPIO_CTRL_DIR3, 0); |
| 1810 | rt2x00_set_field32(®, GPIO_CTRL_VAL3, gpio_bit3); |
| 1811 | rt2800_register_write(rt2x00dev, GPIO_CTRL, reg); |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1812 | } |
| 1813 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1814 | void rt2800_config_ant(struct rt2x00_dev *rt2x00dev, struct antenna_setup *ant) |
| 1815 | { |
| 1816 | u8 r1; |
| 1817 | u8 r3; |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1818 | u16 eeprom; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1819 | |
| 1820 | rt2800_bbp_read(rt2x00dev, 1, &r1); |
| 1821 | rt2800_bbp_read(rt2x00dev, 3, &r3); |
| 1822 | |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 1823 | if (rt2x00_rt(rt2x00dev, RT3572) && |
Gabor Juhos | c429dfe | 2013-10-11 13:18:42 +0200 | [diff] [blame] | 1824 | rt2x00_has_cap_bt_coexist(rt2x00dev)) |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 1825 | rt2800_config_3572bt_ant(rt2x00dev); |
| 1826 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1827 | /* |
| 1828 | * Configure the TX antenna. |
| 1829 | */ |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1830 | switch (ant->tx_chain_num) { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1831 | case 1: |
| 1832 | rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1833 | break; |
| 1834 | case 2: |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 1835 | if (rt2x00_rt(rt2x00dev, RT3572) && |
Gabor Juhos | c429dfe | 2013-10-11 13:18:42 +0200 | [diff] [blame] | 1836 | rt2x00_has_cap_bt_coexist(rt2x00dev)) |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 1837 | rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 1); |
| 1838 | else |
| 1839 | rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1840 | break; |
| 1841 | case 3: |
Gabor Juhos | 4788ac1 | 2013-07-08 16:08:21 +0200 | [diff] [blame] | 1842 | rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1843 | break; |
| 1844 | } |
| 1845 | |
| 1846 | /* |
| 1847 | * Configure the RX antenna. |
| 1848 | */ |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1849 | switch (ant->rx_chain_num) { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1850 | case 1: |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1851 | if (rt2x00_rt(rt2x00dev, RT3070) || |
| 1852 | rt2x00_rt(rt2x00dev, RT3090) || |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 1853 | rt2x00_rt(rt2x00dev, RT3352) || |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1854 | rt2x00_rt(rt2x00dev, RT3390)) { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 1855 | rt2800_eeprom_read(rt2x00dev, |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1856 | EEPROM_NIC_CONF1, &eeprom); |
| 1857 | if (rt2x00_get_field16(eeprom, |
| 1858 | EEPROM_NIC_CONF1_ANT_DIVERSITY)) |
| 1859 | rt2800_set_ant_diversity(rt2x00dev, |
| 1860 | rt2x00dev->default_ant.rx); |
| 1861 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1862 | rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0); |
| 1863 | break; |
| 1864 | case 2: |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 1865 | if (rt2x00_rt(rt2x00dev, RT3572) && |
Gabor Juhos | c429dfe | 2013-10-11 13:18:42 +0200 | [diff] [blame] | 1866 | rt2x00_has_cap_bt_coexist(rt2x00dev)) { |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 1867 | rt2x00_set_field8(&r3, BBP3_RX_ADC, 1); |
| 1868 | rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, |
| 1869 | rt2x00dev->curr_band == IEEE80211_BAND_5GHZ); |
| 1870 | rt2800_set_ant_diversity(rt2x00dev, ANTENNA_B); |
| 1871 | } else { |
| 1872 | rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 1); |
| 1873 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1874 | break; |
| 1875 | case 3: |
| 1876 | rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 2); |
| 1877 | break; |
| 1878 | } |
| 1879 | |
| 1880 | rt2800_bbp_write(rt2x00dev, 3, r3); |
| 1881 | rt2800_bbp_write(rt2x00dev, 1, r1); |
Gabor Juhos | 5cddb3c | 2013-07-08 16:08:22 +0200 | [diff] [blame] | 1882 | |
| 1883 | if (rt2x00_rt(rt2x00dev, RT3593)) { |
| 1884 | if (ant->rx_chain_num == 1) |
| 1885 | rt2800_bbp_write(rt2x00dev, 86, 0x00); |
| 1886 | else |
| 1887 | rt2800_bbp_write(rt2x00dev, 86, 0x46); |
| 1888 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1889 | } |
| 1890 | EXPORT_SYMBOL_GPL(rt2800_config_ant); |
| 1891 | |
| 1892 | static void rt2800_config_lna_gain(struct rt2x00_dev *rt2x00dev, |
| 1893 | struct rt2x00lib_conf *libconf) |
| 1894 | { |
| 1895 | u16 eeprom; |
| 1896 | short lna_gain; |
| 1897 | |
| 1898 | if (libconf->rf.channel <= 14) { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 1899 | rt2800_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1900 | lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_BG); |
| 1901 | } else if (libconf->rf.channel <= 64) { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 1902 | rt2800_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1903 | lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_A0); |
| 1904 | } else if (libconf->rf.channel <= 128) { |
Gabor Juhos | f36bb0c | 2013-07-08 16:08:27 +0200 | [diff] [blame] | 1905 | if (rt2x00_rt(rt2x00dev, RT3593)) { |
| 1906 | rt2800_eeprom_read(rt2x00dev, EEPROM_EXT_LNA2, &eeprom); |
| 1907 | lna_gain = rt2x00_get_field16(eeprom, |
| 1908 | EEPROM_EXT_LNA2_A1); |
| 1909 | } else { |
| 1910 | rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom); |
| 1911 | lna_gain = rt2x00_get_field16(eeprom, |
| 1912 | EEPROM_RSSI_BG2_LNA_A1); |
| 1913 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1914 | } else { |
Gabor Juhos | f36bb0c | 2013-07-08 16:08:27 +0200 | [diff] [blame] | 1915 | if (rt2x00_rt(rt2x00dev, RT3593)) { |
| 1916 | rt2800_eeprom_read(rt2x00dev, EEPROM_EXT_LNA2, &eeprom); |
| 1917 | lna_gain = rt2x00_get_field16(eeprom, |
| 1918 | EEPROM_EXT_LNA2_A2); |
| 1919 | } else { |
| 1920 | rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom); |
| 1921 | lna_gain = rt2x00_get_field16(eeprom, |
| 1922 | EEPROM_RSSI_A2_LNA_A2); |
| 1923 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1924 | } |
| 1925 | |
| 1926 | rt2x00dev->lna_gain = lna_gain; |
| 1927 | } |
| 1928 | |
Gabor Juhos | 3f1b873 | 2013-08-17 14:09:32 +0200 | [diff] [blame] | 1929 | #define FREQ_OFFSET_BOUND 0x5f |
| 1930 | |
| 1931 | static void rt2800_adjust_freq_offset(struct rt2x00_dev *rt2x00dev) |
| 1932 | { |
| 1933 | u8 freq_offset, prev_freq_offset; |
| 1934 | u8 rfcsr, prev_rfcsr; |
| 1935 | |
| 1936 | freq_offset = rt2x00_get_field8(rt2x00dev->freq_offset, RFCSR17_CODE); |
| 1937 | freq_offset = min_t(u8, freq_offset, FREQ_OFFSET_BOUND); |
| 1938 | |
| 1939 | rt2800_rfcsr_read(rt2x00dev, 17, &rfcsr); |
| 1940 | prev_rfcsr = rfcsr; |
| 1941 | |
| 1942 | rt2x00_set_field8(&rfcsr, RFCSR17_CODE, freq_offset); |
| 1943 | if (rfcsr == prev_rfcsr) |
| 1944 | return; |
| 1945 | |
| 1946 | if (rt2x00_is_usb(rt2x00dev)) { |
| 1947 | rt2800_mcu_request(rt2x00dev, MCU_FREQ_OFFSET, 0xff, |
| 1948 | freq_offset, prev_rfcsr); |
| 1949 | return; |
| 1950 | } |
| 1951 | |
| 1952 | prev_freq_offset = rt2x00_get_field8(prev_rfcsr, RFCSR17_CODE); |
| 1953 | while (prev_freq_offset != freq_offset) { |
| 1954 | if (prev_freq_offset < freq_offset) |
| 1955 | prev_freq_offset++; |
| 1956 | else |
| 1957 | prev_freq_offset--; |
| 1958 | |
| 1959 | rt2x00_set_field8(&rfcsr, RFCSR17_CODE, prev_freq_offset); |
| 1960 | rt2800_rfcsr_write(rt2x00dev, 17, rfcsr); |
| 1961 | |
| 1962 | usleep_range(1000, 1500); |
| 1963 | } |
| 1964 | } |
| 1965 | |
Gertjan van Wingerde | 06855ef | 2010-04-11 14:31:07 +0200 | [diff] [blame] | 1966 | static void rt2800_config_channel_rf2xxx(struct rt2x00_dev *rt2x00dev, |
| 1967 | struct ieee80211_conf *conf, |
| 1968 | struct rf_channel *rf, |
| 1969 | struct channel_info *info) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1970 | { |
| 1971 | rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset); |
| 1972 | |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1973 | if (rt2x00dev->default_ant.tx_chain_num == 1) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1974 | rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_TX1, 1); |
| 1975 | |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1976 | if (rt2x00dev->default_ant.rx_chain_num == 1) { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1977 | rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX1, 1); |
| 1978 | rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1); |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1979 | } else if (rt2x00dev->default_ant.rx_chain_num == 2) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1980 | rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1); |
| 1981 | |
| 1982 | if (rf->channel > 14) { |
| 1983 | /* |
| 1984 | * When TX power is below 0, we should increase it by 7 to |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1985 | * make it a positive value (Minimum value is -7). |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1986 | * However this means that values between 0 and 7 have |
| 1987 | * double meaning, and we should set a 7DBm boost flag. |
| 1988 | */ |
| 1989 | rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A_7DBM_BOOST, |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1990 | (info->default_power1 >= 0)); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1991 | |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1992 | if (info->default_power1 < 0) |
| 1993 | info->default_power1 += 7; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1994 | |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1995 | rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A, info->default_power1); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1996 | |
| 1997 | rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A_7DBM_BOOST, |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1998 | (info->default_power2 >= 0)); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1999 | |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 2000 | if (info->default_power2 < 0) |
| 2001 | info->default_power2 += 7; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2002 | |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 2003 | rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A, info->default_power2); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2004 | } else { |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 2005 | rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_G, info->default_power1); |
| 2006 | rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_G, info->default_power2); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | rt2x00_set_field32(&rf->rf4, RF4_HT40, conf_is_ht40(conf)); |
| 2010 | |
| 2011 | rt2800_rf_write(rt2x00dev, 1, rf->rf1); |
| 2012 | rt2800_rf_write(rt2x00dev, 2, rf->rf2); |
| 2013 | rt2800_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004); |
| 2014 | rt2800_rf_write(rt2x00dev, 4, rf->rf4); |
| 2015 | |
| 2016 | udelay(200); |
| 2017 | |
| 2018 | rt2800_rf_write(rt2x00dev, 1, rf->rf1); |
| 2019 | rt2800_rf_write(rt2x00dev, 2, rf->rf2); |
| 2020 | rt2800_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004); |
| 2021 | rt2800_rf_write(rt2x00dev, 4, rf->rf4); |
| 2022 | |
| 2023 | udelay(200); |
| 2024 | |
| 2025 | rt2800_rf_write(rt2x00dev, 1, rf->rf1); |
| 2026 | rt2800_rf_write(rt2x00dev, 2, rf->rf2); |
| 2027 | rt2800_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004); |
| 2028 | rt2800_rf_write(rt2x00dev, 4, rf->rf4); |
| 2029 | } |
| 2030 | |
Gertjan van Wingerde | 06855ef | 2010-04-11 14:31:07 +0200 | [diff] [blame] | 2031 | static void rt2800_config_channel_rf3xxx(struct rt2x00_dev *rt2x00dev, |
| 2032 | struct ieee80211_conf *conf, |
| 2033 | struct rf_channel *rf, |
| 2034 | struct channel_info *info) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2035 | { |
Gertjan van Wingerde | 3a1c012 | 2012-02-06 23:45:07 +0100 | [diff] [blame] | 2036 | struct rt2800_drv_data *drv_data = rt2x00dev->drv_data; |
Stanislaw Gruszka | f1f12f9 | 2012-01-30 16:17:59 +0100 | [diff] [blame] | 2037 | u8 rfcsr, calib_tx, calib_rx; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2038 | |
| 2039 | rt2800_rfcsr_write(rt2x00dev, 2, rf->rf1); |
Stanislaw Gruszka | 7f4666a | 2012-01-30 16:17:56 +0100 | [diff] [blame] | 2040 | |
| 2041 | rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr); |
| 2042 | rt2x00_set_field8(&rfcsr, RFCSR3_K, rf->rf3); |
| 2043 | rt2800_rfcsr_write(rt2x00dev, 3, rfcsr); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2044 | |
| 2045 | rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr); |
Gertjan van Wingerde | fab799c | 2010-04-11 14:31:08 +0200 | [diff] [blame] | 2046 | rt2x00_set_field8(&rfcsr, RFCSR6_R1, rf->rf2); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2047 | rt2800_rfcsr_write(rt2x00dev, 6, rfcsr); |
| 2048 | |
| 2049 | rt2800_rfcsr_read(rt2x00dev, 12, &rfcsr); |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 2050 | rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER, info->default_power1); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2051 | rt2800_rfcsr_write(rt2x00dev, 12, rfcsr); |
| 2052 | |
Helmut Schaa | 5a67396 | 2010-04-23 15:54:43 +0200 | [diff] [blame] | 2053 | rt2800_rfcsr_read(rt2x00dev, 13, &rfcsr); |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 2054 | rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER, info->default_power2); |
Helmut Schaa | 5a67396 | 2010-04-23 15:54:43 +0200 | [diff] [blame] | 2055 | rt2800_rfcsr_write(rt2x00dev, 13, rfcsr); |
| 2056 | |
Stanislaw Gruszka | e3bab19 | 2012-01-30 16:17:57 +0100 | [diff] [blame] | 2057 | rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr); |
| 2058 | rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0); |
Gertjan van Wingerde | 7ad6303 | 2012-09-16 22:29:53 +0200 | [diff] [blame] | 2059 | rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, |
| 2060 | rt2x00dev->default_ant.rx_chain_num <= 1); |
| 2061 | rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, |
| 2062 | rt2x00dev->default_ant.rx_chain_num <= 2); |
Stanislaw Gruszka | e3bab19 | 2012-01-30 16:17:57 +0100 | [diff] [blame] | 2063 | rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0); |
Gertjan van Wingerde | 7ad6303 | 2012-09-16 22:29:53 +0200 | [diff] [blame] | 2064 | rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, |
| 2065 | rt2x00dev->default_ant.tx_chain_num <= 1); |
| 2066 | rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, |
| 2067 | rt2x00dev->default_ant.tx_chain_num <= 2); |
Stanislaw Gruszka | e3bab19 | 2012-01-30 16:17:57 +0100 | [diff] [blame] | 2068 | rt2800_rfcsr_write(rt2x00dev, 1, rfcsr); |
| 2069 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2070 | rt2800_rfcsr_read(rt2x00dev, 23, &rfcsr); |
| 2071 | rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset); |
| 2072 | rt2800_rfcsr_write(rt2x00dev, 23, rfcsr); |
| 2073 | |
Stanislaw Gruszka | f1f12f9 | 2012-01-30 16:17:59 +0100 | [diff] [blame] | 2074 | if (rt2x00_rt(rt2x00dev, RT3390)) { |
| 2075 | calib_tx = conf_is_ht40(conf) ? 0x68 : 0x4f; |
| 2076 | calib_rx = conf_is_ht40(conf) ? 0x6f : 0x4f; |
| 2077 | } else { |
Gertjan van Wingerde | 3a1c012 | 2012-02-06 23:45:07 +0100 | [diff] [blame] | 2078 | if (conf_is_ht40(conf)) { |
| 2079 | calib_tx = drv_data->calibration_bw40; |
| 2080 | calib_rx = drv_data->calibration_bw40; |
| 2081 | } else { |
| 2082 | calib_tx = drv_data->calibration_bw20; |
| 2083 | calib_rx = drv_data->calibration_bw20; |
| 2084 | } |
Stanislaw Gruszka | f1f12f9 | 2012-01-30 16:17:59 +0100 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | rt2800_rfcsr_read(rt2x00dev, 24, &rfcsr); |
| 2088 | rt2x00_set_field8(&rfcsr, RFCSR24_TX_CALIB, calib_tx); |
| 2089 | rt2800_rfcsr_write(rt2x00dev, 24, rfcsr); |
| 2090 | |
| 2091 | rt2800_rfcsr_read(rt2x00dev, 31, &rfcsr); |
| 2092 | rt2x00_set_field8(&rfcsr, RFCSR31_RX_CALIB, calib_rx); |
| 2093 | rt2800_rfcsr_write(rt2x00dev, 31, rfcsr); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2094 | |
Gertjan van Wingerde | 7197690 | 2010-03-24 21:42:36 +0100 | [diff] [blame] | 2095 | rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2096 | rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1); |
Gertjan van Wingerde | 7197690 | 2010-03-24 21:42:36 +0100 | [diff] [blame] | 2097 | rt2800_rfcsr_write(rt2x00dev, 7, rfcsr); |
Stanislaw Gruszka | 3e0c764 | 2012-01-30 16:17:58 +0100 | [diff] [blame] | 2098 | |
| 2099 | rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr); |
| 2100 | rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1); |
| 2101 | rt2800_rfcsr_write(rt2x00dev, 30, rfcsr); |
| 2102 | msleep(1); |
| 2103 | rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0); |
| 2104 | rt2800_rfcsr_write(rt2x00dev, 30, rfcsr); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2105 | } |
| 2106 | |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2107 | static void rt2800_config_channel_rf3052(struct rt2x00_dev *rt2x00dev, |
| 2108 | struct ieee80211_conf *conf, |
| 2109 | struct rf_channel *rf, |
| 2110 | struct channel_info *info) |
| 2111 | { |
Gertjan van Wingerde | 3a1c012 | 2012-02-06 23:45:07 +0100 | [diff] [blame] | 2112 | struct rt2800_drv_data *drv_data = rt2x00dev->drv_data; |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2113 | u8 rfcsr; |
| 2114 | u32 reg; |
| 2115 | |
| 2116 | if (rf->channel <= 14) { |
Gertjan van Wingerde | 5d137df | 2012-02-06 23:45:09 +0100 | [diff] [blame] | 2117 | rt2800_bbp_write(rt2x00dev, 25, drv_data->bbp25); |
| 2118 | rt2800_bbp_write(rt2x00dev, 26, drv_data->bbp26); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2119 | } else { |
| 2120 | rt2800_bbp_write(rt2x00dev, 25, 0x09); |
| 2121 | rt2800_bbp_write(rt2x00dev, 26, 0xff); |
| 2122 | } |
| 2123 | |
| 2124 | rt2800_rfcsr_write(rt2x00dev, 2, rf->rf1); |
| 2125 | rt2800_rfcsr_write(rt2x00dev, 3, rf->rf3); |
| 2126 | |
| 2127 | rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr); |
| 2128 | rt2x00_set_field8(&rfcsr, RFCSR6_R1, rf->rf2); |
| 2129 | if (rf->channel <= 14) |
| 2130 | rt2x00_set_field8(&rfcsr, RFCSR6_TXDIV, 2); |
| 2131 | else |
| 2132 | rt2x00_set_field8(&rfcsr, RFCSR6_TXDIV, 1); |
| 2133 | rt2800_rfcsr_write(rt2x00dev, 6, rfcsr); |
| 2134 | |
| 2135 | rt2800_rfcsr_read(rt2x00dev, 5, &rfcsr); |
| 2136 | if (rf->channel <= 14) |
| 2137 | rt2x00_set_field8(&rfcsr, RFCSR5_R1, 1); |
| 2138 | else |
| 2139 | rt2x00_set_field8(&rfcsr, RFCSR5_R1, 2); |
| 2140 | rt2800_rfcsr_write(rt2x00dev, 5, rfcsr); |
| 2141 | |
| 2142 | rt2800_rfcsr_read(rt2x00dev, 12, &rfcsr); |
| 2143 | if (rf->channel <= 14) { |
| 2144 | rt2x00_set_field8(&rfcsr, RFCSR12_DR0, 3); |
| 2145 | rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER, |
Gertjan van Wingerde | 569ffa5 | 2012-02-06 23:45:10 +0100 | [diff] [blame] | 2146 | info->default_power1); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2147 | } else { |
| 2148 | rt2x00_set_field8(&rfcsr, RFCSR12_DR0, 7); |
| 2149 | rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER, |
| 2150 | (info->default_power1 & 0x3) | |
| 2151 | ((info->default_power1 & 0xC) << 1)); |
| 2152 | } |
| 2153 | rt2800_rfcsr_write(rt2x00dev, 12, rfcsr); |
| 2154 | |
| 2155 | rt2800_rfcsr_read(rt2x00dev, 13, &rfcsr); |
| 2156 | if (rf->channel <= 14) { |
| 2157 | rt2x00_set_field8(&rfcsr, RFCSR13_DR0, 3); |
| 2158 | rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER, |
Gertjan van Wingerde | 569ffa5 | 2012-02-06 23:45:10 +0100 | [diff] [blame] | 2159 | info->default_power2); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2160 | } else { |
| 2161 | rt2x00_set_field8(&rfcsr, RFCSR13_DR0, 7); |
| 2162 | rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER, |
| 2163 | (info->default_power2 & 0x3) | |
| 2164 | ((info->default_power2 & 0xC) << 1)); |
| 2165 | } |
| 2166 | rt2800_rfcsr_write(rt2x00dev, 13, rfcsr); |
| 2167 | |
| 2168 | rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2169 | rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0); |
| 2170 | rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0); |
| 2171 | rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 0); |
| 2172 | rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 0); |
Gertjan van Wingerde | 0cd461e | 2012-02-06 23:45:11 +0100 | [diff] [blame] | 2173 | rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0); |
| 2174 | rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0); |
Gabor Juhos | c429dfe | 2013-10-11 13:18:42 +0200 | [diff] [blame] | 2175 | if (rt2x00_has_cap_bt_coexist(rt2x00dev)) { |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2176 | if (rf->channel <= 14) { |
| 2177 | rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1); |
| 2178 | rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1); |
| 2179 | } |
| 2180 | rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 1); |
| 2181 | rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 1); |
| 2182 | } else { |
| 2183 | switch (rt2x00dev->default_ant.tx_chain_num) { |
| 2184 | case 1: |
| 2185 | rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1); |
| 2186 | case 2: |
| 2187 | rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 1); |
| 2188 | break; |
| 2189 | } |
| 2190 | |
| 2191 | switch (rt2x00dev->default_ant.rx_chain_num) { |
| 2192 | case 1: |
| 2193 | rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1); |
| 2194 | case 2: |
| 2195 | rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 1); |
| 2196 | break; |
| 2197 | } |
| 2198 | } |
| 2199 | rt2800_rfcsr_write(rt2x00dev, 1, rfcsr); |
| 2200 | |
| 2201 | rt2800_rfcsr_read(rt2x00dev, 23, &rfcsr); |
| 2202 | rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset); |
| 2203 | rt2800_rfcsr_write(rt2x00dev, 23, rfcsr); |
| 2204 | |
Gertjan van Wingerde | 3a1c012 | 2012-02-06 23:45:07 +0100 | [diff] [blame] | 2205 | if (conf_is_ht40(conf)) { |
| 2206 | rt2800_rfcsr_write(rt2x00dev, 24, drv_data->calibration_bw40); |
| 2207 | rt2800_rfcsr_write(rt2x00dev, 31, drv_data->calibration_bw40); |
| 2208 | } else { |
| 2209 | rt2800_rfcsr_write(rt2x00dev, 24, drv_data->calibration_bw20); |
| 2210 | rt2800_rfcsr_write(rt2x00dev, 31, drv_data->calibration_bw20); |
| 2211 | } |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2212 | |
| 2213 | if (rf->channel <= 14) { |
| 2214 | rt2800_rfcsr_write(rt2x00dev, 7, 0xd8); |
| 2215 | rt2800_rfcsr_write(rt2x00dev, 9, 0xc3); |
| 2216 | rt2800_rfcsr_write(rt2x00dev, 10, 0xf1); |
| 2217 | rt2800_rfcsr_write(rt2x00dev, 11, 0xb9); |
| 2218 | rt2800_rfcsr_write(rt2x00dev, 15, 0x53); |
Gertjan van Wingerde | 77c06c2 | 2012-02-06 23:45:13 +0100 | [diff] [blame] | 2219 | rfcsr = 0x4c; |
| 2220 | rt2x00_set_field8(&rfcsr, RFCSR16_TXMIXER_GAIN, |
| 2221 | drv_data->txmixer_gain_24g); |
| 2222 | rt2800_rfcsr_write(rt2x00dev, 16, rfcsr); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2223 | rt2800_rfcsr_write(rt2x00dev, 17, 0x23); |
| 2224 | rt2800_rfcsr_write(rt2x00dev, 19, 0x93); |
| 2225 | rt2800_rfcsr_write(rt2x00dev, 20, 0xb3); |
| 2226 | rt2800_rfcsr_write(rt2x00dev, 25, 0x15); |
| 2227 | rt2800_rfcsr_write(rt2x00dev, 26, 0x85); |
| 2228 | rt2800_rfcsr_write(rt2x00dev, 27, 0x00); |
| 2229 | rt2800_rfcsr_write(rt2x00dev, 29, 0x9b); |
| 2230 | } else { |
Gertjan van Wingerde | 58b8ae1 | 2012-02-06 23:45:12 +0100 | [diff] [blame] | 2231 | rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr); |
| 2232 | rt2x00_set_field8(&rfcsr, RFCSR7_BIT2, 1); |
| 2233 | rt2x00_set_field8(&rfcsr, RFCSR7_BIT3, 0); |
| 2234 | rt2x00_set_field8(&rfcsr, RFCSR7_BIT4, 1); |
| 2235 | rt2x00_set_field8(&rfcsr, RFCSR7_BITS67, 0); |
| 2236 | rt2800_rfcsr_write(rt2x00dev, 7, rfcsr); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2237 | rt2800_rfcsr_write(rt2x00dev, 9, 0xc0); |
| 2238 | rt2800_rfcsr_write(rt2x00dev, 10, 0xf1); |
| 2239 | rt2800_rfcsr_write(rt2x00dev, 11, 0x00); |
| 2240 | rt2800_rfcsr_write(rt2x00dev, 15, 0x43); |
Gertjan van Wingerde | 77c06c2 | 2012-02-06 23:45:13 +0100 | [diff] [blame] | 2241 | rfcsr = 0x7a; |
| 2242 | rt2x00_set_field8(&rfcsr, RFCSR16_TXMIXER_GAIN, |
| 2243 | drv_data->txmixer_gain_5g); |
| 2244 | rt2800_rfcsr_write(rt2x00dev, 16, rfcsr); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2245 | rt2800_rfcsr_write(rt2x00dev, 17, 0x23); |
| 2246 | if (rf->channel <= 64) { |
| 2247 | rt2800_rfcsr_write(rt2x00dev, 19, 0xb7); |
| 2248 | rt2800_rfcsr_write(rt2x00dev, 20, 0xf6); |
| 2249 | rt2800_rfcsr_write(rt2x00dev, 25, 0x3d); |
| 2250 | } else if (rf->channel <= 128) { |
| 2251 | rt2800_rfcsr_write(rt2x00dev, 19, 0x74); |
| 2252 | rt2800_rfcsr_write(rt2x00dev, 20, 0xf4); |
| 2253 | rt2800_rfcsr_write(rt2x00dev, 25, 0x01); |
| 2254 | } else { |
| 2255 | rt2800_rfcsr_write(rt2x00dev, 19, 0x72); |
| 2256 | rt2800_rfcsr_write(rt2x00dev, 20, 0xf3); |
| 2257 | rt2800_rfcsr_write(rt2x00dev, 25, 0x01); |
| 2258 | } |
| 2259 | rt2800_rfcsr_write(rt2x00dev, 26, 0x87); |
| 2260 | rt2800_rfcsr_write(rt2x00dev, 27, 0x01); |
| 2261 | rt2800_rfcsr_write(rt2x00dev, 29, 0x9f); |
| 2262 | } |
| 2263 | |
Gertjan van Wingerde | 99bdf51 | 2012-08-31 19:22:13 +0200 | [diff] [blame] | 2264 | rt2800_register_read(rt2x00dev, GPIO_CTRL, ®); |
| 2265 | rt2x00_set_field32(®, GPIO_CTRL_DIR7, 0); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2266 | if (rf->channel <= 14) |
Gertjan van Wingerde | 99bdf51 | 2012-08-31 19:22:13 +0200 | [diff] [blame] | 2267 | rt2x00_set_field32(®, GPIO_CTRL_VAL7, 1); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2268 | else |
Gertjan van Wingerde | 99bdf51 | 2012-08-31 19:22:13 +0200 | [diff] [blame] | 2269 | rt2x00_set_field32(®, GPIO_CTRL_VAL7, 0); |
| 2270 | rt2800_register_write(rt2x00dev, GPIO_CTRL, reg); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2271 | |
| 2272 | rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr); |
| 2273 | rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1); |
| 2274 | rt2800_rfcsr_write(rt2x00dev, 7, rfcsr); |
| 2275 | } |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2276 | |
Gabor Juhos | f42b046 | 2013-07-08 16:08:30 +0200 | [diff] [blame] | 2277 | static void rt2800_config_channel_rf3053(struct rt2x00_dev *rt2x00dev, |
| 2278 | struct ieee80211_conf *conf, |
| 2279 | struct rf_channel *rf, |
| 2280 | struct channel_info *info) |
| 2281 | { |
| 2282 | struct rt2800_drv_data *drv_data = rt2x00dev->drv_data; |
| 2283 | u8 txrx_agc_fc; |
| 2284 | u8 txrx_h20m; |
| 2285 | u8 rfcsr; |
| 2286 | u8 bbp; |
| 2287 | const bool txbf_enabled = false; /* TODO */ |
| 2288 | |
| 2289 | /* TODO: use TX{0,1,2}FinePowerControl values from EEPROM */ |
| 2290 | rt2800_bbp_read(rt2x00dev, 109, &bbp); |
| 2291 | rt2x00_set_field8(&bbp, BBP109_TX0_POWER, 0); |
| 2292 | rt2x00_set_field8(&bbp, BBP109_TX1_POWER, 0); |
| 2293 | rt2800_bbp_write(rt2x00dev, 109, bbp); |
| 2294 | |
| 2295 | rt2800_bbp_read(rt2x00dev, 110, &bbp); |
| 2296 | rt2x00_set_field8(&bbp, BBP110_TX2_POWER, 0); |
| 2297 | rt2800_bbp_write(rt2x00dev, 110, bbp); |
| 2298 | |
| 2299 | if (rf->channel <= 14) { |
| 2300 | /* Restore BBP 25 & 26 for 2.4 GHz */ |
| 2301 | rt2800_bbp_write(rt2x00dev, 25, drv_data->bbp25); |
| 2302 | rt2800_bbp_write(rt2x00dev, 26, drv_data->bbp26); |
| 2303 | } else { |
| 2304 | /* Hard code BBP 25 & 26 for 5GHz */ |
| 2305 | |
| 2306 | /* Enable IQ Phase correction */ |
| 2307 | rt2800_bbp_write(rt2x00dev, 25, 0x09); |
| 2308 | /* Setup IQ Phase correction value */ |
| 2309 | rt2800_bbp_write(rt2x00dev, 26, 0xff); |
| 2310 | } |
| 2311 | |
| 2312 | rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1); |
| 2313 | rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3 & 0xf); |
| 2314 | |
| 2315 | rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr); |
| 2316 | rt2x00_set_field8(&rfcsr, RFCSR11_R, (rf->rf2 & 0x3)); |
| 2317 | rt2800_rfcsr_write(rt2x00dev, 11, rfcsr); |
| 2318 | |
| 2319 | rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr); |
| 2320 | rt2x00_set_field8(&rfcsr, RFCSR11_PLL_IDOH, 1); |
| 2321 | if (rf->channel <= 14) |
| 2322 | rt2x00_set_field8(&rfcsr, RFCSR11_PLL_MOD, 1); |
| 2323 | else |
| 2324 | rt2x00_set_field8(&rfcsr, RFCSR11_PLL_MOD, 2); |
| 2325 | rt2800_rfcsr_write(rt2x00dev, 11, rfcsr); |
| 2326 | |
| 2327 | rt2800_rfcsr_read(rt2x00dev, 53, &rfcsr); |
| 2328 | if (rf->channel <= 14) { |
| 2329 | rfcsr = 0; |
| 2330 | rt2x00_set_field8(&rfcsr, RFCSR53_TX_POWER, |
| 2331 | info->default_power1 & 0x1f); |
| 2332 | } else { |
| 2333 | if (rt2x00_is_usb(rt2x00dev)) |
| 2334 | rfcsr = 0x40; |
| 2335 | |
| 2336 | rt2x00_set_field8(&rfcsr, RFCSR53_TX_POWER, |
| 2337 | ((info->default_power1 & 0x18) << 1) | |
| 2338 | (info->default_power1 & 7)); |
| 2339 | } |
| 2340 | rt2800_rfcsr_write(rt2x00dev, 53, rfcsr); |
| 2341 | |
| 2342 | rt2800_rfcsr_read(rt2x00dev, 55, &rfcsr); |
| 2343 | if (rf->channel <= 14) { |
| 2344 | rfcsr = 0; |
| 2345 | rt2x00_set_field8(&rfcsr, RFCSR55_TX_POWER, |
| 2346 | info->default_power2 & 0x1f); |
| 2347 | } else { |
| 2348 | if (rt2x00_is_usb(rt2x00dev)) |
| 2349 | rfcsr = 0x40; |
| 2350 | |
| 2351 | rt2x00_set_field8(&rfcsr, RFCSR55_TX_POWER, |
| 2352 | ((info->default_power2 & 0x18) << 1) | |
| 2353 | (info->default_power2 & 7)); |
| 2354 | } |
| 2355 | rt2800_rfcsr_write(rt2x00dev, 55, rfcsr); |
| 2356 | |
| 2357 | rt2800_rfcsr_read(rt2x00dev, 54, &rfcsr); |
| 2358 | if (rf->channel <= 14) { |
| 2359 | rfcsr = 0; |
| 2360 | rt2x00_set_field8(&rfcsr, RFCSR54_TX_POWER, |
| 2361 | info->default_power3 & 0x1f); |
| 2362 | } else { |
| 2363 | if (rt2x00_is_usb(rt2x00dev)) |
| 2364 | rfcsr = 0x40; |
| 2365 | |
| 2366 | rt2x00_set_field8(&rfcsr, RFCSR54_TX_POWER, |
| 2367 | ((info->default_power3 & 0x18) << 1) | |
| 2368 | (info->default_power3 & 7)); |
| 2369 | } |
| 2370 | rt2800_rfcsr_write(rt2x00dev, 54, rfcsr); |
| 2371 | |
| 2372 | rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr); |
| 2373 | rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0); |
| 2374 | rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0); |
| 2375 | rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 0); |
| 2376 | rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 0); |
| 2377 | rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0); |
| 2378 | rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0); |
| 2379 | rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1); |
| 2380 | rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1); |
| 2381 | |
| 2382 | switch (rt2x00dev->default_ant.tx_chain_num) { |
| 2383 | case 3: |
| 2384 | rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 1); |
| 2385 | /* fallthrough */ |
| 2386 | case 2: |
| 2387 | rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1); |
| 2388 | /* fallthrough */ |
| 2389 | case 1: |
| 2390 | rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1); |
| 2391 | break; |
| 2392 | } |
| 2393 | |
| 2394 | switch (rt2x00dev->default_ant.rx_chain_num) { |
| 2395 | case 3: |
| 2396 | rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 1); |
| 2397 | /* fallthrough */ |
| 2398 | case 2: |
| 2399 | rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1); |
| 2400 | /* fallthrough */ |
| 2401 | case 1: |
| 2402 | rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1); |
| 2403 | break; |
| 2404 | } |
| 2405 | rt2800_rfcsr_write(rt2x00dev, 1, rfcsr); |
| 2406 | |
Gabor Juhos | e979a8a | 2013-08-17 14:09:33 +0200 | [diff] [blame] | 2407 | rt2800_adjust_freq_offset(rt2x00dev); |
Gabor Juhos | f42b046 | 2013-07-08 16:08:30 +0200 | [diff] [blame] | 2408 | |
| 2409 | if (conf_is_ht40(conf)) { |
| 2410 | txrx_agc_fc = rt2x00_get_field8(drv_data->calibration_bw40, |
| 2411 | RFCSR24_TX_AGC_FC); |
| 2412 | txrx_h20m = rt2x00_get_field8(drv_data->calibration_bw40, |
| 2413 | RFCSR24_TX_H20M); |
| 2414 | } else { |
| 2415 | txrx_agc_fc = rt2x00_get_field8(drv_data->calibration_bw20, |
| 2416 | RFCSR24_TX_AGC_FC); |
| 2417 | txrx_h20m = rt2x00_get_field8(drv_data->calibration_bw20, |
| 2418 | RFCSR24_TX_H20M); |
| 2419 | } |
| 2420 | |
| 2421 | /* NOTE: the reference driver does not writes the new value |
| 2422 | * back to RFCSR 32 |
| 2423 | */ |
| 2424 | rt2800_rfcsr_read(rt2x00dev, 32, &rfcsr); |
| 2425 | rt2x00_set_field8(&rfcsr, RFCSR32_TX_AGC_FC, txrx_agc_fc); |
| 2426 | |
| 2427 | if (rf->channel <= 14) |
| 2428 | rfcsr = 0xa0; |
| 2429 | else |
| 2430 | rfcsr = 0x80; |
| 2431 | rt2800_rfcsr_write(rt2x00dev, 31, rfcsr); |
| 2432 | |
| 2433 | rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr); |
| 2434 | rt2x00_set_field8(&rfcsr, RFCSR30_TX_H20M, txrx_h20m); |
| 2435 | rt2x00_set_field8(&rfcsr, RFCSR30_RX_H20M, txrx_h20m); |
| 2436 | rt2800_rfcsr_write(rt2x00dev, 30, rfcsr); |
| 2437 | |
| 2438 | /* Band selection */ |
| 2439 | rt2800_rfcsr_read(rt2x00dev, 36, &rfcsr); |
| 2440 | if (rf->channel <= 14) |
| 2441 | rt2x00_set_field8(&rfcsr, RFCSR36_RF_BS, 1); |
| 2442 | else |
| 2443 | rt2x00_set_field8(&rfcsr, RFCSR36_RF_BS, 0); |
| 2444 | rt2800_rfcsr_write(rt2x00dev, 36, rfcsr); |
| 2445 | |
| 2446 | rt2800_rfcsr_read(rt2x00dev, 34, &rfcsr); |
| 2447 | if (rf->channel <= 14) |
| 2448 | rfcsr = 0x3c; |
| 2449 | else |
| 2450 | rfcsr = 0x20; |
| 2451 | rt2800_rfcsr_write(rt2x00dev, 34, rfcsr); |
| 2452 | |
| 2453 | rt2800_rfcsr_read(rt2x00dev, 12, &rfcsr); |
| 2454 | if (rf->channel <= 14) |
| 2455 | rfcsr = 0x1a; |
| 2456 | else |
| 2457 | rfcsr = 0x12; |
| 2458 | rt2800_rfcsr_write(rt2x00dev, 12, rfcsr); |
| 2459 | |
| 2460 | rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr); |
| 2461 | if (rf->channel >= 1 && rf->channel <= 14) |
| 2462 | rt2x00_set_field8(&rfcsr, RFCSR6_VCO_IC, 1); |
| 2463 | else if (rf->channel >= 36 && rf->channel <= 64) |
| 2464 | rt2x00_set_field8(&rfcsr, RFCSR6_VCO_IC, 2); |
| 2465 | else if (rf->channel >= 100 && rf->channel <= 128) |
| 2466 | rt2x00_set_field8(&rfcsr, RFCSR6_VCO_IC, 2); |
| 2467 | else |
| 2468 | rt2x00_set_field8(&rfcsr, RFCSR6_VCO_IC, 1); |
| 2469 | rt2800_rfcsr_write(rt2x00dev, 6, rfcsr); |
| 2470 | |
| 2471 | rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr); |
| 2472 | rt2x00_set_field8(&rfcsr, RFCSR30_RX_VCM, 2); |
| 2473 | rt2800_rfcsr_write(rt2x00dev, 30, rfcsr); |
| 2474 | |
| 2475 | rt2800_rfcsr_write(rt2x00dev, 46, 0x60); |
| 2476 | |
| 2477 | if (rf->channel <= 14) { |
| 2478 | rt2800_rfcsr_write(rt2x00dev, 10, 0xd3); |
| 2479 | rt2800_rfcsr_write(rt2x00dev, 13, 0x12); |
| 2480 | } else { |
| 2481 | rt2800_rfcsr_write(rt2x00dev, 10, 0xd8); |
| 2482 | rt2800_rfcsr_write(rt2x00dev, 13, 0x23); |
| 2483 | } |
| 2484 | |
| 2485 | rt2800_rfcsr_read(rt2x00dev, 51, &rfcsr); |
| 2486 | rt2x00_set_field8(&rfcsr, RFCSR51_BITS01, 1); |
| 2487 | rt2800_rfcsr_write(rt2x00dev, 51, rfcsr); |
| 2488 | |
| 2489 | rt2800_rfcsr_read(rt2x00dev, 51, &rfcsr); |
| 2490 | if (rf->channel <= 14) { |
| 2491 | rt2x00_set_field8(&rfcsr, RFCSR51_BITS24, 5); |
| 2492 | rt2x00_set_field8(&rfcsr, RFCSR51_BITS57, 3); |
| 2493 | } else { |
| 2494 | rt2x00_set_field8(&rfcsr, RFCSR51_BITS24, 4); |
| 2495 | rt2x00_set_field8(&rfcsr, RFCSR51_BITS57, 2); |
| 2496 | } |
| 2497 | rt2800_rfcsr_write(rt2x00dev, 51, rfcsr); |
| 2498 | |
| 2499 | rt2800_rfcsr_read(rt2x00dev, 49, &rfcsr); |
| 2500 | if (rf->channel <= 14) |
| 2501 | rt2x00_set_field8(&rfcsr, RFCSR49_TX_LO1_IC, 3); |
| 2502 | else |
| 2503 | rt2x00_set_field8(&rfcsr, RFCSR49_TX_LO1_IC, 2); |
| 2504 | |
| 2505 | if (txbf_enabled) |
| 2506 | rt2x00_set_field8(&rfcsr, RFCSR49_TX_DIV, 1); |
| 2507 | |
| 2508 | rt2800_rfcsr_write(rt2x00dev, 49, rfcsr); |
| 2509 | |
| 2510 | rt2800_rfcsr_read(rt2x00dev, 50, &rfcsr); |
| 2511 | rt2x00_set_field8(&rfcsr, RFCSR50_TX_LO1_EN, 0); |
| 2512 | rt2800_rfcsr_write(rt2x00dev, 50, rfcsr); |
| 2513 | |
| 2514 | rt2800_rfcsr_read(rt2x00dev, 57, &rfcsr); |
| 2515 | if (rf->channel <= 14) |
| 2516 | rt2x00_set_field8(&rfcsr, RFCSR57_DRV_CC, 0x1b); |
| 2517 | else |
| 2518 | rt2x00_set_field8(&rfcsr, RFCSR57_DRV_CC, 0x0f); |
| 2519 | rt2800_rfcsr_write(rt2x00dev, 57, rfcsr); |
| 2520 | |
| 2521 | if (rf->channel <= 14) { |
| 2522 | rt2800_rfcsr_write(rt2x00dev, 44, 0x93); |
| 2523 | rt2800_rfcsr_write(rt2x00dev, 52, 0x45); |
| 2524 | } else { |
| 2525 | rt2800_rfcsr_write(rt2x00dev, 44, 0x9b); |
| 2526 | rt2800_rfcsr_write(rt2x00dev, 52, 0x05); |
| 2527 | } |
| 2528 | |
| 2529 | /* Initiate VCO calibration */ |
| 2530 | rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr); |
| 2531 | if (rf->channel <= 14) { |
| 2532 | rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1); |
| 2533 | } else { |
| 2534 | rt2x00_set_field8(&rfcsr, RFCSR3_BIT1, 1); |
| 2535 | rt2x00_set_field8(&rfcsr, RFCSR3_BIT2, 1); |
| 2536 | rt2x00_set_field8(&rfcsr, RFCSR3_BIT3, 1); |
| 2537 | rt2x00_set_field8(&rfcsr, RFCSR3_BIT4, 1); |
| 2538 | rt2x00_set_field8(&rfcsr, RFCSR3_BIT5, 1); |
| 2539 | rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1); |
| 2540 | } |
| 2541 | rt2800_rfcsr_write(rt2x00dev, 3, rfcsr); |
| 2542 | |
| 2543 | if (rf->channel >= 1 && rf->channel <= 14) { |
| 2544 | rfcsr = 0x23; |
| 2545 | if (txbf_enabled) |
| 2546 | rt2x00_set_field8(&rfcsr, RFCSR39_RX_DIV, 1); |
| 2547 | rt2800_rfcsr_write(rt2x00dev, 39, rfcsr); |
| 2548 | |
| 2549 | rt2800_rfcsr_write(rt2x00dev, 45, 0xbb); |
| 2550 | } else if (rf->channel >= 36 && rf->channel <= 64) { |
| 2551 | rfcsr = 0x36; |
| 2552 | if (txbf_enabled) |
| 2553 | rt2x00_set_field8(&rfcsr, RFCSR39_RX_DIV, 1); |
| 2554 | rt2800_rfcsr_write(rt2x00dev, 39, 0x36); |
| 2555 | |
| 2556 | rt2800_rfcsr_write(rt2x00dev, 45, 0xeb); |
| 2557 | } else if (rf->channel >= 100 && rf->channel <= 128) { |
| 2558 | rfcsr = 0x32; |
| 2559 | if (txbf_enabled) |
| 2560 | rt2x00_set_field8(&rfcsr, RFCSR39_RX_DIV, 1); |
| 2561 | rt2800_rfcsr_write(rt2x00dev, 39, rfcsr); |
| 2562 | |
| 2563 | rt2800_rfcsr_write(rt2x00dev, 45, 0xb3); |
| 2564 | } else { |
| 2565 | rfcsr = 0x30; |
| 2566 | if (txbf_enabled) |
| 2567 | rt2x00_set_field8(&rfcsr, RFCSR39_RX_DIV, 1); |
| 2568 | rt2800_rfcsr_write(rt2x00dev, 39, rfcsr); |
| 2569 | |
| 2570 | rt2800_rfcsr_write(rt2x00dev, 45, 0x9b); |
| 2571 | } |
| 2572 | } |
| 2573 | |
Stanislaw Gruszka | 7573cb5 | 2012-07-09 14:41:48 +0200 | [diff] [blame] | 2574 | #define POWER_BOUND 0x27 |
Stanislaw Gruszka | 8f82109 | 2013-03-16 19:19:32 +0100 | [diff] [blame] | 2575 | #define POWER_BOUND_5G 0x2b |
Stanislaw Gruszka | 0c9e5fb | 2013-03-16 19:19:36 +0100 | [diff] [blame] | 2576 | |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 2577 | static void rt2800_config_channel_rf3290(struct rt2x00_dev *rt2x00dev, |
| 2578 | struct ieee80211_conf *conf, |
| 2579 | struct rf_channel *rf, |
| 2580 | struct channel_info *info) |
| 2581 | { |
| 2582 | u8 rfcsr; |
| 2583 | |
| 2584 | rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1); |
| 2585 | rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3); |
| 2586 | rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr); |
| 2587 | rt2x00_set_field8(&rfcsr, RFCSR11_R, rf->rf2); |
| 2588 | rt2800_rfcsr_write(rt2x00dev, 11, rfcsr); |
| 2589 | |
| 2590 | rt2800_rfcsr_read(rt2x00dev, 49, &rfcsr); |
Stanislaw Gruszka | 7573cb5 | 2012-07-09 14:41:48 +0200 | [diff] [blame] | 2591 | if (info->default_power1 > POWER_BOUND) |
| 2592 | rt2x00_set_field8(&rfcsr, RFCSR49_TX, POWER_BOUND); |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 2593 | else |
| 2594 | rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1); |
| 2595 | rt2800_rfcsr_write(rt2x00dev, 49, rfcsr); |
| 2596 | |
Stanislaw Gruszka | 0c9e5fb | 2013-03-16 19:19:36 +0100 | [diff] [blame] | 2597 | rt2800_adjust_freq_offset(rt2x00dev); |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 2598 | |
| 2599 | if (rf->channel <= 14) { |
| 2600 | if (rf->channel == 6) |
| 2601 | rt2800_bbp_write(rt2x00dev, 68, 0x0c); |
| 2602 | else |
| 2603 | rt2800_bbp_write(rt2x00dev, 68, 0x0b); |
| 2604 | |
| 2605 | if (rf->channel >= 1 && rf->channel <= 6) |
| 2606 | rt2800_bbp_write(rt2x00dev, 59, 0x0f); |
| 2607 | else if (rf->channel >= 7 && rf->channel <= 11) |
| 2608 | rt2800_bbp_write(rt2x00dev, 59, 0x0e); |
| 2609 | else if (rf->channel >= 12 && rf->channel <= 14) |
| 2610 | rt2800_bbp_write(rt2x00dev, 59, 0x0d); |
| 2611 | } |
| 2612 | } |
| 2613 | |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 2614 | static void rt2800_config_channel_rf3322(struct rt2x00_dev *rt2x00dev, |
| 2615 | struct ieee80211_conf *conf, |
| 2616 | struct rf_channel *rf, |
| 2617 | struct channel_info *info) |
| 2618 | { |
| 2619 | u8 rfcsr; |
| 2620 | |
| 2621 | rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1); |
| 2622 | rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3); |
| 2623 | |
| 2624 | rt2800_rfcsr_write(rt2x00dev, 11, 0x42); |
| 2625 | rt2800_rfcsr_write(rt2x00dev, 12, 0x1c); |
| 2626 | rt2800_rfcsr_write(rt2x00dev, 13, 0x00); |
| 2627 | |
| 2628 | if (info->default_power1 > POWER_BOUND) |
| 2629 | rt2800_rfcsr_write(rt2x00dev, 47, POWER_BOUND); |
| 2630 | else |
| 2631 | rt2800_rfcsr_write(rt2x00dev, 47, info->default_power1); |
| 2632 | |
| 2633 | if (info->default_power2 > POWER_BOUND) |
| 2634 | rt2800_rfcsr_write(rt2x00dev, 48, POWER_BOUND); |
| 2635 | else |
| 2636 | rt2800_rfcsr_write(rt2x00dev, 48, info->default_power2); |
| 2637 | |
Stanislaw Gruszka | 0c9e5fb | 2013-03-16 19:19:36 +0100 | [diff] [blame] | 2638 | rt2800_adjust_freq_offset(rt2x00dev); |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 2639 | |
| 2640 | rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr); |
| 2641 | rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1); |
| 2642 | rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1); |
| 2643 | |
| 2644 | if ( rt2x00dev->default_ant.tx_chain_num == 2 ) |
| 2645 | rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1); |
| 2646 | else |
| 2647 | rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 0); |
| 2648 | |
| 2649 | if ( rt2x00dev->default_ant.rx_chain_num == 2 ) |
| 2650 | rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1); |
| 2651 | else |
| 2652 | rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 0); |
| 2653 | |
| 2654 | rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0); |
| 2655 | rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0); |
| 2656 | |
| 2657 | rt2800_rfcsr_write(rt2x00dev, 1, rfcsr); |
| 2658 | |
| 2659 | rt2800_rfcsr_write(rt2x00dev, 31, 80); |
| 2660 | } |
| 2661 | |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2662 | static void rt2800_config_channel_rf53xx(struct rt2x00_dev *rt2x00dev, |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2663 | struct ieee80211_conf *conf, |
| 2664 | struct rf_channel *rf, |
| 2665 | struct channel_info *info) |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2666 | { |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2667 | u8 rfcsr; |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2668 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2669 | rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1); |
| 2670 | rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3); |
| 2671 | rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr); |
| 2672 | rt2x00_set_field8(&rfcsr, RFCSR11_R, rf->rf2); |
| 2673 | rt2800_rfcsr_write(rt2x00dev, 11, rfcsr); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2674 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2675 | rt2800_rfcsr_read(rt2x00dev, 49, &rfcsr); |
Stanislaw Gruszka | 7573cb5 | 2012-07-09 14:41:48 +0200 | [diff] [blame] | 2676 | if (info->default_power1 > POWER_BOUND) |
| 2677 | rt2x00_set_field8(&rfcsr, RFCSR49_TX, POWER_BOUND); |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2678 | else |
| 2679 | rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1); |
| 2680 | rt2800_rfcsr_write(rt2x00dev, 49, rfcsr); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2681 | |
Zero.Lin | cff3d1f | 2012-05-29 16:11:09 +0800 | [diff] [blame] | 2682 | if (rt2x00_rt(rt2x00dev, RT5392)) { |
| 2683 | rt2800_rfcsr_read(rt2x00dev, 50, &rfcsr); |
Felipe Pena | 6264995 | 2013-10-18 21:20:42 -0300 | [diff] [blame] | 2684 | if (info->default_power2 > POWER_BOUND) |
Stanislaw Gruszka | 7573cb5 | 2012-07-09 14:41:48 +0200 | [diff] [blame] | 2685 | rt2x00_set_field8(&rfcsr, RFCSR50_TX, POWER_BOUND); |
Zero.Lin | cff3d1f | 2012-05-29 16:11:09 +0800 | [diff] [blame] | 2686 | else |
| 2687 | rt2x00_set_field8(&rfcsr, RFCSR50_TX, |
| 2688 | info->default_power2); |
| 2689 | rt2800_rfcsr_write(rt2x00dev, 50, rfcsr); |
| 2690 | } |
| 2691 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2692 | rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr); |
Zero.Lin | cff3d1f | 2012-05-29 16:11:09 +0800 | [diff] [blame] | 2693 | if (rt2x00_rt(rt2x00dev, RT5392)) { |
| 2694 | rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1); |
| 2695 | rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1); |
| 2696 | } |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2697 | rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1); |
| 2698 | rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1); |
| 2699 | rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1); |
| 2700 | rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1); |
| 2701 | rt2800_rfcsr_write(rt2x00dev, 1, rfcsr); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2702 | |
Stanislaw Gruszka | 0c9e5fb | 2013-03-16 19:19:36 +0100 | [diff] [blame] | 2703 | rt2800_adjust_freq_offset(rt2x00dev); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2704 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2705 | if (rf->channel <= 14) { |
| 2706 | int idx = rf->channel-1; |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2707 | |
Gabor Juhos | c429dfe | 2013-10-11 13:18:42 +0200 | [diff] [blame] | 2708 | if (rt2x00_has_cap_bt_coexist(rt2x00dev)) { |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2709 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) { |
| 2710 | /* r55/r59 value array of channel 1~14 */ |
| 2711 | static const char r55_bt_rev[] = {0x83, 0x83, |
| 2712 | 0x83, 0x73, 0x73, 0x63, 0x53, 0x53, |
| 2713 | 0x53, 0x43, 0x43, 0x43, 0x43, 0x43}; |
| 2714 | static const char r59_bt_rev[] = {0x0e, 0x0e, |
| 2715 | 0x0e, 0x0e, 0x0e, 0x0b, 0x0a, 0x09, |
| 2716 | 0x07, 0x07, 0x07, 0x07, 0x07, 0x07}; |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2717 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2718 | rt2800_rfcsr_write(rt2x00dev, 55, |
| 2719 | r55_bt_rev[idx]); |
| 2720 | rt2800_rfcsr_write(rt2x00dev, 59, |
| 2721 | r59_bt_rev[idx]); |
| 2722 | } else { |
| 2723 | static const char r59_bt[] = {0x8b, 0x8b, 0x8b, |
| 2724 | 0x8b, 0x8b, 0x8b, 0x8b, 0x8a, 0x89, |
| 2725 | 0x88, 0x88, 0x86, 0x85, 0x84}; |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2726 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2727 | rt2800_rfcsr_write(rt2x00dev, 59, r59_bt[idx]); |
| 2728 | } |
| 2729 | } else { |
| 2730 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) { |
| 2731 | static const char r55_nonbt_rev[] = {0x23, 0x23, |
| 2732 | 0x23, 0x23, 0x13, 0x13, 0x03, 0x03, |
| 2733 | 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}; |
| 2734 | static const char r59_nonbt_rev[] = {0x07, 0x07, |
| 2735 | 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, |
| 2736 | 0x07, 0x07, 0x06, 0x05, 0x04, 0x04}; |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2737 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2738 | rt2800_rfcsr_write(rt2x00dev, 55, |
| 2739 | r55_nonbt_rev[idx]); |
| 2740 | rt2800_rfcsr_write(rt2x00dev, 59, |
| 2741 | r59_nonbt_rev[idx]); |
John Li | 2ed7188 | 2012-02-17 17:33:06 +0800 | [diff] [blame] | 2742 | } else if (rt2x00_rt(rt2x00dev, RT5390) || |
Gabor Juhos | e6d227b | 2012-12-02 15:53:28 +0100 | [diff] [blame] | 2743 | rt2x00_rt(rt2x00dev, RT5392)) { |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2744 | static const char r59_non_bt[] = {0x8f, 0x8f, |
| 2745 | 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8d, |
| 2746 | 0x8a, 0x88, 0x88, 0x87, 0x87, 0x86}; |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2747 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2748 | rt2800_rfcsr_write(rt2x00dev, 59, |
| 2749 | r59_non_bt[idx]); |
| 2750 | } |
| 2751 | } |
| 2752 | } |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2753 | } |
| 2754 | |
Stanislaw Gruszka | 8f82109 | 2013-03-16 19:19:32 +0100 | [diff] [blame] | 2755 | static void rt2800_config_channel_rf55xx(struct rt2x00_dev *rt2x00dev, |
| 2756 | struct ieee80211_conf *conf, |
| 2757 | struct rf_channel *rf, |
| 2758 | struct channel_info *info) |
| 2759 | { |
| 2760 | u8 rfcsr, ep_reg; |
Stanislaw Gruszka | d5ae7a6 | 2013-03-16 19:19:42 +0100 | [diff] [blame] | 2761 | u32 reg; |
Stanislaw Gruszka | 8f82109 | 2013-03-16 19:19:32 +0100 | [diff] [blame] | 2762 | int power_bound; |
| 2763 | |
| 2764 | /* TODO */ |
| 2765 | const bool is_11b = false; |
| 2766 | const bool is_type_ep = false; |
| 2767 | |
Stanislaw Gruszka | d5ae7a6 | 2013-03-16 19:19:42 +0100 | [diff] [blame] | 2768 | rt2800_register_read(rt2x00dev, LDO_CFG0, ®); |
| 2769 | rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, |
| 2770 | (rf->channel > 14 || conf_is_ht40(conf)) ? 5 : 0); |
| 2771 | rt2800_register_write(rt2x00dev, LDO_CFG0, reg); |
Stanislaw Gruszka | 8f82109 | 2013-03-16 19:19:32 +0100 | [diff] [blame] | 2772 | |
| 2773 | /* Order of values on rf_channel entry: N, K, mod, R */ |
| 2774 | rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1 & 0xff); |
| 2775 | |
| 2776 | rt2800_rfcsr_read(rt2x00dev, 9, &rfcsr); |
| 2777 | rt2x00_set_field8(&rfcsr, RFCSR9_K, rf->rf2 & 0xf); |
| 2778 | rt2x00_set_field8(&rfcsr, RFCSR9_N, (rf->rf1 & 0x100) >> 8); |
| 2779 | rt2x00_set_field8(&rfcsr, RFCSR9_MOD, ((rf->rf3 - 8) & 0x4) >> 2); |
| 2780 | rt2800_rfcsr_write(rt2x00dev, 9, rfcsr); |
| 2781 | |
| 2782 | rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr); |
| 2783 | rt2x00_set_field8(&rfcsr, RFCSR11_R, rf->rf4 - 1); |
| 2784 | rt2x00_set_field8(&rfcsr, RFCSR11_MOD, (rf->rf3 - 8) & 0x3); |
| 2785 | rt2800_rfcsr_write(rt2x00dev, 11, rfcsr); |
| 2786 | |
| 2787 | if (rf->channel <= 14) { |
| 2788 | rt2800_rfcsr_write(rt2x00dev, 10, 0x90); |
| 2789 | /* FIXME: RF11 owerwrite ? */ |
| 2790 | rt2800_rfcsr_write(rt2x00dev, 11, 0x4A); |
| 2791 | rt2800_rfcsr_write(rt2x00dev, 12, 0x52); |
| 2792 | rt2800_rfcsr_write(rt2x00dev, 13, 0x42); |
| 2793 | rt2800_rfcsr_write(rt2x00dev, 22, 0x40); |
| 2794 | rt2800_rfcsr_write(rt2x00dev, 24, 0x4A); |
| 2795 | rt2800_rfcsr_write(rt2x00dev, 25, 0x80); |
| 2796 | rt2800_rfcsr_write(rt2x00dev, 27, 0x42); |
| 2797 | rt2800_rfcsr_write(rt2x00dev, 36, 0x80); |
| 2798 | rt2800_rfcsr_write(rt2x00dev, 37, 0x08); |
| 2799 | rt2800_rfcsr_write(rt2x00dev, 38, 0x89); |
| 2800 | rt2800_rfcsr_write(rt2x00dev, 39, 0x1B); |
| 2801 | rt2800_rfcsr_write(rt2x00dev, 40, 0x0D); |
| 2802 | rt2800_rfcsr_write(rt2x00dev, 41, 0x9B); |
| 2803 | rt2800_rfcsr_write(rt2x00dev, 42, 0xD5); |
| 2804 | rt2800_rfcsr_write(rt2x00dev, 43, 0x72); |
| 2805 | rt2800_rfcsr_write(rt2x00dev, 44, 0x0E); |
| 2806 | rt2800_rfcsr_write(rt2x00dev, 45, 0xA2); |
| 2807 | rt2800_rfcsr_write(rt2x00dev, 46, 0x6B); |
| 2808 | rt2800_rfcsr_write(rt2x00dev, 48, 0x10); |
| 2809 | rt2800_rfcsr_write(rt2x00dev, 51, 0x3E); |
| 2810 | rt2800_rfcsr_write(rt2x00dev, 52, 0x48); |
| 2811 | rt2800_rfcsr_write(rt2x00dev, 54, 0x38); |
| 2812 | rt2800_rfcsr_write(rt2x00dev, 56, 0xA1); |
| 2813 | rt2800_rfcsr_write(rt2x00dev, 57, 0x00); |
| 2814 | rt2800_rfcsr_write(rt2x00dev, 58, 0x39); |
| 2815 | rt2800_rfcsr_write(rt2x00dev, 60, 0x45); |
| 2816 | rt2800_rfcsr_write(rt2x00dev, 61, 0x91); |
| 2817 | rt2800_rfcsr_write(rt2x00dev, 62, 0x39); |
| 2818 | |
| 2819 | /* TODO RF27 <- tssi */ |
| 2820 | |
| 2821 | rfcsr = rf->channel <= 10 ? 0x07 : 0x06; |
| 2822 | rt2800_rfcsr_write(rt2x00dev, 23, rfcsr); |
| 2823 | rt2800_rfcsr_write(rt2x00dev, 59, rfcsr); |
| 2824 | |
| 2825 | if (is_11b) { |
| 2826 | /* CCK */ |
| 2827 | rt2800_rfcsr_write(rt2x00dev, 31, 0xF8); |
| 2828 | rt2800_rfcsr_write(rt2x00dev, 32, 0xC0); |
| 2829 | if (is_type_ep) |
| 2830 | rt2800_rfcsr_write(rt2x00dev, 55, 0x06); |
| 2831 | else |
| 2832 | rt2800_rfcsr_write(rt2x00dev, 55, 0x47); |
| 2833 | } else { |
| 2834 | /* OFDM */ |
| 2835 | if (is_type_ep) |
| 2836 | rt2800_rfcsr_write(rt2x00dev, 55, 0x03); |
| 2837 | else |
| 2838 | rt2800_rfcsr_write(rt2x00dev, 55, 0x43); |
| 2839 | } |
| 2840 | |
| 2841 | power_bound = POWER_BOUND; |
| 2842 | ep_reg = 0x2; |
| 2843 | } else { |
| 2844 | rt2800_rfcsr_write(rt2x00dev, 10, 0x97); |
| 2845 | /* FIMXE: RF11 overwrite */ |
| 2846 | rt2800_rfcsr_write(rt2x00dev, 11, 0x40); |
| 2847 | rt2800_rfcsr_write(rt2x00dev, 25, 0xBF); |
| 2848 | rt2800_rfcsr_write(rt2x00dev, 27, 0x42); |
| 2849 | rt2800_rfcsr_write(rt2x00dev, 36, 0x00); |
| 2850 | rt2800_rfcsr_write(rt2x00dev, 37, 0x04); |
| 2851 | rt2800_rfcsr_write(rt2x00dev, 38, 0x85); |
| 2852 | rt2800_rfcsr_write(rt2x00dev, 40, 0x42); |
| 2853 | rt2800_rfcsr_write(rt2x00dev, 41, 0xBB); |
| 2854 | rt2800_rfcsr_write(rt2x00dev, 42, 0xD7); |
| 2855 | rt2800_rfcsr_write(rt2x00dev, 45, 0x41); |
| 2856 | rt2800_rfcsr_write(rt2x00dev, 48, 0x00); |
| 2857 | rt2800_rfcsr_write(rt2x00dev, 57, 0x77); |
| 2858 | rt2800_rfcsr_write(rt2x00dev, 60, 0x05); |
| 2859 | rt2800_rfcsr_write(rt2x00dev, 61, 0x01); |
| 2860 | |
| 2861 | /* TODO RF27 <- tssi */ |
| 2862 | |
| 2863 | if (rf->channel >= 36 && rf->channel <= 64) { |
| 2864 | |
| 2865 | rt2800_rfcsr_write(rt2x00dev, 12, 0x2E); |
| 2866 | rt2800_rfcsr_write(rt2x00dev, 13, 0x22); |
| 2867 | rt2800_rfcsr_write(rt2x00dev, 22, 0x60); |
| 2868 | rt2800_rfcsr_write(rt2x00dev, 23, 0x7F); |
| 2869 | if (rf->channel <= 50) |
| 2870 | rt2800_rfcsr_write(rt2x00dev, 24, 0x09); |
| 2871 | else if (rf->channel >= 52) |
| 2872 | rt2800_rfcsr_write(rt2x00dev, 24, 0x07); |
| 2873 | rt2800_rfcsr_write(rt2x00dev, 39, 0x1C); |
| 2874 | rt2800_rfcsr_write(rt2x00dev, 43, 0x5B); |
| 2875 | rt2800_rfcsr_write(rt2x00dev, 44, 0X40); |
| 2876 | rt2800_rfcsr_write(rt2x00dev, 46, 0X00); |
| 2877 | rt2800_rfcsr_write(rt2x00dev, 51, 0xFE); |
| 2878 | rt2800_rfcsr_write(rt2x00dev, 52, 0x0C); |
| 2879 | rt2800_rfcsr_write(rt2x00dev, 54, 0xF8); |
| 2880 | if (rf->channel <= 50) { |
| 2881 | rt2800_rfcsr_write(rt2x00dev, 55, 0x06), |
| 2882 | rt2800_rfcsr_write(rt2x00dev, 56, 0xD3); |
| 2883 | } else if (rf->channel >= 52) { |
| 2884 | rt2800_rfcsr_write(rt2x00dev, 55, 0x04); |
| 2885 | rt2800_rfcsr_write(rt2x00dev, 56, 0xBB); |
| 2886 | } |
| 2887 | |
| 2888 | rt2800_rfcsr_write(rt2x00dev, 58, 0x15); |
| 2889 | rt2800_rfcsr_write(rt2x00dev, 59, 0x7F); |
| 2890 | rt2800_rfcsr_write(rt2x00dev, 62, 0x15); |
| 2891 | |
| 2892 | } else if (rf->channel >= 100 && rf->channel <= 165) { |
| 2893 | |
| 2894 | rt2800_rfcsr_write(rt2x00dev, 12, 0x0E); |
| 2895 | rt2800_rfcsr_write(rt2x00dev, 13, 0x42); |
| 2896 | rt2800_rfcsr_write(rt2x00dev, 22, 0x40); |
| 2897 | if (rf->channel <= 153) { |
| 2898 | rt2800_rfcsr_write(rt2x00dev, 23, 0x3C); |
| 2899 | rt2800_rfcsr_write(rt2x00dev, 24, 0x06); |
| 2900 | } else if (rf->channel >= 155) { |
| 2901 | rt2800_rfcsr_write(rt2x00dev, 23, 0x38); |
| 2902 | rt2800_rfcsr_write(rt2x00dev, 24, 0x05); |
| 2903 | } |
| 2904 | if (rf->channel <= 138) { |
| 2905 | rt2800_rfcsr_write(rt2x00dev, 39, 0x1A); |
| 2906 | rt2800_rfcsr_write(rt2x00dev, 43, 0x3B); |
| 2907 | rt2800_rfcsr_write(rt2x00dev, 44, 0x20); |
| 2908 | rt2800_rfcsr_write(rt2x00dev, 46, 0x18); |
| 2909 | } else if (rf->channel >= 140) { |
| 2910 | rt2800_rfcsr_write(rt2x00dev, 39, 0x18); |
| 2911 | rt2800_rfcsr_write(rt2x00dev, 43, 0x1B); |
| 2912 | rt2800_rfcsr_write(rt2x00dev, 44, 0x10); |
| 2913 | rt2800_rfcsr_write(rt2x00dev, 46, 0X08); |
| 2914 | } |
| 2915 | if (rf->channel <= 124) |
| 2916 | rt2800_rfcsr_write(rt2x00dev, 51, 0xFC); |
| 2917 | else if (rf->channel >= 126) |
| 2918 | rt2800_rfcsr_write(rt2x00dev, 51, 0xEC); |
| 2919 | if (rf->channel <= 138) |
| 2920 | rt2800_rfcsr_write(rt2x00dev, 52, 0x06); |
| 2921 | else if (rf->channel >= 140) |
| 2922 | rt2800_rfcsr_write(rt2x00dev, 52, 0x06); |
| 2923 | rt2800_rfcsr_write(rt2x00dev, 54, 0xEB); |
| 2924 | if (rf->channel <= 138) |
| 2925 | rt2800_rfcsr_write(rt2x00dev, 55, 0x01); |
| 2926 | else if (rf->channel >= 140) |
| 2927 | rt2800_rfcsr_write(rt2x00dev, 55, 0x00); |
| 2928 | if (rf->channel <= 128) |
| 2929 | rt2800_rfcsr_write(rt2x00dev, 56, 0xBB); |
| 2930 | else if (rf->channel >= 130) |
| 2931 | rt2800_rfcsr_write(rt2x00dev, 56, 0xAB); |
| 2932 | if (rf->channel <= 116) |
| 2933 | rt2800_rfcsr_write(rt2x00dev, 58, 0x1D); |
| 2934 | else if (rf->channel >= 118) |
| 2935 | rt2800_rfcsr_write(rt2x00dev, 58, 0x15); |
| 2936 | if (rf->channel <= 138) |
| 2937 | rt2800_rfcsr_write(rt2x00dev, 59, 0x3F); |
| 2938 | else if (rf->channel >= 140) |
| 2939 | rt2800_rfcsr_write(rt2x00dev, 59, 0x7C); |
| 2940 | if (rf->channel <= 116) |
| 2941 | rt2800_rfcsr_write(rt2x00dev, 62, 0x1D); |
| 2942 | else if (rf->channel >= 118) |
| 2943 | rt2800_rfcsr_write(rt2x00dev, 62, 0x15); |
| 2944 | } |
| 2945 | |
| 2946 | power_bound = POWER_BOUND_5G; |
| 2947 | ep_reg = 0x3; |
| 2948 | } |
| 2949 | |
| 2950 | rt2800_rfcsr_read(rt2x00dev, 49, &rfcsr); |
| 2951 | if (info->default_power1 > power_bound) |
| 2952 | rt2x00_set_field8(&rfcsr, RFCSR49_TX, power_bound); |
| 2953 | else |
| 2954 | rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1); |
| 2955 | if (is_type_ep) |
| 2956 | rt2x00_set_field8(&rfcsr, RFCSR49_EP, ep_reg); |
| 2957 | rt2800_rfcsr_write(rt2x00dev, 49, rfcsr); |
| 2958 | |
| 2959 | rt2800_rfcsr_read(rt2x00dev, 50, &rfcsr); |
Gabor Juhos | 0847beb | 2013-06-25 22:57:29 +0200 | [diff] [blame] | 2960 | if (info->default_power2 > power_bound) |
Stanislaw Gruszka | 8f82109 | 2013-03-16 19:19:32 +0100 | [diff] [blame] | 2961 | rt2x00_set_field8(&rfcsr, RFCSR50_TX, power_bound); |
| 2962 | else |
| 2963 | rt2x00_set_field8(&rfcsr, RFCSR50_TX, info->default_power2); |
| 2964 | if (is_type_ep) |
| 2965 | rt2x00_set_field8(&rfcsr, RFCSR50_EP, ep_reg); |
| 2966 | rt2800_rfcsr_write(rt2x00dev, 50, rfcsr); |
| 2967 | |
| 2968 | rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr); |
| 2969 | rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1); |
| 2970 | rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1); |
| 2971 | |
| 2972 | rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, |
| 2973 | rt2x00dev->default_ant.tx_chain_num >= 1); |
| 2974 | rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, |
| 2975 | rt2x00dev->default_ant.tx_chain_num == 2); |
| 2976 | rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0); |
| 2977 | |
| 2978 | rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, |
| 2979 | rt2x00dev->default_ant.rx_chain_num >= 1); |
| 2980 | rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, |
| 2981 | rt2x00dev->default_ant.rx_chain_num == 2); |
| 2982 | rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0); |
| 2983 | |
| 2984 | rt2800_rfcsr_write(rt2x00dev, 1, rfcsr); |
| 2985 | rt2800_rfcsr_write(rt2x00dev, 6, 0xe4); |
| 2986 | |
| 2987 | if (conf_is_ht40(conf)) |
| 2988 | rt2800_rfcsr_write(rt2x00dev, 30, 0x16); |
| 2989 | else |
| 2990 | rt2800_rfcsr_write(rt2x00dev, 30, 0x10); |
| 2991 | |
| 2992 | if (!is_11b) { |
| 2993 | rt2800_rfcsr_write(rt2x00dev, 31, 0x80); |
| 2994 | rt2800_rfcsr_write(rt2x00dev, 32, 0x80); |
| 2995 | } |
| 2996 | |
| 2997 | /* TODO proper frequency adjustment */ |
Stanislaw Gruszka | 0c9e5fb | 2013-03-16 19:19:36 +0100 | [diff] [blame] | 2998 | rt2800_adjust_freq_offset(rt2x00dev); |
Stanislaw Gruszka | 8f82109 | 2013-03-16 19:19:32 +0100 | [diff] [blame] | 2999 | |
| 3000 | /* TODO merge with others */ |
| 3001 | rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr); |
| 3002 | rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1); |
| 3003 | rt2800_rfcsr_write(rt2x00dev, 3, rfcsr); |
Stanislaw Gruszka | 6803141 | 2013-03-16 19:19:44 +0100 | [diff] [blame] | 3004 | |
| 3005 | /* BBP settings */ |
| 3006 | rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain); |
| 3007 | rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain); |
| 3008 | rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain); |
| 3009 | |
| 3010 | rt2800_bbp_write(rt2x00dev, 79, (rf->channel <= 14) ? 0x1C : 0x18); |
| 3011 | rt2800_bbp_write(rt2x00dev, 80, (rf->channel <= 14) ? 0x0E : 0x08); |
| 3012 | rt2800_bbp_write(rt2x00dev, 81, (rf->channel <= 14) ? 0x3A : 0x38); |
| 3013 | rt2800_bbp_write(rt2x00dev, 82, (rf->channel <= 14) ? 0x62 : 0x92); |
| 3014 | |
| 3015 | /* GLRT band configuration */ |
| 3016 | rt2800_bbp_write(rt2x00dev, 195, 128); |
| 3017 | rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0xE0 : 0xF0); |
| 3018 | rt2800_bbp_write(rt2x00dev, 195, 129); |
| 3019 | rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x1F : 0x1E); |
| 3020 | rt2800_bbp_write(rt2x00dev, 195, 130); |
| 3021 | rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x38 : 0x28); |
| 3022 | rt2800_bbp_write(rt2x00dev, 195, 131); |
| 3023 | rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x32 : 0x20); |
| 3024 | rt2800_bbp_write(rt2x00dev, 195, 133); |
| 3025 | rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x28 : 0x7F); |
| 3026 | rt2800_bbp_write(rt2x00dev, 195, 124); |
| 3027 | rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x19 : 0x7F); |
Stanislaw Gruszka | 8f82109 | 2013-03-16 19:19:32 +0100 | [diff] [blame] | 3028 | } |
| 3029 | |
Stanislaw Gruszka | 5bc2dd0 | 2013-03-16 19:19:47 +0100 | [diff] [blame] | 3030 | static void rt2800_bbp_write_with_rx_chain(struct rt2x00_dev *rt2x00dev, |
| 3031 | const unsigned int word, |
| 3032 | const u8 value) |
| 3033 | { |
| 3034 | u8 chain, reg; |
| 3035 | |
| 3036 | for (chain = 0; chain < rt2x00dev->default_ant.rx_chain_num; chain++) { |
| 3037 | rt2800_bbp_read(rt2x00dev, 27, ®); |
| 3038 | rt2x00_set_field8(®, BBP27_RX_CHAIN_SEL, chain); |
| 3039 | rt2800_bbp_write(rt2x00dev, 27, reg); |
| 3040 | |
| 3041 | rt2800_bbp_write(rt2x00dev, word, value); |
| 3042 | } |
| 3043 | } |
| 3044 | |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 3045 | static void rt2800_iq_calibrate(struct rt2x00_dev *rt2x00dev, int channel) |
| 3046 | { |
| 3047 | u8 cal; |
| 3048 | |
Stanislaw Gruszka | 415e3f2 | 2013-03-16 19:19:52 +0100 | [diff] [blame] | 3049 | /* TX0 IQ Gain */ |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 3050 | rt2800_bbp_write(rt2x00dev, 158, 0x2c); |
Stanislaw Gruszka | 415e3f2 | 2013-03-16 19:19:52 +0100 | [diff] [blame] | 3051 | if (channel <= 14) |
| 3052 | cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_GAIN_CAL_TX0_2G); |
| 3053 | else if (channel >= 36 && channel <= 64) |
| 3054 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 3055 | EEPROM_IQ_GAIN_CAL_TX0_CH36_TO_CH64_5G); |
| 3056 | else if (channel >= 100 && channel <= 138) |
| 3057 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 3058 | EEPROM_IQ_GAIN_CAL_TX0_CH100_TO_CH138_5G); |
| 3059 | else if (channel >= 140 && channel <= 165) |
| 3060 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 3061 | EEPROM_IQ_GAIN_CAL_TX0_CH140_TO_CH165_5G); |
| 3062 | else |
| 3063 | cal = 0; |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 3064 | rt2800_bbp_write(rt2x00dev, 159, cal); |
| 3065 | |
Stanislaw Gruszka | 415e3f2 | 2013-03-16 19:19:52 +0100 | [diff] [blame] | 3066 | /* TX0 IQ Phase */ |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 3067 | rt2800_bbp_write(rt2x00dev, 158, 0x2d); |
Stanislaw Gruszka | 415e3f2 | 2013-03-16 19:19:52 +0100 | [diff] [blame] | 3068 | if (channel <= 14) |
| 3069 | cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_PHASE_CAL_TX0_2G); |
| 3070 | else if (channel >= 36 && channel <= 64) |
| 3071 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 3072 | EEPROM_IQ_PHASE_CAL_TX0_CH36_TO_CH64_5G); |
| 3073 | else if (channel >= 100 && channel <= 138) |
| 3074 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 3075 | EEPROM_IQ_PHASE_CAL_TX0_CH100_TO_CH138_5G); |
| 3076 | else if (channel >= 140 && channel <= 165) |
| 3077 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 3078 | EEPROM_IQ_PHASE_CAL_TX0_CH140_TO_CH165_5G); |
| 3079 | else |
| 3080 | cal = 0; |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 3081 | rt2800_bbp_write(rt2x00dev, 159, cal); |
| 3082 | |
Stanislaw Gruszka | 415e3f2 | 2013-03-16 19:19:52 +0100 | [diff] [blame] | 3083 | /* TX1 IQ Gain */ |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 3084 | rt2800_bbp_write(rt2x00dev, 158, 0x4a); |
Stanislaw Gruszka | 415e3f2 | 2013-03-16 19:19:52 +0100 | [diff] [blame] | 3085 | if (channel <= 14) |
| 3086 | cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_GAIN_CAL_TX1_2G); |
| 3087 | else if (channel >= 36 && channel <= 64) |
| 3088 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 3089 | EEPROM_IQ_GAIN_CAL_TX1_CH36_TO_CH64_5G); |
| 3090 | else if (channel >= 100 && channel <= 138) |
| 3091 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 3092 | EEPROM_IQ_GAIN_CAL_TX1_CH100_TO_CH138_5G); |
| 3093 | else if (channel >= 140 && channel <= 165) |
| 3094 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 3095 | EEPROM_IQ_GAIN_CAL_TX1_CH140_TO_CH165_5G); |
| 3096 | else |
| 3097 | cal = 0; |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 3098 | rt2800_bbp_write(rt2x00dev, 159, cal); |
| 3099 | |
Stanislaw Gruszka | 415e3f2 | 2013-03-16 19:19:52 +0100 | [diff] [blame] | 3100 | /* TX1 IQ Phase */ |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 3101 | rt2800_bbp_write(rt2x00dev, 158, 0x4b); |
Stanislaw Gruszka | 415e3f2 | 2013-03-16 19:19:52 +0100 | [diff] [blame] | 3102 | if (channel <= 14) |
| 3103 | cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_PHASE_CAL_TX1_2G); |
| 3104 | else if (channel >= 36 && channel <= 64) |
| 3105 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 3106 | EEPROM_IQ_PHASE_CAL_TX1_CH36_TO_CH64_5G); |
| 3107 | else if (channel >= 100 && channel <= 138) |
| 3108 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 3109 | EEPROM_IQ_PHASE_CAL_TX1_CH100_TO_CH138_5G); |
| 3110 | else if (channel >= 140 && channel <= 165) |
| 3111 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 3112 | EEPROM_IQ_PHASE_CAL_TX1_CH140_TO_CH165_5G); |
| 3113 | else |
| 3114 | cal = 0; |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 3115 | rt2800_bbp_write(rt2x00dev, 159, cal); |
| 3116 | |
Stanislaw Gruszka | 415e3f2 | 2013-03-16 19:19:52 +0100 | [diff] [blame] | 3117 | /* FIXME: possible RX0, RX1 callibration ? */ |
| 3118 | |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 3119 | /* RF IQ compensation control */ |
| 3120 | rt2800_bbp_write(rt2x00dev, 158, 0x04); |
| 3121 | cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_RF_IQ_COMPENSATION_CONTROL); |
| 3122 | rt2800_bbp_write(rt2x00dev, 159, cal != 0xff ? cal : 0); |
| 3123 | |
| 3124 | /* RF IQ imbalance compensation control */ |
| 3125 | rt2800_bbp_write(rt2x00dev, 158, 0x03); |
Stanislaw Gruszka | 415e3f2 | 2013-03-16 19:19:52 +0100 | [diff] [blame] | 3126 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 3127 | EEPROM_RF_IQ_IMBALANCE_COMPENSATION_CONTROL); |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 3128 | rt2800_bbp_write(rt2x00dev, 159, cal != 0xff ? cal : 0); |
| 3129 | } |
| 3130 | |
Gabor Juhos | 97aa03f | 2013-07-08 16:08:23 +0200 | [diff] [blame] | 3131 | static char rt2800_txpower_to_dev(struct rt2x00_dev *rt2x00dev, |
| 3132 | unsigned int channel, |
| 3133 | char txpower) |
| 3134 | { |
Gabor Juhos | fc739cf | 2013-07-08 16:08:24 +0200 | [diff] [blame] | 3135 | if (rt2x00_rt(rt2x00dev, RT3593)) |
| 3136 | txpower = rt2x00_get_field8(txpower, EEPROM_TXPOWER_ALC); |
| 3137 | |
Gabor Juhos | 97aa03f | 2013-07-08 16:08:23 +0200 | [diff] [blame] | 3138 | if (channel <= 14) |
| 3139 | return clamp_t(char, txpower, MIN_G_TXPOWER, MAX_G_TXPOWER); |
Gabor Juhos | fc739cf | 2013-07-08 16:08:24 +0200 | [diff] [blame] | 3140 | |
| 3141 | if (rt2x00_rt(rt2x00dev, RT3593)) |
| 3142 | return clamp_t(char, txpower, MIN_A_TXPOWER_3593, |
| 3143 | MAX_A_TXPOWER_3593); |
Gabor Juhos | 97aa03f | 2013-07-08 16:08:23 +0200 | [diff] [blame] | 3144 | else |
| 3145 | return clamp_t(char, txpower, MIN_A_TXPOWER, MAX_A_TXPOWER); |
| 3146 | } |
| 3147 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3148 | static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev, |
| 3149 | struct ieee80211_conf *conf, |
| 3150 | struct rf_channel *rf, |
| 3151 | struct channel_info *info) |
| 3152 | { |
| 3153 | u32 reg; |
| 3154 | unsigned int tx_pin; |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 3155 | u8 bbp, rfcsr; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3156 | |
Gabor Juhos | 97aa03f | 2013-07-08 16:08:23 +0200 | [diff] [blame] | 3157 | info->default_power1 = rt2800_txpower_to_dev(rt2x00dev, rf->channel, |
| 3158 | info->default_power1); |
| 3159 | info->default_power2 = rt2800_txpower_to_dev(rt2x00dev, rf->channel, |
| 3160 | info->default_power2); |
Gabor Juhos | c0a1436 | 2013-07-08 16:08:28 +0200 | [diff] [blame] | 3161 | if (rt2x00dev->default_ant.tx_chain_num > 2) |
| 3162 | info->default_power3 = |
| 3163 | rt2800_txpower_to_dev(rt2x00dev, rf->channel, |
| 3164 | info->default_power3); |
Ivo van Doorn | 46323e1 | 2010-08-23 19:55:43 +0200 | [diff] [blame] | 3165 | |
Gertjan van Wingerde | 5aa5701 | 2011-12-28 01:53:20 +0100 | [diff] [blame] | 3166 | switch (rt2x00dev->chip.rf) { |
| 3167 | case RF2020: |
| 3168 | case RF3020: |
| 3169 | case RF3021: |
| 3170 | case RF3022: |
| 3171 | case RF3320: |
Gertjan van Wingerde | 06855ef | 2010-04-11 14:31:07 +0200 | [diff] [blame] | 3172 | rt2800_config_channel_rf3xxx(rt2x00dev, conf, rf, info); |
Gertjan van Wingerde | 5aa5701 | 2011-12-28 01:53:20 +0100 | [diff] [blame] | 3173 | break; |
| 3174 | case RF3052: |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 3175 | rt2800_config_channel_rf3052(rt2x00dev, conf, rf, info); |
Gertjan van Wingerde | 5aa5701 | 2011-12-28 01:53:20 +0100 | [diff] [blame] | 3176 | break; |
Gabor Juhos | f42b046 | 2013-07-08 16:08:30 +0200 | [diff] [blame] | 3177 | case RF3053: |
| 3178 | rt2800_config_channel_rf3053(rt2x00dev, conf, rf, info); |
| 3179 | break; |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 3180 | case RF3290: |
| 3181 | rt2800_config_channel_rf3290(rt2x00dev, conf, rf, info); |
| 3182 | break; |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 3183 | case RF3322: |
| 3184 | rt2800_config_channel_rf3322(rt2x00dev, conf, rf, info); |
| 3185 | break; |
Stanislaw Gruszka | 3b9b74b | 2013-09-25 15:34:55 +0200 | [diff] [blame] | 3186 | case RF3070: |
villacis@palosanto.com | ccf91bd | 2012-05-16 21:07:12 +0200 | [diff] [blame] | 3187 | case RF5360: |
Canek Peláez Valdés | ac0372a | 2014-08-24 19:06:11 -0500 | [diff] [blame] | 3188 | case RF5362: |
Gertjan van Wingerde | 5aa5701 | 2011-12-28 01:53:20 +0100 | [diff] [blame] | 3189 | case RF5370: |
John Li | 2ed7188 | 2012-02-17 17:33:06 +0800 | [diff] [blame] | 3190 | case RF5372: |
Gertjan van Wingerde | 5aa5701 | 2011-12-28 01:53:20 +0100 | [diff] [blame] | 3191 | case RF5390: |
Zero.Lin | cff3d1f | 2012-05-29 16:11:09 +0800 | [diff] [blame] | 3192 | case RF5392: |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3193 | rt2800_config_channel_rf53xx(rt2x00dev, conf, rf, info); |
Gertjan van Wingerde | 5aa5701 | 2011-12-28 01:53:20 +0100 | [diff] [blame] | 3194 | break; |
Stanislaw Gruszka | 8f82109 | 2013-03-16 19:19:32 +0100 | [diff] [blame] | 3195 | case RF5592: |
| 3196 | rt2800_config_channel_rf55xx(rt2x00dev, conf, rf, info); |
| 3197 | break; |
Gertjan van Wingerde | 5aa5701 | 2011-12-28 01:53:20 +0100 | [diff] [blame] | 3198 | default: |
Gertjan van Wingerde | 06855ef | 2010-04-11 14:31:07 +0200 | [diff] [blame] | 3199 | rt2800_config_channel_rf2xxx(rt2x00dev, conf, rf, info); |
Gertjan van Wingerde | 5aa5701 | 2011-12-28 01:53:20 +0100 | [diff] [blame] | 3200 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3201 | |
Stanislaw Gruszka | 3b9b74b | 2013-09-25 15:34:55 +0200 | [diff] [blame] | 3202 | if (rt2x00_rf(rt2x00dev, RF3070) || |
| 3203 | rt2x00_rf(rt2x00dev, RF3290) || |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 3204 | rt2x00_rf(rt2x00dev, RF3322) || |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 3205 | rt2x00_rf(rt2x00dev, RF5360) || |
Canek Peláez Valdés | ac0372a | 2014-08-24 19:06:11 -0500 | [diff] [blame] | 3206 | rt2x00_rf(rt2x00dev, RF5362) || |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 3207 | rt2x00_rf(rt2x00dev, RF5370) || |
| 3208 | rt2x00_rf(rt2x00dev, RF5372) || |
| 3209 | rt2x00_rf(rt2x00dev, RF5390) || |
| 3210 | rt2x00_rf(rt2x00dev, RF5392)) { |
| 3211 | rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr); |
| 3212 | rt2x00_set_field8(&rfcsr, RFCSR30_TX_H20M, 0); |
| 3213 | rt2x00_set_field8(&rfcsr, RFCSR30_RX_H20M, 0); |
| 3214 | rt2800_rfcsr_write(rt2x00dev, 30, rfcsr); |
| 3215 | |
| 3216 | rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr); |
Gabor Juhos | d6d8202 | 2012-12-02 18:34:47 +0100 | [diff] [blame] | 3217 | rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1); |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 3218 | rt2800_rfcsr_write(rt2x00dev, 3, rfcsr); |
| 3219 | } |
| 3220 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3221 | /* |
| 3222 | * Change BBP settings |
| 3223 | */ |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 3224 | if (rt2x00_rt(rt2x00dev, RT3352)) { |
| 3225 | rt2800_bbp_write(rt2x00dev, 27, 0x0); |
Daniel Golle | cf193f6 | 2012-10-04 01:20:41 +0200 | [diff] [blame] | 3226 | rt2800_bbp_write(rt2x00dev, 66, 0x26 + rt2x00dev->lna_gain); |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 3227 | rt2800_bbp_write(rt2x00dev, 27, 0x20); |
Daniel Golle | cf193f6 | 2012-10-04 01:20:41 +0200 | [diff] [blame] | 3228 | rt2800_bbp_write(rt2x00dev, 66, 0x26 + rt2x00dev->lna_gain); |
Gabor Juhos | f42b046 | 2013-07-08 16:08:30 +0200 | [diff] [blame] | 3229 | } else if (rt2x00_rt(rt2x00dev, RT3593)) { |
| 3230 | if (rf->channel > 14) { |
| 3231 | /* Disable CCK Packet detection on 5GHz */ |
| 3232 | rt2800_bbp_write(rt2x00dev, 70, 0x00); |
| 3233 | } else { |
| 3234 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
| 3235 | } |
| 3236 | |
| 3237 | if (conf_is_ht40(conf)) |
| 3238 | rt2800_bbp_write(rt2x00dev, 105, 0x04); |
| 3239 | else |
| 3240 | rt2800_bbp_write(rt2x00dev, 105, 0x34); |
| 3241 | |
| 3242 | rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain); |
| 3243 | rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain); |
| 3244 | rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain); |
| 3245 | rt2800_bbp_write(rt2x00dev, 77, 0x98); |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 3246 | } else { |
| 3247 | rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain); |
| 3248 | rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain); |
| 3249 | rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain); |
| 3250 | rt2800_bbp_write(rt2x00dev, 86, 0); |
| 3251 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3252 | |
| 3253 | if (rf->channel <= 14) { |
John Li | 2ed7188 | 2012-02-17 17:33:06 +0800 | [diff] [blame] | 3254 | if (!rt2x00_rt(rt2x00dev, RT5390) && |
Gabor Juhos | e6d227b | 2012-12-02 15:53:28 +0100 | [diff] [blame] | 3255 | !rt2x00_rt(rt2x00dev, RT5392)) { |
Gabor Juhos | c429dfe | 2013-10-11 13:18:42 +0200 | [diff] [blame] | 3256 | if (rt2x00_has_cap_external_lna_bg(rt2x00dev)) { |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3257 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
| 3258 | rt2800_bbp_write(rt2x00dev, 75, 0x46); |
| 3259 | } else { |
Gabor Juhos | f42b046 | 2013-07-08 16:08:30 +0200 | [diff] [blame] | 3260 | if (rt2x00_rt(rt2x00dev, RT3593)) |
| 3261 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
| 3262 | else |
| 3263 | rt2800_bbp_write(rt2x00dev, 82, 0x84); |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3264 | rt2800_bbp_write(rt2x00dev, 75, 0x50); |
| 3265 | } |
Gabor Juhos | f42b046 | 2013-07-08 16:08:30 +0200 | [diff] [blame] | 3266 | if (rt2x00_rt(rt2x00dev, RT3593)) |
| 3267 | rt2800_bbp_write(rt2x00dev, 83, 0x8a); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3268 | } |
Gabor Juhos | f42b046 | 2013-07-08 16:08:30 +0200 | [diff] [blame] | 3269 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3270 | } else { |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 3271 | if (rt2x00_rt(rt2x00dev, RT3572)) |
| 3272 | rt2800_bbp_write(rt2x00dev, 82, 0x94); |
Gabor Juhos | f42b046 | 2013-07-08 16:08:30 +0200 | [diff] [blame] | 3273 | else if (rt2x00_rt(rt2x00dev, RT3593)) |
| 3274 | rt2800_bbp_write(rt2x00dev, 82, 0x82); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 3275 | else |
| 3276 | rt2800_bbp_write(rt2x00dev, 82, 0xf2); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3277 | |
Gabor Juhos | f42b046 | 2013-07-08 16:08:30 +0200 | [diff] [blame] | 3278 | if (rt2x00_rt(rt2x00dev, RT3593)) |
| 3279 | rt2800_bbp_write(rt2x00dev, 83, 0x9a); |
| 3280 | |
Gabor Juhos | c429dfe | 2013-10-11 13:18:42 +0200 | [diff] [blame] | 3281 | if (rt2x00_has_cap_external_lna_a(rt2x00dev)) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3282 | rt2800_bbp_write(rt2x00dev, 75, 0x46); |
| 3283 | else |
| 3284 | rt2800_bbp_write(rt2x00dev, 75, 0x50); |
| 3285 | } |
| 3286 | |
| 3287 | rt2800_register_read(rt2x00dev, TX_BAND_CFG, ®); |
Gertjan van Wingerde | a21ee72 | 2010-05-03 22:43:04 +0200 | [diff] [blame] | 3288 | 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] | 3289 | rt2x00_set_field32(®, TX_BAND_CFG_A, rf->channel > 14); |
| 3290 | rt2x00_set_field32(®, TX_BAND_CFG_BG, rf->channel <= 14); |
| 3291 | rt2800_register_write(rt2x00dev, TX_BAND_CFG, reg); |
| 3292 | |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 3293 | if (rt2x00_rt(rt2x00dev, RT3572)) |
| 3294 | rt2800_rfcsr_write(rt2x00dev, 8, 0); |
| 3295 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3296 | tx_pin = 0; |
| 3297 | |
Gabor Juhos | bb16d48 | 2013-06-24 23:03:24 +0200 | [diff] [blame] | 3298 | switch (rt2x00dev->default_ant.tx_chain_num) { |
| 3299 | case 3: |
| 3300 | /* Turn on tertiary PAs */ |
| 3301 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A2_EN, |
| 3302 | rf->channel > 14); |
| 3303 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G2_EN, |
| 3304 | rf->channel <= 14); |
| 3305 | /* fall-through */ |
| 3306 | case 2: |
| 3307 | /* Turn on secondary PAs */ |
Gertjan van Wingerde | 65f31b5 | 2011-05-18 20:25:05 +0200 | [diff] [blame] | 3308 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, |
| 3309 | rf->channel > 14); |
| 3310 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, |
| 3311 | rf->channel <= 14); |
Gabor Juhos | bb16d48 | 2013-06-24 23:03:24 +0200 | [diff] [blame] | 3312 | /* fall-through */ |
| 3313 | case 1: |
| 3314 | /* Turn on primary PAs */ |
| 3315 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, |
| 3316 | rf->channel > 14); |
Gabor Juhos | c429dfe | 2013-10-11 13:18:42 +0200 | [diff] [blame] | 3317 | if (rt2x00_has_cap_bt_coexist(rt2x00dev)) |
Gabor Juhos | bb16d48 | 2013-06-24 23:03:24 +0200 | [diff] [blame] | 3318 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, 1); |
| 3319 | else |
| 3320 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, |
| 3321 | rf->channel <= 14); |
| 3322 | break; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3323 | } |
| 3324 | |
Gabor Juhos | bb16d48 | 2013-06-24 23:03:24 +0200 | [diff] [blame] | 3325 | switch (rt2x00dev->default_ant.rx_chain_num) { |
| 3326 | case 3: |
| 3327 | /* Turn on tertiary LNAs */ |
| 3328 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A2_EN, 1); |
| 3329 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G2_EN, 1); |
| 3330 | /* fall-through */ |
| 3331 | case 2: |
| 3332 | /* Turn on secondary LNAs */ |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3333 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1); |
| 3334 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1); |
Gabor Juhos | bb16d48 | 2013-06-24 23:03:24 +0200 | [diff] [blame] | 3335 | /* fall-through */ |
| 3336 | case 1: |
| 3337 | /* Turn on primary LNAs */ |
| 3338 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN, 1); |
| 3339 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN, 1); |
| 3340 | break; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3341 | } |
| 3342 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3343 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1); |
| 3344 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_TRSW_EN, 1); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3345 | |
| 3346 | rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin); |
| 3347 | |
Gabor Juhos | 733aec6 | 2013-10-04 22:07:09 +0200 | [diff] [blame] | 3348 | if (rt2x00_rt(rt2x00dev, RT3572)) { |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 3349 | rt2800_rfcsr_write(rt2x00dev, 8, 0x80); |
| 3350 | |
Gabor Juhos | 733aec6 | 2013-10-04 22:07:09 +0200 | [diff] [blame] | 3351 | /* AGC init */ |
| 3352 | if (rf->channel <= 14) |
| 3353 | reg = 0x1c + (2 * rt2x00dev->lna_gain); |
| 3354 | else |
| 3355 | reg = 0x22 + ((rt2x00dev->lna_gain * 5) / 3); |
| 3356 | |
| 3357 | rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, reg); |
| 3358 | } |
| 3359 | |
Gabor Juhos | f42b046 | 2013-07-08 16:08:30 +0200 | [diff] [blame] | 3360 | if (rt2x00_rt(rt2x00dev, RT3593)) { |
Gabor Juhos | 6075100 | 2013-09-11 19:56:45 +0200 | [diff] [blame] | 3361 | rt2800_register_read(rt2x00dev, GPIO_CTRL, ®); |
Gabor Juhos | f42b046 | 2013-07-08 16:08:30 +0200 | [diff] [blame] | 3362 | |
Gabor Juhos | 6075100 | 2013-09-11 19:56:45 +0200 | [diff] [blame] | 3363 | /* Band selection */ |
| 3364 | if (rt2x00_is_usb(rt2x00dev) || |
| 3365 | rt2x00_is_pcie(rt2x00dev)) { |
| 3366 | /* GPIO #8 controls all paths */ |
Gabor Juhos | f42b046 | 2013-07-08 16:08:30 +0200 | [diff] [blame] | 3367 | rt2x00_set_field32(®, GPIO_CTRL_DIR8, 0); |
| 3368 | if (rf->channel <= 14) |
| 3369 | rt2x00_set_field32(®, GPIO_CTRL_VAL8, 1); |
| 3370 | else |
| 3371 | rt2x00_set_field32(®, GPIO_CTRL_VAL8, 0); |
Gabor Juhos | 6075100 | 2013-09-11 19:56:45 +0200 | [diff] [blame] | 3372 | } |
Gabor Juhos | f42b046 | 2013-07-08 16:08:30 +0200 | [diff] [blame] | 3373 | |
Gabor Juhos | 6075100 | 2013-09-11 19:56:45 +0200 | [diff] [blame] | 3374 | /* LNA PE control. */ |
| 3375 | if (rt2x00_is_usb(rt2x00dev)) { |
| 3376 | /* GPIO #4 controls PE0 and PE1, |
| 3377 | * GPIO #7 controls PE2 |
| 3378 | */ |
Gabor Juhos | f42b046 | 2013-07-08 16:08:30 +0200 | [diff] [blame] | 3379 | rt2x00_set_field32(®, GPIO_CTRL_DIR4, 0); |
| 3380 | rt2x00_set_field32(®, GPIO_CTRL_DIR7, 0); |
| 3381 | |
Gabor Juhos | f42b046 | 2013-07-08 16:08:30 +0200 | [diff] [blame] | 3382 | rt2x00_set_field32(®, GPIO_CTRL_VAL4, 1); |
| 3383 | rt2x00_set_field32(®, GPIO_CTRL_VAL7, 1); |
Gabor Juhos | 6075100 | 2013-09-11 19:56:45 +0200 | [diff] [blame] | 3384 | } else if (rt2x00_is_pcie(rt2x00dev)) { |
| 3385 | /* GPIO #4 controls PE0, PE1 and PE2 */ |
| 3386 | rt2x00_set_field32(®, GPIO_CTRL_DIR4, 0); |
| 3387 | rt2x00_set_field32(®, GPIO_CTRL_VAL4, 1); |
Gabor Juhos | f42b046 | 2013-07-08 16:08:30 +0200 | [diff] [blame] | 3388 | } |
| 3389 | |
Gabor Juhos | 6075100 | 2013-09-11 19:56:45 +0200 | [diff] [blame] | 3390 | rt2800_register_write(rt2x00dev, GPIO_CTRL, reg); |
| 3391 | |
Gabor Juhos | f42b046 | 2013-07-08 16:08:30 +0200 | [diff] [blame] | 3392 | /* AGC init */ |
| 3393 | if (rf->channel <= 14) |
| 3394 | reg = 0x1c + 2 * rt2x00dev->lna_gain; |
| 3395 | else |
| 3396 | reg = 0x22 + ((rt2x00dev->lna_gain * 5) / 3); |
| 3397 | |
| 3398 | rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, reg); |
| 3399 | |
| 3400 | usleep_range(1000, 1500); |
| 3401 | } |
| 3402 | |
Stanislaw Gruszka | 6803141 | 2013-03-16 19:19:44 +0100 | [diff] [blame] | 3403 | if (rt2x00_rt(rt2x00dev, RT5592)) { |
| 3404 | rt2800_bbp_write(rt2x00dev, 195, 141); |
| 3405 | rt2800_bbp_write(rt2x00dev, 196, conf_is_ht40(conf) ? 0x10 : 0x1a); |
| 3406 | |
Stanislaw Gruszka | 8ba0ebf | 2013-03-16 19:19:48 +0100 | [diff] [blame] | 3407 | /* AGC init */ |
| 3408 | reg = (rf->channel <= 14 ? 0x1c : 0x24) + 2 * rt2x00dev->lna_gain; |
| 3409 | rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, reg); |
| 3410 | |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 3411 | rt2800_iq_calibrate(rt2x00dev, rf->channel); |
Stanislaw Gruszka | 6803141 | 2013-03-16 19:19:44 +0100 | [diff] [blame] | 3412 | } |
| 3413 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3414 | rt2800_bbp_read(rt2x00dev, 4, &bbp); |
| 3415 | rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * conf_is_ht40(conf)); |
| 3416 | rt2800_bbp_write(rt2x00dev, 4, bbp); |
| 3417 | |
| 3418 | rt2800_bbp_read(rt2x00dev, 3, &bbp); |
Gertjan van Wingerde | a21ee72 | 2010-05-03 22:43:04 +0200 | [diff] [blame] | 3419 | rt2x00_set_field8(&bbp, BBP3_HT40_MINUS, conf_is_ht40_minus(conf)); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3420 | rt2800_bbp_write(rt2x00dev, 3, bbp); |
| 3421 | |
Gertjan van Wingerde | 8d0c9b6 | 2010-04-11 14:31:10 +0200 | [diff] [blame] | 3422 | if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3423 | if (conf_is_ht40(conf)) { |
| 3424 | rt2800_bbp_write(rt2x00dev, 69, 0x1a); |
| 3425 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
| 3426 | rt2800_bbp_write(rt2x00dev, 73, 0x16); |
| 3427 | } else { |
| 3428 | rt2800_bbp_write(rt2x00dev, 69, 0x16); |
| 3429 | rt2800_bbp_write(rt2x00dev, 70, 0x08); |
| 3430 | rt2800_bbp_write(rt2x00dev, 73, 0x11); |
| 3431 | } |
| 3432 | } |
| 3433 | |
| 3434 | msleep(1); |
Helmut Schaa | 977206d | 2010-12-13 12:31:58 +0100 | [diff] [blame] | 3435 | |
| 3436 | /* |
| 3437 | * Clear channel statistic counters |
| 3438 | */ |
| 3439 | rt2800_register_read(rt2x00dev, CH_IDLE_STA, ®); |
| 3440 | rt2800_register_read(rt2x00dev, CH_BUSY_STA, ®); |
| 3441 | rt2800_register_read(rt2x00dev, CH_BUSY_STA_SEC, ®); |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 3442 | |
| 3443 | /* |
| 3444 | * Clear update flag |
| 3445 | */ |
| 3446 | if (rt2x00_rt(rt2x00dev, RT3352)) { |
| 3447 | rt2800_bbp_read(rt2x00dev, 49, &bbp); |
| 3448 | rt2x00_set_field8(&bbp, BBP49_UPDATE_FLAG, 0); |
| 3449 | rt2800_bbp_write(rt2x00dev, 49, bbp); |
| 3450 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3451 | } |
| 3452 | |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3453 | static int rt2800_get_gain_calibration_delta(struct rt2x00_dev *rt2x00dev) |
| 3454 | { |
| 3455 | u8 tssi_bounds[9]; |
| 3456 | u8 current_tssi; |
| 3457 | u16 eeprom; |
| 3458 | u8 step; |
| 3459 | int i; |
| 3460 | |
| 3461 | /* |
Stanislaw Gruszka | 6e956da | 2013-08-26 15:18:53 +0200 | [diff] [blame] | 3462 | * First check if temperature compensation is supported. |
| 3463 | */ |
| 3464 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom); |
| 3465 | if (!rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_EXTERNAL_TX_ALC)) |
| 3466 | return 0; |
| 3467 | |
| 3468 | /* |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3469 | * Read TSSI boundaries for temperature compensation from |
| 3470 | * the EEPROM. |
| 3471 | * |
| 3472 | * Array idx 0 1 2 3 4 5 6 7 8 |
| 3473 | * Matching Delta value -4 -3 -2 -1 0 +1 +2 +3 +4 |
| 3474 | * Example TSSI bounds 0xF0 0xD0 0xB5 0xA0 0x88 0x45 0x25 0x15 0x00 |
| 3475 | */ |
| 3476 | if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 3477 | rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG1, &eeprom); |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3478 | tssi_bounds[0] = rt2x00_get_field16(eeprom, |
| 3479 | EEPROM_TSSI_BOUND_BG1_MINUS4); |
| 3480 | tssi_bounds[1] = rt2x00_get_field16(eeprom, |
| 3481 | EEPROM_TSSI_BOUND_BG1_MINUS3); |
| 3482 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 3483 | rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG2, &eeprom); |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3484 | tssi_bounds[2] = rt2x00_get_field16(eeprom, |
| 3485 | EEPROM_TSSI_BOUND_BG2_MINUS2); |
| 3486 | tssi_bounds[3] = rt2x00_get_field16(eeprom, |
| 3487 | EEPROM_TSSI_BOUND_BG2_MINUS1); |
| 3488 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 3489 | rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG3, &eeprom); |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3490 | tssi_bounds[4] = rt2x00_get_field16(eeprom, |
| 3491 | EEPROM_TSSI_BOUND_BG3_REF); |
| 3492 | tssi_bounds[5] = rt2x00_get_field16(eeprom, |
| 3493 | EEPROM_TSSI_BOUND_BG3_PLUS1); |
| 3494 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 3495 | rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG4, &eeprom); |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3496 | tssi_bounds[6] = rt2x00_get_field16(eeprom, |
| 3497 | EEPROM_TSSI_BOUND_BG4_PLUS2); |
| 3498 | tssi_bounds[7] = rt2x00_get_field16(eeprom, |
| 3499 | EEPROM_TSSI_BOUND_BG4_PLUS3); |
| 3500 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 3501 | rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG5, &eeprom); |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3502 | tssi_bounds[8] = rt2x00_get_field16(eeprom, |
| 3503 | EEPROM_TSSI_BOUND_BG5_PLUS4); |
| 3504 | |
| 3505 | step = rt2x00_get_field16(eeprom, |
| 3506 | EEPROM_TSSI_BOUND_BG5_AGC_STEP); |
| 3507 | } else { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 3508 | rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A1, &eeprom); |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3509 | tssi_bounds[0] = rt2x00_get_field16(eeprom, |
| 3510 | EEPROM_TSSI_BOUND_A1_MINUS4); |
| 3511 | tssi_bounds[1] = rt2x00_get_field16(eeprom, |
| 3512 | EEPROM_TSSI_BOUND_A1_MINUS3); |
| 3513 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 3514 | rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A2, &eeprom); |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3515 | tssi_bounds[2] = rt2x00_get_field16(eeprom, |
| 3516 | EEPROM_TSSI_BOUND_A2_MINUS2); |
| 3517 | tssi_bounds[3] = rt2x00_get_field16(eeprom, |
| 3518 | EEPROM_TSSI_BOUND_A2_MINUS1); |
| 3519 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 3520 | rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A3, &eeprom); |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3521 | tssi_bounds[4] = rt2x00_get_field16(eeprom, |
| 3522 | EEPROM_TSSI_BOUND_A3_REF); |
| 3523 | tssi_bounds[5] = rt2x00_get_field16(eeprom, |
| 3524 | EEPROM_TSSI_BOUND_A3_PLUS1); |
| 3525 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 3526 | rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A4, &eeprom); |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3527 | tssi_bounds[6] = rt2x00_get_field16(eeprom, |
| 3528 | EEPROM_TSSI_BOUND_A4_PLUS2); |
| 3529 | tssi_bounds[7] = rt2x00_get_field16(eeprom, |
| 3530 | EEPROM_TSSI_BOUND_A4_PLUS3); |
| 3531 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 3532 | rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A5, &eeprom); |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3533 | tssi_bounds[8] = rt2x00_get_field16(eeprom, |
| 3534 | EEPROM_TSSI_BOUND_A5_PLUS4); |
| 3535 | |
| 3536 | step = rt2x00_get_field16(eeprom, |
| 3537 | EEPROM_TSSI_BOUND_A5_AGC_STEP); |
| 3538 | } |
| 3539 | |
| 3540 | /* |
| 3541 | * Check if temperature compensation is supported. |
| 3542 | */ |
Stanislaw Gruszka | bf7e1ab | 2012-10-25 09:51:39 +0200 | [diff] [blame] | 3543 | if (tssi_bounds[4] == 0xff || step == 0xff) |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3544 | return 0; |
| 3545 | |
| 3546 | /* |
| 3547 | * Read current TSSI (BBP 49). |
| 3548 | */ |
| 3549 | rt2800_bbp_read(rt2x00dev, 49, ¤t_tssi); |
| 3550 | |
| 3551 | /* |
| 3552 | * Compare TSSI value (BBP49) with the compensation boundaries |
| 3553 | * from the EEPROM and increase or decrease tx power. |
| 3554 | */ |
| 3555 | for (i = 0; i <= 3; i++) { |
| 3556 | if (current_tssi > tssi_bounds[i]) |
| 3557 | break; |
| 3558 | } |
| 3559 | |
| 3560 | if (i == 4) { |
| 3561 | for (i = 8; i >= 5; i--) { |
| 3562 | if (current_tssi < tssi_bounds[i]) |
| 3563 | break; |
| 3564 | } |
| 3565 | } |
| 3566 | |
| 3567 | return (i - 4) * step; |
| 3568 | } |
| 3569 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3570 | static int rt2800_get_txpower_bw_comp(struct rt2x00_dev *rt2x00dev, |
| 3571 | enum ieee80211_band band) |
| 3572 | { |
| 3573 | u16 eeprom; |
| 3574 | u8 comp_en; |
| 3575 | u8 comp_type; |
Helmut Schaa | 75faae8 | 2011-03-28 13:31:30 +0200 | [diff] [blame] | 3576 | int comp_value = 0; |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3577 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 3578 | rt2800_eeprom_read(rt2x00dev, EEPROM_TXPOWER_DELTA, &eeprom); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3579 | |
Helmut Schaa | 75faae8 | 2011-03-28 13:31:30 +0200 | [diff] [blame] | 3580 | /* |
| 3581 | * HT40 compensation not required. |
| 3582 | */ |
| 3583 | if (eeprom == 0xffff || |
| 3584 | !test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags)) |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3585 | return 0; |
| 3586 | |
| 3587 | if (band == IEEE80211_BAND_2GHZ) { |
| 3588 | comp_en = rt2x00_get_field16(eeprom, |
| 3589 | EEPROM_TXPOWER_DELTA_ENABLE_2G); |
| 3590 | if (comp_en) { |
| 3591 | comp_type = rt2x00_get_field16(eeprom, |
| 3592 | EEPROM_TXPOWER_DELTA_TYPE_2G); |
| 3593 | comp_value = rt2x00_get_field16(eeprom, |
| 3594 | EEPROM_TXPOWER_DELTA_VALUE_2G); |
| 3595 | if (!comp_type) |
| 3596 | comp_value = -comp_value; |
| 3597 | } |
| 3598 | } else { |
| 3599 | comp_en = rt2x00_get_field16(eeprom, |
| 3600 | EEPROM_TXPOWER_DELTA_ENABLE_5G); |
| 3601 | if (comp_en) { |
| 3602 | comp_type = rt2x00_get_field16(eeprom, |
| 3603 | EEPROM_TXPOWER_DELTA_TYPE_5G); |
| 3604 | comp_value = rt2x00_get_field16(eeprom, |
| 3605 | EEPROM_TXPOWER_DELTA_VALUE_5G); |
| 3606 | if (!comp_type) |
| 3607 | comp_value = -comp_value; |
| 3608 | } |
| 3609 | } |
| 3610 | |
| 3611 | return comp_value; |
| 3612 | } |
| 3613 | |
Stanislaw Gruszka | 1e4cf24 | 2012-10-05 13:44:14 +0200 | [diff] [blame] | 3614 | static int rt2800_get_txpower_reg_delta(struct rt2x00_dev *rt2x00dev, |
| 3615 | int power_level, int max_power) |
| 3616 | { |
| 3617 | int delta; |
| 3618 | |
Gabor Juhos | c429dfe | 2013-10-11 13:18:42 +0200 | [diff] [blame] | 3619 | if (rt2x00_has_cap_power_limit(rt2x00dev)) |
Stanislaw Gruszka | 1e4cf24 | 2012-10-05 13:44:14 +0200 | [diff] [blame] | 3620 | return 0; |
| 3621 | |
| 3622 | /* |
| 3623 | * XXX: We don't know the maximum transmit power of our hardware since |
| 3624 | * the EEPROM doesn't expose it. We only know that we are calibrated |
| 3625 | * to 100% tx power. |
| 3626 | * |
| 3627 | * Hence, we assume the regulatory limit that cfg80211 calulated for |
| 3628 | * the current channel is our maximum and if we are requested to lower |
| 3629 | * the value we just reduce our tx power accordingly. |
| 3630 | */ |
| 3631 | delta = power_level - max_power; |
| 3632 | return min(delta, 0); |
| 3633 | } |
| 3634 | |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 3635 | static u8 rt2800_compensate_txpower(struct rt2x00_dev *rt2x00dev, int is_rate_b, |
| 3636 | enum ieee80211_band band, int power_level, |
| 3637 | u8 txpower, int delta) |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3638 | { |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3639 | u16 eeprom; |
| 3640 | u8 criterion; |
| 3641 | u8 eirp_txpower; |
| 3642 | u8 eirp_txpower_criterion; |
| 3643 | u8 reg_limit; |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3644 | |
Gabor Juhos | 34542ff | 2013-07-08 16:08:20 +0200 | [diff] [blame] | 3645 | if (rt2x00_rt(rt2x00dev, RT3593)) |
| 3646 | return min_t(u8, txpower, 0xc); |
| 3647 | |
Gabor Juhos | c429dfe | 2013-10-11 13:18:42 +0200 | [diff] [blame] | 3648 | if (rt2x00_has_cap_power_limit(rt2x00dev)) { |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3649 | /* |
| 3650 | * Check if eirp txpower exceed txpower_limit. |
| 3651 | * We use OFDM 6M as criterion and its eirp txpower |
| 3652 | * is stored at EEPROM_EIRP_MAX_TX_POWER. |
| 3653 | * .11b data rate need add additional 4dbm |
| 3654 | * when calculating eirp txpower. |
| 3655 | */ |
Gabor Juhos | 022138c | 2013-07-08 11:25:54 +0200 | [diff] [blame] | 3656 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE, |
| 3657 | 1, &eeprom); |
Stanislaw Gruszka | d9bceae | 2012-10-05 13:44:12 +0200 | [diff] [blame] | 3658 | criterion = rt2x00_get_field16(eeprom, |
| 3659 | EEPROM_TXPOWER_BYRATE_RATE0); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3660 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 3661 | rt2800_eeprom_read(rt2x00dev, EEPROM_EIRP_MAX_TX_POWER, |
Stanislaw Gruszka | d9bceae | 2012-10-05 13:44:12 +0200 | [diff] [blame] | 3662 | &eeprom); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3663 | |
| 3664 | if (band == IEEE80211_BAND_2GHZ) |
| 3665 | eirp_txpower_criterion = rt2x00_get_field16(eeprom, |
| 3666 | EEPROM_EIRP_MAX_TX_POWER_2GHZ); |
| 3667 | else |
| 3668 | eirp_txpower_criterion = rt2x00_get_field16(eeprom, |
| 3669 | EEPROM_EIRP_MAX_TX_POWER_5GHZ); |
| 3670 | |
| 3671 | eirp_txpower = eirp_txpower_criterion + (txpower - criterion) + |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 3672 | (is_rate_b ? 4 : 0) + delta; |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3673 | |
| 3674 | reg_limit = (eirp_txpower > power_level) ? |
| 3675 | (eirp_txpower - power_level) : 0; |
| 3676 | } else |
| 3677 | reg_limit = 0; |
| 3678 | |
Stanislaw Gruszka | 19f3fa2 | 2012-10-05 13:44:10 +0200 | [diff] [blame] | 3679 | txpower = max(0, txpower + delta - reg_limit); |
| 3680 | return min_t(u8, txpower, 0xc); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3681 | } |
| 3682 | |
Gabor Juhos | 34542ff | 2013-07-08 16:08:20 +0200 | [diff] [blame] | 3683 | |
| 3684 | enum { |
| 3685 | TX_PWR_CFG_0_IDX, |
| 3686 | TX_PWR_CFG_1_IDX, |
| 3687 | TX_PWR_CFG_2_IDX, |
| 3688 | TX_PWR_CFG_3_IDX, |
| 3689 | TX_PWR_CFG_4_IDX, |
| 3690 | TX_PWR_CFG_5_IDX, |
| 3691 | TX_PWR_CFG_6_IDX, |
| 3692 | TX_PWR_CFG_7_IDX, |
| 3693 | TX_PWR_CFG_8_IDX, |
| 3694 | TX_PWR_CFG_9_IDX, |
| 3695 | TX_PWR_CFG_0_EXT_IDX, |
| 3696 | TX_PWR_CFG_1_EXT_IDX, |
| 3697 | TX_PWR_CFG_2_EXT_IDX, |
| 3698 | TX_PWR_CFG_3_EXT_IDX, |
| 3699 | TX_PWR_CFG_4_EXT_IDX, |
| 3700 | TX_PWR_CFG_IDX_COUNT, |
| 3701 | }; |
| 3702 | |
| 3703 | static void rt2800_config_txpower_rt3593(struct rt2x00_dev *rt2x00dev, |
| 3704 | struct ieee80211_channel *chan, |
| 3705 | int power_level) |
| 3706 | { |
| 3707 | u8 txpower; |
| 3708 | u16 eeprom; |
| 3709 | u32 regs[TX_PWR_CFG_IDX_COUNT]; |
| 3710 | unsigned int offset; |
| 3711 | enum ieee80211_band band = chan->band; |
| 3712 | int delta; |
| 3713 | int i; |
| 3714 | |
| 3715 | memset(regs, '\0', sizeof(regs)); |
| 3716 | |
| 3717 | /* TODO: adapt TX power reduction from the rt28xx code */ |
| 3718 | |
| 3719 | /* calculate temperature compensation delta */ |
| 3720 | delta = rt2800_get_gain_calibration_delta(rt2x00dev); |
| 3721 | |
| 3722 | if (band == IEEE80211_BAND_5GHZ) |
| 3723 | offset = 16; |
| 3724 | else |
| 3725 | offset = 0; |
| 3726 | |
| 3727 | if (test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags)) |
| 3728 | offset += 8; |
| 3729 | |
| 3730 | /* read the next four txpower values */ |
| 3731 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE, |
| 3732 | offset, &eeprom); |
| 3733 | |
| 3734 | /* CCK 1MBS,2MBS */ |
| 3735 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0); |
| 3736 | txpower = rt2800_compensate_txpower(rt2x00dev, 1, band, power_level, |
| 3737 | txpower, delta); |
| 3738 | rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX], |
| 3739 | TX_PWR_CFG_0_CCK1_CH0, txpower); |
| 3740 | rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX], |
| 3741 | TX_PWR_CFG_0_CCK1_CH1, txpower); |
| 3742 | rt2x00_set_field32(®s[TX_PWR_CFG_0_EXT_IDX], |
| 3743 | TX_PWR_CFG_0_EXT_CCK1_CH2, txpower); |
| 3744 | |
| 3745 | /* CCK 5.5MBS,11MBS */ |
| 3746 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1); |
| 3747 | txpower = rt2800_compensate_txpower(rt2x00dev, 1, band, power_level, |
| 3748 | txpower, delta); |
| 3749 | rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX], |
| 3750 | TX_PWR_CFG_0_CCK5_CH0, txpower); |
| 3751 | rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX], |
| 3752 | TX_PWR_CFG_0_CCK5_CH1, txpower); |
| 3753 | rt2x00_set_field32(®s[TX_PWR_CFG_0_EXT_IDX], |
| 3754 | TX_PWR_CFG_0_EXT_CCK5_CH2, txpower); |
| 3755 | |
| 3756 | /* OFDM 6MBS,9MBS */ |
| 3757 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2); |
| 3758 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3759 | txpower, delta); |
| 3760 | rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX], |
| 3761 | TX_PWR_CFG_0_OFDM6_CH0, txpower); |
| 3762 | rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX], |
| 3763 | TX_PWR_CFG_0_OFDM6_CH1, txpower); |
| 3764 | rt2x00_set_field32(®s[TX_PWR_CFG_0_EXT_IDX], |
| 3765 | TX_PWR_CFG_0_EXT_OFDM6_CH2, txpower); |
| 3766 | |
| 3767 | /* OFDM 12MBS,18MBS */ |
| 3768 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3); |
| 3769 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3770 | txpower, delta); |
| 3771 | rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX], |
| 3772 | TX_PWR_CFG_0_OFDM12_CH0, txpower); |
| 3773 | rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX], |
| 3774 | TX_PWR_CFG_0_OFDM12_CH1, txpower); |
| 3775 | rt2x00_set_field32(®s[TX_PWR_CFG_0_EXT_IDX], |
| 3776 | TX_PWR_CFG_0_EXT_OFDM12_CH2, txpower); |
| 3777 | |
| 3778 | /* read the next four txpower values */ |
| 3779 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE, |
| 3780 | offset + 1, &eeprom); |
| 3781 | |
| 3782 | /* OFDM 24MBS,36MBS */ |
| 3783 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0); |
| 3784 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3785 | txpower, delta); |
| 3786 | rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX], |
| 3787 | TX_PWR_CFG_1_OFDM24_CH0, txpower); |
| 3788 | rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX], |
| 3789 | TX_PWR_CFG_1_OFDM24_CH1, txpower); |
| 3790 | rt2x00_set_field32(®s[TX_PWR_CFG_1_EXT_IDX], |
| 3791 | TX_PWR_CFG_1_EXT_OFDM24_CH2, txpower); |
| 3792 | |
| 3793 | /* OFDM 48MBS */ |
| 3794 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1); |
| 3795 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3796 | txpower, delta); |
| 3797 | rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX], |
| 3798 | TX_PWR_CFG_1_OFDM48_CH0, txpower); |
| 3799 | rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX], |
| 3800 | TX_PWR_CFG_1_OFDM48_CH1, txpower); |
| 3801 | rt2x00_set_field32(®s[TX_PWR_CFG_1_EXT_IDX], |
| 3802 | TX_PWR_CFG_1_EXT_OFDM48_CH2, txpower); |
| 3803 | |
| 3804 | /* OFDM 54MBS */ |
| 3805 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2); |
| 3806 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3807 | txpower, delta); |
| 3808 | rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX], |
| 3809 | TX_PWR_CFG_7_OFDM54_CH0, txpower); |
| 3810 | rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX], |
| 3811 | TX_PWR_CFG_7_OFDM54_CH1, txpower); |
| 3812 | rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX], |
| 3813 | TX_PWR_CFG_7_OFDM54_CH2, txpower); |
| 3814 | |
| 3815 | /* read the next four txpower values */ |
| 3816 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE, |
| 3817 | offset + 2, &eeprom); |
| 3818 | |
| 3819 | /* MCS 0,1 */ |
| 3820 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0); |
| 3821 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3822 | txpower, delta); |
| 3823 | rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX], |
| 3824 | TX_PWR_CFG_1_MCS0_CH0, txpower); |
| 3825 | rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX], |
| 3826 | TX_PWR_CFG_1_MCS0_CH1, txpower); |
| 3827 | rt2x00_set_field32(®s[TX_PWR_CFG_1_EXT_IDX], |
| 3828 | TX_PWR_CFG_1_EXT_MCS0_CH2, txpower); |
| 3829 | |
| 3830 | /* MCS 2,3 */ |
| 3831 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1); |
| 3832 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3833 | txpower, delta); |
| 3834 | rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX], |
| 3835 | TX_PWR_CFG_1_MCS2_CH0, txpower); |
| 3836 | rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX], |
| 3837 | TX_PWR_CFG_1_MCS2_CH1, txpower); |
| 3838 | rt2x00_set_field32(®s[TX_PWR_CFG_1_EXT_IDX], |
| 3839 | TX_PWR_CFG_1_EXT_MCS2_CH2, txpower); |
| 3840 | |
| 3841 | /* MCS 4,5 */ |
| 3842 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2); |
| 3843 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3844 | txpower, delta); |
| 3845 | rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX], |
| 3846 | TX_PWR_CFG_2_MCS4_CH0, txpower); |
| 3847 | rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX], |
| 3848 | TX_PWR_CFG_2_MCS4_CH1, txpower); |
| 3849 | rt2x00_set_field32(®s[TX_PWR_CFG_2_EXT_IDX], |
| 3850 | TX_PWR_CFG_2_EXT_MCS4_CH2, txpower); |
| 3851 | |
| 3852 | /* MCS 6 */ |
| 3853 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3); |
| 3854 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3855 | txpower, delta); |
| 3856 | rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX], |
| 3857 | TX_PWR_CFG_2_MCS6_CH0, txpower); |
| 3858 | rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX], |
| 3859 | TX_PWR_CFG_2_MCS6_CH1, txpower); |
| 3860 | rt2x00_set_field32(®s[TX_PWR_CFG_2_EXT_IDX], |
| 3861 | TX_PWR_CFG_2_EXT_MCS6_CH2, txpower); |
| 3862 | |
| 3863 | /* read the next four txpower values */ |
| 3864 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE, |
| 3865 | offset + 3, &eeprom); |
| 3866 | |
| 3867 | /* MCS 7 */ |
| 3868 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0); |
| 3869 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3870 | txpower, delta); |
| 3871 | rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX], |
| 3872 | TX_PWR_CFG_7_MCS7_CH0, txpower); |
| 3873 | rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX], |
| 3874 | TX_PWR_CFG_7_MCS7_CH1, txpower); |
| 3875 | rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX], |
| 3876 | TX_PWR_CFG_7_MCS7_CH2, txpower); |
| 3877 | |
| 3878 | /* MCS 8,9 */ |
| 3879 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1); |
| 3880 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3881 | txpower, delta); |
| 3882 | rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX], |
| 3883 | TX_PWR_CFG_2_MCS8_CH0, txpower); |
| 3884 | rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX], |
| 3885 | TX_PWR_CFG_2_MCS8_CH1, txpower); |
| 3886 | rt2x00_set_field32(®s[TX_PWR_CFG_2_EXT_IDX], |
| 3887 | TX_PWR_CFG_2_EXT_MCS8_CH2, txpower); |
| 3888 | |
| 3889 | /* MCS 10,11 */ |
| 3890 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2); |
| 3891 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3892 | txpower, delta); |
| 3893 | rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX], |
| 3894 | TX_PWR_CFG_2_MCS10_CH0, txpower); |
| 3895 | rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX], |
| 3896 | TX_PWR_CFG_2_MCS10_CH1, txpower); |
| 3897 | rt2x00_set_field32(®s[TX_PWR_CFG_2_EXT_IDX], |
| 3898 | TX_PWR_CFG_2_EXT_MCS10_CH2, txpower); |
| 3899 | |
| 3900 | /* MCS 12,13 */ |
| 3901 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3); |
| 3902 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3903 | txpower, delta); |
| 3904 | rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX], |
| 3905 | TX_PWR_CFG_3_MCS12_CH0, txpower); |
| 3906 | rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX], |
| 3907 | TX_PWR_CFG_3_MCS12_CH1, txpower); |
| 3908 | rt2x00_set_field32(®s[TX_PWR_CFG_3_EXT_IDX], |
| 3909 | TX_PWR_CFG_3_EXT_MCS12_CH2, txpower); |
| 3910 | |
| 3911 | /* read the next four txpower values */ |
| 3912 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE, |
| 3913 | offset + 4, &eeprom); |
| 3914 | |
| 3915 | /* MCS 14 */ |
| 3916 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0); |
| 3917 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3918 | txpower, delta); |
| 3919 | rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX], |
| 3920 | TX_PWR_CFG_3_MCS14_CH0, txpower); |
| 3921 | rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX], |
| 3922 | TX_PWR_CFG_3_MCS14_CH1, txpower); |
| 3923 | rt2x00_set_field32(®s[TX_PWR_CFG_3_EXT_IDX], |
| 3924 | TX_PWR_CFG_3_EXT_MCS14_CH2, txpower); |
| 3925 | |
| 3926 | /* MCS 15 */ |
| 3927 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1); |
| 3928 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3929 | txpower, delta); |
| 3930 | rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX], |
| 3931 | TX_PWR_CFG_8_MCS15_CH0, txpower); |
| 3932 | rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX], |
| 3933 | TX_PWR_CFG_8_MCS15_CH1, txpower); |
| 3934 | rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX], |
| 3935 | TX_PWR_CFG_8_MCS15_CH2, txpower); |
| 3936 | |
| 3937 | /* MCS 16,17 */ |
| 3938 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2); |
| 3939 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3940 | txpower, delta); |
| 3941 | rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX], |
| 3942 | TX_PWR_CFG_5_MCS16_CH0, txpower); |
| 3943 | rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX], |
| 3944 | TX_PWR_CFG_5_MCS16_CH1, txpower); |
| 3945 | rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX], |
| 3946 | TX_PWR_CFG_5_MCS16_CH2, txpower); |
| 3947 | |
| 3948 | /* MCS 18,19 */ |
| 3949 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3); |
| 3950 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3951 | txpower, delta); |
| 3952 | rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX], |
| 3953 | TX_PWR_CFG_5_MCS18_CH0, txpower); |
| 3954 | rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX], |
| 3955 | TX_PWR_CFG_5_MCS18_CH1, txpower); |
| 3956 | rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX], |
| 3957 | TX_PWR_CFG_5_MCS18_CH2, txpower); |
| 3958 | |
| 3959 | /* read the next four txpower values */ |
| 3960 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE, |
| 3961 | offset + 5, &eeprom); |
| 3962 | |
| 3963 | /* MCS 20,21 */ |
| 3964 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0); |
| 3965 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3966 | txpower, delta); |
| 3967 | rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX], |
| 3968 | TX_PWR_CFG_6_MCS20_CH0, txpower); |
| 3969 | rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX], |
| 3970 | TX_PWR_CFG_6_MCS20_CH1, txpower); |
| 3971 | rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX], |
| 3972 | TX_PWR_CFG_6_MCS20_CH2, txpower); |
| 3973 | |
| 3974 | /* MCS 22 */ |
| 3975 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1); |
| 3976 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3977 | txpower, delta); |
| 3978 | rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX], |
| 3979 | TX_PWR_CFG_6_MCS22_CH0, txpower); |
| 3980 | rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX], |
| 3981 | TX_PWR_CFG_6_MCS22_CH1, txpower); |
| 3982 | rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX], |
| 3983 | TX_PWR_CFG_6_MCS22_CH2, txpower); |
| 3984 | |
| 3985 | /* MCS 23 */ |
| 3986 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2); |
| 3987 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3988 | txpower, delta); |
| 3989 | rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX], |
| 3990 | TX_PWR_CFG_8_MCS23_CH0, txpower); |
| 3991 | rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX], |
| 3992 | TX_PWR_CFG_8_MCS23_CH1, txpower); |
| 3993 | rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX], |
| 3994 | TX_PWR_CFG_8_MCS23_CH2, txpower); |
| 3995 | |
| 3996 | /* read the next four txpower values */ |
| 3997 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE, |
| 3998 | offset + 6, &eeprom); |
| 3999 | |
| 4000 | /* STBC, MCS 0,1 */ |
| 4001 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0); |
| 4002 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 4003 | txpower, delta); |
| 4004 | rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX], |
| 4005 | TX_PWR_CFG_3_STBC0_CH0, txpower); |
| 4006 | rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX], |
| 4007 | TX_PWR_CFG_3_STBC0_CH1, txpower); |
| 4008 | rt2x00_set_field32(®s[TX_PWR_CFG_3_EXT_IDX], |
| 4009 | TX_PWR_CFG_3_EXT_STBC0_CH2, txpower); |
| 4010 | |
| 4011 | /* STBC, MCS 2,3 */ |
| 4012 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1); |
| 4013 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 4014 | txpower, delta); |
| 4015 | rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX], |
| 4016 | TX_PWR_CFG_3_STBC2_CH0, txpower); |
| 4017 | rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX], |
| 4018 | TX_PWR_CFG_3_STBC2_CH1, txpower); |
| 4019 | rt2x00_set_field32(®s[TX_PWR_CFG_3_EXT_IDX], |
| 4020 | TX_PWR_CFG_3_EXT_STBC2_CH2, txpower); |
| 4021 | |
| 4022 | /* STBC, MCS 4,5 */ |
| 4023 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2); |
| 4024 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 4025 | txpower, delta); |
| 4026 | rt2x00_set_field32(®s[TX_PWR_CFG_4_IDX], TX_PWR_CFG_RATE0, txpower); |
| 4027 | rt2x00_set_field32(®s[TX_PWR_CFG_4_IDX], TX_PWR_CFG_RATE1, txpower); |
| 4028 | rt2x00_set_field32(®s[TX_PWR_CFG_4_EXT_IDX], TX_PWR_CFG_RATE0, |
| 4029 | txpower); |
| 4030 | |
| 4031 | /* STBC, MCS 6 */ |
| 4032 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3); |
| 4033 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 4034 | txpower, delta); |
| 4035 | rt2x00_set_field32(®s[TX_PWR_CFG_4_IDX], TX_PWR_CFG_RATE2, txpower); |
| 4036 | rt2x00_set_field32(®s[TX_PWR_CFG_4_IDX], TX_PWR_CFG_RATE3, txpower); |
| 4037 | rt2x00_set_field32(®s[TX_PWR_CFG_4_EXT_IDX], TX_PWR_CFG_RATE2, |
| 4038 | txpower); |
| 4039 | |
| 4040 | /* read the next four txpower values */ |
| 4041 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE, |
| 4042 | offset + 7, &eeprom); |
| 4043 | |
| 4044 | /* STBC, MCS 7 */ |
| 4045 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0); |
| 4046 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 4047 | txpower, delta); |
| 4048 | rt2x00_set_field32(®s[TX_PWR_CFG_9_IDX], |
| 4049 | TX_PWR_CFG_9_STBC7_CH0, txpower); |
| 4050 | rt2x00_set_field32(®s[TX_PWR_CFG_9_IDX], |
| 4051 | TX_PWR_CFG_9_STBC7_CH1, txpower); |
| 4052 | rt2x00_set_field32(®s[TX_PWR_CFG_9_IDX], |
| 4053 | TX_PWR_CFG_9_STBC7_CH2, txpower); |
| 4054 | |
| 4055 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_0, regs[TX_PWR_CFG_0_IDX]); |
| 4056 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_1, regs[TX_PWR_CFG_1_IDX]); |
| 4057 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_2, regs[TX_PWR_CFG_2_IDX]); |
| 4058 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_3, regs[TX_PWR_CFG_3_IDX]); |
| 4059 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_4, regs[TX_PWR_CFG_4_IDX]); |
| 4060 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_5, regs[TX_PWR_CFG_5_IDX]); |
| 4061 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_6, regs[TX_PWR_CFG_6_IDX]); |
| 4062 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_7, regs[TX_PWR_CFG_7_IDX]); |
| 4063 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_8, regs[TX_PWR_CFG_8_IDX]); |
| 4064 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_9, regs[TX_PWR_CFG_9_IDX]); |
| 4065 | |
| 4066 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_0_EXT, |
| 4067 | regs[TX_PWR_CFG_0_EXT_IDX]); |
| 4068 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_1_EXT, |
| 4069 | regs[TX_PWR_CFG_1_EXT_IDX]); |
| 4070 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_2_EXT, |
| 4071 | regs[TX_PWR_CFG_2_EXT_IDX]); |
| 4072 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_3_EXT, |
| 4073 | regs[TX_PWR_CFG_3_EXT_IDX]); |
| 4074 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_4_EXT, |
| 4075 | regs[TX_PWR_CFG_4_EXT_IDX]); |
| 4076 | |
| 4077 | for (i = 0; i < TX_PWR_CFG_IDX_COUNT; i++) |
| 4078 | rt2x00_dbg(rt2x00dev, |
| 4079 | "band:%cGHz, BW:%c0MHz, TX_PWR_CFG_%d%s = %08lx\n", |
| 4080 | (band == IEEE80211_BAND_5GHZ) ? '5' : '2', |
| 4081 | (test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags)) ? |
| 4082 | '4' : '2', |
| 4083 | (i > TX_PWR_CFG_9_IDX) ? |
| 4084 | (i - TX_PWR_CFG_9_IDX - 1) : i, |
| 4085 | (i > TX_PWR_CFG_9_IDX) ? "_EXT" : "", |
| 4086 | (unsigned long) regs[i]); |
| 4087 | } |
| 4088 | |
Stanislaw Gruszka | 7a66205 | 2012-10-05 13:44:15 +0200 | [diff] [blame] | 4089 | /* |
| 4090 | * We configure transmit power using MAC TX_PWR_CFG_{0,...,N} registers and |
| 4091 | * BBP R1 register. TX_PWR_CFG_X allow to configure per rate TX power values, |
| 4092 | * 4 bits for each rate (tune from 0 to 15 dBm). BBP_R1 controls transmit power |
| 4093 | * for all rates, but allow to set only 4 discrete values: -12, -6, 0 and 6 dBm. |
| 4094 | * Reference per rate transmit power values are located in the EEPROM at |
| 4095 | * EEPROM_TXPOWER_BYRATE offset. We adjust them and BBP R1 settings according to |
| 4096 | * current conditions (i.e. band, bandwidth, temperature, user settings). |
| 4097 | */ |
Gabor Juhos | 34542ff | 2013-07-08 16:08:20 +0200 | [diff] [blame] | 4098 | static void rt2800_config_txpower_rt28xx(struct rt2x00_dev *rt2x00dev, |
| 4099 | struct ieee80211_channel *chan, |
| 4100 | int power_level) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4101 | { |
Stanislaw Gruszka | cee2c73 | 2012-10-05 13:44:09 +0200 | [diff] [blame] | 4102 | u8 txpower, r1; |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4103 | u16 eeprom; |
Stanislaw Gruszka | cee2c73 | 2012-10-05 13:44:09 +0200 | [diff] [blame] | 4104 | u32 reg, offset; |
| 4105 | int i, is_rate_b, delta, power_ctrl; |
Stanislaw Gruszka | 146c3b0 | 2012-10-05 13:44:13 +0200 | [diff] [blame] | 4106 | enum ieee80211_band band = chan->band; |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 4107 | |
| 4108 | /* |
Stanislaw Gruszka | 7a66205 | 2012-10-05 13:44:15 +0200 | [diff] [blame] | 4109 | * Calculate HT40 compensation. For 40MHz we need to add or subtract |
| 4110 | * value read from EEPROM (different for 2GHz and for 5GHz). |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 4111 | */ |
| 4112 | delta = rt2800_get_txpower_bw_comp(rt2x00dev, band); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4113 | |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4114 | /* |
Stanislaw Gruszka | 7a66205 | 2012-10-05 13:44:15 +0200 | [diff] [blame] | 4115 | * Calculate temperature compensation. Depends on measurement of current |
| 4116 | * TSSI (Transmitter Signal Strength Indication) we know TX power (due |
| 4117 | * to temperature or maybe other factors) is smaller or bigger than |
| 4118 | * expected. We adjust it, based on TSSI reference and boundaries values |
| 4119 | * provided in EEPROM. |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 4120 | */ |
Stanislaw Gruszka | 87dd2d7 | 2014-11-25 15:17:29 +0100 | [diff] [blame] | 4121 | switch (rt2x00dev->chip.rt) { |
| 4122 | case RT2860: |
| 4123 | case RT2872: |
| 4124 | case RT2883: |
| 4125 | case RT3070: |
| 4126 | case RT3071: |
| 4127 | case RT3090: |
| 4128 | case RT3572: |
| 4129 | delta += rt2800_get_gain_calibration_delta(rt2x00dev); |
| 4130 | break; |
| 4131 | default: |
| 4132 | /* TODO: temperature compensation code for other chips. */ |
| 4133 | break; |
| 4134 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4135 | |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4136 | /* |
Stanislaw Gruszka | 7a66205 | 2012-10-05 13:44:15 +0200 | [diff] [blame] | 4137 | * Decrease power according to user settings, on devices with unknown |
| 4138 | * maximum tx power. For other devices we take user power_level into |
| 4139 | * consideration on rt2800_compensate_txpower(). |
Stanislaw Gruszka | 1e4cf24 | 2012-10-05 13:44:14 +0200 | [diff] [blame] | 4140 | */ |
| 4141 | delta += rt2800_get_txpower_reg_delta(rt2x00dev, power_level, |
| 4142 | chan->max_power); |
| 4143 | |
| 4144 | /* |
Stanislaw Gruszka | cee2c73 | 2012-10-05 13:44:09 +0200 | [diff] [blame] | 4145 | * BBP_R1 controls TX power for all rates, it allow to set the following |
| 4146 | * gains -12, -6, 0, +6 dBm by setting values 2, 1, 0, 3 respectively. |
| 4147 | * |
| 4148 | * TODO: we do not use +6 dBm option to do not increase power beyond |
| 4149 | * regulatory limit, however this could be utilized for devices with |
| 4150 | * CAPABILITY_POWER_LIMIT. |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4151 | */ |
Stanislaw Gruszka | 87dd2d7 | 2014-11-25 15:17:29 +0100 | [diff] [blame] | 4152 | if (delta <= -12) { |
| 4153 | power_ctrl = 2; |
| 4154 | delta += 12; |
| 4155 | } else if (delta <= -6) { |
| 4156 | power_ctrl = 1; |
| 4157 | delta += 6; |
| 4158 | } else { |
| 4159 | power_ctrl = 0; |
Stanislaw Gruszka | cee2c73 | 2012-10-05 13:44:09 +0200 | [diff] [blame] | 4160 | } |
Stanislaw Gruszka | 87dd2d7 | 2014-11-25 15:17:29 +0100 | [diff] [blame] | 4161 | rt2800_bbp_read(rt2x00dev, 1, &r1); |
| 4162 | rt2x00_set_field8(&r1, BBP1_TX_POWER_CTRL, power_ctrl); |
| 4163 | rt2800_bbp_write(rt2x00dev, 1, r1); |
Stanislaw Gruszka | 8c8d2017 | 2013-06-11 18:48:53 +0200 | [diff] [blame] | 4164 | |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4165 | offset = TX_PWR_CFG_0; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4166 | |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4167 | for (i = 0; i < EEPROM_TXPOWER_BYRATE_SIZE; i += 2) { |
| 4168 | /* just to be safe */ |
| 4169 | if (offset > TX_PWR_CFG_4) |
| 4170 | break; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4171 | |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4172 | rt2800_register_read(rt2x00dev, offset, ®); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4173 | |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4174 | /* read the next four txpower values */ |
Gabor Juhos | 022138c | 2013-07-08 11:25:54 +0200 | [diff] [blame] | 4175 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE, |
| 4176 | i, &eeprom); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4177 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4178 | is_rate_b = i ? 0 : 1; |
| 4179 | /* |
| 4180 | * TX_PWR_CFG_0: 1MBS, TX_PWR_CFG_1: 24MBS, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4181 | * TX_PWR_CFG_2: MCS4, TX_PWR_CFG_3: MCS12, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4182 | * TX_PWR_CFG_4: unknown |
| 4183 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4184 | txpower = rt2x00_get_field16(eeprom, |
| 4185 | EEPROM_TXPOWER_BYRATE_RATE0); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 4186 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 4187 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4188 | rt2x00_set_field32(®, TX_PWR_CFG_RATE0, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4189 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4190 | /* |
| 4191 | * TX_PWR_CFG_0: 2MBS, TX_PWR_CFG_1: 36MBS, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4192 | * TX_PWR_CFG_2: MCS5, TX_PWR_CFG_3: MCS13, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4193 | * TX_PWR_CFG_4: unknown |
| 4194 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4195 | txpower = rt2x00_get_field16(eeprom, |
| 4196 | EEPROM_TXPOWER_BYRATE_RATE1); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 4197 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 4198 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4199 | rt2x00_set_field32(®, TX_PWR_CFG_RATE1, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4200 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4201 | /* |
| 4202 | * TX_PWR_CFG_0: 5.5MBS, TX_PWR_CFG_1: 48MBS, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4203 | * TX_PWR_CFG_2: MCS6, TX_PWR_CFG_3: MCS14, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4204 | * TX_PWR_CFG_4: unknown |
| 4205 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4206 | txpower = rt2x00_get_field16(eeprom, |
| 4207 | EEPROM_TXPOWER_BYRATE_RATE2); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 4208 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 4209 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4210 | rt2x00_set_field32(®, TX_PWR_CFG_RATE2, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4211 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4212 | /* |
| 4213 | * TX_PWR_CFG_0: 11MBS, TX_PWR_CFG_1: 54MBS, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4214 | * TX_PWR_CFG_2: MCS7, TX_PWR_CFG_3: MCS15, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4215 | * TX_PWR_CFG_4: unknown |
| 4216 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4217 | txpower = rt2x00_get_field16(eeprom, |
| 4218 | EEPROM_TXPOWER_BYRATE_RATE3); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 4219 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 4220 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4221 | rt2x00_set_field32(®, TX_PWR_CFG_RATE3, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4222 | |
| 4223 | /* read the next four txpower values */ |
Gabor Juhos | 022138c | 2013-07-08 11:25:54 +0200 | [diff] [blame] | 4224 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE, |
| 4225 | i + 1, &eeprom); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4226 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4227 | is_rate_b = 0; |
| 4228 | /* |
| 4229 | * TX_PWR_CFG_0: 6MBS, TX_PWR_CFG_1: MCS0, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4230 | * TX_PWR_CFG_2: MCS8, TX_PWR_CFG_3: unknown, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4231 | * TX_PWR_CFG_4: unknown |
| 4232 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4233 | txpower = rt2x00_get_field16(eeprom, |
| 4234 | EEPROM_TXPOWER_BYRATE_RATE0); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 4235 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 4236 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4237 | rt2x00_set_field32(®, TX_PWR_CFG_RATE4, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4238 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4239 | /* |
| 4240 | * TX_PWR_CFG_0: 9MBS, TX_PWR_CFG_1: MCS1, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4241 | * TX_PWR_CFG_2: MCS9, TX_PWR_CFG_3: unknown, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4242 | * TX_PWR_CFG_4: unknown |
| 4243 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4244 | txpower = rt2x00_get_field16(eeprom, |
| 4245 | EEPROM_TXPOWER_BYRATE_RATE1); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 4246 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 4247 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4248 | rt2x00_set_field32(®, TX_PWR_CFG_RATE5, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4249 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4250 | /* |
| 4251 | * TX_PWR_CFG_0: 12MBS, TX_PWR_CFG_1: MCS2, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4252 | * TX_PWR_CFG_2: MCS10, TX_PWR_CFG_3: unknown, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4253 | * TX_PWR_CFG_4: unknown |
| 4254 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4255 | txpower = rt2x00_get_field16(eeprom, |
| 4256 | EEPROM_TXPOWER_BYRATE_RATE2); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 4257 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 4258 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4259 | rt2x00_set_field32(®, TX_PWR_CFG_RATE6, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4260 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4261 | /* |
| 4262 | * TX_PWR_CFG_0: 18MBS, TX_PWR_CFG_1: MCS3, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4263 | * TX_PWR_CFG_2: MCS11, TX_PWR_CFG_3: unknown, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4264 | * TX_PWR_CFG_4: unknown |
| 4265 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4266 | txpower = rt2x00_get_field16(eeprom, |
| 4267 | EEPROM_TXPOWER_BYRATE_RATE3); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 4268 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 4269 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4270 | rt2x00_set_field32(®, TX_PWR_CFG_RATE7, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 4271 | |
| 4272 | rt2800_register_write(rt2x00dev, offset, reg); |
| 4273 | |
| 4274 | /* next TX_PWR_CFG register */ |
| 4275 | offset += 4; |
| 4276 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4277 | } |
| 4278 | |
Gabor Juhos | 34542ff | 2013-07-08 16:08:20 +0200 | [diff] [blame] | 4279 | static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev, |
| 4280 | struct ieee80211_channel *chan, |
| 4281 | int power_level) |
| 4282 | { |
| 4283 | if (rt2x00_rt(rt2x00dev, RT3593)) |
| 4284 | rt2800_config_txpower_rt3593(rt2x00dev, chan, power_level); |
| 4285 | else |
| 4286 | rt2800_config_txpower_rt28xx(rt2x00dev, chan, power_level); |
| 4287 | } |
| 4288 | |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 4289 | void rt2800_gain_calibration(struct rt2x00_dev *rt2x00dev) |
| 4290 | { |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 4291 | rt2800_config_txpower(rt2x00dev, rt2x00dev->hw->conf.chandef.chan, |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 4292 | rt2x00dev->tx_power); |
| 4293 | } |
| 4294 | EXPORT_SYMBOL_GPL(rt2800_gain_calibration); |
| 4295 | |
John Li | 2e9c43d | 2012-02-16 21:40:57 +0800 | [diff] [blame] | 4296 | void rt2800_vco_calibration(struct rt2x00_dev *rt2x00dev) |
| 4297 | { |
| 4298 | u32 tx_pin; |
| 4299 | u8 rfcsr; |
| 4300 | |
| 4301 | /* |
| 4302 | * A voltage-controlled oscillator(VCO) is an electronic oscillator |
| 4303 | * designed to be controlled in oscillation frequency by a voltage |
| 4304 | * input. Maybe the temperature will affect the frequency of |
| 4305 | * oscillation to be shifted. The VCO calibration will be called |
| 4306 | * periodically to adjust the frequency to be precision. |
| 4307 | */ |
| 4308 | |
| 4309 | rt2800_register_read(rt2x00dev, TX_PIN_CFG, &tx_pin); |
| 4310 | tx_pin &= TX_PIN_CFG_PA_PE_DISABLE; |
| 4311 | rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin); |
| 4312 | |
| 4313 | switch (rt2x00dev->chip.rf) { |
| 4314 | case RF2020: |
| 4315 | case RF3020: |
| 4316 | case RF3021: |
| 4317 | case RF3022: |
| 4318 | case RF3320: |
| 4319 | case RF3052: |
| 4320 | rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr); |
| 4321 | rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1); |
| 4322 | rt2800_rfcsr_write(rt2x00dev, 7, rfcsr); |
| 4323 | break; |
Gabor Juhos | 1095df0 | 2013-07-08 16:08:31 +0200 | [diff] [blame] | 4324 | case RF3053: |
Stanislaw Gruszka | 3b9b74b | 2013-09-25 15:34:55 +0200 | [diff] [blame] | 4325 | case RF3070: |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 4326 | case RF3290: |
villacis@palosanto.com | ccf91bd | 2012-05-16 21:07:12 +0200 | [diff] [blame] | 4327 | case RF5360: |
Canek Peláez Valdés | ac0372a | 2014-08-24 19:06:11 -0500 | [diff] [blame] | 4328 | case RF5362: |
John Li | 2e9c43d | 2012-02-16 21:40:57 +0800 | [diff] [blame] | 4329 | case RF5370: |
| 4330 | case RF5372: |
| 4331 | case RF5390: |
Zero.Lin | cff3d1f | 2012-05-29 16:11:09 +0800 | [diff] [blame] | 4332 | case RF5392: |
John Li | 2e9c43d | 2012-02-16 21:40:57 +0800 | [diff] [blame] | 4333 | rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr); |
Gabor Juhos | d6d8202 | 2012-12-02 18:34:47 +0100 | [diff] [blame] | 4334 | rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1); |
John Li | 2e9c43d | 2012-02-16 21:40:57 +0800 | [diff] [blame] | 4335 | rt2800_rfcsr_write(rt2x00dev, 3, rfcsr); |
| 4336 | break; |
| 4337 | default: |
| 4338 | return; |
| 4339 | } |
| 4340 | |
| 4341 | mdelay(1); |
| 4342 | |
| 4343 | rt2800_register_read(rt2x00dev, TX_PIN_CFG, &tx_pin); |
| 4344 | if (rt2x00dev->rf_channel <= 14) { |
| 4345 | switch (rt2x00dev->default_ant.tx_chain_num) { |
| 4346 | case 3: |
| 4347 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G2_EN, 1); |
| 4348 | /* fall through */ |
| 4349 | case 2: |
| 4350 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1); |
| 4351 | /* fall through */ |
| 4352 | case 1: |
| 4353 | default: |
| 4354 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, 1); |
| 4355 | break; |
| 4356 | } |
| 4357 | } else { |
| 4358 | switch (rt2x00dev->default_ant.tx_chain_num) { |
| 4359 | case 3: |
| 4360 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A2_EN, 1); |
| 4361 | /* fall through */ |
| 4362 | case 2: |
| 4363 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1); |
| 4364 | /* fall through */ |
| 4365 | case 1: |
| 4366 | default: |
| 4367 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, 1); |
| 4368 | break; |
| 4369 | } |
| 4370 | } |
| 4371 | rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin); |
| 4372 | |
| 4373 | } |
| 4374 | EXPORT_SYMBOL_GPL(rt2800_vco_calibration); |
| 4375 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4376 | static void rt2800_config_retry_limit(struct rt2x00_dev *rt2x00dev, |
| 4377 | struct rt2x00lib_conf *libconf) |
| 4378 | { |
| 4379 | u32 reg; |
| 4380 | |
| 4381 | rt2800_register_read(rt2x00dev, TX_RTY_CFG, ®); |
| 4382 | rt2x00_set_field32(®, TX_RTY_CFG_SHORT_RTY_LIMIT, |
| 4383 | libconf->conf->short_frame_max_tx_count); |
| 4384 | rt2x00_set_field32(®, TX_RTY_CFG_LONG_RTY_LIMIT, |
| 4385 | libconf->conf->long_frame_max_tx_count); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4386 | rt2800_register_write(rt2x00dev, TX_RTY_CFG, reg); |
| 4387 | } |
| 4388 | |
| 4389 | static void rt2800_config_ps(struct rt2x00_dev *rt2x00dev, |
| 4390 | struct rt2x00lib_conf *libconf) |
| 4391 | { |
| 4392 | enum dev_state state = |
| 4393 | (libconf->conf->flags & IEEE80211_CONF_PS) ? |
| 4394 | STATE_SLEEP : STATE_AWAKE; |
| 4395 | u32 reg; |
| 4396 | |
| 4397 | if (state == STATE_SLEEP) { |
| 4398 | rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0); |
| 4399 | |
| 4400 | rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG, ®); |
| 4401 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 5); |
| 4402 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE, |
| 4403 | libconf->conf->listen_interval - 1); |
| 4404 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTOWAKE, 1); |
| 4405 | rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg); |
| 4406 | |
| 4407 | rt2x00dev->ops->lib->set_device_state(rt2x00dev, state); |
| 4408 | } else { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4409 | rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG, ®); |
| 4410 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 0); |
| 4411 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE, 0); |
| 4412 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTOWAKE, 0); |
| 4413 | rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg); |
Gertjan van Wingerde | 5731858 | 2010-03-30 23:50:23 +0200 | [diff] [blame] | 4414 | |
| 4415 | rt2x00dev->ops->lib->set_device_state(rt2x00dev, state); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4416 | } |
| 4417 | } |
| 4418 | |
| 4419 | void rt2800_config(struct rt2x00_dev *rt2x00dev, |
| 4420 | struct rt2x00lib_conf *libconf, |
| 4421 | const unsigned int flags) |
| 4422 | { |
| 4423 | /* Always recalculate LNA gain before changing configuration */ |
| 4424 | rt2800_config_lna_gain(rt2x00dev, libconf); |
| 4425 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4426 | if (flags & IEEE80211_CONF_CHANGE_CHANNEL) { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4427 | rt2800_config_channel(rt2x00dev, libconf->conf, |
| 4428 | &libconf->rf, &libconf->channel); |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 4429 | rt2800_config_txpower(rt2x00dev, libconf->conf->chandef.chan, |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 4430 | libconf->conf->power_level); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 4431 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4432 | if (flags & IEEE80211_CONF_CHANGE_POWER) |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 4433 | rt2800_config_txpower(rt2x00dev, libconf->conf->chandef.chan, |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 4434 | libconf->conf->power_level); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4435 | if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS) |
| 4436 | rt2800_config_retry_limit(rt2x00dev, libconf); |
| 4437 | if (flags & IEEE80211_CONF_CHANGE_PS) |
| 4438 | rt2800_config_ps(rt2x00dev, libconf); |
| 4439 | } |
| 4440 | EXPORT_SYMBOL_GPL(rt2800_config); |
| 4441 | |
| 4442 | /* |
| 4443 | * Link tuning |
| 4444 | */ |
| 4445 | void rt2800_link_stats(struct rt2x00_dev *rt2x00dev, struct link_qual *qual) |
| 4446 | { |
| 4447 | u32 reg; |
| 4448 | |
| 4449 | /* |
| 4450 | * Update FCS error count from register. |
| 4451 | */ |
| 4452 | rt2800_register_read(rt2x00dev, RX_STA_CNT0, ®); |
| 4453 | qual->rx_failed = rt2x00_get_field32(reg, RX_STA_CNT0_CRC_ERR); |
| 4454 | } |
| 4455 | EXPORT_SYMBOL_GPL(rt2800_link_stats); |
| 4456 | |
| 4457 | static u8 rt2800_get_default_vgc(struct rt2x00_dev *rt2x00dev) |
| 4458 | { |
Gertjan van Wingerde | 8c6728b | 2012-09-16 22:29:49 +0200 | [diff] [blame] | 4459 | u8 vgc; |
| 4460 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4461 | if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) { |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 4462 | if (rt2x00_rt(rt2x00dev, RT3070) || |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 4463 | rt2x00_rt(rt2x00dev, RT3071) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 4464 | rt2x00_rt(rt2x00dev, RT3090) || |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 4465 | rt2x00_rt(rt2x00dev, RT3290) || |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 4466 | rt2x00_rt(rt2x00dev, RT3390) || |
Gertjan van Wingerde | d961e44 | 2012-09-16 22:29:50 +0200 | [diff] [blame] | 4467 | rt2x00_rt(rt2x00dev, RT3572) || |
Gabor Juhos | 0ffd2a9 | 2013-10-03 20:00:42 +0200 | [diff] [blame] | 4468 | rt2x00_rt(rt2x00dev, RT3593) || |
John Li | 2ed7188 | 2012-02-17 17:33:06 +0800 | [diff] [blame] | 4469 | rt2x00_rt(rt2x00dev, RT5390) || |
Stanislaw Gruszka | 3d81535 | 2013-03-16 19:19:49 +0100 | [diff] [blame] | 4470 | rt2x00_rt(rt2x00dev, RT5392) || |
| 4471 | rt2x00_rt(rt2x00dev, RT5592)) |
Gertjan van Wingerde | 8c6728b | 2012-09-16 22:29:49 +0200 | [diff] [blame] | 4472 | vgc = 0x1c + (2 * rt2x00dev->lna_gain); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4473 | else |
Gertjan van Wingerde | 8c6728b | 2012-09-16 22:29:49 +0200 | [diff] [blame] | 4474 | vgc = 0x2e + rt2x00dev->lna_gain; |
| 4475 | } else { /* 5GHZ band */ |
Gabor Juhos | 733aec6 | 2013-10-04 22:07:09 +0200 | [diff] [blame] | 4476 | if (rt2x00_rt(rt2x00dev, RT3593)) |
Gabor Juhos | 0ffd2a9 | 2013-10-03 20:00:42 +0200 | [diff] [blame] | 4477 | vgc = 0x20 + (rt2x00dev->lna_gain * 5) / 3; |
Stanislaw Gruszka | 3d81535 | 2013-03-16 19:19:49 +0100 | [diff] [blame] | 4478 | else if (rt2x00_rt(rt2x00dev, RT5592)) |
| 4479 | vgc = 0x24 + (2 * rt2x00dev->lna_gain); |
Gertjan van Wingerde | d961e44 | 2012-09-16 22:29:50 +0200 | [diff] [blame] | 4480 | else { |
| 4481 | if (!test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags)) |
| 4482 | vgc = 0x32 + (rt2x00dev->lna_gain * 5) / 3; |
| 4483 | else |
| 4484 | vgc = 0x3a + (rt2x00dev->lna_gain * 5) / 3; |
| 4485 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4486 | } |
| 4487 | |
Gertjan van Wingerde | 8c6728b | 2012-09-16 22:29:49 +0200 | [diff] [blame] | 4488 | return vgc; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4489 | } |
| 4490 | |
| 4491 | static inline void rt2800_set_vgc(struct rt2x00_dev *rt2x00dev, |
| 4492 | struct link_qual *qual, u8 vgc_level) |
| 4493 | { |
| 4494 | if (qual->vgc_level != vgc_level) { |
Gabor Juhos | 271f1a4 | 2013-10-03 20:00:43 +0200 | [diff] [blame] | 4495 | if (rt2x00_rt(rt2x00dev, RT3572) || |
| 4496 | rt2x00_rt(rt2x00dev, RT3593)) { |
| 4497 | rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, |
| 4498 | vgc_level); |
| 4499 | } else if (rt2x00_rt(rt2x00dev, RT5592)) { |
Stanislaw Gruszka | 3d81535 | 2013-03-16 19:19:49 +0100 | [diff] [blame] | 4500 | rt2800_bbp_write(rt2x00dev, 83, qual->rssi > -65 ? 0x4a : 0x7a); |
| 4501 | rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, vgc_level); |
Gabor Juhos | 271f1a4 | 2013-10-03 20:00:43 +0200 | [diff] [blame] | 4502 | } else { |
Stanislaw Gruszka | 3d81535 | 2013-03-16 19:19:49 +0100 | [diff] [blame] | 4503 | rt2800_bbp_write(rt2x00dev, 66, vgc_level); |
Gabor Juhos | 271f1a4 | 2013-10-03 20:00:43 +0200 | [diff] [blame] | 4504 | } |
| 4505 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4506 | qual->vgc_level = vgc_level; |
| 4507 | qual->vgc_level_reg = vgc_level; |
| 4508 | } |
| 4509 | } |
| 4510 | |
| 4511 | void rt2800_reset_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual) |
| 4512 | { |
| 4513 | rt2800_set_vgc(rt2x00dev, qual, rt2800_get_default_vgc(rt2x00dev)); |
| 4514 | } |
| 4515 | EXPORT_SYMBOL_GPL(rt2800_reset_tuner); |
| 4516 | |
| 4517 | void rt2800_link_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual, |
| 4518 | const u32 count) |
| 4519 | { |
Stanislaw Gruszka | 3d81535 | 2013-03-16 19:19:49 +0100 | [diff] [blame] | 4520 | u8 vgc; |
| 4521 | |
Gertjan van Wingerde | 8d0c9b6 | 2010-04-11 14:31:10 +0200 | [diff] [blame] | 4522 | if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4523 | return; |
Gabor Juhos | e25aa82 | 2013-10-03 20:00:41 +0200 | [diff] [blame] | 4524 | |
| 4525 | /* When RSSI is better than a certain threshold, increase VGC |
| 4526 | * with a chip specific value in order to improve the balance |
| 4527 | * between sensibility and noise isolation. |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4528 | */ |
Stanislaw Gruszka | 3d81535 | 2013-03-16 19:19:49 +0100 | [diff] [blame] | 4529 | |
| 4530 | vgc = rt2800_get_default_vgc(rt2x00dev); |
| 4531 | |
Gabor Juhos | e25aa82 | 2013-10-03 20:00:41 +0200 | [diff] [blame] | 4532 | switch (rt2x00dev->chip.rt) { |
| 4533 | case RT3572: |
| 4534 | case RT3593: |
| 4535 | if (qual->rssi > -65) { |
| 4536 | if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) |
| 4537 | vgc += 0x20; |
| 4538 | else |
| 4539 | vgc += 0x10; |
| 4540 | } |
| 4541 | break; |
| 4542 | |
| 4543 | case RT5592: |
Gabor Juhos | 0beb1bb | 2013-10-03 20:00:40 +0200 | [diff] [blame] | 4544 | if (qual->rssi > -65) |
| 4545 | vgc += 0x20; |
Gabor Juhos | e25aa82 | 2013-10-03 20:00:41 +0200 | [diff] [blame] | 4546 | break; |
| 4547 | |
| 4548 | default: |
Gabor Juhos | 0beb1bb | 2013-10-03 20:00:40 +0200 | [diff] [blame] | 4549 | if (qual->rssi > -80) |
| 4550 | vgc += 0x10; |
Gabor Juhos | e25aa82 | 2013-10-03 20:00:41 +0200 | [diff] [blame] | 4551 | break; |
Gabor Juhos | 0beb1bb | 2013-10-03 20:00:40 +0200 | [diff] [blame] | 4552 | } |
Stanislaw Gruszka | 3d81535 | 2013-03-16 19:19:49 +0100 | [diff] [blame] | 4553 | |
| 4554 | rt2800_set_vgc(rt2x00dev, qual, vgc); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4555 | } |
| 4556 | EXPORT_SYMBOL_GPL(rt2800_link_tuner); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4557 | |
| 4558 | /* |
| 4559 | * Initialization functions. |
| 4560 | */ |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 4561 | static int rt2800_init_registers(struct rt2x00_dev *rt2x00dev) |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4562 | { |
| 4563 | u32 reg; |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 4564 | u16 eeprom; |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4565 | unsigned int i; |
Gertjan van Wingerde | e3a896b | 2010-06-03 10:52:04 +0200 | [diff] [blame] | 4566 | int ret; |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4567 | |
Jakub Kicinski | f7b395e | 2012-04-03 03:40:47 +0200 | [diff] [blame] | 4568 | rt2800_disable_wpdma(rt2x00dev); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4569 | |
Gertjan van Wingerde | e3a896b | 2010-06-03 10:52:04 +0200 | [diff] [blame] | 4570 | ret = rt2800_drv_init_registers(rt2x00dev); |
| 4571 | if (ret) |
| 4572 | return ret; |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4573 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4574 | rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE, 0x0000013f); |
| 4575 | rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003); |
| 4576 | |
| 4577 | rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000); |
| 4578 | |
| 4579 | rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®); |
Helmut Schaa | 8544df3 | 2010-07-11 12:29:49 +0200 | [diff] [blame] | 4580 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_INTERVAL, 1600); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4581 | rt2x00_set_field32(®, BCN_TIME_CFG_TSF_TICKING, 0); |
| 4582 | rt2x00_set_field32(®, BCN_TIME_CFG_TSF_SYNC, 0); |
| 4583 | rt2x00_set_field32(®, BCN_TIME_CFG_TBTT_ENABLE, 0); |
| 4584 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 0); |
| 4585 | rt2x00_set_field32(®, BCN_TIME_CFG_TX_TIME_COMPENSATE, 0); |
| 4586 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
| 4587 | |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4588 | rt2800_config_filter(rt2x00dev, FIF_ALLMULTI); |
| 4589 | |
| 4590 | rt2800_register_read(rt2x00dev, BKOFF_SLOT_CFG, ®); |
| 4591 | rt2x00_set_field32(®, BKOFF_SLOT_CFG_SLOT_TIME, 9); |
| 4592 | rt2x00_set_field32(®, BKOFF_SLOT_CFG_CC_DELAY_TIME, 2); |
| 4593 | rt2800_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg); |
| 4594 | |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 4595 | if (rt2x00_rt(rt2x00dev, RT3290)) { |
| 4596 | rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, ®); |
| 4597 | if (rt2x00_get_field32(reg, WLAN_EN) == 1) { |
| 4598 | rt2x00_set_field32(®, PCIE_APP0_CLK_REQ, 1); |
| 4599 | rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg); |
| 4600 | } |
| 4601 | |
| 4602 | rt2800_register_read(rt2x00dev, CMB_CTRL, ®); |
| 4603 | if (!(rt2x00_get_field32(reg, LDO0_EN) == 1)) { |
| 4604 | rt2x00_set_field32(®, LDO0_EN, 1); |
| 4605 | rt2x00_set_field32(®, LDO_BGSEL, 3); |
| 4606 | rt2800_register_write(rt2x00dev, CMB_CTRL, reg); |
| 4607 | } |
| 4608 | |
| 4609 | rt2800_register_read(rt2x00dev, OSC_CTRL, ®); |
| 4610 | rt2x00_set_field32(®, OSC_ROSC_EN, 1); |
| 4611 | rt2x00_set_field32(®, OSC_CAL_REQ, 1); |
| 4612 | rt2x00_set_field32(®, OSC_REF_CYCLE, 0x27); |
| 4613 | rt2800_register_write(rt2x00dev, OSC_CTRL, reg); |
| 4614 | |
| 4615 | rt2800_register_read(rt2x00dev, COEX_CFG0, ®); |
| 4616 | rt2x00_set_field32(®, COEX_CFG_ANT, 0x5e); |
| 4617 | rt2800_register_write(rt2x00dev, COEX_CFG0, reg); |
| 4618 | |
| 4619 | rt2800_register_read(rt2x00dev, COEX_CFG2, ®); |
| 4620 | rt2x00_set_field32(®, BT_COEX_CFG1, 0x00); |
| 4621 | rt2x00_set_field32(®, BT_COEX_CFG0, 0x17); |
| 4622 | rt2x00_set_field32(®, WL_COEX_CFG1, 0x93); |
| 4623 | rt2x00_set_field32(®, WL_COEX_CFG0, 0x7f); |
| 4624 | rt2800_register_write(rt2x00dev, COEX_CFG2, reg); |
| 4625 | |
| 4626 | rt2800_register_read(rt2x00dev, PLL_CTRL, ®); |
| 4627 | rt2x00_set_field32(®, PLL_CONTROL, 1); |
| 4628 | rt2800_register_write(rt2x00dev, PLL_CTRL, reg); |
| 4629 | } |
| 4630 | |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 4631 | if (rt2x00_rt(rt2x00dev, RT3071) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 4632 | rt2x00_rt(rt2x00dev, RT3090) || |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 4633 | rt2x00_rt(rt2x00dev, RT3290) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 4634 | rt2x00_rt(rt2x00dev, RT3390)) { |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 4635 | |
| 4636 | if (rt2x00_rt(rt2x00dev, RT3290)) |
| 4637 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, |
| 4638 | 0x00000404); |
| 4639 | else |
| 4640 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, |
| 4641 | 0x00000400); |
| 4642 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4643 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000); |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 4644 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 4645 | rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E) || |
| 4646 | rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 4647 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, |
| 4648 | &eeprom); |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 4649 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_DAC_TEST)) |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 4650 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, |
| 4651 | 0x0000002c); |
| 4652 | else |
| 4653 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, |
| 4654 | 0x0000000f); |
| 4655 | } else { |
| 4656 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000); |
| 4657 | } |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 4658 | } else if (rt2x00_rt(rt2x00dev, RT3070)) { |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4659 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400); |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 4660 | |
| 4661 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) { |
| 4662 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000); |
| 4663 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x0000002c); |
| 4664 | } else { |
| 4665 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606); |
| 4666 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000); |
| 4667 | } |
Helmut Schaa | c295a81 | 2010-06-03 10:52:13 +0200 | [diff] [blame] | 4668 | } else if (rt2800_is_305x_soc(rt2x00dev)) { |
| 4669 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400); |
| 4670 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000); |
Helmut Schaa | 961636b | 2011-04-18 15:28:27 +0200 | [diff] [blame] | 4671 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000030); |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 4672 | } else if (rt2x00_rt(rt2x00dev, RT3352)) { |
| 4673 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000402); |
| 4674 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606); |
| 4675 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 4676 | } else if (rt2x00_rt(rt2x00dev, RT3572)) { |
| 4677 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400); |
| 4678 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606); |
Gabor Juhos | 1706d15 | 2013-07-08 16:08:16 +0200 | [diff] [blame] | 4679 | } else if (rt2x00_rt(rt2x00dev, RT3593)) { |
| 4680 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000402); |
| 4681 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000); |
| 4682 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3593, REV_RT3593E)) { |
| 4683 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, |
| 4684 | &eeprom); |
| 4685 | if (rt2x00_get_field16(eeprom, |
| 4686 | EEPROM_NIC_CONF1_DAC_TEST)) |
| 4687 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, |
| 4688 | 0x0000001f); |
| 4689 | else |
| 4690 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, |
| 4691 | 0x0000000f); |
| 4692 | } else { |
| 4693 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, |
| 4694 | 0x00000000); |
| 4695 | } |
John Li | 2ed7188 | 2012-02-17 17:33:06 +0800 | [diff] [blame] | 4696 | } else if (rt2x00_rt(rt2x00dev, RT5390) || |
Stanislaw Gruszka | 7641328 | 2013-03-16 19:19:33 +0100 | [diff] [blame] | 4697 | rt2x00_rt(rt2x00dev, RT5392) || |
| 4698 | rt2x00_rt(rt2x00dev, RT5592)) { |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 4699 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000404); |
| 4700 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606); |
| 4701 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4702 | } else { |
| 4703 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000000); |
| 4704 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606); |
| 4705 | } |
| 4706 | |
| 4707 | rt2800_register_read(rt2x00dev, TX_LINK_CFG, ®); |
| 4708 | rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_MFB_LIFETIME, 32); |
| 4709 | rt2x00_set_field32(®, TX_LINK_CFG_MFB_ENABLE, 0); |
| 4710 | rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_UMFS_ENABLE, 0); |
| 4711 | rt2x00_set_field32(®, TX_LINK_CFG_TX_MRQ_EN, 0); |
| 4712 | rt2x00_set_field32(®, TX_LINK_CFG_TX_RDG_EN, 0); |
| 4713 | rt2x00_set_field32(®, TX_LINK_CFG_TX_CF_ACK_EN, 1); |
| 4714 | rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_MFB, 0); |
| 4715 | rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_MFS, 0); |
| 4716 | rt2800_register_write(rt2x00dev, TX_LINK_CFG, reg); |
| 4717 | |
| 4718 | rt2800_register_read(rt2x00dev, TX_TIMEOUT_CFG, ®); |
| 4719 | rt2x00_set_field32(®, TX_TIMEOUT_CFG_MPDU_LIFETIME, 9); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4720 | rt2x00_set_field32(®, TX_TIMEOUT_CFG_RX_ACK_TIMEOUT, 32); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4721 | rt2x00_set_field32(®, TX_TIMEOUT_CFG_TX_OP_TIMEOUT, 10); |
| 4722 | rt2800_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg); |
| 4723 | |
| 4724 | rt2800_register_read(rt2x00dev, MAX_LEN_CFG, ®); |
| 4725 | rt2x00_set_field32(®, MAX_LEN_CFG_MAX_MPDU, AGGREGATION_SIZE); |
Gertjan van Wingerde | 8d0c9b6 | 2010-04-11 14:31:10 +0200 | [diff] [blame] | 4726 | if (rt2x00_rt_rev_gte(rt2x00dev, RT2872, REV_RT2872E) || |
Gertjan van Wingerde | 49e721e | 2010-02-13 20:55:49 +0100 | [diff] [blame] | 4727 | rt2x00_rt(rt2x00dev, RT2883) || |
Gertjan van Wingerde | 8d0c9b6 | 2010-04-11 14:31:10 +0200 | [diff] [blame] | 4728 | rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070E)) |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4729 | rt2x00_set_field32(®, MAX_LEN_CFG_MAX_PSDU, 2); |
| 4730 | else |
| 4731 | rt2x00_set_field32(®, MAX_LEN_CFG_MAX_PSDU, 1); |
| 4732 | rt2x00_set_field32(®, MAX_LEN_CFG_MIN_PSDU, 0); |
| 4733 | rt2x00_set_field32(®, MAX_LEN_CFG_MIN_MPDU, 0); |
| 4734 | rt2800_register_write(rt2x00dev, MAX_LEN_CFG, reg); |
| 4735 | |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4736 | rt2800_register_read(rt2x00dev, LED_CFG, ®); |
| 4737 | rt2x00_set_field32(®, LED_CFG_ON_PERIOD, 70); |
| 4738 | rt2x00_set_field32(®, LED_CFG_OFF_PERIOD, 30); |
| 4739 | rt2x00_set_field32(®, LED_CFG_SLOW_BLINK_PERIOD, 3); |
| 4740 | rt2x00_set_field32(®, LED_CFG_R_LED_MODE, 3); |
| 4741 | rt2x00_set_field32(®, LED_CFG_G_LED_MODE, 3); |
| 4742 | rt2x00_set_field32(®, LED_CFG_Y_LED_MODE, 3); |
| 4743 | rt2x00_set_field32(®, LED_CFG_LED_POLAR, 1); |
| 4744 | rt2800_register_write(rt2x00dev, LED_CFG, reg); |
| 4745 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4746 | rt2800_register_write(rt2x00dev, PBF_MAX_PCNT, 0x1f3fbf9f); |
| 4747 | |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4748 | rt2800_register_read(rt2x00dev, TX_RTY_CFG, ®); |
| 4749 | rt2x00_set_field32(®, TX_RTY_CFG_SHORT_RTY_LIMIT, 15); |
| 4750 | rt2x00_set_field32(®, TX_RTY_CFG_LONG_RTY_LIMIT, 31); |
| 4751 | rt2x00_set_field32(®, TX_RTY_CFG_LONG_RTY_THRE, 2000); |
| 4752 | rt2x00_set_field32(®, TX_RTY_CFG_NON_AGG_RTY_MODE, 0); |
| 4753 | rt2x00_set_field32(®, TX_RTY_CFG_AGG_RTY_MODE, 0); |
| 4754 | rt2x00_set_field32(®, TX_RTY_CFG_TX_AUTO_FB_ENABLE, 1); |
| 4755 | rt2800_register_write(rt2x00dev, TX_RTY_CFG, reg); |
| 4756 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4757 | rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, ®); |
| 4758 | rt2x00_set_field32(®, AUTO_RSP_CFG_AUTORESPONDER, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4759 | rt2x00_set_field32(®, AUTO_RSP_CFG_BAC_ACK_POLICY, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4760 | rt2x00_set_field32(®, AUTO_RSP_CFG_CTS_40_MMODE, 0); |
| 4761 | rt2x00_set_field32(®, AUTO_RSP_CFG_CTS_40_MREF, 0); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4762 | rt2x00_set_field32(®, AUTO_RSP_CFG_AR_PREAMBLE, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4763 | rt2x00_set_field32(®, AUTO_RSP_CFG_DUAL_CTS_EN, 0); |
| 4764 | rt2x00_set_field32(®, AUTO_RSP_CFG_ACK_CTS_PSM_BIT, 0); |
| 4765 | rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg); |
| 4766 | |
| 4767 | rt2800_register_read(rt2x00dev, CCK_PROT_CFG, ®); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4768 | rt2x00_set_field32(®, CCK_PROT_CFG_PROTECT_RATE, 3); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4769 | rt2x00_set_field32(®, CCK_PROT_CFG_PROTECT_CTRL, 0); |
Shiang Tu | 6f492b6 | 2011-02-20 13:56:54 +0100 | [diff] [blame] | 4770 | rt2x00_set_field32(®, CCK_PROT_CFG_PROTECT_NAV_SHORT, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4771 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 4772 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 4773 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4774 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_MM40, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4775 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4776 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_GF40, 0); |
| 4777 | rt2x00_set_field32(®, CCK_PROT_CFG_RTS_TH_EN, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4778 | rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg); |
| 4779 | |
| 4780 | rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, ®); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4781 | rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_RATE, 3); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4782 | rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_CTRL, 0); |
Shiang Tu | 6f492b6 | 2011-02-20 13:56:54 +0100 | [diff] [blame] | 4783 | rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_NAV_SHORT, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4784 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 4785 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 4786 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4787 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_MM40, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4788 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4789 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_GF40, 0); |
| 4790 | rt2x00_set_field32(®, OFDM_PROT_CFG_RTS_TH_EN, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4791 | rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg); |
| 4792 | |
| 4793 | rt2800_register_read(rt2x00dev, MM20_PROT_CFG, ®); |
| 4794 | rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_RATE, 0x4004); |
| 4795 | rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_CTRL, 0); |
Shiang Tu | 6f492b6 | 2011-02-20 13:56:54 +0100 | [diff] [blame] | 4796 | rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_NAV_SHORT, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4797 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 4798 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 4799 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
| 4800 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_MM40, 0); |
| 4801 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
| 4802 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_GF40, 0); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4803 | rt2x00_set_field32(®, MM20_PROT_CFG_RTS_TH_EN, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4804 | rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg); |
| 4805 | |
| 4806 | rt2800_register_read(rt2x00dev, MM40_PROT_CFG, ®); |
| 4807 | rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_RATE, 0x4084); |
Helmut Schaa | d13a97f | 2010-10-02 11:29:08 +0200 | [diff] [blame] | 4808 | rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_CTRL, 0); |
Shiang Tu | 6f492b6 | 2011-02-20 13:56:54 +0100 | [diff] [blame] | 4809 | rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_NAV_SHORT, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4810 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 4811 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 4812 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
| 4813 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_MM40, 1); |
| 4814 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
| 4815 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_GF40, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4816 | rt2x00_set_field32(®, MM40_PROT_CFG_RTS_TH_EN, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4817 | rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg); |
| 4818 | |
| 4819 | rt2800_register_read(rt2x00dev, GF20_PROT_CFG, ®); |
| 4820 | rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_RATE, 0x4004); |
| 4821 | rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_CTRL, 0); |
Shiang Tu | 6f492b6 | 2011-02-20 13:56:54 +0100 | [diff] [blame] | 4822 | rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_NAV_SHORT, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4823 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 4824 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 4825 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
| 4826 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_MM40, 0); |
| 4827 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
| 4828 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_GF40, 0); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4829 | rt2x00_set_field32(®, GF20_PROT_CFG_RTS_TH_EN, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4830 | rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg); |
| 4831 | |
| 4832 | rt2800_register_read(rt2x00dev, GF40_PROT_CFG, ®); |
| 4833 | rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_RATE, 0x4084); |
| 4834 | rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_CTRL, 0); |
Shiang Tu | 6f492b6 | 2011-02-20 13:56:54 +0100 | [diff] [blame] | 4835 | rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_NAV_SHORT, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4836 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 4837 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 4838 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
| 4839 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_MM40, 1); |
| 4840 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
| 4841 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_GF40, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4842 | rt2x00_set_field32(®, GF40_PROT_CFG_RTS_TH_EN, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4843 | rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg); |
| 4844 | |
Gertjan van Wingerde | cea90e5 | 2010-02-13 20:55:47 +0100 | [diff] [blame] | 4845 | if (rt2x00_is_usb(rt2x00dev)) { |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4846 | rt2800_register_write(rt2x00dev, PBF_CFG, 0xf40006); |
| 4847 | |
| 4848 | rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®); |
| 4849 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0); |
| 4850 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_DMA_BUSY, 0); |
| 4851 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0); |
| 4852 | rt2x00_set_field32(®, WPDMA_GLO_CFG_RX_DMA_BUSY, 0); |
| 4853 | rt2x00_set_field32(®, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 3); |
| 4854 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 0); |
| 4855 | rt2x00_set_field32(®, WPDMA_GLO_CFG_BIG_ENDIAN, 0); |
| 4856 | rt2x00_set_field32(®, WPDMA_GLO_CFG_RX_HDR_SCATTER, 0); |
| 4857 | rt2x00_set_field32(®, WPDMA_GLO_CFG_HDR_SEG_LEN, 0); |
| 4858 | rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg); |
| 4859 | } |
| 4860 | |
Helmut Schaa | 961621a | 2010-11-04 20:36:59 +0100 | [diff] [blame] | 4861 | /* |
| 4862 | * The legacy driver also sets TXOP_CTRL_CFG_RESERVED_TRUN_EN to 1 |
| 4863 | * although it is reserved. |
| 4864 | */ |
| 4865 | rt2800_register_read(rt2x00dev, TXOP_CTRL_CFG, ®); |
| 4866 | rt2x00_set_field32(®, TXOP_CTRL_CFG_TIMEOUT_TRUN_EN, 1); |
| 4867 | rt2x00_set_field32(®, TXOP_CTRL_CFG_AC_TRUN_EN, 1); |
| 4868 | rt2x00_set_field32(®, TXOP_CTRL_CFG_TXRATEGRP_TRUN_EN, 1); |
| 4869 | rt2x00_set_field32(®, TXOP_CTRL_CFG_USER_MODE_TRUN_EN, 1); |
| 4870 | rt2x00_set_field32(®, TXOP_CTRL_CFG_MIMO_PS_TRUN_EN, 1); |
| 4871 | rt2x00_set_field32(®, TXOP_CTRL_CFG_RESERVED_TRUN_EN, 1); |
| 4872 | rt2x00_set_field32(®, TXOP_CTRL_CFG_LSIG_TXOP_EN, 0); |
| 4873 | rt2x00_set_field32(®, TXOP_CTRL_CFG_EXT_CCA_EN, 0); |
| 4874 | rt2x00_set_field32(®, TXOP_CTRL_CFG_EXT_CCA_DLY, 88); |
| 4875 | rt2x00_set_field32(®, TXOP_CTRL_CFG_EXT_CWMIN, 0); |
| 4876 | rt2800_register_write(rt2x00dev, TXOP_CTRL_CFG, reg); |
| 4877 | |
Stanislaw Gruszka | 7641328 | 2013-03-16 19:19:33 +0100 | [diff] [blame] | 4878 | reg = rt2x00_rt(rt2x00dev, RT5592) ? 0x00000082 : 0x00000002; |
| 4879 | rt2800_register_write(rt2x00dev, TXOP_HLDR_ET, reg); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4880 | |
| 4881 | rt2800_register_read(rt2x00dev, TX_RTS_CFG, ®); |
| 4882 | rt2x00_set_field32(®, TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT, 32); |
| 4883 | rt2x00_set_field32(®, TX_RTS_CFG_RTS_THRES, |
| 4884 | IEEE80211_MAX_RTS_THRESHOLD); |
| 4885 | rt2x00_set_field32(®, TX_RTS_CFG_RTS_FBK_EN, 0); |
| 4886 | rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg); |
| 4887 | |
| 4888 | rt2800_register_write(rt2x00dev, EXP_ACK_TIME, 0x002400ca); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4889 | |
Helmut Schaa | a21c2ab | 2010-05-06 12:29:04 +0200 | [diff] [blame] | 4890 | /* |
| 4891 | * Usually the CCK SIFS time should be set to 10 and the OFDM SIFS |
| 4892 | * time should be set to 16. However, the original Ralink driver uses |
| 4893 | * 16 for both and indeed using a value of 10 for CCK SIFS results in |
| 4894 | * connection problems with 11g + CTS protection. Hence, use the same |
| 4895 | * defaults as the Ralink driver: 16 for both, CCK and OFDM SIFS. |
| 4896 | */ |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4897 | rt2800_register_read(rt2x00dev, XIFS_TIME_CFG, ®); |
Helmut Schaa | a21c2ab | 2010-05-06 12:29:04 +0200 | [diff] [blame] | 4898 | rt2x00_set_field32(®, XIFS_TIME_CFG_CCKM_SIFS_TIME, 16); |
| 4899 | rt2x00_set_field32(®, XIFS_TIME_CFG_OFDM_SIFS_TIME, 16); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4900 | rt2x00_set_field32(®, XIFS_TIME_CFG_OFDM_XIFS_TIME, 4); |
| 4901 | rt2x00_set_field32(®, XIFS_TIME_CFG_EIFS, 314); |
| 4902 | rt2x00_set_field32(®, XIFS_TIME_CFG_BB_RXEND_ENABLE, 1); |
| 4903 | rt2800_register_write(rt2x00dev, XIFS_TIME_CFG, reg); |
| 4904 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4905 | rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003); |
| 4906 | |
| 4907 | /* |
| 4908 | * ASIC will keep garbage value after boot, clear encryption keys. |
| 4909 | */ |
| 4910 | for (i = 0; i < 4; i++) |
| 4911 | rt2800_register_write(rt2x00dev, |
| 4912 | SHARED_KEY_MODE_ENTRY(i), 0); |
| 4913 | |
| 4914 | for (i = 0; i < 256; i++) { |
Helmut Schaa | d7d259d | 2011-09-08 14:39:04 +0200 | [diff] [blame] | 4915 | rt2800_config_wcid(rt2x00dev, NULL, i); |
| 4916 | rt2800_delete_wcid_attr(rt2x00dev, i); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4917 | rt2800_register_write(rt2x00dev, MAC_IVEIV_ENTRY(i), 0); |
| 4918 | } |
| 4919 | |
| 4920 | /* |
| 4921 | * Clear all beacons |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4922 | */ |
Gabor Juhos | 77f7c0f | 2013-08-17 00:15:50 +0200 | [diff] [blame] | 4923 | for (i = 0; i < 8; i++) |
| 4924 | rt2800_clear_beacon_register(rt2x00dev, i); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4925 | |
Gertjan van Wingerde | cea90e5 | 2010-02-13 20:55:47 +0100 | [diff] [blame] | 4926 | if (rt2x00_is_usb(rt2x00dev)) { |
Gertjan van Wingerde | 785c3c0 | 2010-06-03 10:51:59 +0200 | [diff] [blame] | 4927 | rt2800_register_read(rt2x00dev, US_CYC_CNT, ®); |
| 4928 | rt2x00_set_field32(®, US_CYC_CNT_CLOCK_CYCLE, 30); |
| 4929 | rt2800_register_write(rt2x00dev, US_CYC_CNT, reg); |
RA-Jay Hung | c6fcc0e | 2011-01-30 13:21:22 +0100 | [diff] [blame] | 4930 | } else if (rt2x00_is_pcie(rt2x00dev)) { |
| 4931 | rt2800_register_read(rt2x00dev, US_CYC_CNT, ®); |
| 4932 | rt2x00_set_field32(®, US_CYC_CNT_CLOCK_CYCLE, 125); |
| 4933 | rt2800_register_write(rt2x00dev, US_CYC_CNT, reg); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4934 | } |
| 4935 | |
| 4936 | rt2800_register_read(rt2x00dev, HT_FBK_CFG0, ®); |
| 4937 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS0FBK, 0); |
| 4938 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS1FBK, 0); |
| 4939 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS2FBK, 1); |
| 4940 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS3FBK, 2); |
| 4941 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS4FBK, 3); |
| 4942 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS5FBK, 4); |
| 4943 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS6FBK, 5); |
| 4944 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS7FBK, 6); |
| 4945 | rt2800_register_write(rt2x00dev, HT_FBK_CFG0, reg); |
| 4946 | |
| 4947 | rt2800_register_read(rt2x00dev, HT_FBK_CFG1, ®); |
| 4948 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS8FBK, 8); |
| 4949 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS9FBK, 8); |
| 4950 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS10FBK, 9); |
| 4951 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS11FBK, 10); |
| 4952 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS12FBK, 11); |
| 4953 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS13FBK, 12); |
| 4954 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS14FBK, 13); |
| 4955 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS15FBK, 14); |
| 4956 | rt2800_register_write(rt2x00dev, HT_FBK_CFG1, reg); |
| 4957 | |
| 4958 | rt2800_register_read(rt2x00dev, LG_FBK_CFG0, ®); |
| 4959 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS0FBK, 8); |
| 4960 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS1FBK, 8); |
| 4961 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS2FBK, 9); |
| 4962 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS3FBK, 10); |
| 4963 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS4FBK, 11); |
| 4964 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS5FBK, 12); |
| 4965 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS6FBK, 13); |
| 4966 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS7FBK, 14); |
| 4967 | rt2800_register_write(rt2x00dev, LG_FBK_CFG0, reg); |
| 4968 | |
| 4969 | rt2800_register_read(rt2x00dev, LG_FBK_CFG1, ®); |
| 4970 | rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS0FBK, 0); |
| 4971 | rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS1FBK, 0); |
| 4972 | rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS2FBK, 1); |
| 4973 | rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS3FBK, 2); |
| 4974 | rt2800_register_write(rt2x00dev, LG_FBK_CFG1, reg); |
| 4975 | |
| 4976 | /* |
Helmut Schaa | 47ee3eb | 2010-09-08 20:56:04 +0200 | [diff] [blame] | 4977 | * Do not force the BA window size, we use the TXWI to set it |
| 4978 | */ |
| 4979 | rt2800_register_read(rt2x00dev, AMPDU_BA_WINSIZE, ®); |
| 4980 | rt2x00_set_field32(®, AMPDU_BA_WINSIZE_FORCE_WINSIZE_ENABLE, 0); |
| 4981 | rt2x00_set_field32(®, AMPDU_BA_WINSIZE_FORCE_WINSIZE, 0); |
| 4982 | rt2800_register_write(rt2x00dev, AMPDU_BA_WINSIZE, reg); |
| 4983 | |
| 4984 | /* |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4985 | * We must clear the error counters. |
| 4986 | * These registers are cleared on read, |
| 4987 | * so we may pass a useless variable to store the value. |
| 4988 | */ |
| 4989 | rt2800_register_read(rt2x00dev, RX_STA_CNT0, ®); |
| 4990 | rt2800_register_read(rt2x00dev, RX_STA_CNT1, ®); |
| 4991 | rt2800_register_read(rt2x00dev, RX_STA_CNT2, ®); |
| 4992 | rt2800_register_read(rt2x00dev, TX_STA_CNT0, ®); |
| 4993 | rt2800_register_read(rt2x00dev, TX_STA_CNT1, ®); |
| 4994 | rt2800_register_read(rt2x00dev, TX_STA_CNT2, ®); |
| 4995 | |
Helmut Schaa | 9f926fb | 2010-07-11 12:28:23 +0200 | [diff] [blame] | 4996 | /* |
| 4997 | * Setup leadtime for pre tbtt interrupt to 6ms |
| 4998 | */ |
| 4999 | rt2800_register_read(rt2x00dev, INT_TIMER_CFG, ®); |
| 5000 | rt2x00_set_field32(®, INT_TIMER_CFG_PRE_TBTT_TIMER, 6 << 4); |
| 5001 | rt2800_register_write(rt2x00dev, INT_TIMER_CFG, reg); |
| 5002 | |
Helmut Schaa | 977206d | 2010-12-13 12:31:58 +0100 | [diff] [blame] | 5003 | /* |
| 5004 | * Set up channel statistics timer |
| 5005 | */ |
| 5006 | rt2800_register_read(rt2x00dev, CH_TIME_CFG, ®); |
| 5007 | rt2x00_set_field32(®, CH_TIME_CFG_EIFS_BUSY, 1); |
| 5008 | rt2x00_set_field32(®, CH_TIME_CFG_NAV_BUSY, 1); |
| 5009 | rt2x00_set_field32(®, CH_TIME_CFG_RX_BUSY, 1); |
| 5010 | rt2x00_set_field32(®, CH_TIME_CFG_TX_BUSY, 1); |
| 5011 | rt2x00_set_field32(®, CH_TIME_CFG_TMR_EN, 1); |
| 5012 | rt2800_register_write(rt2x00dev, CH_TIME_CFG, reg); |
| 5013 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 5014 | return 0; |
| 5015 | } |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 5016 | |
| 5017 | static int rt2800_wait_bbp_rf_ready(struct rt2x00_dev *rt2x00dev) |
| 5018 | { |
| 5019 | unsigned int i; |
| 5020 | u32 reg; |
| 5021 | |
| 5022 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
| 5023 | rt2800_register_read(rt2x00dev, MAC_STATUS_CFG, ®); |
| 5024 | if (!rt2x00_get_field32(reg, MAC_STATUS_CFG_BBP_RF_BUSY)) |
| 5025 | return 0; |
| 5026 | |
| 5027 | udelay(REGISTER_BUSY_DELAY); |
| 5028 | } |
| 5029 | |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 5030 | rt2x00_err(rt2x00dev, "BBP/RF register access failed, aborting\n"); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 5031 | return -EACCES; |
| 5032 | } |
| 5033 | |
| 5034 | static int rt2800_wait_bbp_ready(struct rt2x00_dev *rt2x00dev) |
| 5035 | { |
| 5036 | unsigned int i; |
| 5037 | u8 value; |
| 5038 | |
| 5039 | /* |
| 5040 | * BBP was enabled after firmware was loaded, |
| 5041 | * but we need to reactivate it now. |
| 5042 | */ |
| 5043 | rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0); |
| 5044 | rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0); |
| 5045 | msleep(1); |
| 5046 | |
| 5047 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
| 5048 | rt2800_bbp_read(rt2x00dev, 0, &value); |
| 5049 | if ((value != 0xff) && (value != 0x00)) |
| 5050 | return 0; |
| 5051 | udelay(REGISTER_BUSY_DELAY); |
| 5052 | } |
| 5053 | |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 5054 | rt2x00_err(rt2x00dev, "BBP register access failed, aborting\n"); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 5055 | return -EACCES; |
| 5056 | } |
| 5057 | |
Stanislaw Gruszka | a7bbbe5 | 2013-03-16 19:19:34 +0100 | [diff] [blame] | 5058 | static void rt2800_bbp4_mac_if_ctrl(struct rt2x00_dev *rt2x00dev) |
| 5059 | { |
| 5060 | u8 value; |
| 5061 | |
| 5062 | rt2800_bbp_read(rt2x00dev, 4, &value); |
| 5063 | rt2x00_set_field8(&value, BBP4_MAC_IF_CTRL, 1); |
| 5064 | rt2800_bbp_write(rt2x00dev, 4, value); |
| 5065 | } |
| 5066 | |
Stanislaw Gruszka | c267548 | 2013-03-16 19:19:41 +0100 | [diff] [blame] | 5067 | static void rt2800_init_freq_calibration(struct rt2x00_dev *rt2x00dev) |
| 5068 | { |
| 5069 | rt2800_bbp_write(rt2x00dev, 142, 1); |
| 5070 | rt2800_bbp_write(rt2x00dev, 143, 57); |
| 5071 | } |
| 5072 | |
Stanislaw Gruszka | a7bbbe5 | 2013-03-16 19:19:34 +0100 | [diff] [blame] | 5073 | static void rt2800_init_bbp_5592_glrt(struct rt2x00_dev *rt2x00dev) |
| 5074 | { |
| 5075 | const u8 glrt_table[] = { |
| 5076 | 0xE0, 0x1F, 0X38, 0x32, 0x08, 0x28, 0x19, 0x0A, 0xFF, 0x00, /* 128 ~ 137 */ |
| 5077 | 0x16, 0x10, 0x10, 0x0B, 0x36, 0x2C, 0x26, 0x24, 0x42, 0x36, /* 138 ~ 147 */ |
| 5078 | 0x30, 0x2D, 0x4C, 0x46, 0x3D, 0x40, 0x3E, 0x42, 0x3D, 0x40, /* 148 ~ 157 */ |
| 5079 | 0X3C, 0x34, 0x2C, 0x2F, 0x3C, 0x35, 0x2E, 0x2A, 0x49, 0x41, /* 158 ~ 167 */ |
| 5080 | 0x36, 0x31, 0x30, 0x30, 0x0E, 0x0D, 0x28, 0x21, 0x1C, 0x16, /* 168 ~ 177 */ |
| 5081 | 0x50, 0x4A, 0x43, 0x40, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, /* 178 ~ 187 */ |
| 5082 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 188 ~ 197 */ |
| 5083 | 0x00, 0x00, 0x7D, 0x14, 0x32, 0x2C, 0x36, 0x4C, 0x43, 0x2C, /* 198 ~ 207 */ |
| 5084 | 0x2E, 0x36, 0x30, 0x6E, /* 208 ~ 211 */ |
| 5085 | }; |
| 5086 | int i; |
| 5087 | |
| 5088 | for (i = 0; i < ARRAY_SIZE(glrt_table); i++) { |
| 5089 | rt2800_bbp_write(rt2x00dev, 195, 128 + i); |
| 5090 | rt2800_bbp_write(rt2x00dev, 196, glrt_table[i]); |
| 5091 | } |
| 5092 | }; |
| 5093 | |
Gabor Juhos | 624708b | 2013-04-19 10:13:52 +0200 | [diff] [blame] | 5094 | static void rt2800_init_bbp_early(struct rt2x00_dev *rt2x00dev) |
Stanislaw Gruszka | a4969d0 | 2013-03-16 19:19:35 +0100 | [diff] [blame] | 5095 | { |
| 5096 | rt2800_bbp_write(rt2x00dev, 65, 0x2C); |
| 5097 | rt2800_bbp_write(rt2x00dev, 66, 0x38); |
| 5098 | rt2800_bbp_write(rt2x00dev, 68, 0x0B); |
| 5099 | rt2800_bbp_write(rt2x00dev, 69, 0x12); |
| 5100 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
| 5101 | rt2800_bbp_write(rt2x00dev, 73, 0x10); |
| 5102 | rt2800_bbp_write(rt2x00dev, 81, 0x37); |
| 5103 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
| 5104 | rt2800_bbp_write(rt2x00dev, 83, 0x6A); |
| 5105 | rt2800_bbp_write(rt2x00dev, 84, 0x99); |
| 5106 | rt2800_bbp_write(rt2x00dev, 86, 0x00); |
| 5107 | rt2800_bbp_write(rt2x00dev, 91, 0x04); |
| 5108 | rt2800_bbp_write(rt2x00dev, 92, 0x00); |
| 5109 | rt2800_bbp_write(rt2x00dev, 103, 0x00); |
| 5110 | rt2800_bbp_write(rt2x00dev, 105, 0x05); |
| 5111 | rt2800_bbp_write(rt2x00dev, 106, 0x35); |
| 5112 | } |
| 5113 | |
Stanislaw Gruszka | 5df1ff3 | 2013-05-18 14:03:52 +0200 | [diff] [blame] | 5114 | static void rt2800_disable_unused_dac_adc(struct rt2x00_dev *rt2x00dev) |
| 5115 | { |
| 5116 | u16 eeprom; |
| 5117 | u8 value; |
| 5118 | |
| 5119 | rt2800_bbp_read(rt2x00dev, 138, &value); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 5120 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom); |
Stanislaw Gruszka | 5df1ff3 | 2013-05-18 14:03:52 +0200 | [diff] [blame] | 5121 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) == 1) |
| 5122 | value |= 0x20; |
| 5123 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) == 1) |
| 5124 | value &= ~0x02; |
| 5125 | rt2800_bbp_write(rt2x00dev, 138, value); |
| 5126 | } |
| 5127 | |
Stanislaw Gruszka | dae6295 | 2013-05-18 14:03:26 +0200 | [diff] [blame] | 5128 | static void rt2800_init_bbp_305x_soc(struct rt2x00_dev *rt2x00dev) |
| 5129 | { |
Stanislaw Gruszka | b2f8e0b | 2013-05-18 14:03:29 +0200 | [diff] [blame] | 5130 | rt2800_bbp_write(rt2x00dev, 31, 0x08); |
Stanislaw Gruszka | e379de1 | 2013-05-18 14:03:31 +0200 | [diff] [blame] | 5131 | |
| 5132 | rt2800_bbp_write(rt2x00dev, 65, 0x2c); |
| 5133 | rt2800_bbp_write(rt2x00dev, 66, 0x38); |
Stanislaw Gruszka | 72ffe14 | 2013-05-18 14:03:33 +0200 | [diff] [blame] | 5134 | |
| 5135 | rt2800_bbp_write(rt2x00dev, 69, 0x12); |
| 5136 | rt2800_bbp_write(rt2x00dev, 73, 0x10); |
Stanislaw Gruszka | 8d97be3 | 2013-05-18 14:03:34 +0200 | [diff] [blame] | 5137 | |
| 5138 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
Stanislaw Gruszka | 43f535e | 2013-05-18 14:03:35 +0200 | [diff] [blame] | 5139 | |
| 5140 | rt2800_bbp_write(rt2x00dev, 78, 0x0e); |
| 5141 | rt2800_bbp_write(rt2x00dev, 80, 0x08); |
Stanislaw Gruszka | fa1e342 | 2013-05-18 14:03:36 +0200 | [diff] [blame] | 5142 | |
| 5143 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
Stanislaw Gruszka | 885f241 | 2013-05-18 14:03:37 +0200 | [diff] [blame] | 5144 | |
| 5145 | rt2800_bbp_write(rt2x00dev, 83, 0x6a); |
Stanislaw Gruszka | 3c20a12 | 2013-05-18 14:03:38 +0200 | [diff] [blame] | 5146 | |
| 5147 | rt2800_bbp_write(rt2x00dev, 84, 0x99); |
Stanislaw Gruszka | aef9f38 | 2013-05-18 14:03:39 +0200 | [diff] [blame] | 5148 | |
| 5149 | rt2800_bbp_write(rt2x00dev, 86, 0x00); |
Stanislaw Gruszka | 7af9874 | 2013-05-18 14:03:41 +0200 | [diff] [blame] | 5150 | |
| 5151 | rt2800_bbp_write(rt2x00dev, 91, 0x04); |
Stanislaw Gruszka | b4e121d | 2013-05-18 14:03:42 +0200 | [diff] [blame] | 5152 | |
| 5153 | rt2800_bbp_write(rt2x00dev, 92, 0x00); |
Stanislaw Gruszka | 672d118 | 2013-05-18 14:03:44 +0200 | [diff] [blame] | 5154 | |
| 5155 | rt2800_bbp_write(rt2x00dev, 103, 0xc0); |
Stanislaw Gruszka | 49d6111 | 2013-05-18 14:03:46 +0200 | [diff] [blame] | 5156 | |
| 5157 | rt2800_bbp_write(rt2x00dev, 105, 0x01); |
Stanislaw Gruszka | f867085 | 2013-05-18 14:03:47 +0200 | [diff] [blame] | 5158 | |
| 5159 | rt2800_bbp_write(rt2x00dev, 106, 0x35); |
Stanislaw Gruszka | dae6295 | 2013-05-18 14:03:26 +0200 | [diff] [blame] | 5160 | } |
| 5161 | |
Stanislaw Gruszka | 39ab3e8 | 2013-05-18 14:03:25 +0200 | [diff] [blame] | 5162 | static void rt2800_init_bbp_28xx(struct rt2x00_dev *rt2x00dev) |
| 5163 | { |
Stanislaw Gruszka | e379de1 | 2013-05-18 14:03:31 +0200 | [diff] [blame] | 5164 | rt2800_bbp_write(rt2x00dev, 65, 0x2c); |
| 5165 | rt2800_bbp_write(rt2x00dev, 66, 0x38); |
Stanislaw Gruszka | 72ffe14 | 2013-05-18 14:03:33 +0200 | [diff] [blame] | 5166 | |
| 5167 | if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) { |
| 5168 | rt2800_bbp_write(rt2x00dev, 69, 0x16); |
| 5169 | rt2800_bbp_write(rt2x00dev, 73, 0x12); |
| 5170 | } else { |
| 5171 | rt2800_bbp_write(rt2x00dev, 69, 0x12); |
| 5172 | rt2800_bbp_write(rt2x00dev, 73, 0x10); |
| 5173 | } |
Stanislaw Gruszka | 8d97be3 | 2013-05-18 14:03:34 +0200 | [diff] [blame] | 5174 | |
| 5175 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
Stanislaw Gruszka | 43f535e | 2013-05-18 14:03:35 +0200 | [diff] [blame] | 5176 | |
| 5177 | rt2800_bbp_write(rt2x00dev, 81, 0x37); |
Stanislaw Gruszka | fa1e342 | 2013-05-18 14:03:36 +0200 | [diff] [blame] | 5178 | |
| 5179 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
Stanislaw Gruszka | 885f241 | 2013-05-18 14:03:37 +0200 | [diff] [blame] | 5180 | |
| 5181 | rt2800_bbp_write(rt2x00dev, 83, 0x6a); |
Stanislaw Gruszka | 3c20a12 | 2013-05-18 14:03:38 +0200 | [diff] [blame] | 5182 | |
| 5183 | if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860D)) |
| 5184 | rt2800_bbp_write(rt2x00dev, 84, 0x19); |
| 5185 | else |
| 5186 | rt2800_bbp_write(rt2x00dev, 84, 0x99); |
Stanislaw Gruszka | aef9f38 | 2013-05-18 14:03:39 +0200 | [diff] [blame] | 5187 | |
| 5188 | rt2800_bbp_write(rt2x00dev, 86, 0x00); |
Stanislaw Gruszka | 7af9874 | 2013-05-18 14:03:41 +0200 | [diff] [blame] | 5189 | |
| 5190 | rt2800_bbp_write(rt2x00dev, 91, 0x04); |
Stanislaw Gruszka | b4e121d | 2013-05-18 14:03:42 +0200 | [diff] [blame] | 5191 | |
| 5192 | rt2800_bbp_write(rt2x00dev, 92, 0x00); |
Stanislaw Gruszka | 672d118 | 2013-05-18 14:03:44 +0200 | [diff] [blame] | 5193 | |
| 5194 | rt2800_bbp_write(rt2x00dev, 103, 0x00); |
Stanislaw Gruszka | 49d6111 | 2013-05-18 14:03:46 +0200 | [diff] [blame] | 5195 | |
| 5196 | rt2800_bbp_write(rt2x00dev, 105, 0x05); |
Stanislaw Gruszka | f867085 | 2013-05-18 14:03:47 +0200 | [diff] [blame] | 5197 | |
| 5198 | rt2800_bbp_write(rt2x00dev, 106, 0x35); |
Stanislaw Gruszka | 39ab3e8 | 2013-05-18 14:03:25 +0200 | [diff] [blame] | 5199 | } |
| 5200 | |
| 5201 | static void rt2800_init_bbp_30xx(struct rt2x00_dev *rt2x00dev) |
| 5202 | { |
Stanislaw Gruszka | e379de1 | 2013-05-18 14:03:31 +0200 | [diff] [blame] | 5203 | rt2800_bbp_write(rt2x00dev, 65, 0x2c); |
| 5204 | rt2800_bbp_write(rt2x00dev, 66, 0x38); |
Stanislaw Gruszka | 72ffe14 | 2013-05-18 14:03:33 +0200 | [diff] [blame] | 5205 | |
| 5206 | rt2800_bbp_write(rt2x00dev, 69, 0x12); |
| 5207 | rt2800_bbp_write(rt2x00dev, 73, 0x10); |
Stanislaw Gruszka | 8d97be3 | 2013-05-18 14:03:34 +0200 | [diff] [blame] | 5208 | |
| 5209 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
Stanislaw Gruszka | 43f535e | 2013-05-18 14:03:35 +0200 | [diff] [blame] | 5210 | |
| 5211 | rt2800_bbp_write(rt2x00dev, 79, 0x13); |
| 5212 | rt2800_bbp_write(rt2x00dev, 80, 0x05); |
| 5213 | rt2800_bbp_write(rt2x00dev, 81, 0x33); |
Stanislaw Gruszka | fa1e342 | 2013-05-18 14:03:36 +0200 | [diff] [blame] | 5214 | |
| 5215 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
Stanislaw Gruszka | 885f241 | 2013-05-18 14:03:37 +0200 | [diff] [blame] | 5216 | |
| 5217 | rt2800_bbp_write(rt2x00dev, 83, 0x6a); |
Stanislaw Gruszka | 3c20a12 | 2013-05-18 14:03:38 +0200 | [diff] [blame] | 5218 | |
| 5219 | rt2800_bbp_write(rt2x00dev, 84, 0x99); |
Stanislaw Gruszka | aef9f38 | 2013-05-18 14:03:39 +0200 | [diff] [blame] | 5220 | |
| 5221 | rt2800_bbp_write(rt2x00dev, 86, 0x00); |
Stanislaw Gruszka | 7af9874 | 2013-05-18 14:03:41 +0200 | [diff] [blame] | 5222 | |
| 5223 | rt2800_bbp_write(rt2x00dev, 91, 0x04); |
Stanislaw Gruszka | b4e121d | 2013-05-18 14:03:42 +0200 | [diff] [blame] | 5224 | |
| 5225 | rt2800_bbp_write(rt2x00dev, 92, 0x00); |
Stanislaw Gruszka | 672d118 | 2013-05-18 14:03:44 +0200 | [diff] [blame] | 5226 | |
| 5227 | if (rt2x00_rt_rev_gte(rt2x00dev, RT3070, REV_RT3070F) || |
| 5228 | rt2x00_rt_rev_gte(rt2x00dev, RT3071, REV_RT3071E) || |
| 5229 | rt2x00_rt_rev_gte(rt2x00dev, RT3090, REV_RT3090E)) |
| 5230 | rt2800_bbp_write(rt2x00dev, 103, 0xc0); |
| 5231 | else |
| 5232 | rt2800_bbp_write(rt2x00dev, 103, 0x00); |
Stanislaw Gruszka | 49d6111 | 2013-05-18 14:03:46 +0200 | [diff] [blame] | 5233 | |
| 5234 | rt2800_bbp_write(rt2x00dev, 105, 0x05); |
Stanislaw Gruszka | f867085 | 2013-05-18 14:03:47 +0200 | [diff] [blame] | 5235 | |
| 5236 | rt2800_bbp_write(rt2x00dev, 106, 0x35); |
Stanislaw Gruszka | 5df1ff3 | 2013-05-18 14:03:52 +0200 | [diff] [blame] | 5237 | |
| 5238 | if (rt2x00_rt(rt2x00dev, RT3071) || |
| 5239 | rt2x00_rt(rt2x00dev, RT3090)) |
| 5240 | rt2800_disable_unused_dac_adc(rt2x00dev); |
Stanislaw Gruszka | 39ab3e8 | 2013-05-18 14:03:25 +0200 | [diff] [blame] | 5241 | } |
| 5242 | |
| 5243 | static void rt2800_init_bbp_3290(struct rt2x00_dev *rt2x00dev) |
| 5244 | { |
Stanislaw Gruszka | 6addb24 | 2013-05-18 14:03:54 +0200 | [diff] [blame] | 5245 | u8 value; |
| 5246 | |
Stanislaw Gruszka | c322357 | 2013-05-18 14:03:28 +0200 | [diff] [blame] | 5247 | rt2800_bbp4_mac_if_ctrl(rt2x00dev); |
Stanislaw Gruszka | b2f8e0b | 2013-05-18 14:03:29 +0200 | [diff] [blame] | 5248 | |
| 5249 | rt2800_bbp_write(rt2x00dev, 31, 0x08); |
Stanislaw Gruszka | e379de1 | 2013-05-18 14:03:31 +0200 | [diff] [blame] | 5250 | |
| 5251 | rt2800_bbp_write(rt2x00dev, 65, 0x2c); |
| 5252 | rt2800_bbp_write(rt2x00dev, 66, 0x38); |
Stanislaw Gruszka | 59dcabb | 2013-05-18 14:03:32 +0200 | [diff] [blame] | 5253 | |
| 5254 | rt2800_bbp_write(rt2x00dev, 68, 0x0b); |
Stanislaw Gruszka | 72ffe14 | 2013-05-18 14:03:33 +0200 | [diff] [blame] | 5255 | |
| 5256 | rt2800_bbp_write(rt2x00dev, 69, 0x12); |
| 5257 | rt2800_bbp_write(rt2x00dev, 73, 0x13); |
| 5258 | rt2800_bbp_write(rt2x00dev, 75, 0x46); |
| 5259 | rt2800_bbp_write(rt2x00dev, 76, 0x28); |
| 5260 | |
| 5261 | rt2800_bbp_write(rt2x00dev, 77, 0x58); |
Stanislaw Gruszka | 8d97be3 | 2013-05-18 14:03:34 +0200 | [diff] [blame] | 5262 | |
| 5263 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
Stanislaw Gruszka | 43f535e | 2013-05-18 14:03:35 +0200 | [diff] [blame] | 5264 | |
| 5265 | rt2800_bbp_write(rt2x00dev, 74, 0x0b); |
| 5266 | rt2800_bbp_write(rt2x00dev, 79, 0x18); |
| 5267 | rt2800_bbp_write(rt2x00dev, 80, 0x09); |
| 5268 | rt2800_bbp_write(rt2x00dev, 81, 0x33); |
Stanislaw Gruszka | fa1e342 | 2013-05-18 14:03:36 +0200 | [diff] [blame] | 5269 | |
| 5270 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
Stanislaw Gruszka | 885f241 | 2013-05-18 14:03:37 +0200 | [diff] [blame] | 5271 | |
| 5272 | rt2800_bbp_write(rt2x00dev, 83, 0x7a); |
Stanislaw Gruszka | 3c20a12 | 2013-05-18 14:03:38 +0200 | [diff] [blame] | 5273 | |
| 5274 | rt2800_bbp_write(rt2x00dev, 84, 0x9a); |
Stanislaw Gruszka | aef9f38 | 2013-05-18 14:03:39 +0200 | [diff] [blame] | 5275 | |
| 5276 | rt2800_bbp_write(rt2x00dev, 86, 0x38); |
Stanislaw Gruszka | 7af9874 | 2013-05-18 14:03:41 +0200 | [diff] [blame] | 5277 | |
| 5278 | rt2800_bbp_write(rt2x00dev, 91, 0x04); |
Stanislaw Gruszka | b4e121d | 2013-05-18 14:03:42 +0200 | [diff] [blame] | 5279 | |
| 5280 | rt2800_bbp_write(rt2x00dev, 92, 0x02); |
Stanislaw Gruszka | 672d118 | 2013-05-18 14:03:44 +0200 | [diff] [blame] | 5281 | |
| 5282 | rt2800_bbp_write(rt2x00dev, 103, 0xc0); |
Stanislaw Gruszka | 1ad4408 | 2013-05-18 14:03:45 +0200 | [diff] [blame] | 5283 | |
| 5284 | rt2800_bbp_write(rt2x00dev, 104, 0x92); |
Stanislaw Gruszka | 49d6111 | 2013-05-18 14:03:46 +0200 | [diff] [blame] | 5285 | |
| 5286 | rt2800_bbp_write(rt2x00dev, 105, 0x1c); |
Stanislaw Gruszka | f867085 | 2013-05-18 14:03:47 +0200 | [diff] [blame] | 5287 | |
| 5288 | rt2800_bbp_write(rt2x00dev, 106, 0x03); |
Stanislaw Gruszka | f2b6777 | 2013-05-18 14:03:49 +0200 | [diff] [blame] | 5289 | |
| 5290 | rt2800_bbp_write(rt2x00dev, 128, 0x12); |
Stanislaw Gruszka | 6addb24 | 2013-05-18 14:03:54 +0200 | [diff] [blame] | 5291 | |
| 5292 | rt2800_bbp_write(rt2x00dev, 67, 0x24); |
| 5293 | rt2800_bbp_write(rt2x00dev, 143, 0x04); |
| 5294 | rt2800_bbp_write(rt2x00dev, 142, 0x99); |
| 5295 | rt2800_bbp_write(rt2x00dev, 150, 0x30); |
| 5296 | rt2800_bbp_write(rt2x00dev, 151, 0x2e); |
| 5297 | rt2800_bbp_write(rt2x00dev, 152, 0x20); |
| 5298 | rt2800_bbp_write(rt2x00dev, 153, 0x34); |
| 5299 | rt2800_bbp_write(rt2x00dev, 154, 0x40); |
| 5300 | rt2800_bbp_write(rt2x00dev, 155, 0x3b); |
| 5301 | rt2800_bbp_write(rt2x00dev, 253, 0x04); |
| 5302 | |
| 5303 | rt2800_bbp_read(rt2x00dev, 47, &value); |
| 5304 | rt2x00_set_field8(&value, BBP47_TSSI_ADC6, 1); |
| 5305 | rt2800_bbp_write(rt2x00dev, 47, value); |
| 5306 | |
| 5307 | /* Use 5-bit ADC for Acquisition and 8-bit ADC for data */ |
| 5308 | rt2800_bbp_read(rt2x00dev, 3, &value); |
| 5309 | rt2x00_set_field8(&value, BBP3_ADC_MODE_SWITCH, 1); |
| 5310 | rt2x00_set_field8(&value, BBP3_ADC_INIT_MODE, 1); |
| 5311 | rt2800_bbp_write(rt2x00dev, 3, value); |
Stanislaw Gruszka | 39ab3e8 | 2013-05-18 14:03:25 +0200 | [diff] [blame] | 5312 | } |
| 5313 | |
| 5314 | static void rt2800_init_bbp_3352(struct rt2x00_dev *rt2x00dev) |
| 5315 | { |
Stanislaw Gruszka | 29f3a58 | 2013-05-18 14:03:27 +0200 | [diff] [blame] | 5316 | rt2800_bbp_write(rt2x00dev, 3, 0x00); |
| 5317 | rt2800_bbp_write(rt2x00dev, 4, 0x50); |
Stanislaw Gruszka | b2f8e0b | 2013-05-18 14:03:29 +0200 | [diff] [blame] | 5318 | |
| 5319 | rt2800_bbp_write(rt2x00dev, 31, 0x08); |
Stanislaw Gruszka | 3420f79 | 2013-05-18 14:03:30 +0200 | [diff] [blame] | 5320 | |
| 5321 | rt2800_bbp_write(rt2x00dev, 47, 0x48); |
Stanislaw Gruszka | e379de1 | 2013-05-18 14:03:31 +0200 | [diff] [blame] | 5322 | |
| 5323 | rt2800_bbp_write(rt2x00dev, 65, 0x2c); |
| 5324 | rt2800_bbp_write(rt2x00dev, 66, 0x38); |
Stanislaw Gruszka | 59dcabb | 2013-05-18 14:03:32 +0200 | [diff] [blame] | 5325 | |
| 5326 | rt2800_bbp_write(rt2x00dev, 68, 0x0b); |
Stanislaw Gruszka | 72ffe14 | 2013-05-18 14:03:33 +0200 | [diff] [blame] | 5327 | |
| 5328 | rt2800_bbp_write(rt2x00dev, 69, 0x12); |
| 5329 | rt2800_bbp_write(rt2x00dev, 73, 0x13); |
| 5330 | rt2800_bbp_write(rt2x00dev, 75, 0x46); |
| 5331 | rt2800_bbp_write(rt2x00dev, 76, 0x28); |
| 5332 | |
| 5333 | rt2800_bbp_write(rt2x00dev, 77, 0x59); |
Stanislaw Gruszka | 8d97be3 | 2013-05-18 14:03:34 +0200 | [diff] [blame] | 5334 | |
| 5335 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
Stanislaw Gruszka | 43f535e | 2013-05-18 14:03:35 +0200 | [diff] [blame] | 5336 | |
| 5337 | rt2800_bbp_write(rt2x00dev, 78, 0x0e); |
| 5338 | rt2800_bbp_write(rt2x00dev, 80, 0x08); |
| 5339 | rt2800_bbp_write(rt2x00dev, 81, 0x37); |
Stanislaw Gruszka | fa1e342 | 2013-05-18 14:03:36 +0200 | [diff] [blame] | 5340 | |
| 5341 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
Stanislaw Gruszka | 885f241 | 2013-05-18 14:03:37 +0200 | [diff] [blame] | 5342 | |
| 5343 | rt2800_bbp_write(rt2x00dev, 83, 0x6a); |
Stanislaw Gruszka | 3c20a12 | 2013-05-18 14:03:38 +0200 | [diff] [blame] | 5344 | |
| 5345 | rt2800_bbp_write(rt2x00dev, 84, 0x99); |
Stanislaw Gruszka | aef9f38 | 2013-05-18 14:03:39 +0200 | [diff] [blame] | 5346 | |
| 5347 | rt2800_bbp_write(rt2x00dev, 86, 0x38); |
Stanislaw Gruszka | 9400fa8 | 2013-05-18 14:03:40 +0200 | [diff] [blame] | 5348 | |
| 5349 | rt2800_bbp_write(rt2x00dev, 88, 0x90); |
Stanislaw Gruszka | 7af9874 | 2013-05-18 14:03:41 +0200 | [diff] [blame] | 5350 | |
| 5351 | rt2800_bbp_write(rt2x00dev, 91, 0x04); |
Stanislaw Gruszka | b4e121d | 2013-05-18 14:03:42 +0200 | [diff] [blame] | 5352 | |
| 5353 | rt2800_bbp_write(rt2x00dev, 92, 0x02); |
Stanislaw Gruszka | 672d118 | 2013-05-18 14:03:44 +0200 | [diff] [blame] | 5354 | |
| 5355 | rt2800_bbp_write(rt2x00dev, 103, 0xc0); |
Stanislaw Gruszka | 1ad4408 | 2013-05-18 14:03:45 +0200 | [diff] [blame] | 5356 | |
| 5357 | rt2800_bbp_write(rt2x00dev, 104, 0x92); |
Stanislaw Gruszka | 49d6111 | 2013-05-18 14:03:46 +0200 | [diff] [blame] | 5358 | |
| 5359 | rt2800_bbp_write(rt2x00dev, 105, 0x34); |
Stanislaw Gruszka | f867085 | 2013-05-18 14:03:47 +0200 | [diff] [blame] | 5360 | |
| 5361 | rt2800_bbp_write(rt2x00dev, 106, 0x05); |
Stanislaw Gruszka | 46b90d3 | 2013-05-18 14:03:48 +0200 | [diff] [blame] | 5362 | |
| 5363 | rt2800_bbp_write(rt2x00dev, 120, 0x50); |
Stanislaw Gruszka | b7feb9b | 2013-05-18 14:03:51 +0200 | [diff] [blame] | 5364 | |
| 5365 | rt2800_bbp_write(rt2x00dev, 137, 0x0f); |
Stanislaw Gruszka | c2da527 | 2013-05-18 14:03:53 +0200 | [diff] [blame] | 5366 | |
| 5367 | rt2800_bbp_write(rt2x00dev, 163, 0xbd); |
| 5368 | /* Set ITxBF timeout to 0x9c40=1000msec */ |
| 5369 | rt2800_bbp_write(rt2x00dev, 179, 0x02); |
| 5370 | rt2800_bbp_write(rt2x00dev, 180, 0x00); |
| 5371 | rt2800_bbp_write(rt2x00dev, 182, 0x40); |
| 5372 | rt2800_bbp_write(rt2x00dev, 180, 0x01); |
| 5373 | rt2800_bbp_write(rt2x00dev, 182, 0x9c); |
| 5374 | rt2800_bbp_write(rt2x00dev, 179, 0x00); |
| 5375 | /* Reprogram the inband interface to put right values in RXWI */ |
| 5376 | rt2800_bbp_write(rt2x00dev, 142, 0x04); |
| 5377 | rt2800_bbp_write(rt2x00dev, 143, 0x3b); |
| 5378 | rt2800_bbp_write(rt2x00dev, 142, 0x06); |
| 5379 | rt2800_bbp_write(rt2x00dev, 143, 0xa0); |
| 5380 | rt2800_bbp_write(rt2x00dev, 142, 0x07); |
| 5381 | rt2800_bbp_write(rt2x00dev, 143, 0xa1); |
| 5382 | rt2800_bbp_write(rt2x00dev, 142, 0x08); |
| 5383 | rt2800_bbp_write(rt2x00dev, 143, 0xa2); |
| 5384 | |
| 5385 | rt2800_bbp_write(rt2x00dev, 148, 0xc8); |
Stanislaw Gruszka | 39ab3e8 | 2013-05-18 14:03:25 +0200 | [diff] [blame] | 5386 | } |
| 5387 | |
| 5388 | static void rt2800_init_bbp_3390(struct rt2x00_dev *rt2x00dev) |
| 5389 | { |
Stanislaw Gruszka | e379de1 | 2013-05-18 14:03:31 +0200 | [diff] [blame] | 5390 | rt2800_bbp_write(rt2x00dev, 65, 0x2c); |
| 5391 | rt2800_bbp_write(rt2x00dev, 66, 0x38); |
Stanislaw Gruszka | 72ffe14 | 2013-05-18 14:03:33 +0200 | [diff] [blame] | 5392 | |
| 5393 | rt2800_bbp_write(rt2x00dev, 69, 0x12); |
| 5394 | rt2800_bbp_write(rt2x00dev, 73, 0x10); |
Stanislaw Gruszka | 8d97be3 | 2013-05-18 14:03:34 +0200 | [diff] [blame] | 5395 | |
| 5396 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
Stanislaw Gruszka | 43f535e | 2013-05-18 14:03:35 +0200 | [diff] [blame] | 5397 | |
| 5398 | rt2800_bbp_write(rt2x00dev, 79, 0x13); |
| 5399 | rt2800_bbp_write(rt2x00dev, 80, 0x05); |
| 5400 | rt2800_bbp_write(rt2x00dev, 81, 0x33); |
Stanislaw Gruszka | fa1e342 | 2013-05-18 14:03:36 +0200 | [diff] [blame] | 5401 | |
| 5402 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
Stanislaw Gruszka | 885f241 | 2013-05-18 14:03:37 +0200 | [diff] [blame] | 5403 | |
| 5404 | rt2800_bbp_write(rt2x00dev, 83, 0x6a); |
Stanislaw Gruszka | 3c20a12 | 2013-05-18 14:03:38 +0200 | [diff] [blame] | 5405 | |
| 5406 | rt2800_bbp_write(rt2x00dev, 84, 0x99); |
Stanislaw Gruszka | aef9f38 | 2013-05-18 14:03:39 +0200 | [diff] [blame] | 5407 | |
| 5408 | rt2800_bbp_write(rt2x00dev, 86, 0x00); |
Stanislaw Gruszka | 7af9874 | 2013-05-18 14:03:41 +0200 | [diff] [blame] | 5409 | |
| 5410 | rt2800_bbp_write(rt2x00dev, 91, 0x04); |
Stanislaw Gruszka | b4e121d | 2013-05-18 14:03:42 +0200 | [diff] [blame] | 5411 | |
| 5412 | rt2800_bbp_write(rt2x00dev, 92, 0x00); |
Stanislaw Gruszka | 672d118 | 2013-05-18 14:03:44 +0200 | [diff] [blame] | 5413 | |
| 5414 | if (rt2x00_rt_rev_gte(rt2x00dev, RT3390, REV_RT3390E)) |
| 5415 | rt2800_bbp_write(rt2x00dev, 103, 0xc0); |
| 5416 | else |
| 5417 | rt2800_bbp_write(rt2x00dev, 103, 0x00); |
Stanislaw Gruszka | 49d6111 | 2013-05-18 14:03:46 +0200 | [diff] [blame] | 5418 | |
| 5419 | rt2800_bbp_write(rt2x00dev, 105, 0x05); |
Stanislaw Gruszka | f867085 | 2013-05-18 14:03:47 +0200 | [diff] [blame] | 5420 | |
| 5421 | rt2800_bbp_write(rt2x00dev, 106, 0x35); |
Stanislaw Gruszka | 5df1ff3 | 2013-05-18 14:03:52 +0200 | [diff] [blame] | 5422 | |
| 5423 | rt2800_disable_unused_dac_adc(rt2x00dev); |
Stanislaw Gruszka | 39ab3e8 | 2013-05-18 14:03:25 +0200 | [diff] [blame] | 5424 | } |
| 5425 | |
| 5426 | static void rt2800_init_bbp_3572(struct rt2x00_dev *rt2x00dev) |
| 5427 | { |
Stanislaw Gruszka | b2f8e0b | 2013-05-18 14:03:29 +0200 | [diff] [blame] | 5428 | rt2800_bbp_write(rt2x00dev, 31, 0x08); |
Stanislaw Gruszka | e379de1 | 2013-05-18 14:03:31 +0200 | [diff] [blame] | 5429 | |
| 5430 | rt2800_bbp_write(rt2x00dev, 65, 0x2c); |
| 5431 | rt2800_bbp_write(rt2x00dev, 66, 0x38); |
Stanislaw Gruszka | 72ffe14 | 2013-05-18 14:03:33 +0200 | [diff] [blame] | 5432 | |
| 5433 | rt2800_bbp_write(rt2x00dev, 69, 0x12); |
| 5434 | rt2800_bbp_write(rt2x00dev, 73, 0x10); |
Stanislaw Gruszka | 8d97be3 | 2013-05-18 14:03:34 +0200 | [diff] [blame] | 5435 | |
| 5436 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
Stanislaw Gruszka | 43f535e | 2013-05-18 14:03:35 +0200 | [diff] [blame] | 5437 | |
| 5438 | rt2800_bbp_write(rt2x00dev, 79, 0x13); |
| 5439 | rt2800_bbp_write(rt2x00dev, 80, 0x05); |
| 5440 | rt2800_bbp_write(rt2x00dev, 81, 0x33); |
Stanislaw Gruszka | fa1e342 | 2013-05-18 14:03:36 +0200 | [diff] [blame] | 5441 | |
| 5442 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
Stanislaw Gruszka | 885f241 | 2013-05-18 14:03:37 +0200 | [diff] [blame] | 5443 | |
| 5444 | rt2800_bbp_write(rt2x00dev, 83, 0x6a); |
Stanislaw Gruszka | 3c20a12 | 2013-05-18 14:03:38 +0200 | [diff] [blame] | 5445 | |
| 5446 | rt2800_bbp_write(rt2x00dev, 84, 0x99); |
Stanislaw Gruszka | aef9f38 | 2013-05-18 14:03:39 +0200 | [diff] [blame] | 5447 | |
| 5448 | rt2800_bbp_write(rt2x00dev, 86, 0x00); |
Stanislaw Gruszka | 7af9874 | 2013-05-18 14:03:41 +0200 | [diff] [blame] | 5449 | |
| 5450 | rt2800_bbp_write(rt2x00dev, 91, 0x04); |
Stanislaw Gruszka | b4e121d | 2013-05-18 14:03:42 +0200 | [diff] [blame] | 5451 | |
| 5452 | rt2800_bbp_write(rt2x00dev, 92, 0x00); |
Stanislaw Gruszka | 672d118 | 2013-05-18 14:03:44 +0200 | [diff] [blame] | 5453 | |
| 5454 | rt2800_bbp_write(rt2x00dev, 103, 0xc0); |
Stanislaw Gruszka | 49d6111 | 2013-05-18 14:03:46 +0200 | [diff] [blame] | 5455 | |
| 5456 | rt2800_bbp_write(rt2x00dev, 105, 0x05); |
Stanislaw Gruszka | f867085 | 2013-05-18 14:03:47 +0200 | [diff] [blame] | 5457 | |
| 5458 | rt2800_bbp_write(rt2x00dev, 106, 0x35); |
Stanislaw Gruszka | 5df1ff3 | 2013-05-18 14:03:52 +0200 | [diff] [blame] | 5459 | |
| 5460 | rt2800_disable_unused_dac_adc(rt2x00dev); |
Stanislaw Gruszka | 39ab3e8 | 2013-05-18 14:03:25 +0200 | [diff] [blame] | 5461 | } |
| 5462 | |
Gabor Juhos | b189a18 | 2013-07-08 16:08:17 +0200 | [diff] [blame] | 5463 | static void rt2800_init_bbp_3593(struct rt2x00_dev *rt2x00dev) |
| 5464 | { |
| 5465 | rt2800_init_bbp_early(rt2x00dev); |
| 5466 | |
| 5467 | rt2800_bbp_write(rt2x00dev, 79, 0x13); |
| 5468 | rt2800_bbp_write(rt2x00dev, 80, 0x05); |
| 5469 | rt2800_bbp_write(rt2x00dev, 81, 0x33); |
| 5470 | rt2800_bbp_write(rt2x00dev, 137, 0x0f); |
| 5471 | |
| 5472 | rt2800_bbp_write(rt2x00dev, 84, 0x19); |
| 5473 | |
| 5474 | /* Enable DC filter */ |
| 5475 | if (rt2x00_rt_rev_gte(rt2x00dev, RT3593, REV_RT3593E)) |
| 5476 | rt2800_bbp_write(rt2x00dev, 103, 0xc0); |
| 5477 | } |
| 5478 | |
Stanislaw Gruszka | 39ab3e8 | 2013-05-18 14:03:25 +0200 | [diff] [blame] | 5479 | static void rt2800_init_bbp_53xx(struct rt2x00_dev *rt2x00dev) |
| 5480 | { |
Stanislaw Gruszka | 32ef8f4 | 2013-05-18 14:03:55 +0200 | [diff] [blame] | 5481 | int ant, div_mode; |
| 5482 | u16 eeprom; |
| 5483 | u8 value; |
| 5484 | |
Stanislaw Gruszka | c322357 | 2013-05-18 14:03:28 +0200 | [diff] [blame] | 5485 | rt2800_bbp4_mac_if_ctrl(rt2x00dev); |
Stanislaw Gruszka | b2f8e0b | 2013-05-18 14:03:29 +0200 | [diff] [blame] | 5486 | |
| 5487 | rt2800_bbp_write(rt2x00dev, 31, 0x08); |
Stanislaw Gruszka | e379de1 | 2013-05-18 14:03:31 +0200 | [diff] [blame] | 5488 | |
| 5489 | rt2800_bbp_write(rt2x00dev, 65, 0x2c); |
| 5490 | rt2800_bbp_write(rt2x00dev, 66, 0x38); |
Stanislaw Gruszka | 59dcabb | 2013-05-18 14:03:32 +0200 | [diff] [blame] | 5491 | |
| 5492 | rt2800_bbp_write(rt2x00dev, 68, 0x0b); |
Stanislaw Gruszka | 72ffe14 | 2013-05-18 14:03:33 +0200 | [diff] [blame] | 5493 | |
Stanislaw Gruszka | 5842219 | 2014-03-12 15:14:04 +0100 | [diff] [blame] | 5494 | rt2800_bbp_write(rt2x00dev, 69, 0x12); |
Stanislaw Gruszka | 72ffe14 | 2013-05-18 14:03:33 +0200 | [diff] [blame] | 5495 | rt2800_bbp_write(rt2x00dev, 73, 0x13); |
| 5496 | rt2800_bbp_write(rt2x00dev, 75, 0x46); |
| 5497 | rt2800_bbp_write(rt2x00dev, 76, 0x28); |
| 5498 | |
| 5499 | rt2800_bbp_write(rt2x00dev, 77, 0x59); |
Stanislaw Gruszka | 8d97be3 | 2013-05-18 14:03:34 +0200 | [diff] [blame] | 5500 | |
Stanislaw Gruszka | 5842219 | 2014-03-12 15:14:04 +0100 | [diff] [blame] | 5501 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
| 5502 | |
Stanislaw Gruszka | 43f535e | 2013-05-18 14:03:35 +0200 | [diff] [blame] | 5503 | rt2800_bbp_write(rt2x00dev, 79, 0x13); |
| 5504 | rt2800_bbp_write(rt2x00dev, 80, 0x05); |
| 5505 | rt2800_bbp_write(rt2x00dev, 81, 0x33); |
Stanislaw Gruszka | fa1e342 | 2013-05-18 14:03:36 +0200 | [diff] [blame] | 5506 | |
| 5507 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
Stanislaw Gruszka | 885f241 | 2013-05-18 14:03:37 +0200 | [diff] [blame] | 5508 | |
| 5509 | rt2800_bbp_write(rt2x00dev, 83, 0x7a); |
Stanislaw Gruszka | 3c20a12 | 2013-05-18 14:03:38 +0200 | [diff] [blame] | 5510 | |
| 5511 | rt2800_bbp_write(rt2x00dev, 84, 0x9a); |
Stanislaw Gruszka | aef9f38 | 2013-05-18 14:03:39 +0200 | [diff] [blame] | 5512 | |
| 5513 | rt2800_bbp_write(rt2x00dev, 86, 0x38); |
Stanislaw Gruszka | 9400fa8 | 2013-05-18 14:03:40 +0200 | [diff] [blame] | 5514 | |
| 5515 | if (rt2x00_rt(rt2x00dev, RT5392)) |
| 5516 | rt2800_bbp_write(rt2x00dev, 88, 0x90); |
Stanislaw Gruszka | 7af9874 | 2013-05-18 14:03:41 +0200 | [diff] [blame] | 5517 | |
| 5518 | rt2800_bbp_write(rt2x00dev, 91, 0x04); |
Stanislaw Gruszka | b4e121d | 2013-05-18 14:03:42 +0200 | [diff] [blame] | 5519 | |
| 5520 | rt2800_bbp_write(rt2x00dev, 92, 0x02); |
Stanislaw Gruszka | 90fed53 | 2013-05-18 14:03:43 +0200 | [diff] [blame] | 5521 | |
| 5522 | if (rt2x00_rt(rt2x00dev, RT5392)) { |
| 5523 | rt2800_bbp_write(rt2x00dev, 95, 0x9a); |
| 5524 | rt2800_bbp_write(rt2x00dev, 98, 0x12); |
| 5525 | } |
Stanislaw Gruszka | 672d118 | 2013-05-18 14:03:44 +0200 | [diff] [blame] | 5526 | |
| 5527 | rt2800_bbp_write(rt2x00dev, 103, 0xc0); |
Stanislaw Gruszka | 1ad4408 | 2013-05-18 14:03:45 +0200 | [diff] [blame] | 5528 | |
| 5529 | rt2800_bbp_write(rt2x00dev, 104, 0x92); |
Stanislaw Gruszka | 49d6111 | 2013-05-18 14:03:46 +0200 | [diff] [blame] | 5530 | |
| 5531 | rt2800_bbp_write(rt2x00dev, 105, 0x3c); |
Stanislaw Gruszka | f867085 | 2013-05-18 14:03:47 +0200 | [diff] [blame] | 5532 | |
| 5533 | if (rt2x00_rt(rt2x00dev, RT5390)) |
| 5534 | rt2800_bbp_write(rt2x00dev, 106, 0x03); |
| 5535 | else if (rt2x00_rt(rt2x00dev, RT5392)) |
| 5536 | rt2800_bbp_write(rt2x00dev, 106, 0x12); |
| 5537 | else |
| 5538 | WARN_ON(1); |
Stanislaw Gruszka | f2b6777 | 2013-05-18 14:03:49 +0200 | [diff] [blame] | 5539 | |
| 5540 | rt2800_bbp_write(rt2x00dev, 128, 0x12); |
Stanislaw Gruszka | 7291714 | 2013-05-18 14:03:50 +0200 | [diff] [blame] | 5541 | |
| 5542 | if (rt2x00_rt(rt2x00dev, RT5392)) { |
| 5543 | rt2800_bbp_write(rt2x00dev, 134, 0xd0); |
| 5544 | rt2800_bbp_write(rt2x00dev, 135, 0xf6); |
| 5545 | } |
Stanislaw Gruszka | 5df1ff3 | 2013-05-18 14:03:52 +0200 | [diff] [blame] | 5546 | |
| 5547 | rt2800_disable_unused_dac_adc(rt2x00dev); |
Stanislaw Gruszka | 32ef8f4 | 2013-05-18 14:03:55 +0200 | [diff] [blame] | 5548 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 5549 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom); |
Stanislaw Gruszka | 32ef8f4 | 2013-05-18 14:03:55 +0200 | [diff] [blame] | 5550 | div_mode = rt2x00_get_field16(eeprom, |
| 5551 | EEPROM_NIC_CONF1_ANT_DIVERSITY); |
| 5552 | ant = (div_mode == 3) ? 1 : 0; |
| 5553 | |
| 5554 | /* check if this is a Bluetooth combo card */ |
Gabor Juhos | c429dfe | 2013-10-11 13:18:42 +0200 | [diff] [blame] | 5555 | if (rt2x00_has_cap_bt_coexist(rt2x00dev)) { |
Stanislaw Gruszka | 32ef8f4 | 2013-05-18 14:03:55 +0200 | [diff] [blame] | 5556 | u32 reg; |
| 5557 | |
| 5558 | rt2800_register_read(rt2x00dev, GPIO_CTRL, ®); |
| 5559 | rt2x00_set_field32(®, GPIO_CTRL_DIR3, 0); |
| 5560 | rt2x00_set_field32(®, GPIO_CTRL_DIR6, 0); |
| 5561 | rt2x00_set_field32(®, GPIO_CTRL_VAL3, 0); |
| 5562 | rt2x00_set_field32(®, GPIO_CTRL_VAL6, 0); |
| 5563 | if (ant == 0) |
| 5564 | rt2x00_set_field32(®, GPIO_CTRL_VAL3, 1); |
| 5565 | else if (ant == 1) |
| 5566 | rt2x00_set_field32(®, GPIO_CTRL_VAL6, 1); |
| 5567 | rt2800_register_write(rt2x00dev, GPIO_CTRL, reg); |
| 5568 | } |
| 5569 | |
| 5570 | /* This chip has hardware antenna diversity*/ |
| 5571 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390R)) { |
| 5572 | rt2800_bbp_write(rt2x00dev, 150, 0); /* Disable Antenna Software OFDM */ |
| 5573 | rt2800_bbp_write(rt2x00dev, 151, 0); /* Disable Antenna Software CCK */ |
| 5574 | rt2800_bbp_write(rt2x00dev, 154, 0); /* Clear previously selected antenna */ |
| 5575 | } |
| 5576 | |
| 5577 | rt2800_bbp_read(rt2x00dev, 152, &value); |
| 5578 | if (ant == 0) |
| 5579 | rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 1); |
| 5580 | else |
| 5581 | rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 0); |
| 5582 | rt2800_bbp_write(rt2x00dev, 152, value); |
| 5583 | |
| 5584 | rt2800_init_freq_calibration(rt2x00dev); |
Stanislaw Gruszka | 39ab3e8 | 2013-05-18 14:03:25 +0200 | [diff] [blame] | 5585 | } |
| 5586 | |
Stanislaw Gruszka | a7bbbe5 | 2013-03-16 19:19:34 +0100 | [diff] [blame] | 5587 | static void rt2800_init_bbp_5592(struct rt2x00_dev *rt2x00dev) |
| 5588 | { |
| 5589 | int ant, div_mode; |
| 5590 | u16 eeprom; |
| 5591 | u8 value; |
| 5592 | |
Gabor Juhos | 624708b | 2013-04-19 10:13:52 +0200 | [diff] [blame] | 5593 | rt2800_init_bbp_early(rt2x00dev); |
Stanislaw Gruszka | a4969d0 | 2013-03-16 19:19:35 +0100 | [diff] [blame] | 5594 | |
Stanislaw Gruszka | a7bbbe5 | 2013-03-16 19:19:34 +0100 | [diff] [blame] | 5595 | rt2800_bbp_read(rt2x00dev, 105, &value); |
| 5596 | rt2x00_set_field8(&value, BBP105_MLD, |
| 5597 | rt2x00dev->default_ant.rx_chain_num == 2); |
| 5598 | rt2800_bbp_write(rt2x00dev, 105, value); |
| 5599 | |
| 5600 | rt2800_bbp4_mac_if_ctrl(rt2x00dev); |
| 5601 | |
| 5602 | rt2800_bbp_write(rt2x00dev, 20, 0x06); |
| 5603 | rt2800_bbp_write(rt2x00dev, 31, 0x08); |
| 5604 | rt2800_bbp_write(rt2x00dev, 65, 0x2C); |
| 5605 | rt2800_bbp_write(rt2x00dev, 68, 0xDD); |
| 5606 | rt2800_bbp_write(rt2x00dev, 69, 0x1A); |
| 5607 | rt2800_bbp_write(rt2x00dev, 70, 0x05); |
| 5608 | rt2800_bbp_write(rt2x00dev, 73, 0x13); |
| 5609 | rt2800_bbp_write(rt2x00dev, 74, 0x0F); |
| 5610 | rt2800_bbp_write(rt2x00dev, 75, 0x4F); |
| 5611 | rt2800_bbp_write(rt2x00dev, 76, 0x28); |
| 5612 | rt2800_bbp_write(rt2x00dev, 77, 0x59); |
| 5613 | rt2800_bbp_write(rt2x00dev, 84, 0x9A); |
| 5614 | rt2800_bbp_write(rt2x00dev, 86, 0x38); |
| 5615 | rt2800_bbp_write(rt2x00dev, 88, 0x90); |
| 5616 | rt2800_bbp_write(rt2x00dev, 91, 0x04); |
| 5617 | rt2800_bbp_write(rt2x00dev, 92, 0x02); |
| 5618 | rt2800_bbp_write(rt2x00dev, 95, 0x9a); |
| 5619 | rt2800_bbp_write(rt2x00dev, 98, 0x12); |
| 5620 | rt2800_bbp_write(rt2x00dev, 103, 0xC0); |
| 5621 | rt2800_bbp_write(rt2x00dev, 104, 0x92); |
| 5622 | /* FIXME BBP105 owerwrite */ |
| 5623 | rt2800_bbp_write(rt2x00dev, 105, 0x3C); |
| 5624 | rt2800_bbp_write(rt2x00dev, 106, 0x35); |
| 5625 | rt2800_bbp_write(rt2x00dev, 128, 0x12); |
| 5626 | rt2800_bbp_write(rt2x00dev, 134, 0xD0); |
| 5627 | rt2800_bbp_write(rt2x00dev, 135, 0xF6); |
| 5628 | rt2800_bbp_write(rt2x00dev, 137, 0x0F); |
| 5629 | |
| 5630 | /* Initialize GLRT (Generalized Likehood Radio Test) */ |
| 5631 | rt2800_init_bbp_5592_glrt(rt2x00dev); |
| 5632 | |
| 5633 | rt2800_bbp4_mac_if_ctrl(rt2x00dev); |
| 5634 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 5635 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom); |
Stanislaw Gruszka | a7bbbe5 | 2013-03-16 19:19:34 +0100 | [diff] [blame] | 5636 | div_mode = rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_ANT_DIVERSITY); |
| 5637 | ant = (div_mode == 3) ? 1 : 0; |
| 5638 | rt2800_bbp_read(rt2x00dev, 152, &value); |
| 5639 | if (ant == 0) { |
| 5640 | /* Main antenna */ |
| 5641 | rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 1); |
| 5642 | } else { |
| 5643 | /* Auxiliary antenna */ |
| 5644 | rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 0); |
| 5645 | } |
| 5646 | rt2800_bbp_write(rt2x00dev, 152, value); |
| 5647 | |
| 5648 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5592, REV_RT5592C)) { |
| 5649 | rt2800_bbp_read(rt2x00dev, 254, &value); |
| 5650 | rt2x00_set_field8(&value, BBP254_BIT7, 1); |
| 5651 | rt2800_bbp_write(rt2x00dev, 254, value); |
| 5652 | } |
| 5653 | |
Stanislaw Gruszka | c267548 | 2013-03-16 19:19:41 +0100 | [diff] [blame] | 5654 | rt2800_init_freq_calibration(rt2x00dev); |
| 5655 | |
Stanislaw Gruszka | a7bbbe5 | 2013-03-16 19:19:34 +0100 | [diff] [blame] | 5656 | rt2800_bbp_write(rt2x00dev, 84, 0x19); |
Stanislaw Gruszka | 6e04f25 | 2013-03-16 19:19:38 +0100 | [diff] [blame] | 5657 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5592, REV_RT5592C)) |
| 5658 | rt2800_bbp_write(rt2x00dev, 103, 0xc0); |
Stanislaw Gruszka | a7bbbe5 | 2013-03-16 19:19:34 +0100 | [diff] [blame] | 5659 | } |
| 5660 | |
Stanislaw Gruszka | a1ef503 | 2013-05-18 14:03:24 +0200 | [diff] [blame] | 5661 | static void rt2800_init_bbp(struct rt2x00_dev *rt2x00dev) |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 5662 | { |
| 5663 | unsigned int i; |
| 5664 | u16 eeprom; |
| 5665 | u8 reg_id; |
| 5666 | u8 value; |
| 5667 | |
Stanislaw Gruszka | dae6295 | 2013-05-18 14:03:26 +0200 | [diff] [blame] | 5668 | if (rt2800_is_305x_soc(rt2x00dev)) |
| 5669 | rt2800_init_bbp_305x_soc(rt2x00dev); |
| 5670 | |
Stanislaw Gruszka | 39ab3e8 | 2013-05-18 14:03:25 +0200 | [diff] [blame] | 5671 | switch (rt2x00dev->chip.rt) { |
| 5672 | case RT2860: |
| 5673 | case RT2872: |
| 5674 | case RT2883: |
| 5675 | rt2800_init_bbp_28xx(rt2x00dev); |
| 5676 | break; |
| 5677 | case RT3070: |
| 5678 | case RT3071: |
| 5679 | case RT3090: |
| 5680 | rt2800_init_bbp_30xx(rt2x00dev); |
| 5681 | break; |
| 5682 | case RT3290: |
| 5683 | rt2800_init_bbp_3290(rt2x00dev); |
| 5684 | break; |
| 5685 | case RT3352: |
| 5686 | rt2800_init_bbp_3352(rt2x00dev); |
| 5687 | break; |
| 5688 | case RT3390: |
| 5689 | rt2800_init_bbp_3390(rt2x00dev); |
| 5690 | break; |
| 5691 | case RT3572: |
| 5692 | rt2800_init_bbp_3572(rt2x00dev); |
| 5693 | break; |
Gabor Juhos | b189a18 | 2013-07-08 16:08:17 +0200 | [diff] [blame] | 5694 | case RT3593: |
| 5695 | rt2800_init_bbp_3593(rt2x00dev); |
| 5696 | return; |
Stanislaw Gruszka | 39ab3e8 | 2013-05-18 14:03:25 +0200 | [diff] [blame] | 5697 | case RT5390: |
| 5698 | case RT5392: |
| 5699 | rt2800_init_bbp_53xx(rt2x00dev); |
| 5700 | break; |
| 5701 | case RT5592: |
Stanislaw Gruszka | a7bbbe5 | 2013-03-16 19:19:34 +0100 | [diff] [blame] | 5702 | rt2800_init_bbp_5592(rt2x00dev); |
Stanislaw Gruszka | a1ef503 | 2013-05-18 14:03:24 +0200 | [diff] [blame] | 5703 | return; |
Stanislaw Gruszka | a7bbbe5 | 2013-03-16 19:19:34 +0100 | [diff] [blame] | 5704 | } |
| 5705 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 5706 | for (i = 0; i < EEPROM_BBP_SIZE; i++) { |
Gabor Juhos | 022138c | 2013-07-08 11:25:54 +0200 | [diff] [blame] | 5707 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_BBP_START, i, |
| 5708 | &eeprom); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 5709 | |
| 5710 | if (eeprom != 0xffff && eeprom != 0x0000) { |
| 5711 | reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID); |
| 5712 | value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE); |
| 5713 | rt2800_bbp_write(rt2x00dev, reg_id, value); |
| 5714 | } |
| 5715 | } |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 5716 | } |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 5717 | |
Stanislaw Gruszka | d9517f2 | 2013-04-17 14:08:18 +0200 | [diff] [blame] | 5718 | static void rt2800_led_open_drain_enable(struct rt2x00_dev *rt2x00dev) |
| 5719 | { |
| 5720 | u32 reg; |
| 5721 | |
| 5722 | rt2800_register_read(rt2x00dev, OPT_14_CSR, ®); |
| 5723 | rt2x00_set_field32(®, OPT_14_CSR_BIT0, 1); |
| 5724 | rt2800_register_write(rt2x00dev, OPT_14_CSR, reg); |
| 5725 | } |
| 5726 | |
Stanislaw Gruszka | c5b3c35 | 2013-04-17 14:08:16 +0200 | [diff] [blame] | 5727 | static u8 rt2800_init_rx_filter(struct rt2x00_dev *rt2x00dev, bool bw40, |
| 5728 | u8 filter_target) |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 5729 | { |
| 5730 | unsigned int i; |
| 5731 | u8 bbp; |
| 5732 | u8 rfcsr; |
| 5733 | u8 passband; |
| 5734 | u8 stopband; |
| 5735 | u8 overtuned = 0; |
Stanislaw Gruszka | c5b3c35 | 2013-04-17 14:08:16 +0200 | [diff] [blame] | 5736 | u8 rfcsr24 = (bw40) ? 0x27 : 0x07; |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 5737 | |
| 5738 | rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24); |
| 5739 | |
| 5740 | rt2800_bbp_read(rt2x00dev, 4, &bbp); |
| 5741 | rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * bw40); |
| 5742 | rt2800_bbp_write(rt2x00dev, 4, bbp); |
| 5743 | |
RA-Jay Hung | 80d184e | 2011-01-10 11:28:10 +0100 | [diff] [blame] | 5744 | rt2800_rfcsr_read(rt2x00dev, 31, &rfcsr); |
| 5745 | rt2x00_set_field8(&rfcsr, RFCSR31_RX_H20M, bw40); |
| 5746 | rt2800_rfcsr_write(rt2x00dev, 31, rfcsr); |
| 5747 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 5748 | rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr); |
| 5749 | rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 1); |
| 5750 | rt2800_rfcsr_write(rt2x00dev, 22, rfcsr); |
| 5751 | |
| 5752 | /* |
| 5753 | * Set power & frequency of passband test tone |
| 5754 | */ |
| 5755 | rt2800_bbp_write(rt2x00dev, 24, 0); |
| 5756 | |
| 5757 | for (i = 0; i < 100; i++) { |
| 5758 | rt2800_bbp_write(rt2x00dev, 25, 0x90); |
| 5759 | msleep(1); |
| 5760 | |
| 5761 | rt2800_bbp_read(rt2x00dev, 55, &passband); |
| 5762 | if (passband) |
| 5763 | break; |
| 5764 | } |
| 5765 | |
| 5766 | /* |
| 5767 | * Set power & frequency of stopband test tone |
| 5768 | */ |
| 5769 | rt2800_bbp_write(rt2x00dev, 24, 0x06); |
| 5770 | |
| 5771 | for (i = 0; i < 100; i++) { |
| 5772 | rt2800_bbp_write(rt2x00dev, 25, 0x90); |
| 5773 | msleep(1); |
| 5774 | |
| 5775 | rt2800_bbp_read(rt2x00dev, 55, &stopband); |
| 5776 | |
| 5777 | if ((passband - stopband) <= filter_target) { |
| 5778 | rfcsr24++; |
| 5779 | overtuned += ((passband - stopband) == filter_target); |
| 5780 | } else |
| 5781 | break; |
| 5782 | |
| 5783 | rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24); |
| 5784 | } |
| 5785 | |
| 5786 | rfcsr24 -= !!overtuned; |
| 5787 | |
| 5788 | rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24); |
| 5789 | return rfcsr24; |
| 5790 | } |
| 5791 | |
Stanislaw Gruszka | ce94ede9 | 2013-04-17 14:08:11 +0200 | [diff] [blame] | 5792 | static void rt2800_rf_init_calibration(struct rt2x00_dev *rt2x00dev, |
| 5793 | const unsigned int rf_reg) |
| 5794 | { |
| 5795 | u8 rfcsr; |
| 5796 | |
| 5797 | rt2800_rfcsr_read(rt2x00dev, rf_reg, &rfcsr); |
| 5798 | rt2x00_set_field8(&rfcsr, FIELD8(0x80), 1); |
| 5799 | rt2800_rfcsr_write(rt2x00dev, rf_reg, rfcsr); |
| 5800 | msleep(1); |
| 5801 | rt2x00_set_field8(&rfcsr, FIELD8(0x80), 0); |
| 5802 | rt2800_rfcsr_write(rt2x00dev, rf_reg, rfcsr); |
| 5803 | } |
| 5804 | |
Stanislaw Gruszka | c5b3c35 | 2013-04-17 14:08:16 +0200 | [diff] [blame] | 5805 | static void rt2800_rx_filter_calibration(struct rt2x00_dev *rt2x00dev) |
| 5806 | { |
| 5807 | struct rt2800_drv_data *drv_data = rt2x00dev->drv_data; |
| 5808 | u8 filter_tgt_bw20; |
| 5809 | u8 filter_tgt_bw40; |
| 5810 | u8 rfcsr, bbp; |
| 5811 | |
| 5812 | /* |
| 5813 | * TODO: sync filter_tgt values with vendor driver |
| 5814 | */ |
| 5815 | if (rt2x00_rt(rt2x00dev, RT3070)) { |
| 5816 | filter_tgt_bw20 = 0x16; |
| 5817 | filter_tgt_bw40 = 0x19; |
| 5818 | } else { |
| 5819 | filter_tgt_bw20 = 0x13; |
| 5820 | filter_tgt_bw40 = 0x15; |
| 5821 | } |
| 5822 | |
| 5823 | drv_data->calibration_bw20 = |
| 5824 | rt2800_init_rx_filter(rt2x00dev, false, filter_tgt_bw20); |
| 5825 | drv_data->calibration_bw40 = |
| 5826 | rt2800_init_rx_filter(rt2x00dev, true, filter_tgt_bw40); |
| 5827 | |
| 5828 | /* |
| 5829 | * Save BBP 25 & 26 values for later use in channel switching (for 3052) |
| 5830 | */ |
| 5831 | rt2800_bbp_read(rt2x00dev, 25, &drv_data->bbp25); |
| 5832 | rt2800_bbp_read(rt2x00dev, 26, &drv_data->bbp26); |
| 5833 | |
| 5834 | /* |
| 5835 | * Set back to initial state |
| 5836 | */ |
| 5837 | rt2800_bbp_write(rt2x00dev, 24, 0); |
| 5838 | |
| 5839 | rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr); |
| 5840 | rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 0); |
| 5841 | rt2800_rfcsr_write(rt2x00dev, 22, rfcsr); |
| 5842 | |
| 5843 | /* |
| 5844 | * Set BBP back to BW20 |
| 5845 | */ |
| 5846 | rt2800_bbp_read(rt2x00dev, 4, &bbp); |
| 5847 | rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0); |
| 5848 | rt2800_bbp_write(rt2x00dev, 4, bbp); |
| 5849 | } |
| 5850 | |
Stanislaw Gruszka | da8064c | 2013-04-17 14:08:19 +0200 | [diff] [blame] | 5851 | static void rt2800_normal_mode_setup_3xxx(struct rt2x00_dev *rt2x00dev) |
| 5852 | { |
| 5853 | struct rt2800_drv_data *drv_data = rt2x00dev->drv_data; |
| 5854 | u8 min_gain, rfcsr, bbp; |
| 5855 | u16 eeprom; |
| 5856 | |
| 5857 | rt2800_rfcsr_read(rt2x00dev, 17, &rfcsr); |
| 5858 | |
| 5859 | rt2x00_set_field8(&rfcsr, RFCSR17_TX_LO1_EN, 0); |
| 5860 | if (rt2x00_rt(rt2x00dev, RT3070) || |
| 5861 | rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) || |
| 5862 | rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E) || |
| 5863 | rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) { |
Gabor Juhos | c429dfe | 2013-10-11 13:18:42 +0200 | [diff] [blame] | 5864 | if (!rt2x00_has_cap_external_lna_bg(rt2x00dev)) |
Stanislaw Gruszka | da8064c | 2013-04-17 14:08:19 +0200 | [diff] [blame] | 5865 | rt2x00_set_field8(&rfcsr, RFCSR17_R, 1); |
| 5866 | } |
| 5867 | |
| 5868 | min_gain = rt2x00_rt(rt2x00dev, RT3070) ? 1 : 2; |
| 5869 | if (drv_data->txmixer_gain_24g >= min_gain) { |
| 5870 | rt2x00_set_field8(&rfcsr, RFCSR17_TXMIXER_GAIN, |
| 5871 | drv_data->txmixer_gain_24g); |
| 5872 | } |
| 5873 | |
| 5874 | rt2800_rfcsr_write(rt2x00dev, 17, rfcsr); |
| 5875 | |
| 5876 | if (rt2x00_rt(rt2x00dev, RT3090)) { |
| 5877 | /* Turn off unused DAC1 and ADC1 to reduce power consumption */ |
| 5878 | rt2800_bbp_read(rt2x00dev, 138, &bbp); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 5879 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom); |
Stanislaw Gruszka | da8064c | 2013-04-17 14:08:19 +0200 | [diff] [blame] | 5880 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) == 1) |
| 5881 | rt2x00_set_field8(&bbp, BBP138_RX_ADC1, 0); |
| 5882 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) == 1) |
| 5883 | rt2x00_set_field8(&bbp, BBP138_TX_DAC1, 1); |
| 5884 | rt2800_bbp_write(rt2x00dev, 138, bbp); |
| 5885 | } |
| 5886 | |
| 5887 | if (rt2x00_rt(rt2x00dev, RT3070)) { |
| 5888 | rt2800_rfcsr_read(rt2x00dev, 27, &rfcsr); |
| 5889 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) |
| 5890 | rt2x00_set_field8(&rfcsr, RFCSR27_R1, 3); |
| 5891 | else |
| 5892 | rt2x00_set_field8(&rfcsr, RFCSR27_R1, 0); |
| 5893 | rt2x00_set_field8(&rfcsr, RFCSR27_R2, 0); |
| 5894 | rt2x00_set_field8(&rfcsr, RFCSR27_R3, 0); |
| 5895 | rt2x00_set_field8(&rfcsr, RFCSR27_R4, 0); |
| 5896 | rt2800_rfcsr_write(rt2x00dev, 27, rfcsr); |
| 5897 | } else if (rt2x00_rt(rt2x00dev, RT3071) || |
| 5898 | rt2x00_rt(rt2x00dev, RT3090) || |
| 5899 | rt2x00_rt(rt2x00dev, RT3390)) { |
| 5900 | rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr); |
| 5901 | rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1); |
| 5902 | rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0); |
| 5903 | rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0); |
| 5904 | rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1); |
| 5905 | rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1); |
| 5906 | rt2800_rfcsr_write(rt2x00dev, 1, rfcsr); |
| 5907 | |
| 5908 | rt2800_rfcsr_read(rt2x00dev, 15, &rfcsr); |
| 5909 | rt2x00_set_field8(&rfcsr, RFCSR15_TX_LO2_EN, 0); |
| 5910 | rt2800_rfcsr_write(rt2x00dev, 15, rfcsr); |
| 5911 | |
| 5912 | rt2800_rfcsr_read(rt2x00dev, 20, &rfcsr); |
| 5913 | rt2x00_set_field8(&rfcsr, RFCSR20_RX_LO1_EN, 0); |
| 5914 | rt2800_rfcsr_write(rt2x00dev, 20, rfcsr); |
| 5915 | |
| 5916 | rt2800_rfcsr_read(rt2x00dev, 21, &rfcsr); |
| 5917 | rt2x00_set_field8(&rfcsr, RFCSR21_RX_LO2_EN, 0); |
| 5918 | rt2800_rfcsr_write(rt2x00dev, 21, rfcsr); |
| 5919 | } |
| 5920 | } |
| 5921 | |
Gabor Juhos | ab7078a | 2013-07-08 16:08:18 +0200 | [diff] [blame] | 5922 | static void rt2800_normal_mode_setup_3593(struct rt2x00_dev *rt2x00dev) |
| 5923 | { |
| 5924 | struct rt2800_drv_data *drv_data = rt2x00dev->drv_data; |
| 5925 | u8 rfcsr; |
| 5926 | u8 tx_gain; |
| 5927 | |
| 5928 | rt2800_rfcsr_read(rt2x00dev, 50, &rfcsr); |
| 5929 | rt2x00_set_field8(&rfcsr, RFCSR50_TX_LO2_EN, 0); |
| 5930 | rt2800_rfcsr_write(rt2x00dev, 50, rfcsr); |
| 5931 | |
| 5932 | rt2800_rfcsr_read(rt2x00dev, 51, &rfcsr); |
| 5933 | tx_gain = rt2x00_get_field8(drv_data->txmixer_gain_24g, |
| 5934 | RFCSR17_TXMIXER_GAIN); |
| 5935 | rt2x00_set_field8(&rfcsr, RFCSR51_BITS24, tx_gain); |
| 5936 | rt2800_rfcsr_write(rt2x00dev, 51, rfcsr); |
| 5937 | |
| 5938 | rt2800_rfcsr_read(rt2x00dev, 38, &rfcsr); |
| 5939 | rt2x00_set_field8(&rfcsr, RFCSR38_RX_LO1_EN, 0); |
| 5940 | rt2800_rfcsr_write(rt2x00dev, 38, rfcsr); |
| 5941 | |
| 5942 | rt2800_rfcsr_read(rt2x00dev, 39, &rfcsr); |
| 5943 | rt2x00_set_field8(&rfcsr, RFCSR39_RX_LO2_EN, 0); |
| 5944 | rt2800_rfcsr_write(rt2x00dev, 39, rfcsr); |
| 5945 | |
| 5946 | rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr); |
| 5947 | rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1); |
| 5948 | rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1); |
| 5949 | rt2800_rfcsr_write(rt2x00dev, 1, rfcsr); |
| 5950 | |
| 5951 | rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr); |
| 5952 | rt2x00_set_field8(&rfcsr, RFCSR30_RX_VCM, 2); |
| 5953 | rt2800_rfcsr_write(rt2x00dev, 30, rfcsr); |
| 5954 | |
| 5955 | /* TODO: enable stream mode */ |
| 5956 | } |
| 5957 | |
Stanislaw Gruszka | f7df8fe | 2013-04-17 14:08:10 +0200 | [diff] [blame] | 5958 | static void rt2800_normal_mode_setup_5xxx(struct rt2x00_dev *rt2x00dev) |
| 5959 | { |
| 5960 | u8 reg; |
| 5961 | u16 eeprom; |
| 5962 | |
| 5963 | /* Turn off unused DAC1 and ADC1 to reduce power consumption */ |
| 5964 | rt2800_bbp_read(rt2x00dev, 138, ®); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 5965 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom); |
Stanislaw Gruszka | f7df8fe | 2013-04-17 14:08:10 +0200 | [diff] [blame] | 5966 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) == 1) |
| 5967 | rt2x00_set_field8(®, BBP138_RX_ADC1, 0); |
| 5968 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) == 1) |
| 5969 | rt2x00_set_field8(®, BBP138_TX_DAC1, 1); |
| 5970 | rt2800_bbp_write(rt2x00dev, 138, reg); |
| 5971 | |
| 5972 | rt2800_rfcsr_read(rt2x00dev, 38, ®); |
| 5973 | rt2x00_set_field8(®, RFCSR38_RX_LO1_EN, 0); |
| 5974 | rt2800_rfcsr_write(rt2x00dev, 38, reg); |
| 5975 | |
| 5976 | rt2800_rfcsr_read(rt2x00dev, 39, ®); |
| 5977 | rt2x00_set_field8(®, RFCSR39_RX_LO2_EN, 0); |
| 5978 | rt2800_rfcsr_write(rt2x00dev, 39, reg); |
| 5979 | |
| 5980 | rt2800_bbp4_mac_if_ctrl(rt2x00dev); |
| 5981 | |
| 5982 | rt2800_rfcsr_read(rt2x00dev, 30, ®); |
| 5983 | rt2x00_set_field8(®, RFCSR30_RX_VCM, 2); |
| 5984 | rt2800_rfcsr_write(rt2x00dev, 30, reg); |
| 5985 | } |
| 5986 | |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 5987 | static void rt2800_init_rfcsr_305x_soc(struct rt2x00_dev *rt2x00dev) |
| 5988 | { |
Stanislaw Gruszka | ce94ede9 | 2013-04-17 14:08:11 +0200 | [diff] [blame] | 5989 | rt2800_rf_init_calibration(rt2x00dev, 30); |
| 5990 | |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 5991 | rt2800_rfcsr_write(rt2x00dev, 0, 0x50); |
| 5992 | rt2800_rfcsr_write(rt2x00dev, 1, 0x01); |
| 5993 | rt2800_rfcsr_write(rt2x00dev, 2, 0xf7); |
| 5994 | rt2800_rfcsr_write(rt2x00dev, 3, 0x75); |
| 5995 | rt2800_rfcsr_write(rt2x00dev, 4, 0x40); |
| 5996 | rt2800_rfcsr_write(rt2x00dev, 5, 0x03); |
| 5997 | rt2800_rfcsr_write(rt2x00dev, 6, 0x02); |
| 5998 | rt2800_rfcsr_write(rt2x00dev, 7, 0x50); |
| 5999 | rt2800_rfcsr_write(rt2x00dev, 8, 0x39); |
| 6000 | rt2800_rfcsr_write(rt2x00dev, 9, 0x0f); |
| 6001 | rt2800_rfcsr_write(rt2x00dev, 10, 0x60); |
| 6002 | rt2800_rfcsr_write(rt2x00dev, 11, 0x21); |
| 6003 | rt2800_rfcsr_write(rt2x00dev, 12, 0x75); |
| 6004 | rt2800_rfcsr_write(rt2x00dev, 13, 0x75); |
| 6005 | rt2800_rfcsr_write(rt2x00dev, 14, 0x90); |
| 6006 | rt2800_rfcsr_write(rt2x00dev, 15, 0x58); |
| 6007 | rt2800_rfcsr_write(rt2x00dev, 16, 0xb3); |
| 6008 | rt2800_rfcsr_write(rt2x00dev, 17, 0x92); |
| 6009 | rt2800_rfcsr_write(rt2x00dev, 18, 0x2c); |
| 6010 | rt2800_rfcsr_write(rt2x00dev, 19, 0x02); |
| 6011 | rt2800_rfcsr_write(rt2x00dev, 20, 0xba); |
| 6012 | rt2800_rfcsr_write(rt2x00dev, 21, 0xdb); |
| 6013 | rt2800_rfcsr_write(rt2x00dev, 22, 0x00); |
| 6014 | rt2800_rfcsr_write(rt2x00dev, 23, 0x31); |
| 6015 | rt2800_rfcsr_write(rt2x00dev, 24, 0x08); |
| 6016 | rt2800_rfcsr_write(rt2x00dev, 25, 0x01); |
| 6017 | rt2800_rfcsr_write(rt2x00dev, 26, 0x25); |
| 6018 | rt2800_rfcsr_write(rt2x00dev, 27, 0x23); |
| 6019 | rt2800_rfcsr_write(rt2x00dev, 28, 0x13); |
| 6020 | rt2800_rfcsr_write(rt2x00dev, 29, 0x83); |
| 6021 | rt2800_rfcsr_write(rt2x00dev, 30, 0x00); |
| 6022 | rt2800_rfcsr_write(rt2x00dev, 31, 0x00); |
| 6023 | } |
| 6024 | |
| 6025 | static void rt2800_init_rfcsr_30xx(struct rt2x00_dev *rt2x00dev) |
| 6026 | { |
Stanislaw Gruszka | c9a221b | 2013-04-17 14:08:13 +0200 | [diff] [blame] | 6027 | u8 rfcsr; |
| 6028 | u16 eeprom; |
| 6029 | u32 reg; |
| 6030 | |
Stanislaw Gruszka | ce94ede9 | 2013-04-17 14:08:11 +0200 | [diff] [blame] | 6031 | /* XXX vendor driver do this only for 3070 */ |
| 6032 | rt2800_rf_init_calibration(rt2x00dev, 30); |
| 6033 | |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6034 | rt2800_rfcsr_write(rt2x00dev, 4, 0x40); |
| 6035 | rt2800_rfcsr_write(rt2x00dev, 5, 0x03); |
| 6036 | rt2800_rfcsr_write(rt2x00dev, 6, 0x02); |
| 6037 | rt2800_rfcsr_write(rt2x00dev, 7, 0x60); |
| 6038 | rt2800_rfcsr_write(rt2x00dev, 9, 0x0f); |
| 6039 | rt2800_rfcsr_write(rt2x00dev, 10, 0x41); |
| 6040 | rt2800_rfcsr_write(rt2x00dev, 11, 0x21); |
| 6041 | rt2800_rfcsr_write(rt2x00dev, 12, 0x7b); |
| 6042 | rt2800_rfcsr_write(rt2x00dev, 14, 0x90); |
| 6043 | rt2800_rfcsr_write(rt2x00dev, 15, 0x58); |
| 6044 | rt2800_rfcsr_write(rt2x00dev, 16, 0xb3); |
| 6045 | rt2800_rfcsr_write(rt2x00dev, 17, 0x92); |
| 6046 | rt2800_rfcsr_write(rt2x00dev, 18, 0x2c); |
| 6047 | rt2800_rfcsr_write(rt2x00dev, 19, 0x02); |
| 6048 | rt2800_rfcsr_write(rt2x00dev, 20, 0xba); |
| 6049 | rt2800_rfcsr_write(rt2x00dev, 21, 0xdb); |
| 6050 | rt2800_rfcsr_write(rt2x00dev, 24, 0x16); |
Kevin Lo | 772eb43 | 2013-09-18 16:22:44 +0800 | [diff] [blame] | 6051 | rt2800_rfcsr_write(rt2x00dev, 25, 0x03); |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6052 | rt2800_rfcsr_write(rt2x00dev, 29, 0x1f); |
Stanislaw Gruszka | c9a221b | 2013-04-17 14:08:13 +0200 | [diff] [blame] | 6053 | |
| 6054 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) { |
| 6055 | rt2800_register_read(rt2x00dev, LDO_CFG0, ®); |
| 6056 | rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1); |
| 6057 | rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 3); |
| 6058 | rt2800_register_write(rt2x00dev, LDO_CFG0, reg); |
| 6059 | } else if (rt2x00_rt(rt2x00dev, RT3071) || |
| 6060 | rt2x00_rt(rt2x00dev, RT3090)) { |
| 6061 | rt2800_rfcsr_write(rt2x00dev, 31, 0x14); |
| 6062 | |
| 6063 | rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr); |
| 6064 | rt2x00_set_field8(&rfcsr, RFCSR6_R2, 1); |
| 6065 | rt2800_rfcsr_write(rt2x00dev, 6, rfcsr); |
| 6066 | |
| 6067 | rt2800_register_read(rt2x00dev, LDO_CFG0, ®); |
| 6068 | rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1); |
| 6069 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) || |
| 6070 | rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E)) { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6071 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, |
| 6072 | &eeprom); |
Stanislaw Gruszka | c9a221b | 2013-04-17 14:08:13 +0200 | [diff] [blame] | 6073 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_DAC_TEST)) |
| 6074 | rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 3); |
| 6075 | else |
| 6076 | rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 0); |
| 6077 | } |
| 6078 | rt2800_register_write(rt2x00dev, LDO_CFG0, reg); |
| 6079 | |
| 6080 | rt2800_register_read(rt2x00dev, GPIO_SWITCH, ®); |
| 6081 | rt2x00_set_field32(®, GPIO_SWITCH_5, 0); |
| 6082 | rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg); |
| 6083 | } |
Stanislaw Gruszka | c5b3c35 | 2013-04-17 14:08:16 +0200 | [diff] [blame] | 6084 | |
| 6085 | rt2800_rx_filter_calibration(rt2x00dev); |
Stanislaw Gruszka | 5de5a1f | 2013-04-17 14:08:17 +0200 | [diff] [blame] | 6086 | |
| 6087 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F) || |
| 6088 | rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) || |
| 6089 | rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E)) |
| 6090 | rt2800_rfcsr_write(rt2x00dev, 27, 0x03); |
Stanislaw Gruszka | d9517f2 | 2013-04-17 14:08:18 +0200 | [diff] [blame] | 6091 | |
| 6092 | rt2800_led_open_drain_enable(rt2x00dev); |
Stanislaw Gruszka | da8064c | 2013-04-17 14:08:19 +0200 | [diff] [blame] | 6093 | rt2800_normal_mode_setup_3xxx(rt2x00dev); |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6094 | } |
| 6095 | |
| 6096 | static void rt2800_init_rfcsr_3290(struct rt2x00_dev *rt2x00dev) |
| 6097 | { |
Stanislaw Gruszka | f9cdcbb | 2013-04-17 14:08:12 +0200 | [diff] [blame] | 6098 | u8 rfcsr; |
| 6099 | |
Stanislaw Gruszka | ce94ede9 | 2013-04-17 14:08:11 +0200 | [diff] [blame] | 6100 | rt2800_rf_init_calibration(rt2x00dev, 2); |
| 6101 | |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6102 | rt2800_rfcsr_write(rt2x00dev, 1, 0x0f); |
| 6103 | rt2800_rfcsr_write(rt2x00dev, 2, 0x80); |
| 6104 | rt2800_rfcsr_write(rt2x00dev, 3, 0x08); |
| 6105 | rt2800_rfcsr_write(rt2x00dev, 4, 0x00); |
| 6106 | rt2800_rfcsr_write(rt2x00dev, 6, 0xa0); |
| 6107 | rt2800_rfcsr_write(rt2x00dev, 8, 0xf3); |
| 6108 | rt2800_rfcsr_write(rt2x00dev, 9, 0x02); |
| 6109 | rt2800_rfcsr_write(rt2x00dev, 10, 0x53); |
| 6110 | rt2800_rfcsr_write(rt2x00dev, 11, 0x4a); |
| 6111 | rt2800_rfcsr_write(rt2x00dev, 12, 0x46); |
| 6112 | rt2800_rfcsr_write(rt2x00dev, 13, 0x9f); |
| 6113 | rt2800_rfcsr_write(rt2x00dev, 18, 0x02); |
| 6114 | rt2800_rfcsr_write(rt2x00dev, 22, 0x20); |
| 6115 | rt2800_rfcsr_write(rt2x00dev, 25, 0x83); |
| 6116 | rt2800_rfcsr_write(rt2x00dev, 26, 0x82); |
| 6117 | rt2800_rfcsr_write(rt2x00dev, 27, 0x09); |
| 6118 | rt2800_rfcsr_write(rt2x00dev, 29, 0x10); |
| 6119 | rt2800_rfcsr_write(rt2x00dev, 30, 0x10); |
| 6120 | rt2800_rfcsr_write(rt2x00dev, 31, 0x80); |
| 6121 | rt2800_rfcsr_write(rt2x00dev, 32, 0x80); |
| 6122 | rt2800_rfcsr_write(rt2x00dev, 33, 0x00); |
| 6123 | rt2800_rfcsr_write(rt2x00dev, 34, 0x05); |
| 6124 | rt2800_rfcsr_write(rt2x00dev, 35, 0x12); |
| 6125 | rt2800_rfcsr_write(rt2x00dev, 36, 0x00); |
| 6126 | rt2800_rfcsr_write(rt2x00dev, 38, 0x85); |
| 6127 | rt2800_rfcsr_write(rt2x00dev, 39, 0x1b); |
| 6128 | rt2800_rfcsr_write(rt2x00dev, 40, 0x0b); |
| 6129 | rt2800_rfcsr_write(rt2x00dev, 41, 0xbb); |
| 6130 | rt2800_rfcsr_write(rt2x00dev, 42, 0xd5); |
| 6131 | rt2800_rfcsr_write(rt2x00dev, 43, 0x7b); |
| 6132 | rt2800_rfcsr_write(rt2x00dev, 44, 0x0e); |
| 6133 | rt2800_rfcsr_write(rt2x00dev, 45, 0xa2); |
| 6134 | rt2800_rfcsr_write(rt2x00dev, 46, 0x73); |
| 6135 | rt2800_rfcsr_write(rt2x00dev, 47, 0x00); |
| 6136 | rt2800_rfcsr_write(rt2x00dev, 48, 0x10); |
| 6137 | rt2800_rfcsr_write(rt2x00dev, 49, 0x98); |
| 6138 | rt2800_rfcsr_write(rt2x00dev, 52, 0x38); |
| 6139 | rt2800_rfcsr_write(rt2x00dev, 53, 0x00); |
| 6140 | rt2800_rfcsr_write(rt2x00dev, 54, 0x78); |
| 6141 | rt2800_rfcsr_write(rt2x00dev, 55, 0x43); |
| 6142 | rt2800_rfcsr_write(rt2x00dev, 56, 0x02); |
| 6143 | rt2800_rfcsr_write(rt2x00dev, 57, 0x80); |
| 6144 | rt2800_rfcsr_write(rt2x00dev, 58, 0x7f); |
| 6145 | rt2800_rfcsr_write(rt2x00dev, 59, 0x09); |
| 6146 | rt2800_rfcsr_write(rt2x00dev, 60, 0x45); |
| 6147 | rt2800_rfcsr_write(rt2x00dev, 61, 0xc1); |
Stanislaw Gruszka | f9cdcbb | 2013-04-17 14:08:12 +0200 | [diff] [blame] | 6148 | |
| 6149 | rt2800_rfcsr_read(rt2x00dev, 29, &rfcsr); |
| 6150 | rt2x00_set_field8(&rfcsr, RFCSR29_RSSI_GAIN, 3); |
| 6151 | rt2800_rfcsr_write(rt2x00dev, 29, rfcsr); |
Stanislaw Gruszka | d9517f2 | 2013-04-17 14:08:18 +0200 | [diff] [blame] | 6152 | |
| 6153 | rt2800_led_open_drain_enable(rt2x00dev); |
Stanislaw Gruszka | da8064c | 2013-04-17 14:08:19 +0200 | [diff] [blame] | 6154 | rt2800_normal_mode_setup_3xxx(rt2x00dev); |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6155 | } |
| 6156 | |
| 6157 | static void rt2800_init_rfcsr_3352(struct rt2x00_dev *rt2x00dev) |
| 6158 | { |
Stanislaw Gruszka | ce94ede9 | 2013-04-17 14:08:11 +0200 | [diff] [blame] | 6159 | rt2800_rf_init_calibration(rt2x00dev, 30); |
| 6160 | |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6161 | rt2800_rfcsr_write(rt2x00dev, 0, 0xf0); |
| 6162 | rt2800_rfcsr_write(rt2x00dev, 1, 0x23); |
| 6163 | rt2800_rfcsr_write(rt2x00dev, 2, 0x50); |
| 6164 | rt2800_rfcsr_write(rt2x00dev, 3, 0x18); |
| 6165 | rt2800_rfcsr_write(rt2x00dev, 4, 0x00); |
| 6166 | rt2800_rfcsr_write(rt2x00dev, 5, 0x00); |
| 6167 | rt2800_rfcsr_write(rt2x00dev, 6, 0x33); |
| 6168 | rt2800_rfcsr_write(rt2x00dev, 7, 0x00); |
| 6169 | rt2800_rfcsr_write(rt2x00dev, 8, 0xf1); |
| 6170 | rt2800_rfcsr_write(rt2x00dev, 9, 0x02); |
| 6171 | rt2800_rfcsr_write(rt2x00dev, 10, 0xd2); |
| 6172 | rt2800_rfcsr_write(rt2x00dev, 11, 0x42); |
| 6173 | rt2800_rfcsr_write(rt2x00dev, 12, 0x1c); |
| 6174 | rt2800_rfcsr_write(rt2x00dev, 13, 0x00); |
| 6175 | rt2800_rfcsr_write(rt2x00dev, 14, 0x5a); |
| 6176 | rt2800_rfcsr_write(rt2x00dev, 15, 0x00); |
| 6177 | rt2800_rfcsr_write(rt2x00dev, 16, 0x01); |
| 6178 | rt2800_rfcsr_write(rt2x00dev, 18, 0x45); |
| 6179 | rt2800_rfcsr_write(rt2x00dev, 19, 0x02); |
| 6180 | rt2800_rfcsr_write(rt2x00dev, 20, 0x00); |
| 6181 | rt2800_rfcsr_write(rt2x00dev, 21, 0x00); |
| 6182 | rt2800_rfcsr_write(rt2x00dev, 22, 0x00); |
| 6183 | rt2800_rfcsr_write(rt2x00dev, 23, 0x00); |
| 6184 | rt2800_rfcsr_write(rt2x00dev, 24, 0x00); |
| 6185 | rt2800_rfcsr_write(rt2x00dev, 25, 0x80); |
| 6186 | rt2800_rfcsr_write(rt2x00dev, 26, 0x00); |
| 6187 | rt2800_rfcsr_write(rt2x00dev, 27, 0x03); |
| 6188 | rt2800_rfcsr_write(rt2x00dev, 28, 0x03); |
| 6189 | rt2800_rfcsr_write(rt2x00dev, 29, 0x00); |
| 6190 | rt2800_rfcsr_write(rt2x00dev, 30, 0x10); |
| 6191 | rt2800_rfcsr_write(rt2x00dev, 31, 0x80); |
| 6192 | rt2800_rfcsr_write(rt2x00dev, 32, 0x80); |
| 6193 | rt2800_rfcsr_write(rt2x00dev, 33, 0x00); |
| 6194 | rt2800_rfcsr_write(rt2x00dev, 34, 0x01); |
| 6195 | rt2800_rfcsr_write(rt2x00dev, 35, 0x03); |
| 6196 | rt2800_rfcsr_write(rt2x00dev, 36, 0xbd); |
| 6197 | rt2800_rfcsr_write(rt2x00dev, 37, 0x3c); |
| 6198 | rt2800_rfcsr_write(rt2x00dev, 38, 0x5f); |
| 6199 | rt2800_rfcsr_write(rt2x00dev, 39, 0xc5); |
| 6200 | rt2800_rfcsr_write(rt2x00dev, 40, 0x33); |
| 6201 | rt2800_rfcsr_write(rt2x00dev, 41, 0x5b); |
| 6202 | rt2800_rfcsr_write(rt2x00dev, 42, 0x5b); |
| 6203 | rt2800_rfcsr_write(rt2x00dev, 43, 0xdb); |
| 6204 | rt2800_rfcsr_write(rt2x00dev, 44, 0xdb); |
| 6205 | rt2800_rfcsr_write(rt2x00dev, 45, 0xdb); |
| 6206 | rt2800_rfcsr_write(rt2x00dev, 46, 0xdd); |
| 6207 | rt2800_rfcsr_write(rt2x00dev, 47, 0x0d); |
| 6208 | rt2800_rfcsr_write(rt2x00dev, 48, 0x14); |
| 6209 | rt2800_rfcsr_write(rt2x00dev, 49, 0x00); |
| 6210 | rt2800_rfcsr_write(rt2x00dev, 50, 0x2d); |
| 6211 | rt2800_rfcsr_write(rt2x00dev, 51, 0x7f); |
| 6212 | rt2800_rfcsr_write(rt2x00dev, 52, 0x00); |
| 6213 | rt2800_rfcsr_write(rt2x00dev, 53, 0x52); |
| 6214 | rt2800_rfcsr_write(rt2x00dev, 54, 0x1b); |
| 6215 | rt2800_rfcsr_write(rt2x00dev, 55, 0x7f); |
| 6216 | rt2800_rfcsr_write(rt2x00dev, 56, 0x00); |
| 6217 | rt2800_rfcsr_write(rt2x00dev, 57, 0x52); |
| 6218 | rt2800_rfcsr_write(rt2x00dev, 58, 0x1b); |
| 6219 | rt2800_rfcsr_write(rt2x00dev, 59, 0x00); |
| 6220 | rt2800_rfcsr_write(rt2x00dev, 60, 0x00); |
| 6221 | rt2800_rfcsr_write(rt2x00dev, 61, 0x00); |
| 6222 | rt2800_rfcsr_write(rt2x00dev, 62, 0x00); |
| 6223 | rt2800_rfcsr_write(rt2x00dev, 63, 0x00); |
Stanislaw Gruszka | c5b3c35 | 2013-04-17 14:08:16 +0200 | [diff] [blame] | 6224 | |
| 6225 | rt2800_rx_filter_calibration(rt2x00dev); |
Stanislaw Gruszka | d9517f2 | 2013-04-17 14:08:18 +0200 | [diff] [blame] | 6226 | rt2800_led_open_drain_enable(rt2x00dev); |
Stanislaw Gruszka | da8064c | 2013-04-17 14:08:19 +0200 | [diff] [blame] | 6227 | rt2800_normal_mode_setup_3xxx(rt2x00dev); |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6228 | } |
| 6229 | |
| 6230 | static void rt2800_init_rfcsr_3390(struct rt2x00_dev *rt2x00dev) |
| 6231 | { |
Stanislaw Gruszka | 2971e66 | 2013-04-17 14:08:14 +0200 | [diff] [blame] | 6232 | u32 reg; |
| 6233 | |
Stanislaw Gruszka | ce94ede9 | 2013-04-17 14:08:11 +0200 | [diff] [blame] | 6234 | rt2800_rf_init_calibration(rt2x00dev, 30); |
| 6235 | |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6236 | rt2800_rfcsr_write(rt2x00dev, 0, 0xa0); |
| 6237 | rt2800_rfcsr_write(rt2x00dev, 1, 0xe1); |
| 6238 | rt2800_rfcsr_write(rt2x00dev, 2, 0xf1); |
| 6239 | rt2800_rfcsr_write(rt2x00dev, 3, 0x62); |
| 6240 | rt2800_rfcsr_write(rt2x00dev, 4, 0x40); |
| 6241 | rt2800_rfcsr_write(rt2x00dev, 5, 0x8b); |
| 6242 | rt2800_rfcsr_write(rt2x00dev, 6, 0x42); |
| 6243 | rt2800_rfcsr_write(rt2x00dev, 7, 0x34); |
| 6244 | rt2800_rfcsr_write(rt2x00dev, 8, 0x00); |
| 6245 | rt2800_rfcsr_write(rt2x00dev, 9, 0xc0); |
| 6246 | rt2800_rfcsr_write(rt2x00dev, 10, 0x61); |
| 6247 | rt2800_rfcsr_write(rt2x00dev, 11, 0x21); |
| 6248 | rt2800_rfcsr_write(rt2x00dev, 12, 0x3b); |
| 6249 | rt2800_rfcsr_write(rt2x00dev, 13, 0xe0); |
| 6250 | rt2800_rfcsr_write(rt2x00dev, 14, 0x90); |
| 6251 | rt2800_rfcsr_write(rt2x00dev, 15, 0x53); |
| 6252 | rt2800_rfcsr_write(rt2x00dev, 16, 0xe0); |
| 6253 | rt2800_rfcsr_write(rt2x00dev, 17, 0x94); |
| 6254 | rt2800_rfcsr_write(rt2x00dev, 18, 0x5c); |
| 6255 | rt2800_rfcsr_write(rt2x00dev, 19, 0x4a); |
| 6256 | rt2800_rfcsr_write(rt2x00dev, 20, 0xb2); |
| 6257 | rt2800_rfcsr_write(rt2x00dev, 21, 0xf6); |
| 6258 | rt2800_rfcsr_write(rt2x00dev, 22, 0x00); |
| 6259 | rt2800_rfcsr_write(rt2x00dev, 23, 0x14); |
| 6260 | rt2800_rfcsr_write(rt2x00dev, 24, 0x08); |
| 6261 | rt2800_rfcsr_write(rt2x00dev, 25, 0x3d); |
| 6262 | rt2800_rfcsr_write(rt2x00dev, 26, 0x85); |
| 6263 | rt2800_rfcsr_write(rt2x00dev, 27, 0x00); |
| 6264 | rt2800_rfcsr_write(rt2x00dev, 28, 0x41); |
| 6265 | rt2800_rfcsr_write(rt2x00dev, 29, 0x8f); |
| 6266 | rt2800_rfcsr_write(rt2x00dev, 30, 0x20); |
| 6267 | rt2800_rfcsr_write(rt2x00dev, 31, 0x0f); |
Stanislaw Gruszka | 2971e66 | 2013-04-17 14:08:14 +0200 | [diff] [blame] | 6268 | |
| 6269 | rt2800_register_read(rt2x00dev, GPIO_SWITCH, ®); |
| 6270 | rt2x00_set_field32(®, GPIO_SWITCH_5, 0); |
| 6271 | rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg); |
Stanislaw Gruszka | c5b3c35 | 2013-04-17 14:08:16 +0200 | [diff] [blame] | 6272 | |
| 6273 | rt2800_rx_filter_calibration(rt2x00dev); |
Stanislaw Gruszka | 5de5a1f | 2013-04-17 14:08:17 +0200 | [diff] [blame] | 6274 | |
| 6275 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) |
| 6276 | rt2800_rfcsr_write(rt2x00dev, 27, 0x03); |
Stanislaw Gruszka | d9517f2 | 2013-04-17 14:08:18 +0200 | [diff] [blame] | 6277 | |
| 6278 | rt2800_led_open_drain_enable(rt2x00dev); |
Stanislaw Gruszka | da8064c | 2013-04-17 14:08:19 +0200 | [diff] [blame] | 6279 | rt2800_normal_mode_setup_3xxx(rt2x00dev); |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6280 | } |
| 6281 | |
| 6282 | static void rt2800_init_rfcsr_3572(struct rt2x00_dev *rt2x00dev) |
| 6283 | { |
Stanislaw Gruszka | 87d91db | 2013-04-17 14:08:15 +0200 | [diff] [blame] | 6284 | u8 rfcsr; |
| 6285 | u32 reg; |
| 6286 | |
Stanislaw Gruszka | ce94ede9 | 2013-04-17 14:08:11 +0200 | [diff] [blame] | 6287 | rt2800_rf_init_calibration(rt2x00dev, 30); |
| 6288 | |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6289 | rt2800_rfcsr_write(rt2x00dev, 0, 0x70); |
| 6290 | rt2800_rfcsr_write(rt2x00dev, 1, 0x81); |
| 6291 | rt2800_rfcsr_write(rt2x00dev, 2, 0xf1); |
| 6292 | rt2800_rfcsr_write(rt2x00dev, 3, 0x02); |
| 6293 | rt2800_rfcsr_write(rt2x00dev, 4, 0x4c); |
| 6294 | rt2800_rfcsr_write(rt2x00dev, 5, 0x05); |
| 6295 | rt2800_rfcsr_write(rt2x00dev, 6, 0x4a); |
| 6296 | rt2800_rfcsr_write(rt2x00dev, 7, 0xd8); |
| 6297 | rt2800_rfcsr_write(rt2x00dev, 9, 0xc3); |
| 6298 | rt2800_rfcsr_write(rt2x00dev, 10, 0xf1); |
| 6299 | rt2800_rfcsr_write(rt2x00dev, 11, 0xb9); |
| 6300 | rt2800_rfcsr_write(rt2x00dev, 12, 0x70); |
| 6301 | rt2800_rfcsr_write(rt2x00dev, 13, 0x65); |
| 6302 | rt2800_rfcsr_write(rt2x00dev, 14, 0xa0); |
| 6303 | rt2800_rfcsr_write(rt2x00dev, 15, 0x53); |
| 6304 | rt2800_rfcsr_write(rt2x00dev, 16, 0x4c); |
| 6305 | rt2800_rfcsr_write(rt2x00dev, 17, 0x23); |
| 6306 | rt2800_rfcsr_write(rt2x00dev, 18, 0xac); |
| 6307 | rt2800_rfcsr_write(rt2x00dev, 19, 0x93); |
| 6308 | rt2800_rfcsr_write(rt2x00dev, 20, 0xb3); |
| 6309 | rt2800_rfcsr_write(rt2x00dev, 21, 0xd0); |
| 6310 | rt2800_rfcsr_write(rt2x00dev, 22, 0x00); |
| 6311 | rt2800_rfcsr_write(rt2x00dev, 23, 0x3c); |
| 6312 | rt2800_rfcsr_write(rt2x00dev, 24, 0x16); |
| 6313 | rt2800_rfcsr_write(rt2x00dev, 25, 0x15); |
| 6314 | rt2800_rfcsr_write(rt2x00dev, 26, 0x85); |
| 6315 | rt2800_rfcsr_write(rt2x00dev, 27, 0x00); |
| 6316 | rt2800_rfcsr_write(rt2x00dev, 28, 0x00); |
| 6317 | rt2800_rfcsr_write(rt2x00dev, 29, 0x9b); |
| 6318 | rt2800_rfcsr_write(rt2x00dev, 30, 0x09); |
| 6319 | rt2800_rfcsr_write(rt2x00dev, 31, 0x10); |
Stanislaw Gruszka | 87d91db | 2013-04-17 14:08:15 +0200 | [diff] [blame] | 6320 | |
| 6321 | rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr); |
| 6322 | rt2x00_set_field8(&rfcsr, RFCSR6_R2, 1); |
| 6323 | rt2800_rfcsr_write(rt2x00dev, 6, rfcsr); |
| 6324 | |
| 6325 | rt2800_register_read(rt2x00dev, LDO_CFG0, ®); |
| 6326 | rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 3); |
| 6327 | rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1); |
| 6328 | rt2800_register_write(rt2x00dev, LDO_CFG0, reg); |
| 6329 | msleep(1); |
| 6330 | rt2800_register_read(rt2x00dev, LDO_CFG0, ®); |
| 6331 | rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 0); |
| 6332 | rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1); |
| 6333 | rt2800_register_write(rt2x00dev, LDO_CFG0, reg); |
Stanislaw Gruszka | c5b3c35 | 2013-04-17 14:08:16 +0200 | [diff] [blame] | 6334 | |
| 6335 | rt2800_rx_filter_calibration(rt2x00dev); |
Stanislaw Gruszka | d9517f2 | 2013-04-17 14:08:18 +0200 | [diff] [blame] | 6336 | rt2800_led_open_drain_enable(rt2x00dev); |
Stanislaw Gruszka | da8064c | 2013-04-17 14:08:19 +0200 | [diff] [blame] | 6337 | rt2800_normal_mode_setup_3xxx(rt2x00dev); |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6338 | } |
| 6339 | |
Gabor Juhos | d63f7e8 | 2013-07-08 16:08:19 +0200 | [diff] [blame] | 6340 | static void rt3593_post_bbp_init(struct rt2x00_dev *rt2x00dev) |
| 6341 | { |
| 6342 | u8 bbp; |
| 6343 | bool txbf_enabled = false; /* FIXME */ |
| 6344 | |
| 6345 | rt2800_bbp_read(rt2x00dev, 105, &bbp); |
| 6346 | if (rt2x00dev->default_ant.rx_chain_num == 1) |
| 6347 | rt2x00_set_field8(&bbp, BBP105_MLD, 0); |
| 6348 | else |
| 6349 | rt2x00_set_field8(&bbp, BBP105_MLD, 1); |
| 6350 | rt2800_bbp_write(rt2x00dev, 105, bbp); |
| 6351 | |
| 6352 | rt2800_bbp4_mac_if_ctrl(rt2x00dev); |
| 6353 | |
| 6354 | rt2800_bbp_write(rt2x00dev, 92, 0x02); |
| 6355 | rt2800_bbp_write(rt2x00dev, 82, 0x82); |
| 6356 | rt2800_bbp_write(rt2x00dev, 106, 0x05); |
| 6357 | rt2800_bbp_write(rt2x00dev, 104, 0x92); |
| 6358 | rt2800_bbp_write(rt2x00dev, 88, 0x90); |
| 6359 | rt2800_bbp_write(rt2x00dev, 148, 0xc8); |
| 6360 | rt2800_bbp_write(rt2x00dev, 47, 0x48); |
| 6361 | rt2800_bbp_write(rt2x00dev, 120, 0x50); |
| 6362 | |
| 6363 | if (txbf_enabled) |
| 6364 | rt2800_bbp_write(rt2x00dev, 163, 0xbd); |
| 6365 | else |
| 6366 | rt2800_bbp_write(rt2x00dev, 163, 0x9d); |
| 6367 | |
| 6368 | /* SNR mapping */ |
| 6369 | rt2800_bbp_write(rt2x00dev, 142, 6); |
| 6370 | rt2800_bbp_write(rt2x00dev, 143, 160); |
| 6371 | rt2800_bbp_write(rt2x00dev, 142, 7); |
| 6372 | rt2800_bbp_write(rt2x00dev, 143, 161); |
| 6373 | rt2800_bbp_write(rt2x00dev, 142, 8); |
| 6374 | rt2800_bbp_write(rt2x00dev, 143, 162); |
| 6375 | |
| 6376 | /* ADC/DAC control */ |
| 6377 | rt2800_bbp_write(rt2x00dev, 31, 0x08); |
| 6378 | |
| 6379 | /* RX AGC energy lower bound in log2 */ |
| 6380 | rt2800_bbp_write(rt2x00dev, 68, 0x0b); |
| 6381 | |
| 6382 | /* FIXME: BBP 105 owerwrite? */ |
| 6383 | rt2800_bbp_write(rt2x00dev, 105, 0x04); |
Gabor Juhos | f42b046 | 2013-07-08 16:08:30 +0200 | [diff] [blame] | 6384 | |
Gabor Juhos | d63f7e8 | 2013-07-08 16:08:19 +0200 | [diff] [blame] | 6385 | } |
| 6386 | |
Gabor Juhos | ab7078a | 2013-07-08 16:08:18 +0200 | [diff] [blame] | 6387 | static void rt2800_init_rfcsr_3593(struct rt2x00_dev *rt2x00dev) |
| 6388 | { |
| 6389 | struct rt2800_drv_data *drv_data = rt2x00dev->drv_data; |
| 6390 | u32 reg; |
| 6391 | u8 rfcsr; |
| 6392 | |
| 6393 | /* Disable GPIO #4 and #7 function for LAN PE control */ |
| 6394 | rt2800_register_read(rt2x00dev, GPIO_SWITCH, ®); |
| 6395 | rt2x00_set_field32(®, GPIO_SWITCH_4, 0); |
| 6396 | rt2x00_set_field32(®, GPIO_SWITCH_7, 0); |
| 6397 | rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg); |
| 6398 | |
| 6399 | /* Initialize default register values */ |
| 6400 | rt2800_rfcsr_write(rt2x00dev, 1, 0x03); |
| 6401 | rt2800_rfcsr_write(rt2x00dev, 3, 0x80); |
| 6402 | rt2800_rfcsr_write(rt2x00dev, 5, 0x00); |
| 6403 | rt2800_rfcsr_write(rt2x00dev, 6, 0x40); |
| 6404 | rt2800_rfcsr_write(rt2x00dev, 8, 0xf1); |
| 6405 | rt2800_rfcsr_write(rt2x00dev, 9, 0x02); |
| 6406 | rt2800_rfcsr_write(rt2x00dev, 10, 0xd3); |
| 6407 | rt2800_rfcsr_write(rt2x00dev, 11, 0x40); |
| 6408 | rt2800_rfcsr_write(rt2x00dev, 12, 0x4e); |
| 6409 | rt2800_rfcsr_write(rt2x00dev, 13, 0x12); |
| 6410 | rt2800_rfcsr_write(rt2x00dev, 18, 0x40); |
| 6411 | rt2800_rfcsr_write(rt2x00dev, 22, 0x20); |
| 6412 | rt2800_rfcsr_write(rt2x00dev, 30, 0x10); |
| 6413 | rt2800_rfcsr_write(rt2x00dev, 31, 0x80); |
| 6414 | rt2800_rfcsr_write(rt2x00dev, 32, 0x78); |
| 6415 | rt2800_rfcsr_write(rt2x00dev, 33, 0x3b); |
| 6416 | rt2800_rfcsr_write(rt2x00dev, 34, 0x3c); |
| 6417 | rt2800_rfcsr_write(rt2x00dev, 35, 0xe0); |
| 6418 | rt2800_rfcsr_write(rt2x00dev, 38, 0x86); |
| 6419 | rt2800_rfcsr_write(rt2x00dev, 39, 0x23); |
| 6420 | rt2800_rfcsr_write(rt2x00dev, 44, 0xd3); |
| 6421 | rt2800_rfcsr_write(rt2x00dev, 45, 0xbb); |
| 6422 | rt2800_rfcsr_write(rt2x00dev, 46, 0x60); |
| 6423 | rt2800_rfcsr_write(rt2x00dev, 49, 0x8e); |
| 6424 | rt2800_rfcsr_write(rt2x00dev, 50, 0x86); |
| 6425 | rt2800_rfcsr_write(rt2x00dev, 51, 0x75); |
| 6426 | rt2800_rfcsr_write(rt2x00dev, 52, 0x45); |
| 6427 | rt2800_rfcsr_write(rt2x00dev, 53, 0x18); |
| 6428 | rt2800_rfcsr_write(rt2x00dev, 54, 0x18); |
| 6429 | rt2800_rfcsr_write(rt2x00dev, 55, 0x18); |
| 6430 | rt2800_rfcsr_write(rt2x00dev, 56, 0xdb); |
| 6431 | rt2800_rfcsr_write(rt2x00dev, 57, 0x6e); |
| 6432 | |
| 6433 | /* Initiate calibration */ |
| 6434 | /* TODO: use rt2800_rf_init_calibration ? */ |
| 6435 | rt2800_rfcsr_read(rt2x00dev, 2, &rfcsr); |
| 6436 | rt2x00_set_field8(&rfcsr, RFCSR2_RESCAL_EN, 1); |
| 6437 | rt2800_rfcsr_write(rt2x00dev, 2, rfcsr); |
| 6438 | |
| 6439 | rt2800_adjust_freq_offset(rt2x00dev); |
| 6440 | |
| 6441 | rt2800_rfcsr_read(rt2x00dev, 18, &rfcsr); |
| 6442 | rt2x00_set_field8(&rfcsr, RFCSR18_XO_TUNE_BYPASS, 1); |
| 6443 | rt2800_rfcsr_write(rt2x00dev, 18, rfcsr); |
| 6444 | |
| 6445 | rt2800_register_read(rt2x00dev, LDO_CFG0, ®); |
| 6446 | rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 3); |
| 6447 | rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1); |
| 6448 | rt2800_register_write(rt2x00dev, LDO_CFG0, reg); |
| 6449 | usleep_range(1000, 1500); |
| 6450 | rt2800_register_read(rt2x00dev, LDO_CFG0, ®); |
| 6451 | rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 0); |
| 6452 | rt2800_register_write(rt2x00dev, LDO_CFG0, reg); |
| 6453 | |
| 6454 | /* Set initial values for RX filter calibration */ |
| 6455 | drv_data->calibration_bw20 = 0x1f; |
| 6456 | drv_data->calibration_bw40 = 0x2f; |
| 6457 | |
| 6458 | /* Save BBP 25 & 26 values for later use in channel switching */ |
| 6459 | rt2800_bbp_read(rt2x00dev, 25, &drv_data->bbp25); |
| 6460 | rt2800_bbp_read(rt2x00dev, 26, &drv_data->bbp26); |
| 6461 | |
| 6462 | rt2800_led_open_drain_enable(rt2x00dev); |
| 6463 | rt2800_normal_mode_setup_3593(rt2x00dev); |
| 6464 | |
Gabor Juhos | d63f7e8 | 2013-07-08 16:08:19 +0200 | [diff] [blame] | 6465 | rt3593_post_bbp_init(rt2x00dev); |
Gabor Juhos | ab7078a | 2013-07-08 16:08:18 +0200 | [diff] [blame] | 6466 | |
| 6467 | /* TODO: enable stream mode support */ |
| 6468 | } |
| 6469 | |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6470 | static void rt2800_init_rfcsr_5390(struct rt2x00_dev *rt2x00dev) |
| 6471 | { |
Stanislaw Gruszka | ce94ede9 | 2013-04-17 14:08:11 +0200 | [diff] [blame] | 6472 | rt2800_rf_init_calibration(rt2x00dev, 2); |
| 6473 | |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6474 | rt2800_rfcsr_write(rt2x00dev, 1, 0x0f); |
| 6475 | rt2800_rfcsr_write(rt2x00dev, 2, 0x80); |
| 6476 | rt2800_rfcsr_write(rt2x00dev, 3, 0x88); |
| 6477 | rt2800_rfcsr_write(rt2x00dev, 5, 0x10); |
| 6478 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) |
| 6479 | rt2800_rfcsr_write(rt2x00dev, 6, 0xe0); |
| 6480 | else |
| 6481 | rt2800_rfcsr_write(rt2x00dev, 6, 0xa0); |
| 6482 | rt2800_rfcsr_write(rt2x00dev, 7, 0x00); |
| 6483 | rt2800_rfcsr_write(rt2x00dev, 10, 0x53); |
| 6484 | rt2800_rfcsr_write(rt2x00dev, 11, 0x4a); |
Kevin Lo | c8520bc | 2013-10-24 13:24:08 +0800 | [diff] [blame] | 6485 | rt2800_rfcsr_write(rt2x00dev, 12, 0x46); |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6486 | rt2800_rfcsr_write(rt2x00dev, 13, 0x9f); |
| 6487 | rt2800_rfcsr_write(rt2x00dev, 14, 0x00); |
| 6488 | rt2800_rfcsr_write(rt2x00dev, 15, 0x00); |
| 6489 | rt2800_rfcsr_write(rt2x00dev, 16, 0x00); |
| 6490 | rt2800_rfcsr_write(rt2x00dev, 18, 0x03); |
| 6491 | rt2800_rfcsr_write(rt2x00dev, 19, 0x00); |
| 6492 | |
| 6493 | rt2800_rfcsr_write(rt2x00dev, 20, 0x00); |
| 6494 | rt2800_rfcsr_write(rt2x00dev, 21, 0x00); |
| 6495 | rt2800_rfcsr_write(rt2x00dev, 22, 0x20); |
| 6496 | rt2800_rfcsr_write(rt2x00dev, 23, 0x00); |
| 6497 | rt2800_rfcsr_write(rt2x00dev, 24, 0x00); |
Kevin Lo | c8520bc | 2013-10-24 13:24:08 +0800 | [diff] [blame] | 6498 | if (rt2x00_is_usb(rt2x00dev) && |
| 6499 | rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6500 | rt2800_rfcsr_write(rt2x00dev, 25, 0x80); |
| 6501 | else |
| 6502 | rt2800_rfcsr_write(rt2x00dev, 25, 0xc0); |
| 6503 | rt2800_rfcsr_write(rt2x00dev, 26, 0x00); |
| 6504 | rt2800_rfcsr_write(rt2x00dev, 27, 0x09); |
| 6505 | rt2800_rfcsr_write(rt2x00dev, 28, 0x00); |
| 6506 | rt2800_rfcsr_write(rt2x00dev, 29, 0x10); |
| 6507 | |
Kevin Lo | 7122e66 | 2013-10-12 23:25:23 +0800 | [diff] [blame] | 6508 | rt2800_rfcsr_write(rt2x00dev, 30, 0x10); |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6509 | rt2800_rfcsr_write(rt2x00dev, 31, 0x80); |
| 6510 | rt2800_rfcsr_write(rt2x00dev, 32, 0x80); |
| 6511 | rt2800_rfcsr_write(rt2x00dev, 33, 0x00); |
| 6512 | rt2800_rfcsr_write(rt2x00dev, 34, 0x07); |
| 6513 | rt2800_rfcsr_write(rt2x00dev, 35, 0x12); |
| 6514 | rt2800_rfcsr_write(rt2x00dev, 36, 0x00); |
| 6515 | rt2800_rfcsr_write(rt2x00dev, 37, 0x08); |
| 6516 | rt2800_rfcsr_write(rt2x00dev, 38, 0x85); |
| 6517 | rt2800_rfcsr_write(rt2x00dev, 39, 0x1b); |
| 6518 | |
Kevin Lo | c8520bc | 2013-10-24 13:24:08 +0800 | [diff] [blame] | 6519 | rt2800_rfcsr_write(rt2x00dev, 40, 0x0b); |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6520 | rt2800_rfcsr_write(rt2x00dev, 41, 0xbb); |
| 6521 | rt2800_rfcsr_write(rt2x00dev, 42, 0xd2); |
| 6522 | rt2800_rfcsr_write(rt2x00dev, 43, 0x9a); |
| 6523 | rt2800_rfcsr_write(rt2x00dev, 44, 0x0e); |
| 6524 | rt2800_rfcsr_write(rt2x00dev, 45, 0xa2); |
| 6525 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) |
| 6526 | rt2800_rfcsr_write(rt2x00dev, 46, 0x73); |
| 6527 | else |
| 6528 | rt2800_rfcsr_write(rt2x00dev, 46, 0x7b); |
| 6529 | rt2800_rfcsr_write(rt2x00dev, 47, 0x00); |
| 6530 | rt2800_rfcsr_write(rt2x00dev, 48, 0x10); |
| 6531 | rt2800_rfcsr_write(rt2x00dev, 49, 0x94); |
| 6532 | |
| 6533 | rt2800_rfcsr_write(rt2x00dev, 52, 0x38); |
| 6534 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) |
| 6535 | rt2800_rfcsr_write(rt2x00dev, 53, 0x00); |
| 6536 | else |
| 6537 | rt2800_rfcsr_write(rt2x00dev, 53, 0x84); |
| 6538 | rt2800_rfcsr_write(rt2x00dev, 54, 0x78); |
| 6539 | rt2800_rfcsr_write(rt2x00dev, 55, 0x44); |
Kevin Lo | c8520bc | 2013-10-24 13:24:08 +0800 | [diff] [blame] | 6540 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) |
| 6541 | rt2800_rfcsr_write(rt2x00dev, 56, 0x42); |
| 6542 | else |
| 6543 | rt2800_rfcsr_write(rt2x00dev, 56, 0x22); |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6544 | rt2800_rfcsr_write(rt2x00dev, 57, 0x80); |
| 6545 | rt2800_rfcsr_write(rt2x00dev, 58, 0x7f); |
Kevin Lo | 7122e66 | 2013-10-12 23:25:23 +0800 | [diff] [blame] | 6546 | rt2800_rfcsr_write(rt2x00dev, 59, 0x8f); |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6547 | |
| 6548 | rt2800_rfcsr_write(rt2x00dev, 60, 0x45); |
Kevin Lo | c8520bc | 2013-10-24 13:24:08 +0800 | [diff] [blame] | 6549 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) { |
| 6550 | if (rt2x00_is_usb(rt2x00dev)) |
| 6551 | rt2800_rfcsr_write(rt2x00dev, 61, 0xd1); |
| 6552 | else |
| 6553 | rt2800_rfcsr_write(rt2x00dev, 61, 0xd5); |
| 6554 | } else { |
| 6555 | if (rt2x00_is_usb(rt2x00dev)) |
| 6556 | rt2800_rfcsr_write(rt2x00dev, 61, 0xdd); |
| 6557 | else |
| 6558 | rt2800_rfcsr_write(rt2x00dev, 61, 0xb5); |
| 6559 | } |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6560 | rt2800_rfcsr_write(rt2x00dev, 62, 0x00); |
| 6561 | rt2800_rfcsr_write(rt2x00dev, 63, 0x00); |
Stanislaw Gruszka | f7df8fe | 2013-04-17 14:08:10 +0200 | [diff] [blame] | 6562 | |
| 6563 | rt2800_normal_mode_setup_5xxx(rt2x00dev); |
Stanislaw Gruszka | d9517f2 | 2013-04-17 14:08:18 +0200 | [diff] [blame] | 6564 | |
| 6565 | rt2800_led_open_drain_enable(rt2x00dev); |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6566 | } |
| 6567 | |
| 6568 | static void rt2800_init_rfcsr_5392(struct rt2x00_dev *rt2x00dev) |
| 6569 | { |
Stanislaw Gruszka | ce94ede9 | 2013-04-17 14:08:11 +0200 | [diff] [blame] | 6570 | rt2800_rf_init_calibration(rt2x00dev, 2); |
| 6571 | |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6572 | rt2800_rfcsr_write(rt2x00dev, 1, 0x17); |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6573 | rt2800_rfcsr_write(rt2x00dev, 3, 0x88); |
| 6574 | rt2800_rfcsr_write(rt2x00dev, 5, 0x10); |
| 6575 | rt2800_rfcsr_write(rt2x00dev, 6, 0xe0); |
| 6576 | rt2800_rfcsr_write(rt2x00dev, 7, 0x00); |
| 6577 | rt2800_rfcsr_write(rt2x00dev, 10, 0x53); |
| 6578 | rt2800_rfcsr_write(rt2x00dev, 11, 0x4a); |
| 6579 | rt2800_rfcsr_write(rt2x00dev, 12, 0x46); |
| 6580 | rt2800_rfcsr_write(rt2x00dev, 13, 0x9f); |
| 6581 | rt2800_rfcsr_write(rt2x00dev, 14, 0x00); |
| 6582 | rt2800_rfcsr_write(rt2x00dev, 15, 0x00); |
| 6583 | rt2800_rfcsr_write(rt2x00dev, 16, 0x00); |
| 6584 | rt2800_rfcsr_write(rt2x00dev, 18, 0x03); |
| 6585 | rt2800_rfcsr_write(rt2x00dev, 19, 0x4d); |
| 6586 | rt2800_rfcsr_write(rt2x00dev, 20, 0x00); |
| 6587 | rt2800_rfcsr_write(rt2x00dev, 21, 0x8d); |
| 6588 | rt2800_rfcsr_write(rt2x00dev, 22, 0x20); |
| 6589 | rt2800_rfcsr_write(rt2x00dev, 23, 0x0b); |
| 6590 | rt2800_rfcsr_write(rt2x00dev, 24, 0x44); |
| 6591 | rt2800_rfcsr_write(rt2x00dev, 25, 0x80); |
| 6592 | rt2800_rfcsr_write(rt2x00dev, 26, 0x82); |
| 6593 | rt2800_rfcsr_write(rt2x00dev, 27, 0x09); |
| 6594 | rt2800_rfcsr_write(rt2x00dev, 28, 0x00); |
| 6595 | rt2800_rfcsr_write(rt2x00dev, 29, 0x10); |
| 6596 | rt2800_rfcsr_write(rt2x00dev, 30, 0x10); |
| 6597 | rt2800_rfcsr_write(rt2x00dev, 31, 0x80); |
| 6598 | rt2800_rfcsr_write(rt2x00dev, 32, 0x20); |
| 6599 | rt2800_rfcsr_write(rt2x00dev, 33, 0xC0); |
| 6600 | rt2800_rfcsr_write(rt2x00dev, 34, 0x07); |
| 6601 | rt2800_rfcsr_write(rt2x00dev, 35, 0x12); |
| 6602 | rt2800_rfcsr_write(rt2x00dev, 36, 0x00); |
| 6603 | rt2800_rfcsr_write(rt2x00dev, 37, 0x08); |
| 6604 | rt2800_rfcsr_write(rt2x00dev, 38, 0x89); |
| 6605 | rt2800_rfcsr_write(rt2x00dev, 39, 0x1b); |
| 6606 | rt2800_rfcsr_write(rt2x00dev, 40, 0x0f); |
| 6607 | rt2800_rfcsr_write(rt2x00dev, 41, 0xbb); |
| 6608 | rt2800_rfcsr_write(rt2x00dev, 42, 0xd5); |
| 6609 | rt2800_rfcsr_write(rt2x00dev, 43, 0x9b); |
| 6610 | rt2800_rfcsr_write(rt2x00dev, 44, 0x0e); |
| 6611 | rt2800_rfcsr_write(rt2x00dev, 45, 0xa2); |
| 6612 | rt2800_rfcsr_write(rt2x00dev, 46, 0x73); |
| 6613 | rt2800_rfcsr_write(rt2x00dev, 47, 0x0c); |
| 6614 | rt2800_rfcsr_write(rt2x00dev, 48, 0x10); |
| 6615 | rt2800_rfcsr_write(rt2x00dev, 49, 0x94); |
| 6616 | rt2800_rfcsr_write(rt2x00dev, 50, 0x94); |
| 6617 | rt2800_rfcsr_write(rt2x00dev, 51, 0x3a); |
| 6618 | rt2800_rfcsr_write(rt2x00dev, 52, 0x48); |
| 6619 | rt2800_rfcsr_write(rt2x00dev, 53, 0x44); |
| 6620 | rt2800_rfcsr_write(rt2x00dev, 54, 0x38); |
| 6621 | rt2800_rfcsr_write(rt2x00dev, 55, 0x43); |
| 6622 | rt2800_rfcsr_write(rt2x00dev, 56, 0xa1); |
| 6623 | rt2800_rfcsr_write(rt2x00dev, 57, 0x00); |
| 6624 | rt2800_rfcsr_write(rt2x00dev, 58, 0x39); |
| 6625 | rt2800_rfcsr_write(rt2x00dev, 59, 0x07); |
| 6626 | rt2800_rfcsr_write(rt2x00dev, 60, 0x45); |
| 6627 | rt2800_rfcsr_write(rt2x00dev, 61, 0x91); |
| 6628 | rt2800_rfcsr_write(rt2x00dev, 62, 0x39); |
| 6629 | rt2800_rfcsr_write(rt2x00dev, 63, 0x07); |
Stanislaw Gruszka | f7df8fe | 2013-04-17 14:08:10 +0200 | [diff] [blame] | 6630 | |
| 6631 | rt2800_normal_mode_setup_5xxx(rt2x00dev); |
Stanislaw Gruszka | d9517f2 | 2013-04-17 14:08:18 +0200 | [diff] [blame] | 6632 | |
| 6633 | rt2800_led_open_drain_enable(rt2x00dev); |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6634 | } |
| 6635 | |
Stanislaw Gruszka | 0c9e5fb | 2013-03-16 19:19:36 +0100 | [diff] [blame] | 6636 | static void rt2800_init_rfcsr_5592(struct rt2x00_dev *rt2x00dev) |
| 6637 | { |
Stanislaw Gruszka | ce94ede9 | 2013-04-17 14:08:11 +0200 | [diff] [blame] | 6638 | rt2800_rf_init_calibration(rt2x00dev, 30); |
| 6639 | |
Stanislaw Gruszka | 0c9e5fb | 2013-03-16 19:19:36 +0100 | [diff] [blame] | 6640 | rt2800_rfcsr_write(rt2x00dev, 1, 0x3F); |
| 6641 | rt2800_rfcsr_write(rt2x00dev, 3, 0x08); |
Stanislaw Gruszka | 0c9e5fb | 2013-03-16 19:19:36 +0100 | [diff] [blame] | 6642 | rt2800_rfcsr_write(rt2x00dev, 5, 0x10); |
| 6643 | rt2800_rfcsr_write(rt2x00dev, 6, 0xE4); |
| 6644 | rt2800_rfcsr_write(rt2x00dev, 7, 0x00); |
| 6645 | rt2800_rfcsr_write(rt2x00dev, 14, 0x00); |
| 6646 | rt2800_rfcsr_write(rt2x00dev, 15, 0x00); |
| 6647 | rt2800_rfcsr_write(rt2x00dev, 16, 0x00); |
| 6648 | rt2800_rfcsr_write(rt2x00dev, 18, 0x03); |
| 6649 | rt2800_rfcsr_write(rt2x00dev, 19, 0x4D); |
| 6650 | rt2800_rfcsr_write(rt2x00dev, 20, 0x10); |
| 6651 | rt2800_rfcsr_write(rt2x00dev, 21, 0x8D); |
| 6652 | rt2800_rfcsr_write(rt2x00dev, 26, 0x82); |
| 6653 | rt2800_rfcsr_write(rt2x00dev, 28, 0x00); |
| 6654 | rt2800_rfcsr_write(rt2x00dev, 29, 0x10); |
| 6655 | rt2800_rfcsr_write(rt2x00dev, 33, 0xC0); |
| 6656 | rt2800_rfcsr_write(rt2x00dev, 34, 0x07); |
| 6657 | rt2800_rfcsr_write(rt2x00dev, 35, 0x12); |
| 6658 | rt2800_rfcsr_write(rt2x00dev, 47, 0x0C); |
| 6659 | rt2800_rfcsr_write(rt2x00dev, 53, 0x22); |
| 6660 | rt2800_rfcsr_write(rt2x00dev, 63, 0x07); |
| 6661 | |
| 6662 | rt2800_rfcsr_write(rt2x00dev, 2, 0x80); |
| 6663 | msleep(1); |
| 6664 | |
| 6665 | rt2800_adjust_freq_offset(rt2x00dev); |
Stanislaw Gruszka | c630ccf | 2013-03-16 19:19:46 +0100 | [diff] [blame] | 6666 | |
Stanislaw Gruszka | c630ccf | 2013-03-16 19:19:46 +0100 | [diff] [blame] | 6667 | /* Enable DC filter */ |
| 6668 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5592, REV_RT5592C)) |
| 6669 | rt2800_bbp_write(rt2x00dev, 103, 0xc0); |
| 6670 | |
Stanislaw Gruszka | f7df8fe | 2013-04-17 14:08:10 +0200 | [diff] [blame] | 6671 | rt2800_normal_mode_setup_5xxx(rt2x00dev); |
Stanislaw Gruszka | 5de5a1f | 2013-04-17 14:08:17 +0200 | [diff] [blame] | 6672 | |
| 6673 | if (rt2x00_rt_rev_lt(rt2x00dev, RT5592, REV_RT5592C)) |
| 6674 | rt2800_rfcsr_write(rt2x00dev, 27, 0x03); |
Stanislaw Gruszka | d9517f2 | 2013-04-17 14:08:18 +0200 | [diff] [blame] | 6675 | |
| 6676 | rt2800_led_open_drain_enable(rt2x00dev); |
Stanislaw Gruszka | 0c9e5fb | 2013-03-16 19:19:36 +0100 | [diff] [blame] | 6677 | } |
| 6678 | |
Stanislaw Gruszka | 074f252 | 2013-04-17 14:08:20 +0200 | [diff] [blame] | 6679 | static void rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev) |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 6680 | { |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6681 | if (rt2800_is_305x_soc(rt2x00dev)) { |
| 6682 | rt2800_init_rfcsr_305x_soc(rt2x00dev); |
Stanislaw Gruszka | 074f252 | 2013-04-17 14:08:20 +0200 | [diff] [blame] | 6683 | return; |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6684 | } |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 6685 | |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6686 | switch (rt2x00dev->chip.rt) { |
| 6687 | case RT3070: |
| 6688 | case RT3071: |
| 6689 | case RT3090: |
| 6690 | rt2800_init_rfcsr_30xx(rt2x00dev); |
| 6691 | break; |
| 6692 | case RT3290: |
| 6693 | rt2800_init_rfcsr_3290(rt2x00dev); |
| 6694 | break; |
| 6695 | case RT3352: |
| 6696 | rt2800_init_rfcsr_3352(rt2x00dev); |
| 6697 | break; |
| 6698 | case RT3390: |
| 6699 | rt2800_init_rfcsr_3390(rt2x00dev); |
| 6700 | break; |
| 6701 | case RT3572: |
| 6702 | rt2800_init_rfcsr_3572(rt2x00dev); |
| 6703 | break; |
Gabor Juhos | ab7078a | 2013-07-08 16:08:18 +0200 | [diff] [blame] | 6704 | case RT3593: |
| 6705 | rt2800_init_rfcsr_3593(rt2x00dev); |
| 6706 | break; |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6707 | case RT5390: |
| 6708 | rt2800_init_rfcsr_5390(rt2x00dev); |
| 6709 | break; |
| 6710 | case RT5392: |
| 6711 | rt2800_init_rfcsr_5392(rt2x00dev); |
| 6712 | break; |
Stanislaw Gruszka | 0c9e5fb | 2013-03-16 19:19:36 +0100 | [diff] [blame] | 6713 | case RT5592: |
| 6714 | rt2800_init_rfcsr_5592(rt2x00dev); |
Stanislaw Gruszka | 074f252 | 2013-04-17 14:08:20 +0200 | [diff] [blame] | 6715 | break; |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 6716 | } |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 6717 | } |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 6718 | |
| 6719 | int rt2800_enable_radio(struct rt2x00_dev *rt2x00dev) |
| 6720 | { |
| 6721 | u32 reg; |
| 6722 | u16 word; |
| 6723 | |
| 6724 | /* |
Stanislaw Gruszka | 61edc7f | 2013-09-09 12:37:38 +0200 | [diff] [blame] | 6725 | * Initialize MAC registers. |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 6726 | */ |
| 6727 | if (unlikely(rt2800_wait_wpdma_ready(rt2x00dev) || |
Stanislaw Gruszka | c630ccf | 2013-03-16 19:19:46 +0100 | [diff] [blame] | 6728 | rt2800_init_registers(rt2x00dev))) |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 6729 | return -EIO; |
| 6730 | |
Stanislaw Gruszka | 61edc7f | 2013-09-09 12:37:38 +0200 | [diff] [blame] | 6731 | /* |
| 6732 | * Wait BBP/RF to wake up. |
| 6733 | */ |
Stanislaw Gruszka | f4e1a4d | 2013-09-09 12:37:37 +0200 | [diff] [blame] | 6734 | if (unlikely(rt2800_wait_bbp_rf_ready(rt2x00dev))) |
| 6735 | return -EIO; |
| 6736 | |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 6737 | /* |
Stanislaw Gruszka | 61edc7f | 2013-09-09 12:37:38 +0200 | [diff] [blame] | 6738 | * Send signal during boot time to initialize firmware. |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 6739 | */ |
Stanislaw Gruszka | c630ccf | 2013-03-16 19:19:46 +0100 | [diff] [blame] | 6740 | rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0); |
| 6741 | rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0); |
Stanislaw Gruszka | f4e1a4d | 2013-09-09 12:37:37 +0200 | [diff] [blame] | 6742 | if (rt2x00_is_usb(rt2x00dev)) |
Stanislaw Gruszka | c630ccf | 2013-03-16 19:19:46 +0100 | [diff] [blame] | 6743 | rt2800_register_write(rt2x00dev, H2M_INT_SRC, 0); |
Stanislaw Gruszka | f4e1a4d | 2013-09-09 12:37:37 +0200 | [diff] [blame] | 6744 | rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0, 0, 0); |
Stanislaw Gruszka | c630ccf | 2013-03-16 19:19:46 +0100 | [diff] [blame] | 6745 | msleep(1); |
| 6746 | |
Stanislaw Gruszka | 61edc7f | 2013-09-09 12:37:38 +0200 | [diff] [blame] | 6747 | /* |
| 6748 | * Make sure BBP is up and running. |
| 6749 | */ |
Stanislaw Gruszka | f4e1a4d | 2013-09-09 12:37:37 +0200 | [diff] [blame] | 6750 | if (unlikely(rt2800_wait_bbp_ready(rt2x00dev))) |
Stanislaw Gruszka | c630ccf | 2013-03-16 19:19:46 +0100 | [diff] [blame] | 6751 | return -EIO; |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 6752 | |
Stanislaw Gruszka | 61edc7f | 2013-09-09 12:37:38 +0200 | [diff] [blame] | 6753 | /* |
| 6754 | * Initialize BBP/RF registers. |
| 6755 | */ |
Stanislaw Gruszka | a1ef503 | 2013-05-18 14:03:24 +0200 | [diff] [blame] | 6756 | rt2800_init_bbp(rt2x00dev); |
Stanislaw Gruszka | 074f252 | 2013-04-17 14:08:20 +0200 | [diff] [blame] | 6757 | rt2800_init_rfcsr(rt2x00dev); |
| 6758 | |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 6759 | if (rt2x00_is_usb(rt2x00dev) && |
| 6760 | (rt2x00_rt(rt2x00dev, RT3070) || |
| 6761 | rt2x00_rt(rt2x00dev, RT3071) || |
| 6762 | rt2x00_rt(rt2x00dev, RT3572))) { |
| 6763 | udelay(200); |
| 6764 | rt2800_mcu_request(rt2x00dev, MCU_CURRENT, 0, 0, 0); |
| 6765 | udelay(10); |
| 6766 | } |
| 6767 | |
| 6768 | /* |
| 6769 | * Enable RX. |
| 6770 | */ |
| 6771 | rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, ®); |
| 6772 | rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_TX, 1); |
| 6773 | rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, 0); |
| 6774 | rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg); |
| 6775 | |
| 6776 | udelay(50); |
| 6777 | |
| 6778 | rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®); |
| 6779 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 1); |
| 6780 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 1); |
| 6781 | rt2x00_set_field32(®, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 2); |
| 6782 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1); |
| 6783 | rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg); |
| 6784 | |
| 6785 | rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, ®); |
| 6786 | rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_TX, 1); |
| 6787 | rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, 1); |
| 6788 | rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg); |
| 6789 | |
| 6790 | /* |
| 6791 | * Initialize LED control |
| 6792 | */ |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6793 | rt2800_eeprom_read(rt2x00dev, EEPROM_LED_AG_CONF, &word); |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 6794 | rt2800_mcu_request(rt2x00dev, MCU_LED_AG_CONF, 0xff, |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 6795 | word & 0xff, (word >> 8) & 0xff); |
| 6796 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6797 | rt2800_eeprom_read(rt2x00dev, EEPROM_LED_ACT_CONF, &word); |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 6798 | rt2800_mcu_request(rt2x00dev, MCU_LED_ACT_CONF, 0xff, |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 6799 | word & 0xff, (word >> 8) & 0xff); |
| 6800 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6801 | rt2800_eeprom_read(rt2x00dev, EEPROM_LED_POLARITY, &word); |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 6802 | rt2800_mcu_request(rt2x00dev, MCU_LED_LED_POLARITY, 0xff, |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 6803 | word & 0xff, (word >> 8) & 0xff); |
| 6804 | |
| 6805 | return 0; |
| 6806 | } |
| 6807 | EXPORT_SYMBOL_GPL(rt2800_enable_radio); |
| 6808 | |
| 6809 | void rt2800_disable_radio(struct rt2x00_dev *rt2x00dev) |
| 6810 | { |
| 6811 | u32 reg; |
| 6812 | |
Jakub Kicinski | f7b395e | 2012-04-03 03:40:47 +0200 | [diff] [blame] | 6813 | rt2800_disable_wpdma(rt2x00dev); |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 6814 | |
| 6815 | /* Wait for DMA, ignore error */ |
| 6816 | rt2800_wait_wpdma_ready(rt2x00dev); |
| 6817 | |
| 6818 | rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, ®); |
| 6819 | rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_TX, 0); |
| 6820 | rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, 0); |
| 6821 | rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg); |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 6822 | } |
| 6823 | EXPORT_SYMBOL_GPL(rt2800_disable_radio); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 6824 | |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 6825 | int rt2800_efuse_detect(struct rt2x00_dev *rt2x00dev) |
| 6826 | { |
| 6827 | u32 reg; |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6828 | u16 efuse_ctrl_reg; |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 6829 | |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6830 | if (rt2x00_rt(rt2x00dev, RT3290)) |
| 6831 | efuse_ctrl_reg = EFUSE_CTRL_3290; |
| 6832 | else |
| 6833 | efuse_ctrl_reg = EFUSE_CTRL; |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 6834 | |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6835 | rt2800_register_read(rt2x00dev, efuse_ctrl_reg, ®); |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 6836 | return rt2x00_get_field32(reg, EFUSE_CTRL_PRESENT); |
| 6837 | } |
| 6838 | EXPORT_SYMBOL_GPL(rt2800_efuse_detect); |
| 6839 | |
| 6840 | static void rt2800_efuse_read(struct rt2x00_dev *rt2x00dev, unsigned int i) |
| 6841 | { |
| 6842 | u32 reg; |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6843 | u16 efuse_ctrl_reg; |
| 6844 | u16 efuse_data0_reg; |
| 6845 | u16 efuse_data1_reg; |
| 6846 | u16 efuse_data2_reg; |
| 6847 | u16 efuse_data3_reg; |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 6848 | |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6849 | if (rt2x00_rt(rt2x00dev, RT3290)) { |
| 6850 | efuse_ctrl_reg = EFUSE_CTRL_3290; |
| 6851 | efuse_data0_reg = EFUSE_DATA0_3290; |
| 6852 | efuse_data1_reg = EFUSE_DATA1_3290; |
| 6853 | efuse_data2_reg = EFUSE_DATA2_3290; |
| 6854 | efuse_data3_reg = EFUSE_DATA3_3290; |
| 6855 | } else { |
| 6856 | efuse_ctrl_reg = EFUSE_CTRL; |
| 6857 | efuse_data0_reg = EFUSE_DATA0; |
| 6858 | efuse_data1_reg = EFUSE_DATA1; |
| 6859 | efuse_data2_reg = EFUSE_DATA2; |
| 6860 | efuse_data3_reg = EFUSE_DATA3; |
| 6861 | } |
Gertjan van Wingerde | 31a4cf1 | 2009-11-14 20:20:36 +0100 | [diff] [blame] | 6862 | mutex_lock(&rt2x00dev->csr_mutex); |
| 6863 | |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6864 | rt2800_register_read_lock(rt2x00dev, efuse_ctrl_reg, ®); |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 6865 | rt2x00_set_field32(®, EFUSE_CTRL_ADDRESS_IN, i); |
| 6866 | rt2x00_set_field32(®, EFUSE_CTRL_MODE, 0); |
| 6867 | rt2x00_set_field32(®, EFUSE_CTRL_KICK, 1); |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6868 | rt2800_register_write_lock(rt2x00dev, efuse_ctrl_reg, reg); |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 6869 | |
| 6870 | /* Wait until the EEPROM has been loaded */ |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6871 | rt2800_regbusy_read(rt2x00dev, efuse_ctrl_reg, EFUSE_CTRL_KICK, ®); |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 6872 | /* Apparently the data is read from end to start */ |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6873 | rt2800_register_read_lock(rt2x00dev, efuse_data3_reg, ®); |
Larry Finger | daabead | 2011-09-14 16:50:23 -0500 | [diff] [blame] | 6874 | /* The returned value is in CPU order, but eeprom is le */ |
Gertjan van Wingerde | 68fa64e | 2011-11-16 23:16:15 +0100 | [diff] [blame] | 6875 | *(u32 *)&rt2x00dev->eeprom[i] = cpu_to_le32(reg); |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6876 | rt2800_register_read_lock(rt2x00dev, efuse_data2_reg, ®); |
Larry Finger | daabead | 2011-09-14 16:50:23 -0500 | [diff] [blame] | 6877 | *(u32 *)&rt2x00dev->eeprom[i + 2] = cpu_to_le32(reg); |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6878 | rt2800_register_read_lock(rt2x00dev, efuse_data1_reg, ®); |
Larry Finger | daabead | 2011-09-14 16:50:23 -0500 | [diff] [blame] | 6879 | *(u32 *)&rt2x00dev->eeprom[i + 4] = cpu_to_le32(reg); |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6880 | rt2800_register_read_lock(rt2x00dev, efuse_data0_reg, ®); |
Larry Finger | daabead | 2011-09-14 16:50:23 -0500 | [diff] [blame] | 6881 | *(u32 *)&rt2x00dev->eeprom[i + 6] = cpu_to_le32(reg); |
Gertjan van Wingerde | 31a4cf1 | 2009-11-14 20:20:36 +0100 | [diff] [blame] | 6882 | |
| 6883 | mutex_unlock(&rt2x00dev->csr_mutex); |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 6884 | } |
| 6885 | |
Gabor Juhos | a02308e | 2012-12-29 14:51:51 +0100 | [diff] [blame] | 6886 | int rt2800_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev) |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 6887 | { |
| 6888 | unsigned int i; |
| 6889 | |
| 6890 | for (i = 0; i < EEPROM_SIZE / sizeof(u16); i += 8) |
| 6891 | rt2800_efuse_read(rt2x00dev, i); |
Gabor Juhos | a02308e | 2012-12-29 14:51:51 +0100 | [diff] [blame] | 6892 | |
| 6893 | return 0; |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 6894 | } |
| 6895 | EXPORT_SYMBOL_GPL(rt2800_read_eeprom_efuse); |
| 6896 | |
Gabor Juhos | a3f1625 | 2013-07-08 16:08:25 +0200 | [diff] [blame] | 6897 | static u8 rt2800_get_txmixer_gain_24g(struct rt2x00_dev *rt2x00dev) |
| 6898 | { |
| 6899 | u16 word; |
| 6900 | |
Gabor Juhos | 6316c78 | 2013-07-08 16:08:26 +0200 | [diff] [blame] | 6901 | if (rt2x00_rt(rt2x00dev, RT3593)) |
| 6902 | return 0; |
| 6903 | |
Gabor Juhos | a3f1625 | 2013-07-08 16:08:25 +0200 | [diff] [blame] | 6904 | rt2800_eeprom_read(rt2x00dev, EEPROM_TXMIXER_GAIN_BG, &word); |
| 6905 | if ((word & 0x00ff) != 0x00ff) |
| 6906 | return rt2x00_get_field16(word, EEPROM_TXMIXER_GAIN_BG_VAL); |
| 6907 | |
| 6908 | return 0; |
| 6909 | } |
| 6910 | |
| 6911 | static u8 rt2800_get_txmixer_gain_5g(struct rt2x00_dev *rt2x00dev) |
| 6912 | { |
| 6913 | u16 word; |
| 6914 | |
Gabor Juhos | 6316c78 | 2013-07-08 16:08:26 +0200 | [diff] [blame] | 6915 | if (rt2x00_rt(rt2x00dev, RT3593)) |
| 6916 | return 0; |
| 6917 | |
Gabor Juhos | a3f1625 | 2013-07-08 16:08:25 +0200 | [diff] [blame] | 6918 | rt2800_eeprom_read(rt2x00dev, EEPROM_TXMIXER_GAIN_A, &word); |
| 6919 | if ((word & 0x00ff) != 0x00ff) |
| 6920 | return rt2x00_get_field16(word, EEPROM_TXMIXER_GAIN_A_VAL); |
| 6921 | |
| 6922 | return 0; |
| 6923 | } |
| 6924 | |
Gertjan van Wingerde | ad417a5 | 2012-09-03 03:25:51 +0200 | [diff] [blame] | 6925 | static int rt2800_validate_eeprom(struct rt2x00_dev *rt2x00dev) |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6926 | { |
Gertjan van Wingerde | 77c06c2 | 2012-02-06 23:45:13 +0100 | [diff] [blame] | 6927 | struct rt2800_drv_data *drv_data = rt2x00dev->drv_data; |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6928 | u16 word; |
| 6929 | u8 *mac; |
| 6930 | u8 default_lna_gain; |
Gabor Juhos | a02308e | 2012-12-29 14:51:51 +0100 | [diff] [blame] | 6931 | int retval; |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6932 | |
| 6933 | /* |
Gertjan van Wingerde | ad417a5 | 2012-09-03 03:25:51 +0200 | [diff] [blame] | 6934 | * Read the EEPROM. |
| 6935 | */ |
Gabor Juhos | a02308e | 2012-12-29 14:51:51 +0100 | [diff] [blame] | 6936 | retval = rt2800_read_eeprom(rt2x00dev); |
| 6937 | if (retval) |
| 6938 | return retval; |
Gertjan van Wingerde | ad417a5 | 2012-09-03 03:25:51 +0200 | [diff] [blame] | 6939 | |
| 6940 | /* |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6941 | * Start validation of the data that has been read. |
| 6942 | */ |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6943 | mac = rt2800_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6944 | if (!is_valid_ether_addr(mac)) { |
Joe Perches | f4f7f414 | 2012-07-12 19:33:08 +0000 | [diff] [blame] | 6945 | eth_random_addr(mac); |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 6946 | rt2x00_eeprom_dbg(rt2x00dev, "MAC: %pM\n", mac); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6947 | } |
| 6948 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6949 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6950 | if (word == 0xffff) { |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 6951 | rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RXPATH, 2); |
| 6952 | rt2x00_set_field16(&word, EEPROM_NIC_CONF0_TXPATH, 1); |
| 6953 | rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RF_TYPE, RF2820); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6954 | rt2800_eeprom_write(rt2x00dev, EEPROM_NIC_CONF0, word); |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 6955 | rt2x00_eeprom_dbg(rt2x00dev, "Antenna: 0x%04x\n", word); |
Gertjan van Wingerde | 49e721e | 2010-02-13 20:55:49 +0100 | [diff] [blame] | 6956 | } else if (rt2x00_rt(rt2x00dev, RT2860) || |
Gertjan van Wingerde | e148b4c | 2010-04-11 14:31:09 +0200 | [diff] [blame] | 6957 | rt2x00_rt(rt2x00dev, RT2872)) { |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6958 | /* |
| 6959 | * There is a max of 2 RX streams for RT28x0 series |
| 6960 | */ |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 6961 | if (rt2x00_get_field16(word, EEPROM_NIC_CONF0_RXPATH) > 2) |
| 6962 | rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RXPATH, 2); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6963 | rt2800_eeprom_write(rt2x00dev, EEPROM_NIC_CONF0, word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6964 | } |
| 6965 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6966 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6967 | if (word == 0xffff) { |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 6968 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_HW_RADIO, 0); |
| 6969 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_TX_ALC, 0); |
| 6970 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_LNA_2G, 0); |
| 6971 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_LNA_5G, 0); |
| 6972 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_CARDBUS_ACCEL, 0); |
| 6973 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_SB_2G, 0); |
| 6974 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_SB_5G, 0); |
| 6975 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_WPS_PBC, 0); |
| 6976 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_2G, 0); |
| 6977 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_5G, 0); |
| 6978 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BROADBAND_EXT_LNA, 0); |
| 6979 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_ANT_DIVERSITY, 0); |
| 6980 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_INTERNAL_TX_ALC, 0); |
| 6981 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BT_COEXIST, 0); |
| 6982 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_DAC_TEST, 0); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6983 | rt2800_eeprom_write(rt2x00dev, EEPROM_NIC_CONF1, word); |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 6984 | rt2x00_eeprom_dbg(rt2x00dev, "NIC: 0x%04x\n", word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6985 | } |
| 6986 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6987 | rt2800_eeprom_read(rt2x00dev, EEPROM_FREQ, &word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6988 | if ((word & 0x00ff) == 0x00ff) { |
| 6989 | rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6990 | rt2800_eeprom_write(rt2x00dev, EEPROM_FREQ, word); |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 6991 | rt2x00_eeprom_dbg(rt2x00dev, "Freq: 0x%04x\n", word); |
Gertjan van Wingerde | ec2d179 | 2010-06-29 21:44:50 +0200 | [diff] [blame] | 6992 | } |
| 6993 | if ((word & 0xff00) == 0xff00) { |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6994 | rt2x00_set_field16(&word, EEPROM_FREQ_LED_MODE, |
| 6995 | LED_MODE_TXRX_ACTIVITY); |
| 6996 | rt2x00_set_field16(&word, EEPROM_FREQ_LED_POLARITY, 0); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6997 | rt2800_eeprom_write(rt2x00dev, EEPROM_FREQ, word); |
| 6998 | rt2800_eeprom_write(rt2x00dev, EEPROM_LED_AG_CONF, 0x5555); |
| 6999 | rt2800_eeprom_write(rt2x00dev, EEPROM_LED_ACT_CONF, 0x2221); |
| 7000 | rt2800_eeprom_write(rt2x00dev, EEPROM_LED_POLARITY, 0xa9f8); |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 7001 | rt2x00_eeprom_dbg(rt2x00dev, "Led Mode: 0x%04x\n", word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7002 | } |
| 7003 | |
| 7004 | /* |
| 7005 | * During the LNA validation we are going to use |
| 7006 | * lna0 as correct value. Note that EEPROM_LNA |
| 7007 | * is never validated. |
| 7008 | */ |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 7009 | rt2800_eeprom_read(rt2x00dev, EEPROM_LNA, &word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7010 | default_lna_gain = rt2x00_get_field16(word, EEPROM_LNA_A0); |
| 7011 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 7012 | rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7013 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET0)) > 10) |
| 7014 | rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET0, 0); |
| 7015 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET1)) > 10) |
| 7016 | rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET1, 0); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 7017 | rt2800_eeprom_write(rt2x00dev, EEPROM_RSSI_BG, word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7018 | |
Gabor Juhos | a3f1625 | 2013-07-08 16:08:25 +0200 | [diff] [blame] | 7019 | drv_data->txmixer_gain_24g = rt2800_get_txmixer_gain_24g(rt2x00dev); |
Gertjan van Wingerde | 77c06c2 | 2012-02-06 23:45:13 +0100 | [diff] [blame] | 7020 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 7021 | rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7022 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG2_OFFSET2)) > 10) |
| 7023 | rt2x00_set_field16(&word, EEPROM_RSSI_BG2_OFFSET2, 0); |
Gabor Juhos | f36bb0c | 2013-07-08 16:08:27 +0200 | [diff] [blame] | 7024 | if (!rt2x00_rt(rt2x00dev, RT3593)) { |
| 7025 | if (rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0x00 || |
| 7026 | rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0xff) |
| 7027 | rt2x00_set_field16(&word, EEPROM_RSSI_BG2_LNA_A1, |
| 7028 | default_lna_gain); |
| 7029 | } |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 7030 | rt2800_eeprom_write(rt2x00dev, EEPROM_RSSI_BG2, word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7031 | |
Gabor Juhos | a3f1625 | 2013-07-08 16:08:25 +0200 | [diff] [blame] | 7032 | drv_data->txmixer_gain_5g = rt2800_get_txmixer_gain_5g(rt2x00dev); |
Gertjan van Wingerde | 77c06c2 | 2012-02-06 23:45:13 +0100 | [diff] [blame] | 7033 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 7034 | rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7035 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET0)) > 10) |
| 7036 | rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET0, 0); |
| 7037 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET1)) > 10) |
| 7038 | rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET1, 0); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 7039 | rt2800_eeprom_write(rt2x00dev, EEPROM_RSSI_A, word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7040 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 7041 | rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7042 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A2_OFFSET2)) > 10) |
| 7043 | rt2x00_set_field16(&word, EEPROM_RSSI_A2_OFFSET2, 0); |
Gabor Juhos | f36bb0c | 2013-07-08 16:08:27 +0200 | [diff] [blame] | 7044 | if (!rt2x00_rt(rt2x00dev, RT3593)) { |
| 7045 | if (rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0x00 || |
| 7046 | rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0xff) |
| 7047 | rt2x00_set_field16(&word, EEPROM_RSSI_A2_LNA_A2, |
| 7048 | default_lna_gain); |
| 7049 | } |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 7050 | rt2800_eeprom_write(rt2x00dev, EEPROM_RSSI_A2, word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7051 | |
Gabor Juhos | f36bb0c | 2013-07-08 16:08:27 +0200 | [diff] [blame] | 7052 | if (rt2x00_rt(rt2x00dev, RT3593)) { |
| 7053 | rt2800_eeprom_read(rt2x00dev, EEPROM_EXT_LNA2, &word); |
| 7054 | if (rt2x00_get_field16(word, EEPROM_EXT_LNA2_A1) == 0x00 || |
| 7055 | rt2x00_get_field16(word, EEPROM_EXT_LNA2_A1) == 0xff) |
| 7056 | rt2x00_set_field16(&word, EEPROM_EXT_LNA2_A1, |
| 7057 | default_lna_gain); |
| 7058 | if (rt2x00_get_field16(word, EEPROM_EXT_LNA2_A2) == 0x00 || |
| 7059 | rt2x00_get_field16(word, EEPROM_EXT_LNA2_A2) == 0xff) |
| 7060 | rt2x00_set_field16(&word, EEPROM_EXT_LNA2_A1, |
| 7061 | default_lna_gain); |
| 7062 | rt2800_eeprom_write(rt2x00dev, EEPROM_EXT_LNA2, word); |
| 7063 | } |
| 7064 | |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7065 | return 0; |
| 7066 | } |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7067 | |
Gertjan van Wingerde | ad417a5 | 2012-09-03 03:25:51 +0200 | [diff] [blame] | 7068 | static int rt2800_init_eeprom(struct rt2x00_dev *rt2x00dev) |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7069 | { |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7070 | u16 value; |
| 7071 | u16 eeprom; |
Gabor Juhos | 86868b2 | 2013-03-30 14:53:09 +0100 | [diff] [blame] | 7072 | u16 rf; |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7073 | |
Gabor Juhos | 86868b2 | 2013-03-30 14:53:09 +0100 | [diff] [blame] | 7074 | /* |
| 7075 | * Read EEPROM word for configuration. |
| 7076 | */ |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 7077 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom); |
Gabor Juhos | 86868b2 | 2013-03-30 14:53:09 +0100 | [diff] [blame] | 7078 | |
| 7079 | /* |
| 7080 | * Identify RF chipset by EEPROM value |
| 7081 | * RT28xx/RT30xx: defined in "EEPROM_NIC_CONF0_RF_TYPE" field |
| 7082 | * RT53xx: defined in "EEPROM_CHIP_ID" field |
| 7083 | */ |
| 7084 | if (rt2x00_rt(rt2x00dev, RT3290) || |
| 7085 | rt2x00_rt(rt2x00dev, RT5390) || |
| 7086 | rt2x00_rt(rt2x00dev, RT5392)) |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 7087 | rt2800_eeprom_read(rt2x00dev, EEPROM_CHIP_ID, &rf); |
Gabor Juhos | 86868b2 | 2013-03-30 14:53:09 +0100 | [diff] [blame] | 7088 | else |
| 7089 | rf = rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RF_TYPE); |
| 7090 | |
| 7091 | switch (rf) { |
Larry Finger | d331eb5 | 2011-09-14 16:50:22 -0500 | [diff] [blame] | 7092 | case RF2820: |
| 7093 | case RF2850: |
| 7094 | case RF2720: |
| 7095 | case RF2750: |
| 7096 | case RF3020: |
| 7097 | case RF2020: |
| 7098 | case RF3021: |
| 7099 | case RF3022: |
| 7100 | case RF3052: |
Gabor Juhos | 0f5af26 | 2013-07-08 16:08:32 +0200 | [diff] [blame] | 7101 | case RF3053: |
Stanislaw Gruszka | 3b9b74b | 2013-09-25 15:34:55 +0200 | [diff] [blame] | 7102 | case RF3070: |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 7103 | case RF3290: |
Larry Finger | d331eb5 | 2011-09-14 16:50:22 -0500 | [diff] [blame] | 7104 | case RF3320: |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 7105 | case RF3322: |
villacis@palosanto.com | ccf91bd | 2012-05-16 21:07:12 +0200 | [diff] [blame] | 7106 | case RF5360: |
Canek Peláez Valdés | ac0372a | 2014-08-24 19:06:11 -0500 | [diff] [blame] | 7107 | case RF5362: |
Larry Finger | d331eb5 | 2011-09-14 16:50:22 -0500 | [diff] [blame] | 7108 | case RF5370: |
John Li | 2ed7188 | 2012-02-17 17:33:06 +0800 | [diff] [blame] | 7109 | case RF5372: |
Larry Finger | d331eb5 | 2011-09-14 16:50:22 -0500 | [diff] [blame] | 7110 | case RF5390: |
Zero.Lin | cff3d1f | 2012-05-29 16:11:09 +0800 | [diff] [blame] | 7111 | case RF5392: |
Stanislaw Gruszka | b8863f8 | 2013-03-16 19:19:30 +0100 | [diff] [blame] | 7112 | case RF5592: |
Larry Finger | d331eb5 | 2011-09-14 16:50:22 -0500 | [diff] [blame] | 7113 | break; |
| 7114 | default: |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 7115 | rt2x00_err(rt2x00dev, "Invalid RF chipset 0x%04x detected\n", |
| 7116 | rf); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7117 | return -ENODEV; |
| 7118 | } |
| 7119 | |
Gabor Juhos | 86868b2 | 2013-03-30 14:53:09 +0100 | [diff] [blame] | 7120 | rt2x00_set_rf(rt2x00dev, rf); |
| 7121 | |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7122 | /* |
| 7123 | * Identify default antenna configuration. |
| 7124 | */ |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 7125 | rt2x00dev->default_ant.tx_chain_num = |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 7126 | rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH); |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 7127 | rt2x00dev->default_ant.rx_chain_num = |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 7128 | rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7129 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 7130 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom); |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 7131 | |
| 7132 | if (rt2x00_rt(rt2x00dev, RT3070) || |
| 7133 | rt2x00_rt(rt2x00dev, RT3090) || |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 7134 | rt2x00_rt(rt2x00dev, RT3352) || |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 7135 | rt2x00_rt(rt2x00dev, RT3390)) { |
| 7136 | value = rt2x00_get_field16(eeprom, |
| 7137 | EEPROM_NIC_CONF1_ANT_DIVERSITY); |
| 7138 | switch (value) { |
| 7139 | case 0: |
| 7140 | case 1: |
| 7141 | case 2: |
| 7142 | rt2x00dev->default_ant.tx = ANTENNA_A; |
| 7143 | rt2x00dev->default_ant.rx = ANTENNA_A; |
| 7144 | break; |
| 7145 | case 3: |
| 7146 | rt2x00dev->default_ant.tx = ANTENNA_A; |
| 7147 | rt2x00dev->default_ant.rx = ANTENNA_B; |
| 7148 | break; |
| 7149 | } |
| 7150 | } else { |
| 7151 | rt2x00dev->default_ant.tx = ANTENNA_A; |
| 7152 | rt2x00dev->default_ant.rx = ANTENNA_A; |
| 7153 | } |
| 7154 | |
Anisse Astier | 0586a11 | 2012-04-23 12:33:11 +0200 | [diff] [blame] | 7155 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390R)) { |
| 7156 | rt2x00dev->default_ant.tx = ANTENNA_HW_DIVERSITY; /* Unused */ |
| 7157 | rt2x00dev->default_ant.rx = ANTENNA_HW_DIVERSITY; /* Unused */ |
| 7158 | } |
| 7159 | |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7160 | /* |
Gertjan van Wingerde | 9328fda | 2011-04-30 17:15:13 +0200 | [diff] [blame] | 7161 | * Determine external LNA informations. |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7162 | */ |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 7163 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_EXTERNAL_LNA_5G)) |
Ivo van Doorn | 7dab73b | 2011-04-18 15:27:06 +0200 | [diff] [blame] | 7164 | __set_bit(CAPABILITY_EXTERNAL_LNA_A, &rt2x00dev->cap_flags); |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 7165 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_EXTERNAL_LNA_2G)) |
Ivo van Doorn | 7dab73b | 2011-04-18 15:27:06 +0200 | [diff] [blame] | 7166 | __set_bit(CAPABILITY_EXTERNAL_LNA_BG, &rt2x00dev->cap_flags); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7167 | |
| 7168 | /* |
| 7169 | * Detect if this device has an hardware controlled radio. |
| 7170 | */ |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 7171 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_HW_RADIO)) |
Ivo van Doorn | 7dab73b | 2011-04-18 15:27:06 +0200 | [diff] [blame] | 7172 | __set_bit(CAPABILITY_HW_BUTTON, &rt2x00dev->cap_flags); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7173 | |
| 7174 | /* |
Gertjan van Wingerde | fdbc7b0 | 2011-04-30 17:15:37 +0200 | [diff] [blame] | 7175 | * Detect if this device has Bluetooth co-existence. |
| 7176 | */ |
| 7177 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_BT_COEXIST)) |
| 7178 | __set_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags); |
| 7179 | |
| 7180 | /* |
Gertjan van Wingerde | 9328fda | 2011-04-30 17:15:13 +0200 | [diff] [blame] | 7181 | * Read frequency offset and RF programming sequence. |
| 7182 | */ |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 7183 | rt2800_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom); |
Gertjan van Wingerde | 9328fda | 2011-04-30 17:15:13 +0200 | [diff] [blame] | 7184 | rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET); |
| 7185 | |
| 7186 | /* |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7187 | * Store led settings, for correct led behaviour. |
| 7188 | */ |
| 7189 | #ifdef CONFIG_RT2X00_LIB_LEDS |
| 7190 | rt2800_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO); |
| 7191 | rt2800_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC); |
| 7192 | rt2800_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY); |
| 7193 | |
Gertjan van Wingerde | 9328fda | 2011-04-30 17:15:13 +0200 | [diff] [blame] | 7194 | rt2x00dev->led_mcu_reg = eeprom; |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7195 | #endif /* CONFIG_RT2X00_LIB_LEDS */ |
| 7196 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 7197 | /* |
| 7198 | * Check if support EIRP tx power limit feature. |
| 7199 | */ |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 7200 | rt2800_eeprom_read(rt2x00dev, EEPROM_EIRP_MAX_TX_POWER, &eeprom); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 7201 | |
| 7202 | if (rt2x00_get_field16(eeprom, EEPROM_EIRP_MAX_TX_POWER_2GHZ) < |
| 7203 | EIRP_MAX_TX_POWER_LIMIT) |
Ivo van Doorn | 7dab73b | 2011-04-18 15:27:06 +0200 | [diff] [blame] | 7204 | __set_bit(CAPABILITY_POWER_LIMIT, &rt2x00dev->cap_flags); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 7205 | |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7206 | return 0; |
| 7207 | } |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 7208 | |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7209 | /* |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 7210 | * RF value list for rt28xx |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7211 | * Supports: 2.4 GHz (all) & 5.2 GHz (RF2850 & RF2750) |
| 7212 | */ |
| 7213 | static const struct rf_channel rf_vals[] = { |
| 7214 | { 1, 0x18402ecc, 0x184c0786, 0x1816b455, 0x1800510b }, |
| 7215 | { 2, 0x18402ecc, 0x184c0786, 0x18168a55, 0x1800519f }, |
| 7216 | { 3, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800518b }, |
| 7217 | { 4, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800519f }, |
| 7218 | { 5, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800518b }, |
| 7219 | { 6, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800519f }, |
| 7220 | { 7, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800518b }, |
| 7221 | { 8, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800519f }, |
| 7222 | { 9, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800518b }, |
| 7223 | { 10, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800519f }, |
| 7224 | { 11, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800518b }, |
| 7225 | { 12, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800519f }, |
| 7226 | { 13, 0x18402ecc, 0x184c079e, 0x18168a55, 0x1800518b }, |
| 7227 | { 14, 0x18402ecc, 0x184c07a2, 0x18168a55, 0x18005193 }, |
| 7228 | |
| 7229 | /* 802.11 UNI / HyperLan 2 */ |
| 7230 | { 36, 0x18402ecc, 0x184c099a, 0x18158a55, 0x180ed1a3 }, |
| 7231 | { 38, 0x18402ecc, 0x184c099e, 0x18158a55, 0x180ed193 }, |
| 7232 | { 40, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed183 }, |
| 7233 | { 44, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed1a3 }, |
| 7234 | { 46, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed18b }, |
| 7235 | { 48, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed19b }, |
| 7236 | { 52, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed193 }, |
| 7237 | { 54, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed1a3 }, |
| 7238 | { 56, 0x18402ec8, 0x184c068e, 0x18158a55, 0x180ed18b }, |
| 7239 | { 60, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed183 }, |
| 7240 | { 62, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed193 }, |
| 7241 | { 64, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed1a3 }, |
| 7242 | |
| 7243 | /* 802.11 HyperLan 2 */ |
| 7244 | { 100, 0x18402ec8, 0x184c06b2, 0x18178a55, 0x180ed783 }, |
| 7245 | { 102, 0x18402ec8, 0x184c06b2, 0x18578a55, 0x180ed793 }, |
| 7246 | { 104, 0x18402ec8, 0x185c06b2, 0x18578a55, 0x180ed1a3 }, |
| 7247 | { 108, 0x18402ecc, 0x185c0a32, 0x18578a55, 0x180ed193 }, |
| 7248 | { 110, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed183 }, |
| 7249 | { 112, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed19b }, |
| 7250 | { 116, 0x18402ecc, 0x184c0a3a, 0x18178a55, 0x180ed1a3 }, |
| 7251 | { 118, 0x18402ecc, 0x184c0a3e, 0x18178a55, 0x180ed193 }, |
| 7252 | { 120, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed183 }, |
| 7253 | { 124, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed193 }, |
| 7254 | { 126, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed15b }, |
| 7255 | { 128, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed1a3 }, |
| 7256 | { 132, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed18b }, |
| 7257 | { 134, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed193 }, |
| 7258 | { 136, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed19b }, |
| 7259 | { 140, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed183 }, |
| 7260 | |
| 7261 | /* 802.11 UNII */ |
| 7262 | { 149, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed1a7 }, |
| 7263 | { 151, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed187 }, |
| 7264 | { 153, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed18f }, |
| 7265 | { 157, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed19f }, |
| 7266 | { 159, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed1a7 }, |
| 7267 | { 161, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed187 }, |
| 7268 | { 165, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed197 }, |
| 7269 | { 167, 0x18402ec4, 0x184c03d2, 0x18179855, 0x1815531f }, |
| 7270 | { 169, 0x18402ec4, 0x184c03d2, 0x18179855, 0x18155327 }, |
| 7271 | { 171, 0x18402ec4, 0x184c03d6, 0x18179855, 0x18155307 }, |
| 7272 | { 173, 0x18402ec4, 0x184c03d6, 0x18179855, 0x1815530f }, |
| 7273 | |
| 7274 | /* 802.11 Japan */ |
| 7275 | { 184, 0x15002ccc, 0x1500491e, 0x1509be55, 0x150c0a0b }, |
| 7276 | { 188, 0x15002ccc, 0x15004922, 0x1509be55, 0x150c0a13 }, |
| 7277 | { 192, 0x15002ccc, 0x15004926, 0x1509be55, 0x150c0a1b }, |
| 7278 | { 196, 0x15002ccc, 0x1500492a, 0x1509be55, 0x150c0a23 }, |
| 7279 | { 208, 0x15002ccc, 0x1500493a, 0x1509be55, 0x150c0a13 }, |
| 7280 | { 212, 0x15002ccc, 0x1500493e, 0x1509be55, 0x150c0a1b }, |
| 7281 | { 216, 0x15002ccc, 0x15004982, 0x1509be55, 0x150c0a23 }, |
| 7282 | }; |
| 7283 | |
| 7284 | /* |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 7285 | * RF value list for rt3xxx |
Kevin Lo | b6b561c | 2013-10-14 10:05:45 +0800 | [diff] [blame] | 7286 | * Supports: 2.4 GHz (all) & 5.2 GHz (RF3052 & RF3053) |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7287 | */ |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 7288 | static const struct rf_channel rf_vals_3x[] = { |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7289 | {1, 241, 2, 2 }, |
| 7290 | {2, 241, 2, 7 }, |
| 7291 | {3, 242, 2, 2 }, |
| 7292 | {4, 242, 2, 7 }, |
| 7293 | {5, 243, 2, 2 }, |
| 7294 | {6, 243, 2, 7 }, |
| 7295 | {7, 244, 2, 2 }, |
| 7296 | {8, 244, 2, 7 }, |
| 7297 | {9, 245, 2, 2 }, |
| 7298 | {10, 245, 2, 7 }, |
| 7299 | {11, 246, 2, 2 }, |
| 7300 | {12, 246, 2, 7 }, |
| 7301 | {13, 247, 2, 2 }, |
| 7302 | {14, 248, 2, 4 }, |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 7303 | |
| 7304 | /* 802.11 UNI / HyperLan 2 */ |
| 7305 | {36, 0x56, 0, 4}, |
| 7306 | {38, 0x56, 0, 6}, |
| 7307 | {40, 0x56, 0, 8}, |
| 7308 | {44, 0x57, 0, 0}, |
| 7309 | {46, 0x57, 0, 2}, |
| 7310 | {48, 0x57, 0, 4}, |
| 7311 | {52, 0x57, 0, 8}, |
| 7312 | {54, 0x57, 0, 10}, |
| 7313 | {56, 0x58, 0, 0}, |
| 7314 | {60, 0x58, 0, 4}, |
| 7315 | {62, 0x58, 0, 6}, |
| 7316 | {64, 0x58, 0, 8}, |
| 7317 | |
| 7318 | /* 802.11 HyperLan 2 */ |
| 7319 | {100, 0x5b, 0, 8}, |
| 7320 | {102, 0x5b, 0, 10}, |
| 7321 | {104, 0x5c, 0, 0}, |
| 7322 | {108, 0x5c, 0, 4}, |
| 7323 | {110, 0x5c, 0, 6}, |
| 7324 | {112, 0x5c, 0, 8}, |
| 7325 | {116, 0x5d, 0, 0}, |
| 7326 | {118, 0x5d, 0, 2}, |
| 7327 | {120, 0x5d, 0, 4}, |
| 7328 | {124, 0x5d, 0, 8}, |
| 7329 | {126, 0x5d, 0, 10}, |
| 7330 | {128, 0x5e, 0, 0}, |
| 7331 | {132, 0x5e, 0, 4}, |
| 7332 | {134, 0x5e, 0, 6}, |
| 7333 | {136, 0x5e, 0, 8}, |
| 7334 | {140, 0x5f, 0, 0}, |
| 7335 | |
| 7336 | /* 802.11 UNII */ |
| 7337 | {149, 0x5f, 0, 9}, |
| 7338 | {151, 0x5f, 0, 11}, |
| 7339 | {153, 0x60, 0, 1}, |
| 7340 | {157, 0x60, 0, 5}, |
| 7341 | {159, 0x60, 0, 7}, |
| 7342 | {161, 0x60, 0, 9}, |
| 7343 | {165, 0x61, 0, 1}, |
| 7344 | {167, 0x61, 0, 3}, |
| 7345 | {169, 0x61, 0, 5}, |
| 7346 | {171, 0x61, 0, 7}, |
| 7347 | {173, 0x61, 0, 9}, |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7348 | }; |
| 7349 | |
Stanislaw Gruszka | 7848b23 | 2013-03-16 19:19:31 +0100 | [diff] [blame] | 7350 | static const struct rf_channel rf_vals_5592_xtal20[] = { |
| 7351 | /* Channel, N, K, mod, R */ |
| 7352 | {1, 482, 4, 10, 3}, |
| 7353 | {2, 483, 4, 10, 3}, |
| 7354 | {3, 484, 4, 10, 3}, |
| 7355 | {4, 485, 4, 10, 3}, |
| 7356 | {5, 486, 4, 10, 3}, |
| 7357 | {6, 487, 4, 10, 3}, |
| 7358 | {7, 488, 4, 10, 3}, |
| 7359 | {8, 489, 4, 10, 3}, |
| 7360 | {9, 490, 4, 10, 3}, |
| 7361 | {10, 491, 4, 10, 3}, |
| 7362 | {11, 492, 4, 10, 3}, |
| 7363 | {12, 493, 4, 10, 3}, |
| 7364 | {13, 494, 4, 10, 3}, |
| 7365 | {14, 496, 8, 10, 3}, |
| 7366 | {36, 172, 8, 12, 1}, |
| 7367 | {38, 173, 0, 12, 1}, |
| 7368 | {40, 173, 4, 12, 1}, |
| 7369 | {42, 173, 8, 12, 1}, |
| 7370 | {44, 174, 0, 12, 1}, |
| 7371 | {46, 174, 4, 12, 1}, |
| 7372 | {48, 174, 8, 12, 1}, |
| 7373 | {50, 175, 0, 12, 1}, |
| 7374 | {52, 175, 4, 12, 1}, |
| 7375 | {54, 175, 8, 12, 1}, |
| 7376 | {56, 176, 0, 12, 1}, |
| 7377 | {58, 176, 4, 12, 1}, |
| 7378 | {60, 176, 8, 12, 1}, |
| 7379 | {62, 177, 0, 12, 1}, |
| 7380 | {64, 177, 4, 12, 1}, |
| 7381 | {100, 183, 4, 12, 1}, |
| 7382 | {102, 183, 8, 12, 1}, |
| 7383 | {104, 184, 0, 12, 1}, |
| 7384 | {106, 184, 4, 12, 1}, |
| 7385 | {108, 184, 8, 12, 1}, |
| 7386 | {110, 185, 0, 12, 1}, |
| 7387 | {112, 185, 4, 12, 1}, |
| 7388 | {114, 185, 8, 12, 1}, |
| 7389 | {116, 186, 0, 12, 1}, |
| 7390 | {118, 186, 4, 12, 1}, |
| 7391 | {120, 186, 8, 12, 1}, |
| 7392 | {122, 187, 0, 12, 1}, |
| 7393 | {124, 187, 4, 12, 1}, |
| 7394 | {126, 187, 8, 12, 1}, |
| 7395 | {128, 188, 0, 12, 1}, |
| 7396 | {130, 188, 4, 12, 1}, |
| 7397 | {132, 188, 8, 12, 1}, |
| 7398 | {134, 189, 0, 12, 1}, |
| 7399 | {136, 189, 4, 12, 1}, |
| 7400 | {138, 189, 8, 12, 1}, |
| 7401 | {140, 190, 0, 12, 1}, |
| 7402 | {149, 191, 6, 12, 1}, |
| 7403 | {151, 191, 10, 12, 1}, |
| 7404 | {153, 192, 2, 12, 1}, |
| 7405 | {155, 192, 6, 12, 1}, |
| 7406 | {157, 192, 10, 12, 1}, |
| 7407 | {159, 193, 2, 12, 1}, |
| 7408 | {161, 193, 6, 12, 1}, |
| 7409 | {165, 194, 2, 12, 1}, |
| 7410 | {184, 164, 0, 12, 1}, |
| 7411 | {188, 164, 4, 12, 1}, |
| 7412 | {192, 165, 8, 12, 1}, |
| 7413 | {196, 166, 0, 12, 1}, |
| 7414 | }; |
| 7415 | |
| 7416 | static const struct rf_channel rf_vals_5592_xtal40[] = { |
| 7417 | /* Channel, N, K, mod, R */ |
| 7418 | {1, 241, 2, 10, 3}, |
| 7419 | {2, 241, 7, 10, 3}, |
| 7420 | {3, 242, 2, 10, 3}, |
| 7421 | {4, 242, 7, 10, 3}, |
| 7422 | {5, 243, 2, 10, 3}, |
| 7423 | {6, 243, 7, 10, 3}, |
| 7424 | {7, 244, 2, 10, 3}, |
| 7425 | {8, 244, 7, 10, 3}, |
| 7426 | {9, 245, 2, 10, 3}, |
| 7427 | {10, 245, 7, 10, 3}, |
| 7428 | {11, 246, 2, 10, 3}, |
| 7429 | {12, 246, 7, 10, 3}, |
| 7430 | {13, 247, 2, 10, 3}, |
| 7431 | {14, 248, 4, 10, 3}, |
| 7432 | {36, 86, 4, 12, 1}, |
| 7433 | {38, 86, 6, 12, 1}, |
| 7434 | {40, 86, 8, 12, 1}, |
| 7435 | {42, 86, 10, 12, 1}, |
| 7436 | {44, 87, 0, 12, 1}, |
| 7437 | {46, 87, 2, 12, 1}, |
| 7438 | {48, 87, 4, 12, 1}, |
| 7439 | {50, 87, 6, 12, 1}, |
| 7440 | {52, 87, 8, 12, 1}, |
| 7441 | {54, 87, 10, 12, 1}, |
| 7442 | {56, 88, 0, 12, 1}, |
| 7443 | {58, 88, 2, 12, 1}, |
| 7444 | {60, 88, 4, 12, 1}, |
| 7445 | {62, 88, 6, 12, 1}, |
| 7446 | {64, 88, 8, 12, 1}, |
| 7447 | {100, 91, 8, 12, 1}, |
| 7448 | {102, 91, 10, 12, 1}, |
| 7449 | {104, 92, 0, 12, 1}, |
| 7450 | {106, 92, 2, 12, 1}, |
| 7451 | {108, 92, 4, 12, 1}, |
| 7452 | {110, 92, 6, 12, 1}, |
| 7453 | {112, 92, 8, 12, 1}, |
| 7454 | {114, 92, 10, 12, 1}, |
| 7455 | {116, 93, 0, 12, 1}, |
| 7456 | {118, 93, 2, 12, 1}, |
| 7457 | {120, 93, 4, 12, 1}, |
| 7458 | {122, 93, 6, 12, 1}, |
| 7459 | {124, 93, 8, 12, 1}, |
| 7460 | {126, 93, 10, 12, 1}, |
| 7461 | {128, 94, 0, 12, 1}, |
| 7462 | {130, 94, 2, 12, 1}, |
| 7463 | {132, 94, 4, 12, 1}, |
| 7464 | {134, 94, 6, 12, 1}, |
| 7465 | {136, 94, 8, 12, 1}, |
| 7466 | {138, 94, 10, 12, 1}, |
| 7467 | {140, 95, 0, 12, 1}, |
| 7468 | {149, 95, 9, 12, 1}, |
| 7469 | {151, 95, 11, 12, 1}, |
| 7470 | {153, 96, 1, 12, 1}, |
| 7471 | {155, 96, 3, 12, 1}, |
| 7472 | {157, 96, 5, 12, 1}, |
| 7473 | {159, 96, 7, 12, 1}, |
| 7474 | {161, 96, 9, 12, 1}, |
| 7475 | {165, 97, 1, 12, 1}, |
| 7476 | {184, 82, 0, 12, 1}, |
| 7477 | {188, 82, 4, 12, 1}, |
| 7478 | {192, 82, 8, 12, 1}, |
| 7479 | {196, 83, 0, 12, 1}, |
| 7480 | }; |
| 7481 | |
Gertjan van Wingerde | ad417a5 | 2012-09-03 03:25:51 +0200 | [diff] [blame] | 7482 | static int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev) |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7483 | { |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7484 | struct hw_mode_spec *spec = &rt2x00dev->spec; |
| 7485 | struct channel_info *info; |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 7486 | char *default_power1; |
| 7487 | char *default_power2; |
Gabor Juhos | c0a1436 | 2013-07-08 16:08:28 +0200 | [diff] [blame] | 7488 | char *default_power3; |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7489 | unsigned int i; |
Stanislaw Gruszka | 7848b23 | 2013-03-16 19:19:31 +0100 | [diff] [blame] | 7490 | u32 reg; |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7491 | |
| 7492 | /* |
Stanislaw Gruszka | 58e33a2 | 2014-01-29 17:42:37 +0100 | [diff] [blame] | 7493 | * Disable powersaving as default. |
Gertjan van Wingerde | 93b6bd2 | 2009-12-14 20:33:55 +0100 | [diff] [blame] | 7494 | */ |
Stanislaw Gruszka | 58e33a2 | 2014-01-29 17:42:37 +0100 | [diff] [blame] | 7495 | rt2x00dev->hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; |
Gertjan van Wingerde | 93b6bd2 | 2009-12-14 20:33:55 +0100 | [diff] [blame] | 7496 | |
| 7497 | /* |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7498 | * Initialize all hw fields. |
| 7499 | */ |
| 7500 | rt2x00dev->hw->flags = |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7501 | IEEE80211_HW_SIGNAL_DBM | |
| 7502 | IEEE80211_HW_SUPPORTS_PS | |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 7503 | IEEE80211_HW_PS_NULLFUNC_STACK | |
Helmut Schaa | 9d4f09b | 2012-03-14 08:56:47 +0100 | [diff] [blame] | 7504 | IEEE80211_HW_AMPDU_AGGREGATION | |
Felix Fietkau | 2dfca31 | 2013-08-20 19:43:54 +0200 | [diff] [blame] | 7505 | IEEE80211_HW_REPORTS_TX_ACK_STATUS | |
| 7506 | IEEE80211_HW_SUPPORTS_HT_CCK_RATES; |
Helmut Schaa | 9d4f09b | 2012-03-14 08:56:47 +0100 | [diff] [blame] | 7507 | |
Helmut Schaa | 5a5b6ed | 2010-10-02 11:31:33 +0200 | [diff] [blame] | 7508 | /* |
| 7509 | * Don't set IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING for USB devices |
| 7510 | * unless we are capable of sending the buffered frames out after the |
| 7511 | * DTIM transmission using rt2x00lib_beacondone. This will send out |
| 7512 | * multicast and broadcast traffic immediately instead of buffering it |
| 7513 | * infinitly and thus dropping it after some time. |
| 7514 | */ |
| 7515 | if (!rt2x00_is_usb(rt2x00dev)) |
| 7516 | rt2x00dev->hw->flags |= |
| 7517 | IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING; |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7518 | |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7519 | SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev); |
| 7520 | SET_IEEE80211_PERM_ADDR(rt2x00dev->hw, |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 7521 | rt2800_eeprom_addr(rt2x00dev, |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7522 | EEPROM_MAC_ADDR_0)); |
| 7523 | |
Helmut Schaa | 3f2bee2 | 2010-06-14 22:12:01 +0200 | [diff] [blame] | 7524 | /* |
| 7525 | * As rt2800 has a global fallback table we cannot specify |
| 7526 | * more then one tx rate per frame but since the hw will |
| 7527 | * try several rates (based on the fallback table) we should |
Helmut Schaa | ba3b9e5 | 2010-10-02 11:32:16 +0200 | [diff] [blame] | 7528 | * initialize max_report_rates to the maximum number of rates |
Helmut Schaa | 3f2bee2 | 2010-06-14 22:12:01 +0200 | [diff] [blame] | 7529 | * we are going to try. Otherwise mac80211 will truncate our |
| 7530 | * reported tx rates and the rc algortihm will end up with |
| 7531 | * incorrect data. |
| 7532 | */ |
Helmut Schaa | ba3b9e5 | 2010-10-02 11:32:16 +0200 | [diff] [blame] | 7533 | rt2x00dev->hw->max_rates = 1; |
| 7534 | rt2x00dev->hw->max_report_rates = 7; |
Helmut Schaa | 3f2bee2 | 2010-06-14 22:12:01 +0200 | [diff] [blame] | 7535 | rt2x00dev->hw->max_rate_tries = 1; |
| 7536 | |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7537 | /* |
| 7538 | * Initialize hw_mode information. |
| 7539 | */ |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7540 | spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM; |
| 7541 | |
Gabor Juhos | 4a32c36 | 2013-10-14 21:59:51 +0200 | [diff] [blame] | 7542 | switch (rt2x00dev->chip.rf) { |
| 7543 | case RF2720: |
| 7544 | case RF2820: |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7545 | spec->num_channels = 14; |
| 7546 | spec->channels = rf_vals; |
Gabor Juhos | 4a32c36 | 2013-10-14 21:59:51 +0200 | [diff] [blame] | 7547 | break; |
| 7548 | |
| 7549 | case RF2750: |
| 7550 | case RF2850: |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7551 | spec->num_channels = ARRAY_SIZE(rf_vals); |
| 7552 | spec->channels = rf_vals; |
Gabor Juhos | 4a32c36 | 2013-10-14 21:59:51 +0200 | [diff] [blame] | 7553 | break; |
| 7554 | |
| 7555 | case RF2020: |
| 7556 | case RF3020: |
| 7557 | case RF3021: |
| 7558 | case RF3022: |
| 7559 | case RF3070: |
| 7560 | case RF3290: |
| 7561 | case RF3320: |
| 7562 | case RF3322: |
| 7563 | case RF5360: |
Canek Peláez Valdés | ac0372a | 2014-08-24 19:06:11 -0500 | [diff] [blame] | 7564 | case RF5362: |
Gabor Juhos | 4a32c36 | 2013-10-14 21:59:51 +0200 | [diff] [blame] | 7565 | case RF5370: |
| 7566 | case RF5372: |
| 7567 | case RF5390: |
| 7568 | case RF5392: |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 7569 | spec->num_channels = 14; |
| 7570 | spec->channels = rf_vals_3x; |
Gabor Juhos | 4a32c36 | 2013-10-14 21:59:51 +0200 | [diff] [blame] | 7571 | break; |
| 7572 | |
| 7573 | case RF3052: |
| 7574 | case RF3053: |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 7575 | spec->num_channels = ARRAY_SIZE(rf_vals_3x); |
| 7576 | spec->channels = rf_vals_3x; |
Gabor Juhos | 4a32c36 | 2013-10-14 21:59:51 +0200 | [diff] [blame] | 7577 | break; |
Stanislaw Gruszka | 7848b23 | 2013-03-16 19:19:31 +0100 | [diff] [blame] | 7578 | |
Gabor Juhos | 4a32c36 | 2013-10-14 21:59:51 +0200 | [diff] [blame] | 7579 | case RF5592: |
Stanislaw Gruszka | 7848b23 | 2013-03-16 19:19:31 +0100 | [diff] [blame] | 7580 | rt2800_register_read(rt2x00dev, MAC_DEBUG_INDEX, ®); |
| 7581 | if (rt2x00_get_field32(reg, MAC_DEBUG_INDEX_XTAL)) { |
| 7582 | spec->num_channels = ARRAY_SIZE(rf_vals_5592_xtal40); |
| 7583 | spec->channels = rf_vals_5592_xtal40; |
| 7584 | } else { |
| 7585 | spec->num_channels = ARRAY_SIZE(rf_vals_5592_xtal20); |
| 7586 | spec->channels = rf_vals_5592_xtal20; |
| 7587 | } |
Gabor Juhos | 4a32c36 | 2013-10-14 21:59:51 +0200 | [diff] [blame] | 7588 | break; |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7589 | } |
| 7590 | |
Stanislaw Gruszka | 53216d6 | 2013-03-16 19:19:29 +0100 | [diff] [blame] | 7591 | if (WARN_ON_ONCE(!spec->channels)) |
| 7592 | return -ENODEV; |
| 7593 | |
Gabor Juhos | 53c5a09 | 2013-10-14 21:59:52 +0200 | [diff] [blame] | 7594 | spec->supported_bands = SUPPORT_BAND_2GHZ; |
| 7595 | if (spec->num_channels > 14) |
| 7596 | spec->supported_bands |= SUPPORT_BAND_5GHZ; |
| 7597 | |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7598 | /* |
| 7599 | * Initialize HT information. |
| 7600 | */ |
Gertjan van Wingerde | 5122d89 | 2009-12-23 00:03:25 +0100 | [diff] [blame] | 7601 | if (!rt2x00_rf(rt2x00dev, RF2020)) |
Gertjan van Wingerde | 38a522e | 2009-11-23 22:44:47 +0100 | [diff] [blame] | 7602 | spec->ht.ht_supported = true; |
| 7603 | else |
| 7604 | spec->ht.ht_supported = false; |
| 7605 | |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7606 | spec->ht.cap = |
Gertjan van Wingerde | 06443e4 | 2010-06-03 10:52:08 +0200 | [diff] [blame] | 7607 | IEEE80211_HT_CAP_SUP_WIDTH_20_40 | |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7608 | IEEE80211_HT_CAP_GRN_FLD | |
| 7609 | IEEE80211_HT_CAP_SGI_20 | |
Ivo van Doorn | aa67463 | 2010-06-29 21:48:37 +0200 | [diff] [blame] | 7610 | IEEE80211_HT_CAP_SGI_40; |
Helmut Schaa | 22cabaa | 2010-06-03 10:52:10 +0200 | [diff] [blame] | 7611 | |
Gabor Juhos | aa10350 | 2013-10-14 21:59:50 +0200 | [diff] [blame] | 7612 | if (rt2x00dev->default_ant.tx_chain_num >= 2) |
Helmut Schaa | 22cabaa | 2010-06-03 10:52:10 +0200 | [diff] [blame] | 7613 | spec->ht.cap |= IEEE80211_HT_CAP_TX_STBC; |
| 7614 | |
Gabor Juhos | aa10350 | 2013-10-14 21:59:50 +0200 | [diff] [blame] | 7615 | spec->ht.cap |= rt2x00dev->default_ant.rx_chain_num << |
| 7616 | IEEE80211_HT_CAP_RX_STBC_SHIFT; |
Ivo van Doorn | aa67463 | 2010-06-29 21:48:37 +0200 | [diff] [blame] | 7617 | |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7618 | spec->ht.ampdu_factor = 3; |
| 7619 | spec->ht.ampdu_density = 4; |
| 7620 | spec->ht.mcs.tx_params = |
| 7621 | IEEE80211_HT_MCS_TX_DEFINED | |
| 7622 | IEEE80211_HT_MCS_TX_RX_DIFF | |
Gabor Juhos | aa10350 | 2013-10-14 21:59:50 +0200 | [diff] [blame] | 7623 | ((rt2x00dev->default_ant.tx_chain_num - 1) << |
| 7624 | IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT); |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7625 | |
Gabor Juhos | aa10350 | 2013-10-14 21:59:50 +0200 | [diff] [blame] | 7626 | switch (rt2x00dev->default_ant.rx_chain_num) { |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7627 | case 3: |
| 7628 | spec->ht.mcs.rx_mask[2] = 0xff; |
| 7629 | case 2: |
| 7630 | spec->ht.mcs.rx_mask[1] = 0xff; |
| 7631 | case 1: |
| 7632 | spec->ht.mcs.rx_mask[0] = 0xff; |
| 7633 | spec->ht.mcs.rx_mask[4] = 0x1; /* MCS32 */ |
| 7634 | break; |
| 7635 | } |
| 7636 | |
| 7637 | /* |
| 7638 | * Create channel information array |
| 7639 | */ |
Joe Perches | baeb2ff | 2010-08-11 07:02:48 +0000 | [diff] [blame] | 7640 | info = kcalloc(spec->num_channels, sizeof(*info), GFP_KERNEL); |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7641 | if (!info) |
| 7642 | return -ENOMEM; |
| 7643 | |
| 7644 | spec->channels_info = info; |
| 7645 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 7646 | default_power1 = rt2800_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG1); |
| 7647 | default_power2 = rt2800_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG2); |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7648 | |
Gabor Juhos | c0a1436 | 2013-07-08 16:08:28 +0200 | [diff] [blame] | 7649 | if (rt2x00dev->default_ant.tx_chain_num > 2) |
| 7650 | default_power3 = rt2800_eeprom_addr(rt2x00dev, |
| 7651 | EEPROM_EXT_TXPOWER_BG3); |
| 7652 | else |
| 7653 | default_power3 = NULL; |
| 7654 | |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7655 | for (i = 0; i < 14; i++) { |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 7656 | info[i].default_power1 = default_power1[i]; |
| 7657 | info[i].default_power2 = default_power2[i]; |
Gabor Juhos | c0a1436 | 2013-07-08 16:08:28 +0200 | [diff] [blame] | 7658 | if (default_power3) |
| 7659 | info[i].default_power3 = default_power3[i]; |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7660 | } |
| 7661 | |
| 7662 | if (spec->num_channels > 14) { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 7663 | default_power1 = rt2800_eeprom_addr(rt2x00dev, |
| 7664 | EEPROM_TXPOWER_A1); |
| 7665 | default_power2 = rt2800_eeprom_addr(rt2x00dev, |
| 7666 | EEPROM_TXPOWER_A2); |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7667 | |
Gabor Juhos | c0a1436 | 2013-07-08 16:08:28 +0200 | [diff] [blame] | 7668 | if (rt2x00dev->default_ant.tx_chain_num > 2) |
| 7669 | default_power3 = |
| 7670 | rt2800_eeprom_addr(rt2x00dev, |
| 7671 | EEPROM_EXT_TXPOWER_A3); |
| 7672 | else |
| 7673 | default_power3 = NULL; |
| 7674 | |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7675 | for (i = 14; i < spec->num_channels; i++) { |
Gabor Juhos | 0a6f3a8 | 2013-06-22 13:13:25 +0200 | [diff] [blame] | 7676 | info[i].default_power1 = default_power1[i - 14]; |
| 7677 | info[i].default_power2 = default_power2[i - 14]; |
Gabor Juhos | c0a1436 | 2013-07-08 16:08:28 +0200 | [diff] [blame] | 7678 | if (default_power3) |
| 7679 | info[i].default_power3 = default_power3[i - 14]; |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7680 | } |
| 7681 | } |
| 7682 | |
John Li | 2e9c43d | 2012-02-16 21:40:57 +0800 | [diff] [blame] | 7683 | switch (rt2x00dev->chip.rf) { |
| 7684 | case RF2020: |
| 7685 | case RF3020: |
| 7686 | case RF3021: |
| 7687 | case RF3022: |
| 7688 | case RF3320: |
| 7689 | case RF3052: |
Gabor Juhos | 1095df0 | 2013-07-08 16:08:31 +0200 | [diff] [blame] | 7690 | case RF3053: |
Stanislaw Gruszka | 3b9b74b | 2013-09-25 15:34:55 +0200 | [diff] [blame] | 7691 | case RF3070: |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 7692 | case RF3290: |
villacis@palosanto.com | ccf91bd | 2012-05-16 21:07:12 +0200 | [diff] [blame] | 7693 | case RF5360: |
Canek Peláez Valdés | ac0372a | 2014-08-24 19:06:11 -0500 | [diff] [blame] | 7694 | case RF5362: |
John Li | 2e9c43d | 2012-02-16 21:40:57 +0800 | [diff] [blame] | 7695 | case RF5370: |
| 7696 | case RF5372: |
| 7697 | case RF5390: |
Zero.Lin | cff3d1f | 2012-05-29 16:11:09 +0800 | [diff] [blame] | 7698 | case RF5392: |
John Li | 2e9c43d | 2012-02-16 21:40:57 +0800 | [diff] [blame] | 7699 | __set_bit(CAPABILITY_VCO_RECALIBRATION, &rt2x00dev->cap_flags); |
| 7700 | break; |
| 7701 | } |
| 7702 | |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7703 | return 0; |
| 7704 | } |
Gertjan van Wingerde | ad417a5 | 2012-09-03 03:25:51 +0200 | [diff] [blame] | 7705 | |
Gabor Juhos | cbafb60 | 2013-03-30 14:53:10 +0100 | [diff] [blame] | 7706 | static int rt2800_probe_rt(struct rt2x00_dev *rt2x00dev) |
| 7707 | { |
| 7708 | u32 reg; |
| 7709 | u32 rt; |
| 7710 | u32 rev; |
| 7711 | |
| 7712 | if (rt2x00_rt(rt2x00dev, RT3290)) |
| 7713 | rt2800_register_read(rt2x00dev, MAC_CSR0_3290, ®); |
| 7714 | else |
| 7715 | rt2800_register_read(rt2x00dev, MAC_CSR0, ®); |
| 7716 | |
| 7717 | rt = rt2x00_get_field32(reg, MAC_CSR0_CHIPSET); |
| 7718 | rev = rt2x00_get_field32(reg, MAC_CSR0_REVISION); |
| 7719 | |
| 7720 | switch (rt) { |
| 7721 | case RT2860: |
| 7722 | case RT2872: |
| 7723 | case RT2883: |
| 7724 | case RT3070: |
| 7725 | case RT3071: |
| 7726 | case RT3090: |
| 7727 | case RT3290: |
| 7728 | case RT3352: |
| 7729 | case RT3390: |
| 7730 | case RT3572: |
Gabor Juhos | 2dc2bd2 | 2013-07-08 16:08:33 +0200 | [diff] [blame] | 7731 | case RT3593: |
Gabor Juhos | cbafb60 | 2013-03-30 14:53:10 +0100 | [diff] [blame] | 7732 | case RT5390: |
| 7733 | case RT5392: |
| 7734 | case RT5592: |
| 7735 | break; |
| 7736 | default: |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 7737 | rt2x00_err(rt2x00dev, "Invalid RT chipset 0x%04x, rev %04x detected\n", |
| 7738 | rt, rev); |
Gabor Juhos | cbafb60 | 2013-03-30 14:53:10 +0100 | [diff] [blame] | 7739 | return -ENODEV; |
| 7740 | } |
| 7741 | |
| 7742 | rt2x00_set_rt(rt2x00dev, rt, rev); |
| 7743 | |
| 7744 | return 0; |
| 7745 | } |
| 7746 | |
Gertjan van Wingerde | ad417a5 | 2012-09-03 03:25:51 +0200 | [diff] [blame] | 7747 | int rt2800_probe_hw(struct rt2x00_dev *rt2x00dev) |
| 7748 | { |
| 7749 | int retval; |
| 7750 | u32 reg; |
| 7751 | |
Gabor Juhos | cbafb60 | 2013-03-30 14:53:10 +0100 | [diff] [blame] | 7752 | retval = rt2800_probe_rt(rt2x00dev); |
| 7753 | if (retval) |
| 7754 | return retval; |
| 7755 | |
Gertjan van Wingerde | ad417a5 | 2012-09-03 03:25:51 +0200 | [diff] [blame] | 7756 | /* |
| 7757 | * Allocate eeprom data. |
| 7758 | */ |
| 7759 | retval = rt2800_validate_eeprom(rt2x00dev); |
| 7760 | if (retval) |
| 7761 | return retval; |
| 7762 | |
| 7763 | retval = rt2800_init_eeprom(rt2x00dev); |
| 7764 | if (retval) |
| 7765 | return retval; |
| 7766 | |
| 7767 | /* |
| 7768 | * Enable rfkill polling by setting GPIO direction of the |
| 7769 | * rfkill switch GPIO pin correctly. |
| 7770 | */ |
| 7771 | rt2800_register_read(rt2x00dev, GPIO_CTRL, ®); |
| 7772 | rt2x00_set_field32(®, GPIO_CTRL_DIR2, 1); |
| 7773 | rt2800_register_write(rt2x00dev, GPIO_CTRL, reg); |
| 7774 | |
| 7775 | /* |
| 7776 | * Initialize hw specifications. |
| 7777 | */ |
| 7778 | retval = rt2800_probe_hw_mode(rt2x00dev); |
| 7779 | if (retval) |
| 7780 | return retval; |
| 7781 | |
| 7782 | /* |
| 7783 | * Set device capabilities. |
| 7784 | */ |
| 7785 | __set_bit(CAPABILITY_CONTROL_FILTERS, &rt2x00dev->cap_flags); |
| 7786 | __set_bit(CAPABILITY_CONTROL_FILTER_PSPOLL, &rt2x00dev->cap_flags); |
| 7787 | if (!rt2x00_is_usb(rt2x00dev)) |
| 7788 | __set_bit(CAPABILITY_PRE_TBTT_INTERRUPT, &rt2x00dev->cap_flags); |
| 7789 | |
| 7790 | /* |
| 7791 | * Set device requirements. |
| 7792 | */ |
| 7793 | if (!rt2x00_is_soc(rt2x00dev)) |
| 7794 | __set_bit(REQUIRE_FIRMWARE, &rt2x00dev->cap_flags); |
| 7795 | __set_bit(REQUIRE_L2PAD, &rt2x00dev->cap_flags); |
| 7796 | __set_bit(REQUIRE_TXSTATUS_FIFO, &rt2x00dev->cap_flags); |
| 7797 | if (!rt2800_hwcrypt_disabled(rt2x00dev)) |
| 7798 | __set_bit(CAPABILITY_HW_CRYPTO, &rt2x00dev->cap_flags); |
| 7799 | __set_bit(CAPABILITY_LINK_TUNING, &rt2x00dev->cap_flags); |
| 7800 | __set_bit(REQUIRE_HT_TX_DESC, &rt2x00dev->cap_flags); |
| 7801 | if (rt2x00_is_usb(rt2x00dev)) |
| 7802 | __set_bit(REQUIRE_PS_AUTOWAKE, &rt2x00dev->cap_flags); |
| 7803 | else { |
| 7804 | __set_bit(REQUIRE_DMA, &rt2x00dev->cap_flags); |
| 7805 | __set_bit(REQUIRE_TASKLET_CONTEXT, &rt2x00dev->cap_flags); |
| 7806 | } |
| 7807 | |
| 7808 | /* |
| 7809 | * Set the rssi offset. |
| 7810 | */ |
| 7811 | rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET; |
| 7812 | |
| 7813 | return 0; |
| 7814 | } |
| 7815 | EXPORT_SYMBOL_GPL(rt2800_probe_hw); |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7816 | |
| 7817 | /* |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7818 | * IEEE80211 stack callback functions. |
| 7819 | */ |
Johannes Berg | 9352c19 | 2015-04-20 18:12:41 +0200 | [diff] [blame] | 7820 | void rt2800_get_key_seq(struct ieee80211_hw *hw, |
| 7821 | struct ieee80211_key_conf *key, |
| 7822 | struct ieee80211_key_seq *seq) |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7823 | { |
| 7824 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 7825 | struct mac_iveiv_entry iveiv_entry; |
| 7826 | u32 offset; |
| 7827 | |
Johannes Berg | 9352c19 | 2015-04-20 18:12:41 +0200 | [diff] [blame] | 7828 | if (key->cipher != WLAN_CIPHER_SUITE_TKIP) |
| 7829 | return; |
| 7830 | |
| 7831 | offset = MAC_IVEIV_ENTRY(key->hw_key_idx); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7832 | rt2800_register_multiread(rt2x00dev, offset, |
| 7833 | &iveiv_entry, sizeof(iveiv_entry)); |
| 7834 | |
Johannes Berg | 9352c19 | 2015-04-20 18:12:41 +0200 | [diff] [blame] | 7835 | memcpy(&seq->tkip.iv16, &iveiv_entry.iv[0], 2); |
| 7836 | memcpy(&seq->tkip.iv32, &iveiv_entry.iv[4], 4); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7837 | } |
Johannes Berg | 9352c19 | 2015-04-20 18:12:41 +0200 | [diff] [blame] | 7838 | EXPORT_SYMBOL_GPL(rt2800_get_key_seq); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7839 | |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 7840 | int rt2800_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7841 | { |
| 7842 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 7843 | u32 reg; |
| 7844 | bool enabled = (value < IEEE80211_MAX_RTS_THRESHOLD); |
| 7845 | |
| 7846 | rt2800_register_read(rt2x00dev, TX_RTS_CFG, ®); |
| 7847 | rt2x00_set_field32(®, TX_RTS_CFG_RTS_THRES, value); |
| 7848 | rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg); |
| 7849 | |
| 7850 | rt2800_register_read(rt2x00dev, CCK_PROT_CFG, ®); |
| 7851 | rt2x00_set_field32(®, CCK_PROT_CFG_RTS_TH_EN, enabled); |
| 7852 | rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg); |
| 7853 | |
| 7854 | rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, ®); |
| 7855 | rt2x00_set_field32(®, OFDM_PROT_CFG_RTS_TH_EN, enabled); |
| 7856 | rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg); |
| 7857 | |
| 7858 | rt2800_register_read(rt2x00dev, MM20_PROT_CFG, ®); |
| 7859 | rt2x00_set_field32(®, MM20_PROT_CFG_RTS_TH_EN, enabled); |
| 7860 | rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg); |
| 7861 | |
| 7862 | rt2800_register_read(rt2x00dev, MM40_PROT_CFG, ®); |
| 7863 | rt2x00_set_field32(®, MM40_PROT_CFG_RTS_TH_EN, enabled); |
| 7864 | rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg); |
| 7865 | |
| 7866 | rt2800_register_read(rt2x00dev, GF20_PROT_CFG, ®); |
| 7867 | rt2x00_set_field32(®, GF20_PROT_CFG_RTS_TH_EN, enabled); |
| 7868 | rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg); |
| 7869 | |
| 7870 | rt2800_register_read(rt2x00dev, GF40_PROT_CFG, ®); |
| 7871 | rt2x00_set_field32(®, GF40_PROT_CFG_RTS_TH_EN, enabled); |
| 7872 | rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg); |
| 7873 | |
| 7874 | return 0; |
| 7875 | } |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 7876 | EXPORT_SYMBOL_GPL(rt2800_set_rts_threshold); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7877 | |
Eliad Peller | 8a3a3c8 | 2011-10-02 10:15:52 +0200 | [diff] [blame] | 7878 | int rt2800_conf_tx(struct ieee80211_hw *hw, |
| 7879 | struct ieee80211_vif *vif, u16 queue_idx, |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 7880 | const struct ieee80211_tx_queue_params *params) |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7881 | { |
| 7882 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 7883 | struct data_queue *queue; |
| 7884 | struct rt2x00_field32 field; |
| 7885 | int retval; |
| 7886 | u32 reg; |
| 7887 | u32 offset; |
| 7888 | |
| 7889 | /* |
| 7890 | * First pass the configuration through rt2x00lib, that will |
| 7891 | * update the queue settings and validate the input. After that |
| 7892 | * we are free to update the registers based on the value |
| 7893 | * in the queue parameter. |
| 7894 | */ |
Eliad Peller | 8a3a3c8 | 2011-10-02 10:15:52 +0200 | [diff] [blame] | 7895 | retval = rt2x00mac_conf_tx(hw, vif, queue_idx, params); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7896 | if (retval) |
| 7897 | return retval; |
| 7898 | |
| 7899 | /* |
| 7900 | * We only need to perform additional register initialization |
| 7901 | * for WMM queues/ |
| 7902 | */ |
| 7903 | if (queue_idx >= 4) |
| 7904 | return 0; |
| 7905 | |
Helmut Schaa | 11f818e | 2011-03-03 19:38:55 +0100 | [diff] [blame] | 7906 | queue = rt2x00queue_get_tx_queue(rt2x00dev, queue_idx); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7907 | |
| 7908 | /* Update WMM TXOP register */ |
| 7909 | offset = WMM_TXOP0_CFG + (sizeof(u32) * (!!(queue_idx & 2))); |
| 7910 | field.bit_offset = (queue_idx & 1) * 16; |
| 7911 | field.bit_mask = 0xffff << field.bit_offset; |
| 7912 | |
| 7913 | rt2800_register_read(rt2x00dev, offset, ®); |
| 7914 | rt2x00_set_field32(®, field, queue->txop); |
| 7915 | rt2800_register_write(rt2x00dev, offset, reg); |
| 7916 | |
| 7917 | /* Update WMM registers */ |
| 7918 | field.bit_offset = queue_idx * 4; |
| 7919 | field.bit_mask = 0xf << field.bit_offset; |
| 7920 | |
| 7921 | rt2800_register_read(rt2x00dev, WMM_AIFSN_CFG, ®); |
| 7922 | rt2x00_set_field32(®, field, queue->aifs); |
| 7923 | rt2800_register_write(rt2x00dev, WMM_AIFSN_CFG, reg); |
| 7924 | |
| 7925 | rt2800_register_read(rt2x00dev, WMM_CWMIN_CFG, ®); |
| 7926 | rt2x00_set_field32(®, field, queue->cw_min); |
| 7927 | rt2800_register_write(rt2x00dev, WMM_CWMIN_CFG, reg); |
| 7928 | |
| 7929 | rt2800_register_read(rt2x00dev, WMM_CWMAX_CFG, ®); |
| 7930 | rt2x00_set_field32(®, field, queue->cw_max); |
| 7931 | rt2800_register_write(rt2x00dev, WMM_CWMAX_CFG, reg); |
| 7932 | |
| 7933 | /* Update EDCA registers */ |
| 7934 | offset = EDCA_AC0_CFG + (sizeof(u32) * queue_idx); |
| 7935 | |
| 7936 | rt2800_register_read(rt2x00dev, offset, ®); |
| 7937 | rt2x00_set_field32(®, EDCA_AC0_CFG_TX_OP, queue->txop); |
| 7938 | rt2x00_set_field32(®, EDCA_AC0_CFG_AIFSN, queue->aifs); |
| 7939 | rt2x00_set_field32(®, EDCA_AC0_CFG_CWMIN, queue->cw_min); |
| 7940 | rt2x00_set_field32(®, EDCA_AC0_CFG_CWMAX, queue->cw_max); |
| 7941 | rt2800_register_write(rt2x00dev, offset, reg); |
| 7942 | |
| 7943 | return 0; |
| 7944 | } |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 7945 | EXPORT_SYMBOL_GPL(rt2800_conf_tx); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7946 | |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 7947 | u64 rt2800_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7948 | { |
| 7949 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 7950 | u64 tsf; |
| 7951 | u32 reg; |
| 7952 | |
| 7953 | rt2800_register_read(rt2x00dev, TSF_TIMER_DW1, ®); |
| 7954 | tsf = (u64) rt2x00_get_field32(reg, TSF_TIMER_DW1_HIGH_WORD) << 32; |
| 7955 | rt2800_register_read(rt2x00dev, TSF_TIMER_DW0, ®); |
| 7956 | tsf |= rt2x00_get_field32(reg, TSF_TIMER_DW0_LOW_WORD); |
| 7957 | |
| 7958 | return tsf; |
| 7959 | } |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 7960 | EXPORT_SYMBOL_GPL(rt2800_get_tsf); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7961 | |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 7962 | int rt2800_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 7963 | enum ieee80211_ampdu_mlme_action action, |
Johannes Berg | 0b01f03 | 2011-01-18 13:51:05 +0100 | [diff] [blame] | 7964 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, |
| 7965 | u8 buf_size) |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 7966 | { |
Helmut Schaa | af35323 | 2011-09-08 14:38:36 +0200 | [diff] [blame] | 7967 | struct rt2x00_sta *sta_priv = (struct rt2x00_sta *)sta->drv_priv; |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 7968 | int ret = 0; |
| 7969 | |
Helmut Schaa | af35323 | 2011-09-08 14:38:36 +0200 | [diff] [blame] | 7970 | /* |
| 7971 | * Don't allow aggregation for stations the hardware isn't aware |
| 7972 | * of because tx status reports for frames to an unknown station |
| 7973 | * always contain wcid=255 and thus we can't distinguish between |
| 7974 | * multiple stations which leads to unwanted situations when the |
| 7975 | * hw reorders frames due to aggregation. |
| 7976 | */ |
| 7977 | if (sta_priv->wcid < 0) |
| 7978 | return 1; |
| 7979 | |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 7980 | switch (action) { |
| 7981 | case IEEE80211_AMPDU_RX_START: |
| 7982 | case IEEE80211_AMPDU_RX_STOP: |
Helmut Schaa | 58ed826 | 2010-10-02 11:33:17 +0200 | [diff] [blame] | 7983 | /* |
| 7984 | * The hw itself takes care of setting up BlockAck mechanisms. |
| 7985 | * So, we only have to allow mac80211 to nagotiate a BlockAck |
| 7986 | * agreement. Once that is done, the hw will BlockAck incoming |
| 7987 | * AMPDUs without further setup. |
| 7988 | */ |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 7989 | break; |
| 7990 | case IEEE80211_AMPDU_TX_START: |
| 7991 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 7992 | break; |
Johannes Berg | 18b559d | 2012-07-18 13:51:25 +0200 | [diff] [blame] | 7993 | case IEEE80211_AMPDU_TX_STOP_CONT: |
| 7994 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 7995 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 7996 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 7997 | break; |
| 7998 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 7999 | break; |
| 8000 | default: |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 8001 | rt2x00_warn((struct rt2x00_dev *)hw->priv, |
| 8002 | "Unknown AMPDU action\n"); |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 8003 | } |
| 8004 | |
| 8005 | return ret; |
| 8006 | } |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 8007 | EXPORT_SYMBOL_GPL(rt2800_ampdu_action); |
Ivo van Doorn | a5ea2f0 | 2010-06-14 22:13:15 +0200 | [diff] [blame] | 8008 | |
Helmut Schaa | 977206d | 2010-12-13 12:31:58 +0100 | [diff] [blame] | 8009 | int rt2800_get_survey(struct ieee80211_hw *hw, int idx, |
| 8010 | struct survey_info *survey) |
| 8011 | { |
| 8012 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 8013 | struct ieee80211_conf *conf = &hw->conf; |
| 8014 | u32 idle, busy, busy_ext; |
| 8015 | |
| 8016 | if (idx != 0) |
| 8017 | return -ENOENT; |
| 8018 | |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 8019 | survey->channel = conf->chandef.chan; |
Helmut Schaa | 977206d | 2010-12-13 12:31:58 +0100 | [diff] [blame] | 8020 | |
| 8021 | rt2800_register_read(rt2x00dev, CH_IDLE_STA, &idle); |
| 8022 | rt2800_register_read(rt2x00dev, CH_BUSY_STA, &busy); |
| 8023 | rt2800_register_read(rt2x00dev, CH_BUSY_STA_SEC, &busy_ext); |
| 8024 | |
| 8025 | if (idle || busy) { |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 8026 | survey->filled = SURVEY_INFO_TIME | |
| 8027 | SURVEY_INFO_TIME_BUSY | |
| 8028 | SURVEY_INFO_TIME_EXT_BUSY; |
Helmut Schaa | 977206d | 2010-12-13 12:31:58 +0100 | [diff] [blame] | 8029 | |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 8030 | survey->time = (idle + busy) / 1000; |
| 8031 | survey->time_busy = busy / 1000; |
| 8032 | survey->time_ext_busy = busy_ext / 1000; |
Helmut Schaa | 977206d | 2010-12-13 12:31:58 +0100 | [diff] [blame] | 8033 | } |
| 8034 | |
Helmut Schaa | 9931df2 | 2011-12-22 09:36:29 +0100 | [diff] [blame] | 8035 | if (!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) |
| 8036 | survey->filled |= SURVEY_INFO_IN_USE; |
| 8037 | |
Helmut Schaa | 977206d | 2010-12-13 12:31:58 +0100 | [diff] [blame] | 8038 | return 0; |
| 8039 | |
| 8040 | } |
| 8041 | EXPORT_SYMBOL_GPL(rt2800_get_survey); |
| 8042 | |
Ivo van Doorn | a5ea2f0 | 2010-06-14 22:13:15 +0200 | [diff] [blame] | 8043 | MODULE_AUTHOR(DRV_PROJECT ", Bartlomiej Zolnierkiewicz"); |
| 8044 | MODULE_VERSION(DRV_VERSION); |
| 8045 | MODULE_DESCRIPTION("Ralink RT2800 library"); |
| 8046 | MODULE_LICENSE("GPL"); |