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