ar9003_phy.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680
  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 (REG_READ_FIELD(ah, AR_PHY_MODE,
  304. AR_PHY_MODE_DYNAMIC) == 0x1)
  305. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  306. AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 1);
  307. mask_index = (freq_offset << 4) / 5;
  308. if (mask_index < 0)
  309. mask_index = mask_index - 1;
  310. mask_index = mask_index & 0x7f;
  311. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  312. AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0x1);
  313. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  314. AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0x1);
  315. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  316. AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0x1);
  317. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  318. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, mask_index);
  319. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  320. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, mask_index);
  321. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  322. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, mask_index);
  323. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  324. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0xc);
  325. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  326. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0xc);
  327. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  328. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0xa0);
  329. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  330. AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0xff);
  331. }
  332. static void ar9003_hw_spur_ofdm_9565(struct ath_hw *ah,
  333. int freq_offset)
  334. {
  335. int mask_index = 0;
  336. mask_index = (freq_offset << 4) / 5;
  337. if (mask_index < 0)
  338. mask_index = mask_index - 1;
  339. mask_index = mask_index & 0x7f;
  340. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  341. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_B,
  342. mask_index);
  343. /* A == B */
  344. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_B,
  345. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A,
  346. mask_index);
  347. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  348. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_B,
  349. mask_index);
  350. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  351. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_B, 0xe);
  352. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  353. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_B, 0xe);
  354. /* A == B */
  355. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_B,
  356. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0xa0);
  357. }
  358. static void ar9003_hw_spur_ofdm_work(struct ath_hw *ah,
  359. struct ath9k_channel *chan,
  360. int freq_offset,
  361. int range,
  362. int synth_freq)
  363. {
  364. int spur_freq_sd = 0;
  365. int spur_subchannel_sd = 0;
  366. int spur_delta_phase = 0;
  367. if (IS_CHAN_HT40(chan)) {
  368. if (freq_offset < 0) {
  369. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  370. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  371. spur_subchannel_sd = 1;
  372. else
  373. spur_subchannel_sd = 0;
  374. spur_freq_sd = ((freq_offset + 10) << 9) / 11;
  375. } else {
  376. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  377. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  378. spur_subchannel_sd = 0;
  379. else
  380. spur_subchannel_sd = 1;
  381. spur_freq_sd = ((freq_offset - 10) << 9) / 11;
  382. }
  383. spur_delta_phase = (freq_offset << 17) / 5;
  384. } else {
  385. spur_subchannel_sd = 0;
  386. spur_freq_sd = (freq_offset << 9) /11;
  387. spur_delta_phase = (freq_offset << 18) / 5;
  388. }
  389. spur_freq_sd = spur_freq_sd & 0x3ff;
  390. spur_delta_phase = spur_delta_phase & 0xfffff;
  391. ar9003_hw_spur_ofdm(ah,
  392. freq_offset,
  393. spur_freq_sd,
  394. spur_delta_phase,
  395. spur_subchannel_sd,
  396. range, synth_freq);
  397. }
  398. /* Spur mitigation for OFDM */
  399. static void ar9003_hw_spur_mitigate_ofdm(struct ath_hw *ah,
  400. struct ath9k_channel *chan)
  401. {
  402. int synth_freq;
  403. int range = 10;
  404. int freq_offset = 0;
  405. int mode;
  406. u8* spurChansPtr;
  407. unsigned int i;
  408. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  409. if (IS_CHAN_5GHZ(chan)) {
  410. spurChansPtr = &(eep->modalHeader5G.spurChans[0]);
  411. mode = 0;
  412. }
  413. else {
  414. spurChansPtr = &(eep->modalHeader2G.spurChans[0]);
  415. mode = 1;
  416. }
  417. if (spurChansPtr[0] == 0)
  418. return; /* No spur in the mode */
  419. if (IS_CHAN_HT40(chan)) {
  420. range = 19;
  421. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  422. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  423. synth_freq = chan->channel - 10;
  424. else
  425. synth_freq = chan->channel + 10;
  426. } else {
  427. range = 10;
  428. synth_freq = chan->channel;
  429. }
  430. ar9003_hw_spur_ofdm_clear(ah);
  431. for (i = 0; i < AR_EEPROM_MODAL_SPURS && spurChansPtr[i]; i++) {
  432. freq_offset = ath9k_hw_fbin2freq(spurChansPtr[i], mode);
  433. freq_offset -= synth_freq;
  434. if (abs(freq_offset) < range) {
  435. ar9003_hw_spur_ofdm_work(ah, chan, freq_offset,
  436. range, synth_freq);
  437. if (AR_SREV_9565(ah) && (i < 4)) {
  438. freq_offset = ath9k_hw_fbin2freq(spurChansPtr[i + 1],
  439. mode);
  440. freq_offset -= synth_freq;
  441. if (abs(freq_offset) < range)
  442. ar9003_hw_spur_ofdm_9565(ah, freq_offset);
  443. }
  444. break;
  445. }
  446. }
  447. }
  448. static void ar9003_hw_spur_mitigate(struct ath_hw *ah,
  449. struct ath9k_channel *chan)
  450. {
  451. if (!AR_SREV_9565(ah))
  452. ar9003_hw_spur_mitigate_mrc_cck(ah, chan);
  453. ar9003_hw_spur_mitigate_ofdm(ah, chan);
  454. }
  455. static u32 ar9003_hw_compute_pll_control(struct ath_hw *ah,
  456. struct ath9k_channel *chan)
  457. {
  458. u32 pll;
  459. pll = SM(0x5, AR_RTC_9300_PLL_REFDIV);
  460. if (chan && IS_CHAN_HALF_RATE(chan))
  461. pll |= SM(0x1, AR_RTC_9300_PLL_CLKSEL);
  462. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  463. pll |= SM(0x2, AR_RTC_9300_PLL_CLKSEL);
  464. pll |= SM(0x2c, AR_RTC_9300_PLL_DIV);
  465. return pll;
  466. }
  467. static void ar9003_hw_set_channel_regs(struct ath_hw *ah,
  468. struct ath9k_channel *chan)
  469. {
  470. u32 phymode;
  471. u32 enableDacFifo = 0;
  472. enableDacFifo =
  473. (REG_READ(ah, AR_PHY_GEN_CTRL) & AR_PHY_GC_ENABLE_DAC_FIFO);
  474. /* Enable 11n HT, 20 MHz */
  475. phymode = AR_PHY_GC_HT_EN | AR_PHY_GC_SINGLE_HT_LTF1 |
  476. AR_PHY_GC_SHORT_GI_40 | enableDacFifo;
  477. /* Configure baseband for dynamic 20/40 operation */
  478. if (IS_CHAN_HT40(chan)) {
  479. phymode |= AR_PHY_GC_DYN2040_EN;
  480. /* Configure control (primary) channel at +-10MHz */
  481. if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
  482. (chan->chanmode == CHANNEL_G_HT40PLUS))
  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);
  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. REG_WRITE(ah, AR_PCU_MISC_MODE2,
  543. val | AR_AGG_WEP_ENABLE_FIX | AR_AGG_WEP_ENABLE);
  544. REG_SET_BIT(ah, AR_PHY_CCK_DETECT,
  545. AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
  546. }
  547. static void ar9003_hw_prog_ini(struct ath_hw *ah,
  548. struct ar5416IniArray *iniArr,
  549. int column)
  550. {
  551. unsigned int i, regWrites = 0;
  552. /* New INI format: Array may be undefined (pre, core, post arrays) */
  553. if (!iniArr->ia_array)
  554. return;
  555. /*
  556. * New INI format: Pre, core, and post arrays for a given subsystem
  557. * may be modal (> 2 columns) or non-modal (2 columns). Determine if
  558. * the array is non-modal and force the column to 1.
  559. */
  560. if (column >= iniArr->ia_columns)
  561. column = 1;
  562. for (i = 0; i < iniArr->ia_rows; i++) {
  563. u32 reg = INI_RA(iniArr, i, 0);
  564. u32 val = INI_RA(iniArr, i, column);
  565. REG_WRITE(ah, reg, val);
  566. DO_DELAY(regWrites);
  567. }
  568. }
  569. static int ar9550_hw_get_modes_txgain_index(struct ath_hw *ah,
  570. struct ath9k_channel *chan)
  571. {
  572. int ret;
  573. switch (chan->chanmode) {
  574. case CHANNEL_A:
  575. case CHANNEL_A_HT20:
  576. if (chan->channel <= 5350)
  577. ret = 1;
  578. else if ((chan->channel > 5350) && (chan->channel <= 5600))
  579. ret = 3;
  580. else
  581. ret = 5;
  582. break;
  583. case CHANNEL_A_HT40PLUS:
  584. case CHANNEL_A_HT40MINUS:
  585. if (chan->channel <= 5350)
  586. ret = 2;
  587. else if ((chan->channel > 5350) && (chan->channel <= 5600))
  588. ret = 4;
  589. else
  590. ret = 6;
  591. break;
  592. case CHANNEL_G:
  593. case CHANNEL_G_HT20:
  594. case CHANNEL_B:
  595. ret = 8;
  596. break;
  597. case CHANNEL_G_HT40PLUS:
  598. case CHANNEL_G_HT40MINUS:
  599. ret = 7;
  600. break;
  601. default:
  602. ret = -EINVAL;
  603. }
  604. return ret;
  605. }
  606. static int ar9003_hw_process_ini(struct ath_hw *ah,
  607. struct ath9k_channel *chan)
  608. {
  609. unsigned int regWrites = 0, i;
  610. u32 modesIndex;
  611. switch (chan->chanmode) {
  612. case CHANNEL_A:
  613. case CHANNEL_A_HT20:
  614. modesIndex = 1;
  615. break;
  616. case CHANNEL_A_HT40PLUS:
  617. case CHANNEL_A_HT40MINUS:
  618. modesIndex = 2;
  619. break;
  620. case CHANNEL_G:
  621. case CHANNEL_G_HT20:
  622. case CHANNEL_B:
  623. modesIndex = 4;
  624. break;
  625. case CHANNEL_G_HT40PLUS:
  626. case CHANNEL_G_HT40MINUS:
  627. modesIndex = 3;
  628. break;
  629. default:
  630. return -EINVAL;
  631. }
  632. for (i = 0; i < ATH_INI_NUM_SPLIT; i++) {
  633. ar9003_hw_prog_ini(ah, &ah->iniSOC[i], modesIndex);
  634. ar9003_hw_prog_ini(ah, &ah->iniMac[i], modesIndex);
  635. ar9003_hw_prog_ini(ah, &ah->iniBB[i], modesIndex);
  636. ar9003_hw_prog_ini(ah, &ah->iniRadio[i], modesIndex);
  637. if (i == ATH_INI_POST && AR_SREV_9462_20(ah))
  638. ar9003_hw_prog_ini(ah,
  639. &ah->ini_radio_post_sys2ant,
  640. modesIndex);
  641. }
  642. REG_WRITE_ARRAY(&ah->iniModesRxGain, 1, regWrites);
  643. if (AR_SREV_9550(ah))
  644. REG_WRITE_ARRAY(&ah->ini_modes_rx_gain_bounds, modesIndex,
  645. regWrites);
  646. if (AR_SREV_9550(ah)) {
  647. int modes_txgain_index;
  648. modes_txgain_index = ar9550_hw_get_modes_txgain_index(ah, chan);
  649. if (modes_txgain_index < 0)
  650. return -EINVAL;
  651. REG_WRITE_ARRAY(&ah->iniModesTxGain, modes_txgain_index,
  652. regWrites);
  653. } else {
  654. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  655. }
  656. /*
  657. * For 5GHz channels requiring Fast Clock, apply
  658. * different modal values.
  659. */
  660. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  661. REG_WRITE_ARRAY(&ah->iniModesFastClock,
  662. modesIndex, regWrites);
  663. REG_WRITE_ARRAY(&ah->iniAdditional, 1, regWrites);
  664. if (chan->channel == 2484)
  665. ar9003_hw_prog_ini(ah, &ah->iniCckfirJapan2484, 1);
  666. if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
  667. REG_WRITE(ah, AR_GLB_SWREG_DISCONT_MODE,
  668. AR_GLB_SWREG_DISCONT_EN_BT_WLAN);
  669. ah->modes_index = modesIndex;
  670. ar9003_hw_override_ini(ah);
  671. ar9003_hw_set_channel_regs(ah, chan);
  672. ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
  673. ath9k_hw_apply_txpower(ah, chan, false);
  674. if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
  675. if (REG_READ_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_0,
  676. AR_PHY_TX_IQCAL_CONTROL_0_ENABLE_TXIQ_CAL))
  677. ah->enabled_cals |= TX_IQ_CAL;
  678. else
  679. ah->enabled_cals &= ~TX_IQ_CAL;
  680. if (REG_READ(ah, AR_PHY_CL_CAL_CTL) & AR_PHY_CL_CAL_ENABLE)
  681. ah->enabled_cals |= TX_CL_CAL;
  682. else
  683. ah->enabled_cals &= ~TX_CL_CAL;
  684. }
  685. return 0;
  686. }
  687. static void ar9003_hw_set_rfmode(struct ath_hw *ah,
  688. struct ath9k_channel *chan)
  689. {
  690. u32 rfMode = 0;
  691. if (chan == NULL)
  692. return;
  693. rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
  694. ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
  695. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  696. rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
  697. if (IS_CHAN_QUARTER_RATE(chan))
  698. rfMode |= AR_PHY_MODE_QUARTER;
  699. if (IS_CHAN_HALF_RATE(chan))
  700. rfMode |= AR_PHY_MODE_HALF;
  701. if (rfMode & (AR_PHY_MODE_QUARTER | AR_PHY_MODE_HALF))
  702. REG_RMW_FIELD(ah, AR_PHY_FRAME_CTL,
  703. AR_PHY_FRAME_CTL_CF_OVERLAP_WINDOW, 3);
  704. REG_WRITE(ah, AR_PHY_MODE, rfMode);
  705. }
  706. static void ar9003_hw_mark_phy_inactive(struct ath_hw *ah)
  707. {
  708. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
  709. }
  710. static void ar9003_hw_set_delta_slope(struct ath_hw *ah,
  711. struct ath9k_channel *chan)
  712. {
  713. u32 coef_scaled, ds_coef_exp, ds_coef_man;
  714. u32 clockMhzScaled = 0x64000000;
  715. struct chan_centers centers;
  716. /*
  717. * half and quarter rate can divide the scaled clock by 2 or 4
  718. * scale for selected channel bandwidth
  719. */
  720. if (IS_CHAN_HALF_RATE(chan))
  721. clockMhzScaled = clockMhzScaled >> 1;
  722. else if (IS_CHAN_QUARTER_RATE(chan))
  723. clockMhzScaled = clockMhzScaled >> 2;
  724. /*
  725. * ALGO -> coef = 1e8/fcarrier*fclock/40;
  726. * scaled coef to provide precision for this floating calculation
  727. */
  728. ath9k_hw_get_channel_centers(ah, chan, &centers);
  729. coef_scaled = clockMhzScaled / centers.synth_center;
  730. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  731. &ds_coef_exp);
  732. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  733. AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
  734. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  735. AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
  736. /*
  737. * For Short GI,
  738. * scaled coeff is 9/10 that of normal coeff
  739. */
  740. coef_scaled = (9 * coef_scaled) / 10;
  741. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  742. &ds_coef_exp);
  743. /* for short gi */
  744. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  745. AR_PHY_SGI_DSC_MAN, ds_coef_man);
  746. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  747. AR_PHY_SGI_DSC_EXP, ds_coef_exp);
  748. }
  749. static bool ar9003_hw_rfbus_req(struct ath_hw *ah)
  750. {
  751. REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
  752. return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
  753. AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT);
  754. }
  755. /*
  756. * Wait for the frequency synth to settle (synth goes on via PHY_ACTIVE_EN).
  757. * Read the phy active delay register. Value is in 100ns increments.
  758. */
  759. static void ar9003_hw_rfbus_done(struct ath_hw *ah)
  760. {
  761. u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  762. ath9k_hw_synth_delay(ah, ah->curchan, synthDelay);
  763. REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
  764. }
  765. static bool ar9003_hw_ani_control(struct ath_hw *ah,
  766. enum ath9k_ani_cmd cmd, int param)
  767. {
  768. struct ath_common *common = ath9k_hw_common(ah);
  769. struct ath9k_channel *chan = ah->curchan;
  770. struct ar5416AniState *aniState = &chan->ani;
  771. s32 value, value2;
  772. switch (cmd & ah->ani_function) {
  773. case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
  774. /*
  775. * on == 1 means ofdm weak signal detection is ON
  776. * on == 1 is the default, for less noise immunity
  777. *
  778. * on == 0 means ofdm weak signal detection is OFF
  779. * on == 0 means more noise imm
  780. */
  781. u32 on = param ? 1 : 0;
  782. if (on)
  783. REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
  784. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  785. else
  786. REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
  787. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  788. if (on != aniState->ofdmWeakSigDetect) {
  789. ath_dbg(common, ANI,
  790. "** ch %d: ofdm weak signal: %s=>%s\n",
  791. chan->channel,
  792. aniState->ofdmWeakSigDetect ?
  793. "on" : "off",
  794. on ? "on" : "off");
  795. if (on)
  796. ah->stats.ast_ani_ofdmon++;
  797. else
  798. ah->stats.ast_ani_ofdmoff++;
  799. aniState->ofdmWeakSigDetect = on;
  800. }
  801. break;
  802. }
  803. case ATH9K_ANI_FIRSTEP_LEVEL:{
  804. u32 level = param;
  805. if (level >= ARRAY_SIZE(firstep_table)) {
  806. ath_dbg(common, ANI,
  807. "ATH9K_ANI_FIRSTEP_LEVEL: level out of range (%u > %zu)\n",
  808. level, ARRAY_SIZE(firstep_table));
  809. return false;
  810. }
  811. /*
  812. * make register setting relative to default
  813. * from INI file & cap value
  814. */
  815. value = firstep_table[level] -
  816. firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
  817. aniState->iniDef.firstep;
  818. if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  819. value = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  820. if (value > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  821. value = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  822. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  823. AR_PHY_FIND_SIG_FIRSTEP,
  824. value);
  825. /*
  826. * we need to set first step low register too
  827. * make register setting relative to default
  828. * from INI file & cap value
  829. */
  830. value2 = firstep_table[level] -
  831. firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
  832. aniState->iniDef.firstepLow;
  833. if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  834. value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  835. if (value2 > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  836. value2 = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  837. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
  838. AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW, value2);
  839. if (level != aniState->firstepLevel) {
  840. ath_dbg(common, ANI,
  841. "** ch %d: level %d=>%d[def:%d] firstep[level]=%d ini=%d\n",
  842. chan->channel,
  843. aniState->firstepLevel,
  844. level,
  845. ATH9K_ANI_FIRSTEP_LVL,
  846. value,
  847. aniState->iniDef.firstep);
  848. ath_dbg(common, ANI,
  849. "** ch %d: level %d=>%d[def:%d] firstep_low[level]=%d ini=%d\n",
  850. chan->channel,
  851. aniState->firstepLevel,
  852. level,
  853. ATH9K_ANI_FIRSTEP_LVL,
  854. value2,
  855. aniState->iniDef.firstepLow);
  856. if (level > aniState->firstepLevel)
  857. ah->stats.ast_ani_stepup++;
  858. else if (level < aniState->firstepLevel)
  859. ah->stats.ast_ani_stepdown++;
  860. aniState->firstepLevel = level;
  861. }
  862. break;
  863. }
  864. case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
  865. u32 level = param;
  866. if (level >= ARRAY_SIZE(cycpwrThr1_table)) {
  867. ath_dbg(common, ANI,
  868. "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level out of range (%u > %zu)\n",
  869. level, ARRAY_SIZE(cycpwrThr1_table));
  870. return false;
  871. }
  872. /*
  873. * make register setting relative to default
  874. * from INI file & cap value
  875. */
  876. value = cycpwrThr1_table[level] -
  877. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
  878. aniState->iniDef.cycpwrThr1;
  879. if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  880. value = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  881. if (value > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  882. value = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  883. REG_RMW_FIELD(ah, AR_PHY_TIMING5,
  884. AR_PHY_TIMING5_CYCPWR_THR1,
  885. value);
  886. /*
  887. * set AR_PHY_EXT_CCA for extension channel
  888. * make register setting relative to default
  889. * from INI file & cap value
  890. */
  891. value2 = cycpwrThr1_table[level] -
  892. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
  893. aniState->iniDef.cycpwrThr1Ext;
  894. if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  895. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  896. if (value2 > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  897. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  898. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
  899. AR_PHY_EXT_CYCPWR_THR1, value2);
  900. if (level != aniState->spurImmunityLevel) {
  901. ath_dbg(common, ANI,
  902. "** ch %d: level %d=>%d[def:%d] cycpwrThr1[level]=%d ini=%d\n",
  903. chan->channel,
  904. aniState->spurImmunityLevel,
  905. level,
  906. ATH9K_ANI_SPUR_IMMUNE_LVL,
  907. value,
  908. aniState->iniDef.cycpwrThr1);
  909. ath_dbg(common, ANI,
  910. "** ch %d: level %d=>%d[def:%d] cycpwrThr1Ext[level]=%d ini=%d\n",
  911. chan->channel,
  912. aniState->spurImmunityLevel,
  913. level,
  914. ATH9K_ANI_SPUR_IMMUNE_LVL,
  915. value2,
  916. aniState->iniDef.cycpwrThr1Ext);
  917. if (level > aniState->spurImmunityLevel)
  918. ah->stats.ast_ani_spurup++;
  919. else if (level < aniState->spurImmunityLevel)
  920. ah->stats.ast_ani_spurdown++;
  921. aniState->spurImmunityLevel = level;
  922. }
  923. break;
  924. }
  925. case ATH9K_ANI_MRC_CCK:{
  926. /*
  927. * is_on == 1 means MRC CCK ON (default, less noise imm)
  928. * is_on == 0 means MRC CCK is OFF (more noise imm)
  929. */
  930. bool is_on = param ? 1 : 0;
  931. REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
  932. AR_PHY_MRC_CCK_ENABLE, is_on);
  933. REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
  934. AR_PHY_MRC_CCK_MUX_REG, is_on);
  935. if (is_on != aniState->mrcCCK) {
  936. ath_dbg(common, ANI, "** ch %d: MRC CCK: %s=>%s\n",
  937. chan->channel,
  938. aniState->mrcCCK ? "on" : "off",
  939. is_on ? "on" : "off");
  940. if (is_on)
  941. ah->stats.ast_ani_ccklow++;
  942. else
  943. ah->stats.ast_ani_cckhigh++;
  944. aniState->mrcCCK = is_on;
  945. }
  946. break;
  947. }
  948. case ATH9K_ANI_PRESENT:
  949. break;
  950. default:
  951. ath_dbg(common, ANI, "invalid cmd %u\n", cmd);
  952. return false;
  953. }
  954. ath_dbg(common, ANI,
  955. "ANI parameters: SI=%d, ofdmWS=%s FS=%d MRCcck=%s listenTime=%d ofdmErrs=%d cckErrs=%d\n",
  956. aniState->spurImmunityLevel,
  957. aniState->ofdmWeakSigDetect ? "on" : "off",
  958. aniState->firstepLevel,
  959. aniState->mrcCCK ? "on" : "off",
  960. aniState->listenTime,
  961. aniState->ofdmPhyErrCount,
  962. aniState->cckPhyErrCount);
  963. return true;
  964. }
  965. static void ar9003_hw_do_getnf(struct ath_hw *ah,
  966. int16_t nfarray[NUM_NF_READINGS])
  967. {
  968. #define AR_PHY_CH_MINCCA_PWR 0x1FF00000
  969. #define AR_PHY_CH_MINCCA_PWR_S 20
  970. #define AR_PHY_CH_EXT_MINCCA_PWR 0x01FF0000
  971. #define AR_PHY_CH_EXT_MINCCA_PWR_S 16
  972. int16_t nf;
  973. int i;
  974. for (i = 0; i < AR9300_MAX_CHAINS; i++) {
  975. if (ah->rxchainmask & BIT(i)) {
  976. nf = MS(REG_READ(ah, ah->nf_regs[i]),
  977. AR_PHY_CH_MINCCA_PWR);
  978. nfarray[i] = sign_extend32(nf, 8);
  979. if (IS_CHAN_HT40(ah->curchan)) {
  980. u8 ext_idx = AR9300_MAX_CHAINS + i;
  981. nf = MS(REG_READ(ah, ah->nf_regs[ext_idx]),
  982. AR_PHY_CH_EXT_MINCCA_PWR);
  983. nfarray[ext_idx] = sign_extend32(nf, 8);
  984. }
  985. }
  986. }
  987. }
  988. static void ar9003_hw_set_nf_limits(struct ath_hw *ah)
  989. {
  990. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_2GHZ;
  991. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_2GHZ;
  992. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9300_2GHZ;
  993. ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_5GHZ;
  994. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_5GHZ;
  995. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9300_5GHZ;
  996. if (AR_SREV_9330(ah))
  997. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9330_2GHZ;
  998. if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
  999. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9462_2GHZ;
  1000. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9462_2GHZ;
  1001. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9462_5GHZ;
  1002. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9462_5GHZ;
  1003. }
  1004. }
  1005. /*
  1006. * Initialize the ANI register values with default (ini) values.
  1007. * This routine is called during a (full) hardware reset after
  1008. * all the registers are initialised from the INI.
  1009. */
  1010. static void ar9003_hw_ani_cache_ini_regs(struct ath_hw *ah)
  1011. {
  1012. struct ar5416AniState *aniState;
  1013. struct ath_common *common = ath9k_hw_common(ah);
  1014. struct ath9k_channel *chan = ah->curchan;
  1015. struct ath9k_ani_default *iniDef;
  1016. u32 val;
  1017. aniState = &ah->curchan->ani;
  1018. iniDef = &aniState->iniDef;
  1019. ath_dbg(common, ANI, "ver %d.%d opmode %u chan %d Mhz/0x%x\n",
  1020. ah->hw_version.macVersion,
  1021. ah->hw_version.macRev,
  1022. ah->opmode,
  1023. chan->channel,
  1024. chan->channelFlags);
  1025. val = REG_READ(ah, AR_PHY_SFCORR);
  1026. iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH);
  1027. iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH);
  1028. iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR);
  1029. val = REG_READ(ah, AR_PHY_SFCORR_LOW);
  1030. iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW);
  1031. iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW);
  1032. iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW);
  1033. val = REG_READ(ah, AR_PHY_SFCORR_EXT);
  1034. iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH);
  1035. iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH);
  1036. iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW);
  1037. iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW);
  1038. iniDef->firstep = REG_READ_FIELD(ah,
  1039. AR_PHY_FIND_SIG,
  1040. AR_PHY_FIND_SIG_FIRSTEP);
  1041. iniDef->firstepLow = REG_READ_FIELD(ah,
  1042. AR_PHY_FIND_SIG_LOW,
  1043. AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW);
  1044. iniDef->cycpwrThr1 = REG_READ_FIELD(ah,
  1045. AR_PHY_TIMING5,
  1046. AR_PHY_TIMING5_CYCPWR_THR1);
  1047. iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah,
  1048. AR_PHY_EXT_CCA,
  1049. AR_PHY_EXT_CYCPWR_THR1);
  1050. /* these levels just got reset to defaults by the INI */
  1051. aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL;
  1052. aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL;
  1053. aniState->ofdmWeakSigDetect = ATH9K_ANI_USE_OFDM_WEAK_SIG;
  1054. aniState->mrcCCK = true;
  1055. }
  1056. static void ar9003_hw_set_radar_params(struct ath_hw *ah,
  1057. struct ath_hw_radar_conf *conf)
  1058. {
  1059. u32 radar_0 = 0, radar_1 = 0;
  1060. if (!conf) {
  1061. REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA);
  1062. return;
  1063. }
  1064. radar_0 |= AR_PHY_RADAR_0_ENA | AR_PHY_RADAR_0_FFT_ENA;
  1065. radar_0 |= SM(conf->fir_power, AR_PHY_RADAR_0_FIRPWR);
  1066. radar_0 |= SM(conf->radar_rssi, AR_PHY_RADAR_0_RRSSI);
  1067. radar_0 |= SM(conf->pulse_height, AR_PHY_RADAR_0_HEIGHT);
  1068. radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI);
  1069. radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND);
  1070. radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI;
  1071. radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK;
  1072. radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN);
  1073. radar_1 |= SM(conf->pulse_inband_step, AR_PHY_RADAR_1_RELSTEP_THRESH);
  1074. radar_1 |= SM(conf->radar_inband, AR_PHY_RADAR_1_RELPWR_THRESH);
  1075. REG_WRITE(ah, AR_PHY_RADAR_0, radar_0);
  1076. REG_WRITE(ah, AR_PHY_RADAR_1, radar_1);
  1077. if (conf->ext_channel)
  1078. REG_SET_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1079. else
  1080. REG_CLR_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1081. }
  1082. static void ar9003_hw_set_radar_conf(struct ath_hw *ah)
  1083. {
  1084. struct ath_hw_radar_conf *conf = &ah->radar_conf;
  1085. conf->fir_power = -28;
  1086. conf->radar_rssi = 0;
  1087. conf->pulse_height = 10;
  1088. conf->pulse_rssi = 24;
  1089. conf->pulse_inband = 8;
  1090. conf->pulse_maxlen = 255;
  1091. conf->pulse_inband_step = 12;
  1092. conf->radar_inband = 8;
  1093. }
  1094. static void ar9003_hw_antdiv_comb_conf_get(struct ath_hw *ah,
  1095. struct ath_hw_antcomb_conf *antconf)
  1096. {
  1097. u32 regval;
  1098. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1099. antconf->main_lna_conf = (regval & AR_PHY_ANT_DIV_MAIN_LNACONF) >>
  1100. AR_PHY_ANT_DIV_MAIN_LNACONF_S;
  1101. antconf->alt_lna_conf = (regval & AR_PHY_ANT_DIV_ALT_LNACONF) >>
  1102. AR_PHY_ANT_DIV_ALT_LNACONF_S;
  1103. antconf->fast_div_bias = (regval & AR_PHY_ANT_FAST_DIV_BIAS) >>
  1104. AR_PHY_ANT_FAST_DIV_BIAS_S;
  1105. if (AR_SREV_9330_11(ah)) {
  1106. antconf->lna1_lna2_delta = -9;
  1107. antconf->div_group = 1;
  1108. } else if (AR_SREV_9485(ah)) {
  1109. antconf->lna1_lna2_delta = -9;
  1110. antconf->div_group = 2;
  1111. } else if (AR_SREV_9565(ah)) {
  1112. antconf->lna1_lna2_delta = -3;
  1113. antconf->div_group = 3;
  1114. } else {
  1115. antconf->lna1_lna2_delta = -3;
  1116. antconf->div_group = 0;
  1117. }
  1118. }
  1119. static void ar9003_hw_antdiv_comb_conf_set(struct ath_hw *ah,
  1120. struct ath_hw_antcomb_conf *antconf)
  1121. {
  1122. u32 regval;
  1123. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1124. regval &= ~(AR_PHY_ANT_DIV_MAIN_LNACONF |
  1125. AR_PHY_ANT_DIV_ALT_LNACONF |
  1126. AR_PHY_ANT_FAST_DIV_BIAS |
  1127. AR_PHY_ANT_DIV_MAIN_GAINTB |
  1128. AR_PHY_ANT_DIV_ALT_GAINTB);
  1129. regval |= ((antconf->main_lna_conf << AR_PHY_ANT_DIV_MAIN_LNACONF_S)
  1130. & AR_PHY_ANT_DIV_MAIN_LNACONF);
  1131. regval |= ((antconf->alt_lna_conf << AR_PHY_ANT_DIV_ALT_LNACONF_S)
  1132. & AR_PHY_ANT_DIV_ALT_LNACONF);
  1133. regval |= ((antconf->fast_div_bias << AR_PHY_ANT_FAST_DIV_BIAS_S)
  1134. & AR_PHY_ANT_FAST_DIV_BIAS);
  1135. regval |= ((antconf->main_gaintb << AR_PHY_ANT_DIV_MAIN_GAINTB_S)
  1136. & AR_PHY_ANT_DIV_MAIN_GAINTB);
  1137. regval |= ((antconf->alt_gaintb << AR_PHY_ANT_DIV_ALT_GAINTB_S)
  1138. & AR_PHY_ANT_DIV_ALT_GAINTB);
  1139. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1140. }
  1141. static void ar9003_hw_antctrl_shared_chain_lnadiv(struct ath_hw *ah,
  1142. bool enable)
  1143. {
  1144. u8 ant_div_ctl1;
  1145. u32 regval;
  1146. if (!AR_SREV_9565(ah))
  1147. return;
  1148. ah->shared_chain_lnadiv = enable;
  1149. ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
  1150. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1151. regval &= (~AR_ANT_DIV_CTRL_ALL);
  1152. regval |= (ant_div_ctl1 & 0x3f) << AR_ANT_DIV_CTRL_ALL_S;
  1153. regval &= ~AR_PHY_ANT_DIV_LNADIV;
  1154. regval |= ((ant_div_ctl1 >> 6) & 0x1) << AR_PHY_ANT_DIV_LNADIV_S;
  1155. if (enable)
  1156. regval |= AR_ANT_DIV_ENABLE;
  1157. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1158. regval = REG_READ(ah, AR_PHY_CCK_DETECT);
  1159. regval &= ~AR_FAST_DIV_ENABLE;
  1160. regval |= ((ant_div_ctl1 >> 7) & 0x1) << AR_FAST_DIV_ENABLE_S;
  1161. if (enable)
  1162. regval |= AR_FAST_DIV_ENABLE;
  1163. REG_WRITE(ah, AR_PHY_CCK_DETECT, regval);
  1164. if (enable) {
  1165. REG_SET_BIT(ah, AR_PHY_MC_GAIN_CTRL,
  1166. (1 << AR_PHY_ANT_SW_RX_PROT_S));
  1167. if (ah->curchan && IS_CHAN_2GHZ(ah->curchan))
  1168. REG_SET_BIT(ah, AR_PHY_RESTART,
  1169. AR_PHY_RESTART_ENABLE_DIV_M2FLAG);
  1170. REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV,
  1171. AR_BTCOEX_WL_LNADIV_FORCE_ON);
  1172. } else {
  1173. REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL, AR_ANT_DIV_ENABLE);
  1174. REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL,
  1175. (1 << AR_PHY_ANT_SW_RX_PROT_S));
  1176. REG_CLR_BIT(ah, AR_PHY_CCK_DETECT, AR_FAST_DIV_ENABLE);
  1177. REG_CLR_BIT(ah, AR_BTCOEX_WL_LNADIV,
  1178. AR_BTCOEX_WL_LNADIV_FORCE_ON);
  1179. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1180. regval &= ~(AR_PHY_ANT_DIV_MAIN_LNACONF |
  1181. AR_PHY_ANT_DIV_ALT_LNACONF |
  1182. AR_PHY_ANT_DIV_MAIN_GAINTB |
  1183. AR_PHY_ANT_DIV_ALT_GAINTB);
  1184. regval |= (AR_PHY_ANT_DIV_LNA1 << AR_PHY_ANT_DIV_MAIN_LNACONF_S);
  1185. regval |= (AR_PHY_ANT_DIV_LNA2 << AR_PHY_ANT_DIV_ALT_LNACONF_S);
  1186. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1187. }
  1188. }
  1189. static int ar9003_hw_fast_chan_change(struct ath_hw *ah,
  1190. struct ath9k_channel *chan,
  1191. u8 *ini_reloaded)
  1192. {
  1193. unsigned int regWrites = 0;
  1194. u32 modesIndex;
  1195. switch (chan->chanmode) {
  1196. case CHANNEL_A:
  1197. case CHANNEL_A_HT20:
  1198. modesIndex = 1;
  1199. break;
  1200. case CHANNEL_A_HT40PLUS:
  1201. case CHANNEL_A_HT40MINUS:
  1202. modesIndex = 2;
  1203. break;
  1204. case CHANNEL_G:
  1205. case CHANNEL_G_HT20:
  1206. case CHANNEL_B:
  1207. modesIndex = 4;
  1208. break;
  1209. case CHANNEL_G_HT40PLUS:
  1210. case CHANNEL_G_HT40MINUS:
  1211. modesIndex = 3;
  1212. break;
  1213. default:
  1214. return -EINVAL;
  1215. }
  1216. if (modesIndex == ah->modes_index) {
  1217. *ini_reloaded = false;
  1218. goto set_rfmode;
  1219. }
  1220. ar9003_hw_prog_ini(ah, &ah->iniSOC[ATH_INI_POST], modesIndex);
  1221. ar9003_hw_prog_ini(ah, &ah->iniMac[ATH_INI_POST], modesIndex);
  1222. ar9003_hw_prog_ini(ah, &ah->iniBB[ATH_INI_POST], modesIndex);
  1223. ar9003_hw_prog_ini(ah, &ah->iniRadio[ATH_INI_POST], modesIndex);
  1224. if (AR_SREV_9462_20(ah))
  1225. ar9003_hw_prog_ini(ah, &ah->ini_radio_post_sys2ant,
  1226. modesIndex);
  1227. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  1228. /*
  1229. * For 5GHz channels requiring Fast Clock, apply
  1230. * different modal values.
  1231. */
  1232. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  1233. REG_WRITE_ARRAY(&ah->iniModesFastClock, modesIndex, regWrites);
  1234. if (AR_SREV_9565(ah))
  1235. REG_WRITE_ARRAY(&ah->iniModesFastClock, 1, regWrites);
  1236. REG_WRITE_ARRAY(&ah->iniAdditional, 1, regWrites);
  1237. ah->modes_index = modesIndex;
  1238. *ini_reloaded = true;
  1239. set_rfmode:
  1240. ar9003_hw_set_rfmode(ah, chan);
  1241. return 0;
  1242. }
  1243. static void ar9003_hw_spectral_scan_config(struct ath_hw *ah,
  1244. struct ath_spec_scan *param)
  1245. {
  1246. u8 count;
  1247. if (!param->enabled) {
  1248. REG_CLR_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  1249. AR_PHY_SPECTRAL_SCAN_ENABLE);
  1250. return;
  1251. }
  1252. REG_SET_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_FFT_ENA);
  1253. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN, AR_PHY_SPECTRAL_SCAN_ENABLE);
  1254. /* on AR93xx and newer, count = 0 will make the the chip send
  1255. * spectral samples endlessly. Check if this really was intended,
  1256. * and fix otherwise.
  1257. */
  1258. count = param->count;
  1259. if (param->endless)
  1260. count = 0;
  1261. else if (param->count == 0)
  1262. count = 1;
  1263. if (param->short_repeat)
  1264. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  1265. AR_PHY_SPECTRAL_SCAN_SHORT_REPEAT);
  1266. else
  1267. REG_CLR_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  1268. AR_PHY_SPECTRAL_SCAN_SHORT_REPEAT);
  1269. REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN,
  1270. AR_PHY_SPECTRAL_SCAN_COUNT, count);
  1271. REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN,
  1272. AR_PHY_SPECTRAL_SCAN_PERIOD, param->period);
  1273. REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN,
  1274. AR_PHY_SPECTRAL_SCAN_FFT_PERIOD, param->fft_period);
  1275. return;
  1276. }
  1277. static void ar9003_hw_spectral_scan_trigger(struct ath_hw *ah)
  1278. {
  1279. /* Activate spectral scan */
  1280. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  1281. AR_PHY_SPECTRAL_SCAN_ACTIVE);
  1282. }
  1283. static void ar9003_hw_spectral_scan_wait(struct ath_hw *ah)
  1284. {
  1285. struct ath_common *common = ath9k_hw_common(ah);
  1286. /* Poll for spectral scan complete */
  1287. if (!ath9k_hw_wait(ah, AR_PHY_SPECTRAL_SCAN,
  1288. AR_PHY_SPECTRAL_SCAN_ACTIVE,
  1289. 0, AH_WAIT_TIMEOUT)) {
  1290. ath_err(common, "spectral scan wait failed\n");
  1291. return;
  1292. }
  1293. }
  1294. void ar9003_hw_attach_phy_ops(struct ath_hw *ah)
  1295. {
  1296. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  1297. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  1298. static const u32 ar9300_cca_regs[6] = {
  1299. AR_PHY_CCA_0,
  1300. AR_PHY_CCA_1,
  1301. AR_PHY_CCA_2,
  1302. AR_PHY_EXT_CCA,
  1303. AR_PHY_EXT_CCA_1,
  1304. AR_PHY_EXT_CCA_2,
  1305. };
  1306. priv_ops->rf_set_freq = ar9003_hw_set_channel;
  1307. priv_ops->spur_mitigate_freq = ar9003_hw_spur_mitigate;
  1308. priv_ops->compute_pll_control = ar9003_hw_compute_pll_control;
  1309. priv_ops->set_channel_regs = ar9003_hw_set_channel_regs;
  1310. priv_ops->init_bb = ar9003_hw_init_bb;
  1311. priv_ops->process_ini = ar9003_hw_process_ini;
  1312. priv_ops->set_rfmode = ar9003_hw_set_rfmode;
  1313. priv_ops->mark_phy_inactive = ar9003_hw_mark_phy_inactive;
  1314. priv_ops->set_delta_slope = ar9003_hw_set_delta_slope;
  1315. priv_ops->rfbus_req = ar9003_hw_rfbus_req;
  1316. priv_ops->rfbus_done = ar9003_hw_rfbus_done;
  1317. priv_ops->ani_control = ar9003_hw_ani_control;
  1318. priv_ops->do_getnf = ar9003_hw_do_getnf;
  1319. priv_ops->ani_cache_ini_regs = ar9003_hw_ani_cache_ini_regs;
  1320. priv_ops->set_radar_params = ar9003_hw_set_radar_params;
  1321. priv_ops->fast_chan_change = ar9003_hw_fast_chan_change;
  1322. ops->antdiv_comb_conf_get = ar9003_hw_antdiv_comb_conf_get;
  1323. ops->antdiv_comb_conf_set = ar9003_hw_antdiv_comb_conf_set;
  1324. ops->antctrl_shared_chain_lnadiv = ar9003_hw_antctrl_shared_chain_lnadiv;
  1325. ops->spectral_scan_config = ar9003_hw_spectral_scan_config;
  1326. ops->spectral_scan_trigger = ar9003_hw_spectral_scan_trigger;
  1327. ops->spectral_scan_wait = ar9003_hw_spectral_scan_wait;
  1328. ar9003_hw_set_nf_limits(ah);
  1329. ar9003_hw_set_radar_conf(ah);
  1330. memcpy(ah->nf_regs, ar9300_cca_regs, sizeof(ah->nf_regs));
  1331. }
  1332. void ar9003_hw_bb_watchdog_config(struct ath_hw *ah)
  1333. {
  1334. struct ath_common *common = ath9k_hw_common(ah);
  1335. u32 idle_tmo_ms = ah->bb_watchdog_timeout_ms;
  1336. u32 val, idle_count;
  1337. if (!idle_tmo_ms) {
  1338. /* disable IRQ, disable chip-reset for BB panic */
  1339. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
  1340. REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) &
  1341. ~(AR_PHY_WATCHDOG_RST_ENABLE |
  1342. AR_PHY_WATCHDOG_IRQ_ENABLE));
  1343. /* disable watchdog in non-IDLE mode, disable in IDLE mode */
  1344. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
  1345. REG_READ(ah, AR_PHY_WATCHDOG_CTL_1) &
  1346. ~(AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
  1347. AR_PHY_WATCHDOG_IDLE_ENABLE));
  1348. ath_dbg(common, RESET, "Disabled BB Watchdog\n");
  1349. return;
  1350. }
  1351. /* enable IRQ, disable chip-reset for BB watchdog */
  1352. val = REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) & AR_PHY_WATCHDOG_CNTL2_MASK;
  1353. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
  1354. (val | AR_PHY_WATCHDOG_IRQ_ENABLE) &
  1355. ~AR_PHY_WATCHDOG_RST_ENABLE);
  1356. /* bound limit to 10 secs */
  1357. if (idle_tmo_ms > 10000)
  1358. idle_tmo_ms = 10000;
  1359. /*
  1360. * The time unit for watchdog event is 2^15 44/88MHz cycles.
  1361. *
  1362. * For HT20 we have a time unit of 2^15/44 MHz = .74 ms per tick
  1363. * For HT40 we have a time unit of 2^15/88 MHz = .37 ms per tick
  1364. *
  1365. * Given we use fast clock now in 5 GHz, these time units should
  1366. * be common for both 2 GHz and 5 GHz.
  1367. */
  1368. idle_count = (100 * idle_tmo_ms) / 74;
  1369. if (ah->curchan && IS_CHAN_HT40(ah->curchan))
  1370. idle_count = (100 * idle_tmo_ms) / 37;
  1371. /*
  1372. * enable watchdog in non-IDLE mode, disable in IDLE mode,
  1373. * set idle time-out.
  1374. */
  1375. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
  1376. AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
  1377. AR_PHY_WATCHDOG_IDLE_MASK |
  1378. (AR_PHY_WATCHDOG_NON_IDLE_MASK & (idle_count << 2)));
  1379. ath_dbg(common, RESET, "Enabled BB Watchdog timeout (%u ms)\n",
  1380. idle_tmo_ms);
  1381. }
  1382. void ar9003_hw_bb_watchdog_read(struct ath_hw *ah)
  1383. {
  1384. /*
  1385. * we want to avoid printing in ISR context so we save the
  1386. * watchdog status to be printed later in bottom half context.
  1387. */
  1388. ah->bb_watchdog_last_status = REG_READ(ah, AR_PHY_WATCHDOG_STATUS);
  1389. /*
  1390. * the watchdog timer should reset on status read but to be sure
  1391. * sure we write 0 to the watchdog status bit.
  1392. */
  1393. REG_WRITE(ah, AR_PHY_WATCHDOG_STATUS,
  1394. ah->bb_watchdog_last_status & ~AR_PHY_WATCHDOG_STATUS_CLR);
  1395. }
  1396. void ar9003_hw_bb_watchdog_dbg_info(struct ath_hw *ah)
  1397. {
  1398. struct ath_common *common = ath9k_hw_common(ah);
  1399. u32 status;
  1400. if (likely(!(common->debug_mask & ATH_DBG_RESET)))
  1401. return;
  1402. status = ah->bb_watchdog_last_status;
  1403. ath_dbg(common, RESET,
  1404. "\n==== BB update: BB status=0x%08x ====\n", status);
  1405. ath_dbg(common, RESET,
  1406. "** BB state: wd=%u det=%u rdar=%u rOFDM=%d rCCK=%u tOFDM=%u tCCK=%u agc=%u src=%u **\n",
  1407. MS(status, AR_PHY_WATCHDOG_INFO),
  1408. MS(status, AR_PHY_WATCHDOG_DET_HANG),
  1409. MS(status, AR_PHY_WATCHDOG_RADAR_SM),
  1410. MS(status, AR_PHY_WATCHDOG_RX_OFDM_SM),
  1411. MS(status, AR_PHY_WATCHDOG_RX_CCK_SM),
  1412. MS(status, AR_PHY_WATCHDOG_TX_OFDM_SM),
  1413. MS(status, AR_PHY_WATCHDOG_TX_CCK_SM),
  1414. MS(status, AR_PHY_WATCHDOG_AGC_SM),
  1415. MS(status, AR_PHY_WATCHDOG_SRCH_SM));
  1416. ath_dbg(common, RESET, "** BB WD cntl: cntl1=0x%08x cntl2=0x%08x **\n",
  1417. REG_READ(ah, AR_PHY_WATCHDOG_CTL_1),
  1418. REG_READ(ah, AR_PHY_WATCHDOG_CTL_2));
  1419. ath_dbg(common, RESET, "** BB mode: BB_gen_controls=0x%08x **\n",
  1420. REG_READ(ah, AR_PHY_GEN_CTRL));
  1421. #define PCT(_field) (common->cc_survey._field * 100 / common->cc_survey.cycles)
  1422. if (common->cc_survey.cycles)
  1423. ath_dbg(common, RESET,
  1424. "** BB busy times: rx_clear=%d%%, rx_frame=%d%%, tx_frame=%d%% **\n",
  1425. PCT(rx_busy), PCT(rx_frame), PCT(tx_frame));
  1426. ath_dbg(common, RESET, "==== BB update: done ====\n\n");
  1427. }
  1428. EXPORT_SYMBOL(ar9003_hw_bb_watchdog_dbg_info);
  1429. void ar9003_hw_disable_phy_restart(struct ath_hw *ah)
  1430. {
  1431. u32 val;
  1432. /* While receiving unsupported rate frame rx state machine
  1433. * gets into a state 0xb and if phy_restart happens in that
  1434. * state, BB would go hang. If RXSM is in 0xb state after
  1435. * first bb panic, ensure to disable the phy_restart.
  1436. */
  1437. if (!((MS(ah->bb_watchdog_last_status,
  1438. AR_PHY_WATCHDOG_RX_OFDM_SM) == 0xb) ||
  1439. ah->bb_hang_rx_ofdm))
  1440. return;
  1441. ah->bb_hang_rx_ofdm = true;
  1442. val = REG_READ(ah, AR_PHY_RESTART);
  1443. val &= ~AR_PHY_RESTART_ENA;
  1444. REG_WRITE(ah, AR_PHY_RESTART, val);
  1445. }
  1446. EXPORT_SYMBOL(ar9003_hw_disable_phy_restart);