Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1 | /* |
Sujith | cee075a | 2009-03-13 09:07:23 +0530 | [diff] [blame] | 2 | * Copyright (c) 2008-2009 Atheros Communications Inc. |
Sujith | f1dc560 | 2008-10-29 10:16:30 +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 | |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 17 | #include "ath9k.h" |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 18 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 19 | static void ath9k_hw_analog_shift_rmw(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 20 | u32 reg, u32 mask, |
| 21 | u32 shift, u32 val) |
| 22 | { |
| 23 | u32 regVal; |
| 24 | |
| 25 | regVal = REG_READ(ah, reg) & ~mask; |
| 26 | regVal |= (val << shift) & mask; |
| 27 | |
| 28 | REG_WRITE(ah, reg, regVal); |
| 29 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 30 | if (ah->config.analog_shiftreg) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 31 | udelay(100); |
| 32 | |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | static inline u16 ath9k_hw_fbin2freq(u8 fbin, bool is2GHz) |
| 37 | { |
| 38 | |
| 39 | if (fbin == AR5416_BCHAN_UNUSED) |
| 40 | return fbin; |
| 41 | |
| 42 | return (u16) ((is2GHz) ? (2300 + fbin) : (4800 + 5 * fbin)); |
| 43 | } |
| 44 | |
| 45 | static inline int16_t ath9k_hw_interpolate(u16 target, |
| 46 | u16 srcLeft, u16 srcRight, |
| 47 | int16_t targetLeft, |
| 48 | int16_t targetRight) |
| 49 | { |
| 50 | int16_t rv; |
| 51 | |
| 52 | if (srcRight == srcLeft) { |
| 53 | rv = targetLeft; |
| 54 | } else { |
| 55 | rv = (int16_t) (((target - srcLeft) * targetRight + |
| 56 | (srcRight - target) * targetLeft) / |
| 57 | (srcRight - srcLeft)); |
| 58 | } |
| 59 | return rv; |
| 60 | } |
| 61 | |
| 62 | static inline bool ath9k_hw_get_lower_upper_index(u8 target, u8 *pList, |
| 63 | u16 listSize, u16 *indexL, |
| 64 | u16 *indexR) |
| 65 | { |
| 66 | u16 i; |
| 67 | |
| 68 | if (target <= pList[0]) { |
| 69 | *indexL = *indexR = 0; |
| 70 | return true; |
| 71 | } |
| 72 | if (target >= pList[listSize - 1]) { |
| 73 | *indexL = *indexR = (u16) (listSize - 1); |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | for (i = 0; i < listSize - 1; i++) { |
| 78 | if (pList[i] == target) { |
| 79 | *indexL = *indexR = i; |
| 80 | return true; |
| 81 | } |
| 82 | if (target < pList[i + 1]) { |
| 83 | *indexL = i; |
| 84 | *indexR = (u16) (i + 1); |
| 85 | return false; |
| 86 | } |
| 87 | } |
| 88 | return false; |
| 89 | } |
| 90 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 91 | static inline bool ath9k_hw_nvram_read(struct ath_hw *ah, u32 off, u16 *data) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 92 | { |
Gabor Juhos | 9dbeb91 | 2009-01-14 20:17:08 +0100 | [diff] [blame] | 93 | struct ath_softc *sc = ah->ah_sc; |
| 94 | |
| 95 | return sc->bus_ops->eeprom_read(ah, off, data); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 96 | } |
| 97 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 98 | static inline bool ath9k_hw_fill_vpd_table(u8 pwrMin, u8 pwrMax, u8 *pPwrList, |
| 99 | u8 *pVpdList, u16 numIntercepts, |
| 100 | u8 *pRetVpdList) |
| 101 | { |
| 102 | u16 i, k; |
| 103 | u8 currPwr = pwrMin; |
| 104 | u16 idxL = 0, idxR = 0; |
| 105 | |
| 106 | for (i = 0; i <= (pwrMax - pwrMin) / 2; i++) { |
| 107 | ath9k_hw_get_lower_upper_index(currPwr, pPwrList, |
| 108 | numIntercepts, &(idxL), |
| 109 | &(idxR)); |
| 110 | if (idxR < 1) |
| 111 | idxR = 1; |
| 112 | if (idxL == numIntercepts - 1) |
| 113 | idxL = (u16) (numIntercepts - 2); |
| 114 | if (pPwrList[idxL] == pPwrList[idxR]) |
| 115 | k = pVpdList[idxL]; |
| 116 | else |
| 117 | k = (u16)(((currPwr - pPwrList[idxL]) * pVpdList[idxR] + |
| 118 | (pPwrList[idxR] - currPwr) * pVpdList[idxL]) / |
| 119 | (pPwrList[idxR] - pPwrList[idxL])); |
| 120 | pRetVpdList[i] = (u8) k; |
| 121 | currPwr += 2; |
| 122 | } |
| 123 | |
| 124 | return true; |
| 125 | } |
| 126 | |
| 127 | static void ath9k_hw_get_legacy_target_powers(struct ath_hw *ah, |
| 128 | struct ath9k_channel *chan, |
| 129 | struct cal_target_power_leg *powInfo, |
| 130 | u16 numChannels, |
| 131 | struct cal_target_power_leg *pNewPower, |
| 132 | u16 numRates, bool isExtTarget) |
| 133 | { |
| 134 | struct chan_centers centers; |
| 135 | u16 clo, chi; |
| 136 | int i; |
| 137 | int matchIndex = -1, lowIndex = -1; |
| 138 | u16 freq; |
| 139 | |
| 140 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
| 141 | freq = (isExtTarget) ? centers.ext_center : centers.ctl_center; |
| 142 | |
| 143 | if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel, |
| 144 | IS_CHAN_2GHZ(chan))) { |
| 145 | matchIndex = 0; |
| 146 | } else { |
| 147 | for (i = 0; (i < numChannels) && |
| 148 | (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) { |
| 149 | if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel, |
| 150 | IS_CHAN_2GHZ(chan))) { |
| 151 | matchIndex = i; |
| 152 | break; |
| 153 | } else if ((freq < ath9k_hw_fbin2freq(powInfo[i].bChannel, |
| 154 | IS_CHAN_2GHZ(chan))) && |
| 155 | (freq > ath9k_hw_fbin2freq(powInfo[i - 1].bChannel, |
| 156 | IS_CHAN_2GHZ(chan)))) { |
| 157 | lowIndex = i - 1; |
| 158 | break; |
| 159 | } |
| 160 | } |
| 161 | if ((matchIndex == -1) && (lowIndex == -1)) |
| 162 | matchIndex = i - 1; |
| 163 | } |
| 164 | |
| 165 | if (matchIndex != -1) { |
| 166 | *pNewPower = powInfo[matchIndex]; |
| 167 | } else { |
| 168 | clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel, |
| 169 | IS_CHAN_2GHZ(chan)); |
| 170 | chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel, |
| 171 | IS_CHAN_2GHZ(chan)); |
| 172 | |
| 173 | for (i = 0; i < numRates; i++) { |
| 174 | pNewPower->tPow2x[i] = |
| 175 | (u8)ath9k_hw_interpolate(freq, clo, chi, |
| 176 | powInfo[lowIndex].tPow2x[i], |
| 177 | powInfo[lowIndex + 1].tPow2x[i]); |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 182 | static void ath9k_get_txgain_index(struct ath_hw *ah, |
| 183 | struct ath9k_channel *chan, |
| 184 | struct calDataPerFreqOpLoop *rawDatasetOpLoop, |
| 185 | u8 *calChans, u16 availPiers, u8 *pwr, u8 *pcdacIdx) |
| 186 | { |
| 187 | u8 pcdac, i = 0; |
| 188 | u16 idxL = 0, idxR = 0, numPiers; |
| 189 | bool match; |
| 190 | struct chan_centers centers; |
| 191 | |
| 192 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
| 193 | |
| 194 | for (numPiers = 0; numPiers < availPiers; numPiers++) |
| 195 | if (calChans[numPiers] == AR5416_BCHAN_UNUSED) |
| 196 | break; |
| 197 | |
| 198 | match = ath9k_hw_get_lower_upper_index( |
| 199 | (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)), |
| 200 | calChans, numPiers, &idxL, &idxR); |
| 201 | if (match) { |
| 202 | pcdac = rawDatasetOpLoop[idxL].pcdac[0][0]; |
| 203 | *pwr = rawDatasetOpLoop[idxL].pwrPdg[0][0]; |
| 204 | } else { |
| 205 | pcdac = rawDatasetOpLoop[idxR].pcdac[0][0]; |
| 206 | *pwr = (rawDatasetOpLoop[idxL].pwrPdg[0][0] + |
| 207 | rawDatasetOpLoop[idxR].pwrPdg[0][0])/2; |
| 208 | } |
| 209 | |
| 210 | while (pcdac > ah->originalGain[i] && |
| 211 | i < (AR9280_TX_GAIN_TABLE_SIZE - 1)) |
| 212 | i++; |
| 213 | |
| 214 | *pcdacIdx = i; |
| 215 | return; |
| 216 | } |
| 217 | |
| 218 | static void ath9k_olc_get_pdadcs(struct ath_hw *ah, |
| 219 | u32 initTxGain, |
| 220 | int txPower, |
| 221 | u8 *pPDADCValues) |
| 222 | { |
| 223 | u32 i; |
| 224 | u32 offset; |
| 225 | |
| 226 | REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL6_0, |
| 227 | AR_PHY_TX_PWRCTRL_ERR_EST_MODE, 3); |
| 228 | REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL6_1, |
| 229 | AR_PHY_TX_PWRCTRL_ERR_EST_MODE, 3); |
| 230 | |
| 231 | REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL7, |
| 232 | AR_PHY_TX_PWRCTRL_INIT_TX_GAIN, initTxGain); |
| 233 | |
| 234 | offset = txPower; |
| 235 | for (i = 0; i < AR5416_NUM_PDADC_VALUES; i++) |
| 236 | if (i < offset) |
| 237 | pPDADCValues[i] = 0x0; |
| 238 | else |
| 239 | pPDADCValues[i] = 0xFF; |
| 240 | } |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 245 | static void ath9k_hw_get_target_powers(struct ath_hw *ah, |
| 246 | struct ath9k_channel *chan, |
| 247 | struct cal_target_power_ht *powInfo, |
| 248 | u16 numChannels, |
| 249 | struct cal_target_power_ht *pNewPower, |
| 250 | u16 numRates, bool isHt40Target) |
| 251 | { |
| 252 | struct chan_centers centers; |
| 253 | u16 clo, chi; |
| 254 | int i; |
| 255 | int matchIndex = -1, lowIndex = -1; |
| 256 | u16 freq; |
| 257 | |
| 258 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
| 259 | freq = isHt40Target ? centers.synth_center : centers.ctl_center; |
| 260 | |
| 261 | if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel, IS_CHAN_2GHZ(chan))) { |
| 262 | matchIndex = 0; |
| 263 | } else { |
| 264 | for (i = 0; (i < numChannels) && |
| 265 | (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) { |
| 266 | if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel, |
| 267 | IS_CHAN_2GHZ(chan))) { |
| 268 | matchIndex = i; |
| 269 | break; |
| 270 | } else |
| 271 | if ((freq < ath9k_hw_fbin2freq(powInfo[i].bChannel, |
| 272 | IS_CHAN_2GHZ(chan))) && |
| 273 | (freq > ath9k_hw_fbin2freq(powInfo[i - 1].bChannel, |
| 274 | IS_CHAN_2GHZ(chan)))) { |
| 275 | lowIndex = i - 1; |
| 276 | break; |
| 277 | } |
| 278 | } |
| 279 | if ((matchIndex == -1) && (lowIndex == -1)) |
| 280 | matchIndex = i - 1; |
| 281 | } |
| 282 | |
| 283 | if (matchIndex != -1) { |
| 284 | *pNewPower = powInfo[matchIndex]; |
| 285 | } else { |
| 286 | clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel, |
| 287 | IS_CHAN_2GHZ(chan)); |
| 288 | chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel, |
| 289 | IS_CHAN_2GHZ(chan)); |
| 290 | |
| 291 | for (i = 0; i < numRates; i++) { |
| 292 | pNewPower->tPow2x[i] = (u8)ath9k_hw_interpolate(freq, |
| 293 | clo, chi, |
| 294 | powInfo[lowIndex].tPow2x[i], |
| 295 | powInfo[lowIndex + 1].tPow2x[i]); |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | static u16 ath9k_hw_get_max_edge_power(u16 freq, |
| 301 | struct cal_ctl_edges *pRdEdgesPower, |
| 302 | bool is2GHz, int num_band_edges) |
| 303 | { |
| 304 | u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER; |
| 305 | int i; |
| 306 | |
| 307 | for (i = 0; (i < num_band_edges) && |
| 308 | (pRdEdgesPower[i].bChannel != AR5416_BCHAN_UNUSED); i++) { |
| 309 | if (freq == ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel, is2GHz)) { |
| 310 | twiceMaxEdgePower = pRdEdgesPower[i].tPower; |
| 311 | break; |
| 312 | } else if ((i > 0) && |
| 313 | (freq < ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel, |
| 314 | is2GHz))) { |
| 315 | if (ath9k_hw_fbin2freq(pRdEdgesPower[i - 1].bChannel, |
| 316 | is2GHz) < freq && |
| 317 | pRdEdgesPower[i - 1].flag) { |
| 318 | twiceMaxEdgePower = |
| 319 | pRdEdgesPower[i - 1].tPower; |
| 320 | } |
| 321 | break; |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | return twiceMaxEdgePower; |
| 326 | } |
| 327 | |
| 328 | /****************************************/ |
| 329 | /* EEPROM Operations for 4K sized cards */ |
| 330 | /****************************************/ |
| 331 | |
| 332 | static int ath9k_hw_4k_get_eeprom_ver(struct ath_hw *ah) |
| 333 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 334 | return ((ah->eeprom.map4k.baseEepHeader.version >> 12) & 0xF); |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | static int ath9k_hw_4k_get_eeprom_rev(struct ath_hw *ah) |
| 338 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 339 | return ((ah->eeprom.map4k.baseEepHeader.version) & 0xFFF); |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | static bool ath9k_hw_4k_fill_eeprom(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 343 | { |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 344 | #define SIZE_EEPROM_4K (sizeof(struct ar5416_eeprom_4k) / sizeof(u16)) |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 345 | u16 *eep_data = (u16 *)&ah->eeprom.map4k; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 346 | int addr, eep_start_loc = 0; |
| 347 | |
| 348 | eep_start_loc = 64; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 349 | |
| 350 | if (!ath9k_hw_use_flash(ah)) { |
| 351 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 352 | "Reading from EEPROM, not flash\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 353 | } |
| 354 | |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 355 | for (addr = 0; addr < SIZE_EEPROM_4K; addr++) { |
| 356 | if (!ath9k_hw_nvram_read(ah, addr + eep_start_loc, eep_data)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 357 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 358 | "Unable to read eeprom region \n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 359 | return false; |
| 360 | } |
| 361 | eep_data++; |
| 362 | } |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 363 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 364 | return true; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 365 | #undef SIZE_EEPROM_4K |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 366 | } |
| 367 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 368 | static int ath9k_hw_4k_check_eeprom(struct ath_hw *ah) |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 369 | { |
| 370 | #define EEPROM_4K_SIZE (sizeof(struct ar5416_eeprom_4k) / sizeof(u16)) |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 371 | struct ar5416_eeprom_4k *eep = |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 372 | (struct ar5416_eeprom_4k *) &ah->eeprom.map4k; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 373 | u16 *eepdata, temp, magic, magic2; |
| 374 | u32 sum = 0, el; |
| 375 | bool need_swap = false; |
| 376 | int i, addr; |
| 377 | |
| 378 | |
| 379 | if (!ath9k_hw_use_flash(ah)) { |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 380 | if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET, |
| 381 | &magic)) { |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 382 | DPRINTF(ah->ah_sc, ATH_DBG_FATAL, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 383 | "Reading Magic # failed\n"); |
| 384 | return false; |
| 385 | } |
| 386 | |
| 387 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 388 | "Read Magic = 0x%04X\n", magic); |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 389 | |
| 390 | if (magic != AR5416_EEPROM_MAGIC) { |
| 391 | magic2 = swab16(magic); |
| 392 | |
| 393 | if (magic2 == AR5416_EEPROM_MAGIC) { |
| 394 | need_swap = true; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 395 | eepdata = (u16 *) (&ah->eeprom); |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 396 | |
| 397 | for (addr = 0; addr < EEPROM_4K_SIZE; addr++) { |
| 398 | temp = swab16(*eepdata); |
| 399 | *eepdata = temp; |
| 400 | eepdata++; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 401 | } |
| 402 | } else { |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 403 | DPRINTF(ah->ah_sc, ATH_DBG_FATAL, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 404 | "Invalid EEPROM Magic. " |
| 405 | "endianness mismatch.\n"); |
| 406 | return -EINVAL; |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "need_swap = %s.\n", |
| 412 | need_swap ? "True" : "False"); |
| 413 | |
| 414 | if (need_swap) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 415 | el = swab16(ah->eeprom.map4k.baseEepHeader.length); |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 416 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 417 | el = ah->eeprom.map4k.baseEepHeader.length; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 418 | |
Sujith | e71cef3 | 2009-03-13 08:56:07 +0530 | [diff] [blame] | 419 | if (el > sizeof(struct ar5416_eeprom_4k)) |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 420 | el = sizeof(struct ar5416_eeprom_4k) / sizeof(u16); |
| 421 | else |
| 422 | el = el / sizeof(u16); |
| 423 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 424 | eepdata = (u16 *)(&ah->eeprom); |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 425 | |
| 426 | for (i = 0; i < el; i++) |
| 427 | sum ^= *eepdata++; |
| 428 | |
| 429 | if (need_swap) { |
| 430 | u32 integer; |
| 431 | u16 word; |
| 432 | |
| 433 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 434 | "EEPROM Endianness is not native.. Changing\n"); |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 435 | |
| 436 | word = swab16(eep->baseEepHeader.length); |
| 437 | eep->baseEepHeader.length = word; |
| 438 | |
| 439 | word = swab16(eep->baseEepHeader.checksum); |
| 440 | eep->baseEepHeader.checksum = word; |
| 441 | |
| 442 | word = swab16(eep->baseEepHeader.version); |
| 443 | eep->baseEepHeader.version = word; |
| 444 | |
| 445 | word = swab16(eep->baseEepHeader.regDmn[0]); |
| 446 | eep->baseEepHeader.regDmn[0] = word; |
| 447 | |
| 448 | word = swab16(eep->baseEepHeader.regDmn[1]); |
| 449 | eep->baseEepHeader.regDmn[1] = word; |
| 450 | |
| 451 | word = swab16(eep->baseEepHeader.rfSilent); |
| 452 | eep->baseEepHeader.rfSilent = word; |
| 453 | |
| 454 | word = swab16(eep->baseEepHeader.blueToothOptions); |
| 455 | eep->baseEepHeader.blueToothOptions = word; |
| 456 | |
| 457 | word = swab16(eep->baseEepHeader.deviceCap); |
| 458 | eep->baseEepHeader.deviceCap = word; |
| 459 | |
| 460 | integer = swab32(eep->modalHeader.antCtrlCommon); |
| 461 | eep->modalHeader.antCtrlCommon = integer; |
| 462 | |
Roel Kluin | 008749f | 2009-07-25 23:21:22 +0200 | [diff] [blame] | 463 | for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++) { |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 464 | integer = swab32(eep->modalHeader.antCtrlChain[i]); |
| 465 | eep->modalHeader.antCtrlChain[i] = integer; |
| 466 | } |
| 467 | |
| 468 | for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) { |
| 469 | word = swab16(eep->modalHeader.spurChans[i].spurChan); |
| 470 | eep->modalHeader.spurChans[i].spurChan = word; |
| 471 | } |
| 472 | } |
| 473 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 474 | if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR5416_EEP_VER || |
| 475 | ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) { |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 476 | DPRINTF(ah->ah_sc, ATH_DBG_FATAL, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 477 | "Bad EEPROM checksum 0x%x or revision 0x%04x\n", |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 478 | sum, ah->eep_ops->get_eeprom_ver(ah)); |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 479 | return -EINVAL; |
| 480 | } |
| 481 | |
| 482 | return 0; |
| 483 | #undef EEPROM_4K_SIZE |
| 484 | } |
| 485 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 486 | static u32 ath9k_hw_4k_get_eeprom(struct ath_hw *ah, |
| 487 | enum eeprom_param param) |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 488 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 489 | struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 490 | struct modal_eep_4k_header *pModal = &eep->modalHeader; |
| 491 | struct base_eep_header_4k *pBase = &eep->baseEepHeader; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 492 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 493 | switch (param) { |
| 494 | case EEP_NFTHRESH_2: |
Sujith | 668158a | 2009-02-12 10:06:52 +0530 | [diff] [blame] | 495 | return pModal->noiseFloorThreshCh[0]; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 496 | case AR_EEPROM_MAC(0): |
| 497 | return pBase->macAddr[0] << 8 | pBase->macAddr[1]; |
| 498 | case AR_EEPROM_MAC(1): |
| 499 | return pBase->macAddr[2] << 8 | pBase->macAddr[3]; |
| 500 | case AR_EEPROM_MAC(2): |
| 501 | return pBase->macAddr[4] << 8 | pBase->macAddr[5]; |
| 502 | case EEP_REG_0: |
| 503 | return pBase->regDmn[0]; |
| 504 | case EEP_REG_1: |
| 505 | return pBase->regDmn[1]; |
| 506 | case EEP_OP_CAP: |
| 507 | return pBase->deviceCap; |
| 508 | case EEP_OP_MODE: |
| 509 | return pBase->opCapFlags; |
| 510 | case EEP_RF_SILENT: |
| 511 | return pBase->rfSilent; |
| 512 | case EEP_OB_2: |
| 513 | return pModal->ob_01; |
| 514 | case EEP_DB_2: |
| 515 | return pModal->db1_01; |
| 516 | case EEP_MINOR_REV: |
| 517 | return pBase->version & AR5416_EEP_VER_MINOR_MASK; |
| 518 | case EEP_TX_MASK: |
| 519 | return pBase->txMask; |
| 520 | case EEP_RX_MASK: |
| 521 | return pBase->rxMask; |
Sujith | 06d0f06 | 2009-02-12 10:06:45 +0530 | [diff] [blame] | 522 | case EEP_FRAC_N_5G: |
| 523 | return 0; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 524 | default: |
| 525 | return 0; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 526 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 527 | } |
| 528 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 529 | static void ath9k_hw_get_4k_gain_boundaries_pdadcs(struct ath_hw *ah, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 530 | struct ath9k_channel *chan, |
| 531 | struct cal_data_per_freq_4k *pRawDataSet, |
| 532 | u8 *bChans, u16 availPiers, |
| 533 | u16 tPdGainOverlap, int16_t *pMinCalPower, |
| 534 | u16 *pPdGainBoundaries, u8 *pPDADCValues, |
| 535 | u16 numXpdGains) |
| 536 | { |
| 537 | #define TMP_VAL_VPD_TABLE \ |
| 538 | ((vpdTableI[i][sizeCurrVpdTable - 1] + (ss - maxIndex + 1) * vpdStep)); |
| 539 | int i, j, k; |
| 540 | int16_t ss; |
| 541 | u16 idxL = 0, idxR = 0, numPiers; |
| 542 | static u8 vpdTableL[AR5416_EEP4K_NUM_PD_GAINS] |
| 543 | [AR5416_MAX_PWR_RANGE_IN_HALF_DB]; |
| 544 | static u8 vpdTableR[AR5416_EEP4K_NUM_PD_GAINS] |
| 545 | [AR5416_MAX_PWR_RANGE_IN_HALF_DB]; |
| 546 | static u8 vpdTableI[AR5416_EEP4K_NUM_PD_GAINS] |
| 547 | [AR5416_MAX_PWR_RANGE_IN_HALF_DB]; |
| 548 | |
| 549 | u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR; |
| 550 | u8 minPwrT4[AR5416_EEP4K_NUM_PD_GAINS]; |
| 551 | u8 maxPwrT4[AR5416_EEP4K_NUM_PD_GAINS]; |
| 552 | int16_t vpdStep; |
| 553 | int16_t tmpVal; |
| 554 | u16 sizeCurrVpdTable, maxIndex, tgtIndex; |
| 555 | bool match; |
| 556 | int16_t minDelta = 0; |
| 557 | struct chan_centers centers; |
| 558 | #define PD_GAIN_BOUNDARY_DEFAULT 58; |
| 559 | |
| 560 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
| 561 | |
| 562 | for (numPiers = 0; numPiers < availPiers; numPiers++) { |
| 563 | if (bChans[numPiers] == AR5416_BCHAN_UNUSED) |
| 564 | break; |
| 565 | } |
| 566 | |
| 567 | match = ath9k_hw_get_lower_upper_index( |
| 568 | (u8)FREQ2FBIN(centers.synth_center, |
| 569 | IS_CHAN_2GHZ(chan)), bChans, numPiers, |
| 570 | &idxL, &idxR); |
| 571 | |
| 572 | if (match) { |
| 573 | for (i = 0; i < numXpdGains; i++) { |
| 574 | minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0]; |
| 575 | maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4]; |
| 576 | ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i], |
| 577 | pRawDataSet[idxL].pwrPdg[i], |
| 578 | pRawDataSet[idxL].vpdPdg[i], |
| 579 | AR5416_EEP4K_PD_GAIN_ICEPTS, |
| 580 | vpdTableI[i]); |
| 581 | } |
| 582 | } else { |
| 583 | for (i = 0; i < numXpdGains; i++) { |
| 584 | pVpdL = pRawDataSet[idxL].vpdPdg[i]; |
| 585 | pPwrL = pRawDataSet[idxL].pwrPdg[i]; |
| 586 | pVpdR = pRawDataSet[idxR].vpdPdg[i]; |
| 587 | pPwrR = pRawDataSet[idxR].pwrPdg[i]; |
| 588 | |
| 589 | minPwrT4[i] = max(pPwrL[0], pPwrR[0]); |
| 590 | |
| 591 | maxPwrT4[i] = |
| 592 | min(pPwrL[AR5416_EEP4K_PD_GAIN_ICEPTS - 1], |
| 593 | pPwrR[AR5416_EEP4K_PD_GAIN_ICEPTS - 1]); |
| 594 | |
| 595 | |
| 596 | ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i], |
| 597 | pPwrL, pVpdL, |
| 598 | AR5416_EEP4K_PD_GAIN_ICEPTS, |
| 599 | vpdTableL[i]); |
| 600 | ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i], |
| 601 | pPwrR, pVpdR, |
| 602 | AR5416_EEP4K_PD_GAIN_ICEPTS, |
| 603 | vpdTableR[i]); |
| 604 | |
| 605 | for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) { |
| 606 | vpdTableI[i][j] = |
| 607 | (u8)(ath9k_hw_interpolate((u16) |
| 608 | FREQ2FBIN(centers. |
| 609 | synth_center, |
| 610 | IS_CHAN_2GHZ |
| 611 | (chan)), |
| 612 | bChans[idxL], bChans[idxR], |
| 613 | vpdTableL[i][j], vpdTableR[i][j])); |
| 614 | } |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | *pMinCalPower = (int16_t)(minPwrT4[0] / 2); |
| 619 | |
| 620 | k = 0; |
| 621 | |
| 622 | for (i = 0; i < numXpdGains; i++) { |
| 623 | if (i == (numXpdGains - 1)) |
| 624 | pPdGainBoundaries[i] = |
| 625 | (u16)(maxPwrT4[i] / 2); |
| 626 | else |
| 627 | pPdGainBoundaries[i] = |
| 628 | (u16)((maxPwrT4[i] + minPwrT4[i + 1]) / 4); |
| 629 | |
| 630 | pPdGainBoundaries[i] = |
| 631 | min((u16)AR5416_MAX_RATE_POWER, pPdGainBoundaries[i]); |
| 632 | |
Gabor Juhos | a8c96d3 | 2009-03-06 09:08:51 +0100 | [diff] [blame] | 633 | if ((i == 0) && !AR_SREV_5416_20_OR_LATER(ah)) { |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 634 | minDelta = pPdGainBoundaries[0] - 23; |
| 635 | pPdGainBoundaries[0] = 23; |
| 636 | } else { |
| 637 | minDelta = 0; |
| 638 | } |
| 639 | |
| 640 | if (i == 0) { |
| 641 | if (AR_SREV_9280_10_OR_LATER(ah)) |
| 642 | ss = (int16_t)(0 - (minPwrT4[i] / 2)); |
| 643 | else |
| 644 | ss = 0; |
| 645 | } else { |
| 646 | ss = (int16_t)((pPdGainBoundaries[i - 1] - |
| 647 | (minPwrT4[i] / 2)) - |
| 648 | tPdGainOverlap + 1 + minDelta); |
| 649 | } |
| 650 | vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]); |
| 651 | vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep); |
| 652 | |
| 653 | while ((ss < 0) && (k < (AR5416_NUM_PDADC_VALUES - 1))) { |
| 654 | tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep); |
| 655 | pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal); |
| 656 | ss++; |
| 657 | } |
| 658 | |
| 659 | sizeCurrVpdTable = (u8) ((maxPwrT4[i] - minPwrT4[i]) / 2 + 1); |
| 660 | tgtIndex = (u8)(pPdGainBoundaries[i] + tPdGainOverlap - |
| 661 | (minPwrT4[i] / 2)); |
| 662 | maxIndex = (tgtIndex < sizeCurrVpdTable) ? |
| 663 | tgtIndex : sizeCurrVpdTable; |
| 664 | |
| 665 | while ((ss < maxIndex) && (k < (AR5416_NUM_PDADC_VALUES - 1))) |
| 666 | pPDADCValues[k++] = vpdTableI[i][ss++]; |
| 667 | |
| 668 | vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] - |
| 669 | vpdTableI[i][sizeCurrVpdTable - 2]); |
| 670 | vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep); |
| 671 | |
Vasanthakumar Thiagarajan | be1b08a | 2009-03-06 20:38:36 +0530 | [diff] [blame] | 672 | if (tgtIndex >= maxIndex) { |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 673 | while ((ss <= tgtIndex) && |
| 674 | (k < (AR5416_NUM_PDADC_VALUES - 1))) { |
| 675 | tmpVal = (int16_t) TMP_VAL_VPD_TABLE; |
| 676 | pPDADCValues[k++] = (u8)((tmpVal > 255) ? |
| 677 | 255 : tmpVal); |
| 678 | ss++; |
| 679 | } |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | while (i < AR5416_EEP4K_PD_GAINS_IN_MASK) { |
| 684 | pPdGainBoundaries[i] = PD_GAIN_BOUNDARY_DEFAULT; |
| 685 | i++; |
| 686 | } |
| 687 | |
| 688 | while (k < AR5416_NUM_PDADC_VALUES) { |
| 689 | pPDADCValues[k] = pPDADCValues[k - 1]; |
| 690 | k++; |
| 691 | } |
| 692 | |
| 693 | return; |
| 694 | #undef TMP_VAL_VPD_TABLE |
| 695 | } |
| 696 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 697 | static void ath9k_hw_set_4k_power_cal_table(struct ath_hw *ah, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 698 | struct ath9k_channel *chan, |
| 699 | int16_t *pTxPowerIndexOffset) |
| 700 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 701 | struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 702 | struct cal_data_per_freq_4k *pRawDataset; |
| 703 | u8 *pCalBChans = NULL; |
| 704 | u16 pdGainOverlap_t2; |
| 705 | static u8 pdadcValues[AR5416_NUM_PDADC_VALUES]; |
Vasanthakumar Thiagarajan | be1b08a | 2009-03-06 20:38:36 +0530 | [diff] [blame] | 706 | u16 gainBoundaries[AR5416_EEP4K_PD_GAINS_IN_MASK]; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 707 | u16 numPiers, i, j; |
| 708 | int16_t tMinCalPower; |
| 709 | u16 numXpdGain, xpdMask; |
Vasanthakumar Thiagarajan | be1b08a | 2009-03-06 20:38:36 +0530 | [diff] [blame] | 710 | u16 xpdGainValues[AR5416_EEP4K_NUM_PD_GAINS] = { 0, 0 }; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 711 | u32 reg32, regOffset, regChainOffset; |
| 712 | |
| 713 | xpdMask = pEepData->modalHeader.xpdGain; |
| 714 | |
| 715 | if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >= |
| 716 | AR5416_EEP_MINOR_VER_2) { |
| 717 | pdGainOverlap_t2 = |
| 718 | pEepData->modalHeader.pdGainOverlap; |
| 719 | } else { |
| 720 | pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5), |
| 721 | AR_PHY_TPCRG5_PD_GAIN_OVERLAP)); |
| 722 | } |
| 723 | |
| 724 | pCalBChans = pEepData->calFreqPier2G; |
Vasanthakumar Thiagarajan | be1b08a | 2009-03-06 20:38:36 +0530 | [diff] [blame] | 725 | numPiers = AR5416_EEP4K_NUM_2G_CAL_PIERS; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 726 | |
| 727 | numXpdGain = 0; |
| 728 | |
Vasanthakumar Thiagarajan | be1b08a | 2009-03-06 20:38:36 +0530 | [diff] [blame] | 729 | for (i = 1; i <= AR5416_EEP4K_PD_GAINS_IN_MASK; i++) { |
| 730 | if ((xpdMask >> (AR5416_EEP4K_PD_GAINS_IN_MASK - i)) & 1) { |
| 731 | if (numXpdGain >= AR5416_EEP4K_NUM_PD_GAINS) |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 732 | break; |
| 733 | xpdGainValues[numXpdGain] = |
Vasanthakumar Thiagarajan | be1b08a | 2009-03-06 20:38:36 +0530 | [diff] [blame] | 734 | (u16)(AR5416_EEP4K_PD_GAINS_IN_MASK - i); |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 735 | numXpdGain++; |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN, |
| 740 | (numXpdGain - 1) & 0x3); |
| 741 | REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1, |
| 742 | xpdGainValues[0]); |
| 743 | REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2, |
| 744 | xpdGainValues[1]); |
Vasanthakumar Thiagarajan | f40154e | 2009-02-25 10:28:22 +0530 | [diff] [blame] | 745 | REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3, 0); |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 746 | |
Vasanthakumar Thiagarajan | be1b08a | 2009-03-06 20:38:36 +0530 | [diff] [blame] | 747 | for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++) { |
Gabor Juhos | a8c96d3 | 2009-03-06 09:08:51 +0100 | [diff] [blame] | 748 | if (AR_SREV_5416_20_OR_LATER(ah) && |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 749 | (ah->rxchainmask == 5 || ah->txchainmask == 5) && |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 750 | (i != 0)) { |
| 751 | regChainOffset = (i == 1) ? 0x2000 : 0x1000; |
| 752 | } else |
| 753 | regChainOffset = i * 0x1000; |
| 754 | |
| 755 | if (pEepData->baseEepHeader.txMask & (1 << i)) { |
| 756 | pRawDataset = pEepData->calPierData2G[i]; |
| 757 | |
| 758 | ath9k_hw_get_4k_gain_boundaries_pdadcs(ah, chan, |
| 759 | pRawDataset, pCalBChans, |
| 760 | numPiers, pdGainOverlap_t2, |
| 761 | &tMinCalPower, gainBoundaries, |
| 762 | pdadcValues, numXpdGain); |
| 763 | |
Gabor Juhos | a8c96d3 | 2009-03-06 09:08:51 +0100 | [diff] [blame] | 764 | if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah)) { |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 765 | REG_WRITE(ah, AR_PHY_TPCRG5 + regChainOffset, |
| 766 | SM(pdGainOverlap_t2, |
| 767 | AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
| 768 | | SM(gainBoundaries[0], |
| 769 | AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1) |
| 770 | | SM(gainBoundaries[1], |
| 771 | AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2) |
| 772 | | SM(gainBoundaries[2], |
| 773 | AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3) |
| 774 | | SM(gainBoundaries[3], |
| 775 | AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4)); |
| 776 | } |
| 777 | |
| 778 | regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset; |
| 779 | for (j = 0; j < 32; j++) { |
| 780 | reg32 = ((pdadcValues[4 * j + 0] & 0xFF) << 0) | |
| 781 | ((pdadcValues[4 * j + 1] & 0xFF) << 8) | |
| 782 | ((pdadcValues[4 * j + 2] & 0xFF) << 16)| |
| 783 | ((pdadcValues[4 * j + 3] & 0xFF) << 24); |
| 784 | REG_WRITE(ah, regOffset, reg32); |
| 785 | |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 786 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 787 | "PDADC (%d,%4x): %4.4x %8.8x\n", |
| 788 | i, regChainOffset, regOffset, |
| 789 | reg32); |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 790 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 791 | "PDADC: Chain %d | " |
| 792 | "PDADC %3d Value %3d | " |
| 793 | "PDADC %3d Value %3d | " |
| 794 | "PDADC %3d Value %3d | " |
| 795 | "PDADC %3d Value %3d |\n", |
| 796 | i, 4 * j, pdadcValues[4 * j], |
| 797 | 4 * j + 1, pdadcValues[4 * j + 1], |
| 798 | 4 * j + 2, pdadcValues[4 * j + 2], |
| 799 | 4 * j + 3, |
| 800 | pdadcValues[4 * j + 3]); |
| 801 | |
| 802 | regOffset += 4; |
| 803 | } |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | *pTxPowerIndexOffset = 0; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 808 | } |
| 809 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 810 | static void ath9k_hw_set_4k_power_per_rate_table(struct ath_hw *ah, |
Hannes Eder | bf512bc | 2008-12-26 00:13:29 -0800 | [diff] [blame] | 811 | struct ath9k_channel *chan, |
| 812 | int16_t *ratesArray, |
| 813 | u16 cfgCtl, |
| 814 | u16 AntennaReduction, |
| 815 | u16 twiceMaxRegulatoryPower, |
| 816 | u16 powerLimit) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 817 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 818 | struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 819 | u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER; |
| 820 | static const u16 tpScaleReductionTable[5] = |
| 821 | { 0, 3, 6, 9, AR5416_MAX_RATE_POWER }; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 822 | |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 823 | int i; |
| 824 | int16_t twiceLargestAntenna; |
| 825 | struct cal_ctl_data_4k *rep; |
| 826 | struct cal_target_power_leg targetPowerOfdm, targetPowerCck = { |
| 827 | 0, { 0, 0, 0, 0} |
| 828 | }; |
| 829 | struct cal_target_power_leg targetPowerOfdmExt = { |
| 830 | 0, { 0, 0, 0, 0} }, targetPowerCckExt = { |
| 831 | 0, { 0, 0, 0, 0 } |
| 832 | }; |
| 833 | struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = { |
| 834 | 0, {0, 0, 0, 0} |
| 835 | }; |
| 836 | u16 scaledPower = 0, minCtlPower, maxRegAllowedPower; |
| 837 | u16 ctlModesFor11g[] = |
| 838 | { CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, CTL_11G_EXT, |
| 839 | CTL_2GHT40 |
| 840 | }; |
| 841 | u16 numCtlModes, *pCtlMode, ctlMode, freq; |
| 842 | struct chan_centers centers; |
| 843 | int tx_chainmask; |
| 844 | u16 twiceMinEdgePower; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 845 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 846 | tx_chainmask = ah->txchainmask; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 847 | |
| 848 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
| 849 | |
| 850 | twiceLargestAntenna = pEepData->modalHeader.antennaGainCh[0]; |
| 851 | |
| 852 | twiceLargestAntenna = (int16_t)min(AntennaReduction - |
| 853 | twiceLargestAntenna, 0); |
| 854 | |
| 855 | maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna; |
| 856 | |
Sujith | d6bad49 | 2009-02-09 13:27:08 +0530 | [diff] [blame] | 857 | if (ah->regulatory.tp_scale != ATH9K_TP_SCALE_MAX) { |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 858 | maxRegAllowedPower -= |
Sujith | d6bad49 | 2009-02-09 13:27:08 +0530 | [diff] [blame] | 859 | (tpScaleReductionTable[(ah->regulatory.tp_scale)] * 2); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 860 | } |
| 861 | |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 862 | scaledPower = min(powerLimit, maxRegAllowedPower); |
| 863 | scaledPower = max((u16)0, scaledPower); |
| 864 | |
| 865 | numCtlModes = ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40; |
| 866 | pCtlMode = ctlModesFor11g; |
| 867 | |
| 868 | ath9k_hw_get_legacy_target_powers(ah, chan, |
| 869 | pEepData->calTargetPowerCck, |
| 870 | AR5416_NUM_2G_CCK_TARGET_POWERS, |
| 871 | &targetPowerCck, 4, false); |
| 872 | ath9k_hw_get_legacy_target_powers(ah, chan, |
| 873 | pEepData->calTargetPower2G, |
| 874 | AR5416_NUM_2G_20_TARGET_POWERS, |
| 875 | &targetPowerOfdm, 4, false); |
| 876 | ath9k_hw_get_target_powers(ah, chan, |
| 877 | pEepData->calTargetPower2GHT20, |
| 878 | AR5416_NUM_2G_20_TARGET_POWERS, |
| 879 | &targetPowerHt20, 8, false); |
| 880 | |
| 881 | if (IS_CHAN_HT40(chan)) { |
| 882 | numCtlModes = ARRAY_SIZE(ctlModesFor11g); |
| 883 | ath9k_hw_get_target_powers(ah, chan, |
| 884 | pEepData->calTargetPower2GHT40, |
| 885 | AR5416_NUM_2G_40_TARGET_POWERS, |
| 886 | &targetPowerHt40, 8, true); |
| 887 | ath9k_hw_get_legacy_target_powers(ah, chan, |
| 888 | pEepData->calTargetPowerCck, |
| 889 | AR5416_NUM_2G_CCK_TARGET_POWERS, |
| 890 | &targetPowerCckExt, 4, true); |
| 891 | ath9k_hw_get_legacy_target_powers(ah, chan, |
| 892 | pEepData->calTargetPower2G, |
| 893 | AR5416_NUM_2G_20_TARGET_POWERS, |
| 894 | &targetPowerOfdmExt, 4, true); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 895 | } |
| 896 | |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 897 | for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) { |
| 898 | bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) || |
| 899 | (pCtlMode[ctlMode] == CTL_2GHT40); |
| 900 | if (isHt40CtlMode) |
| 901 | freq = centers.synth_center; |
| 902 | else if (pCtlMode[ctlMode] & EXT_ADDITIVE) |
| 903 | freq = centers.ext_center; |
| 904 | else |
| 905 | freq = centers.ctl_center; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 906 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 907 | if (ah->eep_ops->get_eeprom_ver(ah) == 14 && |
| 908 | ah->eep_ops->get_eeprom_rev(ah) <= 2) |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 909 | twiceMaxEdgePower = AR5416_MAX_RATE_POWER; |
| 910 | |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 911 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 912 | "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d, " |
| 913 | "EXT_ADDITIVE %d\n", |
| 914 | ctlMode, numCtlModes, isHt40CtlMode, |
| 915 | (pCtlMode[ctlMode] & EXT_ADDITIVE)); |
| 916 | |
Roel Kluin | 008749f | 2009-07-25 23:21:22 +0200 | [diff] [blame] | 917 | for (i = 0; (i < AR5416_EEP4K_NUM_CTLS) && |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 918 | pEepData->ctlIndex[i]; i++) { |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 919 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 920 | " LOOP-Ctlidx %d: cfgCtl 0x%2.2x " |
| 921 | "pCtlMode 0x%2.2x ctlIndex 0x%2.2x " |
| 922 | "chan %d\n", |
| 923 | i, cfgCtl, pCtlMode[ctlMode], |
| 924 | pEepData->ctlIndex[i], chan->channel); |
| 925 | |
| 926 | if ((((cfgCtl & ~CTL_MODE_M) | |
| 927 | (pCtlMode[ctlMode] & CTL_MODE_M)) == |
| 928 | pEepData->ctlIndex[i]) || |
| 929 | (((cfgCtl & ~CTL_MODE_M) | |
| 930 | (pCtlMode[ctlMode] & CTL_MODE_M)) == |
| 931 | ((pEepData->ctlIndex[i] & CTL_MODE_M) | |
| 932 | SD_NO_CTL))) { |
| 933 | rep = &(pEepData->ctlData[i]); |
| 934 | |
| 935 | twiceMinEdgePower = |
| 936 | ath9k_hw_get_max_edge_power(freq, |
| 937 | rep->ctlEdges[ar5416_get_ntxchains |
| 938 | (tx_chainmask) - 1], |
| 939 | IS_CHAN_2GHZ(chan), |
| 940 | AR5416_EEP4K_NUM_BAND_EDGES); |
| 941 | |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 942 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 943 | " MATCH-EE_IDX %d: ch %d is2 %d " |
| 944 | "2xMinEdge %d chainmask %d chains %d\n", |
| 945 | i, freq, IS_CHAN_2GHZ(chan), |
| 946 | twiceMinEdgePower, tx_chainmask, |
| 947 | ar5416_get_ntxchains |
| 948 | (tx_chainmask)); |
| 949 | if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) { |
| 950 | twiceMaxEdgePower = |
| 951 | min(twiceMaxEdgePower, |
| 952 | twiceMinEdgePower); |
| 953 | } else { |
| 954 | twiceMaxEdgePower = twiceMinEdgePower; |
| 955 | break; |
| 956 | } |
| 957 | } |
| 958 | } |
| 959 | |
| 960 | minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower); |
| 961 | |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 962 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 963 | " SEL-Min ctlMode %d pCtlMode %d " |
| 964 | "2xMaxEdge %d sP %d minCtlPwr %d\n", |
| 965 | ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower, |
| 966 | scaledPower, minCtlPower); |
| 967 | |
| 968 | switch (pCtlMode[ctlMode]) { |
| 969 | case CTL_11B: |
| 970 | for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); |
| 971 | i++) { |
| 972 | targetPowerCck.tPow2x[i] = |
| 973 | min((u16)targetPowerCck.tPow2x[i], |
| 974 | minCtlPower); |
| 975 | } |
| 976 | break; |
| 977 | case CTL_11G: |
| 978 | for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); |
| 979 | i++) { |
| 980 | targetPowerOfdm.tPow2x[i] = |
| 981 | min((u16)targetPowerOfdm.tPow2x[i], |
| 982 | minCtlPower); |
| 983 | } |
| 984 | break; |
| 985 | case CTL_2GHT20: |
| 986 | for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); |
| 987 | i++) { |
| 988 | targetPowerHt20.tPow2x[i] = |
| 989 | min((u16)targetPowerHt20.tPow2x[i], |
| 990 | minCtlPower); |
| 991 | } |
| 992 | break; |
| 993 | case CTL_11B_EXT: |
| 994 | targetPowerCckExt.tPow2x[0] = min((u16) |
| 995 | targetPowerCckExt.tPow2x[0], |
| 996 | minCtlPower); |
| 997 | break; |
| 998 | case CTL_11G_EXT: |
| 999 | targetPowerOfdmExt.tPow2x[0] = min((u16) |
| 1000 | targetPowerOfdmExt.tPow2x[0], |
| 1001 | minCtlPower); |
| 1002 | break; |
| 1003 | case CTL_2GHT40: |
| 1004 | for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); |
| 1005 | i++) { |
| 1006 | targetPowerHt40.tPow2x[i] = |
| 1007 | min((u16)targetPowerHt40.tPow2x[i], |
| 1008 | minCtlPower); |
| 1009 | } |
| 1010 | break; |
| 1011 | default: |
| 1012 | break; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1013 | } |
| 1014 | } |
| 1015 | |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1016 | ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] = |
| 1017 | ratesArray[rate18mb] = ratesArray[rate24mb] = |
| 1018 | targetPowerOfdm.tPow2x[0]; |
| 1019 | ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1]; |
| 1020 | ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2]; |
| 1021 | ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3]; |
| 1022 | ratesArray[rateXr] = targetPowerOfdm.tPow2x[0]; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1023 | |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1024 | for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) |
| 1025 | ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i]; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1026 | |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1027 | ratesArray[rate1l] = targetPowerCck.tPow2x[0]; |
| 1028 | ratesArray[rate2s] = ratesArray[rate2l] = targetPowerCck.tPow2x[1]; |
| 1029 | ratesArray[rate5_5s] = ratesArray[rate5_5l] = targetPowerCck.tPow2x[2]; |
| 1030 | ratesArray[rate11s] = ratesArray[rate11l] = targetPowerCck.tPow2x[3]; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1031 | |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1032 | if (IS_CHAN_HT40(chan)) { |
| 1033 | for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) { |
| 1034 | ratesArray[rateHt40_0 + i] = |
| 1035 | targetPowerHt40.tPow2x[i]; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1036 | } |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1037 | ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0]; |
| 1038 | ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0]; |
| 1039 | ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0]; |
| 1040 | ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0]; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1041 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1042 | } |
| 1043 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 1044 | static void ath9k_hw_4k_set_txpower(struct ath_hw *ah, |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1045 | struct ath9k_channel *chan, |
| 1046 | u16 cfgCtl, |
| 1047 | u8 twiceAntennaReduction, |
| 1048 | u8 twiceMaxRegulatoryPower, |
| 1049 | u8 powerLimit) |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1050 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1051 | struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1052 | struct modal_eep_4k_header *pModal = &pEepData->modalHeader; |
| 1053 | int16_t ratesArray[Ar5416RateSize]; |
| 1054 | int16_t txPowerIndexOffset = 0; |
| 1055 | u8 ht40PowerIncForPdadc = 2; |
| 1056 | int i; |
| 1057 | |
| 1058 | memset(ratesArray, 0, sizeof(ratesArray)); |
| 1059 | |
| 1060 | if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >= |
| 1061 | AR5416_EEP_MINOR_VER_2) { |
| 1062 | ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc; |
| 1063 | } |
| 1064 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 1065 | ath9k_hw_set_4k_power_per_rate_table(ah, chan, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1066 | &ratesArray[0], cfgCtl, |
| 1067 | twiceAntennaReduction, |
| 1068 | twiceMaxRegulatoryPower, |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 1069 | powerLimit); |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1070 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 1071 | ath9k_hw_set_4k_power_cal_table(ah, chan, &txPowerIndexOffset); |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1072 | |
| 1073 | for (i = 0; i < ARRAY_SIZE(ratesArray); i++) { |
| 1074 | ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]); |
| 1075 | if (ratesArray[i] > AR5416_MAX_RATE_POWER) |
| 1076 | ratesArray[i] = AR5416_MAX_RATE_POWER; |
| 1077 | } |
| 1078 | |
| 1079 | if (AR_SREV_9280_10_OR_LATER(ah)) { |
| 1080 | for (i = 0; i < Ar5416RateSize; i++) |
| 1081 | ratesArray[i] -= AR5416_PWR_TABLE_OFFSET * 2; |
| 1082 | } |
| 1083 | |
| 1084 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE1, |
| 1085 | ATH9K_POW_SM(ratesArray[rate18mb], 24) |
| 1086 | | ATH9K_POW_SM(ratesArray[rate12mb], 16) |
| 1087 | | ATH9K_POW_SM(ratesArray[rate9mb], 8) |
| 1088 | | ATH9K_POW_SM(ratesArray[rate6mb], 0)); |
| 1089 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE2, |
| 1090 | ATH9K_POW_SM(ratesArray[rate54mb], 24) |
| 1091 | | ATH9K_POW_SM(ratesArray[rate48mb], 16) |
| 1092 | | ATH9K_POW_SM(ratesArray[rate36mb], 8) |
| 1093 | | ATH9K_POW_SM(ratesArray[rate24mb], 0)); |
| 1094 | |
| 1095 | if (IS_CHAN_2GHZ(chan)) { |
| 1096 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE3, |
| 1097 | ATH9K_POW_SM(ratesArray[rate2s], 24) |
| 1098 | | ATH9K_POW_SM(ratesArray[rate2l], 16) |
| 1099 | | ATH9K_POW_SM(ratesArray[rateXr], 8) |
| 1100 | | ATH9K_POW_SM(ratesArray[rate1l], 0)); |
| 1101 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE4, |
| 1102 | ATH9K_POW_SM(ratesArray[rate11s], 24) |
| 1103 | | ATH9K_POW_SM(ratesArray[rate11l], 16) |
| 1104 | | ATH9K_POW_SM(ratesArray[rate5_5s], 8) |
| 1105 | | ATH9K_POW_SM(ratesArray[rate5_5l], 0)); |
| 1106 | } |
| 1107 | |
| 1108 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE5, |
| 1109 | ATH9K_POW_SM(ratesArray[rateHt20_3], 24) |
| 1110 | | ATH9K_POW_SM(ratesArray[rateHt20_2], 16) |
| 1111 | | ATH9K_POW_SM(ratesArray[rateHt20_1], 8) |
| 1112 | | ATH9K_POW_SM(ratesArray[rateHt20_0], 0)); |
| 1113 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE6, |
| 1114 | ATH9K_POW_SM(ratesArray[rateHt20_7], 24) |
| 1115 | | ATH9K_POW_SM(ratesArray[rateHt20_6], 16) |
| 1116 | | ATH9K_POW_SM(ratesArray[rateHt20_5], 8) |
| 1117 | | ATH9K_POW_SM(ratesArray[rateHt20_4], 0)); |
| 1118 | |
| 1119 | if (IS_CHAN_HT40(chan)) { |
| 1120 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE7, |
| 1121 | ATH9K_POW_SM(ratesArray[rateHt40_3] + |
| 1122 | ht40PowerIncForPdadc, 24) |
| 1123 | | ATH9K_POW_SM(ratesArray[rateHt40_2] + |
| 1124 | ht40PowerIncForPdadc, 16) |
| 1125 | | ATH9K_POW_SM(ratesArray[rateHt40_1] + |
| 1126 | ht40PowerIncForPdadc, 8) |
| 1127 | | ATH9K_POW_SM(ratesArray[rateHt40_0] + |
| 1128 | ht40PowerIncForPdadc, 0)); |
| 1129 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE8, |
| 1130 | ATH9K_POW_SM(ratesArray[rateHt40_7] + |
| 1131 | ht40PowerIncForPdadc, 24) |
| 1132 | | ATH9K_POW_SM(ratesArray[rateHt40_6] + |
| 1133 | ht40PowerIncForPdadc, 16) |
| 1134 | | ATH9K_POW_SM(ratesArray[rateHt40_5] + |
| 1135 | ht40PowerIncForPdadc, 8) |
| 1136 | | ATH9K_POW_SM(ratesArray[rateHt40_4] + |
| 1137 | ht40PowerIncForPdadc, 0)); |
| 1138 | |
| 1139 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE9, |
| 1140 | ATH9K_POW_SM(ratesArray[rateExtOfdm], 24) |
| 1141 | | ATH9K_POW_SM(ratesArray[rateExtCck], 16) |
| 1142 | | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8) |
| 1143 | | ATH9K_POW_SM(ratesArray[rateDupCck], 0)); |
| 1144 | } |
| 1145 | |
| 1146 | i = rate6mb; |
| 1147 | |
| 1148 | if (IS_CHAN_HT40(chan)) |
| 1149 | i = rateHt40_0; |
| 1150 | else if (IS_CHAN_HT20(chan)) |
| 1151 | i = rateHt20_0; |
| 1152 | |
| 1153 | if (AR_SREV_9280_10_OR_LATER(ah)) |
Sujith | d6bad49 | 2009-02-09 13:27:08 +0530 | [diff] [blame] | 1154 | ah->regulatory.max_power_level = |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1155 | ratesArray[i] + AR5416_PWR_TABLE_OFFSET * 2; |
| 1156 | else |
Sujith | d6bad49 | 2009-02-09 13:27:08 +0530 | [diff] [blame] | 1157 | ah->regulatory.max_power_level = ratesArray[i]; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1158 | |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1159 | } |
| 1160 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1161 | static void ath9k_hw_4k_set_addac(struct ath_hw *ah, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1162 | struct ath9k_channel *chan) |
| 1163 | { |
| 1164 | struct modal_eep_4k_header *pModal; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1165 | struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1166 | u8 biaslevel; |
| 1167 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 1168 | if (ah->hw_version.macVersion != AR_SREV_VERSION_9160) |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1169 | return; |
| 1170 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1171 | if (ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_MINOR_VER_7) |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1172 | return; |
| 1173 | |
| 1174 | pModal = &eep->modalHeader; |
| 1175 | |
| 1176 | if (pModal->xpaBiasLvl != 0xff) { |
| 1177 | biaslevel = pModal->xpaBiasLvl; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1178 | INI_RA(&ah->iniAddac, 7, 1) = |
| 1179 | (INI_RA(&ah->iniAddac, 7, 1) & (~0x18)) | biaslevel << 3; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1180 | } |
| 1181 | } |
| 1182 | |
Sujith | a83615d | 2009-03-13 08:56:04 +0530 | [diff] [blame] | 1183 | static void ath9k_hw_4k_set_gain(struct ath_hw *ah, |
| 1184 | struct modal_eep_4k_header *pModal, |
| 1185 | struct ar5416_eeprom_4k *eep, |
| 1186 | u8 txRxAttenLocal, int regChainOffset) |
| 1187 | { |
| 1188 | REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset, |
| 1189 | pModal->antCtrlChain[0]); |
| 1190 | |
| 1191 | REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset, |
| 1192 | (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset) & |
| 1193 | ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF | |
| 1194 | AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) | |
| 1195 | SM(pModal->iqCalICh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) | |
| 1196 | SM(pModal->iqCalQCh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF)); |
| 1197 | |
| 1198 | if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >= |
| 1199 | AR5416_EEP_MINOR_VER_3) { |
| 1200 | txRxAttenLocal = pModal->txRxAttenCh[0]; |
| 1201 | |
| 1202 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset, |
| 1203 | AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN, pModal->bswMargin[0]); |
| 1204 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset, |
| 1205 | AR_PHY_GAIN_2GHZ_XATTEN1_DB, pModal->bswAtten[0]); |
| 1206 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset, |
| 1207 | AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN, |
| 1208 | pModal->xatten2Margin[0]); |
| 1209 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset, |
| 1210 | AR_PHY_GAIN_2GHZ_XATTEN2_DB, pModal->xatten2Db[0]); |
Senthil Balasubramanian | dd8b15b | 2009-07-14 20:17:08 -0400 | [diff] [blame] | 1211 | |
| 1212 | /* Set the block 1 value to block 0 value */ |
| 1213 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000, |
| 1214 | AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN, |
| 1215 | pModal->bswMargin[0]); |
| 1216 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000, |
| 1217 | AR_PHY_GAIN_2GHZ_XATTEN1_DB, pModal->bswAtten[0]); |
| 1218 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000, |
| 1219 | AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN, |
| 1220 | pModal->xatten2Margin[0]); |
| 1221 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000, |
| 1222 | AR_PHY_GAIN_2GHZ_XATTEN2_DB, |
| 1223 | pModal->xatten2Db[0]); |
Sujith | a83615d | 2009-03-13 08:56:04 +0530 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset, |
| 1227 | AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal); |
| 1228 | REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset, |
| 1229 | AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[0]); |
| 1230 | |
Senthil Balasubramanian | dd8b15b | 2009-07-14 20:17:08 -0400 | [diff] [blame] | 1231 | REG_RMW_FIELD(ah, AR_PHY_RXGAIN + 0x1000, |
| 1232 | AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal); |
| 1233 | REG_RMW_FIELD(ah, AR_PHY_RXGAIN + 0x1000, |
| 1234 | AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[0]); |
| 1235 | |
Sujith | a83615d | 2009-03-13 08:56:04 +0530 | [diff] [blame] | 1236 | if (AR_SREV_9285_11(ah)) |
| 1237 | REG_WRITE(ah, AR9285_AN_TOP4, (AR9285_AN_TOP4_DEFAULT | 0x14)); |
| 1238 | } |
| 1239 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame^] | 1240 | /* |
| 1241 | * Read EEPROM header info and program the device for correct operation |
| 1242 | * given the channel value. |
| 1243 | */ |
Sujith | d650915 | 2009-03-13 08:56:05 +0530 | [diff] [blame] | 1244 | static void ath9k_hw_4k_set_board_values(struct ath_hw *ah, |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1245 | struct ath9k_channel *chan) |
| 1246 | { |
| 1247 | struct modal_eep_4k_header *pModal; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1248 | struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1249 | u8 txRxAttenLocal; |
| 1250 | u8 ob[5], db1[5], db2[5]; |
| 1251 | u8 ant_div_control1, ant_div_control2; |
| 1252 | u32 regVal; |
| 1253 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1254 | pModal = &eep->modalHeader; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1255 | txRxAttenLocal = 23; |
| 1256 | |
| 1257 | REG_WRITE(ah, AR_PHY_SWITCH_COM, |
| 1258 | ah->eep_ops->get_eeprom_antenna_cfg(ah, chan)); |
| 1259 | |
Sujith | a83615d | 2009-03-13 08:56:04 +0530 | [diff] [blame] | 1260 | /* Single chain for 4K EEPROM*/ |
| 1261 | ath9k_hw_4k_set_gain(ah, pModal, eep, txRxAttenLocal, 0); |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1262 | |
| 1263 | /* Initialize Ant Diversity settings from EEPROM */ |
Senthil Balasubramanian | dd8b15b | 2009-07-14 20:17:08 -0400 | [diff] [blame] | 1264 | if (pModal->version >= 3) { |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1265 | ant_div_control1 = ((pModal->ob_234 >> 12) & 0xf); |
| 1266 | ant_div_control2 = ((pModal->db1_234 >> 12) & 0xf); |
| 1267 | regVal = REG_READ(ah, 0x99ac); |
| 1268 | regVal &= (~(0x7f000000)); |
| 1269 | regVal |= ((ant_div_control1 & 0x1) << 24); |
| 1270 | regVal |= (((ant_div_control1 >> 1) & 0x1) << 29); |
| 1271 | regVal |= (((ant_div_control1 >> 2) & 0x1) << 30); |
| 1272 | regVal |= ((ant_div_control2 & 0x3) << 25); |
| 1273 | regVal |= (((ant_div_control2 >> 2) & 0x3) << 27); |
| 1274 | REG_WRITE(ah, 0x99ac, regVal); |
| 1275 | regVal = REG_READ(ah, 0x99ac); |
| 1276 | regVal = REG_READ(ah, 0xa208); |
| 1277 | regVal &= (~(0x1 << 13)); |
| 1278 | regVal |= (((ant_div_control1 >> 3) & 0x1) << 13); |
| 1279 | REG_WRITE(ah, 0xa208, regVal); |
| 1280 | regVal = REG_READ(ah, 0xa208); |
| 1281 | } |
| 1282 | |
| 1283 | if (pModal->version >= 2) { |
| 1284 | ob[0] = (pModal->ob_01 & 0xf); |
| 1285 | ob[1] = (pModal->ob_01 >> 4) & 0xf; |
| 1286 | ob[2] = (pModal->ob_234 & 0xf); |
| 1287 | ob[3] = ((pModal->ob_234 >> 4) & 0xf); |
| 1288 | ob[4] = ((pModal->ob_234 >> 8) & 0xf); |
| 1289 | |
| 1290 | db1[0] = (pModal->db1_01 & 0xf); |
| 1291 | db1[1] = ((pModal->db1_01 >> 4) & 0xf); |
| 1292 | db1[2] = (pModal->db1_234 & 0xf); |
| 1293 | db1[3] = ((pModal->db1_234 >> 4) & 0xf); |
| 1294 | db1[4] = ((pModal->db1_234 >> 8) & 0xf); |
| 1295 | |
| 1296 | db2[0] = (pModal->db2_01 & 0xf); |
| 1297 | db2[1] = ((pModal->db2_01 >> 4) & 0xf); |
| 1298 | db2[2] = (pModal->db2_234 & 0xf); |
| 1299 | db2[3] = ((pModal->db2_234 >> 4) & 0xf); |
| 1300 | db2[4] = ((pModal->db2_234 >> 8) & 0xf); |
| 1301 | |
| 1302 | } else if (pModal->version == 1) { |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1303 | ob[0] = (pModal->ob_01 & 0xf); |
| 1304 | ob[1] = ob[2] = ob[3] = ob[4] = (pModal->ob_01 >> 4) & 0xf; |
| 1305 | db1[0] = (pModal->db1_01 & 0xf); |
| 1306 | db1[1] = db1[2] = db1[3] = |
| 1307 | db1[4] = ((pModal->db1_01 >> 4) & 0xf); |
| 1308 | db2[0] = (pModal->db2_01 & 0xf); |
| 1309 | db2[1] = db2[2] = db2[3] = |
| 1310 | db2[4] = ((pModal->db2_01 >> 4) & 0xf); |
| 1311 | } else { |
| 1312 | int i; |
| 1313 | for (i = 0; i < 5; i++) { |
| 1314 | ob[i] = pModal->ob_01; |
| 1315 | db1[i] = pModal->db1_01; |
| 1316 | db2[i] = pModal->db1_01; |
| 1317 | } |
| 1318 | } |
| 1319 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame^] | 1320 | if (AR_SREV_9271(ah)) { |
| 1321 | ath9k_hw_analog_shift_rmw(ah, |
| 1322 | AR9285_AN_RF2G3, |
| 1323 | AR9271_AN_RF2G3_OB_cck, |
| 1324 | AR9271_AN_RF2G3_OB_cck_S, |
| 1325 | ob[0]); |
| 1326 | ath9k_hw_analog_shift_rmw(ah, |
| 1327 | AR9285_AN_RF2G3, |
| 1328 | AR9271_AN_RF2G3_OB_psk, |
| 1329 | AR9271_AN_RF2G3_OB_psk_S, |
| 1330 | ob[1]); |
| 1331 | ath9k_hw_analog_shift_rmw(ah, |
| 1332 | AR9285_AN_RF2G3, |
| 1333 | AR9271_AN_RF2G3_OB_qam, |
| 1334 | AR9271_AN_RF2G3_OB_qam_S, |
| 1335 | ob[2]); |
| 1336 | ath9k_hw_analog_shift_rmw(ah, |
| 1337 | AR9285_AN_RF2G3, |
| 1338 | AR9271_AN_RF2G3_DB_1, |
| 1339 | AR9271_AN_RF2G3_DB_1_S, |
| 1340 | db1[0]); |
| 1341 | ath9k_hw_analog_shift_rmw(ah, |
| 1342 | AR9285_AN_RF2G4, |
| 1343 | AR9271_AN_RF2G4_DB_2, |
| 1344 | AR9271_AN_RF2G4_DB_2_S, |
| 1345 | db2[0]); |
| 1346 | } else { |
| 1347 | ath9k_hw_analog_shift_rmw(ah, |
| 1348 | AR9285_AN_RF2G3, |
| 1349 | AR9285_AN_RF2G3_OB_0, |
| 1350 | AR9285_AN_RF2G3_OB_0_S, |
| 1351 | ob[0]); |
| 1352 | ath9k_hw_analog_shift_rmw(ah, |
| 1353 | AR9285_AN_RF2G3, |
| 1354 | AR9285_AN_RF2G3_OB_1, |
| 1355 | AR9285_AN_RF2G3_OB_1_S, |
| 1356 | ob[1]); |
| 1357 | ath9k_hw_analog_shift_rmw(ah, |
| 1358 | AR9285_AN_RF2G3, |
| 1359 | AR9285_AN_RF2G3_OB_2, |
| 1360 | AR9285_AN_RF2G3_OB_2_S, |
| 1361 | ob[2]); |
| 1362 | ath9k_hw_analog_shift_rmw(ah, |
| 1363 | AR9285_AN_RF2G3, |
| 1364 | AR9285_AN_RF2G3_OB_3, |
| 1365 | AR9285_AN_RF2G3_OB_3_S, |
| 1366 | ob[3]); |
| 1367 | ath9k_hw_analog_shift_rmw(ah, |
| 1368 | AR9285_AN_RF2G3, |
| 1369 | AR9285_AN_RF2G3_OB_4, |
| 1370 | AR9285_AN_RF2G3_OB_4_S, |
| 1371 | ob[4]); |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1372 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame^] | 1373 | ath9k_hw_analog_shift_rmw(ah, |
| 1374 | AR9285_AN_RF2G3, |
| 1375 | AR9285_AN_RF2G3_DB1_0, |
| 1376 | AR9285_AN_RF2G3_DB1_0_S, |
| 1377 | db1[0]); |
| 1378 | ath9k_hw_analog_shift_rmw(ah, |
| 1379 | AR9285_AN_RF2G3, |
| 1380 | AR9285_AN_RF2G3_DB1_1, |
| 1381 | AR9285_AN_RF2G3_DB1_1_S, |
| 1382 | db1[1]); |
| 1383 | ath9k_hw_analog_shift_rmw(ah, |
| 1384 | AR9285_AN_RF2G3, |
| 1385 | AR9285_AN_RF2G3_DB1_2, |
| 1386 | AR9285_AN_RF2G3_DB1_2_S, |
| 1387 | db1[2]); |
| 1388 | ath9k_hw_analog_shift_rmw(ah, |
| 1389 | AR9285_AN_RF2G4, |
| 1390 | AR9285_AN_RF2G4_DB1_3, |
| 1391 | AR9285_AN_RF2G4_DB1_3_S, |
| 1392 | db1[3]); |
| 1393 | ath9k_hw_analog_shift_rmw(ah, |
| 1394 | AR9285_AN_RF2G4, |
| 1395 | AR9285_AN_RF2G4_DB1_4, |
| 1396 | AR9285_AN_RF2G4_DB1_4_S, db1[4]); |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1397 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame^] | 1398 | ath9k_hw_analog_shift_rmw(ah, |
| 1399 | AR9285_AN_RF2G4, |
| 1400 | AR9285_AN_RF2G4_DB2_0, |
| 1401 | AR9285_AN_RF2G4_DB2_0_S, |
| 1402 | db2[0]); |
| 1403 | ath9k_hw_analog_shift_rmw(ah, |
| 1404 | AR9285_AN_RF2G4, |
| 1405 | AR9285_AN_RF2G4_DB2_1, |
| 1406 | AR9285_AN_RF2G4_DB2_1_S, |
| 1407 | db2[1]); |
| 1408 | ath9k_hw_analog_shift_rmw(ah, |
| 1409 | AR9285_AN_RF2G4, |
| 1410 | AR9285_AN_RF2G4_DB2_2, |
| 1411 | AR9285_AN_RF2G4_DB2_2_S, |
| 1412 | db2[2]); |
| 1413 | ath9k_hw_analog_shift_rmw(ah, |
| 1414 | AR9285_AN_RF2G4, |
| 1415 | AR9285_AN_RF2G4_DB2_3, |
| 1416 | AR9285_AN_RF2G4_DB2_3_S, |
| 1417 | db2[3]); |
| 1418 | ath9k_hw_analog_shift_rmw(ah, |
| 1419 | AR9285_AN_RF2G4, |
| 1420 | AR9285_AN_RF2G4_DB2_4, |
| 1421 | AR9285_AN_RF2G4_DB2_4_S, |
| 1422 | db2[4]); |
| 1423 | } |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1424 | |
| 1425 | |
| 1426 | if (AR_SREV_9285_11(ah)) |
| 1427 | REG_WRITE(ah, AR9285_AN_TOP4, AR9285_AN_TOP4_DEFAULT); |
| 1428 | |
| 1429 | REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH, |
| 1430 | pModal->switchSettling); |
| 1431 | REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC, |
| 1432 | pModal->adcDesiredSize); |
| 1433 | |
| 1434 | REG_WRITE(ah, AR_PHY_RF_CTL4, |
| 1435 | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF) | |
| 1436 | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF) | |
| 1437 | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON) | |
| 1438 | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON)); |
| 1439 | |
| 1440 | REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON, |
| 1441 | pModal->txEndToRxOn); |
| 1442 | REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62, |
| 1443 | pModal->thresh62); |
| 1444 | REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0, AR_PHY_EXT_CCA0_THRESH62, |
| 1445 | pModal->thresh62); |
| 1446 | |
| 1447 | if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >= |
| 1448 | AR5416_EEP_MINOR_VER_2) { |
| 1449 | REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_DATA_START, |
| 1450 | pModal->txFrameToDataStart); |
| 1451 | REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON, |
| 1452 | pModal->txFrameToPaOn); |
| 1453 | } |
| 1454 | |
| 1455 | if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >= |
| 1456 | AR5416_EEP_MINOR_VER_3) { |
| 1457 | if (IS_CHAN_HT40(chan)) |
| 1458 | REG_RMW_FIELD(ah, AR_PHY_SETTLING, |
| 1459 | AR_PHY_SETTLING_SWITCH, |
| 1460 | pModal->swSettleHt40); |
| 1461 | } |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | static u16 ath9k_hw_4k_get_eeprom_antenna_cfg(struct ath_hw *ah, |
| 1465 | struct ath9k_channel *chan) |
| 1466 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1467 | struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1468 | struct modal_eep_4k_header *pModal = &eep->modalHeader; |
| 1469 | |
| 1470 | return pModal->antCtrlCommon & 0xFFFF; |
| 1471 | } |
| 1472 | |
| 1473 | static u8 ath9k_hw_4k_get_num_ant_config(struct ath_hw *ah, |
| 1474 | enum ieee80211_band freq_band) |
| 1475 | { |
| 1476 | return 1; |
| 1477 | } |
| 1478 | |
Hannes Eder | 93f726a | 2009-02-14 11:49:48 +0000 | [diff] [blame] | 1479 | static u16 ath9k_hw_4k_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz) |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1480 | { |
| 1481 | #define EEP_MAP4K_SPURCHAN \ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1482 | (ah->eeprom.map4k.modalHeader.spurChans[i].spurChan) |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1483 | |
| 1484 | u16 spur_val = AR_NO_SPUR; |
| 1485 | |
| 1486 | DPRINTF(ah->ah_sc, ATH_DBG_ANI, |
| 1487 | "Getting spur idx %d is2Ghz. %d val %x\n", |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1488 | i, is2GHz, ah->config.spurchans[i][is2GHz]); |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1489 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1490 | switch (ah->config.spurmode) { |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1491 | case SPUR_DISABLE: |
| 1492 | break; |
| 1493 | case SPUR_ENABLE_IOCTL: |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1494 | spur_val = ah->config.spurchans[i][is2GHz]; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1495 | DPRINTF(ah->ah_sc, ATH_DBG_ANI, |
| 1496 | "Getting spur val from new loc. %d\n", spur_val); |
| 1497 | break; |
| 1498 | case SPUR_ENABLE_EEPROM: |
| 1499 | spur_val = EEP_MAP4K_SPURCHAN; |
| 1500 | break; |
| 1501 | } |
| 1502 | |
| 1503 | return spur_val; |
| 1504 | |
| 1505 | #undef EEP_MAP4K_SPURCHAN |
| 1506 | } |
| 1507 | |
Hannes Eder | 93f726a | 2009-02-14 11:49:48 +0000 | [diff] [blame] | 1508 | static struct eeprom_ops eep_4k_ops = { |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1509 | .check_eeprom = ath9k_hw_4k_check_eeprom, |
| 1510 | .get_eeprom = ath9k_hw_4k_get_eeprom, |
| 1511 | .fill_eeprom = ath9k_hw_4k_fill_eeprom, |
| 1512 | .get_eeprom_ver = ath9k_hw_4k_get_eeprom_ver, |
| 1513 | .get_eeprom_rev = ath9k_hw_4k_get_eeprom_rev, |
| 1514 | .get_num_ant_config = ath9k_hw_4k_get_num_ant_config, |
| 1515 | .get_eeprom_antenna_cfg = ath9k_hw_4k_get_eeprom_antenna_cfg, |
| 1516 | .set_board_values = ath9k_hw_4k_set_board_values, |
| 1517 | .set_addac = ath9k_hw_4k_set_addac, |
| 1518 | .set_txpower = ath9k_hw_4k_set_txpower, |
| 1519 | .get_spur_channel = ath9k_hw_4k_get_spur_channel |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1520 | }; |
| 1521 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1522 | /************************************************/ |
| 1523 | /* EEPROM Operations for non-4K (Default) cards */ |
| 1524 | /************************************************/ |
| 1525 | |
| 1526 | static int ath9k_hw_def_get_eeprom_ver(struct ath_hw *ah) |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1527 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1528 | return ((ah->eeprom.def.baseEepHeader.version >> 12) & 0xF); |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | static int ath9k_hw_def_get_eeprom_rev(struct ath_hw *ah) |
| 1532 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1533 | return ((ah->eeprom.def.baseEepHeader.version) & 0xFFF); |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | static bool ath9k_hw_def_fill_eeprom(struct ath_hw *ah) |
| 1537 | { |
| 1538 | #define SIZE_EEPROM_DEF (sizeof(struct ar5416_eeprom_def) / sizeof(u16)) |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 1539 | u16 *eep_data = (u16 *)&ah->eeprom.def; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1540 | int addr, ar5416_eep_start_loc = 0x100; |
| 1541 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1542 | for (addr = 0; addr < SIZE_EEPROM_DEF; addr++) { |
| 1543 | if (!ath9k_hw_nvram_read(ah, addr + ar5416_eep_start_loc, |
| 1544 | eep_data)) { |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 1545 | DPRINTF(ah->ah_sc, ATH_DBG_FATAL, |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1546 | "Unable to read eeprom region\n"); |
| 1547 | return false; |
| 1548 | } |
| 1549 | eep_data++; |
| 1550 | } |
| 1551 | return true; |
| 1552 | #undef SIZE_EEPROM_DEF |
| 1553 | } |
| 1554 | |
| 1555 | static int ath9k_hw_def_check_eeprom(struct ath_hw *ah) |
| 1556 | { |
| 1557 | struct ar5416_eeprom_def *eep = |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1558 | (struct ar5416_eeprom_def *) &ah->eeprom.def; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1559 | u16 *eepdata, temp, magic, magic2; |
| 1560 | u32 sum = 0, el; |
| 1561 | bool need_swap = false; |
| 1562 | int i, addr, size; |
| 1563 | |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 1564 | if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET, &magic)) { |
| 1565 | DPRINTF(ah->ah_sc, ATH_DBG_FATAL, "Reading Magic # failed\n"); |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1566 | return false; |
| 1567 | } |
| 1568 | |
| 1569 | if (!ath9k_hw_use_flash(ah)) { |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1570 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 1571 | "Read Magic = 0x%04X\n", magic); |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1572 | |
| 1573 | if (magic != AR5416_EEPROM_MAGIC) { |
| 1574 | magic2 = swab16(magic); |
| 1575 | |
| 1576 | if (magic2 == AR5416_EEPROM_MAGIC) { |
| 1577 | size = sizeof(struct ar5416_eeprom_def); |
| 1578 | need_swap = true; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1579 | eepdata = (u16 *) (&ah->eeprom); |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1580 | |
| 1581 | for (addr = 0; addr < size / sizeof(u16); addr++) { |
| 1582 | temp = swab16(*eepdata); |
| 1583 | *eepdata = temp; |
| 1584 | eepdata++; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1585 | } |
| 1586 | } else { |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 1587 | DPRINTF(ah->ah_sc, ATH_DBG_FATAL, |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1588 | "Invalid EEPROM Magic. " |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 1589 | "Endianness mismatch.\n"); |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1590 | return -EINVAL; |
| 1591 | } |
| 1592 | } |
| 1593 | } |
| 1594 | |
| 1595 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "need_swap = %s.\n", |
| 1596 | need_swap ? "True" : "False"); |
| 1597 | |
| 1598 | if (need_swap) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1599 | el = swab16(ah->eeprom.def.baseEepHeader.length); |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1600 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1601 | el = ah->eeprom.def.baseEepHeader.length; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1602 | |
| 1603 | if (el > sizeof(struct ar5416_eeprom_def)) |
| 1604 | el = sizeof(struct ar5416_eeprom_def) / sizeof(u16); |
| 1605 | else |
| 1606 | el = el / sizeof(u16); |
| 1607 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1608 | eepdata = (u16 *)(&ah->eeprom); |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1609 | |
| 1610 | for (i = 0; i < el; i++) |
| 1611 | sum ^= *eepdata++; |
| 1612 | |
| 1613 | if (need_swap) { |
| 1614 | u32 integer, j; |
| 1615 | u16 word; |
| 1616 | |
| 1617 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 1618 | "EEPROM Endianness is not native.. Changing.\n"); |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1619 | |
| 1620 | word = swab16(eep->baseEepHeader.length); |
| 1621 | eep->baseEepHeader.length = word; |
| 1622 | |
| 1623 | word = swab16(eep->baseEepHeader.checksum); |
| 1624 | eep->baseEepHeader.checksum = word; |
| 1625 | |
| 1626 | word = swab16(eep->baseEepHeader.version); |
| 1627 | eep->baseEepHeader.version = word; |
| 1628 | |
| 1629 | word = swab16(eep->baseEepHeader.regDmn[0]); |
| 1630 | eep->baseEepHeader.regDmn[0] = word; |
| 1631 | |
| 1632 | word = swab16(eep->baseEepHeader.regDmn[1]); |
| 1633 | eep->baseEepHeader.regDmn[1] = word; |
| 1634 | |
| 1635 | word = swab16(eep->baseEepHeader.rfSilent); |
| 1636 | eep->baseEepHeader.rfSilent = word; |
| 1637 | |
| 1638 | word = swab16(eep->baseEepHeader.blueToothOptions); |
| 1639 | eep->baseEepHeader.blueToothOptions = word; |
| 1640 | |
| 1641 | word = swab16(eep->baseEepHeader.deviceCap); |
| 1642 | eep->baseEepHeader.deviceCap = word; |
| 1643 | |
| 1644 | for (j = 0; j < ARRAY_SIZE(eep->modalHeader); j++) { |
| 1645 | struct modal_eep_header *pModal = |
| 1646 | &eep->modalHeader[j]; |
| 1647 | integer = swab32(pModal->antCtrlCommon); |
| 1648 | pModal->antCtrlCommon = integer; |
| 1649 | |
| 1650 | for (i = 0; i < AR5416_MAX_CHAINS; i++) { |
| 1651 | integer = swab32(pModal->antCtrlChain[i]); |
| 1652 | pModal->antCtrlChain[i] = integer; |
| 1653 | } |
| 1654 | |
| 1655 | for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) { |
| 1656 | word = swab16(pModal->spurChans[i].spurChan); |
| 1657 | pModal->spurChans[i].spurChan = word; |
| 1658 | } |
| 1659 | } |
| 1660 | } |
| 1661 | |
| 1662 | if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR5416_EEP_VER || |
| 1663 | ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) { |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 1664 | DPRINTF(ah->ah_sc, ATH_DBG_FATAL, |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1665 | "Bad EEPROM checksum 0x%x or revision 0x%04x\n", |
| 1666 | sum, ah->eep_ops->get_eeprom_ver(ah)); |
| 1667 | return -EINVAL; |
| 1668 | } |
| 1669 | |
| 1670 | return 0; |
| 1671 | } |
| 1672 | |
| 1673 | static u32 ath9k_hw_def_get_eeprom(struct ath_hw *ah, |
| 1674 | enum eeprom_param param) |
| 1675 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1676 | struct ar5416_eeprom_def *eep = &ah->eeprom.def; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1677 | struct modal_eep_header *pModal = eep->modalHeader; |
| 1678 | struct base_eep_header *pBase = &eep->baseEepHeader; |
| 1679 | |
| 1680 | switch (param) { |
| 1681 | case EEP_NFTHRESH_5: |
| 1682 | return pModal[0].noiseFloorThreshCh[0]; |
| 1683 | case EEP_NFTHRESH_2: |
| 1684 | return pModal[1].noiseFloorThreshCh[0]; |
| 1685 | case AR_EEPROM_MAC(0): |
| 1686 | return pBase->macAddr[0] << 8 | pBase->macAddr[1]; |
| 1687 | case AR_EEPROM_MAC(1): |
| 1688 | return pBase->macAddr[2] << 8 | pBase->macAddr[3]; |
| 1689 | case AR_EEPROM_MAC(2): |
| 1690 | return pBase->macAddr[4] << 8 | pBase->macAddr[5]; |
| 1691 | case EEP_REG_0: |
| 1692 | return pBase->regDmn[0]; |
| 1693 | case EEP_REG_1: |
| 1694 | return pBase->regDmn[1]; |
| 1695 | case EEP_OP_CAP: |
| 1696 | return pBase->deviceCap; |
| 1697 | case EEP_OP_MODE: |
| 1698 | return pBase->opCapFlags; |
| 1699 | case EEP_RF_SILENT: |
| 1700 | return pBase->rfSilent; |
| 1701 | case EEP_OB_5: |
| 1702 | return pModal[0].ob; |
| 1703 | case EEP_DB_5: |
| 1704 | return pModal[0].db; |
| 1705 | case EEP_OB_2: |
| 1706 | return pModal[1].ob; |
| 1707 | case EEP_DB_2: |
| 1708 | return pModal[1].db; |
| 1709 | case EEP_MINOR_REV: |
| 1710 | return AR5416_VER_MASK; |
| 1711 | case EEP_TX_MASK: |
| 1712 | return pBase->txMask; |
| 1713 | case EEP_RX_MASK: |
| 1714 | return pBase->rxMask; |
| 1715 | case EEP_RXGAIN_TYPE: |
| 1716 | return pBase->rxGainType; |
| 1717 | case EEP_TXGAIN_TYPE: |
| 1718 | return pBase->txGainType; |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 1719 | case EEP_OL_PWRCTRL: |
| 1720 | if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19) |
| 1721 | return pBase->openLoopPwrCntl ? true : false; |
| 1722 | else |
| 1723 | return false; |
| 1724 | case EEP_RC_CHAIN_MASK: |
| 1725 | if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19) |
| 1726 | return pBase->rcChainMask; |
| 1727 | else |
| 1728 | return 0; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1729 | case EEP_DAC_HPWR_5G: |
| 1730 | if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20) |
| 1731 | return pBase->dacHiPwrMode_5G; |
| 1732 | else |
| 1733 | return 0; |
Sujith | 06d0f06 | 2009-02-12 10:06:45 +0530 | [diff] [blame] | 1734 | case EEP_FRAC_N_5G: |
| 1735 | if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_22) |
| 1736 | return pBase->frac_n_5g; |
| 1737 | else |
| 1738 | return 0; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1739 | default: |
| 1740 | return 0; |
| 1741 | } |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1742 | } |
| 1743 | |
Sujith | a83615d | 2009-03-13 08:56:04 +0530 | [diff] [blame] | 1744 | static void ath9k_hw_def_set_gain(struct ath_hw *ah, |
| 1745 | struct modal_eep_header *pModal, |
| 1746 | struct ar5416_eeprom_def *eep, |
| 1747 | u8 txRxAttenLocal, int regChainOffset, int i) |
| 1748 | { |
| 1749 | if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) { |
| 1750 | txRxAttenLocal = pModal->txRxAttenCh[i]; |
| 1751 | |
| 1752 | if (AR_SREV_9280_10_OR_LATER(ah)) { |
| 1753 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset, |
| 1754 | AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN, |
| 1755 | pModal->bswMargin[i]); |
| 1756 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset, |
| 1757 | AR_PHY_GAIN_2GHZ_XATTEN1_DB, |
| 1758 | pModal->bswAtten[i]); |
| 1759 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset, |
| 1760 | AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN, |
| 1761 | pModal->xatten2Margin[i]); |
| 1762 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset, |
| 1763 | AR_PHY_GAIN_2GHZ_XATTEN2_DB, |
| 1764 | pModal->xatten2Db[i]); |
| 1765 | } else { |
| 1766 | REG_WRITE(ah, AR_PHY_GAIN_2GHZ + regChainOffset, |
| 1767 | (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) & |
| 1768 | ~AR_PHY_GAIN_2GHZ_BSW_MARGIN) |
| 1769 | | SM(pModal-> bswMargin[i], |
| 1770 | AR_PHY_GAIN_2GHZ_BSW_MARGIN)); |
| 1771 | REG_WRITE(ah, AR_PHY_GAIN_2GHZ + regChainOffset, |
| 1772 | (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) & |
| 1773 | ~AR_PHY_GAIN_2GHZ_BSW_ATTEN) |
| 1774 | | SM(pModal->bswAtten[i], |
| 1775 | AR_PHY_GAIN_2GHZ_BSW_ATTEN)); |
| 1776 | } |
| 1777 | } |
| 1778 | |
| 1779 | if (AR_SREV_9280_10_OR_LATER(ah)) { |
| 1780 | REG_RMW_FIELD(ah, |
| 1781 | AR_PHY_RXGAIN + regChainOffset, |
| 1782 | AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal); |
| 1783 | REG_RMW_FIELD(ah, |
| 1784 | AR_PHY_RXGAIN + regChainOffset, |
| 1785 | AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[i]); |
| 1786 | } else { |
| 1787 | REG_WRITE(ah, |
| 1788 | AR_PHY_RXGAIN + regChainOffset, |
| 1789 | (REG_READ(ah, AR_PHY_RXGAIN + regChainOffset) & |
| 1790 | ~AR_PHY_RXGAIN_TXRX_ATTEN) |
| 1791 | | SM(txRxAttenLocal, AR_PHY_RXGAIN_TXRX_ATTEN)); |
| 1792 | REG_WRITE(ah, |
| 1793 | AR_PHY_GAIN_2GHZ + regChainOffset, |
| 1794 | (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) & |
| 1795 | ~AR_PHY_GAIN_2GHZ_RXTX_MARGIN) | |
| 1796 | SM(pModal->rxTxMarginCh[i], AR_PHY_GAIN_2GHZ_RXTX_MARGIN)); |
| 1797 | } |
| 1798 | } |
| 1799 | |
Sujith | d650915 | 2009-03-13 08:56:05 +0530 | [diff] [blame] | 1800 | static void ath9k_hw_def_set_board_values(struct ath_hw *ah, |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1801 | struct ath9k_channel *chan) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1802 | { |
| 1803 | struct modal_eep_header *pModal; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1804 | struct ar5416_eeprom_def *eep = &ah->eeprom.def; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1805 | int i, regChainOffset; |
| 1806 | u8 txRxAttenLocal; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1807 | |
| 1808 | pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1809 | txRxAttenLocal = IS_CHAN_2GHZ(chan) ? 23 : 44; |
| 1810 | |
Vasanthakumar Thiagarajan | 81b1e19 | 2009-01-23 14:40:37 +0530 | [diff] [blame] | 1811 | REG_WRITE(ah, AR_PHY_SWITCH_COM, |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1812 | ah->eep_ops->get_eeprom_antenna_cfg(ah, chan)); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1813 | |
| 1814 | for (i = 0; i < AR5416_MAX_CHAINS; i++) { |
| 1815 | if (AR_SREV_9280(ah)) { |
| 1816 | if (i >= 2) |
| 1817 | break; |
| 1818 | } |
| 1819 | |
Gabor Juhos | a8c96d3 | 2009-03-06 09:08:51 +0100 | [diff] [blame] | 1820 | if (AR_SREV_5416_20_OR_LATER(ah) && |
Sujith | a83615d | 2009-03-13 08:56:04 +0530 | [diff] [blame] | 1821 | (ah->rxchainmask == 5 || ah->txchainmask == 5) && (i != 0)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1822 | regChainOffset = (i == 1) ? 0x2000 : 0x1000; |
| 1823 | else |
| 1824 | regChainOffset = i * 0x1000; |
| 1825 | |
| 1826 | REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset, |
| 1827 | pModal->antCtrlChain[i]); |
| 1828 | |
| 1829 | REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset, |
Sujith | a83615d | 2009-03-13 08:56:04 +0530 | [diff] [blame] | 1830 | (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset) & |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1831 | ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF | |
| 1832 | AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) | |
| 1833 | SM(pModal->iqCalICh[i], |
| 1834 | AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) | |
| 1835 | SM(pModal->iqCalQCh[i], |
| 1836 | AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF)); |
| 1837 | |
Sujith | a83615d | 2009-03-13 08:56:04 +0530 | [diff] [blame] | 1838 | if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah)) |
| 1839 | ath9k_hw_def_set_gain(ah, pModal, eep, txRxAttenLocal, |
| 1840 | regChainOffset, i); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1841 | } |
| 1842 | |
| 1843 | if (AR_SREV_9280_10_OR_LATER(ah)) { |
| 1844 | if (IS_CHAN_2GHZ(chan)) { |
| 1845 | ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0, |
| 1846 | AR_AN_RF2G1_CH0_OB, |
| 1847 | AR_AN_RF2G1_CH0_OB_S, |
| 1848 | pModal->ob); |
| 1849 | ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0, |
| 1850 | AR_AN_RF2G1_CH0_DB, |
| 1851 | AR_AN_RF2G1_CH0_DB_S, |
| 1852 | pModal->db); |
| 1853 | ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1, |
| 1854 | AR_AN_RF2G1_CH1_OB, |
| 1855 | AR_AN_RF2G1_CH1_OB_S, |
| 1856 | pModal->ob_ch1); |
| 1857 | ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1, |
| 1858 | AR_AN_RF2G1_CH1_DB, |
| 1859 | AR_AN_RF2G1_CH1_DB_S, |
| 1860 | pModal->db_ch1); |
| 1861 | } else { |
| 1862 | ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0, |
| 1863 | AR_AN_RF5G1_CH0_OB5, |
| 1864 | AR_AN_RF5G1_CH0_OB5_S, |
| 1865 | pModal->ob); |
| 1866 | ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0, |
| 1867 | AR_AN_RF5G1_CH0_DB5, |
| 1868 | AR_AN_RF5G1_CH0_DB5_S, |
| 1869 | pModal->db); |
| 1870 | ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1, |
| 1871 | AR_AN_RF5G1_CH1_OB5, |
| 1872 | AR_AN_RF5G1_CH1_OB5_S, |
| 1873 | pModal->ob_ch1); |
| 1874 | ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1, |
| 1875 | AR_AN_RF5G1_CH1_DB5, |
| 1876 | AR_AN_RF5G1_CH1_DB5_S, |
| 1877 | pModal->db_ch1); |
| 1878 | } |
| 1879 | ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2, |
| 1880 | AR_AN_TOP2_XPABIAS_LVL, |
| 1881 | AR_AN_TOP2_XPABIAS_LVL_S, |
| 1882 | pModal->xpaBiasLvl); |
| 1883 | ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2, |
| 1884 | AR_AN_TOP2_LOCALBIAS, |
| 1885 | AR_AN_TOP2_LOCALBIAS_S, |
| 1886 | pModal->local_bias); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1887 | REG_RMW_FIELD(ah, AR_PHY_XPA_CFG, AR_PHY_FORCE_XPA_CFG, |
| 1888 | pModal->force_xpaon); |
| 1889 | } |
| 1890 | |
| 1891 | REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH, |
| 1892 | pModal->switchSettling); |
| 1893 | REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC, |
| 1894 | pModal->adcDesiredSize); |
| 1895 | |
| 1896 | if (!AR_SREV_9280_10_OR_LATER(ah)) |
| 1897 | REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, |
| 1898 | AR_PHY_DESIRED_SZ_PGA, |
| 1899 | pModal->pgaDesiredSize); |
| 1900 | |
| 1901 | REG_WRITE(ah, AR_PHY_RF_CTL4, |
| 1902 | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF) |
| 1903 | | SM(pModal->txEndToXpaOff, |
| 1904 | AR_PHY_RF_CTL4_TX_END_XPAB_OFF) |
| 1905 | | SM(pModal->txFrameToXpaOn, |
| 1906 | AR_PHY_RF_CTL4_FRAME_XPAA_ON) |
| 1907 | | SM(pModal->txFrameToXpaOn, |
| 1908 | AR_PHY_RF_CTL4_FRAME_XPAB_ON)); |
| 1909 | |
| 1910 | REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON, |
| 1911 | pModal->txEndToRxOn); |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 1912 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1913 | if (AR_SREV_9280_10_OR_LATER(ah)) { |
| 1914 | REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62, |
| 1915 | pModal->thresh62); |
| 1916 | REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0, |
| 1917 | AR_PHY_EXT_CCA0_THRESH62, |
| 1918 | pModal->thresh62); |
| 1919 | } else { |
| 1920 | REG_RMW_FIELD(ah, AR_PHY_CCA, AR_PHY_CCA_THRESH62, |
| 1921 | pModal->thresh62); |
| 1922 | REG_RMW_FIELD(ah, AR_PHY_EXT_CCA, |
| 1923 | AR_PHY_EXT_CCA_THRESH62, |
| 1924 | pModal->thresh62); |
| 1925 | } |
| 1926 | |
Senthil Balasubramanian | cb33c41 | 2008-12-24 18:03:58 +0530 | [diff] [blame] | 1927 | if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_2) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1928 | REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, |
| 1929 | AR_PHY_TX_END_DATA_START, |
| 1930 | pModal->txFrameToDataStart); |
| 1931 | REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON, |
| 1932 | pModal->txFrameToPaOn); |
| 1933 | } |
| 1934 | |
Senthil Balasubramanian | cb33c41 | 2008-12-24 18:03:58 +0530 | [diff] [blame] | 1935 | if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1936 | if (IS_CHAN_HT40(chan)) |
| 1937 | REG_RMW_FIELD(ah, AR_PHY_SETTLING, |
| 1938 | AR_PHY_SETTLING_SWITCH, |
| 1939 | pModal->swSettleHt40); |
| 1940 | } |
| 1941 | |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 1942 | if (AR_SREV_9280_20_OR_LATER(ah) && |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 1943 | AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19) |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 1944 | REG_RMW_FIELD(ah, AR_PHY_CCK_TX_CTRL, |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 1945 | AR_PHY_CCK_TX_CTRL_TX_DAC_SCALE_CCK, |
| 1946 | pModal->miscBits); |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 1947 | |
| 1948 | |
Senthil Balasubramanian | cb33c41 | 2008-12-24 18:03:58 +0530 | [diff] [blame] | 1949 | if (AR_SREV_9280_20(ah) && AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20) { |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 1950 | if (IS_CHAN_2GHZ(chan)) |
Senthil Balasubramanian | cb33c41 | 2008-12-24 18:03:58 +0530 | [diff] [blame] | 1951 | REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE, |
| 1952 | eep->baseEepHeader.dacLpMode); |
| 1953 | else if (eep->baseEepHeader.dacHiPwrMode_5G) |
| 1954 | REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE, 0); |
| 1955 | else |
| 1956 | REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE, |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 1957 | eep->baseEepHeader.dacLpMode); |
Senthil Balasubramanian | cb33c41 | 2008-12-24 18:03:58 +0530 | [diff] [blame] | 1958 | |
| 1959 | REG_RMW_FIELD(ah, AR_PHY_FRAME_CTL, AR_PHY_FRAME_CTL_TX_CLIP, |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 1960 | pModal->miscBits >> 2); |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 1961 | |
| 1962 | REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL9, |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 1963 | AR_PHY_TX_DESIRED_SCALE_CCK, |
| 1964 | eep->baseEepHeader.desiredScaleCCK); |
Senthil Balasubramanian | cb33c41 | 2008-12-24 18:03:58 +0530 | [diff] [blame] | 1965 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1966 | } |
| 1967 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1968 | static void ath9k_hw_def_set_addac(struct ath_hw *ah, |
| 1969 | struct ath9k_channel *chan) |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1970 | { |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1971 | #define XPA_LVL_FREQ(cnt) (pModal->xpaBiasLvlFreq[cnt]) |
| 1972 | struct modal_eep_header *pModal; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1973 | struct ar5416_eeprom_def *eep = &ah->eeprom.def; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1974 | u8 biaslevel; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1975 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1976 | if (ah->hw_version.macVersion != AR_SREV_VERSION_9160) |
| 1977 | return; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1978 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1979 | if (ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_MINOR_VER_7) |
| 1980 | return; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1981 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1982 | pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]); |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1983 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1984 | if (pModal->xpaBiasLvl != 0xff) { |
| 1985 | biaslevel = pModal->xpaBiasLvl; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1986 | } else { |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1987 | u16 resetFreqBin, freqBin, freqCount = 0; |
| 1988 | struct chan_centers centers; |
| 1989 | |
| 1990 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
| 1991 | |
| 1992 | resetFreqBin = FREQ2FBIN(centers.synth_center, |
| 1993 | IS_CHAN_2GHZ(chan)); |
| 1994 | freqBin = XPA_LVL_FREQ(0) & 0xff; |
| 1995 | biaslevel = (u8) (XPA_LVL_FREQ(0) >> 14); |
| 1996 | |
| 1997 | freqCount++; |
| 1998 | |
| 1999 | while (freqCount < 3) { |
| 2000 | if (XPA_LVL_FREQ(freqCount) == 0x0) |
| 2001 | break; |
| 2002 | |
| 2003 | freqBin = XPA_LVL_FREQ(freqCount) & 0xff; |
| 2004 | if (resetFreqBin >= freqBin) |
| 2005 | biaslevel = (u8)(XPA_LVL_FREQ(freqCount) >> 14); |
| 2006 | else |
| 2007 | break; |
| 2008 | freqCount++; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 2009 | } |
| 2010 | } |
| 2011 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2012 | if (IS_CHAN_2GHZ(chan)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2013 | INI_RA(&ah->iniAddac, 7, 1) = (INI_RA(&ah->iniAddac, |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2014 | 7, 1) & (~0x18)) | biaslevel << 3; |
| 2015 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2016 | INI_RA(&ah->iniAddac, 6, 1) = (INI_RA(&ah->iniAddac, |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2017 | 6, 1) & (~0xc0)) | biaslevel << 6; |
| 2018 | } |
| 2019 | #undef XPA_LVL_FREQ |
| 2020 | } |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 2021 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2022 | static void ath9k_hw_get_def_gain_boundaries_pdadcs(struct ath_hw *ah, |
| 2023 | struct ath9k_channel *chan, |
| 2024 | struct cal_data_per_freq *pRawDataSet, |
| 2025 | u8 *bChans, u16 availPiers, |
| 2026 | u16 tPdGainOverlap, int16_t *pMinCalPower, |
| 2027 | u16 *pPdGainBoundaries, u8 *pPDADCValues, |
| 2028 | u16 numXpdGains) |
| 2029 | { |
| 2030 | int i, j, k; |
| 2031 | int16_t ss; |
| 2032 | u16 idxL = 0, idxR = 0, numPiers; |
| 2033 | static u8 vpdTableL[AR5416_NUM_PD_GAINS] |
| 2034 | [AR5416_MAX_PWR_RANGE_IN_HALF_DB]; |
| 2035 | static u8 vpdTableR[AR5416_NUM_PD_GAINS] |
| 2036 | [AR5416_MAX_PWR_RANGE_IN_HALF_DB]; |
| 2037 | static u8 vpdTableI[AR5416_NUM_PD_GAINS] |
| 2038 | [AR5416_MAX_PWR_RANGE_IN_HALF_DB]; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 2039 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2040 | u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR; |
| 2041 | u8 minPwrT4[AR5416_NUM_PD_GAINS]; |
| 2042 | u8 maxPwrT4[AR5416_NUM_PD_GAINS]; |
| 2043 | int16_t vpdStep; |
| 2044 | int16_t tmpVal; |
| 2045 | u16 sizeCurrVpdTable, maxIndex, tgtIndex; |
| 2046 | bool match; |
| 2047 | int16_t minDelta = 0; |
| 2048 | struct chan_centers centers; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 2049 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2050 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 2051 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2052 | for (numPiers = 0; numPiers < availPiers; numPiers++) { |
| 2053 | if (bChans[numPiers] == AR5416_BCHAN_UNUSED) |
| 2054 | break; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 2055 | } |
| 2056 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2057 | match = ath9k_hw_get_lower_upper_index((u8)FREQ2FBIN(centers.synth_center, |
| 2058 | IS_CHAN_2GHZ(chan)), |
| 2059 | bChans, numPiers, &idxL, &idxR); |
| 2060 | |
| 2061 | if (match) { |
| 2062 | for (i = 0; i < numXpdGains; i++) { |
| 2063 | minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0]; |
| 2064 | maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4]; |
| 2065 | ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i], |
| 2066 | pRawDataSet[idxL].pwrPdg[i], |
| 2067 | pRawDataSet[idxL].vpdPdg[i], |
| 2068 | AR5416_PD_GAIN_ICEPTS, |
| 2069 | vpdTableI[i]); |
| 2070 | } |
| 2071 | } else { |
| 2072 | for (i = 0; i < numXpdGains; i++) { |
| 2073 | pVpdL = pRawDataSet[idxL].vpdPdg[i]; |
| 2074 | pPwrL = pRawDataSet[idxL].pwrPdg[i]; |
| 2075 | pVpdR = pRawDataSet[idxR].vpdPdg[i]; |
| 2076 | pPwrR = pRawDataSet[idxR].pwrPdg[i]; |
| 2077 | |
| 2078 | minPwrT4[i] = max(pPwrL[0], pPwrR[0]); |
| 2079 | |
| 2080 | maxPwrT4[i] = |
| 2081 | min(pPwrL[AR5416_PD_GAIN_ICEPTS - 1], |
| 2082 | pPwrR[AR5416_PD_GAIN_ICEPTS - 1]); |
| 2083 | |
| 2084 | |
| 2085 | ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i], |
| 2086 | pPwrL, pVpdL, |
| 2087 | AR5416_PD_GAIN_ICEPTS, |
| 2088 | vpdTableL[i]); |
| 2089 | ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i], |
| 2090 | pPwrR, pVpdR, |
| 2091 | AR5416_PD_GAIN_ICEPTS, |
| 2092 | vpdTableR[i]); |
| 2093 | |
| 2094 | for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) { |
| 2095 | vpdTableI[i][j] = |
| 2096 | (u8)(ath9k_hw_interpolate((u16) |
| 2097 | FREQ2FBIN(centers. |
| 2098 | synth_center, |
| 2099 | IS_CHAN_2GHZ |
| 2100 | (chan)), |
| 2101 | bChans[idxL], bChans[idxR], |
| 2102 | vpdTableL[i][j], vpdTableR[i][j])); |
| 2103 | } |
| 2104 | } |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 2105 | } |
| 2106 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2107 | *pMinCalPower = (int16_t)(minPwrT4[0] / 2); |
| 2108 | |
| 2109 | k = 0; |
| 2110 | |
| 2111 | for (i = 0; i < numXpdGains; i++) { |
| 2112 | if (i == (numXpdGains - 1)) |
| 2113 | pPdGainBoundaries[i] = |
| 2114 | (u16)(maxPwrT4[i] / 2); |
| 2115 | else |
| 2116 | pPdGainBoundaries[i] = |
| 2117 | (u16)((maxPwrT4[i] + minPwrT4[i + 1]) / 4); |
| 2118 | |
| 2119 | pPdGainBoundaries[i] = |
| 2120 | min((u16)AR5416_MAX_RATE_POWER, pPdGainBoundaries[i]); |
| 2121 | |
Gabor Juhos | a8c96d3 | 2009-03-06 09:08:51 +0100 | [diff] [blame] | 2122 | if ((i == 0) && !AR_SREV_5416_20_OR_LATER(ah)) { |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2123 | minDelta = pPdGainBoundaries[0] - 23; |
| 2124 | pPdGainBoundaries[0] = 23; |
| 2125 | } else { |
| 2126 | minDelta = 0; |
| 2127 | } |
| 2128 | |
| 2129 | if (i == 0) { |
| 2130 | if (AR_SREV_9280_10_OR_LATER(ah)) |
| 2131 | ss = (int16_t)(0 - (minPwrT4[i] / 2)); |
| 2132 | else |
| 2133 | ss = 0; |
| 2134 | } else { |
| 2135 | ss = (int16_t)((pPdGainBoundaries[i - 1] - |
| 2136 | (minPwrT4[i] / 2)) - |
| 2137 | tPdGainOverlap + 1 + minDelta); |
| 2138 | } |
| 2139 | vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]); |
| 2140 | vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep); |
| 2141 | |
| 2142 | while ((ss < 0) && (k < (AR5416_NUM_PDADC_VALUES - 1))) { |
| 2143 | tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep); |
| 2144 | pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal); |
| 2145 | ss++; |
| 2146 | } |
| 2147 | |
| 2148 | sizeCurrVpdTable = (u8) ((maxPwrT4[i] - minPwrT4[i]) / 2 + 1); |
| 2149 | tgtIndex = (u8)(pPdGainBoundaries[i] + tPdGainOverlap - |
| 2150 | (minPwrT4[i] / 2)); |
| 2151 | maxIndex = (tgtIndex < sizeCurrVpdTable) ? |
| 2152 | tgtIndex : sizeCurrVpdTable; |
| 2153 | |
| 2154 | while ((ss < maxIndex) && (k < (AR5416_NUM_PDADC_VALUES - 1))) { |
| 2155 | pPDADCValues[k++] = vpdTableI[i][ss++]; |
| 2156 | } |
| 2157 | |
| 2158 | vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] - |
| 2159 | vpdTableI[i][sizeCurrVpdTable - 2]); |
| 2160 | vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep); |
| 2161 | |
| 2162 | if (tgtIndex > maxIndex) { |
| 2163 | while ((ss <= tgtIndex) && |
| 2164 | (k < (AR5416_NUM_PDADC_VALUES - 1))) { |
| 2165 | tmpVal = (int16_t)((vpdTableI[i][sizeCurrVpdTable - 1] + |
| 2166 | (ss - maxIndex + 1) * vpdStep)); |
| 2167 | pPDADCValues[k++] = (u8)((tmpVal > 255) ? |
| 2168 | 255 : tmpVal); |
| 2169 | ss++; |
| 2170 | } |
| 2171 | } |
| 2172 | } |
| 2173 | |
| 2174 | while (i < AR5416_PD_GAINS_IN_MASK) { |
| 2175 | pPdGainBoundaries[i] = pPdGainBoundaries[i - 1]; |
| 2176 | i++; |
| 2177 | } |
| 2178 | |
| 2179 | while (k < AR5416_NUM_PDADC_VALUES) { |
| 2180 | pPDADCValues[k] = pPDADCValues[k - 1]; |
| 2181 | k++; |
| 2182 | } |
| 2183 | |
| 2184 | return; |
| 2185 | } |
| 2186 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 2187 | static void ath9k_hw_set_def_power_cal_table(struct ath_hw *ah, |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2188 | struct ath9k_channel *chan, |
| 2189 | int16_t *pTxPowerIndexOffset) |
| 2190 | { |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 2191 | #define SM_PD_GAIN(x) SM(0x38, AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_##x) |
| 2192 | #define SM_PDGAIN_B(x, y) \ |
| 2193 | SM((gainBoundaries[x]), AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_##y) |
| 2194 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2195 | struct ar5416_eeprom_def *pEepData = &ah->eeprom.def; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2196 | struct cal_data_per_freq *pRawDataset; |
| 2197 | u8 *pCalBChans = NULL; |
| 2198 | u16 pdGainOverlap_t2; |
| 2199 | static u8 pdadcValues[AR5416_NUM_PDADC_VALUES]; |
| 2200 | u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK]; |
| 2201 | u16 numPiers, i, j; |
| 2202 | int16_t tMinCalPower; |
| 2203 | u16 numXpdGain, xpdMask; |
| 2204 | u16 xpdGainValues[AR5416_NUM_PD_GAINS] = { 0, 0, 0, 0 }; |
| 2205 | u32 reg32, regOffset, regChainOffset; |
| 2206 | int16_t modalIdx; |
| 2207 | |
| 2208 | modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0; |
| 2209 | xpdMask = pEepData->modalHeader[modalIdx].xpdGain; |
| 2210 | |
| 2211 | if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >= |
| 2212 | AR5416_EEP_MINOR_VER_2) { |
| 2213 | pdGainOverlap_t2 = |
| 2214 | pEepData->modalHeader[modalIdx].pdGainOverlap; |
| 2215 | } else { |
| 2216 | pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5), |
| 2217 | AR_PHY_TPCRG5_PD_GAIN_OVERLAP)); |
| 2218 | } |
| 2219 | |
| 2220 | if (IS_CHAN_2GHZ(chan)) { |
| 2221 | pCalBChans = pEepData->calFreqPier2G; |
| 2222 | numPiers = AR5416_NUM_2G_CAL_PIERS; |
| 2223 | } else { |
| 2224 | pCalBChans = pEepData->calFreqPier5G; |
| 2225 | numPiers = AR5416_NUM_5G_CAL_PIERS; |
| 2226 | } |
| 2227 | |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 2228 | if (OLC_FOR_AR9280_20_LATER && IS_CHAN_2GHZ(chan)) { |
| 2229 | pRawDataset = pEepData->calPierData2G[0]; |
| 2230 | ah->initPDADC = ((struct calDataPerFreqOpLoop *) |
| 2231 | pRawDataset)->vpdPdg[0][0]; |
| 2232 | } |
| 2233 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2234 | numXpdGain = 0; |
| 2235 | |
| 2236 | for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) { |
| 2237 | if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) { |
| 2238 | if (numXpdGain >= AR5416_NUM_PD_GAINS) |
| 2239 | break; |
| 2240 | xpdGainValues[numXpdGain] = |
| 2241 | (u16)(AR5416_PD_GAINS_IN_MASK - i); |
| 2242 | numXpdGain++; |
| 2243 | } |
| 2244 | } |
| 2245 | |
| 2246 | REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN, |
| 2247 | (numXpdGain - 1) & 0x3); |
| 2248 | REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1, |
| 2249 | xpdGainValues[0]); |
| 2250 | REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2, |
| 2251 | xpdGainValues[1]); |
| 2252 | REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3, |
| 2253 | xpdGainValues[2]); |
| 2254 | |
| 2255 | for (i = 0; i < AR5416_MAX_CHAINS; i++) { |
Gabor Juhos | a8c96d3 | 2009-03-06 09:08:51 +0100 | [diff] [blame] | 2256 | if (AR_SREV_5416_20_OR_LATER(ah) && |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2257 | (ah->rxchainmask == 5 || ah->txchainmask == 5) && |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2258 | (i != 0)) { |
| 2259 | regChainOffset = (i == 1) ? 0x2000 : 0x1000; |
| 2260 | } else |
| 2261 | regChainOffset = i * 0x1000; |
| 2262 | |
| 2263 | if (pEepData->baseEepHeader.txMask & (1 << i)) { |
| 2264 | if (IS_CHAN_2GHZ(chan)) |
| 2265 | pRawDataset = pEepData->calPierData2G[i]; |
| 2266 | else |
| 2267 | pRawDataset = pEepData->calPierData5G[i]; |
| 2268 | |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 2269 | |
| 2270 | if (OLC_FOR_AR9280_20_LATER) { |
| 2271 | u8 pcdacIdx; |
| 2272 | u8 txPower; |
| 2273 | |
| 2274 | ath9k_get_txgain_index(ah, chan, |
| 2275 | (struct calDataPerFreqOpLoop *)pRawDataset, |
| 2276 | pCalBChans, numPiers, &txPower, &pcdacIdx); |
| 2277 | ath9k_olc_get_pdadcs(ah, pcdacIdx, |
| 2278 | txPower/2, pdadcValues); |
| 2279 | } else { |
| 2280 | ath9k_hw_get_def_gain_boundaries_pdadcs(ah, |
| 2281 | chan, pRawDataset, |
| 2282 | pCalBChans, numPiers, |
| 2283 | pdGainOverlap_t2, |
| 2284 | &tMinCalPower, |
| 2285 | gainBoundaries, |
| 2286 | pdadcValues, |
| 2287 | numXpdGain); |
| 2288 | } |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2289 | |
Gabor Juhos | a8c96d3 | 2009-03-06 09:08:51 +0100 | [diff] [blame] | 2290 | if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah)) { |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 2291 | if (OLC_FOR_AR9280_20_LATER) { |
| 2292 | REG_WRITE(ah, |
| 2293 | AR_PHY_TPCRG5 + regChainOffset, |
| 2294 | SM(0x6, |
| 2295 | AR_PHY_TPCRG5_PD_GAIN_OVERLAP) | |
| 2296 | SM_PD_GAIN(1) | SM_PD_GAIN(2) | |
| 2297 | SM_PD_GAIN(3) | SM_PD_GAIN(4)); |
| 2298 | } else { |
| 2299 | REG_WRITE(ah, |
| 2300 | AR_PHY_TPCRG5 + regChainOffset, |
| 2301 | SM(pdGainOverlap_t2, |
| 2302 | AR_PHY_TPCRG5_PD_GAIN_OVERLAP)| |
| 2303 | SM_PDGAIN_B(0, 1) | |
| 2304 | SM_PDGAIN_B(1, 2) | |
| 2305 | SM_PDGAIN_B(2, 3) | |
| 2306 | SM_PDGAIN_B(3, 4)); |
| 2307 | } |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2308 | } |
| 2309 | |
| 2310 | regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset; |
| 2311 | for (j = 0; j < 32; j++) { |
| 2312 | reg32 = ((pdadcValues[4 * j + 0] & 0xFF) << 0) | |
| 2313 | ((pdadcValues[4 * j + 1] & 0xFF) << 8) | |
| 2314 | ((pdadcValues[4 * j + 2] & 0xFF) << 16)| |
| 2315 | ((pdadcValues[4 * j + 3] & 0xFF) << 24); |
| 2316 | REG_WRITE(ah, regOffset, reg32); |
| 2317 | |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 2318 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2319 | "PDADC (%d,%4x): %4.4x %8.8x\n", |
| 2320 | i, regChainOffset, regOffset, |
| 2321 | reg32); |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 2322 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2323 | "PDADC: Chain %d | PDADC %3d " |
| 2324 | "Value %3d | PDADC %3d Value %3d | " |
| 2325 | "PDADC %3d Value %3d | PDADC %3d " |
| 2326 | "Value %3d |\n", |
| 2327 | i, 4 * j, pdadcValues[4 * j], |
| 2328 | 4 * j + 1, pdadcValues[4 * j + 1], |
| 2329 | 4 * j + 2, pdadcValues[4 * j + 2], |
| 2330 | 4 * j + 3, |
| 2331 | pdadcValues[4 * j + 3]); |
| 2332 | |
| 2333 | regOffset += 4; |
| 2334 | } |
| 2335 | } |
| 2336 | } |
| 2337 | |
| 2338 | *pTxPowerIndexOffset = 0; |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 2339 | #undef SM_PD_GAIN |
| 2340 | #undef SM_PDGAIN_B |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 2341 | } |
| 2342 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 2343 | static void ath9k_hw_set_def_power_per_rate_table(struct ath_hw *ah, |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2344 | struct ath9k_channel *chan, |
| 2345 | int16_t *ratesArray, |
| 2346 | u16 cfgCtl, |
| 2347 | u16 AntennaReduction, |
| 2348 | u16 twiceMaxRegulatoryPower, |
| 2349 | u16 powerLimit) |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 2350 | { |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2351 | #define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6 /* 10*log10(2)*2 */ |
| 2352 | #define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10 /* 10*log10(3)*2 */ |
| 2353 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2354 | struct ar5416_eeprom_def *pEepData = &ah->eeprom.def; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2355 | u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER; |
| 2356 | static const u16 tpScaleReductionTable[5] = |
| 2357 | { 0, 3, 6, 9, AR5416_MAX_RATE_POWER }; |
| 2358 | |
| 2359 | int i; |
| 2360 | int16_t twiceLargestAntenna; |
| 2361 | struct cal_ctl_data *rep; |
| 2362 | struct cal_target_power_leg targetPowerOfdm, targetPowerCck = { |
| 2363 | 0, { 0, 0, 0, 0} |
| 2364 | }; |
| 2365 | struct cal_target_power_leg targetPowerOfdmExt = { |
| 2366 | 0, { 0, 0, 0, 0} }, targetPowerCckExt = { |
| 2367 | 0, { 0, 0, 0, 0 } |
| 2368 | }; |
| 2369 | struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = { |
| 2370 | 0, {0, 0, 0, 0} |
| 2371 | }; |
| 2372 | u16 scaledPower = 0, minCtlPower, maxRegAllowedPower; |
| 2373 | u16 ctlModesFor11a[] = |
| 2374 | { CTL_11A, CTL_5GHT20, CTL_11A_EXT, CTL_5GHT40 }; |
| 2375 | u16 ctlModesFor11g[] = |
| 2376 | { CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, CTL_11G_EXT, |
| 2377 | CTL_2GHT40 |
| 2378 | }; |
| 2379 | u16 numCtlModes, *pCtlMode, ctlMode, freq; |
| 2380 | struct chan_centers centers; |
| 2381 | int tx_chainmask; |
| 2382 | u16 twiceMinEdgePower; |
| 2383 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2384 | tx_chainmask = ah->txchainmask; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2385 | |
| 2386 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
| 2387 | |
| 2388 | twiceLargestAntenna = max( |
| 2389 | pEepData->modalHeader |
| 2390 | [IS_CHAN_2GHZ(chan)].antennaGainCh[0], |
| 2391 | pEepData->modalHeader |
| 2392 | [IS_CHAN_2GHZ(chan)].antennaGainCh[1]); |
| 2393 | |
| 2394 | twiceLargestAntenna = max((u8)twiceLargestAntenna, |
| 2395 | pEepData->modalHeader |
| 2396 | [IS_CHAN_2GHZ(chan)].antennaGainCh[2]); |
| 2397 | |
| 2398 | twiceLargestAntenna = (int16_t)min(AntennaReduction - |
| 2399 | twiceLargestAntenna, 0); |
| 2400 | |
| 2401 | maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna; |
| 2402 | |
| 2403 | if (ah->regulatory.tp_scale != ATH9K_TP_SCALE_MAX) { |
| 2404 | maxRegAllowedPower -= |
| 2405 | (tpScaleReductionTable[(ah->regulatory.tp_scale)] * 2); |
| 2406 | } |
| 2407 | |
| 2408 | scaledPower = min(powerLimit, maxRegAllowedPower); |
| 2409 | |
| 2410 | switch (ar5416_get_ntxchains(tx_chainmask)) { |
| 2411 | case 1: |
| 2412 | break; |
| 2413 | case 2: |
| 2414 | scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN; |
| 2415 | break; |
| 2416 | case 3: |
| 2417 | scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN; |
| 2418 | break; |
| 2419 | } |
| 2420 | |
| 2421 | scaledPower = max((u16)0, scaledPower); |
| 2422 | |
| 2423 | if (IS_CHAN_2GHZ(chan)) { |
| 2424 | numCtlModes = ARRAY_SIZE(ctlModesFor11g) - |
| 2425 | SUB_NUM_CTL_MODES_AT_2G_40; |
| 2426 | pCtlMode = ctlModesFor11g; |
| 2427 | |
| 2428 | ath9k_hw_get_legacy_target_powers(ah, chan, |
| 2429 | pEepData->calTargetPowerCck, |
| 2430 | AR5416_NUM_2G_CCK_TARGET_POWERS, |
| 2431 | &targetPowerCck, 4, false); |
| 2432 | ath9k_hw_get_legacy_target_powers(ah, chan, |
| 2433 | pEepData->calTargetPower2G, |
| 2434 | AR5416_NUM_2G_20_TARGET_POWERS, |
| 2435 | &targetPowerOfdm, 4, false); |
| 2436 | ath9k_hw_get_target_powers(ah, chan, |
| 2437 | pEepData->calTargetPower2GHT20, |
| 2438 | AR5416_NUM_2G_20_TARGET_POWERS, |
| 2439 | &targetPowerHt20, 8, false); |
| 2440 | |
| 2441 | if (IS_CHAN_HT40(chan)) { |
| 2442 | numCtlModes = ARRAY_SIZE(ctlModesFor11g); |
| 2443 | ath9k_hw_get_target_powers(ah, chan, |
| 2444 | pEepData->calTargetPower2GHT40, |
| 2445 | AR5416_NUM_2G_40_TARGET_POWERS, |
| 2446 | &targetPowerHt40, 8, true); |
| 2447 | ath9k_hw_get_legacy_target_powers(ah, chan, |
| 2448 | pEepData->calTargetPowerCck, |
| 2449 | AR5416_NUM_2G_CCK_TARGET_POWERS, |
| 2450 | &targetPowerCckExt, 4, true); |
| 2451 | ath9k_hw_get_legacy_target_powers(ah, chan, |
| 2452 | pEepData->calTargetPower2G, |
| 2453 | AR5416_NUM_2G_20_TARGET_POWERS, |
| 2454 | &targetPowerOfdmExt, 4, true); |
| 2455 | } |
| 2456 | } else { |
| 2457 | numCtlModes = ARRAY_SIZE(ctlModesFor11a) - |
| 2458 | SUB_NUM_CTL_MODES_AT_5G_40; |
| 2459 | pCtlMode = ctlModesFor11a; |
| 2460 | |
| 2461 | ath9k_hw_get_legacy_target_powers(ah, chan, |
| 2462 | pEepData->calTargetPower5G, |
| 2463 | AR5416_NUM_5G_20_TARGET_POWERS, |
| 2464 | &targetPowerOfdm, 4, false); |
| 2465 | ath9k_hw_get_target_powers(ah, chan, |
| 2466 | pEepData->calTargetPower5GHT20, |
| 2467 | AR5416_NUM_5G_20_TARGET_POWERS, |
| 2468 | &targetPowerHt20, 8, false); |
| 2469 | |
| 2470 | if (IS_CHAN_HT40(chan)) { |
| 2471 | numCtlModes = ARRAY_SIZE(ctlModesFor11a); |
| 2472 | ath9k_hw_get_target_powers(ah, chan, |
| 2473 | pEepData->calTargetPower5GHT40, |
| 2474 | AR5416_NUM_5G_40_TARGET_POWERS, |
| 2475 | &targetPowerHt40, 8, true); |
| 2476 | ath9k_hw_get_legacy_target_powers(ah, chan, |
| 2477 | pEepData->calTargetPower5G, |
| 2478 | AR5416_NUM_5G_20_TARGET_POWERS, |
| 2479 | &targetPowerOfdmExt, 4, true); |
| 2480 | } |
| 2481 | } |
| 2482 | |
| 2483 | for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) { |
| 2484 | bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) || |
| 2485 | (pCtlMode[ctlMode] == CTL_2GHT40); |
| 2486 | if (isHt40CtlMode) |
| 2487 | freq = centers.synth_center; |
| 2488 | else if (pCtlMode[ctlMode] & EXT_ADDITIVE) |
| 2489 | freq = centers.ext_center; |
| 2490 | else |
| 2491 | freq = centers.ctl_center; |
| 2492 | |
| 2493 | if (ah->eep_ops->get_eeprom_ver(ah) == 14 && |
| 2494 | ah->eep_ops->get_eeprom_rev(ah) <= 2) |
| 2495 | twiceMaxEdgePower = AR5416_MAX_RATE_POWER; |
| 2496 | |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 2497 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2498 | "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d, " |
| 2499 | "EXT_ADDITIVE %d\n", |
| 2500 | ctlMode, numCtlModes, isHt40CtlMode, |
| 2501 | (pCtlMode[ctlMode] & EXT_ADDITIVE)); |
| 2502 | |
| 2503 | for (i = 0; (i < AR5416_NUM_CTLS) && pEepData->ctlIndex[i]; i++) { |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 2504 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2505 | " LOOP-Ctlidx %d: cfgCtl 0x%2.2x " |
| 2506 | "pCtlMode 0x%2.2x ctlIndex 0x%2.2x " |
| 2507 | "chan %d\n", |
| 2508 | i, cfgCtl, pCtlMode[ctlMode], |
| 2509 | pEepData->ctlIndex[i], chan->channel); |
| 2510 | |
| 2511 | if ((((cfgCtl & ~CTL_MODE_M) | |
| 2512 | (pCtlMode[ctlMode] & CTL_MODE_M)) == |
| 2513 | pEepData->ctlIndex[i]) || |
| 2514 | (((cfgCtl & ~CTL_MODE_M) | |
| 2515 | (pCtlMode[ctlMode] & CTL_MODE_M)) == |
| 2516 | ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))) { |
| 2517 | rep = &(pEepData->ctlData[i]); |
| 2518 | |
| 2519 | twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq, |
| 2520 | rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1], |
| 2521 | IS_CHAN_2GHZ(chan), AR5416_NUM_BAND_EDGES); |
| 2522 | |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 2523 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2524 | " MATCH-EE_IDX %d: ch %d is2 %d " |
| 2525 | "2xMinEdge %d chainmask %d chains %d\n", |
| 2526 | i, freq, IS_CHAN_2GHZ(chan), |
| 2527 | twiceMinEdgePower, tx_chainmask, |
| 2528 | ar5416_get_ntxchains |
| 2529 | (tx_chainmask)); |
| 2530 | if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) { |
| 2531 | twiceMaxEdgePower = min(twiceMaxEdgePower, |
| 2532 | twiceMinEdgePower); |
| 2533 | } else { |
| 2534 | twiceMaxEdgePower = twiceMinEdgePower; |
| 2535 | break; |
| 2536 | } |
| 2537 | } |
| 2538 | } |
| 2539 | |
| 2540 | minCtlPower = min(twiceMaxEdgePower, scaledPower); |
| 2541 | |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 2542 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2543 | " SEL-Min ctlMode %d pCtlMode %d " |
| 2544 | "2xMaxEdge %d sP %d minCtlPwr %d\n", |
| 2545 | ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower, |
| 2546 | scaledPower, minCtlPower); |
| 2547 | |
| 2548 | switch (pCtlMode[ctlMode]) { |
| 2549 | case CTL_11B: |
| 2550 | for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) { |
| 2551 | targetPowerCck.tPow2x[i] = |
| 2552 | min((u16)targetPowerCck.tPow2x[i], |
| 2553 | minCtlPower); |
| 2554 | } |
| 2555 | break; |
| 2556 | case CTL_11A: |
| 2557 | case CTL_11G: |
| 2558 | for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) { |
| 2559 | targetPowerOfdm.tPow2x[i] = |
| 2560 | min((u16)targetPowerOfdm.tPow2x[i], |
| 2561 | minCtlPower); |
| 2562 | } |
| 2563 | break; |
| 2564 | case CTL_5GHT20: |
| 2565 | case CTL_2GHT20: |
| 2566 | for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) { |
| 2567 | targetPowerHt20.tPow2x[i] = |
| 2568 | min((u16)targetPowerHt20.tPow2x[i], |
| 2569 | minCtlPower); |
| 2570 | } |
| 2571 | break; |
| 2572 | case CTL_11B_EXT: |
| 2573 | targetPowerCckExt.tPow2x[0] = min((u16) |
| 2574 | targetPowerCckExt.tPow2x[0], |
| 2575 | minCtlPower); |
| 2576 | break; |
| 2577 | case CTL_11A_EXT: |
| 2578 | case CTL_11G_EXT: |
| 2579 | targetPowerOfdmExt.tPow2x[0] = min((u16) |
| 2580 | targetPowerOfdmExt.tPow2x[0], |
| 2581 | minCtlPower); |
| 2582 | break; |
| 2583 | case CTL_5GHT40: |
| 2584 | case CTL_2GHT40: |
| 2585 | for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) { |
| 2586 | targetPowerHt40.tPow2x[i] = |
| 2587 | min((u16)targetPowerHt40.tPow2x[i], |
| 2588 | minCtlPower); |
| 2589 | } |
| 2590 | break; |
| 2591 | default: |
| 2592 | break; |
| 2593 | } |
| 2594 | } |
| 2595 | |
| 2596 | ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] = |
| 2597 | ratesArray[rate18mb] = ratesArray[rate24mb] = |
| 2598 | targetPowerOfdm.tPow2x[0]; |
| 2599 | ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1]; |
| 2600 | ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2]; |
| 2601 | ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3]; |
| 2602 | ratesArray[rateXr] = targetPowerOfdm.tPow2x[0]; |
| 2603 | |
| 2604 | for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) |
| 2605 | ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i]; |
| 2606 | |
| 2607 | if (IS_CHAN_2GHZ(chan)) { |
| 2608 | ratesArray[rate1l] = targetPowerCck.tPow2x[0]; |
| 2609 | ratesArray[rate2s] = ratesArray[rate2l] = |
| 2610 | targetPowerCck.tPow2x[1]; |
| 2611 | ratesArray[rate5_5s] = ratesArray[rate5_5l] = |
| 2612 | targetPowerCck.tPow2x[2]; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2613 | ratesArray[rate11s] = ratesArray[rate11l] = |
| 2614 | targetPowerCck.tPow2x[3]; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2615 | } |
| 2616 | if (IS_CHAN_HT40(chan)) { |
| 2617 | for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) { |
| 2618 | ratesArray[rateHt40_0 + i] = |
| 2619 | targetPowerHt40.tPow2x[i]; |
| 2620 | } |
| 2621 | ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0]; |
| 2622 | ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0]; |
| 2623 | ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0]; |
| 2624 | if (IS_CHAN_2GHZ(chan)) { |
| 2625 | ratesArray[rateExtCck] = |
| 2626 | targetPowerCckExt.tPow2x[0]; |
| 2627 | } |
| 2628 | } |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 2629 | } |
| 2630 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 2631 | static void ath9k_hw_def_set_txpower(struct ath_hw *ah, |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2632 | struct ath9k_channel *chan, |
| 2633 | u16 cfgCtl, |
| 2634 | u8 twiceAntennaReduction, |
| 2635 | u8 twiceMaxRegulatoryPower, |
| 2636 | u8 powerLimit) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2637 | { |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 2638 | #define RT_AR_DELTA(x) (ratesArray[x] - cck_ofdm_delta) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2639 | struct ar5416_eeprom_def *pEepData = &ah->eeprom.def; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2640 | struct modal_eep_header *pModal = |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2641 | &(pEepData->modalHeader[IS_CHAN_2GHZ(chan)]); |
| 2642 | int16_t ratesArray[Ar5416RateSize]; |
| 2643 | int16_t txPowerIndexOffset = 0; |
| 2644 | u8 ht40PowerIncForPdadc = 2; |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 2645 | int i, cck_ofdm_delta = 0; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2646 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2647 | memset(ratesArray, 0, sizeof(ratesArray)); |
| 2648 | |
| 2649 | if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >= |
| 2650 | AR5416_EEP_MINOR_VER_2) { |
| 2651 | ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc; |
| 2652 | } |
| 2653 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 2654 | ath9k_hw_set_def_power_per_rate_table(ah, chan, |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2655 | &ratesArray[0], cfgCtl, |
| 2656 | twiceAntennaReduction, |
| 2657 | twiceMaxRegulatoryPower, |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 2658 | powerLimit); |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2659 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 2660 | ath9k_hw_set_def_power_cal_table(ah, chan, &txPowerIndexOffset); |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2661 | |
| 2662 | for (i = 0; i < ARRAY_SIZE(ratesArray); i++) { |
| 2663 | ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]); |
| 2664 | if (ratesArray[i] > AR5416_MAX_RATE_POWER) |
| 2665 | ratesArray[i] = AR5416_MAX_RATE_POWER; |
| 2666 | } |
| 2667 | |
| 2668 | if (AR_SREV_9280_10_OR_LATER(ah)) { |
| 2669 | for (i = 0; i < Ar5416RateSize; i++) |
| 2670 | ratesArray[i] -= AR5416_PWR_TABLE_OFFSET * 2; |
| 2671 | } |
| 2672 | |
| 2673 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE1, |
| 2674 | ATH9K_POW_SM(ratesArray[rate18mb], 24) |
| 2675 | | ATH9K_POW_SM(ratesArray[rate12mb], 16) |
| 2676 | | ATH9K_POW_SM(ratesArray[rate9mb], 8) |
| 2677 | | ATH9K_POW_SM(ratesArray[rate6mb], 0)); |
| 2678 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE2, |
| 2679 | ATH9K_POW_SM(ratesArray[rate54mb], 24) |
| 2680 | | ATH9K_POW_SM(ratesArray[rate48mb], 16) |
| 2681 | | ATH9K_POW_SM(ratesArray[rate36mb], 8) |
| 2682 | | ATH9K_POW_SM(ratesArray[rate24mb], 0)); |
| 2683 | |
| 2684 | if (IS_CHAN_2GHZ(chan)) { |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 2685 | if (OLC_FOR_AR9280_20_LATER) { |
| 2686 | cck_ofdm_delta = 2; |
| 2687 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE3, |
| 2688 | ATH9K_POW_SM(RT_AR_DELTA(rate2s), 24) |
| 2689 | | ATH9K_POW_SM(RT_AR_DELTA(rate2l), 16) |
| 2690 | | ATH9K_POW_SM(ratesArray[rateXr], 8) |
| 2691 | | ATH9K_POW_SM(RT_AR_DELTA(rate1l), 0)); |
| 2692 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE4, |
| 2693 | ATH9K_POW_SM(RT_AR_DELTA(rate11s), 24) |
| 2694 | | ATH9K_POW_SM(RT_AR_DELTA(rate11l), 16) |
| 2695 | | ATH9K_POW_SM(RT_AR_DELTA(rate5_5s), 8) |
| 2696 | | ATH9K_POW_SM(RT_AR_DELTA(rate5_5l), 0)); |
| 2697 | } else { |
| 2698 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE3, |
| 2699 | ATH9K_POW_SM(ratesArray[rate2s], 24) |
| 2700 | | ATH9K_POW_SM(ratesArray[rate2l], 16) |
| 2701 | | ATH9K_POW_SM(ratesArray[rateXr], 8) |
| 2702 | | ATH9K_POW_SM(ratesArray[rate1l], 0)); |
| 2703 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE4, |
| 2704 | ATH9K_POW_SM(ratesArray[rate11s], 24) |
| 2705 | | ATH9K_POW_SM(ratesArray[rate11l], 16) |
| 2706 | | ATH9K_POW_SM(ratesArray[rate5_5s], 8) |
| 2707 | | ATH9K_POW_SM(ratesArray[rate5_5l], 0)); |
| 2708 | } |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2709 | } |
| 2710 | |
| 2711 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE5, |
| 2712 | ATH9K_POW_SM(ratesArray[rateHt20_3], 24) |
| 2713 | | ATH9K_POW_SM(ratesArray[rateHt20_2], 16) |
| 2714 | | ATH9K_POW_SM(ratesArray[rateHt20_1], 8) |
| 2715 | | ATH9K_POW_SM(ratesArray[rateHt20_0], 0)); |
| 2716 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE6, |
| 2717 | ATH9K_POW_SM(ratesArray[rateHt20_7], 24) |
| 2718 | | ATH9K_POW_SM(ratesArray[rateHt20_6], 16) |
| 2719 | | ATH9K_POW_SM(ratesArray[rateHt20_5], 8) |
| 2720 | | ATH9K_POW_SM(ratesArray[rateHt20_4], 0)); |
| 2721 | |
| 2722 | if (IS_CHAN_HT40(chan)) { |
| 2723 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE7, |
| 2724 | ATH9K_POW_SM(ratesArray[rateHt40_3] + |
| 2725 | ht40PowerIncForPdadc, 24) |
| 2726 | | ATH9K_POW_SM(ratesArray[rateHt40_2] + |
| 2727 | ht40PowerIncForPdadc, 16) |
| 2728 | | ATH9K_POW_SM(ratesArray[rateHt40_1] + |
| 2729 | ht40PowerIncForPdadc, 8) |
| 2730 | | ATH9K_POW_SM(ratesArray[rateHt40_0] + |
| 2731 | ht40PowerIncForPdadc, 0)); |
| 2732 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE8, |
| 2733 | ATH9K_POW_SM(ratesArray[rateHt40_7] + |
| 2734 | ht40PowerIncForPdadc, 24) |
| 2735 | | ATH9K_POW_SM(ratesArray[rateHt40_6] + |
| 2736 | ht40PowerIncForPdadc, 16) |
| 2737 | | ATH9K_POW_SM(ratesArray[rateHt40_5] + |
| 2738 | ht40PowerIncForPdadc, 8) |
| 2739 | | ATH9K_POW_SM(ratesArray[rateHt40_4] + |
| 2740 | ht40PowerIncForPdadc, 0)); |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 2741 | if (OLC_FOR_AR9280_20_LATER) { |
| 2742 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE9, |
| 2743 | ATH9K_POW_SM(ratesArray[rateExtOfdm], 24) |
| 2744 | | ATH9K_POW_SM(RT_AR_DELTA(rateExtCck), 16) |
| 2745 | | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8) |
| 2746 | | ATH9K_POW_SM(RT_AR_DELTA(rateDupCck), 0)); |
| 2747 | } else { |
| 2748 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE9, |
| 2749 | ATH9K_POW_SM(ratesArray[rateExtOfdm], 24) |
| 2750 | | ATH9K_POW_SM(ratesArray[rateExtCck], 16) |
| 2751 | | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8) |
| 2752 | | ATH9K_POW_SM(ratesArray[rateDupCck], 0)); |
| 2753 | } |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2754 | } |
| 2755 | |
| 2756 | REG_WRITE(ah, AR_PHY_POWER_TX_SUB, |
| 2757 | ATH9K_POW_SM(pModal->pwrDecreaseFor3Chain, 6) |
| 2758 | | ATH9K_POW_SM(pModal->pwrDecreaseFor2Chain, 0)); |
| 2759 | |
| 2760 | i = rate6mb; |
| 2761 | |
| 2762 | if (IS_CHAN_HT40(chan)) |
| 2763 | i = rateHt40_0; |
| 2764 | else if (IS_CHAN_HT20(chan)) |
| 2765 | i = rateHt20_0; |
| 2766 | |
| 2767 | if (AR_SREV_9280_10_OR_LATER(ah)) |
| 2768 | ah->regulatory.max_power_level = |
| 2769 | ratesArray[i] + AR5416_PWR_TABLE_OFFSET * 2; |
| 2770 | else |
| 2771 | ah->regulatory.max_power_level = ratesArray[i]; |
| 2772 | |
Sujith | e421c7b | 2009-02-12 10:06:36 +0530 | [diff] [blame] | 2773 | switch(ar5416_get_ntxchains(ah->txchainmask)) { |
| 2774 | case 1: |
| 2775 | break; |
| 2776 | case 2: |
| 2777 | ah->regulatory.max_power_level += INCREASE_MAXPOW_BY_TWO_CHAIN; |
| 2778 | break; |
| 2779 | case 3: |
| 2780 | ah->regulatory.max_power_level += INCREASE_MAXPOW_BY_THREE_CHAIN; |
| 2781 | break; |
| 2782 | default: |
| 2783 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
| 2784 | "Invalid chainmask configuration\n"); |
| 2785 | break; |
| 2786 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2787 | } |
| 2788 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2789 | static u8 ath9k_hw_def_get_num_ant_config(struct ath_hw *ah, |
Hannes Eder | bf512bc | 2008-12-26 00:13:29 -0800 | [diff] [blame] | 2790 | enum ieee80211_band freq_band) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2791 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2792 | struct ar5416_eeprom_def *eep = &ah->eeprom.def; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2793 | struct modal_eep_header *pModal = |
Senthil Balasubramanian | 2df1bff | 2008-12-08 19:43:49 +0530 | [diff] [blame] | 2794 | &(eep->modalHeader[ATH9K_HAL_FREQ_BAND_2GHZ == freq_band]); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2795 | struct base_eep_header *pBase = &eep->baseEepHeader; |
| 2796 | u8 num_ant_config; |
| 2797 | |
| 2798 | num_ant_config = 1; |
| 2799 | |
| 2800 | if (pBase->version >= 0x0E0D) |
| 2801 | if (pModal->useAnt1) |
| 2802 | num_ant_config += 1; |
| 2803 | |
| 2804 | return num_ant_config; |
| 2805 | } |
| 2806 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2807 | static u16 ath9k_hw_def_get_eeprom_antenna_cfg(struct ath_hw *ah, |
| 2808 | struct ath9k_channel *chan) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2809 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2810 | struct ar5416_eeprom_def *eep = &ah->eeprom.def; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2811 | struct modal_eep_header *pModal = |
| 2812 | &(eep->modalHeader[IS_CHAN_2GHZ(chan)]); |
| 2813 | |
| 2814 | return pModal->antCtrlCommon & 0xFFFF; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 2815 | } |
| 2816 | |
Hannes Eder | 93f726a | 2009-02-14 11:49:48 +0000 | [diff] [blame] | 2817 | static u16 ath9k_hw_def_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz) |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 2818 | { |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 2819 | #define EEP_DEF_SPURCHAN \ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2820 | (ah->eeprom.def.modalHeader[is2GHz].spurChans[i].spurChan) |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2821 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2822 | u16 spur_val = AR_NO_SPUR; |
| 2823 | |
| 2824 | DPRINTF(ah->ah_sc, ATH_DBG_ANI, |
| 2825 | "Getting spur idx %d is2Ghz. %d val %x\n", |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2826 | i, is2GHz, ah->config.spurchans[i][is2GHz]); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2827 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2828 | switch (ah->config.spurmode) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2829 | case SPUR_DISABLE: |
| 2830 | break; |
| 2831 | case SPUR_ENABLE_IOCTL: |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2832 | spur_val = ah->config.spurchans[i][is2GHz]; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2833 | DPRINTF(ah->ah_sc, ATH_DBG_ANI, |
| 2834 | "Getting spur val from new loc. %d\n", spur_val); |
| 2835 | break; |
| 2836 | case SPUR_ENABLE_EEPROM: |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2837 | spur_val = EEP_DEF_SPURCHAN; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2838 | break; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2839 | } |
| 2840 | |
| 2841 | return spur_val; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2842 | |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 2843 | #undef EEP_DEF_SPURCHAN |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2844 | } |
| 2845 | |
Hannes Eder | 93f726a | 2009-02-14 11:49:48 +0000 | [diff] [blame] | 2846 | static struct eeprom_ops eep_def_ops = { |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2847 | .check_eeprom = ath9k_hw_def_check_eeprom, |
| 2848 | .get_eeprom = ath9k_hw_def_get_eeprom, |
| 2849 | .fill_eeprom = ath9k_hw_def_fill_eeprom, |
| 2850 | .get_eeprom_ver = ath9k_hw_def_get_eeprom_ver, |
| 2851 | .get_eeprom_rev = ath9k_hw_def_get_eeprom_rev, |
| 2852 | .get_num_ant_config = ath9k_hw_def_get_num_ant_config, |
| 2853 | .get_eeprom_antenna_cfg = ath9k_hw_def_get_eeprom_antenna_cfg, |
| 2854 | .set_board_values = ath9k_hw_def_set_board_values, |
| 2855 | .set_addac = ath9k_hw_def_set_addac, |
| 2856 | .set_txpower = ath9k_hw_def_set_txpower, |
| 2857 | .get_spur_channel = ath9k_hw_def_get_spur_channel |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 2858 | }; |
| 2859 | |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 2860 | |
| 2861 | static int ath9k_hw_AR9287_get_eeprom_ver(struct ath_hw *ah) |
| 2862 | { |
| 2863 | return (ah->eeprom.map9287.baseEepHeader.version >> 12) & 0xF; |
| 2864 | } |
| 2865 | |
| 2866 | static int ath9k_hw_AR9287_get_eeprom_rev(struct ath_hw *ah) |
| 2867 | { |
| 2868 | return (ah->eeprom.map9287.baseEepHeader.version) & 0xFFF; |
| 2869 | } |
| 2870 | |
| 2871 | static bool ath9k_hw_AR9287_fill_eeprom(struct ath_hw *ah) |
| 2872 | { |
Luis R. Rodriguez | 475f598 | 2009-08-03 17:31:25 -0400 | [diff] [blame] | 2873 | struct ar9287_eeprom *eep = &ah->eeprom.map9287; |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 2874 | u16 *eep_data; |
| 2875 | int addr, eep_start_loc = AR9287_EEP_START_LOC; |
| 2876 | eep_data = (u16 *)eep; |
| 2877 | if (!ath9k_hw_use_flash(ah)) { |
| 2878 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
| 2879 | "Reading from EEPROM, not flash\n"); |
| 2880 | } |
| 2881 | |
Luis R. Rodriguez | 475f598 | 2009-08-03 17:31:25 -0400 | [diff] [blame] | 2882 | for (addr = 0; addr < sizeof(struct ar9287_eeprom) / sizeof(u16); |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 2883 | addr++) { |
| 2884 | if (!ath9k_hw_nvram_read(ah, addr + eep_start_loc, eep_data)) { |
| 2885 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
| 2886 | "Unable to read eeprom region \n"); |
| 2887 | return false; |
| 2888 | } |
| 2889 | eep_data++; |
| 2890 | } |
| 2891 | return true; |
| 2892 | } |
| 2893 | static int ath9k_hw_AR9287_check_eeprom(struct ath_hw *ah) |
| 2894 | { |
Luis R. Rodriguez | 475f598 | 2009-08-03 17:31:25 -0400 | [diff] [blame] | 2895 | #define SIZE_EEPROM_87 (sizeof(struct ar9287_eeprom) / sizeof(u16)) |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 2896 | u32 sum = 0, el, integer; |
| 2897 | u16 temp, word, magic, magic2, *eepdata; |
| 2898 | int i, addr; |
| 2899 | bool need_swap = false; |
Luis R. Rodriguez | 475f598 | 2009-08-03 17:31:25 -0400 | [diff] [blame] | 2900 | struct ar9287_eeprom *eep = &ah->eeprom.map9287; |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 2901 | |
| 2902 | if (!ath9k_hw_use_flash(ah)) { |
| 2903 | if (!ath9k_hw_nvram_read |
| 2904 | (ah, AR5416_EEPROM_MAGIC_OFFSET, &magic)) { |
| 2905 | DPRINTF(ah->ah_sc, ATH_DBG_FATAL, |
| 2906 | "Reading Magic # failed\n"); |
| 2907 | return false; |
| 2908 | } |
| 2909 | |
| 2910 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
| 2911 | "Read Magic = 0x%04X\n", magic); |
| 2912 | if (magic != AR5416_EEPROM_MAGIC) { |
| 2913 | |
| 2914 | |
| 2915 | magic2 = swab16(magic); |
| 2916 | |
| 2917 | if (magic2 == AR5416_EEPROM_MAGIC) { |
| 2918 | need_swap = true; |
| 2919 | eepdata = (u16 *)(&ah->eeprom); |
| 2920 | |
| 2921 | for (addr = 0; addr < SIZE_EEPROM_87; addr++) { |
| 2922 | temp = swab16(*eepdata); |
| 2923 | *eepdata = temp; |
| 2924 | eepdata++; |
| 2925 | } |
| 2926 | } else { |
| 2927 | DPRINTF(ah->ah_sc, ATH_DBG_FATAL, |
| 2928 | "Invalid EEPROM Magic. " |
| 2929 | "endianness mismatch.\n"); |
| 2930 | return -EINVAL; } |
| 2931 | } |
| 2932 | } |
| 2933 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "need_swap = %s.\n", need_swap ? |
| 2934 | "True" : "False"); |
| 2935 | |
| 2936 | if (need_swap) |
| 2937 | el = swab16(ah->eeprom.map9287.baseEepHeader.length); |
| 2938 | else |
| 2939 | el = ah->eeprom.map9287.baseEepHeader.length; |
| 2940 | |
| 2941 | eepdata = (u16 *)(&ah->eeprom); |
| 2942 | for (i = 0; i < min(el, SIZE_EEPROM_87); i++) |
| 2943 | sum ^= *eepdata++; |
| 2944 | |
| 2945 | if (need_swap) { |
| 2946 | word = swab16(eep->baseEepHeader.length); |
| 2947 | eep->baseEepHeader.length = word; |
| 2948 | |
| 2949 | word = swab16(eep->baseEepHeader.checksum); |
| 2950 | eep->baseEepHeader.checksum = word; |
| 2951 | |
| 2952 | word = swab16(eep->baseEepHeader.version); |
| 2953 | eep->baseEepHeader.version = word; |
| 2954 | |
| 2955 | word = swab16(eep->baseEepHeader.regDmn[0]); |
| 2956 | eep->baseEepHeader.regDmn[0] = word; |
| 2957 | |
| 2958 | word = swab16(eep->baseEepHeader.regDmn[1]); |
| 2959 | eep->baseEepHeader.regDmn[1] = word; |
| 2960 | |
| 2961 | word = swab16(eep->baseEepHeader.rfSilent); |
| 2962 | eep->baseEepHeader.rfSilent = word; |
| 2963 | |
| 2964 | word = swab16(eep->baseEepHeader.blueToothOptions); |
| 2965 | eep->baseEepHeader.blueToothOptions = word; |
| 2966 | |
| 2967 | word = swab16(eep->baseEepHeader.deviceCap); |
| 2968 | eep->baseEepHeader.deviceCap = word; |
| 2969 | |
| 2970 | integer = swab32(eep->modalHeader.antCtrlCommon); |
| 2971 | eep->modalHeader.antCtrlCommon = integer; |
| 2972 | |
| 2973 | for (i = 0; i < AR9287_MAX_CHAINS; i++) { |
| 2974 | integer = swab32(eep->modalHeader.antCtrlChain[i]); |
| 2975 | eep->modalHeader.antCtrlChain[i] = integer; |
| 2976 | } |
| 2977 | |
| 2978 | for (i = 0; i < AR9287_EEPROM_MODAL_SPURS; i++) { |
| 2979 | word = swab16(eep->modalHeader.spurChans[i].spurChan); |
| 2980 | eep->modalHeader.spurChans[i].spurChan = word; |
| 2981 | } |
| 2982 | } |
| 2983 | |
| 2984 | if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR9287_EEP_VER |
| 2985 | || ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) { |
| 2986 | DPRINTF(ah->ah_sc, ATH_DBG_FATAL, |
| 2987 | "Bad EEPROM checksum 0x%x or revision 0x%04x\n", |
| 2988 | sum, ah->eep_ops->get_eeprom_ver(ah)); |
| 2989 | return -EINVAL; |
| 2990 | } |
| 2991 | |
| 2992 | return 0; |
| 2993 | #undef SIZE_EEPROM_87 |
| 2994 | } |
| 2995 | |
| 2996 | static u32 ath9k_hw_AR9287_get_eeprom(struct ath_hw *ah, |
| 2997 | enum eeprom_param param) |
| 2998 | { |
Luis R. Rodriguez | 475f598 | 2009-08-03 17:31:25 -0400 | [diff] [blame] | 2999 | struct ar9287_eeprom *eep = &ah->eeprom.map9287; |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 3000 | struct modal_eep_ar9287_header *pModal = &eep->modalHeader; |
| 3001 | struct base_eep_ar9287_header *pBase = &eep->baseEepHeader; |
| 3002 | u16 ver_minor; |
| 3003 | |
| 3004 | ver_minor = pBase->version & AR9287_EEP_VER_MINOR_MASK; |
| 3005 | switch (param) { |
| 3006 | case EEP_NFTHRESH_2: |
| 3007 | return pModal->noiseFloorThreshCh[0]; |
| 3008 | case AR_EEPROM_MAC(0): |
| 3009 | return pBase->macAddr[0] << 8 | pBase->macAddr[1]; |
| 3010 | case AR_EEPROM_MAC(1): |
| 3011 | return pBase->macAddr[2] << 8 | pBase->macAddr[3]; |
| 3012 | case AR_EEPROM_MAC(2): |
| 3013 | return pBase->macAddr[4] << 8 | pBase->macAddr[5]; |
| 3014 | case EEP_REG_0: |
| 3015 | return pBase->regDmn[0]; |
| 3016 | case EEP_REG_1: |
| 3017 | return pBase->regDmn[1]; |
| 3018 | case EEP_OP_CAP: |
| 3019 | return pBase->deviceCap; |
| 3020 | case EEP_OP_MODE: |
| 3021 | return pBase->opCapFlags; |
| 3022 | case EEP_RF_SILENT: |
| 3023 | return pBase->rfSilent; |
| 3024 | case EEP_MINOR_REV: |
| 3025 | return ver_minor; |
| 3026 | case EEP_TX_MASK: |
| 3027 | return pBase->txMask; |
| 3028 | case EEP_RX_MASK: |
| 3029 | return pBase->rxMask; |
| 3030 | case EEP_DEV_TYPE: |
| 3031 | return pBase->deviceType; |
| 3032 | case EEP_OL_PWRCTRL: |
| 3033 | return pBase->openLoopPwrCntl; |
| 3034 | case EEP_TEMPSENSE_SLOPE: |
| 3035 | if (ver_minor >= AR9287_EEP_MINOR_VER_2) |
| 3036 | return pBase->tempSensSlope; |
| 3037 | else |
| 3038 | return 0; |
| 3039 | case EEP_TEMPSENSE_SLOPE_PAL_ON: |
| 3040 | if (ver_minor >= AR9287_EEP_MINOR_VER_3) |
| 3041 | return pBase->tempSensSlopePalOn; |
| 3042 | else |
| 3043 | return 0; |
| 3044 | default: |
| 3045 | return 0; |
| 3046 | } |
| 3047 | } |
| 3048 | |
| 3049 | |
| 3050 | static void ath9k_hw_get_AR9287_gain_boundaries_pdadcs(struct ath_hw *ah, |
| 3051 | struct ath9k_channel *chan, |
| 3052 | struct cal_data_per_freq_ar9287 *pRawDataSet, |
| 3053 | u8 *bChans, u16 availPiers, |
| 3054 | u16 tPdGainOverlap, int16_t *pMinCalPower, |
| 3055 | u16 *pPdGainBoundaries, u8 *pPDADCValues, |
| 3056 | u16 numXpdGains) |
| 3057 | { |
| 3058 | #define TMP_VAL_VPD_TABLE \ |
| 3059 | ((vpdTableI[i][sizeCurrVpdTable - 1] + (ss - maxIndex + 1) * vpdStep)); |
| 3060 | int i, j, k; |
| 3061 | int16_t ss; |
| 3062 | u16 idxL = 0, idxR = 0, numPiers; |
| 3063 | u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR; |
| 3064 | u8 minPwrT4[AR9287_NUM_PD_GAINS]; |
| 3065 | u8 maxPwrT4[AR9287_NUM_PD_GAINS]; |
| 3066 | int16_t vpdStep; |
| 3067 | int16_t tmpVal; |
| 3068 | u16 sizeCurrVpdTable, maxIndex, tgtIndex; |
| 3069 | bool match; |
| 3070 | int16_t minDelta = 0; |
| 3071 | struct chan_centers centers; |
| 3072 | static u8 vpdTableL[AR5416_EEP4K_NUM_PD_GAINS] |
| 3073 | [AR5416_MAX_PWR_RANGE_IN_HALF_DB]; |
| 3074 | static u8 vpdTableR[AR5416_EEP4K_NUM_PD_GAINS] |
| 3075 | [AR5416_MAX_PWR_RANGE_IN_HALF_DB]; |
| 3076 | static u8 vpdTableI[AR5416_EEP4K_NUM_PD_GAINS] |
| 3077 | [AR5416_MAX_PWR_RANGE_IN_HALF_DB]; |
| 3078 | |
| 3079 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
| 3080 | for (numPiers = 0; numPiers < availPiers; numPiers++) { |
| 3081 | if (bChans[numPiers] == AR9287_BCHAN_UNUSED) |
| 3082 | break; |
| 3083 | } |
| 3084 | |
| 3085 | match = ath9k_hw_get_lower_upper_index( |
| 3086 | (u8)FREQ2FBIN(centers.synth_center, |
| 3087 | IS_CHAN_2GHZ(chan)), bChans, numPiers, |
| 3088 | &idxL, &idxR); |
| 3089 | |
| 3090 | if (match) { |
| 3091 | for (i = 0; i < numXpdGains; i++) { |
| 3092 | minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0]; |
| 3093 | maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4]; |
| 3094 | ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i], |
| 3095 | pRawDataSet[idxL].pwrPdg[i], |
| 3096 | pRawDataSet[idxL].vpdPdg[i], |
| 3097 | AR9287_PD_GAIN_ICEPTS, vpdTableI[i]); |
| 3098 | } |
| 3099 | } else { |
| 3100 | for (i = 0; i < numXpdGains; i++) { |
| 3101 | pVpdL = pRawDataSet[idxL].vpdPdg[i]; |
| 3102 | pPwrL = pRawDataSet[idxL].pwrPdg[i]; |
| 3103 | pVpdR = pRawDataSet[idxR].vpdPdg[i]; |
| 3104 | pPwrR = pRawDataSet[idxR].pwrPdg[i]; |
| 3105 | |
| 3106 | minPwrT4[i] = max(pPwrL[0], pPwrR[0]); |
| 3107 | |
| 3108 | maxPwrT4[i] = |
| 3109 | min(pPwrL[AR9287_PD_GAIN_ICEPTS - 1], |
| 3110 | pPwrR[AR9287_PD_GAIN_ICEPTS - 1]); |
| 3111 | |
| 3112 | ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i], |
| 3113 | pPwrL, pVpdL, |
| 3114 | AR9287_PD_GAIN_ICEPTS, |
| 3115 | vpdTableL[i]); |
| 3116 | ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i], |
| 3117 | pPwrR, pVpdR, |
| 3118 | AR9287_PD_GAIN_ICEPTS, |
| 3119 | vpdTableR[i]); |
| 3120 | |
| 3121 | for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) { |
| 3122 | vpdTableI[i][j] = |
| 3123 | (u8)(ath9k_hw_interpolate((u16) |
| 3124 | FREQ2FBIN(centers. synth_center, |
| 3125 | IS_CHAN_2GHZ(chan)), |
| 3126 | bChans[idxL], bChans[idxR], |
| 3127 | vpdTableL[i][j], vpdTableR[i][j])); |
| 3128 | } |
| 3129 | } |
| 3130 | } |
| 3131 | *pMinCalPower = (int16_t)(minPwrT4[0] / 2); |
| 3132 | |
| 3133 | k = 0; |
| 3134 | for (i = 0; i < numXpdGains; i++) { |
| 3135 | if (i == (numXpdGains - 1)) |
| 3136 | pPdGainBoundaries[i] = (u16)(maxPwrT4[i] / 2); |
| 3137 | else |
| 3138 | pPdGainBoundaries[i] = (u16)((maxPwrT4[i] + |
| 3139 | minPwrT4[i+1]) / 4); |
| 3140 | |
| 3141 | pPdGainBoundaries[i] = min((u16)AR5416_MAX_RATE_POWER, |
| 3142 | pPdGainBoundaries[i]); |
| 3143 | |
| 3144 | |
| 3145 | if ((i == 0) && !AR_SREV_5416_20_OR_LATER(ah)) { |
| 3146 | minDelta = pPdGainBoundaries[0] - 23; |
| 3147 | pPdGainBoundaries[0] = 23; |
| 3148 | } else |
| 3149 | minDelta = 0; |
| 3150 | |
| 3151 | if (i == 0) { |
| 3152 | if (AR_SREV_9280_10_OR_LATER(ah)) |
| 3153 | ss = (int16_t)(0 - (minPwrT4[i] / 2)); |
| 3154 | else |
| 3155 | ss = 0; |
| 3156 | } else |
| 3157 | ss = (int16_t)((pPdGainBoundaries[i-1] - |
| 3158 | (minPwrT4[i] / 2)) - |
| 3159 | tPdGainOverlap + 1 + minDelta); |
| 3160 | |
| 3161 | vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]); |
| 3162 | vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep); |
| 3163 | while ((ss < 0) && (k < (AR9287_NUM_PDADC_VALUES - 1))) { |
| 3164 | tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep); |
| 3165 | pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal); |
| 3166 | ss++; |
| 3167 | } |
| 3168 | |
| 3169 | sizeCurrVpdTable = (u8)((maxPwrT4[i] - minPwrT4[i]) / 2 + 1); |
| 3170 | tgtIndex = (u8)(pPdGainBoundaries[i] + |
| 3171 | tPdGainOverlap - (minPwrT4[i] / 2)); |
| 3172 | maxIndex = (tgtIndex < sizeCurrVpdTable) ? |
| 3173 | tgtIndex : sizeCurrVpdTable; |
| 3174 | |
| 3175 | while ((ss < maxIndex) && (k < (AR9287_NUM_PDADC_VALUES - 1))) |
| 3176 | pPDADCValues[k++] = vpdTableI[i][ss++]; |
| 3177 | |
| 3178 | vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] - |
| 3179 | vpdTableI[i][sizeCurrVpdTable - 2]); |
| 3180 | vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep); |
| 3181 | if (tgtIndex > maxIndex) { |
| 3182 | while ((ss <= tgtIndex) && |
| 3183 | (k < (AR9287_NUM_PDADC_VALUES - 1))) { |
| 3184 | tmpVal = (int16_t) TMP_VAL_VPD_TABLE; |
| 3185 | pPDADCValues[k++] = (u8)((tmpVal > 255) ? |
| 3186 | 255 : tmpVal); |
| 3187 | ss++; |
| 3188 | } |
| 3189 | } |
| 3190 | } |
| 3191 | |
| 3192 | while (i < AR9287_PD_GAINS_IN_MASK) { |
| 3193 | pPdGainBoundaries[i] = pPdGainBoundaries[i-1]; |
| 3194 | i++; |
| 3195 | } |
| 3196 | |
| 3197 | while (k < AR9287_NUM_PDADC_VALUES) { |
| 3198 | pPDADCValues[k] = pPDADCValues[k-1]; |
| 3199 | k++; |
| 3200 | } |
| 3201 | |
| 3202 | #undef TMP_VAL_VPD_TABLE |
| 3203 | } |
| 3204 | |
| 3205 | static void ar9287_eeprom_get_tx_gain_index(struct ath_hw *ah, |
| 3206 | struct ath9k_channel *chan, |
| 3207 | struct cal_data_op_loop_ar9287 *pRawDatasetOpLoop, |
| 3208 | u8 *pCalChans, u16 availPiers, |
| 3209 | int8_t *pPwr) |
| 3210 | { |
| 3211 | u8 pcdac, i = 0; |
| 3212 | u16 idxL = 0, idxR = 0, numPiers; |
| 3213 | bool match; |
| 3214 | struct chan_centers centers; |
| 3215 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
| 3216 | for (numPiers = 0; numPiers < availPiers; numPiers++) { |
| 3217 | if (pCalChans[numPiers] == AR9287_BCHAN_UNUSED) |
| 3218 | break; |
| 3219 | } |
| 3220 | |
| 3221 | match = ath9k_hw_get_lower_upper_index( |
| 3222 | (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)), |
| 3223 | pCalChans, numPiers, |
| 3224 | &idxL, &idxR); |
| 3225 | |
| 3226 | if (match) { |
| 3227 | pcdac = pRawDatasetOpLoop[idxL].pcdac[0][0]; |
| 3228 | *pPwr = pRawDatasetOpLoop[idxL].pwrPdg[0][0]; |
| 3229 | } else { |
| 3230 | pcdac = pRawDatasetOpLoop[idxR].pcdac[0][0]; |
| 3231 | *pPwr = (pRawDatasetOpLoop[idxL].pwrPdg[0][0] + |
| 3232 | pRawDatasetOpLoop[idxR].pwrPdg[0][0])/2; |
| 3233 | } |
| 3234 | |
| 3235 | while ((pcdac > ah->originalGain[i]) && |
| 3236 | (i < (AR9280_TX_GAIN_TABLE_SIZE - 1))) |
| 3237 | i++; |
| 3238 | } |
| 3239 | |
| 3240 | static void ar9287_eeprom_olpc_set_pdadcs(struct ath_hw *ah, |
| 3241 | int32_t txPower, u16 chain) |
| 3242 | { |
| 3243 | u32 tmpVal; |
| 3244 | u32 a; |
| 3245 | |
| 3246 | tmpVal = REG_READ(ah, 0xa270); |
| 3247 | tmpVal = tmpVal & 0xFCFFFFFF; |
| 3248 | tmpVal = tmpVal | (0x3 << 24); |
| 3249 | REG_WRITE(ah, 0xa270, tmpVal); |
| 3250 | |
| 3251 | tmpVal = REG_READ(ah, 0xb270); |
| 3252 | tmpVal = tmpVal & 0xFCFFFFFF; |
| 3253 | tmpVal = tmpVal | (0x3 << 24); |
| 3254 | REG_WRITE(ah, 0xb270, tmpVal); |
| 3255 | |
| 3256 | if (chain == 0) { |
| 3257 | tmpVal = REG_READ(ah, 0xa398); |
| 3258 | tmpVal = tmpVal & 0xff00ffff; |
| 3259 | a = (txPower)&0xff; |
| 3260 | tmpVal = tmpVal | (a << 16); |
| 3261 | REG_WRITE(ah, 0xa398, tmpVal); |
| 3262 | } |
| 3263 | |
| 3264 | if (chain == 1) { |
| 3265 | tmpVal = REG_READ(ah, 0xb398); |
| 3266 | tmpVal = tmpVal & 0xff00ffff; |
| 3267 | a = (txPower)&0xff; |
| 3268 | tmpVal = tmpVal | (a << 16); |
| 3269 | REG_WRITE(ah, 0xb398, tmpVal); |
| 3270 | } |
| 3271 | } |
| 3272 | |
| 3273 | |
| 3274 | static void ath9k_hw_set_AR9287_power_cal_table(struct ath_hw *ah, |
| 3275 | struct ath9k_channel *chan, int16_t *pTxPowerIndexOffset) |
| 3276 | { |
| 3277 | struct cal_data_per_freq_ar9287 *pRawDataset; |
| 3278 | struct cal_data_op_loop_ar9287 *pRawDatasetOpenLoop; |
| 3279 | u8 *pCalBChans = NULL; |
| 3280 | u16 pdGainOverlap_t2; |
| 3281 | u8 pdadcValues[AR9287_NUM_PDADC_VALUES]; |
| 3282 | u16 gainBoundaries[AR9287_PD_GAINS_IN_MASK]; |
| 3283 | u16 numPiers = 0, i, j; |
| 3284 | int16_t tMinCalPower; |
| 3285 | u16 numXpdGain, xpdMask; |
| 3286 | u16 xpdGainValues[AR9287_NUM_PD_GAINS] = {0, 0, 0, 0}; |
| 3287 | u32 reg32, regOffset, regChainOffset; |
| 3288 | int16_t modalIdx, diff = 0; |
Luis R. Rodriguez | 475f598 | 2009-08-03 17:31:25 -0400 | [diff] [blame] | 3289 | struct ar9287_eeprom *pEepData = &ah->eeprom.map9287; |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 3290 | modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0; |
| 3291 | xpdMask = pEepData->modalHeader.xpdGain; |
| 3292 | if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >= |
| 3293 | AR9287_EEP_MINOR_VER_2) |
| 3294 | pdGainOverlap_t2 = pEepData->modalHeader.pdGainOverlap; |
| 3295 | else |
| 3296 | pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5), |
| 3297 | AR_PHY_TPCRG5_PD_GAIN_OVERLAP)); |
| 3298 | |
| 3299 | if (IS_CHAN_2GHZ(chan)) { |
| 3300 | pCalBChans = pEepData->calFreqPier2G; |
| 3301 | numPiers = AR9287_NUM_2G_CAL_PIERS; |
| 3302 | if (ath9k_hw_AR9287_get_eeprom(ah, EEP_OL_PWRCTRL)) { |
| 3303 | pRawDatasetOpenLoop = |
| 3304 | (struct cal_data_op_loop_ar9287 *) |
| 3305 | pEepData->calPierData2G[0]; |
| 3306 | ah->initPDADC = pRawDatasetOpenLoop->vpdPdg[0][0]; |
| 3307 | } |
| 3308 | } |
| 3309 | |
| 3310 | numXpdGain = 0; |
| 3311 | for (i = 1; i <= AR9287_PD_GAINS_IN_MASK; i++) { |
| 3312 | if ((xpdMask >> (AR9287_PD_GAINS_IN_MASK - i)) & 1) { |
| 3313 | if (numXpdGain >= AR9287_NUM_PD_GAINS) |
| 3314 | break; |
| 3315 | xpdGainValues[numXpdGain] = |
| 3316 | (u16)(AR9287_PD_GAINS_IN_MASK-i); |
| 3317 | numXpdGain++; |
| 3318 | } |
| 3319 | } |
| 3320 | |
| 3321 | REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN, |
| 3322 | (numXpdGain - 1) & 0x3); |
| 3323 | REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1, |
| 3324 | xpdGainValues[0]); |
| 3325 | REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2, |
| 3326 | xpdGainValues[1]); |
| 3327 | REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3, |
| 3328 | xpdGainValues[2]); |
| 3329 | |
| 3330 | for (i = 0; i < AR9287_MAX_CHAINS; i++) { |
| 3331 | regChainOffset = i * 0x1000; |
| 3332 | if (pEepData->baseEepHeader.txMask & (1 << i)) { |
| 3333 | pRawDatasetOpenLoop = (struct cal_data_op_loop_ar9287 *) |
| 3334 | pEepData->calPierData2G[i]; |
| 3335 | if (ath9k_hw_AR9287_get_eeprom(ah, EEP_OL_PWRCTRL)) { |
| 3336 | int8_t txPower; |
| 3337 | ar9287_eeprom_get_tx_gain_index(ah, chan, |
| 3338 | pRawDatasetOpenLoop, |
| 3339 | pCalBChans, numPiers, |
| 3340 | &txPower); |
| 3341 | ar9287_eeprom_olpc_set_pdadcs(ah, txPower, i); |
| 3342 | } else { |
| 3343 | pRawDataset = |
| 3344 | (struct cal_data_per_freq_ar9287 *) |
| 3345 | pEepData->calPierData2G[i]; |
| 3346 | ath9k_hw_get_AR9287_gain_boundaries_pdadcs( |
| 3347 | ah, chan, pRawDataset, |
| 3348 | pCalBChans, numPiers, |
| 3349 | pdGainOverlap_t2, |
| 3350 | &tMinCalPower, gainBoundaries, |
| 3351 | pdadcValues, numXpdGain); |
| 3352 | } |
| 3353 | |
| 3354 | if (i == 0) { |
| 3355 | if (!ath9k_hw_AR9287_get_eeprom( |
| 3356 | ah, EEP_OL_PWRCTRL)) { |
| 3357 | REG_WRITE(ah, AR_PHY_TPCRG5 + |
| 3358 | regChainOffset, |
| 3359 | SM(pdGainOverlap_t2, |
| 3360 | AR_PHY_TPCRG5_PD_GAIN_OVERLAP) | |
| 3361 | SM(gainBoundaries[0], |
| 3362 | AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1) |
| 3363 | | SM(gainBoundaries[1], |
| 3364 | AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2) |
| 3365 | | SM(gainBoundaries[2], |
| 3366 | AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3) |
| 3367 | | SM(gainBoundaries[3], |
| 3368 | AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4)); |
| 3369 | } |
| 3370 | } |
| 3371 | |
| 3372 | if ((int32_t)AR9287_PWR_TABLE_OFFSET_DB != |
| 3373 | pEepData->baseEepHeader.pwrTableOffset) { |
| 3374 | diff = (u16) |
| 3375 | (pEepData->baseEepHeader.pwrTableOffset |
| 3376 | - (int32_t)AR9287_PWR_TABLE_OFFSET_DB); |
| 3377 | diff *= 2; |
| 3378 | |
| 3379 | for (j = 0; |
| 3380 | j < ((u16)AR9287_NUM_PDADC_VALUES-diff); |
| 3381 | j++) |
| 3382 | pdadcValues[j] = pdadcValues[j+diff]; |
| 3383 | |
| 3384 | for (j = (u16)(AR9287_NUM_PDADC_VALUES-diff); |
| 3385 | j < AR9287_NUM_PDADC_VALUES; j++) |
| 3386 | pdadcValues[j] = |
| 3387 | pdadcValues[ |
| 3388 | AR9287_NUM_PDADC_VALUES-diff]; |
| 3389 | } |
| 3390 | if (!ath9k_hw_AR9287_get_eeprom(ah, EEP_OL_PWRCTRL)) { |
| 3391 | regOffset = AR_PHY_BASE + (672 << 2) + |
| 3392 | regChainOffset; |
| 3393 | for (j = 0; j < 32; j++) { |
| 3394 | reg32 = ((pdadcValues[4*j + 0] |
| 3395 | & 0xFF) << 0) | |
| 3396 | ((pdadcValues[4*j + 1] |
| 3397 | & 0xFF) << 8) | |
| 3398 | ((pdadcValues[4*j + 2] |
| 3399 | & 0xFF) << 16) | |
| 3400 | ((pdadcValues[4*j + 3] |
| 3401 | & 0xFF) << 24) ; |
| 3402 | REG_WRITE(ah, regOffset, reg32); |
| 3403 | |
| 3404 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
| 3405 | "PDADC (%d,%4x): %4.4x %8.8x\n", |
| 3406 | i, regChainOffset, regOffset, |
| 3407 | reg32); |
| 3408 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
| 3409 | "PDADC: Chain %d | " |
| 3410 | "PDADC %3d Value %3d | " |
| 3411 | "PDADC %3d Value %3d | " |
| 3412 | "PDADC %3d Value %3d | " |
| 3413 | "PDADC %3d Value %3d |\n", |
| 3414 | i, 4 * j, pdadcValues[4 * j], |
| 3415 | 4 * j + 1, |
| 3416 | pdadcValues[4 * j + 1], |
| 3417 | 4 * j + 2, |
| 3418 | pdadcValues[4 * j + 2], |
| 3419 | 4 * j + 3, |
| 3420 | pdadcValues[4 * j + 3]); |
| 3421 | |
| 3422 | regOffset += 4; |
| 3423 | } |
| 3424 | } |
| 3425 | } |
| 3426 | } |
| 3427 | |
| 3428 | *pTxPowerIndexOffset = 0; |
| 3429 | } |
| 3430 | |
| 3431 | |
| 3432 | static void ath9k_hw_set_AR9287_power_per_rate_table(struct ath_hw *ah, |
| 3433 | struct ath9k_channel *chan, int16_t *ratesArray, u16 cfgCtl, |
| 3434 | u16 AntennaReduction, u16 twiceMaxRegulatoryPower, |
| 3435 | u16 powerLimit) |
| 3436 | { |
| 3437 | #define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6 |
| 3438 | #define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10 |
| 3439 | |
| 3440 | u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER; |
| 3441 | static const u16 tpScaleReductionTable[5] = { 0, 3, 6, 9, |
| 3442 | AR5416_MAX_RATE_POWER }; |
| 3443 | int i; |
| 3444 | int16_t twiceLargestAntenna; |
| 3445 | struct cal_ctl_data_ar9287 *rep; |
| 3446 | struct cal_target_power_leg targetPowerOfdm = {0, {0, 0, 0, 0} }, |
| 3447 | targetPowerCck = {0, {0, 0, 0, 0} }; |
| 3448 | struct cal_target_power_leg targetPowerOfdmExt = {0, {0, 0, 0, 0} }, |
| 3449 | targetPowerCckExt = {0, {0, 0, 0, 0} }; |
| 3450 | struct cal_target_power_ht targetPowerHt20, |
| 3451 | targetPowerHt40 = {0, {0, 0, 0, 0} }; |
| 3452 | u16 scaledPower = 0, minCtlPower, maxRegAllowedPower; |
| 3453 | u16 ctlModesFor11g[] = {CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, |
| 3454 | CTL_11G_EXT, CTL_2GHT40}; |
| 3455 | u16 numCtlModes = 0, *pCtlMode = NULL, ctlMode, freq; |
| 3456 | struct chan_centers centers; |
| 3457 | int tx_chainmask; |
| 3458 | u16 twiceMinEdgePower; |
Luis R. Rodriguez | 475f598 | 2009-08-03 17:31:25 -0400 | [diff] [blame] | 3459 | struct ar9287_eeprom *pEepData = &ah->eeprom.map9287; |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 3460 | tx_chainmask = ah->txchainmask; |
| 3461 | |
| 3462 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
| 3463 | |
| 3464 | twiceLargestAntenna = max(pEepData->modalHeader.antennaGainCh[0], |
| 3465 | pEepData->modalHeader.antennaGainCh[1]); |
| 3466 | |
| 3467 | twiceLargestAntenna = (int16_t)min((AntennaReduction) - |
| 3468 | twiceLargestAntenna, 0); |
| 3469 | |
| 3470 | maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna; |
| 3471 | if (ah->regulatory.tp_scale != ATH9K_TP_SCALE_MAX) |
| 3472 | maxRegAllowedPower -= |
| 3473 | (tpScaleReductionTable[(ah->regulatory.tp_scale)] * 2); |
| 3474 | |
| 3475 | scaledPower = min(powerLimit, maxRegAllowedPower); |
| 3476 | |
| 3477 | switch (ar5416_get_ntxchains(tx_chainmask)) { |
| 3478 | case 1: |
| 3479 | break; |
| 3480 | case 2: |
| 3481 | scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN; |
| 3482 | break; |
| 3483 | case 3: |
| 3484 | scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN; |
| 3485 | break; |
| 3486 | } |
| 3487 | scaledPower = max((u16)0, scaledPower); |
| 3488 | |
| 3489 | if (IS_CHAN_2GHZ(chan)) { |
| 3490 | numCtlModes = ARRAY_SIZE(ctlModesFor11g) - |
| 3491 | SUB_NUM_CTL_MODES_AT_2G_40; |
| 3492 | pCtlMode = ctlModesFor11g; |
| 3493 | |
| 3494 | ath9k_hw_get_legacy_target_powers(ah, chan, |
| 3495 | pEepData->calTargetPowerCck, |
| 3496 | AR9287_NUM_2G_CCK_TARGET_POWERS, |
| 3497 | &targetPowerCck, 4, false); |
| 3498 | ath9k_hw_get_legacy_target_powers(ah, chan, |
| 3499 | pEepData->calTargetPower2G, |
| 3500 | AR9287_NUM_2G_20_TARGET_POWERS, |
| 3501 | &targetPowerOfdm, 4, false); |
| 3502 | ath9k_hw_get_target_powers(ah, chan, |
| 3503 | pEepData->calTargetPower2GHT20, |
| 3504 | AR9287_NUM_2G_20_TARGET_POWERS, |
| 3505 | &targetPowerHt20, 8, false); |
| 3506 | |
| 3507 | if (IS_CHAN_HT40(chan)) { |
| 3508 | numCtlModes = ARRAY_SIZE(ctlModesFor11g); |
| 3509 | ath9k_hw_get_target_powers(ah, chan, |
| 3510 | pEepData->calTargetPower2GHT40, |
| 3511 | AR9287_NUM_2G_40_TARGET_POWERS, |
| 3512 | &targetPowerHt40, 8, true); |
| 3513 | ath9k_hw_get_legacy_target_powers(ah, chan, |
| 3514 | pEepData->calTargetPowerCck, |
| 3515 | AR9287_NUM_2G_CCK_TARGET_POWERS, |
| 3516 | &targetPowerCckExt, 4, true); |
| 3517 | ath9k_hw_get_legacy_target_powers(ah, chan, |
| 3518 | pEepData->calTargetPower2G, |
| 3519 | AR9287_NUM_2G_20_TARGET_POWERS, |
| 3520 | &targetPowerOfdmExt, 4, true); |
| 3521 | } |
| 3522 | } |
| 3523 | |
| 3524 | for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) { |
| 3525 | |
| 3526 | bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) || |
| 3527 | (pCtlMode[ctlMode] == CTL_2GHT40); |
| 3528 | if (isHt40CtlMode) |
| 3529 | freq = centers.synth_center; |
| 3530 | else if (pCtlMode[ctlMode] & EXT_ADDITIVE) |
| 3531 | freq = centers.ext_center; |
| 3532 | else |
| 3533 | freq = centers.ctl_center; |
| 3534 | |
| 3535 | |
| 3536 | if (ah->eep_ops->get_eeprom_ver(ah) == 14 && |
| 3537 | ah->eep_ops->get_eeprom_rev(ah) <= 2) |
| 3538 | twiceMaxEdgePower = AR5416_MAX_RATE_POWER; |
| 3539 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
| 3540 | "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d," |
| 3541 | "EXT_ADDITIVE %d\n", ctlMode, numCtlModes, |
| 3542 | isHt40CtlMode, (pCtlMode[ctlMode] & EXT_ADDITIVE)); |
| 3543 | for (i = 0; (i < AR9287_NUM_CTLS) |
| 3544 | && pEepData->ctlIndex[i]; i++) { |
| 3545 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
| 3546 | "LOOP-Ctlidx %d: cfgCtl 0x%2.2x" |
| 3547 | "pCtlMode 0x%2.2x ctlIndex 0x%2.2x" |
| 3548 | "chan %d chanctl=xxxx\n", |
| 3549 | i, cfgCtl, pCtlMode[ctlMode], |
| 3550 | pEepData->ctlIndex[i], chan->channel); |
| 3551 | |
| 3552 | if ((((cfgCtl & ~CTL_MODE_M) | |
| 3553 | (pCtlMode[ctlMode] & CTL_MODE_M)) == |
| 3554 | pEepData->ctlIndex[i]) || |
| 3555 | (((cfgCtl & ~CTL_MODE_M) | |
| 3556 | (pCtlMode[ctlMode] & CTL_MODE_M)) == |
| 3557 | ((pEepData->ctlIndex[i] & |
| 3558 | CTL_MODE_M) | SD_NO_CTL))) { |
| 3559 | |
| 3560 | rep = &(pEepData->ctlData[i]); |
| 3561 | twiceMinEdgePower = ath9k_hw_get_max_edge_power( |
| 3562 | freq, |
| 3563 | rep->ctlEdges[ar5416_get_ntxchains( |
| 3564 | tx_chainmask) - 1], |
| 3565 | IS_CHAN_2GHZ(chan), AR5416_NUM_BAND_EDGES); |
| 3566 | |
| 3567 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
| 3568 | "MATCH-EE_IDX %d: ch %d is2 %d" |
| 3569 | "2xMinEdge %d chainmask %d chains %d\n", |
| 3570 | i, freq, IS_CHAN_2GHZ(chan), |
| 3571 | twiceMinEdgePower, tx_chainmask, |
| 3572 | ar5416_get_ntxchains(tx_chainmask)); |
| 3573 | |
| 3574 | if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) |
| 3575 | twiceMaxEdgePower = min( |
| 3576 | twiceMaxEdgePower, |
| 3577 | twiceMinEdgePower); |
| 3578 | else { |
| 3579 | twiceMaxEdgePower = twiceMinEdgePower; |
| 3580 | break; |
| 3581 | } |
| 3582 | } |
| 3583 | } |
| 3584 | |
| 3585 | minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower); |
| 3586 | |
| 3587 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
| 3588 | "SEL-Min ctlMode %d pCtlMode %d 2xMaxEdge %d" |
| 3589 | "sP %d minCtlPwr %d\n", |
| 3590 | ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower, |
| 3591 | scaledPower, minCtlPower); |
| 3592 | |
| 3593 | |
| 3594 | switch (pCtlMode[ctlMode]) { |
| 3595 | |
| 3596 | case CTL_11B: |
| 3597 | for (i = 0; |
| 3598 | i < ARRAY_SIZE(targetPowerCck.tPow2x); |
| 3599 | i++) { |
| 3600 | targetPowerCck.tPow2x[i] = (u8)min( |
| 3601 | (u16)targetPowerCck.tPow2x[i], |
| 3602 | minCtlPower); |
| 3603 | } |
| 3604 | break; |
| 3605 | case CTL_11A: |
| 3606 | case CTL_11G: |
| 3607 | for (i = 0; |
| 3608 | i < ARRAY_SIZE(targetPowerOfdm.tPow2x); |
| 3609 | i++) { |
| 3610 | targetPowerOfdm.tPow2x[i] = (u8)min( |
| 3611 | (u16)targetPowerOfdm.tPow2x[i], |
| 3612 | minCtlPower); |
| 3613 | } |
| 3614 | break; |
| 3615 | case CTL_5GHT20: |
| 3616 | case CTL_2GHT20: |
| 3617 | for (i = 0; |
| 3618 | i < ARRAY_SIZE(targetPowerHt20.tPow2x); |
| 3619 | i++) { |
| 3620 | targetPowerHt20.tPow2x[i] = (u8)min( |
| 3621 | (u16)targetPowerHt20.tPow2x[i], |
| 3622 | minCtlPower); |
| 3623 | } |
| 3624 | break; |
| 3625 | case CTL_11B_EXT: |
| 3626 | targetPowerCckExt.tPow2x[0] = (u8)min( |
| 3627 | (u16)targetPowerCckExt.tPow2x[0], |
| 3628 | minCtlPower); |
| 3629 | break; |
| 3630 | case CTL_11A_EXT: |
| 3631 | case CTL_11G_EXT: |
| 3632 | targetPowerOfdmExt.tPow2x[0] = (u8)min( |
| 3633 | (u16)targetPowerOfdmExt.tPow2x[0], |
| 3634 | minCtlPower); |
| 3635 | break; |
| 3636 | case CTL_5GHT40: |
| 3637 | case CTL_2GHT40: |
| 3638 | for (i = 0; |
| 3639 | i < ARRAY_SIZE(targetPowerHt40.tPow2x); |
| 3640 | i++) { |
| 3641 | targetPowerHt40.tPow2x[i] = (u8)min( |
| 3642 | (u16)targetPowerHt40.tPow2x[i], |
| 3643 | minCtlPower); |
| 3644 | } |
| 3645 | break; |
| 3646 | default: |
| 3647 | break; |
| 3648 | } |
| 3649 | } |
| 3650 | |
| 3651 | ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] = |
| 3652 | ratesArray[rate18mb] = ratesArray[rate24mb] = |
| 3653 | targetPowerOfdm.tPow2x[0]; |
| 3654 | ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1]; |
| 3655 | ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2]; |
| 3656 | ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3]; |
| 3657 | ratesArray[rateXr] = targetPowerOfdm.tPow2x[0]; |
| 3658 | |
| 3659 | for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) |
| 3660 | ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i]; |
| 3661 | |
| 3662 | if (IS_CHAN_2GHZ(chan)) { |
| 3663 | ratesArray[rate1l] = targetPowerCck.tPow2x[0]; |
| 3664 | ratesArray[rate2s] = ratesArray[rate2l] = |
| 3665 | targetPowerCck.tPow2x[1]; |
| 3666 | ratesArray[rate5_5s] = ratesArray[rate5_5l] = |
| 3667 | targetPowerCck.tPow2x[2]; |
| 3668 | ratesArray[rate11s] = ratesArray[rate11l] = |
| 3669 | targetPowerCck.tPow2x[3]; |
| 3670 | } |
| 3671 | if (IS_CHAN_HT40(chan)) { |
| 3672 | for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) |
| 3673 | ratesArray[rateHt40_0 + i] = targetPowerHt40.tPow2x[i]; |
| 3674 | |
| 3675 | ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0]; |
| 3676 | ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0]; |
| 3677 | ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0]; |
| 3678 | if (IS_CHAN_2GHZ(chan)) |
| 3679 | ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0]; |
| 3680 | } |
| 3681 | #undef REDUCE_SCALED_POWER_BY_TWO_CHAIN |
| 3682 | #undef REDUCE_SCALED_POWER_BY_THREE_CHAIN |
| 3683 | } |
| 3684 | |
| 3685 | static void ath9k_hw_AR9287_set_txpower(struct ath_hw *ah, |
| 3686 | struct ath9k_channel *chan, u16 cfgCtl, |
| 3687 | u8 twiceAntennaReduction, u8 twiceMaxRegulatoryPower, |
| 3688 | u8 powerLimit) |
| 3689 | { |
| 3690 | #define INCREASE_MAXPOW_BY_TWO_CHAIN 6 |
| 3691 | #define INCREASE_MAXPOW_BY_THREE_CHAIN 10 |
Luis R. Rodriguez | 475f598 | 2009-08-03 17:31:25 -0400 | [diff] [blame] | 3692 | struct ar9287_eeprom *pEepData = &ah->eeprom.map9287; |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 3693 | struct modal_eep_ar9287_header *pModal = &pEepData->modalHeader; |
| 3694 | int16_t ratesArray[Ar5416RateSize]; |
| 3695 | int16_t txPowerIndexOffset = 0; |
| 3696 | u8 ht40PowerIncForPdadc = 2; |
| 3697 | int i; |
| 3698 | memset(ratesArray, 0, sizeof(ratesArray)); |
| 3699 | |
| 3700 | if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >= |
| 3701 | AR9287_EEP_MINOR_VER_2) |
| 3702 | ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc; |
| 3703 | |
| 3704 | ath9k_hw_set_AR9287_power_per_rate_table(ah, chan, |
| 3705 | &ratesArray[0], cfgCtl, |
| 3706 | twiceAntennaReduction, |
| 3707 | twiceMaxRegulatoryPower, |
| 3708 | powerLimit); |
| 3709 | |
| 3710 | |
| 3711 | ath9k_hw_set_AR9287_power_cal_table(ah, chan, &txPowerIndexOffset); |
| 3712 | |
| 3713 | for (i = 0; i < ARRAY_SIZE(ratesArray); i++) { |
| 3714 | ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]); |
| 3715 | if (ratesArray[i] > AR9287_MAX_RATE_POWER) |
| 3716 | ratesArray[i] = AR9287_MAX_RATE_POWER; |
| 3717 | } |
| 3718 | |
| 3719 | if (AR_SREV_9280_10_OR_LATER(ah)) { |
| 3720 | for (i = 0; i < Ar5416RateSize; i++) |
| 3721 | ratesArray[i] -= AR9287_PWR_TABLE_OFFSET_DB * 2; |
| 3722 | } |
| 3723 | |
| 3724 | |
| 3725 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE1, |
| 3726 | ATH9K_POW_SM(ratesArray[rate18mb], 24) |
| 3727 | | ATH9K_POW_SM(ratesArray[rate12mb], 16) |
| 3728 | | ATH9K_POW_SM(ratesArray[rate9mb], 8) |
| 3729 | | ATH9K_POW_SM(ratesArray[rate6mb], 0) |
| 3730 | ); |
| 3731 | |
| 3732 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE2, |
| 3733 | ATH9K_POW_SM(ratesArray[rate54mb], 24) |
| 3734 | | ATH9K_POW_SM(ratesArray[rate48mb], 16) |
| 3735 | | ATH9K_POW_SM(ratesArray[rate36mb], 8) |
| 3736 | | ATH9K_POW_SM(ratesArray[rate24mb], 0) |
| 3737 | ); |
| 3738 | |
| 3739 | if (IS_CHAN_2GHZ(chan)) { |
| 3740 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE3, |
| 3741 | ATH9K_POW_SM(ratesArray[rate2s], 24) |
| 3742 | | ATH9K_POW_SM(ratesArray[rate2l], 16) |
| 3743 | | ATH9K_POW_SM(ratesArray[rateXr], 8) |
| 3744 | | ATH9K_POW_SM(ratesArray[rate1l], 0) |
| 3745 | ); |
| 3746 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE4, |
| 3747 | ATH9K_POW_SM(ratesArray[rate11s], 24) |
| 3748 | | ATH9K_POW_SM(ratesArray[rate11l], 16) |
| 3749 | | ATH9K_POW_SM(ratesArray[rate5_5s], 8) |
| 3750 | | ATH9K_POW_SM(ratesArray[rate5_5l], 0) |
| 3751 | ); |
| 3752 | } |
| 3753 | |
| 3754 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE5, |
| 3755 | ATH9K_POW_SM(ratesArray[rateHt20_3], 24) |
| 3756 | | ATH9K_POW_SM(ratesArray[rateHt20_2], 16) |
| 3757 | | ATH9K_POW_SM(ratesArray[rateHt20_1], 8) |
| 3758 | | ATH9K_POW_SM(ratesArray[rateHt20_0], 0) |
| 3759 | ); |
| 3760 | |
| 3761 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE6, |
| 3762 | ATH9K_POW_SM(ratesArray[rateHt20_7], 24) |
| 3763 | | ATH9K_POW_SM(ratesArray[rateHt20_6], 16) |
| 3764 | | ATH9K_POW_SM(ratesArray[rateHt20_5], 8) |
| 3765 | | ATH9K_POW_SM(ratesArray[rateHt20_4], 0) |
| 3766 | ); |
| 3767 | |
| 3768 | if (IS_CHAN_HT40(chan)) { |
| 3769 | if (ath9k_hw_AR9287_get_eeprom(ah, EEP_OL_PWRCTRL)) { |
| 3770 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE7, |
| 3771 | ATH9K_POW_SM(ratesArray[rateHt40_3], 24) |
| 3772 | | ATH9K_POW_SM(ratesArray[rateHt40_2], 16) |
| 3773 | | ATH9K_POW_SM(ratesArray[rateHt40_1], 8) |
| 3774 | | ATH9K_POW_SM(ratesArray[rateHt40_0], 0) |
| 3775 | ); |
| 3776 | |
| 3777 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE8, |
| 3778 | ATH9K_POW_SM(ratesArray[rateHt40_7], 24) |
| 3779 | | ATH9K_POW_SM(ratesArray[rateHt40_6], 16) |
| 3780 | | ATH9K_POW_SM(ratesArray[rateHt40_5], 8) |
| 3781 | | ATH9K_POW_SM(ratesArray[rateHt40_4], 0) |
| 3782 | ); |
| 3783 | } else { |
| 3784 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE7, |
| 3785 | ATH9K_POW_SM(ratesArray[rateHt40_3] + |
| 3786 | ht40PowerIncForPdadc, 24) |
| 3787 | | ATH9K_POW_SM(ratesArray[rateHt40_2] + |
| 3788 | ht40PowerIncForPdadc, 16) |
| 3789 | | ATH9K_POW_SM(ratesArray[rateHt40_1] + |
| 3790 | ht40PowerIncForPdadc, 8) |
| 3791 | | ATH9K_POW_SM(ratesArray[rateHt40_0] + |
| 3792 | ht40PowerIncForPdadc, 0) |
| 3793 | ); |
| 3794 | |
| 3795 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE8, |
| 3796 | ATH9K_POW_SM(ratesArray[rateHt40_7] + |
| 3797 | ht40PowerIncForPdadc, 24) |
| 3798 | | ATH9K_POW_SM(ratesArray[rateHt40_6] + |
| 3799 | ht40PowerIncForPdadc, 16) |
| 3800 | | ATH9K_POW_SM(ratesArray[rateHt40_5] + |
| 3801 | ht40PowerIncForPdadc, 8) |
| 3802 | | ATH9K_POW_SM(ratesArray[rateHt40_4] + |
| 3803 | ht40PowerIncForPdadc, 0) |
| 3804 | ); |
| 3805 | |
| 3806 | } |
| 3807 | |
| 3808 | REG_WRITE(ah, AR_PHY_POWER_TX_RATE9, |
| 3809 | ATH9K_POW_SM(ratesArray[rateExtOfdm], 24) |
| 3810 | | ATH9K_POW_SM(ratesArray[rateExtCck], 16) |
| 3811 | | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8) |
| 3812 | | ATH9K_POW_SM(ratesArray[rateDupCck], 0) |
| 3813 | ); |
| 3814 | } |
| 3815 | |
| 3816 | |
| 3817 | if (IS_CHAN_2GHZ(chan)) |
| 3818 | i = rate1l; |
| 3819 | else |
| 3820 | i = rate6mb; |
| 3821 | |
| 3822 | if (AR_SREV_9280_10_OR_LATER(ah)) |
| 3823 | ah->regulatory.max_power_level = |
| 3824 | ratesArray[i] + AR9287_PWR_TABLE_OFFSET_DB * 2; |
| 3825 | else |
| 3826 | ah->regulatory.max_power_level = ratesArray[i]; |
| 3827 | |
| 3828 | switch (ar5416_get_ntxchains(ah->txchainmask)) { |
| 3829 | case 1: |
| 3830 | break; |
| 3831 | case 2: |
| 3832 | ah->regulatory.max_power_level += |
| 3833 | INCREASE_MAXPOW_BY_TWO_CHAIN; |
| 3834 | break; |
| 3835 | case 3: |
| 3836 | ah->regulatory.max_power_level += |
| 3837 | INCREASE_MAXPOW_BY_THREE_CHAIN; |
| 3838 | break; |
| 3839 | default: |
| 3840 | DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, |
| 3841 | "Invalid chainmask configuration\n"); |
| 3842 | break; |
| 3843 | } |
| 3844 | } |
| 3845 | |
| 3846 | static void ath9k_hw_AR9287_set_addac(struct ath_hw *ah, |
| 3847 | struct ath9k_channel *chan) |
| 3848 | { |
| 3849 | return; |
| 3850 | } |
| 3851 | |
| 3852 | static void ath9k_hw_AR9287_set_board_values(struct ath_hw *ah, |
| 3853 | struct ath9k_channel *chan) |
| 3854 | { |
Luis R. Rodriguez | 475f598 | 2009-08-03 17:31:25 -0400 | [diff] [blame] | 3855 | struct ar9287_eeprom *eep = &ah->eeprom.map9287; |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 3856 | struct modal_eep_ar9287_header *pModal = &eep->modalHeader; |
| 3857 | |
| 3858 | u16 antWrites[AR9287_ANT_16S]; |
| 3859 | u32 regChainOffset; |
| 3860 | u8 txRxAttenLocal; |
| 3861 | int i, j, offset_num; |
| 3862 | |
| 3863 | pModal = &eep->modalHeader; |
| 3864 | |
| 3865 | antWrites[0] = (u16)((pModal->antCtrlCommon >> 28) & 0xF); |
| 3866 | antWrites[1] = (u16)((pModal->antCtrlCommon >> 24) & 0xF); |
| 3867 | antWrites[2] = (u16)((pModal->antCtrlCommon >> 20) & 0xF); |
| 3868 | antWrites[3] = (u16)((pModal->antCtrlCommon >> 16) & 0xF); |
| 3869 | antWrites[4] = (u16)((pModal->antCtrlCommon >> 12) & 0xF); |
| 3870 | antWrites[5] = (u16)((pModal->antCtrlCommon >> 8) & 0xF); |
| 3871 | antWrites[6] = (u16)((pModal->antCtrlCommon >> 4) & 0xF); |
| 3872 | antWrites[7] = (u16)(pModal->antCtrlCommon & 0xF); |
| 3873 | |
| 3874 | offset_num = 8; |
| 3875 | |
| 3876 | for (i = 0, j = offset_num; i < AR9287_MAX_CHAINS; i++) { |
| 3877 | antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 28) & 0xf); |
| 3878 | antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 10) & 0x3); |
| 3879 | antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 8) & 0x3); |
| 3880 | antWrites[j++] = 0; |
| 3881 | antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 6) & 0x3); |
| 3882 | antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 4) & 0x3); |
| 3883 | antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 2) & 0x3); |
| 3884 | antWrites[j++] = (u16)(pModal->antCtrlChain[i] & 0x3); |
| 3885 | } |
| 3886 | |
| 3887 | |
| 3888 | REG_WRITE(ah, AR_PHY_SWITCH_COM, |
| 3889 | ah->eep_ops->get_eeprom_antenna_cfg(ah, chan)); |
| 3890 | |
| 3891 | for (i = 0; i < AR9287_MAX_CHAINS; i++) { |
| 3892 | regChainOffset = i * 0x1000; |
| 3893 | |
| 3894 | REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset, |
| 3895 | pModal->antCtrlChain[i]); |
| 3896 | |
| 3897 | REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset, |
| 3898 | (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset) |
| 3899 | & ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF | |
| 3900 | AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) | |
| 3901 | SM(pModal->iqCalICh[i], |
| 3902 | AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) | |
| 3903 | SM(pModal->iqCalQCh[i], |
| 3904 | AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF)); |
| 3905 | |
| 3906 | txRxAttenLocal = pModal->txRxAttenCh[i]; |
| 3907 | |
| 3908 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset, |
| 3909 | AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN, |
| 3910 | pModal->bswMargin[i]); |
| 3911 | REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset, |
| 3912 | AR_PHY_GAIN_2GHZ_XATTEN1_DB, |
| 3913 | pModal->bswAtten[i]); |
| 3914 | REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset, |
| 3915 | AR9280_PHY_RXGAIN_TXRX_ATTEN, |
| 3916 | txRxAttenLocal); |
| 3917 | REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset, |
| 3918 | AR9280_PHY_RXGAIN_TXRX_MARGIN, |
| 3919 | pModal->rxTxMarginCh[i]); |
| 3920 | } |
| 3921 | |
| 3922 | |
| 3923 | if (IS_CHAN_HT40(chan)) |
| 3924 | REG_RMW_FIELD(ah, AR_PHY_SETTLING, |
| 3925 | AR_PHY_SETTLING_SWITCH, pModal->swSettleHt40); |
| 3926 | else |
| 3927 | REG_RMW_FIELD(ah, AR_PHY_SETTLING, |
| 3928 | AR_PHY_SETTLING_SWITCH, pModal->switchSettling); |
| 3929 | |
| 3930 | REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, |
| 3931 | AR_PHY_DESIRED_SZ_ADC, pModal->adcDesiredSize); |
| 3932 | |
| 3933 | REG_WRITE(ah, AR_PHY_RF_CTL4, |
| 3934 | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF) |
| 3935 | | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF) |
| 3936 | | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON) |
| 3937 | | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON)); |
| 3938 | |
| 3939 | REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, |
| 3940 | AR_PHY_TX_END_TO_A2_RX_ON, pModal->txEndToRxOn); |
| 3941 | |
| 3942 | REG_RMW_FIELD(ah, AR_PHY_CCA, |
| 3943 | AR9280_PHY_CCA_THRESH62, pModal->thresh62); |
| 3944 | REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0, |
| 3945 | AR_PHY_EXT_CCA0_THRESH62, pModal->thresh62); |
| 3946 | |
| 3947 | ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH0, AR9287_AN_RF2G3_DB1, |
| 3948 | AR9287_AN_RF2G3_DB1_S, pModal->db1); |
| 3949 | ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH0, AR9287_AN_RF2G3_DB2, |
| 3950 | AR9287_AN_RF2G3_DB2_S, pModal->db2); |
| 3951 | ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH0, |
| 3952 | AR9287_AN_RF2G3_OB_CCK, |
| 3953 | AR9287_AN_RF2G3_OB_CCK_S, pModal->ob_cck); |
| 3954 | ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH0, |
| 3955 | AR9287_AN_RF2G3_OB_PSK, |
| 3956 | AR9287_AN_RF2G3_OB_PSK_S, pModal->ob_psk); |
| 3957 | ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH0, |
| 3958 | AR9287_AN_RF2G3_OB_QAM, |
| 3959 | AR9287_AN_RF2G3_OB_QAM_S, pModal->ob_qam); |
| 3960 | ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH0, |
| 3961 | AR9287_AN_RF2G3_OB_PAL_OFF, |
| 3962 | AR9287_AN_RF2G3_OB_PAL_OFF_S, |
| 3963 | pModal->ob_pal_off); |
| 3964 | |
| 3965 | ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH1, |
| 3966 | AR9287_AN_RF2G3_DB1, AR9287_AN_RF2G3_DB1_S, |
| 3967 | pModal->db1); |
| 3968 | ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH1, AR9287_AN_RF2G3_DB2, |
| 3969 | AR9287_AN_RF2G3_DB2_S, pModal->db2); |
| 3970 | ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH1, |
| 3971 | AR9287_AN_RF2G3_OB_CCK, |
| 3972 | AR9287_AN_RF2G3_OB_CCK_S, pModal->ob_cck); |
| 3973 | ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH1, |
| 3974 | AR9287_AN_RF2G3_OB_PSK, |
| 3975 | AR9287_AN_RF2G3_OB_PSK_S, pModal->ob_psk); |
| 3976 | ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH1, |
| 3977 | AR9287_AN_RF2G3_OB_QAM, |
| 3978 | AR9287_AN_RF2G3_OB_QAM_S, pModal->ob_qam); |
| 3979 | ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH1, |
| 3980 | AR9287_AN_RF2G3_OB_PAL_OFF, |
| 3981 | AR9287_AN_RF2G3_OB_PAL_OFF_S, |
| 3982 | pModal->ob_pal_off); |
| 3983 | |
| 3984 | REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, |
| 3985 | AR_PHY_TX_END_DATA_START, pModal->txFrameToDataStart); |
| 3986 | REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, |
| 3987 | AR_PHY_TX_END_PA_ON, pModal->txFrameToPaOn); |
| 3988 | |
| 3989 | ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TOP2, |
| 3990 | AR9287_AN_TOP2_XPABIAS_LVL, |
| 3991 | AR9287_AN_TOP2_XPABIAS_LVL_S, |
| 3992 | pModal->xpaBiasLvl); |
| 3993 | } |
| 3994 | |
| 3995 | static u8 ath9k_hw_AR9287_get_num_ant_config(struct ath_hw *ah, |
| 3996 | enum ieee80211_band freq_band) |
| 3997 | { |
| 3998 | return 1; |
| 3999 | } |
| 4000 | |
| 4001 | |
| 4002 | |
| 4003 | |
| 4004 | static u16 ath9k_hw_AR9287_get_eeprom_antenna_cfg(struct ath_hw *ah, |
| 4005 | struct ath9k_channel *chan) |
| 4006 | { |
Luis R. Rodriguez | 475f598 | 2009-08-03 17:31:25 -0400 | [diff] [blame] | 4007 | struct ar9287_eeprom *eep = &ah->eeprom.map9287; |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 4008 | struct modal_eep_ar9287_header *pModal = &eep->modalHeader; |
| 4009 | return pModal->antCtrlCommon & 0xFFFF; |
| 4010 | } |
| 4011 | |
| 4012 | |
| 4013 | static u16 ath9k_hw_AR9287_get_spur_channel(struct ath_hw *ah, |
| 4014 | u16 i, bool is2GHz) |
| 4015 | { |
| 4016 | #define EEP_MAP9287_SPURCHAN \ |
| 4017 | (ah->eeprom.map9287.modalHeader.spurChans[i].spurChan) |
| 4018 | u16 spur_val = AR_NO_SPUR; |
| 4019 | |
| 4020 | DPRINTF(ah->ah_sc, ATH_DBG_ANI, |
| 4021 | "Getting spur idx %d is2Ghz. %d val %x\n", |
| 4022 | i, is2GHz, ah->config.spurchans[i][is2GHz]); |
| 4023 | |
| 4024 | switch (ah->config.spurmode) { |
| 4025 | case SPUR_DISABLE: |
| 4026 | break; |
| 4027 | case SPUR_ENABLE_IOCTL: |
| 4028 | spur_val = ah->config.spurchans[i][is2GHz]; |
| 4029 | DPRINTF(ah->ah_sc, ATH_DBG_ANI, |
| 4030 | "Getting spur val from new loc. %d\n", spur_val); |
| 4031 | break; |
| 4032 | case SPUR_ENABLE_EEPROM: |
| 4033 | spur_val = EEP_MAP9287_SPURCHAN; |
| 4034 | break; |
| 4035 | } |
| 4036 | |
| 4037 | return spur_val; |
| 4038 | |
| 4039 | #undef EEP_MAP9287_SPURCHAN |
| 4040 | } |
| 4041 | |
| 4042 | static struct eeprom_ops eep_AR9287_ops = { |
| 4043 | .check_eeprom = ath9k_hw_AR9287_check_eeprom, |
| 4044 | .get_eeprom = ath9k_hw_AR9287_get_eeprom, |
| 4045 | .fill_eeprom = ath9k_hw_AR9287_fill_eeprom, |
| 4046 | .get_eeprom_ver = ath9k_hw_AR9287_get_eeprom_ver, |
| 4047 | .get_eeprom_rev = ath9k_hw_AR9287_get_eeprom_rev, |
| 4048 | .get_num_ant_config = ath9k_hw_AR9287_get_num_ant_config, |
| 4049 | .get_eeprom_antenna_cfg = ath9k_hw_AR9287_get_eeprom_antenna_cfg, |
| 4050 | .set_board_values = ath9k_hw_AR9287_set_board_values, |
| 4051 | .set_addac = ath9k_hw_AR9287_set_addac, |
| 4052 | .set_txpower = ath9k_hw_AR9287_set_txpower, |
| 4053 | .get_spur_channel = ath9k_hw_AR9287_get_spur_channel |
| 4054 | }; |
| 4055 | |
| 4056 | |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 4057 | int ath9k_hw_eeprom_init(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4058 | { |
| 4059 | int status; |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 4060 | if (AR_SREV_9287(ah)) { |
| 4061 | ah->eep_map = EEP_MAP_AR9287; |
| 4062 | ah->eep_ops = &eep_AR9287_ops; |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame^] | 4063 | } else if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 4064 | ah->eep_map = EEP_MAP_4KBITS; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 4065 | ah->eep_ops = &eep_4k_ops; |
| 4066 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 4067 | ah->eep_map = EEP_MAP_DEFAULT; |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 4068 | ah->eep_ops = &eep_def_ops; |
| 4069 | } |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 4070 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 4071 | if (!ah->eep_ops->fill_eeprom(ah)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4072 | return -EIO; |
| 4073 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 4074 | status = ah->eep_ops->check_eeprom(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4075 | |
| 4076 | return status; |
| 4077 | } |