ar5008_phy.c 37 KB

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