ar5008_phy.c 36 KB

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