ar9003_phy.c 61 KB

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