18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* Copyright(c) 2009-2013 Realtek Corporation.*/ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#include "../wifi.h" 58c2ecf20Sopenharmony_ci#include "../pci.h" 68c2ecf20Sopenharmony_ci#include "../ps.h" 78c2ecf20Sopenharmony_ci#include "reg.h" 88c2ecf20Sopenharmony_ci#include "def.h" 98c2ecf20Sopenharmony_ci#include "phy.h" 108c2ecf20Sopenharmony_ci#include "rf.h" 118c2ecf20Sopenharmony_ci#include "dm.h" 128c2ecf20Sopenharmony_ci#include "table.h" 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_cistatic u32 _rtl88e_phy_rf_serial_read(struct ieee80211_hw *hw, 158c2ecf20Sopenharmony_ci enum radio_path rfpath, u32 offset); 168c2ecf20Sopenharmony_cistatic void _rtl88e_phy_rf_serial_write(struct ieee80211_hw *hw, 178c2ecf20Sopenharmony_ci enum radio_path rfpath, u32 offset, 188c2ecf20Sopenharmony_ci u32 data); 198c2ecf20Sopenharmony_cistatic bool _rtl88e_phy_bb8188e_config_parafile(struct ieee80211_hw *hw); 208c2ecf20Sopenharmony_cistatic bool _rtl88e_phy_config_mac_with_headerfile(struct ieee80211_hw *hw); 218c2ecf20Sopenharmony_cistatic bool phy_config_bb_with_headerfile(struct ieee80211_hw *hw, 228c2ecf20Sopenharmony_ci u8 configtype); 238c2ecf20Sopenharmony_cistatic bool phy_config_bb_with_pghdr(struct ieee80211_hw *hw, 248c2ecf20Sopenharmony_ci u8 configtype); 258c2ecf20Sopenharmony_cistatic void _rtl88e_phy_init_bb_rf_register_definition(struct ieee80211_hw *hw); 268c2ecf20Sopenharmony_cistatic bool _rtl88e_phy_set_sw_chnl_cmdarray(struct swchnlcmd *cmdtable, 278c2ecf20Sopenharmony_ci u32 cmdtableidx, u32 cmdtablesz, 288c2ecf20Sopenharmony_ci enum swchnlcmd_id cmdid, u32 para1, 298c2ecf20Sopenharmony_ci u32 para2, u32 msdelay); 308c2ecf20Sopenharmony_cistatic bool _rtl88e_phy_sw_chnl_step_by_step(struct ieee80211_hw *hw, 318c2ecf20Sopenharmony_ci u8 channel, u8 *stage, u8 *step, 328c2ecf20Sopenharmony_ci u32 *delay); 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_cistatic long _rtl88e_phy_txpwr_idx_to_dbm(struct ieee80211_hw *hw, 358c2ecf20Sopenharmony_ci enum wireless_mode wirelessmode, 368c2ecf20Sopenharmony_ci u8 txpwridx); 378c2ecf20Sopenharmony_cistatic void rtl88ee_phy_set_rf_on(struct ieee80211_hw *hw); 388c2ecf20Sopenharmony_cistatic void rtl88e_phy_set_io(struct ieee80211_hw *hw); 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ciu32 rtl88e_phy_query_bb_reg(struct ieee80211_hw *hw, u32 regaddr, u32 bitmask) 418c2ecf20Sopenharmony_ci{ 428c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 438c2ecf20Sopenharmony_ci u32 returnvalue, originalvalue, bitshift; 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, 468c2ecf20Sopenharmony_ci "regaddr(%#x), bitmask(%#x)\n", regaddr, bitmask); 478c2ecf20Sopenharmony_ci originalvalue = rtl_read_dword(rtlpriv, regaddr); 488c2ecf20Sopenharmony_ci bitshift = calculate_bit_shift(bitmask); 498c2ecf20Sopenharmony_ci returnvalue = (originalvalue & bitmask) >> bitshift; 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, 528c2ecf20Sopenharmony_ci "BBR MASK=0x%x Addr[0x%x]=0x%x\n", bitmask, 538c2ecf20Sopenharmony_ci regaddr, originalvalue); 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci return returnvalue; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci} 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_civoid rtl88e_phy_set_bb_reg(struct ieee80211_hw *hw, 608c2ecf20Sopenharmony_ci u32 regaddr, u32 bitmask, u32 data) 618c2ecf20Sopenharmony_ci{ 628c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 638c2ecf20Sopenharmony_ci u32 originalvalue, bitshift; 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, 668c2ecf20Sopenharmony_ci "regaddr(%#x), bitmask(%#x), data(%#x)\n", 678c2ecf20Sopenharmony_ci regaddr, bitmask, data); 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci if (bitmask != MASKDWORD) { 708c2ecf20Sopenharmony_ci originalvalue = rtl_read_dword(rtlpriv, regaddr); 718c2ecf20Sopenharmony_ci bitshift = calculate_bit_shift(bitmask); 728c2ecf20Sopenharmony_ci data = ((originalvalue & (~bitmask)) | (data << bitshift)); 738c2ecf20Sopenharmony_ci } 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci rtl_write_dword(rtlpriv, regaddr, data); 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, 788c2ecf20Sopenharmony_ci "regaddr(%#x), bitmask(%#x), data(%#x)\n", 798c2ecf20Sopenharmony_ci regaddr, bitmask, data); 808c2ecf20Sopenharmony_ci} 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ciu32 rtl88e_phy_query_rf_reg(struct ieee80211_hw *hw, 838c2ecf20Sopenharmony_ci enum radio_path rfpath, u32 regaddr, u32 bitmask) 848c2ecf20Sopenharmony_ci{ 858c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 868c2ecf20Sopenharmony_ci u32 original_value, readback_value, bitshift; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, 898c2ecf20Sopenharmony_ci "regaddr(%#x), rfpath(%#x), bitmask(%#x)\n", 908c2ecf20Sopenharmony_ci regaddr, rfpath, bitmask); 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci spin_lock(&rtlpriv->locks.rf_lock); 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci original_value = _rtl88e_phy_rf_serial_read(hw, rfpath, regaddr); 968c2ecf20Sopenharmony_ci bitshift = calculate_bit_shift(bitmask); 978c2ecf20Sopenharmony_ci readback_value = (original_value & bitmask) >> bitshift; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci spin_unlock(&rtlpriv->locks.rf_lock); 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, 1028c2ecf20Sopenharmony_ci "regaddr(%#x), rfpath(%#x), bitmask(%#x), original_value(%#x)\n", 1038c2ecf20Sopenharmony_ci regaddr, rfpath, bitmask, original_value); 1048c2ecf20Sopenharmony_ci return readback_value; 1058c2ecf20Sopenharmony_ci} 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_civoid rtl88e_phy_set_rf_reg(struct ieee80211_hw *hw, 1088c2ecf20Sopenharmony_ci enum radio_path rfpath, 1098c2ecf20Sopenharmony_ci u32 regaddr, u32 bitmask, u32 data) 1108c2ecf20Sopenharmony_ci{ 1118c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 1128c2ecf20Sopenharmony_ci u32 original_value, bitshift; 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, 1158c2ecf20Sopenharmony_ci "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n", 1168c2ecf20Sopenharmony_ci regaddr, bitmask, data, rfpath); 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci spin_lock(&rtlpriv->locks.rf_lock); 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci if (bitmask != RFREG_OFFSET_MASK) { 1218c2ecf20Sopenharmony_ci original_value = _rtl88e_phy_rf_serial_read(hw, 1228c2ecf20Sopenharmony_ci rfpath, 1238c2ecf20Sopenharmony_ci regaddr); 1248c2ecf20Sopenharmony_ci bitshift = calculate_bit_shift(bitmask); 1258c2ecf20Sopenharmony_ci data = 1268c2ecf20Sopenharmony_ci ((original_value & (~bitmask)) | 1278c2ecf20Sopenharmony_ci (data << bitshift)); 1288c2ecf20Sopenharmony_ci } 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci _rtl88e_phy_rf_serial_write(hw, rfpath, regaddr, data); 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci spin_unlock(&rtlpriv->locks.rf_lock); 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, 1368c2ecf20Sopenharmony_ci "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n", 1378c2ecf20Sopenharmony_ci regaddr, bitmask, data, rfpath); 1388c2ecf20Sopenharmony_ci} 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_cistatic u32 _rtl88e_phy_rf_serial_read(struct ieee80211_hw *hw, 1418c2ecf20Sopenharmony_ci enum radio_path rfpath, u32 offset) 1428c2ecf20Sopenharmony_ci{ 1438c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 1448c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 1458c2ecf20Sopenharmony_ci struct bb_reg_def *pphyreg = &rtlphy->phyreg_def[rfpath]; 1468c2ecf20Sopenharmony_ci u32 newoffset; 1478c2ecf20Sopenharmony_ci u32 tmplong, tmplong2; 1488c2ecf20Sopenharmony_ci u8 rfpi_enable = 0; 1498c2ecf20Sopenharmony_ci u32 retvalue; 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci offset &= 0xff; 1528c2ecf20Sopenharmony_ci newoffset = offset; 1538c2ecf20Sopenharmony_ci if (RT_CANNOT_IO(hw)) { 1548c2ecf20Sopenharmony_ci pr_err("return all one\n"); 1558c2ecf20Sopenharmony_ci return 0xFFFFFFFF; 1568c2ecf20Sopenharmony_ci } 1578c2ecf20Sopenharmony_ci tmplong = rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, MASKDWORD); 1588c2ecf20Sopenharmony_ci if (rfpath == RF90_PATH_A) 1598c2ecf20Sopenharmony_ci tmplong2 = tmplong; 1608c2ecf20Sopenharmony_ci else 1618c2ecf20Sopenharmony_ci tmplong2 = rtl_get_bbreg(hw, pphyreg->rfhssi_para2, MASKDWORD); 1628c2ecf20Sopenharmony_ci tmplong2 = (tmplong2 & (~BLSSIREADADDRESS)) | 1638c2ecf20Sopenharmony_ci (newoffset << 23) | BLSSIREADEDGE; 1648c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, MASKDWORD, 1658c2ecf20Sopenharmony_ci tmplong & (~BLSSIREADEDGE)); 1668c2ecf20Sopenharmony_ci udelay(10); 1678c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, pphyreg->rfhssi_para2, MASKDWORD, tmplong2); 1688c2ecf20Sopenharmony_ci udelay(120); 1698c2ecf20Sopenharmony_ci if (rfpath == RF90_PATH_A) 1708c2ecf20Sopenharmony_ci rfpi_enable = (u8)rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER1, 1718c2ecf20Sopenharmony_ci BIT(8)); 1728c2ecf20Sopenharmony_ci else if (rfpath == RF90_PATH_B) 1738c2ecf20Sopenharmony_ci rfpi_enable = (u8)rtl_get_bbreg(hw, RFPGA0_XB_HSSIPARAMETER1, 1748c2ecf20Sopenharmony_ci BIT(8)); 1758c2ecf20Sopenharmony_ci if (rfpi_enable) 1768c2ecf20Sopenharmony_ci retvalue = rtl_get_bbreg(hw, pphyreg->rf_rbpi, 1778c2ecf20Sopenharmony_ci BLSSIREADBACKDATA); 1788c2ecf20Sopenharmony_ci else 1798c2ecf20Sopenharmony_ci retvalue = rtl_get_bbreg(hw, pphyreg->rf_rb, 1808c2ecf20Sopenharmony_ci BLSSIREADBACKDATA); 1818c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, 1828c2ecf20Sopenharmony_ci "RFR-%d Addr[0x%x]=0x%x\n", 1838c2ecf20Sopenharmony_ci rfpath, pphyreg->rf_rb, retvalue); 1848c2ecf20Sopenharmony_ci return retvalue; 1858c2ecf20Sopenharmony_ci} 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_cistatic void _rtl88e_phy_rf_serial_write(struct ieee80211_hw *hw, 1888c2ecf20Sopenharmony_ci enum radio_path rfpath, u32 offset, 1898c2ecf20Sopenharmony_ci u32 data) 1908c2ecf20Sopenharmony_ci{ 1918c2ecf20Sopenharmony_ci u32 data_and_addr; 1928c2ecf20Sopenharmony_ci u32 newoffset; 1938c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 1948c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 1958c2ecf20Sopenharmony_ci struct bb_reg_def *pphyreg = &rtlphy->phyreg_def[rfpath]; 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci if (RT_CANNOT_IO(hw)) { 1988c2ecf20Sopenharmony_ci pr_err("stop\n"); 1998c2ecf20Sopenharmony_ci return; 2008c2ecf20Sopenharmony_ci } 2018c2ecf20Sopenharmony_ci offset &= 0xff; 2028c2ecf20Sopenharmony_ci newoffset = offset; 2038c2ecf20Sopenharmony_ci data_and_addr = ((newoffset << 20) | (data & 0x000fffff)) & 0x0fffffff; 2048c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, pphyreg->rf3wire_offset, MASKDWORD, data_and_addr); 2058c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, 2068c2ecf20Sopenharmony_ci "RFW-%d Addr[0x%x]=0x%x\n", 2078c2ecf20Sopenharmony_ci rfpath, pphyreg->rf3wire_offset, data_and_addr); 2088c2ecf20Sopenharmony_ci} 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_cibool rtl88e_phy_mac_config(struct ieee80211_hw *hw) 2118c2ecf20Sopenharmony_ci{ 2128c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 2138c2ecf20Sopenharmony_ci bool rtstatus = _rtl88e_phy_config_mac_with_headerfile(hw); 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, 0x04CA, 0x0B); 2168c2ecf20Sopenharmony_ci return rtstatus; 2178c2ecf20Sopenharmony_ci} 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_cibool rtl88e_phy_bb_config(struct ieee80211_hw *hw) 2208c2ecf20Sopenharmony_ci{ 2218c2ecf20Sopenharmony_ci bool rtstatus = true; 2228c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 2238c2ecf20Sopenharmony_ci u16 regval; 2248c2ecf20Sopenharmony_ci u8 b_reg_hwparafile = 1; 2258c2ecf20Sopenharmony_ci u32 tmp; 2268c2ecf20Sopenharmony_ci _rtl88e_phy_init_bb_rf_register_definition(hw); 2278c2ecf20Sopenharmony_ci regval = rtl_read_word(rtlpriv, REG_SYS_FUNC_EN); 2288c2ecf20Sopenharmony_ci rtl_write_word(rtlpriv, REG_SYS_FUNC_EN, 2298c2ecf20Sopenharmony_ci regval | BIT(13) | BIT(0) | BIT(1)); 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, REG_RF_CTRL, RF_EN | RF_RSTB | RF_SDMRSTB); 2328c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 2338c2ecf20Sopenharmony_ci FEN_PPLL | FEN_PCIEA | FEN_DIO_PCIE | 2348c2ecf20Sopenharmony_ci FEN_BB_GLB_RSTN | FEN_BBRSTB); 2358c2ecf20Sopenharmony_ci tmp = rtl_read_dword(rtlpriv, 0x4c); 2368c2ecf20Sopenharmony_ci rtl_write_dword(rtlpriv, 0x4c, tmp | BIT(23)); 2378c2ecf20Sopenharmony_ci if (b_reg_hwparafile == 1) 2388c2ecf20Sopenharmony_ci rtstatus = _rtl88e_phy_bb8188e_config_parafile(hw); 2398c2ecf20Sopenharmony_ci return rtstatus; 2408c2ecf20Sopenharmony_ci} 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_cibool rtl88e_phy_rf_config(struct ieee80211_hw *hw) 2438c2ecf20Sopenharmony_ci{ 2448c2ecf20Sopenharmony_ci return rtl88e_phy_rf6052_config(hw); 2458c2ecf20Sopenharmony_ci} 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_cistatic bool _rtl88e_check_condition(struct ieee80211_hw *hw, 2488c2ecf20Sopenharmony_ci const u32 condition) 2498c2ecf20Sopenharmony_ci{ 2508c2ecf20Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 2518c2ecf20Sopenharmony_ci struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 2528c2ecf20Sopenharmony_ci u32 _board = rtlefuse->board_type; /*need efuse define*/ 2538c2ecf20Sopenharmony_ci u32 _interface = rtlhal->interface; 2548c2ecf20Sopenharmony_ci u32 _platform = 0x08;/*SupportPlatform */ 2558c2ecf20Sopenharmony_ci u32 cond; 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci if (condition == 0xCDCDCDCD) 2588c2ecf20Sopenharmony_ci return true; 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ci cond = condition & 0xFF; 2618c2ecf20Sopenharmony_ci if ((_board & cond) == 0 && cond != 0x1F) 2628c2ecf20Sopenharmony_ci return false; 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci cond = condition & 0xFF00; 2658c2ecf20Sopenharmony_ci cond = cond >> 8; 2668c2ecf20Sopenharmony_ci if ((_interface & cond) == 0 && cond != 0x07) 2678c2ecf20Sopenharmony_ci return false; 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci cond = condition & 0xFF0000; 2708c2ecf20Sopenharmony_ci cond = cond >> 16; 2718c2ecf20Sopenharmony_ci if ((_platform & cond) == 0 && cond != 0x0F) 2728c2ecf20Sopenharmony_ci return false; 2738c2ecf20Sopenharmony_ci return true; 2748c2ecf20Sopenharmony_ci} 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_cistatic void _rtl8188e_config_rf_reg(struct ieee80211_hw *hw, u32 addr, 2778c2ecf20Sopenharmony_ci u32 data, enum radio_path rfpath, 2788c2ecf20Sopenharmony_ci u32 regaddr) 2798c2ecf20Sopenharmony_ci{ 2808c2ecf20Sopenharmony_ci if (addr == 0xffe) { 2818c2ecf20Sopenharmony_ci mdelay(50); 2828c2ecf20Sopenharmony_ci } else if (addr == 0xfd) { 2838c2ecf20Sopenharmony_ci mdelay(5); 2848c2ecf20Sopenharmony_ci } else if (addr == 0xfc) { 2858c2ecf20Sopenharmony_ci mdelay(1); 2868c2ecf20Sopenharmony_ci } else if (addr == 0xfb) { 2878c2ecf20Sopenharmony_ci udelay(50); 2888c2ecf20Sopenharmony_ci } else if (addr == 0xfa) { 2898c2ecf20Sopenharmony_ci udelay(5); 2908c2ecf20Sopenharmony_ci } else if (addr == 0xf9) { 2918c2ecf20Sopenharmony_ci udelay(1); 2928c2ecf20Sopenharmony_ci } else { 2938c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, rfpath, regaddr, 2948c2ecf20Sopenharmony_ci RFREG_OFFSET_MASK, 2958c2ecf20Sopenharmony_ci data); 2968c2ecf20Sopenharmony_ci udelay(1); 2978c2ecf20Sopenharmony_ci } 2988c2ecf20Sopenharmony_ci} 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_cistatic void _rtl8188e_config_rf_radio_a(struct ieee80211_hw *hw, 3018c2ecf20Sopenharmony_ci u32 addr, u32 data) 3028c2ecf20Sopenharmony_ci{ 3038c2ecf20Sopenharmony_ci u32 content = 0x1000; /*RF Content: radio_a_txt*/ 3048c2ecf20Sopenharmony_ci u32 maskforphyset = (u32)(content & 0xE000); 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci _rtl8188e_config_rf_reg(hw, addr, data, RF90_PATH_A, 3078c2ecf20Sopenharmony_ci addr | maskforphyset); 3088c2ecf20Sopenharmony_ci} 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_cistatic void _rtl8188e_config_bb_reg(struct ieee80211_hw *hw, 3118c2ecf20Sopenharmony_ci u32 addr, u32 data) 3128c2ecf20Sopenharmony_ci{ 3138c2ecf20Sopenharmony_ci if (addr == 0xfe) { 3148c2ecf20Sopenharmony_ci mdelay(50); 3158c2ecf20Sopenharmony_ci } else if (addr == 0xfd) { 3168c2ecf20Sopenharmony_ci mdelay(5); 3178c2ecf20Sopenharmony_ci } else if (addr == 0xfc) { 3188c2ecf20Sopenharmony_ci mdelay(1); 3198c2ecf20Sopenharmony_ci } else if (addr == 0xfb) { 3208c2ecf20Sopenharmony_ci udelay(50); 3218c2ecf20Sopenharmony_ci } else if (addr == 0xfa) { 3228c2ecf20Sopenharmony_ci udelay(5); 3238c2ecf20Sopenharmony_ci } else if (addr == 0xf9) { 3248c2ecf20Sopenharmony_ci udelay(1); 3258c2ecf20Sopenharmony_ci } else { 3268c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, addr, MASKDWORD, data); 3278c2ecf20Sopenharmony_ci udelay(1); 3288c2ecf20Sopenharmony_ci } 3298c2ecf20Sopenharmony_ci} 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_cistatic bool _rtl88e_phy_bb8188e_config_parafile(struct ieee80211_hw *hw) 3328c2ecf20Sopenharmony_ci{ 3338c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 3348c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 3358c2ecf20Sopenharmony_ci struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 3368c2ecf20Sopenharmony_ci bool rtstatus; 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci rtstatus = phy_config_bb_with_headerfile(hw, BASEBAND_CONFIG_PHY_REG); 3398c2ecf20Sopenharmony_ci if (!rtstatus) { 3408c2ecf20Sopenharmony_ci pr_err("Write BB Reg Fail!!\n"); 3418c2ecf20Sopenharmony_ci return false; 3428c2ecf20Sopenharmony_ci } 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_ci if (!rtlefuse->autoload_failflag) { 3458c2ecf20Sopenharmony_ci rtlphy->pwrgroup_cnt = 0; 3468c2ecf20Sopenharmony_ci rtstatus = 3478c2ecf20Sopenharmony_ci phy_config_bb_with_pghdr(hw, BASEBAND_CONFIG_PHY_REG); 3488c2ecf20Sopenharmony_ci } 3498c2ecf20Sopenharmony_ci if (!rtstatus) { 3508c2ecf20Sopenharmony_ci pr_err("BB_PG Reg Fail!!\n"); 3518c2ecf20Sopenharmony_ci return false; 3528c2ecf20Sopenharmony_ci } 3538c2ecf20Sopenharmony_ci rtstatus = 3548c2ecf20Sopenharmony_ci phy_config_bb_with_headerfile(hw, BASEBAND_CONFIG_AGC_TAB); 3558c2ecf20Sopenharmony_ci if (!rtstatus) { 3568c2ecf20Sopenharmony_ci pr_err("AGC Table Fail\n"); 3578c2ecf20Sopenharmony_ci return false; 3588c2ecf20Sopenharmony_ci } 3598c2ecf20Sopenharmony_ci rtlphy->cck_high_power = 3608c2ecf20Sopenharmony_ci (bool)(rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, 0x200)); 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_ci return true; 3638c2ecf20Sopenharmony_ci} 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_cistatic bool _rtl88e_phy_config_mac_with_headerfile(struct ieee80211_hw *hw) 3668c2ecf20Sopenharmony_ci{ 3678c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 3688c2ecf20Sopenharmony_ci u32 i; 3698c2ecf20Sopenharmony_ci u32 arraylength; 3708c2ecf20Sopenharmony_ci u32 *ptrarray; 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, "Read Rtl8188EMACPHY_Array\n"); 3738c2ecf20Sopenharmony_ci arraylength = RTL8188EEMAC_1T_ARRAYLEN; 3748c2ecf20Sopenharmony_ci ptrarray = RTL8188EEMAC_1T_ARRAY; 3758c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, 3768c2ecf20Sopenharmony_ci "Img:RTL8188EEMAC_1T_ARRAY LEN %d\n", arraylength); 3778c2ecf20Sopenharmony_ci for (i = 0; i < arraylength; i = i + 2) 3788c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, ptrarray[i], (u8)ptrarray[i + 1]); 3798c2ecf20Sopenharmony_ci return true; 3808c2ecf20Sopenharmony_ci} 3818c2ecf20Sopenharmony_ci 3828c2ecf20Sopenharmony_ci#define READ_NEXT_PAIR(v1, v2, i) \ 3838c2ecf20Sopenharmony_ci do { \ 3848c2ecf20Sopenharmony_ci i += 2; v1 = array_table[i]; \ 3858c2ecf20Sopenharmony_ci v2 = array_table[i+1]; \ 3868c2ecf20Sopenharmony_ci } while (0) 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_cistatic void handle_branch1(struct ieee80211_hw *hw, u16 arraylen, 3898c2ecf20Sopenharmony_ci u32 *array_table) 3908c2ecf20Sopenharmony_ci{ 3918c2ecf20Sopenharmony_ci u32 v1; 3928c2ecf20Sopenharmony_ci u32 v2; 3938c2ecf20Sopenharmony_ci int i; 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci for (i = 0; i < arraylen; i = i + 2) { 3968c2ecf20Sopenharmony_ci v1 = array_table[i]; 3978c2ecf20Sopenharmony_ci v2 = array_table[i+1]; 3988c2ecf20Sopenharmony_ci if (v1 < 0xcdcdcdcd) { 3998c2ecf20Sopenharmony_ci _rtl8188e_config_bb_reg(hw, v1, v2); 4008c2ecf20Sopenharmony_ci } else { /*This line is the start line of branch.*/ 4018c2ecf20Sopenharmony_ci /* to protect READ_NEXT_PAIR not overrun */ 4028c2ecf20Sopenharmony_ci if (i >= arraylen - 2) 4038c2ecf20Sopenharmony_ci break; 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ci if (!_rtl88e_check_condition(hw, array_table[i])) { 4068c2ecf20Sopenharmony_ci /*Discard the following (offset, data) pairs*/ 4078c2ecf20Sopenharmony_ci READ_NEXT_PAIR(v1, v2, i); 4088c2ecf20Sopenharmony_ci while (v2 != 0xDEAD && 4098c2ecf20Sopenharmony_ci v2 != 0xCDEF && 4108c2ecf20Sopenharmony_ci v2 != 0xCDCD && i < arraylen - 2) 4118c2ecf20Sopenharmony_ci READ_NEXT_PAIR(v1, v2, i); 4128c2ecf20Sopenharmony_ci i -= 2; /* prevent from for-loop += 2*/ 4138c2ecf20Sopenharmony_ci } else { /* Configure matched pairs and skip 4148c2ecf20Sopenharmony_ci * to end of if-else. 4158c2ecf20Sopenharmony_ci */ 4168c2ecf20Sopenharmony_ci READ_NEXT_PAIR(v1, v2, i); 4178c2ecf20Sopenharmony_ci while (v2 != 0xDEAD && 4188c2ecf20Sopenharmony_ci v2 != 0xCDEF && 4198c2ecf20Sopenharmony_ci v2 != 0xCDCD && i < arraylen - 2) { 4208c2ecf20Sopenharmony_ci _rtl8188e_config_bb_reg(hw, v1, v2); 4218c2ecf20Sopenharmony_ci READ_NEXT_PAIR(v1, v2, i); 4228c2ecf20Sopenharmony_ci } 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_ci while (v2 != 0xDEAD && i < arraylen - 2) 4258c2ecf20Sopenharmony_ci READ_NEXT_PAIR(v1, v2, i); 4268c2ecf20Sopenharmony_ci } 4278c2ecf20Sopenharmony_ci } 4288c2ecf20Sopenharmony_ci } 4298c2ecf20Sopenharmony_ci} 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_cistatic void handle_branch2(struct ieee80211_hw *hw, u16 arraylen, 4328c2ecf20Sopenharmony_ci u32 *array_table) 4338c2ecf20Sopenharmony_ci{ 4348c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 4358c2ecf20Sopenharmony_ci u32 v1; 4368c2ecf20Sopenharmony_ci u32 v2; 4378c2ecf20Sopenharmony_ci int i; 4388c2ecf20Sopenharmony_ci 4398c2ecf20Sopenharmony_ci for (i = 0; i < arraylen; i = i + 2) { 4408c2ecf20Sopenharmony_ci v1 = array_table[i]; 4418c2ecf20Sopenharmony_ci v2 = array_table[i+1]; 4428c2ecf20Sopenharmony_ci if (v1 < 0xCDCDCDCD) { 4438c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, array_table[i], MASKDWORD, 4448c2ecf20Sopenharmony_ci array_table[i + 1]); 4458c2ecf20Sopenharmony_ci udelay(1); 4468c2ecf20Sopenharmony_ci continue; 4478c2ecf20Sopenharmony_ci } else { /*This line is the start line of branch.*/ 4488c2ecf20Sopenharmony_ci /* to protect READ_NEXT_PAIR not overrun */ 4498c2ecf20Sopenharmony_ci if (i >= arraylen - 2) 4508c2ecf20Sopenharmony_ci break; 4518c2ecf20Sopenharmony_ci 4528c2ecf20Sopenharmony_ci if (!_rtl88e_check_condition(hw, array_table[i])) { 4538c2ecf20Sopenharmony_ci /*Discard the following (offset, data) pairs*/ 4548c2ecf20Sopenharmony_ci READ_NEXT_PAIR(v1, v2, i); 4558c2ecf20Sopenharmony_ci while (v2 != 0xDEAD && 4568c2ecf20Sopenharmony_ci v2 != 0xCDEF && 4578c2ecf20Sopenharmony_ci v2 != 0xCDCD && i < arraylen - 2) 4588c2ecf20Sopenharmony_ci READ_NEXT_PAIR(v1, v2, i); 4598c2ecf20Sopenharmony_ci i -= 2; /* prevent from for-loop += 2*/ 4608c2ecf20Sopenharmony_ci } else { /* Configure matched pairs and skip 4618c2ecf20Sopenharmony_ci * to end of if-else. 4628c2ecf20Sopenharmony_ci */ 4638c2ecf20Sopenharmony_ci READ_NEXT_PAIR(v1, v2, i); 4648c2ecf20Sopenharmony_ci while (v2 != 0xDEAD && 4658c2ecf20Sopenharmony_ci v2 != 0xCDEF && 4668c2ecf20Sopenharmony_ci v2 != 0xCDCD && i < arraylen - 2) { 4678c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, array_table[i], 4688c2ecf20Sopenharmony_ci MASKDWORD, 4698c2ecf20Sopenharmony_ci array_table[i + 1]); 4708c2ecf20Sopenharmony_ci udelay(1); 4718c2ecf20Sopenharmony_ci READ_NEXT_PAIR(v1, v2, i); 4728c2ecf20Sopenharmony_ci } 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ci while (v2 != 0xDEAD && i < arraylen - 2) 4758c2ecf20Sopenharmony_ci READ_NEXT_PAIR(v1, v2, i); 4768c2ecf20Sopenharmony_ci } 4778c2ecf20Sopenharmony_ci } 4788c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 4798c2ecf20Sopenharmony_ci "The agctab_array_table[0] is %x Rtl818EEPHY_REGArray[1] is %x\n", 4808c2ecf20Sopenharmony_ci array_table[i], array_table[i + 1]); 4818c2ecf20Sopenharmony_ci } 4828c2ecf20Sopenharmony_ci} 4838c2ecf20Sopenharmony_ci 4848c2ecf20Sopenharmony_cistatic bool phy_config_bb_with_headerfile(struct ieee80211_hw *hw, 4858c2ecf20Sopenharmony_ci u8 configtype) 4868c2ecf20Sopenharmony_ci{ 4878c2ecf20Sopenharmony_ci u32 *array_table; 4888c2ecf20Sopenharmony_ci u16 arraylen; 4898c2ecf20Sopenharmony_ci 4908c2ecf20Sopenharmony_ci if (configtype == BASEBAND_CONFIG_PHY_REG) { 4918c2ecf20Sopenharmony_ci arraylen = RTL8188EEPHY_REG_1TARRAYLEN; 4928c2ecf20Sopenharmony_ci array_table = RTL8188EEPHY_REG_1TARRAY; 4938c2ecf20Sopenharmony_ci handle_branch1(hw, arraylen, array_table); 4948c2ecf20Sopenharmony_ci } else if (configtype == BASEBAND_CONFIG_AGC_TAB) { 4958c2ecf20Sopenharmony_ci arraylen = RTL8188EEAGCTAB_1TARRAYLEN; 4968c2ecf20Sopenharmony_ci array_table = RTL8188EEAGCTAB_1TARRAY; 4978c2ecf20Sopenharmony_ci handle_branch2(hw, arraylen, array_table); 4988c2ecf20Sopenharmony_ci } 4998c2ecf20Sopenharmony_ci return true; 5008c2ecf20Sopenharmony_ci} 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_cistatic void store_pwrindex_rate_offset(struct ieee80211_hw *hw, 5038c2ecf20Sopenharmony_ci u32 regaddr, u32 bitmask, 5048c2ecf20Sopenharmony_ci u32 data) 5058c2ecf20Sopenharmony_ci{ 5068c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 5078c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 5088c2ecf20Sopenharmony_ci int count = rtlphy->pwrgroup_cnt; 5098c2ecf20Sopenharmony_ci 5108c2ecf20Sopenharmony_ci if (regaddr == RTXAGC_A_RATE18_06) { 5118c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][0] = data; 5128c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 5138c2ecf20Sopenharmony_ci "MCSTxPowerLevelOriginalOffset[%d][0] = 0x%x\n", 5148c2ecf20Sopenharmony_ci count, 5158c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][0]); 5168c2ecf20Sopenharmony_ci } 5178c2ecf20Sopenharmony_ci if (regaddr == RTXAGC_A_RATE54_24) { 5188c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][1] = data; 5198c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 5208c2ecf20Sopenharmony_ci "MCSTxPowerLevelOriginalOffset[%d][1] = 0x%x\n", 5218c2ecf20Sopenharmony_ci count, 5228c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][1]); 5238c2ecf20Sopenharmony_ci } 5248c2ecf20Sopenharmony_ci if (regaddr == RTXAGC_A_CCK1_MCS32) { 5258c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][6] = data; 5268c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 5278c2ecf20Sopenharmony_ci "MCSTxPowerLevelOriginalOffset[%d][6] = 0x%x\n", 5288c2ecf20Sopenharmony_ci count, 5298c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][6]); 5308c2ecf20Sopenharmony_ci } 5318c2ecf20Sopenharmony_ci if (regaddr == RTXAGC_B_CCK11_A_CCK2_11 && bitmask == 0xffffff00) { 5328c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][7] = data; 5338c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 5348c2ecf20Sopenharmony_ci "MCSTxPowerLevelOriginalOffset[%d][7] = 0x%x\n", 5358c2ecf20Sopenharmony_ci count, 5368c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][7]); 5378c2ecf20Sopenharmony_ci } 5388c2ecf20Sopenharmony_ci if (regaddr == RTXAGC_A_MCS03_MCS00) { 5398c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][2] = data; 5408c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 5418c2ecf20Sopenharmony_ci "MCSTxPowerLevelOriginalOffset[%d][2] = 0x%x\n", 5428c2ecf20Sopenharmony_ci count, 5438c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][2]); 5448c2ecf20Sopenharmony_ci } 5458c2ecf20Sopenharmony_ci if (regaddr == RTXAGC_A_MCS07_MCS04) { 5468c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][3] = data; 5478c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 5488c2ecf20Sopenharmony_ci "MCSTxPowerLevelOriginalOffset[%d][3] = 0x%x\n", 5498c2ecf20Sopenharmony_ci count, 5508c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][3]); 5518c2ecf20Sopenharmony_ci } 5528c2ecf20Sopenharmony_ci if (regaddr == RTXAGC_A_MCS11_MCS08) { 5538c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][4] = data; 5548c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 5558c2ecf20Sopenharmony_ci "MCSTxPowerLevelOriginalOffset[%d][4] = 0x%x\n", 5568c2ecf20Sopenharmony_ci count, 5578c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][4]); 5588c2ecf20Sopenharmony_ci } 5598c2ecf20Sopenharmony_ci if (regaddr == RTXAGC_A_MCS15_MCS12) { 5608c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][5] = data; 5618c2ecf20Sopenharmony_ci if (get_rf_type(rtlphy) == RF_1T1R) { 5628c2ecf20Sopenharmony_ci count++; 5638c2ecf20Sopenharmony_ci rtlphy->pwrgroup_cnt = count; 5648c2ecf20Sopenharmony_ci } 5658c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 5668c2ecf20Sopenharmony_ci "MCSTxPowerLevelOriginalOffset[%d][5] = 0x%x\n", 5678c2ecf20Sopenharmony_ci count, 5688c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][5]); 5698c2ecf20Sopenharmony_ci } 5708c2ecf20Sopenharmony_ci if (regaddr == RTXAGC_B_RATE18_06) { 5718c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][8] = data; 5728c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 5738c2ecf20Sopenharmony_ci "MCSTxPowerLevelOriginalOffset[%d][8] = 0x%x\n", 5748c2ecf20Sopenharmony_ci count, 5758c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][8]); 5768c2ecf20Sopenharmony_ci } 5778c2ecf20Sopenharmony_ci if (regaddr == RTXAGC_B_RATE54_24) { 5788c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][9] = data; 5798c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 5808c2ecf20Sopenharmony_ci "MCSTxPowerLevelOriginalOffset[%d][9] = 0x%x\n", 5818c2ecf20Sopenharmony_ci count, 5828c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][9]); 5838c2ecf20Sopenharmony_ci } 5848c2ecf20Sopenharmony_ci if (regaddr == RTXAGC_B_CCK1_55_MCS32) { 5858c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][14] = data; 5868c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 5878c2ecf20Sopenharmony_ci "MCSTxPowerLevelOriginalOffset[%d][14] = 0x%x\n", 5888c2ecf20Sopenharmony_ci count, 5898c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][14]); 5908c2ecf20Sopenharmony_ci } 5918c2ecf20Sopenharmony_ci if (regaddr == RTXAGC_B_CCK11_A_CCK2_11 && bitmask == 0x000000ff) { 5928c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][15] = data; 5938c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 5948c2ecf20Sopenharmony_ci "MCSTxPowerLevelOriginalOffset[%d][15] = 0x%x\n", 5958c2ecf20Sopenharmony_ci count, 5968c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][15]); 5978c2ecf20Sopenharmony_ci } 5988c2ecf20Sopenharmony_ci if (regaddr == RTXAGC_B_MCS03_MCS00) { 5998c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][10] = data; 6008c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 6018c2ecf20Sopenharmony_ci "MCSTxPowerLevelOriginalOffset[%d][10] = 0x%x\n", 6028c2ecf20Sopenharmony_ci count, 6038c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][10]); 6048c2ecf20Sopenharmony_ci } 6058c2ecf20Sopenharmony_ci if (regaddr == RTXAGC_B_MCS07_MCS04) { 6068c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][11] = data; 6078c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 6088c2ecf20Sopenharmony_ci "MCSTxPowerLevelOriginalOffset[%d][11] = 0x%x\n", 6098c2ecf20Sopenharmony_ci count, 6108c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][11]); 6118c2ecf20Sopenharmony_ci } 6128c2ecf20Sopenharmony_ci if (regaddr == RTXAGC_B_MCS11_MCS08) { 6138c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][12] = data; 6148c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 6158c2ecf20Sopenharmony_ci "MCSTxPowerLevelOriginalOffset[%d][12] = 0x%x\n", 6168c2ecf20Sopenharmony_ci count, 6178c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][12]); 6188c2ecf20Sopenharmony_ci } 6198c2ecf20Sopenharmony_ci if (regaddr == RTXAGC_B_MCS15_MCS12) { 6208c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][13] = data; 6218c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 6228c2ecf20Sopenharmony_ci "MCSTxPowerLevelOriginalOffset[%d][13] = 0x%x\n", 6238c2ecf20Sopenharmony_ci count, 6248c2ecf20Sopenharmony_ci rtlphy->mcs_txpwrlevel_origoffset[count][13]); 6258c2ecf20Sopenharmony_ci if (get_rf_type(rtlphy) != RF_1T1R) { 6268c2ecf20Sopenharmony_ci count++; 6278c2ecf20Sopenharmony_ci rtlphy->pwrgroup_cnt = count; 6288c2ecf20Sopenharmony_ci } 6298c2ecf20Sopenharmony_ci } 6308c2ecf20Sopenharmony_ci} 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_cistatic bool phy_config_bb_with_pghdr(struct ieee80211_hw *hw, u8 configtype) 6338c2ecf20Sopenharmony_ci{ 6348c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 6358c2ecf20Sopenharmony_ci int i; 6368c2ecf20Sopenharmony_ci u32 *phy_reg_page; 6378c2ecf20Sopenharmony_ci u16 phy_reg_page_len; 6388c2ecf20Sopenharmony_ci u32 v1 = 0, v2 = 0; 6398c2ecf20Sopenharmony_ci 6408c2ecf20Sopenharmony_ci phy_reg_page_len = RTL8188EEPHY_REG_ARRAY_PGLEN; 6418c2ecf20Sopenharmony_ci phy_reg_page = RTL8188EEPHY_REG_ARRAY_PG; 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_ci if (configtype == BASEBAND_CONFIG_PHY_REG) { 6448c2ecf20Sopenharmony_ci for (i = 0; i < phy_reg_page_len; i = i + 3) { 6458c2ecf20Sopenharmony_ci v1 = phy_reg_page[i]; 6468c2ecf20Sopenharmony_ci v2 = phy_reg_page[i+1]; 6478c2ecf20Sopenharmony_ci 6488c2ecf20Sopenharmony_ci if (v1 < 0xcdcdcdcd) { 6498c2ecf20Sopenharmony_ci if (phy_reg_page[i] == 0xfe) 6508c2ecf20Sopenharmony_ci mdelay(50); 6518c2ecf20Sopenharmony_ci else if (phy_reg_page[i] == 0xfd) 6528c2ecf20Sopenharmony_ci mdelay(5); 6538c2ecf20Sopenharmony_ci else if (phy_reg_page[i] == 0xfc) 6548c2ecf20Sopenharmony_ci mdelay(1); 6558c2ecf20Sopenharmony_ci else if (phy_reg_page[i] == 0xfb) 6568c2ecf20Sopenharmony_ci udelay(50); 6578c2ecf20Sopenharmony_ci else if (phy_reg_page[i] == 0xfa) 6588c2ecf20Sopenharmony_ci udelay(5); 6598c2ecf20Sopenharmony_ci else if (phy_reg_page[i] == 0xf9) 6608c2ecf20Sopenharmony_ci udelay(1); 6618c2ecf20Sopenharmony_ci 6628c2ecf20Sopenharmony_ci store_pwrindex_rate_offset(hw, phy_reg_page[i], 6638c2ecf20Sopenharmony_ci phy_reg_page[i + 1], 6648c2ecf20Sopenharmony_ci phy_reg_page[i + 2]); 6658c2ecf20Sopenharmony_ci continue; 6668c2ecf20Sopenharmony_ci } else { 6678c2ecf20Sopenharmony_ci if (!_rtl88e_check_condition(hw, 6688c2ecf20Sopenharmony_ci phy_reg_page[i])) { 6698c2ecf20Sopenharmony_ci /*don't need the hw_body*/ 6708c2ecf20Sopenharmony_ci i += 2; /* skip the pair of expression*/ 6718c2ecf20Sopenharmony_ci /* to protect 'i+1' 'i+2' not overrun */ 6728c2ecf20Sopenharmony_ci if (i >= phy_reg_page_len - 2) 6738c2ecf20Sopenharmony_ci break; 6748c2ecf20Sopenharmony_ci 6758c2ecf20Sopenharmony_ci v1 = phy_reg_page[i]; 6768c2ecf20Sopenharmony_ci v2 = phy_reg_page[i+1]; 6778c2ecf20Sopenharmony_ci while (v2 != 0xDEAD && 6788c2ecf20Sopenharmony_ci i < phy_reg_page_len - 5) { 6798c2ecf20Sopenharmony_ci i += 3; 6808c2ecf20Sopenharmony_ci v1 = phy_reg_page[i]; 6818c2ecf20Sopenharmony_ci v2 = phy_reg_page[i+1]; 6828c2ecf20Sopenharmony_ci } 6838c2ecf20Sopenharmony_ci } 6848c2ecf20Sopenharmony_ci } 6858c2ecf20Sopenharmony_ci } 6868c2ecf20Sopenharmony_ci } else { 6878c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_SEND, DBG_TRACE, 6888c2ecf20Sopenharmony_ci "configtype != BaseBand_Config_PHY_REG\n"); 6898c2ecf20Sopenharmony_ci } 6908c2ecf20Sopenharmony_ci return true; 6918c2ecf20Sopenharmony_ci} 6928c2ecf20Sopenharmony_ci 6938c2ecf20Sopenharmony_ci#define READ_NEXT_RF_PAIR(v1, v2, i) \ 6948c2ecf20Sopenharmony_cido { \ 6958c2ecf20Sopenharmony_ci i += 2; \ 6968c2ecf20Sopenharmony_ci v1 = radioa_array_table[i]; \ 6978c2ecf20Sopenharmony_ci v2 = radioa_array_table[i+1]; \ 6988c2ecf20Sopenharmony_ci} while (0) 6998c2ecf20Sopenharmony_ci 7008c2ecf20Sopenharmony_cistatic void process_path_a(struct ieee80211_hw *hw, 7018c2ecf20Sopenharmony_ci u16 radioa_arraylen, 7028c2ecf20Sopenharmony_ci u32 *radioa_array_table) 7038c2ecf20Sopenharmony_ci{ 7048c2ecf20Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 7058c2ecf20Sopenharmony_ci u32 v1, v2; 7068c2ecf20Sopenharmony_ci int i; 7078c2ecf20Sopenharmony_ci 7088c2ecf20Sopenharmony_ci for (i = 0; i < radioa_arraylen; i = i + 2) { 7098c2ecf20Sopenharmony_ci v1 = radioa_array_table[i]; 7108c2ecf20Sopenharmony_ci v2 = radioa_array_table[i+1]; 7118c2ecf20Sopenharmony_ci if (v1 < 0xcdcdcdcd) { 7128c2ecf20Sopenharmony_ci _rtl8188e_config_rf_radio_a(hw, v1, v2); 7138c2ecf20Sopenharmony_ci } else { /*This line is the start line of branch.*/ 7148c2ecf20Sopenharmony_ci /* to protect READ_NEXT_PAIR not overrun */ 7158c2ecf20Sopenharmony_ci if (i >= radioa_arraylen - 2) 7168c2ecf20Sopenharmony_ci break; 7178c2ecf20Sopenharmony_ci 7188c2ecf20Sopenharmony_ci if (!_rtl88e_check_condition(hw, radioa_array_table[i])) { 7198c2ecf20Sopenharmony_ci /*Discard the following (offset, data) pairs*/ 7208c2ecf20Sopenharmony_ci READ_NEXT_RF_PAIR(v1, v2, i); 7218c2ecf20Sopenharmony_ci while (v2 != 0xDEAD && 7228c2ecf20Sopenharmony_ci v2 != 0xCDEF && 7238c2ecf20Sopenharmony_ci v2 != 0xCDCD && 7248c2ecf20Sopenharmony_ci i < radioa_arraylen - 2) { 7258c2ecf20Sopenharmony_ci READ_NEXT_RF_PAIR(v1, v2, i); 7268c2ecf20Sopenharmony_ci } 7278c2ecf20Sopenharmony_ci i -= 2; /* prevent from for-loop += 2*/ 7288c2ecf20Sopenharmony_ci } else { /* Configure matched pairs and 7298c2ecf20Sopenharmony_ci * skip to end of if-else. 7308c2ecf20Sopenharmony_ci */ 7318c2ecf20Sopenharmony_ci READ_NEXT_RF_PAIR(v1, v2, i); 7328c2ecf20Sopenharmony_ci while (v2 != 0xDEAD && 7338c2ecf20Sopenharmony_ci v2 != 0xCDEF && 7348c2ecf20Sopenharmony_ci v2 != 0xCDCD && 7358c2ecf20Sopenharmony_ci i < radioa_arraylen - 2) { 7368c2ecf20Sopenharmony_ci _rtl8188e_config_rf_radio_a(hw, v1, v2); 7378c2ecf20Sopenharmony_ci READ_NEXT_RF_PAIR(v1, v2, i); 7388c2ecf20Sopenharmony_ci } 7398c2ecf20Sopenharmony_ci 7408c2ecf20Sopenharmony_ci while (v2 != 0xDEAD && 7418c2ecf20Sopenharmony_ci i < radioa_arraylen - 2) 7428c2ecf20Sopenharmony_ci READ_NEXT_RF_PAIR(v1, v2, i); 7438c2ecf20Sopenharmony_ci } 7448c2ecf20Sopenharmony_ci } 7458c2ecf20Sopenharmony_ci } 7468c2ecf20Sopenharmony_ci 7478c2ecf20Sopenharmony_ci if (rtlhal->oem_id == RT_CID_819X_HP) 7488c2ecf20Sopenharmony_ci _rtl8188e_config_rf_radio_a(hw, 0x52, 0x7E4BD); 7498c2ecf20Sopenharmony_ci} 7508c2ecf20Sopenharmony_ci 7518c2ecf20Sopenharmony_cibool rtl88e_phy_config_rf_with_headerfile(struct ieee80211_hw *hw, 7528c2ecf20Sopenharmony_ci enum radio_path rfpath) 7538c2ecf20Sopenharmony_ci{ 7548c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 7558c2ecf20Sopenharmony_ci u32 *radioa_array_table; 7568c2ecf20Sopenharmony_ci u16 radioa_arraylen; 7578c2ecf20Sopenharmony_ci 7588c2ecf20Sopenharmony_ci radioa_arraylen = RTL8188EE_RADIOA_1TARRAYLEN; 7598c2ecf20Sopenharmony_ci radioa_array_table = RTL8188EE_RADIOA_1TARRAY; 7608c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, 7618c2ecf20Sopenharmony_ci "Radio_A:RTL8188EE_RADIOA_1TARRAY %d\n", radioa_arraylen); 7628c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, "Radio No %x\n", rfpath); 7638c2ecf20Sopenharmony_ci switch (rfpath) { 7648c2ecf20Sopenharmony_ci case RF90_PATH_A: 7658c2ecf20Sopenharmony_ci process_path_a(hw, radioa_arraylen, radioa_array_table); 7668c2ecf20Sopenharmony_ci break; 7678c2ecf20Sopenharmony_ci case RF90_PATH_B: 7688c2ecf20Sopenharmony_ci case RF90_PATH_C: 7698c2ecf20Sopenharmony_ci case RF90_PATH_D: 7708c2ecf20Sopenharmony_ci break; 7718c2ecf20Sopenharmony_ci } 7728c2ecf20Sopenharmony_ci return true; 7738c2ecf20Sopenharmony_ci} 7748c2ecf20Sopenharmony_ci 7758c2ecf20Sopenharmony_civoid rtl88e_phy_get_hw_reg_originalvalue(struct ieee80211_hw *hw) 7768c2ecf20Sopenharmony_ci{ 7778c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 7788c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 7798c2ecf20Sopenharmony_ci 7808c2ecf20Sopenharmony_ci rtlphy->default_initialgain[0] = 7818c2ecf20Sopenharmony_ci (u8)rtl_get_bbreg(hw, ROFDM0_XAAGCCORE1, MASKBYTE0); 7828c2ecf20Sopenharmony_ci rtlphy->default_initialgain[1] = 7838c2ecf20Sopenharmony_ci (u8)rtl_get_bbreg(hw, ROFDM0_XBAGCCORE1, MASKBYTE0); 7848c2ecf20Sopenharmony_ci rtlphy->default_initialgain[2] = 7858c2ecf20Sopenharmony_ci (u8)rtl_get_bbreg(hw, ROFDM0_XCAGCCORE1, MASKBYTE0); 7868c2ecf20Sopenharmony_ci rtlphy->default_initialgain[3] = 7878c2ecf20Sopenharmony_ci (u8)rtl_get_bbreg(hw, ROFDM0_XDAGCCORE1, MASKBYTE0); 7888c2ecf20Sopenharmony_ci 7898c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 7908c2ecf20Sopenharmony_ci "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x\n", 7918c2ecf20Sopenharmony_ci rtlphy->default_initialgain[0], 7928c2ecf20Sopenharmony_ci rtlphy->default_initialgain[1], 7938c2ecf20Sopenharmony_ci rtlphy->default_initialgain[2], 7948c2ecf20Sopenharmony_ci rtlphy->default_initialgain[3]); 7958c2ecf20Sopenharmony_ci 7968c2ecf20Sopenharmony_ci rtlphy->framesync = (u8)rtl_get_bbreg(hw, ROFDM0_RXDETECTOR3, 7978c2ecf20Sopenharmony_ci MASKBYTE0); 7988c2ecf20Sopenharmony_ci rtlphy->framesync_c34 = rtl_get_bbreg(hw, ROFDM0_RXDETECTOR2, 7998c2ecf20Sopenharmony_ci MASKDWORD); 8008c2ecf20Sopenharmony_ci 8018c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 8028c2ecf20Sopenharmony_ci "Default framesync (0x%x) = 0x%x\n", 8038c2ecf20Sopenharmony_ci ROFDM0_RXDETECTOR3, rtlphy->framesync); 8048c2ecf20Sopenharmony_ci} 8058c2ecf20Sopenharmony_ci 8068c2ecf20Sopenharmony_cistatic void _rtl88e_phy_init_bb_rf_register_definition(struct ieee80211_hw *hw) 8078c2ecf20Sopenharmony_ci{ 8088c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 8098c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 8108c2ecf20Sopenharmony_ci 8118c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rfintfs = RFPGA0_XAB_RFINTERFACESW; 8128c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rfintfs = RFPGA0_XAB_RFINTERFACESW; 8138c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_C].rfintfs = RFPGA0_XCD_RFINTERFACESW; 8148c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_D].rfintfs = RFPGA0_XCD_RFINTERFACESW; 8158c2ecf20Sopenharmony_ci 8168c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rfintfi = RFPGA0_XAB_RFINTERFACERB; 8178c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rfintfi = RFPGA0_XAB_RFINTERFACERB; 8188c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_C].rfintfi = RFPGA0_XCD_RFINTERFACERB; 8198c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_D].rfintfi = RFPGA0_XCD_RFINTERFACERB; 8208c2ecf20Sopenharmony_ci 8218c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rfintfo = RFPGA0_XA_RFINTERFACEOE; 8228c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rfintfo = RFPGA0_XB_RFINTERFACEOE; 8238c2ecf20Sopenharmony_ci 8248c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rfintfe = RFPGA0_XA_RFINTERFACEOE; 8258c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rfintfe = RFPGA0_XB_RFINTERFACEOE; 8268c2ecf20Sopenharmony_ci 8278c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rf3wire_offset = 8288c2ecf20Sopenharmony_ci RFPGA0_XA_LSSIPARAMETER; 8298c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rf3wire_offset = 8308c2ecf20Sopenharmony_ci RFPGA0_XB_LSSIPARAMETER; 8318c2ecf20Sopenharmony_ci 8328c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rflssi_select = RFPGA0_XAB_RFPARAMETER; 8338c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rflssi_select = RFPGA0_XAB_RFPARAMETER; 8348c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_C].rflssi_select = RFPGA0_XCD_RFPARAMETER; 8358c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_D].rflssi_select = RFPGA0_XCD_RFPARAMETER; 8368c2ecf20Sopenharmony_ci 8378c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rftxgain_stage = RFPGA0_TXGAINSTAGE; 8388c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rftxgain_stage = RFPGA0_TXGAINSTAGE; 8398c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_C].rftxgain_stage = RFPGA0_TXGAINSTAGE; 8408c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_D].rftxgain_stage = RFPGA0_TXGAINSTAGE; 8418c2ecf20Sopenharmony_ci 8428c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rfhssi_para1 = RFPGA0_XA_HSSIPARAMETER1; 8438c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rfhssi_para1 = RFPGA0_XB_HSSIPARAMETER1; 8448c2ecf20Sopenharmony_ci 8458c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rfhssi_para2 = RFPGA0_XA_HSSIPARAMETER2; 8468c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rfhssi_para2 = RFPGA0_XB_HSSIPARAMETER2; 8478c2ecf20Sopenharmony_ci 8488c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rfsw_ctrl = 8498c2ecf20Sopenharmony_ci RFPGA0_XAB_SWITCHCONTROL; 8508c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rfsw_ctrl = 8518c2ecf20Sopenharmony_ci RFPGA0_XAB_SWITCHCONTROL; 8528c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_C].rfsw_ctrl = 8538c2ecf20Sopenharmony_ci RFPGA0_XCD_SWITCHCONTROL; 8548c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_D].rfsw_ctrl = 8558c2ecf20Sopenharmony_ci RFPGA0_XCD_SWITCHCONTROL; 8568c2ecf20Sopenharmony_ci 8578c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rfagc_control1 = ROFDM0_XAAGCCORE1; 8588c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rfagc_control1 = ROFDM0_XBAGCCORE1; 8598c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_C].rfagc_control1 = ROFDM0_XCAGCCORE1; 8608c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_D].rfagc_control1 = ROFDM0_XDAGCCORE1; 8618c2ecf20Sopenharmony_ci 8628c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rfagc_control2 = ROFDM0_XAAGCCORE2; 8638c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rfagc_control2 = ROFDM0_XBAGCCORE2; 8648c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_C].rfagc_control2 = ROFDM0_XCAGCCORE2; 8658c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_D].rfagc_control2 = ROFDM0_XDAGCCORE2; 8668c2ecf20Sopenharmony_ci 8678c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rfrxiq_imbal = ROFDM0_XARXIQIMBALANCE; 8688c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rfrxiq_imbal = ROFDM0_XBRXIQIMBALANCE; 8698c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_C].rfrxiq_imbal = ROFDM0_XCRXIQIMBANLANCE; 8708c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_D].rfrxiq_imbal = ROFDM0_XDRXIQIMBALANCE; 8718c2ecf20Sopenharmony_ci 8728c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rfrx_afe = ROFDM0_XARXAFE; 8738c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rfrx_afe = ROFDM0_XBRXAFE; 8748c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_C].rfrx_afe = ROFDM0_XCRXAFE; 8758c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_D].rfrx_afe = ROFDM0_XDRXAFE; 8768c2ecf20Sopenharmony_ci 8778c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rftxiq_imbal = ROFDM0_XATXIQIMBALANCE; 8788c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rftxiq_imbal = ROFDM0_XBTXIQIMBALANCE; 8798c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_C].rftxiq_imbal = ROFDM0_XCTXIQIMBALANCE; 8808c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_D].rftxiq_imbal = ROFDM0_XDTXIQIMBALANCE; 8818c2ecf20Sopenharmony_ci 8828c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rftx_afe = ROFDM0_XATXAFE; 8838c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rftx_afe = ROFDM0_XBTXAFE; 8848c2ecf20Sopenharmony_ci 8858c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rf_rb = RFPGA0_XA_LSSIREADBACK; 8868c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rf_rb = RFPGA0_XB_LSSIREADBACK; 8878c2ecf20Sopenharmony_ci 8888c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rf_rbpi = TRANSCEIVEA_HSPI_READBACK; 8898c2ecf20Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rf_rbpi = TRANSCEIVEB_HSPI_READBACK; 8908c2ecf20Sopenharmony_ci} 8918c2ecf20Sopenharmony_ci 8928c2ecf20Sopenharmony_civoid rtl88e_phy_get_txpower_level(struct ieee80211_hw *hw, long *powerlevel) 8938c2ecf20Sopenharmony_ci{ 8948c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 8958c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 8968c2ecf20Sopenharmony_ci u8 txpwr_level; 8978c2ecf20Sopenharmony_ci long txpwr_dbm; 8988c2ecf20Sopenharmony_ci 8998c2ecf20Sopenharmony_ci txpwr_level = rtlphy->cur_cck_txpwridx; 9008c2ecf20Sopenharmony_ci txpwr_dbm = _rtl88e_phy_txpwr_idx_to_dbm(hw, 9018c2ecf20Sopenharmony_ci WIRELESS_MODE_B, txpwr_level); 9028c2ecf20Sopenharmony_ci txpwr_level = rtlphy->cur_ofdm24g_txpwridx; 9038c2ecf20Sopenharmony_ci if (_rtl88e_phy_txpwr_idx_to_dbm(hw, 9048c2ecf20Sopenharmony_ci WIRELESS_MODE_G, 9058c2ecf20Sopenharmony_ci txpwr_level) > txpwr_dbm) 9068c2ecf20Sopenharmony_ci txpwr_dbm = 9078c2ecf20Sopenharmony_ci _rtl88e_phy_txpwr_idx_to_dbm(hw, WIRELESS_MODE_G, 9088c2ecf20Sopenharmony_ci txpwr_level); 9098c2ecf20Sopenharmony_ci txpwr_level = rtlphy->cur_ofdm24g_txpwridx; 9108c2ecf20Sopenharmony_ci if (_rtl88e_phy_txpwr_idx_to_dbm(hw, 9118c2ecf20Sopenharmony_ci WIRELESS_MODE_N_24G, 9128c2ecf20Sopenharmony_ci txpwr_level) > txpwr_dbm) 9138c2ecf20Sopenharmony_ci txpwr_dbm = 9148c2ecf20Sopenharmony_ci _rtl88e_phy_txpwr_idx_to_dbm(hw, WIRELESS_MODE_N_24G, 9158c2ecf20Sopenharmony_ci txpwr_level); 9168c2ecf20Sopenharmony_ci *powerlevel = txpwr_dbm; 9178c2ecf20Sopenharmony_ci} 9188c2ecf20Sopenharmony_ci 9198c2ecf20Sopenharmony_cistatic void handle_path_a(struct rtl_efuse *rtlefuse, u8 index, 9208c2ecf20Sopenharmony_ci u8 *cckpowerlevel, u8 *ofdmpowerlevel, 9218c2ecf20Sopenharmony_ci u8 *bw20powerlevel, u8 *bw40powerlevel) 9228c2ecf20Sopenharmony_ci{ 9238c2ecf20Sopenharmony_ci cckpowerlevel[RF90_PATH_A] = 9248c2ecf20Sopenharmony_ci rtlefuse->txpwrlevel_cck[RF90_PATH_A][index]; 9258c2ecf20Sopenharmony_ci /*-8~7 */ 9268c2ecf20Sopenharmony_ci if (rtlefuse->txpwr_ht20diff[RF90_PATH_A][index] > 0x0f) 9278c2ecf20Sopenharmony_ci bw20powerlevel[RF90_PATH_A] = 9288c2ecf20Sopenharmony_ci rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_A][index] - 9298c2ecf20Sopenharmony_ci (~(rtlefuse->txpwr_ht20diff[RF90_PATH_A][index]) + 1); 9308c2ecf20Sopenharmony_ci else 9318c2ecf20Sopenharmony_ci bw20powerlevel[RF90_PATH_A] = 9328c2ecf20Sopenharmony_ci rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_A][index] + 9338c2ecf20Sopenharmony_ci rtlefuse->txpwr_ht20diff[RF90_PATH_A][index]; 9348c2ecf20Sopenharmony_ci if (rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][index] > 0xf) 9358c2ecf20Sopenharmony_ci ofdmpowerlevel[RF90_PATH_A] = 9368c2ecf20Sopenharmony_ci rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_A][index] - 9378c2ecf20Sopenharmony_ci (~(rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][index])+1); 9388c2ecf20Sopenharmony_ci else 9398c2ecf20Sopenharmony_ci ofdmpowerlevel[RF90_PATH_A] = 9408c2ecf20Sopenharmony_ci rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_A][index] + 9418c2ecf20Sopenharmony_ci rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][index]; 9428c2ecf20Sopenharmony_ci bw40powerlevel[RF90_PATH_A] = 9438c2ecf20Sopenharmony_ci rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_A][index]; 9448c2ecf20Sopenharmony_ci} 9458c2ecf20Sopenharmony_ci 9468c2ecf20Sopenharmony_cistatic void _rtl88e_get_txpower_index(struct ieee80211_hw *hw, u8 channel, 9478c2ecf20Sopenharmony_ci u8 *cckpowerlevel, u8 *ofdmpowerlevel, 9488c2ecf20Sopenharmony_ci u8 *bw20powerlevel, u8 *bw40powerlevel) 9498c2ecf20Sopenharmony_ci{ 9508c2ecf20Sopenharmony_ci struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 9518c2ecf20Sopenharmony_ci u8 index = (channel - 1); 9528c2ecf20Sopenharmony_ci u8 rf_path = 0; 9538c2ecf20Sopenharmony_ci 9548c2ecf20Sopenharmony_ci for (rf_path = 0; rf_path < 2; rf_path++) { 9558c2ecf20Sopenharmony_ci if (rf_path == RF90_PATH_A) { 9568c2ecf20Sopenharmony_ci handle_path_a(rtlefuse, index, cckpowerlevel, 9578c2ecf20Sopenharmony_ci ofdmpowerlevel, bw20powerlevel, 9588c2ecf20Sopenharmony_ci bw40powerlevel); 9598c2ecf20Sopenharmony_ci } else if (rf_path == RF90_PATH_B) { 9608c2ecf20Sopenharmony_ci cckpowerlevel[RF90_PATH_B] = 9618c2ecf20Sopenharmony_ci rtlefuse->txpwrlevel_cck[RF90_PATH_B][index]; 9628c2ecf20Sopenharmony_ci bw20powerlevel[RF90_PATH_B] = 9638c2ecf20Sopenharmony_ci rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_B][index] + 9648c2ecf20Sopenharmony_ci rtlefuse->txpwr_ht20diff[RF90_PATH_B][index]; 9658c2ecf20Sopenharmony_ci ofdmpowerlevel[RF90_PATH_B] = 9668c2ecf20Sopenharmony_ci rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_B][index] + 9678c2ecf20Sopenharmony_ci rtlefuse->txpwr_legacyhtdiff[RF90_PATH_B][index]; 9688c2ecf20Sopenharmony_ci bw40powerlevel[RF90_PATH_B] = 9698c2ecf20Sopenharmony_ci rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_B][index]; 9708c2ecf20Sopenharmony_ci } 9718c2ecf20Sopenharmony_ci } 9728c2ecf20Sopenharmony_ci 9738c2ecf20Sopenharmony_ci} 9748c2ecf20Sopenharmony_ci 9758c2ecf20Sopenharmony_cistatic void _rtl88e_ccxpower_index_check(struct ieee80211_hw *hw, 9768c2ecf20Sopenharmony_ci u8 channel, u8 *cckpowerlevel, 9778c2ecf20Sopenharmony_ci u8 *ofdmpowerlevel, u8 *bw20powerlevel, 9788c2ecf20Sopenharmony_ci u8 *bw40powerlevel) 9798c2ecf20Sopenharmony_ci{ 9808c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 9818c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 9828c2ecf20Sopenharmony_ci 9838c2ecf20Sopenharmony_ci rtlphy->cur_cck_txpwridx = cckpowerlevel[0]; 9848c2ecf20Sopenharmony_ci rtlphy->cur_ofdm24g_txpwridx = ofdmpowerlevel[0]; 9858c2ecf20Sopenharmony_ci rtlphy->cur_bw20_txpwridx = bw20powerlevel[0]; 9868c2ecf20Sopenharmony_ci rtlphy->cur_bw40_txpwridx = bw40powerlevel[0]; 9878c2ecf20Sopenharmony_ci 9888c2ecf20Sopenharmony_ci} 9898c2ecf20Sopenharmony_ci 9908c2ecf20Sopenharmony_civoid rtl88e_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel) 9918c2ecf20Sopenharmony_ci{ 9928c2ecf20Sopenharmony_ci struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 9938c2ecf20Sopenharmony_ci u8 cckpowerlevel[MAX_TX_COUNT] = {0}; 9948c2ecf20Sopenharmony_ci u8 ofdmpowerlevel[MAX_TX_COUNT] = {0}; 9958c2ecf20Sopenharmony_ci u8 bw20powerlevel[MAX_TX_COUNT] = {0}; 9968c2ecf20Sopenharmony_ci u8 bw40powerlevel[MAX_TX_COUNT] = {0}; 9978c2ecf20Sopenharmony_ci 9988c2ecf20Sopenharmony_ci if (!rtlefuse->txpwr_fromeprom) 9998c2ecf20Sopenharmony_ci return; 10008c2ecf20Sopenharmony_ci _rtl88e_get_txpower_index(hw, channel, 10018c2ecf20Sopenharmony_ci &cckpowerlevel[0], &ofdmpowerlevel[0], 10028c2ecf20Sopenharmony_ci &bw20powerlevel[0], &bw40powerlevel[0]); 10038c2ecf20Sopenharmony_ci _rtl88e_ccxpower_index_check(hw, channel, 10048c2ecf20Sopenharmony_ci &cckpowerlevel[0], &ofdmpowerlevel[0], 10058c2ecf20Sopenharmony_ci &bw20powerlevel[0], &bw40powerlevel[0]); 10068c2ecf20Sopenharmony_ci rtl88e_phy_rf6052_set_cck_txpower(hw, &cckpowerlevel[0]); 10078c2ecf20Sopenharmony_ci rtl88e_phy_rf6052_set_ofdm_txpower(hw, &ofdmpowerlevel[0], 10088c2ecf20Sopenharmony_ci &bw20powerlevel[0], 10098c2ecf20Sopenharmony_ci &bw40powerlevel[0], channel); 10108c2ecf20Sopenharmony_ci} 10118c2ecf20Sopenharmony_ci 10128c2ecf20Sopenharmony_cistatic long _rtl88e_phy_txpwr_idx_to_dbm(struct ieee80211_hw *hw, 10138c2ecf20Sopenharmony_ci enum wireless_mode wirelessmode, 10148c2ecf20Sopenharmony_ci u8 txpwridx) 10158c2ecf20Sopenharmony_ci{ 10168c2ecf20Sopenharmony_ci long offset; 10178c2ecf20Sopenharmony_ci long pwrout_dbm; 10188c2ecf20Sopenharmony_ci 10198c2ecf20Sopenharmony_ci switch (wirelessmode) { 10208c2ecf20Sopenharmony_ci case WIRELESS_MODE_B: 10218c2ecf20Sopenharmony_ci offset = -7; 10228c2ecf20Sopenharmony_ci break; 10238c2ecf20Sopenharmony_ci case WIRELESS_MODE_G: 10248c2ecf20Sopenharmony_ci case WIRELESS_MODE_N_24G: 10258c2ecf20Sopenharmony_ci offset = -8; 10268c2ecf20Sopenharmony_ci break; 10278c2ecf20Sopenharmony_ci default: 10288c2ecf20Sopenharmony_ci offset = -8; 10298c2ecf20Sopenharmony_ci break; 10308c2ecf20Sopenharmony_ci } 10318c2ecf20Sopenharmony_ci pwrout_dbm = txpwridx / 2 + offset; 10328c2ecf20Sopenharmony_ci return pwrout_dbm; 10338c2ecf20Sopenharmony_ci} 10348c2ecf20Sopenharmony_ci 10358c2ecf20Sopenharmony_civoid rtl88e_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation) 10368c2ecf20Sopenharmony_ci{ 10378c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 10388c2ecf20Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 10398c2ecf20Sopenharmony_ci enum io_type iotype; 10408c2ecf20Sopenharmony_ci 10418c2ecf20Sopenharmony_ci if (!is_hal_stop(rtlhal)) { 10428c2ecf20Sopenharmony_ci switch (operation) { 10438c2ecf20Sopenharmony_ci case SCAN_OPT_BACKUP_BAND0: 10448c2ecf20Sopenharmony_ci iotype = IO_CMD_PAUSE_BAND0_DM_BY_SCAN; 10458c2ecf20Sopenharmony_ci rtlpriv->cfg->ops->set_hw_reg(hw, 10468c2ecf20Sopenharmony_ci HW_VAR_IO_CMD, 10478c2ecf20Sopenharmony_ci (u8 *)&iotype); 10488c2ecf20Sopenharmony_ci 10498c2ecf20Sopenharmony_ci break; 10508c2ecf20Sopenharmony_ci case SCAN_OPT_RESTORE: 10518c2ecf20Sopenharmony_ci iotype = IO_CMD_RESUME_DM_BY_SCAN; 10528c2ecf20Sopenharmony_ci rtlpriv->cfg->ops->set_hw_reg(hw, 10538c2ecf20Sopenharmony_ci HW_VAR_IO_CMD, 10548c2ecf20Sopenharmony_ci (u8 *)&iotype); 10558c2ecf20Sopenharmony_ci break; 10568c2ecf20Sopenharmony_ci default: 10578c2ecf20Sopenharmony_ci pr_err("Unknown Scan Backup operation.\n"); 10588c2ecf20Sopenharmony_ci break; 10598c2ecf20Sopenharmony_ci } 10608c2ecf20Sopenharmony_ci } 10618c2ecf20Sopenharmony_ci} 10628c2ecf20Sopenharmony_ci 10638c2ecf20Sopenharmony_civoid rtl88e_phy_set_bw_mode_callback(struct ieee80211_hw *hw) 10648c2ecf20Sopenharmony_ci{ 10658c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 10668c2ecf20Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 10678c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 10688c2ecf20Sopenharmony_ci struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 10698c2ecf20Sopenharmony_ci u8 reg_bw_opmode; 10708c2ecf20Sopenharmony_ci u8 reg_prsr_rsc; 10718c2ecf20Sopenharmony_ci 10728c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_SCAN, DBG_TRACE, 10738c2ecf20Sopenharmony_ci "Switch to %s bandwidth\n", 10748c2ecf20Sopenharmony_ci rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20 ? 10758c2ecf20Sopenharmony_ci "20MHz" : "40MHz"); 10768c2ecf20Sopenharmony_ci 10778c2ecf20Sopenharmony_ci if (is_hal_stop(rtlhal)) { 10788c2ecf20Sopenharmony_ci rtlphy->set_bwmode_inprogress = false; 10798c2ecf20Sopenharmony_ci return; 10808c2ecf20Sopenharmony_ci } 10818c2ecf20Sopenharmony_ci 10828c2ecf20Sopenharmony_ci reg_bw_opmode = rtl_read_byte(rtlpriv, REG_BWOPMODE); 10838c2ecf20Sopenharmony_ci reg_prsr_rsc = rtl_read_byte(rtlpriv, REG_RRSR + 2); 10848c2ecf20Sopenharmony_ci 10858c2ecf20Sopenharmony_ci switch (rtlphy->current_chan_bw) { 10868c2ecf20Sopenharmony_ci case HT_CHANNEL_WIDTH_20: 10878c2ecf20Sopenharmony_ci reg_bw_opmode |= BW_OPMODE_20MHZ; 10888c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode); 10898c2ecf20Sopenharmony_ci break; 10908c2ecf20Sopenharmony_ci case HT_CHANNEL_WIDTH_20_40: 10918c2ecf20Sopenharmony_ci reg_bw_opmode &= ~BW_OPMODE_20MHZ; 10928c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode); 10938c2ecf20Sopenharmony_ci reg_prsr_rsc = 10948c2ecf20Sopenharmony_ci (reg_prsr_rsc & 0x90) | (mac->cur_40_prime_sc << 5); 10958c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, REG_RRSR + 2, reg_prsr_rsc); 10968c2ecf20Sopenharmony_ci break; 10978c2ecf20Sopenharmony_ci default: 10988c2ecf20Sopenharmony_ci pr_err("unknown bandwidth: %#X\n", 10998c2ecf20Sopenharmony_ci rtlphy->current_chan_bw); 11008c2ecf20Sopenharmony_ci break; 11018c2ecf20Sopenharmony_ci } 11028c2ecf20Sopenharmony_ci 11038c2ecf20Sopenharmony_ci switch (rtlphy->current_chan_bw) { 11048c2ecf20Sopenharmony_ci case HT_CHANNEL_WIDTH_20: 11058c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_RFMOD, BRFMOD, 0x0); 11068c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RFPGA1_RFMOD, BRFMOD, 0x0); 11078c2ecf20Sopenharmony_ci /* rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 1);*/ 11088c2ecf20Sopenharmony_ci break; 11098c2ecf20Sopenharmony_ci case HT_CHANNEL_WIDTH_20_40: 11108c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_RFMOD, BRFMOD, 0x1); 11118c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RFPGA1_RFMOD, BRFMOD, 0x1); 11128c2ecf20Sopenharmony_ci 11138c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RCCK0_SYSTEM, BCCK_SIDEBAND, 11148c2ecf20Sopenharmony_ci (mac->cur_40_prime_sc >> 1)); 11158c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, ROFDM1_LSTF, 0xC00, mac->cur_40_prime_sc); 11168c2ecf20Sopenharmony_ci /*rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 0);*/ 11178c2ecf20Sopenharmony_ci 11188c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0x818, (BIT(26) | BIT(27)), 11198c2ecf20Sopenharmony_ci (mac->cur_40_prime_sc == 11208c2ecf20Sopenharmony_ci HAL_PRIME_CHNL_OFFSET_LOWER) ? 2 : 1); 11218c2ecf20Sopenharmony_ci break; 11228c2ecf20Sopenharmony_ci default: 11238c2ecf20Sopenharmony_ci pr_err("unknown bandwidth: %#X\n", 11248c2ecf20Sopenharmony_ci rtlphy->current_chan_bw); 11258c2ecf20Sopenharmony_ci break; 11268c2ecf20Sopenharmony_ci } 11278c2ecf20Sopenharmony_ci rtl88e_phy_rf6052_set_bandwidth(hw, rtlphy->current_chan_bw); 11288c2ecf20Sopenharmony_ci rtlphy->set_bwmode_inprogress = false; 11298c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_SCAN, DBG_LOUD, "\n"); 11308c2ecf20Sopenharmony_ci} 11318c2ecf20Sopenharmony_ci 11328c2ecf20Sopenharmony_civoid rtl88e_phy_set_bw_mode(struct ieee80211_hw *hw, 11338c2ecf20Sopenharmony_ci enum nl80211_channel_type ch_type) 11348c2ecf20Sopenharmony_ci{ 11358c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 11368c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 11378c2ecf20Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 11388c2ecf20Sopenharmony_ci u8 tmp_bw = rtlphy->current_chan_bw; 11398c2ecf20Sopenharmony_ci 11408c2ecf20Sopenharmony_ci if (rtlphy->set_bwmode_inprogress) 11418c2ecf20Sopenharmony_ci return; 11428c2ecf20Sopenharmony_ci rtlphy->set_bwmode_inprogress = true; 11438c2ecf20Sopenharmony_ci if ((!is_hal_stop(rtlhal)) && !(RT_CANNOT_IO(hw))) { 11448c2ecf20Sopenharmony_ci rtl88e_phy_set_bw_mode_callback(hw); 11458c2ecf20Sopenharmony_ci } else { 11468c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_ERR, DBG_WARNING, 11478c2ecf20Sopenharmony_ci "false driver sleep or unload\n"); 11488c2ecf20Sopenharmony_ci rtlphy->set_bwmode_inprogress = false; 11498c2ecf20Sopenharmony_ci rtlphy->current_chan_bw = tmp_bw; 11508c2ecf20Sopenharmony_ci } 11518c2ecf20Sopenharmony_ci} 11528c2ecf20Sopenharmony_ci 11538c2ecf20Sopenharmony_civoid rtl88e_phy_sw_chnl_callback(struct ieee80211_hw *hw) 11548c2ecf20Sopenharmony_ci{ 11558c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 11568c2ecf20Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 11578c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 11588c2ecf20Sopenharmony_ci u32 delay; 11598c2ecf20Sopenharmony_ci 11608c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_SCAN, DBG_TRACE, 11618c2ecf20Sopenharmony_ci "switch to channel%d\n", rtlphy->current_channel); 11628c2ecf20Sopenharmony_ci if (is_hal_stop(rtlhal)) 11638c2ecf20Sopenharmony_ci return; 11648c2ecf20Sopenharmony_ci do { 11658c2ecf20Sopenharmony_ci if (!rtlphy->sw_chnl_inprogress) 11668c2ecf20Sopenharmony_ci break; 11678c2ecf20Sopenharmony_ci if (!_rtl88e_phy_sw_chnl_step_by_step 11688c2ecf20Sopenharmony_ci (hw, rtlphy->current_channel, &rtlphy->sw_chnl_stage, 11698c2ecf20Sopenharmony_ci &rtlphy->sw_chnl_step, &delay)) { 11708c2ecf20Sopenharmony_ci if (delay > 0) 11718c2ecf20Sopenharmony_ci mdelay(delay); 11728c2ecf20Sopenharmony_ci else 11738c2ecf20Sopenharmony_ci continue; 11748c2ecf20Sopenharmony_ci } else { 11758c2ecf20Sopenharmony_ci rtlphy->sw_chnl_inprogress = false; 11768c2ecf20Sopenharmony_ci } 11778c2ecf20Sopenharmony_ci break; 11788c2ecf20Sopenharmony_ci } while (true); 11798c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_SCAN, DBG_TRACE, "\n"); 11808c2ecf20Sopenharmony_ci} 11818c2ecf20Sopenharmony_ci 11828c2ecf20Sopenharmony_ciu8 rtl88e_phy_sw_chnl(struct ieee80211_hw *hw) 11838c2ecf20Sopenharmony_ci{ 11848c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 11858c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 11868c2ecf20Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 11878c2ecf20Sopenharmony_ci 11888c2ecf20Sopenharmony_ci if (rtlphy->sw_chnl_inprogress) 11898c2ecf20Sopenharmony_ci return 0; 11908c2ecf20Sopenharmony_ci if (rtlphy->set_bwmode_inprogress) 11918c2ecf20Sopenharmony_ci return 0; 11928c2ecf20Sopenharmony_ci WARN_ONCE((rtlphy->current_channel > 14), 11938c2ecf20Sopenharmony_ci "rtl8188ee: WIRELESS_MODE_G but channel>14"); 11948c2ecf20Sopenharmony_ci rtlphy->sw_chnl_inprogress = true; 11958c2ecf20Sopenharmony_ci rtlphy->sw_chnl_stage = 0; 11968c2ecf20Sopenharmony_ci rtlphy->sw_chnl_step = 0; 11978c2ecf20Sopenharmony_ci if (!(is_hal_stop(rtlhal)) && !(RT_CANNOT_IO(hw))) { 11988c2ecf20Sopenharmony_ci rtl88e_phy_sw_chnl_callback(hw); 11998c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CHAN, DBG_LOUD, 12008c2ecf20Sopenharmony_ci "sw_chnl_inprogress false schedule workitem current channel %d\n", 12018c2ecf20Sopenharmony_ci rtlphy->current_channel); 12028c2ecf20Sopenharmony_ci rtlphy->sw_chnl_inprogress = false; 12038c2ecf20Sopenharmony_ci } else { 12048c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CHAN, DBG_LOUD, 12058c2ecf20Sopenharmony_ci "sw_chnl_inprogress false driver sleep or unload\n"); 12068c2ecf20Sopenharmony_ci rtlphy->sw_chnl_inprogress = false; 12078c2ecf20Sopenharmony_ci } 12088c2ecf20Sopenharmony_ci return 1; 12098c2ecf20Sopenharmony_ci} 12108c2ecf20Sopenharmony_ci 12118c2ecf20Sopenharmony_cistatic bool _rtl88e_phy_sw_chnl_step_by_step(struct ieee80211_hw *hw, 12128c2ecf20Sopenharmony_ci u8 channel, u8 *stage, u8 *step, 12138c2ecf20Sopenharmony_ci u32 *delay) 12148c2ecf20Sopenharmony_ci{ 12158c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 12168c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 12178c2ecf20Sopenharmony_ci struct swchnlcmd precommoncmd[MAX_PRECMD_CNT]; 12188c2ecf20Sopenharmony_ci u32 precommoncmdcnt; 12198c2ecf20Sopenharmony_ci struct swchnlcmd postcommoncmd[MAX_POSTCMD_CNT]; 12208c2ecf20Sopenharmony_ci u32 postcommoncmdcnt; 12218c2ecf20Sopenharmony_ci struct swchnlcmd rfdependcmd[MAX_RFDEPENDCMD_CNT]; 12228c2ecf20Sopenharmony_ci u32 rfdependcmdcnt; 12238c2ecf20Sopenharmony_ci struct swchnlcmd *currentcmd = NULL; 12248c2ecf20Sopenharmony_ci u8 rfpath; 12258c2ecf20Sopenharmony_ci u8 num_total_rfpath = rtlphy->num_total_rfpath; 12268c2ecf20Sopenharmony_ci 12278c2ecf20Sopenharmony_ci precommoncmdcnt = 0; 12288c2ecf20Sopenharmony_ci _rtl88e_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++, 12298c2ecf20Sopenharmony_ci MAX_PRECMD_CNT, 12308c2ecf20Sopenharmony_ci CMDID_SET_TXPOWEROWER_LEVEL, 0, 0, 0); 12318c2ecf20Sopenharmony_ci _rtl88e_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++, 12328c2ecf20Sopenharmony_ci MAX_PRECMD_CNT, CMDID_END, 0, 0, 0); 12338c2ecf20Sopenharmony_ci 12348c2ecf20Sopenharmony_ci postcommoncmdcnt = 0; 12358c2ecf20Sopenharmony_ci 12368c2ecf20Sopenharmony_ci _rtl88e_phy_set_sw_chnl_cmdarray(postcommoncmd, postcommoncmdcnt++, 12378c2ecf20Sopenharmony_ci MAX_POSTCMD_CNT, CMDID_END, 0, 0, 0); 12388c2ecf20Sopenharmony_ci 12398c2ecf20Sopenharmony_ci rfdependcmdcnt = 0; 12408c2ecf20Sopenharmony_ci 12418c2ecf20Sopenharmony_ci WARN_ONCE((channel < 1 || channel > 14), 12428c2ecf20Sopenharmony_ci "rtl8188ee: illegal channel for Zebra: %d\n", channel); 12438c2ecf20Sopenharmony_ci 12448c2ecf20Sopenharmony_ci _rtl88e_phy_set_sw_chnl_cmdarray(rfdependcmd, rfdependcmdcnt++, 12458c2ecf20Sopenharmony_ci MAX_RFDEPENDCMD_CNT, CMDID_RF_WRITEREG, 12468c2ecf20Sopenharmony_ci RF_CHNLBW, channel, 10); 12478c2ecf20Sopenharmony_ci 12488c2ecf20Sopenharmony_ci _rtl88e_phy_set_sw_chnl_cmdarray(rfdependcmd, rfdependcmdcnt++, 12498c2ecf20Sopenharmony_ci MAX_RFDEPENDCMD_CNT, CMDID_END, 0, 0, 12508c2ecf20Sopenharmony_ci 0); 12518c2ecf20Sopenharmony_ci 12528c2ecf20Sopenharmony_ci do { 12538c2ecf20Sopenharmony_ci switch (*stage) { 12548c2ecf20Sopenharmony_ci case 0: 12558c2ecf20Sopenharmony_ci currentcmd = &precommoncmd[*step]; 12568c2ecf20Sopenharmony_ci break; 12578c2ecf20Sopenharmony_ci case 1: 12588c2ecf20Sopenharmony_ci currentcmd = &rfdependcmd[*step]; 12598c2ecf20Sopenharmony_ci break; 12608c2ecf20Sopenharmony_ci case 2: 12618c2ecf20Sopenharmony_ci currentcmd = &postcommoncmd[*step]; 12628c2ecf20Sopenharmony_ci break; 12638c2ecf20Sopenharmony_ci default: 12648c2ecf20Sopenharmony_ci pr_err("Invalid 'stage' = %d, Check it!\n", 12658c2ecf20Sopenharmony_ci *stage); 12668c2ecf20Sopenharmony_ci return true; 12678c2ecf20Sopenharmony_ci } 12688c2ecf20Sopenharmony_ci 12698c2ecf20Sopenharmony_ci if (currentcmd->cmdid == CMDID_END) { 12708c2ecf20Sopenharmony_ci if ((*stage) == 2) 12718c2ecf20Sopenharmony_ci return true; 12728c2ecf20Sopenharmony_ci (*stage)++; 12738c2ecf20Sopenharmony_ci (*step) = 0; 12748c2ecf20Sopenharmony_ci continue; 12758c2ecf20Sopenharmony_ci } 12768c2ecf20Sopenharmony_ci 12778c2ecf20Sopenharmony_ci switch (currentcmd->cmdid) { 12788c2ecf20Sopenharmony_ci case CMDID_SET_TXPOWEROWER_LEVEL: 12798c2ecf20Sopenharmony_ci rtl88e_phy_set_txpower_level(hw, channel); 12808c2ecf20Sopenharmony_ci break; 12818c2ecf20Sopenharmony_ci case CMDID_WRITEPORT_ULONG: 12828c2ecf20Sopenharmony_ci rtl_write_dword(rtlpriv, currentcmd->para1, 12838c2ecf20Sopenharmony_ci currentcmd->para2); 12848c2ecf20Sopenharmony_ci break; 12858c2ecf20Sopenharmony_ci case CMDID_WRITEPORT_USHORT: 12868c2ecf20Sopenharmony_ci rtl_write_word(rtlpriv, currentcmd->para1, 12878c2ecf20Sopenharmony_ci (u16)currentcmd->para2); 12888c2ecf20Sopenharmony_ci break; 12898c2ecf20Sopenharmony_ci case CMDID_WRITEPORT_UCHAR: 12908c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, currentcmd->para1, 12918c2ecf20Sopenharmony_ci (u8)currentcmd->para2); 12928c2ecf20Sopenharmony_ci break; 12938c2ecf20Sopenharmony_ci case CMDID_RF_WRITEREG: 12948c2ecf20Sopenharmony_ci for (rfpath = 0; rfpath < num_total_rfpath; rfpath++) { 12958c2ecf20Sopenharmony_ci rtlphy->rfreg_chnlval[rfpath] = 12968c2ecf20Sopenharmony_ci ((rtlphy->rfreg_chnlval[rfpath] & 12978c2ecf20Sopenharmony_ci 0xfffffc00) | currentcmd->para2); 12988c2ecf20Sopenharmony_ci 12998c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, (enum radio_path)rfpath, 13008c2ecf20Sopenharmony_ci currentcmd->para1, 13018c2ecf20Sopenharmony_ci RFREG_OFFSET_MASK, 13028c2ecf20Sopenharmony_ci rtlphy->rfreg_chnlval[rfpath]); 13038c2ecf20Sopenharmony_ci } 13048c2ecf20Sopenharmony_ci break; 13058c2ecf20Sopenharmony_ci default: 13068c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_ERR, DBG_LOUD, 13078c2ecf20Sopenharmony_ci "switch case %#x not processed\n", 13088c2ecf20Sopenharmony_ci currentcmd->cmdid); 13098c2ecf20Sopenharmony_ci break; 13108c2ecf20Sopenharmony_ci } 13118c2ecf20Sopenharmony_ci 13128c2ecf20Sopenharmony_ci break; 13138c2ecf20Sopenharmony_ci } while (true); 13148c2ecf20Sopenharmony_ci 13158c2ecf20Sopenharmony_ci (*delay) = currentcmd->msdelay; 13168c2ecf20Sopenharmony_ci (*step)++; 13178c2ecf20Sopenharmony_ci return false; 13188c2ecf20Sopenharmony_ci} 13198c2ecf20Sopenharmony_ci 13208c2ecf20Sopenharmony_cistatic bool _rtl88e_phy_set_sw_chnl_cmdarray(struct swchnlcmd *cmdtable, 13218c2ecf20Sopenharmony_ci u32 cmdtableidx, u32 cmdtablesz, 13228c2ecf20Sopenharmony_ci enum swchnlcmd_id cmdid, 13238c2ecf20Sopenharmony_ci u32 para1, u32 para2, u32 msdelay) 13248c2ecf20Sopenharmony_ci{ 13258c2ecf20Sopenharmony_ci struct swchnlcmd *pcmd; 13268c2ecf20Sopenharmony_ci 13278c2ecf20Sopenharmony_ci if (cmdtable == NULL) { 13288c2ecf20Sopenharmony_ci WARN_ONCE(true, "rtl8188ee: cmdtable cannot be NULL.\n"); 13298c2ecf20Sopenharmony_ci return false; 13308c2ecf20Sopenharmony_ci } 13318c2ecf20Sopenharmony_ci 13328c2ecf20Sopenharmony_ci if (cmdtableidx >= cmdtablesz) 13338c2ecf20Sopenharmony_ci return false; 13348c2ecf20Sopenharmony_ci 13358c2ecf20Sopenharmony_ci pcmd = cmdtable + cmdtableidx; 13368c2ecf20Sopenharmony_ci pcmd->cmdid = cmdid; 13378c2ecf20Sopenharmony_ci pcmd->para1 = para1; 13388c2ecf20Sopenharmony_ci pcmd->para2 = para2; 13398c2ecf20Sopenharmony_ci pcmd->msdelay = msdelay; 13408c2ecf20Sopenharmony_ci return true; 13418c2ecf20Sopenharmony_ci} 13428c2ecf20Sopenharmony_ci 13438c2ecf20Sopenharmony_cistatic u8 _rtl88e_phy_path_a_iqk(struct ieee80211_hw *hw, bool config_pathb) 13448c2ecf20Sopenharmony_ci{ 13458c2ecf20Sopenharmony_ci u32 reg_eac, reg_e94, reg_e9c, reg_ea4; 13468c2ecf20Sopenharmony_ci u8 result = 0x00; 13478c2ecf20Sopenharmony_ci 13488c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0xe30, MASKDWORD, 0x10008c1c); 13498c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0xe34, MASKDWORD, 0x30008c1c); 13508c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0xe38, MASKDWORD, 0x8214032a); 13518c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0xe3c, MASKDWORD, 0x28160000); 13528c2ecf20Sopenharmony_ci 13538c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0xe4c, MASKDWORD, 0x00462911); 13548c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0xe48, MASKDWORD, 0xf9000000); 13558c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0xe48, MASKDWORD, 0xf8000000); 13568c2ecf20Sopenharmony_ci 13578c2ecf20Sopenharmony_ci mdelay(IQK_DELAY_TIME); 13588c2ecf20Sopenharmony_ci 13598c2ecf20Sopenharmony_ci reg_eac = rtl_get_bbreg(hw, 0xeac, MASKDWORD); 13608c2ecf20Sopenharmony_ci reg_e94 = rtl_get_bbreg(hw, 0xe94, MASKDWORD); 13618c2ecf20Sopenharmony_ci reg_e9c = rtl_get_bbreg(hw, 0xe9c, MASKDWORD); 13628c2ecf20Sopenharmony_ci reg_ea4 = rtl_get_bbreg(hw, 0xea4, MASKDWORD); 13638c2ecf20Sopenharmony_ci 13648c2ecf20Sopenharmony_ci if (!(reg_eac & BIT(28)) && 13658c2ecf20Sopenharmony_ci (((reg_e94 & 0x03FF0000) >> 16) != 0x142) && 13668c2ecf20Sopenharmony_ci (((reg_e9c & 0x03FF0000) >> 16) != 0x42)) 13678c2ecf20Sopenharmony_ci result |= 0x01; 13688c2ecf20Sopenharmony_ci return result; 13698c2ecf20Sopenharmony_ci} 13708c2ecf20Sopenharmony_ci 13718c2ecf20Sopenharmony_cistatic u8 _rtl88e_phy_path_b_iqk(struct ieee80211_hw *hw) 13728c2ecf20Sopenharmony_ci{ 13738c2ecf20Sopenharmony_ci u32 reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc; 13748c2ecf20Sopenharmony_ci u8 result = 0x00; 13758c2ecf20Sopenharmony_ci 13768c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0xe60, MASKDWORD, 0x00000002); 13778c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0xe60, MASKDWORD, 0x00000000); 13788c2ecf20Sopenharmony_ci mdelay(IQK_DELAY_TIME); 13798c2ecf20Sopenharmony_ci reg_eac = rtl_get_bbreg(hw, 0xeac, MASKDWORD); 13808c2ecf20Sopenharmony_ci reg_eb4 = rtl_get_bbreg(hw, 0xeb4, MASKDWORD); 13818c2ecf20Sopenharmony_ci reg_ebc = rtl_get_bbreg(hw, 0xebc, MASKDWORD); 13828c2ecf20Sopenharmony_ci reg_ec4 = rtl_get_bbreg(hw, 0xec4, MASKDWORD); 13838c2ecf20Sopenharmony_ci reg_ecc = rtl_get_bbreg(hw, 0xecc, MASKDWORD); 13848c2ecf20Sopenharmony_ci 13858c2ecf20Sopenharmony_ci if (!(reg_eac & BIT(31)) && 13868c2ecf20Sopenharmony_ci (((reg_eb4 & 0x03FF0000) >> 16) != 0x142) && 13878c2ecf20Sopenharmony_ci (((reg_ebc & 0x03FF0000) >> 16) != 0x42)) 13888c2ecf20Sopenharmony_ci result |= 0x01; 13898c2ecf20Sopenharmony_ci else 13908c2ecf20Sopenharmony_ci return result; 13918c2ecf20Sopenharmony_ci if (!(reg_eac & BIT(30)) && 13928c2ecf20Sopenharmony_ci (((reg_ec4 & 0x03FF0000) >> 16) != 0x132) && 13938c2ecf20Sopenharmony_ci (((reg_ecc & 0x03FF0000) >> 16) != 0x36)) 13948c2ecf20Sopenharmony_ci result |= 0x02; 13958c2ecf20Sopenharmony_ci return result; 13968c2ecf20Sopenharmony_ci} 13978c2ecf20Sopenharmony_ci 13988c2ecf20Sopenharmony_cistatic u8 _rtl88e_phy_path_a_rx_iqk(struct ieee80211_hw *hw, bool config_pathb) 13998c2ecf20Sopenharmony_ci{ 14008c2ecf20Sopenharmony_ci u32 reg_eac, reg_e94, reg_e9c, reg_ea4, u32temp; 14018c2ecf20Sopenharmony_ci u8 result = 0x00; 14028c2ecf20Sopenharmony_ci 14038c2ecf20Sopenharmony_ci /*Get TXIMR Setting*/ 14048c2ecf20Sopenharmony_ci /*Modify RX IQK mode table*/ 14058c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_IQK, MASKDWORD, 0x00000000); 14068c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_A, RF_WE_LUT, RFREG_OFFSET_MASK, 0x800a0); 14078c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_A, RF_RCK_OS, RFREG_OFFSET_MASK, 0x30000); 14088c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_A, RF_TXPA_G1, RFREG_OFFSET_MASK, 0x0000f); 14098c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_A, RF_TXPA_G2, RFREG_OFFSET_MASK, 0xf117b); 14108c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_IQK, MASKDWORD, 0x80800000); 14118c2ecf20Sopenharmony_ci 14128c2ecf20Sopenharmony_ci /*IQK Setting*/ 14138c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RTX_IQK, MASKDWORD, 0x01007c00); 14148c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RRX_IQK, MASKDWORD, 0x81004800); 14158c2ecf20Sopenharmony_ci 14168c2ecf20Sopenharmony_ci /*path a IQK setting*/ 14178c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RTX_IQK_TONE_A, MASKDWORD, 0x10008c1c); 14188c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RRX_IQK_TONE_A, MASKDWORD, 0x30008c1c); 14198c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RTX_IQK_PI_A, MASKDWORD, 0x82160804); 14208c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RRX_IQK_PI_A, MASKDWORD, 0x28160000); 14218c2ecf20Sopenharmony_ci 14228c2ecf20Sopenharmony_ci /*LO calibration Setting*/ 14238c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RIQK_AGC_RSP, MASKDWORD, 0x0046a911); 14248c2ecf20Sopenharmony_ci /*one shot,path A LOK & iqk*/ 14258c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RIQK_AGC_PTS, MASKDWORD, 0xf9000000); 14268c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RIQK_AGC_PTS, MASKDWORD, 0xf8000000); 14278c2ecf20Sopenharmony_ci 14288c2ecf20Sopenharmony_ci mdelay(IQK_DELAY_TIME); 14298c2ecf20Sopenharmony_ci 14308c2ecf20Sopenharmony_ci reg_eac = rtl_get_bbreg(hw, RRX_POWER_AFTER_IQK_A_2, MASKDWORD); 14318c2ecf20Sopenharmony_ci reg_e94 = rtl_get_bbreg(hw, RTX_POWER_BEFORE_IQK_A, MASKDWORD); 14328c2ecf20Sopenharmony_ci reg_e9c = rtl_get_bbreg(hw, RTX_POWER_AFTER_IQK_A, MASKDWORD); 14338c2ecf20Sopenharmony_ci 14348c2ecf20Sopenharmony_ci 14358c2ecf20Sopenharmony_ci if (!(reg_eac & BIT(28)) && 14368c2ecf20Sopenharmony_ci (((reg_e94 & 0x03FF0000) >> 16) != 0x142) && 14378c2ecf20Sopenharmony_ci (((reg_e9c & 0x03FF0000) >> 16) != 0x42)) 14388c2ecf20Sopenharmony_ci result |= 0x01; 14398c2ecf20Sopenharmony_ci else 14408c2ecf20Sopenharmony_ci return result; 14418c2ecf20Sopenharmony_ci 14428c2ecf20Sopenharmony_ci u32temp = 0x80007C00 | (reg_e94&0x3FF0000) | 14438c2ecf20Sopenharmony_ci ((reg_e9c&0x3FF0000) >> 16); 14448c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RTX_IQK, MASKDWORD, u32temp); 14458c2ecf20Sopenharmony_ci /*RX IQK*/ 14468c2ecf20Sopenharmony_ci /*Modify RX IQK mode table*/ 14478c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_IQK, MASKDWORD, 0x00000000); 14488c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_A, RF_WE_LUT, RFREG_OFFSET_MASK, 0x800a0); 14498c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_A, RF_RCK_OS, RFREG_OFFSET_MASK, 0x30000); 14508c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_A, RF_TXPA_G1, RFREG_OFFSET_MASK, 0x0000f); 14518c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_A, RF_TXPA_G2, RFREG_OFFSET_MASK, 0xf7ffa); 14528c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_IQK, MASKDWORD, 0x80800000); 14538c2ecf20Sopenharmony_ci 14548c2ecf20Sopenharmony_ci /*IQK Setting*/ 14558c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RRX_IQK, MASKDWORD, 0x01004800); 14568c2ecf20Sopenharmony_ci 14578c2ecf20Sopenharmony_ci /*path a IQK setting*/ 14588c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RTX_IQK_TONE_A, MASKDWORD, 0x30008c1c); 14598c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RRX_IQK_TONE_A, MASKDWORD, 0x10008c1c); 14608c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RTX_IQK_PI_A, MASKDWORD, 0x82160c05); 14618c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RRX_IQK_PI_A, MASKDWORD, 0x28160c05); 14628c2ecf20Sopenharmony_ci 14638c2ecf20Sopenharmony_ci /*LO calibration Setting*/ 14648c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RIQK_AGC_RSP, MASKDWORD, 0x0046a911); 14658c2ecf20Sopenharmony_ci /*one shot,path A LOK & iqk*/ 14668c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RIQK_AGC_PTS, MASKDWORD, 0xf9000000); 14678c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RIQK_AGC_PTS, MASKDWORD, 0xf8000000); 14688c2ecf20Sopenharmony_ci 14698c2ecf20Sopenharmony_ci mdelay(IQK_DELAY_TIME); 14708c2ecf20Sopenharmony_ci 14718c2ecf20Sopenharmony_ci reg_eac = rtl_get_bbreg(hw, RRX_POWER_AFTER_IQK_A_2, MASKDWORD); 14728c2ecf20Sopenharmony_ci reg_e94 = rtl_get_bbreg(hw, RTX_POWER_BEFORE_IQK_A, MASKDWORD); 14738c2ecf20Sopenharmony_ci reg_e9c = rtl_get_bbreg(hw, RTX_POWER_AFTER_IQK_A, MASKDWORD); 14748c2ecf20Sopenharmony_ci reg_ea4 = rtl_get_bbreg(hw, RRX_POWER_BEFORE_IQK_A_2, MASKDWORD); 14758c2ecf20Sopenharmony_ci 14768c2ecf20Sopenharmony_ci if (!(reg_eac & BIT(27)) && 14778c2ecf20Sopenharmony_ci (((reg_ea4 & 0x03FF0000) >> 16) != 0x132) && 14788c2ecf20Sopenharmony_ci (((reg_eac & 0x03FF0000) >> 16) != 0x36)) 14798c2ecf20Sopenharmony_ci result |= 0x02; 14808c2ecf20Sopenharmony_ci return result; 14818c2ecf20Sopenharmony_ci} 14828c2ecf20Sopenharmony_ci 14838c2ecf20Sopenharmony_cistatic void _rtl88e_phy_path_a_fill_iqk_matrix(struct ieee80211_hw *hw, 14848c2ecf20Sopenharmony_ci bool iqk_ok, long result[][8], 14858c2ecf20Sopenharmony_ci u8 final_candidate, bool btxonly) 14868c2ecf20Sopenharmony_ci{ 14878c2ecf20Sopenharmony_ci u32 oldval_0, x, tx0_a, reg; 14888c2ecf20Sopenharmony_ci long y, tx0_c; 14898c2ecf20Sopenharmony_ci 14908c2ecf20Sopenharmony_ci if (final_candidate == 0xFF) { 14918c2ecf20Sopenharmony_ci return; 14928c2ecf20Sopenharmony_ci } else if (iqk_ok) { 14938c2ecf20Sopenharmony_ci oldval_0 = (rtl_get_bbreg(hw, ROFDM0_XATXIQIMBALANCE, 14948c2ecf20Sopenharmony_ci MASKDWORD) >> 22) & 0x3FF; 14958c2ecf20Sopenharmony_ci x = result[final_candidate][0]; 14968c2ecf20Sopenharmony_ci if ((x & 0x00000200) != 0) 14978c2ecf20Sopenharmony_ci x = x | 0xFFFFFC00; 14988c2ecf20Sopenharmony_ci tx0_a = (x * oldval_0) >> 8; 14998c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XATXIQIMBALANCE, 0x3FF, tx0_a); 15008c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(31), 15018c2ecf20Sopenharmony_ci ((x * oldval_0 >> 7) & 0x1)); 15028c2ecf20Sopenharmony_ci y = result[final_candidate][1]; 15038c2ecf20Sopenharmony_ci if ((y & 0x00000200) != 0) 15048c2ecf20Sopenharmony_ci y = y | 0xFFFFFC00; 15058c2ecf20Sopenharmony_ci tx0_c = (y * oldval_0) >> 8; 15068c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XCTXAFE, 0xF0000000, 15078c2ecf20Sopenharmony_ci ((tx0_c & 0x3C0) >> 6)); 15088c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XATXIQIMBALANCE, 0x003F0000, 15098c2ecf20Sopenharmony_ci (tx0_c & 0x3F)); 15108c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(29), 15118c2ecf20Sopenharmony_ci ((y * oldval_0 >> 7) & 0x1)); 15128c2ecf20Sopenharmony_ci if (btxonly) 15138c2ecf20Sopenharmony_ci return; 15148c2ecf20Sopenharmony_ci reg = result[final_candidate][2]; 15158c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XARXIQIMBALANCE, 0x3FF, reg); 15168c2ecf20Sopenharmony_ci reg = result[final_candidate][3] & 0x3F; 15178c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XARXIQIMBALANCE, 0xFC00, reg); 15188c2ecf20Sopenharmony_ci reg = (result[final_candidate][3] >> 6) & 0xF; 15198c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0xca0, 0xF0000000, reg); 15208c2ecf20Sopenharmony_ci } 15218c2ecf20Sopenharmony_ci} 15228c2ecf20Sopenharmony_ci 15238c2ecf20Sopenharmony_cistatic void _rtl88e_phy_save_adda_registers(struct ieee80211_hw *hw, 15248c2ecf20Sopenharmony_ci u32 *addareg, u32 *addabackup, 15258c2ecf20Sopenharmony_ci u32 registernum) 15268c2ecf20Sopenharmony_ci{ 15278c2ecf20Sopenharmony_ci u32 i; 15288c2ecf20Sopenharmony_ci 15298c2ecf20Sopenharmony_ci for (i = 0; i < registernum; i++) 15308c2ecf20Sopenharmony_ci addabackup[i] = rtl_get_bbreg(hw, addareg[i], MASKDWORD); 15318c2ecf20Sopenharmony_ci} 15328c2ecf20Sopenharmony_ci 15338c2ecf20Sopenharmony_cistatic void _rtl88e_phy_save_mac_registers(struct ieee80211_hw *hw, 15348c2ecf20Sopenharmony_ci u32 *macreg, u32 *macbackup) 15358c2ecf20Sopenharmony_ci{ 15368c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 15378c2ecf20Sopenharmony_ci u32 i; 15388c2ecf20Sopenharmony_ci 15398c2ecf20Sopenharmony_ci for (i = 0; i < (IQK_MAC_REG_NUM - 1); i++) 15408c2ecf20Sopenharmony_ci macbackup[i] = rtl_read_byte(rtlpriv, macreg[i]); 15418c2ecf20Sopenharmony_ci macbackup[i] = rtl_read_dword(rtlpriv, macreg[i]); 15428c2ecf20Sopenharmony_ci} 15438c2ecf20Sopenharmony_ci 15448c2ecf20Sopenharmony_cistatic void _rtl88e_phy_reload_adda_registers(struct ieee80211_hw *hw, 15458c2ecf20Sopenharmony_ci u32 *addareg, u32 *addabackup, 15468c2ecf20Sopenharmony_ci u32 regiesternum) 15478c2ecf20Sopenharmony_ci{ 15488c2ecf20Sopenharmony_ci u32 i; 15498c2ecf20Sopenharmony_ci 15508c2ecf20Sopenharmony_ci for (i = 0; i < regiesternum; i++) 15518c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, addareg[i], MASKDWORD, addabackup[i]); 15528c2ecf20Sopenharmony_ci} 15538c2ecf20Sopenharmony_ci 15548c2ecf20Sopenharmony_cistatic void _rtl88e_phy_reload_mac_registers(struct ieee80211_hw *hw, 15558c2ecf20Sopenharmony_ci u32 *macreg, u32 *macbackup) 15568c2ecf20Sopenharmony_ci{ 15578c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 15588c2ecf20Sopenharmony_ci u32 i; 15598c2ecf20Sopenharmony_ci 15608c2ecf20Sopenharmony_ci for (i = 0; i < (IQK_MAC_REG_NUM - 1); i++) 15618c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, macreg[i], (u8) macbackup[i]); 15628c2ecf20Sopenharmony_ci rtl_write_dword(rtlpriv, macreg[i], macbackup[i]); 15638c2ecf20Sopenharmony_ci} 15648c2ecf20Sopenharmony_ci 15658c2ecf20Sopenharmony_cistatic void _rtl88e_phy_path_adda_on(struct ieee80211_hw *hw, 15668c2ecf20Sopenharmony_ci u32 *addareg, bool is_patha_on, bool is2t) 15678c2ecf20Sopenharmony_ci{ 15688c2ecf20Sopenharmony_ci u32 pathon; 15698c2ecf20Sopenharmony_ci u32 i; 15708c2ecf20Sopenharmony_ci 15718c2ecf20Sopenharmony_ci pathon = is_patha_on ? 0x04db25a4 : 0x0b1b25a4; 15728c2ecf20Sopenharmony_ci if (!is2t) { 15738c2ecf20Sopenharmony_ci pathon = 0x0bdb25a0; 15748c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, addareg[0], MASKDWORD, 0x0b1b25a0); 15758c2ecf20Sopenharmony_ci } else { 15768c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, addareg[0], MASKDWORD, pathon); 15778c2ecf20Sopenharmony_ci } 15788c2ecf20Sopenharmony_ci 15798c2ecf20Sopenharmony_ci for (i = 1; i < IQK_ADDA_REG_NUM; i++) 15808c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, addareg[i], MASKDWORD, pathon); 15818c2ecf20Sopenharmony_ci} 15828c2ecf20Sopenharmony_ci 15838c2ecf20Sopenharmony_cistatic void _rtl88e_phy_mac_setting_calibration(struct ieee80211_hw *hw, 15848c2ecf20Sopenharmony_ci u32 *macreg, u32 *macbackup) 15858c2ecf20Sopenharmony_ci{ 15868c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 15878c2ecf20Sopenharmony_ci u32 i = 0; 15888c2ecf20Sopenharmony_ci 15898c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, macreg[i], 0x3F); 15908c2ecf20Sopenharmony_ci 15918c2ecf20Sopenharmony_ci for (i = 1; i < (IQK_MAC_REG_NUM - 1); i++) 15928c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, macreg[i], 15938c2ecf20Sopenharmony_ci (u8) (macbackup[i] & (~BIT(3)))); 15948c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, macreg[i], (u8) (macbackup[i] & (~BIT(5)))); 15958c2ecf20Sopenharmony_ci} 15968c2ecf20Sopenharmony_ci 15978c2ecf20Sopenharmony_cistatic void _rtl88e_phy_path_a_standby(struct ieee80211_hw *hw) 15988c2ecf20Sopenharmony_ci{ 15998c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0xe28, MASKDWORD, 0x0); 16008c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0x840, MASKDWORD, 0x00010000); 16018c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0xe28, MASKDWORD, 0x80800000); 16028c2ecf20Sopenharmony_ci} 16038c2ecf20Sopenharmony_ci 16048c2ecf20Sopenharmony_cistatic void _rtl88e_phy_pi_mode_switch(struct ieee80211_hw *hw, bool pi_mode) 16058c2ecf20Sopenharmony_ci{ 16068c2ecf20Sopenharmony_ci u32 mode; 16078c2ecf20Sopenharmony_ci 16088c2ecf20Sopenharmony_ci mode = pi_mode ? 0x01000100 : 0x01000000; 16098c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0x820, MASKDWORD, mode); 16108c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0x828, MASKDWORD, mode); 16118c2ecf20Sopenharmony_ci} 16128c2ecf20Sopenharmony_ci 16138c2ecf20Sopenharmony_cistatic bool _rtl88e_phy_simularity_compare(struct ieee80211_hw *hw, 16148c2ecf20Sopenharmony_ci long result[][8], u8 c1, u8 c2) 16158c2ecf20Sopenharmony_ci{ 16168c2ecf20Sopenharmony_ci u32 i, j, diff, simularity_bitmap, bound; 16178c2ecf20Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 16188c2ecf20Sopenharmony_ci 16198c2ecf20Sopenharmony_ci u8 final_candidate[2] = { 0xFF, 0xFF }; 16208c2ecf20Sopenharmony_ci bool bresult = true, is2t = IS_92C_SERIAL(rtlhal->version); 16218c2ecf20Sopenharmony_ci 16228c2ecf20Sopenharmony_ci if (is2t) 16238c2ecf20Sopenharmony_ci bound = 8; 16248c2ecf20Sopenharmony_ci else 16258c2ecf20Sopenharmony_ci bound = 4; 16268c2ecf20Sopenharmony_ci 16278c2ecf20Sopenharmony_ci simularity_bitmap = 0; 16288c2ecf20Sopenharmony_ci 16298c2ecf20Sopenharmony_ci for (i = 0; i < bound; i++) { 16308c2ecf20Sopenharmony_ci diff = (result[c1][i] > result[c2][i]) ? 16318c2ecf20Sopenharmony_ci (result[c1][i] - result[c2][i]) : 16328c2ecf20Sopenharmony_ci (result[c2][i] - result[c1][i]); 16338c2ecf20Sopenharmony_ci 16348c2ecf20Sopenharmony_ci if (diff > MAX_TOLERANCE) { 16358c2ecf20Sopenharmony_ci if ((i == 2 || i == 6) && !simularity_bitmap) { 16368c2ecf20Sopenharmony_ci if (result[c1][i] + result[c1][i + 1] == 0) 16378c2ecf20Sopenharmony_ci final_candidate[(i / 4)] = c2; 16388c2ecf20Sopenharmony_ci else if (result[c2][i] + result[c2][i + 1] == 0) 16398c2ecf20Sopenharmony_ci final_candidate[(i / 4)] = c1; 16408c2ecf20Sopenharmony_ci else 16418c2ecf20Sopenharmony_ci simularity_bitmap = simularity_bitmap | 16428c2ecf20Sopenharmony_ci (1 << i); 16438c2ecf20Sopenharmony_ci } else 16448c2ecf20Sopenharmony_ci simularity_bitmap = 16458c2ecf20Sopenharmony_ci simularity_bitmap | (1 << i); 16468c2ecf20Sopenharmony_ci } 16478c2ecf20Sopenharmony_ci } 16488c2ecf20Sopenharmony_ci 16498c2ecf20Sopenharmony_ci if (simularity_bitmap == 0) { 16508c2ecf20Sopenharmony_ci for (i = 0; i < (bound / 4); i++) { 16518c2ecf20Sopenharmony_ci if (final_candidate[i] != 0xFF) { 16528c2ecf20Sopenharmony_ci for (j = i * 4; j < (i + 1) * 4 - 2; j++) 16538c2ecf20Sopenharmony_ci result[3][j] = 16548c2ecf20Sopenharmony_ci result[final_candidate[i]][j]; 16558c2ecf20Sopenharmony_ci bresult = false; 16568c2ecf20Sopenharmony_ci } 16578c2ecf20Sopenharmony_ci } 16588c2ecf20Sopenharmony_ci return bresult; 16598c2ecf20Sopenharmony_ci } else if (!(simularity_bitmap & 0x0F)) { 16608c2ecf20Sopenharmony_ci for (i = 0; i < 4; i++) 16618c2ecf20Sopenharmony_ci result[3][i] = result[c1][i]; 16628c2ecf20Sopenharmony_ci return false; 16638c2ecf20Sopenharmony_ci } else if (!(simularity_bitmap & 0xF0) && is2t) { 16648c2ecf20Sopenharmony_ci for (i = 4; i < 8; i++) 16658c2ecf20Sopenharmony_ci result[3][i] = result[c1][i]; 16668c2ecf20Sopenharmony_ci return false; 16678c2ecf20Sopenharmony_ci } else { 16688c2ecf20Sopenharmony_ci return false; 16698c2ecf20Sopenharmony_ci } 16708c2ecf20Sopenharmony_ci 16718c2ecf20Sopenharmony_ci} 16728c2ecf20Sopenharmony_ci 16738c2ecf20Sopenharmony_cistatic void _rtl88e_phy_iq_calibrate(struct ieee80211_hw *hw, 16748c2ecf20Sopenharmony_ci long result[][8], u8 t, bool is2t) 16758c2ecf20Sopenharmony_ci{ 16768c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 16778c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 16788c2ecf20Sopenharmony_ci u32 i; 16798c2ecf20Sopenharmony_ci u8 patha_ok, pathb_ok; 16808c2ecf20Sopenharmony_ci u32 adda_reg[IQK_ADDA_REG_NUM] = { 16818c2ecf20Sopenharmony_ci 0x85c, 0xe6c, 0xe70, 0xe74, 16828c2ecf20Sopenharmony_ci 0xe78, 0xe7c, 0xe80, 0xe84, 16838c2ecf20Sopenharmony_ci 0xe88, 0xe8c, 0xed0, 0xed4, 16848c2ecf20Sopenharmony_ci 0xed8, 0xedc, 0xee0, 0xeec 16858c2ecf20Sopenharmony_ci }; 16868c2ecf20Sopenharmony_ci u32 iqk_mac_reg[IQK_MAC_REG_NUM] = { 16878c2ecf20Sopenharmony_ci 0x522, 0x550, 0x551, 0x040 16888c2ecf20Sopenharmony_ci }; 16898c2ecf20Sopenharmony_ci u32 iqk_bb_reg[IQK_BB_REG_NUM] = { 16908c2ecf20Sopenharmony_ci ROFDM0_TRXPATHENABLE, ROFDM0_TRMUXPAR, 16918c2ecf20Sopenharmony_ci RFPGA0_XCD_RFINTERFACESW, 0xb68, 0xb6c, 16928c2ecf20Sopenharmony_ci 0x870, 0x860, 0x864, 0x800 16938c2ecf20Sopenharmony_ci }; 16948c2ecf20Sopenharmony_ci const u32 retrycount = 2; 16958c2ecf20Sopenharmony_ci 16968c2ecf20Sopenharmony_ci if (t == 0) { 16978c2ecf20Sopenharmony_ci _rtl88e_phy_save_adda_registers(hw, adda_reg, 16988c2ecf20Sopenharmony_ci rtlphy->adda_backup, 16); 16998c2ecf20Sopenharmony_ci _rtl88e_phy_save_mac_registers(hw, iqk_mac_reg, 17008c2ecf20Sopenharmony_ci rtlphy->iqk_mac_backup); 17018c2ecf20Sopenharmony_ci _rtl88e_phy_save_adda_registers(hw, iqk_bb_reg, 17028c2ecf20Sopenharmony_ci rtlphy->iqk_bb_backup, 17038c2ecf20Sopenharmony_ci IQK_BB_REG_NUM); 17048c2ecf20Sopenharmony_ci } 17058c2ecf20Sopenharmony_ci _rtl88e_phy_path_adda_on(hw, adda_reg, true, is2t); 17068c2ecf20Sopenharmony_ci if (t == 0) { 17078c2ecf20Sopenharmony_ci rtlphy->rfpi_enable = 17088c2ecf20Sopenharmony_ci (u8)rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER1, BIT(8)); 17098c2ecf20Sopenharmony_ci } 17108c2ecf20Sopenharmony_ci 17118c2ecf20Sopenharmony_ci if (!rtlphy->rfpi_enable) 17128c2ecf20Sopenharmony_ci _rtl88e_phy_pi_mode_switch(hw, true); 17138c2ecf20Sopenharmony_ci /*BB Setting*/ 17148c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0x800, BIT(24), 0x00); 17158c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0xc04, MASKDWORD, 0x03a05600); 17168c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0xc08, MASKDWORD, 0x000800e4); 17178c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0x874, MASKDWORD, 0x22204000); 17188c2ecf20Sopenharmony_ci 17198c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0x870, BIT(10), 0x01); 17208c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0x870, BIT(26), 0x01); 17218c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0x860, BIT(10), 0x00); 17228c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0x864, BIT(10), 0x00); 17238c2ecf20Sopenharmony_ci 17248c2ecf20Sopenharmony_ci if (is2t) { 17258c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0x840, MASKDWORD, 0x00010000); 17268c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0x844, MASKDWORD, 0x00010000); 17278c2ecf20Sopenharmony_ci } 17288c2ecf20Sopenharmony_ci _rtl88e_phy_mac_setting_calibration(hw, iqk_mac_reg, 17298c2ecf20Sopenharmony_ci rtlphy->iqk_mac_backup); 17308c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0xb68, MASKDWORD, 0x0f600000); 17318c2ecf20Sopenharmony_ci if (is2t) 17328c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0xb6c, MASKDWORD, 0x0f600000); 17338c2ecf20Sopenharmony_ci 17348c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0xe28, MASKDWORD, 0x80800000); 17358c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0xe40, MASKDWORD, 0x01007c00); 17368c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0xe44, MASKDWORD, 0x81004800); 17378c2ecf20Sopenharmony_ci for (i = 0; i < retrycount; i++) { 17388c2ecf20Sopenharmony_ci patha_ok = _rtl88e_phy_path_a_iqk(hw, is2t); 17398c2ecf20Sopenharmony_ci if (patha_ok == 0x01) { 17408c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, 17418c2ecf20Sopenharmony_ci "Path A Tx IQK Success!!\n"); 17428c2ecf20Sopenharmony_ci result[t][0] = (rtl_get_bbreg(hw, 0xe94, MASKDWORD) & 17438c2ecf20Sopenharmony_ci 0x3FF0000) >> 16; 17448c2ecf20Sopenharmony_ci result[t][1] = (rtl_get_bbreg(hw, 0xe9c, MASKDWORD) & 17458c2ecf20Sopenharmony_ci 0x3FF0000) >> 16; 17468c2ecf20Sopenharmony_ci break; 17478c2ecf20Sopenharmony_ci } 17488c2ecf20Sopenharmony_ci } 17498c2ecf20Sopenharmony_ci 17508c2ecf20Sopenharmony_ci for (i = 0; i < retrycount; i++) { 17518c2ecf20Sopenharmony_ci patha_ok = _rtl88e_phy_path_a_rx_iqk(hw, is2t); 17528c2ecf20Sopenharmony_ci if (patha_ok == 0x03) { 17538c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, 17548c2ecf20Sopenharmony_ci "Path A Rx IQK Success!!\n"); 17558c2ecf20Sopenharmony_ci result[t][2] = (rtl_get_bbreg(hw, 0xea4, MASKDWORD) & 17568c2ecf20Sopenharmony_ci 0x3FF0000) >> 16; 17578c2ecf20Sopenharmony_ci result[t][3] = (rtl_get_bbreg(hw, 0xeac, MASKDWORD) & 17588c2ecf20Sopenharmony_ci 0x3FF0000) >> 16; 17598c2ecf20Sopenharmony_ci break; 17608c2ecf20Sopenharmony_ci } else { 17618c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, 17628c2ecf20Sopenharmony_ci "Path a RX iqk fail!!!\n"); 17638c2ecf20Sopenharmony_ci } 17648c2ecf20Sopenharmony_ci } 17658c2ecf20Sopenharmony_ci 17668c2ecf20Sopenharmony_ci if (0 == patha_ok) 17678c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, 17688c2ecf20Sopenharmony_ci "Path A IQK Success!!\n"); 17698c2ecf20Sopenharmony_ci if (is2t) { 17708c2ecf20Sopenharmony_ci _rtl88e_phy_path_a_standby(hw); 17718c2ecf20Sopenharmony_ci _rtl88e_phy_path_adda_on(hw, adda_reg, false, is2t); 17728c2ecf20Sopenharmony_ci for (i = 0; i < retrycount; i++) { 17738c2ecf20Sopenharmony_ci pathb_ok = _rtl88e_phy_path_b_iqk(hw); 17748c2ecf20Sopenharmony_ci if (pathb_ok == 0x03) { 17758c2ecf20Sopenharmony_ci result[t][4] = (rtl_get_bbreg(hw, 17768c2ecf20Sopenharmony_ci 0xeb4, 17778c2ecf20Sopenharmony_ci MASKDWORD) & 17788c2ecf20Sopenharmony_ci 0x3FF0000) >> 16; 17798c2ecf20Sopenharmony_ci result[t][5] = 17808c2ecf20Sopenharmony_ci (rtl_get_bbreg(hw, 0xebc, MASKDWORD) & 17818c2ecf20Sopenharmony_ci 0x3FF0000) >> 16; 17828c2ecf20Sopenharmony_ci result[t][6] = 17838c2ecf20Sopenharmony_ci (rtl_get_bbreg(hw, 0xec4, MASKDWORD) & 17848c2ecf20Sopenharmony_ci 0x3FF0000) >> 16; 17858c2ecf20Sopenharmony_ci result[t][7] = 17868c2ecf20Sopenharmony_ci (rtl_get_bbreg(hw, 0xecc, MASKDWORD) & 17878c2ecf20Sopenharmony_ci 0x3FF0000) >> 16; 17888c2ecf20Sopenharmony_ci break; 17898c2ecf20Sopenharmony_ci } else if (i == (retrycount - 1) && pathb_ok == 0x01) { 17908c2ecf20Sopenharmony_ci result[t][4] = (rtl_get_bbreg(hw, 17918c2ecf20Sopenharmony_ci 0xeb4, 17928c2ecf20Sopenharmony_ci MASKDWORD) & 17938c2ecf20Sopenharmony_ci 0x3FF0000) >> 16; 17948c2ecf20Sopenharmony_ci } 17958c2ecf20Sopenharmony_ci result[t][5] = (rtl_get_bbreg(hw, 0xebc, MASKDWORD) & 17968c2ecf20Sopenharmony_ci 0x3FF0000) >> 16; 17978c2ecf20Sopenharmony_ci } 17988c2ecf20Sopenharmony_ci } 17998c2ecf20Sopenharmony_ci 18008c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0xe28, MASKDWORD, 0); 18018c2ecf20Sopenharmony_ci 18028c2ecf20Sopenharmony_ci if (t != 0) { 18038c2ecf20Sopenharmony_ci if (!rtlphy->rfpi_enable) 18048c2ecf20Sopenharmony_ci _rtl88e_phy_pi_mode_switch(hw, false); 18058c2ecf20Sopenharmony_ci _rtl88e_phy_reload_adda_registers(hw, adda_reg, 18068c2ecf20Sopenharmony_ci rtlphy->adda_backup, 16); 18078c2ecf20Sopenharmony_ci _rtl88e_phy_reload_mac_registers(hw, iqk_mac_reg, 18088c2ecf20Sopenharmony_ci rtlphy->iqk_mac_backup); 18098c2ecf20Sopenharmony_ci _rtl88e_phy_reload_adda_registers(hw, iqk_bb_reg, 18108c2ecf20Sopenharmony_ci rtlphy->iqk_bb_backup, 18118c2ecf20Sopenharmony_ci IQK_BB_REG_NUM); 18128c2ecf20Sopenharmony_ci 18138c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0x840, MASKDWORD, 0x00032ed3); 18148c2ecf20Sopenharmony_ci if (is2t) 18158c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0x844, MASKDWORD, 0x00032ed3); 18168c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0xe30, MASKDWORD, 0x01008c00); 18178c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0xe34, MASKDWORD, 0x01008c00); 18188c2ecf20Sopenharmony_ci } 18198c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, "88ee IQK Finish!!\n"); 18208c2ecf20Sopenharmony_ci} 18218c2ecf20Sopenharmony_ci 18228c2ecf20Sopenharmony_cistatic void _rtl88e_phy_lc_calibrate(struct ieee80211_hw *hw, bool is2t) 18238c2ecf20Sopenharmony_ci{ 18248c2ecf20Sopenharmony_ci u8 tmpreg; 18258c2ecf20Sopenharmony_ci u32 rf_a_mode = 0, rf_b_mode = 0, lc_cal; 18268c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 18278c2ecf20Sopenharmony_ci 18288c2ecf20Sopenharmony_ci tmpreg = rtl_read_byte(rtlpriv, 0xd03); 18298c2ecf20Sopenharmony_ci 18308c2ecf20Sopenharmony_ci if ((tmpreg & 0x70) != 0) 18318c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, 0xd03, tmpreg & 0x8F); 18328c2ecf20Sopenharmony_ci else 18338c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF); 18348c2ecf20Sopenharmony_ci 18358c2ecf20Sopenharmony_ci if ((tmpreg & 0x70) != 0) { 18368c2ecf20Sopenharmony_ci rf_a_mode = rtl_get_rfreg(hw, RF90_PATH_A, 0x00, MASK12BITS); 18378c2ecf20Sopenharmony_ci 18388c2ecf20Sopenharmony_ci if (is2t) 18398c2ecf20Sopenharmony_ci rf_b_mode = rtl_get_rfreg(hw, RF90_PATH_B, 0x00, 18408c2ecf20Sopenharmony_ci MASK12BITS); 18418c2ecf20Sopenharmony_ci 18428c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_A, 0x00, MASK12BITS, 18438c2ecf20Sopenharmony_ci (rf_a_mode & 0x8FFFF) | 0x10000); 18448c2ecf20Sopenharmony_ci 18458c2ecf20Sopenharmony_ci if (is2t) 18468c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_B, 0x00, MASK12BITS, 18478c2ecf20Sopenharmony_ci (rf_b_mode & 0x8FFFF) | 0x10000); 18488c2ecf20Sopenharmony_ci } 18498c2ecf20Sopenharmony_ci lc_cal = rtl_get_rfreg(hw, RF90_PATH_A, 0x18, MASK12BITS); 18508c2ecf20Sopenharmony_ci 18518c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_A, 0x18, MASK12BITS, lc_cal | 0x08000); 18528c2ecf20Sopenharmony_ci 18538c2ecf20Sopenharmony_ci mdelay(100); 18548c2ecf20Sopenharmony_ci 18558c2ecf20Sopenharmony_ci if ((tmpreg & 0x70) != 0) { 18568c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, 0xd03, tmpreg); 18578c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_A, 0x00, MASK12BITS, rf_a_mode); 18588c2ecf20Sopenharmony_ci 18598c2ecf20Sopenharmony_ci if (is2t) 18608c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_B, 0x00, MASK12BITS, 18618c2ecf20Sopenharmony_ci rf_b_mode); 18628c2ecf20Sopenharmony_ci } else { 18638c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, REG_TXPAUSE, 0x00); 18648c2ecf20Sopenharmony_ci } 18658c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, "\n"); 18668c2ecf20Sopenharmony_ci} 18678c2ecf20Sopenharmony_ci 18688c2ecf20Sopenharmony_cistatic void _rtl88e_phy_set_rfpath_switch(struct ieee80211_hw *hw, 18698c2ecf20Sopenharmony_ci bool bmain, bool is2t) 18708c2ecf20Sopenharmony_ci{ 18718c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 18728c2ecf20Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 18738c2ecf20Sopenharmony_ci struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 18748c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, "\n"); 18758c2ecf20Sopenharmony_ci 18768c2ecf20Sopenharmony_ci if (is_hal_stop(rtlhal)) { 18778c2ecf20Sopenharmony_ci u8 u1btmp; 18788c2ecf20Sopenharmony_ci u1btmp = rtl_read_byte(rtlpriv, REG_LEDCFG0); 18798c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, REG_LEDCFG0, u1btmp | BIT(7)); 18808c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, BIT(13), 0x01); 18818c2ecf20Sopenharmony_ci } 18828c2ecf20Sopenharmony_ci if (is2t) { 18838c2ecf20Sopenharmony_ci if (bmain) 18848c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XB_RFINTERFACEOE, 18858c2ecf20Sopenharmony_ci BIT(5) | BIT(6), 0x1); 18868c2ecf20Sopenharmony_ci else 18878c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XB_RFINTERFACEOE, 18888c2ecf20Sopenharmony_ci BIT(5) | BIT(6), 0x2); 18898c2ecf20Sopenharmony_ci } else { 18908c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XAB_RFINTERFACESW, BIT(8) | BIT(9), 0); 18918c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, 0x914, MASKLWORD, 0x0201); 18928c2ecf20Sopenharmony_ci 18938c2ecf20Sopenharmony_ci /* We use the RF definition of MAIN and AUX, 18948c2ecf20Sopenharmony_ci * left antenna and right antenna repectively. 18958c2ecf20Sopenharmony_ci * Default output at AUX. 18968c2ecf20Sopenharmony_ci */ 18978c2ecf20Sopenharmony_ci if (bmain) { 18988c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XA_RFINTERFACEOE, 18998c2ecf20Sopenharmony_ci BIT(14) | BIT(13) | BIT(12), 0); 19008c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XB_RFINTERFACEOE, 19018c2ecf20Sopenharmony_ci BIT(5) | BIT(4) | BIT(3), 0); 19028c2ecf20Sopenharmony_ci if (rtlefuse->antenna_div_type == CGCS_RX_HW_ANTDIV) 19038c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RCONFIG_RAM64x16, BIT(31), 0); 19048c2ecf20Sopenharmony_ci } else { 19058c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XA_RFINTERFACEOE, 19068c2ecf20Sopenharmony_ci BIT(14) | BIT(13) | BIT(12), 1); 19078c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XB_RFINTERFACEOE, 19088c2ecf20Sopenharmony_ci BIT(5) | BIT(4) | BIT(3), 1); 19098c2ecf20Sopenharmony_ci if (rtlefuse->antenna_div_type == CGCS_RX_HW_ANTDIV) 19108c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RCONFIG_RAM64x16, BIT(31), 1); 19118c2ecf20Sopenharmony_ci } 19128c2ecf20Sopenharmony_ci } 19138c2ecf20Sopenharmony_ci} 19148c2ecf20Sopenharmony_ci 19158c2ecf20Sopenharmony_ci#undef IQK_ADDA_REG_NUM 19168c2ecf20Sopenharmony_ci#undef IQK_DELAY_TIME 19178c2ecf20Sopenharmony_ci 19188c2ecf20Sopenharmony_civoid rtl88e_phy_iq_calibrate(struct ieee80211_hw *hw, bool b_recovery) 19198c2ecf20Sopenharmony_ci{ 19208c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 19218c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 19228c2ecf20Sopenharmony_ci long result[4][8]; 19238c2ecf20Sopenharmony_ci u8 i, final_candidate; 19248c2ecf20Sopenharmony_ci bool b_patha_ok; 19258c2ecf20Sopenharmony_ci long reg_e94, reg_e9c, reg_ea4, reg_eb4, reg_ebc, 19268c2ecf20Sopenharmony_ci reg_tmp = 0; 19278c2ecf20Sopenharmony_ci bool is12simular, is13simular, is23simular; 19288c2ecf20Sopenharmony_ci u32 iqk_bb_reg[9] = { 19298c2ecf20Sopenharmony_ci ROFDM0_XARXIQIMBALANCE, 19308c2ecf20Sopenharmony_ci ROFDM0_XBRXIQIMBALANCE, 19318c2ecf20Sopenharmony_ci ROFDM0_ECCATHRESHOLD, 19328c2ecf20Sopenharmony_ci ROFDM0_AGCRSSITABLE, 19338c2ecf20Sopenharmony_ci ROFDM0_XATXIQIMBALANCE, 19348c2ecf20Sopenharmony_ci ROFDM0_XBTXIQIMBALANCE, 19358c2ecf20Sopenharmony_ci ROFDM0_XCTXAFE, 19368c2ecf20Sopenharmony_ci ROFDM0_XDTXAFE, 19378c2ecf20Sopenharmony_ci ROFDM0_RXIQEXTANTA 19388c2ecf20Sopenharmony_ci }; 19398c2ecf20Sopenharmony_ci 19408c2ecf20Sopenharmony_ci if (b_recovery) { 19418c2ecf20Sopenharmony_ci _rtl88e_phy_reload_adda_registers(hw, 19428c2ecf20Sopenharmony_ci iqk_bb_reg, 19438c2ecf20Sopenharmony_ci rtlphy->iqk_bb_backup, 9); 19448c2ecf20Sopenharmony_ci return; 19458c2ecf20Sopenharmony_ci } 19468c2ecf20Sopenharmony_ci 19478c2ecf20Sopenharmony_ci for (i = 0; i < 8; i++) { 19488c2ecf20Sopenharmony_ci result[0][i] = 0; 19498c2ecf20Sopenharmony_ci result[1][i] = 0; 19508c2ecf20Sopenharmony_ci result[2][i] = 0; 19518c2ecf20Sopenharmony_ci result[3][i] = 0; 19528c2ecf20Sopenharmony_ci } 19538c2ecf20Sopenharmony_ci final_candidate = 0xff; 19548c2ecf20Sopenharmony_ci b_patha_ok = false; 19558c2ecf20Sopenharmony_ci is12simular = false; 19568c2ecf20Sopenharmony_ci is23simular = false; 19578c2ecf20Sopenharmony_ci is13simular = false; 19588c2ecf20Sopenharmony_ci for (i = 0; i < 3; i++) { 19598c2ecf20Sopenharmony_ci if (get_rf_type(rtlphy) == RF_2T2R) 19608c2ecf20Sopenharmony_ci _rtl88e_phy_iq_calibrate(hw, result, i, true); 19618c2ecf20Sopenharmony_ci else 19628c2ecf20Sopenharmony_ci _rtl88e_phy_iq_calibrate(hw, result, i, false); 19638c2ecf20Sopenharmony_ci if (i == 1) { 19648c2ecf20Sopenharmony_ci is12simular = 19658c2ecf20Sopenharmony_ci _rtl88e_phy_simularity_compare(hw, result, 0, 1); 19668c2ecf20Sopenharmony_ci if (is12simular) { 19678c2ecf20Sopenharmony_ci final_candidate = 0; 19688c2ecf20Sopenharmony_ci break; 19698c2ecf20Sopenharmony_ci } 19708c2ecf20Sopenharmony_ci } 19718c2ecf20Sopenharmony_ci if (i == 2) { 19728c2ecf20Sopenharmony_ci is13simular = 19738c2ecf20Sopenharmony_ci _rtl88e_phy_simularity_compare(hw, result, 0, 2); 19748c2ecf20Sopenharmony_ci if (is13simular) { 19758c2ecf20Sopenharmony_ci final_candidate = 0; 19768c2ecf20Sopenharmony_ci break; 19778c2ecf20Sopenharmony_ci } 19788c2ecf20Sopenharmony_ci is23simular = 19798c2ecf20Sopenharmony_ci _rtl88e_phy_simularity_compare(hw, result, 1, 2); 19808c2ecf20Sopenharmony_ci if (is23simular) { 19818c2ecf20Sopenharmony_ci final_candidate = 1; 19828c2ecf20Sopenharmony_ci } else { 19838c2ecf20Sopenharmony_ci for (i = 0; i < 8; i++) 19848c2ecf20Sopenharmony_ci reg_tmp += result[3][i]; 19858c2ecf20Sopenharmony_ci 19868c2ecf20Sopenharmony_ci if (reg_tmp != 0) 19878c2ecf20Sopenharmony_ci final_candidate = 3; 19888c2ecf20Sopenharmony_ci else 19898c2ecf20Sopenharmony_ci final_candidate = 0xFF; 19908c2ecf20Sopenharmony_ci } 19918c2ecf20Sopenharmony_ci } 19928c2ecf20Sopenharmony_ci } 19938c2ecf20Sopenharmony_ci for (i = 0; i < 4; i++) { 19948c2ecf20Sopenharmony_ci reg_e94 = result[i][0]; 19958c2ecf20Sopenharmony_ci reg_e9c = result[i][1]; 19968c2ecf20Sopenharmony_ci reg_ea4 = result[i][2]; 19978c2ecf20Sopenharmony_ci reg_eb4 = result[i][4]; 19988c2ecf20Sopenharmony_ci reg_ebc = result[i][5]; 19998c2ecf20Sopenharmony_ci } 20008c2ecf20Sopenharmony_ci if (final_candidate != 0xff) { 20018c2ecf20Sopenharmony_ci reg_e94 = result[final_candidate][0]; 20028c2ecf20Sopenharmony_ci reg_e9c = result[final_candidate][1]; 20038c2ecf20Sopenharmony_ci reg_ea4 = result[final_candidate][2]; 20048c2ecf20Sopenharmony_ci reg_eb4 = result[final_candidate][4]; 20058c2ecf20Sopenharmony_ci reg_ebc = result[final_candidate][5]; 20068c2ecf20Sopenharmony_ci rtlphy->reg_eb4 = reg_eb4; 20078c2ecf20Sopenharmony_ci rtlphy->reg_ebc = reg_ebc; 20088c2ecf20Sopenharmony_ci rtlphy->reg_e94 = reg_e94; 20098c2ecf20Sopenharmony_ci rtlphy->reg_e9c = reg_e9c; 20108c2ecf20Sopenharmony_ci b_patha_ok = true; 20118c2ecf20Sopenharmony_ci } else { 20128c2ecf20Sopenharmony_ci rtlphy->reg_e94 = 0x100; 20138c2ecf20Sopenharmony_ci rtlphy->reg_eb4 = 0x100; 20148c2ecf20Sopenharmony_ci rtlphy->reg_e9c = 0x0; 20158c2ecf20Sopenharmony_ci rtlphy->reg_ebc = 0x0; 20168c2ecf20Sopenharmony_ci } 20178c2ecf20Sopenharmony_ci if (reg_e94 != 0) /*&&(reg_ea4 != 0) */ 20188c2ecf20Sopenharmony_ci _rtl88e_phy_path_a_fill_iqk_matrix(hw, b_patha_ok, result, 20198c2ecf20Sopenharmony_ci final_candidate, 20208c2ecf20Sopenharmony_ci (reg_ea4 == 0)); 20218c2ecf20Sopenharmony_ci if (final_candidate != 0xFF) { 20228c2ecf20Sopenharmony_ci for (i = 0; i < IQK_MATRIX_REG_NUM; i++) 20238c2ecf20Sopenharmony_ci rtlphy->iqk_matrix[0].value[0][i] = 20248c2ecf20Sopenharmony_ci result[final_candidate][i]; 20258c2ecf20Sopenharmony_ci rtlphy->iqk_matrix[0].iqk_done = true; 20268c2ecf20Sopenharmony_ci 20278c2ecf20Sopenharmony_ci } 20288c2ecf20Sopenharmony_ci _rtl88e_phy_save_adda_registers(hw, iqk_bb_reg, 20298c2ecf20Sopenharmony_ci rtlphy->iqk_bb_backup, 9); 20308c2ecf20Sopenharmony_ci} 20318c2ecf20Sopenharmony_ci 20328c2ecf20Sopenharmony_civoid rtl88e_phy_lc_calibrate(struct ieee80211_hw *hw) 20338c2ecf20Sopenharmony_ci{ 20348c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 20358c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 20368c2ecf20Sopenharmony_ci struct rtl_hal *rtlhal = &rtlpriv->rtlhal; 20378c2ecf20Sopenharmony_ci u32 timeout = 2000, timecount = 0; 20388c2ecf20Sopenharmony_ci 20398c2ecf20Sopenharmony_ci while (rtlpriv->mac80211.act_scanning && timecount < timeout) { 20408c2ecf20Sopenharmony_ci udelay(50); 20418c2ecf20Sopenharmony_ci timecount += 50; 20428c2ecf20Sopenharmony_ci } 20438c2ecf20Sopenharmony_ci 20448c2ecf20Sopenharmony_ci rtlphy->lck_inprogress = true; 20458c2ecf20Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 20468c2ecf20Sopenharmony_ci "LCK:Start!!! currentband %x delay %d ms\n", 20478c2ecf20Sopenharmony_ci rtlhal->current_bandtype, timecount); 20488c2ecf20Sopenharmony_ci 20498c2ecf20Sopenharmony_ci _rtl88e_phy_lc_calibrate(hw, false); 20508c2ecf20Sopenharmony_ci 20518c2ecf20Sopenharmony_ci rtlphy->lck_inprogress = false; 20528c2ecf20Sopenharmony_ci} 20538c2ecf20Sopenharmony_ci 20548c2ecf20Sopenharmony_civoid rtl88e_phy_set_rfpath_switch(struct ieee80211_hw *hw, bool bmain) 20558c2ecf20Sopenharmony_ci{ 20568c2ecf20Sopenharmony_ci _rtl88e_phy_set_rfpath_switch(hw, bmain, false); 20578c2ecf20Sopenharmony_ci} 20588c2ecf20Sopenharmony_ci 20598c2ecf20Sopenharmony_cibool rtl88e_phy_set_io_cmd(struct ieee80211_hw *hw, enum io_type iotype) 20608c2ecf20Sopenharmony_ci{ 20618c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 20628c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 20638c2ecf20Sopenharmony_ci bool postprocessing = false; 20648c2ecf20Sopenharmony_ci 20658c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE, 20668c2ecf20Sopenharmony_ci "-->IO Cmd(%#x), set_io_inprogress(%d)\n", 20678c2ecf20Sopenharmony_ci iotype, rtlphy->set_io_inprogress); 20688c2ecf20Sopenharmony_ci do { 20698c2ecf20Sopenharmony_ci switch (iotype) { 20708c2ecf20Sopenharmony_ci case IO_CMD_RESUME_DM_BY_SCAN: 20718c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE, 20728c2ecf20Sopenharmony_ci "[IO CMD] Resume DM after scan.\n"); 20738c2ecf20Sopenharmony_ci postprocessing = true; 20748c2ecf20Sopenharmony_ci break; 20758c2ecf20Sopenharmony_ci case IO_CMD_PAUSE_BAND0_DM_BY_SCAN: 20768c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE, 20778c2ecf20Sopenharmony_ci "[IO CMD] Pause DM before scan.\n"); 20788c2ecf20Sopenharmony_ci postprocessing = true; 20798c2ecf20Sopenharmony_ci break; 20808c2ecf20Sopenharmony_ci default: 20818c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_ERR, DBG_LOUD, 20828c2ecf20Sopenharmony_ci "switch case %#x not processed\n", iotype); 20838c2ecf20Sopenharmony_ci break; 20848c2ecf20Sopenharmony_ci } 20858c2ecf20Sopenharmony_ci } while (false); 20868c2ecf20Sopenharmony_ci if (postprocessing && !rtlphy->set_io_inprogress) { 20878c2ecf20Sopenharmony_ci rtlphy->set_io_inprogress = true; 20888c2ecf20Sopenharmony_ci rtlphy->current_io_type = iotype; 20898c2ecf20Sopenharmony_ci } else { 20908c2ecf20Sopenharmony_ci return false; 20918c2ecf20Sopenharmony_ci } 20928c2ecf20Sopenharmony_ci rtl88e_phy_set_io(hw); 20938c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE, "IO Type(%#x)\n", iotype); 20948c2ecf20Sopenharmony_ci return true; 20958c2ecf20Sopenharmony_ci} 20968c2ecf20Sopenharmony_ci 20978c2ecf20Sopenharmony_cistatic void rtl88e_phy_set_io(struct ieee80211_hw *hw) 20988c2ecf20Sopenharmony_ci{ 20998c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 21008c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &rtlpriv->phy; 21018c2ecf20Sopenharmony_ci struct dig_t *dm_digtable = &rtlpriv->dm_digtable; 21028c2ecf20Sopenharmony_ci 21038c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE, 21048c2ecf20Sopenharmony_ci "--->Cmd(%#x), set_io_inprogress(%d)\n", 21058c2ecf20Sopenharmony_ci rtlphy->current_io_type, rtlphy->set_io_inprogress); 21068c2ecf20Sopenharmony_ci switch (rtlphy->current_io_type) { 21078c2ecf20Sopenharmony_ci case IO_CMD_RESUME_DM_BY_SCAN: 21088c2ecf20Sopenharmony_ci dm_digtable->cur_igvalue = rtlphy->initgain_backup.xaagccore1; 21098c2ecf20Sopenharmony_ci /*rtl92c_dm_write_dig(hw);*/ 21108c2ecf20Sopenharmony_ci rtl88e_phy_set_txpower_level(hw, rtlphy->current_channel); 21118c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RCCK0_CCA, 0xff0000, 0x83); 21128c2ecf20Sopenharmony_ci break; 21138c2ecf20Sopenharmony_ci case IO_CMD_PAUSE_BAND0_DM_BY_SCAN: 21148c2ecf20Sopenharmony_ci rtlphy->initgain_backup.xaagccore1 = dm_digtable->cur_igvalue; 21158c2ecf20Sopenharmony_ci dm_digtable->cur_igvalue = 0x17; 21168c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, RCCK0_CCA, 0xff0000, 0x40); 21178c2ecf20Sopenharmony_ci break; 21188c2ecf20Sopenharmony_ci default: 21198c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_ERR, DBG_LOUD, 21208c2ecf20Sopenharmony_ci "switch case %#x not processed\n", 21218c2ecf20Sopenharmony_ci rtlphy->current_io_type); 21228c2ecf20Sopenharmony_ci break; 21238c2ecf20Sopenharmony_ci } 21248c2ecf20Sopenharmony_ci rtlphy->set_io_inprogress = false; 21258c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE, 21268c2ecf20Sopenharmony_ci "(%#x)\n", rtlphy->current_io_type); 21278c2ecf20Sopenharmony_ci} 21288c2ecf20Sopenharmony_ci 21298c2ecf20Sopenharmony_cistatic void rtl88ee_phy_set_rf_on(struct ieee80211_hw *hw) 21308c2ecf20Sopenharmony_ci{ 21318c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 21328c2ecf20Sopenharmony_ci 21338c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x2b); 21348c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE3); 21358c2ecf20Sopenharmony_ci /*rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x00);*/ 21368c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2); 21378c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE3); 21388c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, REG_TXPAUSE, 0x00); 21398c2ecf20Sopenharmony_ci} 21408c2ecf20Sopenharmony_ci 21418c2ecf20Sopenharmony_cistatic void _rtl88ee_phy_set_rf_sleep(struct ieee80211_hw *hw) 21428c2ecf20Sopenharmony_ci{ 21438c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 21448c2ecf20Sopenharmony_ci 21458c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF); 21468c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_A, 0x00, RFREG_OFFSET_MASK, 0x00); 21478c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2); 21488c2ecf20Sopenharmony_ci rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x22); 21498c2ecf20Sopenharmony_ci} 21508c2ecf20Sopenharmony_ci 21518c2ecf20Sopenharmony_cistatic bool _rtl88ee_phy_set_rf_power_state(struct ieee80211_hw *hw, 21528c2ecf20Sopenharmony_ci enum rf_pwrstate rfpwr_state) 21538c2ecf20Sopenharmony_ci{ 21548c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 21558c2ecf20Sopenharmony_ci struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); 21568c2ecf20Sopenharmony_ci struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 21578c2ecf20Sopenharmony_ci struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 21588c2ecf20Sopenharmony_ci bool bresult = true; 21598c2ecf20Sopenharmony_ci u8 i, queue_id; 21608c2ecf20Sopenharmony_ci struct rtl8192_tx_ring *ring = NULL; 21618c2ecf20Sopenharmony_ci 21628c2ecf20Sopenharmony_ci switch (rfpwr_state) { 21638c2ecf20Sopenharmony_ci case ERFON: 21648c2ecf20Sopenharmony_ci if ((ppsc->rfpwr_state == ERFOFF) && 21658c2ecf20Sopenharmony_ci RT_IN_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC)) { 21668c2ecf20Sopenharmony_ci bool rtstatus; 21678c2ecf20Sopenharmony_ci u32 initializecount = 0; 21688c2ecf20Sopenharmony_ci 21698c2ecf20Sopenharmony_ci do { 21708c2ecf20Sopenharmony_ci initializecount++; 21718c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_DMESG, 21728c2ecf20Sopenharmony_ci "IPS Set eRf nic enable\n"); 21738c2ecf20Sopenharmony_ci rtstatus = rtl_ps_enable_nic(hw); 21748c2ecf20Sopenharmony_ci } while (!rtstatus && 21758c2ecf20Sopenharmony_ci (initializecount < 10)); 21768c2ecf20Sopenharmony_ci RT_CLEAR_PS_LEVEL(ppsc, 21778c2ecf20Sopenharmony_ci RT_RF_OFF_LEVL_HALT_NIC); 21788c2ecf20Sopenharmony_ci } else { 21798c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_DMESG, 21808c2ecf20Sopenharmony_ci "Set ERFON slept:%d ms\n", 21818c2ecf20Sopenharmony_ci jiffies_to_msecs(jiffies - 21828c2ecf20Sopenharmony_ci ppsc->last_sleep_jiffies)); 21838c2ecf20Sopenharmony_ci ppsc->last_awake_jiffies = jiffies; 21848c2ecf20Sopenharmony_ci rtl88ee_phy_set_rf_on(hw); 21858c2ecf20Sopenharmony_ci } 21868c2ecf20Sopenharmony_ci if (mac->link_state == MAC80211_LINKED) { 21878c2ecf20Sopenharmony_ci rtlpriv->cfg->ops->led_control(hw, 21888c2ecf20Sopenharmony_ci LED_CTL_LINK); 21898c2ecf20Sopenharmony_ci } else { 21908c2ecf20Sopenharmony_ci rtlpriv->cfg->ops->led_control(hw, 21918c2ecf20Sopenharmony_ci LED_CTL_NO_LINK); 21928c2ecf20Sopenharmony_ci } 21938c2ecf20Sopenharmony_ci break; 21948c2ecf20Sopenharmony_ci case ERFOFF: 21958c2ecf20Sopenharmony_ci for (queue_id = 0, i = 0; 21968c2ecf20Sopenharmony_ci queue_id < RTL_PCI_MAX_TX_QUEUE_COUNT;) { 21978c2ecf20Sopenharmony_ci ring = &pcipriv->dev.tx_ring[queue_id]; 21988c2ecf20Sopenharmony_ci if (queue_id == BEACON_QUEUE || 21998c2ecf20Sopenharmony_ci skb_queue_len(&ring->queue) == 0) { 22008c2ecf20Sopenharmony_ci queue_id++; 22018c2ecf20Sopenharmony_ci continue; 22028c2ecf20Sopenharmony_ci } else { 22038c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_ERR, DBG_WARNING, 22048c2ecf20Sopenharmony_ci "eRf Off/Sleep: %d times TcbBusyQueue[%d] =%d before doze!\n", 22058c2ecf20Sopenharmony_ci (i + 1), queue_id, 22068c2ecf20Sopenharmony_ci skb_queue_len(&ring->queue)); 22078c2ecf20Sopenharmony_ci 22088c2ecf20Sopenharmony_ci udelay(10); 22098c2ecf20Sopenharmony_ci i++; 22108c2ecf20Sopenharmony_ci } 22118c2ecf20Sopenharmony_ci if (i >= MAX_DOZE_WAITING_TIMES_9x) { 22128c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_ERR, DBG_WARNING, 22138c2ecf20Sopenharmony_ci "\n ERFSLEEP: %d times TcbBusyQueue[%d] = %d !\n", 22148c2ecf20Sopenharmony_ci MAX_DOZE_WAITING_TIMES_9x, 22158c2ecf20Sopenharmony_ci queue_id, 22168c2ecf20Sopenharmony_ci skb_queue_len(&ring->queue)); 22178c2ecf20Sopenharmony_ci break; 22188c2ecf20Sopenharmony_ci } 22198c2ecf20Sopenharmony_ci } 22208c2ecf20Sopenharmony_ci 22218c2ecf20Sopenharmony_ci if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC) { 22228c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_DMESG, 22238c2ecf20Sopenharmony_ci "IPS Set eRf nic disable\n"); 22248c2ecf20Sopenharmony_ci rtl_ps_disable_nic(hw); 22258c2ecf20Sopenharmony_ci RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC); 22268c2ecf20Sopenharmony_ci } else { 22278c2ecf20Sopenharmony_ci if (ppsc->rfoff_reason == RF_CHANGE_BY_IPS) { 22288c2ecf20Sopenharmony_ci rtlpriv->cfg->ops->led_control(hw, 22298c2ecf20Sopenharmony_ci LED_CTL_NO_LINK); 22308c2ecf20Sopenharmony_ci } else { 22318c2ecf20Sopenharmony_ci rtlpriv->cfg->ops->led_control(hw, 22328c2ecf20Sopenharmony_ci LED_CTL_POWER_OFF); 22338c2ecf20Sopenharmony_ci } 22348c2ecf20Sopenharmony_ci } 22358c2ecf20Sopenharmony_ci break; 22368c2ecf20Sopenharmony_ci case ERFSLEEP:{ 22378c2ecf20Sopenharmony_ci if (ppsc->rfpwr_state == ERFOFF) 22388c2ecf20Sopenharmony_ci break; 22398c2ecf20Sopenharmony_ci for (queue_id = 0, i = 0; 22408c2ecf20Sopenharmony_ci queue_id < RTL_PCI_MAX_TX_QUEUE_COUNT;) { 22418c2ecf20Sopenharmony_ci ring = &pcipriv->dev.tx_ring[queue_id]; 22428c2ecf20Sopenharmony_ci if (skb_queue_len(&ring->queue) == 0) { 22438c2ecf20Sopenharmony_ci queue_id++; 22448c2ecf20Sopenharmony_ci continue; 22458c2ecf20Sopenharmony_ci } else { 22468c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_ERR, DBG_WARNING, 22478c2ecf20Sopenharmony_ci "eRf Off/Sleep: %d times TcbBusyQueue[%d] =%d before doze!\n", 22488c2ecf20Sopenharmony_ci (i + 1), queue_id, 22498c2ecf20Sopenharmony_ci skb_queue_len(&ring->queue)); 22508c2ecf20Sopenharmony_ci 22518c2ecf20Sopenharmony_ci udelay(10); 22528c2ecf20Sopenharmony_ci i++; 22538c2ecf20Sopenharmony_ci } 22548c2ecf20Sopenharmony_ci if (i >= MAX_DOZE_WAITING_TIMES_9x) { 22558c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_ERR, DBG_WARNING, 22568c2ecf20Sopenharmony_ci "\n ERFSLEEP: %d times TcbBusyQueue[%d] = %d !\n", 22578c2ecf20Sopenharmony_ci MAX_DOZE_WAITING_TIMES_9x, 22588c2ecf20Sopenharmony_ci queue_id, 22598c2ecf20Sopenharmony_ci skb_queue_len(&ring->queue)); 22608c2ecf20Sopenharmony_ci break; 22618c2ecf20Sopenharmony_ci } 22628c2ecf20Sopenharmony_ci } 22638c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_DMESG, 22648c2ecf20Sopenharmony_ci "Set ERFSLEEP awaked:%d ms\n", 22658c2ecf20Sopenharmony_ci jiffies_to_msecs(jiffies - 22668c2ecf20Sopenharmony_ci ppsc->last_awake_jiffies)); 22678c2ecf20Sopenharmony_ci ppsc->last_sleep_jiffies = jiffies; 22688c2ecf20Sopenharmony_ci _rtl88ee_phy_set_rf_sleep(hw); 22698c2ecf20Sopenharmony_ci break; 22708c2ecf20Sopenharmony_ci } 22718c2ecf20Sopenharmony_ci default: 22728c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_ERR, DBG_LOUD, 22738c2ecf20Sopenharmony_ci "switch case %#x not processed\n", rfpwr_state); 22748c2ecf20Sopenharmony_ci bresult = false; 22758c2ecf20Sopenharmony_ci break; 22768c2ecf20Sopenharmony_ci } 22778c2ecf20Sopenharmony_ci if (bresult) 22788c2ecf20Sopenharmony_ci ppsc->rfpwr_state = rfpwr_state; 22798c2ecf20Sopenharmony_ci return bresult; 22808c2ecf20Sopenharmony_ci} 22818c2ecf20Sopenharmony_ci 22828c2ecf20Sopenharmony_cibool rtl88e_phy_set_rf_power_state(struct ieee80211_hw *hw, 22838c2ecf20Sopenharmony_ci enum rf_pwrstate rfpwr_state) 22848c2ecf20Sopenharmony_ci{ 22858c2ecf20Sopenharmony_ci struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 22868c2ecf20Sopenharmony_ci 22878c2ecf20Sopenharmony_ci bool bresult = false; 22888c2ecf20Sopenharmony_ci 22898c2ecf20Sopenharmony_ci if (rfpwr_state == ppsc->rfpwr_state) 22908c2ecf20Sopenharmony_ci return bresult; 22918c2ecf20Sopenharmony_ci bresult = _rtl88ee_phy_set_rf_power_state(hw, rfpwr_state); 22928c2ecf20Sopenharmony_ci return bresult; 22938c2ecf20Sopenharmony_ci} 2294