ar9003_phy.c 64 KB

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