phy.c 16 KB

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