1 /******************************************************************************
3 * Copyright(c) 2009-2010 Realtek Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
26 * Larry Finger <Larry.Finger@lwfinger.net>
28 *****************************************************************************/
42 #define MAX_RF_IMR_INDEX 12
43 #define MAX_RF_IMR_INDEX_NORMAL 13
44 #define RF_REG_NUM_FOR_C_CUT_5G 6
45 #define RF_REG_NUM_FOR_C_CUT_5G_INTERNALPA 7
46 #define RF_REG_NUM_FOR_C_CUT_2G 5
47 #define RF_CHNL_NUM_5G 19
48 #define RF_CHNL_NUM_5G_40M 17
49 #define TARGET_CHNL_NUM_5G 221
50 #define TARGET_CHNL_NUM_2G 14
51 #define CV_CURVE_CNT 64
53 static u32 rf_reg_for_5g_swchnl_normal
[MAX_RF_IMR_INDEX_NORMAL
] = {
54 0, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x0
57 static u8 rf_reg_for_c_cut_5g
[RF_REG_NUM_FOR_C_CUT_5G
] = {
58 RF_SYN_G1
, RF_SYN_G2
, RF_SYN_G3
, RF_SYN_G4
, RF_SYN_G5
, RF_SYN_G6
61 static u8 rf_reg_for_c_cut_2g
[RF_REG_NUM_FOR_C_CUT_2G
] = {
62 RF_SYN_G1
, RF_SYN_G2
, RF_SYN_G3
, RF_SYN_G7
, RF_SYN_G8
65 static u8 rf_for_c_cut_5g_internal_pa
[RF_REG_NUM_FOR_C_CUT_5G_INTERNALPA
] = {
66 0x0B, 0x48, 0x49, 0x4B, 0x03, 0x04, 0x0E
69 static u32 rf_reg_mask_for_c_cut_2g
[RF_REG_NUM_FOR_C_CUT_2G
] = {
70 BIT(19) | BIT(18) | BIT(17) | BIT(14) | BIT(1),
72 BIT(18) | BIT(17) | BIT(16) | BIT(1),
74 BIT(15) | BIT(14) | BIT(13) | BIT(12) | BIT(11)
77 static u8 rf_chnl_5g
[RF_CHNL_NUM_5G
] = {
78 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108,
79 112, 116, 120, 124, 128, 132, 136, 140
82 static u8 rf_chnl_5g_40m
[RF_CHNL_NUM_5G_40M
] = {
83 38, 42, 46, 50, 54, 58, 62, 102, 106, 110, 114,
84 118, 122, 126, 130, 134, 138
86 static u32 rf_reg_pram_c_5g
[5][RF_REG_NUM_FOR_C_CUT_5G
] = {
87 {0xE43BE, 0xFC638, 0x77C0A, 0xDE471, 0xd7110, 0x8EB04},
88 {0xE43BE, 0xFC078, 0xF7C1A, 0xE0C71, 0xD7550, 0xAEB04},
89 {0xE43BF, 0xFF038, 0xF7C0A, 0xDE471, 0xE5550, 0xAEB04},
90 {0xE43BF, 0xFF079, 0xF7C1A, 0xDE471, 0xE5550, 0xAEB04},
91 {0xE43BF, 0xFF038, 0xF7C1A, 0xDE471, 0xd7550, 0xAEB04}
94 static u32 rf_reg_param_for_c_cut_2g
[3][RF_REG_NUM_FOR_C_CUT_2G
] = {
95 {0x643BC, 0xFC038, 0x77C1A, 0x41289, 0x01840},
96 {0x643BC, 0xFC038, 0x07C1A, 0x41289, 0x01840},
97 {0x243BC, 0xFC438, 0x07C1A, 0x4128B, 0x0FC41}
100 static u32 rf_syn_g4_for_c_cut_2g
= 0xD1C31 & 0x7FF;
102 static u32 rf_pram_c_5g_int_pa
[3][RF_REG_NUM_FOR_C_CUT_5G_INTERNALPA
] = {
103 {0x01a00, 0x40443, 0x00eb5, 0x89bec, 0x94a12, 0x94a12, 0x94a12},
104 {0x01800, 0xc0443, 0x00730, 0x896ee, 0x94a52, 0x94a52, 0x94a52},
105 {0x01800, 0xc0443, 0x00730, 0x896ee, 0x94a12, 0x94a12, 0x94a12}
108 /* [mode][patha+b][reg] */
109 static u32 rf_imr_param_normal
[1][3][MAX_RF_IMR_INDEX_NORMAL
] = {
113 0x70000, 0x00ff0, 0x4400f, 0x00ff0, 0x0, 0x0, 0x0,
114 0x0, 0x0, 0x64888, 0xe266c, 0x00090, 0x22fff
118 0x70000, 0x22880, 0x4470f, 0x55880, 0x00070, 0x88000,
119 0x0, 0x88080, 0x70000, 0x64a82, 0xe466c, 0x00090,
124 0x70000, 0x44880, 0x4477f, 0x77880, 0x00070, 0x88000,
125 0x0, 0x880b0, 0x0, 0x64b82, 0xe466c, 0x00090, 0x32c9a
130 static u32 curveindex_5g
[TARGET_CHNL_NUM_5G
] = {0};
132 static u32 curveindex_2g
[TARGET_CHNL_NUM_2G
] = {0};
134 static u32 targetchnl_5g
[TARGET_CHNL_NUM_5G
] = {
135 25141, 25116, 25091, 25066, 25041,
136 25016, 24991, 24966, 24941, 24917,
137 24892, 24867, 24843, 24818, 24794,
138 24770, 24765, 24721, 24697, 24672,
139 24648, 24624, 24600, 24576, 24552,
140 24528, 24504, 24480, 24457, 24433,
141 24409, 24385, 24362, 24338, 24315,
142 24291, 24268, 24245, 24221, 24198,
143 24175, 24151, 24128, 24105, 24082,
144 24059, 24036, 24013, 23990, 23967,
145 23945, 23922, 23899, 23876, 23854,
146 23831, 23809, 23786, 23764, 23741,
147 23719, 23697, 23674, 23652, 23630,
148 23608, 23586, 23564, 23541, 23519,
149 23498, 23476, 23454, 23432, 23410,
150 23388, 23367, 23345, 23323, 23302,
151 23280, 23259, 23237, 23216, 23194,
152 23173, 23152, 23130, 23109, 23088,
153 23067, 23046, 23025, 23003, 22982,
154 22962, 22941, 22920, 22899, 22878,
155 22857, 22837, 22816, 22795, 22775,
156 22754, 22733, 22713, 22692, 22672,
157 22652, 22631, 22611, 22591, 22570,
158 22550, 22530, 22510, 22490, 22469,
159 22449, 22429, 22409, 22390, 22370,
160 22350, 22336, 22310, 22290, 22271,
161 22251, 22231, 22212, 22192, 22173,
162 22153, 22134, 22114, 22095, 22075,
163 22056, 22037, 22017, 21998, 21979,
164 21960, 21941, 21921, 21902, 21883,
165 21864, 21845, 21826, 21807, 21789,
166 21770, 21751, 21732, 21713, 21695,
167 21676, 21657, 21639, 21620, 21602,
168 21583, 21565, 21546, 21528, 21509,
169 21491, 21473, 21454, 21436, 21418,
170 21400, 21381, 21363, 21345, 21327,
171 21309, 21291, 21273, 21255, 21237,
172 21219, 21201, 21183, 21166, 21148,
173 21130, 21112, 21095, 21077, 21059,
174 21042, 21024, 21007, 20989, 20972,
175 25679, 25653, 25627, 25601, 25575,
176 25549, 25523, 25497, 25471, 25446,
177 25420, 25394, 25369, 25343, 25318,
178 25292, 25267, 25242, 25216, 25191,
183 static u32 targetchnl_2g
[TARGET_CHNL_NUM_2G
] = {
184 26084, 26030, 25976, 25923, 25869, 25816, 25764,
185 25711, 25658, 25606, 25554, 25502, 25451, 25328
188 static u32
_rtl92d_phy_calculate_bit_shift(u32 bitmask
)
192 for (i
= 0; i
<= 31; i
++) {
193 if (((bitmask
>> i
) & 0x1) == 1)
200 u32
rtl92d_phy_query_bb_reg(struct ieee80211_hw
*hw
, u32 regaddr
, u32 bitmask
)
202 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
203 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
204 u32 returnvalue
, originalvalue
, bitshift
;
207 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
, ("regaddr(%#x), "
208 "bitmask(%#x)\n", regaddr
, bitmask
));
209 if (rtlhal
->during_mac1init_radioa
|| rtlhal
->during_mac0init_radiob
) {
210 /* mac1 use phy0 read radio_b. */
211 /* mac0 use phy1 read radio_b. */
212 if (rtlhal
->during_mac1init_radioa
)
214 else if (rtlhal
->during_mac0init_radiob
)
215 dbi_direct
= BIT(3) | BIT(2);
216 originalvalue
= rtl92de_read_dword_dbi(hw
, (u16
)regaddr
,
219 originalvalue
= rtl_read_dword(rtlpriv
, regaddr
);
221 bitshift
= _rtl92d_phy_calculate_bit_shift(bitmask
);
222 returnvalue
= (originalvalue
& bitmask
) >> bitshift
;
223 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
, ("BBR MASK=0x%x "
224 "Addr[0x%x]=0x%x\n", bitmask
, regaddr
, originalvalue
));
228 void rtl92d_phy_set_bb_reg(struct ieee80211_hw
*hw
,
229 u32 regaddr
, u32 bitmask
, u32 data
)
231 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
232 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
234 u32 originalvalue
, bitshift
;
236 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
, ("regaddr(%#x), bitmask(%#x),"
237 " data(%#x)\n", regaddr
, bitmask
, data
));
238 if (rtlhal
->during_mac1init_radioa
)
240 else if (rtlhal
->during_mac0init_radiob
)
241 /* mac0 use phy1 write radio_b. */
242 dbi_direct
= BIT(3) | BIT(2);
243 if (bitmask
!= BMASKDWORD
) {
244 if (rtlhal
->during_mac1init_radioa
||
245 rtlhal
->during_mac0init_radiob
)
246 originalvalue
= rtl92de_read_dword_dbi(hw
,
250 originalvalue
= rtl_read_dword(rtlpriv
, regaddr
);
251 bitshift
= _rtl92d_phy_calculate_bit_shift(bitmask
);
252 data
= ((originalvalue
& (~bitmask
)) | (data
<< bitshift
));
254 if (rtlhal
->during_mac1init_radioa
|| rtlhal
->during_mac0init_radiob
)
255 rtl92de_write_dword_dbi(hw
, (u16
) regaddr
, data
, dbi_direct
);
257 rtl_write_dword(rtlpriv
, regaddr
, data
);
258 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
, ("regaddr(%#x), bitmask(%#x),"
259 " data(%#x)\n", regaddr
, bitmask
, data
));
262 static u32
_rtl92d_phy_rf_serial_read(struct ieee80211_hw
*hw
,
263 enum radio_path rfpath
, u32 offset
)
266 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
267 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
268 struct bb_reg_def
*pphyreg
= &rtlphy
->phyreg_def
[rfpath
];
270 u32 tmplong
, tmplong2
;
275 tmplong
= rtl_get_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER2
, BMASKDWORD
);
276 if (rfpath
== RF90_PATH_A
)
279 tmplong2
= rtl_get_bbreg(hw
, pphyreg
->rfhssi_para2
, BMASKDWORD
);
280 tmplong2
= (tmplong2
& (~BLSSIREADADDRESS
)) |
281 (newoffset
<< 23) | BLSSIREADEDGE
;
282 rtl_set_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER2
, BMASKDWORD
,
283 tmplong
& (~BLSSIREADEDGE
));
285 rtl_set_bbreg(hw
, pphyreg
->rfhssi_para2
, BMASKDWORD
, tmplong2
);
288 rtl_set_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER2
, BMASKDWORD
,
289 tmplong
| BLSSIREADEDGE
);
291 if (rfpath
== RF90_PATH_A
)
292 rfpi_enable
= (u8
) rtl_get_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER1
,
294 else if (rfpath
== RF90_PATH_B
)
295 rfpi_enable
= (u8
) rtl_get_bbreg(hw
, RFPGA0_XB_HSSIPARAMETER1
,
298 retvalue
= rtl_get_bbreg(hw
, pphyreg
->rflssi_readbackpi
,
301 retvalue
= rtl_get_bbreg(hw
, pphyreg
->rflssi_readback
,
303 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
, ("RFR-%d Addr[0x%x] = 0x%x\n",
304 rfpath
, pphyreg
->rflssi_readback
, retvalue
));
308 static void _rtl92d_phy_rf_serial_write(struct ieee80211_hw
*hw
,
309 enum radio_path rfpath
,
310 u32 offset
, u32 data
)
314 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
315 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
316 struct bb_reg_def
*pphyreg
= &rtlphy
->phyreg_def
[rfpath
];
320 data_and_addr
= ((newoffset
<< 20) | (data
& 0x000fffff)) & 0x0fffffff;
321 rtl_set_bbreg(hw
, pphyreg
->rf3wire_offset
, BMASKDWORD
, data_and_addr
);
322 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
, ("RFW-%d Addr[0x%x]=0x%x\n",
323 rfpath
, pphyreg
->rf3wire_offset
, data_and_addr
));
326 u32
rtl92d_phy_query_rf_reg(struct ieee80211_hw
*hw
,
327 enum radio_path rfpath
, u32 regaddr
, u32 bitmask
)
329 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
330 u32 original_value
, readback_value
, bitshift
;
333 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
, ("regaddr(%#x), "
334 "rfpath(%#x), bitmask(%#x)\n",
335 regaddr
, rfpath
, bitmask
));
336 spin_lock_irqsave(&rtlpriv
->locks
.rf_lock
, flags
);
337 original_value
= _rtl92d_phy_rf_serial_read(hw
, rfpath
, regaddr
);
338 bitshift
= _rtl92d_phy_calculate_bit_shift(bitmask
);
339 readback_value
= (original_value
& bitmask
) >> bitshift
;
340 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_lock
, flags
);
341 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
, ("regaddr(%#x), rfpath(%#x), "
342 "bitmask(%#x), original_value(%#x)\n",
343 regaddr
, rfpath
, bitmask
, original_value
));
344 return readback_value
;
347 void rtl92d_phy_set_rf_reg(struct ieee80211_hw
*hw
, enum radio_path rfpath
,
348 u32 regaddr
, u32 bitmask
, u32 data
)
350 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
351 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
352 u32 original_value
, bitshift
;
355 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
356 ("regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
357 regaddr
, bitmask
, data
, rfpath
));
360 spin_lock_irqsave(&rtlpriv
->locks
.rf_lock
, flags
);
361 if (rtlphy
->rf_mode
!= RF_OP_BY_FW
) {
362 if (bitmask
!= BRFREGOFFSETMASK
) {
363 original_value
= _rtl92d_phy_rf_serial_read(hw
,
365 bitshift
= _rtl92d_phy_calculate_bit_shift(bitmask
);
366 data
= ((original_value
& (~bitmask
)) |
369 _rtl92d_phy_rf_serial_write(hw
, rfpath
, regaddr
, data
);
371 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_lock
, flags
);
372 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
, ("regaddr(%#x), "
373 "bitmask(%#x), data(%#x), rfpath(%#x)\n",
374 regaddr
, bitmask
, data
, rfpath
));
377 bool rtl92d_phy_mac_config(struct ieee80211_hw
*hw
)
379 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
384 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
, ("Read Rtl819XMACPHY_Array\n"));
385 arraylength
= MAC_2T_ARRAYLENGTH
;
386 ptrarray
= rtl8192de_mac_2tarray
;
387 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
, ("Img:Rtl819XMAC_Array\n"));
388 for (i
= 0; i
< arraylength
; i
= i
+ 2)
389 rtl_write_byte(rtlpriv
, ptrarray
[i
], (u8
) ptrarray
[i
+ 1]);
390 if (rtlpriv
->rtlhal
.macphymode
== SINGLEMAC_SINGLEPHY
) {
391 /* improve 2-stream TX EVM */
392 /* rtl_write_byte(rtlpriv, 0x14,0x71); */
393 /* AMPDU aggregation number 9 */
394 /* rtl_write_word(rtlpriv, REG_MAX_AGGR_NUM, MAX_AGGR_NUM); */
395 rtl_write_byte(rtlpriv
, REG_MAX_AGGR_NUM
, 0x0B);
397 /* 92D need to test to decide the num. */
398 rtl_write_byte(rtlpriv
, REG_MAX_AGGR_NUM
, 0x07);
403 static void _rtl92d_phy_init_bb_rf_register_definition(struct ieee80211_hw
*hw
)
405 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
406 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
408 /* RF Interface Sowrtware Control */
409 /* 16 LSBs if read 32-bit from 0x870 */
410 rtlphy
->phyreg_def
[RF90_PATH_A
].rfintfs
= RFPGA0_XAB_RFINTERFACESW
;
411 /* 16 MSBs if read 32-bit from 0x870 (16-bit for 0x872) */
412 rtlphy
->phyreg_def
[RF90_PATH_B
].rfintfs
= RFPGA0_XAB_RFINTERFACESW
;
413 /* 16 LSBs if read 32-bit from 0x874 */
414 rtlphy
->phyreg_def
[RF90_PATH_C
].rfintfs
= RFPGA0_XCD_RFINTERFACESW
;
415 /* 16 MSBs if read 32-bit from 0x874 (16-bit for 0x876) */
417 rtlphy
->phyreg_def
[RF90_PATH_D
].rfintfs
= RFPGA0_XCD_RFINTERFACESW
;
418 /* RF Interface Readback Value */
419 /* 16 LSBs if read 32-bit from 0x8E0 */
420 rtlphy
->phyreg_def
[RF90_PATH_A
].rfintfi
= RFPGA0_XAB_RFINTERFACERB
;
421 /* 16 MSBs if read 32-bit from 0x8E0 (16-bit for 0x8E2) */
422 rtlphy
->phyreg_def
[RF90_PATH_B
].rfintfi
= RFPGA0_XAB_RFINTERFACERB
;
423 /* 16 LSBs if read 32-bit from 0x8E4 */
424 rtlphy
->phyreg_def
[RF90_PATH_C
].rfintfi
= RFPGA0_XCD_RFINTERFACERB
;
425 /* 16 MSBs if read 32-bit from 0x8E4 (16-bit for 0x8E6) */
426 rtlphy
->phyreg_def
[RF90_PATH_D
].rfintfi
= RFPGA0_XCD_RFINTERFACERB
;
428 /* RF Interface Output (and Enable) */
429 /* 16 LSBs if read 32-bit from 0x860 */
430 rtlphy
->phyreg_def
[RF90_PATH_A
].rfintfo
= RFPGA0_XA_RFINTERFACEOE
;
431 /* 16 LSBs if read 32-bit from 0x864 */
432 rtlphy
->phyreg_def
[RF90_PATH_B
].rfintfo
= RFPGA0_XB_RFINTERFACEOE
;
434 /* RF Interface (Output and) Enable */
435 /* 16 MSBs if read 32-bit from 0x860 (16-bit for 0x862) */
436 rtlphy
->phyreg_def
[RF90_PATH_A
].rfintfe
= RFPGA0_XA_RFINTERFACEOE
;
437 /* 16 MSBs if read 32-bit from 0x864 (16-bit for 0x866) */
438 rtlphy
->phyreg_def
[RF90_PATH_B
].rfintfe
= RFPGA0_XB_RFINTERFACEOE
;
440 /* Addr of LSSI. Wirte RF register by driver */
442 rtlphy
->phyreg_def
[RF90_PATH_A
].rf3wire_offset
=
443 RFPGA0_XA_LSSIPARAMETER
;
444 rtlphy
->phyreg_def
[RF90_PATH_B
].rf3wire_offset
=
445 RFPGA0_XB_LSSIPARAMETER
;
449 rtlphy
->phyreg_def
[RF90_PATH_A
].rflssi_select
= RFPGA0_XAB_RFPARAMETER
;
450 rtlphy
->phyreg_def
[RF90_PATH_B
].rflssi_select
= RFPGA0_XAB_RFPARAMETER
;
451 rtlphy
->phyreg_def
[RF90_PATH_C
].rflssi_select
= RFPGA0_XCD_RFPARAMETER
;
452 rtlphy
->phyreg_def
[RF90_PATH_D
].rflssi_select
= RFPGA0_XCD_RFPARAMETER
;
454 /* Tx AGC Gain Stage (same for all path. Should we remove this?) */
456 rtlphy
->phyreg_def
[RF90_PATH_A
].rftxgain_stage
= RFPGA0_TXGAINSTAGE
;
458 rtlphy
->phyreg_def
[RF90_PATH_B
].rftxgain_stage
= RFPGA0_TXGAINSTAGE
;
460 rtlphy
->phyreg_def
[RF90_PATH_C
].rftxgain_stage
= RFPGA0_TXGAINSTAGE
;
462 rtlphy
->phyreg_def
[RF90_PATH_D
].rftxgain_stage
= RFPGA0_TXGAINSTAGE
;
464 /* Tranceiver A~D HSSI Parameter-1 */
465 /* wire control parameter1 */
466 rtlphy
->phyreg_def
[RF90_PATH_A
].rfhssi_para1
= RFPGA0_XA_HSSIPARAMETER1
;
467 /* wire control parameter1 */
468 rtlphy
->phyreg_def
[RF90_PATH_B
].rfhssi_para1
= RFPGA0_XB_HSSIPARAMETER1
;
470 /* Tranceiver A~D HSSI Parameter-2 */
471 /* wire control parameter2 */
472 rtlphy
->phyreg_def
[RF90_PATH_A
].rfhssi_para2
= RFPGA0_XA_HSSIPARAMETER2
;
473 /* wire control parameter2 */
474 rtlphy
->phyreg_def
[RF90_PATH_B
].rfhssi_para2
= RFPGA0_XB_HSSIPARAMETER2
;
476 /* RF switch Control */
477 /* TR/Ant switch control */
478 rtlphy
->phyreg_def
[RF90_PATH_A
].rfswitch_control
=
479 RFPGA0_XAB_SWITCHCONTROL
;
480 rtlphy
->phyreg_def
[RF90_PATH_B
].rfswitch_control
=
481 RFPGA0_XAB_SWITCHCONTROL
;
482 rtlphy
->phyreg_def
[RF90_PATH_C
].rfswitch_control
=
483 RFPGA0_XCD_SWITCHCONTROL
;
484 rtlphy
->phyreg_def
[RF90_PATH_D
].rfswitch_control
=
485 RFPGA0_XCD_SWITCHCONTROL
;
488 rtlphy
->phyreg_def
[RF90_PATH_A
].rfagc_control1
= ROFDM0_XAAGCCORE1
;
489 rtlphy
->phyreg_def
[RF90_PATH_B
].rfagc_control1
= ROFDM0_XBAGCCORE1
;
490 rtlphy
->phyreg_def
[RF90_PATH_C
].rfagc_control1
= ROFDM0_XCAGCCORE1
;
491 rtlphy
->phyreg_def
[RF90_PATH_D
].rfagc_control1
= ROFDM0_XDAGCCORE1
;
494 rtlphy
->phyreg_def
[RF90_PATH_A
].rfagc_control2
= ROFDM0_XAAGCCORE2
;
495 rtlphy
->phyreg_def
[RF90_PATH_B
].rfagc_control2
= ROFDM0_XBAGCCORE2
;
496 rtlphy
->phyreg_def
[RF90_PATH_C
].rfagc_control2
= ROFDM0_XCAGCCORE2
;
497 rtlphy
->phyreg_def
[RF90_PATH_D
].rfagc_control2
= ROFDM0_XDAGCCORE2
;
499 /* RX AFE control 1 */
500 rtlphy
->phyreg_def
[RF90_PATH_A
].rfrxiq_imbalance
=
501 ROFDM0_XARXIQIMBALANCE
;
502 rtlphy
->phyreg_def
[RF90_PATH_B
].rfrxiq_imbalance
=
503 ROFDM0_XBRXIQIMBALANCE
;
504 rtlphy
->phyreg_def
[RF90_PATH_C
].rfrxiq_imbalance
=
505 ROFDM0_XCRXIQIMBALANCE
;
506 rtlphy
->phyreg_def
[RF90_PATH_D
].rfrxiq_imbalance
=
507 ROFDM0_XDRXIQIMBALANCE
;
509 /*RX AFE control 1 */
510 rtlphy
->phyreg_def
[RF90_PATH_A
].rfrx_afe
= ROFDM0_XARXAFE
;
511 rtlphy
->phyreg_def
[RF90_PATH_B
].rfrx_afe
= ROFDM0_XBRXAFE
;
512 rtlphy
->phyreg_def
[RF90_PATH_C
].rfrx_afe
= ROFDM0_XCRXAFE
;
513 rtlphy
->phyreg_def
[RF90_PATH_D
].rfrx_afe
= ROFDM0_XDRXAFE
;
515 /* Tx AFE control 1 */
516 rtlphy
->phyreg_def
[RF90_PATH_A
].rftxiq_imbalance
=
517 ROFDM0_XATxIQIMBALANCE
;
518 rtlphy
->phyreg_def
[RF90_PATH_B
].rftxiq_imbalance
=
519 ROFDM0_XBTxIQIMBALANCE
;
520 rtlphy
->phyreg_def
[RF90_PATH_C
].rftxiq_imbalance
=
521 ROFDM0_XCTxIQIMBALANCE
;
522 rtlphy
->phyreg_def
[RF90_PATH_D
].rftxiq_imbalance
=
523 ROFDM0_XDTxIQIMBALANCE
;
525 /* Tx AFE control 2 */
526 rtlphy
->phyreg_def
[RF90_PATH_A
].rftx_afe
= ROFDM0_XATxAFE
;
527 rtlphy
->phyreg_def
[RF90_PATH_B
].rftx_afe
= ROFDM0_XBTxAFE
;
528 rtlphy
->phyreg_def
[RF90_PATH_C
].rftx_afe
= ROFDM0_XCTxAFE
;
529 rtlphy
->phyreg_def
[RF90_PATH_D
].rftx_afe
= ROFDM0_XDTxAFE
;
531 /* Tranceiver LSSI Readback SI mode */
532 rtlphy
->phyreg_def
[RF90_PATH_A
].rflssi_readback
=
533 RFPGA0_XA_LSSIREADBACK
;
534 rtlphy
->phyreg_def
[RF90_PATH_B
].rflssi_readback
=
535 RFPGA0_XB_LSSIREADBACK
;
536 rtlphy
->phyreg_def
[RF90_PATH_C
].rflssi_readback
=
537 RFPGA0_XC_LSSIREADBACK
;
538 rtlphy
->phyreg_def
[RF90_PATH_D
].rflssi_readback
=
539 RFPGA0_XD_LSSIREADBACK
;
541 /* Tranceiver LSSI Readback PI mode */
542 rtlphy
->phyreg_def
[RF90_PATH_A
].rflssi_readbackpi
=
543 TRANSCEIVERA_HSPI_READBACK
;
544 rtlphy
->phyreg_def
[RF90_PATH_B
].rflssi_readbackpi
=
545 TRANSCEIVERB_HSPI_READBACK
;
548 static bool _rtl92d_phy_config_bb_with_headerfile(struct ieee80211_hw
*hw
,
552 u32
*phy_regarray_table
;
553 u32
*agctab_array_table
= NULL
;
554 u32
*agctab_5garray_table
;
555 u16 phy_reg_arraylen
, agctab_arraylen
= 0, agctab_5garraylen
;
556 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
557 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
559 /* Normal chip,Mac0 use AGC_TAB.txt for 2G and 5G band. */
560 if (rtlhal
->interfaceindex
== 0) {
561 agctab_arraylen
= AGCTAB_ARRAYLENGTH
;
562 agctab_array_table
= rtl8192de_agctab_array
;
563 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
564 (" ===> phy:MAC0, Rtl819XAGCTAB_Array\n"));
566 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
567 agctab_arraylen
= AGCTAB_2G_ARRAYLENGTH
;
568 agctab_array_table
= rtl8192de_agctab_2garray
;
569 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
570 (" ===> phy:MAC1, Rtl819XAGCTAB_2GArray\n"));
572 agctab_5garraylen
= AGCTAB_5G_ARRAYLENGTH
;
573 agctab_5garray_table
= rtl8192de_agctab_5garray
;
574 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
575 (" ===> phy:MAC1, Rtl819XAGCTAB_5GArray\n"));
579 phy_reg_arraylen
= PHY_REG_2T_ARRAYLENGTH
;
580 phy_regarray_table
= rtl8192de_phy_reg_2tarray
;
581 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
582 (" ===> phy:Rtl819XPHY_REG_Array_PG\n"));
583 if (configtype
== BASEBAND_CONFIG_PHY_REG
) {
584 for (i
= 0; i
< phy_reg_arraylen
; i
= i
+ 2) {
585 if (phy_regarray_table
[i
] == 0xfe)
587 else if (phy_regarray_table
[i
] == 0xfd)
589 else if (phy_regarray_table
[i
] == 0xfc)
591 else if (phy_regarray_table
[i
] == 0xfb)
593 else if (phy_regarray_table
[i
] == 0xfa)
595 else if (phy_regarray_table
[i
] == 0xf9)
597 rtl_set_bbreg(hw
, phy_regarray_table
[i
], BMASKDWORD
,
598 phy_regarray_table
[i
+ 1]);
600 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
601 ("The phy_regarray_table[0] is %x"
602 " Rtl819XPHY_REGArray[1] is %x\n",
603 phy_regarray_table
[i
],
604 phy_regarray_table
[i
+ 1]));
606 } else if (configtype
== BASEBAND_CONFIG_AGC_TAB
) {
607 if (rtlhal
->interfaceindex
== 0) {
608 for (i
= 0; i
< agctab_arraylen
; i
= i
+ 2) {
609 rtl_set_bbreg(hw
, agctab_array_table
[i
],
611 agctab_array_table
[i
+ 1]);
612 /* Add 1us delay between BB/RF register
615 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
616 ("The Rtl819XAGCTAB_Array_"
618 "Rtl819XPHY_REGArray[1] is %ul\n",
619 agctab_array_table
[i
],
620 agctab_array_table
[i
+ 1]));
622 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
623 ("Normal Chip, MAC0, load "
624 "Rtl819XAGCTAB_Array\n"));
626 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
627 for (i
= 0; i
< agctab_arraylen
; i
= i
+ 2) {
628 rtl_set_bbreg(hw
, agctab_array_table
[i
],
630 agctab_array_table
[i
+ 1]);
631 /* Add 1us delay between BB/RF register
634 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
635 ("The Rtl819XAGCTAB_Array_"
636 "Table[0] is %ul Rtl819XPHY_"
637 "REGArray[1] is %ul\n",
638 agctab_array_table
[i
],
639 agctab_array_table
[i
+ 1]));
641 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
642 ("Load Rtl819XAGCTAB_2GArray\n"));
644 for (i
= 0; i
< agctab_5garraylen
; i
= i
+ 2) {
646 agctab_5garray_table
[i
],
648 agctab_5garray_table
[i
+ 1]);
649 /* Add 1us delay between BB/RF registeri
652 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
653 ("The Rtl819XAGCTAB_5GArray_"
654 "Table[0] is %ul Rtl819XPHY_"
655 "REGArray[1] is %ul\n",
656 agctab_5garray_table
[i
],
657 agctab_5garray_table
[i
+ 1]));
659 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
660 ("Load Rtl819XAGCTAB_5GArray\n"));
667 static void _rtl92d_store_pwrindex_diffrate_offset(struct ieee80211_hw
*hw
,
668 u32 regaddr
, u32 bitmask
,
671 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
672 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
674 if (regaddr
== RTXAGC_A_RATE18_06
) {
675 rtlphy
->mcs_txpwrlevel_origoffset
[rtlphy
->pwrgroup_cnt
][0] =
677 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
678 ("MCSTxPowerLevelOriginalOffset[%d][0] = 0x%ulx\n",
679 rtlphy
->pwrgroup_cnt
,
680 rtlphy
->mcs_txpwrlevel_origoffset
681 [rtlphy
->pwrgroup_cnt
][0]));
683 if (regaddr
== RTXAGC_A_RATE54_24
) {
684 rtlphy
->mcs_txpwrlevel_origoffset
[rtlphy
->pwrgroup_cnt
][1] =
686 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
687 ("MCSTxPowerLevelOriginalOffset[%d][1] = 0x%ulx\n",
688 rtlphy
->pwrgroup_cnt
,
689 rtlphy
->mcs_txpwrlevel_origoffset
690 [rtlphy
->pwrgroup_cnt
][1]));
692 if (regaddr
== RTXAGC_A_CCK1_MCS32
) {
693 rtlphy
->mcs_txpwrlevel_origoffset
[rtlphy
->pwrgroup_cnt
][6] =
695 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
696 ("MCSTxPowerLevelOriginalOffset[%d][6] = 0x%ulx\n",
697 rtlphy
->pwrgroup_cnt
,
698 rtlphy
->mcs_txpwrlevel_origoffset
699 [rtlphy
->pwrgroup_cnt
][6]));
701 if (regaddr
== RTXAGC_B_CCK11_A_CCK2_11
&& bitmask
== 0xffffff00) {
702 rtlphy
->mcs_txpwrlevel_origoffset
[rtlphy
->pwrgroup_cnt
][7] =
704 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
705 ("MCSTxPowerLevelOriginalOffset[%d][7] = 0x%ulx\n",
706 rtlphy
->pwrgroup_cnt
,
707 rtlphy
->mcs_txpwrlevel_origoffset
708 [rtlphy
->pwrgroup_cnt
][7]));
710 if (regaddr
== RTXAGC_A_MCS03_MCS00
) {
711 rtlphy
->mcs_txpwrlevel_origoffset
[rtlphy
->pwrgroup_cnt
][2] =
713 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
714 ("MCSTxPowerLevelOriginalOffset[%d][2] = 0x%ulx\n",
715 rtlphy
->pwrgroup_cnt
,
716 rtlphy
->mcs_txpwrlevel_origoffset
717 [rtlphy
->pwrgroup_cnt
][2]));
719 if (regaddr
== RTXAGC_A_MCS07_MCS04
) {
720 rtlphy
->mcs_txpwrlevel_origoffset
[rtlphy
->pwrgroup_cnt
][3] =
722 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
723 ("MCSTxPowerLevelOriginalOffset[%d][3] = 0x%ulx\n",
724 rtlphy
->pwrgroup_cnt
,
725 rtlphy
->mcs_txpwrlevel_origoffset
726 [rtlphy
->pwrgroup_cnt
][3]));
728 if (regaddr
== RTXAGC_A_MCS11_MCS08
) {
729 rtlphy
->mcs_txpwrlevel_origoffset
[rtlphy
->pwrgroup_cnt
][4] =
731 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
732 ("MCSTxPowerLevelOriginalOffset[%d][4] = 0x%ulx\n",
733 rtlphy
->pwrgroup_cnt
,
734 rtlphy
->mcs_txpwrlevel_origoffset
735 [rtlphy
->pwrgroup_cnt
][4]));
737 if (regaddr
== RTXAGC_A_MCS15_MCS12
) {
738 rtlphy
->mcs_txpwrlevel_origoffset
[rtlphy
->pwrgroup_cnt
][5] =
740 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
741 ("MCSTxPowerLevelOriginalOffset[%d][5] = 0x%ulx\n",
742 rtlphy
->pwrgroup_cnt
,
743 rtlphy
->mcs_txpwrlevel_origoffset
744 [rtlphy
->pwrgroup_cnt
][5]));
746 if (regaddr
== RTXAGC_B_RATE18_06
) {
747 rtlphy
->mcs_txpwrlevel_origoffset
[rtlphy
->pwrgroup_cnt
][8] =
749 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
750 ("MCSTxPowerLevelOriginalOffset[%d][8] = 0x%ulx\n",
751 rtlphy
->pwrgroup_cnt
,
752 rtlphy
->mcs_txpwrlevel_origoffset
753 [rtlphy
->pwrgroup_cnt
][8]));
755 if (regaddr
== RTXAGC_B_RATE54_24
) {
756 rtlphy
->mcs_txpwrlevel_origoffset
[rtlphy
->pwrgroup_cnt
][9] =
758 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
759 ("MCSTxPowerLevelOriginalOffset[%d][9] = 0x%ulx\n",
760 rtlphy
->pwrgroup_cnt
,
761 rtlphy
->mcs_txpwrlevel_origoffset
762 [rtlphy
->pwrgroup_cnt
][9]));
764 if (regaddr
== RTXAGC_B_CCK1_55_MCS32
) {
765 rtlphy
->mcs_txpwrlevel_origoffset
[rtlphy
->pwrgroup_cnt
][14] =
767 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
768 ("MCSTxPowerLevelOriginalOffset[%d][14] = 0x%ulx\n",
769 rtlphy
->pwrgroup_cnt
,
770 rtlphy
->mcs_txpwrlevel_origoffset
771 [rtlphy
->pwrgroup_cnt
][14]));
773 if (regaddr
== RTXAGC_B_CCK11_A_CCK2_11
&& bitmask
== 0x000000ff) {
774 rtlphy
->mcs_txpwrlevel_origoffset
[rtlphy
->pwrgroup_cnt
][15] =
776 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
777 ("MCSTxPowerLevelOriginalOffset[%d][15] = 0x%ulx\n",
778 rtlphy
->pwrgroup_cnt
,
779 rtlphy
->mcs_txpwrlevel_origoffset
780 [rtlphy
->pwrgroup_cnt
][15]));
782 if (regaddr
== RTXAGC_B_MCS03_MCS00
) {
783 rtlphy
->mcs_txpwrlevel_origoffset
[rtlphy
->pwrgroup_cnt
][10] =
785 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
786 ("MCSTxPowerLevelOriginalOffset[%d][10] = 0x%ulx\n",
787 rtlphy
->pwrgroup_cnt
,
788 rtlphy
->mcs_txpwrlevel_origoffset
789 [rtlphy
->pwrgroup_cnt
][10]));
791 if (regaddr
== RTXAGC_B_MCS07_MCS04
) {
792 rtlphy
->mcs_txpwrlevel_origoffset
[rtlphy
->pwrgroup_cnt
][11] =
794 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
795 ("MCSTxPowerLevelOriginalOffset[%d][11] = 0x%ulx\n",
796 rtlphy
->pwrgroup_cnt
,
797 rtlphy
->mcs_txpwrlevel_origoffset
798 [rtlphy
->pwrgroup_cnt
][11]));
800 if (regaddr
== RTXAGC_B_MCS11_MCS08
) {
801 rtlphy
->mcs_txpwrlevel_origoffset
[rtlphy
->pwrgroup_cnt
][12] =
803 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
804 ("MCSTxPowerLevelOriginalOffset[%d][12] = 0x%ulx\n",
805 rtlphy
->pwrgroup_cnt
,
806 rtlphy
->mcs_txpwrlevel_origoffset
807 [rtlphy
->pwrgroup_cnt
][12]));
809 if (regaddr
== RTXAGC_B_MCS15_MCS12
) {
810 rtlphy
->mcs_txpwrlevel_origoffset
[rtlphy
->pwrgroup_cnt
][13] =
812 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
813 ("MCSTxPowerLevelOriginalOffset[%d][13] = 0x%ulx\n",
814 rtlphy
->pwrgroup_cnt
,
815 rtlphy
->mcs_txpwrlevel_origoffset
816 [rtlphy
->pwrgroup_cnt
][13]));
817 rtlphy
->pwrgroup_cnt
++;
821 static bool _rtl92d_phy_config_bb_with_pgheaderfile(struct ieee80211_hw
*hw
,
824 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
826 u32
*phy_regarray_table_pg
;
827 u16 phy_regarray_pg_len
;
829 phy_regarray_pg_len
= PHY_REG_ARRAY_PG_LENGTH
;
830 phy_regarray_table_pg
= rtl8192de_phy_reg_array_pg
;
831 if (configtype
== BASEBAND_CONFIG_PHY_REG
) {
832 for (i
= 0; i
< phy_regarray_pg_len
; i
= i
+ 3) {
833 if (phy_regarray_table_pg
[i
] == 0xfe)
835 else if (phy_regarray_table_pg
[i
] == 0xfd)
837 else if (phy_regarray_table_pg
[i
] == 0xfc)
839 else if (phy_regarray_table_pg
[i
] == 0xfb)
841 else if (phy_regarray_table_pg
[i
] == 0xfa)
843 else if (phy_regarray_table_pg
[i
] == 0xf9)
845 _rtl92d_store_pwrindex_diffrate_offset(hw
,
846 phy_regarray_table_pg
[i
],
847 phy_regarray_table_pg
[i
+ 1],
848 phy_regarray_table_pg
[i
+ 2]);
851 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
852 ("configtype != BaseBand_Config_PHY_REG\n"));
857 static bool _rtl92d_phy_bb_config(struct ieee80211_hw
*hw
)
859 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
860 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
861 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
862 bool rtstatus
= true;
864 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
, ("==>\n"));
865 rtstatus
= _rtl92d_phy_config_bb_with_headerfile(hw
,
866 BASEBAND_CONFIG_PHY_REG
);
867 if (rtstatus
!= true) {
868 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, ("Write BB Reg Fail!!"));
872 /* if (rtlphy->rf_type == RF_1T2R) {
873 * _rtl92c_phy_bb_config_1t(hw);
874 * RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, ("Config to 1T!!\n"));
877 if (rtlefuse
->autoload_failflag
== false) {
878 rtlphy
->pwrgroup_cnt
= 0;
879 rtstatus
= _rtl92d_phy_config_bb_with_pgheaderfile(hw
,
880 BASEBAND_CONFIG_PHY_REG
);
882 if (rtstatus
!= true) {
883 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, ("BB_PG Reg Fail!!"));
886 rtstatus
= _rtl92d_phy_config_bb_with_headerfile(hw
,
887 BASEBAND_CONFIG_AGC_TAB
);
888 if (rtstatus
!= true) {
889 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, ("AGC Table Fail\n"));
892 rtlphy
->cck_high_power
= (bool) (rtl_get_bbreg(hw
,
893 RFPGA0_XA_HSSIPARAMETER2
, 0x200));
898 bool rtl92d_phy_bb_config(struct ieee80211_hw
*hw
)
900 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
905 _rtl92d_phy_init_bb_rf_register_definition(hw
);
906 regval
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
);
907 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
,
908 regval
| BIT(13) | BIT(0) | BIT(1));
909 rtl_write_byte(rtlpriv
, REG_AFE_PLL_CTRL
, 0x83);
910 rtl_write_byte(rtlpriv
, REG_AFE_PLL_CTRL
+ 1, 0xdb);
911 /* 0x1f bit7 bit6 represent for mac0/mac1 driver ready */
912 value
= rtl_read_byte(rtlpriv
, REG_RF_CTRL
);
913 rtl_write_byte(rtlpriv
, REG_RF_CTRL
, value
| RF_EN
| RF_RSTB
|
915 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, FEN_PPLL
| FEN_PCIEA
|
916 FEN_DIO_PCIE
| FEN_BB_GLB_RSTn
| FEN_BBRSTB
);
917 rtl_write_byte(rtlpriv
, REG_AFE_XTAL_CTRL
+ 1, 0x80);
918 if (!(IS_92D_SINGLEPHY(rtlpriv
->rtlhal
.version
))) {
919 regvaldw
= rtl_read_dword(rtlpriv
, REG_LEDCFG0
);
920 rtl_write_dword(rtlpriv
, REG_LEDCFG0
, regvaldw
| BIT(23));
923 return _rtl92d_phy_bb_config(hw
);
926 bool rtl92d_phy_rf_config(struct ieee80211_hw
*hw
)
928 return rtl92d_phy_rf6052_config(hw
);
931 bool rtl92d_phy_config_rf_with_headerfile(struct ieee80211_hw
*hw
,
932 enum rf_content content
,
933 enum radio_path rfpath
)
936 u32
*radioa_array_table
;
937 u32
*radiob_array_table
;
938 u16 radioa_arraylen
, radiob_arraylen
;
939 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
941 radioa_arraylen
= RADIOA_2T_ARRAYLENGTH
;
942 radioa_array_table
= rtl8192de_radioa_2tarray
;
943 radiob_arraylen
= RADIOB_2T_ARRAYLENGTH
;
944 radiob_array_table
= rtl8192de_radiob_2tarray
;
945 if (rtlpriv
->efuse
.internal_pa_5g
[0]) {
946 radioa_arraylen
= RADIOA_2T_INT_PA_ARRAYLENGTH
;
947 radioa_array_table
= rtl8192de_radioa_2t_int_paarray
;
949 if (rtlpriv
->efuse
.internal_pa_5g
[1]) {
950 radiob_arraylen
= RADIOB_2T_INT_PA_ARRAYLENGTH
;
951 radiob_array_table
= rtl8192de_radiob_2t_int_paarray
;
953 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
954 ("PHY_ConfigRFWithHeaderFile() "
955 "Radio_A:Rtl819XRadioA_1TArray\n"));
956 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
957 ("PHY_ConfigRFWithHeaderFile() "
958 "Radio_B:Rtl819XRadioB_1TArray\n"));
959 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
, ("Radio No %x\n", rfpath
));
961 /* this only happens when DMDP, mac0 start on 2.4G,
962 * mac1 start on 5G, mac 0 has to set phy0&phy1
963 * pathA or mac1 has to set phy0&phy1 pathA */
964 if ((content
== radiob_txt
) && (rfpath
== RF90_PATH_A
)) {
965 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
966 (" ===> althougth Path A, we load radiob.txt\n"));
967 radioa_arraylen
= radiob_arraylen
;
968 radioa_array_table
= radiob_array_table
;
972 for (i
= 0; i
< radioa_arraylen
; i
= i
+ 2) {
973 if (radioa_array_table
[i
] == 0xfe) {
975 } else if (radioa_array_table
[i
] == 0xfd) {
978 } else if (radioa_array_table
[i
] == 0xfc) {
981 } else if (radioa_array_table
[i
] == 0xfb) {
983 } else if (radioa_array_table
[i
] == 0xfa) {
985 } else if (radioa_array_table
[i
] == 0xf9) {
988 rtl_set_rfreg(hw
, rfpath
, radioa_array_table
[i
],
990 radioa_array_table
[i
+ 1]);
991 /* Add 1us delay between BB/RF register set. */
997 for (i
= 0; i
< radiob_arraylen
; i
= i
+ 2) {
998 if (radiob_array_table
[i
] == 0xfe) {
999 /* Delay specific ms. Only RF configuration
1000 * requires delay. */
1002 } else if (radiob_array_table
[i
] == 0xfd) {
1005 } else if (radiob_array_table
[i
] == 0xfc) {
1008 } else if (radiob_array_table
[i
] == 0xfb) {
1010 } else if (radiob_array_table
[i
] == 0xfa) {
1012 } else if (radiob_array_table
[i
] == 0xf9) {
1015 rtl_set_rfreg(hw
, rfpath
, radiob_array_table
[i
],
1017 radiob_array_table
[i
+ 1]);
1018 /* Add 1us delay between BB/RF register set. */
1024 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1025 ("switch case not process\n"));
1028 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1029 ("switch case not process\n"));
1035 void rtl92d_phy_get_hw_reg_originalvalue(struct ieee80211_hw
*hw
)
1037 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1038 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1040 rtlphy
->default_initialgain
[0] =
1041 (u8
) rtl_get_bbreg(hw
, ROFDM0_XAAGCCORE1
, BMASKBYTE0
);
1042 rtlphy
->default_initialgain
[1] =
1043 (u8
) rtl_get_bbreg(hw
, ROFDM0_XBAGCCORE1
, BMASKBYTE0
);
1044 rtlphy
->default_initialgain
[2] =
1045 (u8
) rtl_get_bbreg(hw
, ROFDM0_XCAGCCORE1
, BMASKBYTE0
);
1046 rtlphy
->default_initialgain
[3] =
1047 (u8
) rtl_get_bbreg(hw
, ROFDM0_XDAGCCORE1
, BMASKBYTE0
);
1048 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1049 ("Default initial gain (c50=0x%x, "
1050 "c58=0x%x, c60=0x%x, c68=0x%x\n",
1051 rtlphy
->default_initialgain
[0],
1052 rtlphy
->default_initialgain
[1],
1053 rtlphy
->default_initialgain
[2],
1054 rtlphy
->default_initialgain
[3]));
1055 rtlphy
->framesync
= (u8
)rtl_get_bbreg(hw
, ROFDM0_RXDETECTOR3
,
1057 rtlphy
->framesync_c34
= rtl_get_bbreg(hw
, ROFDM0_RXDETECTOR2
,
1059 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1060 ("Default framesync (0x%x) = 0x%x\n",
1061 ROFDM0_RXDETECTOR3
, rtlphy
->framesync
));
1064 static void _rtl92d_get_txpower_index(struct ieee80211_hw
*hw
, u8 channel
,
1065 u8
*cckpowerlevel
, u8
*ofdmpowerlevel
)
1067 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1068 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1069 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
1070 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1071 u8 index
= (channel
- 1);
1074 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
1076 cckpowerlevel
[RF90_PATH_A
] =
1077 rtlefuse
->txpwrlevel_cck
[RF90_PATH_A
][index
];
1079 cckpowerlevel
[RF90_PATH_B
] =
1080 rtlefuse
->txpwrlevel_cck
[RF90_PATH_B
][index
];
1082 cckpowerlevel
[RF90_PATH_A
] = 0;
1083 cckpowerlevel
[RF90_PATH_B
] = 0;
1085 /* 2. OFDM for 1S or 2S */
1086 if (rtlphy
->rf_type
== RF_1T2R
|| rtlphy
->rf_type
== RF_1T1R
) {
1087 /* Read HT 40 OFDM TX power */
1088 ofdmpowerlevel
[RF90_PATH_A
] =
1089 rtlefuse
->txpwrlevel_ht40_1s
[RF90_PATH_A
][index
];
1090 ofdmpowerlevel
[RF90_PATH_B
] =
1091 rtlefuse
->txpwrlevel_ht40_1s
[RF90_PATH_B
][index
];
1092 } else if (rtlphy
->rf_type
== RF_2T2R
) {
1093 /* Read HT 40 OFDM TX power */
1094 ofdmpowerlevel
[RF90_PATH_A
] =
1095 rtlefuse
->txpwrlevel_ht40_2s
[RF90_PATH_A
][index
];
1096 ofdmpowerlevel
[RF90_PATH_B
] =
1097 rtlefuse
->txpwrlevel_ht40_2s
[RF90_PATH_B
][index
];
1101 static void _rtl92d_ccxpower_index_check(struct ieee80211_hw
*hw
,
1102 u8 channel
, u8
*cckpowerlevel
, u8
*ofdmpowerlevel
)
1104 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1105 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1107 rtlphy
->cur_cck_txpwridx
= cckpowerlevel
[0];
1108 rtlphy
->cur_ofdm24g_txpwridx
= ofdmpowerlevel
[0];
1111 static u8
_rtl92c_phy_get_rightchnlplace(u8 chnl
)
1113 u8 channel_5g
[59] = {
1114 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
1115 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58,
1116 60, 62, 64, 100, 102, 104, 106, 108, 110, 112,
1117 114, 116, 118, 120, 122, 124, 126, 128,
1118 130, 132, 134, 136, 138, 140, 149, 151,
1119 153, 155, 157, 159, 161, 163, 165
1124 for (place
= 14; place
< sizeof(channel_5g
); place
++) {
1125 if (channel_5g
[place
] == chnl
) {
1134 void rtl92d_phy_set_txpower_level(struct ieee80211_hw
*hw
, u8 channel
)
1136 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1137 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1138 u8 cckpowerlevel
[2], ofdmpowerlevel
[2];
1140 if (rtlefuse
->txpwr_fromeprom
== false)
1142 channel
= _rtl92c_phy_get_rightchnlplace(channel
);
1143 _rtl92d_get_txpower_index(hw
, channel
, &cckpowerlevel
[0],
1144 &ofdmpowerlevel
[0]);
1145 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
1146 _rtl92d_ccxpower_index_check(hw
, channel
, &cckpowerlevel
[0],
1147 &ofdmpowerlevel
[0]);
1148 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
1149 rtl92d_phy_rf6052_set_cck_txpower(hw
, &cckpowerlevel
[0]);
1150 rtl92d_phy_rf6052_set_ofdm_txpower(hw
, &ofdmpowerlevel
[0], channel
);
1153 void rtl92d_phy_scan_operation_backup(struct ieee80211_hw
*hw
, u8 operation
)
1155 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1156 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1157 enum io_type iotype
;
1159 if (!is_hal_stop(rtlhal
)) {
1160 switch (operation
) {
1161 case SCAN_OPT_BACKUP
:
1162 rtlhal
->current_bandtypebackup
=
1163 rtlhal
->current_bandtype
;
1164 iotype
= IO_CMD_PAUSE_DM_BY_SCAN
;
1165 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_IO_CMD
,
1168 case SCAN_OPT_RESTORE
:
1169 iotype
= IO_CMD_RESUME_DM_BY_SCAN
;
1170 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_IO_CMD
,
1174 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1175 ("Unknown Scan Backup operation.\n"));
1181 void rtl92d_phy_set_bw_mode(struct ieee80211_hw
*hw
,
1182 enum nl80211_channel_type ch_type
)
1184 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1185 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1186 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1187 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1188 unsigned long flag
= 0;
1192 if (rtlphy
->set_bwmode_inprogress
)
1194 if ((is_hal_stop(rtlhal
)) || (RT_CANNOT_IO(hw
))) {
1195 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1196 ("FALSE driver sleep or unload\n"));
1199 rtlphy
->set_bwmode_inprogress
= true;
1200 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_TRACE
,
1201 ("Switch to %s bandwidth\n",
1202 rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20
?
1203 "20MHz" : "40MHz"));
1204 reg_bw_opmode
= rtl_read_byte(rtlpriv
, REG_BWOPMODE
);
1205 reg_prsr_rsc
= rtl_read_byte(rtlpriv
, REG_RRSR
+ 2);
1206 switch (rtlphy
->current_chan_bw
) {
1207 case HT_CHANNEL_WIDTH_20
:
1208 reg_bw_opmode
|= BW_OPMODE_20MHZ
;
1209 rtl_write_byte(rtlpriv
, REG_BWOPMODE
, reg_bw_opmode
);
1211 case HT_CHANNEL_WIDTH_20_40
:
1212 reg_bw_opmode
&= ~BW_OPMODE_20MHZ
;
1213 rtl_write_byte(rtlpriv
, REG_BWOPMODE
, reg_bw_opmode
);
1215 reg_prsr_rsc
= (reg_prsr_rsc
& 0x90) |
1216 (mac
->cur_40_prime_sc
<< 5);
1217 rtl_write_byte(rtlpriv
, REG_RRSR
+ 2, reg_prsr_rsc
);
1220 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1221 ("unknown bandwidth: %#X\n", rtlphy
->current_chan_bw
));
1224 switch (rtlphy
->current_chan_bw
) {
1225 case HT_CHANNEL_WIDTH_20
:
1226 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BRFMOD
, 0x0);
1227 rtl_set_bbreg(hw
, RFPGA1_RFMOD
, BRFMOD
, 0x0);
1228 /* SET BIT10 BIT11 for receive cck */
1229 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER2
, BIT(10) |
1232 case HT_CHANNEL_WIDTH_20_40
:
1233 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BRFMOD
, 0x1);
1234 rtl_set_bbreg(hw
, RFPGA1_RFMOD
, BRFMOD
, 0x1);
1235 /* Set Control channel to upper or lower.
1236 * These settings are required only for 40MHz */
1237 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
1238 rtl92d_acquire_cckandrw_pagea_ctl(hw
, &flag
);
1239 rtl_set_bbreg(hw
, RCCK0_SYSTEM
, BCCKSIDEBAND
,
1240 (mac
->cur_40_prime_sc
>> 1));
1241 rtl92d_release_cckandrw_pagea_ctl(hw
, &flag
);
1243 rtl_set_bbreg(hw
, ROFDM1_LSTF
, 0xC00, mac
->cur_40_prime_sc
);
1244 /* SET BIT10 BIT11 for receive cck */
1245 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER2
, BIT(10) |
1247 rtl_set_bbreg(hw
, 0x818, (BIT(26) | BIT(27)),
1248 (mac
->cur_40_prime_sc
==
1249 HAL_PRIME_CHNL_OFFSET_LOWER
) ? 2 : 1);
1252 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1253 ("unknown bandwidth: %#X\n", rtlphy
->current_chan_bw
));
1257 rtl92d_phy_rf6052_set_bandwidth(hw
, rtlphy
->current_chan_bw
);
1258 rtlphy
->set_bwmode_inprogress
= false;
1259 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_TRACE
, ("<==\n"));
1262 static void _rtl92d_phy_stop_trx_before_changeband(struct ieee80211_hw
*hw
)
1264 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BCCKEN
, 0);
1265 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BOFDMEN
, 0);
1266 rtl_set_bbreg(hw
, ROFDM0_TRXPATHENABLE
, BMASKBYTE0
, 0x00);
1267 rtl_set_bbreg(hw
, ROFDM1_TRXPATHENABLE
, BDWORD
, 0x0);
1270 static void rtl92d_phy_switch_wirelessband(struct ieee80211_hw
*hw
, u8 band
)
1272 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1273 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1276 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, ("==>\n"));
1277 rtlhal
->bandset
= band
;
1278 rtlhal
->current_bandtype
= band
;
1279 if (IS_92D_SINGLEPHY(rtlhal
->version
))
1280 rtlhal
->bandset
= BAND_ON_BOTH
;
1282 _rtl92d_phy_stop_trx_before_changeband(hw
);
1283 /* reconfig BB/RF according to wireless mode */
1284 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
1285 /* BB & RF Config */
1286 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_DMESG
, ("====>2.4G\n"));
1287 if (rtlhal
->interfaceindex
== 1)
1288 _rtl92d_phy_config_bb_with_headerfile(hw
,
1289 BASEBAND_CONFIG_AGC_TAB
);
1292 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_DMESG
, ("====>5G\n"));
1293 if (rtlhal
->interfaceindex
== 1)
1294 _rtl92d_phy_config_bb_with_headerfile(hw
,
1295 BASEBAND_CONFIG_AGC_TAB
);
1297 rtl92d_update_bbrf_configuration(hw
);
1298 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
)
1299 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BCCKEN
, 0x1);
1300 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BOFDMEN
, 0x1);
1303 /* rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 1); */
1304 rtlhal
->reloadtxpowerindex
= true;
1305 /* notice fw know band status 0x81[1]/0x53[1] = 0: 5G, 1: 2G */
1306 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
1307 value8
= rtl_read_byte(rtlpriv
, (rtlhal
->interfaceindex
==
1308 0 ? REG_MAC0
: REG_MAC1
));
1310 rtl_write_byte(rtlpriv
, (rtlhal
->interfaceindex
==
1311 0 ? REG_MAC0
: REG_MAC1
), value8
);
1313 value8
= rtl_read_byte(rtlpriv
, (rtlhal
->interfaceindex
==
1314 0 ? REG_MAC0
: REG_MAC1
));
1315 value8
&= (~BIT(1));
1316 rtl_write_byte(rtlpriv
, (rtlhal
->interfaceindex
==
1317 0 ? REG_MAC0
: REG_MAC1
), value8
);
1320 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, ("<==Switch Band OK.\n"));
1323 static void _rtl92d_phy_reload_imr_setting(struct ieee80211_hw
*hw
,
1324 u8 channel
, u8 rfpath
)
1326 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1327 u32 imr_num
= MAX_RF_IMR_INDEX
;
1328 u32 rfmask
= BRFREGOFFSETMASK
;
1330 unsigned long flag
= 0;
1332 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, ("====>path %d\n", rfpath
));
1333 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_5G
) {
1334 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, ("====>5G\n"));
1335 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BIT(25) | BIT(24), 0);
1336 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
, 0x00f00000, 0xf);
1339 rtl_set_bbreg(hw
, ROFDM1_CFOTRACKING
, BIT(13) |
1342 rtl_set_bbreg(hw
, ROFDM1_CFOTRACKING
, BIT(13) |
1344 /* leave 0 for channel1-14. */
1345 group
= channel
<= 64 ? 1 : 2;
1346 imr_num
= MAX_RF_IMR_INDEX_NORMAL
;
1347 for (i
= 0; i
< imr_num
; i
++)
1348 rtl_set_rfreg(hw
, (enum radio_path
)rfpath
,
1349 rf_reg_for_5g_swchnl_normal
[i
], rfmask
,
1350 rf_imr_param_normal
[0][group
][i
]);
1351 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
, 0x00f00000, 0);
1352 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BOFDMEN
, 1);
1355 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_LOUD
,
1356 ("Load RF IMR parameters for G band. IMR already "
1358 rtlpriv
->rtlhal
.load_imrandiqk_setting_for2g
));
1359 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, ("====>2.4G\n"));
1360 if (!rtlpriv
->rtlhal
.load_imrandiqk_setting_for2g
) {
1361 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_LOUD
,
1362 ("Load RF IMR parameters "
1363 "for G band. %d\n", rfpath
));
1364 rtl92d_acquire_cckandrw_pagea_ctl(hw
, &flag
);
1365 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BIT(25) | BIT(24), 0);
1366 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
,
1368 imr_num
= MAX_RF_IMR_INDEX_NORMAL
;
1369 for (i
= 0; i
< imr_num
; i
++) {
1370 rtl_set_rfreg(hw
, (enum radio_path
)rfpath
,
1371 rf_reg_for_5g_swchnl_normal
[i
],
1373 rf_imr_param_normal
[0][0][i
]);
1375 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
,
1377 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BOFDMEN
| BCCKEN
, 3);
1378 rtl92d_release_cckandrw_pagea_ctl(hw
, &flag
);
1381 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, ("<====\n"));
1384 static void _rtl92d_phy_enable_rf_env(struct ieee80211_hw
*hw
,
1385 u8 rfpath
, u32
*pu4_regval
)
1387 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1388 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1389 struct bb_reg_def
*pphyreg
= &rtlphy
->phyreg_def
[rfpath
];
1391 RT_TRACE(rtlpriv
, COMP_RF
, DBG_LOUD
, ("====>\n"));
1392 /*----Store original RFENV control type----*/
1396 *pu4_regval
= rtl_get_bbreg(hw
, pphyreg
->rfintfs
, BRFSI_RFENV
);
1401 rtl_get_bbreg(hw
, pphyreg
->rfintfs
, BRFSI_RFENV
<< 16);
1404 /*----Set RF_ENV enable----*/
1405 rtl_set_bbreg(hw
, pphyreg
->rfintfe
, BRFSI_RFENV
<< 16, 0x1);
1407 /*----Set RF_ENV output high----*/
1408 rtl_set_bbreg(hw
, pphyreg
->rfintfo
, BRFSI_RFENV
, 0x1);
1410 /* Set bit number of Address and Data for RF register */
1411 /* Set 1 to 4 bits for 8255 */
1412 rtl_set_bbreg(hw
, pphyreg
->rfhssi_para2
, B3WIREADDRESSLENGTH
, 0x0);
1414 /*Set 0 to 12 bits for 8255 */
1415 rtl_set_bbreg(hw
, pphyreg
->rfhssi_para2
, B3WIREDATALENGTH
, 0x0);
1417 RT_TRACE(rtlpriv
, COMP_RF
, DBG_LOUD
, ("<====\n"));
1420 static void _rtl92d_phy_restore_rf_env(struct ieee80211_hw
*hw
, u8 rfpath
,
1423 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1424 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1425 struct bb_reg_def
*pphyreg
= &rtlphy
->phyreg_def
[rfpath
];
1427 RT_TRACE(rtlpriv
, COMP_RF
, DBG_LOUD
, ("=====>\n"));
1428 /*----Restore RFENV control type----*/ ;
1432 rtl_set_bbreg(hw
, pphyreg
->rfintfs
, BRFSI_RFENV
, *pu4_regval
);
1436 rtl_set_bbreg(hw
, pphyreg
->rfintfs
, BRFSI_RFENV
<< 16,
1440 RT_TRACE(rtlpriv
, COMP_RF
, DBG_LOUD
, ("<=====\n"));
1443 static void _rtl92d_phy_switch_rf_setting(struct ieee80211_hw
*hw
, u8 channel
)
1445 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1446 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1447 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
1448 u8 path
= rtlhal
->current_bandtype
==
1449 BAND_ON_5G
? RF90_PATH_A
: RF90_PATH_B
;
1450 u8 index
= 0, i
= 0, rfpath
= RF90_PATH_A
;
1451 bool need_pwr_down
= false, internal_pa
= false;
1452 u32 u4regvalue
, mask
= 0x1C000, value
= 0, u4tmp
, u4tmp2
;
1454 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, ("====>\n"));
1455 /* config path A for 5G */
1456 if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
1457 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, ("====>5G\n"));
1458 u4tmp
= curveindex_5g
[channel
- 1];
1459 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("ver 1 set RF-A, 5G, "
1460 "0x28 = 0x%x !!\n", u4tmp
));
1461 for (i
= 0; i
< RF_CHNL_NUM_5G
; i
++) {
1462 if (channel
== rf_chnl_5g
[i
] && channel
<= 140)
1465 for (i
= 0; i
< RF_CHNL_NUM_5G_40M
; i
++) {
1466 if (channel
== rf_chnl_5g_40m
[i
] && channel
<= 140)
1469 if (channel
== 149 || channel
== 155 || channel
== 161)
1471 else if (channel
== 151 || channel
== 153 || channel
== 163
1474 else if (channel
== 157 || channel
== 159)
1477 if (rtlhal
->macphymode
== DUALMAC_DUALPHY
1478 && rtlhal
->interfaceindex
== 1) {
1479 need_pwr_down
= rtl92d_phy_enable_anotherphy(hw
, false);
1480 rtlhal
->during_mac1init_radioa
= true;
1481 /* asume no this case */
1483 _rtl92d_phy_enable_rf_env(hw
, path
,
1486 for (i
= 0; i
< RF_REG_NUM_FOR_C_CUT_5G
; i
++) {
1487 if (i
== 0 && (rtlhal
->macphymode
== DUALMAC_DUALPHY
)) {
1488 rtl_set_rfreg(hw
, (enum radio_path
)path
,
1489 rf_reg_for_c_cut_5g
[i
],
1490 BRFREGOFFSETMASK
, 0xE439D);
1491 } else if (rf_reg_for_c_cut_5g
[i
] == RF_SYN_G4
) {
1492 u4tmp2
= (rf_reg_pram_c_5g
[index
][i
] &
1493 0x7FF) | (u4tmp
<< 11);
1495 u4tmp2
&= ~(BIT(7) | BIT(6));
1496 rtl_set_rfreg(hw
, (enum radio_path
)path
,
1497 rf_reg_for_c_cut_5g
[i
],
1498 BRFREGOFFSETMASK
, u4tmp2
);
1500 rtl_set_rfreg(hw
, (enum radio_path
)path
,
1501 rf_reg_for_c_cut_5g
[i
],
1503 rf_reg_pram_c_5g
[index
][i
]);
1505 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
1506 ("offset 0x%x value 0x%x "
1507 "path %d index %d readback 0x%x\n",
1508 rf_reg_for_c_cut_5g
[i
],
1509 rf_reg_pram_c_5g
[index
][i
], path
,
1510 index
, rtl_get_rfreg(hw
, (enum radio_path
)path
,
1511 rf_reg_for_c_cut_5g
[i
], BRFREGOFFSETMASK
)));
1514 _rtl92d_phy_restore_rf_env(hw
, path
, &u4regvalue
);
1515 if (rtlhal
->during_mac1init_radioa
)
1516 rtl92d_phy_powerdown_anotherphy(hw
, false);
1519 else if (channel
>= 149)
1521 if (channel
>= 36 && channel
<= 64)
1523 else if (channel
>= 100 && channel
<= 140)
1527 for (rfpath
= RF90_PATH_A
; rfpath
< rtlphy
->num_total_rfpath
;
1529 if (rtlhal
->macphymode
== DUALMAC_DUALPHY
&&
1530 rtlhal
->interfaceindex
== 1) /* MAC 1 5G */
1531 internal_pa
= rtlpriv
->efuse
.internal_pa_5g
[1];
1534 rtlpriv
->efuse
.internal_pa_5g
[rfpath
];
1537 i
< RF_REG_NUM_FOR_C_CUT_5G_INTERNALPA
;
1539 rtl_set_rfreg(hw
, rfpath
,
1540 rf_for_c_cut_5g_internal_pa
[i
],
1542 rf_pram_c_5g_int_pa
[index
][i
]);
1543 RT_TRACE(rtlpriv
, COMP_RF
, DBG_LOUD
,
1544 ("offset 0x%x value 0x%x "
1545 "path %d index %d\n",
1546 rf_for_c_cut_5g_internal_pa
[i
],
1547 rf_pram_c_5g_int_pa
[index
][i
],
1551 rtl_set_rfreg(hw
, (enum radio_path
)rfpath
, 0x0B,
1555 } else if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
1556 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, ("====>2.4G\n"));
1557 u4tmp
= curveindex_2g
[channel
- 1];
1558 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("ver 3 set RF-B, 2G, "
1559 "0x28 = 0x%x !!\n", u4tmp
));
1560 if (channel
== 1 || channel
== 2 || channel
== 4 || channel
== 9
1561 || channel
== 10 || channel
== 11 || channel
== 12)
1563 else if (channel
== 3 || channel
== 13 || channel
== 14)
1565 else if (channel
>= 5 && channel
<= 8)
1567 if (rtlhal
->macphymode
== DUALMAC_DUALPHY
) {
1569 if (rtlhal
->interfaceindex
== 0) {
1571 rtl92d_phy_enable_anotherphy(hw
, true);
1572 rtlhal
->during_mac0init_radiob
= true;
1575 _rtl92d_phy_enable_rf_env(hw
, path
,
1579 for (i
= 0; i
< RF_REG_NUM_FOR_C_CUT_2G
; i
++) {
1580 if (rf_reg_for_c_cut_2g
[i
] == RF_SYN_G7
)
1581 rtl_set_rfreg(hw
, (enum radio_path
)path
,
1582 rf_reg_for_c_cut_2g
[i
],
1584 (rf_reg_param_for_c_cut_2g
[index
][i
] |
1587 rtl_set_rfreg(hw
, (enum radio_path
)path
,
1588 rf_reg_for_c_cut_2g
[i
],
1590 rf_reg_param_for_c_cut_2g
1592 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
1593 ("offset 0x%x value 0x%x mak 0x%x path %d "
1594 "index %d readback 0x%x\n",
1595 rf_reg_for_c_cut_2g
[i
],
1596 rf_reg_param_for_c_cut_2g
[index
][i
],
1597 rf_reg_mask_for_c_cut_2g
[i
], path
, index
,
1598 rtl_get_rfreg(hw
, (enum radio_path
)path
,
1599 rf_reg_for_c_cut_2g
[i
],
1600 BRFREGOFFSETMASK
)));
1602 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1603 ("cosa ver 3 set RF-B, 2G, 0x28 = 0x%x !!\n",
1604 rf_syn_g4_for_c_cut_2g
| (u4tmp
<< 11)));
1606 rtl_set_rfreg(hw
, (enum radio_path
)path
, RF_SYN_G4
,
1608 rf_syn_g4_for_c_cut_2g
| (u4tmp
<< 11));
1610 _rtl92d_phy_restore_rf_env(hw
, path
, &u4regvalue
);
1611 if (rtlhal
->during_mac0init_radiob
)
1612 rtl92d_phy_powerdown_anotherphy(hw
, true);
1614 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, ("<====\n"));
1617 u8
rtl92d_get_rightchnlplace_for_iqk(u8 chnl
)
1619 u8 channel_all
[59] = {
1620 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
1621 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58,
1622 60, 62, 64, 100, 102, 104, 106, 108, 110, 112,
1623 114, 116, 118, 120, 122, 124, 126, 128, 130,
1624 132, 134, 136, 138, 140, 149, 151, 153, 155,
1625 157, 159, 161, 163, 165
1630 for (place
= 14; place
< sizeof(channel_all
); place
++) {
1631 if (channel_all
[place
] == chnl
)
1639 #define MAX_TOLERANCE 5
1640 #define IQK_DELAY_TIME 1 /* ms */
1641 #define MAX_TOLERANCE_92D 3
1643 /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */
1644 static u8
_rtl92d_phy_patha_iqk(struct ieee80211_hw
*hw
, bool configpathb
)
1646 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1647 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1648 u32 regeac
, rege94
, rege9c
, regea4
;
1651 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("Path A IQK!\n"));
1652 /* path-A IQK setting */
1653 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("Path-A IQK setting!\n"));
1654 if (rtlhal
->interfaceindex
== 0) {
1655 rtl_set_bbreg(hw
, 0xe30, BMASKDWORD
, 0x10008c1f);
1656 rtl_set_bbreg(hw
, 0xe34, BMASKDWORD
, 0x10008c1f);
1658 rtl_set_bbreg(hw
, 0xe30, BMASKDWORD
, 0x10008c22);
1659 rtl_set_bbreg(hw
, 0xe34, BMASKDWORD
, 0x10008c22);
1661 rtl_set_bbreg(hw
, 0xe38, BMASKDWORD
, 0x82140102);
1662 rtl_set_bbreg(hw
, 0xe3c, BMASKDWORD
, 0x28160206);
1663 /* path-B IQK setting */
1665 rtl_set_bbreg(hw
, 0xe50, BMASKDWORD
, 0x10008c22);
1666 rtl_set_bbreg(hw
, 0xe54, BMASKDWORD
, 0x10008c22);
1667 rtl_set_bbreg(hw
, 0xe58, BMASKDWORD
, 0x82140102);
1668 rtl_set_bbreg(hw
, 0xe5c, BMASKDWORD
, 0x28160206);
1670 /* LO calibration setting */
1671 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("LO calibration setting!\n"));
1672 rtl_set_bbreg(hw
, 0xe4c, BMASKDWORD
, 0x00462911);
1673 /* One shot, path A LOK & IQK */
1674 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("One shot, path A LOK & IQK!\n"));
1675 rtl_set_bbreg(hw
, 0xe48, BMASKDWORD
, 0xf9000000);
1676 rtl_set_bbreg(hw
, 0xe48, BMASKDWORD
, 0xf8000000);
1678 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1679 ("Delay %d ms for One shot, path A LOK & IQK.\n",
1681 mdelay(IQK_DELAY_TIME
);
1683 regeac
= rtl_get_bbreg(hw
, 0xeac, BMASKDWORD
);
1684 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("0xeac = 0x%x\n", regeac
));
1685 rege94
= rtl_get_bbreg(hw
, 0xe94, BMASKDWORD
);
1686 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("0xe94 = 0x%x\n", rege94
));
1687 rege9c
= rtl_get_bbreg(hw
, 0xe9c, BMASKDWORD
);
1688 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("0xe9c = 0x%x\n", rege9c
));
1689 regea4
= rtl_get_bbreg(hw
, 0xea4, BMASKDWORD
);
1690 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("0xea4 = 0x%x\n", regea4
));
1691 if (!(regeac
& BIT(28)) && (((rege94
& 0x03FF0000) >> 16) != 0x142) &&
1692 (((rege9c
& 0x03FF0000) >> 16) != 0x42))
1694 else /* if Tx not OK, ignore Rx */
1696 /* if Tx is OK, check whether Rx is OK */
1697 if (!(regeac
& BIT(27)) && (((regea4
& 0x03FF0000) >> 16) != 0x132) &&
1698 (((regeac
& 0x03FF0000) >> 16) != 0x36))
1701 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("Path A Rx IQK fail!!\n"));
1705 /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */
1706 static u8
_rtl92d_phy_patha_iqk_5g_normal(struct ieee80211_hw
*hw
,
1709 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1710 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1711 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1712 u32 regeac
, rege94
, rege9c
, regea4
;
1716 u32 TxOKBit
= BIT(28), RxOKBit
= BIT(27);
1718 if (rtlhal
->interfaceindex
== 1) { /* PHY1 */
1722 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("Path A IQK!\n"));
1723 /* path-A IQK setting */
1724 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("Path-A IQK setting!\n"));
1725 rtl_set_bbreg(hw
, 0xe30, BMASKDWORD
, 0x18008c1f);
1726 rtl_set_bbreg(hw
, 0xe34, BMASKDWORD
, 0x18008c1f);
1727 rtl_set_bbreg(hw
, 0xe38, BMASKDWORD
, 0x82140307);
1728 rtl_set_bbreg(hw
, 0xe3c, BMASKDWORD
, 0x68160960);
1729 /* path-B IQK setting */
1731 rtl_set_bbreg(hw
, 0xe50, BMASKDWORD
, 0x18008c2f);
1732 rtl_set_bbreg(hw
, 0xe54, BMASKDWORD
, 0x18008c2f);
1733 rtl_set_bbreg(hw
, 0xe58, BMASKDWORD
, 0x82110000);
1734 rtl_set_bbreg(hw
, 0xe5c, BMASKDWORD
, 0x68110000);
1736 /* LO calibration setting */
1737 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("LO calibration setting!\n"));
1738 rtl_set_bbreg(hw
, 0xe4c, BMASKDWORD
, 0x00462911);
1740 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
, BMASKDWORD
, 0x07000f60);
1741 rtl_set_bbreg(hw
, RFPGA0_XA_RFINTERFACEOE
, BMASKDWORD
, 0x66e60e30);
1742 for (i
= 0; i
< retrycount
; i
++) {
1743 /* One shot, path A LOK & IQK */
1744 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1745 ("One shot, path A LOK & IQK!\n"));
1746 rtl_set_bbreg(hw
, 0xe48, BMASKDWORD
, 0xf9000000);
1747 rtl_set_bbreg(hw
, 0xe48, BMASKDWORD
, 0xf8000000);
1749 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1750 ("Delay %d ms for One shot, path A LOK & IQK.\n",
1752 mdelay(IQK_DELAY_TIME
* 10);
1754 regeac
= rtl_get_bbreg(hw
, 0xeac, BMASKDWORD
);
1755 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("0xeac = 0x%x\n", regeac
));
1756 rege94
= rtl_get_bbreg(hw
, 0xe94, BMASKDWORD
);
1757 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("0xe94 = 0x%x\n", rege94
));
1758 rege9c
= rtl_get_bbreg(hw
, 0xe9c, BMASKDWORD
);
1759 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("0xe9c = 0x%x\n", rege9c
));
1760 regea4
= rtl_get_bbreg(hw
, 0xea4, BMASKDWORD
);
1761 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("0xea4 = 0x%x\n", regea4
));
1762 if (!(regeac
& TxOKBit
) &&
1763 (((rege94
& 0x03FF0000) >> 16) != 0x142)) {
1765 } else { /* if Tx not OK, ignore Rx */
1766 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1767 ("Path A Tx IQK fail!!\n"));
1771 /* if Tx is OK, check whether Rx is OK */
1772 if (!(regeac
& RxOKBit
) &&
1773 (((regea4
& 0x03FF0000) >> 16) != 0x132)) {
1777 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1778 ("Path A Rx IQK fail!!\n"));
1782 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
, BMASKDWORD
,
1783 rtlphy
->iqk_bb_backup
[0]);
1784 rtl_set_bbreg(hw
, RFPGA0_XA_RFINTERFACEOE
, BMASKDWORD
,
1785 rtlphy
->iqk_bb_backup
[1]);
1789 /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */
1790 static u8
_rtl92d_phy_pathb_iqk(struct ieee80211_hw
*hw
)
1792 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1793 u32 regeac
, regeb4
, regebc
, regec4
, regecc
;
1796 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("Path B IQK!\n"));
1797 /* One shot, path B LOK & IQK */
1798 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("One shot, path A LOK & IQK!\n"));
1799 rtl_set_bbreg(hw
, 0xe60, BMASKDWORD
, 0x00000002);
1800 rtl_set_bbreg(hw
, 0xe60, BMASKDWORD
, 0x00000000);
1802 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1803 ("Delay %d ms for One shot, path B LOK & IQK.\n",
1805 mdelay(IQK_DELAY_TIME
);
1807 regeac
= rtl_get_bbreg(hw
, 0xeac, BMASKDWORD
);
1808 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("0xeac = 0x%x\n", regeac
));
1809 regeb4
= rtl_get_bbreg(hw
, 0xeb4, BMASKDWORD
);
1810 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("0xeb4 = 0x%x\n", regeb4
));
1811 regebc
= rtl_get_bbreg(hw
, 0xebc, BMASKDWORD
);
1812 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("0xebc = 0x%x\n", regebc
));
1813 regec4
= rtl_get_bbreg(hw
, 0xec4, BMASKDWORD
);
1814 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("0xec4 = 0x%x\n", regec4
));
1815 regecc
= rtl_get_bbreg(hw
, 0xecc, BMASKDWORD
);
1816 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("0xecc = 0x%x\n", regecc
));
1817 if (!(regeac
& BIT(31)) && (((regeb4
& 0x03FF0000) >> 16) != 0x142) &&
1818 (((regebc
& 0x03FF0000) >> 16) != 0x42))
1822 if (!(regeac
& BIT(30)) && (((regec4
& 0x03FF0000) >> 16) != 0x132) &&
1823 (((regecc
& 0x03FF0000) >> 16) != 0x36))
1826 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("Path B Rx IQK fail!!\n"));
1830 /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */
1831 static u8
_rtl92d_phy_pathb_iqk_5g_normal(struct ieee80211_hw
*hw
)
1833 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1834 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1835 u32 regeac
, regeb4
, regebc
, regec4
, regecc
;
1840 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("Path B IQK!\n"));
1841 /* path-A IQK setting */
1842 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("Path-A IQK setting!\n"));
1843 rtl_set_bbreg(hw
, 0xe30, BMASKDWORD
, 0x18008c1f);
1844 rtl_set_bbreg(hw
, 0xe34, BMASKDWORD
, 0x18008c1f);
1845 rtl_set_bbreg(hw
, 0xe38, BMASKDWORD
, 0x82110000);
1846 rtl_set_bbreg(hw
, 0xe3c, BMASKDWORD
, 0x68110000);
1848 /* path-B IQK setting */
1849 rtl_set_bbreg(hw
, 0xe50, BMASKDWORD
, 0x18008c2f);
1850 rtl_set_bbreg(hw
, 0xe54, BMASKDWORD
, 0x18008c2f);
1851 rtl_set_bbreg(hw
, 0xe58, BMASKDWORD
, 0x82140307);
1852 rtl_set_bbreg(hw
, 0xe5c, BMASKDWORD
, 0x68160960);
1854 /* LO calibration setting */
1855 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("LO calibration setting!\n"));
1856 rtl_set_bbreg(hw
, 0xe4c, BMASKDWORD
, 0x00462911);
1859 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
, BMASKDWORD
, 0x0f600700);
1860 rtl_set_bbreg(hw
, RFPGA0_XB_RFINTERFACEOE
, BMASKDWORD
, 0x061f0d30);
1862 for (i
= 0; i
< retrycount
; i
++) {
1863 /* One shot, path B LOK & IQK */
1864 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1865 ("One shot, path A LOK & IQK!\n"));
1866 rtl_set_bbreg(hw
, 0xe48, BMASKDWORD
, 0xfa000000);
1867 rtl_set_bbreg(hw
, 0xe48, BMASKDWORD
, 0xf8000000);
1870 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1871 ("Delay %d ms for One shot, path B LOK & IQK.\n", 10));
1872 mdelay(IQK_DELAY_TIME
* 10);
1875 regeac
= rtl_get_bbreg(hw
, 0xeac, BMASKDWORD
);
1876 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("0xeac = 0x%x\n", regeac
));
1877 regeb4
= rtl_get_bbreg(hw
, 0xeb4, BMASKDWORD
);
1878 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("0xeb4 = 0x%x\n", regeb4
));
1879 regebc
= rtl_get_bbreg(hw
, 0xebc, BMASKDWORD
);
1880 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("0xebc = 0x%x\n", regebc
));
1881 regec4
= rtl_get_bbreg(hw
, 0xec4, BMASKDWORD
);
1882 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("0xec4 = 0x%x\n", regec4
));
1883 regecc
= rtl_get_bbreg(hw
, 0xecc, BMASKDWORD
);
1884 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("0xecc = 0x%x\n", regecc
));
1885 if (!(regeac
& BIT(31)) &&
1886 (((regeb4
& 0x03FF0000) >> 16) != 0x142))
1890 if (!(regeac
& BIT(30)) &&
1891 (((regec4
& 0x03FF0000) >> 16) != 0x132)) {
1895 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1896 ("Path B Rx IQK fail!!\n"));
1901 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
, BMASKDWORD
,
1902 rtlphy
->iqk_bb_backup
[0]);
1903 rtl_set_bbreg(hw
, RFPGA0_XB_RFINTERFACEOE
, BMASKDWORD
,
1904 rtlphy
->iqk_bb_backup
[2]);
1908 static void _rtl92d_phy_save_adda_registers(struct ieee80211_hw
*hw
,
1909 u32
*adda_reg
, u32
*adda_backup
,
1912 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1915 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("Save ADDA parameters.\n"));
1916 for (i
= 0; i
< regnum
; i
++)
1917 adda_backup
[i
] = rtl_get_bbreg(hw
, adda_reg
[i
], BMASKDWORD
);
1920 static void _rtl92d_phy_save_mac_registers(struct ieee80211_hw
*hw
,
1921 u32
*macreg
, u32
*macbackup
)
1923 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1926 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("Save MAC parameters.\n"));
1927 for (i
= 0; i
< (IQK_MAC_REG_NUM
- 1); i
++)
1928 macbackup
[i
] = rtl_read_byte(rtlpriv
, macreg
[i
]);
1929 macbackup
[i
] = rtl_read_dword(rtlpriv
, macreg
[i
]);
1932 static void _rtl92d_phy_reload_adda_registers(struct ieee80211_hw
*hw
,
1933 u32
*adda_reg
, u32
*adda_backup
,
1936 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1939 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1940 ("Reload ADDA power saving parameters !\n"));
1941 for (i
= 0; i
< regnum
; i
++)
1942 rtl_set_bbreg(hw
, adda_reg
[i
], BMASKDWORD
, adda_backup
[i
]);
1945 static void _rtl92d_phy_reload_mac_registers(struct ieee80211_hw
*hw
,
1946 u32
*macreg
, u32
*macbackup
)
1948 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1951 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("Reload MAC parameters !\n"));
1952 for (i
= 0; i
< (IQK_MAC_REG_NUM
- 1); i
++)
1953 rtl_write_byte(rtlpriv
, macreg
[i
], (u8
) macbackup
[i
]);
1954 rtl_write_byte(rtlpriv
, macreg
[i
], macbackup
[i
]);
1957 static void _rtl92d_phy_path_adda_on(struct ieee80211_hw
*hw
,
1958 u32
*adda_reg
, bool patha_on
, bool is2t
)
1960 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1964 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("ADDA ON.\n"));
1965 pathon
= patha_on
? 0x04db25a4 : 0x0b1b25a4;
1967 pathon
= rtlpriv
->rtlhal
.interfaceindex
== 0 ?
1968 0x04db25a4 : 0x0b1b25a4;
1969 for (i
= 0; i
< IQK_ADDA_REG_NUM
; i
++)
1970 rtl_set_bbreg(hw
, adda_reg
[i
], BMASKDWORD
, pathon
);
1973 static void _rtl92d_phy_mac_setting_calibration(struct ieee80211_hw
*hw
,
1974 u32
*macreg
, u32
*macbackup
)
1976 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1979 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("MAC settings for Calibration.\n"));
1980 rtl_write_byte(rtlpriv
, macreg
[0], 0x3F);
1982 for (i
= 1; i
< (IQK_MAC_REG_NUM
- 1); i
++)
1983 rtl_write_byte(rtlpriv
, macreg
[i
], (u8
)(macbackup
[i
] &
1985 rtl_write_byte(rtlpriv
, macreg
[i
], (u8
) (macbackup
[i
] & (~BIT(5))));
1988 static void _rtl92d_phy_patha_standby(struct ieee80211_hw
*hw
)
1990 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1991 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("Path-A standby mode!\n"));
1993 rtl_set_bbreg(hw
, 0xe28, BMASKDWORD
, 0x0);
1994 rtl_set_bbreg(hw
, RFPGA0_XA_LSSIPARAMETER
, BMASKDWORD
, 0x00010000);
1995 rtl_set_bbreg(hw
, 0xe28, BMASKDWORD
, 0x80800000);
1998 static void _rtl92d_phy_pimode_switch(struct ieee80211_hw
*hw
, bool pi_mode
)
2000 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2003 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2004 ("BB Switch to %s mode!\n", (pi_mode
? "PI" : "SI")));
2005 mode
= pi_mode
? 0x01000100 : 0x01000000;
2006 rtl_set_bbreg(hw
, 0x820, BMASKDWORD
, mode
);
2007 rtl_set_bbreg(hw
, 0x828, BMASKDWORD
, mode
);
2010 static void _rtl92d_phy_iq_calibrate(struct ieee80211_hw
*hw
, long result
[][8],
2013 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2014 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2016 u8 patha_ok
, pathb_ok
;
2017 static u32 adda_reg
[IQK_ADDA_REG_NUM
] = {
2018 RFPGA0_XCD_SWITCHCONTROL
, 0xe6c, 0xe70, 0xe74,
2019 0xe78, 0xe7c, 0xe80, 0xe84,
2020 0xe88, 0xe8c, 0xed0, 0xed4,
2021 0xed8, 0xedc, 0xee0, 0xeec
2023 static u32 iqk_mac_reg
[IQK_MAC_REG_NUM
] = {
2024 0x522, 0x550, 0x551, 0x040
2026 static u32 iqk_bb_reg
[IQK_BB_REG_NUM
] = {
2027 RFPGA0_XAB_RFINTERFACESW
, RFPGA0_XA_RFINTERFACEOE
,
2028 RFPGA0_XB_RFINTERFACEOE
, ROFDM0_TRMUXPAR
,
2029 RFPGA0_XCD_RFINTERFACESW
, ROFDM0_TRXPATHENABLE
,
2030 RFPGA0_RFMOD
, RFPGA0_ANALOGPARAMETER4
,
2031 ROFDM0_XAAGCCORE1
, ROFDM0_XBAGCCORE1
2033 const u32 retrycount
= 2;
2036 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("IQK for 2.4G :Start!!!\n"));
2038 bbvalue
= rtl_get_bbreg(hw
, RFPGA0_RFMOD
, BMASKDWORD
);
2039 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("==>0x%08x\n", bbvalue
));
2040 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("IQ Calibration for %s\n",
2041 (is2t
? "2T2R" : "1T1R")));
2043 /* Save ADDA parameters, turn Path A ADDA on */
2044 _rtl92d_phy_save_adda_registers(hw
, adda_reg
,
2045 rtlphy
->adda_backup
, IQK_ADDA_REG_NUM
);
2046 _rtl92d_phy_save_mac_registers(hw
, iqk_mac_reg
,
2047 rtlphy
->iqk_mac_backup
);
2048 _rtl92d_phy_save_adda_registers(hw
, iqk_bb_reg
,
2049 rtlphy
->iqk_bb_backup
, IQK_BB_REG_NUM
);
2051 _rtl92d_phy_path_adda_on(hw
, adda_reg
, true, is2t
);
2053 rtlphy
->rfpi_enable
= (u8
) rtl_get_bbreg(hw
,
2054 RFPGA0_XA_HSSIPARAMETER1
, BIT(8));
2056 /* Switch BB to PI mode to do IQ Calibration. */
2057 if (!rtlphy
->rfpi_enable
)
2058 _rtl92d_phy_pimode_switch(hw
, true);
2060 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BIT(24), 0x00);
2061 rtl_set_bbreg(hw
, ROFDM0_TRXPATHENABLE
, BMASKDWORD
, 0x03a05600);
2062 rtl_set_bbreg(hw
, ROFDM0_TRMUXPAR
, BMASKDWORD
, 0x000800e4);
2063 rtl_set_bbreg(hw
, RFPGA0_XCD_RFINTERFACESW
, BMASKDWORD
, 0x22204000);
2064 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
, 0xf00000, 0x0f);
2066 rtl_set_bbreg(hw
, RFPGA0_XA_LSSIPARAMETER
, BMASKDWORD
,
2068 rtl_set_bbreg(hw
, RFPGA0_XB_LSSIPARAMETER
, BMASKDWORD
,
2072 _rtl92d_phy_mac_setting_calibration(hw
, iqk_mac_reg
,
2073 rtlphy
->iqk_mac_backup
);
2075 rtl_set_bbreg(hw
, 0xb68, BMASKDWORD
, 0x0f600000);
2077 rtl_set_bbreg(hw
, 0xb6c, BMASKDWORD
, 0x0f600000);
2078 /* IQ calibration setting */
2079 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("IQK setting!\n"));
2080 rtl_set_bbreg(hw
, 0xe28, BMASKDWORD
, 0x80800000);
2081 rtl_set_bbreg(hw
, 0xe40, BMASKDWORD
, 0x01007c00);
2082 rtl_set_bbreg(hw
, 0xe44, BMASKDWORD
, 0x01004800);
2083 for (i
= 0; i
< retrycount
; i
++) {
2084 patha_ok
= _rtl92d_phy_patha_iqk(hw
, is2t
);
2085 if (patha_ok
== 0x03) {
2086 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2087 ("Path A IQK Success!!\n"));
2088 result
[t
][0] = (rtl_get_bbreg(hw
, 0xe94, BMASKDWORD
) &
2090 result
[t
][1] = (rtl_get_bbreg(hw
, 0xe9c, BMASKDWORD
) &
2092 result
[t
][2] = (rtl_get_bbreg(hw
, 0xea4, BMASKDWORD
) &
2094 result
[t
][3] = (rtl_get_bbreg(hw
, 0xeac, BMASKDWORD
) &
2097 } else if (i
== (retrycount
- 1) && patha_ok
== 0x01) {
2099 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2100 ("Path A IQK Only Tx Success!!\n"));
2102 result
[t
][0] = (rtl_get_bbreg(hw
, 0xe94, BMASKDWORD
) &
2104 result
[t
][1] = (rtl_get_bbreg(hw
, 0xe9c, BMASKDWORD
) &
2108 if (0x00 == patha_ok
)
2109 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("Path A IQK failed!!\n"));
2111 _rtl92d_phy_patha_standby(hw
);
2112 /* Turn Path B ADDA on */
2113 _rtl92d_phy_path_adda_on(hw
, adda_reg
, false, is2t
);
2114 for (i
= 0; i
< retrycount
; i
++) {
2115 pathb_ok
= _rtl92d_phy_pathb_iqk(hw
);
2116 if (pathb_ok
== 0x03) {
2117 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2118 ("Path B IQK Success!!\n"));
2119 result
[t
][4] = (rtl_get_bbreg(hw
, 0xeb4,
2120 BMASKDWORD
) & 0x3FF0000) >> 16;
2121 result
[t
][5] = (rtl_get_bbreg(hw
, 0xebc,
2122 BMASKDWORD
) & 0x3FF0000) >> 16;
2123 result
[t
][6] = (rtl_get_bbreg(hw
, 0xec4,
2124 BMASKDWORD
) & 0x3FF0000) >> 16;
2125 result
[t
][7] = (rtl_get_bbreg(hw
, 0xecc,
2126 BMASKDWORD
) & 0x3FF0000) >> 16;
2128 } else if (i
== (retrycount
- 1) && pathb_ok
== 0x01) {
2130 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2131 ("Path B Only Tx IQK Success!!\n"));
2132 result
[t
][4] = (rtl_get_bbreg(hw
, 0xeb4,
2133 BMASKDWORD
) & 0x3FF0000) >> 16;
2134 result
[t
][5] = (rtl_get_bbreg(hw
, 0xebc,
2135 BMASKDWORD
) & 0x3FF0000) >> 16;
2138 if (0x00 == pathb_ok
)
2139 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2140 ("Path B IQK failed!!\n"));
2143 /* Back to BB mode, load original value */
2144 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2145 ("IQK:Back to BB mode, load original value!\n"));
2147 rtl_set_bbreg(hw
, 0xe28, BMASKDWORD
, 0);
2149 /* Switch back BB to SI mode after finish IQ Calibration. */
2150 if (!rtlphy
->rfpi_enable
)
2151 _rtl92d_phy_pimode_switch(hw
, false);
2152 /* Reload ADDA power saving parameters */
2153 _rtl92d_phy_reload_adda_registers(hw
, adda_reg
,
2154 rtlphy
->adda_backup
, IQK_ADDA_REG_NUM
);
2155 /* Reload MAC parameters */
2156 _rtl92d_phy_reload_mac_registers(hw
, iqk_mac_reg
,
2157 rtlphy
->iqk_mac_backup
);
2159 _rtl92d_phy_reload_adda_registers(hw
, iqk_bb_reg
,
2160 rtlphy
->iqk_bb_backup
,
2163 _rtl92d_phy_reload_adda_registers(hw
, iqk_bb_reg
,
2164 rtlphy
->iqk_bb_backup
,
2165 IQK_BB_REG_NUM
- 1);
2166 /* load 0xe30 IQC default value */
2167 rtl_set_bbreg(hw
, 0xe30, BMASKDWORD
, 0x01008c00);
2168 rtl_set_bbreg(hw
, 0xe34, BMASKDWORD
, 0x01008c00);
2170 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("<==\n"));
2173 static void _rtl92d_phy_iq_calibrate_5g_normal(struct ieee80211_hw
*hw
,
2174 long result
[][8], u8 t
)
2176 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2177 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2178 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
2179 u8 patha_ok
, pathb_ok
;
2180 static u32 adda_reg
[IQK_ADDA_REG_NUM
] = {
2181 RFPGA0_XCD_SWITCHCONTROL
, 0xe6c, 0xe70, 0xe74,
2182 0xe78, 0xe7c, 0xe80, 0xe84,
2183 0xe88, 0xe8c, 0xed0, 0xed4,
2184 0xed8, 0xedc, 0xee0, 0xeec
2186 static u32 iqk_mac_reg
[IQK_MAC_REG_NUM
] = {
2187 0x522, 0x550, 0x551, 0x040
2189 static u32 iqk_bb_reg
[IQK_BB_REG_NUM
] = {
2190 RFPGA0_XAB_RFINTERFACESW
, RFPGA0_XA_RFINTERFACEOE
,
2191 RFPGA0_XB_RFINTERFACEOE
, ROFDM0_TRMUXPAR
,
2192 RFPGA0_XCD_RFINTERFACESW
, ROFDM0_TRXPATHENABLE
,
2193 RFPGA0_RFMOD
, RFPGA0_ANALOGPARAMETER4
,
2194 ROFDM0_XAAGCCORE1
, ROFDM0_XBAGCCORE1
2197 bool is2t
= IS_92D_SINGLEPHY(rtlhal
->version
);
2199 /* Note: IQ calibration must be performed after loading
2200 * PHY_REG.txt , and radio_a, radio_b.txt */
2202 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("IQK for 5G NORMAL:Start!!!\n"));
2203 mdelay(IQK_DELAY_TIME
* 20);
2205 bbvalue
= rtl_get_bbreg(hw
, RFPGA0_RFMOD
, BMASKDWORD
);
2206 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("==>0x%08x\n", bbvalue
));
2207 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("IQ Calibration for %s\n",
2208 (is2t
? "2T2R" : "1T1R")));
2209 /* Save ADDA parameters, turn Path A ADDA on */
2210 _rtl92d_phy_save_adda_registers(hw
, adda_reg
,
2211 rtlphy
->adda_backup
,
2213 _rtl92d_phy_save_mac_registers(hw
, iqk_mac_reg
,
2214 rtlphy
->iqk_mac_backup
);
2216 _rtl92d_phy_save_adda_registers(hw
, iqk_bb_reg
,
2217 rtlphy
->iqk_bb_backup
,
2220 _rtl92d_phy_save_adda_registers(hw
, iqk_bb_reg
,
2221 rtlphy
->iqk_bb_backup
,
2222 IQK_BB_REG_NUM
- 1);
2224 _rtl92d_phy_path_adda_on(hw
, adda_reg
, true, is2t
);
2226 _rtl92d_phy_mac_setting_calibration(hw
, iqk_mac_reg
,
2227 rtlphy
->iqk_mac_backup
);
2229 rtlphy
->rfpi_enable
= (u8
) rtl_get_bbreg(hw
,
2230 RFPGA0_XA_HSSIPARAMETER1
, BIT(8));
2231 /* Switch BB to PI mode to do IQ Calibration. */
2232 if (!rtlphy
->rfpi_enable
)
2233 _rtl92d_phy_pimode_switch(hw
, true);
2234 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BIT(24), 0x00);
2235 rtl_set_bbreg(hw
, ROFDM0_TRXPATHENABLE
, BMASKDWORD
, 0x03a05600);
2236 rtl_set_bbreg(hw
, ROFDM0_TRMUXPAR
, BMASKDWORD
, 0x000800e4);
2237 rtl_set_bbreg(hw
, RFPGA0_XCD_RFINTERFACESW
, BMASKDWORD
, 0x22208000);
2238 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
, 0xf00000, 0x0f);
2241 rtl_set_bbreg(hw
, 0xb68, BMASKDWORD
, 0x0f600000);
2243 rtl_set_bbreg(hw
, 0xb6c, BMASKDWORD
, 0x0f600000);
2244 /* IQ calibration setting */
2245 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("IQK setting!\n"));
2246 rtl_set_bbreg(hw
, 0xe28, BMASKDWORD
, 0x80800000);
2247 rtl_set_bbreg(hw
, 0xe40, BMASKDWORD
, 0x10007c00);
2248 rtl_set_bbreg(hw
, 0xe44, BMASKDWORD
, 0x01004800);
2249 patha_ok
= _rtl92d_phy_patha_iqk_5g_normal(hw
, is2t
);
2250 if (patha_ok
== 0x03) {
2251 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("Path A IQK Success!!\n"));
2252 result
[t
][0] = (rtl_get_bbreg(hw
, 0xe94, BMASKDWORD
) &
2254 result
[t
][1] = (rtl_get_bbreg(hw
, 0xe9c, BMASKDWORD
) &
2256 result
[t
][2] = (rtl_get_bbreg(hw
, 0xea4, BMASKDWORD
) &
2258 result
[t
][3] = (rtl_get_bbreg(hw
, 0xeac, BMASKDWORD
) &
2260 } else if (patha_ok
== 0x01) { /* Tx IQK OK */
2261 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2262 ("Path A IQK Only Tx Success!!\n"));
2264 result
[t
][0] = (rtl_get_bbreg(hw
, 0xe94, BMASKDWORD
) &
2266 result
[t
][1] = (rtl_get_bbreg(hw
, 0xe9c, BMASKDWORD
) &
2269 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("Path A IQK Fail!!\n"));
2272 /* _rtl92d_phy_patha_standby(hw); */
2273 /* Turn Path B ADDA on */
2274 _rtl92d_phy_path_adda_on(hw
, adda_reg
, false, is2t
);
2275 pathb_ok
= _rtl92d_phy_pathb_iqk_5g_normal(hw
);
2276 if (pathb_ok
== 0x03) {
2277 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2278 ("Path B IQK Success!!\n"));
2279 result
[t
][4] = (rtl_get_bbreg(hw
, 0xeb4, BMASKDWORD
) &
2281 result
[t
][5] = (rtl_get_bbreg(hw
, 0xebc, BMASKDWORD
) &
2283 result
[t
][6] = (rtl_get_bbreg(hw
, 0xec4, BMASKDWORD
) &
2285 result
[t
][7] = (rtl_get_bbreg(hw
, 0xecc, BMASKDWORD
) &
2287 } else if (pathb_ok
== 0x01) { /* Tx IQK OK */
2288 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2289 ("Path B Only Tx IQK Success!!\n"));
2290 result
[t
][4] = (rtl_get_bbreg(hw
, 0xeb4, BMASKDWORD
) &
2292 result
[t
][5] = (rtl_get_bbreg(hw
, 0xebc, BMASKDWORD
) &
2295 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2296 ("Path B IQK failed!!\n"));
2300 /* Back to BB mode, load original value */
2301 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2302 ("IQK:Back to BB mode, load original value!\n"));
2303 rtl_set_bbreg(hw
, 0xe28, BMASKDWORD
, 0);
2306 _rtl92d_phy_reload_adda_registers(hw
, iqk_bb_reg
,
2307 rtlphy
->iqk_bb_backup
,
2310 _rtl92d_phy_reload_adda_registers(hw
, iqk_bb_reg
,
2311 rtlphy
->iqk_bb_backup
,
2312 IQK_BB_REG_NUM
- 1);
2313 /* Reload MAC parameters */
2314 _rtl92d_phy_reload_mac_registers(hw
, iqk_mac_reg
,
2315 rtlphy
->iqk_mac_backup
);
2316 /* Switch back BB to SI mode after finish IQ Calibration. */
2317 if (!rtlphy
->rfpi_enable
)
2318 _rtl92d_phy_pimode_switch(hw
, false);
2319 /* Reload ADDA power saving parameters */
2320 _rtl92d_phy_reload_adda_registers(hw
, adda_reg
,
2321 rtlphy
->adda_backup
,
2324 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("<==\n"));
2327 static bool _rtl92d_phy_simularity_compare(struct ieee80211_hw
*hw
,
2328 long result
[][8], u8 c1
, u8 c2
)
2330 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2331 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
2332 u32 i
, j
, diff
, sim_bitmap
, bound
;
2333 u8 final_candidate
[2] = {0xFF, 0xFF}; /* for path A and path B */
2334 bool bresult
= true;
2335 bool is2t
= IS_92D_SINGLEPHY(rtlhal
->version
);
2342 for (i
= 0; i
< bound
; i
++) {
2343 diff
= (result
[c1
][i
] > result
[c2
][i
]) ? (result
[c1
][i
] -
2344 result
[c2
][i
]) : (result
[c2
][i
] - result
[c1
][i
]);
2345 if (diff
> MAX_TOLERANCE_92D
) {
2346 if ((i
== 2 || i
== 6) && !sim_bitmap
) {
2347 if (result
[c1
][i
] + result
[c1
][i
+ 1] == 0)
2348 final_candidate
[(i
/ 4)] = c2
;
2349 else if (result
[c2
][i
] + result
[c2
][i
+ 1] == 0)
2350 final_candidate
[(i
/ 4)] = c1
;
2352 sim_bitmap
= sim_bitmap
| (1 << i
);
2354 sim_bitmap
= sim_bitmap
| (1 << i
);
2358 if (sim_bitmap
== 0) {
2359 for (i
= 0; i
< (bound
/ 4); i
++) {
2360 if (final_candidate
[i
] != 0xFF) {
2361 for (j
= i
* 4; j
< (i
+ 1) * 4 - 2; j
++)
2363 result
[final_candidate
[i
]][j
];
2369 if (!(sim_bitmap
& 0x0F)) { /* path A OK */
2370 for (i
= 0; i
< 4; i
++)
2371 result
[3][i
] = result
[c1
][i
];
2372 } else if (!(sim_bitmap
& 0x03)) { /* path A, Tx OK */
2373 for (i
= 0; i
< 2; i
++)
2374 result
[3][i
] = result
[c1
][i
];
2376 if (!(sim_bitmap
& 0xF0) && is2t
) { /* path B OK */
2377 for (i
= 4; i
< 8; i
++)
2378 result
[3][i
] = result
[c1
][i
];
2379 } else if (!(sim_bitmap
& 0x30)) { /* path B, Tx OK */
2380 for (i
= 4; i
< 6; i
++)
2381 result
[3][i
] = result
[c1
][i
];
2386 static void _rtl92d_phy_patha_fill_iqk_matrix(struct ieee80211_hw
*hw
,
2387 bool iqk_ok
, long result
[][8],
2388 u8 final_candidate
, bool txonly
)
2390 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2391 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
2392 u32 oldval_0
, val_x
, tx0_a
, reg
;
2394 bool is2t
= IS_92D_SINGLEPHY(rtlhal
->version
) ||
2395 rtlhal
->macphymode
== DUALMAC_DUALPHY
;
2397 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2398 ("Path A IQ Calibration %s !\n",
2399 (iqk_ok
) ? "Success" : "Failed"));
2400 if (final_candidate
== 0xFF) {
2402 } else if (iqk_ok
) {
2403 oldval_0
= (rtl_get_bbreg(hw
, ROFDM0_XATxIQIMBALANCE
,
2404 BMASKDWORD
) >> 22) & 0x3FF; /* OFDM0_D */
2405 val_x
= result
[final_candidate
][0];
2406 if ((val_x
& 0x00000200) != 0)
2407 val_x
= val_x
| 0xFFFFFC00;
2408 tx0_a
= (val_x
* oldval_0
) >> 8;
2409 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("X = 0x%x, tx0_a = 0x%x,"
2410 " oldval_0 0x%x\n", val_x
, tx0_a
, oldval_0
));
2411 rtl_set_bbreg(hw
, ROFDM0_XATxIQIMBALANCE
, 0x3FF, tx0_a
);
2412 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
, BIT(24),
2413 ((val_x
* oldval_0
>> 7) & 0x1));
2414 val_y
= result
[final_candidate
][1];
2415 if ((val_y
& 0x00000200) != 0)
2416 val_y
= val_y
| 0xFFFFFC00;
2417 /* path B IQK result + 3 */
2418 if (rtlhal
->interfaceindex
== 1 &&
2419 rtlhal
->current_bandtype
== BAND_ON_5G
)
2421 tx0_c
= (val_y
* oldval_0
) >> 8;
2422 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("Y = 0x%lx, tx0_c = 0x%lx\n",
2424 rtl_set_bbreg(hw
, ROFDM0_XCTxAFE
, 0xF0000000,
2425 ((tx0_c
& 0x3C0) >> 6));
2426 rtl_set_bbreg(hw
, ROFDM0_XATxIQIMBALANCE
, 0x003F0000,
2429 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
, BIT(26),
2430 ((val_y
* oldval_0
>> 7) & 0x1));
2431 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("0xC80 = 0x%x\n",
2432 rtl_get_bbreg(hw
, ROFDM0_XATxIQIMBALANCE
,
2435 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("only Tx OK\n"));
2438 reg
= result
[final_candidate
][2];
2439 rtl_set_bbreg(hw
, ROFDM0_XARXIQIMBALANCE
, 0x3FF, reg
);
2440 reg
= result
[final_candidate
][3] & 0x3F;
2441 rtl_set_bbreg(hw
, ROFDM0_XARXIQIMBALANCE
, 0xFC00, reg
);
2442 reg
= (result
[final_candidate
][3] >> 6) & 0xF;
2443 rtl_set_bbreg(hw
, 0xca0, 0xF0000000, reg
);
2447 static void _rtl92d_phy_pathb_fill_iqk_matrix(struct ieee80211_hw
*hw
,
2448 bool iqk_ok
, long result
[][8], u8 final_candidate
, bool txonly
)
2450 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2451 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
2452 u32 oldval_1
, val_x
, tx1_a
, reg
;
2455 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("Path B IQ Calibration %s !\n",
2456 (iqk_ok
) ? "Success" : "Failed"));
2457 if (final_candidate
== 0xFF) {
2459 } else if (iqk_ok
) {
2460 oldval_1
= (rtl_get_bbreg(hw
, ROFDM0_XBTxIQIMBALANCE
,
2461 BMASKDWORD
) >> 22) & 0x3FF;
2462 val_x
= result
[final_candidate
][4];
2463 if ((val_x
& 0x00000200) != 0)
2464 val_x
= val_x
| 0xFFFFFC00;
2465 tx1_a
= (val_x
* oldval_1
) >> 8;
2466 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("X = 0x%x, tx1_a = 0x%x\n",
2468 rtl_set_bbreg(hw
, ROFDM0_XBTxIQIMBALANCE
, 0x3FF, tx1_a
);
2469 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
, BIT(28),
2470 ((val_x
* oldval_1
>> 7) & 0x1));
2471 val_y
= result
[final_candidate
][5];
2472 if ((val_y
& 0x00000200) != 0)
2473 val_y
= val_y
| 0xFFFFFC00;
2474 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
2476 tx1_c
= (val_y
* oldval_1
) >> 8;
2477 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("Y = 0x%lx, tx1_c = 0x%lx\n",
2479 rtl_set_bbreg(hw
, ROFDM0_XDTxAFE
, 0xF0000000,
2480 ((tx1_c
& 0x3C0) >> 6));
2481 rtl_set_bbreg(hw
, ROFDM0_XBTxIQIMBALANCE
, 0x003F0000,
2483 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
, BIT(30),
2484 ((val_y
* oldval_1
>> 7) & 0x1));
2487 reg
= result
[final_candidate
][6];
2488 rtl_set_bbreg(hw
, ROFDM0_XBRXIQIMBALANCE
, 0x3FF, reg
);
2489 reg
= result
[final_candidate
][7] & 0x3F;
2490 rtl_set_bbreg(hw
, ROFDM0_XBRXIQIMBALANCE
, 0xFC00, reg
);
2491 reg
= (result
[final_candidate
][7] >> 6) & 0xF;
2492 rtl_set_bbreg(hw
, ROFDM0_AGCRSSITABLE
, 0x0000F000, reg
);
2496 void rtl92d_phy_iq_calibrate(struct ieee80211_hw
*hw
)
2498 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2499 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2500 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
2502 u8 i
, final_candidate
, indexforchannel
;
2503 bool patha_ok
, pathb_ok
;
2504 long rege94
, rege9c
, regea4
, regeac
, regeb4
;
2505 long regebc
, regec4
, regecc
, regtmp
= 0;
2506 bool is12simular
, is13simular
, is23simular
;
2507 unsigned long flag
= 0;
2509 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2510 ("IQK:Start!!!channel %d\n", rtlphy
->current_channel
));
2511 for (i
= 0; i
< 8; i
++) {
2517 final_candidate
= 0xff;
2520 is12simular
= false;
2521 is23simular
= false;
2522 is13simular
= false;
2523 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2524 ("IQK !!!currentband %d\n", rtlhal
->current_bandtype
));
2525 rtl92d_acquire_cckandrw_pagea_ctl(hw
, &flag
);
2526 for (i
= 0; i
< 3; i
++) {
2527 if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
2528 _rtl92d_phy_iq_calibrate_5g_normal(hw
, result
, i
);
2529 } else if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
2530 if (IS_92D_SINGLEPHY(rtlhal
->version
))
2531 _rtl92d_phy_iq_calibrate(hw
, result
, i
, true);
2533 _rtl92d_phy_iq_calibrate(hw
, result
, i
, false);
2536 is12simular
= _rtl92d_phy_simularity_compare(hw
, result
,
2539 final_candidate
= 0;
2544 is13simular
= _rtl92d_phy_simularity_compare(hw
, result
,
2547 final_candidate
= 0;
2550 is23simular
= _rtl92d_phy_simularity_compare(hw
, result
,
2553 final_candidate
= 1;
2555 for (i
= 0; i
< 8; i
++)
2556 regtmp
+= result
[3][i
];
2559 final_candidate
= 3;
2561 final_candidate
= 0xFF;
2565 rtl92d_release_cckandrw_pagea_ctl(hw
, &flag
);
2566 for (i
= 0; i
< 4; i
++) {
2567 rege94
= result
[i
][0];
2568 rege9c
= result
[i
][1];
2569 regea4
= result
[i
][2];
2570 regeac
= result
[i
][3];
2571 regeb4
= result
[i
][4];
2572 regebc
= result
[i
][5];
2573 regec4
= result
[i
][6];
2574 regecc
= result
[i
][7];
2575 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2576 ("IQK: rege94=%lx rege9c=%lx regea4=%lx regeac=%lx "
2577 "regeb4=%lx regebc=%lx regec4=%lx regecc=%lx\n ",
2578 rege94
, rege9c
, regea4
, regeac
, regeb4
, regebc
, regec4
,
2581 if (final_candidate
!= 0xff) {
2582 rtlphy
->reg_e94
= rege94
= result
[final_candidate
][0];
2583 rtlphy
->reg_e9c
= rege9c
= result
[final_candidate
][1];
2584 regea4
= result
[final_candidate
][2];
2585 regeac
= result
[final_candidate
][3];
2586 rtlphy
->reg_eb4
= regeb4
= result
[final_candidate
][4];
2587 rtlphy
->reg_ebc
= regebc
= result
[final_candidate
][5];
2588 regec4
= result
[final_candidate
][6];
2589 regecc
= result
[final_candidate
][7];
2590 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2591 ("IQK: final_candidate is %x\n", final_candidate
));
2592 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2593 ("IQK: rege94=%lx rege9c=%lx regea4=%lx regeac=%lx "
2594 "regeb4=%lx regebc=%lx regec4=%lx regecc=%lx\n ",
2595 rege94
, rege9c
, regea4
, regeac
, regeb4
, regebc
, regec4
,
2597 patha_ok
= pathb_ok
= true;
2599 rtlphy
->reg_e94
= rtlphy
->reg_eb4
= 0x100; /* X default value */
2600 rtlphy
->reg_e9c
= rtlphy
->reg_ebc
= 0x0; /* Y default value */
2602 if ((rege94
!= 0) /*&&(regea4 != 0) */)
2603 _rtl92d_phy_patha_fill_iqk_matrix(hw
, patha_ok
, result
,
2604 final_candidate
, (regea4
== 0));
2605 if (IS_92D_SINGLEPHY(rtlhal
->version
)) {
2606 if ((regeb4
!= 0) /*&&(regec4 != 0) */)
2607 _rtl92d_phy_pathb_fill_iqk_matrix(hw
, pathb_ok
, result
,
2608 final_candidate
, (regec4
== 0));
2610 if (final_candidate
!= 0xFF) {
2611 indexforchannel
= rtl92d_get_rightchnlplace_for_iqk(
2612 rtlphy
->current_channel
);
2614 for (i
= 0; i
< IQK_MATRIX_REG_NUM
; i
++)
2615 rtlphy
->iqk_matrix_regsetting
[indexforchannel
].
2616 value
[0][i
] = result
[final_candidate
][i
];
2617 rtlphy
->iqk_matrix_regsetting
[indexforchannel
].iqk_done
=
2620 RT_TRACE(rtlpriv
, COMP_SCAN
| COMP_MLME
, DBG_LOUD
,
2621 ("\nIQK OK indexforchannel %d.\n", indexforchannel
));
2625 void rtl92d_phy_reload_iqk_setting(struct ieee80211_hw
*hw
, u8 channel
)
2627 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2628 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2629 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
2632 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, ("channel %d\n", channel
));
2633 /*------Do IQK for normal chip and test chip 5G band------- */
2634 indexforchannel
= rtl92d_get_rightchnlplace_for_iqk(channel
);
2635 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
,
2636 ("indexforchannel %d done %d\n", indexforchannel
,
2637 rtlphy
->iqk_matrix_regsetting
[indexforchannel
].iqk_done
));
2638 if (0 && !rtlphy
->iqk_matrix_regsetting
[indexforchannel
].iqk_done
&&
2641 RT_TRACE(rtlpriv
, COMP_SCAN
| COMP_INIT
, DBG_LOUD
,
2642 ("Do IQK Matrix reg for channel:%d....\n", channel
));
2643 rtl92d_phy_iq_calibrate(hw
);
2645 /* Just load the value. */
2646 /* 2G band just load once. */
2647 if (((!rtlhal
->load_imrandiqk_setting_for2g
) &&
2648 indexforchannel
== 0) || indexforchannel
> 0) {
2649 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_LOUD
,
2650 ("Just Read IQK Matrix reg for channel:%d"
2651 "....\n", channel
));
2652 if ((rtlphy
->iqk_matrix_regsetting
[indexforchannel
].
2654 /*&&(regea4 != 0) */)
2655 _rtl92d_phy_patha_fill_iqk_matrix(hw
, true,
2656 rtlphy
->iqk_matrix_regsetting
[
2657 indexforchannel
].value
, 0,
2658 (rtlphy
->iqk_matrix_regsetting
[
2659 indexforchannel
].value
[0][2] == 0));
2660 if (IS_92D_SINGLEPHY(rtlhal
->version
)) {
2661 if ((rtlphy
->iqk_matrix_regsetting
[
2662 indexforchannel
].value
[0][4] != 0)
2663 /*&&(regec4 != 0) */)
2664 _rtl92d_phy_pathb_fill_iqk_matrix(hw
,
2666 rtlphy
->iqk_matrix_regsetting
[
2667 indexforchannel
].value
, 0,
2668 (rtlphy
->iqk_matrix_regsetting
[
2669 indexforchannel
].value
[0][6]
2674 rtlphy
->need_iqk
= false;
2675 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, ("<====\n"));
2678 static u32
_rtl92d_phy_get_abs(u32 val1
, u32 val2
)
2689 static bool _rtl92d_is_legal_5g_channel(struct ieee80211_hw
*hw
, u8 channel
)
2693 u8 channel_5g
[45] = {
2694 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58,
2695 60, 62, 64, 100, 102, 104, 106, 108, 110, 112,
2696 114, 116, 118, 120, 122, 124, 126, 128, 130, 132,
2697 134, 136, 138, 140, 149, 151, 153, 155, 157, 159,
2701 for (i
= 0; i
< sizeof(channel_5g
); i
++)
2702 if (channel
== channel_5g
[i
])
2707 static void _rtl92d_phy_calc_curvindex(struct ieee80211_hw
*hw
,
2708 u32
*targetchnl
, u32
* curvecount_val
,
2709 bool is5g
, u32
*curveindex
)
2711 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2712 u32 smallest_abs_val
= 0xffffffff, u4tmp
;
2714 u8 chnl_num
= is5g
? TARGET_CHNL_NUM_5G
: TARGET_CHNL_NUM_2G
;
2716 for (i
= 0; i
< chnl_num
; i
++) {
2717 if (is5g
&& !_rtl92d_is_legal_5g_channel(hw
, i
+ 1))
2720 for (j
= 0; j
< (CV_CURVE_CNT
* 2); j
++) {
2721 u4tmp
= _rtl92d_phy_get_abs(targetchnl
[i
],
2724 if (u4tmp
< smallest_abs_val
) {
2726 smallest_abs_val
= u4tmp
;
2729 smallest_abs_val
= 0xffffffff;
2730 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("curveindex[%d] = %x\n", i
,
2735 static void _rtl92d_phy_reload_lck_setting(struct ieee80211_hw
*hw
,
2738 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2739 u8 erfpath
= rtlpriv
->rtlhal
.current_bandtype
==
2740 BAND_ON_5G
? RF90_PATH_A
:
2741 IS_92D_SINGLEPHY(rtlpriv
->rtlhal
.version
) ?
2742 RF90_PATH_B
: RF90_PATH_A
;
2743 u32 u4tmp
= 0, u4regvalue
= 0;
2744 bool bneed_powerdown_radio
= false;
2746 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, ("path %d\n", erfpath
));
2747 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("band type = %d\n",
2748 rtlpriv
->rtlhal
.current_bandtype
));
2749 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("channel = %d\n", channel
));
2750 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_5G
) {/* Path-A for 5G */
2751 u4tmp
= curveindex_5g
[channel
-1];
2752 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2753 ("ver 1 set RF-A, 5G, 0x28 = 0x%ulx !!\n", u4tmp
));
2754 if (rtlpriv
->rtlhal
.macphymode
== DUALMAC_DUALPHY
&&
2755 rtlpriv
->rtlhal
.interfaceindex
== 1) {
2756 bneed_powerdown_radio
=
2757 rtl92d_phy_enable_anotherphy(hw
, false);
2758 rtlpriv
->rtlhal
.during_mac1init_radioa
= true;
2759 /* asume no this case */
2760 if (bneed_powerdown_radio
)
2761 _rtl92d_phy_enable_rf_env(hw
, erfpath
,
2764 rtl_set_rfreg(hw
, erfpath
, RF_SYN_G4
, 0x3f800, u4tmp
);
2765 if (bneed_powerdown_radio
)
2766 _rtl92d_phy_restore_rf_env(hw
, erfpath
, &u4regvalue
);
2767 if (rtlpriv
->rtlhal
.during_mac1init_radioa
)
2768 rtl92d_phy_powerdown_anotherphy(hw
, false);
2769 } else if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
) {
2770 u4tmp
= curveindex_2g
[channel
-1];
2771 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2772 ("ver 3 set RF-B, 2G, 0x28 = 0x%ulx !!\n", u4tmp
));
2773 if (rtlpriv
->rtlhal
.macphymode
== DUALMAC_DUALPHY
&&
2774 rtlpriv
->rtlhal
.interfaceindex
== 0) {
2775 bneed_powerdown_radio
=
2776 rtl92d_phy_enable_anotherphy(hw
, true);
2777 rtlpriv
->rtlhal
.during_mac0init_radiob
= true;
2778 if (bneed_powerdown_radio
)
2779 _rtl92d_phy_enable_rf_env(hw
, erfpath
,
2782 rtl_set_rfreg(hw
, erfpath
, RF_SYN_G4
, 0x3f800, u4tmp
);
2783 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2784 ("ver 3 set RF-B, 2G, 0x28 = 0x%ulx !!\n",
2785 rtl_get_rfreg(hw
, erfpath
, RF_SYN_G4
, 0x3f800)));
2786 if (bneed_powerdown_radio
)
2787 _rtl92d_phy_restore_rf_env(hw
, erfpath
, &u4regvalue
);
2788 if (rtlpriv
->rtlhal
.during_mac0init_radiob
)
2789 rtl92d_phy_powerdown_anotherphy(hw
, true);
2791 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, ("<====\n"));
2794 static void _rtl92d_phy_lc_calibrate_sw(struct ieee80211_hw
*hw
, bool is2t
)
2796 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2797 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
2798 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2799 u8 tmpreg
, index
, rf_mode
[2];
2800 u8 path
= is2t
? 2 : 1;
2803 u32 curvecount_val
[CV_CURVE_CNT
* 2] = {0};
2804 u16 timeout
= 800, timecount
= 0;
2806 /* Check continuous TX and Packet TX */
2807 tmpreg
= rtl_read_byte(rtlpriv
, 0xd03);
2808 /* if Deal with contisuous TX case, disable all continuous TX */
2809 /* if Deal with Packet TX case, block all queues */
2810 if ((tmpreg
& 0x70) != 0)
2811 rtl_write_byte(rtlpriv
, 0xd03, tmpreg
& 0x8F);
2813 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0xFF);
2814 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
, 0xF00000, 0x0F);
2815 for (index
= 0; index
< path
; index
++) {
2816 /* 1. Read original RF mode */
2817 offset
= index
== 0 ? ROFDM0_XAAGCCORE1
: ROFDM0_XBAGCCORE1
;
2818 rf_mode
[index
] = rtl_read_byte(rtlpriv
, offset
);
2819 /* 2. Set RF mode = standby mode */
2820 rtl_set_rfreg(hw
, (enum radio_path
)index
, RF_AC
,
2821 BRFREGOFFSETMASK
, 0x010000);
2822 if (rtlpci
->init_ready
) {
2823 /* switch CV-curve control by LC-calibration */
2824 rtl_set_rfreg(hw
, (enum radio_path
)index
, RF_SYN_G7
,
2826 /* 4. Set LC calibration begin */
2827 rtl_set_rfreg(hw
, (enum radio_path
)index
, RF_CHNLBW
,
2830 u4tmp
= rtl_get_rfreg(hw
, (enum radio_path
)index
, RF_SYN_G6
,
2832 while ((!(u4tmp
& BIT(11))) && timecount
<= timeout
) {
2835 u4tmp
= rtl_get_rfreg(hw
, (enum radio_path
)index
,
2836 RF_SYN_G6
, BRFREGOFFSETMASK
);
2838 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2839 ("PHY_LCK finish delay for %d ms=2\n", timecount
));
2840 u4tmp
= rtl_get_rfreg(hw
, index
, RF_SYN_G4
, BRFREGOFFSETMASK
);
2841 if (index
== 0 && rtlhal
->interfaceindex
== 0) {
2842 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2843 ("path-A / 5G LCK\n"));
2845 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2846 ("path-B / 2.4G LCK\n"));
2848 memset(&curvecount_val
[0], 0, CV_CURVE_CNT
* 2);
2849 /* Set LC calibration off */
2850 rtl_set_rfreg(hw
, (enum radio_path
)index
, RF_CHNLBW
,
2852 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("set RF 0x18[15] = 0\n"));
2853 /* save Curve-counting number */
2854 for (i
= 0; i
< CV_CURVE_CNT
; i
++) {
2855 u32 readval
= 0, readval2
= 0;
2856 rtl_set_rfreg(hw
, (enum radio_path
)index
, 0x3F,
2859 rtl_set_rfreg(hw
, (enum radio_path
)index
, 0x4D,
2860 BRFREGOFFSETMASK
, 0x0);
2861 readval
= rtl_get_rfreg(hw
, (enum radio_path
)index
,
2862 0x4F, BRFREGOFFSETMASK
);
2863 curvecount_val
[2 * i
+ 1] = (readval
& 0xfffe0) >> 5;
2864 /* reg 0x4f [4:0] */
2865 /* reg 0x50 [19:10] */
2866 readval2
= rtl_get_rfreg(hw
, (enum radio_path
)index
,
2868 curvecount_val
[2 * i
] = (((readval
& 0x1F) << 10) |
2871 if (index
== 0 && rtlhal
->interfaceindex
== 0)
2872 _rtl92d_phy_calc_curvindex(hw
, targetchnl_5g
,
2874 true, curveindex_5g
);
2876 _rtl92d_phy_calc_curvindex(hw
, targetchnl_2g
,
2878 false, curveindex_2g
);
2879 /* switch CV-curve control mode */
2880 rtl_set_rfreg(hw
, (enum radio_path
)index
, RF_SYN_G7
,
2884 /* Restore original situation */
2885 for (index
= 0; index
< path
; index
++) {
2886 offset
= index
== 0 ? ROFDM0_XAAGCCORE1
: ROFDM0_XBAGCCORE1
;
2887 rtl_write_byte(rtlpriv
, offset
, 0x50);
2888 rtl_write_byte(rtlpriv
, offset
, rf_mode
[index
]);
2890 if ((tmpreg
& 0x70) != 0)
2891 rtl_write_byte(rtlpriv
, 0xd03, tmpreg
);
2892 else /*Deal with Packet TX case */
2893 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0x00);
2894 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
, 0xF00000, 0x00);
2895 _rtl92d_phy_reload_lck_setting(hw
, rtlpriv
->phy
.current_channel
);
2898 static void _rtl92d_phy_lc_calibrate(struct ieee80211_hw
*hw
, bool is2t
)
2900 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2902 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("cosa PHY_LCK ver=2\n"));
2903 _rtl92d_phy_lc_calibrate_sw(hw
, is2t
);
2906 void rtl92d_phy_lc_calibrate(struct ieee80211_hw
*hw
)
2908 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2909 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2910 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
2911 u32 timeout
= 2000, timecount
= 0;
2913 while (rtlpriv
->mac80211
.act_scanning
&& timecount
< timeout
) {
2918 rtlphy
->lck_inprogress
= true;
2919 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2920 ("LCK:Start!!! currentband %x delay %d ms\n",
2921 rtlhal
->current_bandtype
, timecount
));
2922 if (IS_92D_SINGLEPHY(rtlhal
->version
)) {
2923 _rtl92d_phy_lc_calibrate(hw
, true);
2926 _rtl92d_phy_lc_calibrate(hw
, false);
2928 rtlphy
->lck_inprogress
= false;
2929 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, ("LCK:Finish!!!\n"));
2932 void rtl92d_phy_ap_calibrate(struct ieee80211_hw
*hw
, char delta
)
2937 static bool _rtl92d_phy_set_sw_chnl_cmdarray(struct swchnlcmd
*cmdtable
,
2938 u32 cmdtableidx
, u32 cmdtablesz
, enum swchnlcmd_id cmdid
,
2939 u32 para1
, u32 para2
, u32 msdelay
)
2941 struct swchnlcmd
*pcmd
;
2943 if (cmdtable
== NULL
) {
2944 RT_ASSERT(false, ("cmdtable cannot be NULL.\n"));
2947 if (cmdtableidx
>= cmdtablesz
)
2950 pcmd
= cmdtable
+ cmdtableidx
;
2951 pcmd
->cmdid
= cmdid
;
2952 pcmd
->para1
= para1
;
2953 pcmd
->para2
= para2
;
2954 pcmd
->msdelay
= msdelay
;
2958 void rtl92d_phy_reset_iqk_result(struct ieee80211_hw
*hw
)
2960 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2961 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2964 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2965 ("settings regs %d default regs %d\n",
2966 (int)(sizeof(rtlphy
->iqk_matrix_regsetting
) /
2967 sizeof(struct iqk_matrix_regs
)),
2968 IQK_MATRIX_REG_NUM
));
2969 /* 0xe94, 0xe9c, 0xea4, 0xeac, 0xeb4, 0xebc, 0xec4, 0xecc */
2970 for (i
= 0; i
< IQK_MATRIX_SETTINGS_NUM
; i
++) {
2971 rtlphy
->iqk_matrix_regsetting
[i
].value
[0][0] = 0x100;
2972 rtlphy
->iqk_matrix_regsetting
[i
].value
[0][2] = 0x100;
2973 rtlphy
->iqk_matrix_regsetting
[i
].value
[0][4] = 0x100;
2974 rtlphy
->iqk_matrix_regsetting
[i
].value
[0][6] = 0x100;
2975 rtlphy
->iqk_matrix_regsetting
[i
].value
[0][1] = 0x0;
2976 rtlphy
->iqk_matrix_regsetting
[i
].value
[0][3] = 0x0;
2977 rtlphy
->iqk_matrix_regsetting
[i
].value
[0][5] = 0x0;
2978 rtlphy
->iqk_matrix_regsetting
[i
].value
[0][7] = 0x0;
2979 rtlphy
->iqk_matrix_regsetting
[i
].iqk_done
= false;
2983 static bool _rtl92d_phy_sw_chnl_step_by_step(struct ieee80211_hw
*hw
,
2984 u8 channel
, u8
*stage
, u8
*step
,
2987 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2988 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2989 struct swchnlcmd precommoncmd
[MAX_PRECMD_CNT
];
2990 u32 precommoncmdcnt
;
2991 struct swchnlcmd postcommoncmd
[MAX_POSTCMD_CNT
];
2992 u32 postcommoncmdcnt
;
2993 struct swchnlcmd rfdependcmd
[MAX_RFDEPENDCMD_CNT
];
2995 struct swchnlcmd
*currentcmd
= NULL
;
2997 u8 num_total_rfpath
= rtlphy
->num_total_rfpath
;
2999 precommoncmdcnt
= 0;
3000 _rtl92d_phy_set_sw_chnl_cmdarray(precommoncmd
, precommoncmdcnt
++,
3002 CMDID_SET_TXPOWEROWER_LEVEL
, 0, 0, 0);
3003 _rtl92d_phy_set_sw_chnl_cmdarray(precommoncmd
, precommoncmdcnt
++,
3004 MAX_PRECMD_CNT
, CMDID_END
, 0, 0, 0);
3005 postcommoncmdcnt
= 0;
3006 _rtl92d_phy_set_sw_chnl_cmdarray(postcommoncmd
, postcommoncmdcnt
++,
3007 MAX_POSTCMD_CNT
, CMDID_END
, 0, 0, 0);
3009 _rtl92d_phy_set_sw_chnl_cmdarray(rfdependcmd
, rfdependcmdcnt
++,
3010 MAX_RFDEPENDCMD_CNT
, CMDID_RF_WRITEREG
,
3011 RF_CHNLBW
, channel
, 0);
3012 _rtl92d_phy_set_sw_chnl_cmdarray(rfdependcmd
, rfdependcmdcnt
++,
3013 MAX_RFDEPENDCMD_CNT
, CMDID_END
,
3019 currentcmd
= &precommoncmd
[*step
];
3022 currentcmd
= &rfdependcmd
[*step
];
3025 currentcmd
= &postcommoncmd
[*step
];
3028 if (currentcmd
->cmdid
== CMDID_END
) {
3029 if ((*stage
) == 2) {
3037 switch (currentcmd
->cmdid
) {
3038 case CMDID_SET_TXPOWEROWER_LEVEL
:
3039 rtl92d_phy_set_txpower_level(hw
, channel
);
3041 case CMDID_WRITEPORT_ULONG
:
3042 rtl_write_dword(rtlpriv
, currentcmd
->para1
,
3045 case CMDID_WRITEPORT_USHORT
:
3046 rtl_write_word(rtlpriv
, currentcmd
->para1
,
3047 (u16
)currentcmd
->para2
);
3049 case CMDID_WRITEPORT_UCHAR
:
3050 rtl_write_byte(rtlpriv
, currentcmd
->para1
,
3051 (u8
)currentcmd
->para2
);
3053 case CMDID_RF_WRITEREG
:
3054 for (rfpath
= 0; rfpath
< num_total_rfpath
; rfpath
++) {
3055 rtlphy
->rfreg_chnlval
[rfpath
] =
3056 ((rtlphy
->rfreg_chnlval
[rfpath
] &
3057 0xffffff00) | currentcmd
->para2
);
3058 if (rtlpriv
->rtlhal
.current_bandtype
==
3060 if (currentcmd
->para2
> 99)
3061 rtlphy
->rfreg_chnlval
[rfpath
] =
3062 rtlphy
->rfreg_chnlval
3063 [rfpath
] | (BIT(18));
3065 rtlphy
->rfreg_chnlval
[rfpath
] =
3066 rtlphy
->rfreg_chnlval
3067 [rfpath
] & (~BIT(18));
3068 rtlphy
->rfreg_chnlval
[rfpath
] |=
3071 rtlphy
->rfreg_chnlval
[rfpath
] &=
3072 ~(BIT(8) | BIT(16) | BIT(18));
3074 rtl_set_rfreg(hw
, (enum radio_path
)rfpath
,
3077 rtlphy
->rfreg_chnlval
[rfpath
]);
3078 _rtl92d_phy_reload_imr_setting(hw
, channel
,
3081 _rtl92d_phy_switch_rf_setting(hw
, channel
);
3082 /* do IQK when all parameters are ready */
3083 rtl92d_phy_reload_iqk_setting(hw
, channel
);
3086 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
3087 ("switch case not process\n"));
3092 (*delay
) = currentcmd
->msdelay
;
3097 u8
rtl92d_phy_sw_chnl(struct ieee80211_hw
*hw
)
3099 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3100 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
3101 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3103 u32 timeout
= 1000, timecount
= 0;
3104 u8 channel
= rtlphy
->current_channel
;
3107 if (rtlphy
->sw_chnl_inprogress
)
3109 if (rtlphy
->set_bwmode_inprogress
)
3112 if ((is_hal_stop(rtlhal
)) || (RT_CANNOT_IO(hw
))) {
3113 RT_TRACE(rtlpriv
, COMP_CHAN
, DBG_LOUD
,
3114 ("sw_chnl_inprogress false driver sleep or unload\n"));
3117 while (rtlphy
->lck_inprogress
&& timecount
< timeout
) {
3121 if (rtlhal
->macphymode
== SINGLEMAC_SINGLEPHY
&&
3122 rtlhal
->bandset
== BAND_ON_BOTH
) {
3123 ret_value
= rtl_get_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
,
3125 if (rtlphy
->current_channel
> 14 && !(ret_value
& BIT(0)))
3126 rtl92d_phy_switch_wirelessband(hw
, BAND_ON_5G
);
3127 else if (rtlphy
->current_channel
<= 14 && (ret_value
& BIT(0)))
3128 rtl92d_phy_switch_wirelessband(hw
, BAND_ON_2_4G
);
3130 switch (rtlhal
->current_bandtype
) {
3132 /* Get first channel error when change between
3133 * 5G and 2.4G band. */
3136 RT_ASSERT((channel
> 14), ("5G but channel<=14"));
3139 /* Get first channel error when change between
3140 * 5G and 2.4G band. */
3143 RT_ASSERT((channel
<= 14), ("2G but channel>14"));
3147 ("Invalid WirelessMode(%#x)!!\n",
3148 rtlpriv
->mac80211
.mode
));
3151 rtlphy
->sw_chnl_inprogress
= true;
3154 rtlphy
->sw_chnl_stage
= 0;
3155 rtlphy
->sw_chnl_step
= 0;
3156 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_TRACE
,
3157 ("switch to channel%d\n", rtlphy
->current_channel
));
3160 if (!rtlphy
->sw_chnl_inprogress
)
3162 if (!_rtl92d_phy_sw_chnl_step_by_step(hw
,
3163 rtlphy
->current_channel
,
3164 &rtlphy
->sw_chnl_stage
, &rtlphy
->sw_chnl_step
, &delay
)) {
3170 rtlphy
->sw_chnl_inprogress
= false;
3174 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_TRACE
, ("<==\n"));
3175 rtlphy
->sw_chnl_inprogress
= false;
3179 static void rtl92d_phy_set_io(struct ieee80211_hw
*hw
)
3181 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3182 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
3184 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
,
3185 ("--->Cmd(%#x), set_io_inprogress(%d)\n",
3186 rtlphy
->current_io_type
, rtlphy
->set_io_inprogress
));
3187 switch (rtlphy
->current_io_type
) {
3188 case IO_CMD_RESUME_DM_BY_SCAN
:
3189 de_digtable
.cur_igvalue
= rtlphy
->initgain_backup
.xaagccore1
;
3190 rtl92d_dm_write_dig(hw
);
3191 rtl92d_phy_set_txpower_level(hw
, rtlphy
->current_channel
);
3193 case IO_CMD_PAUSE_DM_BY_SCAN
:
3194 rtlphy
->initgain_backup
.xaagccore1
= de_digtable
.cur_igvalue
;
3195 de_digtable
.cur_igvalue
= 0x17;
3196 rtl92d_dm_write_dig(hw
);
3199 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
3200 ("switch case not process\n"));
3203 rtlphy
->set_io_inprogress
= false;
3204 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
,
3205 ("<---(%#x)\n", rtlphy
->current_io_type
));
3208 bool rtl92d_phy_set_io_cmd(struct ieee80211_hw
*hw
, enum io_type iotype
)
3210 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3211 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
3212 bool postprocessing
= false;
3214 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
,
3215 ("-->IO Cmd(%#x), set_io_inprogress(%d)\n",
3216 iotype
, rtlphy
->set_io_inprogress
));
3219 case IO_CMD_RESUME_DM_BY_SCAN
:
3220 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
,
3221 ("[IO CMD] Resume DM after scan.\n"));
3222 postprocessing
= true;
3224 case IO_CMD_PAUSE_DM_BY_SCAN
:
3225 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
,
3226 ("[IO CMD] Pause DM before scan.\n"));
3227 postprocessing
= true;
3230 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
3231 ("switch case not process\n"));
3235 if (postprocessing
&& !rtlphy
->set_io_inprogress
) {
3236 rtlphy
->set_io_inprogress
= true;
3237 rtlphy
->current_io_type
= iotype
;
3241 rtl92d_phy_set_io(hw
);
3242 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
, ("<--IO Type(%#x)\n", iotype
));
3246 static void _rtl92d_phy_set_rfon(struct ieee80211_hw
*hw
)
3248 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3250 /* a. SYS_CLKR 0x08[11] = 1 restore MAC clock */
3251 /* b. SPS_CTRL 0x11[7:0] = 0x2b */
3252 if (rtlpriv
->rtlhal
.macphymode
== SINGLEMAC_SINGLEPHY
)
3253 rtl_write_byte(rtlpriv
, REG_SPS0_CTRL
, 0x2b);
3254 /* c. For PCIE: SYS_FUNC_EN 0x02[7:0] = 0xE3 enable BB TRX function */
3255 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE3);
3256 /* RF_ON_EXCEP(d~g): */
3257 /* d. APSD_CTRL 0x600[7:0] = 0x00 */
3258 rtl_write_byte(rtlpriv
, REG_APSD_CTRL
, 0x00);
3259 /* e. SYS_FUNC_EN 0x02[7:0] = 0xE2 reset BB TRX function again */
3260 /* f. SYS_FUNC_EN 0x02[7:0] = 0xE3 enable BB TRX function*/
3261 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE2);
3262 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE3);
3263 /* g. txpause 0x522[7:0] = 0x00 enable mac tx queue */
3264 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0x00);
3267 static void _rtl92d_phy_set_rfsleep(struct ieee80211_hw
*hw
)
3269 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3273 /* a. TXPAUSE 0x522[7:0] = 0xFF Pause MAC TX queue */
3274 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0xFF);
3275 /* b. RF path 0 offset 0x00 = 0x00 disable RF */
3276 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x00, BRFREGOFFSETMASK
, 0x00);
3277 /* c. APSD_CTRL 0x600[7:0] = 0x40 */
3278 rtl_write_byte(rtlpriv
, REG_APSD_CTRL
, 0x40);
3279 /* d. APSD_CTRL 0x600[7:0] = 0x00
3280 * APSD_CTRL 0x600[7:0] = 0x00
3281 * RF path 0 offset 0x00 = 0x00
3282 * APSD_CTRL 0x600[7:0] = 0x40
3284 u4btmp
= rtl_get_rfreg(hw
, RF90_PATH_A
, 0, BRFREGOFFSETMASK
);
3285 while (u4btmp
!= 0 && delay
> 0) {
3286 rtl_write_byte(rtlpriv
, REG_APSD_CTRL
, 0x0);
3287 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x00, BRFREGOFFSETMASK
, 0x00);
3288 rtl_write_byte(rtlpriv
, REG_APSD_CTRL
, 0x40);
3289 u4btmp
= rtl_get_rfreg(hw
, RF90_PATH_A
, 0, BRFREGOFFSETMASK
);
3293 /* Jump out the LPS turn off sequence to RF_ON_EXCEP */
3294 rtl_write_byte(rtlpriv
, REG_APSD_CTRL
, 0x00);
3296 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE2);
3297 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE3);
3298 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0x00);
3299 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
3300 ("Fail !!! Switch RF timeout.\n"));
3303 /* e. For PCIE: SYS_FUNC_EN 0x02[7:0] = 0xE2 reset BB TRX function */
3304 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE2);
3305 /* f. SPS_CTRL 0x11[7:0] = 0x22 */
3306 if (rtlpriv
->rtlhal
.macphymode
== SINGLEMAC_SINGLEPHY
)
3307 rtl_write_byte(rtlpriv
, REG_SPS0_CTRL
, 0x22);
3308 /* g. SYS_CLKR 0x08[11] = 0 gated MAC clock */
3311 bool rtl92d_phy_set_rf_power_state(struct ieee80211_hw
*hw
,
3312 enum rf_pwrstate rfpwr_state
)
3315 bool bresult
= true;
3316 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3317 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
3318 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
3319 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
3320 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
3322 struct rtl8192_tx_ring
*ring
= NULL
;
3324 if (rfpwr_state
== ppsc
->rfpwr_state
)
3326 switch (rfpwr_state
) {
3328 if ((ppsc
->rfpwr_state
== ERFOFF
) &&
3329 RT_IN_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
)) {
3331 u32 InitializeCount
= 0;
3334 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
3335 ("IPS Set eRf nic enable\n"));
3336 rtstatus
= rtl_ps_enable_nic(hw
);
3337 } while ((rtstatus
!= true) &&
3338 (InitializeCount
< 10));
3340 RT_CLEAR_PS_LEVEL(ppsc
,
3341 RT_RF_OFF_LEVL_HALT_NIC
);
3343 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
3344 ("awake, sleeped:%d ms state_"
3346 jiffies_to_msecs(jiffies
-
3347 ppsc
->last_sleep_jiffies
),
3348 rtlpriv
->psc
.state_inap
));
3349 ppsc
->last_awake_jiffies
= jiffies
;
3350 _rtl92d_phy_set_rfon(hw
);
3353 if (mac
->link_state
== MAC80211_LINKED
)
3354 rtlpriv
->cfg
->ops
->led_control(hw
,
3357 rtlpriv
->cfg
->ops
->led_control(hw
,
3361 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_HALT_NIC
) {
3362 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
3363 ("IPS Set eRf nic disable\n"));
3364 rtl_ps_disable_nic(hw
);
3365 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
3367 if (ppsc
->rfoff_reason
== RF_CHANGE_BY_IPS
)
3368 rtlpriv
->cfg
->ops
->led_control(hw
,
3371 rtlpriv
->cfg
->ops
->led_control(hw
,
3376 if (ppsc
->rfpwr_state
== ERFOFF
)
3379 for (queue_id
= 0, i
= 0;
3380 queue_id
< RTL_PCI_MAX_TX_QUEUE_COUNT
;) {
3381 ring
= &pcipriv
->dev
.tx_ring
[queue_id
];
3382 if (skb_queue_len(&ring
->queue
) == 0 ||
3383 queue_id
== BEACON_QUEUE
) {
3386 } else if (rtlpci
->pdev
->current_state
!= PCI_D0
) {
3387 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
3388 ("eRf Off/Sleep: %d times TcbBusyQueu"
3389 "e[%d] !=0 but lower power state!\n",
3390 (i
+ 1), queue_id
));
3393 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
3394 ("eRf Off/Sleep: %d times TcbBusyQueu"
3396 "before doze!\n", (i
+ 1), queue_id
,
3397 skb_queue_len(&ring
->queue
)));
3402 if (i
>= MAX_DOZE_WAITING_TIMES_9x
) {
3403 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
3404 ("\nERFOFF: %d times TcbBusyQueue[%d] "
3406 MAX_DOZE_WAITING_TIMES_9x
, queue_id
,
3407 skb_queue_len(&ring
->queue
)));
3411 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
3412 ("Set rfsleep awaked:%d ms\n",
3413 jiffies_to_msecs(jiffies
- ppsc
->last_awake_jiffies
)));
3414 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
, ("sleep awaked:%d ms "
3415 "state_inap:%x\n", jiffies_to_msecs(jiffies
-
3416 ppsc
->last_awake_jiffies
), rtlpriv
->psc
.state_inap
));
3417 ppsc
->last_sleep_jiffies
= jiffies
;
3418 _rtl92d_phy_set_rfsleep(hw
);
3421 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
3422 ("switch case not process\n"));
3427 ppsc
->rfpwr_state
= rfpwr_state
;
3431 void rtl92d_phy_config_macphymode(struct ieee80211_hw
*hw
)
3433 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3434 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3435 u8 offset
= REG_MAC_PHY_CTRL_NORMAL
;
3437 switch (rtlhal
->macphymode
) {
3438 case DUALMAC_DUALPHY
:
3439 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3440 ("MacPhyMode: DUALMAC_DUALPHY\n"));
3441 rtl_write_byte(rtlpriv
, offset
, 0xF3);
3443 case SINGLEMAC_SINGLEPHY
:
3444 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3445 ("MacPhyMode: SINGLEMAC_SINGLEPHY\n"));
3446 rtl_write_byte(rtlpriv
, offset
, 0xF4);
3448 case DUALMAC_SINGLEPHY
:
3449 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3450 ("MacPhyMode: DUALMAC_SINGLEPHY\n"));
3451 rtl_write_byte(rtlpriv
, offset
, 0xF1);
3456 void rtl92d_phy_config_macphymode_info(struct ieee80211_hw
*hw
)
3458 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3459 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3460 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
3462 switch (rtlhal
->macphymode
) {
3463 case DUALMAC_SINGLEPHY
:
3464 rtlphy
->rf_type
= RF_2T2R
;
3465 rtlhal
->version
|= CHIP_92D_SINGLEPHY
;
3466 rtlhal
->bandset
= BAND_ON_BOTH
;
3467 rtlhal
->current_bandtype
= BAND_ON_2_4G
;
3470 case SINGLEMAC_SINGLEPHY
:
3471 rtlphy
->rf_type
= RF_2T2R
;
3472 rtlhal
->version
|= CHIP_92D_SINGLEPHY
;
3473 rtlhal
->bandset
= BAND_ON_BOTH
;
3474 rtlhal
->current_bandtype
= BAND_ON_2_4G
;
3477 case DUALMAC_DUALPHY
:
3478 rtlphy
->rf_type
= RF_1T1R
;
3479 rtlhal
->version
&= (~CHIP_92D_SINGLEPHY
);
3480 /* Now we let MAC0 run on 5G band. */
3481 if (rtlhal
->interfaceindex
== 0) {
3482 rtlhal
->bandset
= BAND_ON_5G
;
3483 rtlhal
->current_bandtype
= BAND_ON_5G
;
3485 rtlhal
->bandset
= BAND_ON_2_4G
;
3486 rtlhal
->current_bandtype
= BAND_ON_2_4G
;
3494 u8
rtl92d_get_chnlgroup_fromarray(u8 chnl
)
3497 u8 channel_info
[59] = {
3498 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
3499 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56,
3500 58, 60, 62, 64, 100, 102, 104, 106, 108,
3501 110, 112, 114, 116, 118, 120, 122, 124,
3502 126, 128, 130, 132, 134, 136, 138, 140,
3503 149, 151, 153, 155, 157, 159, 161, 163,
3507 if (channel_info
[chnl
] <= 3)
3509 else if (channel_info
[chnl
] <= 9)
3511 else if (channel_info
[chnl
] <= 14)
3513 else if (channel_info
[chnl
] <= 44)
3515 else if (channel_info
[chnl
] <= 54)
3517 else if (channel_info
[chnl
] <= 64)
3519 else if (channel_info
[chnl
] <= 112)
3521 else if (channel_info
[chnl
] <= 126)
3523 else if (channel_info
[chnl
] <= 140)
3525 else if (channel_info
[chnl
] <= 153)
3527 else if (channel_info
[chnl
] <= 159)
3534 void rtl92d_phy_set_poweron(struct ieee80211_hw
*hw
)
3536 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3537 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3538 unsigned long flags
;
3541 u32 mac_reg
= (rtlhal
->interfaceindex
== 0 ? REG_MAC0
: REG_MAC1
);
3543 /* notice fw know band status 0x81[1]/0x53[1] = 0: 5G, 1: 2G */
3544 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
3545 value8
= rtl_read_byte(rtlpriv
, mac_reg
);
3547 rtl_write_byte(rtlpriv
, mac_reg
, value8
);
3549 value8
= rtl_read_byte(rtlpriv
, mac_reg
);
3550 value8
&= (~BIT(1));
3551 rtl_write_byte(rtlpriv
, mac_reg
, value8
);
3554 if (rtlhal
->macphymode
== SINGLEMAC_SINGLEPHY
) {
3555 value8
= rtl_read_byte(rtlpriv
, REG_MAC0
);
3556 rtl_write_byte(rtlpriv
, REG_MAC0
, value8
| MAC0_ON
);
3558 spin_lock_irqsave(&globalmutex_power
, flags
);
3559 if (rtlhal
->interfaceindex
== 0) {
3560 value8
= rtl_read_byte(rtlpriv
, REG_MAC0
);
3561 rtl_write_byte(rtlpriv
, REG_MAC0
, value8
| MAC0_ON
);
3563 value8
= rtl_read_byte(rtlpriv
, REG_MAC1
);
3564 rtl_write_byte(rtlpriv
, REG_MAC1
, value8
| MAC1_ON
);
3566 value8
= rtl_read_byte(rtlpriv
, REG_POWER_OFF_IN_PROCESS
);
3567 spin_unlock_irqrestore(&globalmutex_power
, flags
);
3568 for (i
= 0; i
< 200; i
++) {
3569 if ((value8
& BIT(7)) == 0) {
3573 spin_lock_irqsave(&globalmutex_power
, flags
);
3574 value8
= rtl_read_byte(rtlpriv
,
3575 REG_POWER_OFF_IN_PROCESS
);
3576 spin_unlock_irqrestore(&globalmutex_power
,
3581 RT_ASSERT(false, ("Another mac power off over time\n"));
3585 void rtl92d_phy_config_maccoexist_rfpage(struct ieee80211_hw
*hw
)
3587 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3589 switch (rtlpriv
->rtlhal
.macphymode
) {
3590 case DUALMAC_DUALPHY
:
3591 rtl_write_byte(rtlpriv
, REG_DMC
, 0x0);
3592 rtl_write_byte(rtlpriv
, REG_RX_PKT_LIMIT
, 0x08);
3593 rtl_write_word(rtlpriv
, REG_TRXFF_BNDY
+ 2, 0x13ff);
3595 case DUALMAC_SINGLEPHY
:
3596 rtl_write_byte(rtlpriv
, REG_DMC
, 0xf8);
3597 rtl_write_byte(rtlpriv
, REG_RX_PKT_LIMIT
, 0x08);
3598 rtl_write_word(rtlpriv
, REG_TRXFF_BNDY
+ 2, 0x13ff);
3600 case SINGLEMAC_SINGLEPHY
:
3601 rtl_write_byte(rtlpriv
, REG_DMC
, 0x0);
3602 rtl_write_byte(rtlpriv
, REG_RX_PKT_LIMIT
, 0x10);
3603 rtl_write_word(rtlpriv
, (REG_TRXFF_BNDY
+ 2), 0x27FF);
3610 void rtl92d_update_bbrf_configuration(struct ieee80211_hw
*hw
)
3612 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3613 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3614 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
3615 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
3618 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, ("==>\n"));
3619 /* r_select_5G for path_A/B 0 for 2.4G, 1 for 5G */
3620 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
3621 /* r_select_5G for path_A/B,0x878 */
3622 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(0), 0x0);
3623 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(15), 0x0);
3624 if (rtlhal
->macphymode
!= DUALMAC_DUALPHY
) {
3625 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(16), 0x0);
3626 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(31), 0x0);
3628 /* rssi_table_select:index 0 for 2.4G.1~3 for 5G,0xc78 */
3629 rtl_set_bbreg(hw
, ROFDM0_AGCRSSITABLE
, BIT(6) | BIT(7), 0x0);
3631 rtl_set_bbreg(hw
, ROFDM1_CFOTRACKING
, BIT(14) | BIT(13), 0x0);
3633 rtl_set_bbreg(hw
, 0xB30, 0x00F00000, 0xa);
3634 /* TX BB gain shift*1,Just for testchip,0xc80,0xc88 */
3635 rtl_set_bbreg(hw
, ROFDM0_XATxIQIMBALANCE
, BMASKDWORD
,
3637 rtl_set_bbreg(hw
, ROFDM0_XBTxIQIMBALANCE
, BMASKDWORD
,
3639 if (rtlhal
->macphymode
== DUALMAC_DUALPHY
) {
3640 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
,
3641 BIT(10) | BIT(6) | BIT(5),
3642 ((rtlefuse
->eeprom_c9
& BIT(3)) >> 3) |
3643 (rtlefuse
->eeprom_c9
& BIT(1)) |
3644 ((rtlefuse
->eeprom_cc
& BIT(1)) << 4));
3645 rtl_set_bbreg(hw
, RFPGA0_XA_RFINTERFACEOE
,
3646 BIT(10) | BIT(6) | BIT(5),
3647 ((rtlefuse
->eeprom_c9
& BIT(2)) >> 2) |
3648 ((rtlefuse
->eeprom_c9
& BIT(0)) << 1) |
3649 ((rtlefuse
->eeprom_cc
& BIT(0)) << 5));
3650 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(15), 0);
3652 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
,
3653 BIT(26) | BIT(22) | BIT(21) | BIT(10) |
3655 ((rtlefuse
->eeprom_c9
& BIT(3)) >> 3) |
3656 (rtlefuse
->eeprom_c9
& BIT(1)) |
3657 ((rtlefuse
->eeprom_cc
& BIT(1)) << 4) |
3658 ((rtlefuse
->eeprom_c9
& BIT(7)) << 9) |
3659 ((rtlefuse
->eeprom_c9
& BIT(5)) << 12) |
3660 ((rtlefuse
->eeprom_cc
& BIT(3)) << 18));
3661 rtl_set_bbreg(hw
, RFPGA0_XA_RFINTERFACEOE
,
3662 BIT(10) | BIT(6) | BIT(5),
3663 ((rtlefuse
->eeprom_c9
& BIT(2)) >> 2) |
3664 ((rtlefuse
->eeprom_c9
& BIT(0)) << 1) |
3665 ((rtlefuse
->eeprom_cc
& BIT(0)) << 5));
3666 rtl_set_bbreg(hw
, RFPGA0_XB_RFINTERFACEOE
,
3667 BIT(10) | BIT(6) | BIT(5),
3668 ((rtlefuse
->eeprom_c9
& BIT(6)) >> 6) |
3669 ((rtlefuse
->eeprom_c9
& BIT(4)) >> 3) |
3670 ((rtlefuse
->eeprom_cc
& BIT(2)) << 3));
3671 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
,
3672 BIT(31) | BIT(15), 0);
3676 /* r_select_5G for path_A/B */
3677 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(0), 0x1);
3678 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(15), 0x1);
3679 if (rtlhal
->macphymode
!= DUALMAC_DUALPHY
) {
3680 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(16), 0x1);
3681 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(31), 0x1);
3683 /* rssi_table_select:index 0 for 2.4G.1~3 for 5G */
3684 rtl_set_bbreg(hw
, ROFDM0_AGCRSSITABLE
, BIT(6) | BIT(7), 0x1);
3686 rtl_set_bbreg(hw
, ROFDM1_CFOTRACKING
, BIT(14) | BIT(13), 0x1);
3688 rtl_set_bbreg(hw
, 0xB30, 0x00F00000, 0x0);
3689 /* TX BB gain shift,Just for testchip,0xc80,0xc88 */
3690 if (rtlefuse
->internal_pa_5g
[0])
3691 rtl_set_bbreg(hw
, ROFDM0_XATxIQIMBALANCE
, BMASKDWORD
,
3694 rtl_set_bbreg(hw
, ROFDM0_XATxIQIMBALANCE
, BMASKDWORD
,
3696 if (rtlefuse
->internal_pa_5g
[1])
3697 rtl_set_bbreg(hw
, ROFDM0_XBTxIQIMBALANCE
, BMASKDWORD
,
3700 rtl_set_bbreg(hw
, ROFDM0_XBTxIQIMBALANCE
, BMASKDWORD
,
3702 if (rtlhal
->macphymode
== DUALMAC_DUALPHY
) {
3703 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
,
3704 BIT(10) | BIT(6) | BIT(5),
3705 (rtlefuse
->eeprom_cc
& BIT(5)));
3706 rtl_set_bbreg(hw
, RFPGA0_XA_RFINTERFACEOE
, BIT(10),
3707 ((rtlefuse
->eeprom_cc
& BIT(4)) >> 4));
3708 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(15),
3709 (rtlefuse
->eeprom_cc
& BIT(4)) >> 4);
3711 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
,
3712 BIT(26) | BIT(22) | BIT(21) | BIT(10) |
3714 (rtlefuse
->eeprom_cc
& BIT(5)) |
3715 ((rtlefuse
->eeprom_cc
& BIT(7)) << 14));
3716 rtl_set_bbreg(hw
, RFPGA0_XA_RFINTERFACEOE
, BIT(10),
3717 ((rtlefuse
->eeprom_cc
& BIT(4)) >> 4));
3718 rtl_set_bbreg(hw
, RFPGA0_XB_RFINTERFACEOE
, BIT(10),
3719 ((rtlefuse
->eeprom_cc
& BIT(6)) >> 6));
3720 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
,
3722 ((rtlefuse
->eeprom_cc
& BIT(4)) >> 4) |
3723 ((rtlefuse
->eeprom_cc
& BIT(6)) << 10));
3726 /* update IQK related settings */
3727 rtl_set_bbreg(hw
, ROFDM0_XARXIQIMBALANCE
, BMASKDWORD
, 0x40000100);
3728 rtl_set_bbreg(hw
, ROFDM0_XBRXIQIMBALANCE
, BMASKDWORD
, 0x40000100);
3729 rtl_set_bbreg(hw
, ROFDM0_XCTxAFE
, 0xF0000000, 0x00);
3730 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
, BIT(30) | BIT(28) |
3731 BIT(26) | BIT(24), 0x00);
3732 rtl_set_bbreg(hw
, ROFDM0_XDTxAFE
, 0xF0000000, 0x00);
3733 rtl_set_bbreg(hw
, 0xca0, 0xF0000000, 0x00);
3734 rtl_set_bbreg(hw
, ROFDM0_AGCRSSITABLE
, 0x0000F000, 0x00);
3737 for (rfpath
= RF90_PATH_A
; rfpath
< rtlphy
->num_total_rfpath
;
3739 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
3740 /* MOD_AG for RF paht_A 0x18 BIT8,BIT16 */
3741 rtl_set_rfreg(hw
, rfpath
, RF_CHNLBW
, BIT(8) | BIT(16) |
3743 /* RF0x0b[16:14] =3b'111 */
3744 rtl_set_rfreg(hw
, (enum radio_path
)rfpath
, 0x0B,
3747 /* MOD_AG for RF paht_A 0x18 BIT8,BIT16 */
3748 rtl_set_rfreg(hw
, rfpath
, RF_CHNLBW
, BIT(8) |
3750 (BIT(16) | BIT(8)) >> 8);
3753 /* Update for all band. */
3755 if (rtlphy
->rf_type
== RF_1T1R
) {
3756 /* Use antenna 0,0xc04,0xd04 */
3757 rtl_set_bbreg(hw
, ROFDM0_TRXPATHENABLE
, BMASKBYTE0
, 0x11);
3758 rtl_set_bbreg(hw
, ROFDM1_TRXPATHENABLE
, BDWORD
, 0x1);
3760 /* enable ad/da clock1 for dual-phy reg0x888 */
3761 if (rtlhal
->interfaceindex
== 0) {
3762 rtl_set_bbreg(hw
, RFPGA0_ADDALLOCKEN
, BIT(12) |
3765 rtl92d_phy_enable_anotherphy(hw
, false);
3766 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3767 ("MAC1 use DBI to update 0x888"));
3769 rtl92de_write_dword_dbi(hw
, RFPGA0_ADDALLOCKEN
,
3770 rtl92de_read_dword_dbi(hw
,
3772 BIT(3)) | BIT(12) | BIT(13),
3774 rtl92d_phy_powerdown_anotherphy(hw
, false);
3778 /* Use antenna 0 & 1,0xc04,0xd04 */
3779 rtl_set_bbreg(hw
, ROFDM0_TRXPATHENABLE
, BMASKBYTE0
, 0x33);
3780 rtl_set_bbreg(hw
, ROFDM1_TRXPATHENABLE
, BDWORD
, 0x3);
3781 /* disable ad/da clock1,0x888 */
3782 rtl_set_bbreg(hw
, RFPGA0_ADDALLOCKEN
, BIT(12) | BIT(13), 0);
3784 for (rfpath
= RF90_PATH_A
; rfpath
< rtlphy
->num_total_rfpath
;
3786 rtlphy
->rfreg_chnlval
[rfpath
] = rtl_get_rfreg(hw
, rfpath
,
3787 RF_CHNLBW
, BRFREGOFFSETMASK
);
3788 rtlphy
->reg_rf3c
[rfpath
] = rtl_get_rfreg(hw
, rfpath
, 0x3C,
3791 for (i
= 0; i
< 2; i
++)
3792 RT_TRACE(rtlpriv
, COMP_RF
, DBG_LOUD
, ("RF 0x18 = 0x%x\n",
3793 rtlphy
->rfreg_chnlval
[i
]));
3794 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, ("<==\n"));
3798 bool rtl92d_phy_check_poweroff(struct ieee80211_hw
*hw
)
3800 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3801 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3803 unsigned long flags
;
3805 if (rtlhal
->macphymode
== SINGLEMAC_SINGLEPHY
) {
3806 u1btmp
= rtl_read_byte(rtlpriv
, REG_MAC0
);
3807 rtl_write_byte(rtlpriv
, REG_MAC0
, u1btmp
& (~MAC0_ON
));
3810 spin_lock_irqsave(&globalmutex_power
, flags
);
3811 if (rtlhal
->interfaceindex
== 0) {
3812 u1btmp
= rtl_read_byte(rtlpriv
, REG_MAC0
);
3813 rtl_write_byte(rtlpriv
, REG_MAC0
, u1btmp
& (~MAC0_ON
));
3814 u1btmp
= rtl_read_byte(rtlpriv
, REG_MAC1
);
3817 u1btmp
= rtl_read_byte(rtlpriv
, REG_MAC1
);
3818 rtl_write_byte(rtlpriv
, REG_MAC1
, u1btmp
& (~MAC1_ON
));
3819 u1btmp
= rtl_read_byte(rtlpriv
, REG_MAC0
);
3823 spin_unlock_irqrestore(&globalmutex_power
, flags
);
3826 u1btmp
= rtl_read_byte(rtlpriv
, REG_POWER_OFF_IN_PROCESS
);
3828 rtl_write_byte(rtlpriv
, REG_POWER_OFF_IN_PROCESS
, u1btmp
);
3829 spin_unlock_irqrestore(&globalmutex_power
, flags
);