Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 1 | /* |
Ivo van Doorn | 96481b2 | 2010-08-06 20:47:57 +0200 | [diff] [blame] | 2 | Copyright (C) 2010 Willow Garage <http://www.willowgarage.com> |
Ivo van Doorn | a5ea2f0 | 2010-06-14 22:13:15 +0200 | [diff] [blame] | 3 | Copyright (C) 2010 Ivo van Doorn <IvDoorn@gmail.com> |
Gertjan van Wingerde | 9c9a0d1 | 2009-11-08 16:39:55 +0100 | [diff] [blame] | 4 | Copyright (C) 2009 Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> |
Gertjan van Wingerde | cce5fc4 | 2009-11-10 22:42:40 +0100 | [diff] [blame] | 5 | Copyright (C) 2009 Gertjan van Wingerde <gwingerde@gmail.com> |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 6 | |
Gertjan van Wingerde | 9c9a0d1 | 2009-11-08 16:39:55 +0100 | [diff] [blame] | 7 | Based on the original rt2800pci.c and rt2800usb.c. |
Gertjan van Wingerde | 9c9a0d1 | 2009-11-08 16:39:55 +0100 | [diff] [blame] | 8 | Copyright (C) 2009 Alban Browaeys <prahal@yahoo.com> |
| 9 | Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org> |
| 10 | Copyright (C) 2009 Luis Correia <luis.f.correia@gmail.com> |
| 11 | Copyright (C) 2009 Mattias Nissler <mattias.nissler@gmx.de> |
| 12 | Copyright (C) 2009 Mark Asselstine <asselsm@gmail.com> |
| 13 | Copyright (C) 2009 Xose Vazquez Perez <xose.vazquez@gmail.com> |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 14 | <http://rt2x00.serialmonkey.com> |
| 15 | |
| 16 | This program is free software; you can redistribute it and/or modify |
| 17 | it under the terms of the GNU General Public License as published by |
| 18 | the Free Software Foundation; either version 2 of the License, or |
| 19 | (at your option) any later version. |
| 20 | |
| 21 | This program is distributed in the hope that it will be useful, |
| 22 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | GNU General Public License for more details. |
| 25 | |
| 26 | You should have received a copy of the GNU General Public License |
| 27 | along with this program; if not, write to the |
| 28 | Free Software Foundation, Inc., |
| 29 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 30 | */ |
| 31 | |
| 32 | /* |
| 33 | Module: rt2800lib |
| 34 | Abstract: rt2800 generic device routines. |
| 35 | */ |
| 36 | |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 37 | #include <linux/crc-ccitt.h> |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 38 | #include <linux/kernel.h> |
| 39 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 40 | #include <linux/slab.h> |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 41 | |
| 42 | #include "rt2x00.h" |
| 43 | #include "rt2800lib.h" |
| 44 | #include "rt2800.h" |
| 45 | |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 46 | /* |
| 47 | * Register access. |
| 48 | * All access to the CSR registers will go through the methods |
| 49 | * rt2800_register_read and rt2800_register_write. |
| 50 | * BBP and RF register require indirect register access, |
| 51 | * and use the CSR registers BBPCSR and RFCSR to achieve this. |
| 52 | * These indirect registers work with busy bits, |
| 53 | * and we will try maximal REGISTER_BUSY_COUNT times to access |
| 54 | * the register while taking a REGISTER_BUSY_DELAY us delay |
| 55 | * between each attampt. When the busy bit is still set at that time, |
| 56 | * the access attempt is considered to have failed, |
| 57 | * and we will print an error. |
| 58 | * The _lock versions must be used if you already hold the csr_mutex |
| 59 | */ |
| 60 | #define WAIT_FOR_BBP(__dev, __reg) \ |
| 61 | rt2800_regbusy_read((__dev), BBP_CSR_CFG, BBP_CSR_CFG_BUSY, (__reg)) |
| 62 | #define WAIT_FOR_RFCSR(__dev, __reg) \ |
| 63 | rt2800_regbusy_read((__dev), RF_CSR_CFG, RF_CSR_CFG_BUSY, (__reg)) |
| 64 | #define WAIT_FOR_RF(__dev, __reg) \ |
| 65 | rt2800_regbusy_read((__dev), RF_CSR_CFG0, RF_CSR_CFG0_BUSY, (__reg)) |
| 66 | #define WAIT_FOR_MCU(__dev, __reg) \ |
| 67 | rt2800_regbusy_read((__dev), H2M_MAILBOX_CSR, \ |
| 68 | H2M_MAILBOX_CSR_OWNER, (__reg)) |
| 69 | |
Helmut Schaa | baff800 | 2010-04-28 09:58:59 +0200 | [diff] [blame] | 70 | static inline bool rt2800_is_305x_soc(struct rt2x00_dev *rt2x00dev) |
| 71 | { |
| 72 | /* check for rt2872 on SoC */ |
| 73 | if (!rt2x00_is_soc(rt2x00dev) || |
| 74 | !rt2x00_rt(rt2x00dev, RT2872)) |
| 75 | return false; |
| 76 | |
| 77 | /* we know for sure that these rf chipsets are used on rt305x boards */ |
| 78 | if (rt2x00_rf(rt2x00dev, RF3020) || |
| 79 | rt2x00_rf(rt2x00dev, RF3021) || |
| 80 | rt2x00_rf(rt2x00dev, RF3022)) |
| 81 | return true; |
| 82 | |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 83 | rt2x00_warn(rt2x00dev, "Unknown RF chipset on rt305x\n"); |
Helmut Schaa | baff800 | 2010-04-28 09:58:59 +0200 | [diff] [blame] | 84 | return false; |
| 85 | } |
| 86 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 87 | static void rt2800_bbp_write(struct rt2x00_dev *rt2x00dev, |
| 88 | const unsigned int word, const u8 value) |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 89 | { |
| 90 | u32 reg; |
| 91 | |
| 92 | mutex_lock(&rt2x00dev->csr_mutex); |
| 93 | |
| 94 | /* |
| 95 | * Wait until the BBP becomes available, afterwards we |
| 96 | * can safely write the new data into the register. |
| 97 | */ |
| 98 | if (WAIT_FOR_BBP(rt2x00dev, ®)) { |
| 99 | reg = 0; |
| 100 | rt2x00_set_field32(®, BBP_CSR_CFG_VALUE, value); |
| 101 | rt2x00_set_field32(®, BBP_CSR_CFG_REGNUM, word); |
| 102 | rt2x00_set_field32(®, BBP_CSR_CFG_BUSY, 1); |
| 103 | rt2x00_set_field32(®, BBP_CSR_CFG_READ_CONTROL, 0); |
Ivo van Doorn | efc7d36 | 2010-06-29 21:49:26 +0200 | [diff] [blame] | 104 | rt2x00_set_field32(®, BBP_CSR_CFG_BBP_RW_MODE, 1); |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 105 | |
| 106 | rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg); |
| 107 | } |
| 108 | |
| 109 | mutex_unlock(&rt2x00dev->csr_mutex); |
| 110 | } |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 111 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 112 | static void rt2800_bbp_read(struct rt2x00_dev *rt2x00dev, |
| 113 | const unsigned int word, u8 *value) |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 114 | { |
| 115 | u32 reg; |
| 116 | |
| 117 | mutex_lock(&rt2x00dev->csr_mutex); |
| 118 | |
| 119 | /* |
| 120 | * Wait until the BBP becomes available, afterwards we |
| 121 | * can safely write the read request into the register. |
| 122 | * After the data has been written, we wait until hardware |
| 123 | * returns the correct value, if at any time the register |
| 124 | * doesn't become available in time, reg will be 0xffffffff |
| 125 | * which means we return 0xff to the caller. |
| 126 | */ |
| 127 | if (WAIT_FOR_BBP(rt2x00dev, ®)) { |
| 128 | reg = 0; |
| 129 | rt2x00_set_field32(®, BBP_CSR_CFG_REGNUM, word); |
| 130 | rt2x00_set_field32(®, BBP_CSR_CFG_BUSY, 1); |
| 131 | rt2x00_set_field32(®, BBP_CSR_CFG_READ_CONTROL, 1); |
Ivo van Doorn | efc7d36 | 2010-06-29 21:49:26 +0200 | [diff] [blame] | 132 | rt2x00_set_field32(®, BBP_CSR_CFG_BBP_RW_MODE, 1); |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 133 | |
| 134 | rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg); |
| 135 | |
| 136 | WAIT_FOR_BBP(rt2x00dev, ®); |
| 137 | } |
| 138 | |
| 139 | *value = rt2x00_get_field32(reg, BBP_CSR_CFG_VALUE); |
| 140 | |
| 141 | mutex_unlock(&rt2x00dev->csr_mutex); |
| 142 | } |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 143 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 144 | static void rt2800_rfcsr_write(struct rt2x00_dev *rt2x00dev, |
| 145 | const unsigned int word, const u8 value) |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 146 | { |
| 147 | u32 reg; |
| 148 | |
| 149 | mutex_lock(&rt2x00dev->csr_mutex); |
| 150 | |
| 151 | /* |
| 152 | * Wait until the RFCSR becomes available, afterwards we |
| 153 | * can safely write the new data into the register. |
| 154 | */ |
| 155 | if (WAIT_FOR_RFCSR(rt2x00dev, ®)) { |
| 156 | reg = 0; |
| 157 | rt2x00_set_field32(®, RF_CSR_CFG_DATA, value); |
| 158 | rt2x00_set_field32(®, RF_CSR_CFG_REGNUM, word); |
| 159 | rt2x00_set_field32(®, RF_CSR_CFG_WRITE, 1); |
| 160 | rt2x00_set_field32(®, RF_CSR_CFG_BUSY, 1); |
| 161 | |
| 162 | rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg); |
| 163 | } |
| 164 | |
| 165 | mutex_unlock(&rt2x00dev->csr_mutex); |
| 166 | } |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 167 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 168 | static void rt2800_rfcsr_read(struct rt2x00_dev *rt2x00dev, |
| 169 | const unsigned int word, u8 *value) |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 170 | { |
| 171 | u32 reg; |
| 172 | |
| 173 | mutex_lock(&rt2x00dev->csr_mutex); |
| 174 | |
| 175 | /* |
| 176 | * Wait until the RFCSR becomes available, afterwards we |
| 177 | * can safely write the read request into the register. |
| 178 | * After the data has been written, we wait until hardware |
| 179 | * returns the correct value, if at any time the register |
| 180 | * doesn't become available in time, reg will be 0xffffffff |
| 181 | * which means we return 0xff to the caller. |
| 182 | */ |
| 183 | if (WAIT_FOR_RFCSR(rt2x00dev, ®)) { |
| 184 | reg = 0; |
| 185 | rt2x00_set_field32(®, RF_CSR_CFG_REGNUM, word); |
| 186 | rt2x00_set_field32(®, RF_CSR_CFG_WRITE, 0); |
| 187 | rt2x00_set_field32(®, RF_CSR_CFG_BUSY, 1); |
| 188 | |
| 189 | rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg); |
| 190 | |
| 191 | WAIT_FOR_RFCSR(rt2x00dev, ®); |
| 192 | } |
| 193 | |
| 194 | *value = rt2x00_get_field32(reg, RF_CSR_CFG_DATA); |
| 195 | |
| 196 | mutex_unlock(&rt2x00dev->csr_mutex); |
| 197 | } |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 198 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 199 | static void rt2800_rf_write(struct rt2x00_dev *rt2x00dev, |
| 200 | const unsigned int word, const u32 value) |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 201 | { |
| 202 | u32 reg; |
| 203 | |
| 204 | mutex_lock(&rt2x00dev->csr_mutex); |
| 205 | |
| 206 | /* |
| 207 | * Wait until the RF becomes available, afterwards we |
| 208 | * can safely write the new data into the register. |
| 209 | */ |
| 210 | if (WAIT_FOR_RF(rt2x00dev, ®)) { |
| 211 | reg = 0; |
| 212 | rt2x00_set_field32(®, RF_CSR_CFG0_REG_VALUE_BW, value); |
| 213 | rt2x00_set_field32(®, RF_CSR_CFG0_STANDBYMODE, 0); |
| 214 | rt2x00_set_field32(®, RF_CSR_CFG0_SEL, 0); |
| 215 | rt2x00_set_field32(®, RF_CSR_CFG0_BUSY, 1); |
| 216 | |
| 217 | rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG0, reg); |
| 218 | rt2x00_rf_write(rt2x00dev, word, value); |
| 219 | } |
| 220 | |
| 221 | mutex_unlock(&rt2x00dev->csr_mutex); |
| 222 | } |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 223 | |
Gabor Juhos | 379448f | 2013-07-08 11:25:55 +0200 | [diff] [blame] | 224 | static const unsigned int rt2800_eeprom_map[EEPROM_WORD_COUNT] = { |
| 225 | [EEPROM_CHIP_ID] = 0x0000, |
| 226 | [EEPROM_VERSION] = 0x0001, |
| 227 | [EEPROM_MAC_ADDR_0] = 0x0002, |
| 228 | [EEPROM_MAC_ADDR_1] = 0x0003, |
| 229 | [EEPROM_MAC_ADDR_2] = 0x0004, |
| 230 | [EEPROM_NIC_CONF0] = 0x001a, |
| 231 | [EEPROM_NIC_CONF1] = 0x001b, |
| 232 | [EEPROM_FREQ] = 0x001d, |
| 233 | [EEPROM_LED_AG_CONF] = 0x001e, |
| 234 | [EEPROM_LED_ACT_CONF] = 0x001f, |
| 235 | [EEPROM_LED_POLARITY] = 0x0020, |
| 236 | [EEPROM_NIC_CONF2] = 0x0021, |
| 237 | [EEPROM_LNA] = 0x0022, |
| 238 | [EEPROM_RSSI_BG] = 0x0023, |
| 239 | [EEPROM_RSSI_BG2] = 0x0024, |
| 240 | [EEPROM_TXMIXER_GAIN_BG] = 0x0024, /* overlaps with RSSI_BG2 */ |
| 241 | [EEPROM_RSSI_A] = 0x0025, |
| 242 | [EEPROM_RSSI_A2] = 0x0026, |
| 243 | [EEPROM_TXMIXER_GAIN_A] = 0x0026, /* overlaps with RSSI_A2 */ |
| 244 | [EEPROM_EIRP_MAX_TX_POWER] = 0x0027, |
| 245 | [EEPROM_TXPOWER_DELTA] = 0x0028, |
| 246 | [EEPROM_TXPOWER_BG1] = 0x0029, |
| 247 | [EEPROM_TXPOWER_BG2] = 0x0030, |
| 248 | [EEPROM_TSSI_BOUND_BG1] = 0x0037, |
| 249 | [EEPROM_TSSI_BOUND_BG2] = 0x0038, |
| 250 | [EEPROM_TSSI_BOUND_BG3] = 0x0039, |
| 251 | [EEPROM_TSSI_BOUND_BG4] = 0x003a, |
| 252 | [EEPROM_TSSI_BOUND_BG5] = 0x003b, |
| 253 | [EEPROM_TXPOWER_A1] = 0x003c, |
| 254 | [EEPROM_TXPOWER_A2] = 0x0053, |
| 255 | [EEPROM_TSSI_BOUND_A1] = 0x006a, |
| 256 | [EEPROM_TSSI_BOUND_A2] = 0x006b, |
| 257 | [EEPROM_TSSI_BOUND_A3] = 0x006c, |
| 258 | [EEPROM_TSSI_BOUND_A4] = 0x006d, |
| 259 | [EEPROM_TSSI_BOUND_A5] = 0x006e, |
| 260 | [EEPROM_TXPOWER_BYRATE] = 0x006f, |
| 261 | [EEPROM_BBP_START] = 0x0078, |
| 262 | }; |
| 263 | |
Gabor Juhos | fa31d15 | 2013-07-08 11:25:56 +0200 | [diff] [blame] | 264 | static const unsigned int rt2800_eeprom_map_ext[EEPROM_WORD_COUNT] = { |
| 265 | [EEPROM_CHIP_ID] = 0x0000, |
| 266 | [EEPROM_VERSION] = 0x0001, |
| 267 | [EEPROM_MAC_ADDR_0] = 0x0002, |
| 268 | [EEPROM_MAC_ADDR_1] = 0x0003, |
| 269 | [EEPROM_MAC_ADDR_2] = 0x0004, |
| 270 | [EEPROM_NIC_CONF0] = 0x001a, |
| 271 | [EEPROM_NIC_CONF1] = 0x001b, |
| 272 | [EEPROM_NIC_CONF2] = 0x001c, |
| 273 | [EEPROM_EIRP_MAX_TX_POWER] = 0x0020, |
| 274 | [EEPROM_FREQ] = 0x0022, |
| 275 | [EEPROM_LED_AG_CONF] = 0x0023, |
| 276 | [EEPROM_LED_ACT_CONF] = 0x0024, |
| 277 | [EEPROM_LED_POLARITY] = 0x0025, |
| 278 | [EEPROM_LNA] = 0x0026, |
| 279 | [EEPROM_EXT_LNA2] = 0x0027, |
| 280 | [EEPROM_RSSI_BG] = 0x0028, |
| 281 | [EEPROM_TXPOWER_DELTA] = 0x0028, /* Overlaps with RSSI_BG */ |
| 282 | [EEPROM_RSSI_BG2] = 0x0029, |
| 283 | [EEPROM_TXMIXER_GAIN_BG] = 0x0029, /* Overlaps with RSSI_BG2 */ |
| 284 | [EEPROM_RSSI_A] = 0x002a, |
| 285 | [EEPROM_RSSI_A2] = 0x002b, |
| 286 | [EEPROM_TXMIXER_GAIN_A] = 0x002b, /* Overlaps with RSSI_A2 */ |
| 287 | [EEPROM_TXPOWER_BG1] = 0x0030, |
| 288 | [EEPROM_TXPOWER_BG2] = 0x0037, |
| 289 | [EEPROM_EXT_TXPOWER_BG3] = 0x003e, |
| 290 | [EEPROM_TSSI_BOUND_BG1] = 0x0045, |
| 291 | [EEPROM_TSSI_BOUND_BG2] = 0x0046, |
| 292 | [EEPROM_TSSI_BOUND_BG3] = 0x0047, |
| 293 | [EEPROM_TSSI_BOUND_BG4] = 0x0048, |
| 294 | [EEPROM_TSSI_BOUND_BG5] = 0x0049, |
| 295 | [EEPROM_TXPOWER_A1] = 0x004b, |
| 296 | [EEPROM_TXPOWER_A2] = 0x0065, |
| 297 | [EEPROM_EXT_TXPOWER_A3] = 0x007f, |
| 298 | [EEPROM_TSSI_BOUND_A1] = 0x009a, |
| 299 | [EEPROM_TSSI_BOUND_A2] = 0x009b, |
| 300 | [EEPROM_TSSI_BOUND_A3] = 0x009c, |
| 301 | [EEPROM_TSSI_BOUND_A4] = 0x009d, |
| 302 | [EEPROM_TSSI_BOUND_A5] = 0x009e, |
| 303 | [EEPROM_TXPOWER_BYRATE] = 0x00a0, |
| 304 | }; |
| 305 | |
Gabor Juhos | 379448f | 2013-07-08 11:25:55 +0200 | [diff] [blame] | 306 | static unsigned int rt2800_eeprom_word_index(struct rt2x00_dev *rt2x00dev, |
| 307 | const enum rt2800_eeprom_word word) |
| 308 | { |
| 309 | const unsigned int *map; |
| 310 | unsigned int index; |
| 311 | |
| 312 | if (WARN_ONCE(word >= EEPROM_WORD_COUNT, |
| 313 | "%s: invalid EEPROM word %d\n", |
| 314 | wiphy_name(rt2x00dev->hw->wiphy), word)) |
| 315 | return 0; |
| 316 | |
Gabor Juhos | fa31d15 | 2013-07-08 11:25:56 +0200 | [diff] [blame] | 317 | if (rt2x00_rt(rt2x00dev, RT3593)) |
| 318 | map = rt2800_eeprom_map_ext; |
| 319 | else |
| 320 | map = rt2800_eeprom_map; |
| 321 | |
Gabor Juhos | 379448f | 2013-07-08 11:25:55 +0200 | [diff] [blame] | 322 | index = map[word]; |
| 323 | |
| 324 | /* Index 0 is valid only for EEPROM_CHIP_ID. |
| 325 | * Otherwise it means that the offset of the |
| 326 | * given word is not initialized in the map, |
| 327 | * or that the field is not usable on the |
| 328 | * actual chipset. |
| 329 | */ |
| 330 | WARN_ONCE(word != EEPROM_CHIP_ID && index == 0, |
| 331 | "%s: invalid access of EEPROM word %d\n", |
| 332 | wiphy_name(rt2x00dev->hw->wiphy), word); |
| 333 | |
| 334 | return index; |
| 335 | } |
| 336 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 337 | static void *rt2800_eeprom_addr(struct rt2x00_dev *rt2x00dev, |
| 338 | const enum rt2800_eeprom_word word) |
| 339 | { |
Gabor Juhos | 379448f | 2013-07-08 11:25:55 +0200 | [diff] [blame] | 340 | unsigned int index; |
| 341 | |
| 342 | index = rt2800_eeprom_word_index(rt2x00dev, word); |
| 343 | return rt2x00_eeprom_addr(rt2x00dev, index); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | static void rt2800_eeprom_read(struct rt2x00_dev *rt2x00dev, |
| 347 | const enum rt2800_eeprom_word word, u16 *data) |
| 348 | { |
Gabor Juhos | 379448f | 2013-07-08 11:25:55 +0200 | [diff] [blame] | 349 | unsigned int index; |
| 350 | |
| 351 | index = rt2800_eeprom_word_index(rt2x00dev, word); |
| 352 | rt2x00_eeprom_read(rt2x00dev, index, data); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | static void rt2800_eeprom_write(struct rt2x00_dev *rt2x00dev, |
| 356 | const enum rt2800_eeprom_word word, u16 data) |
| 357 | { |
Gabor Juhos | 379448f | 2013-07-08 11:25:55 +0200 | [diff] [blame] | 358 | unsigned int index; |
| 359 | |
| 360 | index = rt2800_eeprom_word_index(rt2x00dev, word); |
| 361 | rt2x00_eeprom_write(rt2x00dev, index, data); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 362 | } |
| 363 | |
Gabor Juhos | 022138c | 2013-07-08 11:25:54 +0200 | [diff] [blame] | 364 | static void rt2800_eeprom_read_from_array(struct rt2x00_dev *rt2x00dev, |
| 365 | const enum rt2800_eeprom_word array, |
| 366 | unsigned int offset, |
| 367 | u16 *data) |
| 368 | { |
Gabor Juhos | 379448f | 2013-07-08 11:25:55 +0200 | [diff] [blame] | 369 | unsigned int index; |
| 370 | |
| 371 | index = rt2800_eeprom_word_index(rt2x00dev, array); |
| 372 | rt2x00_eeprom_read(rt2x00dev, index + offset, data); |
Gabor Juhos | 022138c | 2013-07-08 11:25:54 +0200 | [diff] [blame] | 373 | } |
| 374 | |
Woody Hung | 16ebd60 | 2012-07-31 21:53:33 +0800 | [diff] [blame] | 375 | static int rt2800_enable_wlan_rt3290(struct rt2x00_dev *rt2x00dev) |
| 376 | { |
| 377 | u32 reg; |
| 378 | int i, count; |
| 379 | |
| 380 | rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, ®); |
| 381 | if (rt2x00_get_field32(reg, WLAN_EN)) |
| 382 | return 0; |
| 383 | |
| 384 | rt2x00_set_field32(®, WLAN_GPIO_OUT_OE_BIT_ALL, 0xff); |
| 385 | rt2x00_set_field32(®, FRC_WL_ANT_SET, 1); |
| 386 | rt2x00_set_field32(®, WLAN_CLK_EN, 0); |
| 387 | rt2x00_set_field32(®, WLAN_EN, 1); |
| 388 | rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg); |
| 389 | |
| 390 | udelay(REGISTER_BUSY_DELAY); |
| 391 | |
| 392 | count = 0; |
| 393 | do { |
| 394 | /* |
| 395 | * Check PLL_LD & XTAL_RDY. |
| 396 | */ |
| 397 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
| 398 | rt2800_register_read(rt2x00dev, CMB_CTRL, ®); |
| 399 | if (rt2x00_get_field32(reg, PLL_LD) && |
| 400 | rt2x00_get_field32(reg, XTAL_RDY)) |
| 401 | break; |
| 402 | udelay(REGISTER_BUSY_DELAY); |
| 403 | } |
| 404 | |
| 405 | if (i >= REGISTER_BUSY_COUNT) { |
| 406 | |
| 407 | if (count >= 10) |
| 408 | return -EIO; |
| 409 | |
| 410 | rt2800_register_write(rt2x00dev, 0x58, 0x018); |
| 411 | udelay(REGISTER_BUSY_DELAY); |
| 412 | rt2800_register_write(rt2x00dev, 0x58, 0x418); |
| 413 | udelay(REGISTER_BUSY_DELAY); |
| 414 | rt2800_register_write(rt2x00dev, 0x58, 0x618); |
| 415 | udelay(REGISTER_BUSY_DELAY); |
| 416 | count++; |
| 417 | } else { |
| 418 | count = 0; |
| 419 | } |
| 420 | |
| 421 | rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, ®); |
| 422 | rt2x00_set_field32(®, PCIE_APP0_CLK_REQ, 0); |
| 423 | rt2x00_set_field32(®, WLAN_CLK_EN, 1); |
| 424 | rt2x00_set_field32(®, WLAN_RESET, 1); |
| 425 | rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg); |
| 426 | udelay(10); |
| 427 | rt2x00_set_field32(®, WLAN_RESET, 0); |
| 428 | rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg); |
| 429 | udelay(10); |
| 430 | rt2800_register_write(rt2x00dev, INT_SOURCE_CSR, 0x7fffffff); |
| 431 | } while (count != 0); |
| 432 | |
| 433 | return 0; |
| 434 | } |
| 435 | |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 436 | void rt2800_mcu_request(struct rt2x00_dev *rt2x00dev, |
| 437 | const u8 command, const u8 token, |
| 438 | const u8 arg0, const u8 arg1) |
| 439 | { |
| 440 | u32 reg; |
| 441 | |
Gertjan van Wingerde | ee303e5 | 2009-11-23 22:44:49 +0100 | [diff] [blame] | 442 | /* |
Gertjan van Wingerde | cea90e5 | 2010-02-13 20:55:47 +0100 | [diff] [blame] | 443 | * SOC devices don't support MCU requests. |
Gertjan van Wingerde | ee303e5 | 2009-11-23 22:44:49 +0100 | [diff] [blame] | 444 | */ |
Gertjan van Wingerde | cea90e5 | 2010-02-13 20:55:47 +0100 | [diff] [blame] | 445 | if (rt2x00_is_soc(rt2x00dev)) |
Gertjan van Wingerde | ee303e5 | 2009-11-23 22:44:49 +0100 | [diff] [blame] | 446 | return; |
Bartlomiej Zolnierkiewicz | 8929742 | 2009-11-04 18:36:24 +0100 | [diff] [blame] | 447 | |
| 448 | mutex_lock(&rt2x00dev->csr_mutex); |
| 449 | |
| 450 | /* |
| 451 | * Wait until the MCU becomes available, afterwards we |
| 452 | * can safely write the new data into the register. |
| 453 | */ |
| 454 | if (WAIT_FOR_MCU(rt2x00dev, ®)) { |
| 455 | rt2x00_set_field32(®, H2M_MAILBOX_CSR_OWNER, 1); |
| 456 | rt2x00_set_field32(®, H2M_MAILBOX_CSR_CMD_TOKEN, token); |
| 457 | rt2x00_set_field32(®, H2M_MAILBOX_CSR_ARG0, arg0); |
| 458 | rt2x00_set_field32(®, H2M_MAILBOX_CSR_ARG1, arg1); |
| 459 | rt2800_register_write_lock(rt2x00dev, H2M_MAILBOX_CSR, reg); |
| 460 | |
| 461 | reg = 0; |
| 462 | rt2x00_set_field32(®, HOST_CMD_CSR_HOST_COMMAND, command); |
| 463 | rt2800_register_write_lock(rt2x00dev, HOST_CMD_CSR, reg); |
| 464 | } |
| 465 | |
| 466 | mutex_unlock(&rt2x00dev->csr_mutex); |
| 467 | } |
| 468 | EXPORT_SYMBOL_GPL(rt2800_mcu_request); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 469 | |
Ivo van Doorn | 5ffddc4 | 2010-08-30 21:13:08 +0200 | [diff] [blame] | 470 | int rt2800_wait_csr_ready(struct rt2x00_dev *rt2x00dev) |
| 471 | { |
| 472 | unsigned int i = 0; |
| 473 | u32 reg; |
| 474 | |
| 475 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
| 476 | rt2800_register_read(rt2x00dev, MAC_CSR0, ®); |
| 477 | if (reg && reg != ~0) |
| 478 | return 0; |
| 479 | msleep(1); |
| 480 | } |
| 481 | |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 482 | rt2x00_err(rt2x00dev, "Unstable hardware\n"); |
Ivo van Doorn | 5ffddc4 | 2010-08-30 21:13:08 +0200 | [diff] [blame] | 483 | return -EBUSY; |
| 484 | } |
| 485 | EXPORT_SYMBOL_GPL(rt2800_wait_csr_ready); |
| 486 | |
Gertjan van Wingerde | 67a4c1e | 2009-12-30 11:36:32 +0100 | [diff] [blame] | 487 | int rt2800_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev) |
| 488 | { |
| 489 | unsigned int i; |
| 490 | u32 reg; |
| 491 | |
Helmut Schaa | 08e5310 | 2010-11-04 20:37:47 +0100 | [diff] [blame] | 492 | /* |
| 493 | * Some devices are really slow to respond here. Wait a whole second |
| 494 | * before timing out. |
| 495 | */ |
Gertjan van Wingerde | 67a4c1e | 2009-12-30 11:36:32 +0100 | [diff] [blame] | 496 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
| 497 | rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®); |
| 498 | if (!rt2x00_get_field32(reg, WPDMA_GLO_CFG_TX_DMA_BUSY) && |
| 499 | !rt2x00_get_field32(reg, WPDMA_GLO_CFG_RX_DMA_BUSY)) |
| 500 | return 0; |
| 501 | |
Helmut Schaa | 08e5310 | 2010-11-04 20:37:47 +0100 | [diff] [blame] | 502 | msleep(10); |
Gertjan van Wingerde | 67a4c1e | 2009-12-30 11:36:32 +0100 | [diff] [blame] | 503 | } |
| 504 | |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 505 | rt2x00_err(rt2x00dev, "WPDMA TX/RX busy [0x%08x]\n", reg); |
Gertjan van Wingerde | 67a4c1e | 2009-12-30 11:36:32 +0100 | [diff] [blame] | 506 | return -EACCES; |
| 507 | } |
| 508 | EXPORT_SYMBOL_GPL(rt2800_wait_wpdma_ready); |
| 509 | |
Jakub Kicinski | f7b395e | 2012-04-03 03:40:47 +0200 | [diff] [blame] | 510 | void rt2800_disable_wpdma(struct rt2x00_dev *rt2x00dev) |
| 511 | { |
| 512 | u32 reg; |
| 513 | |
| 514 | rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®); |
| 515 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0); |
| 516 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_DMA_BUSY, 0); |
| 517 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0); |
| 518 | rt2x00_set_field32(®, WPDMA_GLO_CFG_RX_DMA_BUSY, 0); |
| 519 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1); |
| 520 | rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg); |
| 521 | } |
| 522 | EXPORT_SYMBOL_GPL(rt2800_disable_wpdma); |
| 523 | |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 524 | static bool rt2800_check_firmware_crc(const u8 *data, const size_t len) |
| 525 | { |
| 526 | u16 fw_crc; |
| 527 | u16 crc; |
| 528 | |
| 529 | /* |
| 530 | * The last 2 bytes in the firmware array are the crc checksum itself, |
| 531 | * this means that we should never pass those 2 bytes to the crc |
| 532 | * algorithm. |
| 533 | */ |
| 534 | fw_crc = (data[len - 2] << 8 | data[len - 1]); |
| 535 | |
| 536 | /* |
| 537 | * Use the crc ccitt algorithm. |
| 538 | * This will return the same value as the legacy driver which |
| 539 | * used bit ordering reversion on the both the firmware bytes |
| 540 | * before input input as well as on the final output. |
| 541 | * Obviously using crc ccitt directly is much more efficient. |
| 542 | */ |
| 543 | crc = crc_ccitt(~0, data, len - 2); |
| 544 | |
| 545 | /* |
| 546 | * There is a small difference between the crc-itu-t + bitrev and |
| 547 | * the crc-ccitt crc calculation. In the latter method the 2 bytes |
| 548 | * will be swapped, use swab16 to convert the crc to the correct |
| 549 | * value. |
| 550 | */ |
| 551 | crc = swab16(crc); |
| 552 | |
| 553 | return fw_crc == crc; |
| 554 | } |
| 555 | |
| 556 | int rt2800_check_firmware(struct rt2x00_dev *rt2x00dev, |
| 557 | const u8 *data, const size_t len) |
| 558 | { |
| 559 | size_t offset = 0; |
| 560 | size_t fw_len; |
| 561 | bool multiple; |
| 562 | |
| 563 | /* |
| 564 | * PCI(e) & SOC devices require firmware with a length |
| 565 | * of 8kb. USB devices require firmware files with a length |
| 566 | * of 4kb. Certain USB chipsets however require different firmware, |
| 567 | * which Ralink only provides attached to the original firmware |
| 568 | * file. Thus for USB devices, firmware files have a length |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 569 | * which is a multiple of 4kb. The firmware for rt3290 chip also |
| 570 | * have a length which is a multiple of 4kb. |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 571 | */ |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 572 | if (rt2x00_is_usb(rt2x00dev) || rt2x00_rt(rt2x00dev, RT3290)) |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 573 | fw_len = 4096; |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 574 | else |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 575 | fw_len = 8192; |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 576 | |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 577 | multiple = true; |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 578 | /* |
| 579 | * Validate the firmware length |
| 580 | */ |
| 581 | if (len != fw_len && (!multiple || (len % fw_len) != 0)) |
| 582 | return FW_BAD_LENGTH; |
| 583 | |
| 584 | /* |
| 585 | * Check if the chipset requires one of the upper parts |
| 586 | * of the firmware. |
| 587 | */ |
| 588 | if (rt2x00_is_usb(rt2x00dev) && |
| 589 | !rt2x00_rt(rt2x00dev, RT2860) && |
| 590 | !rt2x00_rt(rt2x00dev, RT2872) && |
| 591 | !rt2x00_rt(rt2x00dev, RT3070) && |
| 592 | ((len / fw_len) == 1)) |
| 593 | return FW_BAD_VERSION; |
| 594 | |
| 595 | /* |
| 596 | * 8kb firmware files must be checked as if it were |
| 597 | * 2 separate firmware files. |
| 598 | */ |
| 599 | while (offset < len) { |
| 600 | if (!rt2800_check_firmware_crc(data + offset, fw_len)) |
| 601 | return FW_BAD_CRC; |
| 602 | |
| 603 | offset += fw_len; |
| 604 | } |
| 605 | |
| 606 | return FW_OK; |
| 607 | } |
| 608 | EXPORT_SYMBOL_GPL(rt2800_check_firmware); |
| 609 | |
| 610 | int rt2800_load_firmware(struct rt2x00_dev *rt2x00dev, |
| 611 | const u8 *data, const size_t len) |
| 612 | { |
| 613 | unsigned int i; |
| 614 | u32 reg; |
Woody Hung | 16ebd60 | 2012-07-31 21:53:33 +0800 | [diff] [blame] | 615 | int retval; |
| 616 | |
| 617 | if (rt2x00_rt(rt2x00dev, RT3290)) { |
| 618 | retval = rt2800_enable_wlan_rt3290(rt2x00dev); |
| 619 | if (retval) |
| 620 | return -EBUSY; |
| 621 | } |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 622 | |
| 623 | /* |
Ivo van Doorn | b9eca24 | 2010-08-30 21:13:54 +0200 | [diff] [blame] | 624 | * If driver doesn't wake up firmware here, |
| 625 | * rt2800_load_firmware will hang forever when interface is up again. |
| 626 | */ |
| 627 | rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0x00000000); |
| 628 | |
| 629 | /* |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 630 | * Wait for stable hardware. |
| 631 | */ |
Ivo van Doorn | 5ffddc4 | 2010-08-30 21:13:08 +0200 | [diff] [blame] | 632 | if (rt2800_wait_csr_ready(rt2x00dev)) |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 633 | return -EBUSY; |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 634 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 635 | if (rt2x00_is_pci(rt2x00dev)) { |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 636 | if (rt2x00_rt(rt2x00dev, RT3290) || |
| 637 | rt2x00_rt(rt2x00dev, RT3572) || |
John Li | 2ed7188 | 2012-02-17 17:33:06 +0800 | [diff] [blame] | 638 | rt2x00_rt(rt2x00dev, RT5390) || |
| 639 | rt2x00_rt(rt2x00dev, RT5392)) { |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 640 | rt2800_register_read(rt2x00dev, AUX_CTRL, ®); |
| 641 | rt2x00_set_field32(®, AUX_CTRL_FORCE_PCIE_CLK, 1); |
| 642 | rt2x00_set_field32(®, AUX_CTRL_WAKE_PCIE_EN, 1); |
| 643 | rt2800_register_write(rt2x00dev, AUX_CTRL, reg); |
| 644 | } |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 645 | rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000002); |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 646 | } |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 647 | |
Jakub Kicinski | b7e1d22 | 2012-04-03 03:40:48 +0200 | [diff] [blame] | 648 | rt2800_disable_wpdma(rt2x00dev); |
| 649 | |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 650 | /* |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 651 | * Write firmware to the device. |
| 652 | */ |
| 653 | rt2800_drv_write_firmware(rt2x00dev, data, len); |
| 654 | |
| 655 | /* |
| 656 | * Wait for device to stabilize. |
| 657 | */ |
| 658 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
| 659 | rt2800_register_read(rt2x00dev, PBF_SYS_CTRL, ®); |
| 660 | if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY)) |
| 661 | break; |
| 662 | msleep(1); |
| 663 | } |
| 664 | |
| 665 | if (i == REGISTER_BUSY_COUNT) { |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 666 | rt2x00_err(rt2x00dev, "PBF system register not ready\n"); |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 667 | return -EBUSY; |
| 668 | } |
| 669 | |
| 670 | /* |
Stanislaw Gruszka | 4ed1dd2 | 2012-01-24 14:09:07 +0100 | [diff] [blame] | 671 | * Disable DMA, will be reenabled later when enabling |
| 672 | * the radio. |
| 673 | */ |
Jakub Kicinski | f7b395e | 2012-04-03 03:40:47 +0200 | [diff] [blame] | 674 | rt2800_disable_wpdma(rt2x00dev); |
Stanislaw Gruszka | 4ed1dd2 | 2012-01-24 14:09:07 +0100 | [diff] [blame] | 675 | |
| 676 | /* |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 677 | * Initialize firmware. |
| 678 | */ |
| 679 | rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0); |
| 680 | rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0); |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 681 | if (rt2x00_is_usb(rt2x00dev)) { |
Stanislaw Gruszka | 0c17cf9 | 2012-01-24 14:09:06 +0100 | [diff] [blame] | 682 | rt2800_register_write(rt2x00dev, H2M_INT_SRC, 0); |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 683 | rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0, 0, 0); |
| 684 | } |
Ivo van Doorn | f31c9a8 | 2010-07-11 12:30:37 +0200 | [diff] [blame] | 685 | msleep(1); |
| 686 | |
| 687 | return 0; |
| 688 | } |
| 689 | EXPORT_SYMBOL_GPL(rt2800_load_firmware); |
| 690 | |
Ivo van Doorn | 0c5879b | 2010-08-06 20:47:20 +0200 | [diff] [blame] | 691 | void rt2800_write_tx_data(struct queue_entry *entry, |
| 692 | struct txentry_desc *txdesc) |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 693 | { |
Ivo van Doorn | 0c5879b | 2010-08-06 20:47:20 +0200 | [diff] [blame] | 694 | __le32 *txwi = rt2800_drv_get_txwi(entry); |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 695 | u32 word; |
Stanislaw Gruszka | 557985a | 2013-04-17 14:30:48 +0200 | [diff] [blame] | 696 | int i; |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 697 | |
| 698 | /* |
| 699 | * Initialize TX Info descriptor |
| 700 | */ |
| 701 | rt2x00_desc_read(txwi, 0, &word); |
| 702 | rt2x00_set_field32(&word, TXWI_W0_FRAG, |
| 703 | test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags)); |
Ivo van Doorn | 84804cd | 2010-08-06 20:46:19 +0200 | [diff] [blame] | 704 | rt2x00_set_field32(&word, TXWI_W0_MIMO_PS, |
| 705 | test_bit(ENTRY_TXD_HT_MIMO_PS, &txdesc->flags)); |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 706 | rt2x00_set_field32(&word, TXWI_W0_CF_ACK, 0); |
| 707 | rt2x00_set_field32(&word, TXWI_W0_TS, |
| 708 | test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags)); |
| 709 | rt2x00_set_field32(&word, TXWI_W0_AMPDU, |
| 710 | test_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags)); |
Helmut Schaa | 26a1d07 | 2011-03-03 19:42:35 +0100 | [diff] [blame] | 711 | rt2x00_set_field32(&word, TXWI_W0_MPDU_DENSITY, |
| 712 | txdesc->u.ht.mpdu_density); |
| 713 | rt2x00_set_field32(&word, TXWI_W0_TX_OP, txdesc->u.ht.txop); |
| 714 | rt2x00_set_field32(&word, TXWI_W0_MCS, txdesc->u.ht.mcs); |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 715 | rt2x00_set_field32(&word, TXWI_W0_BW, |
| 716 | test_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags)); |
| 717 | rt2x00_set_field32(&word, TXWI_W0_SHORT_GI, |
| 718 | test_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags)); |
Helmut Schaa | 26a1d07 | 2011-03-03 19:42:35 +0100 | [diff] [blame] | 719 | rt2x00_set_field32(&word, TXWI_W0_STBC, txdesc->u.ht.stbc); |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 720 | rt2x00_set_field32(&word, TXWI_W0_PHYMODE, txdesc->rate_mode); |
| 721 | rt2x00_desc_write(txwi, 0, word); |
| 722 | |
| 723 | rt2x00_desc_read(txwi, 1, &word); |
| 724 | rt2x00_set_field32(&word, TXWI_W1_ACK, |
| 725 | test_bit(ENTRY_TXD_ACK, &txdesc->flags)); |
| 726 | rt2x00_set_field32(&word, TXWI_W1_NSEQ, |
| 727 | test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags)); |
Helmut Schaa | 26a1d07 | 2011-03-03 19:42:35 +0100 | [diff] [blame] | 728 | 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] | 729 | rt2x00_set_field32(&word, TXWI_W1_WIRELESS_CLI_ID, |
| 730 | test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags) ? |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 731 | txdesc->key_idx : txdesc->u.ht.wcid); |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 732 | rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT, |
| 733 | txdesc->length); |
Helmut Schaa | 2b23cda | 2010-11-04 20:38:15 +0100 | [diff] [blame] | 734 | rt2x00_set_field32(&word, TXWI_W1_PACKETID_QUEUE, entry->queue->qid); |
Ivo van Doorn | bc8a979 | 2010-10-02 11:32:43 +0200 | [diff] [blame] | 735 | 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] | 736 | rt2x00_desc_write(txwi, 1, word); |
| 737 | |
| 738 | /* |
Stanislaw Gruszka | 557985a | 2013-04-17 14:30:48 +0200 | [diff] [blame] | 739 | * Always write 0 to IV/EIV fields (word 2 and 3), hardware will insert |
| 740 | * 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] | 741 | * When TXD_W3_WIV is set to 1 it will use the IV data |
| 742 | * from the descriptor. The TXWI_W1_WIRELESS_CLI_ID indicates which |
| 743 | * crypto entry in the registers should be used to encrypt the frame. |
Stanislaw Gruszka | 557985a | 2013-04-17 14:30:48 +0200 | [diff] [blame] | 744 | * |
| 745 | * 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] | 746 | */ |
Stanislaw Gruszka | 557985a | 2013-04-17 14:30:48 +0200 | [diff] [blame] | 747 | for (i = 2; i < entry->queue->winfo_size / sizeof(__le32); i++) |
| 748 | _rt2x00_desc_write(txwi, i, 0); |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 749 | } |
Ivo van Doorn | 0c5879b | 2010-08-06 20:47:20 +0200 | [diff] [blame] | 750 | EXPORT_SYMBOL_GPL(rt2800_write_tx_data); |
Gertjan van Wingerde | 59679b9 | 2010-05-08 23:40:21 +0200 | [diff] [blame] | 751 | |
Helmut Schaa | ff6133b | 2010-10-09 13:34:11 +0200 | [diff] [blame] | 752 | 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] | 753 | { |
Luigi Tarenga | 7fc4175 | 2012-01-31 18:51:23 +0100 | [diff] [blame] | 754 | s8 rssi0 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI0); |
| 755 | s8 rssi1 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI1); |
| 756 | s8 rssi2 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI2); |
Ivo van Doorn | 7486192 | 2010-07-11 12:23:50 +0200 | [diff] [blame] | 757 | u16 eeprom; |
| 758 | u8 offset0; |
| 759 | u8 offset1; |
| 760 | u8 offset2; |
| 761 | |
Ivo van Doorn | e5ef5ba | 2010-08-06 20:49:27 +0200 | [diff] [blame] | 762 | if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 763 | rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &eeprom); |
Ivo van Doorn | 7486192 | 2010-07-11 12:23:50 +0200 | [diff] [blame] | 764 | offset0 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG_OFFSET0); |
| 765 | offset1 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG_OFFSET1); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 766 | rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom); |
Ivo van Doorn | 7486192 | 2010-07-11 12:23:50 +0200 | [diff] [blame] | 767 | offset2 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG2_OFFSET2); |
| 768 | } else { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 769 | rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &eeprom); |
Ivo van Doorn | 7486192 | 2010-07-11 12:23:50 +0200 | [diff] [blame] | 770 | offset0 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A_OFFSET0); |
| 771 | offset1 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A_OFFSET1); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 772 | rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom); |
Ivo van Doorn | 7486192 | 2010-07-11 12:23:50 +0200 | [diff] [blame] | 773 | offset2 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A2_OFFSET2); |
| 774 | } |
| 775 | |
| 776 | /* |
| 777 | * Convert the value from the descriptor into the RSSI value |
| 778 | * If the value in the descriptor is 0, it is considered invalid |
| 779 | * and the default (extremely low) rssi value is assumed |
| 780 | */ |
| 781 | rssi0 = (rssi0) ? (-12 - offset0 - rt2x00dev->lna_gain - rssi0) : -128; |
| 782 | rssi1 = (rssi1) ? (-12 - offset1 - rt2x00dev->lna_gain - rssi1) : -128; |
| 783 | rssi2 = (rssi2) ? (-12 - offset2 - rt2x00dev->lna_gain - rssi2) : -128; |
| 784 | |
| 785 | /* |
| 786 | * mac80211 only accepts a single RSSI value. Calculating the |
| 787 | * average doesn't deliver a fair answer either since -60:-60 would |
| 788 | * be considered equally good as -50:-70 while the second is the one |
| 789 | * which gives less energy... |
| 790 | */ |
| 791 | rssi0 = max(rssi0, rssi1); |
Luigi Tarenga | 7fc4175 | 2012-01-31 18:51:23 +0100 | [diff] [blame] | 792 | return (int)max(rssi0, rssi2); |
Ivo van Doorn | 7486192 | 2010-07-11 12:23:50 +0200 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | void rt2800_process_rxwi(struct queue_entry *entry, |
| 796 | struct rxdone_entry_desc *rxdesc) |
| 797 | { |
| 798 | __le32 *rxwi = (__le32 *) entry->skb->data; |
Gertjan van Wingerde | 2de64dd | 2010-05-08 23:40:22 +0200 | [diff] [blame] | 799 | u32 word; |
| 800 | |
| 801 | rt2x00_desc_read(rxwi, 0, &word); |
| 802 | |
| 803 | rxdesc->cipher = rt2x00_get_field32(word, RXWI_W0_UDF); |
| 804 | rxdesc->size = rt2x00_get_field32(word, RXWI_W0_MPDU_TOTAL_BYTE_COUNT); |
| 805 | |
| 806 | rt2x00_desc_read(rxwi, 1, &word); |
| 807 | |
| 808 | if (rt2x00_get_field32(word, RXWI_W1_SHORT_GI)) |
| 809 | rxdesc->flags |= RX_FLAG_SHORT_GI; |
| 810 | |
| 811 | if (rt2x00_get_field32(word, RXWI_W1_BW)) |
| 812 | rxdesc->flags |= RX_FLAG_40MHZ; |
| 813 | |
| 814 | /* |
| 815 | * Detect RX rate, always use MCS as signal type. |
| 816 | */ |
| 817 | rxdesc->dev_flags |= RXDONE_SIGNAL_MCS; |
| 818 | rxdesc->signal = rt2x00_get_field32(word, RXWI_W1_MCS); |
| 819 | rxdesc->rate_mode = rt2x00_get_field32(word, RXWI_W1_PHYMODE); |
| 820 | |
| 821 | /* |
| 822 | * Mask of 0x8 bit to remove the short preamble flag. |
| 823 | */ |
| 824 | if (rxdesc->rate_mode == RATE_MODE_CCK) |
| 825 | rxdesc->signal &= ~0x8; |
| 826 | |
| 827 | rt2x00_desc_read(rxwi, 2, &word); |
| 828 | |
Ivo van Doorn | 7486192 | 2010-07-11 12:23:50 +0200 | [diff] [blame] | 829 | /* |
| 830 | * Convert descriptor AGC value to RSSI value. |
| 831 | */ |
| 832 | rxdesc->rssi = rt2800_agc_to_rssi(entry->queue->rt2x00dev, word); |
Stanislaw Gruszka | f0bda57 | 2013-04-17 14:30:47 +0200 | [diff] [blame] | 833 | /* |
| 834 | * Remove RXWI descriptor from start of the buffer. |
| 835 | */ |
| 836 | skb_pull(entry->skb, entry->queue->winfo_size); |
Gertjan van Wingerde | 2de64dd | 2010-05-08 23:40:22 +0200 | [diff] [blame] | 837 | } |
| 838 | EXPORT_SYMBOL_GPL(rt2800_process_rxwi); |
| 839 | |
Helmut Schaa | 31937c4 | 2011-09-07 20:10:02 +0200 | [diff] [blame] | 840 | void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi) |
Helmut Schaa | 1443333 | 2010-10-02 11:27:03 +0200 | [diff] [blame] | 841 | { |
| 842 | struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; |
Helmut Schaa | b34793e | 2010-10-02 11:34:56 +0200 | [diff] [blame] | 843 | struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); |
Helmut Schaa | 1443333 | 2010-10-02 11:27:03 +0200 | [diff] [blame] | 844 | struct txdone_entry_desc txdesc; |
| 845 | u32 word; |
| 846 | u16 mcs, real_mcs; |
Helmut Schaa | b34793e | 2010-10-02 11:34:56 +0200 | [diff] [blame] | 847 | int aggr, ampdu; |
Helmut Schaa | 1443333 | 2010-10-02 11:27:03 +0200 | [diff] [blame] | 848 | |
| 849 | /* |
| 850 | * Obtain the status about this packet. |
| 851 | */ |
| 852 | txdesc.flags = 0; |
Helmut Schaa | 1443333 | 2010-10-02 11:27:03 +0200 | [diff] [blame] | 853 | rt2x00_desc_read(txwi, 0, &word); |
Helmut Schaa | b34793e | 2010-10-02 11:34:56 +0200 | [diff] [blame] | 854 | |
Helmut Schaa | 1443333 | 2010-10-02 11:27:03 +0200 | [diff] [blame] | 855 | mcs = rt2x00_get_field32(word, TXWI_W0_MCS); |
Helmut Schaa | b34793e | 2010-10-02 11:34:56 +0200 | [diff] [blame] | 856 | ampdu = rt2x00_get_field32(word, TXWI_W0_AMPDU); |
| 857 | |
Helmut Schaa | 1443333 | 2010-10-02 11:27:03 +0200 | [diff] [blame] | 858 | real_mcs = rt2x00_get_field32(status, TX_STA_FIFO_MCS); |
Helmut Schaa | b34793e | 2010-10-02 11:34:56 +0200 | [diff] [blame] | 859 | aggr = rt2x00_get_field32(status, TX_STA_FIFO_TX_AGGRE); |
| 860 | |
| 861 | /* |
| 862 | * If a frame was meant to be sent as a single non-aggregated MPDU |
| 863 | * but ended up in an aggregate the used tx rate doesn't correlate |
| 864 | * with the one specified in the TXWI as the whole aggregate is sent |
| 865 | * with the same rate. |
| 866 | * |
| 867 | * For example: two frames are sent to rt2x00, the first one sets |
| 868 | * AMPDU=1 and requests MCS7 whereas the second frame sets AMDPU=0 |
| 869 | * and requests MCS15. If the hw aggregates both frames into one |
| 870 | * AMDPU the tx status for both frames will contain MCS7 although |
| 871 | * the frame was sent successfully. |
| 872 | * |
| 873 | * Hence, replace the requested rate with the real tx rate to not |
| 874 | * confuse the rate control algortihm by providing clearly wrong |
| 875 | * data. |
| 876 | */ |
Helmut Schaa | 5356d96 | 2011-03-03 19:40:33 +0100 | [diff] [blame] | 877 | if (unlikely(aggr == 1 && ampdu == 0 && real_mcs != mcs)) { |
Helmut Schaa | b34793e | 2010-10-02 11:34:56 +0200 | [diff] [blame] | 878 | skbdesc->tx_rate_idx = real_mcs; |
| 879 | mcs = real_mcs; |
| 880 | } |
Helmut Schaa | 1443333 | 2010-10-02 11:27:03 +0200 | [diff] [blame] | 881 | |
Helmut Schaa | f16d2db | 2011-03-28 13:35:21 +0200 | [diff] [blame] | 882 | if (aggr == 1 || ampdu == 1) |
| 883 | __set_bit(TXDONE_AMPDU, &txdesc.flags); |
| 884 | |
Helmut Schaa | 1443333 | 2010-10-02 11:27:03 +0200 | [diff] [blame] | 885 | /* |
| 886 | * Ralink has a retry mechanism using a global fallback |
| 887 | * table. We setup this fallback table to try the immediate |
| 888 | * lower rate for all rates. In the TX_STA_FIFO, the MCS field |
| 889 | * always contains the MCS used for the last transmission, be |
| 890 | * it successful or not. |
| 891 | */ |
| 892 | if (rt2x00_get_field32(status, TX_STA_FIFO_TX_SUCCESS)) { |
| 893 | /* |
| 894 | * Transmission succeeded. The number of retries is |
| 895 | * mcs - real_mcs |
| 896 | */ |
| 897 | __set_bit(TXDONE_SUCCESS, &txdesc.flags); |
| 898 | txdesc.retry = ((mcs > real_mcs) ? mcs - real_mcs : 0); |
| 899 | } else { |
| 900 | /* |
| 901 | * Transmission failed. The number of retries is |
| 902 | * always 7 in this case (for a total number of 8 |
| 903 | * frames sent). |
| 904 | */ |
| 905 | __set_bit(TXDONE_FAILURE, &txdesc.flags); |
| 906 | txdesc.retry = rt2x00dev->long_retry; |
| 907 | } |
| 908 | |
| 909 | /* |
| 910 | * the frame was retried at least once |
| 911 | * -> hw used fallback rates |
| 912 | */ |
| 913 | if (txdesc.retry) |
| 914 | __set_bit(TXDONE_FALLBACK, &txdesc.flags); |
| 915 | |
| 916 | rt2x00lib_txdone(entry, &txdesc); |
| 917 | } |
| 918 | EXPORT_SYMBOL_GPL(rt2800_txdone_entry); |
| 919 | |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 920 | void rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc) |
| 921 | { |
| 922 | struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; |
| 923 | struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); |
| 924 | unsigned int beacon_base; |
Wolfgang Kufner | 739fd94 | 2010-12-13 12:39:12 +0100 | [diff] [blame] | 925 | unsigned int padding_len; |
Seth Forshee | d76dfc6 | 2011-02-14 08:52:25 -0600 | [diff] [blame] | 926 | u32 orig_reg, reg; |
Stanislaw Gruszka | f0bda57 | 2013-04-17 14:30:47 +0200 | [diff] [blame] | 927 | const int txwi_desc_size = entry->queue->winfo_size; |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 928 | |
| 929 | /* |
| 930 | * Disable beaconing while we are reloading the beacon data, |
| 931 | * otherwise we might be sending out invalid data. |
| 932 | */ |
| 933 | rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®); |
Seth Forshee | d76dfc6 | 2011-02-14 08:52:25 -0600 | [diff] [blame] | 934 | orig_reg = reg; |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 935 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 0); |
| 936 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
| 937 | |
| 938 | /* |
| 939 | * Add space for the TXWI in front of the skb. |
| 940 | */ |
Stanislaw Gruszka | f0bda57 | 2013-04-17 14:30:47 +0200 | [diff] [blame] | 941 | 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] | 942 | |
| 943 | /* |
| 944 | * Register descriptor details in skb frame descriptor. |
| 945 | */ |
| 946 | skbdesc->flags |= SKBDESC_DESC_IN_SKB; |
| 947 | skbdesc->desc = entry->skb->data; |
Stanislaw Gruszka | f0bda57 | 2013-04-17 14:30:47 +0200 | [diff] [blame] | 948 | skbdesc->desc_len = txwi_desc_size; |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 949 | |
| 950 | /* |
| 951 | * Add the TXWI for the beacon to the skb. |
| 952 | */ |
Ivo van Doorn | 0c5879b | 2010-08-06 20:47:20 +0200 | [diff] [blame] | 953 | rt2800_write_tx_data(entry, txdesc); |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 954 | |
| 955 | /* |
| 956 | * Dump beacon to userspace through debugfs. |
| 957 | */ |
| 958 | rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry->skb); |
| 959 | |
| 960 | /* |
Wolfgang Kufner | 739fd94 | 2010-12-13 12:39:12 +0100 | [diff] [blame] | 961 | * Write entire beacon with TXWI and padding to register. |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 962 | */ |
Wolfgang Kufner | 739fd94 | 2010-12-13 12:39:12 +0100 | [diff] [blame] | 963 | padding_len = roundup(entry->skb->len, 4) - entry->skb->len; |
Seth Forshee | d76dfc6 | 2011-02-14 08:52:25 -0600 | [diff] [blame] | 964 | if (padding_len && skb_pad(entry->skb, padding_len)) { |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 965 | rt2x00_err(rt2x00dev, "Failure padding beacon, aborting\n"); |
Seth Forshee | d76dfc6 | 2011-02-14 08:52:25 -0600 | [diff] [blame] | 966 | /* skb freed by skb_pad() on failure */ |
| 967 | entry->skb = NULL; |
| 968 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, orig_reg); |
| 969 | return; |
| 970 | } |
| 971 | |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 972 | beacon_base = HW_BEACON_OFFSET(entry->entry_idx); |
Wolfgang Kufner | 739fd94 | 2010-12-13 12:39:12 +0100 | [diff] [blame] | 973 | rt2800_register_multiwrite(rt2x00dev, beacon_base, entry->skb->data, |
| 974 | entry->skb->len + padding_len); |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 975 | |
| 976 | /* |
| 977 | * Enable beaconing again. |
| 978 | */ |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 979 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 1); |
| 980 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
| 981 | |
| 982 | /* |
| 983 | * Clean up beacon skb. |
| 984 | */ |
| 985 | dev_kfree_skb_any(entry->skb); |
| 986 | entry->skb = NULL; |
| 987 | } |
Ivo van Doorn | 50e888e | 2010-07-11 12:26:12 +0200 | [diff] [blame] | 988 | EXPORT_SYMBOL_GPL(rt2800_write_beacon); |
Gertjan van Wingerde | f0194b2 | 2010-06-03 10:51:53 +0200 | [diff] [blame] | 989 | |
Helmut Schaa | 69cf36a | 2011-01-30 13:16:03 +0100 | [diff] [blame] | 990 | static inline void rt2800_clear_beacon_register(struct rt2x00_dev *rt2x00dev, |
| 991 | unsigned int beacon_base) |
Helmut Schaa | fdb8725 | 2010-06-29 21:48:06 +0200 | [diff] [blame] | 992 | { |
| 993 | int i; |
Gabor Juhos | 0879f87 | 2013-05-01 17:17:33 +0200 | [diff] [blame] | 994 | const int txwi_desc_size = rt2x00dev->bcn->winfo_size; |
Helmut Schaa | fdb8725 | 2010-06-29 21:48:06 +0200 | [diff] [blame] | 995 | |
| 996 | /* |
| 997 | * For the Beacon base registers we only need to clear |
| 998 | * the whole TXWI which (when set to 0) will invalidate |
| 999 | * the entire beacon. |
| 1000 | */ |
Stanislaw Gruszka | f0bda57 | 2013-04-17 14:30:47 +0200 | [diff] [blame] | 1001 | for (i = 0; i < txwi_desc_size; i += sizeof(__le32)) |
Helmut Schaa | fdb8725 | 2010-06-29 21:48:06 +0200 | [diff] [blame] | 1002 | rt2800_register_write(rt2x00dev, beacon_base + i, 0); |
| 1003 | } |
| 1004 | |
Helmut Schaa | 69cf36a | 2011-01-30 13:16:03 +0100 | [diff] [blame] | 1005 | void rt2800_clear_beacon(struct queue_entry *entry) |
| 1006 | { |
| 1007 | struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; |
| 1008 | u32 reg; |
| 1009 | |
| 1010 | /* |
| 1011 | * Disable beaconing while we are reloading the beacon data, |
| 1012 | * otherwise we might be sending out invalid data. |
| 1013 | */ |
| 1014 | rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®); |
| 1015 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 0); |
| 1016 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
| 1017 | |
| 1018 | /* |
| 1019 | * Clear beacon. |
| 1020 | */ |
| 1021 | rt2800_clear_beacon_register(rt2x00dev, |
| 1022 | HW_BEACON_OFFSET(entry->entry_idx)); |
| 1023 | |
| 1024 | /* |
| 1025 | * Enabled beaconing again. |
| 1026 | */ |
| 1027 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 1); |
| 1028 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
| 1029 | } |
| 1030 | EXPORT_SYMBOL_GPL(rt2800_clear_beacon); |
| 1031 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1032 | #ifdef CONFIG_RT2X00_LIB_DEBUGFS |
| 1033 | const struct rt2x00debug rt2800_rt2x00debug = { |
| 1034 | .owner = THIS_MODULE, |
| 1035 | .csr = { |
| 1036 | .read = rt2800_register_read, |
| 1037 | .write = rt2800_register_write, |
| 1038 | .flags = RT2X00DEBUGFS_OFFSET, |
| 1039 | .word_base = CSR_REG_BASE, |
| 1040 | .word_size = sizeof(u32), |
| 1041 | .word_count = CSR_REG_SIZE / sizeof(u32), |
| 1042 | }, |
| 1043 | .eeprom = { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 1044 | /* NOTE: The local EEPROM access functions can't |
| 1045 | * be used here, use the generic versions instead. |
| 1046 | */ |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1047 | .read = rt2x00_eeprom_read, |
| 1048 | .write = rt2x00_eeprom_write, |
| 1049 | .word_base = EEPROM_BASE, |
| 1050 | .word_size = sizeof(u16), |
| 1051 | .word_count = EEPROM_SIZE / sizeof(u16), |
| 1052 | }, |
| 1053 | .bbp = { |
| 1054 | .read = rt2800_bbp_read, |
| 1055 | .write = rt2800_bbp_write, |
| 1056 | .word_base = BBP_BASE, |
| 1057 | .word_size = sizeof(u8), |
| 1058 | .word_count = BBP_SIZE / sizeof(u8), |
| 1059 | }, |
| 1060 | .rf = { |
| 1061 | .read = rt2x00_rf_read, |
| 1062 | .write = rt2800_rf_write, |
| 1063 | .word_base = RF_BASE, |
| 1064 | .word_size = sizeof(u32), |
| 1065 | .word_count = RF_SIZE / sizeof(u32), |
| 1066 | }, |
Anisse Astier | f2bd7f1 | 2012-04-19 15:53:10 +0200 | [diff] [blame] | 1067 | .rfcsr = { |
| 1068 | .read = rt2800_rfcsr_read, |
| 1069 | .write = rt2800_rfcsr_write, |
| 1070 | .word_base = RFCSR_BASE, |
| 1071 | .word_size = sizeof(u8), |
| 1072 | .word_count = RFCSR_SIZE / sizeof(u8), |
| 1073 | }, |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1074 | }; |
| 1075 | EXPORT_SYMBOL_GPL(rt2800_rt2x00debug); |
| 1076 | #endif /* CONFIG_RT2X00_LIB_DEBUGFS */ |
| 1077 | |
| 1078 | int rt2800_rfkill_poll(struct rt2x00_dev *rt2x00dev) |
| 1079 | { |
| 1080 | u32 reg; |
| 1081 | |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 1082 | if (rt2x00_rt(rt2x00dev, RT3290)) { |
| 1083 | rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, ®); |
| 1084 | return rt2x00_get_field32(reg, WLAN_GPIO_IN_BIT0); |
| 1085 | } else { |
Gertjan van Wingerde | 99bdf51 | 2012-08-31 19:22:13 +0200 | [diff] [blame] | 1086 | rt2800_register_read(rt2x00dev, GPIO_CTRL, ®); |
| 1087 | return rt2x00_get_field32(reg, GPIO_CTRL_VAL2); |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 1088 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1089 | } |
| 1090 | EXPORT_SYMBOL_GPL(rt2800_rfkill_poll); |
| 1091 | |
| 1092 | #ifdef CONFIG_RT2X00_LIB_LEDS |
| 1093 | static void rt2800_brightness_set(struct led_classdev *led_cdev, |
| 1094 | enum led_brightness brightness) |
| 1095 | { |
| 1096 | struct rt2x00_led *led = |
| 1097 | container_of(led_cdev, struct rt2x00_led, led_dev); |
| 1098 | unsigned int enabled = brightness != LED_OFF; |
| 1099 | unsigned int bg_mode = |
| 1100 | (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_2GHZ); |
| 1101 | unsigned int polarity = |
| 1102 | rt2x00_get_field16(led->rt2x00dev->led_mcu_reg, |
| 1103 | EEPROM_FREQ_LED_POLARITY); |
| 1104 | unsigned int ledmode = |
| 1105 | rt2x00_get_field16(led->rt2x00dev->led_mcu_reg, |
| 1106 | EEPROM_FREQ_LED_MODE); |
Layne Edwards | 44704e5 | 2011-04-18 15:26:00 +0200 | [diff] [blame] | 1107 | u32 reg; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1108 | |
Layne Edwards | 44704e5 | 2011-04-18 15:26:00 +0200 | [diff] [blame] | 1109 | /* Check for SoC (SOC devices don't support MCU requests) */ |
| 1110 | if (rt2x00_is_soc(led->rt2x00dev)) { |
| 1111 | rt2800_register_read(led->rt2x00dev, LED_CFG, ®); |
| 1112 | |
| 1113 | /* Set LED Polarity */ |
| 1114 | rt2x00_set_field32(®, LED_CFG_LED_POLAR, polarity); |
| 1115 | |
| 1116 | /* Set LED Mode */ |
| 1117 | if (led->type == LED_TYPE_RADIO) { |
| 1118 | rt2x00_set_field32(®, LED_CFG_G_LED_MODE, |
| 1119 | enabled ? 3 : 0); |
| 1120 | } else if (led->type == LED_TYPE_ASSOC) { |
| 1121 | rt2x00_set_field32(®, LED_CFG_Y_LED_MODE, |
| 1122 | enabled ? 3 : 0); |
| 1123 | } else if (led->type == LED_TYPE_QUALITY) { |
| 1124 | rt2x00_set_field32(®, LED_CFG_R_LED_MODE, |
| 1125 | enabled ? 3 : 0); |
| 1126 | } |
| 1127 | |
| 1128 | rt2800_register_write(led->rt2x00dev, LED_CFG, reg); |
| 1129 | |
| 1130 | } else { |
| 1131 | if (led->type == LED_TYPE_RADIO) { |
| 1132 | rt2800_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode, |
| 1133 | enabled ? 0x20 : 0); |
| 1134 | } else if (led->type == LED_TYPE_ASSOC) { |
| 1135 | rt2800_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode, |
| 1136 | enabled ? (bg_mode ? 0x60 : 0xa0) : 0x20); |
| 1137 | } else if (led->type == LED_TYPE_QUALITY) { |
| 1138 | /* |
| 1139 | * The brightness is divided into 6 levels (0 - 5), |
| 1140 | * The specs tell us the following levels: |
| 1141 | * 0, 1 ,3, 7, 15, 31 |
| 1142 | * to determine the level in a simple way we can simply |
| 1143 | * work with bitshifting: |
| 1144 | * (1 << level) - 1 |
| 1145 | */ |
| 1146 | rt2800_mcu_request(led->rt2x00dev, MCU_LED_STRENGTH, 0xff, |
| 1147 | (1 << brightness / (LED_FULL / 6)) - 1, |
| 1148 | polarity); |
| 1149 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1150 | } |
| 1151 | } |
| 1152 | |
Gertjan van Wingerde | b3579d6 | 2009-12-30 11:36:34 +0100 | [diff] [blame] | 1153 | static void rt2800_init_led(struct rt2x00_dev *rt2x00dev, |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1154 | struct rt2x00_led *led, enum led_type type) |
| 1155 | { |
| 1156 | led->rt2x00dev = rt2x00dev; |
| 1157 | led->type = type; |
| 1158 | led->led_dev.brightness_set = rt2800_brightness_set; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1159 | led->flags = LED_INITIALIZED; |
| 1160 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1161 | #endif /* CONFIG_RT2X00_LIB_LEDS */ |
| 1162 | |
| 1163 | /* |
| 1164 | * Configuration handlers. |
| 1165 | */ |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1166 | static void rt2800_config_wcid(struct rt2x00_dev *rt2x00dev, |
| 1167 | const u8 *address, |
| 1168 | int wcid) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1169 | { |
| 1170 | struct mac_wcid_entry wcid_entry; |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1171 | u32 offset; |
| 1172 | |
| 1173 | offset = MAC_WCID_ENTRY(wcid); |
| 1174 | |
| 1175 | memset(&wcid_entry, 0xff, sizeof(wcid_entry)); |
| 1176 | if (address) |
| 1177 | memcpy(wcid_entry.mac, address, ETH_ALEN); |
| 1178 | |
| 1179 | rt2800_register_multiwrite(rt2x00dev, offset, |
| 1180 | &wcid_entry, sizeof(wcid_entry)); |
| 1181 | } |
| 1182 | |
| 1183 | static void rt2800_delete_wcid_attr(struct rt2x00_dev *rt2x00dev, int wcid) |
| 1184 | { |
| 1185 | u32 offset; |
| 1186 | offset = MAC_WCID_ATTR_ENTRY(wcid); |
| 1187 | rt2800_register_write(rt2x00dev, offset, 0); |
| 1188 | } |
| 1189 | |
| 1190 | static void rt2800_config_wcid_attr_bssidx(struct rt2x00_dev *rt2x00dev, |
| 1191 | int wcid, u32 bssidx) |
| 1192 | { |
| 1193 | u32 offset = MAC_WCID_ATTR_ENTRY(wcid); |
| 1194 | u32 reg; |
| 1195 | |
| 1196 | /* |
| 1197 | * The BSS Idx numbers is split in a main value of 3 bits, |
| 1198 | * and a extended field for adding one additional bit to the value. |
| 1199 | */ |
| 1200 | rt2800_register_read(rt2x00dev, offset, ®); |
| 1201 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_BSS_IDX, (bssidx & 0x7)); |
| 1202 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_BSS_IDX_EXT, |
| 1203 | (bssidx & 0x8) >> 3); |
| 1204 | rt2800_register_write(rt2x00dev, offset, reg); |
| 1205 | } |
| 1206 | |
| 1207 | static void rt2800_config_wcid_attr_cipher(struct rt2x00_dev *rt2x00dev, |
| 1208 | struct rt2x00lib_crypto *crypto, |
| 1209 | struct ieee80211_key_conf *key) |
| 1210 | { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1211 | struct mac_iveiv_entry iveiv_entry; |
| 1212 | u32 offset; |
| 1213 | u32 reg; |
| 1214 | |
| 1215 | offset = MAC_WCID_ATTR_ENTRY(key->hw_key_idx); |
| 1216 | |
Ivo van Doorn | e4a0ab3 | 2010-06-14 22:14:19 +0200 | [diff] [blame] | 1217 | if (crypto->cmd == SET_KEY) { |
| 1218 | rt2800_register_read(rt2x00dev, offset, ®); |
| 1219 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_KEYTAB, |
| 1220 | !!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)); |
| 1221 | /* |
| 1222 | * Both the cipher as the BSS Idx numbers are split in a main |
| 1223 | * value of 3 bits, and a extended field for adding one additional |
| 1224 | * bit to the value. |
| 1225 | */ |
| 1226 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_CIPHER, |
| 1227 | (crypto->cipher & 0x7)); |
| 1228 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_CIPHER_EXT, |
| 1229 | (crypto->cipher & 0x8) >> 3); |
Ivo van Doorn | e4a0ab3 | 2010-06-14 22:14:19 +0200 | [diff] [blame] | 1230 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_RX_WIUDF, crypto->cipher); |
| 1231 | rt2800_register_write(rt2x00dev, offset, reg); |
| 1232 | } else { |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1233 | /* Delete the cipher without touching the bssidx */ |
| 1234 | rt2800_register_read(rt2x00dev, offset, ®); |
| 1235 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_KEYTAB, 0); |
| 1236 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_CIPHER, 0); |
| 1237 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_CIPHER_EXT, 0); |
| 1238 | rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_RX_WIUDF, 0); |
| 1239 | rt2800_register_write(rt2x00dev, offset, reg); |
Ivo van Doorn | e4a0ab3 | 2010-06-14 22:14:19 +0200 | [diff] [blame] | 1240 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1241 | |
| 1242 | offset = MAC_IVEIV_ENTRY(key->hw_key_idx); |
| 1243 | |
| 1244 | memset(&iveiv_entry, 0, sizeof(iveiv_entry)); |
| 1245 | if ((crypto->cipher == CIPHER_TKIP) || |
| 1246 | (crypto->cipher == CIPHER_TKIP_NO_MIC) || |
| 1247 | (crypto->cipher == CIPHER_AES)) |
| 1248 | iveiv_entry.iv[3] |= 0x20; |
| 1249 | iveiv_entry.iv[3] |= key->keyidx << 6; |
| 1250 | rt2800_register_multiwrite(rt2x00dev, offset, |
| 1251 | &iveiv_entry, sizeof(iveiv_entry)); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | int rt2800_config_shared_key(struct rt2x00_dev *rt2x00dev, |
| 1255 | struct rt2x00lib_crypto *crypto, |
| 1256 | struct ieee80211_key_conf *key) |
| 1257 | { |
| 1258 | struct hw_key_entry key_entry; |
| 1259 | struct rt2x00_field32 field; |
| 1260 | u32 offset; |
| 1261 | u32 reg; |
| 1262 | |
| 1263 | if (crypto->cmd == SET_KEY) { |
| 1264 | key->hw_key_idx = (4 * crypto->bssidx) + key->keyidx; |
| 1265 | |
| 1266 | memcpy(key_entry.key, crypto->key, |
| 1267 | sizeof(key_entry.key)); |
| 1268 | memcpy(key_entry.tx_mic, crypto->tx_mic, |
| 1269 | sizeof(key_entry.tx_mic)); |
| 1270 | memcpy(key_entry.rx_mic, crypto->rx_mic, |
| 1271 | sizeof(key_entry.rx_mic)); |
| 1272 | |
| 1273 | offset = SHARED_KEY_ENTRY(key->hw_key_idx); |
| 1274 | rt2800_register_multiwrite(rt2x00dev, offset, |
| 1275 | &key_entry, sizeof(key_entry)); |
| 1276 | } |
| 1277 | |
| 1278 | /* |
| 1279 | * The cipher types are stored over multiple registers |
| 1280 | * starting with SHARED_KEY_MODE_BASE each word will have |
| 1281 | * 32 bits and contains the cipher types for 2 bssidx each. |
| 1282 | * Using the correct defines correctly will cause overhead, |
| 1283 | * so just calculate the correct offset. |
| 1284 | */ |
| 1285 | field.bit_offset = 4 * (key->hw_key_idx % 8); |
| 1286 | field.bit_mask = 0x7 << field.bit_offset; |
| 1287 | |
| 1288 | offset = SHARED_KEY_MODE_ENTRY(key->hw_key_idx / 8); |
| 1289 | |
| 1290 | rt2800_register_read(rt2x00dev, offset, ®); |
| 1291 | rt2x00_set_field32(®, field, |
| 1292 | (crypto->cmd == SET_KEY) * crypto->cipher); |
| 1293 | rt2800_register_write(rt2x00dev, offset, reg); |
| 1294 | |
| 1295 | /* |
| 1296 | * Update WCID information |
| 1297 | */ |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1298 | rt2800_config_wcid(rt2x00dev, crypto->address, key->hw_key_idx); |
| 1299 | rt2800_config_wcid_attr_bssidx(rt2x00dev, key->hw_key_idx, |
| 1300 | crypto->bssidx); |
| 1301 | rt2800_config_wcid_attr_cipher(rt2x00dev, crypto, key); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1302 | |
| 1303 | return 0; |
| 1304 | } |
| 1305 | EXPORT_SYMBOL_GPL(rt2800_config_shared_key); |
| 1306 | |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1307 | static inline int rt2800_find_wcid(struct rt2x00_dev *rt2x00dev) |
Helmut Schaa | 1ed3811 | 2011-03-03 19:44:33 +0100 | [diff] [blame] | 1308 | { |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1309 | struct mac_wcid_entry wcid_entry; |
Helmut Schaa | 1ed3811 | 2011-03-03 19:44:33 +0100 | [diff] [blame] | 1310 | int idx; |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1311 | u32 offset; |
Helmut Schaa | 1ed3811 | 2011-03-03 19:44:33 +0100 | [diff] [blame] | 1312 | |
| 1313 | /* |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1314 | * Search for the first free WCID entry and return the corresponding |
| 1315 | * index. |
Helmut Schaa | 1ed3811 | 2011-03-03 19:44:33 +0100 | [diff] [blame] | 1316 | * |
| 1317 | * Make sure the WCID starts _after_ the last possible shared key |
| 1318 | * entry (>32). |
| 1319 | * |
| 1320 | * Since parts of the pairwise key table might be shared with |
| 1321 | * the beacon frame buffers 6 & 7 we should only write into the |
| 1322 | * first 222 entries. |
| 1323 | */ |
| 1324 | for (idx = 33; idx <= 222; idx++) { |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1325 | offset = MAC_WCID_ENTRY(idx); |
| 1326 | rt2800_register_multiread(rt2x00dev, offset, &wcid_entry, |
| 1327 | sizeof(wcid_entry)); |
| 1328 | if (is_broadcast_ether_addr(wcid_entry.mac)) |
Helmut Schaa | 1ed3811 | 2011-03-03 19:44:33 +0100 | [diff] [blame] | 1329 | return idx; |
| 1330 | } |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1331 | |
| 1332 | /* |
| 1333 | * Use -1 to indicate that we don't have any more space in the WCID |
| 1334 | * table. |
| 1335 | */ |
Helmut Schaa | 1ed3811 | 2011-03-03 19:44:33 +0100 | [diff] [blame] | 1336 | return -1; |
| 1337 | } |
| 1338 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1339 | int rt2800_config_pairwise_key(struct rt2x00_dev *rt2x00dev, |
| 1340 | struct rt2x00lib_crypto *crypto, |
| 1341 | struct ieee80211_key_conf *key) |
| 1342 | { |
| 1343 | struct hw_key_entry key_entry; |
| 1344 | u32 offset; |
| 1345 | |
| 1346 | if (crypto->cmd == SET_KEY) { |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1347 | /* |
| 1348 | * Allow key configuration only for STAs that are |
| 1349 | * known by the hw. |
| 1350 | */ |
| 1351 | if (crypto->wcid < 0) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1352 | return -ENOSPC; |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1353 | key->hw_key_idx = crypto->wcid; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1354 | |
| 1355 | memcpy(key_entry.key, crypto->key, |
| 1356 | sizeof(key_entry.key)); |
| 1357 | memcpy(key_entry.tx_mic, crypto->tx_mic, |
| 1358 | sizeof(key_entry.tx_mic)); |
| 1359 | memcpy(key_entry.rx_mic, crypto->rx_mic, |
| 1360 | sizeof(key_entry.rx_mic)); |
| 1361 | |
| 1362 | offset = PAIRWISE_KEY_ENTRY(key->hw_key_idx); |
| 1363 | rt2800_register_multiwrite(rt2x00dev, offset, |
| 1364 | &key_entry, sizeof(key_entry)); |
| 1365 | } |
| 1366 | |
| 1367 | /* |
| 1368 | * Update WCID information |
| 1369 | */ |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1370 | rt2800_config_wcid_attr_cipher(rt2x00dev, crypto, key); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1371 | |
| 1372 | return 0; |
| 1373 | } |
| 1374 | EXPORT_SYMBOL_GPL(rt2800_config_pairwise_key); |
| 1375 | |
Helmut Schaa | a2b1328 | 2011-09-08 14:38:01 +0200 | [diff] [blame] | 1376 | int rt2800_sta_add(struct rt2x00_dev *rt2x00dev, struct ieee80211_vif *vif, |
| 1377 | struct ieee80211_sta *sta) |
| 1378 | { |
| 1379 | int wcid; |
| 1380 | struct rt2x00_sta *sta_priv = sta_to_rt2x00_sta(sta); |
| 1381 | |
| 1382 | /* |
| 1383 | * Find next free WCID. |
| 1384 | */ |
| 1385 | wcid = rt2800_find_wcid(rt2x00dev); |
| 1386 | |
| 1387 | /* |
| 1388 | * Store selected wcid even if it is invalid so that we can |
| 1389 | * later decide if the STA is uploaded into the hw. |
| 1390 | */ |
| 1391 | sta_priv->wcid = wcid; |
| 1392 | |
| 1393 | /* |
| 1394 | * No space left in the device, however, we can still communicate |
| 1395 | * with the STA -> No error. |
| 1396 | */ |
| 1397 | if (wcid < 0) |
| 1398 | return 0; |
| 1399 | |
| 1400 | /* |
| 1401 | * Clean up WCID attributes and write STA address to the device. |
| 1402 | */ |
| 1403 | rt2800_delete_wcid_attr(rt2x00dev, wcid); |
| 1404 | rt2800_config_wcid(rt2x00dev, sta->addr, wcid); |
| 1405 | rt2800_config_wcid_attr_bssidx(rt2x00dev, wcid, |
| 1406 | rt2x00lib_get_bssidx(rt2x00dev, vif)); |
| 1407 | return 0; |
| 1408 | } |
| 1409 | EXPORT_SYMBOL_GPL(rt2800_sta_add); |
| 1410 | |
| 1411 | int rt2800_sta_remove(struct rt2x00_dev *rt2x00dev, int wcid) |
| 1412 | { |
| 1413 | /* |
| 1414 | * Remove WCID entry, no need to clean the attributes as they will |
| 1415 | * get renewed when the WCID is reused. |
| 1416 | */ |
| 1417 | rt2800_config_wcid(rt2x00dev, NULL, wcid); |
| 1418 | |
| 1419 | return 0; |
| 1420 | } |
| 1421 | EXPORT_SYMBOL_GPL(rt2800_sta_remove); |
| 1422 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1423 | void rt2800_config_filter(struct rt2x00_dev *rt2x00dev, |
| 1424 | const unsigned int filter_flags) |
| 1425 | { |
| 1426 | u32 reg; |
| 1427 | |
| 1428 | /* |
| 1429 | * Start configuration steps. |
| 1430 | * Note that the version error will always be dropped |
| 1431 | * and broadcast frames will always be accepted since |
| 1432 | * there is no filter for it at this time. |
| 1433 | */ |
| 1434 | rt2800_register_read(rt2x00dev, RX_FILTER_CFG, ®); |
| 1435 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CRC_ERROR, |
| 1436 | !(filter_flags & FIF_FCSFAIL)); |
| 1437 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_PHY_ERROR, |
| 1438 | !(filter_flags & FIF_PLCPFAIL)); |
| 1439 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_NOT_TO_ME, |
| 1440 | !(filter_flags & FIF_PROMISC_IN_BSS)); |
| 1441 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_NOT_MY_BSSD, 0); |
| 1442 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_VER_ERROR, 1); |
| 1443 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_MULTICAST, |
| 1444 | !(filter_flags & FIF_ALLMULTI)); |
| 1445 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_BROADCAST, 0); |
| 1446 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_DUPLICATE, 1); |
| 1447 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CF_END_ACK, |
| 1448 | !(filter_flags & FIF_CONTROL)); |
| 1449 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CF_END, |
| 1450 | !(filter_flags & FIF_CONTROL)); |
| 1451 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_ACK, |
| 1452 | !(filter_flags & FIF_CONTROL)); |
| 1453 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CTS, |
| 1454 | !(filter_flags & FIF_CONTROL)); |
| 1455 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_RTS, |
| 1456 | !(filter_flags & FIF_CONTROL)); |
| 1457 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_PSPOLL, |
| 1458 | !(filter_flags & FIF_PSPOLL)); |
Helmut Schaa | 84e9e8ebd | 2013-01-17 17:34:32 +0100 | [diff] [blame] | 1459 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_BA, 0); |
Helmut Schaa | 4883993 | 2011-11-24 09:13:26 +0100 | [diff] [blame] | 1460 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_BAR, |
| 1461 | !(filter_flags & FIF_CONTROL)); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1462 | rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CNTL, |
| 1463 | !(filter_flags & FIF_CONTROL)); |
| 1464 | rt2800_register_write(rt2x00dev, RX_FILTER_CFG, reg); |
| 1465 | } |
| 1466 | EXPORT_SYMBOL_GPL(rt2800_config_filter); |
| 1467 | |
| 1468 | void rt2800_config_intf(struct rt2x00_dev *rt2x00dev, struct rt2x00_intf *intf, |
| 1469 | struct rt2x00intf_conf *conf, const unsigned int flags) |
| 1470 | { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1471 | u32 reg; |
Helmut Schaa | fa8b4b2 | 2010-11-04 20:42:36 +0100 | [diff] [blame] | 1472 | bool update_bssid = false; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1473 | |
| 1474 | if (flags & CONFIG_UPDATE_TYPE) { |
| 1475 | /* |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1476 | * Enable synchronisation. |
| 1477 | */ |
| 1478 | rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1479 | rt2x00_set_field32(®, BCN_TIME_CFG_TSF_SYNC, conf->sync); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1480 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
Helmut Schaa | 15a533c | 2011-04-18 15:28:04 +0200 | [diff] [blame] | 1481 | |
| 1482 | if (conf->sync == TSF_SYNC_AP_NONE) { |
| 1483 | /* |
| 1484 | * Tune beacon queue transmit parameters for AP mode |
| 1485 | */ |
| 1486 | rt2800_register_read(rt2x00dev, TBTT_SYNC_CFG, ®); |
| 1487 | rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_CWMIN, 0); |
| 1488 | rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_AIFSN, 1); |
| 1489 | rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_EXP_WIN, 32); |
| 1490 | rt2x00_set_field32(®, TBTT_SYNC_CFG_TBTT_ADJUST, 0); |
| 1491 | rt2800_register_write(rt2x00dev, TBTT_SYNC_CFG, reg); |
| 1492 | } else { |
| 1493 | rt2800_register_read(rt2x00dev, TBTT_SYNC_CFG, ®); |
| 1494 | rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_CWMIN, 4); |
| 1495 | rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_AIFSN, 2); |
| 1496 | rt2x00_set_field32(®, TBTT_SYNC_CFG_BCN_EXP_WIN, 32); |
| 1497 | rt2x00_set_field32(®, TBTT_SYNC_CFG_TBTT_ADJUST, 16); |
| 1498 | rt2800_register_write(rt2x00dev, TBTT_SYNC_CFG, reg); |
| 1499 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | if (flags & CONFIG_UPDATE_MAC) { |
Helmut Schaa | fa8b4b2 | 2010-11-04 20:42:36 +0100 | [diff] [blame] | 1503 | if (flags & CONFIG_UPDATE_TYPE && |
| 1504 | conf->sync == TSF_SYNC_AP_NONE) { |
| 1505 | /* |
| 1506 | * The BSSID register has to be set to our own mac |
| 1507 | * address in AP mode. |
| 1508 | */ |
| 1509 | memcpy(conf->bssid, conf->mac, sizeof(conf->mac)); |
| 1510 | update_bssid = true; |
| 1511 | } |
| 1512 | |
Ivo van Doorn | c600c82 | 2010-08-30 21:14:15 +0200 | [diff] [blame] | 1513 | if (!is_zero_ether_addr((const u8 *)conf->mac)) { |
| 1514 | reg = le32_to_cpu(conf->mac[1]); |
| 1515 | rt2x00_set_field32(®, MAC_ADDR_DW1_UNICAST_TO_ME_MASK, 0xff); |
| 1516 | conf->mac[1] = cpu_to_le32(reg); |
| 1517 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1518 | |
| 1519 | rt2800_register_multiwrite(rt2x00dev, MAC_ADDR_DW0, |
| 1520 | conf->mac, sizeof(conf->mac)); |
| 1521 | } |
| 1522 | |
Helmut Schaa | fa8b4b2 | 2010-11-04 20:42:36 +0100 | [diff] [blame] | 1523 | if ((flags & CONFIG_UPDATE_BSSID) || update_bssid) { |
Ivo van Doorn | c600c82 | 2010-08-30 21:14:15 +0200 | [diff] [blame] | 1524 | if (!is_zero_ether_addr((const u8 *)conf->bssid)) { |
| 1525 | reg = le32_to_cpu(conf->bssid[1]); |
| 1526 | rt2x00_set_field32(®, MAC_BSSID_DW1_BSS_ID_MASK, 3); |
| 1527 | rt2x00_set_field32(®, MAC_BSSID_DW1_BSS_BCN_NUM, 7); |
| 1528 | conf->bssid[1] = cpu_to_le32(reg); |
| 1529 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1530 | |
| 1531 | rt2800_register_multiwrite(rt2x00dev, MAC_BSSID_DW0, |
| 1532 | conf->bssid, sizeof(conf->bssid)); |
| 1533 | } |
| 1534 | } |
| 1535 | EXPORT_SYMBOL_GPL(rt2800_config_intf); |
| 1536 | |
Helmut Schaa | 87c1915 | 2010-10-02 11:28:34 +0200 | [diff] [blame] | 1537 | static void rt2800_config_ht_opmode(struct rt2x00_dev *rt2x00dev, |
| 1538 | struct rt2x00lib_erp *erp) |
| 1539 | { |
| 1540 | bool any_sta_nongf = !!(erp->ht_opmode & |
| 1541 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT); |
| 1542 | u8 protection = erp->ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION; |
| 1543 | u8 mm20_mode, mm40_mode, gf20_mode, gf40_mode; |
| 1544 | u16 mm20_rate, mm40_rate, gf20_rate, gf40_rate; |
| 1545 | u32 reg; |
| 1546 | |
| 1547 | /* default protection rate for HT20: OFDM 24M */ |
| 1548 | mm20_rate = gf20_rate = 0x4004; |
| 1549 | |
| 1550 | /* default protection rate for HT40: duplicate OFDM 24M */ |
| 1551 | mm40_rate = gf40_rate = 0x4084; |
| 1552 | |
| 1553 | switch (protection) { |
| 1554 | case IEEE80211_HT_OP_MODE_PROTECTION_NONE: |
| 1555 | /* |
| 1556 | * All STAs in this BSS are HT20/40 but there might be |
| 1557 | * STAs not supporting greenfield mode. |
| 1558 | * => Disable protection for HT transmissions. |
| 1559 | */ |
| 1560 | mm20_mode = mm40_mode = gf20_mode = gf40_mode = 0; |
| 1561 | |
| 1562 | break; |
| 1563 | case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ: |
| 1564 | /* |
| 1565 | * All STAs in this BSS are HT20 or HT20/40 but there |
| 1566 | * might be STAs not supporting greenfield mode. |
| 1567 | * => Protect all HT40 transmissions. |
| 1568 | */ |
| 1569 | mm20_mode = gf20_mode = 0; |
| 1570 | mm40_mode = gf40_mode = 2; |
| 1571 | |
| 1572 | break; |
| 1573 | case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER: |
| 1574 | /* |
| 1575 | * Nonmember protection: |
| 1576 | * According to 802.11n we _should_ protect all |
| 1577 | * HT transmissions (but we don't have to). |
| 1578 | * |
| 1579 | * But if cts_protection is enabled we _shall_ protect |
| 1580 | * all HT transmissions using a CCK rate. |
| 1581 | * |
| 1582 | * And if any station is non GF we _shall_ protect |
| 1583 | * GF transmissions. |
| 1584 | * |
| 1585 | * We decide to protect everything |
| 1586 | * -> fall through to mixed mode. |
| 1587 | */ |
| 1588 | case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED: |
| 1589 | /* |
| 1590 | * Legacy STAs are present |
| 1591 | * => Protect all HT transmissions. |
| 1592 | */ |
| 1593 | mm20_mode = mm40_mode = gf20_mode = gf40_mode = 2; |
| 1594 | |
| 1595 | /* |
| 1596 | * If erp protection is needed we have to protect HT |
| 1597 | * transmissions with CCK 11M long preamble. |
| 1598 | */ |
| 1599 | if (erp->cts_protection) { |
| 1600 | /* don't duplicate RTS/CTS in CCK mode */ |
| 1601 | mm20_rate = mm40_rate = 0x0003; |
| 1602 | gf20_rate = gf40_rate = 0x0003; |
| 1603 | } |
| 1604 | break; |
Joe Perches | 6403eab | 2011-06-03 11:51:20 +0000 | [diff] [blame] | 1605 | } |
Helmut Schaa | 87c1915 | 2010-10-02 11:28:34 +0200 | [diff] [blame] | 1606 | |
| 1607 | /* check for STAs not supporting greenfield mode */ |
| 1608 | if (any_sta_nongf) |
| 1609 | gf20_mode = gf40_mode = 2; |
| 1610 | |
| 1611 | /* Update HT protection config */ |
| 1612 | rt2800_register_read(rt2x00dev, MM20_PROT_CFG, ®); |
| 1613 | rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_RATE, mm20_rate); |
| 1614 | rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_CTRL, mm20_mode); |
| 1615 | rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg); |
| 1616 | |
| 1617 | rt2800_register_read(rt2x00dev, MM40_PROT_CFG, ®); |
| 1618 | rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_RATE, mm40_rate); |
| 1619 | rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_CTRL, mm40_mode); |
| 1620 | rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg); |
| 1621 | |
| 1622 | rt2800_register_read(rt2x00dev, GF20_PROT_CFG, ®); |
| 1623 | rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_RATE, gf20_rate); |
| 1624 | rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_CTRL, gf20_mode); |
| 1625 | rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg); |
| 1626 | |
| 1627 | rt2800_register_read(rt2x00dev, GF40_PROT_CFG, ®); |
| 1628 | rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_RATE, gf40_rate); |
| 1629 | rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_CTRL, gf40_mode); |
| 1630 | rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg); |
| 1631 | } |
| 1632 | |
Helmut Schaa | 0204464 | 2010-09-08 20:56:32 +0200 | [diff] [blame] | 1633 | void rt2800_config_erp(struct rt2x00_dev *rt2x00dev, struct rt2x00lib_erp *erp, |
| 1634 | u32 changed) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1635 | { |
| 1636 | u32 reg; |
| 1637 | |
Helmut Schaa | 0204464 | 2010-09-08 20:56:32 +0200 | [diff] [blame] | 1638 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
| 1639 | rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, ®); |
| 1640 | rt2x00_set_field32(®, AUTO_RSP_CFG_BAC_ACK_POLICY, |
| 1641 | !!erp->short_preamble); |
| 1642 | rt2x00_set_field32(®, AUTO_RSP_CFG_AR_PREAMBLE, |
| 1643 | !!erp->short_preamble); |
| 1644 | rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg); |
| 1645 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1646 | |
Helmut Schaa | 0204464 | 2010-09-08 20:56:32 +0200 | [diff] [blame] | 1647 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
| 1648 | rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, ®); |
| 1649 | rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_CTRL, |
| 1650 | erp->cts_protection ? 2 : 0); |
| 1651 | rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg); |
| 1652 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1653 | |
Helmut Schaa | 0204464 | 2010-09-08 20:56:32 +0200 | [diff] [blame] | 1654 | if (changed & BSS_CHANGED_BASIC_RATES) { |
| 1655 | rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE, |
| 1656 | erp->basic_rates); |
| 1657 | rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003); |
| 1658 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1659 | |
Helmut Schaa | 0204464 | 2010-09-08 20:56:32 +0200 | [diff] [blame] | 1660 | if (changed & BSS_CHANGED_ERP_SLOT) { |
| 1661 | rt2800_register_read(rt2x00dev, BKOFF_SLOT_CFG, ®); |
| 1662 | rt2x00_set_field32(®, BKOFF_SLOT_CFG_SLOT_TIME, |
| 1663 | erp->slot_time); |
| 1664 | rt2800_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1665 | |
Helmut Schaa | 0204464 | 2010-09-08 20:56:32 +0200 | [diff] [blame] | 1666 | rt2800_register_read(rt2x00dev, XIFS_TIME_CFG, ®); |
| 1667 | rt2x00_set_field32(®, XIFS_TIME_CFG_EIFS, erp->eifs); |
| 1668 | rt2800_register_write(rt2x00dev, XIFS_TIME_CFG, reg); |
| 1669 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1670 | |
Helmut Schaa | 0204464 | 2010-09-08 20:56:32 +0200 | [diff] [blame] | 1671 | if (changed & BSS_CHANGED_BEACON_INT) { |
| 1672 | rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®); |
| 1673 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_INTERVAL, |
| 1674 | erp->beacon_int * 16); |
| 1675 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
| 1676 | } |
Helmut Schaa | 87c1915 | 2010-10-02 11:28:34 +0200 | [diff] [blame] | 1677 | |
| 1678 | if (changed & BSS_CHANGED_HT) |
| 1679 | rt2800_config_ht_opmode(rt2x00dev, erp); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1680 | } |
| 1681 | EXPORT_SYMBOL_GPL(rt2800_config_erp); |
| 1682 | |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 1683 | static void rt2800_config_3572bt_ant(struct rt2x00_dev *rt2x00dev) |
| 1684 | { |
| 1685 | u32 reg; |
| 1686 | u16 eeprom; |
| 1687 | u8 led_ctrl, led_g_mode, led_r_mode; |
| 1688 | |
| 1689 | rt2800_register_read(rt2x00dev, GPIO_SWITCH, ®); |
| 1690 | if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ) { |
| 1691 | rt2x00_set_field32(®, GPIO_SWITCH_0, 1); |
| 1692 | rt2x00_set_field32(®, GPIO_SWITCH_1, 1); |
| 1693 | } else { |
| 1694 | rt2x00_set_field32(®, GPIO_SWITCH_0, 0); |
| 1695 | rt2x00_set_field32(®, GPIO_SWITCH_1, 0); |
| 1696 | } |
| 1697 | rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg); |
| 1698 | |
| 1699 | rt2800_register_read(rt2x00dev, LED_CFG, ®); |
| 1700 | led_g_mode = rt2x00_get_field32(reg, LED_CFG_LED_POLAR) ? 3 : 0; |
| 1701 | led_r_mode = rt2x00_get_field32(reg, LED_CFG_LED_POLAR) ? 0 : 3; |
| 1702 | if (led_g_mode != rt2x00_get_field32(reg, LED_CFG_G_LED_MODE) || |
| 1703 | led_r_mode != rt2x00_get_field32(reg, LED_CFG_R_LED_MODE)) { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 1704 | rt2800_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 1705 | led_ctrl = rt2x00_get_field16(eeprom, EEPROM_FREQ_LED_MODE); |
| 1706 | if (led_ctrl == 0 || led_ctrl > 0x40) { |
| 1707 | rt2x00_set_field32(®, LED_CFG_G_LED_MODE, led_g_mode); |
| 1708 | rt2x00_set_field32(®, LED_CFG_R_LED_MODE, led_r_mode); |
| 1709 | rt2800_register_write(rt2x00dev, LED_CFG, reg); |
| 1710 | } else { |
| 1711 | rt2800_mcu_request(rt2x00dev, MCU_BAND_SELECT, 0xff, |
| 1712 | (led_g_mode << 2) | led_r_mode, 1); |
| 1713 | } |
| 1714 | } |
| 1715 | } |
| 1716 | |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1717 | static void rt2800_set_ant_diversity(struct rt2x00_dev *rt2x00dev, |
| 1718 | enum antenna ant) |
| 1719 | { |
| 1720 | u32 reg; |
| 1721 | u8 eesk_pin = (ant == ANTENNA_A) ? 1 : 0; |
| 1722 | u8 gpio_bit3 = (ant == ANTENNA_A) ? 0 : 1; |
| 1723 | |
| 1724 | if (rt2x00_is_pci(rt2x00dev)) { |
| 1725 | rt2800_register_read(rt2x00dev, E2PROM_CSR, ®); |
| 1726 | rt2x00_set_field32(®, E2PROM_CSR_DATA_CLOCK, eesk_pin); |
| 1727 | rt2800_register_write(rt2x00dev, E2PROM_CSR, reg); |
| 1728 | } else if (rt2x00_is_usb(rt2x00dev)) |
| 1729 | rt2800_mcu_request(rt2x00dev, MCU_ANT_SELECT, 0xff, |
| 1730 | eesk_pin, 0); |
| 1731 | |
Gertjan van Wingerde | 99bdf51 | 2012-08-31 19:22:13 +0200 | [diff] [blame] | 1732 | rt2800_register_read(rt2x00dev, GPIO_CTRL, ®); |
| 1733 | rt2x00_set_field32(®, GPIO_CTRL_DIR3, 0); |
| 1734 | rt2x00_set_field32(®, GPIO_CTRL_VAL3, gpio_bit3); |
| 1735 | rt2800_register_write(rt2x00dev, GPIO_CTRL, reg); |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1736 | } |
| 1737 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1738 | void rt2800_config_ant(struct rt2x00_dev *rt2x00dev, struct antenna_setup *ant) |
| 1739 | { |
| 1740 | u8 r1; |
| 1741 | u8 r3; |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1742 | u16 eeprom; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1743 | |
| 1744 | rt2800_bbp_read(rt2x00dev, 1, &r1); |
| 1745 | rt2800_bbp_read(rt2x00dev, 3, &r3); |
| 1746 | |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 1747 | if (rt2x00_rt(rt2x00dev, RT3572) && |
| 1748 | test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags)) |
| 1749 | rt2800_config_3572bt_ant(rt2x00dev); |
| 1750 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1751 | /* |
| 1752 | * Configure the TX antenna. |
| 1753 | */ |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1754 | switch (ant->tx_chain_num) { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1755 | case 1: |
| 1756 | rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1757 | break; |
| 1758 | case 2: |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 1759 | if (rt2x00_rt(rt2x00dev, RT3572) && |
| 1760 | test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags)) |
| 1761 | rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 1); |
| 1762 | else |
| 1763 | rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1764 | break; |
| 1765 | case 3: |
Gabor Juhos | 4788ac1 | 2013-07-08 16:08:21 +0200 | [diff] [blame] | 1766 | rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1767 | break; |
| 1768 | } |
| 1769 | |
| 1770 | /* |
| 1771 | * Configure the RX antenna. |
| 1772 | */ |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1773 | switch (ant->rx_chain_num) { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1774 | case 1: |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1775 | if (rt2x00_rt(rt2x00dev, RT3070) || |
| 1776 | rt2x00_rt(rt2x00dev, RT3090) || |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 1777 | rt2x00_rt(rt2x00dev, RT3352) || |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1778 | rt2x00_rt(rt2x00dev, RT3390)) { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 1779 | rt2800_eeprom_read(rt2x00dev, |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1780 | EEPROM_NIC_CONF1, &eeprom); |
| 1781 | if (rt2x00_get_field16(eeprom, |
| 1782 | EEPROM_NIC_CONF1_ANT_DIVERSITY)) |
| 1783 | rt2800_set_ant_diversity(rt2x00dev, |
| 1784 | rt2x00dev->default_ant.rx); |
| 1785 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1786 | rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0); |
| 1787 | break; |
| 1788 | case 2: |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 1789 | if (rt2x00_rt(rt2x00dev, RT3572) && |
| 1790 | test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags)) { |
| 1791 | rt2x00_set_field8(&r3, BBP3_RX_ADC, 1); |
| 1792 | rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, |
| 1793 | rt2x00dev->curr_band == IEEE80211_BAND_5GHZ); |
| 1794 | rt2800_set_ant_diversity(rt2x00dev, ANTENNA_B); |
| 1795 | } else { |
| 1796 | rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 1); |
| 1797 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1798 | break; |
| 1799 | case 3: |
| 1800 | rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 2); |
| 1801 | break; |
| 1802 | } |
| 1803 | |
| 1804 | rt2800_bbp_write(rt2x00dev, 3, r3); |
| 1805 | rt2800_bbp_write(rt2x00dev, 1, r1); |
Gabor Juhos | 5cddb3c | 2013-07-08 16:08:22 +0200 | [diff] [blame] | 1806 | |
| 1807 | if (rt2x00_rt(rt2x00dev, RT3593)) { |
| 1808 | if (ant->rx_chain_num == 1) |
| 1809 | rt2800_bbp_write(rt2x00dev, 86, 0x00); |
| 1810 | else |
| 1811 | rt2800_bbp_write(rt2x00dev, 86, 0x46); |
| 1812 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1813 | } |
| 1814 | EXPORT_SYMBOL_GPL(rt2800_config_ant); |
| 1815 | |
| 1816 | static void rt2800_config_lna_gain(struct rt2x00_dev *rt2x00dev, |
| 1817 | struct rt2x00lib_conf *libconf) |
| 1818 | { |
| 1819 | u16 eeprom; |
| 1820 | short lna_gain; |
| 1821 | |
| 1822 | if (libconf->rf.channel <= 14) { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 1823 | rt2800_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1824 | lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_BG); |
| 1825 | } else if (libconf->rf.channel <= 64) { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 1826 | rt2800_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1827 | lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_A0); |
| 1828 | } else if (libconf->rf.channel <= 128) { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 1829 | rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1830 | lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG2_LNA_A1); |
| 1831 | } else { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 1832 | rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1833 | lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_A2_LNA_A2); |
| 1834 | } |
| 1835 | |
| 1836 | rt2x00dev->lna_gain = lna_gain; |
| 1837 | } |
| 1838 | |
Gertjan van Wingerde | 06855ef | 2010-04-11 14:31:07 +0200 | [diff] [blame] | 1839 | static void rt2800_config_channel_rf2xxx(struct rt2x00_dev *rt2x00dev, |
| 1840 | struct ieee80211_conf *conf, |
| 1841 | struct rf_channel *rf, |
| 1842 | struct channel_info *info) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1843 | { |
| 1844 | rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset); |
| 1845 | |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1846 | if (rt2x00dev->default_ant.tx_chain_num == 1) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1847 | rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_TX1, 1); |
| 1848 | |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1849 | if (rt2x00dev->default_ant.rx_chain_num == 1) { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1850 | rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX1, 1); |
| 1851 | rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1); |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 1852 | } else if (rt2x00dev->default_ant.rx_chain_num == 2) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1853 | rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1); |
| 1854 | |
| 1855 | if (rf->channel > 14) { |
| 1856 | /* |
| 1857 | * 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] | 1858 | * make it a positive value (Minimum value is -7). |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1859 | * However this means that values between 0 and 7 have |
| 1860 | * double meaning, and we should set a 7DBm boost flag. |
| 1861 | */ |
| 1862 | rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A_7DBM_BOOST, |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1863 | (info->default_power1 >= 0)); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1864 | |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1865 | if (info->default_power1 < 0) |
| 1866 | info->default_power1 += 7; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1867 | |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1868 | rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A, info->default_power1); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1869 | |
| 1870 | rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A_7DBM_BOOST, |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1871 | (info->default_power2 >= 0)); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1872 | |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1873 | if (info->default_power2 < 0) |
| 1874 | info->default_power2 += 7; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1875 | |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1876 | rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A, info->default_power2); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1877 | } else { |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1878 | rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_G, info->default_power1); |
| 1879 | rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_G, info->default_power2); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1880 | } |
| 1881 | |
| 1882 | rt2x00_set_field32(&rf->rf4, RF4_HT40, conf_is_ht40(conf)); |
| 1883 | |
| 1884 | rt2800_rf_write(rt2x00dev, 1, rf->rf1); |
| 1885 | rt2800_rf_write(rt2x00dev, 2, rf->rf2); |
| 1886 | rt2800_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004); |
| 1887 | rt2800_rf_write(rt2x00dev, 4, rf->rf4); |
| 1888 | |
| 1889 | udelay(200); |
| 1890 | |
| 1891 | rt2800_rf_write(rt2x00dev, 1, rf->rf1); |
| 1892 | rt2800_rf_write(rt2x00dev, 2, rf->rf2); |
| 1893 | rt2800_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004); |
| 1894 | rt2800_rf_write(rt2x00dev, 4, rf->rf4); |
| 1895 | |
| 1896 | udelay(200); |
| 1897 | |
| 1898 | rt2800_rf_write(rt2x00dev, 1, rf->rf1); |
| 1899 | rt2800_rf_write(rt2x00dev, 2, rf->rf2); |
| 1900 | rt2800_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004); |
| 1901 | rt2800_rf_write(rt2x00dev, 4, rf->rf4); |
| 1902 | } |
| 1903 | |
Gertjan van Wingerde | 06855ef | 2010-04-11 14:31:07 +0200 | [diff] [blame] | 1904 | static void rt2800_config_channel_rf3xxx(struct rt2x00_dev *rt2x00dev, |
| 1905 | struct ieee80211_conf *conf, |
| 1906 | struct rf_channel *rf, |
| 1907 | struct channel_info *info) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1908 | { |
Gertjan van Wingerde | 3a1c012 | 2012-02-06 23:45:07 +0100 | [diff] [blame] | 1909 | struct rt2800_drv_data *drv_data = rt2x00dev->drv_data; |
Stanislaw Gruszka | f1f12f9 | 2012-01-30 16:17:59 +0100 | [diff] [blame] | 1910 | u8 rfcsr, calib_tx, calib_rx; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1911 | |
| 1912 | rt2800_rfcsr_write(rt2x00dev, 2, rf->rf1); |
Stanislaw Gruszka | 7f4666a | 2012-01-30 16:17:56 +0100 | [diff] [blame] | 1913 | |
| 1914 | rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr); |
| 1915 | rt2x00_set_field8(&rfcsr, RFCSR3_K, rf->rf3); |
| 1916 | rt2800_rfcsr_write(rt2x00dev, 3, rfcsr); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1917 | |
| 1918 | rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr); |
Gertjan van Wingerde | fab799c | 2010-04-11 14:31:08 +0200 | [diff] [blame] | 1919 | rt2x00_set_field8(&rfcsr, RFCSR6_R1, rf->rf2); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1920 | rt2800_rfcsr_write(rt2x00dev, 6, rfcsr); |
| 1921 | |
| 1922 | rt2800_rfcsr_read(rt2x00dev, 12, &rfcsr); |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1923 | rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER, info->default_power1); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1924 | rt2800_rfcsr_write(rt2x00dev, 12, rfcsr); |
| 1925 | |
Helmut Schaa | 5a67396 | 2010-04-23 15:54:43 +0200 | [diff] [blame] | 1926 | rt2800_rfcsr_read(rt2x00dev, 13, &rfcsr); |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 1927 | rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER, info->default_power2); |
Helmut Schaa | 5a67396 | 2010-04-23 15:54:43 +0200 | [diff] [blame] | 1928 | rt2800_rfcsr_write(rt2x00dev, 13, rfcsr); |
| 1929 | |
Stanislaw Gruszka | e3bab19 | 2012-01-30 16:17:57 +0100 | [diff] [blame] | 1930 | rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr); |
| 1931 | rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0); |
Gertjan van Wingerde | 7ad6303 | 2012-09-16 22:29:53 +0200 | [diff] [blame] | 1932 | rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, |
| 1933 | rt2x00dev->default_ant.rx_chain_num <= 1); |
| 1934 | rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, |
| 1935 | rt2x00dev->default_ant.rx_chain_num <= 2); |
Stanislaw Gruszka | e3bab19 | 2012-01-30 16:17:57 +0100 | [diff] [blame] | 1936 | rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0); |
Gertjan van Wingerde | 7ad6303 | 2012-09-16 22:29:53 +0200 | [diff] [blame] | 1937 | rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, |
| 1938 | rt2x00dev->default_ant.tx_chain_num <= 1); |
| 1939 | rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, |
| 1940 | rt2x00dev->default_ant.tx_chain_num <= 2); |
Stanislaw Gruszka | e3bab19 | 2012-01-30 16:17:57 +0100 | [diff] [blame] | 1941 | rt2800_rfcsr_write(rt2x00dev, 1, rfcsr); |
| 1942 | |
Stanislaw Gruszka | 3e0c764 | 2012-01-30 16:17:58 +0100 | [diff] [blame] | 1943 | rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr); |
| 1944 | rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1); |
| 1945 | rt2800_rfcsr_write(rt2x00dev, 30, rfcsr); |
| 1946 | msleep(1); |
| 1947 | rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0); |
| 1948 | rt2800_rfcsr_write(rt2x00dev, 30, rfcsr); |
| 1949 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1950 | rt2800_rfcsr_read(rt2x00dev, 23, &rfcsr); |
| 1951 | rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset); |
| 1952 | rt2800_rfcsr_write(rt2x00dev, 23, rfcsr); |
| 1953 | |
Stanislaw Gruszka | f1f12f9 | 2012-01-30 16:17:59 +0100 | [diff] [blame] | 1954 | if (rt2x00_rt(rt2x00dev, RT3390)) { |
| 1955 | calib_tx = conf_is_ht40(conf) ? 0x68 : 0x4f; |
| 1956 | calib_rx = conf_is_ht40(conf) ? 0x6f : 0x4f; |
| 1957 | } else { |
Gertjan van Wingerde | 3a1c012 | 2012-02-06 23:45:07 +0100 | [diff] [blame] | 1958 | if (conf_is_ht40(conf)) { |
| 1959 | calib_tx = drv_data->calibration_bw40; |
| 1960 | calib_rx = drv_data->calibration_bw40; |
| 1961 | } else { |
| 1962 | calib_tx = drv_data->calibration_bw20; |
| 1963 | calib_rx = drv_data->calibration_bw20; |
| 1964 | } |
Stanislaw Gruszka | f1f12f9 | 2012-01-30 16:17:59 +0100 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | rt2800_rfcsr_read(rt2x00dev, 24, &rfcsr); |
| 1968 | rt2x00_set_field8(&rfcsr, RFCSR24_TX_CALIB, calib_tx); |
| 1969 | rt2800_rfcsr_write(rt2x00dev, 24, rfcsr); |
| 1970 | |
| 1971 | rt2800_rfcsr_read(rt2x00dev, 31, &rfcsr); |
| 1972 | rt2x00_set_field8(&rfcsr, RFCSR31_RX_CALIB, calib_rx); |
| 1973 | rt2800_rfcsr_write(rt2x00dev, 31, rfcsr); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1974 | |
Gertjan van Wingerde | 7197690 | 2010-03-24 21:42:36 +0100 | [diff] [blame] | 1975 | rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1976 | rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1); |
Gertjan van Wingerde | 7197690 | 2010-03-24 21:42:36 +0100 | [diff] [blame] | 1977 | rt2800_rfcsr_write(rt2x00dev, 7, rfcsr); |
Stanislaw Gruszka | 3e0c764 | 2012-01-30 16:17:58 +0100 | [diff] [blame] | 1978 | |
| 1979 | rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr); |
| 1980 | rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1); |
| 1981 | rt2800_rfcsr_write(rt2x00dev, 30, rfcsr); |
| 1982 | msleep(1); |
| 1983 | rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0); |
| 1984 | rt2800_rfcsr_write(rt2x00dev, 30, rfcsr); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 1985 | } |
| 1986 | |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 1987 | static void rt2800_config_channel_rf3052(struct rt2x00_dev *rt2x00dev, |
| 1988 | struct ieee80211_conf *conf, |
| 1989 | struct rf_channel *rf, |
| 1990 | struct channel_info *info) |
| 1991 | { |
Gertjan van Wingerde | 3a1c012 | 2012-02-06 23:45:07 +0100 | [diff] [blame] | 1992 | struct rt2800_drv_data *drv_data = rt2x00dev->drv_data; |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 1993 | u8 rfcsr; |
| 1994 | u32 reg; |
| 1995 | |
| 1996 | if (rf->channel <= 14) { |
Gertjan van Wingerde | 5d137df | 2012-02-06 23:45:09 +0100 | [diff] [blame] | 1997 | rt2800_bbp_write(rt2x00dev, 25, drv_data->bbp25); |
| 1998 | rt2800_bbp_write(rt2x00dev, 26, drv_data->bbp26); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 1999 | } else { |
| 2000 | rt2800_bbp_write(rt2x00dev, 25, 0x09); |
| 2001 | rt2800_bbp_write(rt2x00dev, 26, 0xff); |
| 2002 | } |
| 2003 | |
| 2004 | rt2800_rfcsr_write(rt2x00dev, 2, rf->rf1); |
| 2005 | rt2800_rfcsr_write(rt2x00dev, 3, rf->rf3); |
| 2006 | |
| 2007 | rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr); |
| 2008 | rt2x00_set_field8(&rfcsr, RFCSR6_R1, rf->rf2); |
| 2009 | if (rf->channel <= 14) |
| 2010 | rt2x00_set_field8(&rfcsr, RFCSR6_TXDIV, 2); |
| 2011 | else |
| 2012 | rt2x00_set_field8(&rfcsr, RFCSR6_TXDIV, 1); |
| 2013 | rt2800_rfcsr_write(rt2x00dev, 6, rfcsr); |
| 2014 | |
| 2015 | rt2800_rfcsr_read(rt2x00dev, 5, &rfcsr); |
| 2016 | if (rf->channel <= 14) |
| 2017 | rt2x00_set_field8(&rfcsr, RFCSR5_R1, 1); |
| 2018 | else |
| 2019 | rt2x00_set_field8(&rfcsr, RFCSR5_R1, 2); |
| 2020 | rt2800_rfcsr_write(rt2x00dev, 5, rfcsr); |
| 2021 | |
| 2022 | rt2800_rfcsr_read(rt2x00dev, 12, &rfcsr); |
| 2023 | if (rf->channel <= 14) { |
| 2024 | rt2x00_set_field8(&rfcsr, RFCSR12_DR0, 3); |
| 2025 | rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER, |
Gertjan van Wingerde | 569ffa5 | 2012-02-06 23:45:10 +0100 | [diff] [blame] | 2026 | info->default_power1); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2027 | } else { |
| 2028 | rt2x00_set_field8(&rfcsr, RFCSR12_DR0, 7); |
| 2029 | rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER, |
| 2030 | (info->default_power1 & 0x3) | |
| 2031 | ((info->default_power1 & 0xC) << 1)); |
| 2032 | } |
| 2033 | rt2800_rfcsr_write(rt2x00dev, 12, rfcsr); |
| 2034 | |
| 2035 | rt2800_rfcsr_read(rt2x00dev, 13, &rfcsr); |
| 2036 | if (rf->channel <= 14) { |
| 2037 | rt2x00_set_field8(&rfcsr, RFCSR13_DR0, 3); |
| 2038 | rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER, |
Gertjan van Wingerde | 569ffa5 | 2012-02-06 23:45:10 +0100 | [diff] [blame] | 2039 | info->default_power2); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2040 | } else { |
| 2041 | rt2x00_set_field8(&rfcsr, RFCSR13_DR0, 7); |
| 2042 | rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER, |
| 2043 | (info->default_power2 & 0x3) | |
| 2044 | ((info->default_power2 & 0xC) << 1)); |
| 2045 | } |
| 2046 | rt2800_rfcsr_write(rt2x00dev, 13, rfcsr); |
| 2047 | |
| 2048 | rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2049 | rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0); |
| 2050 | rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0); |
| 2051 | rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 0); |
| 2052 | rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 0); |
Gertjan van Wingerde | 0cd461e | 2012-02-06 23:45:11 +0100 | [diff] [blame] | 2053 | rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0); |
| 2054 | rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2055 | if (test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags)) { |
| 2056 | if (rf->channel <= 14) { |
| 2057 | rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1); |
| 2058 | rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1); |
| 2059 | } |
| 2060 | rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 1); |
| 2061 | rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 1); |
| 2062 | } else { |
| 2063 | switch (rt2x00dev->default_ant.tx_chain_num) { |
| 2064 | case 1: |
| 2065 | rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1); |
| 2066 | case 2: |
| 2067 | rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 1); |
| 2068 | break; |
| 2069 | } |
| 2070 | |
| 2071 | switch (rt2x00dev->default_ant.rx_chain_num) { |
| 2072 | case 1: |
| 2073 | rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1); |
| 2074 | case 2: |
| 2075 | rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 1); |
| 2076 | break; |
| 2077 | } |
| 2078 | } |
| 2079 | rt2800_rfcsr_write(rt2x00dev, 1, rfcsr); |
| 2080 | |
| 2081 | rt2800_rfcsr_read(rt2x00dev, 23, &rfcsr); |
| 2082 | rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset); |
| 2083 | rt2800_rfcsr_write(rt2x00dev, 23, rfcsr); |
| 2084 | |
Gertjan van Wingerde | 3a1c012 | 2012-02-06 23:45:07 +0100 | [diff] [blame] | 2085 | if (conf_is_ht40(conf)) { |
| 2086 | rt2800_rfcsr_write(rt2x00dev, 24, drv_data->calibration_bw40); |
| 2087 | rt2800_rfcsr_write(rt2x00dev, 31, drv_data->calibration_bw40); |
| 2088 | } else { |
| 2089 | rt2800_rfcsr_write(rt2x00dev, 24, drv_data->calibration_bw20); |
| 2090 | rt2800_rfcsr_write(rt2x00dev, 31, drv_data->calibration_bw20); |
| 2091 | } |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2092 | |
| 2093 | if (rf->channel <= 14) { |
| 2094 | rt2800_rfcsr_write(rt2x00dev, 7, 0xd8); |
| 2095 | rt2800_rfcsr_write(rt2x00dev, 9, 0xc3); |
| 2096 | rt2800_rfcsr_write(rt2x00dev, 10, 0xf1); |
| 2097 | rt2800_rfcsr_write(rt2x00dev, 11, 0xb9); |
| 2098 | rt2800_rfcsr_write(rt2x00dev, 15, 0x53); |
Gertjan van Wingerde | 77c06c2 | 2012-02-06 23:45:13 +0100 | [diff] [blame] | 2099 | rfcsr = 0x4c; |
| 2100 | rt2x00_set_field8(&rfcsr, RFCSR16_TXMIXER_GAIN, |
| 2101 | drv_data->txmixer_gain_24g); |
| 2102 | rt2800_rfcsr_write(rt2x00dev, 16, rfcsr); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2103 | rt2800_rfcsr_write(rt2x00dev, 17, 0x23); |
| 2104 | rt2800_rfcsr_write(rt2x00dev, 19, 0x93); |
| 2105 | rt2800_rfcsr_write(rt2x00dev, 20, 0xb3); |
| 2106 | rt2800_rfcsr_write(rt2x00dev, 25, 0x15); |
| 2107 | rt2800_rfcsr_write(rt2x00dev, 26, 0x85); |
| 2108 | rt2800_rfcsr_write(rt2x00dev, 27, 0x00); |
| 2109 | rt2800_rfcsr_write(rt2x00dev, 29, 0x9b); |
| 2110 | } else { |
Gertjan van Wingerde | 58b8ae1 | 2012-02-06 23:45:12 +0100 | [diff] [blame] | 2111 | rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr); |
| 2112 | rt2x00_set_field8(&rfcsr, RFCSR7_BIT2, 1); |
| 2113 | rt2x00_set_field8(&rfcsr, RFCSR7_BIT3, 0); |
| 2114 | rt2x00_set_field8(&rfcsr, RFCSR7_BIT4, 1); |
| 2115 | rt2x00_set_field8(&rfcsr, RFCSR7_BITS67, 0); |
| 2116 | rt2800_rfcsr_write(rt2x00dev, 7, rfcsr); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2117 | rt2800_rfcsr_write(rt2x00dev, 9, 0xc0); |
| 2118 | rt2800_rfcsr_write(rt2x00dev, 10, 0xf1); |
| 2119 | rt2800_rfcsr_write(rt2x00dev, 11, 0x00); |
| 2120 | rt2800_rfcsr_write(rt2x00dev, 15, 0x43); |
Gertjan van Wingerde | 77c06c2 | 2012-02-06 23:45:13 +0100 | [diff] [blame] | 2121 | rfcsr = 0x7a; |
| 2122 | rt2x00_set_field8(&rfcsr, RFCSR16_TXMIXER_GAIN, |
| 2123 | drv_data->txmixer_gain_5g); |
| 2124 | rt2800_rfcsr_write(rt2x00dev, 16, rfcsr); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2125 | rt2800_rfcsr_write(rt2x00dev, 17, 0x23); |
| 2126 | if (rf->channel <= 64) { |
| 2127 | rt2800_rfcsr_write(rt2x00dev, 19, 0xb7); |
| 2128 | rt2800_rfcsr_write(rt2x00dev, 20, 0xf6); |
| 2129 | rt2800_rfcsr_write(rt2x00dev, 25, 0x3d); |
| 2130 | } else if (rf->channel <= 128) { |
| 2131 | rt2800_rfcsr_write(rt2x00dev, 19, 0x74); |
| 2132 | rt2800_rfcsr_write(rt2x00dev, 20, 0xf4); |
| 2133 | rt2800_rfcsr_write(rt2x00dev, 25, 0x01); |
| 2134 | } else { |
| 2135 | rt2800_rfcsr_write(rt2x00dev, 19, 0x72); |
| 2136 | rt2800_rfcsr_write(rt2x00dev, 20, 0xf3); |
| 2137 | rt2800_rfcsr_write(rt2x00dev, 25, 0x01); |
| 2138 | } |
| 2139 | rt2800_rfcsr_write(rt2x00dev, 26, 0x87); |
| 2140 | rt2800_rfcsr_write(rt2x00dev, 27, 0x01); |
| 2141 | rt2800_rfcsr_write(rt2x00dev, 29, 0x9f); |
| 2142 | } |
| 2143 | |
Gertjan van Wingerde | 99bdf51 | 2012-08-31 19:22:13 +0200 | [diff] [blame] | 2144 | rt2800_register_read(rt2x00dev, GPIO_CTRL, ®); |
| 2145 | rt2x00_set_field32(®, GPIO_CTRL_DIR7, 0); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2146 | if (rf->channel <= 14) |
Gertjan van Wingerde | 99bdf51 | 2012-08-31 19:22:13 +0200 | [diff] [blame] | 2147 | rt2x00_set_field32(®, GPIO_CTRL_VAL7, 1); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2148 | else |
Gertjan van Wingerde | 99bdf51 | 2012-08-31 19:22:13 +0200 | [diff] [blame] | 2149 | rt2x00_set_field32(®, GPIO_CTRL_VAL7, 0); |
| 2150 | rt2800_register_write(rt2x00dev, GPIO_CTRL, reg); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2151 | |
| 2152 | rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr); |
| 2153 | rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1); |
| 2154 | rt2800_rfcsr_write(rt2x00dev, 7, rfcsr); |
| 2155 | } |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2156 | |
Stanislaw Gruszka | 7573cb5 | 2012-07-09 14:41:48 +0200 | [diff] [blame] | 2157 | #define POWER_BOUND 0x27 |
Stanislaw Gruszka | 8f82109 | 2013-03-16 19:19:32 +0100 | [diff] [blame] | 2158 | #define POWER_BOUND_5G 0x2b |
Stanislaw Gruszka | 7573cb5 | 2012-07-09 14:41:48 +0200 | [diff] [blame] | 2159 | #define FREQ_OFFSET_BOUND 0x5f |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2160 | |
Stanislaw Gruszka | 0c9e5fb | 2013-03-16 19:19:36 +0100 | [diff] [blame] | 2161 | static void rt2800_adjust_freq_offset(struct rt2x00_dev *rt2x00dev) |
| 2162 | { |
| 2163 | u8 rfcsr; |
| 2164 | |
| 2165 | rt2800_rfcsr_read(rt2x00dev, 17, &rfcsr); |
| 2166 | if (rt2x00dev->freq_offset > FREQ_OFFSET_BOUND) |
| 2167 | rt2x00_set_field8(&rfcsr, RFCSR17_CODE, FREQ_OFFSET_BOUND); |
| 2168 | else |
| 2169 | rt2x00_set_field8(&rfcsr, RFCSR17_CODE, rt2x00dev->freq_offset); |
| 2170 | rt2800_rfcsr_write(rt2x00dev, 17, rfcsr); |
| 2171 | } |
| 2172 | |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 2173 | static void rt2800_config_channel_rf3290(struct rt2x00_dev *rt2x00dev, |
| 2174 | struct ieee80211_conf *conf, |
| 2175 | struct rf_channel *rf, |
| 2176 | struct channel_info *info) |
| 2177 | { |
| 2178 | u8 rfcsr; |
| 2179 | |
| 2180 | rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1); |
| 2181 | rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3); |
| 2182 | rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr); |
| 2183 | rt2x00_set_field8(&rfcsr, RFCSR11_R, rf->rf2); |
| 2184 | rt2800_rfcsr_write(rt2x00dev, 11, rfcsr); |
| 2185 | |
| 2186 | rt2800_rfcsr_read(rt2x00dev, 49, &rfcsr); |
Stanislaw Gruszka | 7573cb5 | 2012-07-09 14:41:48 +0200 | [diff] [blame] | 2187 | if (info->default_power1 > POWER_BOUND) |
| 2188 | rt2x00_set_field8(&rfcsr, RFCSR49_TX, POWER_BOUND); |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 2189 | else |
| 2190 | rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1); |
| 2191 | rt2800_rfcsr_write(rt2x00dev, 49, rfcsr); |
| 2192 | |
Stanislaw Gruszka | 0c9e5fb | 2013-03-16 19:19:36 +0100 | [diff] [blame] | 2193 | rt2800_adjust_freq_offset(rt2x00dev); |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 2194 | |
| 2195 | if (rf->channel <= 14) { |
| 2196 | if (rf->channel == 6) |
| 2197 | rt2800_bbp_write(rt2x00dev, 68, 0x0c); |
| 2198 | else |
| 2199 | rt2800_bbp_write(rt2x00dev, 68, 0x0b); |
| 2200 | |
| 2201 | if (rf->channel >= 1 && rf->channel <= 6) |
| 2202 | rt2800_bbp_write(rt2x00dev, 59, 0x0f); |
| 2203 | else if (rf->channel >= 7 && rf->channel <= 11) |
| 2204 | rt2800_bbp_write(rt2x00dev, 59, 0x0e); |
| 2205 | else if (rf->channel >= 12 && rf->channel <= 14) |
| 2206 | rt2800_bbp_write(rt2x00dev, 59, 0x0d); |
| 2207 | } |
| 2208 | } |
| 2209 | |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 2210 | static void rt2800_config_channel_rf3322(struct rt2x00_dev *rt2x00dev, |
| 2211 | struct ieee80211_conf *conf, |
| 2212 | struct rf_channel *rf, |
| 2213 | struct channel_info *info) |
| 2214 | { |
| 2215 | u8 rfcsr; |
| 2216 | |
| 2217 | rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1); |
| 2218 | rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3); |
| 2219 | |
| 2220 | rt2800_rfcsr_write(rt2x00dev, 11, 0x42); |
| 2221 | rt2800_rfcsr_write(rt2x00dev, 12, 0x1c); |
| 2222 | rt2800_rfcsr_write(rt2x00dev, 13, 0x00); |
| 2223 | |
| 2224 | if (info->default_power1 > POWER_BOUND) |
| 2225 | rt2800_rfcsr_write(rt2x00dev, 47, POWER_BOUND); |
| 2226 | else |
| 2227 | rt2800_rfcsr_write(rt2x00dev, 47, info->default_power1); |
| 2228 | |
| 2229 | if (info->default_power2 > POWER_BOUND) |
| 2230 | rt2800_rfcsr_write(rt2x00dev, 48, POWER_BOUND); |
| 2231 | else |
| 2232 | rt2800_rfcsr_write(rt2x00dev, 48, info->default_power2); |
| 2233 | |
Stanislaw Gruszka | 0c9e5fb | 2013-03-16 19:19:36 +0100 | [diff] [blame] | 2234 | rt2800_adjust_freq_offset(rt2x00dev); |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 2235 | |
| 2236 | rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr); |
| 2237 | rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1); |
| 2238 | rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1); |
| 2239 | |
| 2240 | if ( rt2x00dev->default_ant.tx_chain_num == 2 ) |
| 2241 | rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1); |
| 2242 | else |
| 2243 | rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 0); |
| 2244 | |
| 2245 | if ( rt2x00dev->default_ant.rx_chain_num == 2 ) |
| 2246 | rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1); |
| 2247 | else |
| 2248 | rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 0); |
| 2249 | |
| 2250 | rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0); |
| 2251 | rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0); |
| 2252 | |
| 2253 | rt2800_rfcsr_write(rt2x00dev, 1, rfcsr); |
| 2254 | |
| 2255 | rt2800_rfcsr_write(rt2x00dev, 31, 80); |
| 2256 | } |
| 2257 | |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2258 | static void rt2800_config_channel_rf53xx(struct rt2x00_dev *rt2x00dev, |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2259 | struct ieee80211_conf *conf, |
| 2260 | struct rf_channel *rf, |
| 2261 | struct channel_info *info) |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2262 | { |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2263 | u8 rfcsr; |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2264 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2265 | rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1); |
| 2266 | rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3); |
| 2267 | rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr); |
| 2268 | rt2x00_set_field8(&rfcsr, RFCSR11_R, rf->rf2); |
| 2269 | rt2800_rfcsr_write(rt2x00dev, 11, rfcsr); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2270 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2271 | rt2800_rfcsr_read(rt2x00dev, 49, &rfcsr); |
Stanislaw Gruszka | 7573cb5 | 2012-07-09 14:41:48 +0200 | [diff] [blame] | 2272 | if (info->default_power1 > POWER_BOUND) |
| 2273 | rt2x00_set_field8(&rfcsr, RFCSR49_TX, POWER_BOUND); |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2274 | else |
| 2275 | rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1); |
| 2276 | rt2800_rfcsr_write(rt2x00dev, 49, rfcsr); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2277 | |
Zero.Lin | cff3d1f | 2012-05-29 16:11:09 +0800 | [diff] [blame] | 2278 | if (rt2x00_rt(rt2x00dev, RT5392)) { |
| 2279 | rt2800_rfcsr_read(rt2x00dev, 50, &rfcsr); |
Stanislaw Gruszka | 7573cb5 | 2012-07-09 14:41:48 +0200 | [diff] [blame] | 2280 | if (info->default_power1 > POWER_BOUND) |
| 2281 | rt2x00_set_field8(&rfcsr, RFCSR50_TX, POWER_BOUND); |
Zero.Lin | cff3d1f | 2012-05-29 16:11:09 +0800 | [diff] [blame] | 2282 | else |
| 2283 | rt2x00_set_field8(&rfcsr, RFCSR50_TX, |
| 2284 | info->default_power2); |
| 2285 | rt2800_rfcsr_write(rt2x00dev, 50, rfcsr); |
| 2286 | } |
| 2287 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2288 | rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr); |
Zero.Lin | cff3d1f | 2012-05-29 16:11:09 +0800 | [diff] [blame] | 2289 | if (rt2x00_rt(rt2x00dev, RT5392)) { |
| 2290 | rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1); |
| 2291 | rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1); |
| 2292 | } |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2293 | rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1); |
| 2294 | rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1); |
| 2295 | rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1); |
| 2296 | rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1); |
| 2297 | rt2800_rfcsr_write(rt2x00dev, 1, rfcsr); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2298 | |
Stanislaw Gruszka | 0c9e5fb | 2013-03-16 19:19:36 +0100 | [diff] [blame] | 2299 | rt2800_adjust_freq_offset(rt2x00dev); |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2300 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2301 | if (rf->channel <= 14) { |
| 2302 | int idx = rf->channel-1; |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2303 | |
Gertjan van Wingerde | fdbc7b0 | 2011-04-30 17:15:37 +0200 | [diff] [blame] | 2304 | if (test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags)) { |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2305 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) { |
| 2306 | /* r55/r59 value array of channel 1~14 */ |
| 2307 | static const char r55_bt_rev[] = {0x83, 0x83, |
| 2308 | 0x83, 0x73, 0x73, 0x63, 0x53, 0x53, |
| 2309 | 0x53, 0x43, 0x43, 0x43, 0x43, 0x43}; |
| 2310 | static const char r59_bt_rev[] = {0x0e, 0x0e, |
| 2311 | 0x0e, 0x0e, 0x0e, 0x0b, 0x0a, 0x09, |
| 2312 | 0x07, 0x07, 0x07, 0x07, 0x07, 0x07}; |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2313 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2314 | rt2800_rfcsr_write(rt2x00dev, 55, |
| 2315 | r55_bt_rev[idx]); |
| 2316 | rt2800_rfcsr_write(rt2x00dev, 59, |
| 2317 | r59_bt_rev[idx]); |
| 2318 | } else { |
| 2319 | static const char r59_bt[] = {0x8b, 0x8b, 0x8b, |
| 2320 | 0x8b, 0x8b, 0x8b, 0x8b, 0x8a, 0x89, |
| 2321 | 0x88, 0x88, 0x86, 0x85, 0x84}; |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2322 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2323 | rt2800_rfcsr_write(rt2x00dev, 59, r59_bt[idx]); |
| 2324 | } |
| 2325 | } else { |
| 2326 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) { |
| 2327 | static const char r55_nonbt_rev[] = {0x23, 0x23, |
| 2328 | 0x23, 0x23, 0x13, 0x13, 0x03, 0x03, |
| 2329 | 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}; |
| 2330 | static const char r59_nonbt_rev[] = {0x07, 0x07, |
| 2331 | 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, |
| 2332 | 0x07, 0x07, 0x06, 0x05, 0x04, 0x04}; |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2333 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2334 | rt2800_rfcsr_write(rt2x00dev, 55, |
| 2335 | r55_nonbt_rev[idx]); |
| 2336 | rt2800_rfcsr_write(rt2x00dev, 59, |
| 2337 | r59_nonbt_rev[idx]); |
John Li | 2ed7188 | 2012-02-17 17:33:06 +0800 | [diff] [blame] | 2338 | } else if (rt2x00_rt(rt2x00dev, RT5390) || |
Gabor Juhos | e6d227b | 2012-12-02 15:53:28 +0100 | [diff] [blame] | 2339 | rt2x00_rt(rt2x00dev, RT5392)) { |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2340 | static const char r59_non_bt[] = {0x8f, 0x8f, |
| 2341 | 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8d, |
| 2342 | 0x8a, 0x88, 0x88, 0x87, 0x87, 0x86}; |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2343 | |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2344 | rt2800_rfcsr_write(rt2x00dev, 59, |
| 2345 | r59_non_bt[idx]); |
| 2346 | } |
| 2347 | } |
| 2348 | } |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 2349 | } |
| 2350 | |
Stanislaw Gruszka | 8f82109 | 2013-03-16 19:19:32 +0100 | [diff] [blame] | 2351 | static void rt2800_config_channel_rf55xx(struct rt2x00_dev *rt2x00dev, |
| 2352 | struct ieee80211_conf *conf, |
| 2353 | struct rf_channel *rf, |
| 2354 | struct channel_info *info) |
| 2355 | { |
| 2356 | u8 rfcsr, ep_reg; |
Stanislaw Gruszka | d5ae7a6 | 2013-03-16 19:19:42 +0100 | [diff] [blame] | 2357 | u32 reg; |
Stanislaw Gruszka | 8f82109 | 2013-03-16 19:19:32 +0100 | [diff] [blame] | 2358 | int power_bound; |
| 2359 | |
| 2360 | /* TODO */ |
| 2361 | const bool is_11b = false; |
| 2362 | const bool is_type_ep = false; |
| 2363 | |
Stanislaw Gruszka | d5ae7a6 | 2013-03-16 19:19:42 +0100 | [diff] [blame] | 2364 | rt2800_register_read(rt2x00dev, LDO_CFG0, ®); |
| 2365 | rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, |
| 2366 | (rf->channel > 14 || conf_is_ht40(conf)) ? 5 : 0); |
| 2367 | rt2800_register_write(rt2x00dev, LDO_CFG0, reg); |
Stanislaw Gruszka | 8f82109 | 2013-03-16 19:19:32 +0100 | [diff] [blame] | 2368 | |
| 2369 | /* Order of values on rf_channel entry: N, K, mod, R */ |
| 2370 | rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1 & 0xff); |
| 2371 | |
| 2372 | rt2800_rfcsr_read(rt2x00dev, 9, &rfcsr); |
| 2373 | rt2x00_set_field8(&rfcsr, RFCSR9_K, rf->rf2 & 0xf); |
| 2374 | rt2x00_set_field8(&rfcsr, RFCSR9_N, (rf->rf1 & 0x100) >> 8); |
| 2375 | rt2x00_set_field8(&rfcsr, RFCSR9_MOD, ((rf->rf3 - 8) & 0x4) >> 2); |
| 2376 | rt2800_rfcsr_write(rt2x00dev, 9, rfcsr); |
| 2377 | |
| 2378 | rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr); |
| 2379 | rt2x00_set_field8(&rfcsr, RFCSR11_R, rf->rf4 - 1); |
| 2380 | rt2x00_set_field8(&rfcsr, RFCSR11_MOD, (rf->rf3 - 8) & 0x3); |
| 2381 | rt2800_rfcsr_write(rt2x00dev, 11, rfcsr); |
| 2382 | |
| 2383 | if (rf->channel <= 14) { |
| 2384 | rt2800_rfcsr_write(rt2x00dev, 10, 0x90); |
| 2385 | /* FIXME: RF11 owerwrite ? */ |
| 2386 | rt2800_rfcsr_write(rt2x00dev, 11, 0x4A); |
| 2387 | rt2800_rfcsr_write(rt2x00dev, 12, 0x52); |
| 2388 | rt2800_rfcsr_write(rt2x00dev, 13, 0x42); |
| 2389 | rt2800_rfcsr_write(rt2x00dev, 22, 0x40); |
| 2390 | rt2800_rfcsr_write(rt2x00dev, 24, 0x4A); |
| 2391 | rt2800_rfcsr_write(rt2x00dev, 25, 0x80); |
| 2392 | rt2800_rfcsr_write(rt2x00dev, 27, 0x42); |
| 2393 | rt2800_rfcsr_write(rt2x00dev, 36, 0x80); |
| 2394 | rt2800_rfcsr_write(rt2x00dev, 37, 0x08); |
| 2395 | rt2800_rfcsr_write(rt2x00dev, 38, 0x89); |
| 2396 | rt2800_rfcsr_write(rt2x00dev, 39, 0x1B); |
| 2397 | rt2800_rfcsr_write(rt2x00dev, 40, 0x0D); |
| 2398 | rt2800_rfcsr_write(rt2x00dev, 41, 0x9B); |
| 2399 | rt2800_rfcsr_write(rt2x00dev, 42, 0xD5); |
| 2400 | rt2800_rfcsr_write(rt2x00dev, 43, 0x72); |
| 2401 | rt2800_rfcsr_write(rt2x00dev, 44, 0x0E); |
| 2402 | rt2800_rfcsr_write(rt2x00dev, 45, 0xA2); |
| 2403 | rt2800_rfcsr_write(rt2x00dev, 46, 0x6B); |
| 2404 | rt2800_rfcsr_write(rt2x00dev, 48, 0x10); |
| 2405 | rt2800_rfcsr_write(rt2x00dev, 51, 0x3E); |
| 2406 | rt2800_rfcsr_write(rt2x00dev, 52, 0x48); |
| 2407 | rt2800_rfcsr_write(rt2x00dev, 54, 0x38); |
| 2408 | rt2800_rfcsr_write(rt2x00dev, 56, 0xA1); |
| 2409 | rt2800_rfcsr_write(rt2x00dev, 57, 0x00); |
| 2410 | rt2800_rfcsr_write(rt2x00dev, 58, 0x39); |
| 2411 | rt2800_rfcsr_write(rt2x00dev, 60, 0x45); |
| 2412 | rt2800_rfcsr_write(rt2x00dev, 61, 0x91); |
| 2413 | rt2800_rfcsr_write(rt2x00dev, 62, 0x39); |
| 2414 | |
| 2415 | /* TODO RF27 <- tssi */ |
| 2416 | |
| 2417 | rfcsr = rf->channel <= 10 ? 0x07 : 0x06; |
| 2418 | rt2800_rfcsr_write(rt2x00dev, 23, rfcsr); |
| 2419 | rt2800_rfcsr_write(rt2x00dev, 59, rfcsr); |
| 2420 | |
| 2421 | if (is_11b) { |
| 2422 | /* CCK */ |
| 2423 | rt2800_rfcsr_write(rt2x00dev, 31, 0xF8); |
| 2424 | rt2800_rfcsr_write(rt2x00dev, 32, 0xC0); |
| 2425 | if (is_type_ep) |
| 2426 | rt2800_rfcsr_write(rt2x00dev, 55, 0x06); |
| 2427 | else |
| 2428 | rt2800_rfcsr_write(rt2x00dev, 55, 0x47); |
| 2429 | } else { |
| 2430 | /* OFDM */ |
| 2431 | if (is_type_ep) |
| 2432 | rt2800_rfcsr_write(rt2x00dev, 55, 0x03); |
| 2433 | else |
| 2434 | rt2800_rfcsr_write(rt2x00dev, 55, 0x43); |
| 2435 | } |
| 2436 | |
| 2437 | power_bound = POWER_BOUND; |
| 2438 | ep_reg = 0x2; |
| 2439 | } else { |
| 2440 | rt2800_rfcsr_write(rt2x00dev, 10, 0x97); |
| 2441 | /* FIMXE: RF11 overwrite */ |
| 2442 | rt2800_rfcsr_write(rt2x00dev, 11, 0x40); |
| 2443 | rt2800_rfcsr_write(rt2x00dev, 25, 0xBF); |
| 2444 | rt2800_rfcsr_write(rt2x00dev, 27, 0x42); |
| 2445 | rt2800_rfcsr_write(rt2x00dev, 36, 0x00); |
| 2446 | rt2800_rfcsr_write(rt2x00dev, 37, 0x04); |
| 2447 | rt2800_rfcsr_write(rt2x00dev, 38, 0x85); |
| 2448 | rt2800_rfcsr_write(rt2x00dev, 40, 0x42); |
| 2449 | rt2800_rfcsr_write(rt2x00dev, 41, 0xBB); |
| 2450 | rt2800_rfcsr_write(rt2x00dev, 42, 0xD7); |
| 2451 | rt2800_rfcsr_write(rt2x00dev, 45, 0x41); |
| 2452 | rt2800_rfcsr_write(rt2x00dev, 48, 0x00); |
| 2453 | rt2800_rfcsr_write(rt2x00dev, 57, 0x77); |
| 2454 | rt2800_rfcsr_write(rt2x00dev, 60, 0x05); |
| 2455 | rt2800_rfcsr_write(rt2x00dev, 61, 0x01); |
| 2456 | |
| 2457 | /* TODO RF27 <- tssi */ |
| 2458 | |
| 2459 | if (rf->channel >= 36 && rf->channel <= 64) { |
| 2460 | |
| 2461 | rt2800_rfcsr_write(rt2x00dev, 12, 0x2E); |
| 2462 | rt2800_rfcsr_write(rt2x00dev, 13, 0x22); |
| 2463 | rt2800_rfcsr_write(rt2x00dev, 22, 0x60); |
| 2464 | rt2800_rfcsr_write(rt2x00dev, 23, 0x7F); |
| 2465 | if (rf->channel <= 50) |
| 2466 | rt2800_rfcsr_write(rt2x00dev, 24, 0x09); |
| 2467 | else if (rf->channel >= 52) |
| 2468 | rt2800_rfcsr_write(rt2x00dev, 24, 0x07); |
| 2469 | rt2800_rfcsr_write(rt2x00dev, 39, 0x1C); |
| 2470 | rt2800_rfcsr_write(rt2x00dev, 43, 0x5B); |
| 2471 | rt2800_rfcsr_write(rt2x00dev, 44, 0X40); |
| 2472 | rt2800_rfcsr_write(rt2x00dev, 46, 0X00); |
| 2473 | rt2800_rfcsr_write(rt2x00dev, 51, 0xFE); |
| 2474 | rt2800_rfcsr_write(rt2x00dev, 52, 0x0C); |
| 2475 | rt2800_rfcsr_write(rt2x00dev, 54, 0xF8); |
| 2476 | if (rf->channel <= 50) { |
| 2477 | rt2800_rfcsr_write(rt2x00dev, 55, 0x06), |
| 2478 | rt2800_rfcsr_write(rt2x00dev, 56, 0xD3); |
| 2479 | } else if (rf->channel >= 52) { |
| 2480 | rt2800_rfcsr_write(rt2x00dev, 55, 0x04); |
| 2481 | rt2800_rfcsr_write(rt2x00dev, 56, 0xBB); |
| 2482 | } |
| 2483 | |
| 2484 | rt2800_rfcsr_write(rt2x00dev, 58, 0x15); |
| 2485 | rt2800_rfcsr_write(rt2x00dev, 59, 0x7F); |
| 2486 | rt2800_rfcsr_write(rt2x00dev, 62, 0x15); |
| 2487 | |
| 2488 | } else if (rf->channel >= 100 && rf->channel <= 165) { |
| 2489 | |
| 2490 | rt2800_rfcsr_write(rt2x00dev, 12, 0x0E); |
| 2491 | rt2800_rfcsr_write(rt2x00dev, 13, 0x42); |
| 2492 | rt2800_rfcsr_write(rt2x00dev, 22, 0x40); |
| 2493 | if (rf->channel <= 153) { |
| 2494 | rt2800_rfcsr_write(rt2x00dev, 23, 0x3C); |
| 2495 | rt2800_rfcsr_write(rt2x00dev, 24, 0x06); |
| 2496 | } else if (rf->channel >= 155) { |
| 2497 | rt2800_rfcsr_write(rt2x00dev, 23, 0x38); |
| 2498 | rt2800_rfcsr_write(rt2x00dev, 24, 0x05); |
| 2499 | } |
| 2500 | if (rf->channel <= 138) { |
| 2501 | rt2800_rfcsr_write(rt2x00dev, 39, 0x1A); |
| 2502 | rt2800_rfcsr_write(rt2x00dev, 43, 0x3B); |
| 2503 | rt2800_rfcsr_write(rt2x00dev, 44, 0x20); |
| 2504 | rt2800_rfcsr_write(rt2x00dev, 46, 0x18); |
| 2505 | } else if (rf->channel >= 140) { |
| 2506 | rt2800_rfcsr_write(rt2x00dev, 39, 0x18); |
| 2507 | rt2800_rfcsr_write(rt2x00dev, 43, 0x1B); |
| 2508 | rt2800_rfcsr_write(rt2x00dev, 44, 0x10); |
| 2509 | rt2800_rfcsr_write(rt2x00dev, 46, 0X08); |
| 2510 | } |
| 2511 | if (rf->channel <= 124) |
| 2512 | rt2800_rfcsr_write(rt2x00dev, 51, 0xFC); |
| 2513 | else if (rf->channel >= 126) |
| 2514 | rt2800_rfcsr_write(rt2x00dev, 51, 0xEC); |
| 2515 | if (rf->channel <= 138) |
| 2516 | rt2800_rfcsr_write(rt2x00dev, 52, 0x06); |
| 2517 | else if (rf->channel >= 140) |
| 2518 | rt2800_rfcsr_write(rt2x00dev, 52, 0x06); |
| 2519 | rt2800_rfcsr_write(rt2x00dev, 54, 0xEB); |
| 2520 | if (rf->channel <= 138) |
| 2521 | rt2800_rfcsr_write(rt2x00dev, 55, 0x01); |
| 2522 | else if (rf->channel >= 140) |
| 2523 | rt2800_rfcsr_write(rt2x00dev, 55, 0x00); |
| 2524 | if (rf->channel <= 128) |
| 2525 | rt2800_rfcsr_write(rt2x00dev, 56, 0xBB); |
| 2526 | else if (rf->channel >= 130) |
| 2527 | rt2800_rfcsr_write(rt2x00dev, 56, 0xAB); |
| 2528 | if (rf->channel <= 116) |
| 2529 | rt2800_rfcsr_write(rt2x00dev, 58, 0x1D); |
| 2530 | else if (rf->channel >= 118) |
| 2531 | rt2800_rfcsr_write(rt2x00dev, 58, 0x15); |
| 2532 | if (rf->channel <= 138) |
| 2533 | rt2800_rfcsr_write(rt2x00dev, 59, 0x3F); |
| 2534 | else if (rf->channel >= 140) |
| 2535 | rt2800_rfcsr_write(rt2x00dev, 59, 0x7C); |
| 2536 | if (rf->channel <= 116) |
| 2537 | rt2800_rfcsr_write(rt2x00dev, 62, 0x1D); |
| 2538 | else if (rf->channel >= 118) |
| 2539 | rt2800_rfcsr_write(rt2x00dev, 62, 0x15); |
| 2540 | } |
| 2541 | |
| 2542 | power_bound = POWER_BOUND_5G; |
| 2543 | ep_reg = 0x3; |
| 2544 | } |
| 2545 | |
| 2546 | rt2800_rfcsr_read(rt2x00dev, 49, &rfcsr); |
| 2547 | if (info->default_power1 > power_bound) |
| 2548 | rt2x00_set_field8(&rfcsr, RFCSR49_TX, power_bound); |
| 2549 | else |
| 2550 | rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1); |
| 2551 | if (is_type_ep) |
| 2552 | rt2x00_set_field8(&rfcsr, RFCSR49_EP, ep_reg); |
| 2553 | rt2800_rfcsr_write(rt2x00dev, 49, rfcsr); |
| 2554 | |
| 2555 | rt2800_rfcsr_read(rt2x00dev, 50, &rfcsr); |
Gabor Juhos | 0847beb | 2013-06-25 22:57:29 +0200 | [diff] [blame] | 2556 | if (info->default_power2 > power_bound) |
Stanislaw Gruszka | 8f82109 | 2013-03-16 19:19:32 +0100 | [diff] [blame] | 2557 | rt2x00_set_field8(&rfcsr, RFCSR50_TX, power_bound); |
| 2558 | else |
| 2559 | rt2x00_set_field8(&rfcsr, RFCSR50_TX, info->default_power2); |
| 2560 | if (is_type_ep) |
| 2561 | rt2x00_set_field8(&rfcsr, RFCSR50_EP, ep_reg); |
| 2562 | rt2800_rfcsr_write(rt2x00dev, 50, rfcsr); |
| 2563 | |
| 2564 | rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr); |
| 2565 | rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1); |
| 2566 | rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1); |
| 2567 | |
| 2568 | rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, |
| 2569 | rt2x00dev->default_ant.tx_chain_num >= 1); |
| 2570 | rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, |
| 2571 | rt2x00dev->default_ant.tx_chain_num == 2); |
| 2572 | rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0); |
| 2573 | |
| 2574 | rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, |
| 2575 | rt2x00dev->default_ant.rx_chain_num >= 1); |
| 2576 | rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, |
| 2577 | rt2x00dev->default_ant.rx_chain_num == 2); |
| 2578 | rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0); |
| 2579 | |
| 2580 | rt2800_rfcsr_write(rt2x00dev, 1, rfcsr); |
| 2581 | rt2800_rfcsr_write(rt2x00dev, 6, 0xe4); |
| 2582 | |
| 2583 | if (conf_is_ht40(conf)) |
| 2584 | rt2800_rfcsr_write(rt2x00dev, 30, 0x16); |
| 2585 | else |
| 2586 | rt2800_rfcsr_write(rt2x00dev, 30, 0x10); |
| 2587 | |
| 2588 | if (!is_11b) { |
| 2589 | rt2800_rfcsr_write(rt2x00dev, 31, 0x80); |
| 2590 | rt2800_rfcsr_write(rt2x00dev, 32, 0x80); |
| 2591 | } |
| 2592 | |
| 2593 | /* TODO proper frequency adjustment */ |
Stanislaw Gruszka | 0c9e5fb | 2013-03-16 19:19:36 +0100 | [diff] [blame] | 2594 | rt2800_adjust_freq_offset(rt2x00dev); |
Stanislaw Gruszka | 8f82109 | 2013-03-16 19:19:32 +0100 | [diff] [blame] | 2595 | |
| 2596 | /* TODO merge with others */ |
| 2597 | rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr); |
| 2598 | rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1); |
| 2599 | rt2800_rfcsr_write(rt2x00dev, 3, rfcsr); |
Stanislaw Gruszka | 6803141 | 2013-03-16 19:19:44 +0100 | [diff] [blame] | 2600 | |
| 2601 | /* BBP settings */ |
| 2602 | rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain); |
| 2603 | rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain); |
| 2604 | rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain); |
| 2605 | |
| 2606 | rt2800_bbp_write(rt2x00dev, 79, (rf->channel <= 14) ? 0x1C : 0x18); |
| 2607 | rt2800_bbp_write(rt2x00dev, 80, (rf->channel <= 14) ? 0x0E : 0x08); |
| 2608 | rt2800_bbp_write(rt2x00dev, 81, (rf->channel <= 14) ? 0x3A : 0x38); |
| 2609 | rt2800_bbp_write(rt2x00dev, 82, (rf->channel <= 14) ? 0x62 : 0x92); |
| 2610 | |
| 2611 | /* GLRT band configuration */ |
| 2612 | rt2800_bbp_write(rt2x00dev, 195, 128); |
| 2613 | rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0xE0 : 0xF0); |
| 2614 | rt2800_bbp_write(rt2x00dev, 195, 129); |
| 2615 | rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x1F : 0x1E); |
| 2616 | rt2800_bbp_write(rt2x00dev, 195, 130); |
| 2617 | rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x38 : 0x28); |
| 2618 | rt2800_bbp_write(rt2x00dev, 195, 131); |
| 2619 | rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x32 : 0x20); |
| 2620 | rt2800_bbp_write(rt2x00dev, 195, 133); |
| 2621 | rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x28 : 0x7F); |
| 2622 | rt2800_bbp_write(rt2x00dev, 195, 124); |
| 2623 | rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x19 : 0x7F); |
Stanislaw Gruszka | 8f82109 | 2013-03-16 19:19:32 +0100 | [diff] [blame] | 2624 | } |
| 2625 | |
Stanislaw Gruszka | 5bc2dd0 | 2013-03-16 19:19:47 +0100 | [diff] [blame] | 2626 | static void rt2800_bbp_write_with_rx_chain(struct rt2x00_dev *rt2x00dev, |
| 2627 | const unsigned int word, |
| 2628 | const u8 value) |
| 2629 | { |
| 2630 | u8 chain, reg; |
| 2631 | |
| 2632 | for (chain = 0; chain < rt2x00dev->default_ant.rx_chain_num; chain++) { |
| 2633 | rt2800_bbp_read(rt2x00dev, 27, ®); |
| 2634 | rt2x00_set_field8(®, BBP27_RX_CHAIN_SEL, chain); |
| 2635 | rt2800_bbp_write(rt2x00dev, 27, reg); |
| 2636 | |
| 2637 | rt2800_bbp_write(rt2x00dev, word, value); |
| 2638 | } |
| 2639 | } |
| 2640 | |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 2641 | static void rt2800_iq_calibrate(struct rt2x00_dev *rt2x00dev, int channel) |
| 2642 | { |
| 2643 | u8 cal; |
| 2644 | |
Stanislaw Gruszka | 415e3f2 | 2013-03-16 19:19:52 +0100 | [diff] [blame] | 2645 | /* TX0 IQ Gain */ |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 2646 | rt2800_bbp_write(rt2x00dev, 158, 0x2c); |
Stanislaw Gruszka | 415e3f2 | 2013-03-16 19:19:52 +0100 | [diff] [blame] | 2647 | if (channel <= 14) |
| 2648 | cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_GAIN_CAL_TX0_2G); |
| 2649 | else if (channel >= 36 && channel <= 64) |
| 2650 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 2651 | EEPROM_IQ_GAIN_CAL_TX0_CH36_TO_CH64_5G); |
| 2652 | else if (channel >= 100 && channel <= 138) |
| 2653 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 2654 | EEPROM_IQ_GAIN_CAL_TX0_CH100_TO_CH138_5G); |
| 2655 | else if (channel >= 140 && channel <= 165) |
| 2656 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 2657 | EEPROM_IQ_GAIN_CAL_TX0_CH140_TO_CH165_5G); |
| 2658 | else |
| 2659 | cal = 0; |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 2660 | rt2800_bbp_write(rt2x00dev, 159, cal); |
| 2661 | |
Stanislaw Gruszka | 415e3f2 | 2013-03-16 19:19:52 +0100 | [diff] [blame] | 2662 | /* TX0 IQ Phase */ |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 2663 | rt2800_bbp_write(rt2x00dev, 158, 0x2d); |
Stanislaw Gruszka | 415e3f2 | 2013-03-16 19:19:52 +0100 | [diff] [blame] | 2664 | if (channel <= 14) |
| 2665 | cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_PHASE_CAL_TX0_2G); |
| 2666 | else if (channel >= 36 && channel <= 64) |
| 2667 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 2668 | EEPROM_IQ_PHASE_CAL_TX0_CH36_TO_CH64_5G); |
| 2669 | else if (channel >= 100 && channel <= 138) |
| 2670 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 2671 | EEPROM_IQ_PHASE_CAL_TX0_CH100_TO_CH138_5G); |
| 2672 | else if (channel >= 140 && channel <= 165) |
| 2673 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 2674 | EEPROM_IQ_PHASE_CAL_TX0_CH140_TO_CH165_5G); |
| 2675 | else |
| 2676 | cal = 0; |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 2677 | rt2800_bbp_write(rt2x00dev, 159, cal); |
| 2678 | |
Stanislaw Gruszka | 415e3f2 | 2013-03-16 19:19:52 +0100 | [diff] [blame] | 2679 | /* TX1 IQ Gain */ |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 2680 | rt2800_bbp_write(rt2x00dev, 158, 0x4a); |
Stanislaw Gruszka | 415e3f2 | 2013-03-16 19:19:52 +0100 | [diff] [blame] | 2681 | if (channel <= 14) |
| 2682 | cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_GAIN_CAL_TX1_2G); |
| 2683 | else if (channel >= 36 && channel <= 64) |
| 2684 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 2685 | EEPROM_IQ_GAIN_CAL_TX1_CH36_TO_CH64_5G); |
| 2686 | else if (channel >= 100 && channel <= 138) |
| 2687 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 2688 | EEPROM_IQ_GAIN_CAL_TX1_CH100_TO_CH138_5G); |
| 2689 | else if (channel >= 140 && channel <= 165) |
| 2690 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 2691 | EEPROM_IQ_GAIN_CAL_TX1_CH140_TO_CH165_5G); |
| 2692 | else |
| 2693 | cal = 0; |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 2694 | rt2800_bbp_write(rt2x00dev, 159, cal); |
| 2695 | |
Stanislaw Gruszka | 415e3f2 | 2013-03-16 19:19:52 +0100 | [diff] [blame] | 2696 | /* TX1 IQ Phase */ |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 2697 | rt2800_bbp_write(rt2x00dev, 158, 0x4b); |
Stanislaw Gruszka | 415e3f2 | 2013-03-16 19:19:52 +0100 | [diff] [blame] | 2698 | if (channel <= 14) |
| 2699 | cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_PHASE_CAL_TX1_2G); |
| 2700 | else if (channel >= 36 && channel <= 64) |
| 2701 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 2702 | EEPROM_IQ_PHASE_CAL_TX1_CH36_TO_CH64_5G); |
| 2703 | else if (channel >= 100 && channel <= 138) |
| 2704 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 2705 | EEPROM_IQ_PHASE_CAL_TX1_CH100_TO_CH138_5G); |
| 2706 | else if (channel >= 140 && channel <= 165) |
| 2707 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 2708 | EEPROM_IQ_PHASE_CAL_TX1_CH140_TO_CH165_5G); |
| 2709 | else |
| 2710 | cal = 0; |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 2711 | rt2800_bbp_write(rt2x00dev, 159, cal); |
| 2712 | |
Stanislaw Gruszka | 415e3f2 | 2013-03-16 19:19:52 +0100 | [diff] [blame] | 2713 | /* FIXME: possible RX0, RX1 callibration ? */ |
| 2714 | |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 2715 | /* RF IQ compensation control */ |
| 2716 | rt2800_bbp_write(rt2x00dev, 158, 0x04); |
| 2717 | cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_RF_IQ_COMPENSATION_CONTROL); |
| 2718 | rt2800_bbp_write(rt2x00dev, 159, cal != 0xff ? cal : 0); |
| 2719 | |
| 2720 | /* RF IQ imbalance compensation control */ |
| 2721 | rt2800_bbp_write(rt2x00dev, 158, 0x03); |
Stanislaw Gruszka | 415e3f2 | 2013-03-16 19:19:52 +0100 | [diff] [blame] | 2722 | cal = rt2x00_eeprom_byte(rt2x00dev, |
| 2723 | EEPROM_RF_IQ_IMBALANCE_COMPENSATION_CONTROL); |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 2724 | rt2800_bbp_write(rt2x00dev, 159, cal != 0xff ? cal : 0); |
| 2725 | } |
| 2726 | |
Gabor Juhos | 97aa03f | 2013-07-08 16:08:23 +0200 | [diff] [blame] | 2727 | static char rt2800_txpower_to_dev(struct rt2x00_dev *rt2x00dev, |
| 2728 | unsigned int channel, |
| 2729 | char txpower) |
| 2730 | { |
Gabor Juhos | fc739cf | 2013-07-08 16:08:24 +0200 | [diff] [blame] | 2731 | if (rt2x00_rt(rt2x00dev, RT3593)) |
| 2732 | txpower = rt2x00_get_field8(txpower, EEPROM_TXPOWER_ALC); |
| 2733 | |
Gabor Juhos | 97aa03f | 2013-07-08 16:08:23 +0200 | [diff] [blame] | 2734 | if (channel <= 14) |
| 2735 | return clamp_t(char, txpower, MIN_G_TXPOWER, MAX_G_TXPOWER); |
Gabor Juhos | fc739cf | 2013-07-08 16:08:24 +0200 | [diff] [blame] | 2736 | |
| 2737 | if (rt2x00_rt(rt2x00dev, RT3593)) |
| 2738 | return clamp_t(char, txpower, MIN_A_TXPOWER_3593, |
| 2739 | MAX_A_TXPOWER_3593); |
Gabor Juhos | 97aa03f | 2013-07-08 16:08:23 +0200 | [diff] [blame] | 2740 | else |
| 2741 | return clamp_t(char, txpower, MIN_A_TXPOWER, MAX_A_TXPOWER); |
| 2742 | } |
| 2743 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2744 | static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev, |
| 2745 | struct ieee80211_conf *conf, |
| 2746 | struct rf_channel *rf, |
| 2747 | struct channel_info *info) |
| 2748 | { |
| 2749 | u32 reg; |
| 2750 | unsigned int tx_pin; |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 2751 | u8 bbp, rfcsr; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2752 | |
Gabor Juhos | 97aa03f | 2013-07-08 16:08:23 +0200 | [diff] [blame] | 2753 | info->default_power1 = rt2800_txpower_to_dev(rt2x00dev, rf->channel, |
| 2754 | info->default_power1); |
| 2755 | info->default_power2 = rt2800_txpower_to_dev(rt2x00dev, rf->channel, |
| 2756 | info->default_power2); |
Ivo van Doorn | 46323e1 | 2010-08-23 19:55:43 +0200 | [diff] [blame] | 2757 | |
Gertjan van Wingerde | 5aa5701 | 2011-12-28 01:53:20 +0100 | [diff] [blame] | 2758 | switch (rt2x00dev->chip.rf) { |
| 2759 | case RF2020: |
| 2760 | case RF3020: |
| 2761 | case RF3021: |
| 2762 | case RF3022: |
| 2763 | case RF3320: |
Gertjan van Wingerde | 06855ef | 2010-04-11 14:31:07 +0200 | [diff] [blame] | 2764 | rt2800_config_channel_rf3xxx(rt2x00dev, conf, rf, info); |
Gertjan van Wingerde | 5aa5701 | 2011-12-28 01:53:20 +0100 | [diff] [blame] | 2765 | break; |
| 2766 | case RF3052: |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2767 | rt2800_config_channel_rf3052(rt2x00dev, conf, rf, info); |
Gertjan van Wingerde | 5aa5701 | 2011-12-28 01:53:20 +0100 | [diff] [blame] | 2768 | break; |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 2769 | case RF3290: |
| 2770 | rt2800_config_channel_rf3290(rt2x00dev, conf, rf, info); |
| 2771 | break; |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 2772 | case RF3322: |
| 2773 | rt2800_config_channel_rf3322(rt2x00dev, conf, rf, info); |
| 2774 | break; |
villacis@palosanto.com | ccf91bd | 2012-05-16 21:07:12 +0200 | [diff] [blame] | 2775 | case RF5360: |
Gertjan van Wingerde | 5aa5701 | 2011-12-28 01:53:20 +0100 | [diff] [blame] | 2776 | case RF5370: |
John Li | 2ed7188 | 2012-02-17 17:33:06 +0800 | [diff] [blame] | 2777 | case RF5372: |
Gertjan van Wingerde | 5aa5701 | 2011-12-28 01:53:20 +0100 | [diff] [blame] | 2778 | case RF5390: |
Zero.Lin | cff3d1f | 2012-05-29 16:11:09 +0800 | [diff] [blame] | 2779 | case RF5392: |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2780 | rt2800_config_channel_rf53xx(rt2x00dev, conf, rf, info); |
Gertjan van Wingerde | 5aa5701 | 2011-12-28 01:53:20 +0100 | [diff] [blame] | 2781 | break; |
Stanislaw Gruszka | 8f82109 | 2013-03-16 19:19:32 +0100 | [diff] [blame] | 2782 | case RF5592: |
| 2783 | rt2800_config_channel_rf55xx(rt2x00dev, conf, rf, info); |
| 2784 | break; |
Gertjan van Wingerde | 5aa5701 | 2011-12-28 01:53:20 +0100 | [diff] [blame] | 2785 | default: |
Gertjan van Wingerde | 06855ef | 2010-04-11 14:31:07 +0200 | [diff] [blame] | 2786 | rt2800_config_channel_rf2xxx(rt2x00dev, conf, rf, info); |
Gertjan van Wingerde | 5aa5701 | 2011-12-28 01:53:20 +0100 | [diff] [blame] | 2787 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2788 | |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 2789 | if (rt2x00_rf(rt2x00dev, RF3290) || |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 2790 | rt2x00_rf(rt2x00dev, RF3322) || |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 2791 | rt2x00_rf(rt2x00dev, RF5360) || |
| 2792 | rt2x00_rf(rt2x00dev, RF5370) || |
| 2793 | rt2x00_rf(rt2x00dev, RF5372) || |
| 2794 | rt2x00_rf(rt2x00dev, RF5390) || |
| 2795 | rt2x00_rf(rt2x00dev, RF5392)) { |
| 2796 | rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr); |
| 2797 | rt2x00_set_field8(&rfcsr, RFCSR30_TX_H20M, 0); |
| 2798 | rt2x00_set_field8(&rfcsr, RFCSR30_RX_H20M, 0); |
| 2799 | rt2800_rfcsr_write(rt2x00dev, 30, rfcsr); |
| 2800 | |
| 2801 | rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr); |
Gabor Juhos | d6d8202 | 2012-12-02 18:34:47 +0100 | [diff] [blame] | 2802 | rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1); |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 2803 | rt2800_rfcsr_write(rt2x00dev, 3, rfcsr); |
| 2804 | } |
| 2805 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2806 | /* |
| 2807 | * Change BBP settings |
| 2808 | */ |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 2809 | if (rt2x00_rt(rt2x00dev, RT3352)) { |
| 2810 | rt2800_bbp_write(rt2x00dev, 27, 0x0); |
Daniel Golle | cf193f6 | 2012-10-04 01:20:41 +0200 | [diff] [blame] | 2811 | rt2800_bbp_write(rt2x00dev, 66, 0x26 + rt2x00dev->lna_gain); |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 2812 | rt2800_bbp_write(rt2x00dev, 27, 0x20); |
Daniel Golle | cf193f6 | 2012-10-04 01:20:41 +0200 | [diff] [blame] | 2813 | rt2800_bbp_write(rt2x00dev, 66, 0x26 + rt2x00dev->lna_gain); |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 2814 | } else { |
| 2815 | rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain); |
| 2816 | rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain); |
| 2817 | rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain); |
| 2818 | rt2800_bbp_write(rt2x00dev, 86, 0); |
| 2819 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2820 | |
| 2821 | if (rf->channel <= 14) { |
John Li | 2ed7188 | 2012-02-17 17:33:06 +0800 | [diff] [blame] | 2822 | if (!rt2x00_rt(rt2x00dev, RT5390) && |
Gabor Juhos | e6d227b | 2012-12-02 15:53:28 +0100 | [diff] [blame] | 2823 | !rt2x00_rt(rt2x00dev, RT5392)) { |
Ivo van Doorn | 7dab73b | 2011-04-18 15:27:06 +0200 | [diff] [blame] | 2824 | if (test_bit(CAPABILITY_EXTERNAL_LNA_BG, |
| 2825 | &rt2x00dev->cap_flags)) { |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 2826 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
| 2827 | rt2800_bbp_write(rt2x00dev, 75, 0x46); |
| 2828 | } else { |
| 2829 | rt2800_bbp_write(rt2x00dev, 82, 0x84); |
| 2830 | rt2800_bbp_write(rt2x00dev, 75, 0x50); |
| 2831 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2832 | } |
| 2833 | } else { |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2834 | if (rt2x00_rt(rt2x00dev, RT3572)) |
| 2835 | rt2800_bbp_write(rt2x00dev, 82, 0x94); |
| 2836 | else |
| 2837 | rt2800_bbp_write(rt2x00dev, 82, 0xf2); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2838 | |
Ivo van Doorn | 7dab73b | 2011-04-18 15:27:06 +0200 | [diff] [blame] | 2839 | if (test_bit(CAPABILITY_EXTERNAL_LNA_A, &rt2x00dev->cap_flags)) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2840 | rt2800_bbp_write(rt2x00dev, 75, 0x46); |
| 2841 | else |
| 2842 | rt2800_bbp_write(rt2x00dev, 75, 0x50); |
| 2843 | } |
| 2844 | |
| 2845 | rt2800_register_read(rt2x00dev, TX_BAND_CFG, ®); |
Gertjan van Wingerde | a21ee72 | 2010-05-03 22:43:04 +0200 | [diff] [blame] | 2846 | 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] | 2847 | rt2x00_set_field32(®, TX_BAND_CFG_A, rf->channel > 14); |
| 2848 | rt2x00_set_field32(®, TX_BAND_CFG_BG, rf->channel <= 14); |
| 2849 | rt2800_register_write(rt2x00dev, TX_BAND_CFG, reg); |
| 2850 | |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2851 | if (rt2x00_rt(rt2x00dev, RT3572)) |
| 2852 | rt2800_rfcsr_write(rt2x00dev, 8, 0); |
| 2853 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2854 | tx_pin = 0; |
| 2855 | |
Gabor Juhos | bb16d48 | 2013-06-24 23:03:24 +0200 | [diff] [blame] | 2856 | switch (rt2x00dev->default_ant.tx_chain_num) { |
| 2857 | case 3: |
| 2858 | /* Turn on tertiary PAs */ |
| 2859 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A2_EN, |
| 2860 | rf->channel > 14); |
| 2861 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G2_EN, |
| 2862 | rf->channel <= 14); |
| 2863 | /* fall-through */ |
| 2864 | case 2: |
| 2865 | /* Turn on secondary PAs */ |
Gertjan van Wingerde | 65f31b5 | 2011-05-18 20:25:05 +0200 | [diff] [blame] | 2866 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, |
| 2867 | rf->channel > 14); |
| 2868 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, |
| 2869 | rf->channel <= 14); |
Gabor Juhos | bb16d48 | 2013-06-24 23:03:24 +0200 | [diff] [blame] | 2870 | /* fall-through */ |
| 2871 | case 1: |
| 2872 | /* Turn on primary PAs */ |
| 2873 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, |
| 2874 | rf->channel > 14); |
| 2875 | if (test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags)) |
| 2876 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, 1); |
| 2877 | else |
| 2878 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, |
| 2879 | rf->channel <= 14); |
| 2880 | break; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2881 | } |
| 2882 | |
Gabor Juhos | bb16d48 | 2013-06-24 23:03:24 +0200 | [diff] [blame] | 2883 | switch (rt2x00dev->default_ant.rx_chain_num) { |
| 2884 | case 3: |
| 2885 | /* Turn on tertiary LNAs */ |
| 2886 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A2_EN, 1); |
| 2887 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G2_EN, 1); |
| 2888 | /* fall-through */ |
| 2889 | case 2: |
| 2890 | /* Turn on secondary LNAs */ |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2891 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1); |
| 2892 | 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] | 2893 | /* fall-through */ |
| 2894 | case 1: |
| 2895 | /* Turn on primary LNAs */ |
| 2896 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN, 1); |
| 2897 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN, 1); |
| 2898 | break; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2899 | } |
| 2900 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2901 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1); |
| 2902 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_TRSW_EN, 1); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2903 | |
| 2904 | rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin); |
| 2905 | |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 2906 | if (rt2x00_rt(rt2x00dev, RT3572)) |
| 2907 | rt2800_rfcsr_write(rt2x00dev, 8, 0x80); |
| 2908 | |
Stanislaw Gruszka | 6803141 | 2013-03-16 19:19:44 +0100 | [diff] [blame] | 2909 | if (rt2x00_rt(rt2x00dev, RT5592)) { |
| 2910 | rt2800_bbp_write(rt2x00dev, 195, 141); |
| 2911 | rt2800_bbp_write(rt2x00dev, 196, conf_is_ht40(conf) ? 0x10 : 0x1a); |
| 2912 | |
Stanislaw Gruszka | 8ba0ebf | 2013-03-16 19:19:48 +0100 | [diff] [blame] | 2913 | /* AGC init */ |
| 2914 | reg = (rf->channel <= 14 ? 0x1c : 0x24) + 2 * rt2x00dev->lna_gain; |
| 2915 | rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, reg); |
| 2916 | |
Stanislaw Gruszka | 8756130 | 2013-03-16 19:19:45 +0100 | [diff] [blame] | 2917 | rt2800_iq_calibrate(rt2x00dev, rf->channel); |
Stanislaw Gruszka | 6803141 | 2013-03-16 19:19:44 +0100 | [diff] [blame] | 2918 | } |
| 2919 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2920 | rt2800_bbp_read(rt2x00dev, 4, &bbp); |
| 2921 | rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * conf_is_ht40(conf)); |
| 2922 | rt2800_bbp_write(rt2x00dev, 4, bbp); |
| 2923 | |
| 2924 | rt2800_bbp_read(rt2x00dev, 3, &bbp); |
Gertjan van Wingerde | a21ee72 | 2010-05-03 22:43:04 +0200 | [diff] [blame] | 2925 | rt2x00_set_field8(&bbp, BBP3_HT40_MINUS, conf_is_ht40_minus(conf)); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2926 | rt2800_bbp_write(rt2x00dev, 3, bbp); |
| 2927 | |
Gertjan van Wingerde | 8d0c9b6 | 2010-04-11 14:31:10 +0200 | [diff] [blame] | 2928 | if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2929 | if (conf_is_ht40(conf)) { |
| 2930 | rt2800_bbp_write(rt2x00dev, 69, 0x1a); |
| 2931 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
| 2932 | rt2800_bbp_write(rt2x00dev, 73, 0x16); |
| 2933 | } else { |
| 2934 | rt2800_bbp_write(rt2x00dev, 69, 0x16); |
| 2935 | rt2800_bbp_write(rt2x00dev, 70, 0x08); |
| 2936 | rt2800_bbp_write(rt2x00dev, 73, 0x11); |
| 2937 | } |
| 2938 | } |
| 2939 | |
| 2940 | msleep(1); |
Helmut Schaa | 977206d | 2010-12-13 12:31:58 +0100 | [diff] [blame] | 2941 | |
| 2942 | /* |
| 2943 | * Clear channel statistic counters |
| 2944 | */ |
| 2945 | rt2800_register_read(rt2x00dev, CH_IDLE_STA, ®); |
| 2946 | rt2800_register_read(rt2x00dev, CH_BUSY_STA, ®); |
| 2947 | rt2800_register_read(rt2x00dev, CH_BUSY_STA_SEC, ®); |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 2948 | |
| 2949 | /* |
| 2950 | * Clear update flag |
| 2951 | */ |
| 2952 | if (rt2x00_rt(rt2x00dev, RT3352)) { |
| 2953 | rt2800_bbp_read(rt2x00dev, 49, &bbp); |
| 2954 | rt2x00_set_field8(&bbp, BBP49_UPDATE_FLAG, 0); |
| 2955 | rt2800_bbp_write(rt2x00dev, 49, bbp); |
| 2956 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 2957 | } |
| 2958 | |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 2959 | static int rt2800_get_gain_calibration_delta(struct rt2x00_dev *rt2x00dev) |
| 2960 | { |
| 2961 | u8 tssi_bounds[9]; |
| 2962 | u8 current_tssi; |
| 2963 | u16 eeprom; |
| 2964 | u8 step; |
| 2965 | int i; |
| 2966 | |
| 2967 | /* |
| 2968 | * Read TSSI boundaries for temperature compensation from |
| 2969 | * the EEPROM. |
| 2970 | * |
| 2971 | * Array idx 0 1 2 3 4 5 6 7 8 |
| 2972 | * Matching Delta value -4 -3 -2 -1 0 +1 +2 +3 +4 |
| 2973 | * Example TSSI bounds 0xF0 0xD0 0xB5 0xA0 0x88 0x45 0x25 0x15 0x00 |
| 2974 | */ |
| 2975 | if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 2976 | rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG1, &eeprom); |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 2977 | tssi_bounds[0] = rt2x00_get_field16(eeprom, |
| 2978 | EEPROM_TSSI_BOUND_BG1_MINUS4); |
| 2979 | tssi_bounds[1] = rt2x00_get_field16(eeprom, |
| 2980 | EEPROM_TSSI_BOUND_BG1_MINUS3); |
| 2981 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 2982 | rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG2, &eeprom); |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 2983 | tssi_bounds[2] = rt2x00_get_field16(eeprom, |
| 2984 | EEPROM_TSSI_BOUND_BG2_MINUS2); |
| 2985 | tssi_bounds[3] = rt2x00_get_field16(eeprom, |
| 2986 | EEPROM_TSSI_BOUND_BG2_MINUS1); |
| 2987 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 2988 | rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG3, &eeprom); |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 2989 | tssi_bounds[4] = rt2x00_get_field16(eeprom, |
| 2990 | EEPROM_TSSI_BOUND_BG3_REF); |
| 2991 | tssi_bounds[5] = rt2x00_get_field16(eeprom, |
| 2992 | EEPROM_TSSI_BOUND_BG3_PLUS1); |
| 2993 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 2994 | rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG4, &eeprom); |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 2995 | tssi_bounds[6] = rt2x00_get_field16(eeprom, |
| 2996 | EEPROM_TSSI_BOUND_BG4_PLUS2); |
| 2997 | tssi_bounds[7] = rt2x00_get_field16(eeprom, |
| 2998 | EEPROM_TSSI_BOUND_BG4_PLUS3); |
| 2999 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 3000 | rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG5, &eeprom); |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3001 | tssi_bounds[8] = rt2x00_get_field16(eeprom, |
| 3002 | EEPROM_TSSI_BOUND_BG5_PLUS4); |
| 3003 | |
| 3004 | step = rt2x00_get_field16(eeprom, |
| 3005 | EEPROM_TSSI_BOUND_BG5_AGC_STEP); |
| 3006 | } else { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 3007 | rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A1, &eeprom); |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3008 | tssi_bounds[0] = rt2x00_get_field16(eeprom, |
| 3009 | EEPROM_TSSI_BOUND_A1_MINUS4); |
| 3010 | tssi_bounds[1] = rt2x00_get_field16(eeprom, |
| 3011 | EEPROM_TSSI_BOUND_A1_MINUS3); |
| 3012 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 3013 | rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A2, &eeprom); |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3014 | tssi_bounds[2] = rt2x00_get_field16(eeprom, |
| 3015 | EEPROM_TSSI_BOUND_A2_MINUS2); |
| 3016 | tssi_bounds[3] = rt2x00_get_field16(eeprom, |
| 3017 | EEPROM_TSSI_BOUND_A2_MINUS1); |
| 3018 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 3019 | rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A3, &eeprom); |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3020 | tssi_bounds[4] = rt2x00_get_field16(eeprom, |
| 3021 | EEPROM_TSSI_BOUND_A3_REF); |
| 3022 | tssi_bounds[5] = rt2x00_get_field16(eeprom, |
| 3023 | EEPROM_TSSI_BOUND_A3_PLUS1); |
| 3024 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 3025 | rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A4, &eeprom); |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3026 | tssi_bounds[6] = rt2x00_get_field16(eeprom, |
| 3027 | EEPROM_TSSI_BOUND_A4_PLUS2); |
| 3028 | tssi_bounds[7] = rt2x00_get_field16(eeprom, |
| 3029 | EEPROM_TSSI_BOUND_A4_PLUS3); |
| 3030 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 3031 | rt2800_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A5, &eeprom); |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3032 | tssi_bounds[8] = rt2x00_get_field16(eeprom, |
| 3033 | EEPROM_TSSI_BOUND_A5_PLUS4); |
| 3034 | |
| 3035 | step = rt2x00_get_field16(eeprom, |
| 3036 | EEPROM_TSSI_BOUND_A5_AGC_STEP); |
| 3037 | } |
| 3038 | |
| 3039 | /* |
| 3040 | * Check if temperature compensation is supported. |
| 3041 | */ |
Stanislaw Gruszka | bf7e1ab | 2012-10-25 09:51:39 +0200 | [diff] [blame] | 3042 | if (tssi_bounds[4] == 0xff || step == 0xff) |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3043 | return 0; |
| 3044 | |
| 3045 | /* |
| 3046 | * Read current TSSI (BBP 49). |
| 3047 | */ |
| 3048 | rt2800_bbp_read(rt2x00dev, 49, ¤t_tssi); |
| 3049 | |
| 3050 | /* |
| 3051 | * Compare TSSI value (BBP49) with the compensation boundaries |
| 3052 | * from the EEPROM and increase or decrease tx power. |
| 3053 | */ |
| 3054 | for (i = 0; i <= 3; i++) { |
| 3055 | if (current_tssi > tssi_bounds[i]) |
| 3056 | break; |
| 3057 | } |
| 3058 | |
| 3059 | if (i == 4) { |
| 3060 | for (i = 8; i >= 5; i--) { |
| 3061 | if (current_tssi < tssi_bounds[i]) |
| 3062 | break; |
| 3063 | } |
| 3064 | } |
| 3065 | |
| 3066 | return (i - 4) * step; |
| 3067 | } |
| 3068 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3069 | static int rt2800_get_txpower_bw_comp(struct rt2x00_dev *rt2x00dev, |
| 3070 | enum ieee80211_band band) |
| 3071 | { |
| 3072 | u16 eeprom; |
| 3073 | u8 comp_en; |
| 3074 | u8 comp_type; |
Helmut Schaa | 75faae8 | 2011-03-28 13:31:30 +0200 | [diff] [blame] | 3075 | int comp_value = 0; |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3076 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 3077 | rt2800_eeprom_read(rt2x00dev, EEPROM_TXPOWER_DELTA, &eeprom); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3078 | |
Helmut Schaa | 75faae8 | 2011-03-28 13:31:30 +0200 | [diff] [blame] | 3079 | /* |
| 3080 | * HT40 compensation not required. |
| 3081 | */ |
| 3082 | if (eeprom == 0xffff || |
| 3083 | !test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags)) |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3084 | return 0; |
| 3085 | |
| 3086 | if (band == IEEE80211_BAND_2GHZ) { |
| 3087 | comp_en = rt2x00_get_field16(eeprom, |
| 3088 | EEPROM_TXPOWER_DELTA_ENABLE_2G); |
| 3089 | if (comp_en) { |
| 3090 | comp_type = rt2x00_get_field16(eeprom, |
| 3091 | EEPROM_TXPOWER_DELTA_TYPE_2G); |
| 3092 | comp_value = rt2x00_get_field16(eeprom, |
| 3093 | EEPROM_TXPOWER_DELTA_VALUE_2G); |
| 3094 | if (!comp_type) |
| 3095 | comp_value = -comp_value; |
| 3096 | } |
| 3097 | } else { |
| 3098 | comp_en = rt2x00_get_field16(eeprom, |
| 3099 | EEPROM_TXPOWER_DELTA_ENABLE_5G); |
| 3100 | if (comp_en) { |
| 3101 | comp_type = rt2x00_get_field16(eeprom, |
| 3102 | EEPROM_TXPOWER_DELTA_TYPE_5G); |
| 3103 | comp_value = rt2x00_get_field16(eeprom, |
| 3104 | EEPROM_TXPOWER_DELTA_VALUE_5G); |
| 3105 | if (!comp_type) |
| 3106 | comp_value = -comp_value; |
| 3107 | } |
| 3108 | } |
| 3109 | |
| 3110 | return comp_value; |
| 3111 | } |
| 3112 | |
Stanislaw Gruszka | 1e4cf24 | 2012-10-05 13:44:14 +0200 | [diff] [blame] | 3113 | static int rt2800_get_txpower_reg_delta(struct rt2x00_dev *rt2x00dev, |
| 3114 | int power_level, int max_power) |
| 3115 | { |
| 3116 | int delta; |
| 3117 | |
| 3118 | if (test_bit(CAPABILITY_POWER_LIMIT, &rt2x00dev->cap_flags)) |
| 3119 | return 0; |
| 3120 | |
| 3121 | /* |
| 3122 | * XXX: We don't know the maximum transmit power of our hardware since |
| 3123 | * the EEPROM doesn't expose it. We only know that we are calibrated |
| 3124 | * to 100% tx power. |
| 3125 | * |
| 3126 | * Hence, we assume the regulatory limit that cfg80211 calulated for |
| 3127 | * the current channel is our maximum and if we are requested to lower |
| 3128 | * the value we just reduce our tx power accordingly. |
| 3129 | */ |
| 3130 | delta = power_level - max_power; |
| 3131 | return min(delta, 0); |
| 3132 | } |
| 3133 | |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 3134 | static u8 rt2800_compensate_txpower(struct rt2x00_dev *rt2x00dev, int is_rate_b, |
| 3135 | enum ieee80211_band band, int power_level, |
| 3136 | u8 txpower, int delta) |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3137 | { |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3138 | u16 eeprom; |
| 3139 | u8 criterion; |
| 3140 | u8 eirp_txpower; |
| 3141 | u8 eirp_txpower_criterion; |
| 3142 | u8 reg_limit; |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3143 | |
Gabor Juhos | 34542ff | 2013-07-08 16:08:20 +0200 | [diff] [blame] | 3144 | if (rt2x00_rt(rt2x00dev, RT3593)) |
| 3145 | return min_t(u8, txpower, 0xc); |
| 3146 | |
Ivo van Doorn | 7dab73b | 2011-04-18 15:27:06 +0200 | [diff] [blame] | 3147 | if (test_bit(CAPABILITY_POWER_LIMIT, &rt2x00dev->cap_flags)) { |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3148 | /* |
| 3149 | * Check if eirp txpower exceed txpower_limit. |
| 3150 | * We use OFDM 6M as criterion and its eirp txpower |
| 3151 | * is stored at EEPROM_EIRP_MAX_TX_POWER. |
| 3152 | * .11b data rate need add additional 4dbm |
| 3153 | * when calculating eirp txpower. |
| 3154 | */ |
Gabor Juhos | 022138c | 2013-07-08 11:25:54 +0200 | [diff] [blame] | 3155 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE, |
| 3156 | 1, &eeprom); |
Stanislaw Gruszka | d9bceae | 2012-10-05 13:44:12 +0200 | [diff] [blame] | 3157 | criterion = rt2x00_get_field16(eeprom, |
| 3158 | EEPROM_TXPOWER_BYRATE_RATE0); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3159 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 3160 | rt2800_eeprom_read(rt2x00dev, EEPROM_EIRP_MAX_TX_POWER, |
Stanislaw Gruszka | d9bceae | 2012-10-05 13:44:12 +0200 | [diff] [blame] | 3161 | &eeprom); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3162 | |
| 3163 | if (band == IEEE80211_BAND_2GHZ) |
| 3164 | eirp_txpower_criterion = rt2x00_get_field16(eeprom, |
| 3165 | EEPROM_EIRP_MAX_TX_POWER_2GHZ); |
| 3166 | else |
| 3167 | eirp_txpower_criterion = rt2x00_get_field16(eeprom, |
| 3168 | EEPROM_EIRP_MAX_TX_POWER_5GHZ); |
| 3169 | |
| 3170 | eirp_txpower = eirp_txpower_criterion + (txpower - criterion) + |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 3171 | (is_rate_b ? 4 : 0) + delta; |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3172 | |
| 3173 | reg_limit = (eirp_txpower > power_level) ? |
| 3174 | (eirp_txpower - power_level) : 0; |
| 3175 | } else |
| 3176 | reg_limit = 0; |
| 3177 | |
Stanislaw Gruszka | 19f3fa2 | 2012-10-05 13:44:10 +0200 | [diff] [blame] | 3178 | txpower = max(0, txpower + delta - reg_limit); |
| 3179 | return min_t(u8, txpower, 0xc); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3180 | } |
| 3181 | |
Gabor Juhos | 34542ff | 2013-07-08 16:08:20 +0200 | [diff] [blame] | 3182 | |
| 3183 | enum { |
| 3184 | TX_PWR_CFG_0_IDX, |
| 3185 | TX_PWR_CFG_1_IDX, |
| 3186 | TX_PWR_CFG_2_IDX, |
| 3187 | TX_PWR_CFG_3_IDX, |
| 3188 | TX_PWR_CFG_4_IDX, |
| 3189 | TX_PWR_CFG_5_IDX, |
| 3190 | TX_PWR_CFG_6_IDX, |
| 3191 | TX_PWR_CFG_7_IDX, |
| 3192 | TX_PWR_CFG_8_IDX, |
| 3193 | TX_PWR_CFG_9_IDX, |
| 3194 | TX_PWR_CFG_0_EXT_IDX, |
| 3195 | TX_PWR_CFG_1_EXT_IDX, |
| 3196 | TX_PWR_CFG_2_EXT_IDX, |
| 3197 | TX_PWR_CFG_3_EXT_IDX, |
| 3198 | TX_PWR_CFG_4_EXT_IDX, |
| 3199 | TX_PWR_CFG_IDX_COUNT, |
| 3200 | }; |
| 3201 | |
| 3202 | static void rt2800_config_txpower_rt3593(struct rt2x00_dev *rt2x00dev, |
| 3203 | struct ieee80211_channel *chan, |
| 3204 | int power_level) |
| 3205 | { |
| 3206 | u8 txpower; |
| 3207 | u16 eeprom; |
| 3208 | u32 regs[TX_PWR_CFG_IDX_COUNT]; |
| 3209 | unsigned int offset; |
| 3210 | enum ieee80211_band band = chan->band; |
| 3211 | int delta; |
| 3212 | int i; |
| 3213 | |
| 3214 | memset(regs, '\0', sizeof(regs)); |
| 3215 | |
| 3216 | /* TODO: adapt TX power reduction from the rt28xx code */ |
| 3217 | |
| 3218 | /* calculate temperature compensation delta */ |
| 3219 | delta = rt2800_get_gain_calibration_delta(rt2x00dev); |
| 3220 | |
| 3221 | if (band == IEEE80211_BAND_5GHZ) |
| 3222 | offset = 16; |
| 3223 | else |
| 3224 | offset = 0; |
| 3225 | |
| 3226 | if (test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags)) |
| 3227 | offset += 8; |
| 3228 | |
| 3229 | /* read the next four txpower values */ |
| 3230 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE, |
| 3231 | offset, &eeprom); |
| 3232 | |
| 3233 | /* CCK 1MBS,2MBS */ |
| 3234 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0); |
| 3235 | txpower = rt2800_compensate_txpower(rt2x00dev, 1, band, power_level, |
| 3236 | txpower, delta); |
| 3237 | rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX], |
| 3238 | TX_PWR_CFG_0_CCK1_CH0, txpower); |
| 3239 | rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX], |
| 3240 | TX_PWR_CFG_0_CCK1_CH1, txpower); |
| 3241 | rt2x00_set_field32(®s[TX_PWR_CFG_0_EXT_IDX], |
| 3242 | TX_PWR_CFG_0_EXT_CCK1_CH2, txpower); |
| 3243 | |
| 3244 | /* CCK 5.5MBS,11MBS */ |
| 3245 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1); |
| 3246 | txpower = rt2800_compensate_txpower(rt2x00dev, 1, band, power_level, |
| 3247 | txpower, delta); |
| 3248 | rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX], |
| 3249 | TX_PWR_CFG_0_CCK5_CH0, txpower); |
| 3250 | rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX], |
| 3251 | TX_PWR_CFG_0_CCK5_CH1, txpower); |
| 3252 | rt2x00_set_field32(®s[TX_PWR_CFG_0_EXT_IDX], |
| 3253 | TX_PWR_CFG_0_EXT_CCK5_CH2, txpower); |
| 3254 | |
| 3255 | /* OFDM 6MBS,9MBS */ |
| 3256 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2); |
| 3257 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3258 | txpower, delta); |
| 3259 | rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX], |
| 3260 | TX_PWR_CFG_0_OFDM6_CH0, txpower); |
| 3261 | rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX], |
| 3262 | TX_PWR_CFG_0_OFDM6_CH1, txpower); |
| 3263 | rt2x00_set_field32(®s[TX_PWR_CFG_0_EXT_IDX], |
| 3264 | TX_PWR_CFG_0_EXT_OFDM6_CH2, txpower); |
| 3265 | |
| 3266 | /* OFDM 12MBS,18MBS */ |
| 3267 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3); |
| 3268 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3269 | txpower, delta); |
| 3270 | rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX], |
| 3271 | TX_PWR_CFG_0_OFDM12_CH0, txpower); |
| 3272 | rt2x00_set_field32(®s[TX_PWR_CFG_0_IDX], |
| 3273 | TX_PWR_CFG_0_OFDM12_CH1, txpower); |
| 3274 | rt2x00_set_field32(®s[TX_PWR_CFG_0_EXT_IDX], |
| 3275 | TX_PWR_CFG_0_EXT_OFDM12_CH2, txpower); |
| 3276 | |
| 3277 | /* read the next four txpower values */ |
| 3278 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE, |
| 3279 | offset + 1, &eeprom); |
| 3280 | |
| 3281 | /* OFDM 24MBS,36MBS */ |
| 3282 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0); |
| 3283 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3284 | txpower, delta); |
| 3285 | rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX], |
| 3286 | TX_PWR_CFG_1_OFDM24_CH0, txpower); |
| 3287 | rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX], |
| 3288 | TX_PWR_CFG_1_OFDM24_CH1, txpower); |
| 3289 | rt2x00_set_field32(®s[TX_PWR_CFG_1_EXT_IDX], |
| 3290 | TX_PWR_CFG_1_EXT_OFDM24_CH2, txpower); |
| 3291 | |
| 3292 | /* OFDM 48MBS */ |
| 3293 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1); |
| 3294 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3295 | txpower, delta); |
| 3296 | rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX], |
| 3297 | TX_PWR_CFG_1_OFDM48_CH0, txpower); |
| 3298 | rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX], |
| 3299 | TX_PWR_CFG_1_OFDM48_CH1, txpower); |
| 3300 | rt2x00_set_field32(®s[TX_PWR_CFG_1_EXT_IDX], |
| 3301 | TX_PWR_CFG_1_EXT_OFDM48_CH2, txpower); |
| 3302 | |
| 3303 | /* OFDM 54MBS */ |
| 3304 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2); |
| 3305 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3306 | txpower, delta); |
| 3307 | rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX], |
| 3308 | TX_PWR_CFG_7_OFDM54_CH0, txpower); |
| 3309 | rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX], |
| 3310 | TX_PWR_CFG_7_OFDM54_CH1, txpower); |
| 3311 | rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX], |
| 3312 | TX_PWR_CFG_7_OFDM54_CH2, txpower); |
| 3313 | |
| 3314 | /* read the next four txpower values */ |
| 3315 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE, |
| 3316 | offset + 2, &eeprom); |
| 3317 | |
| 3318 | /* MCS 0,1 */ |
| 3319 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0); |
| 3320 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3321 | txpower, delta); |
| 3322 | rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX], |
| 3323 | TX_PWR_CFG_1_MCS0_CH0, txpower); |
| 3324 | rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX], |
| 3325 | TX_PWR_CFG_1_MCS0_CH1, txpower); |
| 3326 | rt2x00_set_field32(®s[TX_PWR_CFG_1_EXT_IDX], |
| 3327 | TX_PWR_CFG_1_EXT_MCS0_CH2, txpower); |
| 3328 | |
| 3329 | /* MCS 2,3 */ |
| 3330 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1); |
| 3331 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3332 | txpower, delta); |
| 3333 | rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX], |
| 3334 | TX_PWR_CFG_1_MCS2_CH0, txpower); |
| 3335 | rt2x00_set_field32(®s[TX_PWR_CFG_1_IDX], |
| 3336 | TX_PWR_CFG_1_MCS2_CH1, txpower); |
| 3337 | rt2x00_set_field32(®s[TX_PWR_CFG_1_EXT_IDX], |
| 3338 | TX_PWR_CFG_1_EXT_MCS2_CH2, txpower); |
| 3339 | |
| 3340 | /* MCS 4,5 */ |
| 3341 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2); |
| 3342 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3343 | txpower, delta); |
| 3344 | rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX], |
| 3345 | TX_PWR_CFG_2_MCS4_CH0, txpower); |
| 3346 | rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX], |
| 3347 | TX_PWR_CFG_2_MCS4_CH1, txpower); |
| 3348 | rt2x00_set_field32(®s[TX_PWR_CFG_2_EXT_IDX], |
| 3349 | TX_PWR_CFG_2_EXT_MCS4_CH2, txpower); |
| 3350 | |
| 3351 | /* MCS 6 */ |
| 3352 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3); |
| 3353 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3354 | txpower, delta); |
| 3355 | rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX], |
| 3356 | TX_PWR_CFG_2_MCS6_CH0, txpower); |
| 3357 | rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX], |
| 3358 | TX_PWR_CFG_2_MCS6_CH1, txpower); |
| 3359 | rt2x00_set_field32(®s[TX_PWR_CFG_2_EXT_IDX], |
| 3360 | TX_PWR_CFG_2_EXT_MCS6_CH2, txpower); |
| 3361 | |
| 3362 | /* read the next four txpower values */ |
| 3363 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE, |
| 3364 | offset + 3, &eeprom); |
| 3365 | |
| 3366 | /* MCS 7 */ |
| 3367 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0); |
| 3368 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3369 | txpower, delta); |
| 3370 | rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX], |
| 3371 | TX_PWR_CFG_7_MCS7_CH0, txpower); |
| 3372 | rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX], |
| 3373 | TX_PWR_CFG_7_MCS7_CH1, txpower); |
| 3374 | rt2x00_set_field32(®s[TX_PWR_CFG_7_IDX], |
| 3375 | TX_PWR_CFG_7_MCS7_CH2, txpower); |
| 3376 | |
| 3377 | /* MCS 8,9 */ |
| 3378 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1); |
| 3379 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3380 | txpower, delta); |
| 3381 | rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX], |
| 3382 | TX_PWR_CFG_2_MCS8_CH0, txpower); |
| 3383 | rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX], |
| 3384 | TX_PWR_CFG_2_MCS8_CH1, txpower); |
| 3385 | rt2x00_set_field32(®s[TX_PWR_CFG_2_EXT_IDX], |
| 3386 | TX_PWR_CFG_2_EXT_MCS8_CH2, txpower); |
| 3387 | |
| 3388 | /* MCS 10,11 */ |
| 3389 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2); |
| 3390 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3391 | txpower, delta); |
| 3392 | rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX], |
| 3393 | TX_PWR_CFG_2_MCS10_CH0, txpower); |
| 3394 | rt2x00_set_field32(®s[TX_PWR_CFG_2_IDX], |
| 3395 | TX_PWR_CFG_2_MCS10_CH1, txpower); |
| 3396 | rt2x00_set_field32(®s[TX_PWR_CFG_2_EXT_IDX], |
| 3397 | TX_PWR_CFG_2_EXT_MCS10_CH2, txpower); |
| 3398 | |
| 3399 | /* MCS 12,13 */ |
| 3400 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3); |
| 3401 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3402 | txpower, delta); |
| 3403 | rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX], |
| 3404 | TX_PWR_CFG_3_MCS12_CH0, txpower); |
| 3405 | rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX], |
| 3406 | TX_PWR_CFG_3_MCS12_CH1, txpower); |
| 3407 | rt2x00_set_field32(®s[TX_PWR_CFG_3_EXT_IDX], |
| 3408 | TX_PWR_CFG_3_EXT_MCS12_CH2, txpower); |
| 3409 | |
| 3410 | /* read the next four txpower values */ |
| 3411 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE, |
| 3412 | offset + 4, &eeprom); |
| 3413 | |
| 3414 | /* MCS 14 */ |
| 3415 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0); |
| 3416 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3417 | txpower, delta); |
| 3418 | rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX], |
| 3419 | TX_PWR_CFG_3_MCS14_CH0, txpower); |
| 3420 | rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX], |
| 3421 | TX_PWR_CFG_3_MCS14_CH1, txpower); |
| 3422 | rt2x00_set_field32(®s[TX_PWR_CFG_3_EXT_IDX], |
| 3423 | TX_PWR_CFG_3_EXT_MCS14_CH2, txpower); |
| 3424 | |
| 3425 | /* MCS 15 */ |
| 3426 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1); |
| 3427 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3428 | txpower, delta); |
| 3429 | rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX], |
| 3430 | TX_PWR_CFG_8_MCS15_CH0, txpower); |
| 3431 | rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX], |
| 3432 | TX_PWR_CFG_8_MCS15_CH1, txpower); |
| 3433 | rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX], |
| 3434 | TX_PWR_CFG_8_MCS15_CH2, txpower); |
| 3435 | |
| 3436 | /* MCS 16,17 */ |
| 3437 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2); |
| 3438 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3439 | txpower, delta); |
| 3440 | rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX], |
| 3441 | TX_PWR_CFG_5_MCS16_CH0, txpower); |
| 3442 | rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX], |
| 3443 | TX_PWR_CFG_5_MCS16_CH1, txpower); |
| 3444 | rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX], |
| 3445 | TX_PWR_CFG_5_MCS16_CH2, txpower); |
| 3446 | |
| 3447 | /* MCS 18,19 */ |
| 3448 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3); |
| 3449 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3450 | txpower, delta); |
| 3451 | rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX], |
| 3452 | TX_PWR_CFG_5_MCS18_CH0, txpower); |
| 3453 | rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX], |
| 3454 | TX_PWR_CFG_5_MCS18_CH1, txpower); |
| 3455 | rt2x00_set_field32(®s[TX_PWR_CFG_5_IDX], |
| 3456 | TX_PWR_CFG_5_MCS18_CH2, txpower); |
| 3457 | |
| 3458 | /* read the next four txpower values */ |
| 3459 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE, |
| 3460 | offset + 5, &eeprom); |
| 3461 | |
| 3462 | /* MCS 20,21 */ |
| 3463 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0); |
| 3464 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3465 | txpower, delta); |
| 3466 | rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX], |
| 3467 | TX_PWR_CFG_6_MCS20_CH0, txpower); |
| 3468 | rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX], |
| 3469 | TX_PWR_CFG_6_MCS20_CH1, txpower); |
| 3470 | rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX], |
| 3471 | TX_PWR_CFG_6_MCS20_CH2, txpower); |
| 3472 | |
| 3473 | /* MCS 22 */ |
| 3474 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1); |
| 3475 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3476 | txpower, delta); |
| 3477 | rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX], |
| 3478 | TX_PWR_CFG_6_MCS22_CH0, txpower); |
| 3479 | rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX], |
| 3480 | TX_PWR_CFG_6_MCS22_CH1, txpower); |
| 3481 | rt2x00_set_field32(®s[TX_PWR_CFG_6_IDX], |
| 3482 | TX_PWR_CFG_6_MCS22_CH2, txpower); |
| 3483 | |
| 3484 | /* MCS 23 */ |
| 3485 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2); |
| 3486 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3487 | txpower, delta); |
| 3488 | rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX], |
| 3489 | TX_PWR_CFG_8_MCS23_CH0, txpower); |
| 3490 | rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX], |
| 3491 | TX_PWR_CFG_8_MCS23_CH1, txpower); |
| 3492 | rt2x00_set_field32(®s[TX_PWR_CFG_8_IDX], |
| 3493 | TX_PWR_CFG_8_MCS23_CH2, txpower); |
| 3494 | |
| 3495 | /* read the next four txpower values */ |
| 3496 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE, |
| 3497 | offset + 6, &eeprom); |
| 3498 | |
| 3499 | /* STBC, MCS 0,1 */ |
| 3500 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0); |
| 3501 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3502 | txpower, delta); |
| 3503 | rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX], |
| 3504 | TX_PWR_CFG_3_STBC0_CH0, txpower); |
| 3505 | rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX], |
| 3506 | TX_PWR_CFG_3_STBC0_CH1, txpower); |
| 3507 | rt2x00_set_field32(®s[TX_PWR_CFG_3_EXT_IDX], |
| 3508 | TX_PWR_CFG_3_EXT_STBC0_CH2, txpower); |
| 3509 | |
| 3510 | /* STBC, MCS 2,3 */ |
| 3511 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE1); |
| 3512 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3513 | txpower, delta); |
| 3514 | rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX], |
| 3515 | TX_PWR_CFG_3_STBC2_CH0, txpower); |
| 3516 | rt2x00_set_field32(®s[TX_PWR_CFG_3_IDX], |
| 3517 | TX_PWR_CFG_3_STBC2_CH1, txpower); |
| 3518 | rt2x00_set_field32(®s[TX_PWR_CFG_3_EXT_IDX], |
| 3519 | TX_PWR_CFG_3_EXT_STBC2_CH2, txpower); |
| 3520 | |
| 3521 | /* STBC, MCS 4,5 */ |
| 3522 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE2); |
| 3523 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3524 | txpower, delta); |
| 3525 | rt2x00_set_field32(®s[TX_PWR_CFG_4_IDX], TX_PWR_CFG_RATE0, txpower); |
| 3526 | rt2x00_set_field32(®s[TX_PWR_CFG_4_IDX], TX_PWR_CFG_RATE1, txpower); |
| 3527 | rt2x00_set_field32(®s[TX_PWR_CFG_4_EXT_IDX], TX_PWR_CFG_RATE0, |
| 3528 | txpower); |
| 3529 | |
| 3530 | /* STBC, MCS 6 */ |
| 3531 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE3); |
| 3532 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3533 | txpower, delta); |
| 3534 | rt2x00_set_field32(®s[TX_PWR_CFG_4_IDX], TX_PWR_CFG_RATE2, txpower); |
| 3535 | rt2x00_set_field32(®s[TX_PWR_CFG_4_IDX], TX_PWR_CFG_RATE3, txpower); |
| 3536 | rt2x00_set_field32(®s[TX_PWR_CFG_4_EXT_IDX], TX_PWR_CFG_RATE2, |
| 3537 | txpower); |
| 3538 | |
| 3539 | /* read the next four txpower values */ |
| 3540 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE, |
| 3541 | offset + 7, &eeprom); |
| 3542 | |
| 3543 | /* STBC, MCS 7 */ |
| 3544 | txpower = rt2x00_get_field16(eeprom, EEPROM_TXPOWER_BYRATE_RATE0); |
| 3545 | txpower = rt2800_compensate_txpower(rt2x00dev, 0, band, power_level, |
| 3546 | txpower, delta); |
| 3547 | rt2x00_set_field32(®s[TX_PWR_CFG_9_IDX], |
| 3548 | TX_PWR_CFG_9_STBC7_CH0, txpower); |
| 3549 | rt2x00_set_field32(®s[TX_PWR_CFG_9_IDX], |
| 3550 | TX_PWR_CFG_9_STBC7_CH1, txpower); |
| 3551 | rt2x00_set_field32(®s[TX_PWR_CFG_9_IDX], |
| 3552 | TX_PWR_CFG_9_STBC7_CH2, txpower); |
| 3553 | |
| 3554 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_0, regs[TX_PWR_CFG_0_IDX]); |
| 3555 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_1, regs[TX_PWR_CFG_1_IDX]); |
| 3556 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_2, regs[TX_PWR_CFG_2_IDX]); |
| 3557 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_3, regs[TX_PWR_CFG_3_IDX]); |
| 3558 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_4, regs[TX_PWR_CFG_4_IDX]); |
| 3559 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_5, regs[TX_PWR_CFG_5_IDX]); |
| 3560 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_6, regs[TX_PWR_CFG_6_IDX]); |
| 3561 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_7, regs[TX_PWR_CFG_7_IDX]); |
| 3562 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_8, regs[TX_PWR_CFG_8_IDX]); |
| 3563 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_9, regs[TX_PWR_CFG_9_IDX]); |
| 3564 | |
| 3565 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_0_EXT, |
| 3566 | regs[TX_PWR_CFG_0_EXT_IDX]); |
| 3567 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_1_EXT, |
| 3568 | regs[TX_PWR_CFG_1_EXT_IDX]); |
| 3569 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_2_EXT, |
| 3570 | regs[TX_PWR_CFG_2_EXT_IDX]); |
| 3571 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_3_EXT, |
| 3572 | regs[TX_PWR_CFG_3_EXT_IDX]); |
| 3573 | rt2800_register_write(rt2x00dev, TX_PWR_CFG_4_EXT, |
| 3574 | regs[TX_PWR_CFG_4_EXT_IDX]); |
| 3575 | |
| 3576 | for (i = 0; i < TX_PWR_CFG_IDX_COUNT; i++) |
| 3577 | rt2x00_dbg(rt2x00dev, |
| 3578 | "band:%cGHz, BW:%c0MHz, TX_PWR_CFG_%d%s = %08lx\n", |
| 3579 | (band == IEEE80211_BAND_5GHZ) ? '5' : '2', |
| 3580 | (test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags)) ? |
| 3581 | '4' : '2', |
| 3582 | (i > TX_PWR_CFG_9_IDX) ? |
| 3583 | (i - TX_PWR_CFG_9_IDX - 1) : i, |
| 3584 | (i > TX_PWR_CFG_9_IDX) ? "_EXT" : "", |
| 3585 | (unsigned long) regs[i]); |
| 3586 | } |
| 3587 | |
Stanislaw Gruszka | 7a66205 | 2012-10-05 13:44:15 +0200 | [diff] [blame] | 3588 | /* |
| 3589 | * We configure transmit power using MAC TX_PWR_CFG_{0,...,N} registers and |
| 3590 | * BBP R1 register. TX_PWR_CFG_X allow to configure per rate TX power values, |
| 3591 | * 4 bits for each rate (tune from 0 to 15 dBm). BBP_R1 controls transmit power |
| 3592 | * for all rates, but allow to set only 4 discrete values: -12, -6, 0 and 6 dBm. |
| 3593 | * Reference per rate transmit power values are located in the EEPROM at |
| 3594 | * EEPROM_TXPOWER_BYRATE offset. We adjust them and BBP R1 settings according to |
| 3595 | * current conditions (i.e. band, bandwidth, temperature, user settings). |
| 3596 | */ |
Gabor Juhos | 34542ff | 2013-07-08 16:08:20 +0200 | [diff] [blame] | 3597 | static void rt2800_config_txpower_rt28xx(struct rt2x00_dev *rt2x00dev, |
| 3598 | struct ieee80211_channel *chan, |
| 3599 | int power_level) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3600 | { |
Stanislaw Gruszka | cee2c73 | 2012-10-05 13:44:09 +0200 | [diff] [blame] | 3601 | u8 txpower, r1; |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3602 | u16 eeprom; |
Stanislaw Gruszka | cee2c73 | 2012-10-05 13:44:09 +0200 | [diff] [blame] | 3603 | u32 reg, offset; |
| 3604 | int i, is_rate_b, delta, power_ctrl; |
Stanislaw Gruszka | 146c3b0 | 2012-10-05 13:44:13 +0200 | [diff] [blame] | 3605 | enum ieee80211_band band = chan->band; |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 3606 | |
| 3607 | /* |
Stanislaw Gruszka | 7a66205 | 2012-10-05 13:44:15 +0200 | [diff] [blame] | 3608 | * Calculate HT40 compensation. For 40MHz we need to add or subtract |
| 3609 | * value read from EEPROM (different for 2GHz and for 5GHz). |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 3610 | */ |
| 3611 | delta = rt2800_get_txpower_bw_comp(rt2x00dev, band); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3612 | |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3613 | /* |
Stanislaw Gruszka | 7a66205 | 2012-10-05 13:44:15 +0200 | [diff] [blame] | 3614 | * Calculate temperature compensation. Depends on measurement of current |
| 3615 | * TSSI (Transmitter Signal Strength Indication) we know TX power (due |
| 3616 | * to temperature or maybe other factors) is smaller or bigger than |
| 3617 | * expected. We adjust it, based on TSSI reference and boundaries values |
| 3618 | * provided in EEPROM. |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3619 | */ |
| 3620 | delta += rt2800_get_gain_calibration_delta(rt2x00dev); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3621 | |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3622 | /* |
Stanislaw Gruszka | 7a66205 | 2012-10-05 13:44:15 +0200 | [diff] [blame] | 3623 | * Decrease power according to user settings, on devices with unknown |
| 3624 | * maximum tx power. For other devices we take user power_level into |
| 3625 | * consideration on rt2800_compensate_txpower(). |
Stanislaw Gruszka | 1e4cf24 | 2012-10-05 13:44:14 +0200 | [diff] [blame] | 3626 | */ |
| 3627 | delta += rt2800_get_txpower_reg_delta(rt2x00dev, power_level, |
| 3628 | chan->max_power); |
| 3629 | |
| 3630 | /* |
Stanislaw Gruszka | cee2c73 | 2012-10-05 13:44:09 +0200 | [diff] [blame] | 3631 | * BBP_R1 controls TX power for all rates, it allow to set the following |
| 3632 | * gains -12, -6, 0, +6 dBm by setting values 2, 1, 0, 3 respectively. |
| 3633 | * |
| 3634 | * TODO: we do not use +6 dBm option to do not increase power beyond |
| 3635 | * regulatory limit, however this could be utilized for devices with |
| 3636 | * CAPABILITY_POWER_LIMIT. |
Stanislaw Gruszka | 8c8d2017 | 2013-06-11 18:48:53 +0200 | [diff] [blame] | 3637 | * |
| 3638 | * TODO: add different temperature compensation code for RT3290 & RT5390 |
| 3639 | * to allow to use BBP_R1 for those chips. |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3640 | */ |
Stanislaw Gruszka | 8c8d2017 | 2013-06-11 18:48:53 +0200 | [diff] [blame] | 3641 | if (!rt2x00_rt(rt2x00dev, RT3290) && |
| 3642 | !rt2x00_rt(rt2x00dev, RT5390)) { |
| 3643 | rt2800_bbp_read(rt2x00dev, 1, &r1); |
| 3644 | if (delta <= -12) { |
| 3645 | power_ctrl = 2; |
| 3646 | delta += 12; |
| 3647 | } else if (delta <= -6) { |
| 3648 | power_ctrl = 1; |
| 3649 | delta += 6; |
| 3650 | } else { |
| 3651 | power_ctrl = 0; |
| 3652 | } |
| 3653 | rt2x00_set_field8(&r1, BBP1_TX_POWER_CTRL, power_ctrl); |
| 3654 | rt2800_bbp_write(rt2x00dev, 1, r1); |
Stanislaw Gruszka | cee2c73 | 2012-10-05 13:44:09 +0200 | [diff] [blame] | 3655 | } |
Stanislaw Gruszka | 8c8d2017 | 2013-06-11 18:48:53 +0200 | [diff] [blame] | 3656 | |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3657 | offset = TX_PWR_CFG_0; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3658 | |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3659 | for (i = 0; i < EEPROM_TXPOWER_BYRATE_SIZE; i += 2) { |
| 3660 | /* just to be safe */ |
| 3661 | if (offset > TX_PWR_CFG_4) |
| 3662 | break; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3663 | |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3664 | rt2800_register_read(rt2x00dev, offset, ®); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3665 | |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3666 | /* read the next four txpower values */ |
Gabor Juhos | 022138c | 2013-07-08 11:25:54 +0200 | [diff] [blame] | 3667 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE, |
| 3668 | i, &eeprom); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3669 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3670 | is_rate_b = i ? 0 : 1; |
| 3671 | /* |
| 3672 | * TX_PWR_CFG_0: 1MBS, TX_PWR_CFG_1: 24MBS, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3673 | * TX_PWR_CFG_2: MCS4, TX_PWR_CFG_3: MCS12, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3674 | * TX_PWR_CFG_4: unknown |
| 3675 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3676 | txpower = rt2x00_get_field16(eeprom, |
| 3677 | EEPROM_TXPOWER_BYRATE_RATE0); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 3678 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 3679 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3680 | rt2x00_set_field32(®, TX_PWR_CFG_RATE0, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3681 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3682 | /* |
| 3683 | * TX_PWR_CFG_0: 2MBS, TX_PWR_CFG_1: 36MBS, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3684 | * TX_PWR_CFG_2: MCS5, TX_PWR_CFG_3: MCS13, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3685 | * TX_PWR_CFG_4: unknown |
| 3686 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3687 | txpower = rt2x00_get_field16(eeprom, |
| 3688 | EEPROM_TXPOWER_BYRATE_RATE1); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 3689 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 3690 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3691 | rt2x00_set_field32(®, TX_PWR_CFG_RATE1, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3692 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3693 | /* |
| 3694 | * TX_PWR_CFG_0: 5.5MBS, TX_PWR_CFG_1: 48MBS, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3695 | * TX_PWR_CFG_2: MCS6, TX_PWR_CFG_3: MCS14, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3696 | * TX_PWR_CFG_4: unknown |
| 3697 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3698 | txpower = rt2x00_get_field16(eeprom, |
| 3699 | EEPROM_TXPOWER_BYRATE_RATE2); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 3700 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 3701 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3702 | rt2x00_set_field32(®, TX_PWR_CFG_RATE2, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3703 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3704 | /* |
| 3705 | * TX_PWR_CFG_0: 11MBS, TX_PWR_CFG_1: 54MBS, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3706 | * TX_PWR_CFG_2: MCS7, TX_PWR_CFG_3: MCS15, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3707 | * TX_PWR_CFG_4: unknown |
| 3708 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3709 | txpower = rt2x00_get_field16(eeprom, |
| 3710 | EEPROM_TXPOWER_BYRATE_RATE3); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 3711 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 3712 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3713 | rt2x00_set_field32(®, TX_PWR_CFG_RATE3, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3714 | |
| 3715 | /* read the next four txpower values */ |
Gabor Juhos | 022138c | 2013-07-08 11:25:54 +0200 | [diff] [blame] | 3716 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_TXPOWER_BYRATE, |
| 3717 | i + 1, &eeprom); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3718 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3719 | is_rate_b = 0; |
| 3720 | /* |
| 3721 | * TX_PWR_CFG_0: 6MBS, TX_PWR_CFG_1: MCS0, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3722 | * TX_PWR_CFG_2: MCS8, TX_PWR_CFG_3: unknown, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3723 | * TX_PWR_CFG_4: unknown |
| 3724 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3725 | txpower = rt2x00_get_field16(eeprom, |
| 3726 | EEPROM_TXPOWER_BYRATE_RATE0); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 3727 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 3728 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3729 | rt2x00_set_field32(®, TX_PWR_CFG_RATE4, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3730 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3731 | /* |
| 3732 | * TX_PWR_CFG_0: 9MBS, TX_PWR_CFG_1: MCS1, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3733 | * TX_PWR_CFG_2: MCS9, TX_PWR_CFG_3: unknown, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3734 | * TX_PWR_CFG_4: unknown |
| 3735 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3736 | txpower = rt2x00_get_field16(eeprom, |
| 3737 | EEPROM_TXPOWER_BYRATE_RATE1); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 3738 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 3739 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3740 | rt2x00_set_field32(®, TX_PWR_CFG_RATE5, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3741 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3742 | /* |
| 3743 | * TX_PWR_CFG_0: 12MBS, TX_PWR_CFG_1: MCS2, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3744 | * TX_PWR_CFG_2: MCS10, TX_PWR_CFG_3: unknown, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3745 | * TX_PWR_CFG_4: unknown |
| 3746 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3747 | txpower = rt2x00_get_field16(eeprom, |
| 3748 | EEPROM_TXPOWER_BYRATE_RATE2); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 3749 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 3750 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3751 | rt2x00_set_field32(®, TX_PWR_CFG_RATE6, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3752 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3753 | /* |
| 3754 | * TX_PWR_CFG_0: 18MBS, TX_PWR_CFG_1: MCS3, |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3755 | * TX_PWR_CFG_2: MCS11, TX_PWR_CFG_3: unknown, |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3756 | * TX_PWR_CFG_4: unknown |
| 3757 | */ |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3758 | txpower = rt2x00_get_field16(eeprom, |
| 3759 | EEPROM_TXPOWER_BYRATE_RATE3); |
Helmut Schaa | fa71a16 | 2011-03-28 13:32:32 +0200 | [diff] [blame] | 3760 | txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band, |
Helmut Schaa | 2af242e | 2011-03-28 13:32:01 +0200 | [diff] [blame] | 3761 | power_level, txpower, delta); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3762 | rt2x00_set_field32(®, TX_PWR_CFG_RATE7, txpower); |
Helmut Schaa | 5e84600 | 2010-07-11 12:23:09 +0200 | [diff] [blame] | 3763 | |
| 3764 | rt2800_register_write(rt2x00dev, offset, reg); |
| 3765 | |
| 3766 | /* next TX_PWR_CFG register */ |
| 3767 | offset += 4; |
| 3768 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3769 | } |
| 3770 | |
Gabor Juhos | 34542ff | 2013-07-08 16:08:20 +0200 | [diff] [blame] | 3771 | static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev, |
| 3772 | struct ieee80211_channel *chan, |
| 3773 | int power_level) |
| 3774 | { |
| 3775 | if (rt2x00_rt(rt2x00dev, RT3593)) |
| 3776 | rt2800_config_txpower_rt3593(rt2x00dev, chan, power_level); |
| 3777 | else |
| 3778 | rt2800_config_txpower_rt28xx(rt2x00dev, chan, power_level); |
| 3779 | } |
| 3780 | |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3781 | void rt2800_gain_calibration(struct rt2x00_dev *rt2x00dev) |
| 3782 | { |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 3783 | rt2800_config_txpower(rt2x00dev, rt2x00dev->hw->conf.chandef.chan, |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3784 | rt2x00dev->tx_power); |
| 3785 | } |
| 3786 | EXPORT_SYMBOL_GPL(rt2800_gain_calibration); |
| 3787 | |
John Li | 2e9c43d | 2012-02-16 21:40:57 +0800 | [diff] [blame] | 3788 | void rt2800_vco_calibration(struct rt2x00_dev *rt2x00dev) |
| 3789 | { |
| 3790 | u32 tx_pin; |
| 3791 | u8 rfcsr; |
| 3792 | |
| 3793 | /* |
| 3794 | * A voltage-controlled oscillator(VCO) is an electronic oscillator |
| 3795 | * designed to be controlled in oscillation frequency by a voltage |
| 3796 | * input. Maybe the temperature will affect the frequency of |
| 3797 | * oscillation to be shifted. The VCO calibration will be called |
| 3798 | * periodically to adjust the frequency to be precision. |
| 3799 | */ |
| 3800 | |
| 3801 | rt2800_register_read(rt2x00dev, TX_PIN_CFG, &tx_pin); |
| 3802 | tx_pin &= TX_PIN_CFG_PA_PE_DISABLE; |
| 3803 | rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin); |
| 3804 | |
| 3805 | switch (rt2x00dev->chip.rf) { |
| 3806 | case RF2020: |
| 3807 | case RF3020: |
| 3808 | case RF3021: |
| 3809 | case RF3022: |
| 3810 | case RF3320: |
| 3811 | case RF3052: |
| 3812 | rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr); |
| 3813 | rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1); |
| 3814 | rt2800_rfcsr_write(rt2x00dev, 7, rfcsr); |
| 3815 | break; |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 3816 | case RF3290: |
villacis@palosanto.com | ccf91bd | 2012-05-16 21:07:12 +0200 | [diff] [blame] | 3817 | case RF5360: |
John Li | 2e9c43d | 2012-02-16 21:40:57 +0800 | [diff] [blame] | 3818 | case RF5370: |
| 3819 | case RF5372: |
| 3820 | case RF5390: |
Zero.Lin | cff3d1f | 2012-05-29 16:11:09 +0800 | [diff] [blame] | 3821 | case RF5392: |
John Li | 2e9c43d | 2012-02-16 21:40:57 +0800 | [diff] [blame] | 3822 | rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr); |
Gabor Juhos | d6d8202 | 2012-12-02 18:34:47 +0100 | [diff] [blame] | 3823 | rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1); |
John Li | 2e9c43d | 2012-02-16 21:40:57 +0800 | [diff] [blame] | 3824 | rt2800_rfcsr_write(rt2x00dev, 3, rfcsr); |
| 3825 | break; |
| 3826 | default: |
| 3827 | return; |
| 3828 | } |
| 3829 | |
| 3830 | mdelay(1); |
| 3831 | |
| 3832 | rt2800_register_read(rt2x00dev, TX_PIN_CFG, &tx_pin); |
| 3833 | if (rt2x00dev->rf_channel <= 14) { |
| 3834 | switch (rt2x00dev->default_ant.tx_chain_num) { |
| 3835 | case 3: |
| 3836 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G2_EN, 1); |
| 3837 | /* fall through */ |
| 3838 | case 2: |
| 3839 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1); |
| 3840 | /* fall through */ |
| 3841 | case 1: |
| 3842 | default: |
| 3843 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, 1); |
| 3844 | break; |
| 3845 | } |
| 3846 | } else { |
| 3847 | switch (rt2x00dev->default_ant.tx_chain_num) { |
| 3848 | case 3: |
| 3849 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A2_EN, 1); |
| 3850 | /* fall through */ |
| 3851 | case 2: |
| 3852 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1); |
| 3853 | /* fall through */ |
| 3854 | case 1: |
| 3855 | default: |
| 3856 | rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, 1); |
| 3857 | break; |
| 3858 | } |
| 3859 | } |
| 3860 | rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin); |
| 3861 | |
| 3862 | } |
| 3863 | EXPORT_SYMBOL_GPL(rt2800_vco_calibration); |
| 3864 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3865 | static void rt2800_config_retry_limit(struct rt2x00_dev *rt2x00dev, |
| 3866 | struct rt2x00lib_conf *libconf) |
| 3867 | { |
| 3868 | u32 reg; |
| 3869 | |
| 3870 | rt2800_register_read(rt2x00dev, TX_RTY_CFG, ®); |
| 3871 | rt2x00_set_field32(®, TX_RTY_CFG_SHORT_RTY_LIMIT, |
| 3872 | libconf->conf->short_frame_max_tx_count); |
| 3873 | rt2x00_set_field32(®, TX_RTY_CFG_LONG_RTY_LIMIT, |
| 3874 | libconf->conf->long_frame_max_tx_count); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3875 | rt2800_register_write(rt2x00dev, TX_RTY_CFG, reg); |
| 3876 | } |
| 3877 | |
| 3878 | static void rt2800_config_ps(struct rt2x00_dev *rt2x00dev, |
| 3879 | struct rt2x00lib_conf *libconf) |
| 3880 | { |
| 3881 | enum dev_state state = |
| 3882 | (libconf->conf->flags & IEEE80211_CONF_PS) ? |
| 3883 | STATE_SLEEP : STATE_AWAKE; |
| 3884 | u32 reg; |
| 3885 | |
| 3886 | if (state == STATE_SLEEP) { |
| 3887 | rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0); |
| 3888 | |
| 3889 | rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG, ®); |
| 3890 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 5); |
| 3891 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE, |
| 3892 | libconf->conf->listen_interval - 1); |
| 3893 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTOWAKE, 1); |
| 3894 | rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg); |
| 3895 | |
| 3896 | rt2x00dev->ops->lib->set_device_state(rt2x00dev, state); |
| 3897 | } else { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3898 | rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG, ®); |
| 3899 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 0); |
| 3900 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE, 0); |
| 3901 | rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTOWAKE, 0); |
| 3902 | rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg); |
Gertjan van Wingerde | 5731858 | 2010-03-30 23:50:23 +0200 | [diff] [blame] | 3903 | |
| 3904 | rt2x00dev->ops->lib->set_device_state(rt2x00dev, state); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3905 | } |
| 3906 | } |
| 3907 | |
| 3908 | void rt2800_config(struct rt2x00_dev *rt2x00dev, |
| 3909 | struct rt2x00lib_conf *libconf, |
| 3910 | const unsigned int flags) |
| 3911 | { |
| 3912 | /* Always recalculate LNA gain before changing configuration */ |
| 3913 | rt2800_config_lna_gain(rt2x00dev, libconf); |
| 3914 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3915 | if (flags & IEEE80211_CONF_CHANGE_CHANNEL) { |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3916 | rt2800_config_channel(rt2x00dev, libconf->conf, |
| 3917 | &libconf->rf, &libconf->channel); |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 3918 | rt2800_config_txpower(rt2x00dev, libconf->conf->chandef.chan, |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3919 | libconf->conf->power_level); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 3920 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3921 | if (flags & IEEE80211_CONF_CHANGE_POWER) |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 3922 | rt2800_config_txpower(rt2x00dev, libconf->conf->chandef.chan, |
Helmut Schaa | 9e33a35 | 2011-03-28 13:33:40 +0200 | [diff] [blame] | 3923 | libconf->conf->power_level); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3924 | if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS) |
| 3925 | rt2800_config_retry_limit(rt2x00dev, libconf); |
| 3926 | if (flags & IEEE80211_CONF_CHANGE_PS) |
| 3927 | rt2800_config_ps(rt2x00dev, libconf); |
| 3928 | } |
| 3929 | EXPORT_SYMBOL_GPL(rt2800_config); |
| 3930 | |
| 3931 | /* |
| 3932 | * Link tuning |
| 3933 | */ |
| 3934 | void rt2800_link_stats(struct rt2x00_dev *rt2x00dev, struct link_qual *qual) |
| 3935 | { |
| 3936 | u32 reg; |
| 3937 | |
| 3938 | /* |
| 3939 | * Update FCS error count from register. |
| 3940 | */ |
| 3941 | rt2800_register_read(rt2x00dev, RX_STA_CNT0, ®); |
| 3942 | qual->rx_failed = rt2x00_get_field32(reg, RX_STA_CNT0_CRC_ERR); |
| 3943 | } |
| 3944 | EXPORT_SYMBOL_GPL(rt2800_link_stats); |
| 3945 | |
| 3946 | static u8 rt2800_get_default_vgc(struct rt2x00_dev *rt2x00dev) |
| 3947 | { |
Gertjan van Wingerde | 8c6728b | 2012-09-16 22:29:49 +0200 | [diff] [blame] | 3948 | u8 vgc; |
| 3949 | |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3950 | if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) { |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 3951 | if (rt2x00_rt(rt2x00dev, RT3070) || |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 3952 | rt2x00_rt(rt2x00dev, RT3071) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 3953 | rt2x00_rt(rt2x00dev, RT3090) || |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 3954 | rt2x00_rt(rt2x00dev, RT3290) || |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 3955 | rt2x00_rt(rt2x00dev, RT3390) || |
Gertjan van Wingerde | d961e44 | 2012-09-16 22:29:50 +0200 | [diff] [blame] | 3956 | rt2x00_rt(rt2x00dev, RT3572) || |
John Li | 2ed7188 | 2012-02-17 17:33:06 +0800 | [diff] [blame] | 3957 | rt2x00_rt(rt2x00dev, RT5390) || |
Stanislaw Gruszka | 3d81535 | 2013-03-16 19:19:49 +0100 | [diff] [blame] | 3958 | rt2x00_rt(rt2x00dev, RT5392) || |
| 3959 | rt2x00_rt(rt2x00dev, RT5592)) |
Gertjan van Wingerde | 8c6728b | 2012-09-16 22:29:49 +0200 | [diff] [blame] | 3960 | vgc = 0x1c + (2 * rt2x00dev->lna_gain); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3961 | else |
Gertjan van Wingerde | 8c6728b | 2012-09-16 22:29:49 +0200 | [diff] [blame] | 3962 | vgc = 0x2e + rt2x00dev->lna_gain; |
| 3963 | } else { /* 5GHZ band */ |
Gertjan van Wingerde | d961e44 | 2012-09-16 22:29:50 +0200 | [diff] [blame] | 3964 | if (rt2x00_rt(rt2x00dev, RT3572)) |
| 3965 | vgc = 0x22 + (rt2x00dev->lna_gain * 5) / 3; |
Stanislaw Gruszka | 3d81535 | 2013-03-16 19:19:49 +0100 | [diff] [blame] | 3966 | else if (rt2x00_rt(rt2x00dev, RT5592)) |
| 3967 | vgc = 0x24 + (2 * rt2x00dev->lna_gain); |
Gertjan van Wingerde | d961e44 | 2012-09-16 22:29:50 +0200 | [diff] [blame] | 3968 | else { |
| 3969 | if (!test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags)) |
| 3970 | vgc = 0x32 + (rt2x00dev->lna_gain * 5) / 3; |
| 3971 | else |
| 3972 | vgc = 0x3a + (rt2x00dev->lna_gain * 5) / 3; |
| 3973 | } |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3974 | } |
| 3975 | |
Gertjan van Wingerde | 8c6728b | 2012-09-16 22:29:49 +0200 | [diff] [blame] | 3976 | return vgc; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3977 | } |
| 3978 | |
| 3979 | static inline void rt2800_set_vgc(struct rt2x00_dev *rt2x00dev, |
| 3980 | struct link_qual *qual, u8 vgc_level) |
| 3981 | { |
| 3982 | if (qual->vgc_level != vgc_level) { |
Stanislaw Gruszka | 3d81535 | 2013-03-16 19:19:49 +0100 | [diff] [blame] | 3983 | if (rt2x00_rt(rt2x00dev, RT5592)) { |
| 3984 | rt2800_bbp_write(rt2x00dev, 83, qual->rssi > -65 ? 0x4a : 0x7a); |
| 3985 | rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, vgc_level); |
| 3986 | } else |
| 3987 | rt2800_bbp_write(rt2x00dev, 66, vgc_level); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 3988 | qual->vgc_level = vgc_level; |
| 3989 | qual->vgc_level_reg = vgc_level; |
| 3990 | } |
| 3991 | } |
| 3992 | |
| 3993 | void rt2800_reset_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual) |
| 3994 | { |
| 3995 | rt2800_set_vgc(rt2x00dev, qual, rt2800_get_default_vgc(rt2x00dev)); |
| 3996 | } |
| 3997 | EXPORT_SYMBOL_GPL(rt2800_reset_tuner); |
| 3998 | |
| 3999 | void rt2800_link_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual, |
| 4000 | const u32 count) |
| 4001 | { |
Stanislaw Gruszka | 3d81535 | 2013-03-16 19:19:49 +0100 | [diff] [blame] | 4002 | u8 vgc; |
| 4003 | |
Gertjan van Wingerde | 8d0c9b6 | 2010-04-11 14:31:10 +0200 | [diff] [blame] | 4004 | if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4005 | return; |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4006 | /* |
Stanislaw Gruszka | 3d81535 | 2013-03-16 19:19:49 +0100 | [diff] [blame] | 4007 | * When RSSI is better then -80 increase VGC level with 0x10, except |
| 4008 | * for rt5592 chip. |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4009 | */ |
Stanislaw Gruszka | 3d81535 | 2013-03-16 19:19:49 +0100 | [diff] [blame] | 4010 | |
| 4011 | vgc = rt2800_get_default_vgc(rt2x00dev); |
| 4012 | |
| 4013 | if (rt2x00_rt(rt2x00dev, RT5592) && qual->rssi > -65) |
| 4014 | vgc += 0x20; |
| 4015 | else if (qual->rssi > -80) |
| 4016 | vgc += 0x10; |
| 4017 | |
| 4018 | rt2800_set_vgc(rt2x00dev, qual, vgc); |
Bartlomiej Zolnierkiewicz | f445061 | 2009-11-04 18:36:40 +0100 | [diff] [blame] | 4019 | } |
| 4020 | EXPORT_SYMBOL_GPL(rt2800_link_tuner); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4021 | |
| 4022 | /* |
| 4023 | * Initialization functions. |
| 4024 | */ |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 4025 | static int rt2800_init_registers(struct rt2x00_dev *rt2x00dev) |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4026 | { |
| 4027 | u32 reg; |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 4028 | u16 eeprom; |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4029 | unsigned int i; |
Gertjan van Wingerde | e3a896b | 2010-06-03 10:52:04 +0200 | [diff] [blame] | 4030 | int ret; |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4031 | |
Jakub Kicinski | f7b395e | 2012-04-03 03:40:47 +0200 | [diff] [blame] | 4032 | rt2800_disable_wpdma(rt2x00dev); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4033 | |
Gertjan van Wingerde | e3a896b | 2010-06-03 10:52:04 +0200 | [diff] [blame] | 4034 | ret = rt2800_drv_init_registers(rt2x00dev); |
| 4035 | if (ret) |
| 4036 | return ret; |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4037 | |
| 4038 | rt2800_register_read(rt2x00dev, BCN_OFFSET0, ®); |
| 4039 | rt2x00_set_field32(®, BCN_OFFSET0_BCN0, 0xe0); /* 0x3800 */ |
| 4040 | rt2x00_set_field32(®, BCN_OFFSET0_BCN1, 0xe8); /* 0x3a00 */ |
| 4041 | rt2x00_set_field32(®, BCN_OFFSET0_BCN2, 0xf0); /* 0x3c00 */ |
| 4042 | rt2x00_set_field32(®, BCN_OFFSET0_BCN3, 0xf8); /* 0x3e00 */ |
| 4043 | rt2800_register_write(rt2x00dev, BCN_OFFSET0, reg); |
| 4044 | |
| 4045 | rt2800_register_read(rt2x00dev, BCN_OFFSET1, ®); |
| 4046 | rt2x00_set_field32(®, BCN_OFFSET1_BCN4, 0xc8); /* 0x3200 */ |
| 4047 | rt2x00_set_field32(®, BCN_OFFSET1_BCN5, 0xd0); /* 0x3400 */ |
| 4048 | rt2x00_set_field32(®, BCN_OFFSET1_BCN6, 0x77); /* 0x1dc0 */ |
| 4049 | rt2x00_set_field32(®, BCN_OFFSET1_BCN7, 0x6f); /* 0x1bc0 */ |
| 4050 | rt2800_register_write(rt2x00dev, BCN_OFFSET1, reg); |
| 4051 | |
| 4052 | rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE, 0x0000013f); |
| 4053 | rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003); |
| 4054 | |
| 4055 | rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000); |
| 4056 | |
| 4057 | rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®); |
Helmut Schaa | 8544df3 | 2010-07-11 12:29:49 +0200 | [diff] [blame] | 4058 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_INTERVAL, 1600); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4059 | rt2x00_set_field32(®, BCN_TIME_CFG_TSF_TICKING, 0); |
| 4060 | rt2x00_set_field32(®, BCN_TIME_CFG_TSF_SYNC, 0); |
| 4061 | rt2x00_set_field32(®, BCN_TIME_CFG_TBTT_ENABLE, 0); |
| 4062 | rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 0); |
| 4063 | rt2x00_set_field32(®, BCN_TIME_CFG_TX_TIME_COMPENSATE, 0); |
| 4064 | rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg); |
| 4065 | |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4066 | rt2800_config_filter(rt2x00dev, FIF_ALLMULTI); |
| 4067 | |
| 4068 | rt2800_register_read(rt2x00dev, BKOFF_SLOT_CFG, ®); |
| 4069 | rt2x00_set_field32(®, BKOFF_SLOT_CFG_SLOT_TIME, 9); |
| 4070 | rt2x00_set_field32(®, BKOFF_SLOT_CFG_CC_DELAY_TIME, 2); |
| 4071 | rt2800_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg); |
| 4072 | |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 4073 | if (rt2x00_rt(rt2x00dev, RT3290)) { |
| 4074 | rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, ®); |
| 4075 | if (rt2x00_get_field32(reg, WLAN_EN) == 1) { |
| 4076 | rt2x00_set_field32(®, PCIE_APP0_CLK_REQ, 1); |
| 4077 | rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg); |
| 4078 | } |
| 4079 | |
| 4080 | rt2800_register_read(rt2x00dev, CMB_CTRL, ®); |
| 4081 | if (!(rt2x00_get_field32(reg, LDO0_EN) == 1)) { |
| 4082 | rt2x00_set_field32(®, LDO0_EN, 1); |
| 4083 | rt2x00_set_field32(®, LDO_BGSEL, 3); |
| 4084 | rt2800_register_write(rt2x00dev, CMB_CTRL, reg); |
| 4085 | } |
| 4086 | |
| 4087 | rt2800_register_read(rt2x00dev, OSC_CTRL, ®); |
| 4088 | rt2x00_set_field32(®, OSC_ROSC_EN, 1); |
| 4089 | rt2x00_set_field32(®, OSC_CAL_REQ, 1); |
| 4090 | rt2x00_set_field32(®, OSC_REF_CYCLE, 0x27); |
| 4091 | rt2800_register_write(rt2x00dev, OSC_CTRL, reg); |
| 4092 | |
| 4093 | rt2800_register_read(rt2x00dev, COEX_CFG0, ®); |
| 4094 | rt2x00_set_field32(®, COEX_CFG_ANT, 0x5e); |
| 4095 | rt2800_register_write(rt2x00dev, COEX_CFG0, reg); |
| 4096 | |
| 4097 | rt2800_register_read(rt2x00dev, COEX_CFG2, ®); |
| 4098 | rt2x00_set_field32(®, BT_COEX_CFG1, 0x00); |
| 4099 | rt2x00_set_field32(®, BT_COEX_CFG0, 0x17); |
| 4100 | rt2x00_set_field32(®, WL_COEX_CFG1, 0x93); |
| 4101 | rt2x00_set_field32(®, WL_COEX_CFG0, 0x7f); |
| 4102 | rt2800_register_write(rt2x00dev, COEX_CFG2, reg); |
| 4103 | |
| 4104 | rt2800_register_read(rt2x00dev, PLL_CTRL, ®); |
| 4105 | rt2x00_set_field32(®, PLL_CONTROL, 1); |
| 4106 | rt2800_register_write(rt2x00dev, PLL_CTRL, reg); |
| 4107 | } |
| 4108 | |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 4109 | if (rt2x00_rt(rt2x00dev, RT3071) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 4110 | rt2x00_rt(rt2x00dev, RT3090) || |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 4111 | rt2x00_rt(rt2x00dev, RT3290) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 4112 | rt2x00_rt(rt2x00dev, RT3390)) { |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 4113 | |
| 4114 | if (rt2x00_rt(rt2x00dev, RT3290)) |
| 4115 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, |
| 4116 | 0x00000404); |
| 4117 | else |
| 4118 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, |
| 4119 | 0x00000400); |
| 4120 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4121 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000); |
Gertjan van Wingerde | 6452295 | 2010-04-11 14:31:14 +0200 | [diff] [blame] | 4122 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) || |
Gertjan van Wingerde | cc78e90 | 2010-04-11 14:31:15 +0200 | [diff] [blame] | 4123 | rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E) || |
| 4124 | rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 4125 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, |
| 4126 | &eeprom); |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 4127 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_DAC_TEST)) |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 4128 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, |
| 4129 | 0x0000002c); |
| 4130 | else |
| 4131 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, |
| 4132 | 0x0000000f); |
| 4133 | } else { |
| 4134 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000); |
| 4135 | } |
Gertjan van Wingerde | d5385bf | 2010-04-11 14:31:13 +0200 | [diff] [blame] | 4136 | } else if (rt2x00_rt(rt2x00dev, RT3070)) { |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4137 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400); |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 4138 | |
| 4139 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) { |
| 4140 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000); |
| 4141 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x0000002c); |
| 4142 | } else { |
| 4143 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606); |
| 4144 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000); |
| 4145 | } |
Helmut Schaa | c295a81 | 2010-06-03 10:52:13 +0200 | [diff] [blame] | 4146 | } else if (rt2800_is_305x_soc(rt2x00dev)) { |
| 4147 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400); |
| 4148 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000); |
Helmut Schaa | 961636b | 2011-04-18 15:28:27 +0200 | [diff] [blame] | 4149 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000030); |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 4150 | } else if (rt2x00_rt(rt2x00dev, RT3352)) { |
| 4151 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000402); |
| 4152 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606); |
| 4153 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000); |
Gertjan van Wingerde | 872834d | 2011-05-18 20:25:31 +0200 | [diff] [blame] | 4154 | } else if (rt2x00_rt(rt2x00dev, RT3572)) { |
| 4155 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400); |
| 4156 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606); |
Gabor Juhos | 1706d15 | 2013-07-08 16:08:16 +0200 | [diff] [blame] | 4157 | } else if (rt2x00_rt(rt2x00dev, RT3593)) { |
| 4158 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000402); |
| 4159 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000); |
| 4160 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3593, REV_RT3593E)) { |
| 4161 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, |
| 4162 | &eeprom); |
| 4163 | if (rt2x00_get_field16(eeprom, |
| 4164 | EEPROM_NIC_CONF1_DAC_TEST)) |
| 4165 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, |
| 4166 | 0x0000001f); |
| 4167 | else |
| 4168 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, |
| 4169 | 0x0000000f); |
| 4170 | } else { |
| 4171 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, |
| 4172 | 0x00000000); |
| 4173 | } |
John Li | 2ed7188 | 2012-02-17 17:33:06 +0800 | [diff] [blame] | 4174 | } else if (rt2x00_rt(rt2x00dev, RT5390) || |
Stanislaw Gruszka | 7641328 | 2013-03-16 19:19:33 +0100 | [diff] [blame] | 4175 | rt2x00_rt(rt2x00dev, RT5392) || |
| 4176 | rt2x00_rt(rt2x00dev, RT5592)) { |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 4177 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000404); |
| 4178 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606); |
| 4179 | rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4180 | } else { |
| 4181 | rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000000); |
| 4182 | rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606); |
| 4183 | } |
| 4184 | |
| 4185 | rt2800_register_read(rt2x00dev, TX_LINK_CFG, ®); |
| 4186 | rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_MFB_LIFETIME, 32); |
| 4187 | rt2x00_set_field32(®, TX_LINK_CFG_MFB_ENABLE, 0); |
| 4188 | rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_UMFS_ENABLE, 0); |
| 4189 | rt2x00_set_field32(®, TX_LINK_CFG_TX_MRQ_EN, 0); |
| 4190 | rt2x00_set_field32(®, TX_LINK_CFG_TX_RDG_EN, 0); |
| 4191 | rt2x00_set_field32(®, TX_LINK_CFG_TX_CF_ACK_EN, 1); |
| 4192 | rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_MFB, 0); |
| 4193 | rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_MFS, 0); |
| 4194 | rt2800_register_write(rt2x00dev, TX_LINK_CFG, reg); |
| 4195 | |
| 4196 | rt2800_register_read(rt2x00dev, TX_TIMEOUT_CFG, ®); |
| 4197 | rt2x00_set_field32(®, TX_TIMEOUT_CFG_MPDU_LIFETIME, 9); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4198 | rt2x00_set_field32(®, TX_TIMEOUT_CFG_RX_ACK_TIMEOUT, 32); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4199 | rt2x00_set_field32(®, TX_TIMEOUT_CFG_TX_OP_TIMEOUT, 10); |
| 4200 | rt2800_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg); |
| 4201 | |
| 4202 | rt2800_register_read(rt2x00dev, MAX_LEN_CFG, ®); |
| 4203 | rt2x00_set_field32(®, MAX_LEN_CFG_MAX_MPDU, AGGREGATION_SIZE); |
Gertjan van Wingerde | 8d0c9b6 | 2010-04-11 14:31:10 +0200 | [diff] [blame] | 4204 | if (rt2x00_rt_rev_gte(rt2x00dev, RT2872, REV_RT2872E) || |
Gertjan van Wingerde | 49e721e | 2010-02-13 20:55:49 +0100 | [diff] [blame] | 4205 | rt2x00_rt(rt2x00dev, RT2883) || |
Gertjan van Wingerde | 8d0c9b6 | 2010-04-11 14:31:10 +0200 | [diff] [blame] | 4206 | rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070E)) |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4207 | rt2x00_set_field32(®, MAX_LEN_CFG_MAX_PSDU, 2); |
| 4208 | else |
| 4209 | rt2x00_set_field32(®, MAX_LEN_CFG_MAX_PSDU, 1); |
| 4210 | rt2x00_set_field32(®, MAX_LEN_CFG_MIN_PSDU, 0); |
| 4211 | rt2x00_set_field32(®, MAX_LEN_CFG_MIN_MPDU, 0); |
| 4212 | rt2800_register_write(rt2x00dev, MAX_LEN_CFG, reg); |
| 4213 | |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4214 | rt2800_register_read(rt2x00dev, LED_CFG, ®); |
| 4215 | rt2x00_set_field32(®, LED_CFG_ON_PERIOD, 70); |
| 4216 | rt2x00_set_field32(®, LED_CFG_OFF_PERIOD, 30); |
| 4217 | rt2x00_set_field32(®, LED_CFG_SLOW_BLINK_PERIOD, 3); |
| 4218 | rt2x00_set_field32(®, LED_CFG_R_LED_MODE, 3); |
| 4219 | rt2x00_set_field32(®, LED_CFG_G_LED_MODE, 3); |
| 4220 | rt2x00_set_field32(®, LED_CFG_Y_LED_MODE, 3); |
| 4221 | rt2x00_set_field32(®, LED_CFG_LED_POLAR, 1); |
| 4222 | rt2800_register_write(rt2x00dev, LED_CFG, reg); |
| 4223 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4224 | rt2800_register_write(rt2x00dev, PBF_MAX_PCNT, 0x1f3fbf9f); |
| 4225 | |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4226 | rt2800_register_read(rt2x00dev, TX_RTY_CFG, ®); |
| 4227 | rt2x00_set_field32(®, TX_RTY_CFG_SHORT_RTY_LIMIT, 15); |
| 4228 | rt2x00_set_field32(®, TX_RTY_CFG_LONG_RTY_LIMIT, 31); |
| 4229 | rt2x00_set_field32(®, TX_RTY_CFG_LONG_RTY_THRE, 2000); |
| 4230 | rt2x00_set_field32(®, TX_RTY_CFG_NON_AGG_RTY_MODE, 0); |
| 4231 | rt2x00_set_field32(®, TX_RTY_CFG_AGG_RTY_MODE, 0); |
| 4232 | rt2x00_set_field32(®, TX_RTY_CFG_TX_AUTO_FB_ENABLE, 1); |
| 4233 | rt2800_register_write(rt2x00dev, TX_RTY_CFG, reg); |
| 4234 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4235 | rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, ®); |
| 4236 | rt2x00_set_field32(®, AUTO_RSP_CFG_AUTORESPONDER, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4237 | rt2x00_set_field32(®, AUTO_RSP_CFG_BAC_ACK_POLICY, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4238 | rt2x00_set_field32(®, AUTO_RSP_CFG_CTS_40_MMODE, 0); |
| 4239 | rt2x00_set_field32(®, AUTO_RSP_CFG_CTS_40_MREF, 0); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4240 | rt2x00_set_field32(®, AUTO_RSP_CFG_AR_PREAMBLE, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4241 | rt2x00_set_field32(®, AUTO_RSP_CFG_DUAL_CTS_EN, 0); |
| 4242 | rt2x00_set_field32(®, AUTO_RSP_CFG_ACK_CTS_PSM_BIT, 0); |
| 4243 | rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg); |
| 4244 | |
| 4245 | rt2800_register_read(rt2x00dev, CCK_PROT_CFG, ®); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4246 | rt2x00_set_field32(®, CCK_PROT_CFG_PROTECT_RATE, 3); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4247 | rt2x00_set_field32(®, CCK_PROT_CFG_PROTECT_CTRL, 0); |
Shiang Tu | 6f492b6 | 2011-02-20 13:56:54 +0100 | [diff] [blame] | 4248 | rt2x00_set_field32(®, CCK_PROT_CFG_PROTECT_NAV_SHORT, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4249 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 4250 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 4251 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4252 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_MM40, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4253 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4254 | rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_GF40, 0); |
| 4255 | rt2x00_set_field32(®, CCK_PROT_CFG_RTS_TH_EN, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4256 | rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg); |
| 4257 | |
| 4258 | rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, ®); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4259 | rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_RATE, 3); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4260 | rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_CTRL, 0); |
Shiang Tu | 6f492b6 | 2011-02-20 13:56:54 +0100 | [diff] [blame] | 4261 | rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_NAV_SHORT, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4262 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 4263 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 4264 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4265 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_MM40, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4266 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4267 | rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_GF40, 0); |
| 4268 | rt2x00_set_field32(®, OFDM_PROT_CFG_RTS_TH_EN, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4269 | rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg); |
| 4270 | |
| 4271 | rt2800_register_read(rt2x00dev, MM20_PROT_CFG, ®); |
| 4272 | rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_RATE, 0x4004); |
| 4273 | rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_CTRL, 0); |
Shiang Tu | 6f492b6 | 2011-02-20 13:56:54 +0100 | [diff] [blame] | 4274 | rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_NAV_SHORT, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4275 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 4276 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 4277 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
| 4278 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_MM40, 0); |
| 4279 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
| 4280 | rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_GF40, 0); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4281 | rt2x00_set_field32(®, MM20_PROT_CFG_RTS_TH_EN, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4282 | rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg); |
| 4283 | |
| 4284 | rt2800_register_read(rt2x00dev, MM40_PROT_CFG, ®); |
| 4285 | rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_RATE, 0x4084); |
Helmut Schaa | d13a97f | 2010-10-02 11:29:08 +0200 | [diff] [blame] | 4286 | rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_CTRL, 0); |
Shiang Tu | 6f492b6 | 2011-02-20 13:56:54 +0100 | [diff] [blame] | 4287 | rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_NAV_SHORT, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4288 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 4289 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 4290 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
| 4291 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_MM40, 1); |
| 4292 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
| 4293 | rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_GF40, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4294 | rt2x00_set_field32(®, MM40_PROT_CFG_RTS_TH_EN, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4295 | rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg); |
| 4296 | |
| 4297 | rt2800_register_read(rt2x00dev, GF20_PROT_CFG, ®); |
| 4298 | rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_RATE, 0x4004); |
| 4299 | rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_CTRL, 0); |
Shiang Tu | 6f492b6 | 2011-02-20 13:56:54 +0100 | [diff] [blame] | 4300 | rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_NAV_SHORT, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4301 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 4302 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 4303 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
| 4304 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_MM40, 0); |
| 4305 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
| 4306 | rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_GF40, 0); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4307 | rt2x00_set_field32(®, GF20_PROT_CFG_RTS_TH_EN, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4308 | rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg); |
| 4309 | |
| 4310 | rt2800_register_read(rt2x00dev, GF40_PROT_CFG, ®); |
| 4311 | rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_RATE, 0x4084); |
| 4312 | rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_CTRL, 0); |
Shiang Tu | 6f492b6 | 2011-02-20 13:56:54 +0100 | [diff] [blame] | 4313 | rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_NAV_SHORT, 1); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4314 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_CCK, 1); |
| 4315 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_OFDM, 1); |
| 4316 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_MM20, 1); |
| 4317 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_MM40, 1); |
| 4318 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_GF20, 1); |
| 4319 | rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_GF40, 1); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4320 | rt2x00_set_field32(®, GF40_PROT_CFG_RTS_TH_EN, 0); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4321 | rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg); |
| 4322 | |
Gertjan van Wingerde | cea90e5 | 2010-02-13 20:55:47 +0100 | [diff] [blame] | 4323 | if (rt2x00_is_usb(rt2x00dev)) { |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4324 | rt2800_register_write(rt2x00dev, PBF_CFG, 0xf40006); |
| 4325 | |
| 4326 | rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®); |
| 4327 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0); |
| 4328 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_DMA_BUSY, 0); |
| 4329 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0); |
| 4330 | rt2x00_set_field32(®, WPDMA_GLO_CFG_RX_DMA_BUSY, 0); |
| 4331 | rt2x00_set_field32(®, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 3); |
| 4332 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 0); |
| 4333 | rt2x00_set_field32(®, WPDMA_GLO_CFG_BIG_ENDIAN, 0); |
| 4334 | rt2x00_set_field32(®, WPDMA_GLO_CFG_RX_HDR_SCATTER, 0); |
| 4335 | rt2x00_set_field32(®, WPDMA_GLO_CFG_HDR_SEG_LEN, 0); |
| 4336 | rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg); |
| 4337 | } |
| 4338 | |
Helmut Schaa | 961621a | 2010-11-04 20:36:59 +0100 | [diff] [blame] | 4339 | /* |
| 4340 | * The legacy driver also sets TXOP_CTRL_CFG_RESERVED_TRUN_EN to 1 |
| 4341 | * although it is reserved. |
| 4342 | */ |
| 4343 | rt2800_register_read(rt2x00dev, TXOP_CTRL_CFG, ®); |
| 4344 | rt2x00_set_field32(®, TXOP_CTRL_CFG_TIMEOUT_TRUN_EN, 1); |
| 4345 | rt2x00_set_field32(®, TXOP_CTRL_CFG_AC_TRUN_EN, 1); |
| 4346 | rt2x00_set_field32(®, TXOP_CTRL_CFG_TXRATEGRP_TRUN_EN, 1); |
| 4347 | rt2x00_set_field32(®, TXOP_CTRL_CFG_USER_MODE_TRUN_EN, 1); |
| 4348 | rt2x00_set_field32(®, TXOP_CTRL_CFG_MIMO_PS_TRUN_EN, 1); |
| 4349 | rt2x00_set_field32(®, TXOP_CTRL_CFG_RESERVED_TRUN_EN, 1); |
| 4350 | rt2x00_set_field32(®, TXOP_CTRL_CFG_LSIG_TXOP_EN, 0); |
| 4351 | rt2x00_set_field32(®, TXOP_CTRL_CFG_EXT_CCA_EN, 0); |
| 4352 | rt2x00_set_field32(®, TXOP_CTRL_CFG_EXT_CCA_DLY, 88); |
| 4353 | rt2x00_set_field32(®, TXOP_CTRL_CFG_EXT_CWMIN, 0); |
| 4354 | rt2800_register_write(rt2x00dev, TXOP_CTRL_CFG, reg); |
| 4355 | |
Stanislaw Gruszka | 7641328 | 2013-03-16 19:19:33 +0100 | [diff] [blame] | 4356 | reg = rt2x00_rt(rt2x00dev, RT5592) ? 0x00000082 : 0x00000002; |
| 4357 | rt2800_register_write(rt2x00dev, TXOP_HLDR_ET, reg); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4358 | |
| 4359 | rt2800_register_read(rt2x00dev, TX_RTS_CFG, ®); |
| 4360 | rt2x00_set_field32(®, TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT, 32); |
| 4361 | rt2x00_set_field32(®, TX_RTS_CFG_RTS_THRES, |
| 4362 | IEEE80211_MAX_RTS_THRESHOLD); |
| 4363 | rt2x00_set_field32(®, TX_RTS_CFG_RTS_FBK_EN, 0); |
| 4364 | rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg); |
| 4365 | |
| 4366 | rt2800_register_write(rt2x00dev, EXP_ACK_TIME, 0x002400ca); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4367 | |
Helmut Schaa | a21c2ab | 2010-05-06 12:29:04 +0200 | [diff] [blame] | 4368 | /* |
| 4369 | * Usually the CCK SIFS time should be set to 10 and the OFDM SIFS |
| 4370 | * time should be set to 16. However, the original Ralink driver uses |
| 4371 | * 16 for both and indeed using a value of 10 for CCK SIFS results in |
| 4372 | * connection problems with 11g + CTS protection. Hence, use the same |
| 4373 | * defaults as the Ralink driver: 16 for both, CCK and OFDM SIFS. |
| 4374 | */ |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4375 | rt2800_register_read(rt2x00dev, XIFS_TIME_CFG, ®); |
Helmut Schaa | a21c2ab | 2010-05-06 12:29:04 +0200 | [diff] [blame] | 4376 | rt2x00_set_field32(®, XIFS_TIME_CFG_CCKM_SIFS_TIME, 16); |
| 4377 | rt2x00_set_field32(®, XIFS_TIME_CFG_OFDM_SIFS_TIME, 16); |
Gertjan van Wingerde | a9dce14 | 2010-04-11 14:31:11 +0200 | [diff] [blame] | 4378 | rt2x00_set_field32(®, XIFS_TIME_CFG_OFDM_XIFS_TIME, 4); |
| 4379 | rt2x00_set_field32(®, XIFS_TIME_CFG_EIFS, 314); |
| 4380 | rt2x00_set_field32(®, XIFS_TIME_CFG_BB_RXEND_ENABLE, 1); |
| 4381 | rt2800_register_write(rt2x00dev, XIFS_TIME_CFG, reg); |
| 4382 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4383 | rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003); |
| 4384 | |
| 4385 | /* |
| 4386 | * ASIC will keep garbage value after boot, clear encryption keys. |
| 4387 | */ |
| 4388 | for (i = 0; i < 4; i++) |
| 4389 | rt2800_register_write(rt2x00dev, |
| 4390 | SHARED_KEY_MODE_ENTRY(i), 0); |
| 4391 | |
| 4392 | for (i = 0; i < 256; i++) { |
Helmut Schaa | d7d259d | 2011-09-08 14:39:04 +0200 | [diff] [blame] | 4393 | rt2800_config_wcid(rt2x00dev, NULL, i); |
| 4394 | rt2800_delete_wcid_attr(rt2x00dev, i); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4395 | rt2800_register_write(rt2x00dev, MAC_IVEIV_ENTRY(i), 0); |
| 4396 | } |
| 4397 | |
| 4398 | /* |
| 4399 | * Clear all beacons |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4400 | */ |
Helmut Schaa | 69cf36a | 2011-01-30 13:16:03 +0100 | [diff] [blame] | 4401 | rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE0); |
| 4402 | rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE1); |
| 4403 | rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE2); |
| 4404 | rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE3); |
| 4405 | rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE4); |
| 4406 | rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE5); |
| 4407 | rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE6); |
| 4408 | rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE7); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4409 | |
Gertjan van Wingerde | cea90e5 | 2010-02-13 20:55:47 +0100 | [diff] [blame] | 4410 | if (rt2x00_is_usb(rt2x00dev)) { |
Gertjan van Wingerde | 785c3c0 | 2010-06-03 10:51:59 +0200 | [diff] [blame] | 4411 | rt2800_register_read(rt2x00dev, US_CYC_CNT, ®); |
| 4412 | rt2x00_set_field32(®, US_CYC_CNT_CLOCK_CYCLE, 30); |
| 4413 | rt2800_register_write(rt2x00dev, US_CYC_CNT, reg); |
RA-Jay Hung | c6fcc0e | 2011-01-30 13:21:22 +0100 | [diff] [blame] | 4414 | } else if (rt2x00_is_pcie(rt2x00dev)) { |
| 4415 | rt2800_register_read(rt2x00dev, US_CYC_CNT, ®); |
| 4416 | rt2x00_set_field32(®, US_CYC_CNT_CLOCK_CYCLE, 125); |
| 4417 | rt2800_register_write(rt2x00dev, US_CYC_CNT, reg); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4418 | } |
| 4419 | |
| 4420 | rt2800_register_read(rt2x00dev, HT_FBK_CFG0, ®); |
| 4421 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS0FBK, 0); |
| 4422 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS1FBK, 0); |
| 4423 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS2FBK, 1); |
| 4424 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS3FBK, 2); |
| 4425 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS4FBK, 3); |
| 4426 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS5FBK, 4); |
| 4427 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS6FBK, 5); |
| 4428 | rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS7FBK, 6); |
| 4429 | rt2800_register_write(rt2x00dev, HT_FBK_CFG0, reg); |
| 4430 | |
| 4431 | rt2800_register_read(rt2x00dev, HT_FBK_CFG1, ®); |
| 4432 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS8FBK, 8); |
| 4433 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS9FBK, 8); |
| 4434 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS10FBK, 9); |
| 4435 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS11FBK, 10); |
| 4436 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS12FBK, 11); |
| 4437 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS13FBK, 12); |
| 4438 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS14FBK, 13); |
| 4439 | rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS15FBK, 14); |
| 4440 | rt2800_register_write(rt2x00dev, HT_FBK_CFG1, reg); |
| 4441 | |
| 4442 | rt2800_register_read(rt2x00dev, LG_FBK_CFG0, ®); |
| 4443 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS0FBK, 8); |
| 4444 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS1FBK, 8); |
| 4445 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS2FBK, 9); |
| 4446 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS3FBK, 10); |
| 4447 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS4FBK, 11); |
| 4448 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS5FBK, 12); |
| 4449 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS6FBK, 13); |
| 4450 | rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS7FBK, 14); |
| 4451 | rt2800_register_write(rt2x00dev, LG_FBK_CFG0, reg); |
| 4452 | |
| 4453 | rt2800_register_read(rt2x00dev, LG_FBK_CFG1, ®); |
| 4454 | rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS0FBK, 0); |
| 4455 | rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS1FBK, 0); |
| 4456 | rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS2FBK, 1); |
| 4457 | rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS3FBK, 2); |
| 4458 | rt2800_register_write(rt2x00dev, LG_FBK_CFG1, reg); |
| 4459 | |
| 4460 | /* |
Helmut Schaa | 47ee3eb | 2010-09-08 20:56:04 +0200 | [diff] [blame] | 4461 | * Do not force the BA window size, we use the TXWI to set it |
| 4462 | */ |
| 4463 | rt2800_register_read(rt2x00dev, AMPDU_BA_WINSIZE, ®); |
| 4464 | rt2x00_set_field32(®, AMPDU_BA_WINSIZE_FORCE_WINSIZE_ENABLE, 0); |
| 4465 | rt2x00_set_field32(®, AMPDU_BA_WINSIZE_FORCE_WINSIZE, 0); |
| 4466 | rt2800_register_write(rt2x00dev, AMPDU_BA_WINSIZE, reg); |
| 4467 | |
| 4468 | /* |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4469 | * We must clear the error counters. |
| 4470 | * These registers are cleared on read, |
| 4471 | * so we may pass a useless variable to store the value. |
| 4472 | */ |
| 4473 | rt2800_register_read(rt2x00dev, RX_STA_CNT0, ®); |
| 4474 | rt2800_register_read(rt2x00dev, RX_STA_CNT1, ®); |
| 4475 | rt2800_register_read(rt2x00dev, RX_STA_CNT2, ®); |
| 4476 | rt2800_register_read(rt2x00dev, TX_STA_CNT0, ®); |
| 4477 | rt2800_register_read(rt2x00dev, TX_STA_CNT1, ®); |
| 4478 | rt2800_register_read(rt2x00dev, TX_STA_CNT2, ®); |
| 4479 | |
Helmut Schaa | 9f926fb | 2010-07-11 12:28:23 +0200 | [diff] [blame] | 4480 | /* |
| 4481 | * Setup leadtime for pre tbtt interrupt to 6ms |
| 4482 | */ |
| 4483 | rt2800_register_read(rt2x00dev, INT_TIMER_CFG, ®); |
| 4484 | rt2x00_set_field32(®, INT_TIMER_CFG_PRE_TBTT_TIMER, 6 << 4); |
| 4485 | rt2800_register_write(rt2x00dev, INT_TIMER_CFG, reg); |
| 4486 | |
Helmut Schaa | 977206d | 2010-12-13 12:31:58 +0100 | [diff] [blame] | 4487 | /* |
| 4488 | * Set up channel statistics timer |
| 4489 | */ |
| 4490 | rt2800_register_read(rt2x00dev, CH_TIME_CFG, ®); |
| 4491 | rt2x00_set_field32(®, CH_TIME_CFG_EIFS_BUSY, 1); |
| 4492 | rt2x00_set_field32(®, CH_TIME_CFG_NAV_BUSY, 1); |
| 4493 | rt2x00_set_field32(®, CH_TIME_CFG_RX_BUSY, 1); |
| 4494 | rt2x00_set_field32(®, CH_TIME_CFG_TX_BUSY, 1); |
| 4495 | rt2x00_set_field32(®, CH_TIME_CFG_TMR_EN, 1); |
| 4496 | rt2800_register_write(rt2x00dev, CH_TIME_CFG, reg); |
| 4497 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4498 | return 0; |
| 4499 | } |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4500 | |
| 4501 | static int rt2800_wait_bbp_rf_ready(struct rt2x00_dev *rt2x00dev) |
| 4502 | { |
| 4503 | unsigned int i; |
| 4504 | u32 reg; |
| 4505 | |
| 4506 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
| 4507 | rt2800_register_read(rt2x00dev, MAC_STATUS_CFG, ®); |
| 4508 | if (!rt2x00_get_field32(reg, MAC_STATUS_CFG_BBP_RF_BUSY)) |
| 4509 | return 0; |
| 4510 | |
| 4511 | udelay(REGISTER_BUSY_DELAY); |
| 4512 | } |
| 4513 | |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 4514 | rt2x00_err(rt2x00dev, "BBP/RF register access failed, aborting\n"); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4515 | return -EACCES; |
| 4516 | } |
| 4517 | |
| 4518 | static int rt2800_wait_bbp_ready(struct rt2x00_dev *rt2x00dev) |
| 4519 | { |
| 4520 | unsigned int i; |
| 4521 | u8 value; |
| 4522 | |
| 4523 | /* |
| 4524 | * BBP was enabled after firmware was loaded, |
| 4525 | * but we need to reactivate it now. |
| 4526 | */ |
| 4527 | rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0); |
| 4528 | rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0); |
| 4529 | msleep(1); |
| 4530 | |
| 4531 | for (i = 0; i < REGISTER_BUSY_COUNT; i++) { |
| 4532 | rt2800_bbp_read(rt2x00dev, 0, &value); |
| 4533 | if ((value != 0xff) && (value != 0x00)) |
| 4534 | return 0; |
| 4535 | udelay(REGISTER_BUSY_DELAY); |
| 4536 | } |
| 4537 | |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 4538 | rt2x00_err(rt2x00dev, "BBP register access failed, aborting\n"); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 4539 | return -EACCES; |
| 4540 | } |
| 4541 | |
Stanislaw Gruszka | a7bbbe5 | 2013-03-16 19:19:34 +0100 | [diff] [blame] | 4542 | static void rt2800_bbp4_mac_if_ctrl(struct rt2x00_dev *rt2x00dev) |
| 4543 | { |
| 4544 | u8 value; |
| 4545 | |
| 4546 | rt2800_bbp_read(rt2x00dev, 4, &value); |
| 4547 | rt2x00_set_field8(&value, BBP4_MAC_IF_CTRL, 1); |
| 4548 | rt2800_bbp_write(rt2x00dev, 4, value); |
| 4549 | } |
| 4550 | |
Stanislaw Gruszka | c267548 | 2013-03-16 19:19:41 +0100 | [diff] [blame] | 4551 | static void rt2800_init_freq_calibration(struct rt2x00_dev *rt2x00dev) |
| 4552 | { |
| 4553 | rt2800_bbp_write(rt2x00dev, 142, 1); |
| 4554 | rt2800_bbp_write(rt2x00dev, 143, 57); |
| 4555 | } |
| 4556 | |
Stanislaw Gruszka | a7bbbe5 | 2013-03-16 19:19:34 +0100 | [diff] [blame] | 4557 | static void rt2800_init_bbp_5592_glrt(struct rt2x00_dev *rt2x00dev) |
| 4558 | { |
| 4559 | const u8 glrt_table[] = { |
| 4560 | 0xE0, 0x1F, 0X38, 0x32, 0x08, 0x28, 0x19, 0x0A, 0xFF, 0x00, /* 128 ~ 137 */ |
| 4561 | 0x16, 0x10, 0x10, 0x0B, 0x36, 0x2C, 0x26, 0x24, 0x42, 0x36, /* 138 ~ 147 */ |
| 4562 | 0x30, 0x2D, 0x4C, 0x46, 0x3D, 0x40, 0x3E, 0x42, 0x3D, 0x40, /* 148 ~ 157 */ |
| 4563 | 0X3C, 0x34, 0x2C, 0x2F, 0x3C, 0x35, 0x2E, 0x2A, 0x49, 0x41, /* 158 ~ 167 */ |
| 4564 | 0x36, 0x31, 0x30, 0x30, 0x0E, 0x0D, 0x28, 0x21, 0x1C, 0x16, /* 168 ~ 177 */ |
| 4565 | 0x50, 0x4A, 0x43, 0x40, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, /* 178 ~ 187 */ |
| 4566 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 188 ~ 197 */ |
| 4567 | 0x00, 0x00, 0x7D, 0x14, 0x32, 0x2C, 0x36, 0x4C, 0x43, 0x2C, /* 198 ~ 207 */ |
| 4568 | 0x2E, 0x36, 0x30, 0x6E, /* 208 ~ 211 */ |
| 4569 | }; |
| 4570 | int i; |
| 4571 | |
| 4572 | for (i = 0; i < ARRAY_SIZE(glrt_table); i++) { |
| 4573 | rt2800_bbp_write(rt2x00dev, 195, 128 + i); |
| 4574 | rt2800_bbp_write(rt2x00dev, 196, glrt_table[i]); |
| 4575 | } |
| 4576 | }; |
| 4577 | |
Gabor Juhos | 624708b | 2013-04-19 10:13:52 +0200 | [diff] [blame] | 4578 | static void rt2800_init_bbp_early(struct rt2x00_dev *rt2x00dev) |
Stanislaw Gruszka | a4969d0 | 2013-03-16 19:19:35 +0100 | [diff] [blame] | 4579 | { |
| 4580 | rt2800_bbp_write(rt2x00dev, 65, 0x2C); |
| 4581 | rt2800_bbp_write(rt2x00dev, 66, 0x38); |
| 4582 | rt2800_bbp_write(rt2x00dev, 68, 0x0B); |
| 4583 | rt2800_bbp_write(rt2x00dev, 69, 0x12); |
| 4584 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
| 4585 | rt2800_bbp_write(rt2x00dev, 73, 0x10); |
| 4586 | rt2800_bbp_write(rt2x00dev, 81, 0x37); |
| 4587 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
| 4588 | rt2800_bbp_write(rt2x00dev, 83, 0x6A); |
| 4589 | rt2800_bbp_write(rt2x00dev, 84, 0x99); |
| 4590 | rt2800_bbp_write(rt2x00dev, 86, 0x00); |
| 4591 | rt2800_bbp_write(rt2x00dev, 91, 0x04); |
| 4592 | rt2800_bbp_write(rt2x00dev, 92, 0x00); |
| 4593 | rt2800_bbp_write(rt2x00dev, 103, 0x00); |
| 4594 | rt2800_bbp_write(rt2x00dev, 105, 0x05); |
| 4595 | rt2800_bbp_write(rt2x00dev, 106, 0x35); |
| 4596 | } |
| 4597 | |
Stanislaw Gruszka | 5df1ff3 | 2013-05-18 14:03:52 +0200 | [diff] [blame] | 4598 | static void rt2800_disable_unused_dac_adc(struct rt2x00_dev *rt2x00dev) |
| 4599 | { |
| 4600 | u16 eeprom; |
| 4601 | u8 value; |
| 4602 | |
| 4603 | rt2800_bbp_read(rt2x00dev, 138, &value); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 4604 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom); |
Stanislaw Gruszka | 5df1ff3 | 2013-05-18 14:03:52 +0200 | [diff] [blame] | 4605 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) == 1) |
| 4606 | value |= 0x20; |
| 4607 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) == 1) |
| 4608 | value &= ~0x02; |
| 4609 | rt2800_bbp_write(rt2x00dev, 138, value); |
| 4610 | } |
| 4611 | |
Stanislaw Gruszka | dae6295 | 2013-05-18 14:03:26 +0200 | [diff] [blame] | 4612 | static void rt2800_init_bbp_305x_soc(struct rt2x00_dev *rt2x00dev) |
| 4613 | { |
Stanislaw Gruszka | b2f8e0b | 2013-05-18 14:03:29 +0200 | [diff] [blame] | 4614 | rt2800_bbp_write(rt2x00dev, 31, 0x08); |
Stanislaw Gruszka | e379de1 | 2013-05-18 14:03:31 +0200 | [diff] [blame] | 4615 | |
| 4616 | rt2800_bbp_write(rt2x00dev, 65, 0x2c); |
| 4617 | rt2800_bbp_write(rt2x00dev, 66, 0x38); |
Stanislaw Gruszka | 72ffe14 | 2013-05-18 14:03:33 +0200 | [diff] [blame] | 4618 | |
| 4619 | rt2800_bbp_write(rt2x00dev, 69, 0x12); |
| 4620 | rt2800_bbp_write(rt2x00dev, 73, 0x10); |
Stanislaw Gruszka | 8d97be3 | 2013-05-18 14:03:34 +0200 | [diff] [blame] | 4621 | |
| 4622 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
Stanislaw Gruszka | 43f535e | 2013-05-18 14:03:35 +0200 | [diff] [blame] | 4623 | |
| 4624 | rt2800_bbp_write(rt2x00dev, 78, 0x0e); |
| 4625 | rt2800_bbp_write(rt2x00dev, 80, 0x08); |
Stanislaw Gruszka | fa1e342 | 2013-05-18 14:03:36 +0200 | [diff] [blame] | 4626 | |
| 4627 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
Stanislaw Gruszka | 885f241 | 2013-05-18 14:03:37 +0200 | [diff] [blame] | 4628 | |
| 4629 | rt2800_bbp_write(rt2x00dev, 83, 0x6a); |
Stanislaw Gruszka | 3c20a12 | 2013-05-18 14:03:38 +0200 | [diff] [blame] | 4630 | |
| 4631 | rt2800_bbp_write(rt2x00dev, 84, 0x99); |
Stanislaw Gruszka | aef9f38 | 2013-05-18 14:03:39 +0200 | [diff] [blame] | 4632 | |
| 4633 | rt2800_bbp_write(rt2x00dev, 86, 0x00); |
Stanislaw Gruszka | 7af9874 | 2013-05-18 14:03:41 +0200 | [diff] [blame] | 4634 | |
| 4635 | rt2800_bbp_write(rt2x00dev, 91, 0x04); |
Stanislaw Gruszka | b4e121d | 2013-05-18 14:03:42 +0200 | [diff] [blame] | 4636 | |
| 4637 | rt2800_bbp_write(rt2x00dev, 92, 0x00); |
Stanislaw Gruszka | 672d118 | 2013-05-18 14:03:44 +0200 | [diff] [blame] | 4638 | |
| 4639 | rt2800_bbp_write(rt2x00dev, 103, 0xc0); |
Stanislaw Gruszka | 49d6111 | 2013-05-18 14:03:46 +0200 | [diff] [blame] | 4640 | |
| 4641 | rt2800_bbp_write(rt2x00dev, 105, 0x01); |
Stanislaw Gruszka | f867085 | 2013-05-18 14:03:47 +0200 | [diff] [blame] | 4642 | |
| 4643 | rt2800_bbp_write(rt2x00dev, 106, 0x35); |
Stanislaw Gruszka | dae6295 | 2013-05-18 14:03:26 +0200 | [diff] [blame] | 4644 | } |
| 4645 | |
Stanislaw Gruszka | 39ab3e8 | 2013-05-18 14:03:25 +0200 | [diff] [blame] | 4646 | static void rt2800_init_bbp_28xx(struct rt2x00_dev *rt2x00dev) |
| 4647 | { |
Stanislaw Gruszka | e379de1 | 2013-05-18 14:03:31 +0200 | [diff] [blame] | 4648 | rt2800_bbp_write(rt2x00dev, 65, 0x2c); |
| 4649 | rt2800_bbp_write(rt2x00dev, 66, 0x38); |
Stanislaw Gruszka | 72ffe14 | 2013-05-18 14:03:33 +0200 | [diff] [blame] | 4650 | |
| 4651 | if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) { |
| 4652 | rt2800_bbp_write(rt2x00dev, 69, 0x16); |
| 4653 | rt2800_bbp_write(rt2x00dev, 73, 0x12); |
| 4654 | } else { |
| 4655 | rt2800_bbp_write(rt2x00dev, 69, 0x12); |
| 4656 | rt2800_bbp_write(rt2x00dev, 73, 0x10); |
| 4657 | } |
Stanislaw Gruszka | 8d97be3 | 2013-05-18 14:03:34 +0200 | [diff] [blame] | 4658 | |
| 4659 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
Stanislaw Gruszka | 43f535e | 2013-05-18 14:03:35 +0200 | [diff] [blame] | 4660 | |
| 4661 | rt2800_bbp_write(rt2x00dev, 81, 0x37); |
Stanislaw Gruszka | fa1e342 | 2013-05-18 14:03:36 +0200 | [diff] [blame] | 4662 | |
| 4663 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
Stanislaw Gruszka | 885f241 | 2013-05-18 14:03:37 +0200 | [diff] [blame] | 4664 | |
| 4665 | rt2800_bbp_write(rt2x00dev, 83, 0x6a); |
Stanislaw Gruszka | 3c20a12 | 2013-05-18 14:03:38 +0200 | [diff] [blame] | 4666 | |
| 4667 | if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860D)) |
| 4668 | rt2800_bbp_write(rt2x00dev, 84, 0x19); |
| 4669 | else |
| 4670 | rt2800_bbp_write(rt2x00dev, 84, 0x99); |
Stanislaw Gruszka | aef9f38 | 2013-05-18 14:03:39 +0200 | [diff] [blame] | 4671 | |
| 4672 | rt2800_bbp_write(rt2x00dev, 86, 0x00); |
Stanislaw Gruszka | 7af9874 | 2013-05-18 14:03:41 +0200 | [diff] [blame] | 4673 | |
| 4674 | rt2800_bbp_write(rt2x00dev, 91, 0x04); |
Stanislaw Gruszka | b4e121d | 2013-05-18 14:03:42 +0200 | [diff] [blame] | 4675 | |
| 4676 | rt2800_bbp_write(rt2x00dev, 92, 0x00); |
Stanislaw Gruszka | 672d118 | 2013-05-18 14:03:44 +0200 | [diff] [blame] | 4677 | |
| 4678 | rt2800_bbp_write(rt2x00dev, 103, 0x00); |
Stanislaw Gruszka | 49d6111 | 2013-05-18 14:03:46 +0200 | [diff] [blame] | 4679 | |
| 4680 | rt2800_bbp_write(rt2x00dev, 105, 0x05); |
Stanislaw Gruszka | f867085 | 2013-05-18 14:03:47 +0200 | [diff] [blame] | 4681 | |
| 4682 | rt2800_bbp_write(rt2x00dev, 106, 0x35); |
Stanislaw Gruszka | 39ab3e8 | 2013-05-18 14:03:25 +0200 | [diff] [blame] | 4683 | } |
| 4684 | |
| 4685 | static void rt2800_init_bbp_30xx(struct rt2x00_dev *rt2x00dev) |
| 4686 | { |
Stanislaw Gruszka | e379de1 | 2013-05-18 14:03:31 +0200 | [diff] [blame] | 4687 | rt2800_bbp_write(rt2x00dev, 65, 0x2c); |
| 4688 | rt2800_bbp_write(rt2x00dev, 66, 0x38); |
Stanislaw Gruszka | 72ffe14 | 2013-05-18 14:03:33 +0200 | [diff] [blame] | 4689 | |
| 4690 | rt2800_bbp_write(rt2x00dev, 69, 0x12); |
| 4691 | rt2800_bbp_write(rt2x00dev, 73, 0x10); |
Stanislaw Gruszka | 8d97be3 | 2013-05-18 14:03:34 +0200 | [diff] [blame] | 4692 | |
| 4693 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
Stanislaw Gruszka | 43f535e | 2013-05-18 14:03:35 +0200 | [diff] [blame] | 4694 | |
| 4695 | rt2800_bbp_write(rt2x00dev, 79, 0x13); |
| 4696 | rt2800_bbp_write(rt2x00dev, 80, 0x05); |
| 4697 | rt2800_bbp_write(rt2x00dev, 81, 0x33); |
Stanislaw Gruszka | fa1e342 | 2013-05-18 14:03:36 +0200 | [diff] [blame] | 4698 | |
| 4699 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
Stanislaw Gruszka | 885f241 | 2013-05-18 14:03:37 +0200 | [diff] [blame] | 4700 | |
| 4701 | rt2800_bbp_write(rt2x00dev, 83, 0x6a); |
Stanislaw Gruszka | 3c20a12 | 2013-05-18 14:03:38 +0200 | [diff] [blame] | 4702 | |
| 4703 | rt2800_bbp_write(rt2x00dev, 84, 0x99); |
Stanislaw Gruszka | aef9f38 | 2013-05-18 14:03:39 +0200 | [diff] [blame] | 4704 | |
| 4705 | rt2800_bbp_write(rt2x00dev, 86, 0x00); |
Stanislaw Gruszka | 7af9874 | 2013-05-18 14:03:41 +0200 | [diff] [blame] | 4706 | |
| 4707 | rt2800_bbp_write(rt2x00dev, 91, 0x04); |
Stanislaw Gruszka | b4e121d | 2013-05-18 14:03:42 +0200 | [diff] [blame] | 4708 | |
| 4709 | rt2800_bbp_write(rt2x00dev, 92, 0x00); |
Stanislaw Gruszka | 672d118 | 2013-05-18 14:03:44 +0200 | [diff] [blame] | 4710 | |
| 4711 | if (rt2x00_rt_rev_gte(rt2x00dev, RT3070, REV_RT3070F) || |
| 4712 | rt2x00_rt_rev_gte(rt2x00dev, RT3071, REV_RT3071E) || |
| 4713 | rt2x00_rt_rev_gte(rt2x00dev, RT3090, REV_RT3090E)) |
| 4714 | rt2800_bbp_write(rt2x00dev, 103, 0xc0); |
| 4715 | else |
| 4716 | rt2800_bbp_write(rt2x00dev, 103, 0x00); |
Stanislaw Gruszka | 49d6111 | 2013-05-18 14:03:46 +0200 | [diff] [blame] | 4717 | |
| 4718 | rt2800_bbp_write(rt2x00dev, 105, 0x05); |
Stanislaw Gruszka | f867085 | 2013-05-18 14:03:47 +0200 | [diff] [blame] | 4719 | |
| 4720 | rt2800_bbp_write(rt2x00dev, 106, 0x35); |
Stanislaw Gruszka | 5df1ff3 | 2013-05-18 14:03:52 +0200 | [diff] [blame] | 4721 | |
| 4722 | if (rt2x00_rt(rt2x00dev, RT3071) || |
| 4723 | rt2x00_rt(rt2x00dev, RT3090)) |
| 4724 | rt2800_disable_unused_dac_adc(rt2x00dev); |
Stanislaw Gruszka | 39ab3e8 | 2013-05-18 14:03:25 +0200 | [diff] [blame] | 4725 | } |
| 4726 | |
| 4727 | static void rt2800_init_bbp_3290(struct rt2x00_dev *rt2x00dev) |
| 4728 | { |
Stanislaw Gruszka | 6addb24 | 2013-05-18 14:03:54 +0200 | [diff] [blame] | 4729 | u8 value; |
| 4730 | |
Stanislaw Gruszka | c322357 | 2013-05-18 14:03:28 +0200 | [diff] [blame] | 4731 | rt2800_bbp4_mac_if_ctrl(rt2x00dev); |
Stanislaw Gruszka | b2f8e0b | 2013-05-18 14:03:29 +0200 | [diff] [blame] | 4732 | |
| 4733 | rt2800_bbp_write(rt2x00dev, 31, 0x08); |
Stanislaw Gruszka | e379de1 | 2013-05-18 14:03:31 +0200 | [diff] [blame] | 4734 | |
| 4735 | rt2800_bbp_write(rt2x00dev, 65, 0x2c); |
| 4736 | rt2800_bbp_write(rt2x00dev, 66, 0x38); |
Stanislaw Gruszka | 59dcabb | 2013-05-18 14:03:32 +0200 | [diff] [blame] | 4737 | |
| 4738 | rt2800_bbp_write(rt2x00dev, 68, 0x0b); |
Stanislaw Gruszka | 72ffe14 | 2013-05-18 14:03:33 +0200 | [diff] [blame] | 4739 | |
| 4740 | rt2800_bbp_write(rt2x00dev, 69, 0x12); |
| 4741 | rt2800_bbp_write(rt2x00dev, 73, 0x13); |
| 4742 | rt2800_bbp_write(rt2x00dev, 75, 0x46); |
| 4743 | rt2800_bbp_write(rt2x00dev, 76, 0x28); |
| 4744 | |
| 4745 | rt2800_bbp_write(rt2x00dev, 77, 0x58); |
Stanislaw Gruszka | 8d97be3 | 2013-05-18 14:03:34 +0200 | [diff] [blame] | 4746 | |
| 4747 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
Stanislaw Gruszka | 43f535e | 2013-05-18 14:03:35 +0200 | [diff] [blame] | 4748 | |
| 4749 | rt2800_bbp_write(rt2x00dev, 74, 0x0b); |
| 4750 | rt2800_bbp_write(rt2x00dev, 79, 0x18); |
| 4751 | rt2800_bbp_write(rt2x00dev, 80, 0x09); |
| 4752 | rt2800_bbp_write(rt2x00dev, 81, 0x33); |
Stanislaw Gruszka | fa1e342 | 2013-05-18 14:03:36 +0200 | [diff] [blame] | 4753 | |
| 4754 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
Stanislaw Gruszka | 885f241 | 2013-05-18 14:03:37 +0200 | [diff] [blame] | 4755 | |
| 4756 | rt2800_bbp_write(rt2x00dev, 83, 0x7a); |
Stanislaw Gruszka | 3c20a12 | 2013-05-18 14:03:38 +0200 | [diff] [blame] | 4757 | |
| 4758 | rt2800_bbp_write(rt2x00dev, 84, 0x9a); |
Stanislaw Gruszka | aef9f38 | 2013-05-18 14:03:39 +0200 | [diff] [blame] | 4759 | |
| 4760 | rt2800_bbp_write(rt2x00dev, 86, 0x38); |
Stanislaw Gruszka | 7af9874 | 2013-05-18 14:03:41 +0200 | [diff] [blame] | 4761 | |
| 4762 | rt2800_bbp_write(rt2x00dev, 91, 0x04); |
Stanislaw Gruszka | b4e121d | 2013-05-18 14:03:42 +0200 | [diff] [blame] | 4763 | |
| 4764 | rt2800_bbp_write(rt2x00dev, 92, 0x02); |
Stanislaw Gruszka | 672d118 | 2013-05-18 14:03:44 +0200 | [diff] [blame] | 4765 | |
| 4766 | rt2800_bbp_write(rt2x00dev, 103, 0xc0); |
Stanislaw Gruszka | 1ad4408 | 2013-05-18 14:03:45 +0200 | [diff] [blame] | 4767 | |
| 4768 | rt2800_bbp_write(rt2x00dev, 104, 0x92); |
Stanislaw Gruszka | 49d6111 | 2013-05-18 14:03:46 +0200 | [diff] [blame] | 4769 | |
| 4770 | rt2800_bbp_write(rt2x00dev, 105, 0x1c); |
Stanislaw Gruszka | f867085 | 2013-05-18 14:03:47 +0200 | [diff] [blame] | 4771 | |
| 4772 | rt2800_bbp_write(rt2x00dev, 106, 0x03); |
Stanislaw Gruszka | f2b6777 | 2013-05-18 14:03:49 +0200 | [diff] [blame] | 4773 | |
| 4774 | rt2800_bbp_write(rt2x00dev, 128, 0x12); |
Stanislaw Gruszka | 6addb24 | 2013-05-18 14:03:54 +0200 | [diff] [blame] | 4775 | |
| 4776 | rt2800_bbp_write(rt2x00dev, 67, 0x24); |
| 4777 | rt2800_bbp_write(rt2x00dev, 143, 0x04); |
| 4778 | rt2800_bbp_write(rt2x00dev, 142, 0x99); |
| 4779 | rt2800_bbp_write(rt2x00dev, 150, 0x30); |
| 4780 | rt2800_bbp_write(rt2x00dev, 151, 0x2e); |
| 4781 | rt2800_bbp_write(rt2x00dev, 152, 0x20); |
| 4782 | rt2800_bbp_write(rt2x00dev, 153, 0x34); |
| 4783 | rt2800_bbp_write(rt2x00dev, 154, 0x40); |
| 4784 | rt2800_bbp_write(rt2x00dev, 155, 0x3b); |
| 4785 | rt2800_bbp_write(rt2x00dev, 253, 0x04); |
| 4786 | |
| 4787 | rt2800_bbp_read(rt2x00dev, 47, &value); |
| 4788 | rt2x00_set_field8(&value, BBP47_TSSI_ADC6, 1); |
| 4789 | rt2800_bbp_write(rt2x00dev, 47, value); |
| 4790 | |
| 4791 | /* Use 5-bit ADC for Acquisition and 8-bit ADC for data */ |
| 4792 | rt2800_bbp_read(rt2x00dev, 3, &value); |
| 4793 | rt2x00_set_field8(&value, BBP3_ADC_MODE_SWITCH, 1); |
| 4794 | rt2x00_set_field8(&value, BBP3_ADC_INIT_MODE, 1); |
| 4795 | rt2800_bbp_write(rt2x00dev, 3, value); |
Stanislaw Gruszka | 39ab3e8 | 2013-05-18 14:03:25 +0200 | [diff] [blame] | 4796 | } |
| 4797 | |
| 4798 | static void rt2800_init_bbp_3352(struct rt2x00_dev *rt2x00dev) |
| 4799 | { |
Stanislaw Gruszka | 29f3a58 | 2013-05-18 14:03:27 +0200 | [diff] [blame] | 4800 | rt2800_bbp_write(rt2x00dev, 3, 0x00); |
| 4801 | rt2800_bbp_write(rt2x00dev, 4, 0x50); |
Stanislaw Gruszka | b2f8e0b | 2013-05-18 14:03:29 +0200 | [diff] [blame] | 4802 | |
| 4803 | rt2800_bbp_write(rt2x00dev, 31, 0x08); |
Stanislaw Gruszka | 3420f79 | 2013-05-18 14:03:30 +0200 | [diff] [blame] | 4804 | |
| 4805 | rt2800_bbp_write(rt2x00dev, 47, 0x48); |
Stanislaw Gruszka | e379de1 | 2013-05-18 14:03:31 +0200 | [diff] [blame] | 4806 | |
| 4807 | rt2800_bbp_write(rt2x00dev, 65, 0x2c); |
| 4808 | rt2800_bbp_write(rt2x00dev, 66, 0x38); |
Stanislaw Gruszka | 59dcabb | 2013-05-18 14:03:32 +0200 | [diff] [blame] | 4809 | |
| 4810 | rt2800_bbp_write(rt2x00dev, 68, 0x0b); |
Stanislaw Gruszka | 72ffe14 | 2013-05-18 14:03:33 +0200 | [diff] [blame] | 4811 | |
| 4812 | rt2800_bbp_write(rt2x00dev, 69, 0x12); |
| 4813 | rt2800_bbp_write(rt2x00dev, 73, 0x13); |
| 4814 | rt2800_bbp_write(rt2x00dev, 75, 0x46); |
| 4815 | rt2800_bbp_write(rt2x00dev, 76, 0x28); |
| 4816 | |
| 4817 | rt2800_bbp_write(rt2x00dev, 77, 0x59); |
Stanislaw Gruszka | 8d97be3 | 2013-05-18 14:03:34 +0200 | [diff] [blame] | 4818 | |
| 4819 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
Stanislaw Gruszka | 43f535e | 2013-05-18 14:03:35 +0200 | [diff] [blame] | 4820 | |
| 4821 | rt2800_bbp_write(rt2x00dev, 78, 0x0e); |
| 4822 | rt2800_bbp_write(rt2x00dev, 80, 0x08); |
| 4823 | rt2800_bbp_write(rt2x00dev, 81, 0x37); |
Stanislaw Gruszka | fa1e342 | 2013-05-18 14:03:36 +0200 | [diff] [blame] | 4824 | |
| 4825 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
Stanislaw Gruszka | 885f241 | 2013-05-18 14:03:37 +0200 | [diff] [blame] | 4826 | |
| 4827 | rt2800_bbp_write(rt2x00dev, 83, 0x6a); |
Stanislaw Gruszka | 3c20a12 | 2013-05-18 14:03:38 +0200 | [diff] [blame] | 4828 | |
| 4829 | rt2800_bbp_write(rt2x00dev, 84, 0x99); |
Stanislaw Gruszka | aef9f38 | 2013-05-18 14:03:39 +0200 | [diff] [blame] | 4830 | |
| 4831 | rt2800_bbp_write(rt2x00dev, 86, 0x38); |
Stanislaw Gruszka | 9400fa8 | 2013-05-18 14:03:40 +0200 | [diff] [blame] | 4832 | |
| 4833 | rt2800_bbp_write(rt2x00dev, 88, 0x90); |
Stanislaw Gruszka | 7af9874 | 2013-05-18 14:03:41 +0200 | [diff] [blame] | 4834 | |
| 4835 | rt2800_bbp_write(rt2x00dev, 91, 0x04); |
Stanislaw Gruszka | b4e121d | 2013-05-18 14:03:42 +0200 | [diff] [blame] | 4836 | |
| 4837 | rt2800_bbp_write(rt2x00dev, 92, 0x02); |
Stanislaw Gruszka | 672d118 | 2013-05-18 14:03:44 +0200 | [diff] [blame] | 4838 | |
| 4839 | rt2800_bbp_write(rt2x00dev, 103, 0xc0); |
Stanislaw Gruszka | 1ad4408 | 2013-05-18 14:03:45 +0200 | [diff] [blame] | 4840 | |
| 4841 | rt2800_bbp_write(rt2x00dev, 104, 0x92); |
Stanislaw Gruszka | 49d6111 | 2013-05-18 14:03:46 +0200 | [diff] [blame] | 4842 | |
| 4843 | rt2800_bbp_write(rt2x00dev, 105, 0x34); |
Stanislaw Gruszka | f867085 | 2013-05-18 14:03:47 +0200 | [diff] [blame] | 4844 | |
| 4845 | rt2800_bbp_write(rt2x00dev, 106, 0x05); |
Stanislaw Gruszka | 46b90d3 | 2013-05-18 14:03:48 +0200 | [diff] [blame] | 4846 | |
| 4847 | rt2800_bbp_write(rt2x00dev, 120, 0x50); |
Stanislaw Gruszka | b7feb9b | 2013-05-18 14:03:51 +0200 | [diff] [blame] | 4848 | |
| 4849 | rt2800_bbp_write(rt2x00dev, 137, 0x0f); |
Stanislaw Gruszka | c2da527 | 2013-05-18 14:03:53 +0200 | [diff] [blame] | 4850 | |
| 4851 | rt2800_bbp_write(rt2x00dev, 163, 0xbd); |
| 4852 | /* Set ITxBF timeout to 0x9c40=1000msec */ |
| 4853 | rt2800_bbp_write(rt2x00dev, 179, 0x02); |
| 4854 | rt2800_bbp_write(rt2x00dev, 180, 0x00); |
| 4855 | rt2800_bbp_write(rt2x00dev, 182, 0x40); |
| 4856 | rt2800_bbp_write(rt2x00dev, 180, 0x01); |
| 4857 | rt2800_bbp_write(rt2x00dev, 182, 0x9c); |
| 4858 | rt2800_bbp_write(rt2x00dev, 179, 0x00); |
| 4859 | /* Reprogram the inband interface to put right values in RXWI */ |
| 4860 | rt2800_bbp_write(rt2x00dev, 142, 0x04); |
| 4861 | rt2800_bbp_write(rt2x00dev, 143, 0x3b); |
| 4862 | rt2800_bbp_write(rt2x00dev, 142, 0x06); |
| 4863 | rt2800_bbp_write(rt2x00dev, 143, 0xa0); |
| 4864 | rt2800_bbp_write(rt2x00dev, 142, 0x07); |
| 4865 | rt2800_bbp_write(rt2x00dev, 143, 0xa1); |
| 4866 | rt2800_bbp_write(rt2x00dev, 142, 0x08); |
| 4867 | rt2800_bbp_write(rt2x00dev, 143, 0xa2); |
| 4868 | |
| 4869 | rt2800_bbp_write(rt2x00dev, 148, 0xc8); |
Stanislaw Gruszka | 39ab3e8 | 2013-05-18 14:03:25 +0200 | [diff] [blame] | 4870 | } |
| 4871 | |
| 4872 | static void rt2800_init_bbp_3390(struct rt2x00_dev *rt2x00dev) |
| 4873 | { |
Stanislaw Gruszka | e379de1 | 2013-05-18 14:03:31 +0200 | [diff] [blame] | 4874 | rt2800_bbp_write(rt2x00dev, 65, 0x2c); |
| 4875 | rt2800_bbp_write(rt2x00dev, 66, 0x38); |
Stanislaw Gruszka | 72ffe14 | 2013-05-18 14:03:33 +0200 | [diff] [blame] | 4876 | |
| 4877 | rt2800_bbp_write(rt2x00dev, 69, 0x12); |
| 4878 | rt2800_bbp_write(rt2x00dev, 73, 0x10); |
Stanislaw Gruszka | 8d97be3 | 2013-05-18 14:03:34 +0200 | [diff] [blame] | 4879 | |
| 4880 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
Stanislaw Gruszka | 43f535e | 2013-05-18 14:03:35 +0200 | [diff] [blame] | 4881 | |
| 4882 | rt2800_bbp_write(rt2x00dev, 79, 0x13); |
| 4883 | rt2800_bbp_write(rt2x00dev, 80, 0x05); |
| 4884 | rt2800_bbp_write(rt2x00dev, 81, 0x33); |
Stanislaw Gruszka | fa1e342 | 2013-05-18 14:03:36 +0200 | [diff] [blame] | 4885 | |
| 4886 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
Stanislaw Gruszka | 885f241 | 2013-05-18 14:03:37 +0200 | [diff] [blame] | 4887 | |
| 4888 | rt2800_bbp_write(rt2x00dev, 83, 0x6a); |
Stanislaw Gruszka | 3c20a12 | 2013-05-18 14:03:38 +0200 | [diff] [blame] | 4889 | |
| 4890 | rt2800_bbp_write(rt2x00dev, 84, 0x99); |
Stanislaw Gruszka | aef9f38 | 2013-05-18 14:03:39 +0200 | [diff] [blame] | 4891 | |
| 4892 | rt2800_bbp_write(rt2x00dev, 86, 0x00); |
Stanislaw Gruszka | 7af9874 | 2013-05-18 14:03:41 +0200 | [diff] [blame] | 4893 | |
| 4894 | rt2800_bbp_write(rt2x00dev, 91, 0x04); |
Stanislaw Gruszka | b4e121d | 2013-05-18 14:03:42 +0200 | [diff] [blame] | 4895 | |
| 4896 | rt2800_bbp_write(rt2x00dev, 92, 0x00); |
Stanislaw Gruszka | 672d118 | 2013-05-18 14:03:44 +0200 | [diff] [blame] | 4897 | |
| 4898 | if (rt2x00_rt_rev_gte(rt2x00dev, RT3390, REV_RT3390E)) |
| 4899 | rt2800_bbp_write(rt2x00dev, 103, 0xc0); |
| 4900 | else |
| 4901 | rt2800_bbp_write(rt2x00dev, 103, 0x00); |
Stanislaw Gruszka | 49d6111 | 2013-05-18 14:03:46 +0200 | [diff] [blame] | 4902 | |
| 4903 | rt2800_bbp_write(rt2x00dev, 105, 0x05); |
Stanislaw Gruszka | f867085 | 2013-05-18 14:03:47 +0200 | [diff] [blame] | 4904 | |
| 4905 | rt2800_bbp_write(rt2x00dev, 106, 0x35); |
Stanislaw Gruszka | 5df1ff3 | 2013-05-18 14:03:52 +0200 | [diff] [blame] | 4906 | |
| 4907 | rt2800_disable_unused_dac_adc(rt2x00dev); |
Stanislaw Gruszka | 39ab3e8 | 2013-05-18 14:03:25 +0200 | [diff] [blame] | 4908 | } |
| 4909 | |
| 4910 | static void rt2800_init_bbp_3572(struct rt2x00_dev *rt2x00dev) |
| 4911 | { |
Stanislaw Gruszka | b2f8e0b | 2013-05-18 14:03:29 +0200 | [diff] [blame] | 4912 | rt2800_bbp_write(rt2x00dev, 31, 0x08); |
Stanislaw Gruszka | e379de1 | 2013-05-18 14:03:31 +0200 | [diff] [blame] | 4913 | |
| 4914 | rt2800_bbp_write(rt2x00dev, 65, 0x2c); |
| 4915 | rt2800_bbp_write(rt2x00dev, 66, 0x38); |
Stanislaw Gruszka | 72ffe14 | 2013-05-18 14:03:33 +0200 | [diff] [blame] | 4916 | |
| 4917 | rt2800_bbp_write(rt2x00dev, 69, 0x12); |
| 4918 | rt2800_bbp_write(rt2x00dev, 73, 0x10); |
Stanislaw Gruszka | 8d97be3 | 2013-05-18 14:03:34 +0200 | [diff] [blame] | 4919 | |
| 4920 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
Stanislaw Gruszka | 43f535e | 2013-05-18 14:03:35 +0200 | [diff] [blame] | 4921 | |
| 4922 | rt2800_bbp_write(rt2x00dev, 79, 0x13); |
| 4923 | rt2800_bbp_write(rt2x00dev, 80, 0x05); |
| 4924 | rt2800_bbp_write(rt2x00dev, 81, 0x33); |
Stanislaw Gruszka | fa1e342 | 2013-05-18 14:03:36 +0200 | [diff] [blame] | 4925 | |
| 4926 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
Stanislaw Gruszka | 885f241 | 2013-05-18 14:03:37 +0200 | [diff] [blame] | 4927 | |
| 4928 | rt2800_bbp_write(rt2x00dev, 83, 0x6a); |
Stanislaw Gruszka | 3c20a12 | 2013-05-18 14:03:38 +0200 | [diff] [blame] | 4929 | |
| 4930 | rt2800_bbp_write(rt2x00dev, 84, 0x99); |
Stanislaw Gruszka | aef9f38 | 2013-05-18 14:03:39 +0200 | [diff] [blame] | 4931 | |
| 4932 | rt2800_bbp_write(rt2x00dev, 86, 0x00); |
Stanislaw Gruszka | 7af9874 | 2013-05-18 14:03:41 +0200 | [diff] [blame] | 4933 | |
| 4934 | rt2800_bbp_write(rt2x00dev, 91, 0x04); |
Stanislaw Gruszka | b4e121d | 2013-05-18 14:03:42 +0200 | [diff] [blame] | 4935 | |
| 4936 | rt2800_bbp_write(rt2x00dev, 92, 0x00); |
Stanislaw Gruszka | 672d118 | 2013-05-18 14:03:44 +0200 | [diff] [blame] | 4937 | |
| 4938 | rt2800_bbp_write(rt2x00dev, 103, 0xc0); |
Stanislaw Gruszka | 49d6111 | 2013-05-18 14:03:46 +0200 | [diff] [blame] | 4939 | |
| 4940 | rt2800_bbp_write(rt2x00dev, 105, 0x05); |
Stanislaw Gruszka | f867085 | 2013-05-18 14:03:47 +0200 | [diff] [blame] | 4941 | |
| 4942 | rt2800_bbp_write(rt2x00dev, 106, 0x35); |
Stanislaw Gruszka | 5df1ff3 | 2013-05-18 14:03:52 +0200 | [diff] [blame] | 4943 | |
| 4944 | rt2800_disable_unused_dac_adc(rt2x00dev); |
Stanislaw Gruszka | 39ab3e8 | 2013-05-18 14:03:25 +0200 | [diff] [blame] | 4945 | } |
| 4946 | |
Gabor Juhos | b189a18 | 2013-07-08 16:08:17 +0200 | [diff] [blame] | 4947 | static void rt2800_init_bbp_3593(struct rt2x00_dev *rt2x00dev) |
| 4948 | { |
| 4949 | rt2800_init_bbp_early(rt2x00dev); |
| 4950 | |
| 4951 | rt2800_bbp_write(rt2x00dev, 79, 0x13); |
| 4952 | rt2800_bbp_write(rt2x00dev, 80, 0x05); |
| 4953 | rt2800_bbp_write(rt2x00dev, 81, 0x33); |
| 4954 | rt2800_bbp_write(rt2x00dev, 137, 0x0f); |
| 4955 | |
| 4956 | rt2800_bbp_write(rt2x00dev, 84, 0x19); |
| 4957 | |
| 4958 | /* Enable DC filter */ |
| 4959 | if (rt2x00_rt_rev_gte(rt2x00dev, RT3593, REV_RT3593E)) |
| 4960 | rt2800_bbp_write(rt2x00dev, 103, 0xc0); |
| 4961 | } |
| 4962 | |
Stanislaw Gruszka | 39ab3e8 | 2013-05-18 14:03:25 +0200 | [diff] [blame] | 4963 | static void rt2800_init_bbp_53xx(struct rt2x00_dev *rt2x00dev) |
| 4964 | { |
Stanislaw Gruszka | 32ef8f4 | 2013-05-18 14:03:55 +0200 | [diff] [blame] | 4965 | int ant, div_mode; |
| 4966 | u16 eeprom; |
| 4967 | u8 value; |
| 4968 | |
Stanislaw Gruszka | c322357 | 2013-05-18 14:03:28 +0200 | [diff] [blame] | 4969 | rt2800_bbp4_mac_if_ctrl(rt2x00dev); |
Stanislaw Gruszka | b2f8e0b | 2013-05-18 14:03:29 +0200 | [diff] [blame] | 4970 | |
| 4971 | rt2800_bbp_write(rt2x00dev, 31, 0x08); |
Stanislaw Gruszka | e379de1 | 2013-05-18 14:03:31 +0200 | [diff] [blame] | 4972 | |
| 4973 | rt2800_bbp_write(rt2x00dev, 65, 0x2c); |
| 4974 | rt2800_bbp_write(rt2x00dev, 66, 0x38); |
Stanislaw Gruszka | 59dcabb | 2013-05-18 14:03:32 +0200 | [diff] [blame] | 4975 | |
| 4976 | rt2800_bbp_write(rt2x00dev, 68, 0x0b); |
Stanislaw Gruszka | 72ffe14 | 2013-05-18 14:03:33 +0200 | [diff] [blame] | 4977 | |
| 4978 | rt2800_bbp_write(rt2x00dev, 69, 0x12); |
| 4979 | rt2800_bbp_write(rt2x00dev, 73, 0x13); |
| 4980 | rt2800_bbp_write(rt2x00dev, 75, 0x46); |
| 4981 | rt2800_bbp_write(rt2x00dev, 76, 0x28); |
| 4982 | |
| 4983 | rt2800_bbp_write(rt2x00dev, 77, 0x59); |
Stanislaw Gruszka | 8d97be3 | 2013-05-18 14:03:34 +0200 | [diff] [blame] | 4984 | |
| 4985 | rt2800_bbp_write(rt2x00dev, 70, 0x0a); |
Stanislaw Gruszka | 43f535e | 2013-05-18 14:03:35 +0200 | [diff] [blame] | 4986 | |
| 4987 | rt2800_bbp_write(rt2x00dev, 79, 0x13); |
| 4988 | rt2800_bbp_write(rt2x00dev, 80, 0x05); |
| 4989 | rt2800_bbp_write(rt2x00dev, 81, 0x33); |
Stanislaw Gruszka | fa1e342 | 2013-05-18 14:03:36 +0200 | [diff] [blame] | 4990 | |
| 4991 | rt2800_bbp_write(rt2x00dev, 82, 0x62); |
Stanislaw Gruszka | 885f241 | 2013-05-18 14:03:37 +0200 | [diff] [blame] | 4992 | |
| 4993 | rt2800_bbp_write(rt2x00dev, 83, 0x7a); |
Stanislaw Gruszka | 3c20a12 | 2013-05-18 14:03:38 +0200 | [diff] [blame] | 4994 | |
| 4995 | rt2800_bbp_write(rt2x00dev, 84, 0x9a); |
Stanislaw Gruszka | aef9f38 | 2013-05-18 14:03:39 +0200 | [diff] [blame] | 4996 | |
| 4997 | rt2800_bbp_write(rt2x00dev, 86, 0x38); |
Stanislaw Gruszka | 9400fa8 | 2013-05-18 14:03:40 +0200 | [diff] [blame] | 4998 | |
| 4999 | if (rt2x00_rt(rt2x00dev, RT5392)) |
| 5000 | rt2800_bbp_write(rt2x00dev, 88, 0x90); |
Stanislaw Gruszka | 7af9874 | 2013-05-18 14:03:41 +0200 | [diff] [blame] | 5001 | |
| 5002 | rt2800_bbp_write(rt2x00dev, 91, 0x04); |
Stanislaw Gruszka | b4e121d | 2013-05-18 14:03:42 +0200 | [diff] [blame] | 5003 | |
| 5004 | rt2800_bbp_write(rt2x00dev, 92, 0x02); |
Stanislaw Gruszka | 90fed53 | 2013-05-18 14:03:43 +0200 | [diff] [blame] | 5005 | |
| 5006 | if (rt2x00_rt(rt2x00dev, RT5392)) { |
| 5007 | rt2800_bbp_write(rt2x00dev, 95, 0x9a); |
| 5008 | rt2800_bbp_write(rt2x00dev, 98, 0x12); |
| 5009 | } |
Stanislaw Gruszka | 672d118 | 2013-05-18 14:03:44 +0200 | [diff] [blame] | 5010 | |
| 5011 | rt2800_bbp_write(rt2x00dev, 103, 0xc0); |
Stanislaw Gruszka | 1ad4408 | 2013-05-18 14:03:45 +0200 | [diff] [blame] | 5012 | |
| 5013 | rt2800_bbp_write(rt2x00dev, 104, 0x92); |
Stanislaw Gruszka | 49d6111 | 2013-05-18 14:03:46 +0200 | [diff] [blame] | 5014 | |
| 5015 | rt2800_bbp_write(rt2x00dev, 105, 0x3c); |
Stanislaw Gruszka | f867085 | 2013-05-18 14:03:47 +0200 | [diff] [blame] | 5016 | |
| 5017 | if (rt2x00_rt(rt2x00dev, RT5390)) |
| 5018 | rt2800_bbp_write(rt2x00dev, 106, 0x03); |
| 5019 | else if (rt2x00_rt(rt2x00dev, RT5392)) |
| 5020 | rt2800_bbp_write(rt2x00dev, 106, 0x12); |
| 5021 | else |
| 5022 | WARN_ON(1); |
Stanislaw Gruszka | f2b6777 | 2013-05-18 14:03:49 +0200 | [diff] [blame] | 5023 | |
| 5024 | rt2800_bbp_write(rt2x00dev, 128, 0x12); |
Stanislaw Gruszka | 7291714 | 2013-05-18 14:03:50 +0200 | [diff] [blame] | 5025 | |
| 5026 | if (rt2x00_rt(rt2x00dev, RT5392)) { |
| 5027 | rt2800_bbp_write(rt2x00dev, 134, 0xd0); |
| 5028 | rt2800_bbp_write(rt2x00dev, 135, 0xf6); |
| 5029 | } |
Stanislaw Gruszka | 5df1ff3 | 2013-05-18 14:03:52 +0200 | [diff] [blame] | 5030 | |
| 5031 | rt2800_disable_unused_dac_adc(rt2x00dev); |
Stanislaw Gruszka | 32ef8f4 | 2013-05-18 14:03:55 +0200 | [diff] [blame] | 5032 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 5033 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom); |
Stanislaw Gruszka | 32ef8f4 | 2013-05-18 14:03:55 +0200 | [diff] [blame] | 5034 | div_mode = rt2x00_get_field16(eeprom, |
| 5035 | EEPROM_NIC_CONF1_ANT_DIVERSITY); |
| 5036 | ant = (div_mode == 3) ? 1 : 0; |
| 5037 | |
| 5038 | /* check if this is a Bluetooth combo card */ |
| 5039 | if (test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags)) { |
| 5040 | u32 reg; |
| 5041 | |
| 5042 | rt2800_register_read(rt2x00dev, GPIO_CTRL, ®); |
| 5043 | rt2x00_set_field32(®, GPIO_CTRL_DIR3, 0); |
| 5044 | rt2x00_set_field32(®, GPIO_CTRL_DIR6, 0); |
| 5045 | rt2x00_set_field32(®, GPIO_CTRL_VAL3, 0); |
| 5046 | rt2x00_set_field32(®, GPIO_CTRL_VAL6, 0); |
| 5047 | if (ant == 0) |
| 5048 | rt2x00_set_field32(®, GPIO_CTRL_VAL3, 1); |
| 5049 | else if (ant == 1) |
| 5050 | rt2x00_set_field32(®, GPIO_CTRL_VAL6, 1); |
| 5051 | rt2800_register_write(rt2x00dev, GPIO_CTRL, reg); |
| 5052 | } |
| 5053 | |
| 5054 | /* This chip has hardware antenna diversity*/ |
| 5055 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390R)) { |
| 5056 | rt2800_bbp_write(rt2x00dev, 150, 0); /* Disable Antenna Software OFDM */ |
| 5057 | rt2800_bbp_write(rt2x00dev, 151, 0); /* Disable Antenna Software CCK */ |
| 5058 | rt2800_bbp_write(rt2x00dev, 154, 0); /* Clear previously selected antenna */ |
| 5059 | } |
| 5060 | |
| 5061 | rt2800_bbp_read(rt2x00dev, 152, &value); |
| 5062 | if (ant == 0) |
| 5063 | rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 1); |
| 5064 | else |
| 5065 | rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 0); |
| 5066 | rt2800_bbp_write(rt2x00dev, 152, value); |
| 5067 | |
| 5068 | rt2800_init_freq_calibration(rt2x00dev); |
Stanislaw Gruszka | 39ab3e8 | 2013-05-18 14:03:25 +0200 | [diff] [blame] | 5069 | } |
| 5070 | |
Stanislaw Gruszka | a7bbbe5 | 2013-03-16 19:19:34 +0100 | [diff] [blame] | 5071 | static void rt2800_init_bbp_5592(struct rt2x00_dev *rt2x00dev) |
| 5072 | { |
| 5073 | int ant, div_mode; |
| 5074 | u16 eeprom; |
| 5075 | u8 value; |
| 5076 | |
Gabor Juhos | 624708b | 2013-04-19 10:13:52 +0200 | [diff] [blame] | 5077 | rt2800_init_bbp_early(rt2x00dev); |
Stanislaw Gruszka | a4969d0 | 2013-03-16 19:19:35 +0100 | [diff] [blame] | 5078 | |
Stanislaw Gruszka | a7bbbe5 | 2013-03-16 19:19:34 +0100 | [diff] [blame] | 5079 | rt2800_bbp_read(rt2x00dev, 105, &value); |
| 5080 | rt2x00_set_field8(&value, BBP105_MLD, |
| 5081 | rt2x00dev->default_ant.rx_chain_num == 2); |
| 5082 | rt2800_bbp_write(rt2x00dev, 105, value); |
| 5083 | |
| 5084 | rt2800_bbp4_mac_if_ctrl(rt2x00dev); |
| 5085 | |
| 5086 | rt2800_bbp_write(rt2x00dev, 20, 0x06); |
| 5087 | rt2800_bbp_write(rt2x00dev, 31, 0x08); |
| 5088 | rt2800_bbp_write(rt2x00dev, 65, 0x2C); |
| 5089 | rt2800_bbp_write(rt2x00dev, 68, 0xDD); |
| 5090 | rt2800_bbp_write(rt2x00dev, 69, 0x1A); |
| 5091 | rt2800_bbp_write(rt2x00dev, 70, 0x05); |
| 5092 | rt2800_bbp_write(rt2x00dev, 73, 0x13); |
| 5093 | rt2800_bbp_write(rt2x00dev, 74, 0x0F); |
| 5094 | rt2800_bbp_write(rt2x00dev, 75, 0x4F); |
| 5095 | rt2800_bbp_write(rt2x00dev, 76, 0x28); |
| 5096 | rt2800_bbp_write(rt2x00dev, 77, 0x59); |
| 5097 | rt2800_bbp_write(rt2x00dev, 84, 0x9A); |
| 5098 | rt2800_bbp_write(rt2x00dev, 86, 0x38); |
| 5099 | rt2800_bbp_write(rt2x00dev, 88, 0x90); |
| 5100 | rt2800_bbp_write(rt2x00dev, 91, 0x04); |
| 5101 | rt2800_bbp_write(rt2x00dev, 92, 0x02); |
| 5102 | rt2800_bbp_write(rt2x00dev, 95, 0x9a); |
| 5103 | rt2800_bbp_write(rt2x00dev, 98, 0x12); |
| 5104 | rt2800_bbp_write(rt2x00dev, 103, 0xC0); |
| 5105 | rt2800_bbp_write(rt2x00dev, 104, 0x92); |
| 5106 | /* FIXME BBP105 owerwrite */ |
| 5107 | rt2800_bbp_write(rt2x00dev, 105, 0x3C); |
| 5108 | rt2800_bbp_write(rt2x00dev, 106, 0x35); |
| 5109 | rt2800_bbp_write(rt2x00dev, 128, 0x12); |
| 5110 | rt2800_bbp_write(rt2x00dev, 134, 0xD0); |
| 5111 | rt2800_bbp_write(rt2x00dev, 135, 0xF6); |
| 5112 | rt2800_bbp_write(rt2x00dev, 137, 0x0F); |
| 5113 | |
| 5114 | /* Initialize GLRT (Generalized Likehood Radio Test) */ |
| 5115 | rt2800_init_bbp_5592_glrt(rt2x00dev); |
| 5116 | |
| 5117 | rt2800_bbp4_mac_if_ctrl(rt2x00dev); |
| 5118 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 5119 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom); |
Stanislaw Gruszka | a7bbbe5 | 2013-03-16 19:19:34 +0100 | [diff] [blame] | 5120 | div_mode = rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_ANT_DIVERSITY); |
| 5121 | ant = (div_mode == 3) ? 1 : 0; |
| 5122 | rt2800_bbp_read(rt2x00dev, 152, &value); |
| 5123 | if (ant == 0) { |
| 5124 | /* Main antenna */ |
| 5125 | rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 1); |
| 5126 | } else { |
| 5127 | /* Auxiliary antenna */ |
| 5128 | rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 0); |
| 5129 | } |
| 5130 | rt2800_bbp_write(rt2x00dev, 152, value); |
| 5131 | |
| 5132 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5592, REV_RT5592C)) { |
| 5133 | rt2800_bbp_read(rt2x00dev, 254, &value); |
| 5134 | rt2x00_set_field8(&value, BBP254_BIT7, 1); |
| 5135 | rt2800_bbp_write(rt2x00dev, 254, value); |
| 5136 | } |
| 5137 | |
Stanislaw Gruszka | c267548 | 2013-03-16 19:19:41 +0100 | [diff] [blame] | 5138 | rt2800_init_freq_calibration(rt2x00dev); |
| 5139 | |
Stanislaw Gruszka | a7bbbe5 | 2013-03-16 19:19:34 +0100 | [diff] [blame] | 5140 | rt2800_bbp_write(rt2x00dev, 84, 0x19); |
Stanislaw Gruszka | 6e04f25 | 2013-03-16 19:19:38 +0100 | [diff] [blame] | 5141 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5592, REV_RT5592C)) |
| 5142 | rt2800_bbp_write(rt2x00dev, 103, 0xc0); |
Stanislaw Gruszka | a7bbbe5 | 2013-03-16 19:19:34 +0100 | [diff] [blame] | 5143 | } |
| 5144 | |
Stanislaw Gruszka | a1ef5039 | 2013-05-18 14:03:24 +0200 | [diff] [blame] | 5145 | static void rt2800_init_bbp(struct rt2x00_dev *rt2x00dev) |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 5146 | { |
| 5147 | unsigned int i; |
| 5148 | u16 eeprom; |
| 5149 | u8 reg_id; |
| 5150 | u8 value; |
| 5151 | |
Stanislaw Gruszka | dae6295 | 2013-05-18 14:03:26 +0200 | [diff] [blame] | 5152 | if (rt2800_is_305x_soc(rt2x00dev)) |
| 5153 | rt2800_init_bbp_305x_soc(rt2x00dev); |
| 5154 | |
Stanislaw Gruszka | 39ab3e8 | 2013-05-18 14:03:25 +0200 | [diff] [blame] | 5155 | switch (rt2x00dev->chip.rt) { |
| 5156 | case RT2860: |
| 5157 | case RT2872: |
| 5158 | case RT2883: |
| 5159 | rt2800_init_bbp_28xx(rt2x00dev); |
| 5160 | break; |
| 5161 | case RT3070: |
| 5162 | case RT3071: |
| 5163 | case RT3090: |
| 5164 | rt2800_init_bbp_30xx(rt2x00dev); |
| 5165 | break; |
| 5166 | case RT3290: |
| 5167 | rt2800_init_bbp_3290(rt2x00dev); |
| 5168 | break; |
| 5169 | case RT3352: |
| 5170 | rt2800_init_bbp_3352(rt2x00dev); |
| 5171 | break; |
| 5172 | case RT3390: |
| 5173 | rt2800_init_bbp_3390(rt2x00dev); |
| 5174 | break; |
| 5175 | case RT3572: |
| 5176 | rt2800_init_bbp_3572(rt2x00dev); |
| 5177 | break; |
Gabor Juhos | b189a18 | 2013-07-08 16:08:17 +0200 | [diff] [blame] | 5178 | case RT3593: |
| 5179 | rt2800_init_bbp_3593(rt2x00dev); |
| 5180 | return; |
Stanislaw Gruszka | 39ab3e8 | 2013-05-18 14:03:25 +0200 | [diff] [blame] | 5181 | case RT5390: |
| 5182 | case RT5392: |
| 5183 | rt2800_init_bbp_53xx(rt2x00dev); |
| 5184 | break; |
| 5185 | case RT5592: |
Stanislaw Gruszka | a7bbbe5 | 2013-03-16 19:19:34 +0100 | [diff] [blame] | 5186 | rt2800_init_bbp_5592(rt2x00dev); |
Stanislaw Gruszka | a1ef5039 | 2013-05-18 14:03:24 +0200 | [diff] [blame] | 5187 | return; |
Stanislaw Gruszka | a7bbbe5 | 2013-03-16 19:19:34 +0100 | [diff] [blame] | 5188 | } |
| 5189 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 5190 | for (i = 0; i < EEPROM_BBP_SIZE; i++) { |
Gabor Juhos | 022138c | 2013-07-08 11:25:54 +0200 | [diff] [blame] | 5191 | rt2800_eeprom_read_from_array(rt2x00dev, EEPROM_BBP_START, i, |
| 5192 | &eeprom); |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 5193 | |
| 5194 | if (eeprom != 0xffff && eeprom != 0x0000) { |
| 5195 | reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID); |
| 5196 | value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE); |
| 5197 | rt2800_bbp_write(rt2x00dev, reg_id, value); |
| 5198 | } |
| 5199 | } |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 5200 | } |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 5201 | |
Stanislaw Gruszka | d9517f2 | 2013-04-17 14:08:18 +0200 | [diff] [blame] | 5202 | static void rt2800_led_open_drain_enable(struct rt2x00_dev *rt2x00dev) |
| 5203 | { |
| 5204 | u32 reg; |
| 5205 | |
| 5206 | rt2800_register_read(rt2x00dev, OPT_14_CSR, ®); |
| 5207 | rt2x00_set_field32(®, OPT_14_CSR_BIT0, 1); |
| 5208 | rt2800_register_write(rt2x00dev, OPT_14_CSR, reg); |
| 5209 | } |
| 5210 | |
Stanislaw Gruszka | c5b3c35 | 2013-04-17 14:08:16 +0200 | [diff] [blame] | 5211 | static u8 rt2800_init_rx_filter(struct rt2x00_dev *rt2x00dev, bool bw40, |
| 5212 | u8 filter_target) |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 5213 | { |
| 5214 | unsigned int i; |
| 5215 | u8 bbp; |
| 5216 | u8 rfcsr; |
| 5217 | u8 passband; |
| 5218 | u8 stopband; |
| 5219 | u8 overtuned = 0; |
Stanislaw Gruszka | c5b3c35 | 2013-04-17 14:08:16 +0200 | [diff] [blame] | 5220 | u8 rfcsr24 = (bw40) ? 0x27 : 0x07; |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 5221 | |
| 5222 | rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24); |
| 5223 | |
| 5224 | rt2800_bbp_read(rt2x00dev, 4, &bbp); |
| 5225 | rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * bw40); |
| 5226 | rt2800_bbp_write(rt2x00dev, 4, bbp); |
| 5227 | |
RA-Jay Hung | 80d184e | 2011-01-10 11:28:10 +0100 | [diff] [blame] | 5228 | rt2800_rfcsr_read(rt2x00dev, 31, &rfcsr); |
| 5229 | rt2x00_set_field8(&rfcsr, RFCSR31_RX_H20M, bw40); |
| 5230 | rt2800_rfcsr_write(rt2x00dev, 31, rfcsr); |
| 5231 | |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 5232 | rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr); |
| 5233 | rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 1); |
| 5234 | rt2800_rfcsr_write(rt2x00dev, 22, rfcsr); |
| 5235 | |
| 5236 | /* |
| 5237 | * Set power & frequency of passband test tone |
| 5238 | */ |
| 5239 | rt2800_bbp_write(rt2x00dev, 24, 0); |
| 5240 | |
| 5241 | for (i = 0; i < 100; i++) { |
| 5242 | rt2800_bbp_write(rt2x00dev, 25, 0x90); |
| 5243 | msleep(1); |
| 5244 | |
| 5245 | rt2800_bbp_read(rt2x00dev, 55, &passband); |
| 5246 | if (passband) |
| 5247 | break; |
| 5248 | } |
| 5249 | |
| 5250 | /* |
| 5251 | * Set power & frequency of stopband test tone |
| 5252 | */ |
| 5253 | rt2800_bbp_write(rt2x00dev, 24, 0x06); |
| 5254 | |
| 5255 | for (i = 0; i < 100; i++) { |
| 5256 | rt2800_bbp_write(rt2x00dev, 25, 0x90); |
| 5257 | msleep(1); |
| 5258 | |
| 5259 | rt2800_bbp_read(rt2x00dev, 55, &stopband); |
| 5260 | |
| 5261 | if ((passband - stopband) <= filter_target) { |
| 5262 | rfcsr24++; |
| 5263 | overtuned += ((passband - stopband) == filter_target); |
| 5264 | } else |
| 5265 | break; |
| 5266 | |
| 5267 | rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24); |
| 5268 | } |
| 5269 | |
| 5270 | rfcsr24 -= !!overtuned; |
| 5271 | |
| 5272 | rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24); |
| 5273 | return rfcsr24; |
| 5274 | } |
| 5275 | |
Stanislaw Gruszka | ce94ede9 | 2013-04-17 14:08:11 +0200 | [diff] [blame] | 5276 | static void rt2800_rf_init_calibration(struct rt2x00_dev *rt2x00dev, |
| 5277 | const unsigned int rf_reg) |
| 5278 | { |
| 5279 | u8 rfcsr; |
| 5280 | |
| 5281 | rt2800_rfcsr_read(rt2x00dev, rf_reg, &rfcsr); |
| 5282 | rt2x00_set_field8(&rfcsr, FIELD8(0x80), 1); |
| 5283 | rt2800_rfcsr_write(rt2x00dev, rf_reg, rfcsr); |
| 5284 | msleep(1); |
| 5285 | rt2x00_set_field8(&rfcsr, FIELD8(0x80), 0); |
| 5286 | rt2800_rfcsr_write(rt2x00dev, rf_reg, rfcsr); |
| 5287 | } |
| 5288 | |
Stanislaw Gruszka | c5b3c35 | 2013-04-17 14:08:16 +0200 | [diff] [blame] | 5289 | static void rt2800_rx_filter_calibration(struct rt2x00_dev *rt2x00dev) |
| 5290 | { |
| 5291 | struct rt2800_drv_data *drv_data = rt2x00dev->drv_data; |
| 5292 | u8 filter_tgt_bw20; |
| 5293 | u8 filter_tgt_bw40; |
| 5294 | u8 rfcsr, bbp; |
| 5295 | |
| 5296 | /* |
| 5297 | * TODO: sync filter_tgt values with vendor driver |
| 5298 | */ |
| 5299 | if (rt2x00_rt(rt2x00dev, RT3070)) { |
| 5300 | filter_tgt_bw20 = 0x16; |
| 5301 | filter_tgt_bw40 = 0x19; |
| 5302 | } else { |
| 5303 | filter_tgt_bw20 = 0x13; |
| 5304 | filter_tgt_bw40 = 0x15; |
| 5305 | } |
| 5306 | |
| 5307 | drv_data->calibration_bw20 = |
| 5308 | rt2800_init_rx_filter(rt2x00dev, false, filter_tgt_bw20); |
| 5309 | drv_data->calibration_bw40 = |
| 5310 | rt2800_init_rx_filter(rt2x00dev, true, filter_tgt_bw40); |
| 5311 | |
| 5312 | /* |
| 5313 | * Save BBP 25 & 26 values for later use in channel switching (for 3052) |
| 5314 | */ |
| 5315 | rt2800_bbp_read(rt2x00dev, 25, &drv_data->bbp25); |
| 5316 | rt2800_bbp_read(rt2x00dev, 26, &drv_data->bbp26); |
| 5317 | |
| 5318 | /* |
| 5319 | * Set back to initial state |
| 5320 | */ |
| 5321 | rt2800_bbp_write(rt2x00dev, 24, 0); |
| 5322 | |
| 5323 | rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr); |
| 5324 | rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 0); |
| 5325 | rt2800_rfcsr_write(rt2x00dev, 22, rfcsr); |
| 5326 | |
| 5327 | /* |
| 5328 | * Set BBP back to BW20 |
| 5329 | */ |
| 5330 | rt2800_bbp_read(rt2x00dev, 4, &bbp); |
| 5331 | rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0); |
| 5332 | rt2800_bbp_write(rt2x00dev, 4, bbp); |
| 5333 | } |
| 5334 | |
Stanislaw Gruszka | da8064c | 2013-04-17 14:08:19 +0200 | [diff] [blame] | 5335 | static void rt2800_normal_mode_setup_3xxx(struct rt2x00_dev *rt2x00dev) |
| 5336 | { |
| 5337 | struct rt2800_drv_data *drv_data = rt2x00dev->drv_data; |
| 5338 | u8 min_gain, rfcsr, bbp; |
| 5339 | u16 eeprom; |
| 5340 | |
| 5341 | rt2800_rfcsr_read(rt2x00dev, 17, &rfcsr); |
| 5342 | |
| 5343 | rt2x00_set_field8(&rfcsr, RFCSR17_TX_LO1_EN, 0); |
| 5344 | if (rt2x00_rt(rt2x00dev, RT3070) || |
| 5345 | rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) || |
| 5346 | rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E) || |
| 5347 | rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) { |
| 5348 | if (!test_bit(CAPABILITY_EXTERNAL_LNA_BG, &rt2x00dev->cap_flags)) |
| 5349 | rt2x00_set_field8(&rfcsr, RFCSR17_R, 1); |
| 5350 | } |
| 5351 | |
| 5352 | min_gain = rt2x00_rt(rt2x00dev, RT3070) ? 1 : 2; |
| 5353 | if (drv_data->txmixer_gain_24g >= min_gain) { |
| 5354 | rt2x00_set_field8(&rfcsr, RFCSR17_TXMIXER_GAIN, |
| 5355 | drv_data->txmixer_gain_24g); |
| 5356 | } |
| 5357 | |
| 5358 | rt2800_rfcsr_write(rt2x00dev, 17, rfcsr); |
| 5359 | |
| 5360 | if (rt2x00_rt(rt2x00dev, RT3090)) { |
| 5361 | /* Turn off unused DAC1 and ADC1 to reduce power consumption */ |
| 5362 | rt2800_bbp_read(rt2x00dev, 138, &bbp); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 5363 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom); |
Stanislaw Gruszka | da8064c | 2013-04-17 14:08:19 +0200 | [diff] [blame] | 5364 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) == 1) |
| 5365 | rt2x00_set_field8(&bbp, BBP138_RX_ADC1, 0); |
| 5366 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) == 1) |
| 5367 | rt2x00_set_field8(&bbp, BBP138_TX_DAC1, 1); |
| 5368 | rt2800_bbp_write(rt2x00dev, 138, bbp); |
| 5369 | } |
| 5370 | |
| 5371 | if (rt2x00_rt(rt2x00dev, RT3070)) { |
| 5372 | rt2800_rfcsr_read(rt2x00dev, 27, &rfcsr); |
| 5373 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) |
| 5374 | rt2x00_set_field8(&rfcsr, RFCSR27_R1, 3); |
| 5375 | else |
| 5376 | rt2x00_set_field8(&rfcsr, RFCSR27_R1, 0); |
| 5377 | rt2x00_set_field8(&rfcsr, RFCSR27_R2, 0); |
| 5378 | rt2x00_set_field8(&rfcsr, RFCSR27_R3, 0); |
| 5379 | rt2x00_set_field8(&rfcsr, RFCSR27_R4, 0); |
| 5380 | rt2800_rfcsr_write(rt2x00dev, 27, rfcsr); |
| 5381 | } else if (rt2x00_rt(rt2x00dev, RT3071) || |
| 5382 | rt2x00_rt(rt2x00dev, RT3090) || |
| 5383 | rt2x00_rt(rt2x00dev, RT3390)) { |
| 5384 | rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr); |
| 5385 | rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1); |
| 5386 | rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0); |
| 5387 | rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0); |
| 5388 | rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1); |
| 5389 | rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1); |
| 5390 | rt2800_rfcsr_write(rt2x00dev, 1, rfcsr); |
| 5391 | |
| 5392 | rt2800_rfcsr_read(rt2x00dev, 15, &rfcsr); |
| 5393 | rt2x00_set_field8(&rfcsr, RFCSR15_TX_LO2_EN, 0); |
| 5394 | rt2800_rfcsr_write(rt2x00dev, 15, rfcsr); |
| 5395 | |
| 5396 | rt2800_rfcsr_read(rt2x00dev, 20, &rfcsr); |
| 5397 | rt2x00_set_field8(&rfcsr, RFCSR20_RX_LO1_EN, 0); |
| 5398 | rt2800_rfcsr_write(rt2x00dev, 20, rfcsr); |
| 5399 | |
| 5400 | rt2800_rfcsr_read(rt2x00dev, 21, &rfcsr); |
| 5401 | rt2x00_set_field8(&rfcsr, RFCSR21_RX_LO2_EN, 0); |
| 5402 | rt2800_rfcsr_write(rt2x00dev, 21, rfcsr); |
| 5403 | } |
| 5404 | } |
| 5405 | |
Gabor Juhos | ab7078a | 2013-07-08 16:08:18 +0200 | [diff] [blame] | 5406 | static void rt2800_normal_mode_setup_3593(struct rt2x00_dev *rt2x00dev) |
| 5407 | { |
| 5408 | struct rt2800_drv_data *drv_data = rt2x00dev->drv_data; |
| 5409 | u8 rfcsr; |
| 5410 | u8 tx_gain; |
| 5411 | |
| 5412 | rt2800_rfcsr_read(rt2x00dev, 50, &rfcsr); |
| 5413 | rt2x00_set_field8(&rfcsr, RFCSR50_TX_LO2_EN, 0); |
| 5414 | rt2800_rfcsr_write(rt2x00dev, 50, rfcsr); |
| 5415 | |
| 5416 | rt2800_rfcsr_read(rt2x00dev, 51, &rfcsr); |
| 5417 | tx_gain = rt2x00_get_field8(drv_data->txmixer_gain_24g, |
| 5418 | RFCSR17_TXMIXER_GAIN); |
| 5419 | rt2x00_set_field8(&rfcsr, RFCSR51_BITS24, tx_gain); |
| 5420 | rt2800_rfcsr_write(rt2x00dev, 51, rfcsr); |
| 5421 | |
| 5422 | rt2800_rfcsr_read(rt2x00dev, 38, &rfcsr); |
| 5423 | rt2x00_set_field8(&rfcsr, RFCSR38_RX_LO1_EN, 0); |
| 5424 | rt2800_rfcsr_write(rt2x00dev, 38, rfcsr); |
| 5425 | |
| 5426 | rt2800_rfcsr_read(rt2x00dev, 39, &rfcsr); |
| 5427 | rt2x00_set_field8(&rfcsr, RFCSR39_RX_LO2_EN, 0); |
| 5428 | rt2800_rfcsr_write(rt2x00dev, 39, rfcsr); |
| 5429 | |
| 5430 | rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr); |
| 5431 | rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1); |
| 5432 | rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1); |
| 5433 | rt2800_rfcsr_write(rt2x00dev, 1, rfcsr); |
| 5434 | |
| 5435 | rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr); |
| 5436 | rt2x00_set_field8(&rfcsr, RFCSR30_RX_VCM, 2); |
| 5437 | rt2800_rfcsr_write(rt2x00dev, 30, rfcsr); |
| 5438 | |
| 5439 | /* TODO: enable stream mode */ |
| 5440 | } |
| 5441 | |
Stanislaw Gruszka | f7df8fe | 2013-04-17 14:08:10 +0200 | [diff] [blame] | 5442 | static void rt2800_normal_mode_setup_5xxx(struct rt2x00_dev *rt2x00dev) |
| 5443 | { |
| 5444 | u8 reg; |
| 5445 | u16 eeprom; |
| 5446 | |
| 5447 | /* Turn off unused DAC1 and ADC1 to reduce power consumption */ |
| 5448 | rt2800_bbp_read(rt2x00dev, 138, ®); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 5449 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom); |
Stanislaw Gruszka | f7df8fe | 2013-04-17 14:08:10 +0200 | [diff] [blame] | 5450 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) == 1) |
| 5451 | rt2x00_set_field8(®, BBP138_RX_ADC1, 0); |
| 5452 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) == 1) |
| 5453 | rt2x00_set_field8(®, BBP138_TX_DAC1, 1); |
| 5454 | rt2800_bbp_write(rt2x00dev, 138, reg); |
| 5455 | |
| 5456 | rt2800_rfcsr_read(rt2x00dev, 38, ®); |
| 5457 | rt2x00_set_field8(®, RFCSR38_RX_LO1_EN, 0); |
| 5458 | rt2800_rfcsr_write(rt2x00dev, 38, reg); |
| 5459 | |
| 5460 | rt2800_rfcsr_read(rt2x00dev, 39, ®); |
| 5461 | rt2x00_set_field8(®, RFCSR39_RX_LO2_EN, 0); |
| 5462 | rt2800_rfcsr_write(rt2x00dev, 39, reg); |
| 5463 | |
| 5464 | rt2800_bbp4_mac_if_ctrl(rt2x00dev); |
| 5465 | |
| 5466 | rt2800_rfcsr_read(rt2x00dev, 30, ®); |
| 5467 | rt2x00_set_field8(®, RFCSR30_RX_VCM, 2); |
| 5468 | rt2800_rfcsr_write(rt2x00dev, 30, reg); |
| 5469 | } |
| 5470 | |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 5471 | static void rt2800_init_rfcsr_305x_soc(struct rt2x00_dev *rt2x00dev) |
| 5472 | { |
Stanislaw Gruszka | ce94ede9 | 2013-04-17 14:08:11 +0200 | [diff] [blame] | 5473 | rt2800_rf_init_calibration(rt2x00dev, 30); |
| 5474 | |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 5475 | rt2800_rfcsr_write(rt2x00dev, 0, 0x50); |
| 5476 | rt2800_rfcsr_write(rt2x00dev, 1, 0x01); |
| 5477 | rt2800_rfcsr_write(rt2x00dev, 2, 0xf7); |
| 5478 | rt2800_rfcsr_write(rt2x00dev, 3, 0x75); |
| 5479 | rt2800_rfcsr_write(rt2x00dev, 4, 0x40); |
| 5480 | rt2800_rfcsr_write(rt2x00dev, 5, 0x03); |
| 5481 | rt2800_rfcsr_write(rt2x00dev, 6, 0x02); |
| 5482 | rt2800_rfcsr_write(rt2x00dev, 7, 0x50); |
| 5483 | rt2800_rfcsr_write(rt2x00dev, 8, 0x39); |
| 5484 | rt2800_rfcsr_write(rt2x00dev, 9, 0x0f); |
| 5485 | rt2800_rfcsr_write(rt2x00dev, 10, 0x60); |
| 5486 | rt2800_rfcsr_write(rt2x00dev, 11, 0x21); |
| 5487 | rt2800_rfcsr_write(rt2x00dev, 12, 0x75); |
| 5488 | rt2800_rfcsr_write(rt2x00dev, 13, 0x75); |
| 5489 | rt2800_rfcsr_write(rt2x00dev, 14, 0x90); |
| 5490 | rt2800_rfcsr_write(rt2x00dev, 15, 0x58); |
| 5491 | rt2800_rfcsr_write(rt2x00dev, 16, 0xb3); |
| 5492 | rt2800_rfcsr_write(rt2x00dev, 17, 0x92); |
| 5493 | rt2800_rfcsr_write(rt2x00dev, 18, 0x2c); |
| 5494 | rt2800_rfcsr_write(rt2x00dev, 19, 0x02); |
| 5495 | rt2800_rfcsr_write(rt2x00dev, 20, 0xba); |
| 5496 | rt2800_rfcsr_write(rt2x00dev, 21, 0xdb); |
| 5497 | rt2800_rfcsr_write(rt2x00dev, 22, 0x00); |
| 5498 | rt2800_rfcsr_write(rt2x00dev, 23, 0x31); |
| 5499 | rt2800_rfcsr_write(rt2x00dev, 24, 0x08); |
| 5500 | rt2800_rfcsr_write(rt2x00dev, 25, 0x01); |
| 5501 | rt2800_rfcsr_write(rt2x00dev, 26, 0x25); |
| 5502 | rt2800_rfcsr_write(rt2x00dev, 27, 0x23); |
| 5503 | rt2800_rfcsr_write(rt2x00dev, 28, 0x13); |
| 5504 | rt2800_rfcsr_write(rt2x00dev, 29, 0x83); |
| 5505 | rt2800_rfcsr_write(rt2x00dev, 30, 0x00); |
| 5506 | rt2800_rfcsr_write(rt2x00dev, 31, 0x00); |
| 5507 | } |
| 5508 | |
| 5509 | static void rt2800_init_rfcsr_30xx(struct rt2x00_dev *rt2x00dev) |
| 5510 | { |
Stanislaw Gruszka | c9a221b | 2013-04-17 14:08:13 +0200 | [diff] [blame] | 5511 | u8 rfcsr; |
| 5512 | u16 eeprom; |
| 5513 | u32 reg; |
| 5514 | |
Stanislaw Gruszka | ce94ede9 | 2013-04-17 14:08:11 +0200 | [diff] [blame] | 5515 | /* XXX vendor driver do this only for 3070 */ |
| 5516 | rt2800_rf_init_calibration(rt2x00dev, 30); |
| 5517 | |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 5518 | rt2800_rfcsr_write(rt2x00dev, 4, 0x40); |
| 5519 | rt2800_rfcsr_write(rt2x00dev, 5, 0x03); |
| 5520 | rt2800_rfcsr_write(rt2x00dev, 6, 0x02); |
| 5521 | rt2800_rfcsr_write(rt2x00dev, 7, 0x60); |
| 5522 | rt2800_rfcsr_write(rt2x00dev, 9, 0x0f); |
| 5523 | rt2800_rfcsr_write(rt2x00dev, 10, 0x41); |
| 5524 | rt2800_rfcsr_write(rt2x00dev, 11, 0x21); |
| 5525 | rt2800_rfcsr_write(rt2x00dev, 12, 0x7b); |
| 5526 | rt2800_rfcsr_write(rt2x00dev, 14, 0x90); |
| 5527 | rt2800_rfcsr_write(rt2x00dev, 15, 0x58); |
| 5528 | rt2800_rfcsr_write(rt2x00dev, 16, 0xb3); |
| 5529 | rt2800_rfcsr_write(rt2x00dev, 17, 0x92); |
| 5530 | rt2800_rfcsr_write(rt2x00dev, 18, 0x2c); |
| 5531 | rt2800_rfcsr_write(rt2x00dev, 19, 0x02); |
| 5532 | rt2800_rfcsr_write(rt2x00dev, 20, 0xba); |
| 5533 | rt2800_rfcsr_write(rt2x00dev, 21, 0xdb); |
| 5534 | rt2800_rfcsr_write(rt2x00dev, 24, 0x16); |
| 5535 | rt2800_rfcsr_write(rt2x00dev, 25, 0x01); |
| 5536 | rt2800_rfcsr_write(rt2x00dev, 29, 0x1f); |
Stanislaw Gruszka | c9a221b | 2013-04-17 14:08:13 +0200 | [diff] [blame] | 5537 | |
| 5538 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) { |
| 5539 | rt2800_register_read(rt2x00dev, LDO_CFG0, ®); |
| 5540 | rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1); |
| 5541 | rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 3); |
| 5542 | rt2800_register_write(rt2x00dev, LDO_CFG0, reg); |
| 5543 | } else if (rt2x00_rt(rt2x00dev, RT3071) || |
| 5544 | rt2x00_rt(rt2x00dev, RT3090)) { |
| 5545 | rt2800_rfcsr_write(rt2x00dev, 31, 0x14); |
| 5546 | |
| 5547 | rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr); |
| 5548 | rt2x00_set_field8(&rfcsr, RFCSR6_R2, 1); |
| 5549 | rt2800_rfcsr_write(rt2x00dev, 6, rfcsr); |
| 5550 | |
| 5551 | rt2800_register_read(rt2x00dev, LDO_CFG0, ®); |
| 5552 | rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1); |
| 5553 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) || |
| 5554 | rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E)) { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 5555 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, |
| 5556 | &eeprom); |
Stanislaw Gruszka | c9a221b | 2013-04-17 14:08:13 +0200 | [diff] [blame] | 5557 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_DAC_TEST)) |
| 5558 | rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 3); |
| 5559 | else |
| 5560 | rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 0); |
| 5561 | } |
| 5562 | rt2800_register_write(rt2x00dev, LDO_CFG0, reg); |
| 5563 | |
| 5564 | rt2800_register_read(rt2x00dev, GPIO_SWITCH, ®); |
| 5565 | rt2x00_set_field32(®, GPIO_SWITCH_5, 0); |
| 5566 | rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg); |
| 5567 | } |
Stanislaw Gruszka | c5b3c35 | 2013-04-17 14:08:16 +0200 | [diff] [blame] | 5568 | |
| 5569 | rt2800_rx_filter_calibration(rt2x00dev); |
Stanislaw Gruszka | 5de5a1f | 2013-04-17 14:08:17 +0200 | [diff] [blame] | 5570 | |
| 5571 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F) || |
| 5572 | rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) || |
| 5573 | rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E)) |
| 5574 | rt2800_rfcsr_write(rt2x00dev, 27, 0x03); |
Stanislaw Gruszka | d9517f2 | 2013-04-17 14:08:18 +0200 | [diff] [blame] | 5575 | |
| 5576 | rt2800_led_open_drain_enable(rt2x00dev); |
Stanislaw Gruszka | da8064c | 2013-04-17 14:08:19 +0200 | [diff] [blame] | 5577 | rt2800_normal_mode_setup_3xxx(rt2x00dev); |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 5578 | } |
| 5579 | |
| 5580 | static void rt2800_init_rfcsr_3290(struct rt2x00_dev *rt2x00dev) |
| 5581 | { |
Stanislaw Gruszka | f9cdcbb | 2013-04-17 14:08:12 +0200 | [diff] [blame] | 5582 | u8 rfcsr; |
| 5583 | |
Stanislaw Gruszka | ce94ede9 | 2013-04-17 14:08:11 +0200 | [diff] [blame] | 5584 | rt2800_rf_init_calibration(rt2x00dev, 2); |
| 5585 | |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 5586 | rt2800_rfcsr_write(rt2x00dev, 1, 0x0f); |
| 5587 | rt2800_rfcsr_write(rt2x00dev, 2, 0x80); |
| 5588 | rt2800_rfcsr_write(rt2x00dev, 3, 0x08); |
| 5589 | rt2800_rfcsr_write(rt2x00dev, 4, 0x00); |
| 5590 | rt2800_rfcsr_write(rt2x00dev, 6, 0xa0); |
| 5591 | rt2800_rfcsr_write(rt2x00dev, 8, 0xf3); |
| 5592 | rt2800_rfcsr_write(rt2x00dev, 9, 0x02); |
| 5593 | rt2800_rfcsr_write(rt2x00dev, 10, 0x53); |
| 5594 | rt2800_rfcsr_write(rt2x00dev, 11, 0x4a); |
| 5595 | rt2800_rfcsr_write(rt2x00dev, 12, 0x46); |
| 5596 | rt2800_rfcsr_write(rt2x00dev, 13, 0x9f); |
| 5597 | rt2800_rfcsr_write(rt2x00dev, 18, 0x02); |
| 5598 | rt2800_rfcsr_write(rt2x00dev, 22, 0x20); |
| 5599 | rt2800_rfcsr_write(rt2x00dev, 25, 0x83); |
| 5600 | rt2800_rfcsr_write(rt2x00dev, 26, 0x82); |
| 5601 | rt2800_rfcsr_write(rt2x00dev, 27, 0x09); |
| 5602 | rt2800_rfcsr_write(rt2x00dev, 29, 0x10); |
| 5603 | rt2800_rfcsr_write(rt2x00dev, 30, 0x10); |
| 5604 | rt2800_rfcsr_write(rt2x00dev, 31, 0x80); |
| 5605 | rt2800_rfcsr_write(rt2x00dev, 32, 0x80); |
| 5606 | rt2800_rfcsr_write(rt2x00dev, 33, 0x00); |
| 5607 | rt2800_rfcsr_write(rt2x00dev, 34, 0x05); |
| 5608 | rt2800_rfcsr_write(rt2x00dev, 35, 0x12); |
| 5609 | rt2800_rfcsr_write(rt2x00dev, 36, 0x00); |
| 5610 | rt2800_rfcsr_write(rt2x00dev, 38, 0x85); |
| 5611 | rt2800_rfcsr_write(rt2x00dev, 39, 0x1b); |
| 5612 | rt2800_rfcsr_write(rt2x00dev, 40, 0x0b); |
| 5613 | rt2800_rfcsr_write(rt2x00dev, 41, 0xbb); |
| 5614 | rt2800_rfcsr_write(rt2x00dev, 42, 0xd5); |
| 5615 | rt2800_rfcsr_write(rt2x00dev, 43, 0x7b); |
| 5616 | rt2800_rfcsr_write(rt2x00dev, 44, 0x0e); |
| 5617 | rt2800_rfcsr_write(rt2x00dev, 45, 0xa2); |
| 5618 | rt2800_rfcsr_write(rt2x00dev, 46, 0x73); |
| 5619 | rt2800_rfcsr_write(rt2x00dev, 47, 0x00); |
| 5620 | rt2800_rfcsr_write(rt2x00dev, 48, 0x10); |
| 5621 | rt2800_rfcsr_write(rt2x00dev, 49, 0x98); |
| 5622 | rt2800_rfcsr_write(rt2x00dev, 52, 0x38); |
| 5623 | rt2800_rfcsr_write(rt2x00dev, 53, 0x00); |
| 5624 | rt2800_rfcsr_write(rt2x00dev, 54, 0x78); |
| 5625 | rt2800_rfcsr_write(rt2x00dev, 55, 0x43); |
| 5626 | rt2800_rfcsr_write(rt2x00dev, 56, 0x02); |
| 5627 | rt2800_rfcsr_write(rt2x00dev, 57, 0x80); |
| 5628 | rt2800_rfcsr_write(rt2x00dev, 58, 0x7f); |
| 5629 | rt2800_rfcsr_write(rt2x00dev, 59, 0x09); |
| 5630 | rt2800_rfcsr_write(rt2x00dev, 60, 0x45); |
| 5631 | rt2800_rfcsr_write(rt2x00dev, 61, 0xc1); |
Stanislaw Gruszka | f9cdcbb | 2013-04-17 14:08:12 +0200 | [diff] [blame] | 5632 | |
| 5633 | rt2800_rfcsr_read(rt2x00dev, 29, &rfcsr); |
| 5634 | rt2x00_set_field8(&rfcsr, RFCSR29_RSSI_GAIN, 3); |
| 5635 | rt2800_rfcsr_write(rt2x00dev, 29, rfcsr); |
Stanislaw Gruszka | d9517f2 | 2013-04-17 14:08:18 +0200 | [diff] [blame] | 5636 | |
| 5637 | rt2800_led_open_drain_enable(rt2x00dev); |
Stanislaw Gruszka | da8064c | 2013-04-17 14:08:19 +0200 | [diff] [blame] | 5638 | rt2800_normal_mode_setup_3xxx(rt2x00dev); |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 5639 | } |
| 5640 | |
| 5641 | static void rt2800_init_rfcsr_3352(struct rt2x00_dev *rt2x00dev) |
| 5642 | { |
Stanislaw Gruszka | ce94ede9 | 2013-04-17 14:08:11 +0200 | [diff] [blame] | 5643 | rt2800_rf_init_calibration(rt2x00dev, 30); |
| 5644 | |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 5645 | rt2800_rfcsr_write(rt2x00dev, 0, 0xf0); |
| 5646 | rt2800_rfcsr_write(rt2x00dev, 1, 0x23); |
| 5647 | rt2800_rfcsr_write(rt2x00dev, 2, 0x50); |
| 5648 | rt2800_rfcsr_write(rt2x00dev, 3, 0x18); |
| 5649 | rt2800_rfcsr_write(rt2x00dev, 4, 0x00); |
| 5650 | rt2800_rfcsr_write(rt2x00dev, 5, 0x00); |
| 5651 | rt2800_rfcsr_write(rt2x00dev, 6, 0x33); |
| 5652 | rt2800_rfcsr_write(rt2x00dev, 7, 0x00); |
| 5653 | rt2800_rfcsr_write(rt2x00dev, 8, 0xf1); |
| 5654 | rt2800_rfcsr_write(rt2x00dev, 9, 0x02); |
| 5655 | rt2800_rfcsr_write(rt2x00dev, 10, 0xd2); |
| 5656 | rt2800_rfcsr_write(rt2x00dev, 11, 0x42); |
| 5657 | rt2800_rfcsr_write(rt2x00dev, 12, 0x1c); |
| 5658 | rt2800_rfcsr_write(rt2x00dev, 13, 0x00); |
| 5659 | rt2800_rfcsr_write(rt2x00dev, 14, 0x5a); |
| 5660 | rt2800_rfcsr_write(rt2x00dev, 15, 0x00); |
| 5661 | rt2800_rfcsr_write(rt2x00dev, 16, 0x01); |
| 5662 | rt2800_rfcsr_write(rt2x00dev, 18, 0x45); |
| 5663 | rt2800_rfcsr_write(rt2x00dev, 19, 0x02); |
| 5664 | rt2800_rfcsr_write(rt2x00dev, 20, 0x00); |
| 5665 | rt2800_rfcsr_write(rt2x00dev, 21, 0x00); |
| 5666 | rt2800_rfcsr_write(rt2x00dev, 22, 0x00); |
| 5667 | rt2800_rfcsr_write(rt2x00dev, 23, 0x00); |
| 5668 | rt2800_rfcsr_write(rt2x00dev, 24, 0x00); |
| 5669 | rt2800_rfcsr_write(rt2x00dev, 25, 0x80); |
| 5670 | rt2800_rfcsr_write(rt2x00dev, 26, 0x00); |
| 5671 | rt2800_rfcsr_write(rt2x00dev, 27, 0x03); |
| 5672 | rt2800_rfcsr_write(rt2x00dev, 28, 0x03); |
| 5673 | rt2800_rfcsr_write(rt2x00dev, 29, 0x00); |
| 5674 | rt2800_rfcsr_write(rt2x00dev, 30, 0x10); |
| 5675 | rt2800_rfcsr_write(rt2x00dev, 31, 0x80); |
| 5676 | rt2800_rfcsr_write(rt2x00dev, 32, 0x80); |
| 5677 | rt2800_rfcsr_write(rt2x00dev, 33, 0x00); |
| 5678 | rt2800_rfcsr_write(rt2x00dev, 34, 0x01); |
| 5679 | rt2800_rfcsr_write(rt2x00dev, 35, 0x03); |
| 5680 | rt2800_rfcsr_write(rt2x00dev, 36, 0xbd); |
| 5681 | rt2800_rfcsr_write(rt2x00dev, 37, 0x3c); |
| 5682 | rt2800_rfcsr_write(rt2x00dev, 38, 0x5f); |
| 5683 | rt2800_rfcsr_write(rt2x00dev, 39, 0xc5); |
| 5684 | rt2800_rfcsr_write(rt2x00dev, 40, 0x33); |
| 5685 | rt2800_rfcsr_write(rt2x00dev, 41, 0x5b); |
| 5686 | rt2800_rfcsr_write(rt2x00dev, 42, 0x5b); |
| 5687 | rt2800_rfcsr_write(rt2x00dev, 43, 0xdb); |
| 5688 | rt2800_rfcsr_write(rt2x00dev, 44, 0xdb); |
| 5689 | rt2800_rfcsr_write(rt2x00dev, 45, 0xdb); |
| 5690 | rt2800_rfcsr_write(rt2x00dev, 46, 0xdd); |
| 5691 | rt2800_rfcsr_write(rt2x00dev, 47, 0x0d); |
| 5692 | rt2800_rfcsr_write(rt2x00dev, 48, 0x14); |
| 5693 | rt2800_rfcsr_write(rt2x00dev, 49, 0x00); |
| 5694 | rt2800_rfcsr_write(rt2x00dev, 50, 0x2d); |
| 5695 | rt2800_rfcsr_write(rt2x00dev, 51, 0x7f); |
| 5696 | rt2800_rfcsr_write(rt2x00dev, 52, 0x00); |
| 5697 | rt2800_rfcsr_write(rt2x00dev, 53, 0x52); |
| 5698 | rt2800_rfcsr_write(rt2x00dev, 54, 0x1b); |
| 5699 | rt2800_rfcsr_write(rt2x00dev, 55, 0x7f); |
| 5700 | rt2800_rfcsr_write(rt2x00dev, 56, 0x00); |
| 5701 | rt2800_rfcsr_write(rt2x00dev, 57, 0x52); |
| 5702 | rt2800_rfcsr_write(rt2x00dev, 58, 0x1b); |
| 5703 | rt2800_rfcsr_write(rt2x00dev, 59, 0x00); |
| 5704 | rt2800_rfcsr_write(rt2x00dev, 60, 0x00); |
| 5705 | rt2800_rfcsr_write(rt2x00dev, 61, 0x00); |
| 5706 | rt2800_rfcsr_write(rt2x00dev, 62, 0x00); |
| 5707 | rt2800_rfcsr_write(rt2x00dev, 63, 0x00); |
Stanislaw Gruszka | c5b3c35 | 2013-04-17 14:08:16 +0200 | [diff] [blame] | 5708 | |
| 5709 | rt2800_rx_filter_calibration(rt2x00dev); |
Stanislaw Gruszka | d9517f2 | 2013-04-17 14:08:18 +0200 | [diff] [blame] | 5710 | rt2800_led_open_drain_enable(rt2x00dev); |
Stanislaw Gruszka | da8064c | 2013-04-17 14:08:19 +0200 | [diff] [blame] | 5711 | rt2800_normal_mode_setup_3xxx(rt2x00dev); |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 5712 | } |
| 5713 | |
| 5714 | static void rt2800_init_rfcsr_3390(struct rt2x00_dev *rt2x00dev) |
| 5715 | { |
Stanislaw Gruszka | 2971e66 | 2013-04-17 14:08:14 +0200 | [diff] [blame] | 5716 | u32 reg; |
| 5717 | |
Stanislaw Gruszka | ce94ede9 | 2013-04-17 14:08:11 +0200 | [diff] [blame] | 5718 | rt2800_rf_init_calibration(rt2x00dev, 30); |
| 5719 | |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 5720 | rt2800_rfcsr_write(rt2x00dev, 0, 0xa0); |
| 5721 | rt2800_rfcsr_write(rt2x00dev, 1, 0xe1); |
| 5722 | rt2800_rfcsr_write(rt2x00dev, 2, 0xf1); |
| 5723 | rt2800_rfcsr_write(rt2x00dev, 3, 0x62); |
| 5724 | rt2800_rfcsr_write(rt2x00dev, 4, 0x40); |
| 5725 | rt2800_rfcsr_write(rt2x00dev, 5, 0x8b); |
| 5726 | rt2800_rfcsr_write(rt2x00dev, 6, 0x42); |
| 5727 | rt2800_rfcsr_write(rt2x00dev, 7, 0x34); |
| 5728 | rt2800_rfcsr_write(rt2x00dev, 8, 0x00); |
| 5729 | rt2800_rfcsr_write(rt2x00dev, 9, 0xc0); |
| 5730 | rt2800_rfcsr_write(rt2x00dev, 10, 0x61); |
| 5731 | rt2800_rfcsr_write(rt2x00dev, 11, 0x21); |
| 5732 | rt2800_rfcsr_write(rt2x00dev, 12, 0x3b); |
| 5733 | rt2800_rfcsr_write(rt2x00dev, 13, 0xe0); |
| 5734 | rt2800_rfcsr_write(rt2x00dev, 14, 0x90); |
| 5735 | rt2800_rfcsr_write(rt2x00dev, 15, 0x53); |
| 5736 | rt2800_rfcsr_write(rt2x00dev, 16, 0xe0); |
| 5737 | rt2800_rfcsr_write(rt2x00dev, 17, 0x94); |
| 5738 | rt2800_rfcsr_write(rt2x00dev, 18, 0x5c); |
| 5739 | rt2800_rfcsr_write(rt2x00dev, 19, 0x4a); |
| 5740 | rt2800_rfcsr_write(rt2x00dev, 20, 0xb2); |
| 5741 | rt2800_rfcsr_write(rt2x00dev, 21, 0xf6); |
| 5742 | rt2800_rfcsr_write(rt2x00dev, 22, 0x00); |
| 5743 | rt2800_rfcsr_write(rt2x00dev, 23, 0x14); |
| 5744 | rt2800_rfcsr_write(rt2x00dev, 24, 0x08); |
| 5745 | rt2800_rfcsr_write(rt2x00dev, 25, 0x3d); |
| 5746 | rt2800_rfcsr_write(rt2x00dev, 26, 0x85); |
| 5747 | rt2800_rfcsr_write(rt2x00dev, 27, 0x00); |
| 5748 | rt2800_rfcsr_write(rt2x00dev, 28, 0x41); |
| 5749 | rt2800_rfcsr_write(rt2x00dev, 29, 0x8f); |
| 5750 | rt2800_rfcsr_write(rt2x00dev, 30, 0x20); |
| 5751 | rt2800_rfcsr_write(rt2x00dev, 31, 0x0f); |
Stanislaw Gruszka | 2971e66 | 2013-04-17 14:08:14 +0200 | [diff] [blame] | 5752 | |
| 5753 | rt2800_register_read(rt2x00dev, GPIO_SWITCH, ®); |
| 5754 | rt2x00_set_field32(®, GPIO_SWITCH_5, 0); |
| 5755 | rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg); |
Stanislaw Gruszka | c5b3c35 | 2013-04-17 14:08:16 +0200 | [diff] [blame] | 5756 | |
| 5757 | rt2800_rx_filter_calibration(rt2x00dev); |
Stanislaw Gruszka | 5de5a1f | 2013-04-17 14:08:17 +0200 | [diff] [blame] | 5758 | |
| 5759 | if (rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) |
| 5760 | rt2800_rfcsr_write(rt2x00dev, 27, 0x03); |
Stanislaw Gruszka | d9517f2 | 2013-04-17 14:08:18 +0200 | [diff] [blame] | 5761 | |
| 5762 | rt2800_led_open_drain_enable(rt2x00dev); |
Stanislaw Gruszka | da8064c | 2013-04-17 14:08:19 +0200 | [diff] [blame] | 5763 | rt2800_normal_mode_setup_3xxx(rt2x00dev); |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 5764 | } |
| 5765 | |
| 5766 | static void rt2800_init_rfcsr_3572(struct rt2x00_dev *rt2x00dev) |
| 5767 | { |
Stanislaw Gruszka | 87d91db | 2013-04-17 14:08:15 +0200 | [diff] [blame] | 5768 | u8 rfcsr; |
| 5769 | u32 reg; |
| 5770 | |
Stanislaw Gruszka | ce94ede9 | 2013-04-17 14:08:11 +0200 | [diff] [blame] | 5771 | rt2800_rf_init_calibration(rt2x00dev, 30); |
| 5772 | |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 5773 | rt2800_rfcsr_write(rt2x00dev, 0, 0x70); |
| 5774 | rt2800_rfcsr_write(rt2x00dev, 1, 0x81); |
| 5775 | rt2800_rfcsr_write(rt2x00dev, 2, 0xf1); |
| 5776 | rt2800_rfcsr_write(rt2x00dev, 3, 0x02); |
| 5777 | rt2800_rfcsr_write(rt2x00dev, 4, 0x4c); |
| 5778 | rt2800_rfcsr_write(rt2x00dev, 5, 0x05); |
| 5779 | rt2800_rfcsr_write(rt2x00dev, 6, 0x4a); |
| 5780 | rt2800_rfcsr_write(rt2x00dev, 7, 0xd8); |
| 5781 | rt2800_rfcsr_write(rt2x00dev, 9, 0xc3); |
| 5782 | rt2800_rfcsr_write(rt2x00dev, 10, 0xf1); |
| 5783 | rt2800_rfcsr_write(rt2x00dev, 11, 0xb9); |
| 5784 | rt2800_rfcsr_write(rt2x00dev, 12, 0x70); |
| 5785 | rt2800_rfcsr_write(rt2x00dev, 13, 0x65); |
| 5786 | rt2800_rfcsr_write(rt2x00dev, 14, 0xa0); |
| 5787 | rt2800_rfcsr_write(rt2x00dev, 15, 0x53); |
| 5788 | rt2800_rfcsr_write(rt2x00dev, 16, 0x4c); |
| 5789 | rt2800_rfcsr_write(rt2x00dev, 17, 0x23); |
| 5790 | rt2800_rfcsr_write(rt2x00dev, 18, 0xac); |
| 5791 | rt2800_rfcsr_write(rt2x00dev, 19, 0x93); |
| 5792 | rt2800_rfcsr_write(rt2x00dev, 20, 0xb3); |
| 5793 | rt2800_rfcsr_write(rt2x00dev, 21, 0xd0); |
| 5794 | rt2800_rfcsr_write(rt2x00dev, 22, 0x00); |
| 5795 | rt2800_rfcsr_write(rt2x00dev, 23, 0x3c); |
| 5796 | rt2800_rfcsr_write(rt2x00dev, 24, 0x16); |
| 5797 | rt2800_rfcsr_write(rt2x00dev, 25, 0x15); |
| 5798 | rt2800_rfcsr_write(rt2x00dev, 26, 0x85); |
| 5799 | rt2800_rfcsr_write(rt2x00dev, 27, 0x00); |
| 5800 | rt2800_rfcsr_write(rt2x00dev, 28, 0x00); |
| 5801 | rt2800_rfcsr_write(rt2x00dev, 29, 0x9b); |
| 5802 | rt2800_rfcsr_write(rt2x00dev, 30, 0x09); |
| 5803 | rt2800_rfcsr_write(rt2x00dev, 31, 0x10); |
Stanislaw Gruszka | 87d91db | 2013-04-17 14:08:15 +0200 | [diff] [blame] | 5804 | |
| 5805 | rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr); |
| 5806 | rt2x00_set_field8(&rfcsr, RFCSR6_R2, 1); |
| 5807 | rt2800_rfcsr_write(rt2x00dev, 6, rfcsr); |
| 5808 | |
| 5809 | rt2800_register_read(rt2x00dev, LDO_CFG0, ®); |
| 5810 | rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 3); |
| 5811 | rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1); |
| 5812 | rt2800_register_write(rt2x00dev, LDO_CFG0, reg); |
| 5813 | msleep(1); |
| 5814 | rt2800_register_read(rt2x00dev, LDO_CFG0, ®); |
| 5815 | rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 0); |
| 5816 | rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1); |
| 5817 | rt2800_register_write(rt2x00dev, LDO_CFG0, reg); |
Stanislaw Gruszka | c5b3c35 | 2013-04-17 14:08:16 +0200 | [diff] [blame] | 5818 | |
| 5819 | rt2800_rx_filter_calibration(rt2x00dev); |
Stanislaw Gruszka | d9517f2 | 2013-04-17 14:08:18 +0200 | [diff] [blame] | 5820 | rt2800_led_open_drain_enable(rt2x00dev); |
Stanislaw Gruszka | da8064c | 2013-04-17 14:08:19 +0200 | [diff] [blame] | 5821 | rt2800_normal_mode_setup_3xxx(rt2x00dev); |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 5822 | } |
| 5823 | |
Gabor Juhos | d63f7e8 | 2013-07-08 16:08:19 +0200 | [diff] [blame] | 5824 | static void rt3593_post_bbp_init(struct rt2x00_dev *rt2x00dev) |
| 5825 | { |
| 5826 | u8 bbp; |
| 5827 | bool txbf_enabled = false; /* FIXME */ |
| 5828 | |
| 5829 | rt2800_bbp_read(rt2x00dev, 105, &bbp); |
| 5830 | if (rt2x00dev->default_ant.rx_chain_num == 1) |
| 5831 | rt2x00_set_field8(&bbp, BBP105_MLD, 0); |
| 5832 | else |
| 5833 | rt2x00_set_field8(&bbp, BBP105_MLD, 1); |
| 5834 | rt2800_bbp_write(rt2x00dev, 105, bbp); |
| 5835 | |
| 5836 | rt2800_bbp4_mac_if_ctrl(rt2x00dev); |
| 5837 | |
| 5838 | rt2800_bbp_write(rt2x00dev, 92, 0x02); |
| 5839 | rt2800_bbp_write(rt2x00dev, 82, 0x82); |
| 5840 | rt2800_bbp_write(rt2x00dev, 106, 0x05); |
| 5841 | rt2800_bbp_write(rt2x00dev, 104, 0x92); |
| 5842 | rt2800_bbp_write(rt2x00dev, 88, 0x90); |
| 5843 | rt2800_bbp_write(rt2x00dev, 148, 0xc8); |
| 5844 | rt2800_bbp_write(rt2x00dev, 47, 0x48); |
| 5845 | rt2800_bbp_write(rt2x00dev, 120, 0x50); |
| 5846 | |
| 5847 | if (txbf_enabled) |
| 5848 | rt2800_bbp_write(rt2x00dev, 163, 0xbd); |
| 5849 | else |
| 5850 | rt2800_bbp_write(rt2x00dev, 163, 0x9d); |
| 5851 | |
| 5852 | /* SNR mapping */ |
| 5853 | rt2800_bbp_write(rt2x00dev, 142, 6); |
| 5854 | rt2800_bbp_write(rt2x00dev, 143, 160); |
| 5855 | rt2800_bbp_write(rt2x00dev, 142, 7); |
| 5856 | rt2800_bbp_write(rt2x00dev, 143, 161); |
| 5857 | rt2800_bbp_write(rt2x00dev, 142, 8); |
| 5858 | rt2800_bbp_write(rt2x00dev, 143, 162); |
| 5859 | |
| 5860 | /* ADC/DAC control */ |
| 5861 | rt2800_bbp_write(rt2x00dev, 31, 0x08); |
| 5862 | |
| 5863 | /* RX AGC energy lower bound in log2 */ |
| 5864 | rt2800_bbp_write(rt2x00dev, 68, 0x0b); |
| 5865 | |
| 5866 | /* FIXME: BBP 105 owerwrite? */ |
| 5867 | rt2800_bbp_write(rt2x00dev, 105, 0x04); |
| 5868 | } |
| 5869 | |
Gabor Juhos | ab7078a | 2013-07-08 16:08:18 +0200 | [diff] [blame] | 5870 | static void rt2800_init_rfcsr_3593(struct rt2x00_dev *rt2x00dev) |
| 5871 | { |
| 5872 | struct rt2800_drv_data *drv_data = rt2x00dev->drv_data; |
| 5873 | u32 reg; |
| 5874 | u8 rfcsr; |
| 5875 | |
| 5876 | /* Disable GPIO #4 and #7 function for LAN PE control */ |
| 5877 | rt2800_register_read(rt2x00dev, GPIO_SWITCH, ®); |
| 5878 | rt2x00_set_field32(®, GPIO_SWITCH_4, 0); |
| 5879 | rt2x00_set_field32(®, GPIO_SWITCH_7, 0); |
| 5880 | rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg); |
| 5881 | |
| 5882 | /* Initialize default register values */ |
| 5883 | rt2800_rfcsr_write(rt2x00dev, 1, 0x03); |
| 5884 | rt2800_rfcsr_write(rt2x00dev, 3, 0x80); |
| 5885 | rt2800_rfcsr_write(rt2x00dev, 5, 0x00); |
| 5886 | rt2800_rfcsr_write(rt2x00dev, 6, 0x40); |
| 5887 | rt2800_rfcsr_write(rt2x00dev, 8, 0xf1); |
| 5888 | rt2800_rfcsr_write(rt2x00dev, 9, 0x02); |
| 5889 | rt2800_rfcsr_write(rt2x00dev, 10, 0xd3); |
| 5890 | rt2800_rfcsr_write(rt2x00dev, 11, 0x40); |
| 5891 | rt2800_rfcsr_write(rt2x00dev, 12, 0x4e); |
| 5892 | rt2800_rfcsr_write(rt2x00dev, 13, 0x12); |
| 5893 | rt2800_rfcsr_write(rt2x00dev, 18, 0x40); |
| 5894 | rt2800_rfcsr_write(rt2x00dev, 22, 0x20); |
| 5895 | rt2800_rfcsr_write(rt2x00dev, 30, 0x10); |
| 5896 | rt2800_rfcsr_write(rt2x00dev, 31, 0x80); |
| 5897 | rt2800_rfcsr_write(rt2x00dev, 32, 0x78); |
| 5898 | rt2800_rfcsr_write(rt2x00dev, 33, 0x3b); |
| 5899 | rt2800_rfcsr_write(rt2x00dev, 34, 0x3c); |
| 5900 | rt2800_rfcsr_write(rt2x00dev, 35, 0xe0); |
| 5901 | rt2800_rfcsr_write(rt2x00dev, 38, 0x86); |
| 5902 | rt2800_rfcsr_write(rt2x00dev, 39, 0x23); |
| 5903 | rt2800_rfcsr_write(rt2x00dev, 44, 0xd3); |
| 5904 | rt2800_rfcsr_write(rt2x00dev, 45, 0xbb); |
| 5905 | rt2800_rfcsr_write(rt2x00dev, 46, 0x60); |
| 5906 | rt2800_rfcsr_write(rt2x00dev, 49, 0x8e); |
| 5907 | rt2800_rfcsr_write(rt2x00dev, 50, 0x86); |
| 5908 | rt2800_rfcsr_write(rt2x00dev, 51, 0x75); |
| 5909 | rt2800_rfcsr_write(rt2x00dev, 52, 0x45); |
| 5910 | rt2800_rfcsr_write(rt2x00dev, 53, 0x18); |
| 5911 | rt2800_rfcsr_write(rt2x00dev, 54, 0x18); |
| 5912 | rt2800_rfcsr_write(rt2x00dev, 55, 0x18); |
| 5913 | rt2800_rfcsr_write(rt2x00dev, 56, 0xdb); |
| 5914 | rt2800_rfcsr_write(rt2x00dev, 57, 0x6e); |
| 5915 | |
| 5916 | /* Initiate calibration */ |
| 5917 | /* TODO: use rt2800_rf_init_calibration ? */ |
| 5918 | rt2800_rfcsr_read(rt2x00dev, 2, &rfcsr); |
| 5919 | rt2x00_set_field8(&rfcsr, RFCSR2_RESCAL_EN, 1); |
| 5920 | rt2800_rfcsr_write(rt2x00dev, 2, rfcsr); |
| 5921 | |
| 5922 | rt2800_adjust_freq_offset(rt2x00dev); |
| 5923 | |
| 5924 | rt2800_rfcsr_read(rt2x00dev, 18, &rfcsr); |
| 5925 | rt2x00_set_field8(&rfcsr, RFCSR18_XO_TUNE_BYPASS, 1); |
| 5926 | rt2800_rfcsr_write(rt2x00dev, 18, rfcsr); |
| 5927 | |
| 5928 | rt2800_register_read(rt2x00dev, LDO_CFG0, ®); |
| 5929 | rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 3); |
| 5930 | rt2x00_set_field32(®, LDO_CFG0_BGSEL, 1); |
| 5931 | rt2800_register_write(rt2x00dev, LDO_CFG0, reg); |
| 5932 | usleep_range(1000, 1500); |
| 5933 | rt2800_register_read(rt2x00dev, LDO_CFG0, ®); |
| 5934 | rt2x00_set_field32(®, LDO_CFG0_LDO_CORE_VLEVEL, 0); |
| 5935 | rt2800_register_write(rt2x00dev, LDO_CFG0, reg); |
| 5936 | |
| 5937 | /* Set initial values for RX filter calibration */ |
| 5938 | drv_data->calibration_bw20 = 0x1f; |
| 5939 | drv_data->calibration_bw40 = 0x2f; |
| 5940 | |
| 5941 | /* Save BBP 25 & 26 values for later use in channel switching */ |
| 5942 | rt2800_bbp_read(rt2x00dev, 25, &drv_data->bbp25); |
| 5943 | rt2800_bbp_read(rt2x00dev, 26, &drv_data->bbp26); |
| 5944 | |
| 5945 | rt2800_led_open_drain_enable(rt2x00dev); |
| 5946 | rt2800_normal_mode_setup_3593(rt2x00dev); |
| 5947 | |
Gabor Juhos | d63f7e8 | 2013-07-08 16:08:19 +0200 | [diff] [blame] | 5948 | rt3593_post_bbp_init(rt2x00dev); |
Gabor Juhos | ab7078a | 2013-07-08 16:08:18 +0200 | [diff] [blame] | 5949 | |
| 5950 | /* TODO: enable stream mode support */ |
| 5951 | } |
| 5952 | |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 5953 | static void rt2800_init_rfcsr_5390(struct rt2x00_dev *rt2x00dev) |
| 5954 | { |
Stanislaw Gruszka | ce94ede9 | 2013-04-17 14:08:11 +0200 | [diff] [blame] | 5955 | rt2800_rf_init_calibration(rt2x00dev, 2); |
| 5956 | |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 5957 | rt2800_rfcsr_write(rt2x00dev, 1, 0x0f); |
| 5958 | rt2800_rfcsr_write(rt2x00dev, 2, 0x80); |
| 5959 | rt2800_rfcsr_write(rt2x00dev, 3, 0x88); |
| 5960 | rt2800_rfcsr_write(rt2x00dev, 5, 0x10); |
| 5961 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) |
| 5962 | rt2800_rfcsr_write(rt2x00dev, 6, 0xe0); |
| 5963 | else |
| 5964 | rt2800_rfcsr_write(rt2x00dev, 6, 0xa0); |
| 5965 | rt2800_rfcsr_write(rt2x00dev, 7, 0x00); |
| 5966 | rt2800_rfcsr_write(rt2x00dev, 10, 0x53); |
| 5967 | rt2800_rfcsr_write(rt2x00dev, 11, 0x4a); |
| 5968 | rt2800_rfcsr_write(rt2x00dev, 12, 0xc6); |
| 5969 | rt2800_rfcsr_write(rt2x00dev, 13, 0x9f); |
| 5970 | rt2800_rfcsr_write(rt2x00dev, 14, 0x00); |
| 5971 | rt2800_rfcsr_write(rt2x00dev, 15, 0x00); |
| 5972 | rt2800_rfcsr_write(rt2x00dev, 16, 0x00); |
| 5973 | rt2800_rfcsr_write(rt2x00dev, 18, 0x03); |
| 5974 | rt2800_rfcsr_write(rt2x00dev, 19, 0x00); |
| 5975 | |
| 5976 | rt2800_rfcsr_write(rt2x00dev, 20, 0x00); |
| 5977 | rt2800_rfcsr_write(rt2x00dev, 21, 0x00); |
| 5978 | rt2800_rfcsr_write(rt2x00dev, 22, 0x20); |
| 5979 | rt2800_rfcsr_write(rt2x00dev, 23, 0x00); |
| 5980 | rt2800_rfcsr_write(rt2x00dev, 24, 0x00); |
| 5981 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) |
| 5982 | rt2800_rfcsr_write(rt2x00dev, 25, 0x80); |
| 5983 | else |
| 5984 | rt2800_rfcsr_write(rt2x00dev, 25, 0xc0); |
| 5985 | rt2800_rfcsr_write(rt2x00dev, 26, 0x00); |
| 5986 | rt2800_rfcsr_write(rt2x00dev, 27, 0x09); |
| 5987 | rt2800_rfcsr_write(rt2x00dev, 28, 0x00); |
| 5988 | rt2800_rfcsr_write(rt2x00dev, 29, 0x10); |
| 5989 | |
| 5990 | rt2800_rfcsr_write(rt2x00dev, 30, 0x00); |
| 5991 | rt2800_rfcsr_write(rt2x00dev, 31, 0x80); |
| 5992 | rt2800_rfcsr_write(rt2x00dev, 32, 0x80); |
| 5993 | rt2800_rfcsr_write(rt2x00dev, 33, 0x00); |
| 5994 | rt2800_rfcsr_write(rt2x00dev, 34, 0x07); |
| 5995 | rt2800_rfcsr_write(rt2x00dev, 35, 0x12); |
| 5996 | rt2800_rfcsr_write(rt2x00dev, 36, 0x00); |
| 5997 | rt2800_rfcsr_write(rt2x00dev, 37, 0x08); |
| 5998 | rt2800_rfcsr_write(rt2x00dev, 38, 0x85); |
| 5999 | rt2800_rfcsr_write(rt2x00dev, 39, 0x1b); |
| 6000 | |
| 6001 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) |
| 6002 | rt2800_rfcsr_write(rt2x00dev, 40, 0x0b); |
| 6003 | else |
| 6004 | rt2800_rfcsr_write(rt2x00dev, 40, 0x4b); |
| 6005 | rt2800_rfcsr_write(rt2x00dev, 41, 0xbb); |
| 6006 | rt2800_rfcsr_write(rt2x00dev, 42, 0xd2); |
| 6007 | rt2800_rfcsr_write(rt2x00dev, 43, 0x9a); |
| 6008 | rt2800_rfcsr_write(rt2x00dev, 44, 0x0e); |
| 6009 | rt2800_rfcsr_write(rt2x00dev, 45, 0xa2); |
| 6010 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) |
| 6011 | rt2800_rfcsr_write(rt2x00dev, 46, 0x73); |
| 6012 | else |
| 6013 | rt2800_rfcsr_write(rt2x00dev, 46, 0x7b); |
| 6014 | rt2800_rfcsr_write(rt2x00dev, 47, 0x00); |
| 6015 | rt2800_rfcsr_write(rt2x00dev, 48, 0x10); |
| 6016 | rt2800_rfcsr_write(rt2x00dev, 49, 0x94); |
| 6017 | |
| 6018 | rt2800_rfcsr_write(rt2x00dev, 52, 0x38); |
| 6019 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) |
| 6020 | rt2800_rfcsr_write(rt2x00dev, 53, 0x00); |
| 6021 | else |
| 6022 | rt2800_rfcsr_write(rt2x00dev, 53, 0x84); |
| 6023 | rt2800_rfcsr_write(rt2x00dev, 54, 0x78); |
| 6024 | rt2800_rfcsr_write(rt2x00dev, 55, 0x44); |
| 6025 | rt2800_rfcsr_write(rt2x00dev, 56, 0x22); |
| 6026 | rt2800_rfcsr_write(rt2x00dev, 57, 0x80); |
| 6027 | rt2800_rfcsr_write(rt2x00dev, 58, 0x7f); |
| 6028 | rt2800_rfcsr_write(rt2x00dev, 59, 0x63); |
| 6029 | |
| 6030 | rt2800_rfcsr_write(rt2x00dev, 60, 0x45); |
| 6031 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) |
| 6032 | rt2800_rfcsr_write(rt2x00dev, 61, 0xd1); |
| 6033 | else |
| 6034 | rt2800_rfcsr_write(rt2x00dev, 61, 0xdd); |
| 6035 | rt2800_rfcsr_write(rt2x00dev, 62, 0x00); |
| 6036 | rt2800_rfcsr_write(rt2x00dev, 63, 0x00); |
Stanislaw Gruszka | f7df8fe | 2013-04-17 14:08:10 +0200 | [diff] [blame] | 6037 | |
| 6038 | rt2800_normal_mode_setup_5xxx(rt2x00dev); |
Stanislaw Gruszka | d9517f2 | 2013-04-17 14:08:18 +0200 | [diff] [blame] | 6039 | |
| 6040 | rt2800_led_open_drain_enable(rt2x00dev); |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6041 | } |
| 6042 | |
| 6043 | static void rt2800_init_rfcsr_5392(struct rt2x00_dev *rt2x00dev) |
| 6044 | { |
Stanislaw Gruszka | ce94ede9 | 2013-04-17 14:08:11 +0200 | [diff] [blame] | 6045 | rt2800_rf_init_calibration(rt2x00dev, 2); |
| 6046 | |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6047 | rt2800_rfcsr_write(rt2x00dev, 1, 0x17); |
| 6048 | rt2800_rfcsr_write(rt2x00dev, 2, 0x80); |
| 6049 | rt2800_rfcsr_write(rt2x00dev, 3, 0x88); |
| 6050 | rt2800_rfcsr_write(rt2x00dev, 5, 0x10); |
| 6051 | rt2800_rfcsr_write(rt2x00dev, 6, 0xe0); |
| 6052 | rt2800_rfcsr_write(rt2x00dev, 7, 0x00); |
| 6053 | rt2800_rfcsr_write(rt2x00dev, 10, 0x53); |
| 6054 | rt2800_rfcsr_write(rt2x00dev, 11, 0x4a); |
| 6055 | rt2800_rfcsr_write(rt2x00dev, 12, 0x46); |
| 6056 | rt2800_rfcsr_write(rt2x00dev, 13, 0x9f); |
| 6057 | rt2800_rfcsr_write(rt2x00dev, 14, 0x00); |
| 6058 | rt2800_rfcsr_write(rt2x00dev, 15, 0x00); |
| 6059 | rt2800_rfcsr_write(rt2x00dev, 16, 0x00); |
| 6060 | rt2800_rfcsr_write(rt2x00dev, 18, 0x03); |
| 6061 | rt2800_rfcsr_write(rt2x00dev, 19, 0x4d); |
| 6062 | rt2800_rfcsr_write(rt2x00dev, 20, 0x00); |
| 6063 | rt2800_rfcsr_write(rt2x00dev, 21, 0x8d); |
| 6064 | rt2800_rfcsr_write(rt2x00dev, 22, 0x20); |
| 6065 | rt2800_rfcsr_write(rt2x00dev, 23, 0x0b); |
| 6066 | rt2800_rfcsr_write(rt2x00dev, 24, 0x44); |
| 6067 | rt2800_rfcsr_write(rt2x00dev, 25, 0x80); |
| 6068 | rt2800_rfcsr_write(rt2x00dev, 26, 0x82); |
| 6069 | rt2800_rfcsr_write(rt2x00dev, 27, 0x09); |
| 6070 | rt2800_rfcsr_write(rt2x00dev, 28, 0x00); |
| 6071 | rt2800_rfcsr_write(rt2x00dev, 29, 0x10); |
| 6072 | rt2800_rfcsr_write(rt2x00dev, 30, 0x10); |
| 6073 | rt2800_rfcsr_write(rt2x00dev, 31, 0x80); |
| 6074 | rt2800_rfcsr_write(rt2x00dev, 32, 0x20); |
| 6075 | rt2800_rfcsr_write(rt2x00dev, 33, 0xC0); |
| 6076 | rt2800_rfcsr_write(rt2x00dev, 34, 0x07); |
| 6077 | rt2800_rfcsr_write(rt2x00dev, 35, 0x12); |
| 6078 | rt2800_rfcsr_write(rt2x00dev, 36, 0x00); |
| 6079 | rt2800_rfcsr_write(rt2x00dev, 37, 0x08); |
| 6080 | rt2800_rfcsr_write(rt2x00dev, 38, 0x89); |
| 6081 | rt2800_rfcsr_write(rt2x00dev, 39, 0x1b); |
| 6082 | rt2800_rfcsr_write(rt2x00dev, 40, 0x0f); |
| 6083 | rt2800_rfcsr_write(rt2x00dev, 41, 0xbb); |
| 6084 | rt2800_rfcsr_write(rt2x00dev, 42, 0xd5); |
| 6085 | rt2800_rfcsr_write(rt2x00dev, 43, 0x9b); |
| 6086 | rt2800_rfcsr_write(rt2x00dev, 44, 0x0e); |
| 6087 | rt2800_rfcsr_write(rt2x00dev, 45, 0xa2); |
| 6088 | rt2800_rfcsr_write(rt2x00dev, 46, 0x73); |
| 6089 | rt2800_rfcsr_write(rt2x00dev, 47, 0x0c); |
| 6090 | rt2800_rfcsr_write(rt2x00dev, 48, 0x10); |
| 6091 | rt2800_rfcsr_write(rt2x00dev, 49, 0x94); |
| 6092 | rt2800_rfcsr_write(rt2x00dev, 50, 0x94); |
| 6093 | rt2800_rfcsr_write(rt2x00dev, 51, 0x3a); |
| 6094 | rt2800_rfcsr_write(rt2x00dev, 52, 0x48); |
| 6095 | rt2800_rfcsr_write(rt2x00dev, 53, 0x44); |
| 6096 | rt2800_rfcsr_write(rt2x00dev, 54, 0x38); |
| 6097 | rt2800_rfcsr_write(rt2x00dev, 55, 0x43); |
| 6098 | rt2800_rfcsr_write(rt2x00dev, 56, 0xa1); |
| 6099 | rt2800_rfcsr_write(rt2x00dev, 57, 0x00); |
| 6100 | rt2800_rfcsr_write(rt2x00dev, 58, 0x39); |
| 6101 | rt2800_rfcsr_write(rt2x00dev, 59, 0x07); |
| 6102 | rt2800_rfcsr_write(rt2x00dev, 60, 0x45); |
| 6103 | rt2800_rfcsr_write(rt2x00dev, 61, 0x91); |
| 6104 | rt2800_rfcsr_write(rt2x00dev, 62, 0x39); |
| 6105 | rt2800_rfcsr_write(rt2x00dev, 63, 0x07); |
Stanislaw Gruszka | f7df8fe | 2013-04-17 14:08:10 +0200 | [diff] [blame] | 6106 | |
| 6107 | rt2800_normal_mode_setup_5xxx(rt2x00dev); |
Stanislaw Gruszka | d9517f2 | 2013-04-17 14:08:18 +0200 | [diff] [blame] | 6108 | |
| 6109 | rt2800_led_open_drain_enable(rt2x00dev); |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6110 | } |
| 6111 | |
Stanislaw Gruszka | 0c9e5fb | 2013-03-16 19:19:36 +0100 | [diff] [blame] | 6112 | static void rt2800_init_rfcsr_5592(struct rt2x00_dev *rt2x00dev) |
| 6113 | { |
Stanislaw Gruszka | ce94ede9 | 2013-04-17 14:08:11 +0200 | [diff] [blame] | 6114 | rt2800_rf_init_calibration(rt2x00dev, 30); |
| 6115 | |
Stanislaw Gruszka | 0c9e5fb | 2013-03-16 19:19:36 +0100 | [diff] [blame] | 6116 | rt2800_rfcsr_write(rt2x00dev, 1, 0x3F); |
| 6117 | rt2800_rfcsr_write(rt2x00dev, 3, 0x08); |
| 6118 | rt2800_rfcsr_write(rt2x00dev, 3, 0x08); |
| 6119 | rt2800_rfcsr_write(rt2x00dev, 5, 0x10); |
| 6120 | rt2800_rfcsr_write(rt2x00dev, 6, 0xE4); |
| 6121 | rt2800_rfcsr_write(rt2x00dev, 7, 0x00); |
| 6122 | rt2800_rfcsr_write(rt2x00dev, 14, 0x00); |
| 6123 | rt2800_rfcsr_write(rt2x00dev, 15, 0x00); |
| 6124 | rt2800_rfcsr_write(rt2x00dev, 16, 0x00); |
| 6125 | rt2800_rfcsr_write(rt2x00dev, 18, 0x03); |
| 6126 | rt2800_rfcsr_write(rt2x00dev, 19, 0x4D); |
| 6127 | rt2800_rfcsr_write(rt2x00dev, 20, 0x10); |
| 6128 | rt2800_rfcsr_write(rt2x00dev, 21, 0x8D); |
| 6129 | rt2800_rfcsr_write(rt2x00dev, 26, 0x82); |
| 6130 | rt2800_rfcsr_write(rt2x00dev, 28, 0x00); |
| 6131 | rt2800_rfcsr_write(rt2x00dev, 29, 0x10); |
| 6132 | rt2800_rfcsr_write(rt2x00dev, 33, 0xC0); |
| 6133 | rt2800_rfcsr_write(rt2x00dev, 34, 0x07); |
| 6134 | rt2800_rfcsr_write(rt2x00dev, 35, 0x12); |
| 6135 | rt2800_rfcsr_write(rt2x00dev, 47, 0x0C); |
| 6136 | rt2800_rfcsr_write(rt2x00dev, 53, 0x22); |
| 6137 | rt2800_rfcsr_write(rt2x00dev, 63, 0x07); |
| 6138 | |
| 6139 | rt2800_rfcsr_write(rt2x00dev, 2, 0x80); |
| 6140 | msleep(1); |
| 6141 | |
| 6142 | rt2800_adjust_freq_offset(rt2x00dev); |
Stanislaw Gruszka | c630ccf | 2013-03-16 19:19:46 +0100 | [diff] [blame] | 6143 | |
Stanislaw Gruszka | c630ccf | 2013-03-16 19:19:46 +0100 | [diff] [blame] | 6144 | /* Enable DC filter */ |
| 6145 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5592, REV_RT5592C)) |
| 6146 | rt2800_bbp_write(rt2x00dev, 103, 0xc0); |
| 6147 | |
Stanislaw Gruszka | f7df8fe | 2013-04-17 14:08:10 +0200 | [diff] [blame] | 6148 | rt2800_normal_mode_setup_5xxx(rt2x00dev); |
Stanislaw Gruszka | 5de5a1f | 2013-04-17 14:08:17 +0200 | [diff] [blame] | 6149 | |
| 6150 | if (rt2x00_rt_rev_lt(rt2x00dev, RT5592, REV_RT5592C)) |
| 6151 | rt2800_rfcsr_write(rt2x00dev, 27, 0x03); |
Stanislaw Gruszka | d9517f2 | 2013-04-17 14:08:18 +0200 | [diff] [blame] | 6152 | |
| 6153 | rt2800_led_open_drain_enable(rt2x00dev); |
Stanislaw Gruszka | 0c9e5fb | 2013-03-16 19:19:36 +0100 | [diff] [blame] | 6154 | } |
| 6155 | |
Stanislaw Gruszka | 074f252 | 2013-04-17 14:08:20 +0200 | [diff] [blame] | 6156 | static void rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev) |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 6157 | { |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6158 | if (rt2800_is_305x_soc(rt2x00dev)) { |
| 6159 | rt2800_init_rfcsr_305x_soc(rt2x00dev); |
Stanislaw Gruszka | 074f252 | 2013-04-17 14:08:20 +0200 | [diff] [blame] | 6160 | return; |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6161 | } |
RA-Shiang Tu | 60687ba | 2011-02-20 13:57:46 +0100 | [diff] [blame] | 6162 | |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6163 | switch (rt2x00dev->chip.rt) { |
| 6164 | case RT3070: |
| 6165 | case RT3071: |
| 6166 | case RT3090: |
| 6167 | rt2800_init_rfcsr_30xx(rt2x00dev); |
| 6168 | break; |
| 6169 | case RT3290: |
| 6170 | rt2800_init_rfcsr_3290(rt2x00dev); |
| 6171 | break; |
| 6172 | case RT3352: |
| 6173 | rt2800_init_rfcsr_3352(rt2x00dev); |
| 6174 | break; |
| 6175 | case RT3390: |
| 6176 | rt2800_init_rfcsr_3390(rt2x00dev); |
| 6177 | break; |
| 6178 | case RT3572: |
| 6179 | rt2800_init_rfcsr_3572(rt2x00dev); |
| 6180 | break; |
Gabor Juhos | ab7078a | 2013-07-08 16:08:18 +0200 | [diff] [blame] | 6181 | case RT3593: |
| 6182 | rt2800_init_rfcsr_3593(rt2x00dev); |
| 6183 | break; |
Stanislaw Gruszka | d5374ef | 2012-12-12 06:30:55 +0100 | [diff] [blame] | 6184 | case RT5390: |
| 6185 | rt2800_init_rfcsr_5390(rt2x00dev); |
| 6186 | break; |
| 6187 | case RT5392: |
| 6188 | rt2800_init_rfcsr_5392(rt2x00dev); |
| 6189 | break; |
Stanislaw Gruszka | 0c9e5fb | 2013-03-16 19:19:36 +0100 | [diff] [blame] | 6190 | case RT5592: |
| 6191 | rt2800_init_rfcsr_5592(rt2x00dev); |
Stanislaw Gruszka | 074f252 | 2013-04-17 14:08:20 +0200 | [diff] [blame] | 6192 | break; |
Gertjan van Wingerde | 8cdd15e | 2010-04-11 14:31:12 +0200 | [diff] [blame] | 6193 | } |
Bartlomiej Zolnierkiewicz | fcf5154 | 2009-11-04 18:36:57 +0100 | [diff] [blame] | 6194 | } |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 6195 | |
| 6196 | int rt2800_enable_radio(struct rt2x00_dev *rt2x00dev) |
| 6197 | { |
| 6198 | u32 reg; |
| 6199 | u16 word; |
| 6200 | |
| 6201 | /* |
| 6202 | * Initialize all registers. |
| 6203 | */ |
| 6204 | if (unlikely(rt2800_wait_wpdma_ready(rt2x00dev) || |
Stanislaw Gruszka | c630ccf | 2013-03-16 19:19:46 +0100 | [diff] [blame] | 6205 | rt2800_init_registers(rt2x00dev))) |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 6206 | return -EIO; |
| 6207 | |
| 6208 | /* |
| 6209 | * Send signal to firmware during boot time. |
| 6210 | */ |
Stanislaw Gruszka | c630ccf | 2013-03-16 19:19:46 +0100 | [diff] [blame] | 6211 | rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0); |
| 6212 | rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0); |
| 6213 | if (rt2x00_is_usb(rt2x00dev)) { |
| 6214 | rt2800_register_write(rt2x00dev, H2M_INT_SRC, 0); |
| 6215 | rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0, 0, 0); |
| 6216 | } |
| 6217 | msleep(1); |
| 6218 | |
Stanislaw Gruszka | a1ef5039 | 2013-05-18 14:03:24 +0200 | [diff] [blame] | 6219 | if (unlikely(rt2800_wait_bbp_rf_ready(rt2x00dev) || |
| 6220 | rt2800_wait_bbp_ready(rt2x00dev))) |
Stanislaw Gruszka | c630ccf | 2013-03-16 19:19:46 +0100 | [diff] [blame] | 6221 | return -EIO; |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 6222 | |
Stanislaw Gruszka | a1ef5039 | 2013-05-18 14:03:24 +0200 | [diff] [blame] | 6223 | rt2800_init_bbp(rt2x00dev); |
Stanislaw Gruszka | 074f252 | 2013-04-17 14:08:20 +0200 | [diff] [blame] | 6224 | rt2800_init_rfcsr(rt2x00dev); |
| 6225 | |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 6226 | if (rt2x00_is_usb(rt2x00dev) && |
| 6227 | (rt2x00_rt(rt2x00dev, RT3070) || |
| 6228 | rt2x00_rt(rt2x00dev, RT3071) || |
| 6229 | rt2x00_rt(rt2x00dev, RT3572))) { |
| 6230 | udelay(200); |
| 6231 | rt2800_mcu_request(rt2x00dev, MCU_CURRENT, 0, 0, 0); |
| 6232 | udelay(10); |
| 6233 | } |
| 6234 | |
| 6235 | /* |
| 6236 | * Enable RX. |
| 6237 | */ |
| 6238 | rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, ®); |
| 6239 | rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_TX, 1); |
| 6240 | rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, 0); |
| 6241 | rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg); |
| 6242 | |
| 6243 | udelay(50); |
| 6244 | |
| 6245 | rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®); |
| 6246 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 1); |
| 6247 | rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 1); |
| 6248 | rt2x00_set_field32(®, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 2); |
| 6249 | rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1); |
| 6250 | rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg); |
| 6251 | |
| 6252 | rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, ®); |
| 6253 | rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_TX, 1); |
| 6254 | rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, 1); |
| 6255 | rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg); |
| 6256 | |
| 6257 | /* |
| 6258 | * Initialize LED control |
| 6259 | */ |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6260 | rt2800_eeprom_read(rt2x00dev, EEPROM_LED_AG_CONF, &word); |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 6261 | rt2800_mcu_request(rt2x00dev, MCU_LED_AG_CONF, 0xff, |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 6262 | word & 0xff, (word >> 8) & 0xff); |
| 6263 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6264 | rt2800_eeprom_read(rt2x00dev, EEPROM_LED_ACT_CONF, &word); |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 6265 | rt2800_mcu_request(rt2x00dev, MCU_LED_ACT_CONF, 0xff, |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 6266 | word & 0xff, (word >> 8) & 0xff); |
| 6267 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6268 | rt2800_eeprom_read(rt2x00dev, EEPROM_LED_POLARITY, &word); |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 6269 | rt2800_mcu_request(rt2x00dev, MCU_LED_LED_POLARITY, 0xff, |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 6270 | word & 0xff, (word >> 8) & 0xff); |
| 6271 | |
| 6272 | return 0; |
| 6273 | } |
| 6274 | EXPORT_SYMBOL_GPL(rt2800_enable_radio); |
| 6275 | |
| 6276 | void rt2800_disable_radio(struct rt2x00_dev *rt2x00dev) |
| 6277 | { |
| 6278 | u32 reg; |
| 6279 | |
Jakub Kicinski | f7b395e | 2012-04-03 03:40:47 +0200 | [diff] [blame] | 6280 | rt2800_disable_wpdma(rt2x00dev); |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 6281 | |
| 6282 | /* Wait for DMA, ignore error */ |
| 6283 | rt2800_wait_wpdma_ready(rt2x00dev); |
| 6284 | |
| 6285 | rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, ®); |
| 6286 | rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_TX, 0); |
| 6287 | rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, 0); |
| 6288 | rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg); |
Ivo van Doorn | b9a07ae | 2010-08-23 19:55:22 +0200 | [diff] [blame] | 6289 | } |
| 6290 | EXPORT_SYMBOL_GPL(rt2800_disable_radio); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 6291 | |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 6292 | int rt2800_efuse_detect(struct rt2x00_dev *rt2x00dev) |
| 6293 | { |
| 6294 | u32 reg; |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6295 | u16 efuse_ctrl_reg; |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 6296 | |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6297 | if (rt2x00_rt(rt2x00dev, RT3290)) |
| 6298 | efuse_ctrl_reg = EFUSE_CTRL_3290; |
| 6299 | else |
| 6300 | efuse_ctrl_reg = EFUSE_CTRL; |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 6301 | |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6302 | rt2800_register_read(rt2x00dev, efuse_ctrl_reg, ®); |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 6303 | return rt2x00_get_field32(reg, EFUSE_CTRL_PRESENT); |
| 6304 | } |
| 6305 | EXPORT_SYMBOL_GPL(rt2800_efuse_detect); |
| 6306 | |
| 6307 | static void rt2800_efuse_read(struct rt2x00_dev *rt2x00dev, unsigned int i) |
| 6308 | { |
| 6309 | u32 reg; |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6310 | u16 efuse_ctrl_reg; |
| 6311 | u16 efuse_data0_reg; |
| 6312 | u16 efuse_data1_reg; |
| 6313 | u16 efuse_data2_reg; |
| 6314 | u16 efuse_data3_reg; |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 6315 | |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6316 | if (rt2x00_rt(rt2x00dev, RT3290)) { |
| 6317 | efuse_ctrl_reg = EFUSE_CTRL_3290; |
| 6318 | efuse_data0_reg = EFUSE_DATA0_3290; |
| 6319 | efuse_data1_reg = EFUSE_DATA1_3290; |
| 6320 | efuse_data2_reg = EFUSE_DATA2_3290; |
| 6321 | efuse_data3_reg = EFUSE_DATA3_3290; |
| 6322 | } else { |
| 6323 | efuse_ctrl_reg = EFUSE_CTRL; |
| 6324 | efuse_data0_reg = EFUSE_DATA0; |
| 6325 | efuse_data1_reg = EFUSE_DATA1; |
| 6326 | efuse_data2_reg = EFUSE_DATA2; |
| 6327 | efuse_data3_reg = EFUSE_DATA3; |
| 6328 | } |
Gertjan van Wingerde | 31a4cf1 | 2009-11-14 20:20:36 +0100 | [diff] [blame] | 6329 | mutex_lock(&rt2x00dev->csr_mutex); |
| 6330 | |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6331 | rt2800_register_read_lock(rt2x00dev, efuse_ctrl_reg, ®); |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 6332 | rt2x00_set_field32(®, EFUSE_CTRL_ADDRESS_IN, i); |
| 6333 | rt2x00_set_field32(®, EFUSE_CTRL_MODE, 0); |
| 6334 | rt2x00_set_field32(®, EFUSE_CTRL_KICK, 1); |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6335 | rt2800_register_write_lock(rt2x00dev, efuse_ctrl_reg, reg); |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 6336 | |
| 6337 | /* Wait until the EEPROM has been loaded */ |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6338 | rt2800_regbusy_read(rt2x00dev, efuse_ctrl_reg, EFUSE_CTRL_KICK, ®); |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 6339 | /* Apparently the data is read from end to start */ |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6340 | rt2800_register_read_lock(rt2x00dev, efuse_data3_reg, ®); |
Larry Finger | daabead | 2011-09-14 16:50:23 -0500 | [diff] [blame] | 6341 | /* The returned value is in CPU order, but eeprom is le */ |
Gertjan van Wingerde | 68fa64e | 2011-11-16 23:16:15 +0100 | [diff] [blame] | 6342 | *(u32 *)&rt2x00dev->eeprom[i] = cpu_to_le32(reg); |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6343 | rt2800_register_read_lock(rt2x00dev, efuse_data2_reg, ®); |
Larry Finger | daabead | 2011-09-14 16:50:23 -0500 | [diff] [blame] | 6344 | *(u32 *)&rt2x00dev->eeprom[i + 2] = cpu_to_le32(reg); |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6345 | rt2800_register_read_lock(rt2x00dev, efuse_data1_reg, ®); |
Larry Finger | daabead | 2011-09-14 16:50:23 -0500 | [diff] [blame] | 6346 | *(u32 *)&rt2x00dev->eeprom[i + 4] = cpu_to_le32(reg); |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6347 | rt2800_register_read_lock(rt2x00dev, efuse_data0_reg, ®); |
Larry Finger | daabead | 2011-09-14 16:50:23 -0500 | [diff] [blame] | 6348 | *(u32 *)&rt2x00dev->eeprom[i + 6] = cpu_to_le32(reg); |
Gertjan van Wingerde | 31a4cf1 | 2009-11-14 20:20:36 +0100 | [diff] [blame] | 6349 | |
| 6350 | mutex_unlock(&rt2x00dev->csr_mutex); |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 6351 | } |
| 6352 | |
Gabor Juhos | a02308e | 2012-12-29 14:51:51 +0100 | [diff] [blame] | 6353 | int rt2800_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev) |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 6354 | { |
| 6355 | unsigned int i; |
| 6356 | |
| 6357 | for (i = 0; i < EEPROM_SIZE / sizeof(u16); i += 8) |
| 6358 | rt2800_efuse_read(rt2x00dev, i); |
Gabor Juhos | a02308e | 2012-12-29 14:51:51 +0100 | [diff] [blame] | 6359 | |
| 6360 | return 0; |
Bartlomiej Zolnierkiewicz | 30e8403 | 2009-11-08 14:39:48 +0100 | [diff] [blame] | 6361 | } |
| 6362 | EXPORT_SYMBOL_GPL(rt2800_read_eeprom_efuse); |
| 6363 | |
Gabor Juhos | a3f1625 | 2013-07-08 16:08:25 +0200 | [diff] [blame^] | 6364 | static u8 rt2800_get_txmixer_gain_24g(struct rt2x00_dev *rt2x00dev) |
| 6365 | { |
| 6366 | u16 word; |
| 6367 | |
| 6368 | rt2800_eeprom_read(rt2x00dev, EEPROM_TXMIXER_GAIN_BG, &word); |
| 6369 | if ((word & 0x00ff) != 0x00ff) |
| 6370 | return rt2x00_get_field16(word, EEPROM_TXMIXER_GAIN_BG_VAL); |
| 6371 | |
| 6372 | return 0; |
| 6373 | } |
| 6374 | |
| 6375 | static u8 rt2800_get_txmixer_gain_5g(struct rt2x00_dev *rt2x00dev) |
| 6376 | { |
| 6377 | u16 word; |
| 6378 | |
| 6379 | rt2800_eeprom_read(rt2x00dev, EEPROM_TXMIXER_GAIN_A, &word); |
| 6380 | if ((word & 0x00ff) != 0x00ff) |
| 6381 | return rt2x00_get_field16(word, EEPROM_TXMIXER_GAIN_A_VAL); |
| 6382 | |
| 6383 | return 0; |
| 6384 | } |
| 6385 | |
Gertjan van Wingerde | ad417a5 | 2012-09-03 03:25:51 +0200 | [diff] [blame] | 6386 | static int rt2800_validate_eeprom(struct rt2x00_dev *rt2x00dev) |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6387 | { |
Gertjan van Wingerde | 77c06c2 | 2012-02-06 23:45:13 +0100 | [diff] [blame] | 6388 | struct rt2800_drv_data *drv_data = rt2x00dev->drv_data; |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6389 | u16 word; |
| 6390 | u8 *mac; |
| 6391 | u8 default_lna_gain; |
Gabor Juhos | a02308e | 2012-12-29 14:51:51 +0100 | [diff] [blame] | 6392 | int retval; |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6393 | |
| 6394 | /* |
Gertjan van Wingerde | ad417a5 | 2012-09-03 03:25:51 +0200 | [diff] [blame] | 6395 | * Read the EEPROM. |
| 6396 | */ |
Gabor Juhos | a02308e | 2012-12-29 14:51:51 +0100 | [diff] [blame] | 6397 | retval = rt2800_read_eeprom(rt2x00dev); |
| 6398 | if (retval) |
| 6399 | return retval; |
Gertjan van Wingerde | ad417a5 | 2012-09-03 03:25:51 +0200 | [diff] [blame] | 6400 | |
| 6401 | /* |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6402 | * Start validation of the data that has been read. |
| 6403 | */ |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6404 | mac = rt2800_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6405 | if (!is_valid_ether_addr(mac)) { |
Joe Perches | f4f7f414 | 2012-07-12 19:33:08 +0000 | [diff] [blame] | 6406 | eth_random_addr(mac); |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 6407 | rt2x00_eeprom_dbg(rt2x00dev, "MAC: %pM\n", mac); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6408 | } |
| 6409 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6410 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6411 | if (word == 0xffff) { |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 6412 | rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RXPATH, 2); |
| 6413 | rt2x00_set_field16(&word, EEPROM_NIC_CONF0_TXPATH, 1); |
| 6414 | rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RF_TYPE, RF2820); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6415 | rt2800_eeprom_write(rt2x00dev, EEPROM_NIC_CONF0, word); |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 6416 | rt2x00_eeprom_dbg(rt2x00dev, "Antenna: 0x%04x\n", word); |
Gertjan van Wingerde | 49e721e | 2010-02-13 20:55:49 +0100 | [diff] [blame] | 6417 | } else if (rt2x00_rt(rt2x00dev, RT2860) || |
Gertjan van Wingerde | e148b4c | 2010-04-11 14:31:09 +0200 | [diff] [blame] | 6418 | rt2x00_rt(rt2x00dev, RT2872)) { |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6419 | /* |
| 6420 | * There is a max of 2 RX streams for RT28x0 series |
| 6421 | */ |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 6422 | if (rt2x00_get_field16(word, EEPROM_NIC_CONF0_RXPATH) > 2) |
| 6423 | rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RXPATH, 2); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6424 | rt2800_eeprom_write(rt2x00dev, EEPROM_NIC_CONF0, word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6425 | } |
| 6426 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6427 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6428 | if (word == 0xffff) { |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 6429 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_HW_RADIO, 0); |
| 6430 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_TX_ALC, 0); |
| 6431 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_LNA_2G, 0); |
| 6432 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_LNA_5G, 0); |
| 6433 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_CARDBUS_ACCEL, 0); |
| 6434 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_SB_2G, 0); |
| 6435 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_SB_5G, 0); |
| 6436 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_WPS_PBC, 0); |
| 6437 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_2G, 0); |
| 6438 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_5G, 0); |
| 6439 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BROADBAND_EXT_LNA, 0); |
| 6440 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_ANT_DIVERSITY, 0); |
| 6441 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_INTERNAL_TX_ALC, 0); |
| 6442 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BT_COEXIST, 0); |
| 6443 | rt2x00_set_field16(&word, EEPROM_NIC_CONF1_DAC_TEST, 0); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6444 | rt2800_eeprom_write(rt2x00dev, EEPROM_NIC_CONF1, word); |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 6445 | rt2x00_eeprom_dbg(rt2x00dev, "NIC: 0x%04x\n", word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6446 | } |
| 6447 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6448 | rt2800_eeprom_read(rt2x00dev, EEPROM_FREQ, &word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6449 | if ((word & 0x00ff) == 0x00ff) { |
| 6450 | rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6451 | rt2800_eeprom_write(rt2x00dev, EEPROM_FREQ, word); |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 6452 | rt2x00_eeprom_dbg(rt2x00dev, "Freq: 0x%04x\n", word); |
Gertjan van Wingerde | ec2d179 | 2010-06-29 21:44:50 +0200 | [diff] [blame] | 6453 | } |
| 6454 | if ((word & 0xff00) == 0xff00) { |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6455 | rt2x00_set_field16(&word, EEPROM_FREQ_LED_MODE, |
| 6456 | LED_MODE_TXRX_ACTIVITY); |
| 6457 | rt2x00_set_field16(&word, EEPROM_FREQ_LED_POLARITY, 0); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6458 | rt2800_eeprom_write(rt2x00dev, EEPROM_FREQ, word); |
| 6459 | rt2800_eeprom_write(rt2x00dev, EEPROM_LED_AG_CONF, 0x5555); |
| 6460 | rt2800_eeprom_write(rt2x00dev, EEPROM_LED_ACT_CONF, 0x2221); |
| 6461 | rt2800_eeprom_write(rt2x00dev, EEPROM_LED_POLARITY, 0xa9f8); |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 6462 | rt2x00_eeprom_dbg(rt2x00dev, "Led Mode: 0x%04x\n", word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6463 | } |
| 6464 | |
| 6465 | /* |
| 6466 | * During the LNA validation we are going to use |
| 6467 | * lna0 as correct value. Note that EEPROM_LNA |
| 6468 | * is never validated. |
| 6469 | */ |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6470 | rt2800_eeprom_read(rt2x00dev, EEPROM_LNA, &word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6471 | default_lna_gain = rt2x00_get_field16(word, EEPROM_LNA_A0); |
| 6472 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6473 | rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6474 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET0)) > 10) |
| 6475 | rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET0, 0); |
| 6476 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET1)) > 10) |
| 6477 | rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET1, 0); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6478 | rt2800_eeprom_write(rt2x00dev, EEPROM_RSSI_BG, word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6479 | |
Gabor Juhos | a3f1625 | 2013-07-08 16:08:25 +0200 | [diff] [blame^] | 6480 | drv_data->txmixer_gain_24g = rt2800_get_txmixer_gain_24g(rt2x00dev); |
Gertjan van Wingerde | 77c06c2 | 2012-02-06 23:45:13 +0100 | [diff] [blame] | 6481 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6482 | rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6483 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG2_OFFSET2)) > 10) |
| 6484 | rt2x00_set_field16(&word, EEPROM_RSSI_BG2_OFFSET2, 0); |
| 6485 | if (rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0x00 || |
| 6486 | rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0xff) |
| 6487 | rt2x00_set_field16(&word, EEPROM_RSSI_BG2_LNA_A1, |
| 6488 | default_lna_gain); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6489 | rt2800_eeprom_write(rt2x00dev, EEPROM_RSSI_BG2, word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6490 | |
Gabor Juhos | a3f1625 | 2013-07-08 16:08:25 +0200 | [diff] [blame^] | 6491 | drv_data->txmixer_gain_5g = rt2800_get_txmixer_gain_5g(rt2x00dev); |
Gertjan van Wingerde | 77c06c2 | 2012-02-06 23:45:13 +0100 | [diff] [blame] | 6492 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6493 | rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6494 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET0)) > 10) |
| 6495 | rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET0, 0); |
| 6496 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET1)) > 10) |
| 6497 | rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET1, 0); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6498 | rt2800_eeprom_write(rt2x00dev, EEPROM_RSSI_A, word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6499 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6500 | rt2800_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6501 | if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A2_OFFSET2)) > 10) |
| 6502 | rt2x00_set_field16(&word, EEPROM_RSSI_A2_OFFSET2, 0); |
| 6503 | if (rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0x00 || |
| 6504 | rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0xff) |
| 6505 | rt2x00_set_field16(&word, EEPROM_RSSI_A2_LNA_A2, |
| 6506 | default_lna_gain); |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6507 | rt2800_eeprom_write(rt2x00dev, EEPROM_RSSI_A2, word); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6508 | |
| 6509 | return 0; |
| 6510 | } |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6511 | |
Gertjan van Wingerde | ad417a5 | 2012-09-03 03:25:51 +0200 | [diff] [blame] | 6512 | static int rt2800_init_eeprom(struct rt2x00_dev *rt2x00dev) |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6513 | { |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6514 | u16 value; |
| 6515 | u16 eeprom; |
Gabor Juhos | 86868b2 | 2013-03-30 14:53:09 +0100 | [diff] [blame] | 6516 | u16 rf; |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6517 | |
Gabor Juhos | 86868b2 | 2013-03-30 14:53:09 +0100 | [diff] [blame] | 6518 | /* |
| 6519 | * Read EEPROM word for configuration. |
| 6520 | */ |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6521 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom); |
Gabor Juhos | 86868b2 | 2013-03-30 14:53:09 +0100 | [diff] [blame] | 6522 | |
| 6523 | /* |
| 6524 | * Identify RF chipset by EEPROM value |
| 6525 | * RT28xx/RT30xx: defined in "EEPROM_NIC_CONF0_RF_TYPE" field |
| 6526 | * RT53xx: defined in "EEPROM_CHIP_ID" field |
| 6527 | */ |
| 6528 | if (rt2x00_rt(rt2x00dev, RT3290) || |
| 6529 | rt2x00_rt(rt2x00dev, RT5390) || |
| 6530 | rt2x00_rt(rt2x00dev, RT5392)) |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6531 | rt2800_eeprom_read(rt2x00dev, EEPROM_CHIP_ID, &rf); |
Gabor Juhos | 86868b2 | 2013-03-30 14:53:09 +0100 | [diff] [blame] | 6532 | else |
| 6533 | rf = rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RF_TYPE); |
| 6534 | |
| 6535 | switch (rf) { |
Larry Finger | d331eb5 | 2011-09-14 16:50:22 -0500 | [diff] [blame] | 6536 | case RF2820: |
| 6537 | case RF2850: |
| 6538 | case RF2720: |
| 6539 | case RF2750: |
| 6540 | case RF3020: |
| 6541 | case RF2020: |
| 6542 | case RF3021: |
| 6543 | case RF3022: |
| 6544 | case RF3052: |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6545 | case RF3290: |
Larry Finger | d331eb5 | 2011-09-14 16:50:22 -0500 | [diff] [blame] | 6546 | case RF3320: |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 6547 | case RF3322: |
villacis@palosanto.com | ccf91bd | 2012-05-16 21:07:12 +0200 | [diff] [blame] | 6548 | case RF5360: |
Larry Finger | d331eb5 | 2011-09-14 16:50:22 -0500 | [diff] [blame] | 6549 | case RF5370: |
John Li | 2ed7188 | 2012-02-17 17:33:06 +0800 | [diff] [blame] | 6550 | case RF5372: |
Larry Finger | d331eb5 | 2011-09-14 16:50:22 -0500 | [diff] [blame] | 6551 | case RF5390: |
Zero.Lin | cff3d1f | 2012-05-29 16:11:09 +0800 | [diff] [blame] | 6552 | case RF5392: |
Stanislaw Gruszka | b8863f8 | 2013-03-16 19:19:30 +0100 | [diff] [blame] | 6553 | case RF5592: |
Larry Finger | d331eb5 | 2011-09-14 16:50:22 -0500 | [diff] [blame] | 6554 | break; |
| 6555 | default: |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 6556 | rt2x00_err(rt2x00dev, "Invalid RF chipset 0x%04x detected\n", |
| 6557 | rf); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6558 | return -ENODEV; |
| 6559 | } |
| 6560 | |
Gabor Juhos | 86868b2 | 2013-03-30 14:53:09 +0100 | [diff] [blame] | 6561 | rt2x00_set_rf(rt2x00dev, rf); |
| 6562 | |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6563 | /* |
| 6564 | * Identify default antenna configuration. |
| 6565 | */ |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 6566 | rt2x00dev->default_ant.tx_chain_num = |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 6567 | rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH); |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 6568 | rt2x00dev->default_ant.rx_chain_num = |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 6569 | rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6570 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6571 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom); |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 6572 | |
| 6573 | if (rt2x00_rt(rt2x00dev, RT3070) || |
| 6574 | rt2x00_rt(rt2x00dev, RT3090) || |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 6575 | rt2x00_rt(rt2x00dev, RT3352) || |
RA-Jay Hung | d96aa64 | 2011-02-20 13:54:52 +0100 | [diff] [blame] | 6576 | rt2x00_rt(rt2x00dev, RT3390)) { |
| 6577 | value = rt2x00_get_field16(eeprom, |
| 6578 | EEPROM_NIC_CONF1_ANT_DIVERSITY); |
| 6579 | switch (value) { |
| 6580 | case 0: |
| 6581 | case 1: |
| 6582 | case 2: |
| 6583 | rt2x00dev->default_ant.tx = ANTENNA_A; |
| 6584 | rt2x00dev->default_ant.rx = ANTENNA_A; |
| 6585 | break; |
| 6586 | case 3: |
| 6587 | rt2x00dev->default_ant.tx = ANTENNA_A; |
| 6588 | rt2x00dev->default_ant.rx = ANTENNA_B; |
| 6589 | break; |
| 6590 | } |
| 6591 | } else { |
| 6592 | rt2x00dev->default_ant.tx = ANTENNA_A; |
| 6593 | rt2x00dev->default_ant.rx = ANTENNA_A; |
| 6594 | } |
| 6595 | |
Anisse Astier | 0586a11 | 2012-04-23 12:33:11 +0200 | [diff] [blame] | 6596 | if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390R)) { |
| 6597 | rt2x00dev->default_ant.tx = ANTENNA_HW_DIVERSITY; /* Unused */ |
| 6598 | rt2x00dev->default_ant.rx = ANTENNA_HW_DIVERSITY; /* Unused */ |
| 6599 | } |
| 6600 | |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6601 | /* |
Gertjan van Wingerde | 9328fda | 2011-04-30 17:15:13 +0200 | [diff] [blame] | 6602 | * Determine external LNA informations. |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6603 | */ |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 6604 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_EXTERNAL_LNA_5G)) |
Ivo van Doorn | 7dab73b | 2011-04-18 15:27:06 +0200 | [diff] [blame] | 6605 | __set_bit(CAPABILITY_EXTERNAL_LNA_A, &rt2x00dev->cap_flags); |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 6606 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_EXTERNAL_LNA_2G)) |
Ivo van Doorn | 7dab73b | 2011-04-18 15:27:06 +0200 | [diff] [blame] | 6607 | __set_bit(CAPABILITY_EXTERNAL_LNA_BG, &rt2x00dev->cap_flags); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6608 | |
| 6609 | /* |
| 6610 | * Detect if this device has an hardware controlled radio. |
| 6611 | */ |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 6612 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_HW_RADIO)) |
Ivo van Doorn | 7dab73b | 2011-04-18 15:27:06 +0200 | [diff] [blame] | 6613 | __set_bit(CAPABILITY_HW_BUTTON, &rt2x00dev->cap_flags); |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6614 | |
| 6615 | /* |
Gertjan van Wingerde | fdbc7b0 | 2011-04-30 17:15:37 +0200 | [diff] [blame] | 6616 | * Detect if this device has Bluetooth co-existence. |
| 6617 | */ |
| 6618 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_BT_COEXIST)) |
| 6619 | __set_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags); |
| 6620 | |
| 6621 | /* |
Gertjan van Wingerde | 9328fda | 2011-04-30 17:15:13 +0200 | [diff] [blame] | 6622 | * Read frequency offset and RF programming sequence. |
| 6623 | */ |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6624 | rt2800_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom); |
Gertjan van Wingerde | 9328fda | 2011-04-30 17:15:13 +0200 | [diff] [blame] | 6625 | rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET); |
| 6626 | |
| 6627 | /* |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6628 | * Store led settings, for correct led behaviour. |
| 6629 | */ |
| 6630 | #ifdef CONFIG_RT2X00_LIB_LEDS |
| 6631 | rt2800_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO); |
| 6632 | rt2800_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC); |
| 6633 | rt2800_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY); |
| 6634 | |
Gertjan van Wingerde | 9328fda | 2011-04-30 17:15:13 +0200 | [diff] [blame] | 6635 | rt2x00dev->led_mcu_reg = eeprom; |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6636 | #endif /* CONFIG_RT2X00_LIB_LEDS */ |
| 6637 | |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 6638 | /* |
| 6639 | * Check if support EIRP tx power limit feature. |
| 6640 | */ |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6641 | rt2800_eeprom_read(rt2x00dev, EEPROM_EIRP_MAX_TX_POWER, &eeprom); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 6642 | |
| 6643 | if (rt2x00_get_field16(eeprom, EEPROM_EIRP_MAX_TX_POWER_2GHZ) < |
| 6644 | EIRP_MAX_TX_POWER_LIMIT) |
Ivo van Doorn | 7dab73b | 2011-04-18 15:27:06 +0200 | [diff] [blame] | 6645 | __set_bit(CAPABILITY_POWER_LIMIT, &rt2x00dev->cap_flags); |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 6646 | |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6647 | return 0; |
| 6648 | } |
Bartlomiej Zolnierkiewicz | 38bd7b8 | 2009-11-08 14:39:01 +0100 | [diff] [blame] | 6649 | |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 6650 | /* |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 6651 | * RF value list for rt28xx |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 6652 | * Supports: 2.4 GHz (all) & 5.2 GHz (RF2850 & RF2750) |
| 6653 | */ |
| 6654 | static const struct rf_channel rf_vals[] = { |
| 6655 | { 1, 0x18402ecc, 0x184c0786, 0x1816b455, 0x1800510b }, |
| 6656 | { 2, 0x18402ecc, 0x184c0786, 0x18168a55, 0x1800519f }, |
| 6657 | { 3, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800518b }, |
| 6658 | { 4, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800519f }, |
| 6659 | { 5, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800518b }, |
| 6660 | { 6, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800519f }, |
| 6661 | { 7, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800518b }, |
| 6662 | { 8, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800519f }, |
| 6663 | { 9, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800518b }, |
| 6664 | { 10, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800519f }, |
| 6665 | { 11, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800518b }, |
| 6666 | { 12, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800519f }, |
| 6667 | { 13, 0x18402ecc, 0x184c079e, 0x18168a55, 0x1800518b }, |
| 6668 | { 14, 0x18402ecc, 0x184c07a2, 0x18168a55, 0x18005193 }, |
| 6669 | |
| 6670 | /* 802.11 UNI / HyperLan 2 */ |
| 6671 | { 36, 0x18402ecc, 0x184c099a, 0x18158a55, 0x180ed1a3 }, |
| 6672 | { 38, 0x18402ecc, 0x184c099e, 0x18158a55, 0x180ed193 }, |
| 6673 | { 40, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed183 }, |
| 6674 | { 44, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed1a3 }, |
| 6675 | { 46, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed18b }, |
| 6676 | { 48, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed19b }, |
| 6677 | { 52, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed193 }, |
| 6678 | { 54, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed1a3 }, |
| 6679 | { 56, 0x18402ec8, 0x184c068e, 0x18158a55, 0x180ed18b }, |
| 6680 | { 60, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed183 }, |
| 6681 | { 62, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed193 }, |
| 6682 | { 64, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed1a3 }, |
| 6683 | |
| 6684 | /* 802.11 HyperLan 2 */ |
| 6685 | { 100, 0x18402ec8, 0x184c06b2, 0x18178a55, 0x180ed783 }, |
| 6686 | { 102, 0x18402ec8, 0x184c06b2, 0x18578a55, 0x180ed793 }, |
| 6687 | { 104, 0x18402ec8, 0x185c06b2, 0x18578a55, 0x180ed1a3 }, |
| 6688 | { 108, 0x18402ecc, 0x185c0a32, 0x18578a55, 0x180ed193 }, |
| 6689 | { 110, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed183 }, |
| 6690 | { 112, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed19b }, |
| 6691 | { 116, 0x18402ecc, 0x184c0a3a, 0x18178a55, 0x180ed1a3 }, |
| 6692 | { 118, 0x18402ecc, 0x184c0a3e, 0x18178a55, 0x180ed193 }, |
| 6693 | { 120, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed183 }, |
| 6694 | { 124, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed193 }, |
| 6695 | { 126, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed15b }, |
| 6696 | { 128, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed1a3 }, |
| 6697 | { 132, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed18b }, |
| 6698 | { 134, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed193 }, |
| 6699 | { 136, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed19b }, |
| 6700 | { 140, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed183 }, |
| 6701 | |
| 6702 | /* 802.11 UNII */ |
| 6703 | { 149, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed1a7 }, |
| 6704 | { 151, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed187 }, |
| 6705 | { 153, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed18f }, |
| 6706 | { 157, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed19f }, |
| 6707 | { 159, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed1a7 }, |
| 6708 | { 161, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed187 }, |
| 6709 | { 165, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed197 }, |
| 6710 | { 167, 0x18402ec4, 0x184c03d2, 0x18179855, 0x1815531f }, |
| 6711 | { 169, 0x18402ec4, 0x184c03d2, 0x18179855, 0x18155327 }, |
| 6712 | { 171, 0x18402ec4, 0x184c03d6, 0x18179855, 0x18155307 }, |
| 6713 | { 173, 0x18402ec4, 0x184c03d6, 0x18179855, 0x1815530f }, |
| 6714 | |
| 6715 | /* 802.11 Japan */ |
| 6716 | { 184, 0x15002ccc, 0x1500491e, 0x1509be55, 0x150c0a0b }, |
| 6717 | { 188, 0x15002ccc, 0x15004922, 0x1509be55, 0x150c0a13 }, |
| 6718 | { 192, 0x15002ccc, 0x15004926, 0x1509be55, 0x150c0a1b }, |
| 6719 | { 196, 0x15002ccc, 0x1500492a, 0x1509be55, 0x150c0a23 }, |
| 6720 | { 208, 0x15002ccc, 0x1500493a, 0x1509be55, 0x150c0a13 }, |
| 6721 | { 212, 0x15002ccc, 0x1500493e, 0x1509be55, 0x150c0a1b }, |
| 6722 | { 216, 0x15002ccc, 0x15004982, 0x1509be55, 0x150c0a23 }, |
| 6723 | }; |
| 6724 | |
| 6725 | /* |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 6726 | * RF value list for rt3xxx |
| 6727 | * Supports: 2.4 GHz (all) & 5.2 GHz (RF3052) |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 6728 | */ |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 6729 | static const struct rf_channel rf_vals_3x[] = { |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 6730 | {1, 241, 2, 2 }, |
| 6731 | {2, 241, 2, 7 }, |
| 6732 | {3, 242, 2, 2 }, |
| 6733 | {4, 242, 2, 7 }, |
| 6734 | {5, 243, 2, 2 }, |
| 6735 | {6, 243, 2, 7 }, |
| 6736 | {7, 244, 2, 2 }, |
| 6737 | {8, 244, 2, 7 }, |
| 6738 | {9, 245, 2, 2 }, |
| 6739 | {10, 245, 2, 7 }, |
| 6740 | {11, 246, 2, 2 }, |
| 6741 | {12, 246, 2, 7 }, |
| 6742 | {13, 247, 2, 2 }, |
| 6743 | {14, 248, 2, 4 }, |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 6744 | |
| 6745 | /* 802.11 UNI / HyperLan 2 */ |
| 6746 | {36, 0x56, 0, 4}, |
| 6747 | {38, 0x56, 0, 6}, |
| 6748 | {40, 0x56, 0, 8}, |
| 6749 | {44, 0x57, 0, 0}, |
| 6750 | {46, 0x57, 0, 2}, |
| 6751 | {48, 0x57, 0, 4}, |
| 6752 | {52, 0x57, 0, 8}, |
| 6753 | {54, 0x57, 0, 10}, |
| 6754 | {56, 0x58, 0, 0}, |
| 6755 | {60, 0x58, 0, 4}, |
| 6756 | {62, 0x58, 0, 6}, |
| 6757 | {64, 0x58, 0, 8}, |
| 6758 | |
| 6759 | /* 802.11 HyperLan 2 */ |
| 6760 | {100, 0x5b, 0, 8}, |
| 6761 | {102, 0x5b, 0, 10}, |
| 6762 | {104, 0x5c, 0, 0}, |
| 6763 | {108, 0x5c, 0, 4}, |
| 6764 | {110, 0x5c, 0, 6}, |
| 6765 | {112, 0x5c, 0, 8}, |
| 6766 | {116, 0x5d, 0, 0}, |
| 6767 | {118, 0x5d, 0, 2}, |
| 6768 | {120, 0x5d, 0, 4}, |
| 6769 | {124, 0x5d, 0, 8}, |
| 6770 | {126, 0x5d, 0, 10}, |
| 6771 | {128, 0x5e, 0, 0}, |
| 6772 | {132, 0x5e, 0, 4}, |
| 6773 | {134, 0x5e, 0, 6}, |
| 6774 | {136, 0x5e, 0, 8}, |
| 6775 | {140, 0x5f, 0, 0}, |
| 6776 | |
| 6777 | /* 802.11 UNII */ |
| 6778 | {149, 0x5f, 0, 9}, |
| 6779 | {151, 0x5f, 0, 11}, |
| 6780 | {153, 0x60, 0, 1}, |
| 6781 | {157, 0x60, 0, 5}, |
| 6782 | {159, 0x60, 0, 7}, |
| 6783 | {161, 0x60, 0, 9}, |
| 6784 | {165, 0x61, 0, 1}, |
| 6785 | {167, 0x61, 0, 3}, |
| 6786 | {169, 0x61, 0, 5}, |
| 6787 | {171, 0x61, 0, 7}, |
| 6788 | {173, 0x61, 0, 9}, |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 6789 | }; |
| 6790 | |
Stanislaw Gruszka | 7848b23 | 2013-03-16 19:19:31 +0100 | [diff] [blame] | 6791 | static const struct rf_channel rf_vals_5592_xtal20[] = { |
| 6792 | /* Channel, N, K, mod, R */ |
| 6793 | {1, 482, 4, 10, 3}, |
| 6794 | {2, 483, 4, 10, 3}, |
| 6795 | {3, 484, 4, 10, 3}, |
| 6796 | {4, 485, 4, 10, 3}, |
| 6797 | {5, 486, 4, 10, 3}, |
| 6798 | {6, 487, 4, 10, 3}, |
| 6799 | {7, 488, 4, 10, 3}, |
| 6800 | {8, 489, 4, 10, 3}, |
| 6801 | {9, 490, 4, 10, 3}, |
| 6802 | {10, 491, 4, 10, 3}, |
| 6803 | {11, 492, 4, 10, 3}, |
| 6804 | {12, 493, 4, 10, 3}, |
| 6805 | {13, 494, 4, 10, 3}, |
| 6806 | {14, 496, 8, 10, 3}, |
| 6807 | {36, 172, 8, 12, 1}, |
| 6808 | {38, 173, 0, 12, 1}, |
| 6809 | {40, 173, 4, 12, 1}, |
| 6810 | {42, 173, 8, 12, 1}, |
| 6811 | {44, 174, 0, 12, 1}, |
| 6812 | {46, 174, 4, 12, 1}, |
| 6813 | {48, 174, 8, 12, 1}, |
| 6814 | {50, 175, 0, 12, 1}, |
| 6815 | {52, 175, 4, 12, 1}, |
| 6816 | {54, 175, 8, 12, 1}, |
| 6817 | {56, 176, 0, 12, 1}, |
| 6818 | {58, 176, 4, 12, 1}, |
| 6819 | {60, 176, 8, 12, 1}, |
| 6820 | {62, 177, 0, 12, 1}, |
| 6821 | {64, 177, 4, 12, 1}, |
| 6822 | {100, 183, 4, 12, 1}, |
| 6823 | {102, 183, 8, 12, 1}, |
| 6824 | {104, 184, 0, 12, 1}, |
| 6825 | {106, 184, 4, 12, 1}, |
| 6826 | {108, 184, 8, 12, 1}, |
| 6827 | {110, 185, 0, 12, 1}, |
| 6828 | {112, 185, 4, 12, 1}, |
| 6829 | {114, 185, 8, 12, 1}, |
| 6830 | {116, 186, 0, 12, 1}, |
| 6831 | {118, 186, 4, 12, 1}, |
| 6832 | {120, 186, 8, 12, 1}, |
| 6833 | {122, 187, 0, 12, 1}, |
| 6834 | {124, 187, 4, 12, 1}, |
| 6835 | {126, 187, 8, 12, 1}, |
| 6836 | {128, 188, 0, 12, 1}, |
| 6837 | {130, 188, 4, 12, 1}, |
| 6838 | {132, 188, 8, 12, 1}, |
| 6839 | {134, 189, 0, 12, 1}, |
| 6840 | {136, 189, 4, 12, 1}, |
| 6841 | {138, 189, 8, 12, 1}, |
| 6842 | {140, 190, 0, 12, 1}, |
| 6843 | {149, 191, 6, 12, 1}, |
| 6844 | {151, 191, 10, 12, 1}, |
| 6845 | {153, 192, 2, 12, 1}, |
| 6846 | {155, 192, 6, 12, 1}, |
| 6847 | {157, 192, 10, 12, 1}, |
| 6848 | {159, 193, 2, 12, 1}, |
| 6849 | {161, 193, 6, 12, 1}, |
| 6850 | {165, 194, 2, 12, 1}, |
| 6851 | {184, 164, 0, 12, 1}, |
| 6852 | {188, 164, 4, 12, 1}, |
| 6853 | {192, 165, 8, 12, 1}, |
| 6854 | {196, 166, 0, 12, 1}, |
| 6855 | }; |
| 6856 | |
| 6857 | static const struct rf_channel rf_vals_5592_xtal40[] = { |
| 6858 | /* Channel, N, K, mod, R */ |
| 6859 | {1, 241, 2, 10, 3}, |
| 6860 | {2, 241, 7, 10, 3}, |
| 6861 | {3, 242, 2, 10, 3}, |
| 6862 | {4, 242, 7, 10, 3}, |
| 6863 | {5, 243, 2, 10, 3}, |
| 6864 | {6, 243, 7, 10, 3}, |
| 6865 | {7, 244, 2, 10, 3}, |
| 6866 | {8, 244, 7, 10, 3}, |
| 6867 | {9, 245, 2, 10, 3}, |
| 6868 | {10, 245, 7, 10, 3}, |
| 6869 | {11, 246, 2, 10, 3}, |
| 6870 | {12, 246, 7, 10, 3}, |
| 6871 | {13, 247, 2, 10, 3}, |
| 6872 | {14, 248, 4, 10, 3}, |
| 6873 | {36, 86, 4, 12, 1}, |
| 6874 | {38, 86, 6, 12, 1}, |
| 6875 | {40, 86, 8, 12, 1}, |
| 6876 | {42, 86, 10, 12, 1}, |
| 6877 | {44, 87, 0, 12, 1}, |
| 6878 | {46, 87, 2, 12, 1}, |
| 6879 | {48, 87, 4, 12, 1}, |
| 6880 | {50, 87, 6, 12, 1}, |
| 6881 | {52, 87, 8, 12, 1}, |
| 6882 | {54, 87, 10, 12, 1}, |
| 6883 | {56, 88, 0, 12, 1}, |
| 6884 | {58, 88, 2, 12, 1}, |
| 6885 | {60, 88, 4, 12, 1}, |
| 6886 | {62, 88, 6, 12, 1}, |
| 6887 | {64, 88, 8, 12, 1}, |
| 6888 | {100, 91, 8, 12, 1}, |
| 6889 | {102, 91, 10, 12, 1}, |
| 6890 | {104, 92, 0, 12, 1}, |
| 6891 | {106, 92, 2, 12, 1}, |
| 6892 | {108, 92, 4, 12, 1}, |
| 6893 | {110, 92, 6, 12, 1}, |
| 6894 | {112, 92, 8, 12, 1}, |
| 6895 | {114, 92, 10, 12, 1}, |
| 6896 | {116, 93, 0, 12, 1}, |
| 6897 | {118, 93, 2, 12, 1}, |
| 6898 | {120, 93, 4, 12, 1}, |
| 6899 | {122, 93, 6, 12, 1}, |
| 6900 | {124, 93, 8, 12, 1}, |
| 6901 | {126, 93, 10, 12, 1}, |
| 6902 | {128, 94, 0, 12, 1}, |
| 6903 | {130, 94, 2, 12, 1}, |
| 6904 | {132, 94, 4, 12, 1}, |
| 6905 | {134, 94, 6, 12, 1}, |
| 6906 | {136, 94, 8, 12, 1}, |
| 6907 | {138, 94, 10, 12, 1}, |
| 6908 | {140, 95, 0, 12, 1}, |
| 6909 | {149, 95, 9, 12, 1}, |
| 6910 | {151, 95, 11, 12, 1}, |
| 6911 | {153, 96, 1, 12, 1}, |
| 6912 | {155, 96, 3, 12, 1}, |
| 6913 | {157, 96, 5, 12, 1}, |
| 6914 | {159, 96, 7, 12, 1}, |
| 6915 | {161, 96, 9, 12, 1}, |
| 6916 | {165, 97, 1, 12, 1}, |
| 6917 | {184, 82, 0, 12, 1}, |
| 6918 | {188, 82, 4, 12, 1}, |
| 6919 | {192, 82, 8, 12, 1}, |
| 6920 | {196, 83, 0, 12, 1}, |
| 6921 | }; |
| 6922 | |
Gertjan van Wingerde | ad417a5 | 2012-09-03 03:25:51 +0200 | [diff] [blame] | 6923 | static int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev) |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 6924 | { |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 6925 | struct hw_mode_spec *spec = &rt2x00dev->spec; |
| 6926 | struct channel_info *info; |
Ivo van Doorn | 8d1331b | 2010-08-23 19:56:07 +0200 | [diff] [blame] | 6927 | char *default_power1; |
| 6928 | char *default_power2; |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 6929 | unsigned int i; |
| 6930 | u16 eeprom; |
Stanislaw Gruszka | 7848b23 | 2013-03-16 19:19:31 +0100 | [diff] [blame] | 6931 | u32 reg; |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 6932 | |
| 6933 | /* |
Gertjan van Wingerde | 93b6bd2 | 2009-12-14 20:33:55 +0100 | [diff] [blame] | 6934 | * Disable powersaving as default on PCI devices. |
| 6935 | */ |
Gertjan van Wingerde | cea90e5 | 2010-02-13 20:55:47 +0100 | [diff] [blame] | 6936 | if (rt2x00_is_pci(rt2x00dev) || rt2x00_is_soc(rt2x00dev)) |
Gertjan van Wingerde | 93b6bd2 | 2009-12-14 20:33:55 +0100 | [diff] [blame] | 6937 | rt2x00dev->hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; |
| 6938 | |
| 6939 | /* |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 6940 | * Initialize all hw fields. |
| 6941 | */ |
| 6942 | rt2x00dev->hw->flags = |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 6943 | IEEE80211_HW_SIGNAL_DBM | |
| 6944 | IEEE80211_HW_SUPPORTS_PS | |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 6945 | IEEE80211_HW_PS_NULLFUNC_STACK | |
Helmut Schaa | 9d4f09b | 2012-03-14 08:56:47 +0100 | [diff] [blame] | 6946 | IEEE80211_HW_AMPDU_AGGREGATION | |
Helmut Schaa | 84e9e8ebd | 2013-01-17 17:34:32 +0100 | [diff] [blame] | 6947 | IEEE80211_HW_REPORTS_TX_ACK_STATUS; |
Helmut Schaa | 9d4f09b | 2012-03-14 08:56:47 +0100 | [diff] [blame] | 6948 | |
Helmut Schaa | 5a5b6ed | 2010-10-02 11:31:33 +0200 | [diff] [blame] | 6949 | /* |
| 6950 | * Don't set IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING for USB devices |
| 6951 | * unless we are capable of sending the buffered frames out after the |
| 6952 | * DTIM transmission using rt2x00lib_beacondone. This will send out |
| 6953 | * multicast and broadcast traffic immediately instead of buffering it |
| 6954 | * infinitly and thus dropping it after some time. |
| 6955 | */ |
| 6956 | if (!rt2x00_is_usb(rt2x00dev)) |
| 6957 | rt2x00dev->hw->flags |= |
| 6958 | IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING; |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 6959 | |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 6960 | SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev); |
| 6961 | SET_IEEE80211_PERM_ADDR(rt2x00dev->hw, |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6962 | rt2800_eeprom_addr(rt2x00dev, |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 6963 | EEPROM_MAC_ADDR_0)); |
| 6964 | |
Helmut Schaa | 3f2bee2 | 2010-06-14 22:12:01 +0200 | [diff] [blame] | 6965 | /* |
| 6966 | * As rt2800 has a global fallback table we cannot specify |
| 6967 | * more then one tx rate per frame but since the hw will |
| 6968 | * try several rates (based on the fallback table) we should |
Helmut Schaa | ba3b9e5 | 2010-10-02 11:32:16 +0200 | [diff] [blame] | 6969 | * initialize max_report_rates to the maximum number of rates |
Helmut Schaa | 3f2bee2 | 2010-06-14 22:12:01 +0200 | [diff] [blame] | 6970 | * we are going to try. Otherwise mac80211 will truncate our |
| 6971 | * reported tx rates and the rc algortihm will end up with |
| 6972 | * incorrect data. |
| 6973 | */ |
Helmut Schaa | ba3b9e5 | 2010-10-02 11:32:16 +0200 | [diff] [blame] | 6974 | rt2x00dev->hw->max_rates = 1; |
| 6975 | rt2x00dev->hw->max_report_rates = 7; |
Helmut Schaa | 3f2bee2 | 2010-06-14 22:12:01 +0200 | [diff] [blame] | 6976 | rt2x00dev->hw->max_rate_tries = 1; |
| 6977 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 6978 | rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom); |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 6979 | |
| 6980 | /* |
| 6981 | * Initialize hw_mode information. |
| 6982 | */ |
| 6983 | spec->supported_bands = SUPPORT_BAND_2GHZ; |
| 6984 | spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM; |
| 6985 | |
Gertjan van Wingerde | 5122d89 | 2009-12-23 00:03:25 +0100 | [diff] [blame] | 6986 | if (rt2x00_rf(rt2x00dev, RF2820) || |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 6987 | rt2x00_rf(rt2x00dev, RF2720)) { |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 6988 | spec->num_channels = 14; |
| 6989 | spec->channels = rf_vals; |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 6990 | } else if (rt2x00_rf(rt2x00dev, RF2850) || |
| 6991 | rt2x00_rf(rt2x00dev, RF2750)) { |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 6992 | spec->supported_bands |= SUPPORT_BAND_5GHZ; |
| 6993 | spec->num_channels = ARRAY_SIZE(rf_vals); |
| 6994 | spec->channels = rf_vals; |
Gertjan van Wingerde | 5122d89 | 2009-12-23 00:03:25 +0100 | [diff] [blame] | 6995 | } else if (rt2x00_rf(rt2x00dev, RF3020) || |
| 6996 | rt2x00_rf(rt2x00dev, RF2020) || |
| 6997 | rt2x00_rf(rt2x00dev, RF3021) || |
Gertjan van Wingerde | f93bc9b | 2010-11-13 19:09:50 +0100 | [diff] [blame] | 6998 | rt2x00_rf(rt2x00dev, RF3022) || |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 6999 | rt2x00_rf(rt2x00dev, RF3290) || |
Gabor Juhos | adde588 | 2011-03-03 11:46:45 +0100 | [diff] [blame] | 7000 | rt2x00_rf(rt2x00dev, RF3320) || |
Daniel Golle | 0383995 | 2012-09-09 14:24:39 +0300 | [diff] [blame] | 7001 | rt2x00_rf(rt2x00dev, RF3322) || |
villacis@palosanto.com | ccf91bd | 2012-05-16 21:07:12 +0200 | [diff] [blame] | 7002 | rt2x00_rf(rt2x00dev, RF5360) || |
Gertjan van Wingerde | aca355b | 2011-05-04 21:41:36 +0200 | [diff] [blame] | 7003 | rt2x00_rf(rt2x00dev, RF5370) || |
John Li | 2ed7188 | 2012-02-17 17:33:06 +0800 | [diff] [blame] | 7004 | rt2x00_rf(rt2x00dev, RF5372) || |
Zero.Lin | cff3d1f | 2012-05-29 16:11:09 +0800 | [diff] [blame] | 7005 | rt2x00_rf(rt2x00dev, RF5390) || |
| 7006 | rt2x00_rf(rt2x00dev, RF5392)) { |
Ivo van Doorn | 55f9321 | 2010-05-06 14:45:46 +0200 | [diff] [blame] | 7007 | spec->num_channels = 14; |
| 7008 | spec->channels = rf_vals_3x; |
| 7009 | } else if (rt2x00_rf(rt2x00dev, RF3052)) { |
| 7010 | spec->supported_bands |= SUPPORT_BAND_5GHZ; |
| 7011 | spec->num_channels = ARRAY_SIZE(rf_vals_3x); |
| 7012 | spec->channels = rf_vals_3x; |
Stanislaw Gruszka | 7848b23 | 2013-03-16 19:19:31 +0100 | [diff] [blame] | 7013 | } else if (rt2x00_rf(rt2x00dev, RF5592)) { |
| 7014 | spec->supported_bands |= SUPPORT_BAND_5GHZ; |
| 7015 | |
| 7016 | rt2800_register_read(rt2x00dev, MAC_DEBUG_INDEX, ®); |
| 7017 | if (rt2x00_get_field32(reg, MAC_DEBUG_INDEX_XTAL)) { |
| 7018 | spec->num_channels = ARRAY_SIZE(rf_vals_5592_xtal40); |
| 7019 | spec->channels = rf_vals_5592_xtal40; |
| 7020 | } else { |
| 7021 | spec->num_channels = ARRAY_SIZE(rf_vals_5592_xtal20); |
| 7022 | spec->channels = rf_vals_5592_xtal20; |
| 7023 | } |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7024 | } |
| 7025 | |
Stanislaw Gruszka | 53216d6 | 2013-03-16 19:19:29 +0100 | [diff] [blame] | 7026 | if (WARN_ON_ONCE(!spec->channels)) |
| 7027 | return -ENODEV; |
| 7028 | |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7029 | /* |
| 7030 | * Initialize HT information. |
| 7031 | */ |
Gertjan van Wingerde | 5122d89 | 2009-12-23 00:03:25 +0100 | [diff] [blame] | 7032 | if (!rt2x00_rf(rt2x00dev, RF2020)) |
Gertjan van Wingerde | 38a522e | 2009-11-23 22:44:47 +0100 | [diff] [blame] | 7033 | spec->ht.ht_supported = true; |
| 7034 | else |
| 7035 | spec->ht.ht_supported = false; |
| 7036 | |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7037 | spec->ht.cap = |
Gertjan van Wingerde | 06443e4 | 2010-06-03 10:52:08 +0200 | [diff] [blame] | 7038 | IEEE80211_HT_CAP_SUP_WIDTH_20_40 | |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7039 | IEEE80211_HT_CAP_GRN_FLD | |
| 7040 | IEEE80211_HT_CAP_SGI_20 | |
Ivo van Doorn | aa67463 | 2010-06-29 21:48:37 +0200 | [diff] [blame] | 7041 | IEEE80211_HT_CAP_SGI_40; |
Helmut Schaa | 22cabaa | 2010-06-03 10:52:10 +0200 | [diff] [blame] | 7042 | |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 7043 | if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) >= 2) |
Helmut Schaa | 22cabaa | 2010-06-03 10:52:10 +0200 | [diff] [blame] | 7044 | spec->ht.cap |= IEEE80211_HT_CAP_TX_STBC; |
| 7045 | |
Ivo van Doorn | aa67463 | 2010-06-29 21:48:37 +0200 | [diff] [blame] | 7046 | spec->ht.cap |= |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 7047 | rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) << |
Ivo van Doorn | aa67463 | 2010-06-29 21:48:37 +0200 | [diff] [blame] | 7048 | IEEE80211_HT_CAP_RX_STBC_SHIFT; |
| 7049 | |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7050 | spec->ht.ampdu_factor = 3; |
| 7051 | spec->ht.ampdu_density = 4; |
| 7052 | spec->ht.mcs.tx_params = |
| 7053 | IEEE80211_HT_MCS_TX_DEFINED | |
| 7054 | IEEE80211_HT_MCS_TX_RX_DIFF | |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 7055 | ((rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) - 1) << |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7056 | IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT); |
| 7057 | |
RA-Jay Hung | 38c8a56 | 2010-12-13 12:31:27 +0100 | [diff] [blame] | 7058 | switch (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH)) { |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7059 | case 3: |
| 7060 | spec->ht.mcs.rx_mask[2] = 0xff; |
| 7061 | case 2: |
| 7062 | spec->ht.mcs.rx_mask[1] = 0xff; |
| 7063 | case 1: |
| 7064 | spec->ht.mcs.rx_mask[0] = 0xff; |
| 7065 | spec->ht.mcs.rx_mask[4] = 0x1; /* MCS32 */ |
| 7066 | break; |
| 7067 | } |
| 7068 | |
| 7069 | /* |
| 7070 | * Create channel information array |
| 7071 | */ |
Joe Perches | baeb2ff | 2010-08-11 07:02:48 +0000 | [diff] [blame] | 7072 | info = kcalloc(spec->num_channels, sizeof(*info), GFP_KERNEL); |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7073 | if (!info) |
| 7074 | return -ENOMEM; |
| 7075 | |
| 7076 | spec->channels_info = info; |
| 7077 | |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 7078 | default_power1 = rt2800_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG1); |
| 7079 | default_power2 = rt2800_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG2); |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7080 | |
| 7081 | for (i = 0; i < 14; i++) { |
RA-Jay Hung | e90c54b | 2011-02-20 13:55:25 +0100 | [diff] [blame] | 7082 | info[i].default_power1 = default_power1[i]; |
| 7083 | info[i].default_power2 = default_power2[i]; |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7084 | } |
| 7085 | |
| 7086 | if (spec->num_channels > 14) { |
Gabor Juhos | 3e38d3d | 2013-07-08 11:25:53 +0200 | [diff] [blame] | 7087 | default_power1 = rt2800_eeprom_addr(rt2x00dev, |
| 7088 | EEPROM_TXPOWER_A1); |
| 7089 | default_power2 = rt2800_eeprom_addr(rt2x00dev, |
| 7090 | EEPROM_TXPOWER_A2); |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7091 | |
| 7092 | for (i = 14; i < spec->num_channels; i++) { |
Gabor Juhos | 0a6f3a8 | 2013-06-22 13:13:25 +0200 | [diff] [blame] | 7093 | info[i].default_power1 = default_power1[i - 14]; |
| 7094 | info[i].default_power2 = default_power2[i - 14]; |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7095 | } |
| 7096 | } |
| 7097 | |
John Li | 2e9c43d | 2012-02-16 21:40:57 +0800 | [diff] [blame] | 7098 | switch (rt2x00dev->chip.rf) { |
| 7099 | case RF2020: |
| 7100 | case RF3020: |
| 7101 | case RF3021: |
| 7102 | case RF3022: |
| 7103 | case RF3320: |
| 7104 | case RF3052: |
Woody Hung | a89534e | 2012-06-13 15:01:16 +0800 | [diff] [blame] | 7105 | case RF3290: |
villacis@palosanto.com | ccf91bd | 2012-05-16 21:07:12 +0200 | [diff] [blame] | 7106 | case RF5360: |
John Li | 2e9c43d | 2012-02-16 21:40:57 +0800 | [diff] [blame] | 7107 | case RF5370: |
| 7108 | case RF5372: |
| 7109 | case RF5390: |
Zero.Lin | cff3d1f | 2012-05-29 16:11:09 +0800 | [diff] [blame] | 7110 | case RF5392: |
John Li | 2e9c43d | 2012-02-16 21:40:57 +0800 | [diff] [blame] | 7111 | __set_bit(CAPABILITY_VCO_RECALIBRATION, &rt2x00dev->cap_flags); |
| 7112 | break; |
| 7113 | } |
| 7114 | |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7115 | return 0; |
| 7116 | } |
Gertjan van Wingerde | ad417a5 | 2012-09-03 03:25:51 +0200 | [diff] [blame] | 7117 | |
Gabor Juhos | cbafb60 | 2013-03-30 14:53:10 +0100 | [diff] [blame] | 7118 | static int rt2800_probe_rt(struct rt2x00_dev *rt2x00dev) |
| 7119 | { |
| 7120 | u32 reg; |
| 7121 | u32 rt; |
| 7122 | u32 rev; |
| 7123 | |
| 7124 | if (rt2x00_rt(rt2x00dev, RT3290)) |
| 7125 | rt2800_register_read(rt2x00dev, MAC_CSR0_3290, ®); |
| 7126 | else |
| 7127 | rt2800_register_read(rt2x00dev, MAC_CSR0, ®); |
| 7128 | |
| 7129 | rt = rt2x00_get_field32(reg, MAC_CSR0_CHIPSET); |
| 7130 | rev = rt2x00_get_field32(reg, MAC_CSR0_REVISION); |
| 7131 | |
| 7132 | switch (rt) { |
| 7133 | case RT2860: |
| 7134 | case RT2872: |
| 7135 | case RT2883: |
| 7136 | case RT3070: |
| 7137 | case RT3071: |
| 7138 | case RT3090: |
| 7139 | case RT3290: |
| 7140 | case RT3352: |
| 7141 | case RT3390: |
| 7142 | case RT3572: |
| 7143 | case RT5390: |
| 7144 | case RT5392: |
| 7145 | case RT5592: |
| 7146 | break; |
| 7147 | default: |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 7148 | rt2x00_err(rt2x00dev, "Invalid RT chipset 0x%04x, rev %04x detected\n", |
| 7149 | rt, rev); |
Gabor Juhos | cbafb60 | 2013-03-30 14:53:10 +0100 | [diff] [blame] | 7150 | return -ENODEV; |
| 7151 | } |
| 7152 | |
| 7153 | rt2x00_set_rt(rt2x00dev, rt, rev); |
| 7154 | |
| 7155 | return 0; |
| 7156 | } |
| 7157 | |
Gertjan van Wingerde | ad417a5 | 2012-09-03 03:25:51 +0200 | [diff] [blame] | 7158 | int rt2800_probe_hw(struct rt2x00_dev *rt2x00dev) |
| 7159 | { |
| 7160 | int retval; |
| 7161 | u32 reg; |
| 7162 | |
Gabor Juhos | cbafb60 | 2013-03-30 14:53:10 +0100 | [diff] [blame] | 7163 | retval = rt2800_probe_rt(rt2x00dev); |
| 7164 | if (retval) |
| 7165 | return retval; |
| 7166 | |
Gertjan van Wingerde | ad417a5 | 2012-09-03 03:25:51 +0200 | [diff] [blame] | 7167 | /* |
| 7168 | * Allocate eeprom data. |
| 7169 | */ |
| 7170 | retval = rt2800_validate_eeprom(rt2x00dev); |
| 7171 | if (retval) |
| 7172 | return retval; |
| 7173 | |
| 7174 | retval = rt2800_init_eeprom(rt2x00dev); |
| 7175 | if (retval) |
| 7176 | return retval; |
| 7177 | |
| 7178 | /* |
| 7179 | * Enable rfkill polling by setting GPIO direction of the |
| 7180 | * rfkill switch GPIO pin correctly. |
| 7181 | */ |
| 7182 | rt2800_register_read(rt2x00dev, GPIO_CTRL, ®); |
| 7183 | rt2x00_set_field32(®, GPIO_CTRL_DIR2, 1); |
| 7184 | rt2800_register_write(rt2x00dev, GPIO_CTRL, reg); |
| 7185 | |
| 7186 | /* |
| 7187 | * Initialize hw specifications. |
| 7188 | */ |
| 7189 | retval = rt2800_probe_hw_mode(rt2x00dev); |
| 7190 | if (retval) |
| 7191 | return retval; |
| 7192 | |
| 7193 | /* |
| 7194 | * Set device capabilities. |
| 7195 | */ |
| 7196 | __set_bit(CAPABILITY_CONTROL_FILTERS, &rt2x00dev->cap_flags); |
| 7197 | __set_bit(CAPABILITY_CONTROL_FILTER_PSPOLL, &rt2x00dev->cap_flags); |
| 7198 | if (!rt2x00_is_usb(rt2x00dev)) |
| 7199 | __set_bit(CAPABILITY_PRE_TBTT_INTERRUPT, &rt2x00dev->cap_flags); |
| 7200 | |
| 7201 | /* |
| 7202 | * Set device requirements. |
| 7203 | */ |
| 7204 | if (!rt2x00_is_soc(rt2x00dev)) |
| 7205 | __set_bit(REQUIRE_FIRMWARE, &rt2x00dev->cap_flags); |
| 7206 | __set_bit(REQUIRE_L2PAD, &rt2x00dev->cap_flags); |
| 7207 | __set_bit(REQUIRE_TXSTATUS_FIFO, &rt2x00dev->cap_flags); |
| 7208 | if (!rt2800_hwcrypt_disabled(rt2x00dev)) |
| 7209 | __set_bit(CAPABILITY_HW_CRYPTO, &rt2x00dev->cap_flags); |
| 7210 | __set_bit(CAPABILITY_LINK_TUNING, &rt2x00dev->cap_flags); |
| 7211 | __set_bit(REQUIRE_HT_TX_DESC, &rt2x00dev->cap_flags); |
| 7212 | if (rt2x00_is_usb(rt2x00dev)) |
| 7213 | __set_bit(REQUIRE_PS_AUTOWAKE, &rt2x00dev->cap_flags); |
| 7214 | else { |
| 7215 | __set_bit(REQUIRE_DMA, &rt2x00dev->cap_flags); |
| 7216 | __set_bit(REQUIRE_TASKLET_CONTEXT, &rt2x00dev->cap_flags); |
| 7217 | } |
| 7218 | |
| 7219 | /* |
| 7220 | * Set the rssi offset. |
| 7221 | */ |
| 7222 | rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET; |
| 7223 | |
| 7224 | return 0; |
| 7225 | } |
| 7226 | EXPORT_SYMBOL_GPL(rt2800_probe_hw); |
Bartlomiej Zolnierkiewicz | 4da2933 | 2009-11-08 14:39:32 +0100 | [diff] [blame] | 7227 | |
| 7228 | /* |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7229 | * IEEE80211 stack callback functions. |
| 7230 | */ |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 7231 | void rt2800_get_tkip_seq(struct ieee80211_hw *hw, u8 hw_key_idx, u32 *iv32, |
| 7232 | u16 *iv16) |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7233 | { |
| 7234 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 7235 | struct mac_iveiv_entry iveiv_entry; |
| 7236 | u32 offset; |
| 7237 | |
| 7238 | offset = MAC_IVEIV_ENTRY(hw_key_idx); |
| 7239 | rt2800_register_multiread(rt2x00dev, offset, |
| 7240 | &iveiv_entry, sizeof(iveiv_entry)); |
| 7241 | |
Julia Lawall | 855da5e | 2009-12-13 17:07:45 +0100 | [diff] [blame] | 7242 | memcpy(iv16, &iveiv_entry.iv[0], sizeof(*iv16)); |
| 7243 | memcpy(iv32, &iveiv_entry.iv[4], sizeof(*iv32)); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7244 | } |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 7245 | EXPORT_SYMBOL_GPL(rt2800_get_tkip_seq); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7246 | |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 7247 | int rt2800_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7248 | { |
| 7249 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 7250 | u32 reg; |
| 7251 | bool enabled = (value < IEEE80211_MAX_RTS_THRESHOLD); |
| 7252 | |
| 7253 | rt2800_register_read(rt2x00dev, TX_RTS_CFG, ®); |
| 7254 | rt2x00_set_field32(®, TX_RTS_CFG_RTS_THRES, value); |
| 7255 | rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg); |
| 7256 | |
| 7257 | rt2800_register_read(rt2x00dev, CCK_PROT_CFG, ®); |
| 7258 | rt2x00_set_field32(®, CCK_PROT_CFG_RTS_TH_EN, enabled); |
| 7259 | rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg); |
| 7260 | |
| 7261 | rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, ®); |
| 7262 | rt2x00_set_field32(®, OFDM_PROT_CFG_RTS_TH_EN, enabled); |
| 7263 | rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg); |
| 7264 | |
| 7265 | rt2800_register_read(rt2x00dev, MM20_PROT_CFG, ®); |
| 7266 | rt2x00_set_field32(®, MM20_PROT_CFG_RTS_TH_EN, enabled); |
| 7267 | rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg); |
| 7268 | |
| 7269 | rt2800_register_read(rt2x00dev, MM40_PROT_CFG, ®); |
| 7270 | rt2x00_set_field32(®, MM40_PROT_CFG_RTS_TH_EN, enabled); |
| 7271 | rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg); |
| 7272 | |
| 7273 | rt2800_register_read(rt2x00dev, GF20_PROT_CFG, ®); |
| 7274 | rt2x00_set_field32(®, GF20_PROT_CFG_RTS_TH_EN, enabled); |
| 7275 | rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg); |
| 7276 | |
| 7277 | rt2800_register_read(rt2x00dev, GF40_PROT_CFG, ®); |
| 7278 | rt2x00_set_field32(®, GF40_PROT_CFG_RTS_TH_EN, enabled); |
| 7279 | rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg); |
| 7280 | |
| 7281 | return 0; |
| 7282 | } |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 7283 | EXPORT_SYMBOL_GPL(rt2800_set_rts_threshold); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7284 | |
Eliad Peller | 8a3a3c8 | 2011-10-02 10:15:52 +0200 | [diff] [blame] | 7285 | int rt2800_conf_tx(struct ieee80211_hw *hw, |
| 7286 | struct ieee80211_vif *vif, u16 queue_idx, |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 7287 | const struct ieee80211_tx_queue_params *params) |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7288 | { |
| 7289 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 7290 | struct data_queue *queue; |
| 7291 | struct rt2x00_field32 field; |
| 7292 | int retval; |
| 7293 | u32 reg; |
| 7294 | u32 offset; |
| 7295 | |
| 7296 | /* |
| 7297 | * First pass the configuration through rt2x00lib, that will |
| 7298 | * update the queue settings and validate the input. After that |
| 7299 | * we are free to update the registers based on the value |
| 7300 | * in the queue parameter. |
| 7301 | */ |
Eliad Peller | 8a3a3c8 | 2011-10-02 10:15:52 +0200 | [diff] [blame] | 7302 | retval = rt2x00mac_conf_tx(hw, vif, queue_idx, params); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7303 | if (retval) |
| 7304 | return retval; |
| 7305 | |
| 7306 | /* |
| 7307 | * We only need to perform additional register initialization |
| 7308 | * for WMM queues/ |
| 7309 | */ |
| 7310 | if (queue_idx >= 4) |
| 7311 | return 0; |
| 7312 | |
Helmut Schaa | 11f818e | 2011-03-03 19:38:55 +0100 | [diff] [blame] | 7313 | queue = rt2x00queue_get_tx_queue(rt2x00dev, queue_idx); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7314 | |
| 7315 | /* Update WMM TXOP register */ |
| 7316 | offset = WMM_TXOP0_CFG + (sizeof(u32) * (!!(queue_idx & 2))); |
| 7317 | field.bit_offset = (queue_idx & 1) * 16; |
| 7318 | field.bit_mask = 0xffff << field.bit_offset; |
| 7319 | |
| 7320 | rt2800_register_read(rt2x00dev, offset, ®); |
| 7321 | rt2x00_set_field32(®, field, queue->txop); |
| 7322 | rt2800_register_write(rt2x00dev, offset, reg); |
| 7323 | |
| 7324 | /* Update WMM registers */ |
| 7325 | field.bit_offset = queue_idx * 4; |
| 7326 | field.bit_mask = 0xf << field.bit_offset; |
| 7327 | |
| 7328 | rt2800_register_read(rt2x00dev, WMM_AIFSN_CFG, ®); |
| 7329 | rt2x00_set_field32(®, field, queue->aifs); |
| 7330 | rt2800_register_write(rt2x00dev, WMM_AIFSN_CFG, reg); |
| 7331 | |
| 7332 | rt2800_register_read(rt2x00dev, WMM_CWMIN_CFG, ®); |
| 7333 | rt2x00_set_field32(®, field, queue->cw_min); |
| 7334 | rt2800_register_write(rt2x00dev, WMM_CWMIN_CFG, reg); |
| 7335 | |
| 7336 | rt2800_register_read(rt2x00dev, WMM_CWMAX_CFG, ®); |
| 7337 | rt2x00_set_field32(®, field, queue->cw_max); |
| 7338 | rt2800_register_write(rt2x00dev, WMM_CWMAX_CFG, reg); |
| 7339 | |
| 7340 | /* Update EDCA registers */ |
| 7341 | offset = EDCA_AC0_CFG + (sizeof(u32) * queue_idx); |
| 7342 | |
| 7343 | rt2800_register_read(rt2x00dev, offset, ®); |
| 7344 | rt2x00_set_field32(®, EDCA_AC0_CFG_TX_OP, queue->txop); |
| 7345 | rt2x00_set_field32(®, EDCA_AC0_CFG_AIFSN, queue->aifs); |
| 7346 | rt2x00_set_field32(®, EDCA_AC0_CFG_CWMIN, queue->cw_min); |
| 7347 | rt2x00_set_field32(®, EDCA_AC0_CFG_CWMAX, queue->cw_max); |
| 7348 | rt2800_register_write(rt2x00dev, offset, reg); |
| 7349 | |
| 7350 | return 0; |
| 7351 | } |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 7352 | EXPORT_SYMBOL_GPL(rt2800_conf_tx); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7353 | |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 7354 | u64 rt2800_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7355 | { |
| 7356 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 7357 | u64 tsf; |
| 7358 | u32 reg; |
| 7359 | |
| 7360 | rt2800_register_read(rt2x00dev, TSF_TIMER_DW1, ®); |
| 7361 | tsf = (u64) rt2x00_get_field32(reg, TSF_TIMER_DW1_HIGH_WORD) << 32; |
| 7362 | rt2800_register_read(rt2x00dev, TSF_TIMER_DW0, ®); |
| 7363 | tsf |= rt2x00_get_field32(reg, TSF_TIMER_DW0_LOW_WORD); |
| 7364 | |
| 7365 | return tsf; |
| 7366 | } |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 7367 | EXPORT_SYMBOL_GPL(rt2800_get_tsf); |
Bartlomiej Zolnierkiewicz | 2ce3399 | 2009-11-04 18:37:05 +0100 | [diff] [blame] | 7368 | |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 7369 | int rt2800_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 7370 | enum ieee80211_ampdu_mlme_action action, |
Johannes Berg | 0b01f03 | 2011-01-18 13:51:05 +0100 | [diff] [blame] | 7371 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, |
| 7372 | u8 buf_size) |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 7373 | { |
Helmut Schaa | af35323 | 2011-09-08 14:38:36 +0200 | [diff] [blame] | 7374 | struct rt2x00_sta *sta_priv = (struct rt2x00_sta *)sta->drv_priv; |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 7375 | int ret = 0; |
| 7376 | |
Helmut Schaa | af35323 | 2011-09-08 14:38:36 +0200 | [diff] [blame] | 7377 | /* |
| 7378 | * Don't allow aggregation for stations the hardware isn't aware |
| 7379 | * of because tx status reports for frames to an unknown station |
| 7380 | * always contain wcid=255 and thus we can't distinguish between |
| 7381 | * multiple stations which leads to unwanted situations when the |
| 7382 | * hw reorders frames due to aggregation. |
| 7383 | */ |
| 7384 | if (sta_priv->wcid < 0) |
| 7385 | return 1; |
| 7386 | |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 7387 | switch (action) { |
| 7388 | case IEEE80211_AMPDU_RX_START: |
| 7389 | case IEEE80211_AMPDU_RX_STOP: |
Helmut Schaa | 58ed826 | 2010-10-02 11:33:17 +0200 | [diff] [blame] | 7390 | /* |
| 7391 | * The hw itself takes care of setting up BlockAck mechanisms. |
| 7392 | * So, we only have to allow mac80211 to nagotiate a BlockAck |
| 7393 | * agreement. Once that is done, the hw will BlockAck incoming |
| 7394 | * AMPDUs without further setup. |
| 7395 | */ |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 7396 | break; |
| 7397 | case IEEE80211_AMPDU_TX_START: |
| 7398 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 7399 | break; |
Johannes Berg | 18b559d | 2012-07-18 13:51:25 +0200 | [diff] [blame] | 7400 | case IEEE80211_AMPDU_TX_STOP_CONT: |
| 7401 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 7402 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 7403 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 7404 | break; |
| 7405 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 7406 | break; |
| 7407 | default: |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 7408 | rt2x00_warn((struct rt2x00_dev *)hw->priv, |
| 7409 | "Unknown AMPDU action\n"); |
Helmut Schaa | 1df9080 | 2010-06-29 21:38:12 +0200 | [diff] [blame] | 7410 | } |
| 7411 | |
| 7412 | return ret; |
| 7413 | } |
Helmut Schaa | e783619 | 2010-07-11 12:28:54 +0200 | [diff] [blame] | 7414 | EXPORT_SYMBOL_GPL(rt2800_ampdu_action); |
Ivo van Doorn | a5ea2f0 | 2010-06-14 22:13:15 +0200 | [diff] [blame] | 7415 | |
Helmut Schaa | 977206d | 2010-12-13 12:31:58 +0100 | [diff] [blame] | 7416 | int rt2800_get_survey(struct ieee80211_hw *hw, int idx, |
| 7417 | struct survey_info *survey) |
| 7418 | { |
| 7419 | struct rt2x00_dev *rt2x00dev = hw->priv; |
| 7420 | struct ieee80211_conf *conf = &hw->conf; |
| 7421 | u32 idle, busy, busy_ext; |
| 7422 | |
| 7423 | if (idx != 0) |
| 7424 | return -ENOENT; |
| 7425 | |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 7426 | survey->channel = conf->chandef.chan; |
Helmut Schaa | 977206d | 2010-12-13 12:31:58 +0100 | [diff] [blame] | 7427 | |
| 7428 | rt2800_register_read(rt2x00dev, CH_IDLE_STA, &idle); |
| 7429 | rt2800_register_read(rt2x00dev, CH_BUSY_STA, &busy); |
| 7430 | rt2800_register_read(rt2x00dev, CH_BUSY_STA_SEC, &busy_ext); |
| 7431 | |
| 7432 | if (idle || busy) { |
| 7433 | survey->filled = SURVEY_INFO_CHANNEL_TIME | |
| 7434 | SURVEY_INFO_CHANNEL_TIME_BUSY | |
| 7435 | SURVEY_INFO_CHANNEL_TIME_EXT_BUSY; |
| 7436 | |
| 7437 | survey->channel_time = (idle + busy) / 1000; |
| 7438 | survey->channel_time_busy = busy / 1000; |
| 7439 | survey->channel_time_ext_busy = busy_ext / 1000; |
| 7440 | } |
| 7441 | |
Helmut Schaa | 9931df2 | 2011-12-22 09:36:29 +0100 | [diff] [blame] | 7442 | if (!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) |
| 7443 | survey->filled |= SURVEY_INFO_IN_USE; |
| 7444 | |
Helmut Schaa | 977206d | 2010-12-13 12:31:58 +0100 | [diff] [blame] | 7445 | return 0; |
| 7446 | |
| 7447 | } |
| 7448 | EXPORT_SYMBOL_GPL(rt2800_get_survey); |
| 7449 | |
Ivo van Doorn | a5ea2f0 | 2010-06-14 22:13:15 +0200 | [diff] [blame] | 7450 | MODULE_AUTHOR(DRV_PROJECT ", Bartlomiej Zolnierkiewicz"); |
| 7451 | MODULE_VERSION(DRV_VERSION); |
| 7452 | MODULE_DESCRIPTION("Ralink RT2800 library"); |
| 7453 | MODULE_LICENSE("GPL"); |