ar9003_phy.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134
  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_mrc_cck(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. /* Clean all spur register fields */
  140. static void ar9003_hw_spur_ofdm_clear(struct ath_hw *ah)
  141. {
  142. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  143. AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0);
  144. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  145. AR_PHY_TIMING11_SPUR_FREQ_SD, 0);
  146. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  147. AR_PHY_TIMING11_SPUR_DELTA_PHASE, 0);
  148. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  149. AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, 0);
  150. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  151. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0);
  152. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  153. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0);
  154. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  155. AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0);
  156. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  157. AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 0);
  158. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  159. AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 0);
  160. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  161. AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0);
  162. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  163. AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0);
  164. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  165. AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0);
  166. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  167. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, 0);
  168. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  169. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, 0);
  170. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  171. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, 0);
  172. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  173. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0);
  174. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  175. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0);
  176. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  177. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0);
  178. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  179. AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0);
  180. }
  181. static void ar9003_hw_spur_ofdm(struct ath_hw *ah,
  182. int freq_offset,
  183. int spur_freq_sd,
  184. int spur_delta_phase,
  185. int spur_subchannel_sd)
  186. {
  187. int mask_index = 0;
  188. /* OFDM Spur mitigation */
  189. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  190. AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0x1);
  191. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  192. AR_PHY_TIMING11_SPUR_FREQ_SD, spur_freq_sd);
  193. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  194. AR_PHY_TIMING11_SPUR_DELTA_PHASE, spur_delta_phase);
  195. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  196. AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, spur_subchannel_sd);
  197. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  198. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0x1);
  199. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  200. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0x1);
  201. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  202. AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0x1);
  203. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  204. AR_PHY_SPUR_REG_SPUR_RSSI_THRESH, 34);
  205. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  206. AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 1);
  207. if (REG_READ_FIELD(ah, AR_PHY_MODE,
  208. AR_PHY_MODE_DYNAMIC) == 0x1)
  209. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  210. AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 1);
  211. mask_index = (freq_offset << 4) / 5;
  212. if (mask_index < 0)
  213. mask_index = mask_index - 1;
  214. mask_index = mask_index & 0x7f;
  215. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  216. AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0x1);
  217. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  218. AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0x1);
  219. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  220. AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0x1);
  221. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  222. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, mask_index);
  223. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  224. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, mask_index);
  225. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  226. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, mask_index);
  227. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  228. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0xc);
  229. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  230. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0xc);
  231. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  232. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0xa0);
  233. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  234. AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0xff);
  235. }
  236. static void ar9003_hw_spur_ofdm_work(struct ath_hw *ah,
  237. struct ath9k_channel *chan,
  238. int freq_offset)
  239. {
  240. int spur_freq_sd = 0;
  241. int spur_subchannel_sd = 0;
  242. int spur_delta_phase = 0;
  243. if (IS_CHAN_HT40(chan)) {
  244. if (freq_offset < 0) {
  245. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  246. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  247. spur_subchannel_sd = 1;
  248. else
  249. spur_subchannel_sd = 0;
  250. spur_freq_sd = ((freq_offset + 10) << 9) / 11;
  251. } else {
  252. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  253. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  254. spur_subchannel_sd = 0;
  255. else
  256. spur_subchannel_sd = 1;
  257. spur_freq_sd = ((freq_offset - 10) << 9) / 11;
  258. }
  259. spur_delta_phase = (freq_offset << 17) / 5;
  260. } else {
  261. spur_subchannel_sd = 0;
  262. spur_freq_sd = (freq_offset << 9) /11;
  263. spur_delta_phase = (freq_offset << 18) / 5;
  264. }
  265. spur_freq_sd = spur_freq_sd & 0x3ff;
  266. spur_delta_phase = spur_delta_phase & 0xfffff;
  267. ar9003_hw_spur_ofdm(ah,
  268. freq_offset,
  269. spur_freq_sd,
  270. spur_delta_phase,
  271. spur_subchannel_sd);
  272. }
  273. /* Spur mitigation for OFDM */
  274. static void ar9003_hw_spur_mitigate_ofdm(struct ath_hw *ah,
  275. struct ath9k_channel *chan)
  276. {
  277. int synth_freq;
  278. int range = 10;
  279. int freq_offset = 0;
  280. int mode;
  281. u8* spurChansPtr;
  282. unsigned int i;
  283. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  284. if (IS_CHAN_5GHZ(chan)) {
  285. spurChansPtr = &(eep->modalHeader5G.spurChans[0]);
  286. mode = 0;
  287. }
  288. else {
  289. spurChansPtr = &(eep->modalHeader2G.spurChans[0]);
  290. mode = 1;
  291. }
  292. if (spurChansPtr[0] == 0)
  293. return; /* No spur in the mode */
  294. if (IS_CHAN_HT40(chan)) {
  295. range = 19;
  296. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  297. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  298. synth_freq = chan->channel - 10;
  299. else
  300. synth_freq = chan->channel + 10;
  301. } else {
  302. range = 10;
  303. synth_freq = chan->channel;
  304. }
  305. ar9003_hw_spur_ofdm_clear(ah);
  306. for (i = 0; spurChansPtr[i] && i < 5; i++) {
  307. freq_offset = FBIN2FREQ(spurChansPtr[i], mode) - synth_freq;
  308. if (abs(freq_offset) < range) {
  309. ar9003_hw_spur_ofdm_work(ah, chan, freq_offset);
  310. break;
  311. }
  312. }
  313. }
  314. static void ar9003_hw_spur_mitigate(struct ath_hw *ah,
  315. struct ath9k_channel *chan)
  316. {
  317. ar9003_hw_spur_mitigate_mrc_cck(ah, chan);
  318. ar9003_hw_spur_mitigate_ofdm(ah, chan);
  319. }
  320. static u32 ar9003_hw_compute_pll_control(struct ath_hw *ah,
  321. struct ath9k_channel *chan)
  322. {
  323. u32 pll;
  324. pll = SM(0x5, AR_RTC_9300_PLL_REFDIV);
  325. if (chan && IS_CHAN_HALF_RATE(chan))
  326. pll |= SM(0x1, AR_RTC_9300_PLL_CLKSEL);
  327. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  328. pll |= SM(0x2, AR_RTC_9300_PLL_CLKSEL);
  329. pll |= SM(0x2c, AR_RTC_9300_PLL_DIV);
  330. return pll;
  331. }
  332. static void ar9003_hw_set_channel_regs(struct ath_hw *ah,
  333. struct ath9k_channel *chan)
  334. {
  335. u32 phymode;
  336. u32 enableDacFifo = 0;
  337. enableDacFifo =
  338. (REG_READ(ah, AR_PHY_GEN_CTRL) & AR_PHY_GC_ENABLE_DAC_FIFO);
  339. /* Enable 11n HT, 20 MHz */
  340. phymode = AR_PHY_GC_HT_EN | AR_PHY_GC_SINGLE_HT_LTF1 | AR_PHY_GC_WALSH |
  341. AR_PHY_GC_SHORT_GI_40 | enableDacFifo;
  342. /* Configure baseband for dynamic 20/40 operation */
  343. if (IS_CHAN_HT40(chan)) {
  344. phymode |= AR_PHY_GC_DYN2040_EN;
  345. /* Configure control (primary) channel at +-10MHz */
  346. if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
  347. (chan->chanmode == CHANNEL_G_HT40PLUS))
  348. phymode |= AR_PHY_GC_DYN2040_PRI_CH;
  349. }
  350. /* make sure we preserve INI settings */
  351. phymode |= REG_READ(ah, AR_PHY_GEN_CTRL);
  352. /* turn off Green Field detection for STA for now */
  353. phymode &= ~AR_PHY_GC_GF_DETECT_EN;
  354. REG_WRITE(ah, AR_PHY_GEN_CTRL, phymode);
  355. /* Configure MAC for 20/40 operation */
  356. ath9k_hw_set11nmac2040(ah);
  357. /* global transmit timeout (25 TUs default)*/
  358. REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
  359. /* carrier sense timeout */
  360. REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
  361. }
  362. static void ar9003_hw_init_bb(struct ath_hw *ah,
  363. struct ath9k_channel *chan)
  364. {
  365. u32 synthDelay;
  366. /*
  367. * Wait for the frequency synth to settle (synth goes on
  368. * via AR_PHY_ACTIVE_EN). Read the phy active delay register.
  369. * Value is in 100ns increments.
  370. */
  371. synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  372. if (IS_CHAN_B(chan))
  373. synthDelay = (4 * synthDelay) / 22;
  374. else
  375. synthDelay /= 10;
  376. /* Activate the PHY (includes baseband activate + synthesizer on) */
  377. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
  378. /*
  379. * There is an issue if the AP starts the calibration before
  380. * the base band timeout completes. This could result in the
  381. * rx_clear false triggering. As a workaround we add delay an
  382. * extra BASE_ACTIVATE_DELAY usecs to ensure this condition
  383. * does not happen.
  384. */
  385. udelay(synthDelay + BASE_ACTIVATE_DELAY);
  386. }
  387. void ar9003_hw_set_chain_masks(struct ath_hw *ah, u8 rx, u8 tx)
  388. {
  389. switch (rx) {
  390. case 0x5:
  391. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  392. AR_PHY_SWAP_ALT_CHAIN);
  393. case 0x3:
  394. case 0x1:
  395. case 0x2:
  396. case 0x7:
  397. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx);
  398. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx);
  399. break;
  400. default:
  401. break;
  402. }
  403. REG_WRITE(ah, AR_SELFGEN_MASK, tx);
  404. if (tx == 0x5) {
  405. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  406. AR_PHY_SWAP_ALT_CHAIN);
  407. }
  408. }
  409. /*
  410. * Override INI values with chip specific configuration.
  411. */
  412. static void ar9003_hw_override_ini(struct ath_hw *ah)
  413. {
  414. u32 val;
  415. /*
  416. * Set the RX_ABORT and RX_DIS and clear it only after
  417. * RXE is set for MAC. This prevents frames with
  418. * corrupted descriptor status.
  419. */
  420. REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  421. /*
  422. * For AR9280 and above, there is a new feature that allows
  423. * Multicast search based on both MAC Address and Key ID. By default,
  424. * this feature is enabled. But since the driver is not using this
  425. * feature, we switch it off; otherwise multicast search based on
  426. * MAC addr only will fail.
  427. */
  428. val = REG_READ(ah, AR_PCU_MISC_MODE2) & (~AR_ADHOC_MCAST_KEYID_ENABLE);
  429. REG_WRITE(ah, AR_PCU_MISC_MODE2,
  430. val | AR_AGG_WEP_ENABLE_FIX | AR_AGG_WEP_ENABLE);
  431. }
  432. static void ar9003_hw_prog_ini(struct ath_hw *ah,
  433. struct ar5416IniArray *iniArr,
  434. int column)
  435. {
  436. unsigned int i, regWrites = 0;
  437. /* New INI format: Array may be undefined (pre, core, post arrays) */
  438. if (!iniArr->ia_array)
  439. return;
  440. /*
  441. * New INI format: Pre, core, and post arrays for a given subsystem
  442. * may be modal (> 2 columns) or non-modal (2 columns). Determine if
  443. * the array is non-modal and force the column to 1.
  444. */
  445. if (column >= iniArr->ia_columns)
  446. column = 1;
  447. for (i = 0; i < iniArr->ia_rows; i++) {
  448. u32 reg = INI_RA(iniArr, i, 0);
  449. u32 val = INI_RA(iniArr, i, column);
  450. REG_WRITE(ah, reg, val);
  451. /*
  452. * Determine if this is a shift register value, and insert the
  453. * configured delay if so.
  454. */
  455. if (reg >= 0x16000 && reg < 0x17000
  456. && ah->config.analog_shiftreg)
  457. udelay(100);
  458. DO_DELAY(regWrites);
  459. }
  460. }
  461. static int ar9003_hw_process_ini(struct ath_hw *ah,
  462. struct ath9k_channel *chan)
  463. {
  464. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  465. unsigned int regWrites = 0, i;
  466. struct ieee80211_channel *channel = chan->chan;
  467. u32 modesIndex, freqIndex;
  468. switch (chan->chanmode) {
  469. case CHANNEL_A:
  470. case CHANNEL_A_HT20:
  471. modesIndex = 1;
  472. freqIndex = 1;
  473. break;
  474. case CHANNEL_A_HT40PLUS:
  475. case CHANNEL_A_HT40MINUS:
  476. modesIndex = 2;
  477. freqIndex = 1;
  478. break;
  479. case CHANNEL_G:
  480. case CHANNEL_G_HT20:
  481. case CHANNEL_B:
  482. modesIndex = 4;
  483. freqIndex = 2;
  484. break;
  485. case CHANNEL_G_HT40PLUS:
  486. case CHANNEL_G_HT40MINUS:
  487. modesIndex = 3;
  488. freqIndex = 2;
  489. break;
  490. default:
  491. return -EINVAL;
  492. }
  493. for (i = 0; i < ATH_INI_NUM_SPLIT; i++) {
  494. ar9003_hw_prog_ini(ah, &ah->iniSOC[i], modesIndex);
  495. ar9003_hw_prog_ini(ah, &ah->iniMac[i], modesIndex);
  496. ar9003_hw_prog_ini(ah, &ah->iniBB[i], modesIndex);
  497. ar9003_hw_prog_ini(ah, &ah->iniRadio[i], modesIndex);
  498. }
  499. REG_WRITE_ARRAY(&ah->iniModesRxGain, 1, regWrites);
  500. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  501. /*
  502. * For 5GHz channels requiring Fast Clock, apply
  503. * different modal values.
  504. */
  505. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  506. REG_WRITE_ARRAY(&ah->iniModesAdditional,
  507. modesIndex, regWrites);
  508. ar9003_hw_override_ini(ah);
  509. ar9003_hw_set_channel_regs(ah, chan);
  510. ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
  511. /* Set TX power */
  512. ah->eep_ops->set_txpower(ah, chan,
  513. ath9k_regd_get_ctl(regulatory, chan),
  514. channel->max_antenna_gain * 2,
  515. channel->max_power * 2,
  516. min((u32) MAX_RATE_POWER,
  517. (u32) regulatory->power_limit));
  518. return 0;
  519. }
  520. static void ar9003_hw_set_rfmode(struct ath_hw *ah,
  521. struct ath9k_channel *chan)
  522. {
  523. u32 rfMode = 0;
  524. if (chan == NULL)
  525. return;
  526. rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
  527. ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
  528. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  529. rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
  530. REG_WRITE(ah, AR_PHY_MODE, rfMode);
  531. }
  532. static void ar9003_hw_mark_phy_inactive(struct ath_hw *ah)
  533. {
  534. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
  535. }
  536. static void ar9003_hw_set_delta_slope(struct ath_hw *ah,
  537. struct ath9k_channel *chan)
  538. {
  539. u32 coef_scaled, ds_coef_exp, ds_coef_man;
  540. u32 clockMhzScaled = 0x64000000;
  541. struct chan_centers centers;
  542. /*
  543. * half and quarter rate can divide the scaled clock by 2 or 4
  544. * scale for selected channel bandwidth
  545. */
  546. if (IS_CHAN_HALF_RATE(chan))
  547. clockMhzScaled = clockMhzScaled >> 1;
  548. else if (IS_CHAN_QUARTER_RATE(chan))
  549. clockMhzScaled = clockMhzScaled >> 2;
  550. /*
  551. * ALGO -> coef = 1e8/fcarrier*fclock/40;
  552. * scaled coef to provide precision for this floating calculation
  553. */
  554. ath9k_hw_get_channel_centers(ah, chan, &centers);
  555. coef_scaled = clockMhzScaled / centers.synth_center;
  556. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  557. &ds_coef_exp);
  558. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  559. AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
  560. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  561. AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
  562. /*
  563. * For Short GI,
  564. * scaled coeff is 9/10 that of normal coeff
  565. */
  566. coef_scaled = (9 * coef_scaled) / 10;
  567. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  568. &ds_coef_exp);
  569. /* for short gi */
  570. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  571. AR_PHY_SGI_DSC_MAN, ds_coef_man);
  572. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  573. AR_PHY_SGI_DSC_EXP, ds_coef_exp);
  574. }
  575. static bool ar9003_hw_rfbus_req(struct ath_hw *ah)
  576. {
  577. REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
  578. return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
  579. AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT);
  580. }
  581. /*
  582. * Wait for the frequency synth to settle (synth goes on via PHY_ACTIVE_EN).
  583. * Read the phy active delay register. Value is in 100ns increments.
  584. */
  585. static void ar9003_hw_rfbus_done(struct ath_hw *ah)
  586. {
  587. u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  588. if (IS_CHAN_B(ah->curchan))
  589. synthDelay = (4 * synthDelay) / 22;
  590. else
  591. synthDelay /= 10;
  592. udelay(synthDelay + BASE_ACTIVATE_DELAY);
  593. REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
  594. }
  595. /*
  596. * Set the interrupt and GPIO values so the ISR can disable RF
  597. * on a switch signal. Assumes GPIO port and interrupt polarity
  598. * are set prior to call.
  599. */
  600. static void ar9003_hw_enable_rfkill(struct ath_hw *ah)
  601. {
  602. /* Connect rfsilent_bb_l to baseband */
  603. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
  604. AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
  605. /* Set input mux for rfsilent_bb_l to GPIO #0 */
  606. REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
  607. AR_GPIO_INPUT_MUX2_RFSILENT);
  608. /*
  609. * Configure the desired GPIO port for input and
  610. * enable baseband rf silence.
  611. */
  612. ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
  613. REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
  614. }
  615. static void ar9003_hw_set_diversity(struct ath_hw *ah, bool value)
  616. {
  617. u32 v = REG_READ(ah, AR_PHY_CCK_DETECT);
  618. if (value)
  619. v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
  620. else
  621. v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
  622. REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
  623. }
  624. static bool ar9003_hw_ani_control(struct ath_hw *ah,
  625. enum ath9k_ani_cmd cmd, int param)
  626. {
  627. struct ar5416AniState *aniState = ah->curani;
  628. struct ath_common *common = ath9k_hw_common(ah);
  629. switch (cmd & ah->ani_function) {
  630. case ATH9K_ANI_NOISE_IMMUNITY_LEVEL:{
  631. u32 level = param;
  632. if (level >= ARRAY_SIZE(ah->totalSizeDesired)) {
  633. ath_print(common, ATH_DBG_ANI,
  634. "level out of range (%u > %u)\n",
  635. level,
  636. (unsigned)ARRAY_SIZE(ah->totalSizeDesired));
  637. return false;
  638. }
  639. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
  640. AR_PHY_DESIRED_SZ_TOT_DES,
  641. ah->totalSizeDesired[level]);
  642. REG_RMW_FIELD(ah, AR_PHY_AGC,
  643. AR_PHY_AGC_COARSE_LOW,
  644. ah->coarse_low[level]);
  645. REG_RMW_FIELD(ah, AR_PHY_AGC,
  646. AR_PHY_AGC_COARSE_HIGH,
  647. ah->coarse_high[level]);
  648. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  649. AR_PHY_FIND_SIG_FIRPWR, ah->firpwr[level]);
  650. if (level > aniState->noiseImmunityLevel)
  651. ah->stats.ast_ani_niup++;
  652. else if (level < aniState->noiseImmunityLevel)
  653. ah->stats.ast_ani_nidown++;
  654. aniState->noiseImmunityLevel = level;
  655. break;
  656. }
  657. case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
  658. const int m1ThreshLow[] = { 127, 50 };
  659. const int m2ThreshLow[] = { 127, 40 };
  660. const int m1Thresh[] = { 127, 0x4d };
  661. const int m2Thresh[] = { 127, 0x40 };
  662. const int m2CountThr[] = { 31, 16 };
  663. const int m2CountThrLow[] = { 63, 48 };
  664. u32 on = param ? 1 : 0;
  665. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  666. AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
  667. m1ThreshLow[on]);
  668. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  669. AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
  670. m2ThreshLow[on]);
  671. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  672. AR_PHY_SFCORR_M1_THRESH, m1Thresh[on]);
  673. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  674. AR_PHY_SFCORR_M2_THRESH, m2Thresh[on]);
  675. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  676. AR_PHY_SFCORR_M2COUNT_THR, m2CountThr[on]);
  677. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  678. AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
  679. m2CountThrLow[on]);
  680. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  681. AR_PHY_SFCORR_EXT_M1_THRESH_LOW, m1ThreshLow[on]);
  682. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  683. AR_PHY_SFCORR_EXT_M2_THRESH_LOW, m2ThreshLow[on]);
  684. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  685. AR_PHY_SFCORR_EXT_M1_THRESH, m1Thresh[on]);
  686. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  687. AR_PHY_SFCORR_EXT_M2_THRESH, m2Thresh[on]);
  688. if (on)
  689. REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
  690. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  691. else
  692. REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
  693. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  694. if (!on != aniState->ofdmWeakSigDetectOff) {
  695. if (on)
  696. ah->stats.ast_ani_ofdmon++;
  697. else
  698. ah->stats.ast_ani_ofdmoff++;
  699. aniState->ofdmWeakSigDetectOff = !on;
  700. }
  701. break;
  702. }
  703. case ATH9K_ANI_CCK_WEAK_SIGNAL_THR:{
  704. const int weakSigThrCck[] = { 8, 6 };
  705. u32 high = param ? 1 : 0;
  706. REG_RMW_FIELD(ah, AR_PHY_CCK_DETECT,
  707. AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK,
  708. weakSigThrCck[high]);
  709. if (high != aniState->cckWeakSigThreshold) {
  710. if (high)
  711. ah->stats.ast_ani_cckhigh++;
  712. else
  713. ah->stats.ast_ani_ccklow++;
  714. aniState->cckWeakSigThreshold = high;
  715. }
  716. break;
  717. }
  718. case ATH9K_ANI_FIRSTEP_LEVEL:{
  719. const int firstep[] = { 0, 4, 8 };
  720. u32 level = param;
  721. if (level >= ARRAY_SIZE(firstep)) {
  722. ath_print(common, ATH_DBG_ANI,
  723. "level out of range (%u > %u)\n",
  724. level,
  725. (unsigned) ARRAY_SIZE(firstep));
  726. return false;
  727. }
  728. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  729. AR_PHY_FIND_SIG_FIRSTEP,
  730. firstep[level]);
  731. if (level > aniState->firstepLevel)
  732. ah->stats.ast_ani_stepup++;
  733. else if (level < aniState->firstepLevel)
  734. ah->stats.ast_ani_stepdown++;
  735. aniState->firstepLevel = level;
  736. break;
  737. }
  738. case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
  739. const int cycpwrThr1[] = { 2, 4, 6, 8, 10, 12, 14, 16 };
  740. u32 level = param;
  741. if (level >= ARRAY_SIZE(cycpwrThr1)) {
  742. ath_print(common, ATH_DBG_ANI,
  743. "level out of range (%u > %u)\n",
  744. level,
  745. (unsigned) ARRAY_SIZE(cycpwrThr1));
  746. return false;
  747. }
  748. REG_RMW_FIELD(ah, AR_PHY_TIMING5,
  749. AR_PHY_TIMING5_CYCPWR_THR1,
  750. cycpwrThr1[level]);
  751. if (level > aniState->spurImmunityLevel)
  752. ah->stats.ast_ani_spurup++;
  753. else if (level < aniState->spurImmunityLevel)
  754. ah->stats.ast_ani_spurdown++;
  755. aniState->spurImmunityLevel = level;
  756. break;
  757. }
  758. case ATH9K_ANI_PRESENT:
  759. break;
  760. default:
  761. ath_print(common, ATH_DBG_ANI,
  762. "invalid cmd %u\n", cmd);
  763. return false;
  764. }
  765. ath_print(common, ATH_DBG_ANI, "ANI parameters:\n");
  766. ath_print(common, ATH_DBG_ANI,
  767. "noiseImmunityLevel=%d, spurImmunityLevel=%d, "
  768. "ofdmWeakSigDetectOff=%d\n",
  769. aniState->noiseImmunityLevel,
  770. aniState->spurImmunityLevel,
  771. !aniState->ofdmWeakSigDetectOff);
  772. ath_print(common, ATH_DBG_ANI,
  773. "cckWeakSigThreshold=%d, "
  774. "firstepLevel=%d, listenTime=%d\n",
  775. aniState->cckWeakSigThreshold,
  776. aniState->firstepLevel,
  777. aniState->listenTime);
  778. ath_print(common, ATH_DBG_ANI,
  779. "cycleCount=%d, ofdmPhyErrCount=%d, cckPhyErrCount=%d\n\n",
  780. aniState->cycleCount,
  781. aniState->ofdmPhyErrCount,
  782. aniState->cckPhyErrCount);
  783. return true;
  784. }
  785. static void ar9003_hw_nf_sanitize_2g(struct ath_hw *ah, s16 *nf)
  786. {
  787. struct ath_common *common = ath9k_hw_common(ah);
  788. if (*nf > ah->nf_2g_max) {
  789. ath_print(common, ATH_DBG_CALIBRATE,
  790. "2 GHz NF (%d) > MAX (%d), "
  791. "correcting to MAX",
  792. *nf, ah->nf_2g_max);
  793. *nf = ah->nf_2g_max;
  794. } else if (*nf < ah->nf_2g_min) {
  795. ath_print(common, ATH_DBG_CALIBRATE,
  796. "2 GHz NF (%d) < MIN (%d), "
  797. "correcting to MIN",
  798. *nf, ah->nf_2g_min);
  799. *nf = ah->nf_2g_min;
  800. }
  801. }
  802. static void ar9003_hw_nf_sanitize_5g(struct ath_hw *ah, s16 *nf)
  803. {
  804. struct ath_common *common = ath9k_hw_common(ah);
  805. if (*nf > ah->nf_5g_max) {
  806. ath_print(common, ATH_DBG_CALIBRATE,
  807. "5 GHz NF (%d) > MAX (%d), "
  808. "correcting to MAX",
  809. *nf, ah->nf_5g_max);
  810. *nf = ah->nf_5g_max;
  811. } else if (*nf < ah->nf_5g_min) {
  812. ath_print(common, ATH_DBG_CALIBRATE,
  813. "5 GHz NF (%d) < MIN (%d), "
  814. "correcting to MIN",
  815. *nf, ah->nf_5g_min);
  816. *nf = ah->nf_5g_min;
  817. }
  818. }
  819. static void ar9003_hw_nf_sanitize(struct ath_hw *ah, s16 *nf)
  820. {
  821. if (IS_CHAN_2GHZ(ah->curchan))
  822. ar9003_hw_nf_sanitize_2g(ah, nf);
  823. else
  824. ar9003_hw_nf_sanitize_5g(ah, nf);
  825. }
  826. static void ar9003_hw_do_getnf(struct ath_hw *ah,
  827. int16_t nfarray[NUM_NF_READINGS])
  828. {
  829. struct ath_common *common = ath9k_hw_common(ah);
  830. int16_t nf;
  831. nf = MS(REG_READ(ah, AR_PHY_CCA_0), AR_PHY_MINCCA_PWR);
  832. if (nf & 0x100)
  833. nf = 0 - ((nf ^ 0x1ff) + 1);
  834. ar9003_hw_nf_sanitize(ah, &nf);
  835. ath_print(common, ATH_DBG_CALIBRATE,
  836. "NF calibrated [ctl] [chain 0] is %d\n", nf);
  837. nfarray[0] = nf;
  838. nf = MS(REG_READ(ah, AR_PHY_CCA_1), AR_PHY_CH1_MINCCA_PWR);
  839. if (nf & 0x100)
  840. nf = 0 - ((nf ^ 0x1ff) + 1);
  841. ar9003_hw_nf_sanitize(ah, &nf);
  842. ath_print(common, ATH_DBG_CALIBRATE,
  843. "NF calibrated [ctl] [chain 1] is %d\n", nf);
  844. nfarray[1] = nf;
  845. nf = MS(REG_READ(ah, AR_PHY_CCA_2), AR_PHY_CH2_MINCCA_PWR);
  846. if (nf & 0x100)
  847. nf = 0 - ((nf ^ 0x1ff) + 1);
  848. ar9003_hw_nf_sanitize(ah, &nf);
  849. ath_print(common, ATH_DBG_CALIBRATE,
  850. "NF calibrated [ctl] [chain 2] is %d\n", nf);
  851. nfarray[2] = nf;
  852. nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR);
  853. if (nf & 0x100)
  854. nf = 0 - ((nf ^ 0x1ff) + 1);
  855. ar9003_hw_nf_sanitize(ah, &nf);
  856. ath_print(common, ATH_DBG_CALIBRATE,
  857. "NF calibrated [ext] [chain 0] is %d\n", nf);
  858. nfarray[3] = nf;
  859. nf = MS(REG_READ(ah, AR_PHY_EXT_CCA_1), AR_PHY_CH1_EXT_MINCCA_PWR);
  860. if (nf & 0x100)
  861. nf = 0 - ((nf ^ 0x1ff) + 1);
  862. ar9003_hw_nf_sanitize(ah, &nf);
  863. ath_print(common, ATH_DBG_CALIBRATE,
  864. "NF calibrated [ext] [chain 1] is %d\n", nf);
  865. nfarray[4] = nf;
  866. nf = MS(REG_READ(ah, AR_PHY_EXT_CCA_2), AR_PHY_CH2_EXT_MINCCA_PWR);
  867. if (nf & 0x100)
  868. nf = 0 - ((nf ^ 0x1ff) + 1);
  869. ar9003_hw_nf_sanitize(ah, &nf);
  870. ath_print(common, ATH_DBG_CALIBRATE,
  871. "NF calibrated [ext] [chain 2] is %d\n", nf);
  872. nfarray[5] = nf;
  873. }
  874. void ar9003_hw_set_nf_limits(struct ath_hw *ah)
  875. {
  876. ah->nf_2g_max = AR_PHY_CCA_MAX_GOOD_VAL_9300_2GHZ;
  877. ah->nf_2g_min = AR_PHY_CCA_MIN_GOOD_VAL_9300_2GHZ;
  878. ah->nf_5g_max = AR_PHY_CCA_MAX_GOOD_VAL_9300_5GHZ;
  879. ah->nf_5g_min = AR_PHY_CCA_MIN_GOOD_VAL_9300_5GHZ;
  880. }
  881. /*
  882. * Find out which of the RX chains are enabled
  883. */
  884. static u32 ar9003_hw_get_rx_chainmask(struct ath_hw *ah)
  885. {
  886. u32 chain = REG_READ(ah, AR_PHY_RX_CHAINMASK);
  887. /*
  888. * The bits [2:0] indicate the rx chain mask and are to be
  889. * interpreted as follows:
  890. * 00x => Only chain 0 is enabled
  891. * 01x => Chain 1 and 0 enabled
  892. * 1xx => Chain 2,1 and 0 enabled
  893. */
  894. return chain & 0x7;
  895. }
  896. static void ar9003_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
  897. {
  898. struct ath9k_nfcal_hist *h;
  899. unsigned i, j;
  900. int32_t val;
  901. const u32 ar9300_cca_regs[6] = {
  902. AR_PHY_CCA_0,
  903. AR_PHY_CCA_1,
  904. AR_PHY_CCA_2,
  905. AR_PHY_EXT_CCA,
  906. AR_PHY_EXT_CCA_1,
  907. AR_PHY_EXT_CCA_2,
  908. };
  909. u8 chainmask, rx_chain_status;
  910. struct ath_common *common = ath9k_hw_common(ah);
  911. rx_chain_status = ar9003_hw_get_rx_chainmask(ah);
  912. chainmask = 0x3F;
  913. h = ah->nfCalHist;
  914. for (i = 0; i < NUM_NF_READINGS; i++) {
  915. if (chainmask & (1 << i)) {
  916. val = REG_READ(ah, ar9300_cca_regs[i]);
  917. val &= 0xFFFFFE00;
  918. val |= (((u32) (h[i].privNF) << 1) & 0x1ff);
  919. REG_WRITE(ah, ar9300_cca_regs[i], val);
  920. }
  921. }
  922. /*
  923. * Load software filtered NF value into baseband internal minCCApwr
  924. * variable.
  925. */
  926. REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
  927. AR_PHY_AGC_CONTROL_ENABLE_NF);
  928. REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
  929. AR_PHY_AGC_CONTROL_NO_UPDATE_NF);
  930. REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF);
  931. /*
  932. * Wait for load to complete, should be fast, a few 10s of us.
  933. * The max delay was changed from an original 250us to 10000us
  934. * since 250us often results in NF load timeout and causes deaf
  935. * condition during stress testing 12/12/2009
  936. */
  937. for (j = 0; j < 1000; j++) {
  938. if ((REG_READ(ah, AR_PHY_AGC_CONTROL) &
  939. AR_PHY_AGC_CONTROL_NF) == 0)
  940. break;
  941. udelay(10);
  942. }
  943. /*
  944. * We timed out waiting for the noisefloor to load, probably due to an
  945. * in-progress rx. Simply return here and allow the load plenty of time
  946. * to complete before the next calibration interval. We need to avoid
  947. * trying to load -50 (which happens below) while the previous load is
  948. * still in progress as this can cause rx deafness. Instead by returning
  949. * here, the baseband nf cal will just be capped by our present
  950. * noisefloor until the next calibration timer.
  951. */
  952. if (j == 1000) {
  953. ath_print(common, ATH_DBG_ANY, "Timeout while waiting for nf "
  954. "to load: AR_PHY_AGC_CONTROL=0x%x\n",
  955. REG_READ(ah, AR_PHY_AGC_CONTROL));
  956. return;
  957. }
  958. /*
  959. * Restore maxCCAPower register parameter again so that we're not capped
  960. * by the median we just loaded. This will be initial (and max) value
  961. * of next noise floor calibration the baseband does.
  962. */
  963. for (i = 0; i < NUM_NF_READINGS; i++) {
  964. if (chainmask & (1 << i)) {
  965. val = REG_READ(ah, ar9300_cca_regs[i]);
  966. val &= 0xFFFFFE00;
  967. val |= (((u32) (-50) << 1) & 0x1ff);
  968. REG_WRITE(ah, ar9300_cca_regs[i], val);
  969. }
  970. }
  971. }
  972. void ar9003_hw_attach_phy_ops(struct ath_hw *ah)
  973. {
  974. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  975. priv_ops->rf_set_freq = ar9003_hw_set_channel;
  976. priv_ops->spur_mitigate_freq = ar9003_hw_spur_mitigate;
  977. priv_ops->compute_pll_control = ar9003_hw_compute_pll_control;
  978. priv_ops->set_channel_regs = ar9003_hw_set_channel_regs;
  979. priv_ops->init_bb = ar9003_hw_init_bb;
  980. priv_ops->process_ini = ar9003_hw_process_ini;
  981. priv_ops->set_rfmode = ar9003_hw_set_rfmode;
  982. priv_ops->mark_phy_inactive = ar9003_hw_mark_phy_inactive;
  983. priv_ops->set_delta_slope = ar9003_hw_set_delta_slope;
  984. priv_ops->rfbus_req = ar9003_hw_rfbus_req;
  985. priv_ops->rfbus_done = ar9003_hw_rfbus_done;
  986. priv_ops->enable_rfkill = ar9003_hw_enable_rfkill;
  987. priv_ops->set_diversity = ar9003_hw_set_diversity;
  988. priv_ops->ani_control = ar9003_hw_ani_control;
  989. priv_ops->do_getnf = ar9003_hw_do_getnf;
  990. priv_ops->loadnf = ar9003_hw_loadnf;
  991. }