calib.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021
  1. /*
  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. #include "core.h"
  17. #include "hw.h"
  18. #include "reg.h"
  19. #include "phy.h"
  20. static const int16_t NOISE_FLOOR[] = { -96, -93, -98, -96, -93, -96 };
  21. /* We can tune this as we go by monitoring really low values */
  22. #define ATH9K_NF_TOO_LOW -60
  23. /* AR5416 may return very high value (like -31 dBm), in those cases the nf
  24. * is incorrect and we should use the static NF value. Later we can try to
  25. * find out why they are reporting these values */
  26. static bool ath9k_hw_nf_in_range(struct ath_hal *ah, s16 nf)
  27. {
  28. if (nf > ATH9K_NF_TOO_LOW) {
  29. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  30. "noise floor value detected (%d) is "
  31. "lower than what we think is a "
  32. "reasonable value (%d)\n",
  33. nf, ATH9K_NF_TOO_LOW);
  34. return false;
  35. }
  36. return true;
  37. }
  38. static int16_t ath9k_hw_get_nf_hist_mid(int16_t *nfCalBuffer)
  39. {
  40. int16_t nfval;
  41. int16_t sort[ATH9K_NF_CAL_HIST_MAX];
  42. int i, j;
  43. for (i = 0; i < ATH9K_NF_CAL_HIST_MAX; i++)
  44. sort[i] = nfCalBuffer[i];
  45. for (i = 0; i < ATH9K_NF_CAL_HIST_MAX - 1; i++) {
  46. for (j = 1; j < ATH9K_NF_CAL_HIST_MAX - i; j++) {
  47. if (sort[j] > sort[j - 1]) {
  48. nfval = sort[j];
  49. sort[j] = sort[j - 1];
  50. sort[j - 1] = nfval;
  51. }
  52. }
  53. }
  54. nfval = sort[(ATH9K_NF_CAL_HIST_MAX - 1) >> 1];
  55. return nfval;
  56. }
  57. static void ath9k_hw_update_nfcal_hist_buffer(struct ath9k_nfcal_hist *h,
  58. int16_t *nfarray)
  59. {
  60. int i;
  61. for (i = 0; i < NUM_NF_READINGS; i++) {
  62. h[i].nfCalBuffer[h[i].currIndex] = nfarray[i];
  63. if (++h[i].currIndex >= ATH9K_NF_CAL_HIST_MAX)
  64. h[i].currIndex = 0;
  65. if (h[i].invalidNFcount > 0) {
  66. if (nfarray[i] < AR_PHY_CCA_MIN_BAD_VALUE ||
  67. nfarray[i] > AR_PHY_CCA_MAX_HIGH_VALUE) {
  68. h[i].invalidNFcount = ATH9K_NF_CAL_HIST_MAX;
  69. } else {
  70. h[i].invalidNFcount--;
  71. h[i].privNF = nfarray[i];
  72. }
  73. } else {
  74. h[i].privNF =
  75. ath9k_hw_get_nf_hist_mid(h[i].nfCalBuffer);
  76. }
  77. }
  78. return;
  79. }
  80. static void ath9k_hw_do_getnf(struct ath_hal *ah,
  81. int16_t nfarray[NUM_NF_READINGS])
  82. {
  83. int16_t nf;
  84. if (AR_SREV_9280_10_OR_LATER(ah))
  85. nf = MS(REG_READ(ah, AR_PHY_CCA), AR9280_PHY_MINCCA_PWR);
  86. else
  87. nf = MS(REG_READ(ah, AR_PHY_CCA), AR_PHY_MINCCA_PWR);
  88. if (nf & 0x100)
  89. nf = 0 - ((nf ^ 0x1ff) + 1);
  90. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  91. "NF calibrated [ctl] [chain 0] is %d\n", nf);
  92. nfarray[0] = nf;
  93. if (AR_SREV_9280_10_OR_LATER(ah))
  94. nf = MS(REG_READ(ah, AR_PHY_CH1_CCA),
  95. AR9280_PHY_CH1_MINCCA_PWR);
  96. else
  97. nf = MS(REG_READ(ah, AR_PHY_CH1_CCA),
  98. AR_PHY_CH1_MINCCA_PWR);
  99. if (nf & 0x100)
  100. nf = 0 - ((nf ^ 0x1ff) + 1);
  101. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  102. "NF calibrated [ctl] [chain 1] is %d\n", nf);
  103. nfarray[1] = nf;
  104. if (!AR_SREV_9280(ah)) {
  105. nf = MS(REG_READ(ah, AR_PHY_CH2_CCA),
  106. AR_PHY_CH2_MINCCA_PWR);
  107. if (nf & 0x100)
  108. nf = 0 - ((nf ^ 0x1ff) + 1);
  109. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  110. "NF calibrated [ctl] [chain 2] is %d\n", nf);
  111. nfarray[2] = nf;
  112. }
  113. if (AR_SREV_9280_10_OR_LATER(ah))
  114. nf = MS(REG_READ(ah, AR_PHY_EXT_CCA),
  115. AR9280_PHY_EXT_MINCCA_PWR);
  116. else
  117. nf = MS(REG_READ(ah, AR_PHY_EXT_CCA),
  118. AR_PHY_EXT_MINCCA_PWR);
  119. if (nf & 0x100)
  120. nf = 0 - ((nf ^ 0x1ff) + 1);
  121. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  122. "NF calibrated [ext] [chain 0] is %d\n", nf);
  123. nfarray[3] = nf;
  124. if (AR_SREV_9280_10_OR_LATER(ah))
  125. nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA),
  126. AR9280_PHY_CH1_EXT_MINCCA_PWR);
  127. else
  128. nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA),
  129. AR_PHY_CH1_EXT_MINCCA_PWR);
  130. if (nf & 0x100)
  131. nf = 0 - ((nf ^ 0x1ff) + 1);
  132. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  133. "NF calibrated [ext] [chain 1] is %d\n", nf);
  134. nfarray[4] = nf;
  135. if (!AR_SREV_9280(ah)) {
  136. nf = MS(REG_READ(ah, AR_PHY_CH2_EXT_CCA),
  137. AR_PHY_CH2_EXT_MINCCA_PWR);
  138. if (nf & 0x100)
  139. nf = 0 - ((nf ^ 0x1ff) + 1);
  140. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  141. "NF calibrated [ext] [chain 2] is %d\n", nf);
  142. nfarray[5] = nf;
  143. }
  144. }
  145. static bool getNoiseFloorThresh(struct ath_hal *ah,
  146. const struct ath9k_channel *chan,
  147. int16_t *nft)
  148. {
  149. switch (chan->chanmode) {
  150. case CHANNEL_A:
  151. case CHANNEL_A_HT20:
  152. case CHANNEL_A_HT40PLUS:
  153. case CHANNEL_A_HT40MINUS:
  154. *nft = (int8_t)ath9k_hw_get_eeprom(ah, EEP_NFTHRESH_5);
  155. break;
  156. case CHANNEL_B:
  157. case CHANNEL_G:
  158. case CHANNEL_G_HT20:
  159. case CHANNEL_G_HT40PLUS:
  160. case CHANNEL_G_HT40MINUS:
  161. *nft = (int8_t)ath9k_hw_get_eeprom(ah, EEP_NFTHRESH_2);
  162. break;
  163. default:
  164. DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
  165. "invalid channel flags 0x%x\n", chan->channelFlags);
  166. return false;
  167. }
  168. return true;
  169. }
  170. static void ath9k_hw_setup_calibration(struct ath_hal *ah,
  171. struct hal_cal_list *currCal)
  172. {
  173. REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(0),
  174. AR_PHY_TIMING_CTRL4_IQCAL_LOG_COUNT_MAX,
  175. currCal->calData->calCountMax);
  176. switch (currCal->calData->calType) {
  177. case IQ_MISMATCH_CAL:
  178. REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_IQ);
  179. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  180. "starting IQ Mismatch Calibration\n");
  181. break;
  182. case ADC_GAIN_CAL:
  183. REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_ADC_GAIN);
  184. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  185. "starting ADC Gain Calibration\n");
  186. break;
  187. case ADC_DC_CAL:
  188. REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_ADC_DC_PER);
  189. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  190. "starting ADC DC Calibration\n");
  191. break;
  192. case ADC_DC_INIT_CAL:
  193. REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_ADC_DC_INIT);
  194. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  195. "starting Init ADC DC Calibration\n");
  196. break;
  197. }
  198. REG_SET_BIT(ah, AR_PHY_TIMING_CTRL4(0),
  199. AR_PHY_TIMING_CTRL4_DO_CAL);
  200. }
  201. static void ath9k_hw_reset_calibration(struct ath_hal *ah,
  202. struct hal_cal_list *currCal)
  203. {
  204. struct ath_hal_5416 *ahp = AH5416(ah);
  205. int i;
  206. ath9k_hw_setup_calibration(ah, currCal);
  207. currCal->calState = CAL_RUNNING;
  208. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  209. ahp->ah_Meas0.sign[i] = 0;
  210. ahp->ah_Meas1.sign[i] = 0;
  211. ahp->ah_Meas2.sign[i] = 0;
  212. ahp->ah_Meas3.sign[i] = 0;
  213. }
  214. ahp->ah_CalSamples = 0;
  215. }
  216. static void ath9k_hw_per_calibration(struct ath_hal *ah,
  217. struct ath9k_channel *ichan,
  218. u8 rxchainmask,
  219. struct hal_cal_list *currCal,
  220. bool *isCalDone)
  221. {
  222. struct ath_hal_5416 *ahp = AH5416(ah);
  223. *isCalDone = false;
  224. if (currCal->calState == CAL_RUNNING) {
  225. if (!(REG_READ(ah, AR_PHY_TIMING_CTRL4(0)) &
  226. AR_PHY_TIMING_CTRL4_DO_CAL)) {
  227. currCal->calData->calCollect(ah);
  228. ahp->ah_CalSamples++;
  229. if (ahp->ah_CalSamples >= currCal->calData->calNumSamples) {
  230. int i, numChains = 0;
  231. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  232. if (rxchainmask & (1 << i))
  233. numChains++;
  234. }
  235. currCal->calData->calPostProc(ah, numChains);
  236. ichan->CalValid |= currCal->calData->calType;
  237. currCal->calState = CAL_DONE;
  238. *isCalDone = true;
  239. } else {
  240. ath9k_hw_setup_calibration(ah, currCal);
  241. }
  242. }
  243. } else if (!(ichan->CalValid & currCal->calData->calType)) {
  244. ath9k_hw_reset_calibration(ah, currCal);
  245. }
  246. }
  247. static bool ath9k_hw_iscal_supported(struct ath_hal *ah,
  248. struct ath9k_channel *chan,
  249. enum hal_cal_types calType)
  250. {
  251. struct ath_hal_5416 *ahp = AH5416(ah);
  252. bool retval = false;
  253. switch (calType & ahp->ah_suppCals) {
  254. case IQ_MISMATCH_CAL:
  255. if (!IS_CHAN_B(chan))
  256. retval = true;
  257. break;
  258. case ADC_GAIN_CAL:
  259. case ADC_DC_CAL:
  260. if (!IS_CHAN_B(chan)
  261. && !(IS_CHAN_2GHZ(chan) && IS_CHAN_HT20(chan)))
  262. retval = true;
  263. break;
  264. }
  265. return retval;
  266. }
  267. static void ath9k_hw_iqcal_collect(struct ath_hal *ah)
  268. {
  269. struct ath_hal_5416 *ahp = AH5416(ah);
  270. int i;
  271. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  272. ahp->ah_totalPowerMeasI[i] +=
  273. REG_READ(ah, AR_PHY_CAL_MEAS_0(i));
  274. ahp->ah_totalPowerMeasQ[i] +=
  275. REG_READ(ah, AR_PHY_CAL_MEAS_1(i));
  276. ahp->ah_totalIqCorrMeas[i] +=
  277. (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_2(i));
  278. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  279. "%d: Chn %d pmi=0x%08x;pmq=0x%08x;iqcm=0x%08x;\n",
  280. ahp->ah_CalSamples, i, ahp->ah_totalPowerMeasI[i],
  281. ahp->ah_totalPowerMeasQ[i],
  282. ahp->ah_totalIqCorrMeas[i]);
  283. }
  284. }
  285. static void ath9k_hw_adc_gaincal_collect(struct ath_hal *ah)
  286. {
  287. struct ath_hal_5416 *ahp = AH5416(ah);
  288. int i;
  289. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  290. ahp->ah_totalAdcIOddPhase[i] +=
  291. REG_READ(ah, AR_PHY_CAL_MEAS_0(i));
  292. ahp->ah_totalAdcIEvenPhase[i] +=
  293. REG_READ(ah, AR_PHY_CAL_MEAS_1(i));
  294. ahp->ah_totalAdcQOddPhase[i] +=
  295. REG_READ(ah, AR_PHY_CAL_MEAS_2(i));
  296. ahp->ah_totalAdcQEvenPhase[i] +=
  297. REG_READ(ah, AR_PHY_CAL_MEAS_3(i));
  298. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  299. "%d: Chn %d oddi=0x%08x; eveni=0x%08x; "
  300. "oddq=0x%08x; evenq=0x%08x;\n",
  301. ahp->ah_CalSamples, i,
  302. ahp->ah_totalAdcIOddPhase[i],
  303. ahp->ah_totalAdcIEvenPhase[i],
  304. ahp->ah_totalAdcQOddPhase[i],
  305. ahp->ah_totalAdcQEvenPhase[i]);
  306. }
  307. }
  308. static void ath9k_hw_adc_dccal_collect(struct ath_hal *ah)
  309. {
  310. struct ath_hal_5416 *ahp = AH5416(ah);
  311. int i;
  312. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  313. ahp->ah_totalAdcDcOffsetIOddPhase[i] +=
  314. (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_0(i));
  315. ahp->ah_totalAdcDcOffsetIEvenPhase[i] +=
  316. (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_1(i));
  317. ahp->ah_totalAdcDcOffsetQOddPhase[i] +=
  318. (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_2(i));
  319. ahp->ah_totalAdcDcOffsetQEvenPhase[i] +=
  320. (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_3(i));
  321. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  322. "%d: Chn %d oddi=0x%08x; eveni=0x%08x; "
  323. "oddq=0x%08x; evenq=0x%08x;\n",
  324. ahp->ah_CalSamples, i,
  325. ahp->ah_totalAdcDcOffsetIOddPhase[i],
  326. ahp->ah_totalAdcDcOffsetIEvenPhase[i],
  327. ahp->ah_totalAdcDcOffsetQOddPhase[i],
  328. ahp->ah_totalAdcDcOffsetQEvenPhase[i]);
  329. }
  330. }
  331. static void ath9k_hw_iqcalibrate(struct ath_hal *ah, u8 numChains)
  332. {
  333. struct ath_hal_5416 *ahp = AH5416(ah);
  334. u32 powerMeasQ, powerMeasI, iqCorrMeas;
  335. u32 qCoffDenom, iCoffDenom;
  336. int32_t qCoff, iCoff;
  337. int iqCorrNeg, i;
  338. for (i = 0; i < numChains; i++) {
  339. powerMeasI = ahp->ah_totalPowerMeasI[i];
  340. powerMeasQ = ahp->ah_totalPowerMeasQ[i];
  341. iqCorrMeas = ahp->ah_totalIqCorrMeas[i];
  342. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  343. "Starting IQ Cal and Correction for Chain %d\n",
  344. i);
  345. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  346. "Orignal: Chn %diq_corr_meas = 0x%08x\n",
  347. i, ahp->ah_totalIqCorrMeas[i]);
  348. iqCorrNeg = 0;
  349. if (iqCorrMeas > 0x80000000) {
  350. iqCorrMeas = (0xffffffff - iqCorrMeas) + 1;
  351. iqCorrNeg = 1;
  352. }
  353. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  354. "Chn %d pwr_meas_i = 0x%08x\n", i, powerMeasI);
  355. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  356. "Chn %d pwr_meas_q = 0x%08x\n", i, powerMeasQ);
  357. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE, "iqCorrNeg is 0x%08x\n",
  358. iqCorrNeg);
  359. iCoffDenom = (powerMeasI / 2 + powerMeasQ / 2) / 128;
  360. qCoffDenom = powerMeasQ / 64;
  361. if (powerMeasQ != 0) {
  362. iCoff = iqCorrMeas / iCoffDenom;
  363. qCoff = powerMeasI / qCoffDenom - 64;
  364. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  365. "Chn %d iCoff = 0x%08x\n", i, iCoff);
  366. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  367. "Chn %d qCoff = 0x%08x\n", i, qCoff);
  368. iCoff = iCoff & 0x3f;
  369. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  370. "New: Chn %d iCoff = 0x%08x\n", i, iCoff);
  371. if (iqCorrNeg == 0x0)
  372. iCoff = 0x40 - iCoff;
  373. if (qCoff > 15)
  374. qCoff = 15;
  375. else if (qCoff <= -16)
  376. qCoff = 16;
  377. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  378. "Chn %d : iCoff = 0x%x qCoff = 0x%x\n",
  379. i, iCoff, qCoff);
  380. REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(i),
  381. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF,
  382. iCoff);
  383. REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(i),
  384. AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF,
  385. qCoff);
  386. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  387. "IQ Cal and Correction done for Chain %d\n",
  388. i);
  389. }
  390. }
  391. REG_SET_BIT(ah, AR_PHY_TIMING_CTRL4(0),
  392. AR_PHY_TIMING_CTRL4_IQCORR_ENABLE);
  393. }
  394. static void ath9k_hw_adc_gaincal_calibrate(struct ath_hal *ah, u8 numChains)
  395. {
  396. struct ath_hal_5416 *ahp = AH5416(ah);
  397. u32 iOddMeasOffset, iEvenMeasOffset, qOddMeasOffset, qEvenMeasOffset;
  398. u32 qGainMismatch, iGainMismatch, val, i;
  399. for (i = 0; i < numChains; i++) {
  400. iOddMeasOffset = ahp->ah_totalAdcIOddPhase[i];
  401. iEvenMeasOffset = ahp->ah_totalAdcIEvenPhase[i];
  402. qOddMeasOffset = ahp->ah_totalAdcQOddPhase[i];
  403. qEvenMeasOffset = ahp->ah_totalAdcQEvenPhase[i];
  404. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  405. "Starting ADC Gain Cal for Chain %d\n", i);
  406. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  407. "Chn %d pwr_meas_odd_i = 0x%08x\n", i,
  408. iOddMeasOffset);
  409. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  410. "Chn %d pwr_meas_even_i = 0x%08x\n", i,
  411. iEvenMeasOffset);
  412. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  413. "Chn %d pwr_meas_odd_q = 0x%08x\n", i,
  414. qOddMeasOffset);
  415. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  416. "Chn %d pwr_meas_even_q = 0x%08x\n", i,
  417. qEvenMeasOffset);
  418. if (iOddMeasOffset != 0 && qEvenMeasOffset != 0) {
  419. iGainMismatch =
  420. ((iEvenMeasOffset * 32) /
  421. iOddMeasOffset) & 0x3f;
  422. qGainMismatch =
  423. ((qOddMeasOffset * 32) /
  424. qEvenMeasOffset) & 0x3f;
  425. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  426. "Chn %d gain_mismatch_i = 0x%08x\n", i,
  427. iGainMismatch);
  428. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  429. "Chn %d gain_mismatch_q = 0x%08x\n", i,
  430. qGainMismatch);
  431. val = REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i));
  432. val &= 0xfffff000;
  433. val |= (qGainMismatch) | (iGainMismatch << 6);
  434. REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i), val);
  435. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  436. "ADC Gain Cal done for Chain %d\n", i);
  437. }
  438. }
  439. REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0),
  440. REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0)) |
  441. AR_PHY_NEW_ADC_GAIN_CORR_ENABLE);
  442. }
  443. static void ath9k_hw_adc_dccal_calibrate(struct ath_hal *ah, u8 numChains)
  444. {
  445. struct ath_hal_5416 *ahp = AH5416(ah);
  446. u32 iOddMeasOffset, iEvenMeasOffset, val, i;
  447. int32_t qOddMeasOffset, qEvenMeasOffset, qDcMismatch, iDcMismatch;
  448. const struct hal_percal_data *calData =
  449. ahp->ah_cal_list_curr->calData;
  450. u32 numSamples =
  451. (1 << (calData->calCountMax + 5)) * calData->calNumSamples;
  452. for (i = 0; i < numChains; i++) {
  453. iOddMeasOffset = ahp->ah_totalAdcDcOffsetIOddPhase[i];
  454. iEvenMeasOffset = ahp->ah_totalAdcDcOffsetIEvenPhase[i];
  455. qOddMeasOffset = ahp->ah_totalAdcDcOffsetQOddPhase[i];
  456. qEvenMeasOffset = ahp->ah_totalAdcDcOffsetQEvenPhase[i];
  457. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  458. "Starting ADC DC Offset Cal for Chain %d\n", i);
  459. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  460. "Chn %d pwr_meas_odd_i = %d\n", i,
  461. iOddMeasOffset);
  462. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  463. "Chn %d pwr_meas_even_i = %d\n", i,
  464. iEvenMeasOffset);
  465. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  466. "Chn %d pwr_meas_odd_q = %d\n", i,
  467. qOddMeasOffset);
  468. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  469. "Chn %d pwr_meas_even_q = %d\n", i,
  470. qEvenMeasOffset);
  471. iDcMismatch = (((iEvenMeasOffset - iOddMeasOffset) * 2) /
  472. numSamples) & 0x1ff;
  473. qDcMismatch = (((qOddMeasOffset - qEvenMeasOffset) * 2) /
  474. numSamples) & 0x1ff;
  475. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  476. "Chn %d dc_offset_mismatch_i = 0x%08x\n", i,
  477. iDcMismatch);
  478. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  479. "Chn %d dc_offset_mismatch_q = 0x%08x\n", i,
  480. qDcMismatch);
  481. val = REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i));
  482. val &= 0xc0000fff;
  483. val |= (qDcMismatch << 12) | (iDcMismatch << 21);
  484. REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i), val);
  485. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  486. "ADC DC Offset Cal done for Chain %d\n", i);
  487. }
  488. REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0),
  489. REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0)) |
  490. AR_PHY_NEW_ADC_DC_OFFSET_CORR_ENABLE);
  491. }
  492. void ath9k_hw_reset_calvalid(struct ath_hal *ah, struct ath9k_channel *chan,
  493. bool *isCalDone)
  494. {
  495. struct ath_hal_5416 *ahp = AH5416(ah);
  496. struct ath9k_channel *ichan =
  497. ath9k_regd_check_channel(ah, chan);
  498. struct hal_cal_list *currCal = ahp->ah_cal_list_curr;
  499. *isCalDone = true;
  500. if (!AR_SREV_9100(ah) && !AR_SREV_9160_10_OR_LATER(ah))
  501. return;
  502. if (currCal == NULL)
  503. return;
  504. if (ichan == NULL) {
  505. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  506. "invalid channel %u/0x%x; no mapping\n",
  507. chan->channel, chan->channelFlags);
  508. return;
  509. }
  510. if (currCal->calState != CAL_DONE) {
  511. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  512. "Calibration state incorrect, %d\n",
  513. currCal->calState);
  514. return;
  515. }
  516. if (!ath9k_hw_iscal_supported(ah, chan, currCal->calData->calType))
  517. return;
  518. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  519. "Resetting Cal %d state for channel %u/0x%x\n",
  520. currCal->calData->calType, chan->channel,
  521. chan->channelFlags);
  522. ichan->CalValid &= ~currCal->calData->calType;
  523. currCal->calState = CAL_WAITING;
  524. *isCalDone = false;
  525. }
  526. void ath9k_hw_start_nfcal(struct ath_hal *ah)
  527. {
  528. REG_SET_BIT(ah, AR_PHY_AGC_CONTROL,
  529. AR_PHY_AGC_CONTROL_ENABLE_NF);
  530. REG_SET_BIT(ah, AR_PHY_AGC_CONTROL,
  531. AR_PHY_AGC_CONTROL_NO_UPDATE_NF);
  532. REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF);
  533. }
  534. void ath9k_hw_loadnf(struct ath_hal *ah, struct ath9k_channel *chan)
  535. {
  536. struct ath9k_nfcal_hist *h;
  537. int i, j;
  538. int32_t val;
  539. const u32 ar5416_cca_regs[6] = {
  540. AR_PHY_CCA,
  541. AR_PHY_CH1_CCA,
  542. AR_PHY_CH2_CCA,
  543. AR_PHY_EXT_CCA,
  544. AR_PHY_CH1_EXT_CCA,
  545. AR_PHY_CH2_EXT_CCA
  546. };
  547. u8 chainmask;
  548. if (AR_SREV_9280(ah))
  549. chainmask = 0x1B;
  550. else
  551. chainmask = 0x3F;
  552. #ifdef ATH_NF_PER_CHAN
  553. h = chan->nfCalHist;
  554. #else
  555. h = ah->nfCalHist;
  556. #endif
  557. for (i = 0; i < NUM_NF_READINGS; i++) {
  558. if (chainmask & (1 << i)) {
  559. val = REG_READ(ah, ar5416_cca_regs[i]);
  560. val &= 0xFFFFFE00;
  561. val |= (((u32) (h[i].privNF) << 1) & 0x1ff);
  562. REG_WRITE(ah, ar5416_cca_regs[i], val);
  563. }
  564. }
  565. REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
  566. AR_PHY_AGC_CONTROL_ENABLE_NF);
  567. REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
  568. AR_PHY_AGC_CONTROL_NO_UPDATE_NF);
  569. REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF);
  570. for (j = 0; j < 1000; j++) {
  571. if ((REG_READ(ah, AR_PHY_AGC_CONTROL) &
  572. AR_PHY_AGC_CONTROL_NF) == 0)
  573. break;
  574. udelay(10);
  575. }
  576. for (i = 0; i < NUM_NF_READINGS; i++) {
  577. if (chainmask & (1 << i)) {
  578. val = REG_READ(ah, ar5416_cca_regs[i]);
  579. val &= 0xFFFFFE00;
  580. val |= (((u32) (-50) << 1) & 0x1ff);
  581. REG_WRITE(ah, ar5416_cca_regs[i], val);
  582. }
  583. }
  584. }
  585. int16_t ath9k_hw_getnf(struct ath_hal *ah,
  586. struct ath9k_channel *chan)
  587. {
  588. int16_t nf, nfThresh;
  589. int16_t nfarray[NUM_NF_READINGS] = { 0 };
  590. struct ath9k_nfcal_hist *h;
  591. u8 chainmask;
  592. if (AR_SREV_9280(ah))
  593. chainmask = 0x1B;
  594. else
  595. chainmask = 0x3F;
  596. chan->channelFlags &= (~CHANNEL_CW_INT);
  597. if (REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF) {
  598. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  599. "NF did not complete in calibration window\n");
  600. nf = 0;
  601. chan->rawNoiseFloor = nf;
  602. return chan->rawNoiseFloor;
  603. } else {
  604. ath9k_hw_do_getnf(ah, nfarray);
  605. nf = nfarray[0];
  606. if (getNoiseFloorThresh(ah, chan, &nfThresh)
  607. && nf > nfThresh) {
  608. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  609. "noise floor failed detected; "
  610. "detected %d, threshold %d\n",
  611. nf, nfThresh);
  612. chan->channelFlags |= CHANNEL_CW_INT;
  613. }
  614. }
  615. #ifdef ATH_NF_PER_CHAN
  616. h = chan->nfCalHist;
  617. #else
  618. h = ah->nfCalHist;
  619. #endif
  620. ath9k_hw_update_nfcal_hist_buffer(h, nfarray);
  621. chan->rawNoiseFloor = h[0].privNF;
  622. return chan->rawNoiseFloor;
  623. }
  624. void ath9k_init_nfcal_hist_buffer(struct ath_hal *ah)
  625. {
  626. int i, j;
  627. for (i = 0; i < NUM_NF_READINGS; i++) {
  628. ah->nfCalHist[i].currIndex = 0;
  629. ah->nfCalHist[i].privNF = AR_PHY_CCA_MAX_GOOD_VALUE;
  630. ah->nfCalHist[i].invalidNFcount =
  631. AR_PHY_CCA_FILTERWINDOW_LENGTH;
  632. for (j = 0; j < ATH9K_NF_CAL_HIST_MAX; j++) {
  633. ah->nfCalHist[i].nfCalBuffer[j] =
  634. AR_PHY_CCA_MAX_GOOD_VALUE;
  635. }
  636. }
  637. return;
  638. }
  639. s16 ath9k_hw_getchan_noise(struct ath_hal *ah, struct ath9k_channel *chan)
  640. {
  641. struct ath9k_channel *ichan;
  642. s16 nf;
  643. ichan = ath9k_regd_check_channel(ah, chan);
  644. if (ichan == NULL) {
  645. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  646. "invalid channel %u/0x%x; no mapping\n",
  647. chan->channel, chan->channelFlags);
  648. return ATH_DEFAULT_NOISE_FLOOR;
  649. }
  650. if (ichan->rawNoiseFloor == 0) {
  651. enum wireless_mode mode = ath9k_hw_chan2wmode(ah, chan);
  652. nf = NOISE_FLOOR[mode];
  653. } else
  654. nf = ichan->rawNoiseFloor;
  655. if (!ath9k_hw_nf_in_range(ah, nf))
  656. nf = ATH_DEFAULT_NOISE_FLOOR;
  657. return nf;
  658. }
  659. bool ath9k_hw_calibrate(struct ath_hal *ah, struct ath9k_channel *chan,
  660. u8 rxchainmask, bool longcal,
  661. bool *isCalDone)
  662. {
  663. struct ath_hal_5416 *ahp = AH5416(ah);
  664. struct hal_cal_list *currCal = ahp->ah_cal_list_curr;
  665. struct ath9k_channel *ichan = ath9k_regd_check_channel(ah, chan);
  666. *isCalDone = true;
  667. if (ichan == NULL) {
  668. DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
  669. "invalid channel %u/0x%x; no mapping\n",
  670. chan->channel, chan->channelFlags);
  671. return false;
  672. }
  673. if (currCal &&
  674. (currCal->calState == CAL_RUNNING ||
  675. currCal->calState == CAL_WAITING)) {
  676. ath9k_hw_per_calibration(ah, ichan, rxchainmask, currCal,
  677. isCalDone);
  678. if (*isCalDone) {
  679. ahp->ah_cal_list_curr = currCal = currCal->calNext;
  680. if (currCal->calState == CAL_WAITING) {
  681. *isCalDone = false;
  682. ath9k_hw_reset_calibration(ah, currCal);
  683. }
  684. }
  685. }
  686. if (longcal) {
  687. ath9k_hw_getnf(ah, ichan);
  688. ath9k_hw_loadnf(ah, ah->ah_curchan);
  689. ath9k_hw_start_nfcal(ah);
  690. if ((ichan->channelFlags & CHANNEL_CW_INT) != 0) {
  691. chan->channelFlags |= CHANNEL_CW_INT;
  692. ichan->channelFlags &= ~CHANNEL_CW_INT;
  693. }
  694. }
  695. return true;
  696. }
  697. static inline void ath9k_hw_9285_pa_cal(struct ath_hal *ah)
  698. {
  699. u32 regVal;
  700. int i, offset, offs_6_1, offs_0;
  701. u32 ccomp_org, reg_field;
  702. u32 regList[][2] = {
  703. { 0x786c, 0 },
  704. { 0x7854, 0 },
  705. { 0x7820, 0 },
  706. { 0x7824, 0 },
  707. { 0x7868, 0 },
  708. { 0x783c, 0 },
  709. { 0x7838, 0 },
  710. };
  711. if (AR_SREV_9285_11(ah)) {
  712. REG_WRITE(ah, AR9285_AN_TOP4, (AR9285_AN_TOP4_DEFAULT | 0x14));
  713. udelay(10);
  714. }
  715. for (i = 0; i < ARRAY_SIZE(regList); i++)
  716. regList[i][1] = REG_READ(ah, regList[i][0]);
  717. regVal = REG_READ(ah, 0x7834);
  718. regVal &= (~(0x1));
  719. REG_WRITE(ah, 0x7834, regVal);
  720. regVal = REG_READ(ah, 0x9808);
  721. regVal |= (0x1 << 27);
  722. REG_WRITE(ah, 0x9808, regVal);
  723. REG_RMW_FIELD(ah, AR9285_AN_TOP3, AR9285_AN_TOP3_PWDDAC, 1);
  724. REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDRXTXBB1, 1);
  725. REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDV2I, 1);
  726. REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDDACIF, 1);
  727. REG_RMW_FIELD(ah, AR9285_AN_RF2G2, AR9285_AN_RF2G2_OFFCAL, 0);
  728. REG_RMW_FIELD(ah, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PWDDB, 0);
  729. REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_ENPACAL, 0);
  730. REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV1, 1);
  731. REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV2, 0);
  732. REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPAOUT, 0);
  733. REG_RMW_FIELD(ah, AR9285_AN_RF2G8, AR9285_AN_RF2G8_PADRVGN2TAB0, 7);
  734. REG_RMW_FIELD(ah, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PADRVGN2TAB0, 0);
  735. ccomp_org = MS(REG_READ(ah, AR9285_AN_RF2G6), AR9285_AN_RF2G6_CCOMP);
  736. REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_CCOMP, 7);
  737. REG_WRITE(ah, AR9285_AN_TOP2, 0xca0358a0);
  738. udelay(30);
  739. REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_OFFS, 0);
  740. REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, 0);
  741. for (i = 6; i > 0; i--) {
  742. regVal = REG_READ(ah, 0x7834);
  743. regVal |= (1 << (19 + i));
  744. REG_WRITE(ah, 0x7834, regVal);
  745. udelay(1);
  746. regVal = REG_READ(ah, 0x7834);
  747. regVal &= (~(0x1 << (19 + i)));
  748. reg_field = MS(REG_READ(ah, 0x7840), AR9285_AN_RXTXBB1_SPARE9);
  749. regVal |= (reg_field << (19 + i));
  750. REG_WRITE(ah, 0x7834, regVal);
  751. }
  752. REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, 1);
  753. udelay(1);
  754. reg_field = MS(REG_READ(ah, AR9285_AN_RF2G9), AR9285_AN_RXTXBB1_SPARE9);
  755. REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, reg_field);
  756. offs_6_1 = MS(REG_READ(ah, AR9285_AN_RF2G6), AR9285_AN_RF2G6_OFFS);
  757. offs_0 = MS(REG_READ(ah, AR9285_AN_RF2G3), AR9285_AN_RF2G3_PDVCCOMP);
  758. offset = (offs_6_1<<1) | offs_0;
  759. offset = offset - 0;
  760. offs_6_1 = offset>>1;
  761. offs_0 = offset & 1;
  762. REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_OFFS, offs_6_1);
  763. REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, offs_0);
  764. regVal = REG_READ(ah, 0x7834);
  765. regVal |= 0x1;
  766. REG_WRITE(ah, 0x7834, regVal);
  767. regVal = REG_READ(ah, 0x9808);
  768. regVal &= (~(0x1 << 27));
  769. REG_WRITE(ah, 0x9808, regVal);
  770. for (i = 0; i < ARRAY_SIZE(regList); i++)
  771. REG_WRITE(ah, regList[i][0], regList[i][1]);
  772. REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_CCOMP, ccomp_org);
  773. if (AR_SREV_9285_11(ah))
  774. REG_WRITE(ah, AR9285_AN_TOP4, AR9285_AN_TOP4_DEFAULT);
  775. }
  776. bool ath9k_hw_init_cal(struct ath_hal *ah,
  777. struct ath9k_channel *chan)
  778. {
  779. struct ath_hal_5416 *ahp = AH5416(ah);
  780. struct ath9k_channel *ichan = ath9k_regd_check_channel(ah, chan);
  781. REG_WRITE(ah, AR_PHY_AGC_CONTROL,
  782. REG_READ(ah, AR_PHY_AGC_CONTROL) |
  783. AR_PHY_AGC_CONTROL_CAL);
  784. if (!ath9k_hw_wait(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL, 0)) {
  785. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  786. "offset calibration failed to complete in 1ms; "
  787. "noisy environment?\n");
  788. return false;
  789. }
  790. if (AR_SREV_9285(ah) && AR_SREV_9285_11_OR_LATER(ah))
  791. ath9k_hw_9285_pa_cal(ah);
  792. REG_WRITE(ah, AR_PHY_AGC_CONTROL,
  793. REG_READ(ah, AR_PHY_AGC_CONTROL) |
  794. AR_PHY_AGC_CONTROL_NF);
  795. ahp->ah_cal_list = ahp->ah_cal_list_last = ahp->ah_cal_list_curr = NULL;
  796. if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah)) {
  797. if (ath9k_hw_iscal_supported(ah, chan, ADC_GAIN_CAL)) {
  798. INIT_CAL(&ahp->ah_adcGainCalData);
  799. INSERT_CAL(ahp, &ahp->ah_adcGainCalData);
  800. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  801. "enabling ADC Gain Calibration.\n");
  802. }
  803. if (ath9k_hw_iscal_supported(ah, chan, ADC_DC_CAL)) {
  804. INIT_CAL(&ahp->ah_adcDcCalData);
  805. INSERT_CAL(ahp, &ahp->ah_adcDcCalData);
  806. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  807. "enabling ADC DC Calibration.\n");
  808. }
  809. if (ath9k_hw_iscal_supported(ah, chan, IQ_MISMATCH_CAL)) {
  810. INIT_CAL(&ahp->ah_iqCalData);
  811. INSERT_CAL(ahp, &ahp->ah_iqCalData);
  812. DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
  813. "enabling IQ Calibration.\n");
  814. }
  815. ahp->ah_cal_list_curr = ahp->ah_cal_list;
  816. if (ahp->ah_cal_list_curr)
  817. ath9k_hw_reset_calibration(ah, ahp->ah_cal_list_curr);
  818. }
  819. ichan->CalValid = 0;
  820. return true;
  821. }
  822. const struct hal_percal_data iq_cal_multi_sample = {
  823. IQ_MISMATCH_CAL,
  824. MAX_CAL_SAMPLES,
  825. PER_MIN_LOG_COUNT,
  826. ath9k_hw_iqcal_collect,
  827. ath9k_hw_iqcalibrate
  828. };
  829. const struct hal_percal_data iq_cal_single_sample = {
  830. IQ_MISMATCH_CAL,
  831. MIN_CAL_SAMPLES,
  832. PER_MAX_LOG_COUNT,
  833. ath9k_hw_iqcal_collect,
  834. ath9k_hw_iqcalibrate
  835. };
  836. const struct hal_percal_data adc_gain_cal_multi_sample = {
  837. ADC_GAIN_CAL,
  838. MAX_CAL_SAMPLES,
  839. PER_MIN_LOG_COUNT,
  840. ath9k_hw_adc_gaincal_collect,
  841. ath9k_hw_adc_gaincal_calibrate
  842. };
  843. const struct hal_percal_data adc_gain_cal_single_sample = {
  844. ADC_GAIN_CAL,
  845. MIN_CAL_SAMPLES,
  846. PER_MAX_LOG_COUNT,
  847. ath9k_hw_adc_gaincal_collect,
  848. ath9k_hw_adc_gaincal_calibrate
  849. };
  850. const struct hal_percal_data adc_dc_cal_multi_sample = {
  851. ADC_DC_CAL,
  852. MAX_CAL_SAMPLES,
  853. PER_MIN_LOG_COUNT,
  854. ath9k_hw_adc_dccal_collect,
  855. ath9k_hw_adc_dccal_calibrate
  856. };
  857. const struct hal_percal_data adc_dc_cal_single_sample = {
  858. ADC_DC_CAL,
  859. MIN_CAL_SAMPLES,
  860. PER_MAX_LOG_COUNT,
  861. ath9k_hw_adc_dccal_collect,
  862. ath9k_hw_adc_dccal_calibrate
  863. };
  864. const struct hal_percal_data adc_init_dc_cal = {
  865. ADC_DC_INIT_CAL,
  866. MIN_CAL_SAMPLES,
  867. INIT_LOG_COUNT,
  868. ath9k_hw_adc_dccal_collect,
  869. ath9k_hw_adc_dccal_calibrate
  870. };