You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ath9k_ar5008_phy.c 46KB

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