ar9003_phy.c 65 KB

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