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. 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. { 0x786c, 0 },
  369. { 0x7854, 0 },
  370. { 0x7820, 0 },
  371. { 0x7824, 0 },
  372. { 0x7868, 0 },
  373. { 0x783c, 0 },
  374. { 0x7838, 0 } ,
  375. { 0x7828, 0 } ,
  376. };
  377. for (i = 0; i < ARRAY_SIZE(regList); i++)
  378. regList[i][1] = REG_READ(ah, regList[i][0]);
  379. regVal = REG_READ(ah, 0x7834);
  380. regVal &= (~(0x1));
  381. REG_WRITE(ah, 0x7834, regVal);
  382. regVal = REG_READ(ah, 0x9808);
  383. regVal |= (0x1 << 27);
  384. REG_WRITE(ah, 0x9808, regVal);
  385. /* 786c,b23,1, pwddac=1 */
  386. REG_RMW_FIELD(ah, AR9285_AN_TOP3, AR9285_AN_TOP3_PWDDAC, 1);
  387. /* 7854, b5,1, pdrxtxbb=1 */
  388. REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDRXTXBB1, 1);
  389. /* 7854, b7,1, pdv2i=1 */
  390. REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDV2I, 1);
  391. /* 7854, b8,1, pddacinterface=1 */
  392. REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDDACIF, 1);
  393. /* 7824,b12,0, offcal=0 */
  394. REG_RMW_FIELD(ah, AR9285_AN_RF2G2, AR9285_AN_RF2G2_OFFCAL, 0);
  395. /* 7838, b1,0, pwddb=0 */
  396. REG_RMW_FIELD(ah, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PWDDB, 0);
  397. /* 7820,b11,0, enpacal=0 */
  398. REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_ENPACAL, 0);
  399. /* 7820,b25,1, pdpadrv1=0 */
  400. REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV1, 0);
  401. /* 7820,b24,0, pdpadrv2=0 */
  402. REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV2, 0);
  403. /* 7820,b23,0, pdpaout=0 */
  404. REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPAOUT, 0);
  405. /* 783c,b14-16,7, padrvgn2tab_0=7 */
  406. REG_RMW_FIELD(ah, AR9285_AN_RF2G8, AR9285_AN_RF2G8_PADRVGN2TAB0, 7);
  407. /*
  408. * 7838,b29-31,0, padrvgn1tab_0=0
  409. * does not matter since we turn it off
  410. */
  411. REG_RMW_FIELD(ah, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PADRVGN2TAB0, 0);
  412. REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9271_AN_RF2G3_CCOMP, 0xfff);
  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, 0x7834);
  423. regVal |= (1 << (20 + i));
  424. REG_WRITE(ah, 0x7834, regVal);
  425. udelay(1);
  426. /* regVal = REG_READ(ah, 0x7834); */
  427. regVal &= (~(0x1 << (20 + i)));
  428. regVal |= (MS(REG_READ(ah, 0x7840), AR9285_AN_RXTXBB1_SPARE9)
  429. << (20 + i));
  430. REG_WRITE(ah, 0x7834, regVal);
  431. }
  432. regVal = (regVal >> 20) & 0x7f;
  433. /* Update PA cal info */
  434. if ((!is_reset) && (ah->pacal_info.prev_offset == regVal)) {
  435. if (ah->pacal_info.max_skipcount < MAX_PACAL_SKIPCOUNT)
  436. ah->pacal_info.max_skipcount =
  437. 2 * ah->pacal_info.max_skipcount;
  438. ah->pacal_info.skipcount = ah->pacal_info.max_skipcount;
  439. } else {
  440. ah->pacal_info.max_skipcount = 1;
  441. ah->pacal_info.skipcount = 0;
  442. ah->pacal_info.prev_offset = regVal;
  443. }
  444. ENABLE_REGWRITE_BUFFER(ah);
  445. regVal = REG_READ(ah, 0x7834);
  446. regVal |= 0x1;
  447. REG_WRITE(ah, 0x7834, regVal);
  448. regVal = REG_READ(ah, 0x9808);
  449. regVal &= (~(0x1 << 27));
  450. REG_WRITE(ah, 0x9808, regVal);
  451. for (i = 0; i < ARRAY_SIZE(regList); i++)
  452. REG_WRITE(ah, regList[i][0], regList[i][1]);
  453. REGWRITE_BUFFER_FLUSH(ah);
  454. }
  455. static inline void ar9285_hw_pa_cal(struct ath_hw *ah, bool is_reset)
  456. {
  457. struct ath_common *common = ath9k_hw_common(ah);
  458. u32 regVal;
  459. int i, offset, offs_6_1, offs_0;
  460. u32 ccomp_org, reg_field;
  461. u32 regList[][2] = {
  462. { 0x786c, 0 },
  463. { 0x7854, 0 },
  464. { 0x7820, 0 },
  465. { 0x7824, 0 },
  466. { 0x7868, 0 },
  467. { 0x783c, 0 },
  468. { 0x7838, 0 },
  469. };
  470. ath_dbg(common, CALIBRATE, "Running PA Calibration\n");
  471. /* PA CAL is not needed for high power solution */
  472. if (ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE) ==
  473. AR5416_EEP_TXGAIN_HIGH_POWER)
  474. return;
  475. for (i = 0; i < ARRAY_SIZE(regList); i++)
  476. regList[i][1] = REG_READ(ah, regList[i][0]);
  477. regVal = REG_READ(ah, 0x7834);
  478. regVal &= (~(0x1));
  479. REG_WRITE(ah, 0x7834, regVal);
  480. regVal = REG_READ(ah, 0x9808);
  481. regVal |= (0x1 << 27);
  482. REG_WRITE(ah, 0x9808, regVal);
  483. REG_RMW_FIELD(ah, AR9285_AN_TOP3, AR9285_AN_TOP3_PWDDAC, 1);
  484. REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDRXTXBB1, 1);
  485. REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDV2I, 1);
  486. REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDDACIF, 1);
  487. REG_RMW_FIELD(ah, AR9285_AN_RF2G2, AR9285_AN_RF2G2_OFFCAL, 0);
  488. REG_RMW_FIELD(ah, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PWDDB, 0);
  489. REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_ENPACAL, 0);
  490. REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV1, 0);
  491. REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV2, 0);
  492. REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPAOUT, 0);
  493. REG_RMW_FIELD(ah, AR9285_AN_RF2G8, AR9285_AN_RF2G8_PADRVGN2TAB0, 7);
  494. REG_RMW_FIELD(ah, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PADRVGN2TAB0, 0);
  495. ccomp_org = MS(REG_READ(ah, AR9285_AN_RF2G6), AR9285_AN_RF2G6_CCOMP);
  496. REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_CCOMP, 0xf);
  497. REG_WRITE(ah, AR9285_AN_TOP2, 0xca0358a0);
  498. udelay(30);
  499. REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_OFFS, 0);
  500. REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, 0);
  501. for (i = 6; i > 0; i--) {
  502. regVal = REG_READ(ah, 0x7834);
  503. regVal |= (1 << (19 + i));
  504. REG_WRITE(ah, 0x7834, regVal);
  505. udelay(1);
  506. regVal = REG_READ(ah, 0x7834);
  507. regVal &= (~(0x1 << (19 + i)));
  508. reg_field = MS(REG_READ(ah, 0x7840), AR9285_AN_RXTXBB1_SPARE9);
  509. regVal |= (reg_field << (19 + i));
  510. REG_WRITE(ah, 0x7834, regVal);
  511. }
  512. REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, 1);
  513. udelay(1);
  514. reg_field = MS(REG_READ(ah, AR9285_AN_RF2G9), AR9285_AN_RXTXBB1_SPARE9);
  515. REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, reg_field);
  516. offs_6_1 = MS(REG_READ(ah, AR9285_AN_RF2G6), AR9285_AN_RF2G6_OFFS);
  517. offs_0 = MS(REG_READ(ah, AR9285_AN_RF2G3), AR9285_AN_RF2G3_PDVCCOMP);
  518. offset = (offs_6_1<<1) | offs_0;
  519. offset = offset - 0;
  520. offs_6_1 = offset>>1;
  521. offs_0 = offset & 1;
  522. if ((!is_reset) && (ah->pacal_info.prev_offset == offset)) {
  523. if (ah->pacal_info.max_skipcount < MAX_PACAL_SKIPCOUNT)
  524. ah->pacal_info.max_skipcount =
  525. 2 * ah->pacal_info.max_skipcount;
  526. ah->pacal_info.skipcount = ah->pacal_info.max_skipcount;
  527. } else {
  528. ah->pacal_info.max_skipcount = 1;
  529. ah->pacal_info.skipcount = 0;
  530. ah->pacal_info.prev_offset = offset;
  531. }
  532. REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_OFFS, offs_6_1);
  533. REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, offs_0);
  534. regVal = REG_READ(ah, 0x7834);
  535. regVal |= 0x1;
  536. REG_WRITE(ah, 0x7834, regVal);
  537. regVal = REG_READ(ah, 0x9808);
  538. regVal &= (~(0x1 << 27));
  539. REG_WRITE(ah, 0x9808, regVal);
  540. for (i = 0; i < ARRAY_SIZE(regList); i++)
  541. REG_WRITE(ah, regList[i][0], regList[i][1]);
  542. REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_CCOMP, ccomp_org);
  543. }
  544. static void ar9002_hw_pa_cal(struct ath_hw *ah, bool is_reset)
  545. {
  546. if (AR_SREV_9271(ah)) {
  547. if (is_reset || !ah->pacal_info.skipcount)
  548. ar9271_hw_pa_cal(ah, is_reset);
  549. else
  550. ah->pacal_info.skipcount--;
  551. } else if (AR_SREV_9285_12_OR_LATER(ah)) {
  552. if (is_reset || !ah->pacal_info.skipcount)
  553. ar9285_hw_pa_cal(ah, is_reset);
  554. else
  555. ah->pacal_info.skipcount--;
  556. }
  557. }
  558. static void ar9002_hw_olc_temp_compensation(struct ath_hw *ah)
  559. {
  560. if (OLC_FOR_AR9287_10_LATER)
  561. ar9287_hw_olc_temp_compensation(ah);
  562. else if (OLC_FOR_AR9280_20_LATER)
  563. ar9280_hw_olc_temp_compensation(ah);
  564. }
  565. static bool ar9002_hw_calibrate(struct ath_hw *ah,
  566. struct ath9k_channel *chan,
  567. u8 rxchainmask,
  568. bool longcal)
  569. {
  570. bool iscaldone = true;
  571. struct ath9k_cal_list *currCal = ah->cal_list_curr;
  572. bool nfcal, nfcal_pending = false;
  573. nfcal = !!(REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF);
  574. if (ah->caldata)
  575. nfcal_pending = test_bit(NFCAL_PENDING, &ah->caldata->cal_flags);
  576. if (currCal && !nfcal &&
  577. (currCal->calState == CAL_RUNNING ||
  578. currCal->calState == CAL_WAITING)) {
  579. iscaldone = ar9002_hw_per_calibration(ah, chan,
  580. rxchainmask, currCal);
  581. if (iscaldone) {
  582. ah->cal_list_curr = currCal = currCal->calNext;
  583. if (currCal->calState == CAL_WAITING) {
  584. iscaldone = false;
  585. ath9k_hw_reset_calibration(ah, currCal);
  586. }
  587. }
  588. }
  589. /* Do NF cal only at longer intervals */
  590. if (longcal || nfcal_pending) {
  591. /*
  592. * Get the value from the previous NF cal and update
  593. * history buffer.
  594. */
  595. if (ath9k_hw_getnf(ah, chan)) {
  596. /*
  597. * Load the NF from history buffer of the current
  598. * channel.
  599. * NF is slow time-variant, so it is OK to use a
  600. * historical value.
  601. */
  602. ath9k_hw_loadnf(ah, ah->curchan);
  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 iscaldone;
  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. if (ah->caldata)
  743. set_bit(NFCAL_PENDING, &ah->caldata->cal_flags);
  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. }