ar9003_phy.c 39 KB

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