blob: 26d87527acbd32f07613f6526fe086df651c6047 [file] [log] [blame]
Sujithf1dc5602008-10-29 10:16:30 +05301/*
Sujithcee075a2009-03-13 09:07:23 +05302 * Copyright (c) 2008-2009 Atheros Communications Inc.
Sujithf1dc5602008-10-29 10:16:30 +05303 *
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
Sujith394cf0a2009-02-09 13:26:54 +053017#include "ath9k.h"
Sujithf1dc5602008-10-29 10:16:30 +053018
Sujithf1dc5602008-10-29 10:16:30 +053019/* We can tune this as we go by monitoring really low values */
20#define ATH9K_NF_TOO_LOW -60
21
22/* AR5416 may return very high value (like -31 dBm), in those cases the nf
23 * is incorrect and we should use the static NF value. Later we can try to
24 * find out why they are reporting these values */
25
Sujithcbe61d82009-02-09 13:27:12 +053026static bool ath9k_hw_nf_in_range(struct ath_hw *ah, s16 nf)
Sujithf1dc5602008-10-29 10:16:30 +053027{
28 if (nf > ATH9K_NF_TOO_LOW) {
Sujith04bd4632008-11-28 22:18:05 +053029 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
30 "noise floor value detected (%d) is "
Sujithf1dc5602008-10-29 10:16:30 +053031 "lower than what we think is a "
32 "reasonable value (%d)\n",
Sujith04bd4632008-11-28 22:18:05 +053033 nf, ATH9K_NF_TOO_LOW);
Sujithf1dc5602008-10-29 10:16:30 +053034 return false;
35 }
36 return true;
37}
38
39static int16_t ath9k_hw_get_nf_hist_mid(int16_t *nfCalBuffer)
40{
41 int16_t nfval;
42 int16_t sort[ATH9K_NF_CAL_HIST_MAX];
43 int i, j;
44
45 for (i = 0; i < ATH9K_NF_CAL_HIST_MAX; i++)
46 sort[i] = nfCalBuffer[i];
47
48 for (i = 0; i < ATH9K_NF_CAL_HIST_MAX - 1; i++) {
49 for (j = 1; j < ATH9K_NF_CAL_HIST_MAX - i; j++) {
50 if (sort[j] > sort[j - 1]) {
51 nfval = sort[j];
52 sort[j] = sort[j - 1];
53 sort[j - 1] = nfval;
54 }
55 }
56 }
57 nfval = sort[(ATH9K_NF_CAL_HIST_MAX - 1) >> 1];
58
59 return nfval;
60}
61
62static void ath9k_hw_update_nfcal_hist_buffer(struct ath9k_nfcal_hist *h,
63 int16_t *nfarray)
64{
65 int i;
66
67 for (i = 0; i < NUM_NF_READINGS; i++) {
68 h[i].nfCalBuffer[h[i].currIndex] = nfarray[i];
69
70 if (++h[i].currIndex >= ATH9K_NF_CAL_HIST_MAX)
71 h[i].currIndex = 0;
72
73 if (h[i].invalidNFcount > 0) {
74 if (nfarray[i] < AR_PHY_CCA_MIN_BAD_VALUE ||
75 nfarray[i] > AR_PHY_CCA_MAX_HIGH_VALUE) {
76 h[i].invalidNFcount = ATH9K_NF_CAL_HIST_MAX;
77 } else {
78 h[i].invalidNFcount--;
79 h[i].privNF = nfarray[i];
80 }
81 } else {
82 h[i].privNF =
83 ath9k_hw_get_nf_hist_mid(h[i].nfCalBuffer);
84 }
85 }
86 return;
87}
88
Sujithcbe61d82009-02-09 13:27:12 +053089static void ath9k_hw_do_getnf(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +053090 int16_t nfarray[NUM_NF_READINGS])
91{
92 int16_t nf;
93
94 if (AR_SREV_9280_10_OR_LATER(ah))
95 nf = MS(REG_READ(ah, AR_PHY_CCA), AR9280_PHY_MINCCA_PWR);
96 else
97 nf = MS(REG_READ(ah, AR_PHY_CCA), AR_PHY_MINCCA_PWR);
98
99 if (nf & 0x100)
100 nf = 0 - ((nf ^ 0x1ff) + 1);
101 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
102 "NF calibrated [ctl] [chain 0] is %d\n", nf);
103 nfarray[0] = nf;
104
Senthil Balasubramanian793c5922009-01-26 20:28:14 +0530105 if (!AR_SREV_9285(ah)) {
106 if (AR_SREV_9280_10_OR_LATER(ah))
107 nf = MS(REG_READ(ah, AR_PHY_CH1_CCA),
108 AR9280_PHY_CH1_MINCCA_PWR);
109 else
110 nf = MS(REG_READ(ah, AR_PHY_CH1_CCA),
111 AR_PHY_CH1_MINCCA_PWR);
Sujithf1dc5602008-10-29 10:16:30 +0530112
Sujithf1dc5602008-10-29 10:16:30 +0530113 if (nf & 0x100)
114 nf = 0 - ((nf ^ 0x1ff) + 1);
Sujith04bd4632008-11-28 22:18:05 +0530115 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Senthil Balasubramanian793c5922009-01-26 20:28:14 +0530116 "NF calibrated [ctl] [chain 1] is %d\n", nf);
117 nfarray[1] = nf;
118
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530119 if (!AR_SREV_9280(ah) && !AR_SREV_9287(ah)) {
Senthil Balasubramanian793c5922009-01-26 20:28:14 +0530120 nf = MS(REG_READ(ah, AR_PHY_CH2_CCA),
121 AR_PHY_CH2_MINCCA_PWR);
122 if (nf & 0x100)
123 nf = 0 - ((nf ^ 0x1ff) + 1);
124 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
125 "NF calibrated [ctl] [chain 2] is %d\n", nf);
126 nfarray[2] = nf;
127 }
Sujithf1dc5602008-10-29 10:16:30 +0530128 }
129
130 if (AR_SREV_9280_10_OR_LATER(ah))
131 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA),
132 AR9280_PHY_EXT_MINCCA_PWR);
133 else
134 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA),
135 AR_PHY_EXT_MINCCA_PWR);
136
137 if (nf & 0x100)
138 nf = 0 - ((nf ^ 0x1ff) + 1);
Sujith04bd4632008-11-28 22:18:05 +0530139 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujithf1dc5602008-10-29 10:16:30 +0530140 "NF calibrated [ext] [chain 0] is %d\n", nf);
141 nfarray[3] = nf;
142
Senthil Balasubramanian793c5922009-01-26 20:28:14 +0530143 if (!AR_SREV_9285(ah)) {
144 if (AR_SREV_9280_10_OR_LATER(ah))
145 nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA),
146 AR9280_PHY_CH1_EXT_MINCCA_PWR);
147 else
148 nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA),
149 AR_PHY_CH1_EXT_MINCCA_PWR);
Sujithf1dc5602008-10-29 10:16:30 +0530150
Sujithf1dc5602008-10-29 10:16:30 +0530151 if (nf & 0x100)
152 nf = 0 - ((nf ^ 0x1ff) + 1);
Sujith04bd4632008-11-28 22:18:05 +0530153 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Senthil Balasubramanian793c5922009-01-26 20:28:14 +0530154 "NF calibrated [ext] [chain 1] is %d\n", nf);
155 nfarray[4] = nf;
156
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530157 if (!AR_SREV_9280(ah) && !AR_SREV_9287(ah)) {
Senthil Balasubramanian793c5922009-01-26 20:28:14 +0530158 nf = MS(REG_READ(ah, AR_PHY_CH2_EXT_CCA),
159 AR_PHY_CH2_EXT_MINCCA_PWR);
160 if (nf & 0x100)
161 nf = 0 - ((nf ^ 0x1ff) + 1);
162 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
163 "NF calibrated [ext] [chain 2] is %d\n", nf);
164 nfarray[5] = nf;
165 }
Sujithf1dc5602008-10-29 10:16:30 +0530166 }
167}
168
Sujithcbe61d82009-02-09 13:27:12 +0530169static bool getNoiseFloorThresh(struct ath_hw *ah,
Luis R. Rodriguez76061ab2008-12-23 15:58:41 -0800170 enum ieee80211_band band,
Sujithf1dc5602008-10-29 10:16:30 +0530171 int16_t *nft)
172{
Luis R. Rodriguez76061ab2008-12-23 15:58:41 -0800173 switch (band) {
174 case IEEE80211_BAND_5GHZ:
Sujithf74df6f2009-02-09 13:27:24 +0530175 *nft = (int8_t)ah->eep_ops->get_eeprom(ah, EEP_NFTHRESH_5);
Sujithf1dc5602008-10-29 10:16:30 +0530176 break;
Luis R. Rodriguez76061ab2008-12-23 15:58:41 -0800177 case IEEE80211_BAND_2GHZ:
Sujithf74df6f2009-02-09 13:27:24 +0530178 *nft = (int8_t)ah->eep_ops->get_eeprom(ah, EEP_NFTHRESH_2);
Sujithf1dc5602008-10-29 10:16:30 +0530179 break;
180 default:
Luis R. Rodriguez76061ab2008-12-23 15:58:41 -0800181 BUG_ON(1);
Sujithf1dc5602008-10-29 10:16:30 +0530182 return false;
183 }
184
185 return true;
186}
187
Sujithcbe61d82009-02-09 13:27:12 +0530188static void ath9k_hw_setup_calibration(struct ath_hw *ah,
Sujithcbfe9462009-04-13 21:56:56 +0530189 struct ath9k_cal_list *currCal)
Sujithf1dc5602008-10-29 10:16:30 +0530190{
191 REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(0),
192 AR_PHY_TIMING_CTRL4_IQCAL_LOG_COUNT_MAX,
193 currCal->calData->calCountMax);
194
195 switch (currCal->calData->calType) {
196 case IQ_MISMATCH_CAL:
197 REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_IQ);
198 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530199 "starting IQ Mismatch Calibration\n");
Sujithf1dc5602008-10-29 10:16:30 +0530200 break;
201 case ADC_GAIN_CAL:
202 REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_ADC_GAIN);
203 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530204 "starting ADC Gain Calibration\n");
Sujithf1dc5602008-10-29 10:16:30 +0530205 break;
206 case ADC_DC_CAL:
207 REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_ADC_DC_PER);
208 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530209 "starting ADC DC Calibration\n");
Sujithf1dc5602008-10-29 10:16:30 +0530210 break;
211 case ADC_DC_INIT_CAL:
212 REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_ADC_DC_INIT);
213 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530214 "starting Init ADC DC Calibration\n");
Sujithf1dc5602008-10-29 10:16:30 +0530215 break;
216 }
217
218 REG_SET_BIT(ah, AR_PHY_TIMING_CTRL4(0),
219 AR_PHY_TIMING_CTRL4_DO_CAL);
220}
221
Sujithcbe61d82009-02-09 13:27:12 +0530222static void ath9k_hw_reset_calibration(struct ath_hw *ah,
Sujithcbfe9462009-04-13 21:56:56 +0530223 struct ath9k_cal_list *currCal)
Sujithf1dc5602008-10-29 10:16:30 +0530224{
Sujithf1dc5602008-10-29 10:16:30 +0530225 int i;
226
227 ath9k_hw_setup_calibration(ah, currCal);
228
229 currCal->calState = CAL_RUNNING;
230
231 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530232 ah->meas0.sign[i] = 0;
233 ah->meas1.sign[i] = 0;
234 ah->meas2.sign[i] = 0;
235 ah->meas3.sign[i] = 0;
Sujithf1dc5602008-10-29 10:16:30 +0530236 }
237
Sujith2660b812009-02-09 13:27:26 +0530238 ah->cal_samples = 0;
Sujithf1dc5602008-10-29 10:16:30 +0530239}
240
Sujith379f0442009-04-13 21:56:48 +0530241static bool ath9k_hw_per_calibration(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530242 struct ath9k_channel *ichan,
243 u8 rxchainmask,
Sujithcbfe9462009-04-13 21:56:56 +0530244 struct ath9k_cal_list *currCal)
Sujithf1dc5602008-10-29 10:16:30 +0530245{
Sujith379f0442009-04-13 21:56:48 +0530246 bool iscaldone = false;
Sujithf1dc5602008-10-29 10:16:30 +0530247
248 if (currCal->calState == CAL_RUNNING) {
249 if (!(REG_READ(ah, AR_PHY_TIMING_CTRL4(0)) &
250 AR_PHY_TIMING_CTRL4_DO_CAL)) {
251
252 currCal->calData->calCollect(ah);
Sujith2660b812009-02-09 13:27:26 +0530253 ah->cal_samples++;
Sujithf1dc5602008-10-29 10:16:30 +0530254
Sujith2660b812009-02-09 13:27:26 +0530255 if (ah->cal_samples >= currCal->calData->calNumSamples) {
Sujithf1dc5602008-10-29 10:16:30 +0530256 int i, numChains = 0;
257 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
258 if (rxchainmask & (1 << i))
259 numChains++;
260 }
261
262 currCal->calData->calPostProc(ah, numChains);
263 ichan->CalValid |= currCal->calData->calType;
264 currCal->calState = CAL_DONE;
Sujith379f0442009-04-13 21:56:48 +0530265 iscaldone = true;
Sujithf1dc5602008-10-29 10:16:30 +0530266 } else {
267 ath9k_hw_setup_calibration(ah, currCal);
268 }
269 }
270 } else if (!(ichan->CalValid & currCal->calData->calType)) {
271 ath9k_hw_reset_calibration(ah, currCal);
272 }
Sujith379f0442009-04-13 21:56:48 +0530273
274 return iscaldone;
Sujithf1dc5602008-10-29 10:16:30 +0530275}
276
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800277/* Assumes you are talking about the currently configured channel */
Sujithcbe61d82009-02-09 13:27:12 +0530278static bool ath9k_hw_iscal_supported(struct ath_hw *ah,
Sujithcbfe9462009-04-13 21:56:56 +0530279 enum ath9k_cal_types calType)
Sujithf1dc5602008-10-29 10:16:30 +0530280{
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800281 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +0530282
Sujith2660b812009-02-09 13:27:26 +0530283 switch (calType & ah->supp_cals) {
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800284 case IQ_MISMATCH_CAL: /* Both 2 GHz and 5 GHz support OFDM */
285 return true;
Sujithf1dc5602008-10-29 10:16:30 +0530286 case ADC_GAIN_CAL:
287 case ADC_DC_CAL:
Sujitha451aa62009-04-13 21:56:43 +0530288 if (!(conf->channel->band == IEEE80211_BAND_2GHZ &&
289 conf_is_ht20(conf)))
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800290 return true;
Sujithf1dc5602008-10-29 10:16:30 +0530291 break;
292 }
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800293 return false;
Sujithf1dc5602008-10-29 10:16:30 +0530294}
295
Sujithcbe61d82009-02-09 13:27:12 +0530296static void ath9k_hw_iqcal_collect(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530297{
Sujithf1dc5602008-10-29 10:16:30 +0530298 int i;
299
300 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530301 ah->totalPowerMeasI[i] +=
Sujithf1dc5602008-10-29 10:16:30 +0530302 REG_READ(ah, AR_PHY_CAL_MEAS_0(i));
Sujith2660b812009-02-09 13:27:26 +0530303 ah->totalPowerMeasQ[i] +=
Sujithf1dc5602008-10-29 10:16:30 +0530304 REG_READ(ah, AR_PHY_CAL_MEAS_1(i));
Sujith2660b812009-02-09 13:27:26 +0530305 ah->totalIqCorrMeas[i] +=
Sujithf1dc5602008-10-29 10:16:30 +0530306 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_2(i));
307 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
308 "%d: Chn %d pmi=0x%08x;pmq=0x%08x;iqcm=0x%08x;\n",
Sujith2660b812009-02-09 13:27:26 +0530309 ah->cal_samples, i, ah->totalPowerMeasI[i],
310 ah->totalPowerMeasQ[i],
311 ah->totalIqCorrMeas[i]);
Sujithf1dc5602008-10-29 10:16:30 +0530312 }
313}
314
Sujithcbe61d82009-02-09 13:27:12 +0530315static void ath9k_hw_adc_gaincal_collect(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530316{
Sujithf1dc5602008-10-29 10:16:30 +0530317 int i;
318
319 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530320 ah->totalAdcIOddPhase[i] +=
Sujithf1dc5602008-10-29 10:16:30 +0530321 REG_READ(ah, AR_PHY_CAL_MEAS_0(i));
Sujith2660b812009-02-09 13:27:26 +0530322 ah->totalAdcIEvenPhase[i] +=
Sujithf1dc5602008-10-29 10:16:30 +0530323 REG_READ(ah, AR_PHY_CAL_MEAS_1(i));
Sujith2660b812009-02-09 13:27:26 +0530324 ah->totalAdcQOddPhase[i] +=
Sujithf1dc5602008-10-29 10:16:30 +0530325 REG_READ(ah, AR_PHY_CAL_MEAS_2(i));
Sujith2660b812009-02-09 13:27:26 +0530326 ah->totalAdcQEvenPhase[i] +=
Sujithf1dc5602008-10-29 10:16:30 +0530327 REG_READ(ah, AR_PHY_CAL_MEAS_3(i));
328
329 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
330 "%d: Chn %d oddi=0x%08x; eveni=0x%08x; "
331 "oddq=0x%08x; evenq=0x%08x;\n",
Sujith2660b812009-02-09 13:27:26 +0530332 ah->cal_samples, i,
333 ah->totalAdcIOddPhase[i],
334 ah->totalAdcIEvenPhase[i],
335 ah->totalAdcQOddPhase[i],
336 ah->totalAdcQEvenPhase[i]);
Sujithf1dc5602008-10-29 10:16:30 +0530337 }
338}
339
Sujithcbe61d82009-02-09 13:27:12 +0530340static void ath9k_hw_adc_dccal_collect(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530341{
Sujithf1dc5602008-10-29 10:16:30 +0530342 int i;
343
344 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530345 ah->totalAdcDcOffsetIOddPhase[i] +=
Sujithf1dc5602008-10-29 10:16:30 +0530346 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_0(i));
Sujith2660b812009-02-09 13:27:26 +0530347 ah->totalAdcDcOffsetIEvenPhase[i] +=
Sujithf1dc5602008-10-29 10:16:30 +0530348 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_1(i));
Sujith2660b812009-02-09 13:27:26 +0530349 ah->totalAdcDcOffsetQOddPhase[i] +=
Sujithf1dc5602008-10-29 10:16:30 +0530350 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_2(i));
Sujith2660b812009-02-09 13:27:26 +0530351 ah->totalAdcDcOffsetQEvenPhase[i] +=
Sujithf1dc5602008-10-29 10:16:30 +0530352 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_3(i));
353
354 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
355 "%d: Chn %d oddi=0x%08x; eveni=0x%08x; "
356 "oddq=0x%08x; evenq=0x%08x;\n",
Sujith2660b812009-02-09 13:27:26 +0530357 ah->cal_samples, i,
358 ah->totalAdcDcOffsetIOddPhase[i],
359 ah->totalAdcDcOffsetIEvenPhase[i],
360 ah->totalAdcDcOffsetQOddPhase[i],
361 ah->totalAdcDcOffsetQEvenPhase[i]);
Sujithf1dc5602008-10-29 10:16:30 +0530362 }
363}
364
Sujithcbe61d82009-02-09 13:27:12 +0530365static void ath9k_hw_iqcalibrate(struct ath_hw *ah, u8 numChains)
Sujithf1dc5602008-10-29 10:16:30 +0530366{
Sujithf1dc5602008-10-29 10:16:30 +0530367 u32 powerMeasQ, powerMeasI, iqCorrMeas;
368 u32 qCoffDenom, iCoffDenom;
369 int32_t qCoff, iCoff;
370 int iqCorrNeg, i;
371
372 for (i = 0; i < numChains; i++) {
Sujith2660b812009-02-09 13:27:26 +0530373 powerMeasI = ah->totalPowerMeasI[i];
374 powerMeasQ = ah->totalPowerMeasQ[i];
375 iqCorrMeas = ah->totalIqCorrMeas[i];
Sujithf1dc5602008-10-29 10:16:30 +0530376
377 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
378 "Starting IQ Cal and Correction for Chain %d\n",
379 i);
380
381 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
382 "Orignal: Chn %diq_corr_meas = 0x%08x\n",
Sujith2660b812009-02-09 13:27:26 +0530383 i, ah->totalIqCorrMeas[i]);
Sujithf1dc5602008-10-29 10:16:30 +0530384
385 iqCorrNeg = 0;
386
387 if (iqCorrMeas > 0x80000000) {
388 iqCorrMeas = (0xffffffff - iqCorrMeas) + 1;
389 iqCorrNeg = 1;
390 }
391
392 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
393 "Chn %d pwr_meas_i = 0x%08x\n", i, powerMeasI);
394 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
395 "Chn %d pwr_meas_q = 0x%08x\n", i, powerMeasQ);
396 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE, "iqCorrNeg is 0x%08x\n",
397 iqCorrNeg);
398
399 iCoffDenom = (powerMeasI / 2 + powerMeasQ / 2) / 128;
400 qCoffDenom = powerMeasQ / 64;
401
402 if (powerMeasQ != 0) {
403 iCoff = iqCorrMeas / iCoffDenom;
404 qCoff = powerMeasI / qCoffDenom - 64;
405 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
406 "Chn %d iCoff = 0x%08x\n", i, iCoff);
407 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
408 "Chn %d qCoff = 0x%08x\n", i, qCoff);
409
410 iCoff = iCoff & 0x3f;
411 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
412 "New: Chn %d iCoff = 0x%08x\n", i, iCoff);
413 if (iqCorrNeg == 0x0)
414 iCoff = 0x40 - iCoff;
415
416 if (qCoff > 15)
417 qCoff = 15;
418 else if (qCoff <= -16)
419 qCoff = 16;
420
421 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
422 "Chn %d : iCoff = 0x%x qCoff = 0x%x\n",
423 i, iCoff, qCoff);
424
425 REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(i),
426 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF,
427 iCoff);
428 REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(i),
429 AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF,
430 qCoff);
431 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
432 "IQ Cal and Correction done for Chain %d\n",
433 i);
434 }
435 }
436
437 REG_SET_BIT(ah, AR_PHY_TIMING_CTRL4(0),
438 AR_PHY_TIMING_CTRL4_IQCORR_ENABLE);
439}
440
Sujithcbe61d82009-02-09 13:27:12 +0530441static void ath9k_hw_adc_gaincal_calibrate(struct ath_hw *ah, u8 numChains)
Sujithf1dc5602008-10-29 10:16:30 +0530442{
Sujithf1dc5602008-10-29 10:16:30 +0530443 u32 iOddMeasOffset, iEvenMeasOffset, qOddMeasOffset, qEvenMeasOffset;
444 u32 qGainMismatch, iGainMismatch, val, i;
445
446 for (i = 0; i < numChains; i++) {
Sujith2660b812009-02-09 13:27:26 +0530447 iOddMeasOffset = ah->totalAdcIOddPhase[i];
448 iEvenMeasOffset = ah->totalAdcIEvenPhase[i];
449 qOddMeasOffset = ah->totalAdcQOddPhase[i];
450 qEvenMeasOffset = ah->totalAdcQEvenPhase[i];
Sujithf1dc5602008-10-29 10:16:30 +0530451
452 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
453 "Starting ADC Gain Cal for Chain %d\n", i);
454
455 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
456 "Chn %d pwr_meas_odd_i = 0x%08x\n", i,
457 iOddMeasOffset);
458 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
459 "Chn %d pwr_meas_even_i = 0x%08x\n", i,
460 iEvenMeasOffset);
461 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
462 "Chn %d pwr_meas_odd_q = 0x%08x\n", i,
463 qOddMeasOffset);
464 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
465 "Chn %d pwr_meas_even_q = 0x%08x\n", i,
466 qEvenMeasOffset);
467
468 if (iOddMeasOffset != 0 && qEvenMeasOffset != 0) {
469 iGainMismatch =
470 ((iEvenMeasOffset * 32) /
471 iOddMeasOffset) & 0x3f;
472 qGainMismatch =
473 ((qOddMeasOffset * 32) /
474 qEvenMeasOffset) & 0x3f;
475
476 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
477 "Chn %d gain_mismatch_i = 0x%08x\n", i,
478 iGainMismatch);
479 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
480 "Chn %d gain_mismatch_q = 0x%08x\n", i,
481 qGainMismatch);
482
483 val = REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i));
484 val &= 0xfffff000;
485 val |= (qGainMismatch) | (iGainMismatch << 6);
486 REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i), val);
487
488 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
489 "ADC Gain Cal done for Chain %d\n", i);
490 }
491 }
492
493 REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0),
494 REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0)) |
495 AR_PHY_NEW_ADC_GAIN_CORR_ENABLE);
496}
497
Sujithcbe61d82009-02-09 13:27:12 +0530498static void ath9k_hw_adc_dccal_calibrate(struct ath_hw *ah, u8 numChains)
Sujithf1dc5602008-10-29 10:16:30 +0530499{
Sujithf1dc5602008-10-29 10:16:30 +0530500 u32 iOddMeasOffset, iEvenMeasOffset, val, i;
501 int32_t qOddMeasOffset, qEvenMeasOffset, qDcMismatch, iDcMismatch;
Sujithcbfe9462009-04-13 21:56:56 +0530502 const struct ath9k_percal_data *calData =
Sujith2660b812009-02-09 13:27:26 +0530503 ah->cal_list_curr->calData;
Sujithf1dc5602008-10-29 10:16:30 +0530504 u32 numSamples =
505 (1 << (calData->calCountMax + 5)) * calData->calNumSamples;
506
507 for (i = 0; i < numChains; i++) {
Sujith2660b812009-02-09 13:27:26 +0530508 iOddMeasOffset = ah->totalAdcDcOffsetIOddPhase[i];
509 iEvenMeasOffset = ah->totalAdcDcOffsetIEvenPhase[i];
510 qOddMeasOffset = ah->totalAdcDcOffsetQOddPhase[i];
511 qEvenMeasOffset = ah->totalAdcDcOffsetQEvenPhase[i];
Sujithf1dc5602008-10-29 10:16:30 +0530512
513 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
514 "Starting ADC DC Offset Cal for Chain %d\n", i);
515
516 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
517 "Chn %d pwr_meas_odd_i = %d\n", i,
518 iOddMeasOffset);
519 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
520 "Chn %d pwr_meas_even_i = %d\n", i,
521 iEvenMeasOffset);
522 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
523 "Chn %d pwr_meas_odd_q = %d\n", i,
524 qOddMeasOffset);
525 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
526 "Chn %d pwr_meas_even_q = %d\n", i,
527 qEvenMeasOffset);
528
529 iDcMismatch = (((iEvenMeasOffset - iOddMeasOffset) * 2) /
530 numSamples) & 0x1ff;
531 qDcMismatch = (((qOddMeasOffset - qEvenMeasOffset) * 2) /
532 numSamples) & 0x1ff;
533
534 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
535 "Chn %d dc_offset_mismatch_i = 0x%08x\n", i,
536 iDcMismatch);
537 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
538 "Chn %d dc_offset_mismatch_q = 0x%08x\n", i,
539 qDcMismatch);
540
541 val = REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i));
542 val &= 0xc0000fff;
543 val |= (qDcMismatch << 12) | (iDcMismatch << 21);
544 REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i), val);
545
546 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
547 "ADC DC Offset Cal done for Chain %d\n", i);
548 }
549
550 REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0),
551 REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0)) |
552 AR_PHY_NEW_ADC_DC_OFFSET_CORR_ENABLE);
553}
554
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800555/* This is done for the currently configured channel */
Sujithcbe61d82009-02-09 13:27:12 +0530556bool ath9k_hw_reset_calvalid(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530557{
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800558 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
Sujithcbfe9462009-04-13 21:56:56 +0530559 struct ath9k_cal_list *currCal = ah->cal_list_curr;
Sujithf1dc5602008-10-29 10:16:30 +0530560
Sujith2660b812009-02-09 13:27:26 +0530561 if (!ah->curchan)
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800562 return true;
Sujithf1dc5602008-10-29 10:16:30 +0530563
564 if (!AR_SREV_9100(ah) && !AR_SREV_9160_10_OR_LATER(ah))
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800565 return true;
Sujithf1dc5602008-10-29 10:16:30 +0530566
567 if (currCal == NULL)
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800568 return true;
Sujithf1dc5602008-10-29 10:16:30 +0530569
570 if (currCal->calState != CAL_DONE) {
571 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530572 "Calibration state incorrect, %d\n",
573 currCal->calState);
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800574 return true;
Sujithf1dc5602008-10-29 10:16:30 +0530575 }
576
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800577 if (!ath9k_hw_iscal_supported(ah, currCal->calData->calType))
578 return true;
Sujithf1dc5602008-10-29 10:16:30 +0530579
580 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800581 "Resetting Cal %d state for channel %u\n",
582 currCal->calData->calType, conf->channel->center_freq);
Sujithf1dc5602008-10-29 10:16:30 +0530583
Sujith2660b812009-02-09 13:27:26 +0530584 ah->curchan->CalValid &= ~currCal->calData->calType;
Sujithf1dc5602008-10-29 10:16:30 +0530585 currCal->calState = CAL_WAITING;
586
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800587 return false;
Sujithf1dc5602008-10-29 10:16:30 +0530588}
589
Sujithcbe61d82009-02-09 13:27:12 +0530590void ath9k_hw_start_nfcal(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530591{
592 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL,
593 AR_PHY_AGC_CONTROL_ENABLE_NF);
594 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL,
595 AR_PHY_AGC_CONTROL_NO_UPDATE_NF);
596 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF);
597}
598
Sujithcbe61d82009-02-09 13:27:12 +0530599void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +0530600{
601 struct ath9k_nfcal_hist *h;
602 int i, j;
603 int32_t val;
604 const u32 ar5416_cca_regs[6] = {
605 AR_PHY_CCA,
606 AR_PHY_CH1_CCA,
607 AR_PHY_CH2_CCA,
608 AR_PHY_EXT_CCA,
609 AR_PHY_CH1_EXT_CCA,
610 AR_PHY_CH2_EXT_CCA
611 };
612 u8 chainmask;
613
Sujith5dad40c2009-01-23 11:20:55 +0530614 if (AR_SREV_9285(ah))
615 chainmask = 0x9;
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530616 else if (AR_SREV_9280(ah) || AR_SREV_9287(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530617 chainmask = 0x1B;
618 else
619 chainmask = 0x3F;
620
Sujithf1dc5602008-10-29 10:16:30 +0530621 h = ah->nfCalHist;
Sujithf1dc5602008-10-29 10:16:30 +0530622
623 for (i = 0; i < NUM_NF_READINGS; i++) {
624 if (chainmask & (1 << i)) {
625 val = REG_READ(ah, ar5416_cca_regs[i]);
626 val &= 0xFFFFFE00;
627 val |= (((u32) (h[i].privNF) << 1) & 0x1ff);
628 REG_WRITE(ah, ar5416_cca_regs[i], val);
629 }
630 }
631
632 REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
633 AR_PHY_AGC_CONTROL_ENABLE_NF);
634 REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
635 AR_PHY_AGC_CONTROL_NO_UPDATE_NF);
636 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF);
637
638 for (j = 0; j < 1000; j++) {
639 if ((REG_READ(ah, AR_PHY_AGC_CONTROL) &
640 AR_PHY_AGC_CONTROL_NF) == 0)
641 break;
642 udelay(10);
643 }
644
645 for (i = 0; i < NUM_NF_READINGS; i++) {
646 if (chainmask & (1 << i)) {
647 val = REG_READ(ah, ar5416_cca_regs[i]);
648 val &= 0xFFFFFE00;
649 val |= (((u32) (-50) << 1) & 0x1ff);
650 REG_WRITE(ah, ar5416_cca_regs[i], val);
651 }
652 }
653}
654
Sujithcbe61d82009-02-09 13:27:12 +0530655int16_t ath9k_hw_getnf(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530656 struct ath9k_channel *chan)
657{
658 int16_t nf, nfThresh;
659 int16_t nfarray[NUM_NF_READINGS] = { 0 };
660 struct ath9k_nfcal_hist *h;
Luis R. Rodriguez76061ab2008-12-23 15:58:41 -0800661 struct ieee80211_channel *c = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +0530662
663 chan->channelFlags &= (~CHANNEL_CW_INT);
664 if (REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF) {
665 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530666 "NF did not complete in calibration window\n");
Sujithf1dc5602008-10-29 10:16:30 +0530667 nf = 0;
668 chan->rawNoiseFloor = nf;
669 return chan->rawNoiseFloor;
670 } else {
671 ath9k_hw_do_getnf(ah, nfarray);
672 nf = nfarray[0];
Luis R. Rodriguez76061ab2008-12-23 15:58:41 -0800673 if (getNoiseFloorThresh(ah, c->band, &nfThresh)
Sujithf1dc5602008-10-29 10:16:30 +0530674 && nf > nfThresh) {
675 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530676 "noise floor failed detected; "
677 "detected %d, threshold %d\n",
Sujithf1dc5602008-10-29 10:16:30 +0530678 nf, nfThresh);
679 chan->channelFlags |= CHANNEL_CW_INT;
680 }
681 }
682
Sujithf1dc5602008-10-29 10:16:30 +0530683 h = ah->nfCalHist;
Sujithf1dc5602008-10-29 10:16:30 +0530684
685 ath9k_hw_update_nfcal_hist_buffer(h, nfarray);
686 chan->rawNoiseFloor = h[0].privNF;
687
688 return chan->rawNoiseFloor;
689}
690
Sujithcbe61d82009-02-09 13:27:12 +0530691void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530692{
693 int i, j;
Senthil Balasubramaniana59b5a52009-07-14 20:17:07 -0400694 s16 noise_floor;
695
696 if (AR_SREV_9280(ah))
697 noise_floor = AR_PHY_CCA_MAX_AR9280_GOOD_VALUE;
698 else if (AR_SREV_9285(ah))
699 noise_floor = AR_PHY_CCA_MAX_AR9285_GOOD_VALUE;
700 else
701 noise_floor = AR_PHY_CCA_MAX_AR5416_GOOD_VALUE;
Sujithf1dc5602008-10-29 10:16:30 +0530702
703 for (i = 0; i < NUM_NF_READINGS; i++) {
704 ah->nfCalHist[i].currIndex = 0;
Senthil Balasubramaniana59b5a52009-07-14 20:17:07 -0400705 ah->nfCalHist[i].privNF = noise_floor;
Sujithf1dc5602008-10-29 10:16:30 +0530706 ah->nfCalHist[i].invalidNFcount =
707 AR_PHY_CCA_FILTERWINDOW_LENGTH;
708 for (j = 0; j < ATH9K_NF_CAL_HIST_MAX; j++) {
Senthil Balasubramaniana59b5a52009-07-14 20:17:07 -0400709 ah->nfCalHist[i].nfCalBuffer[j] = noise_floor;
Sujithf1dc5602008-10-29 10:16:30 +0530710 }
711 }
Sujithf1dc5602008-10-29 10:16:30 +0530712}
713
Sujithcbe61d82009-02-09 13:27:12 +0530714s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +0530715{
Sujithf1dc5602008-10-29 10:16:30 +0530716 s16 nf;
717
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800718 if (chan->rawNoiseFloor == 0)
Luis R. Rodrigueze56db712008-12-23 15:58:47 -0800719 nf = -96;
720 else
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800721 nf = chan->rawNoiseFloor;
Sujithf1dc5602008-10-29 10:16:30 +0530722
723 if (!ath9k_hw_nf_in_range(ah, nf))
724 nf = ATH_DEFAULT_NOISE_FLOOR;
725
726 return nf;
727}
728
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +0530729static void ath9k_olc_temp_compensation(struct ath_hw *ah)
730{
731 u32 rddata, i;
732 int delta, currPDADC, regval;
733
734 rddata = REG_READ(ah, AR_PHY_TX_PWRCTRL4);
735
736 currPDADC = MS(rddata, AR_PHY_TX_PWRCTRL_PD_AVG_OUT);
737
738 if (ah->eep_ops->get_eeprom(ah, EEP_DAC_HPWR_5G))
739 delta = (currPDADC - ah->initPDADC + 4) / 8;
740 else
741 delta = (currPDADC - ah->initPDADC + 5) / 10;
742
743 if (delta != ah->PDADCdelta) {
744 ah->PDADCdelta = delta;
745 for (i = 1; i < AR9280_TX_GAIN_TABLE_SIZE; i++) {
746 regval = ah->originalGain[i] - delta;
747 if (regval < 0)
748 regval = 0;
749
750 REG_RMW_FIELD(ah, AR_PHY_TX_GAIN_TBL1 + i * 4,
751 AR_PHY_TX_GAIN, regval);
752 }
753 }
754}
755
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400756static void ath9k_hw_9271_pa_cal(struct ath_hw *ah)
757{
758 u32 regVal;
759 unsigned int i;
760 u32 regList [][2] = {
761 { 0x786c, 0 },
762 { 0x7854, 0 },
763 { 0x7820, 0 },
764 { 0x7824, 0 },
765 { 0x7868, 0 },
766 { 0x783c, 0 },
767 { 0x7838, 0 } ,
768 { 0x7828, 0 } ,
769 };
770
771 for (i = 0; i < ARRAY_SIZE(regList); i++)
772 regList[i][1] = REG_READ(ah, regList[i][0]);
773
774 regVal = REG_READ(ah, 0x7834);
775 regVal &= (~(0x1));
776 REG_WRITE(ah, 0x7834, regVal);
777 regVal = REG_READ(ah, 0x9808);
778 regVal |= (0x1 << 27);
779 REG_WRITE(ah, 0x9808, regVal);
780
781 /* 786c,b23,1, pwddac=1 */
782 REG_RMW_FIELD(ah, AR9285_AN_TOP3, AR9285_AN_TOP3_PWDDAC, 1);
783 /* 7854, b5,1, pdrxtxbb=1 */
784 REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDRXTXBB1, 1);
785 /* 7854, b7,1, pdv2i=1 */
786 REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDV2I, 1);
787 /* 7854, b8,1, pddacinterface=1 */
788 REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDDACIF, 1);
789 /* 7824,b12,0, offcal=0 */
790 REG_RMW_FIELD(ah, AR9285_AN_RF2G2, AR9285_AN_RF2G2_OFFCAL, 0);
791 /* 7838, b1,0, pwddb=0 */
792 REG_RMW_FIELD(ah, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PWDDB, 0);
793 /* 7820,b11,0, enpacal=0 */
794 REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_ENPACAL, 0);
795 /* 7820,b25,1, pdpadrv1=0 */
796 REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV1, 0);
797 /* 7820,b24,0, pdpadrv2=0 */
798 REG_RMW_FIELD(ah, AR9285_AN_RF2G1,AR9285_AN_RF2G1_PDPADRV2,0);
799 /* 7820,b23,0, pdpaout=0 */
800 REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPAOUT, 0);
801 /* 783c,b14-16,7, padrvgn2tab_0=7 */
802 REG_RMW_FIELD(ah, AR9285_AN_RF2G8,AR9285_AN_RF2G8_PADRVGN2TAB0, 7);
803 /*
804 * 7838,b29-31,0, padrvgn1tab_0=0
805 * does not matter since we turn it off
806 */
807 REG_RMW_FIELD(ah, AR9285_AN_RF2G7,AR9285_AN_RF2G7_PADRVGN2TAB0, 0);
808
809 REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9271_AN_RF2G3_CCOMP, 0xfff);
810
811 /* Set:
812 * localmode=1,bmode=1,bmoderxtx=1,synthon=1,
813 * txon=1,paon=1,oscon=1,synthon_force=1
814 */
815 REG_WRITE(ah, AR9285_AN_TOP2, 0xca0358a0);
816 udelay(30);
817 REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9271_AN_RF2G6_OFFS, 0);
818
819 /* find off_6_1; */
820 for (i = 6; i >= 0; i--) {
821 regVal = REG_READ(ah, 0x7834);
822 regVal |= (1 << (20 + i));
823 REG_WRITE(ah, 0x7834, regVal);
824 udelay(1);
825 //regVal = REG_READ(ah, 0x7834);
826 regVal &= (~(0x1 << (20 + i)));
827 regVal |= (MS(REG_READ(ah, 0x7840), AR9285_AN_RXTXBB1_SPARE9)
828 << (20 + i));
829 REG_WRITE(ah, 0x7834, regVal);
830 }
831
832 /* Empirical offset correction */
833#if 0
834 REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9271_AN_RF2G6_OFFS, 0x20);
835#endif
836
837 regVal = REG_READ(ah, 0x7834);
838 regVal |= 0x1;
839 REG_WRITE(ah, 0x7834, regVal);
840 regVal = REG_READ(ah, 0x9808);
841 regVal &= (~(0x1 << 27));
842 REG_WRITE(ah, 0x9808, regVal);
843
844 for (i = 0; i < ARRAY_SIZE(regList); i++)
845 REG_WRITE(ah, regList[i][0], regList[i][1]);
846}
847
Sujithcbe61d82009-02-09 13:27:12 +0530848static inline void ath9k_hw_9285_pa_cal(struct ath_hw *ah)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530849{
850
851 u32 regVal;
852 int i, offset, offs_6_1, offs_0;
853 u32 ccomp_org, reg_field;
854 u32 regList[][2] = {
855 { 0x786c, 0 },
856 { 0x7854, 0 },
857 { 0x7820, 0 },
858 { 0x7824, 0 },
859 { 0x7868, 0 },
860 { 0x783c, 0 },
861 { 0x7838, 0 },
862 };
863
864 if (AR_SREV_9285_11(ah)) {
865 REG_WRITE(ah, AR9285_AN_TOP4, (AR9285_AN_TOP4_DEFAULT | 0x14));
866 udelay(10);
867 }
868
869 for (i = 0; i < ARRAY_SIZE(regList); i++)
870 regList[i][1] = REG_READ(ah, regList[i][0]);
871
872 regVal = REG_READ(ah, 0x7834);
873 regVal &= (~(0x1));
874 REG_WRITE(ah, 0x7834, regVal);
875 regVal = REG_READ(ah, 0x9808);
876 regVal |= (0x1 << 27);
877 REG_WRITE(ah, 0x9808, regVal);
878
879 REG_RMW_FIELD(ah, AR9285_AN_TOP3, AR9285_AN_TOP3_PWDDAC, 1);
880 REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDRXTXBB1, 1);
881 REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDV2I, 1);
882 REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDDACIF, 1);
883 REG_RMW_FIELD(ah, AR9285_AN_RF2G2, AR9285_AN_RF2G2_OFFCAL, 0);
884 REG_RMW_FIELD(ah, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PWDDB, 0);
885 REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_ENPACAL, 0);
886 REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV1, 1);
887 REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV2, 0);
888 REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPAOUT, 0);
889 REG_RMW_FIELD(ah, AR9285_AN_RF2G8, AR9285_AN_RF2G8_PADRVGN2TAB0, 7);
890 REG_RMW_FIELD(ah, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PADRVGN2TAB0, 0);
891 ccomp_org = MS(REG_READ(ah, AR9285_AN_RF2G6), AR9285_AN_RF2G6_CCOMP);
892 REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_CCOMP, 7);
893
894 REG_WRITE(ah, AR9285_AN_TOP2, 0xca0358a0);
895 udelay(30);
896 REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_OFFS, 0);
897 REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, 0);
898
899 for (i = 6; i > 0; i--) {
900 regVal = REG_READ(ah, 0x7834);
901 regVal |= (1 << (19 + i));
902 REG_WRITE(ah, 0x7834, regVal);
903 udelay(1);
904 regVal = REG_READ(ah, 0x7834);
905 regVal &= (~(0x1 << (19 + i)));
906 reg_field = MS(REG_READ(ah, 0x7840), AR9285_AN_RXTXBB1_SPARE9);
907 regVal |= (reg_field << (19 + i));
908 REG_WRITE(ah, 0x7834, regVal);
909 }
910
911 REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, 1);
912 udelay(1);
913 reg_field = MS(REG_READ(ah, AR9285_AN_RF2G9), AR9285_AN_RXTXBB1_SPARE9);
914 REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, reg_field);
915 offs_6_1 = MS(REG_READ(ah, AR9285_AN_RF2G6), AR9285_AN_RF2G6_OFFS);
916 offs_0 = MS(REG_READ(ah, AR9285_AN_RF2G3), AR9285_AN_RF2G3_PDVCCOMP);
917
918 offset = (offs_6_1<<1) | offs_0;
919 offset = offset - 0;
920 offs_6_1 = offset>>1;
921 offs_0 = offset & 1;
922
923 REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_OFFS, offs_6_1);
924 REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, offs_0);
925
926 regVal = REG_READ(ah, 0x7834);
927 regVal |= 0x1;
928 REG_WRITE(ah, 0x7834, regVal);
929 regVal = REG_READ(ah, 0x9808);
930 regVal &= (~(0x1 << 27));
931 REG_WRITE(ah, 0x9808, regVal);
932
933 for (i = 0; i < ARRAY_SIZE(regList); i++)
934 REG_WRITE(ah, regList[i][0], regList[i][1]);
935
936 REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_CCOMP, ccomp_org);
937
938 if (AR_SREV_9285_11(ah))
939 REG_WRITE(ah, AR9285_AN_TOP4, AR9285_AN_TOP4_DEFAULT);
940
941}
942
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530943bool ath9k_hw_calibrate(struct ath_hw *ah, struct ath9k_channel *chan,
Sujith379f0442009-04-13 21:56:48 +0530944 u8 rxchainmask, bool longcal)
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530945{
Sujith379f0442009-04-13 21:56:48 +0530946 bool iscaldone = true;
Sujithcbfe9462009-04-13 21:56:56 +0530947 struct ath9k_cal_list *currCal = ah->cal_list_curr;
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530948
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530949 if (currCal &&
950 (currCal->calState == CAL_RUNNING ||
951 currCal->calState == CAL_WAITING)) {
Sujith379f0442009-04-13 21:56:48 +0530952 iscaldone = ath9k_hw_per_calibration(ah, chan,
953 rxchainmask, currCal);
954 if (iscaldone) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530955 ah->cal_list_curr = currCal = currCal->calNext;
956
957 if (currCal->calState == CAL_WAITING) {
Sujith379f0442009-04-13 21:56:48 +0530958 iscaldone = false;
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530959 ath9k_hw_reset_calibration(ah, currCal);
960 }
961 }
962 }
963
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400964 /* Do NF cal only at longer intervals */
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530965 if (longcal) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400966 /* Do periodic PAOffset Cal */
967 if (AR_SREV_9271(ah))
968 ath9k_hw_9271_pa_cal(ah);
969 else if (AR_SREV_9285_11_OR_LATER(ah))
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530970 ath9k_hw_9285_pa_cal(ah);
971
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530972 if (OLC_FOR_AR9280_20_LATER || OLC_FOR_AR9287_10_LATER)
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530973 ath9k_olc_temp_compensation(ah);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400974
975 /* Get the value from the previous NF cal and update history buffer */
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530976 ath9k_hw_getnf(ah, chan);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400977
978 /*
979 * Load the NF from history buffer of the current channel.
980 * NF is slow time-variant, so it is OK to use a historical value.
981 */
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530982 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400983
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530984 ath9k_hw_start_nfcal(ah);
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530985 }
986
Sujith379f0442009-04-13 21:56:48 +0530987 return iscaldone;
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530988}
989
Luis R. Rodriguez15cc0f12009-03-09 22:09:42 -0400990static bool ar9285_clc(struct ath_hw *ah, struct ath9k_channel *chan)
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530991{
992 REG_SET_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_CL_CAL_ENABLE);
Sujithdb2f63f2009-04-13 21:56:41 +0530993 if (IS_CHAN_HT20(chan)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530994 REG_SET_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_PARALLEL_CAL_ENABLE);
995 REG_SET_BIT(ah, AR_PHY_TURBO, AR_PHY_FC_DYN2040_EN);
996 REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
997 AR_PHY_AGC_CONTROL_FLTR_CAL);
998 REG_CLR_BIT(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_CAL_ENABLE);
999 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL);
1000 if (!ath9k_hw_wait(ah, AR_PHY_AGC_CONTROL,
1001 AR_PHY_AGC_CONTROL_CAL, 0, AH_WAIT_TIMEOUT)) {
1002 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE, "offset "
1003 "calibration failed to complete in "
1004 "1ms; noisy ??\n");
1005 return false;
1006 }
1007 REG_CLR_BIT(ah, AR_PHY_TURBO, AR_PHY_FC_DYN2040_EN);
1008 REG_CLR_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_PARALLEL_CAL_ENABLE);
1009 REG_CLR_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_CL_CAL_ENABLE);
1010 }
1011 REG_CLR_BIT(ah, AR_PHY_ADC_CTL, AR_PHY_ADC_CTL_OFF_PWDADC);
1012 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_FLTR_CAL);
1013 REG_SET_BIT(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_CAL_ENABLE);
1014 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL);
1015 if (!ath9k_hw_wait(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL,
1016 0, AH_WAIT_TIMEOUT)) {
1017 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE, "offset calibration "
1018 "failed to complete in 1ms; noisy ??\n");
1019 return false;
1020 }
1021
1022 REG_SET_BIT(ah, AR_PHY_ADC_CTL, AR_PHY_ADC_CTL_OFF_PWDADC);
1023 REG_CLR_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_CL_CAL_ENABLE);
1024 REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_FLTR_CAL);
1025
1026 return true;
1027}
1028
Sujith04d19dd2009-04-13 21:56:59 +05301029bool ath9k_hw_init_cal(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301030{
Gabor Juhosf9dd6b52009-05-06 09:47:30 +02001031 if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +05301032 if (!ar9285_clc(ah, chan))
1033 return false;
Sujith04d19dd2009-04-13 21:56:59 +05301034 } else {
1035 if (AR_SREV_9280_10_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301036 if (!AR_SREV_9287_10_OR_LATER(ah))
1037 REG_CLR_BIT(ah, AR_PHY_ADC_CTL,
1038 AR_PHY_ADC_CTL_OFF_PWDADC);
1039 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL,
1040 AR_PHY_AGC_CONTROL_FLTR_CAL);
Sujith04d19dd2009-04-13 21:56:59 +05301041 }
Sujithedf7c062009-02-12 10:06:49 +05301042
Sujith04d19dd2009-04-13 21:56:59 +05301043 /* Calibrate the AGC */
Sujithedf7c062009-02-12 10:06:49 +05301044 REG_WRITE(ah, AR_PHY_AGC_CONTROL,
Sujith04d19dd2009-04-13 21:56:59 +05301045 REG_READ(ah, AR_PHY_AGC_CONTROL) |
1046 AR_PHY_AGC_CONTROL_CAL);
Sujithedf7c062009-02-12 10:06:49 +05301047
Sujith04d19dd2009-04-13 21:56:59 +05301048 /* Poll for offset calibration complete */
1049 if (!ath9k_hw_wait(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL,
1050 0, AH_WAIT_TIMEOUT)) {
Sujithedf7c062009-02-12 10:06:49 +05301051 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
1052 "offset calibration failed to complete in 1ms; "
1053 "noisy environment?\n");
1054 return false;
1055 }
1056
Sujith04d19dd2009-04-13 21:56:59 +05301057 if (AR_SREV_9280_10_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301058 if (!AR_SREV_9287_10_OR_LATER(ah))
1059 REG_SET_BIT(ah, AR_PHY_ADC_CTL,
1060 AR_PHY_ADC_CTL_OFF_PWDADC);
1061 REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
1062 AR_PHY_AGC_CONTROL_FLTR_CAL);
Sujith04d19dd2009-04-13 21:56:59 +05301063 }
Sujithedf7c062009-02-12 10:06:49 +05301064 }
1065
1066 /* Do PA Calibration */
Gabor Juhosf9dd6b52009-05-06 09:47:30 +02001067 if (AR_SREV_9285_11_OR_LATER(ah))
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301068 ath9k_hw_9285_pa_cal(ah);
1069
Sujith04d19dd2009-04-13 21:56:59 +05301070 /* Do NF Calibration after DC offset and other calibrations */
Sujithf1dc5602008-10-29 10:16:30 +05301071 REG_WRITE(ah, AR_PHY_AGC_CONTROL,
Sujith04d19dd2009-04-13 21:56:59 +05301072 REG_READ(ah, AR_PHY_AGC_CONTROL) | AR_PHY_AGC_CONTROL_NF);
Sujithf1dc5602008-10-29 10:16:30 +05301073
Sujith2660b812009-02-09 13:27:26 +05301074 ah->cal_list = ah->cal_list_last = ah->cal_list_curr = NULL;
Sujithf1dc5602008-10-29 10:16:30 +05301075
Sujith04d19dd2009-04-13 21:56:59 +05301076 /* Enable IQ, ADC Gain and ADC DC offset CALs */
Sujithf1dc5602008-10-29 10:16:30 +05301077 if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah)) {
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -08001078 if (ath9k_hw_iscal_supported(ah, ADC_GAIN_CAL)) {
Sujith2660b812009-02-09 13:27:26 +05301079 INIT_CAL(&ah->adcgain_caldata);
1080 INSERT_CAL(ah, &ah->adcgain_caldata);
Sujithf1dc5602008-10-29 10:16:30 +05301081 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04d19dd2009-04-13 21:56:59 +05301082 "enabling ADC Gain Calibration.\n");
Sujithf1dc5602008-10-29 10:16:30 +05301083 }
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -08001084 if (ath9k_hw_iscal_supported(ah, ADC_DC_CAL)) {
Sujith2660b812009-02-09 13:27:26 +05301085 INIT_CAL(&ah->adcdc_caldata);
1086 INSERT_CAL(ah, &ah->adcdc_caldata);
Sujithf1dc5602008-10-29 10:16:30 +05301087 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04d19dd2009-04-13 21:56:59 +05301088 "enabling ADC DC Calibration.\n");
Sujithf1dc5602008-10-29 10:16:30 +05301089 }
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -08001090 if (ath9k_hw_iscal_supported(ah, IQ_MISMATCH_CAL)) {
Sujith2660b812009-02-09 13:27:26 +05301091 INIT_CAL(&ah->iq_caldata);
1092 INSERT_CAL(ah, &ah->iq_caldata);
Sujithf1dc5602008-10-29 10:16:30 +05301093 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04d19dd2009-04-13 21:56:59 +05301094 "enabling IQ Calibration.\n");
Sujithf1dc5602008-10-29 10:16:30 +05301095 }
1096
Sujith2660b812009-02-09 13:27:26 +05301097 ah->cal_list_curr = ah->cal_list;
Sujithf1dc5602008-10-29 10:16:30 +05301098
Sujith2660b812009-02-09 13:27:26 +05301099 if (ah->cal_list_curr)
1100 ath9k_hw_reset_calibration(ah, ah->cal_list_curr);
Sujithf1dc5602008-10-29 10:16:30 +05301101 }
1102
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001103 chan->CalValid = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301104
1105 return true;
1106}
1107
Sujithcbfe9462009-04-13 21:56:56 +05301108const struct ath9k_percal_data iq_cal_multi_sample = {
Sujithf1dc5602008-10-29 10:16:30 +05301109 IQ_MISMATCH_CAL,
1110 MAX_CAL_SAMPLES,
1111 PER_MIN_LOG_COUNT,
1112 ath9k_hw_iqcal_collect,
1113 ath9k_hw_iqcalibrate
1114};
Sujithcbfe9462009-04-13 21:56:56 +05301115const struct ath9k_percal_data iq_cal_single_sample = {
Sujithf1dc5602008-10-29 10:16:30 +05301116 IQ_MISMATCH_CAL,
1117 MIN_CAL_SAMPLES,
1118 PER_MAX_LOG_COUNT,
1119 ath9k_hw_iqcal_collect,
1120 ath9k_hw_iqcalibrate
1121};
Sujithcbfe9462009-04-13 21:56:56 +05301122const struct ath9k_percal_data adc_gain_cal_multi_sample = {
Sujithf1dc5602008-10-29 10:16:30 +05301123 ADC_GAIN_CAL,
1124 MAX_CAL_SAMPLES,
1125 PER_MIN_LOG_COUNT,
1126 ath9k_hw_adc_gaincal_collect,
1127 ath9k_hw_adc_gaincal_calibrate
1128};
Sujithcbfe9462009-04-13 21:56:56 +05301129const struct ath9k_percal_data adc_gain_cal_single_sample = {
Sujithf1dc5602008-10-29 10:16:30 +05301130 ADC_GAIN_CAL,
1131 MIN_CAL_SAMPLES,
1132 PER_MAX_LOG_COUNT,
1133 ath9k_hw_adc_gaincal_collect,
1134 ath9k_hw_adc_gaincal_calibrate
1135};
Sujithcbfe9462009-04-13 21:56:56 +05301136const struct ath9k_percal_data adc_dc_cal_multi_sample = {
Sujithf1dc5602008-10-29 10:16:30 +05301137 ADC_DC_CAL,
1138 MAX_CAL_SAMPLES,
1139 PER_MIN_LOG_COUNT,
1140 ath9k_hw_adc_dccal_collect,
1141 ath9k_hw_adc_dccal_calibrate
1142};
Sujithcbfe9462009-04-13 21:56:56 +05301143const struct ath9k_percal_data adc_dc_cal_single_sample = {
Sujithf1dc5602008-10-29 10:16:30 +05301144 ADC_DC_CAL,
1145 MIN_CAL_SAMPLES,
1146 PER_MAX_LOG_COUNT,
1147 ath9k_hw_adc_dccal_collect,
1148 ath9k_hw_adc_dccal_calibrate
1149};
Sujithcbfe9462009-04-13 21:56:56 +05301150const struct ath9k_percal_data adc_init_dc_cal = {
Sujithf1dc5602008-10-29 10:16:30 +05301151 ADC_DC_INIT_CAL,
1152 MIN_CAL_SAMPLES,
1153 INIT_LOG_COUNT,
1154 ath9k_hw_adc_dccal_collect,
1155 ath9k_hw_adc_dccal_calibrate
1156};