ar5008_phy.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393
  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->analogBank7Data, ah->iniBank7.ia_rows);
  422. return 0;
  423. #undef ATH_ALLOC_BANK
  424. error:
  425. ath_err(common, "Cannot allocate RF banks\n");
  426. return -ENOMEM;
  427. }
  428. /* *
  429. * ar5008_hw_set_rf_regs - programs rf registers based on EEPROM
  430. * @ah: atheros hardware structure
  431. * @chan:
  432. * @modesIndex:
  433. *
  434. * Used for the external AR2133/AR5133 radios.
  435. *
  436. * Reads the EEPROM header info from the device structure and programs
  437. * all rf registers. This routine requires access to the analog
  438. * rf device. This is not required for single-chip devices.
  439. */
  440. static bool ar5008_hw_set_rf_regs(struct ath_hw *ah,
  441. struct ath9k_channel *chan,
  442. u16 modesIndex)
  443. {
  444. u32 eepMinorRev;
  445. u32 ob5GHz = 0, db5GHz = 0;
  446. u32 ob2GHz = 0, db2GHz = 0;
  447. int regWrites = 0;
  448. int i;
  449. /*
  450. * Software does not need to program bank data
  451. * for single chip devices, that is AR9280 or anything
  452. * after that.
  453. */
  454. if (AR_SREV_9280_20_OR_LATER(ah))
  455. return true;
  456. /* Setup rf parameters */
  457. eepMinorRev = ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV);
  458. /* Setup Bank 0 Write */
  459. ar5008_rf_bank_setup(ah->analogBank0Data, &ah->iniBank0, 1);
  460. /* Setup Bank 1 Write */
  461. ar5008_rf_bank_setup(ah->analogBank1Data, &ah->iniBank1, 1);
  462. /* Setup Bank 2 Write */
  463. ar5008_rf_bank_setup(ah->analogBank2Data, &ah->iniBank2, 1);
  464. /* Setup Bank 6 Write */
  465. ar5008_rf_bank_setup(ah->analogBank3Data, &ah->iniBank3,
  466. modesIndex);
  467. for (i = 0; i < ah->iniBank6.ia_rows; i++)
  468. ah->analogBank6Data[i] = INI_RA(&ah->iniBank6, i, modesIndex);
  469. /* Only the 5 or 2 GHz OB/DB need to be set for a mode */
  470. if (eepMinorRev >= 2) {
  471. if (IS_CHAN_2GHZ(chan)) {
  472. ob2GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_2);
  473. db2GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_2);
  474. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
  475. ob2GHz, 3, 197, 0);
  476. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
  477. db2GHz, 3, 194, 0);
  478. } else {
  479. ob5GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_5);
  480. db5GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_5);
  481. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
  482. ob5GHz, 3, 203, 0);
  483. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
  484. db5GHz, 3, 200, 0);
  485. }
  486. }
  487. /* Setup Bank 7 Setup */
  488. ar5008_rf_bank_setup(ah->analogBank7Data, &ah->iniBank7, 1);
  489. /* Write Analog registers */
  490. REG_WRITE_RF_ARRAY(&ah->iniBank0, ah->analogBank0Data, regWrites);
  491. REG_WRITE_RF_ARRAY(&ah->iniBank1, ah->analogBank1Data, regWrites);
  492. REG_WRITE_RF_ARRAY(&ah->iniBank2, ah->analogBank2Data, regWrites);
  493. REG_WRITE_RF_ARRAY(&ah->iniBank3, ah->analogBank3Data, regWrites);
  494. REG_WRITE_RF_ARRAY(&ah->iniBank6, ah->analogBank6Data, regWrites);
  495. REG_WRITE_RF_ARRAY(&ah->iniBank7, ah->analogBank7Data, regWrites);
  496. return true;
  497. }
  498. static void ar5008_hw_init_bb(struct ath_hw *ah,
  499. struct ath9k_channel *chan)
  500. {
  501. u32 synthDelay;
  502. synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  503. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
  504. ath9k_hw_synth_delay(ah, chan, synthDelay);
  505. }
  506. static void ar5008_hw_init_chain_masks(struct ath_hw *ah)
  507. {
  508. int rx_chainmask, tx_chainmask;
  509. rx_chainmask = ah->rxchainmask;
  510. tx_chainmask = ah->txchainmask;
  511. switch (rx_chainmask) {
  512. case 0x5:
  513. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  514. AR_PHY_SWAP_ALT_CHAIN);
  515. case 0x3:
  516. if (ah->hw_version.macVersion == AR_SREV_REVISION_5416_10) {
  517. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
  518. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
  519. break;
  520. }
  521. case 0x1:
  522. case 0x2:
  523. case 0x7:
  524. ENABLE_REGWRITE_BUFFER(ah);
  525. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
  526. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
  527. break;
  528. default:
  529. ENABLE_REGWRITE_BUFFER(ah);
  530. break;
  531. }
  532. REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
  533. REGWRITE_BUFFER_FLUSH(ah);
  534. if (tx_chainmask == 0x5) {
  535. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  536. AR_PHY_SWAP_ALT_CHAIN);
  537. }
  538. if (AR_SREV_9100(ah))
  539. REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
  540. REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
  541. }
  542. static void ar5008_hw_override_ini(struct ath_hw *ah,
  543. struct ath9k_channel *chan)
  544. {
  545. u32 val;
  546. /*
  547. * Set the RX_ABORT and RX_DIS and clear if off only after
  548. * RXE is set for MAC. This prevents frames with corrupted
  549. * descriptor status.
  550. */
  551. REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  552. if (AR_SREV_9280_20_OR_LATER(ah)) {
  553. val = REG_READ(ah, AR_PCU_MISC_MODE2);
  554. if (!AR_SREV_9271(ah))
  555. val &= ~AR_PCU_MISC_MODE2_HWWAR1;
  556. if (AR_SREV_9287_11_OR_LATER(ah))
  557. val = val & (~AR_PCU_MISC_MODE2_HWWAR2);
  558. REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
  559. }
  560. REG_SET_BIT(ah, AR_PHY_CCK_DETECT,
  561. AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
  562. if (AR_SREV_9280_20_OR_LATER(ah))
  563. return;
  564. /*
  565. * Disable BB clock gating
  566. * Necessary to avoid issues on AR5416 2.0
  567. */
  568. REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
  569. /*
  570. * Disable RIFS search on some chips to avoid baseband
  571. * hang issues.
  572. */
  573. if (AR_SREV_9100(ah) || AR_SREV_9160(ah)) {
  574. val = REG_READ(ah, AR_PHY_HEAVY_CLIP_FACTOR_RIFS);
  575. val &= ~AR_PHY_RIFS_INIT_DELAY;
  576. REG_WRITE(ah, AR_PHY_HEAVY_CLIP_FACTOR_RIFS, val);
  577. }
  578. }
  579. static void ar5008_hw_set_channel_regs(struct ath_hw *ah,
  580. struct ath9k_channel *chan)
  581. {
  582. u32 phymode;
  583. u32 enableDacFifo = 0;
  584. if (AR_SREV_9285_12_OR_LATER(ah))
  585. enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
  586. AR_PHY_FC_ENABLE_DAC_FIFO);
  587. phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
  588. | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
  589. if (IS_CHAN_HT40(chan)) {
  590. phymode |= AR_PHY_FC_DYN2040_EN;
  591. if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
  592. (chan->chanmode == CHANNEL_G_HT40PLUS))
  593. phymode |= AR_PHY_FC_DYN2040_PRI_CH;
  594. }
  595. REG_WRITE(ah, AR_PHY_TURBO, phymode);
  596. ath9k_hw_set11nmac2040(ah);
  597. ENABLE_REGWRITE_BUFFER(ah);
  598. REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
  599. REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
  600. REGWRITE_BUFFER_FLUSH(ah);
  601. }
  602. static int ar5008_hw_process_ini(struct ath_hw *ah,
  603. struct ath9k_channel *chan)
  604. {
  605. struct ath_common *common = ath9k_hw_common(ah);
  606. int i, regWrites = 0;
  607. u32 modesIndex, freqIndex;
  608. switch (chan->chanmode) {
  609. case CHANNEL_A:
  610. case CHANNEL_A_HT20:
  611. modesIndex = 1;
  612. freqIndex = 1;
  613. break;
  614. case CHANNEL_A_HT40PLUS:
  615. case CHANNEL_A_HT40MINUS:
  616. modesIndex = 2;
  617. freqIndex = 1;
  618. break;
  619. case CHANNEL_G:
  620. case CHANNEL_G_HT20:
  621. case CHANNEL_B:
  622. modesIndex = 4;
  623. freqIndex = 2;
  624. break;
  625. case CHANNEL_G_HT40PLUS:
  626. case CHANNEL_G_HT40MINUS:
  627. modesIndex = 3;
  628. freqIndex = 2;
  629. break;
  630. default:
  631. return -EINVAL;
  632. }
  633. /*
  634. * Set correct baseband to analog shift setting to
  635. * access analog chips.
  636. */
  637. REG_WRITE(ah, AR_PHY(0), 0x00000007);
  638. /* Write ADDAC shifts */
  639. REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
  640. if (ah->eep_ops->set_addac)
  641. ah->eep_ops->set_addac(ah, chan);
  642. REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
  643. REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
  644. ENABLE_REGWRITE_BUFFER(ah);
  645. for (i = 0; i < ah->iniModes.ia_rows; i++) {
  646. u32 reg = INI_RA(&ah->iniModes, i, 0);
  647. u32 val = INI_RA(&ah->iniModes, i, modesIndex);
  648. if (reg == AR_AN_TOP2 && ah->need_an_top2_fixup)
  649. val &= ~AR_AN_TOP2_PWDCLKIND;
  650. REG_WRITE(ah, reg, val);
  651. if (reg >= 0x7800 && reg < 0x78a0
  652. && ah->config.analog_shiftreg
  653. && (common->bus_ops->ath_bus_type != ATH_USB)) {
  654. udelay(100);
  655. }
  656. DO_DELAY(regWrites);
  657. }
  658. REGWRITE_BUFFER_FLUSH(ah);
  659. if (AR_SREV_9280(ah) || AR_SREV_9287_11_OR_LATER(ah))
  660. REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
  661. if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) ||
  662. AR_SREV_9287_11_OR_LATER(ah))
  663. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  664. if (AR_SREV_9271_10(ah)) {
  665. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN, AR_PHY_SPECTRAL_SCAN_ENA);
  666. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_ADC_ON, 0xa);
  667. }
  668. ENABLE_REGWRITE_BUFFER(ah);
  669. /* Write common array parameters */
  670. for (i = 0; i < ah->iniCommon.ia_rows; i++) {
  671. u32 reg = INI_RA(&ah->iniCommon, i, 0);
  672. u32 val = INI_RA(&ah->iniCommon, i, 1);
  673. REG_WRITE(ah, reg, val);
  674. if (reg >= 0x7800 && reg < 0x78a0
  675. && ah->config.analog_shiftreg
  676. && (common->bus_ops->ath_bus_type != ATH_USB)) {
  677. udelay(100);
  678. }
  679. DO_DELAY(regWrites);
  680. }
  681. REGWRITE_BUFFER_FLUSH(ah);
  682. REG_WRITE_ARRAY(&ah->iniBB_RfGain, freqIndex, regWrites);
  683. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  684. REG_WRITE_ARRAY(&ah->iniModesFastClock, modesIndex,
  685. regWrites);
  686. ar5008_hw_override_ini(ah, chan);
  687. ar5008_hw_set_channel_regs(ah, chan);
  688. ar5008_hw_init_chain_masks(ah);
  689. ath9k_olc_init(ah);
  690. ath9k_hw_apply_txpower(ah, chan, false);
  691. /* Write analog registers */
  692. if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
  693. ath_err(ath9k_hw_common(ah), "ar5416SetRfRegs failed\n");
  694. return -EIO;
  695. }
  696. return 0;
  697. }
  698. static void ar5008_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
  699. {
  700. u32 rfMode = 0;
  701. if (chan == NULL)
  702. return;
  703. rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
  704. ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
  705. if (!AR_SREV_9280_20_OR_LATER(ah))
  706. rfMode |= (IS_CHAN_5GHZ(chan)) ?
  707. AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
  708. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  709. rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
  710. REG_WRITE(ah, AR_PHY_MODE, rfMode);
  711. }
  712. static void ar5008_hw_mark_phy_inactive(struct ath_hw *ah)
  713. {
  714. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
  715. }
  716. static void ar5008_hw_set_delta_slope(struct ath_hw *ah,
  717. struct ath9k_channel *chan)
  718. {
  719. u32 coef_scaled, ds_coef_exp, ds_coef_man;
  720. u32 clockMhzScaled = 0x64000000;
  721. struct chan_centers centers;
  722. if (IS_CHAN_HALF_RATE(chan))
  723. clockMhzScaled = clockMhzScaled >> 1;
  724. else if (IS_CHAN_QUARTER_RATE(chan))
  725. clockMhzScaled = clockMhzScaled >> 2;
  726. ath9k_hw_get_channel_centers(ah, chan, &centers);
  727. coef_scaled = clockMhzScaled / centers.synth_center;
  728. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  729. &ds_coef_exp);
  730. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  731. AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
  732. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  733. AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
  734. coef_scaled = (9 * coef_scaled) / 10;
  735. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  736. &ds_coef_exp);
  737. REG_RMW_FIELD(ah, AR_PHY_HALFGI,
  738. AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
  739. REG_RMW_FIELD(ah, AR_PHY_HALFGI,
  740. AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
  741. }
  742. static bool ar5008_hw_rfbus_req(struct ath_hw *ah)
  743. {
  744. REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
  745. return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
  746. AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT);
  747. }
  748. static void ar5008_hw_rfbus_done(struct ath_hw *ah)
  749. {
  750. u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  751. ath9k_hw_synth_delay(ah, ah->curchan, synthDelay);
  752. REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
  753. }
  754. static void ar5008_restore_chainmask(struct ath_hw *ah)
  755. {
  756. int rx_chainmask = ah->rxchainmask;
  757. if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
  758. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
  759. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
  760. }
  761. }
  762. static u32 ar9160_hw_compute_pll_control(struct ath_hw *ah,
  763. struct ath9k_channel *chan)
  764. {
  765. u32 pll;
  766. pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
  767. if (chan && IS_CHAN_HALF_RATE(chan))
  768. pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
  769. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  770. pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
  771. if (chan && IS_CHAN_5GHZ(chan))
  772. pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
  773. else
  774. pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
  775. return pll;
  776. }
  777. static u32 ar5008_hw_compute_pll_control(struct ath_hw *ah,
  778. struct ath9k_channel *chan)
  779. {
  780. u32 pll;
  781. pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
  782. if (chan && IS_CHAN_HALF_RATE(chan))
  783. pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
  784. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  785. pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
  786. if (chan && IS_CHAN_5GHZ(chan))
  787. pll |= SM(0xa, AR_RTC_PLL_DIV);
  788. else
  789. pll |= SM(0xb, AR_RTC_PLL_DIV);
  790. return pll;
  791. }
  792. static bool ar5008_hw_ani_control_new(struct ath_hw *ah,
  793. enum ath9k_ani_cmd cmd,
  794. int param)
  795. {
  796. struct ath_common *common = ath9k_hw_common(ah);
  797. struct ath9k_channel *chan = ah->curchan;
  798. struct ar5416AniState *aniState = &chan->ani;
  799. s32 value, value2;
  800. switch (cmd & ah->ani_function) {
  801. case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
  802. /*
  803. * on == 1 means ofdm weak signal detection is ON
  804. * on == 1 is the default, for less noise immunity
  805. *
  806. * on == 0 means ofdm weak signal detection is OFF
  807. * on == 0 means more noise imm
  808. */
  809. u32 on = param ? 1 : 0;
  810. /*
  811. * make register setting for default
  812. * (weak sig detect ON) come from INI file
  813. */
  814. int m1ThreshLow = on ?
  815. aniState->iniDef.m1ThreshLow : m1ThreshLow_off;
  816. int m2ThreshLow = on ?
  817. aniState->iniDef.m2ThreshLow : m2ThreshLow_off;
  818. int m1Thresh = on ?
  819. aniState->iniDef.m1Thresh : m1Thresh_off;
  820. int m2Thresh = on ?
  821. aniState->iniDef.m2Thresh : m2Thresh_off;
  822. int m2CountThr = on ?
  823. aniState->iniDef.m2CountThr : m2CountThr_off;
  824. int m2CountThrLow = on ?
  825. aniState->iniDef.m2CountThrLow : m2CountThrLow_off;
  826. int m1ThreshLowExt = on ?
  827. aniState->iniDef.m1ThreshLowExt : m1ThreshLowExt_off;
  828. int m2ThreshLowExt = on ?
  829. aniState->iniDef.m2ThreshLowExt : m2ThreshLowExt_off;
  830. int m1ThreshExt = on ?
  831. aniState->iniDef.m1ThreshExt : m1ThreshExt_off;
  832. int m2ThreshExt = on ?
  833. aniState->iniDef.m2ThreshExt : m2ThreshExt_off;
  834. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  835. AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
  836. m1ThreshLow);
  837. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  838. AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
  839. m2ThreshLow);
  840. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  841. AR_PHY_SFCORR_M1_THRESH, m1Thresh);
  842. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  843. AR_PHY_SFCORR_M2_THRESH, m2Thresh);
  844. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  845. AR_PHY_SFCORR_M2COUNT_THR, m2CountThr);
  846. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  847. AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
  848. m2CountThrLow);
  849. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  850. AR_PHY_SFCORR_EXT_M1_THRESH_LOW, m1ThreshLowExt);
  851. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  852. AR_PHY_SFCORR_EXT_M2_THRESH_LOW, m2ThreshLowExt);
  853. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  854. AR_PHY_SFCORR_EXT_M1_THRESH, m1ThreshExt);
  855. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  856. AR_PHY_SFCORR_EXT_M2_THRESH, m2ThreshExt);
  857. if (on)
  858. REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
  859. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  860. else
  861. REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
  862. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  863. if (on != aniState->ofdmWeakSigDetect) {
  864. ath_dbg(common, ANI,
  865. "** ch %d: ofdm weak signal: %s=>%s\n",
  866. chan->channel,
  867. aniState->ofdmWeakSigDetect ?
  868. "on" : "off",
  869. on ? "on" : "off");
  870. if (on)
  871. ah->stats.ast_ani_ofdmon++;
  872. else
  873. ah->stats.ast_ani_ofdmoff++;
  874. aniState->ofdmWeakSigDetect = on;
  875. }
  876. break;
  877. }
  878. case ATH9K_ANI_FIRSTEP_LEVEL:{
  879. u32 level = param;
  880. if (level >= ARRAY_SIZE(firstep_table)) {
  881. ath_dbg(common, ANI,
  882. "ATH9K_ANI_FIRSTEP_LEVEL: level out of range (%u > %zu)\n",
  883. level, ARRAY_SIZE(firstep_table));
  884. return false;
  885. }
  886. /*
  887. * make register setting relative to default
  888. * from INI file & cap value
  889. */
  890. value = firstep_table[level] -
  891. firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
  892. aniState->iniDef.firstep;
  893. if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  894. value = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  895. if (value > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  896. value = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  897. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  898. AR_PHY_FIND_SIG_FIRSTEP,
  899. value);
  900. /*
  901. * we need to set first step low register too
  902. * make register setting relative to default
  903. * from INI file & cap value
  904. */
  905. value2 = firstep_table[level] -
  906. firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
  907. aniState->iniDef.firstepLow;
  908. if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  909. value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  910. if (value2 > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  911. value2 = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  912. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
  913. AR_PHY_FIND_SIG_FIRSTEP_LOW, value2);
  914. if (level != aniState->firstepLevel) {
  915. ath_dbg(common, ANI,
  916. "** ch %d: level %d=>%d[def:%d] firstep[level]=%d ini=%d\n",
  917. chan->channel,
  918. aniState->firstepLevel,
  919. level,
  920. ATH9K_ANI_FIRSTEP_LVL,
  921. value,
  922. aniState->iniDef.firstep);
  923. ath_dbg(common, ANI,
  924. "** ch %d: level %d=>%d[def:%d] firstep_low[level]=%d ini=%d\n",
  925. chan->channel,
  926. aniState->firstepLevel,
  927. level,
  928. ATH9K_ANI_FIRSTEP_LVL,
  929. value2,
  930. aniState->iniDef.firstepLow);
  931. if (level > aniState->firstepLevel)
  932. ah->stats.ast_ani_stepup++;
  933. else if (level < aniState->firstepLevel)
  934. ah->stats.ast_ani_stepdown++;
  935. aniState->firstepLevel = level;
  936. }
  937. break;
  938. }
  939. case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
  940. u32 level = param;
  941. if (level >= ARRAY_SIZE(cycpwrThr1_table)) {
  942. ath_dbg(common, ANI,
  943. "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level out of range (%u > %zu)\n",
  944. level, ARRAY_SIZE(cycpwrThr1_table));
  945. return false;
  946. }
  947. /*
  948. * make register setting relative to default
  949. * from INI file & cap value
  950. */
  951. value = cycpwrThr1_table[level] -
  952. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
  953. aniState->iniDef.cycpwrThr1;
  954. if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  955. value = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  956. if (value > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  957. value = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  958. REG_RMW_FIELD(ah, AR_PHY_TIMING5,
  959. AR_PHY_TIMING5_CYCPWR_THR1,
  960. value);
  961. /*
  962. * set AR_PHY_EXT_CCA for extension channel
  963. * make register setting relative to default
  964. * from INI file & cap value
  965. */
  966. value2 = cycpwrThr1_table[level] -
  967. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
  968. aniState->iniDef.cycpwrThr1Ext;
  969. if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  970. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  971. if (value2 > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  972. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  973. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
  974. AR_PHY_EXT_TIMING5_CYCPWR_THR1, value2);
  975. if (level != aniState->spurImmunityLevel) {
  976. ath_dbg(common, ANI,
  977. "** ch %d: level %d=>%d[def:%d] cycpwrThr1[level]=%d ini=%d\n",
  978. chan->channel,
  979. aniState->spurImmunityLevel,
  980. level,
  981. ATH9K_ANI_SPUR_IMMUNE_LVL,
  982. value,
  983. aniState->iniDef.cycpwrThr1);
  984. ath_dbg(common, ANI,
  985. "** ch %d: level %d=>%d[def:%d] cycpwrThr1Ext[level]=%d ini=%d\n",
  986. chan->channel,
  987. aniState->spurImmunityLevel,
  988. level,
  989. ATH9K_ANI_SPUR_IMMUNE_LVL,
  990. value2,
  991. aniState->iniDef.cycpwrThr1Ext);
  992. if (level > aniState->spurImmunityLevel)
  993. ah->stats.ast_ani_spurup++;
  994. else if (level < aniState->spurImmunityLevel)
  995. ah->stats.ast_ani_spurdown++;
  996. aniState->spurImmunityLevel = level;
  997. }
  998. break;
  999. }
  1000. case ATH9K_ANI_MRC_CCK:
  1001. /*
  1002. * You should not see this as AR5008, AR9001, AR9002
  1003. * does not have hardware support for MRC CCK.
  1004. */
  1005. WARN_ON(1);
  1006. break;
  1007. case ATH9K_ANI_PRESENT:
  1008. break;
  1009. default:
  1010. ath_dbg(common, ANI, "invalid cmd %u\n", cmd);
  1011. return false;
  1012. }
  1013. ath_dbg(common, ANI,
  1014. "ANI parameters: SI=%d, ofdmWS=%s FS=%d MRCcck=%s listenTime=%d ofdmErrs=%d cckErrs=%d\n",
  1015. aniState->spurImmunityLevel,
  1016. aniState->ofdmWeakSigDetect ? "on" : "off",
  1017. aniState->firstepLevel,
  1018. aniState->mrcCCK ? "on" : "off",
  1019. aniState->listenTime,
  1020. aniState->ofdmPhyErrCount,
  1021. aniState->cckPhyErrCount);
  1022. return true;
  1023. }
  1024. static void ar5008_hw_do_getnf(struct ath_hw *ah,
  1025. int16_t nfarray[NUM_NF_READINGS])
  1026. {
  1027. int16_t nf;
  1028. nf = MS(REG_READ(ah, AR_PHY_CCA), AR_PHY_MINCCA_PWR);
  1029. nfarray[0] = sign_extend32(nf, 8);
  1030. nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), AR_PHY_CH1_MINCCA_PWR);
  1031. nfarray[1] = sign_extend32(nf, 8);
  1032. nf = MS(REG_READ(ah, AR_PHY_CH2_CCA), AR_PHY_CH2_MINCCA_PWR);
  1033. nfarray[2] = sign_extend32(nf, 8);
  1034. if (!IS_CHAN_HT40(ah->curchan))
  1035. return;
  1036. nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR);
  1037. nfarray[3] = sign_extend32(nf, 8);
  1038. nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA), AR_PHY_CH1_EXT_MINCCA_PWR);
  1039. nfarray[4] = sign_extend32(nf, 8);
  1040. nf = MS(REG_READ(ah, AR_PHY_CH2_EXT_CCA), AR_PHY_CH2_EXT_MINCCA_PWR);
  1041. nfarray[5] = sign_extend32(nf, 8);
  1042. }
  1043. /*
  1044. * Initialize the ANI register values with default (ini) values.
  1045. * This routine is called during a (full) hardware reset after
  1046. * all the registers are initialised from the INI.
  1047. */
  1048. static void ar5008_hw_ani_cache_ini_regs(struct ath_hw *ah)
  1049. {
  1050. struct ath_common *common = ath9k_hw_common(ah);
  1051. struct ath9k_channel *chan = ah->curchan;
  1052. struct ar5416AniState *aniState = &chan->ani;
  1053. struct ath9k_ani_default *iniDef;
  1054. u32 val;
  1055. iniDef = &aniState->iniDef;
  1056. ath_dbg(common, ANI, "ver %d.%d opmode %u chan %d Mhz/0x%x\n",
  1057. ah->hw_version.macVersion,
  1058. ah->hw_version.macRev,
  1059. ah->opmode,
  1060. chan->channel,
  1061. chan->channelFlags);
  1062. val = REG_READ(ah, AR_PHY_SFCORR);
  1063. iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH);
  1064. iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH);
  1065. iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR);
  1066. val = REG_READ(ah, AR_PHY_SFCORR_LOW);
  1067. iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW);
  1068. iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW);
  1069. iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW);
  1070. val = REG_READ(ah, AR_PHY_SFCORR_EXT);
  1071. iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH);
  1072. iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH);
  1073. iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW);
  1074. iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW);
  1075. iniDef->firstep = REG_READ_FIELD(ah,
  1076. AR_PHY_FIND_SIG,
  1077. AR_PHY_FIND_SIG_FIRSTEP);
  1078. iniDef->firstepLow = REG_READ_FIELD(ah,
  1079. AR_PHY_FIND_SIG_LOW,
  1080. AR_PHY_FIND_SIG_FIRSTEP_LOW);
  1081. iniDef->cycpwrThr1 = REG_READ_FIELD(ah,
  1082. AR_PHY_TIMING5,
  1083. AR_PHY_TIMING5_CYCPWR_THR1);
  1084. iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah,
  1085. AR_PHY_EXT_CCA,
  1086. AR_PHY_EXT_TIMING5_CYCPWR_THR1);
  1087. /* these levels just got reset to defaults by the INI */
  1088. aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL;
  1089. aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL;
  1090. aniState->ofdmWeakSigDetect = ATH9K_ANI_USE_OFDM_WEAK_SIG;
  1091. aniState->mrcCCK = false; /* not available on pre AR9003 */
  1092. }
  1093. static void ar5008_hw_set_nf_limits(struct ath_hw *ah)
  1094. {
  1095. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_5416_2GHZ;
  1096. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_5416_2GHZ;
  1097. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_5416_2GHZ;
  1098. ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_5416_5GHZ;
  1099. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_5416_5GHZ;
  1100. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_5416_5GHZ;
  1101. }
  1102. static void ar5008_hw_set_radar_params(struct ath_hw *ah,
  1103. struct ath_hw_radar_conf *conf)
  1104. {
  1105. u32 radar_0 = 0, radar_1 = 0;
  1106. if (!conf) {
  1107. REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA);
  1108. return;
  1109. }
  1110. radar_0 |= AR_PHY_RADAR_0_ENA | AR_PHY_RADAR_0_FFT_ENA;
  1111. radar_0 |= SM(conf->fir_power, AR_PHY_RADAR_0_FIRPWR);
  1112. radar_0 |= SM(conf->radar_rssi, AR_PHY_RADAR_0_RRSSI);
  1113. radar_0 |= SM(conf->pulse_height, AR_PHY_RADAR_0_HEIGHT);
  1114. radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI);
  1115. radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND);
  1116. radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI;
  1117. radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK;
  1118. radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN);
  1119. radar_1 |= SM(conf->pulse_inband_step, AR_PHY_RADAR_1_RELSTEP_THRESH);
  1120. radar_1 |= SM(conf->radar_inband, AR_PHY_RADAR_1_RELPWR_THRESH);
  1121. REG_WRITE(ah, AR_PHY_RADAR_0, radar_0);
  1122. REG_WRITE(ah, AR_PHY_RADAR_1, radar_1);
  1123. if (conf->ext_channel)
  1124. REG_SET_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1125. else
  1126. REG_CLR_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1127. }
  1128. static void ar5008_hw_set_radar_conf(struct ath_hw *ah)
  1129. {
  1130. struct ath_hw_radar_conf *conf = &ah->radar_conf;
  1131. conf->fir_power = -33;
  1132. conf->radar_rssi = 20;
  1133. conf->pulse_height = 10;
  1134. conf->pulse_rssi = 24;
  1135. conf->pulse_inband = 15;
  1136. conf->pulse_maxlen = 255;
  1137. conf->pulse_inband_step = 12;
  1138. conf->radar_inband = 8;
  1139. }
  1140. int ar5008_hw_attach_phy_ops(struct ath_hw *ah)
  1141. {
  1142. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  1143. static const u32 ar5416_cca_regs[6] = {
  1144. AR_PHY_CCA,
  1145. AR_PHY_CH1_CCA,
  1146. AR_PHY_CH2_CCA,
  1147. AR_PHY_EXT_CCA,
  1148. AR_PHY_CH1_EXT_CCA,
  1149. AR_PHY_CH2_EXT_CCA
  1150. };
  1151. int ret;
  1152. ret = ar5008_hw_rf_alloc_ext_banks(ah);
  1153. if (ret)
  1154. return ret;
  1155. priv_ops->rf_set_freq = ar5008_hw_set_channel;
  1156. priv_ops->spur_mitigate_freq = ar5008_hw_spur_mitigate;
  1157. priv_ops->set_rf_regs = ar5008_hw_set_rf_regs;
  1158. priv_ops->set_channel_regs = ar5008_hw_set_channel_regs;
  1159. priv_ops->init_bb = ar5008_hw_init_bb;
  1160. priv_ops->process_ini = ar5008_hw_process_ini;
  1161. priv_ops->set_rfmode = ar5008_hw_set_rfmode;
  1162. priv_ops->mark_phy_inactive = ar5008_hw_mark_phy_inactive;
  1163. priv_ops->set_delta_slope = ar5008_hw_set_delta_slope;
  1164. priv_ops->rfbus_req = ar5008_hw_rfbus_req;
  1165. priv_ops->rfbus_done = ar5008_hw_rfbus_done;
  1166. priv_ops->restore_chainmask = ar5008_restore_chainmask;
  1167. priv_ops->do_getnf = ar5008_hw_do_getnf;
  1168. priv_ops->set_radar_params = ar5008_hw_set_radar_params;
  1169. priv_ops->ani_control = ar5008_hw_ani_control_new;
  1170. priv_ops->ani_cache_ini_regs = ar5008_hw_ani_cache_ini_regs;
  1171. if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah))
  1172. priv_ops->compute_pll_control = ar9160_hw_compute_pll_control;
  1173. else
  1174. priv_ops->compute_pll_control = ar5008_hw_compute_pll_control;
  1175. ar5008_hw_set_nf_limits(ah);
  1176. ar5008_hw_set_radar_conf(ah);
  1177. memcpy(ah->nf_regs, ar5416_cca_regs, sizeof(ah->nf_regs));
  1178. return 0;
  1179. }