ar9003_phy.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613
  1. /*
  2. * Copyright (c) 2010-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 <linux/export.h>
  17. #include "hw.h"
  18. #include "ar9003_phy.h"
  19. static const int firstep_table[] =
  20. /* level: 0 1 2 3 4 5 6 7 8 */
  21. { -4, -2, 0, 2, 4, 6, 8, 10, 12 }; /* lvl 0-8, default 2 */
  22. static const int cycpwrThr1_table[] =
  23. /* level: 0 1 2 3 4 5 6 7 8 */
  24. { -6, -4, -2, 0, 2, 4, 6, 8 }; /* lvl 0-7, default 3 */
  25. /*
  26. * register values to turn OFDM weak signal detection OFF
  27. */
  28. static const int m1ThreshLow_off = 127;
  29. static const int m2ThreshLow_off = 127;
  30. static const int m1Thresh_off = 127;
  31. static const int m2Thresh_off = 127;
  32. static const int m2CountThr_off = 31;
  33. static const int m2CountThrLow_off = 63;
  34. static const int m1ThreshLowExt_off = 127;
  35. static const int m2ThreshLowExt_off = 127;
  36. static const int m1ThreshExt_off = 127;
  37. static const int m2ThreshExt_off = 127;
  38. /**
  39. * ar9003_hw_set_channel - set channel on single-chip device
  40. * @ah: atheros hardware structure
  41. * @chan:
  42. *
  43. * This is the function to change channel on single-chip devices, that is
  44. * for AR9300 family of chipsets.
  45. *
  46. * This function takes the channel value in MHz and sets
  47. * hardware channel value. Assumes writes have been enabled to analog bus.
  48. *
  49. * Actual Expression,
  50. *
  51. * For 2GHz channel,
  52. * Channel Frequency = (3/4) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
  53. * (freq_ref = 40MHz)
  54. *
  55. * For 5GHz channel,
  56. * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^10)
  57. * (freq_ref = 40MHz/(24>>amodeRefSel))
  58. *
  59. * For 5GHz channels which are 5MHz spaced,
  60. * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
  61. * (freq_ref = 40MHz)
  62. */
  63. static int ar9003_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
  64. {
  65. u16 bMode, fracMode = 0, aModeRefSel = 0;
  66. u32 freq, channelSel = 0, reg32 = 0;
  67. struct chan_centers centers;
  68. int loadSynthChannel;
  69. ath9k_hw_get_channel_centers(ah, chan, &centers);
  70. freq = centers.synth_center;
  71. if (freq < 4800) { /* 2 GHz, fractional mode */
  72. if (AR_SREV_9330(ah)) {
  73. u32 chan_frac;
  74. u32 div;
  75. if (ah->is_clk_25mhz)
  76. div = 75;
  77. else
  78. div = 120;
  79. channelSel = (freq * 4) / div;
  80. chan_frac = (((freq * 4) % div) * 0x20000) / div;
  81. channelSel = (channelSel << 17) | chan_frac;
  82. } else if (AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
  83. u32 chan_frac;
  84. /*
  85. * freq_ref = 40 / (refdiva >> amoderefsel); where refdiva=1 and amoderefsel=0
  86. * ndiv = ((chan_mhz * 4) / 3) / freq_ref;
  87. * chansel = int(ndiv), chanfrac = (ndiv - chansel) * 0x20000
  88. */
  89. channelSel = (freq * 4) / 120;
  90. chan_frac = (((freq * 4) % 120) * 0x20000) / 120;
  91. channelSel = (channelSel << 17) | chan_frac;
  92. } else if (AR_SREV_9340(ah) || AR_SREV_9550(ah)) {
  93. if (ah->is_clk_25mhz) {
  94. u32 chan_frac;
  95. channelSel = (freq * 2) / 75;
  96. chan_frac = (((freq * 2) % 75) * 0x20000) / 75;
  97. channelSel = (channelSel << 17) | chan_frac;
  98. } else
  99. channelSel = CHANSEL_2G(freq) >> 1;
  100. } else
  101. channelSel = CHANSEL_2G(freq);
  102. /* Set to 2G mode */
  103. bMode = 1;
  104. } else {
  105. if ((AR_SREV_9340(ah) || AR_SREV_9550(ah)) &&
  106. ah->is_clk_25mhz) {
  107. u32 chan_frac;
  108. channelSel = freq / 75;
  109. chan_frac = ((freq % 75) * 0x20000) / 75;
  110. channelSel = (channelSel << 17) | chan_frac;
  111. } else {
  112. channelSel = CHANSEL_5G(freq);
  113. /* Doubler is ON, so, divide channelSel by 2. */
  114. channelSel >>= 1;
  115. }
  116. /* Set to 5G mode */
  117. bMode = 0;
  118. }
  119. /* Enable fractional mode for all channels */
  120. fracMode = 1;
  121. aModeRefSel = 0;
  122. loadSynthChannel = 0;
  123. reg32 = (bMode << 29);
  124. REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
  125. /* Enable Long shift Select for Synthesizer */
  126. REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_SYNTH4,
  127. AR_PHY_SYNTH4_LONG_SHIFT_SELECT, 1);
  128. /* Program Synth. setting */
  129. reg32 = (channelSel << 2) | (fracMode << 30) |
  130. (aModeRefSel << 28) | (loadSynthChannel << 31);
  131. REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
  132. /* Toggle Load Synth channel bit */
  133. loadSynthChannel = 1;
  134. reg32 = (channelSel << 2) | (fracMode << 30) |
  135. (aModeRefSel << 28) | (loadSynthChannel << 31);
  136. REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
  137. ah->curchan = chan;
  138. return 0;
  139. }
  140. /**
  141. * ar9003_hw_spur_mitigate_mrc_cck - convert baseband spur frequency
  142. * @ah: atheros hardware structure
  143. * @chan:
  144. *
  145. * For single-chip solutions. Converts to baseband spur frequency given the
  146. * input channel frequency and compute register settings below.
  147. *
  148. * Spur mitigation for MRC CCK
  149. */
  150. static void ar9003_hw_spur_mitigate_mrc_cck(struct ath_hw *ah,
  151. struct ath9k_channel *chan)
  152. {
  153. static const u32 spur_freq[4] = { 2420, 2440, 2464, 2480 };
  154. int cur_bb_spur, negative = 0, cck_spur_freq;
  155. int i;
  156. int range, max_spur_cnts, synth_freq;
  157. u8 *spur_fbin_ptr = ar9003_get_spur_chan_ptr(ah, IS_CHAN_2GHZ(chan));
  158. /*
  159. * Need to verify range +/- 10 MHz in control channel, otherwise spur
  160. * is out-of-band and can be ignored.
  161. */
  162. if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah) ||
  163. AR_SREV_9550(ah)) {
  164. if (spur_fbin_ptr[0] == 0) /* No spur */
  165. return;
  166. max_spur_cnts = 5;
  167. if (IS_CHAN_HT40(chan)) {
  168. range = 19;
  169. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  170. AR_PHY_GC_DYN2040_PRI_CH) == 0)
  171. synth_freq = chan->channel + 10;
  172. else
  173. synth_freq = chan->channel - 10;
  174. } else {
  175. range = 10;
  176. synth_freq = chan->channel;
  177. }
  178. } else {
  179. range = AR_SREV_9462(ah) ? 5 : 10;
  180. max_spur_cnts = 4;
  181. synth_freq = chan->channel;
  182. }
  183. for (i = 0; i < max_spur_cnts; i++) {
  184. if (AR_SREV_9462(ah) && (i == 0 || i == 3))
  185. continue;
  186. negative = 0;
  187. if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah) ||
  188. AR_SREV_9550(ah))
  189. cur_bb_spur = ath9k_hw_fbin2freq(spur_fbin_ptr[i],
  190. IS_CHAN_2GHZ(chan));
  191. else
  192. cur_bb_spur = spur_freq[i];
  193. cur_bb_spur -= synth_freq;
  194. if (cur_bb_spur < 0) {
  195. negative = 1;
  196. cur_bb_spur = -cur_bb_spur;
  197. }
  198. if (cur_bb_spur < range) {
  199. cck_spur_freq = (int)((cur_bb_spur << 19) / 11);
  200. if (negative == 1)
  201. cck_spur_freq = -cck_spur_freq;
  202. cck_spur_freq = cck_spur_freq & 0xfffff;
  203. REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
  204. AR_PHY_AGC_CONTROL_YCOK_MAX, 0x7);
  205. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  206. AR_PHY_CCK_SPUR_MIT_SPUR_RSSI_THR, 0x7f);
  207. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  208. AR_PHY_CCK_SPUR_MIT_SPUR_FILTER_TYPE,
  209. 0x2);
  210. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  211. AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT,
  212. 0x1);
  213. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  214. AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ,
  215. cck_spur_freq);
  216. return;
  217. }
  218. }
  219. REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
  220. AR_PHY_AGC_CONTROL_YCOK_MAX, 0x5);
  221. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  222. AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT, 0x0);
  223. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  224. AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ, 0x0);
  225. }
  226. /* Clean all spur register fields */
  227. static void ar9003_hw_spur_ofdm_clear(struct ath_hw *ah)
  228. {
  229. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  230. AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0);
  231. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  232. AR_PHY_TIMING11_SPUR_FREQ_SD, 0);
  233. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  234. AR_PHY_TIMING11_SPUR_DELTA_PHASE, 0);
  235. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  236. AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, 0);
  237. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  238. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0);
  239. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  240. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0);
  241. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  242. AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0);
  243. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  244. AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 0);
  245. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  246. AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 0);
  247. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  248. AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0);
  249. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  250. AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0);
  251. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  252. AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0);
  253. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  254. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, 0);
  255. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  256. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, 0);
  257. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  258. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, 0);
  259. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  260. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0);
  261. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  262. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0);
  263. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  264. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0);
  265. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  266. AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0);
  267. }
  268. static void ar9003_hw_spur_ofdm(struct ath_hw *ah,
  269. int freq_offset,
  270. int spur_freq_sd,
  271. int spur_delta_phase,
  272. int spur_subchannel_sd,
  273. int range,
  274. int synth_freq)
  275. {
  276. int mask_index = 0;
  277. /* OFDM Spur mitigation */
  278. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  279. AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0x1);
  280. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  281. AR_PHY_TIMING11_SPUR_FREQ_SD, spur_freq_sd);
  282. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  283. AR_PHY_TIMING11_SPUR_DELTA_PHASE, spur_delta_phase);
  284. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  285. AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, spur_subchannel_sd);
  286. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  287. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0x1);
  288. if (!(AR_SREV_9565(ah) && range == 10 && synth_freq == 2437))
  289. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  290. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0x1);
  291. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  292. AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0x1);
  293. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  294. AR_PHY_SPUR_REG_SPUR_RSSI_THRESH, 34);
  295. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  296. AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 1);
  297. if (REG_READ_FIELD(ah, AR_PHY_MODE,
  298. AR_PHY_MODE_DYNAMIC) == 0x1)
  299. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  300. AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 1);
  301. mask_index = (freq_offset << 4) / 5;
  302. if (mask_index < 0)
  303. mask_index = mask_index - 1;
  304. mask_index = mask_index & 0x7f;
  305. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  306. AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0x1);
  307. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  308. AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0x1);
  309. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  310. AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0x1);
  311. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  312. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, mask_index);
  313. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  314. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, mask_index);
  315. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  316. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, mask_index);
  317. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  318. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0xc);
  319. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  320. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0xc);
  321. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  322. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0xa0);
  323. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  324. AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0xff);
  325. }
  326. static void ar9003_hw_spur_ofdm_9565(struct ath_hw *ah,
  327. int freq_offset)
  328. {
  329. int mask_index = 0;
  330. mask_index = (freq_offset << 4) / 5;
  331. if (mask_index < 0)
  332. mask_index = mask_index - 1;
  333. mask_index = mask_index & 0x7f;
  334. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  335. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_B,
  336. mask_index);
  337. /* A == B */
  338. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_B,
  339. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A,
  340. mask_index);
  341. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  342. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_B,
  343. mask_index);
  344. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  345. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_B, 0xe);
  346. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  347. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_B, 0xe);
  348. /* A == B */
  349. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_B,
  350. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0xa0);
  351. }
  352. static void ar9003_hw_spur_ofdm_work(struct ath_hw *ah,
  353. struct ath9k_channel *chan,
  354. int freq_offset,
  355. int range,
  356. int synth_freq)
  357. {
  358. int spur_freq_sd = 0;
  359. int spur_subchannel_sd = 0;
  360. int spur_delta_phase = 0;
  361. if (IS_CHAN_HT40(chan)) {
  362. if (freq_offset < 0) {
  363. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  364. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  365. spur_subchannel_sd = 1;
  366. else
  367. spur_subchannel_sd = 0;
  368. spur_freq_sd = ((freq_offset + 10) << 9) / 11;
  369. } else {
  370. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  371. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  372. spur_subchannel_sd = 0;
  373. else
  374. spur_subchannel_sd = 1;
  375. spur_freq_sd = ((freq_offset - 10) << 9) / 11;
  376. }
  377. spur_delta_phase = (freq_offset << 17) / 5;
  378. } else {
  379. spur_subchannel_sd = 0;
  380. spur_freq_sd = (freq_offset << 9) /11;
  381. spur_delta_phase = (freq_offset << 18) / 5;
  382. }
  383. spur_freq_sd = spur_freq_sd & 0x3ff;
  384. spur_delta_phase = spur_delta_phase & 0xfffff;
  385. ar9003_hw_spur_ofdm(ah,
  386. freq_offset,
  387. spur_freq_sd,
  388. spur_delta_phase,
  389. spur_subchannel_sd,
  390. range, synth_freq);
  391. }
  392. /* Spur mitigation for OFDM */
  393. static void ar9003_hw_spur_mitigate_ofdm(struct ath_hw *ah,
  394. struct ath9k_channel *chan)
  395. {
  396. int synth_freq;
  397. int range = 10;
  398. int freq_offset = 0;
  399. int mode;
  400. u8* spurChansPtr;
  401. unsigned int i;
  402. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  403. if (IS_CHAN_5GHZ(chan)) {
  404. spurChansPtr = &(eep->modalHeader5G.spurChans[0]);
  405. mode = 0;
  406. }
  407. else {
  408. spurChansPtr = &(eep->modalHeader2G.spurChans[0]);
  409. mode = 1;
  410. }
  411. if (spurChansPtr[0] == 0)
  412. return; /* No spur in the mode */
  413. if (IS_CHAN_HT40(chan)) {
  414. range = 19;
  415. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  416. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  417. synth_freq = chan->channel - 10;
  418. else
  419. synth_freq = chan->channel + 10;
  420. } else {
  421. range = 10;
  422. synth_freq = chan->channel;
  423. }
  424. ar9003_hw_spur_ofdm_clear(ah);
  425. for (i = 0; i < AR_EEPROM_MODAL_SPURS && spurChansPtr[i]; i++) {
  426. freq_offset = ath9k_hw_fbin2freq(spurChansPtr[i], mode);
  427. freq_offset -= synth_freq;
  428. if (abs(freq_offset) < range) {
  429. ar9003_hw_spur_ofdm_work(ah, chan, freq_offset,
  430. range, synth_freq);
  431. if (AR_SREV_9565(ah) && (i < 4)) {
  432. freq_offset = ath9k_hw_fbin2freq(spurChansPtr[i + 1],
  433. mode);
  434. freq_offset -= synth_freq;
  435. if (abs(freq_offset) < range)
  436. ar9003_hw_spur_ofdm_9565(ah, freq_offset);
  437. }
  438. break;
  439. }
  440. }
  441. }
  442. static void ar9003_hw_spur_mitigate(struct ath_hw *ah,
  443. struct ath9k_channel *chan)
  444. {
  445. if (!AR_SREV_9565(ah))
  446. ar9003_hw_spur_mitigate_mrc_cck(ah, chan);
  447. ar9003_hw_spur_mitigate_ofdm(ah, chan);
  448. }
  449. static u32 ar9003_hw_compute_pll_control(struct ath_hw *ah,
  450. struct ath9k_channel *chan)
  451. {
  452. u32 pll;
  453. pll = SM(0x5, AR_RTC_9300_PLL_REFDIV);
  454. if (chan && IS_CHAN_HALF_RATE(chan))
  455. pll |= SM(0x1, AR_RTC_9300_PLL_CLKSEL);
  456. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  457. pll |= SM(0x2, AR_RTC_9300_PLL_CLKSEL);
  458. pll |= SM(0x2c, AR_RTC_9300_PLL_DIV);
  459. return pll;
  460. }
  461. static void ar9003_hw_set_channel_regs(struct ath_hw *ah,
  462. struct ath9k_channel *chan)
  463. {
  464. u32 phymode;
  465. u32 enableDacFifo = 0;
  466. enableDacFifo =
  467. (REG_READ(ah, AR_PHY_GEN_CTRL) & AR_PHY_GC_ENABLE_DAC_FIFO);
  468. /* Enable 11n HT, 20 MHz */
  469. phymode = AR_PHY_GC_HT_EN | AR_PHY_GC_SINGLE_HT_LTF1 |
  470. AR_PHY_GC_SHORT_GI_40 | enableDacFifo;
  471. /* Configure baseband for dynamic 20/40 operation */
  472. if (IS_CHAN_HT40(chan)) {
  473. phymode |= AR_PHY_GC_DYN2040_EN;
  474. /* Configure control (primary) channel at +-10MHz */
  475. if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
  476. (chan->chanmode == CHANNEL_G_HT40PLUS))
  477. phymode |= AR_PHY_GC_DYN2040_PRI_CH;
  478. }
  479. /* make sure we preserve INI settings */
  480. phymode |= REG_READ(ah, AR_PHY_GEN_CTRL);
  481. /* turn off Green Field detection for STA for now */
  482. phymode &= ~AR_PHY_GC_GF_DETECT_EN;
  483. REG_WRITE(ah, AR_PHY_GEN_CTRL, phymode);
  484. /* Configure MAC for 20/40 operation */
  485. ath9k_hw_set11nmac2040(ah);
  486. /* global transmit timeout (25 TUs default)*/
  487. REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
  488. /* carrier sense timeout */
  489. REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
  490. }
  491. static void ar9003_hw_init_bb(struct ath_hw *ah,
  492. struct ath9k_channel *chan)
  493. {
  494. u32 synthDelay;
  495. /*
  496. * Wait for the frequency synth to settle (synth goes on
  497. * via AR_PHY_ACTIVE_EN). Read the phy active delay register.
  498. * Value is in 100ns increments.
  499. */
  500. synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  501. /* Activate the PHY (includes baseband activate + synthesizer on) */
  502. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
  503. ath9k_hw_synth_delay(ah, chan, synthDelay);
  504. }
  505. void ar9003_hw_set_chain_masks(struct ath_hw *ah, u8 rx, u8 tx)
  506. {
  507. if (ah->caps.tx_chainmask == 5 || ah->caps.rx_chainmask == 5)
  508. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  509. AR_PHY_SWAP_ALT_CHAIN);
  510. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx);
  511. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx);
  512. if ((ah->caps.hw_caps & ATH9K_HW_CAP_APM) && (tx == 0x7))
  513. tx = 3;
  514. REG_WRITE(ah, AR_SELFGEN_MASK, tx);
  515. }
  516. /*
  517. * Override INI values with chip specific configuration.
  518. */
  519. static void ar9003_hw_override_ini(struct ath_hw *ah)
  520. {
  521. u32 val;
  522. /*
  523. * Set the RX_ABORT and RX_DIS and clear it only after
  524. * RXE is set for MAC. This prevents frames with
  525. * corrupted descriptor status.
  526. */
  527. REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  528. /*
  529. * For AR9280 and above, there is a new feature that allows
  530. * Multicast search based on both MAC Address and Key ID. By default,
  531. * this feature is enabled. But since the driver is not using this
  532. * feature, we switch it off; otherwise multicast search based on
  533. * MAC addr only will fail.
  534. */
  535. val = REG_READ(ah, AR_PCU_MISC_MODE2) & (~AR_ADHOC_MCAST_KEYID_ENABLE);
  536. REG_WRITE(ah, AR_PCU_MISC_MODE2,
  537. val | AR_AGG_WEP_ENABLE_FIX | AR_AGG_WEP_ENABLE);
  538. REG_SET_BIT(ah, AR_PHY_CCK_DETECT,
  539. AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
  540. }
  541. static void ar9003_hw_prog_ini(struct ath_hw *ah,
  542. struct ar5416IniArray *iniArr,
  543. int column)
  544. {
  545. unsigned int i, regWrites = 0;
  546. /* New INI format: Array may be undefined (pre, core, post arrays) */
  547. if (!iniArr->ia_array)
  548. return;
  549. /*
  550. * New INI format: Pre, core, and post arrays for a given subsystem
  551. * may be modal (> 2 columns) or non-modal (2 columns). Determine if
  552. * the array is non-modal and force the column to 1.
  553. */
  554. if (column >= iniArr->ia_columns)
  555. column = 1;
  556. for (i = 0; i < iniArr->ia_rows; i++) {
  557. u32 reg = INI_RA(iniArr, i, 0);
  558. u32 val = INI_RA(iniArr, i, column);
  559. REG_WRITE(ah, reg, val);
  560. DO_DELAY(regWrites);
  561. }
  562. }
  563. static int ar9550_hw_get_modes_txgain_index(struct ath_hw *ah,
  564. struct ath9k_channel *chan)
  565. {
  566. int ret;
  567. switch (chan->chanmode) {
  568. case CHANNEL_A:
  569. case CHANNEL_A_HT20:
  570. if (chan->channel <= 5350)
  571. ret = 1;
  572. else if ((chan->channel > 5350) && (chan->channel <= 5600))
  573. ret = 3;
  574. else
  575. ret = 5;
  576. break;
  577. case CHANNEL_A_HT40PLUS:
  578. case CHANNEL_A_HT40MINUS:
  579. if (chan->channel <= 5350)
  580. ret = 2;
  581. else if ((chan->channel > 5350) && (chan->channel <= 5600))
  582. ret = 4;
  583. else
  584. ret = 6;
  585. break;
  586. case CHANNEL_G:
  587. case CHANNEL_G_HT20:
  588. case CHANNEL_B:
  589. ret = 8;
  590. break;
  591. case CHANNEL_G_HT40PLUS:
  592. case CHANNEL_G_HT40MINUS:
  593. ret = 7;
  594. break;
  595. default:
  596. ret = -EINVAL;
  597. }
  598. return ret;
  599. }
  600. static int ar9003_hw_process_ini(struct ath_hw *ah,
  601. struct ath9k_channel *chan)
  602. {
  603. unsigned int regWrites = 0, i;
  604. u32 modesIndex;
  605. switch (chan->chanmode) {
  606. case CHANNEL_A:
  607. case CHANNEL_A_HT20:
  608. modesIndex = 1;
  609. break;
  610. case CHANNEL_A_HT40PLUS:
  611. case CHANNEL_A_HT40MINUS:
  612. modesIndex = 2;
  613. break;
  614. case CHANNEL_G:
  615. case CHANNEL_G_HT20:
  616. case CHANNEL_B:
  617. modesIndex = 4;
  618. break;
  619. case CHANNEL_G_HT40PLUS:
  620. case CHANNEL_G_HT40MINUS:
  621. modesIndex = 3;
  622. break;
  623. default:
  624. return -EINVAL;
  625. }
  626. for (i = 0; i < ATH_INI_NUM_SPLIT; i++) {
  627. ar9003_hw_prog_ini(ah, &ah->iniSOC[i], modesIndex);
  628. ar9003_hw_prog_ini(ah, &ah->iniMac[i], modesIndex);
  629. ar9003_hw_prog_ini(ah, &ah->iniBB[i], modesIndex);
  630. ar9003_hw_prog_ini(ah, &ah->iniRadio[i], modesIndex);
  631. if (i == ATH_INI_POST && AR_SREV_9462_20(ah))
  632. ar9003_hw_prog_ini(ah,
  633. &ah->ini_radio_post_sys2ant,
  634. modesIndex);
  635. }
  636. REG_WRITE_ARRAY(&ah->iniModesRxGain, 1, regWrites);
  637. if (AR_SREV_9550(ah))
  638. REG_WRITE_ARRAY(&ah->ini_modes_rx_gain_bounds, modesIndex,
  639. regWrites);
  640. if (AR_SREV_9550(ah)) {
  641. int modes_txgain_index;
  642. modes_txgain_index = ar9550_hw_get_modes_txgain_index(ah, chan);
  643. if (modes_txgain_index < 0)
  644. return -EINVAL;
  645. REG_WRITE_ARRAY(&ah->iniModesTxGain, modes_txgain_index,
  646. regWrites);
  647. } else {
  648. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  649. }
  650. /*
  651. * For 5GHz channels requiring Fast Clock, apply
  652. * different modal values.
  653. */
  654. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  655. REG_WRITE_ARRAY(&ah->iniModesFastClock,
  656. modesIndex, regWrites);
  657. REG_WRITE_ARRAY(&ah->iniAdditional, 1, regWrites);
  658. if (chan->channel == 2484)
  659. ar9003_hw_prog_ini(ah, &ah->iniCckfirJapan2484, 1);
  660. if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
  661. REG_WRITE(ah, AR_GLB_SWREG_DISCONT_MODE,
  662. AR_GLB_SWREG_DISCONT_EN_BT_WLAN);
  663. ah->modes_index = modesIndex;
  664. ar9003_hw_override_ini(ah);
  665. ar9003_hw_set_channel_regs(ah, chan);
  666. ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
  667. ath9k_hw_apply_txpower(ah, chan, false);
  668. if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
  669. if (REG_READ_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_0,
  670. AR_PHY_TX_IQCAL_CONTROL_0_ENABLE_TXIQ_CAL))
  671. ah->enabled_cals |= TX_IQ_CAL;
  672. else
  673. ah->enabled_cals &= ~TX_IQ_CAL;
  674. if (REG_READ(ah, AR_PHY_CL_CAL_CTL) & AR_PHY_CL_CAL_ENABLE)
  675. ah->enabled_cals |= TX_CL_CAL;
  676. else
  677. ah->enabled_cals &= ~TX_CL_CAL;
  678. }
  679. return 0;
  680. }
  681. static void ar9003_hw_set_rfmode(struct ath_hw *ah,
  682. struct ath9k_channel *chan)
  683. {
  684. u32 rfMode = 0;
  685. if (chan == NULL)
  686. return;
  687. rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
  688. ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
  689. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  690. rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
  691. if (IS_CHAN_QUARTER_RATE(chan))
  692. rfMode |= AR_PHY_MODE_QUARTER;
  693. if (IS_CHAN_HALF_RATE(chan))
  694. rfMode |= AR_PHY_MODE_HALF;
  695. if (rfMode & (AR_PHY_MODE_QUARTER | AR_PHY_MODE_HALF))
  696. REG_RMW_FIELD(ah, AR_PHY_FRAME_CTL,
  697. AR_PHY_FRAME_CTL_CF_OVERLAP_WINDOW, 3);
  698. REG_WRITE(ah, AR_PHY_MODE, rfMode);
  699. }
  700. static void ar9003_hw_mark_phy_inactive(struct ath_hw *ah)
  701. {
  702. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
  703. }
  704. static void ar9003_hw_set_delta_slope(struct ath_hw *ah,
  705. struct ath9k_channel *chan)
  706. {
  707. u32 coef_scaled, ds_coef_exp, ds_coef_man;
  708. u32 clockMhzScaled = 0x64000000;
  709. struct chan_centers centers;
  710. /*
  711. * half and quarter rate can divide the scaled clock by 2 or 4
  712. * scale for selected channel bandwidth
  713. */
  714. if (IS_CHAN_HALF_RATE(chan))
  715. clockMhzScaled = clockMhzScaled >> 1;
  716. else if (IS_CHAN_QUARTER_RATE(chan))
  717. clockMhzScaled = clockMhzScaled >> 2;
  718. /*
  719. * ALGO -> coef = 1e8/fcarrier*fclock/40;
  720. * scaled coef to provide precision for this floating calculation
  721. */
  722. ath9k_hw_get_channel_centers(ah, chan, &centers);
  723. coef_scaled = clockMhzScaled / centers.synth_center;
  724. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  725. &ds_coef_exp);
  726. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  727. AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
  728. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  729. AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
  730. /*
  731. * For Short GI,
  732. * scaled coeff is 9/10 that of normal coeff
  733. */
  734. coef_scaled = (9 * coef_scaled) / 10;
  735. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  736. &ds_coef_exp);
  737. /* for short gi */
  738. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  739. AR_PHY_SGI_DSC_MAN, ds_coef_man);
  740. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  741. AR_PHY_SGI_DSC_EXP, ds_coef_exp);
  742. }
  743. static bool ar9003_hw_rfbus_req(struct ath_hw *ah)
  744. {
  745. REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
  746. return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
  747. AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT);
  748. }
  749. /*
  750. * Wait for the frequency synth to settle (synth goes on via PHY_ACTIVE_EN).
  751. * Read the phy active delay register. Value is in 100ns increments.
  752. */
  753. static void ar9003_hw_rfbus_done(struct ath_hw *ah)
  754. {
  755. u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  756. ath9k_hw_synth_delay(ah, ah->curchan, synthDelay);
  757. REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
  758. }
  759. static bool ar9003_hw_ani_control(struct ath_hw *ah,
  760. enum ath9k_ani_cmd cmd, int param)
  761. {
  762. struct ath_common *common = ath9k_hw_common(ah);
  763. struct ath9k_channel *chan = ah->curchan;
  764. struct ar5416AniState *aniState = &chan->ani;
  765. s32 value, value2;
  766. switch (cmd & ah->ani_function) {
  767. case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
  768. /*
  769. * on == 1 means ofdm weak signal detection is ON
  770. * on == 1 is the default, for less noise immunity
  771. *
  772. * on == 0 means ofdm weak signal detection is OFF
  773. * on == 0 means more noise imm
  774. */
  775. u32 on = param ? 1 : 0;
  776. if (on)
  777. REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
  778. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  779. else
  780. REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
  781. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  782. if (on != aniState->ofdmWeakSigDetect) {
  783. ath_dbg(common, ANI,
  784. "** ch %d: ofdm weak signal: %s=>%s\n",
  785. chan->channel,
  786. aniState->ofdmWeakSigDetect ?
  787. "on" : "off",
  788. on ? "on" : "off");
  789. if (on)
  790. ah->stats.ast_ani_ofdmon++;
  791. else
  792. ah->stats.ast_ani_ofdmoff++;
  793. aniState->ofdmWeakSigDetect = on;
  794. }
  795. break;
  796. }
  797. case ATH9K_ANI_FIRSTEP_LEVEL:{
  798. u32 level = param;
  799. if (level >= ARRAY_SIZE(firstep_table)) {
  800. ath_dbg(common, ANI,
  801. "ATH9K_ANI_FIRSTEP_LEVEL: level out of range (%u > %zu)\n",
  802. level, ARRAY_SIZE(firstep_table));
  803. return false;
  804. }
  805. /*
  806. * make register setting relative to default
  807. * from INI file & cap value
  808. */
  809. value = firstep_table[level] -
  810. firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
  811. aniState->iniDef.firstep;
  812. if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  813. value = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  814. if (value > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  815. value = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  816. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  817. AR_PHY_FIND_SIG_FIRSTEP,
  818. value);
  819. /*
  820. * we need to set first step low register too
  821. * make register setting relative to default
  822. * from INI file & cap value
  823. */
  824. value2 = firstep_table[level] -
  825. firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
  826. aniState->iniDef.firstepLow;
  827. if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  828. value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  829. if (value2 > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  830. value2 = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  831. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
  832. AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW, value2);
  833. if (level != aniState->firstepLevel) {
  834. ath_dbg(common, ANI,
  835. "** ch %d: level %d=>%d[def:%d] firstep[level]=%d ini=%d\n",
  836. chan->channel,
  837. aniState->firstepLevel,
  838. level,
  839. ATH9K_ANI_FIRSTEP_LVL,
  840. value,
  841. aniState->iniDef.firstep);
  842. ath_dbg(common, ANI,
  843. "** ch %d: level %d=>%d[def:%d] firstep_low[level]=%d ini=%d\n",
  844. chan->channel,
  845. aniState->firstepLevel,
  846. level,
  847. ATH9K_ANI_FIRSTEP_LVL,
  848. value2,
  849. aniState->iniDef.firstepLow);
  850. if (level > aniState->firstepLevel)
  851. ah->stats.ast_ani_stepup++;
  852. else if (level < aniState->firstepLevel)
  853. ah->stats.ast_ani_stepdown++;
  854. aniState->firstepLevel = level;
  855. }
  856. break;
  857. }
  858. case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
  859. u32 level = param;
  860. if (level >= ARRAY_SIZE(cycpwrThr1_table)) {
  861. ath_dbg(common, ANI,
  862. "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level out of range (%u > %zu)\n",
  863. level, ARRAY_SIZE(cycpwrThr1_table));
  864. return false;
  865. }
  866. /*
  867. * make register setting relative to default
  868. * from INI file & cap value
  869. */
  870. value = cycpwrThr1_table[level] -
  871. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
  872. aniState->iniDef.cycpwrThr1;
  873. if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  874. value = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  875. if (value > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  876. value = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  877. REG_RMW_FIELD(ah, AR_PHY_TIMING5,
  878. AR_PHY_TIMING5_CYCPWR_THR1,
  879. value);
  880. /*
  881. * set AR_PHY_EXT_CCA for extension channel
  882. * make register setting relative to default
  883. * from INI file & cap value
  884. */
  885. value2 = cycpwrThr1_table[level] -
  886. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
  887. aniState->iniDef.cycpwrThr1Ext;
  888. if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  889. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  890. if (value2 > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  891. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  892. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
  893. AR_PHY_EXT_CYCPWR_THR1, value2);
  894. if (level != aniState->spurImmunityLevel) {
  895. ath_dbg(common, ANI,
  896. "** ch %d: level %d=>%d[def:%d] cycpwrThr1[level]=%d ini=%d\n",
  897. chan->channel,
  898. aniState->spurImmunityLevel,
  899. level,
  900. ATH9K_ANI_SPUR_IMMUNE_LVL,
  901. value,
  902. aniState->iniDef.cycpwrThr1);
  903. ath_dbg(common, ANI,
  904. "** ch %d: level %d=>%d[def:%d] cycpwrThr1Ext[level]=%d ini=%d\n",
  905. chan->channel,
  906. aniState->spurImmunityLevel,
  907. level,
  908. ATH9K_ANI_SPUR_IMMUNE_LVL,
  909. value2,
  910. aniState->iniDef.cycpwrThr1Ext);
  911. if (level > aniState->spurImmunityLevel)
  912. ah->stats.ast_ani_spurup++;
  913. else if (level < aniState->spurImmunityLevel)
  914. ah->stats.ast_ani_spurdown++;
  915. aniState->spurImmunityLevel = level;
  916. }
  917. break;
  918. }
  919. case ATH9K_ANI_MRC_CCK:{
  920. /*
  921. * is_on == 1 means MRC CCK ON (default, less noise imm)
  922. * is_on == 0 means MRC CCK is OFF (more noise imm)
  923. */
  924. bool is_on = param ? 1 : 0;
  925. REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
  926. AR_PHY_MRC_CCK_ENABLE, is_on);
  927. REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
  928. AR_PHY_MRC_CCK_MUX_REG, is_on);
  929. if (is_on != aniState->mrcCCK) {
  930. ath_dbg(common, ANI, "** ch %d: MRC CCK: %s=>%s\n",
  931. chan->channel,
  932. aniState->mrcCCK ? "on" : "off",
  933. is_on ? "on" : "off");
  934. if (is_on)
  935. ah->stats.ast_ani_ccklow++;
  936. else
  937. ah->stats.ast_ani_cckhigh++;
  938. aniState->mrcCCK = is_on;
  939. }
  940. break;
  941. }
  942. case ATH9K_ANI_PRESENT:
  943. break;
  944. default:
  945. ath_dbg(common, ANI, "invalid cmd %u\n", cmd);
  946. return false;
  947. }
  948. ath_dbg(common, ANI,
  949. "ANI parameters: SI=%d, ofdmWS=%s FS=%d MRCcck=%s listenTime=%d ofdmErrs=%d cckErrs=%d\n",
  950. aniState->spurImmunityLevel,
  951. aniState->ofdmWeakSigDetect ? "on" : "off",
  952. aniState->firstepLevel,
  953. aniState->mrcCCK ? "on" : "off",
  954. aniState->listenTime,
  955. aniState->ofdmPhyErrCount,
  956. aniState->cckPhyErrCount);
  957. return true;
  958. }
  959. static void ar9003_hw_do_getnf(struct ath_hw *ah,
  960. int16_t nfarray[NUM_NF_READINGS])
  961. {
  962. #define AR_PHY_CH_MINCCA_PWR 0x1FF00000
  963. #define AR_PHY_CH_MINCCA_PWR_S 20
  964. #define AR_PHY_CH_EXT_MINCCA_PWR 0x01FF0000
  965. #define AR_PHY_CH_EXT_MINCCA_PWR_S 16
  966. int16_t nf;
  967. int i;
  968. for (i = 0; i < AR9300_MAX_CHAINS; i++) {
  969. if (ah->rxchainmask & BIT(i)) {
  970. nf = MS(REG_READ(ah, ah->nf_regs[i]),
  971. AR_PHY_CH_MINCCA_PWR);
  972. nfarray[i] = sign_extend32(nf, 8);
  973. if (IS_CHAN_HT40(ah->curchan)) {
  974. u8 ext_idx = AR9300_MAX_CHAINS + i;
  975. nf = MS(REG_READ(ah, ah->nf_regs[ext_idx]),
  976. AR_PHY_CH_EXT_MINCCA_PWR);
  977. nfarray[ext_idx] = sign_extend32(nf, 8);
  978. }
  979. }
  980. }
  981. }
  982. static void ar9003_hw_set_nf_limits(struct ath_hw *ah)
  983. {
  984. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_2GHZ;
  985. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_2GHZ;
  986. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9300_2GHZ;
  987. ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_5GHZ;
  988. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_5GHZ;
  989. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9300_5GHZ;
  990. if (AR_SREV_9330(ah))
  991. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9330_2GHZ;
  992. if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
  993. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9462_2GHZ;
  994. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9462_2GHZ;
  995. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9462_5GHZ;
  996. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9462_5GHZ;
  997. }
  998. }
  999. /*
  1000. * Initialize the ANI register values with default (ini) values.
  1001. * This routine is called during a (full) hardware reset after
  1002. * all the registers are initialised from the INI.
  1003. */
  1004. static void ar9003_hw_ani_cache_ini_regs(struct ath_hw *ah)
  1005. {
  1006. struct ar5416AniState *aniState;
  1007. struct ath_common *common = ath9k_hw_common(ah);
  1008. struct ath9k_channel *chan = ah->curchan;
  1009. struct ath9k_ani_default *iniDef;
  1010. u32 val;
  1011. aniState = &ah->curchan->ani;
  1012. iniDef = &aniState->iniDef;
  1013. ath_dbg(common, ANI, "ver %d.%d opmode %u chan %d Mhz/0x%x\n",
  1014. ah->hw_version.macVersion,
  1015. ah->hw_version.macRev,
  1016. ah->opmode,
  1017. chan->channel,
  1018. chan->channelFlags);
  1019. val = REG_READ(ah, AR_PHY_SFCORR);
  1020. iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH);
  1021. iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH);
  1022. iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR);
  1023. val = REG_READ(ah, AR_PHY_SFCORR_LOW);
  1024. iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW);
  1025. iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW);
  1026. iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW);
  1027. val = REG_READ(ah, AR_PHY_SFCORR_EXT);
  1028. iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH);
  1029. iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH);
  1030. iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW);
  1031. iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW);
  1032. iniDef->firstep = REG_READ_FIELD(ah,
  1033. AR_PHY_FIND_SIG,
  1034. AR_PHY_FIND_SIG_FIRSTEP);
  1035. iniDef->firstepLow = REG_READ_FIELD(ah,
  1036. AR_PHY_FIND_SIG_LOW,
  1037. AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW);
  1038. iniDef->cycpwrThr1 = REG_READ_FIELD(ah,
  1039. AR_PHY_TIMING5,
  1040. AR_PHY_TIMING5_CYCPWR_THR1);
  1041. iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah,
  1042. AR_PHY_EXT_CCA,
  1043. AR_PHY_EXT_CYCPWR_THR1);
  1044. /* these levels just got reset to defaults by the INI */
  1045. aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL;
  1046. aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL;
  1047. aniState->ofdmWeakSigDetect = ATH9K_ANI_USE_OFDM_WEAK_SIG;
  1048. aniState->mrcCCK = true;
  1049. }
  1050. static void ar9003_hw_set_radar_params(struct ath_hw *ah,
  1051. struct ath_hw_radar_conf *conf)
  1052. {
  1053. u32 radar_0 = 0, radar_1 = 0;
  1054. if (!conf) {
  1055. REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA);
  1056. return;
  1057. }
  1058. radar_0 |= AR_PHY_RADAR_0_ENA | AR_PHY_RADAR_0_FFT_ENA;
  1059. radar_0 |= SM(conf->fir_power, AR_PHY_RADAR_0_FIRPWR);
  1060. radar_0 |= SM(conf->radar_rssi, AR_PHY_RADAR_0_RRSSI);
  1061. radar_0 |= SM(conf->pulse_height, AR_PHY_RADAR_0_HEIGHT);
  1062. radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI);
  1063. radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND);
  1064. radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI;
  1065. radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK;
  1066. radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN);
  1067. radar_1 |= SM(conf->pulse_inband_step, AR_PHY_RADAR_1_RELSTEP_THRESH);
  1068. radar_1 |= SM(conf->radar_inband, AR_PHY_RADAR_1_RELPWR_THRESH);
  1069. REG_WRITE(ah, AR_PHY_RADAR_0, radar_0);
  1070. REG_WRITE(ah, AR_PHY_RADAR_1, radar_1);
  1071. if (conf->ext_channel)
  1072. REG_SET_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1073. else
  1074. REG_CLR_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1075. }
  1076. static void ar9003_hw_set_radar_conf(struct ath_hw *ah)
  1077. {
  1078. struct ath_hw_radar_conf *conf = &ah->radar_conf;
  1079. conf->fir_power = -28;
  1080. conf->radar_rssi = 0;
  1081. conf->pulse_height = 10;
  1082. conf->pulse_rssi = 24;
  1083. conf->pulse_inband = 8;
  1084. conf->pulse_maxlen = 255;
  1085. conf->pulse_inband_step = 12;
  1086. conf->radar_inband = 8;
  1087. }
  1088. static void ar9003_hw_antdiv_comb_conf_get(struct ath_hw *ah,
  1089. struct ath_hw_antcomb_conf *antconf)
  1090. {
  1091. u32 regval;
  1092. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1093. antconf->main_lna_conf = (regval & AR_PHY_ANT_DIV_MAIN_LNACONF) >>
  1094. AR_PHY_ANT_DIV_MAIN_LNACONF_S;
  1095. antconf->alt_lna_conf = (regval & AR_PHY_ANT_DIV_ALT_LNACONF) >>
  1096. AR_PHY_ANT_DIV_ALT_LNACONF_S;
  1097. antconf->fast_div_bias = (regval & AR_PHY_ANT_FAST_DIV_BIAS) >>
  1098. AR_PHY_ANT_FAST_DIV_BIAS_S;
  1099. if (AR_SREV_9330_11(ah)) {
  1100. antconf->lna1_lna2_delta = -9;
  1101. antconf->div_group = 1;
  1102. } else if (AR_SREV_9485(ah)) {
  1103. antconf->lna1_lna2_delta = -9;
  1104. antconf->div_group = 2;
  1105. } else if (AR_SREV_9565(ah)) {
  1106. antconf->lna1_lna2_delta = -3;
  1107. antconf->div_group = 3;
  1108. } else {
  1109. antconf->lna1_lna2_delta = -3;
  1110. antconf->div_group = 0;
  1111. }
  1112. }
  1113. static void ar9003_hw_antdiv_comb_conf_set(struct ath_hw *ah,
  1114. struct ath_hw_antcomb_conf *antconf)
  1115. {
  1116. u32 regval;
  1117. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1118. regval &= ~(AR_PHY_ANT_DIV_MAIN_LNACONF |
  1119. AR_PHY_ANT_DIV_ALT_LNACONF |
  1120. AR_PHY_ANT_FAST_DIV_BIAS |
  1121. AR_PHY_ANT_DIV_MAIN_GAINTB |
  1122. AR_PHY_ANT_DIV_ALT_GAINTB);
  1123. regval |= ((antconf->main_lna_conf << AR_PHY_ANT_DIV_MAIN_LNACONF_S)
  1124. & AR_PHY_ANT_DIV_MAIN_LNACONF);
  1125. regval |= ((antconf->alt_lna_conf << AR_PHY_ANT_DIV_ALT_LNACONF_S)
  1126. & AR_PHY_ANT_DIV_ALT_LNACONF);
  1127. regval |= ((antconf->fast_div_bias << AR_PHY_ANT_FAST_DIV_BIAS_S)
  1128. & AR_PHY_ANT_FAST_DIV_BIAS);
  1129. regval |= ((antconf->main_gaintb << AR_PHY_ANT_DIV_MAIN_GAINTB_S)
  1130. & AR_PHY_ANT_DIV_MAIN_GAINTB);
  1131. regval |= ((antconf->alt_gaintb << AR_PHY_ANT_DIV_ALT_GAINTB_S)
  1132. & AR_PHY_ANT_DIV_ALT_GAINTB);
  1133. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1134. }
  1135. static void ar9003_hw_antctrl_shared_chain_lnadiv(struct ath_hw *ah,
  1136. bool enable)
  1137. {
  1138. u8 ant_div_ctl1;
  1139. u32 regval;
  1140. if (!AR_SREV_9565(ah))
  1141. return;
  1142. ah->shared_chain_lnadiv = enable;
  1143. ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
  1144. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1145. regval &= (~AR_ANT_DIV_CTRL_ALL);
  1146. regval |= (ant_div_ctl1 & 0x3f) << AR_ANT_DIV_CTRL_ALL_S;
  1147. regval &= ~AR_PHY_ANT_DIV_LNADIV;
  1148. regval |= ((ant_div_ctl1 >> 6) & 0x1) << AR_PHY_ANT_DIV_LNADIV_S;
  1149. if (enable)
  1150. regval |= AR_ANT_DIV_ENABLE;
  1151. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1152. regval = REG_READ(ah, AR_PHY_CCK_DETECT);
  1153. regval &= ~AR_FAST_DIV_ENABLE;
  1154. regval |= ((ant_div_ctl1 >> 7) & 0x1) << AR_FAST_DIV_ENABLE_S;
  1155. if (enable)
  1156. regval |= AR_FAST_DIV_ENABLE;
  1157. REG_WRITE(ah, AR_PHY_CCK_DETECT, regval);
  1158. if (enable) {
  1159. REG_SET_BIT(ah, AR_PHY_MC_GAIN_CTRL,
  1160. (1 << AR_PHY_ANT_SW_RX_PROT_S));
  1161. if (ah->curchan && IS_CHAN_2GHZ(ah->curchan))
  1162. REG_SET_BIT(ah, AR_PHY_RESTART,
  1163. AR_PHY_RESTART_ENABLE_DIV_M2FLAG);
  1164. REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV,
  1165. AR_BTCOEX_WL_LNADIV_FORCE_ON);
  1166. } else {
  1167. REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL, AR_ANT_DIV_ENABLE);
  1168. REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL,
  1169. (1 << AR_PHY_ANT_SW_RX_PROT_S));
  1170. REG_CLR_BIT(ah, AR_PHY_CCK_DETECT, AR_FAST_DIV_ENABLE);
  1171. REG_CLR_BIT(ah, AR_BTCOEX_WL_LNADIV,
  1172. AR_BTCOEX_WL_LNADIV_FORCE_ON);
  1173. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1174. regval &= ~(AR_PHY_ANT_DIV_MAIN_LNACONF |
  1175. AR_PHY_ANT_DIV_ALT_LNACONF |
  1176. AR_PHY_ANT_DIV_MAIN_GAINTB |
  1177. AR_PHY_ANT_DIV_ALT_GAINTB);
  1178. regval |= (AR_PHY_ANT_DIV_LNA1 << AR_PHY_ANT_DIV_MAIN_LNACONF_S);
  1179. regval |= (AR_PHY_ANT_DIV_LNA2 << AR_PHY_ANT_DIV_ALT_LNACONF_S);
  1180. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1181. }
  1182. }
  1183. static int ar9003_hw_fast_chan_change(struct ath_hw *ah,
  1184. struct ath9k_channel *chan,
  1185. u8 *ini_reloaded)
  1186. {
  1187. unsigned int regWrites = 0;
  1188. u32 modesIndex;
  1189. switch (chan->chanmode) {
  1190. case CHANNEL_A:
  1191. case CHANNEL_A_HT20:
  1192. modesIndex = 1;
  1193. break;
  1194. case CHANNEL_A_HT40PLUS:
  1195. case CHANNEL_A_HT40MINUS:
  1196. modesIndex = 2;
  1197. break;
  1198. case CHANNEL_G:
  1199. case CHANNEL_G_HT20:
  1200. case CHANNEL_B:
  1201. modesIndex = 4;
  1202. break;
  1203. case CHANNEL_G_HT40PLUS:
  1204. case CHANNEL_G_HT40MINUS:
  1205. modesIndex = 3;
  1206. break;
  1207. default:
  1208. return -EINVAL;
  1209. }
  1210. if (modesIndex == ah->modes_index) {
  1211. *ini_reloaded = false;
  1212. goto set_rfmode;
  1213. }
  1214. ar9003_hw_prog_ini(ah, &ah->iniSOC[ATH_INI_POST], modesIndex);
  1215. ar9003_hw_prog_ini(ah, &ah->iniMac[ATH_INI_POST], modesIndex);
  1216. ar9003_hw_prog_ini(ah, &ah->iniBB[ATH_INI_POST], modesIndex);
  1217. ar9003_hw_prog_ini(ah, &ah->iniRadio[ATH_INI_POST], modesIndex);
  1218. if (AR_SREV_9462_20(ah))
  1219. ar9003_hw_prog_ini(ah, &ah->ini_radio_post_sys2ant,
  1220. modesIndex);
  1221. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  1222. /*
  1223. * For 5GHz channels requiring Fast Clock, apply
  1224. * different modal values.
  1225. */
  1226. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  1227. REG_WRITE_ARRAY(&ah->iniModesFastClock, modesIndex, regWrites);
  1228. if (AR_SREV_9565(ah))
  1229. REG_WRITE_ARRAY(&ah->iniModesFastClock, 1, regWrites);
  1230. REG_WRITE_ARRAY(&ah->iniAdditional, 1, regWrites);
  1231. ah->modes_index = modesIndex;
  1232. *ini_reloaded = true;
  1233. set_rfmode:
  1234. ar9003_hw_set_rfmode(ah, chan);
  1235. return 0;
  1236. }
  1237. void ar9003_hw_attach_phy_ops(struct ath_hw *ah)
  1238. {
  1239. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  1240. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  1241. static const u32 ar9300_cca_regs[6] = {
  1242. AR_PHY_CCA_0,
  1243. AR_PHY_CCA_1,
  1244. AR_PHY_CCA_2,
  1245. AR_PHY_EXT_CCA,
  1246. AR_PHY_EXT_CCA_1,
  1247. AR_PHY_EXT_CCA_2,
  1248. };
  1249. priv_ops->rf_set_freq = ar9003_hw_set_channel;
  1250. priv_ops->spur_mitigate_freq = ar9003_hw_spur_mitigate;
  1251. priv_ops->compute_pll_control = ar9003_hw_compute_pll_control;
  1252. priv_ops->set_channel_regs = ar9003_hw_set_channel_regs;
  1253. priv_ops->init_bb = ar9003_hw_init_bb;
  1254. priv_ops->process_ini = ar9003_hw_process_ini;
  1255. priv_ops->set_rfmode = ar9003_hw_set_rfmode;
  1256. priv_ops->mark_phy_inactive = ar9003_hw_mark_phy_inactive;
  1257. priv_ops->set_delta_slope = ar9003_hw_set_delta_slope;
  1258. priv_ops->rfbus_req = ar9003_hw_rfbus_req;
  1259. priv_ops->rfbus_done = ar9003_hw_rfbus_done;
  1260. priv_ops->ani_control = ar9003_hw_ani_control;
  1261. priv_ops->do_getnf = ar9003_hw_do_getnf;
  1262. priv_ops->ani_cache_ini_regs = ar9003_hw_ani_cache_ini_regs;
  1263. priv_ops->set_radar_params = ar9003_hw_set_radar_params;
  1264. priv_ops->fast_chan_change = ar9003_hw_fast_chan_change;
  1265. ops->antdiv_comb_conf_get = ar9003_hw_antdiv_comb_conf_get;
  1266. ops->antdiv_comb_conf_set = ar9003_hw_antdiv_comb_conf_set;
  1267. ops->antctrl_shared_chain_lnadiv = ar9003_hw_antctrl_shared_chain_lnadiv;
  1268. ar9003_hw_set_nf_limits(ah);
  1269. ar9003_hw_set_radar_conf(ah);
  1270. memcpy(ah->nf_regs, ar9300_cca_regs, sizeof(ah->nf_regs));
  1271. }
  1272. void ar9003_hw_bb_watchdog_config(struct ath_hw *ah)
  1273. {
  1274. struct ath_common *common = ath9k_hw_common(ah);
  1275. u32 idle_tmo_ms = ah->bb_watchdog_timeout_ms;
  1276. u32 val, idle_count;
  1277. if (!idle_tmo_ms) {
  1278. /* disable IRQ, disable chip-reset for BB panic */
  1279. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
  1280. REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) &
  1281. ~(AR_PHY_WATCHDOG_RST_ENABLE |
  1282. AR_PHY_WATCHDOG_IRQ_ENABLE));
  1283. /* disable watchdog in non-IDLE mode, disable in IDLE mode */
  1284. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
  1285. REG_READ(ah, AR_PHY_WATCHDOG_CTL_1) &
  1286. ~(AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
  1287. AR_PHY_WATCHDOG_IDLE_ENABLE));
  1288. ath_dbg(common, RESET, "Disabled BB Watchdog\n");
  1289. return;
  1290. }
  1291. /* enable IRQ, disable chip-reset for BB watchdog */
  1292. val = REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) & AR_PHY_WATCHDOG_CNTL2_MASK;
  1293. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
  1294. (val | AR_PHY_WATCHDOG_IRQ_ENABLE) &
  1295. ~AR_PHY_WATCHDOG_RST_ENABLE);
  1296. /* bound limit to 10 secs */
  1297. if (idle_tmo_ms > 10000)
  1298. idle_tmo_ms = 10000;
  1299. /*
  1300. * The time unit for watchdog event is 2^15 44/88MHz cycles.
  1301. *
  1302. * For HT20 we have a time unit of 2^15/44 MHz = .74 ms per tick
  1303. * For HT40 we have a time unit of 2^15/88 MHz = .37 ms per tick
  1304. *
  1305. * Given we use fast clock now in 5 GHz, these time units should
  1306. * be common for both 2 GHz and 5 GHz.
  1307. */
  1308. idle_count = (100 * idle_tmo_ms) / 74;
  1309. if (ah->curchan && IS_CHAN_HT40(ah->curchan))
  1310. idle_count = (100 * idle_tmo_ms) / 37;
  1311. /*
  1312. * enable watchdog in non-IDLE mode, disable in IDLE mode,
  1313. * set idle time-out.
  1314. */
  1315. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
  1316. AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
  1317. AR_PHY_WATCHDOG_IDLE_MASK |
  1318. (AR_PHY_WATCHDOG_NON_IDLE_MASK & (idle_count << 2)));
  1319. ath_dbg(common, RESET, "Enabled BB Watchdog timeout (%u ms)\n",
  1320. idle_tmo_ms);
  1321. }
  1322. void ar9003_hw_bb_watchdog_read(struct ath_hw *ah)
  1323. {
  1324. /*
  1325. * we want to avoid printing in ISR context so we save the
  1326. * watchdog status to be printed later in bottom half context.
  1327. */
  1328. ah->bb_watchdog_last_status = REG_READ(ah, AR_PHY_WATCHDOG_STATUS);
  1329. /*
  1330. * the watchdog timer should reset on status read but to be sure
  1331. * sure we write 0 to the watchdog status bit.
  1332. */
  1333. REG_WRITE(ah, AR_PHY_WATCHDOG_STATUS,
  1334. ah->bb_watchdog_last_status & ~AR_PHY_WATCHDOG_STATUS_CLR);
  1335. }
  1336. void ar9003_hw_bb_watchdog_dbg_info(struct ath_hw *ah)
  1337. {
  1338. struct ath_common *common = ath9k_hw_common(ah);
  1339. u32 status;
  1340. if (likely(!(common->debug_mask & ATH_DBG_RESET)))
  1341. return;
  1342. status = ah->bb_watchdog_last_status;
  1343. ath_dbg(common, RESET,
  1344. "\n==== BB update: BB status=0x%08x ====\n", status);
  1345. ath_dbg(common, RESET,
  1346. "** BB state: wd=%u det=%u rdar=%u rOFDM=%d rCCK=%u tOFDM=%u tCCK=%u agc=%u src=%u **\n",
  1347. MS(status, AR_PHY_WATCHDOG_INFO),
  1348. MS(status, AR_PHY_WATCHDOG_DET_HANG),
  1349. MS(status, AR_PHY_WATCHDOG_RADAR_SM),
  1350. MS(status, AR_PHY_WATCHDOG_RX_OFDM_SM),
  1351. MS(status, AR_PHY_WATCHDOG_RX_CCK_SM),
  1352. MS(status, AR_PHY_WATCHDOG_TX_OFDM_SM),
  1353. MS(status, AR_PHY_WATCHDOG_TX_CCK_SM),
  1354. MS(status, AR_PHY_WATCHDOG_AGC_SM),
  1355. MS(status, AR_PHY_WATCHDOG_SRCH_SM));
  1356. ath_dbg(common, RESET, "** BB WD cntl: cntl1=0x%08x cntl2=0x%08x **\n",
  1357. REG_READ(ah, AR_PHY_WATCHDOG_CTL_1),
  1358. REG_READ(ah, AR_PHY_WATCHDOG_CTL_2));
  1359. ath_dbg(common, RESET, "** BB mode: BB_gen_controls=0x%08x **\n",
  1360. REG_READ(ah, AR_PHY_GEN_CTRL));
  1361. #define PCT(_field) (common->cc_survey._field * 100 / common->cc_survey.cycles)
  1362. if (common->cc_survey.cycles)
  1363. ath_dbg(common, RESET,
  1364. "** BB busy times: rx_clear=%d%%, rx_frame=%d%%, tx_frame=%d%% **\n",
  1365. PCT(rx_busy), PCT(rx_frame), PCT(tx_frame));
  1366. ath_dbg(common, RESET, "==== BB update: done ====\n\n");
  1367. }
  1368. EXPORT_SYMBOL(ar9003_hw_bb_watchdog_dbg_info);
  1369. void ar9003_hw_disable_phy_restart(struct ath_hw *ah)
  1370. {
  1371. u32 val;
  1372. /* While receiving unsupported rate frame rx state machine
  1373. * gets into a state 0xb and if phy_restart happens in that
  1374. * state, BB would go hang. If RXSM is in 0xb state after
  1375. * first bb panic, ensure to disable the phy_restart.
  1376. */
  1377. if (!((MS(ah->bb_watchdog_last_status,
  1378. AR_PHY_WATCHDOG_RX_OFDM_SM) == 0xb) ||
  1379. ah->bb_hang_rx_ofdm))
  1380. return;
  1381. ah->bb_hang_rx_ofdm = true;
  1382. val = REG_READ(ah, AR_PHY_RESTART);
  1383. val &= ~AR_PHY_RESTART_ENA;
  1384. REG_WRITE(ah, AR_PHY_RESTART, val);
  1385. }
  1386. EXPORT_SYMBOL(ar9003_hw_disable_phy_restart);