ar9002_phy.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. /*
  2. * Copyright (c) 2008-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. /**
  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 (IS_CHAN_HALF_RATE(chan) || IS_CHAN_QUARTER_RATE(chan))
  106. aModeRefSel = 0;
  107. else if ((freq % 20) == 0)
  108. aModeRefSel = 3;
  109. else if ((freq % 10) == 0)
  110. aModeRefSel = 2;
  111. if (aModeRefSel)
  112. break;
  113. fallthrough;
  114. case 1:
  115. default:
  116. aModeRefSel = 0;
  117. /*
  118. * Enable 2G (fractional) mode for channels
  119. * which are 5MHz spaced.
  120. */
  121. fracMode = 1;
  122. refDivA = 1;
  123. channelSel = CHANSEL_5G(freq);
  124. /* RefDivA setting */
  125. ath9k_hw_analog_shift_rmw(ah, AR_AN_SYNTH9,
  126. AR_AN_SYNTH9_REFDIVA,
  127. AR_AN_SYNTH9_REFDIVA_S, refDivA);
  128. }
  129. if (!fracMode) {
  130. ndiv = (freq * (refDivA >> aModeRefSel)) / 60;
  131. channelSel = ndiv & 0x1ff;
  132. channelFrac = (ndiv & 0xfffffe00) * 2;
  133. channelSel = (channelSel << 17) | channelFrac;
  134. }
  135. }
  136. reg32 = reg32 |
  137. (bMode << 29) |
  138. (fracMode << 28) | (aModeRefSel << 26) | (channelSel);
  139. REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
  140. ah->curchan = chan;
  141. return 0;
  142. }
  143. /**
  144. * ar9002_hw_spur_mitigate - convert baseband spur frequency
  145. * @ah: atheros hardware structure
  146. * @chan:
  147. *
  148. * For single-chip solutions. Converts to baseband spur frequency given the
  149. * input channel frequency and compute register settings below.
  150. */
  151. static void ar9002_hw_spur_mitigate(struct ath_hw *ah,
  152. struct ath9k_channel *chan)
  153. {
  154. int bb_spur = AR_NO_SPUR;
  155. int freq;
  156. int bin;
  157. int bb_spur_off, spur_subchannel_sd;
  158. int spur_freq_sd;
  159. int spur_delta_phase;
  160. int denominator;
  161. int tmp, newVal;
  162. int i;
  163. struct chan_centers centers;
  164. int cur_bb_spur;
  165. bool is2GHz = IS_CHAN_2GHZ(chan);
  166. ath9k_hw_get_channel_centers(ah, chan, &centers);
  167. freq = centers.synth_center;
  168. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  169. cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
  170. if (AR_NO_SPUR == cur_bb_spur)
  171. break;
  172. if (is2GHz)
  173. cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
  174. else
  175. cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
  176. cur_bb_spur = cur_bb_spur - freq;
  177. if (IS_CHAN_HT40(chan)) {
  178. if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
  179. (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
  180. bb_spur = cur_bb_spur;
  181. break;
  182. }
  183. } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
  184. (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
  185. bb_spur = cur_bb_spur;
  186. break;
  187. }
  188. }
  189. if (AR_NO_SPUR == bb_spur) {
  190. REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
  191. AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
  192. return;
  193. } else {
  194. REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
  195. AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
  196. }
  197. bin = bb_spur * 320;
  198. tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
  199. ENABLE_REGWRITE_BUFFER(ah);
  200. newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
  201. AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
  202. AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
  203. AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
  204. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
  205. newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
  206. AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
  207. AR_PHY_SPUR_REG_MASK_RATE_SELECT |
  208. AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
  209. SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
  210. REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
  211. if (IS_CHAN_HT40(chan)) {
  212. if (bb_spur < 0) {
  213. spur_subchannel_sd = 1;
  214. bb_spur_off = bb_spur + 10;
  215. } else {
  216. spur_subchannel_sd = 0;
  217. bb_spur_off = bb_spur - 10;
  218. }
  219. } else {
  220. spur_subchannel_sd = 0;
  221. bb_spur_off = bb_spur;
  222. }
  223. if (IS_CHAN_HT40(chan))
  224. spur_delta_phase =
  225. ((bb_spur * 262144) /
  226. 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
  227. else
  228. spur_delta_phase =
  229. ((bb_spur * 524288) /
  230. 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
  231. denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
  232. spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
  233. newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
  234. SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
  235. SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
  236. REG_WRITE(ah, AR_PHY_TIMING11, newVal);
  237. newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
  238. REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
  239. ar5008_hw_cmn_spur_mitigate(ah, chan, bin);
  240. REGWRITE_BUFFER_FLUSH(ah);
  241. }
  242. static void ar9002_olc_init(struct ath_hw *ah)
  243. {
  244. u32 i;
  245. if (!OLC_FOR_AR9280_20_LATER(ah))
  246. return;
  247. if (OLC_FOR_AR9287_10_LATER(ah)) {
  248. REG_SET_BIT(ah, AR_PHY_TX_PWRCTRL9,
  249. AR_PHY_TX_PWRCTRL9_RES_DC_REMOVAL);
  250. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TXPC0,
  251. AR9287_AN_TXPC0_TXPCMODE,
  252. AR9287_AN_TXPC0_TXPCMODE_S,
  253. AR9287_AN_TXPC0_TXPCMODE_TEMPSENSE);
  254. udelay(100);
  255. } else {
  256. for (i = 0; i < AR9280_TX_GAIN_TABLE_SIZE; i++)
  257. ah->originalGain[i] =
  258. MS(REG_READ(ah, AR_PHY_TX_GAIN_TBL1 + i * 4),
  259. AR_PHY_TX_GAIN);
  260. ah->PDADCdelta = 0;
  261. }
  262. }
  263. static u32 ar9002_hw_compute_pll_control(struct ath_hw *ah,
  264. struct ath9k_channel *chan)
  265. {
  266. int ref_div = 5;
  267. int pll_div = 0x2c;
  268. u32 pll;
  269. if (chan && IS_CHAN_5GHZ(chan) && !IS_CHAN_A_FAST_CLOCK(ah, chan)) {
  270. if (AR_SREV_9280_20(ah)) {
  271. ref_div = 10;
  272. pll_div = 0x50;
  273. } else {
  274. pll_div = 0x28;
  275. }
  276. }
  277. pll = SM(ref_div, AR_RTC_9160_PLL_REFDIV);
  278. pll |= SM(pll_div, AR_RTC_9160_PLL_DIV);
  279. if (chan && IS_CHAN_HALF_RATE(chan))
  280. pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
  281. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  282. pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
  283. return pll;
  284. }
  285. static void ar9002_hw_do_getnf(struct ath_hw *ah,
  286. int16_t nfarray[NUM_NF_READINGS])
  287. {
  288. int16_t nf;
  289. nf = MS(REG_READ(ah, AR_PHY_CCA), AR9280_PHY_MINCCA_PWR);
  290. nfarray[0] = sign_extend32(nf, 8);
  291. nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR9280_PHY_EXT_MINCCA_PWR);
  292. if (IS_CHAN_HT40(ah->curchan))
  293. nfarray[3] = sign_extend32(nf, 8);
  294. if (!(ah->rxchainmask & BIT(1)))
  295. return;
  296. nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), AR9280_PHY_CH1_MINCCA_PWR);
  297. nfarray[1] = sign_extend32(nf, 8);
  298. nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA), AR9280_PHY_CH1_EXT_MINCCA_PWR);
  299. if (IS_CHAN_HT40(ah->curchan))
  300. nfarray[4] = sign_extend32(nf, 8);
  301. }
  302. static void ar9002_hw_set_nf_limits(struct ath_hw *ah)
  303. {
  304. if (AR_SREV_9285(ah)) {
  305. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9285_2GHZ;
  306. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9285_2GHZ;
  307. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9285_2GHZ;
  308. } else if (AR_SREV_9287(ah)) {
  309. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9287_2GHZ;
  310. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9287_2GHZ;
  311. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9287_2GHZ;
  312. } else if (AR_SREV_9271(ah)) {
  313. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9271_2GHZ;
  314. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9271_2GHZ;
  315. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9271_2GHZ;
  316. } else {
  317. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9280_2GHZ;
  318. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9280_2GHZ;
  319. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9280_2GHZ;
  320. ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9280_5GHZ;
  321. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9280_5GHZ;
  322. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9280_5GHZ;
  323. }
  324. }
  325. static void ar9002_hw_antdiv_comb_conf_get(struct ath_hw *ah,
  326. struct ath_hw_antcomb_conf *antconf)
  327. {
  328. u32 regval;
  329. regval = REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);
  330. antconf->main_lna_conf = (regval & AR_PHY_9285_ANT_DIV_MAIN_LNACONF) >>
  331. AR_PHY_9285_ANT_DIV_MAIN_LNACONF_S;
  332. antconf->alt_lna_conf = (regval & AR_PHY_9285_ANT_DIV_ALT_LNACONF) >>
  333. AR_PHY_9285_ANT_DIV_ALT_LNACONF_S;
  334. antconf->fast_div_bias = (regval & AR_PHY_9285_FAST_DIV_BIAS) >>
  335. AR_PHY_9285_FAST_DIV_BIAS_S;
  336. antconf->lna1_lna2_switch_delta = -1;
  337. antconf->lna1_lna2_delta = -3;
  338. antconf->div_group = 0;
  339. }
  340. static void ar9002_hw_antdiv_comb_conf_set(struct ath_hw *ah,
  341. struct ath_hw_antcomb_conf *antconf)
  342. {
  343. u32 regval;
  344. regval = REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);
  345. regval &= ~(AR_PHY_9285_ANT_DIV_MAIN_LNACONF |
  346. AR_PHY_9285_ANT_DIV_ALT_LNACONF |
  347. AR_PHY_9285_FAST_DIV_BIAS);
  348. regval |= ((antconf->main_lna_conf << AR_PHY_9285_ANT_DIV_MAIN_LNACONF_S)
  349. & AR_PHY_9285_ANT_DIV_MAIN_LNACONF);
  350. regval |= ((antconf->alt_lna_conf << AR_PHY_9285_ANT_DIV_ALT_LNACONF_S)
  351. & AR_PHY_9285_ANT_DIV_ALT_LNACONF);
  352. regval |= ((antconf->fast_div_bias << AR_PHY_9285_FAST_DIV_BIAS_S)
  353. & AR_PHY_9285_FAST_DIV_BIAS);
  354. REG_WRITE(ah, AR_PHY_MULTICHAIN_GAIN_CTL, regval);
  355. }
  356. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  357. static void ar9002_hw_set_bt_ant_diversity(struct ath_hw *ah, bool enable)
  358. {
  359. struct ath_btcoex_hw *btcoex = &ah->btcoex_hw;
  360. u8 antdiv_ctrl1, antdiv_ctrl2;
  361. u32 regval;
  362. if (enable) {
  363. antdiv_ctrl1 = ATH_BT_COEX_ANTDIV_CONTROL1_ENABLE;
  364. antdiv_ctrl2 = ATH_BT_COEX_ANTDIV_CONTROL2_ENABLE;
  365. /*
  366. * Don't disable BT ant to allow BB to control SWCOM.
  367. */
  368. btcoex->bt_coex_mode2 &= (~(AR_BT_DISABLE_BT_ANT));
  369. REG_WRITE(ah, AR_BT_COEX_MODE2, btcoex->bt_coex_mode2);
  370. REG_WRITE(ah, AR_PHY_SWITCH_COM, ATH_BT_COEX_ANT_DIV_SWITCH_COM);
  371. REG_RMW(ah, AR_PHY_SWITCH_CHAIN_0, 0, 0xf0000000);
  372. } else {
  373. /*
  374. * Disable antenna diversity, use LNA1 only.
  375. */
  376. antdiv_ctrl1 = ATH_BT_COEX_ANTDIV_CONTROL1_FIXED_A;
  377. antdiv_ctrl2 = ATH_BT_COEX_ANTDIV_CONTROL2_FIXED_A;
  378. /*
  379. * Disable BT Ant. to allow concurrent BT and WLAN receive.
  380. */
  381. btcoex->bt_coex_mode2 |= AR_BT_DISABLE_BT_ANT;
  382. REG_WRITE(ah, AR_BT_COEX_MODE2, btcoex->bt_coex_mode2);
  383. /*
  384. * Program SWCOM table to make sure RF switch always parks
  385. * at BT side.
  386. */
  387. REG_WRITE(ah, AR_PHY_SWITCH_COM, 0);
  388. REG_RMW(ah, AR_PHY_SWITCH_CHAIN_0, 0, 0xf0000000);
  389. }
  390. regval = REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);
  391. regval &= (~(AR_PHY_9285_ANT_DIV_CTL_ALL));
  392. /*
  393. * Clear ant_fast_div_bias [14:9] since for WB195,
  394. * the main LNA is always LNA1.
  395. */
  396. regval &= (~(AR_PHY_9285_FAST_DIV_BIAS));
  397. regval |= SM(antdiv_ctrl1, AR_PHY_9285_ANT_DIV_CTL);
  398. regval |= SM(antdiv_ctrl2, AR_PHY_9285_ANT_DIV_ALT_LNACONF);
  399. regval |= SM((antdiv_ctrl2 >> 2), AR_PHY_9285_ANT_DIV_MAIN_LNACONF);
  400. regval |= SM((antdiv_ctrl1 >> 1), AR_PHY_9285_ANT_DIV_ALT_GAINTB);
  401. regval |= SM((antdiv_ctrl1 >> 2), AR_PHY_9285_ANT_DIV_MAIN_GAINTB);
  402. REG_WRITE(ah, AR_PHY_MULTICHAIN_GAIN_CTL, regval);
  403. regval = REG_READ(ah, AR_PHY_CCK_DETECT);
  404. regval &= (~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
  405. regval |= SM((antdiv_ctrl1 >> 3), AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
  406. REG_WRITE(ah, AR_PHY_CCK_DETECT, regval);
  407. }
  408. #endif
  409. static void ar9002_hw_spectral_scan_config(struct ath_hw *ah,
  410. struct ath_spec_scan *param)
  411. {
  412. u32 repeat_bit;
  413. u8 count;
  414. if (!param->enabled) {
  415. REG_CLR_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  416. AR_PHY_SPECTRAL_SCAN_ENABLE);
  417. return;
  418. }
  419. REG_SET_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_FFT_ENA);
  420. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN, AR_PHY_SPECTRAL_SCAN_ENABLE);
  421. if (AR_SREV_9280(ah))
  422. repeat_bit = AR_PHY_SPECTRAL_SCAN_SHORT_REPEAT;
  423. else
  424. repeat_bit = AR_PHY_SPECTRAL_SCAN_SHORT_REPEAT_KIWI;
  425. if (param->short_repeat)
  426. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN, repeat_bit);
  427. else
  428. REG_CLR_BIT(ah, AR_PHY_SPECTRAL_SCAN, repeat_bit);
  429. /* on AR92xx, the highest bit of count will make the chip send
  430. * spectral samples endlessly. Check if this really was intended,
  431. * and fix otherwise.
  432. */
  433. count = param->count;
  434. if (param->endless) {
  435. if (AR_SREV_9280(ah))
  436. count = 0x80;
  437. else
  438. count = 0;
  439. } else if (count & 0x80)
  440. count = 0x7f;
  441. else if (!count)
  442. count = 1;
  443. if (AR_SREV_9280(ah)) {
  444. REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN,
  445. AR_PHY_SPECTRAL_SCAN_COUNT, count);
  446. } else {
  447. REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN,
  448. AR_PHY_SPECTRAL_SCAN_COUNT_KIWI, count);
  449. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  450. AR_PHY_SPECTRAL_SCAN_PHYERR_MASK_SELECT);
  451. }
  452. REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN,
  453. AR_PHY_SPECTRAL_SCAN_PERIOD, param->period);
  454. REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN,
  455. AR_PHY_SPECTRAL_SCAN_FFT_PERIOD, param->fft_period);
  456. return;
  457. }
  458. static void ar9002_hw_spectral_scan_trigger(struct ath_hw *ah)
  459. {
  460. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN, AR_PHY_SPECTRAL_SCAN_ENABLE);
  461. /* Activate spectral scan */
  462. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  463. AR_PHY_SPECTRAL_SCAN_ACTIVE);
  464. }
  465. static void ar9002_hw_spectral_scan_wait(struct ath_hw *ah)
  466. {
  467. struct ath_common *common = ath9k_hw_common(ah);
  468. /* Poll for spectral scan complete */
  469. if (!ath9k_hw_wait(ah, AR_PHY_SPECTRAL_SCAN,
  470. AR_PHY_SPECTRAL_SCAN_ACTIVE,
  471. 0, AH_WAIT_TIMEOUT)) {
  472. ath_err(common, "spectral scan wait failed\n");
  473. return;
  474. }
  475. }
  476. static void ar9002_hw_tx99_start(struct ath_hw *ah, u32 qnum)
  477. {
  478. REG_SET_BIT(ah, 0x9864, 0x7f000);
  479. REG_SET_BIT(ah, 0x9924, 0x7f00fe);
  480. REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
  481. REG_WRITE(ah, AR_CR, AR_CR_RXD);
  482. REG_WRITE(ah, AR_DLCL_IFS(qnum), 0);
  483. REG_WRITE(ah, AR_D_GBL_IFS_SIFS, 20);
  484. REG_WRITE(ah, AR_D_GBL_IFS_EIFS, 20);
  485. REG_WRITE(ah, AR_D_FPCTL, 0x10|qnum);
  486. REG_WRITE(ah, AR_TIME_OUT, 0x00000400);
  487. REG_WRITE(ah, AR_DRETRY_LIMIT(qnum), 0xffffffff);
  488. REG_SET_BIT(ah, AR_QMISC(qnum), AR_Q_MISC_DCU_EARLY_TERM_REQ);
  489. }
  490. static void ar9002_hw_tx99_stop(struct ath_hw *ah)
  491. {
  492. REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
  493. }
  494. void ar9002_hw_attach_phy_ops(struct ath_hw *ah)
  495. {
  496. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  497. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  498. priv_ops->set_rf_regs = NULL;
  499. priv_ops->rf_set_freq = ar9002_hw_set_channel;
  500. priv_ops->spur_mitigate_freq = ar9002_hw_spur_mitigate;
  501. priv_ops->olc_init = ar9002_olc_init;
  502. priv_ops->compute_pll_control = ar9002_hw_compute_pll_control;
  503. priv_ops->do_getnf = ar9002_hw_do_getnf;
  504. ops->antdiv_comb_conf_get = ar9002_hw_antdiv_comb_conf_get;
  505. ops->antdiv_comb_conf_set = ar9002_hw_antdiv_comb_conf_set;
  506. ops->spectral_scan_config = ar9002_hw_spectral_scan_config;
  507. ops->spectral_scan_trigger = ar9002_hw_spectral_scan_trigger;
  508. ops->spectral_scan_wait = ar9002_hw_spectral_scan_wait;
  509. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  510. ops->set_bt_ant_diversity = ar9002_hw_set_bt_ant_diversity;
  511. #endif
  512. ops->tx99_start = ar9002_hw_tx99_start;
  513. ops->tx99_stop = ar9002_hw_tx99_stop;
  514. ar9002_hw_set_nf_limits(ah);
  515. }