phy_common.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2012 Realtek Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * The full GNU General Public License is included in this distribution in the
  19. * file called LICENSE.
  20. *
  21. * Contact Information:
  22. * wlanfae <wlanfae@realtek.com>
  23. * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  24. * Hsinchu 300, Taiwan.
  25. *
  26. * Larry Finger <Larry.Finger@lwfinger.net>
  27. *
  28. *****************************************************************************/
  29. #include "../wifi.h"
  30. #include "../rtl8192ce/reg.h"
  31. #include "../rtl8192ce/def.h"
  32. #include "dm_common.h"
  33. #include "fw_common.h"
  34. #include "phy_common.h"
  35. #include <linux/export.h>
  36. u32 rtl92c_phy_query_bb_reg(struct ieee80211_hw *hw, u32 regaddr, u32 bitmask)
  37. {
  38. struct rtl_priv *rtlpriv = rtl_priv(hw);
  39. u32 returnvalue, originalvalue, bitshift;
  40. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE, "regaddr(%#x), bitmask(%#x)\n",
  41. regaddr, bitmask);
  42. originalvalue = rtl_read_dword(rtlpriv, regaddr);
  43. bitshift = _rtl92c_phy_calculate_bit_shift(bitmask);
  44. returnvalue = (originalvalue & bitmask) >> bitshift;
  45. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
  46. "BBR MASK=0x%x Addr[0x%x]=0x%x\n",
  47. bitmask, regaddr, originalvalue);
  48. return returnvalue;
  49. }
  50. EXPORT_SYMBOL(rtl92c_phy_query_bb_reg);
  51. void rtl92c_phy_set_bb_reg(struct ieee80211_hw *hw,
  52. u32 regaddr, u32 bitmask, u32 data)
  53. {
  54. struct rtl_priv *rtlpriv = rtl_priv(hw);
  55. u32 originalvalue, bitshift;
  56. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
  57. "regaddr(%#x), bitmask(%#x), data(%#x)\n",
  58. regaddr, bitmask, data);
  59. if (bitmask != MASKDWORD) {
  60. originalvalue = rtl_read_dword(rtlpriv, regaddr);
  61. bitshift = _rtl92c_phy_calculate_bit_shift(bitmask);
  62. data = ((originalvalue & (~bitmask)) | (data << bitshift));
  63. }
  64. rtl_write_dword(rtlpriv, regaddr, data);
  65. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
  66. "regaddr(%#x), bitmask(%#x), data(%#x)\n",
  67. regaddr, bitmask, data);
  68. }
  69. EXPORT_SYMBOL(rtl92c_phy_set_bb_reg);
  70. u32 _rtl92c_phy_fw_rf_serial_read(struct ieee80211_hw *hw,
  71. enum radio_path rfpath, u32 offset)
  72. {
  73. RT_ASSERT(false, "deprecated!\n");
  74. return 0;
  75. }
  76. EXPORT_SYMBOL(_rtl92c_phy_fw_rf_serial_read);
  77. void _rtl92c_phy_fw_rf_serial_write(struct ieee80211_hw *hw,
  78. enum radio_path rfpath, u32 offset,
  79. u32 data)
  80. {
  81. RT_ASSERT(false, "deprecated!\n");
  82. }
  83. EXPORT_SYMBOL(_rtl92c_phy_fw_rf_serial_write);
  84. u32 _rtl92c_phy_rf_serial_read(struct ieee80211_hw *hw,
  85. enum radio_path rfpath, u32 offset)
  86. {
  87. struct rtl_priv *rtlpriv = rtl_priv(hw);
  88. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  89. struct bb_reg_def *pphyreg = &rtlphy->phyreg_def[rfpath];
  90. u32 newoffset;
  91. u32 tmplong, tmplong2;
  92. u8 rfpi_enable = 0;
  93. u32 retvalue;
  94. offset &= 0x3f;
  95. newoffset = offset;
  96. if (RT_CANNOT_IO(hw)) {
  97. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "return all one\n");
  98. return 0xFFFFFFFF;
  99. }
  100. tmplong = rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, MASKDWORD);
  101. if (rfpath == RF90_PATH_A)
  102. tmplong2 = tmplong;
  103. else
  104. tmplong2 = rtl_get_bbreg(hw, pphyreg->rfhssi_para2, MASKDWORD);
  105. tmplong2 = (tmplong2 & (~BLSSIREADADDRESS)) |
  106. (newoffset << 23) | BLSSIREADEDGE;
  107. rtl_set_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, MASKDWORD,
  108. tmplong & (~BLSSIREADEDGE));
  109. mdelay(1);
  110. rtl_set_bbreg(hw, pphyreg->rfhssi_para2, MASKDWORD, tmplong2);
  111. mdelay(1);
  112. rtl_set_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, MASKDWORD,
  113. tmplong | BLSSIREADEDGE);
  114. mdelay(1);
  115. if (rfpath == RF90_PATH_A)
  116. rfpi_enable = (u8)rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER1,
  117. BIT(8));
  118. else if (rfpath == RF90_PATH_B)
  119. rfpi_enable = (u8)rtl_get_bbreg(hw, RFPGA0_XB_HSSIPARAMETER1,
  120. BIT(8));
  121. if (rfpi_enable)
  122. retvalue = rtl_get_bbreg(hw, pphyreg->rf_rbpi,
  123. BLSSIREADBACKDATA);
  124. else
  125. retvalue = rtl_get_bbreg(hw, pphyreg->rf_rb,
  126. BLSSIREADBACKDATA);
  127. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE, "RFR-%d Addr[0x%x]=0x%x\n",
  128. rfpath, pphyreg->rf_rb,
  129. retvalue);
  130. return retvalue;
  131. }
  132. EXPORT_SYMBOL(_rtl92c_phy_rf_serial_read);
  133. void _rtl92c_phy_rf_serial_write(struct ieee80211_hw *hw,
  134. enum radio_path rfpath, u32 offset,
  135. u32 data)
  136. {
  137. u32 data_and_addr;
  138. u32 newoffset;
  139. struct rtl_priv *rtlpriv = rtl_priv(hw);
  140. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  141. struct bb_reg_def *pphyreg = &rtlphy->phyreg_def[rfpath];
  142. if (RT_CANNOT_IO(hw)) {
  143. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "stop\n");
  144. return;
  145. }
  146. offset &= 0x3f;
  147. newoffset = offset;
  148. data_and_addr = ((newoffset << 20) | (data & 0x000fffff)) & 0x0fffffff;
  149. rtl_set_bbreg(hw, pphyreg->rf3wire_offset, MASKDWORD, data_and_addr);
  150. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE, "RFW-%d Addr[0x%x]=0x%x\n",
  151. rfpath, pphyreg->rf3wire_offset,
  152. data_and_addr);
  153. }
  154. EXPORT_SYMBOL(_rtl92c_phy_rf_serial_write);
  155. u32 _rtl92c_phy_calculate_bit_shift(u32 bitmask)
  156. {
  157. u32 i;
  158. for (i = 0; i <= 31; i++) {
  159. if (((bitmask >> i) & 0x1) == 1)
  160. break;
  161. }
  162. return i;
  163. }
  164. EXPORT_SYMBOL(_rtl92c_phy_calculate_bit_shift);
  165. static void _rtl92c_phy_bb_config_1t(struct ieee80211_hw *hw)
  166. {
  167. rtl_set_bbreg(hw, RFPGA0_TXINFO, 0x3, 0x2);
  168. rtl_set_bbreg(hw, RFPGA1_TXINFO, 0x300033, 0x200022);
  169. rtl_set_bbreg(hw, RCCK0_AFESETTING, MASKBYTE3, 0x45);
  170. rtl_set_bbreg(hw, ROFDM0_TRXPATHENABLE, MASKBYTE0, 0x23);
  171. rtl_set_bbreg(hw, ROFDM0_AGCPARAMETER1, 0x30, 0x1);
  172. rtl_set_bbreg(hw, 0xe74, 0x0c000000, 0x2);
  173. rtl_set_bbreg(hw, 0xe78, 0x0c000000, 0x2);
  174. rtl_set_bbreg(hw, 0xe7c, 0x0c000000, 0x2);
  175. rtl_set_bbreg(hw, 0xe80, 0x0c000000, 0x2);
  176. rtl_set_bbreg(hw, 0xe88, 0x0c000000, 0x2);
  177. }
  178. bool rtl92c_phy_rf_config(struct ieee80211_hw *hw)
  179. {
  180. struct rtl_priv *rtlpriv = rtl_priv(hw);
  181. return rtlpriv->cfg->ops->phy_rf6052_config(hw);
  182. }
  183. EXPORT_SYMBOL(rtl92c_phy_rf_config);
  184. bool _rtl92c_phy_bb8192c_config_parafile(struct ieee80211_hw *hw)
  185. {
  186. struct rtl_priv *rtlpriv = rtl_priv(hw);
  187. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  188. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  189. bool rtstatus;
  190. rtstatus = rtlpriv->cfg->ops->config_bb_with_headerfile(hw,
  191. BASEBAND_CONFIG_PHY_REG);
  192. if (!rtstatus) {
  193. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Write BB Reg Fail!!");
  194. return false;
  195. }
  196. if (rtlphy->rf_type == RF_1T2R) {
  197. _rtl92c_phy_bb_config_1t(hw);
  198. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "Config to 1T!!\n");
  199. }
  200. if (rtlefuse->autoload_failflag == false) {
  201. rtlphy->pwrgroup_cnt = 0;
  202. rtstatus = rtlpriv->cfg->ops->config_bb_with_pgheaderfile(hw,
  203. BASEBAND_CONFIG_PHY_REG);
  204. }
  205. if (!rtstatus) {
  206. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "BB_PG Reg Fail!!");
  207. return false;
  208. }
  209. rtstatus = rtlpriv->cfg->ops->config_bb_with_headerfile(hw,
  210. BASEBAND_CONFIG_AGC_TAB);
  211. if (!rtstatus) {
  212. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "AGC Table Fail\n");
  213. return false;
  214. }
  215. rtlphy->cck_high_power =
  216. (bool)(rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, 0x200));
  217. return true;
  218. }
  219. EXPORT_SYMBOL(_rtl92c_phy_bb8192c_config_parafile);
  220. void _rtl92c_store_pwrIndex_diffrate_offset(struct ieee80211_hw *hw,
  221. u32 regaddr, u32 bitmask,
  222. u32 data)
  223. {
  224. struct rtl_priv *rtlpriv = rtl_priv(hw);
  225. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  226. if (regaddr == RTXAGC_A_RATE18_06) {
  227. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][0] =
  228. data;
  229. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  230. "MCSTxPowerLevelOriginalOffset[%d][0] = 0x%x\n",
  231. rtlphy->pwrgroup_cnt,
  232. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
  233. pwrgroup_cnt][0]);
  234. }
  235. if (regaddr == RTXAGC_A_RATE54_24) {
  236. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][1] =
  237. data;
  238. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  239. "MCSTxPowerLevelOriginalOffset[%d][1] = 0x%x\n",
  240. rtlphy->pwrgroup_cnt,
  241. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
  242. pwrgroup_cnt][1]);
  243. }
  244. if (regaddr == RTXAGC_A_CCK1_MCS32) {
  245. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][6] =
  246. data;
  247. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  248. "MCSTxPowerLevelOriginalOffset[%d][6] = 0x%x\n",
  249. rtlphy->pwrgroup_cnt,
  250. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
  251. pwrgroup_cnt][6]);
  252. }
  253. if (regaddr == RTXAGC_B_CCK11_A_CCK2_11 && bitmask == 0xffffff00) {
  254. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][7] =
  255. data;
  256. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  257. "MCSTxPowerLevelOriginalOffset[%d][7] = 0x%x\n",
  258. rtlphy->pwrgroup_cnt,
  259. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
  260. pwrgroup_cnt][7]);
  261. }
  262. if (regaddr == RTXAGC_A_MCS03_MCS00) {
  263. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][2] =
  264. data;
  265. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  266. "MCSTxPowerLevelOriginalOffset[%d][2] = 0x%x\n",
  267. rtlphy->pwrgroup_cnt,
  268. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
  269. pwrgroup_cnt][2]);
  270. }
  271. if (regaddr == RTXAGC_A_MCS07_MCS04) {
  272. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][3] =
  273. data;
  274. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  275. "MCSTxPowerLevelOriginalOffset[%d][3] = 0x%x\n",
  276. rtlphy->pwrgroup_cnt,
  277. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
  278. pwrgroup_cnt][3]);
  279. }
  280. if (regaddr == RTXAGC_A_MCS11_MCS08) {
  281. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][4] =
  282. data;
  283. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  284. "MCSTxPowerLevelOriginalOffset[%d][4] = 0x%x\n",
  285. rtlphy->pwrgroup_cnt,
  286. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
  287. pwrgroup_cnt][4]);
  288. }
  289. if (regaddr == RTXAGC_A_MCS15_MCS12) {
  290. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][5] =
  291. data;
  292. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  293. "MCSTxPowerLevelOriginalOffset[%d][5] = 0x%x\n",
  294. rtlphy->pwrgroup_cnt,
  295. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
  296. pwrgroup_cnt][5]);
  297. }
  298. if (regaddr == RTXAGC_B_RATE18_06) {
  299. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][8] =
  300. data;
  301. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  302. "MCSTxPowerLevelOriginalOffset[%d][8] = 0x%x\n",
  303. rtlphy->pwrgroup_cnt,
  304. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
  305. pwrgroup_cnt][8]);
  306. }
  307. if (regaddr == RTXAGC_B_RATE54_24) {
  308. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][9] =
  309. data;
  310. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  311. "MCSTxPowerLevelOriginalOffset[%d][9] = 0x%x\n",
  312. rtlphy->pwrgroup_cnt,
  313. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
  314. pwrgroup_cnt][9]);
  315. }
  316. if (regaddr == RTXAGC_B_CCK1_55_MCS32) {
  317. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][14] =
  318. data;
  319. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  320. "MCSTxPowerLevelOriginalOffset[%d][14] = 0x%x\n",
  321. rtlphy->pwrgroup_cnt,
  322. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
  323. pwrgroup_cnt][14]);
  324. }
  325. if (regaddr == RTXAGC_B_CCK11_A_CCK2_11 && bitmask == 0x000000ff) {
  326. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][15] =
  327. data;
  328. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  329. "MCSTxPowerLevelOriginalOffset[%d][15] = 0x%x\n",
  330. rtlphy->pwrgroup_cnt,
  331. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
  332. pwrgroup_cnt][15]);
  333. }
  334. if (regaddr == RTXAGC_B_MCS03_MCS00) {
  335. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][10] =
  336. data;
  337. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  338. "MCSTxPowerLevelOriginalOffset[%d][10] = 0x%x\n",
  339. rtlphy->pwrgroup_cnt,
  340. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
  341. pwrgroup_cnt][10]);
  342. }
  343. if (regaddr == RTXAGC_B_MCS07_MCS04) {
  344. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][11] =
  345. data;
  346. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  347. "MCSTxPowerLevelOriginalOffset[%d][11] = 0x%x\n",
  348. rtlphy->pwrgroup_cnt,
  349. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
  350. pwrgroup_cnt][11]);
  351. }
  352. if (regaddr == RTXAGC_B_MCS11_MCS08) {
  353. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][12] =
  354. data;
  355. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  356. "MCSTxPowerLevelOriginalOffset[%d][12] = 0x%x\n",
  357. rtlphy->pwrgroup_cnt,
  358. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
  359. pwrgroup_cnt][12]);
  360. }
  361. if (regaddr == RTXAGC_B_MCS15_MCS12) {
  362. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][13] =
  363. data;
  364. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  365. "MCSTxPowerLevelOriginalOffset[%d][13] = 0x%x\n",
  366. rtlphy->pwrgroup_cnt,
  367. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->
  368. pwrgroup_cnt][13]);
  369. rtlphy->pwrgroup_cnt++;
  370. }
  371. }
  372. EXPORT_SYMBOL(_rtl92c_store_pwrIndex_diffrate_offset);
  373. void rtl92c_phy_get_hw_reg_originalvalue(struct ieee80211_hw *hw)
  374. {
  375. struct rtl_priv *rtlpriv = rtl_priv(hw);
  376. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  377. rtlphy->default_initialgain[0] =
  378. (u8)rtl_get_bbreg(hw, ROFDM0_XAAGCCORE1, MASKBYTE0);
  379. rtlphy->default_initialgain[1] =
  380. (u8)rtl_get_bbreg(hw, ROFDM0_XBAGCCORE1, MASKBYTE0);
  381. rtlphy->default_initialgain[2] =
  382. (u8)rtl_get_bbreg(hw, ROFDM0_XCAGCCORE1, MASKBYTE0);
  383. rtlphy->default_initialgain[3] =
  384. (u8)rtl_get_bbreg(hw, ROFDM0_XDAGCCORE1, MASKBYTE0);
  385. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  386. "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x\n",
  387. rtlphy->default_initialgain[0],
  388. rtlphy->default_initialgain[1],
  389. rtlphy->default_initialgain[2],
  390. rtlphy->default_initialgain[3]);
  391. rtlphy->framesync = (u8)rtl_get_bbreg(hw,
  392. ROFDM0_RXDETECTOR3, MASKBYTE0);
  393. rtlphy->framesync_c34 = rtl_get_bbreg(hw,
  394. ROFDM0_RXDETECTOR2, MASKDWORD);
  395. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  396. "Default framesync (0x%x) = 0x%x\n",
  397. ROFDM0_RXDETECTOR3, rtlphy->framesync);
  398. }
  399. void _rtl92c_phy_init_bb_rf_register_definition(struct ieee80211_hw *hw)
  400. {
  401. struct rtl_priv *rtlpriv = rtl_priv(hw);
  402. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  403. rtlphy->phyreg_def[RF90_PATH_A].rfintfs = RFPGA0_XAB_RFINTERFACESW;
  404. rtlphy->phyreg_def[RF90_PATH_B].rfintfs = RFPGA0_XAB_RFINTERFACESW;
  405. rtlphy->phyreg_def[RF90_PATH_C].rfintfs = RFPGA0_XCD_RFINTERFACESW;
  406. rtlphy->phyreg_def[RF90_PATH_D].rfintfs = RFPGA0_XCD_RFINTERFACESW;
  407. rtlphy->phyreg_def[RF90_PATH_A].rfintfi = RFPGA0_XAB_RFINTERFACERB;
  408. rtlphy->phyreg_def[RF90_PATH_B].rfintfi = RFPGA0_XAB_RFINTERFACERB;
  409. rtlphy->phyreg_def[RF90_PATH_C].rfintfi = RFPGA0_XCD_RFINTERFACERB;
  410. rtlphy->phyreg_def[RF90_PATH_D].rfintfi = RFPGA0_XCD_RFINTERFACERB;
  411. rtlphy->phyreg_def[RF90_PATH_A].rfintfo = RFPGA0_XA_RFINTERFACEOE;
  412. rtlphy->phyreg_def[RF90_PATH_B].rfintfo = RFPGA0_XB_RFINTERFACEOE;
  413. rtlphy->phyreg_def[RF90_PATH_A].rfintfe = RFPGA0_XA_RFINTERFACEOE;
  414. rtlphy->phyreg_def[RF90_PATH_B].rfintfe = RFPGA0_XB_RFINTERFACEOE;
  415. rtlphy->phyreg_def[RF90_PATH_A].rf3wire_offset =
  416. RFPGA0_XA_LSSIPARAMETER;
  417. rtlphy->phyreg_def[RF90_PATH_B].rf3wire_offset =
  418. RFPGA0_XB_LSSIPARAMETER;
  419. rtlphy->phyreg_def[RF90_PATH_A].rflssi_select = rFPGA0_XAB_RFPARAMETER;
  420. rtlphy->phyreg_def[RF90_PATH_B].rflssi_select = rFPGA0_XAB_RFPARAMETER;
  421. rtlphy->phyreg_def[RF90_PATH_C].rflssi_select = rFPGA0_XCD_RFPARAMETER;
  422. rtlphy->phyreg_def[RF90_PATH_D].rflssi_select = rFPGA0_XCD_RFPARAMETER;
  423. rtlphy->phyreg_def[RF90_PATH_A].rftxgain_stage = RFPGA0_TXGAINSTAGE;
  424. rtlphy->phyreg_def[RF90_PATH_B].rftxgain_stage = RFPGA0_TXGAINSTAGE;
  425. rtlphy->phyreg_def[RF90_PATH_C].rftxgain_stage = RFPGA0_TXGAINSTAGE;
  426. rtlphy->phyreg_def[RF90_PATH_D].rftxgain_stage = RFPGA0_TXGAINSTAGE;
  427. rtlphy->phyreg_def[RF90_PATH_A].rfhssi_para1 = RFPGA0_XA_HSSIPARAMETER1;
  428. rtlphy->phyreg_def[RF90_PATH_B].rfhssi_para1 = RFPGA0_XB_HSSIPARAMETER1;
  429. rtlphy->phyreg_def[RF90_PATH_A].rfhssi_para2 = RFPGA0_XA_HSSIPARAMETER2;
  430. rtlphy->phyreg_def[RF90_PATH_B].rfhssi_para2 = RFPGA0_XB_HSSIPARAMETER2;
  431. rtlphy->phyreg_def[RF90_PATH_A].rfsw_ctrl = RFPGA0_XAB_SWITCHCONTROL;
  432. rtlphy->phyreg_def[RF90_PATH_B].rfsw_ctrl = RFPGA0_XAB_SWITCHCONTROL;
  433. rtlphy->phyreg_def[RF90_PATH_C].rfsw_ctrl = RFPGA0_XCD_SWITCHCONTROL;
  434. rtlphy->phyreg_def[RF90_PATH_D].rfsw_ctrl = RFPGA0_XCD_SWITCHCONTROL;
  435. rtlphy->phyreg_def[RF90_PATH_A].rfagc_control1 = ROFDM0_XAAGCCORE1;
  436. rtlphy->phyreg_def[RF90_PATH_B].rfagc_control1 = ROFDM0_XBAGCCORE1;
  437. rtlphy->phyreg_def[RF90_PATH_C].rfagc_control1 = ROFDM0_XCAGCCORE1;
  438. rtlphy->phyreg_def[RF90_PATH_D].rfagc_control1 = ROFDM0_XDAGCCORE1;
  439. rtlphy->phyreg_def[RF90_PATH_A].rfagc_control2 = ROFDM0_XAAGCCORE2;
  440. rtlphy->phyreg_def[RF90_PATH_B].rfagc_control2 = ROFDM0_XBAGCCORE2;
  441. rtlphy->phyreg_def[RF90_PATH_C].rfagc_control2 = ROFDM0_XCAGCCORE2;
  442. rtlphy->phyreg_def[RF90_PATH_D].rfagc_control2 = ROFDM0_XDAGCCORE2;
  443. rtlphy->phyreg_def[RF90_PATH_A].rfrxiq_imbal = ROFDM0_XARXIQIMBALANCE;
  444. rtlphy->phyreg_def[RF90_PATH_B].rfrxiq_imbal = ROFDM0_XBRXIQIMBALANCE;
  445. rtlphy->phyreg_def[RF90_PATH_C].rfrxiq_imbal = ROFDM0_XCRXIQIMBANLANCE;
  446. rtlphy->phyreg_def[RF90_PATH_D].rfrxiq_imbal = ROFDM0_XDRXIQIMBALANCE;
  447. rtlphy->phyreg_def[RF90_PATH_A].rfrx_afe = ROFDM0_XARXAFE;
  448. rtlphy->phyreg_def[RF90_PATH_B].rfrx_afe = ROFDM0_XBRXAFE;
  449. rtlphy->phyreg_def[RF90_PATH_C].rfrx_afe = ROFDM0_XCRXAFE;
  450. rtlphy->phyreg_def[RF90_PATH_D].rfrx_afe = ROFDM0_XDRXAFE;
  451. rtlphy->phyreg_def[RF90_PATH_A].rftxiq_imbal = ROFDM0_XATXIQIMBALANCE;
  452. rtlphy->phyreg_def[RF90_PATH_B].rftxiq_imbal = ROFDM0_XBTXIQIMBALANCE;
  453. rtlphy->phyreg_def[RF90_PATH_C].rftxiq_imbal = ROFDM0_XCTXIQIMBALANCE;
  454. rtlphy->phyreg_def[RF90_PATH_D].rftxiq_imbal = ROFDM0_XDTXIQIMBALANCE;
  455. rtlphy->phyreg_def[RF90_PATH_A].rftx_afe = ROFDM0_XATXAFE;
  456. rtlphy->phyreg_def[RF90_PATH_B].rftx_afe = ROFDM0_XBTXAFE;
  457. rtlphy->phyreg_def[RF90_PATH_C].rftx_afe = ROFDM0_XCTXAFE;
  458. rtlphy->phyreg_def[RF90_PATH_D].rftx_afe = ROFDM0_XDTXAFE;
  459. rtlphy->phyreg_def[RF90_PATH_A].rf_rb = RFPGA0_XA_LSSIREADBACK;
  460. rtlphy->phyreg_def[RF90_PATH_B].rf_rb = RFPGA0_XB_LSSIREADBACK;
  461. rtlphy->phyreg_def[RF90_PATH_C].rf_rb = RFPGA0_XC_LSSIREADBACK;
  462. rtlphy->phyreg_def[RF90_PATH_D].rf_rb = RFPGA0_XD_LSSIREADBACK;
  463. rtlphy->phyreg_def[RF90_PATH_A].rf_rbpi = TRANSCEIVEA_HSPI_READBACK;
  464. rtlphy->phyreg_def[RF90_PATH_B].rf_rbpi = TRANSCEIVEB_HSPI_READBACK;
  465. }
  466. EXPORT_SYMBOL(_rtl92c_phy_init_bb_rf_register_definition);
  467. void rtl92c_phy_get_txpower_level(struct ieee80211_hw *hw, long *powerlevel)
  468. {
  469. struct rtl_priv *rtlpriv = rtl_priv(hw);
  470. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  471. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  472. u8 txpwr_level;
  473. long txpwr_dbm;
  474. txpwr_level = rtlphy->cur_cck_txpwridx;
  475. txpwr_dbm = _rtl92c_phy_txpwr_idx_to_dbm(hw, WIRELESS_MODE_B,
  476. txpwr_level);
  477. txpwr_level = rtlphy->cur_ofdm24g_txpwridx +
  478. rtlefuse->legacy_ht_txpowerdiff;
  479. if (_rtl92c_phy_txpwr_idx_to_dbm(hw, WIRELESS_MODE_G,
  480. txpwr_level) > txpwr_dbm)
  481. txpwr_dbm =
  482. _rtl92c_phy_txpwr_idx_to_dbm(hw, WIRELESS_MODE_G,
  483. txpwr_level);
  484. txpwr_level = rtlphy->cur_ofdm24g_txpwridx;
  485. if (_rtl92c_phy_txpwr_idx_to_dbm(hw, WIRELESS_MODE_N_24G,
  486. txpwr_level) > txpwr_dbm)
  487. txpwr_dbm =
  488. _rtl92c_phy_txpwr_idx_to_dbm(hw, WIRELESS_MODE_N_24G,
  489. txpwr_level);
  490. *powerlevel = txpwr_dbm;
  491. }
  492. static void _rtl92c_get_txpower_index(struct ieee80211_hw *hw, u8 channel,
  493. u8 *cckpowerlevel, u8 *ofdmpowerlevel)
  494. {
  495. struct rtl_priv *rtlpriv = rtl_priv(hw);
  496. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  497. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  498. u8 index = (channel - 1);
  499. cckpowerlevel[RF90_PATH_A] =
  500. rtlefuse->txpwrlevel_cck[RF90_PATH_A][index];
  501. cckpowerlevel[RF90_PATH_B] =
  502. rtlefuse->txpwrlevel_cck[RF90_PATH_B][index];
  503. if (get_rf_type(rtlphy) == RF_1T2R || get_rf_type(rtlphy) == RF_1T1R) {
  504. ofdmpowerlevel[RF90_PATH_A] =
  505. rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_A][index];
  506. ofdmpowerlevel[RF90_PATH_B] =
  507. rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_B][index];
  508. } else if (get_rf_type(rtlphy) == RF_2T2R) {
  509. ofdmpowerlevel[RF90_PATH_A] =
  510. rtlefuse->txpwrlevel_ht40_2s[RF90_PATH_A][index];
  511. ofdmpowerlevel[RF90_PATH_B] =
  512. rtlefuse->txpwrlevel_ht40_2s[RF90_PATH_B][index];
  513. }
  514. }
  515. static void _rtl92c_ccxpower_index_check(struct ieee80211_hw *hw,
  516. u8 channel, u8 *cckpowerlevel,
  517. u8 *ofdmpowerlevel)
  518. {
  519. struct rtl_priv *rtlpriv = rtl_priv(hw);
  520. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  521. rtlphy->cur_cck_txpwridx = cckpowerlevel[0];
  522. rtlphy->cur_ofdm24g_txpwridx = ofdmpowerlevel[0];
  523. }
  524. void rtl92c_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel)
  525. {
  526. struct rtl_priv *rtlpriv = rtl_priv(hw);
  527. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  528. u8 cckpowerlevel[2], ofdmpowerlevel[2];
  529. if (!rtlefuse->txpwr_fromeprom)
  530. return;
  531. _rtl92c_get_txpower_index(hw, channel,
  532. &cckpowerlevel[0], &ofdmpowerlevel[0]);
  533. _rtl92c_ccxpower_index_check(hw, channel, &cckpowerlevel[0],
  534. &ofdmpowerlevel[0]);
  535. rtlpriv->cfg->ops->phy_rf6052_set_cck_txpower(hw, &cckpowerlevel[0]);
  536. rtlpriv->cfg->ops->phy_rf6052_set_ofdm_txpower(hw, &ofdmpowerlevel[0],
  537. channel);
  538. }
  539. EXPORT_SYMBOL(rtl92c_phy_set_txpower_level);
  540. bool rtl92c_phy_update_txpower_dbm(struct ieee80211_hw *hw, long power_indbm)
  541. {
  542. struct rtl_priv *rtlpriv = rtl_priv(hw);
  543. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  544. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  545. u8 idx;
  546. u8 rf_path;
  547. u8 ccktxpwridx = _rtl92c_phy_dbm_to_txpwr_idx(hw, WIRELESS_MODE_B,
  548. power_indbm);
  549. u8 ofdmtxpwridx = _rtl92c_phy_dbm_to_txpwr_idx(hw, WIRELESS_MODE_N_24G,
  550. power_indbm);
  551. if (ofdmtxpwridx - rtlefuse->legacy_ht_txpowerdiff > 0)
  552. ofdmtxpwridx -= rtlefuse->legacy_ht_txpowerdiff;
  553. else
  554. ofdmtxpwridx = 0;
  555. RT_TRACE(rtlpriv, COMP_TXAGC, DBG_TRACE,
  556. "%lx dBm, ccktxpwridx = %d, ofdmtxpwridx = %d\n",
  557. power_indbm, ccktxpwridx, ofdmtxpwridx);
  558. for (idx = 0; idx < 14; idx++) {
  559. for (rf_path = 0; rf_path < 2; rf_path++) {
  560. rtlefuse->txpwrlevel_cck[rf_path][idx] = ccktxpwridx;
  561. rtlefuse->txpwrlevel_ht40_1s[rf_path][idx] =
  562. ofdmtxpwridx;
  563. rtlefuse->txpwrlevel_ht40_2s[rf_path][idx] =
  564. ofdmtxpwridx;
  565. }
  566. }
  567. rtl92c_phy_set_txpower_level(hw, rtlphy->current_channel);
  568. return true;
  569. }
  570. EXPORT_SYMBOL(rtl92c_phy_update_txpower_dbm);
  571. u8 _rtl92c_phy_dbm_to_txpwr_idx(struct ieee80211_hw *hw,
  572. enum wireless_mode wirelessmode,
  573. long power_indbm)
  574. {
  575. u8 txpwridx;
  576. long offset;
  577. switch (wirelessmode) {
  578. case WIRELESS_MODE_B:
  579. offset = -7;
  580. break;
  581. case WIRELESS_MODE_G:
  582. case WIRELESS_MODE_N_24G:
  583. offset = -8;
  584. break;
  585. default:
  586. offset = -8;
  587. break;
  588. }
  589. if ((power_indbm - offset) > 0)
  590. txpwridx = (u8)((power_indbm - offset) * 2);
  591. else
  592. txpwridx = 0;
  593. if (txpwridx > MAX_TXPWR_IDX_NMODE_92S)
  594. txpwridx = MAX_TXPWR_IDX_NMODE_92S;
  595. return txpwridx;
  596. }
  597. EXPORT_SYMBOL(_rtl92c_phy_dbm_to_txpwr_idx);
  598. long _rtl92c_phy_txpwr_idx_to_dbm(struct ieee80211_hw *hw,
  599. enum wireless_mode wirelessmode,
  600. u8 txpwridx)
  601. {
  602. long offset;
  603. long pwrout_dbm;
  604. switch (wirelessmode) {
  605. case WIRELESS_MODE_B:
  606. offset = -7;
  607. break;
  608. case WIRELESS_MODE_G:
  609. case WIRELESS_MODE_N_24G:
  610. offset = -8;
  611. break;
  612. default:
  613. offset = -8;
  614. break;
  615. }
  616. pwrout_dbm = txpwridx / 2 + offset;
  617. return pwrout_dbm;
  618. }
  619. EXPORT_SYMBOL(_rtl92c_phy_txpwr_idx_to_dbm);
  620. void rtl92c_phy_set_bw_mode(struct ieee80211_hw *hw,
  621. enum nl80211_channel_type ch_type)
  622. {
  623. struct rtl_priv *rtlpriv = rtl_priv(hw);
  624. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  625. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  626. u8 tmp_bw = rtlphy->current_chan_bw;
  627. if (rtlphy->set_bwmode_inprogress)
  628. return;
  629. rtlphy->set_bwmode_inprogress = true;
  630. if ((!is_hal_stop(rtlhal)) && !(RT_CANNOT_IO(hw))) {
  631. rtlpriv->cfg->ops->phy_set_bw_mode_callback(hw);
  632. } else {
  633. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  634. "false driver sleep or unload\n");
  635. rtlphy->set_bwmode_inprogress = false;
  636. rtlphy->current_chan_bw = tmp_bw;
  637. }
  638. }
  639. EXPORT_SYMBOL(rtl92c_phy_set_bw_mode);
  640. void rtl92c_phy_sw_chnl_callback(struct ieee80211_hw *hw)
  641. {
  642. struct rtl_priv *rtlpriv = rtl_priv(hw);
  643. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  644. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  645. u32 delay;
  646. RT_TRACE(rtlpriv, COMP_SCAN, DBG_TRACE,
  647. "switch to channel%d\n", rtlphy->current_channel);
  648. if (is_hal_stop(rtlhal))
  649. return;
  650. do {
  651. if (!rtlphy->sw_chnl_inprogress)
  652. break;
  653. if (!_rtl92c_phy_sw_chnl_step_by_step
  654. (hw, rtlphy->current_channel, &rtlphy->sw_chnl_stage,
  655. &rtlphy->sw_chnl_step, &delay)) {
  656. if (delay > 0)
  657. mdelay(delay);
  658. else
  659. continue;
  660. } else {
  661. rtlphy->sw_chnl_inprogress = false;
  662. }
  663. break;
  664. } while (true);
  665. RT_TRACE(rtlpriv, COMP_SCAN, DBG_TRACE, "\n");
  666. }
  667. EXPORT_SYMBOL(rtl92c_phy_sw_chnl_callback);
  668. u8 rtl92c_phy_sw_chnl(struct ieee80211_hw *hw)
  669. {
  670. struct rtl_priv *rtlpriv = rtl_priv(hw);
  671. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  672. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  673. if (rtlphy->sw_chnl_inprogress)
  674. return 0;
  675. if (rtlphy->set_bwmode_inprogress)
  676. return 0;
  677. RT_ASSERT((rtlphy->current_channel <= 14),
  678. "WIRELESS_MODE_G but channel>14");
  679. rtlphy->sw_chnl_inprogress = true;
  680. rtlphy->sw_chnl_stage = 0;
  681. rtlphy->sw_chnl_step = 0;
  682. if (!(is_hal_stop(rtlhal)) && !(RT_CANNOT_IO(hw))) {
  683. rtl92c_phy_sw_chnl_callback(hw);
  684. RT_TRACE(rtlpriv, COMP_CHAN, DBG_LOUD,
  685. "sw_chnl_inprogress false schdule workitem\n");
  686. rtlphy->sw_chnl_inprogress = false;
  687. } else {
  688. RT_TRACE(rtlpriv, COMP_CHAN, DBG_LOUD,
  689. "sw_chnl_inprogress false driver sleep or unload\n");
  690. rtlphy->sw_chnl_inprogress = false;
  691. }
  692. return 1;
  693. }
  694. EXPORT_SYMBOL(rtl92c_phy_sw_chnl);
  695. static void _rtl92c_phy_sw_rf_seting(struct ieee80211_hw *hw, u8 channel)
  696. {
  697. struct rtl_priv *rtlpriv = rtl_priv(hw);
  698. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  699. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  700. if (IS_81XXC_VENDOR_UMC_B_CUT(rtlhal->version)) {
  701. if (channel == 6 &&
  702. rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20) {
  703. rtl_set_rfreg(hw, RF90_PATH_A, RF_RX_G1,
  704. MASKDWORD, 0x00255);
  705. } else {
  706. u32 backuprf0x1A =
  707. (u32)rtl_get_rfreg(hw, RF90_PATH_A, RF_RX_G1,
  708. RFREG_OFFSET_MASK);
  709. rtl_set_rfreg(hw, RF90_PATH_A, RF_RX_G1, MASKDWORD,
  710. backuprf0x1A);
  711. }
  712. }
  713. }
  714. static bool _rtl92c_phy_set_sw_chnl_cmdarray(struct swchnlcmd *cmdtable,
  715. u32 cmdtableidx, u32 cmdtablesz,
  716. enum swchnlcmd_id cmdid,
  717. u32 para1, u32 para2, u32 msdelay)
  718. {
  719. struct swchnlcmd *pcmd;
  720. if (cmdtable == NULL) {
  721. RT_ASSERT(false, "cmdtable cannot be NULL.\n");
  722. return false;
  723. }
  724. if (cmdtableidx >= cmdtablesz)
  725. return false;
  726. pcmd = cmdtable + cmdtableidx;
  727. pcmd->cmdid = cmdid;
  728. pcmd->para1 = para1;
  729. pcmd->para2 = para2;
  730. pcmd->msdelay = msdelay;
  731. return true;
  732. }
  733. bool _rtl92c_phy_sw_chnl_step_by_step(struct ieee80211_hw *hw,
  734. u8 channel, u8 *stage, u8 *step,
  735. u32 *delay)
  736. {
  737. struct rtl_priv *rtlpriv = rtl_priv(hw);
  738. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  739. struct swchnlcmd precommoncmd[MAX_PRECMD_CNT];
  740. u32 precommoncmdcnt;
  741. struct swchnlcmd postcommoncmd[MAX_POSTCMD_CNT];
  742. u32 postcommoncmdcnt;
  743. struct swchnlcmd rfdependcmd[MAX_RFDEPENDCMD_CNT];
  744. u32 rfdependcmdcnt;
  745. struct swchnlcmd *currentcmd = NULL;
  746. u8 rfpath;
  747. u8 num_total_rfpath = rtlphy->num_total_rfpath;
  748. precommoncmdcnt = 0;
  749. _rtl92c_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++,
  750. MAX_PRECMD_CNT,
  751. CMDID_SET_TXPOWEROWER_LEVEL, 0, 0, 0);
  752. _rtl92c_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++,
  753. MAX_PRECMD_CNT, CMDID_END, 0, 0, 0);
  754. postcommoncmdcnt = 0;
  755. _rtl92c_phy_set_sw_chnl_cmdarray(postcommoncmd, postcommoncmdcnt++,
  756. MAX_POSTCMD_CNT, CMDID_END, 0, 0, 0);
  757. rfdependcmdcnt = 0;
  758. RT_ASSERT((channel >= 1 && channel <= 14),
  759. "illegal channel for Zebra: %d\n", channel);
  760. _rtl92c_phy_set_sw_chnl_cmdarray(rfdependcmd, rfdependcmdcnt++,
  761. MAX_RFDEPENDCMD_CNT, CMDID_RF_WRITEREG,
  762. RF_CHNLBW, channel, 10);
  763. _rtl92c_phy_set_sw_chnl_cmdarray(rfdependcmd, rfdependcmdcnt++,
  764. MAX_RFDEPENDCMD_CNT, CMDID_END, 0, 0,
  765. 0);
  766. do {
  767. switch (*stage) {
  768. case 0:
  769. currentcmd = &precommoncmd[*step];
  770. break;
  771. case 1:
  772. currentcmd = &rfdependcmd[*step];
  773. break;
  774. case 2:
  775. currentcmd = &postcommoncmd[*step];
  776. break;
  777. default:
  778. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  779. "Invalid 'stage' = %d, Check it!\n", *stage);
  780. return true;
  781. }
  782. if (currentcmd->cmdid == CMDID_END) {
  783. if ((*stage) == 2) {
  784. return true;
  785. } else {
  786. (*stage)++;
  787. (*step) = 0;
  788. continue;
  789. }
  790. }
  791. switch (currentcmd->cmdid) {
  792. case CMDID_SET_TXPOWEROWER_LEVEL:
  793. rtl92c_phy_set_txpower_level(hw, channel);
  794. break;
  795. case CMDID_WRITEPORT_ULONG:
  796. rtl_write_dword(rtlpriv, currentcmd->para1,
  797. currentcmd->para2);
  798. break;
  799. case CMDID_WRITEPORT_USHORT:
  800. rtl_write_word(rtlpriv, currentcmd->para1,
  801. (u16) currentcmd->para2);
  802. break;
  803. case CMDID_WRITEPORT_UCHAR:
  804. rtl_write_byte(rtlpriv, currentcmd->para1,
  805. (u8)currentcmd->para2);
  806. break;
  807. case CMDID_RF_WRITEREG:
  808. for (rfpath = 0; rfpath < num_total_rfpath; rfpath++) {
  809. rtlphy->rfreg_chnlval[rfpath] =
  810. ((rtlphy->rfreg_chnlval[rfpath] &
  811. 0xfffffc00) | currentcmd->para2);
  812. rtl_set_rfreg(hw, (enum radio_path)rfpath,
  813. currentcmd->para1,
  814. RFREG_OFFSET_MASK,
  815. rtlphy->rfreg_chnlval[rfpath]);
  816. }
  817. _rtl92c_phy_sw_rf_seting(hw, channel);
  818. break;
  819. default:
  820. RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
  821. "switch case not process\n");
  822. break;
  823. }
  824. break;
  825. } while (true);
  826. (*delay) = currentcmd->msdelay;
  827. (*step)++;
  828. return false;
  829. }
  830. bool rtl8192_phy_check_is_legal_rfpath(struct ieee80211_hw *hw, u32 rfpath)
  831. {
  832. return true;
  833. }
  834. EXPORT_SYMBOL(rtl8192_phy_check_is_legal_rfpath);
  835. static u8 _rtl92c_phy_path_a_iqk(struct ieee80211_hw *hw, bool config_pathb)
  836. {
  837. u32 reg_eac, reg_e94, reg_e9c, reg_ea4;
  838. u8 result = 0x00;
  839. rtl_set_bbreg(hw, 0xe30, MASKDWORD, 0x10008c1f);
  840. rtl_set_bbreg(hw, 0xe34, MASKDWORD, 0x10008c1f);
  841. rtl_set_bbreg(hw, 0xe38, MASKDWORD, 0x82140102);
  842. rtl_set_bbreg(hw, 0xe3c, MASKDWORD,
  843. config_pathb ? 0x28160202 : 0x28160502);
  844. if (config_pathb) {
  845. rtl_set_bbreg(hw, 0xe50, MASKDWORD, 0x10008c22);
  846. rtl_set_bbreg(hw, 0xe54, MASKDWORD, 0x10008c22);
  847. rtl_set_bbreg(hw, 0xe58, MASKDWORD, 0x82140102);
  848. rtl_set_bbreg(hw, 0xe5c, MASKDWORD, 0x28160202);
  849. }
  850. rtl_set_bbreg(hw, 0xe4c, MASKDWORD, 0x001028d1);
  851. rtl_set_bbreg(hw, 0xe48, MASKDWORD, 0xf9000000);
  852. rtl_set_bbreg(hw, 0xe48, MASKDWORD, 0xf8000000);
  853. mdelay(IQK_DELAY_TIME);
  854. reg_eac = rtl_get_bbreg(hw, 0xeac, MASKDWORD);
  855. reg_e94 = rtl_get_bbreg(hw, 0xe94, MASKDWORD);
  856. reg_e9c = rtl_get_bbreg(hw, 0xe9c, MASKDWORD);
  857. reg_ea4 = rtl_get_bbreg(hw, 0xea4, MASKDWORD);
  858. if (!(reg_eac & BIT(28)) &&
  859. (((reg_e94 & 0x03FF0000) >> 16) != 0x142) &&
  860. (((reg_e9c & 0x03FF0000) >> 16) != 0x42))
  861. result |= 0x01;
  862. else
  863. return result;
  864. if (!(reg_eac & BIT(27)) &&
  865. (((reg_ea4 & 0x03FF0000) >> 16) != 0x132) &&
  866. (((reg_eac & 0x03FF0000) >> 16) != 0x36))
  867. result |= 0x02;
  868. return result;
  869. }
  870. static u8 _rtl92c_phy_path_b_iqk(struct ieee80211_hw *hw)
  871. {
  872. u32 reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc;
  873. u8 result = 0x00;
  874. rtl_set_bbreg(hw, 0xe60, MASKDWORD, 0x00000002);
  875. rtl_set_bbreg(hw, 0xe60, MASKDWORD, 0x00000000);
  876. mdelay(IQK_DELAY_TIME);
  877. reg_eac = rtl_get_bbreg(hw, 0xeac, MASKDWORD);
  878. reg_eb4 = rtl_get_bbreg(hw, 0xeb4, MASKDWORD);
  879. reg_ebc = rtl_get_bbreg(hw, 0xebc, MASKDWORD);
  880. reg_ec4 = rtl_get_bbreg(hw, 0xec4, MASKDWORD);
  881. reg_ecc = rtl_get_bbreg(hw, 0xecc, MASKDWORD);
  882. if (!(reg_eac & BIT(31)) &&
  883. (((reg_eb4 & 0x03FF0000) >> 16) != 0x142) &&
  884. (((reg_ebc & 0x03FF0000) >> 16) != 0x42))
  885. result |= 0x01;
  886. else
  887. return result;
  888. if (!(reg_eac & BIT(30)) &&
  889. (((reg_ec4 & 0x03FF0000) >> 16) != 0x132) &&
  890. (((reg_ecc & 0x03FF0000) >> 16) != 0x36))
  891. result |= 0x02;
  892. return result;
  893. }
  894. static void _rtl92c_phy_path_a_fill_iqk_matrix(struct ieee80211_hw *hw,
  895. bool b_iqk_ok, long result[][8],
  896. u8 final_candidate, bool btxonly)
  897. {
  898. u32 oldval_0, x, tx0_a, reg;
  899. long y, tx0_c;
  900. if (final_candidate == 0xFF) {
  901. return;
  902. } else if (b_iqk_ok) {
  903. oldval_0 = (rtl_get_bbreg(hw, ROFDM0_XATXIQIMBALANCE,
  904. MASKDWORD) >> 22) & 0x3FF;
  905. x = result[final_candidate][0];
  906. if ((x & 0x00000200) != 0)
  907. x = x | 0xFFFFFC00;
  908. tx0_a = (x * oldval_0) >> 8;
  909. rtl_set_bbreg(hw, ROFDM0_XATXIQIMBALANCE, 0x3FF, tx0_a);
  910. rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(31),
  911. ((x * oldval_0 >> 7) & 0x1));
  912. y = result[final_candidate][1];
  913. if ((y & 0x00000200) != 0)
  914. y = y | 0xFFFFFC00;
  915. tx0_c = (y * oldval_0) >> 8;
  916. rtl_set_bbreg(hw, ROFDM0_XCTXAFE, 0xF0000000,
  917. ((tx0_c & 0x3C0) >> 6));
  918. rtl_set_bbreg(hw, ROFDM0_XATXIQIMBALANCE, 0x003F0000,
  919. (tx0_c & 0x3F));
  920. rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(29),
  921. ((y * oldval_0 >> 7) & 0x1));
  922. if (btxonly)
  923. return;
  924. reg = result[final_candidate][2];
  925. rtl_set_bbreg(hw, ROFDM0_XARXIQIMBALANCE, 0x3FF, reg);
  926. reg = result[final_candidate][3] & 0x3F;
  927. rtl_set_bbreg(hw, ROFDM0_XARXIQIMBALANCE, 0xFC00, reg);
  928. reg = (result[final_candidate][3] >> 6) & 0xF;
  929. rtl_set_bbreg(hw, 0xca0, 0xF0000000, reg);
  930. }
  931. }
  932. static void _rtl92c_phy_path_b_fill_iqk_matrix(struct ieee80211_hw *hw,
  933. bool b_iqk_ok, long result[][8],
  934. u8 final_candidate, bool btxonly)
  935. {
  936. u32 oldval_1, x, tx1_a, reg;
  937. long y, tx1_c;
  938. if (final_candidate == 0xFF) {
  939. return;
  940. } else if (b_iqk_ok) {
  941. oldval_1 = (rtl_get_bbreg(hw, ROFDM0_XBTXIQIMBALANCE,
  942. MASKDWORD) >> 22) & 0x3FF;
  943. x = result[final_candidate][4];
  944. if ((x & 0x00000200) != 0)
  945. x = x | 0xFFFFFC00;
  946. tx1_a = (x * oldval_1) >> 8;
  947. rtl_set_bbreg(hw, ROFDM0_XBTXIQIMBALANCE, 0x3FF, tx1_a);
  948. rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(27),
  949. ((x * oldval_1 >> 7) & 0x1));
  950. y = result[final_candidate][5];
  951. if ((y & 0x00000200) != 0)
  952. y = y | 0xFFFFFC00;
  953. tx1_c = (y * oldval_1) >> 8;
  954. rtl_set_bbreg(hw, ROFDM0_XDTXAFE, 0xF0000000,
  955. ((tx1_c & 0x3C0) >> 6));
  956. rtl_set_bbreg(hw, ROFDM0_XBTXIQIMBALANCE, 0x003F0000,
  957. (tx1_c & 0x3F));
  958. rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(25),
  959. ((y * oldval_1 >> 7) & 0x1));
  960. if (btxonly)
  961. return;
  962. reg = result[final_candidate][6];
  963. rtl_set_bbreg(hw, ROFDM0_XBRXIQIMBALANCE, 0x3FF, reg);
  964. reg = result[final_candidate][7] & 0x3F;
  965. rtl_set_bbreg(hw, ROFDM0_XBRXIQIMBALANCE, 0xFC00, reg);
  966. reg = (result[final_candidate][7] >> 6) & 0xF;
  967. rtl_set_bbreg(hw, ROFDM0_AGCRSSITABLE, 0x0000F000, reg);
  968. }
  969. }
  970. static void _rtl92c_phy_save_adda_registers(struct ieee80211_hw *hw,
  971. u32 *addareg, u32 *addabackup,
  972. u32 registernum)
  973. {
  974. u32 i;
  975. for (i = 0; i < registernum; i++)
  976. addabackup[i] = rtl_get_bbreg(hw, addareg[i], MASKDWORD);
  977. }
  978. static void _rtl92c_phy_save_mac_registers(struct ieee80211_hw *hw,
  979. u32 *macreg, u32 *macbackup)
  980. {
  981. struct rtl_priv *rtlpriv = rtl_priv(hw);
  982. u32 i;
  983. for (i = 0; i < (IQK_MAC_REG_NUM - 1); i++)
  984. macbackup[i] = rtl_read_byte(rtlpriv, macreg[i]);
  985. macbackup[i] = rtl_read_dword(rtlpriv, macreg[i]);
  986. }
  987. static void _rtl92c_phy_reload_adda_registers(struct ieee80211_hw *hw,
  988. u32 *addareg, u32 *addabackup,
  989. u32 regiesternum)
  990. {
  991. u32 i;
  992. for (i = 0; i < regiesternum; i++)
  993. rtl_set_bbreg(hw, addareg[i], MASKDWORD, addabackup[i]);
  994. }
  995. static void _rtl92c_phy_reload_mac_registers(struct ieee80211_hw *hw,
  996. u32 *macreg, u32 *macbackup)
  997. {
  998. struct rtl_priv *rtlpriv = rtl_priv(hw);
  999. u32 i;
  1000. for (i = 0; i < (IQK_MAC_REG_NUM - 1); i++)
  1001. rtl_write_byte(rtlpriv, macreg[i], (u8)macbackup[i]);
  1002. rtl_write_dword(rtlpriv, macreg[i], macbackup[i]);
  1003. }
  1004. static void _rtl92c_phy_path_adda_on(struct ieee80211_hw *hw,
  1005. u32 *addareg, bool is_patha_on, bool is2t)
  1006. {
  1007. u32 pathOn;
  1008. u32 i;
  1009. pathOn = is_patha_on ? 0x04db25a4 : 0x0b1b25a4;
  1010. if (false == is2t) {
  1011. pathOn = 0x0bdb25a0;
  1012. rtl_set_bbreg(hw, addareg[0], MASKDWORD, 0x0b1b25a0);
  1013. } else {
  1014. rtl_set_bbreg(hw, addareg[0], MASKDWORD, pathOn);
  1015. }
  1016. for (i = 1; i < IQK_ADDA_REG_NUM; i++)
  1017. rtl_set_bbreg(hw, addareg[i], MASKDWORD, pathOn);
  1018. }
  1019. static void _rtl92c_phy_mac_setting_calibration(struct ieee80211_hw *hw,
  1020. u32 *macreg, u32 *macbackup)
  1021. {
  1022. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1023. u32 i = 0;
  1024. rtl_write_byte(rtlpriv, macreg[i], 0x3F);
  1025. for (i = 1; i < (IQK_MAC_REG_NUM - 1); i++)
  1026. rtl_write_byte(rtlpriv, macreg[i],
  1027. (u8)(macbackup[i] & (~BIT(3))));
  1028. rtl_write_byte(rtlpriv, macreg[i], (u8)(macbackup[i] & (~BIT(5))));
  1029. }
  1030. static void _rtl92c_phy_path_a_standby(struct ieee80211_hw *hw)
  1031. {
  1032. rtl_set_bbreg(hw, 0xe28, MASKDWORD, 0x0);
  1033. rtl_set_bbreg(hw, 0x840, MASKDWORD, 0x00010000);
  1034. rtl_set_bbreg(hw, 0xe28, MASKDWORD, 0x80800000);
  1035. }
  1036. static void _rtl92c_phy_pi_mode_switch(struct ieee80211_hw *hw, bool pi_mode)
  1037. {
  1038. u32 mode;
  1039. mode = pi_mode ? 0x01000100 : 0x01000000;
  1040. rtl_set_bbreg(hw, 0x820, MASKDWORD, mode);
  1041. rtl_set_bbreg(hw, 0x828, MASKDWORD, mode);
  1042. }
  1043. static bool _rtl92c_phy_simularity_compare(struct ieee80211_hw *hw,
  1044. long result[][8], u8 c1, u8 c2)
  1045. {
  1046. u32 i, j, diff, simularity_bitmap, bound;
  1047. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1048. u8 final_candidate[2] = { 0xFF, 0xFF };
  1049. bool bresult = true, is2t = IS_92C_SERIAL(rtlhal->version);
  1050. if (is2t)
  1051. bound = 8;
  1052. else
  1053. bound = 4;
  1054. simularity_bitmap = 0;
  1055. for (i = 0; i < bound; i++) {
  1056. diff = (result[c1][i] > result[c2][i]) ?
  1057. (result[c1][i] - result[c2][i]) :
  1058. (result[c2][i] - result[c1][i]);
  1059. if (diff > MAX_TOLERANCE) {
  1060. if ((i == 2 || i == 6) && !simularity_bitmap) {
  1061. if (result[c1][i] + result[c1][i + 1] == 0)
  1062. final_candidate[(i / 4)] = c2;
  1063. else if (result[c2][i] + result[c2][i + 1] == 0)
  1064. final_candidate[(i / 4)] = c1;
  1065. else
  1066. simularity_bitmap = simularity_bitmap |
  1067. (1 << i);
  1068. } else
  1069. simularity_bitmap =
  1070. simularity_bitmap | (1 << i);
  1071. }
  1072. }
  1073. if (simularity_bitmap == 0) {
  1074. for (i = 0; i < (bound / 4); i++) {
  1075. if (final_candidate[i] != 0xFF) {
  1076. for (j = i * 4; j < (i + 1) * 4 - 2; j++)
  1077. result[3][j] =
  1078. result[final_candidate[i]][j];
  1079. bresult = false;
  1080. }
  1081. }
  1082. return bresult;
  1083. } else if (!(simularity_bitmap & 0x0F)) {
  1084. for (i = 0; i < 4; i++)
  1085. result[3][i] = result[c1][i];
  1086. return false;
  1087. } else if (!(simularity_bitmap & 0xF0) && is2t) {
  1088. for (i = 4; i < 8; i++)
  1089. result[3][i] = result[c1][i];
  1090. return false;
  1091. } else {
  1092. return false;
  1093. }
  1094. }
  1095. static void _rtl92c_phy_iq_calibrate(struct ieee80211_hw *hw,
  1096. long result[][8], u8 t, bool is2t)
  1097. {
  1098. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1099. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1100. u32 i;
  1101. u8 patha_ok, pathb_ok;
  1102. u32 adda_reg[IQK_ADDA_REG_NUM] = {
  1103. 0x85c, 0xe6c, 0xe70, 0xe74,
  1104. 0xe78, 0xe7c, 0xe80, 0xe84,
  1105. 0xe88, 0xe8c, 0xed0, 0xed4,
  1106. 0xed8, 0xedc, 0xee0, 0xeec
  1107. };
  1108. u32 iqk_mac_reg[IQK_MAC_REG_NUM] = {
  1109. 0x522, 0x550, 0x551, 0x040
  1110. };
  1111. const u32 retrycount = 2;
  1112. u32 bbvalue;
  1113. if (t == 0) {
  1114. bbvalue = rtl_get_bbreg(hw, 0x800, MASKDWORD);
  1115. _rtl92c_phy_save_adda_registers(hw, adda_reg,
  1116. rtlphy->adda_backup, 16);
  1117. _rtl92c_phy_save_mac_registers(hw, iqk_mac_reg,
  1118. rtlphy->iqk_mac_backup);
  1119. }
  1120. _rtl92c_phy_path_adda_on(hw, adda_reg, true, is2t);
  1121. if (t == 0) {
  1122. rtlphy->rfpi_enable =
  1123. (u8)rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER1,
  1124. BIT(8));
  1125. }
  1126. if (!rtlphy->rfpi_enable)
  1127. _rtl92c_phy_pi_mode_switch(hw, true);
  1128. if (t == 0) {
  1129. rtlphy->reg_c04 = rtl_get_bbreg(hw, 0xc04, MASKDWORD);
  1130. rtlphy->reg_c08 = rtl_get_bbreg(hw, 0xc08, MASKDWORD);
  1131. rtlphy->reg_874 = rtl_get_bbreg(hw, 0x874, MASKDWORD);
  1132. }
  1133. rtl_set_bbreg(hw, 0xc04, MASKDWORD, 0x03a05600);
  1134. rtl_set_bbreg(hw, 0xc08, MASKDWORD, 0x000800e4);
  1135. rtl_set_bbreg(hw, 0x874, MASKDWORD, 0x22204000);
  1136. if (is2t) {
  1137. rtl_set_bbreg(hw, 0x840, MASKDWORD, 0x00010000);
  1138. rtl_set_bbreg(hw, 0x844, MASKDWORD, 0x00010000);
  1139. }
  1140. _rtl92c_phy_mac_setting_calibration(hw, iqk_mac_reg,
  1141. rtlphy->iqk_mac_backup);
  1142. rtl_set_bbreg(hw, 0xb68, MASKDWORD, 0x00080000);
  1143. if (is2t)
  1144. rtl_set_bbreg(hw, 0xb6c, MASKDWORD, 0x00080000);
  1145. rtl_set_bbreg(hw, 0xe28, MASKDWORD, 0x80800000);
  1146. rtl_set_bbreg(hw, 0xe40, MASKDWORD, 0x01007c00);
  1147. rtl_set_bbreg(hw, 0xe44, MASKDWORD, 0x01004800);
  1148. for (i = 0; i < retrycount; i++) {
  1149. patha_ok = _rtl92c_phy_path_a_iqk(hw, is2t);
  1150. if (patha_ok == 0x03) {
  1151. result[t][0] = (rtl_get_bbreg(hw, 0xe94, MASKDWORD) &
  1152. 0x3FF0000) >> 16;
  1153. result[t][1] = (rtl_get_bbreg(hw, 0xe9c, MASKDWORD) &
  1154. 0x3FF0000) >> 16;
  1155. result[t][2] = (rtl_get_bbreg(hw, 0xea4, MASKDWORD) &
  1156. 0x3FF0000) >> 16;
  1157. result[t][3] = (rtl_get_bbreg(hw, 0xeac, MASKDWORD) &
  1158. 0x3FF0000) >> 16;
  1159. break;
  1160. } else if (i == (retrycount - 1) && patha_ok == 0x01)
  1161. result[t][0] = (rtl_get_bbreg(hw, 0xe94,
  1162. MASKDWORD) & 0x3FF0000) >>
  1163. 16;
  1164. result[t][1] =
  1165. (rtl_get_bbreg(hw, 0xe9c, MASKDWORD) & 0x3FF0000) >> 16;
  1166. }
  1167. if (is2t) {
  1168. _rtl92c_phy_path_a_standby(hw);
  1169. _rtl92c_phy_path_adda_on(hw, adda_reg, false, is2t);
  1170. for (i = 0; i < retrycount; i++) {
  1171. pathb_ok = _rtl92c_phy_path_b_iqk(hw);
  1172. if (pathb_ok == 0x03) {
  1173. result[t][4] = (rtl_get_bbreg(hw,
  1174. 0xeb4,
  1175. MASKDWORD) &
  1176. 0x3FF0000) >> 16;
  1177. result[t][5] =
  1178. (rtl_get_bbreg(hw, 0xebc, MASKDWORD) &
  1179. 0x3FF0000) >> 16;
  1180. result[t][6] =
  1181. (rtl_get_bbreg(hw, 0xec4, MASKDWORD) &
  1182. 0x3FF0000) >> 16;
  1183. result[t][7] =
  1184. (rtl_get_bbreg(hw, 0xecc, MASKDWORD) &
  1185. 0x3FF0000) >> 16;
  1186. break;
  1187. } else if (i == (retrycount - 1) && pathb_ok == 0x01) {
  1188. result[t][4] = (rtl_get_bbreg(hw,
  1189. 0xeb4,
  1190. MASKDWORD) &
  1191. 0x3FF0000) >> 16;
  1192. }
  1193. result[t][5] = (rtl_get_bbreg(hw, 0xebc, MASKDWORD) &
  1194. 0x3FF0000) >> 16;
  1195. }
  1196. }
  1197. rtl_set_bbreg(hw, 0xc04, MASKDWORD, rtlphy->reg_c04);
  1198. rtl_set_bbreg(hw, 0x874, MASKDWORD, rtlphy->reg_874);
  1199. rtl_set_bbreg(hw, 0xc08, MASKDWORD, rtlphy->reg_c08);
  1200. rtl_set_bbreg(hw, 0xe28, MASKDWORD, 0);
  1201. rtl_set_bbreg(hw, 0x840, MASKDWORD, 0x00032ed3);
  1202. if (is2t)
  1203. rtl_set_bbreg(hw, 0x844, MASKDWORD, 0x00032ed3);
  1204. if (t != 0) {
  1205. if (!rtlphy->rfpi_enable)
  1206. _rtl92c_phy_pi_mode_switch(hw, false);
  1207. _rtl92c_phy_reload_adda_registers(hw, adda_reg,
  1208. rtlphy->adda_backup, 16);
  1209. _rtl92c_phy_reload_mac_registers(hw, iqk_mac_reg,
  1210. rtlphy->iqk_mac_backup);
  1211. }
  1212. }
  1213. static void _rtl92c_phy_ap_calibrate(struct ieee80211_hw *hw,
  1214. char delta, bool is2t)
  1215. {
  1216. }
  1217. static void _rtl92c_phy_set_rfpath_switch(struct ieee80211_hw *hw,
  1218. bool bmain, bool is2t)
  1219. {
  1220. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1221. if (is_hal_stop(rtlhal)) {
  1222. rtl_set_bbreg(hw, REG_LEDCFG0, BIT(23), 0x01);
  1223. rtl_set_bbreg(hw, rFPGA0_XAB_RFPARAMETER, BIT(13), 0x01);
  1224. }
  1225. if (is2t) {
  1226. if (bmain)
  1227. rtl_set_bbreg(hw, RFPGA0_XB_RFINTERFACEOE,
  1228. BIT(5) | BIT(6), 0x1);
  1229. else
  1230. rtl_set_bbreg(hw, RFPGA0_XB_RFINTERFACEOE,
  1231. BIT(5) | BIT(6), 0x2);
  1232. } else {
  1233. if (bmain)
  1234. rtl_set_bbreg(hw, RFPGA0_XA_RFINTERFACEOE, 0x300, 0x2);
  1235. else
  1236. rtl_set_bbreg(hw, RFPGA0_XA_RFINTERFACEOE, 0x300, 0x1);
  1237. }
  1238. }
  1239. #undef IQK_ADDA_REG_NUM
  1240. #undef IQK_DELAY_TIME
  1241. void rtl92c_phy_iq_calibrate(struct ieee80211_hw *hw, bool b_recovery)
  1242. {
  1243. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1244. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1245. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1246. long result[4][8];
  1247. u8 i, final_candidate;
  1248. bool b_patha_ok, b_pathb_ok;
  1249. long reg_e94, reg_e9c, reg_ea4, reg_eac, reg_eb4, reg_ebc, reg_ec4,
  1250. reg_ecc, reg_tmp = 0;
  1251. bool is12simular, is13simular, is23simular;
  1252. u32 iqk_bb_reg[10] = {
  1253. ROFDM0_XARXIQIMBALANCE,
  1254. ROFDM0_XBRXIQIMBALANCE,
  1255. ROFDM0_ECCATHRESHOLD,
  1256. ROFDM0_AGCRSSITABLE,
  1257. ROFDM0_XATXIQIMBALANCE,
  1258. ROFDM0_XBTXIQIMBALANCE,
  1259. ROFDM0_XCTXIQIMBALANCE,
  1260. ROFDM0_XCTXAFE,
  1261. ROFDM0_XDTXAFE,
  1262. ROFDM0_RXIQEXTANTA
  1263. };
  1264. if (b_recovery) {
  1265. _rtl92c_phy_reload_adda_registers(hw,
  1266. iqk_bb_reg,
  1267. rtlphy->iqk_bb_backup, 10);
  1268. return;
  1269. }
  1270. for (i = 0; i < 8; i++) {
  1271. result[0][i] = 0;
  1272. result[1][i] = 0;
  1273. result[2][i] = 0;
  1274. result[3][i] = 0;
  1275. }
  1276. final_candidate = 0xff;
  1277. b_patha_ok = false;
  1278. b_pathb_ok = false;
  1279. is12simular = false;
  1280. is23simular = false;
  1281. is13simular = false;
  1282. for (i = 0; i < 3; i++) {
  1283. if (IS_92C_SERIAL(rtlhal->version))
  1284. _rtl92c_phy_iq_calibrate(hw, result, i, true);
  1285. else
  1286. _rtl92c_phy_iq_calibrate(hw, result, i, false);
  1287. if (i == 1) {
  1288. is12simular = _rtl92c_phy_simularity_compare(hw,
  1289. result, 0,
  1290. 1);
  1291. if (is12simular) {
  1292. final_candidate = 0;
  1293. break;
  1294. }
  1295. }
  1296. if (i == 2) {
  1297. is13simular = _rtl92c_phy_simularity_compare(hw,
  1298. result, 0,
  1299. 2);
  1300. if (is13simular) {
  1301. final_candidate = 0;
  1302. break;
  1303. }
  1304. is23simular = _rtl92c_phy_simularity_compare(hw,
  1305. result, 1,
  1306. 2);
  1307. if (is23simular)
  1308. final_candidate = 1;
  1309. else {
  1310. for (i = 0; i < 8; i++)
  1311. reg_tmp += result[3][i];
  1312. if (reg_tmp != 0)
  1313. final_candidate = 3;
  1314. else
  1315. final_candidate = 0xFF;
  1316. }
  1317. }
  1318. }
  1319. for (i = 0; i < 4; i++) {
  1320. reg_e94 = result[i][0];
  1321. reg_e9c = result[i][1];
  1322. reg_ea4 = result[i][2];
  1323. reg_eac = result[i][3];
  1324. reg_eb4 = result[i][4];
  1325. reg_ebc = result[i][5];
  1326. reg_ec4 = result[i][6];
  1327. reg_ecc = result[i][7];
  1328. }
  1329. if (final_candidate != 0xff) {
  1330. rtlphy->reg_e94 = reg_e94 = result[final_candidate][0];
  1331. rtlphy->reg_e9c = reg_e9c = result[final_candidate][1];
  1332. reg_ea4 = result[final_candidate][2];
  1333. reg_eac = result[final_candidate][3];
  1334. rtlphy->reg_eb4 = reg_eb4 = result[final_candidate][4];
  1335. rtlphy->reg_ebc = reg_ebc = result[final_candidate][5];
  1336. reg_ec4 = result[final_candidate][6];
  1337. reg_ecc = result[final_candidate][7];
  1338. b_patha_ok = true;
  1339. b_pathb_ok = true;
  1340. } else {
  1341. rtlphy->reg_e94 = rtlphy->reg_eb4 = 0x100;
  1342. rtlphy->reg_e9c = rtlphy->reg_ebc = 0x0;
  1343. }
  1344. if (reg_e94 != 0) /*&&(reg_ea4 != 0) */
  1345. _rtl92c_phy_path_a_fill_iqk_matrix(hw, b_patha_ok, result,
  1346. final_candidate,
  1347. (reg_ea4 == 0));
  1348. if (IS_92C_SERIAL(rtlhal->version)) {
  1349. if (reg_eb4 != 0) /*&&(reg_ec4 != 0) */
  1350. _rtl92c_phy_path_b_fill_iqk_matrix(hw, b_pathb_ok,
  1351. result,
  1352. final_candidate,
  1353. (reg_ec4 == 0));
  1354. }
  1355. _rtl92c_phy_save_adda_registers(hw, iqk_bb_reg,
  1356. rtlphy->iqk_bb_backup, 10);
  1357. }
  1358. EXPORT_SYMBOL(rtl92c_phy_iq_calibrate);
  1359. void rtl92c_phy_lc_calibrate(struct ieee80211_hw *hw)
  1360. {
  1361. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1362. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1363. if (IS_92C_SERIAL(rtlhal->version))
  1364. rtlpriv->cfg->ops->phy_lc_calibrate(hw, true);
  1365. else
  1366. rtlpriv->cfg->ops->phy_lc_calibrate(hw, false);
  1367. }
  1368. EXPORT_SYMBOL(rtl92c_phy_lc_calibrate);
  1369. void rtl92c_phy_ap_calibrate(struct ieee80211_hw *hw, char delta)
  1370. {
  1371. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1372. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1373. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1374. if (rtlphy->apk_done)
  1375. return;
  1376. if (IS_92C_SERIAL(rtlhal->version))
  1377. _rtl92c_phy_ap_calibrate(hw, delta, true);
  1378. else
  1379. _rtl92c_phy_ap_calibrate(hw, delta, false);
  1380. }
  1381. EXPORT_SYMBOL(rtl92c_phy_ap_calibrate);
  1382. void rtl92c_phy_set_rfpath_switch(struct ieee80211_hw *hw, bool bmain)
  1383. {
  1384. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1385. if (IS_92C_SERIAL(rtlhal->version))
  1386. _rtl92c_phy_set_rfpath_switch(hw, bmain, true);
  1387. else
  1388. _rtl92c_phy_set_rfpath_switch(hw, bmain, false);
  1389. }
  1390. EXPORT_SYMBOL(rtl92c_phy_set_rfpath_switch);
  1391. bool rtl92c_phy_set_io_cmd(struct ieee80211_hw *hw, enum io_type iotype)
  1392. {
  1393. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1394. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1395. bool postprocessing = false;
  1396. RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE,
  1397. "-->IO Cmd(%#x), set_io_inprogress(%d)\n",
  1398. iotype, rtlphy->set_io_inprogress);
  1399. do {
  1400. switch (iotype) {
  1401. case IO_CMD_RESUME_DM_BY_SCAN:
  1402. RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE,
  1403. "[IO CMD] Resume DM after scan.\n");
  1404. postprocessing = true;
  1405. break;
  1406. case IO_CMD_PAUSE_BAND0_DM_BY_SCAN:
  1407. RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE,
  1408. "[IO CMD] Pause DM before scan.\n");
  1409. postprocessing = true;
  1410. break;
  1411. default:
  1412. RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
  1413. "switch case not process\n");
  1414. break;
  1415. }
  1416. } while (false);
  1417. if (postprocessing && !rtlphy->set_io_inprogress) {
  1418. rtlphy->set_io_inprogress = true;
  1419. rtlphy->current_io_type = iotype;
  1420. } else {
  1421. return false;
  1422. }
  1423. rtl92c_phy_set_io(hw);
  1424. RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE, "IO Type(%#x)\n", iotype);
  1425. return true;
  1426. }
  1427. EXPORT_SYMBOL(rtl92c_phy_set_io_cmd);
  1428. void rtl92c_phy_set_io(struct ieee80211_hw *hw)
  1429. {
  1430. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1431. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1432. struct dig_t *dm_digtable = &rtlpriv->dm_digtable;
  1433. RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE,
  1434. "--->Cmd(%#x), set_io_inprogress(%d)\n",
  1435. rtlphy->current_io_type, rtlphy->set_io_inprogress);
  1436. switch (rtlphy->current_io_type) {
  1437. case IO_CMD_RESUME_DM_BY_SCAN:
  1438. dm_digtable->cur_igvalue = rtlphy->initgain_backup.xaagccore1;
  1439. rtl92c_dm_write_dig(hw);
  1440. rtl92c_phy_set_txpower_level(hw, rtlphy->current_channel);
  1441. break;
  1442. case IO_CMD_PAUSE_BAND0_DM_BY_SCAN:
  1443. rtlphy->initgain_backup.xaagccore1 = dm_digtable->cur_igvalue;
  1444. dm_digtable->cur_igvalue = 0x17;
  1445. rtl92c_dm_write_dig(hw);
  1446. break;
  1447. default:
  1448. RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
  1449. "switch case not process\n");
  1450. break;
  1451. }
  1452. rtlphy->set_io_inprogress = false;
  1453. RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE,
  1454. "(%#x)\n", rtlphy->current_io_type);
  1455. }
  1456. EXPORT_SYMBOL(rtl92c_phy_set_io);
  1457. void rtl92ce_phy_set_rf_on(struct ieee80211_hw *hw)
  1458. {
  1459. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1460. rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x2b);
  1461. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE3);
  1462. rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x00);
  1463. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
  1464. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE3);
  1465. rtl_write_byte(rtlpriv, REG_TXPAUSE, 0x00);
  1466. }
  1467. EXPORT_SYMBOL(rtl92ce_phy_set_rf_on);
  1468. void _rtl92c_phy_set_rf_sleep(struct ieee80211_hw *hw)
  1469. {
  1470. u32 u4b_tmp;
  1471. u8 delay = 5;
  1472. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1473. rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF);
  1474. rtl_set_rfreg(hw, RF90_PATH_A, 0x00, RFREG_OFFSET_MASK, 0x00);
  1475. rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x40);
  1476. u4b_tmp = rtl_get_rfreg(hw, RF90_PATH_A, 0, RFREG_OFFSET_MASK);
  1477. while (u4b_tmp != 0 && delay > 0) {
  1478. rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x0);
  1479. rtl_set_rfreg(hw, RF90_PATH_A, 0x00, RFREG_OFFSET_MASK, 0x00);
  1480. rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x40);
  1481. u4b_tmp = rtl_get_rfreg(hw, RF90_PATH_A, 0, RFREG_OFFSET_MASK);
  1482. delay--;
  1483. }
  1484. if (delay == 0) {
  1485. rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x00);
  1486. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
  1487. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE3);
  1488. rtl_write_byte(rtlpriv, REG_TXPAUSE, 0x00);
  1489. RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE,
  1490. "Switch RF timeout !!!.\n");
  1491. return;
  1492. }
  1493. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
  1494. rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x22);
  1495. }
  1496. EXPORT_SYMBOL(_rtl92c_phy_set_rf_sleep);