blob: 016302c53cc57272bebdd416347b4fb3d85dea91 [file] [log] [blame]
Sujithf1dc5602008-10-29 10:16:30 +05301/*
2 * Copyright (c) 2008 Atheros Communications Inc.
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
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
26static bool ath9k_hw_nf_in_range(struct ath_hal *ah, s16 nf)
27{
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
89static void ath9k_hw_do_getnf(struct ath_hal *ah,
90 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
119 if (!AR_SREV_9280(ah)) {
120 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
157 if (!AR_SREV_9280(ah)) {
158 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
169static bool getNoiseFloorThresh(struct ath_hal *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:
Senthil Balasubramanianf9bbf432008-11-13 17:59:36 +0530175 *nft = (int8_t)ath9k_hw_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:
Senthil Balasubramanianf9bbf432008-11-13 17:59:36 +0530178 *nft = (int8_t)ath9k_hw_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
188static void ath9k_hw_setup_calibration(struct ath_hal *ah,
189 struct hal_cal_list *currCal)
190{
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
222static void ath9k_hw_reset_calibration(struct ath_hal *ah,
223 struct hal_cal_list *currCal)
224{
225 struct ath_hal_5416 *ahp = AH5416(ah);
226 int i;
227
228 ath9k_hw_setup_calibration(ah, currCal);
229
230 currCal->calState = CAL_RUNNING;
231
232 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
233 ahp->ah_Meas0.sign[i] = 0;
234 ahp->ah_Meas1.sign[i] = 0;
235 ahp->ah_Meas2.sign[i] = 0;
236 ahp->ah_Meas3.sign[i] = 0;
237 }
238
239 ahp->ah_CalSamples = 0;
240}
241
242static void ath9k_hw_per_calibration(struct ath_hal *ah,
243 struct ath9k_channel *ichan,
244 u8 rxchainmask,
245 struct hal_cal_list *currCal,
246 bool *isCalDone)
247{
248 struct ath_hal_5416 *ahp = AH5416(ah);
249
250 *isCalDone = false;
251
252 if (currCal->calState == CAL_RUNNING) {
253 if (!(REG_READ(ah, AR_PHY_TIMING_CTRL4(0)) &
254 AR_PHY_TIMING_CTRL4_DO_CAL)) {
255
256 currCal->calData->calCollect(ah);
257 ahp->ah_CalSamples++;
258
259 if (ahp->ah_CalSamples >= currCal->calData->calNumSamples) {
260 int i, numChains = 0;
261 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
262 if (rxchainmask & (1 << i))
263 numChains++;
264 }
265
266 currCal->calData->calPostProc(ah, numChains);
267 ichan->CalValid |= currCal->calData->calType;
268 currCal->calState = CAL_DONE;
269 *isCalDone = true;
270 } else {
271 ath9k_hw_setup_calibration(ah, currCal);
272 }
273 }
274 } else if (!(ichan->CalValid & currCal->calData->calType)) {
275 ath9k_hw_reset_calibration(ah, currCal);
276 }
277}
278
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800279/* Assumes you are talking about the currently configured channel */
Sujithf1dc5602008-10-29 10:16:30 +0530280static bool ath9k_hw_iscal_supported(struct ath_hal *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530281 enum hal_cal_types calType)
282{
283 struct ath_hal_5416 *ahp = AH5416(ah);
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800284 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +0530285
286 switch (calType & ahp->ah_suppCals) {
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800287 case IQ_MISMATCH_CAL: /* Both 2 GHz and 5 GHz support OFDM */
288 return true;
Sujithf1dc5602008-10-29 10:16:30 +0530289 case ADC_GAIN_CAL:
290 case ADC_DC_CAL:
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800291 if (conf->channel->band == IEEE80211_BAND_5GHZ &&
292 conf_is_ht20(conf))
293 return true;
Sujithf1dc5602008-10-29 10:16:30 +0530294 break;
295 }
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800296 return false;
Sujithf1dc5602008-10-29 10:16:30 +0530297}
298
299static void ath9k_hw_iqcal_collect(struct ath_hal *ah)
300{
301 struct ath_hal_5416 *ahp = AH5416(ah);
302 int i;
303
304 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
305 ahp->ah_totalPowerMeasI[i] +=
306 REG_READ(ah, AR_PHY_CAL_MEAS_0(i));
307 ahp->ah_totalPowerMeasQ[i] +=
308 REG_READ(ah, AR_PHY_CAL_MEAS_1(i));
309 ahp->ah_totalIqCorrMeas[i] +=
310 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_2(i));
311 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
312 "%d: Chn %d pmi=0x%08x;pmq=0x%08x;iqcm=0x%08x;\n",
313 ahp->ah_CalSamples, i, ahp->ah_totalPowerMeasI[i],
314 ahp->ah_totalPowerMeasQ[i],
315 ahp->ah_totalIqCorrMeas[i]);
316 }
317}
318
319static void ath9k_hw_adc_gaincal_collect(struct ath_hal *ah)
320{
321 struct ath_hal_5416 *ahp = AH5416(ah);
322 int i;
323
324 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
325 ahp->ah_totalAdcIOddPhase[i] +=
326 REG_READ(ah, AR_PHY_CAL_MEAS_0(i));
327 ahp->ah_totalAdcIEvenPhase[i] +=
328 REG_READ(ah, AR_PHY_CAL_MEAS_1(i));
329 ahp->ah_totalAdcQOddPhase[i] +=
330 REG_READ(ah, AR_PHY_CAL_MEAS_2(i));
331 ahp->ah_totalAdcQEvenPhase[i] +=
332 REG_READ(ah, AR_PHY_CAL_MEAS_3(i));
333
334 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
335 "%d: Chn %d oddi=0x%08x; eveni=0x%08x; "
336 "oddq=0x%08x; evenq=0x%08x;\n",
337 ahp->ah_CalSamples, i,
338 ahp->ah_totalAdcIOddPhase[i],
339 ahp->ah_totalAdcIEvenPhase[i],
340 ahp->ah_totalAdcQOddPhase[i],
341 ahp->ah_totalAdcQEvenPhase[i]);
342 }
343}
344
345static void ath9k_hw_adc_dccal_collect(struct ath_hal *ah)
346{
347 struct ath_hal_5416 *ahp = AH5416(ah);
348 int i;
349
350 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
351 ahp->ah_totalAdcDcOffsetIOddPhase[i] +=
352 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_0(i));
353 ahp->ah_totalAdcDcOffsetIEvenPhase[i] +=
354 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_1(i));
355 ahp->ah_totalAdcDcOffsetQOddPhase[i] +=
356 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_2(i));
357 ahp->ah_totalAdcDcOffsetQEvenPhase[i] +=
358 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_3(i));
359
360 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
361 "%d: Chn %d oddi=0x%08x; eveni=0x%08x; "
362 "oddq=0x%08x; evenq=0x%08x;\n",
363 ahp->ah_CalSamples, i,
364 ahp->ah_totalAdcDcOffsetIOddPhase[i],
365 ahp->ah_totalAdcDcOffsetIEvenPhase[i],
366 ahp->ah_totalAdcDcOffsetQOddPhase[i],
367 ahp->ah_totalAdcDcOffsetQEvenPhase[i]);
368 }
369}
370
371static void ath9k_hw_iqcalibrate(struct ath_hal *ah, u8 numChains)
372{
373 struct ath_hal_5416 *ahp = AH5416(ah);
374 u32 powerMeasQ, powerMeasI, iqCorrMeas;
375 u32 qCoffDenom, iCoffDenom;
376 int32_t qCoff, iCoff;
377 int iqCorrNeg, i;
378
379 for (i = 0; i < numChains; i++) {
380 powerMeasI = ahp->ah_totalPowerMeasI[i];
381 powerMeasQ = ahp->ah_totalPowerMeasQ[i];
382 iqCorrMeas = ahp->ah_totalIqCorrMeas[i];
383
384 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
385 "Starting IQ Cal and Correction for Chain %d\n",
386 i);
387
388 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
389 "Orignal: Chn %diq_corr_meas = 0x%08x\n",
390 i, ahp->ah_totalIqCorrMeas[i]);
391
392 iqCorrNeg = 0;
393
394 if (iqCorrMeas > 0x80000000) {
395 iqCorrMeas = (0xffffffff - iqCorrMeas) + 1;
396 iqCorrNeg = 1;
397 }
398
399 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
400 "Chn %d pwr_meas_i = 0x%08x\n", i, powerMeasI);
401 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
402 "Chn %d pwr_meas_q = 0x%08x\n", i, powerMeasQ);
403 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE, "iqCorrNeg is 0x%08x\n",
404 iqCorrNeg);
405
406 iCoffDenom = (powerMeasI / 2 + powerMeasQ / 2) / 128;
407 qCoffDenom = powerMeasQ / 64;
408
409 if (powerMeasQ != 0) {
410 iCoff = iqCorrMeas / iCoffDenom;
411 qCoff = powerMeasI / qCoffDenom - 64;
412 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
413 "Chn %d iCoff = 0x%08x\n", i, iCoff);
414 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
415 "Chn %d qCoff = 0x%08x\n", i, qCoff);
416
417 iCoff = iCoff & 0x3f;
418 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
419 "New: Chn %d iCoff = 0x%08x\n", i, iCoff);
420 if (iqCorrNeg == 0x0)
421 iCoff = 0x40 - iCoff;
422
423 if (qCoff > 15)
424 qCoff = 15;
425 else if (qCoff <= -16)
426 qCoff = 16;
427
428 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
429 "Chn %d : iCoff = 0x%x qCoff = 0x%x\n",
430 i, iCoff, qCoff);
431
432 REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(i),
433 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF,
434 iCoff);
435 REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(i),
436 AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF,
437 qCoff);
438 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
439 "IQ Cal and Correction done for Chain %d\n",
440 i);
441 }
442 }
443
444 REG_SET_BIT(ah, AR_PHY_TIMING_CTRL4(0),
445 AR_PHY_TIMING_CTRL4_IQCORR_ENABLE);
446}
447
448static void ath9k_hw_adc_gaincal_calibrate(struct ath_hal *ah, u8 numChains)
449{
450 struct ath_hal_5416 *ahp = AH5416(ah);
451 u32 iOddMeasOffset, iEvenMeasOffset, qOddMeasOffset, qEvenMeasOffset;
452 u32 qGainMismatch, iGainMismatch, val, i;
453
454 for (i = 0; i < numChains; i++) {
455 iOddMeasOffset = ahp->ah_totalAdcIOddPhase[i];
456 iEvenMeasOffset = ahp->ah_totalAdcIEvenPhase[i];
457 qOddMeasOffset = ahp->ah_totalAdcQOddPhase[i];
458 qEvenMeasOffset = ahp->ah_totalAdcQEvenPhase[i];
459
460 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
461 "Starting ADC Gain Cal for Chain %d\n", i);
462
463 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
464 "Chn %d pwr_meas_odd_i = 0x%08x\n", i,
465 iOddMeasOffset);
466 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
467 "Chn %d pwr_meas_even_i = 0x%08x\n", i,
468 iEvenMeasOffset);
469 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
470 "Chn %d pwr_meas_odd_q = 0x%08x\n", i,
471 qOddMeasOffset);
472 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
473 "Chn %d pwr_meas_even_q = 0x%08x\n", i,
474 qEvenMeasOffset);
475
476 if (iOddMeasOffset != 0 && qEvenMeasOffset != 0) {
477 iGainMismatch =
478 ((iEvenMeasOffset * 32) /
479 iOddMeasOffset) & 0x3f;
480 qGainMismatch =
481 ((qOddMeasOffset * 32) /
482 qEvenMeasOffset) & 0x3f;
483
484 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
485 "Chn %d gain_mismatch_i = 0x%08x\n", i,
486 iGainMismatch);
487 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
488 "Chn %d gain_mismatch_q = 0x%08x\n", i,
489 qGainMismatch);
490
491 val = REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i));
492 val &= 0xfffff000;
493 val |= (qGainMismatch) | (iGainMismatch << 6);
494 REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i), val);
495
496 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
497 "ADC Gain Cal done for Chain %d\n", i);
498 }
499 }
500
501 REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0),
502 REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0)) |
503 AR_PHY_NEW_ADC_GAIN_CORR_ENABLE);
504}
505
506static void ath9k_hw_adc_dccal_calibrate(struct ath_hal *ah, u8 numChains)
507{
508 struct ath_hal_5416 *ahp = AH5416(ah);
509 u32 iOddMeasOffset, iEvenMeasOffset, val, i;
510 int32_t qOddMeasOffset, qEvenMeasOffset, qDcMismatch, iDcMismatch;
511 const struct hal_percal_data *calData =
512 ahp->ah_cal_list_curr->calData;
513 u32 numSamples =
514 (1 << (calData->calCountMax + 5)) * calData->calNumSamples;
515
516 for (i = 0; i < numChains; i++) {
517 iOddMeasOffset = ahp->ah_totalAdcDcOffsetIOddPhase[i];
518 iEvenMeasOffset = ahp->ah_totalAdcDcOffsetIEvenPhase[i];
519 qOddMeasOffset = ahp->ah_totalAdcDcOffsetQOddPhase[i];
520 qEvenMeasOffset = ahp->ah_totalAdcDcOffsetQEvenPhase[i];
521
522 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
523 "Starting ADC DC Offset Cal for Chain %d\n", i);
524
525 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
526 "Chn %d pwr_meas_odd_i = %d\n", i,
527 iOddMeasOffset);
528 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
529 "Chn %d pwr_meas_even_i = %d\n", i,
530 iEvenMeasOffset);
531 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
532 "Chn %d pwr_meas_odd_q = %d\n", i,
533 qOddMeasOffset);
534 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
535 "Chn %d pwr_meas_even_q = %d\n", i,
536 qEvenMeasOffset);
537
538 iDcMismatch = (((iEvenMeasOffset - iOddMeasOffset) * 2) /
539 numSamples) & 0x1ff;
540 qDcMismatch = (((qOddMeasOffset - qEvenMeasOffset) * 2) /
541 numSamples) & 0x1ff;
542
543 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
544 "Chn %d dc_offset_mismatch_i = 0x%08x\n", i,
545 iDcMismatch);
546 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
547 "Chn %d dc_offset_mismatch_q = 0x%08x\n", i,
548 qDcMismatch);
549
550 val = REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i));
551 val &= 0xc0000fff;
552 val |= (qDcMismatch << 12) | (iDcMismatch << 21);
553 REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i), val);
554
555 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
556 "ADC DC Offset Cal done for Chain %d\n", i);
557 }
558
559 REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0),
560 REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0)) |
561 AR_PHY_NEW_ADC_DC_OFFSET_CORR_ENABLE);
562}
563
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800564/* This is done for the currently configured channel */
565bool ath9k_hw_reset_calvalid(struct ath_hal *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530566{
567 struct ath_hal_5416 *ahp = AH5416(ah);
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800568 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +0530569 struct hal_cal_list *currCal = ahp->ah_cal_list_curr;
570
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800571 if (!ah->ah_curchan)
572 return true;
Sujithf1dc5602008-10-29 10:16:30 +0530573
574 if (!AR_SREV_9100(ah) && !AR_SREV_9160_10_OR_LATER(ah))
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800575 return true;
Sujithf1dc5602008-10-29 10:16:30 +0530576
577 if (currCal == NULL)
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800578 return true;
Sujithf1dc5602008-10-29 10:16:30 +0530579
580 if (currCal->calState != CAL_DONE) {
581 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530582 "Calibration state incorrect, %d\n",
583 currCal->calState);
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800584 return true;
Sujithf1dc5602008-10-29 10:16:30 +0530585 }
586
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800587 if (!ath9k_hw_iscal_supported(ah, currCal->calData->calType))
588 return true;
Sujithf1dc5602008-10-29 10:16:30 +0530589
590 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800591 "Resetting Cal %d state for channel %u\n",
592 currCal->calData->calType, conf->channel->center_freq);
Sujithf1dc5602008-10-29 10:16:30 +0530593
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800594 ah->ah_curchan->CalValid &= ~currCal->calData->calType;
Sujithf1dc5602008-10-29 10:16:30 +0530595 currCal->calState = CAL_WAITING;
596
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800597 return false;
Sujithf1dc5602008-10-29 10:16:30 +0530598}
599
600void ath9k_hw_start_nfcal(struct ath_hal *ah)
601{
602 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL,
603 AR_PHY_AGC_CONTROL_ENABLE_NF);
604 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL,
605 AR_PHY_AGC_CONTROL_NO_UPDATE_NF);
606 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF);
607}
608
609void ath9k_hw_loadnf(struct ath_hal *ah, struct ath9k_channel *chan)
610{
611 struct ath9k_nfcal_hist *h;
612 int i, j;
613 int32_t val;
614 const u32 ar5416_cca_regs[6] = {
615 AR_PHY_CCA,
616 AR_PHY_CH1_CCA,
617 AR_PHY_CH2_CCA,
618 AR_PHY_EXT_CCA,
619 AR_PHY_CH1_EXT_CCA,
620 AR_PHY_CH2_EXT_CCA
621 };
622 u8 chainmask;
623
Sujith5dad40c2009-01-23 11:20:55 +0530624 if (AR_SREV_9285(ah))
625 chainmask = 0x9;
626 else if (AR_SREV_9280(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530627 chainmask = 0x1B;
628 else
629 chainmask = 0x3F;
630
Sujithf1dc5602008-10-29 10:16:30 +0530631 h = ah->nfCalHist;
Sujithf1dc5602008-10-29 10:16:30 +0530632
633 for (i = 0; i < NUM_NF_READINGS; i++) {
634 if (chainmask & (1 << i)) {
635 val = REG_READ(ah, ar5416_cca_regs[i]);
636 val &= 0xFFFFFE00;
637 val |= (((u32) (h[i].privNF) << 1) & 0x1ff);
638 REG_WRITE(ah, ar5416_cca_regs[i], val);
639 }
640 }
641
642 REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
643 AR_PHY_AGC_CONTROL_ENABLE_NF);
644 REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
645 AR_PHY_AGC_CONTROL_NO_UPDATE_NF);
646 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF);
647
648 for (j = 0; j < 1000; j++) {
649 if ((REG_READ(ah, AR_PHY_AGC_CONTROL) &
650 AR_PHY_AGC_CONTROL_NF) == 0)
651 break;
652 udelay(10);
653 }
654
655 for (i = 0; i < NUM_NF_READINGS; i++) {
656 if (chainmask & (1 << i)) {
657 val = REG_READ(ah, ar5416_cca_regs[i]);
658 val &= 0xFFFFFE00;
659 val |= (((u32) (-50) << 1) & 0x1ff);
660 REG_WRITE(ah, ar5416_cca_regs[i], val);
661 }
662 }
663}
664
665int16_t ath9k_hw_getnf(struct ath_hal *ah,
666 struct ath9k_channel *chan)
667{
668 int16_t nf, nfThresh;
669 int16_t nfarray[NUM_NF_READINGS] = { 0 };
670 struct ath9k_nfcal_hist *h;
Luis R. Rodriguez76061ab2008-12-23 15:58:41 -0800671 struct ieee80211_channel *c = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +0530672
673 chan->channelFlags &= (~CHANNEL_CW_INT);
674 if (REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF) {
675 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530676 "NF did not complete in calibration window\n");
Sujithf1dc5602008-10-29 10:16:30 +0530677 nf = 0;
678 chan->rawNoiseFloor = nf;
679 return chan->rawNoiseFloor;
680 } else {
681 ath9k_hw_do_getnf(ah, nfarray);
682 nf = nfarray[0];
Luis R. Rodriguez76061ab2008-12-23 15:58:41 -0800683 if (getNoiseFloorThresh(ah, c->band, &nfThresh)
Sujithf1dc5602008-10-29 10:16:30 +0530684 && nf > nfThresh) {
685 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530686 "noise floor failed detected; "
687 "detected %d, threshold %d\n",
Sujithf1dc5602008-10-29 10:16:30 +0530688 nf, nfThresh);
689 chan->channelFlags |= CHANNEL_CW_INT;
690 }
691 }
692
Sujithf1dc5602008-10-29 10:16:30 +0530693 h = ah->nfCalHist;
Sujithf1dc5602008-10-29 10:16:30 +0530694
695 ath9k_hw_update_nfcal_hist_buffer(h, nfarray);
696 chan->rawNoiseFloor = h[0].privNF;
697
698 return chan->rawNoiseFloor;
699}
700
701void ath9k_init_nfcal_hist_buffer(struct ath_hal *ah)
702{
703 int i, j;
704
705 for (i = 0; i < NUM_NF_READINGS; i++) {
706 ah->nfCalHist[i].currIndex = 0;
707 ah->nfCalHist[i].privNF = AR_PHY_CCA_MAX_GOOD_VALUE;
708 ah->nfCalHist[i].invalidNFcount =
709 AR_PHY_CCA_FILTERWINDOW_LENGTH;
710 for (j = 0; j < ATH9K_NF_CAL_HIST_MAX; j++) {
711 ah->nfCalHist[i].nfCalBuffer[j] =
712 AR_PHY_CCA_MAX_GOOD_VALUE;
713 }
714 }
715 return;
716}
717
718s16 ath9k_hw_getchan_noise(struct ath_hal *ah, struct ath9k_channel *chan)
719{
Sujithf1dc5602008-10-29 10:16:30 +0530720 s16 nf;
721
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800722 if (chan->rawNoiseFloor == 0)
Luis R. Rodrigueze56db712008-12-23 15:58:47 -0800723 nf = -96;
724 else
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800725 nf = chan->rawNoiseFloor;
Sujithf1dc5602008-10-29 10:16:30 +0530726
727 if (!ath9k_hw_nf_in_range(ah, nf))
728 nf = ATH_DEFAULT_NOISE_FLOOR;
729
730 return nf;
731}
732
733bool ath9k_hw_calibrate(struct ath_hal *ah, struct ath9k_channel *chan,
734 u8 rxchainmask, bool longcal,
735 bool *isCalDone)
736{
737 struct ath_hal_5416 *ahp = AH5416(ah);
738 struct hal_cal_list *currCal = ahp->ah_cal_list_curr;
Sujithf1dc5602008-10-29 10:16:30 +0530739
740 *isCalDone = true;
741
Sujithf1dc5602008-10-29 10:16:30 +0530742 if (currCal &&
743 (currCal->calState == CAL_RUNNING ||
744 currCal->calState == CAL_WAITING)) {
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800745 ath9k_hw_per_calibration(ah, chan, rxchainmask, currCal,
Sujithf1dc5602008-10-29 10:16:30 +0530746 isCalDone);
747 if (*isCalDone) {
748 ahp->ah_cal_list_curr = currCal = currCal->calNext;
749
750 if (currCal->calState == CAL_WAITING) {
751 *isCalDone = false;
752 ath9k_hw_reset_calibration(ah, currCal);
753 }
754 }
755 }
756
757 if (longcal) {
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800758 ath9k_hw_getnf(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +0530759 ath9k_hw_loadnf(ah, ah->ah_curchan);
760 ath9k_hw_start_nfcal(ah);
761
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800762 if (chan->channelFlags & CHANNEL_CW_INT)
763 chan->channelFlags &= ~CHANNEL_CW_INT;
Sujithf1dc5602008-10-29 10:16:30 +0530764 }
765
766 return true;
767}
768
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530769static inline void ath9k_hw_9285_pa_cal(struct ath_hal *ah)
770{
771
772 u32 regVal;
773 int i, offset, offs_6_1, offs_0;
774 u32 ccomp_org, reg_field;
775 u32 regList[][2] = {
776 { 0x786c, 0 },
777 { 0x7854, 0 },
778 { 0x7820, 0 },
779 { 0x7824, 0 },
780 { 0x7868, 0 },
781 { 0x783c, 0 },
782 { 0x7838, 0 },
783 };
784
785 if (AR_SREV_9285_11(ah)) {
786 REG_WRITE(ah, AR9285_AN_TOP4, (AR9285_AN_TOP4_DEFAULT | 0x14));
787 udelay(10);
788 }
789
790 for (i = 0; i < ARRAY_SIZE(regList); i++)
791 regList[i][1] = REG_READ(ah, regList[i][0]);
792
793 regVal = REG_READ(ah, 0x7834);
794 regVal &= (~(0x1));
795 REG_WRITE(ah, 0x7834, regVal);
796 regVal = REG_READ(ah, 0x9808);
797 regVal |= (0x1 << 27);
798 REG_WRITE(ah, 0x9808, regVal);
799
800 REG_RMW_FIELD(ah, AR9285_AN_TOP3, AR9285_AN_TOP3_PWDDAC, 1);
801 REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDRXTXBB1, 1);
802 REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDV2I, 1);
803 REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDDACIF, 1);
804 REG_RMW_FIELD(ah, AR9285_AN_RF2G2, AR9285_AN_RF2G2_OFFCAL, 0);
805 REG_RMW_FIELD(ah, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PWDDB, 0);
806 REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_ENPACAL, 0);
807 REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV1, 1);
808 REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV2, 0);
809 REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPAOUT, 0);
810 REG_RMW_FIELD(ah, AR9285_AN_RF2G8, AR9285_AN_RF2G8_PADRVGN2TAB0, 7);
811 REG_RMW_FIELD(ah, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PADRVGN2TAB0, 0);
812 ccomp_org = MS(REG_READ(ah, AR9285_AN_RF2G6), AR9285_AN_RF2G6_CCOMP);
813 REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_CCOMP, 7);
814
815 REG_WRITE(ah, AR9285_AN_TOP2, 0xca0358a0);
816 udelay(30);
817 REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_OFFS, 0);
818 REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, 0);
819
820 for (i = 6; i > 0; i--) {
821 regVal = REG_READ(ah, 0x7834);
822 regVal |= (1 << (19 + i));
823 REG_WRITE(ah, 0x7834, regVal);
824 udelay(1);
825 regVal = REG_READ(ah, 0x7834);
826 regVal &= (~(0x1 << (19 + i)));
827 reg_field = MS(REG_READ(ah, 0x7840), AR9285_AN_RXTXBB1_SPARE9);
828 regVal |= (reg_field << (19 + i));
829 REG_WRITE(ah, 0x7834, regVal);
830 }
831
832 REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, 1);
833 udelay(1);
834 reg_field = MS(REG_READ(ah, AR9285_AN_RF2G9), AR9285_AN_RXTXBB1_SPARE9);
835 REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, reg_field);
836 offs_6_1 = MS(REG_READ(ah, AR9285_AN_RF2G6), AR9285_AN_RF2G6_OFFS);
837 offs_0 = MS(REG_READ(ah, AR9285_AN_RF2G3), AR9285_AN_RF2G3_PDVCCOMP);
838
839 offset = (offs_6_1<<1) | offs_0;
840 offset = offset - 0;
841 offs_6_1 = offset>>1;
842 offs_0 = offset & 1;
843
844 REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_OFFS, offs_6_1);
845 REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, offs_0);
846
847 regVal = REG_READ(ah, 0x7834);
848 regVal |= 0x1;
849 REG_WRITE(ah, 0x7834, regVal);
850 regVal = REG_READ(ah, 0x9808);
851 regVal &= (~(0x1 << 27));
852 REG_WRITE(ah, 0x9808, regVal);
853
854 for (i = 0; i < ARRAY_SIZE(regList); i++)
855 REG_WRITE(ah, regList[i][0], regList[i][1]);
856
857 REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_CCOMP, ccomp_org);
858
859 if (AR_SREV_9285_11(ah))
860 REG_WRITE(ah, AR9285_AN_TOP4, AR9285_AN_TOP4_DEFAULT);
861
862}
863
Sujithf1dc5602008-10-29 10:16:30 +0530864bool ath9k_hw_init_cal(struct ath_hal *ah,
865 struct ath9k_channel *chan)
866{
867 struct ath_hal_5416 *ahp = AH5416(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530868
869 REG_WRITE(ah, AR_PHY_AGC_CONTROL,
870 REG_READ(ah, AR_PHY_AGC_CONTROL) |
871 AR_PHY_AGC_CONTROL_CAL);
872
873 if (!ath9k_hw_wait(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL, 0)) {
874 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530875 "offset calibration failed to complete in 1ms; "
876 "noisy environment?\n");
Sujithf1dc5602008-10-29 10:16:30 +0530877 return false;
878 }
879
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530880 if (AR_SREV_9285(ah) && AR_SREV_9285_11_OR_LATER(ah))
881 ath9k_hw_9285_pa_cal(ah);
882
Sujithf1dc5602008-10-29 10:16:30 +0530883 REG_WRITE(ah, AR_PHY_AGC_CONTROL,
884 REG_READ(ah, AR_PHY_AGC_CONTROL) |
885 AR_PHY_AGC_CONTROL_NF);
886
887 ahp->ah_cal_list = ahp->ah_cal_list_last = ahp->ah_cal_list_curr = NULL;
888
889 if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah)) {
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800890 if (ath9k_hw_iscal_supported(ah, ADC_GAIN_CAL)) {
Sujithf1dc5602008-10-29 10:16:30 +0530891 INIT_CAL(&ahp->ah_adcGainCalData);
892 INSERT_CAL(ahp, &ahp->ah_adcGainCalData);
893 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530894 "enabling ADC Gain Calibration.\n");
Sujithf1dc5602008-10-29 10:16:30 +0530895 }
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800896 if (ath9k_hw_iscal_supported(ah, ADC_DC_CAL)) {
Sujithf1dc5602008-10-29 10:16:30 +0530897 INIT_CAL(&ahp->ah_adcDcCalData);
898 INSERT_CAL(ahp, &ahp->ah_adcDcCalData);
899 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530900 "enabling ADC DC Calibration.\n");
Sujithf1dc5602008-10-29 10:16:30 +0530901 }
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800902 if (ath9k_hw_iscal_supported(ah, IQ_MISMATCH_CAL)) {
Sujithf1dc5602008-10-29 10:16:30 +0530903 INIT_CAL(&ahp->ah_iqCalData);
904 INSERT_CAL(ahp, &ahp->ah_iqCalData);
905 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530906 "enabling IQ Calibration.\n");
Sujithf1dc5602008-10-29 10:16:30 +0530907 }
908
909 ahp->ah_cal_list_curr = ahp->ah_cal_list;
910
911 if (ahp->ah_cal_list_curr)
912 ath9k_hw_reset_calibration(ah, ahp->ah_cal_list_curr);
913 }
914
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800915 chan->CalValid = 0;
Sujithf1dc5602008-10-29 10:16:30 +0530916
917 return true;
918}
919
920const struct hal_percal_data iq_cal_multi_sample = {
921 IQ_MISMATCH_CAL,
922 MAX_CAL_SAMPLES,
923 PER_MIN_LOG_COUNT,
924 ath9k_hw_iqcal_collect,
925 ath9k_hw_iqcalibrate
926};
927const struct hal_percal_data iq_cal_single_sample = {
928 IQ_MISMATCH_CAL,
929 MIN_CAL_SAMPLES,
930 PER_MAX_LOG_COUNT,
931 ath9k_hw_iqcal_collect,
932 ath9k_hw_iqcalibrate
933};
934const struct hal_percal_data adc_gain_cal_multi_sample = {
935 ADC_GAIN_CAL,
936 MAX_CAL_SAMPLES,
937 PER_MIN_LOG_COUNT,
938 ath9k_hw_adc_gaincal_collect,
939 ath9k_hw_adc_gaincal_calibrate
940};
941const struct hal_percal_data adc_gain_cal_single_sample = {
942 ADC_GAIN_CAL,
943 MIN_CAL_SAMPLES,
944 PER_MAX_LOG_COUNT,
945 ath9k_hw_adc_gaincal_collect,
946 ath9k_hw_adc_gaincal_calibrate
947};
948const struct hal_percal_data adc_dc_cal_multi_sample = {
949 ADC_DC_CAL,
950 MAX_CAL_SAMPLES,
951 PER_MIN_LOG_COUNT,
952 ath9k_hw_adc_dccal_collect,
953 ath9k_hw_adc_dccal_calibrate
954};
955const struct hal_percal_data adc_dc_cal_single_sample = {
956 ADC_DC_CAL,
957 MIN_CAL_SAMPLES,
958 PER_MAX_LOG_COUNT,
959 ath9k_hw_adc_dccal_collect,
960 ath9k_hw_adc_dccal_calibrate
961};
962const struct hal_percal_data adc_init_dc_cal = {
963 ADC_DC_INIT_CAL,
964 MIN_CAL_SAMPLES,
965 INIT_LOG_COUNT,
966 ath9k_hw_adc_dccal_collect,
967 ath9k_hw_adc_dccal_calibrate
968};