blob: 707289685b4113c6b1a3664b4e17c37b9df5ee18 [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
17#include "core.h"
18#include "hw.h"
19#include "reg.h"
20#include "phy.h"
21
22static const int16_t NOISE_FLOOR[] = { -96, -93, -98, -96, -93, -96 };
23
24/* We can tune this as we go by monitoring really low values */
25#define ATH9K_NF_TOO_LOW -60
26
27/* AR5416 may return very high value (like -31 dBm), in those cases the nf
28 * is incorrect and we should use the static NF value. Later we can try to
29 * find out why they are reporting these values */
30
31static bool ath9k_hw_nf_in_range(struct ath_hal *ah, s16 nf)
32{
33 if (nf > ATH9K_NF_TOO_LOW) {
Sujith04bd4632008-11-28 22:18:05 +053034 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
35 "noise floor value detected (%d) is "
Sujithf1dc5602008-10-29 10:16:30 +053036 "lower than what we think is a "
37 "reasonable value (%d)\n",
Sujith04bd4632008-11-28 22:18:05 +053038 nf, ATH9K_NF_TOO_LOW);
Sujithf1dc5602008-10-29 10:16:30 +053039 return false;
40 }
41 return true;
42}
43
44static int16_t ath9k_hw_get_nf_hist_mid(int16_t *nfCalBuffer)
45{
46 int16_t nfval;
47 int16_t sort[ATH9K_NF_CAL_HIST_MAX];
48 int i, j;
49
50 for (i = 0; i < ATH9K_NF_CAL_HIST_MAX; i++)
51 sort[i] = nfCalBuffer[i];
52
53 for (i = 0; i < ATH9K_NF_CAL_HIST_MAX - 1; i++) {
54 for (j = 1; j < ATH9K_NF_CAL_HIST_MAX - i; j++) {
55 if (sort[j] > sort[j - 1]) {
56 nfval = sort[j];
57 sort[j] = sort[j - 1];
58 sort[j - 1] = nfval;
59 }
60 }
61 }
62 nfval = sort[(ATH9K_NF_CAL_HIST_MAX - 1) >> 1];
63
64 return nfval;
65}
66
67static void ath9k_hw_update_nfcal_hist_buffer(struct ath9k_nfcal_hist *h,
68 int16_t *nfarray)
69{
70 int i;
71
72 for (i = 0; i < NUM_NF_READINGS; i++) {
73 h[i].nfCalBuffer[h[i].currIndex] = nfarray[i];
74
75 if (++h[i].currIndex >= ATH9K_NF_CAL_HIST_MAX)
76 h[i].currIndex = 0;
77
78 if (h[i].invalidNFcount > 0) {
79 if (nfarray[i] < AR_PHY_CCA_MIN_BAD_VALUE ||
80 nfarray[i] > AR_PHY_CCA_MAX_HIGH_VALUE) {
81 h[i].invalidNFcount = ATH9K_NF_CAL_HIST_MAX;
82 } else {
83 h[i].invalidNFcount--;
84 h[i].privNF = nfarray[i];
85 }
86 } else {
87 h[i].privNF =
88 ath9k_hw_get_nf_hist_mid(h[i].nfCalBuffer);
89 }
90 }
91 return;
92}
93
94static void ath9k_hw_do_getnf(struct ath_hal *ah,
95 int16_t nfarray[NUM_NF_READINGS])
96{
97 int16_t nf;
98
99 if (AR_SREV_9280_10_OR_LATER(ah))
100 nf = MS(REG_READ(ah, AR_PHY_CCA), AR9280_PHY_MINCCA_PWR);
101 else
102 nf = MS(REG_READ(ah, AR_PHY_CCA), AR_PHY_MINCCA_PWR);
103
104 if (nf & 0x100)
105 nf = 0 - ((nf ^ 0x1ff) + 1);
106 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
107 "NF calibrated [ctl] [chain 0] is %d\n", nf);
108 nfarray[0] = nf;
109
110 if (AR_SREV_9280_10_OR_LATER(ah))
111 nf = MS(REG_READ(ah, AR_PHY_CH1_CCA),
112 AR9280_PHY_CH1_MINCCA_PWR);
113 else
114 nf = MS(REG_READ(ah, AR_PHY_CH1_CCA),
115 AR_PHY_CH1_MINCCA_PWR);
116
117 if (nf & 0x100)
118 nf = 0 - ((nf ^ 0x1ff) + 1);
Sujith04bd4632008-11-28 22:18:05 +0530119 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujithf1dc5602008-10-29 10:16:30 +0530120 "NF calibrated [ctl] [chain 1] is %d\n", nf);
121 nfarray[1] = nf;
122
123 if (!AR_SREV_9280(ah)) {
124 nf = MS(REG_READ(ah, AR_PHY_CH2_CCA),
125 AR_PHY_CH2_MINCCA_PWR);
126 if (nf & 0x100)
127 nf = 0 - ((nf ^ 0x1ff) + 1);
Sujith04bd4632008-11-28 22:18:05 +0530128 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujithf1dc5602008-10-29 10:16:30 +0530129 "NF calibrated [ctl] [chain 2] is %d\n", nf);
130 nfarray[2] = nf;
131 }
132
133 if (AR_SREV_9280_10_OR_LATER(ah))
134 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA),
135 AR9280_PHY_EXT_MINCCA_PWR);
136 else
137 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA),
138 AR_PHY_EXT_MINCCA_PWR);
139
140 if (nf & 0x100)
141 nf = 0 - ((nf ^ 0x1ff) + 1);
Sujith04bd4632008-11-28 22:18:05 +0530142 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujithf1dc5602008-10-29 10:16:30 +0530143 "NF calibrated [ext] [chain 0] is %d\n", nf);
144 nfarray[3] = nf;
145
146 if (AR_SREV_9280_10_OR_LATER(ah))
147 nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA),
148 AR9280_PHY_CH1_EXT_MINCCA_PWR);
149 else
150 nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA),
151 AR_PHY_CH1_EXT_MINCCA_PWR);
152
153 if (nf & 0x100)
154 nf = 0 - ((nf ^ 0x1ff) + 1);
155 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
156 "NF calibrated [ext] [chain 1] is %d\n", nf);
157 nfarray[4] = nf;
158
159 if (!AR_SREV_9280(ah)) {
160 nf = MS(REG_READ(ah, AR_PHY_CH2_EXT_CCA),
161 AR_PHY_CH2_EXT_MINCCA_PWR);
162 if (nf & 0x100)
163 nf = 0 - ((nf ^ 0x1ff) + 1);
Sujith04bd4632008-11-28 22:18:05 +0530164 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujithf1dc5602008-10-29 10:16:30 +0530165 "NF calibrated [ext] [chain 2] is %d\n", nf);
166 nfarray[5] = nf;
167 }
168}
169
170static bool getNoiseFloorThresh(struct ath_hal *ah,
Luis R. Rodriguez76061ab2008-12-23 15:58:41 -0800171 enum ieee80211_band band,
Sujithf1dc5602008-10-29 10:16:30 +0530172 int16_t *nft)
173{
Luis R. Rodriguez76061ab2008-12-23 15:58:41 -0800174 switch (band) {
175 case IEEE80211_BAND_5GHZ:
Senthil Balasubramanianf9bbf432008-11-13 17:59:36 +0530176 *nft = (int8_t)ath9k_hw_get_eeprom(ah, EEP_NFTHRESH_5);
Sujithf1dc5602008-10-29 10:16:30 +0530177 break;
Luis R. Rodriguez76061ab2008-12-23 15:58:41 -0800178 case IEEE80211_BAND_2GHZ:
Senthil Balasubramanianf9bbf432008-11-13 17:59:36 +0530179 *nft = (int8_t)ath9k_hw_get_eeprom(ah, EEP_NFTHRESH_2);
Sujithf1dc5602008-10-29 10:16:30 +0530180 break;
181 default:
Luis R. Rodriguez76061ab2008-12-23 15:58:41 -0800182 BUG_ON(1);
Sujithf1dc5602008-10-29 10:16:30 +0530183 return false;
184 }
185
186 return true;
187}
188
189static void ath9k_hw_setup_calibration(struct ath_hal *ah,
190 struct hal_cal_list *currCal)
191{
192 REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(0),
193 AR_PHY_TIMING_CTRL4_IQCAL_LOG_COUNT_MAX,
194 currCal->calData->calCountMax);
195
196 switch (currCal->calData->calType) {
197 case IQ_MISMATCH_CAL:
198 REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_IQ);
199 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530200 "starting IQ Mismatch Calibration\n");
Sujithf1dc5602008-10-29 10:16:30 +0530201 break;
202 case ADC_GAIN_CAL:
203 REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_ADC_GAIN);
204 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530205 "starting ADC Gain Calibration\n");
Sujithf1dc5602008-10-29 10:16:30 +0530206 break;
207 case ADC_DC_CAL:
208 REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_ADC_DC_PER);
209 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530210 "starting ADC DC Calibration\n");
Sujithf1dc5602008-10-29 10:16:30 +0530211 break;
212 case ADC_DC_INIT_CAL:
213 REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_ADC_DC_INIT);
214 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530215 "starting Init ADC DC Calibration\n");
Sujithf1dc5602008-10-29 10:16:30 +0530216 break;
217 }
218
219 REG_SET_BIT(ah, AR_PHY_TIMING_CTRL4(0),
220 AR_PHY_TIMING_CTRL4_DO_CAL);
221}
222
223static void ath9k_hw_reset_calibration(struct ath_hal *ah,
224 struct hal_cal_list *currCal)
225{
226 struct ath_hal_5416 *ahp = AH5416(ah);
227 int i;
228
229 ath9k_hw_setup_calibration(ah, currCal);
230
231 currCal->calState = CAL_RUNNING;
232
233 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
234 ahp->ah_Meas0.sign[i] = 0;
235 ahp->ah_Meas1.sign[i] = 0;
236 ahp->ah_Meas2.sign[i] = 0;
237 ahp->ah_Meas3.sign[i] = 0;
238 }
239
240 ahp->ah_CalSamples = 0;
241}
242
243static void ath9k_hw_per_calibration(struct ath_hal *ah,
244 struct ath9k_channel *ichan,
245 u8 rxchainmask,
246 struct hal_cal_list *currCal,
247 bool *isCalDone)
248{
249 struct ath_hal_5416 *ahp = AH5416(ah);
250
251 *isCalDone = false;
252
253 if (currCal->calState == CAL_RUNNING) {
254 if (!(REG_READ(ah, AR_PHY_TIMING_CTRL4(0)) &
255 AR_PHY_TIMING_CTRL4_DO_CAL)) {
256
257 currCal->calData->calCollect(ah);
258 ahp->ah_CalSamples++;
259
260 if (ahp->ah_CalSamples >= currCal->calData->calNumSamples) {
261 int i, numChains = 0;
262 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
263 if (rxchainmask & (1 << i))
264 numChains++;
265 }
266
267 currCal->calData->calPostProc(ah, numChains);
268 ichan->CalValid |= currCal->calData->calType;
269 currCal->calState = CAL_DONE;
270 *isCalDone = true;
271 } else {
272 ath9k_hw_setup_calibration(ah, currCal);
273 }
274 }
275 } else if (!(ichan->CalValid & currCal->calData->calType)) {
276 ath9k_hw_reset_calibration(ah, currCal);
277 }
278}
279
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800280/* Assumes you are talking about the currently configured channel */
Sujithf1dc5602008-10-29 10:16:30 +0530281static bool ath9k_hw_iscal_supported(struct ath_hal *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530282 enum hal_cal_types calType)
283{
284 struct ath_hal_5416 *ahp = AH5416(ah);
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800285 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +0530286
287 switch (calType & ahp->ah_suppCals) {
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800288 case IQ_MISMATCH_CAL: /* Both 2 GHz and 5 GHz support OFDM */
289 return true;
Sujithf1dc5602008-10-29 10:16:30 +0530290 case ADC_GAIN_CAL:
291 case ADC_DC_CAL:
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800292 if (conf->channel->band == IEEE80211_BAND_5GHZ &&
293 conf_is_ht20(conf))
294 return true;
Sujithf1dc5602008-10-29 10:16:30 +0530295 break;
296 }
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800297 return false;
Sujithf1dc5602008-10-29 10:16:30 +0530298}
299
300static void ath9k_hw_iqcal_collect(struct ath_hal *ah)
301{
302 struct ath_hal_5416 *ahp = AH5416(ah);
303 int i;
304
305 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
306 ahp->ah_totalPowerMeasI[i] +=
307 REG_READ(ah, AR_PHY_CAL_MEAS_0(i));
308 ahp->ah_totalPowerMeasQ[i] +=
309 REG_READ(ah, AR_PHY_CAL_MEAS_1(i));
310 ahp->ah_totalIqCorrMeas[i] +=
311 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_2(i));
312 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
313 "%d: Chn %d pmi=0x%08x;pmq=0x%08x;iqcm=0x%08x;\n",
314 ahp->ah_CalSamples, i, ahp->ah_totalPowerMeasI[i],
315 ahp->ah_totalPowerMeasQ[i],
316 ahp->ah_totalIqCorrMeas[i]);
317 }
318}
319
320static void ath9k_hw_adc_gaincal_collect(struct ath_hal *ah)
321{
322 struct ath_hal_5416 *ahp = AH5416(ah);
323 int i;
324
325 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
326 ahp->ah_totalAdcIOddPhase[i] +=
327 REG_READ(ah, AR_PHY_CAL_MEAS_0(i));
328 ahp->ah_totalAdcIEvenPhase[i] +=
329 REG_READ(ah, AR_PHY_CAL_MEAS_1(i));
330 ahp->ah_totalAdcQOddPhase[i] +=
331 REG_READ(ah, AR_PHY_CAL_MEAS_2(i));
332 ahp->ah_totalAdcQEvenPhase[i] +=
333 REG_READ(ah, AR_PHY_CAL_MEAS_3(i));
334
335 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
336 "%d: Chn %d oddi=0x%08x; eveni=0x%08x; "
337 "oddq=0x%08x; evenq=0x%08x;\n",
338 ahp->ah_CalSamples, i,
339 ahp->ah_totalAdcIOddPhase[i],
340 ahp->ah_totalAdcIEvenPhase[i],
341 ahp->ah_totalAdcQOddPhase[i],
342 ahp->ah_totalAdcQEvenPhase[i]);
343 }
344}
345
346static void ath9k_hw_adc_dccal_collect(struct ath_hal *ah)
347{
348 struct ath_hal_5416 *ahp = AH5416(ah);
349 int i;
350
351 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
352 ahp->ah_totalAdcDcOffsetIOddPhase[i] +=
353 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_0(i));
354 ahp->ah_totalAdcDcOffsetIEvenPhase[i] +=
355 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_1(i));
356 ahp->ah_totalAdcDcOffsetQOddPhase[i] +=
357 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_2(i));
358 ahp->ah_totalAdcDcOffsetQEvenPhase[i] +=
359 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_3(i));
360
361 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
362 "%d: Chn %d oddi=0x%08x; eveni=0x%08x; "
363 "oddq=0x%08x; evenq=0x%08x;\n",
364 ahp->ah_CalSamples, i,
365 ahp->ah_totalAdcDcOffsetIOddPhase[i],
366 ahp->ah_totalAdcDcOffsetIEvenPhase[i],
367 ahp->ah_totalAdcDcOffsetQOddPhase[i],
368 ahp->ah_totalAdcDcOffsetQEvenPhase[i]);
369 }
370}
371
372static void ath9k_hw_iqcalibrate(struct ath_hal *ah, u8 numChains)
373{
374 struct ath_hal_5416 *ahp = AH5416(ah);
375 u32 powerMeasQ, powerMeasI, iqCorrMeas;
376 u32 qCoffDenom, iCoffDenom;
377 int32_t qCoff, iCoff;
378 int iqCorrNeg, i;
379
380 for (i = 0; i < numChains; i++) {
381 powerMeasI = ahp->ah_totalPowerMeasI[i];
382 powerMeasQ = ahp->ah_totalPowerMeasQ[i];
383 iqCorrMeas = ahp->ah_totalIqCorrMeas[i];
384
385 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
386 "Starting IQ Cal and Correction for Chain %d\n",
387 i);
388
389 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
390 "Orignal: Chn %diq_corr_meas = 0x%08x\n",
391 i, ahp->ah_totalIqCorrMeas[i]);
392
393 iqCorrNeg = 0;
394
395 if (iqCorrMeas > 0x80000000) {
396 iqCorrMeas = (0xffffffff - iqCorrMeas) + 1;
397 iqCorrNeg = 1;
398 }
399
400 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
401 "Chn %d pwr_meas_i = 0x%08x\n", i, powerMeasI);
402 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
403 "Chn %d pwr_meas_q = 0x%08x\n", i, powerMeasQ);
404 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE, "iqCorrNeg is 0x%08x\n",
405 iqCorrNeg);
406
407 iCoffDenom = (powerMeasI / 2 + powerMeasQ / 2) / 128;
408 qCoffDenom = powerMeasQ / 64;
409
410 if (powerMeasQ != 0) {
411 iCoff = iqCorrMeas / iCoffDenom;
412 qCoff = powerMeasI / qCoffDenom - 64;
413 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
414 "Chn %d iCoff = 0x%08x\n", i, iCoff);
415 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
416 "Chn %d qCoff = 0x%08x\n", i, qCoff);
417
418 iCoff = iCoff & 0x3f;
419 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
420 "New: Chn %d iCoff = 0x%08x\n", i, iCoff);
421 if (iqCorrNeg == 0x0)
422 iCoff = 0x40 - iCoff;
423
424 if (qCoff > 15)
425 qCoff = 15;
426 else if (qCoff <= -16)
427 qCoff = 16;
428
429 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
430 "Chn %d : iCoff = 0x%x qCoff = 0x%x\n",
431 i, iCoff, qCoff);
432
433 REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(i),
434 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF,
435 iCoff);
436 REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(i),
437 AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF,
438 qCoff);
439 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
440 "IQ Cal and Correction done for Chain %d\n",
441 i);
442 }
443 }
444
445 REG_SET_BIT(ah, AR_PHY_TIMING_CTRL4(0),
446 AR_PHY_TIMING_CTRL4_IQCORR_ENABLE);
447}
448
449static void ath9k_hw_adc_gaincal_calibrate(struct ath_hal *ah, u8 numChains)
450{
451 struct ath_hal_5416 *ahp = AH5416(ah);
452 u32 iOddMeasOffset, iEvenMeasOffset, qOddMeasOffset, qEvenMeasOffset;
453 u32 qGainMismatch, iGainMismatch, val, i;
454
455 for (i = 0; i < numChains; i++) {
456 iOddMeasOffset = ahp->ah_totalAdcIOddPhase[i];
457 iEvenMeasOffset = ahp->ah_totalAdcIEvenPhase[i];
458 qOddMeasOffset = ahp->ah_totalAdcQOddPhase[i];
459 qEvenMeasOffset = ahp->ah_totalAdcQEvenPhase[i];
460
461 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
462 "Starting ADC Gain Cal for Chain %d\n", i);
463
464 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
465 "Chn %d pwr_meas_odd_i = 0x%08x\n", i,
466 iOddMeasOffset);
467 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
468 "Chn %d pwr_meas_even_i = 0x%08x\n", i,
469 iEvenMeasOffset);
470 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
471 "Chn %d pwr_meas_odd_q = 0x%08x\n", i,
472 qOddMeasOffset);
473 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
474 "Chn %d pwr_meas_even_q = 0x%08x\n", i,
475 qEvenMeasOffset);
476
477 if (iOddMeasOffset != 0 && qEvenMeasOffset != 0) {
478 iGainMismatch =
479 ((iEvenMeasOffset * 32) /
480 iOddMeasOffset) & 0x3f;
481 qGainMismatch =
482 ((qOddMeasOffset * 32) /
483 qEvenMeasOffset) & 0x3f;
484
485 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
486 "Chn %d gain_mismatch_i = 0x%08x\n", i,
487 iGainMismatch);
488 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
489 "Chn %d gain_mismatch_q = 0x%08x\n", i,
490 qGainMismatch);
491
492 val = REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i));
493 val &= 0xfffff000;
494 val |= (qGainMismatch) | (iGainMismatch << 6);
495 REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i), val);
496
497 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
498 "ADC Gain Cal done for Chain %d\n", i);
499 }
500 }
501
502 REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0),
503 REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0)) |
504 AR_PHY_NEW_ADC_GAIN_CORR_ENABLE);
505}
506
507static void ath9k_hw_adc_dccal_calibrate(struct ath_hal *ah, u8 numChains)
508{
509 struct ath_hal_5416 *ahp = AH5416(ah);
510 u32 iOddMeasOffset, iEvenMeasOffset, val, i;
511 int32_t qOddMeasOffset, qEvenMeasOffset, qDcMismatch, iDcMismatch;
512 const struct hal_percal_data *calData =
513 ahp->ah_cal_list_curr->calData;
514 u32 numSamples =
515 (1 << (calData->calCountMax + 5)) * calData->calNumSamples;
516
517 for (i = 0; i < numChains; i++) {
518 iOddMeasOffset = ahp->ah_totalAdcDcOffsetIOddPhase[i];
519 iEvenMeasOffset = ahp->ah_totalAdcDcOffsetIEvenPhase[i];
520 qOddMeasOffset = ahp->ah_totalAdcDcOffsetQOddPhase[i];
521 qEvenMeasOffset = ahp->ah_totalAdcDcOffsetQEvenPhase[i];
522
523 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
524 "Starting ADC DC Offset Cal for Chain %d\n", i);
525
526 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
527 "Chn %d pwr_meas_odd_i = %d\n", i,
528 iOddMeasOffset);
529 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
530 "Chn %d pwr_meas_even_i = %d\n", i,
531 iEvenMeasOffset);
532 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
533 "Chn %d pwr_meas_odd_q = %d\n", i,
534 qOddMeasOffset);
535 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
536 "Chn %d pwr_meas_even_q = %d\n", i,
537 qEvenMeasOffset);
538
539 iDcMismatch = (((iEvenMeasOffset - iOddMeasOffset) * 2) /
540 numSamples) & 0x1ff;
541 qDcMismatch = (((qOddMeasOffset - qEvenMeasOffset) * 2) /
542 numSamples) & 0x1ff;
543
544 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
545 "Chn %d dc_offset_mismatch_i = 0x%08x\n", i,
546 iDcMismatch);
547 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
548 "Chn %d dc_offset_mismatch_q = 0x%08x\n", i,
549 qDcMismatch);
550
551 val = REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i));
552 val &= 0xc0000fff;
553 val |= (qDcMismatch << 12) | (iDcMismatch << 21);
554 REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i), val);
555
556 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
557 "ADC DC Offset Cal done for Chain %d\n", i);
558 }
559
560 REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0),
561 REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0)) |
562 AR_PHY_NEW_ADC_DC_OFFSET_CORR_ENABLE);
563}
564
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800565/* This is done for the currently configured channel */
566bool ath9k_hw_reset_calvalid(struct ath_hal *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530567{
568 struct ath_hal_5416 *ahp = AH5416(ah);
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800569 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +0530570 struct hal_cal_list *currCal = ahp->ah_cal_list_curr;
571
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800572 if (!ah->ah_curchan)
573 return true;
Sujithf1dc5602008-10-29 10:16:30 +0530574
575 if (!AR_SREV_9100(ah) && !AR_SREV_9160_10_OR_LATER(ah))
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800576 return true;
Sujithf1dc5602008-10-29 10:16:30 +0530577
578 if (currCal == NULL)
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800579 return true;
Sujithf1dc5602008-10-29 10:16:30 +0530580
581 if (currCal->calState != CAL_DONE) {
582 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530583 "Calibration state incorrect, %d\n",
584 currCal->calState);
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800585 return true;
Sujithf1dc5602008-10-29 10:16:30 +0530586 }
587
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800588 if (!ath9k_hw_iscal_supported(ah, currCal->calData->calType))
589 return true;
Sujithf1dc5602008-10-29 10:16:30 +0530590
591 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800592 "Resetting Cal %d state for channel %u\n",
593 currCal->calData->calType, conf->channel->center_freq);
Sujithf1dc5602008-10-29 10:16:30 +0530594
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800595 ah->ah_curchan->CalValid &= ~currCal->calData->calType;
Sujithf1dc5602008-10-29 10:16:30 +0530596 currCal->calState = CAL_WAITING;
597
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800598 return false;
Sujithf1dc5602008-10-29 10:16:30 +0530599}
600
601void ath9k_hw_start_nfcal(struct ath_hal *ah)
602{
603 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL,
604 AR_PHY_AGC_CONTROL_ENABLE_NF);
605 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL,
606 AR_PHY_AGC_CONTROL_NO_UPDATE_NF);
607 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF);
608}
609
610void ath9k_hw_loadnf(struct ath_hal *ah, struct ath9k_channel *chan)
611{
612 struct ath9k_nfcal_hist *h;
613 int i, j;
614 int32_t val;
615 const u32 ar5416_cca_regs[6] = {
616 AR_PHY_CCA,
617 AR_PHY_CH1_CCA,
618 AR_PHY_CH2_CCA,
619 AR_PHY_EXT_CCA,
620 AR_PHY_CH1_EXT_CCA,
621 AR_PHY_CH2_EXT_CCA
622 };
623 u8 chainmask;
624
625 if (AR_SREV_9280(ah))
626 chainmask = 0x1B;
627 else
628 chainmask = 0x3F;
629
630#ifdef ATH_NF_PER_CHAN
631 h = chan->nfCalHist;
632#else
633 h = ah->nfCalHist;
634#endif
635
636 for (i = 0; i < NUM_NF_READINGS; i++) {
637 if (chainmask & (1 << i)) {
638 val = REG_READ(ah, ar5416_cca_regs[i]);
639 val &= 0xFFFFFE00;
640 val |= (((u32) (h[i].privNF) << 1) & 0x1ff);
641 REG_WRITE(ah, ar5416_cca_regs[i], val);
642 }
643 }
644
645 REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
646 AR_PHY_AGC_CONTROL_ENABLE_NF);
647 REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
648 AR_PHY_AGC_CONTROL_NO_UPDATE_NF);
649 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF);
650
651 for (j = 0; j < 1000; j++) {
652 if ((REG_READ(ah, AR_PHY_AGC_CONTROL) &
653 AR_PHY_AGC_CONTROL_NF) == 0)
654 break;
655 udelay(10);
656 }
657
658 for (i = 0; i < NUM_NF_READINGS; i++) {
659 if (chainmask & (1 << i)) {
660 val = REG_READ(ah, ar5416_cca_regs[i]);
661 val &= 0xFFFFFE00;
662 val |= (((u32) (-50) << 1) & 0x1ff);
663 REG_WRITE(ah, ar5416_cca_regs[i], val);
664 }
665 }
666}
667
668int16_t ath9k_hw_getnf(struct ath_hal *ah,
669 struct ath9k_channel *chan)
670{
671 int16_t nf, nfThresh;
672 int16_t nfarray[NUM_NF_READINGS] = { 0 };
673 struct ath9k_nfcal_hist *h;
Luis R. Rodriguez76061ab2008-12-23 15:58:41 -0800674 struct ieee80211_channel *c = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +0530675 u8 chainmask;
676
677 if (AR_SREV_9280(ah))
678 chainmask = 0x1B;
679 else
680 chainmask = 0x3F;
681
682 chan->channelFlags &= (~CHANNEL_CW_INT);
683 if (REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF) {
684 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530685 "NF did not complete in calibration window\n");
Sujithf1dc5602008-10-29 10:16:30 +0530686 nf = 0;
687 chan->rawNoiseFloor = nf;
688 return chan->rawNoiseFloor;
689 } else {
690 ath9k_hw_do_getnf(ah, nfarray);
691 nf = nfarray[0];
Luis R. Rodriguez76061ab2008-12-23 15:58:41 -0800692 if (getNoiseFloorThresh(ah, c->band, &nfThresh)
Sujithf1dc5602008-10-29 10:16:30 +0530693 && nf > nfThresh) {
694 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530695 "noise floor failed detected; "
696 "detected %d, threshold %d\n",
Sujithf1dc5602008-10-29 10:16:30 +0530697 nf, nfThresh);
698 chan->channelFlags |= CHANNEL_CW_INT;
699 }
700 }
701
702#ifdef ATH_NF_PER_CHAN
703 h = chan->nfCalHist;
704#else
705 h = ah->nfCalHist;
706#endif
707
708 ath9k_hw_update_nfcal_hist_buffer(h, nfarray);
709 chan->rawNoiseFloor = h[0].privNF;
710
711 return chan->rawNoiseFloor;
712}
713
714void ath9k_init_nfcal_hist_buffer(struct ath_hal *ah)
715{
716 int i, j;
717
718 for (i = 0; i < NUM_NF_READINGS; i++) {
719 ah->nfCalHist[i].currIndex = 0;
720 ah->nfCalHist[i].privNF = AR_PHY_CCA_MAX_GOOD_VALUE;
721 ah->nfCalHist[i].invalidNFcount =
722 AR_PHY_CCA_FILTERWINDOW_LENGTH;
723 for (j = 0; j < ATH9K_NF_CAL_HIST_MAX; j++) {
724 ah->nfCalHist[i].nfCalBuffer[j] =
725 AR_PHY_CCA_MAX_GOOD_VALUE;
726 }
727 }
728 return;
729}
730
731s16 ath9k_hw_getchan_noise(struct ath_hal *ah, struct ath9k_channel *chan)
732{
733 struct ath9k_channel *ichan;
734 s16 nf;
735
736 ichan = ath9k_regd_check_channel(ah, chan);
737 if (ichan == NULL) {
Sujith04bd4632008-11-28 22:18:05 +0530738 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
739 "invalid channel %u/0x%x; no mapping\n",
740 chan->channel, chan->channelFlags);
Sujithf1dc5602008-10-29 10:16:30 +0530741 return ATH_DEFAULT_NOISE_FLOOR;
742 }
743 if (ichan->rawNoiseFloor == 0) {
744 enum wireless_mode mode = ath9k_hw_chan2wmode(ah, chan);
745 nf = NOISE_FLOOR[mode];
746 } else
747 nf = ichan->rawNoiseFloor;
748
749 if (!ath9k_hw_nf_in_range(ah, nf))
750 nf = ATH_DEFAULT_NOISE_FLOOR;
751
752 return nf;
753}
754
755bool ath9k_hw_calibrate(struct ath_hal *ah, struct ath9k_channel *chan,
756 u8 rxchainmask, bool longcal,
757 bool *isCalDone)
758{
759 struct ath_hal_5416 *ahp = AH5416(ah);
760 struct hal_cal_list *currCal = ahp->ah_cal_list_curr;
761 struct ath9k_channel *ichan = ath9k_regd_check_channel(ah, chan);
762
763 *isCalDone = true;
764
765 if (ichan == NULL) {
766 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
Sujith04bd4632008-11-28 22:18:05 +0530767 "invalid channel %u/0x%x; no mapping\n",
768 chan->channel, chan->channelFlags);
Sujithf1dc5602008-10-29 10:16:30 +0530769 return false;
770 }
771
772 if (currCal &&
773 (currCal->calState == CAL_RUNNING ||
774 currCal->calState == CAL_WAITING)) {
775 ath9k_hw_per_calibration(ah, ichan, rxchainmask, currCal,
776 isCalDone);
777 if (*isCalDone) {
778 ahp->ah_cal_list_curr = currCal = currCal->calNext;
779
780 if (currCal->calState == CAL_WAITING) {
781 *isCalDone = false;
782 ath9k_hw_reset_calibration(ah, currCal);
783 }
784 }
785 }
786
787 if (longcal) {
788 ath9k_hw_getnf(ah, ichan);
789 ath9k_hw_loadnf(ah, ah->ah_curchan);
790 ath9k_hw_start_nfcal(ah);
791
792 if ((ichan->channelFlags & CHANNEL_CW_INT) != 0) {
793 chan->channelFlags |= CHANNEL_CW_INT;
794 ichan->channelFlags &= ~CHANNEL_CW_INT;
795 }
796 }
797
798 return true;
799}
800
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530801static inline void ath9k_hw_9285_pa_cal(struct ath_hal *ah)
802{
803
804 u32 regVal;
805 int i, offset, offs_6_1, offs_0;
806 u32 ccomp_org, reg_field;
807 u32 regList[][2] = {
808 { 0x786c, 0 },
809 { 0x7854, 0 },
810 { 0x7820, 0 },
811 { 0x7824, 0 },
812 { 0x7868, 0 },
813 { 0x783c, 0 },
814 { 0x7838, 0 },
815 };
816
817 if (AR_SREV_9285_11(ah)) {
818 REG_WRITE(ah, AR9285_AN_TOP4, (AR9285_AN_TOP4_DEFAULT | 0x14));
819 udelay(10);
820 }
821
822 for (i = 0; i < ARRAY_SIZE(regList); i++)
823 regList[i][1] = REG_READ(ah, regList[i][0]);
824
825 regVal = REG_READ(ah, 0x7834);
826 regVal &= (~(0x1));
827 REG_WRITE(ah, 0x7834, regVal);
828 regVal = REG_READ(ah, 0x9808);
829 regVal |= (0x1 << 27);
830 REG_WRITE(ah, 0x9808, regVal);
831
832 REG_RMW_FIELD(ah, AR9285_AN_TOP3, AR9285_AN_TOP3_PWDDAC, 1);
833 REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDRXTXBB1, 1);
834 REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDV2I, 1);
835 REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDDACIF, 1);
836 REG_RMW_FIELD(ah, AR9285_AN_RF2G2, AR9285_AN_RF2G2_OFFCAL, 0);
837 REG_RMW_FIELD(ah, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PWDDB, 0);
838 REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_ENPACAL, 0);
839 REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV1, 1);
840 REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV2, 0);
841 REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPAOUT, 0);
842 REG_RMW_FIELD(ah, AR9285_AN_RF2G8, AR9285_AN_RF2G8_PADRVGN2TAB0, 7);
843 REG_RMW_FIELD(ah, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PADRVGN2TAB0, 0);
844 ccomp_org = MS(REG_READ(ah, AR9285_AN_RF2G6), AR9285_AN_RF2G6_CCOMP);
845 REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_CCOMP, 7);
846
847 REG_WRITE(ah, AR9285_AN_TOP2, 0xca0358a0);
848 udelay(30);
849 REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_OFFS, 0);
850 REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, 0);
851
852 for (i = 6; i > 0; i--) {
853 regVal = REG_READ(ah, 0x7834);
854 regVal |= (1 << (19 + i));
855 REG_WRITE(ah, 0x7834, regVal);
856 udelay(1);
857 regVal = REG_READ(ah, 0x7834);
858 regVal &= (~(0x1 << (19 + i)));
859 reg_field = MS(REG_READ(ah, 0x7840), AR9285_AN_RXTXBB1_SPARE9);
860 regVal |= (reg_field << (19 + i));
861 REG_WRITE(ah, 0x7834, regVal);
862 }
863
864 REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, 1);
865 udelay(1);
866 reg_field = MS(REG_READ(ah, AR9285_AN_RF2G9), AR9285_AN_RXTXBB1_SPARE9);
867 REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, reg_field);
868 offs_6_1 = MS(REG_READ(ah, AR9285_AN_RF2G6), AR9285_AN_RF2G6_OFFS);
869 offs_0 = MS(REG_READ(ah, AR9285_AN_RF2G3), AR9285_AN_RF2G3_PDVCCOMP);
870
871 offset = (offs_6_1<<1) | offs_0;
872 offset = offset - 0;
873 offs_6_1 = offset>>1;
874 offs_0 = offset & 1;
875
876 REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_OFFS, offs_6_1);
877 REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, offs_0);
878
879 regVal = REG_READ(ah, 0x7834);
880 regVal |= 0x1;
881 REG_WRITE(ah, 0x7834, regVal);
882 regVal = REG_READ(ah, 0x9808);
883 regVal &= (~(0x1 << 27));
884 REG_WRITE(ah, 0x9808, regVal);
885
886 for (i = 0; i < ARRAY_SIZE(regList); i++)
887 REG_WRITE(ah, regList[i][0], regList[i][1]);
888
889 REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_CCOMP, ccomp_org);
890
891 if (AR_SREV_9285_11(ah))
892 REG_WRITE(ah, AR9285_AN_TOP4, AR9285_AN_TOP4_DEFAULT);
893
894}
895
Sujithf1dc5602008-10-29 10:16:30 +0530896bool ath9k_hw_init_cal(struct ath_hal *ah,
897 struct ath9k_channel *chan)
898{
899 struct ath_hal_5416 *ahp = AH5416(ah);
900 struct ath9k_channel *ichan = ath9k_regd_check_channel(ah, chan);
901
902 REG_WRITE(ah, AR_PHY_AGC_CONTROL,
903 REG_READ(ah, AR_PHY_AGC_CONTROL) |
904 AR_PHY_AGC_CONTROL_CAL);
905
906 if (!ath9k_hw_wait(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL, 0)) {
907 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530908 "offset calibration failed to complete in 1ms; "
909 "noisy environment?\n");
Sujithf1dc5602008-10-29 10:16:30 +0530910 return false;
911 }
912
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530913 if (AR_SREV_9285(ah) && AR_SREV_9285_11_OR_LATER(ah))
914 ath9k_hw_9285_pa_cal(ah);
915
Sujithf1dc5602008-10-29 10:16:30 +0530916 REG_WRITE(ah, AR_PHY_AGC_CONTROL,
917 REG_READ(ah, AR_PHY_AGC_CONTROL) |
918 AR_PHY_AGC_CONTROL_NF);
919
920 ahp->ah_cal_list = ahp->ah_cal_list_last = ahp->ah_cal_list_curr = NULL;
921
922 if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah)) {
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800923 if (ath9k_hw_iscal_supported(ah, ADC_GAIN_CAL)) {
Sujithf1dc5602008-10-29 10:16:30 +0530924 INIT_CAL(&ahp->ah_adcGainCalData);
925 INSERT_CAL(ahp, &ahp->ah_adcGainCalData);
926 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530927 "enabling ADC Gain Calibration.\n");
Sujithf1dc5602008-10-29 10:16:30 +0530928 }
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800929 if (ath9k_hw_iscal_supported(ah, ADC_DC_CAL)) {
Sujithf1dc5602008-10-29 10:16:30 +0530930 INIT_CAL(&ahp->ah_adcDcCalData);
931 INSERT_CAL(ahp, &ahp->ah_adcDcCalData);
932 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530933 "enabling ADC DC Calibration.\n");
Sujithf1dc5602008-10-29 10:16:30 +0530934 }
Luis R. Rodriguezc9e27d92008-12-23 15:58:42 -0800935 if (ath9k_hw_iscal_supported(ah, IQ_MISMATCH_CAL)) {
Sujithf1dc5602008-10-29 10:16:30 +0530936 INIT_CAL(&ahp->ah_iqCalData);
937 INSERT_CAL(ahp, &ahp->ah_iqCalData);
938 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
Sujith04bd4632008-11-28 22:18:05 +0530939 "enabling IQ Calibration.\n");
Sujithf1dc5602008-10-29 10:16:30 +0530940 }
941
942 ahp->ah_cal_list_curr = ahp->ah_cal_list;
943
944 if (ahp->ah_cal_list_curr)
945 ath9k_hw_reset_calibration(ah, ahp->ah_cal_list_curr);
946 }
947
948 ichan->CalValid = 0;
949
950 return true;
951}
952
953const struct hal_percal_data iq_cal_multi_sample = {
954 IQ_MISMATCH_CAL,
955 MAX_CAL_SAMPLES,
956 PER_MIN_LOG_COUNT,
957 ath9k_hw_iqcal_collect,
958 ath9k_hw_iqcalibrate
959};
960const struct hal_percal_data iq_cal_single_sample = {
961 IQ_MISMATCH_CAL,
962 MIN_CAL_SAMPLES,
963 PER_MAX_LOG_COUNT,
964 ath9k_hw_iqcal_collect,
965 ath9k_hw_iqcalibrate
966};
967const struct hal_percal_data adc_gain_cal_multi_sample = {
968 ADC_GAIN_CAL,
969 MAX_CAL_SAMPLES,
970 PER_MIN_LOG_COUNT,
971 ath9k_hw_adc_gaincal_collect,
972 ath9k_hw_adc_gaincal_calibrate
973};
974const struct hal_percal_data adc_gain_cal_single_sample = {
975 ADC_GAIN_CAL,
976 MIN_CAL_SAMPLES,
977 PER_MAX_LOG_COUNT,
978 ath9k_hw_adc_gaincal_collect,
979 ath9k_hw_adc_gaincal_calibrate
980};
981const struct hal_percal_data adc_dc_cal_multi_sample = {
982 ADC_DC_CAL,
983 MAX_CAL_SAMPLES,
984 PER_MIN_LOG_COUNT,
985 ath9k_hw_adc_dccal_collect,
986 ath9k_hw_adc_dccal_calibrate
987};
988const struct hal_percal_data adc_dc_cal_single_sample = {
989 ADC_DC_CAL,
990 MIN_CAL_SAMPLES,
991 PER_MAX_LOG_COUNT,
992 ath9k_hw_adc_dccal_collect,
993 ath9k_hw_adc_dccal_calibrate
994};
995const struct hal_percal_data adc_init_dc_cal = {
996 ADC_DC_INIT_CAL,
997 MIN_CAL_SAMPLES,
998 INIT_LOG_COUNT,
999 ath9k_hw_adc_dccal_collect,
1000 ath9k_hw_adc_dccal_calibrate
1001};