ar5008_phy.c 46 KB

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