ar9002_calib.c 28 KB

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