Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 1 | /* |
Sujith Manoharan | 5b68138 | 2011-05-17 13:36:18 +0530 | [diff] [blame] | 2 | * Copyright (c) 2008-2011 Atheros Communications Inc. |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
Pavel Roskin | 78fa99a | 2011-07-15 19:06:33 -0400 | [diff] [blame] | 17 | #include <asm/unaligned.h> |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 18 | #include "hw.h" |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 19 | #include "ar9002_phy.h" |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 20 | |
| 21 | static int ath9k_hw_4k_get_eeprom_ver(struct ath_hw *ah) |
| 22 | { |
| 23 | return ((ah->eeprom.map4k.baseEepHeader.version >> 12) & 0xF); |
| 24 | } |
| 25 | |
| 26 | static int ath9k_hw_4k_get_eeprom_rev(struct ath_hw *ah) |
| 27 | { |
| 28 | return ((ah->eeprom.map4k.baseEepHeader.version) & 0xFFF); |
| 29 | } |
| 30 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 31 | #define SIZE_EEPROM_4K (sizeof(struct ar5416_eeprom_4k) / sizeof(u16)) |
Sujith Manoharan | 04cf53f | 2011-01-04 13:17:28 +0530 | [diff] [blame] | 32 | |
| 33 | static bool __ath9k_hw_4k_fill_eeprom(struct ath_hw *ah) |
| 34 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 35 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 36 | u16 *eep_data = (u16 *)&ah->eeprom.map4k; |
Sujith Manoharan | 04cf53f | 2011-01-04 13:17:28 +0530 | [diff] [blame] | 37 | int addr, eep_start_loc = 64; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 38 | |
| 39 | for (addr = 0; addr < SIZE_EEPROM_4K; addr++) { |
Luis R. Rodriguez | 5bb1279 | 2009-09-14 00:55:09 -0700 | [diff] [blame] | 40 | if (!ath9k_hw_nvram_read(common, addr + eep_start_loc, eep_data)) { |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 41 | ath_dbg(common, ATH_DBG_EEPROM, |
| 42 | "Unable to read eeprom region\n"); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 43 | return false; |
| 44 | } |
| 45 | eep_data++; |
| 46 | } |
| 47 | |
| 48 | return true; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 49 | } |
| 50 | |
Sujith Manoharan | 04cf53f | 2011-01-04 13:17:28 +0530 | [diff] [blame] | 51 | static bool __ath9k_hw_usb_4k_fill_eeprom(struct ath_hw *ah) |
| 52 | { |
| 53 | u16 *eep_data = (u16 *)&ah->eeprom.map4k; |
| 54 | |
| 55 | ath9k_hw_usb_gen_fill_eeprom(ah, eep_data, 64, SIZE_EEPROM_4K); |
| 56 | |
| 57 | return true; |
| 58 | } |
| 59 | |
| 60 | static bool ath9k_hw_4k_fill_eeprom(struct ath_hw *ah) |
| 61 | { |
| 62 | struct ath_common *common = ath9k_hw_common(ah); |
| 63 | |
| 64 | if (!ath9k_hw_use_flash(ah)) { |
| 65 | ath_dbg(common, ATH_DBG_EEPROM, |
| 66 | "Reading from EEPROM, not flash\n"); |
| 67 | } |
| 68 | |
| 69 | if (common->bus_ops->ath_bus_type == ATH_USB) |
| 70 | return __ath9k_hw_usb_4k_fill_eeprom(ah); |
| 71 | else |
| 72 | return __ath9k_hw_4k_fill_eeprom(ah); |
| 73 | } |
| 74 | |
Rajkumar Manoharan | 4f011a2 | 2011-07-29 17:38:09 +0530 | [diff] [blame] | 75 | #if defined(CONFIG_ATH9K_DEBUGFS) || defined(CONFIG_ATH9K_HTC_DEBUGFS) |
| 76 | static u32 ath9k_dump_4k_modal_eeprom(char *buf, u32 len, u32 size, |
| 77 | struct modal_eep_4k_header *modal_hdr) |
| 78 | { |
| 79 | PR_EEP("Chain0 Ant. Control", modal_hdr->antCtrlChain[0]); |
| 80 | PR_EEP("Ant. Common Control", modal_hdr->antCtrlCommon); |
| 81 | PR_EEP("Chain0 Ant. Gain", modal_hdr->antennaGainCh[0]); |
| 82 | PR_EEP("Switch Settle", modal_hdr->switchSettling); |
| 83 | PR_EEP("Chain0 TxRxAtten", modal_hdr->txRxAttenCh[0]); |
| 84 | PR_EEP("Chain0 RxTxMargin", modal_hdr->rxTxMarginCh[0]); |
| 85 | PR_EEP("ADC Desired size", modal_hdr->adcDesiredSize); |
| 86 | PR_EEP("PGA Desired size", modal_hdr->pgaDesiredSize); |
| 87 | PR_EEP("Chain0 xlna Gain", modal_hdr->xlnaGainCh[0]); |
| 88 | PR_EEP("txEndToXpaOff", modal_hdr->txEndToXpaOff); |
| 89 | PR_EEP("txEndToRxOn", modal_hdr->txEndToRxOn); |
| 90 | PR_EEP("txFrameToXpaOn", modal_hdr->txFrameToXpaOn); |
| 91 | PR_EEP("CCA Threshold)", modal_hdr->thresh62); |
| 92 | PR_EEP("Chain0 NF Threshold", modal_hdr->noiseFloorThreshCh[0]); |
| 93 | PR_EEP("xpdGain", modal_hdr->xpdGain); |
| 94 | PR_EEP("External PD", modal_hdr->xpd); |
| 95 | PR_EEP("Chain0 I Coefficient", modal_hdr->iqCalICh[0]); |
| 96 | PR_EEP("Chain0 Q Coefficient", modal_hdr->iqCalQCh[0]); |
| 97 | PR_EEP("pdGainOverlap", modal_hdr->pdGainOverlap); |
| 98 | PR_EEP("O/D Bias Version", modal_hdr->version); |
| 99 | PR_EEP("CCK OutputBias", modal_hdr->ob_0); |
| 100 | PR_EEP("BPSK OutputBias", modal_hdr->ob_1); |
| 101 | PR_EEP("QPSK OutputBias", modal_hdr->ob_2); |
| 102 | PR_EEP("16QAM OutputBias", modal_hdr->ob_3); |
| 103 | PR_EEP("64QAM OutputBias", modal_hdr->ob_4); |
| 104 | PR_EEP("CCK Driver1_Bias", modal_hdr->db1_0); |
| 105 | PR_EEP("BPSK Driver1_Bias", modal_hdr->db1_1); |
| 106 | PR_EEP("QPSK Driver1_Bias", modal_hdr->db1_2); |
| 107 | PR_EEP("16QAM Driver1_Bias", modal_hdr->db1_3); |
| 108 | PR_EEP("64QAM Driver1_Bias", modal_hdr->db1_4); |
| 109 | PR_EEP("CCK Driver2_Bias", modal_hdr->db2_0); |
| 110 | PR_EEP("BPSK Driver2_Bias", modal_hdr->db2_1); |
| 111 | PR_EEP("QPSK Driver2_Bias", modal_hdr->db2_2); |
| 112 | PR_EEP("16QAM Driver2_Bias", modal_hdr->db2_3); |
| 113 | PR_EEP("64QAM Driver2_Bias", modal_hdr->db2_4); |
| 114 | PR_EEP("xPA Bias Level", modal_hdr->xpaBiasLvl); |
| 115 | PR_EEP("txFrameToDataStart", modal_hdr->txFrameToDataStart); |
| 116 | PR_EEP("txFrameToPaOn", modal_hdr->txFrameToPaOn); |
| 117 | PR_EEP("HT40 Power Inc.", modal_hdr->ht40PowerIncForPdadc); |
| 118 | PR_EEP("Chain0 bswAtten", modal_hdr->bswAtten[0]); |
| 119 | PR_EEP("Chain0 bswMargin", modal_hdr->bswMargin[0]); |
| 120 | PR_EEP("HT40 Switch Settle", modal_hdr->swSettleHt40); |
| 121 | PR_EEP("Chain0 xatten2Db", modal_hdr->xatten2Db[0]); |
| 122 | PR_EEP("Chain0 xatten2Margin", modal_hdr->xatten2Margin[0]); |
| 123 | PR_EEP("Ant. Diversity ctl1", modal_hdr->antdiv_ctl1); |
| 124 | PR_EEP("Ant. Diversity ctl2", modal_hdr->antdiv_ctl2); |
| 125 | PR_EEP("TX Diversity", modal_hdr->tx_diversity); |
| 126 | |
| 127 | return len; |
| 128 | } |
| 129 | |
| 130 | static u32 ath9k_hw_4k_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr, |
| 131 | u8 *buf, u32 len, u32 size) |
| 132 | { |
| 133 | struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k; |
| 134 | struct base_eep_header_4k *pBase = &eep->baseEepHeader; |
| 135 | |
| 136 | if (!dump_base_hdr) { |
| 137 | len += snprintf(buf + len, size - len, |
| 138 | "%20s :\n", "2GHz modal Header"); |
| 139 | len += ath9k_dump_4k_modal_eeprom(buf, len, size, |
| 140 | &eep->modalHeader); |
| 141 | goto out; |
| 142 | } |
| 143 | |
| 144 | PR_EEP("Major Version", pBase->version >> 12); |
| 145 | PR_EEP("Minor Version", pBase->version & 0xFFF); |
| 146 | PR_EEP("Checksum", pBase->checksum); |
| 147 | PR_EEP("Length", pBase->length); |
| 148 | PR_EEP("RegDomain1", pBase->regDmn[0]); |
| 149 | PR_EEP("RegDomain2", pBase->regDmn[1]); |
| 150 | PR_EEP("TX Mask", pBase->txMask); |
| 151 | PR_EEP("RX Mask", pBase->rxMask); |
| 152 | PR_EEP("Allow 5GHz", !!(pBase->opCapFlags & AR5416_OPFLAGS_11A)); |
| 153 | PR_EEP("Allow 2GHz", !!(pBase->opCapFlags & AR5416_OPFLAGS_11G)); |
| 154 | PR_EEP("Disable 2GHz HT20", !!(pBase->opCapFlags & |
| 155 | AR5416_OPFLAGS_N_2G_HT20)); |
| 156 | PR_EEP("Disable 2GHz HT40", !!(pBase->opCapFlags & |
| 157 | AR5416_OPFLAGS_N_2G_HT40)); |
| 158 | PR_EEP("Disable 5Ghz HT20", !!(pBase->opCapFlags & |
| 159 | AR5416_OPFLAGS_N_5G_HT20)); |
| 160 | PR_EEP("Disable 5Ghz HT40", !!(pBase->opCapFlags & |
| 161 | AR5416_OPFLAGS_N_5G_HT40)); |
| 162 | PR_EEP("Big Endian", !!(pBase->eepMisc & 0x01)); |
| 163 | PR_EEP("Cal Bin Major Ver", (pBase->binBuildNumber >> 24) & 0xFF); |
| 164 | PR_EEP("Cal Bin Minor Ver", (pBase->binBuildNumber >> 16) & 0xFF); |
| 165 | PR_EEP("Cal Bin Build", (pBase->binBuildNumber >> 8) & 0xFF); |
| 166 | PR_EEP("TX Gain type", pBase->txGainType); |
| 167 | |
| 168 | len += snprintf(buf + len, size - len, "%20s : %pM\n", "MacAddress", |
| 169 | pBase->macAddr); |
| 170 | |
| 171 | out: |
| 172 | if (len > size) |
| 173 | len = size; |
| 174 | |
| 175 | return len; |
| 176 | } |
| 177 | #else |
| 178 | static u32 ath9k_hw_4k_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr, |
| 179 | u8 *buf, u32 len, u32 size) |
| 180 | { |
| 181 | return 0; |
| 182 | } |
| 183 | #endif |
| 184 | |
| 185 | |
Sujith Manoharan | 04cf53f | 2011-01-04 13:17:28 +0530 | [diff] [blame] | 186 | #undef SIZE_EEPROM_4K |
| 187 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 188 | static int ath9k_hw_4k_check_eeprom(struct ath_hw *ah) |
| 189 | { |
| 190 | #define EEPROM_4K_SIZE (sizeof(struct ar5416_eeprom_4k) / sizeof(u16)) |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 191 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 192 | struct ar5416_eeprom_4k *eep = |
| 193 | (struct ar5416_eeprom_4k *) &ah->eeprom.map4k; |
| 194 | u16 *eepdata, temp, magic, magic2; |
| 195 | u32 sum = 0, el; |
| 196 | bool need_swap = false; |
| 197 | int i, addr; |
| 198 | |
| 199 | |
| 200 | if (!ath9k_hw_use_flash(ah)) { |
Luis R. Rodriguez | 5bb1279 | 2009-09-14 00:55:09 -0700 | [diff] [blame] | 201 | if (!ath9k_hw_nvram_read(common, AR5416_EEPROM_MAGIC_OFFSET, |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 202 | &magic)) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 203 | ath_err(common, "Reading Magic # failed\n"); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 204 | return false; |
| 205 | } |
| 206 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 207 | ath_dbg(common, ATH_DBG_EEPROM, |
| 208 | "Read Magic = 0x%04X\n", magic); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 209 | |
| 210 | if (magic != AR5416_EEPROM_MAGIC) { |
| 211 | magic2 = swab16(magic); |
| 212 | |
| 213 | if (magic2 == AR5416_EEPROM_MAGIC) { |
| 214 | need_swap = true; |
| 215 | eepdata = (u16 *) (&ah->eeprom); |
| 216 | |
| 217 | for (addr = 0; addr < EEPROM_4K_SIZE; addr++) { |
| 218 | temp = swab16(*eepdata); |
| 219 | *eepdata = temp; |
| 220 | eepdata++; |
| 221 | } |
| 222 | } else { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 223 | ath_err(common, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 224 | "Invalid EEPROM Magic. Endianness mismatch.\n"); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 225 | return -EINVAL; |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 230 | ath_dbg(common, ATH_DBG_EEPROM, "need_swap = %s.\n", |
| 231 | need_swap ? "True" : "False"); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 232 | |
| 233 | if (need_swap) |
| 234 | el = swab16(ah->eeprom.map4k.baseEepHeader.length); |
| 235 | else |
| 236 | el = ah->eeprom.map4k.baseEepHeader.length; |
| 237 | |
| 238 | if (el > sizeof(struct ar5416_eeprom_4k)) |
| 239 | el = sizeof(struct ar5416_eeprom_4k) / sizeof(u16); |
| 240 | else |
| 241 | el = el / sizeof(u16); |
| 242 | |
| 243 | eepdata = (u16 *)(&ah->eeprom); |
| 244 | |
| 245 | for (i = 0; i < el; i++) |
| 246 | sum ^= *eepdata++; |
| 247 | |
| 248 | if (need_swap) { |
| 249 | u32 integer; |
| 250 | u16 word; |
| 251 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 252 | ath_dbg(common, ATH_DBG_EEPROM, |
| 253 | "EEPROM Endianness is not native.. Changing\n"); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 254 | |
| 255 | word = swab16(eep->baseEepHeader.length); |
| 256 | eep->baseEepHeader.length = word; |
| 257 | |
| 258 | word = swab16(eep->baseEepHeader.checksum); |
| 259 | eep->baseEepHeader.checksum = word; |
| 260 | |
| 261 | word = swab16(eep->baseEepHeader.version); |
| 262 | eep->baseEepHeader.version = word; |
| 263 | |
| 264 | word = swab16(eep->baseEepHeader.regDmn[0]); |
| 265 | eep->baseEepHeader.regDmn[0] = word; |
| 266 | |
| 267 | word = swab16(eep->baseEepHeader.regDmn[1]); |
| 268 | eep->baseEepHeader.regDmn[1] = word; |
| 269 | |
| 270 | word = swab16(eep->baseEepHeader.rfSilent); |
| 271 | eep->baseEepHeader.rfSilent = word; |
| 272 | |
| 273 | word = swab16(eep->baseEepHeader.blueToothOptions); |
| 274 | eep->baseEepHeader.blueToothOptions = word; |
| 275 | |
| 276 | word = swab16(eep->baseEepHeader.deviceCap); |
| 277 | eep->baseEepHeader.deviceCap = word; |
| 278 | |
| 279 | integer = swab32(eep->modalHeader.antCtrlCommon); |
| 280 | eep->modalHeader.antCtrlCommon = integer; |
| 281 | |
| 282 | for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++) { |
| 283 | integer = swab32(eep->modalHeader.antCtrlChain[i]); |
| 284 | eep->modalHeader.antCtrlChain[i] = integer; |
| 285 | } |
| 286 | |
Felix Fietkau | 4ddfcd7 | 2010-12-12 00:51:08 +0100 | [diff] [blame] | 287 | for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) { |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 288 | word = swab16(eep->modalHeader.spurChans[i].spurChan); |
| 289 | eep->modalHeader.spurChans[i].spurChan = word; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR5416_EEP_VER || |
| 294 | ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 295 | ath_err(common, "Bad EEPROM checksum 0x%x or revision 0x%04x\n", |
| 296 | sum, ah->eep_ops->get_eeprom_ver(ah)); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 297 | return -EINVAL; |
| 298 | } |
| 299 | |
| 300 | return 0; |
| 301 | #undef EEPROM_4K_SIZE |
| 302 | } |
| 303 | |
| 304 | static u32 ath9k_hw_4k_get_eeprom(struct ath_hw *ah, |
| 305 | enum eeprom_param param) |
| 306 | { |
| 307 | struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k; |
| 308 | struct modal_eep_4k_header *pModal = &eep->modalHeader; |
| 309 | struct base_eep_header_4k *pBase = &eep->baseEepHeader; |
Gabor Juhos | 970bf9d | 2010-10-05 11:32:17 +0200 | [diff] [blame] | 310 | u16 ver_minor; |
| 311 | |
| 312 | ver_minor = pBase->version & AR5416_EEP_VER_MINOR_MASK; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 313 | |
| 314 | switch (param) { |
| 315 | case EEP_NFTHRESH_2: |
| 316 | return pModal->noiseFloorThreshCh[0]; |
Luis R. Rodriguez | 4910167 | 2010-04-15 17:39:13 -0400 | [diff] [blame] | 317 | case EEP_MAC_LSW: |
Pavel Roskin | 78fa99a | 2011-07-15 19:06:33 -0400 | [diff] [blame] | 318 | return get_unaligned_be16(pBase->macAddr); |
Luis R. Rodriguez | 4910167 | 2010-04-15 17:39:13 -0400 | [diff] [blame] | 319 | case EEP_MAC_MID: |
Pavel Roskin | 78fa99a | 2011-07-15 19:06:33 -0400 | [diff] [blame] | 320 | return get_unaligned_be16(pBase->macAddr + 2); |
Luis R. Rodriguez | 4910167 | 2010-04-15 17:39:13 -0400 | [diff] [blame] | 321 | case EEP_MAC_MSW: |
Pavel Roskin | 78fa99a | 2011-07-15 19:06:33 -0400 | [diff] [blame] | 322 | return get_unaligned_be16(pBase->macAddr + 4); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 323 | case EEP_REG_0: |
| 324 | return pBase->regDmn[0]; |
| 325 | case EEP_REG_1: |
| 326 | return pBase->regDmn[1]; |
| 327 | case EEP_OP_CAP: |
| 328 | return pBase->deviceCap; |
| 329 | case EEP_OP_MODE: |
| 330 | return pBase->opCapFlags; |
| 331 | case EEP_RF_SILENT: |
| 332 | return pBase->rfSilent; |
| 333 | case EEP_OB_2: |
Sujith | 7f63845 | 2009-08-07 09:45:23 +0530 | [diff] [blame] | 334 | return pModal->ob_0; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 335 | case EEP_DB_2: |
Sujith | 7f63845 | 2009-08-07 09:45:23 +0530 | [diff] [blame] | 336 | return pModal->db1_1; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 337 | case EEP_MINOR_REV: |
Gabor Juhos | 970bf9d | 2010-10-05 11:32:17 +0200 | [diff] [blame] | 338 | return ver_minor; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 339 | case EEP_TX_MASK: |
| 340 | return pBase->txMask; |
| 341 | case EEP_RX_MASK: |
| 342 | return pBase->rxMask; |
| 343 | case EEP_FRAC_N_5G: |
| 344 | return 0; |
Senthil Balasubramanian | e41f0bf | 2009-09-18 15:08:20 +0530 | [diff] [blame] | 345 | case EEP_PWR_TABLE_OFFSET: |
| 346 | return AR5416_PWR_TABLE_OFFSET_DB; |
Vasanthakumar Thiagarajan | 754dc53 | 2010-09-02 01:34:41 -0700 | [diff] [blame] | 347 | case EEP_MODAL_VER: |
| 348 | return pModal->version; |
| 349 | case EEP_ANT_DIV_CTL1: |
| 350 | return pModal->antdiv_ctl1; |
Gabor Juhos | 970bf9d | 2010-10-05 11:32:17 +0200 | [diff] [blame] | 351 | case EEP_TXGAIN_TYPE: |
Marek Lindner | f3d4505 | 2011-08-03 16:35:16 +0200 | [diff] [blame] | 352 | return pBase->txGainType; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 353 | default: |
| 354 | return 0; |
| 355 | } |
| 356 | } |
| 357 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 358 | static void ath9k_hw_set_4k_power_cal_table(struct ath_hw *ah, |
Felix Fietkau | e832bf1 | 2011-07-27 15:01:03 +0200 | [diff] [blame] | 359 | struct ath9k_channel *chan) |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 360 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 361 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 362 | struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k; |
| 363 | struct cal_data_per_freq_4k *pRawDataset; |
| 364 | u8 *pCalBChans = NULL; |
| 365 | u16 pdGainOverlap_t2; |
| 366 | static u8 pdadcValues[AR5416_NUM_PDADC_VALUES]; |
Felix Fietkau | 4ddfcd7 | 2010-12-12 00:51:08 +0100 | [diff] [blame] | 367 | u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK]; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 368 | u16 numPiers, i, j; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 369 | u16 numXpdGain, xpdMask; |
| 370 | u16 xpdGainValues[AR5416_EEP4K_NUM_PD_GAINS] = { 0, 0 }; |
| 371 | u32 reg32, regOffset, regChainOffset; |
| 372 | |
| 373 | xpdMask = pEepData->modalHeader.xpdGain; |
| 374 | |
| 375 | if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >= |
| 376 | AR5416_EEP_MINOR_VER_2) { |
| 377 | pdGainOverlap_t2 = |
| 378 | pEepData->modalHeader.pdGainOverlap; |
| 379 | } else { |
| 380 | pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5), |
| 381 | AR_PHY_TPCRG5_PD_GAIN_OVERLAP)); |
| 382 | } |
| 383 | |
| 384 | pCalBChans = pEepData->calFreqPier2G; |
| 385 | numPiers = AR5416_EEP4K_NUM_2G_CAL_PIERS; |
| 386 | |
| 387 | numXpdGain = 0; |
| 388 | |
Felix Fietkau | 4ddfcd7 | 2010-12-12 00:51:08 +0100 | [diff] [blame] | 389 | for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) { |
| 390 | if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) { |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 391 | if (numXpdGain >= AR5416_EEP4K_NUM_PD_GAINS) |
| 392 | break; |
| 393 | xpdGainValues[numXpdGain] = |
Felix Fietkau | 4ddfcd7 | 2010-12-12 00:51:08 +0100 | [diff] [blame] | 394 | (u16)(AR5416_PD_GAINS_IN_MASK - i); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 395 | numXpdGain++; |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN, |
| 400 | (numXpdGain - 1) & 0x3); |
| 401 | REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1, |
| 402 | xpdGainValues[0]); |
| 403 | REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2, |
| 404 | xpdGainValues[1]); |
| 405 | REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3, 0); |
| 406 | |
| 407 | for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++) { |
Felix Fietkau | 1b8714f | 2011-09-15 14:25:35 +0200 | [diff] [blame^] | 408 | regChainOffset = i * 0x1000; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 409 | |
| 410 | if (pEepData->baseEepHeader.txMask & (1 << i)) { |
| 411 | pRawDataset = pEepData->calPierData2G[i]; |
| 412 | |
Felix Fietkau | 115277a | 2010-12-12 00:51:09 +0100 | [diff] [blame] | 413 | ath9k_hw_get_gain_boundaries_pdadcs(ah, chan, |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 414 | pRawDataset, pCalBChans, |
| 415 | numPiers, pdGainOverlap_t2, |
Pavel Roskin | 6eb90d4 | 2010-07-06 12:51:27 -0400 | [diff] [blame] | 416 | gainBoundaries, |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 417 | pdadcValues, numXpdGain); |
| 418 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 419 | ENABLE_REGWRITE_BUFFER(ah); |
| 420 | |
Felix Fietkau | 1b8714f | 2011-09-15 14:25:35 +0200 | [diff] [blame^] | 421 | REG_WRITE(ah, AR_PHY_TPCRG5 + regChainOffset, |
| 422 | SM(pdGainOverlap_t2, |
| 423 | AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
| 424 | | SM(gainBoundaries[0], |
| 425 | AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1) |
| 426 | | SM(gainBoundaries[1], |
| 427 | AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2) |
| 428 | | SM(gainBoundaries[2], |
| 429 | AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3) |
| 430 | | SM(gainBoundaries[3], |
| 431 | AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4)); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 432 | |
| 433 | regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset; |
| 434 | for (j = 0; j < 32; j++) { |
Pavel Roskin | 78fa99a | 2011-07-15 19:06:33 -0400 | [diff] [blame] | 435 | reg32 = get_unaligned_le32(&pdadcValues[4 * j]); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 436 | REG_WRITE(ah, regOffset, reg32); |
| 437 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 438 | ath_dbg(common, ATH_DBG_EEPROM, |
| 439 | "PDADC (%d,%4x): %4.4x %8.8x\n", |
| 440 | i, regChainOffset, regOffset, |
| 441 | reg32); |
| 442 | ath_dbg(common, ATH_DBG_EEPROM, |
| 443 | "PDADC: Chain %d | " |
| 444 | "PDADC %3d Value %3d | " |
| 445 | "PDADC %3d Value %3d | " |
| 446 | "PDADC %3d Value %3d | " |
| 447 | "PDADC %3d Value %3d |\n", |
| 448 | i, 4 * j, pdadcValues[4 * j], |
| 449 | 4 * j + 1, pdadcValues[4 * j + 1], |
| 450 | 4 * j + 2, pdadcValues[4 * j + 2], |
| 451 | 4 * j + 3, pdadcValues[4 * j + 3]); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 452 | |
| 453 | regOffset += 4; |
| 454 | } |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 455 | |
| 456 | REGWRITE_BUFFER_FLUSH(ah); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 457 | } |
| 458 | } |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | static void ath9k_hw_set_4k_power_per_rate_table(struct ath_hw *ah, |
| 462 | struct ath9k_channel *chan, |
| 463 | int16_t *ratesArray, |
| 464 | u16 cfgCtl, |
| 465 | u16 AntennaReduction, |
| 466 | u16 twiceMaxRegulatoryPower, |
| 467 | u16 powerLimit) |
| 468 | { |
Sujith | 180d674b | 2009-08-07 09:45:33 +0530 | [diff] [blame] | 469 | #define CMP_TEST_GRP \ |
| 470 | (((cfgCtl & ~CTL_MODE_M)| (pCtlMode[ctlMode] & CTL_MODE_M)) == \ |
| 471 | pEepData->ctlIndex[i]) \ |
| 472 | || (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \ |
| 473 | ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL)) |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 474 | |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 475 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 476 | int i; |
| 477 | int16_t twiceLargestAntenna; |
Sujith | 180d674b | 2009-08-07 09:45:33 +0530 | [diff] [blame] | 478 | u16 twiceMinEdgePower; |
Felix Fietkau | 4ddfcd7 | 2010-12-12 00:51:08 +0100 | [diff] [blame] | 479 | u16 twiceMaxEdgePower = MAX_RATE_POWER; |
Sujith | 180d674b | 2009-08-07 09:45:33 +0530 | [diff] [blame] | 480 | u16 scaledPower = 0, minCtlPower, maxRegAllowedPower; |
Joe Perches | 07b2fa5 | 2010-11-20 18:38:53 -0800 | [diff] [blame] | 481 | u16 numCtlModes; |
| 482 | const u16 *pCtlMode; |
| 483 | u16 ctlMode, freq; |
Sujith | 180d674b | 2009-08-07 09:45:33 +0530 | [diff] [blame] | 484 | struct chan_centers centers; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 485 | struct cal_ctl_data_4k *rep; |
Sujith | 180d674b | 2009-08-07 09:45:33 +0530 | [diff] [blame] | 486 | struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k; |
| 487 | static const u16 tpScaleReductionTable[5] = |
Felix Fietkau | 4ddfcd7 | 2010-12-12 00:51:08 +0100 | [diff] [blame] | 488 | { 0, 3, 6, 9, MAX_RATE_POWER }; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 489 | struct cal_target_power_leg targetPowerOfdm, targetPowerCck = { |
| 490 | 0, { 0, 0, 0, 0} |
| 491 | }; |
| 492 | struct cal_target_power_leg targetPowerOfdmExt = { |
| 493 | 0, { 0, 0, 0, 0} }, targetPowerCckExt = { |
| 494 | 0, { 0, 0, 0, 0 } |
| 495 | }; |
| 496 | struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = { |
| 497 | 0, {0, 0, 0, 0} |
| 498 | }; |
Joe Perches | 07b2fa5 | 2010-11-20 18:38:53 -0800 | [diff] [blame] | 499 | static const u16 ctlModesFor11g[] = { |
| 500 | CTL_11B, CTL_11G, CTL_2GHT20, |
| 501 | CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40 |
| 502 | }; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 503 | |
| 504 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
| 505 | |
| 506 | twiceLargestAntenna = pEepData->modalHeader.antennaGainCh[0]; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 507 | twiceLargestAntenna = (int16_t)min(AntennaReduction - |
| 508 | twiceLargestAntenna, 0); |
| 509 | |
| 510 | maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna; |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 511 | if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX) { |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 512 | maxRegAllowedPower -= |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 513 | (tpScaleReductionTable[(regulatory->tp_scale)] * 2); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | scaledPower = min(powerLimit, maxRegAllowedPower); |
| 517 | scaledPower = max((u16)0, scaledPower); |
| 518 | |
| 519 | numCtlModes = ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40; |
| 520 | pCtlMode = ctlModesFor11g; |
| 521 | |
| 522 | ath9k_hw_get_legacy_target_powers(ah, chan, |
| 523 | pEepData->calTargetPowerCck, |
| 524 | AR5416_NUM_2G_CCK_TARGET_POWERS, |
| 525 | &targetPowerCck, 4, false); |
| 526 | ath9k_hw_get_legacy_target_powers(ah, chan, |
| 527 | pEepData->calTargetPower2G, |
| 528 | AR5416_NUM_2G_20_TARGET_POWERS, |
| 529 | &targetPowerOfdm, 4, false); |
| 530 | ath9k_hw_get_target_powers(ah, chan, |
| 531 | pEepData->calTargetPower2GHT20, |
| 532 | AR5416_NUM_2G_20_TARGET_POWERS, |
| 533 | &targetPowerHt20, 8, false); |
| 534 | |
| 535 | if (IS_CHAN_HT40(chan)) { |
| 536 | numCtlModes = ARRAY_SIZE(ctlModesFor11g); |
| 537 | ath9k_hw_get_target_powers(ah, chan, |
| 538 | pEepData->calTargetPower2GHT40, |
| 539 | AR5416_NUM_2G_40_TARGET_POWERS, |
| 540 | &targetPowerHt40, 8, true); |
| 541 | ath9k_hw_get_legacy_target_powers(ah, chan, |
| 542 | pEepData->calTargetPowerCck, |
| 543 | AR5416_NUM_2G_CCK_TARGET_POWERS, |
| 544 | &targetPowerCckExt, 4, true); |
| 545 | ath9k_hw_get_legacy_target_powers(ah, chan, |
| 546 | pEepData->calTargetPower2G, |
| 547 | AR5416_NUM_2G_20_TARGET_POWERS, |
| 548 | &targetPowerOfdmExt, 4, true); |
| 549 | } |
| 550 | |
| 551 | for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) { |
| 552 | bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) || |
| 553 | (pCtlMode[ctlMode] == CTL_2GHT40); |
Sujith | 180d674b | 2009-08-07 09:45:33 +0530 | [diff] [blame] | 554 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 555 | if (isHt40CtlMode) |
| 556 | freq = centers.synth_center; |
| 557 | else if (pCtlMode[ctlMode] & EXT_ADDITIVE) |
| 558 | freq = centers.ext_center; |
| 559 | else |
| 560 | freq = centers.ctl_center; |
| 561 | |
| 562 | if (ah->eep_ops->get_eeprom_ver(ah) == 14 && |
| 563 | ah->eep_ops->get_eeprom_rev(ah) <= 2) |
Felix Fietkau | 4ddfcd7 | 2010-12-12 00:51:08 +0100 | [diff] [blame] | 564 | twiceMaxEdgePower = MAX_RATE_POWER; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 565 | |
| 566 | for (i = 0; (i < AR5416_EEP4K_NUM_CTLS) && |
Sujith | 180d674b | 2009-08-07 09:45:33 +0530 | [diff] [blame] | 567 | pEepData->ctlIndex[i]; i++) { |
| 568 | |
| 569 | if (CMP_TEST_GRP) { |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 570 | rep = &(pEepData->ctlData[i]); |
| 571 | |
Sujith | 180d674b | 2009-08-07 09:45:33 +0530 | [diff] [blame] | 572 | twiceMinEdgePower = ath9k_hw_get_max_edge_power( |
| 573 | freq, |
| 574 | rep->ctlEdges[ |
| 575 | ar5416_get_ntxchains(ah->txchainmask) - 1], |
| 576 | IS_CHAN_2GHZ(chan), |
| 577 | AR5416_EEP4K_NUM_BAND_EDGES); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 578 | |
| 579 | if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) { |
| 580 | twiceMaxEdgePower = |
| 581 | min(twiceMaxEdgePower, |
| 582 | twiceMinEdgePower); |
| 583 | } else { |
| 584 | twiceMaxEdgePower = twiceMinEdgePower; |
| 585 | break; |
| 586 | } |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower); |
| 591 | |
| 592 | switch (pCtlMode[ctlMode]) { |
| 593 | case CTL_11B: |
Sujith | 180d674b | 2009-08-07 09:45:33 +0530 | [diff] [blame] | 594 | for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) { |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 595 | targetPowerCck.tPow2x[i] = |
| 596 | min((u16)targetPowerCck.tPow2x[i], |
| 597 | minCtlPower); |
| 598 | } |
| 599 | break; |
| 600 | case CTL_11G: |
Sujith | 180d674b | 2009-08-07 09:45:33 +0530 | [diff] [blame] | 601 | for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) { |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 602 | targetPowerOfdm.tPow2x[i] = |
| 603 | min((u16)targetPowerOfdm.tPow2x[i], |
| 604 | minCtlPower); |
| 605 | } |
| 606 | break; |
| 607 | case CTL_2GHT20: |
Sujith | 180d674b | 2009-08-07 09:45:33 +0530 | [diff] [blame] | 608 | for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) { |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 609 | targetPowerHt20.tPow2x[i] = |
| 610 | min((u16)targetPowerHt20.tPow2x[i], |
| 611 | minCtlPower); |
| 612 | } |
| 613 | break; |
| 614 | case CTL_11B_EXT: |
Sujith | 180d674b | 2009-08-07 09:45:33 +0530 | [diff] [blame] | 615 | targetPowerCckExt.tPow2x[0] = |
| 616 | min((u16)targetPowerCckExt.tPow2x[0], |
| 617 | minCtlPower); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 618 | break; |
| 619 | case CTL_11G_EXT: |
Sujith | 180d674b | 2009-08-07 09:45:33 +0530 | [diff] [blame] | 620 | targetPowerOfdmExt.tPow2x[0] = |
| 621 | min((u16)targetPowerOfdmExt.tPow2x[0], |
| 622 | minCtlPower); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 623 | break; |
| 624 | case CTL_2GHT40: |
Sujith | 180d674b | 2009-08-07 09:45:33 +0530 | [diff] [blame] | 625 | for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) { |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 626 | targetPowerHt40.tPow2x[i] = |
| 627 | min((u16)targetPowerHt40.tPow2x[i], |
| 628 | minCtlPower); |
| 629 | } |
| 630 | break; |
| 631 | default: |
| 632 | break; |
| 633 | } |
| 634 | } |
| 635 | |
Sujith | 180d674b | 2009-08-07 09:45:33 +0530 | [diff] [blame] | 636 | ratesArray[rate6mb] = |
| 637 | ratesArray[rate9mb] = |
| 638 | ratesArray[rate12mb] = |
| 639 | ratesArray[rate18mb] = |
| 640 | ratesArray[rate24mb] = |
| 641 | targetPowerOfdm.tPow2x[0]; |
| 642 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 643 | ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1]; |
| 644 | ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2]; |
| 645 | ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3]; |
| 646 | ratesArray[rateXr] = targetPowerOfdm.tPow2x[0]; |
| 647 | |
| 648 | for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) |
| 649 | ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i]; |
| 650 | |
| 651 | ratesArray[rate1l] = targetPowerCck.tPow2x[0]; |
| 652 | ratesArray[rate2s] = ratesArray[rate2l] = targetPowerCck.tPow2x[1]; |
| 653 | ratesArray[rate5_5s] = ratesArray[rate5_5l] = targetPowerCck.tPow2x[2]; |
| 654 | ratesArray[rate11s] = ratesArray[rate11l] = targetPowerCck.tPow2x[3]; |
| 655 | |
| 656 | if (IS_CHAN_HT40(chan)) { |
| 657 | for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) { |
| 658 | ratesArray[rateHt40_0 + i] = |
| 659 | targetPowerHt40.tPow2x[i]; |
| 660 | } |
| 661 | ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0]; |
| 662 | ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0]; |
| 663 | ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0]; |
| 664 | ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0]; |
| 665 | } |
Sujith | 180d674b | 2009-08-07 09:45:33 +0530 | [diff] [blame] | 666 | |
| 667 | #undef CMP_TEST_GRP |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | static void ath9k_hw_4k_set_txpower(struct ath_hw *ah, |
Sujith | bf466fb | 2009-08-07 09:45:30 +0530 | [diff] [blame] | 671 | struct ath9k_channel *chan, |
| 672 | u16 cfgCtl, |
| 673 | u8 twiceAntennaReduction, |
| 674 | u8 twiceMaxRegulatoryPower, |
Felix Fietkau | de40f31 | 2010-10-20 03:08:53 +0200 | [diff] [blame] | 675 | u8 powerLimit, bool test) |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 676 | { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 677 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 678 | struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k; |
| 679 | struct modal_eep_4k_header *pModal = &pEepData->modalHeader; |
| 680 | int16_t ratesArray[Ar5416RateSize]; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 681 | u8 ht40PowerIncForPdadc = 2; |
| 682 | int i; |
| 683 | |
| 684 | memset(ratesArray, 0, sizeof(ratesArray)); |
| 685 | |
| 686 | if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >= |
| 687 | AR5416_EEP_MINOR_VER_2) { |
| 688 | ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc; |
| 689 | } |
| 690 | |
| 691 | ath9k_hw_set_4k_power_per_rate_table(ah, chan, |
Sujith | bf466fb | 2009-08-07 09:45:30 +0530 | [diff] [blame] | 692 | &ratesArray[0], cfgCtl, |
| 693 | twiceAntennaReduction, |
| 694 | twiceMaxRegulatoryPower, |
| 695 | powerLimit); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 696 | |
Felix Fietkau | e832bf1 | 2011-07-27 15:01:03 +0200 | [diff] [blame] | 697 | ath9k_hw_set_4k_power_cal_table(ah, chan); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 698 | |
Felix Fietkau | de40f31 | 2010-10-20 03:08:53 +0200 | [diff] [blame] | 699 | regulatory->max_power_level = 0; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 700 | for (i = 0; i < ARRAY_SIZE(ratesArray); i++) { |
Felix Fietkau | 4ddfcd7 | 2010-12-12 00:51:08 +0100 | [diff] [blame] | 701 | if (ratesArray[i] > MAX_RATE_POWER) |
| 702 | ratesArray[i] = MAX_RATE_POWER; |
Felix Fietkau | de40f31 | 2010-10-20 03:08:53 +0200 | [diff] [blame] | 703 | |
| 704 | if (ratesArray[i] > regulatory->max_power_level) |
| 705 | regulatory->max_power_level = ratesArray[i]; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 706 | } |
| 707 | |
Felix Fietkau | de40f31 | 2010-10-20 03:08:53 +0200 | [diff] [blame] | 708 | if (test) |
| 709 | return; |
Sujith | bf466fb | 2009-08-07 09:45:30 +0530 | [diff] [blame] | 710 | |
Felix Fietkau | 1b8714f | 2011-09-15 14:25:35 +0200 | [diff] [blame^] | 711 | for (i = 0; i < Ar5416RateSize; i++) |
| 712 | ratesArray[i] -= AR5416_PWR_TABLE_OFFSET_DB * 2; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 713 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 714 | ENABLE_REGWRITE_BUFFER(ah); |
| 715 | |
Sujith | bf466fb | 2009-08-07 09:45:30 +0530 | [diff] [blame] | 716 | /* OFDM power per rate */ |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 717 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE1, |
| 718 | ATH9K_POW_SM(ratesArray[rate18mb], 24) |
| 719 | | ATH9K_POW_SM(ratesArray[rate12mb], 16) |
| 720 | | ATH9K_POW_SM(ratesArray[rate9mb], 8) |
| 721 | | ATH9K_POW_SM(ratesArray[rate6mb], 0)); |
| 722 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE2, |
| 723 | ATH9K_POW_SM(ratesArray[rate54mb], 24) |
| 724 | | ATH9K_POW_SM(ratesArray[rate48mb], 16) |
| 725 | | ATH9K_POW_SM(ratesArray[rate36mb], 8) |
| 726 | | ATH9K_POW_SM(ratesArray[rate24mb], 0)); |
| 727 | |
Sujith | bf466fb | 2009-08-07 09:45:30 +0530 | [diff] [blame] | 728 | /* CCK power per rate */ |
| 729 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE3, |
| 730 | ATH9K_POW_SM(ratesArray[rate2s], 24) |
| 731 | | ATH9K_POW_SM(ratesArray[rate2l], 16) |
| 732 | | ATH9K_POW_SM(ratesArray[rateXr], 8) |
| 733 | | ATH9K_POW_SM(ratesArray[rate1l], 0)); |
| 734 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE4, |
| 735 | ATH9K_POW_SM(ratesArray[rate11s], 24) |
| 736 | | ATH9K_POW_SM(ratesArray[rate11l], 16) |
| 737 | | ATH9K_POW_SM(ratesArray[rate5_5s], 8) |
| 738 | | ATH9K_POW_SM(ratesArray[rate5_5l], 0)); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 739 | |
Sujith | bf466fb | 2009-08-07 09:45:30 +0530 | [diff] [blame] | 740 | /* HT20 power per rate */ |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 741 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE5, |
| 742 | ATH9K_POW_SM(ratesArray[rateHt20_3], 24) |
| 743 | | ATH9K_POW_SM(ratesArray[rateHt20_2], 16) |
| 744 | | ATH9K_POW_SM(ratesArray[rateHt20_1], 8) |
| 745 | | ATH9K_POW_SM(ratesArray[rateHt20_0], 0)); |
| 746 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE6, |
| 747 | ATH9K_POW_SM(ratesArray[rateHt20_7], 24) |
| 748 | | ATH9K_POW_SM(ratesArray[rateHt20_6], 16) |
| 749 | | ATH9K_POW_SM(ratesArray[rateHt20_5], 8) |
| 750 | | ATH9K_POW_SM(ratesArray[rateHt20_4], 0)); |
| 751 | |
Sujith | bf466fb | 2009-08-07 09:45:30 +0530 | [diff] [blame] | 752 | /* HT40 power per rate */ |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 753 | if (IS_CHAN_HT40(chan)) { |
| 754 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE7, |
| 755 | ATH9K_POW_SM(ratesArray[rateHt40_3] + |
| 756 | ht40PowerIncForPdadc, 24) |
| 757 | | ATH9K_POW_SM(ratesArray[rateHt40_2] + |
| 758 | ht40PowerIncForPdadc, 16) |
| 759 | | ATH9K_POW_SM(ratesArray[rateHt40_1] + |
| 760 | ht40PowerIncForPdadc, 8) |
| 761 | | ATH9K_POW_SM(ratesArray[rateHt40_0] + |
| 762 | ht40PowerIncForPdadc, 0)); |
| 763 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE8, |
| 764 | ATH9K_POW_SM(ratesArray[rateHt40_7] + |
| 765 | ht40PowerIncForPdadc, 24) |
| 766 | | ATH9K_POW_SM(ratesArray[rateHt40_6] + |
| 767 | ht40PowerIncForPdadc, 16) |
| 768 | | ATH9K_POW_SM(ratesArray[rateHt40_5] + |
| 769 | ht40PowerIncForPdadc, 8) |
| 770 | | ATH9K_POW_SM(ratesArray[rateHt40_4] + |
| 771 | ht40PowerIncForPdadc, 0)); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 772 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE9, |
| 773 | ATH9K_POW_SM(ratesArray[rateExtOfdm], 24) |
| 774 | | ATH9K_POW_SM(ratesArray[rateExtCck], 16) |
| 775 | | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8) |
| 776 | | ATH9K_POW_SM(ratesArray[rateDupCck], 0)); |
| 777 | } |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 778 | |
| 779 | REGWRITE_BUFFER_FLUSH(ah); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | static void ath9k_hw_4k_set_addac(struct ath_hw *ah, |
| 783 | struct ath9k_channel *chan) |
| 784 | { |
| 785 | struct modal_eep_4k_header *pModal; |
| 786 | struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k; |
| 787 | u8 biaslevel; |
| 788 | |
| 789 | if (ah->hw_version.macVersion != AR_SREV_VERSION_9160) |
| 790 | return; |
| 791 | |
| 792 | if (ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_MINOR_VER_7) |
| 793 | return; |
| 794 | |
| 795 | pModal = &eep->modalHeader; |
| 796 | |
| 797 | if (pModal->xpaBiasLvl != 0xff) { |
| 798 | biaslevel = pModal->xpaBiasLvl; |
| 799 | INI_RA(&ah->iniAddac, 7, 1) = |
| 800 | (INI_RA(&ah->iniAddac, 7, 1) & (~0x18)) | biaslevel << 3; |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | static void ath9k_hw_4k_set_gain(struct ath_hw *ah, |
| 805 | struct modal_eep_4k_header *pModal, |
| 806 | struct ar5416_eeprom_4k *eep, |
Sujith | a37414a | 2009-08-07 09:45:19 +0530 | [diff] [blame] | 807 | u8 txRxAttenLocal) |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 808 | { |
Sujith | a37414a | 2009-08-07 09:45:19 +0530 | [diff] [blame] | 809 | REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0, |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 810 | pModal->antCtrlChain[0]); |
| 811 | |
Sujith | a37414a | 2009-08-07 09:45:19 +0530 | [diff] [blame] | 812 | REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), |
| 813 | (REG_READ(ah, AR_PHY_TIMING_CTRL4(0)) & |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 814 | ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF | |
| 815 | AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) | |
| 816 | SM(pModal->iqCalICh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) | |
| 817 | SM(pModal->iqCalQCh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF)); |
| 818 | |
| 819 | if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >= |
| 820 | AR5416_EEP_MINOR_VER_3) { |
| 821 | txRxAttenLocal = pModal->txRxAttenCh[0]; |
| 822 | |
Sujith | a37414a | 2009-08-07 09:45:19 +0530 | [diff] [blame] | 823 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ, |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 824 | AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN, pModal->bswMargin[0]); |
Sujith | a37414a | 2009-08-07 09:45:19 +0530 | [diff] [blame] | 825 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ, |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 826 | AR_PHY_GAIN_2GHZ_XATTEN1_DB, pModal->bswAtten[0]); |
Sujith | a37414a | 2009-08-07 09:45:19 +0530 | [diff] [blame] | 827 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ, |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 828 | AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN, |
| 829 | pModal->xatten2Margin[0]); |
Sujith | a37414a | 2009-08-07 09:45:19 +0530 | [diff] [blame] | 830 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ, |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 831 | AR_PHY_GAIN_2GHZ_XATTEN2_DB, pModal->xatten2Db[0]); |
| 832 | |
| 833 | /* Set the block 1 value to block 0 value */ |
| 834 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000, |
| 835 | AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN, |
| 836 | pModal->bswMargin[0]); |
| 837 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000, |
| 838 | AR_PHY_GAIN_2GHZ_XATTEN1_DB, pModal->bswAtten[0]); |
| 839 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000, |
| 840 | AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN, |
| 841 | pModal->xatten2Margin[0]); |
| 842 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000, |
| 843 | AR_PHY_GAIN_2GHZ_XATTEN2_DB, |
| 844 | pModal->xatten2Db[0]); |
| 845 | } |
| 846 | |
Sujith | a37414a | 2009-08-07 09:45:19 +0530 | [diff] [blame] | 847 | REG_RMW_FIELD(ah, AR_PHY_RXGAIN, |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 848 | AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal); |
Sujith | a37414a | 2009-08-07 09:45:19 +0530 | [diff] [blame] | 849 | REG_RMW_FIELD(ah, AR_PHY_RXGAIN, |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 850 | AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[0]); |
| 851 | |
| 852 | REG_RMW_FIELD(ah, AR_PHY_RXGAIN + 0x1000, |
| 853 | AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal); |
| 854 | REG_RMW_FIELD(ah, AR_PHY_RXGAIN + 0x1000, |
| 855 | AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[0]); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | /* |
| 859 | * Read EEPROM header info and program the device for correct operation |
| 860 | * given the channel value. |
| 861 | */ |
| 862 | static void ath9k_hw_4k_set_board_values(struct ath_hw *ah, |
| 863 | struct ath9k_channel *chan) |
| 864 | { |
| 865 | struct modal_eep_4k_header *pModal; |
| 866 | struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k; |
Rajkumar Manoharan | d88525e | 2011-04-06 21:42:52 +0530 | [diff] [blame] | 867 | struct base_eep_header_4k *pBase = &eep->baseEepHeader; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 868 | u8 txRxAttenLocal; |
| 869 | u8 ob[5], db1[5], db2[5]; |
| 870 | u8 ant_div_control1, ant_div_control2; |
Felix Fietkau | 1b8714f | 2011-09-15 14:25:35 +0200 | [diff] [blame^] | 871 | u8 bb_desired_scale; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 872 | u32 regVal; |
| 873 | |
| 874 | pModal = &eep->modalHeader; |
| 875 | txRxAttenLocal = 23; |
| 876 | |
Felix Fietkau | df3c8b2 | 2010-12-12 00:51:11 +0100 | [diff] [blame] | 877 | REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 878 | |
| 879 | /* Single chain for 4K EEPROM*/ |
Sujith | a37414a | 2009-08-07 09:45:19 +0530 | [diff] [blame] | 880 | ath9k_hw_4k_set_gain(ah, pModal, eep, txRxAttenLocal); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 881 | |
| 882 | /* Initialize Ant Diversity settings from EEPROM */ |
| 883 | if (pModal->version >= 3) { |
Sujith | 7f63845 | 2009-08-07 09:45:23 +0530 | [diff] [blame] | 884 | ant_div_control1 = pModal->antdiv_ctl1; |
| 885 | ant_div_control2 = pModal->antdiv_ctl2; |
| 886 | |
| 887 | regVal = REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL); |
| 888 | regVal &= (~(AR_PHY_9285_ANT_DIV_CTL_ALL)); |
| 889 | |
| 890 | regVal |= SM(ant_div_control1, |
| 891 | AR_PHY_9285_ANT_DIV_CTL); |
| 892 | regVal |= SM(ant_div_control2, |
| 893 | AR_PHY_9285_ANT_DIV_ALT_LNACONF); |
| 894 | regVal |= SM((ant_div_control2 >> 2), |
| 895 | AR_PHY_9285_ANT_DIV_MAIN_LNACONF); |
| 896 | regVal |= SM((ant_div_control1 >> 1), |
| 897 | AR_PHY_9285_ANT_DIV_ALT_GAINTB); |
| 898 | regVal |= SM((ant_div_control1 >> 2), |
| 899 | AR_PHY_9285_ANT_DIV_MAIN_GAINTB); |
| 900 | |
| 901 | |
| 902 | REG_WRITE(ah, AR_PHY_MULTICHAIN_GAIN_CTL, regVal); |
| 903 | regVal = REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL); |
| 904 | regVal = REG_READ(ah, AR_PHY_CCK_DETECT); |
| 905 | regVal &= (~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV); |
| 906 | regVal |= SM((ant_div_control1 >> 3), |
| 907 | AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV); |
| 908 | |
| 909 | REG_WRITE(ah, AR_PHY_CCK_DETECT, regVal); |
| 910 | regVal = REG_READ(ah, AR_PHY_CCK_DETECT); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | if (pModal->version >= 2) { |
Sujith | 7f63845 | 2009-08-07 09:45:23 +0530 | [diff] [blame] | 914 | ob[0] = pModal->ob_0; |
| 915 | ob[1] = pModal->ob_1; |
| 916 | ob[2] = pModal->ob_2; |
| 917 | ob[3] = pModal->ob_3; |
| 918 | ob[4] = pModal->ob_4; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 919 | |
Sujith | 7f63845 | 2009-08-07 09:45:23 +0530 | [diff] [blame] | 920 | db1[0] = pModal->db1_0; |
| 921 | db1[1] = pModal->db1_1; |
| 922 | db1[2] = pModal->db1_2; |
| 923 | db1[3] = pModal->db1_3; |
| 924 | db1[4] = pModal->db1_4; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 925 | |
Sujith | 7f63845 | 2009-08-07 09:45:23 +0530 | [diff] [blame] | 926 | db2[0] = pModal->db2_0; |
| 927 | db2[1] = pModal->db2_1; |
| 928 | db2[2] = pModal->db2_2; |
| 929 | db2[3] = pModal->db2_3; |
| 930 | db2[4] = pModal->db2_4; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 931 | } else if (pModal->version == 1) { |
Sujith | 7f63845 | 2009-08-07 09:45:23 +0530 | [diff] [blame] | 932 | ob[0] = pModal->ob_0; |
| 933 | ob[1] = ob[2] = ob[3] = ob[4] = pModal->ob_1; |
| 934 | db1[0] = pModal->db1_0; |
| 935 | db1[1] = db1[2] = db1[3] = db1[4] = pModal->db1_1; |
| 936 | db2[0] = pModal->db2_0; |
| 937 | db2[1] = db2[2] = db2[3] = db2[4] = pModal->db2_1; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 938 | } else { |
| 939 | int i; |
Sujith | 7f63845 | 2009-08-07 09:45:23 +0530 | [diff] [blame] | 940 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 941 | for (i = 0; i < 5; i++) { |
Sujith | 7f63845 | 2009-08-07 09:45:23 +0530 | [diff] [blame] | 942 | ob[i] = pModal->ob_0; |
| 943 | db1[i] = pModal->db1_0; |
| 944 | db2[i] = pModal->db1_0; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 945 | } |
| 946 | } |
| 947 | |
| 948 | if (AR_SREV_9271(ah)) { |
| 949 | ath9k_hw_analog_shift_rmw(ah, |
| 950 | AR9285_AN_RF2G3, |
| 951 | AR9271_AN_RF2G3_OB_cck, |
| 952 | AR9271_AN_RF2G3_OB_cck_S, |
| 953 | ob[0]); |
| 954 | ath9k_hw_analog_shift_rmw(ah, |
| 955 | AR9285_AN_RF2G3, |
| 956 | AR9271_AN_RF2G3_OB_psk, |
| 957 | AR9271_AN_RF2G3_OB_psk_S, |
| 958 | ob[1]); |
| 959 | ath9k_hw_analog_shift_rmw(ah, |
| 960 | AR9285_AN_RF2G3, |
| 961 | AR9271_AN_RF2G3_OB_qam, |
| 962 | AR9271_AN_RF2G3_OB_qam_S, |
| 963 | ob[2]); |
| 964 | ath9k_hw_analog_shift_rmw(ah, |
| 965 | AR9285_AN_RF2G3, |
| 966 | AR9271_AN_RF2G3_DB_1, |
| 967 | AR9271_AN_RF2G3_DB_1_S, |
| 968 | db1[0]); |
| 969 | ath9k_hw_analog_shift_rmw(ah, |
| 970 | AR9285_AN_RF2G4, |
| 971 | AR9271_AN_RF2G4_DB_2, |
| 972 | AR9271_AN_RF2G4_DB_2_S, |
| 973 | db2[0]); |
| 974 | } else { |
| 975 | ath9k_hw_analog_shift_rmw(ah, |
| 976 | AR9285_AN_RF2G3, |
| 977 | AR9285_AN_RF2G3_OB_0, |
| 978 | AR9285_AN_RF2G3_OB_0_S, |
| 979 | ob[0]); |
| 980 | ath9k_hw_analog_shift_rmw(ah, |
| 981 | AR9285_AN_RF2G3, |
| 982 | AR9285_AN_RF2G3_OB_1, |
| 983 | AR9285_AN_RF2G3_OB_1_S, |
| 984 | ob[1]); |
| 985 | ath9k_hw_analog_shift_rmw(ah, |
| 986 | AR9285_AN_RF2G3, |
| 987 | AR9285_AN_RF2G3_OB_2, |
| 988 | AR9285_AN_RF2G3_OB_2_S, |
| 989 | ob[2]); |
| 990 | ath9k_hw_analog_shift_rmw(ah, |
| 991 | AR9285_AN_RF2G3, |
| 992 | AR9285_AN_RF2G3_OB_3, |
| 993 | AR9285_AN_RF2G3_OB_3_S, |
| 994 | ob[3]); |
| 995 | ath9k_hw_analog_shift_rmw(ah, |
| 996 | AR9285_AN_RF2G3, |
| 997 | AR9285_AN_RF2G3_OB_4, |
| 998 | AR9285_AN_RF2G3_OB_4_S, |
| 999 | ob[4]); |
| 1000 | |
| 1001 | ath9k_hw_analog_shift_rmw(ah, |
| 1002 | AR9285_AN_RF2G3, |
| 1003 | AR9285_AN_RF2G3_DB1_0, |
| 1004 | AR9285_AN_RF2G3_DB1_0_S, |
| 1005 | db1[0]); |
| 1006 | ath9k_hw_analog_shift_rmw(ah, |
| 1007 | AR9285_AN_RF2G3, |
| 1008 | AR9285_AN_RF2G3_DB1_1, |
| 1009 | AR9285_AN_RF2G3_DB1_1_S, |
| 1010 | db1[1]); |
| 1011 | ath9k_hw_analog_shift_rmw(ah, |
| 1012 | AR9285_AN_RF2G3, |
| 1013 | AR9285_AN_RF2G3_DB1_2, |
| 1014 | AR9285_AN_RF2G3_DB1_2_S, |
| 1015 | db1[2]); |
| 1016 | ath9k_hw_analog_shift_rmw(ah, |
| 1017 | AR9285_AN_RF2G4, |
| 1018 | AR9285_AN_RF2G4_DB1_3, |
| 1019 | AR9285_AN_RF2G4_DB1_3_S, |
| 1020 | db1[3]); |
| 1021 | ath9k_hw_analog_shift_rmw(ah, |
| 1022 | AR9285_AN_RF2G4, |
| 1023 | AR9285_AN_RF2G4_DB1_4, |
| 1024 | AR9285_AN_RF2G4_DB1_4_S, db1[4]); |
| 1025 | |
| 1026 | ath9k_hw_analog_shift_rmw(ah, |
| 1027 | AR9285_AN_RF2G4, |
| 1028 | AR9285_AN_RF2G4_DB2_0, |
| 1029 | AR9285_AN_RF2G4_DB2_0_S, |
| 1030 | db2[0]); |
| 1031 | ath9k_hw_analog_shift_rmw(ah, |
| 1032 | AR9285_AN_RF2G4, |
| 1033 | AR9285_AN_RF2G4_DB2_1, |
| 1034 | AR9285_AN_RF2G4_DB2_1_S, |
| 1035 | db2[1]); |
| 1036 | ath9k_hw_analog_shift_rmw(ah, |
| 1037 | AR9285_AN_RF2G4, |
| 1038 | AR9285_AN_RF2G4_DB2_2, |
| 1039 | AR9285_AN_RF2G4_DB2_2_S, |
| 1040 | db2[2]); |
| 1041 | ath9k_hw_analog_shift_rmw(ah, |
| 1042 | AR9285_AN_RF2G4, |
| 1043 | AR9285_AN_RF2G4_DB2_3, |
| 1044 | AR9285_AN_RF2G4_DB2_3_S, |
| 1045 | db2[3]); |
| 1046 | ath9k_hw_analog_shift_rmw(ah, |
| 1047 | AR9285_AN_RF2G4, |
| 1048 | AR9285_AN_RF2G4_DB2_4, |
| 1049 | AR9285_AN_RF2G4_DB2_4_S, |
| 1050 | db2[4]); |
| 1051 | } |
| 1052 | |
| 1053 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 1054 | REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH, |
| 1055 | pModal->switchSettling); |
| 1056 | REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC, |
| 1057 | pModal->adcDesiredSize); |
| 1058 | |
| 1059 | REG_WRITE(ah, AR_PHY_RF_CTL4, |
| 1060 | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF) | |
| 1061 | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF) | |
| 1062 | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON) | |
| 1063 | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON)); |
| 1064 | |
| 1065 | REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON, |
| 1066 | pModal->txEndToRxOn); |
Luis R. Rodriguez | 0cab655 | 2009-10-19 02:33:32 -0400 | [diff] [blame] | 1067 | |
| 1068 | if (AR_SREV_9271_10(ah)) |
| 1069 | REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON, |
| 1070 | pModal->txEndToRxOn); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 1071 | REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62, |
| 1072 | pModal->thresh62); |
| 1073 | REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0, AR_PHY_EXT_CCA0_THRESH62, |
| 1074 | pModal->thresh62); |
| 1075 | |
| 1076 | if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >= |
| 1077 | AR5416_EEP_MINOR_VER_2) { |
| 1078 | REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_DATA_START, |
| 1079 | pModal->txFrameToDataStart); |
| 1080 | REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON, |
| 1081 | pModal->txFrameToPaOn); |
| 1082 | } |
| 1083 | |
| 1084 | if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >= |
| 1085 | AR5416_EEP_MINOR_VER_3) { |
| 1086 | if (IS_CHAN_HT40(chan)) |
| 1087 | REG_RMW_FIELD(ah, AR_PHY_SETTLING, |
| 1088 | AR_PHY_SETTLING_SWITCH, |
| 1089 | pModal->swSettleHt40); |
| 1090 | } |
Rajkumar Manoharan | d88525e | 2011-04-06 21:42:52 +0530 | [diff] [blame] | 1091 | |
Felix Fietkau | 1b8714f | 2011-09-15 14:25:35 +0200 | [diff] [blame^] | 1092 | bb_desired_scale = (pModal->bb_scale_smrt_antenna & |
| 1093 | EEP_4K_BB_DESIRED_SCALE_MASK); |
| 1094 | if ((pBase->txGainType == 0) && (bb_desired_scale != 0)) { |
| 1095 | u32 pwrctrl, mask, clr; |
Rajkumar Manoharan | d88525e | 2011-04-06 21:42:52 +0530 | [diff] [blame] | 1096 | |
Felix Fietkau | 1b8714f | 2011-09-15 14:25:35 +0200 | [diff] [blame^] | 1097 | mask = BIT(0)|BIT(5)|BIT(10)|BIT(15)|BIT(20)|BIT(25); |
| 1098 | pwrctrl = mask * bb_desired_scale; |
| 1099 | clr = mask * 0x1f; |
| 1100 | REG_RMW(ah, AR_PHY_TX_PWRCTRL8, pwrctrl, clr); |
| 1101 | REG_RMW(ah, AR_PHY_TX_PWRCTRL10, pwrctrl, clr); |
| 1102 | REG_RMW(ah, AR_PHY_CH0_TX_PWRCTRL12, pwrctrl, clr); |
Rajkumar Manoharan | d88525e | 2011-04-06 21:42:52 +0530 | [diff] [blame] | 1103 | |
Felix Fietkau | 1b8714f | 2011-09-15 14:25:35 +0200 | [diff] [blame^] | 1104 | mask = BIT(0)|BIT(5)|BIT(15); |
| 1105 | pwrctrl = mask * bb_desired_scale; |
| 1106 | clr = mask * 0x1f; |
| 1107 | REG_RMW(ah, AR_PHY_TX_PWRCTRL9, pwrctrl, clr); |
| 1108 | |
| 1109 | mask = BIT(0)|BIT(5); |
| 1110 | pwrctrl = mask * bb_desired_scale; |
| 1111 | clr = mask * 0x1f; |
| 1112 | REG_RMW(ah, AR_PHY_CH0_TX_PWRCTRL11, pwrctrl, clr); |
| 1113 | REG_RMW(ah, AR_PHY_CH0_TX_PWRCTRL13, pwrctrl, clr); |
Rajkumar Manoharan | d88525e | 2011-04-06 21:42:52 +0530 | [diff] [blame] | 1114 | } |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 1115 | } |
| 1116 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 1117 | static u16 ath9k_hw_4k_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz) |
| 1118 | { |
| 1119 | #define EEP_MAP4K_SPURCHAN \ |
| 1120 | (ah->eeprom.map4k.modalHeader.spurChans[i].spurChan) |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1121 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 1122 | |
| 1123 | u16 spur_val = AR_NO_SPUR; |
| 1124 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1125 | ath_dbg(common, ATH_DBG_ANI, |
| 1126 | "Getting spur idx:%d is2Ghz:%d val:%x\n", |
| 1127 | i, is2GHz, ah->config.spurchans[i][is2GHz]); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 1128 | |
| 1129 | switch (ah->config.spurmode) { |
| 1130 | case SPUR_DISABLE: |
| 1131 | break; |
| 1132 | case SPUR_ENABLE_IOCTL: |
| 1133 | spur_val = ah->config.spurchans[i][is2GHz]; |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1134 | ath_dbg(common, ATH_DBG_ANI, |
| 1135 | "Getting spur val from new loc. %d\n", spur_val); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 1136 | break; |
| 1137 | case SPUR_ENABLE_EEPROM: |
| 1138 | spur_val = EEP_MAP4K_SPURCHAN; |
| 1139 | break; |
| 1140 | } |
| 1141 | |
| 1142 | return spur_val; |
| 1143 | |
| 1144 | #undef EEP_MAP4K_SPURCHAN |
| 1145 | } |
| 1146 | |
| 1147 | const struct eeprom_ops eep_4k_ops = { |
| 1148 | .check_eeprom = ath9k_hw_4k_check_eeprom, |
| 1149 | .get_eeprom = ath9k_hw_4k_get_eeprom, |
| 1150 | .fill_eeprom = ath9k_hw_4k_fill_eeprom, |
Rajkumar Manoharan | 4f011a2 | 2011-07-29 17:38:09 +0530 | [diff] [blame] | 1151 | .dump_eeprom = ath9k_hw_4k_dump_eeprom, |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 1152 | .get_eeprom_ver = ath9k_hw_4k_get_eeprom_ver, |
| 1153 | .get_eeprom_rev = ath9k_hw_4k_get_eeprom_rev, |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 1154 | .set_board_values = ath9k_hw_4k_set_board_values, |
| 1155 | .set_addac = ath9k_hw_4k_set_addac, |
| 1156 | .set_txpower = ath9k_hw_4k_set_txpower, |
| 1157 | .get_spur_channel = ath9k_hw_4k_get_spur_channel |
| 1158 | }; |