ar9002_phy.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. /*
  2. * Copyright (c) 2008-2010 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. /**
  17. * DOC: Programming Atheros 802.11n analog front end radios
  18. *
  19. * AR5416 MAC based PCI devices and AR518 MAC based PCI-Express
  20. * devices have either an external AR2133 analog front end radio for single
  21. * band 2.4 GHz communication or an AR5133 analog front end radio for dual
  22. * band 2.4 GHz / 5 GHz communication.
  23. *
  24. * All devices after the AR5416 and AR5418 family starting with the AR9280
  25. * have their analog front radios, MAC/BB and host PCIe/USB interface embedded
  26. * into a single-chip and require less programming.
  27. *
  28. * The following single-chips exist with a respective embedded radio:
  29. *
  30. * AR9280 - 11n dual-band 2x2 MIMO for PCIe
  31. * AR9281 - 11n single-band 1x2 MIMO for PCIe
  32. * AR9285 - 11n single-band 1x1 for PCIe
  33. * AR9287 - 11n single-band 2x2 MIMO for PCIe
  34. *
  35. * AR9220 - 11n dual-band 2x2 MIMO for PCI
  36. * AR9223 - 11n single-band 2x2 MIMO for PCI
  37. *
  38. * AR9287 - 11n single-band 1x1 MIMO for USB
  39. */
  40. #include "hw.h"
  41. #include "ar9002_phy.h"
  42. /**
  43. * ar9002_hw_set_channel - set channel on single-chip device
  44. * @ah: atheros hardware structure
  45. * @chan:
  46. *
  47. * This is the function to change channel on single-chip devices, that is
  48. * all devices after ar9280.
  49. *
  50. * This function takes the channel value in MHz and sets
  51. * hardware channel value. Assumes writes have been enabled to analog bus.
  52. *
  53. * Actual Expression,
  54. *
  55. * For 2GHz channel,
  56. * Channel Frequency = (3/4) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
  57. * (freq_ref = 40MHz)
  58. *
  59. * For 5GHz channel,
  60. * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^10)
  61. * (freq_ref = 40MHz/(24>>amodeRefSel))
  62. */
  63. static int ar9002_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
  64. {
  65. u16 bMode, fracMode, aModeRefSel = 0;
  66. u32 freq, ndiv, channelSel = 0, channelFrac = 0, reg32 = 0;
  67. struct chan_centers centers;
  68. u32 refDivA = 24;
  69. ath9k_hw_get_channel_centers(ah, chan, &centers);
  70. freq = centers.synth_center;
  71. reg32 = REG_READ(ah, AR_PHY_SYNTH_CONTROL);
  72. reg32 &= 0xc0000000;
  73. if (freq < 4800) { /* 2 GHz, fractional mode */
  74. u32 txctl;
  75. int regWrites = 0;
  76. bMode = 1;
  77. fracMode = 1;
  78. aModeRefSel = 0;
  79. channelSel = CHANSEL_2G(freq);
  80. if (AR_SREV_9287_11_OR_LATER(ah)) {
  81. if (freq == 2484) {
  82. /* Enable channel spreading for channel 14 */
  83. REG_WRITE_ARRAY(&ah->iniCckfirJapan2484,
  84. 1, regWrites);
  85. } else {
  86. REG_WRITE_ARRAY(&ah->iniCckfirNormal,
  87. 1, regWrites);
  88. }
  89. } else {
  90. txctl = REG_READ(ah, AR_PHY_CCK_TX_CTRL);
  91. if (freq == 2484) {
  92. /* Enable channel spreading for channel 14 */
  93. REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
  94. txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
  95. } else {
  96. REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
  97. txctl & ~AR_PHY_CCK_TX_CTRL_JAPAN);
  98. }
  99. }
  100. } else {
  101. bMode = 0;
  102. fracMode = 0;
  103. switch (ah->eep_ops->get_eeprom(ah, EEP_FRAC_N_5G)) {
  104. case 0:
  105. if ((freq % 20) == 0)
  106. aModeRefSel = 3;
  107. else if ((freq % 10) == 0)
  108. aModeRefSel = 2;
  109. if (aModeRefSel)
  110. break;
  111. case 1:
  112. default:
  113. aModeRefSel = 0;
  114. /*
  115. * Enable 2G (fractional) mode for channels
  116. * which are 5MHz spaced.
  117. */
  118. fracMode = 1;
  119. refDivA = 1;
  120. channelSel = CHANSEL_5G(freq);
  121. /* RefDivA setting */
  122. REG_RMW_FIELD(ah, AR_AN_SYNTH9,
  123. AR_AN_SYNTH9_REFDIVA, refDivA);
  124. }
  125. if (!fracMode) {
  126. ndiv = (freq * (refDivA >> aModeRefSel)) / 60;
  127. channelSel = ndiv & 0x1ff;
  128. channelFrac = (ndiv & 0xfffffe00) * 2;
  129. channelSel = (channelSel << 17) | channelFrac;
  130. }
  131. }
  132. reg32 = reg32 |
  133. (bMode << 29) |
  134. (fracMode << 28) | (aModeRefSel << 26) | (channelSel);
  135. REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
  136. ah->curchan = chan;
  137. ah->curchan_rad_index = -1;
  138. return 0;
  139. }
  140. /**
  141. * ar9002_hw_spur_mitigate - convert baseband spur frequency
  142. * @ah: atheros hardware structure
  143. * @chan:
  144. *
  145. * For single-chip solutions. Converts to baseband spur frequency given the
  146. * input channel frequency and compute register settings below.
  147. */
  148. static void ar9002_hw_spur_mitigate(struct ath_hw *ah,
  149. struct ath9k_channel *chan)
  150. {
  151. int bb_spur = AR_NO_SPUR;
  152. int freq;
  153. int bin, cur_bin;
  154. int bb_spur_off, spur_subchannel_sd;
  155. int spur_freq_sd;
  156. int spur_delta_phase;
  157. int denominator;
  158. int upper, lower, cur_vit_mask;
  159. int tmp, newVal;
  160. int i;
  161. int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
  162. AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
  163. };
  164. int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
  165. AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
  166. };
  167. int inc[4] = { 0, 100, 0, 0 };
  168. struct chan_centers centers;
  169. int8_t mask_m[123];
  170. int8_t mask_p[123];
  171. int8_t mask_amt;
  172. int tmp_mask;
  173. int cur_bb_spur;
  174. bool is2GHz = IS_CHAN_2GHZ(chan);
  175. memset(&mask_m, 0, sizeof(int8_t) * 123);
  176. memset(&mask_p, 0, sizeof(int8_t) * 123);
  177. ath9k_hw_get_channel_centers(ah, chan, &centers);
  178. freq = centers.synth_center;
  179. ah->config.spurmode = SPUR_ENABLE_EEPROM;
  180. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  181. cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
  182. if (is2GHz)
  183. cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
  184. else
  185. cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
  186. if (AR_NO_SPUR == cur_bb_spur)
  187. break;
  188. cur_bb_spur = cur_bb_spur - freq;
  189. if (IS_CHAN_HT40(chan)) {
  190. if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
  191. (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
  192. bb_spur = cur_bb_spur;
  193. break;
  194. }
  195. } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
  196. (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
  197. bb_spur = cur_bb_spur;
  198. break;
  199. }
  200. }
  201. if (AR_NO_SPUR == bb_spur) {
  202. REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
  203. AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
  204. return;
  205. } else {
  206. REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
  207. AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
  208. }
  209. bin = bb_spur * 320;
  210. tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
  211. ENABLE_REGWRITE_BUFFER(ah);
  212. newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
  213. AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
  214. AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
  215. AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
  216. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
  217. newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
  218. AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
  219. AR_PHY_SPUR_REG_MASK_RATE_SELECT |
  220. AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
  221. SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
  222. REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
  223. if (IS_CHAN_HT40(chan)) {
  224. if (bb_spur < 0) {
  225. spur_subchannel_sd = 1;
  226. bb_spur_off = bb_spur + 10;
  227. } else {
  228. spur_subchannel_sd = 0;
  229. bb_spur_off = bb_spur - 10;
  230. }
  231. } else {
  232. spur_subchannel_sd = 0;
  233. bb_spur_off = bb_spur;
  234. }
  235. if (IS_CHAN_HT40(chan))
  236. spur_delta_phase =
  237. ((bb_spur * 262144) /
  238. 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
  239. else
  240. spur_delta_phase =
  241. ((bb_spur * 524288) /
  242. 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
  243. denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
  244. spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
  245. newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
  246. SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
  247. SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
  248. REG_WRITE(ah, AR_PHY_TIMING11, newVal);
  249. newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
  250. REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
  251. cur_bin = -6000;
  252. upper = bin + 100;
  253. lower = bin - 100;
  254. for (i = 0; i < 4; i++) {
  255. int pilot_mask = 0;
  256. int chan_mask = 0;
  257. int bp = 0;
  258. for (bp = 0; bp < 30; bp++) {
  259. if ((cur_bin > lower) && (cur_bin < upper)) {
  260. pilot_mask = pilot_mask | 0x1 << bp;
  261. chan_mask = chan_mask | 0x1 << bp;
  262. }
  263. cur_bin += 100;
  264. }
  265. cur_bin += inc[i];
  266. REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
  267. REG_WRITE(ah, chan_mask_reg[i], chan_mask);
  268. }
  269. cur_vit_mask = 6100;
  270. upper = bin + 120;
  271. lower = bin - 120;
  272. for (i = 0; i < 123; i++) {
  273. if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
  274. /* workaround for gcc bug #37014 */
  275. volatile int tmp_v = abs(cur_vit_mask - bin);
  276. if (tmp_v < 75)
  277. mask_amt = 1;
  278. else
  279. mask_amt = 0;
  280. if (cur_vit_mask < 0)
  281. mask_m[abs(cur_vit_mask / 100)] = mask_amt;
  282. else
  283. mask_p[cur_vit_mask / 100] = mask_amt;
  284. }
  285. cur_vit_mask -= 100;
  286. }
  287. tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
  288. | (mask_m[48] << 26) | (mask_m[49] << 24)
  289. | (mask_m[50] << 22) | (mask_m[51] << 20)
  290. | (mask_m[52] << 18) | (mask_m[53] << 16)
  291. | (mask_m[54] << 14) | (mask_m[55] << 12)
  292. | (mask_m[56] << 10) | (mask_m[57] << 8)
  293. | (mask_m[58] << 6) | (mask_m[59] << 4)
  294. | (mask_m[60] << 2) | (mask_m[61] << 0);
  295. REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
  296. REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
  297. tmp_mask = (mask_m[31] << 28)
  298. | (mask_m[32] << 26) | (mask_m[33] << 24)
  299. | (mask_m[34] << 22) | (mask_m[35] << 20)
  300. | (mask_m[36] << 18) | (mask_m[37] << 16)
  301. | (mask_m[48] << 14) | (mask_m[39] << 12)
  302. | (mask_m[40] << 10) | (mask_m[41] << 8)
  303. | (mask_m[42] << 6) | (mask_m[43] << 4)
  304. | (mask_m[44] << 2) | (mask_m[45] << 0);
  305. REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
  306. REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
  307. tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
  308. | (mask_m[18] << 26) | (mask_m[18] << 24)
  309. | (mask_m[20] << 22) | (mask_m[20] << 20)
  310. | (mask_m[22] << 18) | (mask_m[22] << 16)
  311. | (mask_m[24] << 14) | (mask_m[24] << 12)
  312. | (mask_m[25] << 10) | (mask_m[26] << 8)
  313. | (mask_m[27] << 6) | (mask_m[28] << 4)
  314. | (mask_m[29] << 2) | (mask_m[30] << 0);
  315. REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
  316. REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
  317. tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
  318. | (mask_m[2] << 26) | (mask_m[3] << 24)
  319. | (mask_m[4] << 22) | (mask_m[5] << 20)
  320. | (mask_m[6] << 18) | (mask_m[7] << 16)
  321. | (mask_m[8] << 14) | (mask_m[9] << 12)
  322. | (mask_m[10] << 10) | (mask_m[11] << 8)
  323. | (mask_m[12] << 6) | (mask_m[13] << 4)
  324. | (mask_m[14] << 2) | (mask_m[15] << 0);
  325. REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
  326. REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
  327. tmp_mask = (mask_p[15] << 28)
  328. | (mask_p[14] << 26) | (mask_p[13] << 24)
  329. | (mask_p[12] << 22) | (mask_p[11] << 20)
  330. | (mask_p[10] << 18) | (mask_p[9] << 16)
  331. | (mask_p[8] << 14) | (mask_p[7] << 12)
  332. | (mask_p[6] << 10) | (mask_p[5] << 8)
  333. | (mask_p[4] << 6) | (mask_p[3] << 4)
  334. | (mask_p[2] << 2) | (mask_p[1] << 0);
  335. REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
  336. REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
  337. tmp_mask = (mask_p[30] << 28)
  338. | (mask_p[29] << 26) | (mask_p[28] << 24)
  339. | (mask_p[27] << 22) | (mask_p[26] << 20)
  340. | (mask_p[25] << 18) | (mask_p[24] << 16)
  341. | (mask_p[23] << 14) | (mask_p[22] << 12)
  342. | (mask_p[21] << 10) | (mask_p[20] << 8)
  343. | (mask_p[19] << 6) | (mask_p[18] << 4)
  344. | (mask_p[17] << 2) | (mask_p[16] << 0);
  345. REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
  346. REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
  347. tmp_mask = (mask_p[45] << 28)
  348. | (mask_p[44] << 26) | (mask_p[43] << 24)
  349. | (mask_p[42] << 22) | (mask_p[41] << 20)
  350. | (mask_p[40] << 18) | (mask_p[39] << 16)
  351. | (mask_p[38] << 14) | (mask_p[37] << 12)
  352. | (mask_p[36] << 10) | (mask_p[35] << 8)
  353. | (mask_p[34] << 6) | (mask_p[33] << 4)
  354. | (mask_p[32] << 2) | (mask_p[31] << 0);
  355. REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
  356. REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
  357. tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
  358. | (mask_p[59] << 26) | (mask_p[58] << 24)
  359. | (mask_p[57] << 22) | (mask_p[56] << 20)
  360. | (mask_p[55] << 18) | (mask_p[54] << 16)
  361. | (mask_p[53] << 14) | (mask_p[52] << 12)
  362. | (mask_p[51] << 10) | (mask_p[50] << 8)
  363. | (mask_p[49] << 6) | (mask_p[48] << 4)
  364. | (mask_p[47] << 2) | (mask_p[46] << 0);
  365. REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
  366. REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
  367. REGWRITE_BUFFER_FLUSH(ah);
  368. DISABLE_REGWRITE_BUFFER(ah);
  369. }
  370. static void ar9002_olc_init(struct ath_hw *ah)
  371. {
  372. u32 i;
  373. if (!OLC_FOR_AR9280_20_LATER)
  374. return;
  375. if (OLC_FOR_AR9287_10_LATER) {
  376. REG_SET_BIT(ah, AR_PHY_TX_PWRCTRL9,
  377. AR_PHY_TX_PWRCTRL9_RES_DC_REMOVAL);
  378. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TXPC0,
  379. AR9287_AN_TXPC0_TXPCMODE,
  380. AR9287_AN_TXPC0_TXPCMODE_S,
  381. AR9287_AN_TXPC0_TXPCMODE_TEMPSENSE);
  382. udelay(100);
  383. } else {
  384. for (i = 0; i < AR9280_TX_GAIN_TABLE_SIZE; i++)
  385. ah->originalGain[i] =
  386. MS(REG_READ(ah, AR_PHY_TX_GAIN_TBL1 + i * 4),
  387. AR_PHY_TX_GAIN);
  388. ah->PDADCdelta = 0;
  389. }
  390. }
  391. static u32 ar9002_hw_compute_pll_control(struct ath_hw *ah,
  392. struct ath9k_channel *chan)
  393. {
  394. u32 pll;
  395. pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
  396. if (chan && IS_CHAN_HALF_RATE(chan))
  397. pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
  398. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  399. pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
  400. if (chan && IS_CHAN_5GHZ(chan)) {
  401. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  402. pll = 0x142c;
  403. else if (AR_SREV_9280_20(ah))
  404. pll = 0x2850;
  405. else
  406. pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
  407. } else {
  408. pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
  409. }
  410. return pll;
  411. }
  412. static void ar9002_hw_do_getnf(struct ath_hw *ah,
  413. int16_t nfarray[NUM_NF_READINGS])
  414. {
  415. int16_t nf;
  416. nf = MS(REG_READ(ah, AR_PHY_CCA), AR9280_PHY_MINCCA_PWR);
  417. nfarray[0] = sign_extend(nf, 9);
  418. nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR9280_PHY_EXT_MINCCA_PWR);
  419. if (IS_CHAN_HT40(ah->curchan))
  420. nfarray[3] = sign_extend(nf, 9);
  421. if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
  422. return;
  423. nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), AR9280_PHY_CH1_MINCCA_PWR);
  424. nfarray[1] = sign_extend(nf, 9);
  425. nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA), AR9280_PHY_CH1_EXT_MINCCA_PWR);
  426. if (IS_CHAN_HT40(ah->curchan))
  427. nfarray[4] = sign_extend(nf, 9);
  428. }
  429. static void ar9002_hw_set_nf_limits(struct ath_hw *ah)
  430. {
  431. if (AR_SREV_9285(ah)) {
  432. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9285_2GHZ;
  433. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9285_2GHZ;
  434. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9285_2GHZ;
  435. } else if (AR_SREV_9287(ah)) {
  436. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9287_2GHZ;
  437. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9287_2GHZ;
  438. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9287_2GHZ;
  439. } else if (AR_SREV_9271(ah)) {
  440. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9271_2GHZ;
  441. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9271_2GHZ;
  442. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9271_2GHZ;
  443. } else {
  444. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9280_2GHZ;
  445. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9280_2GHZ;
  446. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9280_2GHZ;
  447. ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9280_5GHZ;
  448. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9280_5GHZ;
  449. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9280_5GHZ;
  450. }
  451. }
  452. void ar9002_hw_attach_phy_ops(struct ath_hw *ah)
  453. {
  454. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  455. priv_ops->set_rf_regs = NULL;
  456. priv_ops->rf_alloc_ext_banks = NULL;
  457. priv_ops->rf_free_ext_banks = NULL;
  458. priv_ops->rf_set_freq = ar9002_hw_set_channel;
  459. priv_ops->spur_mitigate_freq = ar9002_hw_spur_mitigate;
  460. priv_ops->olc_init = ar9002_olc_init;
  461. priv_ops->compute_pll_control = ar9002_hw_compute_pll_control;
  462. priv_ops->do_getnf = ar9002_hw_do_getnf;
  463. ar9002_hw_set_nf_limits(ah);
  464. }
  465. void ath9k_hw_antdiv_comb_conf_get(struct ath_hw *ah,
  466. struct ath_hw_antcomb_conf *antconf)
  467. {
  468. u32 regval;
  469. regval = REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);
  470. antconf->main_lna_conf = (regval & AR_PHY_9285_ANT_DIV_MAIN_LNACONF) >>
  471. AR_PHY_9285_ANT_DIV_MAIN_LNACONF_S;
  472. antconf->alt_lna_conf = (regval & AR_PHY_9285_ANT_DIV_ALT_LNACONF) >>
  473. AR_PHY_9285_ANT_DIV_ALT_LNACONF_S;
  474. antconf->fast_div_bias = (regval & AR_PHY_9285_FAST_DIV_BIAS) >>
  475. AR_PHY_9285_FAST_DIV_BIAS_S;
  476. }
  477. EXPORT_SYMBOL(ath9k_hw_antdiv_comb_conf_get);
  478. void ath9k_hw_antdiv_comb_conf_set(struct ath_hw *ah,
  479. struct ath_hw_antcomb_conf *antconf)
  480. {
  481. u32 regval;
  482. regval = REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);
  483. regval &= ~(AR_PHY_9285_ANT_DIV_MAIN_LNACONF |
  484. AR_PHY_9285_ANT_DIV_ALT_LNACONF |
  485. AR_PHY_9285_FAST_DIV_BIAS);
  486. regval |= ((antconf->main_lna_conf << AR_PHY_9285_ANT_DIV_MAIN_LNACONF_S)
  487. & AR_PHY_9285_ANT_DIV_MAIN_LNACONF);
  488. regval |= ((antconf->alt_lna_conf << AR_PHY_9285_ANT_DIV_ALT_LNACONF_S)
  489. & AR_PHY_9285_ANT_DIV_ALT_LNACONF);
  490. regval |= ((antconf->fast_div_bias << AR_PHY_9285_FAST_DIV_BIAS_S)
  491. & AR_PHY_9285_FAST_DIV_BIAS);
  492. REG_WRITE(ah, AR_PHY_MULTICHAIN_GAIN_CTL, regval);
  493. }
  494. EXPORT_SYMBOL(ath9k_hw_antdiv_comb_conf_set);