ar9003_calib.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  1. /*
  2. * Copyright (c) 2010 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 "hw.h"
  17. #include "hw-ops.h"
  18. #include "ar9003_phy.h"
  19. #define MPASS 3
  20. #define MAX_MEASUREMENT 8
  21. #define MAX_DIFFERENCE 10
  22. struct coeff {
  23. int mag_coeff[AR9300_MAX_CHAINS][MAX_MEASUREMENT][MPASS];
  24. int phs_coeff[AR9300_MAX_CHAINS][MAX_MEASUREMENT][MPASS];
  25. int iqc_coeff[2];
  26. };
  27. enum ar9003_cal_types {
  28. IQ_MISMATCH_CAL = BIT(0),
  29. TEMP_COMP_CAL = BIT(1),
  30. };
  31. static void ar9003_hw_setup_calibration(struct ath_hw *ah,
  32. struct ath9k_cal_list *currCal)
  33. {
  34. struct ath_common *common = ath9k_hw_common(ah);
  35. /* Select calibration to run */
  36. switch (currCal->calData->calType) {
  37. case IQ_MISMATCH_CAL:
  38. /*
  39. * Start calibration with
  40. * 2^(INIT_IQCAL_LOG_COUNT_MAX+1) samples
  41. */
  42. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  43. AR_PHY_TIMING4_IQCAL_LOG_COUNT_MAX,
  44. currCal->calData->calCountMax);
  45. REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_IQ);
  46. ath_dbg(common, ATH_DBG_CALIBRATE,
  47. "starting IQ Mismatch Calibration\n");
  48. /* Kick-off cal */
  49. REG_SET_BIT(ah, AR_PHY_TIMING4, AR_PHY_TIMING4_DO_CAL);
  50. break;
  51. case TEMP_COMP_CAL:
  52. REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_THERM,
  53. AR_PHY_65NM_CH0_THERM_LOCAL, 1);
  54. REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_THERM,
  55. AR_PHY_65NM_CH0_THERM_START, 1);
  56. ath_dbg(common, ATH_DBG_CALIBRATE,
  57. "starting Temperature Compensation Calibration\n");
  58. break;
  59. }
  60. }
  61. /*
  62. * Generic calibration routine.
  63. * Recalibrate the lower PHY chips to account for temperature/environment
  64. * changes.
  65. */
  66. static bool ar9003_hw_per_calibration(struct ath_hw *ah,
  67. struct ath9k_channel *ichan,
  68. u8 rxchainmask,
  69. struct ath9k_cal_list *currCal)
  70. {
  71. struct ath9k_hw_cal_data *caldata = ah->caldata;
  72. /* Cal is assumed not done until explicitly set below */
  73. bool iscaldone = false;
  74. /* Calibration in progress. */
  75. if (currCal->calState == CAL_RUNNING) {
  76. /* Check to see if it has finished. */
  77. if (!(REG_READ(ah, AR_PHY_TIMING4) & AR_PHY_TIMING4_DO_CAL)) {
  78. /*
  79. * Accumulate cal measures for active chains
  80. */
  81. currCal->calData->calCollect(ah);
  82. ah->cal_samples++;
  83. if (ah->cal_samples >=
  84. currCal->calData->calNumSamples) {
  85. unsigned int i, numChains = 0;
  86. for (i = 0; i < AR9300_MAX_CHAINS; i++) {
  87. if (rxchainmask & (1 << i))
  88. numChains++;
  89. }
  90. /*
  91. * Process accumulated data
  92. */
  93. currCal->calData->calPostProc(ah, numChains);
  94. /* Calibration has finished. */
  95. caldata->CalValid |= currCal->calData->calType;
  96. currCal->calState = CAL_DONE;
  97. iscaldone = true;
  98. } else {
  99. /*
  100. * Set-up collection of another sub-sample until we
  101. * get desired number
  102. */
  103. ar9003_hw_setup_calibration(ah, currCal);
  104. }
  105. }
  106. } else if (!(caldata->CalValid & currCal->calData->calType)) {
  107. /* If current cal is marked invalid in channel, kick it off */
  108. ath9k_hw_reset_calibration(ah, currCal);
  109. }
  110. return iscaldone;
  111. }
  112. static bool ar9003_hw_calibrate(struct ath_hw *ah,
  113. struct ath9k_channel *chan,
  114. u8 rxchainmask,
  115. bool longcal)
  116. {
  117. bool iscaldone = true;
  118. struct ath9k_cal_list *currCal = ah->cal_list_curr;
  119. /*
  120. * For given calibration:
  121. * 1. Call generic cal routine
  122. * 2. When this cal is done (isCalDone) if we have more cals waiting
  123. * (eg after reset), mask this to upper layers by not propagating
  124. * isCalDone if it is set to TRUE.
  125. * Instead, change isCalDone to FALSE and setup the waiting cal(s)
  126. * to be run.
  127. */
  128. if (currCal &&
  129. (currCal->calState == CAL_RUNNING ||
  130. currCal->calState == CAL_WAITING)) {
  131. iscaldone = ar9003_hw_per_calibration(ah, chan,
  132. rxchainmask, currCal);
  133. if (iscaldone) {
  134. ah->cal_list_curr = currCal = currCal->calNext;
  135. if (currCal->calState == CAL_WAITING) {
  136. iscaldone = false;
  137. ath9k_hw_reset_calibration(ah, currCal);
  138. }
  139. }
  140. }
  141. /* Do NF cal only at longer intervals */
  142. if (longcal) {
  143. /*
  144. * Get the value from the previous NF cal and update
  145. * history buffer.
  146. */
  147. ath9k_hw_getnf(ah, chan);
  148. /*
  149. * Load the NF from history buffer of the current channel.
  150. * NF is slow time-variant, so it is OK to use a historical
  151. * value.
  152. */
  153. ath9k_hw_loadnf(ah, ah->curchan);
  154. /* start NF calibration, without updating BB NF register */
  155. ath9k_hw_start_nfcal(ah, false);
  156. }
  157. return iscaldone;
  158. }
  159. static void ar9003_hw_iqcal_collect(struct ath_hw *ah)
  160. {
  161. int i;
  162. /* Accumulate IQ cal measures for active chains */
  163. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  164. ah->totalPowerMeasI[i] +=
  165. REG_READ(ah, AR_PHY_CAL_MEAS_0(i));
  166. ah->totalPowerMeasQ[i] +=
  167. REG_READ(ah, AR_PHY_CAL_MEAS_1(i));
  168. ah->totalIqCorrMeas[i] +=
  169. (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_2(i));
  170. ath_dbg(ath9k_hw_common(ah), ATH_DBG_CALIBRATE,
  171. "%d: Chn %d pmi=0x%08x;pmq=0x%08x;iqcm=0x%08x;\n",
  172. ah->cal_samples, i, ah->totalPowerMeasI[i],
  173. ah->totalPowerMeasQ[i],
  174. ah->totalIqCorrMeas[i]);
  175. }
  176. }
  177. static void ar9003_hw_iqcalibrate(struct ath_hw *ah, u8 numChains)
  178. {
  179. struct ath_common *common = ath9k_hw_common(ah);
  180. u32 powerMeasQ, powerMeasI, iqCorrMeas;
  181. u32 qCoffDenom, iCoffDenom;
  182. int32_t qCoff, iCoff;
  183. int iqCorrNeg, i;
  184. static const u_int32_t offset_array[3] = {
  185. AR_PHY_RX_IQCAL_CORR_B0,
  186. AR_PHY_RX_IQCAL_CORR_B1,
  187. AR_PHY_RX_IQCAL_CORR_B2,
  188. };
  189. for (i = 0; i < numChains; i++) {
  190. powerMeasI = ah->totalPowerMeasI[i];
  191. powerMeasQ = ah->totalPowerMeasQ[i];
  192. iqCorrMeas = ah->totalIqCorrMeas[i];
  193. ath_dbg(common, ATH_DBG_CALIBRATE,
  194. "Starting IQ Cal and Correction for Chain %d\n",
  195. i);
  196. ath_dbg(common, ATH_DBG_CALIBRATE,
  197. "Orignal: Chn %diq_corr_meas = 0x%08x\n",
  198. i, ah->totalIqCorrMeas[i]);
  199. iqCorrNeg = 0;
  200. if (iqCorrMeas > 0x80000000) {
  201. iqCorrMeas = (0xffffffff - iqCorrMeas) + 1;
  202. iqCorrNeg = 1;
  203. }
  204. ath_dbg(common, ATH_DBG_CALIBRATE,
  205. "Chn %d pwr_meas_i = 0x%08x\n", i, powerMeasI);
  206. ath_dbg(common, ATH_DBG_CALIBRATE,
  207. "Chn %d pwr_meas_q = 0x%08x\n", i, powerMeasQ);
  208. ath_dbg(common, ATH_DBG_CALIBRATE, "iqCorrNeg is 0x%08x\n",
  209. iqCorrNeg);
  210. iCoffDenom = (powerMeasI / 2 + powerMeasQ / 2) / 256;
  211. qCoffDenom = powerMeasQ / 64;
  212. if ((iCoffDenom != 0) && (qCoffDenom != 0)) {
  213. iCoff = iqCorrMeas / iCoffDenom;
  214. qCoff = powerMeasI / qCoffDenom - 64;
  215. ath_dbg(common, ATH_DBG_CALIBRATE,
  216. "Chn %d iCoff = 0x%08x\n", i, iCoff);
  217. ath_dbg(common, ATH_DBG_CALIBRATE,
  218. "Chn %d qCoff = 0x%08x\n", i, qCoff);
  219. /* Force bounds on iCoff */
  220. if (iCoff >= 63)
  221. iCoff = 63;
  222. else if (iCoff <= -63)
  223. iCoff = -63;
  224. /* Negate iCoff if iqCorrNeg == 0 */
  225. if (iqCorrNeg == 0x0)
  226. iCoff = -iCoff;
  227. /* Force bounds on qCoff */
  228. if (qCoff >= 63)
  229. qCoff = 63;
  230. else if (qCoff <= -63)
  231. qCoff = -63;
  232. iCoff = iCoff & 0x7f;
  233. qCoff = qCoff & 0x7f;
  234. ath_dbg(common, ATH_DBG_CALIBRATE,
  235. "Chn %d : iCoff = 0x%x qCoff = 0x%x\n",
  236. i, iCoff, qCoff);
  237. ath_dbg(common, ATH_DBG_CALIBRATE,
  238. "Register offset (0x%04x) before update = 0x%x\n",
  239. offset_array[i],
  240. REG_READ(ah, offset_array[i]));
  241. REG_RMW_FIELD(ah, offset_array[i],
  242. AR_PHY_RX_IQCAL_CORR_IQCORR_Q_I_COFF,
  243. iCoff);
  244. REG_RMW_FIELD(ah, offset_array[i],
  245. AR_PHY_RX_IQCAL_CORR_IQCORR_Q_Q_COFF,
  246. qCoff);
  247. ath_dbg(common, ATH_DBG_CALIBRATE,
  248. "Register offset (0x%04x) QI COFF (bitfields 0x%08x) after update = 0x%x\n",
  249. offset_array[i],
  250. AR_PHY_RX_IQCAL_CORR_IQCORR_Q_I_COFF,
  251. REG_READ(ah, offset_array[i]));
  252. ath_dbg(common, ATH_DBG_CALIBRATE,
  253. "Register offset (0x%04x) QQ COFF (bitfields 0x%08x) after update = 0x%x\n",
  254. offset_array[i],
  255. AR_PHY_RX_IQCAL_CORR_IQCORR_Q_Q_COFF,
  256. REG_READ(ah, offset_array[i]));
  257. ath_dbg(common, ATH_DBG_CALIBRATE,
  258. "IQ Cal and Correction done for Chain %d\n", i);
  259. }
  260. }
  261. REG_SET_BIT(ah, AR_PHY_RX_IQCAL_CORR_B0,
  262. AR_PHY_RX_IQCAL_CORR_IQCORR_ENABLE);
  263. ath_dbg(common, ATH_DBG_CALIBRATE,
  264. "IQ Cal and Correction (offset 0x%04x) enabled (bit position 0x%08x). New Value 0x%08x\n",
  265. (unsigned) (AR_PHY_RX_IQCAL_CORR_B0),
  266. AR_PHY_RX_IQCAL_CORR_IQCORR_ENABLE,
  267. REG_READ(ah, AR_PHY_RX_IQCAL_CORR_B0));
  268. }
  269. static const struct ath9k_percal_data iq_cal_single_sample = {
  270. IQ_MISMATCH_CAL,
  271. MIN_CAL_SAMPLES,
  272. PER_MAX_LOG_COUNT,
  273. ar9003_hw_iqcal_collect,
  274. ar9003_hw_iqcalibrate
  275. };
  276. static void ar9003_hw_init_cal_settings(struct ath_hw *ah)
  277. {
  278. ah->iq_caldata.calData = &iq_cal_single_sample;
  279. }
  280. /*
  281. * solve 4x4 linear equation used in loopback iq cal.
  282. */
  283. static bool ar9003_hw_solve_iq_cal(struct ath_hw *ah,
  284. s32 sin_2phi_1,
  285. s32 cos_2phi_1,
  286. s32 sin_2phi_2,
  287. s32 cos_2phi_2,
  288. s32 mag_a0_d0,
  289. s32 phs_a0_d0,
  290. s32 mag_a1_d0,
  291. s32 phs_a1_d0,
  292. s32 solved_eq[])
  293. {
  294. s32 f1 = cos_2phi_1 - cos_2phi_2,
  295. f3 = sin_2phi_1 - sin_2phi_2,
  296. f2;
  297. s32 mag_tx, phs_tx, mag_rx, phs_rx;
  298. const s32 result_shift = 1 << 15;
  299. struct ath_common *common = ath9k_hw_common(ah);
  300. f2 = (f1 * f1 + f3 * f3) / result_shift;
  301. if (!f2) {
  302. ath_dbg(common, ATH_DBG_CALIBRATE, "Divide by 0\n");
  303. return false;
  304. }
  305. /* mag mismatch, tx */
  306. mag_tx = f1 * (mag_a0_d0 - mag_a1_d0) + f3 * (phs_a0_d0 - phs_a1_d0);
  307. /* phs mismatch, tx */
  308. phs_tx = f3 * (-mag_a0_d0 + mag_a1_d0) + f1 * (phs_a0_d0 - phs_a1_d0);
  309. mag_tx = (mag_tx / f2);
  310. phs_tx = (phs_tx / f2);
  311. /* mag mismatch, rx */
  312. mag_rx = mag_a0_d0 - (cos_2phi_1 * mag_tx + sin_2phi_1 * phs_tx) /
  313. result_shift;
  314. /* phs mismatch, rx */
  315. phs_rx = phs_a0_d0 + (sin_2phi_1 * mag_tx - cos_2phi_1 * phs_tx) /
  316. result_shift;
  317. solved_eq[0] = mag_tx;
  318. solved_eq[1] = phs_tx;
  319. solved_eq[2] = mag_rx;
  320. solved_eq[3] = phs_rx;
  321. return true;
  322. }
  323. static s32 ar9003_hw_find_mag_approx(struct ath_hw *ah, s32 in_re, s32 in_im)
  324. {
  325. s32 abs_i = abs(in_re),
  326. abs_q = abs(in_im),
  327. max_abs, min_abs;
  328. if (abs_i > abs_q) {
  329. max_abs = abs_i;
  330. min_abs = abs_q;
  331. } else {
  332. max_abs = abs_q;
  333. min_abs = abs_i;
  334. }
  335. return max_abs - (max_abs / 32) + (min_abs / 8) + (min_abs / 4);
  336. }
  337. #define DELPT 32
  338. static bool ar9003_hw_calc_iq_corr(struct ath_hw *ah,
  339. s32 chain_idx,
  340. const s32 iq_res[],
  341. s32 iqc_coeff[])
  342. {
  343. s32 i2_m_q2_a0_d0, i2_p_q2_a0_d0, iq_corr_a0_d0,
  344. i2_m_q2_a0_d1, i2_p_q2_a0_d1, iq_corr_a0_d1,
  345. i2_m_q2_a1_d0, i2_p_q2_a1_d0, iq_corr_a1_d0,
  346. i2_m_q2_a1_d1, i2_p_q2_a1_d1, iq_corr_a1_d1;
  347. s32 mag_a0_d0, mag_a1_d0, mag_a0_d1, mag_a1_d1,
  348. phs_a0_d0, phs_a1_d0, phs_a0_d1, phs_a1_d1,
  349. sin_2phi_1, cos_2phi_1,
  350. sin_2phi_2, cos_2phi_2;
  351. s32 mag_tx, phs_tx, mag_rx, phs_rx;
  352. s32 solved_eq[4], mag_corr_tx, phs_corr_tx, mag_corr_rx, phs_corr_rx,
  353. q_q_coff, q_i_coff;
  354. const s32 res_scale = 1 << 15;
  355. const s32 delpt_shift = 1 << 8;
  356. s32 mag1, mag2;
  357. struct ath_common *common = ath9k_hw_common(ah);
  358. i2_m_q2_a0_d0 = iq_res[0] & 0xfff;
  359. i2_p_q2_a0_d0 = (iq_res[0] >> 12) & 0xfff;
  360. iq_corr_a0_d0 = ((iq_res[0] >> 24) & 0xff) + ((iq_res[1] & 0xf) << 8);
  361. if (i2_m_q2_a0_d0 > 0x800)
  362. i2_m_q2_a0_d0 = -((0xfff - i2_m_q2_a0_d0) + 1);
  363. if (i2_p_q2_a0_d0 > 0x800)
  364. i2_p_q2_a0_d0 = -((0xfff - i2_p_q2_a0_d0) + 1);
  365. if (iq_corr_a0_d0 > 0x800)
  366. iq_corr_a0_d0 = -((0xfff - iq_corr_a0_d0) + 1);
  367. i2_m_q2_a0_d1 = (iq_res[1] >> 4) & 0xfff;
  368. i2_p_q2_a0_d1 = (iq_res[2] & 0xfff);
  369. iq_corr_a0_d1 = (iq_res[2] >> 12) & 0xfff;
  370. if (i2_m_q2_a0_d1 > 0x800)
  371. i2_m_q2_a0_d1 = -((0xfff - i2_m_q2_a0_d1) + 1);
  372. if (i2_p_q2_a0_d1 > 0x800)
  373. i2_p_q2_a0_d1 = -((0xfff - i2_p_q2_a0_d1) + 1);
  374. if (iq_corr_a0_d1 > 0x800)
  375. iq_corr_a0_d1 = -((0xfff - iq_corr_a0_d1) + 1);
  376. i2_m_q2_a1_d0 = ((iq_res[2] >> 24) & 0xff) + ((iq_res[3] & 0xf) << 8);
  377. i2_p_q2_a1_d0 = (iq_res[3] >> 4) & 0xfff;
  378. iq_corr_a1_d0 = iq_res[4] & 0xfff;
  379. if (i2_m_q2_a1_d0 > 0x800)
  380. i2_m_q2_a1_d0 = -((0xfff - i2_m_q2_a1_d0) + 1);
  381. if (i2_p_q2_a1_d0 > 0x800)
  382. i2_p_q2_a1_d0 = -((0xfff - i2_p_q2_a1_d0) + 1);
  383. if (iq_corr_a1_d0 > 0x800)
  384. iq_corr_a1_d0 = -((0xfff - iq_corr_a1_d0) + 1);
  385. i2_m_q2_a1_d1 = (iq_res[4] >> 12) & 0xfff;
  386. i2_p_q2_a1_d1 = ((iq_res[4] >> 24) & 0xff) + ((iq_res[5] & 0xf) << 8);
  387. iq_corr_a1_d1 = (iq_res[5] >> 4) & 0xfff;
  388. if (i2_m_q2_a1_d1 > 0x800)
  389. i2_m_q2_a1_d1 = -((0xfff - i2_m_q2_a1_d1) + 1);
  390. if (i2_p_q2_a1_d1 > 0x800)
  391. i2_p_q2_a1_d1 = -((0xfff - i2_p_q2_a1_d1) + 1);
  392. if (iq_corr_a1_d1 > 0x800)
  393. iq_corr_a1_d1 = -((0xfff - iq_corr_a1_d1) + 1);
  394. if ((i2_p_q2_a0_d0 == 0) || (i2_p_q2_a0_d1 == 0) ||
  395. (i2_p_q2_a1_d0 == 0) || (i2_p_q2_a1_d1 == 0)) {
  396. ath_dbg(common, ATH_DBG_CALIBRATE,
  397. "Divide by 0:\n"
  398. "a0_d0=%d\n"
  399. "a0_d1=%d\n"
  400. "a2_d0=%d\n"
  401. "a1_d1=%d\n",
  402. i2_p_q2_a0_d0, i2_p_q2_a0_d1,
  403. i2_p_q2_a1_d0, i2_p_q2_a1_d1);
  404. return false;
  405. }
  406. mag_a0_d0 = (i2_m_q2_a0_d0 * res_scale) / i2_p_q2_a0_d0;
  407. phs_a0_d0 = (iq_corr_a0_d0 * res_scale) / i2_p_q2_a0_d0;
  408. mag_a0_d1 = (i2_m_q2_a0_d1 * res_scale) / i2_p_q2_a0_d1;
  409. phs_a0_d1 = (iq_corr_a0_d1 * res_scale) / i2_p_q2_a0_d1;
  410. mag_a1_d0 = (i2_m_q2_a1_d0 * res_scale) / i2_p_q2_a1_d0;
  411. phs_a1_d0 = (iq_corr_a1_d0 * res_scale) / i2_p_q2_a1_d0;
  412. mag_a1_d1 = (i2_m_q2_a1_d1 * res_scale) / i2_p_q2_a1_d1;
  413. phs_a1_d1 = (iq_corr_a1_d1 * res_scale) / i2_p_q2_a1_d1;
  414. /* w/o analog phase shift */
  415. sin_2phi_1 = (((mag_a0_d0 - mag_a0_d1) * delpt_shift) / DELPT);
  416. /* w/o analog phase shift */
  417. cos_2phi_1 = (((phs_a0_d1 - phs_a0_d0) * delpt_shift) / DELPT);
  418. /* w/ analog phase shift */
  419. sin_2phi_2 = (((mag_a1_d0 - mag_a1_d1) * delpt_shift) / DELPT);
  420. /* w/ analog phase shift */
  421. cos_2phi_2 = (((phs_a1_d1 - phs_a1_d0) * delpt_shift) / DELPT);
  422. /*
  423. * force sin^2 + cos^2 = 1;
  424. * find magnitude by approximation
  425. */
  426. mag1 = ar9003_hw_find_mag_approx(ah, cos_2phi_1, sin_2phi_1);
  427. mag2 = ar9003_hw_find_mag_approx(ah, cos_2phi_2, sin_2phi_2);
  428. if ((mag1 == 0) || (mag2 == 0)) {
  429. ath_dbg(common, ATH_DBG_CALIBRATE,
  430. "Divide by 0: mag1=%d, mag2=%d\n",
  431. mag1, mag2);
  432. return false;
  433. }
  434. /* normalization sin and cos by mag */
  435. sin_2phi_1 = (sin_2phi_1 * res_scale / mag1);
  436. cos_2phi_1 = (cos_2phi_1 * res_scale / mag1);
  437. sin_2phi_2 = (sin_2phi_2 * res_scale / mag2);
  438. cos_2phi_2 = (cos_2phi_2 * res_scale / mag2);
  439. /* calculate IQ mismatch */
  440. if (!ar9003_hw_solve_iq_cal(ah,
  441. sin_2phi_1, cos_2phi_1,
  442. sin_2phi_2, cos_2phi_2,
  443. mag_a0_d0, phs_a0_d0,
  444. mag_a1_d0,
  445. phs_a1_d0, solved_eq)) {
  446. ath_dbg(common, ATH_DBG_CALIBRATE,
  447. "Call to ar9003_hw_solve_iq_cal() failed.\n");
  448. return false;
  449. }
  450. mag_tx = solved_eq[0];
  451. phs_tx = solved_eq[1];
  452. mag_rx = solved_eq[2];
  453. phs_rx = solved_eq[3];
  454. ath_dbg(common, ATH_DBG_CALIBRATE,
  455. "chain %d: mag mismatch=%d phase mismatch=%d\n",
  456. chain_idx, mag_tx/res_scale, phs_tx/res_scale);
  457. if (res_scale == mag_tx) {
  458. ath_dbg(common, ATH_DBG_CALIBRATE,
  459. "Divide by 0: mag_tx=%d, res_scale=%d\n",
  460. mag_tx, res_scale);
  461. return false;
  462. }
  463. /* calculate and quantize Tx IQ correction factor */
  464. mag_corr_tx = (mag_tx * res_scale) / (res_scale - mag_tx);
  465. phs_corr_tx = -phs_tx;
  466. q_q_coff = (mag_corr_tx * 128 / res_scale);
  467. q_i_coff = (phs_corr_tx * 256 / res_scale);
  468. ath_dbg(common, ATH_DBG_CALIBRATE,
  469. "tx chain %d: mag corr=%d phase corr=%d\n",
  470. chain_idx, q_q_coff, q_i_coff);
  471. if (q_i_coff < -63)
  472. q_i_coff = -63;
  473. if (q_i_coff > 63)
  474. q_i_coff = 63;
  475. if (q_q_coff < -63)
  476. q_q_coff = -63;
  477. if (q_q_coff > 63)
  478. q_q_coff = 63;
  479. iqc_coeff[0] = (q_q_coff * 128) + q_i_coff;
  480. ath_dbg(common, ATH_DBG_CALIBRATE,
  481. "tx chain %d: iq corr coeff=%x\n",
  482. chain_idx, iqc_coeff[0]);
  483. if (-mag_rx == res_scale) {
  484. ath_dbg(common, ATH_DBG_CALIBRATE,
  485. "Divide by 0: mag_rx=%d, res_scale=%d\n",
  486. mag_rx, res_scale);
  487. return false;
  488. }
  489. /* calculate and quantize Rx IQ correction factors */
  490. mag_corr_rx = (-mag_rx * res_scale) / (res_scale + mag_rx);
  491. phs_corr_rx = -phs_rx;
  492. q_q_coff = (mag_corr_rx * 128 / res_scale);
  493. q_i_coff = (phs_corr_rx * 256 / res_scale);
  494. ath_dbg(common, ATH_DBG_CALIBRATE,
  495. "rx chain %d: mag corr=%d phase corr=%d\n",
  496. chain_idx, q_q_coff, q_i_coff);
  497. if (q_i_coff < -63)
  498. q_i_coff = -63;
  499. if (q_i_coff > 63)
  500. q_i_coff = 63;
  501. if (q_q_coff < -63)
  502. q_q_coff = -63;
  503. if (q_q_coff > 63)
  504. q_q_coff = 63;
  505. iqc_coeff[1] = (q_q_coff * 128) + q_i_coff;
  506. ath_dbg(common, ATH_DBG_CALIBRATE,
  507. "rx chain %d: iq corr coeff=%x\n",
  508. chain_idx, iqc_coeff[1]);
  509. return true;
  510. }
  511. static void ar9003_hw_tx_iq_cal(struct ath_hw *ah)
  512. {
  513. struct ath_common *common = ath9k_hw_common(ah);
  514. static const u32 txiqcal_status[AR9300_MAX_CHAINS] = {
  515. AR_PHY_TX_IQCAL_STATUS_B0,
  516. AR_PHY_TX_IQCAL_STATUS_B1,
  517. AR_PHY_TX_IQCAL_STATUS_B2,
  518. };
  519. static const u32 rx_corr[AR9300_MAX_CHAINS] = {
  520. AR_PHY_RX_IQCAL_CORR_B0,
  521. AR_PHY_RX_IQCAL_CORR_B1,
  522. AR_PHY_RX_IQCAL_CORR_B2,
  523. };
  524. static const u_int32_t chan_info_tab[] = {
  525. AR_PHY_CHAN_INFO_TAB_0,
  526. AR_PHY_CHAN_INFO_TAB_1,
  527. AR_PHY_CHAN_INFO_TAB_2,
  528. };
  529. u32 tx_corr_coeff[AR9300_MAX_CHAINS];
  530. s32 iq_res[6];
  531. s32 iqc_coeff[2];
  532. s32 i, j;
  533. u32 num_chains = 0;
  534. tx_corr_coeff[0] = AR_PHY_TX_IQCAL_CORR_COEFF_B0(0);
  535. tx_corr_coeff[1] = AR_PHY_TX_IQCAL_CORR_COEFF_B1(0);
  536. tx_corr_coeff[2] = AR_PHY_TX_IQCAL_CORR_COEFF_B2(0);
  537. for (i = 0; i < AR9300_MAX_CHAINS; i++) {
  538. if (ah->txchainmask & (1 << i))
  539. num_chains++;
  540. }
  541. REG_RMW_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_1,
  542. AR_PHY_TX_IQCAQL_CONTROL_1_IQCORR_I_Q_COFF_DELPT,
  543. DELPT);
  544. REG_RMW_FIELD(ah, AR_PHY_TX_IQCAL_START,
  545. AR_PHY_TX_IQCAL_START_DO_CAL,
  546. AR_PHY_TX_IQCAL_START_DO_CAL);
  547. if (!ath9k_hw_wait(ah, AR_PHY_TX_IQCAL_START,
  548. AR_PHY_TX_IQCAL_START_DO_CAL,
  549. 0, AH_WAIT_TIMEOUT)) {
  550. ath_dbg(common, ATH_DBG_CALIBRATE,
  551. "Tx IQ Cal not complete.\n");
  552. goto TX_IQ_CAL_FAILED;
  553. }
  554. for (i = 0; i < num_chains; i++) {
  555. ath_dbg(common, ATH_DBG_CALIBRATE,
  556. "Doing Tx IQ Cal for chain %d.\n", i);
  557. if (REG_READ(ah, txiqcal_status[i]) &
  558. AR_PHY_TX_IQCAL_STATUS_FAILED) {
  559. ath_dbg(common, ATH_DBG_CALIBRATE,
  560. "Tx IQ Cal failed for chain %d.\n", i);
  561. goto TX_IQ_CAL_FAILED;
  562. }
  563. for (j = 0; j < 3; j++) {
  564. u_int8_t idx = 2 * j,
  565. offset = 4 * j;
  566. REG_RMW_FIELD(ah, AR_PHY_CHAN_INFO_MEMORY,
  567. AR_PHY_CHAN_INFO_TAB_S2_READ, 0);
  568. /* 32 bits */
  569. iq_res[idx] = REG_READ(ah, chan_info_tab[i] + offset);
  570. REG_RMW_FIELD(ah, AR_PHY_CHAN_INFO_MEMORY,
  571. AR_PHY_CHAN_INFO_TAB_S2_READ, 1);
  572. /* 16 bits */
  573. iq_res[idx+1] = 0xffff & REG_READ(ah,
  574. chan_info_tab[i] +
  575. offset);
  576. ath_dbg(common, ATH_DBG_CALIBRATE,
  577. "IQ RES[%d]=0x%x IQ_RES[%d]=0x%x\n",
  578. idx, iq_res[idx], idx+1, iq_res[idx+1]);
  579. }
  580. if (!ar9003_hw_calc_iq_corr(ah, i, iq_res, iqc_coeff)) {
  581. ath_dbg(common, ATH_DBG_CALIBRATE,
  582. "Failed in calculation of IQ correction.\n");
  583. goto TX_IQ_CAL_FAILED;
  584. }
  585. ath_dbg(common, ATH_DBG_CALIBRATE,
  586. "IQ_COEFF[0] = 0x%x IQ_COEFF[1] = 0x%x\n",
  587. iqc_coeff[0], iqc_coeff[1]);
  588. REG_RMW_FIELD(ah, tx_corr_coeff[i],
  589. AR_PHY_TX_IQCAL_CORR_COEFF_01_COEFF_TABLE,
  590. iqc_coeff[0]);
  591. REG_RMW_FIELD(ah, rx_corr[i],
  592. AR_PHY_RX_IQCAL_CORR_LOOPBACK_IQCORR_Q_Q_COFF,
  593. iqc_coeff[1] >> 7);
  594. REG_RMW_FIELD(ah, rx_corr[i],
  595. AR_PHY_RX_IQCAL_CORR_LOOPBACK_IQCORR_Q_I_COFF,
  596. iqc_coeff[1]);
  597. }
  598. REG_RMW_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_3,
  599. AR_PHY_TX_IQCAL_CONTROL_3_IQCORR_EN, 0x1);
  600. REG_RMW_FIELD(ah, AR_PHY_RX_IQCAL_CORR_B0,
  601. AR_PHY_RX_IQCAL_CORR_B0_LOOPBACK_IQCORR_EN, 0x1);
  602. return;
  603. TX_IQ_CAL_FAILED:
  604. ath_dbg(common, ATH_DBG_CALIBRATE, "Tx IQ Cal failed\n");
  605. }
  606. static bool ar9003_hw_compute_closest_pass_and_avg(int *mp_coeff, int *mp_avg)
  607. {
  608. int diff[MPASS];
  609. diff[0] = abs(mp_coeff[0] - mp_coeff[1]);
  610. diff[1] = abs(mp_coeff[1] - mp_coeff[2]);
  611. diff[2] = abs(mp_coeff[2] - mp_coeff[0]);
  612. if (diff[0] > MAX_MEASUREMENT &&
  613. diff[1] > MAX_MEASUREMENT &&
  614. diff[2] > MAX_MEASUREMENT)
  615. return false;
  616. if (diff[0] <= diff[1] && diff[0] <= diff[2])
  617. *mp_avg = (mp_coeff[0] + mp_coeff[1]) / 2;
  618. else if (diff[1] <= diff[2])
  619. *mp_avg = (mp_coeff[1] + mp_coeff[2]) / 2;
  620. else
  621. *mp_avg = (mp_coeff[2] + mp_coeff[0]) / 2;
  622. return true;
  623. }
  624. static void ar9003_hw_tx_iqcal_load_avg_2_passes(struct ath_hw *ah,
  625. u8 num_chains,
  626. struct coeff *coeff)
  627. {
  628. struct ath_common *common = ath9k_hw_common(ah);
  629. int i, im, nmeasurement;
  630. int magnitude, phase;
  631. u32 tx_corr_coeff[MAX_MEASUREMENT][AR9300_MAX_CHAINS];
  632. memset(tx_corr_coeff, 0, sizeof(tx_corr_coeff));
  633. for (i = 0; i < MAX_MEASUREMENT / 2; i++) {
  634. tx_corr_coeff[i * 2][0] = tx_corr_coeff[(i * 2) + 1][0] =
  635. AR_PHY_TX_IQCAL_CORR_COEFF_B0(i);
  636. if (!AR_SREV_9485(ah)) {
  637. tx_corr_coeff[i * 2][1] =
  638. tx_corr_coeff[(i * 2) + 1][1] =
  639. AR_PHY_TX_IQCAL_CORR_COEFF_B1(i);
  640. tx_corr_coeff[i * 2][2] =
  641. tx_corr_coeff[(i * 2) + 1][2] =
  642. AR_PHY_TX_IQCAL_CORR_COEFF_B2(i);
  643. }
  644. }
  645. /* Load the average of 2 passes */
  646. for (i = 0; i < num_chains; i++) {
  647. if (AR_SREV_9485(ah))
  648. nmeasurement = REG_READ_FIELD(ah,
  649. AR_PHY_TX_IQCAL_STATUS_B0_9485,
  650. AR_PHY_CALIBRATED_GAINS_0);
  651. else
  652. nmeasurement = REG_READ_FIELD(ah,
  653. AR_PHY_TX_IQCAL_STATUS_B0,
  654. AR_PHY_CALIBRATED_GAINS_0);
  655. if (nmeasurement > MAX_MEASUREMENT)
  656. nmeasurement = MAX_MEASUREMENT;
  657. for (im = 0; im < nmeasurement; im++) {
  658. /*
  659. * Determine which 2 passes are closest and compute avg
  660. * magnitude
  661. */
  662. if (!ar9003_hw_compute_closest_pass_and_avg(coeff->mag_coeff[i][im],
  663. &magnitude))
  664. goto disable_txiqcal;
  665. /*
  666. * Determine which 2 passes are closest and compute avg
  667. * phase
  668. */
  669. if (!ar9003_hw_compute_closest_pass_and_avg(coeff->phs_coeff[i][im],
  670. &phase))
  671. goto disable_txiqcal;
  672. coeff->iqc_coeff[0] = (magnitude & 0x7f) |
  673. ((phase & 0x7f) << 7);
  674. if ((im % 2) == 0)
  675. REG_RMW_FIELD(ah, tx_corr_coeff[im][i],
  676. AR_PHY_TX_IQCAL_CORR_COEFF_00_COEFF_TABLE,
  677. coeff->iqc_coeff[0]);
  678. else
  679. REG_RMW_FIELD(ah, tx_corr_coeff[im][i],
  680. AR_PHY_TX_IQCAL_CORR_COEFF_01_COEFF_TABLE,
  681. coeff->iqc_coeff[0]);
  682. }
  683. }
  684. REG_RMW_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_3,
  685. AR_PHY_TX_IQCAL_CONTROL_3_IQCORR_EN, 0x1);
  686. REG_RMW_FIELD(ah, AR_PHY_RX_IQCAL_CORR_B0,
  687. AR_PHY_RX_IQCAL_CORR_B0_LOOPBACK_IQCORR_EN, 0x1);
  688. return;
  689. disable_txiqcal:
  690. REG_RMW_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_3,
  691. AR_PHY_TX_IQCAL_CONTROL_3_IQCORR_EN, 0x0);
  692. REG_RMW_FIELD(ah, AR_PHY_RX_IQCAL_CORR_B0,
  693. AR_PHY_RX_IQCAL_CORR_B0_LOOPBACK_IQCORR_EN, 0x0);
  694. ath_dbg(common, ATH_DBG_CALIBRATE, "TX IQ Cal disabled\n");
  695. }
  696. static void ar9003_hw_tx_iq_cal_run(struct ath_hw *ah)
  697. {
  698. u8 tx_gain_forced;
  699. REG_RMW_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_1_9485,
  700. AR_PHY_TX_IQCAQL_CONTROL_1_IQCORR_I_Q_COFF_DELPT, DELPT);
  701. tx_gain_forced = REG_READ_FIELD(ah, AR_PHY_TX_FORCED_GAIN,
  702. AR_PHY_TXGAIN_FORCE);
  703. if (tx_gain_forced)
  704. REG_RMW_FIELD(ah, AR_PHY_TX_FORCED_GAIN,
  705. AR_PHY_TXGAIN_FORCE, 0);
  706. REG_RMW_FIELD(ah, AR_PHY_TX_IQCAL_START_9485,
  707. AR_PHY_TX_IQCAL_START_DO_CAL_9485, 1);
  708. }
  709. static void ar9003_hw_tx_iq_cal_post_proc(struct ath_hw *ah)
  710. {
  711. struct ath_common *common = ath9k_hw_common(ah);
  712. const u32 txiqcal_status[AR9300_MAX_CHAINS] = {
  713. AR_PHY_TX_IQCAL_STATUS_B0_9485,
  714. AR_PHY_TX_IQCAL_STATUS_B1,
  715. AR_PHY_TX_IQCAL_STATUS_B2,
  716. };
  717. const u_int32_t chan_info_tab[] = {
  718. AR_PHY_CHAN_INFO_TAB_0,
  719. AR_PHY_CHAN_INFO_TAB_1,
  720. AR_PHY_CHAN_INFO_TAB_2,
  721. };
  722. struct coeff coeff;
  723. s32 iq_res[6];
  724. u8 num_chains = 0;
  725. int i, ip, im, j;
  726. int nmeasurement;
  727. for (i = 0; i < AR9300_MAX_CHAINS; i++) {
  728. if (ah->txchainmask & (1 << i))
  729. num_chains++;
  730. }
  731. for (ip = 0; ip < MPASS; ip++) {
  732. for (i = 0; i < num_chains; i++) {
  733. nmeasurement = REG_READ_FIELD(ah,
  734. AR_PHY_TX_IQCAL_STATUS_B0_9485,
  735. AR_PHY_CALIBRATED_GAINS_0);
  736. if (nmeasurement > MAX_MEASUREMENT)
  737. nmeasurement = MAX_MEASUREMENT;
  738. for (im = 0; im < nmeasurement; im++) {
  739. ath_dbg(common, ATH_DBG_CALIBRATE,
  740. "Doing Tx IQ Cal for chain %d.\n", i);
  741. if (REG_READ(ah, txiqcal_status[i]) &
  742. AR_PHY_TX_IQCAL_STATUS_FAILED) {
  743. ath_dbg(common, ATH_DBG_CALIBRATE,
  744. "Tx IQ Cal failed for chain %d.\n", i);
  745. goto tx_iqcal_fail;
  746. }
  747. for (j = 0; j < 3; j++) {
  748. u32 idx = 2 * j, offset = 4 * (3 * im + j);
  749. REG_RMW_FIELD(ah,
  750. AR_PHY_CHAN_INFO_MEMORY,
  751. AR_PHY_CHAN_INFO_TAB_S2_READ,
  752. 0);
  753. /* 32 bits */
  754. iq_res[idx] = REG_READ(ah,
  755. chan_info_tab[i] +
  756. offset);
  757. REG_RMW_FIELD(ah,
  758. AR_PHY_CHAN_INFO_MEMORY,
  759. AR_PHY_CHAN_INFO_TAB_S2_READ,
  760. 1);
  761. /* 16 bits */
  762. iq_res[idx + 1] = 0xffff & REG_READ(ah,
  763. chan_info_tab[i] + offset);
  764. ath_dbg(common, ATH_DBG_CALIBRATE,
  765. "IQ RES[%d]=0x%x"
  766. "IQ_RES[%d]=0x%x\n",
  767. idx, iq_res[idx], idx + 1,
  768. iq_res[idx + 1]);
  769. }
  770. if (!ar9003_hw_calc_iq_corr(ah, i, iq_res,
  771. coeff.iqc_coeff)) {
  772. ath_dbg(common, ATH_DBG_CALIBRATE,
  773. "Failed in calculation of IQ correction.\n");
  774. goto tx_iqcal_fail;
  775. }
  776. coeff.mag_coeff[i][im][ip] =
  777. coeff.iqc_coeff[0] & 0x7f;
  778. coeff.phs_coeff[i][im][ip] =
  779. (coeff.iqc_coeff[0] >> 7) & 0x7f;
  780. if (coeff.mag_coeff[i][im][ip] > 63)
  781. coeff.mag_coeff[i][im][ip] -= 128;
  782. if (coeff.phs_coeff[i][im][ip] > 63)
  783. coeff.phs_coeff[i][im][ip] -= 128;
  784. }
  785. }
  786. }
  787. ar9003_hw_tx_iqcal_load_avg_2_passes(ah, num_chains, &coeff);
  788. return;
  789. tx_iqcal_fail:
  790. ath_dbg(common, ATH_DBG_CALIBRATE, "Tx IQ Cal failed\n");
  791. return;
  792. }
  793. static bool ar9003_hw_init_cal(struct ath_hw *ah,
  794. struct ath9k_channel *chan)
  795. {
  796. struct ath_common *common = ath9k_hw_common(ah);
  797. int val;
  798. val = REG_READ(ah, AR_ENT_OTP);
  799. ath_dbg(common, ATH_DBG_CALIBRATE, "ath9k: AR_ENT_OTP 0x%x\n", val);
  800. if (AR_SREV_9485(ah))
  801. ar9003_hw_set_chain_masks(ah, 0x1, 0x1);
  802. else if (val & AR_ENT_OTP_CHAIN2_DISABLE)
  803. ar9003_hw_set_chain_masks(ah, 0x3, 0x3);
  804. else
  805. /*
  806. * 0x7 = 0b111 , AR9003 needs to be configured for 3-chain
  807. * mode before running AGC/TxIQ cals
  808. */
  809. ar9003_hw_set_chain_masks(ah, 0x7, 0x7);
  810. /* Do Tx IQ Calibration */
  811. if (AR_SREV_9485(ah))
  812. ar9003_hw_tx_iq_cal_run(ah);
  813. else
  814. ar9003_hw_tx_iq_cal(ah);
  815. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
  816. udelay(5);
  817. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
  818. /* Calibrate the AGC */
  819. REG_WRITE(ah, AR_PHY_AGC_CONTROL,
  820. REG_READ(ah, AR_PHY_AGC_CONTROL) |
  821. AR_PHY_AGC_CONTROL_CAL);
  822. /* Poll for offset calibration complete */
  823. if (!ath9k_hw_wait(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL,
  824. 0, AH_WAIT_TIMEOUT)) {
  825. ath_dbg(common, ATH_DBG_CALIBRATE,
  826. "offset calibration failed to complete in 1ms; noisy environment?\n");
  827. return false;
  828. }
  829. if (AR_SREV_9485(ah))
  830. ar9003_hw_tx_iq_cal_post_proc(ah);
  831. /* Revert chainmasks to their original values before NF cal */
  832. ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
  833. ath9k_hw_start_nfcal(ah, true);
  834. /* Initialize list pointers */
  835. ah->cal_list = ah->cal_list_last = ah->cal_list_curr = NULL;
  836. ah->supp_cals = IQ_MISMATCH_CAL;
  837. if (ah->supp_cals & IQ_MISMATCH_CAL) {
  838. INIT_CAL(&ah->iq_caldata);
  839. INSERT_CAL(ah, &ah->iq_caldata);
  840. ath_dbg(common, ATH_DBG_CALIBRATE,
  841. "enabling IQ Calibration.\n");
  842. }
  843. if (ah->supp_cals & TEMP_COMP_CAL) {
  844. INIT_CAL(&ah->tempCompCalData);
  845. INSERT_CAL(ah, &ah->tempCompCalData);
  846. ath_dbg(common, ATH_DBG_CALIBRATE,
  847. "enabling Temperature Compensation Calibration.\n");
  848. }
  849. /* Initialize current pointer to first element in list */
  850. ah->cal_list_curr = ah->cal_list;
  851. if (ah->cal_list_curr)
  852. ath9k_hw_reset_calibration(ah, ah->cal_list_curr);
  853. if (ah->caldata)
  854. ah->caldata->CalValid = 0;
  855. return true;
  856. }
  857. void ar9003_hw_attach_calib_ops(struct ath_hw *ah)
  858. {
  859. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  860. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  861. priv_ops->init_cal_settings = ar9003_hw_init_cal_settings;
  862. priv_ops->init_cal = ar9003_hw_init_cal;
  863. priv_ops->setup_calibration = ar9003_hw_setup_calibration;
  864. ops->calibrate = ar9003_hw_calibrate;
  865. }