ar5008_phy.c 46 KB

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