ar9002_calib.c 28 KB

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