162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci/* Copyright(c) 2009-2012 Realtek Corporation.*/ 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci#include "../wifi.h" 562306a36Sopenharmony_ci#include "../pci.h" 662306a36Sopenharmony_ci#include "../ps.h" 762306a36Sopenharmony_ci#include "../core.h" 862306a36Sopenharmony_ci#include "reg.h" 962306a36Sopenharmony_ci#include "def.h" 1062306a36Sopenharmony_ci#include "phy.h" 1162306a36Sopenharmony_ci#include "rf.h" 1262306a36Sopenharmony_ci#include "dm.h" 1362306a36Sopenharmony_ci#include "table.h" 1462306a36Sopenharmony_ci#include "sw.h" 1562306a36Sopenharmony_ci#include "hw.h" 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#define MAX_RF_IMR_INDEX 12 1862306a36Sopenharmony_ci#define MAX_RF_IMR_INDEX_NORMAL 13 1962306a36Sopenharmony_ci#define RF_REG_NUM_FOR_C_CUT_5G 6 2062306a36Sopenharmony_ci#define RF_REG_NUM_FOR_C_CUT_5G_INTERNALPA 7 2162306a36Sopenharmony_ci#define RF_REG_NUM_FOR_C_CUT_2G 5 2262306a36Sopenharmony_ci#define RF_CHNL_NUM_5G 19 2362306a36Sopenharmony_ci#define RF_CHNL_NUM_5G_40M 17 2462306a36Sopenharmony_ci#define TARGET_CHNL_NUM_5G 221 2562306a36Sopenharmony_ci#define TARGET_CHNL_NUM_2G 14 2662306a36Sopenharmony_ci#define CV_CURVE_CNT 64 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_cistatic u32 rf_reg_for_5g_swchnl_normal[MAX_RF_IMR_INDEX_NORMAL] = { 2962306a36Sopenharmony_ci 0, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x0 3062306a36Sopenharmony_ci}; 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_cistatic u8 rf_reg_for_c_cut_5g[RF_REG_NUM_FOR_C_CUT_5G] = { 3362306a36Sopenharmony_ci RF_SYN_G1, RF_SYN_G2, RF_SYN_G3, RF_SYN_G4, RF_SYN_G5, RF_SYN_G6 3462306a36Sopenharmony_ci}; 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_cistatic u8 rf_reg_for_c_cut_2g[RF_REG_NUM_FOR_C_CUT_2G] = { 3762306a36Sopenharmony_ci RF_SYN_G1, RF_SYN_G2, RF_SYN_G3, RF_SYN_G7, RF_SYN_G8 3862306a36Sopenharmony_ci}; 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_cistatic u8 rf_for_c_cut_5g_internal_pa[RF_REG_NUM_FOR_C_CUT_5G_INTERNALPA] = { 4162306a36Sopenharmony_ci 0x0B, 0x48, 0x49, 0x4B, 0x03, 0x04, 0x0E 4262306a36Sopenharmony_ci}; 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_cistatic u32 rf_reg_mask_for_c_cut_2g[RF_REG_NUM_FOR_C_CUT_2G] = { 4562306a36Sopenharmony_ci BIT(19) | BIT(18) | BIT(17) | BIT(14) | BIT(1), 4662306a36Sopenharmony_ci BIT(10) | BIT(9), 4762306a36Sopenharmony_ci BIT(18) | BIT(17) | BIT(16) | BIT(1), 4862306a36Sopenharmony_ci BIT(2) | BIT(1), 4962306a36Sopenharmony_ci BIT(15) | BIT(14) | BIT(13) | BIT(12) | BIT(11) 5062306a36Sopenharmony_ci}; 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_cistatic u8 rf_chnl_5g[RF_CHNL_NUM_5G] = { 5362306a36Sopenharmony_ci 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 5462306a36Sopenharmony_ci 112, 116, 120, 124, 128, 132, 136, 140 5562306a36Sopenharmony_ci}; 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_cistatic u8 rf_chnl_5g_40m[RF_CHNL_NUM_5G_40M] = { 5862306a36Sopenharmony_ci 38, 42, 46, 50, 54, 58, 62, 102, 106, 110, 114, 5962306a36Sopenharmony_ci 118, 122, 126, 130, 134, 138 6062306a36Sopenharmony_ci}; 6162306a36Sopenharmony_cistatic u32 rf_reg_pram_c_5g[5][RF_REG_NUM_FOR_C_CUT_5G] = { 6262306a36Sopenharmony_ci {0xE43BE, 0xFC638, 0x77C0A, 0xDE471, 0xd7110, 0x8EB04}, 6362306a36Sopenharmony_ci {0xE43BE, 0xFC078, 0xF7C1A, 0xE0C71, 0xD7550, 0xAEB04}, 6462306a36Sopenharmony_ci {0xE43BF, 0xFF038, 0xF7C0A, 0xDE471, 0xE5550, 0xAEB04}, 6562306a36Sopenharmony_ci {0xE43BF, 0xFF079, 0xF7C1A, 0xDE471, 0xE5550, 0xAEB04}, 6662306a36Sopenharmony_ci {0xE43BF, 0xFF038, 0xF7C1A, 0xDE471, 0xd7550, 0xAEB04} 6762306a36Sopenharmony_ci}; 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_cistatic u32 rf_reg_param_for_c_cut_2g[3][RF_REG_NUM_FOR_C_CUT_2G] = { 7062306a36Sopenharmony_ci {0x643BC, 0xFC038, 0x77C1A, 0x41289, 0x01840}, 7162306a36Sopenharmony_ci {0x643BC, 0xFC038, 0x07C1A, 0x41289, 0x01840}, 7262306a36Sopenharmony_ci {0x243BC, 0xFC438, 0x07C1A, 0x4128B, 0x0FC41} 7362306a36Sopenharmony_ci}; 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_cistatic u32 rf_syn_g4_for_c_cut_2g = 0xD1C31 & 0x7FF; 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_cistatic u32 rf_pram_c_5g_int_pa[3][RF_REG_NUM_FOR_C_CUT_5G_INTERNALPA] = { 7862306a36Sopenharmony_ci {0x01a00, 0x40443, 0x00eb5, 0x89bec, 0x94a12, 0x94a12, 0x94a12}, 7962306a36Sopenharmony_ci {0x01800, 0xc0443, 0x00730, 0x896ee, 0x94a52, 0x94a52, 0x94a52}, 8062306a36Sopenharmony_ci {0x01800, 0xc0443, 0x00730, 0x896ee, 0x94a12, 0x94a12, 0x94a12} 8162306a36Sopenharmony_ci}; 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci/* [mode][patha+b][reg] */ 8462306a36Sopenharmony_cistatic u32 rf_imr_param_normal[1][3][MAX_RF_IMR_INDEX_NORMAL] = { 8562306a36Sopenharmony_ci { 8662306a36Sopenharmony_ci /* channel 1-14. */ 8762306a36Sopenharmony_ci { 8862306a36Sopenharmony_ci 0x70000, 0x00ff0, 0x4400f, 0x00ff0, 0x0, 0x0, 0x0, 8962306a36Sopenharmony_ci 0x0, 0x0, 0x64888, 0xe266c, 0x00090, 0x22fff 9062306a36Sopenharmony_ci }, 9162306a36Sopenharmony_ci /* path 36-64 */ 9262306a36Sopenharmony_ci { 9362306a36Sopenharmony_ci 0x70000, 0x22880, 0x4470f, 0x55880, 0x00070, 0x88000, 9462306a36Sopenharmony_ci 0x0, 0x88080, 0x70000, 0x64a82, 0xe466c, 0x00090, 9562306a36Sopenharmony_ci 0x32c9a 9662306a36Sopenharmony_ci }, 9762306a36Sopenharmony_ci /* 100 -165 */ 9862306a36Sopenharmony_ci { 9962306a36Sopenharmony_ci 0x70000, 0x44880, 0x4477f, 0x77880, 0x00070, 0x88000, 10062306a36Sopenharmony_ci 0x0, 0x880b0, 0x0, 0x64b82, 0xe466c, 0x00090, 0x32c9a 10162306a36Sopenharmony_ci } 10262306a36Sopenharmony_ci } 10362306a36Sopenharmony_ci}; 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_cistatic u32 curveindex_5g[TARGET_CHNL_NUM_5G] = {0}; 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_cistatic u32 curveindex_2g[TARGET_CHNL_NUM_2G] = {0}; 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_cistatic u32 targetchnl_5g[TARGET_CHNL_NUM_5G] = { 11062306a36Sopenharmony_ci 25141, 25116, 25091, 25066, 25041, 11162306a36Sopenharmony_ci 25016, 24991, 24966, 24941, 24917, 11262306a36Sopenharmony_ci 24892, 24867, 24843, 24818, 24794, 11362306a36Sopenharmony_ci 24770, 24765, 24721, 24697, 24672, 11462306a36Sopenharmony_ci 24648, 24624, 24600, 24576, 24552, 11562306a36Sopenharmony_ci 24528, 24504, 24480, 24457, 24433, 11662306a36Sopenharmony_ci 24409, 24385, 24362, 24338, 24315, 11762306a36Sopenharmony_ci 24291, 24268, 24245, 24221, 24198, 11862306a36Sopenharmony_ci 24175, 24151, 24128, 24105, 24082, 11962306a36Sopenharmony_ci 24059, 24036, 24013, 23990, 23967, 12062306a36Sopenharmony_ci 23945, 23922, 23899, 23876, 23854, 12162306a36Sopenharmony_ci 23831, 23809, 23786, 23764, 23741, 12262306a36Sopenharmony_ci 23719, 23697, 23674, 23652, 23630, 12362306a36Sopenharmony_ci 23608, 23586, 23564, 23541, 23519, 12462306a36Sopenharmony_ci 23498, 23476, 23454, 23432, 23410, 12562306a36Sopenharmony_ci 23388, 23367, 23345, 23323, 23302, 12662306a36Sopenharmony_ci 23280, 23259, 23237, 23216, 23194, 12762306a36Sopenharmony_ci 23173, 23152, 23130, 23109, 23088, 12862306a36Sopenharmony_ci 23067, 23046, 23025, 23003, 22982, 12962306a36Sopenharmony_ci 22962, 22941, 22920, 22899, 22878, 13062306a36Sopenharmony_ci 22857, 22837, 22816, 22795, 22775, 13162306a36Sopenharmony_ci 22754, 22733, 22713, 22692, 22672, 13262306a36Sopenharmony_ci 22652, 22631, 22611, 22591, 22570, 13362306a36Sopenharmony_ci 22550, 22530, 22510, 22490, 22469, 13462306a36Sopenharmony_ci 22449, 22429, 22409, 22390, 22370, 13562306a36Sopenharmony_ci 22350, 22336, 22310, 22290, 22271, 13662306a36Sopenharmony_ci 22251, 22231, 22212, 22192, 22173, 13762306a36Sopenharmony_ci 22153, 22134, 22114, 22095, 22075, 13862306a36Sopenharmony_ci 22056, 22037, 22017, 21998, 21979, 13962306a36Sopenharmony_ci 21960, 21941, 21921, 21902, 21883, 14062306a36Sopenharmony_ci 21864, 21845, 21826, 21807, 21789, 14162306a36Sopenharmony_ci 21770, 21751, 21732, 21713, 21695, 14262306a36Sopenharmony_ci 21676, 21657, 21639, 21620, 21602, 14362306a36Sopenharmony_ci 21583, 21565, 21546, 21528, 21509, 14462306a36Sopenharmony_ci 21491, 21473, 21454, 21436, 21418, 14562306a36Sopenharmony_ci 21400, 21381, 21363, 21345, 21327, 14662306a36Sopenharmony_ci 21309, 21291, 21273, 21255, 21237, 14762306a36Sopenharmony_ci 21219, 21201, 21183, 21166, 21148, 14862306a36Sopenharmony_ci 21130, 21112, 21095, 21077, 21059, 14962306a36Sopenharmony_ci 21042, 21024, 21007, 20989, 20972, 15062306a36Sopenharmony_ci 25679, 25653, 25627, 25601, 25575, 15162306a36Sopenharmony_ci 25549, 25523, 25497, 25471, 25446, 15262306a36Sopenharmony_ci 25420, 25394, 25369, 25343, 25318, 15362306a36Sopenharmony_ci 25292, 25267, 25242, 25216, 25191, 15462306a36Sopenharmony_ci 25166 15562306a36Sopenharmony_ci}; 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ci/* channel 1~14 */ 15862306a36Sopenharmony_cistatic u32 targetchnl_2g[TARGET_CHNL_NUM_2G] = { 15962306a36Sopenharmony_ci 26084, 26030, 25976, 25923, 25869, 25816, 25764, 16062306a36Sopenharmony_ci 25711, 25658, 25606, 25554, 25502, 25451, 25328 16162306a36Sopenharmony_ci}; 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_cistatic const u8 channel_all[59] = { 16462306a36Sopenharmony_ci 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16562306a36Sopenharmony_ci 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 16662306a36Sopenharmony_ci 60, 62, 64, 100, 102, 104, 106, 108, 110, 112, 16762306a36Sopenharmony_ci 114, 116, 118, 120, 122, 124, 126, 128, 130, 16862306a36Sopenharmony_ci 132, 134, 136, 138, 140, 149, 151, 153, 155, 16962306a36Sopenharmony_ci 157, 159, 161, 163, 165 17062306a36Sopenharmony_ci}; 17162306a36Sopenharmony_ci 17262306a36Sopenharmony_ciu32 rtl92d_phy_query_bb_reg(struct ieee80211_hw *hw, u32 regaddr, u32 bitmask) 17362306a36Sopenharmony_ci{ 17462306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 17562306a36Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 17662306a36Sopenharmony_ci u32 returnvalue, originalvalue, bitshift; 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, "regaddr(%#x), bitmask(%#x)\n", 17962306a36Sopenharmony_ci regaddr, bitmask); 18062306a36Sopenharmony_ci if (rtlhal->during_mac1init_radioa || rtlhal->during_mac0init_radiob) { 18162306a36Sopenharmony_ci u8 dbi_direct = 0; 18262306a36Sopenharmony_ci 18362306a36Sopenharmony_ci /* mac1 use phy0 read radio_b. */ 18462306a36Sopenharmony_ci /* mac0 use phy1 read radio_b. */ 18562306a36Sopenharmony_ci if (rtlhal->during_mac1init_radioa) 18662306a36Sopenharmony_ci dbi_direct = BIT(3); 18762306a36Sopenharmony_ci else if (rtlhal->during_mac0init_radiob) 18862306a36Sopenharmony_ci dbi_direct = BIT(3) | BIT(2); 18962306a36Sopenharmony_ci originalvalue = rtl92de_read_dword_dbi(hw, (u16)regaddr, 19062306a36Sopenharmony_ci dbi_direct); 19162306a36Sopenharmony_ci } else { 19262306a36Sopenharmony_ci originalvalue = rtl_read_dword(rtlpriv, regaddr); 19362306a36Sopenharmony_ci } 19462306a36Sopenharmony_ci bitshift = calculate_bit_shift(bitmask); 19562306a36Sopenharmony_ci returnvalue = (originalvalue & bitmask) >> bitshift; 19662306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, 19762306a36Sopenharmony_ci "BBR MASK=0x%x Addr[0x%x]=0x%x\n", 19862306a36Sopenharmony_ci bitmask, regaddr, originalvalue); 19962306a36Sopenharmony_ci return returnvalue; 20062306a36Sopenharmony_ci} 20162306a36Sopenharmony_ci 20262306a36Sopenharmony_civoid rtl92d_phy_set_bb_reg(struct ieee80211_hw *hw, 20362306a36Sopenharmony_ci u32 regaddr, u32 bitmask, u32 data) 20462306a36Sopenharmony_ci{ 20562306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 20662306a36Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 20762306a36Sopenharmony_ci u8 dbi_direct = 0; 20862306a36Sopenharmony_ci u32 originalvalue, bitshift; 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, 21162306a36Sopenharmony_ci "regaddr(%#x), bitmask(%#x), data(%#x)\n", 21262306a36Sopenharmony_ci regaddr, bitmask, data); 21362306a36Sopenharmony_ci if (rtlhal->during_mac1init_radioa) 21462306a36Sopenharmony_ci dbi_direct = BIT(3); 21562306a36Sopenharmony_ci else if (rtlhal->during_mac0init_radiob) 21662306a36Sopenharmony_ci /* mac0 use phy1 write radio_b. */ 21762306a36Sopenharmony_ci dbi_direct = BIT(3) | BIT(2); 21862306a36Sopenharmony_ci if (bitmask != MASKDWORD) { 21962306a36Sopenharmony_ci if (rtlhal->during_mac1init_radioa || 22062306a36Sopenharmony_ci rtlhal->during_mac0init_radiob) 22162306a36Sopenharmony_ci originalvalue = rtl92de_read_dword_dbi(hw, 22262306a36Sopenharmony_ci (u16) regaddr, 22362306a36Sopenharmony_ci dbi_direct); 22462306a36Sopenharmony_ci else 22562306a36Sopenharmony_ci originalvalue = rtl_read_dword(rtlpriv, regaddr); 22662306a36Sopenharmony_ci bitshift = calculate_bit_shift(bitmask); 22762306a36Sopenharmony_ci data = ((originalvalue & (~bitmask)) | (data << bitshift)); 22862306a36Sopenharmony_ci } 22962306a36Sopenharmony_ci if (rtlhal->during_mac1init_radioa || rtlhal->during_mac0init_radiob) 23062306a36Sopenharmony_ci rtl92de_write_dword_dbi(hw, (u16) regaddr, data, dbi_direct); 23162306a36Sopenharmony_ci else 23262306a36Sopenharmony_ci rtl_write_dword(rtlpriv, regaddr, data); 23362306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, 23462306a36Sopenharmony_ci "regaddr(%#x), bitmask(%#x), data(%#x)\n", 23562306a36Sopenharmony_ci regaddr, bitmask, data); 23662306a36Sopenharmony_ci} 23762306a36Sopenharmony_ci 23862306a36Sopenharmony_cistatic u32 _rtl92d_phy_rf_serial_read(struct ieee80211_hw *hw, 23962306a36Sopenharmony_ci enum radio_path rfpath, u32 offset) 24062306a36Sopenharmony_ci{ 24162306a36Sopenharmony_ci 24262306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 24362306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 24462306a36Sopenharmony_ci struct bb_reg_def *pphyreg = &rtlphy->phyreg_def[rfpath]; 24562306a36Sopenharmony_ci u32 newoffset; 24662306a36Sopenharmony_ci u32 tmplong, tmplong2; 24762306a36Sopenharmony_ci u8 rfpi_enable = 0; 24862306a36Sopenharmony_ci u32 retvalue; 24962306a36Sopenharmony_ci 25062306a36Sopenharmony_ci newoffset = offset; 25162306a36Sopenharmony_ci tmplong = rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, MASKDWORD); 25262306a36Sopenharmony_ci if (rfpath == RF90_PATH_A) 25362306a36Sopenharmony_ci tmplong2 = tmplong; 25462306a36Sopenharmony_ci else 25562306a36Sopenharmony_ci tmplong2 = rtl_get_bbreg(hw, pphyreg->rfhssi_para2, MASKDWORD); 25662306a36Sopenharmony_ci tmplong2 = (tmplong2 & (~BLSSIREADADDRESS)) | 25762306a36Sopenharmony_ci (newoffset << 23) | BLSSIREADEDGE; 25862306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, MASKDWORD, 25962306a36Sopenharmony_ci tmplong & (~BLSSIREADEDGE)); 26062306a36Sopenharmony_ci udelay(10); 26162306a36Sopenharmony_ci rtl_set_bbreg(hw, pphyreg->rfhssi_para2, MASKDWORD, tmplong2); 26262306a36Sopenharmony_ci udelay(50); 26362306a36Sopenharmony_ci udelay(50); 26462306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, MASKDWORD, 26562306a36Sopenharmony_ci tmplong | BLSSIREADEDGE); 26662306a36Sopenharmony_ci udelay(10); 26762306a36Sopenharmony_ci if (rfpath == RF90_PATH_A) 26862306a36Sopenharmony_ci rfpi_enable = (u8) rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER1, 26962306a36Sopenharmony_ci BIT(8)); 27062306a36Sopenharmony_ci else if (rfpath == RF90_PATH_B) 27162306a36Sopenharmony_ci rfpi_enable = (u8) rtl_get_bbreg(hw, RFPGA0_XB_HSSIPARAMETER1, 27262306a36Sopenharmony_ci BIT(8)); 27362306a36Sopenharmony_ci if (rfpi_enable) 27462306a36Sopenharmony_ci retvalue = rtl_get_bbreg(hw, pphyreg->rf_rbpi, 27562306a36Sopenharmony_ci BLSSIREADBACKDATA); 27662306a36Sopenharmony_ci else 27762306a36Sopenharmony_ci retvalue = rtl_get_bbreg(hw, pphyreg->rf_rb, 27862306a36Sopenharmony_ci BLSSIREADBACKDATA); 27962306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, "RFR-%d Addr[0x%x] = 0x%x\n", 28062306a36Sopenharmony_ci rfpath, pphyreg->rf_rb, retvalue); 28162306a36Sopenharmony_ci return retvalue; 28262306a36Sopenharmony_ci} 28362306a36Sopenharmony_ci 28462306a36Sopenharmony_cistatic void _rtl92d_phy_rf_serial_write(struct ieee80211_hw *hw, 28562306a36Sopenharmony_ci enum radio_path rfpath, 28662306a36Sopenharmony_ci u32 offset, u32 data) 28762306a36Sopenharmony_ci{ 28862306a36Sopenharmony_ci u32 data_and_addr; 28962306a36Sopenharmony_ci u32 newoffset; 29062306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 29162306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 29262306a36Sopenharmony_ci struct bb_reg_def *pphyreg = &rtlphy->phyreg_def[rfpath]; 29362306a36Sopenharmony_ci 29462306a36Sopenharmony_ci newoffset = offset; 29562306a36Sopenharmony_ci /* T65 RF */ 29662306a36Sopenharmony_ci data_and_addr = ((newoffset << 20) | (data & 0x000fffff)) & 0x0fffffff; 29762306a36Sopenharmony_ci rtl_set_bbreg(hw, pphyreg->rf3wire_offset, MASKDWORD, data_and_addr); 29862306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, "RFW-%d Addr[0x%x]=0x%x\n", 29962306a36Sopenharmony_ci rfpath, pphyreg->rf3wire_offset, data_and_addr); 30062306a36Sopenharmony_ci} 30162306a36Sopenharmony_ci 30262306a36Sopenharmony_ciu32 rtl92d_phy_query_rf_reg(struct ieee80211_hw *hw, 30362306a36Sopenharmony_ci enum radio_path rfpath, u32 regaddr, u32 bitmask) 30462306a36Sopenharmony_ci{ 30562306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 30662306a36Sopenharmony_ci u32 original_value, readback_value, bitshift; 30762306a36Sopenharmony_ci 30862306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, 30962306a36Sopenharmony_ci "regaddr(%#x), rfpath(%#x), bitmask(%#x)\n", 31062306a36Sopenharmony_ci regaddr, rfpath, bitmask); 31162306a36Sopenharmony_ci spin_lock(&rtlpriv->locks.rf_lock); 31262306a36Sopenharmony_ci original_value = _rtl92d_phy_rf_serial_read(hw, rfpath, regaddr); 31362306a36Sopenharmony_ci bitshift = calculate_bit_shift(bitmask); 31462306a36Sopenharmony_ci readback_value = (original_value & bitmask) >> bitshift; 31562306a36Sopenharmony_ci spin_unlock(&rtlpriv->locks.rf_lock); 31662306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, 31762306a36Sopenharmony_ci "regaddr(%#x), rfpath(%#x), bitmask(%#x), original_value(%#x)\n", 31862306a36Sopenharmony_ci regaddr, rfpath, bitmask, original_value); 31962306a36Sopenharmony_ci return readback_value; 32062306a36Sopenharmony_ci} 32162306a36Sopenharmony_ci 32262306a36Sopenharmony_civoid rtl92d_phy_set_rf_reg(struct ieee80211_hw *hw, enum radio_path rfpath, 32362306a36Sopenharmony_ci u32 regaddr, u32 bitmask, u32 data) 32462306a36Sopenharmony_ci{ 32562306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 32662306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 32762306a36Sopenharmony_ci u32 original_value, bitshift; 32862306a36Sopenharmony_ci 32962306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, 33062306a36Sopenharmony_ci "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n", 33162306a36Sopenharmony_ci regaddr, bitmask, data, rfpath); 33262306a36Sopenharmony_ci if (bitmask == 0) 33362306a36Sopenharmony_ci return; 33462306a36Sopenharmony_ci spin_lock(&rtlpriv->locks.rf_lock); 33562306a36Sopenharmony_ci if (rtlphy->rf_mode != RF_OP_BY_FW) { 33662306a36Sopenharmony_ci if (bitmask != RFREG_OFFSET_MASK) { 33762306a36Sopenharmony_ci original_value = _rtl92d_phy_rf_serial_read(hw, 33862306a36Sopenharmony_ci rfpath, regaddr); 33962306a36Sopenharmony_ci bitshift = calculate_bit_shift(bitmask); 34062306a36Sopenharmony_ci data = ((original_value & (~bitmask)) | 34162306a36Sopenharmony_ci (data << bitshift)); 34262306a36Sopenharmony_ci } 34362306a36Sopenharmony_ci _rtl92d_phy_rf_serial_write(hw, rfpath, regaddr, data); 34462306a36Sopenharmony_ci } 34562306a36Sopenharmony_ci spin_unlock(&rtlpriv->locks.rf_lock); 34662306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, 34762306a36Sopenharmony_ci "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n", 34862306a36Sopenharmony_ci regaddr, bitmask, data, rfpath); 34962306a36Sopenharmony_ci} 35062306a36Sopenharmony_ci 35162306a36Sopenharmony_cibool rtl92d_phy_mac_config(struct ieee80211_hw *hw) 35262306a36Sopenharmony_ci{ 35362306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 35462306a36Sopenharmony_ci u32 i; 35562306a36Sopenharmony_ci u32 arraylength; 35662306a36Sopenharmony_ci u32 *ptrarray; 35762306a36Sopenharmony_ci 35862306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, "Read Rtl819XMACPHY_Array\n"); 35962306a36Sopenharmony_ci arraylength = MAC_2T_ARRAYLENGTH; 36062306a36Sopenharmony_ci ptrarray = rtl8192de_mac_2tarray; 36162306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, "Img:Rtl819XMAC_Array\n"); 36262306a36Sopenharmony_ci for (i = 0; i < arraylength; i = i + 2) 36362306a36Sopenharmony_ci rtl_write_byte(rtlpriv, ptrarray[i], (u8) ptrarray[i + 1]); 36462306a36Sopenharmony_ci if (rtlpriv->rtlhal.macphymode == SINGLEMAC_SINGLEPHY) { 36562306a36Sopenharmony_ci /* improve 2-stream TX EVM */ 36662306a36Sopenharmony_ci /* rtl_write_byte(rtlpriv, 0x14,0x71); */ 36762306a36Sopenharmony_ci /* AMPDU aggregation number 9 */ 36862306a36Sopenharmony_ci /* rtl_write_word(rtlpriv, REG_MAX_AGGR_NUM, MAX_AGGR_NUM); */ 36962306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_MAX_AGGR_NUM, 0x0B); 37062306a36Sopenharmony_ci } else { 37162306a36Sopenharmony_ci /* 92D need to test to decide the num. */ 37262306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_MAX_AGGR_NUM, 0x07); 37362306a36Sopenharmony_ci } 37462306a36Sopenharmony_ci return true; 37562306a36Sopenharmony_ci} 37662306a36Sopenharmony_ci 37762306a36Sopenharmony_cistatic void _rtl92d_phy_init_bb_rf_register_definition(struct ieee80211_hw *hw) 37862306a36Sopenharmony_ci{ 37962306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 38062306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 38162306a36Sopenharmony_ci 38262306a36Sopenharmony_ci /* RF Interface Sowrtware Control */ 38362306a36Sopenharmony_ci /* 16 LSBs if read 32-bit from 0x870 */ 38462306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rfintfs = RFPGA0_XAB_RFINTERFACESW; 38562306a36Sopenharmony_ci /* 16 MSBs if read 32-bit from 0x870 (16-bit for 0x872) */ 38662306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rfintfs = RFPGA0_XAB_RFINTERFACESW; 38762306a36Sopenharmony_ci /* 16 LSBs if read 32-bit from 0x874 */ 38862306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_C].rfintfs = RFPGA0_XCD_RFINTERFACESW; 38962306a36Sopenharmony_ci /* 16 MSBs if read 32-bit from 0x874 (16-bit for 0x876) */ 39062306a36Sopenharmony_ci 39162306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_D].rfintfs = RFPGA0_XCD_RFINTERFACESW; 39262306a36Sopenharmony_ci /* RF Interface Readback Value */ 39362306a36Sopenharmony_ci /* 16 LSBs if read 32-bit from 0x8E0 */ 39462306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rfintfi = RFPGA0_XAB_RFINTERFACERB; 39562306a36Sopenharmony_ci /* 16 MSBs if read 32-bit from 0x8E0 (16-bit for 0x8E2) */ 39662306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rfintfi = RFPGA0_XAB_RFINTERFACERB; 39762306a36Sopenharmony_ci /* 16 LSBs if read 32-bit from 0x8E4 */ 39862306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_C].rfintfi = RFPGA0_XCD_RFINTERFACERB; 39962306a36Sopenharmony_ci /* 16 MSBs if read 32-bit from 0x8E4 (16-bit for 0x8E6) */ 40062306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_D].rfintfi = RFPGA0_XCD_RFINTERFACERB; 40162306a36Sopenharmony_ci 40262306a36Sopenharmony_ci /* RF Interface Output (and Enable) */ 40362306a36Sopenharmony_ci /* 16 LSBs if read 32-bit from 0x860 */ 40462306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rfintfo = RFPGA0_XA_RFINTERFACEOE; 40562306a36Sopenharmony_ci /* 16 LSBs if read 32-bit from 0x864 */ 40662306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rfintfo = RFPGA0_XB_RFINTERFACEOE; 40762306a36Sopenharmony_ci 40862306a36Sopenharmony_ci /* RF Interface (Output and) Enable */ 40962306a36Sopenharmony_ci /* 16 MSBs if read 32-bit from 0x860 (16-bit for 0x862) */ 41062306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rfintfe = RFPGA0_XA_RFINTERFACEOE; 41162306a36Sopenharmony_ci /* 16 MSBs if read 32-bit from 0x864 (16-bit for 0x866) */ 41262306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rfintfe = RFPGA0_XB_RFINTERFACEOE; 41362306a36Sopenharmony_ci 41462306a36Sopenharmony_ci /* Addr of LSSI. Wirte RF register by driver */ 41562306a36Sopenharmony_ci /* LSSI Parameter */ 41662306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rf3wire_offset = 41762306a36Sopenharmony_ci RFPGA0_XA_LSSIPARAMETER; 41862306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rf3wire_offset = 41962306a36Sopenharmony_ci RFPGA0_XB_LSSIPARAMETER; 42062306a36Sopenharmony_ci 42162306a36Sopenharmony_ci /* RF parameter */ 42262306a36Sopenharmony_ci /* BB Band Select */ 42362306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rflssi_select = RFPGA0_XAB_RFPARAMETER; 42462306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rflssi_select = RFPGA0_XAB_RFPARAMETER; 42562306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_C].rflssi_select = RFPGA0_XCD_RFPARAMETER; 42662306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_D].rflssi_select = RFPGA0_XCD_RFPARAMETER; 42762306a36Sopenharmony_ci 42862306a36Sopenharmony_ci /* Tx AGC Gain Stage (same for all path. Should we remove this?) */ 42962306a36Sopenharmony_ci /* Tx gain stage */ 43062306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rftxgain_stage = RFPGA0_TXGAINSTAGE; 43162306a36Sopenharmony_ci /* Tx gain stage */ 43262306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rftxgain_stage = RFPGA0_TXGAINSTAGE; 43362306a36Sopenharmony_ci /* Tx gain stage */ 43462306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_C].rftxgain_stage = RFPGA0_TXGAINSTAGE; 43562306a36Sopenharmony_ci /* Tx gain stage */ 43662306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_D].rftxgain_stage = RFPGA0_TXGAINSTAGE; 43762306a36Sopenharmony_ci 43862306a36Sopenharmony_ci /* Tranceiver A~D HSSI Parameter-1 */ 43962306a36Sopenharmony_ci /* wire control parameter1 */ 44062306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rfhssi_para1 = RFPGA0_XA_HSSIPARAMETER1; 44162306a36Sopenharmony_ci /* wire control parameter1 */ 44262306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rfhssi_para1 = RFPGA0_XB_HSSIPARAMETER1; 44362306a36Sopenharmony_ci 44462306a36Sopenharmony_ci /* Tranceiver A~D HSSI Parameter-2 */ 44562306a36Sopenharmony_ci /* wire control parameter2 */ 44662306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rfhssi_para2 = RFPGA0_XA_HSSIPARAMETER2; 44762306a36Sopenharmony_ci /* wire control parameter2 */ 44862306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rfhssi_para2 = RFPGA0_XB_HSSIPARAMETER2; 44962306a36Sopenharmony_ci 45062306a36Sopenharmony_ci /* RF switch Control */ 45162306a36Sopenharmony_ci /* TR/Ant switch control */ 45262306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rfsw_ctrl = RFPGA0_XAB_SWITCHCONTROL; 45362306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rfsw_ctrl = RFPGA0_XAB_SWITCHCONTROL; 45462306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_C].rfsw_ctrl = RFPGA0_XCD_SWITCHCONTROL; 45562306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_D].rfsw_ctrl = RFPGA0_XCD_SWITCHCONTROL; 45662306a36Sopenharmony_ci 45762306a36Sopenharmony_ci /* AGC control 1 */ 45862306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rfagc_control1 = ROFDM0_XAAGCCORE1; 45962306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rfagc_control1 = ROFDM0_XBAGCCORE1; 46062306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_C].rfagc_control1 = ROFDM0_XCAGCCORE1; 46162306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_D].rfagc_control1 = ROFDM0_XDAGCCORE1; 46262306a36Sopenharmony_ci 46362306a36Sopenharmony_ci /* AGC control 2 */ 46462306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rfagc_control2 = ROFDM0_XAAGCCORE2; 46562306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rfagc_control2 = ROFDM0_XBAGCCORE2; 46662306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_C].rfagc_control2 = ROFDM0_XCAGCCORE2; 46762306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_D].rfagc_control2 = ROFDM0_XDAGCCORE2; 46862306a36Sopenharmony_ci 46962306a36Sopenharmony_ci /* RX AFE control 1 */ 47062306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rfrxiq_imbal = ROFDM0_XARXIQIMBALANCE; 47162306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rfrxiq_imbal = ROFDM0_XBRXIQIMBALANCE; 47262306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_C].rfrxiq_imbal = ROFDM0_XCRXIQIMBALANCE; 47362306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_D].rfrxiq_imbal = ROFDM0_XDRXIQIMBALANCE; 47462306a36Sopenharmony_ci 47562306a36Sopenharmony_ci /*RX AFE control 1 */ 47662306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rfrx_afe = ROFDM0_XARXAFE; 47762306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rfrx_afe = ROFDM0_XBRXAFE; 47862306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_C].rfrx_afe = ROFDM0_XCRXAFE; 47962306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_D].rfrx_afe = ROFDM0_XDRXAFE; 48062306a36Sopenharmony_ci 48162306a36Sopenharmony_ci /* Tx AFE control 1 */ 48262306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rftxiq_imbal = ROFDM0_XATXIQIMBALANCE; 48362306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rftxiq_imbal = ROFDM0_XBTXIQIMBALANCE; 48462306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_C].rftxiq_imbal = ROFDM0_XCTXIQIMBALANCE; 48562306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_D].rftxiq_imbal = ROFDM0_XDTXIQIMBALANCE; 48662306a36Sopenharmony_ci 48762306a36Sopenharmony_ci /* Tx AFE control 2 */ 48862306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rftx_afe = ROFDM0_XATXAFE; 48962306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rftx_afe = ROFDM0_XBTXAFE; 49062306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_C].rftx_afe = ROFDM0_XCTXAFE; 49162306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_D].rftx_afe = ROFDM0_XDTXAFE; 49262306a36Sopenharmony_ci 49362306a36Sopenharmony_ci /* Tranceiver LSSI Readback SI mode */ 49462306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rf_rb = RFPGA0_XA_LSSIREADBACK; 49562306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rf_rb = RFPGA0_XB_LSSIREADBACK; 49662306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_C].rf_rb = RFPGA0_XC_LSSIREADBACK; 49762306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_D].rf_rb = RFPGA0_XD_LSSIREADBACK; 49862306a36Sopenharmony_ci 49962306a36Sopenharmony_ci /* Tranceiver LSSI Readback PI mode */ 50062306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_A].rf_rbpi = TRANSCEIVERA_HSPI_READBACK; 50162306a36Sopenharmony_ci rtlphy->phyreg_def[RF90_PATH_B].rf_rbpi = TRANSCEIVERB_HSPI_READBACK; 50262306a36Sopenharmony_ci} 50362306a36Sopenharmony_ci 50462306a36Sopenharmony_cistatic bool _rtl92d_phy_config_bb_with_headerfile(struct ieee80211_hw *hw, 50562306a36Sopenharmony_ci u8 configtype) 50662306a36Sopenharmony_ci{ 50762306a36Sopenharmony_ci int i; 50862306a36Sopenharmony_ci u32 *phy_regarray_table; 50962306a36Sopenharmony_ci u32 *agctab_array_table = NULL; 51062306a36Sopenharmony_ci u32 *agctab_5garray_table; 51162306a36Sopenharmony_ci u16 phy_reg_arraylen, agctab_arraylen = 0, agctab_5garraylen; 51262306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 51362306a36Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 51462306a36Sopenharmony_ci 51562306a36Sopenharmony_ci /* Normal chip,Mac0 use AGC_TAB.txt for 2G and 5G band. */ 51662306a36Sopenharmony_ci if (rtlhal->interfaceindex == 0) { 51762306a36Sopenharmony_ci agctab_arraylen = AGCTAB_ARRAYLENGTH; 51862306a36Sopenharmony_ci agctab_array_table = rtl8192de_agctab_array; 51962306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, 52062306a36Sopenharmony_ci " ===> phy:MAC0, Rtl819XAGCTAB_Array\n"); 52162306a36Sopenharmony_ci } else { 52262306a36Sopenharmony_ci if (rtlhal->current_bandtype == BAND_ON_2_4G) { 52362306a36Sopenharmony_ci agctab_arraylen = AGCTAB_2G_ARRAYLENGTH; 52462306a36Sopenharmony_ci agctab_array_table = rtl8192de_agctab_2garray; 52562306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, 52662306a36Sopenharmony_ci " ===> phy:MAC1, Rtl819XAGCTAB_2GArray\n"); 52762306a36Sopenharmony_ci } else { 52862306a36Sopenharmony_ci agctab_5garraylen = AGCTAB_5G_ARRAYLENGTH; 52962306a36Sopenharmony_ci agctab_5garray_table = rtl8192de_agctab_5garray; 53062306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, 53162306a36Sopenharmony_ci " ===> phy:MAC1, Rtl819XAGCTAB_5GArray\n"); 53262306a36Sopenharmony_ci 53362306a36Sopenharmony_ci } 53462306a36Sopenharmony_ci } 53562306a36Sopenharmony_ci phy_reg_arraylen = PHY_REG_2T_ARRAYLENGTH; 53662306a36Sopenharmony_ci phy_regarray_table = rtl8192de_phy_reg_2tarray; 53762306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, 53862306a36Sopenharmony_ci " ===> phy:Rtl819XPHY_REG_Array_PG\n"); 53962306a36Sopenharmony_ci if (configtype == BASEBAND_CONFIG_PHY_REG) { 54062306a36Sopenharmony_ci for (i = 0; i < phy_reg_arraylen; i = i + 2) { 54162306a36Sopenharmony_ci rtl_addr_delay(phy_regarray_table[i]); 54262306a36Sopenharmony_ci rtl_set_bbreg(hw, phy_regarray_table[i], MASKDWORD, 54362306a36Sopenharmony_ci phy_regarray_table[i + 1]); 54462306a36Sopenharmony_ci udelay(1); 54562306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 54662306a36Sopenharmony_ci "The phy_regarray_table[0] is %x Rtl819XPHY_REGArray[1] is %x\n", 54762306a36Sopenharmony_ci phy_regarray_table[i], 54862306a36Sopenharmony_ci phy_regarray_table[i + 1]); 54962306a36Sopenharmony_ci } 55062306a36Sopenharmony_ci } else if (configtype == BASEBAND_CONFIG_AGC_TAB) { 55162306a36Sopenharmony_ci if (rtlhal->interfaceindex == 0) { 55262306a36Sopenharmony_ci for (i = 0; i < agctab_arraylen; i = i + 2) { 55362306a36Sopenharmony_ci rtl_set_bbreg(hw, agctab_array_table[i], 55462306a36Sopenharmony_ci MASKDWORD, 55562306a36Sopenharmony_ci agctab_array_table[i + 1]); 55662306a36Sopenharmony_ci /* Add 1us delay between BB/RF register 55762306a36Sopenharmony_ci * setting. */ 55862306a36Sopenharmony_ci udelay(1); 55962306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 56062306a36Sopenharmony_ci "The Rtl819XAGCTAB_Array_Table[0] is %u Rtl819XPHY_REGArray[1] is %u\n", 56162306a36Sopenharmony_ci agctab_array_table[i], 56262306a36Sopenharmony_ci agctab_array_table[i + 1]); 56362306a36Sopenharmony_ci } 56462306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, 56562306a36Sopenharmony_ci "Normal Chip, MAC0, load Rtl819XAGCTAB_Array\n"); 56662306a36Sopenharmony_ci } else { 56762306a36Sopenharmony_ci if (rtlhal->current_bandtype == BAND_ON_2_4G) { 56862306a36Sopenharmony_ci for (i = 0; i < agctab_arraylen; i = i + 2) { 56962306a36Sopenharmony_ci rtl_set_bbreg(hw, agctab_array_table[i], 57062306a36Sopenharmony_ci MASKDWORD, 57162306a36Sopenharmony_ci agctab_array_table[i + 1]); 57262306a36Sopenharmony_ci /* Add 1us delay between BB/RF register 57362306a36Sopenharmony_ci * setting. */ 57462306a36Sopenharmony_ci udelay(1); 57562306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 57662306a36Sopenharmony_ci "The Rtl819XAGCTAB_Array_Table[0] is %u Rtl819XPHY_REGArray[1] is %u\n", 57762306a36Sopenharmony_ci agctab_array_table[i], 57862306a36Sopenharmony_ci agctab_array_table[i + 1]); 57962306a36Sopenharmony_ci } 58062306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, 58162306a36Sopenharmony_ci "Load Rtl819XAGCTAB_2GArray\n"); 58262306a36Sopenharmony_ci } else { 58362306a36Sopenharmony_ci for (i = 0; i < agctab_5garraylen; i = i + 2) { 58462306a36Sopenharmony_ci rtl_set_bbreg(hw, 58562306a36Sopenharmony_ci agctab_5garray_table[i], 58662306a36Sopenharmony_ci MASKDWORD, 58762306a36Sopenharmony_ci agctab_5garray_table[i + 1]); 58862306a36Sopenharmony_ci /* Add 1us delay between BB/RF registeri 58962306a36Sopenharmony_ci * setting. */ 59062306a36Sopenharmony_ci udelay(1); 59162306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 59262306a36Sopenharmony_ci "The Rtl819XAGCTAB_5GArray_Table[0] is %u Rtl819XPHY_REGArray[1] is %u\n", 59362306a36Sopenharmony_ci agctab_5garray_table[i], 59462306a36Sopenharmony_ci agctab_5garray_table[i + 1]); 59562306a36Sopenharmony_ci } 59662306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, 59762306a36Sopenharmony_ci "Load Rtl819XAGCTAB_5GArray\n"); 59862306a36Sopenharmony_ci } 59962306a36Sopenharmony_ci } 60062306a36Sopenharmony_ci } 60162306a36Sopenharmony_ci return true; 60262306a36Sopenharmony_ci} 60362306a36Sopenharmony_ci 60462306a36Sopenharmony_cistatic void _rtl92d_store_pwrindex_diffrate_offset(struct ieee80211_hw *hw, 60562306a36Sopenharmony_ci u32 regaddr, u32 bitmask, 60662306a36Sopenharmony_ci u32 data) 60762306a36Sopenharmony_ci{ 60862306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 60962306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 61062306a36Sopenharmony_ci int index; 61162306a36Sopenharmony_ci 61262306a36Sopenharmony_ci if (regaddr == RTXAGC_A_RATE18_06) 61362306a36Sopenharmony_ci index = 0; 61462306a36Sopenharmony_ci else if (regaddr == RTXAGC_A_RATE54_24) 61562306a36Sopenharmony_ci index = 1; 61662306a36Sopenharmony_ci else if (regaddr == RTXAGC_A_CCK1_MCS32) 61762306a36Sopenharmony_ci index = 6; 61862306a36Sopenharmony_ci else if (regaddr == RTXAGC_B_CCK11_A_CCK2_11 && bitmask == 0xffffff00) 61962306a36Sopenharmony_ci index = 7; 62062306a36Sopenharmony_ci else if (regaddr == RTXAGC_A_MCS03_MCS00) 62162306a36Sopenharmony_ci index = 2; 62262306a36Sopenharmony_ci else if (regaddr == RTXAGC_A_MCS07_MCS04) 62362306a36Sopenharmony_ci index = 3; 62462306a36Sopenharmony_ci else if (regaddr == RTXAGC_A_MCS11_MCS08) 62562306a36Sopenharmony_ci index = 4; 62662306a36Sopenharmony_ci else if (regaddr == RTXAGC_A_MCS15_MCS12) 62762306a36Sopenharmony_ci index = 5; 62862306a36Sopenharmony_ci else if (regaddr == RTXAGC_B_RATE18_06) 62962306a36Sopenharmony_ci index = 8; 63062306a36Sopenharmony_ci else if (regaddr == RTXAGC_B_RATE54_24) 63162306a36Sopenharmony_ci index = 9; 63262306a36Sopenharmony_ci else if (regaddr == RTXAGC_B_CCK1_55_MCS32) 63362306a36Sopenharmony_ci index = 14; 63462306a36Sopenharmony_ci else if (regaddr == RTXAGC_B_CCK11_A_CCK2_11 && bitmask == 0x000000ff) 63562306a36Sopenharmony_ci index = 15; 63662306a36Sopenharmony_ci else if (regaddr == RTXAGC_B_MCS03_MCS00) 63762306a36Sopenharmony_ci index = 10; 63862306a36Sopenharmony_ci else if (regaddr == RTXAGC_B_MCS07_MCS04) 63962306a36Sopenharmony_ci index = 11; 64062306a36Sopenharmony_ci else if (regaddr == RTXAGC_B_MCS11_MCS08) 64162306a36Sopenharmony_ci index = 12; 64262306a36Sopenharmony_ci else if (regaddr == RTXAGC_B_MCS15_MCS12) 64362306a36Sopenharmony_ci index = 13; 64462306a36Sopenharmony_ci else 64562306a36Sopenharmony_ci return; 64662306a36Sopenharmony_ci 64762306a36Sopenharmony_ci rtlphy->mcs_offset[rtlphy->pwrgroup_cnt][index] = data; 64862306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 64962306a36Sopenharmony_ci "MCSTxPowerLevelOriginalOffset[%d][%d] = 0x%x\n", 65062306a36Sopenharmony_ci rtlphy->pwrgroup_cnt, index, 65162306a36Sopenharmony_ci rtlphy->mcs_offset[rtlphy->pwrgroup_cnt][index]); 65262306a36Sopenharmony_ci if (index == 13) 65362306a36Sopenharmony_ci rtlphy->pwrgroup_cnt++; 65462306a36Sopenharmony_ci} 65562306a36Sopenharmony_ci 65662306a36Sopenharmony_cistatic bool _rtl92d_phy_config_bb_with_pgheaderfile(struct ieee80211_hw *hw, 65762306a36Sopenharmony_ci u8 configtype) 65862306a36Sopenharmony_ci{ 65962306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 66062306a36Sopenharmony_ci int i; 66162306a36Sopenharmony_ci u32 *phy_regarray_table_pg; 66262306a36Sopenharmony_ci u16 phy_regarray_pg_len; 66362306a36Sopenharmony_ci 66462306a36Sopenharmony_ci phy_regarray_pg_len = PHY_REG_ARRAY_PG_LENGTH; 66562306a36Sopenharmony_ci phy_regarray_table_pg = rtl8192de_phy_reg_array_pg; 66662306a36Sopenharmony_ci if (configtype == BASEBAND_CONFIG_PHY_REG) { 66762306a36Sopenharmony_ci for (i = 0; i < phy_regarray_pg_len; i = i + 3) { 66862306a36Sopenharmony_ci rtl_addr_delay(phy_regarray_table_pg[i]); 66962306a36Sopenharmony_ci _rtl92d_store_pwrindex_diffrate_offset(hw, 67062306a36Sopenharmony_ci phy_regarray_table_pg[i], 67162306a36Sopenharmony_ci phy_regarray_table_pg[i + 1], 67262306a36Sopenharmony_ci phy_regarray_table_pg[i + 2]); 67362306a36Sopenharmony_ci } 67462306a36Sopenharmony_ci } else { 67562306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_SEND, DBG_TRACE, 67662306a36Sopenharmony_ci "configtype != BaseBand_Config_PHY_REG\n"); 67762306a36Sopenharmony_ci } 67862306a36Sopenharmony_ci return true; 67962306a36Sopenharmony_ci} 68062306a36Sopenharmony_ci 68162306a36Sopenharmony_cistatic bool _rtl92d_phy_bb_config(struct ieee80211_hw *hw) 68262306a36Sopenharmony_ci{ 68362306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 68462306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 68562306a36Sopenharmony_ci struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 68662306a36Sopenharmony_ci bool rtstatus; 68762306a36Sopenharmony_ci 68862306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, "==>\n"); 68962306a36Sopenharmony_ci rtstatus = _rtl92d_phy_config_bb_with_headerfile(hw, 69062306a36Sopenharmony_ci BASEBAND_CONFIG_PHY_REG); 69162306a36Sopenharmony_ci if (!rtstatus) { 69262306a36Sopenharmony_ci pr_err("Write BB Reg Fail!!\n"); 69362306a36Sopenharmony_ci return false; 69462306a36Sopenharmony_ci } 69562306a36Sopenharmony_ci 69662306a36Sopenharmony_ci /* if (rtlphy->rf_type == RF_1T2R) { 69762306a36Sopenharmony_ci * _rtl92c_phy_bb_config_1t(hw); 69862306a36Sopenharmony_ci * rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, "Config to 1T!!\n"); 69962306a36Sopenharmony_ci *} */ 70062306a36Sopenharmony_ci 70162306a36Sopenharmony_ci if (rtlefuse->autoload_failflag == false) { 70262306a36Sopenharmony_ci rtlphy->pwrgroup_cnt = 0; 70362306a36Sopenharmony_ci rtstatus = _rtl92d_phy_config_bb_with_pgheaderfile(hw, 70462306a36Sopenharmony_ci BASEBAND_CONFIG_PHY_REG); 70562306a36Sopenharmony_ci } 70662306a36Sopenharmony_ci if (!rtstatus) { 70762306a36Sopenharmony_ci pr_err("BB_PG Reg Fail!!\n"); 70862306a36Sopenharmony_ci return false; 70962306a36Sopenharmony_ci } 71062306a36Sopenharmony_ci rtstatus = _rtl92d_phy_config_bb_with_headerfile(hw, 71162306a36Sopenharmony_ci BASEBAND_CONFIG_AGC_TAB); 71262306a36Sopenharmony_ci if (!rtstatus) { 71362306a36Sopenharmony_ci pr_err("AGC Table Fail\n"); 71462306a36Sopenharmony_ci return false; 71562306a36Sopenharmony_ci } 71662306a36Sopenharmony_ci rtlphy->cck_high_power = (bool) (rtl_get_bbreg(hw, 71762306a36Sopenharmony_ci RFPGA0_XA_HSSIPARAMETER2, 0x200)); 71862306a36Sopenharmony_ci 71962306a36Sopenharmony_ci return true; 72062306a36Sopenharmony_ci} 72162306a36Sopenharmony_ci 72262306a36Sopenharmony_cibool rtl92d_phy_bb_config(struct ieee80211_hw *hw) 72362306a36Sopenharmony_ci{ 72462306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 72562306a36Sopenharmony_ci u16 regval; 72662306a36Sopenharmony_ci u32 regvaldw; 72762306a36Sopenharmony_ci u8 value; 72862306a36Sopenharmony_ci 72962306a36Sopenharmony_ci _rtl92d_phy_init_bb_rf_register_definition(hw); 73062306a36Sopenharmony_ci regval = rtl_read_word(rtlpriv, REG_SYS_FUNC_EN); 73162306a36Sopenharmony_ci rtl_write_word(rtlpriv, REG_SYS_FUNC_EN, 73262306a36Sopenharmony_ci regval | BIT(13) | BIT(0) | BIT(1)); 73362306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_AFE_PLL_CTRL, 0x83); 73462306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_AFE_PLL_CTRL + 1, 0xdb); 73562306a36Sopenharmony_ci /* 0x1f bit7 bit6 represent for mac0/mac1 driver ready */ 73662306a36Sopenharmony_ci value = rtl_read_byte(rtlpriv, REG_RF_CTRL); 73762306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_RF_CTRL, value | RF_EN | RF_RSTB | 73862306a36Sopenharmony_ci RF_SDMRSTB); 73962306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, FEN_PPLL | FEN_PCIEA | 74062306a36Sopenharmony_ci FEN_DIO_PCIE | FEN_BB_GLB_RSTN | FEN_BBRSTB); 74162306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL + 1, 0x80); 74262306a36Sopenharmony_ci if (!(IS_92D_SINGLEPHY(rtlpriv->rtlhal.version))) { 74362306a36Sopenharmony_ci regvaldw = rtl_read_dword(rtlpriv, REG_LEDCFG0); 74462306a36Sopenharmony_ci rtl_write_dword(rtlpriv, REG_LEDCFG0, regvaldw | BIT(23)); 74562306a36Sopenharmony_ci } 74662306a36Sopenharmony_ci 74762306a36Sopenharmony_ci return _rtl92d_phy_bb_config(hw); 74862306a36Sopenharmony_ci} 74962306a36Sopenharmony_ci 75062306a36Sopenharmony_cibool rtl92d_phy_rf_config(struct ieee80211_hw *hw) 75162306a36Sopenharmony_ci{ 75262306a36Sopenharmony_ci return rtl92d_phy_rf6052_config(hw); 75362306a36Sopenharmony_ci} 75462306a36Sopenharmony_ci 75562306a36Sopenharmony_cibool rtl92d_phy_config_rf_with_headerfile(struct ieee80211_hw *hw, 75662306a36Sopenharmony_ci enum rf_content content, 75762306a36Sopenharmony_ci enum radio_path rfpath) 75862306a36Sopenharmony_ci{ 75962306a36Sopenharmony_ci int i; 76062306a36Sopenharmony_ci u32 *radioa_array_table; 76162306a36Sopenharmony_ci u32 *radiob_array_table; 76262306a36Sopenharmony_ci u16 radioa_arraylen, radiob_arraylen; 76362306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 76462306a36Sopenharmony_ci 76562306a36Sopenharmony_ci radioa_arraylen = RADIOA_2T_ARRAYLENGTH; 76662306a36Sopenharmony_ci radioa_array_table = rtl8192de_radioa_2tarray; 76762306a36Sopenharmony_ci radiob_arraylen = RADIOB_2T_ARRAYLENGTH; 76862306a36Sopenharmony_ci radiob_array_table = rtl8192de_radiob_2tarray; 76962306a36Sopenharmony_ci if (rtlpriv->efuse.internal_pa_5g[0]) { 77062306a36Sopenharmony_ci radioa_arraylen = RADIOA_2T_INT_PA_ARRAYLENGTH; 77162306a36Sopenharmony_ci radioa_array_table = rtl8192de_radioa_2t_int_paarray; 77262306a36Sopenharmony_ci } 77362306a36Sopenharmony_ci if (rtlpriv->efuse.internal_pa_5g[1]) { 77462306a36Sopenharmony_ci radiob_arraylen = RADIOB_2T_INT_PA_ARRAYLENGTH; 77562306a36Sopenharmony_ci radiob_array_table = rtl8192de_radiob_2t_int_paarray; 77662306a36Sopenharmony_ci } 77762306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, 77862306a36Sopenharmony_ci "PHY_ConfigRFWithHeaderFile() Radio_A:Rtl819XRadioA_1TArray\n"); 77962306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, 78062306a36Sopenharmony_ci "PHY_ConfigRFWithHeaderFile() Radio_B:Rtl819XRadioB_1TArray\n"); 78162306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, "Radio No %x\n", rfpath); 78262306a36Sopenharmony_ci 78362306a36Sopenharmony_ci /* this only happens when DMDP, mac0 start on 2.4G, 78462306a36Sopenharmony_ci * mac1 start on 5G, mac 0 has to set phy0&phy1 78562306a36Sopenharmony_ci * pathA or mac1 has to set phy0&phy1 pathA */ 78662306a36Sopenharmony_ci if ((content == radiob_txt) && (rfpath == RF90_PATH_A)) { 78762306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, 78862306a36Sopenharmony_ci " ===> althougth Path A, we load radiob.txt\n"); 78962306a36Sopenharmony_ci radioa_arraylen = radiob_arraylen; 79062306a36Sopenharmony_ci radioa_array_table = radiob_array_table; 79162306a36Sopenharmony_ci } 79262306a36Sopenharmony_ci switch (rfpath) { 79362306a36Sopenharmony_ci case RF90_PATH_A: 79462306a36Sopenharmony_ci for (i = 0; i < radioa_arraylen; i = i + 2) { 79562306a36Sopenharmony_ci rtl_rfreg_delay(hw, rfpath, radioa_array_table[i], 79662306a36Sopenharmony_ci RFREG_OFFSET_MASK, 79762306a36Sopenharmony_ci radioa_array_table[i + 1]); 79862306a36Sopenharmony_ci } 79962306a36Sopenharmony_ci break; 80062306a36Sopenharmony_ci case RF90_PATH_B: 80162306a36Sopenharmony_ci for (i = 0; i < radiob_arraylen; i = i + 2) { 80262306a36Sopenharmony_ci rtl_rfreg_delay(hw, rfpath, radiob_array_table[i], 80362306a36Sopenharmony_ci RFREG_OFFSET_MASK, 80462306a36Sopenharmony_ci radiob_array_table[i + 1]); 80562306a36Sopenharmony_ci } 80662306a36Sopenharmony_ci break; 80762306a36Sopenharmony_ci case RF90_PATH_C: 80862306a36Sopenharmony_ci case RF90_PATH_D: 80962306a36Sopenharmony_ci pr_err("switch case %#x not processed\n", rfpath); 81062306a36Sopenharmony_ci break; 81162306a36Sopenharmony_ci } 81262306a36Sopenharmony_ci return true; 81362306a36Sopenharmony_ci} 81462306a36Sopenharmony_ci 81562306a36Sopenharmony_civoid rtl92d_phy_get_hw_reg_originalvalue(struct ieee80211_hw *hw) 81662306a36Sopenharmony_ci{ 81762306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 81862306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 81962306a36Sopenharmony_ci 82062306a36Sopenharmony_ci rtlphy->default_initialgain[0] = 82162306a36Sopenharmony_ci (u8) rtl_get_bbreg(hw, ROFDM0_XAAGCCORE1, MASKBYTE0); 82262306a36Sopenharmony_ci rtlphy->default_initialgain[1] = 82362306a36Sopenharmony_ci (u8) rtl_get_bbreg(hw, ROFDM0_XBAGCCORE1, MASKBYTE0); 82462306a36Sopenharmony_ci rtlphy->default_initialgain[2] = 82562306a36Sopenharmony_ci (u8) rtl_get_bbreg(hw, ROFDM0_XCAGCCORE1, MASKBYTE0); 82662306a36Sopenharmony_ci rtlphy->default_initialgain[3] = 82762306a36Sopenharmony_ci (u8) rtl_get_bbreg(hw, ROFDM0_XDAGCCORE1, MASKBYTE0); 82862306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 82962306a36Sopenharmony_ci "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x\n", 83062306a36Sopenharmony_ci rtlphy->default_initialgain[0], 83162306a36Sopenharmony_ci rtlphy->default_initialgain[1], 83262306a36Sopenharmony_ci rtlphy->default_initialgain[2], 83362306a36Sopenharmony_ci rtlphy->default_initialgain[3]); 83462306a36Sopenharmony_ci rtlphy->framesync = (u8)rtl_get_bbreg(hw, ROFDM0_RXDETECTOR3, 83562306a36Sopenharmony_ci MASKBYTE0); 83662306a36Sopenharmony_ci rtlphy->framesync_c34 = rtl_get_bbreg(hw, ROFDM0_RXDETECTOR2, 83762306a36Sopenharmony_ci MASKDWORD); 83862306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, 83962306a36Sopenharmony_ci "Default framesync (0x%x) = 0x%x\n", 84062306a36Sopenharmony_ci ROFDM0_RXDETECTOR3, rtlphy->framesync); 84162306a36Sopenharmony_ci} 84262306a36Sopenharmony_ci 84362306a36Sopenharmony_cistatic void _rtl92d_get_txpower_index(struct ieee80211_hw *hw, u8 channel, 84462306a36Sopenharmony_ci u8 *cckpowerlevel, u8 *ofdmpowerlevel) 84562306a36Sopenharmony_ci{ 84662306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 84762306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 84862306a36Sopenharmony_ci struct rtl_hal *rtlhal = &(rtlpriv->rtlhal); 84962306a36Sopenharmony_ci struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 85062306a36Sopenharmony_ci u8 index = (channel - 1); 85162306a36Sopenharmony_ci 85262306a36Sopenharmony_ci /* 1. CCK */ 85362306a36Sopenharmony_ci if (rtlhal->current_bandtype == BAND_ON_2_4G) { 85462306a36Sopenharmony_ci /* RF-A */ 85562306a36Sopenharmony_ci cckpowerlevel[RF90_PATH_A] = 85662306a36Sopenharmony_ci rtlefuse->txpwrlevel_cck[RF90_PATH_A][index]; 85762306a36Sopenharmony_ci /* RF-B */ 85862306a36Sopenharmony_ci cckpowerlevel[RF90_PATH_B] = 85962306a36Sopenharmony_ci rtlefuse->txpwrlevel_cck[RF90_PATH_B][index]; 86062306a36Sopenharmony_ci } else { 86162306a36Sopenharmony_ci cckpowerlevel[RF90_PATH_A] = 0; 86262306a36Sopenharmony_ci cckpowerlevel[RF90_PATH_B] = 0; 86362306a36Sopenharmony_ci } 86462306a36Sopenharmony_ci /* 2. OFDM for 1S or 2S */ 86562306a36Sopenharmony_ci if (rtlphy->rf_type == RF_1T2R || rtlphy->rf_type == RF_1T1R) { 86662306a36Sopenharmony_ci /* Read HT 40 OFDM TX power */ 86762306a36Sopenharmony_ci ofdmpowerlevel[RF90_PATH_A] = 86862306a36Sopenharmony_ci rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_A][index]; 86962306a36Sopenharmony_ci ofdmpowerlevel[RF90_PATH_B] = 87062306a36Sopenharmony_ci rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_B][index]; 87162306a36Sopenharmony_ci } else if (rtlphy->rf_type == RF_2T2R) { 87262306a36Sopenharmony_ci /* Read HT 40 OFDM TX power */ 87362306a36Sopenharmony_ci ofdmpowerlevel[RF90_PATH_A] = 87462306a36Sopenharmony_ci rtlefuse->txpwrlevel_ht40_2s[RF90_PATH_A][index]; 87562306a36Sopenharmony_ci ofdmpowerlevel[RF90_PATH_B] = 87662306a36Sopenharmony_ci rtlefuse->txpwrlevel_ht40_2s[RF90_PATH_B][index]; 87762306a36Sopenharmony_ci } 87862306a36Sopenharmony_ci} 87962306a36Sopenharmony_ci 88062306a36Sopenharmony_cistatic void _rtl92d_ccxpower_index_check(struct ieee80211_hw *hw, 88162306a36Sopenharmony_ci u8 channel, u8 *cckpowerlevel, u8 *ofdmpowerlevel) 88262306a36Sopenharmony_ci{ 88362306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 88462306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 88562306a36Sopenharmony_ci 88662306a36Sopenharmony_ci rtlphy->cur_cck_txpwridx = cckpowerlevel[0]; 88762306a36Sopenharmony_ci rtlphy->cur_ofdm24g_txpwridx = ofdmpowerlevel[0]; 88862306a36Sopenharmony_ci} 88962306a36Sopenharmony_ci 89062306a36Sopenharmony_cistatic u8 _rtl92c_phy_get_rightchnlplace(u8 chnl) 89162306a36Sopenharmony_ci{ 89262306a36Sopenharmony_ci u8 place = chnl; 89362306a36Sopenharmony_ci 89462306a36Sopenharmony_ci if (chnl > 14) { 89562306a36Sopenharmony_ci for (place = 14; place < ARRAY_SIZE(channel5g); place++) { 89662306a36Sopenharmony_ci if (channel5g[place] == chnl) { 89762306a36Sopenharmony_ci place++; 89862306a36Sopenharmony_ci break; 89962306a36Sopenharmony_ci } 90062306a36Sopenharmony_ci } 90162306a36Sopenharmony_ci } 90262306a36Sopenharmony_ci return place; 90362306a36Sopenharmony_ci} 90462306a36Sopenharmony_ci 90562306a36Sopenharmony_civoid rtl92d_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel) 90662306a36Sopenharmony_ci{ 90762306a36Sopenharmony_ci struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 90862306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 90962306a36Sopenharmony_ci u8 cckpowerlevel[2], ofdmpowerlevel[2]; 91062306a36Sopenharmony_ci 91162306a36Sopenharmony_ci if (!rtlefuse->txpwr_fromeprom) 91262306a36Sopenharmony_ci return; 91362306a36Sopenharmony_ci channel = _rtl92c_phy_get_rightchnlplace(channel); 91462306a36Sopenharmony_ci _rtl92d_get_txpower_index(hw, channel, &cckpowerlevel[0], 91562306a36Sopenharmony_ci &ofdmpowerlevel[0]); 91662306a36Sopenharmony_ci if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G) 91762306a36Sopenharmony_ci _rtl92d_ccxpower_index_check(hw, channel, &cckpowerlevel[0], 91862306a36Sopenharmony_ci &ofdmpowerlevel[0]); 91962306a36Sopenharmony_ci if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G) 92062306a36Sopenharmony_ci rtl92d_phy_rf6052_set_cck_txpower(hw, &cckpowerlevel[0]); 92162306a36Sopenharmony_ci rtl92d_phy_rf6052_set_ofdm_txpower(hw, &ofdmpowerlevel[0], channel); 92262306a36Sopenharmony_ci} 92362306a36Sopenharmony_ci 92462306a36Sopenharmony_civoid rtl92d_phy_set_bw_mode(struct ieee80211_hw *hw, 92562306a36Sopenharmony_ci enum nl80211_channel_type ch_type) 92662306a36Sopenharmony_ci{ 92762306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 92862306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 92962306a36Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 93062306a36Sopenharmony_ci struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 93162306a36Sopenharmony_ci unsigned long flag = 0; 93262306a36Sopenharmony_ci u8 reg_prsr_rsc; 93362306a36Sopenharmony_ci u8 reg_bw_opmode; 93462306a36Sopenharmony_ci 93562306a36Sopenharmony_ci if (rtlphy->set_bwmode_inprogress) 93662306a36Sopenharmony_ci return; 93762306a36Sopenharmony_ci if ((is_hal_stop(rtlhal)) || (RT_CANNOT_IO(hw))) { 93862306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_ERR, DBG_WARNING, 93962306a36Sopenharmony_ci "FALSE driver sleep or unload\n"); 94062306a36Sopenharmony_ci return; 94162306a36Sopenharmony_ci } 94262306a36Sopenharmony_ci rtlphy->set_bwmode_inprogress = true; 94362306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_SCAN, DBG_TRACE, "Switch to %s bandwidth\n", 94462306a36Sopenharmony_ci rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20 ? 94562306a36Sopenharmony_ci "20MHz" : "40MHz"); 94662306a36Sopenharmony_ci reg_bw_opmode = rtl_read_byte(rtlpriv, REG_BWOPMODE); 94762306a36Sopenharmony_ci reg_prsr_rsc = rtl_read_byte(rtlpriv, REG_RRSR + 2); 94862306a36Sopenharmony_ci switch (rtlphy->current_chan_bw) { 94962306a36Sopenharmony_ci case HT_CHANNEL_WIDTH_20: 95062306a36Sopenharmony_ci reg_bw_opmode |= BW_OPMODE_20MHZ; 95162306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode); 95262306a36Sopenharmony_ci break; 95362306a36Sopenharmony_ci case HT_CHANNEL_WIDTH_20_40: 95462306a36Sopenharmony_ci reg_bw_opmode &= ~BW_OPMODE_20MHZ; 95562306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode); 95662306a36Sopenharmony_ci 95762306a36Sopenharmony_ci reg_prsr_rsc = (reg_prsr_rsc & 0x90) | 95862306a36Sopenharmony_ci (mac->cur_40_prime_sc << 5); 95962306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_RRSR + 2, reg_prsr_rsc); 96062306a36Sopenharmony_ci break; 96162306a36Sopenharmony_ci default: 96262306a36Sopenharmony_ci pr_err("unknown bandwidth: %#X\n", 96362306a36Sopenharmony_ci rtlphy->current_chan_bw); 96462306a36Sopenharmony_ci break; 96562306a36Sopenharmony_ci } 96662306a36Sopenharmony_ci switch (rtlphy->current_chan_bw) { 96762306a36Sopenharmony_ci case HT_CHANNEL_WIDTH_20: 96862306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_RFMOD, BRFMOD, 0x0); 96962306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA1_RFMOD, BRFMOD, 0x0); 97062306a36Sopenharmony_ci /* SET BIT10 BIT11 for receive cck */ 97162306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10) | 97262306a36Sopenharmony_ci BIT(11), 3); 97362306a36Sopenharmony_ci break; 97462306a36Sopenharmony_ci case HT_CHANNEL_WIDTH_20_40: 97562306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_RFMOD, BRFMOD, 0x1); 97662306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA1_RFMOD, BRFMOD, 0x1); 97762306a36Sopenharmony_ci /* Set Control channel to upper or lower. 97862306a36Sopenharmony_ci * These settings are required only for 40MHz */ 97962306a36Sopenharmony_ci if (rtlhal->current_bandtype == BAND_ON_2_4G) { 98062306a36Sopenharmony_ci rtl92d_acquire_cckandrw_pagea_ctl(hw, &flag); 98162306a36Sopenharmony_ci rtl_set_bbreg(hw, RCCK0_SYSTEM, BCCKSIDEBAND, 98262306a36Sopenharmony_ci (mac->cur_40_prime_sc >> 1)); 98362306a36Sopenharmony_ci rtl92d_release_cckandrw_pagea_ctl(hw, &flag); 98462306a36Sopenharmony_ci } 98562306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM1_LSTF, 0xC00, mac->cur_40_prime_sc); 98662306a36Sopenharmony_ci /* SET BIT10 BIT11 for receive cck */ 98762306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10) | 98862306a36Sopenharmony_ci BIT(11), 0); 98962306a36Sopenharmony_ci rtl_set_bbreg(hw, 0x818, (BIT(26) | BIT(27)), 99062306a36Sopenharmony_ci (mac->cur_40_prime_sc == 99162306a36Sopenharmony_ci HAL_PRIME_CHNL_OFFSET_LOWER) ? 2 : 1); 99262306a36Sopenharmony_ci break; 99362306a36Sopenharmony_ci default: 99462306a36Sopenharmony_ci pr_err("unknown bandwidth: %#X\n", 99562306a36Sopenharmony_ci rtlphy->current_chan_bw); 99662306a36Sopenharmony_ci break; 99762306a36Sopenharmony_ci 99862306a36Sopenharmony_ci } 99962306a36Sopenharmony_ci rtl92d_phy_rf6052_set_bandwidth(hw, rtlphy->current_chan_bw); 100062306a36Sopenharmony_ci rtlphy->set_bwmode_inprogress = false; 100162306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_SCAN, DBG_TRACE, "<==\n"); 100262306a36Sopenharmony_ci} 100362306a36Sopenharmony_ci 100462306a36Sopenharmony_cistatic void _rtl92d_phy_stop_trx_before_changeband(struct ieee80211_hw *hw) 100562306a36Sopenharmony_ci{ 100662306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_RFMOD, BCCKEN, 0); 100762306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_RFMOD, BOFDMEN, 0); 100862306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_TRXPATHENABLE, MASKBYTE0, 0x00); 100962306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM1_TRXPATHENABLE, BDWORD, 0x0); 101062306a36Sopenharmony_ci} 101162306a36Sopenharmony_ci 101262306a36Sopenharmony_cistatic void rtl92d_phy_switch_wirelessband(struct ieee80211_hw *hw, u8 band) 101362306a36Sopenharmony_ci{ 101462306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 101562306a36Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 101662306a36Sopenharmony_ci u8 value8; 101762306a36Sopenharmony_ci 101862306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, "==>\n"); 101962306a36Sopenharmony_ci rtlhal->bandset = band; 102062306a36Sopenharmony_ci rtlhal->current_bandtype = band; 102162306a36Sopenharmony_ci if (IS_92D_SINGLEPHY(rtlhal->version)) 102262306a36Sopenharmony_ci rtlhal->bandset = BAND_ON_BOTH; 102362306a36Sopenharmony_ci /* stop RX/Tx */ 102462306a36Sopenharmony_ci _rtl92d_phy_stop_trx_before_changeband(hw); 102562306a36Sopenharmony_ci /* reconfig BB/RF according to wireless mode */ 102662306a36Sopenharmony_ci if (rtlhal->current_bandtype == BAND_ON_2_4G) { 102762306a36Sopenharmony_ci /* BB & RF Config */ 102862306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_DMESG, "====>2.4G\n"); 102962306a36Sopenharmony_ci if (rtlhal->interfaceindex == 1) 103062306a36Sopenharmony_ci _rtl92d_phy_config_bb_with_headerfile(hw, 103162306a36Sopenharmony_ci BASEBAND_CONFIG_AGC_TAB); 103262306a36Sopenharmony_ci } else { 103362306a36Sopenharmony_ci /* 5G band */ 103462306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_DMESG, "====>5G\n"); 103562306a36Sopenharmony_ci if (rtlhal->interfaceindex == 1) 103662306a36Sopenharmony_ci _rtl92d_phy_config_bb_with_headerfile(hw, 103762306a36Sopenharmony_ci BASEBAND_CONFIG_AGC_TAB); 103862306a36Sopenharmony_ci } 103962306a36Sopenharmony_ci rtl92d_update_bbrf_configuration(hw); 104062306a36Sopenharmony_ci if (rtlhal->current_bandtype == BAND_ON_2_4G) 104162306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_RFMOD, BCCKEN, 0x1); 104262306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_RFMOD, BOFDMEN, 0x1); 104362306a36Sopenharmony_ci 104462306a36Sopenharmony_ci /* 20M BW. */ 104562306a36Sopenharmony_ci /* rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 1); */ 104662306a36Sopenharmony_ci rtlhal->reloadtxpowerindex = true; 104762306a36Sopenharmony_ci /* notice fw know band status 0x81[1]/0x53[1] = 0: 5G, 1: 2G */ 104862306a36Sopenharmony_ci if (rtlhal->current_bandtype == BAND_ON_2_4G) { 104962306a36Sopenharmony_ci value8 = rtl_read_byte(rtlpriv, (rtlhal->interfaceindex == 105062306a36Sopenharmony_ci 0 ? REG_MAC0 : REG_MAC1)); 105162306a36Sopenharmony_ci value8 |= BIT(1); 105262306a36Sopenharmony_ci rtl_write_byte(rtlpriv, (rtlhal->interfaceindex == 105362306a36Sopenharmony_ci 0 ? REG_MAC0 : REG_MAC1), value8); 105462306a36Sopenharmony_ci } else { 105562306a36Sopenharmony_ci value8 = rtl_read_byte(rtlpriv, (rtlhal->interfaceindex == 105662306a36Sopenharmony_ci 0 ? REG_MAC0 : REG_MAC1)); 105762306a36Sopenharmony_ci value8 &= (~BIT(1)); 105862306a36Sopenharmony_ci rtl_write_byte(rtlpriv, (rtlhal->interfaceindex == 105962306a36Sopenharmony_ci 0 ? REG_MAC0 : REG_MAC1), value8); 106062306a36Sopenharmony_ci } 106162306a36Sopenharmony_ci mdelay(1); 106262306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, "<==Switch Band OK\n"); 106362306a36Sopenharmony_ci} 106462306a36Sopenharmony_ci 106562306a36Sopenharmony_cistatic void _rtl92d_phy_reload_imr_setting(struct ieee80211_hw *hw, 106662306a36Sopenharmony_ci u8 channel, u8 rfpath) 106762306a36Sopenharmony_ci{ 106862306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 106962306a36Sopenharmony_ci u32 imr_num = MAX_RF_IMR_INDEX; 107062306a36Sopenharmony_ci u32 rfmask = RFREG_OFFSET_MASK; 107162306a36Sopenharmony_ci u8 group, i; 107262306a36Sopenharmony_ci unsigned long flag = 0; 107362306a36Sopenharmony_ci 107462306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, "====>path %d\n", rfpath); 107562306a36Sopenharmony_ci if (rtlpriv->rtlhal.current_bandtype == BAND_ON_5G) { 107662306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, "====>5G\n"); 107762306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_RFMOD, BIT(25) | BIT(24), 0); 107862306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER4, 0x00f00000, 0xf); 107962306a36Sopenharmony_ci /* fc area 0xd2c */ 108062306a36Sopenharmony_ci if (channel > 99) 108162306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM1_CFOTRACKING, BIT(13) | 108262306a36Sopenharmony_ci BIT(14), 2); 108362306a36Sopenharmony_ci else 108462306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM1_CFOTRACKING, BIT(13) | 108562306a36Sopenharmony_ci BIT(14), 1); 108662306a36Sopenharmony_ci /* leave 0 for channel1-14. */ 108762306a36Sopenharmony_ci group = channel <= 64 ? 1 : 2; 108862306a36Sopenharmony_ci imr_num = MAX_RF_IMR_INDEX_NORMAL; 108962306a36Sopenharmony_ci for (i = 0; i < imr_num; i++) 109062306a36Sopenharmony_ci rtl_set_rfreg(hw, (enum radio_path)rfpath, 109162306a36Sopenharmony_ci rf_reg_for_5g_swchnl_normal[i], rfmask, 109262306a36Sopenharmony_ci rf_imr_param_normal[0][group][i]); 109362306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER4, 0x00f00000, 0); 109462306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_RFMOD, BOFDMEN, 1); 109562306a36Sopenharmony_ci } else { 109662306a36Sopenharmony_ci /* G band. */ 109762306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_SCAN, DBG_LOUD, 109862306a36Sopenharmony_ci "Load RF IMR parameters for G band. IMR already setting %d\n", 109962306a36Sopenharmony_ci rtlpriv->rtlhal.load_imrandiqk_setting_for2g); 110062306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, "====>2.4G\n"); 110162306a36Sopenharmony_ci if (!rtlpriv->rtlhal.load_imrandiqk_setting_for2g) { 110262306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_SCAN, DBG_LOUD, 110362306a36Sopenharmony_ci "Load RF IMR parameters for G band. %d\n", 110462306a36Sopenharmony_ci rfpath); 110562306a36Sopenharmony_ci rtl92d_acquire_cckandrw_pagea_ctl(hw, &flag); 110662306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_RFMOD, BIT(25) | BIT(24), 0); 110762306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER4, 110862306a36Sopenharmony_ci 0x00f00000, 0xf); 110962306a36Sopenharmony_ci imr_num = MAX_RF_IMR_INDEX_NORMAL; 111062306a36Sopenharmony_ci for (i = 0; i < imr_num; i++) { 111162306a36Sopenharmony_ci rtl_set_rfreg(hw, (enum radio_path)rfpath, 111262306a36Sopenharmony_ci rf_reg_for_5g_swchnl_normal[i], 111362306a36Sopenharmony_ci RFREG_OFFSET_MASK, 111462306a36Sopenharmony_ci rf_imr_param_normal[0][0][i]); 111562306a36Sopenharmony_ci } 111662306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER4, 111762306a36Sopenharmony_ci 0x00f00000, 0); 111862306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_RFMOD, BOFDMEN | BCCKEN, 3); 111962306a36Sopenharmony_ci rtl92d_release_cckandrw_pagea_ctl(hw, &flag); 112062306a36Sopenharmony_ci } 112162306a36Sopenharmony_ci } 112262306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, "<====\n"); 112362306a36Sopenharmony_ci} 112462306a36Sopenharmony_ci 112562306a36Sopenharmony_cistatic void _rtl92d_phy_enable_rf_env(struct ieee80211_hw *hw, 112662306a36Sopenharmony_ci u8 rfpath, u32 *pu4_regval) 112762306a36Sopenharmony_ci{ 112862306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 112962306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 113062306a36Sopenharmony_ci struct bb_reg_def *pphyreg = &rtlphy->phyreg_def[rfpath]; 113162306a36Sopenharmony_ci 113262306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_LOUD, "====>\n"); 113362306a36Sopenharmony_ci /*----Store original RFENV control type----*/ 113462306a36Sopenharmony_ci switch (rfpath) { 113562306a36Sopenharmony_ci case RF90_PATH_A: 113662306a36Sopenharmony_ci case RF90_PATH_C: 113762306a36Sopenharmony_ci *pu4_regval = rtl_get_bbreg(hw, pphyreg->rfintfs, BRFSI_RFENV); 113862306a36Sopenharmony_ci break; 113962306a36Sopenharmony_ci case RF90_PATH_B: 114062306a36Sopenharmony_ci case RF90_PATH_D: 114162306a36Sopenharmony_ci *pu4_regval = 114262306a36Sopenharmony_ci rtl_get_bbreg(hw, pphyreg->rfintfs, BRFSI_RFENV << 16); 114362306a36Sopenharmony_ci break; 114462306a36Sopenharmony_ci } 114562306a36Sopenharmony_ci /*----Set RF_ENV enable----*/ 114662306a36Sopenharmony_ci rtl_set_bbreg(hw, pphyreg->rfintfe, BRFSI_RFENV << 16, 0x1); 114762306a36Sopenharmony_ci udelay(1); 114862306a36Sopenharmony_ci /*----Set RF_ENV output high----*/ 114962306a36Sopenharmony_ci rtl_set_bbreg(hw, pphyreg->rfintfo, BRFSI_RFENV, 0x1); 115062306a36Sopenharmony_ci udelay(1); 115162306a36Sopenharmony_ci /* Set bit number of Address and Data for RF register */ 115262306a36Sopenharmony_ci /* Set 1 to 4 bits for 8255 */ 115362306a36Sopenharmony_ci rtl_set_bbreg(hw, pphyreg->rfhssi_para2, B3WIREADDRESSLENGTH, 0x0); 115462306a36Sopenharmony_ci udelay(1); 115562306a36Sopenharmony_ci /*Set 0 to 12 bits for 8255 */ 115662306a36Sopenharmony_ci rtl_set_bbreg(hw, pphyreg->rfhssi_para2, B3WIREDATALENGTH, 0x0); 115762306a36Sopenharmony_ci udelay(1); 115862306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_LOUD, "<====\n"); 115962306a36Sopenharmony_ci} 116062306a36Sopenharmony_ci 116162306a36Sopenharmony_cistatic void _rtl92d_phy_restore_rf_env(struct ieee80211_hw *hw, u8 rfpath, 116262306a36Sopenharmony_ci u32 *pu4_regval) 116362306a36Sopenharmony_ci{ 116462306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 116562306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 116662306a36Sopenharmony_ci struct bb_reg_def *pphyreg = &rtlphy->phyreg_def[rfpath]; 116762306a36Sopenharmony_ci 116862306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_LOUD, "=====>\n"); 116962306a36Sopenharmony_ci /*----Restore RFENV control type----*/ 117062306a36Sopenharmony_ci switch (rfpath) { 117162306a36Sopenharmony_ci case RF90_PATH_A: 117262306a36Sopenharmony_ci case RF90_PATH_C: 117362306a36Sopenharmony_ci rtl_set_bbreg(hw, pphyreg->rfintfs, BRFSI_RFENV, *pu4_regval); 117462306a36Sopenharmony_ci break; 117562306a36Sopenharmony_ci case RF90_PATH_B: 117662306a36Sopenharmony_ci case RF90_PATH_D: 117762306a36Sopenharmony_ci rtl_set_bbreg(hw, pphyreg->rfintfs, BRFSI_RFENV << 16, 117862306a36Sopenharmony_ci *pu4_regval); 117962306a36Sopenharmony_ci break; 118062306a36Sopenharmony_ci } 118162306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_LOUD, "<=====\n"); 118262306a36Sopenharmony_ci} 118362306a36Sopenharmony_ci 118462306a36Sopenharmony_cistatic void _rtl92d_phy_switch_rf_setting(struct ieee80211_hw *hw, u8 channel) 118562306a36Sopenharmony_ci{ 118662306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 118762306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 118862306a36Sopenharmony_ci struct rtl_hal *rtlhal = &(rtlpriv->rtlhal); 118962306a36Sopenharmony_ci u8 path = rtlhal->current_bandtype == 119062306a36Sopenharmony_ci BAND_ON_5G ? RF90_PATH_A : RF90_PATH_B; 119162306a36Sopenharmony_ci u8 index = 0, i = 0, rfpath = RF90_PATH_A; 119262306a36Sopenharmony_ci bool need_pwr_down = false, internal_pa = false; 119362306a36Sopenharmony_ci u32 u4regvalue, mask = 0x1C000, value = 0, u4tmp, u4tmp2; 119462306a36Sopenharmony_ci 119562306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, "====>\n"); 119662306a36Sopenharmony_ci /* config path A for 5G */ 119762306a36Sopenharmony_ci if (rtlhal->current_bandtype == BAND_ON_5G) { 119862306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, "====>5G\n"); 119962306a36Sopenharmony_ci u4tmp = curveindex_5g[channel - 1]; 120062306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 120162306a36Sopenharmony_ci "ver 1 set RF-A, 5G, 0x28 = 0x%x !!\n", u4tmp); 120262306a36Sopenharmony_ci for (i = 0; i < RF_CHNL_NUM_5G; i++) { 120362306a36Sopenharmony_ci if (channel == rf_chnl_5g[i] && channel <= 140) 120462306a36Sopenharmony_ci index = 0; 120562306a36Sopenharmony_ci } 120662306a36Sopenharmony_ci for (i = 0; i < RF_CHNL_NUM_5G_40M; i++) { 120762306a36Sopenharmony_ci if (channel == rf_chnl_5g_40m[i] && channel <= 140) 120862306a36Sopenharmony_ci index = 1; 120962306a36Sopenharmony_ci } 121062306a36Sopenharmony_ci if (channel == 149 || channel == 155 || channel == 161) 121162306a36Sopenharmony_ci index = 2; 121262306a36Sopenharmony_ci else if (channel == 151 || channel == 153 || channel == 163 121362306a36Sopenharmony_ci || channel == 165) 121462306a36Sopenharmony_ci index = 3; 121562306a36Sopenharmony_ci else if (channel == 157 || channel == 159) 121662306a36Sopenharmony_ci index = 4; 121762306a36Sopenharmony_ci 121862306a36Sopenharmony_ci if (rtlhal->macphymode == DUALMAC_DUALPHY 121962306a36Sopenharmony_ci && rtlhal->interfaceindex == 1) { 122062306a36Sopenharmony_ci need_pwr_down = rtl92d_phy_enable_anotherphy(hw, false); 122162306a36Sopenharmony_ci rtlhal->during_mac1init_radioa = true; 122262306a36Sopenharmony_ci /* asume no this case */ 122362306a36Sopenharmony_ci if (need_pwr_down) 122462306a36Sopenharmony_ci _rtl92d_phy_enable_rf_env(hw, path, 122562306a36Sopenharmony_ci &u4regvalue); 122662306a36Sopenharmony_ci } 122762306a36Sopenharmony_ci for (i = 0; i < RF_REG_NUM_FOR_C_CUT_5G; i++) { 122862306a36Sopenharmony_ci if (i == 0 && (rtlhal->macphymode == DUALMAC_DUALPHY)) { 122962306a36Sopenharmony_ci rtl_set_rfreg(hw, (enum radio_path)path, 123062306a36Sopenharmony_ci rf_reg_for_c_cut_5g[i], 123162306a36Sopenharmony_ci RFREG_OFFSET_MASK, 0xE439D); 123262306a36Sopenharmony_ci } else if (rf_reg_for_c_cut_5g[i] == RF_SYN_G4) { 123362306a36Sopenharmony_ci u4tmp2 = (rf_reg_pram_c_5g[index][i] & 123462306a36Sopenharmony_ci 0x7FF) | (u4tmp << 11); 123562306a36Sopenharmony_ci if (channel == 36) 123662306a36Sopenharmony_ci u4tmp2 &= ~(BIT(7) | BIT(6)); 123762306a36Sopenharmony_ci rtl_set_rfreg(hw, (enum radio_path)path, 123862306a36Sopenharmony_ci rf_reg_for_c_cut_5g[i], 123962306a36Sopenharmony_ci RFREG_OFFSET_MASK, u4tmp2); 124062306a36Sopenharmony_ci } else { 124162306a36Sopenharmony_ci rtl_set_rfreg(hw, (enum radio_path)path, 124262306a36Sopenharmony_ci rf_reg_for_c_cut_5g[i], 124362306a36Sopenharmony_ci RFREG_OFFSET_MASK, 124462306a36Sopenharmony_ci rf_reg_pram_c_5g[index][i]); 124562306a36Sopenharmony_ci } 124662306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, 124762306a36Sopenharmony_ci "offset 0x%x value 0x%x path %d index %d readback 0x%x\n", 124862306a36Sopenharmony_ci rf_reg_for_c_cut_5g[i], 124962306a36Sopenharmony_ci rf_reg_pram_c_5g[index][i], 125062306a36Sopenharmony_ci path, index, 125162306a36Sopenharmony_ci rtl_get_rfreg(hw, (enum radio_path)path, 125262306a36Sopenharmony_ci rf_reg_for_c_cut_5g[i], 125362306a36Sopenharmony_ci RFREG_OFFSET_MASK)); 125462306a36Sopenharmony_ci } 125562306a36Sopenharmony_ci if (need_pwr_down) 125662306a36Sopenharmony_ci _rtl92d_phy_restore_rf_env(hw, path, &u4regvalue); 125762306a36Sopenharmony_ci if (rtlhal->during_mac1init_radioa) 125862306a36Sopenharmony_ci rtl92d_phy_powerdown_anotherphy(hw, false); 125962306a36Sopenharmony_ci if (channel < 149) 126062306a36Sopenharmony_ci value = 0x07; 126162306a36Sopenharmony_ci else if (channel >= 149) 126262306a36Sopenharmony_ci value = 0x02; 126362306a36Sopenharmony_ci if (channel >= 36 && channel <= 64) 126462306a36Sopenharmony_ci index = 0; 126562306a36Sopenharmony_ci else if (channel >= 100 && channel <= 140) 126662306a36Sopenharmony_ci index = 1; 126762306a36Sopenharmony_ci else 126862306a36Sopenharmony_ci index = 2; 126962306a36Sopenharmony_ci for (rfpath = RF90_PATH_A; rfpath < rtlphy->num_total_rfpath; 127062306a36Sopenharmony_ci rfpath++) { 127162306a36Sopenharmony_ci if (rtlhal->macphymode == DUALMAC_DUALPHY && 127262306a36Sopenharmony_ci rtlhal->interfaceindex == 1) /* MAC 1 5G */ 127362306a36Sopenharmony_ci internal_pa = rtlpriv->efuse.internal_pa_5g[1]; 127462306a36Sopenharmony_ci else 127562306a36Sopenharmony_ci internal_pa = 127662306a36Sopenharmony_ci rtlpriv->efuse.internal_pa_5g[rfpath]; 127762306a36Sopenharmony_ci if (internal_pa) { 127862306a36Sopenharmony_ci for (i = 0; 127962306a36Sopenharmony_ci i < RF_REG_NUM_FOR_C_CUT_5G_INTERNALPA; 128062306a36Sopenharmony_ci i++) { 128162306a36Sopenharmony_ci rtl_set_rfreg(hw, rfpath, 128262306a36Sopenharmony_ci rf_for_c_cut_5g_internal_pa[i], 128362306a36Sopenharmony_ci RFREG_OFFSET_MASK, 128462306a36Sopenharmony_ci rf_pram_c_5g_int_pa[index][i]); 128562306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_LOUD, 128662306a36Sopenharmony_ci "offset 0x%x value 0x%x path %d index %d\n", 128762306a36Sopenharmony_ci rf_for_c_cut_5g_internal_pa[i], 128862306a36Sopenharmony_ci rf_pram_c_5g_int_pa[index][i], 128962306a36Sopenharmony_ci rfpath, index); 129062306a36Sopenharmony_ci } 129162306a36Sopenharmony_ci } else { 129262306a36Sopenharmony_ci rtl_set_rfreg(hw, (enum radio_path)rfpath, 0x0B, 129362306a36Sopenharmony_ci mask, value); 129462306a36Sopenharmony_ci } 129562306a36Sopenharmony_ci } 129662306a36Sopenharmony_ci } else if (rtlhal->current_bandtype == BAND_ON_2_4G) { 129762306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, "====>2.4G\n"); 129862306a36Sopenharmony_ci u4tmp = curveindex_2g[channel - 1]; 129962306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 130062306a36Sopenharmony_ci "ver 3 set RF-B, 2G, 0x28 = 0x%x !!\n", u4tmp); 130162306a36Sopenharmony_ci if (channel == 1 || channel == 2 || channel == 4 || channel == 9 130262306a36Sopenharmony_ci || channel == 10 || channel == 11 || channel == 12) 130362306a36Sopenharmony_ci index = 0; 130462306a36Sopenharmony_ci else if (channel == 3 || channel == 13 || channel == 14) 130562306a36Sopenharmony_ci index = 1; 130662306a36Sopenharmony_ci else if (channel >= 5 && channel <= 8) 130762306a36Sopenharmony_ci index = 2; 130862306a36Sopenharmony_ci if (rtlhal->macphymode == DUALMAC_DUALPHY) { 130962306a36Sopenharmony_ci path = RF90_PATH_A; 131062306a36Sopenharmony_ci if (rtlhal->interfaceindex == 0) { 131162306a36Sopenharmony_ci need_pwr_down = 131262306a36Sopenharmony_ci rtl92d_phy_enable_anotherphy(hw, true); 131362306a36Sopenharmony_ci rtlhal->during_mac0init_radiob = true; 131462306a36Sopenharmony_ci 131562306a36Sopenharmony_ci if (need_pwr_down) 131662306a36Sopenharmony_ci _rtl92d_phy_enable_rf_env(hw, path, 131762306a36Sopenharmony_ci &u4regvalue); 131862306a36Sopenharmony_ci } 131962306a36Sopenharmony_ci } 132062306a36Sopenharmony_ci for (i = 0; i < RF_REG_NUM_FOR_C_CUT_2G; i++) { 132162306a36Sopenharmony_ci if (rf_reg_for_c_cut_2g[i] == RF_SYN_G7) 132262306a36Sopenharmony_ci rtl_set_rfreg(hw, (enum radio_path)path, 132362306a36Sopenharmony_ci rf_reg_for_c_cut_2g[i], 132462306a36Sopenharmony_ci RFREG_OFFSET_MASK, 132562306a36Sopenharmony_ci (rf_reg_param_for_c_cut_2g[index][i] | 132662306a36Sopenharmony_ci BIT(17))); 132762306a36Sopenharmony_ci else 132862306a36Sopenharmony_ci rtl_set_rfreg(hw, (enum radio_path)path, 132962306a36Sopenharmony_ci rf_reg_for_c_cut_2g[i], 133062306a36Sopenharmony_ci RFREG_OFFSET_MASK, 133162306a36Sopenharmony_ci rf_reg_param_for_c_cut_2g 133262306a36Sopenharmony_ci [index][i]); 133362306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE, 133462306a36Sopenharmony_ci "offset 0x%x value 0x%x mak 0x%x path %d index %d readback 0x%x\n", 133562306a36Sopenharmony_ci rf_reg_for_c_cut_2g[i], 133662306a36Sopenharmony_ci rf_reg_param_for_c_cut_2g[index][i], 133762306a36Sopenharmony_ci rf_reg_mask_for_c_cut_2g[i], path, index, 133862306a36Sopenharmony_ci rtl_get_rfreg(hw, (enum radio_path)path, 133962306a36Sopenharmony_ci rf_reg_for_c_cut_2g[i], 134062306a36Sopenharmony_ci RFREG_OFFSET_MASK)); 134162306a36Sopenharmony_ci } 134262306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 134362306a36Sopenharmony_ci "cosa ver 3 set RF-B, 2G, 0x28 = 0x%x !!\n", 134462306a36Sopenharmony_ci rf_syn_g4_for_c_cut_2g | (u4tmp << 11)); 134562306a36Sopenharmony_ci 134662306a36Sopenharmony_ci rtl_set_rfreg(hw, (enum radio_path)path, RF_SYN_G4, 134762306a36Sopenharmony_ci RFREG_OFFSET_MASK, 134862306a36Sopenharmony_ci rf_syn_g4_for_c_cut_2g | (u4tmp << 11)); 134962306a36Sopenharmony_ci if (need_pwr_down) 135062306a36Sopenharmony_ci _rtl92d_phy_restore_rf_env(hw, path, &u4regvalue); 135162306a36Sopenharmony_ci if (rtlhal->during_mac0init_radiob) 135262306a36Sopenharmony_ci rtl92d_phy_powerdown_anotherphy(hw, true); 135362306a36Sopenharmony_ci } 135462306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, "<====\n"); 135562306a36Sopenharmony_ci} 135662306a36Sopenharmony_ci 135762306a36Sopenharmony_ciu8 rtl92d_get_rightchnlplace_for_iqk(u8 chnl) 135862306a36Sopenharmony_ci{ 135962306a36Sopenharmony_ci u8 place; 136062306a36Sopenharmony_ci 136162306a36Sopenharmony_ci if (chnl > 14) { 136262306a36Sopenharmony_ci for (place = 14; place < ARRAY_SIZE(channel_all); place++) { 136362306a36Sopenharmony_ci if (channel_all[place] == chnl) 136462306a36Sopenharmony_ci return place - 13; 136562306a36Sopenharmony_ci } 136662306a36Sopenharmony_ci } 136762306a36Sopenharmony_ci 136862306a36Sopenharmony_ci return 0; 136962306a36Sopenharmony_ci} 137062306a36Sopenharmony_ci 137162306a36Sopenharmony_ci#define MAX_TOLERANCE 5 137262306a36Sopenharmony_ci#define IQK_DELAY_TIME 1 /* ms */ 137362306a36Sopenharmony_ci#define MAX_TOLERANCE_92D 3 137462306a36Sopenharmony_ci 137562306a36Sopenharmony_ci/* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */ 137662306a36Sopenharmony_cistatic u8 _rtl92d_phy_patha_iqk(struct ieee80211_hw *hw, bool configpathb) 137762306a36Sopenharmony_ci{ 137862306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 137962306a36Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 138062306a36Sopenharmony_ci u32 regeac, rege94, rege9c, regea4; 138162306a36Sopenharmony_ci u8 result = 0; 138262306a36Sopenharmony_ci 138362306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "Path A IQK!\n"); 138462306a36Sopenharmony_ci /* path-A IQK setting */ 138562306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "Path-A IQK setting!\n"); 138662306a36Sopenharmony_ci if (rtlhal->interfaceindex == 0) { 138762306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe30, MASKDWORD, 0x10008c1f); 138862306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe34, MASKDWORD, 0x10008c1f); 138962306a36Sopenharmony_ci } else { 139062306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe30, MASKDWORD, 0x10008c22); 139162306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe34, MASKDWORD, 0x10008c22); 139262306a36Sopenharmony_ci } 139362306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe38, MASKDWORD, 0x82140102); 139462306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe3c, MASKDWORD, 0x28160206); 139562306a36Sopenharmony_ci /* path-B IQK setting */ 139662306a36Sopenharmony_ci if (configpathb) { 139762306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe50, MASKDWORD, 0x10008c22); 139862306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe54, MASKDWORD, 0x10008c22); 139962306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe58, MASKDWORD, 0x82140102); 140062306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe5c, MASKDWORD, 0x28160206); 140162306a36Sopenharmony_ci } 140262306a36Sopenharmony_ci /* LO calibration setting */ 140362306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "LO calibration setting!\n"); 140462306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe4c, MASKDWORD, 0x00462911); 140562306a36Sopenharmony_ci /* One shot, path A LOK & IQK */ 140662306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "One shot, path A LOK & IQK!\n"); 140762306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe48, MASKDWORD, 0xf9000000); 140862306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe48, MASKDWORD, 0xf8000000); 140962306a36Sopenharmony_ci /* delay x ms */ 141062306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 141162306a36Sopenharmony_ci "Delay %d ms for One shot, path A LOK & IQK\n", 141262306a36Sopenharmony_ci IQK_DELAY_TIME); 141362306a36Sopenharmony_ci mdelay(IQK_DELAY_TIME); 141462306a36Sopenharmony_ci /* Check failed */ 141562306a36Sopenharmony_ci regeac = rtl_get_bbreg(hw, 0xeac, MASKDWORD); 141662306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "0xeac = 0x%x\n", regeac); 141762306a36Sopenharmony_ci rege94 = rtl_get_bbreg(hw, 0xe94, MASKDWORD); 141862306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "0xe94 = 0x%x\n", rege94); 141962306a36Sopenharmony_ci rege9c = rtl_get_bbreg(hw, 0xe9c, MASKDWORD); 142062306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "0xe9c = 0x%x\n", rege9c); 142162306a36Sopenharmony_ci regea4 = rtl_get_bbreg(hw, 0xea4, MASKDWORD); 142262306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "0xea4 = 0x%x\n", regea4); 142362306a36Sopenharmony_ci if (!(regeac & BIT(28)) && (((rege94 & 0x03FF0000) >> 16) != 0x142) && 142462306a36Sopenharmony_ci (((rege9c & 0x03FF0000) >> 16) != 0x42)) 142562306a36Sopenharmony_ci result |= 0x01; 142662306a36Sopenharmony_ci else /* if Tx not OK, ignore Rx */ 142762306a36Sopenharmony_ci return result; 142862306a36Sopenharmony_ci /* if Tx is OK, check whether Rx is OK */ 142962306a36Sopenharmony_ci if (!(regeac & BIT(27)) && (((regea4 & 0x03FF0000) >> 16) != 0x132) && 143062306a36Sopenharmony_ci (((regeac & 0x03FF0000) >> 16) != 0x36)) 143162306a36Sopenharmony_ci result |= 0x02; 143262306a36Sopenharmony_ci else 143362306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "Path A Rx IQK fail!!\n"); 143462306a36Sopenharmony_ci return result; 143562306a36Sopenharmony_ci} 143662306a36Sopenharmony_ci 143762306a36Sopenharmony_ci/* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */ 143862306a36Sopenharmony_cistatic u8 _rtl92d_phy_patha_iqk_5g_normal(struct ieee80211_hw *hw, 143962306a36Sopenharmony_ci bool configpathb) 144062306a36Sopenharmony_ci{ 144162306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 144262306a36Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 144362306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 144462306a36Sopenharmony_ci u32 regeac, rege94, rege9c, regea4; 144562306a36Sopenharmony_ci u8 result = 0; 144662306a36Sopenharmony_ci u8 i; 144762306a36Sopenharmony_ci u8 retrycount = 2; 144862306a36Sopenharmony_ci u32 TXOKBIT = BIT(28), RXOKBIT = BIT(27); 144962306a36Sopenharmony_ci 145062306a36Sopenharmony_ci if (rtlhal->interfaceindex == 1) { /* PHY1 */ 145162306a36Sopenharmony_ci TXOKBIT = BIT(31); 145262306a36Sopenharmony_ci RXOKBIT = BIT(30); 145362306a36Sopenharmony_ci } 145462306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "Path A IQK!\n"); 145562306a36Sopenharmony_ci /* path-A IQK setting */ 145662306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "Path-A IQK setting!\n"); 145762306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe30, MASKDWORD, 0x18008c1f); 145862306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe34, MASKDWORD, 0x18008c1f); 145962306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe38, MASKDWORD, 0x82140307); 146062306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe3c, MASKDWORD, 0x68160960); 146162306a36Sopenharmony_ci /* path-B IQK setting */ 146262306a36Sopenharmony_ci if (configpathb) { 146362306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe50, MASKDWORD, 0x18008c2f); 146462306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe54, MASKDWORD, 0x18008c2f); 146562306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe58, MASKDWORD, 0x82110000); 146662306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe5c, MASKDWORD, 0x68110000); 146762306a36Sopenharmony_ci } 146862306a36Sopenharmony_ci /* LO calibration setting */ 146962306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "LO calibration setting!\n"); 147062306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe4c, MASKDWORD, 0x00462911); 147162306a36Sopenharmony_ci /* path-A PA on */ 147262306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XAB_RFINTERFACESW, MASKDWORD, 0x07000f60); 147362306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XA_RFINTERFACEOE, MASKDWORD, 0x66e60e30); 147462306a36Sopenharmony_ci for (i = 0; i < retrycount; i++) { 147562306a36Sopenharmony_ci /* One shot, path A LOK & IQK */ 147662306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 147762306a36Sopenharmony_ci "One shot, path A LOK & IQK!\n"); 147862306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe48, MASKDWORD, 0xf9000000); 147962306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe48, MASKDWORD, 0xf8000000); 148062306a36Sopenharmony_ci /* delay x ms */ 148162306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 148262306a36Sopenharmony_ci "Delay %d ms for One shot, path A LOK & IQK.\n", 148362306a36Sopenharmony_ci IQK_DELAY_TIME); 148462306a36Sopenharmony_ci mdelay(IQK_DELAY_TIME * 10); 148562306a36Sopenharmony_ci /* Check failed */ 148662306a36Sopenharmony_ci regeac = rtl_get_bbreg(hw, 0xeac, MASKDWORD); 148762306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "0xeac = 0x%x\n", regeac); 148862306a36Sopenharmony_ci rege94 = rtl_get_bbreg(hw, 0xe94, MASKDWORD); 148962306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "0xe94 = 0x%x\n", rege94); 149062306a36Sopenharmony_ci rege9c = rtl_get_bbreg(hw, 0xe9c, MASKDWORD); 149162306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "0xe9c = 0x%x\n", rege9c); 149262306a36Sopenharmony_ci regea4 = rtl_get_bbreg(hw, 0xea4, MASKDWORD); 149362306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "0xea4 = 0x%x\n", regea4); 149462306a36Sopenharmony_ci if (!(regeac & TXOKBIT) && 149562306a36Sopenharmony_ci (((rege94 & 0x03FF0000) >> 16) != 0x142)) { 149662306a36Sopenharmony_ci result |= 0x01; 149762306a36Sopenharmony_ci } else { /* if Tx not OK, ignore Rx */ 149862306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 149962306a36Sopenharmony_ci "Path A Tx IQK fail!!\n"); 150062306a36Sopenharmony_ci continue; 150162306a36Sopenharmony_ci } 150262306a36Sopenharmony_ci 150362306a36Sopenharmony_ci /* if Tx is OK, check whether Rx is OK */ 150462306a36Sopenharmony_ci if (!(regeac & RXOKBIT) && 150562306a36Sopenharmony_ci (((regea4 & 0x03FF0000) >> 16) != 0x132)) { 150662306a36Sopenharmony_ci result |= 0x02; 150762306a36Sopenharmony_ci break; 150862306a36Sopenharmony_ci } else { 150962306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 151062306a36Sopenharmony_ci "Path A Rx IQK fail!!\n"); 151162306a36Sopenharmony_ci } 151262306a36Sopenharmony_ci } 151362306a36Sopenharmony_ci /* path A PA off */ 151462306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XAB_RFINTERFACESW, MASKDWORD, 151562306a36Sopenharmony_ci rtlphy->iqk_bb_backup[0]); 151662306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XA_RFINTERFACEOE, MASKDWORD, 151762306a36Sopenharmony_ci rtlphy->iqk_bb_backup[1]); 151862306a36Sopenharmony_ci return result; 151962306a36Sopenharmony_ci} 152062306a36Sopenharmony_ci 152162306a36Sopenharmony_ci/* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */ 152262306a36Sopenharmony_cistatic u8 _rtl92d_phy_pathb_iqk(struct ieee80211_hw *hw) 152362306a36Sopenharmony_ci{ 152462306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 152562306a36Sopenharmony_ci u32 regeac, regeb4, regebc, regec4, regecc; 152662306a36Sopenharmony_ci u8 result = 0; 152762306a36Sopenharmony_ci 152862306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "Path B IQK!\n"); 152962306a36Sopenharmony_ci /* One shot, path B LOK & IQK */ 153062306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "One shot, path A LOK & IQK!\n"); 153162306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe60, MASKDWORD, 0x00000002); 153262306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe60, MASKDWORD, 0x00000000); 153362306a36Sopenharmony_ci /* delay x ms */ 153462306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 153562306a36Sopenharmony_ci "Delay %d ms for One shot, path B LOK & IQK\n", IQK_DELAY_TIME); 153662306a36Sopenharmony_ci mdelay(IQK_DELAY_TIME); 153762306a36Sopenharmony_ci /* Check failed */ 153862306a36Sopenharmony_ci regeac = rtl_get_bbreg(hw, 0xeac, MASKDWORD); 153962306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "0xeac = 0x%x\n", regeac); 154062306a36Sopenharmony_ci regeb4 = rtl_get_bbreg(hw, 0xeb4, MASKDWORD); 154162306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "0xeb4 = 0x%x\n", regeb4); 154262306a36Sopenharmony_ci regebc = rtl_get_bbreg(hw, 0xebc, MASKDWORD); 154362306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "0xebc = 0x%x\n", regebc); 154462306a36Sopenharmony_ci regec4 = rtl_get_bbreg(hw, 0xec4, MASKDWORD); 154562306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "0xec4 = 0x%x\n", regec4); 154662306a36Sopenharmony_ci regecc = rtl_get_bbreg(hw, 0xecc, MASKDWORD); 154762306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "0xecc = 0x%x\n", regecc); 154862306a36Sopenharmony_ci if (!(regeac & BIT(31)) && (((regeb4 & 0x03FF0000) >> 16) != 0x142) && 154962306a36Sopenharmony_ci (((regebc & 0x03FF0000) >> 16) != 0x42)) 155062306a36Sopenharmony_ci result |= 0x01; 155162306a36Sopenharmony_ci else 155262306a36Sopenharmony_ci return result; 155362306a36Sopenharmony_ci if (!(regeac & BIT(30)) && (((regec4 & 0x03FF0000) >> 16) != 0x132) && 155462306a36Sopenharmony_ci (((regecc & 0x03FF0000) >> 16) != 0x36)) 155562306a36Sopenharmony_ci result |= 0x02; 155662306a36Sopenharmony_ci else 155762306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "Path B Rx IQK fail!!\n"); 155862306a36Sopenharmony_ci return result; 155962306a36Sopenharmony_ci} 156062306a36Sopenharmony_ci 156162306a36Sopenharmony_ci/* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */ 156262306a36Sopenharmony_cistatic u8 _rtl92d_phy_pathb_iqk_5g_normal(struct ieee80211_hw *hw) 156362306a36Sopenharmony_ci{ 156462306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 156562306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 156662306a36Sopenharmony_ci u32 regeac, regeb4, regebc, regec4, regecc; 156762306a36Sopenharmony_ci u8 result = 0; 156862306a36Sopenharmony_ci u8 i; 156962306a36Sopenharmony_ci u8 retrycount = 2; 157062306a36Sopenharmony_ci 157162306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "Path B IQK!\n"); 157262306a36Sopenharmony_ci /* path-A IQK setting */ 157362306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "Path-A IQK setting!\n"); 157462306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe30, MASKDWORD, 0x18008c1f); 157562306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe34, MASKDWORD, 0x18008c1f); 157662306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe38, MASKDWORD, 0x82110000); 157762306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe3c, MASKDWORD, 0x68110000); 157862306a36Sopenharmony_ci 157962306a36Sopenharmony_ci /* path-B IQK setting */ 158062306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe50, MASKDWORD, 0x18008c2f); 158162306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe54, MASKDWORD, 0x18008c2f); 158262306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe58, MASKDWORD, 0x82140307); 158362306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe5c, MASKDWORD, 0x68160960); 158462306a36Sopenharmony_ci 158562306a36Sopenharmony_ci /* LO calibration setting */ 158662306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "LO calibration setting!\n"); 158762306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe4c, MASKDWORD, 0x00462911); 158862306a36Sopenharmony_ci 158962306a36Sopenharmony_ci /* path-B PA on */ 159062306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XAB_RFINTERFACESW, MASKDWORD, 0x0f600700); 159162306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XB_RFINTERFACEOE, MASKDWORD, 0x061f0d30); 159262306a36Sopenharmony_ci 159362306a36Sopenharmony_ci for (i = 0; i < retrycount; i++) { 159462306a36Sopenharmony_ci /* One shot, path B LOK & IQK */ 159562306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 159662306a36Sopenharmony_ci "One shot, path A LOK & IQK!\n"); 159762306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe48, MASKDWORD, 0xfa000000); 159862306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe48, MASKDWORD, 0xf8000000); 159962306a36Sopenharmony_ci 160062306a36Sopenharmony_ci /* delay x ms */ 160162306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 160262306a36Sopenharmony_ci "Delay %d ms for One shot, path B LOK & IQK.\n", 10); 160362306a36Sopenharmony_ci mdelay(IQK_DELAY_TIME * 10); 160462306a36Sopenharmony_ci 160562306a36Sopenharmony_ci /* Check failed */ 160662306a36Sopenharmony_ci regeac = rtl_get_bbreg(hw, 0xeac, MASKDWORD); 160762306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "0xeac = 0x%x\n", regeac); 160862306a36Sopenharmony_ci regeb4 = rtl_get_bbreg(hw, 0xeb4, MASKDWORD); 160962306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "0xeb4 = 0x%x\n", regeb4); 161062306a36Sopenharmony_ci regebc = rtl_get_bbreg(hw, 0xebc, MASKDWORD); 161162306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "0xebc = 0x%x\n", regebc); 161262306a36Sopenharmony_ci regec4 = rtl_get_bbreg(hw, 0xec4, MASKDWORD); 161362306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "0xec4 = 0x%x\n", regec4); 161462306a36Sopenharmony_ci regecc = rtl_get_bbreg(hw, 0xecc, MASKDWORD); 161562306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "0xecc = 0x%x\n", regecc); 161662306a36Sopenharmony_ci if (!(regeac & BIT(31)) && 161762306a36Sopenharmony_ci (((regeb4 & 0x03FF0000) >> 16) != 0x142)) 161862306a36Sopenharmony_ci result |= 0x01; 161962306a36Sopenharmony_ci else 162062306a36Sopenharmony_ci continue; 162162306a36Sopenharmony_ci if (!(regeac & BIT(30)) && 162262306a36Sopenharmony_ci (((regec4 & 0x03FF0000) >> 16) != 0x132)) { 162362306a36Sopenharmony_ci result |= 0x02; 162462306a36Sopenharmony_ci break; 162562306a36Sopenharmony_ci } else { 162662306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 162762306a36Sopenharmony_ci "Path B Rx IQK fail!!\n"); 162862306a36Sopenharmony_ci } 162962306a36Sopenharmony_ci } 163062306a36Sopenharmony_ci 163162306a36Sopenharmony_ci /* path B PA off */ 163262306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XAB_RFINTERFACESW, MASKDWORD, 163362306a36Sopenharmony_ci rtlphy->iqk_bb_backup[0]); 163462306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XB_RFINTERFACEOE, MASKDWORD, 163562306a36Sopenharmony_ci rtlphy->iqk_bb_backup[2]); 163662306a36Sopenharmony_ci return result; 163762306a36Sopenharmony_ci} 163862306a36Sopenharmony_ci 163962306a36Sopenharmony_cistatic void _rtl92d_phy_save_adda_registers(struct ieee80211_hw *hw, 164062306a36Sopenharmony_ci u32 *adda_reg, u32 *adda_backup, 164162306a36Sopenharmony_ci u32 regnum) 164262306a36Sopenharmony_ci{ 164362306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 164462306a36Sopenharmony_ci u32 i; 164562306a36Sopenharmony_ci 164662306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "Save ADDA parameters.\n"); 164762306a36Sopenharmony_ci for (i = 0; i < regnum; i++) 164862306a36Sopenharmony_ci adda_backup[i] = rtl_get_bbreg(hw, adda_reg[i], MASKDWORD); 164962306a36Sopenharmony_ci} 165062306a36Sopenharmony_ci 165162306a36Sopenharmony_cistatic void _rtl92d_phy_save_mac_registers(struct ieee80211_hw *hw, 165262306a36Sopenharmony_ci u32 *macreg, u32 *macbackup) 165362306a36Sopenharmony_ci{ 165462306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 165562306a36Sopenharmony_ci u32 i; 165662306a36Sopenharmony_ci 165762306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "Save MAC parameters.\n"); 165862306a36Sopenharmony_ci for (i = 0; i < (IQK_MAC_REG_NUM - 1); i++) 165962306a36Sopenharmony_ci macbackup[i] = rtl_read_byte(rtlpriv, macreg[i]); 166062306a36Sopenharmony_ci macbackup[i] = rtl_read_dword(rtlpriv, macreg[i]); 166162306a36Sopenharmony_ci} 166262306a36Sopenharmony_ci 166362306a36Sopenharmony_cistatic void _rtl92d_phy_reload_adda_registers(struct ieee80211_hw *hw, 166462306a36Sopenharmony_ci u32 *adda_reg, u32 *adda_backup, 166562306a36Sopenharmony_ci u32 regnum) 166662306a36Sopenharmony_ci{ 166762306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 166862306a36Sopenharmony_ci u32 i; 166962306a36Sopenharmony_ci 167062306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 167162306a36Sopenharmony_ci "Reload ADDA power saving parameters !\n"); 167262306a36Sopenharmony_ci for (i = 0; i < regnum; i++) 167362306a36Sopenharmony_ci rtl_set_bbreg(hw, adda_reg[i], MASKDWORD, adda_backup[i]); 167462306a36Sopenharmony_ci} 167562306a36Sopenharmony_ci 167662306a36Sopenharmony_cistatic void _rtl92d_phy_reload_mac_registers(struct ieee80211_hw *hw, 167762306a36Sopenharmony_ci u32 *macreg, u32 *macbackup) 167862306a36Sopenharmony_ci{ 167962306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 168062306a36Sopenharmony_ci u32 i; 168162306a36Sopenharmony_ci 168262306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "Reload MAC parameters !\n"); 168362306a36Sopenharmony_ci for (i = 0; i < (IQK_MAC_REG_NUM - 1); i++) 168462306a36Sopenharmony_ci rtl_write_byte(rtlpriv, macreg[i], (u8) macbackup[i]); 168562306a36Sopenharmony_ci rtl_write_byte(rtlpriv, macreg[i], macbackup[i]); 168662306a36Sopenharmony_ci} 168762306a36Sopenharmony_ci 168862306a36Sopenharmony_cistatic void _rtl92d_phy_path_adda_on(struct ieee80211_hw *hw, 168962306a36Sopenharmony_ci u32 *adda_reg, bool patha_on, bool is2t) 169062306a36Sopenharmony_ci{ 169162306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 169262306a36Sopenharmony_ci u32 pathon; 169362306a36Sopenharmony_ci u32 i; 169462306a36Sopenharmony_ci 169562306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "ADDA ON.\n"); 169662306a36Sopenharmony_ci pathon = patha_on ? 0x04db25a4 : 0x0b1b25a4; 169762306a36Sopenharmony_ci if (patha_on) 169862306a36Sopenharmony_ci pathon = rtlpriv->rtlhal.interfaceindex == 0 ? 169962306a36Sopenharmony_ci 0x04db25a4 : 0x0b1b25a4; 170062306a36Sopenharmony_ci for (i = 0; i < IQK_ADDA_REG_NUM; i++) 170162306a36Sopenharmony_ci rtl_set_bbreg(hw, adda_reg[i], MASKDWORD, pathon); 170262306a36Sopenharmony_ci} 170362306a36Sopenharmony_ci 170462306a36Sopenharmony_cistatic void _rtl92d_phy_mac_setting_calibration(struct ieee80211_hw *hw, 170562306a36Sopenharmony_ci u32 *macreg, u32 *macbackup) 170662306a36Sopenharmony_ci{ 170762306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 170862306a36Sopenharmony_ci u32 i; 170962306a36Sopenharmony_ci 171062306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "MAC settings for Calibration.\n"); 171162306a36Sopenharmony_ci rtl_write_byte(rtlpriv, macreg[0], 0x3F); 171262306a36Sopenharmony_ci 171362306a36Sopenharmony_ci for (i = 1; i < (IQK_MAC_REG_NUM - 1); i++) 171462306a36Sopenharmony_ci rtl_write_byte(rtlpriv, macreg[i], (u8)(macbackup[i] & 171562306a36Sopenharmony_ci (~BIT(3)))); 171662306a36Sopenharmony_ci rtl_write_byte(rtlpriv, macreg[i], (u8) (macbackup[i] & (~BIT(5)))); 171762306a36Sopenharmony_ci} 171862306a36Sopenharmony_ci 171962306a36Sopenharmony_cistatic void _rtl92d_phy_patha_standby(struct ieee80211_hw *hw) 172062306a36Sopenharmony_ci{ 172162306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 172262306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "Path-A standby mode!\n"); 172362306a36Sopenharmony_ci 172462306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe28, MASKDWORD, 0x0); 172562306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XA_LSSIPARAMETER, MASKDWORD, 0x00010000); 172662306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe28, MASKDWORD, 0x80800000); 172762306a36Sopenharmony_ci} 172862306a36Sopenharmony_ci 172962306a36Sopenharmony_cistatic void _rtl92d_phy_pimode_switch(struct ieee80211_hw *hw, bool pi_mode) 173062306a36Sopenharmony_ci{ 173162306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 173262306a36Sopenharmony_ci u32 mode; 173362306a36Sopenharmony_ci 173462306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 173562306a36Sopenharmony_ci "BB Switch to %s mode!\n", pi_mode ? "PI" : "SI"); 173662306a36Sopenharmony_ci mode = pi_mode ? 0x01000100 : 0x01000000; 173762306a36Sopenharmony_ci rtl_set_bbreg(hw, 0x820, MASKDWORD, mode); 173862306a36Sopenharmony_ci rtl_set_bbreg(hw, 0x828, MASKDWORD, mode); 173962306a36Sopenharmony_ci} 174062306a36Sopenharmony_ci 174162306a36Sopenharmony_cistatic void _rtl92d_phy_iq_calibrate(struct ieee80211_hw *hw, long result[][8], 174262306a36Sopenharmony_ci u8 t, bool is2t) 174362306a36Sopenharmony_ci{ 174462306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 174562306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 174662306a36Sopenharmony_ci u32 i; 174762306a36Sopenharmony_ci u8 patha_ok, pathb_ok; 174862306a36Sopenharmony_ci static u32 adda_reg[IQK_ADDA_REG_NUM] = { 174962306a36Sopenharmony_ci RFPGA0_XCD_SWITCHCONTROL, 0xe6c, 0xe70, 0xe74, 175062306a36Sopenharmony_ci 0xe78, 0xe7c, 0xe80, 0xe84, 175162306a36Sopenharmony_ci 0xe88, 0xe8c, 0xed0, 0xed4, 175262306a36Sopenharmony_ci 0xed8, 0xedc, 0xee0, 0xeec 175362306a36Sopenharmony_ci }; 175462306a36Sopenharmony_ci static u32 iqk_mac_reg[IQK_MAC_REG_NUM] = { 175562306a36Sopenharmony_ci 0x522, 0x550, 0x551, 0x040 175662306a36Sopenharmony_ci }; 175762306a36Sopenharmony_ci static u32 iqk_bb_reg[IQK_BB_REG_NUM] = { 175862306a36Sopenharmony_ci RFPGA0_XAB_RFINTERFACESW, RFPGA0_XA_RFINTERFACEOE, 175962306a36Sopenharmony_ci RFPGA0_XB_RFINTERFACEOE, ROFDM0_TRMUXPAR, 176062306a36Sopenharmony_ci RFPGA0_XCD_RFINTERFACESW, ROFDM0_TRXPATHENABLE, 176162306a36Sopenharmony_ci RFPGA0_RFMOD, RFPGA0_ANALOGPARAMETER4, 176262306a36Sopenharmony_ci ROFDM0_XAAGCCORE1, ROFDM0_XBAGCCORE1 176362306a36Sopenharmony_ci }; 176462306a36Sopenharmony_ci const u32 retrycount = 2; 176562306a36Sopenharmony_ci u32 bbvalue; 176662306a36Sopenharmony_ci 176762306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "IQK for 2.4G :Start!!!\n"); 176862306a36Sopenharmony_ci if (t == 0) { 176962306a36Sopenharmony_ci bbvalue = rtl_get_bbreg(hw, RFPGA0_RFMOD, MASKDWORD); 177062306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "==>0x%08x\n", bbvalue); 177162306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "IQ Calibration for %s\n", 177262306a36Sopenharmony_ci is2t ? "2T2R" : "1T1R"); 177362306a36Sopenharmony_ci 177462306a36Sopenharmony_ci /* Save ADDA parameters, turn Path A ADDA on */ 177562306a36Sopenharmony_ci _rtl92d_phy_save_adda_registers(hw, adda_reg, 177662306a36Sopenharmony_ci rtlphy->adda_backup, IQK_ADDA_REG_NUM); 177762306a36Sopenharmony_ci _rtl92d_phy_save_mac_registers(hw, iqk_mac_reg, 177862306a36Sopenharmony_ci rtlphy->iqk_mac_backup); 177962306a36Sopenharmony_ci _rtl92d_phy_save_adda_registers(hw, iqk_bb_reg, 178062306a36Sopenharmony_ci rtlphy->iqk_bb_backup, IQK_BB_REG_NUM); 178162306a36Sopenharmony_ci } 178262306a36Sopenharmony_ci _rtl92d_phy_path_adda_on(hw, adda_reg, true, is2t); 178362306a36Sopenharmony_ci if (t == 0) 178462306a36Sopenharmony_ci rtlphy->rfpi_enable = (u8) rtl_get_bbreg(hw, 178562306a36Sopenharmony_ci RFPGA0_XA_HSSIPARAMETER1, BIT(8)); 178662306a36Sopenharmony_ci 178762306a36Sopenharmony_ci /* Switch BB to PI mode to do IQ Calibration. */ 178862306a36Sopenharmony_ci if (!rtlphy->rfpi_enable) 178962306a36Sopenharmony_ci _rtl92d_phy_pimode_switch(hw, true); 179062306a36Sopenharmony_ci 179162306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_RFMOD, BIT(24), 0x00); 179262306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_TRXPATHENABLE, MASKDWORD, 0x03a05600); 179362306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_TRMUXPAR, MASKDWORD, 0x000800e4); 179462306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XCD_RFINTERFACESW, MASKDWORD, 0x22204000); 179562306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER4, 0xf00000, 0x0f); 179662306a36Sopenharmony_ci if (is2t) { 179762306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XA_LSSIPARAMETER, MASKDWORD, 179862306a36Sopenharmony_ci 0x00010000); 179962306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XB_LSSIPARAMETER, MASKDWORD, 180062306a36Sopenharmony_ci 0x00010000); 180162306a36Sopenharmony_ci } 180262306a36Sopenharmony_ci /* MAC settings */ 180362306a36Sopenharmony_ci _rtl92d_phy_mac_setting_calibration(hw, iqk_mac_reg, 180462306a36Sopenharmony_ci rtlphy->iqk_mac_backup); 180562306a36Sopenharmony_ci /* Page B init */ 180662306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xb68, MASKDWORD, 0x0f600000); 180762306a36Sopenharmony_ci if (is2t) 180862306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xb6c, MASKDWORD, 0x0f600000); 180962306a36Sopenharmony_ci /* IQ calibration setting */ 181062306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "IQK setting!\n"); 181162306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe28, MASKDWORD, 0x80800000); 181262306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe40, MASKDWORD, 0x01007c00); 181362306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe44, MASKDWORD, 0x01004800); 181462306a36Sopenharmony_ci for (i = 0; i < retrycount; i++) { 181562306a36Sopenharmony_ci patha_ok = _rtl92d_phy_patha_iqk(hw, is2t); 181662306a36Sopenharmony_ci if (patha_ok == 0x03) { 181762306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 181862306a36Sopenharmony_ci "Path A IQK Success!!\n"); 181962306a36Sopenharmony_ci result[t][0] = (rtl_get_bbreg(hw, 0xe94, MASKDWORD) & 182062306a36Sopenharmony_ci 0x3FF0000) >> 16; 182162306a36Sopenharmony_ci result[t][1] = (rtl_get_bbreg(hw, 0xe9c, MASKDWORD) & 182262306a36Sopenharmony_ci 0x3FF0000) >> 16; 182362306a36Sopenharmony_ci result[t][2] = (rtl_get_bbreg(hw, 0xea4, MASKDWORD) & 182462306a36Sopenharmony_ci 0x3FF0000) >> 16; 182562306a36Sopenharmony_ci result[t][3] = (rtl_get_bbreg(hw, 0xeac, MASKDWORD) & 182662306a36Sopenharmony_ci 0x3FF0000) >> 16; 182762306a36Sopenharmony_ci break; 182862306a36Sopenharmony_ci } else if (i == (retrycount - 1) && patha_ok == 0x01) { 182962306a36Sopenharmony_ci /* Tx IQK OK */ 183062306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 183162306a36Sopenharmony_ci "Path A IQK Only Tx Success!!\n"); 183262306a36Sopenharmony_ci 183362306a36Sopenharmony_ci result[t][0] = (rtl_get_bbreg(hw, 0xe94, MASKDWORD) & 183462306a36Sopenharmony_ci 0x3FF0000) >> 16; 183562306a36Sopenharmony_ci result[t][1] = (rtl_get_bbreg(hw, 0xe9c, MASKDWORD) & 183662306a36Sopenharmony_ci 0x3FF0000) >> 16; 183762306a36Sopenharmony_ci } 183862306a36Sopenharmony_ci } 183962306a36Sopenharmony_ci if (0x00 == patha_ok) 184062306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "Path A IQK failed!!\n"); 184162306a36Sopenharmony_ci if (is2t) { 184262306a36Sopenharmony_ci _rtl92d_phy_patha_standby(hw); 184362306a36Sopenharmony_ci /* Turn Path B ADDA on */ 184462306a36Sopenharmony_ci _rtl92d_phy_path_adda_on(hw, adda_reg, false, is2t); 184562306a36Sopenharmony_ci for (i = 0; i < retrycount; i++) { 184662306a36Sopenharmony_ci pathb_ok = _rtl92d_phy_pathb_iqk(hw); 184762306a36Sopenharmony_ci if (pathb_ok == 0x03) { 184862306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 184962306a36Sopenharmony_ci "Path B IQK Success!!\n"); 185062306a36Sopenharmony_ci result[t][4] = (rtl_get_bbreg(hw, 0xeb4, 185162306a36Sopenharmony_ci MASKDWORD) & 0x3FF0000) >> 16; 185262306a36Sopenharmony_ci result[t][5] = (rtl_get_bbreg(hw, 0xebc, 185362306a36Sopenharmony_ci MASKDWORD) & 0x3FF0000) >> 16; 185462306a36Sopenharmony_ci result[t][6] = (rtl_get_bbreg(hw, 0xec4, 185562306a36Sopenharmony_ci MASKDWORD) & 0x3FF0000) >> 16; 185662306a36Sopenharmony_ci result[t][7] = (rtl_get_bbreg(hw, 0xecc, 185762306a36Sopenharmony_ci MASKDWORD) & 0x3FF0000) >> 16; 185862306a36Sopenharmony_ci break; 185962306a36Sopenharmony_ci } else if (i == (retrycount - 1) && pathb_ok == 0x01) { 186062306a36Sopenharmony_ci /* Tx IQK OK */ 186162306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 186262306a36Sopenharmony_ci "Path B Only Tx IQK Success!!\n"); 186362306a36Sopenharmony_ci result[t][4] = (rtl_get_bbreg(hw, 0xeb4, 186462306a36Sopenharmony_ci MASKDWORD) & 0x3FF0000) >> 16; 186562306a36Sopenharmony_ci result[t][5] = (rtl_get_bbreg(hw, 0xebc, 186662306a36Sopenharmony_ci MASKDWORD) & 0x3FF0000) >> 16; 186762306a36Sopenharmony_ci } 186862306a36Sopenharmony_ci } 186962306a36Sopenharmony_ci if (0x00 == pathb_ok) 187062306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 187162306a36Sopenharmony_ci "Path B IQK failed!!\n"); 187262306a36Sopenharmony_ci } 187362306a36Sopenharmony_ci 187462306a36Sopenharmony_ci /* Back to BB mode, load original value */ 187562306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 187662306a36Sopenharmony_ci "IQK:Back to BB mode, load original value!\n"); 187762306a36Sopenharmony_ci 187862306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe28, MASKDWORD, 0); 187962306a36Sopenharmony_ci if (t != 0) { 188062306a36Sopenharmony_ci /* Switch back BB to SI mode after finish IQ Calibration. */ 188162306a36Sopenharmony_ci if (!rtlphy->rfpi_enable) 188262306a36Sopenharmony_ci _rtl92d_phy_pimode_switch(hw, false); 188362306a36Sopenharmony_ci /* Reload ADDA power saving parameters */ 188462306a36Sopenharmony_ci _rtl92d_phy_reload_adda_registers(hw, adda_reg, 188562306a36Sopenharmony_ci rtlphy->adda_backup, IQK_ADDA_REG_NUM); 188662306a36Sopenharmony_ci /* Reload MAC parameters */ 188762306a36Sopenharmony_ci _rtl92d_phy_reload_mac_registers(hw, iqk_mac_reg, 188862306a36Sopenharmony_ci rtlphy->iqk_mac_backup); 188962306a36Sopenharmony_ci if (is2t) 189062306a36Sopenharmony_ci _rtl92d_phy_reload_adda_registers(hw, iqk_bb_reg, 189162306a36Sopenharmony_ci rtlphy->iqk_bb_backup, 189262306a36Sopenharmony_ci IQK_BB_REG_NUM); 189362306a36Sopenharmony_ci else 189462306a36Sopenharmony_ci _rtl92d_phy_reload_adda_registers(hw, iqk_bb_reg, 189562306a36Sopenharmony_ci rtlphy->iqk_bb_backup, 189662306a36Sopenharmony_ci IQK_BB_REG_NUM - 1); 189762306a36Sopenharmony_ci /* load 0xe30 IQC default value */ 189862306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe30, MASKDWORD, 0x01008c00); 189962306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe34, MASKDWORD, 0x01008c00); 190062306a36Sopenharmony_ci } 190162306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "<==\n"); 190262306a36Sopenharmony_ci} 190362306a36Sopenharmony_ci 190462306a36Sopenharmony_cistatic void _rtl92d_phy_iq_calibrate_5g_normal(struct ieee80211_hw *hw, 190562306a36Sopenharmony_ci long result[][8], u8 t) 190662306a36Sopenharmony_ci{ 190762306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 190862306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 190962306a36Sopenharmony_ci struct rtl_hal *rtlhal = &(rtlpriv->rtlhal); 191062306a36Sopenharmony_ci u8 patha_ok, pathb_ok; 191162306a36Sopenharmony_ci static u32 adda_reg[IQK_ADDA_REG_NUM] = { 191262306a36Sopenharmony_ci RFPGA0_XCD_SWITCHCONTROL, 0xe6c, 0xe70, 0xe74, 191362306a36Sopenharmony_ci 0xe78, 0xe7c, 0xe80, 0xe84, 191462306a36Sopenharmony_ci 0xe88, 0xe8c, 0xed0, 0xed4, 191562306a36Sopenharmony_ci 0xed8, 0xedc, 0xee0, 0xeec 191662306a36Sopenharmony_ci }; 191762306a36Sopenharmony_ci static u32 iqk_mac_reg[IQK_MAC_REG_NUM] = { 191862306a36Sopenharmony_ci 0x522, 0x550, 0x551, 0x040 191962306a36Sopenharmony_ci }; 192062306a36Sopenharmony_ci static u32 iqk_bb_reg[IQK_BB_REG_NUM] = { 192162306a36Sopenharmony_ci RFPGA0_XAB_RFINTERFACESW, RFPGA0_XA_RFINTERFACEOE, 192262306a36Sopenharmony_ci RFPGA0_XB_RFINTERFACEOE, ROFDM0_TRMUXPAR, 192362306a36Sopenharmony_ci RFPGA0_XCD_RFINTERFACESW, ROFDM0_TRXPATHENABLE, 192462306a36Sopenharmony_ci RFPGA0_RFMOD, RFPGA0_ANALOGPARAMETER4, 192562306a36Sopenharmony_ci ROFDM0_XAAGCCORE1, ROFDM0_XBAGCCORE1 192662306a36Sopenharmony_ci }; 192762306a36Sopenharmony_ci u32 bbvalue; 192862306a36Sopenharmony_ci bool is2t = IS_92D_SINGLEPHY(rtlhal->version); 192962306a36Sopenharmony_ci 193062306a36Sopenharmony_ci /* Note: IQ calibration must be performed after loading 193162306a36Sopenharmony_ci * PHY_REG.txt , and radio_a, radio_b.txt */ 193262306a36Sopenharmony_ci 193362306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "IQK for 5G NORMAL:Start!!!\n"); 193462306a36Sopenharmony_ci mdelay(IQK_DELAY_TIME * 20); 193562306a36Sopenharmony_ci if (t == 0) { 193662306a36Sopenharmony_ci bbvalue = rtl_get_bbreg(hw, RFPGA0_RFMOD, MASKDWORD); 193762306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "==>0x%08x\n", bbvalue); 193862306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "IQ Calibration for %s\n", 193962306a36Sopenharmony_ci is2t ? "2T2R" : "1T1R"); 194062306a36Sopenharmony_ci /* Save ADDA parameters, turn Path A ADDA on */ 194162306a36Sopenharmony_ci _rtl92d_phy_save_adda_registers(hw, adda_reg, 194262306a36Sopenharmony_ci rtlphy->adda_backup, 194362306a36Sopenharmony_ci IQK_ADDA_REG_NUM); 194462306a36Sopenharmony_ci _rtl92d_phy_save_mac_registers(hw, iqk_mac_reg, 194562306a36Sopenharmony_ci rtlphy->iqk_mac_backup); 194662306a36Sopenharmony_ci if (is2t) 194762306a36Sopenharmony_ci _rtl92d_phy_save_adda_registers(hw, iqk_bb_reg, 194862306a36Sopenharmony_ci rtlphy->iqk_bb_backup, 194962306a36Sopenharmony_ci IQK_BB_REG_NUM); 195062306a36Sopenharmony_ci else 195162306a36Sopenharmony_ci _rtl92d_phy_save_adda_registers(hw, iqk_bb_reg, 195262306a36Sopenharmony_ci rtlphy->iqk_bb_backup, 195362306a36Sopenharmony_ci IQK_BB_REG_NUM - 1); 195462306a36Sopenharmony_ci } 195562306a36Sopenharmony_ci _rtl92d_phy_path_adda_on(hw, adda_reg, true, is2t); 195662306a36Sopenharmony_ci /* MAC settings */ 195762306a36Sopenharmony_ci _rtl92d_phy_mac_setting_calibration(hw, iqk_mac_reg, 195862306a36Sopenharmony_ci rtlphy->iqk_mac_backup); 195962306a36Sopenharmony_ci if (t == 0) 196062306a36Sopenharmony_ci rtlphy->rfpi_enable = (u8) rtl_get_bbreg(hw, 196162306a36Sopenharmony_ci RFPGA0_XA_HSSIPARAMETER1, BIT(8)); 196262306a36Sopenharmony_ci /* Switch BB to PI mode to do IQ Calibration. */ 196362306a36Sopenharmony_ci if (!rtlphy->rfpi_enable) 196462306a36Sopenharmony_ci _rtl92d_phy_pimode_switch(hw, true); 196562306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_RFMOD, BIT(24), 0x00); 196662306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_TRXPATHENABLE, MASKDWORD, 0x03a05600); 196762306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_TRMUXPAR, MASKDWORD, 0x000800e4); 196862306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XCD_RFINTERFACESW, MASKDWORD, 0x22208000); 196962306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER4, 0xf00000, 0x0f); 197062306a36Sopenharmony_ci 197162306a36Sopenharmony_ci /* Page B init */ 197262306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xb68, MASKDWORD, 0x0f600000); 197362306a36Sopenharmony_ci if (is2t) 197462306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xb6c, MASKDWORD, 0x0f600000); 197562306a36Sopenharmony_ci /* IQ calibration setting */ 197662306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "IQK setting!\n"); 197762306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe28, MASKDWORD, 0x80800000); 197862306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe40, MASKDWORD, 0x10007c00); 197962306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe44, MASKDWORD, 0x01004800); 198062306a36Sopenharmony_ci patha_ok = _rtl92d_phy_patha_iqk_5g_normal(hw, is2t); 198162306a36Sopenharmony_ci if (patha_ok == 0x03) { 198262306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "Path A IQK Success!!\n"); 198362306a36Sopenharmony_ci result[t][0] = (rtl_get_bbreg(hw, 0xe94, MASKDWORD) & 198462306a36Sopenharmony_ci 0x3FF0000) >> 16; 198562306a36Sopenharmony_ci result[t][1] = (rtl_get_bbreg(hw, 0xe9c, MASKDWORD) & 198662306a36Sopenharmony_ci 0x3FF0000) >> 16; 198762306a36Sopenharmony_ci result[t][2] = (rtl_get_bbreg(hw, 0xea4, MASKDWORD) & 198862306a36Sopenharmony_ci 0x3FF0000) >> 16; 198962306a36Sopenharmony_ci result[t][3] = (rtl_get_bbreg(hw, 0xeac, MASKDWORD) & 199062306a36Sopenharmony_ci 0x3FF0000) >> 16; 199162306a36Sopenharmony_ci } else if (patha_ok == 0x01) { /* Tx IQK OK */ 199262306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 199362306a36Sopenharmony_ci "Path A IQK Only Tx Success!!\n"); 199462306a36Sopenharmony_ci 199562306a36Sopenharmony_ci result[t][0] = (rtl_get_bbreg(hw, 0xe94, MASKDWORD) & 199662306a36Sopenharmony_ci 0x3FF0000) >> 16; 199762306a36Sopenharmony_ci result[t][1] = (rtl_get_bbreg(hw, 0xe9c, MASKDWORD) & 199862306a36Sopenharmony_ci 0x3FF0000) >> 16; 199962306a36Sopenharmony_ci } else { 200062306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "Path A IQK Fail!!\n"); 200162306a36Sopenharmony_ci } 200262306a36Sopenharmony_ci if (is2t) { 200362306a36Sopenharmony_ci /* _rtl92d_phy_patha_standby(hw); */ 200462306a36Sopenharmony_ci /* Turn Path B ADDA on */ 200562306a36Sopenharmony_ci _rtl92d_phy_path_adda_on(hw, adda_reg, false, is2t); 200662306a36Sopenharmony_ci pathb_ok = _rtl92d_phy_pathb_iqk_5g_normal(hw); 200762306a36Sopenharmony_ci if (pathb_ok == 0x03) { 200862306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 200962306a36Sopenharmony_ci "Path B IQK Success!!\n"); 201062306a36Sopenharmony_ci result[t][4] = (rtl_get_bbreg(hw, 0xeb4, MASKDWORD) & 201162306a36Sopenharmony_ci 0x3FF0000) >> 16; 201262306a36Sopenharmony_ci result[t][5] = (rtl_get_bbreg(hw, 0xebc, MASKDWORD) & 201362306a36Sopenharmony_ci 0x3FF0000) >> 16; 201462306a36Sopenharmony_ci result[t][6] = (rtl_get_bbreg(hw, 0xec4, MASKDWORD) & 201562306a36Sopenharmony_ci 0x3FF0000) >> 16; 201662306a36Sopenharmony_ci result[t][7] = (rtl_get_bbreg(hw, 0xecc, MASKDWORD) & 201762306a36Sopenharmony_ci 0x3FF0000) >> 16; 201862306a36Sopenharmony_ci } else if (pathb_ok == 0x01) { /* Tx IQK OK */ 201962306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 202062306a36Sopenharmony_ci "Path B Only Tx IQK Success!!\n"); 202162306a36Sopenharmony_ci result[t][4] = (rtl_get_bbreg(hw, 0xeb4, MASKDWORD) & 202262306a36Sopenharmony_ci 0x3FF0000) >> 16; 202362306a36Sopenharmony_ci result[t][5] = (rtl_get_bbreg(hw, 0xebc, MASKDWORD) & 202462306a36Sopenharmony_ci 0x3FF0000) >> 16; 202562306a36Sopenharmony_ci } else { 202662306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 202762306a36Sopenharmony_ci "Path B IQK failed!!\n"); 202862306a36Sopenharmony_ci } 202962306a36Sopenharmony_ci } 203062306a36Sopenharmony_ci 203162306a36Sopenharmony_ci /* Back to BB mode, load original value */ 203262306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 203362306a36Sopenharmony_ci "IQK:Back to BB mode, load original value!\n"); 203462306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xe28, MASKDWORD, 0); 203562306a36Sopenharmony_ci if (t != 0) { 203662306a36Sopenharmony_ci if (is2t) 203762306a36Sopenharmony_ci _rtl92d_phy_reload_adda_registers(hw, iqk_bb_reg, 203862306a36Sopenharmony_ci rtlphy->iqk_bb_backup, 203962306a36Sopenharmony_ci IQK_BB_REG_NUM); 204062306a36Sopenharmony_ci else 204162306a36Sopenharmony_ci _rtl92d_phy_reload_adda_registers(hw, iqk_bb_reg, 204262306a36Sopenharmony_ci rtlphy->iqk_bb_backup, 204362306a36Sopenharmony_ci IQK_BB_REG_NUM - 1); 204462306a36Sopenharmony_ci /* Reload MAC parameters */ 204562306a36Sopenharmony_ci _rtl92d_phy_reload_mac_registers(hw, iqk_mac_reg, 204662306a36Sopenharmony_ci rtlphy->iqk_mac_backup); 204762306a36Sopenharmony_ci /* Switch back BB to SI mode after finish IQ Calibration. */ 204862306a36Sopenharmony_ci if (!rtlphy->rfpi_enable) 204962306a36Sopenharmony_ci _rtl92d_phy_pimode_switch(hw, false); 205062306a36Sopenharmony_ci /* Reload ADDA power saving parameters */ 205162306a36Sopenharmony_ci _rtl92d_phy_reload_adda_registers(hw, adda_reg, 205262306a36Sopenharmony_ci rtlphy->adda_backup, 205362306a36Sopenharmony_ci IQK_ADDA_REG_NUM); 205462306a36Sopenharmony_ci } 205562306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "<==\n"); 205662306a36Sopenharmony_ci} 205762306a36Sopenharmony_ci 205862306a36Sopenharmony_cistatic bool _rtl92d_phy_simularity_compare(struct ieee80211_hw *hw, 205962306a36Sopenharmony_ci long result[][8], u8 c1, u8 c2) 206062306a36Sopenharmony_ci{ 206162306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 206262306a36Sopenharmony_ci struct rtl_hal *rtlhal = &(rtlpriv->rtlhal); 206362306a36Sopenharmony_ci u32 i, j, diff, sim_bitmap, bound; 206462306a36Sopenharmony_ci u8 final_candidate[2] = {0xFF, 0xFF}; /* for path A and path B */ 206562306a36Sopenharmony_ci bool bresult = true; 206662306a36Sopenharmony_ci bool is2t = IS_92D_SINGLEPHY(rtlhal->version); 206762306a36Sopenharmony_ci 206862306a36Sopenharmony_ci if (is2t) 206962306a36Sopenharmony_ci bound = 8; 207062306a36Sopenharmony_ci else 207162306a36Sopenharmony_ci bound = 4; 207262306a36Sopenharmony_ci sim_bitmap = 0; 207362306a36Sopenharmony_ci for (i = 0; i < bound; i++) { 207462306a36Sopenharmony_ci diff = (result[c1][i] > result[c2][i]) ? (result[c1][i] - 207562306a36Sopenharmony_ci result[c2][i]) : (result[c2][i] - result[c1][i]); 207662306a36Sopenharmony_ci if (diff > MAX_TOLERANCE_92D) { 207762306a36Sopenharmony_ci if ((i == 2 || i == 6) && !sim_bitmap) { 207862306a36Sopenharmony_ci if (result[c1][i] + result[c1][i + 1] == 0) 207962306a36Sopenharmony_ci final_candidate[(i / 4)] = c2; 208062306a36Sopenharmony_ci else if (result[c2][i] + result[c2][i + 1] == 0) 208162306a36Sopenharmony_ci final_candidate[(i / 4)] = c1; 208262306a36Sopenharmony_ci else 208362306a36Sopenharmony_ci sim_bitmap = sim_bitmap | (1 << i); 208462306a36Sopenharmony_ci } else { 208562306a36Sopenharmony_ci sim_bitmap = sim_bitmap | (1 << i); 208662306a36Sopenharmony_ci } 208762306a36Sopenharmony_ci } 208862306a36Sopenharmony_ci } 208962306a36Sopenharmony_ci if (sim_bitmap == 0) { 209062306a36Sopenharmony_ci for (i = 0; i < (bound / 4); i++) { 209162306a36Sopenharmony_ci if (final_candidate[i] != 0xFF) { 209262306a36Sopenharmony_ci for (j = i * 4; j < (i + 1) * 4 - 2; j++) 209362306a36Sopenharmony_ci result[3][j] = 209462306a36Sopenharmony_ci result[final_candidate[i]][j]; 209562306a36Sopenharmony_ci bresult = false; 209662306a36Sopenharmony_ci } 209762306a36Sopenharmony_ci } 209862306a36Sopenharmony_ci return bresult; 209962306a36Sopenharmony_ci } 210062306a36Sopenharmony_ci if (!(sim_bitmap & 0x0F)) { /* path A OK */ 210162306a36Sopenharmony_ci for (i = 0; i < 4; i++) 210262306a36Sopenharmony_ci result[3][i] = result[c1][i]; 210362306a36Sopenharmony_ci } else if (!(sim_bitmap & 0x03)) { /* path A, Tx OK */ 210462306a36Sopenharmony_ci for (i = 0; i < 2; i++) 210562306a36Sopenharmony_ci result[3][i] = result[c1][i]; 210662306a36Sopenharmony_ci } 210762306a36Sopenharmony_ci if (!(sim_bitmap & 0xF0) && is2t) { /* path B OK */ 210862306a36Sopenharmony_ci for (i = 4; i < 8; i++) 210962306a36Sopenharmony_ci result[3][i] = result[c1][i]; 211062306a36Sopenharmony_ci } else if (!(sim_bitmap & 0x30)) { /* path B, Tx OK */ 211162306a36Sopenharmony_ci for (i = 4; i < 6; i++) 211262306a36Sopenharmony_ci result[3][i] = result[c1][i]; 211362306a36Sopenharmony_ci } 211462306a36Sopenharmony_ci return false; 211562306a36Sopenharmony_ci} 211662306a36Sopenharmony_ci 211762306a36Sopenharmony_cistatic void _rtl92d_phy_patha_fill_iqk_matrix(struct ieee80211_hw *hw, 211862306a36Sopenharmony_ci bool iqk_ok, long result[][8], 211962306a36Sopenharmony_ci u8 final_candidate, bool txonly) 212062306a36Sopenharmony_ci{ 212162306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 212262306a36Sopenharmony_ci struct rtl_hal *rtlhal = &(rtlpriv->rtlhal); 212362306a36Sopenharmony_ci u32 oldval_0, val_x, tx0_a, reg; 212462306a36Sopenharmony_ci long val_y, tx0_c; 212562306a36Sopenharmony_ci bool is2t = IS_92D_SINGLEPHY(rtlhal->version) || 212662306a36Sopenharmony_ci rtlhal->macphymode == DUALMAC_DUALPHY; 212762306a36Sopenharmony_ci 212862306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 212962306a36Sopenharmony_ci "Path A IQ Calibration %s !\n", iqk_ok ? "Success" : "Failed"); 213062306a36Sopenharmony_ci if (final_candidate == 0xFF) { 213162306a36Sopenharmony_ci return; 213262306a36Sopenharmony_ci } else if (iqk_ok) { 213362306a36Sopenharmony_ci oldval_0 = (rtl_get_bbreg(hw, ROFDM0_XATXIQIMBALANCE, 213462306a36Sopenharmony_ci MASKDWORD) >> 22) & 0x3FF; /* OFDM0_D */ 213562306a36Sopenharmony_ci val_x = result[final_candidate][0]; 213662306a36Sopenharmony_ci if ((val_x & 0x00000200) != 0) 213762306a36Sopenharmony_ci val_x = val_x | 0xFFFFFC00; 213862306a36Sopenharmony_ci tx0_a = (val_x * oldval_0) >> 8; 213962306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 214062306a36Sopenharmony_ci "X = 0x%x, tx0_a = 0x%x, oldval_0 0x%x\n", 214162306a36Sopenharmony_ci val_x, tx0_a, oldval_0); 214262306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XATXIQIMBALANCE, 0x3FF, tx0_a); 214362306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(24), 214462306a36Sopenharmony_ci ((val_x * oldval_0 >> 7) & 0x1)); 214562306a36Sopenharmony_ci val_y = result[final_candidate][1]; 214662306a36Sopenharmony_ci if ((val_y & 0x00000200) != 0) 214762306a36Sopenharmony_ci val_y = val_y | 0xFFFFFC00; 214862306a36Sopenharmony_ci /* path B IQK result + 3 */ 214962306a36Sopenharmony_ci if (rtlhal->interfaceindex == 1 && 215062306a36Sopenharmony_ci rtlhal->current_bandtype == BAND_ON_5G) 215162306a36Sopenharmony_ci val_y += 3; 215262306a36Sopenharmony_ci tx0_c = (val_y * oldval_0) >> 8; 215362306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 215462306a36Sopenharmony_ci "Y = 0x%lx, tx0_c = 0x%lx\n", 215562306a36Sopenharmony_ci val_y, tx0_c); 215662306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XCTXAFE, 0xF0000000, 215762306a36Sopenharmony_ci ((tx0_c & 0x3C0) >> 6)); 215862306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XATXIQIMBALANCE, 0x003F0000, 215962306a36Sopenharmony_ci (tx0_c & 0x3F)); 216062306a36Sopenharmony_ci if (is2t) 216162306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(26), 216262306a36Sopenharmony_ci ((val_y * oldval_0 >> 7) & 0x1)); 216362306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "0xC80 = 0x%x\n", 216462306a36Sopenharmony_ci rtl_get_bbreg(hw, ROFDM0_XATXIQIMBALANCE, 216562306a36Sopenharmony_ci MASKDWORD)); 216662306a36Sopenharmony_ci if (txonly) { 216762306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "only Tx OK\n"); 216862306a36Sopenharmony_ci return; 216962306a36Sopenharmony_ci } 217062306a36Sopenharmony_ci reg = result[final_candidate][2]; 217162306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XARXIQIMBALANCE, 0x3FF, reg); 217262306a36Sopenharmony_ci reg = result[final_candidate][3] & 0x3F; 217362306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XARXIQIMBALANCE, 0xFC00, reg); 217462306a36Sopenharmony_ci reg = (result[final_candidate][3] >> 6) & 0xF; 217562306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xca0, 0xF0000000, reg); 217662306a36Sopenharmony_ci } 217762306a36Sopenharmony_ci} 217862306a36Sopenharmony_ci 217962306a36Sopenharmony_cistatic void _rtl92d_phy_pathb_fill_iqk_matrix(struct ieee80211_hw *hw, 218062306a36Sopenharmony_ci bool iqk_ok, long result[][8], u8 final_candidate, bool txonly) 218162306a36Sopenharmony_ci{ 218262306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 218362306a36Sopenharmony_ci struct rtl_hal *rtlhal = &(rtlpriv->rtlhal); 218462306a36Sopenharmony_ci u32 oldval_1, val_x, tx1_a, reg; 218562306a36Sopenharmony_ci long val_y, tx1_c; 218662306a36Sopenharmony_ci 218762306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "Path B IQ Calibration %s !\n", 218862306a36Sopenharmony_ci iqk_ok ? "Success" : "Failed"); 218962306a36Sopenharmony_ci if (final_candidate == 0xFF) { 219062306a36Sopenharmony_ci return; 219162306a36Sopenharmony_ci } else if (iqk_ok) { 219262306a36Sopenharmony_ci oldval_1 = (rtl_get_bbreg(hw, ROFDM0_XBTXIQIMBALANCE, 219362306a36Sopenharmony_ci MASKDWORD) >> 22) & 0x3FF; 219462306a36Sopenharmony_ci val_x = result[final_candidate][4]; 219562306a36Sopenharmony_ci if ((val_x & 0x00000200) != 0) 219662306a36Sopenharmony_ci val_x = val_x | 0xFFFFFC00; 219762306a36Sopenharmony_ci tx1_a = (val_x * oldval_1) >> 8; 219862306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "X = 0x%x, tx1_a = 0x%x\n", 219962306a36Sopenharmony_ci val_x, tx1_a); 220062306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XBTXIQIMBALANCE, 0x3FF, tx1_a); 220162306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(28), 220262306a36Sopenharmony_ci ((val_x * oldval_1 >> 7) & 0x1)); 220362306a36Sopenharmony_ci val_y = result[final_candidate][5]; 220462306a36Sopenharmony_ci if ((val_y & 0x00000200) != 0) 220562306a36Sopenharmony_ci val_y = val_y | 0xFFFFFC00; 220662306a36Sopenharmony_ci if (rtlhal->current_bandtype == BAND_ON_5G) 220762306a36Sopenharmony_ci val_y += 3; 220862306a36Sopenharmony_ci tx1_c = (val_y * oldval_1) >> 8; 220962306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "Y = 0x%lx, tx1_c = 0x%lx\n", 221062306a36Sopenharmony_ci val_y, tx1_c); 221162306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XDTXAFE, 0xF0000000, 221262306a36Sopenharmony_ci ((tx1_c & 0x3C0) >> 6)); 221362306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XBTXIQIMBALANCE, 0x003F0000, 221462306a36Sopenharmony_ci (tx1_c & 0x3F)); 221562306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(30), 221662306a36Sopenharmony_ci ((val_y * oldval_1 >> 7) & 0x1)); 221762306a36Sopenharmony_ci if (txonly) 221862306a36Sopenharmony_ci return; 221962306a36Sopenharmony_ci reg = result[final_candidate][6]; 222062306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XBRXIQIMBALANCE, 0x3FF, reg); 222162306a36Sopenharmony_ci reg = result[final_candidate][7] & 0x3F; 222262306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XBRXIQIMBALANCE, 0xFC00, reg); 222362306a36Sopenharmony_ci reg = (result[final_candidate][7] >> 6) & 0xF; 222462306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_AGCRSSITABLE, 0x0000F000, reg); 222562306a36Sopenharmony_ci } 222662306a36Sopenharmony_ci} 222762306a36Sopenharmony_ci 222862306a36Sopenharmony_civoid rtl92d_phy_iq_calibrate(struct ieee80211_hw *hw) 222962306a36Sopenharmony_ci{ 223062306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 223162306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 223262306a36Sopenharmony_ci struct rtl_hal *rtlhal = &(rtlpriv->rtlhal); 223362306a36Sopenharmony_ci long result[4][8]; 223462306a36Sopenharmony_ci u8 i, final_candidate, indexforchannel; 223562306a36Sopenharmony_ci bool patha_ok, pathb_ok; 223662306a36Sopenharmony_ci long rege94, rege9c, regea4, regeac, regeb4; 223762306a36Sopenharmony_ci long regebc, regec4, regecc, regtmp = 0; 223862306a36Sopenharmony_ci bool is12simular, is13simular, is23simular; 223962306a36Sopenharmony_ci unsigned long flag = 0; 224062306a36Sopenharmony_ci 224162306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 224262306a36Sopenharmony_ci "IQK:Start!!!channel %d\n", rtlphy->current_channel); 224362306a36Sopenharmony_ci for (i = 0; i < 8; i++) { 224462306a36Sopenharmony_ci result[0][i] = 0; 224562306a36Sopenharmony_ci result[1][i] = 0; 224662306a36Sopenharmony_ci result[2][i] = 0; 224762306a36Sopenharmony_ci result[3][i] = 0; 224862306a36Sopenharmony_ci } 224962306a36Sopenharmony_ci final_candidate = 0xff; 225062306a36Sopenharmony_ci patha_ok = false; 225162306a36Sopenharmony_ci pathb_ok = false; 225262306a36Sopenharmony_ci is12simular = false; 225362306a36Sopenharmony_ci is23simular = false; 225462306a36Sopenharmony_ci is13simular = false; 225562306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 225662306a36Sopenharmony_ci "IQK !!!currentband %d\n", rtlhal->current_bandtype); 225762306a36Sopenharmony_ci rtl92d_acquire_cckandrw_pagea_ctl(hw, &flag); 225862306a36Sopenharmony_ci for (i = 0; i < 3; i++) { 225962306a36Sopenharmony_ci if (rtlhal->current_bandtype == BAND_ON_5G) { 226062306a36Sopenharmony_ci _rtl92d_phy_iq_calibrate_5g_normal(hw, result, i); 226162306a36Sopenharmony_ci } else if (rtlhal->current_bandtype == BAND_ON_2_4G) { 226262306a36Sopenharmony_ci if (IS_92D_SINGLEPHY(rtlhal->version)) 226362306a36Sopenharmony_ci _rtl92d_phy_iq_calibrate(hw, result, i, true); 226462306a36Sopenharmony_ci else 226562306a36Sopenharmony_ci _rtl92d_phy_iq_calibrate(hw, result, i, false); 226662306a36Sopenharmony_ci } 226762306a36Sopenharmony_ci if (i == 1) { 226862306a36Sopenharmony_ci is12simular = _rtl92d_phy_simularity_compare(hw, result, 226962306a36Sopenharmony_ci 0, 1); 227062306a36Sopenharmony_ci if (is12simular) { 227162306a36Sopenharmony_ci final_candidate = 0; 227262306a36Sopenharmony_ci break; 227362306a36Sopenharmony_ci } 227462306a36Sopenharmony_ci } 227562306a36Sopenharmony_ci if (i == 2) { 227662306a36Sopenharmony_ci is13simular = _rtl92d_phy_simularity_compare(hw, result, 227762306a36Sopenharmony_ci 0, 2); 227862306a36Sopenharmony_ci if (is13simular) { 227962306a36Sopenharmony_ci final_candidate = 0; 228062306a36Sopenharmony_ci break; 228162306a36Sopenharmony_ci } 228262306a36Sopenharmony_ci is23simular = _rtl92d_phy_simularity_compare(hw, result, 228362306a36Sopenharmony_ci 1, 2); 228462306a36Sopenharmony_ci if (is23simular) { 228562306a36Sopenharmony_ci final_candidate = 1; 228662306a36Sopenharmony_ci } else { 228762306a36Sopenharmony_ci for (i = 0; i < 8; i++) 228862306a36Sopenharmony_ci regtmp += result[3][i]; 228962306a36Sopenharmony_ci 229062306a36Sopenharmony_ci if (regtmp != 0) 229162306a36Sopenharmony_ci final_candidate = 3; 229262306a36Sopenharmony_ci else 229362306a36Sopenharmony_ci final_candidate = 0xFF; 229462306a36Sopenharmony_ci } 229562306a36Sopenharmony_ci } 229662306a36Sopenharmony_ci } 229762306a36Sopenharmony_ci rtl92d_release_cckandrw_pagea_ctl(hw, &flag); 229862306a36Sopenharmony_ci for (i = 0; i < 4; i++) { 229962306a36Sopenharmony_ci rege94 = result[i][0]; 230062306a36Sopenharmony_ci rege9c = result[i][1]; 230162306a36Sopenharmony_ci regea4 = result[i][2]; 230262306a36Sopenharmony_ci regeac = result[i][3]; 230362306a36Sopenharmony_ci regeb4 = result[i][4]; 230462306a36Sopenharmony_ci regebc = result[i][5]; 230562306a36Sopenharmony_ci regec4 = result[i][6]; 230662306a36Sopenharmony_ci regecc = result[i][7]; 230762306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 230862306a36Sopenharmony_ci "IQK: rege94=%lx rege9c=%lx regea4=%lx regeac=%lx regeb4=%lx regebc=%lx regec4=%lx regecc=%lx\n", 230962306a36Sopenharmony_ci rege94, rege9c, regea4, regeac, regeb4, regebc, regec4, 231062306a36Sopenharmony_ci regecc); 231162306a36Sopenharmony_ci } 231262306a36Sopenharmony_ci if (final_candidate != 0xff) { 231362306a36Sopenharmony_ci rtlphy->reg_e94 = rege94 = result[final_candidate][0]; 231462306a36Sopenharmony_ci rtlphy->reg_e9c = rege9c = result[final_candidate][1]; 231562306a36Sopenharmony_ci regea4 = result[final_candidate][2]; 231662306a36Sopenharmony_ci regeac = result[final_candidate][3]; 231762306a36Sopenharmony_ci rtlphy->reg_eb4 = regeb4 = result[final_candidate][4]; 231862306a36Sopenharmony_ci rtlphy->reg_ebc = regebc = result[final_candidate][5]; 231962306a36Sopenharmony_ci regec4 = result[final_candidate][6]; 232062306a36Sopenharmony_ci regecc = result[final_candidate][7]; 232162306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 232262306a36Sopenharmony_ci "IQK: final_candidate is %x\n", final_candidate); 232362306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 232462306a36Sopenharmony_ci "IQK: rege94=%lx rege9c=%lx regea4=%lx regeac=%lx regeb4=%lx regebc=%lx regec4=%lx regecc=%lx\n", 232562306a36Sopenharmony_ci rege94, rege9c, regea4, regeac, regeb4, regebc, regec4, 232662306a36Sopenharmony_ci regecc); 232762306a36Sopenharmony_ci patha_ok = pathb_ok = true; 232862306a36Sopenharmony_ci } else { 232962306a36Sopenharmony_ci rtlphy->reg_e94 = rtlphy->reg_eb4 = 0x100; /* X default value */ 233062306a36Sopenharmony_ci rtlphy->reg_e9c = rtlphy->reg_ebc = 0x0; /* Y default value */ 233162306a36Sopenharmony_ci } 233262306a36Sopenharmony_ci if ((rege94 != 0) /*&&(regea4 != 0) */) 233362306a36Sopenharmony_ci _rtl92d_phy_patha_fill_iqk_matrix(hw, patha_ok, result, 233462306a36Sopenharmony_ci final_candidate, (regea4 == 0)); 233562306a36Sopenharmony_ci if (IS_92D_SINGLEPHY(rtlhal->version)) { 233662306a36Sopenharmony_ci if ((regeb4 != 0) /*&&(regec4 != 0) */) 233762306a36Sopenharmony_ci _rtl92d_phy_pathb_fill_iqk_matrix(hw, pathb_ok, result, 233862306a36Sopenharmony_ci final_candidate, (regec4 == 0)); 233962306a36Sopenharmony_ci } 234062306a36Sopenharmony_ci if (final_candidate != 0xFF) { 234162306a36Sopenharmony_ci indexforchannel = rtl92d_get_rightchnlplace_for_iqk( 234262306a36Sopenharmony_ci rtlphy->current_channel); 234362306a36Sopenharmony_ci 234462306a36Sopenharmony_ci for (i = 0; i < IQK_MATRIX_REG_NUM; i++) 234562306a36Sopenharmony_ci rtlphy->iqk_matrix[indexforchannel]. 234662306a36Sopenharmony_ci value[0][i] = result[final_candidate][i]; 234762306a36Sopenharmony_ci rtlphy->iqk_matrix[indexforchannel].iqk_done = 234862306a36Sopenharmony_ci true; 234962306a36Sopenharmony_ci 235062306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_SCAN | COMP_MLME, DBG_LOUD, 235162306a36Sopenharmony_ci "IQK OK indexforchannel %d\n", indexforchannel); 235262306a36Sopenharmony_ci } 235362306a36Sopenharmony_ci} 235462306a36Sopenharmony_ci 235562306a36Sopenharmony_civoid rtl92d_phy_reload_iqk_setting(struct ieee80211_hw *hw, u8 channel) 235662306a36Sopenharmony_ci{ 235762306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 235862306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 235962306a36Sopenharmony_ci struct rtl_hal *rtlhal = &(rtlpriv->rtlhal); 236062306a36Sopenharmony_ci u8 indexforchannel; 236162306a36Sopenharmony_ci 236262306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, "channel %d\n", channel); 236362306a36Sopenharmony_ci /*------Do IQK for normal chip and test chip 5G band------- */ 236462306a36Sopenharmony_ci indexforchannel = rtl92d_get_rightchnlplace_for_iqk(channel); 236562306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, "indexforchannel %d done %d\n", 236662306a36Sopenharmony_ci indexforchannel, 236762306a36Sopenharmony_ci rtlphy->iqk_matrix[indexforchannel].iqk_done); 236862306a36Sopenharmony_ci if (0 && !rtlphy->iqk_matrix[indexforchannel].iqk_done && 236962306a36Sopenharmony_ci rtlphy->need_iqk) { 237062306a36Sopenharmony_ci /* Re Do IQK. */ 237162306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_SCAN | COMP_INIT, DBG_LOUD, 237262306a36Sopenharmony_ci "Do IQK Matrix reg for channel:%d....\n", channel); 237362306a36Sopenharmony_ci rtl92d_phy_iq_calibrate(hw); 237462306a36Sopenharmony_ci } else { 237562306a36Sopenharmony_ci /* Just load the value. */ 237662306a36Sopenharmony_ci /* 2G band just load once. */ 237762306a36Sopenharmony_ci if (((!rtlhal->load_imrandiqk_setting_for2g) && 237862306a36Sopenharmony_ci indexforchannel == 0) || indexforchannel > 0) { 237962306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_SCAN, DBG_LOUD, 238062306a36Sopenharmony_ci "Just Read IQK Matrix reg for channel:%d....\n", 238162306a36Sopenharmony_ci channel); 238262306a36Sopenharmony_ci if (rtlphy->iqk_matrix[indexforchannel].value[0][0] != 0) 238362306a36Sopenharmony_ci _rtl92d_phy_patha_fill_iqk_matrix(hw, true, 238462306a36Sopenharmony_ci rtlphy->iqk_matrix[indexforchannel].value, 0, 238562306a36Sopenharmony_ci rtlphy->iqk_matrix[indexforchannel].value[0][2] == 0); 238662306a36Sopenharmony_ci if (IS_92D_SINGLEPHY(rtlhal->version)) { 238762306a36Sopenharmony_ci if ((rtlphy->iqk_matrix[ 238862306a36Sopenharmony_ci indexforchannel].value[0][4] != 0) 238962306a36Sopenharmony_ci /*&&(regec4 != 0) */) 239062306a36Sopenharmony_ci _rtl92d_phy_pathb_fill_iqk_matrix(hw, 239162306a36Sopenharmony_ci true, 239262306a36Sopenharmony_ci rtlphy->iqk_matrix[ 239362306a36Sopenharmony_ci indexforchannel].value, 0, 239462306a36Sopenharmony_ci (rtlphy->iqk_matrix[ 239562306a36Sopenharmony_ci indexforchannel].value[0][6] 239662306a36Sopenharmony_ci == 0)); 239762306a36Sopenharmony_ci } 239862306a36Sopenharmony_ci } 239962306a36Sopenharmony_ci } 240062306a36Sopenharmony_ci rtlphy->need_iqk = false; 240162306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, "<====\n"); 240262306a36Sopenharmony_ci} 240362306a36Sopenharmony_ci 240462306a36Sopenharmony_cistatic u32 _rtl92d_phy_get_abs(u32 val1, u32 val2) 240562306a36Sopenharmony_ci{ 240662306a36Sopenharmony_ci u32 ret; 240762306a36Sopenharmony_ci 240862306a36Sopenharmony_ci if (val1 >= val2) 240962306a36Sopenharmony_ci ret = val1 - val2; 241062306a36Sopenharmony_ci else 241162306a36Sopenharmony_ci ret = val2 - val1; 241262306a36Sopenharmony_ci return ret; 241362306a36Sopenharmony_ci} 241462306a36Sopenharmony_ci 241562306a36Sopenharmony_cistatic bool _rtl92d_is_legal_5g_channel(struct ieee80211_hw *hw, u8 channel) 241662306a36Sopenharmony_ci{ 241762306a36Sopenharmony_ci 241862306a36Sopenharmony_ci int i; 241962306a36Sopenharmony_ci 242062306a36Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(channel5g); i++) 242162306a36Sopenharmony_ci if (channel == channel5g[i]) 242262306a36Sopenharmony_ci return true; 242362306a36Sopenharmony_ci return false; 242462306a36Sopenharmony_ci} 242562306a36Sopenharmony_ci 242662306a36Sopenharmony_cistatic void _rtl92d_phy_calc_curvindex(struct ieee80211_hw *hw, 242762306a36Sopenharmony_ci u32 *targetchnl, u32 * curvecount_val, 242862306a36Sopenharmony_ci bool is5g, u32 *curveindex) 242962306a36Sopenharmony_ci{ 243062306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 243162306a36Sopenharmony_ci u32 smallest_abs_val = 0xffffffff, u4tmp; 243262306a36Sopenharmony_ci u8 i, j; 243362306a36Sopenharmony_ci u8 chnl_num = is5g ? TARGET_CHNL_NUM_5G : TARGET_CHNL_NUM_2G; 243462306a36Sopenharmony_ci 243562306a36Sopenharmony_ci for (i = 0; i < chnl_num; i++) { 243662306a36Sopenharmony_ci if (is5g && !_rtl92d_is_legal_5g_channel(hw, i + 1)) 243762306a36Sopenharmony_ci continue; 243862306a36Sopenharmony_ci curveindex[i] = 0; 243962306a36Sopenharmony_ci for (j = 0; j < (CV_CURVE_CNT * 2); j++) { 244062306a36Sopenharmony_ci u4tmp = _rtl92d_phy_get_abs(targetchnl[i], 244162306a36Sopenharmony_ci curvecount_val[j]); 244262306a36Sopenharmony_ci 244362306a36Sopenharmony_ci if (u4tmp < smallest_abs_val) { 244462306a36Sopenharmony_ci curveindex[i] = j; 244562306a36Sopenharmony_ci smallest_abs_val = u4tmp; 244662306a36Sopenharmony_ci } 244762306a36Sopenharmony_ci } 244862306a36Sopenharmony_ci smallest_abs_val = 0xffffffff; 244962306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "curveindex[%d] = %x\n", 245062306a36Sopenharmony_ci i, curveindex[i]); 245162306a36Sopenharmony_ci } 245262306a36Sopenharmony_ci} 245362306a36Sopenharmony_ci 245462306a36Sopenharmony_cistatic void _rtl92d_phy_reload_lck_setting(struct ieee80211_hw *hw, 245562306a36Sopenharmony_ci u8 channel) 245662306a36Sopenharmony_ci{ 245762306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 245862306a36Sopenharmony_ci u8 erfpath = rtlpriv->rtlhal.current_bandtype == 245962306a36Sopenharmony_ci BAND_ON_5G ? RF90_PATH_A : 246062306a36Sopenharmony_ci IS_92D_SINGLEPHY(rtlpriv->rtlhal.version) ? 246162306a36Sopenharmony_ci RF90_PATH_B : RF90_PATH_A; 246262306a36Sopenharmony_ci u32 u4tmp = 0, u4regvalue = 0; 246362306a36Sopenharmony_ci bool bneed_powerdown_radio = false; 246462306a36Sopenharmony_ci 246562306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, "path %d\n", erfpath); 246662306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "band type = %d\n", 246762306a36Sopenharmony_ci rtlpriv->rtlhal.current_bandtype); 246862306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "channel = %d\n", channel); 246962306a36Sopenharmony_ci if (rtlpriv->rtlhal.current_bandtype == BAND_ON_5G) {/* Path-A for 5G */ 247062306a36Sopenharmony_ci u4tmp = curveindex_5g[channel-1]; 247162306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 247262306a36Sopenharmony_ci "ver 1 set RF-A, 5G, 0x28 = 0x%x !!\n", u4tmp); 247362306a36Sopenharmony_ci if (rtlpriv->rtlhal.macphymode == DUALMAC_DUALPHY && 247462306a36Sopenharmony_ci rtlpriv->rtlhal.interfaceindex == 1) { 247562306a36Sopenharmony_ci bneed_powerdown_radio = 247662306a36Sopenharmony_ci rtl92d_phy_enable_anotherphy(hw, false); 247762306a36Sopenharmony_ci rtlpriv->rtlhal.during_mac1init_radioa = true; 247862306a36Sopenharmony_ci /* asume no this case */ 247962306a36Sopenharmony_ci if (bneed_powerdown_radio) 248062306a36Sopenharmony_ci _rtl92d_phy_enable_rf_env(hw, erfpath, 248162306a36Sopenharmony_ci &u4regvalue); 248262306a36Sopenharmony_ci } 248362306a36Sopenharmony_ci rtl_set_rfreg(hw, erfpath, RF_SYN_G4, 0x3f800, u4tmp); 248462306a36Sopenharmony_ci if (bneed_powerdown_radio) 248562306a36Sopenharmony_ci _rtl92d_phy_restore_rf_env(hw, erfpath, &u4regvalue); 248662306a36Sopenharmony_ci if (rtlpriv->rtlhal.during_mac1init_radioa) 248762306a36Sopenharmony_ci rtl92d_phy_powerdown_anotherphy(hw, false); 248862306a36Sopenharmony_ci } else if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G) { 248962306a36Sopenharmony_ci u4tmp = curveindex_2g[channel-1]; 249062306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 249162306a36Sopenharmony_ci "ver 3 set RF-B, 2G, 0x28 = 0x%x !!\n", u4tmp); 249262306a36Sopenharmony_ci if (rtlpriv->rtlhal.macphymode == DUALMAC_DUALPHY && 249362306a36Sopenharmony_ci rtlpriv->rtlhal.interfaceindex == 0) { 249462306a36Sopenharmony_ci bneed_powerdown_radio = 249562306a36Sopenharmony_ci rtl92d_phy_enable_anotherphy(hw, true); 249662306a36Sopenharmony_ci rtlpriv->rtlhal.during_mac0init_radiob = true; 249762306a36Sopenharmony_ci if (bneed_powerdown_radio) 249862306a36Sopenharmony_ci _rtl92d_phy_enable_rf_env(hw, erfpath, 249962306a36Sopenharmony_ci &u4regvalue); 250062306a36Sopenharmony_ci } 250162306a36Sopenharmony_ci rtl_set_rfreg(hw, erfpath, RF_SYN_G4, 0x3f800, u4tmp); 250262306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 250362306a36Sopenharmony_ci "ver 3 set RF-B, 2G, 0x28 = 0x%x !!\n", 250462306a36Sopenharmony_ci rtl_get_rfreg(hw, erfpath, RF_SYN_G4, 0x3f800)); 250562306a36Sopenharmony_ci if (bneed_powerdown_radio) 250662306a36Sopenharmony_ci _rtl92d_phy_restore_rf_env(hw, erfpath, &u4regvalue); 250762306a36Sopenharmony_ci if (rtlpriv->rtlhal.during_mac0init_radiob) 250862306a36Sopenharmony_ci rtl92d_phy_powerdown_anotherphy(hw, true); 250962306a36Sopenharmony_ci } 251062306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD, "<====\n"); 251162306a36Sopenharmony_ci} 251262306a36Sopenharmony_ci 251362306a36Sopenharmony_cistatic void _rtl92d_phy_lc_calibrate_sw(struct ieee80211_hw *hw, bool is2t) 251462306a36Sopenharmony_ci{ 251562306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 251662306a36Sopenharmony_ci struct rtl_hal *rtlhal = &(rtlpriv->rtlhal); 251762306a36Sopenharmony_ci struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 251862306a36Sopenharmony_ci u8 tmpreg, index, rf_mode[2]; 251962306a36Sopenharmony_ci u8 path = is2t ? 2 : 1; 252062306a36Sopenharmony_ci u8 i; 252162306a36Sopenharmony_ci u32 u4tmp, offset; 252262306a36Sopenharmony_ci u32 curvecount_val[CV_CURVE_CNT * 2] = {0}; 252362306a36Sopenharmony_ci u16 timeout = 800, timecount = 0; 252462306a36Sopenharmony_ci 252562306a36Sopenharmony_ci /* Check continuous TX and Packet TX */ 252662306a36Sopenharmony_ci tmpreg = rtl_read_byte(rtlpriv, 0xd03); 252762306a36Sopenharmony_ci /* if Deal with contisuous TX case, disable all continuous TX */ 252862306a36Sopenharmony_ci /* if Deal with Packet TX case, block all queues */ 252962306a36Sopenharmony_ci if ((tmpreg & 0x70) != 0) 253062306a36Sopenharmony_ci rtl_write_byte(rtlpriv, 0xd03, tmpreg & 0x8F); 253162306a36Sopenharmony_ci else 253262306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF); 253362306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER4, 0xF00000, 0x0F); 253462306a36Sopenharmony_ci for (index = 0; index < path; index++) { 253562306a36Sopenharmony_ci /* 1. Read original RF mode */ 253662306a36Sopenharmony_ci offset = index == 0 ? ROFDM0_XAAGCCORE1 : ROFDM0_XBAGCCORE1; 253762306a36Sopenharmony_ci rf_mode[index] = rtl_read_byte(rtlpriv, offset); 253862306a36Sopenharmony_ci /* 2. Set RF mode = standby mode */ 253962306a36Sopenharmony_ci rtl_set_rfreg(hw, (enum radio_path)index, RF_AC, 254062306a36Sopenharmony_ci RFREG_OFFSET_MASK, 0x010000); 254162306a36Sopenharmony_ci if (rtlpci->init_ready) { 254262306a36Sopenharmony_ci /* switch CV-curve control by LC-calibration */ 254362306a36Sopenharmony_ci rtl_set_rfreg(hw, (enum radio_path)index, RF_SYN_G7, 254462306a36Sopenharmony_ci BIT(17), 0x0); 254562306a36Sopenharmony_ci /* 4. Set LC calibration begin */ 254662306a36Sopenharmony_ci rtl_set_rfreg(hw, (enum radio_path)index, RF_CHNLBW, 254762306a36Sopenharmony_ci 0x08000, 0x01); 254862306a36Sopenharmony_ci } 254962306a36Sopenharmony_ci u4tmp = rtl_get_rfreg(hw, (enum radio_path)index, RF_SYN_G6, 255062306a36Sopenharmony_ci RFREG_OFFSET_MASK); 255162306a36Sopenharmony_ci while ((!(u4tmp & BIT(11))) && timecount <= timeout) { 255262306a36Sopenharmony_ci mdelay(50); 255362306a36Sopenharmony_ci timecount += 50; 255462306a36Sopenharmony_ci u4tmp = rtl_get_rfreg(hw, (enum radio_path)index, 255562306a36Sopenharmony_ci RF_SYN_G6, RFREG_OFFSET_MASK); 255662306a36Sopenharmony_ci } 255762306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 255862306a36Sopenharmony_ci "PHY_LCK finish delay for %d ms=2\n", timecount); 255962306a36Sopenharmony_ci rtl_get_rfreg(hw, index, RF_SYN_G4, RFREG_OFFSET_MASK); 256062306a36Sopenharmony_ci if (index == 0 && rtlhal->interfaceindex == 0) { 256162306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 256262306a36Sopenharmony_ci "path-A / 5G LCK\n"); 256362306a36Sopenharmony_ci } else { 256462306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 256562306a36Sopenharmony_ci "path-B / 2.4G LCK\n"); 256662306a36Sopenharmony_ci } 256762306a36Sopenharmony_ci memset(curvecount_val, 0, sizeof(curvecount_val)); 256862306a36Sopenharmony_ci /* Set LC calibration off */ 256962306a36Sopenharmony_ci rtl_set_rfreg(hw, (enum radio_path)index, RF_CHNLBW, 257062306a36Sopenharmony_ci 0x08000, 0x0); 257162306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "set RF 0x18[15] = 0\n"); 257262306a36Sopenharmony_ci /* save Curve-counting number */ 257362306a36Sopenharmony_ci for (i = 0; i < CV_CURVE_CNT; i++) { 257462306a36Sopenharmony_ci u32 readval = 0, readval2 = 0; 257562306a36Sopenharmony_ci rtl_set_rfreg(hw, (enum radio_path)index, 0x3F, 257662306a36Sopenharmony_ci 0x7f, i); 257762306a36Sopenharmony_ci 257862306a36Sopenharmony_ci rtl_set_rfreg(hw, (enum radio_path)index, 0x4D, 257962306a36Sopenharmony_ci RFREG_OFFSET_MASK, 0x0); 258062306a36Sopenharmony_ci readval = rtl_get_rfreg(hw, (enum radio_path)index, 258162306a36Sopenharmony_ci 0x4F, RFREG_OFFSET_MASK); 258262306a36Sopenharmony_ci curvecount_val[2 * i + 1] = (readval & 0xfffe0) >> 5; 258362306a36Sopenharmony_ci /* reg 0x4f [4:0] */ 258462306a36Sopenharmony_ci /* reg 0x50 [19:10] */ 258562306a36Sopenharmony_ci readval2 = rtl_get_rfreg(hw, (enum radio_path)index, 258662306a36Sopenharmony_ci 0x50, 0xffc00); 258762306a36Sopenharmony_ci curvecount_val[2 * i] = (((readval & 0x1F) << 10) | 258862306a36Sopenharmony_ci readval2); 258962306a36Sopenharmony_ci } 259062306a36Sopenharmony_ci if (index == 0 && rtlhal->interfaceindex == 0) 259162306a36Sopenharmony_ci _rtl92d_phy_calc_curvindex(hw, targetchnl_5g, 259262306a36Sopenharmony_ci curvecount_val, 259362306a36Sopenharmony_ci true, curveindex_5g); 259462306a36Sopenharmony_ci else 259562306a36Sopenharmony_ci _rtl92d_phy_calc_curvindex(hw, targetchnl_2g, 259662306a36Sopenharmony_ci curvecount_val, 259762306a36Sopenharmony_ci false, curveindex_2g); 259862306a36Sopenharmony_ci /* switch CV-curve control mode */ 259962306a36Sopenharmony_ci rtl_set_rfreg(hw, (enum radio_path)index, RF_SYN_G7, 260062306a36Sopenharmony_ci BIT(17), 0x1); 260162306a36Sopenharmony_ci } 260262306a36Sopenharmony_ci 260362306a36Sopenharmony_ci /* Restore original situation */ 260462306a36Sopenharmony_ci for (index = 0; index < path; index++) { 260562306a36Sopenharmony_ci offset = index == 0 ? ROFDM0_XAAGCCORE1 : ROFDM0_XBAGCCORE1; 260662306a36Sopenharmony_ci rtl_write_byte(rtlpriv, offset, 0x50); 260762306a36Sopenharmony_ci rtl_write_byte(rtlpriv, offset, rf_mode[index]); 260862306a36Sopenharmony_ci } 260962306a36Sopenharmony_ci if ((tmpreg & 0x70) != 0) 261062306a36Sopenharmony_ci rtl_write_byte(rtlpriv, 0xd03, tmpreg); 261162306a36Sopenharmony_ci else /*Deal with Packet TX case */ 261262306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_TXPAUSE, 0x00); 261362306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER4, 0xF00000, 0x00); 261462306a36Sopenharmony_ci _rtl92d_phy_reload_lck_setting(hw, rtlpriv->phy.current_channel); 261562306a36Sopenharmony_ci} 261662306a36Sopenharmony_ci 261762306a36Sopenharmony_cistatic void _rtl92d_phy_lc_calibrate(struct ieee80211_hw *hw, bool is2t) 261862306a36Sopenharmony_ci{ 261962306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 262062306a36Sopenharmony_ci 262162306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "cosa PHY_LCK ver=2\n"); 262262306a36Sopenharmony_ci _rtl92d_phy_lc_calibrate_sw(hw, is2t); 262362306a36Sopenharmony_ci} 262462306a36Sopenharmony_ci 262562306a36Sopenharmony_civoid rtl92d_phy_lc_calibrate(struct ieee80211_hw *hw) 262662306a36Sopenharmony_ci{ 262762306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 262862306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 262962306a36Sopenharmony_ci struct rtl_hal *rtlhal = &(rtlpriv->rtlhal); 263062306a36Sopenharmony_ci u32 timeout = 2000, timecount = 0; 263162306a36Sopenharmony_ci 263262306a36Sopenharmony_ci while (rtlpriv->mac80211.act_scanning && timecount < timeout) { 263362306a36Sopenharmony_ci udelay(50); 263462306a36Sopenharmony_ci timecount += 50; 263562306a36Sopenharmony_ci } 263662306a36Sopenharmony_ci 263762306a36Sopenharmony_ci rtlphy->lck_inprogress = true; 263862306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, 263962306a36Sopenharmony_ci "LCK:Start!!! currentband %x delay %d ms\n", 264062306a36Sopenharmony_ci rtlhal->current_bandtype, timecount); 264162306a36Sopenharmony_ci if (IS_92D_SINGLEPHY(rtlhal->version)) { 264262306a36Sopenharmony_ci _rtl92d_phy_lc_calibrate(hw, true); 264362306a36Sopenharmony_ci } else { 264462306a36Sopenharmony_ci /* For 1T1R */ 264562306a36Sopenharmony_ci _rtl92d_phy_lc_calibrate(hw, false); 264662306a36Sopenharmony_ci } 264762306a36Sopenharmony_ci rtlphy->lck_inprogress = false; 264862306a36Sopenharmony_ci RTPRINT(rtlpriv, FINIT, INIT_IQK, "LCK:Finish!!!\n"); 264962306a36Sopenharmony_ci} 265062306a36Sopenharmony_ci 265162306a36Sopenharmony_civoid rtl92d_phy_ap_calibrate(struct ieee80211_hw *hw, s8 delta) 265262306a36Sopenharmony_ci{ 265362306a36Sopenharmony_ci return; 265462306a36Sopenharmony_ci} 265562306a36Sopenharmony_ci 265662306a36Sopenharmony_cistatic bool _rtl92d_phy_set_sw_chnl_cmdarray(struct swchnlcmd *cmdtable, 265762306a36Sopenharmony_ci u32 cmdtableidx, u32 cmdtablesz, enum swchnlcmd_id cmdid, 265862306a36Sopenharmony_ci u32 para1, u32 para2, u32 msdelay) 265962306a36Sopenharmony_ci{ 266062306a36Sopenharmony_ci struct swchnlcmd *pcmd; 266162306a36Sopenharmony_ci 266262306a36Sopenharmony_ci if (cmdtable == NULL) { 266362306a36Sopenharmony_ci WARN_ONCE(true, "rtl8192de: cmdtable cannot be NULL\n"); 266462306a36Sopenharmony_ci return false; 266562306a36Sopenharmony_ci } 266662306a36Sopenharmony_ci if (cmdtableidx >= cmdtablesz) 266762306a36Sopenharmony_ci return false; 266862306a36Sopenharmony_ci 266962306a36Sopenharmony_ci pcmd = cmdtable + cmdtableidx; 267062306a36Sopenharmony_ci pcmd->cmdid = cmdid; 267162306a36Sopenharmony_ci pcmd->para1 = para1; 267262306a36Sopenharmony_ci pcmd->para2 = para2; 267362306a36Sopenharmony_ci pcmd->msdelay = msdelay; 267462306a36Sopenharmony_ci return true; 267562306a36Sopenharmony_ci} 267662306a36Sopenharmony_ci 267762306a36Sopenharmony_civoid rtl92d_phy_reset_iqk_result(struct ieee80211_hw *hw) 267862306a36Sopenharmony_ci{ 267962306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 268062306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 268162306a36Sopenharmony_ci u8 i; 268262306a36Sopenharmony_ci 268362306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, 268462306a36Sopenharmony_ci "settings regs %zu default regs %d\n", 268562306a36Sopenharmony_ci ARRAY_SIZE(rtlphy->iqk_matrix), 268662306a36Sopenharmony_ci IQK_MATRIX_REG_NUM); 268762306a36Sopenharmony_ci /* 0xe94, 0xe9c, 0xea4, 0xeac, 0xeb4, 0xebc, 0xec4, 0xecc */ 268862306a36Sopenharmony_ci for (i = 0; i < IQK_MATRIX_SETTINGS_NUM; i++) { 268962306a36Sopenharmony_ci rtlphy->iqk_matrix[i].value[0][0] = 0x100; 269062306a36Sopenharmony_ci rtlphy->iqk_matrix[i].value[0][2] = 0x100; 269162306a36Sopenharmony_ci rtlphy->iqk_matrix[i].value[0][4] = 0x100; 269262306a36Sopenharmony_ci rtlphy->iqk_matrix[i].value[0][6] = 0x100; 269362306a36Sopenharmony_ci rtlphy->iqk_matrix[i].value[0][1] = 0x0; 269462306a36Sopenharmony_ci rtlphy->iqk_matrix[i].value[0][3] = 0x0; 269562306a36Sopenharmony_ci rtlphy->iqk_matrix[i].value[0][5] = 0x0; 269662306a36Sopenharmony_ci rtlphy->iqk_matrix[i].value[0][7] = 0x0; 269762306a36Sopenharmony_ci rtlphy->iqk_matrix[i].iqk_done = false; 269862306a36Sopenharmony_ci } 269962306a36Sopenharmony_ci} 270062306a36Sopenharmony_ci 270162306a36Sopenharmony_cistatic bool _rtl92d_phy_sw_chnl_step_by_step(struct ieee80211_hw *hw, 270262306a36Sopenharmony_ci u8 channel, u8 *stage, u8 *step, 270362306a36Sopenharmony_ci u32 *delay) 270462306a36Sopenharmony_ci{ 270562306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 270662306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 270762306a36Sopenharmony_ci struct swchnlcmd precommoncmd[MAX_PRECMD_CNT]; 270862306a36Sopenharmony_ci u32 precommoncmdcnt; 270962306a36Sopenharmony_ci struct swchnlcmd postcommoncmd[MAX_POSTCMD_CNT]; 271062306a36Sopenharmony_ci u32 postcommoncmdcnt; 271162306a36Sopenharmony_ci struct swchnlcmd rfdependcmd[MAX_RFDEPENDCMD_CNT]; 271262306a36Sopenharmony_ci u32 rfdependcmdcnt; 271362306a36Sopenharmony_ci struct swchnlcmd *currentcmd = NULL; 271462306a36Sopenharmony_ci u8 rfpath; 271562306a36Sopenharmony_ci u8 num_total_rfpath = rtlphy->num_total_rfpath; 271662306a36Sopenharmony_ci 271762306a36Sopenharmony_ci precommoncmdcnt = 0; 271862306a36Sopenharmony_ci _rtl92d_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++, 271962306a36Sopenharmony_ci MAX_PRECMD_CNT, 272062306a36Sopenharmony_ci CMDID_SET_TXPOWEROWER_LEVEL, 0, 0, 0); 272162306a36Sopenharmony_ci _rtl92d_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++, 272262306a36Sopenharmony_ci MAX_PRECMD_CNT, CMDID_END, 0, 0, 0); 272362306a36Sopenharmony_ci postcommoncmdcnt = 0; 272462306a36Sopenharmony_ci _rtl92d_phy_set_sw_chnl_cmdarray(postcommoncmd, postcommoncmdcnt++, 272562306a36Sopenharmony_ci MAX_POSTCMD_CNT, CMDID_END, 0, 0, 0); 272662306a36Sopenharmony_ci rfdependcmdcnt = 0; 272762306a36Sopenharmony_ci _rtl92d_phy_set_sw_chnl_cmdarray(rfdependcmd, rfdependcmdcnt++, 272862306a36Sopenharmony_ci MAX_RFDEPENDCMD_CNT, CMDID_RF_WRITEREG, 272962306a36Sopenharmony_ci RF_CHNLBW, channel, 0); 273062306a36Sopenharmony_ci _rtl92d_phy_set_sw_chnl_cmdarray(rfdependcmd, rfdependcmdcnt++, 273162306a36Sopenharmony_ci MAX_RFDEPENDCMD_CNT, CMDID_END, 273262306a36Sopenharmony_ci 0, 0, 0); 273362306a36Sopenharmony_ci 273462306a36Sopenharmony_ci do { 273562306a36Sopenharmony_ci switch (*stage) { 273662306a36Sopenharmony_ci case 0: 273762306a36Sopenharmony_ci currentcmd = &precommoncmd[*step]; 273862306a36Sopenharmony_ci break; 273962306a36Sopenharmony_ci case 1: 274062306a36Sopenharmony_ci currentcmd = &rfdependcmd[*step]; 274162306a36Sopenharmony_ci break; 274262306a36Sopenharmony_ci case 2: 274362306a36Sopenharmony_ci currentcmd = &postcommoncmd[*step]; 274462306a36Sopenharmony_ci break; 274562306a36Sopenharmony_ci } 274662306a36Sopenharmony_ci if (currentcmd->cmdid == CMDID_END) { 274762306a36Sopenharmony_ci if ((*stage) == 2) { 274862306a36Sopenharmony_ci return true; 274962306a36Sopenharmony_ci } else { 275062306a36Sopenharmony_ci (*stage)++; 275162306a36Sopenharmony_ci (*step) = 0; 275262306a36Sopenharmony_ci continue; 275362306a36Sopenharmony_ci } 275462306a36Sopenharmony_ci } 275562306a36Sopenharmony_ci switch (currentcmd->cmdid) { 275662306a36Sopenharmony_ci case CMDID_SET_TXPOWEROWER_LEVEL: 275762306a36Sopenharmony_ci rtl92d_phy_set_txpower_level(hw, channel); 275862306a36Sopenharmony_ci break; 275962306a36Sopenharmony_ci case CMDID_WRITEPORT_ULONG: 276062306a36Sopenharmony_ci rtl_write_dword(rtlpriv, currentcmd->para1, 276162306a36Sopenharmony_ci currentcmd->para2); 276262306a36Sopenharmony_ci break; 276362306a36Sopenharmony_ci case CMDID_WRITEPORT_USHORT: 276462306a36Sopenharmony_ci rtl_write_word(rtlpriv, currentcmd->para1, 276562306a36Sopenharmony_ci (u16)currentcmd->para2); 276662306a36Sopenharmony_ci break; 276762306a36Sopenharmony_ci case CMDID_WRITEPORT_UCHAR: 276862306a36Sopenharmony_ci rtl_write_byte(rtlpriv, currentcmd->para1, 276962306a36Sopenharmony_ci (u8)currentcmd->para2); 277062306a36Sopenharmony_ci break; 277162306a36Sopenharmony_ci case CMDID_RF_WRITEREG: 277262306a36Sopenharmony_ci for (rfpath = 0; rfpath < num_total_rfpath; rfpath++) { 277362306a36Sopenharmony_ci rtlphy->rfreg_chnlval[rfpath] = 277462306a36Sopenharmony_ci ((rtlphy->rfreg_chnlval[rfpath] & 277562306a36Sopenharmony_ci 0xffffff00) | currentcmd->para2); 277662306a36Sopenharmony_ci if (rtlpriv->rtlhal.current_bandtype == 277762306a36Sopenharmony_ci BAND_ON_5G) { 277862306a36Sopenharmony_ci if (currentcmd->para2 > 99) 277962306a36Sopenharmony_ci rtlphy->rfreg_chnlval[rfpath] = 278062306a36Sopenharmony_ci rtlphy->rfreg_chnlval 278162306a36Sopenharmony_ci [rfpath] | (BIT(18)); 278262306a36Sopenharmony_ci else 278362306a36Sopenharmony_ci rtlphy->rfreg_chnlval[rfpath] = 278462306a36Sopenharmony_ci rtlphy->rfreg_chnlval 278562306a36Sopenharmony_ci [rfpath] & (~BIT(18)); 278662306a36Sopenharmony_ci rtlphy->rfreg_chnlval[rfpath] |= 278762306a36Sopenharmony_ci (BIT(16) | BIT(8)); 278862306a36Sopenharmony_ci } else { 278962306a36Sopenharmony_ci rtlphy->rfreg_chnlval[rfpath] &= 279062306a36Sopenharmony_ci ~(BIT(8) | BIT(16) | BIT(18)); 279162306a36Sopenharmony_ci } 279262306a36Sopenharmony_ci rtl_set_rfreg(hw, (enum radio_path)rfpath, 279362306a36Sopenharmony_ci currentcmd->para1, 279462306a36Sopenharmony_ci RFREG_OFFSET_MASK, 279562306a36Sopenharmony_ci rtlphy->rfreg_chnlval[rfpath]); 279662306a36Sopenharmony_ci _rtl92d_phy_reload_imr_setting(hw, channel, 279762306a36Sopenharmony_ci rfpath); 279862306a36Sopenharmony_ci } 279962306a36Sopenharmony_ci _rtl92d_phy_switch_rf_setting(hw, channel); 280062306a36Sopenharmony_ci /* do IQK when all parameters are ready */ 280162306a36Sopenharmony_ci rtl92d_phy_reload_iqk_setting(hw, channel); 280262306a36Sopenharmony_ci break; 280362306a36Sopenharmony_ci default: 280462306a36Sopenharmony_ci pr_err("switch case %#x not processed\n", 280562306a36Sopenharmony_ci currentcmd->cmdid); 280662306a36Sopenharmony_ci break; 280762306a36Sopenharmony_ci } 280862306a36Sopenharmony_ci break; 280962306a36Sopenharmony_ci } while (true); 281062306a36Sopenharmony_ci (*delay) = currentcmd->msdelay; 281162306a36Sopenharmony_ci (*step)++; 281262306a36Sopenharmony_ci return false; 281362306a36Sopenharmony_ci} 281462306a36Sopenharmony_ci 281562306a36Sopenharmony_ciu8 rtl92d_phy_sw_chnl(struct ieee80211_hw *hw) 281662306a36Sopenharmony_ci{ 281762306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 281862306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 281962306a36Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 282062306a36Sopenharmony_ci u32 delay; 282162306a36Sopenharmony_ci u32 timeout = 1000, timecount = 0; 282262306a36Sopenharmony_ci u8 channel = rtlphy->current_channel; 282362306a36Sopenharmony_ci u32 ret_value; 282462306a36Sopenharmony_ci 282562306a36Sopenharmony_ci if (rtlphy->sw_chnl_inprogress) 282662306a36Sopenharmony_ci return 0; 282762306a36Sopenharmony_ci if (rtlphy->set_bwmode_inprogress) 282862306a36Sopenharmony_ci return 0; 282962306a36Sopenharmony_ci 283062306a36Sopenharmony_ci if ((is_hal_stop(rtlhal)) || (RT_CANNOT_IO(hw))) { 283162306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CHAN, DBG_LOUD, 283262306a36Sopenharmony_ci "sw_chnl_inprogress false driver sleep or unload\n"); 283362306a36Sopenharmony_ci return 0; 283462306a36Sopenharmony_ci } 283562306a36Sopenharmony_ci while (rtlphy->lck_inprogress && timecount < timeout) { 283662306a36Sopenharmony_ci mdelay(50); 283762306a36Sopenharmony_ci timecount += 50; 283862306a36Sopenharmony_ci } 283962306a36Sopenharmony_ci if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY && 284062306a36Sopenharmony_ci rtlhal->bandset == BAND_ON_BOTH) { 284162306a36Sopenharmony_ci ret_value = rtl_get_bbreg(hw, RFPGA0_XAB_RFPARAMETER, 284262306a36Sopenharmony_ci MASKDWORD); 284362306a36Sopenharmony_ci if (rtlphy->current_channel > 14 && !(ret_value & BIT(0))) 284462306a36Sopenharmony_ci rtl92d_phy_switch_wirelessband(hw, BAND_ON_5G); 284562306a36Sopenharmony_ci else if (rtlphy->current_channel <= 14 && (ret_value & BIT(0))) 284662306a36Sopenharmony_ci rtl92d_phy_switch_wirelessband(hw, BAND_ON_2_4G); 284762306a36Sopenharmony_ci } 284862306a36Sopenharmony_ci switch (rtlhal->current_bandtype) { 284962306a36Sopenharmony_ci case BAND_ON_5G: 285062306a36Sopenharmony_ci /* Get first channel error when change between 285162306a36Sopenharmony_ci * 5G and 2.4G band. */ 285262306a36Sopenharmony_ci if (WARN_ONCE(channel <= 14, "rtl8192de: 5G but channel<=14\n")) 285362306a36Sopenharmony_ci return 0; 285462306a36Sopenharmony_ci break; 285562306a36Sopenharmony_ci case BAND_ON_2_4G: 285662306a36Sopenharmony_ci /* Get first channel error when change between 285762306a36Sopenharmony_ci * 5G and 2.4G band. */ 285862306a36Sopenharmony_ci if (WARN_ONCE(channel > 14, "rtl8192de: 2G but channel>14\n")) 285962306a36Sopenharmony_ci return 0; 286062306a36Sopenharmony_ci break; 286162306a36Sopenharmony_ci default: 286262306a36Sopenharmony_ci WARN_ONCE(true, "rtl8192de: Invalid WirelessMode(%#x)!!\n", 286362306a36Sopenharmony_ci rtlpriv->mac80211.mode); 286462306a36Sopenharmony_ci break; 286562306a36Sopenharmony_ci } 286662306a36Sopenharmony_ci rtlphy->sw_chnl_inprogress = true; 286762306a36Sopenharmony_ci if (channel == 0) 286862306a36Sopenharmony_ci channel = 1; 286962306a36Sopenharmony_ci rtlphy->sw_chnl_stage = 0; 287062306a36Sopenharmony_ci rtlphy->sw_chnl_step = 0; 287162306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_SCAN, DBG_TRACE, 287262306a36Sopenharmony_ci "switch to channel%d\n", rtlphy->current_channel); 287362306a36Sopenharmony_ci 287462306a36Sopenharmony_ci do { 287562306a36Sopenharmony_ci if (!rtlphy->sw_chnl_inprogress) 287662306a36Sopenharmony_ci break; 287762306a36Sopenharmony_ci if (!_rtl92d_phy_sw_chnl_step_by_step(hw, 287862306a36Sopenharmony_ci rtlphy->current_channel, 287962306a36Sopenharmony_ci &rtlphy->sw_chnl_stage, &rtlphy->sw_chnl_step, &delay)) { 288062306a36Sopenharmony_ci if (delay > 0) 288162306a36Sopenharmony_ci mdelay(delay); 288262306a36Sopenharmony_ci else 288362306a36Sopenharmony_ci continue; 288462306a36Sopenharmony_ci } else { 288562306a36Sopenharmony_ci rtlphy->sw_chnl_inprogress = false; 288662306a36Sopenharmony_ci } 288762306a36Sopenharmony_ci break; 288862306a36Sopenharmony_ci } while (true); 288962306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_SCAN, DBG_TRACE, "<==\n"); 289062306a36Sopenharmony_ci rtlphy->sw_chnl_inprogress = false; 289162306a36Sopenharmony_ci return 1; 289262306a36Sopenharmony_ci} 289362306a36Sopenharmony_ci 289462306a36Sopenharmony_cistatic void rtl92d_phy_set_io(struct ieee80211_hw *hw) 289562306a36Sopenharmony_ci{ 289662306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 289762306a36Sopenharmony_ci struct dig_t *de_digtable = &rtlpriv->dm_digtable; 289862306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 289962306a36Sopenharmony_ci 290062306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE, 290162306a36Sopenharmony_ci "--->Cmd(%#x), set_io_inprogress(%d)\n", 290262306a36Sopenharmony_ci rtlphy->current_io_type, rtlphy->set_io_inprogress); 290362306a36Sopenharmony_ci switch (rtlphy->current_io_type) { 290462306a36Sopenharmony_ci case IO_CMD_RESUME_DM_BY_SCAN: 290562306a36Sopenharmony_ci de_digtable->cur_igvalue = rtlphy->initgain_backup.xaagccore1; 290662306a36Sopenharmony_ci rtl92d_dm_write_dig(hw); 290762306a36Sopenharmony_ci rtl92d_phy_set_txpower_level(hw, rtlphy->current_channel); 290862306a36Sopenharmony_ci break; 290962306a36Sopenharmony_ci case IO_CMD_PAUSE_DM_BY_SCAN: 291062306a36Sopenharmony_ci rtlphy->initgain_backup.xaagccore1 = de_digtable->cur_igvalue; 291162306a36Sopenharmony_ci de_digtable->cur_igvalue = 0x37; 291262306a36Sopenharmony_ci rtl92d_dm_write_dig(hw); 291362306a36Sopenharmony_ci break; 291462306a36Sopenharmony_ci default: 291562306a36Sopenharmony_ci pr_err("switch case %#x not processed\n", 291662306a36Sopenharmony_ci rtlphy->current_io_type); 291762306a36Sopenharmony_ci break; 291862306a36Sopenharmony_ci } 291962306a36Sopenharmony_ci rtlphy->set_io_inprogress = false; 292062306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE, "<---(%#x)\n", 292162306a36Sopenharmony_ci rtlphy->current_io_type); 292262306a36Sopenharmony_ci} 292362306a36Sopenharmony_ci 292462306a36Sopenharmony_cibool rtl92d_phy_set_io_cmd(struct ieee80211_hw *hw, enum io_type iotype) 292562306a36Sopenharmony_ci{ 292662306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 292762306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 292862306a36Sopenharmony_ci bool postprocessing = false; 292962306a36Sopenharmony_ci 293062306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE, 293162306a36Sopenharmony_ci "-->IO Cmd(%#x), set_io_inprogress(%d)\n", 293262306a36Sopenharmony_ci iotype, rtlphy->set_io_inprogress); 293362306a36Sopenharmony_ci do { 293462306a36Sopenharmony_ci switch (iotype) { 293562306a36Sopenharmony_ci case IO_CMD_RESUME_DM_BY_SCAN: 293662306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE, 293762306a36Sopenharmony_ci "[IO CMD] Resume DM after scan\n"); 293862306a36Sopenharmony_ci postprocessing = true; 293962306a36Sopenharmony_ci break; 294062306a36Sopenharmony_ci case IO_CMD_PAUSE_DM_BY_SCAN: 294162306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE, 294262306a36Sopenharmony_ci "[IO CMD] Pause DM before scan\n"); 294362306a36Sopenharmony_ci postprocessing = true; 294462306a36Sopenharmony_ci break; 294562306a36Sopenharmony_ci default: 294662306a36Sopenharmony_ci pr_err("switch case %#x not processed\n", 294762306a36Sopenharmony_ci iotype); 294862306a36Sopenharmony_ci break; 294962306a36Sopenharmony_ci } 295062306a36Sopenharmony_ci } while (false); 295162306a36Sopenharmony_ci if (postprocessing && !rtlphy->set_io_inprogress) { 295262306a36Sopenharmony_ci rtlphy->set_io_inprogress = true; 295362306a36Sopenharmony_ci rtlphy->current_io_type = iotype; 295462306a36Sopenharmony_ci } else { 295562306a36Sopenharmony_ci return false; 295662306a36Sopenharmony_ci } 295762306a36Sopenharmony_ci rtl92d_phy_set_io(hw); 295862306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_CMD, DBG_TRACE, "<--IO Type(%#x)\n", iotype); 295962306a36Sopenharmony_ci return true; 296062306a36Sopenharmony_ci} 296162306a36Sopenharmony_ci 296262306a36Sopenharmony_cistatic void _rtl92d_phy_set_rfon(struct ieee80211_hw *hw) 296362306a36Sopenharmony_ci{ 296462306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 296562306a36Sopenharmony_ci 296662306a36Sopenharmony_ci /* a. SYS_CLKR 0x08[11] = 1 restore MAC clock */ 296762306a36Sopenharmony_ci /* b. SPS_CTRL 0x11[7:0] = 0x2b */ 296862306a36Sopenharmony_ci if (rtlpriv->rtlhal.macphymode == SINGLEMAC_SINGLEPHY) 296962306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x2b); 297062306a36Sopenharmony_ci /* c. For PCIE: SYS_FUNC_EN 0x02[7:0] = 0xE3 enable BB TRX function */ 297162306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE3); 297262306a36Sopenharmony_ci /* RF_ON_EXCEP(d~g): */ 297362306a36Sopenharmony_ci /* d. APSD_CTRL 0x600[7:0] = 0x00 */ 297462306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x00); 297562306a36Sopenharmony_ci /* e. SYS_FUNC_EN 0x02[7:0] = 0xE2 reset BB TRX function again */ 297662306a36Sopenharmony_ci /* f. SYS_FUNC_EN 0x02[7:0] = 0xE3 enable BB TRX function*/ 297762306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2); 297862306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE3); 297962306a36Sopenharmony_ci /* g. txpause 0x522[7:0] = 0x00 enable mac tx queue */ 298062306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_TXPAUSE, 0x00); 298162306a36Sopenharmony_ci} 298262306a36Sopenharmony_ci 298362306a36Sopenharmony_cistatic void _rtl92d_phy_set_rfsleep(struct ieee80211_hw *hw) 298462306a36Sopenharmony_ci{ 298562306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 298662306a36Sopenharmony_ci u32 u4btmp; 298762306a36Sopenharmony_ci u8 delay = 5; 298862306a36Sopenharmony_ci 298962306a36Sopenharmony_ci /* a. TXPAUSE 0x522[7:0] = 0xFF Pause MAC TX queue */ 299062306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF); 299162306a36Sopenharmony_ci /* b. RF path 0 offset 0x00 = 0x00 disable RF */ 299262306a36Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_A, 0x00, RFREG_OFFSET_MASK, 0x00); 299362306a36Sopenharmony_ci /* c. APSD_CTRL 0x600[7:0] = 0x40 */ 299462306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x40); 299562306a36Sopenharmony_ci /* d. APSD_CTRL 0x600[7:0] = 0x00 299662306a36Sopenharmony_ci * APSD_CTRL 0x600[7:0] = 0x00 299762306a36Sopenharmony_ci * RF path 0 offset 0x00 = 0x00 299862306a36Sopenharmony_ci * APSD_CTRL 0x600[7:0] = 0x40 299962306a36Sopenharmony_ci * */ 300062306a36Sopenharmony_ci u4btmp = rtl_get_rfreg(hw, RF90_PATH_A, 0, RFREG_OFFSET_MASK); 300162306a36Sopenharmony_ci while (u4btmp != 0 && delay > 0) { 300262306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x0); 300362306a36Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_A, 0x00, RFREG_OFFSET_MASK, 0x00); 300462306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x40); 300562306a36Sopenharmony_ci u4btmp = rtl_get_rfreg(hw, RF90_PATH_A, 0, RFREG_OFFSET_MASK); 300662306a36Sopenharmony_ci delay--; 300762306a36Sopenharmony_ci } 300862306a36Sopenharmony_ci if (delay == 0) { 300962306a36Sopenharmony_ci /* Jump out the LPS turn off sequence to RF_ON_EXCEP */ 301062306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x00); 301162306a36Sopenharmony_ci 301262306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2); 301362306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE3); 301462306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_TXPAUSE, 0x00); 301562306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_POWER, DBG_LOUD, 301662306a36Sopenharmony_ci "Fail !!! Switch RF timeout\n"); 301762306a36Sopenharmony_ci return; 301862306a36Sopenharmony_ci } 301962306a36Sopenharmony_ci /* e. For PCIE: SYS_FUNC_EN 0x02[7:0] = 0xE2 reset BB TRX function */ 302062306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2); 302162306a36Sopenharmony_ci /* f. SPS_CTRL 0x11[7:0] = 0x22 */ 302262306a36Sopenharmony_ci if (rtlpriv->rtlhal.macphymode == SINGLEMAC_SINGLEPHY) 302362306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x22); 302462306a36Sopenharmony_ci /* g. SYS_CLKR 0x08[11] = 0 gated MAC clock */ 302562306a36Sopenharmony_ci} 302662306a36Sopenharmony_ci 302762306a36Sopenharmony_cibool rtl92d_phy_set_rf_power_state(struct ieee80211_hw *hw, 302862306a36Sopenharmony_ci enum rf_pwrstate rfpwr_state) 302962306a36Sopenharmony_ci{ 303062306a36Sopenharmony_ci 303162306a36Sopenharmony_ci bool bresult = true; 303262306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 303362306a36Sopenharmony_ci struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); 303462306a36Sopenharmony_ci struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 303562306a36Sopenharmony_ci struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 303662306a36Sopenharmony_ci struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 303762306a36Sopenharmony_ci u8 i, queue_id; 303862306a36Sopenharmony_ci struct rtl8192_tx_ring *ring = NULL; 303962306a36Sopenharmony_ci 304062306a36Sopenharmony_ci if (rfpwr_state == ppsc->rfpwr_state) 304162306a36Sopenharmony_ci return false; 304262306a36Sopenharmony_ci switch (rfpwr_state) { 304362306a36Sopenharmony_ci case ERFON: 304462306a36Sopenharmony_ci if ((ppsc->rfpwr_state == ERFOFF) && 304562306a36Sopenharmony_ci RT_IN_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC)) { 304662306a36Sopenharmony_ci bool rtstatus; 304762306a36Sopenharmony_ci u32 initializecount = 0; 304862306a36Sopenharmony_ci do { 304962306a36Sopenharmony_ci initializecount++; 305062306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_DMESG, 305162306a36Sopenharmony_ci "IPS Set eRf nic enable\n"); 305262306a36Sopenharmony_ci rtstatus = rtl_ps_enable_nic(hw); 305362306a36Sopenharmony_ci } while (!rtstatus && (initializecount < 10)); 305462306a36Sopenharmony_ci 305562306a36Sopenharmony_ci RT_CLEAR_PS_LEVEL(ppsc, 305662306a36Sopenharmony_ci RT_RF_OFF_LEVL_HALT_NIC); 305762306a36Sopenharmony_ci } else { 305862306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_POWER, DBG_DMESG, 305962306a36Sopenharmony_ci "awake, slept:%d ms state_inap:%x\n", 306062306a36Sopenharmony_ci jiffies_to_msecs(jiffies - 306162306a36Sopenharmony_ci ppsc->last_sleep_jiffies), 306262306a36Sopenharmony_ci rtlpriv->psc.state_inap); 306362306a36Sopenharmony_ci ppsc->last_awake_jiffies = jiffies; 306462306a36Sopenharmony_ci _rtl92d_phy_set_rfon(hw); 306562306a36Sopenharmony_ci } 306662306a36Sopenharmony_ci 306762306a36Sopenharmony_ci if (mac->link_state == MAC80211_LINKED) 306862306a36Sopenharmony_ci rtlpriv->cfg->ops->led_control(hw, 306962306a36Sopenharmony_ci LED_CTL_LINK); 307062306a36Sopenharmony_ci else 307162306a36Sopenharmony_ci rtlpriv->cfg->ops->led_control(hw, 307262306a36Sopenharmony_ci LED_CTL_NO_LINK); 307362306a36Sopenharmony_ci break; 307462306a36Sopenharmony_ci case ERFOFF: 307562306a36Sopenharmony_ci if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC) { 307662306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_DMESG, 307762306a36Sopenharmony_ci "IPS Set eRf nic disable\n"); 307862306a36Sopenharmony_ci rtl_ps_disable_nic(hw); 307962306a36Sopenharmony_ci RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC); 308062306a36Sopenharmony_ci } else { 308162306a36Sopenharmony_ci if (ppsc->rfoff_reason == RF_CHANGE_BY_IPS) 308262306a36Sopenharmony_ci rtlpriv->cfg->ops->led_control(hw, 308362306a36Sopenharmony_ci LED_CTL_NO_LINK); 308462306a36Sopenharmony_ci else 308562306a36Sopenharmony_ci rtlpriv->cfg->ops->led_control(hw, 308662306a36Sopenharmony_ci LED_CTL_POWER_OFF); 308762306a36Sopenharmony_ci } 308862306a36Sopenharmony_ci break; 308962306a36Sopenharmony_ci case ERFSLEEP: 309062306a36Sopenharmony_ci if (ppsc->rfpwr_state == ERFOFF) 309162306a36Sopenharmony_ci return false; 309262306a36Sopenharmony_ci 309362306a36Sopenharmony_ci for (queue_id = 0, i = 0; 309462306a36Sopenharmony_ci queue_id < RTL_PCI_MAX_TX_QUEUE_COUNT;) { 309562306a36Sopenharmony_ci ring = &pcipriv->dev.tx_ring[queue_id]; 309662306a36Sopenharmony_ci if (skb_queue_len(&ring->queue) == 0 || 309762306a36Sopenharmony_ci queue_id == BEACON_QUEUE) { 309862306a36Sopenharmony_ci queue_id++; 309962306a36Sopenharmony_ci continue; 310062306a36Sopenharmony_ci } else if (rtlpci->pdev->current_state != PCI_D0) { 310162306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_POWER, DBG_LOUD, 310262306a36Sopenharmony_ci "eRf Off/Sleep: %d times TcbBusyQueue[%d] !=0 but lower power state!\n", 310362306a36Sopenharmony_ci i + 1, queue_id); 310462306a36Sopenharmony_ci break; 310562306a36Sopenharmony_ci } else { 310662306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_ERR, DBG_WARNING, 310762306a36Sopenharmony_ci "eRf Off/Sleep: %d times TcbBusyQueue[%d] =%d before doze!\n", 310862306a36Sopenharmony_ci i + 1, queue_id, 310962306a36Sopenharmony_ci skb_queue_len(&ring->queue)); 311062306a36Sopenharmony_ci udelay(10); 311162306a36Sopenharmony_ci i++; 311262306a36Sopenharmony_ci } 311362306a36Sopenharmony_ci 311462306a36Sopenharmony_ci if (i >= MAX_DOZE_WAITING_TIMES_9x) { 311562306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_ERR, DBG_WARNING, 311662306a36Sopenharmony_ci "ERFOFF: %d times TcbBusyQueue[%d] = %d !\n", 311762306a36Sopenharmony_ci MAX_DOZE_WAITING_TIMES_9x, queue_id, 311862306a36Sopenharmony_ci skb_queue_len(&ring->queue)); 311962306a36Sopenharmony_ci break; 312062306a36Sopenharmony_ci } 312162306a36Sopenharmony_ci } 312262306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_POWER, DBG_DMESG, 312362306a36Sopenharmony_ci "Set rfsleep awakened:%d ms\n", 312462306a36Sopenharmony_ci jiffies_to_msecs(jiffies - ppsc->last_awake_jiffies)); 312562306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_POWER, DBG_DMESG, 312662306a36Sopenharmony_ci "sleep awakened:%d ms state_inap:%x\n", 312762306a36Sopenharmony_ci jiffies_to_msecs(jiffies - 312862306a36Sopenharmony_ci ppsc->last_awake_jiffies), 312962306a36Sopenharmony_ci rtlpriv->psc.state_inap); 313062306a36Sopenharmony_ci ppsc->last_sleep_jiffies = jiffies; 313162306a36Sopenharmony_ci _rtl92d_phy_set_rfsleep(hw); 313262306a36Sopenharmony_ci break; 313362306a36Sopenharmony_ci default: 313462306a36Sopenharmony_ci pr_err("switch case %#x not processed\n", 313562306a36Sopenharmony_ci rfpwr_state); 313662306a36Sopenharmony_ci bresult = false; 313762306a36Sopenharmony_ci break; 313862306a36Sopenharmony_ci } 313962306a36Sopenharmony_ci if (bresult) 314062306a36Sopenharmony_ci ppsc->rfpwr_state = rfpwr_state; 314162306a36Sopenharmony_ci return bresult; 314262306a36Sopenharmony_ci} 314362306a36Sopenharmony_ci 314462306a36Sopenharmony_civoid rtl92d_phy_config_macphymode(struct ieee80211_hw *hw) 314562306a36Sopenharmony_ci{ 314662306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 314762306a36Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 314862306a36Sopenharmony_ci u8 offset = REG_MAC_PHY_CTRL_NORMAL; 314962306a36Sopenharmony_ci 315062306a36Sopenharmony_ci switch (rtlhal->macphymode) { 315162306a36Sopenharmony_ci case DUALMAC_DUALPHY: 315262306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, 315362306a36Sopenharmony_ci "MacPhyMode: DUALMAC_DUALPHY\n"); 315462306a36Sopenharmony_ci rtl_write_byte(rtlpriv, offset, 0xF3); 315562306a36Sopenharmony_ci break; 315662306a36Sopenharmony_ci case SINGLEMAC_SINGLEPHY: 315762306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, 315862306a36Sopenharmony_ci "MacPhyMode: SINGLEMAC_SINGLEPHY\n"); 315962306a36Sopenharmony_ci rtl_write_byte(rtlpriv, offset, 0xF4); 316062306a36Sopenharmony_ci break; 316162306a36Sopenharmony_ci case DUALMAC_SINGLEPHY: 316262306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, 316362306a36Sopenharmony_ci "MacPhyMode: DUALMAC_SINGLEPHY\n"); 316462306a36Sopenharmony_ci rtl_write_byte(rtlpriv, offset, 0xF1); 316562306a36Sopenharmony_ci break; 316662306a36Sopenharmony_ci } 316762306a36Sopenharmony_ci} 316862306a36Sopenharmony_ci 316962306a36Sopenharmony_civoid rtl92d_phy_config_macphymode_info(struct ieee80211_hw *hw) 317062306a36Sopenharmony_ci{ 317162306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 317262306a36Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 317362306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 317462306a36Sopenharmony_ci 317562306a36Sopenharmony_ci switch (rtlhal->macphymode) { 317662306a36Sopenharmony_ci case DUALMAC_SINGLEPHY: 317762306a36Sopenharmony_ci rtlphy->rf_type = RF_2T2R; 317862306a36Sopenharmony_ci rtlhal->version |= RF_TYPE_2T2R; 317962306a36Sopenharmony_ci rtlhal->bandset = BAND_ON_BOTH; 318062306a36Sopenharmony_ci rtlhal->current_bandtype = BAND_ON_2_4G; 318162306a36Sopenharmony_ci break; 318262306a36Sopenharmony_ci 318362306a36Sopenharmony_ci case SINGLEMAC_SINGLEPHY: 318462306a36Sopenharmony_ci rtlphy->rf_type = RF_2T2R; 318562306a36Sopenharmony_ci rtlhal->version |= RF_TYPE_2T2R; 318662306a36Sopenharmony_ci rtlhal->bandset = BAND_ON_BOTH; 318762306a36Sopenharmony_ci rtlhal->current_bandtype = BAND_ON_2_4G; 318862306a36Sopenharmony_ci break; 318962306a36Sopenharmony_ci 319062306a36Sopenharmony_ci case DUALMAC_DUALPHY: 319162306a36Sopenharmony_ci rtlphy->rf_type = RF_1T1R; 319262306a36Sopenharmony_ci rtlhal->version &= RF_TYPE_1T1R; 319362306a36Sopenharmony_ci /* Now we let MAC0 run on 5G band. */ 319462306a36Sopenharmony_ci if (rtlhal->interfaceindex == 0) { 319562306a36Sopenharmony_ci rtlhal->bandset = BAND_ON_5G; 319662306a36Sopenharmony_ci rtlhal->current_bandtype = BAND_ON_5G; 319762306a36Sopenharmony_ci } else { 319862306a36Sopenharmony_ci rtlhal->bandset = BAND_ON_2_4G; 319962306a36Sopenharmony_ci rtlhal->current_bandtype = BAND_ON_2_4G; 320062306a36Sopenharmony_ci } 320162306a36Sopenharmony_ci break; 320262306a36Sopenharmony_ci default: 320362306a36Sopenharmony_ci break; 320462306a36Sopenharmony_ci } 320562306a36Sopenharmony_ci} 320662306a36Sopenharmony_ci 320762306a36Sopenharmony_ciu8 rtl92d_get_chnlgroup_fromarray(u8 chnl) 320862306a36Sopenharmony_ci{ 320962306a36Sopenharmony_ci u8 group; 321062306a36Sopenharmony_ci 321162306a36Sopenharmony_ci if (channel_all[chnl] <= 3) 321262306a36Sopenharmony_ci group = 0; 321362306a36Sopenharmony_ci else if (channel_all[chnl] <= 9) 321462306a36Sopenharmony_ci group = 1; 321562306a36Sopenharmony_ci else if (channel_all[chnl] <= 14) 321662306a36Sopenharmony_ci group = 2; 321762306a36Sopenharmony_ci else if (channel_all[chnl] <= 44) 321862306a36Sopenharmony_ci group = 3; 321962306a36Sopenharmony_ci else if (channel_all[chnl] <= 54) 322062306a36Sopenharmony_ci group = 4; 322162306a36Sopenharmony_ci else if (channel_all[chnl] <= 64) 322262306a36Sopenharmony_ci group = 5; 322362306a36Sopenharmony_ci else if (channel_all[chnl] <= 112) 322462306a36Sopenharmony_ci group = 6; 322562306a36Sopenharmony_ci else if (channel_all[chnl] <= 126) 322662306a36Sopenharmony_ci group = 7; 322762306a36Sopenharmony_ci else if (channel_all[chnl] <= 140) 322862306a36Sopenharmony_ci group = 8; 322962306a36Sopenharmony_ci else if (channel_all[chnl] <= 153) 323062306a36Sopenharmony_ci group = 9; 323162306a36Sopenharmony_ci else if (channel_all[chnl] <= 159) 323262306a36Sopenharmony_ci group = 10; 323362306a36Sopenharmony_ci else 323462306a36Sopenharmony_ci group = 11; 323562306a36Sopenharmony_ci return group; 323662306a36Sopenharmony_ci} 323762306a36Sopenharmony_ci 323862306a36Sopenharmony_civoid rtl92d_phy_set_poweron(struct ieee80211_hw *hw) 323962306a36Sopenharmony_ci{ 324062306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 324162306a36Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 324262306a36Sopenharmony_ci unsigned long flags; 324362306a36Sopenharmony_ci u8 value8; 324462306a36Sopenharmony_ci u16 i; 324562306a36Sopenharmony_ci u32 mac_reg = (rtlhal->interfaceindex == 0 ? REG_MAC0 : REG_MAC1); 324662306a36Sopenharmony_ci 324762306a36Sopenharmony_ci /* notice fw know band status 0x81[1]/0x53[1] = 0: 5G, 1: 2G */ 324862306a36Sopenharmony_ci if (rtlhal->current_bandtype == BAND_ON_2_4G) { 324962306a36Sopenharmony_ci value8 = rtl_read_byte(rtlpriv, mac_reg); 325062306a36Sopenharmony_ci value8 |= BIT(1); 325162306a36Sopenharmony_ci rtl_write_byte(rtlpriv, mac_reg, value8); 325262306a36Sopenharmony_ci } else { 325362306a36Sopenharmony_ci value8 = rtl_read_byte(rtlpriv, mac_reg); 325462306a36Sopenharmony_ci value8 &= (~BIT(1)); 325562306a36Sopenharmony_ci rtl_write_byte(rtlpriv, mac_reg, value8); 325662306a36Sopenharmony_ci } 325762306a36Sopenharmony_ci 325862306a36Sopenharmony_ci if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY) { 325962306a36Sopenharmony_ci value8 = rtl_read_byte(rtlpriv, REG_MAC0); 326062306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_MAC0, value8 | MAC0_ON); 326162306a36Sopenharmony_ci } else { 326262306a36Sopenharmony_ci spin_lock_irqsave(&globalmutex_power, flags); 326362306a36Sopenharmony_ci if (rtlhal->interfaceindex == 0) { 326462306a36Sopenharmony_ci value8 = rtl_read_byte(rtlpriv, REG_MAC0); 326562306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_MAC0, value8 | MAC0_ON); 326662306a36Sopenharmony_ci } else { 326762306a36Sopenharmony_ci value8 = rtl_read_byte(rtlpriv, REG_MAC1); 326862306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_MAC1, value8 | MAC1_ON); 326962306a36Sopenharmony_ci } 327062306a36Sopenharmony_ci value8 = rtl_read_byte(rtlpriv, REG_POWER_OFF_IN_PROCESS); 327162306a36Sopenharmony_ci spin_unlock_irqrestore(&globalmutex_power, flags); 327262306a36Sopenharmony_ci for (i = 0; i < 200; i++) { 327362306a36Sopenharmony_ci if ((value8 & BIT(7)) == 0) { 327462306a36Sopenharmony_ci break; 327562306a36Sopenharmony_ci } else { 327662306a36Sopenharmony_ci udelay(500); 327762306a36Sopenharmony_ci spin_lock_irqsave(&globalmutex_power, flags); 327862306a36Sopenharmony_ci value8 = rtl_read_byte(rtlpriv, 327962306a36Sopenharmony_ci REG_POWER_OFF_IN_PROCESS); 328062306a36Sopenharmony_ci spin_unlock_irqrestore(&globalmutex_power, 328162306a36Sopenharmony_ci flags); 328262306a36Sopenharmony_ci } 328362306a36Sopenharmony_ci } 328462306a36Sopenharmony_ci if (i == 200) 328562306a36Sopenharmony_ci WARN_ONCE(true, "rtl8192de: Another mac power off over time\n"); 328662306a36Sopenharmony_ci } 328762306a36Sopenharmony_ci} 328862306a36Sopenharmony_ci 328962306a36Sopenharmony_civoid rtl92d_phy_config_maccoexist_rfpage(struct ieee80211_hw *hw) 329062306a36Sopenharmony_ci{ 329162306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 329262306a36Sopenharmony_ci 329362306a36Sopenharmony_ci switch (rtlpriv->rtlhal.macphymode) { 329462306a36Sopenharmony_ci case DUALMAC_DUALPHY: 329562306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_DMC, 0x0); 329662306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_RX_PKT_LIMIT, 0x08); 329762306a36Sopenharmony_ci rtl_write_word(rtlpriv, REG_TRXFF_BNDY + 2, 0x13ff); 329862306a36Sopenharmony_ci break; 329962306a36Sopenharmony_ci case DUALMAC_SINGLEPHY: 330062306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_DMC, 0xf8); 330162306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_RX_PKT_LIMIT, 0x08); 330262306a36Sopenharmony_ci rtl_write_word(rtlpriv, REG_TRXFF_BNDY + 2, 0x13ff); 330362306a36Sopenharmony_ci break; 330462306a36Sopenharmony_ci case SINGLEMAC_SINGLEPHY: 330562306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_DMC, 0x0); 330662306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_RX_PKT_LIMIT, 0x10); 330762306a36Sopenharmony_ci rtl_write_word(rtlpriv, (REG_TRXFF_BNDY + 2), 0x27FF); 330862306a36Sopenharmony_ci break; 330962306a36Sopenharmony_ci default: 331062306a36Sopenharmony_ci break; 331162306a36Sopenharmony_ci } 331262306a36Sopenharmony_ci} 331362306a36Sopenharmony_ci 331462306a36Sopenharmony_civoid rtl92d_update_bbrf_configuration(struct ieee80211_hw *hw) 331562306a36Sopenharmony_ci{ 331662306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 331762306a36Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 331862306a36Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 331962306a36Sopenharmony_ci struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 332062306a36Sopenharmony_ci u8 rfpath, i; 332162306a36Sopenharmony_ci 332262306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, "==>\n"); 332362306a36Sopenharmony_ci /* r_select_5G for path_A/B 0 for 2.4G, 1 for 5G */ 332462306a36Sopenharmony_ci if (rtlhal->current_bandtype == BAND_ON_2_4G) { 332562306a36Sopenharmony_ci /* r_select_5G for path_A/B,0x878 */ 332662306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, BIT(0), 0x0); 332762306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, BIT(15), 0x0); 332862306a36Sopenharmony_ci if (rtlhal->macphymode != DUALMAC_DUALPHY) { 332962306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, BIT(16), 0x0); 333062306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, BIT(31), 0x0); 333162306a36Sopenharmony_ci } 333262306a36Sopenharmony_ci /* rssi_table_select:index 0 for 2.4G.1~3 for 5G,0xc78 */ 333362306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_AGCRSSITABLE, BIT(6) | BIT(7), 0x0); 333462306a36Sopenharmony_ci /* fc_area 0xd2c */ 333562306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM1_CFOTRACKING, BIT(14) | BIT(13), 0x0); 333662306a36Sopenharmony_ci /* 5G LAN ON */ 333762306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xB30, 0x00F00000, 0xa); 333862306a36Sopenharmony_ci /* TX BB gain shift*1,Just for testchip,0xc80,0xc88 */ 333962306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XATXIQIMBALANCE, MASKDWORD, 334062306a36Sopenharmony_ci 0x40000100); 334162306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XBTXIQIMBALANCE, MASKDWORD, 334262306a36Sopenharmony_ci 0x40000100); 334362306a36Sopenharmony_ci if (rtlhal->macphymode == DUALMAC_DUALPHY) { 334462306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XAB_RFINTERFACESW, 334562306a36Sopenharmony_ci BIT(10) | BIT(6) | BIT(5), 334662306a36Sopenharmony_ci ((rtlefuse->eeprom_c9 & BIT(3)) >> 3) | 334762306a36Sopenharmony_ci (rtlefuse->eeprom_c9 & BIT(1)) | 334862306a36Sopenharmony_ci ((rtlefuse->eeprom_cc & BIT(1)) << 4)); 334962306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XA_RFINTERFACEOE, 335062306a36Sopenharmony_ci BIT(10) | BIT(6) | BIT(5), 335162306a36Sopenharmony_ci ((rtlefuse->eeprom_c9 & BIT(2)) >> 2) | 335262306a36Sopenharmony_ci ((rtlefuse->eeprom_c9 & BIT(0)) << 1) | 335362306a36Sopenharmony_ci ((rtlefuse->eeprom_cc & BIT(0)) << 5)); 335462306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, BIT(15), 0); 335562306a36Sopenharmony_ci } else { 335662306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XAB_RFINTERFACESW, 335762306a36Sopenharmony_ci BIT(26) | BIT(22) | BIT(21) | BIT(10) | 335862306a36Sopenharmony_ci BIT(6) | BIT(5), 335962306a36Sopenharmony_ci ((rtlefuse->eeprom_c9 & BIT(3)) >> 3) | 336062306a36Sopenharmony_ci (rtlefuse->eeprom_c9 & BIT(1)) | 336162306a36Sopenharmony_ci ((rtlefuse->eeprom_cc & BIT(1)) << 4) | 336262306a36Sopenharmony_ci ((rtlefuse->eeprom_c9 & BIT(7)) << 9) | 336362306a36Sopenharmony_ci ((rtlefuse->eeprom_c9 & BIT(5)) << 12) | 336462306a36Sopenharmony_ci ((rtlefuse->eeprom_cc & BIT(3)) << 18)); 336562306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XA_RFINTERFACEOE, 336662306a36Sopenharmony_ci BIT(10) | BIT(6) | BIT(5), 336762306a36Sopenharmony_ci ((rtlefuse->eeprom_c9 & BIT(2)) >> 2) | 336862306a36Sopenharmony_ci ((rtlefuse->eeprom_c9 & BIT(0)) << 1) | 336962306a36Sopenharmony_ci ((rtlefuse->eeprom_cc & BIT(0)) << 5)); 337062306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XB_RFINTERFACEOE, 337162306a36Sopenharmony_ci BIT(10) | BIT(6) | BIT(5), 337262306a36Sopenharmony_ci ((rtlefuse->eeprom_c9 & BIT(6)) >> 6) | 337362306a36Sopenharmony_ci ((rtlefuse->eeprom_c9 & BIT(4)) >> 3) | 337462306a36Sopenharmony_ci ((rtlefuse->eeprom_cc & BIT(2)) << 3)); 337562306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, 337662306a36Sopenharmony_ci BIT(31) | BIT(15), 0); 337762306a36Sopenharmony_ci } 337862306a36Sopenharmony_ci /* 1.5V_LDO */ 337962306a36Sopenharmony_ci } else { 338062306a36Sopenharmony_ci /* r_select_5G for path_A/B */ 338162306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, BIT(0), 0x1); 338262306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, BIT(15), 0x1); 338362306a36Sopenharmony_ci if (rtlhal->macphymode != DUALMAC_DUALPHY) { 338462306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, BIT(16), 0x1); 338562306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, BIT(31), 0x1); 338662306a36Sopenharmony_ci } 338762306a36Sopenharmony_ci /* rssi_table_select:index 0 for 2.4G.1~3 for 5G */ 338862306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_AGCRSSITABLE, BIT(6) | BIT(7), 0x1); 338962306a36Sopenharmony_ci /* fc_area */ 339062306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM1_CFOTRACKING, BIT(14) | BIT(13), 0x1); 339162306a36Sopenharmony_ci /* 5G LAN ON */ 339262306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xB30, 0x00F00000, 0x0); 339362306a36Sopenharmony_ci /* TX BB gain shift,Just for testchip,0xc80,0xc88 */ 339462306a36Sopenharmony_ci if (rtlefuse->internal_pa_5g[0]) 339562306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XATXIQIMBALANCE, MASKDWORD, 339662306a36Sopenharmony_ci 0x2d4000b5); 339762306a36Sopenharmony_ci else 339862306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XATXIQIMBALANCE, MASKDWORD, 339962306a36Sopenharmony_ci 0x20000080); 340062306a36Sopenharmony_ci if (rtlefuse->internal_pa_5g[1]) 340162306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XBTXIQIMBALANCE, MASKDWORD, 340262306a36Sopenharmony_ci 0x2d4000b5); 340362306a36Sopenharmony_ci else 340462306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XBTXIQIMBALANCE, MASKDWORD, 340562306a36Sopenharmony_ci 0x20000080); 340662306a36Sopenharmony_ci if (rtlhal->macphymode == DUALMAC_DUALPHY) { 340762306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XAB_RFINTERFACESW, 340862306a36Sopenharmony_ci BIT(10) | BIT(6) | BIT(5), 340962306a36Sopenharmony_ci (rtlefuse->eeprom_cc & BIT(5))); 341062306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XA_RFINTERFACEOE, BIT(10), 341162306a36Sopenharmony_ci ((rtlefuse->eeprom_cc & BIT(4)) >> 4)); 341262306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, BIT(15), 341362306a36Sopenharmony_ci (rtlefuse->eeprom_cc & BIT(4)) >> 4); 341462306a36Sopenharmony_ci } else { 341562306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XAB_RFINTERFACESW, 341662306a36Sopenharmony_ci BIT(26) | BIT(22) | BIT(21) | BIT(10) | 341762306a36Sopenharmony_ci BIT(6) | BIT(5), 341862306a36Sopenharmony_ci (rtlefuse->eeprom_cc & BIT(5)) | 341962306a36Sopenharmony_ci ((rtlefuse->eeprom_cc & BIT(7)) << 14)); 342062306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XA_RFINTERFACEOE, BIT(10), 342162306a36Sopenharmony_ci ((rtlefuse->eeprom_cc & BIT(4)) >> 4)); 342262306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XB_RFINTERFACEOE, BIT(10), 342362306a36Sopenharmony_ci ((rtlefuse->eeprom_cc & BIT(6)) >> 6)); 342462306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, 342562306a36Sopenharmony_ci BIT(31) | BIT(15), 342662306a36Sopenharmony_ci ((rtlefuse->eeprom_cc & BIT(4)) >> 4) | 342762306a36Sopenharmony_ci ((rtlefuse->eeprom_cc & BIT(6)) << 10)); 342862306a36Sopenharmony_ci } 342962306a36Sopenharmony_ci } 343062306a36Sopenharmony_ci /* update IQK related settings */ 343162306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XARXIQIMBALANCE, MASKDWORD, 0x40000100); 343262306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XBRXIQIMBALANCE, MASKDWORD, 0x40000100); 343362306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XCTXAFE, 0xF0000000, 0x00); 343462306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(30) | BIT(28) | 343562306a36Sopenharmony_ci BIT(26) | BIT(24), 0x00); 343662306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XDTXAFE, 0xF0000000, 0x00); 343762306a36Sopenharmony_ci rtl_set_bbreg(hw, 0xca0, 0xF0000000, 0x00); 343862306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_AGCRSSITABLE, 0x0000F000, 0x00); 343962306a36Sopenharmony_ci 344062306a36Sopenharmony_ci /* Update RF */ 344162306a36Sopenharmony_ci for (rfpath = RF90_PATH_A; rfpath < rtlphy->num_total_rfpath; 344262306a36Sopenharmony_ci rfpath++) { 344362306a36Sopenharmony_ci if (rtlhal->current_bandtype == BAND_ON_2_4G) { 344462306a36Sopenharmony_ci /* MOD_AG for RF path_A 0x18 BIT8,BIT16 */ 344562306a36Sopenharmony_ci rtl_set_rfreg(hw, rfpath, RF_CHNLBW, BIT(8) | BIT(16) | 344662306a36Sopenharmony_ci BIT(18), 0); 344762306a36Sopenharmony_ci /* RF0x0b[16:14] =3b'111 */ 344862306a36Sopenharmony_ci rtl_set_rfreg(hw, (enum radio_path)rfpath, 0x0B, 344962306a36Sopenharmony_ci 0x1c000, 0x07); 345062306a36Sopenharmony_ci } else { 345162306a36Sopenharmony_ci /* MOD_AG for RF path_A 0x18 BIT8,BIT16 */ 345262306a36Sopenharmony_ci rtl_set_rfreg(hw, rfpath, RF_CHNLBW, BIT(8) | 345362306a36Sopenharmony_ci BIT(16) | BIT(18), 345462306a36Sopenharmony_ci (BIT(16) | BIT(8)) >> 8); 345562306a36Sopenharmony_ci } 345662306a36Sopenharmony_ci } 345762306a36Sopenharmony_ci /* Update for all band. */ 345862306a36Sopenharmony_ci /* DMDP */ 345962306a36Sopenharmony_ci if (rtlphy->rf_type == RF_1T1R) { 346062306a36Sopenharmony_ci /* Use antenna 0,0xc04,0xd04 */ 346162306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_TRXPATHENABLE, MASKBYTE0, 0x11); 346262306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM1_TRXPATHENABLE, BDWORD, 0x1); 346362306a36Sopenharmony_ci 346462306a36Sopenharmony_ci /* enable ad/da clock1 for dual-phy reg0x888 */ 346562306a36Sopenharmony_ci if (rtlhal->interfaceindex == 0) { 346662306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_ADDALLOCKEN, BIT(12) | 346762306a36Sopenharmony_ci BIT(13), 0x3); 346862306a36Sopenharmony_ci } else { 346962306a36Sopenharmony_ci rtl92d_phy_enable_anotherphy(hw, false); 347062306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, 347162306a36Sopenharmony_ci "MAC1 use DBI to update 0x888\n"); 347262306a36Sopenharmony_ci /* 0x888 */ 347362306a36Sopenharmony_ci rtl92de_write_dword_dbi(hw, RFPGA0_ADDALLOCKEN, 347462306a36Sopenharmony_ci rtl92de_read_dword_dbi(hw, 347562306a36Sopenharmony_ci RFPGA0_ADDALLOCKEN, 347662306a36Sopenharmony_ci BIT(3)) | BIT(12) | BIT(13), 347762306a36Sopenharmony_ci BIT(3)); 347862306a36Sopenharmony_ci rtl92d_phy_powerdown_anotherphy(hw, false); 347962306a36Sopenharmony_ci } 348062306a36Sopenharmony_ci } else { 348162306a36Sopenharmony_ci /* Single PHY */ 348262306a36Sopenharmony_ci /* Use antenna 0 & 1,0xc04,0xd04 */ 348362306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_TRXPATHENABLE, MASKBYTE0, 0x33); 348462306a36Sopenharmony_ci rtl_set_bbreg(hw, ROFDM1_TRXPATHENABLE, BDWORD, 0x3); 348562306a36Sopenharmony_ci /* disable ad/da clock1,0x888 */ 348662306a36Sopenharmony_ci rtl_set_bbreg(hw, RFPGA0_ADDALLOCKEN, BIT(12) | BIT(13), 0); 348762306a36Sopenharmony_ci } 348862306a36Sopenharmony_ci for (rfpath = RF90_PATH_A; rfpath < rtlphy->num_total_rfpath; 348962306a36Sopenharmony_ci rfpath++) { 349062306a36Sopenharmony_ci rtlphy->rfreg_chnlval[rfpath] = rtl_get_rfreg(hw, rfpath, 349162306a36Sopenharmony_ci RF_CHNLBW, RFREG_OFFSET_MASK); 349262306a36Sopenharmony_ci rtlphy->reg_rf3c[rfpath] = rtl_get_rfreg(hw, rfpath, 0x3C, 349362306a36Sopenharmony_ci RFREG_OFFSET_MASK); 349462306a36Sopenharmony_ci } 349562306a36Sopenharmony_ci for (i = 0; i < 2; i++) 349662306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RF, DBG_LOUD, "RF 0x18 = 0x%x\n", 349762306a36Sopenharmony_ci rtlphy->rfreg_chnlval[i]); 349862306a36Sopenharmony_ci rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD, "<==\n"); 349962306a36Sopenharmony_ci 350062306a36Sopenharmony_ci} 350162306a36Sopenharmony_ci 350262306a36Sopenharmony_cibool rtl92d_phy_check_poweroff(struct ieee80211_hw *hw) 350362306a36Sopenharmony_ci{ 350462306a36Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 350562306a36Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 350662306a36Sopenharmony_ci u8 u1btmp; 350762306a36Sopenharmony_ci unsigned long flags; 350862306a36Sopenharmony_ci 350962306a36Sopenharmony_ci if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY) { 351062306a36Sopenharmony_ci u1btmp = rtl_read_byte(rtlpriv, REG_MAC0); 351162306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_MAC0, u1btmp & (~MAC0_ON)); 351262306a36Sopenharmony_ci return true; 351362306a36Sopenharmony_ci } 351462306a36Sopenharmony_ci spin_lock_irqsave(&globalmutex_power, flags); 351562306a36Sopenharmony_ci if (rtlhal->interfaceindex == 0) { 351662306a36Sopenharmony_ci u1btmp = rtl_read_byte(rtlpriv, REG_MAC0); 351762306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_MAC0, u1btmp & (~MAC0_ON)); 351862306a36Sopenharmony_ci u1btmp = rtl_read_byte(rtlpriv, REG_MAC1); 351962306a36Sopenharmony_ci u1btmp &= MAC1_ON; 352062306a36Sopenharmony_ci } else { 352162306a36Sopenharmony_ci u1btmp = rtl_read_byte(rtlpriv, REG_MAC1); 352262306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_MAC1, u1btmp & (~MAC1_ON)); 352362306a36Sopenharmony_ci u1btmp = rtl_read_byte(rtlpriv, REG_MAC0); 352462306a36Sopenharmony_ci u1btmp &= MAC0_ON; 352562306a36Sopenharmony_ci } 352662306a36Sopenharmony_ci if (u1btmp) { 352762306a36Sopenharmony_ci spin_unlock_irqrestore(&globalmutex_power, flags); 352862306a36Sopenharmony_ci return false; 352962306a36Sopenharmony_ci } 353062306a36Sopenharmony_ci u1btmp = rtl_read_byte(rtlpriv, REG_POWER_OFF_IN_PROCESS); 353162306a36Sopenharmony_ci u1btmp |= BIT(7); 353262306a36Sopenharmony_ci rtl_write_byte(rtlpriv, REG_POWER_OFF_IN_PROCESS, u1btmp); 353362306a36Sopenharmony_ci spin_unlock_irqrestore(&globalmutex_power, flags); 353462306a36Sopenharmony_ci return true; 353562306a36Sopenharmony_ci} 3536