ar9003_phy.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198
  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. #include "ar9003_eeprom.h"
  20. #define AR9300_OFDM_RATES 8
  21. #define AR9300_HT_SS_RATES 8
  22. #define AR9300_HT_DS_RATES 8
  23. #define AR9300_HT_TS_RATES 8
  24. #define AR9300_11NA_OFDM_SHIFT 0
  25. #define AR9300_11NA_HT_SS_SHIFT 8
  26. #define AR9300_11NA_HT_DS_SHIFT 16
  27. #define AR9300_11NA_HT_TS_SHIFT 24
  28. #define AR9300_11NG_OFDM_SHIFT 4
  29. #define AR9300_11NG_HT_SS_SHIFT 12
  30. #define AR9300_11NG_HT_DS_SHIFT 20
  31. #define AR9300_11NG_HT_TS_SHIFT 28
  32. static const int firstep_table[] =
  33. /* level: 0 1 2 3 4 5 6 7 8 */
  34. { -4, -2, 0, 2, 4, 6, 8, 10, 12 }; /* lvl 0-8, default 2 */
  35. static const int cycpwrThr1_table[] =
  36. /* level: 0 1 2 3 4 5 6 7 8 */
  37. { -6, -4, -2, 0, 2, 4, 6, 8 }; /* lvl 0-7, default 3 */
  38. /*
  39. * register values to turn OFDM weak signal detection OFF
  40. */
  41. static const int m1ThreshLow_off = 127;
  42. static const int m2ThreshLow_off = 127;
  43. static const int m1Thresh_off = 127;
  44. static const int m2Thresh_off = 127;
  45. static const int m2CountThr_off = 31;
  46. static const int m2CountThrLow_off = 63;
  47. static const int m1ThreshLowExt_off = 127;
  48. static const int m2ThreshLowExt_off = 127;
  49. static const int m1ThreshExt_off = 127;
  50. static const int m2ThreshExt_off = 127;
  51. static const u8 ofdm2pwr[] = {
  52. ALL_TARGET_LEGACY_6_24,
  53. ALL_TARGET_LEGACY_6_24,
  54. ALL_TARGET_LEGACY_6_24,
  55. ALL_TARGET_LEGACY_6_24,
  56. ALL_TARGET_LEGACY_6_24,
  57. ALL_TARGET_LEGACY_36,
  58. ALL_TARGET_LEGACY_48,
  59. ALL_TARGET_LEGACY_54
  60. };
  61. static const u8 mcs2pwr_ht20[] = {
  62. ALL_TARGET_HT20_0_8_16,
  63. ALL_TARGET_HT20_1_3_9_11_17_19,
  64. ALL_TARGET_HT20_1_3_9_11_17_19,
  65. ALL_TARGET_HT20_1_3_9_11_17_19,
  66. ALL_TARGET_HT20_4,
  67. ALL_TARGET_HT20_5,
  68. ALL_TARGET_HT20_6,
  69. ALL_TARGET_HT20_7,
  70. ALL_TARGET_HT20_0_8_16,
  71. ALL_TARGET_HT20_1_3_9_11_17_19,
  72. ALL_TARGET_HT20_1_3_9_11_17_19,
  73. ALL_TARGET_HT20_1_3_9_11_17_19,
  74. ALL_TARGET_HT20_12,
  75. ALL_TARGET_HT20_13,
  76. ALL_TARGET_HT20_14,
  77. ALL_TARGET_HT20_15,
  78. ALL_TARGET_HT20_0_8_16,
  79. ALL_TARGET_HT20_1_3_9_11_17_19,
  80. ALL_TARGET_HT20_1_3_9_11_17_19,
  81. ALL_TARGET_HT20_1_3_9_11_17_19,
  82. ALL_TARGET_HT20_20,
  83. ALL_TARGET_HT20_21,
  84. ALL_TARGET_HT20_22,
  85. ALL_TARGET_HT20_23
  86. };
  87. static const u8 mcs2pwr_ht40[] = {
  88. ALL_TARGET_HT40_0_8_16,
  89. ALL_TARGET_HT40_1_3_9_11_17_19,
  90. ALL_TARGET_HT40_1_3_9_11_17_19,
  91. ALL_TARGET_HT40_1_3_9_11_17_19,
  92. ALL_TARGET_HT40_4,
  93. ALL_TARGET_HT40_5,
  94. ALL_TARGET_HT40_6,
  95. ALL_TARGET_HT40_7,
  96. ALL_TARGET_HT40_0_8_16,
  97. ALL_TARGET_HT40_1_3_9_11_17_19,
  98. ALL_TARGET_HT40_1_3_9_11_17_19,
  99. ALL_TARGET_HT40_1_3_9_11_17_19,
  100. ALL_TARGET_HT40_12,
  101. ALL_TARGET_HT40_13,
  102. ALL_TARGET_HT40_14,
  103. ALL_TARGET_HT40_15,
  104. ALL_TARGET_HT40_0_8_16,
  105. ALL_TARGET_HT40_1_3_9_11_17_19,
  106. ALL_TARGET_HT40_1_3_9_11_17_19,
  107. ALL_TARGET_HT40_1_3_9_11_17_19,
  108. ALL_TARGET_HT40_20,
  109. ALL_TARGET_HT40_21,
  110. ALL_TARGET_HT40_22,
  111. ALL_TARGET_HT40_23,
  112. };
  113. /**
  114. * ar9003_hw_set_channel - set channel on single-chip device
  115. * @ah: atheros hardware structure
  116. * @chan:
  117. *
  118. * This is the function to change channel on single-chip devices, that is
  119. * for AR9300 family of chipsets.
  120. *
  121. * This function takes the channel value in MHz and sets
  122. * hardware channel value. Assumes writes have been enabled to analog bus.
  123. *
  124. * Actual Expression,
  125. *
  126. * For 2GHz channel,
  127. * Channel Frequency = (3/4) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
  128. * (freq_ref = 40MHz)
  129. *
  130. * For 5GHz channel,
  131. * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^10)
  132. * (freq_ref = 40MHz/(24>>amodeRefSel))
  133. *
  134. * For 5GHz channels which are 5MHz spaced,
  135. * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
  136. * (freq_ref = 40MHz)
  137. */
  138. static int ar9003_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
  139. {
  140. u16 bMode, fracMode = 0, aModeRefSel = 0;
  141. u32 freq, chan_frac, div, channelSel = 0, reg32 = 0;
  142. struct chan_centers centers;
  143. int loadSynthChannel;
  144. ath9k_hw_get_channel_centers(ah, chan, &centers);
  145. freq = centers.synth_center;
  146. if (freq < 4800) { /* 2 GHz, fractional mode */
  147. if (AR_SREV_9330(ah)) {
  148. if (ah->is_clk_25mhz)
  149. div = 75;
  150. else
  151. div = 120;
  152. channelSel = (freq * 4) / div;
  153. chan_frac = (((freq * 4) % div) * 0x20000) / div;
  154. channelSel = (channelSel << 17) | chan_frac;
  155. } else if (AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
  156. /*
  157. * freq_ref = 40 / (refdiva >> amoderefsel);
  158. * where refdiva=1 and amoderefsel=0
  159. * ndiv = ((chan_mhz * 4) / 3) / freq_ref;
  160. * chansel = int(ndiv), chanfrac = (ndiv - chansel) * 0x20000
  161. */
  162. channelSel = (freq * 4) / 120;
  163. chan_frac = (((freq * 4) % 120) * 0x20000) / 120;
  164. channelSel = (channelSel << 17) | chan_frac;
  165. } else if (AR_SREV_9340(ah)) {
  166. if (ah->is_clk_25mhz) {
  167. channelSel = (freq * 2) / 75;
  168. chan_frac = (((freq * 2) % 75) * 0x20000) / 75;
  169. channelSel = (channelSel << 17) | chan_frac;
  170. } else {
  171. channelSel = CHANSEL_2G(freq) >> 1;
  172. }
  173. } else if (AR_SREV_9550(ah) || AR_SREV_9531(ah) ||
  174. AR_SREV_9561(ah)) {
  175. if (ah->is_clk_25mhz)
  176. div = 75;
  177. else
  178. div = 120;
  179. channelSel = (freq * 4) / div;
  180. chan_frac = (((freq * 4) % div) * 0x20000) / div;
  181. channelSel = (channelSel << 17) | chan_frac;
  182. } else {
  183. channelSel = CHANSEL_2G(freq);
  184. }
  185. /* Set to 2G mode */
  186. bMode = 1;
  187. } else {
  188. if ((AR_SREV_9340(ah) || AR_SREV_9550(ah) ||
  189. AR_SREV_9531(ah) || AR_SREV_9561(ah)) &&
  190. ah->is_clk_25mhz) {
  191. channelSel = freq / 75;
  192. chan_frac = ((freq % 75) * 0x20000) / 75;
  193. channelSel = (channelSel << 17) | chan_frac;
  194. } else {
  195. channelSel = CHANSEL_5G(freq);
  196. /* Doubler is ON, so, divide channelSel by 2. */
  197. channelSel >>= 1;
  198. }
  199. /* Set to 5G mode */
  200. bMode = 0;
  201. }
  202. /* Enable fractional mode for all channels */
  203. fracMode = 1;
  204. aModeRefSel = 0;
  205. loadSynthChannel = 0;
  206. reg32 = (bMode << 29);
  207. REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
  208. /* Enable Long shift Select for Synthesizer */
  209. REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_SYNTH4,
  210. AR_PHY_SYNTH4_LONG_SHIFT_SELECT, 1);
  211. /* Program Synth. setting */
  212. reg32 = (channelSel << 2) | (fracMode << 30) |
  213. (aModeRefSel << 28) | (loadSynthChannel << 31);
  214. REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
  215. /* Toggle Load Synth channel bit */
  216. loadSynthChannel = 1;
  217. reg32 = (channelSel << 2) | (fracMode << 30) |
  218. (aModeRefSel << 28) | (loadSynthChannel << 31);
  219. REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
  220. ah->curchan = chan;
  221. return 0;
  222. }
  223. /**
  224. * ar9003_hw_spur_mitigate_mrc_cck - convert baseband spur frequency
  225. * @ah: atheros hardware structure
  226. * @chan:
  227. *
  228. * For single-chip solutions. Converts to baseband spur frequency given the
  229. * input channel frequency and compute register settings below.
  230. *
  231. * Spur mitigation for MRC CCK
  232. */
  233. static void ar9003_hw_spur_mitigate_mrc_cck(struct ath_hw *ah,
  234. struct ath9k_channel *chan)
  235. {
  236. static const u32 spur_freq[4] = { 2420, 2440, 2464, 2480 };
  237. int cur_bb_spur, negative = 0, cck_spur_freq;
  238. int i;
  239. int range, max_spur_cnts, synth_freq;
  240. u8 *spur_fbin_ptr = ar9003_get_spur_chan_ptr(ah, IS_CHAN_2GHZ(chan));
  241. /*
  242. * Need to verify range +/- 10 MHz in control channel, otherwise spur
  243. * is out-of-band and can be ignored.
  244. */
  245. if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah) ||
  246. AR_SREV_9550(ah) || AR_SREV_9561(ah)) {
  247. if (spur_fbin_ptr[0] == 0) /* No spur */
  248. return;
  249. max_spur_cnts = 5;
  250. if (IS_CHAN_HT40(chan)) {
  251. range = 19;
  252. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  253. AR_PHY_GC_DYN2040_PRI_CH) == 0)
  254. synth_freq = chan->channel + 10;
  255. else
  256. synth_freq = chan->channel - 10;
  257. } else {
  258. range = 10;
  259. synth_freq = chan->channel;
  260. }
  261. } else {
  262. range = AR_SREV_9462(ah) ? 5 : 10;
  263. max_spur_cnts = 4;
  264. synth_freq = chan->channel;
  265. }
  266. for (i = 0; i < max_spur_cnts; i++) {
  267. if (AR_SREV_9462(ah) && (i == 0 || i == 3))
  268. continue;
  269. negative = 0;
  270. if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah) ||
  271. AR_SREV_9550(ah) || AR_SREV_9561(ah))
  272. cur_bb_spur = ath9k_hw_fbin2freq(spur_fbin_ptr[i],
  273. IS_CHAN_2GHZ(chan));
  274. else
  275. cur_bb_spur = spur_freq[i];
  276. cur_bb_spur -= synth_freq;
  277. if (cur_bb_spur < 0) {
  278. negative = 1;
  279. cur_bb_spur = -cur_bb_spur;
  280. }
  281. if (cur_bb_spur < range) {
  282. cck_spur_freq = (int)((cur_bb_spur << 19) / 11);
  283. if (negative == 1)
  284. cck_spur_freq = -cck_spur_freq;
  285. cck_spur_freq = cck_spur_freq & 0xfffff;
  286. REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
  287. AR_PHY_AGC_CONTROL_YCOK_MAX, 0x7);
  288. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  289. AR_PHY_CCK_SPUR_MIT_SPUR_RSSI_THR, 0x7f);
  290. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  291. AR_PHY_CCK_SPUR_MIT_SPUR_FILTER_TYPE,
  292. 0x2);
  293. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  294. AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT,
  295. 0x1);
  296. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  297. AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ,
  298. cck_spur_freq);
  299. return;
  300. }
  301. }
  302. REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
  303. AR_PHY_AGC_CONTROL_YCOK_MAX, 0x5);
  304. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  305. AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT, 0x0);
  306. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  307. AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ, 0x0);
  308. }
  309. /* Clean all spur register fields */
  310. static void ar9003_hw_spur_ofdm_clear(struct ath_hw *ah)
  311. {
  312. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  313. AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0);
  314. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  315. AR_PHY_TIMING11_SPUR_FREQ_SD, 0);
  316. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  317. AR_PHY_TIMING11_SPUR_DELTA_PHASE, 0);
  318. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  319. AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, 0);
  320. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  321. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0);
  322. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  323. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0);
  324. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  325. AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0);
  326. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  327. AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 0);
  328. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  329. AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 0);
  330. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  331. AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0);
  332. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  333. AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0);
  334. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  335. AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0);
  336. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  337. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, 0);
  338. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  339. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, 0);
  340. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  341. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, 0);
  342. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  343. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0);
  344. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  345. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0);
  346. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  347. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0);
  348. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  349. AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0);
  350. }
  351. static void ar9003_hw_spur_ofdm(struct ath_hw *ah,
  352. int freq_offset,
  353. int spur_freq_sd,
  354. int spur_delta_phase,
  355. int spur_subchannel_sd,
  356. int range,
  357. int synth_freq)
  358. {
  359. int mask_index = 0;
  360. /* OFDM Spur mitigation */
  361. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  362. AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0x1);
  363. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  364. AR_PHY_TIMING11_SPUR_FREQ_SD, spur_freq_sd);
  365. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  366. AR_PHY_TIMING11_SPUR_DELTA_PHASE, spur_delta_phase);
  367. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  368. AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, spur_subchannel_sd);
  369. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  370. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0x1);
  371. if (!(AR_SREV_9565(ah) && range == 10 && synth_freq == 2437))
  372. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  373. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0x1);
  374. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  375. AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0x1);
  376. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  377. AR_PHY_SPUR_REG_SPUR_RSSI_THRESH, 34);
  378. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  379. AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 1);
  380. if (!AR_SREV_9340(ah) &&
  381. REG_READ_FIELD(ah, AR_PHY_MODE,
  382. AR_PHY_MODE_DYNAMIC) == 0x1)
  383. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  384. AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 1);
  385. mask_index = (freq_offset << 4) / 5;
  386. if (mask_index < 0)
  387. mask_index = mask_index - 1;
  388. mask_index = mask_index & 0x7f;
  389. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  390. AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0x1);
  391. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  392. AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0x1);
  393. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  394. AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0x1);
  395. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  396. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, mask_index);
  397. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  398. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, mask_index);
  399. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  400. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, mask_index);
  401. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  402. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0xc);
  403. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  404. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0xc);
  405. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  406. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0xa0);
  407. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  408. AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0xff);
  409. }
  410. static void ar9003_hw_spur_ofdm_9565(struct ath_hw *ah,
  411. int freq_offset)
  412. {
  413. int mask_index = 0;
  414. mask_index = (freq_offset << 4) / 5;
  415. if (mask_index < 0)
  416. mask_index = mask_index - 1;
  417. mask_index = mask_index & 0x7f;
  418. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  419. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_B,
  420. mask_index);
  421. /* A == B */
  422. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_B,
  423. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A,
  424. mask_index);
  425. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  426. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_B,
  427. mask_index);
  428. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  429. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_B, 0xe);
  430. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  431. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_B, 0xe);
  432. /* A == B */
  433. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_B,
  434. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0xa0);
  435. }
  436. static void ar9003_hw_spur_ofdm_work(struct ath_hw *ah,
  437. struct ath9k_channel *chan,
  438. int freq_offset,
  439. int range,
  440. int synth_freq)
  441. {
  442. int spur_freq_sd = 0;
  443. int spur_subchannel_sd = 0;
  444. int spur_delta_phase = 0;
  445. if (IS_CHAN_HT40(chan)) {
  446. if (freq_offset < 0) {
  447. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  448. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  449. spur_subchannel_sd = 1;
  450. else
  451. spur_subchannel_sd = 0;
  452. spur_freq_sd = ((freq_offset + 10) << 9) / 11;
  453. } else {
  454. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  455. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  456. spur_subchannel_sd = 0;
  457. else
  458. spur_subchannel_sd = 1;
  459. spur_freq_sd = ((freq_offset - 10) << 9) / 11;
  460. }
  461. spur_delta_phase = (freq_offset << 17) / 5;
  462. } else {
  463. spur_subchannel_sd = 0;
  464. spur_freq_sd = (freq_offset << 9) /11;
  465. spur_delta_phase = (freq_offset << 18) / 5;
  466. }
  467. spur_freq_sd = spur_freq_sd & 0x3ff;
  468. spur_delta_phase = spur_delta_phase & 0xfffff;
  469. ar9003_hw_spur_ofdm(ah,
  470. freq_offset,
  471. spur_freq_sd,
  472. spur_delta_phase,
  473. spur_subchannel_sd,
  474. range, synth_freq);
  475. }
  476. /* Spur mitigation for OFDM */
  477. static void ar9003_hw_spur_mitigate_ofdm(struct ath_hw *ah,
  478. struct ath9k_channel *chan)
  479. {
  480. int synth_freq;
  481. int range = 10;
  482. int freq_offset = 0;
  483. int mode;
  484. u8* spurChansPtr;
  485. unsigned int i;
  486. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  487. if (IS_CHAN_5GHZ(chan)) {
  488. spurChansPtr = &(eep->modalHeader5G.spurChans[0]);
  489. mode = 0;
  490. }
  491. else {
  492. spurChansPtr = &(eep->modalHeader2G.spurChans[0]);
  493. mode = 1;
  494. }
  495. if (spurChansPtr[0] == 0)
  496. return; /* No spur in the mode */
  497. if (IS_CHAN_HT40(chan)) {
  498. range = 19;
  499. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  500. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  501. synth_freq = chan->channel - 10;
  502. else
  503. synth_freq = chan->channel + 10;
  504. } else {
  505. range = 10;
  506. synth_freq = chan->channel;
  507. }
  508. ar9003_hw_spur_ofdm_clear(ah);
  509. for (i = 0; i < AR_EEPROM_MODAL_SPURS && spurChansPtr[i]; i++) {
  510. freq_offset = ath9k_hw_fbin2freq(spurChansPtr[i], mode);
  511. freq_offset -= synth_freq;
  512. if (abs(freq_offset) < range) {
  513. ar9003_hw_spur_ofdm_work(ah, chan, freq_offset,
  514. range, synth_freq);
  515. if (AR_SREV_9565(ah) && (i < 4)) {
  516. freq_offset = ath9k_hw_fbin2freq(spurChansPtr[i + 1],
  517. mode);
  518. freq_offset -= synth_freq;
  519. if (abs(freq_offset) < range)
  520. ar9003_hw_spur_ofdm_9565(ah, freq_offset);
  521. }
  522. break;
  523. }
  524. }
  525. }
  526. static void ar9003_hw_spur_mitigate(struct ath_hw *ah,
  527. struct ath9k_channel *chan)
  528. {
  529. if (!AR_SREV_9565(ah))
  530. ar9003_hw_spur_mitigate_mrc_cck(ah, chan);
  531. ar9003_hw_spur_mitigate_ofdm(ah, chan);
  532. }
  533. static u32 ar9003_hw_compute_pll_control_soc(struct ath_hw *ah,
  534. struct ath9k_channel *chan)
  535. {
  536. u32 pll;
  537. pll = SM(0x5, AR_RTC_9300_SOC_PLL_REFDIV);
  538. if (chan && IS_CHAN_HALF_RATE(chan))
  539. pll |= SM(0x1, AR_RTC_9300_SOC_PLL_CLKSEL);
  540. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  541. pll |= SM(0x2, AR_RTC_9300_SOC_PLL_CLKSEL);
  542. pll |= SM(0x2c, AR_RTC_9300_SOC_PLL_DIV_INT);
  543. return pll;
  544. }
  545. static u32 ar9003_hw_compute_pll_control(struct ath_hw *ah,
  546. struct ath9k_channel *chan)
  547. {
  548. u32 pll;
  549. pll = SM(0x5, AR_RTC_9300_PLL_REFDIV);
  550. if (chan && IS_CHAN_HALF_RATE(chan))
  551. pll |= SM(0x1, AR_RTC_9300_PLL_CLKSEL);
  552. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  553. pll |= SM(0x2, AR_RTC_9300_PLL_CLKSEL);
  554. pll |= SM(0x2c, AR_RTC_9300_PLL_DIV);
  555. return pll;
  556. }
  557. static void ar9003_hw_set_channel_regs(struct ath_hw *ah,
  558. struct ath9k_channel *chan)
  559. {
  560. u32 phymode;
  561. u32 enableDacFifo = 0;
  562. enableDacFifo =
  563. (REG_READ(ah, AR_PHY_GEN_CTRL) & AR_PHY_GC_ENABLE_DAC_FIFO);
  564. /* Enable 11n HT, 20 MHz */
  565. phymode = AR_PHY_GC_HT_EN | AR_PHY_GC_SHORT_GI_40 | enableDacFifo;
  566. if (!AR_SREV_9561(ah))
  567. phymode |= AR_PHY_GC_SINGLE_HT_LTF1;
  568. /* Configure baseband for dynamic 20/40 operation */
  569. if (IS_CHAN_HT40(chan)) {
  570. phymode |= AR_PHY_GC_DYN2040_EN;
  571. /* Configure control (primary) channel at +-10MHz */
  572. if (IS_CHAN_HT40PLUS(chan))
  573. phymode |= AR_PHY_GC_DYN2040_PRI_CH;
  574. }
  575. /* make sure we preserve INI settings */
  576. phymode |= REG_READ(ah, AR_PHY_GEN_CTRL);
  577. /* turn off Green Field detection for STA for now */
  578. phymode &= ~AR_PHY_GC_GF_DETECT_EN;
  579. REG_WRITE(ah, AR_PHY_GEN_CTRL, phymode);
  580. /* Configure MAC for 20/40 operation */
  581. ath9k_hw_set11nmac2040(ah, chan);
  582. /* global transmit timeout (25 TUs default)*/
  583. REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
  584. /* carrier sense timeout */
  585. REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
  586. }
  587. static void ar9003_hw_init_bb(struct ath_hw *ah,
  588. struct ath9k_channel *chan)
  589. {
  590. u32 synthDelay;
  591. /*
  592. * Wait for the frequency synth to settle (synth goes on
  593. * via AR_PHY_ACTIVE_EN). Read the phy active delay register.
  594. * Value is in 100ns increments.
  595. */
  596. synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  597. /* Activate the PHY (includes baseband activate + synthesizer on) */
  598. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
  599. ath9k_hw_synth_delay(ah, chan, synthDelay);
  600. }
  601. void ar9003_hw_set_chain_masks(struct ath_hw *ah, u8 rx, u8 tx)
  602. {
  603. if (ah->caps.tx_chainmask == 5 || ah->caps.rx_chainmask == 5)
  604. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  605. AR_PHY_SWAP_ALT_CHAIN);
  606. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx);
  607. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx);
  608. if ((ah->caps.hw_caps & ATH9K_HW_CAP_APM) && (tx == 0x7))
  609. tx = 3;
  610. REG_WRITE(ah, AR_SELFGEN_MASK, tx);
  611. }
  612. /*
  613. * Override INI values with chip specific configuration.
  614. */
  615. static void ar9003_hw_override_ini(struct ath_hw *ah)
  616. {
  617. u32 val;
  618. /*
  619. * Set the RX_ABORT and RX_DIS and clear it only after
  620. * RXE is set for MAC. This prevents frames with
  621. * corrupted descriptor status.
  622. */
  623. REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  624. /*
  625. * For AR9280 and above, there is a new feature that allows
  626. * Multicast search based on both MAC Address and Key ID. By default,
  627. * this feature is enabled. But since the driver is not using this
  628. * feature, we switch it off; otherwise multicast search based on
  629. * MAC addr only will fail.
  630. */
  631. val = REG_READ(ah, AR_PCU_MISC_MODE2) & (~AR_ADHOC_MCAST_KEYID_ENABLE);
  632. val |= AR_AGG_WEP_ENABLE_FIX |
  633. AR_AGG_WEP_ENABLE |
  634. AR_PCU_MISC_MODE2_CFP_IGNORE;
  635. REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
  636. if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
  637. REG_WRITE(ah, AR_GLB_SWREG_DISCONT_MODE,
  638. AR_GLB_SWREG_DISCONT_EN_BT_WLAN);
  639. if (REG_READ_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_0,
  640. AR_PHY_TX_IQCAL_CONTROL_0_ENABLE_TXIQ_CAL))
  641. ah->enabled_cals |= TX_IQ_CAL;
  642. else
  643. ah->enabled_cals &= ~TX_IQ_CAL;
  644. }
  645. if (REG_READ(ah, AR_PHY_CL_CAL_CTL) & AR_PHY_CL_CAL_ENABLE)
  646. ah->enabled_cals |= TX_CL_CAL;
  647. else
  648. ah->enabled_cals &= ~TX_CL_CAL;
  649. if (AR_SREV_9340(ah) || AR_SREV_9531(ah) || AR_SREV_9550(ah) ||
  650. AR_SREV_9561(ah)) {
  651. if (ah->is_clk_25mhz) {
  652. REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x17c << 1);
  653. REG_WRITE(ah, AR_SLP32_MODE, 0x0010f3d7);
  654. REG_WRITE(ah, AR_SLP32_INC, 0x0001e7ae);
  655. } else {
  656. REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x261 << 1);
  657. REG_WRITE(ah, AR_SLP32_MODE, 0x0010f400);
  658. REG_WRITE(ah, AR_SLP32_INC, 0x0001e800);
  659. }
  660. udelay(100);
  661. }
  662. }
  663. static void ar9003_hw_prog_ini(struct ath_hw *ah,
  664. struct ar5416IniArray *iniArr,
  665. int column)
  666. {
  667. unsigned int i, regWrites = 0;
  668. /* New INI format: Array may be undefined (pre, core, post arrays) */
  669. if (!iniArr->ia_array)
  670. return;
  671. /*
  672. * New INI format: Pre, core, and post arrays for a given subsystem
  673. * may be modal (> 2 columns) or non-modal (2 columns). Determine if
  674. * the array is non-modal and force the column to 1.
  675. */
  676. if (column >= iniArr->ia_columns)
  677. column = 1;
  678. for (i = 0; i < iniArr->ia_rows; i++) {
  679. u32 reg = INI_RA(iniArr, i, 0);
  680. u32 val = INI_RA(iniArr, i, column);
  681. REG_WRITE(ah, reg, val);
  682. DO_DELAY(regWrites);
  683. }
  684. }
  685. static int ar9550_hw_get_modes_txgain_index(struct ath_hw *ah,
  686. struct ath9k_channel *chan)
  687. {
  688. int ret;
  689. if (IS_CHAN_2GHZ(chan)) {
  690. if (IS_CHAN_HT40(chan))
  691. return 7;
  692. else
  693. return 8;
  694. }
  695. if (chan->channel <= 5350)
  696. ret = 1;
  697. else if ((chan->channel > 5350) && (chan->channel <= 5600))
  698. ret = 3;
  699. else
  700. ret = 5;
  701. if (IS_CHAN_HT40(chan))
  702. ret++;
  703. return ret;
  704. }
  705. static int ar9561_hw_get_modes_txgain_index(struct ath_hw *ah,
  706. struct ath9k_channel *chan)
  707. {
  708. if (IS_CHAN_2GHZ(chan)) {
  709. if (IS_CHAN_HT40(chan))
  710. return 1;
  711. else
  712. return 2;
  713. }
  714. return 0;
  715. }
  716. static void ar9003_doubler_fix(struct ath_hw *ah)
  717. {
  718. if (AR_SREV_9300(ah) || AR_SREV_9580(ah) || AR_SREV_9550(ah)) {
  719. REG_RMW(ah, AR_PHY_65NM_CH0_RXTX2,
  720. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
  721. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S, 0);
  722. REG_RMW(ah, AR_PHY_65NM_CH1_RXTX2,
  723. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
  724. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S, 0);
  725. REG_RMW(ah, AR_PHY_65NM_CH2_RXTX2,
  726. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
  727. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S, 0);
  728. udelay(200);
  729. REG_CLR_BIT(ah, AR_PHY_65NM_CH0_RXTX2,
  730. AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK);
  731. REG_CLR_BIT(ah, AR_PHY_65NM_CH1_RXTX2,
  732. AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK);
  733. REG_CLR_BIT(ah, AR_PHY_65NM_CH2_RXTX2,
  734. AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK);
  735. udelay(1);
  736. REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_RXTX2,
  737. AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK, 1);
  738. REG_RMW_FIELD(ah, AR_PHY_65NM_CH1_RXTX2,
  739. AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK, 1);
  740. REG_RMW_FIELD(ah, AR_PHY_65NM_CH2_RXTX2,
  741. AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK, 1);
  742. udelay(200);
  743. REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_SYNTH12,
  744. AR_PHY_65NM_CH0_SYNTH12_VREFMUL3, 0xf);
  745. REG_RMW(ah, AR_PHY_65NM_CH0_RXTX2, 0,
  746. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
  747. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S);
  748. REG_RMW(ah, AR_PHY_65NM_CH1_RXTX2, 0,
  749. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
  750. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S);
  751. REG_RMW(ah, AR_PHY_65NM_CH2_RXTX2, 0,
  752. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
  753. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S);
  754. }
  755. }
  756. static int ar9003_hw_process_ini(struct ath_hw *ah,
  757. struct ath9k_channel *chan)
  758. {
  759. unsigned int regWrites = 0, i;
  760. u32 modesIndex;
  761. if (IS_CHAN_5GHZ(chan))
  762. modesIndex = IS_CHAN_HT40(chan) ? 2 : 1;
  763. else
  764. modesIndex = IS_CHAN_HT40(chan) ? 3 : 4;
  765. /*
  766. * SOC, MAC, BB, RADIO initvals.
  767. */
  768. for (i = 0; i < ATH_INI_NUM_SPLIT; i++) {
  769. ar9003_hw_prog_ini(ah, &ah->iniSOC[i], modesIndex);
  770. ar9003_hw_prog_ini(ah, &ah->iniMac[i], modesIndex);
  771. ar9003_hw_prog_ini(ah, &ah->iniBB[i], modesIndex);
  772. ar9003_hw_prog_ini(ah, &ah->iniRadio[i], modesIndex);
  773. if (i == ATH_INI_POST && AR_SREV_9462_20_OR_LATER(ah))
  774. ar9003_hw_prog_ini(ah,
  775. &ah->ini_radio_post_sys2ant,
  776. modesIndex);
  777. }
  778. ar9003_doubler_fix(ah);
  779. /*
  780. * RXGAIN initvals.
  781. */
  782. REG_WRITE_ARRAY(&ah->iniModesRxGain, 1, regWrites);
  783. if (AR_SREV_9462_20_OR_LATER(ah)) {
  784. /*
  785. * CUS217 mix LNA mode.
  786. */
  787. if (ar9003_hw_get_rx_gain_idx(ah) == 2) {
  788. REG_WRITE_ARRAY(&ah->ini_modes_rxgain_bb_core,
  789. 1, regWrites);
  790. REG_WRITE_ARRAY(&ah->ini_modes_rxgain_bb_postamble,
  791. modesIndex, regWrites);
  792. }
  793. /*
  794. * 5G-XLNA
  795. */
  796. if ((ar9003_hw_get_rx_gain_idx(ah) == 2) ||
  797. (ar9003_hw_get_rx_gain_idx(ah) == 3)) {
  798. REG_WRITE_ARRAY(&ah->ini_modes_rxgain_xlna,
  799. modesIndex, regWrites);
  800. }
  801. }
  802. if (AR_SREV_9550(ah) || AR_SREV_9561(ah))
  803. REG_WRITE_ARRAY(&ah->ini_modes_rx_gain_bounds, modesIndex,
  804. regWrites);
  805. if (AR_SREV_9561(ah) && (ar9003_hw_get_rx_gain_idx(ah) == 0))
  806. REG_WRITE_ARRAY(&ah->ini_modes_rxgain_xlna,
  807. modesIndex, regWrites);
  808. /*
  809. * TXGAIN initvals.
  810. */
  811. if (AR_SREV_9550(ah) || AR_SREV_9531(ah) || AR_SREV_9561(ah)) {
  812. int modes_txgain_index = 1;
  813. if (AR_SREV_9550(ah))
  814. modes_txgain_index = ar9550_hw_get_modes_txgain_index(ah, chan);
  815. if (AR_SREV_9561(ah))
  816. modes_txgain_index =
  817. ar9561_hw_get_modes_txgain_index(ah, chan);
  818. if (modes_txgain_index < 0)
  819. return -EINVAL;
  820. REG_WRITE_ARRAY(&ah->iniModesTxGain, modes_txgain_index,
  821. regWrites);
  822. } else {
  823. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  824. }
  825. /*
  826. * For 5GHz channels requiring Fast Clock, apply
  827. * different modal values.
  828. */
  829. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  830. REG_WRITE_ARRAY(&ah->iniModesFastClock,
  831. modesIndex, regWrites);
  832. /*
  833. * Clock frequency initvals.
  834. */
  835. REG_WRITE_ARRAY(&ah->iniAdditional, 1, regWrites);
  836. /*
  837. * JAPAN regulatory.
  838. */
  839. if (chan->channel == 2484) {
  840. ar9003_hw_prog_ini(ah, &ah->iniCckfirJapan2484, 1);
  841. if (AR_SREV_9531(ah))
  842. REG_RMW_FIELD(ah, AR_PHY_FCAL_2_0,
  843. AR_PHY_FLC_PWR_THRESH, 0);
  844. }
  845. ah->modes_index = modesIndex;
  846. ar9003_hw_override_ini(ah);
  847. ar9003_hw_set_channel_regs(ah, chan);
  848. ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
  849. ath9k_hw_apply_txpower(ah, chan, false);
  850. return 0;
  851. }
  852. static void ar9003_hw_set_rfmode(struct ath_hw *ah,
  853. struct ath9k_channel *chan)
  854. {
  855. u32 rfMode = 0;
  856. if (chan == NULL)
  857. return;
  858. if (IS_CHAN_2GHZ(chan))
  859. rfMode |= AR_PHY_MODE_DYNAMIC;
  860. else
  861. rfMode |= AR_PHY_MODE_OFDM;
  862. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  863. rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
  864. if (IS_CHAN_HALF_RATE(chan) || IS_CHAN_QUARTER_RATE(chan))
  865. REG_RMW_FIELD(ah, AR_PHY_FRAME_CTL,
  866. AR_PHY_FRAME_CTL_CF_OVERLAP_WINDOW, 3);
  867. REG_WRITE(ah, AR_PHY_MODE, rfMode);
  868. }
  869. static void ar9003_hw_mark_phy_inactive(struct ath_hw *ah)
  870. {
  871. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
  872. }
  873. static void ar9003_hw_set_delta_slope(struct ath_hw *ah,
  874. struct ath9k_channel *chan)
  875. {
  876. u32 coef_scaled, ds_coef_exp, ds_coef_man;
  877. u32 clockMhzScaled = 0x64000000;
  878. struct chan_centers centers;
  879. /*
  880. * half and quarter rate can divide the scaled clock by 2 or 4
  881. * scale for selected channel bandwidth
  882. */
  883. if (IS_CHAN_HALF_RATE(chan))
  884. clockMhzScaled = clockMhzScaled >> 1;
  885. else if (IS_CHAN_QUARTER_RATE(chan))
  886. clockMhzScaled = clockMhzScaled >> 2;
  887. /*
  888. * ALGO -> coef = 1e8/fcarrier*fclock/40;
  889. * scaled coef to provide precision for this floating calculation
  890. */
  891. ath9k_hw_get_channel_centers(ah, chan, &centers);
  892. coef_scaled = clockMhzScaled / centers.synth_center;
  893. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  894. &ds_coef_exp);
  895. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  896. AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
  897. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  898. AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
  899. /*
  900. * For Short GI,
  901. * scaled coeff is 9/10 that of normal coeff
  902. */
  903. coef_scaled = (9 * coef_scaled) / 10;
  904. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  905. &ds_coef_exp);
  906. /* for short gi */
  907. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  908. AR_PHY_SGI_DSC_MAN, ds_coef_man);
  909. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  910. AR_PHY_SGI_DSC_EXP, ds_coef_exp);
  911. }
  912. static bool ar9003_hw_rfbus_req(struct ath_hw *ah)
  913. {
  914. REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
  915. return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
  916. AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT);
  917. }
  918. /*
  919. * Wait for the frequency synth to settle (synth goes on via PHY_ACTIVE_EN).
  920. * Read the phy active delay register. Value is in 100ns increments.
  921. */
  922. static void ar9003_hw_rfbus_done(struct ath_hw *ah)
  923. {
  924. u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  925. ath9k_hw_synth_delay(ah, ah->curchan, synthDelay);
  926. REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
  927. }
  928. static bool ar9003_hw_ani_control(struct ath_hw *ah,
  929. enum ath9k_ani_cmd cmd, int param)
  930. {
  931. struct ath_common *common = ath9k_hw_common(ah);
  932. struct ath9k_channel *chan = ah->curchan;
  933. struct ar5416AniState *aniState = &ah->ani;
  934. int m1ThreshLow, m2ThreshLow;
  935. int m1Thresh, m2Thresh;
  936. int m2CountThr, m2CountThrLow;
  937. int m1ThreshLowExt, m2ThreshLowExt;
  938. int m1ThreshExt, m2ThreshExt;
  939. s32 value, value2;
  940. switch (cmd & ah->ani_function) {
  941. case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
  942. /*
  943. * on == 1 means ofdm weak signal detection is ON
  944. * on == 1 is the default, for less noise immunity
  945. *
  946. * on == 0 means ofdm weak signal detection is OFF
  947. * on == 0 means more noise imm
  948. */
  949. u32 on = param ? 1 : 0;
  950. if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
  951. goto skip_ws_det;
  952. m1ThreshLow = on ?
  953. aniState->iniDef.m1ThreshLow : m1ThreshLow_off;
  954. m2ThreshLow = on ?
  955. aniState->iniDef.m2ThreshLow : m2ThreshLow_off;
  956. m1Thresh = on ?
  957. aniState->iniDef.m1Thresh : m1Thresh_off;
  958. m2Thresh = on ?
  959. aniState->iniDef.m2Thresh : m2Thresh_off;
  960. m2CountThr = on ?
  961. aniState->iniDef.m2CountThr : m2CountThr_off;
  962. m2CountThrLow = on ?
  963. aniState->iniDef.m2CountThrLow : m2CountThrLow_off;
  964. m1ThreshLowExt = on ?
  965. aniState->iniDef.m1ThreshLowExt : m1ThreshLowExt_off;
  966. m2ThreshLowExt = on ?
  967. aniState->iniDef.m2ThreshLowExt : m2ThreshLowExt_off;
  968. m1ThreshExt = on ?
  969. aniState->iniDef.m1ThreshExt : m1ThreshExt_off;
  970. m2ThreshExt = on ?
  971. aniState->iniDef.m2ThreshExt : m2ThreshExt_off;
  972. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  973. AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
  974. m1ThreshLow);
  975. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  976. AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
  977. m2ThreshLow);
  978. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  979. AR_PHY_SFCORR_M1_THRESH,
  980. m1Thresh);
  981. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  982. AR_PHY_SFCORR_M2_THRESH,
  983. m2Thresh);
  984. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  985. AR_PHY_SFCORR_M2COUNT_THR,
  986. m2CountThr);
  987. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  988. AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
  989. m2CountThrLow);
  990. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  991. AR_PHY_SFCORR_EXT_M1_THRESH_LOW,
  992. m1ThreshLowExt);
  993. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  994. AR_PHY_SFCORR_EXT_M2_THRESH_LOW,
  995. m2ThreshLowExt);
  996. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  997. AR_PHY_SFCORR_EXT_M1_THRESH,
  998. m1ThreshExt);
  999. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  1000. AR_PHY_SFCORR_EXT_M2_THRESH,
  1001. m2ThreshExt);
  1002. skip_ws_det:
  1003. if (on)
  1004. REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
  1005. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  1006. else
  1007. REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
  1008. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  1009. if (on != aniState->ofdmWeakSigDetect) {
  1010. ath_dbg(common, ANI,
  1011. "** ch %d: ofdm weak signal: %s=>%s\n",
  1012. chan->channel,
  1013. aniState->ofdmWeakSigDetect ?
  1014. "on" : "off",
  1015. on ? "on" : "off");
  1016. if (on)
  1017. ah->stats.ast_ani_ofdmon++;
  1018. else
  1019. ah->stats.ast_ani_ofdmoff++;
  1020. aniState->ofdmWeakSigDetect = on;
  1021. }
  1022. break;
  1023. }
  1024. case ATH9K_ANI_FIRSTEP_LEVEL:{
  1025. u32 level = param;
  1026. if (level >= ARRAY_SIZE(firstep_table)) {
  1027. ath_dbg(common, ANI,
  1028. "ATH9K_ANI_FIRSTEP_LEVEL: level out of range (%u > %zu)\n",
  1029. level, ARRAY_SIZE(firstep_table));
  1030. return false;
  1031. }
  1032. /*
  1033. * make register setting relative to default
  1034. * from INI file & cap value
  1035. */
  1036. value = firstep_table[level] -
  1037. firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
  1038. aniState->iniDef.firstep;
  1039. if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  1040. value = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  1041. if (value > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  1042. value = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  1043. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  1044. AR_PHY_FIND_SIG_FIRSTEP,
  1045. value);
  1046. /*
  1047. * we need to set first step low register too
  1048. * make register setting relative to default
  1049. * from INI file & cap value
  1050. */
  1051. value2 = firstep_table[level] -
  1052. firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
  1053. aniState->iniDef.firstepLow;
  1054. if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  1055. value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  1056. if (value2 > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  1057. value2 = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  1058. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
  1059. AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW, value2);
  1060. if (level != aniState->firstepLevel) {
  1061. ath_dbg(common, ANI,
  1062. "** ch %d: level %d=>%d[def:%d] firstep[level]=%d ini=%d\n",
  1063. chan->channel,
  1064. aniState->firstepLevel,
  1065. level,
  1066. ATH9K_ANI_FIRSTEP_LVL,
  1067. value,
  1068. aniState->iniDef.firstep);
  1069. ath_dbg(common, ANI,
  1070. "** ch %d: level %d=>%d[def:%d] firstep_low[level]=%d ini=%d\n",
  1071. chan->channel,
  1072. aniState->firstepLevel,
  1073. level,
  1074. ATH9K_ANI_FIRSTEP_LVL,
  1075. value2,
  1076. aniState->iniDef.firstepLow);
  1077. if (level > aniState->firstepLevel)
  1078. ah->stats.ast_ani_stepup++;
  1079. else if (level < aniState->firstepLevel)
  1080. ah->stats.ast_ani_stepdown++;
  1081. aniState->firstepLevel = level;
  1082. }
  1083. break;
  1084. }
  1085. case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
  1086. u32 level = param;
  1087. if (level >= ARRAY_SIZE(cycpwrThr1_table)) {
  1088. ath_dbg(common, ANI,
  1089. "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level out of range (%u > %zu)\n",
  1090. level, ARRAY_SIZE(cycpwrThr1_table));
  1091. return false;
  1092. }
  1093. /*
  1094. * make register setting relative to default
  1095. * from INI file & cap value
  1096. */
  1097. value = cycpwrThr1_table[level] -
  1098. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
  1099. aniState->iniDef.cycpwrThr1;
  1100. if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  1101. value = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  1102. if (value > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  1103. value = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  1104. REG_RMW_FIELD(ah, AR_PHY_TIMING5,
  1105. AR_PHY_TIMING5_CYCPWR_THR1,
  1106. value);
  1107. /*
  1108. * set AR_PHY_EXT_CCA for extension channel
  1109. * make register setting relative to default
  1110. * from INI file & cap value
  1111. */
  1112. value2 = cycpwrThr1_table[level] -
  1113. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
  1114. aniState->iniDef.cycpwrThr1Ext;
  1115. if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  1116. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  1117. if (value2 > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  1118. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  1119. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
  1120. AR_PHY_EXT_CYCPWR_THR1, value2);
  1121. if (level != aniState->spurImmunityLevel) {
  1122. ath_dbg(common, ANI,
  1123. "** ch %d: level %d=>%d[def:%d] cycpwrThr1[level]=%d ini=%d\n",
  1124. chan->channel,
  1125. aniState->spurImmunityLevel,
  1126. level,
  1127. ATH9K_ANI_SPUR_IMMUNE_LVL,
  1128. value,
  1129. aniState->iniDef.cycpwrThr1);
  1130. ath_dbg(common, ANI,
  1131. "** ch %d: level %d=>%d[def:%d] cycpwrThr1Ext[level]=%d ini=%d\n",
  1132. chan->channel,
  1133. aniState->spurImmunityLevel,
  1134. level,
  1135. ATH9K_ANI_SPUR_IMMUNE_LVL,
  1136. value2,
  1137. aniState->iniDef.cycpwrThr1Ext);
  1138. if (level > aniState->spurImmunityLevel)
  1139. ah->stats.ast_ani_spurup++;
  1140. else if (level < aniState->spurImmunityLevel)
  1141. ah->stats.ast_ani_spurdown++;
  1142. aniState->spurImmunityLevel = level;
  1143. }
  1144. break;
  1145. }
  1146. case ATH9K_ANI_MRC_CCK:{
  1147. /*
  1148. * is_on == 1 means MRC CCK ON (default, less noise imm)
  1149. * is_on == 0 means MRC CCK is OFF (more noise imm)
  1150. */
  1151. bool is_on = param ? 1 : 0;
  1152. if (ah->caps.rx_chainmask == 1)
  1153. break;
  1154. REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
  1155. AR_PHY_MRC_CCK_ENABLE, is_on);
  1156. REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
  1157. AR_PHY_MRC_CCK_MUX_REG, is_on);
  1158. if (is_on != aniState->mrcCCK) {
  1159. ath_dbg(common, ANI, "** ch %d: MRC CCK: %s=>%s\n",
  1160. chan->channel,
  1161. aniState->mrcCCK ? "on" : "off",
  1162. is_on ? "on" : "off");
  1163. if (is_on)
  1164. ah->stats.ast_ani_ccklow++;
  1165. else
  1166. ah->stats.ast_ani_cckhigh++;
  1167. aniState->mrcCCK = is_on;
  1168. }
  1169. break;
  1170. }
  1171. default:
  1172. ath_dbg(common, ANI, "invalid cmd %u\n", cmd);
  1173. return false;
  1174. }
  1175. ath_dbg(common, ANI,
  1176. "ANI parameters: SI=%d, ofdmWS=%s FS=%d MRCcck=%s listenTime=%d ofdmErrs=%d cckErrs=%d\n",
  1177. aniState->spurImmunityLevel,
  1178. aniState->ofdmWeakSigDetect ? "on" : "off",
  1179. aniState->firstepLevel,
  1180. aniState->mrcCCK ? "on" : "off",
  1181. aniState->listenTime,
  1182. aniState->ofdmPhyErrCount,
  1183. aniState->cckPhyErrCount);
  1184. return true;
  1185. }
  1186. static void ar9003_hw_do_getnf(struct ath_hw *ah,
  1187. int16_t nfarray[NUM_NF_READINGS])
  1188. {
  1189. #define AR_PHY_CH_MINCCA_PWR 0x1FF00000
  1190. #define AR_PHY_CH_MINCCA_PWR_S 20
  1191. #define AR_PHY_CH_EXT_MINCCA_PWR 0x01FF0000
  1192. #define AR_PHY_CH_EXT_MINCCA_PWR_S 16
  1193. int16_t nf;
  1194. int i;
  1195. for (i = 0; i < AR9300_MAX_CHAINS; i++) {
  1196. if (ah->rxchainmask & BIT(i)) {
  1197. nf = MS(REG_READ(ah, ah->nf_regs[i]),
  1198. AR_PHY_CH_MINCCA_PWR);
  1199. nfarray[i] = sign_extend32(nf, 8);
  1200. if (IS_CHAN_HT40(ah->curchan)) {
  1201. u8 ext_idx = AR9300_MAX_CHAINS + i;
  1202. nf = MS(REG_READ(ah, ah->nf_regs[ext_idx]),
  1203. AR_PHY_CH_EXT_MINCCA_PWR);
  1204. nfarray[ext_idx] = sign_extend32(nf, 8);
  1205. }
  1206. }
  1207. }
  1208. }
  1209. static void ar9003_hw_set_nf_limits(struct ath_hw *ah)
  1210. {
  1211. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_2GHZ;
  1212. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_2GHZ;
  1213. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9300_2GHZ;
  1214. ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_5GHZ;
  1215. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_5GHZ;
  1216. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9300_5GHZ;
  1217. if (AR_SREV_9330(ah))
  1218. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9330_2GHZ;
  1219. if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
  1220. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9462_2GHZ;
  1221. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9462_2GHZ;
  1222. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9462_5GHZ;
  1223. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9462_5GHZ;
  1224. }
  1225. }
  1226. /*
  1227. * Initialize the ANI register values with default (ini) values.
  1228. * This routine is called during a (full) hardware reset after
  1229. * all the registers are initialised from the INI.
  1230. */
  1231. static void ar9003_hw_ani_cache_ini_regs(struct ath_hw *ah)
  1232. {
  1233. struct ar5416AniState *aniState;
  1234. struct ath_common *common = ath9k_hw_common(ah);
  1235. struct ath9k_channel *chan = ah->curchan;
  1236. struct ath9k_ani_default *iniDef;
  1237. u32 val;
  1238. aniState = &ah->ani;
  1239. iniDef = &aniState->iniDef;
  1240. ath_dbg(common, ANI, "ver %d.%d opmode %u chan %d Mhz\n",
  1241. ah->hw_version.macVersion,
  1242. ah->hw_version.macRev,
  1243. ah->opmode,
  1244. chan->channel);
  1245. val = REG_READ(ah, AR_PHY_SFCORR);
  1246. iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH);
  1247. iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH);
  1248. iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR);
  1249. val = REG_READ(ah, AR_PHY_SFCORR_LOW);
  1250. iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW);
  1251. iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW);
  1252. iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW);
  1253. val = REG_READ(ah, AR_PHY_SFCORR_EXT);
  1254. iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH);
  1255. iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH);
  1256. iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW);
  1257. iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW);
  1258. iniDef->firstep = REG_READ_FIELD(ah,
  1259. AR_PHY_FIND_SIG,
  1260. AR_PHY_FIND_SIG_FIRSTEP);
  1261. iniDef->firstepLow = REG_READ_FIELD(ah,
  1262. AR_PHY_FIND_SIG_LOW,
  1263. AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW);
  1264. iniDef->cycpwrThr1 = REG_READ_FIELD(ah,
  1265. AR_PHY_TIMING5,
  1266. AR_PHY_TIMING5_CYCPWR_THR1);
  1267. iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah,
  1268. AR_PHY_EXT_CCA,
  1269. AR_PHY_EXT_CYCPWR_THR1);
  1270. /* these levels just got reset to defaults by the INI */
  1271. aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL;
  1272. aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL;
  1273. aniState->ofdmWeakSigDetect = true;
  1274. aniState->mrcCCK = true;
  1275. }
  1276. static void ar9003_hw_set_radar_params(struct ath_hw *ah,
  1277. struct ath_hw_radar_conf *conf)
  1278. {
  1279. unsigned int regWrites = 0;
  1280. u32 radar_0 = 0, radar_1;
  1281. if (!conf) {
  1282. REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA);
  1283. return;
  1284. }
  1285. radar_0 |= AR_PHY_RADAR_0_ENA | AR_PHY_RADAR_0_FFT_ENA;
  1286. radar_0 |= SM(conf->fir_power, AR_PHY_RADAR_0_FIRPWR);
  1287. radar_0 |= SM(conf->radar_rssi, AR_PHY_RADAR_0_RRSSI);
  1288. radar_0 |= SM(conf->pulse_height, AR_PHY_RADAR_0_HEIGHT);
  1289. radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI);
  1290. radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND);
  1291. radar_1 = REG_READ(ah, AR_PHY_RADAR_1);
  1292. radar_1 &= ~(AR_PHY_RADAR_1_MAXLEN | AR_PHY_RADAR_1_RELSTEP_THRESH |
  1293. AR_PHY_RADAR_1_RELPWR_THRESH);
  1294. radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI;
  1295. radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK;
  1296. radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN);
  1297. radar_1 |= SM(conf->pulse_inband_step, AR_PHY_RADAR_1_RELSTEP_THRESH);
  1298. radar_1 |= SM(conf->radar_inband, AR_PHY_RADAR_1_RELPWR_THRESH);
  1299. REG_WRITE(ah, AR_PHY_RADAR_0, radar_0);
  1300. REG_WRITE(ah, AR_PHY_RADAR_1, radar_1);
  1301. if (conf->ext_channel)
  1302. REG_SET_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1303. else
  1304. REG_CLR_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1305. if (AR_SREV_9300(ah) || AR_SREV_9340(ah) || AR_SREV_9580(ah)) {
  1306. REG_WRITE_ARRAY(&ah->ini_dfs,
  1307. IS_CHAN_HT40(ah->curchan) ? 2 : 1, regWrites);
  1308. }
  1309. }
  1310. static void ar9003_hw_set_radar_conf(struct ath_hw *ah)
  1311. {
  1312. struct ath_hw_radar_conf *conf = &ah->radar_conf;
  1313. conf->fir_power = -28;
  1314. conf->radar_rssi = 0;
  1315. conf->pulse_height = 10;
  1316. conf->pulse_rssi = 15;
  1317. conf->pulse_inband = 8;
  1318. conf->pulse_maxlen = 255;
  1319. conf->pulse_inband_step = 12;
  1320. conf->radar_inband = 8;
  1321. }
  1322. static void ar9003_hw_antdiv_comb_conf_get(struct ath_hw *ah,
  1323. struct ath_hw_antcomb_conf *antconf)
  1324. {
  1325. u32 regval;
  1326. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1327. antconf->main_lna_conf = (regval & AR_PHY_ANT_DIV_MAIN_LNACONF) >>
  1328. AR_PHY_ANT_DIV_MAIN_LNACONF_S;
  1329. antconf->alt_lna_conf = (regval & AR_PHY_ANT_DIV_ALT_LNACONF) >>
  1330. AR_PHY_ANT_DIV_ALT_LNACONF_S;
  1331. antconf->fast_div_bias = (regval & AR_PHY_ANT_FAST_DIV_BIAS) >>
  1332. AR_PHY_ANT_FAST_DIV_BIAS_S;
  1333. if (AR_SREV_9330_11(ah)) {
  1334. antconf->lna1_lna2_switch_delta = -1;
  1335. antconf->lna1_lna2_delta = -9;
  1336. antconf->div_group = 1;
  1337. } else if (AR_SREV_9485(ah)) {
  1338. antconf->lna1_lna2_switch_delta = -1;
  1339. antconf->lna1_lna2_delta = -9;
  1340. antconf->div_group = 2;
  1341. } else if (AR_SREV_9565(ah)) {
  1342. antconf->lna1_lna2_switch_delta = 3;
  1343. antconf->lna1_lna2_delta = -9;
  1344. antconf->div_group = 3;
  1345. } else {
  1346. antconf->lna1_lna2_switch_delta = -1;
  1347. antconf->lna1_lna2_delta = -3;
  1348. antconf->div_group = 0;
  1349. }
  1350. }
  1351. static void ar9003_hw_antdiv_comb_conf_set(struct ath_hw *ah,
  1352. struct ath_hw_antcomb_conf *antconf)
  1353. {
  1354. u32 regval;
  1355. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1356. regval &= ~(AR_PHY_ANT_DIV_MAIN_LNACONF |
  1357. AR_PHY_ANT_DIV_ALT_LNACONF |
  1358. AR_PHY_ANT_FAST_DIV_BIAS |
  1359. AR_PHY_ANT_DIV_MAIN_GAINTB |
  1360. AR_PHY_ANT_DIV_ALT_GAINTB);
  1361. regval |= ((antconf->main_lna_conf << AR_PHY_ANT_DIV_MAIN_LNACONF_S)
  1362. & AR_PHY_ANT_DIV_MAIN_LNACONF);
  1363. regval |= ((antconf->alt_lna_conf << AR_PHY_ANT_DIV_ALT_LNACONF_S)
  1364. & AR_PHY_ANT_DIV_ALT_LNACONF);
  1365. regval |= ((antconf->fast_div_bias << AR_PHY_ANT_FAST_DIV_BIAS_S)
  1366. & AR_PHY_ANT_FAST_DIV_BIAS);
  1367. regval |= ((antconf->main_gaintb << AR_PHY_ANT_DIV_MAIN_GAINTB_S)
  1368. & AR_PHY_ANT_DIV_MAIN_GAINTB);
  1369. regval |= ((antconf->alt_gaintb << AR_PHY_ANT_DIV_ALT_GAINTB_S)
  1370. & AR_PHY_ANT_DIV_ALT_GAINTB);
  1371. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1372. }
  1373. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  1374. static void ar9003_hw_set_bt_ant_diversity(struct ath_hw *ah, bool enable)
  1375. {
  1376. struct ath9k_hw_capabilities *pCap = &ah->caps;
  1377. u8 ant_div_ctl1;
  1378. u32 regval;
  1379. if (!AR_SREV_9485(ah) && !AR_SREV_9565(ah))
  1380. return;
  1381. if (AR_SREV_9485(ah)) {
  1382. regval = ar9003_hw_ant_ctrl_common_2_get(ah,
  1383. IS_CHAN_2GHZ(ah->curchan));
  1384. if (enable) {
  1385. regval &= ~AR_SWITCH_TABLE_COM2_ALL;
  1386. regval |= ah->config.ant_ctrl_comm2g_switch_enable;
  1387. }
  1388. REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM_2,
  1389. AR_SWITCH_TABLE_COM2_ALL, regval);
  1390. }
  1391. ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
  1392. /*
  1393. * Set MAIN/ALT LNA conf.
  1394. * Set MAIN/ALT gain_tb.
  1395. */
  1396. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1397. regval &= (~AR_ANT_DIV_CTRL_ALL);
  1398. regval |= (ant_div_ctl1 & 0x3f) << AR_ANT_DIV_CTRL_ALL_S;
  1399. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1400. if (AR_SREV_9485_11_OR_LATER(ah)) {
  1401. /*
  1402. * Enable LNA diversity.
  1403. */
  1404. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1405. regval &= ~AR_PHY_ANT_DIV_LNADIV;
  1406. regval |= ((ant_div_ctl1 >> 6) & 0x1) << AR_PHY_ANT_DIV_LNADIV_S;
  1407. if (enable)
  1408. regval |= AR_ANT_DIV_ENABLE;
  1409. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1410. /*
  1411. * Enable fast antenna diversity.
  1412. */
  1413. regval = REG_READ(ah, AR_PHY_CCK_DETECT);
  1414. regval &= ~AR_FAST_DIV_ENABLE;
  1415. regval |= ((ant_div_ctl1 >> 7) & 0x1) << AR_FAST_DIV_ENABLE_S;
  1416. if (enable)
  1417. regval |= AR_FAST_DIV_ENABLE;
  1418. REG_WRITE(ah, AR_PHY_CCK_DETECT, regval);
  1419. if (pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) {
  1420. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1421. regval &= (~(AR_PHY_ANT_DIV_MAIN_LNACONF |
  1422. AR_PHY_ANT_DIV_ALT_LNACONF |
  1423. AR_PHY_ANT_DIV_ALT_GAINTB |
  1424. AR_PHY_ANT_DIV_MAIN_GAINTB));
  1425. /*
  1426. * Set MAIN to LNA1 and ALT to LNA2 at the
  1427. * beginning.
  1428. */
  1429. regval |= (ATH_ANT_DIV_COMB_LNA1 <<
  1430. AR_PHY_ANT_DIV_MAIN_LNACONF_S);
  1431. regval |= (ATH_ANT_DIV_COMB_LNA2 <<
  1432. AR_PHY_ANT_DIV_ALT_LNACONF_S);
  1433. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1434. }
  1435. } else if (AR_SREV_9565(ah)) {
  1436. if (enable) {
  1437. REG_SET_BIT(ah, AR_PHY_MC_GAIN_CTRL,
  1438. AR_ANT_DIV_ENABLE);
  1439. REG_SET_BIT(ah, AR_PHY_MC_GAIN_CTRL,
  1440. (1 << AR_PHY_ANT_SW_RX_PROT_S));
  1441. REG_SET_BIT(ah, AR_PHY_CCK_DETECT,
  1442. AR_FAST_DIV_ENABLE);
  1443. REG_SET_BIT(ah, AR_PHY_RESTART,
  1444. AR_PHY_RESTART_ENABLE_DIV_M2FLAG);
  1445. REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV,
  1446. AR_BTCOEX_WL_LNADIV_FORCE_ON);
  1447. } else {
  1448. REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL,
  1449. AR_ANT_DIV_ENABLE);
  1450. REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL,
  1451. (1 << AR_PHY_ANT_SW_RX_PROT_S));
  1452. REG_CLR_BIT(ah, AR_PHY_CCK_DETECT,
  1453. AR_FAST_DIV_ENABLE);
  1454. REG_CLR_BIT(ah, AR_PHY_RESTART,
  1455. AR_PHY_RESTART_ENABLE_DIV_M2FLAG);
  1456. REG_CLR_BIT(ah, AR_BTCOEX_WL_LNADIV,
  1457. AR_BTCOEX_WL_LNADIV_FORCE_ON);
  1458. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1459. regval &= ~(AR_PHY_ANT_DIV_MAIN_LNACONF |
  1460. AR_PHY_ANT_DIV_ALT_LNACONF |
  1461. AR_PHY_ANT_DIV_MAIN_GAINTB |
  1462. AR_PHY_ANT_DIV_ALT_GAINTB);
  1463. regval |= (ATH_ANT_DIV_COMB_LNA1 <<
  1464. AR_PHY_ANT_DIV_MAIN_LNACONF_S);
  1465. regval |= (ATH_ANT_DIV_COMB_LNA2 <<
  1466. AR_PHY_ANT_DIV_ALT_LNACONF_S);
  1467. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1468. }
  1469. }
  1470. }
  1471. #endif
  1472. static int ar9003_hw_fast_chan_change(struct ath_hw *ah,
  1473. struct ath9k_channel *chan,
  1474. u8 *ini_reloaded)
  1475. {
  1476. unsigned int regWrites = 0;
  1477. u32 modesIndex, txgain_index;
  1478. if (IS_CHAN_5GHZ(chan))
  1479. modesIndex = IS_CHAN_HT40(chan) ? 2 : 1;
  1480. else
  1481. modesIndex = IS_CHAN_HT40(chan) ? 3 : 4;
  1482. txgain_index = AR_SREV_9531(ah) ? 1 : modesIndex;
  1483. if (modesIndex == ah->modes_index) {
  1484. *ini_reloaded = false;
  1485. goto set_rfmode;
  1486. }
  1487. ar9003_hw_prog_ini(ah, &ah->iniSOC[ATH_INI_POST], modesIndex);
  1488. ar9003_hw_prog_ini(ah, &ah->iniMac[ATH_INI_POST], modesIndex);
  1489. ar9003_hw_prog_ini(ah, &ah->iniBB[ATH_INI_POST], modesIndex);
  1490. ar9003_hw_prog_ini(ah, &ah->iniRadio[ATH_INI_POST], modesIndex);
  1491. if (AR_SREV_9462_20_OR_LATER(ah))
  1492. ar9003_hw_prog_ini(ah, &ah->ini_radio_post_sys2ant,
  1493. modesIndex);
  1494. REG_WRITE_ARRAY(&ah->iniModesTxGain, txgain_index, regWrites);
  1495. if (AR_SREV_9462_20_OR_LATER(ah)) {
  1496. /*
  1497. * CUS217 mix LNA mode.
  1498. */
  1499. if (ar9003_hw_get_rx_gain_idx(ah) == 2) {
  1500. REG_WRITE_ARRAY(&ah->ini_modes_rxgain_bb_core,
  1501. 1, regWrites);
  1502. REG_WRITE_ARRAY(&ah->ini_modes_rxgain_bb_postamble,
  1503. modesIndex, regWrites);
  1504. }
  1505. }
  1506. /*
  1507. * For 5GHz channels requiring Fast Clock, apply
  1508. * different modal values.
  1509. */
  1510. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  1511. REG_WRITE_ARRAY(&ah->iniModesFastClock, modesIndex, regWrites);
  1512. if (AR_SREV_9565(ah))
  1513. REG_WRITE_ARRAY(&ah->iniModesFastClock, 1, regWrites);
  1514. /*
  1515. * JAPAN regulatory.
  1516. */
  1517. if (chan->channel == 2484)
  1518. ar9003_hw_prog_ini(ah, &ah->iniCckfirJapan2484, 1);
  1519. ah->modes_index = modesIndex;
  1520. *ini_reloaded = true;
  1521. set_rfmode:
  1522. ar9003_hw_set_rfmode(ah, chan);
  1523. return 0;
  1524. }
  1525. static void ar9003_hw_spectral_scan_config(struct ath_hw *ah,
  1526. struct ath_spec_scan *param)
  1527. {
  1528. u8 count;
  1529. if (!param->enabled) {
  1530. REG_CLR_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  1531. AR_PHY_SPECTRAL_SCAN_ENABLE);
  1532. return;
  1533. }
  1534. REG_SET_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_FFT_ENA);
  1535. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN, AR_PHY_SPECTRAL_SCAN_ENABLE);
  1536. /* on AR93xx and newer, count = 0 will make the the chip send
  1537. * spectral samples endlessly. Check if this really was intended,
  1538. * and fix otherwise.
  1539. */
  1540. count = param->count;
  1541. if (param->endless)
  1542. count = 0;
  1543. else if (param->count == 0)
  1544. count = 1;
  1545. if (param->short_repeat)
  1546. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  1547. AR_PHY_SPECTRAL_SCAN_SHORT_REPEAT);
  1548. else
  1549. REG_CLR_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  1550. AR_PHY_SPECTRAL_SCAN_SHORT_REPEAT);
  1551. REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN,
  1552. AR_PHY_SPECTRAL_SCAN_COUNT, count);
  1553. REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN,
  1554. AR_PHY_SPECTRAL_SCAN_PERIOD, param->period);
  1555. REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN,
  1556. AR_PHY_SPECTRAL_SCAN_FFT_PERIOD, param->fft_period);
  1557. return;
  1558. }
  1559. static void ar9003_hw_spectral_scan_trigger(struct ath_hw *ah)
  1560. {
  1561. /* Activate spectral scan */
  1562. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  1563. AR_PHY_SPECTRAL_SCAN_ACTIVE);
  1564. }
  1565. static void ar9003_hw_spectral_scan_wait(struct ath_hw *ah)
  1566. {
  1567. struct ath_common *common = ath9k_hw_common(ah);
  1568. /* Poll for spectral scan complete */
  1569. if (!ath9k_hw_wait(ah, AR_PHY_SPECTRAL_SCAN,
  1570. AR_PHY_SPECTRAL_SCAN_ACTIVE,
  1571. 0, AH_WAIT_TIMEOUT)) {
  1572. ath_err(common, "spectral scan wait failed\n");
  1573. return;
  1574. }
  1575. }
  1576. static void ar9003_hw_tx99_start(struct ath_hw *ah, u32 qnum)
  1577. {
  1578. REG_SET_BIT(ah, AR_PHY_TEST, PHY_AGC_CLR);
  1579. REG_SET_BIT(ah, 0x9864, 0x7f000);
  1580. REG_SET_BIT(ah, 0x9924, 0x7f00fe);
  1581. REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
  1582. REG_WRITE(ah, AR_CR, AR_CR_RXD);
  1583. REG_WRITE(ah, AR_DLCL_IFS(qnum), 0);
  1584. REG_WRITE(ah, AR_D_GBL_IFS_SIFS, 20); /* 50 OK */
  1585. REG_WRITE(ah, AR_D_GBL_IFS_EIFS, 20);
  1586. REG_WRITE(ah, AR_TIME_OUT, 0x00000400);
  1587. REG_WRITE(ah, AR_DRETRY_LIMIT(qnum), 0xffffffff);
  1588. REG_SET_BIT(ah, AR_QMISC(qnum), AR_Q_MISC_DCU_EARLY_TERM_REQ);
  1589. }
  1590. static void ar9003_hw_tx99_stop(struct ath_hw *ah)
  1591. {
  1592. REG_CLR_BIT(ah, AR_PHY_TEST, PHY_AGC_CLR);
  1593. REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
  1594. }
  1595. static void ar9003_hw_tx99_set_txpower(struct ath_hw *ah, u8 txpower)
  1596. {
  1597. static u8 p_pwr_array[ar9300RateSize] = { 0 };
  1598. unsigned int i;
  1599. txpower = txpower <= MAX_RATE_POWER ? txpower : MAX_RATE_POWER;
  1600. for (i = 0; i < ar9300RateSize; i++)
  1601. p_pwr_array[i] = txpower;
  1602. ar9003_hw_tx_power_regwrite(ah, p_pwr_array);
  1603. }
  1604. static void ar9003_hw_init_txpower_cck(struct ath_hw *ah, u8 *rate_array)
  1605. {
  1606. ah->tx_power[0] = rate_array[ALL_TARGET_LEGACY_1L_5L];
  1607. ah->tx_power[1] = rate_array[ALL_TARGET_LEGACY_1L_5L];
  1608. ah->tx_power[2] = min(rate_array[ALL_TARGET_LEGACY_1L_5L],
  1609. rate_array[ALL_TARGET_LEGACY_5S]);
  1610. ah->tx_power[3] = min(rate_array[ALL_TARGET_LEGACY_11L],
  1611. rate_array[ALL_TARGET_LEGACY_11S]);
  1612. }
  1613. static void ar9003_hw_init_txpower_ofdm(struct ath_hw *ah, u8 *rate_array,
  1614. int offset)
  1615. {
  1616. int i, j;
  1617. for (i = offset; i < offset + AR9300_OFDM_RATES; i++) {
  1618. /* OFDM rate to power table idx */
  1619. j = ofdm2pwr[i - offset];
  1620. ah->tx_power[i] = rate_array[j];
  1621. }
  1622. }
  1623. static void ar9003_hw_init_txpower_ht(struct ath_hw *ah, u8 *rate_array,
  1624. int ss_offset, int ds_offset,
  1625. int ts_offset, bool is_40)
  1626. {
  1627. int i, j, mcs_idx = 0;
  1628. const u8 *mcs2pwr = (is_40) ? mcs2pwr_ht40 : mcs2pwr_ht20;
  1629. for (i = ss_offset; i < ss_offset + AR9300_HT_SS_RATES; i++) {
  1630. j = mcs2pwr[mcs_idx];
  1631. ah->tx_power[i] = rate_array[j];
  1632. mcs_idx++;
  1633. }
  1634. for (i = ds_offset; i < ds_offset + AR9300_HT_DS_RATES; i++) {
  1635. j = mcs2pwr[mcs_idx];
  1636. ah->tx_power[i] = rate_array[j];
  1637. mcs_idx++;
  1638. }
  1639. for (i = ts_offset; i < ts_offset + AR9300_HT_TS_RATES; i++) {
  1640. j = mcs2pwr[mcs_idx];
  1641. ah->tx_power[i] = rate_array[j];
  1642. mcs_idx++;
  1643. }
  1644. }
  1645. static void ar9003_hw_init_txpower_stbc(struct ath_hw *ah, int ss_offset,
  1646. int ds_offset, int ts_offset)
  1647. {
  1648. memcpy(&ah->tx_power_stbc[ss_offset], &ah->tx_power[ss_offset],
  1649. AR9300_HT_SS_RATES);
  1650. memcpy(&ah->tx_power_stbc[ds_offset], &ah->tx_power[ds_offset],
  1651. AR9300_HT_DS_RATES);
  1652. memcpy(&ah->tx_power_stbc[ts_offset], &ah->tx_power[ts_offset],
  1653. AR9300_HT_TS_RATES);
  1654. }
  1655. void ar9003_hw_init_rate_txpower(struct ath_hw *ah, u8 *rate_array,
  1656. struct ath9k_channel *chan)
  1657. {
  1658. if (IS_CHAN_5GHZ(chan)) {
  1659. ar9003_hw_init_txpower_ofdm(ah, rate_array,
  1660. AR9300_11NA_OFDM_SHIFT);
  1661. if (IS_CHAN_HT20(chan) || IS_CHAN_HT40(chan)) {
  1662. ar9003_hw_init_txpower_ht(ah, rate_array,
  1663. AR9300_11NA_HT_SS_SHIFT,
  1664. AR9300_11NA_HT_DS_SHIFT,
  1665. AR9300_11NA_HT_TS_SHIFT,
  1666. IS_CHAN_HT40(chan));
  1667. ar9003_hw_init_txpower_stbc(ah,
  1668. AR9300_11NA_HT_SS_SHIFT,
  1669. AR9300_11NA_HT_DS_SHIFT,
  1670. AR9300_11NA_HT_TS_SHIFT);
  1671. }
  1672. } else {
  1673. ar9003_hw_init_txpower_cck(ah, rate_array);
  1674. ar9003_hw_init_txpower_ofdm(ah, rate_array,
  1675. AR9300_11NG_OFDM_SHIFT);
  1676. if (IS_CHAN_HT20(chan) || IS_CHAN_HT40(chan)) {
  1677. ar9003_hw_init_txpower_ht(ah, rate_array,
  1678. AR9300_11NG_HT_SS_SHIFT,
  1679. AR9300_11NG_HT_DS_SHIFT,
  1680. AR9300_11NG_HT_TS_SHIFT,
  1681. IS_CHAN_HT40(chan));
  1682. ar9003_hw_init_txpower_stbc(ah,
  1683. AR9300_11NG_HT_SS_SHIFT,
  1684. AR9300_11NG_HT_DS_SHIFT,
  1685. AR9300_11NG_HT_TS_SHIFT);
  1686. }
  1687. }
  1688. }
  1689. void ar9003_hw_attach_phy_ops(struct ath_hw *ah)
  1690. {
  1691. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  1692. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  1693. static const u32 ar9300_cca_regs[6] = {
  1694. AR_PHY_CCA_0,
  1695. AR_PHY_CCA_1,
  1696. AR_PHY_CCA_2,
  1697. AR_PHY_EXT_CCA,
  1698. AR_PHY_EXT_CCA_1,
  1699. AR_PHY_EXT_CCA_2,
  1700. };
  1701. priv_ops->rf_set_freq = ar9003_hw_set_channel;
  1702. priv_ops->spur_mitigate_freq = ar9003_hw_spur_mitigate;
  1703. if (AR_SREV_9340(ah) || AR_SREV_9550(ah) || AR_SREV_9531(ah) ||
  1704. AR_SREV_9561(ah))
  1705. priv_ops->compute_pll_control = ar9003_hw_compute_pll_control_soc;
  1706. else
  1707. priv_ops->compute_pll_control = ar9003_hw_compute_pll_control;
  1708. priv_ops->set_channel_regs = ar9003_hw_set_channel_regs;
  1709. priv_ops->init_bb = ar9003_hw_init_bb;
  1710. priv_ops->process_ini = ar9003_hw_process_ini;
  1711. priv_ops->set_rfmode = ar9003_hw_set_rfmode;
  1712. priv_ops->mark_phy_inactive = ar9003_hw_mark_phy_inactive;
  1713. priv_ops->set_delta_slope = ar9003_hw_set_delta_slope;
  1714. priv_ops->rfbus_req = ar9003_hw_rfbus_req;
  1715. priv_ops->rfbus_done = ar9003_hw_rfbus_done;
  1716. priv_ops->ani_control = ar9003_hw_ani_control;
  1717. priv_ops->do_getnf = ar9003_hw_do_getnf;
  1718. priv_ops->ani_cache_ini_regs = ar9003_hw_ani_cache_ini_regs;
  1719. priv_ops->set_radar_params = ar9003_hw_set_radar_params;
  1720. priv_ops->fast_chan_change = ar9003_hw_fast_chan_change;
  1721. ops->antdiv_comb_conf_get = ar9003_hw_antdiv_comb_conf_get;
  1722. ops->antdiv_comb_conf_set = ar9003_hw_antdiv_comb_conf_set;
  1723. ops->spectral_scan_config = ar9003_hw_spectral_scan_config;
  1724. ops->spectral_scan_trigger = ar9003_hw_spectral_scan_trigger;
  1725. ops->spectral_scan_wait = ar9003_hw_spectral_scan_wait;
  1726. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  1727. ops->set_bt_ant_diversity = ar9003_hw_set_bt_ant_diversity;
  1728. #endif
  1729. ops->tx99_start = ar9003_hw_tx99_start;
  1730. ops->tx99_stop = ar9003_hw_tx99_stop;
  1731. ops->tx99_set_txpower = ar9003_hw_tx99_set_txpower;
  1732. ar9003_hw_set_nf_limits(ah);
  1733. ar9003_hw_set_radar_conf(ah);
  1734. memcpy(ah->nf_regs, ar9300_cca_regs, sizeof(ah->nf_regs));
  1735. }
  1736. /*
  1737. * Baseband Watchdog signatures:
  1738. *
  1739. * 0x04000539: BB hang when operating in HT40 DFS Channel.
  1740. * Full chip reset is not required, but a recovery
  1741. * mechanism is needed.
  1742. *
  1743. * 0x1300000a: Related to CAC deafness.
  1744. * Chip reset is not required.
  1745. *
  1746. * 0x0400000a: Related to CAC deafness.
  1747. * Full chip reset is required.
  1748. *
  1749. * 0x04000b09: RX state machine gets into an illegal state
  1750. * when a packet with unsupported rate is received.
  1751. * Full chip reset is required and PHY_RESTART has
  1752. * to be disabled.
  1753. *
  1754. * 0x04000409: Packet stuck on receive.
  1755. * Full chip reset is required for all chips except
  1756. * AR9340, AR9531 and AR9561.
  1757. */
  1758. /*
  1759. * ar9003_hw_bb_watchdog_check(): Returns true if a chip reset is required.
  1760. */
  1761. bool ar9003_hw_bb_watchdog_check(struct ath_hw *ah)
  1762. {
  1763. u32 val;
  1764. switch(ah->bb_watchdog_last_status) {
  1765. case 0x04000539:
  1766. val = REG_READ(ah, AR_PHY_RADAR_0);
  1767. val &= (~AR_PHY_RADAR_0_FIRPWR);
  1768. val |= SM(0x7f, AR_PHY_RADAR_0_FIRPWR);
  1769. REG_WRITE(ah, AR_PHY_RADAR_0, val);
  1770. udelay(1);
  1771. val = REG_READ(ah, AR_PHY_RADAR_0);
  1772. val &= ~AR_PHY_RADAR_0_FIRPWR;
  1773. val |= SM(AR9300_DFS_FIRPWR, AR_PHY_RADAR_0_FIRPWR);
  1774. REG_WRITE(ah, AR_PHY_RADAR_0, val);
  1775. return false;
  1776. case 0x1300000a:
  1777. return false;
  1778. case 0x0400000a:
  1779. case 0x04000b09:
  1780. return true;
  1781. case 0x04000409:
  1782. if (AR_SREV_9340(ah) || AR_SREV_9531(ah) || AR_SREV_9561(ah))
  1783. return false;
  1784. else
  1785. return true;
  1786. default:
  1787. /*
  1788. * For any other unknown signatures, do a
  1789. * full chip reset.
  1790. */
  1791. return true;
  1792. }
  1793. }
  1794. EXPORT_SYMBOL(ar9003_hw_bb_watchdog_check);
  1795. void ar9003_hw_bb_watchdog_config(struct ath_hw *ah)
  1796. {
  1797. struct ath_common *common = ath9k_hw_common(ah);
  1798. u32 idle_tmo_ms = ah->bb_watchdog_timeout_ms;
  1799. u32 val, idle_count;
  1800. if (!idle_tmo_ms) {
  1801. /* disable IRQ, disable chip-reset for BB panic */
  1802. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
  1803. REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) &
  1804. ~(AR_PHY_WATCHDOG_RST_ENABLE |
  1805. AR_PHY_WATCHDOG_IRQ_ENABLE));
  1806. /* disable watchdog in non-IDLE mode, disable in IDLE mode */
  1807. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
  1808. REG_READ(ah, AR_PHY_WATCHDOG_CTL_1) &
  1809. ~(AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
  1810. AR_PHY_WATCHDOG_IDLE_ENABLE));
  1811. ath_dbg(common, RESET, "Disabled BB Watchdog\n");
  1812. return;
  1813. }
  1814. /* enable IRQ, disable chip-reset for BB watchdog */
  1815. val = REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) & AR_PHY_WATCHDOG_CNTL2_MASK;
  1816. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
  1817. (val | AR_PHY_WATCHDOG_IRQ_ENABLE) &
  1818. ~AR_PHY_WATCHDOG_RST_ENABLE);
  1819. /* bound limit to 10 secs */
  1820. if (idle_tmo_ms > 10000)
  1821. idle_tmo_ms = 10000;
  1822. /*
  1823. * The time unit for watchdog event is 2^15 44/88MHz cycles.
  1824. *
  1825. * For HT20 we have a time unit of 2^15/44 MHz = .74 ms per tick
  1826. * For HT40 we have a time unit of 2^15/88 MHz = .37 ms per tick
  1827. *
  1828. * Given we use fast clock now in 5 GHz, these time units should
  1829. * be common for both 2 GHz and 5 GHz.
  1830. */
  1831. idle_count = (100 * idle_tmo_ms) / 74;
  1832. if (ah->curchan && IS_CHAN_HT40(ah->curchan))
  1833. idle_count = (100 * idle_tmo_ms) / 37;
  1834. /*
  1835. * enable watchdog in non-IDLE mode, disable in IDLE mode,
  1836. * set idle time-out.
  1837. */
  1838. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
  1839. AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
  1840. AR_PHY_WATCHDOG_IDLE_MASK |
  1841. (AR_PHY_WATCHDOG_NON_IDLE_MASK & (idle_count << 2)));
  1842. ath_dbg(common, RESET, "Enabled BB Watchdog timeout (%u ms)\n",
  1843. idle_tmo_ms);
  1844. }
  1845. void ar9003_hw_bb_watchdog_read(struct ath_hw *ah)
  1846. {
  1847. /*
  1848. * we want to avoid printing in ISR context so we save the
  1849. * watchdog status to be printed later in bottom half context.
  1850. */
  1851. ah->bb_watchdog_last_status = REG_READ(ah, AR_PHY_WATCHDOG_STATUS);
  1852. /*
  1853. * the watchdog timer should reset on status read but to be sure
  1854. * sure we write 0 to the watchdog status bit.
  1855. */
  1856. REG_WRITE(ah, AR_PHY_WATCHDOG_STATUS,
  1857. ah->bb_watchdog_last_status & ~AR_PHY_WATCHDOG_STATUS_CLR);
  1858. }
  1859. void ar9003_hw_bb_watchdog_dbg_info(struct ath_hw *ah)
  1860. {
  1861. struct ath_common *common = ath9k_hw_common(ah);
  1862. u32 status;
  1863. if (likely(!(common->debug_mask & ATH_DBG_RESET)))
  1864. return;
  1865. status = ah->bb_watchdog_last_status;
  1866. ath_dbg(common, RESET,
  1867. "\n==== BB update: BB status=0x%08x ====\n", status);
  1868. ath_dbg(common, RESET,
  1869. "** BB state: wd=%u det=%u rdar=%u rOFDM=%d rCCK=%u tOFDM=%u tCCK=%u agc=%u src=%u **\n",
  1870. MS(status, AR_PHY_WATCHDOG_INFO),
  1871. MS(status, AR_PHY_WATCHDOG_DET_HANG),
  1872. MS(status, AR_PHY_WATCHDOG_RADAR_SM),
  1873. MS(status, AR_PHY_WATCHDOG_RX_OFDM_SM),
  1874. MS(status, AR_PHY_WATCHDOG_RX_CCK_SM),
  1875. MS(status, AR_PHY_WATCHDOG_TX_OFDM_SM),
  1876. MS(status, AR_PHY_WATCHDOG_TX_CCK_SM),
  1877. MS(status, AR_PHY_WATCHDOG_AGC_SM),
  1878. MS(status, AR_PHY_WATCHDOG_SRCH_SM));
  1879. ath_dbg(common, RESET, "** BB WD cntl: cntl1=0x%08x cntl2=0x%08x **\n",
  1880. REG_READ(ah, AR_PHY_WATCHDOG_CTL_1),
  1881. REG_READ(ah, AR_PHY_WATCHDOG_CTL_2));
  1882. ath_dbg(common, RESET, "** BB mode: BB_gen_controls=0x%08x **\n",
  1883. REG_READ(ah, AR_PHY_GEN_CTRL));
  1884. #define PCT(_field) (common->cc_survey._field * 100 / common->cc_survey.cycles)
  1885. if (common->cc_survey.cycles)
  1886. ath_dbg(common, RESET,
  1887. "** BB busy times: rx_clear=%d%%, rx_frame=%d%%, tx_frame=%d%% **\n",
  1888. PCT(rx_busy), PCT(rx_frame), PCT(tx_frame));
  1889. ath_dbg(common, RESET, "==== BB update: done ====\n\n");
  1890. }
  1891. EXPORT_SYMBOL(ar9003_hw_bb_watchdog_dbg_info);
  1892. void ar9003_hw_disable_phy_restart(struct ath_hw *ah)
  1893. {
  1894. u8 result;
  1895. u32 val;
  1896. /* While receiving unsupported rate frame rx state machine
  1897. * gets into a state 0xb and if phy_restart happens in that
  1898. * state, BB would go hang. If RXSM is in 0xb state after
  1899. * first bb panic, ensure to disable the phy_restart.
  1900. */
  1901. result = MS(ah->bb_watchdog_last_status, AR_PHY_WATCHDOG_RX_OFDM_SM);
  1902. if ((result == 0xb) || ah->bb_hang_rx_ofdm) {
  1903. ah->bb_hang_rx_ofdm = true;
  1904. val = REG_READ(ah, AR_PHY_RESTART);
  1905. val &= ~AR_PHY_RESTART_ENA;
  1906. REG_WRITE(ah, AR_PHY_RESTART, val);
  1907. }
  1908. }
  1909. EXPORT_SYMBOL(ar9003_hw_disable_phy_restart);