ar5008_phy.c 47 KB

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