ar9003_paprd.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989
  1. /*
  2. * Copyright (c) 2010-2011 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/export.h>
  17. #include "hw.h"
  18. #include "ar9003_phy.h"
  19. void ar9003_paprd_enable(struct ath_hw *ah, bool val)
  20. {
  21. struct ath9k_channel *chan = ah->curchan;
  22. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  23. /*
  24. * 3 bits for modalHeader5G.papdRateMaskHt20
  25. * is used for sub-band disabling of PAPRD.
  26. * 5G band is divided into 3 sub-bands -- upper,
  27. * middle, lower.
  28. * if bit 30 of modalHeader5G.papdRateMaskHt20 is set
  29. * -- disable PAPRD for upper band 5GHz
  30. * if bit 29 of modalHeader5G.papdRateMaskHt20 is set
  31. * -- disable PAPRD for middle band 5GHz
  32. * if bit 28 of modalHeader5G.papdRateMaskHt20 is set
  33. * -- disable PAPRD for lower band 5GHz
  34. */
  35. if (IS_CHAN_5GHZ(chan)) {
  36. if (chan->channel >= UPPER_5G_SUB_BAND_START) {
  37. if (le32_to_cpu(eep->modalHeader5G.papdRateMaskHt20)
  38. & BIT(30))
  39. val = false;
  40. } else if (chan->channel >= MID_5G_SUB_BAND_START) {
  41. if (le32_to_cpu(eep->modalHeader5G.papdRateMaskHt20)
  42. & BIT(29))
  43. val = false;
  44. } else {
  45. if (le32_to_cpu(eep->modalHeader5G.papdRateMaskHt20)
  46. & BIT(28))
  47. val = false;
  48. }
  49. }
  50. if (val) {
  51. ah->paprd_table_write_done = true;
  52. ath9k_hw_apply_txpower(ah, chan, false);
  53. }
  54. REG_RMW_FIELD(ah, AR_PHY_PAPRD_CTRL0_B0,
  55. AR_PHY_PAPRD_CTRL0_PAPRD_ENABLE, !!val);
  56. if (ah->caps.tx_chainmask & BIT(1))
  57. REG_RMW_FIELD(ah, AR_PHY_PAPRD_CTRL0_B1,
  58. AR_PHY_PAPRD_CTRL0_PAPRD_ENABLE, !!val);
  59. if (ah->caps.tx_chainmask & BIT(2))
  60. REG_RMW_FIELD(ah, AR_PHY_PAPRD_CTRL0_B2,
  61. AR_PHY_PAPRD_CTRL0_PAPRD_ENABLE, !!val);
  62. }
  63. EXPORT_SYMBOL(ar9003_paprd_enable);
  64. static int ar9003_get_training_power_2g(struct ath_hw *ah)
  65. {
  66. struct ath9k_channel *chan = ah->curchan;
  67. unsigned int power, scale, delta;
  68. scale = ar9003_get_paprd_scale_factor(ah, chan);
  69. power = REG_READ_FIELD(ah, AR_PHY_POWERTX_RATE5,
  70. AR_PHY_POWERTX_RATE5_POWERTXHT20_0);
  71. delta = abs((int) ah->paprd_target_power - (int) power);
  72. if (delta > scale)
  73. return -1;
  74. if (delta < 4)
  75. power -= 4 - delta;
  76. return power;
  77. }
  78. static int ar9003_get_training_power_5g(struct ath_hw *ah)
  79. {
  80. struct ath_common *common = ath9k_hw_common(ah);
  81. struct ath9k_channel *chan = ah->curchan;
  82. unsigned int power, scale, delta;
  83. scale = ar9003_get_paprd_scale_factor(ah, chan);
  84. if (IS_CHAN_HT40(chan))
  85. power = REG_READ_FIELD(ah, AR_PHY_POWERTX_RATE8,
  86. AR_PHY_POWERTX_RATE8_POWERTXHT40_5);
  87. else
  88. power = REG_READ_FIELD(ah, AR_PHY_POWERTX_RATE6,
  89. AR_PHY_POWERTX_RATE6_POWERTXHT20_5);
  90. power += scale;
  91. delta = abs((int) ah->paprd_target_power - (int) power);
  92. if (delta > scale)
  93. return -1;
  94. switch (get_streams(ah->txchainmask)) {
  95. case 1:
  96. delta = 6;
  97. break;
  98. case 2:
  99. delta = 4;
  100. break;
  101. case 3:
  102. delta = 2;
  103. break;
  104. default:
  105. delta = 0;
  106. ath_dbg(common, CALIBRATE, "Invalid tx-chainmask: %u\n",
  107. ah->txchainmask);
  108. }
  109. power += delta;
  110. return power;
  111. }
  112. static int ar9003_paprd_setup_single_table(struct ath_hw *ah)
  113. {
  114. struct ath_common *common = ath9k_hw_common(ah);
  115. static const u32 ctrl0[3] = {
  116. AR_PHY_PAPRD_CTRL0_B0,
  117. AR_PHY_PAPRD_CTRL0_B1,
  118. AR_PHY_PAPRD_CTRL0_B2
  119. };
  120. static const u32 ctrl1[3] = {
  121. AR_PHY_PAPRD_CTRL1_B0,
  122. AR_PHY_PAPRD_CTRL1_B1,
  123. AR_PHY_PAPRD_CTRL1_B2
  124. };
  125. int training_power;
  126. int i, val;
  127. u32 am2pm_mask = ah->paprd_ratemask;
  128. if (IS_CHAN_2GHZ(ah->curchan))
  129. training_power = ar9003_get_training_power_2g(ah);
  130. else
  131. training_power = ar9003_get_training_power_5g(ah);
  132. ath_dbg(common, CALIBRATE, "Training power: %d, Target power: %d\n",
  133. training_power, ah->paprd_target_power);
  134. if (training_power < 0) {
  135. ath_dbg(common, CALIBRATE,
  136. "PAPRD target power delta out of range\n");
  137. return -ERANGE;
  138. }
  139. ah->paprd_training_power = training_power;
  140. if (AR_SREV_9330(ah))
  141. am2pm_mask = 0;
  142. REG_RMW_FIELD(ah, AR_PHY_PAPRD_AM2AM, AR_PHY_PAPRD_AM2AM_MASK,
  143. ah->paprd_ratemask);
  144. REG_RMW_FIELD(ah, AR_PHY_PAPRD_AM2PM, AR_PHY_PAPRD_AM2PM_MASK,
  145. am2pm_mask);
  146. REG_RMW_FIELD(ah, AR_PHY_PAPRD_HT40, AR_PHY_PAPRD_HT40_MASK,
  147. ah->paprd_ratemask_ht40);
  148. ath_dbg(common, CALIBRATE, "PAPRD HT20 mask: 0x%x, HT40 mask: 0x%x\n",
  149. ah->paprd_ratemask, ah->paprd_ratemask_ht40);
  150. for (i = 0; i < ah->caps.max_txchains; i++) {
  151. REG_RMW_FIELD(ah, ctrl0[i],
  152. AR_PHY_PAPRD_CTRL0_USE_SINGLE_TABLE_MASK, 1);
  153. REG_RMW_FIELD(ah, ctrl1[i],
  154. AR_PHY_PAPRD_CTRL1_ADAPTIVE_AM2PM_ENABLE, 1);
  155. REG_RMW_FIELD(ah, ctrl1[i],
  156. AR_PHY_PAPRD_CTRL1_ADAPTIVE_AM2AM_ENABLE, 1);
  157. REG_RMW_FIELD(ah, ctrl1[i],
  158. AR_PHY_PAPRD_CTRL1_ADAPTIVE_SCALING_ENA, 0);
  159. REG_RMW_FIELD(ah, ctrl1[i],
  160. AR_PHY_PAPRD_CTRL1_PA_GAIN_SCALE_FACT_MASK, 181);
  161. REG_RMW_FIELD(ah, ctrl1[i],
  162. AR_PHY_PAPRD_CTRL1_PAPRD_MAG_SCALE_FACT, 361);
  163. REG_RMW_FIELD(ah, ctrl1[i],
  164. AR_PHY_PAPRD_CTRL1_ADAPTIVE_SCALING_ENA, 0);
  165. REG_RMW_FIELD(ah, ctrl0[i],
  166. AR_PHY_PAPRD_CTRL0_PAPRD_MAG_THRSH, 3);
  167. }
  168. ar9003_paprd_enable(ah, false);
  169. REG_RMW_FIELD(ah, AR_PHY_PAPRD_TRAINER_CNTL1,
  170. AR_PHY_PAPRD_TRAINER_CNTL1_CF_PAPRD_LB_SKIP, 0x30);
  171. REG_RMW_FIELD(ah, AR_PHY_PAPRD_TRAINER_CNTL1,
  172. AR_PHY_PAPRD_TRAINER_CNTL1_CF_PAPRD_LB_ENABLE, 1);
  173. REG_RMW_FIELD(ah, AR_PHY_PAPRD_TRAINER_CNTL1,
  174. AR_PHY_PAPRD_TRAINER_CNTL1_CF_PAPRD_TX_GAIN_FORCE, 1);
  175. REG_RMW_FIELD(ah, AR_PHY_PAPRD_TRAINER_CNTL1,
  176. AR_PHY_PAPRD_TRAINER_CNTL1_CF_PAPRD_RX_BB_GAIN_FORCE, 0);
  177. REG_RMW_FIELD(ah, AR_PHY_PAPRD_TRAINER_CNTL1,
  178. AR_PHY_PAPRD_TRAINER_CNTL1_CF_PAPRD_IQCORR_ENABLE, 0);
  179. REG_RMW_FIELD(ah, AR_PHY_PAPRD_TRAINER_CNTL1,
  180. AR_PHY_PAPRD_TRAINER_CNTL1_CF_PAPRD_AGC2_SETTLING, 28);
  181. REG_RMW_FIELD(ah, AR_PHY_PAPRD_TRAINER_CNTL1,
  182. AR_PHY_PAPRD_TRAINER_CNTL1_CF_CF_PAPRD_TRAIN_ENABLE, 1);
  183. if (AR_SREV_9485(ah)) {
  184. val = 148;
  185. } else {
  186. if (IS_CHAN_2GHZ(ah->curchan)) {
  187. if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
  188. val = 145;
  189. else
  190. val = 147;
  191. } else {
  192. val = 137;
  193. }
  194. }
  195. REG_RMW_FIELD(ah, AR_PHY_PAPRD_TRAINER_CNTL2,
  196. AR_PHY_PAPRD_TRAINER_CNTL2_CF_PAPRD_INIT_RX_BB_GAIN, val);
  197. REG_RMW_FIELD(ah, AR_PHY_PAPRD_TRAINER_CNTL3,
  198. AR_PHY_PAPRD_TRAINER_CNTL3_CF_PAPRD_FINE_CORR_LEN, 4);
  199. REG_RMW_FIELD(ah, AR_PHY_PAPRD_TRAINER_CNTL3,
  200. AR_PHY_PAPRD_TRAINER_CNTL3_CF_PAPRD_COARSE_CORR_LEN, 4);
  201. REG_RMW_FIELD(ah, AR_PHY_PAPRD_TRAINER_CNTL3,
  202. AR_PHY_PAPRD_TRAINER_CNTL3_CF_PAPRD_NUM_CORR_STAGES, 7);
  203. REG_RMW_FIELD(ah, AR_PHY_PAPRD_TRAINER_CNTL3,
  204. AR_PHY_PAPRD_TRAINER_CNTL3_CF_PAPRD_MIN_LOOPBACK_DEL, 1);
  205. if (AR_SREV_9485(ah) ||
  206. AR_SREV_9462(ah) ||
  207. AR_SREV_9565(ah) ||
  208. AR_SREV_9550(ah) ||
  209. AR_SREV_9330(ah) ||
  210. AR_SREV_9340(ah))
  211. REG_RMW_FIELD(ah, AR_PHY_PAPRD_TRAINER_CNTL3,
  212. AR_PHY_PAPRD_TRAINER_CNTL3_CF_PAPRD_QUICK_DROP, -3);
  213. else
  214. REG_RMW_FIELD(ah, AR_PHY_PAPRD_TRAINER_CNTL3,
  215. AR_PHY_PAPRD_TRAINER_CNTL3_CF_PAPRD_QUICK_DROP, -6);
  216. val = -10;
  217. if (IS_CHAN_2GHZ(ah->curchan) && !AR_SREV_9462(ah) && !AR_SREV_9565(ah))
  218. val = -15;
  219. REG_RMW_FIELD(ah, AR_PHY_PAPRD_TRAINER_CNTL3,
  220. AR_PHY_PAPRD_TRAINER_CNTL3_CF_PAPRD_ADC_DESIRED_SIZE,
  221. val);
  222. REG_RMW_FIELD(ah, AR_PHY_PAPRD_TRAINER_CNTL3,
  223. AR_PHY_PAPRD_TRAINER_CNTL3_CF_PAPRD_BBTXMIX_DISABLE, 1);
  224. REG_RMW_FIELD(ah, AR_PHY_PAPRD_TRAINER_CNTL4,
  225. AR_PHY_PAPRD_TRAINER_CNTL4_CF_PAPRD_SAFETY_DELTA, 0);
  226. REG_RMW_FIELD(ah, AR_PHY_PAPRD_TRAINER_CNTL4,
  227. AR_PHY_PAPRD_TRAINER_CNTL4_CF_PAPRD_MIN_CORR, 400);
  228. REG_RMW_FIELD(ah, AR_PHY_PAPRD_TRAINER_CNTL4,
  229. AR_PHY_PAPRD_TRAINER_CNTL4_CF_PAPRD_NUM_TRAIN_SAMPLES,
  230. 100);
  231. REG_RMW_FIELD(ah, AR_PHY_PAPRD_PRE_POST_SCALE_0_B0,
  232. AR_PHY_PAPRD_PRE_POST_SCALING, 261376);
  233. REG_RMW_FIELD(ah, AR_PHY_PAPRD_PRE_POST_SCALE_1_B0,
  234. AR_PHY_PAPRD_PRE_POST_SCALING, 248079);
  235. REG_RMW_FIELD(ah, AR_PHY_PAPRD_PRE_POST_SCALE_2_B0,
  236. AR_PHY_PAPRD_PRE_POST_SCALING, 233759);
  237. REG_RMW_FIELD(ah, AR_PHY_PAPRD_PRE_POST_SCALE_3_B0,
  238. AR_PHY_PAPRD_PRE_POST_SCALING, 220464);
  239. REG_RMW_FIELD(ah, AR_PHY_PAPRD_PRE_POST_SCALE_4_B0,
  240. AR_PHY_PAPRD_PRE_POST_SCALING, 208194);
  241. REG_RMW_FIELD(ah, AR_PHY_PAPRD_PRE_POST_SCALE_5_B0,
  242. AR_PHY_PAPRD_PRE_POST_SCALING, 196949);
  243. REG_RMW_FIELD(ah, AR_PHY_PAPRD_PRE_POST_SCALE_6_B0,
  244. AR_PHY_PAPRD_PRE_POST_SCALING, 185706);
  245. REG_RMW_FIELD(ah, AR_PHY_PAPRD_PRE_POST_SCALE_7_B0,
  246. AR_PHY_PAPRD_PRE_POST_SCALING, 175487);
  247. return 0;
  248. }
  249. static void ar9003_paprd_get_gain_table(struct ath_hw *ah)
  250. {
  251. u32 *entry = ah->paprd_gain_table_entries;
  252. u8 *index = ah->paprd_gain_table_index;
  253. u32 reg = AR_PHY_TXGAIN_TABLE;
  254. int i;
  255. for (i = 0; i < PAPRD_GAIN_TABLE_ENTRIES; i++) {
  256. entry[i] = REG_READ(ah, reg);
  257. index[i] = (entry[i] >> 24) & 0xff;
  258. reg += 4;
  259. }
  260. }
  261. static unsigned int ar9003_get_desired_gain(struct ath_hw *ah, int chain,
  262. int target_power)
  263. {
  264. int olpc_gain_delta = 0, cl_gain_mod;
  265. int alpha_therm, alpha_volt;
  266. int therm_cal_value, volt_cal_value;
  267. int therm_value, volt_value;
  268. int thermal_gain_corr, voltage_gain_corr;
  269. int desired_scale, desired_gain = 0;
  270. u32 reg_olpc = 0, reg_cl_gain = 0;
  271. REG_CLR_BIT(ah, AR_PHY_PAPRD_TRAINER_STAT1,
  272. AR_PHY_PAPRD_TRAINER_STAT1_PAPRD_TRAIN_DONE);
  273. desired_scale = REG_READ_FIELD(ah, AR_PHY_TPC_12,
  274. AR_PHY_TPC_12_DESIRED_SCALE_HT40_5);
  275. alpha_therm = REG_READ_FIELD(ah, AR_PHY_TPC_19,
  276. AR_PHY_TPC_19_ALPHA_THERM);
  277. alpha_volt = REG_READ_FIELD(ah, AR_PHY_TPC_19,
  278. AR_PHY_TPC_19_ALPHA_VOLT);
  279. therm_cal_value = REG_READ_FIELD(ah, AR_PHY_TPC_18,
  280. AR_PHY_TPC_18_THERM_CAL_VALUE);
  281. volt_cal_value = REG_READ_FIELD(ah, AR_PHY_TPC_18,
  282. AR_PHY_TPC_18_VOLT_CAL_VALUE);
  283. therm_value = REG_READ_FIELD(ah, AR_PHY_BB_THERM_ADC_4,
  284. AR_PHY_BB_THERM_ADC_4_LATEST_THERM_VALUE);
  285. volt_value = REG_READ_FIELD(ah, AR_PHY_BB_THERM_ADC_4,
  286. AR_PHY_BB_THERM_ADC_4_LATEST_VOLT_VALUE);
  287. switch (chain) {
  288. case 0:
  289. reg_olpc = AR_PHY_TPC_11_B0;
  290. reg_cl_gain = AR_PHY_CL_TAB_0;
  291. break;
  292. case 1:
  293. reg_olpc = AR_PHY_TPC_11_B1;
  294. reg_cl_gain = AR_PHY_CL_TAB_1;
  295. break;
  296. case 2:
  297. reg_olpc = AR_PHY_TPC_11_B2;
  298. reg_cl_gain = AR_PHY_CL_TAB_2;
  299. break;
  300. default:
  301. ath_dbg(ath9k_hw_common(ah), CALIBRATE,
  302. "Invalid chainmask: %d\n", chain);
  303. break;
  304. }
  305. olpc_gain_delta = REG_READ_FIELD(ah, reg_olpc,
  306. AR_PHY_TPC_11_OLPC_GAIN_DELTA);
  307. cl_gain_mod = REG_READ_FIELD(ah, reg_cl_gain,
  308. AR_PHY_CL_TAB_CL_GAIN_MOD);
  309. if (olpc_gain_delta >= 128)
  310. olpc_gain_delta = olpc_gain_delta - 256;
  311. thermal_gain_corr = (alpha_therm * (therm_value - therm_cal_value) +
  312. (256 / 2)) / 256;
  313. voltage_gain_corr = (alpha_volt * (volt_value - volt_cal_value) +
  314. (128 / 2)) / 128;
  315. desired_gain = target_power - olpc_gain_delta - thermal_gain_corr -
  316. voltage_gain_corr + desired_scale + cl_gain_mod;
  317. return desired_gain;
  318. }
  319. static void ar9003_tx_force_gain(struct ath_hw *ah, unsigned int gain_index)
  320. {
  321. int selected_gain_entry, txbb1dbgain, txbb6dbgain, txmxrgain;
  322. int padrvgnA, padrvgnB, padrvgnC, padrvgnD;
  323. u32 *gain_table_entries = ah->paprd_gain_table_entries;
  324. selected_gain_entry = gain_table_entries[gain_index];
  325. txbb1dbgain = selected_gain_entry & 0x7;
  326. txbb6dbgain = (selected_gain_entry >> 3) & 0x3;
  327. txmxrgain = (selected_gain_entry >> 5) & 0xf;
  328. padrvgnA = (selected_gain_entry >> 9) & 0xf;
  329. padrvgnB = (selected_gain_entry >> 13) & 0xf;
  330. padrvgnC = (selected_gain_entry >> 17) & 0xf;
  331. padrvgnD = (selected_gain_entry >> 21) & 0x3;
  332. REG_RMW_FIELD(ah, AR_PHY_TX_FORCED_GAIN,
  333. AR_PHY_TX_FORCED_GAIN_FORCED_TXBB1DBGAIN, txbb1dbgain);
  334. REG_RMW_FIELD(ah, AR_PHY_TX_FORCED_GAIN,
  335. AR_PHY_TX_FORCED_GAIN_FORCED_TXBB6DBGAIN, txbb6dbgain);
  336. REG_RMW_FIELD(ah, AR_PHY_TX_FORCED_GAIN,
  337. AR_PHY_TX_FORCED_GAIN_FORCED_TXMXRGAIN, txmxrgain);
  338. REG_RMW_FIELD(ah, AR_PHY_TX_FORCED_GAIN,
  339. AR_PHY_TX_FORCED_GAIN_FORCED_PADRVGNA, padrvgnA);
  340. REG_RMW_FIELD(ah, AR_PHY_TX_FORCED_GAIN,
  341. AR_PHY_TX_FORCED_GAIN_FORCED_PADRVGNB, padrvgnB);
  342. REG_RMW_FIELD(ah, AR_PHY_TX_FORCED_GAIN,
  343. AR_PHY_TX_FORCED_GAIN_FORCED_PADRVGNC, padrvgnC);
  344. REG_RMW_FIELD(ah, AR_PHY_TX_FORCED_GAIN,
  345. AR_PHY_TX_FORCED_GAIN_FORCED_PADRVGND, padrvgnD);
  346. REG_RMW_FIELD(ah, AR_PHY_TX_FORCED_GAIN,
  347. AR_PHY_TX_FORCED_GAIN_FORCED_ENABLE_PAL, 0);
  348. REG_RMW_FIELD(ah, AR_PHY_TX_FORCED_GAIN,
  349. AR_PHY_TX_FORCED_GAIN_FORCE_TX_GAIN, 0);
  350. REG_RMW_FIELD(ah, AR_PHY_TPC_1, AR_PHY_TPC_1_FORCED_DAC_GAIN, 0);
  351. REG_RMW_FIELD(ah, AR_PHY_TPC_1, AR_PHY_TPC_1_FORCE_DAC_GAIN, 0);
  352. }
  353. static inline int find_expn(int num)
  354. {
  355. return fls(num) - 1;
  356. }
  357. static inline int find_proper_scale(int expn, int N)
  358. {
  359. return (expn > N) ? expn - 10 : 0;
  360. }
  361. #define NUM_BIN 23
  362. static bool create_pa_curve(u32 *data_L, u32 *data_U, u32 *pa_table, u16 *gain)
  363. {
  364. unsigned int thresh_accum_cnt;
  365. int x_est[NUM_BIN + 1], Y[NUM_BIN + 1], theta[NUM_BIN + 1];
  366. int PA_in[NUM_BIN + 1];
  367. int B1_tmp[NUM_BIN + 1], B2_tmp[NUM_BIN + 1];
  368. unsigned int B1_abs_max, B2_abs_max;
  369. int max_index, scale_factor;
  370. int y_est[NUM_BIN + 1];
  371. int x_est_fxp1_nonlin, x_tilde[NUM_BIN + 1];
  372. unsigned int x_tilde_abs;
  373. int G_fxp, Y_intercept, order_x_by_y, M, I, L, sum_y_sqr, sum_y_quad;
  374. int Q_x, Q_B1, Q_B2, beta_raw, alpha_raw, scale_B;
  375. int Q_scale_B, Q_beta, Q_alpha, alpha, beta, order_1, order_2;
  376. int order1_5x, order2_3x, order1_5x_rem, order2_3x_rem;
  377. int y5, y3, tmp;
  378. int theta_low_bin = 0;
  379. int i;
  380. /* disregard any bin that contains <= 16 samples */
  381. thresh_accum_cnt = 16;
  382. scale_factor = 5;
  383. max_index = 0;
  384. memset(theta, 0, sizeof(theta));
  385. memset(x_est, 0, sizeof(x_est));
  386. memset(Y, 0, sizeof(Y));
  387. memset(y_est, 0, sizeof(y_est));
  388. memset(x_tilde, 0, sizeof(x_tilde));
  389. for (i = 0; i < NUM_BIN; i++) {
  390. s32 accum_cnt, accum_tx, accum_rx, accum_ang;
  391. /* number of samples */
  392. accum_cnt = data_L[i] & 0xffff;
  393. if (accum_cnt <= thresh_accum_cnt)
  394. continue;
  395. /* sum(tx amplitude) */
  396. accum_tx = ((data_L[i] >> 16) & 0xffff) |
  397. ((data_U[i] & 0x7ff) << 16);
  398. /* sum(rx amplitude distance to lower bin edge) */
  399. accum_rx = ((data_U[i] >> 11) & 0x1f) |
  400. ((data_L[i + 23] & 0xffff) << 5);
  401. /* sum(angles) */
  402. accum_ang = ((data_L[i + 23] >> 16) & 0xffff) |
  403. ((data_U[i + 23] & 0x7ff) << 16);
  404. accum_tx <<= scale_factor;
  405. accum_rx <<= scale_factor;
  406. x_est[i + 1] = (((accum_tx + accum_cnt) / accum_cnt) + 32) >>
  407. scale_factor;
  408. Y[i + 1] = ((((accum_rx + accum_cnt) / accum_cnt) + 32) >>
  409. scale_factor) +
  410. (1 << scale_factor) * max_index + 16;
  411. if (accum_ang >= (1 << 26))
  412. accum_ang -= 1 << 27;
  413. theta[i + 1] = ((accum_ang * (1 << scale_factor)) + accum_cnt) /
  414. accum_cnt;
  415. max_index++;
  416. }
  417. /*
  418. * Find average theta of first 5 bin and all of those to same value.
  419. * Curve is linear at that range.
  420. */
  421. for (i = 1; i < 6; i++)
  422. theta_low_bin += theta[i];
  423. theta_low_bin = theta_low_bin / 5;
  424. for (i = 1; i < 6; i++)
  425. theta[i] = theta_low_bin;
  426. /* Set values at origin */
  427. theta[0] = theta_low_bin;
  428. for (i = 0; i <= max_index; i++)
  429. theta[i] -= theta_low_bin;
  430. x_est[0] = 0;
  431. Y[0] = 0;
  432. scale_factor = 8;
  433. /* low signal gain */
  434. if (x_est[6] == x_est[3])
  435. return false;
  436. G_fxp =
  437. (((Y[6] - Y[3]) * 1 << scale_factor) +
  438. (x_est[6] - x_est[3])) / (x_est[6] - x_est[3]);
  439. /* prevent division by zero */
  440. if (G_fxp == 0)
  441. return false;
  442. Y_intercept =
  443. (G_fxp * (x_est[0] - x_est[3]) +
  444. (1 << scale_factor)) / (1 << scale_factor) + Y[3];
  445. for (i = 0; i <= max_index; i++)
  446. y_est[i] = Y[i] - Y_intercept;
  447. for (i = 0; i <= 3; i++) {
  448. y_est[i] = i * 32;
  449. x_est[i] = ((y_est[i] * 1 << scale_factor) + G_fxp) / G_fxp;
  450. }
  451. if (y_est[max_index] == 0)
  452. return false;
  453. x_est_fxp1_nonlin =
  454. x_est[max_index] - ((1 << scale_factor) * y_est[max_index] +
  455. G_fxp) / G_fxp;
  456. order_x_by_y =
  457. (x_est_fxp1_nonlin + y_est[max_index]) / y_est[max_index];
  458. if (order_x_by_y == 0)
  459. M = 10;
  460. else if (order_x_by_y == 1)
  461. M = 9;
  462. else
  463. M = 8;
  464. I = (max_index > 15) ? 7 : max_index >> 1;
  465. L = max_index - I;
  466. scale_factor = 8;
  467. sum_y_sqr = 0;
  468. sum_y_quad = 0;
  469. x_tilde_abs = 0;
  470. for (i = 0; i <= L; i++) {
  471. unsigned int y_sqr;
  472. unsigned int y_quad;
  473. unsigned int tmp_abs;
  474. /* prevent division by zero */
  475. if (y_est[i + I] == 0)
  476. return false;
  477. x_est_fxp1_nonlin =
  478. x_est[i + I] - ((1 << scale_factor) * y_est[i + I] +
  479. G_fxp) / G_fxp;
  480. x_tilde[i] =
  481. (x_est_fxp1_nonlin * (1 << M) + y_est[i + I]) / y_est[i +
  482. I];
  483. x_tilde[i] =
  484. (x_tilde[i] * (1 << M) + y_est[i + I]) / y_est[i + I];
  485. x_tilde[i] =
  486. (x_tilde[i] * (1 << M) + y_est[i + I]) / y_est[i + I];
  487. y_sqr =
  488. (y_est[i + I] * y_est[i + I] +
  489. (scale_factor * scale_factor)) / (scale_factor *
  490. scale_factor);
  491. tmp_abs = abs(x_tilde[i]);
  492. if (tmp_abs > x_tilde_abs)
  493. x_tilde_abs = tmp_abs;
  494. y_quad = y_sqr * y_sqr;
  495. sum_y_sqr = sum_y_sqr + y_sqr;
  496. sum_y_quad = sum_y_quad + y_quad;
  497. B1_tmp[i] = y_sqr * (L + 1);
  498. B2_tmp[i] = y_sqr;
  499. }
  500. B1_abs_max = 0;
  501. B2_abs_max = 0;
  502. for (i = 0; i <= L; i++) {
  503. int abs_val;
  504. B1_tmp[i] -= sum_y_sqr;
  505. B2_tmp[i] = sum_y_quad - sum_y_sqr * B2_tmp[i];
  506. abs_val = abs(B1_tmp[i]);
  507. if (abs_val > B1_abs_max)
  508. B1_abs_max = abs_val;
  509. abs_val = abs(B2_tmp[i]);
  510. if (abs_val > B2_abs_max)
  511. B2_abs_max = abs_val;
  512. }
  513. Q_x = find_proper_scale(find_expn(x_tilde_abs), 10);
  514. Q_B1 = find_proper_scale(find_expn(B1_abs_max), 10);
  515. Q_B2 = find_proper_scale(find_expn(B2_abs_max), 10);
  516. beta_raw = 0;
  517. alpha_raw = 0;
  518. for (i = 0; i <= L; i++) {
  519. x_tilde[i] = x_tilde[i] / (1 << Q_x);
  520. B1_tmp[i] = B1_tmp[i] / (1 << Q_B1);
  521. B2_tmp[i] = B2_tmp[i] / (1 << Q_B2);
  522. beta_raw = beta_raw + B1_tmp[i] * x_tilde[i];
  523. alpha_raw = alpha_raw + B2_tmp[i] * x_tilde[i];
  524. }
  525. scale_B =
  526. ((sum_y_quad / scale_factor) * (L + 1) -
  527. (sum_y_sqr / scale_factor) * sum_y_sqr) * scale_factor;
  528. Q_scale_B = find_proper_scale(find_expn(abs(scale_B)), 10);
  529. scale_B = scale_B / (1 << Q_scale_B);
  530. if (scale_B == 0)
  531. return false;
  532. Q_beta = find_proper_scale(find_expn(abs(beta_raw)), 10);
  533. Q_alpha = find_proper_scale(find_expn(abs(alpha_raw)), 10);
  534. beta_raw = beta_raw / (1 << Q_beta);
  535. alpha_raw = alpha_raw / (1 << Q_alpha);
  536. alpha = (alpha_raw << 10) / scale_B;
  537. beta = (beta_raw << 10) / scale_B;
  538. order_1 = 3 * M - Q_x - Q_B1 - Q_beta + 10 + Q_scale_B;
  539. order_2 = 3 * M - Q_x - Q_B2 - Q_alpha + 10 + Q_scale_B;
  540. order1_5x = order_1 / 5;
  541. order2_3x = order_2 / 3;
  542. order1_5x_rem = order_1 - 5 * order1_5x;
  543. order2_3x_rem = order_2 - 3 * order2_3x;
  544. for (i = 0; i < PAPRD_TABLE_SZ; i++) {
  545. tmp = i * 32;
  546. y5 = ((beta * tmp) >> 6) >> order1_5x;
  547. y5 = (y5 * tmp) >> order1_5x;
  548. y5 = (y5 * tmp) >> order1_5x;
  549. y5 = (y5 * tmp) >> order1_5x;
  550. y5 = (y5 * tmp) >> order1_5x;
  551. y5 = y5 >> order1_5x_rem;
  552. y3 = (alpha * tmp) >> order2_3x;
  553. y3 = (y3 * tmp) >> order2_3x;
  554. y3 = (y3 * tmp) >> order2_3x;
  555. y3 = y3 >> order2_3x_rem;
  556. PA_in[i] = y5 + y3 + (256 * tmp) / G_fxp;
  557. if (i >= 2) {
  558. tmp = PA_in[i] - PA_in[i - 1];
  559. if (tmp < 0)
  560. PA_in[i] =
  561. PA_in[i - 1] + (PA_in[i - 1] -
  562. PA_in[i - 2]);
  563. }
  564. PA_in[i] = (PA_in[i] < 1400) ? PA_in[i] : 1400;
  565. }
  566. beta_raw = 0;
  567. alpha_raw = 0;
  568. for (i = 0; i <= L; i++) {
  569. int theta_tilde =
  570. ((theta[i + I] << M) + y_est[i + I]) / y_est[i + I];
  571. theta_tilde =
  572. ((theta_tilde << M) + y_est[i + I]) / y_est[i + I];
  573. theta_tilde =
  574. ((theta_tilde << M) + y_est[i + I]) / y_est[i + I];
  575. beta_raw = beta_raw + B1_tmp[i] * theta_tilde;
  576. alpha_raw = alpha_raw + B2_tmp[i] * theta_tilde;
  577. }
  578. Q_beta = find_proper_scale(find_expn(abs(beta_raw)), 10);
  579. Q_alpha = find_proper_scale(find_expn(abs(alpha_raw)), 10);
  580. beta_raw = beta_raw / (1 << Q_beta);
  581. alpha_raw = alpha_raw / (1 << Q_alpha);
  582. alpha = (alpha_raw << 10) / scale_B;
  583. beta = (beta_raw << 10) / scale_B;
  584. order_1 = 3 * M - Q_x - Q_B1 - Q_beta + 10 + Q_scale_B + 5;
  585. order_2 = 3 * M - Q_x - Q_B2 - Q_alpha + 10 + Q_scale_B + 5;
  586. order1_5x = order_1 / 5;
  587. order2_3x = order_2 / 3;
  588. order1_5x_rem = order_1 - 5 * order1_5x;
  589. order2_3x_rem = order_2 - 3 * order2_3x;
  590. for (i = 0; i < PAPRD_TABLE_SZ; i++) {
  591. int PA_angle;
  592. /* pa_table[4] is calculated from PA_angle for i=5 */
  593. if (i == 4)
  594. continue;
  595. tmp = i * 32;
  596. if (beta > 0)
  597. y5 = (((beta * tmp - 64) >> 6) -
  598. (1 << order1_5x)) / (1 << order1_5x);
  599. else
  600. y5 = ((((beta * tmp - 64) >> 6) +
  601. (1 << order1_5x)) / (1 << order1_5x));
  602. y5 = (y5 * tmp) / (1 << order1_5x);
  603. y5 = (y5 * tmp) / (1 << order1_5x);
  604. y5 = (y5 * tmp) / (1 << order1_5x);
  605. y5 = (y5 * tmp) / (1 << order1_5x);
  606. y5 = y5 / (1 << order1_5x_rem);
  607. if (beta > 0)
  608. y3 = (alpha * tmp -
  609. (1 << order2_3x)) / (1 << order2_3x);
  610. else
  611. y3 = (alpha * tmp +
  612. (1 << order2_3x)) / (1 << order2_3x);
  613. y3 = (y3 * tmp) / (1 << order2_3x);
  614. y3 = (y3 * tmp) / (1 << order2_3x);
  615. y3 = y3 / (1 << order2_3x_rem);
  616. if (i < 4) {
  617. PA_angle = 0;
  618. } else {
  619. PA_angle = y5 + y3;
  620. if (PA_angle < -150)
  621. PA_angle = -150;
  622. else if (PA_angle > 150)
  623. PA_angle = 150;
  624. }
  625. pa_table[i] = ((PA_in[i] & 0x7ff) << 11) + (PA_angle & 0x7ff);
  626. if (i == 5) {
  627. PA_angle = (PA_angle + 2) >> 1;
  628. pa_table[i - 1] = ((PA_in[i - 1] & 0x7ff) << 11) +
  629. (PA_angle & 0x7ff);
  630. }
  631. }
  632. *gain = G_fxp;
  633. return true;
  634. }
  635. void ar9003_paprd_populate_single_table(struct ath_hw *ah,
  636. struct ath9k_hw_cal_data *caldata,
  637. int chain)
  638. {
  639. u32 *paprd_table_val = caldata->pa_table[chain];
  640. u32 small_signal_gain = caldata->small_signal_gain[chain];
  641. u32 training_power = ah->paprd_training_power;
  642. u32 reg = 0;
  643. int i;
  644. if (chain == 0)
  645. reg = AR_PHY_PAPRD_MEM_TAB_B0;
  646. else if (chain == 1)
  647. reg = AR_PHY_PAPRD_MEM_TAB_B1;
  648. else if (chain == 2)
  649. reg = AR_PHY_PAPRD_MEM_TAB_B2;
  650. for (i = 0; i < PAPRD_TABLE_SZ; i++) {
  651. REG_WRITE(ah, reg, paprd_table_val[i]);
  652. reg = reg + 4;
  653. }
  654. if (chain == 0)
  655. reg = AR_PHY_PA_GAIN123_B0;
  656. else if (chain == 1)
  657. reg = AR_PHY_PA_GAIN123_B1;
  658. else
  659. reg = AR_PHY_PA_GAIN123_B2;
  660. REG_RMW_FIELD(ah, reg, AR_PHY_PA_GAIN123_PA_GAIN1, small_signal_gain);
  661. REG_RMW_FIELD(ah, AR_PHY_PAPRD_CTRL1_B0,
  662. AR_PHY_PAPRD_CTRL1_PAPRD_POWER_AT_AM2AM_CAL,
  663. training_power);
  664. if (ah->caps.tx_chainmask & BIT(1))
  665. REG_RMW_FIELD(ah, AR_PHY_PAPRD_CTRL1_B1,
  666. AR_PHY_PAPRD_CTRL1_PAPRD_POWER_AT_AM2AM_CAL,
  667. training_power);
  668. if (ah->caps.tx_chainmask & BIT(2))
  669. /* val AR_PHY_PAPRD_CTRL1_PAPRD_POWER_AT_AM2AM_CAL correct? */
  670. REG_RMW_FIELD(ah, AR_PHY_PAPRD_CTRL1_B2,
  671. AR_PHY_PAPRD_CTRL1_PAPRD_POWER_AT_AM2AM_CAL,
  672. training_power);
  673. }
  674. EXPORT_SYMBOL(ar9003_paprd_populate_single_table);
  675. void ar9003_paprd_setup_gain_table(struct ath_hw *ah, int chain)
  676. {
  677. unsigned int i, desired_gain, gain_index;
  678. unsigned int train_power = ah->paprd_training_power;
  679. desired_gain = ar9003_get_desired_gain(ah, chain, train_power);
  680. gain_index = 0;
  681. for (i = 0; i < PAPRD_GAIN_TABLE_ENTRIES; i++) {
  682. if (ah->paprd_gain_table_index[i] >= desired_gain)
  683. break;
  684. gain_index++;
  685. }
  686. ar9003_tx_force_gain(ah, gain_index);
  687. REG_CLR_BIT(ah, AR_PHY_PAPRD_TRAINER_STAT1,
  688. AR_PHY_PAPRD_TRAINER_STAT1_PAPRD_TRAIN_DONE);
  689. }
  690. EXPORT_SYMBOL(ar9003_paprd_setup_gain_table);
  691. static bool ar9003_paprd_retrain_pa_in(struct ath_hw *ah,
  692. struct ath9k_hw_cal_data *caldata,
  693. int chain)
  694. {
  695. u32 *pa_in = caldata->pa_table[chain];
  696. int capdiv_offset, quick_drop_offset;
  697. int capdiv2g, quick_drop;
  698. int count = 0;
  699. int i;
  700. if (!AR_SREV_9485(ah) && !AR_SREV_9330(ah))
  701. return false;
  702. capdiv2g = REG_READ_FIELD(ah, AR_PHY_65NM_CH0_TXRF3,
  703. AR_PHY_65NM_CH0_TXRF3_CAPDIV2G);
  704. quick_drop = REG_READ_FIELD(ah, AR_PHY_PAPRD_TRAINER_CNTL3,
  705. AR_PHY_PAPRD_TRAINER_CNTL3_CF_PAPRD_QUICK_DROP);
  706. if (quick_drop)
  707. quick_drop -= 0x40;
  708. for (i = 0; i < NUM_BIN + 1; i++) {
  709. if (pa_in[i] == 1400)
  710. count++;
  711. }
  712. if (AR_SREV_9485(ah)) {
  713. if (pa_in[23] < 800) {
  714. capdiv_offset = (int)((1000 - pa_in[23] + 75) / 150);
  715. capdiv2g += capdiv_offset;
  716. if (capdiv2g > 7) {
  717. capdiv2g = 7;
  718. if (pa_in[23] < 600) {
  719. quick_drop++;
  720. if (quick_drop > 0)
  721. quick_drop = 0;
  722. }
  723. }
  724. } else if (pa_in[23] == 1400) {
  725. quick_drop_offset = min_t(int, count / 3, 2);
  726. quick_drop += quick_drop_offset;
  727. capdiv2g += quick_drop_offset / 2;
  728. if (capdiv2g > 7)
  729. capdiv2g = 7;
  730. if (quick_drop > 0) {
  731. quick_drop = 0;
  732. capdiv2g -= quick_drop_offset;
  733. if (capdiv2g < 0)
  734. capdiv2g = 0;
  735. }
  736. } else {
  737. return false;
  738. }
  739. } else if (AR_SREV_9330(ah)) {
  740. if (pa_in[23] < 1000) {
  741. capdiv_offset = (1000 - pa_in[23]) / 100;
  742. capdiv2g += capdiv_offset;
  743. if (capdiv_offset > 3) {
  744. capdiv_offset = 1;
  745. quick_drop--;
  746. }
  747. capdiv2g += capdiv_offset;
  748. if (capdiv2g > 6)
  749. capdiv2g = 6;
  750. if (quick_drop < -4)
  751. quick_drop = -4;
  752. } else if (pa_in[23] == 1400) {
  753. if (count > 3) {
  754. quick_drop++;
  755. capdiv2g -= count / 4;
  756. if (quick_drop > -2)
  757. quick_drop = -2;
  758. } else {
  759. capdiv2g--;
  760. }
  761. if (capdiv2g < 0)
  762. capdiv2g = 0;
  763. } else {
  764. return false;
  765. }
  766. }
  767. REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_TXRF3,
  768. AR_PHY_65NM_CH0_TXRF3_CAPDIV2G, capdiv2g);
  769. REG_RMW_FIELD(ah, AR_PHY_PAPRD_TRAINER_CNTL3,
  770. AR_PHY_PAPRD_TRAINER_CNTL3_CF_PAPRD_QUICK_DROP,
  771. quick_drop);
  772. return true;
  773. }
  774. int ar9003_paprd_create_curve(struct ath_hw *ah,
  775. struct ath9k_hw_cal_data *caldata, int chain)
  776. {
  777. u16 *small_signal_gain = &caldata->small_signal_gain[chain];
  778. u32 *pa_table = caldata->pa_table[chain];
  779. u32 *data_L, *data_U;
  780. int i, status = 0;
  781. u32 *buf;
  782. u32 reg;
  783. memset(caldata->pa_table[chain], 0, sizeof(caldata->pa_table[chain]));
  784. buf = kmalloc(2 * 48 * sizeof(u32), GFP_KERNEL);
  785. if (!buf)
  786. return -ENOMEM;
  787. data_L = &buf[0];
  788. data_U = &buf[48];
  789. REG_CLR_BIT(ah, AR_PHY_CHAN_INFO_MEMORY,
  790. AR_PHY_CHAN_INFO_MEMORY_CHANINFOMEM_S2_READ);
  791. reg = AR_PHY_CHAN_INFO_TAB_0;
  792. for (i = 0; i < 48; i++)
  793. data_L[i] = REG_READ(ah, reg + (i << 2));
  794. REG_SET_BIT(ah, AR_PHY_CHAN_INFO_MEMORY,
  795. AR_PHY_CHAN_INFO_MEMORY_CHANINFOMEM_S2_READ);
  796. for (i = 0; i < 48; i++)
  797. data_U[i] = REG_READ(ah, reg + (i << 2));
  798. if (!create_pa_curve(data_L, data_U, pa_table, small_signal_gain))
  799. status = -2;
  800. if (ar9003_paprd_retrain_pa_in(ah, caldata, chain))
  801. status = -EINPROGRESS;
  802. REG_CLR_BIT(ah, AR_PHY_PAPRD_TRAINER_STAT1,
  803. AR_PHY_PAPRD_TRAINER_STAT1_PAPRD_TRAIN_DONE);
  804. kfree(buf);
  805. return status;
  806. }
  807. EXPORT_SYMBOL(ar9003_paprd_create_curve);
  808. int ar9003_paprd_init_table(struct ath_hw *ah)
  809. {
  810. int ret;
  811. ret = ar9003_paprd_setup_single_table(ah);
  812. if (ret < 0)
  813. return ret;
  814. ar9003_paprd_get_gain_table(ah);
  815. return 0;
  816. }
  817. EXPORT_SYMBOL(ar9003_paprd_init_table);
  818. bool ar9003_paprd_is_done(struct ath_hw *ah)
  819. {
  820. int paprd_done, agc2_pwr;
  821. paprd_done = REG_READ_FIELD(ah, AR_PHY_PAPRD_TRAINER_STAT1,
  822. AR_PHY_PAPRD_TRAINER_STAT1_PAPRD_TRAIN_DONE);
  823. if (paprd_done == 0x1) {
  824. agc2_pwr = REG_READ_FIELD(ah, AR_PHY_PAPRD_TRAINER_STAT1,
  825. AR_PHY_PAPRD_TRAINER_STAT1_PAPRD_AGC2_PWR);
  826. ath_dbg(ath9k_hw_common(ah), CALIBRATE,
  827. "AGC2_PWR = 0x%x training done = 0x%x\n",
  828. agc2_pwr, paprd_done);
  829. /*
  830. * agc2_pwr range should not be less than 'IDEAL_AGC2_PWR_CHANGE'
  831. * when the training is completely done, otherwise retraining is
  832. * done to make sure the value is in ideal range
  833. */
  834. if (agc2_pwr <= PAPRD_IDEAL_AGC2_PWR_RANGE)
  835. paprd_done = 0;
  836. }
  837. return !!paprd_done;
  838. }
  839. EXPORT_SYMBOL(ar9003_paprd_is_done);