phy_common.c 50 KB

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