phy.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  1. /*
  2. * Copyright (c) 2008-2009 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. /**
  17. * DOC: Programming Atheros 802.11n analog front end radios
  18. *
  19. * AR5416 MAC based PCI devices and AR518 MAC based PCI-Express
  20. * devices have either an external AR2133 analog front end radio for single
  21. * band 2.4 GHz communication or an AR5133 analog front end radio for dual
  22. * band 2.4 GHz / 5 GHz communication.
  23. *
  24. * All devices after the AR5416 and AR5418 family starting with the AR9280
  25. * have their analog front radios, MAC/BB and host PCIe/USB interface embedded
  26. * into a single-chip and require less programming.
  27. *
  28. * The following single-chips exist with a respective embedded radio:
  29. *
  30. * AR9280 - 11n dual-band 2x2 MIMO for PCIe
  31. * AR9281 - 11n single-band 1x2 MIMO for PCIe
  32. * AR9285 - 11n single-band 1x1 for PCIe
  33. * AR9287 - 11n single-band 2x2 MIMO for PCIe
  34. *
  35. * AR9220 - 11n dual-band 2x2 MIMO for PCI
  36. * AR9223 - 11n single-band 2x2 MIMO for PCI
  37. *
  38. * AR9287 - 11n single-band 1x1 MIMO for USB
  39. */
  40. #include "hw.h"
  41. /**
  42. * ath9k_hw_write_regs - ??
  43. *
  44. * @ah: atheros hardware structure
  45. * @modesIndex:
  46. * @freqIndex:
  47. * @regWrites:
  48. *
  49. * Used for both the chipsets with an external AR2133/AR5133 radios and
  50. * single-chip devices.
  51. */
  52. void ath9k_hw_write_regs(struct ath_hw *ah, u32 modesIndex,
  53. u32 freqIndex, int regWrites)
  54. {
  55. REG_WRITE_ARRAY(&ah->iniBB_RfGain, freqIndex, regWrites);
  56. }
  57. /**
  58. * ath9k_hw_ar9280_set_channel - set channel on single-chip device
  59. * @ah: atheros hardware structure
  60. * @chan:
  61. *
  62. * This is the function to change channel on single-chip devices, that is
  63. * all devices after ar9280.
  64. *
  65. * This function takes the channel value in MHz and sets
  66. * hardware channel value. Assumes writes have been enabled to analog bus.
  67. *
  68. * Actual Expression,
  69. *
  70. * For 2GHz channel,
  71. * Channel Frequency = (3/4) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
  72. * (freq_ref = 40MHz)
  73. *
  74. * For 5GHz channel,
  75. * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^10)
  76. * (freq_ref = 40MHz/(24>>amodeRefSel))
  77. */
  78. int ath9k_hw_ar9280_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
  79. {
  80. u16 bMode, fracMode, aModeRefSel = 0;
  81. u32 freq, ndiv, channelSel = 0, channelFrac = 0, reg32 = 0;
  82. struct chan_centers centers;
  83. u32 refDivA = 24;
  84. ath9k_hw_get_channel_centers(ah, chan, &centers);
  85. freq = centers.synth_center;
  86. reg32 = REG_READ(ah, AR_PHY_SYNTH_CONTROL);
  87. reg32 &= 0xc0000000;
  88. if (freq < 4800) { /* 2 GHz, fractional mode */
  89. u32 txctl;
  90. int regWrites = 0;
  91. bMode = 1;
  92. fracMode = 1;
  93. aModeRefSel = 0;
  94. channelSel = (freq * 0x10000) / 15;
  95. if (AR_SREV_9287_11_OR_LATER(ah)) {
  96. if (freq == 2484) {
  97. /* Enable channel spreading for channel 14 */
  98. REG_WRITE_ARRAY(&ah->iniCckfirJapan2484,
  99. 1, regWrites);
  100. } else {
  101. REG_WRITE_ARRAY(&ah->iniCckfirNormal,
  102. 1, regWrites);
  103. }
  104. } else {
  105. txctl = REG_READ(ah, AR_PHY_CCK_TX_CTRL);
  106. if (freq == 2484) {
  107. /* Enable channel spreading for channel 14 */
  108. REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
  109. txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
  110. } else {
  111. REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
  112. txctl &~ AR_PHY_CCK_TX_CTRL_JAPAN);
  113. }
  114. }
  115. } else {
  116. bMode = 0;
  117. fracMode = 0;
  118. switch(ah->eep_ops->get_eeprom(ah, EEP_FRAC_N_5G)) {
  119. case 0:
  120. if ((freq % 20) == 0) {
  121. aModeRefSel = 3;
  122. } else if ((freq % 10) == 0) {
  123. aModeRefSel = 2;
  124. }
  125. if (aModeRefSel)
  126. break;
  127. case 1:
  128. default:
  129. aModeRefSel = 0;
  130. /*
  131. * Enable 2G (fractional) mode for channels
  132. * which are 5MHz spaced.
  133. */
  134. fracMode = 1;
  135. refDivA = 1;
  136. channelSel = (freq * 0x8000) / 15;
  137. /* RefDivA setting */
  138. REG_RMW_FIELD(ah, AR_AN_SYNTH9,
  139. AR_AN_SYNTH9_REFDIVA, refDivA);
  140. }
  141. if (!fracMode) {
  142. ndiv = (freq * (refDivA >> aModeRefSel)) / 60;
  143. channelSel = ndiv & 0x1ff;
  144. channelFrac = (ndiv & 0xfffffe00) * 2;
  145. channelSel = (channelSel << 17) | channelFrac;
  146. }
  147. }
  148. reg32 = reg32 |
  149. (bMode << 29) |
  150. (fracMode << 28) | (aModeRefSel << 26) | (channelSel);
  151. REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
  152. ah->curchan = chan;
  153. ah->curchan_rad_index = -1;
  154. return 0;
  155. }
  156. /**
  157. * ath9k_hw_9280_spur_mitigate - convert baseband spur frequency
  158. * @ah: atheros hardware structure
  159. * @chan:
  160. *
  161. * For single-chip solutions. Converts to baseband spur frequency given the
  162. * input channel frequency and compute register settings below.
  163. */
  164. void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
  165. {
  166. int bb_spur = AR_NO_SPUR;
  167. int freq;
  168. int bin, cur_bin;
  169. int bb_spur_off, spur_subchannel_sd;
  170. int spur_freq_sd;
  171. int spur_delta_phase;
  172. int denominator;
  173. int upper, lower, cur_vit_mask;
  174. int tmp, newVal;
  175. int i;
  176. int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
  177. AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
  178. };
  179. int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
  180. AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
  181. };
  182. int inc[4] = { 0, 100, 0, 0 };
  183. struct chan_centers centers;
  184. int8_t mask_m[123];
  185. int8_t mask_p[123];
  186. int8_t mask_amt;
  187. int tmp_mask;
  188. int cur_bb_spur;
  189. bool is2GHz = IS_CHAN_2GHZ(chan);
  190. memset(&mask_m, 0, sizeof(int8_t) * 123);
  191. memset(&mask_p, 0, sizeof(int8_t) * 123);
  192. ath9k_hw_get_channel_centers(ah, chan, &centers);
  193. freq = centers.synth_center;
  194. ah->config.spurmode = SPUR_ENABLE_EEPROM;
  195. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  196. cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
  197. if (is2GHz)
  198. cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
  199. else
  200. cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
  201. if (AR_NO_SPUR == cur_bb_spur)
  202. break;
  203. cur_bb_spur = cur_bb_spur - freq;
  204. if (IS_CHAN_HT40(chan)) {
  205. if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
  206. (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
  207. bb_spur = cur_bb_spur;
  208. break;
  209. }
  210. } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
  211. (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
  212. bb_spur = cur_bb_spur;
  213. break;
  214. }
  215. }
  216. if (AR_NO_SPUR == bb_spur) {
  217. REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
  218. AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
  219. return;
  220. } else {
  221. REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
  222. AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
  223. }
  224. bin = bb_spur * 320;
  225. tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
  226. newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
  227. AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
  228. AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
  229. AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
  230. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
  231. newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
  232. AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
  233. AR_PHY_SPUR_REG_MASK_RATE_SELECT |
  234. AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
  235. SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
  236. REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
  237. if (IS_CHAN_HT40(chan)) {
  238. if (bb_spur < 0) {
  239. spur_subchannel_sd = 1;
  240. bb_spur_off = bb_spur + 10;
  241. } else {
  242. spur_subchannel_sd = 0;
  243. bb_spur_off = bb_spur - 10;
  244. }
  245. } else {
  246. spur_subchannel_sd = 0;
  247. bb_spur_off = bb_spur;
  248. }
  249. if (IS_CHAN_HT40(chan))
  250. spur_delta_phase =
  251. ((bb_spur * 262144) /
  252. 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
  253. else
  254. spur_delta_phase =
  255. ((bb_spur * 524288) /
  256. 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
  257. denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
  258. spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
  259. newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
  260. SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
  261. SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
  262. REG_WRITE(ah, AR_PHY_TIMING11, newVal);
  263. newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
  264. REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
  265. cur_bin = -6000;
  266. upper = bin + 100;
  267. lower = bin - 100;
  268. for (i = 0; i < 4; i++) {
  269. int pilot_mask = 0;
  270. int chan_mask = 0;
  271. int bp = 0;
  272. for (bp = 0; bp < 30; bp++) {
  273. if ((cur_bin > lower) && (cur_bin < upper)) {
  274. pilot_mask = pilot_mask | 0x1 << bp;
  275. chan_mask = chan_mask | 0x1 << bp;
  276. }
  277. cur_bin += 100;
  278. }
  279. cur_bin += inc[i];
  280. REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
  281. REG_WRITE(ah, chan_mask_reg[i], chan_mask);
  282. }
  283. cur_vit_mask = 6100;
  284. upper = bin + 120;
  285. lower = bin - 120;
  286. for (i = 0; i < 123; i++) {
  287. if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
  288. /* workaround for gcc bug #37014 */
  289. volatile int tmp_v = abs(cur_vit_mask - bin);
  290. if (tmp_v < 75)
  291. mask_amt = 1;
  292. else
  293. mask_amt = 0;
  294. if (cur_vit_mask < 0)
  295. mask_m[abs(cur_vit_mask / 100)] = mask_amt;
  296. else
  297. mask_p[cur_vit_mask / 100] = mask_amt;
  298. }
  299. cur_vit_mask -= 100;
  300. }
  301. tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
  302. | (mask_m[48] << 26) | (mask_m[49] << 24)
  303. | (mask_m[50] << 22) | (mask_m[51] << 20)
  304. | (mask_m[52] << 18) | (mask_m[53] << 16)
  305. | (mask_m[54] << 14) | (mask_m[55] << 12)
  306. | (mask_m[56] << 10) | (mask_m[57] << 8)
  307. | (mask_m[58] << 6) | (mask_m[59] << 4)
  308. | (mask_m[60] << 2) | (mask_m[61] << 0);
  309. REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
  310. REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
  311. tmp_mask = (mask_m[31] << 28)
  312. | (mask_m[32] << 26) | (mask_m[33] << 24)
  313. | (mask_m[34] << 22) | (mask_m[35] << 20)
  314. | (mask_m[36] << 18) | (mask_m[37] << 16)
  315. | (mask_m[48] << 14) | (mask_m[39] << 12)
  316. | (mask_m[40] << 10) | (mask_m[41] << 8)
  317. | (mask_m[42] << 6) | (mask_m[43] << 4)
  318. | (mask_m[44] << 2) | (mask_m[45] << 0);
  319. REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
  320. REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
  321. tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
  322. | (mask_m[18] << 26) | (mask_m[18] << 24)
  323. | (mask_m[20] << 22) | (mask_m[20] << 20)
  324. | (mask_m[22] << 18) | (mask_m[22] << 16)
  325. | (mask_m[24] << 14) | (mask_m[24] << 12)
  326. | (mask_m[25] << 10) | (mask_m[26] << 8)
  327. | (mask_m[27] << 6) | (mask_m[28] << 4)
  328. | (mask_m[29] << 2) | (mask_m[30] << 0);
  329. REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
  330. REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
  331. tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
  332. | (mask_m[2] << 26) | (mask_m[3] << 24)
  333. | (mask_m[4] << 22) | (mask_m[5] << 20)
  334. | (mask_m[6] << 18) | (mask_m[7] << 16)
  335. | (mask_m[8] << 14) | (mask_m[9] << 12)
  336. | (mask_m[10] << 10) | (mask_m[11] << 8)
  337. | (mask_m[12] << 6) | (mask_m[13] << 4)
  338. | (mask_m[14] << 2) | (mask_m[15] << 0);
  339. REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
  340. REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
  341. tmp_mask = (mask_p[15] << 28)
  342. | (mask_p[14] << 26) | (mask_p[13] << 24)
  343. | (mask_p[12] << 22) | (mask_p[11] << 20)
  344. | (mask_p[10] << 18) | (mask_p[9] << 16)
  345. | (mask_p[8] << 14) | (mask_p[7] << 12)
  346. | (mask_p[6] << 10) | (mask_p[5] << 8)
  347. | (mask_p[4] << 6) | (mask_p[3] << 4)
  348. | (mask_p[2] << 2) | (mask_p[1] << 0);
  349. REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
  350. REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
  351. tmp_mask = (mask_p[30] << 28)
  352. | (mask_p[29] << 26) | (mask_p[28] << 24)
  353. | (mask_p[27] << 22) | (mask_p[26] << 20)
  354. | (mask_p[25] << 18) | (mask_p[24] << 16)
  355. | (mask_p[23] << 14) | (mask_p[22] << 12)
  356. | (mask_p[21] << 10) | (mask_p[20] << 8)
  357. | (mask_p[19] << 6) | (mask_p[18] << 4)
  358. | (mask_p[17] << 2) | (mask_p[16] << 0);
  359. REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
  360. REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
  361. tmp_mask = (mask_p[45] << 28)
  362. | (mask_p[44] << 26) | (mask_p[43] << 24)
  363. | (mask_p[42] << 22) | (mask_p[41] << 20)
  364. | (mask_p[40] << 18) | (mask_p[39] << 16)
  365. | (mask_p[38] << 14) | (mask_p[37] << 12)
  366. | (mask_p[36] << 10) | (mask_p[35] << 8)
  367. | (mask_p[34] << 6) | (mask_p[33] << 4)
  368. | (mask_p[32] << 2) | (mask_p[31] << 0);
  369. REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
  370. REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
  371. tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
  372. | (mask_p[59] << 26) | (mask_p[58] << 24)
  373. | (mask_p[57] << 22) | (mask_p[56] << 20)
  374. | (mask_p[55] << 18) | (mask_p[54] << 16)
  375. | (mask_p[53] << 14) | (mask_p[52] << 12)
  376. | (mask_p[51] << 10) | (mask_p[50] << 8)
  377. | (mask_p[49] << 6) | (mask_p[48] << 4)
  378. | (mask_p[47] << 2) | (mask_p[46] << 0);
  379. REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
  380. REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
  381. }
  382. /* All code below is for non single-chip solutions */
  383. /**
  384. * ath9k_hw_set_channel - tune to a channel on the external AR2133/AR5133 radios
  385. * @ah: atheros hardware stucture
  386. * @chan:
  387. *
  388. * For the external AR2133/AR5133 radios, takes the MHz channel value and set
  389. * the channel value. Assumes writes enabled to analog bus and bank6 register
  390. * cache in ah->analogBank6Data.
  391. */
  392. int ath9k_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
  393. {
  394. struct ath_common *common = ath9k_hw_common(ah);
  395. u32 channelSel = 0;
  396. u32 bModeSynth = 0;
  397. u32 aModeRefSel = 0;
  398. u32 reg32 = 0;
  399. u16 freq;
  400. struct chan_centers centers;
  401. ath9k_hw_get_channel_centers(ah, chan, &centers);
  402. freq = centers.synth_center;
  403. if (freq < 4800) {
  404. u32 txctl;
  405. if (((freq - 2192) % 5) == 0) {
  406. channelSel = ((freq - 672) * 2 - 3040) / 10;
  407. bModeSynth = 0;
  408. } else if (((freq - 2224) % 5) == 0) {
  409. channelSel = ((freq - 704) * 2 - 3040) / 10;
  410. bModeSynth = 1;
  411. } else {
  412. ath_print(common, ATH_DBG_FATAL,
  413. "Invalid channel %u MHz\n", freq);
  414. return -EINVAL;
  415. }
  416. channelSel = (channelSel << 2) & 0xff;
  417. channelSel = ath9k_hw_reverse_bits(channelSel, 8);
  418. txctl = REG_READ(ah, AR_PHY_CCK_TX_CTRL);
  419. if (freq == 2484) {
  420. REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
  421. txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
  422. } else {
  423. REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
  424. txctl & ~AR_PHY_CCK_TX_CTRL_JAPAN);
  425. }
  426. } else if ((freq % 20) == 0 && freq >= 5120) {
  427. channelSel =
  428. ath9k_hw_reverse_bits(((freq - 4800) / 20 << 2), 8);
  429. aModeRefSel = ath9k_hw_reverse_bits(1, 2);
  430. } else if ((freq % 10) == 0) {
  431. channelSel =
  432. ath9k_hw_reverse_bits(((freq - 4800) / 10 << 1), 8);
  433. if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah))
  434. aModeRefSel = ath9k_hw_reverse_bits(2, 2);
  435. else
  436. aModeRefSel = ath9k_hw_reverse_bits(1, 2);
  437. } else if ((freq % 5) == 0) {
  438. channelSel = ath9k_hw_reverse_bits((freq - 4800) / 5, 8);
  439. aModeRefSel = ath9k_hw_reverse_bits(1, 2);
  440. } else {
  441. ath_print(common, ATH_DBG_FATAL,
  442. "Invalid channel %u MHz\n", freq);
  443. return -EINVAL;
  444. }
  445. reg32 =
  446. (channelSel << 8) | (aModeRefSel << 2) | (bModeSynth << 1) |
  447. (1 << 5) | 0x1;
  448. REG_WRITE(ah, AR_PHY(0x37), reg32);
  449. ah->curchan = chan;
  450. ah->curchan_rad_index = -1;
  451. return 0;
  452. }
  453. /**
  454. * ath9k_hw_spur_mitigate - convert baseband spur frequency for external radios
  455. * @ah: atheros hardware structure
  456. * @chan:
  457. *
  458. * For non single-chip solutions. Converts to baseband spur frequency given the
  459. * input channel frequency and compute register settings below.
  460. */
  461. void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
  462. {
  463. int bb_spur = AR_NO_SPUR;
  464. int bin, cur_bin;
  465. int spur_freq_sd;
  466. int spur_delta_phase;
  467. int denominator;
  468. int upper, lower, cur_vit_mask;
  469. int tmp, new;
  470. int i;
  471. int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
  472. AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
  473. };
  474. int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
  475. AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
  476. };
  477. int inc[4] = { 0, 100, 0, 0 };
  478. int8_t mask_m[123];
  479. int8_t mask_p[123];
  480. int8_t mask_amt;
  481. int tmp_mask;
  482. int cur_bb_spur;
  483. bool is2GHz = IS_CHAN_2GHZ(chan);
  484. memset(&mask_m, 0, sizeof(int8_t) * 123);
  485. memset(&mask_p, 0, sizeof(int8_t) * 123);
  486. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  487. cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
  488. if (AR_NO_SPUR == cur_bb_spur)
  489. break;
  490. cur_bb_spur = cur_bb_spur - (chan->channel * 10);
  491. if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
  492. bb_spur = cur_bb_spur;
  493. break;
  494. }
  495. }
  496. if (AR_NO_SPUR == bb_spur)
  497. return;
  498. bin = bb_spur * 32;
  499. tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
  500. new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
  501. AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
  502. AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
  503. AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
  504. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
  505. new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
  506. AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
  507. AR_PHY_SPUR_REG_MASK_RATE_SELECT |
  508. AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
  509. SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
  510. REG_WRITE(ah, AR_PHY_SPUR_REG, new);
  511. spur_delta_phase = ((bb_spur * 524288) / 100) &
  512. AR_PHY_TIMING11_SPUR_DELTA_PHASE;
  513. denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
  514. spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
  515. new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
  516. SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
  517. SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
  518. REG_WRITE(ah, AR_PHY_TIMING11, new);
  519. cur_bin = -6000;
  520. upper = bin + 100;
  521. lower = bin - 100;
  522. for (i = 0; i < 4; i++) {
  523. int pilot_mask = 0;
  524. int chan_mask = 0;
  525. int bp = 0;
  526. for (bp = 0; bp < 30; bp++) {
  527. if ((cur_bin > lower) && (cur_bin < upper)) {
  528. pilot_mask = pilot_mask | 0x1 << bp;
  529. chan_mask = chan_mask | 0x1 << bp;
  530. }
  531. cur_bin += 100;
  532. }
  533. cur_bin += inc[i];
  534. REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
  535. REG_WRITE(ah, chan_mask_reg[i], chan_mask);
  536. }
  537. cur_vit_mask = 6100;
  538. upper = bin + 120;
  539. lower = bin - 120;
  540. for (i = 0; i < 123; i++) {
  541. if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
  542. /* workaround for gcc bug #37014 */
  543. volatile int tmp_v = abs(cur_vit_mask - bin);
  544. if (tmp_v < 75)
  545. mask_amt = 1;
  546. else
  547. mask_amt = 0;
  548. if (cur_vit_mask < 0)
  549. mask_m[abs(cur_vit_mask / 100)] = mask_amt;
  550. else
  551. mask_p[cur_vit_mask / 100] = mask_amt;
  552. }
  553. cur_vit_mask -= 100;
  554. }
  555. tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
  556. | (mask_m[48] << 26) | (mask_m[49] << 24)
  557. | (mask_m[50] << 22) | (mask_m[51] << 20)
  558. | (mask_m[52] << 18) | (mask_m[53] << 16)
  559. | (mask_m[54] << 14) | (mask_m[55] << 12)
  560. | (mask_m[56] << 10) | (mask_m[57] << 8)
  561. | (mask_m[58] << 6) | (mask_m[59] << 4)
  562. | (mask_m[60] << 2) | (mask_m[61] << 0);
  563. REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
  564. REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
  565. tmp_mask = (mask_m[31] << 28)
  566. | (mask_m[32] << 26) | (mask_m[33] << 24)
  567. | (mask_m[34] << 22) | (mask_m[35] << 20)
  568. | (mask_m[36] << 18) | (mask_m[37] << 16)
  569. | (mask_m[48] << 14) | (mask_m[39] << 12)
  570. | (mask_m[40] << 10) | (mask_m[41] << 8)
  571. | (mask_m[42] << 6) | (mask_m[43] << 4)
  572. | (mask_m[44] << 2) | (mask_m[45] << 0);
  573. REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
  574. REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
  575. tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
  576. | (mask_m[18] << 26) | (mask_m[18] << 24)
  577. | (mask_m[20] << 22) | (mask_m[20] << 20)
  578. | (mask_m[22] << 18) | (mask_m[22] << 16)
  579. | (mask_m[24] << 14) | (mask_m[24] << 12)
  580. | (mask_m[25] << 10) | (mask_m[26] << 8)
  581. | (mask_m[27] << 6) | (mask_m[28] << 4)
  582. | (mask_m[29] << 2) | (mask_m[30] << 0);
  583. REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
  584. REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
  585. tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
  586. | (mask_m[2] << 26) | (mask_m[3] << 24)
  587. | (mask_m[4] << 22) | (mask_m[5] << 20)
  588. | (mask_m[6] << 18) | (mask_m[7] << 16)
  589. | (mask_m[8] << 14) | (mask_m[9] << 12)
  590. | (mask_m[10] << 10) | (mask_m[11] << 8)
  591. | (mask_m[12] << 6) | (mask_m[13] << 4)
  592. | (mask_m[14] << 2) | (mask_m[15] << 0);
  593. REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
  594. REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
  595. tmp_mask = (mask_p[15] << 28)
  596. | (mask_p[14] << 26) | (mask_p[13] << 24)
  597. | (mask_p[12] << 22) | (mask_p[11] << 20)
  598. | (mask_p[10] << 18) | (mask_p[9] << 16)
  599. | (mask_p[8] << 14) | (mask_p[7] << 12)
  600. | (mask_p[6] << 10) | (mask_p[5] << 8)
  601. | (mask_p[4] << 6) | (mask_p[3] << 4)
  602. | (mask_p[2] << 2) | (mask_p[1] << 0);
  603. REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
  604. REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
  605. tmp_mask = (mask_p[30] << 28)
  606. | (mask_p[29] << 26) | (mask_p[28] << 24)
  607. | (mask_p[27] << 22) | (mask_p[26] << 20)
  608. | (mask_p[25] << 18) | (mask_p[24] << 16)
  609. | (mask_p[23] << 14) | (mask_p[22] << 12)
  610. | (mask_p[21] << 10) | (mask_p[20] << 8)
  611. | (mask_p[19] << 6) | (mask_p[18] << 4)
  612. | (mask_p[17] << 2) | (mask_p[16] << 0);
  613. REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
  614. REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
  615. tmp_mask = (mask_p[45] << 28)
  616. | (mask_p[44] << 26) | (mask_p[43] << 24)
  617. | (mask_p[42] << 22) | (mask_p[41] << 20)
  618. | (mask_p[40] << 18) | (mask_p[39] << 16)
  619. | (mask_p[38] << 14) | (mask_p[37] << 12)
  620. | (mask_p[36] << 10) | (mask_p[35] << 8)
  621. | (mask_p[34] << 6) | (mask_p[33] << 4)
  622. | (mask_p[32] << 2) | (mask_p[31] << 0);
  623. REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
  624. REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
  625. tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
  626. | (mask_p[59] << 26) | (mask_p[58] << 24)
  627. | (mask_p[57] << 22) | (mask_p[56] << 20)
  628. | (mask_p[55] << 18) | (mask_p[54] << 16)
  629. | (mask_p[53] << 14) | (mask_p[52] << 12)
  630. | (mask_p[51] << 10) | (mask_p[50] << 8)
  631. | (mask_p[49] << 6) | (mask_p[48] << 4)
  632. | (mask_p[47] << 2) | (mask_p[46] << 0);
  633. REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
  634. REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
  635. }
  636. /**
  637. * ath9k_hw_rf_alloc_ext_banks - allocates banks for external radio programming
  638. * @ah: atheros hardware structure
  639. *
  640. * Only required for older devices with external AR2133/AR5133 radios.
  641. */
  642. int ath9k_hw_rf_alloc_ext_banks(struct ath_hw *ah)
  643. {
  644. #define ATH_ALLOC_BANK(bank, size) do { \
  645. bank = kzalloc((sizeof(u32) * size), GFP_KERNEL); \
  646. if (!bank) { \
  647. ath_print(common, ATH_DBG_FATAL, \
  648. "Cannot allocate RF banks\n"); \
  649. return -ENOMEM; \
  650. } \
  651. } while (0);
  652. struct ath_common *common = ath9k_hw_common(ah);
  653. BUG_ON(AR_SREV_9280_10_OR_LATER(ah));
  654. ATH_ALLOC_BANK(ah->analogBank0Data, ah->iniBank0.ia_rows);
  655. ATH_ALLOC_BANK(ah->analogBank1Data, ah->iniBank1.ia_rows);
  656. ATH_ALLOC_BANK(ah->analogBank2Data, ah->iniBank2.ia_rows);
  657. ATH_ALLOC_BANK(ah->analogBank3Data, ah->iniBank3.ia_rows);
  658. ATH_ALLOC_BANK(ah->analogBank6Data, ah->iniBank6.ia_rows);
  659. ATH_ALLOC_BANK(ah->analogBank6TPCData, ah->iniBank6TPC.ia_rows);
  660. ATH_ALLOC_BANK(ah->analogBank7Data, ah->iniBank7.ia_rows);
  661. ATH_ALLOC_BANK(ah->addac5416_21,
  662. ah->iniAddac.ia_rows * ah->iniAddac.ia_columns);
  663. ATH_ALLOC_BANK(ah->bank6Temp, ah->iniBank6.ia_rows);
  664. return 0;
  665. #undef ATH_ALLOC_BANK
  666. }
  667. /**
  668. * ath9k_hw_rf_free_ext_banks - Free memory for analog bank scratch buffers
  669. * @ah: atheros hardware struture
  670. * For the external AR2133/AR5133 radios banks.
  671. */
  672. void
  673. ath9k_hw_rf_free_ext_banks(struct ath_hw *ah)
  674. {
  675. #define ATH_FREE_BANK(bank) do { \
  676. kfree(bank); \
  677. bank = NULL; \
  678. } while (0);
  679. BUG_ON(AR_SREV_9280_10_OR_LATER(ah));
  680. ATH_FREE_BANK(ah->analogBank0Data);
  681. ATH_FREE_BANK(ah->analogBank1Data);
  682. ATH_FREE_BANK(ah->analogBank2Data);
  683. ATH_FREE_BANK(ah->analogBank3Data);
  684. ATH_FREE_BANK(ah->analogBank6Data);
  685. ATH_FREE_BANK(ah->analogBank6TPCData);
  686. ATH_FREE_BANK(ah->analogBank7Data);
  687. ATH_FREE_BANK(ah->addac5416_21);
  688. ATH_FREE_BANK(ah->bank6Temp);
  689. #undef ATH_FREE_BANK
  690. }
  691. /**
  692. * ath9k_phy_modify_rx_buffer() - perform analog swizzling of parameters
  693. * @rfbuf:
  694. * @reg32:
  695. * @numBits:
  696. * @firstBit:
  697. * @column:
  698. *
  699. * Performs analog "swizzling" of parameters into their location.
  700. * Used on external AR2133/AR5133 radios.
  701. */
  702. static void ath9k_phy_modify_rx_buffer(u32 *rfBuf, u32 reg32,
  703. u32 numBits, u32 firstBit,
  704. u32 column)
  705. {
  706. u32 tmp32, mask, arrayEntry, lastBit;
  707. int32_t bitPosition, bitsLeft;
  708. tmp32 = ath9k_hw_reverse_bits(reg32, numBits);
  709. arrayEntry = (firstBit - 1) / 8;
  710. bitPosition = (firstBit - 1) % 8;
  711. bitsLeft = numBits;
  712. while (bitsLeft > 0) {
  713. lastBit = (bitPosition + bitsLeft > 8) ?
  714. 8 : bitPosition + bitsLeft;
  715. mask = (((1 << lastBit) - 1) ^ ((1 << bitPosition) - 1)) <<
  716. (column * 8);
  717. rfBuf[arrayEntry] &= ~mask;
  718. rfBuf[arrayEntry] |= ((tmp32 << bitPosition) <<
  719. (column * 8)) & mask;
  720. bitsLeft -= 8 - bitPosition;
  721. tmp32 = tmp32 >> (8 - bitPosition);
  722. bitPosition = 0;
  723. arrayEntry++;
  724. }
  725. }
  726. /* *
  727. * ath9k_hw_set_rf_regs - programs rf registers based on EEPROM
  728. * @ah: atheros hardware structure
  729. * @chan:
  730. * @modesIndex:
  731. *
  732. * Used for the external AR2133/AR5133 radios.
  733. *
  734. * Reads the EEPROM header info from the device structure and programs
  735. * all rf registers. This routine requires access to the analog
  736. * rf device. This is not required for single-chip devices.
  737. */
  738. bool ath9k_hw_set_rf_regs(struct ath_hw *ah, struct ath9k_channel *chan,
  739. u16 modesIndex)
  740. {
  741. u32 eepMinorRev;
  742. u32 ob5GHz = 0, db5GHz = 0;
  743. u32 ob2GHz = 0, db2GHz = 0;
  744. int regWrites = 0;
  745. /*
  746. * Software does not need to program bank data
  747. * for single chip devices, that is AR9280 or anything
  748. * after that.
  749. */
  750. if (AR_SREV_9280_10_OR_LATER(ah))
  751. return true;
  752. /* Setup rf parameters */
  753. eepMinorRev = ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV);
  754. /* Setup Bank 0 Write */
  755. RF_BANK_SETUP(ah->analogBank0Data, &ah->iniBank0, 1);
  756. /* Setup Bank 1 Write */
  757. RF_BANK_SETUP(ah->analogBank1Data, &ah->iniBank1, 1);
  758. /* Setup Bank 2 Write */
  759. RF_BANK_SETUP(ah->analogBank2Data, &ah->iniBank2, 1);
  760. /* Setup Bank 6 Write */
  761. RF_BANK_SETUP(ah->analogBank3Data, &ah->iniBank3,
  762. modesIndex);
  763. {
  764. int i;
  765. for (i = 0; i < ah->iniBank6TPC.ia_rows; i++) {
  766. ah->analogBank6Data[i] =
  767. INI_RA(&ah->iniBank6TPC, i, modesIndex);
  768. }
  769. }
  770. /* Only the 5 or 2 GHz OB/DB need to be set for a mode */
  771. if (eepMinorRev >= 2) {
  772. if (IS_CHAN_2GHZ(chan)) {
  773. ob2GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_2);
  774. db2GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_2);
  775. ath9k_phy_modify_rx_buffer(ah->analogBank6Data,
  776. ob2GHz, 3, 197, 0);
  777. ath9k_phy_modify_rx_buffer(ah->analogBank6Data,
  778. db2GHz, 3, 194, 0);
  779. } else {
  780. ob5GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_5);
  781. db5GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_5);
  782. ath9k_phy_modify_rx_buffer(ah->analogBank6Data,
  783. ob5GHz, 3, 203, 0);
  784. ath9k_phy_modify_rx_buffer(ah->analogBank6Data,
  785. db5GHz, 3, 200, 0);
  786. }
  787. }
  788. /* Setup Bank 7 Setup */
  789. RF_BANK_SETUP(ah->analogBank7Data, &ah->iniBank7, 1);
  790. /* Write Analog registers */
  791. REG_WRITE_RF_ARRAY(&ah->iniBank0, ah->analogBank0Data,
  792. regWrites);
  793. REG_WRITE_RF_ARRAY(&ah->iniBank1, ah->analogBank1Data,
  794. regWrites);
  795. REG_WRITE_RF_ARRAY(&ah->iniBank2, ah->analogBank2Data,
  796. regWrites);
  797. REG_WRITE_RF_ARRAY(&ah->iniBank3, ah->analogBank3Data,
  798. regWrites);
  799. REG_WRITE_RF_ARRAY(&ah->iniBank6TPC, ah->analogBank6Data,
  800. regWrites);
  801. REG_WRITE_RF_ARRAY(&ah->iniBank7, ah->analogBank7Data,
  802. regWrites);
  803. return true;
  804. }
  805. /**
  806. * ath9k_hw_decrease_chain_power()
  807. *
  808. * @ah: atheros hardware structure
  809. * @chan:
  810. *
  811. * Only used on the AR5416 and AR5418 with the external AR2133/AR5133 radios.
  812. *
  813. * Sets a chain internal RF path to the lowest output power. Any
  814. * further writes to bank6 after this setting will override these
  815. * changes. Thus this function must be the last function in the
  816. * sequence to modify bank 6.
  817. *
  818. * This function must be called after ar5416SetRfRegs() which is
  819. * called from ath9k_hw_process_ini() due to swizzling of bank 6.
  820. * Depends on ah->analogBank6Data being initialized by
  821. * ath9k_hw_set_rf_regs()
  822. *
  823. * Additional additive reduction in power -
  824. * change chain's switch table so chain's tx state is actually the rx
  825. * state value. May produce different results in 2GHz/5GHz as well as
  826. * board to board but in general should be a reduction.
  827. *
  828. * Activated by #ifdef ALTER_SWITCH. Not tried yet. If so, must be
  829. * called after ah->eep_ops->set_board_values() due to RMW of
  830. * PHY_SWITCH_CHAIN_0.
  831. */
  832. void
  833. ath9k_hw_decrease_chain_power(struct ath_hw *ah, struct ath9k_channel *chan)
  834. {
  835. int i, regWrites = 0;
  836. u32 bank6SelMask;
  837. u32 *bank6Temp = ah->bank6Temp;
  838. switch (ah->config.diversity_control) {
  839. case ATH9K_ANT_FIXED_A:
  840. bank6SelMask =
  841. (ah->config.antenna_switch_swap & ANTSWAP_AB) ?
  842. REDUCE_CHAIN_0 : /* swapped, reduce chain 0 */
  843. REDUCE_CHAIN_1; /* normal, select chain 1/2 to reduce */
  844. break;
  845. case ATH9K_ANT_FIXED_B:
  846. bank6SelMask =
  847. (ah->config.antenna_switch_swap & ANTSWAP_AB) ?
  848. REDUCE_CHAIN_1 : /* swapped, reduce chain 1/2 */
  849. REDUCE_CHAIN_0; /* normal, select chain 0 to reduce */
  850. break;
  851. case ATH9K_ANT_VARIABLE:
  852. return; /* do not change anything */
  853. break;
  854. default:
  855. return; /* do not change anything */
  856. break;
  857. }
  858. for (i = 0; i < ah->iniBank6.ia_rows; i++)
  859. bank6Temp[i] = ah->analogBank6Data[i];
  860. /* Write Bank 5 to switch Bank 6 write to selected chain only */
  861. REG_WRITE(ah, AR_PHY_BASE + 0xD8, bank6SelMask);
  862. /*
  863. * Modify Bank6 selected chain to use lowest amplification.
  864. * Modifies the parameters to a value of 1.
  865. * Depends on existing bank 6 values to be cached in
  866. * ah->analogBank6Data
  867. */
  868. ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 189, 0);
  869. ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 190, 0);
  870. ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 191, 0);
  871. ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 192, 0);
  872. ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 193, 0);
  873. ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 222, 0);
  874. ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 245, 0);
  875. ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 246, 0);
  876. ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 247, 0);
  877. REG_WRITE_RF_ARRAY(&ah->iniBank6, bank6Temp, regWrites);
  878. REG_WRITE(ah, AR_PHY_BASE + 0xD8, 0x00000053);
  879. #ifdef ALTER_SWITCH
  880. REG_WRITE(ah, PHY_SWITCH_CHAIN_0,
  881. (REG_READ(ah, PHY_SWITCH_CHAIN_0) & ~0x38)
  882. | ((REG_READ(ah, PHY_SWITCH_CHAIN_0) >> 3) & 0x38));
  883. #endif
  884. }