Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008-2009 Atheros Communications Inc. |
| 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 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 17 | #include "hw.h" |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 18 | #include "ar9002_phy.h" |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 19 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 20 | #define NUM_EEP_WORDS (sizeof(struct ar9287_eeprom) / sizeof(u16)) |
| 21 | |
| 22 | static int ath9k_hw_ar9287_get_eeprom_ver(struct ath_hw *ah) |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 23 | { |
| 24 | return (ah->eeprom.map9287.baseEepHeader.version >> 12) & 0xF; |
| 25 | } |
| 26 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 27 | static int ath9k_hw_ar9287_get_eeprom_rev(struct ath_hw *ah) |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 28 | { |
| 29 | return (ah->eeprom.map9287.baseEepHeader.version) & 0xFFF; |
| 30 | } |
| 31 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 32 | static bool ath9k_hw_ar9287_fill_eeprom(struct ath_hw *ah) |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 33 | { |
| 34 | struct ar9287_eeprom *eep = &ah->eeprom.map9287; |
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; |
| 37 | int addr, eep_start_loc = AR9287_EEP_START_LOC; |
| 38 | eep_data = (u16 *)eep; |
| 39 | |
| 40 | if (!ath9k_hw_use_flash(ah)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 41 | ath_print(common, ATH_DBG_EEPROM, |
| 42 | "Reading from EEPROM, not flash\n"); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 43 | } |
| 44 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 45 | for (addr = 0; addr < NUM_EEP_WORDS; addr++) { |
| 46 | if (!ath9k_hw_nvram_read(common, addr + eep_start_loc, |
| 47 | eep_data)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 48 | ath_print(common, ATH_DBG_EEPROM, |
Frans Pop | 60ece40 | 2010-03-24 19:46:30 +0100 | [diff] [blame] | 49 | "Unable to read eeprom region\n"); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 50 | return false; |
| 51 | } |
| 52 | eep_data++; |
| 53 | } |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 54 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 55 | return true; |
| 56 | } |
| 57 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 58 | static int ath9k_hw_ar9287_check_eeprom(struct ath_hw *ah) |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 59 | { |
| 60 | u32 sum = 0, el, integer; |
| 61 | u16 temp, word, magic, magic2, *eepdata; |
| 62 | int i, addr; |
| 63 | bool need_swap = false; |
| 64 | struct ar9287_eeprom *eep = &ah->eeprom.map9287; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 65 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 66 | |
| 67 | if (!ath9k_hw_use_flash(ah)) { |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 68 | if (!ath9k_hw_nvram_read(common, AR5416_EEPROM_MAGIC_OFFSET, |
| 69 | &magic)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 70 | ath_print(common, ATH_DBG_FATAL, |
| 71 | "Reading Magic # failed\n"); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 72 | return false; |
| 73 | } |
| 74 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 75 | ath_print(common, ATH_DBG_EEPROM, |
| 76 | "Read Magic = 0x%04X\n", magic); |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 77 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 78 | if (magic != AR5416_EEPROM_MAGIC) { |
| 79 | magic2 = swab16(magic); |
| 80 | |
| 81 | if (magic2 == AR5416_EEPROM_MAGIC) { |
| 82 | need_swap = true; |
| 83 | eepdata = (u16 *)(&ah->eeprom); |
| 84 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 85 | for (addr = 0; addr < NUM_EEP_WORDS; addr++) { |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 86 | temp = swab16(*eepdata); |
| 87 | *eepdata = temp; |
| 88 | eepdata++; |
| 89 | } |
| 90 | } else { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 91 | ath_print(common, ATH_DBG_FATAL, |
| 92 | "Invalid EEPROM Magic. " |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 93 | "Endianness mismatch.\n"); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 94 | return -EINVAL; |
| 95 | } |
| 96 | } |
| 97 | } |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 98 | |
| 99 | ath_print(common, ATH_DBG_EEPROM, "need_swap = %s.\n", |
| 100 | need_swap ? "True" : "False"); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 101 | |
| 102 | if (need_swap) |
| 103 | el = swab16(ah->eeprom.map9287.baseEepHeader.length); |
| 104 | else |
| 105 | el = ah->eeprom.map9287.baseEepHeader.length; |
| 106 | |
| 107 | if (el > sizeof(struct ar9287_eeprom)) |
| 108 | el = sizeof(struct ar9287_eeprom) / sizeof(u16); |
| 109 | else |
| 110 | el = el / sizeof(u16); |
| 111 | |
| 112 | eepdata = (u16 *)(&ah->eeprom); |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 113 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 114 | for (i = 0; i < el; i++) |
| 115 | sum ^= *eepdata++; |
| 116 | |
| 117 | if (need_swap) { |
| 118 | word = swab16(eep->baseEepHeader.length); |
| 119 | eep->baseEepHeader.length = word; |
| 120 | |
| 121 | word = swab16(eep->baseEepHeader.checksum); |
| 122 | eep->baseEepHeader.checksum = word; |
| 123 | |
| 124 | word = swab16(eep->baseEepHeader.version); |
| 125 | eep->baseEepHeader.version = word; |
| 126 | |
| 127 | word = swab16(eep->baseEepHeader.regDmn[0]); |
| 128 | eep->baseEepHeader.regDmn[0] = word; |
| 129 | |
| 130 | word = swab16(eep->baseEepHeader.regDmn[1]); |
| 131 | eep->baseEepHeader.regDmn[1] = word; |
| 132 | |
| 133 | word = swab16(eep->baseEepHeader.rfSilent); |
| 134 | eep->baseEepHeader.rfSilent = word; |
| 135 | |
| 136 | word = swab16(eep->baseEepHeader.blueToothOptions); |
| 137 | eep->baseEepHeader.blueToothOptions = word; |
| 138 | |
| 139 | word = swab16(eep->baseEepHeader.deviceCap); |
| 140 | eep->baseEepHeader.deviceCap = word; |
| 141 | |
| 142 | integer = swab32(eep->modalHeader.antCtrlCommon); |
| 143 | eep->modalHeader.antCtrlCommon = integer; |
| 144 | |
| 145 | for (i = 0; i < AR9287_MAX_CHAINS; i++) { |
| 146 | integer = swab32(eep->modalHeader.antCtrlChain[i]); |
| 147 | eep->modalHeader.antCtrlChain[i] = integer; |
| 148 | } |
| 149 | |
| 150 | for (i = 0; i < AR9287_EEPROM_MODAL_SPURS; i++) { |
| 151 | word = swab16(eep->modalHeader.spurChans[i].spurChan); |
| 152 | eep->modalHeader.spurChans[i].spurChan = word; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR9287_EEP_VER |
| 157 | || ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 158 | ath_print(common, ATH_DBG_FATAL, |
| 159 | "Bad EEPROM checksum 0x%x or revision 0x%04x\n", |
| 160 | sum, ah->eep_ops->get_eeprom_ver(ah)); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 161 | return -EINVAL; |
| 162 | } |
| 163 | |
| 164 | return 0; |
| 165 | } |
| 166 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 167 | static u32 ath9k_hw_ar9287_get_eeprom(struct ath_hw *ah, |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 168 | enum eeprom_param param) |
| 169 | { |
| 170 | struct ar9287_eeprom *eep = &ah->eeprom.map9287; |
| 171 | struct modal_eep_ar9287_header *pModal = &eep->modalHeader; |
| 172 | struct base_eep_ar9287_header *pBase = &eep->baseEepHeader; |
| 173 | u16 ver_minor; |
| 174 | |
| 175 | ver_minor = pBase->version & AR9287_EEP_VER_MINOR_MASK; |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 176 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 177 | switch (param) { |
| 178 | case EEP_NFTHRESH_2: |
| 179 | return pModal->noiseFloorThreshCh[0]; |
Luis R. Rodriguez | 4910167 | 2010-04-15 17:39:13 -0400 | [diff] [blame] | 180 | case EEP_MAC_LSW: |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 181 | return pBase->macAddr[0] << 8 | pBase->macAddr[1]; |
Luis R. Rodriguez | 4910167 | 2010-04-15 17:39:13 -0400 | [diff] [blame] | 182 | case EEP_MAC_MID: |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 183 | return pBase->macAddr[2] << 8 | pBase->macAddr[3]; |
Luis R. Rodriguez | 4910167 | 2010-04-15 17:39:13 -0400 | [diff] [blame] | 184 | case EEP_MAC_MSW: |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 185 | return pBase->macAddr[4] << 8 | pBase->macAddr[5]; |
| 186 | case EEP_REG_0: |
| 187 | return pBase->regDmn[0]; |
| 188 | case EEP_REG_1: |
| 189 | return pBase->regDmn[1]; |
| 190 | case EEP_OP_CAP: |
| 191 | return pBase->deviceCap; |
| 192 | case EEP_OP_MODE: |
| 193 | return pBase->opCapFlags; |
| 194 | case EEP_RF_SILENT: |
| 195 | return pBase->rfSilent; |
| 196 | case EEP_MINOR_REV: |
| 197 | return ver_minor; |
| 198 | case EEP_TX_MASK: |
| 199 | return pBase->txMask; |
| 200 | case EEP_RX_MASK: |
| 201 | return pBase->rxMask; |
| 202 | case EEP_DEV_TYPE: |
| 203 | return pBase->deviceType; |
| 204 | case EEP_OL_PWRCTRL: |
| 205 | return pBase->openLoopPwrCntl; |
| 206 | case EEP_TEMPSENSE_SLOPE: |
| 207 | if (ver_minor >= AR9287_EEP_MINOR_VER_2) |
| 208 | return pBase->tempSensSlope; |
| 209 | else |
| 210 | return 0; |
| 211 | case EEP_TEMPSENSE_SLOPE_PAL_ON: |
| 212 | if (ver_minor >= AR9287_EEP_MINOR_VER_3) |
| 213 | return pBase->tempSensSlopePalOn; |
| 214 | else |
| 215 | return 0; |
| 216 | default: |
| 217 | return 0; |
| 218 | } |
| 219 | } |
| 220 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 221 | static void ath9k_hw_get_ar9287_gain_boundaries_pdadcs(struct ath_hw *ah, |
| 222 | struct ath9k_channel *chan, |
| 223 | struct cal_data_per_freq_ar9287 *pRawDataSet, |
| 224 | u8 *bChans, u16 availPiers, |
| 225 | u16 tPdGainOverlap, |
| 226 | int16_t *pMinCalPower, |
| 227 | u16 *pPdGainBoundaries, |
| 228 | u8 *pPDADCValues, |
| 229 | u16 numXpdGains) |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 230 | { |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 231 | #define TMP_VAL_VPD_TABLE \ |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 232 | ((vpdTableI[i][sizeCurrVpdTable - 1] + (ss - maxIndex + 1) * vpdStep)); |
| 233 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 234 | int i, j, k; |
| 235 | int16_t ss; |
| 236 | u16 idxL = 0, idxR = 0, numPiers; |
| 237 | u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR; |
| 238 | u8 minPwrT4[AR9287_NUM_PD_GAINS]; |
| 239 | u8 maxPwrT4[AR9287_NUM_PD_GAINS]; |
| 240 | int16_t vpdStep; |
| 241 | int16_t tmpVal; |
| 242 | u16 sizeCurrVpdTable, maxIndex, tgtIndex; |
| 243 | bool match; |
| 244 | int16_t minDelta = 0; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 245 | struct chan_centers centers; |
| 246 | static u8 vpdTableL[AR5416_EEP4K_NUM_PD_GAINS] |
| 247 | [AR5416_MAX_PWR_RANGE_IN_HALF_DB]; |
| 248 | static u8 vpdTableR[AR5416_EEP4K_NUM_PD_GAINS] |
| 249 | [AR5416_MAX_PWR_RANGE_IN_HALF_DB]; |
| 250 | static u8 vpdTableI[AR5416_EEP4K_NUM_PD_GAINS] |
| 251 | [AR5416_MAX_PWR_RANGE_IN_HALF_DB]; |
| 252 | |
| 253 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
| 254 | |
| 255 | for (numPiers = 0; numPiers < availPiers; numPiers++) { |
| 256 | if (bChans[numPiers] == AR9287_BCHAN_UNUSED) |
| 257 | break; |
| 258 | } |
| 259 | |
| 260 | match = ath9k_hw_get_lower_upper_index( |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 261 | (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)), |
| 262 | bChans, numPiers, &idxL, &idxR); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 263 | |
| 264 | if (match) { |
| 265 | for (i = 0; i < numXpdGains; i++) { |
| 266 | minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0]; |
| 267 | maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4]; |
| 268 | ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i], |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 269 | pRawDataSet[idxL].pwrPdg[i], |
| 270 | pRawDataSet[idxL].vpdPdg[i], |
| 271 | AR9287_PD_GAIN_ICEPTS, |
| 272 | vpdTableI[i]); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 273 | } |
| 274 | } else { |
| 275 | for (i = 0; i < numXpdGains; i++) { |
| 276 | pVpdL = pRawDataSet[idxL].vpdPdg[i]; |
| 277 | pPwrL = pRawDataSet[idxL].pwrPdg[i]; |
| 278 | pVpdR = pRawDataSet[idxR].vpdPdg[i]; |
| 279 | pPwrR = pRawDataSet[idxR].pwrPdg[i]; |
| 280 | |
| 281 | minPwrT4[i] = max(pPwrL[0], pPwrR[0]); |
| 282 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 283 | maxPwrT4[i] = min(pPwrL[AR9287_PD_GAIN_ICEPTS - 1], |
| 284 | pPwrR[AR9287_PD_GAIN_ICEPTS - 1]); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 285 | |
| 286 | ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i], |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 287 | pPwrL, pVpdL, |
| 288 | AR9287_PD_GAIN_ICEPTS, |
| 289 | vpdTableL[i]); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 290 | ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i], |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 291 | pPwrR, pVpdR, |
| 292 | AR9287_PD_GAIN_ICEPTS, |
| 293 | vpdTableR[i]); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 294 | |
| 295 | for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) { |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 296 | vpdTableI[i][j] = (u8)(ath9k_hw_interpolate( |
| 297 | (u16)FREQ2FBIN(centers. synth_center, |
| 298 | IS_CHAN_2GHZ(chan)), |
| 299 | bChans[idxL], bChans[idxR], |
| 300 | vpdTableL[i][j], vpdTableR[i][j])); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | } |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 304 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 305 | *pMinCalPower = (int16_t)(minPwrT4[0] / 2); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 306 | k = 0; |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 307 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 308 | for (i = 0; i < numXpdGains; i++) { |
| 309 | if (i == (numXpdGains - 1)) |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 310 | pPdGainBoundaries[i] = |
| 311 | (u16)(maxPwrT4[i] / 2); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 312 | else |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 313 | pPdGainBoundaries[i] = |
| 314 | (u16)((maxPwrT4[i] + minPwrT4[i+1]) / 4); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 315 | |
| 316 | pPdGainBoundaries[i] = min((u16)AR5416_MAX_RATE_POWER, |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 317 | pPdGainBoundaries[i]); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 318 | |
| 319 | |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 320 | minDelta = 0; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 321 | |
| 322 | if (i == 0) { |
| 323 | if (AR_SREV_9280_10_OR_LATER(ah)) |
| 324 | ss = (int16_t)(0 - (minPwrT4[i] / 2)); |
| 325 | else |
| 326 | ss = 0; |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 327 | } else { |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 328 | ss = (int16_t)((pPdGainBoundaries[i-1] - |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 329 | (minPwrT4[i] / 2)) - |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 330 | tPdGainOverlap + 1 + minDelta); |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 331 | } |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 332 | |
| 333 | vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]); |
| 334 | vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep); |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 335 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 336 | while ((ss < 0) && (k < (AR9287_NUM_PDADC_VALUES - 1))) { |
| 337 | tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep); |
| 338 | pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal); |
| 339 | ss++; |
| 340 | } |
| 341 | |
| 342 | sizeCurrVpdTable = (u8)((maxPwrT4[i] - minPwrT4[i]) / 2 + 1); |
| 343 | tgtIndex = (u8)(pPdGainBoundaries[i] + |
| 344 | tPdGainOverlap - (minPwrT4[i] / 2)); |
| 345 | maxIndex = (tgtIndex < sizeCurrVpdTable) ? |
| 346 | tgtIndex : sizeCurrVpdTable; |
| 347 | |
| 348 | while ((ss < maxIndex) && (k < (AR9287_NUM_PDADC_VALUES - 1))) |
| 349 | pPDADCValues[k++] = vpdTableI[i][ss++]; |
| 350 | |
| 351 | vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] - |
| 352 | vpdTableI[i][sizeCurrVpdTable - 2]); |
| 353 | vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep); |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 354 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 355 | if (tgtIndex > maxIndex) { |
| 356 | while ((ss <= tgtIndex) && |
| 357 | (k < (AR9287_NUM_PDADC_VALUES - 1))) { |
| 358 | tmpVal = (int16_t) TMP_VAL_VPD_TABLE; |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 359 | pPDADCValues[k++] = |
| 360 | (u8)((tmpVal > 255) ? 255 : tmpVal); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 361 | ss++; |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | while (i < AR9287_PD_GAINS_IN_MASK) { |
| 367 | pPdGainBoundaries[i] = pPdGainBoundaries[i-1]; |
| 368 | i++; |
| 369 | } |
| 370 | |
| 371 | while (k < AR9287_NUM_PDADC_VALUES) { |
| 372 | pPDADCValues[k] = pPDADCValues[k-1]; |
| 373 | k++; |
| 374 | } |
| 375 | |
| 376 | #undef TMP_VAL_VPD_TABLE |
| 377 | } |
| 378 | |
| 379 | static void ar9287_eeprom_get_tx_gain_index(struct ath_hw *ah, |
| 380 | struct ath9k_channel *chan, |
| 381 | struct cal_data_op_loop_ar9287 *pRawDatasetOpLoop, |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 382 | u8 *pCalChans, u16 availPiers, int8_t *pPwr) |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 383 | { |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 384 | u16 idxL = 0, idxR = 0, numPiers; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 385 | bool match; |
| 386 | struct chan_centers centers; |
| 387 | |
| 388 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
| 389 | |
| 390 | for (numPiers = 0; numPiers < availPiers; numPiers++) { |
| 391 | if (pCalChans[numPiers] == AR9287_BCHAN_UNUSED) |
| 392 | break; |
| 393 | } |
| 394 | |
| 395 | match = ath9k_hw_get_lower_upper_index( |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 396 | (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)), |
| 397 | pCalChans, numPiers, &idxL, &idxR); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 398 | |
| 399 | if (match) { |
Vivek Natarajan | d4fe5af | 2009-08-14 11:32:04 +0530 | [diff] [blame] | 400 | *pPwr = (int8_t) pRawDatasetOpLoop[idxL].pwrPdg[0][0]; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 401 | } else { |
Vivek Natarajan | d4fe5af | 2009-08-14 11:32:04 +0530 | [diff] [blame] | 402 | *pPwr = ((int8_t) pRawDatasetOpLoop[idxL].pwrPdg[0][0] + |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 403 | (int8_t) pRawDatasetOpLoop[idxR].pwrPdg[0][0])/2; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 404 | } |
| 405 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | static void ar9287_eeprom_olpc_set_pdadcs(struct ath_hw *ah, |
| 409 | int32_t txPower, u16 chain) |
| 410 | { |
| 411 | u32 tmpVal; |
| 412 | u32 a; |
| 413 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 414 | /* Enable OLPC for chain 0 */ |
| 415 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 416 | tmpVal = REG_READ(ah, 0xa270); |
| 417 | tmpVal = tmpVal & 0xFCFFFFFF; |
| 418 | tmpVal = tmpVal | (0x3 << 24); |
| 419 | REG_WRITE(ah, 0xa270, tmpVal); |
| 420 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 421 | /* Enable OLPC for chain 1 */ |
| 422 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 423 | tmpVal = REG_READ(ah, 0xb270); |
| 424 | tmpVal = tmpVal & 0xFCFFFFFF; |
| 425 | tmpVal = tmpVal | (0x3 << 24); |
| 426 | REG_WRITE(ah, 0xb270, tmpVal); |
| 427 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 428 | /* Write the OLPC ref power for chain 0 */ |
| 429 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 430 | if (chain == 0) { |
| 431 | tmpVal = REG_READ(ah, 0xa398); |
| 432 | tmpVal = tmpVal & 0xff00ffff; |
| 433 | a = (txPower)&0xff; |
| 434 | tmpVal = tmpVal | (a << 16); |
| 435 | REG_WRITE(ah, 0xa398, tmpVal); |
| 436 | } |
| 437 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 438 | /* Write the OLPC ref power for chain 1 */ |
| 439 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 440 | if (chain == 1) { |
| 441 | tmpVal = REG_READ(ah, 0xb398); |
| 442 | tmpVal = tmpVal & 0xff00ffff; |
| 443 | a = (txPower)&0xff; |
| 444 | tmpVal = tmpVal | (a << 16); |
| 445 | REG_WRITE(ah, 0xb398, tmpVal); |
| 446 | } |
| 447 | } |
| 448 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 449 | static void ath9k_hw_set_ar9287_power_cal_table(struct ath_hw *ah, |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 450 | struct ath9k_channel *chan, |
| 451 | int16_t *pTxPowerIndexOffset) |
| 452 | { |
| 453 | struct cal_data_per_freq_ar9287 *pRawDataset; |
| 454 | struct cal_data_op_loop_ar9287 *pRawDatasetOpenLoop; |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 455 | u8 *pCalBChans = NULL; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 456 | u16 pdGainOverlap_t2; |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 457 | u8 pdadcValues[AR9287_NUM_PDADC_VALUES]; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 458 | u16 gainBoundaries[AR9287_PD_GAINS_IN_MASK]; |
| 459 | u16 numPiers = 0, i, j; |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 460 | int16_t tMinCalPower; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 461 | u16 numXpdGain, xpdMask; |
| 462 | u16 xpdGainValues[AR9287_NUM_PD_GAINS] = {0, 0, 0, 0}; |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 463 | u32 reg32, regOffset, regChainOffset, regval; |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 464 | int16_t modalIdx, diff = 0; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 465 | struct ar9287_eeprom *pEepData = &ah->eeprom.map9287; |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 466 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 467 | modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0; |
| 468 | xpdMask = pEepData->modalHeader.xpdGain; |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 469 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 470 | if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >= |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 471 | AR9287_EEP_MINOR_VER_2) |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 472 | pdGainOverlap_t2 = pEepData->modalHeader.pdGainOverlap; |
| 473 | else |
| 474 | pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5), |
| 475 | AR_PHY_TPCRG5_PD_GAIN_OVERLAP)); |
| 476 | |
| 477 | if (IS_CHAN_2GHZ(chan)) { |
| 478 | pCalBChans = pEepData->calFreqPier2G; |
| 479 | numPiers = AR9287_NUM_2G_CAL_PIERS; |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 480 | if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) { |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 481 | pRawDatasetOpenLoop = |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 482 | (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[0]; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 483 | ah->initPDADC = pRawDatasetOpenLoop->vpdPdg[0][0]; |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | numXpdGain = 0; |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 488 | |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 489 | /* Calculate the value of xpdgains from the xpdGain Mask */ |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 490 | for (i = 1; i <= AR9287_PD_GAINS_IN_MASK; i++) { |
| 491 | if ((xpdMask >> (AR9287_PD_GAINS_IN_MASK - i)) & 1) { |
| 492 | if (numXpdGain >= AR9287_NUM_PD_GAINS) |
| 493 | break; |
| 494 | xpdGainValues[numXpdGain] = |
| 495 | (u16)(AR9287_PD_GAINS_IN_MASK-i); |
| 496 | numXpdGain++; |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN, |
| 501 | (numXpdGain - 1) & 0x3); |
| 502 | REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1, |
| 503 | xpdGainValues[0]); |
| 504 | REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2, |
| 505 | xpdGainValues[1]); |
| 506 | REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3, |
| 507 | xpdGainValues[2]); |
| 508 | |
| 509 | for (i = 0; i < AR9287_MAX_CHAINS; i++) { |
| 510 | regChainOffset = i * 0x1000; |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 511 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 512 | if (pEepData->baseEepHeader.txMask & (1 << i)) { |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 513 | pRawDatasetOpenLoop = |
| 514 | (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[i]; |
| 515 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 516 | if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) { |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 517 | int8_t txPower; |
| 518 | ar9287_eeprom_get_tx_gain_index(ah, chan, |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 519 | pRawDatasetOpenLoop, |
| 520 | pCalBChans, numPiers, |
| 521 | &txPower); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 522 | ar9287_eeprom_olpc_set_pdadcs(ah, txPower, i); |
| 523 | } else { |
| 524 | pRawDataset = |
| 525 | (struct cal_data_per_freq_ar9287 *) |
| 526 | pEepData->calPierData2G[i]; |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 527 | |
| 528 | ath9k_hw_get_ar9287_gain_boundaries_pdadcs(ah, chan, |
| 529 | pRawDataset, |
| 530 | pCalBChans, numPiers, |
| 531 | pdGainOverlap_t2, |
| 532 | &tMinCalPower, |
| 533 | gainBoundaries, |
| 534 | pdadcValues, |
| 535 | numXpdGain); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | if (i == 0) { |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 539 | if (!ath9k_hw_ar9287_get_eeprom(ah, |
| 540 | EEP_OL_PWRCTRL)) { |
| 541 | |
| 542 | regval = SM(pdGainOverlap_t2, |
| 543 | AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
| 544 | | SM(gainBoundaries[0], |
| 545 | AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1) |
| 546 | | SM(gainBoundaries[1], |
| 547 | AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2) |
| 548 | | SM(gainBoundaries[2], |
| 549 | AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3) |
| 550 | | SM(gainBoundaries[3], |
| 551 | AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4); |
| 552 | |
| 553 | REG_WRITE(ah, |
| 554 | AR_PHY_TPCRG5 + regChainOffset, |
| 555 | regval); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 556 | } |
| 557 | } |
| 558 | |
| 559 | if ((int32_t)AR9287_PWR_TABLE_OFFSET_DB != |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 560 | pEepData->baseEepHeader.pwrTableOffset) { |
| 561 | diff = (u16)(pEepData->baseEepHeader.pwrTableOffset - |
| 562 | (int32_t)AR9287_PWR_TABLE_OFFSET_DB); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 563 | diff *= 2; |
| 564 | |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 565 | for (j = 0; j < ((u16)AR9287_NUM_PDADC_VALUES-diff); j++) |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 566 | pdadcValues[j] = pdadcValues[j+diff]; |
| 567 | |
| 568 | for (j = (u16)(AR9287_NUM_PDADC_VALUES-diff); |
| 569 | j < AR9287_NUM_PDADC_VALUES; j++) |
| 570 | pdadcValues[j] = |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 571 | pdadcValues[AR9287_NUM_PDADC_VALUES-diff]; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 572 | } |
| 573 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 574 | if (!ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) { |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 575 | regOffset = AR_PHY_BASE + |
| 576 | (672 << 2) + regChainOffset; |
| 577 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 578 | for (j = 0; j < 32; j++) { |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 579 | reg32 = ((pdadcValues[4*j + 0] & 0xFF) << 0) |
| 580 | | ((pdadcValues[4*j + 1] & 0xFF) << 8) |
| 581 | | ((pdadcValues[4*j + 2] & 0xFF) << 16) |
| 582 | | ((pdadcValues[4*j + 3] & 0xFF) << 24); |
| 583 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 584 | REG_WRITE(ah, regOffset, reg32); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 585 | regOffset += 4; |
| 586 | } |
| 587 | } |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | *pTxPowerIndexOffset = 0; |
| 592 | } |
| 593 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 594 | static void ath9k_hw_set_ar9287_power_per_rate_table(struct ath_hw *ah, |
| 595 | struct ath9k_channel *chan, |
| 596 | int16_t *ratesArray, |
| 597 | u16 cfgCtl, |
| 598 | u16 AntennaReduction, |
| 599 | u16 twiceMaxRegulatoryPower, |
| 600 | u16 powerLimit) |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 601 | { |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 602 | #define CMP_CTL \ |
| 603 | (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \ |
| 604 | pEepData->ctlIndex[i]) |
| 605 | |
| 606 | #define CMP_NO_CTL \ |
| 607 | (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \ |
| 608 | ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL)) |
| 609 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 610 | #define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6 |
| 611 | #define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10 |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 612 | |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 613 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 614 | u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER; |
| 615 | static const u16 tpScaleReductionTable[5] = |
| 616 | { 0, 3, 6, 9, AR5416_MAX_RATE_POWER }; |
| 617 | int i; |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 618 | int16_t twiceLargestAntenna; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 619 | struct cal_ctl_data_ar9287 *rep; |
| 620 | struct cal_target_power_leg targetPowerOfdm = {0, {0, 0, 0, 0} }, |
| 621 | targetPowerCck = {0, {0, 0, 0, 0} }; |
| 622 | struct cal_target_power_leg targetPowerOfdmExt = {0, {0, 0, 0, 0} }, |
| 623 | targetPowerCckExt = {0, {0, 0, 0, 0} }; |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 624 | struct cal_target_power_ht targetPowerHt20, |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 625 | targetPowerHt40 = {0, {0, 0, 0, 0} }; |
| 626 | u16 scaledPower = 0, minCtlPower, maxRegAllowedPower; |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 627 | u16 ctlModesFor11g[] = {CTL_11B, |
| 628 | CTL_11G, |
| 629 | CTL_2GHT20, |
| 630 | CTL_11B_EXT, |
| 631 | CTL_11G_EXT, |
| 632 | CTL_2GHT40}; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 633 | u16 numCtlModes = 0, *pCtlMode = NULL, ctlMode, freq; |
| 634 | struct chan_centers centers; |
| 635 | int tx_chainmask; |
| 636 | u16 twiceMinEdgePower; |
| 637 | struct ar9287_eeprom *pEepData = &ah->eeprom.map9287; |
| 638 | tx_chainmask = ah->txchainmask; |
| 639 | |
| 640 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
| 641 | |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 642 | /* Compute TxPower reduction due to Antenna Gain */ |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 643 | twiceLargestAntenna = max(pEepData->modalHeader.antennaGainCh[0], |
| 644 | pEepData->modalHeader.antennaGainCh[1]); |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 645 | twiceLargestAntenna = (int16_t)min((AntennaReduction) - |
| 646 | twiceLargestAntenna, 0); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 647 | |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 648 | /* |
| 649 | * scaledPower is the minimum of the user input power level |
| 650 | * and the regulatory allowed power level. |
| 651 | */ |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 652 | maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna; |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 653 | |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 654 | if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX) |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 655 | maxRegAllowedPower -= |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 656 | (tpScaleReductionTable[(regulatory->tp_scale)] * 2); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 657 | |
| 658 | scaledPower = min(powerLimit, maxRegAllowedPower); |
| 659 | |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 660 | /* |
| 661 | * Reduce scaled Power by number of chains active |
| 662 | * to get the per chain tx power level. |
| 663 | */ |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 664 | switch (ar5416_get_ntxchains(tx_chainmask)) { |
| 665 | case 1: |
| 666 | break; |
| 667 | case 2: |
| 668 | scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN; |
| 669 | break; |
| 670 | case 3: |
| 671 | scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN; |
| 672 | break; |
| 673 | } |
| 674 | scaledPower = max((u16)0, scaledPower); |
| 675 | |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 676 | /* |
| 677 | * Get TX power from EEPROM. |
| 678 | */ |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 679 | if (IS_CHAN_2GHZ(chan)) { |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 680 | /* CTL_11B, CTL_11G, CTL_2GHT20 */ |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 681 | numCtlModes = |
| 682 | ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40; |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 683 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 684 | pCtlMode = ctlModesFor11g; |
| 685 | |
| 686 | ath9k_hw_get_legacy_target_powers(ah, chan, |
| 687 | pEepData->calTargetPowerCck, |
| 688 | AR9287_NUM_2G_CCK_TARGET_POWERS, |
| 689 | &targetPowerCck, 4, false); |
| 690 | ath9k_hw_get_legacy_target_powers(ah, chan, |
| 691 | pEepData->calTargetPower2G, |
| 692 | AR9287_NUM_2G_20_TARGET_POWERS, |
| 693 | &targetPowerOfdm, 4, false); |
| 694 | ath9k_hw_get_target_powers(ah, chan, |
| 695 | pEepData->calTargetPower2GHT20, |
| 696 | AR9287_NUM_2G_20_TARGET_POWERS, |
| 697 | &targetPowerHt20, 8, false); |
| 698 | |
| 699 | if (IS_CHAN_HT40(chan)) { |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 700 | /* All 2G CTLs */ |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 701 | numCtlModes = ARRAY_SIZE(ctlModesFor11g); |
| 702 | ath9k_hw_get_target_powers(ah, chan, |
| 703 | pEepData->calTargetPower2GHT40, |
| 704 | AR9287_NUM_2G_40_TARGET_POWERS, |
| 705 | &targetPowerHt40, 8, true); |
| 706 | ath9k_hw_get_legacy_target_powers(ah, chan, |
| 707 | pEepData->calTargetPowerCck, |
| 708 | AR9287_NUM_2G_CCK_TARGET_POWERS, |
| 709 | &targetPowerCckExt, 4, true); |
| 710 | ath9k_hw_get_legacy_target_powers(ah, chan, |
| 711 | pEepData->calTargetPower2G, |
| 712 | AR9287_NUM_2G_20_TARGET_POWERS, |
| 713 | &targetPowerOfdmExt, 4, true); |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) { |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 718 | bool isHt40CtlMode = |
| 719 | (pCtlMode[ctlMode] == CTL_2GHT40) ? true : false; |
| 720 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 721 | if (isHt40CtlMode) |
| 722 | freq = centers.synth_center; |
| 723 | else if (pCtlMode[ctlMode] & EXT_ADDITIVE) |
| 724 | freq = centers.ext_center; |
| 725 | else |
| 726 | freq = centers.ctl_center; |
| 727 | |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 728 | /* Walk through the CTL indices stored in EEPROM */ |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 729 | for (i = 0; (i < AR9287_NUM_CTLS) && pEepData->ctlIndex[i]; i++) { |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 730 | struct cal_ctl_edges *pRdEdgesPower; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 731 | |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 732 | /* |
| 733 | * Compare test group from regulatory channel list |
| 734 | * with test mode from pCtlMode list |
| 735 | */ |
| 736 | if (CMP_CTL || CMP_NO_CTL) { |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 737 | rep = &(pEepData->ctlData[i]); |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 738 | pRdEdgesPower = |
| 739 | rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1]; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 740 | |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 741 | twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq, |
| 742 | pRdEdgesPower, |
| 743 | IS_CHAN_2GHZ(chan), |
| 744 | AR5416_NUM_BAND_EDGES); |
| 745 | |
| 746 | if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) { |
| 747 | twiceMaxEdgePower = min(twiceMaxEdgePower, |
| 748 | twiceMinEdgePower); |
| 749 | } else { |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 750 | twiceMaxEdgePower = twiceMinEdgePower; |
| 751 | break; |
| 752 | } |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower); |
| 757 | |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 758 | /* Apply ctl mode to correct target power set */ |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 759 | switch (pCtlMode[ctlMode]) { |
| 760 | case CTL_11B: |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 761 | for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) { |
| 762 | targetPowerCck.tPow2x[i] = |
| 763 | (u8)min((u16)targetPowerCck.tPow2x[i], |
| 764 | minCtlPower); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 765 | } |
| 766 | break; |
| 767 | case CTL_11A: |
| 768 | case CTL_11G: |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 769 | for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) { |
| 770 | targetPowerOfdm.tPow2x[i] = |
| 771 | (u8)min((u16)targetPowerOfdm.tPow2x[i], |
| 772 | minCtlPower); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 773 | } |
| 774 | break; |
| 775 | case CTL_5GHT20: |
| 776 | case CTL_2GHT20: |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 777 | for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) { |
| 778 | targetPowerHt20.tPow2x[i] = |
| 779 | (u8)min((u16)targetPowerHt20.tPow2x[i], |
| 780 | minCtlPower); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 781 | } |
| 782 | break; |
| 783 | case CTL_11B_EXT: |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 784 | targetPowerCckExt.tPow2x[0] = |
| 785 | (u8)min((u16)targetPowerCckExt.tPow2x[0], |
| 786 | minCtlPower); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 787 | break; |
| 788 | case CTL_11A_EXT: |
| 789 | case CTL_11G_EXT: |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 790 | targetPowerOfdmExt.tPow2x[0] = |
| 791 | (u8)min((u16)targetPowerOfdmExt.tPow2x[0], |
| 792 | minCtlPower); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 793 | break; |
| 794 | case CTL_5GHT40: |
| 795 | case CTL_2GHT40: |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 796 | for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) { |
| 797 | targetPowerHt40.tPow2x[i] = |
| 798 | (u8)min((u16)targetPowerHt40.tPow2x[i], |
| 799 | minCtlPower); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 800 | } |
| 801 | break; |
| 802 | default: |
| 803 | break; |
| 804 | } |
| 805 | } |
| 806 | |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 807 | /* Now set the rates array */ |
| 808 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 809 | ratesArray[rate6mb] = |
| 810 | ratesArray[rate9mb] = |
| 811 | ratesArray[rate12mb] = |
| 812 | ratesArray[rate18mb] = |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 813 | ratesArray[rate24mb] = targetPowerOfdm.tPow2x[0]; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 814 | |
| 815 | ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1]; |
| 816 | ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2]; |
| 817 | ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3]; |
| 818 | ratesArray[rateXr] = targetPowerOfdm.tPow2x[0]; |
| 819 | |
| 820 | for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) |
| 821 | ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i]; |
| 822 | |
| 823 | if (IS_CHAN_2GHZ(chan)) { |
| 824 | ratesArray[rate1l] = targetPowerCck.tPow2x[0]; |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 825 | ratesArray[rate2s] = |
| 826 | ratesArray[rate2l] = targetPowerCck.tPow2x[1]; |
| 827 | ratesArray[rate5_5s] = |
| 828 | ratesArray[rate5_5l] = targetPowerCck.tPow2x[2]; |
| 829 | ratesArray[rate11s] = |
| 830 | ratesArray[rate11l] = targetPowerCck.tPow2x[3]; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 831 | } |
| 832 | if (IS_CHAN_HT40(chan)) { |
| 833 | for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) |
| 834 | ratesArray[rateHt40_0 + i] = targetPowerHt40.tPow2x[i]; |
| 835 | |
| 836 | ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0]; |
| 837 | ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0]; |
| 838 | ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0]; |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 839 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 840 | if (IS_CHAN_2GHZ(chan)) |
| 841 | ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0]; |
| 842 | } |
| 843 | |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 844 | #undef CMP_CTL |
| 845 | #undef CMP_NO_CTL |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 846 | #undef REDUCE_SCALED_POWER_BY_TWO_CHAIN |
| 847 | #undef REDUCE_SCALED_POWER_BY_THREE_CHAIN |
| 848 | } |
| 849 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 850 | static void ath9k_hw_ar9287_set_txpower(struct ath_hw *ah, |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 851 | struct ath9k_channel *chan, u16 cfgCtl, |
| 852 | u8 twiceAntennaReduction, |
| 853 | u8 twiceMaxRegulatoryPower, |
| 854 | u8 powerLimit) |
| 855 | { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 856 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 857 | struct ar9287_eeprom *pEepData = &ah->eeprom.map9287; |
| 858 | struct modal_eep_ar9287_header *pModal = &pEepData->modalHeader; |
| 859 | int16_t ratesArray[Ar5416RateSize]; |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 860 | int16_t txPowerIndexOffset = 0; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 861 | u8 ht40PowerIncForPdadc = 2; |
| 862 | int i; |
| 863 | |
| 864 | memset(ratesArray, 0, sizeof(ratesArray)); |
| 865 | |
| 866 | if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >= |
| 867 | AR9287_EEP_MINOR_VER_2) |
| 868 | ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc; |
| 869 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 870 | ath9k_hw_set_ar9287_power_per_rate_table(ah, chan, |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 871 | &ratesArray[0], cfgCtl, |
| 872 | twiceAntennaReduction, |
| 873 | twiceMaxRegulatoryPower, |
| 874 | powerLimit); |
| 875 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 876 | ath9k_hw_set_ar9287_power_cal_table(ah, chan, &txPowerIndexOffset); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 877 | |
| 878 | for (i = 0; i < ARRAY_SIZE(ratesArray); i++) { |
| 879 | ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]); |
| 880 | if (ratesArray[i] > AR9287_MAX_RATE_POWER) |
| 881 | ratesArray[i] = AR9287_MAX_RATE_POWER; |
| 882 | } |
| 883 | |
| 884 | if (AR_SREV_9280_10_OR_LATER(ah)) { |
| 885 | for (i = 0; i < Ar5416RateSize; i++) |
| 886 | ratesArray[i] -= AR9287_PWR_TABLE_OFFSET_DB * 2; |
| 887 | } |
| 888 | |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 889 | /* OFDM power per rate */ |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 890 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE1, |
| 891 | ATH9K_POW_SM(ratesArray[rate18mb], 24) |
| 892 | | ATH9K_POW_SM(ratesArray[rate12mb], 16) |
| 893 | | ATH9K_POW_SM(ratesArray[rate9mb], 8) |
| 894 | | ATH9K_POW_SM(ratesArray[rate6mb], 0)); |
| 895 | |
| 896 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE2, |
| 897 | ATH9K_POW_SM(ratesArray[rate54mb], 24) |
| 898 | | ATH9K_POW_SM(ratesArray[rate48mb], 16) |
| 899 | | ATH9K_POW_SM(ratesArray[rate36mb], 8) |
| 900 | | ATH9K_POW_SM(ratesArray[rate24mb], 0)); |
| 901 | |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 902 | /* CCK power per rate */ |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 903 | if (IS_CHAN_2GHZ(chan)) { |
| 904 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE3, |
| 905 | ATH9K_POW_SM(ratesArray[rate2s], 24) |
| 906 | | ATH9K_POW_SM(ratesArray[rate2l], 16) |
| 907 | | ATH9K_POW_SM(ratesArray[rateXr], 8) |
| 908 | | ATH9K_POW_SM(ratesArray[rate1l], 0)); |
| 909 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE4, |
| 910 | ATH9K_POW_SM(ratesArray[rate11s], 24) |
| 911 | | ATH9K_POW_SM(ratesArray[rate11l], 16) |
| 912 | | ATH9K_POW_SM(ratesArray[rate5_5s], 8) |
| 913 | | ATH9K_POW_SM(ratesArray[rate5_5l], 0)); |
| 914 | } |
| 915 | |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 916 | /* HT20 power per rate */ |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 917 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE5, |
| 918 | ATH9K_POW_SM(ratesArray[rateHt20_3], 24) |
| 919 | | ATH9K_POW_SM(ratesArray[rateHt20_2], 16) |
| 920 | | ATH9K_POW_SM(ratesArray[rateHt20_1], 8) |
| 921 | | ATH9K_POW_SM(ratesArray[rateHt20_0], 0)); |
| 922 | |
| 923 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE6, |
| 924 | ATH9K_POW_SM(ratesArray[rateHt20_7], 24) |
| 925 | | ATH9K_POW_SM(ratesArray[rateHt20_6], 16) |
| 926 | | ATH9K_POW_SM(ratesArray[rateHt20_5], 8) |
| 927 | | ATH9K_POW_SM(ratesArray[rateHt20_4], 0)); |
| 928 | |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 929 | /* HT40 power per rate */ |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 930 | if (IS_CHAN_HT40(chan)) { |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 931 | if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) { |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 932 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE7, |
| 933 | ATH9K_POW_SM(ratesArray[rateHt40_3], 24) |
| 934 | | ATH9K_POW_SM(ratesArray[rateHt40_2], 16) |
| 935 | | ATH9K_POW_SM(ratesArray[rateHt40_1], 8) |
| 936 | | ATH9K_POW_SM(ratesArray[rateHt40_0], 0)); |
| 937 | |
| 938 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE8, |
| 939 | ATH9K_POW_SM(ratesArray[rateHt40_7], 24) |
| 940 | | ATH9K_POW_SM(ratesArray[rateHt40_6], 16) |
| 941 | | ATH9K_POW_SM(ratesArray[rateHt40_5], 8) |
| 942 | | ATH9K_POW_SM(ratesArray[rateHt40_4], 0)); |
| 943 | } else { |
| 944 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE7, |
| 945 | ATH9K_POW_SM(ratesArray[rateHt40_3] + |
| 946 | ht40PowerIncForPdadc, 24) |
| 947 | | ATH9K_POW_SM(ratesArray[rateHt40_2] + |
| 948 | ht40PowerIncForPdadc, 16) |
| 949 | | ATH9K_POW_SM(ratesArray[rateHt40_1] + |
| 950 | ht40PowerIncForPdadc, 8) |
| 951 | | ATH9K_POW_SM(ratesArray[rateHt40_0] + |
| 952 | ht40PowerIncForPdadc, 0)); |
| 953 | |
| 954 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE8, |
| 955 | ATH9K_POW_SM(ratesArray[rateHt40_7] + |
| 956 | ht40PowerIncForPdadc, 24) |
| 957 | | ATH9K_POW_SM(ratesArray[rateHt40_6] + |
| 958 | ht40PowerIncForPdadc, 16) |
| 959 | | ATH9K_POW_SM(ratesArray[rateHt40_5] + |
| 960 | ht40PowerIncForPdadc, 8) |
| 961 | | ATH9K_POW_SM(ratesArray[rateHt40_4] + |
| 962 | ht40PowerIncForPdadc, 0)); |
| 963 | } |
| 964 | |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame^] | 965 | /* Dup/Ext power per rate */ |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 966 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE9, |
| 967 | ATH9K_POW_SM(ratesArray[rateExtOfdm], 24) |
| 968 | | ATH9K_POW_SM(ratesArray[rateExtCck], 16) |
| 969 | | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8) |
| 970 | | ATH9K_POW_SM(ratesArray[rateDupCck], 0)); |
| 971 | } |
| 972 | |
| 973 | if (IS_CHAN_2GHZ(chan)) |
| 974 | i = rate1l; |
| 975 | else |
| 976 | i = rate6mb; |
| 977 | |
| 978 | if (AR_SREV_9280_10_OR_LATER(ah)) |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 979 | regulatory->max_power_level = |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 980 | ratesArray[i] + AR9287_PWR_TABLE_OFFSET_DB * 2; |
| 981 | else |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 982 | regulatory->max_power_level = ratesArray[i]; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 983 | } |
| 984 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 985 | static void ath9k_hw_ar9287_set_addac(struct ath_hw *ah, |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 986 | struct ath9k_channel *chan) |
| 987 | { |
| 988 | } |
| 989 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 990 | static void ath9k_hw_ar9287_set_board_values(struct ath_hw *ah, |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 991 | struct ath9k_channel *chan) |
| 992 | { |
| 993 | struct ar9287_eeprom *eep = &ah->eeprom.map9287; |
| 994 | struct modal_eep_ar9287_header *pModal = &eep->modalHeader; |
| 995 | u16 antWrites[AR9287_ANT_16S]; |
Sujith | 79d7f4b | 2010-06-01 15:14:06 +0530 | [diff] [blame] | 996 | u32 regChainOffset, regval; |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 997 | u8 txRxAttenLocal; |
| 998 | int i, j, offset_num; |
| 999 | |
| 1000 | pModal = &eep->modalHeader; |
| 1001 | |
| 1002 | antWrites[0] = (u16)((pModal->antCtrlCommon >> 28) & 0xF); |
| 1003 | antWrites[1] = (u16)((pModal->antCtrlCommon >> 24) & 0xF); |
| 1004 | antWrites[2] = (u16)((pModal->antCtrlCommon >> 20) & 0xF); |
| 1005 | antWrites[3] = (u16)((pModal->antCtrlCommon >> 16) & 0xF); |
| 1006 | antWrites[4] = (u16)((pModal->antCtrlCommon >> 12) & 0xF); |
| 1007 | antWrites[5] = (u16)((pModal->antCtrlCommon >> 8) & 0xF); |
| 1008 | antWrites[6] = (u16)((pModal->antCtrlCommon >> 4) & 0xF); |
| 1009 | antWrites[7] = (u16)(pModal->antCtrlCommon & 0xF); |
| 1010 | |
| 1011 | offset_num = 8; |
| 1012 | |
| 1013 | for (i = 0, j = offset_num; i < AR9287_MAX_CHAINS; i++) { |
| 1014 | antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 28) & 0xf); |
| 1015 | antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 10) & 0x3); |
| 1016 | antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 8) & 0x3); |
| 1017 | antWrites[j++] = 0; |
| 1018 | antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 6) & 0x3); |
| 1019 | antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 4) & 0x3); |
| 1020 | antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 2) & 0x3); |
| 1021 | antWrites[j++] = (u16)(pModal->antCtrlChain[i] & 0x3); |
| 1022 | } |
| 1023 | |
| 1024 | REG_WRITE(ah, AR_PHY_SWITCH_COM, |
| 1025 | ah->eep_ops->get_eeprom_antenna_cfg(ah, chan)); |
| 1026 | |
| 1027 | for (i = 0; i < AR9287_MAX_CHAINS; i++) { |
| 1028 | regChainOffset = i * 0x1000; |
| 1029 | |
| 1030 | REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset, |
| 1031 | pModal->antCtrlChain[i]); |
| 1032 | |
| 1033 | REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset, |
| 1034 | (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset) |
| 1035 | & ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF | |
| 1036 | AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) | |
| 1037 | SM(pModal->iqCalICh[i], |
| 1038 | AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) | |
| 1039 | SM(pModal->iqCalQCh[i], |
| 1040 | AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF)); |
| 1041 | |
| 1042 | txRxAttenLocal = pModal->txRxAttenCh[i]; |
| 1043 | |
| 1044 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset, |
| 1045 | AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN, |
| 1046 | pModal->bswMargin[i]); |
| 1047 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset, |
| 1048 | AR_PHY_GAIN_2GHZ_XATTEN1_DB, |
| 1049 | pModal->bswAtten[i]); |
| 1050 | REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset, |
| 1051 | AR9280_PHY_RXGAIN_TXRX_ATTEN, |
| 1052 | txRxAttenLocal); |
| 1053 | REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset, |
| 1054 | AR9280_PHY_RXGAIN_TXRX_MARGIN, |
| 1055 | pModal->rxTxMarginCh[i]); |
| 1056 | } |
| 1057 | |
| 1058 | |
| 1059 | if (IS_CHAN_HT40(chan)) |
| 1060 | REG_RMW_FIELD(ah, AR_PHY_SETTLING, |
| 1061 | AR_PHY_SETTLING_SWITCH, pModal->swSettleHt40); |
| 1062 | else |
| 1063 | REG_RMW_FIELD(ah, AR_PHY_SETTLING, |
| 1064 | AR_PHY_SETTLING_SWITCH, pModal->switchSettling); |
| 1065 | |
| 1066 | REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, |
| 1067 | AR_PHY_DESIRED_SZ_ADC, pModal->adcDesiredSize); |
| 1068 | |
| 1069 | REG_WRITE(ah, AR_PHY_RF_CTL4, |
| 1070 | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF) |
| 1071 | | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF) |
| 1072 | | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON) |
| 1073 | | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON)); |
| 1074 | |
| 1075 | REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, |
| 1076 | AR_PHY_TX_END_TO_A2_RX_ON, pModal->txEndToRxOn); |
| 1077 | |
| 1078 | REG_RMW_FIELD(ah, AR_PHY_CCA, |
| 1079 | AR9280_PHY_CCA_THRESH62, pModal->thresh62); |
| 1080 | REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0, |
| 1081 | AR_PHY_EXT_CCA0_THRESH62, pModal->thresh62); |
| 1082 | |
Sujith | 79d7f4b | 2010-06-01 15:14:06 +0530 | [diff] [blame] | 1083 | regval = REG_READ(ah, AR9287_AN_RF2G3_CH0); |
| 1084 | regval &= ~(AR9287_AN_RF2G3_DB1 | |
| 1085 | AR9287_AN_RF2G3_DB2 | |
| 1086 | AR9287_AN_RF2G3_OB_CCK | |
| 1087 | AR9287_AN_RF2G3_OB_PSK | |
| 1088 | AR9287_AN_RF2G3_OB_QAM | |
| 1089 | AR9287_AN_RF2G3_OB_PAL_OFF); |
| 1090 | regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) | |
| 1091 | SM(pModal->db2, AR9287_AN_RF2G3_DB2) | |
| 1092 | SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) | |
| 1093 | SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) | |
| 1094 | SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) | |
| 1095 | SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF)); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 1096 | |
Sujith | 79d7f4b | 2010-06-01 15:14:06 +0530 | [diff] [blame] | 1097 | ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH0, regval); |
| 1098 | |
| 1099 | regval = REG_READ(ah, AR9287_AN_RF2G3_CH1); |
| 1100 | regval &= ~(AR9287_AN_RF2G3_DB1 | |
| 1101 | AR9287_AN_RF2G3_DB2 | |
| 1102 | AR9287_AN_RF2G3_OB_CCK | |
| 1103 | AR9287_AN_RF2G3_OB_PSK | |
| 1104 | AR9287_AN_RF2G3_OB_QAM | |
| 1105 | AR9287_AN_RF2G3_OB_PAL_OFF); |
| 1106 | regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) | |
| 1107 | SM(pModal->db2, AR9287_AN_RF2G3_DB2) | |
| 1108 | SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) | |
| 1109 | SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) | |
| 1110 | SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) | |
| 1111 | SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF)); |
| 1112 | |
| 1113 | ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH1, regval); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 1114 | |
| 1115 | REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, |
| 1116 | AR_PHY_TX_END_DATA_START, pModal->txFrameToDataStart); |
| 1117 | REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, |
| 1118 | AR_PHY_TX_END_PA_ON, pModal->txFrameToPaOn); |
| 1119 | |
| 1120 | ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TOP2, |
| 1121 | AR9287_AN_TOP2_XPABIAS_LVL, |
| 1122 | AR9287_AN_TOP2_XPABIAS_LVL_S, |
| 1123 | pModal->xpaBiasLvl); |
| 1124 | } |
| 1125 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 1126 | static u8 ath9k_hw_ar9287_get_num_ant_config(struct ath_hw *ah, |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 1127 | enum ieee80211_band freq_band) |
| 1128 | { |
| 1129 | return 1; |
| 1130 | } |
| 1131 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 1132 | static u16 ath9k_hw_ar9287_get_eeprom_antenna_cfg(struct ath_hw *ah, |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 1133 | struct ath9k_channel *chan) |
| 1134 | { |
| 1135 | struct ar9287_eeprom *eep = &ah->eeprom.map9287; |
| 1136 | struct modal_eep_ar9287_header *pModal = &eep->modalHeader; |
| 1137 | |
| 1138 | return pModal->antCtrlCommon & 0xFFFF; |
| 1139 | } |
| 1140 | |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 1141 | static u16 ath9k_hw_ar9287_get_spur_channel(struct ath_hw *ah, |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 1142 | u16 i, bool is2GHz) |
| 1143 | { |
| 1144 | #define EEP_MAP9287_SPURCHAN \ |
| 1145 | (ah->eeprom.map9287.modalHeader.spurChans[i].spurChan) |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 1146 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1147 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 1148 | u16 spur_val = AR_NO_SPUR; |
| 1149 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1150 | ath_print(common, ATH_DBG_ANI, |
| 1151 | "Getting spur idx %d is2Ghz. %d val %x\n", |
| 1152 | i, is2GHz, ah->config.spurchans[i][is2GHz]); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 1153 | |
| 1154 | switch (ah->config.spurmode) { |
| 1155 | case SPUR_DISABLE: |
| 1156 | break; |
| 1157 | case SPUR_ENABLE_IOCTL: |
| 1158 | spur_val = ah->config.spurchans[i][is2GHz]; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1159 | ath_print(common, ATH_DBG_ANI, |
| 1160 | "Getting spur val from new loc. %d\n", spur_val); |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 1161 | break; |
| 1162 | case SPUR_ENABLE_EEPROM: |
| 1163 | spur_val = EEP_MAP9287_SPURCHAN; |
| 1164 | break; |
| 1165 | } |
| 1166 | |
| 1167 | return spur_val; |
| 1168 | |
| 1169 | #undef EEP_MAP9287_SPURCHAN |
| 1170 | } |
| 1171 | |
Luis R. Rodriguez | 0b8f6f2b1 | 2010-04-15 17:39:12 -0400 | [diff] [blame] | 1172 | const struct eeprom_ops eep_ar9287_ops = { |
Sujith | 16c94ac | 2010-06-01 15:14:04 +0530 | [diff] [blame] | 1173 | .check_eeprom = ath9k_hw_ar9287_check_eeprom, |
| 1174 | .get_eeprom = ath9k_hw_ar9287_get_eeprom, |
| 1175 | .fill_eeprom = ath9k_hw_ar9287_fill_eeprom, |
| 1176 | .get_eeprom_ver = ath9k_hw_ar9287_get_eeprom_ver, |
| 1177 | .get_eeprom_rev = ath9k_hw_ar9287_get_eeprom_rev, |
| 1178 | .get_num_ant_config = ath9k_hw_ar9287_get_num_ant_config, |
| 1179 | .get_eeprom_antenna_cfg = ath9k_hw_ar9287_get_eeprom_antenna_cfg, |
| 1180 | .set_board_values = ath9k_hw_ar9287_set_board_values, |
| 1181 | .set_addac = ath9k_hw_ar9287_set_addac, |
| 1182 | .set_txpower = ath9k_hw_ar9287_set_txpower, |
| 1183 | .get_spur_channel = ath9k_hw_ar9287_get_spur_channel |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 1184 | }; |