ar9003_phy.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. /*
  2. * Copyright (c) 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. #include "hw.h"
  17. #include "ar9003_phy.h"
  18. /**
  19. * ar9003_hw_set_channel - set channel on single-chip device
  20. * @ah: atheros hardware structure
  21. * @chan:
  22. *
  23. * This is the function to change channel on single-chip devices, that is
  24. * all devices after ar9280.
  25. *
  26. * This function takes the channel value in MHz and sets
  27. * hardware channel value. Assumes writes have been enabled to analog bus.
  28. *
  29. * Actual Expression,
  30. *
  31. * For 2GHz channel,
  32. * Channel Frequency = (3/4) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
  33. * (freq_ref = 40MHz)
  34. *
  35. * For 5GHz channel,
  36. * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^10)
  37. * (freq_ref = 40MHz/(24>>amodeRefSel))
  38. *
  39. * For 5GHz channels which are 5MHz spaced,
  40. * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
  41. * (freq_ref = 40MHz)
  42. */
  43. static int ar9003_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
  44. {
  45. u16 bMode, fracMode = 0, aModeRefSel = 0;
  46. u32 freq, channelSel = 0, reg32 = 0;
  47. struct chan_centers centers;
  48. int loadSynthChannel;
  49. ath9k_hw_get_channel_centers(ah, chan, &centers);
  50. freq = centers.synth_center;
  51. if (freq < 4800) { /* 2 GHz, fractional mode */
  52. channelSel = CHANSEL_2G(freq);
  53. /* Set to 2G mode */
  54. bMode = 1;
  55. } else {
  56. channelSel = CHANSEL_5G(freq);
  57. /* Doubler is ON, so, divide channelSel by 2. */
  58. channelSel >>= 1;
  59. /* Set to 5G mode */
  60. bMode = 0;
  61. }
  62. /* Enable fractional mode for all channels */
  63. fracMode = 1;
  64. aModeRefSel = 0;
  65. loadSynthChannel = 0;
  66. reg32 = (bMode << 29);
  67. REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
  68. /* Enable Long shift Select for Synthesizer */
  69. REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_SYNTH4,
  70. AR_PHY_SYNTH4_LONG_SHIFT_SELECT, 1);
  71. /* Program Synth. setting */
  72. reg32 = (channelSel << 2) | (fracMode << 30) |
  73. (aModeRefSel << 28) | (loadSynthChannel << 31);
  74. REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
  75. /* Toggle Load Synth channel bit */
  76. loadSynthChannel = 1;
  77. reg32 = (channelSel << 2) | (fracMode << 30) |
  78. (aModeRefSel << 28) | (loadSynthChannel << 31);
  79. REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
  80. ah->curchan = chan;
  81. ah->curchan_rad_index = -1;
  82. return 0;
  83. }
  84. /**
  85. * ar9003_hw_spur_mitigate - convert baseband spur frequency
  86. * @ah: atheros hardware structure
  87. * @chan:
  88. *
  89. * For single-chip solutions. Converts to baseband spur frequency given the
  90. * input channel frequency and compute register settings below.
  91. *
  92. * Spur mitigation for MRC CCK
  93. */
  94. static void ar9003_hw_spur_mitigate(struct ath_hw *ah,
  95. struct ath9k_channel *chan)
  96. {
  97. u32 spur_freq[4] = { 2420, 2440, 2464, 2480 };
  98. int cur_bb_spur, negative = 0, cck_spur_freq;
  99. int i;
  100. /*
  101. * Need to verify range +/- 10 MHz in control channel, otherwise spur
  102. * is out-of-band and can be ignored.
  103. */
  104. for (i = 0; i < 4; i++) {
  105. negative = 0;
  106. cur_bb_spur = spur_freq[i] - chan->channel;
  107. if (cur_bb_spur < 0) {
  108. negative = 1;
  109. cur_bb_spur = -cur_bb_spur;
  110. }
  111. if (cur_bb_spur < 10) {
  112. cck_spur_freq = (int)((cur_bb_spur << 19) / 11);
  113. if (negative == 1)
  114. cck_spur_freq = -cck_spur_freq;
  115. cck_spur_freq = cck_spur_freq & 0xfffff;
  116. REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
  117. AR_PHY_AGC_CONTROL_YCOK_MAX, 0x7);
  118. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  119. AR_PHY_CCK_SPUR_MIT_SPUR_RSSI_THR, 0x7f);
  120. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  121. AR_PHY_CCK_SPUR_MIT_SPUR_FILTER_TYPE,
  122. 0x2);
  123. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  124. AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT,
  125. 0x1);
  126. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  127. AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ,
  128. cck_spur_freq);
  129. return;
  130. }
  131. }
  132. REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
  133. AR_PHY_AGC_CONTROL_YCOK_MAX, 0x5);
  134. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  135. AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT, 0x0);
  136. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  137. AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ, 0x0);
  138. }
  139. static u32 ar9003_hw_compute_pll_control(struct ath_hw *ah,
  140. struct ath9k_channel *chan)
  141. {
  142. u32 pll;
  143. pll = SM(0x5, AR_RTC_9300_PLL_REFDIV);
  144. if (chan && IS_CHAN_HALF_RATE(chan))
  145. pll |= SM(0x1, AR_RTC_9300_PLL_CLKSEL);
  146. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  147. pll |= SM(0x2, AR_RTC_9300_PLL_CLKSEL);
  148. if (chan && IS_CHAN_5GHZ(chan)) {
  149. pll |= SM(0x28, AR_RTC_9300_PLL_DIV);
  150. /*
  151. * When doing fast clock, set PLL to 0x142c
  152. */
  153. if (IS_CHAN_A_5MHZ_SPACED(chan))
  154. pll = 0x142c;
  155. } else
  156. pll |= SM(0x2c, AR_RTC_9300_PLL_DIV);
  157. return pll;
  158. }
  159. static void ar9003_hw_set_channel_regs(struct ath_hw *ah,
  160. struct ath9k_channel *chan)
  161. {
  162. u32 phymode;
  163. u32 enableDacFifo = 0;
  164. enableDacFifo =
  165. (REG_READ(ah, AR_PHY_GEN_CTRL) & AR_PHY_GC_ENABLE_DAC_FIFO);
  166. /* Enable 11n HT, 20 MHz */
  167. phymode = AR_PHY_GC_HT_EN | AR_PHY_GC_SINGLE_HT_LTF1 | AR_PHY_GC_WALSH |
  168. AR_PHY_GC_SHORT_GI_40 | enableDacFifo;
  169. /* Configure baseband for dynamic 20/40 operation */
  170. if (IS_CHAN_HT40(chan)) {
  171. phymode |= AR_PHY_GC_DYN2040_EN;
  172. /* Configure control (primary) channel at +-10MHz */
  173. if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
  174. (chan->chanmode == CHANNEL_G_HT40PLUS))
  175. phymode |= AR_PHY_GC_DYN2040_PRI_CH;
  176. }
  177. /* make sure we preserve INI settings */
  178. phymode |= REG_READ(ah, AR_PHY_GEN_CTRL);
  179. /* turn off Green Field detection for STA for now */
  180. phymode &= ~AR_PHY_GC_GF_DETECT_EN;
  181. REG_WRITE(ah, AR_PHY_GEN_CTRL, phymode);
  182. /* Configure MAC for 20/40 operation */
  183. ath9k_hw_set11nmac2040(ah);
  184. /* global transmit timeout (25 TUs default)*/
  185. REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
  186. /* carrier sense timeout */
  187. REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
  188. }
  189. static void ar9003_hw_init_bb(struct ath_hw *ah,
  190. struct ath9k_channel *chan)
  191. {
  192. u32 synthDelay;
  193. /*
  194. * Wait for the frequency synth to settle (synth goes on
  195. * via AR_PHY_ACTIVE_EN). Read the phy active delay register.
  196. * Value is in 100ns increments.
  197. */
  198. synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  199. if (IS_CHAN_B(chan))
  200. synthDelay = (4 * synthDelay) / 22;
  201. else
  202. synthDelay /= 10;
  203. /* Activate the PHY (includes baseband activate + synthesizer on) */
  204. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
  205. /*
  206. * There is an issue if the AP starts the calibration before
  207. * the base band timeout completes. This could result in the
  208. * rx_clear false triggering. As a workaround we add delay an
  209. * extra BASE_ACTIVATE_DELAY usecs to ensure this condition
  210. * does not happen.
  211. */
  212. udelay(synthDelay + BASE_ACTIVATE_DELAY);
  213. }
  214. void ar9003_hw_set_chain_masks(struct ath_hw *ah, u8 rx, u8 tx)
  215. {
  216. switch (rx) {
  217. case 0x5:
  218. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  219. AR_PHY_SWAP_ALT_CHAIN);
  220. case 0x3:
  221. case 0x1:
  222. case 0x2:
  223. case 0x7:
  224. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx);
  225. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx);
  226. break;
  227. default:
  228. break;
  229. }
  230. REG_WRITE(ah, AR_SELFGEN_MASK, tx);
  231. if (tx == 0x5) {
  232. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  233. AR_PHY_SWAP_ALT_CHAIN);
  234. }
  235. }
  236. /*
  237. * Override INI values with chip specific configuration.
  238. */
  239. static void ar9003_hw_override_ini(struct ath_hw *ah)
  240. {
  241. u32 val;
  242. /*
  243. * Set the RX_ABORT and RX_DIS and clear it only after
  244. * RXE is set for MAC. This prevents frames with
  245. * corrupted descriptor status.
  246. */
  247. REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  248. /*
  249. * For AR9280 and above, there is a new feature that allows
  250. * Multicast search based on both MAC Address and Key ID. By default,
  251. * this feature is enabled. But since the driver is not using this
  252. * feature, we switch it off; otherwise multicast search based on
  253. * MAC addr only will fail.
  254. */
  255. val = REG_READ(ah, AR_PCU_MISC_MODE2) & (~AR_ADHOC_MCAST_KEYID_ENABLE);
  256. REG_WRITE(ah, AR_PCU_MISC_MODE2,
  257. val | AR_AGG_WEP_ENABLE_FIX | AR_AGG_WEP_ENABLE);
  258. }
  259. static void ar9003_hw_prog_ini(struct ath_hw *ah,
  260. struct ar5416IniArray *iniArr,
  261. int column)
  262. {
  263. unsigned int i, regWrites = 0;
  264. /* New INI format: Array may be undefined (pre, core, post arrays) */
  265. if (!iniArr->ia_array)
  266. return;
  267. /*
  268. * New INI format: Pre, core, and post arrays for a given subsystem
  269. * may be modal (> 2 columns) or non-modal (2 columns). Determine if
  270. * the array is non-modal and force the column to 1.
  271. */
  272. if (column >= iniArr->ia_columns)
  273. column = 1;
  274. for (i = 0; i < iniArr->ia_rows; i++) {
  275. u32 reg = INI_RA(iniArr, i, 0);
  276. u32 val = INI_RA(iniArr, i, column);
  277. REG_WRITE(ah, reg, val);
  278. /*
  279. * Determine if this is a shift register value, and insert the
  280. * configured delay if so.
  281. */
  282. if (reg >= 0x16000 && reg < 0x17000
  283. && ah->config.analog_shiftreg)
  284. udelay(100);
  285. DO_DELAY(regWrites);
  286. }
  287. }
  288. static int ar9003_hw_process_ini(struct ath_hw *ah,
  289. struct ath9k_channel *chan)
  290. {
  291. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  292. unsigned int regWrites = 0, i;
  293. struct ieee80211_channel *channel = chan->chan;
  294. u32 modesIndex, freqIndex;
  295. switch (chan->chanmode) {
  296. case CHANNEL_A:
  297. case CHANNEL_A_HT20:
  298. modesIndex = 1;
  299. freqIndex = 1;
  300. break;
  301. case CHANNEL_A_HT40PLUS:
  302. case CHANNEL_A_HT40MINUS:
  303. modesIndex = 2;
  304. freqIndex = 1;
  305. break;
  306. case CHANNEL_G:
  307. case CHANNEL_G_HT20:
  308. case CHANNEL_B:
  309. modesIndex = 4;
  310. freqIndex = 2;
  311. break;
  312. case CHANNEL_G_HT40PLUS:
  313. case CHANNEL_G_HT40MINUS:
  314. modesIndex = 3;
  315. freqIndex = 2;
  316. break;
  317. default:
  318. return -EINVAL;
  319. }
  320. for (i = 0; i < ATH_INI_NUM_SPLIT; i++) {
  321. ar9003_hw_prog_ini(ah, &ah->iniSOC[i], modesIndex);
  322. ar9003_hw_prog_ini(ah, &ah->iniMac[i], modesIndex);
  323. ar9003_hw_prog_ini(ah, &ah->iniBB[i], modesIndex);
  324. ar9003_hw_prog_ini(ah, &ah->iniRadio[i], modesIndex);
  325. }
  326. REG_WRITE_ARRAY(&ah->iniModesRxGain, 1, regWrites);
  327. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  328. /*
  329. * For 5GHz channels requiring Fast Clock, apply
  330. * different modal values.
  331. */
  332. if (IS_CHAN_A_5MHZ_SPACED(chan))
  333. REG_WRITE_ARRAY(&ah->iniModesAdditional,
  334. modesIndex, regWrites);
  335. ar9003_hw_override_ini(ah);
  336. ar9003_hw_set_channel_regs(ah, chan);
  337. ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
  338. /* Set TX power */
  339. ah->eep_ops->set_txpower(ah, chan,
  340. ath9k_regd_get_ctl(regulatory, chan),
  341. channel->max_antenna_gain * 2,
  342. channel->max_power * 2,
  343. min((u32) MAX_RATE_POWER,
  344. (u32) regulatory->power_limit));
  345. return 0;
  346. }
  347. static void ar9003_hw_set_rfmode(struct ath_hw *ah,
  348. struct ath9k_channel *chan)
  349. {
  350. u32 rfMode = 0;
  351. if (chan == NULL)
  352. return;
  353. rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
  354. ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
  355. if (IS_CHAN_A_5MHZ_SPACED(chan))
  356. rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
  357. REG_WRITE(ah, AR_PHY_MODE, rfMode);
  358. }
  359. static void ar9003_hw_mark_phy_inactive(struct ath_hw *ah)
  360. {
  361. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
  362. }
  363. static void ar9003_hw_set_delta_slope(struct ath_hw *ah,
  364. struct ath9k_channel *chan)
  365. {
  366. u32 coef_scaled, ds_coef_exp, ds_coef_man;
  367. u32 clockMhzScaled = 0x64000000;
  368. struct chan_centers centers;
  369. /*
  370. * half and quarter rate can divide the scaled clock by 2 or 4
  371. * scale for selected channel bandwidth
  372. */
  373. if (IS_CHAN_HALF_RATE(chan))
  374. clockMhzScaled = clockMhzScaled >> 1;
  375. else if (IS_CHAN_QUARTER_RATE(chan))
  376. clockMhzScaled = clockMhzScaled >> 2;
  377. /*
  378. * ALGO -> coef = 1e8/fcarrier*fclock/40;
  379. * scaled coef to provide precision for this floating calculation
  380. */
  381. ath9k_hw_get_channel_centers(ah, chan, &centers);
  382. coef_scaled = clockMhzScaled / centers.synth_center;
  383. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  384. &ds_coef_exp);
  385. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  386. AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
  387. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  388. AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
  389. /*
  390. * For Short GI,
  391. * scaled coeff is 9/10 that of normal coeff
  392. */
  393. coef_scaled = (9 * coef_scaled) / 10;
  394. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  395. &ds_coef_exp);
  396. /* for short gi */
  397. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  398. AR_PHY_SGI_DSC_MAN, ds_coef_man);
  399. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  400. AR_PHY_SGI_DSC_EXP, ds_coef_exp);
  401. }
  402. static bool ar9003_hw_rfbus_req(struct ath_hw *ah)
  403. {
  404. REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
  405. return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
  406. AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT);
  407. }
  408. /*
  409. * Wait for the frequency synth to settle (synth goes on via PHY_ACTIVE_EN).
  410. * Read the phy active delay register. Value is in 100ns increments.
  411. */
  412. static void ar9003_hw_rfbus_done(struct ath_hw *ah)
  413. {
  414. u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  415. if (IS_CHAN_B(ah->curchan))
  416. synthDelay = (4 * synthDelay) / 22;
  417. else
  418. synthDelay /= 10;
  419. udelay(synthDelay + BASE_ACTIVATE_DELAY);
  420. REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
  421. }
  422. /*
  423. * Set the interrupt and GPIO values so the ISR can disable RF
  424. * on a switch signal. Assumes GPIO port and interrupt polarity
  425. * are set prior to call.
  426. */
  427. static void ar9003_hw_enable_rfkill(struct ath_hw *ah)
  428. {
  429. /* Connect rfsilent_bb_l to baseband */
  430. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
  431. AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
  432. /* Set input mux for rfsilent_bb_l to GPIO #0 */
  433. REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
  434. AR_GPIO_INPUT_MUX2_RFSILENT);
  435. /*
  436. * Configure the desired GPIO port for input and
  437. * enable baseband rf silence.
  438. */
  439. ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
  440. REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
  441. }
  442. static void ar9003_hw_set_diversity(struct ath_hw *ah, bool value)
  443. {
  444. u32 v = REG_READ(ah, AR_PHY_CCK_DETECT);
  445. if (value)
  446. v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
  447. else
  448. v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
  449. REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
  450. }
  451. static bool ar9003_hw_ani_control(struct ath_hw *ah,
  452. enum ath9k_ani_cmd cmd, int param)
  453. {
  454. struct ar5416AniState *aniState = ah->curani;
  455. struct ath_common *common = ath9k_hw_common(ah);
  456. switch (cmd & ah->ani_function) {
  457. case ATH9K_ANI_NOISE_IMMUNITY_LEVEL:{
  458. u32 level = param;
  459. if (level >= ARRAY_SIZE(ah->totalSizeDesired)) {
  460. ath_print(common, ATH_DBG_ANI,
  461. "level out of range (%u > %u)\n",
  462. level,
  463. (unsigned)ARRAY_SIZE(ah->totalSizeDesired));
  464. return false;
  465. }
  466. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
  467. AR_PHY_DESIRED_SZ_TOT_DES,
  468. ah->totalSizeDesired[level]);
  469. REG_RMW_FIELD(ah, AR_PHY_AGC,
  470. AR_PHY_AGC_COARSE_LOW,
  471. ah->coarse_low[level]);
  472. REG_RMW_FIELD(ah, AR_PHY_AGC,
  473. AR_PHY_AGC_COARSE_HIGH,
  474. ah->coarse_high[level]);
  475. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  476. AR_PHY_FIND_SIG_FIRPWR, ah->firpwr[level]);
  477. if (level > aniState->noiseImmunityLevel)
  478. ah->stats.ast_ani_niup++;
  479. else if (level < aniState->noiseImmunityLevel)
  480. ah->stats.ast_ani_nidown++;
  481. aniState->noiseImmunityLevel = level;
  482. break;
  483. }
  484. case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
  485. const int m1ThreshLow[] = { 127, 50 };
  486. const int m2ThreshLow[] = { 127, 40 };
  487. const int m1Thresh[] = { 127, 0x4d };
  488. const int m2Thresh[] = { 127, 0x40 };
  489. const int m2CountThr[] = { 31, 16 };
  490. const int m2CountThrLow[] = { 63, 48 };
  491. u32 on = param ? 1 : 0;
  492. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  493. AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
  494. m1ThreshLow[on]);
  495. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  496. AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
  497. m2ThreshLow[on]);
  498. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  499. AR_PHY_SFCORR_M1_THRESH, m1Thresh[on]);
  500. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  501. AR_PHY_SFCORR_M2_THRESH, m2Thresh[on]);
  502. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  503. AR_PHY_SFCORR_M2COUNT_THR, m2CountThr[on]);
  504. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  505. AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
  506. m2CountThrLow[on]);
  507. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  508. AR_PHY_SFCORR_EXT_M1_THRESH_LOW, m1ThreshLow[on]);
  509. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  510. AR_PHY_SFCORR_EXT_M2_THRESH_LOW, m2ThreshLow[on]);
  511. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  512. AR_PHY_SFCORR_EXT_M1_THRESH, m1Thresh[on]);
  513. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  514. AR_PHY_SFCORR_EXT_M2_THRESH, m2Thresh[on]);
  515. if (on)
  516. REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
  517. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  518. else
  519. REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
  520. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  521. if (!on != aniState->ofdmWeakSigDetectOff) {
  522. if (on)
  523. ah->stats.ast_ani_ofdmon++;
  524. else
  525. ah->stats.ast_ani_ofdmoff++;
  526. aniState->ofdmWeakSigDetectOff = !on;
  527. }
  528. break;
  529. }
  530. case ATH9K_ANI_CCK_WEAK_SIGNAL_THR:{
  531. const int weakSigThrCck[] = { 8, 6 };
  532. u32 high = param ? 1 : 0;
  533. REG_RMW_FIELD(ah, AR_PHY_CCK_DETECT,
  534. AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK,
  535. weakSigThrCck[high]);
  536. if (high != aniState->cckWeakSigThreshold) {
  537. if (high)
  538. ah->stats.ast_ani_cckhigh++;
  539. else
  540. ah->stats.ast_ani_ccklow++;
  541. aniState->cckWeakSigThreshold = high;
  542. }
  543. break;
  544. }
  545. case ATH9K_ANI_FIRSTEP_LEVEL:{
  546. const int firstep[] = { 0, 4, 8 };
  547. u32 level = param;
  548. if (level >= ARRAY_SIZE(firstep)) {
  549. ath_print(common, ATH_DBG_ANI,
  550. "level out of range (%u > %u)\n",
  551. level,
  552. (unsigned) ARRAY_SIZE(firstep));
  553. return false;
  554. }
  555. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  556. AR_PHY_FIND_SIG_FIRSTEP,
  557. firstep[level]);
  558. if (level > aniState->firstepLevel)
  559. ah->stats.ast_ani_stepup++;
  560. else if (level < aniState->firstepLevel)
  561. ah->stats.ast_ani_stepdown++;
  562. aniState->firstepLevel = level;
  563. break;
  564. }
  565. case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
  566. const int cycpwrThr1[] = { 2, 4, 6, 8, 10, 12, 14, 16 };
  567. u32 level = param;
  568. if (level >= ARRAY_SIZE(cycpwrThr1)) {
  569. ath_print(common, ATH_DBG_ANI,
  570. "level out of range (%u > %u)\n",
  571. level,
  572. (unsigned) ARRAY_SIZE(cycpwrThr1));
  573. return false;
  574. }
  575. REG_RMW_FIELD(ah, AR_PHY_TIMING5,
  576. AR_PHY_TIMING5_CYCPWR_THR1,
  577. cycpwrThr1[level]);
  578. if (level > aniState->spurImmunityLevel)
  579. ah->stats.ast_ani_spurup++;
  580. else if (level < aniState->spurImmunityLevel)
  581. ah->stats.ast_ani_spurdown++;
  582. aniState->spurImmunityLevel = level;
  583. break;
  584. }
  585. case ATH9K_ANI_PRESENT:
  586. break;
  587. default:
  588. ath_print(common, ATH_DBG_ANI,
  589. "invalid cmd %u\n", cmd);
  590. return false;
  591. }
  592. ath_print(common, ATH_DBG_ANI, "ANI parameters:\n");
  593. ath_print(common, ATH_DBG_ANI,
  594. "noiseImmunityLevel=%d, spurImmunityLevel=%d, "
  595. "ofdmWeakSigDetectOff=%d\n",
  596. aniState->noiseImmunityLevel,
  597. aniState->spurImmunityLevel,
  598. !aniState->ofdmWeakSigDetectOff);
  599. ath_print(common, ATH_DBG_ANI,
  600. "cckWeakSigThreshold=%d, "
  601. "firstepLevel=%d, listenTime=%d\n",
  602. aniState->cckWeakSigThreshold,
  603. aniState->firstepLevel,
  604. aniState->listenTime);
  605. ath_print(common, ATH_DBG_ANI,
  606. "cycleCount=%d, ofdmPhyErrCount=%d, cckPhyErrCount=%d\n\n",
  607. aniState->cycleCount,
  608. aniState->ofdmPhyErrCount,
  609. aniState->cckPhyErrCount);
  610. return true;
  611. }
  612. void ar9003_hw_attach_phy_ops(struct ath_hw *ah)
  613. {
  614. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  615. priv_ops->rf_set_freq = ar9003_hw_set_channel;
  616. priv_ops->spur_mitigate_freq = ar9003_hw_spur_mitigate;
  617. priv_ops->compute_pll_control = ar9003_hw_compute_pll_control;
  618. priv_ops->set_channel_regs = ar9003_hw_set_channel_regs;
  619. priv_ops->init_bb = ar9003_hw_init_bb;
  620. priv_ops->process_ini = ar9003_hw_process_ini;
  621. priv_ops->set_rfmode = ar9003_hw_set_rfmode;
  622. priv_ops->mark_phy_inactive = ar9003_hw_mark_phy_inactive;
  623. priv_ops->set_delta_slope = ar9003_hw_set_delta_slope;
  624. priv_ops->rfbus_req = ar9003_hw_rfbus_req;
  625. priv_ops->rfbus_done = ar9003_hw_rfbus_done;
  626. priv_ops->enable_rfkill = ar9003_hw_enable_rfkill;
  627. priv_ops->set_diversity = ar9003_hw_set_diversity;
  628. priv_ops->ani_control = ar9003_hw_ani_control;
  629. }