46 for (i = 0; i <= 31; i++) {
47 if (((bitmask >> i) & 0x1) == 1)
57 u32 returnvalue = 0, originalvalue, bitshift;
62 originalvalue = rtl_read_dword(rtlpriv, regaddr);
63 bitshift = _rtl92s_phy_calculate_bit_shift(bitmask);
64 returnvalue = (originalvalue &
bitmask) >> bitshift;
67 bitmask, regaddr, originalvalue);
77 u32 originalvalue, bitshift;
80 "regaddr(%#x), bitmask(%#x), data(%#x)\n",
81 regaddr, bitmask, data);
84 originalvalue = rtl_read_dword(rtlpriv, regaddr);
85 bitshift = _rtl92s_phy_calculate_bit_shift(bitmask);
86 data = ((originalvalue & (~bitmask)) | (data << bitshift));
89 rtl_write_dword(rtlpriv, regaddr, data);
92 "regaddr(%#x), bitmask(%#x), data(%#x)\n",
93 regaddr, bitmask, data);
105 u32 tmplong, tmplong2;
158 static void _rtl92s_phy_rf_serial_write(
struct ieee80211_hw *hw,
165 u32 data_and_addr = 0;
171 data_and_addr = ((newoffset << 20) | (data & 0x000fffff)) & 0x0fffffff;
183 u32 original_value, readback_value, bitshift;
186 "regaddr(%#x), rfpath(%#x), bitmask(%#x)\n",
187 regaddr, rfpath, bitmask);
189 spin_lock(&rtlpriv->
locks.rf_lock);
191 original_value = _rtl92s_phy_rf_serial_read(hw, rfpath, regaddr);
193 bitshift = _rtl92s_phy_calculate_bit_shift(bitmask);
194 readback_value = (original_value &
bitmask) >> bitshift;
196 spin_unlock(&rtlpriv->
locks.rf_lock);
199 "regaddr(%#x), rfpath(%#x), bitmask(%#x), original_value(%#x)\n",
200 regaddr, rfpath, bitmask, original_value);
202 return readback_value;
210 u32 original_value, bitshift;
216 "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
217 regaddr, bitmask, data, rfpath);
219 spin_lock(&rtlpriv->
locks.rf_lock);
222 original_value = _rtl92s_phy_rf_serial_read(hw, rfpath,
224 bitshift = _rtl92s_phy_calculate_bit_shift(bitmask);
225 data = ((original_value & (~bitmask)) | (data << bitshift));
228 _rtl92s_phy_rf_serial_write(hw, rfpath, regaddr, data);
230 spin_unlock(&rtlpriv->
locks.rf_lock);
233 "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
234 regaddr, bitmask, data, rfpath);
244 if (!is_hal_stop(rtlhal)) {
254 "Unknown operation\n");
275 if (is_hal_stop(rtlhal))
280 reg_bw_opmode = rtl_read_byte(rtlpriv,
BW_OPMODE);
282 rtl_read_byte(rtlpriv,
RRSR + 2);
287 rtl_write_byte(rtlpriv,
BW_OPMODE, reg_bw_opmode);
291 rtl_write_byte(rtlpriv,
BW_OPMODE, reg_bw_opmode);
329 static bool _rtl92s_phy_set_sw_chnl_cmdarray(
struct swchnlcmd *cmdtable,
335 if (cmdtable ==
NULL) {
336 RT_ASSERT(
false,
"cmdtable cannot be NULL\n");
340 if (cmdtableidx >= cmdtablesz)
343 pcmd = cmdtable + cmdtableidx;
352 static bool _rtl92s_phy_sw_chnl_step_by_step(
struct ieee80211_hw *hw,
360 u32 postcommoncmdcnt;
368 _rtl92s_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++,
370 _rtl92s_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++,
373 postcommoncmdcnt = 0;
375 _rtl92s_phy_set_sw_chnl_cmdarray(postcommoncmd, postcommoncmdcnt++,
380 RT_ASSERT((channel >= 1 && channel <= 14),
381 "invalid channel for Zebra: %d\n", channel);
383 _rtl92s_phy_set_sw_chnl_cmdarray(rfdependcmd, rfdependcmdcnt++,
387 _rtl92s_phy_set_sw_chnl_cmdarray(rfdependcmd, rfdependcmdcnt++,
393 currentcmd = &precommoncmd[*
step];
396 currentcmd = &rfdependcmd[*
step];
399 currentcmd = &postcommoncmd[*
step];
413 switch (currentcmd->
cmdid) {
418 rtl_write_dword(rtlpriv, currentcmd->
para1,
422 rtl_write_word(rtlpriv, currentcmd->
para1,
426 rtl_write_byte(rtlpriv, currentcmd->
para1,
430 for (rfpath = 0; rfpath < num_total_rfpath; rfpath++) {
433 0xfffffc00) | currentcmd->
para2);
442 "switch case not processed\n");
449 (*delay) = currentcmd->
msdelay;
471 if (is_hal_stop(rtlhal))
482 ret = _rtl92s_phy_sw_chnl_step_by_step(hw,
504 static void _rtl92se_phy_set_rf_sleep(
struct ieee80211_hw *hw)
514 rtl_write_byte(rtlpriv,
TXPAUSE, 0xFF);
515 rtl_write_word(rtlpriv,
CMDR, 0x57FC);
518 rtl_write_word(rtlpriv,
CMDR, 0x77FC);
519 rtl_write_byte(rtlpriv,
PHY_CCA, 0x0);
522 rtl_write_word(rtlpriv,
CMDR, 0x37FC);
525 rtl_write_word(rtlpriv,
CMDR, 0x77FC);
528 rtl_write_word(rtlpriv,
CMDR, 0x57FC);
549 switch (rfpwr_state) {
555 u32 InitializeCount = 0;
559 "IPS Set eRf nic enable\n");
561 }
while (!rtstatus && (InitializeCount < 10));
567 "awake, sleeped:%d ms state_inap:%x\n",
571 rtlpriv->
psc.state_inap);
573 rtl_write_word(rtlpriv,
CMDR, 0x37FC);
574 rtl_write_byte(rtlpriv,
TXPAUSE, 0x00);
575 rtl_write_byte(rtlpriv,
PHY_CCA, 0x3);
579 rtlpriv->
cfg->ops->led_control(hw,
582 rtlpriv->
cfg->ops->led_control(hw,
589 "IPS Set eRf nic disable\n");
594 rtlpriv->
cfg->ops->led_control(hw,
597 rtlpriv->
cfg->ops->led_control(hw,
606 for (queue_id = 0, i = 0;
608 ring = &pcipriv->
dev.tx_ring[queue_id];
609 if (skb_queue_len(&ring->
queue) == 0 ||
615 "eRf Off/Sleep: %d times TcbBusyQueue[%d] = %d before doze!\n",
617 skb_queue_len(&ring->
queue));
625 "ERFOFF: %d times TcbBusyQueue[%d] = %d !\n",
628 skb_queue_len(&ring->
queue));
634 "Set ERFSLEEP awaked:%d ms\n",
639 "sleep awaked:%d ms state_inap:%x\n",
642 rtlpriv->
psc.state_inap);
644 _rtl92se_phy_set_rf_sleep(hw);
648 "switch case not processed\n");
659 static bool _rtl92s_phy_config_rfpa_bias_current(
struct ieee80211_hw *hw,
663 bool rtstatus =
true;
675 static void _rtl92s_store_pwrindex_diffrate_offset(
struct ieee80211_hw *hw,
704 static void _rtl92s_phy_init_register_definition(
struct ieee80211_hw *hw)
844 u16 phy_reg_len, agc_len;
853 for (i = 0; i < phy_reg_len; i = i + 2) {
854 if (phy_reg_table[i] == 0xfe)
856 else if (phy_reg_table[i] == 0xfd)
858 else if (phy_reg_table[i] == 0xfc)
860 else if (phy_reg_table[i] == 0xfb)
862 else if (phy_reg_table[i] == 0xfa)
864 else if (phy_reg_table[i] == 0xf9)
871 phy_reg_table[i + 1]);
874 for (i = 0; i < agc_len; i = i + 2) {
886 static bool _rtl92s_phy_set_bb_to_diff_rf(
struct ieee80211_hw *hw,
891 u32 *phy_regarray2xtxr_table;
892 u16 phy_regarray2xtxr_len;
906 for (i = 0; i < phy_regarray2xtxr_len; i = i + 3) {
907 if (phy_regarray2xtxr_table[i] == 0xfe)
909 else if (phy_regarray2xtxr_table[i] == 0xfd)
911 else if (phy_regarray2xtxr_table[i] == 0xfc)
913 else if (phy_regarray2xtxr_table[i] == 0xfb)
915 else if (phy_regarray2xtxr_table[i] == 0xfa)
917 else if (phy_regarray2xtxr_table[i] == 0xf9)
921 phy_regarray2xtxr_table[i + 1],
922 phy_regarray2xtxr_table[i + 2]);
929 static bool _rtl92s_phy_config_bb_with_pg(
struct ieee80211_hw *hw,
940 for (i = 0; i < phy_pg_len; i = i + 3) {
941 if (phy_table_pg[i] == 0xfe)
943 else if (phy_table_pg[i] == 0xfd)
945 else if (phy_table_pg[i] == 0xfc)
947 else if (phy_table_pg[i] == 0xfb)
949 else if (phy_table_pg[i] == 0xfa)
951 else if (phy_table_pg[i] == 0xf9)
954 _rtl92s_store_pwrindex_diffrate_offset(hw,
957 phy_table_pg[i + 2]);
960 phy_table_pg[i + 2]);
967 static bool _rtl92s_phy_bb_config_parafile(
struct ieee80211_hw *hw)
972 bool rtstatus =
true;
984 rtstatus = _rtl92s_phy_set_bb_to_diff_rf(hw,
992 "Write BB Reg Fail!!\n");
993 goto phy_BB8190_Config_ParaFile_Fail;
1001 rtstatus = _rtl92s_phy_config_bb_with_pg(hw,
1006 "_rtl92s_phy_bb_config_parafile(): BB_PG Reg Fail!!\n");
1007 goto phy_BB8190_Config_ParaFile_Fail;
1014 pr_err(
"%s(): AGC Table Fail\n", __func__);
1015 goto phy_BB8190_Config_ParaFile_Fail;
1023 phy_BB8190_Config_ParaFile_Fail:
1032 bool rtstatus =
true;
1035 u16 radio_a_tblen, radio_b_tblen;
1054 for (i = 0; i < radio_a_tblen; i = i + 2) {
1055 if (radio_a_table[i] == 0xfe)
1059 else if (radio_a_table[i] == 0xfd)
1061 else if (radio_a_table[i] == 0xfc)
1063 else if (radio_a_table[i] == 0xfb)
1065 else if (radio_a_table[i] == 0xfa)
1067 else if (radio_a_table[i] == 0xf9)
1073 radio_a_table[i + 1]);
1080 _rtl92s_phy_config_rfpa_bias_current(hw, rfpath);
1083 for (i = 0; i < radio_b_tblen; i = i + 2) {
1084 if (radio_b_table[i] == 0xfe)
1088 else if (radio_b_table[i] == 0xfd)
1090 else if (radio_b_table[i] == 0xfc)
1092 else if (radio_b_table[i] == 0xfb)
1094 else if (radio_b_table[i] == 0xfa)
1096 else if (radio_b_table[i] == 0xf9)
1102 radio_b_table[i + 1]);
1132 for (i = 0; i < arraylength; i = i + 2)
1133 rtl_write_byte(rtlpriv, ptraArray[i], (
u8)ptraArray[i + 1]);
1143 bool rtstatus =
true;
1144 u8 pathmap,
index, rf_num = 0;
1147 _rtl92s_phy_init_register_definition(hw);
1150 rtstatus = _rtl92s_phy_bb_config_parafile(hw);
1158 pathmap = path1 | path2;
1161 for (index = 0; index < 4; index++) {
1162 if ((pathmap >> index) & 0x1)
1171 "RF_Type(%x) does not match RF_Num(%x)!!\n",
1174 "path1 0x%x, path2 0x%x, pathmap 0x%x\n",
1175 path1, path2, pathmap);
1211 "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x)\n",
1222 "Default framesync (0x%x) = 0x%x\n",
1227 static void _rtl92s_phy_get_txpower_index(
struct ieee80211_hw *hw,
u8 channel,
1228 u8 *cckpowerlevel,
u8 *ofdmpowerLevel)
1233 u8 index = (channel - 1);
1251 ofdmpowerLevel[0] = 0;
1252 ofdmpowerLevel[1] = 0;
1256 static void _rtl92s_phy_ccxpower_indexcheck(
struct ieee80211_hw *hw,
1257 u8 channel,
u8 *cckpowerlevel,
u8 *ofdmpowerlevel)
1271 u8 cckpowerlevel[2], ofdmpowerLevel[2];
1282 _rtl92s_phy_get_txpower_index(hw, channel, &cckpowerlevel[0],
1283 &ofdmpowerLevel[0]);
1286 "Channel-%d, cckPowerLevel (A / B) = 0x%x / 0x%x, ofdmPowerLevel (A / B) = 0x%x / 0x%x\n",
1287 channel, cckpowerlevel[0], cckpowerlevel[1],
1288 ofdmpowerLevel[0], ofdmpowerLevel[1]);
1290 _rtl92s_phy_ccxpower_indexcheck(hw, channel, &cckpowerlevel[0],
1291 &ofdmpowerLevel[0]);
1301 u16 pollingcnt = 10000;
1308 tmpvalue = rtl_read_dword(rtlpriv,
WFM5);
1311 }
while (--pollingcnt);
1313 if (pollingcnt == 0)
1318 static void _rtl92s_phy_set_fwcmd_io(
struct ieee80211_hw *hw)
1325 if (is_hal_stop(rtlhal))
1355 rtl_write_dword(rtlpriv,
WFM5, input);
1362 "FW_CMD_RA_REFRESH_BG\n");
1370 "FW_CMD_RA_REFRESH_N_COMB\n");
1372 rtl_write_dword(rtlpriv,
WFM5, input);
1377 "FW_CMD_RA_REFRESH_BG_COMB\n");
1379 rtl_write_dword(rtlpriv,
WFM5, input);
1411 rtlpriv->
dm.dynamic_txpower_enable)
1419 current_aid = rtlpriv->
mac80211.assoc_id;
1421 ((current_aid | 0xc000) << 8)));
1438 "FW_CMD_CTRL_DM_BY_DRIVER\n");
1461 bool bPostProcessing =
false;
1464 "Set FW Cmd(%#x), set_fwcmd_inprogress(%d)\n",
1501 "Set DIG disable!!\n");
1509 "Set DIG enable or resume!!\n");
1516 "Set DIG halt!!\n");
1527 thermalval = rtlpriv->
dm.thermalvalue;
1528 fw_param |= ((thermalval << 24) |
1532 "Set TxPwr tracking!! FwCmdMap(%#x), FwParam(%#x)\n",
1533 fw_cmdmap, fw_param);
1554 "[FW CMD] [New Version] Set RA/IOT Comb in n mode!! FwCmdMap(%#x), FwParam(%#x)\n",
1555 fw_cmdmap, fw_param);
1599 rtlpriv->
dm.dynamic_txpower_enable)
1609 bPostProcessing =
true;
1616 bPostProcessing =
true;
1621 bPostProcessing =
true;
1625 !rtlpriv->
dm.dynamic_txpower_enable) {
1629 bPostProcessing =
true;
1642 "[FW CMD] Set PAPE Control\n");
1650 bPostProcessing =
true;
1665 _rtl92s_phy_set_fwcmd_io(hw);
1669 static void _rtl92s_phy_check_ephy_switchready(
struct ieee80211_hw *hw)
1675 regu1 = rtl_read_byte(rtlpriv, 0x554);
1676 while ((regu1 &
BIT(5)) && (delay > 0)) {
1677 regu1 = rtl_read_byte(rtlpriv, 0x554);
1694 rtl_write_dword(rtlpriv, 0x540, 0x73c11);
1695 rtl_write_dword(rtlpriv, 0x548, 0x2407c);
1698 rtl_write_word(rtlpriv, 0x550, 0x1000);
1699 rtl_write_byte(rtlpriv, 0x554, 0x20);
1700 _rtl92s_phy_check_ephy_switchready(hw);
1702 rtl_write_word(rtlpriv, 0x550, 0xa0eb);
1703 rtl_write_byte(rtlpriv, 0x554, 0x3e);
1704 _rtl92s_phy_check_ephy_switchready(hw);
1706 rtl_write_word(rtlpriv, 0x550, 0xff80);
1707 rtl_write_byte(rtlpriv, 0x554, 0x39);
1708 _rtl92s_phy_check_ephy_switchready(hw);
1712 rtl_write_byte(rtlpriv, 0x560, 0x40);
1714 rtl_write_byte(rtlpriv, 0x560, 0x00);
1721 rtl_write_dword(rtlpriv,
WFM5, 0xF1000000 | (BeaconInterval << 8));