Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ath9k_ar9002_calib.c 28KB

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