ar9002_calib.c 29 KB

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