PageRenderTime 1167ms CodeModel.GetById 21ms RepoModel.GetById 2ms app.codeStats 0ms

/drivers/net/wireless/ath/ath9k/ar9002_calib.c

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