phy.c 17 KB

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