ar5008_phy.c 38 KB

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