ar5008_phy.c 39 KB

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