ar9003_phy.c 59 KB

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