ar5008_phy.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677
  1. /*
  2. * Copyright (c) 2008-2010 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 "hw.h"
  17. #include "hw-ops.h"
  18. #include "../regd.h"
  19. #include "ar9002_phy.h"
  20. /* All code below is for AR5008, AR9001, AR9002 */
  21. static const int firstep_table[] =
  22. /* level: 0 1 2 3 4 5 6 7 8 */
  23. { -4, -2, 0, 2, 4, 6, 8, 10, 12 }; /* lvl 0-8, default 2 */
  24. static const int cycpwrThr1_table[] =
  25. /* level: 0 1 2 3 4 5 6 7 8 */
  26. { -6, -4, -2, 0, 2, 4, 6, 8 }; /* lvl 0-7, default 3 */
  27. /*
  28. * register values to turn OFDM weak signal detection OFF
  29. */
  30. static const int m1ThreshLow_off = 127;
  31. static const int m2ThreshLow_off = 127;
  32. static const int m1Thresh_off = 127;
  33. static const int m2Thresh_off = 127;
  34. static const int m2CountThr_off = 31;
  35. static const int m2CountThrLow_off = 63;
  36. static const int m1ThreshLowExt_off = 127;
  37. static const int m2ThreshLowExt_off = 127;
  38. static const int m1ThreshExt_off = 127;
  39. static const int m2ThreshExt_off = 127;
  40. /**
  41. * ar5008_hw_phy_modify_rx_buffer() - perform analog swizzling of parameters
  42. * @rfbuf:
  43. * @reg32:
  44. * @numBits:
  45. * @firstBit:
  46. * @column:
  47. *
  48. * Performs analog "swizzling" of parameters into their location.
  49. * Used on external AR2133/AR5133 radios.
  50. */
  51. static void ar5008_hw_phy_modify_rx_buffer(u32 *rfBuf, u32 reg32,
  52. u32 numBits, u32 firstBit,
  53. u32 column)
  54. {
  55. u32 tmp32, mask, arrayEntry, lastBit;
  56. int32_t bitPosition, bitsLeft;
  57. tmp32 = ath9k_hw_reverse_bits(reg32, numBits);
  58. arrayEntry = (firstBit - 1) / 8;
  59. bitPosition = (firstBit - 1) % 8;
  60. bitsLeft = numBits;
  61. while (bitsLeft > 0) {
  62. lastBit = (bitPosition + bitsLeft > 8) ?
  63. 8 : bitPosition + bitsLeft;
  64. mask = (((1 << lastBit) - 1) ^ ((1 << bitPosition) - 1)) <<
  65. (column * 8);
  66. rfBuf[arrayEntry] &= ~mask;
  67. rfBuf[arrayEntry] |= ((tmp32 << bitPosition) <<
  68. (column * 8)) & mask;
  69. bitsLeft -= 8 - bitPosition;
  70. tmp32 = tmp32 >> (8 - bitPosition);
  71. bitPosition = 0;
  72. arrayEntry++;
  73. }
  74. }
  75. /*
  76. * Fix on 2.4 GHz band for orientation sensitivity issue by increasing
  77. * rf_pwd_icsyndiv.
  78. *
  79. * Theoretical Rules:
  80. * if 2 GHz band
  81. * if forceBiasAuto
  82. * if synth_freq < 2412
  83. * bias = 0
  84. * else if 2412 <= synth_freq <= 2422
  85. * bias = 1
  86. * else // synth_freq > 2422
  87. * bias = 2
  88. * else if forceBias > 0
  89. * bias = forceBias & 7
  90. * else
  91. * no change, use value from ini file
  92. * else
  93. * no change, invalid band
  94. *
  95. * 1st Mod:
  96. * 2422 also uses value of 2
  97. * <approved>
  98. *
  99. * 2nd Mod:
  100. * Less than 2412 uses value of 0, 2412 and above uses value of 2
  101. */
  102. static void ar5008_hw_force_bias(struct ath_hw *ah, u16 synth_freq)
  103. {
  104. struct ath_common *common = ath9k_hw_common(ah);
  105. u32 tmp_reg;
  106. int reg_writes = 0;
  107. u32 new_bias = 0;
  108. if (!AR_SREV_5416(ah) || synth_freq >= 3000)
  109. return;
  110. BUG_ON(AR_SREV_9280_20_OR_LATER(ah));
  111. if (synth_freq < 2412)
  112. new_bias = 0;
  113. else if (synth_freq < 2422)
  114. new_bias = 1;
  115. else
  116. new_bias = 2;
  117. /* pre-reverse this field */
  118. tmp_reg = ath9k_hw_reverse_bits(new_bias, 3);
  119. ath_print(common, ATH_DBG_CONFIG,
  120. "Force rf_pwd_icsyndiv to %1d on %4d\n",
  121. new_bias, synth_freq);
  122. /* swizzle rf_pwd_icsyndiv */
  123. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data, tmp_reg, 3, 181, 3);
  124. /* write Bank 6 with new params */
  125. REG_WRITE_RF_ARRAY(&ah->iniBank6, ah->analogBank6Data, reg_writes);
  126. }
  127. /**
  128. * ar5008_hw_set_channel - tune to a channel on the external AR2133/AR5133 radios
  129. * @ah: atheros hardware stucture
  130. * @chan:
  131. *
  132. * For the external AR2133/AR5133 radios, takes the MHz channel value and set
  133. * the channel value. Assumes writes enabled to analog bus and bank6 register
  134. * cache in ah->analogBank6Data.
  135. */
  136. static int ar5008_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
  137. {
  138. struct ath_common *common = ath9k_hw_common(ah);
  139. u32 channelSel = 0;
  140. u32 bModeSynth = 0;
  141. u32 aModeRefSel = 0;
  142. u32 reg32 = 0;
  143. u16 freq;
  144. struct chan_centers centers;
  145. ath9k_hw_get_channel_centers(ah, chan, &centers);
  146. freq = centers.synth_center;
  147. if (freq < 4800) {
  148. u32 txctl;
  149. if (((freq - 2192) % 5) == 0) {
  150. channelSel = ((freq - 672) * 2 - 3040) / 10;
  151. bModeSynth = 0;
  152. } else if (((freq - 2224) % 5) == 0) {
  153. channelSel = ((freq - 704) * 2 - 3040) / 10;
  154. bModeSynth = 1;
  155. } else {
  156. ath_print(common, ATH_DBG_FATAL,
  157. "Invalid channel %u MHz\n", freq);
  158. return -EINVAL;
  159. }
  160. channelSel = (channelSel << 2) & 0xff;
  161. channelSel = ath9k_hw_reverse_bits(channelSel, 8);
  162. txctl = REG_READ(ah, AR_PHY_CCK_TX_CTRL);
  163. if (freq == 2484) {
  164. REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
  165. txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
  166. } else {
  167. REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
  168. txctl & ~AR_PHY_CCK_TX_CTRL_JAPAN);
  169. }
  170. } else if ((freq % 20) == 0 && freq >= 5120) {
  171. channelSel =
  172. ath9k_hw_reverse_bits(((freq - 4800) / 20 << 2), 8);
  173. aModeRefSel = ath9k_hw_reverse_bits(1, 2);
  174. } else if ((freq % 10) == 0) {
  175. channelSel =
  176. ath9k_hw_reverse_bits(((freq - 4800) / 10 << 1), 8);
  177. if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah))
  178. aModeRefSel = ath9k_hw_reverse_bits(2, 2);
  179. else
  180. aModeRefSel = ath9k_hw_reverse_bits(1, 2);
  181. } else if ((freq % 5) == 0) {
  182. channelSel = ath9k_hw_reverse_bits((freq - 4800) / 5, 8);
  183. aModeRefSel = ath9k_hw_reverse_bits(1, 2);
  184. } else {
  185. ath_print(common, ATH_DBG_FATAL,
  186. "Invalid channel %u MHz\n", freq);
  187. return -EINVAL;
  188. }
  189. ar5008_hw_force_bias(ah, freq);
  190. reg32 =
  191. (channelSel << 8) | (aModeRefSel << 2) | (bModeSynth << 1) |
  192. (1 << 5) | 0x1;
  193. REG_WRITE(ah, AR_PHY(0x37), reg32);
  194. ah->curchan = chan;
  195. ah->curchan_rad_index = -1;
  196. return 0;
  197. }
  198. /**
  199. * ar5008_hw_spur_mitigate - convert baseband spur frequency for external radios
  200. * @ah: atheros hardware structure
  201. * @chan:
  202. *
  203. * For non single-chip solutions. Converts to baseband spur frequency given the
  204. * input channel frequency and compute register settings below.
  205. */
  206. static void ar5008_hw_spur_mitigate(struct ath_hw *ah,
  207. struct ath9k_channel *chan)
  208. {
  209. int bb_spur = AR_NO_SPUR;
  210. int bin, cur_bin;
  211. int spur_freq_sd;
  212. int spur_delta_phase;
  213. int denominator;
  214. int upper, lower, cur_vit_mask;
  215. int tmp, new;
  216. int i;
  217. static int pilot_mask_reg[4] = {
  218. AR_PHY_TIMING7, AR_PHY_TIMING8,
  219. AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
  220. };
  221. static int chan_mask_reg[4] = {
  222. AR_PHY_TIMING9, AR_PHY_TIMING10,
  223. AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
  224. };
  225. static int inc[4] = { 0, 100, 0, 0 };
  226. int8_t mask_m[123];
  227. int8_t mask_p[123];
  228. int8_t mask_amt;
  229. int tmp_mask;
  230. int cur_bb_spur;
  231. bool is2GHz = IS_CHAN_2GHZ(chan);
  232. memset(&mask_m, 0, sizeof(int8_t) * 123);
  233. memset(&mask_p, 0, sizeof(int8_t) * 123);
  234. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  235. cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
  236. if (AR_NO_SPUR == cur_bb_spur)
  237. break;
  238. cur_bb_spur = cur_bb_spur - (chan->channel * 10);
  239. if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
  240. bb_spur = cur_bb_spur;
  241. break;
  242. }
  243. }
  244. if (AR_NO_SPUR == bb_spur)
  245. return;
  246. bin = bb_spur * 32;
  247. tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
  248. new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
  249. AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
  250. AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
  251. AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
  252. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
  253. new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
  254. AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
  255. AR_PHY_SPUR_REG_MASK_RATE_SELECT |
  256. AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
  257. SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
  258. REG_WRITE(ah, AR_PHY_SPUR_REG, new);
  259. spur_delta_phase = ((bb_spur * 524288) / 100) &
  260. AR_PHY_TIMING11_SPUR_DELTA_PHASE;
  261. denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
  262. spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
  263. new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
  264. SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
  265. SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
  266. REG_WRITE(ah, AR_PHY_TIMING11, new);
  267. cur_bin = -6000;
  268. upper = bin + 100;
  269. lower = bin - 100;
  270. for (i = 0; i < 4; i++) {
  271. int pilot_mask = 0;
  272. int chan_mask = 0;
  273. int bp = 0;
  274. for (bp = 0; bp < 30; bp++) {
  275. if ((cur_bin > lower) && (cur_bin < upper)) {
  276. pilot_mask = pilot_mask | 0x1 << bp;
  277. chan_mask = chan_mask | 0x1 << bp;
  278. }
  279. cur_bin += 100;
  280. }
  281. cur_bin += inc[i];
  282. REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
  283. REG_WRITE(ah, chan_mask_reg[i], chan_mask);
  284. }
  285. cur_vit_mask = 6100;
  286. upper = bin + 120;
  287. lower = bin - 120;
  288. for (i = 0; i < 123; i++) {
  289. if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
  290. /* workaround for gcc bug #37014 */
  291. volatile int tmp_v = abs(cur_vit_mask - bin);
  292. if (tmp_v < 75)
  293. mask_amt = 1;
  294. else
  295. mask_amt = 0;
  296. if (cur_vit_mask < 0)
  297. mask_m[abs(cur_vit_mask / 100)] = mask_amt;
  298. else
  299. mask_p[cur_vit_mask / 100] = mask_amt;
  300. }
  301. cur_vit_mask -= 100;
  302. }
  303. tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
  304. | (mask_m[48] << 26) | (mask_m[49] << 24)
  305. | (mask_m[50] << 22) | (mask_m[51] << 20)
  306. | (mask_m[52] << 18) | (mask_m[53] << 16)
  307. | (mask_m[54] << 14) | (mask_m[55] << 12)
  308. | (mask_m[56] << 10) | (mask_m[57] << 8)
  309. | (mask_m[58] << 6) | (mask_m[59] << 4)
  310. | (mask_m[60] << 2) | (mask_m[61] << 0);
  311. REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
  312. REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
  313. tmp_mask = (mask_m[31] << 28)
  314. | (mask_m[32] << 26) | (mask_m[33] << 24)
  315. | (mask_m[34] << 22) | (mask_m[35] << 20)
  316. | (mask_m[36] << 18) | (mask_m[37] << 16)
  317. | (mask_m[48] << 14) | (mask_m[39] << 12)
  318. | (mask_m[40] << 10) | (mask_m[41] << 8)
  319. | (mask_m[42] << 6) | (mask_m[43] << 4)
  320. | (mask_m[44] << 2) | (mask_m[45] << 0);
  321. REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
  322. REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
  323. tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
  324. | (mask_m[18] << 26) | (mask_m[18] << 24)
  325. | (mask_m[20] << 22) | (mask_m[20] << 20)
  326. | (mask_m[22] << 18) | (mask_m[22] << 16)
  327. | (mask_m[24] << 14) | (mask_m[24] << 12)
  328. | (mask_m[25] << 10) | (mask_m[26] << 8)
  329. | (mask_m[27] << 6) | (mask_m[28] << 4)
  330. | (mask_m[29] << 2) | (mask_m[30] << 0);
  331. REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
  332. REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
  333. tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
  334. | (mask_m[2] << 26) | (mask_m[3] << 24)
  335. | (mask_m[4] << 22) | (mask_m[5] << 20)
  336. | (mask_m[6] << 18) | (mask_m[7] << 16)
  337. | (mask_m[8] << 14) | (mask_m[9] << 12)
  338. | (mask_m[10] << 10) | (mask_m[11] << 8)
  339. | (mask_m[12] << 6) | (mask_m[13] << 4)
  340. | (mask_m[14] << 2) | (mask_m[15] << 0);
  341. REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
  342. REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
  343. tmp_mask = (mask_p[15] << 28)
  344. | (mask_p[14] << 26) | (mask_p[13] << 24)
  345. | (mask_p[12] << 22) | (mask_p[11] << 20)
  346. | (mask_p[10] << 18) | (mask_p[9] << 16)
  347. | (mask_p[8] << 14) | (mask_p[7] << 12)
  348. | (mask_p[6] << 10) | (mask_p[5] << 8)
  349. | (mask_p[4] << 6) | (mask_p[3] << 4)
  350. | (mask_p[2] << 2) | (mask_p[1] << 0);
  351. REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
  352. REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
  353. tmp_mask = (mask_p[30] << 28)
  354. | (mask_p[29] << 26) | (mask_p[28] << 24)
  355. | (mask_p[27] << 22) | (mask_p[26] << 20)
  356. | (mask_p[25] << 18) | (mask_p[24] << 16)
  357. | (mask_p[23] << 14) | (mask_p[22] << 12)
  358. | (mask_p[21] << 10) | (mask_p[20] << 8)
  359. | (mask_p[19] << 6) | (mask_p[18] << 4)
  360. | (mask_p[17] << 2) | (mask_p[16] << 0);
  361. REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
  362. REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
  363. tmp_mask = (mask_p[45] << 28)
  364. | (mask_p[44] << 26) | (mask_p[43] << 24)
  365. | (mask_p[42] << 22) | (mask_p[41] << 20)
  366. | (mask_p[40] << 18) | (mask_p[39] << 16)
  367. | (mask_p[38] << 14) | (mask_p[37] << 12)
  368. | (mask_p[36] << 10) | (mask_p[35] << 8)
  369. | (mask_p[34] << 6) | (mask_p[33] << 4)
  370. | (mask_p[32] << 2) | (mask_p[31] << 0);
  371. REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
  372. REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
  373. tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
  374. | (mask_p[59] << 26) | (mask_p[58] << 24)
  375. | (mask_p[57] << 22) | (mask_p[56] << 20)
  376. | (mask_p[55] << 18) | (mask_p[54] << 16)
  377. | (mask_p[53] << 14) | (mask_p[52] << 12)
  378. | (mask_p[51] << 10) | (mask_p[50] << 8)
  379. | (mask_p[49] << 6) | (mask_p[48] << 4)
  380. | (mask_p[47] << 2) | (mask_p[46] << 0);
  381. REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
  382. REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
  383. }
  384. /**
  385. * ar5008_hw_rf_alloc_ext_banks - allocates banks for external radio programming
  386. * @ah: atheros hardware structure
  387. *
  388. * Only required for older devices with external AR2133/AR5133 radios.
  389. */
  390. static int ar5008_hw_rf_alloc_ext_banks(struct ath_hw *ah)
  391. {
  392. #define ATH_ALLOC_BANK(bank, size) do { \
  393. bank = kzalloc((sizeof(u32) * size), GFP_KERNEL); \
  394. if (!bank) { \
  395. ath_print(common, ATH_DBG_FATAL, \
  396. "Cannot allocate RF banks\n"); \
  397. return -ENOMEM; \
  398. } \
  399. } while (0);
  400. struct ath_common *common = ath9k_hw_common(ah);
  401. BUG_ON(AR_SREV_9280_20_OR_LATER(ah));
  402. ATH_ALLOC_BANK(ah->analogBank0Data, ah->iniBank0.ia_rows);
  403. ATH_ALLOC_BANK(ah->analogBank1Data, ah->iniBank1.ia_rows);
  404. ATH_ALLOC_BANK(ah->analogBank2Data, ah->iniBank2.ia_rows);
  405. ATH_ALLOC_BANK(ah->analogBank3Data, ah->iniBank3.ia_rows);
  406. ATH_ALLOC_BANK(ah->analogBank6Data, ah->iniBank6.ia_rows);
  407. ATH_ALLOC_BANK(ah->analogBank6TPCData, ah->iniBank6TPC.ia_rows);
  408. ATH_ALLOC_BANK(ah->analogBank7Data, ah->iniBank7.ia_rows);
  409. ATH_ALLOC_BANK(ah->addac5416_21,
  410. ah->iniAddac.ia_rows * ah->iniAddac.ia_columns);
  411. ATH_ALLOC_BANK(ah->bank6Temp, ah->iniBank6.ia_rows);
  412. return 0;
  413. #undef ATH_ALLOC_BANK
  414. }
  415. /**
  416. * ar5008_hw_rf_free_ext_banks - Free memory for analog bank scratch buffers
  417. * @ah: atheros hardware struture
  418. * For the external AR2133/AR5133 radios banks.
  419. */
  420. static void ar5008_hw_rf_free_ext_banks(struct ath_hw *ah)
  421. {
  422. #define ATH_FREE_BANK(bank) do { \
  423. kfree(bank); \
  424. bank = NULL; \
  425. } while (0);
  426. BUG_ON(AR_SREV_9280_20_OR_LATER(ah));
  427. ATH_FREE_BANK(ah->analogBank0Data);
  428. ATH_FREE_BANK(ah->analogBank1Data);
  429. ATH_FREE_BANK(ah->analogBank2Data);
  430. ATH_FREE_BANK(ah->analogBank3Data);
  431. ATH_FREE_BANK(ah->analogBank6Data);
  432. ATH_FREE_BANK(ah->analogBank6TPCData);
  433. ATH_FREE_BANK(ah->analogBank7Data);
  434. ATH_FREE_BANK(ah->addac5416_21);
  435. ATH_FREE_BANK(ah->bank6Temp);
  436. #undef ATH_FREE_BANK
  437. }
  438. /* *
  439. * ar5008_hw_set_rf_regs - programs rf registers based on EEPROM
  440. * @ah: atheros hardware structure
  441. * @chan:
  442. * @modesIndex:
  443. *
  444. * Used for the external AR2133/AR5133 radios.
  445. *
  446. * Reads the EEPROM header info from the device structure and programs
  447. * all rf registers. This routine requires access to the analog
  448. * rf device. This is not required for single-chip devices.
  449. */
  450. static bool ar5008_hw_set_rf_regs(struct ath_hw *ah,
  451. struct ath9k_channel *chan,
  452. u16 modesIndex)
  453. {
  454. u32 eepMinorRev;
  455. u32 ob5GHz = 0, db5GHz = 0;
  456. u32 ob2GHz = 0, db2GHz = 0;
  457. int regWrites = 0;
  458. /*
  459. * Software does not need to program bank data
  460. * for single chip devices, that is AR9280 or anything
  461. * after that.
  462. */
  463. if (AR_SREV_9280_20_OR_LATER(ah))
  464. return true;
  465. /* Setup rf parameters */
  466. eepMinorRev = ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV);
  467. /* Setup Bank 0 Write */
  468. RF_BANK_SETUP(ah->analogBank0Data, &ah->iniBank0, 1);
  469. /* Setup Bank 1 Write */
  470. RF_BANK_SETUP(ah->analogBank1Data, &ah->iniBank1, 1);
  471. /* Setup Bank 2 Write */
  472. RF_BANK_SETUP(ah->analogBank2Data, &ah->iniBank2, 1);
  473. /* Setup Bank 6 Write */
  474. RF_BANK_SETUP(ah->analogBank3Data, &ah->iniBank3,
  475. modesIndex);
  476. {
  477. int i;
  478. for (i = 0; i < ah->iniBank6TPC.ia_rows; i++) {
  479. ah->analogBank6Data[i] =
  480. INI_RA(&ah->iniBank6TPC, i, modesIndex);
  481. }
  482. }
  483. /* Only the 5 or 2 GHz OB/DB need to be set for a mode */
  484. if (eepMinorRev >= 2) {
  485. if (IS_CHAN_2GHZ(chan)) {
  486. ob2GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_2);
  487. db2GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_2);
  488. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
  489. ob2GHz, 3, 197, 0);
  490. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
  491. db2GHz, 3, 194, 0);
  492. } else {
  493. ob5GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_5);
  494. db5GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_5);
  495. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
  496. ob5GHz, 3, 203, 0);
  497. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
  498. db5GHz, 3, 200, 0);
  499. }
  500. }
  501. /* Setup Bank 7 Setup */
  502. RF_BANK_SETUP(ah->analogBank7Data, &ah->iniBank7, 1);
  503. /* Write Analog registers */
  504. REG_WRITE_RF_ARRAY(&ah->iniBank0, ah->analogBank0Data,
  505. regWrites);
  506. REG_WRITE_RF_ARRAY(&ah->iniBank1, ah->analogBank1Data,
  507. regWrites);
  508. REG_WRITE_RF_ARRAY(&ah->iniBank2, ah->analogBank2Data,
  509. regWrites);
  510. REG_WRITE_RF_ARRAY(&ah->iniBank3, ah->analogBank3Data,
  511. regWrites);
  512. REG_WRITE_RF_ARRAY(&ah->iniBank6TPC, ah->analogBank6Data,
  513. regWrites);
  514. REG_WRITE_RF_ARRAY(&ah->iniBank7, ah->analogBank7Data,
  515. regWrites);
  516. return true;
  517. }
  518. static void ar5008_hw_init_bb(struct ath_hw *ah,
  519. struct ath9k_channel *chan)
  520. {
  521. u32 synthDelay;
  522. synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  523. if (IS_CHAN_B(chan))
  524. synthDelay = (4 * synthDelay) / 22;
  525. else
  526. synthDelay /= 10;
  527. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
  528. udelay(synthDelay + BASE_ACTIVATE_DELAY);
  529. }
  530. static void ar5008_hw_init_chain_masks(struct ath_hw *ah)
  531. {
  532. int rx_chainmask, tx_chainmask;
  533. rx_chainmask = ah->rxchainmask;
  534. tx_chainmask = ah->txchainmask;
  535. switch (rx_chainmask) {
  536. case 0x5:
  537. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  538. AR_PHY_SWAP_ALT_CHAIN);
  539. case 0x3:
  540. if (ah->hw_version.macVersion == AR_SREV_REVISION_5416_10) {
  541. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
  542. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
  543. break;
  544. }
  545. case 0x1:
  546. case 0x2:
  547. case 0x7:
  548. ENABLE_REGWRITE_BUFFER(ah);
  549. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
  550. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
  551. break;
  552. default:
  553. ENABLE_REGWRITE_BUFFER(ah);
  554. break;
  555. }
  556. REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
  557. REGWRITE_BUFFER_FLUSH(ah);
  558. if (tx_chainmask == 0x5) {
  559. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  560. AR_PHY_SWAP_ALT_CHAIN);
  561. }
  562. if (AR_SREV_9100(ah))
  563. REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
  564. REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
  565. }
  566. static void ar5008_hw_override_ini(struct ath_hw *ah,
  567. struct ath9k_channel *chan)
  568. {
  569. u32 val;
  570. /*
  571. * Set the RX_ABORT and RX_DIS and clear if off only after
  572. * RXE is set for MAC. This prevents frames with corrupted
  573. * descriptor status.
  574. */
  575. REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  576. if (AR_SREV_9280_20_OR_LATER(ah)) {
  577. val = REG_READ(ah, AR_PCU_MISC_MODE2);
  578. if (!AR_SREV_9271(ah))
  579. val &= ~AR_PCU_MISC_MODE2_HWWAR1;
  580. if (AR_SREV_9287_11_OR_LATER(ah))
  581. val = val & (~AR_PCU_MISC_MODE2_HWWAR2);
  582. REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
  583. }
  584. if (!AR_SREV_5416_20_OR_LATER(ah) ||
  585. AR_SREV_9280_20_OR_LATER(ah))
  586. return;
  587. /*
  588. * Disable BB clock gating
  589. * Necessary to avoid issues on AR5416 2.0
  590. */
  591. REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
  592. /*
  593. * Disable RIFS search on some chips to avoid baseband
  594. * hang issues.
  595. */
  596. if (AR_SREV_9100(ah) || AR_SREV_9160(ah)) {
  597. val = REG_READ(ah, AR_PHY_HEAVY_CLIP_FACTOR_RIFS);
  598. val &= ~AR_PHY_RIFS_INIT_DELAY;
  599. REG_WRITE(ah, AR_PHY_HEAVY_CLIP_FACTOR_RIFS, val);
  600. }
  601. }
  602. static void ar5008_hw_set_channel_regs(struct ath_hw *ah,
  603. struct ath9k_channel *chan)
  604. {
  605. u32 phymode;
  606. u32 enableDacFifo = 0;
  607. if (AR_SREV_9285_12_OR_LATER(ah))
  608. enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
  609. AR_PHY_FC_ENABLE_DAC_FIFO);
  610. phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
  611. | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
  612. if (IS_CHAN_HT40(chan)) {
  613. phymode |= AR_PHY_FC_DYN2040_EN;
  614. if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
  615. (chan->chanmode == CHANNEL_G_HT40PLUS))
  616. phymode |= AR_PHY_FC_DYN2040_PRI_CH;
  617. }
  618. REG_WRITE(ah, AR_PHY_TURBO, phymode);
  619. ath9k_hw_set11nmac2040(ah);
  620. ENABLE_REGWRITE_BUFFER(ah);
  621. REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
  622. REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
  623. REGWRITE_BUFFER_FLUSH(ah);
  624. }
  625. static int ar5008_hw_process_ini(struct ath_hw *ah,
  626. struct ath9k_channel *chan)
  627. {
  628. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  629. int i, regWrites = 0;
  630. struct ieee80211_channel *channel = chan->chan;
  631. u32 modesIndex, freqIndex;
  632. switch (chan->chanmode) {
  633. case CHANNEL_A:
  634. case CHANNEL_A_HT20:
  635. modesIndex = 1;
  636. freqIndex = 1;
  637. break;
  638. case CHANNEL_A_HT40PLUS:
  639. case CHANNEL_A_HT40MINUS:
  640. modesIndex = 2;
  641. freqIndex = 1;
  642. break;
  643. case CHANNEL_G:
  644. case CHANNEL_G_HT20:
  645. case CHANNEL_B:
  646. modesIndex = 4;
  647. freqIndex = 2;
  648. break;
  649. case CHANNEL_G_HT40PLUS:
  650. case CHANNEL_G_HT40MINUS:
  651. modesIndex = 3;
  652. freqIndex = 2;
  653. break;
  654. default:
  655. return -EINVAL;
  656. }
  657. /*
  658. * Set correct baseband to analog shift setting to
  659. * access analog chips.
  660. */
  661. REG_WRITE(ah, AR_PHY(0), 0x00000007);
  662. /* Write ADDAC shifts */
  663. REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
  664. ah->eep_ops->set_addac(ah, chan);
  665. if (AR_SREV_5416_22_OR_LATER(ah)) {
  666. REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
  667. } else {
  668. struct ar5416IniArray temp;
  669. u32 addacSize =
  670. sizeof(u32) * ah->iniAddac.ia_rows *
  671. ah->iniAddac.ia_columns;
  672. /* For AR5416 2.0/2.1 */
  673. memcpy(ah->addac5416_21,
  674. ah->iniAddac.ia_array, addacSize);
  675. /* override CLKDRV value at [row, column] = [31, 1] */
  676. (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0;
  677. temp.ia_array = ah->addac5416_21;
  678. temp.ia_columns = ah->iniAddac.ia_columns;
  679. temp.ia_rows = ah->iniAddac.ia_rows;
  680. REG_WRITE_ARRAY(&temp, 1, regWrites);
  681. }
  682. REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
  683. ENABLE_REGWRITE_BUFFER(ah);
  684. for (i = 0; i < ah->iniModes.ia_rows; i++) {
  685. u32 reg = INI_RA(&ah->iniModes, i, 0);
  686. u32 val = INI_RA(&ah->iniModes, i, modesIndex);
  687. if (reg == AR_AN_TOP2 && ah->need_an_top2_fixup)
  688. val &= ~AR_AN_TOP2_PWDCLKIND;
  689. REG_WRITE(ah, reg, val);
  690. if (reg >= 0x7800 && reg < 0x78a0
  691. && ah->config.analog_shiftreg) {
  692. udelay(100);
  693. }
  694. DO_DELAY(regWrites);
  695. }
  696. REGWRITE_BUFFER_FLUSH(ah);
  697. if (AR_SREV_9280(ah) || AR_SREV_9287_11_OR_LATER(ah))
  698. REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
  699. if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) ||
  700. AR_SREV_9287_11_OR_LATER(ah))
  701. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  702. if (AR_SREV_9271_10(ah))
  703. REG_WRITE_ARRAY(&ah->iniModes_9271_1_0_only,
  704. modesIndex, regWrites);
  705. ENABLE_REGWRITE_BUFFER(ah);
  706. /* Write common array parameters */
  707. for (i = 0; i < ah->iniCommon.ia_rows; i++) {
  708. u32 reg = INI_RA(&ah->iniCommon, i, 0);
  709. u32 val = INI_RA(&ah->iniCommon, i, 1);
  710. REG_WRITE(ah, reg, val);
  711. if (reg >= 0x7800 && reg < 0x78a0
  712. && ah->config.analog_shiftreg) {
  713. udelay(100);
  714. }
  715. DO_DELAY(regWrites);
  716. }
  717. REGWRITE_BUFFER_FLUSH(ah);
  718. if (AR_SREV_9271(ah)) {
  719. if (ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE) == 1)
  720. REG_WRITE_ARRAY(&ah->iniModes_high_power_tx_gain_9271,
  721. modesIndex, regWrites);
  722. else
  723. REG_WRITE_ARRAY(&ah->iniModes_normal_power_tx_gain_9271,
  724. modesIndex, regWrites);
  725. }
  726. REG_WRITE_ARRAY(&ah->iniBB_RfGain, freqIndex, regWrites);
  727. if (IS_CHAN_A_FAST_CLOCK(ah, chan)) {
  728. REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex,
  729. regWrites);
  730. }
  731. ar5008_hw_override_ini(ah, chan);
  732. ar5008_hw_set_channel_regs(ah, chan);
  733. ar5008_hw_init_chain_masks(ah);
  734. ath9k_olc_init(ah);
  735. /* Set TX power */
  736. ah->eep_ops->set_txpower(ah, chan,
  737. ath9k_regd_get_ctl(regulatory, chan),
  738. channel->max_antenna_gain * 2,
  739. channel->max_power * 2,
  740. min((u32) MAX_RATE_POWER,
  741. (u32) regulatory->power_limit), false);
  742. /* Write analog registers */
  743. if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
  744. ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
  745. "ar5416SetRfRegs failed\n");
  746. return -EIO;
  747. }
  748. return 0;
  749. }
  750. static void ar5008_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
  751. {
  752. u32 rfMode = 0;
  753. if (chan == NULL)
  754. return;
  755. rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
  756. ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
  757. if (!AR_SREV_9280_20_OR_LATER(ah))
  758. rfMode |= (IS_CHAN_5GHZ(chan)) ?
  759. AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
  760. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  761. rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
  762. REG_WRITE(ah, AR_PHY_MODE, rfMode);
  763. }
  764. static void ar5008_hw_mark_phy_inactive(struct ath_hw *ah)
  765. {
  766. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
  767. }
  768. static void ar5008_hw_set_delta_slope(struct ath_hw *ah,
  769. struct ath9k_channel *chan)
  770. {
  771. u32 coef_scaled, ds_coef_exp, ds_coef_man;
  772. u32 clockMhzScaled = 0x64000000;
  773. struct chan_centers centers;
  774. if (IS_CHAN_HALF_RATE(chan))
  775. clockMhzScaled = clockMhzScaled >> 1;
  776. else if (IS_CHAN_QUARTER_RATE(chan))
  777. clockMhzScaled = clockMhzScaled >> 2;
  778. ath9k_hw_get_channel_centers(ah, chan, &centers);
  779. coef_scaled = clockMhzScaled / centers.synth_center;
  780. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  781. &ds_coef_exp);
  782. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  783. AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
  784. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  785. AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
  786. coef_scaled = (9 * coef_scaled) / 10;
  787. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  788. &ds_coef_exp);
  789. REG_RMW_FIELD(ah, AR_PHY_HALFGI,
  790. AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
  791. REG_RMW_FIELD(ah, AR_PHY_HALFGI,
  792. AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
  793. }
  794. static bool ar5008_hw_rfbus_req(struct ath_hw *ah)
  795. {
  796. REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
  797. return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
  798. AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT);
  799. }
  800. static void ar5008_hw_rfbus_done(struct ath_hw *ah)
  801. {
  802. u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  803. if (IS_CHAN_B(ah->curchan))
  804. synthDelay = (4 * synthDelay) / 22;
  805. else
  806. synthDelay /= 10;
  807. udelay(synthDelay + BASE_ACTIVATE_DELAY);
  808. REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
  809. }
  810. static void ar5008_hw_enable_rfkill(struct ath_hw *ah)
  811. {
  812. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
  813. AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
  814. REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
  815. AR_GPIO_INPUT_MUX2_RFSILENT);
  816. ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
  817. REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
  818. }
  819. static void ar5008_restore_chainmask(struct ath_hw *ah)
  820. {
  821. int rx_chainmask = ah->rxchainmask;
  822. if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
  823. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
  824. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
  825. }
  826. }
  827. static void ar5008_set_diversity(struct ath_hw *ah, bool value)
  828. {
  829. u32 v = REG_READ(ah, AR_PHY_CCK_DETECT);
  830. if (value)
  831. v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
  832. else
  833. v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
  834. REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
  835. }
  836. static u32 ar9100_hw_compute_pll_control(struct ath_hw *ah,
  837. struct ath9k_channel *chan)
  838. {
  839. if (chan && IS_CHAN_5GHZ(chan))
  840. return 0x1450;
  841. return 0x1458;
  842. }
  843. static u32 ar9160_hw_compute_pll_control(struct ath_hw *ah,
  844. struct ath9k_channel *chan)
  845. {
  846. u32 pll;
  847. pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
  848. if (chan && IS_CHAN_HALF_RATE(chan))
  849. pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
  850. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  851. pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
  852. if (chan && IS_CHAN_5GHZ(chan))
  853. pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
  854. else
  855. pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
  856. return pll;
  857. }
  858. static u32 ar5008_hw_compute_pll_control(struct ath_hw *ah,
  859. struct ath9k_channel *chan)
  860. {
  861. u32 pll;
  862. pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
  863. if (chan && IS_CHAN_HALF_RATE(chan))
  864. pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
  865. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  866. pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
  867. if (chan && IS_CHAN_5GHZ(chan))
  868. pll |= SM(0xa, AR_RTC_PLL_DIV);
  869. else
  870. pll |= SM(0xb, AR_RTC_PLL_DIV);
  871. return pll;
  872. }
  873. static bool ar5008_hw_ani_control_old(struct ath_hw *ah,
  874. enum ath9k_ani_cmd cmd,
  875. int param)
  876. {
  877. struct ar5416AniState *aniState = &ah->curchan->ani;
  878. struct ath_common *common = ath9k_hw_common(ah);
  879. switch (cmd & ah->ani_function) {
  880. case ATH9K_ANI_NOISE_IMMUNITY_LEVEL:{
  881. u32 level = param;
  882. if (level >= ARRAY_SIZE(ah->totalSizeDesired)) {
  883. ath_print(common, ATH_DBG_ANI,
  884. "level out of range (%u > %u)\n",
  885. level,
  886. (unsigned)ARRAY_SIZE(ah->totalSizeDesired));
  887. return false;
  888. }
  889. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
  890. AR_PHY_DESIRED_SZ_TOT_DES,
  891. ah->totalSizeDesired[level]);
  892. REG_RMW_FIELD(ah, AR_PHY_AGC_CTL1,
  893. AR_PHY_AGC_CTL1_COARSE_LOW,
  894. ah->coarse_low[level]);
  895. REG_RMW_FIELD(ah, AR_PHY_AGC_CTL1,
  896. AR_PHY_AGC_CTL1_COARSE_HIGH,
  897. ah->coarse_high[level]);
  898. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  899. AR_PHY_FIND_SIG_FIRPWR,
  900. ah->firpwr[level]);
  901. if (level > aniState->noiseImmunityLevel)
  902. ah->stats.ast_ani_niup++;
  903. else if (level < aniState->noiseImmunityLevel)
  904. ah->stats.ast_ani_nidown++;
  905. aniState->noiseImmunityLevel = level;
  906. break;
  907. }
  908. case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
  909. static const int m1ThreshLow[] = { 127, 50 };
  910. static const int m2ThreshLow[] = { 127, 40 };
  911. static const int m1Thresh[] = { 127, 0x4d };
  912. static const int m2Thresh[] = { 127, 0x40 };
  913. static const int m2CountThr[] = { 31, 16 };
  914. static const int m2CountThrLow[] = { 63, 48 };
  915. u32 on = param ? 1 : 0;
  916. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  917. AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
  918. m1ThreshLow[on]);
  919. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  920. AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
  921. m2ThreshLow[on]);
  922. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  923. AR_PHY_SFCORR_M1_THRESH,
  924. m1Thresh[on]);
  925. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  926. AR_PHY_SFCORR_M2_THRESH,
  927. m2Thresh[on]);
  928. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  929. AR_PHY_SFCORR_M2COUNT_THR,
  930. m2CountThr[on]);
  931. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  932. AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
  933. m2CountThrLow[on]);
  934. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  935. AR_PHY_SFCORR_EXT_M1_THRESH_LOW,
  936. m1ThreshLow[on]);
  937. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  938. AR_PHY_SFCORR_EXT_M2_THRESH_LOW,
  939. m2ThreshLow[on]);
  940. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  941. AR_PHY_SFCORR_EXT_M1_THRESH,
  942. m1Thresh[on]);
  943. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  944. AR_PHY_SFCORR_EXT_M2_THRESH,
  945. m2Thresh[on]);
  946. if (on)
  947. REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
  948. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  949. else
  950. REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
  951. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  952. if (!on != aniState->ofdmWeakSigDetectOff) {
  953. if (on)
  954. ah->stats.ast_ani_ofdmon++;
  955. else
  956. ah->stats.ast_ani_ofdmoff++;
  957. aniState->ofdmWeakSigDetectOff = !on;
  958. }
  959. break;
  960. }
  961. case ATH9K_ANI_CCK_WEAK_SIGNAL_THR:{
  962. static const int weakSigThrCck[] = { 8, 6 };
  963. u32 high = param ? 1 : 0;
  964. REG_RMW_FIELD(ah, AR_PHY_CCK_DETECT,
  965. AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK,
  966. weakSigThrCck[high]);
  967. if (high != aniState->cckWeakSigThreshold) {
  968. if (high)
  969. ah->stats.ast_ani_cckhigh++;
  970. else
  971. ah->stats.ast_ani_ccklow++;
  972. aniState->cckWeakSigThreshold = high;
  973. }
  974. break;
  975. }
  976. case ATH9K_ANI_FIRSTEP_LEVEL:{
  977. static const int firstep[] = { 0, 4, 8 };
  978. u32 level = param;
  979. if (level >= ARRAY_SIZE(firstep)) {
  980. ath_print(common, ATH_DBG_ANI,
  981. "level out of range (%u > %u)\n",
  982. level,
  983. (unsigned) ARRAY_SIZE(firstep));
  984. return false;
  985. }
  986. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  987. AR_PHY_FIND_SIG_FIRSTEP,
  988. firstep[level]);
  989. if (level > aniState->firstepLevel)
  990. ah->stats.ast_ani_stepup++;
  991. else if (level < aniState->firstepLevel)
  992. ah->stats.ast_ani_stepdown++;
  993. aniState->firstepLevel = level;
  994. break;
  995. }
  996. case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
  997. static const int cycpwrThr1[] = { 2, 4, 6, 8, 10, 12, 14, 16 };
  998. u32 level = param;
  999. if (level >= ARRAY_SIZE(cycpwrThr1)) {
  1000. ath_print(common, ATH_DBG_ANI,
  1001. "level out of range (%u > %u)\n",
  1002. level,
  1003. (unsigned) ARRAY_SIZE(cycpwrThr1));
  1004. return false;
  1005. }
  1006. REG_RMW_FIELD(ah, AR_PHY_TIMING5,
  1007. AR_PHY_TIMING5_CYCPWR_THR1,
  1008. cycpwrThr1[level]);
  1009. if (level > aniState->spurImmunityLevel)
  1010. ah->stats.ast_ani_spurup++;
  1011. else if (level < aniState->spurImmunityLevel)
  1012. ah->stats.ast_ani_spurdown++;
  1013. aniState->spurImmunityLevel = level;
  1014. break;
  1015. }
  1016. case ATH9K_ANI_PRESENT:
  1017. break;
  1018. default:
  1019. ath_print(common, ATH_DBG_ANI,
  1020. "invalid cmd %u\n", cmd);
  1021. return false;
  1022. }
  1023. ath_print(common, ATH_DBG_ANI, "ANI parameters:\n");
  1024. ath_print(common, ATH_DBG_ANI,
  1025. "noiseImmunityLevel=%d, spurImmunityLevel=%d, "
  1026. "ofdmWeakSigDetectOff=%d\n",
  1027. aniState->noiseImmunityLevel,
  1028. aniState->spurImmunityLevel,
  1029. !aniState->ofdmWeakSigDetectOff);
  1030. ath_print(common, ATH_DBG_ANI,
  1031. "cckWeakSigThreshold=%d, "
  1032. "firstepLevel=%d, listenTime=%d\n",
  1033. aniState->cckWeakSigThreshold,
  1034. aniState->firstepLevel,
  1035. aniState->listenTime);
  1036. ath_print(common, ATH_DBG_ANI,
  1037. "ofdmPhyErrCount=%d, cckPhyErrCount=%d\n\n",
  1038. aniState->ofdmPhyErrCount,
  1039. aniState->cckPhyErrCount);
  1040. return true;
  1041. }
  1042. static bool ar5008_hw_ani_control_new(struct ath_hw *ah,
  1043. enum ath9k_ani_cmd cmd,
  1044. int param)
  1045. {
  1046. struct ath_common *common = ath9k_hw_common(ah);
  1047. struct ath9k_channel *chan = ah->curchan;
  1048. struct ar5416AniState *aniState = &chan->ani;
  1049. s32 value, value2;
  1050. switch (cmd & ah->ani_function) {
  1051. case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
  1052. /*
  1053. * on == 1 means ofdm weak signal detection is ON
  1054. * on == 1 is the default, for less noise immunity
  1055. *
  1056. * on == 0 means ofdm weak signal detection is OFF
  1057. * on == 0 means more noise imm
  1058. */
  1059. u32 on = param ? 1 : 0;
  1060. /*
  1061. * make register setting for default
  1062. * (weak sig detect ON) come from INI file
  1063. */
  1064. int m1ThreshLow = on ?
  1065. aniState->iniDef.m1ThreshLow : m1ThreshLow_off;
  1066. int m2ThreshLow = on ?
  1067. aniState->iniDef.m2ThreshLow : m2ThreshLow_off;
  1068. int m1Thresh = on ?
  1069. aniState->iniDef.m1Thresh : m1Thresh_off;
  1070. int m2Thresh = on ?
  1071. aniState->iniDef.m2Thresh : m2Thresh_off;
  1072. int m2CountThr = on ?
  1073. aniState->iniDef.m2CountThr : m2CountThr_off;
  1074. int m2CountThrLow = on ?
  1075. aniState->iniDef.m2CountThrLow : m2CountThrLow_off;
  1076. int m1ThreshLowExt = on ?
  1077. aniState->iniDef.m1ThreshLowExt : m1ThreshLowExt_off;
  1078. int m2ThreshLowExt = on ?
  1079. aniState->iniDef.m2ThreshLowExt : m2ThreshLowExt_off;
  1080. int m1ThreshExt = on ?
  1081. aniState->iniDef.m1ThreshExt : m1ThreshExt_off;
  1082. int m2ThreshExt = on ?
  1083. aniState->iniDef.m2ThreshExt : m2ThreshExt_off;
  1084. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  1085. AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
  1086. m1ThreshLow);
  1087. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  1088. AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
  1089. m2ThreshLow);
  1090. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  1091. AR_PHY_SFCORR_M1_THRESH, m1Thresh);
  1092. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  1093. AR_PHY_SFCORR_M2_THRESH, m2Thresh);
  1094. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  1095. AR_PHY_SFCORR_M2COUNT_THR, m2CountThr);
  1096. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  1097. AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
  1098. m2CountThrLow);
  1099. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  1100. AR_PHY_SFCORR_EXT_M1_THRESH_LOW, m1ThreshLowExt);
  1101. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  1102. AR_PHY_SFCORR_EXT_M2_THRESH_LOW, m2ThreshLowExt);
  1103. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  1104. AR_PHY_SFCORR_EXT_M1_THRESH, m1ThreshExt);
  1105. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  1106. AR_PHY_SFCORR_EXT_M2_THRESH, m2ThreshExt);
  1107. if (on)
  1108. REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
  1109. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  1110. else
  1111. REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
  1112. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  1113. if (!on != aniState->ofdmWeakSigDetectOff) {
  1114. ath_print(common, ATH_DBG_ANI,
  1115. "** ch %d: ofdm weak signal: %s=>%s\n",
  1116. chan->channel,
  1117. !aniState->ofdmWeakSigDetectOff ?
  1118. "on" : "off",
  1119. on ? "on" : "off");
  1120. if (on)
  1121. ah->stats.ast_ani_ofdmon++;
  1122. else
  1123. ah->stats.ast_ani_ofdmoff++;
  1124. aniState->ofdmWeakSigDetectOff = !on;
  1125. }
  1126. break;
  1127. }
  1128. case ATH9K_ANI_FIRSTEP_LEVEL:{
  1129. u32 level = param;
  1130. if (level >= ARRAY_SIZE(firstep_table)) {
  1131. ath_print(common, ATH_DBG_ANI,
  1132. "ATH9K_ANI_FIRSTEP_LEVEL: level "
  1133. "out of range (%u > %u)\n",
  1134. level,
  1135. (unsigned) ARRAY_SIZE(firstep_table));
  1136. return false;
  1137. }
  1138. /*
  1139. * make register setting relative to default
  1140. * from INI file & cap value
  1141. */
  1142. value = firstep_table[level] -
  1143. firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
  1144. aniState->iniDef.firstep;
  1145. if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  1146. value = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  1147. if (value > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  1148. value = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  1149. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  1150. AR_PHY_FIND_SIG_FIRSTEP,
  1151. value);
  1152. /*
  1153. * we need to set first step low register too
  1154. * make register setting relative to default
  1155. * from INI file & cap value
  1156. */
  1157. value2 = firstep_table[level] -
  1158. firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
  1159. aniState->iniDef.firstepLow;
  1160. if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  1161. value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  1162. if (value2 > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  1163. value2 = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  1164. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
  1165. AR_PHY_FIND_SIG_FIRSTEP_LOW, value2);
  1166. if (level != aniState->firstepLevel) {
  1167. ath_print(common, ATH_DBG_ANI,
  1168. "** ch %d: level %d=>%d[def:%d] "
  1169. "firstep[level]=%d ini=%d\n",
  1170. chan->channel,
  1171. aniState->firstepLevel,
  1172. level,
  1173. ATH9K_ANI_FIRSTEP_LVL_NEW,
  1174. value,
  1175. aniState->iniDef.firstep);
  1176. ath_print(common, ATH_DBG_ANI,
  1177. "** ch %d: level %d=>%d[def:%d] "
  1178. "firstep_low[level]=%d ini=%d\n",
  1179. chan->channel,
  1180. aniState->firstepLevel,
  1181. level,
  1182. ATH9K_ANI_FIRSTEP_LVL_NEW,
  1183. value2,
  1184. aniState->iniDef.firstepLow);
  1185. if (level > aniState->firstepLevel)
  1186. ah->stats.ast_ani_stepup++;
  1187. else if (level < aniState->firstepLevel)
  1188. ah->stats.ast_ani_stepdown++;
  1189. aniState->firstepLevel = level;
  1190. }
  1191. break;
  1192. }
  1193. case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
  1194. u32 level = param;
  1195. if (level >= ARRAY_SIZE(cycpwrThr1_table)) {
  1196. ath_print(common, ATH_DBG_ANI,
  1197. "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level "
  1198. "out of range (%u > %u)\n",
  1199. level,
  1200. (unsigned) ARRAY_SIZE(cycpwrThr1_table));
  1201. return false;
  1202. }
  1203. /*
  1204. * make register setting relative to default
  1205. * from INI file & cap value
  1206. */
  1207. value = cycpwrThr1_table[level] -
  1208. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
  1209. aniState->iniDef.cycpwrThr1;
  1210. if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  1211. value = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  1212. if (value > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  1213. value = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  1214. REG_RMW_FIELD(ah, AR_PHY_TIMING5,
  1215. AR_PHY_TIMING5_CYCPWR_THR1,
  1216. value);
  1217. /*
  1218. * set AR_PHY_EXT_CCA for extension channel
  1219. * make register setting relative to default
  1220. * from INI file & cap value
  1221. */
  1222. value2 = cycpwrThr1_table[level] -
  1223. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
  1224. aniState->iniDef.cycpwrThr1Ext;
  1225. if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  1226. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  1227. if (value2 > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  1228. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  1229. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
  1230. AR_PHY_EXT_TIMING5_CYCPWR_THR1, value2);
  1231. if (level != aniState->spurImmunityLevel) {
  1232. ath_print(common, ATH_DBG_ANI,
  1233. "** ch %d: level %d=>%d[def:%d] "
  1234. "cycpwrThr1[level]=%d ini=%d\n",
  1235. chan->channel,
  1236. aniState->spurImmunityLevel,
  1237. level,
  1238. ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
  1239. value,
  1240. aniState->iniDef.cycpwrThr1);
  1241. ath_print(common, ATH_DBG_ANI,
  1242. "** ch %d: level %d=>%d[def:%d] "
  1243. "cycpwrThr1Ext[level]=%d ini=%d\n",
  1244. chan->channel,
  1245. aniState->spurImmunityLevel,
  1246. level,
  1247. ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
  1248. value2,
  1249. aniState->iniDef.cycpwrThr1Ext);
  1250. if (level > aniState->spurImmunityLevel)
  1251. ah->stats.ast_ani_spurup++;
  1252. else if (level < aniState->spurImmunityLevel)
  1253. ah->stats.ast_ani_spurdown++;
  1254. aniState->spurImmunityLevel = level;
  1255. }
  1256. break;
  1257. }
  1258. case ATH9K_ANI_MRC_CCK:
  1259. /*
  1260. * You should not see this as AR5008, AR9001, AR9002
  1261. * does not have hardware support for MRC CCK.
  1262. */
  1263. WARN_ON(1);
  1264. break;
  1265. case ATH9K_ANI_PRESENT:
  1266. break;
  1267. default:
  1268. ath_print(common, ATH_DBG_ANI,
  1269. "invalid cmd %u\n", cmd);
  1270. return false;
  1271. }
  1272. ath_print(common, ATH_DBG_ANI,
  1273. "ANI parameters: SI=%d, ofdmWS=%s FS=%d "
  1274. "MRCcck=%s listenTime=%d "
  1275. "ofdmErrs=%d cckErrs=%d\n",
  1276. aniState->spurImmunityLevel,
  1277. !aniState->ofdmWeakSigDetectOff ? "on" : "off",
  1278. aniState->firstepLevel,
  1279. !aniState->mrcCCKOff ? "on" : "off",
  1280. aniState->listenTime,
  1281. aniState->ofdmPhyErrCount,
  1282. aniState->cckPhyErrCount);
  1283. return true;
  1284. }
  1285. static void ar5008_hw_do_getnf(struct ath_hw *ah,
  1286. int16_t nfarray[NUM_NF_READINGS])
  1287. {
  1288. int16_t nf;
  1289. nf = MS(REG_READ(ah, AR_PHY_CCA), AR_PHY_MINCCA_PWR);
  1290. nfarray[0] = sign_extend32(nf, 8);
  1291. nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), AR_PHY_CH1_MINCCA_PWR);
  1292. nfarray[1] = sign_extend32(nf, 8);
  1293. nf = MS(REG_READ(ah, AR_PHY_CH2_CCA), AR_PHY_CH2_MINCCA_PWR);
  1294. nfarray[2] = sign_extend32(nf, 8);
  1295. if (!IS_CHAN_HT40(ah->curchan))
  1296. return;
  1297. nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR);
  1298. nfarray[3] = sign_extend32(nf, 8);
  1299. nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA), AR_PHY_CH1_EXT_MINCCA_PWR);
  1300. nfarray[4] = sign_extend32(nf, 8);
  1301. nf = MS(REG_READ(ah, AR_PHY_CH2_EXT_CCA), AR_PHY_CH2_EXT_MINCCA_PWR);
  1302. nfarray[5] = sign_extend32(nf, 8);
  1303. }
  1304. /*
  1305. * Initialize the ANI register values with default (ini) values.
  1306. * This routine is called during a (full) hardware reset after
  1307. * all the registers are initialised from the INI.
  1308. */
  1309. static void ar5008_hw_ani_cache_ini_regs(struct ath_hw *ah)
  1310. {
  1311. struct ath_common *common = ath9k_hw_common(ah);
  1312. struct ath9k_channel *chan = ah->curchan;
  1313. struct ar5416AniState *aniState = &chan->ani;
  1314. struct ath9k_ani_default *iniDef;
  1315. u32 val;
  1316. iniDef = &aniState->iniDef;
  1317. ath_print(common, ATH_DBG_ANI,
  1318. "ver %d.%d opmode %u chan %d Mhz/0x%x\n",
  1319. ah->hw_version.macVersion,
  1320. ah->hw_version.macRev,
  1321. ah->opmode,
  1322. chan->channel,
  1323. chan->channelFlags);
  1324. val = REG_READ(ah, AR_PHY_SFCORR);
  1325. iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH);
  1326. iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH);
  1327. iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR);
  1328. val = REG_READ(ah, AR_PHY_SFCORR_LOW);
  1329. iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW);
  1330. iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW);
  1331. iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW);
  1332. val = REG_READ(ah, AR_PHY_SFCORR_EXT);
  1333. iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH);
  1334. iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH);
  1335. iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW);
  1336. iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW);
  1337. iniDef->firstep = REG_READ_FIELD(ah,
  1338. AR_PHY_FIND_SIG,
  1339. AR_PHY_FIND_SIG_FIRSTEP);
  1340. iniDef->firstepLow = REG_READ_FIELD(ah,
  1341. AR_PHY_FIND_SIG_LOW,
  1342. AR_PHY_FIND_SIG_FIRSTEP_LOW);
  1343. iniDef->cycpwrThr1 = REG_READ_FIELD(ah,
  1344. AR_PHY_TIMING5,
  1345. AR_PHY_TIMING5_CYCPWR_THR1);
  1346. iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah,
  1347. AR_PHY_EXT_CCA,
  1348. AR_PHY_EXT_TIMING5_CYCPWR_THR1);
  1349. /* these levels just got reset to defaults by the INI */
  1350. aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL_NEW;
  1351. aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL_NEW;
  1352. aniState->ofdmWeakSigDetectOff = !ATH9K_ANI_USE_OFDM_WEAK_SIG;
  1353. aniState->mrcCCKOff = true; /* not available on pre AR9003 */
  1354. }
  1355. static void ar5008_hw_set_nf_limits(struct ath_hw *ah)
  1356. {
  1357. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_5416_2GHZ;
  1358. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_5416_2GHZ;
  1359. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_5416_2GHZ;
  1360. ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_5416_5GHZ;
  1361. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_5416_5GHZ;
  1362. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_5416_5GHZ;
  1363. }
  1364. static void ar5008_hw_set_radar_params(struct ath_hw *ah,
  1365. struct ath_hw_radar_conf *conf)
  1366. {
  1367. u32 radar_0 = 0, radar_1 = 0;
  1368. if (!conf) {
  1369. REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA);
  1370. return;
  1371. }
  1372. radar_0 |= AR_PHY_RADAR_0_ENA | AR_PHY_RADAR_0_FFT_ENA;
  1373. radar_0 |= SM(conf->fir_power, AR_PHY_RADAR_0_FIRPWR);
  1374. radar_0 |= SM(conf->radar_rssi, AR_PHY_RADAR_0_RRSSI);
  1375. radar_0 |= SM(conf->pulse_height, AR_PHY_RADAR_0_HEIGHT);
  1376. radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI);
  1377. radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND);
  1378. radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI;
  1379. radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK;
  1380. radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN);
  1381. radar_1 |= SM(conf->pulse_inband_step, AR_PHY_RADAR_1_RELSTEP_THRESH);
  1382. radar_1 |= SM(conf->radar_inband, AR_PHY_RADAR_1_RELPWR_THRESH);
  1383. REG_WRITE(ah, AR_PHY_RADAR_0, radar_0);
  1384. REG_WRITE(ah, AR_PHY_RADAR_1, radar_1);
  1385. if (conf->ext_channel)
  1386. REG_SET_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1387. else
  1388. REG_CLR_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1389. }
  1390. static void ar5008_hw_set_radar_conf(struct ath_hw *ah)
  1391. {
  1392. struct ath_hw_radar_conf *conf = &ah->radar_conf;
  1393. conf->fir_power = -33;
  1394. conf->radar_rssi = 20;
  1395. conf->pulse_height = 10;
  1396. conf->pulse_rssi = 24;
  1397. conf->pulse_inband = 15;
  1398. conf->pulse_maxlen = 255;
  1399. conf->pulse_inband_step = 12;
  1400. conf->radar_inband = 8;
  1401. }
  1402. void ar5008_hw_attach_phy_ops(struct ath_hw *ah)
  1403. {
  1404. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  1405. static const u32 ar5416_cca_regs[6] = {
  1406. AR_PHY_CCA,
  1407. AR_PHY_CH1_CCA,
  1408. AR_PHY_CH2_CCA,
  1409. AR_PHY_EXT_CCA,
  1410. AR_PHY_CH1_EXT_CCA,
  1411. AR_PHY_CH2_EXT_CCA
  1412. };
  1413. priv_ops->rf_set_freq = ar5008_hw_set_channel;
  1414. priv_ops->spur_mitigate_freq = ar5008_hw_spur_mitigate;
  1415. priv_ops->rf_alloc_ext_banks = ar5008_hw_rf_alloc_ext_banks;
  1416. priv_ops->rf_free_ext_banks = ar5008_hw_rf_free_ext_banks;
  1417. priv_ops->set_rf_regs = ar5008_hw_set_rf_regs;
  1418. priv_ops->set_channel_regs = ar5008_hw_set_channel_regs;
  1419. priv_ops->init_bb = ar5008_hw_init_bb;
  1420. priv_ops->process_ini = ar5008_hw_process_ini;
  1421. priv_ops->set_rfmode = ar5008_hw_set_rfmode;
  1422. priv_ops->mark_phy_inactive = ar5008_hw_mark_phy_inactive;
  1423. priv_ops->set_delta_slope = ar5008_hw_set_delta_slope;
  1424. priv_ops->rfbus_req = ar5008_hw_rfbus_req;
  1425. priv_ops->rfbus_done = ar5008_hw_rfbus_done;
  1426. priv_ops->enable_rfkill = ar5008_hw_enable_rfkill;
  1427. priv_ops->restore_chainmask = ar5008_restore_chainmask;
  1428. priv_ops->set_diversity = ar5008_set_diversity;
  1429. priv_ops->do_getnf = ar5008_hw_do_getnf;
  1430. priv_ops->set_radar_params = ar5008_hw_set_radar_params;
  1431. if (modparam_force_new_ani) {
  1432. priv_ops->ani_control = ar5008_hw_ani_control_new;
  1433. priv_ops->ani_cache_ini_regs = ar5008_hw_ani_cache_ini_regs;
  1434. } else
  1435. priv_ops->ani_control = ar5008_hw_ani_control_old;
  1436. if (AR_SREV_9100(ah))
  1437. priv_ops->compute_pll_control = ar9100_hw_compute_pll_control;
  1438. else if (AR_SREV_9160_10_OR_LATER(ah))
  1439. priv_ops->compute_pll_control = ar9160_hw_compute_pll_control;
  1440. else
  1441. priv_ops->compute_pll_control = ar5008_hw_compute_pll_control;
  1442. ar5008_hw_set_nf_limits(ah);
  1443. ar5008_hw_set_radar_conf(ah);
  1444. memcpy(ah->nf_regs, ar5416_cca_regs, sizeof(ah->nf_regs));
  1445. }