ar5008_phy.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373
  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. #include "ar5008_initvals.h"
  21. /* All code below is for AR5008, AR9001, AR9002 */
  22. #define AR5008_OFDM_RATES 8
  23. #define AR5008_HT_SS_RATES 8
  24. #define AR5008_HT_DS_RATES 8
  25. #define AR5008_HT20_SHIFT 16
  26. #define AR5008_HT40_SHIFT 24
  27. #define AR5008_11NA_OFDM_SHIFT 0
  28. #define AR5008_11NA_HT_SS_SHIFT 8
  29. #define AR5008_11NA_HT_DS_SHIFT 16
  30. #define AR5008_11NG_OFDM_SHIFT 4
  31. #define AR5008_11NG_HT_SS_SHIFT 12
  32. #define AR5008_11NG_HT_DS_SHIFT 20
  33. static const int firstep_table[] =
  34. /* level: 0 1 2 3 4 5 6 7 8 */
  35. { -4, -2, 0, 2, 4, 6, 8, 10, 12 }; /* lvl 0-8, default 2 */
  36. /*
  37. * register values to turn OFDM weak signal detection OFF
  38. */
  39. static const int m1ThreshLow_off = 127;
  40. static const int m2ThreshLow_off = 127;
  41. static const int m1Thresh_off = 127;
  42. static const int m2Thresh_off = 127;
  43. static const int m2CountThr_off = 31;
  44. static const int m2CountThrLow_off = 63;
  45. static const int m1ThreshLowExt_off = 127;
  46. static const int m2ThreshLowExt_off = 127;
  47. static const int m1ThreshExt_off = 127;
  48. static const int m2ThreshExt_off = 127;
  49. static const struct ar5416IniArray bank0 = STATIC_INI_ARRAY(ar5416Bank0);
  50. static const struct ar5416IniArray bank1 = STATIC_INI_ARRAY(ar5416Bank1);
  51. static const struct ar5416IniArray bank2 = STATIC_INI_ARRAY(ar5416Bank2);
  52. static const struct ar5416IniArray bank3 = STATIC_INI_ARRAY(ar5416Bank3);
  53. static const struct ar5416IniArray bank7 = STATIC_INI_ARRAY(ar5416Bank7);
  54. static void ar5008_write_bank6(struct ath_hw *ah, unsigned int *writecnt)
  55. {
  56. struct ar5416IniArray *array = &ah->iniBank6;
  57. u32 *data = ah->analogBank6Data;
  58. int r;
  59. ENABLE_REGWRITE_BUFFER(ah);
  60. for (r = 0; r < array->ia_rows; r++) {
  61. REG_WRITE(ah, INI_RA(array, r, 0), data[r]);
  62. DO_DELAY(*writecnt);
  63. }
  64. REGWRITE_BUFFER_FLUSH(ah);
  65. }
  66. /**
  67. * ar5008_hw_phy_modify_rx_buffer() - perform analog swizzling of parameters
  68. * @rfbuf:
  69. * @reg32:
  70. * @numBits:
  71. * @firstBit:
  72. * @column:
  73. *
  74. * Performs analog "swizzling" of parameters into their location.
  75. * Used on external AR2133/AR5133 radios.
  76. */
  77. static void ar5008_hw_phy_modify_rx_buffer(u32 *rfBuf, u32 reg32,
  78. u32 numBits, u32 firstBit,
  79. u32 column)
  80. {
  81. u32 tmp32, mask, arrayEntry, lastBit;
  82. int32_t bitPosition, bitsLeft;
  83. tmp32 = ath9k_hw_reverse_bits(reg32, numBits);
  84. arrayEntry = (firstBit - 1) / 8;
  85. bitPosition = (firstBit - 1) % 8;
  86. bitsLeft = numBits;
  87. while (bitsLeft > 0) {
  88. lastBit = (bitPosition + bitsLeft > 8) ?
  89. 8 : bitPosition + bitsLeft;
  90. mask = (((1 << lastBit) - 1) ^ ((1 << bitPosition) - 1)) <<
  91. (column * 8);
  92. rfBuf[arrayEntry] &= ~mask;
  93. rfBuf[arrayEntry] |= ((tmp32 << bitPosition) <<
  94. (column * 8)) & mask;
  95. bitsLeft -= 8 - bitPosition;
  96. tmp32 = tmp32 >> (8 - bitPosition);
  97. bitPosition = 0;
  98. arrayEntry++;
  99. }
  100. }
  101. /*
  102. * Fix on 2.4 GHz band for orientation sensitivity issue by increasing
  103. * rf_pwd_icsyndiv.
  104. *
  105. * Theoretical Rules:
  106. * if 2 GHz band
  107. * if forceBiasAuto
  108. * if synth_freq < 2412
  109. * bias = 0
  110. * else if 2412 <= synth_freq <= 2422
  111. * bias = 1
  112. * else // synth_freq > 2422
  113. * bias = 2
  114. * else if forceBias > 0
  115. * bias = forceBias & 7
  116. * else
  117. * no change, use value from ini file
  118. * else
  119. * no change, invalid band
  120. *
  121. * 1st Mod:
  122. * 2422 also uses value of 2
  123. * <approved>
  124. *
  125. * 2nd Mod:
  126. * Less than 2412 uses value of 0, 2412 and above uses value of 2
  127. */
  128. static void ar5008_hw_force_bias(struct ath_hw *ah, u16 synth_freq)
  129. {
  130. struct ath_common *common = ath9k_hw_common(ah);
  131. u32 tmp_reg;
  132. int reg_writes = 0;
  133. u32 new_bias = 0;
  134. if (!AR_SREV_5416(ah) || synth_freq >= 3000)
  135. return;
  136. BUG_ON(AR_SREV_9280_20_OR_LATER(ah));
  137. if (synth_freq < 2412)
  138. new_bias = 0;
  139. else if (synth_freq < 2422)
  140. new_bias = 1;
  141. else
  142. new_bias = 2;
  143. /* pre-reverse this field */
  144. tmp_reg = ath9k_hw_reverse_bits(new_bias, 3);
  145. ath_dbg(common, CONFIG, "Force rf_pwd_icsyndiv to %1d on %4d\n",
  146. new_bias, synth_freq);
  147. /* swizzle rf_pwd_icsyndiv */
  148. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data, tmp_reg, 3, 181, 3);
  149. /* write Bank 6 with new params */
  150. ar5008_write_bank6(ah, &reg_writes);
  151. }
  152. /**
  153. * ar5008_hw_set_channel - tune to a channel on the external AR2133/AR5133 radios
  154. * @ah: atheros hardware structure
  155. * @chan:
  156. *
  157. * For the external AR2133/AR5133 radios, takes the MHz channel value and set
  158. * the channel value. Assumes writes enabled to analog bus and bank6 register
  159. * cache in ah->analogBank6Data.
  160. */
  161. static int ar5008_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
  162. {
  163. struct ath_common *common = ath9k_hw_common(ah);
  164. u32 channelSel = 0;
  165. u32 bModeSynth = 0;
  166. u32 aModeRefSel = 0;
  167. u32 reg32 = 0;
  168. u16 freq;
  169. struct chan_centers centers;
  170. ath9k_hw_get_channel_centers(ah, chan, &centers);
  171. freq = centers.synth_center;
  172. if (freq < 4800) {
  173. u32 txctl;
  174. if (((freq - 2192) % 5) == 0) {
  175. channelSel = ((freq - 672) * 2 - 3040) / 10;
  176. bModeSynth = 0;
  177. } else if (((freq - 2224) % 5) == 0) {
  178. channelSel = ((freq - 704) * 2 - 3040) / 10;
  179. bModeSynth = 1;
  180. } else {
  181. ath_err(common, "Invalid channel %u MHz\n", freq);
  182. return -EINVAL;
  183. }
  184. channelSel = (channelSel << 2) & 0xff;
  185. channelSel = ath9k_hw_reverse_bits(channelSel, 8);
  186. txctl = REG_READ(ah, AR_PHY_CCK_TX_CTRL);
  187. if (freq == 2484) {
  188. REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
  189. txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
  190. } else {
  191. REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
  192. txctl & ~AR_PHY_CCK_TX_CTRL_JAPAN);
  193. }
  194. } else if ((freq % 20) == 0 && freq >= 5120) {
  195. channelSel =
  196. ath9k_hw_reverse_bits(((freq - 4800) / 20 << 2), 8);
  197. aModeRefSel = ath9k_hw_reverse_bits(1, 2);
  198. } else if ((freq % 10) == 0) {
  199. channelSel =
  200. ath9k_hw_reverse_bits(((freq - 4800) / 10 << 1), 8);
  201. if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah))
  202. aModeRefSel = ath9k_hw_reverse_bits(2, 2);
  203. else
  204. aModeRefSel = ath9k_hw_reverse_bits(1, 2);
  205. } else if ((freq % 5) == 0) {
  206. channelSel = ath9k_hw_reverse_bits((freq - 4800) / 5, 8);
  207. aModeRefSel = ath9k_hw_reverse_bits(1, 2);
  208. } else {
  209. ath_err(common, "Invalid channel %u MHz\n", freq);
  210. return -EINVAL;
  211. }
  212. ar5008_hw_force_bias(ah, freq);
  213. reg32 =
  214. (channelSel << 8) | (aModeRefSel << 2) | (bModeSynth << 1) |
  215. (1 << 5) | 0x1;
  216. REG_WRITE(ah, AR_PHY(0x37), reg32);
  217. ah->curchan = chan;
  218. return 0;
  219. }
  220. void ar5008_hw_cmn_spur_mitigate(struct ath_hw *ah,
  221. struct ath9k_channel *chan, int bin)
  222. {
  223. int cur_bin;
  224. int upper, lower, cur_vit_mask;
  225. int i;
  226. int8_t mask_m[123];
  227. int8_t mask_p[123];
  228. int8_t mask_amt;
  229. int tmp_mask;
  230. static const int pilot_mask_reg[4] = {
  231. AR_PHY_TIMING7, AR_PHY_TIMING8,
  232. AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
  233. };
  234. static const int chan_mask_reg[4] = {
  235. AR_PHY_TIMING9, AR_PHY_TIMING10,
  236. AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
  237. };
  238. static const int inc[4] = { 0, 100, 0, 0 };
  239. memset(&mask_m, 0, sizeof(int8_t) * 123);
  240. memset(&mask_p, 0, sizeof(int8_t) * 123);
  241. cur_bin = -6000;
  242. upper = bin + 100;
  243. lower = bin - 100;
  244. for (i = 0; i < 4; i++) {
  245. int pilot_mask = 0;
  246. int chan_mask = 0;
  247. int bp = 0;
  248. for (bp = 0; bp < 30; bp++) {
  249. if ((cur_bin > lower) && (cur_bin < upper)) {
  250. pilot_mask = pilot_mask | 0x1 << bp;
  251. chan_mask = chan_mask | 0x1 << bp;
  252. }
  253. cur_bin += 100;
  254. }
  255. cur_bin += inc[i];
  256. REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
  257. REG_WRITE(ah, chan_mask_reg[i], chan_mask);
  258. }
  259. cur_vit_mask = 6100;
  260. upper = bin + 120;
  261. lower = bin - 120;
  262. for (i = 0; i < 123; i++) {
  263. if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
  264. /* workaround for gcc bug #37014 */
  265. volatile int tmp_v = abs(cur_vit_mask - bin);
  266. if (tmp_v < 75)
  267. mask_amt = 1;
  268. else
  269. mask_amt = 0;
  270. if (cur_vit_mask < 0)
  271. mask_m[abs(cur_vit_mask / 100)] = mask_amt;
  272. else
  273. mask_p[cur_vit_mask / 100] = mask_amt;
  274. }
  275. cur_vit_mask -= 100;
  276. }
  277. tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
  278. | (mask_m[48] << 26) | (mask_m[49] << 24)
  279. | (mask_m[50] << 22) | (mask_m[51] << 20)
  280. | (mask_m[52] << 18) | (mask_m[53] << 16)
  281. | (mask_m[54] << 14) | (mask_m[55] << 12)
  282. | (mask_m[56] << 10) | (mask_m[57] << 8)
  283. | (mask_m[58] << 6) | (mask_m[59] << 4)
  284. | (mask_m[60] << 2) | (mask_m[61] << 0);
  285. REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
  286. REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
  287. tmp_mask = (mask_m[31] << 28)
  288. | (mask_m[32] << 26) | (mask_m[33] << 24)
  289. | (mask_m[34] << 22) | (mask_m[35] << 20)
  290. | (mask_m[36] << 18) | (mask_m[37] << 16)
  291. | (mask_m[48] << 14) | (mask_m[39] << 12)
  292. | (mask_m[40] << 10) | (mask_m[41] << 8)
  293. | (mask_m[42] << 6) | (mask_m[43] << 4)
  294. | (mask_m[44] << 2) | (mask_m[45] << 0);
  295. REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
  296. REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
  297. tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
  298. | (mask_m[18] << 26) | (mask_m[18] << 24)
  299. | (mask_m[20] << 22) | (mask_m[20] << 20)
  300. | (mask_m[22] << 18) | (mask_m[22] << 16)
  301. | (mask_m[24] << 14) | (mask_m[24] << 12)
  302. | (mask_m[25] << 10) | (mask_m[26] << 8)
  303. | (mask_m[27] << 6) | (mask_m[28] << 4)
  304. | (mask_m[29] << 2) | (mask_m[30] << 0);
  305. REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
  306. REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
  307. tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
  308. | (mask_m[2] << 26) | (mask_m[3] << 24)
  309. | (mask_m[4] << 22) | (mask_m[5] << 20)
  310. | (mask_m[6] << 18) | (mask_m[7] << 16)
  311. | (mask_m[8] << 14) | (mask_m[9] << 12)
  312. | (mask_m[10] << 10) | (mask_m[11] << 8)
  313. | (mask_m[12] << 6) | (mask_m[13] << 4)
  314. | (mask_m[14] << 2) | (mask_m[15] << 0);
  315. REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
  316. REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
  317. tmp_mask = (mask_p[15] << 28)
  318. | (mask_p[14] << 26) | (mask_p[13] << 24)
  319. | (mask_p[12] << 22) | (mask_p[11] << 20)
  320. | (mask_p[10] << 18) | (mask_p[9] << 16)
  321. | (mask_p[8] << 14) | (mask_p[7] << 12)
  322. | (mask_p[6] << 10) | (mask_p[5] << 8)
  323. | (mask_p[4] << 6) | (mask_p[3] << 4)
  324. | (mask_p[2] << 2) | (mask_p[1] << 0);
  325. REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
  326. REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
  327. tmp_mask = (mask_p[30] << 28)
  328. | (mask_p[29] << 26) | (mask_p[28] << 24)
  329. | (mask_p[27] << 22) | (mask_p[26] << 20)
  330. | (mask_p[25] << 18) | (mask_p[24] << 16)
  331. | (mask_p[23] << 14) | (mask_p[22] << 12)
  332. | (mask_p[21] << 10) | (mask_p[20] << 8)
  333. | (mask_p[19] << 6) | (mask_p[18] << 4)
  334. | (mask_p[17] << 2) | (mask_p[16] << 0);
  335. REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
  336. REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
  337. tmp_mask = (mask_p[45] << 28)
  338. | (mask_p[44] << 26) | (mask_p[43] << 24)
  339. | (mask_p[42] << 22) | (mask_p[41] << 20)
  340. | (mask_p[40] << 18) | (mask_p[39] << 16)
  341. | (mask_p[38] << 14) | (mask_p[37] << 12)
  342. | (mask_p[36] << 10) | (mask_p[35] << 8)
  343. | (mask_p[34] << 6) | (mask_p[33] << 4)
  344. | (mask_p[32] << 2) | (mask_p[31] << 0);
  345. REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
  346. REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
  347. tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
  348. | (mask_p[59] << 26) | (mask_p[58] << 24)
  349. | (mask_p[57] << 22) | (mask_p[56] << 20)
  350. | (mask_p[55] << 18) | (mask_p[54] << 16)
  351. | (mask_p[53] << 14) | (mask_p[52] << 12)
  352. | (mask_p[51] << 10) | (mask_p[50] << 8)
  353. | (mask_p[49] << 6) | (mask_p[48] << 4)
  354. | (mask_p[47] << 2) | (mask_p[46] << 0);
  355. REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
  356. REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
  357. }
  358. /**
  359. * ar5008_hw_spur_mitigate - convert baseband spur frequency for external radios
  360. * @ah: atheros hardware structure
  361. * @chan:
  362. *
  363. * For non single-chip solutions. Converts to baseband spur frequency given the
  364. * input channel frequency and compute register settings below.
  365. */
  366. static void ar5008_hw_spur_mitigate(struct ath_hw *ah,
  367. struct ath9k_channel *chan)
  368. {
  369. int bb_spur = AR_NO_SPUR;
  370. int bin;
  371. int spur_freq_sd;
  372. int spur_delta_phase;
  373. int denominator;
  374. int tmp, new;
  375. int i;
  376. int cur_bb_spur;
  377. bool is2GHz = IS_CHAN_2GHZ(chan);
  378. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  379. cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
  380. if (AR_NO_SPUR == cur_bb_spur)
  381. break;
  382. cur_bb_spur = cur_bb_spur - (chan->channel * 10);
  383. if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
  384. bb_spur = cur_bb_spur;
  385. break;
  386. }
  387. }
  388. if (AR_NO_SPUR == bb_spur)
  389. return;
  390. bin = bb_spur * 32;
  391. tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
  392. new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
  393. AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
  394. AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
  395. AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
  396. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
  397. new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
  398. AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
  399. AR_PHY_SPUR_REG_MASK_RATE_SELECT |
  400. AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
  401. SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
  402. REG_WRITE(ah, AR_PHY_SPUR_REG, new);
  403. spur_delta_phase = ((bb_spur * 524288) / 100) &
  404. AR_PHY_TIMING11_SPUR_DELTA_PHASE;
  405. denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
  406. spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
  407. new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
  408. SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
  409. SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
  410. REG_WRITE(ah, AR_PHY_TIMING11, new);
  411. ar5008_hw_cmn_spur_mitigate(ah, chan, bin);
  412. }
  413. /**
  414. * ar5008_hw_rf_alloc_ext_banks - allocates banks for external radio programming
  415. * @ah: atheros hardware structure
  416. *
  417. * Only required for older devices with external AR2133/AR5133 radios.
  418. */
  419. static int ar5008_hw_rf_alloc_ext_banks(struct ath_hw *ah)
  420. {
  421. int size = ah->iniBank6.ia_rows * sizeof(u32);
  422. if (AR_SREV_9280_20_OR_LATER(ah))
  423. return 0;
  424. ah->analogBank6Data = devm_kzalloc(ah->dev, size, GFP_KERNEL);
  425. if (!ah->analogBank6Data)
  426. return -ENOMEM;
  427. return 0;
  428. }
  429. /* *
  430. * ar5008_hw_set_rf_regs - programs rf registers based on EEPROM
  431. * @ah: atheros hardware structure
  432. * @chan:
  433. * @modesIndex:
  434. *
  435. * Used for the external AR2133/AR5133 radios.
  436. *
  437. * Reads the EEPROM header info from the device structure and programs
  438. * all rf registers. This routine requires access to the analog
  439. * rf device. This is not required for single-chip devices.
  440. */
  441. static bool ar5008_hw_set_rf_regs(struct ath_hw *ah,
  442. struct ath9k_channel *chan,
  443. u16 modesIndex)
  444. {
  445. u32 eepMinorRev;
  446. u32 ob5GHz = 0, db5GHz = 0;
  447. u32 ob2GHz = 0, db2GHz = 0;
  448. int regWrites = 0;
  449. int i;
  450. /*
  451. * Software does not need to program bank data
  452. * for single chip devices, that is AR9280 or anything
  453. * after that.
  454. */
  455. if (AR_SREV_9280_20_OR_LATER(ah))
  456. return true;
  457. /* Setup rf parameters */
  458. eepMinorRev = ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV);
  459. for (i = 0; i < ah->iniBank6.ia_rows; i++)
  460. ah->analogBank6Data[i] = INI_RA(&ah->iniBank6, i, modesIndex);
  461. /* Only the 5 or 2 GHz OB/DB need to be set for a mode */
  462. if (eepMinorRev >= 2) {
  463. if (IS_CHAN_2GHZ(chan)) {
  464. ob2GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_2);
  465. db2GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_2);
  466. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
  467. ob2GHz, 3, 197, 0);
  468. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
  469. db2GHz, 3, 194, 0);
  470. } else {
  471. ob5GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_5);
  472. db5GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_5);
  473. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
  474. ob5GHz, 3, 203, 0);
  475. ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
  476. db5GHz, 3, 200, 0);
  477. }
  478. }
  479. /* Write Analog registers */
  480. REG_WRITE_ARRAY(&bank0, 1, regWrites);
  481. REG_WRITE_ARRAY(&bank1, 1, regWrites);
  482. REG_WRITE_ARRAY(&bank2, 1, regWrites);
  483. REG_WRITE_ARRAY(&bank3, modesIndex, regWrites);
  484. ar5008_write_bank6(ah, &regWrites);
  485. REG_WRITE_ARRAY(&bank7, 1, regWrites);
  486. return true;
  487. }
  488. static void ar5008_hw_init_bb(struct ath_hw *ah,
  489. struct ath9k_channel *chan)
  490. {
  491. u32 synthDelay;
  492. synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  493. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
  494. ath9k_hw_synth_delay(ah, chan, synthDelay);
  495. }
  496. static void ar5008_hw_init_chain_masks(struct ath_hw *ah)
  497. {
  498. int rx_chainmask, tx_chainmask;
  499. rx_chainmask = ah->rxchainmask;
  500. tx_chainmask = ah->txchainmask;
  501. switch (rx_chainmask) {
  502. case 0x5:
  503. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  504. AR_PHY_SWAP_ALT_CHAIN);
  505. case 0x3:
  506. if (ah->hw_version.macVersion == AR_SREV_REVISION_5416_10) {
  507. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
  508. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
  509. break;
  510. }
  511. case 0x1:
  512. case 0x2:
  513. case 0x7:
  514. ENABLE_REGWRITE_BUFFER(ah);
  515. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
  516. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
  517. break;
  518. default:
  519. ENABLE_REGWRITE_BUFFER(ah);
  520. break;
  521. }
  522. REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
  523. REGWRITE_BUFFER_FLUSH(ah);
  524. if (tx_chainmask == 0x5) {
  525. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  526. AR_PHY_SWAP_ALT_CHAIN);
  527. }
  528. if (AR_SREV_9100(ah))
  529. REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
  530. REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
  531. }
  532. static void ar5008_hw_override_ini(struct ath_hw *ah,
  533. struct ath9k_channel *chan)
  534. {
  535. u32 val;
  536. /*
  537. * Set the RX_ABORT and RX_DIS and clear if off only after
  538. * RXE is set for MAC. This prevents frames with corrupted
  539. * descriptor status.
  540. */
  541. REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  542. if (AR_SREV_9280_20_OR_LATER(ah)) {
  543. /*
  544. * For AR9280 and above, there is a new feature that allows
  545. * Multicast search based on both MAC Address and Key ID.
  546. * By default, this feature is enabled. But since the driver
  547. * is not using this feature, we switch it off; otherwise
  548. * multicast search based on MAC addr only will fail.
  549. */
  550. val = REG_READ(ah, AR_PCU_MISC_MODE2) &
  551. (~AR_ADHOC_MCAST_KEYID_ENABLE);
  552. if (!AR_SREV_9271(ah))
  553. val &= ~AR_PCU_MISC_MODE2_HWWAR1;
  554. if (AR_SREV_9287_11_OR_LATER(ah))
  555. val = val & (~AR_PCU_MISC_MODE2_HWWAR2);
  556. val |= AR_PCU_MISC_MODE2_CFP_IGNORE;
  557. REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
  558. }
  559. if (AR_SREV_9280_20_OR_LATER(ah))
  560. return;
  561. /*
  562. * Disable BB clock gating
  563. * Necessary to avoid issues on AR5416 2.0
  564. */
  565. REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
  566. /*
  567. * Disable RIFS search on some chips to avoid baseband
  568. * hang issues.
  569. */
  570. if (AR_SREV_9100(ah) || AR_SREV_9160(ah)) {
  571. val = REG_READ(ah, AR_PHY_HEAVY_CLIP_FACTOR_RIFS);
  572. val &= ~AR_PHY_RIFS_INIT_DELAY;
  573. REG_WRITE(ah, AR_PHY_HEAVY_CLIP_FACTOR_RIFS, val);
  574. }
  575. }
  576. static void ar5008_hw_set_channel_regs(struct ath_hw *ah,
  577. struct ath9k_channel *chan)
  578. {
  579. u32 phymode;
  580. u32 enableDacFifo = 0;
  581. if (AR_SREV_9285_12_OR_LATER(ah))
  582. enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
  583. AR_PHY_FC_ENABLE_DAC_FIFO);
  584. phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
  585. | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
  586. if (IS_CHAN_HT40(chan)) {
  587. phymode |= AR_PHY_FC_DYN2040_EN;
  588. if (IS_CHAN_HT40PLUS(chan))
  589. phymode |= AR_PHY_FC_DYN2040_PRI_CH;
  590. }
  591. ENABLE_REGWRITE_BUFFER(ah);
  592. REG_WRITE(ah, AR_PHY_TURBO, phymode);
  593. /* This function do only REG_WRITE, so
  594. * we can include it to REGWRITE_BUFFER. */
  595. ath9k_hw_set11nmac2040(ah, chan);
  596. REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
  597. REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
  598. REGWRITE_BUFFER_FLUSH(ah);
  599. }
  600. static int ar5008_hw_process_ini(struct ath_hw *ah,
  601. struct ath9k_channel *chan)
  602. {
  603. struct ath_common *common = ath9k_hw_common(ah);
  604. int i, regWrites = 0;
  605. u32 modesIndex, freqIndex;
  606. if (IS_CHAN_5GHZ(chan)) {
  607. freqIndex = 1;
  608. modesIndex = IS_CHAN_HT40(chan) ? 2 : 1;
  609. } else {
  610. freqIndex = 2;
  611. modesIndex = IS_CHAN_HT40(chan) ? 3 : 4;
  612. }
  613. /*
  614. * Set correct baseband to analog shift setting to
  615. * access analog chips.
  616. */
  617. REG_WRITE(ah, AR_PHY(0), 0x00000007);
  618. /* Write ADDAC shifts */
  619. REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
  620. if (ah->eep_ops->set_addac)
  621. ah->eep_ops->set_addac(ah, chan);
  622. REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
  623. REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
  624. ENABLE_REGWRITE_BUFFER(ah);
  625. for (i = 0; i < ah->iniModes.ia_rows; i++) {
  626. u32 reg = INI_RA(&ah->iniModes, i, 0);
  627. u32 val = INI_RA(&ah->iniModes, i, modesIndex);
  628. if (reg == AR_AN_TOP2 && ah->need_an_top2_fixup)
  629. val &= ~AR_AN_TOP2_PWDCLKIND;
  630. REG_WRITE(ah, reg, val);
  631. if (reg >= 0x7800 && reg < 0x78a0
  632. && ah->config.analog_shiftreg
  633. && (common->bus_ops->ath_bus_type != ATH_USB)) {
  634. udelay(100);
  635. }
  636. DO_DELAY(regWrites);
  637. }
  638. REGWRITE_BUFFER_FLUSH(ah);
  639. if (AR_SREV_9280(ah) || AR_SREV_9287_11_OR_LATER(ah))
  640. REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
  641. if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) ||
  642. AR_SREV_9287_11_OR_LATER(ah))
  643. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  644. if (AR_SREV_9271_10(ah)) {
  645. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN, AR_PHY_SPECTRAL_SCAN_ENA);
  646. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_ADC_ON, 0xa);
  647. }
  648. ENABLE_REGWRITE_BUFFER(ah);
  649. /* Write common array parameters */
  650. for (i = 0; i < ah->iniCommon.ia_rows; i++) {
  651. u32 reg = INI_RA(&ah->iniCommon, i, 0);
  652. u32 val = INI_RA(&ah->iniCommon, i, 1);
  653. REG_WRITE(ah, reg, val);
  654. if (reg >= 0x7800 && reg < 0x78a0
  655. && ah->config.analog_shiftreg
  656. && (common->bus_ops->ath_bus_type != ATH_USB)) {
  657. udelay(100);
  658. }
  659. DO_DELAY(regWrites);
  660. }
  661. REGWRITE_BUFFER_FLUSH(ah);
  662. REG_WRITE_ARRAY(&ah->iniBB_RfGain, freqIndex, regWrites);
  663. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  664. REG_WRITE_ARRAY(&ah->iniModesFastClock, modesIndex,
  665. regWrites);
  666. ar5008_hw_override_ini(ah, chan);
  667. ar5008_hw_set_channel_regs(ah, chan);
  668. ar5008_hw_init_chain_masks(ah);
  669. ath9k_olc_init(ah);
  670. ath9k_hw_apply_txpower(ah, chan, false);
  671. /* Write analog registers */
  672. if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
  673. ath_err(ath9k_hw_common(ah), "ar5416SetRfRegs failed\n");
  674. return -EIO;
  675. }
  676. return 0;
  677. }
  678. static void ar5008_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
  679. {
  680. u32 rfMode = 0;
  681. if (chan == NULL)
  682. return;
  683. if (IS_CHAN_2GHZ(chan))
  684. rfMode |= AR_PHY_MODE_DYNAMIC;
  685. else
  686. rfMode |= AR_PHY_MODE_OFDM;
  687. if (!AR_SREV_9280_20_OR_LATER(ah))
  688. rfMode |= (IS_CHAN_5GHZ(chan)) ?
  689. AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
  690. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  691. rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
  692. REG_WRITE(ah, AR_PHY_MODE, rfMode);
  693. }
  694. static void ar5008_hw_mark_phy_inactive(struct ath_hw *ah)
  695. {
  696. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
  697. }
  698. static void ar5008_hw_set_delta_slope(struct ath_hw *ah,
  699. struct ath9k_channel *chan)
  700. {
  701. u32 coef_scaled, ds_coef_exp, ds_coef_man;
  702. u32 clockMhzScaled = 0x64000000;
  703. struct chan_centers centers;
  704. if (IS_CHAN_HALF_RATE(chan))
  705. clockMhzScaled = clockMhzScaled >> 1;
  706. else if (IS_CHAN_QUARTER_RATE(chan))
  707. clockMhzScaled = clockMhzScaled >> 2;
  708. ath9k_hw_get_channel_centers(ah, chan, &centers);
  709. coef_scaled = clockMhzScaled / centers.synth_center;
  710. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  711. &ds_coef_exp);
  712. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  713. AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
  714. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  715. AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
  716. coef_scaled = (9 * coef_scaled) / 10;
  717. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  718. &ds_coef_exp);
  719. REG_RMW_FIELD(ah, AR_PHY_HALFGI,
  720. AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
  721. REG_RMW_FIELD(ah, AR_PHY_HALFGI,
  722. AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
  723. }
  724. static bool ar5008_hw_rfbus_req(struct ath_hw *ah)
  725. {
  726. REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
  727. return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
  728. AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT);
  729. }
  730. static void ar5008_hw_rfbus_done(struct ath_hw *ah)
  731. {
  732. u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  733. ath9k_hw_synth_delay(ah, ah->curchan, synthDelay);
  734. REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
  735. }
  736. static void ar5008_restore_chainmask(struct ath_hw *ah)
  737. {
  738. int rx_chainmask = ah->rxchainmask;
  739. if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
  740. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
  741. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
  742. }
  743. }
  744. static u32 ar9160_hw_compute_pll_control(struct ath_hw *ah,
  745. struct ath9k_channel *chan)
  746. {
  747. u32 pll;
  748. pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
  749. if (chan && IS_CHAN_HALF_RATE(chan))
  750. pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
  751. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  752. pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
  753. if (chan && IS_CHAN_5GHZ(chan))
  754. pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
  755. else
  756. pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
  757. return pll;
  758. }
  759. static u32 ar5008_hw_compute_pll_control(struct ath_hw *ah,
  760. struct ath9k_channel *chan)
  761. {
  762. u32 pll;
  763. pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
  764. if (chan && IS_CHAN_HALF_RATE(chan))
  765. pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
  766. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  767. pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
  768. if (chan && IS_CHAN_5GHZ(chan))
  769. pll |= SM(0xa, AR_RTC_PLL_DIV);
  770. else
  771. pll |= SM(0xb, AR_RTC_PLL_DIV);
  772. return pll;
  773. }
  774. static bool ar5008_hw_ani_control_new(struct ath_hw *ah,
  775. enum ath9k_ani_cmd cmd,
  776. int param)
  777. {
  778. struct ath_common *common = ath9k_hw_common(ah);
  779. struct ath9k_channel *chan = ah->curchan;
  780. struct ar5416AniState *aniState = &ah->ani;
  781. s32 value;
  782. switch (cmd & ah->ani_function) {
  783. case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
  784. /*
  785. * on == 1 means ofdm weak signal detection is ON
  786. * on == 1 is the default, for less noise immunity
  787. *
  788. * on == 0 means ofdm weak signal detection is OFF
  789. * on == 0 means more noise imm
  790. */
  791. u32 on = param ? 1 : 0;
  792. /*
  793. * make register setting for default
  794. * (weak sig detect ON) come from INI file
  795. */
  796. int m1ThreshLow = on ?
  797. aniState->iniDef.m1ThreshLow : m1ThreshLow_off;
  798. int m2ThreshLow = on ?
  799. aniState->iniDef.m2ThreshLow : m2ThreshLow_off;
  800. int m1Thresh = on ?
  801. aniState->iniDef.m1Thresh : m1Thresh_off;
  802. int m2Thresh = on ?
  803. aniState->iniDef.m2Thresh : m2Thresh_off;
  804. int m2CountThr = on ?
  805. aniState->iniDef.m2CountThr : m2CountThr_off;
  806. int m2CountThrLow = on ?
  807. aniState->iniDef.m2CountThrLow : m2CountThrLow_off;
  808. int m1ThreshLowExt = on ?
  809. aniState->iniDef.m1ThreshLowExt : m1ThreshLowExt_off;
  810. int m2ThreshLowExt = on ?
  811. aniState->iniDef.m2ThreshLowExt : m2ThreshLowExt_off;
  812. int m1ThreshExt = on ?
  813. aniState->iniDef.m1ThreshExt : m1ThreshExt_off;
  814. int m2ThreshExt = on ?
  815. aniState->iniDef.m2ThreshExt : m2ThreshExt_off;
  816. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  817. AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
  818. m1ThreshLow);
  819. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  820. AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
  821. m2ThreshLow);
  822. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  823. AR_PHY_SFCORR_M1_THRESH, m1Thresh);
  824. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  825. AR_PHY_SFCORR_M2_THRESH, m2Thresh);
  826. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  827. AR_PHY_SFCORR_M2COUNT_THR, m2CountThr);
  828. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  829. AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
  830. m2CountThrLow);
  831. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  832. AR_PHY_SFCORR_EXT_M1_THRESH_LOW, m1ThreshLowExt);
  833. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  834. AR_PHY_SFCORR_EXT_M2_THRESH_LOW, m2ThreshLowExt);
  835. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  836. AR_PHY_SFCORR_EXT_M1_THRESH, m1ThreshExt);
  837. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  838. AR_PHY_SFCORR_EXT_M2_THRESH, m2ThreshExt);
  839. if (on)
  840. REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
  841. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  842. else
  843. REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
  844. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  845. if (on != aniState->ofdmWeakSigDetect) {
  846. ath_dbg(common, ANI,
  847. "** ch %d: ofdm weak signal: %s=>%s\n",
  848. chan->channel,
  849. aniState->ofdmWeakSigDetect ?
  850. "on" : "off",
  851. on ? "on" : "off");
  852. if (on)
  853. ah->stats.ast_ani_ofdmon++;
  854. else
  855. ah->stats.ast_ani_ofdmoff++;
  856. aniState->ofdmWeakSigDetect = on;
  857. }
  858. break;
  859. }
  860. case ATH9K_ANI_FIRSTEP_LEVEL:{
  861. u32 level = param;
  862. value = level * 2;
  863. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  864. AR_PHY_FIND_SIG_FIRSTEP, value);
  865. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
  866. AR_PHY_FIND_SIG_FIRSTEP_LOW, value);
  867. if (level != aniState->firstepLevel) {
  868. ath_dbg(common, ANI,
  869. "** ch %d: level %d=>%d[def:%d] firstep[level]=%d ini=%d\n",
  870. chan->channel,
  871. aniState->firstepLevel,
  872. level,
  873. ATH9K_ANI_FIRSTEP_LVL,
  874. value,
  875. aniState->iniDef.firstep);
  876. ath_dbg(common, ANI,
  877. "** ch %d: level %d=>%d[def:%d] firstep_low[level]=%d ini=%d\n",
  878. chan->channel,
  879. aniState->firstepLevel,
  880. level,
  881. ATH9K_ANI_FIRSTEP_LVL,
  882. value,
  883. aniState->iniDef.firstepLow);
  884. if (level > aniState->firstepLevel)
  885. ah->stats.ast_ani_stepup++;
  886. else if (level < aniState->firstepLevel)
  887. ah->stats.ast_ani_stepdown++;
  888. aniState->firstepLevel = level;
  889. }
  890. break;
  891. }
  892. case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
  893. u32 level = param;
  894. value = (level + 1) * 2;
  895. REG_RMW_FIELD(ah, AR_PHY_TIMING5,
  896. AR_PHY_TIMING5_CYCPWR_THR1, value);
  897. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
  898. AR_PHY_EXT_TIMING5_CYCPWR_THR1, value - 1);
  899. if (level != aniState->spurImmunityLevel) {
  900. ath_dbg(common, ANI,
  901. "** ch %d: level %d=>%d[def:%d] cycpwrThr1[level]=%d ini=%d\n",
  902. chan->channel,
  903. aniState->spurImmunityLevel,
  904. level,
  905. ATH9K_ANI_SPUR_IMMUNE_LVL,
  906. value,
  907. aniState->iniDef.cycpwrThr1);
  908. ath_dbg(common, ANI,
  909. "** ch %d: level %d=>%d[def:%d] cycpwrThr1Ext[level]=%d ini=%d\n",
  910. chan->channel,
  911. aniState->spurImmunityLevel,
  912. level,
  913. ATH9K_ANI_SPUR_IMMUNE_LVL,
  914. value,
  915. aniState->iniDef.cycpwrThr1Ext);
  916. if (level > aniState->spurImmunityLevel)
  917. ah->stats.ast_ani_spurup++;
  918. else if (level < aniState->spurImmunityLevel)
  919. ah->stats.ast_ani_spurdown++;
  920. aniState->spurImmunityLevel = level;
  921. }
  922. break;
  923. }
  924. case ATH9K_ANI_MRC_CCK:
  925. /*
  926. * You should not see this as AR5008, AR9001, AR9002
  927. * does not have hardware support for MRC CCK.
  928. */
  929. WARN_ON(1);
  930. break;
  931. default:
  932. ath_dbg(common, ANI, "invalid cmd %u\n", cmd);
  933. return false;
  934. }
  935. ath_dbg(common, ANI,
  936. "ANI parameters: SI=%d, ofdmWS=%s FS=%d MRCcck=%s listenTime=%d ofdmErrs=%d cckErrs=%d\n",
  937. aniState->spurImmunityLevel,
  938. aniState->ofdmWeakSigDetect ? "on" : "off",
  939. aniState->firstepLevel,
  940. aniState->mrcCCK ? "on" : "off",
  941. aniState->listenTime,
  942. aniState->ofdmPhyErrCount,
  943. aniState->cckPhyErrCount);
  944. return true;
  945. }
  946. static void ar5008_hw_do_getnf(struct ath_hw *ah,
  947. int16_t nfarray[NUM_NF_READINGS])
  948. {
  949. int16_t nf;
  950. nf = MS(REG_READ(ah, AR_PHY_CCA), AR_PHY_MINCCA_PWR);
  951. nfarray[0] = sign_extend32(nf, 8);
  952. nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), AR_PHY_CH1_MINCCA_PWR);
  953. nfarray[1] = sign_extend32(nf, 8);
  954. nf = MS(REG_READ(ah, AR_PHY_CH2_CCA), AR_PHY_CH2_MINCCA_PWR);
  955. nfarray[2] = sign_extend32(nf, 8);
  956. if (!IS_CHAN_HT40(ah->curchan))
  957. return;
  958. nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR);
  959. nfarray[3] = sign_extend32(nf, 8);
  960. nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA), AR_PHY_CH1_EXT_MINCCA_PWR);
  961. nfarray[4] = sign_extend32(nf, 8);
  962. nf = MS(REG_READ(ah, AR_PHY_CH2_EXT_CCA), AR_PHY_CH2_EXT_MINCCA_PWR);
  963. nfarray[5] = sign_extend32(nf, 8);
  964. }
  965. /*
  966. * Initialize the ANI register values with default (ini) values.
  967. * This routine is called during a (full) hardware reset after
  968. * all the registers are initialised from the INI.
  969. */
  970. static void ar5008_hw_ani_cache_ini_regs(struct ath_hw *ah)
  971. {
  972. struct ath_common *common = ath9k_hw_common(ah);
  973. struct ath9k_channel *chan = ah->curchan;
  974. struct ar5416AniState *aniState = &ah->ani;
  975. struct ath9k_ani_default *iniDef;
  976. u32 val;
  977. iniDef = &aniState->iniDef;
  978. ath_dbg(common, ANI, "ver %d.%d opmode %u chan %d Mhz\n",
  979. ah->hw_version.macVersion,
  980. ah->hw_version.macRev,
  981. ah->opmode,
  982. chan->channel);
  983. val = REG_READ(ah, AR_PHY_SFCORR);
  984. iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH);
  985. iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH);
  986. iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR);
  987. val = REG_READ(ah, AR_PHY_SFCORR_LOW);
  988. iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW);
  989. iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW);
  990. iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW);
  991. val = REG_READ(ah, AR_PHY_SFCORR_EXT);
  992. iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH);
  993. iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH);
  994. iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW);
  995. iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW);
  996. iniDef->firstep = REG_READ_FIELD(ah,
  997. AR_PHY_FIND_SIG,
  998. AR_PHY_FIND_SIG_FIRSTEP);
  999. iniDef->firstepLow = REG_READ_FIELD(ah,
  1000. AR_PHY_FIND_SIG_LOW,
  1001. AR_PHY_FIND_SIG_FIRSTEP_LOW);
  1002. iniDef->cycpwrThr1 = REG_READ_FIELD(ah,
  1003. AR_PHY_TIMING5,
  1004. AR_PHY_TIMING5_CYCPWR_THR1);
  1005. iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah,
  1006. AR_PHY_EXT_CCA,
  1007. AR_PHY_EXT_TIMING5_CYCPWR_THR1);
  1008. /* these levels just got reset to defaults by the INI */
  1009. aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL;
  1010. aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL;
  1011. aniState->ofdmWeakSigDetect = true;
  1012. aniState->mrcCCK = false; /* not available on pre AR9003 */
  1013. }
  1014. static void ar5008_hw_set_nf_limits(struct ath_hw *ah)
  1015. {
  1016. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_5416_2GHZ;
  1017. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_5416_2GHZ;
  1018. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_5416_2GHZ;
  1019. ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_5416_5GHZ;
  1020. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_5416_5GHZ;
  1021. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_5416_5GHZ;
  1022. }
  1023. static void ar5008_hw_set_radar_params(struct ath_hw *ah,
  1024. struct ath_hw_radar_conf *conf)
  1025. {
  1026. u32 radar_0 = 0, radar_1;
  1027. if (!conf) {
  1028. REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA);
  1029. return;
  1030. }
  1031. radar_0 |= AR_PHY_RADAR_0_ENA | AR_PHY_RADAR_0_FFT_ENA;
  1032. radar_0 |= SM(conf->fir_power, AR_PHY_RADAR_0_FIRPWR);
  1033. radar_0 |= SM(conf->radar_rssi, AR_PHY_RADAR_0_RRSSI);
  1034. radar_0 |= SM(conf->pulse_height, AR_PHY_RADAR_0_HEIGHT);
  1035. radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI);
  1036. radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND);
  1037. radar_1 = REG_READ(ah, AR_PHY_RADAR_1);
  1038. radar_1 &= ~(AR_PHY_RADAR_1_MAXLEN | AR_PHY_RADAR_1_RELSTEP_THRESH |
  1039. AR_PHY_RADAR_1_RELPWR_THRESH);
  1040. radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI;
  1041. radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK;
  1042. radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN);
  1043. radar_1 |= SM(conf->pulse_inband_step, AR_PHY_RADAR_1_RELSTEP_THRESH);
  1044. radar_1 |= SM(conf->radar_inband, AR_PHY_RADAR_1_RELPWR_THRESH);
  1045. REG_WRITE(ah, AR_PHY_RADAR_0, radar_0);
  1046. REG_WRITE(ah, AR_PHY_RADAR_1, radar_1);
  1047. if (conf->ext_channel)
  1048. REG_SET_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1049. else
  1050. REG_CLR_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1051. }
  1052. static void ar5008_hw_set_radar_conf(struct ath_hw *ah)
  1053. {
  1054. struct ath_hw_radar_conf *conf = &ah->radar_conf;
  1055. conf->fir_power = -33;
  1056. conf->radar_rssi = 20;
  1057. conf->pulse_height = 10;
  1058. conf->pulse_rssi = 15;
  1059. conf->pulse_inband = 15;
  1060. conf->pulse_maxlen = 255;
  1061. conf->pulse_inband_step = 12;
  1062. conf->radar_inband = 8;
  1063. }
  1064. static void ar5008_hw_init_txpower_cck(struct ath_hw *ah, int16_t *rate_array)
  1065. {
  1066. #define CCK_DELTA(x) ((OLC_FOR_AR9280_20_LATER) ? max((x) - 2, 0) : (x))
  1067. ah->tx_power[0] = CCK_DELTA(rate_array[rate1l]);
  1068. ah->tx_power[1] = CCK_DELTA(min(rate_array[rate2l],
  1069. rate_array[rate2s]));
  1070. ah->tx_power[2] = CCK_DELTA(min(rate_array[rate5_5l],
  1071. rate_array[rate5_5s]));
  1072. ah->tx_power[3] = CCK_DELTA(min(rate_array[rate11l],
  1073. rate_array[rate11s]));
  1074. #undef CCK_DELTA
  1075. }
  1076. static void ar5008_hw_init_txpower_ofdm(struct ath_hw *ah, int16_t *rate_array,
  1077. int offset)
  1078. {
  1079. int i, idx = 0;
  1080. for (i = offset; i < offset + AR5008_OFDM_RATES; i++) {
  1081. ah->tx_power[i] = rate_array[idx];
  1082. idx++;
  1083. }
  1084. }
  1085. static void ar5008_hw_init_txpower_ht(struct ath_hw *ah, int16_t *rate_array,
  1086. int ss_offset, int ds_offset,
  1087. bool is_40, int ht40_delta)
  1088. {
  1089. int i, mcs_idx = (is_40) ? AR5008_HT40_SHIFT : AR5008_HT20_SHIFT;
  1090. for (i = ss_offset; i < ss_offset + AR5008_HT_SS_RATES; i++) {
  1091. ah->tx_power[i] = rate_array[mcs_idx] + ht40_delta;
  1092. mcs_idx++;
  1093. }
  1094. memcpy(&ah->tx_power[ds_offset], &ah->tx_power[ss_offset],
  1095. AR5008_HT_SS_RATES);
  1096. }
  1097. void ar5008_hw_init_rate_txpower(struct ath_hw *ah, int16_t *rate_array,
  1098. struct ath9k_channel *chan, int ht40_delta)
  1099. {
  1100. if (IS_CHAN_5GHZ(chan)) {
  1101. ar5008_hw_init_txpower_ofdm(ah, rate_array,
  1102. AR5008_11NA_OFDM_SHIFT);
  1103. if (IS_CHAN_HT20(chan) || IS_CHAN_HT40(chan)) {
  1104. ar5008_hw_init_txpower_ht(ah, rate_array,
  1105. AR5008_11NA_HT_SS_SHIFT,
  1106. AR5008_11NA_HT_DS_SHIFT,
  1107. IS_CHAN_HT40(chan),
  1108. ht40_delta);
  1109. }
  1110. } else {
  1111. ar5008_hw_init_txpower_cck(ah, rate_array);
  1112. ar5008_hw_init_txpower_ofdm(ah, rate_array,
  1113. AR5008_11NG_OFDM_SHIFT);
  1114. if (IS_CHAN_HT20(chan) || IS_CHAN_HT40(chan)) {
  1115. ar5008_hw_init_txpower_ht(ah, rate_array,
  1116. AR5008_11NG_HT_SS_SHIFT,
  1117. AR5008_11NG_HT_DS_SHIFT,
  1118. IS_CHAN_HT40(chan),
  1119. ht40_delta);
  1120. }
  1121. }
  1122. }
  1123. int ar5008_hw_attach_phy_ops(struct ath_hw *ah)
  1124. {
  1125. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  1126. static const u32 ar5416_cca_regs[6] = {
  1127. AR_PHY_CCA,
  1128. AR_PHY_CH1_CCA,
  1129. AR_PHY_CH2_CCA,
  1130. AR_PHY_EXT_CCA,
  1131. AR_PHY_CH1_EXT_CCA,
  1132. AR_PHY_CH2_EXT_CCA
  1133. };
  1134. int ret;
  1135. ret = ar5008_hw_rf_alloc_ext_banks(ah);
  1136. if (ret)
  1137. return ret;
  1138. priv_ops->rf_set_freq = ar5008_hw_set_channel;
  1139. priv_ops->spur_mitigate_freq = ar5008_hw_spur_mitigate;
  1140. priv_ops->set_rf_regs = ar5008_hw_set_rf_regs;
  1141. priv_ops->set_channel_regs = ar5008_hw_set_channel_regs;
  1142. priv_ops->init_bb = ar5008_hw_init_bb;
  1143. priv_ops->process_ini = ar5008_hw_process_ini;
  1144. priv_ops->set_rfmode = ar5008_hw_set_rfmode;
  1145. priv_ops->mark_phy_inactive = ar5008_hw_mark_phy_inactive;
  1146. priv_ops->set_delta_slope = ar5008_hw_set_delta_slope;
  1147. priv_ops->rfbus_req = ar5008_hw_rfbus_req;
  1148. priv_ops->rfbus_done = ar5008_hw_rfbus_done;
  1149. priv_ops->restore_chainmask = ar5008_restore_chainmask;
  1150. priv_ops->do_getnf = ar5008_hw_do_getnf;
  1151. priv_ops->set_radar_params = ar5008_hw_set_radar_params;
  1152. priv_ops->ani_control = ar5008_hw_ani_control_new;
  1153. priv_ops->ani_cache_ini_regs = ar5008_hw_ani_cache_ini_regs;
  1154. if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah))
  1155. priv_ops->compute_pll_control = ar9160_hw_compute_pll_control;
  1156. else
  1157. priv_ops->compute_pll_control = ar5008_hw_compute_pll_control;
  1158. ar5008_hw_set_nf_limits(ah);
  1159. ar5008_hw_set_radar_conf(ah);
  1160. memcpy(ah->nf_regs, ar5416_cca_regs, sizeof(ah->nf_regs));
  1161. return 0;
  1162. }