ar9003_phy.c 40 KB

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