You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ath9k_ar9003_phy.c 37KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  1. /*
  2. * Copyright (c) 2010-2011 Atheros Communications Inc.
  3. *
  4. * Modified for iPXE by Scott K Logan <logans@cottsay.net> July 2011
  5. * Original from Linux kernel 3.0.1
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for any
  8. * purpose with or without fee is hereby granted, provided that the above
  9. * copyright notice and this permission notice appear in all copies.
  10. *
  11. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  12. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  13. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  14. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  15. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  16. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  17. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #include <ipxe/io.h>
  20. #include "hw.h"
  21. #include "ar9003_phy.h"
  22. static const int firstep_table[] =
  23. /* level: 0 1 2 3 4 5 6 7 8 */
  24. { -4, -2, 0, 2, 4, 6, 8, 10, 12 }; /* lvl 0-8, default 2 */
  25. static const int cycpwrThr1_table[] =
  26. /* level: 0 1 2 3 4 5 6 7 8 */
  27. { -6, -4, -2, 0, 2, 4, 6, 8 }; /* lvl 0-7, default 3 */
  28. /*
  29. * register values to turn OFDM weak signal detection OFF
  30. */
  31. static const int m1ThreshLow_off = 127;
  32. static const int m2ThreshLow_off = 127;
  33. static const int m1Thresh_off = 127;
  34. static const int m2Thresh_off = 127;
  35. static const int m2CountThr_off = 31;
  36. static const int m2CountThrLow_off = 63;
  37. static const int m1ThreshLowExt_off = 127;
  38. static const int m2ThreshLowExt_off = 127;
  39. static const int m1ThreshExt_off = 127;
  40. static const int m2ThreshExt_off = 127;
  41. /**
  42. * ar9003_hw_set_channel - set channel on single-chip device
  43. * @ah: atheros hardware structure
  44. * @chan:
  45. *
  46. * This is the function to change channel on single-chip devices, that is
  47. * all devices after ar9280.
  48. *
  49. * This function takes the channel value in MHz and sets
  50. * hardware channel value. Assumes writes have been enabled to analog bus.
  51. *
  52. * Actual Expression,
  53. *
  54. * For 2GHz channel,
  55. * Channel Frequency = (3/4) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
  56. * (freq_ref = 40MHz)
  57. *
  58. * For 5GHz channel,
  59. * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^10)
  60. * (freq_ref = 40MHz/(24>>amodeRefSel))
  61. *
  62. * For 5GHz channels which are 5MHz spaced,
  63. * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
  64. * (freq_ref = 40MHz)
  65. */
  66. static int ar9003_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
  67. {
  68. u16 bMode, fracMode = 0, aModeRefSel = 0;
  69. u32 freq, channelSel = 0, reg32 = 0;
  70. struct chan_centers centers;
  71. int loadSynthChannel;
  72. ath9k_hw_get_channel_centers(ah, chan, &centers);
  73. freq = centers.synth_center;
  74. if (freq < 4800) { /* 2 GHz, fractional mode */
  75. if (AR_SREV_9485(ah)) {
  76. u32 chan_frac;
  77. /*
  78. * freq_ref = 40 / (refdiva >> amoderefsel); where refdiva=1 and amoderefsel=0
  79. * ndiv = ((chan_mhz * 4) / 3) / freq_ref;
  80. * chansel = int(ndiv), chanfrac = (ndiv - chansel) * 0x20000
  81. */
  82. channelSel = (freq * 4) / 120;
  83. chan_frac = (((freq * 4) % 120) * 0x20000) / 120;
  84. channelSel = (channelSel << 17) | chan_frac;
  85. } else if (AR_SREV_9340(ah)) {
  86. if (ah->is_clk_25mhz) {
  87. u32 chan_frac;
  88. channelSel = (freq * 2) / 75;
  89. chan_frac = (((freq * 2) % 75) * 0x20000) / 75;
  90. channelSel = (channelSel << 17) | chan_frac;
  91. } else
  92. channelSel = CHANSEL_2G(freq) >> 1;
  93. } else
  94. channelSel = CHANSEL_2G(freq);
  95. /* Set to 2G mode */
  96. bMode = 1;
  97. } else {
  98. if (AR_SREV_9340(ah) && ah->is_clk_25mhz) {
  99. u32 chan_frac;
  100. channelSel = (freq * 2) / 75;
  101. chan_frac = ((freq % 75) * 0x20000) / 75;
  102. channelSel = (channelSel << 17) | chan_frac;
  103. } else {
  104. channelSel = CHANSEL_5G(freq);
  105. /* Doubler is ON, so, divide channelSel by 2. */
  106. channelSel >>= 1;
  107. }
  108. /* Set to 5G mode */
  109. bMode = 0;
  110. }
  111. /* Enable fractional mode for all channels */
  112. fracMode = 1;
  113. aModeRefSel = 0;
  114. loadSynthChannel = 0;
  115. reg32 = (bMode << 29);
  116. REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
  117. /* Enable Long shift Select for Synthesizer */
  118. REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_SYNTH4,
  119. AR_PHY_SYNTH4_LONG_SHIFT_SELECT, 1);
  120. /* Program Synth. setting */
  121. reg32 = (channelSel << 2) | (fracMode << 30) |
  122. (aModeRefSel << 28) | (loadSynthChannel << 31);
  123. REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
  124. /* Toggle Load Synth channel bit */
  125. loadSynthChannel = 1;
  126. reg32 = (channelSel << 2) | (fracMode << 30) |
  127. (aModeRefSel << 28) | (loadSynthChannel << 31);
  128. REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
  129. ah->curchan = chan;
  130. ah->curchan_rad_index = -1;
  131. return 0;
  132. }
  133. /**
  134. * ar9003_hw_spur_mitigate_mrc_cck - convert baseband spur frequency
  135. * @ah: atheros hardware structure
  136. * @chan:
  137. *
  138. * For single-chip solutions. Converts to baseband spur frequency given the
  139. * input channel frequency and compute register settings below.
  140. *
  141. * Spur mitigation for MRC CCK
  142. */
  143. static void ar9003_hw_spur_mitigate_mrc_cck(struct ath_hw *ah,
  144. struct ath9k_channel *chan)
  145. {
  146. static const u32 spur_freq[4] = { 2420, 2440, 2464, 2480 };
  147. int cur_bb_spur, negative = 0, cck_spur_freq;
  148. int i;
  149. int range, max_spur_cnts, synth_freq;
  150. u8 *spur_fbin_ptr = NULL;
  151. /*
  152. * Need to verify range +/- 10 MHz in control channel, otherwise spur
  153. * is out-of-band and can be ignored.
  154. */
  155. if (AR_SREV_9485(ah) || AR_SREV_9340(ah)) {
  156. spur_fbin_ptr = ar9003_get_spur_chan_ptr(ah,
  157. IS_CHAN_2GHZ(chan));
  158. if (spur_fbin_ptr[0] == 0) /* No spur */
  159. return;
  160. max_spur_cnts = 5;
  161. if (IS_CHAN_HT40(chan)) {
  162. range = 19;
  163. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  164. AR_PHY_GC_DYN2040_PRI_CH) == 0)
  165. synth_freq = chan->channel + 10;
  166. else
  167. synth_freq = chan->channel - 10;
  168. } else {
  169. range = 10;
  170. synth_freq = chan->channel;
  171. }
  172. } else {
  173. range = 10;
  174. max_spur_cnts = 4;
  175. synth_freq = chan->channel;
  176. }
  177. for (i = 0; i < max_spur_cnts; i++) {
  178. negative = 0;
  179. if (AR_SREV_9485(ah) || AR_SREV_9340(ah))
  180. cur_bb_spur = FBIN2FREQ(spur_fbin_ptr[i],
  181. IS_CHAN_2GHZ(chan)) - synth_freq;
  182. else
  183. cur_bb_spur = spur_freq[i] - synth_freq;
  184. if (cur_bb_spur < 0) {
  185. negative = 1;
  186. cur_bb_spur = -cur_bb_spur;
  187. }
  188. if (cur_bb_spur < range) {
  189. cck_spur_freq = (int)((cur_bb_spur << 19) / 11);
  190. if (negative == 1)
  191. cck_spur_freq = -cck_spur_freq;
  192. cck_spur_freq = cck_spur_freq & 0xfffff;
  193. REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
  194. AR_PHY_AGC_CONTROL_YCOK_MAX, 0x7);
  195. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  196. AR_PHY_CCK_SPUR_MIT_SPUR_RSSI_THR, 0x7f);
  197. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  198. AR_PHY_CCK_SPUR_MIT_SPUR_FILTER_TYPE,
  199. 0x2);
  200. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  201. AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT,
  202. 0x1);
  203. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  204. AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ,
  205. cck_spur_freq);
  206. return;
  207. }
  208. }
  209. REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
  210. AR_PHY_AGC_CONTROL_YCOK_MAX, 0x5);
  211. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  212. AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT, 0x0);
  213. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  214. AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ, 0x0);
  215. }
  216. /* Clean all spur register fields */
  217. static void ar9003_hw_spur_ofdm_clear(struct ath_hw *ah)
  218. {
  219. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  220. AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0);
  221. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  222. AR_PHY_TIMING11_SPUR_FREQ_SD, 0);
  223. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  224. AR_PHY_TIMING11_SPUR_DELTA_PHASE, 0);
  225. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  226. AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, 0);
  227. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  228. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0);
  229. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  230. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0);
  231. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  232. AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0);
  233. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  234. AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 0);
  235. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  236. AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 0);
  237. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  238. AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0);
  239. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  240. AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0);
  241. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  242. AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0);
  243. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  244. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, 0);
  245. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  246. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, 0);
  247. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  248. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, 0);
  249. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  250. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0);
  251. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  252. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0);
  253. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  254. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0);
  255. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  256. AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0);
  257. }
  258. static void ar9003_hw_spur_ofdm(struct ath_hw *ah,
  259. int freq_offset,
  260. int spur_freq_sd,
  261. int spur_delta_phase,
  262. int spur_subchannel_sd)
  263. {
  264. int mask_index = 0;
  265. /* OFDM Spur mitigation */
  266. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  267. AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0x1);
  268. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  269. AR_PHY_TIMING11_SPUR_FREQ_SD, spur_freq_sd);
  270. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  271. AR_PHY_TIMING11_SPUR_DELTA_PHASE, spur_delta_phase);
  272. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  273. AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, spur_subchannel_sd);
  274. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  275. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0x1);
  276. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  277. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0x1);
  278. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  279. AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0x1);
  280. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  281. AR_PHY_SPUR_REG_SPUR_RSSI_THRESH, 34);
  282. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  283. AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 1);
  284. if (REG_READ_FIELD(ah, AR_PHY_MODE,
  285. AR_PHY_MODE_DYNAMIC) == 0x1)
  286. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  287. AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 1);
  288. mask_index = (freq_offset << 4) / 5;
  289. if (mask_index < 0)
  290. mask_index = mask_index - 1;
  291. mask_index = mask_index & 0x7f;
  292. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  293. AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0x1);
  294. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  295. AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0x1);
  296. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  297. AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0x1);
  298. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  299. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, mask_index);
  300. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  301. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, mask_index);
  302. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  303. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, mask_index);
  304. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  305. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0xc);
  306. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  307. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0xc);
  308. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  309. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0xa0);
  310. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  311. AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0xff);
  312. }
  313. static void ar9003_hw_spur_ofdm_work(struct ath_hw *ah,
  314. struct ath9k_channel *chan,
  315. int freq_offset)
  316. {
  317. int spur_freq_sd = 0;
  318. int spur_subchannel_sd = 0;
  319. int spur_delta_phase = 0;
  320. if (IS_CHAN_HT40(chan)) {
  321. if (freq_offset < 0) {
  322. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  323. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  324. spur_subchannel_sd = 1;
  325. else
  326. spur_subchannel_sd = 0;
  327. spur_freq_sd = ((freq_offset + 10) << 9) / 11;
  328. } else {
  329. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  330. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  331. spur_subchannel_sd = 0;
  332. else
  333. spur_subchannel_sd = 1;
  334. spur_freq_sd = ((freq_offset - 10) << 9) / 11;
  335. }
  336. spur_delta_phase = (freq_offset << 17) / 5;
  337. } else {
  338. spur_subchannel_sd = 0;
  339. spur_freq_sd = (freq_offset << 9) /11;
  340. spur_delta_phase = (freq_offset << 18) / 5;
  341. }
  342. spur_freq_sd = spur_freq_sd & 0x3ff;
  343. spur_delta_phase = spur_delta_phase & 0xfffff;
  344. ar9003_hw_spur_ofdm(ah,
  345. freq_offset,
  346. spur_freq_sd,
  347. spur_delta_phase,
  348. spur_subchannel_sd);
  349. }
  350. /* Spur mitigation for OFDM */
  351. static void ar9003_hw_spur_mitigate_ofdm(struct ath_hw *ah,
  352. struct ath9k_channel *chan)
  353. {
  354. int synth_freq;
  355. int range = 10;
  356. int freq_offset = 0;
  357. int mode;
  358. u8* spurChansPtr;
  359. unsigned int i;
  360. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  361. if (IS_CHAN_5GHZ(chan)) {
  362. spurChansPtr = &(eep->modalHeader5G.spurChans[0]);
  363. mode = 0;
  364. }
  365. else {
  366. spurChansPtr = &(eep->modalHeader2G.spurChans[0]);
  367. mode = 1;
  368. }
  369. if (spurChansPtr[0] == 0)
  370. return; /* No spur in the mode */
  371. if (IS_CHAN_HT40(chan)) {
  372. range = 19;
  373. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  374. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  375. synth_freq = chan->channel - 10;
  376. else
  377. synth_freq = chan->channel + 10;
  378. } else {
  379. range = 10;
  380. synth_freq = chan->channel;
  381. }
  382. ar9003_hw_spur_ofdm_clear(ah);
  383. for (i = 0; i < AR_EEPROM_MODAL_SPURS && spurChansPtr[i]; i++) {
  384. freq_offset = FBIN2FREQ(spurChansPtr[i], mode) - synth_freq;
  385. if (abs(freq_offset) < range) {
  386. ar9003_hw_spur_ofdm_work(ah, chan, freq_offset);
  387. break;
  388. }
  389. }
  390. }
  391. static void ar9003_hw_spur_mitigate(struct ath_hw *ah,
  392. struct ath9k_channel *chan)
  393. {
  394. ar9003_hw_spur_mitigate_mrc_cck(ah, chan);
  395. ar9003_hw_spur_mitigate_ofdm(ah, chan);
  396. }
  397. static u32 ar9003_hw_compute_pll_control(struct ath_hw *ah __unused,
  398. struct ath9k_channel *chan)
  399. {
  400. u32 pll;
  401. pll = SM(0x5, AR_RTC_9300_PLL_REFDIV);
  402. if (chan && IS_CHAN_HALF_RATE(chan))
  403. pll |= SM(0x1, AR_RTC_9300_PLL_CLKSEL);
  404. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  405. pll |= SM(0x2, AR_RTC_9300_PLL_CLKSEL);
  406. pll |= SM(0x2c, AR_RTC_9300_PLL_DIV);
  407. return pll;
  408. }
  409. static void ar9003_hw_set_channel_regs(struct ath_hw *ah,
  410. struct ath9k_channel *chan)
  411. {
  412. u32 phymode;
  413. u32 enableDacFifo = 0;
  414. enableDacFifo =
  415. (REG_READ(ah, AR_PHY_GEN_CTRL) & AR_PHY_GC_ENABLE_DAC_FIFO);
  416. /* Enable 11n HT, 20 MHz */
  417. phymode = AR_PHY_GC_HT_EN | AR_PHY_GC_SINGLE_HT_LTF1 | AR_PHY_GC_WALSH |
  418. AR_PHY_GC_SHORT_GI_40 | enableDacFifo;
  419. /* Configure baseband for dynamic 20/40 operation */
  420. if (IS_CHAN_HT40(chan)) {
  421. phymode |= AR_PHY_GC_DYN2040_EN;
  422. /* Configure control (primary) channel at +-10MHz */
  423. if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
  424. (chan->chanmode == CHANNEL_G_HT40PLUS))
  425. phymode |= AR_PHY_GC_DYN2040_PRI_CH;
  426. }
  427. /* make sure we preserve INI settings */
  428. phymode |= REG_READ(ah, AR_PHY_GEN_CTRL);
  429. /* turn off Green Field detection for STA for now */
  430. phymode &= ~AR_PHY_GC_GF_DETECT_EN;
  431. REG_WRITE(ah, AR_PHY_GEN_CTRL, phymode);
  432. /* Configure MAC for 20/40 operation */
  433. ath9k_hw_set11nmac2040(ah);
  434. /* global transmit timeout (25 TUs default)*/
  435. REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
  436. /* carrier sense timeout */
  437. REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
  438. }
  439. static void ar9003_hw_init_bb(struct ath_hw *ah,
  440. struct ath9k_channel *chan)
  441. {
  442. u32 synthDelay;
  443. /*
  444. * Wait for the frequency synth to settle (synth goes on
  445. * via AR_PHY_ACTIVE_EN). Read the phy active delay register.
  446. * Value is in 100ns increments.
  447. */
  448. synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  449. if (IS_CHAN_B(chan))
  450. synthDelay = (4 * synthDelay) / 22;
  451. else
  452. synthDelay /= 10;
  453. /* Activate the PHY (includes baseband activate + synthesizer on) */
  454. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
  455. /*
  456. * There is an issue if the AP starts the calibration before
  457. * the base band timeout completes. This could result in the
  458. * rx_clear false triggering. As a workaround we add delay an
  459. * extra BASE_ACTIVATE_DELAY usecs to ensure this condition
  460. * does not happen.
  461. */
  462. udelay(synthDelay + BASE_ACTIVATE_DELAY);
  463. }
  464. void ar9003_hw_set_chain_masks(struct ath_hw *ah, u8 rx, u8 tx)
  465. {
  466. switch (rx) {
  467. case 0x5:
  468. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  469. AR_PHY_SWAP_ALT_CHAIN);
  470. case 0x3:
  471. case 0x1:
  472. case 0x2:
  473. case 0x7:
  474. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx);
  475. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx);
  476. break;
  477. default:
  478. break;
  479. }
  480. if ((ah->caps.hw_caps & ATH9K_HW_CAP_APM) && (tx == 0x7))
  481. REG_WRITE(ah, AR_SELFGEN_MASK, 0x3);
  482. else
  483. REG_WRITE(ah, AR_SELFGEN_MASK, tx);
  484. if (tx == 0x5) {
  485. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  486. AR_PHY_SWAP_ALT_CHAIN);
  487. }
  488. }
  489. /*
  490. * Override INI values with chip specific configuration.
  491. */
  492. static void ar9003_hw_override_ini(struct ath_hw *ah)
  493. {
  494. u32 val;
  495. /*
  496. * Set the RX_ABORT and RX_DIS and clear it only after
  497. * RXE is set for MAC. This prevents frames with
  498. * corrupted descriptor status.
  499. */
  500. REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  501. /*
  502. * For AR9280 and above, there is a new feature that allows
  503. * Multicast search based on both MAC Address and Key ID. By default,
  504. * this feature is enabled. But since the driver is not using this
  505. * feature, we switch it off; otherwise multicast search based on
  506. * MAC addr only will fail.
  507. */
  508. val = REG_READ(ah, AR_PCU_MISC_MODE2) & (~AR_ADHOC_MCAST_KEYID_ENABLE);
  509. REG_WRITE(ah, AR_PCU_MISC_MODE2,
  510. val | AR_AGG_WEP_ENABLE_FIX | AR_AGG_WEP_ENABLE);
  511. }
  512. static void ar9003_hw_prog_ini(struct ath_hw *ah,
  513. struct ar5416IniArray *iniArr,
  514. int column)
  515. {
  516. unsigned int i, regWrites = 0;
  517. /* New INI format: Array may be undefined (pre, core, post arrays) */
  518. if (!iniArr->ia_array)
  519. return;
  520. /*
  521. * New INI format: Pre, core, and post arrays for a given subsystem
  522. * may be modal (> 2 columns) or non-modal (2 columns). Determine if
  523. * the array is non-modal and force the column to 1.
  524. */
  525. if ((unsigned int)column >= iniArr->ia_columns)
  526. column = 1;
  527. for (i = 0; i < iniArr->ia_rows; i++) {
  528. u32 reg = INI_RA(iniArr, i, 0);
  529. u32 val = INI_RA(iniArr, i, column);
  530. REG_WRITE(ah, reg, val);
  531. DO_DELAY(regWrites);
  532. }
  533. }
  534. static int ar9003_hw_process_ini(struct ath_hw *ah,
  535. struct ath9k_channel *chan)
  536. {
  537. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  538. unsigned int regWrites = 0, i;
  539. struct net80211_channel *channel = chan->chan;
  540. u32 modesIndex;
  541. switch (chan->chanmode) {
  542. case CHANNEL_A:
  543. case CHANNEL_A_HT20:
  544. modesIndex = 1;
  545. break;
  546. case CHANNEL_A_HT40PLUS:
  547. case CHANNEL_A_HT40MINUS:
  548. modesIndex = 2;
  549. break;
  550. case CHANNEL_G:
  551. case CHANNEL_G_HT20:
  552. case CHANNEL_B:
  553. modesIndex = 4;
  554. break;
  555. case CHANNEL_G_HT40PLUS:
  556. case CHANNEL_G_HT40MINUS:
  557. modesIndex = 3;
  558. break;
  559. default:
  560. return -EINVAL;
  561. }
  562. for (i = 0; i < ATH_INI_NUM_SPLIT; i++) {
  563. ar9003_hw_prog_ini(ah, &ah->iniSOC[i], modesIndex);
  564. ar9003_hw_prog_ini(ah, &ah->iniMac[i], modesIndex);
  565. ar9003_hw_prog_ini(ah, &ah->iniBB[i], modesIndex);
  566. ar9003_hw_prog_ini(ah, &ah->iniRadio[i], modesIndex);
  567. }
  568. REG_WRITE_ARRAY(&ah->iniModesRxGain, 1, regWrites);
  569. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  570. /*
  571. * For 5GHz channels requiring Fast Clock, apply
  572. * different modal values.
  573. */
  574. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  575. REG_WRITE_ARRAY(&ah->iniModesAdditional,
  576. modesIndex, regWrites);
  577. if (AR_SREV_9340(ah) && !ah->is_clk_25mhz)
  578. REG_WRITE_ARRAY(&ah->iniModesAdditional_40M, 1, regWrites);
  579. ar9003_hw_override_ini(ah);
  580. ar9003_hw_set_channel_regs(ah, chan);
  581. ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
  582. /* Set TX power */
  583. ah->eep_ops->set_txpower(ah, chan,
  584. ath9k_regd_get_ctl(regulatory, chan),
  585. 0,
  586. channel->maxpower * 2,
  587. min((u32) MAX_RATE_POWER,
  588. (u32) regulatory->power_limit), 0);
  589. return 0;
  590. }
  591. static void ar9003_hw_set_rfmode(struct ath_hw *ah,
  592. struct ath9k_channel *chan)
  593. {
  594. u32 rfMode = 0;
  595. if (chan == NULL)
  596. return;
  597. rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
  598. ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
  599. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  600. rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
  601. REG_WRITE(ah, AR_PHY_MODE, rfMode);
  602. }
  603. static void ar9003_hw_mark_phy_inactive(struct ath_hw *ah)
  604. {
  605. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
  606. }
  607. static void ar9003_hw_set_delta_slope(struct ath_hw *ah,
  608. struct ath9k_channel *chan)
  609. {
  610. u32 coef_scaled, ds_coef_exp, ds_coef_man;
  611. u32 clockMhzScaled = 0x64000000;
  612. struct chan_centers centers;
  613. /*
  614. * half and quarter rate can divide the scaled clock by 2 or 4
  615. * scale for selected channel bandwidth
  616. */
  617. if (IS_CHAN_HALF_RATE(chan))
  618. clockMhzScaled = clockMhzScaled >> 1;
  619. else if (IS_CHAN_QUARTER_RATE(chan))
  620. clockMhzScaled = clockMhzScaled >> 2;
  621. /*
  622. * ALGO -> coef = 1e8/fcarrier*fclock/40;
  623. * scaled coef to provide precision for this floating calculation
  624. */
  625. ath9k_hw_get_channel_centers(ah, chan, &centers);
  626. coef_scaled = clockMhzScaled / centers.synth_center;
  627. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  628. &ds_coef_exp);
  629. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  630. AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
  631. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  632. AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
  633. /*
  634. * For Short GI,
  635. * scaled coeff is 9/10 that of normal coeff
  636. */
  637. coef_scaled = (9 * coef_scaled) / 10;
  638. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  639. &ds_coef_exp);
  640. /* for short gi */
  641. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  642. AR_PHY_SGI_DSC_MAN, ds_coef_man);
  643. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  644. AR_PHY_SGI_DSC_EXP, ds_coef_exp);
  645. }
  646. static int ar9003_hw_rfbus_req(struct ath_hw *ah)
  647. {
  648. REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
  649. return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
  650. AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT);
  651. }
  652. /*
  653. * Wait for the frequency synth to settle (synth goes on via PHY_ACTIVE_EN).
  654. * Read the phy active delay register. Value is in 100ns increments.
  655. */
  656. static void ar9003_hw_rfbus_done(struct ath_hw *ah)
  657. {
  658. u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  659. if (IS_CHAN_B(ah->curchan))
  660. synthDelay = (4 * synthDelay) / 22;
  661. else
  662. synthDelay /= 10;
  663. udelay(synthDelay + BASE_ACTIVATE_DELAY);
  664. REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
  665. }
  666. static void ar9003_hw_set_diversity(struct ath_hw *ah, int value)
  667. {
  668. u32 v = REG_READ(ah, AR_PHY_CCK_DETECT);
  669. if (value)
  670. v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
  671. else
  672. v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
  673. REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
  674. }
  675. static int ar9003_hw_ani_control(struct ath_hw *ah,
  676. enum ath9k_ani_cmd cmd, int param)
  677. {
  678. struct ath9k_channel *chan = ah->curchan;
  679. struct ar5416AniState *aniState = &chan->ani;
  680. s32 value, value2;
  681. switch (cmd & ah->ani_function) {
  682. case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
  683. /*
  684. * on == 1 means ofdm weak signal detection is ON
  685. * on == 1 is the default, for less noise immunity
  686. *
  687. * on == 0 means ofdm weak signal detection is OFF
  688. * on == 0 means more noise imm
  689. */
  690. u32 on = param ? 1 : 0;
  691. /*
  692. * make register setting for default
  693. * (weak sig detect ON) come from INI file
  694. */
  695. int m1ThreshLow = on ?
  696. aniState->iniDef.m1ThreshLow : m1ThreshLow_off;
  697. int m2ThreshLow = on ?
  698. aniState->iniDef.m2ThreshLow : m2ThreshLow_off;
  699. int m1Thresh = on ?
  700. aniState->iniDef.m1Thresh : m1Thresh_off;
  701. int m2Thresh = on ?
  702. aniState->iniDef.m2Thresh : m2Thresh_off;
  703. int m2CountThr = on ?
  704. aniState->iniDef.m2CountThr : m2CountThr_off;
  705. int m2CountThrLow = on ?
  706. aniState->iniDef.m2CountThrLow : m2CountThrLow_off;
  707. int m1ThreshLowExt = on ?
  708. aniState->iniDef.m1ThreshLowExt : m1ThreshLowExt_off;
  709. int m2ThreshLowExt = on ?
  710. aniState->iniDef.m2ThreshLowExt : m2ThreshLowExt_off;
  711. int m1ThreshExt = on ?
  712. aniState->iniDef.m1ThreshExt : m1ThreshExt_off;
  713. int m2ThreshExt = on ?
  714. aniState->iniDef.m2ThreshExt : m2ThreshExt_off;
  715. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  716. AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
  717. m1ThreshLow);
  718. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  719. AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
  720. m2ThreshLow);
  721. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  722. AR_PHY_SFCORR_M1_THRESH, m1Thresh);
  723. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  724. AR_PHY_SFCORR_M2_THRESH, m2Thresh);
  725. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  726. AR_PHY_SFCORR_M2COUNT_THR, m2CountThr);
  727. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  728. AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
  729. m2CountThrLow);
  730. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  731. AR_PHY_SFCORR_EXT_M1_THRESH_LOW, m1ThreshLowExt);
  732. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  733. AR_PHY_SFCORR_EXT_M2_THRESH_LOW, m2ThreshLowExt);
  734. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  735. AR_PHY_SFCORR_EXT_M1_THRESH, m1ThreshExt);
  736. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  737. AR_PHY_SFCORR_EXT_M2_THRESH, m2ThreshExt);
  738. if (on)
  739. REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
  740. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  741. else
  742. REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
  743. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  744. if (!on != aniState->ofdmWeakSigDetectOff) {
  745. DBG2("ath9k: "
  746. "** ch %d: ofdm weak signal: %s=>%s\n",
  747. chan->channel,
  748. !aniState->ofdmWeakSigDetectOff ?
  749. "on" : "off",
  750. on ? "on" : "off");
  751. if (on)
  752. ah->stats.ast_ani_ofdmon++;
  753. else
  754. ah->stats.ast_ani_ofdmoff++;
  755. aniState->ofdmWeakSigDetectOff = !on;
  756. }
  757. break;
  758. }
  759. case ATH9K_ANI_FIRSTEP_LEVEL:{
  760. u32 level = param;
  761. if (level >= ARRAY_SIZE(firstep_table)) {
  762. DBG("ath9k: "
  763. "ATH9K_ANI_FIRSTEP_LEVEL: level out of range (%d > %zd)\n",
  764. level, ARRAY_SIZE(firstep_table));
  765. return 0;
  766. }
  767. /*
  768. * make register setting relative to default
  769. * from INI file & cap value
  770. */
  771. value = firstep_table[level] -
  772. firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
  773. aniState->iniDef.firstep;
  774. if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  775. value = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  776. if (value > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  777. value = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  778. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  779. AR_PHY_FIND_SIG_FIRSTEP,
  780. value);
  781. /*
  782. * we need to set first step low register too
  783. * make register setting relative to default
  784. * from INI file & cap value
  785. */
  786. value2 = firstep_table[level] -
  787. firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
  788. aniState->iniDef.firstepLow;
  789. if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  790. value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  791. if (value2 > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  792. value2 = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  793. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
  794. AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW, value2);
  795. if (level != aniState->firstepLevel) {
  796. DBG2("ath9k: "
  797. "** ch %d: level %d=>%d[def:%d] firstep[level]=%d ini=%d\n",
  798. chan->channel,
  799. aniState->firstepLevel,
  800. level,
  801. ATH9K_ANI_FIRSTEP_LVL_NEW,
  802. value,
  803. aniState->iniDef.firstep);
  804. DBG2("ath9k: "
  805. "** ch %d: level %d=>%d[def:%d] firstep_low[level]=%d ini=%d\n",
  806. chan->channel,
  807. aniState->firstepLevel,
  808. level,
  809. ATH9K_ANI_FIRSTEP_LVL_NEW,
  810. value2,
  811. aniState->iniDef.firstepLow);
  812. if (level > aniState->firstepLevel)
  813. ah->stats.ast_ani_stepup++;
  814. else if (level < aniState->firstepLevel)
  815. ah->stats.ast_ani_stepdown++;
  816. aniState->firstepLevel = level;
  817. }
  818. break;
  819. }
  820. case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
  821. u32 level = param;
  822. if (level >= ARRAY_SIZE(cycpwrThr1_table)) {
  823. DBG("ath9k: "
  824. "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level out of range (%d > %zd)\n",
  825. level, ARRAY_SIZE(cycpwrThr1_table));
  826. return 0;
  827. }
  828. /*
  829. * make register setting relative to default
  830. * from INI file & cap value
  831. */
  832. value = cycpwrThr1_table[level] -
  833. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
  834. aniState->iniDef.cycpwrThr1;
  835. if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  836. value = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  837. if (value > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  838. value = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  839. REG_RMW_FIELD(ah, AR_PHY_TIMING5,
  840. AR_PHY_TIMING5_CYCPWR_THR1,
  841. value);
  842. /*
  843. * set AR_PHY_EXT_CCA for extension channel
  844. * make register setting relative to default
  845. * from INI file & cap value
  846. */
  847. value2 = cycpwrThr1_table[level] -
  848. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
  849. aniState->iniDef.cycpwrThr1Ext;
  850. if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  851. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  852. if (value2 > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  853. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  854. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
  855. AR_PHY_EXT_CYCPWR_THR1, value2);
  856. if (level != aniState->spurImmunityLevel) {
  857. DBG2("ath9k: "
  858. "** ch %d: level %d=>%d[def:%d] cycpwrThr1[level]=%d ini=%d\n",
  859. chan->channel,
  860. aniState->spurImmunityLevel,
  861. level,
  862. ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
  863. value,
  864. aniState->iniDef.cycpwrThr1);
  865. DBG2("ath9k: "
  866. "** ch %d: level %d=>%d[def:%d] cycpwrThr1Ext[level]=%d ini=%d\n",
  867. chan->channel,
  868. aniState->spurImmunityLevel,
  869. level,
  870. ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
  871. value2,
  872. aniState->iniDef.cycpwrThr1Ext);
  873. if (level > aniState->spurImmunityLevel)
  874. ah->stats.ast_ani_spurup++;
  875. else if (level < aniState->spurImmunityLevel)
  876. ah->stats.ast_ani_spurdown++;
  877. aniState->spurImmunityLevel = level;
  878. }
  879. break;
  880. }
  881. case ATH9K_ANI_MRC_CCK:{
  882. /*
  883. * is_on == 1 means MRC CCK ON (default, less noise imm)
  884. * is_on == 0 means MRC CCK is OFF (more noise imm)
  885. */
  886. int is_on = param ? 1 : 0;
  887. REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
  888. AR_PHY_MRC_CCK_ENABLE, is_on);
  889. REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
  890. AR_PHY_MRC_CCK_MUX_REG, is_on);
  891. if (!is_on != aniState->mrcCCKOff) {
  892. DBG2("ath9k: "
  893. "** ch %d: MRC CCK: %s=>%s\n",
  894. chan->channel,
  895. !aniState->mrcCCKOff ? "on" : "off",
  896. is_on ? "on" : "off");
  897. if (is_on)
  898. ah->stats.ast_ani_ccklow++;
  899. else
  900. ah->stats.ast_ani_cckhigh++;
  901. aniState->mrcCCKOff = !is_on;
  902. }
  903. break;
  904. }
  905. case ATH9K_ANI_PRESENT:
  906. break;
  907. default:
  908. DBG2("ath9k: invalid cmd %d\n", cmd);
  909. return 0;
  910. }
  911. DBG2("ath9k: "
  912. "ANI parameters: SI=%d, ofdmWS=%s FS=%d MRCcck=%s listenTime=%d ofdmErrs=%d cckErrs=%d\n",
  913. aniState->spurImmunityLevel,
  914. !aniState->ofdmWeakSigDetectOff ? "on" : "off",
  915. aniState->firstepLevel,
  916. !aniState->mrcCCKOff ? "on" : "off",
  917. aniState->listenTime,
  918. aniState->ofdmPhyErrCount,
  919. aniState->cckPhyErrCount);
  920. return 1;
  921. }
  922. static void ar9003_hw_do_getnf(struct ath_hw *ah,
  923. int16_t nfarray[NUM_NF_READINGS])
  924. {
  925. #define AR_PHY_CH_MINCCA_PWR 0x1FF00000
  926. #define AR_PHY_CH_MINCCA_PWR_S 20
  927. #define AR_PHY_CH_EXT_MINCCA_PWR 0x01FF0000
  928. #define AR_PHY_CH_EXT_MINCCA_PWR_S 16
  929. int16_t nf;
  930. int i;
  931. for (i = 0; i < AR9300_MAX_CHAINS; i++) {
  932. if (ah->rxchainmask & BIT(i)) {
  933. nf = MS(REG_READ(ah, ah->nf_regs[i]),
  934. AR_PHY_CH_MINCCA_PWR);
  935. nfarray[i] = sign_extend32(nf, 8);
  936. if (IS_CHAN_HT40(ah->curchan)) {
  937. u8 ext_idx = AR9300_MAX_CHAINS + i;
  938. nf = MS(REG_READ(ah, ah->nf_regs[ext_idx]),
  939. AR_PHY_CH_EXT_MINCCA_PWR);
  940. nfarray[ext_idx] = sign_extend32(nf, 8);
  941. }
  942. }
  943. }
  944. }
  945. static void ar9003_hw_set_nf_limits(struct ath_hw *ah)
  946. {
  947. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_2GHZ;
  948. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_2GHZ;
  949. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9300_2GHZ;
  950. ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_5GHZ;
  951. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_5GHZ;
  952. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9300_5GHZ;
  953. }
  954. /*
  955. * Initialize the ANI register values with default (ini) values.
  956. * This routine is called during a (full) hardware reset after
  957. * all the registers are initialised from the INI.
  958. */
  959. static void ar9003_hw_ani_cache_ini_regs(struct ath_hw *ah)
  960. {
  961. struct ar5416AniState *aniState;
  962. struct ath9k_channel *chan = ah->curchan;
  963. struct ath9k_ani_default *iniDef;
  964. u32 val;
  965. aniState = &ah->curchan->ani;
  966. iniDef = &aniState->iniDef;
  967. DBG2("ath9k: "
  968. "ver %d.%d chan %d Mhz/0x%x\n",
  969. ah->hw_version.macVersion,
  970. ah->hw_version.macRev,
  971. chan->channel,
  972. chan->channelFlags);
  973. val = REG_READ(ah, AR_PHY_SFCORR);
  974. iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH);
  975. iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH);
  976. iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR);
  977. val = REG_READ(ah, AR_PHY_SFCORR_LOW);
  978. iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW);
  979. iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW);
  980. iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW);
  981. val = REG_READ(ah, AR_PHY_SFCORR_EXT);
  982. iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH);
  983. iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH);
  984. iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW);
  985. iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW);
  986. iniDef->firstep = REG_READ_FIELD(ah,
  987. AR_PHY_FIND_SIG,
  988. AR_PHY_FIND_SIG_FIRSTEP);
  989. iniDef->firstepLow = REG_READ_FIELD(ah,
  990. AR_PHY_FIND_SIG_LOW,
  991. AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW);
  992. iniDef->cycpwrThr1 = REG_READ_FIELD(ah,
  993. AR_PHY_TIMING5,
  994. AR_PHY_TIMING5_CYCPWR_THR1);
  995. iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah,
  996. AR_PHY_EXT_CCA,
  997. AR_PHY_EXT_CYCPWR_THR1);
  998. /* these levels just got reset to defaults by the INI */
  999. aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL_NEW;
  1000. aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL_NEW;
  1001. aniState->ofdmWeakSigDetectOff = !ATH9K_ANI_USE_OFDM_WEAK_SIG;
  1002. aniState->mrcCCKOff = !ATH9K_ANI_ENABLE_MRC_CCK;
  1003. }
  1004. static void ar9003_hw_set_radar_params(struct ath_hw *ah,
  1005. struct ath_hw_radar_conf *conf)
  1006. {
  1007. u32 radar_0 = 0, radar_1 = 0;
  1008. if (!conf) {
  1009. REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA);
  1010. return;
  1011. }
  1012. radar_0 |= AR_PHY_RADAR_0_ENA | AR_PHY_RADAR_0_FFT_ENA;
  1013. radar_0 |= SM(conf->fir_power, AR_PHY_RADAR_0_FIRPWR);
  1014. radar_0 |= SM(conf->radar_rssi, AR_PHY_RADAR_0_RRSSI);
  1015. radar_0 |= SM(conf->pulse_height, AR_PHY_RADAR_0_HEIGHT);
  1016. radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI);
  1017. radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND);
  1018. radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI;
  1019. radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK;
  1020. radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN);
  1021. radar_1 |= SM(conf->pulse_inband_step, AR_PHY_RADAR_1_RELSTEP_THRESH);
  1022. radar_1 |= SM(conf->radar_inband, AR_PHY_RADAR_1_RELPWR_THRESH);
  1023. REG_WRITE(ah, AR_PHY_RADAR_0, radar_0);
  1024. REG_WRITE(ah, AR_PHY_RADAR_1, radar_1);
  1025. if (conf->ext_channel)
  1026. REG_SET_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1027. else
  1028. REG_CLR_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1029. }
  1030. static void ar9003_hw_set_radar_conf(struct ath_hw *ah)
  1031. {
  1032. struct ath_hw_radar_conf *conf = &ah->radar_conf;
  1033. conf->fir_power = -28;
  1034. conf->radar_rssi = 0;
  1035. conf->pulse_height = 10;
  1036. conf->pulse_rssi = 24;
  1037. conf->pulse_inband = 8;
  1038. conf->pulse_maxlen = 255;
  1039. conf->pulse_inband_step = 12;
  1040. conf->radar_inband = 8;
  1041. }
  1042. static void ar9003_hw_antdiv_comb_conf_get(struct ath_hw *ah,
  1043. struct ath_hw_antcomb_conf *antconf)
  1044. {
  1045. u32 regval;
  1046. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1047. antconf->main_lna_conf = (regval & AR_PHY_9485_ANT_DIV_MAIN_LNACONF) >>
  1048. AR_PHY_9485_ANT_DIV_MAIN_LNACONF_S;
  1049. antconf->alt_lna_conf = (regval & AR_PHY_9485_ANT_DIV_ALT_LNACONF) >>
  1050. AR_PHY_9485_ANT_DIV_ALT_LNACONF_S;
  1051. antconf->fast_div_bias = (regval & AR_PHY_9485_ANT_FAST_DIV_BIAS) >>
  1052. AR_PHY_9485_ANT_FAST_DIV_BIAS_S;
  1053. antconf->lna1_lna2_delta = -9;
  1054. antconf->div_group = 2;
  1055. }
  1056. static void ar9003_hw_antdiv_comb_conf_set(struct ath_hw *ah,
  1057. struct ath_hw_antcomb_conf *antconf)
  1058. {
  1059. u32 regval;
  1060. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1061. regval &= ~(AR_PHY_9485_ANT_DIV_MAIN_LNACONF |
  1062. AR_PHY_9485_ANT_DIV_ALT_LNACONF |
  1063. AR_PHY_9485_ANT_FAST_DIV_BIAS |
  1064. AR_PHY_9485_ANT_DIV_MAIN_GAINTB |
  1065. AR_PHY_9485_ANT_DIV_ALT_GAINTB);
  1066. regval |= ((antconf->main_lna_conf <<
  1067. AR_PHY_9485_ANT_DIV_MAIN_LNACONF_S)
  1068. & AR_PHY_9485_ANT_DIV_MAIN_LNACONF);
  1069. regval |= ((antconf->alt_lna_conf << AR_PHY_9485_ANT_DIV_ALT_LNACONF_S)
  1070. & AR_PHY_9485_ANT_DIV_ALT_LNACONF);
  1071. regval |= ((antconf->fast_div_bias << AR_PHY_9485_ANT_FAST_DIV_BIAS_S)
  1072. & AR_PHY_9485_ANT_FAST_DIV_BIAS);
  1073. regval |= ((antconf->main_gaintb << AR_PHY_9485_ANT_DIV_MAIN_GAINTB_S)
  1074. & AR_PHY_9485_ANT_DIV_MAIN_GAINTB);
  1075. regval |= ((antconf->alt_gaintb << AR_PHY_9485_ANT_DIV_ALT_GAINTB_S)
  1076. & AR_PHY_9485_ANT_DIV_ALT_GAINTB);
  1077. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1078. }
  1079. void ar9003_hw_attach_phy_ops(struct ath_hw *ah)
  1080. {
  1081. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  1082. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  1083. static const u32 ar9300_cca_regs[6] = {
  1084. AR_PHY_CCA_0,
  1085. AR_PHY_CCA_1,
  1086. AR_PHY_CCA_2,
  1087. AR_PHY_EXT_CCA,
  1088. AR_PHY_EXT_CCA_1,
  1089. AR_PHY_EXT_CCA_2,
  1090. };
  1091. priv_ops->rf_set_freq = ar9003_hw_set_channel;
  1092. priv_ops->spur_mitigate_freq = ar9003_hw_spur_mitigate;
  1093. priv_ops->compute_pll_control = ar9003_hw_compute_pll_control;
  1094. priv_ops->set_channel_regs = ar9003_hw_set_channel_regs;
  1095. priv_ops->init_bb = ar9003_hw_init_bb;
  1096. priv_ops->process_ini = ar9003_hw_process_ini;
  1097. priv_ops->set_rfmode = ar9003_hw_set_rfmode;
  1098. priv_ops->mark_phy_inactive = ar9003_hw_mark_phy_inactive;
  1099. priv_ops->set_delta_slope = ar9003_hw_set_delta_slope;
  1100. priv_ops->rfbus_req = ar9003_hw_rfbus_req;
  1101. priv_ops->rfbus_done = ar9003_hw_rfbus_done;
  1102. priv_ops->set_diversity = ar9003_hw_set_diversity;
  1103. priv_ops->ani_control = ar9003_hw_ani_control;
  1104. priv_ops->do_getnf = ar9003_hw_do_getnf;
  1105. priv_ops->ani_cache_ini_regs = ar9003_hw_ani_cache_ini_regs;
  1106. priv_ops->set_radar_params = ar9003_hw_set_radar_params;
  1107. ops->antdiv_comb_conf_get = ar9003_hw_antdiv_comb_conf_get;
  1108. ops->antdiv_comb_conf_set = ar9003_hw_antdiv_comb_conf_set;
  1109. ar9003_hw_set_nf_limits(ah);
  1110. ar9003_hw_set_radar_conf(ah);
  1111. memcpy(ah->nf_regs, ar9300_cca_regs, sizeof(ah->nf_regs));
  1112. }
  1113. void ar9003_hw_disable_phy_restart(struct ath_hw *ah)
  1114. {
  1115. u32 val;
  1116. val = REG_READ(ah, AR_PHY_RESTART);
  1117. val &= ~AR_PHY_RESTART_ENA;
  1118. REG_WRITE(ah, AR_PHY_RESTART, val);
  1119. }