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