ar9002_calib.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  1. /*
  2. * Copyright (c) 2008-2011 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 "ar9002_phy.h"
  19. #define AR9285_CLCAL_REDO_THRESH 1
  20. enum ar9002_cal_types {
  21. ADC_GAIN_CAL = BIT(0),
  22. ADC_DC_CAL = BIT(1),
  23. IQ_MISMATCH_CAL = BIT(2),
  24. };
  25. static bool ar9002_hw_is_cal_supported(struct ath_hw *ah,
  26. struct ath9k_channel *chan,
  27. enum ar9002_cal_types cal_type)
  28. {
  29. bool supported = false;
  30. switch (ah->supp_cals & cal_type) {
  31. case IQ_MISMATCH_CAL:
  32. /* Run IQ Mismatch for non-CCK only */
  33. if (!IS_CHAN_B(chan))
  34. supported = true;
  35. break;
  36. case ADC_GAIN_CAL:
  37. case ADC_DC_CAL:
  38. /* Run ADC Gain Cal for non-CCK & non 2GHz-HT20 only */
  39. if (!IS_CHAN_B(chan) &&
  40. !(IS_CHAN_2GHZ(chan) && IS_CHAN_HT20(chan)))
  41. supported = true;
  42. break;
  43. }
  44. return supported;
  45. }
  46. static void ar9002_hw_setup_calibration(struct ath_hw *ah,
  47. struct ath9k_cal_list *currCal)
  48. {
  49. struct ath_common *common = ath9k_hw_common(ah);
  50. REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(0),
  51. AR_PHY_TIMING_CTRL4_IQCAL_LOG_COUNT_MAX,
  52. currCal->calData->calCountMax);
  53. switch (currCal->calData->calType) {
  54. case IQ_MISMATCH_CAL:
  55. REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_IQ);
  56. ath_dbg(common, ATH_DBG_CALIBRATE,
  57. "starting IQ Mismatch Calibration\n");
  58. break;
  59. case ADC_GAIN_CAL:
  60. REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_ADC_GAIN);
  61. ath_dbg(common, ATH_DBG_CALIBRATE,
  62. "starting ADC Gain Calibration\n");
  63. break;
  64. case ADC_DC_CAL:
  65. REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_ADC_DC_PER);
  66. ath_dbg(common, ATH_DBG_CALIBRATE,
  67. "starting ADC DC Calibration\n");
  68. break;
  69. }
  70. REG_SET_BIT(ah, AR_PHY_TIMING_CTRL4(0),
  71. AR_PHY_TIMING_CTRL4_DO_CAL);
  72. }
  73. static bool ar9002_hw_per_calibration(struct ath_hw *ah,
  74. struct ath9k_channel *ichan,
  75. u8 rxchainmask,
  76. struct ath9k_cal_list *currCal)
  77. {
  78. struct ath9k_hw_cal_data *caldata = ah->caldata;
  79. bool iscaldone = false;
  80. if (currCal->calState == CAL_RUNNING) {
  81. if (!(REG_READ(ah, AR_PHY_TIMING_CTRL4(0)) &
  82. AR_PHY_TIMING_CTRL4_DO_CAL)) {
  83. currCal->calData->calCollect(ah);
  84. ah->cal_samples++;
  85. if (ah->cal_samples >=
  86. currCal->calData->calNumSamples) {
  87. int i, numChains = 0;
  88. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  89. if (rxchainmask & (1 << i))
  90. numChains++;
  91. }
  92. currCal->calData->calPostProc(ah, numChains);
  93. caldata->CalValid |= currCal->calData->calType;
  94. currCal->calState = CAL_DONE;
  95. iscaldone = true;
  96. } else {
  97. ar9002_hw_setup_calibration(ah, currCal);
  98. }
  99. }
  100. } else if (!(caldata->CalValid & currCal->calData->calType)) {
  101. ath9k_hw_reset_calibration(ah, currCal);
  102. }
  103. return iscaldone;
  104. }
  105. static void ar9002_hw_iqcal_collect(struct ath_hw *ah)
  106. {
  107. int i;
  108. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  109. ah->totalPowerMeasI[i] +=
  110. REG_READ(ah, AR_PHY_CAL_MEAS_0(i));
  111. ah->totalPowerMeasQ[i] +=
  112. REG_READ(ah, AR_PHY_CAL_MEAS_1(i));
  113. ah->totalIqCorrMeas[i] +=
  114. (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_2(i));
  115. ath_dbg(ath9k_hw_common(ah), ATH_DBG_CALIBRATE,
  116. "%d: Chn %d pmi=0x%08x;pmq=0x%08x;iqcm=0x%08x;\n",
  117. ah->cal_samples, i, ah->totalPowerMeasI[i],
  118. ah->totalPowerMeasQ[i],
  119. ah->totalIqCorrMeas[i]);
  120. }
  121. }
  122. static void ar9002_hw_adc_gaincal_collect(struct ath_hw *ah)
  123. {
  124. int i;
  125. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  126. ah->totalAdcIOddPhase[i] +=
  127. REG_READ(ah, AR_PHY_CAL_MEAS_0(i));
  128. ah->totalAdcIEvenPhase[i] +=
  129. REG_READ(ah, AR_PHY_CAL_MEAS_1(i));
  130. ah->totalAdcQOddPhase[i] +=
  131. REG_READ(ah, AR_PHY_CAL_MEAS_2(i));
  132. ah->totalAdcQEvenPhase[i] +=
  133. REG_READ(ah, AR_PHY_CAL_MEAS_3(i));
  134. ath_dbg(ath9k_hw_common(ah), ATH_DBG_CALIBRATE,
  135. "%d: Chn %d oddi=0x%08x; eveni=0x%08x; oddq=0x%08x; evenq=0x%08x;\n",
  136. ah->cal_samples, i,
  137. ah->totalAdcIOddPhase[i],
  138. ah->totalAdcIEvenPhase[i],
  139. ah->totalAdcQOddPhase[i],
  140. ah->totalAdcQEvenPhase[i]);
  141. }
  142. }
  143. static void ar9002_hw_adc_dccal_collect(struct ath_hw *ah)
  144. {
  145. int i;
  146. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  147. ah->totalAdcDcOffsetIOddPhase[i] +=
  148. (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_0(i));
  149. ah->totalAdcDcOffsetIEvenPhase[i] +=
  150. (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_1(i));
  151. ah->totalAdcDcOffsetQOddPhase[i] +=
  152. (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_2(i));
  153. ah->totalAdcDcOffsetQEvenPhase[i] +=
  154. (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_3(i));
  155. ath_dbg(ath9k_hw_common(ah), ATH_DBG_CALIBRATE,
  156. "%d: Chn %d oddi=0x%08x; eveni=0x%08x; oddq=0x%08x; evenq=0x%08x;\n",
  157. ah->cal_samples, i,
  158. ah->totalAdcDcOffsetIOddPhase[i],
  159. ah->totalAdcDcOffsetIEvenPhase[i],
  160. ah->totalAdcDcOffsetQOddPhase[i],
  161. ah->totalAdcDcOffsetQEvenPhase[i]);
  162. }
  163. }
  164. static void ar9002_hw_iqcalibrate(struct ath_hw *ah, u8 numChains)
  165. {
  166. struct ath_common *common = ath9k_hw_common(ah);
  167. u32 powerMeasQ, powerMeasI, iqCorrMeas;
  168. u32 qCoffDenom, iCoffDenom;
  169. int32_t qCoff, iCoff;
  170. int iqCorrNeg, i;
  171. for (i = 0; i < numChains; i++) {
  172. powerMeasI = ah->totalPowerMeasI[i];
  173. powerMeasQ = ah->totalPowerMeasQ[i];
  174. iqCorrMeas = ah->totalIqCorrMeas[i];
  175. ath_dbg(common, ATH_DBG_CALIBRATE,
  176. "Starting IQ Cal and Correction for Chain %d\n",
  177. i);
  178. ath_dbg(common, ATH_DBG_CALIBRATE,
  179. "Orignal: Chn %diq_corr_meas = 0x%08x\n",
  180. i, ah->totalIqCorrMeas[i]);
  181. iqCorrNeg = 0;
  182. if (iqCorrMeas > 0x80000000) {
  183. iqCorrMeas = (0xffffffff - iqCorrMeas) + 1;
  184. iqCorrNeg = 1;
  185. }
  186. ath_dbg(common, ATH_DBG_CALIBRATE,
  187. "Chn %d pwr_meas_i = 0x%08x\n", i, powerMeasI);
  188. ath_dbg(common, ATH_DBG_CALIBRATE,
  189. "Chn %d pwr_meas_q = 0x%08x\n", i, powerMeasQ);
  190. ath_dbg(common, ATH_DBG_CALIBRATE, "iqCorrNeg is 0x%08x\n",
  191. iqCorrNeg);
  192. iCoffDenom = (powerMeasI / 2 + powerMeasQ / 2) / 128;
  193. qCoffDenom = powerMeasQ / 64;
  194. if ((powerMeasQ != 0) && (iCoffDenom != 0) &&
  195. (qCoffDenom != 0)) {
  196. iCoff = iqCorrMeas / iCoffDenom;
  197. qCoff = powerMeasI / qCoffDenom - 64;
  198. ath_dbg(common, ATH_DBG_CALIBRATE,
  199. "Chn %d iCoff = 0x%08x\n", i, iCoff);
  200. ath_dbg(common, ATH_DBG_CALIBRATE,
  201. "Chn %d qCoff = 0x%08x\n", i, qCoff);
  202. iCoff = iCoff & 0x3f;
  203. ath_dbg(common, ATH_DBG_CALIBRATE,
  204. "New: Chn %d iCoff = 0x%08x\n", i, iCoff);
  205. if (iqCorrNeg == 0x0)
  206. iCoff = 0x40 - iCoff;
  207. if (qCoff > 15)
  208. qCoff = 15;
  209. else if (qCoff <= -16)
  210. qCoff = -16;
  211. ath_dbg(common, ATH_DBG_CALIBRATE,
  212. "Chn %d : iCoff = 0x%x qCoff = 0x%x\n",
  213. i, iCoff, qCoff);
  214. REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(i),
  215. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF,
  216. iCoff);
  217. REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(i),
  218. AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF,
  219. qCoff);
  220. ath_dbg(common, ATH_DBG_CALIBRATE,
  221. "IQ Cal and Correction done for Chain %d\n",
  222. i);
  223. }
  224. }
  225. REG_SET_BIT(ah, AR_PHY_TIMING_CTRL4(0),
  226. AR_PHY_TIMING_CTRL4_IQCORR_ENABLE);
  227. }
  228. static void ar9002_hw_adc_gaincal_calibrate(struct ath_hw *ah, u8 numChains)
  229. {
  230. struct ath_common *common = ath9k_hw_common(ah);
  231. u32 iOddMeasOffset, iEvenMeasOffset, qOddMeasOffset, qEvenMeasOffset;
  232. u32 qGainMismatch, iGainMismatch, val, i;
  233. for (i = 0; i < numChains; i++) {
  234. iOddMeasOffset = ah->totalAdcIOddPhase[i];
  235. iEvenMeasOffset = ah->totalAdcIEvenPhase[i];
  236. qOddMeasOffset = ah->totalAdcQOddPhase[i];
  237. qEvenMeasOffset = ah->totalAdcQEvenPhase[i];
  238. ath_dbg(common, ATH_DBG_CALIBRATE,
  239. "Starting ADC Gain Cal for Chain %d\n", i);
  240. ath_dbg(common, ATH_DBG_CALIBRATE,
  241. "Chn %d pwr_meas_odd_i = 0x%08x\n", i,
  242. iOddMeasOffset);
  243. ath_dbg(common, ATH_DBG_CALIBRATE,
  244. "Chn %d pwr_meas_even_i = 0x%08x\n", i,
  245. iEvenMeasOffset);
  246. ath_dbg(common, ATH_DBG_CALIBRATE,
  247. "Chn %d pwr_meas_odd_q = 0x%08x\n", i,
  248. qOddMeasOffset);
  249. ath_dbg(common, ATH_DBG_CALIBRATE,
  250. "Chn %d pwr_meas_even_q = 0x%08x\n", i,
  251. qEvenMeasOffset);
  252. if (iOddMeasOffset != 0 && qEvenMeasOffset != 0) {
  253. iGainMismatch =
  254. ((iEvenMeasOffset * 32) /
  255. iOddMeasOffset) & 0x3f;
  256. qGainMismatch =
  257. ((qOddMeasOffset * 32) /
  258. qEvenMeasOffset) & 0x3f;
  259. ath_dbg(common, ATH_DBG_CALIBRATE,
  260. "Chn %d gain_mismatch_i = 0x%08x\n", i,
  261. iGainMismatch);
  262. ath_dbg(common, ATH_DBG_CALIBRATE,
  263. "Chn %d gain_mismatch_q = 0x%08x\n", i,
  264. qGainMismatch);
  265. val = REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i));
  266. val &= 0xfffff000;
  267. val |= (qGainMismatch) | (iGainMismatch << 6);
  268. REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i), val);
  269. ath_dbg(common, ATH_DBG_CALIBRATE,
  270. "ADC Gain Cal done for Chain %d\n", i);
  271. }
  272. }
  273. REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0),
  274. REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0)) |
  275. AR_PHY_NEW_ADC_GAIN_CORR_ENABLE);
  276. }
  277. static void ar9002_hw_adc_dccal_calibrate(struct ath_hw *ah, u8 numChains)
  278. {
  279. struct ath_common *common = ath9k_hw_common(ah);
  280. u32 iOddMeasOffset, iEvenMeasOffset, val, i;
  281. int32_t qOddMeasOffset, qEvenMeasOffset, qDcMismatch, iDcMismatch;
  282. const struct ath9k_percal_data *calData =
  283. ah->cal_list_curr->calData;
  284. u32 numSamples =
  285. (1 << (calData->calCountMax + 5)) * calData->calNumSamples;
  286. for (i = 0; i < numChains; i++) {
  287. iOddMeasOffset = ah->totalAdcDcOffsetIOddPhase[i];
  288. iEvenMeasOffset = ah->totalAdcDcOffsetIEvenPhase[i];
  289. qOddMeasOffset = ah->totalAdcDcOffsetQOddPhase[i];
  290. qEvenMeasOffset = ah->totalAdcDcOffsetQEvenPhase[i];
  291. ath_dbg(common, ATH_DBG_CALIBRATE,
  292. "Starting ADC DC Offset Cal for Chain %d\n", i);
  293. ath_dbg(common, ATH_DBG_CALIBRATE,
  294. "Chn %d pwr_meas_odd_i = %d\n", i,
  295. iOddMeasOffset);
  296. ath_dbg(common, ATH_DBG_CALIBRATE,
  297. "Chn %d pwr_meas_even_i = %d\n", i,
  298. iEvenMeasOffset);
  299. ath_dbg(common, ATH_DBG_CALIBRATE,
  300. "Chn %d pwr_meas_odd_q = %d\n", i,
  301. qOddMeasOffset);
  302. ath_dbg(common, ATH_DBG_CALIBRATE,
  303. "Chn %d pwr_meas_even_q = %d\n", i,
  304. qEvenMeasOffset);
  305. iDcMismatch = (((iEvenMeasOffset - iOddMeasOffset) * 2) /
  306. numSamples) & 0x1ff;
  307. qDcMismatch = (((qOddMeasOffset - qEvenMeasOffset) * 2) /
  308. numSamples) & 0x1ff;
  309. ath_dbg(common, ATH_DBG_CALIBRATE,
  310. "Chn %d dc_offset_mismatch_i = 0x%08x\n", i,
  311. iDcMismatch);
  312. ath_dbg(common, ATH_DBG_CALIBRATE,
  313. "Chn %d dc_offset_mismatch_q = 0x%08x\n", i,
  314. qDcMismatch);
  315. val = REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i));
  316. val &= 0xc0000fff;
  317. val |= (qDcMismatch << 12) | (iDcMismatch << 21);
  318. REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i), val);
  319. ath_dbg(common, ATH_DBG_CALIBRATE,
  320. "ADC DC Offset Cal done for Chain %d\n", i);
  321. }
  322. REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0),
  323. REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0)) |
  324. AR_PHY_NEW_ADC_DC_OFFSET_CORR_ENABLE);
  325. }
  326. static void ar9287_hw_olc_temp_compensation(struct ath_hw *ah)
  327. {
  328. u32 rddata;
  329. int32_t delta, currPDADC, slope;
  330. rddata = REG_READ(ah, AR_PHY_TX_PWRCTRL4);
  331. currPDADC = MS(rddata, AR_PHY_TX_PWRCTRL_PD_AVG_OUT);
  332. if (ah->initPDADC == 0 || currPDADC == 0) {
  333. /*
  334. * Zero value indicates that no frames have been transmitted
  335. * yet, can't do temperature compensation until frames are
  336. * transmitted.
  337. */
  338. return;
  339. } else {
  340. slope = ah->eep_ops->get_eeprom(ah, EEP_TEMPSENSE_SLOPE);
  341. if (slope == 0) { /* to avoid divide by zero case */
  342. delta = 0;
  343. } else {
  344. delta = ((currPDADC - ah->initPDADC)*4) / slope;
  345. }
  346. REG_RMW_FIELD(ah, AR_PHY_CH0_TX_PWRCTRL11,
  347. AR_PHY_TX_PWRCTRL_OLPC_TEMP_COMP, delta);
  348. REG_RMW_FIELD(ah, AR_PHY_CH1_TX_PWRCTRL11,
  349. AR_PHY_TX_PWRCTRL_OLPC_TEMP_COMP, delta);
  350. }
  351. }
  352. static void ar9280_hw_olc_temp_compensation(struct ath_hw *ah)
  353. {
  354. u32 rddata, i;
  355. int delta, currPDADC, regval;
  356. rddata = REG_READ(ah, AR_PHY_TX_PWRCTRL4);
  357. currPDADC = MS(rddata, AR_PHY_TX_PWRCTRL_PD_AVG_OUT);
  358. if (ah->initPDADC == 0 || currPDADC == 0)
  359. return;
  360. if (ah->eep_ops->get_eeprom(ah, EEP_DAC_HPWR_5G))
  361. delta = (currPDADC - ah->initPDADC + 4) / 8;
  362. else
  363. delta = (currPDADC - ah->initPDADC + 5) / 10;
  364. if (delta != ah->PDADCdelta) {
  365. ah->PDADCdelta = delta;
  366. for (i = 1; i < AR9280_TX_GAIN_TABLE_SIZE; i++) {
  367. regval = ah->originalGain[i] - delta;
  368. if (regval < 0)
  369. regval = 0;
  370. REG_RMW_FIELD(ah,
  371. AR_PHY_TX_GAIN_TBL1 + i * 4,
  372. AR_PHY_TX_GAIN, regval);
  373. }
  374. }
  375. }
  376. static void ar9271_hw_pa_cal(struct ath_hw *ah, bool is_reset)
  377. {
  378. u32 regVal;
  379. unsigned int i;
  380. u32 regList[][2] = {
  381. { 0x786c, 0 },
  382. { 0x7854, 0 },
  383. { 0x7820, 0 },
  384. { 0x7824, 0 },
  385. { 0x7868, 0 },
  386. { 0x783c, 0 },
  387. { 0x7838, 0 } ,
  388. { 0x7828, 0 } ,
  389. };
  390. for (i = 0; i < ARRAY_SIZE(regList); i++)
  391. regList[i][1] = REG_READ(ah, regList[i][0]);
  392. regVal = REG_READ(ah, 0x7834);
  393. regVal &= (~(0x1));
  394. REG_WRITE(ah, 0x7834, regVal);
  395. regVal = REG_READ(ah, 0x9808);
  396. regVal |= (0x1 << 27);
  397. REG_WRITE(ah, 0x9808, regVal);
  398. /* 786c,b23,1, pwddac=1 */
  399. REG_RMW_FIELD(ah, AR9285_AN_TOP3, AR9285_AN_TOP3_PWDDAC, 1);
  400. /* 7854, b5,1, pdrxtxbb=1 */
  401. REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDRXTXBB1, 1);
  402. /* 7854, b7,1, pdv2i=1 */
  403. REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDV2I, 1);
  404. /* 7854, b8,1, pddacinterface=1 */
  405. REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDDACIF, 1);
  406. /* 7824,b12,0, offcal=0 */
  407. REG_RMW_FIELD(ah, AR9285_AN_RF2G2, AR9285_AN_RF2G2_OFFCAL, 0);
  408. /* 7838, b1,0, pwddb=0 */
  409. REG_RMW_FIELD(ah, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PWDDB, 0);
  410. /* 7820,b11,0, enpacal=0 */
  411. REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_ENPACAL, 0);
  412. /* 7820,b25,1, pdpadrv1=0 */
  413. REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV1, 0);
  414. /* 7820,b24,0, pdpadrv2=0 */
  415. REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV2, 0);
  416. /* 7820,b23,0, pdpaout=0 */
  417. REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPAOUT, 0);
  418. /* 783c,b14-16,7, padrvgn2tab_0=7 */
  419. REG_RMW_FIELD(ah, AR9285_AN_RF2G8, AR9285_AN_RF2G8_PADRVGN2TAB0, 7);
  420. /*
  421. * 7838,b29-31,0, padrvgn1tab_0=0
  422. * does not matter since we turn it off
  423. */
  424. REG_RMW_FIELD(ah, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PADRVGN2TAB0, 0);
  425. REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9271_AN_RF2G3_CCOMP, 0xfff);
  426. /* Set:
  427. * localmode=1,bmode=1,bmoderxtx=1,synthon=1,
  428. * txon=1,paon=1,oscon=1,synthon_force=1
  429. */
  430. REG_WRITE(ah, AR9285_AN_TOP2, 0xca0358a0);
  431. udelay(30);
  432. REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9271_AN_RF2G6_OFFS, 0);
  433. /* find off_6_1; */
  434. for (i = 6; i > 0; i--) {
  435. regVal = REG_READ(ah, 0x7834);
  436. regVal |= (1 << (20 + i));
  437. REG_WRITE(ah, 0x7834, regVal);
  438. udelay(1);
  439. /* regVal = REG_READ(ah, 0x7834); */
  440. regVal &= (~(0x1 << (20 + i)));
  441. regVal |= (MS(REG_READ(ah, 0x7840), AR9285_AN_RXTXBB1_SPARE9)
  442. << (20 + i));
  443. REG_WRITE(ah, 0x7834, regVal);
  444. }
  445. regVal = (regVal >> 20) & 0x7f;
  446. /* Update PA cal info */
  447. if ((!is_reset) && (ah->pacal_info.prev_offset == regVal)) {
  448. if (ah->pacal_info.max_skipcount < MAX_PACAL_SKIPCOUNT)
  449. ah->pacal_info.max_skipcount =
  450. 2 * ah->pacal_info.max_skipcount;
  451. ah->pacal_info.skipcount = ah->pacal_info.max_skipcount;
  452. } else {
  453. ah->pacal_info.max_skipcount = 1;
  454. ah->pacal_info.skipcount = 0;
  455. ah->pacal_info.prev_offset = regVal;
  456. }
  457. ENABLE_REGWRITE_BUFFER(ah);
  458. regVal = REG_READ(ah, 0x7834);
  459. regVal |= 0x1;
  460. REG_WRITE(ah, 0x7834, regVal);
  461. regVal = REG_READ(ah, 0x9808);
  462. regVal &= (~(0x1 << 27));
  463. REG_WRITE(ah, 0x9808, regVal);
  464. for (i = 0; i < ARRAY_SIZE(regList); i++)
  465. REG_WRITE(ah, regList[i][0], regList[i][1]);
  466. REGWRITE_BUFFER_FLUSH(ah);
  467. }
  468. static inline void ar9285_hw_pa_cal(struct ath_hw *ah, bool is_reset)
  469. {
  470. struct ath_common *common = ath9k_hw_common(ah);
  471. u32 regVal;
  472. int i, offset, offs_6_1, offs_0;
  473. u32 ccomp_org, reg_field;
  474. u32 regList[][2] = {
  475. { 0x786c, 0 },
  476. { 0x7854, 0 },
  477. { 0x7820, 0 },
  478. { 0x7824, 0 },
  479. { 0x7868, 0 },
  480. { 0x783c, 0 },
  481. { 0x7838, 0 },
  482. };
  483. ath_dbg(common, ATH_DBG_CALIBRATE, "Running PA Calibration\n");
  484. /* PA CAL is not needed for high power solution */
  485. if (ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE) ==
  486. AR5416_EEP_TXGAIN_HIGH_POWER)
  487. return;
  488. for (i = 0; i < ARRAY_SIZE(regList); i++)
  489. regList[i][1] = REG_READ(ah, regList[i][0]);
  490. regVal = REG_READ(ah, 0x7834);
  491. regVal &= (~(0x1));
  492. REG_WRITE(ah, 0x7834, regVal);
  493. regVal = REG_READ(ah, 0x9808);
  494. regVal |= (0x1 << 27);
  495. REG_WRITE(ah, 0x9808, regVal);
  496. REG_RMW_FIELD(ah, AR9285_AN_TOP3, AR9285_AN_TOP3_PWDDAC, 1);
  497. REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDRXTXBB1, 1);
  498. REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDV2I, 1);
  499. REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDDACIF, 1);
  500. REG_RMW_FIELD(ah, AR9285_AN_RF2G2, AR9285_AN_RF2G2_OFFCAL, 0);
  501. REG_RMW_FIELD(ah, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PWDDB, 0);
  502. REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_ENPACAL, 0);
  503. REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV1, 0);
  504. REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV2, 0);
  505. REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPAOUT, 0);
  506. REG_RMW_FIELD(ah, AR9285_AN_RF2G8, AR9285_AN_RF2G8_PADRVGN2TAB0, 7);
  507. REG_RMW_FIELD(ah, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PADRVGN2TAB0, 0);
  508. ccomp_org = MS(REG_READ(ah, AR9285_AN_RF2G6), AR9285_AN_RF2G6_CCOMP);
  509. REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_CCOMP, 0xf);
  510. REG_WRITE(ah, AR9285_AN_TOP2, 0xca0358a0);
  511. udelay(30);
  512. REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_OFFS, 0);
  513. REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, 0);
  514. for (i = 6; i > 0; i--) {
  515. regVal = REG_READ(ah, 0x7834);
  516. regVal |= (1 << (19 + i));
  517. REG_WRITE(ah, 0x7834, regVal);
  518. udelay(1);
  519. regVal = REG_READ(ah, 0x7834);
  520. regVal &= (~(0x1 << (19 + i)));
  521. reg_field = MS(REG_READ(ah, 0x7840), AR9285_AN_RXTXBB1_SPARE9);
  522. regVal |= (reg_field << (19 + i));
  523. REG_WRITE(ah, 0x7834, regVal);
  524. }
  525. REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, 1);
  526. udelay(1);
  527. reg_field = MS(REG_READ(ah, AR9285_AN_RF2G9), AR9285_AN_RXTXBB1_SPARE9);
  528. REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, reg_field);
  529. offs_6_1 = MS(REG_READ(ah, AR9285_AN_RF2G6), AR9285_AN_RF2G6_OFFS);
  530. offs_0 = MS(REG_READ(ah, AR9285_AN_RF2G3), AR9285_AN_RF2G3_PDVCCOMP);
  531. offset = (offs_6_1<<1) | offs_0;
  532. offset = offset - 0;
  533. offs_6_1 = offset>>1;
  534. offs_0 = offset & 1;
  535. if ((!is_reset) && (ah->pacal_info.prev_offset == offset)) {
  536. if (ah->pacal_info.max_skipcount < MAX_PACAL_SKIPCOUNT)
  537. ah->pacal_info.max_skipcount =
  538. 2 * ah->pacal_info.max_skipcount;
  539. ah->pacal_info.skipcount = ah->pacal_info.max_skipcount;
  540. } else {
  541. ah->pacal_info.max_skipcount = 1;
  542. ah->pacal_info.skipcount = 0;
  543. ah->pacal_info.prev_offset = offset;
  544. }
  545. REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_OFFS, offs_6_1);
  546. REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, offs_0);
  547. regVal = REG_READ(ah, 0x7834);
  548. regVal |= 0x1;
  549. REG_WRITE(ah, 0x7834, regVal);
  550. regVal = REG_READ(ah, 0x9808);
  551. regVal &= (~(0x1 << 27));
  552. REG_WRITE(ah, 0x9808, regVal);
  553. for (i = 0; i < ARRAY_SIZE(regList); i++)
  554. REG_WRITE(ah, regList[i][0], regList[i][1]);
  555. REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_CCOMP, ccomp_org);
  556. }
  557. static void ar9002_hw_pa_cal(struct ath_hw *ah, bool is_reset)
  558. {
  559. if (AR_SREV_9271(ah)) {
  560. if (is_reset || !ah->pacal_info.skipcount)
  561. ar9271_hw_pa_cal(ah, is_reset);
  562. else
  563. ah->pacal_info.skipcount--;
  564. } else if (AR_SREV_9285_12_OR_LATER(ah)) {
  565. if (is_reset || !ah->pacal_info.skipcount)
  566. ar9285_hw_pa_cal(ah, is_reset);
  567. else
  568. ah->pacal_info.skipcount--;
  569. }
  570. }
  571. static void ar9002_hw_olc_temp_compensation(struct ath_hw *ah)
  572. {
  573. if (OLC_FOR_AR9287_10_LATER)
  574. ar9287_hw_olc_temp_compensation(ah);
  575. else if (OLC_FOR_AR9280_20_LATER)
  576. ar9280_hw_olc_temp_compensation(ah);
  577. }
  578. static bool ar9002_hw_calibrate(struct ath_hw *ah,
  579. struct ath9k_channel *chan,
  580. u8 rxchainmask,
  581. bool longcal)
  582. {
  583. bool iscaldone = true;
  584. struct ath9k_cal_list *currCal = ah->cal_list_curr;
  585. bool nfcal, nfcal_pending = false;
  586. nfcal = !!(REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF);
  587. if (ah->caldata)
  588. nfcal_pending = ah->caldata->nfcal_pending;
  589. if (currCal && !nfcal &&
  590. (currCal->calState == CAL_RUNNING ||
  591. currCal->calState == CAL_WAITING)) {
  592. iscaldone = ar9002_hw_per_calibration(ah, chan,
  593. rxchainmask, currCal);
  594. if (iscaldone) {
  595. ah->cal_list_curr = currCal = currCal->calNext;
  596. if (currCal->calState == CAL_WAITING) {
  597. iscaldone = false;
  598. ath9k_hw_reset_calibration(ah, currCal);
  599. }
  600. }
  601. }
  602. /* Do NF cal only at longer intervals */
  603. if (longcal || nfcal_pending) {
  604. /*
  605. * Get the value from the previous NF cal and update
  606. * history buffer.
  607. */
  608. if (ath9k_hw_getnf(ah, chan)) {
  609. /*
  610. * Load the NF from history buffer of the current
  611. * channel.
  612. * NF is slow time-variant, so it is OK to use a
  613. * historical value.
  614. */
  615. ath9k_hw_loadnf(ah, ah->curchan);
  616. }
  617. if (longcal) {
  618. ath9k_hw_start_nfcal(ah, false);
  619. /* Do periodic PAOffset Cal */
  620. ar9002_hw_pa_cal(ah, false);
  621. ar9002_hw_olc_temp_compensation(ah);
  622. }
  623. }
  624. return iscaldone;
  625. }
  626. /* Carrier leakage Calibration fix */
  627. static bool ar9285_hw_cl_cal(struct ath_hw *ah, struct ath9k_channel *chan)
  628. {
  629. struct ath_common *common = ath9k_hw_common(ah);
  630. REG_SET_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_CL_CAL_ENABLE);
  631. if (IS_CHAN_HT20(chan)) {
  632. REG_SET_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_PARALLEL_CAL_ENABLE);
  633. REG_SET_BIT(ah, AR_PHY_TURBO, AR_PHY_FC_DYN2040_EN);
  634. REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
  635. AR_PHY_AGC_CONTROL_FLTR_CAL);
  636. REG_CLR_BIT(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_CAL_ENABLE);
  637. REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL);
  638. if (!ath9k_hw_wait(ah, AR_PHY_AGC_CONTROL,
  639. AR_PHY_AGC_CONTROL_CAL, 0, AH_WAIT_TIMEOUT)) {
  640. ath_dbg(common, ATH_DBG_CALIBRATE,
  641. "offset calibration failed to complete in 1ms; noisy environment?\n");
  642. return false;
  643. }
  644. REG_CLR_BIT(ah, AR_PHY_TURBO, AR_PHY_FC_DYN2040_EN);
  645. REG_CLR_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_PARALLEL_CAL_ENABLE);
  646. REG_CLR_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_CL_CAL_ENABLE);
  647. }
  648. REG_CLR_BIT(ah, AR_PHY_ADC_CTL, AR_PHY_ADC_CTL_OFF_PWDADC);
  649. REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_FLTR_CAL);
  650. REG_SET_BIT(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_CAL_ENABLE);
  651. REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL);
  652. if (!ath9k_hw_wait(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL,
  653. 0, AH_WAIT_TIMEOUT)) {
  654. ath_dbg(common, ATH_DBG_CALIBRATE,
  655. "offset calibration failed to complete in 1ms; noisy environment?\n");
  656. return false;
  657. }
  658. REG_SET_BIT(ah, AR_PHY_ADC_CTL, AR_PHY_ADC_CTL_OFF_PWDADC);
  659. REG_CLR_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_CL_CAL_ENABLE);
  660. REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_FLTR_CAL);
  661. return true;
  662. }
  663. static bool ar9285_hw_clc(struct ath_hw *ah, struct ath9k_channel *chan)
  664. {
  665. int i;
  666. u_int32_t txgain_max;
  667. u_int32_t clc_gain, gain_mask = 0, clc_num = 0;
  668. u_int32_t reg_clc_I0, reg_clc_Q0;
  669. u_int32_t i0_num = 0;
  670. u_int32_t q0_num = 0;
  671. u_int32_t total_num = 0;
  672. u_int32_t reg_rf2g5_org;
  673. bool retv = true;
  674. if (!(ar9285_hw_cl_cal(ah, chan)))
  675. return false;
  676. txgain_max = MS(REG_READ(ah, AR_PHY_TX_PWRCTRL7),
  677. AR_PHY_TX_PWRCTRL_TX_GAIN_TAB_MAX);
  678. for (i = 0; i < (txgain_max+1); i++) {
  679. clc_gain = (REG_READ(ah, (AR_PHY_TX_GAIN_TBL1+(i<<2))) &
  680. AR_PHY_TX_GAIN_CLC) >> AR_PHY_TX_GAIN_CLC_S;
  681. if (!(gain_mask & (1 << clc_gain))) {
  682. gain_mask |= (1 << clc_gain);
  683. clc_num++;
  684. }
  685. }
  686. for (i = 0; i < clc_num; i++) {
  687. reg_clc_I0 = (REG_READ(ah, (AR_PHY_CLC_TBL1 + (i << 2)))
  688. & AR_PHY_CLC_I0) >> AR_PHY_CLC_I0_S;
  689. reg_clc_Q0 = (REG_READ(ah, (AR_PHY_CLC_TBL1 + (i << 2)))
  690. & AR_PHY_CLC_Q0) >> AR_PHY_CLC_Q0_S;
  691. if (reg_clc_I0 == 0)
  692. i0_num++;
  693. if (reg_clc_Q0 == 0)
  694. q0_num++;
  695. }
  696. total_num = i0_num + q0_num;
  697. if (total_num > AR9285_CLCAL_REDO_THRESH) {
  698. reg_rf2g5_org = REG_READ(ah, AR9285_RF2G5);
  699. if (AR_SREV_9285E_20(ah)) {
  700. REG_WRITE(ah, AR9285_RF2G5,
  701. (reg_rf2g5_org & AR9285_RF2G5_IC50TX) |
  702. AR9285_RF2G5_IC50TX_XE_SET);
  703. } else {
  704. REG_WRITE(ah, AR9285_RF2G5,
  705. (reg_rf2g5_org & AR9285_RF2G5_IC50TX) |
  706. AR9285_RF2G5_IC50TX_SET);
  707. }
  708. retv = ar9285_hw_cl_cal(ah, chan);
  709. REG_WRITE(ah, AR9285_RF2G5, reg_rf2g5_org);
  710. }
  711. return retv;
  712. }
  713. static bool ar9002_hw_init_cal(struct ath_hw *ah, struct ath9k_channel *chan)
  714. {
  715. struct ath_common *common = ath9k_hw_common(ah);
  716. if (AR_SREV_9271(ah)) {
  717. if (!ar9285_hw_cl_cal(ah, chan))
  718. return false;
  719. } else if (AR_SREV_9285(ah) && AR_SREV_9285_12_OR_LATER(ah)) {
  720. if (!ar9285_hw_clc(ah, chan))
  721. return false;
  722. } else {
  723. if (AR_SREV_9280_20_OR_LATER(ah)) {
  724. if (!AR_SREV_9287_11_OR_LATER(ah))
  725. REG_CLR_BIT(ah, AR_PHY_ADC_CTL,
  726. AR_PHY_ADC_CTL_OFF_PWDADC);
  727. REG_SET_BIT(ah, AR_PHY_AGC_CONTROL,
  728. AR_PHY_AGC_CONTROL_FLTR_CAL);
  729. }
  730. /* Calibrate the AGC */
  731. REG_WRITE(ah, AR_PHY_AGC_CONTROL,
  732. REG_READ(ah, AR_PHY_AGC_CONTROL) |
  733. AR_PHY_AGC_CONTROL_CAL);
  734. /* Poll for offset calibration complete */
  735. if (!ath9k_hw_wait(ah, AR_PHY_AGC_CONTROL,
  736. AR_PHY_AGC_CONTROL_CAL,
  737. 0, AH_WAIT_TIMEOUT)) {
  738. ath_dbg(common, ATH_DBG_CALIBRATE,
  739. "offset calibration failed to complete in 1ms; noisy environment?\n");
  740. return false;
  741. }
  742. if (AR_SREV_9280_20_OR_LATER(ah)) {
  743. if (!AR_SREV_9287_11_OR_LATER(ah))
  744. REG_SET_BIT(ah, AR_PHY_ADC_CTL,
  745. AR_PHY_ADC_CTL_OFF_PWDADC);
  746. REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
  747. AR_PHY_AGC_CONTROL_FLTR_CAL);
  748. }
  749. }
  750. /* Do PA Calibration */
  751. ar9002_hw_pa_cal(ah, true);
  752. /* Do NF Calibration after DC offset and other calibrations */
  753. ath9k_hw_start_nfcal(ah, true);
  754. if (ah->caldata)
  755. ah->caldata->nfcal_pending = true;
  756. ah->cal_list = ah->cal_list_last = ah->cal_list_curr = NULL;
  757. /* Enable IQ, ADC Gain and ADC DC offset CALs */
  758. if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah)) {
  759. ah->supp_cals = IQ_MISMATCH_CAL;
  760. if (AR_SREV_9160_10_OR_LATER(ah))
  761. ah->supp_cals |= ADC_GAIN_CAL | ADC_DC_CAL;
  762. if (AR_SREV_9287(ah))
  763. ah->supp_cals &= ~ADC_GAIN_CAL;
  764. if (ar9002_hw_is_cal_supported(ah, chan, ADC_GAIN_CAL)) {
  765. INIT_CAL(&ah->adcgain_caldata);
  766. INSERT_CAL(ah, &ah->adcgain_caldata);
  767. ath_dbg(common, ATH_DBG_CALIBRATE,
  768. "enabling ADC Gain Calibration.\n");
  769. }
  770. if (ar9002_hw_is_cal_supported(ah, chan, ADC_DC_CAL)) {
  771. INIT_CAL(&ah->adcdc_caldata);
  772. INSERT_CAL(ah, &ah->adcdc_caldata);
  773. ath_dbg(common, ATH_DBG_CALIBRATE,
  774. "enabling ADC DC Calibration.\n");
  775. }
  776. if (ar9002_hw_is_cal_supported(ah, chan, IQ_MISMATCH_CAL)) {
  777. INIT_CAL(&ah->iq_caldata);
  778. INSERT_CAL(ah, &ah->iq_caldata);
  779. ath_dbg(common, ATH_DBG_CALIBRATE,
  780. "enabling IQ Calibration.\n");
  781. }
  782. ah->cal_list_curr = ah->cal_list;
  783. if (ah->cal_list_curr)
  784. ath9k_hw_reset_calibration(ah, ah->cal_list_curr);
  785. }
  786. if (ah->caldata)
  787. ah->caldata->CalValid = 0;
  788. return true;
  789. }
  790. static const struct ath9k_percal_data iq_cal_multi_sample = {
  791. IQ_MISMATCH_CAL,
  792. MAX_CAL_SAMPLES,
  793. PER_MIN_LOG_COUNT,
  794. ar9002_hw_iqcal_collect,
  795. ar9002_hw_iqcalibrate
  796. };
  797. static const struct ath9k_percal_data iq_cal_single_sample = {
  798. IQ_MISMATCH_CAL,
  799. MIN_CAL_SAMPLES,
  800. PER_MAX_LOG_COUNT,
  801. ar9002_hw_iqcal_collect,
  802. ar9002_hw_iqcalibrate
  803. };
  804. static const struct ath9k_percal_data adc_gain_cal_multi_sample = {
  805. ADC_GAIN_CAL,
  806. MAX_CAL_SAMPLES,
  807. PER_MIN_LOG_COUNT,
  808. ar9002_hw_adc_gaincal_collect,
  809. ar9002_hw_adc_gaincal_calibrate
  810. };
  811. static const struct ath9k_percal_data adc_gain_cal_single_sample = {
  812. ADC_GAIN_CAL,
  813. MIN_CAL_SAMPLES,
  814. PER_MAX_LOG_COUNT,
  815. ar9002_hw_adc_gaincal_collect,
  816. ar9002_hw_adc_gaincal_calibrate
  817. };
  818. static const struct ath9k_percal_data adc_dc_cal_multi_sample = {
  819. ADC_DC_CAL,
  820. MAX_CAL_SAMPLES,
  821. PER_MIN_LOG_COUNT,
  822. ar9002_hw_adc_dccal_collect,
  823. ar9002_hw_adc_dccal_calibrate
  824. };
  825. static const struct ath9k_percal_data adc_dc_cal_single_sample = {
  826. ADC_DC_CAL,
  827. MIN_CAL_SAMPLES,
  828. PER_MAX_LOG_COUNT,
  829. ar9002_hw_adc_dccal_collect,
  830. ar9002_hw_adc_dccal_calibrate
  831. };
  832. static void ar9002_hw_init_cal_settings(struct ath_hw *ah)
  833. {
  834. if (AR_SREV_9100(ah)) {
  835. ah->iq_caldata.calData = &iq_cal_multi_sample;
  836. ah->supp_cals = IQ_MISMATCH_CAL;
  837. return;
  838. }
  839. if (AR_SREV_9160_10_OR_LATER(ah)) {
  840. if (AR_SREV_9280_20_OR_LATER(ah)) {
  841. ah->iq_caldata.calData = &iq_cal_single_sample;
  842. ah->adcgain_caldata.calData =
  843. &adc_gain_cal_single_sample;
  844. ah->adcdc_caldata.calData =
  845. &adc_dc_cal_single_sample;
  846. } else {
  847. ah->iq_caldata.calData = &iq_cal_multi_sample;
  848. ah->adcgain_caldata.calData =
  849. &adc_gain_cal_multi_sample;
  850. ah->adcdc_caldata.calData =
  851. &adc_dc_cal_multi_sample;
  852. }
  853. ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
  854. if (AR_SREV_9287(ah))
  855. ah->supp_cals &= ~ADC_GAIN_CAL;
  856. }
  857. }
  858. void ar9002_hw_attach_calib_ops(struct ath_hw *ah)
  859. {
  860. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  861. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  862. priv_ops->init_cal_settings = ar9002_hw_init_cal_settings;
  863. priv_ops->init_cal = ar9002_hw_init_cal;
  864. priv_ops->setup_calibration = ar9002_hw_setup_calibration;
  865. ops->calibrate = ar9002_hw_calibrate;
  866. }