ar9003_phy.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778
  1. /*
  2. * Copyright (c) 2010-2011 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/export.h>
  17. #include "hw.h"
  18. #include "ar9003_phy.h"
  19. static const int firstep_table[] =
  20. /* level: 0 1 2 3 4 5 6 7 8 */
  21. { -4, -2, 0, 2, 4, 6, 8, 10, 12 }; /* lvl 0-8, default 2 */
  22. static const int cycpwrThr1_table[] =
  23. /* level: 0 1 2 3 4 5 6 7 8 */
  24. { -6, -4, -2, 0, 2, 4, 6, 8 }; /* lvl 0-7, default 3 */
  25. /*
  26. * register values to turn OFDM weak signal detection OFF
  27. */
  28. static const int m1ThreshLow_off = 127;
  29. static const int m2ThreshLow_off = 127;
  30. static const int m1Thresh_off = 127;
  31. static const int m2Thresh_off = 127;
  32. static const int m2CountThr_off = 31;
  33. static const int m2CountThrLow_off = 63;
  34. static const int m1ThreshLowExt_off = 127;
  35. static const int m2ThreshLowExt_off = 127;
  36. static const int m1ThreshExt_off = 127;
  37. static const int m2ThreshExt_off = 127;
  38. /**
  39. * ar9003_hw_set_channel - set channel on single-chip device
  40. * @ah: atheros hardware structure
  41. * @chan:
  42. *
  43. * This is the function to change channel on single-chip devices, that is
  44. * for AR9300 family of chipsets.
  45. *
  46. * This function takes the channel value in MHz and sets
  47. * hardware channel value. Assumes writes have been enabled to analog bus.
  48. *
  49. * Actual Expression,
  50. *
  51. * For 2GHz channel,
  52. * Channel Frequency = (3/4) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
  53. * (freq_ref = 40MHz)
  54. *
  55. * For 5GHz channel,
  56. * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^10)
  57. * (freq_ref = 40MHz/(24>>amodeRefSel))
  58. *
  59. * For 5GHz channels which are 5MHz spaced,
  60. * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
  61. * (freq_ref = 40MHz)
  62. */
  63. static int ar9003_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
  64. {
  65. u16 bMode, fracMode = 0, aModeRefSel = 0;
  66. u32 freq, chan_frac, div, channelSel = 0, reg32 = 0;
  67. struct chan_centers centers;
  68. int loadSynthChannel;
  69. ath9k_hw_get_channel_centers(ah, chan, &centers);
  70. freq = centers.synth_center;
  71. if (freq < 4800) { /* 2 GHz, fractional mode */
  72. if (AR_SREV_9330(ah)) {
  73. if (ah->is_clk_25mhz)
  74. div = 75;
  75. else
  76. div = 120;
  77. channelSel = (freq * 4) / div;
  78. chan_frac = (((freq * 4) % div) * 0x20000) / div;
  79. channelSel = (channelSel << 17) | chan_frac;
  80. } else if (AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
  81. /*
  82. * freq_ref = 40 / (refdiva >> amoderefsel);
  83. * where refdiva=1 and amoderefsel=0
  84. * ndiv = ((chan_mhz * 4) / 3) / freq_ref;
  85. * chansel = int(ndiv), chanfrac = (ndiv - chansel) * 0x20000
  86. */
  87. channelSel = (freq * 4) / 120;
  88. chan_frac = (((freq * 4) % 120) * 0x20000) / 120;
  89. channelSel = (channelSel << 17) | chan_frac;
  90. } else if (AR_SREV_9340(ah)) {
  91. if (ah->is_clk_25mhz) {
  92. channelSel = (freq * 2) / 75;
  93. chan_frac = (((freq * 2) % 75) * 0x20000) / 75;
  94. channelSel = (channelSel << 17) | chan_frac;
  95. } else {
  96. channelSel = CHANSEL_2G(freq) >> 1;
  97. }
  98. } else if (AR_SREV_9550(ah)) {
  99. if (ah->is_clk_25mhz)
  100. div = 75;
  101. else
  102. div = 120;
  103. channelSel = (freq * 4) / div;
  104. chan_frac = (((freq * 4) % div) * 0x20000) / div;
  105. channelSel = (channelSel << 17) | chan_frac;
  106. } else {
  107. channelSel = CHANSEL_2G(freq);
  108. }
  109. /* Set to 2G mode */
  110. bMode = 1;
  111. } else {
  112. if ((AR_SREV_9340(ah) || AR_SREV_9550(ah)) &&
  113. ah->is_clk_25mhz) {
  114. channelSel = freq / 75;
  115. chan_frac = ((freq % 75) * 0x20000) / 75;
  116. channelSel = (channelSel << 17) | chan_frac;
  117. } else {
  118. channelSel = CHANSEL_5G(freq);
  119. /* Doubler is ON, so, divide channelSel by 2. */
  120. channelSel >>= 1;
  121. }
  122. /* Set to 5G mode */
  123. bMode = 0;
  124. }
  125. /* Enable fractional mode for all channels */
  126. fracMode = 1;
  127. aModeRefSel = 0;
  128. loadSynthChannel = 0;
  129. reg32 = (bMode << 29);
  130. REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
  131. /* Enable Long shift Select for Synthesizer */
  132. REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_SYNTH4,
  133. AR_PHY_SYNTH4_LONG_SHIFT_SELECT, 1);
  134. /* Program Synth. setting */
  135. reg32 = (channelSel << 2) | (fracMode << 30) |
  136. (aModeRefSel << 28) | (loadSynthChannel << 31);
  137. REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
  138. /* Toggle Load Synth channel bit */
  139. loadSynthChannel = 1;
  140. reg32 = (channelSel << 2) | (fracMode << 30) |
  141. (aModeRefSel << 28) | (loadSynthChannel << 31);
  142. REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
  143. ah->curchan = chan;
  144. return 0;
  145. }
  146. /**
  147. * ar9003_hw_spur_mitigate_mrc_cck - convert baseband spur frequency
  148. * @ah: atheros hardware structure
  149. * @chan:
  150. *
  151. * For single-chip solutions. Converts to baseband spur frequency given the
  152. * input channel frequency and compute register settings below.
  153. *
  154. * Spur mitigation for MRC CCK
  155. */
  156. static void ar9003_hw_spur_mitigate_mrc_cck(struct ath_hw *ah,
  157. struct ath9k_channel *chan)
  158. {
  159. static const u32 spur_freq[4] = { 2420, 2440, 2464, 2480 };
  160. int cur_bb_spur, negative = 0, cck_spur_freq;
  161. int i;
  162. int range, max_spur_cnts, synth_freq;
  163. u8 *spur_fbin_ptr = ar9003_get_spur_chan_ptr(ah, IS_CHAN_2GHZ(chan));
  164. /*
  165. * Need to verify range +/- 10 MHz in control channel, otherwise spur
  166. * is out-of-band and can be ignored.
  167. */
  168. if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah) ||
  169. AR_SREV_9550(ah)) {
  170. if (spur_fbin_ptr[0] == 0) /* No spur */
  171. return;
  172. max_spur_cnts = 5;
  173. if (IS_CHAN_HT40(chan)) {
  174. range = 19;
  175. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  176. AR_PHY_GC_DYN2040_PRI_CH) == 0)
  177. synth_freq = chan->channel + 10;
  178. else
  179. synth_freq = chan->channel - 10;
  180. } else {
  181. range = 10;
  182. synth_freq = chan->channel;
  183. }
  184. } else {
  185. range = AR_SREV_9462(ah) ? 5 : 10;
  186. max_spur_cnts = 4;
  187. synth_freq = chan->channel;
  188. }
  189. for (i = 0; i < max_spur_cnts; i++) {
  190. if (AR_SREV_9462(ah) && (i == 0 || i == 3))
  191. continue;
  192. negative = 0;
  193. if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah) ||
  194. AR_SREV_9550(ah))
  195. cur_bb_spur = ath9k_hw_fbin2freq(spur_fbin_ptr[i],
  196. IS_CHAN_2GHZ(chan));
  197. else
  198. cur_bb_spur = spur_freq[i];
  199. cur_bb_spur -= synth_freq;
  200. if (cur_bb_spur < 0) {
  201. negative = 1;
  202. cur_bb_spur = -cur_bb_spur;
  203. }
  204. if (cur_bb_spur < range) {
  205. cck_spur_freq = (int)((cur_bb_spur << 19) / 11);
  206. if (negative == 1)
  207. cck_spur_freq = -cck_spur_freq;
  208. cck_spur_freq = cck_spur_freq & 0xfffff;
  209. REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
  210. AR_PHY_AGC_CONTROL_YCOK_MAX, 0x7);
  211. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  212. AR_PHY_CCK_SPUR_MIT_SPUR_RSSI_THR, 0x7f);
  213. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  214. AR_PHY_CCK_SPUR_MIT_SPUR_FILTER_TYPE,
  215. 0x2);
  216. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  217. AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT,
  218. 0x1);
  219. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  220. AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ,
  221. cck_spur_freq);
  222. return;
  223. }
  224. }
  225. REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
  226. AR_PHY_AGC_CONTROL_YCOK_MAX, 0x5);
  227. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  228. AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT, 0x0);
  229. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  230. AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ, 0x0);
  231. }
  232. /* Clean all spur register fields */
  233. static void ar9003_hw_spur_ofdm_clear(struct ath_hw *ah)
  234. {
  235. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  236. AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0);
  237. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  238. AR_PHY_TIMING11_SPUR_FREQ_SD, 0);
  239. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  240. AR_PHY_TIMING11_SPUR_DELTA_PHASE, 0);
  241. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  242. AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, 0);
  243. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  244. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0);
  245. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  246. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0);
  247. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  248. AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0);
  249. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  250. AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 0);
  251. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  252. AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 0);
  253. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  254. AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0);
  255. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  256. AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0);
  257. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  258. AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0);
  259. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  260. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, 0);
  261. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  262. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, 0);
  263. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  264. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, 0);
  265. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  266. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0);
  267. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  268. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0);
  269. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  270. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0);
  271. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  272. AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0);
  273. }
  274. static void ar9003_hw_spur_ofdm(struct ath_hw *ah,
  275. int freq_offset,
  276. int spur_freq_sd,
  277. int spur_delta_phase,
  278. int spur_subchannel_sd,
  279. int range,
  280. int synth_freq)
  281. {
  282. int mask_index = 0;
  283. /* OFDM Spur mitigation */
  284. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  285. AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0x1);
  286. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  287. AR_PHY_TIMING11_SPUR_FREQ_SD, spur_freq_sd);
  288. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  289. AR_PHY_TIMING11_SPUR_DELTA_PHASE, spur_delta_phase);
  290. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  291. AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, spur_subchannel_sd);
  292. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  293. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0x1);
  294. if (!(AR_SREV_9565(ah) && range == 10 && synth_freq == 2437))
  295. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  296. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0x1);
  297. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  298. AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0x1);
  299. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  300. AR_PHY_SPUR_REG_SPUR_RSSI_THRESH, 34);
  301. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  302. AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 1);
  303. if (!AR_SREV_9340(ah) &&
  304. REG_READ_FIELD(ah, AR_PHY_MODE,
  305. AR_PHY_MODE_DYNAMIC) == 0x1)
  306. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  307. AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 1);
  308. mask_index = (freq_offset << 4) / 5;
  309. if (mask_index < 0)
  310. mask_index = mask_index - 1;
  311. mask_index = mask_index & 0x7f;
  312. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  313. AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0x1);
  314. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  315. AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0x1);
  316. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  317. AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0x1);
  318. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  319. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, mask_index);
  320. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  321. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, mask_index);
  322. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  323. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, mask_index);
  324. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  325. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0xc);
  326. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  327. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0xc);
  328. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  329. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0xa0);
  330. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  331. AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0xff);
  332. }
  333. static void ar9003_hw_spur_ofdm_9565(struct ath_hw *ah,
  334. int freq_offset)
  335. {
  336. int mask_index = 0;
  337. mask_index = (freq_offset << 4) / 5;
  338. if (mask_index < 0)
  339. mask_index = mask_index - 1;
  340. mask_index = mask_index & 0x7f;
  341. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  342. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_B,
  343. mask_index);
  344. /* A == B */
  345. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_B,
  346. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A,
  347. mask_index);
  348. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  349. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_B,
  350. mask_index);
  351. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  352. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_B, 0xe);
  353. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  354. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_B, 0xe);
  355. /* A == B */
  356. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_B,
  357. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0xa0);
  358. }
  359. static void ar9003_hw_spur_ofdm_work(struct ath_hw *ah,
  360. struct ath9k_channel *chan,
  361. int freq_offset,
  362. int range,
  363. int synth_freq)
  364. {
  365. int spur_freq_sd = 0;
  366. int spur_subchannel_sd = 0;
  367. int spur_delta_phase = 0;
  368. if (IS_CHAN_HT40(chan)) {
  369. if (freq_offset < 0) {
  370. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  371. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  372. spur_subchannel_sd = 1;
  373. else
  374. spur_subchannel_sd = 0;
  375. spur_freq_sd = ((freq_offset + 10) << 9) / 11;
  376. } else {
  377. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  378. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  379. spur_subchannel_sd = 0;
  380. else
  381. spur_subchannel_sd = 1;
  382. spur_freq_sd = ((freq_offset - 10) << 9) / 11;
  383. }
  384. spur_delta_phase = (freq_offset << 17) / 5;
  385. } else {
  386. spur_subchannel_sd = 0;
  387. spur_freq_sd = (freq_offset << 9) /11;
  388. spur_delta_phase = (freq_offset << 18) / 5;
  389. }
  390. spur_freq_sd = spur_freq_sd & 0x3ff;
  391. spur_delta_phase = spur_delta_phase & 0xfffff;
  392. ar9003_hw_spur_ofdm(ah,
  393. freq_offset,
  394. spur_freq_sd,
  395. spur_delta_phase,
  396. spur_subchannel_sd,
  397. range, synth_freq);
  398. }
  399. /* Spur mitigation for OFDM */
  400. static void ar9003_hw_spur_mitigate_ofdm(struct ath_hw *ah,
  401. struct ath9k_channel *chan)
  402. {
  403. int synth_freq;
  404. int range = 10;
  405. int freq_offset = 0;
  406. int mode;
  407. u8* spurChansPtr;
  408. unsigned int i;
  409. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  410. if (IS_CHAN_5GHZ(chan)) {
  411. spurChansPtr = &(eep->modalHeader5G.spurChans[0]);
  412. mode = 0;
  413. }
  414. else {
  415. spurChansPtr = &(eep->modalHeader2G.spurChans[0]);
  416. mode = 1;
  417. }
  418. if (spurChansPtr[0] == 0)
  419. return; /* No spur in the mode */
  420. if (IS_CHAN_HT40(chan)) {
  421. range = 19;
  422. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  423. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  424. synth_freq = chan->channel - 10;
  425. else
  426. synth_freq = chan->channel + 10;
  427. } else {
  428. range = 10;
  429. synth_freq = chan->channel;
  430. }
  431. ar9003_hw_spur_ofdm_clear(ah);
  432. for (i = 0; i < AR_EEPROM_MODAL_SPURS && spurChansPtr[i]; i++) {
  433. freq_offset = ath9k_hw_fbin2freq(spurChansPtr[i], mode);
  434. freq_offset -= synth_freq;
  435. if (abs(freq_offset) < range) {
  436. ar9003_hw_spur_ofdm_work(ah, chan, freq_offset,
  437. range, synth_freq);
  438. if (AR_SREV_9565(ah) && (i < 4)) {
  439. freq_offset = ath9k_hw_fbin2freq(spurChansPtr[i + 1],
  440. mode);
  441. freq_offset -= synth_freq;
  442. if (abs(freq_offset) < range)
  443. ar9003_hw_spur_ofdm_9565(ah, freq_offset);
  444. }
  445. break;
  446. }
  447. }
  448. }
  449. static void ar9003_hw_spur_mitigate(struct ath_hw *ah,
  450. struct ath9k_channel *chan)
  451. {
  452. if (!AR_SREV_9565(ah))
  453. ar9003_hw_spur_mitigate_mrc_cck(ah, chan);
  454. ar9003_hw_spur_mitigate_ofdm(ah, chan);
  455. }
  456. static u32 ar9003_hw_compute_pll_control(struct ath_hw *ah,
  457. struct ath9k_channel *chan)
  458. {
  459. u32 pll;
  460. pll = SM(0x5, AR_RTC_9300_PLL_REFDIV);
  461. if (chan && IS_CHAN_HALF_RATE(chan))
  462. pll |= SM(0x1, AR_RTC_9300_PLL_CLKSEL);
  463. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  464. pll |= SM(0x2, AR_RTC_9300_PLL_CLKSEL);
  465. pll |= SM(0x2c, AR_RTC_9300_PLL_DIV);
  466. return pll;
  467. }
  468. static void ar9003_hw_set_channel_regs(struct ath_hw *ah,
  469. struct ath9k_channel *chan)
  470. {
  471. u32 phymode;
  472. u32 enableDacFifo = 0;
  473. enableDacFifo =
  474. (REG_READ(ah, AR_PHY_GEN_CTRL) & AR_PHY_GC_ENABLE_DAC_FIFO);
  475. /* Enable 11n HT, 20 MHz */
  476. phymode = AR_PHY_GC_HT_EN | AR_PHY_GC_SINGLE_HT_LTF1 |
  477. AR_PHY_GC_SHORT_GI_40 | enableDacFifo;
  478. /* Configure baseband for dynamic 20/40 operation */
  479. if (IS_CHAN_HT40(chan)) {
  480. phymode |= AR_PHY_GC_DYN2040_EN;
  481. /* Configure control (primary) channel at +-10MHz */
  482. if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
  483. (chan->chanmode == CHANNEL_G_HT40PLUS))
  484. phymode |= AR_PHY_GC_DYN2040_PRI_CH;
  485. }
  486. /* make sure we preserve INI settings */
  487. phymode |= REG_READ(ah, AR_PHY_GEN_CTRL);
  488. /* turn off Green Field detection for STA for now */
  489. phymode &= ~AR_PHY_GC_GF_DETECT_EN;
  490. REG_WRITE(ah, AR_PHY_GEN_CTRL, phymode);
  491. /* Configure MAC for 20/40 operation */
  492. ath9k_hw_set11nmac2040(ah);
  493. /* global transmit timeout (25 TUs default)*/
  494. REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
  495. /* carrier sense timeout */
  496. REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
  497. }
  498. static void ar9003_hw_init_bb(struct ath_hw *ah,
  499. struct ath9k_channel *chan)
  500. {
  501. u32 synthDelay;
  502. /*
  503. * Wait for the frequency synth to settle (synth goes on
  504. * via AR_PHY_ACTIVE_EN). Read the phy active delay register.
  505. * Value is in 100ns increments.
  506. */
  507. synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  508. /* Activate the PHY (includes baseband activate + synthesizer on) */
  509. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
  510. ath9k_hw_synth_delay(ah, chan, synthDelay);
  511. }
  512. void ar9003_hw_set_chain_masks(struct ath_hw *ah, u8 rx, u8 tx)
  513. {
  514. if (ah->caps.tx_chainmask == 5 || ah->caps.rx_chainmask == 5)
  515. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  516. AR_PHY_SWAP_ALT_CHAIN);
  517. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx);
  518. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx);
  519. if ((ah->caps.hw_caps & ATH9K_HW_CAP_APM) && (tx == 0x7))
  520. tx = 3;
  521. REG_WRITE(ah, AR_SELFGEN_MASK, tx);
  522. }
  523. /*
  524. * Override INI values with chip specific configuration.
  525. */
  526. static void ar9003_hw_override_ini(struct ath_hw *ah)
  527. {
  528. u32 val;
  529. /*
  530. * Set the RX_ABORT and RX_DIS and clear it only after
  531. * RXE is set for MAC. This prevents frames with
  532. * corrupted descriptor status.
  533. */
  534. REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  535. /*
  536. * For AR9280 and above, there is a new feature that allows
  537. * Multicast search based on both MAC Address and Key ID. By default,
  538. * this feature is enabled. But since the driver is not using this
  539. * feature, we switch it off; otherwise multicast search based on
  540. * MAC addr only will fail.
  541. */
  542. val = REG_READ(ah, AR_PCU_MISC_MODE2) & (~AR_ADHOC_MCAST_KEYID_ENABLE);
  543. REG_WRITE(ah, AR_PCU_MISC_MODE2,
  544. val | AR_AGG_WEP_ENABLE_FIX | AR_AGG_WEP_ENABLE);
  545. REG_SET_BIT(ah, AR_PHY_CCK_DETECT,
  546. AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
  547. }
  548. static void ar9003_hw_prog_ini(struct ath_hw *ah,
  549. struct ar5416IniArray *iniArr,
  550. int column)
  551. {
  552. unsigned int i, regWrites = 0;
  553. /* New INI format: Array may be undefined (pre, core, post arrays) */
  554. if (!iniArr->ia_array)
  555. return;
  556. /*
  557. * New INI format: Pre, core, and post arrays for a given subsystem
  558. * may be modal (> 2 columns) or non-modal (2 columns). Determine if
  559. * the array is non-modal and force the column to 1.
  560. */
  561. if (column >= iniArr->ia_columns)
  562. column = 1;
  563. for (i = 0; i < iniArr->ia_rows; i++) {
  564. u32 reg = INI_RA(iniArr, i, 0);
  565. u32 val = INI_RA(iniArr, i, column);
  566. REG_WRITE(ah, reg, val);
  567. DO_DELAY(regWrites);
  568. }
  569. }
  570. static int ar9550_hw_get_modes_txgain_index(struct ath_hw *ah,
  571. struct ath9k_channel *chan)
  572. {
  573. int ret;
  574. switch (chan->chanmode) {
  575. case CHANNEL_A:
  576. case CHANNEL_A_HT20:
  577. if (chan->channel <= 5350)
  578. ret = 1;
  579. else if ((chan->channel > 5350) && (chan->channel <= 5600))
  580. ret = 3;
  581. else
  582. ret = 5;
  583. break;
  584. case CHANNEL_A_HT40PLUS:
  585. case CHANNEL_A_HT40MINUS:
  586. if (chan->channel <= 5350)
  587. ret = 2;
  588. else if ((chan->channel > 5350) && (chan->channel <= 5600))
  589. ret = 4;
  590. else
  591. ret = 6;
  592. break;
  593. case CHANNEL_G:
  594. case CHANNEL_G_HT20:
  595. case CHANNEL_B:
  596. ret = 8;
  597. break;
  598. case CHANNEL_G_HT40PLUS:
  599. case CHANNEL_G_HT40MINUS:
  600. ret = 7;
  601. break;
  602. default:
  603. ret = -EINVAL;
  604. }
  605. return ret;
  606. }
  607. static int ar9003_hw_process_ini(struct ath_hw *ah,
  608. struct ath9k_channel *chan)
  609. {
  610. unsigned int regWrites = 0, i;
  611. u32 modesIndex;
  612. switch (chan->chanmode) {
  613. case CHANNEL_A:
  614. case CHANNEL_A_HT20:
  615. modesIndex = 1;
  616. break;
  617. case CHANNEL_A_HT40PLUS:
  618. case CHANNEL_A_HT40MINUS:
  619. modesIndex = 2;
  620. break;
  621. case CHANNEL_G:
  622. case CHANNEL_G_HT20:
  623. case CHANNEL_B:
  624. modesIndex = 4;
  625. break;
  626. case CHANNEL_G_HT40PLUS:
  627. case CHANNEL_G_HT40MINUS:
  628. modesIndex = 3;
  629. break;
  630. default:
  631. return -EINVAL;
  632. }
  633. /*
  634. * SOC, MAC, BB, RADIO initvals.
  635. */
  636. for (i = 0; i < ATH_INI_NUM_SPLIT; i++) {
  637. ar9003_hw_prog_ini(ah, &ah->iniSOC[i], modesIndex);
  638. ar9003_hw_prog_ini(ah, &ah->iniMac[i], modesIndex);
  639. ar9003_hw_prog_ini(ah, &ah->iniBB[i], modesIndex);
  640. ar9003_hw_prog_ini(ah, &ah->iniRadio[i], modesIndex);
  641. if (i == ATH_INI_POST && AR_SREV_9462_20_OR_LATER(ah))
  642. ar9003_hw_prog_ini(ah,
  643. &ah->ini_radio_post_sys2ant,
  644. modesIndex);
  645. }
  646. /*
  647. * RXGAIN initvals.
  648. */
  649. REG_WRITE_ARRAY(&ah->iniModesRxGain, 1, regWrites);
  650. if (AR_SREV_9462_20_OR_LATER(ah)) {
  651. /*
  652. * CUS217 mix LNA mode.
  653. */
  654. if (ar9003_hw_get_rx_gain_idx(ah) == 2) {
  655. REG_WRITE_ARRAY(&ah->ini_modes_rxgain_bb_core,
  656. 1, regWrites);
  657. REG_WRITE_ARRAY(&ah->ini_modes_rxgain_bb_postamble,
  658. modesIndex, regWrites);
  659. }
  660. /*
  661. * 5G-XLNA
  662. */
  663. if ((ar9003_hw_get_rx_gain_idx(ah) == 2) ||
  664. (ar9003_hw_get_rx_gain_idx(ah) == 3)) {
  665. REG_WRITE_ARRAY(&ah->ini_modes_rxgain_5g_xlna,
  666. modesIndex, regWrites);
  667. }
  668. }
  669. if (AR_SREV_9550(ah))
  670. REG_WRITE_ARRAY(&ah->ini_modes_rx_gain_bounds, modesIndex,
  671. regWrites);
  672. /*
  673. * TXGAIN initvals.
  674. */
  675. if (AR_SREV_9550(ah)) {
  676. int modes_txgain_index;
  677. modes_txgain_index = ar9550_hw_get_modes_txgain_index(ah, chan);
  678. if (modes_txgain_index < 0)
  679. return -EINVAL;
  680. REG_WRITE_ARRAY(&ah->iniModesTxGain, modes_txgain_index,
  681. regWrites);
  682. } else {
  683. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  684. }
  685. /*
  686. * For 5GHz channels requiring Fast Clock, apply
  687. * different modal values.
  688. */
  689. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  690. REG_WRITE_ARRAY(&ah->iniModesFastClock,
  691. modesIndex, regWrites);
  692. /*
  693. * Clock frequency initvals.
  694. */
  695. REG_WRITE_ARRAY(&ah->iniAdditional, 1, regWrites);
  696. /*
  697. * JAPAN regulatory.
  698. */
  699. if (chan->channel == 2484)
  700. ar9003_hw_prog_ini(ah, &ah->iniCckfirJapan2484, 1);
  701. if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
  702. REG_WRITE(ah, AR_GLB_SWREG_DISCONT_MODE,
  703. AR_GLB_SWREG_DISCONT_EN_BT_WLAN);
  704. ah->modes_index = modesIndex;
  705. ar9003_hw_override_ini(ah);
  706. ar9003_hw_set_channel_regs(ah, chan);
  707. ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
  708. ath9k_hw_apply_txpower(ah, chan, false);
  709. if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
  710. if (REG_READ_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_0,
  711. AR_PHY_TX_IQCAL_CONTROL_0_ENABLE_TXIQ_CAL))
  712. ah->enabled_cals |= TX_IQ_CAL;
  713. else
  714. ah->enabled_cals &= ~TX_IQ_CAL;
  715. if (REG_READ(ah, AR_PHY_CL_CAL_CTL) & AR_PHY_CL_CAL_ENABLE)
  716. ah->enabled_cals |= TX_CL_CAL;
  717. else
  718. ah->enabled_cals &= ~TX_CL_CAL;
  719. }
  720. return 0;
  721. }
  722. static void ar9003_hw_set_rfmode(struct ath_hw *ah,
  723. struct ath9k_channel *chan)
  724. {
  725. u32 rfMode = 0;
  726. if (chan == NULL)
  727. return;
  728. rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
  729. ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
  730. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  731. rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
  732. if (IS_CHAN_QUARTER_RATE(chan))
  733. rfMode |= AR_PHY_MODE_QUARTER;
  734. if (IS_CHAN_HALF_RATE(chan))
  735. rfMode |= AR_PHY_MODE_HALF;
  736. if (rfMode & (AR_PHY_MODE_QUARTER | AR_PHY_MODE_HALF))
  737. REG_RMW_FIELD(ah, AR_PHY_FRAME_CTL,
  738. AR_PHY_FRAME_CTL_CF_OVERLAP_WINDOW, 3);
  739. REG_WRITE(ah, AR_PHY_MODE, rfMode);
  740. }
  741. static void ar9003_hw_mark_phy_inactive(struct ath_hw *ah)
  742. {
  743. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
  744. }
  745. static void ar9003_hw_set_delta_slope(struct ath_hw *ah,
  746. struct ath9k_channel *chan)
  747. {
  748. u32 coef_scaled, ds_coef_exp, ds_coef_man;
  749. u32 clockMhzScaled = 0x64000000;
  750. struct chan_centers centers;
  751. /*
  752. * half and quarter rate can divide the scaled clock by 2 or 4
  753. * scale for selected channel bandwidth
  754. */
  755. if (IS_CHAN_HALF_RATE(chan))
  756. clockMhzScaled = clockMhzScaled >> 1;
  757. else if (IS_CHAN_QUARTER_RATE(chan))
  758. clockMhzScaled = clockMhzScaled >> 2;
  759. /*
  760. * ALGO -> coef = 1e8/fcarrier*fclock/40;
  761. * scaled coef to provide precision for this floating calculation
  762. */
  763. ath9k_hw_get_channel_centers(ah, chan, &centers);
  764. coef_scaled = clockMhzScaled / centers.synth_center;
  765. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  766. &ds_coef_exp);
  767. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  768. AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
  769. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  770. AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
  771. /*
  772. * For Short GI,
  773. * scaled coeff is 9/10 that of normal coeff
  774. */
  775. coef_scaled = (9 * coef_scaled) / 10;
  776. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  777. &ds_coef_exp);
  778. /* for short gi */
  779. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  780. AR_PHY_SGI_DSC_MAN, ds_coef_man);
  781. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  782. AR_PHY_SGI_DSC_EXP, ds_coef_exp);
  783. }
  784. static bool ar9003_hw_rfbus_req(struct ath_hw *ah)
  785. {
  786. REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
  787. return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
  788. AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT);
  789. }
  790. /*
  791. * Wait for the frequency synth to settle (synth goes on via PHY_ACTIVE_EN).
  792. * Read the phy active delay register. Value is in 100ns increments.
  793. */
  794. static void ar9003_hw_rfbus_done(struct ath_hw *ah)
  795. {
  796. u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  797. ath9k_hw_synth_delay(ah, ah->curchan, synthDelay);
  798. REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
  799. }
  800. static bool ar9003_hw_ani_control(struct ath_hw *ah,
  801. enum ath9k_ani_cmd cmd, int param)
  802. {
  803. struct ath_common *common = ath9k_hw_common(ah);
  804. struct ath9k_channel *chan = ah->curchan;
  805. struct ar5416AniState *aniState = &ah->ani;
  806. int m1ThreshLow, m2ThreshLow;
  807. int m1Thresh, m2Thresh;
  808. int m2CountThr, m2CountThrLow;
  809. int m1ThreshLowExt, m2ThreshLowExt;
  810. int m1ThreshExt, m2ThreshExt;
  811. s32 value, value2;
  812. switch (cmd & ah->ani_function) {
  813. case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
  814. /*
  815. * on == 1 means ofdm weak signal detection is ON
  816. * on == 1 is the default, for less noise immunity
  817. *
  818. * on == 0 means ofdm weak signal detection is OFF
  819. * on == 0 means more noise imm
  820. */
  821. u32 on = param ? 1 : 0;
  822. if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
  823. goto skip_ws_det;
  824. m1ThreshLow = on ?
  825. aniState->iniDef.m1ThreshLow : m1ThreshLow_off;
  826. m2ThreshLow = on ?
  827. aniState->iniDef.m2ThreshLow : m2ThreshLow_off;
  828. m1Thresh = on ?
  829. aniState->iniDef.m1Thresh : m1Thresh_off;
  830. m2Thresh = on ?
  831. aniState->iniDef.m2Thresh : m2Thresh_off;
  832. m2CountThr = on ?
  833. aniState->iniDef.m2CountThr : m2CountThr_off;
  834. m2CountThrLow = on ?
  835. aniState->iniDef.m2CountThrLow : m2CountThrLow_off;
  836. m1ThreshLowExt = on ?
  837. aniState->iniDef.m1ThreshLowExt : m1ThreshLowExt_off;
  838. m2ThreshLowExt = on ?
  839. aniState->iniDef.m2ThreshLowExt : m2ThreshLowExt_off;
  840. m1ThreshExt = on ?
  841. aniState->iniDef.m1ThreshExt : m1ThreshExt_off;
  842. m2ThreshExt = on ?
  843. aniState->iniDef.m2ThreshExt : m2ThreshExt_off;
  844. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  845. AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
  846. m1ThreshLow);
  847. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  848. AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
  849. m2ThreshLow);
  850. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  851. AR_PHY_SFCORR_M1_THRESH,
  852. m1Thresh);
  853. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  854. AR_PHY_SFCORR_M2_THRESH,
  855. m2Thresh);
  856. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  857. AR_PHY_SFCORR_M2COUNT_THR,
  858. m2CountThr);
  859. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  860. AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
  861. m2CountThrLow);
  862. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  863. AR_PHY_SFCORR_EXT_M1_THRESH_LOW,
  864. m1ThreshLowExt);
  865. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  866. AR_PHY_SFCORR_EXT_M2_THRESH_LOW,
  867. m2ThreshLowExt);
  868. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  869. AR_PHY_SFCORR_EXT_M1_THRESH,
  870. m1ThreshExt);
  871. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  872. AR_PHY_SFCORR_EXT_M2_THRESH,
  873. m2ThreshExt);
  874. skip_ws_det:
  875. if (on)
  876. REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
  877. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  878. else
  879. REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
  880. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  881. if (on != aniState->ofdmWeakSigDetect) {
  882. ath_dbg(common, ANI,
  883. "** ch %d: ofdm weak signal: %s=>%s\n",
  884. chan->channel,
  885. aniState->ofdmWeakSigDetect ?
  886. "on" : "off",
  887. on ? "on" : "off");
  888. if (on)
  889. ah->stats.ast_ani_ofdmon++;
  890. else
  891. ah->stats.ast_ani_ofdmoff++;
  892. aniState->ofdmWeakSigDetect = on;
  893. }
  894. break;
  895. }
  896. case ATH9K_ANI_FIRSTEP_LEVEL:{
  897. u32 level = param;
  898. if (level >= ARRAY_SIZE(firstep_table)) {
  899. ath_dbg(common, ANI,
  900. "ATH9K_ANI_FIRSTEP_LEVEL: level out of range (%u > %zu)\n",
  901. level, ARRAY_SIZE(firstep_table));
  902. return false;
  903. }
  904. /*
  905. * make register setting relative to default
  906. * from INI file & cap value
  907. */
  908. value = firstep_table[level] -
  909. firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
  910. aniState->iniDef.firstep;
  911. if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  912. value = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  913. if (value > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  914. value = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  915. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  916. AR_PHY_FIND_SIG_FIRSTEP,
  917. value);
  918. /*
  919. * we need to set first step low register too
  920. * make register setting relative to default
  921. * from INI file & cap value
  922. */
  923. value2 = firstep_table[level] -
  924. firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
  925. aniState->iniDef.firstepLow;
  926. if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  927. value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  928. if (value2 > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  929. value2 = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  930. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
  931. AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW, value2);
  932. if (level != aniState->firstepLevel) {
  933. ath_dbg(common, ANI,
  934. "** ch %d: level %d=>%d[def:%d] firstep[level]=%d ini=%d\n",
  935. chan->channel,
  936. aniState->firstepLevel,
  937. level,
  938. ATH9K_ANI_FIRSTEP_LVL,
  939. value,
  940. aniState->iniDef.firstep);
  941. ath_dbg(common, ANI,
  942. "** ch %d: level %d=>%d[def:%d] firstep_low[level]=%d ini=%d\n",
  943. chan->channel,
  944. aniState->firstepLevel,
  945. level,
  946. ATH9K_ANI_FIRSTEP_LVL,
  947. value2,
  948. aniState->iniDef.firstepLow);
  949. if (level > aniState->firstepLevel)
  950. ah->stats.ast_ani_stepup++;
  951. else if (level < aniState->firstepLevel)
  952. ah->stats.ast_ani_stepdown++;
  953. aniState->firstepLevel = level;
  954. }
  955. break;
  956. }
  957. case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
  958. u32 level = param;
  959. if (level >= ARRAY_SIZE(cycpwrThr1_table)) {
  960. ath_dbg(common, ANI,
  961. "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level out of range (%u > %zu)\n",
  962. level, ARRAY_SIZE(cycpwrThr1_table));
  963. return false;
  964. }
  965. /*
  966. * make register setting relative to default
  967. * from INI file & cap value
  968. */
  969. value = cycpwrThr1_table[level] -
  970. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
  971. aniState->iniDef.cycpwrThr1;
  972. if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  973. value = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  974. if (value > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  975. value = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  976. REG_RMW_FIELD(ah, AR_PHY_TIMING5,
  977. AR_PHY_TIMING5_CYCPWR_THR1,
  978. value);
  979. /*
  980. * set AR_PHY_EXT_CCA for extension channel
  981. * make register setting relative to default
  982. * from INI file & cap value
  983. */
  984. value2 = cycpwrThr1_table[level] -
  985. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
  986. aniState->iniDef.cycpwrThr1Ext;
  987. if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  988. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  989. if (value2 > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  990. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  991. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
  992. AR_PHY_EXT_CYCPWR_THR1, value2);
  993. if (level != aniState->spurImmunityLevel) {
  994. ath_dbg(common, ANI,
  995. "** ch %d: level %d=>%d[def:%d] cycpwrThr1[level]=%d ini=%d\n",
  996. chan->channel,
  997. aniState->spurImmunityLevel,
  998. level,
  999. ATH9K_ANI_SPUR_IMMUNE_LVL,
  1000. value,
  1001. aniState->iniDef.cycpwrThr1);
  1002. ath_dbg(common, ANI,
  1003. "** ch %d: level %d=>%d[def:%d] cycpwrThr1Ext[level]=%d ini=%d\n",
  1004. chan->channel,
  1005. aniState->spurImmunityLevel,
  1006. level,
  1007. ATH9K_ANI_SPUR_IMMUNE_LVL,
  1008. value2,
  1009. aniState->iniDef.cycpwrThr1Ext);
  1010. if (level > aniState->spurImmunityLevel)
  1011. ah->stats.ast_ani_spurup++;
  1012. else if (level < aniState->spurImmunityLevel)
  1013. ah->stats.ast_ani_spurdown++;
  1014. aniState->spurImmunityLevel = level;
  1015. }
  1016. break;
  1017. }
  1018. case ATH9K_ANI_MRC_CCK:{
  1019. /*
  1020. * is_on == 1 means MRC CCK ON (default, less noise imm)
  1021. * is_on == 0 means MRC CCK is OFF (more noise imm)
  1022. */
  1023. bool is_on = param ? 1 : 0;
  1024. REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
  1025. AR_PHY_MRC_CCK_ENABLE, is_on);
  1026. REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
  1027. AR_PHY_MRC_CCK_MUX_REG, is_on);
  1028. if (is_on != aniState->mrcCCK) {
  1029. ath_dbg(common, ANI, "** ch %d: MRC CCK: %s=>%s\n",
  1030. chan->channel,
  1031. aniState->mrcCCK ? "on" : "off",
  1032. is_on ? "on" : "off");
  1033. if (is_on)
  1034. ah->stats.ast_ani_ccklow++;
  1035. else
  1036. ah->stats.ast_ani_cckhigh++;
  1037. aniState->mrcCCK = is_on;
  1038. }
  1039. break;
  1040. }
  1041. case ATH9K_ANI_PRESENT:
  1042. break;
  1043. default:
  1044. ath_dbg(common, ANI, "invalid cmd %u\n", cmd);
  1045. return false;
  1046. }
  1047. ath_dbg(common, ANI,
  1048. "ANI parameters: SI=%d, ofdmWS=%s FS=%d MRCcck=%s listenTime=%d ofdmErrs=%d cckErrs=%d\n",
  1049. aniState->spurImmunityLevel,
  1050. aniState->ofdmWeakSigDetect ? "on" : "off",
  1051. aniState->firstepLevel,
  1052. aniState->mrcCCK ? "on" : "off",
  1053. aniState->listenTime,
  1054. aniState->ofdmPhyErrCount,
  1055. aniState->cckPhyErrCount);
  1056. return true;
  1057. }
  1058. static void ar9003_hw_do_getnf(struct ath_hw *ah,
  1059. int16_t nfarray[NUM_NF_READINGS])
  1060. {
  1061. #define AR_PHY_CH_MINCCA_PWR 0x1FF00000
  1062. #define AR_PHY_CH_MINCCA_PWR_S 20
  1063. #define AR_PHY_CH_EXT_MINCCA_PWR 0x01FF0000
  1064. #define AR_PHY_CH_EXT_MINCCA_PWR_S 16
  1065. int16_t nf;
  1066. int i;
  1067. for (i = 0; i < AR9300_MAX_CHAINS; i++) {
  1068. if (ah->rxchainmask & BIT(i)) {
  1069. nf = MS(REG_READ(ah, ah->nf_regs[i]),
  1070. AR_PHY_CH_MINCCA_PWR);
  1071. nfarray[i] = sign_extend32(nf, 8);
  1072. if (IS_CHAN_HT40(ah->curchan)) {
  1073. u8 ext_idx = AR9300_MAX_CHAINS + i;
  1074. nf = MS(REG_READ(ah, ah->nf_regs[ext_idx]),
  1075. AR_PHY_CH_EXT_MINCCA_PWR);
  1076. nfarray[ext_idx] = sign_extend32(nf, 8);
  1077. }
  1078. }
  1079. }
  1080. }
  1081. static void ar9003_hw_set_nf_limits(struct ath_hw *ah)
  1082. {
  1083. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_2GHZ;
  1084. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_2GHZ;
  1085. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9300_2GHZ;
  1086. ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_5GHZ;
  1087. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_5GHZ;
  1088. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9300_5GHZ;
  1089. if (AR_SREV_9330(ah))
  1090. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9330_2GHZ;
  1091. if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
  1092. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9462_2GHZ;
  1093. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9462_2GHZ;
  1094. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9462_5GHZ;
  1095. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9462_5GHZ;
  1096. }
  1097. }
  1098. /*
  1099. * Initialize the ANI register values with default (ini) values.
  1100. * This routine is called during a (full) hardware reset after
  1101. * all the registers are initialised from the INI.
  1102. */
  1103. static void ar9003_hw_ani_cache_ini_regs(struct ath_hw *ah)
  1104. {
  1105. struct ar5416AniState *aniState;
  1106. struct ath_common *common = ath9k_hw_common(ah);
  1107. struct ath9k_channel *chan = ah->curchan;
  1108. struct ath9k_ani_default *iniDef;
  1109. u32 val;
  1110. aniState = &ah->ani;
  1111. iniDef = &aniState->iniDef;
  1112. ath_dbg(common, ANI, "ver %d.%d opmode %u chan %d Mhz/0x%x\n",
  1113. ah->hw_version.macVersion,
  1114. ah->hw_version.macRev,
  1115. ah->opmode,
  1116. chan->channel,
  1117. chan->channelFlags);
  1118. val = REG_READ(ah, AR_PHY_SFCORR);
  1119. iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH);
  1120. iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH);
  1121. iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR);
  1122. val = REG_READ(ah, AR_PHY_SFCORR_LOW);
  1123. iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW);
  1124. iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW);
  1125. iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW);
  1126. val = REG_READ(ah, AR_PHY_SFCORR_EXT);
  1127. iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH);
  1128. iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH);
  1129. iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW);
  1130. iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW);
  1131. iniDef->firstep = REG_READ_FIELD(ah,
  1132. AR_PHY_FIND_SIG,
  1133. AR_PHY_FIND_SIG_FIRSTEP);
  1134. iniDef->firstepLow = REG_READ_FIELD(ah,
  1135. AR_PHY_FIND_SIG_LOW,
  1136. AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW);
  1137. iniDef->cycpwrThr1 = REG_READ_FIELD(ah,
  1138. AR_PHY_TIMING5,
  1139. AR_PHY_TIMING5_CYCPWR_THR1);
  1140. iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah,
  1141. AR_PHY_EXT_CCA,
  1142. AR_PHY_EXT_CYCPWR_THR1);
  1143. /* these levels just got reset to defaults by the INI */
  1144. aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL;
  1145. aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL;
  1146. aniState->ofdmWeakSigDetect = true;
  1147. aniState->mrcCCK = true;
  1148. }
  1149. static void ar9003_hw_set_radar_params(struct ath_hw *ah,
  1150. struct ath_hw_radar_conf *conf)
  1151. {
  1152. u32 radar_0 = 0, radar_1 = 0;
  1153. if (!conf) {
  1154. REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA);
  1155. return;
  1156. }
  1157. radar_0 |= AR_PHY_RADAR_0_ENA | AR_PHY_RADAR_0_FFT_ENA;
  1158. radar_0 |= SM(conf->fir_power, AR_PHY_RADAR_0_FIRPWR);
  1159. radar_0 |= SM(conf->radar_rssi, AR_PHY_RADAR_0_RRSSI);
  1160. radar_0 |= SM(conf->pulse_height, AR_PHY_RADAR_0_HEIGHT);
  1161. radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI);
  1162. radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND);
  1163. radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI;
  1164. radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK;
  1165. radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN);
  1166. radar_1 |= SM(conf->pulse_inband_step, AR_PHY_RADAR_1_RELSTEP_THRESH);
  1167. radar_1 |= SM(conf->radar_inband, AR_PHY_RADAR_1_RELPWR_THRESH);
  1168. REG_WRITE(ah, AR_PHY_RADAR_0, radar_0);
  1169. REG_WRITE(ah, AR_PHY_RADAR_1, radar_1);
  1170. if (conf->ext_channel)
  1171. REG_SET_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1172. else
  1173. REG_CLR_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1174. }
  1175. static void ar9003_hw_set_radar_conf(struct ath_hw *ah)
  1176. {
  1177. struct ath_hw_radar_conf *conf = &ah->radar_conf;
  1178. conf->fir_power = -28;
  1179. conf->radar_rssi = 0;
  1180. conf->pulse_height = 10;
  1181. conf->pulse_rssi = 24;
  1182. conf->pulse_inband = 8;
  1183. conf->pulse_maxlen = 255;
  1184. conf->pulse_inband_step = 12;
  1185. conf->radar_inband = 8;
  1186. }
  1187. static void ar9003_hw_antdiv_comb_conf_get(struct ath_hw *ah,
  1188. struct ath_hw_antcomb_conf *antconf)
  1189. {
  1190. u32 regval;
  1191. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1192. antconf->main_lna_conf = (regval & AR_PHY_ANT_DIV_MAIN_LNACONF) >>
  1193. AR_PHY_ANT_DIV_MAIN_LNACONF_S;
  1194. antconf->alt_lna_conf = (regval & AR_PHY_ANT_DIV_ALT_LNACONF) >>
  1195. AR_PHY_ANT_DIV_ALT_LNACONF_S;
  1196. antconf->fast_div_bias = (regval & AR_PHY_ANT_FAST_DIV_BIAS) >>
  1197. AR_PHY_ANT_FAST_DIV_BIAS_S;
  1198. if (AR_SREV_9330_11(ah)) {
  1199. antconf->lna1_lna2_delta = -9;
  1200. antconf->div_group = 1;
  1201. } else if (AR_SREV_9485(ah)) {
  1202. antconf->lna1_lna2_delta = -9;
  1203. antconf->div_group = 2;
  1204. } else if (AR_SREV_9565(ah)) {
  1205. antconf->lna1_lna2_delta = -3;
  1206. antconf->div_group = 3;
  1207. } else {
  1208. antconf->lna1_lna2_delta = -3;
  1209. antconf->div_group = 0;
  1210. }
  1211. }
  1212. static void ar9003_hw_antdiv_comb_conf_set(struct ath_hw *ah,
  1213. struct ath_hw_antcomb_conf *antconf)
  1214. {
  1215. u32 regval;
  1216. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1217. regval &= ~(AR_PHY_ANT_DIV_MAIN_LNACONF |
  1218. AR_PHY_ANT_DIV_ALT_LNACONF |
  1219. AR_PHY_ANT_FAST_DIV_BIAS |
  1220. AR_PHY_ANT_DIV_MAIN_GAINTB |
  1221. AR_PHY_ANT_DIV_ALT_GAINTB);
  1222. regval |= ((antconf->main_lna_conf << AR_PHY_ANT_DIV_MAIN_LNACONF_S)
  1223. & AR_PHY_ANT_DIV_MAIN_LNACONF);
  1224. regval |= ((antconf->alt_lna_conf << AR_PHY_ANT_DIV_ALT_LNACONF_S)
  1225. & AR_PHY_ANT_DIV_ALT_LNACONF);
  1226. regval |= ((antconf->fast_div_bias << AR_PHY_ANT_FAST_DIV_BIAS_S)
  1227. & AR_PHY_ANT_FAST_DIV_BIAS);
  1228. regval |= ((antconf->main_gaintb << AR_PHY_ANT_DIV_MAIN_GAINTB_S)
  1229. & AR_PHY_ANT_DIV_MAIN_GAINTB);
  1230. regval |= ((antconf->alt_gaintb << AR_PHY_ANT_DIV_ALT_GAINTB_S)
  1231. & AR_PHY_ANT_DIV_ALT_GAINTB);
  1232. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1233. }
  1234. static void ar9003_hw_antctrl_shared_chain_lnadiv(struct ath_hw *ah,
  1235. bool enable)
  1236. {
  1237. u8 ant_div_ctl1;
  1238. u32 regval;
  1239. if (!AR_SREV_9565(ah))
  1240. return;
  1241. ah->shared_chain_lnadiv = enable;
  1242. ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
  1243. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1244. regval &= (~AR_ANT_DIV_CTRL_ALL);
  1245. regval |= (ant_div_ctl1 & 0x3f) << AR_ANT_DIV_CTRL_ALL_S;
  1246. regval &= ~AR_PHY_ANT_DIV_LNADIV;
  1247. regval |= ((ant_div_ctl1 >> 6) & 0x1) << AR_PHY_ANT_DIV_LNADIV_S;
  1248. if (enable)
  1249. regval |= AR_ANT_DIV_ENABLE;
  1250. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1251. regval = REG_READ(ah, AR_PHY_CCK_DETECT);
  1252. regval &= ~AR_FAST_DIV_ENABLE;
  1253. regval |= ((ant_div_ctl1 >> 7) & 0x1) << AR_FAST_DIV_ENABLE_S;
  1254. if (enable)
  1255. regval |= AR_FAST_DIV_ENABLE;
  1256. REG_WRITE(ah, AR_PHY_CCK_DETECT, regval);
  1257. if (enable) {
  1258. REG_SET_BIT(ah, AR_PHY_MC_GAIN_CTRL,
  1259. (1 << AR_PHY_ANT_SW_RX_PROT_S));
  1260. if (ah->curchan && IS_CHAN_2GHZ(ah->curchan))
  1261. REG_SET_BIT(ah, AR_PHY_RESTART,
  1262. AR_PHY_RESTART_ENABLE_DIV_M2FLAG);
  1263. REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV,
  1264. AR_BTCOEX_WL_LNADIV_FORCE_ON);
  1265. } else {
  1266. REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL, AR_ANT_DIV_ENABLE);
  1267. REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL,
  1268. (1 << AR_PHY_ANT_SW_RX_PROT_S));
  1269. REG_CLR_BIT(ah, AR_PHY_CCK_DETECT, AR_FAST_DIV_ENABLE);
  1270. REG_CLR_BIT(ah, AR_BTCOEX_WL_LNADIV,
  1271. AR_BTCOEX_WL_LNADIV_FORCE_ON);
  1272. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1273. regval &= ~(AR_PHY_ANT_DIV_MAIN_LNACONF |
  1274. AR_PHY_ANT_DIV_ALT_LNACONF |
  1275. AR_PHY_ANT_DIV_MAIN_GAINTB |
  1276. AR_PHY_ANT_DIV_ALT_GAINTB);
  1277. regval |= (AR_PHY_ANT_DIV_LNA1 << AR_PHY_ANT_DIV_MAIN_LNACONF_S);
  1278. regval |= (AR_PHY_ANT_DIV_LNA2 << AR_PHY_ANT_DIV_ALT_LNACONF_S);
  1279. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1280. }
  1281. }
  1282. static int ar9003_hw_fast_chan_change(struct ath_hw *ah,
  1283. struct ath9k_channel *chan,
  1284. u8 *ini_reloaded)
  1285. {
  1286. unsigned int regWrites = 0;
  1287. u32 modesIndex;
  1288. switch (chan->chanmode) {
  1289. case CHANNEL_A:
  1290. case CHANNEL_A_HT20:
  1291. modesIndex = 1;
  1292. break;
  1293. case CHANNEL_A_HT40PLUS:
  1294. case CHANNEL_A_HT40MINUS:
  1295. modesIndex = 2;
  1296. break;
  1297. case CHANNEL_G:
  1298. case CHANNEL_G_HT20:
  1299. case CHANNEL_B:
  1300. modesIndex = 4;
  1301. break;
  1302. case CHANNEL_G_HT40PLUS:
  1303. case CHANNEL_G_HT40MINUS:
  1304. modesIndex = 3;
  1305. break;
  1306. default:
  1307. return -EINVAL;
  1308. }
  1309. if (modesIndex == ah->modes_index) {
  1310. *ini_reloaded = false;
  1311. goto set_rfmode;
  1312. }
  1313. ar9003_hw_prog_ini(ah, &ah->iniSOC[ATH_INI_POST], modesIndex);
  1314. ar9003_hw_prog_ini(ah, &ah->iniMac[ATH_INI_POST], modesIndex);
  1315. ar9003_hw_prog_ini(ah, &ah->iniBB[ATH_INI_POST], modesIndex);
  1316. ar9003_hw_prog_ini(ah, &ah->iniRadio[ATH_INI_POST], modesIndex);
  1317. if (AR_SREV_9462_20_OR_LATER(ah))
  1318. ar9003_hw_prog_ini(ah, &ah->ini_radio_post_sys2ant,
  1319. modesIndex);
  1320. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  1321. /*
  1322. * For 5GHz channels requiring Fast Clock, apply
  1323. * different modal values.
  1324. */
  1325. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  1326. REG_WRITE_ARRAY(&ah->iniModesFastClock, modesIndex, regWrites);
  1327. if (AR_SREV_9565(ah))
  1328. REG_WRITE_ARRAY(&ah->iniModesFastClock, 1, regWrites);
  1329. REG_WRITE_ARRAY(&ah->iniAdditional, 1, regWrites);
  1330. ah->modes_index = modesIndex;
  1331. *ini_reloaded = true;
  1332. set_rfmode:
  1333. ar9003_hw_set_rfmode(ah, chan);
  1334. return 0;
  1335. }
  1336. static void ar9003_hw_spectral_scan_config(struct ath_hw *ah,
  1337. struct ath_spec_scan *param)
  1338. {
  1339. u8 count;
  1340. if (!param->enabled) {
  1341. REG_CLR_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  1342. AR_PHY_SPECTRAL_SCAN_ENABLE);
  1343. return;
  1344. }
  1345. REG_SET_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_FFT_ENA);
  1346. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN, AR_PHY_SPECTRAL_SCAN_ENABLE);
  1347. /* on AR93xx and newer, count = 0 will make the the chip send
  1348. * spectral samples endlessly. Check if this really was intended,
  1349. * and fix otherwise.
  1350. */
  1351. count = param->count;
  1352. if (param->endless)
  1353. count = 0;
  1354. else if (param->count == 0)
  1355. count = 1;
  1356. if (param->short_repeat)
  1357. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  1358. AR_PHY_SPECTRAL_SCAN_SHORT_REPEAT);
  1359. else
  1360. REG_CLR_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  1361. AR_PHY_SPECTRAL_SCAN_SHORT_REPEAT);
  1362. REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN,
  1363. AR_PHY_SPECTRAL_SCAN_COUNT, count);
  1364. REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN,
  1365. AR_PHY_SPECTRAL_SCAN_PERIOD, param->period);
  1366. REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN,
  1367. AR_PHY_SPECTRAL_SCAN_FFT_PERIOD, param->fft_period);
  1368. return;
  1369. }
  1370. static void ar9003_hw_spectral_scan_trigger(struct ath_hw *ah)
  1371. {
  1372. /* Activate spectral scan */
  1373. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  1374. AR_PHY_SPECTRAL_SCAN_ACTIVE);
  1375. }
  1376. static void ar9003_hw_spectral_scan_wait(struct ath_hw *ah)
  1377. {
  1378. struct ath_common *common = ath9k_hw_common(ah);
  1379. /* Poll for spectral scan complete */
  1380. if (!ath9k_hw_wait(ah, AR_PHY_SPECTRAL_SCAN,
  1381. AR_PHY_SPECTRAL_SCAN_ACTIVE,
  1382. 0, AH_WAIT_TIMEOUT)) {
  1383. ath_err(common, "spectral scan wait failed\n");
  1384. return;
  1385. }
  1386. }
  1387. void ar9003_hw_attach_phy_ops(struct ath_hw *ah)
  1388. {
  1389. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  1390. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  1391. static const u32 ar9300_cca_regs[6] = {
  1392. AR_PHY_CCA_0,
  1393. AR_PHY_CCA_1,
  1394. AR_PHY_CCA_2,
  1395. AR_PHY_EXT_CCA,
  1396. AR_PHY_EXT_CCA_1,
  1397. AR_PHY_EXT_CCA_2,
  1398. };
  1399. priv_ops->rf_set_freq = ar9003_hw_set_channel;
  1400. priv_ops->spur_mitigate_freq = ar9003_hw_spur_mitigate;
  1401. priv_ops->compute_pll_control = ar9003_hw_compute_pll_control;
  1402. priv_ops->set_channel_regs = ar9003_hw_set_channel_regs;
  1403. priv_ops->init_bb = ar9003_hw_init_bb;
  1404. priv_ops->process_ini = ar9003_hw_process_ini;
  1405. priv_ops->set_rfmode = ar9003_hw_set_rfmode;
  1406. priv_ops->mark_phy_inactive = ar9003_hw_mark_phy_inactive;
  1407. priv_ops->set_delta_slope = ar9003_hw_set_delta_slope;
  1408. priv_ops->rfbus_req = ar9003_hw_rfbus_req;
  1409. priv_ops->rfbus_done = ar9003_hw_rfbus_done;
  1410. priv_ops->ani_control = ar9003_hw_ani_control;
  1411. priv_ops->do_getnf = ar9003_hw_do_getnf;
  1412. priv_ops->ani_cache_ini_regs = ar9003_hw_ani_cache_ini_regs;
  1413. priv_ops->set_radar_params = ar9003_hw_set_radar_params;
  1414. priv_ops->fast_chan_change = ar9003_hw_fast_chan_change;
  1415. ops->antdiv_comb_conf_get = ar9003_hw_antdiv_comb_conf_get;
  1416. ops->antdiv_comb_conf_set = ar9003_hw_antdiv_comb_conf_set;
  1417. ops->antctrl_shared_chain_lnadiv = ar9003_hw_antctrl_shared_chain_lnadiv;
  1418. ops->spectral_scan_config = ar9003_hw_spectral_scan_config;
  1419. ops->spectral_scan_trigger = ar9003_hw_spectral_scan_trigger;
  1420. ops->spectral_scan_wait = ar9003_hw_spectral_scan_wait;
  1421. ar9003_hw_set_nf_limits(ah);
  1422. ar9003_hw_set_radar_conf(ah);
  1423. memcpy(ah->nf_regs, ar9300_cca_regs, sizeof(ah->nf_regs));
  1424. }
  1425. void ar9003_hw_bb_watchdog_config(struct ath_hw *ah)
  1426. {
  1427. struct ath_common *common = ath9k_hw_common(ah);
  1428. u32 idle_tmo_ms = ah->bb_watchdog_timeout_ms;
  1429. u32 val, idle_count;
  1430. if (!idle_tmo_ms) {
  1431. /* disable IRQ, disable chip-reset for BB panic */
  1432. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
  1433. REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) &
  1434. ~(AR_PHY_WATCHDOG_RST_ENABLE |
  1435. AR_PHY_WATCHDOG_IRQ_ENABLE));
  1436. /* disable watchdog in non-IDLE mode, disable in IDLE mode */
  1437. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
  1438. REG_READ(ah, AR_PHY_WATCHDOG_CTL_1) &
  1439. ~(AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
  1440. AR_PHY_WATCHDOG_IDLE_ENABLE));
  1441. ath_dbg(common, RESET, "Disabled BB Watchdog\n");
  1442. return;
  1443. }
  1444. /* enable IRQ, disable chip-reset for BB watchdog */
  1445. val = REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) & AR_PHY_WATCHDOG_CNTL2_MASK;
  1446. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
  1447. (val | AR_PHY_WATCHDOG_IRQ_ENABLE) &
  1448. ~AR_PHY_WATCHDOG_RST_ENABLE);
  1449. /* bound limit to 10 secs */
  1450. if (idle_tmo_ms > 10000)
  1451. idle_tmo_ms = 10000;
  1452. /*
  1453. * The time unit for watchdog event is 2^15 44/88MHz cycles.
  1454. *
  1455. * For HT20 we have a time unit of 2^15/44 MHz = .74 ms per tick
  1456. * For HT40 we have a time unit of 2^15/88 MHz = .37 ms per tick
  1457. *
  1458. * Given we use fast clock now in 5 GHz, these time units should
  1459. * be common for both 2 GHz and 5 GHz.
  1460. */
  1461. idle_count = (100 * idle_tmo_ms) / 74;
  1462. if (ah->curchan && IS_CHAN_HT40(ah->curchan))
  1463. idle_count = (100 * idle_tmo_ms) / 37;
  1464. /*
  1465. * enable watchdog in non-IDLE mode, disable in IDLE mode,
  1466. * set idle time-out.
  1467. */
  1468. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
  1469. AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
  1470. AR_PHY_WATCHDOG_IDLE_MASK |
  1471. (AR_PHY_WATCHDOG_NON_IDLE_MASK & (idle_count << 2)));
  1472. ath_dbg(common, RESET, "Enabled BB Watchdog timeout (%u ms)\n",
  1473. idle_tmo_ms);
  1474. }
  1475. void ar9003_hw_bb_watchdog_read(struct ath_hw *ah)
  1476. {
  1477. /*
  1478. * we want to avoid printing in ISR context so we save the
  1479. * watchdog status to be printed later in bottom half context.
  1480. */
  1481. ah->bb_watchdog_last_status = REG_READ(ah, AR_PHY_WATCHDOG_STATUS);
  1482. /*
  1483. * the watchdog timer should reset on status read but to be sure
  1484. * sure we write 0 to the watchdog status bit.
  1485. */
  1486. REG_WRITE(ah, AR_PHY_WATCHDOG_STATUS,
  1487. ah->bb_watchdog_last_status & ~AR_PHY_WATCHDOG_STATUS_CLR);
  1488. }
  1489. void ar9003_hw_bb_watchdog_dbg_info(struct ath_hw *ah)
  1490. {
  1491. struct ath_common *common = ath9k_hw_common(ah);
  1492. u32 status;
  1493. if (likely(!(common->debug_mask & ATH_DBG_RESET)))
  1494. return;
  1495. status = ah->bb_watchdog_last_status;
  1496. ath_dbg(common, RESET,
  1497. "\n==== BB update: BB status=0x%08x ====\n", status);
  1498. ath_dbg(common, RESET,
  1499. "** BB state: wd=%u det=%u rdar=%u rOFDM=%d rCCK=%u tOFDM=%u tCCK=%u agc=%u src=%u **\n",
  1500. MS(status, AR_PHY_WATCHDOG_INFO),
  1501. MS(status, AR_PHY_WATCHDOG_DET_HANG),
  1502. MS(status, AR_PHY_WATCHDOG_RADAR_SM),
  1503. MS(status, AR_PHY_WATCHDOG_RX_OFDM_SM),
  1504. MS(status, AR_PHY_WATCHDOG_RX_CCK_SM),
  1505. MS(status, AR_PHY_WATCHDOG_TX_OFDM_SM),
  1506. MS(status, AR_PHY_WATCHDOG_TX_CCK_SM),
  1507. MS(status, AR_PHY_WATCHDOG_AGC_SM),
  1508. MS(status, AR_PHY_WATCHDOG_SRCH_SM));
  1509. ath_dbg(common, RESET, "** BB WD cntl: cntl1=0x%08x cntl2=0x%08x **\n",
  1510. REG_READ(ah, AR_PHY_WATCHDOG_CTL_1),
  1511. REG_READ(ah, AR_PHY_WATCHDOG_CTL_2));
  1512. ath_dbg(common, RESET, "** BB mode: BB_gen_controls=0x%08x **\n",
  1513. REG_READ(ah, AR_PHY_GEN_CTRL));
  1514. #define PCT(_field) (common->cc_survey._field * 100 / common->cc_survey.cycles)
  1515. if (common->cc_survey.cycles)
  1516. ath_dbg(common, RESET,
  1517. "** BB busy times: rx_clear=%d%%, rx_frame=%d%%, tx_frame=%d%% **\n",
  1518. PCT(rx_busy), PCT(rx_frame), PCT(tx_frame));
  1519. ath_dbg(common, RESET, "==== BB update: done ====\n\n");
  1520. }
  1521. EXPORT_SYMBOL(ar9003_hw_bb_watchdog_dbg_info);
  1522. void ar9003_hw_disable_phy_restart(struct ath_hw *ah)
  1523. {
  1524. u32 val;
  1525. /* While receiving unsupported rate frame rx state machine
  1526. * gets into a state 0xb and if phy_restart happens in that
  1527. * state, BB would go hang. If RXSM is in 0xb state after
  1528. * first bb panic, ensure to disable the phy_restart.
  1529. */
  1530. if (!((MS(ah->bb_watchdog_last_status,
  1531. AR_PHY_WATCHDOG_RX_OFDM_SM) == 0xb) ||
  1532. ah->bb_hang_rx_ofdm))
  1533. return;
  1534. ah->bb_hang_rx_ofdm = true;
  1535. val = REG_READ(ah, AR_PHY_RESTART);
  1536. val &= ~AR_PHY_RESTART_ENA;
  1537. REG_WRITE(ah, AR_PHY_RESTART, val);
  1538. }
  1539. EXPORT_SYMBOL(ar9003_hw_disable_phy_restart);