42 #define MAX_RF_IMR_INDEX 12
43 #define MAX_RF_IMR_INDEX_NORMAL 13
44 #define RF_REG_NUM_FOR_C_CUT_5G 6
45 #define RF_REG_NUM_FOR_C_CUT_5G_INTERNALPA 7
46 #define RF_REG_NUM_FOR_C_CUT_2G 5
47 #define RF_CHNL_NUM_5G 19
48 #define RF_CHNL_NUM_5G_40M 17
49 #define TARGET_CHNL_NUM_5G 221
50 #define TARGET_CHNL_NUM_2G 14
51 #define CV_CURVE_CNT 64
54 0, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x0
66 0x0B, 0x48, 0x49, 0x4B, 0x03, 0x04, 0x0E
78 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108,
79 112, 116, 120, 124, 128, 132, 136, 140
83 38, 42, 46, 50, 54, 58, 62, 102, 106, 110, 114,
84 118, 122, 126, 130, 134, 138
87 {0xE43BE, 0xFC638, 0x77C0A, 0xDE471, 0xd7110, 0x8EB04},
88 {0xE43BE, 0xFC078, 0xF7C1A, 0xE0C71, 0xD7550, 0xAEB04},
89 {0xE43BF, 0xFF038, 0xF7C0A, 0xDE471, 0xE5550, 0xAEB04},
90 {0xE43BF, 0xFF079, 0xF7C1A, 0xDE471, 0xE5550, 0xAEB04},
91 {0xE43BF, 0xFF038, 0xF7C1A, 0xDE471, 0xd7550, 0xAEB04}
95 {0x643BC, 0xFC038, 0x77C1A, 0x41289, 0x01840},
96 {0x643BC, 0xFC038, 0x07C1A, 0x41289, 0x01840},
97 {0x243BC, 0xFC438, 0x07C1A, 0x4128B, 0x0FC41}
100 static u32 rf_syn_g4_for_c_cut_2g = 0xD1C31 & 0x7FF;
103 {0x01a00, 0x40443, 0x00eb5, 0x89bec, 0x94a12, 0x94a12, 0x94a12},
104 {0x01800, 0xc0443, 0x00730, 0x896ee, 0x94a52, 0x94a52, 0x94a52},
105 {0x01800, 0xc0443, 0x00730, 0x896ee, 0x94a12, 0x94a12, 0x94a12}
113 0x70000, 0x00ff0, 0x4400f, 0x00ff0, 0x0, 0x0, 0x0,
114 0x0, 0x0, 0x64888, 0xe266c, 0x00090, 0x22fff
118 0x70000, 0x22880, 0x4470f, 0x55880, 0x00070, 0x88000,
119 0x0, 0x88080, 0x70000, 0x64a82, 0xe466c, 0x00090,
124 0x70000, 0x44880, 0x4477f, 0x77880, 0x00070, 0x88000,
125 0x0, 0x880b0, 0x0, 0x64b82, 0xe466c, 0x00090, 0x32c9a
135 25141, 25116, 25091, 25066, 25041,
136 25016, 24991, 24966, 24941, 24917,
137 24892, 24867, 24843, 24818, 24794,
138 24770, 24765, 24721, 24697, 24672,
139 24648, 24624, 24600, 24576, 24552,
140 24528, 24504, 24480, 24457, 24433,
141 24409, 24385, 24362, 24338, 24315,
142 24291, 24268, 24245, 24221, 24198,
143 24175, 24151, 24128, 24105, 24082,
144 24059, 24036, 24013, 23990, 23967,
145 23945, 23922, 23899, 23876, 23854,
146 23831, 23809, 23786, 23764, 23741,
147 23719, 23697, 23674, 23652, 23630,
148 23608, 23586, 23564, 23541, 23519,
149 23498, 23476, 23454, 23432, 23410,
150 23388, 23367, 23345, 23323, 23302,
151 23280, 23259, 23237, 23216, 23194,
152 23173, 23152, 23130, 23109, 23088,
153 23067, 23046, 23025, 23003, 22982,
154 22962, 22941, 22920, 22899, 22878,
155 22857, 22837, 22816, 22795, 22775,
156 22754, 22733, 22713, 22692, 22672,
157 22652, 22631, 22611, 22591, 22570,
158 22550, 22530, 22510, 22490, 22469,
159 22449, 22429, 22409, 22390, 22370,
160 22350, 22336, 22310, 22290, 22271,
161 22251, 22231, 22212, 22192, 22173,
162 22153, 22134, 22114, 22095, 22075,
163 22056, 22037, 22017, 21998, 21979,
164 21960, 21941, 21921, 21902, 21883,
165 21864, 21845, 21826, 21807, 21789,
166 21770, 21751, 21732, 21713, 21695,
167 21676, 21657, 21639, 21620, 21602,
168 21583, 21565, 21546, 21528, 21509,
169 21491, 21473, 21454, 21436, 21418,
170 21400, 21381, 21363, 21345, 21327,
171 21309, 21291, 21273, 21255, 21237,
172 21219, 21201, 21183, 21166, 21148,
173 21130, 21112, 21095, 21077, 21059,
174 21042, 21024, 21007, 20989, 20972,
175 25679, 25653, 25627, 25601, 25575,
176 25549, 25523, 25497, 25471, 25446,
177 25420, 25394, 25369, 25343, 25318,
178 25292, 25267, 25242, 25216, 25191,
184 26084, 26030, 25976, 25923, 25869, 25816, 25764,
185 25711, 25658, 25606, 25554, 25502, 25451, 25328
192 for (i = 0; i <= 31; i++) {
193 if (((bitmask >> i) & 0x1) == 1)
204 u32 returnvalue, originalvalue, bitshift;
215 dbi_direct =
BIT(3) |
BIT(2);
219 originalvalue = rtl_read_dword(rtlpriv, regaddr);
221 bitshift = _rtl92d_phy_calculate_bit_shift(bitmask);
222 returnvalue = (originalvalue &
bitmask) >> bitshift;
224 "BBR MASK=0x%x Addr[0x%x]=0x%x\n",
225 bitmask, regaddr, originalvalue);
235 u32 originalvalue, bitshift;
238 "regaddr(%#x), bitmask(%#x), data(%#x)\n",
239 regaddr, bitmask, data);
244 dbi_direct =
BIT(3) |
BIT(2);
252 originalvalue = rtl_read_dword(rtlpriv, regaddr);
253 bitshift = _rtl92d_phy_calculate_bit_shift(bitmask);
254 data = ((originalvalue & (~bitmask)) | (data << bitshift));
259 rtl_write_dword(rtlpriv, regaddr, data);
261 "regaddr(%#x), bitmask(%#x), data(%#x)\n",
262 regaddr, bitmask, data);
273 u32 tmplong, tmplong2;
311 static void _rtl92d_phy_rf_serial_write(
struct ieee80211_hw *hw,
323 data_and_addr = ((newoffset << 20) | (data & 0x000fffff)) & 0x0fffffff;
333 u32 original_value, readback_value, bitshift;
337 "regaddr(%#x), rfpath(%#x), bitmask(%#x)\n",
338 regaddr, rfpath, bitmask);
340 original_value = _rtl92d_phy_rf_serial_read(hw, rfpath, regaddr);
341 bitshift = _rtl92d_phy_calculate_bit_shift(bitmask);
342 readback_value = (original_value &
bitmask) >> bitshift;
343 spin_unlock_irqrestore(&rtlpriv->
locks.rf_lock, flags);
345 "regaddr(%#x), rfpath(%#x), bitmask(%#x), original_value(%#x)\n",
346 regaddr, rfpath, bitmask, original_value);
347 return readback_value;
355 u32 original_value, bitshift;
359 "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
360 regaddr, bitmask, data, rfpath);
366 original_value = _rtl92d_phy_rf_serial_read(hw,
368 bitshift = _rtl92d_phy_calculate_bit_shift(bitmask);
369 data = ((original_value & (~bitmask)) |
372 _rtl92d_phy_rf_serial_write(hw, rfpath, regaddr, data);
374 spin_unlock_irqrestore(&rtlpriv->
locks.rf_lock, flags);
376 "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
377 regaddr, bitmask, data, rfpath);
391 for (i = 0; i < arraylength; i = i + 2)
392 rtl_write_byte(rtlpriv, ptrarray[i], (
u8) ptrarray[i + 1]);
406 static void _rtl92d_phy_init_bb_rf_register_definition(
struct ieee80211_hw *hw)
551 static bool _rtl92d_phy_config_bb_with_headerfile(
struct ieee80211_hw *hw,
555 u32 *phy_regarray_table;
556 u32 *agctab_array_table =
NULL;
557 u32 *agctab_5garray_table;
558 u16 phy_reg_arraylen, agctab_arraylen = 0, agctab_5garraylen;
567 " ===> phy:MAC0, Rtl819XAGCTAB_Array\n");
573 " ===> phy:MAC1, Rtl819XAGCTAB_2GArray\n");
578 " ===> phy:MAC1, Rtl819XAGCTAB_5GArray\n");
585 " ===> phy:Rtl819XPHY_REG_Array_PG\n");
587 for (i = 0; i < phy_reg_arraylen; i = i + 2) {
588 if (phy_regarray_table[i] == 0xfe)
590 else if (phy_regarray_table[i] == 0xfd)
592 else if (phy_regarray_table[i] == 0xfc)
594 else if (phy_regarray_table[i] == 0xfb)
596 else if (phy_regarray_table[i] == 0xfa)
598 else if (phy_regarray_table[i] == 0xf9)
600 rtl_set_bbreg(hw, phy_regarray_table[i],
BMASKDWORD,
601 phy_regarray_table[i + 1]);
604 "The phy_regarray_table[0] is %x Rtl819XPHY_REGArray[1] is %x\n",
605 phy_regarray_table[i],
606 phy_regarray_table[i + 1]);
610 for (i = 0; i < agctab_arraylen; i = i + 2) {
611 rtl_set_bbreg(hw, agctab_array_table[i],
613 agctab_array_table[i + 1]);
618 "The Rtl819XAGCTAB_Array_Table[0] is %ul Rtl819XPHY_REGArray[1] is %ul\n",
619 agctab_array_table[i],
620 agctab_array_table[i + 1]);
623 "Normal Chip, MAC0, load Rtl819XAGCTAB_Array\n");
626 for (i = 0; i < agctab_arraylen; i = i + 2) {
627 rtl_set_bbreg(hw, agctab_array_table[i],
629 agctab_array_table[i + 1]);
634 "The Rtl819XAGCTAB_Array_Table[0] is %ul Rtl819XPHY_REGArray[1] is %ul\n",
635 agctab_array_table[i],
636 agctab_array_table[i + 1]);
639 "Load Rtl819XAGCTAB_2GArray\n");
641 for (i = 0; i < agctab_5garraylen; i = i + 2) {
643 agctab_5garray_table[i],
645 agctab_5garray_table[i + 1]);
650 "The Rtl819XAGCTAB_5GArray_Table[0] is %ul Rtl819XPHY_REGArray[1] is %ul\n",
651 agctab_5garray_table[i],
652 agctab_5garray_table[i + 1]);
655 "Load Rtl819XAGCTAB_5GArray\n");
662 static void _rtl92d_store_pwrindex_diffrate_offset(
struct ieee80211_hw *hw,
707 "MCSTxPowerLevelOriginalOffset[%d][%d] = 0x%ulx\n",
715 static bool _rtl92d_phy_config_bb_with_pgheaderfile(
struct ieee80211_hw *hw,
720 u32 *phy_regarray_table_pg;
721 u16 phy_regarray_pg_len;
726 for (i = 0; i < phy_regarray_pg_len; i = i + 3) {
727 if (phy_regarray_table_pg[i] == 0xfe)
729 else if (phy_regarray_table_pg[i] == 0xfd)
731 else if (phy_regarray_table_pg[i] == 0xfc)
733 else if (phy_regarray_table_pg[i] == 0xfb)
735 else if (phy_regarray_table_pg[i] == 0xfa)
737 else if (phy_regarray_table_pg[i] == 0xf9)
739 _rtl92d_store_pwrindex_diffrate_offset(hw,
740 phy_regarray_table_pg[i],
741 phy_regarray_table_pg[i + 1],
742 phy_regarray_table_pg[i + 2]);
746 "configtype != BaseBand_Config_PHY_REG\n");
751 static bool _rtl92d_phy_bb_config(
struct ieee80211_hw *hw)
756 bool rtstatus =
true;
759 rtstatus = _rtl92d_phy_config_bb_with_headerfile(hw,
773 rtstatus = _rtl92d_phy_config_bb_with_pgheaderfile(hw,
780 rtstatus = _rtl92d_phy_config_bb_with_headerfile(hw,
799 _rtl92d_phy_init_bb_rf_register_definition(hw);
817 return _rtl92d_phy_bb_config(hw);
830 u32 *radioa_array_table;
831 u32 *radiob_array_table;
832 u16 radioa_arraylen, radiob_arraylen;
839 if (rtlpriv->
efuse.internal_pa_5g[0]) {
843 if (rtlpriv->
efuse.internal_pa_5g[1]) {
848 "PHY_ConfigRFWithHeaderFile() Radio_A:Rtl819XRadioA_1TArray\n");
850 "PHY_ConfigRFWithHeaderFile() Radio_B:Rtl819XRadioB_1TArray\n");
858 " ===> althougth Path A, we load radiob.txt\n");
859 radioa_arraylen = radiob_arraylen;
860 radioa_array_table = radiob_array_table;
864 for (i = 0; i < radioa_arraylen; i = i + 2) {
865 if (radioa_array_table[i] == 0xfe) {
867 }
else if (radioa_array_table[i] == 0xfd) {
870 }
else if (radioa_array_table[i] == 0xfc) {
873 }
else if (radioa_array_table[i] == 0xfb) {
875 }
else if (radioa_array_table[i] == 0xfa) {
877 }
else if (radioa_array_table[i] == 0xf9) {
880 rtl_set_rfreg(hw, rfpath, radioa_array_table[i],
882 radioa_array_table[i + 1]);
889 for (i = 0; i < radiob_arraylen; i = i + 2) {
890 if (radiob_array_table[i] == 0xfe) {
894 }
else if (radiob_array_table[i] == 0xfd) {
897 }
else if (radiob_array_table[i] == 0xfc) {
900 }
else if (radiob_array_table[i] == 0xfb) {
902 }
else if (radiob_array_table[i] == 0xfa) {
904 }
else if (radiob_array_table[i] == 0xf9) {
907 rtl_set_rfreg(hw, rfpath, radiob_array_table[i],
909 radiob_array_table[i + 1]);
917 "switch case not processed\n");
921 "switch case not processed\n");
941 "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x\n",
951 "Default framesync (0x%x) = 0x%x\n",
956 u8 *cckpowerlevel,
u8 *ofdmpowerlevel)
962 u8 index = (channel - 1);
992 static void _rtl92d_ccxpower_index_check(
struct ieee80211_hw *hw,
993 u8 channel,
u8 *cckpowerlevel,
u8 *ofdmpowerlevel)
1002 static u8 _rtl92c_phy_get_rightchnlplace(
u8 chnl)
1004 u8 channel_5g[59] = {
1005 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
1006 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58,
1007 60, 62, 64, 100, 102, 104, 106, 108, 110, 112,
1008 114, 116, 118, 120, 122, 124, 126, 128,
1009 130, 132, 134, 136, 138, 140, 149, 151,
1010 153, 155, 157, 159, 161, 163, 165
1015 for (place = 14; place <
sizeof(channel_5g); place++) {
1016 if (channel_5g[place] == chnl) {
1029 u8 cckpowerlevel[2], ofdmpowerlevel[2];
1033 channel = _rtl92c_phy_get_rightchnlplace(channel);
1034 _rtl92d_get_txpower_index(hw, channel, &cckpowerlevel[0],
1035 &ofdmpowerlevel[0]);
1037 _rtl92d_ccxpower_index_check(hw, channel, &cckpowerlevel[0],
1038 &ofdmpowerlevel[0]);
1050 if (!is_hal_stop(rtlhal)) {
1051 switch (operation) {
1066 "Unknown Scan Backup operation\n");
1079 unsigned long flag = 0;
1087 "FALSE driver sleep or unload\n");
1095 reg_prsr_rsc = rtl_read_byte(rtlpriv,
REG_RRSR + 2);
1105 reg_prsr_rsc = (reg_prsr_rsc & 0x90) |
1107 rtl_write_byte(rtlpriv,
REG_RRSR + 2, reg_prsr_rsc);
1128 rtl92d_acquire_cckandrw_pagea_ctl(hw, &flag);
1131 rtl92d_release_cckandrw_pagea_ctl(hw, &flag);
1137 rtl_set_bbreg(hw, 0x818, (
BIT(26) |
BIT(27)),
1152 static void _rtl92d_phy_stop_trx_before_changeband(
struct ieee80211_hw *hw)
1160 static void rtl92d_phy_switch_wirelessband(
struct ieee80211_hw *hw,
u8 band)
1172 _rtl92d_phy_stop_trx_before_changeband(hw);
1178 _rtl92d_phy_config_bb_with_headerfile(hw,
1184 _rtl92d_phy_config_bb_with_headerfile(hw,
1205 value8 &= (~
BIT(1));
1213 static void _rtl92d_phy_reload_imr_setting(
struct ieee80211_hw *hw,
1214 u8 channel,
u8 rfpath)
1220 unsigned long flag = 0;
1235 group = channel <= 64 ? 1 : 2;
1237 for (i = 0; i < imr_num; i++)
1239 rf_reg_for_5g_swchnl_normal[i], rfmask,
1240 rf_imr_param_normal[0][group][i]);
1246 "Load RF IMR parameters for G band. IMR already setting %d\n",
1247 rtlpriv->
rtlhal.load_imrandiqk_setting_for2g);
1249 if (!rtlpriv->
rtlhal.load_imrandiqk_setting_for2g) {
1251 "Load RF IMR parameters for G band. %d\n",
1253 rtl92d_acquire_cckandrw_pagea_ctl(hw, &flag);
1258 for (i = 0; i < imr_num; i++) {
1260 rf_reg_for_5g_swchnl_normal[i],
1262 rf_imr_param_normal[0][0][i]);
1267 rtl92d_release_cckandrw_pagea_ctl(hw, &flag);
1273 static void _rtl92d_phy_enable_rf_env(
struct ieee80211_hw *hw,
1274 u8 rfpath,
u32 *pu4_regval)
1309 static void _rtl92d_phy_restore_rf_env(
struct ieee80211_hw *hw,
u8 rfpath,
1332 static void _rtl92d_phy_switch_rf_setting(
struct ieee80211_hw *hw,
u8 channel)
1340 bool need_pwr_down =
false, internal_pa =
false;
1341 u32 u4regvalue,
mask = 0x1C000,
value = 0, u4tmp, u4tmp2;
1347 u4tmp = curveindex_5g[channel - 1];
1349 "ver 1 set RF-A, 5G, 0x28 = 0x%x !!\n", u4tmp);
1351 if (channel == rf_chnl_5g[i] && channel <= 140)
1355 if (channel == rf_chnl_5g_40m[i] && channel <= 140)
1358 if (channel == 149 || channel == 155 || channel == 161)
1360 else if (channel == 151 || channel == 153 || channel == 163
1363 else if (channel == 157 || channel == 159)
1372 _rtl92d_phy_enable_rf_env(hw, path,
1378 rf_reg_for_c_cut_5g[i],
1380 }
else if (rf_reg_for_c_cut_5g[i] ==
RF_SYN_G4) {
1381 u4tmp2 = (rf_reg_pram_c_5g[
index][
i] &
1382 0x7FF) | (u4tmp << 11);
1384 u4tmp2 &= ~(
BIT(7) |
BIT(6));
1386 rf_reg_for_c_cut_5g[i],
1390 rf_reg_for_c_cut_5g[i],
1392 rf_reg_pram_c_5g[index][i]);
1395 "offset 0x%x value 0x%x path %d index %d readback 0x%x\n",
1396 rf_reg_for_c_cut_5g[i],
1397 rf_reg_pram_c_5g[index][i],
1400 rf_reg_for_c_cut_5g[i],
1404 _rtl92d_phy_restore_rf_env(hw, path, &u4regvalue);
1409 else if (channel >= 149)
1411 if (channel >= 36 && channel <= 64)
1413 else if (channel >= 100 && channel <= 140)
1421 internal_pa = rtlpriv->
efuse.internal_pa_5g[1];
1424 rtlpriv->
efuse.internal_pa_5g[rfpath];
1429 rtl_set_rfreg(hw, rfpath,
1430 rf_for_c_cut_5g_internal_pa[i],
1432 rf_pram_c_5g_int_pa[index][i]);
1434 "offset 0x%x value 0x%x path %d index %d\n",
1435 rf_for_c_cut_5g_internal_pa[i],
1436 rf_pram_c_5g_int_pa[index][i],
1440 rtl_set_rfreg(hw, (
enum radio_path)rfpath, 0x0B,
1446 u4tmp = curveindex_2g[channel - 1];
1448 "ver 3 set RF-B, 2G, 0x28 = 0x%x !!\n", u4tmp);
1449 if (channel == 1 || channel == 2 || channel == 4 || channel == 9
1450 || channel == 10 || channel == 11 || channel == 12)
1452 else if (channel == 3 || channel == 13 || channel == 14)
1454 else if (channel >= 5 && channel <= 8)
1464 _rtl92d_phy_enable_rf_env(hw, path,
1469 if (rf_reg_for_c_cut_2g[i] ==
RF_SYN_G7)
1471 rf_reg_for_c_cut_2g[i],
1473 (rf_reg_param_for_c_cut_2g[index][i] |
1477 rf_reg_for_c_cut_2g[i],
1479 rf_reg_param_for_c_cut_2g
1482 "offset 0x%x value 0x%x mak 0x%x path %d index %d readback 0x%x\n",
1483 rf_reg_for_c_cut_2g[i],
1484 rf_reg_param_for_c_cut_2g[index][i],
1485 rf_reg_mask_for_c_cut_2g[i], path, index,
1487 rf_reg_for_c_cut_2g[i],
1491 "cosa ver 3 set RF-B, 2G, 0x28 = 0x%x !!\n",
1492 rf_syn_g4_for_c_cut_2g | (u4tmp << 11));
1496 rf_syn_g4_for_c_cut_2g | (u4tmp << 11));
1498 _rtl92d_phy_restore_rf_env(hw, path, &u4regvalue);
1507 u8 channel_all[59] = {
1508 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
1509 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58,
1510 60, 62, 64, 100, 102, 104, 106, 108, 110, 112,
1511 114, 116, 118, 120, 122, 124, 126, 128, 130,
1512 132, 134, 136, 138, 140, 149, 151, 153, 155,
1513 157, 159, 161, 163, 165
1518 for (place = 14; place <
sizeof(channel_all); place++) {
1519 if (channel_all[place] == chnl)
1527 #define MAX_TOLERANCE 5
1528 #define IQK_DELAY_TIME 1
1529 #define MAX_TOLERANCE_92D 3
1532 static u8 _rtl92d_phy_patha_iqk(
struct ieee80211_hw *hw,
bool configpathb)
1536 u32 regeac, rege94, rege9c, regea4;
1543 rtl_set_bbreg(hw, 0xe30,
BMASKDWORD, 0x10008c1f);
1544 rtl_set_bbreg(hw, 0xe34,
BMASKDWORD, 0x10008c1f);
1546 rtl_set_bbreg(hw, 0xe30,
BMASKDWORD, 0x10008c22);
1547 rtl_set_bbreg(hw, 0xe34,
BMASKDWORD, 0x10008c22);
1549 rtl_set_bbreg(hw, 0xe38,
BMASKDWORD, 0x82140102);
1550 rtl_set_bbreg(hw, 0xe3c,
BMASKDWORD, 0x28160206);
1553 rtl_set_bbreg(hw, 0xe50,
BMASKDWORD, 0x10008c22);
1554 rtl_set_bbreg(hw, 0xe54,
BMASKDWORD, 0x10008c22);
1555 rtl_set_bbreg(hw, 0xe58,
BMASKDWORD, 0x82140102);
1556 rtl_set_bbreg(hw, 0xe5c,
BMASKDWORD, 0x28160206);
1559 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"LO calibration setting!\n");
1560 rtl_set_bbreg(hw, 0xe4c,
BMASKDWORD, 0x00462911);
1562 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"One shot, path A LOK & IQK!\n");
1563 rtl_set_bbreg(hw, 0xe48,
BMASKDWORD, 0xf9000000);
1564 rtl_set_bbreg(hw, 0xe48,
BMASKDWORD, 0xf8000000);
1567 "Delay %d ms for One shot, path A LOK & IQK\n",
1571 regeac = rtl_get_bbreg(hw, 0xeac,
BMASKDWORD);
1572 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"0xeac = 0x%x\n", regeac);
1573 rege94 = rtl_get_bbreg(hw, 0xe94,
BMASKDWORD);
1574 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"0xe94 = 0x%x\n", rege94);
1575 rege9c = rtl_get_bbreg(hw, 0xe9c,
BMASKDWORD);
1576 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"0xe9c = 0x%x\n", rege9c);
1577 regea4 = rtl_get_bbreg(hw, 0xea4,
BMASKDWORD);
1578 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"0xea4 = 0x%x\n", regea4);
1579 if (!(regeac &
BIT(28)) && (((rege94 & 0x03FF0000) >> 16) != 0x142) &&
1580 (((rege9c & 0x03FF0000) >> 16) != 0x42))
1585 if (!(regeac &
BIT(27)) && (((regea4 & 0x03FF0000) >> 16) != 0x132) &&
1586 (((regeac & 0x03FF0000) >> 16) != 0x36))
1589 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"Path A Rx IQK fail!!\n");
1594 static u8 _rtl92d_phy_patha_iqk_5g_normal(
struct ieee80211_hw *hw,
1600 u32 regeac, rege94, rege9c, regea4;
1604 u32 TxOKBit =
BIT(28), RxOKBit =
BIT(27);
1613 rtl_set_bbreg(hw, 0xe30,
BMASKDWORD, 0x18008c1f);
1614 rtl_set_bbreg(hw, 0xe34,
BMASKDWORD, 0x18008c1f);
1615 rtl_set_bbreg(hw, 0xe38,
BMASKDWORD, 0x82140307);
1616 rtl_set_bbreg(hw, 0xe3c,
BMASKDWORD, 0x68160960);
1619 rtl_set_bbreg(hw, 0xe50,
BMASKDWORD, 0x18008c2f);
1620 rtl_set_bbreg(hw, 0xe54,
BMASKDWORD, 0x18008c2f);
1621 rtl_set_bbreg(hw, 0xe58,
BMASKDWORD, 0x82110000);
1622 rtl_set_bbreg(hw, 0xe5c,
BMASKDWORD, 0x68110000);
1625 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"LO calibration setting!\n");
1626 rtl_set_bbreg(hw, 0xe4c,
BMASKDWORD, 0x00462911);
1630 for (i = 0; i < retrycount; i++) {
1633 "One shot, path A LOK & IQK!\n");
1634 rtl_set_bbreg(hw, 0xe48,
BMASKDWORD, 0xf9000000);
1635 rtl_set_bbreg(hw, 0xe48,
BMASKDWORD, 0xf8000000);
1638 "Delay %d ms for One shot, path A LOK & IQK.\n",
1642 regeac = rtl_get_bbreg(hw, 0xeac,
BMASKDWORD);
1643 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"0xeac = 0x%x\n", regeac);
1644 rege94 = rtl_get_bbreg(hw, 0xe94,
BMASKDWORD);
1645 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"0xe94 = 0x%x\n", rege94);
1646 rege9c = rtl_get_bbreg(hw, 0xe9c,
BMASKDWORD);
1647 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"0xe9c = 0x%x\n", rege9c);
1648 regea4 = rtl_get_bbreg(hw, 0xea4,
BMASKDWORD);
1649 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"0xea4 = 0x%x\n", regea4);
1650 if (!(regeac & TxOKBit) &&
1651 (((rege94 & 0x03FF0000) >> 16) != 0x142)) {
1655 "Path A Tx IQK fail!!\n");
1660 if (!(regeac & RxOKBit) &&
1661 (((regea4 & 0x03FF0000) >> 16) != 0x132)) {
1666 "Path A Rx IQK fail!!\n");
1681 u32 regeac, regeb4, regebc, regec4, regecc;
1686 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"One shot, path A LOK & IQK!\n");
1687 rtl_set_bbreg(hw, 0xe60,
BMASKDWORD, 0x00000002);
1688 rtl_set_bbreg(hw, 0xe60,
BMASKDWORD, 0x00000000);
1694 regeac = rtl_get_bbreg(hw, 0xeac,
BMASKDWORD);
1695 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"0xeac = 0x%x\n", regeac);
1696 regeb4 = rtl_get_bbreg(hw, 0xeb4,
BMASKDWORD);
1697 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"0xeb4 = 0x%x\n", regeb4);
1698 regebc = rtl_get_bbreg(hw, 0xebc,
BMASKDWORD);
1699 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"0xebc = 0x%x\n", regebc);
1700 regec4 = rtl_get_bbreg(hw, 0xec4,
BMASKDWORD);
1701 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"0xec4 = 0x%x\n", regec4);
1702 regecc = rtl_get_bbreg(hw, 0xecc,
BMASKDWORD);
1703 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"0xecc = 0x%x\n", regecc);
1704 if (!(regeac &
BIT(31)) && (((regeb4 & 0x03FF0000) >> 16) != 0x142) &&
1705 (((regebc & 0x03FF0000) >> 16) != 0x42))
1709 if (!(regeac &
BIT(30)) && (((regec4 & 0x03FF0000) >> 16) != 0x132) &&
1710 (((regecc & 0x03FF0000) >> 16) != 0x36))
1713 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"Path B Rx IQK fail!!\n");
1718 static u8 _rtl92d_phy_pathb_iqk_5g_normal(
struct ieee80211_hw *hw)
1722 u32 regeac, regeb4, regebc, regec4, regecc;
1730 rtl_set_bbreg(hw, 0xe30,
BMASKDWORD, 0x18008c1f);
1731 rtl_set_bbreg(hw, 0xe34,
BMASKDWORD, 0x18008c1f);
1732 rtl_set_bbreg(hw, 0xe38,
BMASKDWORD, 0x82110000);
1733 rtl_set_bbreg(hw, 0xe3c,
BMASKDWORD, 0x68110000);
1736 rtl_set_bbreg(hw, 0xe50,
BMASKDWORD, 0x18008c2f);
1737 rtl_set_bbreg(hw, 0xe54,
BMASKDWORD, 0x18008c2f);
1738 rtl_set_bbreg(hw, 0xe58,
BMASKDWORD, 0x82140307);
1739 rtl_set_bbreg(hw, 0xe5c,
BMASKDWORD, 0x68160960);
1742 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"LO calibration setting!\n");
1743 rtl_set_bbreg(hw, 0xe4c,
BMASKDWORD, 0x00462911);
1749 for (i = 0; i < retrycount; i++) {
1752 "One shot, path A LOK & IQK!\n");
1753 rtl_set_bbreg(hw, 0xe48,
BMASKDWORD, 0xfa000000);
1754 rtl_set_bbreg(hw, 0xe48,
BMASKDWORD, 0xf8000000);
1758 "Delay %d ms for One shot, path B LOK & IQK.\n", 10);
1762 regeac = rtl_get_bbreg(hw, 0xeac,
BMASKDWORD);
1763 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"0xeac = 0x%x\n", regeac);
1764 regeb4 = rtl_get_bbreg(hw, 0xeb4,
BMASKDWORD);
1765 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"0xeb4 = 0x%x\n", regeb4);
1766 regebc = rtl_get_bbreg(hw, 0xebc,
BMASKDWORD);
1767 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"0xebc = 0x%x\n", regebc);
1768 regec4 = rtl_get_bbreg(hw, 0xec4,
BMASKDWORD);
1769 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"0xec4 = 0x%x\n", regec4);
1770 regecc = rtl_get_bbreg(hw, 0xecc,
BMASKDWORD);
1771 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"0xecc = 0x%x\n", regecc);
1772 if (!(regeac &
BIT(31)) &&
1773 (((regeb4 & 0x03FF0000) >> 16) != 0x142))
1777 if (!(regeac &
BIT(30)) &&
1778 (((regec4 & 0x03FF0000) >> 16) != 0x132)) {
1783 "Path B Rx IQK fail!!\n");
1795 static void _rtl92d_phy_save_adda_registers(
struct ieee80211_hw *hw,
1802 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"Save ADDA parameters.\n");
1803 for (i = 0; i < regnum; i++)
1804 adda_backup[i] = rtl_get_bbreg(hw, adda_reg[i],
BMASKDWORD);
1807 static void _rtl92d_phy_save_mac_registers(
struct ieee80211_hw *hw,
1808 u32 *macreg,
u32 *macbackup)
1813 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"Save MAC parameters.\n");
1815 macbackup[i] = rtl_read_byte(rtlpriv, macreg[i]);
1816 macbackup[
i] = rtl_read_dword(rtlpriv, macreg[i]);
1819 static void _rtl92d_phy_reload_adda_registers(
struct ieee80211_hw *hw,
1820 u32 *adda_reg,
u32 *adda_backup,
1827 "Reload ADDA power saving parameters !\n");
1828 for (i = 0; i < regnum; i++)
1829 rtl_set_bbreg(hw, adda_reg[i],
BMASKDWORD, adda_backup[i]);
1832 static void _rtl92d_phy_reload_mac_registers(
struct ieee80211_hw *hw,
1833 u32 *macreg,
u32 *macbackup)
1838 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"Reload MAC parameters !\n");
1840 rtl_write_byte(rtlpriv, macreg[i], (
u8) macbackup[
i]);
1841 rtl_write_byte(rtlpriv, macreg[i], macbackup[i]);
1844 static void _rtl92d_phy_path_adda_on(
struct ieee80211_hw *hw,
1845 u32 *adda_reg,
bool patha_on,
bool is2t)
1852 pathon = patha_on ? 0x04db25a4 : 0x0b1b25a4;
1854 pathon = rtlpriv->
rtlhal.interfaceindex == 0 ?
1855 0x04db25a4 : 0x0b1b25a4;
1857 rtl_set_bbreg(hw, adda_reg[i],
BMASKDWORD, pathon);
1860 static void _rtl92d_phy_mac_setting_calibration(
struct ieee80211_hw *hw,
1861 u32 *macreg,
u32 *macbackup)
1866 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"MAC settings for Calibration.\n");
1867 rtl_write_byte(rtlpriv, macreg[0], 0x3F);
1870 rtl_write_byte(rtlpriv, macreg[i], (
u8)(macbackup[
i] &
1872 rtl_write_byte(rtlpriv, macreg[i], (
u8) (macbackup[i] & (~
BIT(5))));
1875 static void _rtl92d_phy_patha_standby(
struct ieee80211_hw *hw)
1878 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"Path-A standby mode!\n");
1882 rtl_set_bbreg(hw, 0xe28,
BMASKDWORD, 0x80800000);
1885 static void _rtl92d_phy_pimode_switch(
struct ieee80211_hw *hw,
bool pi_mode)
1891 "BB Switch to %s mode!\n", pi_mode ?
"PI" :
"SI");
1892 mode = pi_mode ? 0x01000100 : 0x01000000;
1897 static void _rtl92d_phy_iq_calibrate(
struct ieee80211_hw *hw,
long result[][8],
1903 u8 patha_ok, pathb_ok;
1906 0xe78, 0xe7c, 0xe80, 0xe84,
1907 0xe88, 0xe8c, 0xed0, 0xed4,
1908 0xed8, 0xedc, 0xee0, 0xeec
1911 0x522, 0x550, 0x551, 0x040
1920 const u32 retrycount = 2;
1923 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"IQK for 2.4G :Start!!!\n");
1927 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"IQ Calibration for %s\n",
1928 is2t ?
"2T2R" :
"1T1R");
1931 _rtl92d_phy_save_adda_registers(hw, adda_reg,
1933 _rtl92d_phy_save_mac_registers(hw, iqk_mac_reg,
1935 _rtl92d_phy_save_adda_registers(hw, iqk_bb_reg,
1938 _rtl92d_phy_path_adda_on(hw, adda_reg,
true, is2t);
1945 _rtl92d_phy_pimode_switch(hw,
true);
1959 _rtl92d_phy_mac_setting_calibration(hw, iqk_mac_reg,
1962 rtl_set_bbreg(hw, 0xb68,
BMASKDWORD, 0x0f600000);
1964 rtl_set_bbreg(hw, 0xb6c,
BMASKDWORD, 0x0f600000);
1967 rtl_set_bbreg(hw, 0xe28,
BMASKDWORD, 0x80800000);
1968 rtl_set_bbreg(hw, 0xe40,
BMASKDWORD, 0x01007c00);
1969 rtl_set_bbreg(hw, 0xe44,
BMASKDWORD, 0x01004800);
1970 for (i = 0; i < retrycount; i++) {
1971 patha_ok = _rtl92d_phy_patha_iqk(hw, is2t);
1972 if (patha_ok == 0x03) {
1974 "Path A IQK Success!!\n");
1975 result[
t][0] = (rtl_get_bbreg(hw, 0xe94,
BMASKDWORD) &
1977 result[
t][1] = (rtl_get_bbreg(hw, 0xe9c,
BMASKDWORD) &
1979 result[
t][2] = (rtl_get_bbreg(hw, 0xea4,
BMASKDWORD) &
1981 result[
t][3] = (rtl_get_bbreg(hw, 0xeac,
BMASKDWORD) &
1984 }
else if (i == (retrycount - 1) && patha_ok == 0x01) {
1987 "Path A IQK Only Tx Success!!\n");
1989 result[
t][0] = (rtl_get_bbreg(hw, 0xe94,
BMASKDWORD) &
1991 result[
t][1] = (rtl_get_bbreg(hw, 0xe9c,
BMASKDWORD) &
1995 if (0x00 == patha_ok)
1998 _rtl92d_phy_patha_standby(hw);
2000 _rtl92d_phy_path_adda_on(hw, adda_reg,
false, is2t);
2001 for (i = 0; i < retrycount; i++) {
2002 pathb_ok = _rtl92d_phy_pathb_iqk(hw);
2003 if (pathb_ok == 0x03) {
2005 "Path B IQK Success!!\n");
2006 result[
t][4] = (rtl_get_bbreg(hw, 0xeb4,
2008 result[
t][5] = (rtl_get_bbreg(hw, 0xebc,
2010 result[
t][6] = (rtl_get_bbreg(hw, 0xec4,
2012 result[
t][7] = (rtl_get_bbreg(hw, 0xecc,
2015 }
else if (i == (retrycount - 1) && pathb_ok == 0x01) {
2018 "Path B Only Tx IQK Success!!\n");
2019 result[
t][4] = (rtl_get_bbreg(hw, 0xeb4,
2021 result[
t][5] = (rtl_get_bbreg(hw, 0xebc,
2025 if (0x00 == pathb_ok)
2027 "Path B IQK failed!!\n");
2032 "IQK:Back to BB mode, load original value!\n");
2038 _rtl92d_phy_pimode_switch(hw,
false);
2040 _rtl92d_phy_reload_adda_registers(hw, adda_reg,
2043 _rtl92d_phy_reload_mac_registers(hw, iqk_mac_reg,
2046 _rtl92d_phy_reload_adda_registers(hw, iqk_bb_reg,
2050 _rtl92d_phy_reload_adda_registers(hw, iqk_bb_reg,
2054 rtl_set_bbreg(hw, 0xe30,
BMASKDWORD, 0x01008c00);
2055 rtl_set_bbreg(hw, 0xe34,
BMASKDWORD, 0x01008c00);
2060 static void _rtl92d_phy_iq_calibrate_5g_normal(
struct ieee80211_hw *hw,
2061 long result[][8],
u8 t)
2066 u8 patha_ok, pathb_ok;
2069 0xe78, 0xe7c, 0xe80, 0xe84,
2070 0xe88, 0xe8c, 0xed0, 0xed4,
2071 0xed8, 0xedc, 0xee0, 0xeec
2074 0x522, 0x550, 0x551, 0x040
2089 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"IQK for 5G NORMAL:Start!!!\n");
2094 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"IQ Calibration for %s\n",
2095 is2t ?
"2T2R" :
"1T1R");
2097 _rtl92d_phy_save_adda_registers(hw, adda_reg,
2100 _rtl92d_phy_save_mac_registers(hw, iqk_mac_reg,
2103 _rtl92d_phy_save_adda_registers(hw, iqk_bb_reg,
2107 _rtl92d_phy_save_adda_registers(hw, iqk_bb_reg,
2111 _rtl92d_phy_path_adda_on(hw, adda_reg,
true, is2t);
2113 _rtl92d_phy_mac_setting_calibration(hw, iqk_mac_reg,
2120 _rtl92d_phy_pimode_switch(hw,
true);
2128 rtl_set_bbreg(hw, 0xb68,
BMASKDWORD, 0x0f600000);
2130 rtl_set_bbreg(hw, 0xb6c,
BMASKDWORD, 0x0f600000);
2133 rtl_set_bbreg(hw, 0xe28,
BMASKDWORD, 0x80800000);
2134 rtl_set_bbreg(hw, 0xe40,
BMASKDWORD, 0x10007c00);
2135 rtl_set_bbreg(hw, 0xe44,
BMASKDWORD, 0x01004800);
2136 patha_ok = _rtl92d_phy_patha_iqk_5g_normal(hw, is2t);
2137 if (patha_ok == 0x03) {
2138 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"Path A IQK Success!!\n");
2139 result[
t][0] = (rtl_get_bbreg(hw, 0xe94,
BMASKDWORD) &
2141 result[
t][1] = (rtl_get_bbreg(hw, 0xe9c,
BMASKDWORD) &
2143 result[
t][2] = (rtl_get_bbreg(hw, 0xea4,
BMASKDWORD) &
2145 result[
t][3] = (rtl_get_bbreg(hw, 0xeac,
BMASKDWORD) &
2147 }
else if (patha_ok == 0x01) {
2149 "Path A IQK Only Tx Success!!\n");
2151 result[
t][0] = (rtl_get_bbreg(hw, 0xe94,
BMASKDWORD) &
2153 result[
t][1] = (rtl_get_bbreg(hw, 0xe9c,
BMASKDWORD) &
2161 _rtl92d_phy_path_adda_on(hw, adda_reg,
false, is2t);
2162 pathb_ok = _rtl92d_phy_pathb_iqk_5g_normal(hw);
2163 if (pathb_ok == 0x03) {
2165 "Path B IQK Success!!\n");
2166 result[
t][4] = (rtl_get_bbreg(hw, 0xeb4,
BMASKDWORD) &
2168 result[
t][5] = (rtl_get_bbreg(hw, 0xebc,
BMASKDWORD) &
2170 result[
t][6] = (rtl_get_bbreg(hw, 0xec4,
BMASKDWORD) &
2172 result[
t][7] = (rtl_get_bbreg(hw, 0xecc,
BMASKDWORD) &
2174 }
else if (pathb_ok == 0x01) {
2176 "Path B Only Tx IQK Success!!\n");
2177 result[
t][4] = (rtl_get_bbreg(hw, 0xeb4,
BMASKDWORD) &
2179 result[
t][5] = (rtl_get_bbreg(hw, 0xebc,
BMASKDWORD) &
2183 "Path B IQK failed!!\n");
2189 "IQK:Back to BB mode, load original value!\n");
2193 _rtl92d_phy_reload_adda_registers(hw, iqk_bb_reg,
2197 _rtl92d_phy_reload_adda_registers(hw, iqk_bb_reg,
2201 _rtl92d_phy_reload_mac_registers(hw, iqk_mac_reg,
2205 _rtl92d_phy_pimode_switch(hw,
false);
2207 _rtl92d_phy_reload_adda_registers(hw, adda_reg,
2214 static bool _rtl92d_phy_simularity_compare(
struct ieee80211_hw *hw,
2215 long result[][8],
u8 c1,
u8 c2)
2219 u32 i,
j, diff, sim_bitmap, bound;
2220 u8 final_candidate[2] = {0xFF, 0xFF};
2221 bool bresult =
true;
2229 for (i = 0; i < bound; i++) {
2230 diff = (result[c1][
i] > result[c2][
i]) ? (result[c1][i] -
2231 result[c2][i]) : (result[c2][
i] - result[c1][
i]);
2233 if ((i == 2 || i == 6) && !sim_bitmap) {
2234 if (result[c1][i] + result[c1][i + 1] == 0)
2235 final_candidate[(i / 4)] = c2;
2236 else if (result[c2][i] + result[c2][i + 1] == 0)
2237 final_candidate[(i / 4)] = c1;
2239 sim_bitmap = sim_bitmap | (1 <<
i);
2241 sim_bitmap = sim_bitmap | (1 <<
i);
2245 if (sim_bitmap == 0) {
2246 for (i = 0; i < (bound / 4); i++) {
2247 if (final_candidate[i] != 0xFF) {
2248 for (j = i * 4; j < (i + 1) * 4 - 2; j++)
2250 result[final_candidate[i]][j];
2256 if (!(sim_bitmap & 0x0F)) {
2257 for (i = 0; i < 4; i++)
2258 result[3][i] = result[c1][i];
2259 }
else if (!(sim_bitmap & 0x03)) {
2260 for (i = 0; i < 2; i++)
2261 result[3][i] = result[c1][i];
2263 if (!(sim_bitmap & 0xF0) && is2t) {
2264 for (i = 4; i < 8; i++)
2265 result[3][i] = result[c1][i];
2266 }
else if (!(sim_bitmap & 0x30)) {
2267 for (i = 4; i < 6; i++)
2268 result[3][i] = result[c1][i];
2273 static void _rtl92d_phy_patha_fill_iqk_matrix(
struct ieee80211_hw *hw,
2274 bool iqk_ok,
long result[][8],
2275 u8 final_candidate,
bool txonly)
2279 u32 oldval_0, val_x, tx0_a,
reg;
2285 "Path A IQ Calibration %s !\n", iqk_ok ?
"Success" :
"Failed");
2286 if (final_candidate == 0xFF) {
2288 }
else if (iqk_ok) {
2291 val_x = result[final_candidate][0];
2292 if ((val_x & 0x00000200) != 0)
2293 val_x = val_x | 0xFFFFFC00;
2294 tx0_a = (val_x * oldval_0) >> 8;
2296 "X = 0x%x, tx0_a = 0x%x, oldval_0 0x%x\n",
2297 val_x, tx0_a, oldval_0);
2300 ((val_x * oldval_0 >> 7) & 0x1));
2301 val_y = result[final_candidate][1];
2302 if ((val_y & 0x00000200) != 0)
2303 val_y = val_y | 0xFFFFFC00;
2308 tx0_c = (val_y * oldval_0) >> 8;
2310 "Y = 0x%lx, tx0_c = 0x%lx\n",
2313 ((tx0_c & 0x3C0) >> 6));
2318 ((val_y * oldval_0 >> 7) & 0x1));
2326 reg = result[final_candidate][2];
2328 reg = result[final_candidate][3] & 0x3F;
2330 reg = (result[final_candidate][3] >> 6) & 0xF;
2331 rtl_set_bbreg(hw, 0xca0, 0xF0000000, reg);
2335 static void _rtl92d_phy_pathb_fill_iqk_matrix(
struct ieee80211_hw *hw,
2336 bool iqk_ok,
long result[][8],
u8 final_candidate,
bool txonly)
2340 u32 oldval_1, val_x, tx1_a,
reg;
2343 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"Path B IQ Calibration %s !\n",
2344 iqk_ok ?
"Success" :
"Failed");
2345 if (final_candidate == 0xFF) {
2347 }
else if (iqk_ok) {
2350 val_x = result[final_candidate][4];
2351 if ((val_x & 0x00000200) != 0)
2352 val_x = val_x | 0xFFFFFC00;
2353 tx1_a = (val_x * oldval_1) >> 8;
2354 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"X = 0x%x, tx1_a = 0x%x\n",
2358 ((val_x * oldval_1 >> 7) & 0x1));
2359 val_y = result[final_candidate][5];
2360 if ((val_y & 0x00000200) != 0)
2361 val_y = val_y | 0xFFFFFC00;
2364 tx1_c = (val_y * oldval_1) >> 8;
2365 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"Y = 0x%lx, tx1_c = 0x%lx\n",
2368 ((tx1_c & 0x3C0) >> 6));
2372 ((val_y * oldval_1 >> 7) & 0x1));
2375 reg = result[final_candidate][6];
2377 reg = result[final_candidate][7] & 0x3F;
2379 reg = (result[final_candidate][7] >> 6) & 0xF;
2390 u8 i, final_candidate, indexforchannel;
2391 bool patha_ok, pathb_ok;
2392 long rege94, rege9c, regea4, regeac, regeb4;
2393 long regebc, regec4, regecc, regtmp = 0;
2394 bool is12simular, is13simular, is23simular;
2395 unsigned long flag = 0;
2399 for (i = 0; i < 8; i++) {
2405 final_candidate = 0xff;
2408 is12simular =
false;
2409 is23simular =
false;
2410 is13simular =
false;
2413 rtl92d_acquire_cckandrw_pagea_ctl(hw, &flag);
2414 for (i = 0; i < 3; i++) {
2416 _rtl92d_phy_iq_calibrate_5g_normal(hw, result, i);
2419 _rtl92d_phy_iq_calibrate(hw, result, i,
true);
2421 _rtl92d_phy_iq_calibrate(hw, result, i,
false);
2424 is12simular = _rtl92d_phy_simularity_compare(hw, result,
2427 final_candidate = 0;
2432 is13simular = _rtl92d_phy_simularity_compare(hw, result,
2435 final_candidate = 0;
2438 is23simular = _rtl92d_phy_simularity_compare(hw, result,
2441 final_candidate = 1;
2443 for (i = 0; i < 8; i++)
2444 regtmp += result[3][i];
2447 final_candidate = 3;
2449 final_candidate = 0xFF;
2453 rtl92d_release_cckandrw_pagea_ctl(hw, &flag);
2454 for (i = 0; i < 4; i++) {
2455 rege94 = result[
i][0];
2456 rege9c = result[
i][1];
2457 regea4 = result[
i][2];
2458 regeac = result[
i][3];
2459 regeb4 = result[
i][4];
2460 regebc = result[
i][5];
2461 regec4 = result[
i][6];
2462 regecc = result[
i][7];
2464 "IQK: rege94=%lx rege9c=%lx regea4=%lx regeac=%lx regeb4=%lx regebc=%lx regec4=%lx regecc=%lx\n",
2465 rege94, rege9c, regea4, regeac, regeb4, regebc, regec4,
2468 if (final_candidate != 0xff) {
2469 rtlphy->
reg_e94 = rege94 = result[final_candidate][0];
2470 rtlphy->
reg_e9c = rege9c = result[final_candidate][1];
2471 regea4 = result[final_candidate][2];
2472 regeac = result[final_candidate][3];
2473 rtlphy->
reg_eb4 = regeb4 = result[final_candidate][4];
2474 rtlphy->
reg_ebc = regebc = result[final_candidate][5];
2475 regec4 = result[final_candidate][6];
2476 regecc = result[final_candidate][7];
2478 "IQK: final_candidate is %x\n", final_candidate);
2480 "IQK: rege94=%lx rege9c=%lx regea4=%lx regeac=%lx regeb4=%lx regebc=%lx regec4=%lx regecc=%lx\n",
2481 rege94, rege9c, regea4, regeac, regeb4, regebc, regec4,
2483 patha_ok = pathb_ok =
true;
2489 _rtl92d_phy_patha_fill_iqk_matrix(hw, patha_ok, result,
2490 final_candidate, (regea4 == 0));
2493 _rtl92d_phy_pathb_fill_iqk_matrix(hw, pathb_ok, result,
2494 final_candidate, (regec4 == 0));
2496 if (final_candidate != 0xFF) {
2502 value[0][i] = result[final_candidate][i];
2507 "IQK OK indexforchannel %d\n", indexforchannel);
2528 "Do IQK Matrix reg for channel:%d....\n", channel);
2534 indexforchannel == 0) || indexforchannel > 0) {
2536 "Just Read IQK Matrix reg for channel:%d....\n",
2541 _rtl92d_phy_patha_fill_iqk_matrix(hw,
true,
2543 indexforchannel].value, 0,
2545 indexforchannel].value[0][2] == 0));
2548 indexforchannel].value[0][4] != 0)
2550 _rtl92d_phy_pathb_fill_iqk_matrix(hw,
2553 indexforchannel].value, 0,
2555 indexforchannel].value[0][6]
2564 static u32 _rtl92d_phy_get_abs(
u32 val1,
u32 val2)
2575 static bool _rtl92d_is_legal_5g_channel(
struct ieee80211_hw *hw,
u8 channel)
2579 u8 channel_5g[45] = {
2580 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58,
2581 60, 62, 64, 100, 102, 104, 106, 108, 110, 112,
2582 114, 116, 118, 120, 122, 124, 126, 128, 130, 132,
2583 134, 136, 138, 140, 149, 151, 153, 155, 157, 159,
2587 for (i = 0; i <
sizeof(channel_5g); i++)
2588 if (channel == channel_5g[i])
2593 static void _rtl92d_phy_calc_curvindex(
struct ieee80211_hw *hw,
2594 u32 *targetchnl,
u32 * curvecount_val,
2595 bool is5g,
u32 *curveindex)
2598 u32 smallest_abs_val = 0xffffffff, u4tmp;
2602 for (i = 0; i < chnl_num; i++) {
2603 if (is5g && !_rtl92d_is_legal_5g_channel(hw, i + 1))
2607 u4tmp = _rtl92d_phy_get_abs(targetchnl[i],
2610 if (u4tmp < smallest_abs_val) {
2612 smallest_abs_val = u4tmp;
2615 smallest_abs_val = 0xffffffff;
2621 static void _rtl92d_phy_reload_lck_setting(
struct ieee80211_hw *hw,
2625 u8 erfpath = rtlpriv->
rtlhal.current_bandtype ==
2629 u32 u4tmp = 0, u4regvalue = 0;
2630 bool bneed_powerdown_radio =
false;
2634 rtlpriv->
rtlhal.current_bandtype);
2635 RTPRINT(rtlpriv,
FINIT,
INIT_IQK,
"channel = %d\n", channel);
2637 u4tmp = curveindex_5g[channel-1];
2639 "ver 1 set RF-A, 5G, 0x28 = 0x%ulx !!\n", u4tmp);
2641 rtlpriv->
rtlhal.interfaceindex == 1) {
2642 bneed_powerdown_radio =
2644 rtlpriv->
rtlhal.during_mac1init_radioa =
true;
2646 if (bneed_powerdown_radio)
2647 _rtl92d_phy_enable_rf_env(hw, erfpath,
2650 rtl_set_rfreg(hw, erfpath,
RF_SYN_G4, 0x3f800, u4tmp);
2651 if (bneed_powerdown_radio)
2652 _rtl92d_phy_restore_rf_env(hw, erfpath, &u4regvalue);
2653 if (rtlpriv->
rtlhal.during_mac1init_radioa)
2656 u4tmp = curveindex_2g[channel-1];
2658 "ver 3 set RF-B, 2G, 0x28 = 0x%ulx !!\n", u4tmp);
2660 rtlpriv->
rtlhal.interfaceindex == 0) {
2661 bneed_powerdown_radio =
2663 rtlpriv->
rtlhal.during_mac0init_radiob =
true;
2664 if (bneed_powerdown_radio)
2665 _rtl92d_phy_enable_rf_env(hw, erfpath,
2668 rtl_set_rfreg(hw, erfpath,
RF_SYN_G4, 0x3f800, u4tmp);
2670 "ver 3 set RF-B, 2G, 0x28 = 0x%ulx !!\n",
2671 rtl_get_rfreg(hw, erfpath,
RF_SYN_G4, 0x3f800));
2672 if (bneed_powerdown_radio)
2673 _rtl92d_phy_restore_rf_env(hw, erfpath, &u4regvalue);
2674 if (rtlpriv->
rtlhal.during_mac0init_radiob)
2680 static void _rtl92d_phy_lc_calibrate_sw(
struct ieee80211_hw *hw,
bool is2t)
2686 u8 path = is2t ? 2 : 1;
2693 tmpreg = rtl_read_byte(rtlpriv, 0xd03);
2696 if ((tmpreg & 0x70) != 0)
2697 rtl_write_byte(rtlpriv, 0xd03, tmpreg & 0x8F);
2701 for (index = 0; index <
path; index++) {
2704 rf_mode[
index] = rtl_read_byte(rtlpriv, offset);
2718 while ((!(u4tmp &
BIT(11))) && timecount <= timeout) {
2721 u4tmp = rtl_get_rfreg(hw, (
enum radio_path)index,
2725 "PHY_LCK finish delay for %d ms=2\n", timecount);
2729 "path-A / 5G LCK\n");
2732 "path-B / 2.4G LCK\n");
2741 u32 readval = 0, readval2 = 0;
2742 rtl_set_rfreg(hw, (
enum radio_path)index, 0x3F,
2745 rtl_set_rfreg(hw, (
enum radio_path)index, 0x4D,
2747 readval = rtl_get_rfreg(hw, (
enum radio_path)index,
2749 curvecount_val[2 * i + 1] = (readval & 0xfffe0) >> 5;
2752 readval2 = rtl_get_rfreg(hw, (
enum radio_path)index,
2754 curvecount_val[2 *
i] = (((readval & 0x1F) << 10) |
2758 _rtl92d_phy_calc_curvindex(hw, targetchnl_5g,
2760 true, curveindex_5g);
2762 _rtl92d_phy_calc_curvindex(hw, targetchnl_2g,
2764 false, curveindex_2g);
2771 for (index = 0; index <
path; index++) {
2773 rtl_write_byte(rtlpriv, offset, 0x50);
2774 rtl_write_byte(rtlpriv, offset, rf_mode[index]);
2776 if ((tmpreg & 0x70) != 0)
2777 rtl_write_byte(rtlpriv, 0xd03, tmpreg);
2781 _rtl92d_phy_reload_lck_setting(hw, rtlpriv->
phy.current_channel);
2784 static void _rtl92d_phy_lc_calibrate(
struct ieee80211_hw *hw,
bool is2t)
2789 _rtl92d_phy_lc_calibrate_sw(hw, is2t);
2797 u32 timeout = 2000, timecount = 0;
2799 while (rtlpriv->
mac80211.act_scanning && timecount < timeout) {
2806 "LCK:Start!!! currentband %x delay %d ms\n",
2809 _rtl92d_phy_lc_calibrate(hw,
true);
2812 _rtl92d_phy_lc_calibrate(hw,
false);
2823 static bool _rtl92d_phy_set_sw_chnl_cmdarray(
struct swchnlcmd *cmdtable,
2829 if (cmdtable ==
NULL) {
2830 RT_ASSERT(
false,
"cmdtable cannot be NULL\n");
2833 if (cmdtableidx >= cmdtablesz)
2836 pcmd = cmdtable + cmdtableidx;
2851 "settings regs %d default regs %d\n",
2869 static bool _rtl92d_phy_sw_chnl_step_by_step(
struct ieee80211_hw *hw,
2876 u32 precommoncmdcnt;
2878 u32 postcommoncmdcnt;
2885 precommoncmdcnt = 0;
2886 _rtl92d_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++,
2889 _rtl92d_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++,
2891 postcommoncmdcnt = 0;
2892 _rtl92d_phy_set_sw_chnl_cmdarray(postcommoncmd, postcommoncmdcnt++,
2895 _rtl92d_phy_set_sw_chnl_cmdarray(rfdependcmd, rfdependcmdcnt++,
2898 _rtl92d_phy_set_sw_chnl_cmdarray(rfdependcmd, rfdependcmdcnt++,
2905 currentcmd = &precommoncmd[*
step];
2908 currentcmd = &rfdependcmd[*
step];
2911 currentcmd = &postcommoncmd[*
step];
2915 if ((*stage) == 2) {
2923 switch (currentcmd->
cmdid) {
2928 rtl_write_dword(rtlpriv, currentcmd->
para1,
2932 rtl_write_word(rtlpriv, currentcmd->
para1,
2936 rtl_write_byte(rtlpriv, currentcmd->
para1,
2940 for (rfpath = 0; rfpath < num_total_rfpath; rfpath++) {
2943 0xffffff00) | currentcmd->
para2);
2944 if (rtlpriv->
rtlhal.current_bandtype ==
2946 if (currentcmd->
para2 > 99)
2949 [rfpath] | (
BIT(18));
2953 [rfpath] & (~
BIT(18));
2964 _rtl92d_phy_reload_imr_setting(hw, channel,
2967 _rtl92d_phy_switch_rf_setting(hw, channel);
2973 "switch case not processed\n");
2978 (*delay) = currentcmd->
msdelay;
2989 u32 timeout = 1000, timecount = 0;
3000 "sw_chnl_inprogress false driver sleep or unload\n");
3012 rtl92d_phy_switch_wirelessband(hw,
BAND_ON_5G);
3022 RT_ASSERT((channel > 14),
"5G but channel<=14\n");
3029 RT_ASSERT((channel <= 14),
"2G but channel>14\n");
3032 RT_ASSERT(
false,
"Invalid WirelessMode(%#x)!!\n",
3047 if (!_rtl92d_phy_sw_chnl_step_by_step(hw,
3071 "--->Cmd(%#x), set_io_inprogress(%d)\n",
3086 "switch case not processed\n");
3098 bool postprocessing =
false;
3101 "-->IO Cmd(%#x), set_io_inprogress(%d)\n",
3107 "[IO CMD] Resume DM after scan\n");
3108 postprocessing =
true;
3112 "[IO CMD] Pause DM before scan\n");
3113 postprocessing =
true;
3117 "switch case not processed\n");
3127 rtl92d_phy_set_io(hw);
3132 static void _rtl92d_phy_set_rfon(
struct ieee80211_hw *hw)
3153 static void _rtl92d_phy_set_rfsleep(
struct ieee80211_hw *hw)
3171 while (u4btmp != 0 && delay > 0) {
3186 "Fail !!! Switch RF timeout\n");
3201 bool bresult =
true;
3212 switch (rfpwr_state) {
3217 u32 InitializeCount = 0;
3221 "IPS Set eRf nic enable\n");
3223 }
while (!rtstatus && (InitializeCount < 10));
3229 "awake, sleeped:%d ms state_inap:%x\n",
3232 rtlpriv->
psc.state_inap);
3234 _rtl92d_phy_set_rfon(hw);
3238 rtlpriv->
cfg->ops->led_control(hw,
3241 rtlpriv->
cfg->ops->led_control(hw,
3247 "IPS Set eRf nic disable\n");
3252 rtlpriv->
cfg->ops->led_control(hw,
3255 rtlpriv->
cfg->ops->led_control(hw,
3263 for (queue_id = 0, i = 0;
3265 ring = &pcipriv->
dev.tx_ring[queue_id];
3266 if (skb_queue_len(&ring->
queue) == 0 ||
3270 }
else if (rtlpci->
pdev->current_state !=
PCI_D0) {
3272 "eRf Off/Sleep: %d times TcbBusyQueue[%d] !=0 but lower power state!\n",
3277 "eRf Off/Sleep: %d times TcbBusyQueue[%d] =%d before doze!\n",
3279 skb_queue_len(&ring->
queue));
3286 "ERFOFF: %d times TcbBusyQueue[%d] = %d !\n",
3288 skb_queue_len(&ring->
queue));
3293 "Set rfsleep awaked:%d ms\n",
3296 "sleep awaked:%d ms state_inap:%x\n",
3299 rtlpriv->
psc.state_inap);
3301 _rtl92d_phy_set_rfsleep(hw);
3305 "switch case not processed\n");
3323 "MacPhyMode: DUALMAC_DUALPHY\n");
3324 rtl_write_byte(rtlpriv, offset, 0xF3);
3328 "MacPhyMode: SINGLEMAC_SINGLEPHY\n");
3329 rtl_write_byte(rtlpriv, offset, 0xF4);
3333 "MacPhyMode: DUALMAC_SINGLEPHY\n");
3334 rtl_write_byte(rtlpriv, offset, 0xF1);
3381 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
3382 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56,
3383 58, 60, 62, 64, 100, 102, 104, 106, 108,
3384 110, 112, 114, 116, 118, 120, 122, 124,
3385 126, 128, 130, 132, 134, 136, 138, 140,
3386 149, 151, 153, 155, 157, 159, 161, 163,
3390 if (channel_info[chnl] <= 3)
3392 else if (channel_info[chnl] <= 9)
3394 else if (channel_info[chnl] <= 14)
3396 else if (channel_info[chnl] <= 44)
3398 else if (channel_info[chnl] <= 54)
3400 else if (channel_info[chnl] <= 64)
3402 else if (channel_info[chnl] <= 112)
3404 else if (channel_info[chnl] <= 126)
3406 else if (channel_info[chnl] <= 140)
3408 else if (channel_info[chnl] <= 153)
3410 else if (channel_info[chnl] <= 159)
3421 unsigned long flags;
3428 value8 = rtl_read_byte(rtlpriv, mac_reg);
3430 rtl_write_byte(rtlpriv, mac_reg, value8);
3432 value8 = rtl_read_byte(rtlpriv, mac_reg);
3433 value8 &= (~
BIT(1));
3434 rtl_write_byte(rtlpriv, mac_reg, value8);
3438 value8 = rtl_read_byte(rtlpriv,
REG_MAC0);
3443 value8 = rtl_read_byte(rtlpriv,
REG_MAC0);
3446 value8 = rtl_read_byte(rtlpriv,
REG_MAC1);
3451 for (i = 0; i < 200; i++) {
3452 if ((value8 &
BIT(7)) == 0) {
3457 value8 = rtl_read_byte(rtlpriv,
3464 RT_ASSERT(
false,
"Another mac power off over time\n");
3472 switch (rtlpriv->
rtlhal.macphymode) {
3474 rtl_write_byte(rtlpriv,
REG_DMC, 0x0);
3479 rtl_write_byte(rtlpriv,
REG_DMC, 0xf8);
3484 rtl_write_byte(rtlpriv,
REG_DMC, 0x0);
3516 rtl_set_bbreg(hw, 0xB30, 0x00F00000, 0xa);
3571 rtl_set_bbreg(hw, 0xB30, 0x00F00000, 0x0);
3614 BIT(26) |
BIT(24), 0x00);
3616 rtl_set_bbreg(hw, 0xca0, 0xF0000000, 0x00);
3627 rtl_set_rfreg(hw, (
enum radio_path)rfpath, 0x0B,
3633 (
BIT(16) |
BIT(8)) >> 8);
3650 "MAC1 use DBI to update 0x888\n");
3671 rtlphy->
reg_rf3c[rfpath] = rtl_get_rfreg(hw, rfpath, 0x3C,
3674 for (i = 0; i < 2; i++)
3686 unsigned long flags;
3689 u1btmp = rtl_read_byte(rtlpriv,
REG_MAC0);
3695 u1btmp = rtl_read_byte(rtlpriv,
REG_MAC0);
3697 u1btmp = rtl_read_byte(rtlpriv,
REG_MAC1);
3700 u1btmp = rtl_read_byte(rtlpriv,
REG_MAC1);
3702 u1btmp = rtl_read_byte(rtlpriv,
REG_MAC0);