ar9003_phy.c 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014
  1. /*
  2. * Copyright (c) 2010-2011 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/export.h>
  17. #include "hw.h"
  18. #include "ar9003_phy.h"
  19. static const int firstep_table[] =
  20. /* level: 0 1 2 3 4 5 6 7 8 */
  21. { -4, -2, 0, 2, 4, 6, 8, 10, 12 }; /* lvl 0-8, default 2 */
  22. static const int cycpwrThr1_table[] =
  23. /* level: 0 1 2 3 4 5 6 7 8 */
  24. { -6, -4, -2, 0, 2, 4, 6, 8 }; /* lvl 0-7, default 3 */
  25. /*
  26. * register values to turn OFDM weak signal detection OFF
  27. */
  28. static const int m1ThreshLow_off = 127;
  29. static const int m2ThreshLow_off = 127;
  30. static const int m1Thresh_off = 127;
  31. static const int m2Thresh_off = 127;
  32. static const int m2CountThr_off = 31;
  33. static const int m2CountThrLow_off = 63;
  34. static const int m1ThreshLowExt_off = 127;
  35. static const int m2ThreshLowExt_off = 127;
  36. static const int m1ThreshExt_off = 127;
  37. static const int m2ThreshExt_off = 127;
  38. /**
  39. * ar9003_hw_set_channel - set channel on single-chip device
  40. * @ah: atheros hardware structure
  41. * @chan:
  42. *
  43. * This is the function to change channel on single-chip devices, that is
  44. * for AR9300 family of chipsets.
  45. *
  46. * This function takes the channel value in MHz and sets
  47. * hardware channel value. Assumes writes have been enabled to analog bus.
  48. *
  49. * Actual Expression,
  50. *
  51. * For 2GHz channel,
  52. * Channel Frequency = (3/4) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
  53. * (freq_ref = 40MHz)
  54. *
  55. * For 5GHz channel,
  56. * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^10)
  57. * (freq_ref = 40MHz/(24>>amodeRefSel))
  58. *
  59. * For 5GHz channels which are 5MHz spaced,
  60. * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
  61. * (freq_ref = 40MHz)
  62. */
  63. static int ar9003_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
  64. {
  65. u16 bMode, fracMode = 0, aModeRefSel = 0;
  66. u32 freq, chan_frac, div, channelSel = 0, reg32 = 0;
  67. struct chan_centers centers;
  68. int loadSynthChannel;
  69. ath9k_hw_get_channel_centers(ah, chan, &centers);
  70. freq = centers.synth_center;
  71. if (freq < 4800) { /* 2 GHz, fractional mode */
  72. if (AR_SREV_9330(ah)) {
  73. if (ah->is_clk_25mhz)
  74. div = 75;
  75. else
  76. div = 120;
  77. channelSel = (freq * 4) / div;
  78. chan_frac = (((freq * 4) % div) * 0x20000) / div;
  79. channelSel = (channelSel << 17) | chan_frac;
  80. } else if (AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
  81. /*
  82. * freq_ref = 40 / (refdiva >> amoderefsel);
  83. * where refdiva=1 and amoderefsel=0
  84. * ndiv = ((chan_mhz * 4) / 3) / freq_ref;
  85. * chansel = int(ndiv), chanfrac = (ndiv - chansel) * 0x20000
  86. */
  87. channelSel = (freq * 4) / 120;
  88. chan_frac = (((freq * 4) % 120) * 0x20000) / 120;
  89. channelSel = (channelSel << 17) | chan_frac;
  90. } else if (AR_SREV_9340(ah)) {
  91. if (ah->is_clk_25mhz) {
  92. channelSel = (freq * 2) / 75;
  93. chan_frac = (((freq * 2) % 75) * 0x20000) / 75;
  94. channelSel = (channelSel << 17) | chan_frac;
  95. } else {
  96. channelSel = CHANSEL_2G(freq) >> 1;
  97. }
  98. } else if (AR_SREV_9550(ah) || AR_SREV_9531(ah)) {
  99. if (ah->is_clk_25mhz)
  100. div = 75;
  101. else
  102. div = 120;
  103. channelSel = (freq * 4) / div;
  104. chan_frac = (((freq * 4) % div) * 0x20000) / div;
  105. channelSel = (channelSel << 17) | chan_frac;
  106. } else {
  107. channelSel = CHANSEL_2G(freq);
  108. }
  109. /* Set to 2G mode */
  110. bMode = 1;
  111. } else {
  112. if ((AR_SREV_9340(ah) || AR_SREV_9550(ah) || AR_SREV_9531(ah)) &&
  113. ah->is_clk_25mhz) {
  114. channelSel = freq / 75;
  115. chan_frac = ((freq % 75) * 0x20000) / 75;
  116. channelSel = (channelSel << 17) | chan_frac;
  117. } else {
  118. channelSel = CHANSEL_5G(freq);
  119. /* Doubler is ON, so, divide channelSel by 2. */
  120. channelSel >>= 1;
  121. }
  122. /* Set to 5G mode */
  123. bMode = 0;
  124. }
  125. /* Enable fractional mode for all channels */
  126. fracMode = 1;
  127. aModeRefSel = 0;
  128. loadSynthChannel = 0;
  129. reg32 = (bMode << 29);
  130. REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
  131. /* Enable Long shift Select for Synthesizer */
  132. REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_SYNTH4,
  133. AR_PHY_SYNTH4_LONG_SHIFT_SELECT, 1);
  134. /* Program Synth. setting */
  135. reg32 = (channelSel << 2) | (fracMode << 30) |
  136. (aModeRefSel << 28) | (loadSynthChannel << 31);
  137. REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
  138. /* Toggle Load Synth channel bit */
  139. loadSynthChannel = 1;
  140. reg32 = (channelSel << 2) | (fracMode << 30) |
  141. (aModeRefSel << 28) | (loadSynthChannel << 31);
  142. REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
  143. ah->curchan = chan;
  144. return 0;
  145. }
  146. /**
  147. * ar9003_hw_spur_mitigate_mrc_cck - convert baseband spur frequency
  148. * @ah: atheros hardware structure
  149. * @chan:
  150. *
  151. * For single-chip solutions. Converts to baseband spur frequency given the
  152. * input channel frequency and compute register settings below.
  153. *
  154. * Spur mitigation for MRC CCK
  155. */
  156. static void ar9003_hw_spur_mitigate_mrc_cck(struct ath_hw *ah,
  157. struct ath9k_channel *chan)
  158. {
  159. static const u32 spur_freq[4] = { 2420, 2440, 2464, 2480 };
  160. int cur_bb_spur, negative = 0, cck_spur_freq;
  161. int i;
  162. int range, max_spur_cnts, synth_freq;
  163. u8 *spur_fbin_ptr = ar9003_get_spur_chan_ptr(ah, IS_CHAN_2GHZ(chan));
  164. /*
  165. * Need to verify range +/- 10 MHz in control channel, otherwise spur
  166. * is out-of-band and can be ignored.
  167. */
  168. if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah) ||
  169. AR_SREV_9550(ah)) {
  170. if (spur_fbin_ptr[0] == 0) /* No spur */
  171. return;
  172. max_spur_cnts = 5;
  173. if (IS_CHAN_HT40(chan)) {
  174. range = 19;
  175. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  176. AR_PHY_GC_DYN2040_PRI_CH) == 0)
  177. synth_freq = chan->channel + 10;
  178. else
  179. synth_freq = chan->channel - 10;
  180. } else {
  181. range = 10;
  182. synth_freq = chan->channel;
  183. }
  184. } else {
  185. range = AR_SREV_9462(ah) ? 5 : 10;
  186. max_spur_cnts = 4;
  187. synth_freq = chan->channel;
  188. }
  189. for (i = 0; i < max_spur_cnts; i++) {
  190. if (AR_SREV_9462(ah) && (i == 0 || i == 3))
  191. continue;
  192. negative = 0;
  193. if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah) ||
  194. AR_SREV_9550(ah))
  195. cur_bb_spur = ath9k_hw_fbin2freq(spur_fbin_ptr[i],
  196. IS_CHAN_2GHZ(chan));
  197. else
  198. cur_bb_spur = spur_freq[i];
  199. cur_bb_spur -= synth_freq;
  200. if (cur_bb_spur < 0) {
  201. negative = 1;
  202. cur_bb_spur = -cur_bb_spur;
  203. }
  204. if (cur_bb_spur < range) {
  205. cck_spur_freq = (int)((cur_bb_spur << 19) / 11);
  206. if (negative == 1)
  207. cck_spur_freq = -cck_spur_freq;
  208. cck_spur_freq = cck_spur_freq & 0xfffff;
  209. REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
  210. AR_PHY_AGC_CONTROL_YCOK_MAX, 0x7);
  211. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  212. AR_PHY_CCK_SPUR_MIT_SPUR_RSSI_THR, 0x7f);
  213. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  214. AR_PHY_CCK_SPUR_MIT_SPUR_FILTER_TYPE,
  215. 0x2);
  216. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  217. AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT,
  218. 0x1);
  219. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  220. AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ,
  221. cck_spur_freq);
  222. return;
  223. }
  224. }
  225. REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
  226. AR_PHY_AGC_CONTROL_YCOK_MAX, 0x5);
  227. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  228. AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT, 0x0);
  229. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  230. AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ, 0x0);
  231. }
  232. /* Clean all spur register fields */
  233. static void ar9003_hw_spur_ofdm_clear(struct ath_hw *ah)
  234. {
  235. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  236. AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0);
  237. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  238. AR_PHY_TIMING11_SPUR_FREQ_SD, 0);
  239. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  240. AR_PHY_TIMING11_SPUR_DELTA_PHASE, 0);
  241. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  242. AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, 0);
  243. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  244. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0);
  245. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  246. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0);
  247. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  248. AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0);
  249. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  250. AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 0);
  251. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  252. AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 0);
  253. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  254. AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0);
  255. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  256. AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0);
  257. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  258. AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0);
  259. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  260. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, 0);
  261. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  262. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, 0);
  263. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  264. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, 0);
  265. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  266. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0);
  267. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  268. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0);
  269. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  270. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0);
  271. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  272. AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0);
  273. }
  274. static void ar9003_hw_spur_ofdm(struct ath_hw *ah,
  275. int freq_offset,
  276. int spur_freq_sd,
  277. int spur_delta_phase,
  278. int spur_subchannel_sd,
  279. int range,
  280. int synth_freq)
  281. {
  282. int mask_index = 0;
  283. /* OFDM Spur mitigation */
  284. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  285. AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0x1);
  286. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  287. AR_PHY_TIMING11_SPUR_FREQ_SD, spur_freq_sd);
  288. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  289. AR_PHY_TIMING11_SPUR_DELTA_PHASE, spur_delta_phase);
  290. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  291. AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, spur_subchannel_sd);
  292. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  293. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0x1);
  294. if (!(AR_SREV_9565(ah) && range == 10 && synth_freq == 2437))
  295. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  296. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0x1);
  297. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  298. AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0x1);
  299. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  300. AR_PHY_SPUR_REG_SPUR_RSSI_THRESH, 34);
  301. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  302. AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 1);
  303. if (!AR_SREV_9340(ah) &&
  304. REG_READ_FIELD(ah, AR_PHY_MODE,
  305. AR_PHY_MODE_DYNAMIC) == 0x1)
  306. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  307. AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 1);
  308. mask_index = (freq_offset << 4) / 5;
  309. if (mask_index < 0)
  310. mask_index = mask_index - 1;
  311. mask_index = mask_index & 0x7f;
  312. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  313. AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0x1);
  314. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  315. AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0x1);
  316. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  317. AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0x1);
  318. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  319. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, mask_index);
  320. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  321. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, mask_index);
  322. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  323. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, mask_index);
  324. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  325. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0xc);
  326. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  327. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0xc);
  328. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  329. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0xa0);
  330. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  331. AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0xff);
  332. }
  333. static void ar9003_hw_spur_ofdm_9565(struct ath_hw *ah,
  334. int freq_offset)
  335. {
  336. int mask_index = 0;
  337. mask_index = (freq_offset << 4) / 5;
  338. if (mask_index < 0)
  339. mask_index = mask_index - 1;
  340. mask_index = mask_index & 0x7f;
  341. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  342. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_B,
  343. mask_index);
  344. /* A == B */
  345. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_B,
  346. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A,
  347. mask_index);
  348. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  349. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_B,
  350. mask_index);
  351. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  352. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_B, 0xe);
  353. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  354. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_B, 0xe);
  355. /* A == B */
  356. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_B,
  357. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0xa0);
  358. }
  359. static void ar9003_hw_spur_ofdm_work(struct ath_hw *ah,
  360. struct ath9k_channel *chan,
  361. int freq_offset,
  362. int range,
  363. int synth_freq)
  364. {
  365. int spur_freq_sd = 0;
  366. int spur_subchannel_sd = 0;
  367. int spur_delta_phase = 0;
  368. if (IS_CHAN_HT40(chan)) {
  369. if (freq_offset < 0) {
  370. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  371. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  372. spur_subchannel_sd = 1;
  373. else
  374. spur_subchannel_sd = 0;
  375. spur_freq_sd = ((freq_offset + 10) << 9) / 11;
  376. } else {
  377. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  378. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  379. spur_subchannel_sd = 0;
  380. else
  381. spur_subchannel_sd = 1;
  382. spur_freq_sd = ((freq_offset - 10) << 9) / 11;
  383. }
  384. spur_delta_phase = (freq_offset << 17) / 5;
  385. } else {
  386. spur_subchannel_sd = 0;
  387. spur_freq_sd = (freq_offset << 9) /11;
  388. spur_delta_phase = (freq_offset << 18) / 5;
  389. }
  390. spur_freq_sd = spur_freq_sd & 0x3ff;
  391. spur_delta_phase = spur_delta_phase & 0xfffff;
  392. ar9003_hw_spur_ofdm(ah,
  393. freq_offset,
  394. spur_freq_sd,
  395. spur_delta_phase,
  396. spur_subchannel_sd,
  397. range, synth_freq);
  398. }
  399. /* Spur mitigation for OFDM */
  400. static void ar9003_hw_spur_mitigate_ofdm(struct ath_hw *ah,
  401. struct ath9k_channel *chan)
  402. {
  403. int synth_freq;
  404. int range = 10;
  405. int freq_offset = 0;
  406. int mode;
  407. u8* spurChansPtr;
  408. unsigned int i;
  409. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  410. if (IS_CHAN_5GHZ(chan)) {
  411. spurChansPtr = &(eep->modalHeader5G.spurChans[0]);
  412. mode = 0;
  413. }
  414. else {
  415. spurChansPtr = &(eep->modalHeader2G.spurChans[0]);
  416. mode = 1;
  417. }
  418. if (spurChansPtr[0] == 0)
  419. return; /* No spur in the mode */
  420. if (IS_CHAN_HT40(chan)) {
  421. range = 19;
  422. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  423. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  424. synth_freq = chan->channel - 10;
  425. else
  426. synth_freq = chan->channel + 10;
  427. } else {
  428. range = 10;
  429. synth_freq = chan->channel;
  430. }
  431. ar9003_hw_spur_ofdm_clear(ah);
  432. for (i = 0; i < AR_EEPROM_MODAL_SPURS && spurChansPtr[i]; i++) {
  433. freq_offset = ath9k_hw_fbin2freq(spurChansPtr[i], mode);
  434. freq_offset -= synth_freq;
  435. if (abs(freq_offset) < range) {
  436. ar9003_hw_spur_ofdm_work(ah, chan, freq_offset,
  437. range, synth_freq);
  438. if (AR_SREV_9565(ah) && (i < 4)) {
  439. freq_offset = ath9k_hw_fbin2freq(spurChansPtr[i + 1],
  440. mode);
  441. freq_offset -= synth_freq;
  442. if (abs(freq_offset) < range)
  443. ar9003_hw_spur_ofdm_9565(ah, freq_offset);
  444. }
  445. break;
  446. }
  447. }
  448. }
  449. static void ar9003_hw_spur_mitigate(struct ath_hw *ah,
  450. struct ath9k_channel *chan)
  451. {
  452. if (!AR_SREV_9565(ah))
  453. ar9003_hw_spur_mitigate_mrc_cck(ah, chan);
  454. ar9003_hw_spur_mitigate_ofdm(ah, chan);
  455. }
  456. static u32 ar9003_hw_compute_pll_control(struct ath_hw *ah,
  457. struct ath9k_channel *chan)
  458. {
  459. u32 pll;
  460. pll = SM(0x5, AR_RTC_9300_PLL_REFDIV);
  461. if (chan && IS_CHAN_HALF_RATE(chan))
  462. pll |= SM(0x1, AR_RTC_9300_PLL_CLKSEL);
  463. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  464. pll |= SM(0x2, AR_RTC_9300_PLL_CLKSEL);
  465. pll |= SM(0x2c, AR_RTC_9300_PLL_DIV);
  466. return pll;
  467. }
  468. static void ar9003_hw_set_channel_regs(struct ath_hw *ah,
  469. struct ath9k_channel *chan)
  470. {
  471. u32 phymode;
  472. u32 enableDacFifo = 0;
  473. enableDacFifo =
  474. (REG_READ(ah, AR_PHY_GEN_CTRL) & AR_PHY_GC_ENABLE_DAC_FIFO);
  475. /* Enable 11n HT, 20 MHz */
  476. phymode = AR_PHY_GC_HT_EN | AR_PHY_GC_SINGLE_HT_LTF1 |
  477. AR_PHY_GC_SHORT_GI_40 | enableDacFifo;
  478. /* Configure baseband for dynamic 20/40 operation */
  479. if (IS_CHAN_HT40(chan)) {
  480. phymode |= AR_PHY_GC_DYN2040_EN;
  481. /* Configure control (primary) channel at +-10MHz */
  482. if (IS_CHAN_HT40PLUS(chan))
  483. phymode |= AR_PHY_GC_DYN2040_PRI_CH;
  484. }
  485. /* make sure we preserve INI settings */
  486. phymode |= REG_READ(ah, AR_PHY_GEN_CTRL);
  487. /* turn off Green Field detection for STA for now */
  488. phymode &= ~AR_PHY_GC_GF_DETECT_EN;
  489. REG_WRITE(ah, AR_PHY_GEN_CTRL, phymode);
  490. /* Configure MAC for 20/40 operation */
  491. ath9k_hw_set11nmac2040(ah, chan);
  492. /* global transmit timeout (25 TUs default)*/
  493. REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
  494. /* carrier sense timeout */
  495. REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
  496. }
  497. static void ar9003_hw_init_bb(struct ath_hw *ah,
  498. struct ath9k_channel *chan)
  499. {
  500. u32 synthDelay;
  501. /*
  502. * Wait for the frequency synth to settle (synth goes on
  503. * via AR_PHY_ACTIVE_EN). Read the phy active delay register.
  504. * Value is in 100ns increments.
  505. */
  506. synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  507. /* Activate the PHY (includes baseband activate + synthesizer on) */
  508. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
  509. ath9k_hw_synth_delay(ah, chan, synthDelay);
  510. }
  511. void ar9003_hw_set_chain_masks(struct ath_hw *ah, u8 rx, u8 tx)
  512. {
  513. if (ah->caps.tx_chainmask == 5 || ah->caps.rx_chainmask == 5)
  514. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  515. AR_PHY_SWAP_ALT_CHAIN);
  516. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx);
  517. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx);
  518. if ((ah->caps.hw_caps & ATH9K_HW_CAP_APM) && (tx == 0x7))
  519. tx = 3;
  520. REG_WRITE(ah, AR_SELFGEN_MASK, tx);
  521. }
  522. /*
  523. * Override INI values with chip specific configuration.
  524. */
  525. static void ar9003_hw_override_ini(struct ath_hw *ah)
  526. {
  527. u32 val;
  528. /*
  529. * Set the RX_ABORT and RX_DIS and clear it only after
  530. * RXE is set for MAC. This prevents frames with
  531. * corrupted descriptor status.
  532. */
  533. REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  534. /*
  535. * For AR9280 and above, there is a new feature that allows
  536. * Multicast search based on both MAC Address and Key ID. By default,
  537. * this feature is enabled. But since the driver is not using this
  538. * feature, we switch it off; otherwise multicast search based on
  539. * MAC addr only will fail.
  540. */
  541. val = REG_READ(ah, AR_PCU_MISC_MODE2) & (~AR_ADHOC_MCAST_KEYID_ENABLE);
  542. val |= AR_AGG_WEP_ENABLE_FIX |
  543. AR_AGG_WEP_ENABLE |
  544. AR_PCU_MISC_MODE2_CFP_IGNORE;
  545. REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
  546. if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
  547. REG_WRITE(ah, AR_GLB_SWREG_DISCONT_MODE,
  548. AR_GLB_SWREG_DISCONT_EN_BT_WLAN);
  549. if (REG_READ_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_0,
  550. AR_PHY_TX_IQCAL_CONTROL_0_ENABLE_TXIQ_CAL))
  551. ah->enabled_cals |= TX_IQ_CAL;
  552. else
  553. ah->enabled_cals &= ~TX_IQ_CAL;
  554. }
  555. if (REG_READ(ah, AR_PHY_CL_CAL_CTL) & AR_PHY_CL_CAL_ENABLE)
  556. ah->enabled_cals |= TX_CL_CAL;
  557. else
  558. ah->enabled_cals &= ~TX_CL_CAL;
  559. }
  560. static void ar9003_hw_prog_ini(struct ath_hw *ah,
  561. struct ar5416IniArray *iniArr,
  562. int column)
  563. {
  564. unsigned int i, regWrites = 0;
  565. /* New INI format: Array may be undefined (pre, core, post arrays) */
  566. if (!iniArr->ia_array)
  567. return;
  568. /*
  569. * New INI format: Pre, core, and post arrays for a given subsystem
  570. * may be modal (> 2 columns) or non-modal (2 columns). Determine if
  571. * the array is non-modal and force the column to 1.
  572. */
  573. if (column >= iniArr->ia_columns)
  574. column = 1;
  575. for (i = 0; i < iniArr->ia_rows; i++) {
  576. u32 reg = INI_RA(iniArr, i, 0);
  577. u32 val = INI_RA(iniArr, i, column);
  578. REG_WRITE(ah, reg, val);
  579. DO_DELAY(regWrites);
  580. }
  581. }
  582. static int ar9550_hw_get_modes_txgain_index(struct ath_hw *ah,
  583. struct ath9k_channel *chan)
  584. {
  585. int ret;
  586. if (IS_CHAN_2GHZ(chan)) {
  587. if (IS_CHAN_HT40(chan))
  588. return 7;
  589. else
  590. return 8;
  591. }
  592. if (chan->channel <= 5350)
  593. ret = 1;
  594. else if ((chan->channel > 5350) && (chan->channel <= 5600))
  595. ret = 3;
  596. else
  597. ret = 5;
  598. if (IS_CHAN_HT40(chan))
  599. ret++;
  600. return ret;
  601. }
  602. static void ar9003_doubler_fix(struct ath_hw *ah)
  603. {
  604. if (AR_SREV_9300(ah) || AR_SREV_9580(ah) || AR_SREV_9550(ah)) {
  605. REG_RMW(ah, AR_PHY_65NM_CH0_RXTX2,
  606. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
  607. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S, 0);
  608. REG_RMW(ah, AR_PHY_65NM_CH1_RXTX2,
  609. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
  610. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S, 0);
  611. REG_RMW(ah, AR_PHY_65NM_CH2_RXTX2,
  612. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
  613. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S, 0);
  614. udelay(200);
  615. REG_CLR_BIT(ah, AR_PHY_65NM_CH0_RXTX2,
  616. AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK);
  617. REG_CLR_BIT(ah, AR_PHY_65NM_CH1_RXTX2,
  618. AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK);
  619. REG_CLR_BIT(ah, AR_PHY_65NM_CH2_RXTX2,
  620. AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK);
  621. udelay(1);
  622. REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_RXTX2,
  623. AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK, 1);
  624. REG_RMW_FIELD(ah, AR_PHY_65NM_CH1_RXTX2,
  625. AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK, 1);
  626. REG_RMW_FIELD(ah, AR_PHY_65NM_CH2_RXTX2,
  627. AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK, 1);
  628. udelay(200);
  629. REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_SYNTH12,
  630. AR_PHY_65NM_CH0_SYNTH12_VREFMUL3, 0xf);
  631. REG_RMW(ah, AR_PHY_65NM_CH0_RXTX2, 0,
  632. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
  633. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S);
  634. REG_RMW(ah, AR_PHY_65NM_CH1_RXTX2, 0,
  635. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
  636. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S);
  637. REG_RMW(ah, AR_PHY_65NM_CH2_RXTX2, 0,
  638. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
  639. 1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S);
  640. }
  641. }
  642. static int ar9003_hw_process_ini(struct ath_hw *ah,
  643. struct ath9k_channel *chan)
  644. {
  645. unsigned int regWrites = 0, i;
  646. u32 modesIndex;
  647. if (IS_CHAN_5GHZ(chan))
  648. modesIndex = IS_CHAN_HT40(chan) ? 2 : 1;
  649. else
  650. modesIndex = IS_CHAN_HT40(chan) ? 3 : 4;
  651. /*
  652. * SOC, MAC, BB, RADIO initvals.
  653. */
  654. for (i = 0; i < ATH_INI_NUM_SPLIT; i++) {
  655. ar9003_hw_prog_ini(ah, &ah->iniSOC[i], modesIndex);
  656. ar9003_hw_prog_ini(ah, &ah->iniMac[i], modesIndex);
  657. ar9003_hw_prog_ini(ah, &ah->iniBB[i], modesIndex);
  658. ar9003_hw_prog_ini(ah, &ah->iniRadio[i], modesIndex);
  659. if (i == ATH_INI_POST && AR_SREV_9462_20_OR_LATER(ah))
  660. ar9003_hw_prog_ini(ah,
  661. &ah->ini_radio_post_sys2ant,
  662. modesIndex);
  663. }
  664. ar9003_doubler_fix(ah);
  665. /*
  666. * RXGAIN initvals.
  667. */
  668. REG_WRITE_ARRAY(&ah->iniModesRxGain, 1, regWrites);
  669. if (AR_SREV_9462_20_OR_LATER(ah)) {
  670. /*
  671. * CUS217 mix LNA mode.
  672. */
  673. if (ar9003_hw_get_rx_gain_idx(ah) == 2) {
  674. REG_WRITE_ARRAY(&ah->ini_modes_rxgain_bb_core,
  675. 1, regWrites);
  676. REG_WRITE_ARRAY(&ah->ini_modes_rxgain_bb_postamble,
  677. modesIndex, regWrites);
  678. }
  679. /*
  680. * 5G-XLNA
  681. */
  682. if ((ar9003_hw_get_rx_gain_idx(ah) == 2) ||
  683. (ar9003_hw_get_rx_gain_idx(ah) == 3)) {
  684. REG_WRITE_ARRAY(&ah->ini_modes_rxgain_5g_xlna,
  685. modesIndex, regWrites);
  686. }
  687. }
  688. if (AR_SREV_9550(ah))
  689. REG_WRITE_ARRAY(&ah->ini_modes_rx_gain_bounds, modesIndex,
  690. regWrites);
  691. /*
  692. * TXGAIN initvals.
  693. */
  694. if (AR_SREV_9550(ah) || AR_SREV_9531(ah)) {
  695. int modes_txgain_index = 1;
  696. if (AR_SREV_9550(ah))
  697. modes_txgain_index = ar9550_hw_get_modes_txgain_index(ah, chan);
  698. if (modes_txgain_index < 0)
  699. return -EINVAL;
  700. REG_WRITE_ARRAY(&ah->iniModesTxGain, modes_txgain_index,
  701. regWrites);
  702. } else {
  703. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  704. }
  705. /*
  706. * For 5GHz channels requiring Fast Clock, apply
  707. * different modal values.
  708. */
  709. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  710. REG_WRITE_ARRAY(&ah->iniModesFastClock,
  711. modesIndex, regWrites);
  712. /*
  713. * Clock frequency initvals.
  714. */
  715. REG_WRITE_ARRAY(&ah->iniAdditional, 1, regWrites);
  716. /*
  717. * JAPAN regulatory.
  718. */
  719. if (chan->channel == 2484)
  720. ar9003_hw_prog_ini(ah, &ah->iniCckfirJapan2484, 1);
  721. ah->modes_index = modesIndex;
  722. ar9003_hw_override_ini(ah);
  723. ar9003_hw_set_channel_regs(ah, chan);
  724. ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
  725. ath9k_hw_apply_txpower(ah, chan, false);
  726. return 0;
  727. }
  728. static void ar9003_hw_set_rfmode(struct ath_hw *ah,
  729. struct ath9k_channel *chan)
  730. {
  731. u32 rfMode = 0;
  732. if (chan == NULL)
  733. return;
  734. if (IS_CHAN_2GHZ(chan))
  735. rfMode |= AR_PHY_MODE_DYNAMIC;
  736. else
  737. rfMode |= AR_PHY_MODE_OFDM;
  738. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  739. rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
  740. if (IS_CHAN_QUARTER_RATE(chan))
  741. rfMode |= AR_PHY_MODE_QUARTER;
  742. if (IS_CHAN_HALF_RATE(chan))
  743. rfMode |= AR_PHY_MODE_HALF;
  744. if (rfMode & (AR_PHY_MODE_QUARTER | AR_PHY_MODE_HALF))
  745. REG_RMW_FIELD(ah, AR_PHY_FRAME_CTL,
  746. AR_PHY_FRAME_CTL_CF_OVERLAP_WINDOW, 3);
  747. REG_WRITE(ah, AR_PHY_MODE, rfMode);
  748. }
  749. static void ar9003_hw_mark_phy_inactive(struct ath_hw *ah)
  750. {
  751. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
  752. }
  753. static void ar9003_hw_set_delta_slope(struct ath_hw *ah,
  754. struct ath9k_channel *chan)
  755. {
  756. u32 coef_scaled, ds_coef_exp, ds_coef_man;
  757. u32 clockMhzScaled = 0x64000000;
  758. struct chan_centers centers;
  759. /*
  760. * half and quarter rate can divide the scaled clock by 2 or 4
  761. * scale for selected channel bandwidth
  762. */
  763. if (IS_CHAN_HALF_RATE(chan))
  764. clockMhzScaled = clockMhzScaled >> 1;
  765. else if (IS_CHAN_QUARTER_RATE(chan))
  766. clockMhzScaled = clockMhzScaled >> 2;
  767. /*
  768. * ALGO -> coef = 1e8/fcarrier*fclock/40;
  769. * scaled coef to provide precision for this floating calculation
  770. */
  771. ath9k_hw_get_channel_centers(ah, chan, &centers);
  772. coef_scaled = clockMhzScaled / centers.synth_center;
  773. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  774. &ds_coef_exp);
  775. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  776. AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
  777. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  778. AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
  779. /*
  780. * For Short GI,
  781. * scaled coeff is 9/10 that of normal coeff
  782. */
  783. coef_scaled = (9 * coef_scaled) / 10;
  784. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  785. &ds_coef_exp);
  786. /* for short gi */
  787. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  788. AR_PHY_SGI_DSC_MAN, ds_coef_man);
  789. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  790. AR_PHY_SGI_DSC_EXP, ds_coef_exp);
  791. }
  792. static bool ar9003_hw_rfbus_req(struct ath_hw *ah)
  793. {
  794. REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
  795. return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
  796. AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT);
  797. }
  798. /*
  799. * Wait for the frequency synth to settle (synth goes on via PHY_ACTIVE_EN).
  800. * Read the phy active delay register. Value is in 100ns increments.
  801. */
  802. static void ar9003_hw_rfbus_done(struct ath_hw *ah)
  803. {
  804. u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  805. ath9k_hw_synth_delay(ah, ah->curchan, synthDelay);
  806. REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
  807. }
  808. static bool ar9003_hw_ani_control(struct ath_hw *ah,
  809. enum ath9k_ani_cmd cmd, int param)
  810. {
  811. struct ath_common *common = ath9k_hw_common(ah);
  812. struct ath9k_channel *chan = ah->curchan;
  813. struct ar5416AniState *aniState = &ah->ani;
  814. int m1ThreshLow, m2ThreshLow;
  815. int m1Thresh, m2Thresh;
  816. int m2CountThr, m2CountThrLow;
  817. int m1ThreshLowExt, m2ThreshLowExt;
  818. int m1ThreshExt, m2ThreshExt;
  819. s32 value, value2;
  820. switch (cmd & ah->ani_function) {
  821. case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
  822. /*
  823. * on == 1 means ofdm weak signal detection is ON
  824. * on == 1 is the default, for less noise immunity
  825. *
  826. * on == 0 means ofdm weak signal detection is OFF
  827. * on == 0 means more noise imm
  828. */
  829. u32 on = param ? 1 : 0;
  830. if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
  831. goto skip_ws_det;
  832. m1ThreshLow = on ?
  833. aniState->iniDef.m1ThreshLow : m1ThreshLow_off;
  834. m2ThreshLow = on ?
  835. aniState->iniDef.m2ThreshLow : m2ThreshLow_off;
  836. m1Thresh = on ?
  837. aniState->iniDef.m1Thresh : m1Thresh_off;
  838. m2Thresh = on ?
  839. aniState->iniDef.m2Thresh : m2Thresh_off;
  840. m2CountThr = on ?
  841. aniState->iniDef.m2CountThr : m2CountThr_off;
  842. m2CountThrLow = on ?
  843. aniState->iniDef.m2CountThrLow : m2CountThrLow_off;
  844. m1ThreshLowExt = on ?
  845. aniState->iniDef.m1ThreshLowExt : m1ThreshLowExt_off;
  846. m2ThreshLowExt = on ?
  847. aniState->iniDef.m2ThreshLowExt : m2ThreshLowExt_off;
  848. m1ThreshExt = on ?
  849. aniState->iniDef.m1ThreshExt : m1ThreshExt_off;
  850. m2ThreshExt = on ?
  851. aniState->iniDef.m2ThreshExt : m2ThreshExt_off;
  852. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  853. AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
  854. m1ThreshLow);
  855. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  856. AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
  857. m2ThreshLow);
  858. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  859. AR_PHY_SFCORR_M1_THRESH,
  860. m1Thresh);
  861. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  862. AR_PHY_SFCORR_M2_THRESH,
  863. m2Thresh);
  864. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  865. AR_PHY_SFCORR_M2COUNT_THR,
  866. m2CountThr);
  867. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  868. AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
  869. m2CountThrLow);
  870. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  871. AR_PHY_SFCORR_EXT_M1_THRESH_LOW,
  872. m1ThreshLowExt);
  873. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  874. AR_PHY_SFCORR_EXT_M2_THRESH_LOW,
  875. m2ThreshLowExt);
  876. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  877. AR_PHY_SFCORR_EXT_M1_THRESH,
  878. m1ThreshExt);
  879. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  880. AR_PHY_SFCORR_EXT_M2_THRESH,
  881. m2ThreshExt);
  882. skip_ws_det:
  883. if (on)
  884. REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
  885. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  886. else
  887. REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
  888. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  889. if (on != aniState->ofdmWeakSigDetect) {
  890. ath_dbg(common, ANI,
  891. "** ch %d: ofdm weak signal: %s=>%s\n",
  892. chan->channel,
  893. aniState->ofdmWeakSigDetect ?
  894. "on" : "off",
  895. on ? "on" : "off");
  896. if (on)
  897. ah->stats.ast_ani_ofdmon++;
  898. else
  899. ah->stats.ast_ani_ofdmoff++;
  900. aniState->ofdmWeakSigDetect = on;
  901. }
  902. break;
  903. }
  904. case ATH9K_ANI_FIRSTEP_LEVEL:{
  905. u32 level = param;
  906. if (level >= ARRAY_SIZE(firstep_table)) {
  907. ath_dbg(common, ANI,
  908. "ATH9K_ANI_FIRSTEP_LEVEL: level out of range (%u > %zu)\n",
  909. level, ARRAY_SIZE(firstep_table));
  910. return false;
  911. }
  912. /*
  913. * make register setting relative to default
  914. * from INI file & cap value
  915. */
  916. value = firstep_table[level] -
  917. firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
  918. aniState->iniDef.firstep;
  919. if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  920. value = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  921. if (value > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  922. value = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  923. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  924. AR_PHY_FIND_SIG_FIRSTEP,
  925. value);
  926. /*
  927. * we need to set first step low register too
  928. * make register setting relative to default
  929. * from INI file & cap value
  930. */
  931. value2 = firstep_table[level] -
  932. firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
  933. aniState->iniDef.firstepLow;
  934. if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  935. value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  936. if (value2 > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  937. value2 = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  938. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
  939. AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW, value2);
  940. if (level != aniState->firstepLevel) {
  941. ath_dbg(common, ANI,
  942. "** ch %d: level %d=>%d[def:%d] firstep[level]=%d ini=%d\n",
  943. chan->channel,
  944. aniState->firstepLevel,
  945. level,
  946. ATH9K_ANI_FIRSTEP_LVL,
  947. value,
  948. aniState->iniDef.firstep);
  949. ath_dbg(common, ANI,
  950. "** ch %d: level %d=>%d[def:%d] firstep_low[level]=%d ini=%d\n",
  951. chan->channel,
  952. aniState->firstepLevel,
  953. level,
  954. ATH9K_ANI_FIRSTEP_LVL,
  955. value2,
  956. aniState->iniDef.firstepLow);
  957. if (level > aniState->firstepLevel)
  958. ah->stats.ast_ani_stepup++;
  959. else if (level < aniState->firstepLevel)
  960. ah->stats.ast_ani_stepdown++;
  961. aniState->firstepLevel = level;
  962. }
  963. break;
  964. }
  965. case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
  966. u32 level = param;
  967. if (level >= ARRAY_SIZE(cycpwrThr1_table)) {
  968. ath_dbg(common, ANI,
  969. "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level out of range (%u > %zu)\n",
  970. level, ARRAY_SIZE(cycpwrThr1_table));
  971. return false;
  972. }
  973. /*
  974. * make register setting relative to default
  975. * from INI file & cap value
  976. */
  977. value = cycpwrThr1_table[level] -
  978. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
  979. aniState->iniDef.cycpwrThr1;
  980. if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  981. value = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  982. if (value > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  983. value = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  984. REG_RMW_FIELD(ah, AR_PHY_TIMING5,
  985. AR_PHY_TIMING5_CYCPWR_THR1,
  986. value);
  987. /*
  988. * set AR_PHY_EXT_CCA for extension channel
  989. * make register setting relative to default
  990. * from INI file & cap value
  991. */
  992. value2 = cycpwrThr1_table[level] -
  993. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
  994. aniState->iniDef.cycpwrThr1Ext;
  995. if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  996. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  997. if (value2 > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  998. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  999. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
  1000. AR_PHY_EXT_CYCPWR_THR1, value2);
  1001. if (level != aniState->spurImmunityLevel) {
  1002. ath_dbg(common, ANI,
  1003. "** ch %d: level %d=>%d[def:%d] cycpwrThr1[level]=%d ini=%d\n",
  1004. chan->channel,
  1005. aniState->spurImmunityLevel,
  1006. level,
  1007. ATH9K_ANI_SPUR_IMMUNE_LVL,
  1008. value,
  1009. aniState->iniDef.cycpwrThr1);
  1010. ath_dbg(common, ANI,
  1011. "** ch %d: level %d=>%d[def:%d] cycpwrThr1Ext[level]=%d ini=%d\n",
  1012. chan->channel,
  1013. aniState->spurImmunityLevel,
  1014. level,
  1015. ATH9K_ANI_SPUR_IMMUNE_LVL,
  1016. value2,
  1017. aniState->iniDef.cycpwrThr1Ext);
  1018. if (level > aniState->spurImmunityLevel)
  1019. ah->stats.ast_ani_spurup++;
  1020. else if (level < aniState->spurImmunityLevel)
  1021. ah->stats.ast_ani_spurdown++;
  1022. aniState->spurImmunityLevel = level;
  1023. }
  1024. break;
  1025. }
  1026. case ATH9K_ANI_MRC_CCK:{
  1027. /*
  1028. * is_on == 1 means MRC CCK ON (default, less noise imm)
  1029. * is_on == 0 means MRC CCK is OFF (more noise imm)
  1030. */
  1031. bool is_on = param ? 1 : 0;
  1032. if (ah->caps.rx_chainmask == 1)
  1033. break;
  1034. REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
  1035. AR_PHY_MRC_CCK_ENABLE, is_on);
  1036. REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
  1037. AR_PHY_MRC_CCK_MUX_REG, is_on);
  1038. if (is_on != aniState->mrcCCK) {
  1039. ath_dbg(common, ANI, "** ch %d: MRC CCK: %s=>%s\n",
  1040. chan->channel,
  1041. aniState->mrcCCK ? "on" : "off",
  1042. is_on ? "on" : "off");
  1043. if (is_on)
  1044. ah->stats.ast_ani_ccklow++;
  1045. else
  1046. ah->stats.ast_ani_cckhigh++;
  1047. aniState->mrcCCK = is_on;
  1048. }
  1049. break;
  1050. }
  1051. default:
  1052. ath_dbg(common, ANI, "invalid cmd %u\n", cmd);
  1053. return false;
  1054. }
  1055. ath_dbg(common, ANI,
  1056. "ANI parameters: SI=%d, ofdmWS=%s FS=%d MRCcck=%s listenTime=%d ofdmErrs=%d cckErrs=%d\n",
  1057. aniState->spurImmunityLevel,
  1058. aniState->ofdmWeakSigDetect ? "on" : "off",
  1059. aniState->firstepLevel,
  1060. aniState->mrcCCK ? "on" : "off",
  1061. aniState->listenTime,
  1062. aniState->ofdmPhyErrCount,
  1063. aniState->cckPhyErrCount);
  1064. return true;
  1065. }
  1066. static void ar9003_hw_do_getnf(struct ath_hw *ah,
  1067. int16_t nfarray[NUM_NF_READINGS])
  1068. {
  1069. #define AR_PHY_CH_MINCCA_PWR 0x1FF00000
  1070. #define AR_PHY_CH_MINCCA_PWR_S 20
  1071. #define AR_PHY_CH_EXT_MINCCA_PWR 0x01FF0000
  1072. #define AR_PHY_CH_EXT_MINCCA_PWR_S 16
  1073. int16_t nf;
  1074. int i;
  1075. for (i = 0; i < AR9300_MAX_CHAINS; i++) {
  1076. if (ah->rxchainmask & BIT(i)) {
  1077. nf = MS(REG_READ(ah, ah->nf_regs[i]),
  1078. AR_PHY_CH_MINCCA_PWR);
  1079. nfarray[i] = sign_extend32(nf, 8);
  1080. if (IS_CHAN_HT40(ah->curchan)) {
  1081. u8 ext_idx = AR9300_MAX_CHAINS + i;
  1082. nf = MS(REG_READ(ah, ah->nf_regs[ext_idx]),
  1083. AR_PHY_CH_EXT_MINCCA_PWR);
  1084. nfarray[ext_idx] = sign_extend32(nf, 8);
  1085. }
  1086. }
  1087. }
  1088. }
  1089. static void ar9003_hw_set_nf_limits(struct ath_hw *ah)
  1090. {
  1091. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_2GHZ;
  1092. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_2GHZ;
  1093. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9300_2GHZ;
  1094. ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_5GHZ;
  1095. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_5GHZ;
  1096. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9300_5GHZ;
  1097. if (AR_SREV_9330(ah))
  1098. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9330_2GHZ;
  1099. if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
  1100. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9462_2GHZ;
  1101. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9462_2GHZ;
  1102. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9462_5GHZ;
  1103. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9462_5GHZ;
  1104. }
  1105. }
  1106. /*
  1107. * Initialize the ANI register values with default (ini) values.
  1108. * This routine is called during a (full) hardware reset after
  1109. * all the registers are initialised from the INI.
  1110. */
  1111. static void ar9003_hw_ani_cache_ini_regs(struct ath_hw *ah)
  1112. {
  1113. struct ar5416AniState *aniState;
  1114. struct ath_common *common = ath9k_hw_common(ah);
  1115. struct ath9k_channel *chan = ah->curchan;
  1116. struct ath9k_ani_default *iniDef;
  1117. u32 val;
  1118. aniState = &ah->ani;
  1119. iniDef = &aniState->iniDef;
  1120. ath_dbg(common, ANI, "ver %d.%d opmode %u chan %d Mhz\n",
  1121. ah->hw_version.macVersion,
  1122. ah->hw_version.macRev,
  1123. ah->opmode,
  1124. chan->channel);
  1125. val = REG_READ(ah, AR_PHY_SFCORR);
  1126. iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH);
  1127. iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH);
  1128. iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR);
  1129. val = REG_READ(ah, AR_PHY_SFCORR_LOW);
  1130. iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW);
  1131. iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW);
  1132. iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW);
  1133. val = REG_READ(ah, AR_PHY_SFCORR_EXT);
  1134. iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH);
  1135. iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH);
  1136. iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW);
  1137. iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW);
  1138. iniDef->firstep = REG_READ_FIELD(ah,
  1139. AR_PHY_FIND_SIG,
  1140. AR_PHY_FIND_SIG_FIRSTEP);
  1141. iniDef->firstepLow = REG_READ_FIELD(ah,
  1142. AR_PHY_FIND_SIG_LOW,
  1143. AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW);
  1144. iniDef->cycpwrThr1 = REG_READ_FIELD(ah,
  1145. AR_PHY_TIMING5,
  1146. AR_PHY_TIMING5_CYCPWR_THR1);
  1147. iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah,
  1148. AR_PHY_EXT_CCA,
  1149. AR_PHY_EXT_CYCPWR_THR1);
  1150. /* these levels just got reset to defaults by the INI */
  1151. aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL;
  1152. aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL;
  1153. aniState->ofdmWeakSigDetect = true;
  1154. aniState->mrcCCK = true;
  1155. }
  1156. static void ar9003_hw_set_radar_params(struct ath_hw *ah,
  1157. struct ath_hw_radar_conf *conf)
  1158. {
  1159. unsigned int regWrites = 0;
  1160. u32 radar_0 = 0, radar_1 = 0;
  1161. if (!conf) {
  1162. REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA);
  1163. return;
  1164. }
  1165. radar_0 |= AR_PHY_RADAR_0_ENA | AR_PHY_RADAR_0_FFT_ENA;
  1166. radar_0 |= SM(conf->fir_power, AR_PHY_RADAR_0_FIRPWR);
  1167. radar_0 |= SM(conf->radar_rssi, AR_PHY_RADAR_0_RRSSI);
  1168. radar_0 |= SM(conf->pulse_height, AR_PHY_RADAR_0_HEIGHT);
  1169. radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI);
  1170. radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND);
  1171. radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI;
  1172. radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK;
  1173. radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN);
  1174. radar_1 |= SM(conf->pulse_inband_step, AR_PHY_RADAR_1_RELSTEP_THRESH);
  1175. radar_1 |= SM(conf->radar_inband, AR_PHY_RADAR_1_RELPWR_THRESH);
  1176. REG_WRITE(ah, AR_PHY_RADAR_0, radar_0);
  1177. REG_WRITE(ah, AR_PHY_RADAR_1, radar_1);
  1178. if (conf->ext_channel)
  1179. REG_SET_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1180. else
  1181. REG_CLR_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1182. if (AR_SREV_9300(ah) || AR_SREV_9340(ah) || AR_SREV_9580(ah)) {
  1183. REG_WRITE_ARRAY(&ah->ini_dfs,
  1184. IS_CHAN_HT40(ah->curchan) ? 2 : 1, regWrites);
  1185. }
  1186. }
  1187. static void ar9003_hw_set_radar_conf(struct ath_hw *ah)
  1188. {
  1189. struct ath_hw_radar_conf *conf = &ah->radar_conf;
  1190. conf->fir_power = -28;
  1191. conf->radar_rssi = 0;
  1192. conf->pulse_height = 10;
  1193. conf->pulse_rssi = 24;
  1194. conf->pulse_inband = 8;
  1195. conf->pulse_maxlen = 255;
  1196. conf->pulse_inband_step = 12;
  1197. conf->radar_inband = 8;
  1198. }
  1199. static void ar9003_hw_antdiv_comb_conf_get(struct ath_hw *ah,
  1200. struct ath_hw_antcomb_conf *antconf)
  1201. {
  1202. u32 regval;
  1203. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1204. antconf->main_lna_conf = (regval & AR_PHY_ANT_DIV_MAIN_LNACONF) >>
  1205. AR_PHY_ANT_DIV_MAIN_LNACONF_S;
  1206. antconf->alt_lna_conf = (regval & AR_PHY_ANT_DIV_ALT_LNACONF) >>
  1207. AR_PHY_ANT_DIV_ALT_LNACONF_S;
  1208. antconf->fast_div_bias = (regval & AR_PHY_ANT_FAST_DIV_BIAS) >>
  1209. AR_PHY_ANT_FAST_DIV_BIAS_S;
  1210. if (AR_SREV_9330_11(ah)) {
  1211. antconf->lna1_lna2_switch_delta = -1;
  1212. antconf->lna1_lna2_delta = -9;
  1213. antconf->div_group = 1;
  1214. } else if (AR_SREV_9485(ah)) {
  1215. antconf->lna1_lna2_switch_delta = -1;
  1216. antconf->lna1_lna2_delta = -9;
  1217. antconf->div_group = 2;
  1218. } else if (AR_SREV_9565(ah)) {
  1219. antconf->lna1_lna2_switch_delta = 3;
  1220. antconf->lna1_lna2_delta = -9;
  1221. antconf->div_group = 3;
  1222. } else {
  1223. antconf->lna1_lna2_switch_delta = -1;
  1224. antconf->lna1_lna2_delta = -3;
  1225. antconf->div_group = 0;
  1226. }
  1227. }
  1228. static void ar9003_hw_antdiv_comb_conf_set(struct ath_hw *ah,
  1229. struct ath_hw_antcomb_conf *antconf)
  1230. {
  1231. u32 regval;
  1232. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1233. regval &= ~(AR_PHY_ANT_DIV_MAIN_LNACONF |
  1234. AR_PHY_ANT_DIV_ALT_LNACONF |
  1235. AR_PHY_ANT_FAST_DIV_BIAS |
  1236. AR_PHY_ANT_DIV_MAIN_GAINTB |
  1237. AR_PHY_ANT_DIV_ALT_GAINTB);
  1238. regval |= ((antconf->main_lna_conf << AR_PHY_ANT_DIV_MAIN_LNACONF_S)
  1239. & AR_PHY_ANT_DIV_MAIN_LNACONF);
  1240. regval |= ((antconf->alt_lna_conf << AR_PHY_ANT_DIV_ALT_LNACONF_S)
  1241. & AR_PHY_ANT_DIV_ALT_LNACONF);
  1242. regval |= ((antconf->fast_div_bias << AR_PHY_ANT_FAST_DIV_BIAS_S)
  1243. & AR_PHY_ANT_FAST_DIV_BIAS);
  1244. regval |= ((antconf->main_gaintb << AR_PHY_ANT_DIV_MAIN_GAINTB_S)
  1245. & AR_PHY_ANT_DIV_MAIN_GAINTB);
  1246. regval |= ((antconf->alt_gaintb << AR_PHY_ANT_DIV_ALT_GAINTB_S)
  1247. & AR_PHY_ANT_DIV_ALT_GAINTB);
  1248. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1249. }
  1250. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  1251. static void ar9003_hw_set_bt_ant_diversity(struct ath_hw *ah, bool enable)
  1252. {
  1253. struct ath9k_hw_capabilities *pCap = &ah->caps;
  1254. u8 ant_div_ctl1;
  1255. u32 regval;
  1256. if (!AR_SREV_9485(ah) && !AR_SREV_9565(ah))
  1257. return;
  1258. if (AR_SREV_9485(ah)) {
  1259. regval = ar9003_hw_ant_ctrl_common_2_get(ah,
  1260. IS_CHAN_2GHZ(ah->curchan));
  1261. if (enable) {
  1262. regval &= ~AR_SWITCH_TABLE_COM2_ALL;
  1263. regval |= ah->config.ant_ctrl_comm2g_switch_enable;
  1264. }
  1265. REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM_2,
  1266. AR_SWITCH_TABLE_COM2_ALL, regval);
  1267. }
  1268. ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
  1269. /*
  1270. * Set MAIN/ALT LNA conf.
  1271. * Set MAIN/ALT gain_tb.
  1272. */
  1273. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1274. regval &= (~AR_ANT_DIV_CTRL_ALL);
  1275. regval |= (ant_div_ctl1 & 0x3f) << AR_ANT_DIV_CTRL_ALL_S;
  1276. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1277. if (AR_SREV_9485_11_OR_LATER(ah)) {
  1278. /*
  1279. * Enable LNA diversity.
  1280. */
  1281. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1282. regval &= ~AR_PHY_ANT_DIV_LNADIV;
  1283. regval |= ((ant_div_ctl1 >> 6) & 0x1) << AR_PHY_ANT_DIV_LNADIV_S;
  1284. if (enable)
  1285. regval |= AR_ANT_DIV_ENABLE;
  1286. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1287. /*
  1288. * Enable fast antenna diversity.
  1289. */
  1290. regval = REG_READ(ah, AR_PHY_CCK_DETECT);
  1291. regval &= ~AR_FAST_DIV_ENABLE;
  1292. regval |= ((ant_div_ctl1 >> 7) & 0x1) << AR_FAST_DIV_ENABLE_S;
  1293. if (enable)
  1294. regval |= AR_FAST_DIV_ENABLE;
  1295. REG_WRITE(ah, AR_PHY_CCK_DETECT, regval);
  1296. if (pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) {
  1297. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1298. regval &= (~(AR_PHY_ANT_DIV_MAIN_LNACONF |
  1299. AR_PHY_ANT_DIV_ALT_LNACONF |
  1300. AR_PHY_ANT_DIV_ALT_GAINTB |
  1301. AR_PHY_ANT_DIV_MAIN_GAINTB));
  1302. /*
  1303. * Set MAIN to LNA1 and ALT to LNA2 at the
  1304. * beginning.
  1305. */
  1306. regval |= (ATH_ANT_DIV_COMB_LNA1 <<
  1307. AR_PHY_ANT_DIV_MAIN_LNACONF_S);
  1308. regval |= (ATH_ANT_DIV_COMB_LNA2 <<
  1309. AR_PHY_ANT_DIV_ALT_LNACONF_S);
  1310. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1311. }
  1312. } else if (AR_SREV_9565(ah)) {
  1313. if (enable) {
  1314. REG_SET_BIT(ah, AR_PHY_MC_GAIN_CTRL,
  1315. AR_ANT_DIV_ENABLE);
  1316. REG_SET_BIT(ah, AR_PHY_MC_GAIN_CTRL,
  1317. (1 << AR_PHY_ANT_SW_RX_PROT_S));
  1318. REG_SET_BIT(ah, AR_PHY_CCK_DETECT,
  1319. AR_FAST_DIV_ENABLE);
  1320. REG_SET_BIT(ah, AR_PHY_RESTART,
  1321. AR_PHY_RESTART_ENABLE_DIV_M2FLAG);
  1322. REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV,
  1323. AR_BTCOEX_WL_LNADIV_FORCE_ON);
  1324. } else {
  1325. REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL,
  1326. AR_ANT_DIV_ENABLE);
  1327. REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL,
  1328. (1 << AR_PHY_ANT_SW_RX_PROT_S));
  1329. REG_CLR_BIT(ah, AR_PHY_CCK_DETECT,
  1330. AR_FAST_DIV_ENABLE);
  1331. REG_CLR_BIT(ah, AR_PHY_RESTART,
  1332. AR_PHY_RESTART_ENABLE_DIV_M2FLAG);
  1333. REG_CLR_BIT(ah, AR_BTCOEX_WL_LNADIV,
  1334. AR_BTCOEX_WL_LNADIV_FORCE_ON);
  1335. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1336. regval &= ~(AR_PHY_ANT_DIV_MAIN_LNACONF |
  1337. AR_PHY_ANT_DIV_ALT_LNACONF |
  1338. AR_PHY_ANT_DIV_MAIN_GAINTB |
  1339. AR_PHY_ANT_DIV_ALT_GAINTB);
  1340. regval |= (ATH_ANT_DIV_COMB_LNA1 <<
  1341. AR_PHY_ANT_DIV_MAIN_LNACONF_S);
  1342. regval |= (ATH_ANT_DIV_COMB_LNA2 <<
  1343. AR_PHY_ANT_DIV_ALT_LNACONF_S);
  1344. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1345. }
  1346. }
  1347. }
  1348. #endif
  1349. static int ar9003_hw_fast_chan_change(struct ath_hw *ah,
  1350. struct ath9k_channel *chan,
  1351. u8 *ini_reloaded)
  1352. {
  1353. unsigned int regWrites = 0;
  1354. u32 modesIndex;
  1355. if (IS_CHAN_5GHZ(chan))
  1356. modesIndex = IS_CHAN_HT40(chan) ? 2 : 1;
  1357. else
  1358. modesIndex = IS_CHAN_HT40(chan) ? 3 : 4;
  1359. if (modesIndex == ah->modes_index) {
  1360. *ini_reloaded = false;
  1361. goto set_rfmode;
  1362. }
  1363. ar9003_hw_prog_ini(ah, &ah->iniSOC[ATH_INI_POST], modesIndex);
  1364. ar9003_hw_prog_ini(ah, &ah->iniMac[ATH_INI_POST], modesIndex);
  1365. ar9003_hw_prog_ini(ah, &ah->iniBB[ATH_INI_POST], modesIndex);
  1366. ar9003_hw_prog_ini(ah, &ah->iniRadio[ATH_INI_POST], modesIndex);
  1367. if (AR_SREV_9462_20_OR_LATER(ah))
  1368. ar9003_hw_prog_ini(ah, &ah->ini_radio_post_sys2ant,
  1369. modesIndex);
  1370. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  1371. if (AR_SREV_9462_20_OR_LATER(ah)) {
  1372. /*
  1373. * CUS217 mix LNA mode.
  1374. */
  1375. if (ar9003_hw_get_rx_gain_idx(ah) == 2) {
  1376. REG_WRITE_ARRAY(&ah->ini_modes_rxgain_bb_core,
  1377. 1, regWrites);
  1378. REG_WRITE_ARRAY(&ah->ini_modes_rxgain_bb_postamble,
  1379. modesIndex, regWrites);
  1380. }
  1381. }
  1382. /*
  1383. * For 5GHz channels requiring Fast Clock, apply
  1384. * different modal values.
  1385. */
  1386. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  1387. REG_WRITE_ARRAY(&ah->iniModesFastClock, modesIndex, regWrites);
  1388. if (AR_SREV_9565(ah))
  1389. REG_WRITE_ARRAY(&ah->iniModesFastClock, 1, regWrites);
  1390. /*
  1391. * JAPAN regulatory.
  1392. */
  1393. if (chan->channel == 2484)
  1394. ar9003_hw_prog_ini(ah, &ah->iniCckfirJapan2484, 1);
  1395. ah->modes_index = modesIndex;
  1396. *ini_reloaded = true;
  1397. set_rfmode:
  1398. ar9003_hw_set_rfmode(ah, chan);
  1399. return 0;
  1400. }
  1401. static void ar9003_hw_spectral_scan_config(struct ath_hw *ah,
  1402. struct ath_spec_scan *param)
  1403. {
  1404. u8 count;
  1405. if (!param->enabled) {
  1406. REG_CLR_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  1407. AR_PHY_SPECTRAL_SCAN_ENABLE);
  1408. return;
  1409. }
  1410. REG_SET_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_FFT_ENA);
  1411. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN, AR_PHY_SPECTRAL_SCAN_ENABLE);
  1412. /* on AR93xx and newer, count = 0 will make the the chip send
  1413. * spectral samples endlessly. Check if this really was intended,
  1414. * and fix otherwise.
  1415. */
  1416. count = param->count;
  1417. if (param->endless)
  1418. count = 0;
  1419. else if (param->count == 0)
  1420. count = 1;
  1421. if (param->short_repeat)
  1422. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  1423. AR_PHY_SPECTRAL_SCAN_SHORT_REPEAT);
  1424. else
  1425. REG_CLR_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  1426. AR_PHY_SPECTRAL_SCAN_SHORT_REPEAT);
  1427. REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN,
  1428. AR_PHY_SPECTRAL_SCAN_COUNT, count);
  1429. REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN,
  1430. AR_PHY_SPECTRAL_SCAN_PERIOD, param->period);
  1431. REG_RMW_FIELD(ah, AR_PHY_SPECTRAL_SCAN,
  1432. AR_PHY_SPECTRAL_SCAN_FFT_PERIOD, param->fft_period);
  1433. return;
  1434. }
  1435. static void ar9003_hw_spectral_scan_trigger(struct ath_hw *ah)
  1436. {
  1437. /* Activate spectral scan */
  1438. REG_SET_BIT(ah, AR_PHY_SPECTRAL_SCAN,
  1439. AR_PHY_SPECTRAL_SCAN_ACTIVE);
  1440. }
  1441. static void ar9003_hw_spectral_scan_wait(struct ath_hw *ah)
  1442. {
  1443. struct ath_common *common = ath9k_hw_common(ah);
  1444. /* Poll for spectral scan complete */
  1445. if (!ath9k_hw_wait(ah, AR_PHY_SPECTRAL_SCAN,
  1446. AR_PHY_SPECTRAL_SCAN_ACTIVE,
  1447. 0, AH_WAIT_TIMEOUT)) {
  1448. ath_err(common, "spectral scan wait failed\n");
  1449. return;
  1450. }
  1451. }
  1452. static void ar9003_hw_tx99_start(struct ath_hw *ah, u32 qnum)
  1453. {
  1454. REG_SET_BIT(ah, AR_PHY_TEST, PHY_AGC_CLR);
  1455. REG_SET_BIT(ah, 0x9864, 0x7f000);
  1456. REG_SET_BIT(ah, 0x9924, 0x7f00fe);
  1457. REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
  1458. REG_WRITE(ah, AR_CR, AR_CR_RXD);
  1459. REG_WRITE(ah, AR_DLCL_IFS(qnum), 0);
  1460. REG_WRITE(ah, AR_D_GBL_IFS_SIFS, 20); /* 50 OK */
  1461. REG_WRITE(ah, AR_D_GBL_IFS_EIFS, 20);
  1462. REG_WRITE(ah, AR_TIME_OUT, 0x00000400);
  1463. REG_WRITE(ah, AR_DRETRY_LIMIT(qnum), 0xffffffff);
  1464. REG_SET_BIT(ah, AR_QMISC(qnum), AR_Q_MISC_DCU_EARLY_TERM_REQ);
  1465. }
  1466. static void ar9003_hw_tx99_stop(struct ath_hw *ah)
  1467. {
  1468. REG_CLR_BIT(ah, AR_PHY_TEST, PHY_AGC_CLR);
  1469. REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
  1470. }
  1471. static void ar9003_hw_tx99_set_txpower(struct ath_hw *ah, u8 txpower)
  1472. {
  1473. static s16 p_pwr_array[ar9300RateSize] = { 0 };
  1474. unsigned int i;
  1475. if (txpower <= MAX_RATE_POWER) {
  1476. for (i = 0; i < ar9300RateSize; i++)
  1477. p_pwr_array[i] = txpower;
  1478. } else {
  1479. for (i = 0; i < ar9300RateSize; i++)
  1480. p_pwr_array[i] = MAX_RATE_POWER;
  1481. }
  1482. REG_WRITE(ah, 0xa458, 0);
  1483. REG_WRITE(ah, 0xa3c0,
  1484. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_LEGACY_6_24], 24) |
  1485. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_LEGACY_6_24], 16) |
  1486. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_LEGACY_6_24], 8) |
  1487. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_LEGACY_6_24], 0));
  1488. REG_WRITE(ah, 0xa3c4,
  1489. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_LEGACY_54], 24) |
  1490. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_LEGACY_48], 16) |
  1491. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_LEGACY_36], 8) |
  1492. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_LEGACY_6_24], 0));
  1493. REG_WRITE(ah, 0xa3c8,
  1494. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], 24) |
  1495. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], 16) |
  1496. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], 0));
  1497. REG_WRITE(ah, 0xa3cc,
  1498. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_LEGACY_11S], 24) |
  1499. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_LEGACY_11L], 16) |
  1500. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_LEGACY_5S], 8) |
  1501. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], 0));
  1502. REG_WRITE(ah, 0xa3d0,
  1503. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT20_5], 24) |
  1504. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT20_4], 16) |
  1505. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT20_1_3_9_11_17_19], 8)|
  1506. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT20_0_8_16], 0));
  1507. REG_WRITE(ah, 0xa3d4,
  1508. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT20_13], 24) |
  1509. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT20_12], 16) |
  1510. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT20_7], 8) |
  1511. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT20_6], 0));
  1512. REG_WRITE(ah, 0xa3e4,
  1513. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT20_21], 24) |
  1514. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT20_20], 16) |
  1515. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT20_15], 8) |
  1516. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT20_14], 0));
  1517. REG_WRITE(ah, 0xa3e8,
  1518. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT40_23], 24) |
  1519. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT40_22], 16) |
  1520. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT20_23], 8) |
  1521. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT20_22], 0));
  1522. REG_WRITE(ah, 0xa3d8,
  1523. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT40_5], 24) |
  1524. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT40_4], 16) |
  1525. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT40_1_3_9_11_17_19], 8) |
  1526. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT40_0_8_16], 0));
  1527. REG_WRITE(ah, 0xa3dc,
  1528. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT40_13], 24) |
  1529. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT40_12], 16) |
  1530. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT40_7], 8) |
  1531. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT40_6], 0));
  1532. REG_WRITE(ah, 0xa3ec,
  1533. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT40_21], 24) |
  1534. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT40_20], 16) |
  1535. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT40_15], 8) |
  1536. ATH9K_POW_SM(p_pwr_array[ALL_TARGET_HT40_14], 0));
  1537. }
  1538. void ar9003_hw_attach_phy_ops(struct ath_hw *ah)
  1539. {
  1540. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  1541. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  1542. static const u32 ar9300_cca_regs[6] = {
  1543. AR_PHY_CCA_0,
  1544. AR_PHY_CCA_1,
  1545. AR_PHY_CCA_2,
  1546. AR_PHY_EXT_CCA,
  1547. AR_PHY_EXT_CCA_1,
  1548. AR_PHY_EXT_CCA_2,
  1549. };
  1550. priv_ops->rf_set_freq = ar9003_hw_set_channel;
  1551. priv_ops->spur_mitigate_freq = ar9003_hw_spur_mitigate;
  1552. priv_ops->compute_pll_control = ar9003_hw_compute_pll_control;
  1553. priv_ops->set_channel_regs = ar9003_hw_set_channel_regs;
  1554. priv_ops->init_bb = ar9003_hw_init_bb;
  1555. priv_ops->process_ini = ar9003_hw_process_ini;
  1556. priv_ops->set_rfmode = ar9003_hw_set_rfmode;
  1557. priv_ops->mark_phy_inactive = ar9003_hw_mark_phy_inactive;
  1558. priv_ops->set_delta_slope = ar9003_hw_set_delta_slope;
  1559. priv_ops->rfbus_req = ar9003_hw_rfbus_req;
  1560. priv_ops->rfbus_done = ar9003_hw_rfbus_done;
  1561. priv_ops->ani_control = ar9003_hw_ani_control;
  1562. priv_ops->do_getnf = ar9003_hw_do_getnf;
  1563. priv_ops->ani_cache_ini_regs = ar9003_hw_ani_cache_ini_regs;
  1564. priv_ops->set_radar_params = ar9003_hw_set_radar_params;
  1565. priv_ops->fast_chan_change = ar9003_hw_fast_chan_change;
  1566. ops->antdiv_comb_conf_get = ar9003_hw_antdiv_comb_conf_get;
  1567. ops->antdiv_comb_conf_set = ar9003_hw_antdiv_comb_conf_set;
  1568. ops->spectral_scan_config = ar9003_hw_spectral_scan_config;
  1569. ops->spectral_scan_trigger = ar9003_hw_spectral_scan_trigger;
  1570. ops->spectral_scan_wait = ar9003_hw_spectral_scan_wait;
  1571. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  1572. ops->set_bt_ant_diversity = ar9003_hw_set_bt_ant_diversity;
  1573. #endif
  1574. ops->tx99_start = ar9003_hw_tx99_start;
  1575. ops->tx99_stop = ar9003_hw_tx99_stop;
  1576. ops->tx99_set_txpower = ar9003_hw_tx99_set_txpower;
  1577. ar9003_hw_set_nf_limits(ah);
  1578. ar9003_hw_set_radar_conf(ah);
  1579. memcpy(ah->nf_regs, ar9300_cca_regs, sizeof(ah->nf_regs));
  1580. }
  1581. /*
  1582. * Baseband Watchdog signatures:
  1583. *
  1584. * 0x04000539: BB hang when operating in HT40 DFS Channel.
  1585. * Full chip reset is not required, but a recovery
  1586. * mechanism is needed.
  1587. *
  1588. * 0x1300000a: Related to CAC deafness.
  1589. * Chip reset is not required.
  1590. *
  1591. * 0x0400000a: Related to CAC deafness.
  1592. * Full chip reset is required.
  1593. *
  1594. * 0x04000b09: RX state machine gets into an illegal state
  1595. * when a packet with unsupported rate is received.
  1596. * Full chip reset is required and PHY_RESTART has
  1597. * to be disabled.
  1598. *
  1599. * 0x04000409: Packet stuck on receive.
  1600. * Full chip reset is required for all chips except AR9340.
  1601. */
  1602. /*
  1603. * ar9003_hw_bb_watchdog_check(): Returns true if a chip reset is required.
  1604. */
  1605. bool ar9003_hw_bb_watchdog_check(struct ath_hw *ah)
  1606. {
  1607. u32 val;
  1608. switch(ah->bb_watchdog_last_status) {
  1609. case 0x04000539:
  1610. val = REG_READ(ah, AR_PHY_RADAR_0);
  1611. val &= (~AR_PHY_RADAR_0_FIRPWR);
  1612. val |= SM(0x7f, AR_PHY_RADAR_0_FIRPWR);
  1613. REG_WRITE(ah, AR_PHY_RADAR_0, val);
  1614. udelay(1);
  1615. val = REG_READ(ah, AR_PHY_RADAR_0);
  1616. val &= ~AR_PHY_RADAR_0_FIRPWR;
  1617. val |= SM(AR9300_DFS_FIRPWR, AR_PHY_RADAR_0_FIRPWR);
  1618. REG_WRITE(ah, AR_PHY_RADAR_0, val);
  1619. return false;
  1620. case 0x1300000a:
  1621. return false;
  1622. case 0x0400000a:
  1623. case 0x04000b09:
  1624. return true;
  1625. case 0x04000409:
  1626. if (AR_SREV_9340(ah) || AR_SREV_9531(ah))
  1627. return false;
  1628. else
  1629. return true;
  1630. default:
  1631. /*
  1632. * For any other unknown signatures, do a
  1633. * full chip reset.
  1634. */
  1635. return true;
  1636. }
  1637. }
  1638. EXPORT_SYMBOL(ar9003_hw_bb_watchdog_check);
  1639. void ar9003_hw_bb_watchdog_config(struct ath_hw *ah)
  1640. {
  1641. struct ath_common *common = ath9k_hw_common(ah);
  1642. u32 idle_tmo_ms = ah->bb_watchdog_timeout_ms;
  1643. u32 val, idle_count;
  1644. if (!idle_tmo_ms) {
  1645. /* disable IRQ, disable chip-reset for BB panic */
  1646. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
  1647. REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) &
  1648. ~(AR_PHY_WATCHDOG_RST_ENABLE |
  1649. AR_PHY_WATCHDOG_IRQ_ENABLE));
  1650. /* disable watchdog in non-IDLE mode, disable in IDLE mode */
  1651. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
  1652. REG_READ(ah, AR_PHY_WATCHDOG_CTL_1) &
  1653. ~(AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
  1654. AR_PHY_WATCHDOG_IDLE_ENABLE));
  1655. ath_dbg(common, RESET, "Disabled BB Watchdog\n");
  1656. return;
  1657. }
  1658. /* enable IRQ, disable chip-reset for BB watchdog */
  1659. val = REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) & AR_PHY_WATCHDOG_CNTL2_MASK;
  1660. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
  1661. (val | AR_PHY_WATCHDOG_IRQ_ENABLE) &
  1662. ~AR_PHY_WATCHDOG_RST_ENABLE);
  1663. /* bound limit to 10 secs */
  1664. if (idle_tmo_ms > 10000)
  1665. idle_tmo_ms = 10000;
  1666. /*
  1667. * The time unit for watchdog event is 2^15 44/88MHz cycles.
  1668. *
  1669. * For HT20 we have a time unit of 2^15/44 MHz = .74 ms per tick
  1670. * For HT40 we have a time unit of 2^15/88 MHz = .37 ms per tick
  1671. *
  1672. * Given we use fast clock now in 5 GHz, these time units should
  1673. * be common for both 2 GHz and 5 GHz.
  1674. */
  1675. idle_count = (100 * idle_tmo_ms) / 74;
  1676. if (ah->curchan && IS_CHAN_HT40(ah->curchan))
  1677. idle_count = (100 * idle_tmo_ms) / 37;
  1678. /*
  1679. * enable watchdog in non-IDLE mode, disable in IDLE mode,
  1680. * set idle time-out.
  1681. */
  1682. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
  1683. AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
  1684. AR_PHY_WATCHDOG_IDLE_MASK |
  1685. (AR_PHY_WATCHDOG_NON_IDLE_MASK & (idle_count << 2)));
  1686. ath_dbg(common, RESET, "Enabled BB Watchdog timeout (%u ms)\n",
  1687. idle_tmo_ms);
  1688. }
  1689. void ar9003_hw_bb_watchdog_read(struct ath_hw *ah)
  1690. {
  1691. /*
  1692. * we want to avoid printing in ISR context so we save the
  1693. * watchdog status to be printed later in bottom half context.
  1694. */
  1695. ah->bb_watchdog_last_status = REG_READ(ah, AR_PHY_WATCHDOG_STATUS);
  1696. /*
  1697. * the watchdog timer should reset on status read but to be sure
  1698. * sure we write 0 to the watchdog status bit.
  1699. */
  1700. REG_WRITE(ah, AR_PHY_WATCHDOG_STATUS,
  1701. ah->bb_watchdog_last_status & ~AR_PHY_WATCHDOG_STATUS_CLR);
  1702. }
  1703. void ar9003_hw_bb_watchdog_dbg_info(struct ath_hw *ah)
  1704. {
  1705. struct ath_common *common = ath9k_hw_common(ah);
  1706. u32 status;
  1707. if (likely(!(common->debug_mask & ATH_DBG_RESET)))
  1708. return;
  1709. status = ah->bb_watchdog_last_status;
  1710. ath_dbg(common, RESET,
  1711. "\n==== BB update: BB status=0x%08x ====\n", status);
  1712. ath_dbg(common, RESET,
  1713. "** BB state: wd=%u det=%u rdar=%u rOFDM=%d rCCK=%u tOFDM=%u tCCK=%u agc=%u src=%u **\n",
  1714. MS(status, AR_PHY_WATCHDOG_INFO),
  1715. MS(status, AR_PHY_WATCHDOG_DET_HANG),
  1716. MS(status, AR_PHY_WATCHDOG_RADAR_SM),
  1717. MS(status, AR_PHY_WATCHDOG_RX_OFDM_SM),
  1718. MS(status, AR_PHY_WATCHDOG_RX_CCK_SM),
  1719. MS(status, AR_PHY_WATCHDOG_TX_OFDM_SM),
  1720. MS(status, AR_PHY_WATCHDOG_TX_CCK_SM),
  1721. MS(status, AR_PHY_WATCHDOG_AGC_SM),
  1722. MS(status, AR_PHY_WATCHDOG_SRCH_SM));
  1723. ath_dbg(common, RESET, "** BB WD cntl: cntl1=0x%08x cntl2=0x%08x **\n",
  1724. REG_READ(ah, AR_PHY_WATCHDOG_CTL_1),
  1725. REG_READ(ah, AR_PHY_WATCHDOG_CTL_2));
  1726. ath_dbg(common, RESET, "** BB mode: BB_gen_controls=0x%08x **\n",
  1727. REG_READ(ah, AR_PHY_GEN_CTRL));
  1728. #define PCT(_field) (common->cc_survey._field * 100 / common->cc_survey.cycles)
  1729. if (common->cc_survey.cycles)
  1730. ath_dbg(common, RESET,
  1731. "** BB busy times: rx_clear=%d%%, rx_frame=%d%%, tx_frame=%d%% **\n",
  1732. PCT(rx_busy), PCT(rx_frame), PCT(tx_frame));
  1733. ath_dbg(common, RESET, "==== BB update: done ====\n\n");
  1734. }
  1735. EXPORT_SYMBOL(ar9003_hw_bb_watchdog_dbg_info);
  1736. void ar9003_hw_disable_phy_restart(struct ath_hw *ah)
  1737. {
  1738. u8 result;
  1739. u32 val;
  1740. /* While receiving unsupported rate frame rx state machine
  1741. * gets into a state 0xb and if phy_restart happens in that
  1742. * state, BB would go hang. If RXSM is in 0xb state after
  1743. * first bb panic, ensure to disable the phy_restart.
  1744. */
  1745. result = MS(ah->bb_watchdog_last_status, AR_PHY_WATCHDOG_RX_OFDM_SM);
  1746. if ((result == 0xb) || ah->bb_hang_rx_ofdm) {
  1747. ah->bb_hang_rx_ofdm = true;
  1748. val = REG_READ(ah, AR_PHY_RESTART);
  1749. val &= ~AR_PHY_RESTART_ENA;
  1750. REG_WRITE(ah, AR_PHY_RESTART, val);
  1751. }
  1752. }
  1753. EXPORT_SYMBOL(ar9003_hw_disable_phy_restart);