You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ath9k_ar9002_phy.c 17KB

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