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