ar5008_phy.c 47 KB

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