ar9002_calib.c 29 KB

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