ar5008_phy.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344
  1. /*
  2. * Copyright (c) 2008-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 "hw.h"
  17. #include "hw-ops.h"
  18. #include "../regd.h"
  19. #include "ar9002_phy.h"
  20. #include "ar5008_initvals.h"
  21. /* All code below is for AR5008, AR9001, AR9002 */
  22. static const int firstep_table[] =
  23. /* level: 0 1 2 3 4 5 6 7 8 */
  24. { -4, -2, 0, 2, 4, 6, 8, 10, 12 }; /* lvl 0-8, default 2 */
  25. static const int cycpwrThr1_table[] =
  26. /* level: 0 1 2 3 4 5 6 7 8 */
  27. { -6, -4, -2, 0, 2, 4, 6, 8 }; /* lvl 0-7, default 3 */
  28. /*
  29. * register values to turn OFDM weak signal detection OFF
  30. */
  31. static const int m1ThreshLow_off = 127;
  32. static const int m2ThreshLow_off = 127;
  33. static const int m1Thresh_off = 127;
  34. static const int m2Thresh_off = 127;
  35. static const int m2CountThr_off = 31;
  36. static const int m2CountThrLow_off = 63;
  37. static const int m1ThreshLowExt_off = 127;
  38. static const int m2ThreshLowExt_off = 127;
  39. static const int m1ThreshExt_off = 127;
  40. static const int m2ThreshExt_off = 127;
  41. static const struct ar5416IniArray bank0 = STATIC_INI_ARRAY(ar5416Bank0);
  42. static const struct ar5416IniArray bank1 = STATIC_INI_ARRAY(ar5416Bank1);
  43. static const struct ar5416IniArray bank2 = STATIC_INI_ARRAY(ar5416Bank2);
  44. static const struct ar5416IniArray bank3 = STATIC_INI_ARRAY(ar5416Bank3);
  45. static const struct ar5416IniArray bank7 = STATIC_INI_ARRAY(ar5416Bank7);
  46. static void ar5008_write_bank6(struct ath_hw *ah, unsigned int *writecnt)
  47. {
  48. struct ar5416IniArray *array = &ah->iniBank6;
  49. u32 *data = ah->analogBank6Data;
  50. int r;
  51. ENABLE_REGWRITE_BUFFER(ah);
  52. for (r = 0; r < array->ia_rows; r++) {
  53. REG_WRITE(ah, INI_RA(array, r, 0), data[r]);
  54. DO_DELAY(*writecnt);
  55. }
  56. REGWRITE_BUFFER_FLUSH(ah);
  57. }
  58. /**
  59. * ar5008_hw_phy_modify_rx_buffer() - perform analog swizzling of parameters
  60. * @rfbuf:
  61. * @reg32:
  62. * @numBits:
  63. * @firstBit:
  64. * @column:
  65. *
  66. * Performs analog "swizzling" of parameters into their location.
  67. * Used on external AR2133/AR5133 radios.
  68. */
  69. static void ar5008_hw_phy_modify_rx_buffer(u32 *rfBuf, u32 reg32,
  70. u32 numBits, u32 firstBit,
  71. u32 column)
  72. {
  73. u32 tmp32, mask, arrayEntry, lastBit;
  74. int32_t bitPosition, bitsLeft;
  75. tmp32 = ath9k_hw_reverse_bits(reg32, numBits);
  76. arrayEntry = (firstBit - 1) / 8;
  77. bitPosition = (firstBit - 1) % 8;
  78. bitsLeft = numBits;
  79. while (bitsLeft > 0) {
  80. lastBit = (bitPosition + bitsLeft > 8) ?
  81. 8 : bitPosition + bitsLeft;
  82. mask = (((1 << lastBit) - 1) ^ ((1 << bitPosition) - 1)) <<
  83. (column * 8);
  84. rfBuf[arrayEntry] &= ~mask;
  85. rfBuf[arrayEntry] |= ((tmp32 << bitPosition) <<
  86. (column * 8)) & mask;
  87. bitsLeft -= 8 - bitPosition;
  88. tmp32 = tmp32 >> (8 - bitPosition);
  89. bitPosition = 0;
  90. arrayEntry++;
  91. }
  92. }
  93. /*
  94. * Fix on 2.4 GHz band for orientation sensitivity issue by increasing
  95. * rf_pwd_icsyndiv.
  96. *
  97. * Theoretical Rules:
  98. * if 2 GHz band
  99. * if forceBiasAuto
  100. * if synth_freq < 2412
  101. * bias = 0
  102. * else if 2412 <= synth_freq <= 2422
  103. * bias = 1
  104. * else // synth_freq > 2422
  105. * bias = 2
  106. * else if forceBias > 0
  107. * bias = forceBias & 7
  108. * else
  109. * no change, use value from ini file
  110. * else
  111. * no change, invalid band
  112. *
  113. * 1st Mod:
  114. * 2422 also uses value of 2
  115. * <approved>
  116. *
  117. * 2nd Mod:
  118. * Less than 2412 uses value of 0, 2412 and above uses value of 2
  119. */
  120. static void ar5008_hw_force_bias(struct ath_hw *ah, u16 synth_freq)
  121. {
  122. struct ath_common *common = ath9k_hw_common(ah);
  123. u32 tmp_reg;
  124. int reg_writes = 0;
  125. u32 new_bias = 0;
  126. if (!AR_SREV_5416(ah) || synth_freq >= 3000)
  127. return;
  128. BUG_ON(AR_SREV_9280_20_OR_LATER(ah));
  129. if (synth_freq < 2412)
  130. new_bias = 0;
  131. else if (synth_freq < 2422)
  132. new_bias = 1;
  133. else
  134. new_bias = 2;
  135. /* pre-reverse this field */
  136. tmp_reg = ath9k_hw_reverse_bits(new_bias, 3);
  137. ath_dbg(common, CONFIG, "Force rf_pwd_icsyndiv to %1d on %4d\n",
  138. new_bias, synth_freq);
  139. /* swizzle rf_pwd_icsyndiv */
  140. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data, tmp_reg, 3, 181, 3);
  141. /* write Bank 6 with new params */
  142. ar5008_write_bank6(ah, &reg_writes);
  143. }
  144. /**
  145. * ar5008_hw_set_channel - tune to a channel on the external AR2133/AR5133 radios
  146. * @ah: atheros hardware structure
  147. * @chan:
  148. *
  149. * For the external AR2133/AR5133 radios, takes the MHz channel value and set
  150. * the channel value. Assumes writes enabled to analog bus and bank6 register
  151. * cache in ah->analogBank6Data.
  152. */
  153. static int ar5008_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
  154. {
  155. struct ath_common *common = ath9k_hw_common(ah);
  156. u32 channelSel = 0;
  157. u32 bModeSynth = 0;
  158. u32 aModeRefSel = 0;
  159. u32 reg32 = 0;
  160. u16 freq;
  161. struct chan_centers centers;
  162. ath9k_hw_get_channel_centers(ah, chan, &centers);
  163. freq = centers.synth_center;
  164. if (freq < 4800) {
  165. u32 txctl;
  166. if (((freq - 2192) % 5) == 0) {
  167. channelSel = ((freq - 672) * 2 - 3040) / 10;
  168. bModeSynth = 0;
  169. } else if (((freq - 2224) % 5) == 0) {
  170. channelSel = ((freq - 704) * 2 - 3040) / 10;
  171. bModeSynth = 1;
  172. } else {
  173. ath_err(common, "Invalid channel %u MHz\n", freq);
  174. return -EINVAL;
  175. }
  176. channelSel = (channelSel << 2) & 0xff;
  177. channelSel = ath9k_hw_reverse_bits(channelSel, 8);
  178. txctl = REG_READ(ah, AR_PHY_CCK_TX_CTRL);
  179. if (freq == 2484) {
  180. REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
  181. txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
  182. } else {
  183. REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
  184. txctl & ~AR_PHY_CCK_TX_CTRL_JAPAN);
  185. }
  186. } else if ((freq % 20) == 0 && freq >= 5120) {
  187. channelSel =
  188. ath9k_hw_reverse_bits(((freq - 4800) / 20 << 2), 8);
  189. aModeRefSel = ath9k_hw_reverse_bits(1, 2);
  190. } else if ((freq % 10) == 0) {
  191. channelSel =
  192. ath9k_hw_reverse_bits(((freq - 4800) / 10 << 1), 8);
  193. if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah))
  194. aModeRefSel = ath9k_hw_reverse_bits(2, 2);
  195. else
  196. aModeRefSel = ath9k_hw_reverse_bits(1, 2);
  197. } else if ((freq % 5) == 0) {
  198. channelSel = ath9k_hw_reverse_bits((freq - 4800) / 5, 8);
  199. aModeRefSel = ath9k_hw_reverse_bits(1, 2);
  200. } else {
  201. ath_err(common, "Invalid channel %u MHz\n", freq);
  202. return -EINVAL;
  203. }
  204. ar5008_hw_force_bias(ah, freq);
  205. reg32 =
  206. (channelSel << 8) | (aModeRefSel << 2) | (bModeSynth << 1) |
  207. (1 << 5) | 0x1;
  208. REG_WRITE(ah, AR_PHY(0x37), reg32);
  209. ah->curchan = chan;
  210. return 0;
  211. }
  212. /**
  213. * ar5008_hw_spur_mitigate - convert baseband spur frequency for external radios
  214. * @ah: atheros hardware structure
  215. * @chan:
  216. *
  217. * For non single-chip solutions. Converts to baseband spur frequency given the
  218. * input channel frequency and compute register settings below.
  219. */
  220. static void ar5008_hw_spur_mitigate(struct ath_hw *ah,
  221. struct ath9k_channel *chan)
  222. {
  223. int bb_spur = AR_NO_SPUR;
  224. int bin, cur_bin;
  225. int spur_freq_sd;
  226. int spur_delta_phase;
  227. int denominator;
  228. int upper, lower, cur_vit_mask;
  229. int tmp, new;
  230. int i;
  231. static int pilot_mask_reg[4] = {
  232. AR_PHY_TIMING7, AR_PHY_TIMING8,
  233. AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
  234. };
  235. static int chan_mask_reg[4] = {
  236. AR_PHY_TIMING9, AR_PHY_TIMING10,
  237. AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
  238. };
  239. static int inc[4] = { 0, 100, 0, 0 };
  240. int8_t mask_m[123];
  241. int8_t mask_p[123];
  242. int8_t mask_amt;
  243. int tmp_mask;
  244. int cur_bb_spur;
  245. bool is2GHz = IS_CHAN_2GHZ(chan);
  246. memset(&mask_m, 0, sizeof(int8_t) * 123);
  247. memset(&mask_p, 0, sizeof(int8_t) * 123);
  248. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  249. cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
  250. if (AR_NO_SPUR == cur_bb_spur)
  251. break;
  252. cur_bb_spur = cur_bb_spur - (chan->channel * 10);
  253. if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
  254. bb_spur = cur_bb_spur;
  255. break;
  256. }
  257. }
  258. if (AR_NO_SPUR == bb_spur)
  259. return;
  260. bin = bb_spur * 32;
  261. tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
  262. new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
  263. AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
  264. AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
  265. AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
  266. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
  267. new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
  268. AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
  269. AR_PHY_SPUR_REG_MASK_RATE_SELECT |
  270. AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
  271. SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
  272. REG_WRITE(ah, AR_PHY_SPUR_REG, new);
  273. spur_delta_phase = ((bb_spur * 524288) / 100) &
  274. AR_PHY_TIMING11_SPUR_DELTA_PHASE;
  275. denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
  276. spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
  277. new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
  278. SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
  279. SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
  280. REG_WRITE(ah, AR_PHY_TIMING11, new);
  281. cur_bin = -6000;
  282. upper = bin + 100;
  283. lower = bin - 100;
  284. for (i = 0; i < 4; i++) {
  285. int pilot_mask = 0;
  286. int chan_mask = 0;
  287. int bp = 0;
  288. for (bp = 0; bp < 30; bp++) {
  289. if ((cur_bin > lower) && (cur_bin < upper)) {
  290. pilot_mask = pilot_mask | 0x1 << bp;
  291. chan_mask = chan_mask | 0x1 << bp;
  292. }
  293. cur_bin += 100;
  294. }
  295. cur_bin += inc[i];
  296. REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
  297. REG_WRITE(ah, chan_mask_reg[i], chan_mask);
  298. }
  299. cur_vit_mask = 6100;
  300. upper = bin + 120;
  301. lower = bin - 120;
  302. for (i = 0; i < 123; i++) {
  303. if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
  304. /* workaround for gcc bug #37014 */
  305. volatile int tmp_v = abs(cur_vit_mask - bin);
  306. if (tmp_v < 75)
  307. mask_amt = 1;
  308. else
  309. mask_amt = 0;
  310. if (cur_vit_mask < 0)
  311. mask_m[abs(cur_vit_mask / 100)] = mask_amt;
  312. else
  313. mask_p[cur_vit_mask / 100] = mask_amt;
  314. }
  315. cur_vit_mask -= 100;
  316. }
  317. tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
  318. | (mask_m[48] << 26) | (mask_m[49] << 24)
  319. | (mask_m[50] << 22) | (mask_m[51] << 20)
  320. | (mask_m[52] << 18) | (mask_m[53] << 16)
  321. | (mask_m[54] << 14) | (mask_m[55] << 12)
  322. | (mask_m[56] << 10) | (mask_m[57] << 8)
  323. | (mask_m[58] << 6) | (mask_m[59] << 4)
  324. | (mask_m[60] << 2) | (mask_m[61] << 0);
  325. REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
  326. REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
  327. tmp_mask = (mask_m[31] << 28)
  328. | (mask_m[32] << 26) | (mask_m[33] << 24)
  329. | (mask_m[34] << 22) | (mask_m[35] << 20)
  330. | (mask_m[36] << 18) | (mask_m[37] << 16)
  331. | (mask_m[48] << 14) | (mask_m[39] << 12)
  332. | (mask_m[40] << 10) | (mask_m[41] << 8)
  333. | (mask_m[42] << 6) | (mask_m[43] << 4)
  334. | (mask_m[44] << 2) | (mask_m[45] << 0);
  335. REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
  336. REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
  337. tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
  338. | (mask_m[18] << 26) | (mask_m[18] << 24)
  339. | (mask_m[20] << 22) | (mask_m[20] << 20)
  340. | (mask_m[22] << 18) | (mask_m[22] << 16)
  341. | (mask_m[24] << 14) | (mask_m[24] << 12)
  342. | (mask_m[25] << 10) | (mask_m[26] << 8)
  343. | (mask_m[27] << 6) | (mask_m[28] << 4)
  344. | (mask_m[29] << 2) | (mask_m[30] << 0);
  345. REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
  346. REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
  347. tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
  348. | (mask_m[2] << 26) | (mask_m[3] << 24)
  349. | (mask_m[4] << 22) | (mask_m[5] << 20)
  350. | (mask_m[6] << 18) | (mask_m[7] << 16)
  351. | (mask_m[8] << 14) | (mask_m[9] << 12)
  352. | (mask_m[10] << 10) | (mask_m[11] << 8)
  353. | (mask_m[12] << 6) | (mask_m[13] << 4)
  354. | (mask_m[14] << 2) | (mask_m[15] << 0);
  355. REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
  356. REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
  357. tmp_mask = (mask_p[15] << 28)
  358. | (mask_p[14] << 26) | (mask_p[13] << 24)
  359. | (mask_p[12] << 22) | (mask_p[11] << 20)
  360. | (mask_p[10] << 18) | (mask_p[9] << 16)
  361. | (mask_p[8] << 14) | (mask_p[7] << 12)
  362. | (mask_p[6] << 10) | (mask_p[5] << 8)
  363. | (mask_p[4] << 6) | (mask_p[3] << 4)
  364. | (mask_p[2] << 2) | (mask_p[1] << 0);
  365. REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
  366. REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
  367. tmp_mask = (mask_p[30] << 28)
  368. | (mask_p[29] << 26) | (mask_p[28] << 24)
  369. | (mask_p[27] << 22) | (mask_p[26] << 20)
  370. | (mask_p[25] << 18) | (mask_p[24] << 16)
  371. | (mask_p[23] << 14) | (mask_p[22] << 12)
  372. | (mask_p[21] << 10) | (mask_p[20] << 8)
  373. | (mask_p[19] << 6) | (mask_p[18] << 4)
  374. | (mask_p[17] << 2) | (mask_p[16] << 0);
  375. REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
  376. REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
  377. tmp_mask = (mask_p[45] << 28)
  378. | (mask_p[44] << 26) | (mask_p[43] << 24)
  379. | (mask_p[42] << 22) | (mask_p[41] << 20)
  380. | (mask_p[40] << 18) | (mask_p[39] << 16)
  381. | (mask_p[38] << 14) | (mask_p[37] << 12)
  382. | (mask_p[36] << 10) | (mask_p[35] << 8)
  383. | (mask_p[34] << 6) | (mask_p[33] << 4)
  384. | (mask_p[32] << 2) | (mask_p[31] << 0);
  385. REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
  386. REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
  387. tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
  388. | (mask_p[59] << 26) | (mask_p[58] << 24)
  389. | (mask_p[57] << 22) | (mask_p[56] << 20)
  390. | (mask_p[55] << 18) | (mask_p[54] << 16)
  391. | (mask_p[53] << 14) | (mask_p[52] << 12)
  392. | (mask_p[51] << 10) | (mask_p[50] << 8)
  393. | (mask_p[49] << 6) | (mask_p[48] << 4)
  394. | (mask_p[47] << 2) | (mask_p[46] << 0);
  395. REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
  396. REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
  397. }
  398. /**
  399. * ar5008_hw_rf_alloc_ext_banks - allocates banks for external radio programming
  400. * @ah: atheros hardware structure
  401. *
  402. * Only required for older devices with external AR2133/AR5133 radios.
  403. */
  404. static int ar5008_hw_rf_alloc_ext_banks(struct ath_hw *ah)
  405. {
  406. int size = ah->iniBank6.ia_rows * sizeof(u32);
  407. if (AR_SREV_9280_20_OR_LATER(ah))
  408. return 0;
  409. ah->analogBank6Data = devm_kzalloc(ah->dev, size, GFP_KERNEL);
  410. if (!ah->analogBank6Data)
  411. return -ENOMEM;
  412. return 0;
  413. }
  414. /* *
  415. * ar5008_hw_set_rf_regs - programs rf registers based on EEPROM
  416. * @ah: atheros hardware structure
  417. * @chan:
  418. * @modesIndex:
  419. *
  420. * Used for the external AR2133/AR5133 radios.
  421. *
  422. * Reads the EEPROM header info from the device structure and programs
  423. * all rf registers. This routine requires access to the analog
  424. * rf device. This is not required for single-chip devices.
  425. */
  426. static bool ar5008_hw_set_rf_regs(struct ath_hw *ah,
  427. struct ath9k_channel *chan,
  428. u16 modesIndex)
  429. {
  430. u32 eepMinorRev;
  431. u32 ob5GHz = 0, db5GHz = 0;
  432. u32 ob2GHz = 0, db2GHz = 0;
  433. int regWrites = 0;
  434. int i;
  435. /*
  436. * Software does not need to program bank data
  437. * for single chip devices, that is AR9280 or anything
  438. * after that.
  439. */
  440. if (AR_SREV_9280_20_OR_LATER(ah))
  441. return true;
  442. /* Setup rf parameters */
  443. eepMinorRev = ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV);
  444. for (i = 0; i < ah->iniBank6.ia_rows; i++)
  445. ah->analogBank6Data[i] = INI_RA(&ah->iniBank6, i, modesIndex);
  446. /* Only the 5 or 2 GHz OB/DB need to be set for a mode */
  447. if (eepMinorRev >= 2) {
  448. if (IS_CHAN_2GHZ(chan)) {
  449. ob2GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_2);
  450. db2GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_2);
  451. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
  452. ob2GHz, 3, 197, 0);
  453. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
  454. db2GHz, 3, 194, 0);
  455. } else {
  456. ob5GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_5);
  457. db5GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_5);
  458. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
  459. ob5GHz, 3, 203, 0);
  460. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
  461. db5GHz, 3, 200, 0);
  462. }
  463. }
  464. /* Write Analog registers */
  465. REG_WRITE_ARRAY(&bank0, 1, regWrites);
  466. REG_WRITE_ARRAY(&bank1, 1, regWrites);
  467. REG_WRITE_ARRAY(&bank2, 1, regWrites);
  468. REG_WRITE_ARRAY(&bank3, modesIndex, regWrites);
  469. ar5008_write_bank6(ah, &regWrites);
  470. REG_WRITE_ARRAY(&bank7, 1, regWrites);
  471. return true;
  472. }
  473. static void ar5008_hw_init_bb(struct ath_hw *ah,
  474. struct ath9k_channel *chan)
  475. {
  476. u32 synthDelay;
  477. synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  478. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
  479. ath9k_hw_synth_delay(ah, chan, synthDelay);
  480. }
  481. static void ar5008_hw_init_chain_masks(struct ath_hw *ah)
  482. {
  483. int rx_chainmask, tx_chainmask;
  484. rx_chainmask = ah->rxchainmask;
  485. tx_chainmask = ah->txchainmask;
  486. switch (rx_chainmask) {
  487. case 0x5:
  488. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  489. AR_PHY_SWAP_ALT_CHAIN);
  490. case 0x3:
  491. if (ah->hw_version.macVersion == AR_SREV_REVISION_5416_10) {
  492. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
  493. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
  494. break;
  495. }
  496. case 0x1:
  497. case 0x2:
  498. case 0x7:
  499. ENABLE_REGWRITE_BUFFER(ah);
  500. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
  501. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
  502. break;
  503. default:
  504. ENABLE_REGWRITE_BUFFER(ah);
  505. break;
  506. }
  507. REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
  508. REGWRITE_BUFFER_FLUSH(ah);
  509. if (tx_chainmask == 0x5) {
  510. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  511. AR_PHY_SWAP_ALT_CHAIN);
  512. }
  513. if (AR_SREV_9100(ah))
  514. REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
  515. REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
  516. }
  517. static void ar5008_hw_override_ini(struct ath_hw *ah,
  518. struct ath9k_channel *chan)
  519. {
  520. u32 val;
  521. /*
  522. * Set the RX_ABORT and RX_DIS and clear if off only after
  523. * RXE is set for MAC. This prevents frames with corrupted
  524. * descriptor status.
  525. */
  526. REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  527. if (AR_SREV_9280_20_OR_LATER(ah)) {
  528. /*
  529. * For AR9280 and above, there is a new feature that allows
  530. * Multicast search based on both MAC Address and Key ID.
  531. * By default, this feature is enabled. But since the driver
  532. * is not using this feature, we switch it off; otherwise
  533. * multicast search based on MAC addr only will fail.
  534. */
  535. val = REG_READ(ah, AR_PCU_MISC_MODE2) &
  536. (~AR_ADHOC_MCAST_KEYID_ENABLE);
  537. if (!AR_SREV_9271(ah))
  538. val &= ~AR_PCU_MISC_MODE2_HWWAR1;
  539. if (AR_SREV_9287_11_OR_LATER(ah))
  540. val = val & (~AR_PCU_MISC_MODE2_HWWAR2);
  541. val |= AR_PCU_MISC_MODE2_CFP_IGNORE;
  542. REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
  543. }
  544. if (AR_SREV_9280_20_OR_LATER(ah))
  545. return;
  546. /*
  547. * Disable BB clock gating
  548. * Necessary to avoid issues on AR5416 2.0
  549. */
  550. REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
  551. /*
  552. * Disable RIFS search on some chips to avoid baseband
  553. * hang issues.
  554. */
  555. if (AR_SREV_9100(ah) || AR_SREV_9160(ah)) {
  556. val = REG_READ(ah, AR_PHY_HEAVY_CLIP_FACTOR_RIFS);
  557. val &= ~AR_PHY_RIFS_INIT_DELAY;
  558. REG_WRITE(ah, AR_PHY_HEAVY_CLIP_FACTOR_RIFS, val);
  559. }
  560. }
  561. static void ar5008_hw_set_channel_regs(struct ath_hw *ah,
  562. struct ath9k_channel *chan)
  563. {
  564. u32 phymode;
  565. u32 enableDacFifo = 0;
  566. if (AR_SREV_9285_12_OR_LATER(ah))
  567. enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
  568. AR_PHY_FC_ENABLE_DAC_FIFO);
  569. phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
  570. | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
  571. if (IS_CHAN_HT40(chan)) {
  572. phymode |= AR_PHY_FC_DYN2040_EN;
  573. if (IS_CHAN_HT40PLUS(chan))
  574. phymode |= AR_PHY_FC_DYN2040_PRI_CH;
  575. }
  576. REG_WRITE(ah, AR_PHY_TURBO, phymode);
  577. ath9k_hw_set11nmac2040(ah, chan);
  578. ENABLE_REGWRITE_BUFFER(ah);
  579. REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
  580. REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
  581. REGWRITE_BUFFER_FLUSH(ah);
  582. }
  583. static int ar5008_hw_process_ini(struct ath_hw *ah,
  584. struct ath9k_channel *chan)
  585. {
  586. struct ath_common *common = ath9k_hw_common(ah);
  587. int i, regWrites = 0;
  588. u32 modesIndex, freqIndex;
  589. if (IS_CHAN_5GHZ(chan)) {
  590. freqIndex = 1;
  591. modesIndex = IS_CHAN_HT40(chan) ? 2 : 1;
  592. } else {
  593. freqIndex = 2;
  594. modesIndex = IS_CHAN_HT40(chan) ? 3 : 4;
  595. }
  596. /*
  597. * Set correct baseband to analog shift setting to
  598. * access analog chips.
  599. */
  600. REG_WRITE(ah, AR_PHY(0), 0x00000007);
  601. /* Write ADDAC shifts */
  602. REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
  603. if (ah->eep_ops->set_addac)
  604. ah->eep_ops->set_addac(ah, chan);
  605. REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
  606. REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
  607. ENABLE_REGWRITE_BUFFER(ah);
  608. for (i = 0; i < ah->iniModes.ia_rows; i++) {
  609. u32 reg = INI_RA(&ah->iniModes, i, 0);
  610. u32 val = INI_RA(&ah->iniModes, i, modesIndex);
  611. if (reg == AR_AN_TOP2 && ah->need_an_top2_fixup)
  612. val &= ~AR_AN_TOP2_PWDCLKIND;
  613. REG_WRITE(ah, reg, val);
  614. if (reg >= 0x7800 && reg < 0x78a0
  615. && ah->config.analog_shiftreg
  616. && (common->bus_ops->ath_bus_type != ATH_USB)) {
  617. udelay(100);
  618. }
  619. DO_DELAY(regWrites);
  620. }
  621. REGWRITE_BUFFER_FLUSH(ah);
  622. if (AR_SREV_9280(ah) || AR_SREV_9287_11_OR_LATER(ah))
  623. REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
  624. if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) ||
  625. AR_SREV_9287_11_OR_LATER(ah))
  626. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  627. if (AR_SREV_9271_10(ah)) {
  628. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN, AR_PHY_SPECTRAL_SCAN_ENA);
  629. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_ADC_ON, 0xa);
  630. }
  631. ENABLE_REGWRITE_BUFFER(ah);
  632. /* Write common array parameters */
  633. for (i = 0; i < ah->iniCommon.ia_rows; i++) {
  634. u32 reg = INI_RA(&ah->iniCommon, i, 0);
  635. u32 val = INI_RA(&ah->iniCommon, i, 1);
  636. REG_WRITE(ah, reg, val);
  637. if (reg >= 0x7800 && reg < 0x78a0
  638. && ah->config.analog_shiftreg
  639. && (common->bus_ops->ath_bus_type != ATH_USB)) {
  640. udelay(100);
  641. }
  642. DO_DELAY(regWrites);
  643. }
  644. REGWRITE_BUFFER_FLUSH(ah);
  645. REG_WRITE_ARRAY(&ah->iniBB_RfGain, freqIndex, regWrites);
  646. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  647. REG_WRITE_ARRAY(&ah->iniModesFastClock, modesIndex,
  648. regWrites);
  649. ar5008_hw_override_ini(ah, chan);
  650. ar5008_hw_set_channel_regs(ah, chan);
  651. ar5008_hw_init_chain_masks(ah);
  652. ath9k_olc_init(ah);
  653. ath9k_hw_apply_txpower(ah, chan, false);
  654. /* Write analog registers */
  655. if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
  656. ath_err(ath9k_hw_common(ah), "ar5416SetRfRegs failed\n");
  657. return -EIO;
  658. }
  659. return 0;
  660. }
  661. static void ar5008_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
  662. {
  663. u32 rfMode = 0;
  664. if (chan == NULL)
  665. return;
  666. if (IS_CHAN_2GHZ(chan))
  667. rfMode |= AR_PHY_MODE_DYNAMIC;
  668. else
  669. rfMode |= AR_PHY_MODE_OFDM;
  670. if (!AR_SREV_9280_20_OR_LATER(ah))
  671. rfMode |= (IS_CHAN_5GHZ(chan)) ?
  672. AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
  673. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  674. rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
  675. REG_WRITE(ah, AR_PHY_MODE, rfMode);
  676. }
  677. static void ar5008_hw_mark_phy_inactive(struct ath_hw *ah)
  678. {
  679. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
  680. }
  681. static void ar5008_hw_set_delta_slope(struct ath_hw *ah,
  682. struct ath9k_channel *chan)
  683. {
  684. u32 coef_scaled, ds_coef_exp, ds_coef_man;
  685. u32 clockMhzScaled = 0x64000000;
  686. struct chan_centers centers;
  687. if (IS_CHAN_HALF_RATE(chan))
  688. clockMhzScaled = clockMhzScaled >> 1;
  689. else if (IS_CHAN_QUARTER_RATE(chan))
  690. clockMhzScaled = clockMhzScaled >> 2;
  691. ath9k_hw_get_channel_centers(ah, chan, &centers);
  692. coef_scaled = clockMhzScaled / centers.synth_center;
  693. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  694. &ds_coef_exp);
  695. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  696. AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
  697. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  698. AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
  699. coef_scaled = (9 * coef_scaled) / 10;
  700. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  701. &ds_coef_exp);
  702. REG_RMW_FIELD(ah, AR_PHY_HALFGI,
  703. AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
  704. REG_RMW_FIELD(ah, AR_PHY_HALFGI,
  705. AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
  706. }
  707. static bool ar5008_hw_rfbus_req(struct ath_hw *ah)
  708. {
  709. REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
  710. return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
  711. AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT);
  712. }
  713. static void ar5008_hw_rfbus_done(struct ath_hw *ah)
  714. {
  715. u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  716. ath9k_hw_synth_delay(ah, ah->curchan, synthDelay);
  717. REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
  718. }
  719. static void ar5008_restore_chainmask(struct ath_hw *ah)
  720. {
  721. int rx_chainmask = ah->rxchainmask;
  722. if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
  723. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
  724. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
  725. }
  726. }
  727. static u32 ar9160_hw_compute_pll_control(struct ath_hw *ah,
  728. struct ath9k_channel *chan)
  729. {
  730. u32 pll;
  731. pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
  732. if (chan && IS_CHAN_HALF_RATE(chan))
  733. pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
  734. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  735. pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
  736. if (chan && IS_CHAN_5GHZ(chan))
  737. pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
  738. else
  739. pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
  740. return pll;
  741. }
  742. static u32 ar5008_hw_compute_pll_control(struct ath_hw *ah,
  743. struct ath9k_channel *chan)
  744. {
  745. u32 pll;
  746. pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
  747. if (chan && IS_CHAN_HALF_RATE(chan))
  748. pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
  749. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  750. pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
  751. if (chan && IS_CHAN_5GHZ(chan))
  752. pll |= SM(0xa, AR_RTC_PLL_DIV);
  753. else
  754. pll |= SM(0xb, AR_RTC_PLL_DIV);
  755. return pll;
  756. }
  757. static bool ar5008_hw_ani_control_new(struct ath_hw *ah,
  758. enum ath9k_ani_cmd cmd,
  759. int param)
  760. {
  761. struct ath_common *common = ath9k_hw_common(ah);
  762. struct ath9k_channel *chan = ah->curchan;
  763. struct ar5416AniState *aniState = &ah->ani;
  764. s32 value, value2;
  765. switch (cmd & ah->ani_function) {
  766. case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
  767. /*
  768. * on == 1 means ofdm weak signal detection is ON
  769. * on == 1 is the default, for less noise immunity
  770. *
  771. * on == 0 means ofdm weak signal detection is OFF
  772. * on == 0 means more noise imm
  773. */
  774. u32 on = param ? 1 : 0;
  775. /*
  776. * make register setting for default
  777. * (weak sig detect ON) come from INI file
  778. */
  779. int m1ThreshLow = on ?
  780. aniState->iniDef.m1ThreshLow : m1ThreshLow_off;
  781. int m2ThreshLow = on ?
  782. aniState->iniDef.m2ThreshLow : m2ThreshLow_off;
  783. int m1Thresh = on ?
  784. aniState->iniDef.m1Thresh : m1Thresh_off;
  785. int m2Thresh = on ?
  786. aniState->iniDef.m2Thresh : m2Thresh_off;
  787. int m2CountThr = on ?
  788. aniState->iniDef.m2CountThr : m2CountThr_off;
  789. int m2CountThrLow = on ?
  790. aniState->iniDef.m2CountThrLow : m2CountThrLow_off;
  791. int m1ThreshLowExt = on ?
  792. aniState->iniDef.m1ThreshLowExt : m1ThreshLowExt_off;
  793. int m2ThreshLowExt = on ?
  794. aniState->iniDef.m2ThreshLowExt : m2ThreshLowExt_off;
  795. int m1ThreshExt = on ?
  796. aniState->iniDef.m1ThreshExt : m1ThreshExt_off;
  797. int m2ThreshExt = on ?
  798. aniState->iniDef.m2ThreshExt : m2ThreshExt_off;
  799. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  800. AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
  801. m1ThreshLow);
  802. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  803. AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
  804. m2ThreshLow);
  805. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  806. AR_PHY_SFCORR_M1_THRESH, m1Thresh);
  807. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  808. AR_PHY_SFCORR_M2_THRESH, m2Thresh);
  809. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  810. AR_PHY_SFCORR_M2COUNT_THR, m2CountThr);
  811. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  812. AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
  813. m2CountThrLow);
  814. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  815. AR_PHY_SFCORR_EXT_M1_THRESH_LOW, m1ThreshLowExt);
  816. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  817. AR_PHY_SFCORR_EXT_M2_THRESH_LOW, m2ThreshLowExt);
  818. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  819. AR_PHY_SFCORR_EXT_M1_THRESH, m1ThreshExt);
  820. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  821. AR_PHY_SFCORR_EXT_M2_THRESH, m2ThreshExt);
  822. if (on)
  823. REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
  824. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  825. else
  826. REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
  827. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  828. if (on != aniState->ofdmWeakSigDetect) {
  829. ath_dbg(common, ANI,
  830. "** ch %d: ofdm weak signal: %s=>%s\n",
  831. chan->channel,
  832. aniState->ofdmWeakSigDetect ?
  833. "on" : "off",
  834. on ? "on" : "off");
  835. if (on)
  836. ah->stats.ast_ani_ofdmon++;
  837. else
  838. ah->stats.ast_ani_ofdmoff++;
  839. aniState->ofdmWeakSigDetect = on;
  840. }
  841. break;
  842. }
  843. case ATH9K_ANI_FIRSTEP_LEVEL:{
  844. u32 level = param;
  845. if (level >= ARRAY_SIZE(firstep_table)) {
  846. ath_dbg(common, ANI,
  847. "ATH9K_ANI_FIRSTEP_LEVEL: level out of range (%u > %zu)\n",
  848. level, ARRAY_SIZE(firstep_table));
  849. return false;
  850. }
  851. /*
  852. * make register setting relative to default
  853. * from INI file & cap value
  854. */
  855. value = firstep_table[level] -
  856. firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
  857. aniState->iniDef.firstep;
  858. if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  859. value = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  860. if (value > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  861. value = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  862. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  863. AR_PHY_FIND_SIG_FIRSTEP,
  864. value);
  865. /*
  866. * we need to set first step low register too
  867. * make register setting relative to default
  868. * from INI file & cap value
  869. */
  870. value2 = firstep_table[level] -
  871. firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
  872. aniState->iniDef.firstepLow;
  873. if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  874. value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  875. if (value2 > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  876. value2 = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  877. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
  878. AR_PHY_FIND_SIG_FIRSTEP_LOW, value2);
  879. if (level != aniState->firstepLevel) {
  880. ath_dbg(common, ANI,
  881. "** ch %d: level %d=>%d[def:%d] firstep[level]=%d ini=%d\n",
  882. chan->channel,
  883. aniState->firstepLevel,
  884. level,
  885. ATH9K_ANI_FIRSTEP_LVL,
  886. value,
  887. aniState->iniDef.firstep);
  888. ath_dbg(common, ANI,
  889. "** ch %d: level %d=>%d[def:%d] firstep_low[level]=%d ini=%d\n",
  890. chan->channel,
  891. aniState->firstepLevel,
  892. level,
  893. ATH9K_ANI_FIRSTEP_LVL,
  894. value2,
  895. aniState->iniDef.firstepLow);
  896. if (level > aniState->firstepLevel)
  897. ah->stats.ast_ani_stepup++;
  898. else if (level < aniState->firstepLevel)
  899. ah->stats.ast_ani_stepdown++;
  900. aniState->firstepLevel = level;
  901. }
  902. break;
  903. }
  904. case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
  905. u32 level = param;
  906. if (level >= ARRAY_SIZE(cycpwrThr1_table)) {
  907. ath_dbg(common, ANI,
  908. "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level out of range (%u > %zu)\n",
  909. level, ARRAY_SIZE(cycpwrThr1_table));
  910. return false;
  911. }
  912. /*
  913. * make register setting relative to default
  914. * from INI file & cap value
  915. */
  916. value = cycpwrThr1_table[level] -
  917. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
  918. aniState->iniDef.cycpwrThr1;
  919. if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  920. value = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  921. if (value > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  922. value = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  923. REG_RMW_FIELD(ah, AR_PHY_TIMING5,
  924. AR_PHY_TIMING5_CYCPWR_THR1,
  925. value);
  926. /*
  927. * set AR_PHY_EXT_CCA for extension channel
  928. * make register setting relative to default
  929. * from INI file & cap value
  930. */
  931. value2 = cycpwrThr1_table[level] -
  932. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
  933. aniState->iniDef.cycpwrThr1Ext;
  934. if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  935. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  936. if (value2 > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  937. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  938. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
  939. AR_PHY_EXT_TIMING5_CYCPWR_THR1, value2);
  940. if (level != aniState->spurImmunityLevel) {
  941. ath_dbg(common, ANI,
  942. "** ch %d: level %d=>%d[def:%d] cycpwrThr1[level]=%d ini=%d\n",
  943. chan->channel,
  944. aniState->spurImmunityLevel,
  945. level,
  946. ATH9K_ANI_SPUR_IMMUNE_LVL,
  947. value,
  948. aniState->iniDef.cycpwrThr1);
  949. ath_dbg(common, ANI,
  950. "** ch %d: level %d=>%d[def:%d] cycpwrThr1Ext[level]=%d ini=%d\n",
  951. chan->channel,
  952. aniState->spurImmunityLevel,
  953. level,
  954. ATH9K_ANI_SPUR_IMMUNE_LVL,
  955. value2,
  956. aniState->iniDef.cycpwrThr1Ext);
  957. if (level > aniState->spurImmunityLevel)
  958. ah->stats.ast_ani_spurup++;
  959. else if (level < aniState->spurImmunityLevel)
  960. ah->stats.ast_ani_spurdown++;
  961. aniState->spurImmunityLevel = level;
  962. }
  963. break;
  964. }
  965. case ATH9K_ANI_MRC_CCK:
  966. /*
  967. * You should not see this as AR5008, AR9001, AR9002
  968. * does not have hardware support for MRC CCK.
  969. */
  970. WARN_ON(1);
  971. break;
  972. default:
  973. ath_dbg(common, ANI, "invalid cmd %u\n", cmd);
  974. return false;
  975. }
  976. ath_dbg(common, ANI,
  977. "ANI parameters: SI=%d, ofdmWS=%s FS=%d MRCcck=%s listenTime=%d ofdmErrs=%d cckErrs=%d\n",
  978. aniState->spurImmunityLevel,
  979. aniState->ofdmWeakSigDetect ? "on" : "off",
  980. aniState->firstepLevel,
  981. aniState->mrcCCK ? "on" : "off",
  982. aniState->listenTime,
  983. aniState->ofdmPhyErrCount,
  984. aniState->cckPhyErrCount);
  985. return true;
  986. }
  987. static void ar5008_hw_do_getnf(struct ath_hw *ah,
  988. int16_t nfarray[NUM_NF_READINGS])
  989. {
  990. int16_t nf;
  991. nf = MS(REG_READ(ah, AR_PHY_CCA), AR_PHY_MINCCA_PWR);
  992. nfarray[0] = sign_extend32(nf, 8);
  993. nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), AR_PHY_CH1_MINCCA_PWR);
  994. nfarray[1] = sign_extend32(nf, 8);
  995. nf = MS(REG_READ(ah, AR_PHY_CH2_CCA), AR_PHY_CH2_MINCCA_PWR);
  996. nfarray[2] = sign_extend32(nf, 8);
  997. if (!IS_CHAN_HT40(ah->curchan))
  998. return;
  999. nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR);
  1000. nfarray[3] = sign_extend32(nf, 8);
  1001. nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA), AR_PHY_CH1_EXT_MINCCA_PWR);
  1002. nfarray[4] = sign_extend32(nf, 8);
  1003. nf = MS(REG_READ(ah, AR_PHY_CH2_EXT_CCA), AR_PHY_CH2_EXT_MINCCA_PWR);
  1004. nfarray[5] = sign_extend32(nf, 8);
  1005. }
  1006. /*
  1007. * Initialize the ANI register values with default (ini) values.
  1008. * This routine is called during a (full) hardware reset after
  1009. * all the registers are initialised from the INI.
  1010. */
  1011. static void ar5008_hw_ani_cache_ini_regs(struct ath_hw *ah)
  1012. {
  1013. struct ath_common *common = ath9k_hw_common(ah);
  1014. struct ath9k_channel *chan = ah->curchan;
  1015. struct ar5416AniState *aniState = &ah->ani;
  1016. struct ath9k_ani_default *iniDef;
  1017. u32 val;
  1018. iniDef = &aniState->iniDef;
  1019. ath_dbg(common, ANI, "ver %d.%d opmode %u chan %d Mhz\n",
  1020. ah->hw_version.macVersion,
  1021. ah->hw_version.macRev,
  1022. ah->opmode,
  1023. chan->channel);
  1024. val = REG_READ(ah, AR_PHY_SFCORR);
  1025. iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH);
  1026. iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH);
  1027. iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR);
  1028. val = REG_READ(ah, AR_PHY_SFCORR_LOW);
  1029. iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW);
  1030. iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW);
  1031. iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW);
  1032. val = REG_READ(ah, AR_PHY_SFCORR_EXT);
  1033. iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH);
  1034. iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH);
  1035. iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW);
  1036. iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW);
  1037. iniDef->firstep = REG_READ_FIELD(ah,
  1038. AR_PHY_FIND_SIG,
  1039. AR_PHY_FIND_SIG_FIRSTEP);
  1040. iniDef->firstepLow = REG_READ_FIELD(ah,
  1041. AR_PHY_FIND_SIG_LOW,
  1042. AR_PHY_FIND_SIG_FIRSTEP_LOW);
  1043. iniDef->cycpwrThr1 = REG_READ_FIELD(ah,
  1044. AR_PHY_TIMING5,
  1045. AR_PHY_TIMING5_CYCPWR_THR1);
  1046. iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah,
  1047. AR_PHY_EXT_CCA,
  1048. AR_PHY_EXT_TIMING5_CYCPWR_THR1);
  1049. /* these levels just got reset to defaults by the INI */
  1050. aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL;
  1051. aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL;
  1052. aniState->ofdmWeakSigDetect = true;
  1053. aniState->mrcCCK = false; /* not available on pre AR9003 */
  1054. }
  1055. static void ar5008_hw_set_nf_limits(struct ath_hw *ah)
  1056. {
  1057. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_5416_2GHZ;
  1058. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_5416_2GHZ;
  1059. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_5416_2GHZ;
  1060. ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_5416_5GHZ;
  1061. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_5416_5GHZ;
  1062. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_5416_5GHZ;
  1063. }
  1064. static void ar5008_hw_set_radar_params(struct ath_hw *ah,
  1065. struct ath_hw_radar_conf *conf)
  1066. {
  1067. u32 radar_0 = 0, radar_1 = 0;
  1068. if (!conf) {
  1069. REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA);
  1070. return;
  1071. }
  1072. radar_0 |= AR_PHY_RADAR_0_ENA | AR_PHY_RADAR_0_FFT_ENA;
  1073. radar_0 |= SM(conf->fir_power, AR_PHY_RADAR_0_FIRPWR);
  1074. radar_0 |= SM(conf->radar_rssi, AR_PHY_RADAR_0_RRSSI);
  1075. radar_0 |= SM(conf->pulse_height, AR_PHY_RADAR_0_HEIGHT);
  1076. radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI);
  1077. radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND);
  1078. radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI;
  1079. radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK;
  1080. radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN);
  1081. radar_1 |= SM(conf->pulse_inband_step, AR_PHY_RADAR_1_RELSTEP_THRESH);
  1082. radar_1 |= SM(conf->radar_inband, AR_PHY_RADAR_1_RELPWR_THRESH);
  1083. REG_WRITE(ah, AR_PHY_RADAR_0, radar_0);
  1084. REG_WRITE(ah, AR_PHY_RADAR_1, radar_1);
  1085. if (conf->ext_channel)
  1086. REG_SET_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1087. else
  1088. REG_CLR_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1089. }
  1090. static void ar5008_hw_set_radar_conf(struct ath_hw *ah)
  1091. {
  1092. struct ath_hw_radar_conf *conf = &ah->radar_conf;
  1093. conf->fir_power = -33;
  1094. conf->radar_rssi = 20;
  1095. conf->pulse_height = 10;
  1096. conf->pulse_rssi = 24;
  1097. conf->pulse_inband = 15;
  1098. conf->pulse_maxlen = 255;
  1099. conf->pulse_inband_step = 12;
  1100. conf->radar_inband = 8;
  1101. }
  1102. int ar5008_hw_attach_phy_ops(struct ath_hw *ah)
  1103. {
  1104. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  1105. static const u32 ar5416_cca_regs[6] = {
  1106. AR_PHY_CCA,
  1107. AR_PHY_CH1_CCA,
  1108. AR_PHY_CH2_CCA,
  1109. AR_PHY_EXT_CCA,
  1110. AR_PHY_CH1_EXT_CCA,
  1111. AR_PHY_CH2_EXT_CCA
  1112. };
  1113. int ret;
  1114. ret = ar5008_hw_rf_alloc_ext_banks(ah);
  1115. if (ret)
  1116. return ret;
  1117. priv_ops->rf_set_freq = ar5008_hw_set_channel;
  1118. priv_ops->spur_mitigate_freq = ar5008_hw_spur_mitigate;
  1119. priv_ops->set_rf_regs = ar5008_hw_set_rf_regs;
  1120. priv_ops->set_channel_regs = ar5008_hw_set_channel_regs;
  1121. priv_ops->init_bb = ar5008_hw_init_bb;
  1122. priv_ops->process_ini = ar5008_hw_process_ini;
  1123. priv_ops->set_rfmode = ar5008_hw_set_rfmode;
  1124. priv_ops->mark_phy_inactive = ar5008_hw_mark_phy_inactive;
  1125. priv_ops->set_delta_slope = ar5008_hw_set_delta_slope;
  1126. priv_ops->rfbus_req = ar5008_hw_rfbus_req;
  1127. priv_ops->rfbus_done = ar5008_hw_rfbus_done;
  1128. priv_ops->restore_chainmask = ar5008_restore_chainmask;
  1129. priv_ops->do_getnf = ar5008_hw_do_getnf;
  1130. priv_ops->set_radar_params = ar5008_hw_set_radar_params;
  1131. priv_ops->ani_control = ar5008_hw_ani_control_new;
  1132. priv_ops->ani_cache_ini_regs = ar5008_hw_ani_cache_ini_regs;
  1133. if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah))
  1134. priv_ops->compute_pll_control = ar9160_hw_compute_pll_control;
  1135. else
  1136. priv_ops->compute_pll_control = ar5008_hw_compute_pll_control;
  1137. ar5008_hw_set_nf_limits(ah);
  1138. ar5008_hw_set_radar_conf(ah);
  1139. memcpy(ah->nf_regs, ar5416_cca_regs, sizeof(ah->nf_regs));
  1140. return 0;
  1141. }