PageRenderTime 62ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/net/wireless/ath/ath9k/ar9003_phy.c

http://github.com/mirrors/linux
C | 2180 lines | 1619 code | 288 blank | 273 comment | 258 complexity | 76d476ff4467dcccd566ea88e6f84260 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0
  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. #include "ar9003_eeprom.h"
  20. #define AR9300_OFDM_RATES 8
  21. #define AR9300_HT_SS_RATES 8
  22. #define AR9300_HT_DS_RATES 8
  23. #define AR9300_HT_TS_RATES 8
  24. #define AR9300_11NA_OFDM_SHIFT 0
  25. #define AR9300_11NA_HT_SS_SHIFT 8
  26. #define AR9300_11NA_HT_DS_SHIFT 16
  27. #define AR9300_11NA_HT_TS_SHIFT 24
  28. #define AR9300_11NG_OFDM_SHIFT 4
  29. #define AR9300_11NG_HT_SS_SHIFT 12
  30. #define AR9300_11NG_HT_DS_SHIFT 20
  31. #define AR9300_11NG_HT_TS_SHIFT 28
  32. static const int firstep_table[] =
  33. /* level: 0 1 2 3 4 5 6 7 8 */
  34. { -4, -2, 0, 2, 4, 6, 8, 10, 12 }; /* lvl 0-8, default 2 */
  35. static const int cycpwrThr1_table[] =
  36. /* level: 0 1 2 3 4 5 6 7 8 */
  37. { -6, -4, -2, 0, 2, 4, 6, 8 }; /* lvl 0-7, default 3 */
  38. /*
  39. * register values to turn OFDM weak signal detection OFF
  40. */
  41. static const int m1ThreshLow_off = 127;
  42. static const int m2ThreshLow_off = 127;
  43. static const int m1Thresh_off = 127;
  44. static const int m2Thresh_off = 127;
  45. static const int m2CountThr_off = 31;
  46. static const int m2CountThrLow_off = 63;
  47. static const int m1ThreshLowExt_off = 127;
  48. static const int m2ThreshLowExt_off = 127;
  49. static const int m1ThreshExt_off = 127;
  50. static const int m2ThreshExt_off = 127;
  51. static const u8 ofdm2pwr[] = {
  52. ALL_TARGET_LEGACY_6_24,
  53. ALL_TARGET_LEGACY_6_24,
  54. ALL_TARGET_LEGACY_6_24,
  55. ALL_TARGET_LEGACY_6_24,
  56. ALL_TARGET_LEGACY_6_24,
  57. ALL_TARGET_LEGACY_36,
  58. ALL_TARGET_LEGACY_48,
  59. ALL_TARGET_LEGACY_54
  60. };
  61. static const u8 mcs2pwr_ht20[] = {
  62. ALL_TARGET_HT20_0_8_16,
  63. ALL_TARGET_HT20_1_3_9_11_17_19,
  64. ALL_TARGET_HT20_1_3_9_11_17_19,
  65. ALL_TARGET_HT20_1_3_9_11_17_19,
  66. ALL_TARGET_HT20_4,
  67. ALL_TARGET_HT20_5,
  68. ALL_TARGET_HT20_6,
  69. ALL_TARGET_HT20_7,
  70. ALL_TARGET_HT20_0_8_16,
  71. ALL_TARGET_HT20_1_3_9_11_17_19,
  72. ALL_TARGET_HT20_1_3_9_11_17_19,
  73. ALL_TARGET_HT20_1_3_9_11_17_19,
  74. ALL_TARGET_HT20_12,
  75. ALL_TARGET_HT20_13,
  76. ALL_TARGET_HT20_14,
  77. ALL_TARGET_HT20_15,
  78. ALL_TARGET_HT20_0_8_16,
  79. ALL_TARGET_HT20_1_3_9_11_17_19,
  80. ALL_TARGET_HT20_1_3_9_11_17_19,
  81. ALL_TARGET_HT20_1_3_9_11_17_19,
  82. ALL_TARGET_HT20_20,
  83. ALL_TARGET_HT20_21,
  84. ALL_TARGET_HT20_22,
  85. ALL_TARGET_HT20_23
  86. };
  87. static const u8 mcs2pwr_ht40[] = {
  88. ALL_TARGET_HT40_0_8_16,
  89. ALL_TARGET_HT40_1_3_9_11_17_19,
  90. ALL_TARGET_HT40_1_3_9_11_17_19,
  91. ALL_TARGET_HT40_1_3_9_11_17_19,
  92. ALL_TARGET_HT40_4,
  93. ALL_TARGET_HT40_5,
  94. ALL_TARGET_HT40_6,
  95. ALL_TARGET_HT40_7,
  96. ALL_TARGET_HT40_0_8_16,
  97. ALL_TARGET_HT40_1_3_9_11_17_19,
  98. ALL_TARGET_HT40_1_3_9_11_17_19,
  99. ALL_TARGET_HT40_1_3_9_11_17_19,
  100. ALL_TARGET_HT40_12,
  101. ALL_TARGET_HT40_13,
  102. ALL_TARGET_HT40_14,
  103. ALL_TARGET_HT40_15,
  104. ALL_TARGET_HT40_0_8_16,
  105. ALL_TARGET_HT40_1_3_9_11_17_19,
  106. ALL_TARGET_HT40_1_3_9_11_17_19,
  107. ALL_TARGET_HT40_1_3_9_11_17_19,
  108. ALL_TARGET_HT40_20,
  109. ALL_TARGET_HT40_21,
  110. ALL_TARGET_HT40_22,
  111. ALL_TARGET_HT40_23,
  112. };
  113. /**
  114. * ar9003_hw_set_channel - set channel on single-chip device
  115. * @ah: atheros hardware structure
  116. * @chan:
  117. *
  118. * This is the function to change channel on single-chip devices, that is
  119. * for AR9300 family of chipsets.
  120. *
  121. * This function takes the channel value in MHz and sets
  122. * hardware channel value. Assumes writes have been enabled to analog bus.
  123. *
  124. * Actual Expression,
  125. *
  126. * For 2GHz channel,
  127. * Channel Frequency = (3/4) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
  128. * (freq_ref = 40MHz)
  129. *
  130. * For 5GHz channel,
  131. * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^10)
  132. * (freq_ref = 40MHz/(24>>amodeRefSel))
  133. *
  134. * For 5GHz channels which are 5MHz spaced,
  135. * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
  136. * (freq_ref = 40MHz)
  137. */
  138. static int ar9003_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
  139. {
  140. u16 bMode, fracMode = 0, aModeRefSel = 0;
  141. u32 freq, chan_frac, div, channelSel = 0, reg32 = 0;
  142. struct chan_centers centers;
  143. int loadSynthChannel;
  144. ath9k_hw_get_channel_centers(ah, chan, &centers);
  145. freq = centers.synth_center;
  146. if (freq < 4800) { /* 2 GHz, fractional mode */
  147. if (AR_SREV_9330(ah) || AR_SREV_9485(ah) ||
  148. AR_SREV_9531(ah) || AR_SREV_9550(ah) ||
  149. AR_SREV_9561(ah) || AR_SREV_9565(ah)) {
  150. if (ah->is_clk_25mhz)
  151. div = 75;
  152. else
  153. div = 120;
  154. channelSel = (freq * 4) / div;
  155. chan_frac = (((freq * 4) % div) * 0x20000) / div;
  156. channelSel = (channelSel << 17) | chan_frac;
  157. } else if (AR_SREV_9340(ah)) {
  158. if (ah->is_clk_25mhz) {
  159. channelSel = (freq * 2) / 75;
  160. chan_frac = (((freq * 2) % 75) * 0x20000) / 75;
  161. channelSel = (channelSel << 17) | chan_frac;
  162. } else {
  163. channelSel = CHANSEL_2G(freq) >> 1;
  164. }
  165. } else {
  166. channelSel = CHANSEL_2G(freq);
  167. }
  168. /* Set to 2G mode */
  169. bMode = 1;
  170. } else {
  171. if ((AR_SREV_9340(ah) || AR_SREV_9550(ah) ||
  172. AR_SREV_9531(ah) || AR_SREV_9561(ah)) &&
  173. ah->is_clk_25mhz) {
  174. channelSel = freq / 75;
  175. chan_frac = ((freq % 75) * 0x20000) / 75;
  176. channelSel = (channelSel << 17) | chan_frac;
  177. } else {
  178. channelSel = CHANSEL_5G(freq);
  179. /* Doubler is ON, so, divide channelSel by 2. */
  180. channelSel >>= 1;
  181. }
  182. /* Set to 5G mode */
  183. bMode = 0;
  184. }
  185. /* Enable fractional mode for all channels */
  186. fracMode = 1;
  187. aModeRefSel = 0;
  188. loadSynthChannel = 0;
  189. reg32 = (bMode << 29);
  190. REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
  191. /* Enable Long shift Select for Synthesizer */
  192. REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_SYNTH4,
  193. AR_PHY_SYNTH4_LONG_SHIFT_SELECT, 1);
  194. /* Program Synth. setting */
  195. reg32 = (channelSel << 2) | (fracMode << 30) |
  196. (aModeRefSel << 28) | (loadSynthChannel << 31);
  197. REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
  198. /* Toggle Load Synth channel bit */
  199. loadSynthChannel = 1;
  200. reg32 = (channelSel << 2) | (fracMode << 30) |
  201. (aModeRefSel << 28) | (loadSynthChannel << 31);
  202. REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
  203. ah->curchan = chan;
  204. return 0;
  205. }
  206. /**
  207. * ar9003_hw_spur_mitigate_mrc_cck - convert baseband spur frequency
  208. * @ah: atheros hardware structure
  209. * @chan:
  210. *
  211. * For single-chip solutions. Converts to baseband spur frequency given the
  212. * input channel frequency and compute register settings below.
  213. *
  214. * Spur mitigation for MRC CCK
  215. */
  216. static void ar9003_hw_spur_mitigate_mrc_cck(struct ath_hw *ah,
  217. struct ath9k_channel *chan)
  218. {
  219. static const u32 spur_freq[4] = { 2420, 2440, 2464, 2480 };
  220. int cur_bb_spur, negative = 0, cck_spur_freq;
  221. int i;
  222. int range, max_spur_cnts, synth_freq;
  223. u8 *spur_fbin_ptr = ar9003_get_spur_chan_ptr(ah, IS_CHAN_2GHZ(chan));
  224. /*
  225. * Need to verify range +/- 10 MHz in control channel, otherwise spur
  226. * is out-of-band and can be ignored.
  227. */
  228. if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah) ||
  229. AR_SREV_9550(ah) || AR_SREV_9561(ah)) {
  230. if (spur_fbin_ptr[0] == 0) /* No spur */
  231. return;
  232. max_spur_cnts = 5;
  233. if (IS_CHAN_HT40(chan)) {
  234. range = 19;
  235. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  236. AR_PHY_GC_DYN2040_PRI_CH) == 0)
  237. synth_freq = chan->channel + 10;
  238. else
  239. synth_freq = chan->channel - 10;
  240. } else {
  241. range = 10;
  242. synth_freq = chan->channel;
  243. }
  244. } else {
  245. range = AR_SREV_9462(ah) ? 5 : 10;
  246. max_spur_cnts = 4;
  247. synth_freq = chan->channel;
  248. }
  249. for (i = 0; i < max_spur_cnts; i++) {
  250. if (AR_SREV_9462(ah) && (i == 0 || i == 3))
  251. continue;
  252. negative = 0;
  253. if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah) ||
  254. AR_SREV_9550(ah) || AR_SREV_9561(ah))
  255. cur_bb_spur = ath9k_hw_fbin2freq(spur_fbin_ptr[i],
  256. IS_CHAN_2GHZ(chan));
  257. else
  258. cur_bb_spur = spur_freq[i];
  259. cur_bb_spur -= synth_freq;
  260. if (cur_bb_spur < 0) {
  261. negative = 1;
  262. cur_bb_spur = -cur_bb_spur;
  263. }
  264. if (cur_bb_spur < range) {
  265. cck_spur_freq = (int)((cur_bb_spur << 19) / 11);
  266. if (negative == 1)
  267. cck_spur_freq = -cck_spur_freq;
  268. cck_spur_freq = cck_spur_freq & 0xfffff;
  269. REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
  270. AR_PHY_AGC_CONTROL_YCOK_MAX, 0x7);
  271. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  272. AR_PHY_CCK_SPUR_MIT_SPUR_RSSI_THR, 0x7f);
  273. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  274. AR_PHY_CCK_SPUR_MIT_SPUR_FILTER_TYPE,
  275. 0x2);
  276. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  277. AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT,
  278. 0x1);
  279. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  280. AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ,
  281. cck_spur_freq);
  282. return;
  283. }
  284. }
  285. REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
  286. AR_PHY_AGC_CONTROL_YCOK_MAX, 0x5);
  287. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  288. AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT, 0x0);
  289. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  290. AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ, 0x0);
  291. }
  292. /* Clean all spur register fields */
  293. static void ar9003_hw_spur_ofdm_clear(struct ath_hw *ah)
  294. {
  295. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  296. AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0);
  297. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  298. AR_PHY_TIMING11_SPUR_FREQ_SD, 0);
  299. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  300. AR_PHY_TIMING11_SPUR_DELTA_PHASE, 0);
  301. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  302. AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, 0);
  303. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  304. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0);
  305. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  306. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0);
  307. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  308. AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0);
  309. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  310. AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 0);
  311. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  312. AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 0);
  313. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  314. AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0);
  315. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  316. AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0);
  317. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  318. AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0);
  319. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  320. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, 0);
  321. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  322. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, 0);
  323. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  324. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, 0);
  325. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  326. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0);
  327. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  328. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0);
  329. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  330. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0);
  331. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  332. AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0);
  333. }
  334. static void ar9003_hw_spur_ofdm(struct ath_hw *ah,
  335. int freq_offset,
  336. int spur_freq_sd,
  337. int spur_delta_phase,
  338. int spur_subchannel_sd,
  339. int range,
  340. int synth_freq)
  341. {
  342. int mask_index = 0;
  343. /* OFDM Spur mitigation */
  344. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  345. AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0x1);
  346. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  347. AR_PHY_TIMING11_SPUR_FREQ_SD, spur_freq_sd);
  348. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  349. AR_PHY_TIMING11_SPUR_DELTA_PHASE, spur_delta_phase);
  350. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  351. AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, spur_subchannel_sd);
  352. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  353. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0x1);
  354. if (!(AR_SREV_9565(ah) && range == 10 && synth_freq == 2437))
  355. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  356. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0x1);
  357. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  358. AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0x1);
  359. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  360. AR_PHY_SPUR_REG_SPUR_RSSI_THRESH, 34);
  361. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  362. AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 1);
  363. if (!AR_SREV_9340(ah) &&
  364. REG_READ_FIELD(ah, AR_PHY_MODE,
  365. AR_PHY_MODE_DYNAMIC) == 0x1)
  366. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  367. AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 1);
  368. mask_index = (freq_offset << 4) / 5;
  369. if (mask_index < 0)
  370. mask_index = mask_index - 1;
  371. mask_index = mask_index & 0x7f;
  372. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  373. AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0x1);
  374. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  375. AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0x1);
  376. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  377. AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0x1);
  378. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  379. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, mask_index);
  380. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  381. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, mask_index);
  382. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  383. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, mask_index);
  384. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  385. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0xc);
  386. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  387. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0xc);
  388. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  389. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0xa0);
  390. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  391. AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0xff);
  392. }
  393. static void ar9003_hw_spur_ofdm_9565(struct ath_hw *ah,
  394. int freq_offset)
  395. {
  396. int mask_index = 0;
  397. mask_index = (freq_offset << 4) / 5;
  398. if (mask_index < 0)
  399. mask_index = mask_index - 1;
  400. mask_index = mask_index & 0x7f;
  401. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  402. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_B,
  403. mask_index);
  404. /* A == B */
  405. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_B,
  406. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A,
  407. mask_index);
  408. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  409. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_B,
  410. mask_index);
  411. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  412. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_B, 0xe);
  413. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  414. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_B, 0xe);
  415. /* A == B */
  416. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_B,
  417. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0xa0);
  418. }
  419. static void ar9003_hw_spur_ofdm_work(struct ath_hw *ah,
  420. struct ath9k_channel *chan,
  421. int freq_offset,
  422. int range,
  423. int synth_freq)
  424. {
  425. int spur_freq_sd = 0;
  426. int spur_subchannel_sd = 0;
  427. int spur_delta_phase = 0;
  428. if (IS_CHAN_HT40(chan)) {
  429. if (freq_offset < 0) {
  430. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  431. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  432. spur_subchannel_sd = 1;
  433. else
  434. spur_subchannel_sd = 0;
  435. spur_freq_sd = ((freq_offset + 10) << 9) / 11;
  436. } else {
  437. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  438. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  439. spur_subchannel_sd = 0;
  440. else
  441. spur_subchannel_sd = 1;
  442. spur_freq_sd = ((freq_offset - 10) << 9) / 11;
  443. }
  444. spur_delta_phase = (freq_offset << 17) / 5;
  445. } else {
  446. spur_subchannel_sd = 0;
  447. spur_freq_sd = (freq_offset << 9) /11;
  448. spur_delta_phase = (freq_offset << 18) / 5;
  449. }
  450. spur_freq_sd = spur_freq_sd & 0x3ff;
  451. spur_delta_phase = spur_delta_phase & 0xfffff;
  452. ar9003_hw_spur_ofdm(ah,
  453. freq_offset,
  454. spur_freq_sd,
  455. spur_delta_phase,
  456. spur_subchannel_sd,
  457. range, synth_freq);
  458. }
  459. /* Spur mitigation for OFDM */
  460. static void ar9003_hw_spur_mitigate_ofdm(struct ath_hw *ah,
  461. struct ath9k_channel *chan)
  462. {
  463. int synth_freq;
  464. int range = 10;
  465. int freq_offset = 0;
  466. int mode;
  467. u8* spurChansPtr;
  468. unsigned int i;
  469. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  470. if (IS_CHAN_5GHZ(chan)) {
  471. spurChansPtr = &(eep->modalHeader5G.spurChans[0]);
  472. mode = 0;
  473. }
  474. else {
  475. spurChansPtr = &(eep->modalHeader2G.spurChans[0]);
  476. mode = 1;
  477. }
  478. if (spurChansPtr[0] == 0)
  479. return; /* No spur in the mode */
  480. if (IS_CHAN_HT40(chan)) {
  481. range = 19;
  482. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  483. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  484. synth_freq = chan->channel - 10;
  485. else
  486. synth_freq = chan->channel + 10;
  487. } else {
  488. range = 10;
  489. synth_freq = chan->channel;
  490. }
  491. ar9003_hw_spur_ofdm_clear(ah);
  492. for (i = 0; i < AR_EEPROM_MODAL_SPURS && spurChansPtr[i]; i++) {
  493. freq_offset = ath9k_hw_fbin2freq(spurChansPtr[i], mode);
  494. freq_offset -= synth_freq;
  495. if (abs(freq_offset) < range) {
  496. ar9003_hw_spur_ofdm_work(ah, chan, freq_offset,
  497. range, synth_freq);
  498. if (AR_SREV_9565(ah) && (i < 4)) {
  499. freq_offset = ath9k_hw_fbin2freq(spurChansPtr[i + 1],
  500. mode);
  501. freq_offset -= synth_freq;
  502. if (abs(freq_offset) < range)
  503. ar9003_hw_spur_ofdm_9565(ah, freq_offset);
  504. }
  505. break;
  506. }
  507. }
  508. }
  509. static void ar9003_hw_spur_mitigate(struct ath_hw *ah,
  510. struct ath9k_channel *chan)
  511. {
  512. if (!AR_SREV_9565(ah))
  513. ar9003_hw_spur_mitigate_mrc_cck(ah, chan);
  514. ar9003_hw_spur_mitigate_ofdm(ah, chan);
  515. }
  516. static u32 ar9003_hw_compute_pll_control_soc(struct ath_hw *ah,
  517. struct ath9k_channel *chan)
  518. {
  519. u32 pll;
  520. pll = SM(0x5, AR_RTC_9300_SOC_PLL_REFDIV);
  521. if (chan && IS_CHAN_HALF_RATE(chan))
  522. pll |= SM(0x1, AR_RTC_9300_SOC_PLL_CLKSEL);
  523. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  524. pll |= SM(0x2, AR_RTC_9300_SOC_PLL_CLKSEL);
  525. pll |= SM(0x2c, AR_RTC_9300_SOC_PLL_DIV_INT);
  526. return pll;
  527. }
  528. static u32 ar9003_hw_compute_pll_control(struct ath_hw *ah,
  529. struct ath9k_channel *chan)
  530. {
  531. u32 pll;
  532. pll = SM(0x5, AR_RTC_9300_PLL_REFDIV);
  533. if (chan && IS_CHAN_HALF_RATE(chan))
  534. pll |= SM(0x1, AR_RTC_9300_PLL_CLKSEL);
  535. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  536. pll |= SM(0x2, AR_RTC_9300_PLL_CLKSEL);
  537. pll |= SM(0x2c, AR_RTC_9300_PLL_DIV);
  538. return pll;
  539. }
  540. static void ar9003_hw_set_channel_regs(struct ath_hw *ah,
  541. struct ath9k_channel *chan)
  542. {
  543. u32 phymode;
  544. u32 enableDacFifo = 0;
  545. enableDacFifo =
  546. (REG_READ(ah, AR_PHY_GEN_CTRL) & AR_PHY_GC_ENABLE_DAC_FIFO);
  547. /* Enable 11n HT, 20 MHz */
  548. phymode = AR_PHY_GC_HT_EN | AR_PHY_GC_SHORT_GI_40 | enableDacFifo;
  549. if (!AR_SREV_9561(ah))
  550. phymode |= AR_PHY_GC_SINGLE_HT_LTF1;
  551. /* Configure baseband for dynamic 20/40 operation */
  552. if (IS_CHAN_HT40(chan)) {
  553. phymode |= AR_PHY_GC_DYN2040_EN;
  554. /* Configure control (primary) channel at +-10MHz */
  555. if (IS_CHAN_HT40PLUS(chan))
  556. phymode |= AR_PHY_GC_DYN2040_PRI_CH;
  557. }
  558. /* make sure we preserve INI settings */
  559. phymode |= REG_READ(ah, AR_PHY_GEN_CTRL);
  560. /* turn off Green Field detection for STA for now */
  561. phymode &= ~AR_PHY_GC_GF_DETECT_EN;
  562. REG_WRITE(ah, AR_PHY_GEN_CTRL, phymode);
  563. /* Configure MAC for 20/40 operation */
  564. ath9k_hw_set11nmac2040(ah, chan);
  565. /* global transmit timeout (25 TUs default)*/
  566. REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
  567. /* carrier sense timeout */
  568. REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
  569. }
  570. static void ar9003_hw_init_bb(struct ath_hw *ah,
  571. struct ath9k_channel *chan)
  572. {
  573. u32 synthDelay;
  574. /*
  575. * Wait for the frequency synth to settle (synth goes on
  576. * via AR_PHY_ACTIVE_EN). Read the phy active delay register.
  577. * Value is in 100ns increments.
  578. */
  579. synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  580. /* Activate the PHY (includes baseband activate + synthesizer on) */
  581. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
  582. ath9k_hw_synth_delay(ah, chan, synthDelay);
  583. }
  584. void ar9003_hw_set_chain_masks(struct ath_hw *ah, u8 rx, u8 tx)
  585. {
  586. if (ah->caps.tx_chainmask == 5 || ah->caps.rx_chainmask == 5)
  587. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  588. AR_PHY_SWAP_ALT_CHAIN);
  589. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx);
  590. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx);
  591. if ((ah->caps.hw_caps & ATH9K_HW_CAP_APM) && (tx == 0x7))
  592. tx = 3;
  593. REG_WRITE(ah, AR_SELFGEN_MASK, tx);
  594. }
  595. /*
  596. * Override INI values with chip specific configuration.
  597. */
  598. static void ar9003_hw_override_ini(struct ath_hw *ah)
  599. {
  600. u32 val;
  601. /*
  602. * Set the RX_ABORT and RX_DIS and clear it only after
  603. * RXE is set for MAC. This prevents frames with
  604. * corrupted descriptor status.
  605. */
  606. REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  607. /*
  608. * For AR9280 and above, there is a new feature that allows
  609. * Multicast search based on both MAC Address and Key ID. By default,
  610. * this feature is enabled. But since the driver is not using this
  611. * feature, we switch it off; otherwise multicast search based on
  612. * MAC addr only will fail.
  613. */
  614. val = REG_READ(ah, AR_PCU_MISC_MODE2) & (~AR_ADHOC_MCAST_KEYID_ENABLE);
  615. val |= AR_AGG_WEP_ENABLE_FIX |
  616. AR_AGG_WEP_ENABLE |
  617. AR_PCU_MISC_MODE2_CFP_IGNORE;
  618. REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
  619. if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
  620. REG_WRITE(ah, AR_GLB_SWREG_DISCONT_MODE,
  621. AR_GLB_SWREG_DISCONT_EN_BT_WLAN);
  622. if (REG_READ_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_0,
  623. AR_PHY_TX_IQCAL_CONTROL_0_ENABLE_TXIQ_CAL))
  624. ah->enabled_cals |= TX_IQ_CAL;
  625. else
  626. ah->enabled_cals &= ~TX_IQ_CAL;
  627. }
  628. if (REG_READ(ah, AR_PHY_CL_CAL_CTL) & AR_PHY_CL_CAL_ENABLE)
  629. ah->enabled_cals |= TX_CL_CAL;
  630. else
  631. ah->enabled_cals &= ~TX_CL_CAL;
  632. if (AR_SREV_9340(ah) || AR_SREV_9531(ah) || AR_SREV_9550(ah) ||
  633. AR_SREV_9561(ah)) {
  634. if (ah->is_clk_25mhz) {
  635. REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x17c << 1);
  636. REG_WRITE(ah, AR_SLP32_MODE, 0x0010f3d7);
  637. REG_WRITE(ah, AR_SLP32_INC, 0x0001e7ae);
  638. } else {
  639. REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x261 << 1);
  640. REG_WRITE(ah, AR_SLP32_MODE, 0x0010f400);
  641. REG_WRITE(ah, AR_SLP32_INC, 0x0001e800);
  642. }
  643. udelay(100);
  644. }
  645. }
  646. static void ar9003_hw_prog_ini(struct ath_hw *ah,
  647. struct ar5416IniArray *iniArr,
  648. int column)
  649. {
  650. unsigned int i, regWrites = 0;
  651. /* New INI format: Array may be undefined (pre, core, post arrays) */
  652. if (!iniArr->ia_array)
  653. return;
  654. /*
  655. * New INI format: Pre, core, and post arrays for a given subsystem
  656. * may be modal (> 2 columns) or non-modal (2 columns). Determine if
  657. * the array is non-modal and force the column to 1.
  658. */
  659. if (column >= iniArr->ia_columns)
  660. column = 1;
  661. for (i = 0; i < iniArr->ia_rows; i++) {
  662. u32 reg = INI_RA(iniArr, i, 0);
  663. u32 val = INI_RA(iniArr, i, column);
  664. REG_WRITE(ah, reg, val);
  665. DO_DELAY(regWrites);
  666. }
  667. }
  668. static int ar9550_hw_get_modes_txgain_index(struct ath_hw *ah,
  669. struct ath9k_channel *chan)
  670. {
  671. int ret;
  672. if (IS_CHAN_2GHZ(chan)) {
  673. if (IS_CHAN_HT40(chan))
  674. return 7;
  675. else
  676. return 8;
  677. }
  678. if (chan->channel <= 5350)
  679. ret = 1;
  680. else if ((chan->channel > 5350) && (chan->channel <= 5600))
  681. ret = 3;
  682. else
  683. ret = 5;
  684. if (IS_CHAN_HT40(chan))
  685. ret++;
  686. return ret;
  687. }
  688. static int ar9561_hw_get_modes_txgain_index(struct ath_hw *ah,
  689. struct ath9k_channel *chan)
  690. {
  691. if (IS_CHAN_2GHZ(chan)) {
  692. if (IS_CHAN_HT40(chan))
  693. return 1;
  694. else
  695. return 2;
  696. }
  697. return 0;
  698. }
  699. static void ar9003_doubler_fix(struct ath_hw *ah)
  700. {
  701. if (AR_SREV_9300(ah) || AR_SREV_9580(ah) || AR_SREV_9550(ah)) {
  702. REG_RMW(ah, AR_PHY_65NM_CH0_RXTX2,
  703. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
  704. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S, 0);
  705. REG_RMW(ah, AR_PHY_65NM_CH1_RXTX2,
  706. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
  707. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S, 0);
  708. REG_RMW(ah, AR_PHY_65NM_CH2_RXTX2,
  709. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
  710. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S, 0);
  711. udelay(200);
  712. REG_CLR_BIT(ah, AR_PHY_65NM_CH0_RXTX2,
  713. AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK);
  714. REG_CLR_BIT(ah, AR_PHY_65NM_CH1_RXTX2,
  715. AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK);
  716. REG_CLR_BIT(ah, AR_PHY_65NM_CH2_RXTX2,
  717. AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK);
  718. udelay(1);
  719. REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_RXTX2,
  720. AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK, 1);
  721. REG_RMW_FIELD(ah, AR_PHY_65NM_CH1_RXTX2,
  722. AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK, 1);
  723. REG_RMW_FIELD(ah, AR_PHY_65NM_CH2_RXTX2,
  724. AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK, 1);
  725. udelay(200);
  726. REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_SYNTH12,
  727. AR_PHY_65NM_CH0_SYNTH12_VREFMUL3, 0xf);
  728. REG_RMW(ah, AR_PHY_65NM_CH0_RXTX2, 0,
  729. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
  730. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S);
  731. REG_RMW(ah, AR_PHY_65NM_CH1_RXTX2, 0,
  732. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
  733. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S);
  734. REG_RMW(ah, AR_PHY_65NM_CH2_RXTX2, 0,
  735. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
  736. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S);
  737. }
  738. }
  739. static int ar9003_hw_process_ini(struct ath_hw *ah,
  740. struct ath9k_channel *chan)
  741. {
  742. unsigned int regWrites = 0, i;
  743. u32 modesIndex;
  744. if (IS_CHAN_5GHZ(chan))
  745. modesIndex = IS_CHAN_HT40(chan) ? 2 : 1;
  746. else
  747. modesIndex = IS_CHAN_HT40(chan) ? 3 : 4;
  748. /*
  749. * SOC, MAC, BB, RADIO initvals.
  750. */
  751. for (i = 0; i < ATH_INI_NUM_SPLIT; i++) {
  752. ar9003_hw_prog_ini(ah, &ah->iniSOC[i], modesIndex);
  753. ar9003_hw_prog_ini(ah, &ah->iniMac[i], modesIndex);
  754. ar9003_hw_prog_ini(ah, &ah->iniBB[i], modesIndex);
  755. ar9003_hw_prog_ini(ah, &ah->iniRadio[i], modesIndex);
  756. if (i == ATH_INI_POST && AR_SREV_9462_20_OR_LATER(ah))
  757. ar9003_hw_prog_ini(ah,
  758. &ah->ini_radio_post_sys2ant,
  759. modesIndex);
  760. }
  761. ar9003_doubler_fix(ah);
  762. /*
  763. * RXGAIN initvals.
  764. */
  765. REG_WRITE_ARRAY(&ah->iniModesRxGain, 1, regWrites);
  766. if (AR_SREV_9462_20_OR_LATER(ah)) {
  767. /*
  768. * CUS217 mix LNA mode.
  769. */
  770. if (ar9003_hw_get_rx_gain_idx(ah) == 2) {
  771. REG_WRITE_ARRAY(&ah->ini_modes_rxgain_bb_core,
  772. 1, regWrites);
  773. REG_WRITE_ARRAY(&ah->ini_modes_rxgain_bb_postamble,
  774. modesIndex, regWrites);
  775. }
  776. /*
  777. * 5G-XLNA
  778. */
  779. if ((ar9003_hw_get_rx_gain_idx(ah) == 2) ||
  780. (ar9003_hw_get_rx_gain_idx(ah) == 3)) {
  781. REG_WRITE_ARRAY(&ah->ini_modes_rxgain_xlna,
  782. modesIndex, regWrites);
  783. }
  784. }
  785. if (AR_SREV_9550(ah) || AR_SREV_9561(ah))
  786. REG_WRITE_ARRAY(&ah->ini_modes_rx_gain_bounds, modesIndex,
  787. regWrites);
  788. if (AR_SREV_9561(ah) && (ar9003_hw_get_rx_gain_idx(ah) == 0))
  789. REG_WRITE_ARRAY(&ah->ini_modes_rxgain_xlna,
  790. modesIndex, regWrites);
  791. /*
  792. * TXGAIN initvals.
  793. */
  794. if (AR_SREV_9550(ah) || AR_SREV_9531(ah) || AR_SREV_9561(ah)) {
  795. int modes_txgain_index = 1;
  796. if (AR_SREV_9550(ah))
  797. modes_txgain_index = ar9550_hw_get_modes_txgain_index(ah, chan);
  798. if (AR_SREV_9561(ah))
  799. modes_txgain_index =
  800. ar9561_hw_get_modes_txgain_index(ah, chan);
  801. if (modes_txgain_index < 0)
  802. return -EINVAL;
  803. REG_WRITE_ARRAY(&ah->iniModesTxGain, modes_txgain_index,
  804. regWrites);
  805. } else {
  806. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  807. }
  808. /*
  809. * For 5GHz channels requiring Fast Clock, apply
  810. * different modal values.
  811. */
  812. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  813. REG_WRITE_ARRAY(&ah->iniModesFastClock,
  814. modesIndex, regWrites);
  815. /*
  816. * Clock frequency initvals.
  817. */
  818. REG_WRITE_ARRAY(&ah->iniAdditional, 1, regWrites);
  819. /*
  820. * JAPAN regulatory.
  821. */
  822. if (chan->channel == 2484) {
  823. ar9003_hw_prog_ini(ah, &ah->iniCckfirJapan2484, 1);
  824. if (AR_SREV_9531(ah))
  825. REG_RMW_FIELD(ah, AR_PHY_FCAL_2_0,
  826. AR_PHY_FLC_PWR_THRESH, 0);
  827. }
  828. ah->modes_index = modesIndex;
  829. ar9003_hw_override_ini(ah);
  830. ar9003_hw_set_channel_regs(ah, chan);
  831. ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
  832. ath9k_hw_apply_txpower(ah, chan, false);
  833. return 0;
  834. }
  835. static void ar9003_hw_set_rfmode(struct ath_hw *ah,
  836. struct ath9k_channel *chan)
  837. {
  838. u32 rfMode = 0;
  839. if (chan == NULL)
  840. return;
  841. if (IS_CHAN_2GHZ(chan))
  842. rfMode |= AR_PHY_MODE_DYNAMIC;
  843. else
  844. rfMode |= AR_PHY_MODE_OFDM;
  845. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  846. rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
  847. if (IS_CHAN_HALF_RATE(chan) || IS_CHAN_QUARTER_RATE(chan))
  848. REG_RMW_FIELD(ah, AR_PHY_FRAME_CTL,
  849. AR_PHY_FRAME_CTL_CF_OVERLAP_WINDOW, 3);
  850. REG_WRITE(ah, AR_PHY_MODE, rfMode);
  851. }
  852. static void ar9003_hw_mark_phy_inactive(struct ath_hw *ah)
  853. {
  854. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
  855. }
  856. static void ar9003_hw_set_delta_slope(struct ath_hw *ah,
  857. struct ath9k_channel *chan)
  858. {
  859. u32 coef_scaled, ds_coef_exp, ds_coef_man;
  860. u32 clockMhzScaled = 0x64000000;
  861. struct chan_centers centers;
  862. /*
  863. * half and quarter rate can divide the scaled clock by 2 or 4
  864. * scale for selected channel bandwidth
  865. */
  866. if (IS_CHAN_HALF_RATE(chan))
  867. clockMhzScaled = clockMhzScaled >> 1;
  868. else if (IS_CHAN_QUARTER_RATE(chan))
  869. clockMhzScaled = clockMhzScaled >> 2;
  870. /*
  871. * ALGO -> coef = 1e8/fcarrier*fclock/40;
  872. * scaled coef to provide precision for this floating calculation
  873. */
  874. ath9k_hw_get_channel_centers(ah, chan, &centers);
  875. coef_scaled = clockMhzScaled / centers.synth_center;
  876. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  877. &ds_coef_exp);
  878. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  879. AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
  880. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  881. AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
  882. /*
  883. * For Short GI,
  884. * scaled coeff is 9/10 that of normal coeff
  885. */
  886. coef_scaled = (9 * coef_scaled) / 10;
  887. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  888. &ds_coef_exp);
  889. /* for short gi */
  890. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  891. AR_PHY_SGI_DSC_MAN, ds_coef_man);
  892. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  893. AR_PHY_SGI_DSC_EXP, ds_coef_exp);
  894. }
  895. static bool ar9003_hw_rfbus_req(struct ath_hw *ah)
  896. {
  897. REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
  898. return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
  899. AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT);
  900. }
  901. /*
  902. * Wait for the frequency synth to settle (synth goes on via PHY_ACTIVE_EN).
  903. * Read the phy active delay register. Value is in 100ns increments.
  904. */
  905. static void ar9003_hw_rfbus_done(struct ath_hw *ah)
  906. {
  907. u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  908. ath9k_hw_synth_delay(ah, ah->curchan, synthDelay);
  909. REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
  910. }
  911. static bool ar9003_hw_ani_control(struct ath_hw *ah,
  912. enum ath9k_ani_cmd cmd, int param)
  913. {
  914. struct ath_common *common = ath9k_hw_common(ah);
  915. struct ath9k_channel *chan = ah->curchan;
  916. struct ar5416AniState *aniState = &ah->ani;
  917. int m1ThreshLow, m2ThreshLow;
  918. int m1Thresh, m2Thresh;
  919. int m2CountThr, m2CountThrLow;
  920. int m1ThreshLowExt, m2ThreshLowExt;
  921. int m1ThreshExt, m2ThreshExt;
  922. s32 value, value2;
  923. switch (cmd & ah->ani_function) {
  924. case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
  925. /*
  926. * on == 1 means ofdm weak signal detection is ON
  927. * on == 1 is the default, for less noise immunity
  928. *
  929. * on == 0 means ofdm weak signal detection is OFF
  930. * on == 0 means more noise imm
  931. */
  932. u32 on = param ? 1 : 0;
  933. if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
  934. goto skip_ws_det;
  935. m1ThreshLow = on ?
  936. aniState->iniDef.m1ThreshLow : m1ThreshLow_off;
  937. m2ThreshLow = on ?
  938. aniState->iniDef.m2ThreshLow : m2ThreshLow_off;
  939. m1Thresh = on ?
  940. aniState->iniDef.m1Thresh : m1Thresh_off;
  941. m2Thresh = on ?
  942. aniState->iniDef.m2Thresh : m2Thresh_off;
  943. m2CountThr = on ?
  944. aniState->iniDef.m2CountThr : m2CountThr_off;
  945. m2CountThrLow = on ?
  946. aniState->iniDef.m2CountThrLow : m2CountThrLow_off;
  947. m1ThreshLowExt = on ?
  948. aniState->iniDef.m1ThreshLowExt : m1ThreshLowExt_off;
  949. m2ThreshLowExt = on ?
  950. aniState->iniDef.m2ThreshLowExt : m2ThreshLowExt_off;
  951. m1ThreshExt = on ?
  952. aniState->iniDef.m1ThreshExt : m1ThreshExt_off;
  953. m2ThreshExt = on ?
  954. aniState->iniDef.m2ThreshExt : m2ThreshExt_off;
  955. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  956. AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
  957. m1ThreshLow);
  958. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  959. AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
  960. m2ThreshLow);
  961. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  962. AR_PHY_SFCORR_M1_THRESH,
  963. m1Thresh);
  964. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  965. AR_PHY_SFCORR_M2_THRESH,
  966. m2Thresh);
  967. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  968. AR_PHY_SFCORR_M2COUNT_THR,
  969. m2CountThr);
  970. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  971. AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
  972. m2CountThrLow);
  973. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  974. AR_PHY_SFCORR_EXT_M1_THRESH_LOW,
  975. m1ThreshLowExt);
  976. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  977. AR_PHY_SFCORR_EXT_M2_THRESH_LOW,
  978. m2ThreshLowExt);
  979. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  980. AR_PHY_SFCORR_EXT_M1_THRESH,
  981. m1ThreshExt);
  982. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  983. AR_PHY_SFCORR_EXT_M2_THRESH,
  984. m2ThreshExt);
  985. skip_ws_det:
  986. if (on)
  987. REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
  988. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  989. else
  990. REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
  991. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  992. if (on != aniState->ofdmWeakSigDetect) {
  993. ath_dbg(common, ANI,
  994. "** ch %d: ofdm weak signal: %s=>%s\n",
  995. chan->channel,
  996. aniState->ofdmWeakSigDetect ?
  997. "on" : "off",
  998. on ? "on" : "off");
  999. if (on)
  1000. ah->stats.ast_ani_ofdmon++;
  1001. else
  1002. ah->stats.ast_ani_ofdmoff++;
  1003. aniState->ofdmWeakSigDetect = on;
  1004. }
  1005. break;
  1006. }
  1007. case ATH9K_ANI_FIRSTEP_LEVEL:{
  1008. u32 level = param;
  1009. if (level >= ARRAY_SIZE(firstep_table)) {
  1010. ath_dbg(common, ANI,
  1011. "ATH9K_ANI_FIRSTEP_LEVEL: level out of range (%u > %zu)\n",
  1012. level, ARRAY_SIZE(firstep_table));
  1013. return false;
  1014. }
  1015. /*
  1016. * make register setting relative to default
  1017. * from INI file & cap value
  1018. */
  1019. value = firstep_table[level] -
  1020. firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
  1021. aniState->iniDef.firstep;
  1022. if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  1023. value = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  1024. if (value > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  1025. value = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  1026. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  1027. AR_PHY_FIND_SIG_FIRSTEP,
  1028. value);
  1029. /*
  1030. * we need to set first step low register too
  1031. * make register setting relative to default
  1032. * from INI file & cap value
  1033. */
  1034. value2 = firstep_table[level] -
  1035. firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
  1036. aniState->iniDef.firstepLow;
  1037. if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  1038. value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  1039. if (value2 > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  1040. value2 = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  1041. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
  1042. AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW, value2);
  1043. if (level != aniState->firstepLevel) {
  1044. ath_dbg(common, ANI,
  1045. "** ch %d: level %d=>%d[def:%d] firstep[level]=%d ini=%d\n",
  1046. chan->channel,
  1047. aniState->firstepLevel,
  1048. level,
  1049. ATH9K_ANI_FIRSTEP_LVL,
  1050. value,
  1051. aniState->iniDef.firstep);
  1052. ath_dbg(common, ANI,
  1053. "** ch %d: level %d=>%d[def:%d] firstep_low[level]=%d ini=%d\n",
  1054. chan->channel,
  1055. aniState->firstepLevel,
  1056. level,
  1057. ATH9K_ANI_FIRSTEP_LVL,
  1058. value2,
  1059. aniState->iniDef.firstepLow);
  1060. if (level > aniState->firstepLevel)
  1061. ah->stats.ast_ani_stepup++;
  1062. else if (level < aniState->firstepLevel)
  1063. ah->stats.ast_ani_stepdown++;
  1064. aniState->firstepLevel = level;
  1065. }
  1066. break;
  1067. }
  1068. case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
  1069. u32 level = param;
  1070. if (level >= ARRAY_SIZE(cycpwrThr1_table)) {
  1071. ath_dbg(common, ANI,
  1072. "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level out of range (%u > %zu)\n",
  1073. level, ARRAY_SIZE(cycpwrThr1_table));
  1074. return false;
  1075. }
  1076. /*
  1077. * make register setting relative to default
  1078. * from INI file & cap value
  1079. */
  1080. value = cycpwrThr1_table[level] -
  1081. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
  1082. aniState->iniDef.cycpwrThr1;
  1083. if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  1084. value = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  1085. if (value > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  1086. value = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  1087. REG_RMW_FIELD(ah, AR_PHY_TIMING5,
  1088. AR_PHY_TIMING5_CYCPWR_THR1,
  1089. value);
  1090. /*
  1091. * set AR_PHY_EXT_CCA for extension channel
  1092. * make register setting relative to default
  1093. * from INI file & cap value
  1094. */
  1095. value2 = cycpwrThr1_table[level] -
  1096. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
  1097. aniState->iniDef.cycpwrThr1Ext;
  1098. if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  1099. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  1100. if (value2 > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  1101. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  1102. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
  1103. AR_PHY_EXT_CYCPWR_THR1, value2);
  1104. if (level != aniState->spurImmunityLevel) {
  1105. ath_dbg(common, ANI,
  1106. "** ch %d: level %d=>%d[def:%d] cycpwrThr1[level]=%d ini=%d\n",
  1107. chan->channel,
  1108. aniState->spurImmunityLevel,
  1109. level,
  1110. ATH9K_ANI_SPUR_IMMUNE_LVL,
  1111. value,
  1112. aniState->iniDef.cycpwrThr1);
  1113. ath_dbg(common, ANI,
  1114. "** ch %d: level %d=>%d[def:%d] cycpwrThr1Ext[level]=%d ini=%d\n",
  1115. chan->channel,
  1116. aniState->spurImmunityLevel,
  1117. level,
  1118. ATH9K_ANI_SPUR_IMMUNE_LVL,
  1119. value2,
  1120. aniState->iniDef.cycpwrThr1Ext);
  1121. if (level > aniState->spurImmunityLevel)
  1122. ah->stats.ast_ani_spurup++;
  1123. else if (level < aniState->spurImmunityLevel)
  1124. ah->stats.ast_ani_spurdown++;
  1125. aniState->spurImmunityLevel = level;
  1126. }
  1127. break;
  1128. }
  1129. case ATH9K_ANI_MRC_CCK:{
  1130. /*
  1131. * is_on == 1 means MRC CCK ON (default, less noise imm)
  1132. * is_on == 0 means MRC CCK is OFF (more noise imm)
  1133. */
  1134. bool is_on = param ? 1 : 0;
  1135. if (ah->caps.rx_chainmask == 1)
  1136. break;
  1137. REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
  1138. AR_PHY_MRC_CCK_ENABLE, is_on);
  1139. REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
  1140. AR_PHY_MRC_CCK_MUX_REG, is_on);
  1141. if (is_on != aniState->mrcCCK) {
  1142. ath_dbg(common, ANI, "** ch %d: MRC CCK: %s=>%s\n",
  1143. chan->channel,
  1144. aniState->mrcCCK ? "on" : "off",
  1145. is_on ? "on" : "off");
  1146. if (is_on)
  1147. ah->stats.ast_ani_ccklow++;
  1148. else
  1149. ah->stats.ast_ani_cckhigh++;
  1150. aniState->mrcCCK = is_on;
  1151. }
  1152. break;
  1153. }
  1154. default:
  1155. ath_dbg(common, ANI, "invalid cmd %u\n", cmd);
  1156. return false;
  1157. }
  1158. ath_dbg(common, ANI,
  1159. "ANI parameters: SI=%d, ofdmWS=%s FS=%d MRCcck=%s listenTime=%d ofdmErrs=%d cckErrs=%d\n",
  1160. aniState->spurImmunityLevel,
  1161. aniState->ofdmWeakSigDetect ? "on" : "off",
  1162. aniState->firstepLevel,
  1163. aniState->mrcCCK ? "on" : "off",
  1164. aniState->listenTime,
  1165. aniState->ofdmPhyErrCount,
  1166. aniState->cckPhyErrCount);
  1167. return true;
  1168. }
  1169. static void ar9003_hw_do_getnf(struct ath_hw *ah,
  1170. int16_t nfarray[NUM_NF_READINGS])
  1171. {
  1172. #define AR_PHY_CH_MINCCA_PWR 0x1FF00000
  1173. #define AR_PHY_CH_MINCCA_PWR_S 20
  1174. #define AR_PHY_CH_EXT_MINCCA_PWR 0x01FF0000
  1175. #define AR_PHY_CH_EXT_MINCCA_PWR_S 16
  1176. int16_t nf;
  1177. int i;
  1178. for (i = 0; i < AR9300_MAX_CHAINS; i++) {
  1179. if (ah->rxchainmask & BIT(i)) {
  1180. nf = MS(REG_READ(ah, ah->nf_regs[i]),
  1181. AR_PHY_CH_MINCCA_PWR);
  1182. nfarray[i] = sign_extend32(nf, 8);
  1183. if (IS_CHAN_HT40(ah->curchan)) {
  1184. u8 ext_idx = AR9300_MAX_CHAINS + i;
  1185. nf = MS(REG_READ(ah, ah->nf_regs[ext_idx]),
  1186. AR_PHY_CH_EXT_MINCCA_PWR);
  1187. nfarray[ext_idx] = sign_extend32(nf, 8);
  1188. }
  1189. }
  1190. }
  1191. }
  1192. static void ar9003_hw_set_nf_limits(struct ath_hw *ah)
  1193. {
  1194. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_2GHZ;
  1195. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_2GHZ;
  1196. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9300_2GHZ;
  1197. ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_5GHZ;
  1198. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_5GHZ;
  1199. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9300_5GHZ;
  1200. if (AR_SREV_9330(ah))
  1201. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9330_2GHZ;
  1202. if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
  1203. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9462_2GHZ;
  1204. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9462_2GHZ;
  1205. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9462_5GHZ;
  1206. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9462_5GHZ;
  1207. }
  1208. }
  1209. /*
  1210. * Initialize the ANI register values with default (ini) values.
  1211. * This routine is called during a (full) hardware reset after
  1212. * all the registers are initialised from the INI.
  1213. */
  1214. static void ar9003_hw_ani_cache_ini_regs(struct ath_hw *ah)
  1215. {
  1216. struct ar5416AniState *aniState;
  1217. struct ath_common *common = ath9k_hw_common(ah);
  1218. struct ath9k_channel *chan = ah->curchan;
  1219. struct ath9k_ani_default *iniDef;
  1220. u32 val;
  1221. aniState = &ah->ani;
  1222. iniDef = &aniState->iniDef;
  1223. ath_dbg(common, ANI, "ver %d.%d opmode %u chan %d Mhz\n",
  1224. ah->hw_version.macVersion,
  1225. ah->hw_version.macRev,
  1226. ah->opmode,
  1227. chan->channel);
  1228. val = REG_READ(ah, AR_PHY_SFCORR);
  1229. iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH);
  1230. iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH);
  1231. iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR);
  1232. val = REG_READ(ah, AR_PHY_SFCORR_LOW);
  1233. iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW);
  1234. iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW);
  1235. iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW);
  1236. val = REG_READ(ah, AR_PHY_SFCORR_EXT);
  1237. iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH);
  1238. iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH);
  1239. iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW);
  1240. iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW);
  1241. iniDef->firstep = REG_READ_FIELD(ah,
  1242. AR_PHY_FIND_SIG,
  1243. AR_PHY_FIND_SIG_FIRSTEP);
  1244. iniDef->firstepLow = REG_READ_FIELD(ah,
  1245. AR_PHY_FIND_SIG_LOW,
  1246. AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW);
  1247. iniDef->cycpwrThr1 = REG_READ_FIELD(ah,
  1248. AR_PHY_TIMING5,
  1249. AR_PHY_TIMING5_CYCPWR_THR1);
  1250. iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah,
  1251. AR_PHY_EXT_CCA,
  1252. AR_PHY_EXT_CYCPWR_THR1);
  1253. /* these levels just got reset to defaults by the INI */
  1254. aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL;
  1255. aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL;
  1256. aniState->ofdmWeakSigDetect = true;
  1257. aniState->mrcCCK = true;
  1258. }
  1259. static void ar9003_hw_set_radar_params(struct ath_hw *ah,
  1260. struct ath_hw_radar_conf *conf)
  1261. {
  1262. unsigned int regWrites = 0;
  1263. u32 radar_0 = 0, radar_1;
  1264. if (!conf) {
  1265. REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA);
  1266. return;
  1267. }
  1268. radar_0 |= AR_PHY_RADAR_0_ENA | AR_PHY_RADAR_0_FFT_ENA;
  1269. radar_0 |= SM(conf->fir_power, AR_PHY_RADAR_0_FIRPWR);
  1270. radar_0 |= SM(conf->radar_rssi, AR_PHY_RADAR_0_RRSSI);
  1271. radar_0 |= SM(conf->pulse_height, AR_PHY_RADAR_0_HEIGHT);
  1272. radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI);
  1273. radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND);
  1274. radar_1 = REG_READ(ah, AR_PHY_RADAR_1);
  1275. radar_1 &= ~(AR_PHY_RADAR_1_MAXLEN | AR_PHY_RADAR_1_RELSTEP_THRESH |
  1276. AR_PHY_RADAR_1_RELPWR_THRESH);
  1277. radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI;
  1278. radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK;
  1279. radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN);
  1280. radar_1 |= SM(conf->pulse_inband_step, AR_PHY_RADAR_1_RELSTEP_THRESH);
  1281. radar_1 |= SM(conf->radar_inband, AR_PHY_RADAR_1_RELPWR_THRESH);
  1282. REG_WRITE(ah, AR_PHY_RADAR_0, radar_0);
  1283. REG_WRITE(ah, AR_PHY_RADAR_1, radar_1);
  1284. if (conf->ext_channel)
  1285. REG_SET_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1286. else
  1287. REG_CLR_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1288. if (AR_SREV_9300(ah) || AR_SREV_9340(ah) || AR_SREV_9580(ah)) {
  1289. REG_WRITE_ARRAY(&ah->ini_dfs,
  1290. IS_CHAN_HT40(ah->curchan) ? 2 : 1, regWrites);
  1291. }
  1292. }
  1293. static void ar9003_hw_set_radar_conf(struct ath_hw *ah)
  1294. {
  1295. struct ath_hw_radar_conf *conf = &ah->radar_conf;
  1296. conf->fir_power = -28;
  1297. conf->radar_rssi = 0;
  1298. conf->pulse_height = 10;
  1299. conf->pulse_rssi = 15;
  1300. conf->pulse_inband = 8;
  1301. conf->pulse_maxlen = 255;
  1302. conf->pulse_inband_step = 12;
  1303. conf->radar_inband = 8;
  1304. }
  1305. static void ar9003_hw_antdiv_comb_conf_get(struct ath_hw *ah,
  1306. struct ath_hw_antcomb_conf *antconf)
  1307. {
  1308. u32 regval;
  1309. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1310. antconf->main_lna_conf = (regval & AR_PHY_ANT_DIV_MAIN_LNACONF) >>
  1311. AR_PHY_ANT_DIV_MAIN_LNACONF_S;
  1312. antconf->alt_lna_conf = (regval & AR_PHY_ANT_DIV_ALT_LNACONF) >>
  1313. AR_PHY_ANT_DIV_ALT_LNACONF_S;
  1314. antconf->fast_div_bias = (regval & AR_PHY_ANT_FAST_DIV_BIAS) >>
  1315. AR_PHY_ANT_FAST_DIV_BIAS_S;
  1316. if (AR_SREV_9330_11(ah)) {
  1317. antconf->lna1_lna2_switch_delta = -1;
  1318. antconf->lna1_lna2_delta = -9;
  1319. antconf->div_group = 1;
  1320. } else if (AR_SREV_9485(ah)) {
  1321. antconf->lna1_lna2_switch_delta = -1;
  1322. antconf->lna1_lna2_delta = -9;
  1323. antconf->div_group = 2;
  1324. } else if (AR_SREV_9565(ah)) {
  1325. antconf->lna1_lna2_switch_delta = 3;
  1326. antconf->lna1_lna2_delta = -9;
  1327. antconf->div_group = 3;
  1328. } else {
  1329. antconf->lna1_lna2_switch_delta = -1;
  1330. antconf->lna1_lna2_delta = -3;
  1331. antconf->div_group = 0;
  1332. }
  1333. }
  1334. static void ar9003_hw_antdiv_comb_conf_set(struct ath_hw *ah,
  1335. struct ath_hw_antcomb_conf *antconf)
  1336. {
  1337. u32 regval;
  1338. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1339. regval &= ~(AR_PHY_ANT_DIV_MAIN_LNACONF |
  1340. AR_PHY_ANT_DIV_ALT_LNACONF |
  1341. AR_PHY_ANT_FAST_DIV_BIAS |
  1342. AR_PHY_ANT_DIV_MAIN_GAINTB |
  1343. AR_PHY_ANT_DIV_ALT_GAINTB);
  1344. regval |= ((antconf->main_lna_conf << AR_PHY_ANT_DIV_MAIN_LNACONF_S)
  1345. & AR_PHY_ANT_DIV_MAIN_LNACONF);
  1346. regval |= ((antconf->alt_lna_conf << AR_PHY_ANT_DIV_ALT_LNACONF_S)
  1347. & AR_PHY_ANT_DIV_ALT_LNACONF);
  1348. regval |= ((antconf->fast_div_bias << AR_PHY_ANT_FAST_DIV_BIAS_S)
  1349. & AR_PHY_ANT_FAST_DIV_BIAS);
  1350. regval |= ((antconf->main_gaintb << AR_PHY_ANT_DIV_MAIN_GAINTB_S)
  1351. & AR_PHY_ANT_DIV_MAIN_GAINTB);
  1352. regval |= ((antconf->alt_gaintb << AR_PHY_ANT_DIV_ALT_GAINTB_S)
  1353. & AR_PHY_ANT_DIV_ALT_GAINTB);
  1354. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1355. }
  1356. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  1357. static void ar9003_hw_set_bt_ant_diversity(struct ath_hw *ah, bool enable)
  1358. {
  1359. struct ath9k_hw_capabilities *pCap = &ah->caps;
  1360. u8 ant_div_ctl1;
  1361. u32 regval;
  1362. if (!AR_SREV_9485(ah) && !AR_SREV_9565(ah))
  1363. return;
  1364. if (AR_SREV_9485(ah)) {
  1365. regval = ar9003_hw_ant_ctrl_common_2_get(ah,
  1366. IS_CHAN_2GHZ(ah->curchan));
  1367. if (enable) {
  1368. regval &= ~AR_SWITCH_TABLE_COM2_ALL;
  1369. regval |= ah->config.ant_ctrl_comm2g_switch_enable;
  1370. }
  1371. REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM_2,
  1372. AR_SWITCH_TABLE_COM2_ALL, regval);
  1373. }
  1374. ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
  1375. /*
  1376. * Set MAIN/ALT LNA conf.
  1377. * Set MAIN/ALT gain_tb.
  1378. */
  1379. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1380. regval &= (~AR_ANT_DIV_CTRL_ALL);
  1381. regval |= (ant_div_ctl1 & 0x3f) << AR_ANT_DIV_CTRL_ALL_S;
  1382. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1383. if (AR_SREV_9485_11_OR_LATER(ah)) {
  1384. /*
  1385. * Enable LNA diversity.
  1386. */
  1387. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1388. regval &= ~AR_PHY_ANT_DIV_LNADIV;
  1389. regval |= ((ant_div_ctl1 >> 6) & 0x1) << AR_PHY_ANT_DIV_LNADIV_S;
  1390. if (enable)
  1391. regval |= AR_ANT_DIV_ENABLE;
  1392. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1393. /*
  1394. * Enable fast antenna diversity.
  1395. */
  1396. regval = REG_READ(ah, AR_PHY_CCK_DETECT);
  1397. regval &= ~AR_FAST_DIV_ENABLE;
  1398. regval |= ((ant_div_ctl1 >> 7) & 0x1) << AR_FAST_DIV_ENABLE_S;
  1399. if (enable)
  1400. regval |= AR_FAST_DIV_ENABLE;
  1401. REG_WRITE(ah, AR_PHY_CCK_DETECT, regval);
  1402. if (pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) {
  1403. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1404. regval &= (~(AR_PHY_ANT_DIV_MAIN_LNACONF |
  1405. AR_PHY_ANT_DIV_ALT_LNACONF |
  1406. AR_PHY_ANT_DIV_ALT_GAINTB |
  1407. AR_PHY_ANT_DIV_MAIN_GAINTB));
  1408. /*
  1409. * Set MAIN to LNA1 and ALT to LNA2 at the
  1410. * beginning.
  1411. */
  1412. regval |= (ATH_ANT_DIV_COMB_LNA1 <<
  1413. AR_PHY_ANT_DIV_MAIN_LNACONF_S);
  1414. regval |= (ATH_ANT_DIV_COMB_LNA2 <<
  1415. AR_PHY_ANT_DIV_ALT_LNACONF_S);
  1416. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1417. }
  1418. } else if (AR_SREV_9565(ah)) {
  1419. if (enable) {
  1420. REG_SET_BIT(ah, AR_PHY_MC_GAIN_CTRL,
  1421. AR_ANT_DIV_ENABLE);
  1422. REG_SET_BIT(ah, AR_PHY_MC_GAIN_CTRL,
  1423. (1 << AR_PHY_ANT_SW_RX_PROT_S));
  1424. REG_SET_BIT(ah, AR_PHY_CCK_DETECT,
  1425. AR_FAST_DIV_ENABLE);
  1426. REG_SET_BIT(ah, AR_PHY_RESTART,
  1427. AR_PHY_RESTART_ENABLE_DIV_M2FLAG);
  1428. REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV,
  1429. AR_BTCOEX_WL_LNADIV_FORCE_ON);
  1430. } else {
  1431. REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL,
  1432. AR_ANT_DIV_ENABLE);
  1433. REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL,
  1434. (1 << AR_PHY_ANT_SW_RX_PROT_S));
  1435. REG_CLR_BIT(ah, AR_PHY_CCK_DETECT,
  1436. AR_FAST_DIV_ENABLE);
  1437. REG_CLR_BIT(ah, AR_PHY_RESTART,
  1438. AR_PHY_RESTART_ENABLE_DIV_M2FLAG);
  1439. REG_CLR_BIT(ah, AR_BTCOEX_WL_LNADIV,
  1440. AR_BTCOEX_WL_LNADIV_FORCE_ON);
  1441. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1442. regval &= ~(AR_PHY_ANT_DIV_MAIN_LNACONF |
  1443. AR_PHY_ANT_DIV_ALT_LNACONF |
  1444. AR_PHY_ANT_DIV_MAIN_GAINTB |
  1445. AR_PHY_ANT_DIV_ALT_GAINTB);
  1446. regval |= (ATH_ANT_DIV_COMB_LNA1 <<
  1447. AR_PHY_ANT_DIV_MAIN_LNACONF_S);
  1448. regval |= (ATH_ANT_DIV_COMB_LNA2 <<
  1449. AR_PHY_ANT_DIV_ALT_LNACONF_S);
  1450. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1451. }
  1452. }
  1453. }
  1454. #endif
  1455. static int ar9003_hw_fast_chan_change(struct ath_hw *ah,
  1456. struct ath9k_channel *chan,
  1457. u8 *ini_reloaded)
  1458. {
  1459. unsigned int regWrites = 0;
  1460. u32 modesIndex, txgain_index;
  1461. if (IS_CHAN_5GHZ(chan))
  1462. modesIndex = IS_CHAN_HT40(chan) ? 2 : 1;
  1463. else
  1464. modesIndex = IS_CHAN_HT40(chan) ? 3 : 4;
  1465. txgain_index = AR_SREV_9531(ah) ? 1 : modesIndex;
  1466. if (modesIndex == ah->modes_index) {
  1467. *ini_reloaded = false;
  1468. goto set_rfmode;
  1469. }
  1470. ar9003_hw_prog_ini(ah, &ah->iniSOC[ATH_INI_POST], modesIndex);
  1471. ar9003_hw_prog_ini(ah, &ah->iniMac[ATH_INI_POST], modesIndex);
  1472. ar9003_hw_prog_ini(ah, &ah->iniBB[ATH_INI_POST], modesIndex);
  1473. ar9003_hw_prog_ini(ah, &ah->iniRadio[ATH_INI_POST], modesIndex);
  1474. if (AR_SREV_9462_20_OR_LATER(ah))
  1475. ar9003_hw_prog_ini(ah, &ah->ini_radio_post_sys2ant,
  1476. modesIndex);
  1477. REG_WRITE_ARRAY(&ah->iniModesTxGain, txgain_index, regWrites);
  1478. if (AR_SREV_9462_20_OR_LATER(ah)) {
  1479. /*
  1480. * CUS217 mix LNA mode.
  1481. */
  1482. if (ar9003_hw_get_rx_gain_idx(ah) == 2) {
  1483. REG_WRITE_ARRAY(&ah->ini_modes_rxgain_bb_core,
  1484. 1, regWrites);
  1485. REG_WRITE_ARRAY(&ah->ini_modes_rxgain_bb_postamble,
  1486. modesIndex, regWrites);
  1487. }
  1488. }
  1489. /*
  1490. * For 5GHz channels requiring Fast Clock, apply
  1491. * different modal values.
  1492. */
  1493. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  1494. REG_WRITE_ARRAY(&ah->iniModesFastClock, modesIndex, regWrites);
  1495. if (AR_SREV_9565(ah))
  1496. REG_WRITE_ARRAY(&ah->iniModesFastClock, 1, regWrites);
  1497. /*
  1498. * JAPAN regulatory.
  1499. */
  1500. if (chan->channel == 2484)
  1501. ar9003_hw_prog_ini(ah, &ah->iniCckfirJapan2484, 1);
  1502. ah->modes_index = modesIndex;
  1503. *ini_reloaded = true;
  1504. set_rfmode:
  1505. ar9003_hw_set_rfmode(ah, chan);
  1506. return 0;
  1507. }
  1508. static void ar9003_hw_spectral_scan_config(struct ath_hw *ah,
  1509. struct ath_spec_scan *param)
  1510. {
  1511. u8 count;
  1512. if (!param->enabled) {
  1513. REG_CLR_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  1514. AR_PHY_SPECTRAL_SCAN_ENABLE);
  1515. return;
  1516. }
  1517. REG_SET_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_FFT_ENA);
  1518. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN, AR_PHY_SPECTRAL_SCAN_ENABLE);
  1519. /* on AR93xx and newer, count = 0 will make the the chip send
  1520. * spectral samples endlessly. Check if this really was intended,
  1521. * and fix otherwise.
  1522. */
  1523. count = param->count;
  1524. if (param->endless)
  1525. count = 0;
  1526. else if (param->count == 0)
  1527. count = 1;
  1528. if (param->short_repeat)
  1529. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  1530. AR_PHY_SPECTRAL_SCAN_SHORT_REPEAT);
  1531. else
  1532. REG_CLR_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  1533. AR_PHY_SPECTRAL_SCAN_SHORT_REPEAT);
  1534. REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN,
  1535. AR_PHY_SPECTRAL_SCAN_COUNT, count);
  1536. REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN,
  1537. AR_PHY_SPECTRAL_SCAN_PERIOD, param->period);
  1538. REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN,
  1539. AR_PHY_SPECTRAL_SCAN_FFT_PERIOD, param->fft_period);
  1540. return;
  1541. }
  1542. static void ar9003_hw_spectral_scan_trigger(struct ath_hw *ah)
  1543. {
  1544. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  1545. AR_PHY_SPECTRAL_SCAN_ENABLE);
  1546. /* Activate spectral scan */
  1547. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  1548. AR_PHY_SPECTRAL_SCAN_ACTIVE);
  1549. }
  1550. static void ar9003_hw_spectral_scan_wait(struct ath_hw *ah)
  1551. {
  1552. struct ath_common *common = ath9k_hw_common(ah);
  1553. /* Poll for spectral scan complete */
  1554. if (!ath9k_hw_wait(ah, AR_PHY_SPECTRAL_SCAN,
  1555. AR_PHY_SPECTRAL_SCAN_ACTIVE,
  1556. 0, AH_WAIT_TIMEOUT)) {
  1557. ath_err(common, "spectral scan wait failed\n");
  1558. return;
  1559. }
  1560. }
  1561. static void ar9003_hw_tx99_start(struct ath_hw *ah, u32 qnum)
  1562. {
  1563. REG_SET_BIT(ah, AR_PHY_TEST, PHY_AGC_CLR);
  1564. REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
  1565. REG_WRITE(ah, AR_CR, AR_CR_RXD);
  1566. REG_WRITE(ah, AR_DLCL_IFS(qnum), 0);
  1567. REG_WRITE(ah, AR_D_GBL_IFS_SIFS, 20); /* 50 OK */
  1568. REG_WRITE(ah, AR_D_GBL_IFS_EIFS, 20);
  1569. REG_WRITE(ah, AR_TIME_OUT, 0x00000400);
  1570. REG_WRITE(ah, AR_DRETRY_LIMIT(qnum), 0xffffffff);
  1571. REG_SET_BIT(ah, AR_QMISC(qnum), AR_Q_MISC_DCU_EARLY_TERM_REQ);
  1572. }
  1573. static void ar9003_hw_tx99_stop(struct ath_hw *ah)
  1574. {
  1575. REG_CLR_BIT(ah, AR_PHY_TEST, PHY_AGC_CLR);
  1576. REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
  1577. }
  1578. static void ar9003_hw_tx99_set_txpower(struct ath_hw *ah, u8 txpower)
  1579. {
  1580. static u8 p_pwr_array[ar9300RateSize] = { 0 };
  1581. unsigned int i;
  1582. txpower = txpower <= MAX_RATE_POWER ? txpower : MAX_RATE_POWER;
  1583. for (i = 0; i < ar9300RateSize; i++)
  1584. p_pwr_array[i] = txpower;
  1585. ar9003_hw_tx_power_regwrite(ah, p_pwr_array);
  1586. }
  1587. static void ar9003_hw_init_txpower_cck(struct ath_hw *ah, u8 *rate_array)
  1588. {
  1589. ah->tx_power[0] = rate_array[ALL_TARGET_LEGACY_1L_5L];
  1590. ah->tx_power[1] = rate_array[ALL_TARGET_LEGACY_1L_5L];
  1591. ah->tx_power[2] = min(rate_array[ALL_TARGET_LEGACY_1L_5L],
  1592. rate_array[ALL_TARGET_LEGACY_5S]);
  1593. ah->tx_power[3] = min(rate_array[ALL_TARGET_LEGACY_11L],
  1594. rate_array[ALL_TARGET_LEGACY_11S]);
  1595. }
  1596. static void ar9003_hw_init_txpower_ofdm(struct ath_hw *ah, u8 *rate_array,
  1597. int offset)
  1598. {
  1599. int i, j;
  1600. for (i = offset; i < offset + AR9300_OFDM_RATES; i++) {
  1601. /* OFDM rate to power table idx */
  1602. j = ofdm2pwr[i - offset];
  1603. ah->tx_power[i] = rate_array[j];
  1604. }
  1605. }
  1606. static void ar9003_hw_init_txpower_ht(struct ath_hw *ah, u8 *rate_array,
  1607. int ss_offset, int ds_offset,
  1608. int ts_offset, bool is_40)
  1609. {
  1610. int i, j, mcs_idx = 0;
  1611. const u8 *mcs2pwr = (is_40) ? mcs2pwr_ht40 : mcs2pwr_ht20;
  1612. for (i = ss_offset; i < ss_offset + AR9300_HT_SS_RATES; i++) {
  1613. j = mcs2pwr[mcs_idx];
  1614. ah->tx_power[i] = rate_array[j];
  1615. mcs_idx++;
  1616. }
  1617. for (i = ds_offset; i < ds_offset + AR9300_HT_DS_RATES; i++) {
  1618. j = mcs2pwr[mcs_idx];
  1619. ah->tx_power[i] = rate_array[j];
  1620. mcs_idx++;
  1621. }
  1622. for (i = ts_offset; i < ts_offset + AR9300_HT_TS_RATES; i++) {
  1623. j = mcs2pwr[mcs_idx];
  1624. ah->tx_power[i] = rate_array[j];
  1625. mcs_idx++;
  1626. }
  1627. }
  1628. static void ar9003_hw_init_txpower_stbc(struct ath_hw *ah, int ss_offset,
  1629. int ds_offset, int ts_offset)
  1630. {
  1631. memcpy(&ah->tx_power_stbc[ss_offset], &ah->tx_power[ss_offset],
  1632. AR9300_HT_SS_RATES);
  1633. memcpy(&ah->tx_power_stbc[ds_offset], &ah->tx_power[ds_offset],
  1634. AR9300_HT_DS_RATES);
  1635. memcpy(&ah->tx_power_stbc[ts_offset], &ah->tx_power[ts_offset],
  1636. AR9300_HT_TS_RATES);
  1637. }
  1638. void ar9003_hw_init_rate_txpower(struct ath_hw *ah, u8 *rate_array,
  1639. struct ath9k_channel *chan)
  1640. {
  1641. if (IS_CHAN_5GHZ(chan)) {
  1642. ar9003_hw_init_txpower_ofdm(ah, rate_array,
  1643. AR9300_11NA_OFDM_SHIFT);
  1644. if (IS_CHAN_HT20(chan) || IS_CHAN_HT40(chan)) {
  1645. ar9003_hw_init_txpower_ht(ah, rate_array,
  1646. AR9300_11NA_HT_SS_SHIFT,
  1647. AR9300_11NA_HT_DS_SHIFT,
  1648. AR9300_11NA_HT_TS_SHIFT,
  1649. IS_CHAN_HT40(chan));
  1650. ar9003_hw_init_txpower_stbc(ah,
  1651. AR9300_11NA_HT_SS_SHIFT,
  1652. AR9300_11NA_HT_DS_SHIFT,
  1653. AR9300_11NA_HT_TS_SHIFT);
  1654. }
  1655. } else {
  1656. ar9003_hw_init_txpower_cck(ah, rate_array);
  1657. ar9003_hw_init_txpower_ofdm(ah, rate_array,
  1658. AR9300_11NG_OFDM_SHIFT);
  1659. if (IS_CHAN_HT20(chan) || IS_CHAN_HT40(chan)) {
  1660. ar9003_hw_init_txpower_ht(ah, rate_array,
  1661. AR9300_11NG_HT_SS_SHIFT,
  1662. AR9300_11NG_HT_DS_SHIFT,
  1663. AR9300_11NG_HT_TS_SHIFT,
  1664. IS_CHAN_HT40(chan));
  1665. ar9003_hw_init_txpower_stbc(ah,
  1666. AR9300_11NG_HT_SS_SHIFT,
  1667. AR9300_11NG_HT_DS_SHIFT,
  1668. AR9300_11NG_HT_TS_SHIFT);
  1669. }
  1670. }
  1671. }
  1672. void ar9003_hw_attach_phy_ops(struct ath_hw *ah)
  1673. {
  1674. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  1675. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  1676. static const u32 ar9300_cca_regs[6] = {
  1677. AR_PHY_CCA_0,
  1678. AR_PHY_CCA_1,
  1679. AR_PHY_CCA_2,
  1680. AR_PHY_EXT_CCA,
  1681. AR_PHY_EXT_CCA_1,
  1682. AR_PHY_EXT_CCA_2,
  1683. };
  1684. priv_ops->rf_set_freq = ar9003_hw_set_channel;
  1685. priv_ops->spur_mitigate_freq = ar9003_hw_spur_mitigate;
  1686. if (AR_SREV_9340(ah) || AR_SREV_9550(ah) || AR_SREV_9531(ah) ||
  1687. AR_SREV_9561(ah))
  1688. priv_ops->compute_pll_control = ar9003_hw_compute_pll_control_soc;
  1689. else
  1690. priv_ops->compute_pll_control = ar9003_hw_compute_pll_control;
  1691. priv_ops->set_channel_regs = ar9003_hw_set_channel_regs;
  1692. priv_ops->init_bb = ar9003_hw_init_bb;
  1693. priv_ops->process_ini = ar9003_hw_process_ini;
  1694. priv_ops->set_rfmode = ar9003_hw_set_rfmode;
  1695. priv_ops->mark_phy_inactive = ar9003_hw_mark_phy_inactive;
  1696. priv_ops->set_delta_slope = ar9003_hw_set_delta_slope;
  1697. priv_ops->rfbus_req = ar9003_hw_rfbus_req;
  1698. priv_ops->rfbus_done = ar9003_hw_rfbus_done;
  1699. priv_ops->ani_control = ar9003_hw_ani_control;
  1700. priv_ops->do_getnf = ar9003_hw_do_getnf;
  1701. priv_ops->ani_cache_ini_regs = ar9003_hw_ani_cache_ini_regs;
  1702. priv_ops->set_radar_params = ar9003_hw_set_radar_params;
  1703. priv_ops->fast_chan_change = ar9003_hw_fast_chan_change;
  1704. ops->antdiv_comb_conf_get = ar9003_hw_antdiv_comb_conf_get;
  1705. ops->antdiv_comb_conf_set = ar9003_hw_antdiv_comb_conf_set;
  1706. ops->spectral_scan_config = ar9003_hw_spectral_scan_config;
  1707. ops->spectral_scan_trigger = ar9003_hw_spectral_scan_trigger;
  1708. ops->spectral_scan_wait = ar9003_hw_spectral_scan_wait;
  1709. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  1710. ops->set_bt_ant_diversity = ar9003_hw_set_bt_ant_diversity;
  1711. #endif
  1712. ops->tx99_start = ar9003_hw_tx99_start;
  1713. ops->tx99_stop = ar9003_hw_tx99_stop;
  1714. ops->tx99_set_txpower = ar9003_hw_tx99_set_txpower;
  1715. ar9003_hw_set_nf_limits(ah);
  1716. ar9003_hw_set_radar_conf(ah);
  1717. memcpy(ah->nf_regs, ar9300_cca_regs, sizeof(ah->nf_regs));
  1718. }
  1719. /*
  1720. * Baseband Watchdog signatures:
  1721. *
  1722. * 0x04000539: BB hang when operating in HT40 DFS Channel.
  1723. * Full chip reset is not required, but a recovery
  1724. * mechanism is needed.
  1725. *
  1726. * 0x1300000a: Related to CAC deafness.
  1727. * Chip reset is not required.
  1728. *
  1729. * 0x0400000a: Related to CAC deafness.
  1730. * Full chip reset is required.
  1731. *
  1732. * 0x04000b09: RX state machine gets into an illegal state
  1733. * when a packet with unsupported rate is received.
  1734. * Full chip reset is required and PHY_RESTART has
  1735. * to be disabled.
  1736. *
  1737. * 0x04000409: Packet stuck on receive.
  1738. * Full chip reset is required for all chips except
  1739. * AR9340, AR9531 and AR9561.
  1740. */
  1741. /*
  1742. * ar9003_hw_bb_watchdog_check(): Returns true if a chip reset is required.
  1743. */
  1744. bool ar9003_hw_bb_watchdog_check(struct ath_hw *ah)
  1745. {
  1746. u32 val;
  1747. switch(ah->bb_watchdog_last_status) {
  1748. case 0x04000539:
  1749. val = REG_READ(ah, AR_PHY_RADAR_0);
  1750. val &= (~AR_PHY_RADAR_0_FIRPWR);
  1751. val |= SM(0x7f, AR_PHY_RADAR_0_FIRPWR);
  1752. REG_WRITE(ah, AR_PHY_RADAR_0, val);
  1753. udelay(1);
  1754. val = REG_READ(ah, AR_PHY_RADAR_0);
  1755. val &= ~AR_PHY_RADAR_0_FIRPWR;
  1756. val |= SM(AR9300_DFS_FIRPWR, AR_PHY_RADAR_0_FIRPWR);
  1757. REG_WRITE(ah, AR_PHY_RADAR_0, val);
  1758. return false;
  1759. case 0x1300000a:
  1760. return false;
  1761. case 0x0400000a:
  1762. case 0x04000b09:
  1763. return true;
  1764. case 0x04000409:
  1765. if (AR_SREV_9340(ah) || AR_SREV_9531(ah) || AR_SREV_9561(ah))
  1766. return false;
  1767. else
  1768. return true;
  1769. default:
  1770. /*
  1771. * For any other unknown signatures, do a
  1772. * full chip reset.
  1773. */
  1774. return true;
  1775. }
  1776. }
  1777. EXPORT_SYMBOL(ar9003_hw_bb_watchdog_check);
  1778. void ar9003_hw_bb_watchdog_config(struct ath_hw *ah)
  1779. {
  1780. struct ath_common *common = ath9k_hw_common(ah);
  1781. u32 idle_tmo_ms = ah->bb_watchdog_timeout_ms;
  1782. u32 val, idle_count;
  1783. if (!idle_tmo_ms) {
  1784. /* disable IRQ, disable chip-reset for BB panic */
  1785. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
  1786. REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) &
  1787. ~(AR_PHY_WATCHDOG_RST_ENABLE |
  1788. AR_PHY_WATCHDOG_IRQ_ENABLE));
  1789. /* disable watchdog in non-IDLE mode, disable in IDLE mode */
  1790. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
  1791. REG_READ(ah, AR_PHY_WATCHDOG_CTL_1) &
  1792. ~(AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
  1793. AR_PHY_WATCHDOG_IDLE_ENABLE));
  1794. ath_dbg(common, RESET, "Disabled BB Watchdog\n");
  1795. return;
  1796. }
  1797. /* enable IRQ, disable chip-reset for BB watchdog */
  1798. val = REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) & AR_PHY_WATCHDOG_CNTL2_MASK;
  1799. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
  1800. (val | AR_PHY_WATCHDOG_IRQ_ENABLE) &
  1801. ~AR_PHY_WATCHDOG_RST_ENABLE);
  1802. /* bound limit to 10 secs */
  1803. if (idle_tmo_ms > 10000)
  1804. idle_tmo_ms = 10000;
  1805. /*
  1806. * The time unit for watchdog event is 2^15 44/88MHz cycles.
  1807. *
  1808. * For HT20 we have a time unit of 2^15/44 MHz = .74 ms per tick
  1809. * For HT40 we have a time unit of 2^15/88 MHz = .37 ms per tick
  1810. *
  1811. * Given we use fast clock now in 5 GHz, these time units should
  1812. * be common for both 2 GHz and 5 GHz.
  1813. */
  1814. idle_count = (100 * idle_tmo_ms) / 74;
  1815. if (ah->curchan && IS_CHAN_HT40(ah->curchan))
  1816. idle_count = (100 * idle_tmo_ms) / 37;
  1817. /*
  1818. * enable watchdog in non-IDLE mode, disable in IDLE mode,
  1819. * set idle time-out.
  1820. */
  1821. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
  1822. AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
  1823. AR_PHY_WATCHDOG_IDLE_MASK |
  1824. (AR_PHY_WATCHDOG_NON_IDLE_MASK & (idle_count << 2)));
  1825. ath_dbg(common, RESET, "Enabled BB Watchdog timeout (%u ms)\n",
  1826. idle_tmo_ms);
  1827. }
  1828. void ar9003_hw_bb_watchdog_read(struct ath_hw *ah)
  1829. {
  1830. /*
  1831. * we want to avoid printing in ISR context so we save the
  1832. * watchdog status to be printed later in bottom half context.
  1833. */
  1834. ah->bb_watchdog_last_status = REG_READ(ah, AR_PHY_WATCHDOG_STATUS);
  1835. /*
  1836. * the watchdog timer should reset on status read but to be sure
  1837. * sure we write 0 to the watchdog status bit.
  1838. */
  1839. REG_WRITE(ah, AR_PHY_WATCHDOG_STATUS,
  1840. ah->bb_watchdog_last_status & ~AR_PHY_WATCHDOG_STATUS_CLR);
  1841. }
  1842. void ar9003_hw_bb_watchdog_dbg_info(struct ath_hw *ah)
  1843. {
  1844. struct ath_common *common = ath9k_hw_common(ah);
  1845. u32 status;
  1846. if (likely(!(common->debug_mask & ATH_DBG_RESET)))
  1847. return;
  1848. status = ah->bb_watchdog_last_status;
  1849. ath_dbg(common, RESET,
  1850. "\n==== BB update: BB status=0x%08x ====\n", status);
  1851. ath_dbg(common, RESET,
  1852. "** BB state: wd=%u det=%u rdar=%u rOFDM=%d rCCK=%u tOFDM=%u tCCK=%u agc=%u src=%u **\n",
  1853. MS(status, AR_PHY_WATCHDOG_INFO),
  1854. MS(status, AR_PHY_WATCHDOG_DET_HANG),
  1855. MS(status, AR_PHY_WATCHDOG_RADAR_SM),
  1856. MS(status, AR_PHY_WATCHDOG_RX_OFDM_SM),
  1857. MS(status, AR_PHY_WATCHDOG_RX_CCK_SM),
  1858. MS(status, AR_PHY_WATCHDOG_TX_OFDM_SM),
  1859. MS(status, AR_PHY_WATCHDOG_TX_CCK_SM),
  1860. MS(status, AR_PHY_WATCHDOG_AGC_SM),
  1861. MS(status, AR_PHY_WATCHDOG_SRCH_SM));
  1862. ath_dbg(common, RESET, "** BB WD cntl: cntl1=0x%08x cntl2=0x%08x **\n",
  1863. REG_READ(ah, AR_PHY_WATCHDOG_CTL_1),
  1864. REG_READ(ah, AR_PHY_WATCHDOG_CTL_2));
  1865. ath_dbg(common, RESET, "** BB mode: BB_gen_controls=0x%08x **\n",
  1866. REG_READ(ah, AR_PHY_GEN_CTRL));
  1867. #define PCT(_field) (common->cc_survey._field * 100 / common->cc_survey.cycles)
  1868. if (common->cc_survey.cycles)
  1869. ath_dbg(common, RESET,
  1870. "** BB busy times: rx_clear=%d%%, rx_frame=%d%%, tx_frame=%d%% **\n",
  1871. PCT(rx_busy), PCT(rx_frame), PCT(tx_frame));
  1872. ath_dbg(common, RESET, "==== BB update: done ====\n\n");
  1873. }
  1874. EXPORT_SYMBOL(ar9003_hw_bb_watchdog_dbg_info);
  1875. void ar9003_hw_disable_phy_restart(struct ath_hw *ah)
  1876. {
  1877. u8 result;
  1878. u32 val;
  1879. /* While receiving unsupported rate frame rx state machine
  1880. * gets into a state 0xb and if phy_restart happens in that
  1881. * state, BB would go hang. If RXSM is in 0xb state after
  1882. * first bb panic, ensure to disable the phy_restart.
  1883. */
  1884. result = MS(ah->bb_watchdog_last_status, AR_PHY_WATCHDOG_RX_OFDM_SM);
  1885. if ((result == 0xb) || ah->bb_hang_rx_ofdm) {
  1886. ah->bb_hang_rx_ofdm = true;
  1887. val = REG_READ(ah, AR_PHY_RESTART);
  1888. val &= ~AR_PHY_RESTART_ENA;
  1889. REG_WRITE(ah, AR_PHY_RESTART, val);
  1890. }
  1891. }
  1892. EXPORT_SYMBOL(ar9003_hw_disable_phy_restart);