ar9003_phy.c 57 KB

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