ar5008_phy.c 44 KB

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