ar9003_paprd.c 28 KB

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