ar9003_phy.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  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. static const int firstep_table[] =
  19. /* level: 0 1 2 3 4 5 6 7 8 */
  20. { -4, -2, 0, 2, 4, 6, 8, 10, 12 }; /* lvl 0-8, default 2 */
  21. static const int cycpwrThr1_table[] =
  22. /* level: 0 1 2 3 4 5 6 7 8 */
  23. { -6, -4, -2, 0, 2, 4, 6, 8 }; /* lvl 0-7, default 3 */
  24. /*
  25. * register values to turn OFDM weak signal detection OFF
  26. */
  27. static const int m1ThreshLow_off = 127;
  28. static const int m2ThreshLow_off = 127;
  29. static const int m1Thresh_off = 127;
  30. static const int m2Thresh_off = 127;
  31. static const int m2CountThr_off = 31;
  32. static const int m2CountThrLow_off = 63;
  33. static const int m1ThreshLowExt_off = 127;
  34. static const int m2ThreshLowExt_off = 127;
  35. static const int m1ThreshExt_off = 127;
  36. static const int m2ThreshExt_off = 127;
  37. /**
  38. * ar9003_hw_set_channel - set channel on single-chip device
  39. * @ah: atheros hardware structure
  40. * @chan:
  41. *
  42. * This is the function to change channel on single-chip devices, that is
  43. * all devices after ar9280.
  44. *
  45. * This function takes the channel value in MHz and sets
  46. * hardware channel value. Assumes writes have been enabled to analog bus.
  47. *
  48. * Actual Expression,
  49. *
  50. * For 2GHz channel,
  51. * Channel Frequency = (3/4) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
  52. * (freq_ref = 40MHz)
  53. *
  54. * For 5GHz channel,
  55. * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^10)
  56. * (freq_ref = 40MHz/(24>>amodeRefSel))
  57. *
  58. * For 5GHz channels which are 5MHz spaced,
  59. * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
  60. * (freq_ref = 40MHz)
  61. */
  62. static int ar9003_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
  63. {
  64. u16 bMode, fracMode = 0, aModeRefSel = 0;
  65. u32 freq, channelSel = 0, reg32 = 0;
  66. struct chan_centers centers;
  67. int loadSynthChannel;
  68. ath9k_hw_get_channel_centers(ah, chan, &centers);
  69. freq = centers.synth_center;
  70. if (freq < 4800) { /* 2 GHz, fractional mode */
  71. channelSel = CHANSEL_2G(freq);
  72. /* Set to 2G mode */
  73. bMode = 1;
  74. } else {
  75. channelSel = CHANSEL_5G(freq);
  76. /* Doubler is ON, so, divide channelSel by 2. */
  77. channelSel >>= 1;
  78. /* Set to 5G mode */
  79. bMode = 0;
  80. }
  81. /* Enable fractional mode for all channels */
  82. fracMode = 1;
  83. aModeRefSel = 0;
  84. loadSynthChannel = 0;
  85. reg32 = (bMode << 29);
  86. REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
  87. /* Enable Long shift Select for Synthesizer */
  88. REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_SYNTH4,
  89. AR_PHY_SYNTH4_LONG_SHIFT_SELECT, 1);
  90. /* Program Synth. setting */
  91. reg32 = (channelSel << 2) | (fracMode << 30) |
  92. (aModeRefSel << 28) | (loadSynthChannel << 31);
  93. REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
  94. /* Toggle Load Synth channel bit */
  95. loadSynthChannel = 1;
  96. reg32 = (channelSel << 2) | (fracMode << 30) |
  97. (aModeRefSel << 28) | (loadSynthChannel << 31);
  98. REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
  99. ah->curchan = chan;
  100. ah->curchan_rad_index = -1;
  101. return 0;
  102. }
  103. /**
  104. * ar9003_hw_spur_mitigate_mrc_cck - convert baseband spur frequency
  105. * @ah: atheros hardware structure
  106. * @chan:
  107. *
  108. * For single-chip solutions. Converts to baseband spur frequency given the
  109. * input channel frequency and compute register settings below.
  110. *
  111. * Spur mitigation for MRC CCK
  112. */
  113. static void ar9003_hw_spur_mitigate_mrc_cck(struct ath_hw *ah,
  114. struct ath9k_channel *chan)
  115. {
  116. u32 spur_freq[4] = { 2420, 2440, 2464, 2480 };
  117. int cur_bb_spur, negative = 0, cck_spur_freq;
  118. int i;
  119. /*
  120. * Need to verify range +/- 10 MHz in control channel, otherwise spur
  121. * is out-of-band and can be ignored.
  122. */
  123. for (i = 0; i < 4; i++) {
  124. negative = 0;
  125. cur_bb_spur = spur_freq[i] - chan->channel;
  126. if (cur_bb_spur < 0) {
  127. negative = 1;
  128. cur_bb_spur = -cur_bb_spur;
  129. }
  130. if (cur_bb_spur < 10) {
  131. cck_spur_freq = (int)((cur_bb_spur << 19) / 11);
  132. if (negative == 1)
  133. cck_spur_freq = -cck_spur_freq;
  134. cck_spur_freq = cck_spur_freq & 0xfffff;
  135. REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
  136. AR_PHY_AGC_CONTROL_YCOK_MAX, 0x7);
  137. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  138. AR_PHY_CCK_SPUR_MIT_SPUR_RSSI_THR, 0x7f);
  139. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  140. AR_PHY_CCK_SPUR_MIT_SPUR_FILTER_TYPE,
  141. 0x2);
  142. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  143. AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT,
  144. 0x1);
  145. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  146. AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ,
  147. cck_spur_freq);
  148. return;
  149. }
  150. }
  151. REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
  152. AR_PHY_AGC_CONTROL_YCOK_MAX, 0x5);
  153. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  154. AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT, 0x0);
  155. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  156. AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ, 0x0);
  157. }
  158. /* Clean all spur register fields */
  159. static void ar9003_hw_spur_ofdm_clear(struct ath_hw *ah)
  160. {
  161. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  162. AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0);
  163. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  164. AR_PHY_TIMING11_SPUR_FREQ_SD, 0);
  165. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  166. AR_PHY_TIMING11_SPUR_DELTA_PHASE, 0);
  167. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  168. AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, 0);
  169. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  170. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0);
  171. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  172. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0);
  173. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  174. AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0);
  175. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  176. AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 0);
  177. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  178. AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 0);
  179. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  180. AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0);
  181. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  182. AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0);
  183. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  184. AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0);
  185. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  186. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, 0);
  187. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  188. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, 0);
  189. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  190. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, 0);
  191. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  192. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0);
  193. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  194. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0);
  195. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  196. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0);
  197. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  198. AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0);
  199. }
  200. static void ar9003_hw_spur_ofdm(struct ath_hw *ah,
  201. int freq_offset,
  202. int spur_freq_sd,
  203. int spur_delta_phase,
  204. int spur_subchannel_sd)
  205. {
  206. int mask_index = 0;
  207. /* OFDM Spur mitigation */
  208. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  209. AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0x1);
  210. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  211. AR_PHY_TIMING11_SPUR_FREQ_SD, spur_freq_sd);
  212. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  213. AR_PHY_TIMING11_SPUR_DELTA_PHASE, spur_delta_phase);
  214. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  215. AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, spur_subchannel_sd);
  216. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  217. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0x1);
  218. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  219. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0x1);
  220. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  221. AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0x1);
  222. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  223. AR_PHY_SPUR_REG_SPUR_RSSI_THRESH, 34);
  224. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  225. AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 1);
  226. if (REG_READ_FIELD(ah, AR_PHY_MODE,
  227. AR_PHY_MODE_DYNAMIC) == 0x1)
  228. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  229. AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 1);
  230. mask_index = (freq_offset << 4) / 5;
  231. if (mask_index < 0)
  232. mask_index = mask_index - 1;
  233. mask_index = mask_index & 0x7f;
  234. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  235. AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0x1);
  236. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  237. AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0x1);
  238. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  239. AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0x1);
  240. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  241. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, mask_index);
  242. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  243. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, mask_index);
  244. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  245. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, mask_index);
  246. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  247. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0xc);
  248. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  249. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0xc);
  250. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  251. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0xa0);
  252. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  253. AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0xff);
  254. }
  255. static void ar9003_hw_spur_ofdm_work(struct ath_hw *ah,
  256. struct ath9k_channel *chan,
  257. int freq_offset)
  258. {
  259. int spur_freq_sd = 0;
  260. int spur_subchannel_sd = 0;
  261. int spur_delta_phase = 0;
  262. if (IS_CHAN_HT40(chan)) {
  263. if (freq_offset < 0) {
  264. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  265. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  266. spur_subchannel_sd = 1;
  267. else
  268. spur_subchannel_sd = 0;
  269. spur_freq_sd = ((freq_offset + 10) << 9) / 11;
  270. } else {
  271. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  272. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  273. spur_subchannel_sd = 0;
  274. else
  275. spur_subchannel_sd = 1;
  276. spur_freq_sd = ((freq_offset - 10) << 9) / 11;
  277. }
  278. spur_delta_phase = (freq_offset << 17) / 5;
  279. } else {
  280. spur_subchannel_sd = 0;
  281. spur_freq_sd = (freq_offset << 9) /11;
  282. spur_delta_phase = (freq_offset << 18) / 5;
  283. }
  284. spur_freq_sd = spur_freq_sd & 0x3ff;
  285. spur_delta_phase = spur_delta_phase & 0xfffff;
  286. ar9003_hw_spur_ofdm(ah,
  287. freq_offset,
  288. spur_freq_sd,
  289. spur_delta_phase,
  290. spur_subchannel_sd);
  291. }
  292. /* Spur mitigation for OFDM */
  293. static void ar9003_hw_spur_mitigate_ofdm(struct ath_hw *ah,
  294. struct ath9k_channel *chan)
  295. {
  296. int synth_freq;
  297. int range = 10;
  298. int freq_offset = 0;
  299. int mode;
  300. u8* spurChansPtr;
  301. unsigned int i;
  302. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  303. if (IS_CHAN_5GHZ(chan)) {
  304. spurChansPtr = &(eep->modalHeader5G.spurChans[0]);
  305. mode = 0;
  306. }
  307. else {
  308. spurChansPtr = &(eep->modalHeader2G.spurChans[0]);
  309. mode = 1;
  310. }
  311. if (spurChansPtr[0] == 0)
  312. return; /* No spur in the mode */
  313. if (IS_CHAN_HT40(chan)) {
  314. range = 19;
  315. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  316. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  317. synth_freq = chan->channel - 10;
  318. else
  319. synth_freq = chan->channel + 10;
  320. } else {
  321. range = 10;
  322. synth_freq = chan->channel;
  323. }
  324. ar9003_hw_spur_ofdm_clear(ah);
  325. for (i = 0; spurChansPtr[i] && i < 5; i++) {
  326. freq_offset = FBIN2FREQ(spurChansPtr[i], mode) - synth_freq;
  327. if (abs(freq_offset) < range) {
  328. ar9003_hw_spur_ofdm_work(ah, chan, freq_offset);
  329. break;
  330. }
  331. }
  332. }
  333. static void ar9003_hw_spur_mitigate(struct ath_hw *ah,
  334. struct ath9k_channel *chan)
  335. {
  336. ar9003_hw_spur_mitigate_mrc_cck(ah, chan);
  337. ar9003_hw_spur_mitigate_ofdm(ah, chan);
  338. }
  339. static u32 ar9003_hw_compute_pll_control(struct ath_hw *ah,
  340. struct ath9k_channel *chan)
  341. {
  342. u32 pll;
  343. pll = SM(0x5, AR_RTC_9300_PLL_REFDIV);
  344. if (chan && IS_CHAN_HALF_RATE(chan))
  345. pll |= SM(0x1, AR_RTC_9300_PLL_CLKSEL);
  346. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  347. pll |= SM(0x2, AR_RTC_9300_PLL_CLKSEL);
  348. pll |= SM(0x2c, AR_RTC_9300_PLL_DIV);
  349. return pll;
  350. }
  351. static void ar9003_hw_set_channel_regs(struct ath_hw *ah,
  352. struct ath9k_channel *chan)
  353. {
  354. u32 phymode;
  355. u32 enableDacFifo = 0;
  356. enableDacFifo =
  357. (REG_READ(ah, AR_PHY_GEN_CTRL) & AR_PHY_GC_ENABLE_DAC_FIFO);
  358. /* Enable 11n HT, 20 MHz */
  359. phymode = AR_PHY_GC_HT_EN | AR_PHY_GC_SINGLE_HT_LTF1 | AR_PHY_GC_WALSH |
  360. AR_PHY_GC_SHORT_GI_40 | enableDacFifo;
  361. /* Configure baseband for dynamic 20/40 operation */
  362. if (IS_CHAN_HT40(chan)) {
  363. phymode |= AR_PHY_GC_DYN2040_EN;
  364. /* Configure control (primary) channel at +-10MHz */
  365. if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
  366. (chan->chanmode == CHANNEL_G_HT40PLUS))
  367. phymode |= AR_PHY_GC_DYN2040_PRI_CH;
  368. }
  369. /* make sure we preserve INI settings */
  370. phymode |= REG_READ(ah, AR_PHY_GEN_CTRL);
  371. /* turn off Green Field detection for STA for now */
  372. phymode &= ~AR_PHY_GC_GF_DETECT_EN;
  373. REG_WRITE(ah, AR_PHY_GEN_CTRL, phymode);
  374. /* Configure MAC for 20/40 operation */
  375. ath9k_hw_set11nmac2040(ah);
  376. /* global transmit timeout (25 TUs default)*/
  377. REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
  378. /* carrier sense timeout */
  379. REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
  380. }
  381. static void ar9003_hw_init_bb(struct ath_hw *ah,
  382. struct ath9k_channel *chan)
  383. {
  384. u32 synthDelay;
  385. /*
  386. * Wait for the frequency synth to settle (synth goes on
  387. * via AR_PHY_ACTIVE_EN). Read the phy active delay register.
  388. * Value is in 100ns increments.
  389. */
  390. synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  391. if (IS_CHAN_B(chan))
  392. synthDelay = (4 * synthDelay) / 22;
  393. else
  394. synthDelay /= 10;
  395. /* Activate the PHY (includes baseband activate + synthesizer on) */
  396. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
  397. /*
  398. * There is an issue if the AP starts the calibration before
  399. * the base band timeout completes. This could result in the
  400. * rx_clear false triggering. As a workaround we add delay an
  401. * extra BASE_ACTIVATE_DELAY usecs to ensure this condition
  402. * does not happen.
  403. */
  404. udelay(synthDelay + BASE_ACTIVATE_DELAY);
  405. }
  406. void ar9003_hw_set_chain_masks(struct ath_hw *ah, u8 rx, u8 tx)
  407. {
  408. switch (rx) {
  409. case 0x5:
  410. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  411. AR_PHY_SWAP_ALT_CHAIN);
  412. case 0x3:
  413. case 0x1:
  414. case 0x2:
  415. case 0x7:
  416. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx);
  417. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx);
  418. break;
  419. default:
  420. break;
  421. }
  422. REG_WRITE(ah, AR_SELFGEN_MASK, tx);
  423. if (tx == 0x5) {
  424. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  425. AR_PHY_SWAP_ALT_CHAIN);
  426. }
  427. }
  428. /*
  429. * Override INI values with chip specific configuration.
  430. */
  431. static void ar9003_hw_override_ini(struct ath_hw *ah)
  432. {
  433. u32 val;
  434. /*
  435. * Set the RX_ABORT and RX_DIS and clear it only after
  436. * RXE is set for MAC. This prevents frames with
  437. * corrupted descriptor status.
  438. */
  439. REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  440. /*
  441. * For AR9280 and above, there is a new feature that allows
  442. * Multicast search based on both MAC Address and Key ID. By default,
  443. * this feature is enabled. But since the driver is not using this
  444. * feature, we switch it off; otherwise multicast search based on
  445. * MAC addr only will fail.
  446. */
  447. val = REG_READ(ah, AR_PCU_MISC_MODE2) & (~AR_ADHOC_MCAST_KEYID_ENABLE);
  448. REG_WRITE(ah, AR_PCU_MISC_MODE2,
  449. val | AR_AGG_WEP_ENABLE_FIX | AR_AGG_WEP_ENABLE);
  450. }
  451. static void ar9003_hw_prog_ini(struct ath_hw *ah,
  452. struct ar5416IniArray *iniArr,
  453. int column)
  454. {
  455. unsigned int i, regWrites = 0;
  456. /* New INI format: Array may be undefined (pre, core, post arrays) */
  457. if (!iniArr->ia_array)
  458. return;
  459. /*
  460. * New INI format: Pre, core, and post arrays for a given subsystem
  461. * may be modal (> 2 columns) or non-modal (2 columns). Determine if
  462. * the array is non-modal and force the column to 1.
  463. */
  464. if (column >= iniArr->ia_columns)
  465. column = 1;
  466. for (i = 0; i < iniArr->ia_rows; i++) {
  467. u32 reg = INI_RA(iniArr, i, 0);
  468. u32 val = INI_RA(iniArr, i, column);
  469. if (reg >= 0x16000 && reg < 0x17000)
  470. ath9k_hw_analog_shift_regwrite(ah, reg, val);
  471. else
  472. REG_WRITE(ah, reg, val);
  473. DO_DELAY(regWrites);
  474. }
  475. }
  476. static int ar9003_hw_process_ini(struct ath_hw *ah,
  477. struct ath9k_channel *chan)
  478. {
  479. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  480. unsigned int regWrites = 0, i;
  481. struct ieee80211_channel *channel = chan->chan;
  482. u32 modesIndex, freqIndex;
  483. switch (chan->chanmode) {
  484. case CHANNEL_A:
  485. case CHANNEL_A_HT20:
  486. modesIndex = 1;
  487. freqIndex = 1;
  488. break;
  489. case CHANNEL_A_HT40PLUS:
  490. case CHANNEL_A_HT40MINUS:
  491. modesIndex = 2;
  492. freqIndex = 1;
  493. break;
  494. case CHANNEL_G:
  495. case CHANNEL_G_HT20:
  496. case CHANNEL_B:
  497. modesIndex = 4;
  498. freqIndex = 2;
  499. break;
  500. case CHANNEL_G_HT40PLUS:
  501. case CHANNEL_G_HT40MINUS:
  502. modesIndex = 3;
  503. freqIndex = 2;
  504. break;
  505. default:
  506. return -EINVAL;
  507. }
  508. for (i = 0; i < ATH_INI_NUM_SPLIT; i++) {
  509. ar9003_hw_prog_ini(ah, &ah->iniSOC[i], modesIndex);
  510. ar9003_hw_prog_ini(ah, &ah->iniMac[i], modesIndex);
  511. ar9003_hw_prog_ini(ah, &ah->iniBB[i], modesIndex);
  512. ar9003_hw_prog_ini(ah, &ah->iniRadio[i], modesIndex);
  513. }
  514. REG_WRITE_ARRAY(&ah->iniModesRxGain, 1, regWrites);
  515. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  516. /*
  517. * For 5GHz channels requiring Fast Clock, apply
  518. * different modal values.
  519. */
  520. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  521. REG_WRITE_ARRAY(&ah->iniModesAdditional,
  522. modesIndex, regWrites);
  523. ar9003_hw_override_ini(ah);
  524. ar9003_hw_set_channel_regs(ah, chan);
  525. ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
  526. /* Set TX power */
  527. ah->eep_ops->set_txpower(ah, chan,
  528. ath9k_regd_get_ctl(regulatory, chan),
  529. channel->max_antenna_gain * 2,
  530. channel->max_power * 2,
  531. min((u32) MAX_RATE_POWER,
  532. (u32) regulatory->power_limit));
  533. return 0;
  534. }
  535. static void ar9003_hw_set_rfmode(struct ath_hw *ah,
  536. struct ath9k_channel *chan)
  537. {
  538. u32 rfMode = 0;
  539. if (chan == NULL)
  540. return;
  541. rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
  542. ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
  543. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  544. rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
  545. REG_WRITE(ah, AR_PHY_MODE, rfMode);
  546. }
  547. static void ar9003_hw_mark_phy_inactive(struct ath_hw *ah)
  548. {
  549. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
  550. }
  551. static void ar9003_hw_set_delta_slope(struct ath_hw *ah,
  552. struct ath9k_channel *chan)
  553. {
  554. u32 coef_scaled, ds_coef_exp, ds_coef_man;
  555. u32 clockMhzScaled = 0x64000000;
  556. struct chan_centers centers;
  557. /*
  558. * half and quarter rate can divide the scaled clock by 2 or 4
  559. * scale for selected channel bandwidth
  560. */
  561. if (IS_CHAN_HALF_RATE(chan))
  562. clockMhzScaled = clockMhzScaled >> 1;
  563. else if (IS_CHAN_QUARTER_RATE(chan))
  564. clockMhzScaled = clockMhzScaled >> 2;
  565. /*
  566. * ALGO -> coef = 1e8/fcarrier*fclock/40;
  567. * scaled coef to provide precision for this floating calculation
  568. */
  569. ath9k_hw_get_channel_centers(ah, chan, &centers);
  570. coef_scaled = clockMhzScaled / centers.synth_center;
  571. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  572. &ds_coef_exp);
  573. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  574. AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
  575. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  576. AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
  577. /*
  578. * For Short GI,
  579. * scaled coeff is 9/10 that of normal coeff
  580. */
  581. coef_scaled = (9 * coef_scaled) / 10;
  582. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  583. &ds_coef_exp);
  584. /* for short gi */
  585. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  586. AR_PHY_SGI_DSC_MAN, ds_coef_man);
  587. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  588. AR_PHY_SGI_DSC_EXP, ds_coef_exp);
  589. }
  590. static bool ar9003_hw_rfbus_req(struct ath_hw *ah)
  591. {
  592. REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
  593. return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
  594. AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT);
  595. }
  596. /*
  597. * Wait for the frequency synth to settle (synth goes on via PHY_ACTIVE_EN).
  598. * Read the phy active delay register. Value is in 100ns increments.
  599. */
  600. static void ar9003_hw_rfbus_done(struct ath_hw *ah)
  601. {
  602. u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  603. if (IS_CHAN_B(ah->curchan))
  604. synthDelay = (4 * synthDelay) / 22;
  605. else
  606. synthDelay /= 10;
  607. udelay(synthDelay + BASE_ACTIVATE_DELAY);
  608. REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
  609. }
  610. /*
  611. * Set the interrupt and GPIO values so the ISR can disable RF
  612. * on a switch signal. Assumes GPIO port and interrupt polarity
  613. * are set prior to call.
  614. */
  615. static void ar9003_hw_enable_rfkill(struct ath_hw *ah)
  616. {
  617. /* Connect rfsilent_bb_l to baseband */
  618. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
  619. AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
  620. /* Set input mux for rfsilent_bb_l to GPIO #0 */
  621. REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
  622. AR_GPIO_INPUT_MUX2_RFSILENT);
  623. /*
  624. * Configure the desired GPIO port for input and
  625. * enable baseband rf silence.
  626. */
  627. ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
  628. REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
  629. }
  630. static void ar9003_hw_set_diversity(struct ath_hw *ah, bool value)
  631. {
  632. u32 v = REG_READ(ah, AR_PHY_CCK_DETECT);
  633. if (value)
  634. v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
  635. else
  636. v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
  637. REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
  638. }
  639. static bool ar9003_hw_ani_control(struct ath_hw *ah,
  640. enum ath9k_ani_cmd cmd, int param)
  641. {
  642. struct ar5416AniState *aniState = ah->curani;
  643. struct ath_common *common = ath9k_hw_common(ah);
  644. struct ath9k_channel *chan = ah->curchan;
  645. s32 value, value2;
  646. switch (cmd & ah->ani_function) {
  647. case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
  648. /*
  649. * on == 1 means ofdm weak signal detection is ON
  650. * on == 1 is the default, for less noise immunity
  651. *
  652. * on == 0 means ofdm weak signal detection is OFF
  653. * on == 0 means more noise imm
  654. */
  655. u32 on = param ? 1 : 0;
  656. /*
  657. * make register setting for default
  658. * (weak sig detect ON) come from INI file
  659. */
  660. int m1ThreshLow = on ?
  661. aniState->iniDef.m1ThreshLow : m1ThreshLow_off;
  662. int m2ThreshLow = on ?
  663. aniState->iniDef.m2ThreshLow : m2ThreshLow_off;
  664. int m1Thresh = on ?
  665. aniState->iniDef.m1Thresh : m1Thresh_off;
  666. int m2Thresh = on ?
  667. aniState->iniDef.m2Thresh : m2Thresh_off;
  668. int m2CountThr = on ?
  669. aniState->iniDef.m2CountThr : m2CountThr_off;
  670. int m2CountThrLow = on ?
  671. aniState->iniDef.m2CountThrLow : m2CountThrLow_off;
  672. int m1ThreshLowExt = on ?
  673. aniState->iniDef.m1ThreshLowExt : m1ThreshLowExt_off;
  674. int m2ThreshLowExt = on ?
  675. aniState->iniDef.m2ThreshLowExt : m2ThreshLowExt_off;
  676. int m1ThreshExt = on ?
  677. aniState->iniDef.m1ThreshExt : m1ThreshExt_off;
  678. int m2ThreshExt = on ?
  679. aniState->iniDef.m2ThreshExt : m2ThreshExt_off;
  680. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  681. AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
  682. m1ThreshLow);
  683. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  684. AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
  685. m2ThreshLow);
  686. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  687. AR_PHY_SFCORR_M1_THRESH, m1Thresh);
  688. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  689. AR_PHY_SFCORR_M2_THRESH, m2Thresh);
  690. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  691. AR_PHY_SFCORR_M2COUNT_THR, m2CountThr);
  692. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  693. AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
  694. m2CountThrLow);
  695. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  696. AR_PHY_SFCORR_EXT_M1_THRESH_LOW, m1ThreshLowExt);
  697. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  698. AR_PHY_SFCORR_EXT_M2_THRESH_LOW, m2ThreshLowExt);
  699. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  700. AR_PHY_SFCORR_EXT_M1_THRESH, m1ThreshExt);
  701. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  702. AR_PHY_SFCORR_EXT_M2_THRESH, m2ThreshExt);
  703. if (on)
  704. REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
  705. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  706. else
  707. REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
  708. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  709. if (!on != aniState->ofdmWeakSigDetectOff) {
  710. ath_print(common, ATH_DBG_ANI,
  711. "** ch %d: ofdm weak signal: %s=>%s\n",
  712. chan->channel,
  713. !aniState->ofdmWeakSigDetectOff ?
  714. "on" : "off",
  715. on ? "on" : "off");
  716. if (on)
  717. ah->stats.ast_ani_ofdmon++;
  718. else
  719. ah->stats.ast_ani_ofdmoff++;
  720. aniState->ofdmWeakSigDetectOff = !on;
  721. }
  722. break;
  723. }
  724. case ATH9K_ANI_FIRSTEP_LEVEL:{
  725. u32 level = param;
  726. if (level >= ARRAY_SIZE(firstep_table)) {
  727. ath_print(common, ATH_DBG_ANI,
  728. "ATH9K_ANI_FIRSTEP_LEVEL: level "
  729. "out of range (%u > %u)\n",
  730. level,
  731. (unsigned) ARRAY_SIZE(firstep_table));
  732. return false;
  733. }
  734. /*
  735. * make register setting relative to default
  736. * from INI file & cap value
  737. */
  738. value = firstep_table[level] -
  739. firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
  740. aniState->iniDef.firstep;
  741. if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  742. value = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  743. if (value > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  744. value = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  745. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  746. AR_PHY_FIND_SIG_FIRSTEP,
  747. value);
  748. /*
  749. * we need to set first step low register too
  750. * make register setting relative to default
  751. * from INI file & cap value
  752. */
  753. value2 = firstep_table[level] -
  754. firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
  755. aniState->iniDef.firstepLow;
  756. if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  757. value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  758. if (value2 > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  759. value2 = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  760. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
  761. AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW, value2);
  762. if (level != aniState->firstepLevel) {
  763. ath_print(common, ATH_DBG_ANI,
  764. "** ch %d: level %d=>%d[def:%d] "
  765. "firstep[level]=%d ini=%d\n",
  766. chan->channel,
  767. aniState->firstepLevel,
  768. level,
  769. ATH9K_ANI_FIRSTEP_LVL_NEW,
  770. value,
  771. aniState->iniDef.firstep);
  772. ath_print(common, ATH_DBG_ANI,
  773. "** ch %d: level %d=>%d[def:%d] "
  774. "firstep_low[level]=%d ini=%d\n",
  775. chan->channel,
  776. aniState->firstepLevel,
  777. level,
  778. ATH9K_ANI_FIRSTEP_LVL_NEW,
  779. value2,
  780. aniState->iniDef.firstepLow);
  781. if (level > aniState->firstepLevel)
  782. ah->stats.ast_ani_stepup++;
  783. else if (level < aniState->firstepLevel)
  784. ah->stats.ast_ani_stepdown++;
  785. aniState->firstepLevel = level;
  786. }
  787. break;
  788. }
  789. case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
  790. u32 level = param;
  791. if (level >= ARRAY_SIZE(cycpwrThr1_table)) {
  792. ath_print(common, ATH_DBG_ANI,
  793. "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level "
  794. "out of range (%u > %u)\n",
  795. level,
  796. (unsigned) ARRAY_SIZE(cycpwrThr1_table));
  797. return false;
  798. }
  799. /*
  800. * make register setting relative to default
  801. * from INI file & cap value
  802. */
  803. value = cycpwrThr1_table[level] -
  804. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
  805. aniState->iniDef.cycpwrThr1;
  806. if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  807. value = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  808. if (value > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  809. value = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  810. REG_RMW_FIELD(ah, AR_PHY_TIMING5,
  811. AR_PHY_TIMING5_CYCPWR_THR1,
  812. value);
  813. /*
  814. * set AR_PHY_EXT_CCA for extension channel
  815. * make register setting relative to default
  816. * from INI file & cap value
  817. */
  818. value2 = cycpwrThr1_table[level] -
  819. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
  820. aniState->iniDef.cycpwrThr1Ext;
  821. if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  822. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  823. if (value2 > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  824. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  825. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
  826. AR_PHY_EXT_CYCPWR_THR1, value2);
  827. if (level != aniState->spurImmunityLevel) {
  828. ath_print(common, ATH_DBG_ANI,
  829. "** ch %d: level %d=>%d[def:%d] "
  830. "cycpwrThr1[level]=%d ini=%d\n",
  831. chan->channel,
  832. aniState->spurImmunityLevel,
  833. level,
  834. ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
  835. value,
  836. aniState->iniDef.cycpwrThr1);
  837. ath_print(common, ATH_DBG_ANI,
  838. "** ch %d: level %d=>%d[def:%d] "
  839. "cycpwrThr1Ext[level]=%d ini=%d\n",
  840. chan->channel,
  841. aniState->spurImmunityLevel,
  842. level,
  843. ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
  844. value2,
  845. aniState->iniDef.cycpwrThr1Ext);
  846. if (level > aniState->spurImmunityLevel)
  847. ah->stats.ast_ani_spurup++;
  848. else if (level < aniState->spurImmunityLevel)
  849. ah->stats.ast_ani_spurdown++;
  850. aniState->spurImmunityLevel = level;
  851. }
  852. break;
  853. }
  854. case ATH9K_ANI_MRC_CCK:{
  855. /*
  856. * is_on == 1 means MRC CCK ON (default, less noise imm)
  857. * is_on == 0 means MRC CCK is OFF (more noise imm)
  858. */
  859. bool is_on = param ? 1 : 0;
  860. REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
  861. AR_PHY_MRC_CCK_ENABLE, is_on);
  862. REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
  863. AR_PHY_MRC_CCK_MUX_REG, is_on);
  864. if (!is_on != aniState->mrcCCKOff) {
  865. ath_print(common, ATH_DBG_ANI,
  866. "** ch %d: MRC CCK: %s=>%s\n",
  867. chan->channel,
  868. !aniState->mrcCCKOff ? "on" : "off",
  869. is_on ? "on" : "off");
  870. if (is_on)
  871. ah->stats.ast_ani_ccklow++;
  872. else
  873. ah->stats.ast_ani_cckhigh++;
  874. aniState->mrcCCKOff = !is_on;
  875. }
  876. break;
  877. }
  878. case ATH9K_ANI_PRESENT:
  879. break;
  880. default:
  881. ath_print(common, ATH_DBG_ANI,
  882. "invalid cmd %u\n", cmd);
  883. return false;
  884. }
  885. ath_print(common, ATH_DBG_ANI,
  886. "ANI parameters: SI=%d, ofdmWS=%s FS=%d "
  887. "MRCcck=%s listenTime=%d CC=%d listen=%d "
  888. "ofdmErrs=%d cckErrs=%d\n",
  889. aniState->spurImmunityLevel,
  890. !aniState->ofdmWeakSigDetectOff ? "on" : "off",
  891. aniState->firstepLevel,
  892. !aniState->mrcCCKOff ? "on" : "off",
  893. aniState->listenTime,
  894. aniState->cycleCount,
  895. aniState->listenTime,
  896. aniState->ofdmPhyErrCount,
  897. aniState->cckPhyErrCount);
  898. return true;
  899. }
  900. static void ar9003_hw_do_getnf(struct ath_hw *ah,
  901. int16_t nfarray[NUM_NF_READINGS])
  902. {
  903. int16_t nf;
  904. nf = MS(REG_READ(ah, AR_PHY_CCA_0), AR_PHY_MINCCA_PWR);
  905. nfarray[0] = sign_extend(nf, 9);
  906. nf = MS(REG_READ(ah, AR_PHY_CCA_1), AR_PHY_CH1_MINCCA_PWR);
  907. nfarray[1] = sign_extend(nf, 9);
  908. nf = MS(REG_READ(ah, AR_PHY_CCA_2), AR_PHY_CH2_MINCCA_PWR);
  909. nfarray[2] = sign_extend(nf, 9);
  910. if (!IS_CHAN_HT40(ah->curchan))
  911. return;
  912. nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR);
  913. nfarray[3] = sign_extend(nf, 9);
  914. nf = MS(REG_READ(ah, AR_PHY_EXT_CCA_1), AR_PHY_CH1_EXT_MINCCA_PWR);
  915. nfarray[4] = sign_extend(nf, 9);
  916. nf = MS(REG_READ(ah, AR_PHY_EXT_CCA_2), AR_PHY_CH2_EXT_MINCCA_PWR);
  917. nfarray[5] = sign_extend(nf, 9);
  918. }
  919. static void ar9003_hw_set_nf_limits(struct ath_hw *ah)
  920. {
  921. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_2GHZ;
  922. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_2GHZ;
  923. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9300_2GHZ;
  924. ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_5GHZ;
  925. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_5GHZ;
  926. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9300_5GHZ;
  927. }
  928. /*
  929. * Initialize the ANI register values with default (ini) values.
  930. * This routine is called during a (full) hardware reset after
  931. * all the registers are initialised from the INI.
  932. */
  933. static void ar9003_hw_ani_cache_ini_regs(struct ath_hw *ah)
  934. {
  935. struct ar5416AniState *aniState;
  936. struct ath_common *common = ath9k_hw_common(ah);
  937. struct ath9k_channel *chan = ah->curchan;
  938. struct ath9k_ani_default *iniDef;
  939. int index;
  940. u32 val;
  941. index = ath9k_hw_get_ani_channel_idx(ah, chan);
  942. aniState = &ah->ani[index];
  943. ah->curani = aniState;
  944. iniDef = &aniState->iniDef;
  945. ath_print(common, ATH_DBG_ANI,
  946. "ver %d.%d opmode %u chan %d Mhz/0x%x\n",
  947. ah->hw_version.macVersion,
  948. ah->hw_version.macRev,
  949. ah->opmode,
  950. chan->channel,
  951. chan->channelFlags);
  952. val = REG_READ(ah, AR_PHY_SFCORR);
  953. iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH);
  954. iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH);
  955. iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR);
  956. val = REG_READ(ah, AR_PHY_SFCORR_LOW);
  957. iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW);
  958. iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW);
  959. iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW);
  960. val = REG_READ(ah, AR_PHY_SFCORR_EXT);
  961. iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH);
  962. iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH);
  963. iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW);
  964. iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW);
  965. iniDef->firstep = REG_READ_FIELD(ah,
  966. AR_PHY_FIND_SIG,
  967. AR_PHY_FIND_SIG_FIRSTEP);
  968. iniDef->firstepLow = REG_READ_FIELD(ah,
  969. AR_PHY_FIND_SIG_LOW,
  970. AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW);
  971. iniDef->cycpwrThr1 = REG_READ_FIELD(ah,
  972. AR_PHY_TIMING5,
  973. AR_PHY_TIMING5_CYCPWR_THR1);
  974. iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah,
  975. AR_PHY_EXT_CCA,
  976. AR_PHY_EXT_CYCPWR_THR1);
  977. /* these levels just got reset to defaults by the INI */
  978. aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL_NEW;
  979. aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL_NEW;
  980. aniState->ofdmWeakSigDetectOff = !ATH9K_ANI_USE_OFDM_WEAK_SIG;
  981. aniState->mrcCCKOff = !ATH9K_ANI_ENABLE_MRC_CCK;
  982. aniState->cycleCount = 0;
  983. }
  984. void ar9003_hw_attach_phy_ops(struct ath_hw *ah)
  985. {
  986. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  987. const u32 ar9300_cca_regs[6] = {
  988. AR_PHY_CCA_0,
  989. AR_PHY_CCA_1,
  990. AR_PHY_CCA_2,
  991. AR_PHY_EXT_CCA,
  992. AR_PHY_EXT_CCA_1,
  993. AR_PHY_EXT_CCA_2,
  994. };
  995. priv_ops->rf_set_freq = ar9003_hw_set_channel;
  996. priv_ops->spur_mitigate_freq = ar9003_hw_spur_mitigate;
  997. priv_ops->compute_pll_control = ar9003_hw_compute_pll_control;
  998. priv_ops->set_channel_regs = ar9003_hw_set_channel_regs;
  999. priv_ops->init_bb = ar9003_hw_init_bb;
  1000. priv_ops->process_ini = ar9003_hw_process_ini;
  1001. priv_ops->set_rfmode = ar9003_hw_set_rfmode;
  1002. priv_ops->mark_phy_inactive = ar9003_hw_mark_phy_inactive;
  1003. priv_ops->set_delta_slope = ar9003_hw_set_delta_slope;
  1004. priv_ops->rfbus_req = ar9003_hw_rfbus_req;
  1005. priv_ops->rfbus_done = ar9003_hw_rfbus_done;
  1006. priv_ops->enable_rfkill = ar9003_hw_enable_rfkill;
  1007. priv_ops->set_diversity = ar9003_hw_set_diversity;
  1008. priv_ops->ani_control = ar9003_hw_ani_control;
  1009. priv_ops->do_getnf = ar9003_hw_do_getnf;
  1010. priv_ops->ani_cache_ini_regs = ar9003_hw_ani_cache_ini_regs;
  1011. ar9003_hw_set_nf_limits(ah);
  1012. memcpy(ah->nf_regs, ar9300_cca_regs, sizeof(ah->nf_regs));
  1013. }
  1014. void ar9003_hw_bb_watchdog_config(struct ath_hw *ah)
  1015. {
  1016. struct ath_common *common = ath9k_hw_common(ah);
  1017. u32 idle_tmo_ms = ah->bb_watchdog_timeout_ms;
  1018. u32 val, idle_count;
  1019. if (!idle_tmo_ms) {
  1020. /* disable IRQ, disable chip-reset for BB panic */
  1021. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
  1022. REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) &
  1023. ~(AR_PHY_WATCHDOG_RST_ENABLE |
  1024. AR_PHY_WATCHDOG_IRQ_ENABLE));
  1025. /* disable watchdog in non-IDLE mode, disable in IDLE mode */
  1026. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
  1027. REG_READ(ah, AR_PHY_WATCHDOG_CTL_1) &
  1028. ~(AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
  1029. AR_PHY_WATCHDOG_IDLE_ENABLE));
  1030. ath_print(common, ATH_DBG_RESET, "Disabled BB Watchdog\n");
  1031. return;
  1032. }
  1033. /* enable IRQ, disable chip-reset for BB watchdog */
  1034. val = REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) & AR_PHY_WATCHDOG_CNTL2_MASK;
  1035. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
  1036. (val | AR_PHY_WATCHDOG_IRQ_ENABLE) &
  1037. ~AR_PHY_WATCHDOG_RST_ENABLE);
  1038. /* bound limit to 10 secs */
  1039. if (idle_tmo_ms > 10000)
  1040. idle_tmo_ms = 10000;
  1041. /*
  1042. * The time unit for watchdog event is 2^15 44/88MHz cycles.
  1043. *
  1044. * For HT20 we have a time unit of 2^15/44 MHz = .74 ms per tick
  1045. * For HT40 we have a time unit of 2^15/88 MHz = .37 ms per tick
  1046. *
  1047. * Given we use fast clock now in 5 GHz, these time units should
  1048. * be common for both 2 GHz and 5 GHz.
  1049. */
  1050. idle_count = (100 * idle_tmo_ms) / 74;
  1051. if (ah->curchan && IS_CHAN_HT40(ah->curchan))
  1052. idle_count = (100 * idle_tmo_ms) / 37;
  1053. /*
  1054. * enable watchdog in non-IDLE mode, disable in IDLE mode,
  1055. * set idle time-out.
  1056. */
  1057. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
  1058. AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
  1059. AR_PHY_WATCHDOG_IDLE_MASK |
  1060. (AR_PHY_WATCHDOG_NON_IDLE_MASK & (idle_count << 2)));
  1061. ath_print(common, ATH_DBG_RESET,
  1062. "Enabled BB Watchdog timeout (%u ms)\n",
  1063. idle_tmo_ms);
  1064. }
  1065. void ar9003_hw_bb_watchdog_read(struct ath_hw *ah)
  1066. {
  1067. /*
  1068. * we want to avoid printing in ISR context so we save the
  1069. * watchdog status to be printed later in bottom half context.
  1070. */
  1071. ah->bb_watchdog_last_status = REG_READ(ah, AR_PHY_WATCHDOG_STATUS);
  1072. /*
  1073. * the watchdog timer should reset on status read but to be sure
  1074. * sure we write 0 to the watchdog status bit.
  1075. */
  1076. REG_WRITE(ah, AR_PHY_WATCHDOG_STATUS,
  1077. ah->bb_watchdog_last_status & ~AR_PHY_WATCHDOG_STATUS_CLR);
  1078. }
  1079. void ar9003_hw_bb_watchdog_dbg_info(struct ath_hw *ah)
  1080. {
  1081. struct ath_common *common = ath9k_hw_common(ah);
  1082. u32 rxc_pcnt = 0, rxf_pcnt = 0, txf_pcnt = 0, status;
  1083. if (likely(!(common->debug_mask & ATH_DBG_RESET)))
  1084. return;
  1085. status = ah->bb_watchdog_last_status;
  1086. ath_print(common, ATH_DBG_RESET,
  1087. "\n==== BB update: BB status=0x%08x ====\n", status);
  1088. ath_print(common, ATH_DBG_RESET,
  1089. "** BB state: wd=%u det=%u rdar=%u rOFDM=%d "
  1090. "rCCK=%u tOFDM=%u tCCK=%u agc=%u src=%u **\n",
  1091. MS(status, AR_PHY_WATCHDOG_INFO),
  1092. MS(status, AR_PHY_WATCHDOG_DET_HANG),
  1093. MS(status, AR_PHY_WATCHDOG_RADAR_SM),
  1094. MS(status, AR_PHY_WATCHDOG_RX_OFDM_SM),
  1095. MS(status, AR_PHY_WATCHDOG_RX_CCK_SM),
  1096. MS(status, AR_PHY_WATCHDOG_TX_OFDM_SM),
  1097. MS(status, AR_PHY_WATCHDOG_TX_CCK_SM),
  1098. MS(status, AR_PHY_WATCHDOG_AGC_SM),
  1099. MS(status,AR_PHY_WATCHDOG_SRCH_SM));
  1100. ath_print(common, ATH_DBG_RESET,
  1101. "** BB WD cntl: cntl1=0x%08x cntl2=0x%08x **\n",
  1102. REG_READ(ah, AR_PHY_WATCHDOG_CTL_1),
  1103. REG_READ(ah, AR_PHY_WATCHDOG_CTL_2));
  1104. ath_print(common, ATH_DBG_RESET,
  1105. "** BB mode: BB_gen_controls=0x%08x **\n",
  1106. REG_READ(ah, AR_PHY_GEN_CTRL));
  1107. if (ath9k_hw_GetMibCycleCountsPct(ah, &rxc_pcnt, &rxf_pcnt, &txf_pcnt))
  1108. ath_print(common, ATH_DBG_RESET,
  1109. "** BB busy times: rx_clear=%d%%, "
  1110. "rx_frame=%d%%, tx_frame=%d%% **\n",
  1111. rxc_pcnt, rxf_pcnt, txf_pcnt);
  1112. ath_print(common, ATH_DBG_RESET,
  1113. "==== BB update: done ====\n\n");
  1114. }
  1115. EXPORT_SYMBOL(ar9003_hw_bb_watchdog_dbg_info);