ar9002_calib.c 29 KB

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