ar9003_phy.c 65 KB

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