ar5008_phy.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576
  1. /*
  2. * Copyright (c) 2008-2011 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "hw.h"
  17. #include "hw-ops.h"
  18. #include "../regd.h"
  19. #include "ar9002_phy.h"
  20. /* All code below is for AR5008, AR9001, AR9002 */
  21. static const int firstep_table[] =
  22. /* level: 0 1 2 3 4 5 6 7 8 */
  23. { -4, -2, 0, 2, 4, 6, 8, 10, 12 }; /* lvl 0-8, default 2 */
  24. static const int cycpwrThr1_table[] =
  25. /* level: 0 1 2 3 4 5 6 7 8 */
  26. { -6, -4, -2, 0, 2, 4, 6, 8 }; /* lvl 0-7, default 3 */
  27. /*
  28. * register values to turn OFDM weak signal detection OFF
  29. */
  30. static const int m1ThreshLow_off = 127;
  31. static const int m2ThreshLow_off = 127;
  32. static const int m1Thresh_off = 127;
  33. static const int m2Thresh_off = 127;
  34. static const int m2CountThr_off = 31;
  35. static const int m2CountThrLow_off = 63;
  36. static const int m1ThreshLowExt_off = 127;
  37. static const int m2ThreshLowExt_off = 127;
  38. static const int m1ThreshExt_off = 127;
  39. static const int m2ThreshExt_off = 127;
  40. static void ar5008_rf_bank_setup(u32 *bank, struct ar5416IniArray *array,
  41. int col)
  42. {
  43. int i;
  44. for (i = 0; i < array->ia_rows; i++)
  45. bank[i] = INI_RA(array, i, col);
  46. }
  47. #define REG_WRITE_RF_ARRAY(iniarray, regData, regWr) \
  48. ar5008_write_rf_array(ah, iniarray, regData, &(regWr))
  49. static void ar5008_write_rf_array(struct ath_hw *ah, struct ar5416IniArray *array,
  50. u32 *data, unsigned int *writecnt)
  51. {
  52. int r;
  53. ENABLE_REGWRITE_BUFFER(ah);
  54. for (r = 0; r < array->ia_rows; r++) {
  55. REG_WRITE(ah, INI_RA(array, r, 0), data[r]);
  56. DO_DELAY(*writecnt);
  57. }
  58. REGWRITE_BUFFER_FLUSH(ah);
  59. }
  60. /**
  61. * ar5008_hw_phy_modify_rx_buffer() - perform analog swizzling of parameters
  62. * @rfbuf:
  63. * @reg32:
  64. * @numBits:
  65. * @firstBit:
  66. * @column:
  67. *
  68. * Performs analog "swizzling" of parameters into their location.
  69. * Used on external AR2133/AR5133 radios.
  70. */
  71. static void ar5008_hw_phy_modify_rx_buffer(u32 *rfBuf, u32 reg32,
  72. u32 numBits, u32 firstBit,
  73. u32 column)
  74. {
  75. u32 tmp32, mask, arrayEntry, lastBit;
  76. int32_t bitPosition, bitsLeft;
  77. tmp32 = ath9k_hw_reverse_bits(reg32, numBits);
  78. arrayEntry = (firstBit - 1) / 8;
  79. bitPosition = (firstBit - 1) % 8;
  80. bitsLeft = numBits;
  81. while (bitsLeft > 0) {
  82. lastBit = (bitPosition + bitsLeft > 8) ?
  83. 8 : bitPosition + bitsLeft;
  84. mask = (((1 << lastBit) - 1) ^ ((1 << bitPosition) - 1)) <<
  85. (column * 8);
  86. rfBuf[arrayEntry] &= ~mask;
  87. rfBuf[arrayEntry] |= ((tmp32 << bitPosition) <<
  88. (column * 8)) & mask;
  89. bitsLeft -= 8 - bitPosition;
  90. tmp32 = tmp32 >> (8 - bitPosition);
  91. bitPosition = 0;
  92. arrayEntry++;
  93. }
  94. }
  95. /*
  96. * Fix on 2.4 GHz band for orientation sensitivity issue by increasing
  97. * rf_pwd_icsyndiv.
  98. *
  99. * Theoretical Rules:
  100. * if 2 GHz band
  101. * if forceBiasAuto
  102. * if synth_freq < 2412
  103. * bias = 0
  104. * else if 2412 <= synth_freq <= 2422
  105. * bias = 1
  106. * else // synth_freq > 2422
  107. * bias = 2
  108. * else if forceBias > 0
  109. * bias = forceBias & 7
  110. * else
  111. * no change, use value from ini file
  112. * else
  113. * no change, invalid band
  114. *
  115. * 1st Mod:
  116. * 2422 also uses value of 2
  117. * <approved>
  118. *
  119. * 2nd Mod:
  120. * Less than 2412 uses value of 0, 2412 and above uses value of 2
  121. */
  122. static void ar5008_hw_force_bias(struct ath_hw *ah, u16 synth_freq)
  123. {
  124. struct ath_common *common = ath9k_hw_common(ah);
  125. u32 tmp_reg;
  126. int reg_writes = 0;
  127. u32 new_bias = 0;
  128. if (!AR_SREV_5416(ah) || synth_freq >= 3000)
  129. return;
  130. BUG_ON(AR_SREV_9280_20_OR_LATER(ah));
  131. if (synth_freq < 2412)
  132. new_bias = 0;
  133. else if (synth_freq < 2422)
  134. new_bias = 1;
  135. else
  136. new_bias = 2;
  137. /* pre-reverse this field */
  138. tmp_reg = ath9k_hw_reverse_bits(new_bias, 3);
  139. ath_dbg(common, CONFIG, "Force rf_pwd_icsyndiv to %1d on %4d\n",
  140. new_bias, synth_freq);
  141. /* swizzle rf_pwd_icsyndiv */
  142. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data, tmp_reg, 3, 181, 3);
  143. /* write Bank 6 with new params */
  144. REG_WRITE_RF_ARRAY(&ah->iniBank6, ah->analogBank6Data, reg_writes);
  145. }
  146. /**
  147. * ar5008_hw_set_channel - tune to a channel on the external AR2133/AR5133 radios
  148. * @ah: atheros hardware structure
  149. * @chan:
  150. *
  151. * For the external AR2133/AR5133 radios, takes the MHz channel value and set
  152. * the channel value. Assumes writes enabled to analog bus and bank6 register
  153. * cache in ah->analogBank6Data.
  154. */
  155. static int ar5008_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
  156. {
  157. struct ath_common *common = ath9k_hw_common(ah);
  158. u32 channelSel = 0;
  159. u32 bModeSynth = 0;
  160. u32 aModeRefSel = 0;
  161. u32 reg32 = 0;
  162. u16 freq;
  163. struct chan_centers centers;
  164. ath9k_hw_get_channel_centers(ah, chan, &centers);
  165. freq = centers.synth_center;
  166. if (freq < 4800) {
  167. u32 txctl;
  168. if (((freq - 2192) % 5) == 0) {
  169. channelSel = ((freq - 672) * 2 - 3040) / 10;
  170. bModeSynth = 0;
  171. } else if (((freq - 2224) % 5) == 0) {
  172. channelSel = ((freq - 704) * 2 - 3040) / 10;
  173. bModeSynth = 1;
  174. } else {
  175. ath_err(common, "Invalid channel %u MHz\n", freq);
  176. return -EINVAL;
  177. }
  178. channelSel = (channelSel << 2) & 0xff;
  179. channelSel = ath9k_hw_reverse_bits(channelSel, 8);
  180. txctl = REG_READ(ah, AR_PHY_CCK_TX_CTRL);
  181. if (freq == 2484) {
  182. REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
  183. txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
  184. } else {
  185. REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
  186. txctl & ~AR_PHY_CCK_TX_CTRL_JAPAN);
  187. }
  188. } else if ((freq % 20) == 0 && freq >= 5120) {
  189. channelSel =
  190. ath9k_hw_reverse_bits(((freq - 4800) / 20 << 2), 8);
  191. aModeRefSel = ath9k_hw_reverse_bits(1, 2);
  192. } else if ((freq % 10) == 0) {
  193. channelSel =
  194. ath9k_hw_reverse_bits(((freq - 4800) / 10 << 1), 8);
  195. if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah))
  196. aModeRefSel = ath9k_hw_reverse_bits(2, 2);
  197. else
  198. aModeRefSel = ath9k_hw_reverse_bits(1, 2);
  199. } else if ((freq % 5) == 0) {
  200. channelSel = ath9k_hw_reverse_bits((freq - 4800) / 5, 8);
  201. aModeRefSel = ath9k_hw_reverse_bits(1, 2);
  202. } else {
  203. ath_err(common, "Invalid channel %u MHz\n", freq);
  204. return -EINVAL;
  205. }
  206. ar5008_hw_force_bias(ah, freq);
  207. reg32 =
  208. (channelSel << 8) | (aModeRefSel << 2) | (bModeSynth << 1) |
  209. (1 << 5) | 0x1;
  210. REG_WRITE(ah, AR_PHY(0x37), reg32);
  211. ah->curchan = chan;
  212. 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->bank6Temp, ah->iniBank6.ia_rows);
  426. return 0;
  427. #undef ATH_ALLOC_BANK
  428. }
  429. /**
  430. * ar5008_hw_rf_free_ext_banks - Free memory for analog bank scratch buffers
  431. * @ah: atheros hardware struture
  432. * For the external AR2133/AR5133 radios banks.
  433. */
  434. static void ar5008_hw_rf_free_ext_banks(struct ath_hw *ah)
  435. {
  436. #define ATH_FREE_BANK(bank) do { \
  437. kfree(bank); \
  438. bank = NULL; \
  439. } while (0);
  440. BUG_ON(AR_SREV_9280_20_OR_LATER(ah));
  441. ATH_FREE_BANK(ah->analogBank0Data);
  442. ATH_FREE_BANK(ah->analogBank1Data);
  443. ATH_FREE_BANK(ah->analogBank2Data);
  444. ATH_FREE_BANK(ah->analogBank3Data);
  445. ATH_FREE_BANK(ah->analogBank6Data);
  446. ATH_FREE_BANK(ah->analogBank6TPCData);
  447. ATH_FREE_BANK(ah->analogBank7Data);
  448. ATH_FREE_BANK(ah->bank6Temp);
  449. #undef ATH_FREE_BANK
  450. }
  451. /* *
  452. * ar5008_hw_set_rf_regs - programs rf registers based on EEPROM
  453. * @ah: atheros hardware structure
  454. * @chan:
  455. * @modesIndex:
  456. *
  457. * Used for the external AR2133/AR5133 radios.
  458. *
  459. * Reads the EEPROM header info from the device structure and programs
  460. * all rf registers. This routine requires access to the analog
  461. * rf device. This is not required for single-chip devices.
  462. */
  463. static bool ar5008_hw_set_rf_regs(struct ath_hw *ah,
  464. struct ath9k_channel *chan,
  465. u16 modesIndex)
  466. {
  467. u32 eepMinorRev;
  468. u32 ob5GHz = 0, db5GHz = 0;
  469. u32 ob2GHz = 0, db2GHz = 0;
  470. int regWrites = 0;
  471. /*
  472. * Software does not need to program bank data
  473. * for single chip devices, that is AR9280 or anything
  474. * after that.
  475. */
  476. if (AR_SREV_9280_20_OR_LATER(ah))
  477. return true;
  478. /* Setup rf parameters */
  479. eepMinorRev = ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV);
  480. /* Setup Bank 0 Write */
  481. ar5008_rf_bank_setup(ah->analogBank0Data, &ah->iniBank0, 1);
  482. /* Setup Bank 1 Write */
  483. ar5008_rf_bank_setup(ah->analogBank1Data, &ah->iniBank1, 1);
  484. /* Setup Bank 2 Write */
  485. ar5008_rf_bank_setup(ah->analogBank2Data, &ah->iniBank2, 1);
  486. /* Setup Bank 6 Write */
  487. ar5008_rf_bank_setup(ah->analogBank3Data, &ah->iniBank3,
  488. modesIndex);
  489. {
  490. int i;
  491. for (i = 0; i < ah->iniBank6TPC.ia_rows; i++) {
  492. ah->analogBank6Data[i] =
  493. INI_RA(&ah->iniBank6TPC, i, modesIndex);
  494. }
  495. }
  496. /* Only the 5 or 2 GHz OB/DB need to be set for a mode */
  497. if (eepMinorRev >= 2) {
  498. if (IS_CHAN_2GHZ(chan)) {
  499. ob2GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_2);
  500. db2GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_2);
  501. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
  502. ob2GHz, 3, 197, 0);
  503. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
  504. db2GHz, 3, 194, 0);
  505. } else {
  506. ob5GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_5);
  507. db5GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_5);
  508. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
  509. ob5GHz, 3, 203, 0);
  510. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
  511. db5GHz, 3, 200, 0);
  512. }
  513. }
  514. /* Setup Bank 7 Setup */
  515. ar5008_rf_bank_setup(ah->analogBank7Data, &ah->iniBank7, 1);
  516. /* Write Analog registers */
  517. REG_WRITE_RF_ARRAY(&ah->iniBank0, ah->analogBank0Data,
  518. regWrites);
  519. REG_WRITE_RF_ARRAY(&ah->iniBank1, ah->analogBank1Data,
  520. regWrites);
  521. REG_WRITE_RF_ARRAY(&ah->iniBank2, ah->analogBank2Data,
  522. regWrites);
  523. REG_WRITE_RF_ARRAY(&ah->iniBank3, ah->analogBank3Data,
  524. regWrites);
  525. REG_WRITE_RF_ARRAY(&ah->iniBank6TPC, ah->analogBank6Data,
  526. regWrites);
  527. REG_WRITE_RF_ARRAY(&ah->iniBank7, ah->analogBank7Data,
  528. regWrites);
  529. return true;
  530. }
  531. static void ar5008_hw_init_bb(struct ath_hw *ah,
  532. struct ath9k_channel *chan)
  533. {
  534. u32 synthDelay;
  535. synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  536. if (IS_CHAN_B(chan))
  537. synthDelay = (4 * synthDelay) / 22;
  538. else
  539. synthDelay /= 10;
  540. if (IS_CHAN_HALF_RATE(chan))
  541. synthDelay *= 2;
  542. else if (IS_CHAN_QUARTER_RATE(chan))
  543. synthDelay *= 4;
  544. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
  545. udelay(synthDelay + BASE_ACTIVATE_DELAY);
  546. }
  547. static void ar5008_hw_init_chain_masks(struct ath_hw *ah)
  548. {
  549. int rx_chainmask, tx_chainmask;
  550. rx_chainmask = ah->rxchainmask;
  551. tx_chainmask = ah->txchainmask;
  552. switch (rx_chainmask) {
  553. case 0x5:
  554. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  555. AR_PHY_SWAP_ALT_CHAIN);
  556. case 0x3:
  557. if (ah->hw_version.macVersion == AR_SREV_REVISION_5416_10) {
  558. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
  559. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
  560. break;
  561. }
  562. case 0x1:
  563. case 0x2:
  564. case 0x7:
  565. ENABLE_REGWRITE_BUFFER(ah);
  566. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
  567. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
  568. break;
  569. default:
  570. ENABLE_REGWRITE_BUFFER(ah);
  571. break;
  572. }
  573. REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
  574. REGWRITE_BUFFER_FLUSH(ah);
  575. if (tx_chainmask == 0x5) {
  576. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  577. AR_PHY_SWAP_ALT_CHAIN);
  578. }
  579. if (AR_SREV_9100(ah))
  580. REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
  581. REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
  582. }
  583. static void ar5008_hw_override_ini(struct ath_hw *ah,
  584. struct ath9k_channel *chan)
  585. {
  586. u32 val;
  587. /*
  588. * Set the RX_ABORT and RX_DIS and clear if off only after
  589. * RXE is set for MAC. This prevents frames with corrupted
  590. * descriptor status.
  591. */
  592. REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  593. if (AR_SREV_9280_20_OR_LATER(ah)) {
  594. val = REG_READ(ah, AR_PCU_MISC_MODE2);
  595. if (!AR_SREV_9271(ah))
  596. val &= ~AR_PCU_MISC_MODE2_HWWAR1;
  597. if (AR_SREV_9287_11_OR_LATER(ah))
  598. val = val & (~AR_PCU_MISC_MODE2_HWWAR2);
  599. REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
  600. }
  601. REG_SET_BIT(ah, AR_PHY_CCK_DETECT,
  602. AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
  603. if (AR_SREV_9280_20_OR_LATER(ah))
  604. return;
  605. /*
  606. * Disable BB clock gating
  607. * Necessary to avoid issues on AR5416 2.0
  608. */
  609. REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
  610. /*
  611. * Disable RIFS search on some chips to avoid baseband
  612. * hang issues.
  613. */
  614. if (AR_SREV_9100(ah) || AR_SREV_9160(ah)) {
  615. val = REG_READ(ah, AR_PHY_HEAVY_CLIP_FACTOR_RIFS);
  616. val &= ~AR_PHY_RIFS_INIT_DELAY;
  617. REG_WRITE(ah, AR_PHY_HEAVY_CLIP_FACTOR_RIFS, val);
  618. }
  619. }
  620. static void ar5008_hw_set_channel_regs(struct ath_hw *ah,
  621. struct ath9k_channel *chan)
  622. {
  623. u32 phymode;
  624. u32 enableDacFifo = 0;
  625. if (AR_SREV_9285_12_OR_LATER(ah))
  626. enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
  627. AR_PHY_FC_ENABLE_DAC_FIFO);
  628. phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
  629. | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
  630. if (IS_CHAN_HT40(chan)) {
  631. phymode |= AR_PHY_FC_DYN2040_EN;
  632. if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
  633. (chan->chanmode == CHANNEL_G_HT40PLUS))
  634. phymode |= AR_PHY_FC_DYN2040_PRI_CH;
  635. }
  636. REG_WRITE(ah, AR_PHY_TURBO, phymode);
  637. ath9k_hw_set11nmac2040(ah);
  638. ENABLE_REGWRITE_BUFFER(ah);
  639. REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
  640. REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
  641. REGWRITE_BUFFER_FLUSH(ah);
  642. }
  643. static int ar5008_hw_process_ini(struct ath_hw *ah,
  644. struct ath9k_channel *chan)
  645. {
  646. struct ath_common *common = ath9k_hw_common(ah);
  647. int i, regWrites = 0;
  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. if (ah->eep_ops->set_addac)
  682. ah->eep_ops->set_addac(ah, chan);
  683. REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
  684. REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
  685. ENABLE_REGWRITE_BUFFER(ah);
  686. for (i = 0; i < ah->iniModes.ia_rows; i++) {
  687. u32 reg = INI_RA(&ah->iniModes, i, 0);
  688. u32 val = INI_RA(&ah->iniModes, i, modesIndex);
  689. if (reg == AR_AN_TOP2 && ah->need_an_top2_fixup)
  690. val &= ~AR_AN_TOP2_PWDCLKIND;
  691. REG_WRITE(ah, reg, val);
  692. if (reg >= 0x7800 && reg < 0x78a0
  693. && ah->config.analog_shiftreg
  694. && (common->bus_ops->ath_bus_type != ATH_USB)) {
  695. udelay(100);
  696. }
  697. DO_DELAY(regWrites);
  698. }
  699. REGWRITE_BUFFER_FLUSH(ah);
  700. if (AR_SREV_9280(ah) || AR_SREV_9287_11_OR_LATER(ah))
  701. REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
  702. if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) ||
  703. AR_SREV_9287_11_OR_LATER(ah))
  704. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  705. if (AR_SREV_9271_10(ah)) {
  706. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN, AR_PHY_SPECTRAL_SCAN_ENA);
  707. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_ADC_ON, 0xa);
  708. }
  709. ENABLE_REGWRITE_BUFFER(ah);
  710. /* Write common array parameters */
  711. for (i = 0; i < ah->iniCommon.ia_rows; i++) {
  712. u32 reg = INI_RA(&ah->iniCommon, i, 0);
  713. u32 val = INI_RA(&ah->iniCommon, i, 1);
  714. REG_WRITE(ah, reg, val);
  715. if (reg >= 0x7800 && reg < 0x78a0
  716. && ah->config.analog_shiftreg
  717. && (common->bus_ops->ath_bus_type != ATH_USB)) {
  718. udelay(100);
  719. }
  720. DO_DELAY(regWrites);
  721. }
  722. REGWRITE_BUFFER_FLUSH(ah);
  723. REG_WRITE_ARRAY(&ah->iniBB_RfGain, freqIndex, regWrites);
  724. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  725. REG_WRITE_ARRAY(&ah->iniModesFastClock, modesIndex,
  726. regWrites);
  727. ar5008_hw_override_ini(ah, chan);
  728. ar5008_hw_set_channel_regs(ah, chan);
  729. ar5008_hw_init_chain_masks(ah);
  730. ath9k_olc_init(ah);
  731. ath9k_hw_apply_txpower(ah, chan);
  732. /* Write analog registers */
  733. if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
  734. ath_err(ath9k_hw_common(ah), "ar5416SetRfRegs failed\n");
  735. return -EIO;
  736. }
  737. return 0;
  738. }
  739. static void ar5008_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
  740. {
  741. u32 rfMode = 0;
  742. if (chan == NULL)
  743. return;
  744. rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
  745. ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
  746. if (!AR_SREV_9280_20_OR_LATER(ah))
  747. rfMode |= (IS_CHAN_5GHZ(chan)) ?
  748. AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
  749. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  750. rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
  751. REG_WRITE(ah, AR_PHY_MODE, rfMode);
  752. }
  753. static void ar5008_hw_mark_phy_inactive(struct ath_hw *ah)
  754. {
  755. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
  756. }
  757. static void ar5008_hw_set_delta_slope(struct ath_hw *ah,
  758. struct ath9k_channel *chan)
  759. {
  760. u32 coef_scaled, ds_coef_exp, ds_coef_man;
  761. u32 clockMhzScaled = 0x64000000;
  762. struct chan_centers centers;
  763. if (IS_CHAN_HALF_RATE(chan))
  764. clockMhzScaled = clockMhzScaled >> 1;
  765. else if (IS_CHAN_QUARTER_RATE(chan))
  766. clockMhzScaled = clockMhzScaled >> 2;
  767. ath9k_hw_get_channel_centers(ah, chan, &centers);
  768. coef_scaled = clockMhzScaled / centers.synth_center;
  769. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  770. &ds_coef_exp);
  771. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  772. AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
  773. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  774. AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
  775. coef_scaled = (9 * coef_scaled) / 10;
  776. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  777. &ds_coef_exp);
  778. REG_RMW_FIELD(ah, AR_PHY_HALFGI,
  779. AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
  780. REG_RMW_FIELD(ah, AR_PHY_HALFGI,
  781. AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
  782. }
  783. static bool ar5008_hw_rfbus_req(struct ath_hw *ah)
  784. {
  785. REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
  786. return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
  787. AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT);
  788. }
  789. static void ar5008_hw_rfbus_done(struct ath_hw *ah)
  790. {
  791. u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  792. if (IS_CHAN_B(ah->curchan))
  793. synthDelay = (4 * synthDelay) / 22;
  794. else
  795. synthDelay /= 10;
  796. udelay(synthDelay + BASE_ACTIVATE_DELAY);
  797. REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
  798. }
  799. static void ar5008_restore_chainmask(struct ath_hw *ah)
  800. {
  801. int rx_chainmask = ah->rxchainmask;
  802. if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
  803. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
  804. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
  805. }
  806. }
  807. static u32 ar9160_hw_compute_pll_control(struct ath_hw *ah,
  808. struct ath9k_channel *chan)
  809. {
  810. u32 pll;
  811. pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
  812. if (chan && IS_CHAN_HALF_RATE(chan))
  813. pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
  814. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  815. pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
  816. if (chan && IS_CHAN_5GHZ(chan))
  817. pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
  818. else
  819. pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
  820. return pll;
  821. }
  822. static u32 ar5008_hw_compute_pll_control(struct ath_hw *ah,
  823. struct ath9k_channel *chan)
  824. {
  825. u32 pll;
  826. pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
  827. if (chan && IS_CHAN_HALF_RATE(chan))
  828. pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
  829. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  830. pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
  831. if (chan && IS_CHAN_5GHZ(chan))
  832. pll |= SM(0xa, AR_RTC_PLL_DIV);
  833. else
  834. pll |= SM(0xb, AR_RTC_PLL_DIV);
  835. return pll;
  836. }
  837. static bool ar5008_hw_ani_control_old(struct ath_hw *ah,
  838. enum ath9k_ani_cmd cmd,
  839. int param)
  840. {
  841. struct ar5416AniState *aniState = &ah->curchan->ani;
  842. struct ath_common *common = ath9k_hw_common(ah);
  843. switch (cmd & ah->ani_function) {
  844. case ATH9K_ANI_NOISE_IMMUNITY_LEVEL:{
  845. u32 level = param;
  846. if (level >= ARRAY_SIZE(ah->totalSizeDesired)) {
  847. ath_dbg(common, ANI, "level out of range (%u > %zu)\n",
  848. level, ARRAY_SIZE(ah->totalSizeDesired));
  849. return false;
  850. }
  851. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
  852. AR_PHY_DESIRED_SZ_TOT_DES,
  853. ah->totalSizeDesired[level]);
  854. REG_RMW_FIELD(ah, AR_PHY_AGC_CTL1,
  855. AR_PHY_AGC_CTL1_COARSE_LOW,
  856. ah->coarse_low[level]);
  857. REG_RMW_FIELD(ah, AR_PHY_AGC_CTL1,
  858. AR_PHY_AGC_CTL1_COARSE_HIGH,
  859. ah->coarse_high[level]);
  860. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  861. AR_PHY_FIND_SIG_FIRPWR,
  862. ah->firpwr[level]);
  863. if (level > aniState->noiseImmunityLevel)
  864. ah->stats.ast_ani_niup++;
  865. else if (level < aniState->noiseImmunityLevel)
  866. ah->stats.ast_ani_nidown++;
  867. aniState->noiseImmunityLevel = level;
  868. break;
  869. }
  870. case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
  871. u32 on = param ? 1 : 0;
  872. if (on)
  873. REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
  874. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  875. else
  876. REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
  877. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  878. if (!on != aniState->ofdmWeakSigDetectOff) {
  879. if (on)
  880. ah->stats.ast_ani_ofdmon++;
  881. else
  882. ah->stats.ast_ani_ofdmoff++;
  883. aniState->ofdmWeakSigDetectOff = !on;
  884. }
  885. break;
  886. }
  887. case ATH9K_ANI_CCK_WEAK_SIGNAL_THR:{
  888. static const int weakSigThrCck[] = { 8, 6 };
  889. u32 high = param ? 1 : 0;
  890. REG_RMW_FIELD(ah, AR_PHY_CCK_DETECT,
  891. AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK,
  892. weakSigThrCck[high]);
  893. if (high != aniState->cckWeakSigThreshold) {
  894. if (high)
  895. ah->stats.ast_ani_cckhigh++;
  896. else
  897. ah->stats.ast_ani_ccklow++;
  898. aniState->cckWeakSigThreshold = high;
  899. }
  900. break;
  901. }
  902. case ATH9K_ANI_FIRSTEP_LEVEL:{
  903. static const int firstep[] = { 0, 4, 8 };
  904. u32 level = param;
  905. if (level >= ARRAY_SIZE(firstep)) {
  906. ath_dbg(common, ANI, "level out of range (%u > %zu)\n",
  907. level, ARRAY_SIZE(firstep));
  908. return false;
  909. }
  910. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  911. AR_PHY_FIND_SIG_FIRSTEP,
  912. firstep[level]);
  913. if (level > aniState->firstepLevel)
  914. ah->stats.ast_ani_stepup++;
  915. else if (level < aniState->firstepLevel)
  916. ah->stats.ast_ani_stepdown++;
  917. aniState->firstepLevel = level;
  918. break;
  919. }
  920. case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
  921. static const int cycpwrThr1[] = { 2, 4, 6, 8, 10, 12, 14, 16 };
  922. u32 level = param;
  923. if (level >= ARRAY_SIZE(cycpwrThr1)) {
  924. ath_dbg(common, ANI, "level out of range (%u > %zu)\n",
  925. level, ARRAY_SIZE(cycpwrThr1));
  926. return false;
  927. }
  928. REG_RMW_FIELD(ah, AR_PHY_TIMING5,
  929. AR_PHY_TIMING5_CYCPWR_THR1,
  930. cycpwrThr1[level]);
  931. if (level > aniState->spurImmunityLevel)
  932. ah->stats.ast_ani_spurup++;
  933. else if (level < aniState->spurImmunityLevel)
  934. ah->stats.ast_ani_spurdown++;
  935. aniState->spurImmunityLevel = level;
  936. break;
  937. }
  938. case ATH9K_ANI_PRESENT:
  939. break;
  940. default:
  941. ath_dbg(common, ANI, "invalid cmd %u\n", cmd);
  942. return false;
  943. }
  944. ath_dbg(common, ANI, "ANI parameters:\n");
  945. ath_dbg(common, ANI,
  946. "noiseImmunityLevel=%d, spurImmunityLevel=%d, ofdmWeakSigDetectOff=%d\n",
  947. aniState->noiseImmunityLevel,
  948. aniState->spurImmunityLevel,
  949. !aniState->ofdmWeakSigDetectOff);
  950. ath_dbg(common, ANI,
  951. "cckWeakSigThreshold=%d, firstepLevel=%d, listenTime=%d\n",
  952. aniState->cckWeakSigThreshold,
  953. aniState->firstepLevel,
  954. aniState->listenTime);
  955. ath_dbg(common, ANI, "ofdmPhyErrCount=%d, cckPhyErrCount=%d\n\n",
  956. aniState->ofdmPhyErrCount,
  957. aniState->cckPhyErrCount);
  958. return true;
  959. }
  960. static bool ar5008_hw_ani_control_new(struct ath_hw *ah,
  961. enum ath9k_ani_cmd cmd,
  962. int param)
  963. {
  964. struct ath_common *common = ath9k_hw_common(ah);
  965. struct ath9k_channel *chan = ah->curchan;
  966. struct ar5416AniState *aniState = &chan->ani;
  967. s32 value, value2;
  968. switch (cmd & ah->ani_function) {
  969. case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
  970. /*
  971. * on == 1 means ofdm weak signal detection is ON
  972. * on == 1 is the default, for less noise immunity
  973. *
  974. * on == 0 means ofdm weak signal detection is OFF
  975. * on == 0 means more noise imm
  976. */
  977. u32 on = param ? 1 : 0;
  978. /*
  979. * make register setting for default
  980. * (weak sig detect ON) come from INI file
  981. */
  982. int m1ThreshLow = on ?
  983. aniState->iniDef.m1ThreshLow : m1ThreshLow_off;
  984. int m2ThreshLow = on ?
  985. aniState->iniDef.m2ThreshLow : m2ThreshLow_off;
  986. int m1Thresh = on ?
  987. aniState->iniDef.m1Thresh : m1Thresh_off;
  988. int m2Thresh = on ?
  989. aniState->iniDef.m2Thresh : m2Thresh_off;
  990. int m2CountThr = on ?
  991. aniState->iniDef.m2CountThr : m2CountThr_off;
  992. int m2CountThrLow = on ?
  993. aniState->iniDef.m2CountThrLow : m2CountThrLow_off;
  994. int m1ThreshLowExt = on ?
  995. aniState->iniDef.m1ThreshLowExt : m1ThreshLowExt_off;
  996. int m2ThreshLowExt = on ?
  997. aniState->iniDef.m2ThreshLowExt : m2ThreshLowExt_off;
  998. int m1ThreshExt = on ?
  999. aniState->iniDef.m1ThreshExt : m1ThreshExt_off;
  1000. int m2ThreshExt = on ?
  1001. aniState->iniDef.m2ThreshExt : m2ThreshExt_off;
  1002. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  1003. AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
  1004. m1ThreshLow);
  1005. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  1006. AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
  1007. m2ThreshLow);
  1008. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  1009. AR_PHY_SFCORR_M1_THRESH, m1Thresh);
  1010. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  1011. AR_PHY_SFCORR_M2_THRESH, m2Thresh);
  1012. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  1013. AR_PHY_SFCORR_M2COUNT_THR, m2CountThr);
  1014. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  1015. AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
  1016. m2CountThrLow);
  1017. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  1018. AR_PHY_SFCORR_EXT_M1_THRESH_LOW, m1ThreshLowExt);
  1019. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  1020. AR_PHY_SFCORR_EXT_M2_THRESH_LOW, m2ThreshLowExt);
  1021. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  1022. AR_PHY_SFCORR_EXT_M1_THRESH, m1ThreshExt);
  1023. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  1024. AR_PHY_SFCORR_EXT_M2_THRESH, m2ThreshExt);
  1025. if (on)
  1026. REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
  1027. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  1028. else
  1029. REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
  1030. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  1031. if (!on != aniState->ofdmWeakSigDetectOff) {
  1032. ath_dbg(common, ANI,
  1033. "** ch %d: ofdm weak signal: %s=>%s\n",
  1034. chan->channel,
  1035. !aniState->ofdmWeakSigDetectOff ?
  1036. "on" : "off",
  1037. on ? "on" : "off");
  1038. if (on)
  1039. ah->stats.ast_ani_ofdmon++;
  1040. else
  1041. ah->stats.ast_ani_ofdmoff++;
  1042. aniState->ofdmWeakSigDetectOff = !on;
  1043. }
  1044. break;
  1045. }
  1046. case ATH9K_ANI_FIRSTEP_LEVEL:{
  1047. u32 level = param;
  1048. if (level >= ARRAY_SIZE(firstep_table)) {
  1049. ath_dbg(common, ANI,
  1050. "ATH9K_ANI_FIRSTEP_LEVEL: level out of range (%u > %zu)\n",
  1051. level, ARRAY_SIZE(firstep_table));
  1052. return false;
  1053. }
  1054. /*
  1055. * make register setting relative to default
  1056. * from INI file & cap value
  1057. */
  1058. value = firstep_table[level] -
  1059. firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
  1060. aniState->iniDef.firstep;
  1061. if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  1062. value = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  1063. if (value > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  1064. value = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  1065. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  1066. AR_PHY_FIND_SIG_FIRSTEP,
  1067. value);
  1068. /*
  1069. * we need to set first step low register too
  1070. * make register setting relative to default
  1071. * from INI file & cap value
  1072. */
  1073. value2 = firstep_table[level] -
  1074. firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
  1075. aniState->iniDef.firstepLow;
  1076. if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  1077. value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  1078. if (value2 > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  1079. value2 = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  1080. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
  1081. AR_PHY_FIND_SIG_FIRSTEP_LOW, value2);
  1082. if (level != aniState->firstepLevel) {
  1083. ath_dbg(common, ANI,
  1084. "** ch %d: level %d=>%d[def:%d] firstep[level]=%d ini=%d\n",
  1085. chan->channel,
  1086. aniState->firstepLevel,
  1087. level,
  1088. ATH9K_ANI_FIRSTEP_LVL_NEW,
  1089. value,
  1090. aniState->iniDef.firstep);
  1091. ath_dbg(common, ANI,
  1092. "** ch %d: level %d=>%d[def:%d] firstep_low[level]=%d ini=%d\n",
  1093. chan->channel,
  1094. aniState->firstepLevel,
  1095. level,
  1096. ATH9K_ANI_FIRSTEP_LVL_NEW,
  1097. value2,
  1098. aniState->iniDef.firstepLow);
  1099. if (level > aniState->firstepLevel)
  1100. ah->stats.ast_ani_stepup++;
  1101. else if (level < aniState->firstepLevel)
  1102. ah->stats.ast_ani_stepdown++;
  1103. aniState->firstepLevel = level;
  1104. }
  1105. break;
  1106. }
  1107. case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
  1108. u32 level = param;
  1109. if (level >= ARRAY_SIZE(cycpwrThr1_table)) {
  1110. ath_dbg(common, ANI,
  1111. "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level out of range (%u > %zu)\n",
  1112. level, ARRAY_SIZE(cycpwrThr1_table));
  1113. return false;
  1114. }
  1115. /*
  1116. * make register setting relative to default
  1117. * from INI file & cap value
  1118. */
  1119. value = cycpwrThr1_table[level] -
  1120. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
  1121. aniState->iniDef.cycpwrThr1;
  1122. if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  1123. value = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  1124. if (value > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  1125. value = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  1126. REG_RMW_FIELD(ah, AR_PHY_TIMING5,
  1127. AR_PHY_TIMING5_CYCPWR_THR1,
  1128. value);
  1129. /*
  1130. * set AR_PHY_EXT_CCA for extension channel
  1131. * make register setting relative to default
  1132. * from INI file & cap value
  1133. */
  1134. value2 = cycpwrThr1_table[level] -
  1135. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
  1136. aniState->iniDef.cycpwrThr1Ext;
  1137. if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  1138. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  1139. if (value2 > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  1140. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  1141. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
  1142. AR_PHY_EXT_TIMING5_CYCPWR_THR1, value2);
  1143. if (level != aniState->spurImmunityLevel) {
  1144. ath_dbg(common, ANI,
  1145. "** ch %d: level %d=>%d[def:%d] cycpwrThr1[level]=%d ini=%d\n",
  1146. chan->channel,
  1147. aniState->spurImmunityLevel,
  1148. level,
  1149. ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
  1150. value,
  1151. aniState->iniDef.cycpwrThr1);
  1152. ath_dbg(common, ANI,
  1153. "** ch %d: level %d=>%d[def:%d] cycpwrThr1Ext[level]=%d ini=%d\n",
  1154. chan->channel,
  1155. aniState->spurImmunityLevel,
  1156. level,
  1157. ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
  1158. value2,
  1159. aniState->iniDef.cycpwrThr1Ext);
  1160. if (level > aniState->spurImmunityLevel)
  1161. ah->stats.ast_ani_spurup++;
  1162. else if (level < aniState->spurImmunityLevel)
  1163. ah->stats.ast_ani_spurdown++;
  1164. aniState->spurImmunityLevel = level;
  1165. }
  1166. break;
  1167. }
  1168. case ATH9K_ANI_MRC_CCK:
  1169. /*
  1170. * You should not see this as AR5008, AR9001, AR9002
  1171. * does not have hardware support for MRC CCK.
  1172. */
  1173. WARN_ON(1);
  1174. break;
  1175. case ATH9K_ANI_PRESENT:
  1176. break;
  1177. default:
  1178. ath_dbg(common, ANI, "invalid cmd %u\n", cmd);
  1179. return false;
  1180. }
  1181. ath_dbg(common, ANI,
  1182. "ANI parameters: SI=%d, ofdmWS=%s FS=%d MRCcck=%s listenTime=%d ofdmErrs=%d cckErrs=%d\n",
  1183. aniState->spurImmunityLevel,
  1184. !aniState->ofdmWeakSigDetectOff ? "on" : "off",
  1185. aniState->firstepLevel,
  1186. !aniState->mrcCCKOff ? "on" : "off",
  1187. aniState->listenTime,
  1188. aniState->ofdmPhyErrCount,
  1189. aniState->cckPhyErrCount);
  1190. return true;
  1191. }
  1192. static void ar5008_hw_do_getnf(struct ath_hw *ah,
  1193. int16_t nfarray[NUM_NF_READINGS])
  1194. {
  1195. int16_t nf;
  1196. nf = MS(REG_READ(ah, AR_PHY_CCA), AR_PHY_MINCCA_PWR);
  1197. nfarray[0] = sign_extend32(nf, 8);
  1198. nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), AR_PHY_CH1_MINCCA_PWR);
  1199. nfarray[1] = sign_extend32(nf, 8);
  1200. nf = MS(REG_READ(ah, AR_PHY_CH2_CCA), AR_PHY_CH2_MINCCA_PWR);
  1201. nfarray[2] = sign_extend32(nf, 8);
  1202. if (!IS_CHAN_HT40(ah->curchan))
  1203. return;
  1204. nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR);
  1205. nfarray[3] = sign_extend32(nf, 8);
  1206. nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA), AR_PHY_CH1_EXT_MINCCA_PWR);
  1207. nfarray[4] = sign_extend32(nf, 8);
  1208. nf = MS(REG_READ(ah, AR_PHY_CH2_EXT_CCA), AR_PHY_CH2_EXT_MINCCA_PWR);
  1209. nfarray[5] = sign_extend32(nf, 8);
  1210. }
  1211. /*
  1212. * Initialize the ANI register values with default (ini) values.
  1213. * This routine is called during a (full) hardware reset after
  1214. * all the registers are initialised from the INI.
  1215. */
  1216. static void ar5008_hw_ani_cache_ini_regs(struct ath_hw *ah)
  1217. {
  1218. struct ath_common *common = ath9k_hw_common(ah);
  1219. struct ath9k_channel *chan = ah->curchan;
  1220. struct ar5416AniState *aniState = &chan->ani;
  1221. struct ath9k_ani_default *iniDef;
  1222. u32 val;
  1223. iniDef = &aniState->iniDef;
  1224. ath_dbg(common, ANI, "ver %d.%d opmode %u chan %d Mhz/0x%x\n",
  1225. ah->hw_version.macVersion,
  1226. ah->hw_version.macRev,
  1227. ah->opmode,
  1228. chan->channel,
  1229. chan->channelFlags);
  1230. val = REG_READ(ah, AR_PHY_SFCORR);
  1231. iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH);
  1232. iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH);
  1233. iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR);
  1234. val = REG_READ(ah, AR_PHY_SFCORR_LOW);
  1235. iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW);
  1236. iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW);
  1237. iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW);
  1238. val = REG_READ(ah, AR_PHY_SFCORR_EXT);
  1239. iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH);
  1240. iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH);
  1241. iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW);
  1242. iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW);
  1243. iniDef->firstep = REG_READ_FIELD(ah,
  1244. AR_PHY_FIND_SIG,
  1245. AR_PHY_FIND_SIG_FIRSTEP);
  1246. iniDef->firstepLow = REG_READ_FIELD(ah,
  1247. AR_PHY_FIND_SIG_LOW,
  1248. AR_PHY_FIND_SIG_FIRSTEP_LOW);
  1249. iniDef->cycpwrThr1 = REG_READ_FIELD(ah,
  1250. AR_PHY_TIMING5,
  1251. AR_PHY_TIMING5_CYCPWR_THR1);
  1252. iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah,
  1253. AR_PHY_EXT_CCA,
  1254. AR_PHY_EXT_TIMING5_CYCPWR_THR1);
  1255. /* these levels just got reset to defaults by the INI */
  1256. aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL_NEW;
  1257. aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL_NEW;
  1258. aniState->ofdmWeakSigDetectOff = !ATH9K_ANI_USE_OFDM_WEAK_SIG;
  1259. aniState->mrcCCKOff = true; /* not available on pre AR9003 */
  1260. }
  1261. static void ar5008_hw_set_nf_limits(struct ath_hw *ah)
  1262. {
  1263. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_5416_2GHZ;
  1264. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_5416_2GHZ;
  1265. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_5416_2GHZ;
  1266. ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_5416_5GHZ;
  1267. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_5416_5GHZ;
  1268. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_5416_5GHZ;
  1269. }
  1270. static void ar5008_hw_set_radar_params(struct ath_hw *ah,
  1271. struct ath_hw_radar_conf *conf)
  1272. {
  1273. u32 radar_0 = 0, radar_1 = 0;
  1274. if (!conf) {
  1275. REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA);
  1276. return;
  1277. }
  1278. radar_0 |= AR_PHY_RADAR_0_ENA | AR_PHY_RADAR_0_FFT_ENA;
  1279. radar_0 |= SM(conf->fir_power, AR_PHY_RADAR_0_FIRPWR);
  1280. radar_0 |= SM(conf->radar_rssi, AR_PHY_RADAR_0_RRSSI);
  1281. radar_0 |= SM(conf->pulse_height, AR_PHY_RADAR_0_HEIGHT);
  1282. radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI);
  1283. radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND);
  1284. radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI;
  1285. radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK;
  1286. radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN);
  1287. radar_1 |= SM(conf->pulse_inband_step, AR_PHY_RADAR_1_RELSTEP_THRESH);
  1288. radar_1 |= SM(conf->radar_inband, AR_PHY_RADAR_1_RELPWR_THRESH);
  1289. REG_WRITE(ah, AR_PHY_RADAR_0, radar_0);
  1290. REG_WRITE(ah, AR_PHY_RADAR_1, radar_1);
  1291. if (conf->ext_channel)
  1292. REG_SET_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1293. else
  1294. REG_CLR_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1295. }
  1296. static void ar5008_hw_set_radar_conf(struct ath_hw *ah)
  1297. {
  1298. struct ath_hw_radar_conf *conf = &ah->radar_conf;
  1299. conf->fir_power = -33;
  1300. conf->radar_rssi = 20;
  1301. conf->pulse_height = 10;
  1302. conf->pulse_rssi = 24;
  1303. conf->pulse_inband = 15;
  1304. conf->pulse_maxlen = 255;
  1305. conf->pulse_inband_step = 12;
  1306. conf->radar_inband = 8;
  1307. }
  1308. void ar5008_hw_attach_phy_ops(struct ath_hw *ah)
  1309. {
  1310. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  1311. static const u32 ar5416_cca_regs[6] = {
  1312. AR_PHY_CCA,
  1313. AR_PHY_CH1_CCA,
  1314. AR_PHY_CH2_CCA,
  1315. AR_PHY_EXT_CCA,
  1316. AR_PHY_CH1_EXT_CCA,
  1317. AR_PHY_CH2_EXT_CCA
  1318. };
  1319. priv_ops->rf_set_freq = ar5008_hw_set_channel;
  1320. priv_ops->spur_mitigate_freq = ar5008_hw_spur_mitigate;
  1321. priv_ops->rf_alloc_ext_banks = ar5008_hw_rf_alloc_ext_banks;
  1322. priv_ops->rf_free_ext_banks = ar5008_hw_rf_free_ext_banks;
  1323. priv_ops->set_rf_regs = ar5008_hw_set_rf_regs;
  1324. priv_ops->set_channel_regs = ar5008_hw_set_channel_regs;
  1325. priv_ops->init_bb = ar5008_hw_init_bb;
  1326. priv_ops->process_ini = ar5008_hw_process_ini;
  1327. priv_ops->set_rfmode = ar5008_hw_set_rfmode;
  1328. priv_ops->mark_phy_inactive = ar5008_hw_mark_phy_inactive;
  1329. priv_ops->set_delta_slope = ar5008_hw_set_delta_slope;
  1330. priv_ops->rfbus_req = ar5008_hw_rfbus_req;
  1331. priv_ops->rfbus_done = ar5008_hw_rfbus_done;
  1332. priv_ops->restore_chainmask = ar5008_restore_chainmask;
  1333. priv_ops->do_getnf = ar5008_hw_do_getnf;
  1334. priv_ops->set_radar_params = ar5008_hw_set_radar_params;
  1335. if (modparam_force_new_ani) {
  1336. priv_ops->ani_control = ar5008_hw_ani_control_new;
  1337. priv_ops->ani_cache_ini_regs = ar5008_hw_ani_cache_ini_regs;
  1338. } else
  1339. priv_ops->ani_control = ar5008_hw_ani_control_old;
  1340. if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah))
  1341. priv_ops->compute_pll_control = ar9160_hw_compute_pll_control;
  1342. else
  1343. priv_ops->compute_pll_control = ar5008_hw_compute_pll_control;
  1344. ar5008_hw_set_nf_limits(ah);
  1345. ar5008_hw_set_radar_conf(ah);
  1346. memcpy(ah->nf_regs, ar5416_cca_regs, sizeof(ah->nf_regs));
  1347. }