ar9002_calib.c 28 KB

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