ar5008_phy.c 44 KB

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