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 | |
Luis R. Rodriguez | 5bb1279 | 2009-09-14 00:55:09 -0700 | [diff] [blame] | 17 | #include "hw.h" |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 18 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 19 | static inline u16 ath9k_hw_fbin2freq(u8 fbin, bool is2GHz) |
| 20 | { |
| 21 | if (fbin == AR5416_BCHAN_UNUSED) |
| 22 | return fbin; |
| 23 | |
| 24 | return (u16) ((is2GHz) ? (2300 + fbin) : (4800 + 5 * fbin)); |
| 25 | } |
| 26 | |
Sujith | 79d7f4b | 2010-06-01 15:14:06 +0530 | [diff] [blame] | 27 | void ath9k_hw_analog_shift_regwrite(struct ath_hw *ah, u32 reg, u32 val) |
| 28 | { |
| 29 | REG_WRITE(ah, reg, val); |
| 30 | |
| 31 | if (ah->config.analog_shiftreg) |
| 32 | udelay(100); |
| 33 | } |
| 34 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 35 | void ath9k_hw_analog_shift_rmw(struct ath_hw *ah, u32 reg, u32 mask, |
| 36 | u32 shift, u32 val) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 37 | { |
| 38 | u32 regVal; |
| 39 | |
| 40 | regVal = REG_READ(ah, reg) & ~mask; |
| 41 | regVal |= (val << shift) & mask; |
| 42 | |
| 43 | REG_WRITE(ah, reg, regVal); |
| 44 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 45 | if (ah->config.analog_shiftreg) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 46 | udelay(100); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 47 | } |
| 48 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 49 | int16_t ath9k_hw_interpolate(u16 target, u16 srcLeft, u16 srcRight, |
| 50 | int16_t targetLeft, int16_t targetRight) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 51 | { |
| 52 | int16_t rv; |
| 53 | |
| 54 | if (srcRight == srcLeft) { |
| 55 | rv = targetLeft; |
| 56 | } else { |
| 57 | rv = (int16_t) (((target - srcLeft) * targetRight + |
| 58 | (srcRight - target) * targetLeft) / |
| 59 | (srcRight - srcLeft)); |
| 60 | } |
| 61 | return rv; |
| 62 | } |
| 63 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 64 | bool ath9k_hw_get_lower_upper_index(u8 target, u8 *pList, u16 listSize, |
| 65 | u16 *indexL, u16 *indexR) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 66 | { |
| 67 | u16 i; |
| 68 | |
| 69 | if (target <= pList[0]) { |
| 70 | *indexL = *indexR = 0; |
| 71 | return true; |
| 72 | } |
| 73 | if (target >= pList[listSize - 1]) { |
| 74 | *indexL = *indexR = (u16) (listSize - 1); |
| 75 | return true; |
| 76 | } |
| 77 | |
| 78 | for (i = 0; i < listSize - 1; i++) { |
| 79 | if (pList[i] == target) { |
| 80 | *indexL = *indexR = i; |
| 81 | return true; |
| 82 | } |
| 83 | if (target < pList[i + 1]) { |
| 84 | *indexL = i; |
| 85 | *indexR = (u16) (i + 1); |
| 86 | return false; |
| 87 | } |
| 88 | } |
| 89 | return false; |
| 90 | } |
| 91 | |
Luis R. Rodriguez | 5bb1279 | 2009-09-14 00:55:09 -0700 | [diff] [blame] | 92 | bool ath9k_hw_nvram_read(struct ath_common *common, u32 off, u16 *data) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 93 | { |
Luis R. Rodriguez | 5bb1279 | 2009-09-14 00:55:09 -0700 | [diff] [blame] | 94 | return common->bus_ops->eeprom_read(common, off, data); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 95 | } |
| 96 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 97 | void ath9k_hw_fill_vpd_table(u8 pwrMin, u8 pwrMax, u8 *pPwrList, |
| 98 | u8 *pVpdList, u16 numIntercepts, |
| 99 | u8 *pRetVpdList) |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 100 | { |
| 101 | u16 i, k; |
| 102 | u8 currPwr = pwrMin; |
| 103 | u16 idxL = 0, idxR = 0; |
| 104 | |
| 105 | for (i = 0; i <= (pwrMax - pwrMin) / 2; i++) { |
| 106 | ath9k_hw_get_lower_upper_index(currPwr, pPwrList, |
| 107 | numIntercepts, &(idxL), |
| 108 | &(idxR)); |
| 109 | if (idxR < 1) |
| 110 | idxR = 1; |
| 111 | if (idxL == numIntercepts - 1) |
| 112 | idxL = (u16) (numIntercepts - 2); |
| 113 | if (pPwrList[idxL] == pPwrList[idxR]) |
| 114 | k = pVpdList[idxL]; |
| 115 | else |
| 116 | k = (u16)(((currPwr - pPwrList[idxL]) * pVpdList[idxR] + |
| 117 | (pPwrList[idxR] - currPwr) * pVpdList[idxL]) / |
| 118 | (pPwrList[idxR] - pPwrList[idxL])); |
| 119 | pRetVpdList[i] = (u8) k; |
| 120 | currPwr += 2; |
| 121 | } |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 122 | } |
| 123 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 124 | void ath9k_hw_get_legacy_target_powers(struct ath_hw *ah, |
| 125 | struct ath9k_channel *chan, |
| 126 | struct cal_target_power_leg *powInfo, |
| 127 | u16 numChannels, |
| 128 | struct cal_target_power_leg *pNewPower, |
| 129 | u16 numRates, bool isExtTarget) |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 130 | { |
| 131 | struct chan_centers centers; |
| 132 | u16 clo, chi; |
| 133 | int i; |
| 134 | int matchIndex = -1, lowIndex = -1; |
| 135 | u16 freq; |
| 136 | |
| 137 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
| 138 | freq = (isExtTarget) ? centers.ext_center : centers.ctl_center; |
| 139 | |
| 140 | if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel, |
| 141 | IS_CHAN_2GHZ(chan))) { |
| 142 | matchIndex = 0; |
| 143 | } else { |
| 144 | for (i = 0; (i < numChannels) && |
| 145 | (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) { |
| 146 | if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel, |
| 147 | IS_CHAN_2GHZ(chan))) { |
| 148 | matchIndex = i; |
| 149 | break; |
Roel Kluin | 73f57f8 | 2009-08-07 23:50:00 +0200 | [diff] [blame] | 150 | } else if (freq < ath9k_hw_fbin2freq(powInfo[i].bChannel, |
| 151 | IS_CHAN_2GHZ(chan)) && i > 0 && |
| 152 | freq > ath9k_hw_fbin2freq(powInfo[i - 1].bChannel, |
| 153 | IS_CHAN_2GHZ(chan))) { |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 154 | lowIndex = i - 1; |
| 155 | break; |
| 156 | } |
| 157 | } |
| 158 | if ((matchIndex == -1) && (lowIndex == -1)) |
| 159 | matchIndex = i - 1; |
| 160 | } |
| 161 | |
| 162 | if (matchIndex != -1) { |
| 163 | *pNewPower = powInfo[matchIndex]; |
| 164 | } else { |
| 165 | clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel, |
| 166 | IS_CHAN_2GHZ(chan)); |
| 167 | chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel, |
| 168 | IS_CHAN_2GHZ(chan)); |
| 169 | |
| 170 | for (i = 0; i < numRates; i++) { |
| 171 | pNewPower->tPow2x[i] = |
| 172 | (u8)ath9k_hw_interpolate(freq, clo, chi, |
| 173 | powInfo[lowIndex].tPow2x[i], |
| 174 | powInfo[lowIndex + 1].tPow2x[i]); |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 179 | void ath9k_hw_get_target_powers(struct ath_hw *ah, |
| 180 | struct ath9k_channel *chan, |
| 181 | struct cal_target_power_ht *powInfo, |
| 182 | u16 numChannels, |
| 183 | struct cal_target_power_ht *pNewPower, |
| 184 | u16 numRates, bool isHt40Target) |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 185 | { |
| 186 | struct chan_centers centers; |
| 187 | u16 clo, chi; |
| 188 | int i; |
| 189 | int matchIndex = -1, lowIndex = -1; |
| 190 | u16 freq; |
| 191 | |
| 192 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
| 193 | freq = isHt40Target ? centers.synth_center : centers.ctl_center; |
| 194 | |
| 195 | if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel, IS_CHAN_2GHZ(chan))) { |
| 196 | matchIndex = 0; |
| 197 | } else { |
| 198 | for (i = 0; (i < numChannels) && |
| 199 | (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) { |
| 200 | if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel, |
| 201 | IS_CHAN_2GHZ(chan))) { |
| 202 | matchIndex = i; |
| 203 | break; |
| 204 | } else |
Roel Kluin | 73f57f8 | 2009-08-07 23:50:00 +0200 | [diff] [blame] | 205 | if (freq < ath9k_hw_fbin2freq(powInfo[i].bChannel, |
| 206 | IS_CHAN_2GHZ(chan)) && i > 0 && |
| 207 | freq > ath9k_hw_fbin2freq(powInfo[i - 1].bChannel, |
| 208 | IS_CHAN_2GHZ(chan))) { |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 209 | lowIndex = i - 1; |
| 210 | break; |
| 211 | } |
| 212 | } |
| 213 | if ((matchIndex == -1) && (lowIndex == -1)) |
| 214 | matchIndex = i - 1; |
| 215 | } |
| 216 | |
| 217 | if (matchIndex != -1) { |
| 218 | *pNewPower = powInfo[matchIndex]; |
| 219 | } else { |
| 220 | clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel, |
| 221 | IS_CHAN_2GHZ(chan)); |
| 222 | chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel, |
| 223 | IS_CHAN_2GHZ(chan)); |
| 224 | |
| 225 | for (i = 0; i < numRates; i++) { |
| 226 | pNewPower->tPow2x[i] = (u8)ath9k_hw_interpolate(freq, |
| 227 | clo, chi, |
| 228 | powInfo[lowIndex].tPow2x[i], |
| 229 | powInfo[lowIndex + 1].tPow2x[i]); |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | |
Sujith | b5aec95 | 2009-08-07 09:45:15 +0530 | [diff] [blame] | 234 | u16 ath9k_hw_get_max_edge_power(u16 freq, struct cal_ctl_edges *pRdEdgesPower, |
| 235 | bool is2GHz, int num_band_edges) |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 236 | { |
| 237 | u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER; |
| 238 | int i; |
| 239 | |
| 240 | for (i = 0; (i < num_band_edges) && |
| 241 | (pRdEdgesPower[i].bChannel != AR5416_BCHAN_UNUSED); i++) { |
| 242 | if (freq == ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel, is2GHz)) { |
| 243 | twiceMaxEdgePower = pRdEdgesPower[i].tPower; |
| 244 | break; |
| 245 | } else if ((i > 0) && |
| 246 | (freq < ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel, |
| 247 | is2GHz))) { |
| 248 | if (ath9k_hw_fbin2freq(pRdEdgesPower[i - 1].bChannel, |
| 249 | is2GHz) < freq && |
| 250 | pRdEdgesPower[i - 1].flag) { |
| 251 | twiceMaxEdgePower = |
| 252 | pRdEdgesPower[i - 1].tPower; |
| 253 | } |
| 254 | break; |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | return twiceMaxEdgePower; |
| 259 | } |
| 260 | |
Sujith | a55f858 | 2010-06-01 15:14:07 +0530 | [diff] [blame] | 261 | void ath9k_hw_update_regulatory_maxpower(struct ath_hw *ah) |
| 262 | { |
| 263 | struct ath_common *common = ath9k_hw_common(ah); |
| 264 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
| 265 | |
| 266 | switch (ar5416_get_ntxchains(ah->txchainmask)) { |
| 267 | case 1: |
| 268 | break; |
| 269 | case 2: |
| 270 | regulatory->max_power_level += INCREASE_MAXPOW_BY_TWO_CHAIN; |
| 271 | break; |
| 272 | case 3: |
| 273 | regulatory->max_power_level += INCREASE_MAXPOW_BY_THREE_CHAIN; |
| 274 | break; |
| 275 | default: |
| 276 | ath_print(common, ATH_DBG_EEPROM, |
| 277 | "Invalid chainmask configuration\n"); |
| 278 | break; |
| 279 | } |
| 280 | } |
| 281 | |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 282 | int ath9k_hw_eeprom_init(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 283 | { |
| 284 | int status; |
Sujith | c16c9d0 | 2009-08-07 09:45:11 +0530 | [diff] [blame] | 285 | |
Senthil Balasubramanian | 15c9ee7 | 2010-04-15 17:39:14 -0400 | [diff] [blame] | 286 | if (AR_SREV_9300_20_OR_LATER(ah)) |
| 287 | ah->eep_ops = &eep_ar9300_ops; |
| 288 | else if (AR_SREV_9287(ah)) { |
Luis R. Rodriguez | 0b8f6f2b1 | 2010-04-15 17:39:12 -0400 | [diff] [blame] | 289 | ah->eep_ops = &eep_ar9287_ops; |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 290 | } else if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) { |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 291 | ah->eep_ops = &eep_4k_ops; |
| 292 | } else { |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 293 | ah->eep_ops = &eep_def_ops; |
| 294 | } |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 295 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 296 | if (!ah->eep_ops->fill_eeprom(ah)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 297 | return -EIO; |
| 298 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 299 | status = ah->eep_ops->check_eeprom(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 300 | |
| 301 | return status; |
| 302 | } |