phy.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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 "../pci.h"
  27. #include "../ps.h"
  28. #include "../core.h"
  29. #include "reg.h"
  30. #include "def.h"
  31. #include "hw.h"
  32. #include "phy.h"
  33. #include "../rtl8192c/phy_common.h"
  34. #include "rf.h"
  35. #include "dm.h"
  36. #include "../rtl8192c/dm_common.h"
  37. #include "../rtl8192c/fw_common.h"
  38. #include "table.h"
  39. static bool _rtl92c_phy_config_mac_with_headerfile(struct ieee80211_hw *hw);
  40. u32 rtl92c_phy_query_rf_reg(struct ieee80211_hw *hw,
  41. enum radio_path rfpath, u32 regaddr, u32 bitmask)
  42. {
  43. struct rtl_priv *rtlpriv = rtl_priv(hw);
  44. u32 original_value, readback_value, bitshift;
  45. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  46. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
  47. "regaddr(%#x), rfpath(%#x), bitmask(%#x)\n",
  48. regaddr, rfpath, bitmask);
  49. spin_lock(&rtlpriv->locks.rf_lock);
  50. if (rtlphy->rf_mode != RF_OP_BY_FW) {
  51. original_value = _rtl92c_phy_rf_serial_read(hw,
  52. rfpath, regaddr);
  53. } else {
  54. original_value = _rtl92c_phy_fw_rf_serial_read(hw,
  55. rfpath, regaddr);
  56. }
  57. bitshift = _rtl92c_phy_calculate_bit_shift(bitmask);
  58. readback_value = (original_value & bitmask) >> bitshift;
  59. spin_unlock(&rtlpriv->locks.rf_lock);
  60. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
  61. "regaddr(%#x), rfpath(%#x), bitmask(%#x), original_value(%#x)\n",
  62. regaddr, rfpath, bitmask, original_value);
  63. return readback_value;
  64. }
  65. bool rtl92c_phy_mac_config(struct ieee80211_hw *hw)
  66. {
  67. struct rtl_priv *rtlpriv = rtl_priv(hw);
  68. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  69. bool is92c = IS_92C_SERIAL(rtlhal->version);
  70. bool rtstatus = _rtl92c_phy_config_mac_with_headerfile(hw);
  71. if (is92c)
  72. rtl_write_byte(rtlpriv, 0x14, 0x71);
  73. else
  74. rtl_write_byte(rtlpriv, 0x04CA, 0x0A);
  75. return rtstatus;
  76. }
  77. bool rtl92c_phy_bb_config(struct ieee80211_hw *hw)
  78. {
  79. bool rtstatus = true;
  80. struct rtl_priv *rtlpriv = rtl_priv(hw);
  81. u16 regval;
  82. u32 regvaldw;
  83. u8 reg_hwparafile = 1;
  84. _rtl92c_phy_init_bb_rf_register_definition(hw);
  85. regval = rtl_read_word(rtlpriv, REG_SYS_FUNC_EN);
  86. rtl_write_word(rtlpriv, REG_SYS_FUNC_EN,
  87. regval | BIT(13) | BIT(0) | BIT(1));
  88. rtl_write_byte(rtlpriv, REG_AFE_PLL_CTRL, 0x83);
  89. rtl_write_byte(rtlpriv, REG_AFE_PLL_CTRL + 1, 0xdb);
  90. rtl_write_byte(rtlpriv, REG_RF_CTRL, RF_EN | RF_RSTB | RF_SDMRSTB);
  91. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN,
  92. FEN_PPLL | FEN_PCIEA | FEN_DIO_PCIE |
  93. FEN_BB_GLB_RSTn | FEN_BBRSTB);
  94. rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL + 1, 0x80);
  95. regvaldw = rtl_read_dword(rtlpriv, REG_LEDCFG0);
  96. rtl_write_dword(rtlpriv, REG_LEDCFG0, regvaldw | BIT(23));
  97. if (reg_hwparafile == 1)
  98. rtstatus = _rtl92c_phy_bb8192c_config_parafile(hw);
  99. return rtstatus;
  100. }
  101. void rtl92ce_phy_set_rf_reg(struct ieee80211_hw *hw,
  102. enum radio_path rfpath,
  103. u32 regaddr, u32 bitmask, u32 data)
  104. {
  105. struct rtl_priv *rtlpriv = rtl_priv(hw);
  106. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  107. u32 original_value, bitshift;
  108. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
  109. "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
  110. regaddr, bitmask, data, rfpath);
  111. spin_lock(&rtlpriv->locks.rf_lock);
  112. if (rtlphy->rf_mode != RF_OP_BY_FW) {
  113. if (bitmask != RFREG_OFFSET_MASK) {
  114. original_value = _rtl92c_phy_rf_serial_read(hw,
  115. rfpath,
  116. regaddr);
  117. bitshift = _rtl92c_phy_calculate_bit_shift(bitmask);
  118. data =
  119. ((original_value & (~bitmask)) |
  120. (data << bitshift));
  121. }
  122. _rtl92c_phy_rf_serial_write(hw, rfpath, regaddr, data);
  123. } else {
  124. if (bitmask != RFREG_OFFSET_MASK) {
  125. original_value = _rtl92c_phy_fw_rf_serial_read(hw,
  126. rfpath,
  127. regaddr);
  128. bitshift = _rtl92c_phy_calculate_bit_shift(bitmask);
  129. data =
  130. ((original_value & (~bitmask)) |
  131. (data << bitshift));
  132. }
  133. _rtl92c_phy_fw_rf_serial_write(hw, rfpath, regaddr, data);
  134. }
  135. spin_unlock(&rtlpriv->locks.rf_lock);
  136. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
  137. "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
  138. regaddr, bitmask, data, rfpath);
  139. }
  140. static bool _rtl92c_phy_config_mac_with_headerfile(struct ieee80211_hw *hw)
  141. {
  142. struct rtl_priv *rtlpriv = rtl_priv(hw);
  143. u32 i;
  144. u32 arraylength;
  145. u32 *ptrarray;
  146. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "Read Rtl819XMACPHY_Array\n");
  147. arraylength = MAC_2T_ARRAYLENGTH;
  148. ptrarray = RTL8192CEMAC_2T_ARRAY;
  149. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "Img:RTL8192CEMAC_2T_ARRAY\n");
  150. for (i = 0; i < arraylength; i = i + 2)
  151. rtl_write_byte(rtlpriv, ptrarray[i], (u8) ptrarray[i + 1]);
  152. return true;
  153. }
  154. bool _rtl92ce_phy_config_bb_with_headerfile(struct ieee80211_hw *hw,
  155. u8 configtype)
  156. {
  157. int i;
  158. u32 *phy_regarray_table;
  159. u32 *agctab_array_table;
  160. u16 phy_reg_arraylen, agctab_arraylen;
  161. struct rtl_priv *rtlpriv = rtl_priv(hw);
  162. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  163. if (IS_92C_SERIAL(rtlhal->version)) {
  164. agctab_arraylen = AGCTAB_2TARRAYLENGTH;
  165. agctab_array_table = RTL8192CEAGCTAB_2TARRAY;
  166. phy_reg_arraylen = PHY_REG_2TARRAY_LENGTH;
  167. phy_regarray_table = RTL8192CEPHY_REG_2TARRAY;
  168. } else {
  169. agctab_arraylen = AGCTAB_1TARRAYLENGTH;
  170. agctab_array_table = RTL8192CEAGCTAB_1TARRAY;
  171. phy_reg_arraylen = PHY_REG_1TARRAY_LENGTH;
  172. phy_regarray_table = RTL8192CEPHY_REG_1TARRAY;
  173. }
  174. if (configtype == BASEBAND_CONFIG_PHY_REG) {
  175. for (i = 0; i < phy_reg_arraylen; i = i + 2) {
  176. rtl_addr_delay(phy_regarray_table[i]);
  177. rtl_set_bbreg(hw, phy_regarray_table[i], MASKDWORD,
  178. phy_regarray_table[i + 1]);
  179. udelay(1);
  180. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  181. "The phy_regarray_table[0] is %x Rtl819XPHY_REGArray[1] is %x\n",
  182. phy_regarray_table[i],
  183. phy_regarray_table[i + 1]);
  184. }
  185. } else if (configtype == BASEBAND_CONFIG_AGC_TAB) {
  186. for (i = 0; i < agctab_arraylen; i = i + 2) {
  187. rtl_set_bbreg(hw, agctab_array_table[i], MASKDWORD,
  188. agctab_array_table[i + 1]);
  189. udelay(1);
  190. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  191. "The agctab_array_table[0] is %x Rtl819XPHY_REGArray[1] is %x\n",
  192. agctab_array_table[i],
  193. agctab_array_table[i + 1]);
  194. }
  195. }
  196. return true;
  197. }
  198. bool _rtl92ce_phy_config_bb_with_pgheaderfile(struct ieee80211_hw *hw,
  199. u8 configtype)
  200. {
  201. struct rtl_priv *rtlpriv = rtl_priv(hw);
  202. int i;
  203. u32 *phy_regarray_table_pg;
  204. u16 phy_regarray_pg_len;
  205. phy_regarray_pg_len = PHY_REG_ARRAY_PGLENGTH;
  206. phy_regarray_table_pg = RTL8192CEPHY_REG_ARRAY_PG;
  207. if (configtype == BASEBAND_CONFIG_PHY_REG) {
  208. for (i = 0; i < phy_regarray_pg_len; i = i + 3) {
  209. rtl_addr_delay(phy_regarray_table_pg[i]);
  210. _rtl92c_store_pwrIndex_diffrate_offset(hw,
  211. phy_regarray_table_pg[i],
  212. phy_regarray_table_pg[i + 1],
  213. phy_regarray_table_pg[i + 2]);
  214. }
  215. } else {
  216. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  217. "configtype != BaseBand_Config_PHY_REG\n");
  218. }
  219. return true;
  220. }
  221. bool rtl92c_phy_config_rf_with_headerfile(struct ieee80211_hw *hw,
  222. enum radio_path rfpath)
  223. {
  224. int i;
  225. u32 *radioa_array_table;
  226. u32 *radiob_array_table;
  227. u16 radioa_arraylen, radiob_arraylen;
  228. struct rtl_priv *rtlpriv = rtl_priv(hw);
  229. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  230. if (IS_92C_SERIAL(rtlhal->version)) {
  231. radioa_arraylen = RADIOA_2TARRAYLENGTH;
  232. radioa_array_table = RTL8192CERADIOA_2TARRAY;
  233. radiob_arraylen = RADIOB_2TARRAYLENGTH;
  234. radiob_array_table = RTL8192CE_RADIOB_2TARRAY;
  235. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  236. "Radio_A:RTL8192CERADIOA_2TARRAY\n");
  237. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  238. "Radio_B:RTL8192CE_RADIOB_2TARRAY\n");
  239. } else {
  240. radioa_arraylen = RADIOA_1TARRAYLENGTH;
  241. radioa_array_table = RTL8192CE_RADIOA_1TARRAY;
  242. radiob_arraylen = RADIOB_1TARRAYLENGTH;
  243. radiob_array_table = RTL8192CE_RADIOB_1TARRAY;
  244. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  245. "Radio_A:RTL8192CE_RADIOA_1TARRAY\n");
  246. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  247. "Radio_B:RTL8192CE_RADIOB_1TARRAY\n");
  248. }
  249. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "Radio No %x\n", rfpath);
  250. switch (rfpath) {
  251. case RF90_PATH_A:
  252. for (i = 0; i < radioa_arraylen; i = i + 2) {
  253. rtl_rfreg_delay(hw, rfpath, radioa_array_table[i],
  254. RFREG_OFFSET_MASK,
  255. radioa_array_table[i + 1]);
  256. }
  257. break;
  258. case RF90_PATH_B:
  259. for (i = 0; i < radiob_arraylen; i = i + 2) {
  260. rtl_rfreg_delay(hw, rfpath, radiob_array_table[i],
  261. RFREG_OFFSET_MASK,
  262. radiob_array_table[i + 1]);
  263. }
  264. break;
  265. case RF90_PATH_C:
  266. case RF90_PATH_D:
  267. pr_info("Incorrect rfpath %#x\n", rfpath);
  268. break;
  269. default:
  270. pr_info("switch case %#x not processed\n", rfpath);
  271. break;
  272. }
  273. return true;
  274. }
  275. void rtl92ce_phy_set_bw_mode_callback(struct ieee80211_hw *hw)
  276. {
  277. struct rtl_priv *rtlpriv = rtl_priv(hw);
  278. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  279. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  280. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  281. u8 reg_bw_opmode;
  282. u8 reg_prsr_rsc;
  283. RT_TRACE(rtlpriv, COMP_SCAN, DBG_TRACE, "Switch to %s bandwidth\n",
  284. rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20 ?
  285. "20MHz" : "40MHz");
  286. if (is_hal_stop(rtlhal)) {
  287. rtlphy->set_bwmode_inprogress = false;
  288. return;
  289. }
  290. reg_bw_opmode = rtl_read_byte(rtlpriv, REG_BWOPMODE);
  291. reg_prsr_rsc = rtl_read_byte(rtlpriv, REG_RRSR + 2);
  292. switch (rtlphy->current_chan_bw) {
  293. case HT_CHANNEL_WIDTH_20:
  294. reg_bw_opmode |= BW_OPMODE_20MHZ;
  295. rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode);
  296. break;
  297. case HT_CHANNEL_WIDTH_20_40:
  298. reg_bw_opmode &= ~BW_OPMODE_20MHZ;
  299. rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode);
  300. reg_prsr_rsc =
  301. (reg_prsr_rsc & 0x90) | (mac->cur_40_prime_sc << 5);
  302. rtl_write_byte(rtlpriv, REG_RRSR + 2, reg_prsr_rsc);
  303. break;
  304. default:
  305. pr_info("unknown bandwidth: %#X\n", rtlphy->current_chan_bw);
  306. break;
  307. }
  308. switch (rtlphy->current_chan_bw) {
  309. case HT_CHANNEL_WIDTH_20:
  310. rtl_set_bbreg(hw, RFPGA0_RFMOD, BRFMOD, 0x0);
  311. rtl_set_bbreg(hw, RFPGA1_RFMOD, BRFMOD, 0x0);
  312. rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 1);
  313. break;
  314. case HT_CHANNEL_WIDTH_20_40:
  315. rtl_set_bbreg(hw, RFPGA0_RFMOD, BRFMOD, 0x1);
  316. rtl_set_bbreg(hw, RFPGA1_RFMOD, BRFMOD, 0x1);
  317. rtl_set_bbreg(hw, RCCK0_SYSTEM, BCCK_SIDEBAND,
  318. (mac->cur_40_prime_sc >> 1));
  319. rtl_set_bbreg(hw, ROFDM1_LSTF, 0xC00, mac->cur_40_prime_sc);
  320. rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 0);
  321. rtl_set_bbreg(hw, 0x818, (BIT(26) | BIT(27)),
  322. (mac->cur_40_prime_sc ==
  323. HAL_PRIME_CHNL_OFFSET_LOWER) ? 2 : 1);
  324. break;
  325. default:
  326. pr_err("unknown bandwidth: %#X\n",
  327. rtlphy->current_chan_bw);
  328. break;
  329. }
  330. rtl92ce_phy_rf6052_set_bandwidth(hw, rtlphy->current_chan_bw);
  331. rtlphy->set_bwmode_inprogress = false;
  332. RT_TRACE(rtlpriv, COMP_SCAN, DBG_TRACE, "<==\n");
  333. }
  334. void _rtl92ce_phy_lc_calibrate(struct ieee80211_hw *hw, bool is2t)
  335. {
  336. u8 tmpreg;
  337. u32 rf_a_mode = 0, rf_b_mode = 0, lc_cal;
  338. struct rtl_priv *rtlpriv = rtl_priv(hw);
  339. tmpreg = rtl_read_byte(rtlpriv, 0xd03);
  340. if ((tmpreg & 0x70) != 0)
  341. rtl_write_byte(rtlpriv, 0xd03, tmpreg & 0x8F);
  342. else
  343. rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF);
  344. if ((tmpreg & 0x70) != 0) {
  345. rf_a_mode = rtl_get_rfreg(hw, RF90_PATH_A, 0x00, MASK12BITS);
  346. if (is2t)
  347. rf_b_mode = rtl_get_rfreg(hw, RF90_PATH_B, 0x00,
  348. MASK12BITS);
  349. rtl_set_rfreg(hw, RF90_PATH_A, 0x00, MASK12BITS,
  350. (rf_a_mode & 0x8FFFF) | 0x10000);
  351. if (is2t)
  352. rtl_set_rfreg(hw, RF90_PATH_B, 0x00, MASK12BITS,
  353. (rf_b_mode & 0x8FFFF) | 0x10000);
  354. }
  355. lc_cal = rtl_get_rfreg(hw, RF90_PATH_A, 0x18, MASK12BITS);
  356. rtl_set_rfreg(hw, RF90_PATH_A, 0x18, MASK12BITS, lc_cal | 0x08000);
  357. mdelay(100);
  358. if ((tmpreg & 0x70) != 0) {
  359. rtl_write_byte(rtlpriv, 0xd03, tmpreg);
  360. rtl_set_rfreg(hw, RF90_PATH_A, 0x00, MASK12BITS, rf_a_mode);
  361. if (is2t)
  362. rtl_set_rfreg(hw, RF90_PATH_B, 0x00, MASK12BITS,
  363. rf_b_mode);
  364. } else {
  365. rtl_write_byte(rtlpriv, REG_TXPAUSE, 0x00);
  366. }
  367. }
  368. static void _rtl92ce_phy_set_rf_sleep(struct ieee80211_hw *hw)
  369. {
  370. u32 u4b_tmp;
  371. u8 delay = 5;
  372. struct rtl_priv *rtlpriv = rtl_priv(hw);
  373. rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF);
  374. rtl_set_rfreg(hw, RF90_PATH_A, 0x00, RFREG_OFFSET_MASK, 0x00);
  375. rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x40);
  376. u4b_tmp = rtl_get_rfreg(hw, RF90_PATH_A, 0, RFREG_OFFSET_MASK);
  377. while (u4b_tmp != 0 && delay > 0) {
  378. rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x0);
  379. rtl_set_rfreg(hw, RF90_PATH_A, 0x00, RFREG_OFFSET_MASK, 0x00);
  380. rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x40);
  381. u4b_tmp = rtl_get_rfreg(hw, RF90_PATH_A, 0, RFREG_OFFSET_MASK);
  382. delay--;
  383. }
  384. if (delay == 0) {
  385. rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x00);
  386. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
  387. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE3);
  388. rtl_write_byte(rtlpriv, REG_TXPAUSE, 0x00);
  389. RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE,
  390. "Switch RF timeout !!!\n");
  391. return;
  392. }
  393. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
  394. rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x22);
  395. }
  396. static bool _rtl92ce_phy_set_rf_power_state(struct ieee80211_hw *hw,
  397. enum rf_pwrstate rfpwr_state)
  398. {
  399. struct rtl_priv *rtlpriv = rtl_priv(hw);
  400. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  401. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  402. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  403. bool bresult = true;
  404. u8 i, queue_id;
  405. struct rtl8192_tx_ring *ring = NULL;
  406. switch (rfpwr_state) {
  407. case ERFON:{
  408. if ((ppsc->rfpwr_state == ERFOFF) &&
  409. RT_IN_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC)) {
  410. bool rtstatus;
  411. u32 InitializeCount = 0;
  412. do {
  413. InitializeCount++;
  414. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  415. "IPS Set eRf nic enable\n");
  416. rtstatus = rtl_ps_enable_nic(hw);
  417. } while (!rtstatus && (InitializeCount < 10));
  418. RT_CLEAR_PS_LEVEL(ppsc,
  419. RT_RF_OFF_LEVL_HALT_NIC);
  420. } else {
  421. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  422. "Set ERFON sleeped:%d ms\n",
  423. jiffies_to_msecs(jiffies -
  424. ppsc->
  425. last_sleep_jiffies));
  426. ppsc->last_awake_jiffies = jiffies;
  427. rtl92ce_phy_set_rf_on(hw);
  428. }
  429. if (mac->link_state == MAC80211_LINKED) {
  430. rtlpriv->cfg->ops->led_control(hw,
  431. LED_CTL_LINK);
  432. } else {
  433. rtlpriv->cfg->ops->led_control(hw,
  434. LED_CTL_NO_LINK);
  435. }
  436. break;
  437. }
  438. case ERFOFF:{
  439. if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC) {
  440. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  441. "IPS Set eRf nic disable\n");
  442. rtl_ps_disable_nic(hw);
  443. RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
  444. } else {
  445. if (ppsc->rfoff_reason == RF_CHANGE_BY_IPS) {
  446. rtlpriv->cfg->ops->led_control(hw,
  447. LED_CTL_NO_LINK);
  448. } else {
  449. rtlpriv->cfg->ops->led_control(hw,
  450. LED_CTL_POWER_OFF);
  451. }
  452. }
  453. break;
  454. }
  455. case ERFSLEEP:{
  456. if (ppsc->rfpwr_state == ERFOFF)
  457. break;
  458. for (queue_id = 0, i = 0;
  459. queue_id < RTL_PCI_MAX_TX_QUEUE_COUNT;) {
  460. ring = &pcipriv->dev.tx_ring[queue_id];
  461. if (queue_id == BEACON_QUEUE ||
  462. skb_queue_len(&ring->queue) == 0) {
  463. queue_id++;
  464. continue;
  465. } else {
  466. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  467. "eRf Off/Sleep: %d times TcbBusyQueue[%d] =%d before doze!\n",
  468. i + 1, queue_id,
  469. skb_queue_len(&ring->queue));
  470. udelay(10);
  471. i++;
  472. }
  473. if (i >= MAX_DOZE_WAITING_TIMES_9x) {
  474. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  475. "ERFSLEEP: %d times TcbBusyQueue[%d] = %d !\n",
  476. MAX_DOZE_WAITING_TIMES_9x,
  477. queue_id,
  478. skb_queue_len(&ring->queue));
  479. break;
  480. }
  481. }
  482. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  483. "Set ERFSLEEP awaked:%d ms\n",
  484. jiffies_to_msecs(jiffies -
  485. ppsc->last_awake_jiffies));
  486. ppsc->last_sleep_jiffies = jiffies;
  487. _rtl92ce_phy_set_rf_sleep(hw);
  488. break;
  489. }
  490. default:
  491. pr_err("switch case %#x not processed\n",
  492. rfpwr_state);
  493. bresult = false;
  494. break;
  495. }
  496. if (bresult)
  497. ppsc->rfpwr_state = rfpwr_state;
  498. return bresult;
  499. }
  500. bool rtl92c_phy_set_rf_power_state(struct ieee80211_hw *hw,
  501. enum rf_pwrstate rfpwr_state)
  502. {
  503. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  504. bool bresult = false;
  505. if (rfpwr_state == ppsc->rfpwr_state)
  506. return bresult;
  507. bresult = _rtl92ce_phy_set_rf_power_state(hw, rfpwr_state);
  508. return bresult;
  509. }