phy.c 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2013 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 "../pci.h"
  27. #include "../ps.h"
  28. #include "reg.h"
  29. #include "def.h"
  30. #include "phy.h"
  31. #include "rf.h"
  32. #include "dm.h"
  33. #include "table.h"
  34. static u32 _rtl88e_phy_rf_serial_read(struct ieee80211_hw *hw,
  35. enum radio_path rfpath, u32 offset);
  36. static void _rtl88e_phy_rf_serial_write(struct ieee80211_hw *hw,
  37. enum radio_path rfpath, u32 offset,
  38. u32 data);
  39. static u32 _rtl88e_phy_calculate_bit_shift(u32 bitmask);
  40. static bool _rtl88e_phy_bb8188e_config_parafile(struct ieee80211_hw *hw);
  41. static bool _rtl88e_phy_config_mac_with_headerfile(struct ieee80211_hw *hw);
  42. static bool phy_config_bb_with_headerfile(struct ieee80211_hw *hw,
  43. u8 configtype);
  44. static bool phy_config_bb_with_pghdr(struct ieee80211_hw *hw,
  45. u8 configtype);
  46. static void _rtl88e_phy_init_bb_rf_register_definition(struct ieee80211_hw *hw);
  47. static bool _rtl88e_phy_set_sw_chnl_cmdarray(struct swchnlcmd *cmdtable,
  48. u32 cmdtableidx, u32 cmdtablesz,
  49. enum swchnlcmd_id cmdid, u32 para1,
  50. u32 para2, u32 msdelay);
  51. static bool _rtl88e_phy_sw_chnl_step_by_step(struct ieee80211_hw *hw,
  52. u8 channel, u8 *stage, u8 *step,
  53. u32 *delay);
  54. static long _rtl88e_phy_txpwr_idx_to_dbm(struct ieee80211_hw *hw,
  55. enum wireless_mode wirelessmode,
  56. u8 txpwridx);
  57. static void rtl88ee_phy_set_rf_on(struct ieee80211_hw *hw);
  58. static void rtl88e_phy_set_io(struct ieee80211_hw *hw);
  59. u32 rtl88e_phy_query_bb_reg(struct ieee80211_hw *hw, u32 regaddr, u32 bitmask)
  60. {
  61. struct rtl_priv *rtlpriv = rtl_priv(hw);
  62. u32 returnvalue, originalvalue, bitshift;
  63. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
  64. "regaddr(%#x), bitmask(%#x)\n", regaddr, bitmask);
  65. originalvalue = rtl_read_dword(rtlpriv, regaddr);
  66. bitshift = _rtl88e_phy_calculate_bit_shift(bitmask);
  67. returnvalue = (originalvalue & bitmask) >> bitshift;
  68. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
  69. "BBR MASK=0x%x Addr[0x%x]=0x%x\n", bitmask,
  70. regaddr, originalvalue);
  71. return returnvalue;
  72. }
  73. void rtl88e_phy_set_bb_reg(struct ieee80211_hw *hw,
  74. u32 regaddr, u32 bitmask, u32 data)
  75. {
  76. struct rtl_priv *rtlpriv = rtl_priv(hw);
  77. u32 originalvalue, bitshift;
  78. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
  79. "regaddr(%#x), bitmask(%#x), data(%#x)\n",
  80. regaddr, bitmask, data);
  81. if (bitmask != MASKDWORD) {
  82. originalvalue = rtl_read_dword(rtlpriv, regaddr);
  83. bitshift = _rtl88e_phy_calculate_bit_shift(bitmask);
  84. data = ((originalvalue & (~bitmask)) | (data << bitshift));
  85. }
  86. rtl_write_dword(rtlpriv, regaddr, data);
  87. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
  88. "regaddr(%#x), bitmask(%#x), data(%#x)\n",
  89. regaddr, bitmask, data);
  90. }
  91. u32 rtl88e_phy_query_rf_reg(struct ieee80211_hw *hw,
  92. enum radio_path rfpath, u32 regaddr, u32 bitmask)
  93. {
  94. struct rtl_priv *rtlpriv = rtl_priv(hw);
  95. u32 original_value, readback_value, bitshift;
  96. unsigned long flags;
  97. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
  98. "regaddr(%#x), rfpath(%#x), bitmask(%#x)\n",
  99. regaddr, rfpath, bitmask);
  100. spin_lock_irqsave(&rtlpriv->locks.rf_lock, flags);
  101. original_value = _rtl88e_phy_rf_serial_read(hw, rfpath, regaddr);
  102. bitshift = _rtl88e_phy_calculate_bit_shift(bitmask);
  103. readback_value = (original_value & bitmask) >> bitshift;
  104. spin_unlock_irqrestore(&rtlpriv->locks.rf_lock, flags);
  105. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
  106. "regaddr(%#x), rfpath(%#x), bitmask(%#x), original_value(%#x)\n",
  107. regaddr, rfpath, bitmask, original_value);
  108. return readback_value;
  109. }
  110. void rtl88e_phy_set_rf_reg(struct ieee80211_hw *hw,
  111. enum radio_path rfpath,
  112. u32 regaddr, u32 bitmask, u32 data)
  113. {
  114. struct rtl_priv *rtlpriv = rtl_priv(hw);
  115. u32 original_value, bitshift;
  116. unsigned long flags;
  117. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
  118. "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
  119. regaddr, bitmask, data, rfpath);
  120. spin_lock_irqsave(&rtlpriv->locks.rf_lock, flags);
  121. if (bitmask != RFREG_OFFSET_MASK) {
  122. original_value = _rtl88e_phy_rf_serial_read(hw,
  123. rfpath,
  124. regaddr);
  125. bitshift = _rtl88e_phy_calculate_bit_shift(bitmask);
  126. data =
  127. ((original_value & (~bitmask)) |
  128. (data << bitshift));
  129. }
  130. _rtl88e_phy_rf_serial_write(hw, rfpath, regaddr, data);
  131. spin_unlock_irqrestore(&rtlpriv->locks.rf_lock, flags);
  132. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
  133. "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
  134. regaddr, bitmask, data, rfpath);
  135. }
  136. static u32 _rtl88e_phy_rf_serial_read(struct ieee80211_hw *hw,
  137. enum radio_path rfpath, u32 offset)
  138. {
  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. u32 newoffset;
  143. u32 tmplong, tmplong2;
  144. u8 rfpi_enable = 0;
  145. u32 retvalue;
  146. offset &= 0xff;
  147. newoffset = offset;
  148. if (RT_CANNOT_IO(hw)) {
  149. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "return all one\n");
  150. return 0xFFFFFFFF;
  151. }
  152. tmplong = rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, MASKDWORD);
  153. if (rfpath == RF90_PATH_A)
  154. tmplong2 = tmplong;
  155. else
  156. tmplong2 = rtl_get_bbreg(hw, pphyreg->rfhssi_para2, MASKDWORD);
  157. tmplong2 = (tmplong2 & (~BLSSIREADADDRESS)) |
  158. (newoffset << 23) | BLSSIREADEDGE;
  159. rtl_set_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, MASKDWORD,
  160. tmplong & (~BLSSIREADEDGE));
  161. mdelay(1);
  162. rtl_set_bbreg(hw, pphyreg->rfhssi_para2, MASKDWORD, tmplong2);
  163. mdelay(2);
  164. if (rfpath == RF90_PATH_A)
  165. rfpi_enable = (u8)rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER1,
  166. BIT(8));
  167. else if (rfpath == RF90_PATH_B)
  168. rfpi_enable = (u8)rtl_get_bbreg(hw, RFPGA0_XB_HSSIPARAMETER1,
  169. BIT(8));
  170. if (rfpi_enable)
  171. retvalue = rtl_get_bbreg(hw, pphyreg->rf_rbpi,
  172. BLSSIREADBACKDATA);
  173. else
  174. retvalue = rtl_get_bbreg(hw, pphyreg->rf_rb,
  175. BLSSIREADBACKDATA);
  176. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
  177. "RFR-%d Addr[0x%x]=0x%x\n",
  178. rfpath, pphyreg->rf_rb, retvalue);
  179. return retvalue;
  180. }
  181. static void _rtl88e_phy_rf_serial_write(struct ieee80211_hw *hw,
  182. enum radio_path rfpath, u32 offset,
  183. u32 data)
  184. {
  185. u32 data_and_addr;
  186. u32 newoffset;
  187. struct rtl_priv *rtlpriv = rtl_priv(hw);
  188. struct rtl_phy *rtlphy = &rtlpriv->phy;
  189. struct bb_reg_def *pphyreg = &rtlphy->phyreg_def[rfpath];
  190. if (RT_CANNOT_IO(hw)) {
  191. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "stop\n");
  192. return;
  193. }
  194. offset &= 0xff;
  195. newoffset = offset;
  196. data_and_addr = ((newoffset << 20) | (data & 0x000fffff)) & 0x0fffffff;
  197. rtl_set_bbreg(hw, pphyreg->rf3wire_offset, MASKDWORD, data_and_addr);
  198. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
  199. "RFW-%d Addr[0x%x]=0x%x\n",
  200. rfpath, pphyreg->rf3wire_offset, data_and_addr);
  201. }
  202. static u32 _rtl88e_phy_calculate_bit_shift(u32 bitmask)
  203. {
  204. u32 i;
  205. for (i = 0; i <= 31; i++) {
  206. if (((bitmask >> i) & 0x1) == 1)
  207. break;
  208. }
  209. return i;
  210. }
  211. bool rtl88e_phy_mac_config(struct ieee80211_hw *hw)
  212. {
  213. struct rtl_priv *rtlpriv = rtl_priv(hw);
  214. bool rtstatus = _rtl88e_phy_config_mac_with_headerfile(hw);
  215. rtl_write_byte(rtlpriv, 0x04CA, 0x0B);
  216. return rtstatus;
  217. }
  218. bool rtl88e_phy_bb_config(struct ieee80211_hw *hw)
  219. {
  220. bool rtstatus = true;
  221. struct rtl_priv *rtlpriv = rtl_priv(hw);
  222. u16 regval;
  223. u8 b_reg_hwparafile = 1;
  224. u32 tmp;
  225. _rtl88e_phy_init_bb_rf_register_definition(hw);
  226. regval = rtl_read_word(rtlpriv, REG_SYS_FUNC_EN);
  227. rtl_write_word(rtlpriv, REG_SYS_FUNC_EN,
  228. regval | BIT(13) | BIT(0) | BIT(1));
  229. rtl_write_byte(rtlpriv, REG_RF_CTRL, RF_EN | RF_RSTB | RF_SDMRSTB);
  230. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN,
  231. FEN_PPLL | FEN_PCIEA | FEN_DIO_PCIE |
  232. FEN_BB_GLB_RSTN | FEN_BBRSTB);
  233. tmp = rtl_read_dword(rtlpriv, 0x4c);
  234. rtl_write_dword(rtlpriv, 0x4c, tmp | BIT(23));
  235. if (b_reg_hwparafile == 1)
  236. rtstatus = _rtl88e_phy_bb8188e_config_parafile(hw);
  237. return rtstatus;
  238. }
  239. bool rtl88e_phy_rf_config(struct ieee80211_hw *hw)
  240. {
  241. return rtl88e_phy_rf6052_config(hw);
  242. }
  243. static bool _rtl88e_check_condition(struct ieee80211_hw *hw,
  244. const u32 condition)
  245. {
  246. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  247. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  248. u32 _board = rtlefuse->board_type; /*need efuse define*/
  249. u32 _interface = rtlhal->interface;
  250. u32 _platform = 0x08;/*SupportPlatform */
  251. u32 cond = condition;
  252. if (condition == 0xCDCDCDCD)
  253. return true;
  254. cond = condition & 0xFF;
  255. if ((_board & cond) == 0 && cond != 0x1F)
  256. return false;
  257. cond = condition & 0xFF00;
  258. cond = cond >> 8;
  259. if ((_interface & cond) == 0 && cond != 0x07)
  260. return false;
  261. cond = condition & 0xFF0000;
  262. cond = cond >> 16;
  263. if ((_platform & cond) == 0 && cond != 0x0F)
  264. return false;
  265. return true;
  266. }
  267. static void _rtl8188e_config_rf_reg(struct ieee80211_hw *hw, u32 addr,
  268. u32 data, enum radio_path rfpath,
  269. u32 regaddr)
  270. {
  271. if (addr == 0xffe) {
  272. mdelay(50);
  273. } else if (addr == 0xfd) {
  274. mdelay(5);
  275. } else if (addr == 0xfc) {
  276. mdelay(1);
  277. } else if (addr == 0xfb) {
  278. udelay(50);
  279. } else if (addr == 0xfa) {
  280. udelay(5);
  281. } else if (addr == 0xf9) {
  282. udelay(1);
  283. } else {
  284. rtl_set_rfreg(hw, rfpath, regaddr,
  285. RFREG_OFFSET_MASK,
  286. data);
  287. udelay(1);
  288. }
  289. }
  290. static void _rtl8188e_config_rf_radio_a(struct ieee80211_hw *hw,
  291. u32 addr, u32 data)
  292. {
  293. u32 content = 0x1000; /*RF Content: radio_a_txt*/
  294. u32 maskforphyset = (u32)(content & 0xE000);
  295. _rtl8188e_config_rf_reg(hw, addr, data, RF90_PATH_A,
  296. addr | maskforphyset);
  297. }
  298. static void _rtl8188e_config_bb_reg(struct ieee80211_hw *hw,
  299. u32 addr, u32 data)
  300. {
  301. if (addr == 0xfe) {
  302. mdelay(50);
  303. } else if (addr == 0xfd) {
  304. mdelay(5);
  305. } else if (addr == 0xfc) {
  306. mdelay(1);
  307. } else if (addr == 0xfb) {
  308. udelay(50);
  309. } else if (addr == 0xfa) {
  310. udelay(5);
  311. } else if (addr == 0xf9) {
  312. udelay(1);
  313. } else {
  314. rtl_set_bbreg(hw, addr, MASKDWORD, data);
  315. udelay(1);
  316. }
  317. }
  318. static bool _rtl88e_phy_bb8188e_config_parafile(struct ieee80211_hw *hw)
  319. {
  320. struct rtl_priv *rtlpriv = rtl_priv(hw);
  321. struct rtl_phy *rtlphy = &rtlpriv->phy;
  322. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  323. bool rtstatus;
  324. rtstatus = phy_config_bb_with_headerfile(hw, BASEBAND_CONFIG_PHY_REG);
  325. if (!rtstatus) {
  326. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Write BB Reg Fail!!");
  327. return false;
  328. }
  329. if (!rtlefuse->autoload_failflag) {
  330. rtlphy->pwrgroup_cnt = 0;
  331. rtstatus =
  332. phy_config_bb_with_pghdr(hw, BASEBAND_CONFIG_PHY_REG);
  333. }
  334. if (!rtstatus) {
  335. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "BB_PG Reg Fail!!");
  336. return false;
  337. }
  338. rtstatus =
  339. phy_config_bb_with_headerfile(hw, BASEBAND_CONFIG_AGC_TAB);
  340. if (!rtstatus) {
  341. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "AGC Table Fail\n");
  342. return false;
  343. }
  344. rtlphy->cck_high_power =
  345. (bool)(rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, 0x200));
  346. return true;
  347. }
  348. static bool _rtl88e_phy_config_mac_with_headerfile(struct ieee80211_hw *hw)
  349. {
  350. struct rtl_priv *rtlpriv = rtl_priv(hw);
  351. u32 i;
  352. u32 arraylength;
  353. u32 *ptrarray;
  354. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "Read Rtl8188EMACPHY_Array\n");
  355. arraylength = RTL8188EEMAC_1T_ARRAYLEN;
  356. ptrarray = RTL8188EEMAC_1T_ARRAY;
  357. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  358. "Img:RTL8188EEMAC_1T_ARRAY LEN %d\n", arraylength);
  359. for (i = 0; i < arraylength; i = i + 2)
  360. rtl_write_byte(rtlpriv, ptrarray[i], (u8)ptrarray[i + 1]);
  361. return true;
  362. }
  363. #define READ_NEXT_PAIR(v1, v2, i) \
  364. do { \
  365. i += 2; v1 = array_table[i]; \
  366. v2 = array_table[i+1]; \
  367. } while (0)
  368. static void handle_branch1(struct ieee80211_hw *hw, u16 arraylen,
  369. u32 *array_table)
  370. {
  371. u32 v1;
  372. u32 v2;
  373. int i;
  374. for (i = 0; i < arraylen; i = i + 2) {
  375. v1 = array_table[i];
  376. v2 = array_table[i+1];
  377. if (v1 < 0xcdcdcdcd) {
  378. _rtl8188e_config_bb_reg(hw, v1, v2);
  379. } else { /*This line is the start line of branch.*/
  380. /* to protect READ_NEXT_PAIR not overrun */
  381. if (i >= arraylen - 2)
  382. break;
  383. if (!_rtl88e_check_condition(hw, array_table[i])) {
  384. /*Discard the following (offset, data) pairs*/
  385. READ_NEXT_PAIR(v1, v2, i);
  386. while (v2 != 0xDEAD &&
  387. v2 != 0xCDEF &&
  388. v2 != 0xCDCD && i < arraylen - 2)
  389. READ_NEXT_PAIR(v1, v2, i);
  390. i -= 2; /* prevent from for-loop += 2*/
  391. } else { /* Configure matched pairs and skip
  392. * to end of if-else.
  393. */
  394. READ_NEXT_PAIR(v1, v2, i);
  395. while (v2 != 0xDEAD &&
  396. v2 != 0xCDEF &&
  397. v2 != 0xCDCD && i < arraylen - 2) {
  398. _rtl8188e_config_bb_reg(hw, v1, v2);
  399. READ_NEXT_PAIR(v1, v2, i);
  400. }
  401. while (v2 != 0xDEAD && i < arraylen - 2)
  402. READ_NEXT_PAIR(v1, v2, i);
  403. }
  404. }
  405. }
  406. }
  407. static void handle_branch2(struct ieee80211_hw *hw, u16 arraylen,
  408. u32 *array_table)
  409. {
  410. struct rtl_priv *rtlpriv = rtl_priv(hw);
  411. u32 v1;
  412. u32 v2;
  413. int i;
  414. for (i = 0; i < arraylen; i = i + 2) {
  415. v1 = array_table[i];
  416. v2 = array_table[i+1];
  417. if (v1 < 0xCDCDCDCD) {
  418. rtl_set_bbreg(hw, array_table[i], MASKDWORD,
  419. array_table[i + 1]);
  420. udelay(1);
  421. continue;
  422. } else { /*This line is the start line of branch.*/
  423. /* to protect READ_NEXT_PAIR not overrun */
  424. if (i >= arraylen - 2)
  425. break;
  426. if (!_rtl88e_check_condition(hw, array_table[i])) {
  427. /*Discard the following (offset, data) pairs*/
  428. READ_NEXT_PAIR(v1, v2, i);
  429. while (v2 != 0xDEAD &&
  430. v2 != 0xCDEF &&
  431. v2 != 0xCDCD && i < arraylen - 2)
  432. READ_NEXT_PAIR(v1, v2, i);
  433. i -= 2; /* prevent from for-loop += 2*/
  434. } else { /* Configure matched pairs and skip
  435. * to end of if-else.
  436. */
  437. READ_NEXT_PAIR(v1, v2, i);
  438. while (v2 != 0xDEAD &&
  439. v2 != 0xCDEF &&
  440. v2 != 0xCDCD && i < arraylen - 2) {
  441. rtl_set_bbreg(hw, array_table[i],
  442. MASKDWORD,
  443. array_table[i + 1]);
  444. udelay(1);
  445. READ_NEXT_PAIR(v1, v2, i);
  446. }
  447. while (v2 != 0xDEAD && i < arraylen - 2)
  448. READ_NEXT_PAIR(v1, v2, i);
  449. }
  450. }
  451. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  452. "The agctab_array_table[0] is %x Rtl818EEPHY_REGArray[1] is %x\n",
  453. array_table[i], array_table[i + 1]);
  454. }
  455. }
  456. static bool phy_config_bb_with_headerfile(struct ieee80211_hw *hw,
  457. u8 configtype)
  458. {
  459. u32 *array_table;
  460. u16 arraylen;
  461. if (configtype == BASEBAND_CONFIG_PHY_REG) {
  462. arraylen = RTL8188EEPHY_REG_1TARRAYLEN;
  463. array_table = RTL8188EEPHY_REG_1TARRAY;
  464. handle_branch1(hw, arraylen, array_table);
  465. } else if (configtype == BASEBAND_CONFIG_AGC_TAB) {
  466. arraylen = RTL8188EEAGCTAB_1TARRAYLEN;
  467. array_table = RTL8188EEAGCTAB_1TARRAY;
  468. handle_branch2(hw, arraylen, array_table);
  469. }
  470. return true;
  471. }
  472. static void store_pwrindex_rate_offset(struct ieee80211_hw *hw,
  473. u32 regaddr, u32 bitmask,
  474. u32 data)
  475. {
  476. struct rtl_priv *rtlpriv = rtl_priv(hw);
  477. struct rtl_phy *rtlphy = &rtlpriv->phy;
  478. int count = rtlphy->pwrgroup_cnt;
  479. if (regaddr == RTXAGC_A_RATE18_06) {
  480. rtlphy->mcs_txpwrlevel_origoffset[count][0] = data;
  481. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  482. "MCSTxPowerLevelOriginalOffset[%d][0] = 0x%x\n",
  483. count,
  484. rtlphy->mcs_txpwrlevel_origoffset[count][0]);
  485. }
  486. if (regaddr == RTXAGC_A_RATE54_24) {
  487. rtlphy->mcs_txpwrlevel_origoffset[count][1] = data;
  488. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  489. "MCSTxPowerLevelOriginalOffset[%d][1] = 0x%x\n",
  490. count,
  491. rtlphy->mcs_txpwrlevel_origoffset[count][1]);
  492. }
  493. if (regaddr == RTXAGC_A_CCK1_MCS32) {
  494. rtlphy->mcs_txpwrlevel_origoffset[count][6] = data;
  495. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  496. "MCSTxPowerLevelOriginalOffset[%d][6] = 0x%x\n",
  497. count,
  498. rtlphy->mcs_txpwrlevel_origoffset[count][6]);
  499. }
  500. if (regaddr == RTXAGC_B_CCK11_A_CCK2_11 && bitmask == 0xffffff00) {
  501. rtlphy->mcs_txpwrlevel_origoffset[count][7] = data;
  502. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  503. "MCSTxPowerLevelOriginalOffset[%d][7] = 0x%x\n",
  504. count,
  505. rtlphy->mcs_txpwrlevel_origoffset[count][7]);
  506. }
  507. if (regaddr == RTXAGC_A_MCS03_MCS00) {
  508. rtlphy->mcs_txpwrlevel_origoffset[count][2] = data;
  509. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  510. "MCSTxPowerLevelOriginalOffset[%d][2] = 0x%x\n",
  511. count,
  512. rtlphy->mcs_txpwrlevel_origoffset[count][2]);
  513. }
  514. if (regaddr == RTXAGC_A_MCS07_MCS04) {
  515. rtlphy->mcs_txpwrlevel_origoffset[count][3] = data;
  516. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  517. "MCSTxPowerLevelOriginalOffset[%d][3] = 0x%x\n",
  518. count,
  519. rtlphy->mcs_txpwrlevel_origoffset[count][3]);
  520. }
  521. if (regaddr == RTXAGC_A_MCS11_MCS08) {
  522. rtlphy->mcs_txpwrlevel_origoffset[count][4] = data;
  523. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  524. "MCSTxPowerLevelOriginalOffset[%d][4] = 0x%x\n",
  525. count,
  526. rtlphy->mcs_txpwrlevel_origoffset[count][4]);
  527. }
  528. if (regaddr == RTXAGC_A_MCS15_MCS12) {
  529. rtlphy->mcs_txpwrlevel_origoffset[count][5] = data;
  530. if (get_rf_type(rtlphy) == RF_1T1R) {
  531. count++;
  532. rtlphy->pwrgroup_cnt = count;
  533. }
  534. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  535. "MCSTxPowerLevelOriginalOffset[%d][5] = 0x%x\n",
  536. count,
  537. rtlphy->mcs_txpwrlevel_origoffset[count][5]);
  538. }
  539. if (regaddr == RTXAGC_B_RATE18_06) {
  540. rtlphy->mcs_txpwrlevel_origoffset[count][8] = data;
  541. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  542. "MCSTxPowerLevelOriginalOffset[%d][8] = 0x%x\n",
  543. count,
  544. rtlphy->mcs_txpwrlevel_origoffset[count][8]);
  545. }
  546. if (regaddr == RTXAGC_B_RATE54_24) {
  547. rtlphy->mcs_txpwrlevel_origoffset[count][9] = data;
  548. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  549. "MCSTxPowerLevelOriginalOffset[%d][9] = 0x%x\n",
  550. count,
  551. rtlphy->mcs_txpwrlevel_origoffset[count][9]);
  552. }
  553. if (regaddr == RTXAGC_B_CCK1_55_MCS32) {
  554. rtlphy->mcs_txpwrlevel_origoffset[count][14] = data;
  555. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  556. "MCSTxPowerLevelOriginalOffset[%d][14] = 0x%x\n",
  557. count,
  558. rtlphy->mcs_txpwrlevel_origoffset[count][14]);
  559. }
  560. if (regaddr == RTXAGC_B_CCK11_A_CCK2_11 && bitmask == 0x000000ff) {
  561. rtlphy->mcs_txpwrlevel_origoffset[count][15] = data;
  562. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  563. "MCSTxPowerLevelOriginalOffset[%d][15] = 0x%x\n",
  564. count,
  565. rtlphy->mcs_txpwrlevel_origoffset[count][15]);
  566. }
  567. if (regaddr == RTXAGC_B_MCS03_MCS00) {
  568. rtlphy->mcs_txpwrlevel_origoffset[count][10] = data;
  569. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  570. "MCSTxPowerLevelOriginalOffset[%d][10] = 0x%x\n",
  571. count,
  572. rtlphy->mcs_txpwrlevel_origoffset[count][10]);
  573. }
  574. if (regaddr == RTXAGC_B_MCS07_MCS04) {
  575. rtlphy->mcs_txpwrlevel_origoffset[count][11] = data;
  576. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  577. "MCSTxPowerLevelOriginalOffset[%d][11] = 0x%x\n",
  578. count,
  579. rtlphy->mcs_txpwrlevel_origoffset[count][11]);
  580. }
  581. if (regaddr == RTXAGC_B_MCS11_MCS08) {
  582. rtlphy->mcs_txpwrlevel_origoffset[count][12] = data;
  583. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  584. "MCSTxPowerLevelOriginalOffset[%d][12] = 0x%x\n",
  585. count,
  586. rtlphy->mcs_txpwrlevel_origoffset[count][12]);
  587. }
  588. if (regaddr == RTXAGC_B_MCS15_MCS12) {
  589. rtlphy->mcs_txpwrlevel_origoffset[count][13] = data;
  590. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  591. "MCSTxPowerLevelOriginalOffset[%d][13] = 0x%x\n",
  592. count,
  593. rtlphy->mcs_txpwrlevel_origoffset[count][13]);
  594. if (get_rf_type(rtlphy) != RF_1T1R) {
  595. count++;
  596. rtlphy->pwrgroup_cnt = count;
  597. }
  598. }
  599. }
  600. static bool phy_config_bb_with_pghdr(struct ieee80211_hw *hw, u8 configtype)
  601. {
  602. struct rtl_priv *rtlpriv = rtl_priv(hw);
  603. int i;
  604. u32 *phy_reg_page;
  605. u16 phy_reg_page_len;
  606. u32 v1 = 0, v2 = 0, v3 = 0;
  607. phy_reg_page_len = RTL8188EEPHY_REG_ARRAY_PGLEN;
  608. phy_reg_page = RTL8188EEPHY_REG_ARRAY_PG;
  609. if (configtype == BASEBAND_CONFIG_PHY_REG) {
  610. for (i = 0; i < phy_reg_page_len; i = i + 3) {
  611. v1 = phy_reg_page[i];
  612. v2 = phy_reg_page[i+1];
  613. v3 = phy_reg_page[i+2];
  614. if (v1 < 0xcdcdcdcd) {
  615. if (phy_reg_page[i] == 0xfe)
  616. mdelay(50);
  617. else if (phy_reg_page[i] == 0xfd)
  618. mdelay(5);
  619. else if (phy_reg_page[i] == 0xfc)
  620. mdelay(1);
  621. else if (phy_reg_page[i] == 0xfb)
  622. udelay(50);
  623. else if (phy_reg_page[i] == 0xfa)
  624. udelay(5);
  625. else if (phy_reg_page[i] == 0xf9)
  626. udelay(1);
  627. store_pwrindex_rate_offset(hw, phy_reg_page[i],
  628. phy_reg_page[i + 1],
  629. phy_reg_page[i + 2]);
  630. continue;
  631. } else {
  632. if (!_rtl88e_check_condition(hw,
  633. phy_reg_page[i])) {
  634. /*don't need the hw_body*/
  635. i += 2; /* skip the pair of expression*/
  636. /* to protect 'i+1' 'i+2' not overrun */
  637. if (i >= phy_reg_page_len - 2)
  638. break;
  639. v1 = phy_reg_page[i];
  640. v2 = phy_reg_page[i+1];
  641. v3 = phy_reg_page[i+2];
  642. while (v2 != 0xDEAD &&
  643. i < phy_reg_page_len - 5) {
  644. i += 3;
  645. v1 = phy_reg_page[i];
  646. v2 = phy_reg_page[i+1];
  647. v3 = phy_reg_page[i+2];
  648. }
  649. }
  650. }
  651. }
  652. } else {
  653. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  654. "configtype != BaseBand_Config_PHY_REG\n");
  655. }
  656. return true;
  657. }
  658. #define READ_NEXT_RF_PAIR(v1, v2, i) \
  659. do { \
  660. i += 2; \
  661. v1 = radioa_array_table[i]; \
  662. v2 = radioa_array_table[i+1]; \
  663. } while (0)
  664. static void process_path_a(struct ieee80211_hw *hw,
  665. u16 radioa_arraylen,
  666. u32 *radioa_array_table)
  667. {
  668. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  669. u32 v1, v2;
  670. int i;
  671. for (i = 0; i < radioa_arraylen; i = i + 2) {
  672. v1 = radioa_array_table[i];
  673. v2 = radioa_array_table[i+1];
  674. if (v1 < 0xcdcdcdcd) {
  675. _rtl8188e_config_rf_radio_a(hw, v1, v2);
  676. } else { /*This line is the start line of branch.*/
  677. /* to protect READ_NEXT_PAIR not overrun */
  678. if (i >= radioa_arraylen - 2)
  679. break;
  680. if (!_rtl88e_check_condition(hw, radioa_array_table[i])) {
  681. /*Discard the following (offset, data) pairs*/
  682. READ_NEXT_RF_PAIR(v1, v2, i);
  683. while (v2 != 0xDEAD &&
  684. v2 != 0xCDEF &&
  685. v2 != 0xCDCD &&
  686. i < radioa_arraylen - 2) {
  687. READ_NEXT_RF_PAIR(v1, v2, i);
  688. }
  689. i -= 2; /* prevent from for-loop += 2*/
  690. } else { /* Configure matched pairs and
  691. * skip to end of if-else.
  692. */
  693. READ_NEXT_RF_PAIR(v1, v2, i);
  694. while (v2 != 0xDEAD &&
  695. v2 != 0xCDEF &&
  696. v2 != 0xCDCD &&
  697. i < radioa_arraylen - 2) {
  698. _rtl8188e_config_rf_radio_a(hw, v1, v2);
  699. READ_NEXT_RF_PAIR(v1, v2, i);
  700. }
  701. while (v2 != 0xDEAD &&
  702. i < radioa_arraylen - 2)
  703. READ_NEXT_RF_PAIR(v1, v2, i);
  704. }
  705. }
  706. }
  707. if (rtlhal->oem_id == RT_CID_819X_HP)
  708. _rtl8188e_config_rf_radio_a(hw, 0x52, 0x7E4BD);
  709. }
  710. bool rtl88e_phy_config_rf_with_headerfile(struct ieee80211_hw *hw,
  711. enum radio_path rfpath)
  712. {
  713. struct rtl_priv *rtlpriv = rtl_priv(hw);
  714. bool rtstatus = true;
  715. u32 *radioa_array_table;
  716. u16 radioa_arraylen;
  717. radioa_arraylen = RTL8188EE_RADIOA_1TARRAYLEN;
  718. radioa_array_table = RTL8188EE_RADIOA_1TARRAY;
  719. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  720. "Radio_A:RTL8188EE_RADIOA_1TARRAY %d\n", radioa_arraylen);
  721. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Radio No %x\n", rfpath);
  722. rtstatus = true;
  723. switch (rfpath) {
  724. case RF90_PATH_A:
  725. process_path_a(hw, radioa_arraylen, radioa_array_table);
  726. break;
  727. case RF90_PATH_B:
  728. case RF90_PATH_C:
  729. case RF90_PATH_D:
  730. break;
  731. }
  732. return true;
  733. }
  734. void rtl88e_phy_get_hw_reg_originalvalue(struct ieee80211_hw *hw)
  735. {
  736. struct rtl_priv *rtlpriv = rtl_priv(hw);
  737. struct rtl_phy *rtlphy = &rtlpriv->phy;
  738. rtlphy->default_initialgain[0] =
  739. (u8)rtl_get_bbreg(hw, ROFDM0_XAAGCCORE1, MASKBYTE0);
  740. rtlphy->default_initialgain[1] =
  741. (u8)rtl_get_bbreg(hw, ROFDM0_XBAGCCORE1, MASKBYTE0);
  742. rtlphy->default_initialgain[2] =
  743. (u8)rtl_get_bbreg(hw, ROFDM0_XCAGCCORE1, MASKBYTE0);
  744. rtlphy->default_initialgain[3] =
  745. (u8)rtl_get_bbreg(hw, ROFDM0_XDAGCCORE1, MASKBYTE0);
  746. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  747. "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x\n",
  748. rtlphy->default_initialgain[0],
  749. rtlphy->default_initialgain[1],
  750. rtlphy->default_initialgain[2],
  751. rtlphy->default_initialgain[3]);
  752. rtlphy->framesync = (u8)rtl_get_bbreg(hw, ROFDM0_RXDETECTOR3,
  753. MASKBYTE0);
  754. rtlphy->framesync_c34 = rtl_get_bbreg(hw, ROFDM0_RXDETECTOR2,
  755. MASKDWORD);
  756. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  757. "Default framesync (0x%x) = 0x%x\n",
  758. ROFDM0_RXDETECTOR3, rtlphy->framesync);
  759. }
  760. static void _rtl88e_phy_init_bb_rf_register_definition(struct ieee80211_hw *hw)
  761. {
  762. struct rtl_priv *rtlpriv = rtl_priv(hw);
  763. struct rtl_phy *rtlphy = &rtlpriv->phy;
  764. rtlphy->phyreg_def[RF90_PATH_A].rfintfs = RFPGA0_XAB_RFINTERFACESW;
  765. rtlphy->phyreg_def[RF90_PATH_B].rfintfs = RFPGA0_XAB_RFINTERFACESW;
  766. rtlphy->phyreg_def[RF90_PATH_C].rfintfs = RFPGA0_XCD_RFINTERFACESW;
  767. rtlphy->phyreg_def[RF90_PATH_D].rfintfs = RFPGA0_XCD_RFINTERFACESW;
  768. rtlphy->phyreg_def[RF90_PATH_A].rfintfi = RFPGA0_XAB_RFINTERFACERB;
  769. rtlphy->phyreg_def[RF90_PATH_B].rfintfi = RFPGA0_XAB_RFINTERFACERB;
  770. rtlphy->phyreg_def[RF90_PATH_C].rfintfi = RFPGA0_XCD_RFINTERFACERB;
  771. rtlphy->phyreg_def[RF90_PATH_D].rfintfi = RFPGA0_XCD_RFINTERFACERB;
  772. rtlphy->phyreg_def[RF90_PATH_A].rfintfo = RFPGA0_XA_RFINTERFACEOE;
  773. rtlphy->phyreg_def[RF90_PATH_B].rfintfo = RFPGA0_XB_RFINTERFACEOE;
  774. rtlphy->phyreg_def[RF90_PATH_A].rfintfe = RFPGA0_XA_RFINTERFACEOE;
  775. rtlphy->phyreg_def[RF90_PATH_B].rfintfe = RFPGA0_XB_RFINTERFACEOE;
  776. rtlphy->phyreg_def[RF90_PATH_A].rf3wire_offset =
  777. RFPGA0_XA_LSSIPARAMETER;
  778. rtlphy->phyreg_def[RF90_PATH_B].rf3wire_offset =
  779. RFPGA0_XB_LSSIPARAMETER;
  780. rtlphy->phyreg_def[RF90_PATH_A].rflssi_select = RFPGA0_XAB_RFPARAMETER;
  781. rtlphy->phyreg_def[RF90_PATH_B].rflssi_select = RFPGA0_XAB_RFPARAMETER;
  782. rtlphy->phyreg_def[RF90_PATH_C].rflssi_select = RFPGA0_XCD_RFPARAMETER;
  783. rtlphy->phyreg_def[RF90_PATH_D].rflssi_select = RFPGA0_XCD_RFPARAMETER;
  784. rtlphy->phyreg_def[RF90_PATH_A].rftxgain_stage = RFPGA0_TXGAINSTAGE;
  785. rtlphy->phyreg_def[RF90_PATH_B].rftxgain_stage = RFPGA0_TXGAINSTAGE;
  786. rtlphy->phyreg_def[RF90_PATH_C].rftxgain_stage = RFPGA0_TXGAINSTAGE;
  787. rtlphy->phyreg_def[RF90_PATH_D].rftxgain_stage = RFPGA0_TXGAINSTAGE;
  788. rtlphy->phyreg_def[RF90_PATH_A].rfhssi_para1 = RFPGA0_XA_HSSIPARAMETER1;
  789. rtlphy->phyreg_def[RF90_PATH_B].rfhssi_para1 = RFPGA0_XB_HSSIPARAMETER1;
  790. rtlphy->phyreg_def[RF90_PATH_A].rfhssi_para2 = RFPGA0_XA_HSSIPARAMETER2;
  791. rtlphy->phyreg_def[RF90_PATH_B].rfhssi_para2 = RFPGA0_XB_HSSIPARAMETER2;
  792. rtlphy->phyreg_def[RF90_PATH_A].rfsw_ctrl =
  793. RFPGA0_XAB_SWITCHCONTROL;
  794. rtlphy->phyreg_def[RF90_PATH_B].rfsw_ctrl =
  795. RFPGA0_XAB_SWITCHCONTROL;
  796. rtlphy->phyreg_def[RF90_PATH_C].rfsw_ctrl =
  797. RFPGA0_XCD_SWITCHCONTROL;
  798. rtlphy->phyreg_def[RF90_PATH_D].rfsw_ctrl =
  799. RFPGA0_XCD_SWITCHCONTROL;
  800. rtlphy->phyreg_def[RF90_PATH_A].rfagc_control1 = ROFDM0_XAAGCCORE1;
  801. rtlphy->phyreg_def[RF90_PATH_B].rfagc_control1 = ROFDM0_XBAGCCORE1;
  802. rtlphy->phyreg_def[RF90_PATH_C].rfagc_control1 = ROFDM0_XCAGCCORE1;
  803. rtlphy->phyreg_def[RF90_PATH_D].rfagc_control1 = ROFDM0_XDAGCCORE1;
  804. rtlphy->phyreg_def[RF90_PATH_A].rfagc_control2 = ROFDM0_XAAGCCORE2;
  805. rtlphy->phyreg_def[RF90_PATH_B].rfagc_control2 = ROFDM0_XBAGCCORE2;
  806. rtlphy->phyreg_def[RF90_PATH_C].rfagc_control2 = ROFDM0_XCAGCCORE2;
  807. rtlphy->phyreg_def[RF90_PATH_D].rfagc_control2 = ROFDM0_XDAGCCORE2;
  808. rtlphy->phyreg_def[RF90_PATH_A].rfrxiq_imbal = ROFDM0_XARXIQIMBALANCE;
  809. rtlphy->phyreg_def[RF90_PATH_B].rfrxiq_imbal = ROFDM0_XBRXIQIMBALANCE;
  810. rtlphy->phyreg_def[RF90_PATH_C].rfrxiq_imbal = ROFDM0_XCRXIQIMBANLANCE;
  811. rtlphy->phyreg_def[RF90_PATH_D].rfrxiq_imbal = ROFDM0_XDRXIQIMBALANCE;
  812. rtlphy->phyreg_def[RF90_PATH_A].rfrx_afe = ROFDM0_XARXAFE;
  813. rtlphy->phyreg_def[RF90_PATH_B].rfrx_afe = ROFDM0_XBRXAFE;
  814. rtlphy->phyreg_def[RF90_PATH_C].rfrx_afe = ROFDM0_XCRXAFE;
  815. rtlphy->phyreg_def[RF90_PATH_D].rfrx_afe = ROFDM0_XDRXAFE;
  816. rtlphy->phyreg_def[RF90_PATH_A].rftxiq_imbal = ROFDM0_XATXIQIMBALANCE;
  817. rtlphy->phyreg_def[RF90_PATH_B].rftxiq_imbal = ROFDM0_XBTXIQIMBALANCE;
  818. rtlphy->phyreg_def[RF90_PATH_C].rftxiq_imbal = ROFDM0_XCTXIQIMBALANCE;
  819. rtlphy->phyreg_def[RF90_PATH_D].rftxiq_imbal = ROFDM0_XDTXIQIMBALANCE;
  820. rtlphy->phyreg_def[RF90_PATH_A].rftx_afe = ROFDM0_XATXAFE;
  821. rtlphy->phyreg_def[RF90_PATH_B].rftx_afe = ROFDM0_XBTXAFE;
  822. rtlphy->phyreg_def[RF90_PATH_A].rf_rb = RFPGA0_XA_LSSIREADBACK;
  823. rtlphy->phyreg_def[RF90_PATH_B].rf_rb = RFPGA0_XB_LSSIREADBACK;
  824. rtlphy->phyreg_def[RF90_PATH_A].rf_rbpi = TRANSCEIVEA_HSPI_READBACK;
  825. rtlphy->phyreg_def[RF90_PATH_B].rf_rbpi = TRANSCEIVEB_HSPI_READBACK;
  826. }
  827. void rtl88e_phy_get_txpower_level(struct ieee80211_hw *hw, long *powerlevel)
  828. {
  829. struct rtl_priv *rtlpriv = rtl_priv(hw);
  830. struct rtl_phy *rtlphy = &rtlpriv->phy;
  831. u8 txpwr_level;
  832. long txpwr_dbm;
  833. txpwr_level = rtlphy->cur_cck_txpwridx;
  834. txpwr_dbm = _rtl88e_phy_txpwr_idx_to_dbm(hw,
  835. WIRELESS_MODE_B, txpwr_level);
  836. txpwr_level = rtlphy->cur_ofdm24g_txpwridx;
  837. if (_rtl88e_phy_txpwr_idx_to_dbm(hw,
  838. WIRELESS_MODE_G,
  839. txpwr_level) > txpwr_dbm)
  840. txpwr_dbm =
  841. _rtl88e_phy_txpwr_idx_to_dbm(hw, WIRELESS_MODE_G,
  842. txpwr_level);
  843. txpwr_level = rtlphy->cur_ofdm24g_txpwridx;
  844. if (_rtl88e_phy_txpwr_idx_to_dbm(hw,
  845. WIRELESS_MODE_N_24G,
  846. txpwr_level) > txpwr_dbm)
  847. txpwr_dbm =
  848. _rtl88e_phy_txpwr_idx_to_dbm(hw, WIRELESS_MODE_N_24G,
  849. txpwr_level);
  850. *powerlevel = txpwr_dbm;
  851. }
  852. static void handle_path_a(struct rtl_efuse *rtlefuse, u8 index,
  853. u8 *cckpowerlevel, u8 *ofdmpowerlevel,
  854. u8 *bw20powerlevel, u8 *bw40powerlevel)
  855. {
  856. cckpowerlevel[RF90_PATH_A] =
  857. rtlefuse->txpwrlevel_cck[RF90_PATH_A][index];
  858. /*-8~7 */
  859. if (rtlefuse->txpwr_ht20diff[RF90_PATH_A][index] > 0x0f)
  860. bw20powerlevel[RF90_PATH_A] =
  861. rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_A][index] -
  862. (~(rtlefuse->txpwr_ht20diff[RF90_PATH_A][index]) + 1);
  863. else
  864. bw20powerlevel[RF90_PATH_A] =
  865. rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_A][index] +
  866. rtlefuse->txpwr_ht20diff[RF90_PATH_A][index];
  867. if (rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][index] > 0xf)
  868. ofdmpowerlevel[RF90_PATH_A] =
  869. rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_A][index] -
  870. (~(rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][index])+1);
  871. else
  872. ofdmpowerlevel[RF90_PATH_A] =
  873. rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_A][index] +
  874. rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][index];
  875. bw40powerlevel[RF90_PATH_A] =
  876. rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_A][index];
  877. }
  878. static void _rtl88e_get_txpower_index(struct ieee80211_hw *hw, u8 channel,
  879. u8 *cckpowerlevel, u8 *ofdmpowerlevel,
  880. u8 *bw20powerlevel, u8 *bw40powerlevel)
  881. {
  882. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  883. u8 index = (channel - 1);
  884. u8 rf_path = 0;
  885. for (rf_path = 0; rf_path < 2; rf_path++) {
  886. if (rf_path == RF90_PATH_A) {
  887. handle_path_a(rtlefuse, index, cckpowerlevel,
  888. ofdmpowerlevel, bw20powerlevel,
  889. bw40powerlevel);
  890. } else if (rf_path == RF90_PATH_B) {
  891. cckpowerlevel[RF90_PATH_B] =
  892. rtlefuse->txpwrlevel_cck[RF90_PATH_B][index];
  893. bw20powerlevel[RF90_PATH_B] =
  894. rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_B][index] +
  895. rtlefuse->txpwr_ht20diff[RF90_PATH_B][index];
  896. ofdmpowerlevel[RF90_PATH_B] =
  897. rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_B][index] +
  898. rtlefuse->txpwr_legacyhtdiff[RF90_PATH_B][index];
  899. bw40powerlevel[RF90_PATH_B] =
  900. rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_B][index];
  901. }
  902. }
  903. }
  904. static void _rtl88e_ccxpower_index_check(struct ieee80211_hw *hw,
  905. u8 channel, u8 *cckpowerlevel,
  906. u8 *ofdmpowerlevel, u8 *bw20powerlevel,
  907. u8 *bw40powerlevel)
  908. {
  909. struct rtl_priv *rtlpriv = rtl_priv(hw);
  910. struct rtl_phy *rtlphy = &rtlpriv->phy;
  911. rtlphy->cur_cck_txpwridx = cckpowerlevel[0];
  912. rtlphy->cur_ofdm24g_txpwridx = ofdmpowerlevel[0];
  913. rtlphy->cur_bw20_txpwridx = bw20powerlevel[0];
  914. rtlphy->cur_bw40_txpwridx = bw40powerlevel[0];
  915. }
  916. void rtl88e_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel)
  917. {
  918. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  919. u8 cckpowerlevel[MAX_TX_COUNT] = {0};
  920. u8 ofdmpowerlevel[MAX_TX_COUNT] = {0};
  921. u8 bw20powerlevel[MAX_TX_COUNT] = {0};
  922. u8 bw40powerlevel[MAX_TX_COUNT] = {0};
  923. if (!rtlefuse->txpwr_fromeprom)
  924. return;
  925. _rtl88e_get_txpower_index(hw, channel,
  926. &cckpowerlevel[0], &ofdmpowerlevel[0],
  927. &bw20powerlevel[0], &bw40powerlevel[0]);
  928. _rtl88e_ccxpower_index_check(hw, channel,
  929. &cckpowerlevel[0], &ofdmpowerlevel[0],
  930. &bw20powerlevel[0], &bw40powerlevel[0]);
  931. rtl88e_phy_rf6052_set_cck_txpower(hw, &cckpowerlevel[0]);
  932. rtl88e_phy_rf6052_set_ofdm_txpower(hw, &ofdmpowerlevel[0],
  933. &bw20powerlevel[0],
  934. &bw40powerlevel[0], channel);
  935. }
  936. static long _rtl88e_phy_txpwr_idx_to_dbm(struct ieee80211_hw *hw,
  937. enum wireless_mode wirelessmode,
  938. u8 txpwridx)
  939. {
  940. long offset;
  941. long pwrout_dbm;
  942. switch (wirelessmode) {
  943. case WIRELESS_MODE_B:
  944. offset = -7;
  945. break;
  946. case WIRELESS_MODE_G:
  947. case WIRELESS_MODE_N_24G:
  948. offset = -8;
  949. break;
  950. default:
  951. offset = -8;
  952. break;
  953. }
  954. pwrout_dbm = txpwridx / 2 + offset;
  955. return pwrout_dbm;
  956. }
  957. void rtl88e_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation)
  958. {
  959. struct rtl_priv *rtlpriv = rtl_priv(hw);
  960. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  961. enum io_type iotype;
  962. if (!is_hal_stop(rtlhal)) {
  963. switch (operation) {
  964. case SCAN_OPT_BACKUP_BAND0:
  965. iotype = IO_CMD_PAUSE_BAND0_DM_BY_SCAN;
  966. rtlpriv->cfg->ops->set_hw_reg(hw,
  967. HW_VAR_IO_CMD,
  968. (u8 *)&iotype);
  969. break;
  970. case SCAN_OPT_RESTORE:
  971. iotype = IO_CMD_RESUME_DM_BY_SCAN;
  972. rtlpriv->cfg->ops->set_hw_reg(hw,
  973. HW_VAR_IO_CMD,
  974. (u8 *)&iotype);
  975. break;
  976. default:
  977. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  978. "Unknown Scan Backup operation.\n");
  979. break;
  980. }
  981. }
  982. }
  983. void rtl88e_phy_set_bw_mode_callback(struct ieee80211_hw *hw)
  984. {
  985. struct rtl_priv *rtlpriv = rtl_priv(hw);
  986. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  987. struct rtl_phy *rtlphy = &rtlpriv->phy;
  988. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  989. u8 reg_bw_opmode;
  990. u8 reg_prsr_rsc;
  991. RT_TRACE(rtlpriv, COMP_SCAN, DBG_TRACE,
  992. "Switch to %s bandwidth\n",
  993. rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20 ?
  994. "20MHz" : "40MHz");
  995. if (is_hal_stop(rtlhal)) {
  996. rtlphy->set_bwmode_inprogress = false;
  997. return;
  998. }
  999. reg_bw_opmode = rtl_read_byte(rtlpriv, REG_BWOPMODE);
  1000. reg_prsr_rsc = rtl_read_byte(rtlpriv, REG_RRSR + 2);
  1001. switch (rtlphy->current_chan_bw) {
  1002. case HT_CHANNEL_WIDTH_20:
  1003. reg_bw_opmode |= BW_OPMODE_20MHZ;
  1004. rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode);
  1005. break;
  1006. case HT_CHANNEL_WIDTH_20_40:
  1007. reg_bw_opmode &= ~BW_OPMODE_20MHZ;
  1008. rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode);
  1009. reg_prsr_rsc =
  1010. (reg_prsr_rsc & 0x90) | (mac->cur_40_prime_sc << 5);
  1011. rtl_write_byte(rtlpriv, REG_RRSR + 2, reg_prsr_rsc);
  1012. break;
  1013. default:
  1014. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1015. "unknown bandwidth: %#X\n", rtlphy->current_chan_bw);
  1016. break;
  1017. }
  1018. switch (rtlphy->current_chan_bw) {
  1019. case HT_CHANNEL_WIDTH_20:
  1020. rtl_set_bbreg(hw, RFPGA0_RFMOD, BRFMOD, 0x0);
  1021. rtl_set_bbreg(hw, RFPGA1_RFMOD, BRFMOD, 0x0);
  1022. /* rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 1);*/
  1023. break;
  1024. case HT_CHANNEL_WIDTH_20_40:
  1025. rtl_set_bbreg(hw, RFPGA0_RFMOD, BRFMOD, 0x1);
  1026. rtl_set_bbreg(hw, RFPGA1_RFMOD, BRFMOD, 0x1);
  1027. rtl_set_bbreg(hw, RCCK0_SYSTEM, BCCK_SIDEBAND,
  1028. (mac->cur_40_prime_sc >> 1));
  1029. rtl_set_bbreg(hw, ROFDM1_LSTF, 0xC00, mac->cur_40_prime_sc);
  1030. /*rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 0);*/
  1031. rtl_set_bbreg(hw, 0x818, (BIT(26) | BIT(27)),
  1032. (mac->cur_40_prime_sc ==
  1033. HAL_PRIME_CHNL_OFFSET_LOWER) ? 2 : 1);
  1034. break;
  1035. default:
  1036. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1037. "unknown bandwidth: %#X\n", rtlphy->current_chan_bw);
  1038. break;
  1039. }
  1040. rtl88e_phy_rf6052_set_bandwidth(hw, rtlphy->current_chan_bw);
  1041. rtlphy->set_bwmode_inprogress = false;
  1042. RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD, "\n");
  1043. }
  1044. void rtl88e_phy_set_bw_mode(struct ieee80211_hw *hw,
  1045. enum nl80211_channel_type ch_type)
  1046. {
  1047. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1048. struct rtl_phy *rtlphy = &rtlpriv->phy;
  1049. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1050. u8 tmp_bw = rtlphy->current_chan_bw;
  1051. if (rtlphy->set_bwmode_inprogress)
  1052. return;
  1053. rtlphy->set_bwmode_inprogress = true;
  1054. if ((!is_hal_stop(rtlhal)) && !(RT_CANNOT_IO(hw))) {
  1055. rtl88e_phy_set_bw_mode_callback(hw);
  1056. } else {
  1057. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  1058. "false driver sleep or unload\n");
  1059. rtlphy->set_bwmode_inprogress = false;
  1060. rtlphy->current_chan_bw = tmp_bw;
  1061. }
  1062. }
  1063. void rtl88e_phy_sw_chnl_callback(struct ieee80211_hw *hw)
  1064. {
  1065. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1066. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1067. struct rtl_phy *rtlphy = &rtlpriv->phy;
  1068. u32 delay;
  1069. RT_TRACE(rtlpriv, COMP_SCAN, DBG_TRACE,
  1070. "switch to channel%d\n", rtlphy->current_channel);
  1071. if (is_hal_stop(rtlhal))
  1072. return;
  1073. do {
  1074. if (!rtlphy->sw_chnl_inprogress)
  1075. break;
  1076. if (!_rtl88e_phy_sw_chnl_step_by_step
  1077. (hw, rtlphy->current_channel, &rtlphy->sw_chnl_stage,
  1078. &rtlphy->sw_chnl_step, &delay)) {
  1079. if (delay > 0)
  1080. mdelay(delay);
  1081. else
  1082. continue;
  1083. } else {
  1084. rtlphy->sw_chnl_inprogress = false;
  1085. }
  1086. break;
  1087. } while (true);
  1088. RT_TRACE(rtlpriv, COMP_SCAN, DBG_TRACE, "\n");
  1089. }
  1090. u8 rtl88e_phy_sw_chnl(struct ieee80211_hw *hw)
  1091. {
  1092. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1093. struct rtl_phy *rtlphy = &rtlpriv->phy;
  1094. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1095. if (rtlphy->sw_chnl_inprogress)
  1096. return 0;
  1097. if (rtlphy->set_bwmode_inprogress)
  1098. return 0;
  1099. RT_ASSERT((rtlphy->current_channel <= 14),
  1100. "WIRELESS_MODE_G but channel>14");
  1101. rtlphy->sw_chnl_inprogress = true;
  1102. rtlphy->sw_chnl_stage = 0;
  1103. rtlphy->sw_chnl_step = 0;
  1104. if (!(is_hal_stop(rtlhal)) && !(RT_CANNOT_IO(hw))) {
  1105. rtl88e_phy_sw_chnl_callback(hw);
  1106. RT_TRACE(rtlpriv, COMP_CHAN, DBG_LOUD,
  1107. "sw_chnl_inprogress false schdule workitem current channel %d\n",
  1108. rtlphy->current_channel);
  1109. rtlphy->sw_chnl_inprogress = false;
  1110. } else {
  1111. RT_TRACE(rtlpriv, COMP_CHAN, DBG_LOUD,
  1112. "sw_chnl_inprogress false driver sleep or unload\n");
  1113. rtlphy->sw_chnl_inprogress = false;
  1114. }
  1115. return 1;
  1116. }
  1117. static bool _rtl88e_phy_sw_chnl_step_by_step(struct ieee80211_hw *hw,
  1118. u8 channel, u8 *stage, u8 *step,
  1119. u32 *delay)
  1120. {
  1121. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1122. struct rtl_phy *rtlphy = &rtlpriv->phy;
  1123. struct swchnlcmd precommoncmd[MAX_PRECMD_CNT];
  1124. u32 precommoncmdcnt;
  1125. struct swchnlcmd postcommoncmd[MAX_POSTCMD_CNT];
  1126. u32 postcommoncmdcnt;
  1127. struct swchnlcmd rfdependcmd[MAX_RFDEPENDCMD_CNT];
  1128. u32 rfdependcmdcnt;
  1129. struct swchnlcmd *currentcmd = NULL;
  1130. u8 rfpath;
  1131. u8 num_total_rfpath = rtlphy->num_total_rfpath;
  1132. precommoncmdcnt = 0;
  1133. _rtl88e_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++,
  1134. MAX_PRECMD_CNT,
  1135. CMDID_SET_TXPOWEROWER_LEVEL, 0, 0, 0);
  1136. _rtl88e_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++,
  1137. MAX_PRECMD_CNT, CMDID_END, 0, 0, 0);
  1138. postcommoncmdcnt = 0;
  1139. _rtl88e_phy_set_sw_chnl_cmdarray(postcommoncmd, postcommoncmdcnt++,
  1140. MAX_POSTCMD_CNT, CMDID_END, 0, 0, 0);
  1141. rfdependcmdcnt = 0;
  1142. RT_ASSERT((channel >= 1 && channel <= 14),
  1143. "illegal channel for Zebra: %d\n", channel);
  1144. _rtl88e_phy_set_sw_chnl_cmdarray(rfdependcmd, rfdependcmdcnt++,
  1145. MAX_RFDEPENDCMD_CNT, CMDID_RF_WRITEREG,
  1146. RF_CHNLBW, channel, 10);
  1147. _rtl88e_phy_set_sw_chnl_cmdarray(rfdependcmd, rfdependcmdcnt++,
  1148. MAX_RFDEPENDCMD_CNT, CMDID_END, 0, 0,
  1149. 0);
  1150. do {
  1151. switch (*stage) {
  1152. case 0:
  1153. currentcmd = &precommoncmd[*step];
  1154. break;
  1155. case 1:
  1156. currentcmd = &rfdependcmd[*step];
  1157. break;
  1158. case 2:
  1159. currentcmd = &postcommoncmd[*step];
  1160. break;
  1161. default:
  1162. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1163. "Invalid 'stage' = %d, Check it!\n", *stage);
  1164. return true;
  1165. }
  1166. if (currentcmd->cmdid == CMDID_END) {
  1167. if ((*stage) == 2)
  1168. return true;
  1169. (*stage)++;
  1170. (*step) = 0;
  1171. continue;
  1172. }
  1173. switch (currentcmd->cmdid) {
  1174. case CMDID_SET_TXPOWEROWER_LEVEL:
  1175. rtl88e_phy_set_txpower_level(hw, channel);
  1176. break;
  1177. case CMDID_WRITEPORT_ULONG:
  1178. rtl_write_dword(rtlpriv, currentcmd->para1,
  1179. currentcmd->para2);
  1180. break;
  1181. case CMDID_WRITEPORT_USHORT:
  1182. rtl_write_word(rtlpriv, currentcmd->para1,
  1183. (u16)currentcmd->para2);
  1184. break;
  1185. case CMDID_WRITEPORT_UCHAR:
  1186. rtl_write_byte(rtlpriv, currentcmd->para1,
  1187. (u8)currentcmd->para2);
  1188. break;
  1189. case CMDID_RF_WRITEREG:
  1190. for (rfpath = 0; rfpath < num_total_rfpath; rfpath++) {
  1191. rtlphy->rfreg_chnlval[rfpath] =
  1192. ((rtlphy->rfreg_chnlval[rfpath] &
  1193. 0xfffffc00) | currentcmd->para2);
  1194. rtl_set_rfreg(hw, (enum radio_path)rfpath,
  1195. currentcmd->para1,
  1196. RFREG_OFFSET_MASK,
  1197. rtlphy->rfreg_chnlval[rfpath]);
  1198. }
  1199. break;
  1200. default:
  1201. RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
  1202. "switch case not process\n");
  1203. break;
  1204. }
  1205. break;
  1206. } while (true);
  1207. (*delay) = currentcmd->msdelay;
  1208. (*step)++;
  1209. return false;
  1210. }
  1211. static bool _rtl88e_phy_set_sw_chnl_cmdarray(struct swchnlcmd *cmdtable,
  1212. u32 cmdtableidx, u32 cmdtablesz,
  1213. enum swchnlcmd_id cmdid,
  1214. u32 para1, u32 para2, u32 msdelay)
  1215. {
  1216. struct swchnlcmd *pcmd;
  1217. if (cmdtable == NULL) {
  1218. RT_ASSERT(false, "cmdtable cannot be NULL.\n");
  1219. return false;
  1220. }
  1221. if (cmdtableidx >= cmdtablesz)
  1222. return false;
  1223. pcmd = cmdtable + cmdtableidx;
  1224. pcmd->cmdid = cmdid;
  1225. pcmd->para1 = para1;
  1226. pcmd->para2 = para2;
  1227. pcmd->msdelay = msdelay;
  1228. return true;
  1229. }
  1230. static u8 _rtl88e_phy_path_a_iqk(struct ieee80211_hw *hw, bool config_pathb)
  1231. {
  1232. u32 reg_eac, reg_e94, reg_e9c, reg_ea4;
  1233. u8 result = 0x00;
  1234. rtl_set_bbreg(hw, 0xe30, MASKDWORD, 0x10008c1c);
  1235. rtl_set_bbreg(hw, 0xe34, MASKDWORD, 0x30008c1c);
  1236. rtl_set_bbreg(hw, 0xe38, MASKDWORD, 0x8214032a);
  1237. rtl_set_bbreg(hw, 0xe3c, MASKDWORD, 0x28160000);
  1238. rtl_set_bbreg(hw, 0xe4c, MASKDWORD, 0x00462911);
  1239. rtl_set_bbreg(hw, 0xe48, MASKDWORD, 0xf9000000);
  1240. rtl_set_bbreg(hw, 0xe48, MASKDWORD, 0xf8000000);
  1241. mdelay(IQK_DELAY_TIME);
  1242. reg_eac = rtl_get_bbreg(hw, 0xeac, MASKDWORD);
  1243. reg_e94 = rtl_get_bbreg(hw, 0xe94, MASKDWORD);
  1244. reg_e9c = rtl_get_bbreg(hw, 0xe9c, MASKDWORD);
  1245. reg_ea4 = rtl_get_bbreg(hw, 0xea4, MASKDWORD);
  1246. if (!(reg_eac & BIT(28)) &&
  1247. (((reg_e94 & 0x03FF0000) >> 16) != 0x142) &&
  1248. (((reg_e9c & 0x03FF0000) >> 16) != 0x42))
  1249. result |= 0x01;
  1250. return result;
  1251. }
  1252. static u8 _rtl88e_phy_path_b_iqk(struct ieee80211_hw *hw)
  1253. {
  1254. u32 reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc;
  1255. u8 result = 0x00;
  1256. rtl_set_bbreg(hw, 0xe60, MASKDWORD, 0x00000002);
  1257. rtl_set_bbreg(hw, 0xe60, MASKDWORD, 0x00000000);
  1258. mdelay(IQK_DELAY_TIME);
  1259. reg_eac = rtl_get_bbreg(hw, 0xeac, MASKDWORD);
  1260. reg_eb4 = rtl_get_bbreg(hw, 0xeb4, MASKDWORD);
  1261. reg_ebc = rtl_get_bbreg(hw, 0xebc, MASKDWORD);
  1262. reg_ec4 = rtl_get_bbreg(hw, 0xec4, MASKDWORD);
  1263. reg_ecc = rtl_get_bbreg(hw, 0xecc, MASKDWORD);
  1264. if (!(reg_eac & BIT(31)) &&
  1265. (((reg_eb4 & 0x03FF0000) >> 16) != 0x142) &&
  1266. (((reg_ebc & 0x03FF0000) >> 16) != 0x42))
  1267. result |= 0x01;
  1268. else
  1269. return result;
  1270. if (!(reg_eac & BIT(30)) &&
  1271. (((reg_ec4 & 0x03FF0000) >> 16) != 0x132) &&
  1272. (((reg_ecc & 0x03FF0000) >> 16) != 0x36))
  1273. result |= 0x02;
  1274. return result;
  1275. }
  1276. static u8 _rtl88e_phy_path_a_rx_iqk(struct ieee80211_hw *hw, bool config_pathb)
  1277. {
  1278. u32 reg_eac, reg_e94, reg_e9c, reg_ea4, u32temp;
  1279. u8 result = 0x00;
  1280. /*Get TXIMR Setting*/
  1281. /*Modify RX IQK mode table*/
  1282. rtl_set_bbreg(hw, RFPGA0_IQK, MASKDWORD, 0x00000000);
  1283. rtl_set_rfreg(hw, RF90_PATH_A, RF_WE_LUT, RFREG_OFFSET_MASK, 0x800a0);
  1284. rtl_set_rfreg(hw, RF90_PATH_A, RF_RCK_OS, RFREG_OFFSET_MASK, 0x30000);
  1285. rtl_set_rfreg(hw, RF90_PATH_A, RF_TXPA_G1, RFREG_OFFSET_MASK, 0x0000f);
  1286. rtl_set_rfreg(hw, RF90_PATH_A, RF_TXPA_G2, RFREG_OFFSET_MASK, 0xf117b);
  1287. rtl_set_bbreg(hw, RFPGA0_IQK, MASKDWORD, 0x80800000);
  1288. /*IQK Setting*/
  1289. rtl_set_bbreg(hw, RTX_IQK, MASKDWORD, 0x01007c00);
  1290. rtl_set_bbreg(hw, RRX_IQK, MASKDWORD, 0x81004800);
  1291. /*path a IQK setting*/
  1292. rtl_set_bbreg(hw, RTX_IQK_TONE_A, MASKDWORD, 0x10008c1c);
  1293. rtl_set_bbreg(hw, RRX_IQK_TONE_A, MASKDWORD, 0x30008c1c);
  1294. rtl_set_bbreg(hw, RTX_IQK_PI_A, MASKDWORD, 0x82160804);
  1295. rtl_set_bbreg(hw, RRX_IQK_PI_A, MASKDWORD, 0x28160000);
  1296. /*LO calibration Setting*/
  1297. rtl_set_bbreg(hw, RIQK_AGC_RSP, MASKDWORD, 0x0046a911);
  1298. /*one shot,path A LOK & iqk*/
  1299. rtl_set_bbreg(hw, RIQK_AGC_PTS, MASKDWORD, 0xf9000000);
  1300. rtl_set_bbreg(hw, RIQK_AGC_PTS, MASKDWORD, 0xf8000000);
  1301. mdelay(IQK_DELAY_TIME);
  1302. reg_eac = rtl_get_bbreg(hw, RRX_POWER_AFTER_IQK_A_2, MASKDWORD);
  1303. reg_e94 = rtl_get_bbreg(hw, RTX_POWER_BEFORE_IQK_A, MASKDWORD);
  1304. reg_e9c = rtl_get_bbreg(hw, RTX_POWER_AFTER_IQK_A, MASKDWORD);
  1305. if (!(reg_eac & BIT(28)) &&
  1306. (((reg_e94 & 0x03FF0000) >> 16) != 0x142) &&
  1307. (((reg_e9c & 0x03FF0000) >> 16) != 0x42))
  1308. result |= 0x01;
  1309. else
  1310. return result;
  1311. u32temp = 0x80007C00 | (reg_e94&0x3FF0000) |
  1312. ((reg_e9c&0x3FF0000) >> 16);
  1313. rtl_set_bbreg(hw, RTX_IQK, MASKDWORD, u32temp);
  1314. /*RX IQK*/
  1315. /*Modify RX IQK mode table*/
  1316. rtl_set_bbreg(hw, RFPGA0_IQK, MASKDWORD, 0x00000000);
  1317. rtl_set_rfreg(hw, RF90_PATH_A, RF_WE_LUT, RFREG_OFFSET_MASK, 0x800a0);
  1318. rtl_set_rfreg(hw, RF90_PATH_A, RF_RCK_OS, RFREG_OFFSET_MASK, 0x30000);
  1319. rtl_set_rfreg(hw, RF90_PATH_A, RF_TXPA_G1, RFREG_OFFSET_MASK, 0x0000f);
  1320. rtl_set_rfreg(hw, RF90_PATH_A, RF_TXPA_G2, RFREG_OFFSET_MASK, 0xf7ffa);
  1321. rtl_set_bbreg(hw, RFPGA0_IQK, MASKDWORD, 0x80800000);
  1322. /*IQK Setting*/
  1323. rtl_set_bbreg(hw, RRX_IQK, MASKDWORD, 0x01004800);
  1324. /*path a IQK setting*/
  1325. rtl_set_bbreg(hw, RTX_IQK_TONE_A, MASKDWORD, 0x30008c1c);
  1326. rtl_set_bbreg(hw, RRX_IQK_TONE_A, MASKDWORD, 0x10008c1c);
  1327. rtl_set_bbreg(hw, RTX_IQK_PI_A, MASKDWORD, 0x82160c05);
  1328. rtl_set_bbreg(hw, RRX_IQK_PI_A, MASKDWORD, 0x28160c05);
  1329. /*LO calibration Setting*/
  1330. rtl_set_bbreg(hw, RIQK_AGC_RSP, MASKDWORD, 0x0046a911);
  1331. /*one shot,path A LOK & iqk*/
  1332. rtl_set_bbreg(hw, RIQK_AGC_PTS, MASKDWORD, 0xf9000000);
  1333. rtl_set_bbreg(hw, RIQK_AGC_PTS, MASKDWORD, 0xf8000000);
  1334. mdelay(IQK_DELAY_TIME);
  1335. reg_eac = rtl_get_bbreg(hw, RRX_POWER_AFTER_IQK_A_2, MASKDWORD);
  1336. reg_e94 = rtl_get_bbreg(hw, RTX_POWER_BEFORE_IQK_A, MASKDWORD);
  1337. reg_e9c = rtl_get_bbreg(hw, RTX_POWER_AFTER_IQK_A, MASKDWORD);
  1338. reg_ea4 = rtl_get_bbreg(hw, RRX_POWER_BEFORE_IQK_A_2, MASKDWORD);
  1339. if (!(reg_eac & BIT(27)) &&
  1340. (((reg_ea4 & 0x03FF0000) >> 16) != 0x132) &&
  1341. (((reg_eac & 0x03FF0000) >> 16) != 0x36))
  1342. result |= 0x02;
  1343. return result;
  1344. }
  1345. static void _rtl88e_phy_path_a_fill_iqk_matrix(struct ieee80211_hw *hw,
  1346. bool iqk_ok, long result[][8],
  1347. u8 final_candidate, bool btxonly)
  1348. {
  1349. u32 oldval_0, x, tx0_a, reg;
  1350. long y, tx0_c;
  1351. if (final_candidate == 0xFF) {
  1352. return;
  1353. } else if (iqk_ok) {
  1354. oldval_0 = (rtl_get_bbreg(hw, ROFDM0_XATXIQIMBALANCE,
  1355. MASKDWORD) >> 22) & 0x3FF;
  1356. x = result[final_candidate][0];
  1357. if ((x & 0x00000200) != 0)
  1358. x = x | 0xFFFFFC00;
  1359. tx0_a = (x * oldval_0) >> 8;
  1360. rtl_set_bbreg(hw, ROFDM0_XATXIQIMBALANCE, 0x3FF, tx0_a);
  1361. rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(31),
  1362. ((x * oldval_0 >> 7) & 0x1));
  1363. y = result[final_candidate][1];
  1364. if ((y & 0x00000200) != 0)
  1365. y = y | 0xFFFFFC00;
  1366. tx0_c = (y * oldval_0) >> 8;
  1367. rtl_set_bbreg(hw, ROFDM0_XCTXAFE, 0xF0000000,
  1368. ((tx0_c & 0x3C0) >> 6));
  1369. rtl_set_bbreg(hw, ROFDM0_XATXIQIMBALANCE, 0x003F0000,
  1370. (tx0_c & 0x3F));
  1371. rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(29),
  1372. ((y * oldval_0 >> 7) & 0x1));
  1373. if (btxonly)
  1374. return;
  1375. reg = result[final_candidate][2];
  1376. rtl_set_bbreg(hw, ROFDM0_XARXIQIMBALANCE, 0x3FF, reg);
  1377. reg = result[final_candidate][3] & 0x3F;
  1378. rtl_set_bbreg(hw, ROFDM0_XARXIQIMBALANCE, 0xFC00, reg);
  1379. reg = (result[final_candidate][3] >> 6) & 0xF;
  1380. rtl_set_bbreg(hw, 0xca0, 0xF0000000, reg);
  1381. }
  1382. }
  1383. static void _rtl88e_phy_save_adda_registers(struct ieee80211_hw *hw,
  1384. u32 *addareg, u32 *addabackup,
  1385. u32 registernum)
  1386. {
  1387. u32 i;
  1388. for (i = 0; i < registernum; i++)
  1389. addabackup[i] = rtl_get_bbreg(hw, addareg[i], MASKDWORD);
  1390. }
  1391. static void _rtl88e_phy_save_mac_registers(struct ieee80211_hw *hw,
  1392. u32 *macreg, u32 *macbackup)
  1393. {
  1394. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1395. u32 i;
  1396. for (i = 0; i < (IQK_MAC_REG_NUM - 1); i++)
  1397. macbackup[i] = rtl_read_byte(rtlpriv, macreg[i]);
  1398. macbackup[i] = rtl_read_dword(rtlpriv, macreg[i]);
  1399. }
  1400. static void _rtl88e_phy_reload_adda_registers(struct ieee80211_hw *hw,
  1401. u32 *addareg, u32 *addabackup,
  1402. u32 regiesternum)
  1403. {
  1404. u32 i;
  1405. for (i = 0; i < regiesternum; i++)
  1406. rtl_set_bbreg(hw, addareg[i], MASKDWORD, addabackup[i]);
  1407. }
  1408. static void _rtl88e_phy_reload_mac_registers(struct ieee80211_hw *hw,
  1409. u32 *macreg, u32 *macbackup)
  1410. {
  1411. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1412. u32 i;
  1413. for (i = 0; i < (IQK_MAC_REG_NUM - 1); i++)
  1414. rtl_write_byte(rtlpriv, macreg[i], (u8) macbackup[i]);
  1415. rtl_write_dword(rtlpriv, macreg[i], macbackup[i]);
  1416. }
  1417. static void _rtl88e_phy_path_adda_on(struct ieee80211_hw *hw,
  1418. u32 *addareg, bool is_patha_on, bool is2t)
  1419. {
  1420. u32 pathon;
  1421. u32 i;
  1422. pathon = is_patha_on ? 0x04db25a4 : 0x0b1b25a4;
  1423. if (false == is2t) {
  1424. pathon = 0x0bdb25a0;
  1425. rtl_set_bbreg(hw, addareg[0], MASKDWORD, 0x0b1b25a0);
  1426. } else {
  1427. rtl_set_bbreg(hw, addareg[0], MASKDWORD, pathon);
  1428. }
  1429. for (i = 1; i < IQK_ADDA_REG_NUM; i++)
  1430. rtl_set_bbreg(hw, addareg[i], MASKDWORD, pathon);
  1431. }
  1432. static void _rtl88e_phy_mac_setting_calibration(struct ieee80211_hw *hw,
  1433. u32 *macreg, u32 *macbackup)
  1434. {
  1435. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1436. u32 i = 0;
  1437. rtl_write_byte(rtlpriv, macreg[i], 0x3F);
  1438. for (i = 1; i < (IQK_MAC_REG_NUM - 1); i++)
  1439. rtl_write_byte(rtlpriv, macreg[i],
  1440. (u8) (macbackup[i] & (~BIT(3))));
  1441. rtl_write_byte(rtlpriv, macreg[i], (u8) (macbackup[i] & (~BIT(5))));
  1442. }
  1443. static void _rtl88e_phy_path_a_standby(struct ieee80211_hw *hw)
  1444. {
  1445. rtl_set_bbreg(hw, 0xe28, MASKDWORD, 0x0);
  1446. rtl_set_bbreg(hw, 0x840, MASKDWORD, 0x00010000);
  1447. rtl_set_bbreg(hw, 0xe28, MASKDWORD, 0x80800000);
  1448. }
  1449. static void _rtl88e_phy_pi_mode_switch(struct ieee80211_hw *hw, bool pi_mode)
  1450. {
  1451. u32 mode;
  1452. mode = pi_mode ? 0x01000100 : 0x01000000;
  1453. rtl_set_bbreg(hw, 0x820, MASKDWORD, mode);
  1454. rtl_set_bbreg(hw, 0x828, MASKDWORD, mode);
  1455. }
  1456. static bool _rtl88e_phy_simularity_compare(struct ieee80211_hw *hw,
  1457. long result[][8], u8 c1, u8 c2)
  1458. {
  1459. u32 i, j, diff, simularity_bitmap, bound;
  1460. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1461. u8 final_candidate[2] = { 0xFF, 0xFF };
  1462. bool bresult = true, is2t = IS_92C_SERIAL(rtlhal->version);
  1463. if (is2t)
  1464. bound = 8;
  1465. else
  1466. bound = 4;
  1467. simularity_bitmap = 0;
  1468. for (i = 0; i < bound; i++) {
  1469. diff = (result[c1][i] > result[c2][i]) ?
  1470. (result[c1][i] - result[c2][i]) :
  1471. (result[c2][i] - result[c1][i]);
  1472. if (diff > MAX_TOLERANCE) {
  1473. if ((i == 2 || i == 6) && !simularity_bitmap) {
  1474. if (result[c1][i] + result[c1][i + 1] == 0)
  1475. final_candidate[(i / 4)] = c2;
  1476. else if (result[c2][i] + result[c2][i + 1] == 0)
  1477. final_candidate[(i / 4)] = c1;
  1478. else
  1479. simularity_bitmap = simularity_bitmap |
  1480. (1 << i);
  1481. } else
  1482. simularity_bitmap =
  1483. simularity_bitmap | (1 << i);
  1484. }
  1485. }
  1486. if (simularity_bitmap == 0) {
  1487. for (i = 0; i < (bound / 4); i++) {
  1488. if (final_candidate[i] != 0xFF) {
  1489. for (j = i * 4; j < (i + 1) * 4 - 2; j++)
  1490. result[3][j] =
  1491. result[final_candidate[i]][j];
  1492. bresult = false;
  1493. }
  1494. }
  1495. return bresult;
  1496. } else if (!(simularity_bitmap & 0x0F)) {
  1497. for (i = 0; i < 4; i++)
  1498. result[3][i] = result[c1][i];
  1499. return false;
  1500. } else if (!(simularity_bitmap & 0xF0) && is2t) {
  1501. for (i = 4; i < 8; i++)
  1502. result[3][i] = result[c1][i];
  1503. return false;
  1504. } else {
  1505. return false;
  1506. }
  1507. }
  1508. static void _rtl88e_phy_iq_calibrate(struct ieee80211_hw *hw,
  1509. long result[][8], u8 t, bool is2t)
  1510. {
  1511. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1512. struct rtl_phy *rtlphy = &rtlpriv->phy;
  1513. u32 i;
  1514. u8 patha_ok, pathb_ok;
  1515. u32 adda_reg[IQK_ADDA_REG_NUM] = {
  1516. 0x85c, 0xe6c, 0xe70, 0xe74,
  1517. 0xe78, 0xe7c, 0xe80, 0xe84,
  1518. 0xe88, 0xe8c, 0xed0, 0xed4,
  1519. 0xed8, 0xedc, 0xee0, 0xeec
  1520. };
  1521. u32 iqk_mac_reg[IQK_MAC_REG_NUM] = {
  1522. 0x522, 0x550, 0x551, 0x040
  1523. };
  1524. u32 iqk_bb_reg[IQK_BB_REG_NUM] = {
  1525. ROFDM0_TRXPATHENABLE, ROFDM0_TRMUXPAR,
  1526. RFPGA0_XCD_RFINTERFACESW, 0xb68, 0xb6c,
  1527. 0x870, 0x860, 0x864, 0x800
  1528. };
  1529. const u32 retrycount = 2;
  1530. if (t == 0) {
  1531. _rtl88e_phy_save_adda_registers(hw, adda_reg,
  1532. rtlphy->adda_backup, 16);
  1533. _rtl88e_phy_save_mac_registers(hw, iqk_mac_reg,
  1534. rtlphy->iqk_mac_backup);
  1535. _rtl88e_phy_save_adda_registers(hw, iqk_bb_reg,
  1536. rtlphy->iqk_bb_backup,
  1537. IQK_BB_REG_NUM);
  1538. }
  1539. _rtl88e_phy_path_adda_on(hw, adda_reg, true, is2t);
  1540. if (t == 0) {
  1541. rtlphy->rfpi_enable =
  1542. (u8)rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER1, BIT(8));
  1543. }
  1544. if (!rtlphy->rfpi_enable)
  1545. _rtl88e_phy_pi_mode_switch(hw, true);
  1546. /*BB Setting*/
  1547. rtl_set_bbreg(hw, 0x800, BIT(24), 0x00);
  1548. rtl_set_bbreg(hw, 0xc04, MASKDWORD, 0x03a05600);
  1549. rtl_set_bbreg(hw, 0xc08, MASKDWORD, 0x000800e4);
  1550. rtl_set_bbreg(hw, 0x874, MASKDWORD, 0x22204000);
  1551. rtl_set_bbreg(hw, 0x870, BIT(10), 0x01);
  1552. rtl_set_bbreg(hw, 0x870, BIT(26), 0x01);
  1553. rtl_set_bbreg(hw, 0x860, BIT(10), 0x00);
  1554. rtl_set_bbreg(hw, 0x864, BIT(10), 0x00);
  1555. if (is2t) {
  1556. rtl_set_bbreg(hw, 0x840, MASKDWORD, 0x00010000);
  1557. rtl_set_bbreg(hw, 0x844, MASKDWORD, 0x00010000);
  1558. }
  1559. _rtl88e_phy_mac_setting_calibration(hw, iqk_mac_reg,
  1560. rtlphy->iqk_mac_backup);
  1561. rtl_set_bbreg(hw, 0xb68, MASKDWORD, 0x0f600000);
  1562. if (is2t)
  1563. rtl_set_bbreg(hw, 0xb6c, MASKDWORD, 0x0f600000);
  1564. rtl_set_bbreg(hw, 0xe28, MASKDWORD, 0x80800000);
  1565. rtl_set_bbreg(hw, 0xe40, MASKDWORD, 0x01007c00);
  1566. rtl_set_bbreg(hw, 0xe44, MASKDWORD, 0x81004800);
  1567. for (i = 0; i < retrycount; i++) {
  1568. patha_ok = _rtl88e_phy_path_a_iqk(hw, is2t);
  1569. if (patha_ok == 0x01) {
  1570. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1571. "Path A Tx IQK Success!!\n");
  1572. result[t][0] = (rtl_get_bbreg(hw, 0xe94, MASKDWORD) &
  1573. 0x3FF0000) >> 16;
  1574. result[t][1] = (rtl_get_bbreg(hw, 0xe9c, MASKDWORD) &
  1575. 0x3FF0000) >> 16;
  1576. break;
  1577. }
  1578. }
  1579. for (i = 0; i < retrycount; i++) {
  1580. patha_ok = _rtl88e_phy_path_a_rx_iqk(hw, is2t);
  1581. if (patha_ok == 0x03) {
  1582. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1583. "Path A Rx IQK Success!!\n");
  1584. result[t][2] = (rtl_get_bbreg(hw, 0xea4, MASKDWORD) &
  1585. 0x3FF0000) >> 16;
  1586. result[t][3] = (rtl_get_bbreg(hw, 0xeac, MASKDWORD) &
  1587. 0x3FF0000) >> 16;
  1588. break;
  1589. } else {
  1590. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1591. "Path a RX iqk fail!!!\n");
  1592. }
  1593. }
  1594. if (0 == patha_ok)
  1595. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1596. "Path A IQK Success!!\n");
  1597. if (is2t) {
  1598. _rtl88e_phy_path_a_standby(hw);
  1599. _rtl88e_phy_path_adda_on(hw, adda_reg, false, is2t);
  1600. for (i = 0; i < retrycount; i++) {
  1601. pathb_ok = _rtl88e_phy_path_b_iqk(hw);
  1602. if (pathb_ok == 0x03) {
  1603. result[t][4] = (rtl_get_bbreg(hw,
  1604. 0xeb4,
  1605. MASKDWORD) &
  1606. 0x3FF0000) >> 16;
  1607. result[t][5] =
  1608. (rtl_get_bbreg(hw, 0xebc, MASKDWORD) &
  1609. 0x3FF0000) >> 16;
  1610. result[t][6] =
  1611. (rtl_get_bbreg(hw, 0xec4, MASKDWORD) &
  1612. 0x3FF0000) >> 16;
  1613. result[t][7] =
  1614. (rtl_get_bbreg(hw, 0xecc, MASKDWORD) &
  1615. 0x3FF0000) >> 16;
  1616. break;
  1617. } else if (i == (retrycount - 1) && pathb_ok == 0x01) {
  1618. result[t][4] = (rtl_get_bbreg(hw,
  1619. 0xeb4,
  1620. MASKDWORD) &
  1621. 0x3FF0000) >> 16;
  1622. }
  1623. result[t][5] = (rtl_get_bbreg(hw, 0xebc, MASKDWORD) &
  1624. 0x3FF0000) >> 16;
  1625. }
  1626. }
  1627. rtl_set_bbreg(hw, 0xe28, MASKDWORD, 0);
  1628. if (t != 0) {
  1629. if (!rtlphy->rfpi_enable)
  1630. _rtl88e_phy_pi_mode_switch(hw, false);
  1631. _rtl88e_phy_reload_adda_registers(hw, adda_reg,
  1632. rtlphy->adda_backup, 16);
  1633. _rtl88e_phy_reload_mac_registers(hw, iqk_mac_reg,
  1634. rtlphy->iqk_mac_backup);
  1635. _rtl88e_phy_reload_adda_registers(hw, iqk_bb_reg,
  1636. rtlphy->iqk_bb_backup,
  1637. IQK_BB_REG_NUM);
  1638. rtl_set_bbreg(hw, 0x840, MASKDWORD, 0x00032ed3);
  1639. if (is2t)
  1640. rtl_set_bbreg(hw, 0x844, MASKDWORD, 0x00032ed3);
  1641. rtl_set_bbreg(hw, 0xe30, MASKDWORD, 0x01008c00);
  1642. rtl_set_bbreg(hw, 0xe34, MASKDWORD, 0x01008c00);
  1643. }
  1644. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "88ee IQK Finish!!\n");
  1645. }
  1646. static void _rtl88e_phy_lc_calibrate(struct ieee80211_hw *hw, bool is2t)
  1647. {
  1648. u8 tmpreg;
  1649. u32 rf_a_mode = 0, rf_b_mode = 0, lc_cal;
  1650. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1651. tmpreg = rtl_read_byte(rtlpriv, 0xd03);
  1652. if ((tmpreg & 0x70) != 0)
  1653. rtl_write_byte(rtlpriv, 0xd03, tmpreg & 0x8F);
  1654. else
  1655. rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF);
  1656. if ((tmpreg & 0x70) != 0) {
  1657. rf_a_mode = rtl_get_rfreg(hw, RF90_PATH_A, 0x00, MASK12BITS);
  1658. if (is2t)
  1659. rf_b_mode = rtl_get_rfreg(hw, RF90_PATH_B, 0x00,
  1660. MASK12BITS);
  1661. rtl_set_rfreg(hw, RF90_PATH_A, 0x00, MASK12BITS,
  1662. (rf_a_mode & 0x8FFFF) | 0x10000);
  1663. if (is2t)
  1664. rtl_set_rfreg(hw, RF90_PATH_B, 0x00, MASK12BITS,
  1665. (rf_b_mode & 0x8FFFF) | 0x10000);
  1666. }
  1667. lc_cal = rtl_get_rfreg(hw, RF90_PATH_A, 0x18, MASK12BITS);
  1668. rtl_set_rfreg(hw, RF90_PATH_A, 0x18, MASK12BITS, lc_cal | 0x08000);
  1669. mdelay(100);
  1670. if ((tmpreg & 0x70) != 0) {
  1671. rtl_write_byte(rtlpriv, 0xd03, tmpreg);
  1672. rtl_set_rfreg(hw, RF90_PATH_A, 0x00, MASK12BITS, rf_a_mode);
  1673. if (is2t)
  1674. rtl_set_rfreg(hw, RF90_PATH_B, 0x00, MASK12BITS,
  1675. rf_b_mode);
  1676. } else {
  1677. rtl_write_byte(rtlpriv, REG_TXPAUSE, 0x00);
  1678. }
  1679. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "\n");
  1680. }
  1681. static void _rtl88e_phy_set_rfpath_switch(struct ieee80211_hw *hw,
  1682. bool bmain, bool is2t)
  1683. {
  1684. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1685. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1686. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1687. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "\n");
  1688. if (is_hal_stop(rtlhal)) {
  1689. u8 u1btmp;
  1690. u1btmp = rtl_read_byte(rtlpriv, REG_LEDCFG0);
  1691. rtl_write_byte(rtlpriv, REG_LEDCFG0, u1btmp | BIT(7));
  1692. rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, BIT(13), 0x01);
  1693. }
  1694. if (is2t) {
  1695. if (bmain)
  1696. rtl_set_bbreg(hw, RFPGA0_XB_RFINTERFACEOE,
  1697. BIT(5) | BIT(6), 0x1);
  1698. else
  1699. rtl_set_bbreg(hw, RFPGA0_XB_RFINTERFACEOE,
  1700. BIT(5) | BIT(6), 0x2);
  1701. } else {
  1702. rtl_set_bbreg(hw, RFPGA0_XAB_RFINTERFACESW, BIT(8) | BIT(9), 0);
  1703. rtl_set_bbreg(hw, 0x914, MASKLWORD, 0x0201);
  1704. /* We use the RF definition of MAIN and AUX,
  1705. * left antenna and right antenna repectively.
  1706. * Default output at AUX.
  1707. */
  1708. if (bmain) {
  1709. rtl_set_bbreg(hw, RFPGA0_XA_RFINTERFACEOE,
  1710. BIT(14) | BIT(13) | BIT(12), 0);
  1711. rtl_set_bbreg(hw, RFPGA0_XB_RFINTERFACEOE,
  1712. BIT(5) | BIT(4) | BIT(3), 0);
  1713. if (rtlefuse->antenna_div_type == CGCS_RX_HW_ANTDIV)
  1714. rtl_set_bbreg(hw, RCONFIG_RAM64x16, BIT(31), 0);
  1715. } else {
  1716. rtl_set_bbreg(hw, RFPGA0_XA_RFINTERFACEOE,
  1717. BIT(14) | BIT(13) | BIT(12), 1);
  1718. rtl_set_bbreg(hw, RFPGA0_XB_RFINTERFACEOE,
  1719. BIT(5) | BIT(4) | BIT(3), 1);
  1720. if (rtlefuse->antenna_div_type == CGCS_RX_HW_ANTDIV)
  1721. rtl_set_bbreg(hw, RCONFIG_RAM64x16, BIT(31), 1);
  1722. }
  1723. }
  1724. }
  1725. #undef IQK_ADDA_REG_NUM
  1726. #undef IQK_DELAY_TIME
  1727. void rtl88e_phy_iq_calibrate(struct ieee80211_hw *hw, bool b_recovery)
  1728. {
  1729. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1730. struct rtl_phy *rtlphy = &rtlpriv->phy;
  1731. long result[4][8];
  1732. u8 i, final_candidate;
  1733. bool b_patha_ok, b_pathb_ok;
  1734. long reg_e94, reg_e9c, reg_ea4, reg_eac, reg_eb4, reg_ebc, reg_ec4,
  1735. reg_ecc, reg_tmp = 0;
  1736. bool is12simular, is13simular, is23simular;
  1737. u32 iqk_bb_reg[9] = {
  1738. ROFDM0_XARXIQIMBALANCE,
  1739. ROFDM0_XBRXIQIMBALANCE,
  1740. ROFDM0_ECCATHRESHOLD,
  1741. ROFDM0_AGCRSSITABLE,
  1742. ROFDM0_XATXIQIMBALANCE,
  1743. ROFDM0_XBTXIQIMBALANCE,
  1744. ROFDM0_XCTXAFE,
  1745. ROFDM0_XDTXAFE,
  1746. ROFDM0_RXIQEXTANTA
  1747. };
  1748. if (b_recovery) {
  1749. _rtl88e_phy_reload_adda_registers(hw,
  1750. iqk_bb_reg,
  1751. rtlphy->iqk_bb_backup, 9);
  1752. return;
  1753. }
  1754. for (i = 0; i < 8; i++) {
  1755. result[0][i] = 0;
  1756. result[1][i] = 0;
  1757. result[2][i] = 0;
  1758. result[3][i] = 0;
  1759. }
  1760. final_candidate = 0xff;
  1761. b_patha_ok = false;
  1762. b_pathb_ok = false;
  1763. is12simular = false;
  1764. is23simular = false;
  1765. is13simular = false;
  1766. for (i = 0; i < 3; i++) {
  1767. if (get_rf_type(rtlphy) == RF_2T2R)
  1768. _rtl88e_phy_iq_calibrate(hw, result, i, true);
  1769. else
  1770. _rtl88e_phy_iq_calibrate(hw, result, i, false);
  1771. if (i == 1) {
  1772. is12simular =
  1773. _rtl88e_phy_simularity_compare(hw, result, 0, 1);
  1774. if (is12simular) {
  1775. final_candidate = 0;
  1776. break;
  1777. }
  1778. }
  1779. if (i == 2) {
  1780. is13simular =
  1781. _rtl88e_phy_simularity_compare(hw, result, 0, 2);
  1782. if (is13simular) {
  1783. final_candidate = 0;
  1784. break;
  1785. }
  1786. is23simular =
  1787. _rtl88e_phy_simularity_compare(hw, result, 1, 2);
  1788. if (is23simular) {
  1789. final_candidate = 1;
  1790. } else {
  1791. for (i = 0; i < 8; i++)
  1792. reg_tmp += result[3][i];
  1793. if (reg_tmp != 0)
  1794. final_candidate = 3;
  1795. else
  1796. final_candidate = 0xFF;
  1797. }
  1798. }
  1799. }
  1800. for (i = 0; i < 4; i++) {
  1801. reg_e94 = result[i][0];
  1802. reg_e9c = result[i][1];
  1803. reg_ea4 = result[i][2];
  1804. reg_eac = result[i][3];
  1805. reg_eb4 = result[i][4];
  1806. reg_ebc = result[i][5];
  1807. reg_ec4 = result[i][6];
  1808. reg_ecc = result[i][7];
  1809. }
  1810. if (final_candidate != 0xff) {
  1811. reg_e94 = result[final_candidate][0];
  1812. reg_e9c = result[final_candidate][1];
  1813. reg_ea4 = result[final_candidate][2];
  1814. reg_eac = result[final_candidate][3];
  1815. reg_eb4 = result[final_candidate][4];
  1816. reg_ebc = result[final_candidate][5];
  1817. reg_ec4 = result[final_candidate][6];
  1818. reg_ecc = result[final_candidate][7];
  1819. rtlphy->reg_eb4 = reg_eb4;
  1820. rtlphy->reg_ebc = reg_ebc;
  1821. rtlphy->reg_e94 = reg_e94;
  1822. rtlphy->reg_e9c = reg_e9c;
  1823. b_patha_ok = true;
  1824. b_pathb_ok = true;
  1825. } else {
  1826. rtlphy->reg_e94 = 0x100;
  1827. rtlphy->reg_eb4 = 0x100;
  1828. rtlphy->reg_e9c = 0x0;
  1829. rtlphy->reg_ebc = 0x0;
  1830. }
  1831. if (reg_e94 != 0) /*&&(reg_ea4 != 0) */
  1832. _rtl88e_phy_path_a_fill_iqk_matrix(hw, b_patha_ok, result,
  1833. final_candidate,
  1834. (reg_ea4 == 0));
  1835. if (final_candidate != 0xFF) {
  1836. for (i = 0; i < IQK_MATRIX_REG_NUM; i++)
  1837. rtlphy->iqk_matrix[0].value[0][i] =
  1838. result[final_candidate][i];
  1839. rtlphy->iqk_matrix[0].iqk_done = true;
  1840. }
  1841. _rtl88e_phy_save_adda_registers(hw, iqk_bb_reg,
  1842. rtlphy->iqk_bb_backup, 9);
  1843. }
  1844. void rtl88e_phy_lc_calibrate(struct ieee80211_hw *hw)
  1845. {
  1846. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1847. struct rtl_phy *rtlphy = &rtlpriv->phy;
  1848. struct rtl_hal *rtlhal = &rtlpriv->rtlhal;
  1849. u32 timeout = 2000, timecount = 0;
  1850. while (rtlpriv->mac80211.act_scanning && timecount < timeout) {
  1851. udelay(50);
  1852. timecount += 50;
  1853. }
  1854. rtlphy->lck_inprogress = true;
  1855. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  1856. "LCK:Start!!! currentband %x delay %d ms\n",
  1857. rtlhal->current_bandtype, timecount);
  1858. _rtl88e_phy_lc_calibrate(hw, false);
  1859. rtlphy->lck_inprogress = false;
  1860. }
  1861. void rtl88e_phy_set_rfpath_switch(struct ieee80211_hw *hw, bool bmain)
  1862. {
  1863. _rtl88e_phy_set_rfpath_switch(hw, bmain, false);
  1864. }
  1865. bool rtl88e_phy_set_io_cmd(struct ieee80211_hw *hw, enum io_type iotype)
  1866. {
  1867. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1868. struct rtl_phy *rtlphy = &rtlpriv->phy;
  1869. bool postprocessing = false;
  1870. RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE,
  1871. "-->IO Cmd(%#x), set_io_inprogress(%d)\n",
  1872. iotype, rtlphy->set_io_inprogress);
  1873. do {
  1874. switch (iotype) {
  1875. case IO_CMD_RESUME_DM_BY_SCAN:
  1876. RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE,
  1877. "[IO CMD] Resume DM after scan.\n");
  1878. postprocessing = true;
  1879. break;
  1880. case IO_CMD_PAUSE_BAND0_DM_BY_SCAN:
  1881. RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE,
  1882. "[IO CMD] Pause DM before scan.\n");
  1883. postprocessing = true;
  1884. break;
  1885. default:
  1886. RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
  1887. "switch case not process\n");
  1888. break;
  1889. }
  1890. } while (false);
  1891. if (postprocessing && !rtlphy->set_io_inprogress) {
  1892. rtlphy->set_io_inprogress = true;
  1893. rtlphy->current_io_type = iotype;
  1894. } else {
  1895. return false;
  1896. }
  1897. rtl88e_phy_set_io(hw);
  1898. RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE, "IO Type(%#x)\n", iotype);
  1899. return true;
  1900. }
  1901. static void rtl88e_phy_set_io(struct ieee80211_hw *hw)
  1902. {
  1903. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1904. struct rtl_phy *rtlphy = &rtlpriv->phy;
  1905. struct dig_t *dm_digtable = &rtlpriv->dm_digtable;
  1906. RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE,
  1907. "--->Cmd(%#x), set_io_inprogress(%d)\n",
  1908. rtlphy->current_io_type, rtlphy->set_io_inprogress);
  1909. switch (rtlphy->current_io_type) {
  1910. case IO_CMD_RESUME_DM_BY_SCAN:
  1911. dm_digtable->cur_igvalue = rtlphy->initgain_backup.xaagccore1;
  1912. /*rtl92c_dm_write_dig(hw);*/
  1913. rtl88e_phy_set_txpower_level(hw, rtlphy->current_channel);
  1914. rtl_set_bbreg(hw, RCCK0_CCA, 0xff0000, 0x83);
  1915. break;
  1916. case IO_CMD_PAUSE_BAND0_DM_BY_SCAN:
  1917. rtlphy->initgain_backup.xaagccore1 = dm_digtable->cur_igvalue;
  1918. dm_digtable->cur_igvalue = 0x17;
  1919. rtl_set_bbreg(hw, RCCK0_CCA, 0xff0000, 0x40);
  1920. break;
  1921. default:
  1922. RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
  1923. "switch case not process\n");
  1924. break;
  1925. }
  1926. rtlphy->set_io_inprogress = false;
  1927. RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE,
  1928. "(%#x)\n", rtlphy->current_io_type);
  1929. }
  1930. static void rtl88ee_phy_set_rf_on(struct ieee80211_hw *hw)
  1931. {
  1932. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1933. rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x2b);
  1934. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE3);
  1935. /*rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x00);*/
  1936. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
  1937. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE3);
  1938. rtl_write_byte(rtlpriv, REG_TXPAUSE, 0x00);
  1939. }
  1940. static void _rtl88ee_phy_set_rf_sleep(struct ieee80211_hw *hw)
  1941. {
  1942. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1943. rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF);
  1944. rtl_set_rfreg(hw, RF90_PATH_A, 0x00, RFREG_OFFSET_MASK, 0x00);
  1945. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
  1946. rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x22);
  1947. }
  1948. static bool _rtl88ee_phy_set_rf_power_state(struct ieee80211_hw *hw,
  1949. enum rf_pwrstate rfpwr_state)
  1950. {
  1951. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1952. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  1953. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1954. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1955. bool bresult = true;
  1956. u8 i, queue_id;
  1957. struct rtl8192_tx_ring *ring = NULL;
  1958. switch (rfpwr_state) {
  1959. case ERFON:
  1960. if ((ppsc->rfpwr_state == ERFOFF) &&
  1961. RT_IN_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC)) {
  1962. bool rtstatus;
  1963. u32 initializecount = 0;
  1964. do {
  1965. initializecount++;
  1966. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  1967. "IPS Set eRf nic enable\n");
  1968. rtstatus = rtl_ps_enable_nic(hw);
  1969. } while (!rtstatus &&
  1970. (initializecount < 10));
  1971. RT_CLEAR_PS_LEVEL(ppsc,
  1972. RT_RF_OFF_LEVL_HALT_NIC);
  1973. } else {
  1974. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  1975. "Set ERFON sleeped:%d ms\n",
  1976. jiffies_to_msecs(jiffies -
  1977. ppsc->
  1978. last_sleep_jiffies));
  1979. ppsc->last_awake_jiffies = jiffies;
  1980. rtl88ee_phy_set_rf_on(hw);
  1981. }
  1982. if (mac->link_state == MAC80211_LINKED) {
  1983. rtlpriv->cfg->ops->led_control(hw,
  1984. LED_CTL_LINK);
  1985. } else {
  1986. rtlpriv->cfg->ops->led_control(hw,
  1987. LED_CTL_NO_LINK);
  1988. }
  1989. break;
  1990. case ERFOFF:
  1991. for (queue_id = 0, i = 0;
  1992. queue_id < RTL_PCI_MAX_TX_QUEUE_COUNT;) {
  1993. ring = &pcipriv->dev.tx_ring[queue_id];
  1994. if (queue_id == BEACON_QUEUE ||
  1995. skb_queue_len(&ring->queue) == 0) {
  1996. queue_id++;
  1997. continue;
  1998. } else {
  1999. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  2000. "eRf Off/Sleep: %d times TcbBusyQueue[%d] =%d before doze!\n",
  2001. (i + 1), queue_id,
  2002. skb_queue_len(&ring->queue));
  2003. udelay(10);
  2004. i++;
  2005. }
  2006. if (i >= MAX_DOZE_WAITING_TIMES_9x) {
  2007. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  2008. "\n ERFSLEEP: %d times TcbBusyQueue[%d] = %d !\n",
  2009. MAX_DOZE_WAITING_TIMES_9x,
  2010. queue_id,
  2011. skb_queue_len(&ring->queue));
  2012. break;
  2013. }
  2014. }
  2015. if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC) {
  2016. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  2017. "IPS Set eRf nic disable\n");
  2018. rtl_ps_disable_nic(hw);
  2019. RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
  2020. } else {
  2021. if (ppsc->rfoff_reason == RF_CHANGE_BY_IPS) {
  2022. rtlpriv->cfg->ops->led_control(hw,
  2023. LED_CTL_NO_LINK);
  2024. } else {
  2025. rtlpriv->cfg->ops->led_control(hw,
  2026. LED_CTL_POWER_OFF);
  2027. }
  2028. }
  2029. break;
  2030. case ERFSLEEP:{
  2031. if (ppsc->rfpwr_state == ERFOFF)
  2032. break;
  2033. for (queue_id = 0, i = 0;
  2034. queue_id < RTL_PCI_MAX_TX_QUEUE_COUNT;) {
  2035. ring = &pcipriv->dev.tx_ring[queue_id];
  2036. if (skb_queue_len(&ring->queue) == 0) {
  2037. queue_id++;
  2038. continue;
  2039. } else {
  2040. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  2041. "eRf Off/Sleep: %d times TcbBusyQueue[%d] =%d before doze!\n",
  2042. (i + 1), queue_id,
  2043. skb_queue_len(&ring->queue));
  2044. udelay(10);
  2045. i++;
  2046. }
  2047. if (i >= MAX_DOZE_WAITING_TIMES_9x) {
  2048. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  2049. "\n ERFSLEEP: %d times TcbBusyQueue[%d] = %d !\n",
  2050. MAX_DOZE_WAITING_TIMES_9x,
  2051. queue_id,
  2052. skb_queue_len(&ring->queue));
  2053. break;
  2054. }
  2055. }
  2056. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  2057. "Set ERFSLEEP awaked:%d ms\n",
  2058. jiffies_to_msecs(jiffies -
  2059. ppsc->last_awake_jiffies));
  2060. ppsc->last_sleep_jiffies = jiffies;
  2061. _rtl88ee_phy_set_rf_sleep(hw);
  2062. break;
  2063. }
  2064. default:
  2065. RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
  2066. "switch case not process\n");
  2067. bresult = false;
  2068. break;
  2069. }
  2070. if (bresult)
  2071. ppsc->rfpwr_state = rfpwr_state;
  2072. return bresult;
  2073. }
  2074. bool rtl88e_phy_set_rf_power_state(struct ieee80211_hw *hw,
  2075. enum rf_pwrstate rfpwr_state)
  2076. {
  2077. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  2078. bool bresult = false;
  2079. if (rfpwr_state == ppsc->rfpwr_state)
  2080. return bresult;
  2081. bresult = _rtl88ee_phy_set_rf_power_state(hw, rfpwr_state);
  2082. return bresult;
  2083. }