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" |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 18 | #include "hw.h" |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 19 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 20 | /* We can tune this as we go by monitoring really low values */ |
| 21 | #define ATH9K_NF_TOO_LOW -60 |
| 22 | |
| 23 | /* AR5416 may return very high value (like -31 dBm), in those cases the nf |
| 24 | * is incorrect and we should use the static NF value. Later we can try to |
| 25 | * find out why they are reporting these values */ |
| 26 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 27 | static bool ath9k_hw_nf_in_range(struct ath_hw *ah, s16 nf) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 28 | { |
| 29 | if (nf > ATH9K_NF_TOO_LOW) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 30 | ath_print(ath9k_hw_common(ah), ATH_DBG_CALIBRATE, |
| 31 | "noise floor value detected (%d) is " |
| 32 | "lower than what we think is a " |
| 33 | "reasonable value (%d)\n", |
| 34 | nf, ATH9K_NF_TOO_LOW); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 35 | return false; |
| 36 | } |
| 37 | return true; |
| 38 | } |
| 39 | |
| 40 | static int16_t ath9k_hw_get_nf_hist_mid(int16_t *nfCalBuffer) |
| 41 | { |
| 42 | int16_t nfval; |
| 43 | int16_t sort[ATH9K_NF_CAL_HIST_MAX]; |
| 44 | int i, j; |
| 45 | |
| 46 | for (i = 0; i < ATH9K_NF_CAL_HIST_MAX; i++) |
| 47 | sort[i] = nfCalBuffer[i]; |
| 48 | |
| 49 | for (i = 0; i < ATH9K_NF_CAL_HIST_MAX - 1; i++) { |
| 50 | for (j = 1; j < ATH9K_NF_CAL_HIST_MAX - i; j++) { |
| 51 | if (sort[j] > sort[j - 1]) { |
| 52 | nfval = sort[j]; |
| 53 | sort[j] = sort[j - 1]; |
| 54 | sort[j - 1] = nfval; |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | nfval = sort[(ATH9K_NF_CAL_HIST_MAX - 1) >> 1]; |
| 59 | |
| 60 | return nfval; |
| 61 | } |
| 62 | |
| 63 | static void ath9k_hw_update_nfcal_hist_buffer(struct ath9k_nfcal_hist *h, |
| 64 | int16_t *nfarray) |
| 65 | { |
| 66 | int i; |
| 67 | |
| 68 | for (i = 0; i < NUM_NF_READINGS; i++) { |
| 69 | h[i].nfCalBuffer[h[i].currIndex] = nfarray[i]; |
| 70 | |
| 71 | if (++h[i].currIndex >= ATH9K_NF_CAL_HIST_MAX) |
| 72 | h[i].currIndex = 0; |
| 73 | |
| 74 | if (h[i].invalidNFcount > 0) { |
| 75 | if (nfarray[i] < AR_PHY_CCA_MIN_BAD_VALUE || |
| 76 | nfarray[i] > AR_PHY_CCA_MAX_HIGH_VALUE) { |
| 77 | h[i].invalidNFcount = ATH9K_NF_CAL_HIST_MAX; |
| 78 | } else { |
| 79 | h[i].invalidNFcount--; |
| 80 | h[i].privNF = nfarray[i]; |
| 81 | } |
| 82 | } else { |
| 83 | h[i].privNF = |
| 84 | ath9k_hw_get_nf_hist_mid(h[i].nfCalBuffer); |
| 85 | } |
| 86 | } |
| 87 | return; |
| 88 | } |
| 89 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 90 | static void ath9k_hw_do_getnf(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 91 | int16_t nfarray[NUM_NF_READINGS]) |
| 92 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 93 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 94 | int16_t nf; |
| 95 | |
| 96 | if (AR_SREV_9280_10_OR_LATER(ah)) |
| 97 | nf = MS(REG_READ(ah, AR_PHY_CCA), AR9280_PHY_MINCCA_PWR); |
| 98 | else |
| 99 | nf = MS(REG_READ(ah, AR_PHY_CCA), AR_PHY_MINCCA_PWR); |
| 100 | |
| 101 | if (nf & 0x100) |
| 102 | nf = 0 - ((nf ^ 0x1ff) + 1); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 103 | ath_print(common, ATH_DBG_CALIBRATE, |
| 104 | "NF calibrated [ctl] [chain 0] is %d\n", nf); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 105 | nfarray[0] = nf; |
| 106 | |
Senthil Balasubramanian | 793c592 | 2009-01-26 20:28:14 +0530 | [diff] [blame] | 107 | if (!AR_SREV_9285(ah)) { |
| 108 | if (AR_SREV_9280_10_OR_LATER(ah)) |
| 109 | nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), |
| 110 | AR9280_PHY_CH1_MINCCA_PWR); |
| 111 | else |
| 112 | nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), |
| 113 | AR_PHY_CH1_MINCCA_PWR); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 114 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 115 | if (nf & 0x100) |
| 116 | nf = 0 - ((nf ^ 0x1ff) + 1); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 117 | ath_print(common, ATH_DBG_CALIBRATE, |
| 118 | "NF calibrated [ctl] [chain 1] is %d\n", nf); |
Senthil Balasubramanian | 793c592 | 2009-01-26 20:28:14 +0530 | [diff] [blame] | 119 | nfarray[1] = nf; |
| 120 | |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 121 | if (!AR_SREV_9280(ah) && !AR_SREV_9287(ah)) { |
Senthil Balasubramanian | 793c592 | 2009-01-26 20:28:14 +0530 | [diff] [blame] | 122 | nf = MS(REG_READ(ah, AR_PHY_CH2_CCA), |
| 123 | AR_PHY_CH2_MINCCA_PWR); |
| 124 | if (nf & 0x100) |
| 125 | nf = 0 - ((nf ^ 0x1ff) + 1); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 126 | ath_print(common, ATH_DBG_CALIBRATE, |
| 127 | "NF calibrated [ctl] [chain 2] is %d\n", nf); |
Senthil Balasubramanian | 793c592 | 2009-01-26 20:28:14 +0530 | [diff] [blame] | 128 | nfarray[2] = nf; |
| 129 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | if (AR_SREV_9280_10_OR_LATER(ah)) |
| 133 | nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), |
| 134 | AR9280_PHY_EXT_MINCCA_PWR); |
| 135 | else |
| 136 | nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), |
| 137 | AR_PHY_EXT_MINCCA_PWR); |
| 138 | |
| 139 | if (nf & 0x100) |
| 140 | nf = 0 - ((nf ^ 0x1ff) + 1); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 141 | ath_print(common, ATH_DBG_CALIBRATE, |
| 142 | "NF calibrated [ext] [chain 0] is %d\n", nf); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 143 | nfarray[3] = nf; |
| 144 | |
Senthil Balasubramanian | 793c592 | 2009-01-26 20:28:14 +0530 | [diff] [blame] | 145 | if (!AR_SREV_9285(ah)) { |
| 146 | if (AR_SREV_9280_10_OR_LATER(ah)) |
| 147 | nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA), |
| 148 | AR9280_PHY_CH1_EXT_MINCCA_PWR); |
| 149 | else |
| 150 | nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA), |
| 151 | AR_PHY_CH1_EXT_MINCCA_PWR); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 152 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 153 | if (nf & 0x100) |
| 154 | nf = 0 - ((nf ^ 0x1ff) + 1); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 155 | ath_print(common, ATH_DBG_CALIBRATE, |
| 156 | "NF calibrated [ext] [chain 1] is %d\n", nf); |
Senthil Balasubramanian | 793c592 | 2009-01-26 20:28:14 +0530 | [diff] [blame] | 157 | nfarray[4] = nf; |
| 158 | |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 159 | if (!AR_SREV_9280(ah) && !AR_SREV_9287(ah)) { |
Senthil Balasubramanian | 793c592 | 2009-01-26 20:28:14 +0530 | [diff] [blame] | 160 | nf = MS(REG_READ(ah, AR_PHY_CH2_EXT_CCA), |
| 161 | AR_PHY_CH2_EXT_MINCCA_PWR); |
| 162 | if (nf & 0x100) |
| 163 | nf = 0 - ((nf ^ 0x1ff) + 1); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 164 | ath_print(common, ATH_DBG_CALIBRATE, |
| 165 | "NF calibrated [ext] [chain 2] is %d\n", nf); |
Senthil Balasubramanian | 793c592 | 2009-01-26 20:28:14 +0530 | [diff] [blame] | 166 | nfarray[5] = nf; |
| 167 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 171 | static bool getNoiseFloorThresh(struct ath_hw *ah, |
Luis R. Rodriguez | 76061ab | 2008-12-23 15:58:41 -0800 | [diff] [blame] | 172 | enum ieee80211_band band, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 173 | int16_t *nft) |
| 174 | { |
Luis R. Rodriguez | 76061ab | 2008-12-23 15:58:41 -0800 | [diff] [blame] | 175 | switch (band) { |
| 176 | case IEEE80211_BAND_5GHZ: |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 177 | *nft = (int8_t)ah->eep_ops->get_eeprom(ah, EEP_NFTHRESH_5); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 178 | break; |
Luis R. Rodriguez | 76061ab | 2008-12-23 15:58:41 -0800 | [diff] [blame] | 179 | case IEEE80211_BAND_2GHZ: |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 180 | *nft = (int8_t)ah->eep_ops->get_eeprom(ah, EEP_NFTHRESH_2); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 181 | break; |
| 182 | default: |
Luis R. Rodriguez | 76061ab | 2008-12-23 15:58:41 -0800 | [diff] [blame] | 183 | BUG_ON(1); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 184 | return false; |
| 185 | } |
| 186 | |
| 187 | return true; |
| 188 | } |
| 189 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 190 | static void ath9k_hw_setup_calibration(struct ath_hw *ah, |
Sujith | cbfe946 | 2009-04-13 21:56:56 +0530 | [diff] [blame] | 191 | struct ath9k_cal_list *currCal) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 192 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 193 | struct ath_common *common = ath9k_hw_common(ah); |
| 194 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 195 | REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(0), |
| 196 | AR_PHY_TIMING_CTRL4_IQCAL_LOG_COUNT_MAX, |
| 197 | currCal->calData->calCountMax); |
| 198 | |
| 199 | switch (currCal->calData->calType) { |
| 200 | case IQ_MISMATCH_CAL: |
| 201 | REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_IQ); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 202 | ath_print(common, ATH_DBG_CALIBRATE, |
| 203 | "starting IQ Mismatch Calibration\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 204 | break; |
| 205 | case ADC_GAIN_CAL: |
| 206 | REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_ADC_GAIN); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 207 | ath_print(common, ATH_DBG_CALIBRATE, |
| 208 | "starting ADC Gain Calibration\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 209 | break; |
| 210 | case ADC_DC_CAL: |
| 211 | REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_ADC_DC_PER); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 212 | ath_print(common, ATH_DBG_CALIBRATE, |
| 213 | "starting ADC DC Calibration\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 214 | break; |
| 215 | case ADC_DC_INIT_CAL: |
| 216 | REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_ADC_DC_INIT); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 217 | ath_print(common, ATH_DBG_CALIBRATE, |
| 218 | "starting Init ADC DC Calibration\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 219 | break; |
| 220 | } |
| 221 | |
| 222 | REG_SET_BIT(ah, AR_PHY_TIMING_CTRL4(0), |
| 223 | AR_PHY_TIMING_CTRL4_DO_CAL); |
| 224 | } |
| 225 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 226 | static void ath9k_hw_reset_calibration(struct ath_hw *ah, |
Sujith | cbfe946 | 2009-04-13 21:56:56 +0530 | [diff] [blame] | 227 | struct ath9k_cal_list *currCal) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 228 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 229 | int i; |
| 230 | |
| 231 | ath9k_hw_setup_calibration(ah, currCal); |
| 232 | |
| 233 | currCal->calState = CAL_RUNNING; |
| 234 | |
| 235 | for (i = 0; i < AR5416_MAX_CHAINS; i++) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 236 | ah->meas0.sign[i] = 0; |
| 237 | ah->meas1.sign[i] = 0; |
| 238 | ah->meas2.sign[i] = 0; |
| 239 | ah->meas3.sign[i] = 0; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 240 | } |
| 241 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 242 | ah->cal_samples = 0; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 243 | } |
| 244 | |
Sujith | 379f044 | 2009-04-13 21:56:48 +0530 | [diff] [blame] | 245 | static bool ath9k_hw_per_calibration(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 246 | struct ath9k_channel *ichan, |
| 247 | u8 rxchainmask, |
Sujith | cbfe946 | 2009-04-13 21:56:56 +0530 | [diff] [blame] | 248 | struct ath9k_cal_list *currCal) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 249 | { |
Sujith | 379f044 | 2009-04-13 21:56:48 +0530 | [diff] [blame] | 250 | bool iscaldone = false; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 251 | |
| 252 | if (currCal->calState == CAL_RUNNING) { |
| 253 | if (!(REG_READ(ah, AR_PHY_TIMING_CTRL4(0)) & |
| 254 | AR_PHY_TIMING_CTRL4_DO_CAL)) { |
| 255 | |
| 256 | currCal->calData->calCollect(ah); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 257 | ah->cal_samples++; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 258 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 259 | if (ah->cal_samples >= currCal->calData->calNumSamples) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 260 | int i, numChains = 0; |
| 261 | for (i = 0; i < AR5416_MAX_CHAINS; i++) { |
| 262 | if (rxchainmask & (1 << i)) |
| 263 | numChains++; |
| 264 | } |
| 265 | |
| 266 | currCal->calData->calPostProc(ah, numChains); |
| 267 | ichan->CalValid |= currCal->calData->calType; |
| 268 | currCal->calState = CAL_DONE; |
Sujith | 379f044 | 2009-04-13 21:56:48 +0530 | [diff] [blame] | 269 | iscaldone = true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 270 | } else { |
| 271 | ath9k_hw_setup_calibration(ah, currCal); |
| 272 | } |
| 273 | } |
| 274 | } else if (!(ichan->CalValid & currCal->calData->calType)) { |
| 275 | ath9k_hw_reset_calibration(ah, currCal); |
| 276 | } |
Sujith | 379f044 | 2009-04-13 21:56:48 +0530 | [diff] [blame] | 277 | |
| 278 | return iscaldone; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 279 | } |
| 280 | |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 281 | /* Assumes you are talking about the currently configured channel */ |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 282 | static bool ath9k_hw_iscal_supported(struct ath_hw *ah, |
Sujith | cbfe946 | 2009-04-13 21:56:56 +0530 | [diff] [blame] | 283 | enum ath9k_cal_types calType) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 284 | { |
Luis R. Rodriguez | b002a4a | 2009-09-13 00:03:27 -0700 | [diff] [blame] | 285 | struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 286 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 287 | switch (calType & ah->supp_cals) { |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 288 | case IQ_MISMATCH_CAL: /* Both 2 GHz and 5 GHz support OFDM */ |
| 289 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 290 | case ADC_GAIN_CAL: |
| 291 | case ADC_DC_CAL: |
Sujith | a451aa6 | 2009-04-13 21:56:43 +0530 | [diff] [blame] | 292 | if (!(conf->channel->band == IEEE80211_BAND_2GHZ && |
| 293 | conf_is_ht20(conf))) |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 294 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 295 | break; |
| 296 | } |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 297 | return false; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 298 | } |
| 299 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 300 | static void ath9k_hw_iqcal_collect(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 301 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 302 | int i; |
| 303 | |
| 304 | for (i = 0; i < AR5416_MAX_CHAINS; i++) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 305 | ah->totalPowerMeasI[i] += |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 306 | REG_READ(ah, AR_PHY_CAL_MEAS_0(i)); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 307 | ah->totalPowerMeasQ[i] += |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 308 | REG_READ(ah, AR_PHY_CAL_MEAS_1(i)); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 309 | ah->totalIqCorrMeas[i] += |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 310 | (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_2(i)); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 311 | ath_print(ath9k_hw_common(ah), ATH_DBG_CALIBRATE, |
| 312 | "%d: Chn %d pmi=0x%08x;pmq=0x%08x;iqcm=0x%08x;\n", |
| 313 | ah->cal_samples, i, ah->totalPowerMeasI[i], |
| 314 | ah->totalPowerMeasQ[i], |
| 315 | ah->totalIqCorrMeas[i]); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 319 | static void ath9k_hw_adc_gaincal_collect(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 320 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 321 | int i; |
| 322 | |
| 323 | for (i = 0; i < AR5416_MAX_CHAINS; i++) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 324 | ah->totalAdcIOddPhase[i] += |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 325 | REG_READ(ah, AR_PHY_CAL_MEAS_0(i)); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 326 | ah->totalAdcIEvenPhase[i] += |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 327 | REG_READ(ah, AR_PHY_CAL_MEAS_1(i)); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 328 | ah->totalAdcQOddPhase[i] += |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 329 | REG_READ(ah, AR_PHY_CAL_MEAS_2(i)); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 330 | ah->totalAdcQEvenPhase[i] += |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 331 | REG_READ(ah, AR_PHY_CAL_MEAS_3(i)); |
| 332 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 333 | ath_print(ath9k_hw_common(ah), ATH_DBG_CALIBRATE, |
| 334 | "%d: Chn %d oddi=0x%08x; eveni=0x%08x; " |
| 335 | "oddq=0x%08x; evenq=0x%08x;\n", |
| 336 | ah->cal_samples, i, |
| 337 | ah->totalAdcIOddPhase[i], |
| 338 | ah->totalAdcIEvenPhase[i], |
| 339 | ah->totalAdcQOddPhase[i], |
| 340 | ah->totalAdcQEvenPhase[i]); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 344 | static void ath9k_hw_adc_dccal_collect(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 345 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 346 | int i; |
| 347 | |
| 348 | for (i = 0; i < AR5416_MAX_CHAINS; i++) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 349 | ah->totalAdcDcOffsetIOddPhase[i] += |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 350 | (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_0(i)); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 351 | ah->totalAdcDcOffsetIEvenPhase[i] += |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 352 | (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_1(i)); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 353 | ah->totalAdcDcOffsetQOddPhase[i] += |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 354 | (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_2(i)); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 355 | ah->totalAdcDcOffsetQEvenPhase[i] += |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 356 | (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_3(i)); |
| 357 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 358 | ath_print(ath9k_hw_common(ah), ATH_DBG_CALIBRATE, |
| 359 | "%d: Chn %d oddi=0x%08x; eveni=0x%08x; " |
| 360 | "oddq=0x%08x; evenq=0x%08x;\n", |
| 361 | ah->cal_samples, i, |
| 362 | ah->totalAdcDcOffsetIOddPhase[i], |
| 363 | ah->totalAdcDcOffsetIEvenPhase[i], |
| 364 | ah->totalAdcDcOffsetQOddPhase[i], |
| 365 | ah->totalAdcDcOffsetQEvenPhase[i]); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 369 | static void ath9k_hw_iqcalibrate(struct ath_hw *ah, u8 numChains) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 370 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 371 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 372 | u32 powerMeasQ, powerMeasI, iqCorrMeas; |
| 373 | u32 qCoffDenom, iCoffDenom; |
| 374 | int32_t qCoff, iCoff; |
| 375 | int iqCorrNeg, i; |
| 376 | |
| 377 | for (i = 0; i < numChains; i++) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 378 | powerMeasI = ah->totalPowerMeasI[i]; |
| 379 | powerMeasQ = ah->totalPowerMeasQ[i]; |
| 380 | iqCorrMeas = ah->totalIqCorrMeas[i]; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 381 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 382 | ath_print(common, ATH_DBG_CALIBRATE, |
| 383 | "Starting IQ Cal and Correction for Chain %d\n", |
| 384 | i); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 385 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 386 | ath_print(common, ATH_DBG_CALIBRATE, |
| 387 | "Orignal: Chn %diq_corr_meas = 0x%08x\n", |
| 388 | i, ah->totalIqCorrMeas[i]); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 389 | |
| 390 | iqCorrNeg = 0; |
| 391 | |
| 392 | if (iqCorrMeas > 0x80000000) { |
| 393 | iqCorrMeas = (0xffffffff - iqCorrMeas) + 1; |
| 394 | iqCorrNeg = 1; |
| 395 | } |
| 396 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 397 | ath_print(common, ATH_DBG_CALIBRATE, |
| 398 | "Chn %d pwr_meas_i = 0x%08x\n", i, powerMeasI); |
| 399 | ath_print(common, ATH_DBG_CALIBRATE, |
| 400 | "Chn %d pwr_meas_q = 0x%08x\n", i, powerMeasQ); |
| 401 | ath_print(common, ATH_DBG_CALIBRATE, "iqCorrNeg is 0x%08x\n", |
| 402 | iqCorrNeg); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 403 | |
| 404 | iCoffDenom = (powerMeasI / 2 + powerMeasQ / 2) / 128; |
| 405 | qCoffDenom = powerMeasQ / 64; |
| 406 | |
| 407 | if (powerMeasQ != 0) { |
| 408 | iCoff = iqCorrMeas / iCoffDenom; |
| 409 | qCoff = powerMeasI / qCoffDenom - 64; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 410 | ath_print(common, ATH_DBG_CALIBRATE, |
| 411 | "Chn %d iCoff = 0x%08x\n", i, iCoff); |
| 412 | ath_print(common, ATH_DBG_CALIBRATE, |
| 413 | "Chn %d qCoff = 0x%08x\n", i, qCoff); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 414 | |
| 415 | iCoff = iCoff & 0x3f; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 416 | ath_print(common, ATH_DBG_CALIBRATE, |
| 417 | "New: Chn %d iCoff = 0x%08x\n", i, iCoff); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 418 | if (iqCorrNeg == 0x0) |
| 419 | iCoff = 0x40 - iCoff; |
| 420 | |
| 421 | if (qCoff > 15) |
| 422 | qCoff = 15; |
| 423 | else if (qCoff <= -16) |
| 424 | qCoff = 16; |
| 425 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 426 | ath_print(common, ATH_DBG_CALIBRATE, |
| 427 | "Chn %d : iCoff = 0x%x qCoff = 0x%x\n", |
| 428 | i, iCoff, qCoff); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 429 | |
| 430 | REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(i), |
| 431 | AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF, |
| 432 | iCoff); |
| 433 | REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(i), |
| 434 | AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF, |
| 435 | qCoff); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 436 | ath_print(common, ATH_DBG_CALIBRATE, |
| 437 | "IQ Cal and Correction done for Chain %d\n", |
| 438 | i); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 439 | } |
| 440 | } |
| 441 | |
| 442 | REG_SET_BIT(ah, AR_PHY_TIMING_CTRL4(0), |
| 443 | AR_PHY_TIMING_CTRL4_IQCORR_ENABLE); |
| 444 | } |
| 445 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 446 | static void ath9k_hw_adc_gaincal_calibrate(struct ath_hw *ah, u8 numChains) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 447 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 448 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 449 | u32 iOddMeasOffset, iEvenMeasOffset, qOddMeasOffset, qEvenMeasOffset; |
| 450 | u32 qGainMismatch, iGainMismatch, val, i; |
| 451 | |
| 452 | for (i = 0; i < numChains; i++) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 453 | iOddMeasOffset = ah->totalAdcIOddPhase[i]; |
| 454 | iEvenMeasOffset = ah->totalAdcIEvenPhase[i]; |
| 455 | qOddMeasOffset = ah->totalAdcQOddPhase[i]; |
| 456 | qEvenMeasOffset = ah->totalAdcQEvenPhase[i]; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 457 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 458 | ath_print(common, ATH_DBG_CALIBRATE, |
| 459 | "Starting ADC Gain Cal for Chain %d\n", i); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 460 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 461 | ath_print(common, ATH_DBG_CALIBRATE, |
| 462 | "Chn %d pwr_meas_odd_i = 0x%08x\n", i, |
| 463 | iOddMeasOffset); |
| 464 | ath_print(common, ATH_DBG_CALIBRATE, |
| 465 | "Chn %d pwr_meas_even_i = 0x%08x\n", i, |
| 466 | iEvenMeasOffset); |
| 467 | ath_print(common, ATH_DBG_CALIBRATE, |
| 468 | "Chn %d pwr_meas_odd_q = 0x%08x\n", i, |
| 469 | qOddMeasOffset); |
| 470 | ath_print(common, ATH_DBG_CALIBRATE, |
| 471 | "Chn %d pwr_meas_even_q = 0x%08x\n", i, |
| 472 | qEvenMeasOffset); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 473 | |
| 474 | if (iOddMeasOffset != 0 && qEvenMeasOffset != 0) { |
| 475 | iGainMismatch = |
| 476 | ((iEvenMeasOffset * 32) / |
| 477 | iOddMeasOffset) & 0x3f; |
| 478 | qGainMismatch = |
| 479 | ((qOddMeasOffset * 32) / |
| 480 | qEvenMeasOffset) & 0x3f; |
| 481 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 482 | ath_print(common, ATH_DBG_CALIBRATE, |
| 483 | "Chn %d gain_mismatch_i = 0x%08x\n", i, |
| 484 | iGainMismatch); |
| 485 | ath_print(common, ATH_DBG_CALIBRATE, |
| 486 | "Chn %d gain_mismatch_q = 0x%08x\n", i, |
| 487 | qGainMismatch); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 488 | |
| 489 | val = REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i)); |
| 490 | val &= 0xfffff000; |
| 491 | val |= (qGainMismatch) | (iGainMismatch << 6); |
| 492 | REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i), val); |
| 493 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 494 | ath_print(common, ATH_DBG_CALIBRATE, |
| 495 | "ADC Gain Cal done for Chain %d\n", i); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 496 | } |
| 497 | } |
| 498 | |
| 499 | REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0), |
| 500 | REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0)) | |
| 501 | AR_PHY_NEW_ADC_GAIN_CORR_ENABLE); |
| 502 | } |
| 503 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 504 | static void ath9k_hw_adc_dccal_calibrate(struct ath_hw *ah, u8 numChains) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 505 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 506 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 507 | u32 iOddMeasOffset, iEvenMeasOffset, val, i; |
| 508 | int32_t qOddMeasOffset, qEvenMeasOffset, qDcMismatch, iDcMismatch; |
Sujith | cbfe946 | 2009-04-13 21:56:56 +0530 | [diff] [blame] | 509 | const struct ath9k_percal_data *calData = |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 510 | ah->cal_list_curr->calData; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 511 | u32 numSamples = |
| 512 | (1 << (calData->calCountMax + 5)) * calData->calNumSamples; |
| 513 | |
| 514 | for (i = 0; i < numChains; i++) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 515 | iOddMeasOffset = ah->totalAdcDcOffsetIOddPhase[i]; |
| 516 | iEvenMeasOffset = ah->totalAdcDcOffsetIEvenPhase[i]; |
| 517 | qOddMeasOffset = ah->totalAdcDcOffsetQOddPhase[i]; |
| 518 | qEvenMeasOffset = ah->totalAdcDcOffsetQEvenPhase[i]; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 519 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 520 | ath_print(common, ATH_DBG_CALIBRATE, |
| 521 | "Starting ADC DC Offset Cal for Chain %d\n", i); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 522 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 523 | ath_print(common, ATH_DBG_CALIBRATE, |
| 524 | "Chn %d pwr_meas_odd_i = %d\n", i, |
| 525 | iOddMeasOffset); |
| 526 | ath_print(common, ATH_DBG_CALIBRATE, |
| 527 | "Chn %d pwr_meas_even_i = %d\n", i, |
| 528 | iEvenMeasOffset); |
| 529 | ath_print(common, ATH_DBG_CALIBRATE, |
| 530 | "Chn %d pwr_meas_odd_q = %d\n", i, |
| 531 | qOddMeasOffset); |
| 532 | ath_print(common, ATH_DBG_CALIBRATE, |
| 533 | "Chn %d pwr_meas_even_q = %d\n", i, |
| 534 | qEvenMeasOffset); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 535 | |
| 536 | iDcMismatch = (((iEvenMeasOffset - iOddMeasOffset) * 2) / |
| 537 | numSamples) & 0x1ff; |
| 538 | qDcMismatch = (((qOddMeasOffset - qEvenMeasOffset) * 2) / |
| 539 | numSamples) & 0x1ff; |
| 540 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 541 | ath_print(common, ATH_DBG_CALIBRATE, |
| 542 | "Chn %d dc_offset_mismatch_i = 0x%08x\n", i, |
| 543 | iDcMismatch); |
| 544 | ath_print(common, ATH_DBG_CALIBRATE, |
| 545 | "Chn %d dc_offset_mismatch_q = 0x%08x\n", i, |
| 546 | qDcMismatch); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 547 | |
| 548 | val = REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i)); |
| 549 | val &= 0xc0000fff; |
| 550 | val |= (qDcMismatch << 12) | (iDcMismatch << 21); |
| 551 | REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i), val); |
| 552 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 553 | ath_print(common, ATH_DBG_CALIBRATE, |
| 554 | "ADC DC Offset Cal done for Chain %d\n", i); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0), |
| 558 | REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0)) | |
| 559 | AR_PHY_NEW_ADC_DC_OFFSET_CORR_ENABLE); |
| 560 | } |
| 561 | |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 562 | /* This is done for the currently configured channel */ |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 563 | bool ath9k_hw_reset_calvalid(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 564 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 565 | struct ath_common *common = ath9k_hw_common(ah); |
| 566 | struct ieee80211_conf *conf = &common->hw->conf; |
Sujith | cbfe946 | 2009-04-13 21:56:56 +0530 | [diff] [blame] | 567 | struct ath9k_cal_list *currCal = ah->cal_list_curr; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 568 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 569 | if (!ah->curchan) |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 570 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 571 | |
| 572 | if (!AR_SREV_9100(ah) && !AR_SREV_9160_10_OR_LATER(ah)) |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 573 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 574 | |
| 575 | if (currCal == NULL) |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 576 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 577 | |
| 578 | if (currCal->calState != CAL_DONE) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 579 | ath_print(common, ATH_DBG_CALIBRATE, |
| 580 | "Calibration state incorrect, %d\n", |
| 581 | currCal->calState); |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 582 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 583 | } |
| 584 | |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 585 | if (!ath9k_hw_iscal_supported(ah, currCal->calData->calType)) |
| 586 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 587 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 588 | ath_print(common, ATH_DBG_CALIBRATE, |
| 589 | "Resetting Cal %d state for channel %u\n", |
| 590 | currCal->calData->calType, conf->channel->center_freq); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 591 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 592 | ah->curchan->CalValid &= ~currCal->calData->calType; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 593 | currCal->calState = CAL_WAITING; |
| 594 | |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 595 | return false; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 596 | } |
| 597 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 598 | void ath9k_hw_start_nfcal(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 599 | { |
| 600 | REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, |
| 601 | AR_PHY_AGC_CONTROL_ENABLE_NF); |
| 602 | REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, |
| 603 | AR_PHY_AGC_CONTROL_NO_UPDATE_NF); |
| 604 | REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF); |
| 605 | } |
| 606 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 607 | void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 608 | { |
| 609 | struct ath9k_nfcal_hist *h; |
| 610 | int i, j; |
| 611 | int32_t val; |
| 612 | const u32 ar5416_cca_regs[6] = { |
| 613 | AR_PHY_CCA, |
| 614 | AR_PHY_CH1_CCA, |
| 615 | AR_PHY_CH2_CCA, |
| 616 | AR_PHY_EXT_CCA, |
| 617 | AR_PHY_CH1_EXT_CCA, |
| 618 | AR_PHY_CH2_EXT_CCA |
| 619 | }; |
Senthil Balasubramanian | ce143bb | 2009-09-17 09:27:33 +0530 | [diff] [blame] | 620 | u8 chainmask, rx_chain_status; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 621 | |
Senthil Balasubramanian | ce143bb | 2009-09-17 09:27:33 +0530 | [diff] [blame] | 622 | rx_chain_status = REG_READ(ah, AR_PHY_RX_CHAINMASK); |
Sujith | 5dad40c | 2009-01-23 11:20:55 +0530 | [diff] [blame] | 623 | if (AR_SREV_9285(ah)) |
| 624 | chainmask = 0x9; |
Senthil Balasubramanian | ce143bb | 2009-09-17 09:27:33 +0530 | [diff] [blame] | 625 | else if (AR_SREV_9280(ah) || AR_SREV_9287(ah)) { |
| 626 | if ((rx_chain_status & 0x2) || (rx_chain_status & 0x4)) |
| 627 | chainmask = 0x1B; |
| 628 | else |
| 629 | chainmask = 0x09; |
| 630 | } else { |
| 631 | if (rx_chain_status & 0x4) |
| 632 | chainmask = 0x3F; |
| 633 | else if (rx_chain_status & 0x2) |
| 634 | chainmask = 0x1B; |
| 635 | else |
| 636 | chainmask = 0x09; |
| 637 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 638 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 639 | h = ah->nfCalHist; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 640 | |
| 641 | for (i = 0; i < NUM_NF_READINGS; i++) { |
| 642 | if (chainmask & (1 << i)) { |
| 643 | val = REG_READ(ah, ar5416_cca_regs[i]); |
| 644 | val &= 0xFFFFFE00; |
| 645 | val |= (((u32) (h[i].privNF) << 1) & 0x1ff); |
| 646 | REG_WRITE(ah, ar5416_cca_regs[i], val); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL, |
| 651 | AR_PHY_AGC_CONTROL_ENABLE_NF); |
| 652 | REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL, |
| 653 | AR_PHY_AGC_CONTROL_NO_UPDATE_NF); |
| 654 | REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF); |
| 655 | |
| 656 | for (j = 0; j < 1000; j++) { |
| 657 | if ((REG_READ(ah, AR_PHY_AGC_CONTROL) & |
| 658 | AR_PHY_AGC_CONTROL_NF) == 0) |
| 659 | break; |
| 660 | udelay(10); |
| 661 | } |
| 662 | |
| 663 | for (i = 0; i < NUM_NF_READINGS; i++) { |
| 664 | if (chainmask & (1 << i)) { |
| 665 | val = REG_READ(ah, ar5416_cca_regs[i]); |
| 666 | val &= 0xFFFFFE00; |
| 667 | val |= (((u32) (-50) << 1) & 0x1ff); |
| 668 | REG_WRITE(ah, ar5416_cca_regs[i], val); |
| 669 | } |
| 670 | } |
| 671 | } |
| 672 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 673 | int16_t ath9k_hw_getnf(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 674 | struct ath9k_channel *chan) |
| 675 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 676 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 677 | int16_t nf, nfThresh; |
| 678 | int16_t nfarray[NUM_NF_READINGS] = { 0 }; |
| 679 | struct ath9k_nfcal_hist *h; |
Luis R. Rodriguez | 76061ab | 2008-12-23 15:58:41 -0800 | [diff] [blame] | 680 | struct ieee80211_channel *c = chan->chan; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 681 | |
| 682 | chan->channelFlags &= (~CHANNEL_CW_INT); |
| 683 | if (REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 684 | ath_print(common, ATH_DBG_CALIBRATE, |
| 685 | "NF did not complete in calibration window\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 686 | nf = 0; |
| 687 | chan->rawNoiseFloor = nf; |
| 688 | return chan->rawNoiseFloor; |
| 689 | } else { |
| 690 | ath9k_hw_do_getnf(ah, nfarray); |
| 691 | nf = nfarray[0]; |
Luis R. Rodriguez | 76061ab | 2008-12-23 15:58:41 -0800 | [diff] [blame] | 692 | if (getNoiseFloorThresh(ah, c->band, &nfThresh) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 693 | && nf > nfThresh) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 694 | ath_print(common, ATH_DBG_CALIBRATE, |
| 695 | "noise floor failed detected; " |
| 696 | "detected %d, threshold %d\n", |
| 697 | nf, nfThresh); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 698 | chan->channelFlags |= CHANNEL_CW_INT; |
| 699 | } |
| 700 | } |
| 701 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 702 | h = ah->nfCalHist; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 703 | |
| 704 | ath9k_hw_update_nfcal_hist_buffer(h, nfarray); |
| 705 | chan->rawNoiseFloor = h[0].privNF; |
| 706 | |
| 707 | return chan->rawNoiseFloor; |
| 708 | } |
| 709 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 710 | void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 711 | { |
| 712 | int i, j; |
Senthil Balasubramanian | a59b5a5 | 2009-07-14 20:17:07 -0400 | [diff] [blame] | 713 | s16 noise_floor; |
| 714 | |
| 715 | if (AR_SREV_9280(ah)) |
| 716 | noise_floor = AR_PHY_CCA_MAX_AR9280_GOOD_VALUE; |
| 717 | else if (AR_SREV_9285(ah)) |
| 718 | noise_floor = AR_PHY_CCA_MAX_AR9285_GOOD_VALUE; |
Vivek Natarajan | 6170cd5 | 2009-09-17 09:24:24 +0530 | [diff] [blame] | 719 | else if (AR_SREV_9287(ah)) |
| 720 | noise_floor = AR_PHY_CCA_MAX_AR9287_GOOD_VALUE; |
Senthil Balasubramanian | a59b5a5 | 2009-07-14 20:17:07 -0400 | [diff] [blame] | 721 | else |
| 722 | noise_floor = AR_PHY_CCA_MAX_AR5416_GOOD_VALUE; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 723 | |
| 724 | for (i = 0; i < NUM_NF_READINGS; i++) { |
| 725 | ah->nfCalHist[i].currIndex = 0; |
Senthil Balasubramanian | a59b5a5 | 2009-07-14 20:17:07 -0400 | [diff] [blame] | 726 | ah->nfCalHist[i].privNF = noise_floor; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 727 | ah->nfCalHist[i].invalidNFcount = |
| 728 | AR_PHY_CCA_FILTERWINDOW_LENGTH; |
| 729 | for (j = 0; j < ATH9K_NF_CAL_HIST_MAX; j++) { |
Senthil Balasubramanian | a59b5a5 | 2009-07-14 20:17:07 -0400 | [diff] [blame] | 730 | ah->nfCalHist[i].nfCalBuffer[j] = noise_floor; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 731 | } |
| 732 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 733 | } |
| 734 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 735 | s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 736 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 737 | s16 nf; |
| 738 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 739 | if (chan->rawNoiseFloor == 0) |
Luis R. Rodriguez | e56db71 | 2008-12-23 15:58:47 -0800 | [diff] [blame] | 740 | nf = -96; |
| 741 | else |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 742 | nf = chan->rawNoiseFloor; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 743 | |
| 744 | if (!ath9k_hw_nf_in_range(ah, nf)) |
| 745 | nf = ATH_DEFAULT_NOISE_FLOOR; |
| 746 | |
| 747 | return nf; |
| 748 | } |
| 749 | |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 750 | static void ath9k_olc_temp_compensation(struct ath_hw *ah) |
| 751 | { |
| 752 | u32 rddata, i; |
Vivek Natarajan | db91f2e | 2009-08-14 11:27:16 +0530 | [diff] [blame] | 753 | int delta, currPDADC, regval, slope; |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 754 | |
| 755 | rddata = REG_READ(ah, AR_PHY_TX_PWRCTRL4); |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 756 | currPDADC = MS(rddata, AR_PHY_TX_PWRCTRL_PD_AVG_OUT); |
| 757 | |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 758 | |
Vivek Natarajan | db91f2e | 2009-08-14 11:27:16 +0530 | [diff] [blame] | 759 | if (OLC_FOR_AR9287_10_LATER) { |
| 760 | if (ah->initPDADC == 0 || currPDADC == 0) { |
| 761 | return; |
| 762 | } else { |
| 763 | slope = ah->eep_ops->get_eeprom(ah, EEP_TEMPSENSE_SLOPE); |
| 764 | if (slope == 0) |
| 765 | delta = 0; |
| 766 | else |
| 767 | delta = ((currPDADC - ah->initPDADC)*4) / slope; |
| 768 | REG_RMW_FIELD(ah, AR_PHY_CH0_TX_PWRCTRL11, |
| 769 | AR_PHY_TX_PWRCTRL_OLPC_TEMP_COMP, delta); |
| 770 | REG_RMW_FIELD(ah, AR_PHY_CH1_TX_PWRCTRL11, |
| 771 | AR_PHY_TX_PWRCTRL_OLPC_TEMP_COMP, delta); |
| 772 | } |
| 773 | } else { |
| 774 | if (ah->eep_ops->get_eeprom(ah, EEP_DAC_HPWR_5G)) |
| 775 | delta = (currPDADC - ah->initPDADC + 4) / 8; |
| 776 | else |
| 777 | delta = (currPDADC - ah->initPDADC + 5) / 10; |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 778 | |
Vivek Natarajan | db91f2e | 2009-08-14 11:27:16 +0530 | [diff] [blame] | 779 | if (delta != ah->PDADCdelta) { |
| 780 | ah->PDADCdelta = delta; |
| 781 | for (i = 1; i < AR9280_TX_GAIN_TABLE_SIZE; i++) { |
| 782 | regval = ah->originalGain[i] - delta; |
| 783 | if (regval < 0) |
| 784 | regval = 0; |
| 785 | |
| 786 | REG_RMW_FIELD(ah, AR_PHY_TX_GAIN_TBL1 + i * 4, |
| 787 | AR_PHY_TX_GAIN, regval); |
| 788 | } |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 789 | } |
| 790 | } |
| 791 | } |
| 792 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 793 | static void ath9k_hw_9271_pa_cal(struct ath_hw *ah) |
| 794 | { |
| 795 | u32 regVal; |
| 796 | unsigned int i; |
| 797 | u32 regList [][2] = { |
| 798 | { 0x786c, 0 }, |
| 799 | { 0x7854, 0 }, |
| 800 | { 0x7820, 0 }, |
| 801 | { 0x7824, 0 }, |
| 802 | { 0x7868, 0 }, |
| 803 | { 0x783c, 0 }, |
| 804 | { 0x7838, 0 } , |
| 805 | { 0x7828, 0 } , |
| 806 | }; |
| 807 | |
| 808 | for (i = 0; i < ARRAY_SIZE(regList); i++) |
| 809 | regList[i][1] = REG_READ(ah, regList[i][0]); |
| 810 | |
| 811 | regVal = REG_READ(ah, 0x7834); |
| 812 | regVal &= (~(0x1)); |
| 813 | REG_WRITE(ah, 0x7834, regVal); |
| 814 | regVal = REG_READ(ah, 0x9808); |
| 815 | regVal |= (0x1 << 27); |
| 816 | REG_WRITE(ah, 0x9808, regVal); |
| 817 | |
| 818 | /* 786c,b23,1, pwddac=1 */ |
| 819 | REG_RMW_FIELD(ah, AR9285_AN_TOP3, AR9285_AN_TOP3_PWDDAC, 1); |
| 820 | /* 7854, b5,1, pdrxtxbb=1 */ |
| 821 | REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDRXTXBB1, 1); |
| 822 | /* 7854, b7,1, pdv2i=1 */ |
| 823 | REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDV2I, 1); |
| 824 | /* 7854, b8,1, pddacinterface=1 */ |
| 825 | REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDDACIF, 1); |
| 826 | /* 7824,b12,0, offcal=0 */ |
| 827 | REG_RMW_FIELD(ah, AR9285_AN_RF2G2, AR9285_AN_RF2G2_OFFCAL, 0); |
| 828 | /* 7838, b1,0, pwddb=0 */ |
| 829 | REG_RMW_FIELD(ah, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PWDDB, 0); |
| 830 | /* 7820,b11,0, enpacal=0 */ |
| 831 | REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_ENPACAL, 0); |
| 832 | /* 7820,b25,1, pdpadrv1=0 */ |
| 833 | REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV1, 0); |
| 834 | /* 7820,b24,0, pdpadrv2=0 */ |
| 835 | REG_RMW_FIELD(ah, AR9285_AN_RF2G1,AR9285_AN_RF2G1_PDPADRV2,0); |
| 836 | /* 7820,b23,0, pdpaout=0 */ |
| 837 | REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPAOUT, 0); |
| 838 | /* 783c,b14-16,7, padrvgn2tab_0=7 */ |
| 839 | REG_RMW_FIELD(ah, AR9285_AN_RF2G8,AR9285_AN_RF2G8_PADRVGN2TAB0, 7); |
| 840 | /* |
| 841 | * 7838,b29-31,0, padrvgn1tab_0=0 |
| 842 | * does not matter since we turn it off |
| 843 | */ |
| 844 | REG_RMW_FIELD(ah, AR9285_AN_RF2G7,AR9285_AN_RF2G7_PADRVGN2TAB0, 0); |
| 845 | |
| 846 | REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9271_AN_RF2G3_CCOMP, 0xfff); |
| 847 | |
| 848 | /* Set: |
| 849 | * localmode=1,bmode=1,bmoderxtx=1,synthon=1, |
| 850 | * txon=1,paon=1,oscon=1,synthon_force=1 |
| 851 | */ |
| 852 | REG_WRITE(ah, AR9285_AN_TOP2, 0xca0358a0); |
| 853 | udelay(30); |
| 854 | REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9271_AN_RF2G6_OFFS, 0); |
| 855 | |
| 856 | /* find off_6_1; */ |
| 857 | for (i = 6; i >= 0; i--) { |
| 858 | regVal = REG_READ(ah, 0x7834); |
| 859 | regVal |= (1 << (20 + i)); |
| 860 | REG_WRITE(ah, 0x7834, regVal); |
| 861 | udelay(1); |
| 862 | //regVal = REG_READ(ah, 0x7834); |
| 863 | regVal &= (~(0x1 << (20 + i))); |
| 864 | regVal |= (MS(REG_READ(ah, 0x7840), AR9285_AN_RXTXBB1_SPARE9) |
| 865 | << (20 + i)); |
| 866 | REG_WRITE(ah, 0x7834, regVal); |
| 867 | } |
| 868 | |
| 869 | /* Empirical offset correction */ |
| 870 | #if 0 |
| 871 | REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9271_AN_RF2G6_OFFS, 0x20); |
| 872 | #endif |
| 873 | |
| 874 | regVal = REG_READ(ah, 0x7834); |
| 875 | regVal |= 0x1; |
| 876 | REG_WRITE(ah, 0x7834, regVal); |
| 877 | regVal = REG_READ(ah, 0x9808); |
| 878 | regVal &= (~(0x1 << 27)); |
| 879 | REG_WRITE(ah, 0x9808, regVal); |
| 880 | |
| 881 | for (i = 0; i < ARRAY_SIZE(regList); i++) |
| 882 | REG_WRITE(ah, regList[i][0], regList[i][1]); |
| 883 | } |
| 884 | |
Sujith | a13883b | 2009-08-26 08:39:40 +0530 | [diff] [blame] | 885 | static inline void ath9k_hw_9285_pa_cal(struct ath_hw *ah, bool is_reset) |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 886 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 887 | struct ath_common *common = ath9k_hw_common(ah); |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 888 | u32 regVal; |
| 889 | int i, offset, offs_6_1, offs_0; |
| 890 | u32 ccomp_org, reg_field; |
| 891 | u32 regList[][2] = { |
| 892 | { 0x786c, 0 }, |
| 893 | { 0x7854, 0 }, |
| 894 | { 0x7820, 0 }, |
| 895 | { 0x7824, 0 }, |
| 896 | { 0x7868, 0 }, |
| 897 | { 0x783c, 0 }, |
| 898 | { 0x7838, 0 }, |
| 899 | }; |
| 900 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 901 | ath_print(common, ATH_DBG_CALIBRATE, "Running PA Calibration\n"); |
Sujith | a13883b | 2009-08-26 08:39:40 +0530 | [diff] [blame] | 902 | |
Sujith | 20caf0d | 2009-08-26 08:39:52 +0530 | [diff] [blame] | 903 | /* PA CAL is not needed for high power solution */ |
| 904 | if (ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE) == |
| 905 | AR5416_EEP_TXGAIN_HIGH_POWER) |
| 906 | return; |
| 907 | |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 908 | if (AR_SREV_9285_11(ah)) { |
| 909 | REG_WRITE(ah, AR9285_AN_TOP4, (AR9285_AN_TOP4_DEFAULT | 0x14)); |
| 910 | udelay(10); |
| 911 | } |
| 912 | |
| 913 | for (i = 0; i < ARRAY_SIZE(regList); i++) |
| 914 | regList[i][1] = REG_READ(ah, regList[i][0]); |
| 915 | |
| 916 | regVal = REG_READ(ah, 0x7834); |
| 917 | regVal &= (~(0x1)); |
| 918 | REG_WRITE(ah, 0x7834, regVal); |
| 919 | regVal = REG_READ(ah, 0x9808); |
| 920 | regVal |= (0x1 << 27); |
| 921 | REG_WRITE(ah, 0x9808, regVal); |
| 922 | |
| 923 | REG_RMW_FIELD(ah, AR9285_AN_TOP3, AR9285_AN_TOP3_PWDDAC, 1); |
| 924 | REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDRXTXBB1, 1); |
| 925 | REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDV2I, 1); |
| 926 | REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDDACIF, 1); |
| 927 | REG_RMW_FIELD(ah, AR9285_AN_RF2G2, AR9285_AN_RF2G2_OFFCAL, 0); |
| 928 | REG_RMW_FIELD(ah, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PWDDB, 0); |
| 929 | REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_ENPACAL, 0); |
Sujith | 0abb096 | 2009-08-26 08:39:50 +0530 | [diff] [blame] | 930 | REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV1, 0); |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 931 | REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV2, 0); |
| 932 | REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPAOUT, 0); |
| 933 | REG_RMW_FIELD(ah, AR9285_AN_RF2G8, AR9285_AN_RF2G8_PADRVGN2TAB0, 7); |
| 934 | REG_RMW_FIELD(ah, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PADRVGN2TAB0, 0); |
| 935 | ccomp_org = MS(REG_READ(ah, AR9285_AN_RF2G6), AR9285_AN_RF2G6_CCOMP); |
Sujith | 0abb096 | 2009-08-26 08:39:50 +0530 | [diff] [blame] | 936 | REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_CCOMP, 0xf); |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 937 | |
| 938 | REG_WRITE(ah, AR9285_AN_TOP2, 0xca0358a0); |
| 939 | udelay(30); |
| 940 | REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_OFFS, 0); |
| 941 | REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, 0); |
| 942 | |
| 943 | for (i = 6; i > 0; i--) { |
| 944 | regVal = REG_READ(ah, 0x7834); |
| 945 | regVal |= (1 << (19 + i)); |
| 946 | REG_WRITE(ah, 0x7834, regVal); |
| 947 | udelay(1); |
Sujith | edbf51f | 2009-09-17 09:28:41 +0530 | [diff] [blame] | 948 | regVal = REG_READ(ah, 0x7834); |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 949 | regVal &= (~(0x1 << (19 + i))); |
| 950 | reg_field = MS(REG_READ(ah, 0x7840), AR9285_AN_RXTXBB1_SPARE9); |
| 951 | regVal |= (reg_field << (19 + i)); |
| 952 | REG_WRITE(ah, 0x7834, regVal); |
| 953 | } |
| 954 | |
| 955 | REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, 1); |
| 956 | udelay(1); |
| 957 | reg_field = MS(REG_READ(ah, AR9285_AN_RF2G9), AR9285_AN_RXTXBB1_SPARE9); |
| 958 | REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, reg_field); |
| 959 | offs_6_1 = MS(REG_READ(ah, AR9285_AN_RF2G6), AR9285_AN_RF2G6_OFFS); |
| 960 | offs_0 = MS(REG_READ(ah, AR9285_AN_RF2G3), AR9285_AN_RF2G3_PDVCCOMP); |
| 961 | |
| 962 | offset = (offs_6_1<<1) | offs_0; |
| 963 | offset = offset - 0; |
| 964 | offs_6_1 = offset>>1; |
| 965 | offs_0 = offset & 1; |
| 966 | |
Sujith | a13883b | 2009-08-26 08:39:40 +0530 | [diff] [blame] | 967 | if ((!is_reset) && (ah->pacal_info.prev_offset == offset)) { |
| 968 | if (ah->pacal_info.max_skipcount < MAX_PACAL_SKIPCOUNT) |
| 969 | ah->pacal_info.max_skipcount = |
| 970 | 2 * ah->pacal_info.max_skipcount; |
| 971 | ah->pacal_info.skipcount = ah->pacal_info.max_skipcount; |
| 972 | } else { |
| 973 | ah->pacal_info.max_skipcount = 1; |
| 974 | ah->pacal_info.skipcount = 0; |
| 975 | ah->pacal_info.prev_offset = offset; |
| 976 | } |
| 977 | |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 978 | REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_OFFS, offs_6_1); |
| 979 | REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, offs_0); |
| 980 | |
| 981 | regVal = REG_READ(ah, 0x7834); |
| 982 | regVal |= 0x1; |
| 983 | REG_WRITE(ah, 0x7834, regVal); |
| 984 | regVal = REG_READ(ah, 0x9808); |
| 985 | regVal &= (~(0x1 << 27)); |
| 986 | REG_WRITE(ah, 0x9808, regVal); |
| 987 | |
| 988 | for (i = 0; i < ARRAY_SIZE(regList); i++) |
| 989 | REG_WRITE(ah, regList[i][0], regList[i][1]); |
| 990 | |
| 991 | REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_CCOMP, ccomp_org); |
| 992 | |
| 993 | if (AR_SREV_9285_11(ah)) |
| 994 | REG_WRITE(ah, AR9285_AN_TOP4, AR9285_AN_TOP4_DEFAULT); |
| 995 | |
| 996 | } |
| 997 | |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 998 | bool ath9k_hw_calibrate(struct ath_hw *ah, struct ath9k_channel *chan, |
Sujith | 379f044 | 2009-04-13 21:56:48 +0530 | [diff] [blame] | 999 | u8 rxchainmask, bool longcal) |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 1000 | { |
Sujith | 379f044 | 2009-04-13 21:56:48 +0530 | [diff] [blame] | 1001 | bool iscaldone = true; |
Sujith | cbfe946 | 2009-04-13 21:56:56 +0530 | [diff] [blame] | 1002 | struct ath9k_cal_list *currCal = ah->cal_list_curr; |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 1003 | |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 1004 | if (currCal && |
| 1005 | (currCal->calState == CAL_RUNNING || |
| 1006 | currCal->calState == CAL_WAITING)) { |
Sujith | 379f044 | 2009-04-13 21:56:48 +0530 | [diff] [blame] | 1007 | iscaldone = ath9k_hw_per_calibration(ah, chan, |
| 1008 | rxchainmask, currCal); |
| 1009 | if (iscaldone) { |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 1010 | ah->cal_list_curr = currCal = currCal->calNext; |
| 1011 | |
| 1012 | if (currCal->calState == CAL_WAITING) { |
Sujith | 379f044 | 2009-04-13 21:56:48 +0530 | [diff] [blame] | 1013 | iscaldone = false; |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 1014 | ath9k_hw_reset_calibration(ah, currCal); |
| 1015 | } |
| 1016 | } |
| 1017 | } |
| 1018 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1019 | /* Do NF cal only at longer intervals */ |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 1020 | if (longcal) { |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1021 | /* Do periodic PAOffset Cal */ |
| 1022 | if (AR_SREV_9271(ah)) |
| 1023 | ath9k_hw_9271_pa_cal(ah); |
Sujith | a13883b | 2009-08-26 08:39:40 +0530 | [diff] [blame] | 1024 | else if (AR_SREV_9285_11_OR_LATER(ah)) { |
| 1025 | if (!ah->pacal_info.skipcount) |
| 1026 | ath9k_hw_9285_pa_cal(ah, false); |
| 1027 | else |
| 1028 | ah->pacal_info.skipcount--; |
| 1029 | } |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 1030 | |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 1031 | if (OLC_FOR_AR9280_20_LATER || OLC_FOR_AR9287_10_LATER) |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 1032 | ath9k_olc_temp_compensation(ah); |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1033 | |
| 1034 | /* Get the value from the previous NF cal and update history buffer */ |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 1035 | ath9k_hw_getnf(ah, chan); |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1036 | |
| 1037 | /* |
| 1038 | * Load the NF from history buffer of the current channel. |
| 1039 | * NF is slow time-variant, so it is OK to use a historical value. |
| 1040 | */ |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 1041 | ath9k_hw_loadnf(ah, ah->curchan); |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1042 | |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 1043 | ath9k_hw_start_nfcal(ah); |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 1044 | } |
| 1045 | |
Sujith | 379f044 | 2009-04-13 21:56:48 +0530 | [diff] [blame] | 1046 | return iscaldone; |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 1047 | } |
| 1048 | |
Luis R. Rodriguez | 15cc0f1 | 2009-03-09 22:09:42 -0400 | [diff] [blame] | 1049 | static bool ar9285_clc(struct ath_hw *ah, struct ath9k_channel *chan) |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 1050 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1051 | struct ath_common *common = ath9k_hw_common(ah); |
| 1052 | |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 1053 | REG_SET_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_CL_CAL_ENABLE); |
Sujith | db2f63f | 2009-04-13 21:56:41 +0530 | [diff] [blame] | 1054 | if (IS_CHAN_HT20(chan)) { |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 1055 | REG_SET_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_PARALLEL_CAL_ENABLE); |
| 1056 | REG_SET_BIT(ah, AR_PHY_TURBO, AR_PHY_FC_DYN2040_EN); |
| 1057 | REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL, |
| 1058 | AR_PHY_AGC_CONTROL_FLTR_CAL); |
| 1059 | REG_CLR_BIT(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_CAL_ENABLE); |
| 1060 | REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL); |
| 1061 | if (!ath9k_hw_wait(ah, AR_PHY_AGC_CONTROL, |
| 1062 | AR_PHY_AGC_CONTROL_CAL, 0, AH_WAIT_TIMEOUT)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1063 | ath_print(common, ATH_DBG_CALIBRATE, "offset " |
| 1064 | "calibration failed to complete in " |
| 1065 | "1ms; noisy ??\n"); |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 1066 | return false; |
| 1067 | } |
| 1068 | REG_CLR_BIT(ah, AR_PHY_TURBO, AR_PHY_FC_DYN2040_EN); |
| 1069 | REG_CLR_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_PARALLEL_CAL_ENABLE); |
| 1070 | REG_CLR_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_CL_CAL_ENABLE); |
| 1071 | } |
| 1072 | REG_CLR_BIT(ah, AR_PHY_ADC_CTL, AR_PHY_ADC_CTL_OFF_PWDADC); |
| 1073 | REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_FLTR_CAL); |
| 1074 | REG_SET_BIT(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_CAL_ENABLE); |
| 1075 | REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL); |
| 1076 | if (!ath9k_hw_wait(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL, |
| 1077 | 0, AH_WAIT_TIMEOUT)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1078 | ath_print(common, ATH_DBG_CALIBRATE, "offset calibration " |
| 1079 | "failed to complete in 1ms; noisy ??\n"); |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 1080 | return false; |
| 1081 | } |
| 1082 | |
| 1083 | REG_SET_BIT(ah, AR_PHY_ADC_CTL, AR_PHY_ADC_CTL_OFF_PWDADC); |
| 1084 | REG_CLR_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_CL_CAL_ENABLE); |
| 1085 | REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_FLTR_CAL); |
| 1086 | |
| 1087 | return true; |
| 1088 | } |
| 1089 | |
Sujith | 04d19dd | 2009-04-13 21:56:59 +0530 | [diff] [blame] | 1090 | bool ath9k_hw_init_cal(struct ath_hw *ah, struct ath9k_channel *chan) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1091 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1092 | struct ath_common *common = ath9k_hw_common(ah); |
| 1093 | |
Gabor Juhos | f9dd6b5 | 2009-05-06 09:47:30 +0200 | [diff] [blame] | 1094 | if (AR_SREV_9285_12_OR_LATER(ah)) { |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 1095 | if (!ar9285_clc(ah, chan)) |
| 1096 | return false; |
Sujith | 04d19dd | 2009-04-13 21:56:59 +0530 | [diff] [blame] | 1097 | } else { |
| 1098 | if (AR_SREV_9280_10_OR_LATER(ah)) { |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 1099 | if (!AR_SREV_9287_10_OR_LATER(ah)) |
| 1100 | REG_CLR_BIT(ah, AR_PHY_ADC_CTL, |
| 1101 | AR_PHY_ADC_CTL_OFF_PWDADC); |
| 1102 | REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, |
| 1103 | AR_PHY_AGC_CONTROL_FLTR_CAL); |
Sujith | 04d19dd | 2009-04-13 21:56:59 +0530 | [diff] [blame] | 1104 | } |
Sujith | edf7c06 | 2009-02-12 10:06:49 +0530 | [diff] [blame] | 1105 | |
Sujith | 04d19dd | 2009-04-13 21:56:59 +0530 | [diff] [blame] | 1106 | /* Calibrate the AGC */ |
Sujith | edf7c06 | 2009-02-12 10:06:49 +0530 | [diff] [blame] | 1107 | REG_WRITE(ah, AR_PHY_AGC_CONTROL, |
Sujith | 04d19dd | 2009-04-13 21:56:59 +0530 | [diff] [blame] | 1108 | REG_READ(ah, AR_PHY_AGC_CONTROL) | |
| 1109 | AR_PHY_AGC_CONTROL_CAL); |
Sujith | edf7c06 | 2009-02-12 10:06:49 +0530 | [diff] [blame] | 1110 | |
Sujith | 04d19dd | 2009-04-13 21:56:59 +0530 | [diff] [blame] | 1111 | /* Poll for offset calibration complete */ |
| 1112 | if (!ath9k_hw_wait(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL, |
| 1113 | 0, AH_WAIT_TIMEOUT)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1114 | ath_print(common, ATH_DBG_CALIBRATE, |
| 1115 | "offset calibration failed to " |
| 1116 | "complete in 1ms; noisy environment?\n"); |
Sujith | edf7c06 | 2009-02-12 10:06:49 +0530 | [diff] [blame] | 1117 | return false; |
| 1118 | } |
| 1119 | |
Sujith | 04d19dd | 2009-04-13 21:56:59 +0530 | [diff] [blame] | 1120 | if (AR_SREV_9280_10_OR_LATER(ah)) { |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 1121 | if (!AR_SREV_9287_10_OR_LATER(ah)) |
| 1122 | REG_SET_BIT(ah, AR_PHY_ADC_CTL, |
| 1123 | AR_PHY_ADC_CTL_OFF_PWDADC); |
| 1124 | REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL, |
| 1125 | AR_PHY_AGC_CONTROL_FLTR_CAL); |
Sujith | 04d19dd | 2009-04-13 21:56:59 +0530 | [diff] [blame] | 1126 | } |
Sujith | edf7c06 | 2009-02-12 10:06:49 +0530 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | /* Do PA Calibration */ |
Gabor Juhos | f9dd6b5 | 2009-05-06 09:47:30 +0200 | [diff] [blame] | 1130 | if (AR_SREV_9285_11_OR_LATER(ah)) |
Sujith | a13883b | 2009-08-26 08:39:40 +0530 | [diff] [blame] | 1131 | ath9k_hw_9285_pa_cal(ah, true); |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1132 | |
Sujith | 04d19dd | 2009-04-13 21:56:59 +0530 | [diff] [blame] | 1133 | /* Do NF Calibration after DC offset and other calibrations */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1134 | REG_WRITE(ah, AR_PHY_AGC_CONTROL, |
Sujith | 04d19dd | 2009-04-13 21:56:59 +0530 | [diff] [blame] | 1135 | REG_READ(ah, AR_PHY_AGC_CONTROL) | AR_PHY_AGC_CONTROL_NF); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1136 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1137 | ah->cal_list = ah->cal_list_last = ah->cal_list_curr = NULL; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1138 | |
Sujith | 04d19dd | 2009-04-13 21:56:59 +0530 | [diff] [blame] | 1139 | /* Enable IQ, ADC Gain and ADC DC offset CALs */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1140 | if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah)) { |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 1141 | if (ath9k_hw_iscal_supported(ah, ADC_GAIN_CAL)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1142 | INIT_CAL(&ah->adcgain_caldata); |
| 1143 | INSERT_CAL(ah, &ah->adcgain_caldata); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1144 | ath_print(common, ATH_DBG_CALIBRATE, |
| 1145 | "enabling ADC Gain Calibration.\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1146 | } |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 1147 | if (ath9k_hw_iscal_supported(ah, ADC_DC_CAL)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1148 | INIT_CAL(&ah->adcdc_caldata); |
| 1149 | INSERT_CAL(ah, &ah->adcdc_caldata); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1150 | ath_print(common, ATH_DBG_CALIBRATE, |
| 1151 | "enabling ADC DC Calibration.\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1152 | } |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 1153 | if (ath9k_hw_iscal_supported(ah, IQ_MISMATCH_CAL)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1154 | INIT_CAL(&ah->iq_caldata); |
| 1155 | INSERT_CAL(ah, &ah->iq_caldata); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1156 | ath_print(common, ATH_DBG_CALIBRATE, |
| 1157 | "enabling IQ Calibration.\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1158 | } |
| 1159 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1160 | ah->cal_list_curr = ah->cal_list; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1161 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1162 | if (ah->cal_list_curr) |
| 1163 | ath9k_hw_reset_calibration(ah, ah->cal_list_curr); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1164 | } |
| 1165 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 1166 | chan->CalValid = 0; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1167 | |
| 1168 | return true; |
| 1169 | } |
| 1170 | |
Sujith | cbfe946 | 2009-04-13 21:56:56 +0530 | [diff] [blame] | 1171 | const struct ath9k_percal_data iq_cal_multi_sample = { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1172 | IQ_MISMATCH_CAL, |
| 1173 | MAX_CAL_SAMPLES, |
| 1174 | PER_MIN_LOG_COUNT, |
| 1175 | ath9k_hw_iqcal_collect, |
| 1176 | ath9k_hw_iqcalibrate |
| 1177 | }; |
Sujith | cbfe946 | 2009-04-13 21:56:56 +0530 | [diff] [blame] | 1178 | const struct ath9k_percal_data iq_cal_single_sample = { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1179 | IQ_MISMATCH_CAL, |
| 1180 | MIN_CAL_SAMPLES, |
| 1181 | PER_MAX_LOG_COUNT, |
| 1182 | ath9k_hw_iqcal_collect, |
| 1183 | ath9k_hw_iqcalibrate |
| 1184 | }; |
Sujith | cbfe946 | 2009-04-13 21:56:56 +0530 | [diff] [blame] | 1185 | const struct ath9k_percal_data adc_gain_cal_multi_sample = { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1186 | ADC_GAIN_CAL, |
| 1187 | MAX_CAL_SAMPLES, |
| 1188 | PER_MIN_LOG_COUNT, |
| 1189 | ath9k_hw_adc_gaincal_collect, |
| 1190 | ath9k_hw_adc_gaincal_calibrate |
| 1191 | }; |
Sujith | cbfe946 | 2009-04-13 21:56:56 +0530 | [diff] [blame] | 1192 | const struct ath9k_percal_data adc_gain_cal_single_sample = { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1193 | ADC_GAIN_CAL, |
| 1194 | MIN_CAL_SAMPLES, |
| 1195 | PER_MAX_LOG_COUNT, |
| 1196 | ath9k_hw_adc_gaincal_collect, |
| 1197 | ath9k_hw_adc_gaincal_calibrate |
| 1198 | }; |
Sujith | cbfe946 | 2009-04-13 21:56:56 +0530 | [diff] [blame] | 1199 | const struct ath9k_percal_data adc_dc_cal_multi_sample = { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1200 | ADC_DC_CAL, |
| 1201 | MAX_CAL_SAMPLES, |
| 1202 | PER_MIN_LOG_COUNT, |
| 1203 | ath9k_hw_adc_dccal_collect, |
| 1204 | ath9k_hw_adc_dccal_calibrate |
| 1205 | }; |
Sujith | cbfe946 | 2009-04-13 21:56:56 +0530 | [diff] [blame] | 1206 | const struct ath9k_percal_data adc_dc_cal_single_sample = { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1207 | ADC_DC_CAL, |
| 1208 | MIN_CAL_SAMPLES, |
| 1209 | PER_MAX_LOG_COUNT, |
| 1210 | ath9k_hw_adc_dccal_collect, |
| 1211 | ath9k_hw_adc_dccal_calibrate |
| 1212 | }; |
Sujith | cbfe946 | 2009-04-13 21:56:56 +0530 | [diff] [blame] | 1213 | const struct ath9k_percal_data adc_init_dc_cal = { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1214 | ADC_DC_INIT_CAL, |
| 1215 | MIN_CAL_SAMPLES, |
| 1216 | INIT_LOG_COUNT, |
| 1217 | ath9k_hw_adc_dccal_collect, |
| 1218 | ath9k_hw_adc_dccal_calibrate |
| 1219 | }; |