1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2012 Realtek Corporation.*/
17 #define MAX_RF_IMR_INDEX 12
18 #define MAX_RF_IMR_INDEX_NORMAL 13
19 #define RF_REG_NUM_FOR_C_CUT_5G 6
20 #define RF_REG_NUM_FOR_C_CUT_5G_INTERNALPA 7
21 #define RF_REG_NUM_FOR_C_CUT_2G 5
22 #define RF_CHNL_NUM_5G 19
23 #define RF_CHNL_NUM_5G_40M 17
24 #define TARGET_CHNL_NUM_5G 221
25 #define TARGET_CHNL_NUM_2G 14
26 #define CV_CURVE_CNT 64
28 static u32 rf_reg_for_5g_swchnl_normal
[MAX_RF_IMR_INDEX_NORMAL
] = {
29 0, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x0
32 static u8 rf_reg_for_c_cut_5g
[RF_REG_NUM_FOR_C_CUT_5G
] = {
33 RF_SYN_G1
, RF_SYN_G2
, RF_SYN_G3
, RF_SYN_G4
, RF_SYN_G5
, RF_SYN_G6
36 static u8 rf_reg_for_c_cut_2g
[RF_REG_NUM_FOR_C_CUT_2G
] = {
37 RF_SYN_G1
, RF_SYN_G2
, RF_SYN_G3
, RF_SYN_G7
, RF_SYN_G8
40 static u8 rf_for_c_cut_5g_internal_pa
[RF_REG_NUM_FOR_C_CUT_5G_INTERNALPA
] = {
41 0x0B, 0x48, 0x49, 0x4B, 0x03, 0x04, 0x0E
44 static u32 rf_reg_mask_for_c_cut_2g
[RF_REG_NUM_FOR_C_CUT_2G
] = {
45 BIT(19) | BIT(18) | BIT(17) | BIT(14) | BIT(1),
47 BIT(18) | BIT(17) | BIT(16) | BIT(1),
49 BIT(15) | BIT(14) | BIT(13) | BIT(12) | BIT(11)
52 static u8 rf_chnl_5g
[RF_CHNL_NUM_5G
] = {
53 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108,
54 112, 116, 120, 124, 128, 132, 136, 140
57 static u8 rf_chnl_5g_40m
[RF_CHNL_NUM_5G_40M
] = {
58 38, 42, 46, 50, 54, 58, 62, 102, 106, 110, 114,
59 118, 122, 126, 130, 134, 138
61 static u32 rf_reg_pram_c_5g
[5][RF_REG_NUM_FOR_C_CUT_5G
] = {
62 {0xE43BE, 0xFC638, 0x77C0A, 0xDE471, 0xd7110, 0x8EB04},
63 {0xE43BE, 0xFC078, 0xF7C1A, 0xE0C71, 0xD7550, 0xAEB04},
64 {0xE43BF, 0xFF038, 0xF7C0A, 0xDE471, 0xE5550, 0xAEB04},
65 {0xE43BF, 0xFF079, 0xF7C1A, 0xDE471, 0xE5550, 0xAEB04},
66 {0xE43BF, 0xFF038, 0xF7C1A, 0xDE471, 0xd7550, 0xAEB04}
69 static u32 rf_reg_param_for_c_cut_2g
[3][RF_REG_NUM_FOR_C_CUT_2G
] = {
70 {0x643BC, 0xFC038, 0x77C1A, 0x41289, 0x01840},
71 {0x643BC, 0xFC038, 0x07C1A, 0x41289, 0x01840},
72 {0x243BC, 0xFC438, 0x07C1A, 0x4128B, 0x0FC41}
75 static u32 rf_syn_g4_for_c_cut_2g
= 0xD1C31 & 0x7FF;
77 static u32 rf_pram_c_5g_int_pa
[3][RF_REG_NUM_FOR_C_CUT_5G_INTERNALPA
] = {
78 {0x01a00, 0x40443, 0x00eb5, 0x89bec, 0x94a12, 0x94a12, 0x94a12},
79 {0x01800, 0xc0443, 0x00730, 0x896ee, 0x94a52, 0x94a52, 0x94a52},
80 {0x01800, 0xc0443, 0x00730, 0x896ee, 0x94a12, 0x94a12, 0x94a12}
83 /* [mode][patha+b][reg] */
84 static u32 rf_imr_param_normal
[1][3][MAX_RF_IMR_INDEX_NORMAL
] = {
88 0x70000, 0x00ff0, 0x4400f, 0x00ff0, 0x0, 0x0, 0x0,
89 0x0, 0x0, 0x64888, 0xe266c, 0x00090, 0x22fff
93 0x70000, 0x22880, 0x4470f, 0x55880, 0x00070, 0x88000,
94 0x0, 0x88080, 0x70000, 0x64a82, 0xe466c, 0x00090,
99 0x70000, 0x44880, 0x4477f, 0x77880, 0x00070, 0x88000,
100 0x0, 0x880b0, 0x0, 0x64b82, 0xe466c, 0x00090, 0x32c9a
105 static u32 curveindex_5g
[TARGET_CHNL_NUM_5G
] = {0};
107 static u32 curveindex_2g
[TARGET_CHNL_NUM_2G
] = {0};
109 static u32 targetchnl_5g
[TARGET_CHNL_NUM_5G
] = {
110 25141, 25116, 25091, 25066, 25041,
111 25016, 24991, 24966, 24941, 24917,
112 24892, 24867, 24843, 24818, 24794,
113 24770, 24765, 24721, 24697, 24672,
114 24648, 24624, 24600, 24576, 24552,
115 24528, 24504, 24480, 24457, 24433,
116 24409, 24385, 24362, 24338, 24315,
117 24291, 24268, 24245, 24221, 24198,
118 24175, 24151, 24128, 24105, 24082,
119 24059, 24036, 24013, 23990, 23967,
120 23945, 23922, 23899, 23876, 23854,
121 23831, 23809, 23786, 23764, 23741,
122 23719, 23697, 23674, 23652, 23630,
123 23608, 23586, 23564, 23541, 23519,
124 23498, 23476, 23454, 23432, 23410,
125 23388, 23367, 23345, 23323, 23302,
126 23280, 23259, 23237, 23216, 23194,
127 23173, 23152, 23130, 23109, 23088,
128 23067, 23046, 23025, 23003, 22982,
129 22962, 22941, 22920, 22899, 22878,
130 22857, 22837, 22816, 22795, 22775,
131 22754, 22733, 22713, 22692, 22672,
132 22652, 22631, 22611, 22591, 22570,
133 22550, 22530, 22510, 22490, 22469,
134 22449, 22429, 22409, 22390, 22370,
135 22350, 22336, 22310, 22290, 22271,
136 22251, 22231, 22212, 22192, 22173,
137 22153, 22134, 22114, 22095, 22075,
138 22056, 22037, 22017, 21998, 21979,
139 21960, 21941, 21921, 21902, 21883,
140 21864, 21845, 21826, 21807, 21789,
141 21770, 21751, 21732, 21713, 21695,
142 21676, 21657, 21639, 21620, 21602,
143 21583, 21565, 21546, 21528, 21509,
144 21491, 21473, 21454, 21436, 21418,
145 21400, 21381, 21363, 21345, 21327,
146 21309, 21291, 21273, 21255, 21237,
147 21219, 21201, 21183, 21166, 21148,
148 21130, 21112, 21095, 21077, 21059,
149 21042, 21024, 21007, 20989, 20972,
150 25679, 25653, 25627, 25601, 25575,
151 25549, 25523, 25497, 25471, 25446,
152 25420, 25394, 25369, 25343, 25318,
153 25292, 25267, 25242, 25216, 25191,
158 static u32 targetchnl_2g
[TARGET_CHNL_NUM_2G
] = {
159 26084, 26030, 25976, 25923, 25869, 25816, 25764,
160 25711, 25658, 25606, 25554, 25502, 25451, 25328
163 static u32
_rtl92d_phy_calculate_bit_shift(u32 bitmask
)
167 for (i
= 0; i
<= 31; i
++) {
168 if (((bitmask
>> i
) & 0x1) == 1)
175 u32
rtl92d_phy_query_bb_reg(struct ieee80211_hw
*hw
, u32 regaddr
, u32 bitmask
)
177 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
178 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
179 u32 returnvalue
, originalvalue
, bitshift
;
181 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
, "regaddr(%#x), bitmask(%#x)\n",
183 if (rtlhal
->during_mac1init_radioa
|| rtlhal
->during_mac0init_radiob
) {
186 /* mac1 use phy0 read radio_b. */
187 /* mac0 use phy1 read radio_b. */
188 if (rtlhal
->during_mac1init_radioa
)
190 else if (rtlhal
->during_mac0init_radiob
)
191 dbi_direct
= BIT(3) | BIT(2);
192 originalvalue
= rtl92de_read_dword_dbi(hw
, (u16
)regaddr
,
195 originalvalue
= rtl_read_dword(rtlpriv
, regaddr
);
197 bitshift
= _rtl92d_phy_calculate_bit_shift(bitmask
);
198 returnvalue
= (originalvalue
& bitmask
) >> bitshift
;
199 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
200 "BBR MASK=0x%x Addr[0x%x]=0x%x\n",
201 bitmask
, regaddr
, originalvalue
);
205 void rtl92d_phy_set_bb_reg(struct ieee80211_hw
*hw
,
206 u32 regaddr
, u32 bitmask
, u32 data
)
208 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
209 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
211 u32 originalvalue
, bitshift
;
213 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
214 "regaddr(%#x), bitmask(%#x), data(%#x)\n",
215 regaddr
, bitmask
, data
);
216 if (rtlhal
->during_mac1init_radioa
)
218 else if (rtlhal
->during_mac0init_radiob
)
219 /* mac0 use phy1 write radio_b. */
220 dbi_direct
= BIT(3) | BIT(2);
221 if (bitmask
!= MASKDWORD
) {
222 if (rtlhal
->during_mac1init_radioa
||
223 rtlhal
->during_mac0init_radiob
)
224 originalvalue
= rtl92de_read_dword_dbi(hw
,
228 originalvalue
= rtl_read_dword(rtlpriv
, regaddr
);
229 bitshift
= _rtl92d_phy_calculate_bit_shift(bitmask
);
230 data
= ((originalvalue
& (~bitmask
)) | (data
<< bitshift
));
232 if (rtlhal
->during_mac1init_radioa
|| rtlhal
->during_mac0init_radiob
)
233 rtl92de_write_dword_dbi(hw
, (u16
) regaddr
, data
, dbi_direct
);
235 rtl_write_dword(rtlpriv
, regaddr
, data
);
236 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
237 "regaddr(%#x), bitmask(%#x), data(%#x)\n",
238 regaddr
, bitmask
, data
);
241 static u32
_rtl92d_phy_rf_serial_read(struct ieee80211_hw
*hw
,
242 enum radio_path rfpath
, u32 offset
)
245 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
246 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
247 struct bb_reg_def
*pphyreg
= &rtlphy
->phyreg_def
[rfpath
];
249 u32 tmplong
, tmplong2
;
254 tmplong
= rtl_get_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER2
, MASKDWORD
);
255 if (rfpath
== RF90_PATH_A
)
258 tmplong2
= rtl_get_bbreg(hw
, pphyreg
->rfhssi_para2
, MASKDWORD
);
259 tmplong2
= (tmplong2
& (~BLSSIREADADDRESS
)) |
260 (newoffset
<< 23) | BLSSIREADEDGE
;
261 rtl_set_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER2
, MASKDWORD
,
262 tmplong
& (~BLSSIREADEDGE
));
264 rtl_set_bbreg(hw
, pphyreg
->rfhssi_para2
, MASKDWORD
, tmplong2
);
267 rtl_set_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER2
, MASKDWORD
,
268 tmplong
| BLSSIREADEDGE
);
270 if (rfpath
== RF90_PATH_A
)
271 rfpi_enable
= (u8
) rtl_get_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER1
,
273 else if (rfpath
== RF90_PATH_B
)
274 rfpi_enable
= (u8
) rtl_get_bbreg(hw
, RFPGA0_XB_HSSIPARAMETER1
,
277 retvalue
= rtl_get_bbreg(hw
, pphyreg
->rf_rbpi
,
280 retvalue
= rtl_get_bbreg(hw
, pphyreg
->rf_rb
,
282 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
, "RFR-%d Addr[0x%x] = 0x%x\n",
283 rfpath
, pphyreg
->rf_rb
, retvalue
);
287 static void _rtl92d_phy_rf_serial_write(struct ieee80211_hw
*hw
,
288 enum radio_path rfpath
,
289 u32 offset
, u32 data
)
293 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
294 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
295 struct bb_reg_def
*pphyreg
= &rtlphy
->phyreg_def
[rfpath
];
299 data_and_addr
= ((newoffset
<< 20) | (data
& 0x000fffff)) & 0x0fffffff;
300 rtl_set_bbreg(hw
, pphyreg
->rf3wire_offset
, MASKDWORD
, data_and_addr
);
301 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
, "RFW-%d Addr[0x%x]=0x%x\n",
302 rfpath
, pphyreg
->rf3wire_offset
, data_and_addr
);
305 u32
rtl92d_phy_query_rf_reg(struct ieee80211_hw
*hw
,
306 enum radio_path rfpath
, u32 regaddr
, u32 bitmask
)
308 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
309 u32 original_value
, readback_value
, bitshift
;
311 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
312 "regaddr(%#x), rfpath(%#x), bitmask(%#x)\n",
313 regaddr
, rfpath
, bitmask
);
314 spin_lock(&rtlpriv
->locks
.rf_lock
);
315 original_value
= _rtl92d_phy_rf_serial_read(hw
, rfpath
, regaddr
);
316 bitshift
= _rtl92d_phy_calculate_bit_shift(bitmask
);
317 readback_value
= (original_value
& bitmask
) >> bitshift
;
318 spin_unlock(&rtlpriv
->locks
.rf_lock
);
319 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
320 "regaddr(%#x), rfpath(%#x), bitmask(%#x), original_value(%#x)\n",
321 regaddr
, rfpath
, bitmask
, original_value
);
322 return readback_value
;
325 void rtl92d_phy_set_rf_reg(struct ieee80211_hw
*hw
, enum radio_path rfpath
,
326 u32 regaddr
, u32 bitmask
, u32 data
)
328 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
329 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
330 u32 original_value
, bitshift
;
332 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
333 "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
334 regaddr
, bitmask
, data
, rfpath
);
337 spin_lock(&rtlpriv
->locks
.rf_lock
);
338 if (rtlphy
->rf_mode
!= RF_OP_BY_FW
) {
339 if (bitmask
!= RFREG_OFFSET_MASK
) {
340 original_value
= _rtl92d_phy_rf_serial_read(hw
,
342 bitshift
= _rtl92d_phy_calculate_bit_shift(bitmask
);
343 data
= ((original_value
& (~bitmask
)) |
346 _rtl92d_phy_rf_serial_write(hw
, rfpath
, regaddr
, data
);
348 spin_unlock(&rtlpriv
->locks
.rf_lock
);
349 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
350 "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
351 regaddr
, bitmask
, data
, rfpath
);
354 bool rtl92d_phy_mac_config(struct ieee80211_hw
*hw
)
356 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
361 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
, "Read Rtl819XMACPHY_Array\n");
362 arraylength
= MAC_2T_ARRAYLENGTH
;
363 ptrarray
= rtl8192de_mac_2tarray
;
364 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
, "Img:Rtl819XMAC_Array\n");
365 for (i
= 0; i
< arraylength
; i
= i
+ 2)
366 rtl_write_byte(rtlpriv
, ptrarray
[i
], (u8
) ptrarray
[i
+ 1]);
367 if (rtlpriv
->rtlhal
.macphymode
== SINGLEMAC_SINGLEPHY
) {
368 /* improve 2-stream TX EVM */
369 /* rtl_write_byte(rtlpriv, 0x14,0x71); */
370 /* AMPDU aggregation number 9 */
371 /* rtl_write_word(rtlpriv, REG_MAX_AGGR_NUM, MAX_AGGR_NUM); */
372 rtl_write_byte(rtlpriv
, REG_MAX_AGGR_NUM
, 0x0B);
374 /* 92D need to test to decide the num. */
375 rtl_write_byte(rtlpriv
, REG_MAX_AGGR_NUM
, 0x07);
380 static void _rtl92d_phy_init_bb_rf_register_definition(struct ieee80211_hw
*hw
)
382 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
383 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
385 /* RF Interface Sowrtware Control */
386 /* 16 LSBs if read 32-bit from 0x870 */
387 rtlphy
->phyreg_def
[RF90_PATH_A
].rfintfs
= RFPGA0_XAB_RFINTERFACESW
;
388 /* 16 MSBs if read 32-bit from 0x870 (16-bit for 0x872) */
389 rtlphy
->phyreg_def
[RF90_PATH_B
].rfintfs
= RFPGA0_XAB_RFINTERFACESW
;
390 /* 16 LSBs if read 32-bit from 0x874 */
391 rtlphy
->phyreg_def
[RF90_PATH_C
].rfintfs
= RFPGA0_XCD_RFINTERFACESW
;
392 /* 16 MSBs if read 32-bit from 0x874 (16-bit for 0x876) */
394 rtlphy
->phyreg_def
[RF90_PATH_D
].rfintfs
= RFPGA0_XCD_RFINTERFACESW
;
395 /* RF Interface Readback Value */
396 /* 16 LSBs if read 32-bit from 0x8E0 */
397 rtlphy
->phyreg_def
[RF90_PATH_A
].rfintfi
= RFPGA0_XAB_RFINTERFACERB
;
398 /* 16 MSBs if read 32-bit from 0x8E0 (16-bit for 0x8E2) */
399 rtlphy
->phyreg_def
[RF90_PATH_B
].rfintfi
= RFPGA0_XAB_RFINTERFACERB
;
400 /* 16 LSBs if read 32-bit from 0x8E4 */
401 rtlphy
->phyreg_def
[RF90_PATH_C
].rfintfi
= RFPGA0_XCD_RFINTERFACERB
;
402 /* 16 MSBs if read 32-bit from 0x8E4 (16-bit for 0x8E6) */
403 rtlphy
->phyreg_def
[RF90_PATH_D
].rfintfi
= RFPGA0_XCD_RFINTERFACERB
;
405 /* RF Interface Output (and Enable) */
406 /* 16 LSBs if read 32-bit from 0x860 */
407 rtlphy
->phyreg_def
[RF90_PATH_A
].rfintfo
= RFPGA0_XA_RFINTERFACEOE
;
408 /* 16 LSBs if read 32-bit from 0x864 */
409 rtlphy
->phyreg_def
[RF90_PATH_B
].rfintfo
= RFPGA0_XB_RFINTERFACEOE
;
411 /* RF Interface (Output and) Enable */
412 /* 16 MSBs if read 32-bit from 0x860 (16-bit for 0x862) */
413 rtlphy
->phyreg_def
[RF90_PATH_A
].rfintfe
= RFPGA0_XA_RFINTERFACEOE
;
414 /* 16 MSBs if read 32-bit from 0x864 (16-bit for 0x866) */
415 rtlphy
->phyreg_def
[RF90_PATH_B
].rfintfe
= RFPGA0_XB_RFINTERFACEOE
;
417 /* Addr of LSSI. Wirte RF register by driver */
419 rtlphy
->phyreg_def
[RF90_PATH_A
].rf3wire_offset
=
420 RFPGA0_XA_LSSIPARAMETER
;
421 rtlphy
->phyreg_def
[RF90_PATH_B
].rf3wire_offset
=
422 RFPGA0_XB_LSSIPARAMETER
;
426 rtlphy
->phyreg_def
[RF90_PATH_A
].rflssi_select
= RFPGA0_XAB_RFPARAMETER
;
427 rtlphy
->phyreg_def
[RF90_PATH_B
].rflssi_select
= RFPGA0_XAB_RFPARAMETER
;
428 rtlphy
->phyreg_def
[RF90_PATH_C
].rflssi_select
= RFPGA0_XCD_RFPARAMETER
;
429 rtlphy
->phyreg_def
[RF90_PATH_D
].rflssi_select
= RFPGA0_XCD_RFPARAMETER
;
431 /* Tx AGC Gain Stage (same for all path. Should we remove this?) */
433 rtlphy
->phyreg_def
[RF90_PATH_A
].rftxgain_stage
= RFPGA0_TXGAINSTAGE
;
435 rtlphy
->phyreg_def
[RF90_PATH_B
].rftxgain_stage
= RFPGA0_TXGAINSTAGE
;
437 rtlphy
->phyreg_def
[RF90_PATH_C
].rftxgain_stage
= RFPGA0_TXGAINSTAGE
;
439 rtlphy
->phyreg_def
[RF90_PATH_D
].rftxgain_stage
= RFPGA0_TXGAINSTAGE
;
441 /* Tranceiver A~D HSSI Parameter-1 */
442 /* wire control parameter1 */
443 rtlphy
->phyreg_def
[RF90_PATH_A
].rfhssi_para1
= RFPGA0_XA_HSSIPARAMETER1
;
444 /* wire control parameter1 */
445 rtlphy
->phyreg_def
[RF90_PATH_B
].rfhssi_para1
= RFPGA0_XB_HSSIPARAMETER1
;
447 /* Tranceiver A~D HSSI Parameter-2 */
448 /* wire control parameter2 */
449 rtlphy
->phyreg_def
[RF90_PATH_A
].rfhssi_para2
= RFPGA0_XA_HSSIPARAMETER2
;
450 /* wire control parameter2 */
451 rtlphy
->phyreg_def
[RF90_PATH_B
].rfhssi_para2
= RFPGA0_XB_HSSIPARAMETER2
;
453 /* RF switch Control */
454 /* TR/Ant switch control */
455 rtlphy
->phyreg_def
[RF90_PATH_A
].rfsw_ctrl
= RFPGA0_XAB_SWITCHCONTROL
;
456 rtlphy
->phyreg_def
[RF90_PATH_B
].rfsw_ctrl
= RFPGA0_XAB_SWITCHCONTROL
;
457 rtlphy
->phyreg_def
[RF90_PATH_C
].rfsw_ctrl
= RFPGA0_XCD_SWITCHCONTROL
;
458 rtlphy
->phyreg_def
[RF90_PATH_D
].rfsw_ctrl
= RFPGA0_XCD_SWITCHCONTROL
;
461 rtlphy
->phyreg_def
[RF90_PATH_A
].rfagc_control1
= ROFDM0_XAAGCCORE1
;
462 rtlphy
->phyreg_def
[RF90_PATH_B
].rfagc_control1
= ROFDM0_XBAGCCORE1
;
463 rtlphy
->phyreg_def
[RF90_PATH_C
].rfagc_control1
= ROFDM0_XCAGCCORE1
;
464 rtlphy
->phyreg_def
[RF90_PATH_D
].rfagc_control1
= ROFDM0_XDAGCCORE1
;
467 rtlphy
->phyreg_def
[RF90_PATH_A
].rfagc_control2
= ROFDM0_XAAGCCORE2
;
468 rtlphy
->phyreg_def
[RF90_PATH_B
].rfagc_control2
= ROFDM0_XBAGCCORE2
;
469 rtlphy
->phyreg_def
[RF90_PATH_C
].rfagc_control2
= ROFDM0_XCAGCCORE2
;
470 rtlphy
->phyreg_def
[RF90_PATH_D
].rfagc_control2
= ROFDM0_XDAGCCORE2
;
472 /* RX AFE control 1 */
473 rtlphy
->phyreg_def
[RF90_PATH_A
].rfrxiq_imbal
= ROFDM0_XARXIQIMBALANCE
;
474 rtlphy
->phyreg_def
[RF90_PATH_B
].rfrxiq_imbal
= ROFDM0_XBRXIQIMBALANCE
;
475 rtlphy
->phyreg_def
[RF90_PATH_C
].rfrxiq_imbal
= ROFDM0_XCRXIQIMBALANCE
;
476 rtlphy
->phyreg_def
[RF90_PATH_D
].rfrxiq_imbal
= ROFDM0_XDRXIQIMBALANCE
;
478 /*RX AFE control 1 */
479 rtlphy
->phyreg_def
[RF90_PATH_A
].rfrx_afe
= ROFDM0_XARXAFE
;
480 rtlphy
->phyreg_def
[RF90_PATH_B
].rfrx_afe
= ROFDM0_XBRXAFE
;
481 rtlphy
->phyreg_def
[RF90_PATH_C
].rfrx_afe
= ROFDM0_XCRXAFE
;
482 rtlphy
->phyreg_def
[RF90_PATH_D
].rfrx_afe
= ROFDM0_XDRXAFE
;
484 /* Tx AFE control 1 */
485 rtlphy
->phyreg_def
[RF90_PATH_A
].rftxiq_imbal
= ROFDM0_XATXIQIMBALANCE
;
486 rtlphy
->phyreg_def
[RF90_PATH_B
].rftxiq_imbal
= ROFDM0_XBTXIQIMBALANCE
;
487 rtlphy
->phyreg_def
[RF90_PATH_C
].rftxiq_imbal
= ROFDM0_XCTXIQIMBALANCE
;
488 rtlphy
->phyreg_def
[RF90_PATH_D
].rftxiq_imbal
= ROFDM0_XDTXIQIMBALANCE
;
490 /* Tx AFE control 2 */
491 rtlphy
->phyreg_def
[RF90_PATH_A
].rftx_afe
= ROFDM0_XATXAFE
;
492 rtlphy
->phyreg_def
[RF90_PATH_B
].rftx_afe
= ROFDM0_XBTXAFE
;
493 rtlphy
->phyreg_def
[RF90_PATH_C
].rftx_afe
= ROFDM0_XCTXAFE
;
494 rtlphy
->phyreg_def
[RF90_PATH_D
].rftx_afe
= ROFDM0_XDTXAFE
;
496 /* Tranceiver LSSI Readback SI mode */
497 rtlphy
->phyreg_def
[RF90_PATH_A
].rf_rb
= RFPGA0_XA_LSSIREADBACK
;
498 rtlphy
->phyreg_def
[RF90_PATH_B
].rf_rb
= RFPGA0_XB_LSSIREADBACK
;
499 rtlphy
->phyreg_def
[RF90_PATH_C
].rf_rb
= RFPGA0_XC_LSSIREADBACK
;
500 rtlphy
->phyreg_def
[RF90_PATH_D
].rf_rb
= RFPGA0_XD_LSSIREADBACK
;
502 /* Tranceiver LSSI Readback PI mode */
503 rtlphy
->phyreg_def
[RF90_PATH_A
].rf_rbpi
= TRANSCEIVERA_HSPI_READBACK
;
504 rtlphy
->phyreg_def
[RF90_PATH_B
].rf_rbpi
= TRANSCEIVERB_HSPI_READBACK
;
507 static bool _rtl92d_phy_config_bb_with_headerfile(struct ieee80211_hw
*hw
,
511 u32
*phy_regarray_table
;
512 u32
*agctab_array_table
= NULL
;
513 u32
*agctab_5garray_table
;
514 u16 phy_reg_arraylen
, agctab_arraylen
= 0, agctab_5garraylen
;
515 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
516 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
518 /* Normal chip,Mac0 use AGC_TAB.txt for 2G and 5G band. */
519 if (rtlhal
->interfaceindex
== 0) {
520 agctab_arraylen
= AGCTAB_ARRAYLENGTH
;
521 agctab_array_table
= rtl8192de_agctab_array
;
522 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
523 " ===> phy:MAC0, Rtl819XAGCTAB_Array\n");
525 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
526 agctab_arraylen
= AGCTAB_2G_ARRAYLENGTH
;
527 agctab_array_table
= rtl8192de_agctab_2garray
;
528 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
529 " ===> phy:MAC1, Rtl819XAGCTAB_2GArray\n");
531 agctab_5garraylen
= AGCTAB_5G_ARRAYLENGTH
;
532 agctab_5garray_table
= rtl8192de_agctab_5garray
;
533 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
534 " ===> phy:MAC1, Rtl819XAGCTAB_5GArray\n");
538 phy_reg_arraylen
= PHY_REG_2T_ARRAYLENGTH
;
539 phy_regarray_table
= rtl8192de_phy_reg_2tarray
;
540 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
541 " ===> phy:Rtl819XPHY_REG_Array_PG\n");
542 if (configtype
== BASEBAND_CONFIG_PHY_REG
) {
543 for (i
= 0; i
< phy_reg_arraylen
; i
= i
+ 2) {
544 rtl_addr_delay(phy_regarray_table
[i
]);
545 rtl_set_bbreg(hw
, phy_regarray_table
[i
], MASKDWORD
,
546 phy_regarray_table
[i
+ 1]);
548 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
549 "The phy_regarray_table[0] is %x Rtl819XPHY_REGArray[1] is %x\n",
550 phy_regarray_table
[i
],
551 phy_regarray_table
[i
+ 1]);
553 } else if (configtype
== BASEBAND_CONFIG_AGC_TAB
) {
554 if (rtlhal
->interfaceindex
== 0) {
555 for (i
= 0; i
< agctab_arraylen
; i
= i
+ 2) {
556 rtl_set_bbreg(hw
, agctab_array_table
[i
],
558 agctab_array_table
[i
+ 1]);
559 /* Add 1us delay between BB/RF register
562 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
563 "The Rtl819XAGCTAB_Array_Table[0] is %u Rtl819XPHY_REGArray[1] is %u\n",
564 agctab_array_table
[i
],
565 agctab_array_table
[i
+ 1]);
567 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
568 "Normal Chip, MAC0, load Rtl819XAGCTAB_Array\n");
570 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
571 for (i
= 0; i
< agctab_arraylen
; i
= i
+ 2) {
572 rtl_set_bbreg(hw
, agctab_array_table
[i
],
574 agctab_array_table
[i
+ 1]);
575 /* Add 1us delay between BB/RF register
578 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
579 "The Rtl819XAGCTAB_Array_Table[0] is %u Rtl819XPHY_REGArray[1] is %u\n",
580 agctab_array_table
[i
],
581 agctab_array_table
[i
+ 1]);
583 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
584 "Load Rtl819XAGCTAB_2GArray\n");
586 for (i
= 0; i
< agctab_5garraylen
; i
= i
+ 2) {
588 agctab_5garray_table
[i
],
590 agctab_5garray_table
[i
+ 1]);
591 /* Add 1us delay between BB/RF registeri
594 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
595 "The Rtl819XAGCTAB_5GArray_Table[0] is %u Rtl819XPHY_REGArray[1] is %u\n",
596 agctab_5garray_table
[i
],
597 agctab_5garray_table
[i
+ 1]);
599 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
600 "Load Rtl819XAGCTAB_5GArray\n");
607 static void _rtl92d_store_pwrindex_diffrate_offset(struct ieee80211_hw
*hw
,
608 u32 regaddr
, u32 bitmask
,
611 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
612 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
615 if (regaddr
== RTXAGC_A_RATE18_06
)
617 else if (regaddr
== RTXAGC_A_RATE54_24
)
619 else if (regaddr
== RTXAGC_A_CCK1_MCS32
)
621 else if (regaddr
== RTXAGC_B_CCK11_A_CCK2_11
&& bitmask
== 0xffffff00)
623 else if (regaddr
== RTXAGC_A_MCS03_MCS00
)
625 else if (regaddr
== RTXAGC_A_MCS07_MCS04
)
627 else if (regaddr
== RTXAGC_A_MCS11_MCS08
)
629 else if (regaddr
== RTXAGC_A_MCS15_MCS12
)
631 else if (regaddr
== RTXAGC_B_RATE18_06
)
633 else if (regaddr
== RTXAGC_B_RATE54_24
)
635 else if (regaddr
== RTXAGC_B_CCK1_55_MCS32
)
637 else if (regaddr
== RTXAGC_B_CCK11_A_CCK2_11
&& bitmask
== 0x000000ff)
639 else if (regaddr
== RTXAGC_B_MCS03_MCS00
)
641 else if (regaddr
== RTXAGC_B_MCS07_MCS04
)
643 else if (regaddr
== RTXAGC_B_MCS11_MCS08
)
645 else if (regaddr
== RTXAGC_B_MCS15_MCS12
)
650 rtlphy
->mcs_offset
[rtlphy
->pwrgroup_cnt
][index
] = data
;
651 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
652 "MCSTxPowerLevelOriginalOffset[%d][%d] = 0x%x\n",
653 rtlphy
->pwrgroup_cnt
, index
,
654 rtlphy
->mcs_offset
[rtlphy
->pwrgroup_cnt
][index
]);
656 rtlphy
->pwrgroup_cnt
++;
659 static bool _rtl92d_phy_config_bb_with_pgheaderfile(struct ieee80211_hw
*hw
,
662 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
664 u32
*phy_regarray_table_pg
;
665 u16 phy_regarray_pg_len
;
667 phy_regarray_pg_len
= PHY_REG_ARRAY_PG_LENGTH
;
668 phy_regarray_table_pg
= rtl8192de_phy_reg_array_pg
;
669 if (configtype
== BASEBAND_CONFIG_PHY_REG
) {
670 for (i
= 0; i
< phy_regarray_pg_len
; i
= i
+ 3) {
671 rtl_addr_delay(phy_regarray_table_pg
[i
]);
672 _rtl92d_store_pwrindex_diffrate_offset(hw
,
673 phy_regarray_table_pg
[i
],
674 phy_regarray_table_pg
[i
+ 1],
675 phy_regarray_table_pg
[i
+ 2]);
678 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
679 "configtype != BaseBand_Config_PHY_REG\n");
684 static bool _rtl92d_phy_bb_config(struct ieee80211_hw
*hw
)
686 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
687 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
688 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
689 bool rtstatus
= true;
691 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
, "==>\n");
692 rtstatus
= _rtl92d_phy_config_bb_with_headerfile(hw
,
693 BASEBAND_CONFIG_PHY_REG
);
695 pr_err("Write BB Reg Fail!!\n");
699 /* if (rtlphy->rf_type == RF_1T2R) {
700 * _rtl92c_phy_bb_config_1t(hw);
701 * RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "Config to 1T!!\n");
704 if (rtlefuse
->autoload_failflag
== false) {
705 rtlphy
->pwrgroup_cnt
= 0;
706 rtstatus
= _rtl92d_phy_config_bb_with_pgheaderfile(hw
,
707 BASEBAND_CONFIG_PHY_REG
);
710 pr_err("BB_PG Reg Fail!!\n");
713 rtstatus
= _rtl92d_phy_config_bb_with_headerfile(hw
,
714 BASEBAND_CONFIG_AGC_TAB
);
716 pr_err("AGC Table Fail\n");
719 rtlphy
->cck_high_power
= (bool) (rtl_get_bbreg(hw
,
720 RFPGA0_XA_HSSIPARAMETER2
, 0x200));
725 bool rtl92d_phy_bb_config(struct ieee80211_hw
*hw
)
727 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
732 _rtl92d_phy_init_bb_rf_register_definition(hw
);
733 regval
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
);
734 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
,
735 regval
| BIT(13) | BIT(0) | BIT(1));
736 rtl_write_byte(rtlpriv
, REG_AFE_PLL_CTRL
, 0x83);
737 rtl_write_byte(rtlpriv
, REG_AFE_PLL_CTRL
+ 1, 0xdb);
738 /* 0x1f bit7 bit6 represent for mac0/mac1 driver ready */
739 value
= rtl_read_byte(rtlpriv
, REG_RF_CTRL
);
740 rtl_write_byte(rtlpriv
, REG_RF_CTRL
, value
| RF_EN
| RF_RSTB
|
742 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, FEN_PPLL
| FEN_PCIEA
|
743 FEN_DIO_PCIE
| FEN_BB_GLB_RSTN
| FEN_BBRSTB
);
744 rtl_write_byte(rtlpriv
, REG_AFE_XTAL_CTRL
+ 1, 0x80);
745 if (!(IS_92D_SINGLEPHY(rtlpriv
->rtlhal
.version
))) {
746 regvaldw
= rtl_read_dword(rtlpriv
, REG_LEDCFG0
);
747 rtl_write_dword(rtlpriv
, REG_LEDCFG0
, regvaldw
| BIT(23));
750 return _rtl92d_phy_bb_config(hw
);
753 bool rtl92d_phy_rf_config(struct ieee80211_hw
*hw
)
755 return rtl92d_phy_rf6052_config(hw
);
758 bool rtl92d_phy_config_rf_with_headerfile(struct ieee80211_hw
*hw
,
759 enum rf_content content
,
760 enum radio_path rfpath
)
763 u32
*radioa_array_table
;
764 u32
*radiob_array_table
;
765 u16 radioa_arraylen
, radiob_arraylen
;
766 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
768 radioa_arraylen
= RADIOA_2T_ARRAYLENGTH
;
769 radioa_array_table
= rtl8192de_radioa_2tarray
;
770 radiob_arraylen
= RADIOB_2T_ARRAYLENGTH
;
771 radiob_array_table
= rtl8192de_radiob_2tarray
;
772 if (rtlpriv
->efuse
.internal_pa_5g
[0]) {
773 radioa_arraylen
= RADIOA_2T_INT_PA_ARRAYLENGTH
;
774 radioa_array_table
= rtl8192de_radioa_2t_int_paarray
;
776 if (rtlpriv
->efuse
.internal_pa_5g
[1]) {
777 radiob_arraylen
= RADIOB_2T_INT_PA_ARRAYLENGTH
;
778 radiob_array_table
= rtl8192de_radiob_2t_int_paarray
;
780 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
781 "PHY_ConfigRFWithHeaderFile() Radio_A:Rtl819XRadioA_1TArray\n");
782 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
783 "PHY_ConfigRFWithHeaderFile() Radio_B:Rtl819XRadioB_1TArray\n");
784 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
, "Radio No %x\n", rfpath
);
786 /* this only happens when DMDP, mac0 start on 2.4G,
787 * mac1 start on 5G, mac 0 has to set phy0&phy1
788 * pathA or mac1 has to set phy0&phy1 pathA */
789 if ((content
== radiob_txt
) && (rfpath
== RF90_PATH_A
)) {
790 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
791 " ===> althougth Path A, we load radiob.txt\n");
792 radioa_arraylen
= radiob_arraylen
;
793 radioa_array_table
= radiob_array_table
;
797 for (i
= 0; i
< radioa_arraylen
; i
= i
+ 2) {
798 rtl_rfreg_delay(hw
, rfpath
, radioa_array_table
[i
],
800 radioa_array_table
[i
+ 1]);
804 for (i
= 0; i
< radiob_arraylen
; i
= i
+ 2) {
805 rtl_rfreg_delay(hw
, rfpath
, radiob_array_table
[i
],
807 radiob_array_table
[i
+ 1]);
812 pr_err("switch case %#x not processed\n", rfpath
);
818 void rtl92d_phy_get_hw_reg_originalvalue(struct ieee80211_hw
*hw
)
820 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
821 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
823 rtlphy
->default_initialgain
[0] =
824 (u8
) rtl_get_bbreg(hw
, ROFDM0_XAAGCCORE1
, MASKBYTE0
);
825 rtlphy
->default_initialgain
[1] =
826 (u8
) rtl_get_bbreg(hw
, ROFDM0_XBAGCCORE1
, MASKBYTE0
);
827 rtlphy
->default_initialgain
[2] =
828 (u8
) rtl_get_bbreg(hw
, ROFDM0_XCAGCCORE1
, MASKBYTE0
);
829 rtlphy
->default_initialgain
[3] =
830 (u8
) rtl_get_bbreg(hw
, ROFDM0_XDAGCCORE1
, MASKBYTE0
);
831 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
832 "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x\n",
833 rtlphy
->default_initialgain
[0],
834 rtlphy
->default_initialgain
[1],
835 rtlphy
->default_initialgain
[2],
836 rtlphy
->default_initialgain
[3]);
837 rtlphy
->framesync
= (u8
)rtl_get_bbreg(hw
, ROFDM0_RXDETECTOR3
,
839 rtlphy
->framesync_c34
= rtl_get_bbreg(hw
, ROFDM0_RXDETECTOR2
,
841 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
842 "Default framesync (0x%x) = 0x%x\n",
843 ROFDM0_RXDETECTOR3
, rtlphy
->framesync
);
846 static void _rtl92d_get_txpower_index(struct ieee80211_hw
*hw
, u8 channel
,
847 u8
*cckpowerlevel
, u8
*ofdmpowerlevel
)
849 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
850 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
851 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
852 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
853 u8 index
= (channel
- 1);
856 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
858 cckpowerlevel
[RF90_PATH_A
] =
859 rtlefuse
->txpwrlevel_cck
[RF90_PATH_A
][index
];
861 cckpowerlevel
[RF90_PATH_B
] =
862 rtlefuse
->txpwrlevel_cck
[RF90_PATH_B
][index
];
864 cckpowerlevel
[RF90_PATH_A
] = 0;
865 cckpowerlevel
[RF90_PATH_B
] = 0;
867 /* 2. OFDM for 1S or 2S */
868 if (rtlphy
->rf_type
== RF_1T2R
|| rtlphy
->rf_type
== RF_1T1R
) {
869 /* Read HT 40 OFDM TX power */
870 ofdmpowerlevel
[RF90_PATH_A
] =
871 rtlefuse
->txpwrlevel_ht40_1s
[RF90_PATH_A
][index
];
872 ofdmpowerlevel
[RF90_PATH_B
] =
873 rtlefuse
->txpwrlevel_ht40_1s
[RF90_PATH_B
][index
];
874 } else if (rtlphy
->rf_type
== RF_2T2R
) {
875 /* Read HT 40 OFDM TX power */
876 ofdmpowerlevel
[RF90_PATH_A
] =
877 rtlefuse
->txpwrlevel_ht40_2s
[RF90_PATH_A
][index
];
878 ofdmpowerlevel
[RF90_PATH_B
] =
879 rtlefuse
->txpwrlevel_ht40_2s
[RF90_PATH_B
][index
];
883 static void _rtl92d_ccxpower_index_check(struct ieee80211_hw
*hw
,
884 u8 channel
, u8
*cckpowerlevel
, u8
*ofdmpowerlevel
)
886 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
887 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
889 rtlphy
->cur_cck_txpwridx
= cckpowerlevel
[0];
890 rtlphy
->cur_ofdm24g_txpwridx
= ofdmpowerlevel
[0];
893 static u8
_rtl92c_phy_get_rightchnlplace(u8 chnl
)
898 for (place
= 14; place
< sizeof(channel5g
); place
++) {
899 if (channel5g
[place
] == chnl
) {
908 void rtl92d_phy_set_txpower_level(struct ieee80211_hw
*hw
, u8 channel
)
910 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
911 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
912 u8 cckpowerlevel
[2], ofdmpowerlevel
[2];
914 if (!rtlefuse
->txpwr_fromeprom
)
916 channel
= _rtl92c_phy_get_rightchnlplace(channel
);
917 _rtl92d_get_txpower_index(hw
, channel
, &cckpowerlevel
[0],
919 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
920 _rtl92d_ccxpower_index_check(hw
, channel
, &cckpowerlevel
[0],
922 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
923 rtl92d_phy_rf6052_set_cck_txpower(hw
, &cckpowerlevel
[0]);
924 rtl92d_phy_rf6052_set_ofdm_txpower(hw
, &ofdmpowerlevel
[0], channel
);
927 void rtl92d_phy_set_bw_mode(struct ieee80211_hw
*hw
,
928 enum nl80211_channel_type ch_type
)
930 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
931 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
932 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
933 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
934 unsigned long flag
= 0;
938 if (rtlphy
->set_bwmode_inprogress
)
940 if ((is_hal_stop(rtlhal
)) || (RT_CANNOT_IO(hw
))) {
941 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
942 "FALSE driver sleep or unload\n");
945 rtlphy
->set_bwmode_inprogress
= true;
946 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_TRACE
, "Switch to %s bandwidth\n",
947 rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20
?
949 reg_bw_opmode
= rtl_read_byte(rtlpriv
, REG_BWOPMODE
);
950 reg_prsr_rsc
= rtl_read_byte(rtlpriv
, REG_RRSR
+ 2);
951 switch (rtlphy
->current_chan_bw
) {
952 case HT_CHANNEL_WIDTH_20
:
953 reg_bw_opmode
|= BW_OPMODE_20MHZ
;
954 rtl_write_byte(rtlpriv
, REG_BWOPMODE
, reg_bw_opmode
);
956 case HT_CHANNEL_WIDTH_20_40
:
957 reg_bw_opmode
&= ~BW_OPMODE_20MHZ
;
958 rtl_write_byte(rtlpriv
, REG_BWOPMODE
, reg_bw_opmode
);
960 reg_prsr_rsc
= (reg_prsr_rsc
& 0x90) |
961 (mac
->cur_40_prime_sc
<< 5);
962 rtl_write_byte(rtlpriv
, REG_RRSR
+ 2, reg_prsr_rsc
);
965 pr_err("unknown bandwidth: %#X\n",
966 rtlphy
->current_chan_bw
);
969 switch (rtlphy
->current_chan_bw
) {
970 case HT_CHANNEL_WIDTH_20
:
971 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BRFMOD
, 0x0);
972 rtl_set_bbreg(hw
, RFPGA1_RFMOD
, BRFMOD
, 0x0);
973 /* SET BIT10 BIT11 for receive cck */
974 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER2
, BIT(10) |
977 case HT_CHANNEL_WIDTH_20_40
:
978 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BRFMOD
, 0x1);
979 rtl_set_bbreg(hw
, RFPGA1_RFMOD
, BRFMOD
, 0x1);
980 /* Set Control channel to upper or lower.
981 * These settings are required only for 40MHz */
982 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
983 rtl92d_acquire_cckandrw_pagea_ctl(hw
, &flag
);
984 rtl_set_bbreg(hw
, RCCK0_SYSTEM
, BCCKSIDEBAND
,
985 (mac
->cur_40_prime_sc
>> 1));
986 rtl92d_release_cckandrw_pagea_ctl(hw
, &flag
);
988 rtl_set_bbreg(hw
, ROFDM1_LSTF
, 0xC00, mac
->cur_40_prime_sc
);
989 /* SET BIT10 BIT11 for receive cck */
990 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER2
, BIT(10) |
992 rtl_set_bbreg(hw
, 0x818, (BIT(26) | BIT(27)),
993 (mac
->cur_40_prime_sc
==
994 HAL_PRIME_CHNL_OFFSET_LOWER
) ? 2 : 1);
997 pr_err("unknown bandwidth: %#X\n",
998 rtlphy
->current_chan_bw
);
1002 rtl92d_phy_rf6052_set_bandwidth(hw
, rtlphy
->current_chan_bw
);
1003 rtlphy
->set_bwmode_inprogress
= false;
1004 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_TRACE
, "<==\n");
1007 static void _rtl92d_phy_stop_trx_before_changeband(struct ieee80211_hw
*hw
)
1009 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BCCKEN
, 0);
1010 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BOFDMEN
, 0);
1011 rtl_set_bbreg(hw
, ROFDM0_TRXPATHENABLE
, MASKBYTE0
, 0x00);
1012 rtl_set_bbreg(hw
, ROFDM1_TRXPATHENABLE
, BDWORD
, 0x0);
1015 static void rtl92d_phy_switch_wirelessband(struct ieee80211_hw
*hw
, u8 band
)
1017 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1018 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1021 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "==>\n");
1022 rtlhal
->bandset
= band
;
1023 rtlhal
->current_bandtype
= band
;
1024 if (IS_92D_SINGLEPHY(rtlhal
->version
))
1025 rtlhal
->bandset
= BAND_ON_BOTH
;
1027 _rtl92d_phy_stop_trx_before_changeband(hw
);
1028 /* reconfig BB/RF according to wireless mode */
1029 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
1030 /* BB & RF Config */
1031 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_DMESG
, "====>2.4G\n");
1032 if (rtlhal
->interfaceindex
== 1)
1033 _rtl92d_phy_config_bb_with_headerfile(hw
,
1034 BASEBAND_CONFIG_AGC_TAB
);
1037 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_DMESG
, "====>5G\n");
1038 if (rtlhal
->interfaceindex
== 1)
1039 _rtl92d_phy_config_bb_with_headerfile(hw
,
1040 BASEBAND_CONFIG_AGC_TAB
);
1042 rtl92d_update_bbrf_configuration(hw
);
1043 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
)
1044 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BCCKEN
, 0x1);
1045 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BOFDMEN
, 0x1);
1048 /* rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 1); */
1049 rtlhal
->reloadtxpowerindex
= true;
1050 /* notice fw know band status 0x81[1]/0x53[1] = 0: 5G, 1: 2G */
1051 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
1052 value8
= rtl_read_byte(rtlpriv
, (rtlhal
->interfaceindex
==
1053 0 ? REG_MAC0
: REG_MAC1
));
1055 rtl_write_byte(rtlpriv
, (rtlhal
->interfaceindex
==
1056 0 ? REG_MAC0
: REG_MAC1
), value8
);
1058 value8
= rtl_read_byte(rtlpriv
, (rtlhal
->interfaceindex
==
1059 0 ? REG_MAC0
: REG_MAC1
));
1060 value8
&= (~BIT(1));
1061 rtl_write_byte(rtlpriv
, (rtlhal
->interfaceindex
==
1062 0 ? REG_MAC0
: REG_MAC1
), value8
);
1065 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "<==Switch Band OK\n");
1068 static void _rtl92d_phy_reload_imr_setting(struct ieee80211_hw
*hw
,
1069 u8 channel
, u8 rfpath
)
1071 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1072 u32 imr_num
= MAX_RF_IMR_INDEX
;
1073 u32 rfmask
= RFREG_OFFSET_MASK
;
1075 unsigned long flag
= 0;
1077 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "====>path %d\n", rfpath
);
1078 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_5G
) {
1079 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "====>5G\n");
1080 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BIT(25) | BIT(24), 0);
1081 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
, 0x00f00000, 0xf);
1084 rtl_set_bbreg(hw
, ROFDM1_CFOTRACKING
, BIT(13) |
1087 rtl_set_bbreg(hw
, ROFDM1_CFOTRACKING
, BIT(13) |
1089 /* leave 0 for channel1-14. */
1090 group
= channel
<= 64 ? 1 : 2;
1091 imr_num
= MAX_RF_IMR_INDEX_NORMAL
;
1092 for (i
= 0; i
< imr_num
; i
++)
1093 rtl_set_rfreg(hw
, (enum radio_path
)rfpath
,
1094 rf_reg_for_5g_swchnl_normal
[i
], rfmask
,
1095 rf_imr_param_normal
[0][group
][i
]);
1096 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
, 0x00f00000, 0);
1097 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BOFDMEN
, 1);
1100 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_LOUD
,
1101 "Load RF IMR parameters for G band. IMR already setting %d\n",
1102 rtlpriv
->rtlhal
.load_imrandiqk_setting_for2g
);
1103 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "====>2.4G\n");
1104 if (!rtlpriv
->rtlhal
.load_imrandiqk_setting_for2g
) {
1105 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_LOUD
,
1106 "Load RF IMR parameters for G band. %d\n",
1108 rtl92d_acquire_cckandrw_pagea_ctl(hw
, &flag
);
1109 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BIT(25) | BIT(24), 0);
1110 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
,
1112 imr_num
= MAX_RF_IMR_INDEX_NORMAL
;
1113 for (i
= 0; i
< imr_num
; i
++) {
1114 rtl_set_rfreg(hw
, (enum radio_path
)rfpath
,
1115 rf_reg_for_5g_swchnl_normal
[i
],
1117 rf_imr_param_normal
[0][0][i
]);
1119 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
,
1121 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BOFDMEN
| BCCKEN
, 3);
1122 rtl92d_release_cckandrw_pagea_ctl(hw
, &flag
);
1125 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "<====\n");
1128 static void _rtl92d_phy_enable_rf_env(struct ieee80211_hw
*hw
,
1129 u8 rfpath
, u32
*pu4_regval
)
1131 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1132 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1133 struct bb_reg_def
*pphyreg
= &rtlphy
->phyreg_def
[rfpath
];
1135 RT_TRACE(rtlpriv
, COMP_RF
, DBG_LOUD
, "====>\n");
1136 /*----Store original RFENV control type----*/
1140 *pu4_regval
= rtl_get_bbreg(hw
, pphyreg
->rfintfs
, BRFSI_RFENV
);
1145 rtl_get_bbreg(hw
, pphyreg
->rfintfs
, BRFSI_RFENV
<< 16);
1148 /*----Set RF_ENV enable----*/
1149 rtl_set_bbreg(hw
, pphyreg
->rfintfe
, BRFSI_RFENV
<< 16, 0x1);
1151 /*----Set RF_ENV output high----*/
1152 rtl_set_bbreg(hw
, pphyreg
->rfintfo
, BRFSI_RFENV
, 0x1);
1154 /* Set bit number of Address and Data for RF register */
1155 /* Set 1 to 4 bits for 8255 */
1156 rtl_set_bbreg(hw
, pphyreg
->rfhssi_para2
, B3WIREADDRESSLENGTH
, 0x0);
1158 /*Set 0 to 12 bits for 8255 */
1159 rtl_set_bbreg(hw
, pphyreg
->rfhssi_para2
, B3WIREDATALENGTH
, 0x0);
1161 RT_TRACE(rtlpriv
, COMP_RF
, DBG_LOUD
, "<====\n");
1164 static void _rtl92d_phy_restore_rf_env(struct ieee80211_hw
*hw
, u8 rfpath
,
1167 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1168 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1169 struct bb_reg_def
*pphyreg
= &rtlphy
->phyreg_def
[rfpath
];
1171 RT_TRACE(rtlpriv
, COMP_RF
, DBG_LOUD
, "=====>\n");
1172 /*----Restore RFENV control type----*/
1176 rtl_set_bbreg(hw
, pphyreg
->rfintfs
, BRFSI_RFENV
, *pu4_regval
);
1180 rtl_set_bbreg(hw
, pphyreg
->rfintfs
, BRFSI_RFENV
<< 16,
1184 RT_TRACE(rtlpriv
, COMP_RF
, DBG_LOUD
, "<=====\n");
1187 static void _rtl92d_phy_switch_rf_setting(struct ieee80211_hw
*hw
, u8 channel
)
1189 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1190 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1191 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
1192 u8 path
= rtlhal
->current_bandtype
==
1193 BAND_ON_5G
? RF90_PATH_A
: RF90_PATH_B
;
1194 u8 index
= 0, i
= 0, rfpath
= RF90_PATH_A
;
1195 bool need_pwr_down
= false, internal_pa
= false;
1196 u32 u4regvalue
, mask
= 0x1C000, value
= 0, u4tmp
, u4tmp2
;
1198 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "====>\n");
1199 /* config path A for 5G */
1200 if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
1201 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "====>5G\n");
1202 u4tmp
= curveindex_5g
[channel
- 1];
1203 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1204 "ver 1 set RF-A, 5G, 0x28 = 0x%x !!\n", u4tmp
);
1205 for (i
= 0; i
< RF_CHNL_NUM_5G
; i
++) {
1206 if (channel
== rf_chnl_5g
[i
] && channel
<= 140)
1209 for (i
= 0; i
< RF_CHNL_NUM_5G_40M
; i
++) {
1210 if (channel
== rf_chnl_5g_40m
[i
] && channel
<= 140)
1213 if (channel
== 149 || channel
== 155 || channel
== 161)
1215 else if (channel
== 151 || channel
== 153 || channel
== 163
1218 else if (channel
== 157 || channel
== 159)
1221 if (rtlhal
->macphymode
== DUALMAC_DUALPHY
1222 && rtlhal
->interfaceindex
== 1) {
1223 need_pwr_down
= rtl92d_phy_enable_anotherphy(hw
, false);
1224 rtlhal
->during_mac1init_radioa
= true;
1225 /* asume no this case */
1227 _rtl92d_phy_enable_rf_env(hw
, path
,
1230 for (i
= 0; i
< RF_REG_NUM_FOR_C_CUT_5G
; i
++) {
1231 if (i
== 0 && (rtlhal
->macphymode
== DUALMAC_DUALPHY
)) {
1232 rtl_set_rfreg(hw
, (enum radio_path
)path
,
1233 rf_reg_for_c_cut_5g
[i
],
1234 RFREG_OFFSET_MASK
, 0xE439D);
1235 } else if (rf_reg_for_c_cut_5g
[i
] == RF_SYN_G4
) {
1236 u4tmp2
= (rf_reg_pram_c_5g
[index
][i
] &
1237 0x7FF) | (u4tmp
<< 11);
1239 u4tmp2
&= ~(BIT(7) | BIT(6));
1240 rtl_set_rfreg(hw
, (enum radio_path
)path
,
1241 rf_reg_for_c_cut_5g
[i
],
1242 RFREG_OFFSET_MASK
, u4tmp2
);
1244 rtl_set_rfreg(hw
, (enum radio_path
)path
,
1245 rf_reg_for_c_cut_5g
[i
],
1247 rf_reg_pram_c_5g
[index
][i
]);
1249 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
1250 "offset 0x%x value 0x%x path %d index %d readback 0x%x\n",
1251 rf_reg_for_c_cut_5g
[i
],
1252 rf_reg_pram_c_5g
[index
][i
],
1254 rtl_get_rfreg(hw
, (enum radio_path
)path
,
1255 rf_reg_for_c_cut_5g
[i
],
1256 RFREG_OFFSET_MASK
));
1259 _rtl92d_phy_restore_rf_env(hw
, path
, &u4regvalue
);
1260 if (rtlhal
->during_mac1init_radioa
)
1261 rtl92d_phy_powerdown_anotherphy(hw
, false);
1264 else if (channel
>= 149)
1266 if (channel
>= 36 && channel
<= 64)
1268 else if (channel
>= 100 && channel
<= 140)
1272 for (rfpath
= RF90_PATH_A
; rfpath
< rtlphy
->num_total_rfpath
;
1274 if (rtlhal
->macphymode
== DUALMAC_DUALPHY
&&
1275 rtlhal
->interfaceindex
== 1) /* MAC 1 5G */
1276 internal_pa
= rtlpriv
->efuse
.internal_pa_5g
[1];
1279 rtlpriv
->efuse
.internal_pa_5g
[rfpath
];
1282 i
< RF_REG_NUM_FOR_C_CUT_5G_INTERNALPA
;
1284 rtl_set_rfreg(hw
, rfpath
,
1285 rf_for_c_cut_5g_internal_pa
[i
],
1287 rf_pram_c_5g_int_pa
[index
][i
]);
1288 RT_TRACE(rtlpriv
, COMP_RF
, DBG_LOUD
,
1289 "offset 0x%x value 0x%x path %d index %d\n",
1290 rf_for_c_cut_5g_internal_pa
[i
],
1291 rf_pram_c_5g_int_pa
[index
][i
],
1295 rtl_set_rfreg(hw
, (enum radio_path
)rfpath
, 0x0B,
1299 } else if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
1300 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "====>2.4G\n");
1301 u4tmp
= curveindex_2g
[channel
- 1];
1302 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1303 "ver 3 set RF-B, 2G, 0x28 = 0x%x !!\n", u4tmp
);
1304 if (channel
== 1 || channel
== 2 || channel
== 4 || channel
== 9
1305 || channel
== 10 || channel
== 11 || channel
== 12)
1307 else if (channel
== 3 || channel
== 13 || channel
== 14)
1309 else if (channel
>= 5 && channel
<= 8)
1311 if (rtlhal
->macphymode
== DUALMAC_DUALPHY
) {
1313 if (rtlhal
->interfaceindex
== 0) {
1315 rtl92d_phy_enable_anotherphy(hw
, true);
1316 rtlhal
->during_mac0init_radiob
= true;
1319 _rtl92d_phy_enable_rf_env(hw
, path
,
1323 for (i
= 0; i
< RF_REG_NUM_FOR_C_CUT_2G
; i
++) {
1324 if (rf_reg_for_c_cut_2g
[i
] == RF_SYN_G7
)
1325 rtl_set_rfreg(hw
, (enum radio_path
)path
,
1326 rf_reg_for_c_cut_2g
[i
],
1328 (rf_reg_param_for_c_cut_2g
[index
][i
] |
1331 rtl_set_rfreg(hw
, (enum radio_path
)path
,
1332 rf_reg_for_c_cut_2g
[i
],
1334 rf_reg_param_for_c_cut_2g
1336 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
1337 "offset 0x%x value 0x%x mak 0x%x path %d index %d readback 0x%x\n",
1338 rf_reg_for_c_cut_2g
[i
],
1339 rf_reg_param_for_c_cut_2g
[index
][i
],
1340 rf_reg_mask_for_c_cut_2g
[i
], path
, index
,
1341 rtl_get_rfreg(hw
, (enum radio_path
)path
,
1342 rf_reg_for_c_cut_2g
[i
],
1343 RFREG_OFFSET_MASK
));
1345 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1346 "cosa ver 3 set RF-B, 2G, 0x28 = 0x%x !!\n",
1347 rf_syn_g4_for_c_cut_2g
| (u4tmp
<< 11));
1349 rtl_set_rfreg(hw
, (enum radio_path
)path
, RF_SYN_G4
,
1351 rf_syn_g4_for_c_cut_2g
| (u4tmp
<< 11));
1353 _rtl92d_phy_restore_rf_env(hw
, path
, &u4regvalue
);
1354 if (rtlhal
->during_mac0init_radiob
)
1355 rtl92d_phy_powerdown_anotherphy(hw
, true);
1357 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "<====\n");
1360 u8
rtl92d_get_rightchnlplace_for_iqk(u8 chnl
)
1362 u8 channel_all
[59] = {
1363 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
1364 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58,
1365 60, 62, 64, 100, 102, 104, 106, 108, 110, 112,
1366 114, 116, 118, 120, 122, 124, 126, 128, 130,
1367 132, 134, 136, 138, 140, 149, 151, 153, 155,
1368 157, 159, 161, 163, 165
1373 for (place
= 14; place
< sizeof(channel_all
); place
++) {
1374 if (channel_all
[place
] == chnl
)
1382 #define MAX_TOLERANCE 5
1383 #define IQK_DELAY_TIME 1 /* ms */
1384 #define MAX_TOLERANCE_92D 3
1386 /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */
1387 static u8
_rtl92d_phy_patha_iqk(struct ieee80211_hw
*hw
, bool configpathb
)
1389 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1390 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1391 u32 regeac
, rege94
, rege9c
, regea4
;
1394 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path A IQK!\n");
1395 /* path-A IQK setting */
1396 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path-A IQK setting!\n");
1397 if (rtlhal
->interfaceindex
== 0) {
1398 rtl_set_bbreg(hw
, 0xe30, MASKDWORD
, 0x10008c1f);
1399 rtl_set_bbreg(hw
, 0xe34, MASKDWORD
, 0x10008c1f);
1401 rtl_set_bbreg(hw
, 0xe30, MASKDWORD
, 0x10008c22);
1402 rtl_set_bbreg(hw
, 0xe34, MASKDWORD
, 0x10008c22);
1404 rtl_set_bbreg(hw
, 0xe38, MASKDWORD
, 0x82140102);
1405 rtl_set_bbreg(hw
, 0xe3c, MASKDWORD
, 0x28160206);
1406 /* path-B IQK setting */
1408 rtl_set_bbreg(hw
, 0xe50, MASKDWORD
, 0x10008c22);
1409 rtl_set_bbreg(hw
, 0xe54, MASKDWORD
, 0x10008c22);
1410 rtl_set_bbreg(hw
, 0xe58, MASKDWORD
, 0x82140102);
1411 rtl_set_bbreg(hw
, 0xe5c, MASKDWORD
, 0x28160206);
1413 /* LO calibration setting */
1414 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "LO calibration setting!\n");
1415 rtl_set_bbreg(hw
, 0xe4c, MASKDWORD
, 0x00462911);
1416 /* One shot, path A LOK & IQK */
1417 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "One shot, path A LOK & IQK!\n");
1418 rtl_set_bbreg(hw
, 0xe48, MASKDWORD
, 0xf9000000);
1419 rtl_set_bbreg(hw
, 0xe48, MASKDWORD
, 0xf8000000);
1421 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1422 "Delay %d ms for One shot, path A LOK & IQK\n",
1424 mdelay(IQK_DELAY_TIME
);
1426 regeac
= rtl_get_bbreg(hw
, 0xeac, MASKDWORD
);
1427 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xeac = 0x%x\n", regeac
);
1428 rege94
= rtl_get_bbreg(hw
, 0xe94, MASKDWORD
);
1429 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xe94 = 0x%x\n", rege94
);
1430 rege9c
= rtl_get_bbreg(hw
, 0xe9c, MASKDWORD
);
1431 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xe9c = 0x%x\n", rege9c
);
1432 regea4
= rtl_get_bbreg(hw
, 0xea4, MASKDWORD
);
1433 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xea4 = 0x%x\n", regea4
);
1434 if (!(regeac
& BIT(28)) && (((rege94
& 0x03FF0000) >> 16) != 0x142) &&
1435 (((rege9c
& 0x03FF0000) >> 16) != 0x42))
1437 else /* if Tx not OK, ignore Rx */
1439 /* if Tx is OK, check whether Rx is OK */
1440 if (!(regeac
& BIT(27)) && (((regea4
& 0x03FF0000) >> 16) != 0x132) &&
1441 (((regeac
& 0x03FF0000) >> 16) != 0x36))
1444 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path A Rx IQK fail!!\n");
1448 /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */
1449 static u8
_rtl92d_phy_patha_iqk_5g_normal(struct ieee80211_hw
*hw
,
1452 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1453 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1454 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1455 u32 regeac
, rege94
, rege9c
, regea4
;
1459 u32 TXOKBIT
= BIT(28), RXOKBIT
= BIT(27);
1461 if (rtlhal
->interfaceindex
== 1) { /* PHY1 */
1465 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path A IQK!\n");
1466 /* path-A IQK setting */
1467 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path-A IQK setting!\n");
1468 rtl_set_bbreg(hw
, 0xe30, MASKDWORD
, 0x18008c1f);
1469 rtl_set_bbreg(hw
, 0xe34, MASKDWORD
, 0x18008c1f);
1470 rtl_set_bbreg(hw
, 0xe38, MASKDWORD
, 0x82140307);
1471 rtl_set_bbreg(hw
, 0xe3c, MASKDWORD
, 0x68160960);
1472 /* path-B IQK setting */
1474 rtl_set_bbreg(hw
, 0xe50, MASKDWORD
, 0x18008c2f);
1475 rtl_set_bbreg(hw
, 0xe54, MASKDWORD
, 0x18008c2f);
1476 rtl_set_bbreg(hw
, 0xe58, MASKDWORD
, 0x82110000);
1477 rtl_set_bbreg(hw
, 0xe5c, MASKDWORD
, 0x68110000);
1479 /* LO calibration setting */
1480 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "LO calibration setting!\n");
1481 rtl_set_bbreg(hw
, 0xe4c, MASKDWORD
, 0x00462911);
1483 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
, MASKDWORD
, 0x07000f60);
1484 rtl_set_bbreg(hw
, RFPGA0_XA_RFINTERFACEOE
, MASKDWORD
, 0x66e60e30);
1485 for (i
= 0; i
< retrycount
; i
++) {
1486 /* One shot, path A LOK & IQK */
1487 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1488 "One shot, path A LOK & IQK!\n");
1489 rtl_set_bbreg(hw
, 0xe48, MASKDWORD
, 0xf9000000);
1490 rtl_set_bbreg(hw
, 0xe48, MASKDWORD
, 0xf8000000);
1492 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1493 "Delay %d ms for One shot, path A LOK & IQK.\n",
1495 mdelay(IQK_DELAY_TIME
* 10);
1497 regeac
= rtl_get_bbreg(hw
, 0xeac, MASKDWORD
);
1498 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xeac = 0x%x\n", regeac
);
1499 rege94
= rtl_get_bbreg(hw
, 0xe94, MASKDWORD
);
1500 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xe94 = 0x%x\n", rege94
);
1501 rege9c
= rtl_get_bbreg(hw
, 0xe9c, MASKDWORD
);
1502 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xe9c = 0x%x\n", rege9c
);
1503 regea4
= rtl_get_bbreg(hw
, 0xea4, MASKDWORD
);
1504 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xea4 = 0x%x\n", regea4
);
1505 if (!(regeac
& TXOKBIT
) &&
1506 (((rege94
& 0x03FF0000) >> 16) != 0x142)) {
1508 } else { /* if Tx not OK, ignore Rx */
1509 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1510 "Path A Tx IQK fail!!\n");
1514 /* if Tx is OK, check whether Rx is OK */
1515 if (!(regeac
& RXOKBIT
) &&
1516 (((regea4
& 0x03FF0000) >> 16) != 0x132)) {
1520 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1521 "Path A Rx IQK fail!!\n");
1525 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
, MASKDWORD
,
1526 rtlphy
->iqk_bb_backup
[0]);
1527 rtl_set_bbreg(hw
, RFPGA0_XA_RFINTERFACEOE
, MASKDWORD
,
1528 rtlphy
->iqk_bb_backup
[1]);
1532 /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */
1533 static u8
_rtl92d_phy_pathb_iqk(struct ieee80211_hw
*hw
)
1535 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1536 u32 regeac
, regeb4
, regebc
, regec4
, regecc
;
1539 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path B IQK!\n");
1540 /* One shot, path B LOK & IQK */
1541 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "One shot, path A LOK & IQK!\n");
1542 rtl_set_bbreg(hw
, 0xe60, MASKDWORD
, 0x00000002);
1543 rtl_set_bbreg(hw
, 0xe60, MASKDWORD
, 0x00000000);
1545 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1546 "Delay %d ms for One shot, path B LOK & IQK\n", IQK_DELAY_TIME
);
1547 mdelay(IQK_DELAY_TIME
);
1549 regeac
= rtl_get_bbreg(hw
, 0xeac, MASKDWORD
);
1550 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xeac = 0x%x\n", regeac
);
1551 regeb4
= rtl_get_bbreg(hw
, 0xeb4, MASKDWORD
);
1552 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xeb4 = 0x%x\n", regeb4
);
1553 regebc
= rtl_get_bbreg(hw
, 0xebc, MASKDWORD
);
1554 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xebc = 0x%x\n", regebc
);
1555 regec4
= rtl_get_bbreg(hw
, 0xec4, MASKDWORD
);
1556 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xec4 = 0x%x\n", regec4
);
1557 regecc
= rtl_get_bbreg(hw
, 0xecc, MASKDWORD
);
1558 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xecc = 0x%x\n", regecc
);
1559 if (!(regeac
& BIT(31)) && (((regeb4
& 0x03FF0000) >> 16) != 0x142) &&
1560 (((regebc
& 0x03FF0000) >> 16) != 0x42))
1564 if (!(regeac
& BIT(30)) && (((regec4
& 0x03FF0000) >> 16) != 0x132) &&
1565 (((regecc
& 0x03FF0000) >> 16) != 0x36))
1568 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path B Rx IQK fail!!\n");
1572 /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */
1573 static u8
_rtl92d_phy_pathb_iqk_5g_normal(struct ieee80211_hw
*hw
)
1575 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1576 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1577 u32 regeac
, regeb4
, regebc
, regec4
, regecc
;
1582 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path B IQK!\n");
1583 /* path-A IQK setting */
1584 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path-A IQK setting!\n");
1585 rtl_set_bbreg(hw
, 0xe30, MASKDWORD
, 0x18008c1f);
1586 rtl_set_bbreg(hw
, 0xe34, MASKDWORD
, 0x18008c1f);
1587 rtl_set_bbreg(hw
, 0xe38, MASKDWORD
, 0x82110000);
1588 rtl_set_bbreg(hw
, 0xe3c, MASKDWORD
, 0x68110000);
1590 /* path-B IQK setting */
1591 rtl_set_bbreg(hw
, 0xe50, MASKDWORD
, 0x18008c2f);
1592 rtl_set_bbreg(hw
, 0xe54, MASKDWORD
, 0x18008c2f);
1593 rtl_set_bbreg(hw
, 0xe58, MASKDWORD
, 0x82140307);
1594 rtl_set_bbreg(hw
, 0xe5c, MASKDWORD
, 0x68160960);
1596 /* LO calibration setting */
1597 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "LO calibration setting!\n");
1598 rtl_set_bbreg(hw
, 0xe4c, MASKDWORD
, 0x00462911);
1601 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
, MASKDWORD
, 0x0f600700);
1602 rtl_set_bbreg(hw
, RFPGA0_XB_RFINTERFACEOE
, MASKDWORD
, 0x061f0d30);
1604 for (i
= 0; i
< retrycount
; i
++) {
1605 /* One shot, path B LOK & IQK */
1606 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1607 "One shot, path A LOK & IQK!\n");
1608 rtl_set_bbreg(hw
, 0xe48, MASKDWORD
, 0xfa000000);
1609 rtl_set_bbreg(hw
, 0xe48, MASKDWORD
, 0xf8000000);
1612 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1613 "Delay %d ms for One shot, path B LOK & IQK.\n", 10);
1614 mdelay(IQK_DELAY_TIME
* 10);
1617 regeac
= rtl_get_bbreg(hw
, 0xeac, MASKDWORD
);
1618 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xeac = 0x%x\n", regeac
);
1619 regeb4
= rtl_get_bbreg(hw
, 0xeb4, MASKDWORD
);
1620 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xeb4 = 0x%x\n", regeb4
);
1621 regebc
= rtl_get_bbreg(hw
, 0xebc, MASKDWORD
);
1622 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xebc = 0x%x\n", regebc
);
1623 regec4
= rtl_get_bbreg(hw
, 0xec4, MASKDWORD
);
1624 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xec4 = 0x%x\n", regec4
);
1625 regecc
= rtl_get_bbreg(hw
, 0xecc, MASKDWORD
);
1626 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xecc = 0x%x\n", regecc
);
1627 if (!(regeac
& BIT(31)) &&
1628 (((regeb4
& 0x03FF0000) >> 16) != 0x142))
1632 if (!(regeac
& BIT(30)) &&
1633 (((regec4
& 0x03FF0000) >> 16) != 0x132)) {
1637 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1638 "Path B Rx IQK fail!!\n");
1643 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
, MASKDWORD
,
1644 rtlphy
->iqk_bb_backup
[0]);
1645 rtl_set_bbreg(hw
, RFPGA0_XB_RFINTERFACEOE
, MASKDWORD
,
1646 rtlphy
->iqk_bb_backup
[2]);
1650 static void _rtl92d_phy_save_adda_registers(struct ieee80211_hw
*hw
,
1651 u32
*adda_reg
, u32
*adda_backup
,
1654 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1657 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Save ADDA parameters.\n");
1658 for (i
= 0; i
< regnum
; i
++)
1659 adda_backup
[i
] = rtl_get_bbreg(hw
, adda_reg
[i
], MASKDWORD
);
1662 static void _rtl92d_phy_save_mac_registers(struct ieee80211_hw
*hw
,
1663 u32
*macreg
, u32
*macbackup
)
1665 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1668 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Save MAC parameters.\n");
1669 for (i
= 0; i
< (IQK_MAC_REG_NUM
- 1); i
++)
1670 macbackup
[i
] = rtl_read_byte(rtlpriv
, macreg
[i
]);
1671 macbackup
[i
] = rtl_read_dword(rtlpriv
, macreg
[i
]);
1674 static void _rtl92d_phy_reload_adda_registers(struct ieee80211_hw
*hw
,
1675 u32
*adda_reg
, u32
*adda_backup
,
1678 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1681 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1682 "Reload ADDA power saving parameters !\n");
1683 for (i
= 0; i
< regnum
; i
++)
1684 rtl_set_bbreg(hw
, adda_reg
[i
], MASKDWORD
, adda_backup
[i
]);
1687 static void _rtl92d_phy_reload_mac_registers(struct ieee80211_hw
*hw
,
1688 u32
*macreg
, u32
*macbackup
)
1690 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1693 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Reload MAC parameters !\n");
1694 for (i
= 0; i
< (IQK_MAC_REG_NUM
- 1); i
++)
1695 rtl_write_byte(rtlpriv
, macreg
[i
], (u8
) macbackup
[i
]);
1696 rtl_write_byte(rtlpriv
, macreg
[i
], macbackup
[i
]);
1699 static void _rtl92d_phy_path_adda_on(struct ieee80211_hw
*hw
,
1700 u32
*adda_reg
, bool patha_on
, bool is2t
)
1702 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1706 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "ADDA ON.\n");
1707 pathon
= patha_on
? 0x04db25a4 : 0x0b1b25a4;
1709 pathon
= rtlpriv
->rtlhal
.interfaceindex
== 0 ?
1710 0x04db25a4 : 0x0b1b25a4;
1711 for (i
= 0; i
< IQK_ADDA_REG_NUM
; i
++)
1712 rtl_set_bbreg(hw
, adda_reg
[i
], MASKDWORD
, pathon
);
1715 static void _rtl92d_phy_mac_setting_calibration(struct ieee80211_hw
*hw
,
1716 u32
*macreg
, u32
*macbackup
)
1718 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1721 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "MAC settings for Calibration.\n");
1722 rtl_write_byte(rtlpriv
, macreg
[0], 0x3F);
1724 for (i
= 1; i
< (IQK_MAC_REG_NUM
- 1); i
++)
1725 rtl_write_byte(rtlpriv
, macreg
[i
], (u8
)(macbackup
[i
] &
1727 rtl_write_byte(rtlpriv
, macreg
[i
], (u8
) (macbackup
[i
] & (~BIT(5))));
1730 static void _rtl92d_phy_patha_standby(struct ieee80211_hw
*hw
)
1732 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1733 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path-A standby mode!\n");
1735 rtl_set_bbreg(hw
, 0xe28, MASKDWORD
, 0x0);
1736 rtl_set_bbreg(hw
, RFPGA0_XA_LSSIPARAMETER
, MASKDWORD
, 0x00010000);
1737 rtl_set_bbreg(hw
, 0xe28, MASKDWORD
, 0x80800000);
1740 static void _rtl92d_phy_pimode_switch(struct ieee80211_hw
*hw
, bool pi_mode
)
1742 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1745 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1746 "BB Switch to %s mode!\n", pi_mode
? "PI" : "SI");
1747 mode
= pi_mode
? 0x01000100 : 0x01000000;
1748 rtl_set_bbreg(hw
, 0x820, MASKDWORD
, mode
);
1749 rtl_set_bbreg(hw
, 0x828, MASKDWORD
, mode
);
1752 static void _rtl92d_phy_iq_calibrate(struct ieee80211_hw
*hw
, long result
[][8],
1755 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1756 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1758 u8 patha_ok
, pathb_ok
;
1759 static u32 adda_reg
[IQK_ADDA_REG_NUM
] = {
1760 RFPGA0_XCD_SWITCHCONTROL
, 0xe6c, 0xe70, 0xe74,
1761 0xe78, 0xe7c, 0xe80, 0xe84,
1762 0xe88, 0xe8c, 0xed0, 0xed4,
1763 0xed8, 0xedc, 0xee0, 0xeec
1765 static u32 iqk_mac_reg
[IQK_MAC_REG_NUM
] = {
1766 0x522, 0x550, 0x551, 0x040
1768 static u32 iqk_bb_reg
[IQK_BB_REG_NUM
] = {
1769 RFPGA0_XAB_RFINTERFACESW
, RFPGA0_XA_RFINTERFACEOE
,
1770 RFPGA0_XB_RFINTERFACEOE
, ROFDM0_TRMUXPAR
,
1771 RFPGA0_XCD_RFINTERFACESW
, ROFDM0_TRXPATHENABLE
,
1772 RFPGA0_RFMOD
, RFPGA0_ANALOGPARAMETER4
,
1773 ROFDM0_XAAGCCORE1
, ROFDM0_XBAGCCORE1
1775 const u32 retrycount
= 2;
1778 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "IQK for 2.4G :Start!!!\n");
1780 bbvalue
= rtl_get_bbreg(hw
, RFPGA0_RFMOD
, MASKDWORD
);
1781 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "==>0x%08x\n", bbvalue
);
1782 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "IQ Calibration for %s\n",
1783 is2t
? "2T2R" : "1T1R");
1785 /* Save ADDA parameters, turn Path A ADDA on */
1786 _rtl92d_phy_save_adda_registers(hw
, adda_reg
,
1787 rtlphy
->adda_backup
, IQK_ADDA_REG_NUM
);
1788 _rtl92d_phy_save_mac_registers(hw
, iqk_mac_reg
,
1789 rtlphy
->iqk_mac_backup
);
1790 _rtl92d_phy_save_adda_registers(hw
, iqk_bb_reg
,
1791 rtlphy
->iqk_bb_backup
, IQK_BB_REG_NUM
);
1793 _rtl92d_phy_path_adda_on(hw
, adda_reg
, true, is2t
);
1795 rtlphy
->rfpi_enable
= (u8
) rtl_get_bbreg(hw
,
1796 RFPGA0_XA_HSSIPARAMETER1
, BIT(8));
1798 /* Switch BB to PI mode to do IQ Calibration. */
1799 if (!rtlphy
->rfpi_enable
)
1800 _rtl92d_phy_pimode_switch(hw
, true);
1802 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BIT(24), 0x00);
1803 rtl_set_bbreg(hw
, ROFDM0_TRXPATHENABLE
, MASKDWORD
, 0x03a05600);
1804 rtl_set_bbreg(hw
, ROFDM0_TRMUXPAR
, MASKDWORD
, 0x000800e4);
1805 rtl_set_bbreg(hw
, RFPGA0_XCD_RFINTERFACESW
, MASKDWORD
, 0x22204000);
1806 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
, 0xf00000, 0x0f);
1808 rtl_set_bbreg(hw
, RFPGA0_XA_LSSIPARAMETER
, MASKDWORD
,
1810 rtl_set_bbreg(hw
, RFPGA0_XB_LSSIPARAMETER
, MASKDWORD
,
1814 _rtl92d_phy_mac_setting_calibration(hw
, iqk_mac_reg
,
1815 rtlphy
->iqk_mac_backup
);
1817 rtl_set_bbreg(hw
, 0xb68, MASKDWORD
, 0x0f600000);
1819 rtl_set_bbreg(hw
, 0xb6c, MASKDWORD
, 0x0f600000);
1820 /* IQ calibration setting */
1821 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "IQK setting!\n");
1822 rtl_set_bbreg(hw
, 0xe28, MASKDWORD
, 0x80800000);
1823 rtl_set_bbreg(hw
, 0xe40, MASKDWORD
, 0x01007c00);
1824 rtl_set_bbreg(hw
, 0xe44, MASKDWORD
, 0x01004800);
1825 for (i
= 0; i
< retrycount
; i
++) {
1826 patha_ok
= _rtl92d_phy_patha_iqk(hw
, is2t
);
1827 if (patha_ok
== 0x03) {
1828 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1829 "Path A IQK Success!!\n");
1830 result
[t
][0] = (rtl_get_bbreg(hw
, 0xe94, MASKDWORD
) &
1832 result
[t
][1] = (rtl_get_bbreg(hw
, 0xe9c, MASKDWORD
) &
1834 result
[t
][2] = (rtl_get_bbreg(hw
, 0xea4, MASKDWORD
) &
1836 result
[t
][3] = (rtl_get_bbreg(hw
, 0xeac, MASKDWORD
) &
1839 } else if (i
== (retrycount
- 1) && patha_ok
== 0x01) {
1841 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1842 "Path A IQK Only Tx Success!!\n");
1844 result
[t
][0] = (rtl_get_bbreg(hw
, 0xe94, MASKDWORD
) &
1846 result
[t
][1] = (rtl_get_bbreg(hw
, 0xe9c, MASKDWORD
) &
1850 if (0x00 == patha_ok
)
1851 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path A IQK failed!!\n");
1853 _rtl92d_phy_patha_standby(hw
);
1854 /* Turn Path B ADDA on */
1855 _rtl92d_phy_path_adda_on(hw
, adda_reg
, false, is2t
);
1856 for (i
= 0; i
< retrycount
; i
++) {
1857 pathb_ok
= _rtl92d_phy_pathb_iqk(hw
);
1858 if (pathb_ok
== 0x03) {
1859 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1860 "Path B IQK Success!!\n");
1861 result
[t
][4] = (rtl_get_bbreg(hw
, 0xeb4,
1862 MASKDWORD
) & 0x3FF0000) >> 16;
1863 result
[t
][5] = (rtl_get_bbreg(hw
, 0xebc,
1864 MASKDWORD
) & 0x3FF0000) >> 16;
1865 result
[t
][6] = (rtl_get_bbreg(hw
, 0xec4,
1866 MASKDWORD
) & 0x3FF0000) >> 16;
1867 result
[t
][7] = (rtl_get_bbreg(hw
, 0xecc,
1868 MASKDWORD
) & 0x3FF0000) >> 16;
1870 } else if (i
== (retrycount
- 1) && pathb_ok
== 0x01) {
1872 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1873 "Path B Only Tx IQK Success!!\n");
1874 result
[t
][4] = (rtl_get_bbreg(hw
, 0xeb4,
1875 MASKDWORD
) & 0x3FF0000) >> 16;
1876 result
[t
][5] = (rtl_get_bbreg(hw
, 0xebc,
1877 MASKDWORD
) & 0x3FF0000) >> 16;
1880 if (0x00 == pathb_ok
)
1881 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1882 "Path B IQK failed!!\n");
1885 /* Back to BB mode, load original value */
1886 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1887 "IQK:Back to BB mode, load original value!\n");
1889 rtl_set_bbreg(hw
, 0xe28, MASKDWORD
, 0);
1891 /* Switch back BB to SI mode after finish IQ Calibration. */
1892 if (!rtlphy
->rfpi_enable
)
1893 _rtl92d_phy_pimode_switch(hw
, false);
1894 /* Reload ADDA power saving parameters */
1895 _rtl92d_phy_reload_adda_registers(hw
, adda_reg
,
1896 rtlphy
->adda_backup
, IQK_ADDA_REG_NUM
);
1897 /* Reload MAC parameters */
1898 _rtl92d_phy_reload_mac_registers(hw
, iqk_mac_reg
,
1899 rtlphy
->iqk_mac_backup
);
1901 _rtl92d_phy_reload_adda_registers(hw
, iqk_bb_reg
,
1902 rtlphy
->iqk_bb_backup
,
1905 _rtl92d_phy_reload_adda_registers(hw
, iqk_bb_reg
,
1906 rtlphy
->iqk_bb_backup
,
1907 IQK_BB_REG_NUM
- 1);
1908 /* load 0xe30 IQC default value */
1909 rtl_set_bbreg(hw
, 0xe30, MASKDWORD
, 0x01008c00);
1910 rtl_set_bbreg(hw
, 0xe34, MASKDWORD
, 0x01008c00);
1912 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "<==\n");
1915 static void _rtl92d_phy_iq_calibrate_5g_normal(struct ieee80211_hw
*hw
,
1916 long result
[][8], u8 t
)
1918 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1919 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1920 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
1921 u8 patha_ok
, pathb_ok
;
1922 static u32 adda_reg
[IQK_ADDA_REG_NUM
] = {
1923 RFPGA0_XCD_SWITCHCONTROL
, 0xe6c, 0xe70, 0xe74,
1924 0xe78, 0xe7c, 0xe80, 0xe84,
1925 0xe88, 0xe8c, 0xed0, 0xed4,
1926 0xed8, 0xedc, 0xee0, 0xeec
1928 static u32 iqk_mac_reg
[IQK_MAC_REG_NUM
] = {
1929 0x522, 0x550, 0x551, 0x040
1931 static u32 iqk_bb_reg
[IQK_BB_REG_NUM
] = {
1932 RFPGA0_XAB_RFINTERFACESW
, RFPGA0_XA_RFINTERFACEOE
,
1933 RFPGA0_XB_RFINTERFACEOE
, ROFDM0_TRMUXPAR
,
1934 RFPGA0_XCD_RFINTERFACESW
, ROFDM0_TRXPATHENABLE
,
1935 RFPGA0_RFMOD
, RFPGA0_ANALOGPARAMETER4
,
1936 ROFDM0_XAAGCCORE1
, ROFDM0_XBAGCCORE1
1939 bool is2t
= IS_92D_SINGLEPHY(rtlhal
->version
);
1941 /* Note: IQ calibration must be performed after loading
1942 * PHY_REG.txt , and radio_a, radio_b.txt */
1944 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "IQK for 5G NORMAL:Start!!!\n");
1945 mdelay(IQK_DELAY_TIME
* 20);
1947 bbvalue
= rtl_get_bbreg(hw
, RFPGA0_RFMOD
, MASKDWORD
);
1948 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "==>0x%08x\n", bbvalue
);
1949 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "IQ Calibration for %s\n",
1950 is2t
? "2T2R" : "1T1R");
1951 /* Save ADDA parameters, turn Path A ADDA on */
1952 _rtl92d_phy_save_adda_registers(hw
, adda_reg
,
1953 rtlphy
->adda_backup
,
1955 _rtl92d_phy_save_mac_registers(hw
, iqk_mac_reg
,
1956 rtlphy
->iqk_mac_backup
);
1958 _rtl92d_phy_save_adda_registers(hw
, iqk_bb_reg
,
1959 rtlphy
->iqk_bb_backup
,
1962 _rtl92d_phy_save_adda_registers(hw
, iqk_bb_reg
,
1963 rtlphy
->iqk_bb_backup
,
1964 IQK_BB_REG_NUM
- 1);
1966 _rtl92d_phy_path_adda_on(hw
, adda_reg
, true, is2t
);
1968 _rtl92d_phy_mac_setting_calibration(hw
, iqk_mac_reg
,
1969 rtlphy
->iqk_mac_backup
);
1971 rtlphy
->rfpi_enable
= (u8
) rtl_get_bbreg(hw
,
1972 RFPGA0_XA_HSSIPARAMETER1
, BIT(8));
1973 /* Switch BB to PI mode to do IQ Calibration. */
1974 if (!rtlphy
->rfpi_enable
)
1975 _rtl92d_phy_pimode_switch(hw
, true);
1976 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BIT(24), 0x00);
1977 rtl_set_bbreg(hw
, ROFDM0_TRXPATHENABLE
, MASKDWORD
, 0x03a05600);
1978 rtl_set_bbreg(hw
, ROFDM0_TRMUXPAR
, MASKDWORD
, 0x000800e4);
1979 rtl_set_bbreg(hw
, RFPGA0_XCD_RFINTERFACESW
, MASKDWORD
, 0x22208000);
1980 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
, 0xf00000, 0x0f);
1983 rtl_set_bbreg(hw
, 0xb68, MASKDWORD
, 0x0f600000);
1985 rtl_set_bbreg(hw
, 0xb6c, MASKDWORD
, 0x0f600000);
1986 /* IQ calibration setting */
1987 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "IQK setting!\n");
1988 rtl_set_bbreg(hw
, 0xe28, MASKDWORD
, 0x80800000);
1989 rtl_set_bbreg(hw
, 0xe40, MASKDWORD
, 0x10007c00);
1990 rtl_set_bbreg(hw
, 0xe44, MASKDWORD
, 0x01004800);
1991 patha_ok
= _rtl92d_phy_patha_iqk_5g_normal(hw
, is2t
);
1992 if (patha_ok
== 0x03) {
1993 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path A IQK Success!!\n");
1994 result
[t
][0] = (rtl_get_bbreg(hw
, 0xe94, MASKDWORD
) &
1996 result
[t
][1] = (rtl_get_bbreg(hw
, 0xe9c, MASKDWORD
) &
1998 result
[t
][2] = (rtl_get_bbreg(hw
, 0xea4, MASKDWORD
) &
2000 result
[t
][3] = (rtl_get_bbreg(hw
, 0xeac, MASKDWORD
) &
2002 } else if (patha_ok
== 0x01) { /* Tx IQK OK */
2003 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2004 "Path A IQK Only Tx Success!!\n");
2006 result
[t
][0] = (rtl_get_bbreg(hw
, 0xe94, MASKDWORD
) &
2008 result
[t
][1] = (rtl_get_bbreg(hw
, 0xe9c, MASKDWORD
) &
2011 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path A IQK Fail!!\n");
2014 /* _rtl92d_phy_patha_standby(hw); */
2015 /* Turn Path B ADDA on */
2016 _rtl92d_phy_path_adda_on(hw
, adda_reg
, false, is2t
);
2017 pathb_ok
= _rtl92d_phy_pathb_iqk_5g_normal(hw
);
2018 if (pathb_ok
== 0x03) {
2019 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2020 "Path B IQK Success!!\n");
2021 result
[t
][4] = (rtl_get_bbreg(hw
, 0xeb4, MASKDWORD
) &
2023 result
[t
][5] = (rtl_get_bbreg(hw
, 0xebc, MASKDWORD
) &
2025 result
[t
][6] = (rtl_get_bbreg(hw
, 0xec4, MASKDWORD
) &
2027 result
[t
][7] = (rtl_get_bbreg(hw
, 0xecc, MASKDWORD
) &
2029 } else if (pathb_ok
== 0x01) { /* Tx IQK OK */
2030 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2031 "Path B Only Tx IQK Success!!\n");
2032 result
[t
][4] = (rtl_get_bbreg(hw
, 0xeb4, MASKDWORD
) &
2034 result
[t
][5] = (rtl_get_bbreg(hw
, 0xebc, MASKDWORD
) &
2037 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2038 "Path B IQK failed!!\n");
2042 /* Back to BB mode, load original value */
2043 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2044 "IQK:Back to BB mode, load original value!\n");
2045 rtl_set_bbreg(hw
, 0xe28, MASKDWORD
, 0);
2048 _rtl92d_phy_reload_adda_registers(hw
, iqk_bb_reg
,
2049 rtlphy
->iqk_bb_backup
,
2052 _rtl92d_phy_reload_adda_registers(hw
, iqk_bb_reg
,
2053 rtlphy
->iqk_bb_backup
,
2054 IQK_BB_REG_NUM
- 1);
2055 /* Reload MAC parameters */
2056 _rtl92d_phy_reload_mac_registers(hw
, iqk_mac_reg
,
2057 rtlphy
->iqk_mac_backup
);
2058 /* Switch back BB to SI mode after finish IQ Calibration. */
2059 if (!rtlphy
->rfpi_enable
)
2060 _rtl92d_phy_pimode_switch(hw
, false);
2061 /* Reload ADDA power saving parameters */
2062 _rtl92d_phy_reload_adda_registers(hw
, adda_reg
,
2063 rtlphy
->adda_backup
,
2066 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "<==\n");
2069 static bool _rtl92d_phy_simularity_compare(struct ieee80211_hw
*hw
,
2070 long result
[][8], u8 c1
, u8 c2
)
2072 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2073 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
2074 u32 i
, j
, diff
, sim_bitmap
, bound
;
2075 u8 final_candidate
[2] = {0xFF, 0xFF}; /* for path A and path B */
2076 bool bresult
= true;
2077 bool is2t
= IS_92D_SINGLEPHY(rtlhal
->version
);
2084 for (i
= 0; i
< bound
; i
++) {
2085 diff
= (result
[c1
][i
] > result
[c2
][i
]) ? (result
[c1
][i
] -
2086 result
[c2
][i
]) : (result
[c2
][i
] - result
[c1
][i
]);
2087 if (diff
> MAX_TOLERANCE_92D
) {
2088 if ((i
== 2 || i
== 6) && !sim_bitmap
) {
2089 if (result
[c1
][i
] + result
[c1
][i
+ 1] == 0)
2090 final_candidate
[(i
/ 4)] = c2
;
2091 else if (result
[c2
][i
] + result
[c2
][i
+ 1] == 0)
2092 final_candidate
[(i
/ 4)] = c1
;
2094 sim_bitmap
= sim_bitmap
| (1 << i
);
2096 sim_bitmap
= sim_bitmap
| (1 << i
);
2100 if (sim_bitmap
== 0) {
2101 for (i
= 0; i
< (bound
/ 4); i
++) {
2102 if (final_candidate
[i
] != 0xFF) {
2103 for (j
= i
* 4; j
< (i
+ 1) * 4 - 2; j
++)
2105 result
[final_candidate
[i
]][j
];
2111 if (!(sim_bitmap
& 0x0F)) { /* path A OK */
2112 for (i
= 0; i
< 4; i
++)
2113 result
[3][i
] = result
[c1
][i
];
2114 } else if (!(sim_bitmap
& 0x03)) { /* path A, Tx OK */
2115 for (i
= 0; i
< 2; i
++)
2116 result
[3][i
] = result
[c1
][i
];
2118 if (!(sim_bitmap
& 0xF0) && is2t
) { /* path B OK */
2119 for (i
= 4; i
< 8; i
++)
2120 result
[3][i
] = result
[c1
][i
];
2121 } else if (!(sim_bitmap
& 0x30)) { /* path B, Tx OK */
2122 for (i
= 4; i
< 6; i
++)
2123 result
[3][i
] = result
[c1
][i
];
2128 static void _rtl92d_phy_patha_fill_iqk_matrix(struct ieee80211_hw
*hw
,
2129 bool iqk_ok
, long result
[][8],
2130 u8 final_candidate
, bool txonly
)
2132 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2133 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
2134 u32 oldval_0
, val_x
, tx0_a
, reg
;
2136 bool is2t
= IS_92D_SINGLEPHY(rtlhal
->version
) ||
2137 rtlhal
->macphymode
== DUALMAC_DUALPHY
;
2139 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2140 "Path A IQ Calibration %s !\n", iqk_ok
? "Success" : "Failed");
2141 if (final_candidate
== 0xFF) {
2143 } else if (iqk_ok
) {
2144 oldval_0
= (rtl_get_bbreg(hw
, ROFDM0_XATXIQIMBALANCE
,
2145 MASKDWORD
) >> 22) & 0x3FF; /* OFDM0_D */
2146 val_x
= result
[final_candidate
][0];
2147 if ((val_x
& 0x00000200) != 0)
2148 val_x
= val_x
| 0xFFFFFC00;
2149 tx0_a
= (val_x
* oldval_0
) >> 8;
2150 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2151 "X = 0x%x, tx0_a = 0x%x, oldval_0 0x%x\n",
2152 val_x
, tx0_a
, oldval_0
);
2153 rtl_set_bbreg(hw
, ROFDM0_XATXIQIMBALANCE
, 0x3FF, tx0_a
);
2154 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
, BIT(24),
2155 ((val_x
* oldval_0
>> 7) & 0x1));
2156 val_y
= result
[final_candidate
][1];
2157 if ((val_y
& 0x00000200) != 0)
2158 val_y
= val_y
| 0xFFFFFC00;
2159 /* path B IQK result + 3 */
2160 if (rtlhal
->interfaceindex
== 1 &&
2161 rtlhal
->current_bandtype
== BAND_ON_5G
)
2163 tx0_c
= (val_y
* oldval_0
) >> 8;
2164 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2165 "Y = 0x%lx, tx0_c = 0x%lx\n",
2167 rtl_set_bbreg(hw
, ROFDM0_XCTXAFE
, 0xF0000000,
2168 ((tx0_c
& 0x3C0) >> 6));
2169 rtl_set_bbreg(hw
, ROFDM0_XATXIQIMBALANCE
, 0x003F0000,
2172 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
, BIT(26),
2173 ((val_y
* oldval_0
>> 7) & 0x1));
2174 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xC80 = 0x%x\n",
2175 rtl_get_bbreg(hw
, ROFDM0_XATXIQIMBALANCE
,
2178 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "only Tx OK\n");
2181 reg
= result
[final_candidate
][2];
2182 rtl_set_bbreg(hw
, ROFDM0_XARXIQIMBALANCE
, 0x3FF, reg
);
2183 reg
= result
[final_candidate
][3] & 0x3F;
2184 rtl_set_bbreg(hw
, ROFDM0_XARXIQIMBALANCE
, 0xFC00, reg
);
2185 reg
= (result
[final_candidate
][3] >> 6) & 0xF;
2186 rtl_set_bbreg(hw
, 0xca0, 0xF0000000, reg
);
2190 static void _rtl92d_phy_pathb_fill_iqk_matrix(struct ieee80211_hw
*hw
,
2191 bool iqk_ok
, long result
[][8], u8 final_candidate
, bool txonly
)
2193 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2194 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
2195 u32 oldval_1
, val_x
, tx1_a
, reg
;
2198 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path B IQ Calibration %s !\n",
2199 iqk_ok
? "Success" : "Failed");
2200 if (final_candidate
== 0xFF) {
2202 } else if (iqk_ok
) {
2203 oldval_1
= (rtl_get_bbreg(hw
, ROFDM0_XBTXIQIMBALANCE
,
2204 MASKDWORD
) >> 22) & 0x3FF;
2205 val_x
= result
[final_candidate
][4];
2206 if ((val_x
& 0x00000200) != 0)
2207 val_x
= val_x
| 0xFFFFFC00;
2208 tx1_a
= (val_x
* oldval_1
) >> 8;
2209 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "X = 0x%x, tx1_a = 0x%x\n",
2211 rtl_set_bbreg(hw
, ROFDM0_XBTXIQIMBALANCE
, 0x3FF, tx1_a
);
2212 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
, BIT(28),
2213 ((val_x
* oldval_1
>> 7) & 0x1));
2214 val_y
= result
[final_candidate
][5];
2215 if ((val_y
& 0x00000200) != 0)
2216 val_y
= val_y
| 0xFFFFFC00;
2217 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
2219 tx1_c
= (val_y
* oldval_1
) >> 8;
2220 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Y = 0x%lx, tx1_c = 0x%lx\n",
2222 rtl_set_bbreg(hw
, ROFDM0_XDTXAFE
, 0xF0000000,
2223 ((tx1_c
& 0x3C0) >> 6));
2224 rtl_set_bbreg(hw
, ROFDM0_XBTXIQIMBALANCE
, 0x003F0000,
2226 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
, BIT(30),
2227 ((val_y
* oldval_1
>> 7) & 0x1));
2230 reg
= result
[final_candidate
][6];
2231 rtl_set_bbreg(hw
, ROFDM0_XBRXIQIMBALANCE
, 0x3FF, reg
);
2232 reg
= result
[final_candidate
][7] & 0x3F;
2233 rtl_set_bbreg(hw
, ROFDM0_XBRXIQIMBALANCE
, 0xFC00, reg
);
2234 reg
= (result
[final_candidate
][7] >> 6) & 0xF;
2235 rtl_set_bbreg(hw
, ROFDM0_AGCRSSITABLE
, 0x0000F000, reg
);
2239 void rtl92d_phy_iq_calibrate(struct ieee80211_hw
*hw
)
2241 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2242 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2243 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
2245 u8 i
, final_candidate
, indexforchannel
;
2246 bool patha_ok
, pathb_ok
;
2247 long rege94
, rege9c
, regea4
, regeac
, regeb4
;
2248 long regebc
, regec4
, regecc
, regtmp
= 0;
2249 bool is12simular
, is13simular
, is23simular
;
2250 unsigned long flag
= 0;
2252 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2253 "IQK:Start!!!channel %d\n", rtlphy
->current_channel
);
2254 for (i
= 0; i
< 8; i
++) {
2260 final_candidate
= 0xff;
2263 is12simular
= false;
2264 is23simular
= false;
2265 is13simular
= false;
2266 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2267 "IQK !!!currentband %d\n", rtlhal
->current_bandtype
);
2268 rtl92d_acquire_cckandrw_pagea_ctl(hw
, &flag
);
2269 for (i
= 0; i
< 3; i
++) {
2270 if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
2271 _rtl92d_phy_iq_calibrate_5g_normal(hw
, result
, i
);
2272 } else if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
2273 if (IS_92D_SINGLEPHY(rtlhal
->version
))
2274 _rtl92d_phy_iq_calibrate(hw
, result
, i
, true);
2276 _rtl92d_phy_iq_calibrate(hw
, result
, i
, false);
2279 is12simular
= _rtl92d_phy_simularity_compare(hw
, result
,
2282 final_candidate
= 0;
2287 is13simular
= _rtl92d_phy_simularity_compare(hw
, result
,
2290 final_candidate
= 0;
2293 is23simular
= _rtl92d_phy_simularity_compare(hw
, result
,
2296 final_candidate
= 1;
2298 for (i
= 0; i
< 8; i
++)
2299 regtmp
+= result
[3][i
];
2302 final_candidate
= 3;
2304 final_candidate
= 0xFF;
2308 rtl92d_release_cckandrw_pagea_ctl(hw
, &flag
);
2309 for (i
= 0; i
< 4; i
++) {
2310 rege94
= result
[i
][0];
2311 rege9c
= result
[i
][1];
2312 regea4
= result
[i
][2];
2313 regeac
= result
[i
][3];
2314 regeb4
= result
[i
][4];
2315 regebc
= result
[i
][5];
2316 regec4
= result
[i
][6];
2317 regecc
= result
[i
][7];
2318 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2319 "IQK: rege94=%lx rege9c=%lx regea4=%lx regeac=%lx regeb4=%lx regebc=%lx regec4=%lx regecc=%lx\n",
2320 rege94
, rege9c
, regea4
, regeac
, regeb4
, regebc
, regec4
,
2323 if (final_candidate
!= 0xff) {
2324 rtlphy
->reg_e94
= rege94
= result
[final_candidate
][0];
2325 rtlphy
->reg_e9c
= rege9c
= result
[final_candidate
][1];
2326 regea4
= result
[final_candidate
][2];
2327 regeac
= result
[final_candidate
][3];
2328 rtlphy
->reg_eb4
= regeb4
= result
[final_candidate
][4];
2329 rtlphy
->reg_ebc
= regebc
= result
[final_candidate
][5];
2330 regec4
= result
[final_candidate
][6];
2331 regecc
= result
[final_candidate
][7];
2332 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2333 "IQK: final_candidate is %x\n", final_candidate
);
2334 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2335 "IQK: rege94=%lx rege9c=%lx regea4=%lx regeac=%lx regeb4=%lx regebc=%lx regec4=%lx regecc=%lx\n",
2336 rege94
, rege9c
, regea4
, regeac
, regeb4
, regebc
, regec4
,
2338 patha_ok
= pathb_ok
= true;
2340 rtlphy
->reg_e94
= rtlphy
->reg_eb4
= 0x100; /* X default value */
2341 rtlphy
->reg_e9c
= rtlphy
->reg_ebc
= 0x0; /* Y default value */
2343 if ((rege94
!= 0) /*&&(regea4 != 0) */)
2344 _rtl92d_phy_patha_fill_iqk_matrix(hw
, patha_ok
, result
,
2345 final_candidate
, (regea4
== 0));
2346 if (IS_92D_SINGLEPHY(rtlhal
->version
)) {
2347 if ((regeb4
!= 0) /*&&(regec4 != 0) */)
2348 _rtl92d_phy_pathb_fill_iqk_matrix(hw
, pathb_ok
, result
,
2349 final_candidate
, (regec4
== 0));
2351 if (final_candidate
!= 0xFF) {
2352 indexforchannel
= rtl92d_get_rightchnlplace_for_iqk(
2353 rtlphy
->current_channel
);
2355 for (i
= 0; i
< IQK_MATRIX_REG_NUM
; i
++)
2356 rtlphy
->iqk_matrix
[indexforchannel
].
2357 value
[0][i
] = result
[final_candidate
][i
];
2358 rtlphy
->iqk_matrix
[indexforchannel
].iqk_done
=
2361 RT_TRACE(rtlpriv
, COMP_SCAN
| COMP_MLME
, DBG_LOUD
,
2362 "IQK OK indexforchannel %d\n", indexforchannel
);
2366 void rtl92d_phy_reload_iqk_setting(struct ieee80211_hw
*hw
, u8 channel
)
2368 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2369 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2370 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
2373 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "channel %d\n", channel
);
2374 /*------Do IQK for normal chip and test chip 5G band------- */
2375 indexforchannel
= rtl92d_get_rightchnlplace_for_iqk(channel
);
2376 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "indexforchannel %d done %d\n",
2378 rtlphy
->iqk_matrix
[indexforchannel
].iqk_done
);
2379 if (0 && !rtlphy
->iqk_matrix
[indexforchannel
].iqk_done
&&
2382 RT_TRACE(rtlpriv
, COMP_SCAN
| COMP_INIT
, DBG_LOUD
,
2383 "Do IQK Matrix reg for channel:%d....\n", channel
);
2384 rtl92d_phy_iq_calibrate(hw
);
2386 /* Just load the value. */
2387 /* 2G band just load once. */
2388 if (((!rtlhal
->load_imrandiqk_setting_for2g
) &&
2389 indexforchannel
== 0) || indexforchannel
> 0) {
2390 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_LOUD
,
2391 "Just Read IQK Matrix reg for channel:%d....\n",
2393 if ((rtlphy
->iqk_matrix
[indexforchannel
].
2395 /*&&(regea4 != 0) */)
2396 _rtl92d_phy_patha_fill_iqk_matrix(hw
, true,
2398 indexforchannel
].value
, 0,
2399 (rtlphy
->iqk_matrix
[
2400 indexforchannel
].value
[0][2] == 0));
2401 if (IS_92D_SINGLEPHY(rtlhal
->version
)) {
2402 if ((rtlphy
->iqk_matrix
[
2403 indexforchannel
].value
[0][4] != 0)
2404 /*&&(regec4 != 0) */)
2405 _rtl92d_phy_pathb_fill_iqk_matrix(hw
,
2408 indexforchannel
].value
, 0,
2409 (rtlphy
->iqk_matrix
[
2410 indexforchannel
].value
[0][6]
2415 rtlphy
->need_iqk
= false;
2416 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "<====\n");
2419 static u32
_rtl92d_phy_get_abs(u32 val1
, u32 val2
)
2430 static bool _rtl92d_is_legal_5g_channel(struct ieee80211_hw
*hw
, u8 channel
)
2435 for (i
= 0; i
< sizeof(channel5g
); i
++)
2436 if (channel
== channel5g
[i
])
2441 static void _rtl92d_phy_calc_curvindex(struct ieee80211_hw
*hw
,
2442 u32
*targetchnl
, u32
* curvecount_val
,
2443 bool is5g
, u32
*curveindex
)
2445 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2446 u32 smallest_abs_val
= 0xffffffff, u4tmp
;
2448 u8 chnl_num
= is5g
? TARGET_CHNL_NUM_5G
: TARGET_CHNL_NUM_2G
;
2450 for (i
= 0; i
< chnl_num
; i
++) {
2451 if (is5g
&& !_rtl92d_is_legal_5g_channel(hw
, i
+ 1))
2454 for (j
= 0; j
< (CV_CURVE_CNT
* 2); j
++) {
2455 u4tmp
= _rtl92d_phy_get_abs(targetchnl
[i
],
2458 if (u4tmp
< smallest_abs_val
) {
2460 smallest_abs_val
= u4tmp
;
2463 smallest_abs_val
= 0xffffffff;
2464 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "curveindex[%d] = %x\n",
2469 static void _rtl92d_phy_reload_lck_setting(struct ieee80211_hw
*hw
,
2472 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2473 u8 erfpath
= rtlpriv
->rtlhal
.current_bandtype
==
2474 BAND_ON_5G
? RF90_PATH_A
:
2475 IS_92D_SINGLEPHY(rtlpriv
->rtlhal
.version
) ?
2476 RF90_PATH_B
: RF90_PATH_A
;
2477 u32 u4tmp
= 0, u4regvalue
= 0;
2478 bool bneed_powerdown_radio
= false;
2480 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "path %d\n", erfpath
);
2481 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "band type = %d\n",
2482 rtlpriv
->rtlhal
.current_bandtype
);
2483 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "channel = %d\n", channel
);
2484 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_5G
) {/* Path-A for 5G */
2485 u4tmp
= curveindex_5g
[channel
-1];
2486 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2487 "ver 1 set RF-A, 5G, 0x28 = 0x%x !!\n", u4tmp
);
2488 if (rtlpriv
->rtlhal
.macphymode
== DUALMAC_DUALPHY
&&
2489 rtlpriv
->rtlhal
.interfaceindex
== 1) {
2490 bneed_powerdown_radio
=
2491 rtl92d_phy_enable_anotherphy(hw
, false);
2492 rtlpriv
->rtlhal
.during_mac1init_radioa
= true;
2493 /* asume no this case */
2494 if (bneed_powerdown_radio
)
2495 _rtl92d_phy_enable_rf_env(hw
, erfpath
,
2498 rtl_set_rfreg(hw
, erfpath
, RF_SYN_G4
, 0x3f800, u4tmp
);
2499 if (bneed_powerdown_radio
)
2500 _rtl92d_phy_restore_rf_env(hw
, erfpath
, &u4regvalue
);
2501 if (rtlpriv
->rtlhal
.during_mac1init_radioa
)
2502 rtl92d_phy_powerdown_anotherphy(hw
, false);
2503 } else if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
) {
2504 u4tmp
= curveindex_2g
[channel
-1];
2505 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2506 "ver 3 set RF-B, 2G, 0x28 = 0x%x !!\n", u4tmp
);
2507 if (rtlpriv
->rtlhal
.macphymode
== DUALMAC_DUALPHY
&&
2508 rtlpriv
->rtlhal
.interfaceindex
== 0) {
2509 bneed_powerdown_radio
=
2510 rtl92d_phy_enable_anotherphy(hw
, true);
2511 rtlpriv
->rtlhal
.during_mac0init_radiob
= true;
2512 if (bneed_powerdown_radio
)
2513 _rtl92d_phy_enable_rf_env(hw
, erfpath
,
2516 rtl_set_rfreg(hw
, erfpath
, RF_SYN_G4
, 0x3f800, u4tmp
);
2517 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2518 "ver 3 set RF-B, 2G, 0x28 = 0x%x !!\n",
2519 rtl_get_rfreg(hw
, erfpath
, RF_SYN_G4
, 0x3f800));
2520 if (bneed_powerdown_radio
)
2521 _rtl92d_phy_restore_rf_env(hw
, erfpath
, &u4regvalue
);
2522 if (rtlpriv
->rtlhal
.during_mac0init_radiob
)
2523 rtl92d_phy_powerdown_anotherphy(hw
, true);
2525 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "<====\n");
2528 static void _rtl92d_phy_lc_calibrate_sw(struct ieee80211_hw
*hw
, bool is2t
)
2530 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2531 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
2532 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2533 u8 tmpreg
, index
, rf_mode
[2];
2534 u8 path
= is2t
? 2 : 1;
2537 u32 curvecount_val
[CV_CURVE_CNT
* 2] = {0};
2538 u16 timeout
= 800, timecount
= 0;
2540 /* Check continuous TX and Packet TX */
2541 tmpreg
= rtl_read_byte(rtlpriv
, 0xd03);
2542 /* if Deal with contisuous TX case, disable all continuous TX */
2543 /* if Deal with Packet TX case, block all queues */
2544 if ((tmpreg
& 0x70) != 0)
2545 rtl_write_byte(rtlpriv
, 0xd03, tmpreg
& 0x8F);
2547 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0xFF);
2548 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
, 0xF00000, 0x0F);
2549 for (index
= 0; index
< path
; index
++) {
2550 /* 1. Read original RF mode */
2551 offset
= index
== 0 ? ROFDM0_XAAGCCORE1
: ROFDM0_XBAGCCORE1
;
2552 rf_mode
[index
] = rtl_read_byte(rtlpriv
, offset
);
2553 /* 2. Set RF mode = standby mode */
2554 rtl_set_rfreg(hw
, (enum radio_path
)index
, RF_AC
,
2555 RFREG_OFFSET_MASK
, 0x010000);
2556 if (rtlpci
->init_ready
) {
2557 /* switch CV-curve control by LC-calibration */
2558 rtl_set_rfreg(hw
, (enum radio_path
)index
, RF_SYN_G7
,
2560 /* 4. Set LC calibration begin */
2561 rtl_set_rfreg(hw
, (enum radio_path
)index
, RF_CHNLBW
,
2564 u4tmp
= rtl_get_rfreg(hw
, (enum radio_path
)index
, RF_SYN_G6
,
2566 while ((!(u4tmp
& BIT(11))) && timecount
<= timeout
) {
2569 u4tmp
= rtl_get_rfreg(hw
, (enum radio_path
)index
,
2570 RF_SYN_G6
, RFREG_OFFSET_MASK
);
2572 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2573 "PHY_LCK finish delay for %d ms=2\n", timecount
);
2574 u4tmp
= rtl_get_rfreg(hw
, index
, RF_SYN_G4
, RFREG_OFFSET_MASK
);
2575 if (index
== 0 && rtlhal
->interfaceindex
== 0) {
2576 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2577 "path-A / 5G LCK\n");
2579 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2580 "path-B / 2.4G LCK\n");
2582 memset(&curvecount_val
[0], 0, CV_CURVE_CNT
* 2);
2583 /* Set LC calibration off */
2584 rtl_set_rfreg(hw
, (enum radio_path
)index
, RF_CHNLBW
,
2586 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "set RF 0x18[15] = 0\n");
2587 /* save Curve-counting number */
2588 for (i
= 0; i
< CV_CURVE_CNT
; i
++) {
2589 u32 readval
= 0, readval2
= 0;
2590 rtl_set_rfreg(hw
, (enum radio_path
)index
, 0x3F,
2593 rtl_set_rfreg(hw
, (enum radio_path
)index
, 0x4D,
2594 RFREG_OFFSET_MASK
, 0x0);
2595 readval
= rtl_get_rfreg(hw
, (enum radio_path
)index
,
2596 0x4F, RFREG_OFFSET_MASK
);
2597 curvecount_val
[2 * i
+ 1] = (readval
& 0xfffe0) >> 5;
2598 /* reg 0x4f [4:0] */
2599 /* reg 0x50 [19:10] */
2600 readval2
= rtl_get_rfreg(hw
, (enum radio_path
)index
,
2602 curvecount_val
[2 * i
] = (((readval
& 0x1F) << 10) |
2605 if (index
== 0 && rtlhal
->interfaceindex
== 0)
2606 _rtl92d_phy_calc_curvindex(hw
, targetchnl_5g
,
2608 true, curveindex_5g
);
2610 _rtl92d_phy_calc_curvindex(hw
, targetchnl_2g
,
2612 false, curveindex_2g
);
2613 /* switch CV-curve control mode */
2614 rtl_set_rfreg(hw
, (enum radio_path
)index
, RF_SYN_G7
,
2618 /* Restore original situation */
2619 for (index
= 0; index
< path
; index
++) {
2620 offset
= index
== 0 ? ROFDM0_XAAGCCORE1
: ROFDM0_XBAGCCORE1
;
2621 rtl_write_byte(rtlpriv
, offset
, 0x50);
2622 rtl_write_byte(rtlpriv
, offset
, rf_mode
[index
]);
2624 if ((tmpreg
& 0x70) != 0)
2625 rtl_write_byte(rtlpriv
, 0xd03, tmpreg
);
2626 else /*Deal with Packet TX case */
2627 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0x00);
2628 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
, 0xF00000, 0x00);
2629 _rtl92d_phy_reload_lck_setting(hw
, rtlpriv
->phy
.current_channel
);
2632 static void _rtl92d_phy_lc_calibrate(struct ieee80211_hw
*hw
, bool is2t
)
2634 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2636 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "cosa PHY_LCK ver=2\n");
2637 _rtl92d_phy_lc_calibrate_sw(hw
, is2t
);
2640 void rtl92d_phy_lc_calibrate(struct ieee80211_hw
*hw
)
2642 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2643 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2644 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
2645 u32 timeout
= 2000, timecount
= 0;
2647 while (rtlpriv
->mac80211
.act_scanning
&& timecount
< timeout
) {
2652 rtlphy
->lck_inprogress
= true;
2653 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2654 "LCK:Start!!! currentband %x delay %d ms\n",
2655 rtlhal
->current_bandtype
, timecount
);
2656 if (IS_92D_SINGLEPHY(rtlhal
->version
)) {
2657 _rtl92d_phy_lc_calibrate(hw
, true);
2660 _rtl92d_phy_lc_calibrate(hw
, false);
2662 rtlphy
->lck_inprogress
= false;
2663 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "LCK:Finish!!!\n");
2666 void rtl92d_phy_ap_calibrate(struct ieee80211_hw
*hw
, s8 delta
)
2671 static bool _rtl92d_phy_set_sw_chnl_cmdarray(struct swchnlcmd
*cmdtable
,
2672 u32 cmdtableidx
, u32 cmdtablesz
, enum swchnlcmd_id cmdid
,
2673 u32 para1
, u32 para2
, u32 msdelay
)
2675 struct swchnlcmd
*pcmd
;
2677 if (cmdtable
== NULL
) {
2678 WARN_ONCE(true, "rtl8192de: cmdtable cannot be NULL\n");
2681 if (cmdtableidx
>= cmdtablesz
)
2684 pcmd
= cmdtable
+ cmdtableidx
;
2685 pcmd
->cmdid
= cmdid
;
2686 pcmd
->para1
= para1
;
2687 pcmd
->para2
= para2
;
2688 pcmd
->msdelay
= msdelay
;
2692 void rtl92d_phy_reset_iqk_result(struct ieee80211_hw
*hw
)
2694 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2695 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2698 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2699 "settings regs %d default regs %d\n",
2700 (int)(sizeof(rtlphy
->iqk_matrix
) /
2701 sizeof(struct iqk_matrix_regs
)),
2702 IQK_MATRIX_REG_NUM
);
2703 /* 0xe94, 0xe9c, 0xea4, 0xeac, 0xeb4, 0xebc, 0xec4, 0xecc */
2704 for (i
= 0; i
< IQK_MATRIX_SETTINGS_NUM
; i
++) {
2705 rtlphy
->iqk_matrix
[i
].value
[0][0] = 0x100;
2706 rtlphy
->iqk_matrix
[i
].value
[0][2] = 0x100;
2707 rtlphy
->iqk_matrix
[i
].value
[0][4] = 0x100;
2708 rtlphy
->iqk_matrix
[i
].value
[0][6] = 0x100;
2709 rtlphy
->iqk_matrix
[i
].value
[0][1] = 0x0;
2710 rtlphy
->iqk_matrix
[i
].value
[0][3] = 0x0;
2711 rtlphy
->iqk_matrix
[i
].value
[0][5] = 0x0;
2712 rtlphy
->iqk_matrix
[i
].value
[0][7] = 0x0;
2713 rtlphy
->iqk_matrix
[i
].iqk_done
= false;
2717 static bool _rtl92d_phy_sw_chnl_step_by_step(struct ieee80211_hw
*hw
,
2718 u8 channel
, u8
*stage
, u8
*step
,
2721 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2722 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2723 struct swchnlcmd precommoncmd
[MAX_PRECMD_CNT
];
2724 u32 precommoncmdcnt
;
2725 struct swchnlcmd postcommoncmd
[MAX_POSTCMD_CNT
];
2726 u32 postcommoncmdcnt
;
2727 struct swchnlcmd rfdependcmd
[MAX_RFDEPENDCMD_CNT
];
2729 struct swchnlcmd
*currentcmd
= NULL
;
2731 u8 num_total_rfpath
= rtlphy
->num_total_rfpath
;
2733 precommoncmdcnt
= 0;
2734 _rtl92d_phy_set_sw_chnl_cmdarray(precommoncmd
, precommoncmdcnt
++,
2736 CMDID_SET_TXPOWEROWER_LEVEL
, 0, 0, 0);
2737 _rtl92d_phy_set_sw_chnl_cmdarray(precommoncmd
, precommoncmdcnt
++,
2738 MAX_PRECMD_CNT
, CMDID_END
, 0, 0, 0);
2739 postcommoncmdcnt
= 0;
2740 _rtl92d_phy_set_sw_chnl_cmdarray(postcommoncmd
, postcommoncmdcnt
++,
2741 MAX_POSTCMD_CNT
, CMDID_END
, 0, 0, 0);
2743 _rtl92d_phy_set_sw_chnl_cmdarray(rfdependcmd
, rfdependcmdcnt
++,
2744 MAX_RFDEPENDCMD_CNT
, CMDID_RF_WRITEREG
,
2745 RF_CHNLBW
, channel
, 0);
2746 _rtl92d_phy_set_sw_chnl_cmdarray(rfdependcmd
, rfdependcmdcnt
++,
2747 MAX_RFDEPENDCMD_CNT
, CMDID_END
,
2753 currentcmd
= &precommoncmd
[*step
];
2756 currentcmd
= &rfdependcmd
[*step
];
2759 currentcmd
= &postcommoncmd
[*step
];
2762 if (currentcmd
->cmdid
== CMDID_END
) {
2763 if ((*stage
) == 2) {
2771 switch (currentcmd
->cmdid
) {
2772 case CMDID_SET_TXPOWEROWER_LEVEL
:
2773 rtl92d_phy_set_txpower_level(hw
, channel
);
2775 case CMDID_WRITEPORT_ULONG
:
2776 rtl_write_dword(rtlpriv
, currentcmd
->para1
,
2779 case CMDID_WRITEPORT_USHORT
:
2780 rtl_write_word(rtlpriv
, currentcmd
->para1
,
2781 (u16
)currentcmd
->para2
);
2783 case CMDID_WRITEPORT_UCHAR
:
2784 rtl_write_byte(rtlpriv
, currentcmd
->para1
,
2785 (u8
)currentcmd
->para2
);
2787 case CMDID_RF_WRITEREG
:
2788 for (rfpath
= 0; rfpath
< num_total_rfpath
; rfpath
++) {
2789 rtlphy
->rfreg_chnlval
[rfpath
] =
2790 ((rtlphy
->rfreg_chnlval
[rfpath
] &
2791 0xffffff00) | currentcmd
->para2
);
2792 if (rtlpriv
->rtlhal
.current_bandtype
==
2794 if (currentcmd
->para2
> 99)
2795 rtlphy
->rfreg_chnlval
[rfpath
] =
2796 rtlphy
->rfreg_chnlval
2797 [rfpath
] | (BIT(18));
2799 rtlphy
->rfreg_chnlval
[rfpath
] =
2800 rtlphy
->rfreg_chnlval
2801 [rfpath
] & (~BIT(18));
2802 rtlphy
->rfreg_chnlval
[rfpath
] |=
2805 rtlphy
->rfreg_chnlval
[rfpath
] &=
2806 ~(BIT(8) | BIT(16) | BIT(18));
2808 rtl_set_rfreg(hw
, (enum radio_path
)rfpath
,
2811 rtlphy
->rfreg_chnlval
[rfpath
]);
2812 _rtl92d_phy_reload_imr_setting(hw
, channel
,
2815 _rtl92d_phy_switch_rf_setting(hw
, channel
);
2816 /* do IQK when all parameters are ready */
2817 rtl92d_phy_reload_iqk_setting(hw
, channel
);
2820 pr_err("switch case %#x not processed\n",
2826 (*delay
) = currentcmd
->msdelay
;
2831 u8
rtl92d_phy_sw_chnl(struct ieee80211_hw
*hw
)
2833 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2834 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2835 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2837 u32 timeout
= 1000, timecount
= 0;
2838 u8 channel
= rtlphy
->current_channel
;
2841 if (rtlphy
->sw_chnl_inprogress
)
2843 if (rtlphy
->set_bwmode_inprogress
)
2846 if ((is_hal_stop(rtlhal
)) || (RT_CANNOT_IO(hw
))) {
2847 RT_TRACE(rtlpriv
, COMP_CHAN
, DBG_LOUD
,
2848 "sw_chnl_inprogress false driver sleep or unload\n");
2851 while (rtlphy
->lck_inprogress
&& timecount
< timeout
) {
2855 if (rtlhal
->macphymode
== SINGLEMAC_SINGLEPHY
&&
2856 rtlhal
->bandset
== BAND_ON_BOTH
) {
2857 ret_value
= rtl_get_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
,
2859 if (rtlphy
->current_channel
> 14 && !(ret_value
& BIT(0)))
2860 rtl92d_phy_switch_wirelessband(hw
, BAND_ON_5G
);
2861 else if (rtlphy
->current_channel
<= 14 && (ret_value
& BIT(0)))
2862 rtl92d_phy_switch_wirelessband(hw
, BAND_ON_2_4G
);
2864 switch (rtlhal
->current_bandtype
) {
2866 /* Get first channel error when change between
2867 * 5G and 2.4G band. */
2870 WARN_ONCE((channel
<= 14), "rtl8192de: 5G but channel<=14\n");
2873 /* Get first channel error when change between
2874 * 5G and 2.4G band. */
2877 WARN_ONCE((channel
> 14), "rtl8192de: 2G but channel>14\n");
2880 WARN_ONCE(true, "rtl8192de: Invalid WirelessMode(%#x)!!\n",
2881 rtlpriv
->mac80211
.mode
);
2884 rtlphy
->sw_chnl_inprogress
= true;
2887 rtlphy
->sw_chnl_stage
= 0;
2888 rtlphy
->sw_chnl_step
= 0;
2889 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_TRACE
,
2890 "switch to channel%d\n", rtlphy
->current_channel
);
2893 if (!rtlphy
->sw_chnl_inprogress
)
2895 if (!_rtl92d_phy_sw_chnl_step_by_step(hw
,
2896 rtlphy
->current_channel
,
2897 &rtlphy
->sw_chnl_stage
, &rtlphy
->sw_chnl_step
, &delay
)) {
2903 rtlphy
->sw_chnl_inprogress
= false;
2907 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_TRACE
, "<==\n");
2908 rtlphy
->sw_chnl_inprogress
= false;
2912 static void rtl92d_phy_set_io(struct ieee80211_hw
*hw
)
2914 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2915 struct dig_t
*de_digtable
= &rtlpriv
->dm_digtable
;
2916 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2918 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
,
2919 "--->Cmd(%#x), set_io_inprogress(%d)\n",
2920 rtlphy
->current_io_type
, rtlphy
->set_io_inprogress
);
2921 switch (rtlphy
->current_io_type
) {
2922 case IO_CMD_RESUME_DM_BY_SCAN
:
2923 de_digtable
->cur_igvalue
= rtlphy
->initgain_backup
.xaagccore1
;
2924 rtl92d_dm_write_dig(hw
);
2925 rtl92d_phy_set_txpower_level(hw
, rtlphy
->current_channel
);
2927 case IO_CMD_PAUSE_DM_BY_SCAN
:
2928 rtlphy
->initgain_backup
.xaagccore1
= de_digtable
->cur_igvalue
;
2929 de_digtable
->cur_igvalue
= 0x37;
2930 rtl92d_dm_write_dig(hw
);
2933 pr_err("switch case %#x not processed\n",
2934 rtlphy
->current_io_type
);
2937 rtlphy
->set_io_inprogress
= false;
2938 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
, "<---(%#x)\n",
2939 rtlphy
->current_io_type
);
2942 bool rtl92d_phy_set_io_cmd(struct ieee80211_hw
*hw
, enum io_type iotype
)
2944 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2945 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2946 bool postprocessing
= false;
2948 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
,
2949 "-->IO Cmd(%#x), set_io_inprogress(%d)\n",
2950 iotype
, rtlphy
->set_io_inprogress
);
2953 case IO_CMD_RESUME_DM_BY_SCAN
:
2954 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
,
2955 "[IO CMD] Resume DM after scan\n");
2956 postprocessing
= true;
2958 case IO_CMD_PAUSE_DM_BY_SCAN
:
2959 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
,
2960 "[IO CMD] Pause DM before scan\n");
2961 postprocessing
= true;
2964 pr_err("switch case %#x not processed\n",
2969 if (postprocessing
&& !rtlphy
->set_io_inprogress
) {
2970 rtlphy
->set_io_inprogress
= true;
2971 rtlphy
->current_io_type
= iotype
;
2975 rtl92d_phy_set_io(hw
);
2976 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
, "<--IO Type(%#x)\n", iotype
);
2980 static void _rtl92d_phy_set_rfon(struct ieee80211_hw
*hw
)
2982 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2984 /* a. SYS_CLKR 0x08[11] = 1 restore MAC clock */
2985 /* b. SPS_CTRL 0x11[7:0] = 0x2b */
2986 if (rtlpriv
->rtlhal
.macphymode
== SINGLEMAC_SINGLEPHY
)
2987 rtl_write_byte(rtlpriv
, REG_SPS0_CTRL
, 0x2b);
2988 /* c. For PCIE: SYS_FUNC_EN 0x02[7:0] = 0xE3 enable BB TRX function */
2989 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE3);
2990 /* RF_ON_EXCEP(d~g): */
2991 /* d. APSD_CTRL 0x600[7:0] = 0x00 */
2992 rtl_write_byte(rtlpriv
, REG_APSD_CTRL
, 0x00);
2993 /* e. SYS_FUNC_EN 0x02[7:0] = 0xE2 reset BB TRX function again */
2994 /* f. SYS_FUNC_EN 0x02[7:0] = 0xE3 enable BB TRX function*/
2995 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE2);
2996 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE3);
2997 /* g. txpause 0x522[7:0] = 0x00 enable mac tx queue */
2998 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0x00);
3001 static void _rtl92d_phy_set_rfsleep(struct ieee80211_hw
*hw
)
3003 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3007 /* a. TXPAUSE 0x522[7:0] = 0xFF Pause MAC TX queue */
3008 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0xFF);
3009 /* b. RF path 0 offset 0x00 = 0x00 disable RF */
3010 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x00, RFREG_OFFSET_MASK
, 0x00);
3011 /* c. APSD_CTRL 0x600[7:0] = 0x40 */
3012 rtl_write_byte(rtlpriv
, REG_APSD_CTRL
, 0x40);
3013 /* d. APSD_CTRL 0x600[7:0] = 0x00
3014 * APSD_CTRL 0x600[7:0] = 0x00
3015 * RF path 0 offset 0x00 = 0x00
3016 * APSD_CTRL 0x600[7:0] = 0x40
3018 u4btmp
= rtl_get_rfreg(hw
, RF90_PATH_A
, 0, RFREG_OFFSET_MASK
);
3019 while (u4btmp
!= 0 && delay
> 0) {
3020 rtl_write_byte(rtlpriv
, REG_APSD_CTRL
, 0x0);
3021 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x00, RFREG_OFFSET_MASK
, 0x00);
3022 rtl_write_byte(rtlpriv
, REG_APSD_CTRL
, 0x40);
3023 u4btmp
= rtl_get_rfreg(hw
, RF90_PATH_A
, 0, RFREG_OFFSET_MASK
);
3027 /* Jump out the LPS turn off sequence to RF_ON_EXCEP */
3028 rtl_write_byte(rtlpriv
, REG_APSD_CTRL
, 0x00);
3030 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE2);
3031 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE3);
3032 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0x00);
3033 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
3034 "Fail !!! Switch RF timeout\n");
3037 /* e. For PCIE: SYS_FUNC_EN 0x02[7:0] = 0xE2 reset BB TRX function */
3038 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE2);
3039 /* f. SPS_CTRL 0x11[7:0] = 0x22 */
3040 if (rtlpriv
->rtlhal
.macphymode
== SINGLEMAC_SINGLEPHY
)
3041 rtl_write_byte(rtlpriv
, REG_SPS0_CTRL
, 0x22);
3042 /* g. SYS_CLKR 0x08[11] = 0 gated MAC clock */
3045 bool rtl92d_phy_set_rf_power_state(struct ieee80211_hw
*hw
,
3046 enum rf_pwrstate rfpwr_state
)
3049 bool bresult
= true;
3050 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3051 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
3052 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
3053 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
3054 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
3056 struct rtl8192_tx_ring
*ring
= NULL
;
3058 if (rfpwr_state
== ppsc
->rfpwr_state
)
3060 switch (rfpwr_state
) {
3062 if ((ppsc
->rfpwr_state
== ERFOFF
) &&
3063 RT_IN_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
)) {
3065 u32 initializecount
= 0;
3068 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
3069 "IPS Set eRf nic enable\n");
3070 rtstatus
= rtl_ps_enable_nic(hw
);
3071 } while (!rtstatus
&& (initializecount
< 10));
3073 RT_CLEAR_PS_LEVEL(ppsc
,
3074 RT_RF_OFF_LEVL_HALT_NIC
);
3076 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
3077 "awake, sleeped:%d ms state_inap:%x\n",
3078 jiffies_to_msecs(jiffies
-
3079 ppsc
->last_sleep_jiffies
),
3080 rtlpriv
->psc
.state_inap
);
3081 ppsc
->last_awake_jiffies
= jiffies
;
3082 _rtl92d_phy_set_rfon(hw
);
3085 if (mac
->link_state
== MAC80211_LINKED
)
3086 rtlpriv
->cfg
->ops
->led_control(hw
,
3089 rtlpriv
->cfg
->ops
->led_control(hw
,
3093 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_HALT_NIC
) {
3094 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
3095 "IPS Set eRf nic disable\n");
3096 rtl_ps_disable_nic(hw
);
3097 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
3099 if (ppsc
->rfoff_reason
== RF_CHANGE_BY_IPS
)
3100 rtlpriv
->cfg
->ops
->led_control(hw
,
3103 rtlpriv
->cfg
->ops
->led_control(hw
,
3108 if (ppsc
->rfpwr_state
== ERFOFF
)
3111 for (queue_id
= 0, i
= 0;
3112 queue_id
< RTL_PCI_MAX_TX_QUEUE_COUNT
;) {
3113 ring
= &pcipriv
->dev
.tx_ring
[queue_id
];
3114 if (skb_queue_len(&ring
->queue
) == 0 ||
3115 queue_id
== BEACON_QUEUE
) {
3118 } else if (rtlpci
->pdev
->current_state
!= PCI_D0
) {
3119 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
3120 "eRf Off/Sleep: %d times TcbBusyQueue[%d] !=0 but lower power state!\n",
3124 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
3125 "eRf Off/Sleep: %d times TcbBusyQueue[%d] =%d before doze!\n",
3127 skb_queue_len(&ring
->queue
));
3132 if (i
>= MAX_DOZE_WAITING_TIMES_9x
) {
3133 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
3134 "ERFOFF: %d times TcbBusyQueue[%d] = %d !\n",
3135 MAX_DOZE_WAITING_TIMES_9x
, queue_id
,
3136 skb_queue_len(&ring
->queue
));
3140 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
3141 "Set rfsleep awaked:%d ms\n",
3142 jiffies_to_msecs(jiffies
- ppsc
->last_awake_jiffies
));
3143 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
3144 "sleep awaked:%d ms state_inap:%x\n",
3145 jiffies_to_msecs(jiffies
-
3146 ppsc
->last_awake_jiffies
),
3147 rtlpriv
->psc
.state_inap
);
3148 ppsc
->last_sleep_jiffies
= jiffies
;
3149 _rtl92d_phy_set_rfsleep(hw
);
3152 pr_err("switch case %#x not processed\n",
3158 ppsc
->rfpwr_state
= rfpwr_state
;
3162 void rtl92d_phy_config_macphymode(struct ieee80211_hw
*hw
)
3164 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3165 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3166 u8 offset
= REG_MAC_PHY_CTRL_NORMAL
;
3168 switch (rtlhal
->macphymode
) {
3169 case DUALMAC_DUALPHY
:
3170 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3171 "MacPhyMode: DUALMAC_DUALPHY\n");
3172 rtl_write_byte(rtlpriv
, offset
, 0xF3);
3174 case SINGLEMAC_SINGLEPHY
:
3175 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3176 "MacPhyMode: SINGLEMAC_SINGLEPHY\n");
3177 rtl_write_byte(rtlpriv
, offset
, 0xF4);
3179 case DUALMAC_SINGLEPHY
:
3180 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3181 "MacPhyMode: DUALMAC_SINGLEPHY\n");
3182 rtl_write_byte(rtlpriv
, offset
, 0xF1);
3187 void rtl92d_phy_config_macphymode_info(struct ieee80211_hw
*hw
)
3189 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3190 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3191 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
3193 switch (rtlhal
->macphymode
) {
3194 case DUALMAC_SINGLEPHY
:
3195 rtlphy
->rf_type
= RF_2T2R
;
3196 rtlhal
->version
|= RF_TYPE_2T2R
;
3197 rtlhal
->bandset
= BAND_ON_BOTH
;
3198 rtlhal
->current_bandtype
= BAND_ON_2_4G
;
3201 case SINGLEMAC_SINGLEPHY
:
3202 rtlphy
->rf_type
= RF_2T2R
;
3203 rtlhal
->version
|= RF_TYPE_2T2R
;
3204 rtlhal
->bandset
= BAND_ON_BOTH
;
3205 rtlhal
->current_bandtype
= BAND_ON_2_4G
;
3208 case DUALMAC_DUALPHY
:
3209 rtlphy
->rf_type
= RF_1T1R
;
3210 rtlhal
->version
&= RF_TYPE_1T1R
;
3211 /* Now we let MAC0 run on 5G band. */
3212 if (rtlhal
->interfaceindex
== 0) {
3213 rtlhal
->bandset
= BAND_ON_5G
;
3214 rtlhal
->current_bandtype
= BAND_ON_5G
;
3216 rtlhal
->bandset
= BAND_ON_2_4G
;
3217 rtlhal
->current_bandtype
= BAND_ON_2_4G
;
3225 u8
rtl92d_get_chnlgroup_fromarray(u8 chnl
)
3228 u8 channel_info
[59] = {
3229 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
3230 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56,
3231 58, 60, 62, 64, 100, 102, 104, 106, 108,
3232 110, 112, 114, 116, 118, 120, 122, 124,
3233 126, 128, 130, 132, 134, 136, 138, 140,
3234 149, 151, 153, 155, 157, 159, 161, 163,
3238 if (channel_info
[chnl
] <= 3)
3240 else if (channel_info
[chnl
] <= 9)
3242 else if (channel_info
[chnl
] <= 14)
3244 else if (channel_info
[chnl
] <= 44)
3246 else if (channel_info
[chnl
] <= 54)
3248 else if (channel_info
[chnl
] <= 64)
3250 else if (channel_info
[chnl
] <= 112)
3252 else if (channel_info
[chnl
] <= 126)
3254 else if (channel_info
[chnl
] <= 140)
3256 else if (channel_info
[chnl
] <= 153)
3258 else if (channel_info
[chnl
] <= 159)
3265 void rtl92d_phy_set_poweron(struct ieee80211_hw
*hw
)
3267 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3268 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3269 unsigned long flags
;
3272 u32 mac_reg
= (rtlhal
->interfaceindex
== 0 ? REG_MAC0
: REG_MAC1
);
3274 /* notice fw know band status 0x81[1]/0x53[1] = 0: 5G, 1: 2G */
3275 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
3276 value8
= rtl_read_byte(rtlpriv
, mac_reg
);
3278 rtl_write_byte(rtlpriv
, mac_reg
, value8
);
3280 value8
= rtl_read_byte(rtlpriv
, mac_reg
);
3281 value8
&= (~BIT(1));
3282 rtl_write_byte(rtlpriv
, mac_reg
, value8
);
3285 if (rtlhal
->macphymode
== SINGLEMAC_SINGLEPHY
) {
3286 value8
= rtl_read_byte(rtlpriv
, REG_MAC0
);
3287 rtl_write_byte(rtlpriv
, REG_MAC0
, value8
| MAC0_ON
);
3289 spin_lock_irqsave(&globalmutex_power
, flags
);
3290 if (rtlhal
->interfaceindex
== 0) {
3291 value8
= rtl_read_byte(rtlpriv
, REG_MAC0
);
3292 rtl_write_byte(rtlpriv
, REG_MAC0
, value8
| MAC0_ON
);
3294 value8
= rtl_read_byte(rtlpriv
, REG_MAC1
);
3295 rtl_write_byte(rtlpriv
, REG_MAC1
, value8
| MAC1_ON
);
3297 value8
= rtl_read_byte(rtlpriv
, REG_POWER_OFF_IN_PROCESS
);
3298 spin_unlock_irqrestore(&globalmutex_power
, flags
);
3299 for (i
= 0; i
< 200; i
++) {
3300 if ((value8
& BIT(7)) == 0) {
3304 spin_lock_irqsave(&globalmutex_power
, flags
);
3305 value8
= rtl_read_byte(rtlpriv
,
3306 REG_POWER_OFF_IN_PROCESS
);
3307 spin_unlock_irqrestore(&globalmutex_power
,
3312 WARN_ONCE(true, "rtl8192de: Another mac power off over time\n");
3316 void rtl92d_phy_config_maccoexist_rfpage(struct ieee80211_hw
*hw
)
3318 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3320 switch (rtlpriv
->rtlhal
.macphymode
) {
3321 case DUALMAC_DUALPHY
:
3322 rtl_write_byte(rtlpriv
, REG_DMC
, 0x0);
3323 rtl_write_byte(rtlpriv
, REG_RX_PKT_LIMIT
, 0x08);
3324 rtl_write_word(rtlpriv
, REG_TRXFF_BNDY
+ 2, 0x13ff);
3326 case DUALMAC_SINGLEPHY
:
3327 rtl_write_byte(rtlpriv
, REG_DMC
, 0xf8);
3328 rtl_write_byte(rtlpriv
, REG_RX_PKT_LIMIT
, 0x08);
3329 rtl_write_word(rtlpriv
, REG_TRXFF_BNDY
+ 2, 0x13ff);
3331 case SINGLEMAC_SINGLEPHY
:
3332 rtl_write_byte(rtlpriv
, REG_DMC
, 0x0);
3333 rtl_write_byte(rtlpriv
, REG_RX_PKT_LIMIT
, 0x10);
3334 rtl_write_word(rtlpriv
, (REG_TRXFF_BNDY
+ 2), 0x27FF);
3341 void rtl92d_update_bbrf_configuration(struct ieee80211_hw
*hw
)
3343 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3344 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3345 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
3346 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
3349 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "==>\n");
3350 /* r_select_5G for path_A/B 0 for 2.4G, 1 for 5G */
3351 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
3352 /* r_select_5G for path_A/B,0x878 */
3353 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(0), 0x0);
3354 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(15), 0x0);
3355 if (rtlhal
->macphymode
!= DUALMAC_DUALPHY
) {
3356 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(16), 0x0);
3357 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(31), 0x0);
3359 /* rssi_table_select:index 0 for 2.4G.1~3 for 5G,0xc78 */
3360 rtl_set_bbreg(hw
, ROFDM0_AGCRSSITABLE
, BIT(6) | BIT(7), 0x0);
3362 rtl_set_bbreg(hw
, ROFDM1_CFOTRACKING
, BIT(14) | BIT(13), 0x0);
3364 rtl_set_bbreg(hw
, 0xB30, 0x00F00000, 0xa);
3365 /* TX BB gain shift*1,Just for testchip,0xc80,0xc88 */
3366 rtl_set_bbreg(hw
, ROFDM0_XATXIQIMBALANCE
, MASKDWORD
,
3368 rtl_set_bbreg(hw
, ROFDM0_XBTXIQIMBALANCE
, MASKDWORD
,
3370 if (rtlhal
->macphymode
== DUALMAC_DUALPHY
) {
3371 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
,
3372 BIT(10) | BIT(6) | BIT(5),
3373 ((rtlefuse
->eeprom_c9
& BIT(3)) >> 3) |
3374 (rtlefuse
->eeprom_c9
& BIT(1)) |
3375 ((rtlefuse
->eeprom_cc
& BIT(1)) << 4));
3376 rtl_set_bbreg(hw
, RFPGA0_XA_RFINTERFACEOE
,
3377 BIT(10) | BIT(6) | BIT(5),
3378 ((rtlefuse
->eeprom_c9
& BIT(2)) >> 2) |
3379 ((rtlefuse
->eeprom_c9
& BIT(0)) << 1) |
3380 ((rtlefuse
->eeprom_cc
& BIT(0)) << 5));
3381 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(15), 0);
3383 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
,
3384 BIT(26) | BIT(22) | BIT(21) | BIT(10) |
3386 ((rtlefuse
->eeprom_c9
& BIT(3)) >> 3) |
3387 (rtlefuse
->eeprom_c9
& BIT(1)) |
3388 ((rtlefuse
->eeprom_cc
& BIT(1)) << 4) |
3389 ((rtlefuse
->eeprom_c9
& BIT(7)) << 9) |
3390 ((rtlefuse
->eeprom_c9
& BIT(5)) << 12) |
3391 ((rtlefuse
->eeprom_cc
& BIT(3)) << 18));
3392 rtl_set_bbreg(hw
, RFPGA0_XA_RFINTERFACEOE
,
3393 BIT(10) | BIT(6) | BIT(5),
3394 ((rtlefuse
->eeprom_c9
& BIT(2)) >> 2) |
3395 ((rtlefuse
->eeprom_c9
& BIT(0)) << 1) |
3396 ((rtlefuse
->eeprom_cc
& BIT(0)) << 5));
3397 rtl_set_bbreg(hw
, RFPGA0_XB_RFINTERFACEOE
,
3398 BIT(10) | BIT(6) | BIT(5),
3399 ((rtlefuse
->eeprom_c9
& BIT(6)) >> 6) |
3400 ((rtlefuse
->eeprom_c9
& BIT(4)) >> 3) |
3401 ((rtlefuse
->eeprom_cc
& BIT(2)) << 3));
3402 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
,
3403 BIT(31) | BIT(15), 0);
3407 /* r_select_5G for path_A/B */
3408 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(0), 0x1);
3409 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(15), 0x1);
3410 if (rtlhal
->macphymode
!= DUALMAC_DUALPHY
) {
3411 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(16), 0x1);
3412 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(31), 0x1);
3414 /* rssi_table_select:index 0 for 2.4G.1~3 for 5G */
3415 rtl_set_bbreg(hw
, ROFDM0_AGCRSSITABLE
, BIT(6) | BIT(7), 0x1);
3417 rtl_set_bbreg(hw
, ROFDM1_CFOTRACKING
, BIT(14) | BIT(13), 0x1);
3419 rtl_set_bbreg(hw
, 0xB30, 0x00F00000, 0x0);
3420 /* TX BB gain shift,Just for testchip,0xc80,0xc88 */
3421 if (rtlefuse
->internal_pa_5g
[0])
3422 rtl_set_bbreg(hw
, ROFDM0_XATXIQIMBALANCE
, MASKDWORD
,
3425 rtl_set_bbreg(hw
, ROFDM0_XATXIQIMBALANCE
, MASKDWORD
,
3427 if (rtlefuse
->internal_pa_5g
[1])
3428 rtl_set_bbreg(hw
, ROFDM0_XBTXIQIMBALANCE
, MASKDWORD
,
3431 rtl_set_bbreg(hw
, ROFDM0_XBTXIQIMBALANCE
, MASKDWORD
,
3433 if (rtlhal
->macphymode
== DUALMAC_DUALPHY
) {
3434 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
,
3435 BIT(10) | BIT(6) | BIT(5),
3436 (rtlefuse
->eeprom_cc
& BIT(5)));
3437 rtl_set_bbreg(hw
, RFPGA0_XA_RFINTERFACEOE
, BIT(10),
3438 ((rtlefuse
->eeprom_cc
& BIT(4)) >> 4));
3439 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(15),
3440 (rtlefuse
->eeprom_cc
& BIT(4)) >> 4);
3442 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
,
3443 BIT(26) | BIT(22) | BIT(21) | BIT(10) |
3445 (rtlefuse
->eeprom_cc
& BIT(5)) |
3446 ((rtlefuse
->eeprom_cc
& BIT(7)) << 14));
3447 rtl_set_bbreg(hw
, RFPGA0_XA_RFINTERFACEOE
, BIT(10),
3448 ((rtlefuse
->eeprom_cc
& BIT(4)) >> 4));
3449 rtl_set_bbreg(hw
, RFPGA0_XB_RFINTERFACEOE
, BIT(10),
3450 ((rtlefuse
->eeprom_cc
& BIT(6)) >> 6));
3451 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
,
3453 ((rtlefuse
->eeprom_cc
& BIT(4)) >> 4) |
3454 ((rtlefuse
->eeprom_cc
& BIT(6)) << 10));
3457 /* update IQK related settings */
3458 rtl_set_bbreg(hw
, ROFDM0_XARXIQIMBALANCE
, MASKDWORD
, 0x40000100);
3459 rtl_set_bbreg(hw
, ROFDM0_XBRXIQIMBALANCE
, MASKDWORD
, 0x40000100);
3460 rtl_set_bbreg(hw
, ROFDM0_XCTXAFE
, 0xF0000000, 0x00);
3461 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
, BIT(30) | BIT(28) |
3462 BIT(26) | BIT(24), 0x00);
3463 rtl_set_bbreg(hw
, ROFDM0_XDTXAFE
, 0xF0000000, 0x00);
3464 rtl_set_bbreg(hw
, 0xca0, 0xF0000000, 0x00);
3465 rtl_set_bbreg(hw
, ROFDM0_AGCRSSITABLE
, 0x0000F000, 0x00);
3468 for (rfpath
= RF90_PATH_A
; rfpath
< rtlphy
->num_total_rfpath
;
3470 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
3471 /* MOD_AG for RF path_A 0x18 BIT8,BIT16 */
3472 rtl_set_rfreg(hw
, rfpath
, RF_CHNLBW
, BIT(8) | BIT(16) |
3474 /* RF0x0b[16:14] =3b'111 */
3475 rtl_set_rfreg(hw
, (enum radio_path
)rfpath
, 0x0B,
3478 /* MOD_AG for RF path_A 0x18 BIT8,BIT16 */
3479 rtl_set_rfreg(hw
, rfpath
, RF_CHNLBW
, BIT(8) |
3481 (BIT(16) | BIT(8)) >> 8);
3484 /* Update for all band. */
3486 if (rtlphy
->rf_type
== RF_1T1R
) {
3487 /* Use antenna 0,0xc04,0xd04 */
3488 rtl_set_bbreg(hw
, ROFDM0_TRXPATHENABLE
, MASKBYTE0
, 0x11);
3489 rtl_set_bbreg(hw
, ROFDM1_TRXPATHENABLE
, BDWORD
, 0x1);
3491 /* enable ad/da clock1 for dual-phy reg0x888 */
3492 if (rtlhal
->interfaceindex
== 0) {
3493 rtl_set_bbreg(hw
, RFPGA0_ADDALLOCKEN
, BIT(12) |
3496 rtl92d_phy_enable_anotherphy(hw
, false);
3497 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3498 "MAC1 use DBI to update 0x888\n");
3500 rtl92de_write_dword_dbi(hw
, RFPGA0_ADDALLOCKEN
,
3501 rtl92de_read_dword_dbi(hw
,
3503 BIT(3)) | BIT(12) | BIT(13),
3505 rtl92d_phy_powerdown_anotherphy(hw
, false);
3509 /* Use antenna 0 & 1,0xc04,0xd04 */
3510 rtl_set_bbreg(hw
, ROFDM0_TRXPATHENABLE
, MASKBYTE0
, 0x33);
3511 rtl_set_bbreg(hw
, ROFDM1_TRXPATHENABLE
, BDWORD
, 0x3);
3512 /* disable ad/da clock1,0x888 */
3513 rtl_set_bbreg(hw
, RFPGA0_ADDALLOCKEN
, BIT(12) | BIT(13), 0);
3515 for (rfpath
= RF90_PATH_A
; rfpath
< rtlphy
->num_total_rfpath
;
3517 rtlphy
->rfreg_chnlval
[rfpath
] = rtl_get_rfreg(hw
, rfpath
,
3518 RF_CHNLBW
, RFREG_OFFSET_MASK
);
3519 rtlphy
->reg_rf3c
[rfpath
] = rtl_get_rfreg(hw
, rfpath
, 0x3C,
3522 for (i
= 0; i
< 2; i
++)
3523 RT_TRACE(rtlpriv
, COMP_RF
, DBG_LOUD
, "RF 0x18 = 0x%x\n",
3524 rtlphy
->rfreg_chnlval
[i
]);
3525 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "<==\n");
3529 bool rtl92d_phy_check_poweroff(struct ieee80211_hw
*hw
)
3531 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3532 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3534 unsigned long flags
;
3536 if (rtlhal
->macphymode
== SINGLEMAC_SINGLEPHY
) {
3537 u1btmp
= rtl_read_byte(rtlpriv
, REG_MAC0
);
3538 rtl_write_byte(rtlpriv
, REG_MAC0
, u1btmp
& (~MAC0_ON
));
3541 spin_lock_irqsave(&globalmutex_power
, flags
);
3542 if (rtlhal
->interfaceindex
== 0) {
3543 u1btmp
= rtl_read_byte(rtlpriv
, REG_MAC0
);
3544 rtl_write_byte(rtlpriv
, REG_MAC0
, u1btmp
& (~MAC0_ON
));
3545 u1btmp
= rtl_read_byte(rtlpriv
, REG_MAC1
);
3548 u1btmp
= rtl_read_byte(rtlpriv
, REG_MAC1
);
3549 rtl_write_byte(rtlpriv
, REG_MAC1
, u1btmp
& (~MAC1_ON
));
3550 u1btmp
= rtl_read_byte(rtlpriv
, REG_MAC0
);
3554 spin_unlock_irqrestore(&globalmutex_power
, flags
);
3557 u1btmp
= rtl_read_byte(rtlpriv
, REG_POWER_OFF_IN_PROCESS
);
3559 rtl_write_byte(rtlpriv
, REG_POWER_OFF_IN_PROCESS
, u1btmp
);
3560 spin_unlock_irqrestore(&globalmutex_power
, flags
);