1 /******************************************************************************
3 * Copyright(c) 2009-2012 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 *****************************************************************************/
43 #define MAX_RF_IMR_INDEX 12
44 #define MAX_RF_IMR_INDEX_NORMAL 13
45 #define RF_REG_NUM_FOR_C_CUT_5G 6
46 #define RF_REG_NUM_FOR_C_CUT_5G_INTERNALPA 7
47 #define RF_REG_NUM_FOR_C_CUT_2G 5
48 #define RF_CHNL_NUM_5G 19
49 #define RF_CHNL_NUM_5G_40M 17
50 #define TARGET_CHNL_NUM_5G 221
51 #define TARGET_CHNL_NUM_2G 14
52 #define CV_CURVE_CNT 64
54 static u32 rf_reg_for_5g_swchnl_normal
[MAX_RF_IMR_INDEX_NORMAL
] = {
55 0, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x0
58 static u8 rf_reg_for_c_cut_5g
[RF_REG_NUM_FOR_C_CUT_5G
] = {
59 RF_SYN_G1
, RF_SYN_G2
, RF_SYN_G3
, RF_SYN_G4
, RF_SYN_G5
, RF_SYN_G6
62 static u8 rf_reg_for_c_cut_2g
[RF_REG_NUM_FOR_C_CUT_2G
] = {
63 RF_SYN_G1
, RF_SYN_G2
, RF_SYN_G3
, RF_SYN_G7
, RF_SYN_G8
66 static u8 rf_for_c_cut_5g_internal_pa
[RF_REG_NUM_FOR_C_CUT_5G_INTERNALPA
] = {
67 0x0B, 0x48, 0x49, 0x4B, 0x03, 0x04, 0x0E
70 static u32 rf_reg_mask_for_c_cut_2g
[RF_REG_NUM_FOR_C_CUT_2G
] = {
71 BIT(19) | BIT(18) | BIT(17) | BIT(14) | BIT(1),
73 BIT(18) | BIT(17) | BIT(16) | BIT(1),
75 BIT(15) | BIT(14) | BIT(13) | BIT(12) | BIT(11)
78 static u8 rf_chnl_5g
[RF_CHNL_NUM_5G
] = {
79 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108,
80 112, 116, 120, 124, 128, 132, 136, 140
83 static u8 rf_chnl_5g_40m
[RF_CHNL_NUM_5G_40M
] = {
84 38, 42, 46, 50, 54, 58, 62, 102, 106, 110, 114,
85 118, 122, 126, 130, 134, 138
87 static u32 rf_reg_pram_c_5g
[5][RF_REG_NUM_FOR_C_CUT_5G
] = {
88 {0xE43BE, 0xFC638, 0x77C0A, 0xDE471, 0xd7110, 0x8EB04},
89 {0xE43BE, 0xFC078, 0xF7C1A, 0xE0C71, 0xD7550, 0xAEB04},
90 {0xE43BF, 0xFF038, 0xF7C0A, 0xDE471, 0xE5550, 0xAEB04},
91 {0xE43BF, 0xFF079, 0xF7C1A, 0xDE471, 0xE5550, 0xAEB04},
92 {0xE43BF, 0xFF038, 0xF7C1A, 0xDE471, 0xd7550, 0xAEB04}
95 static u32 rf_reg_param_for_c_cut_2g
[3][RF_REG_NUM_FOR_C_CUT_2G
] = {
96 {0x643BC, 0xFC038, 0x77C1A, 0x41289, 0x01840},
97 {0x643BC, 0xFC038, 0x07C1A, 0x41289, 0x01840},
98 {0x243BC, 0xFC438, 0x07C1A, 0x4128B, 0x0FC41}
101 static u32 rf_syn_g4_for_c_cut_2g
= 0xD1C31 & 0x7FF;
103 static u32 rf_pram_c_5g_int_pa
[3][RF_REG_NUM_FOR_C_CUT_5G_INTERNALPA
] = {
104 {0x01a00, 0x40443, 0x00eb5, 0x89bec, 0x94a12, 0x94a12, 0x94a12},
105 {0x01800, 0xc0443, 0x00730, 0x896ee, 0x94a52, 0x94a52, 0x94a52},
106 {0x01800, 0xc0443, 0x00730, 0x896ee, 0x94a12, 0x94a12, 0x94a12}
109 /* [mode][patha+b][reg] */
110 static u32 rf_imr_param_normal
[1][3][MAX_RF_IMR_INDEX_NORMAL
] = {
114 0x70000, 0x00ff0, 0x4400f, 0x00ff0, 0x0, 0x0, 0x0,
115 0x0, 0x0, 0x64888, 0xe266c, 0x00090, 0x22fff
119 0x70000, 0x22880, 0x4470f, 0x55880, 0x00070, 0x88000,
120 0x0, 0x88080, 0x70000, 0x64a82, 0xe466c, 0x00090,
125 0x70000, 0x44880, 0x4477f, 0x77880, 0x00070, 0x88000,
126 0x0, 0x880b0, 0x0, 0x64b82, 0xe466c, 0x00090, 0x32c9a
131 static u32 curveindex_5g
[TARGET_CHNL_NUM_5G
] = {0};
133 static u32 curveindex_2g
[TARGET_CHNL_NUM_2G
] = {0};
135 static u32 targetchnl_5g
[TARGET_CHNL_NUM_5G
] = {
136 25141, 25116, 25091, 25066, 25041,
137 25016, 24991, 24966, 24941, 24917,
138 24892, 24867, 24843, 24818, 24794,
139 24770, 24765, 24721, 24697, 24672,
140 24648, 24624, 24600, 24576, 24552,
141 24528, 24504, 24480, 24457, 24433,
142 24409, 24385, 24362, 24338, 24315,
143 24291, 24268, 24245, 24221, 24198,
144 24175, 24151, 24128, 24105, 24082,
145 24059, 24036, 24013, 23990, 23967,
146 23945, 23922, 23899, 23876, 23854,
147 23831, 23809, 23786, 23764, 23741,
148 23719, 23697, 23674, 23652, 23630,
149 23608, 23586, 23564, 23541, 23519,
150 23498, 23476, 23454, 23432, 23410,
151 23388, 23367, 23345, 23323, 23302,
152 23280, 23259, 23237, 23216, 23194,
153 23173, 23152, 23130, 23109, 23088,
154 23067, 23046, 23025, 23003, 22982,
155 22962, 22941, 22920, 22899, 22878,
156 22857, 22837, 22816, 22795, 22775,
157 22754, 22733, 22713, 22692, 22672,
158 22652, 22631, 22611, 22591, 22570,
159 22550, 22530, 22510, 22490, 22469,
160 22449, 22429, 22409, 22390, 22370,
161 22350, 22336, 22310, 22290, 22271,
162 22251, 22231, 22212, 22192, 22173,
163 22153, 22134, 22114, 22095, 22075,
164 22056, 22037, 22017, 21998, 21979,
165 21960, 21941, 21921, 21902, 21883,
166 21864, 21845, 21826, 21807, 21789,
167 21770, 21751, 21732, 21713, 21695,
168 21676, 21657, 21639, 21620, 21602,
169 21583, 21565, 21546, 21528, 21509,
170 21491, 21473, 21454, 21436, 21418,
171 21400, 21381, 21363, 21345, 21327,
172 21309, 21291, 21273, 21255, 21237,
173 21219, 21201, 21183, 21166, 21148,
174 21130, 21112, 21095, 21077, 21059,
175 21042, 21024, 21007, 20989, 20972,
176 25679, 25653, 25627, 25601, 25575,
177 25549, 25523, 25497, 25471, 25446,
178 25420, 25394, 25369, 25343, 25318,
179 25292, 25267, 25242, 25216, 25191,
184 static u32 targetchnl_2g
[TARGET_CHNL_NUM_2G
] = {
185 26084, 26030, 25976, 25923, 25869, 25816, 25764,
186 25711, 25658, 25606, 25554, 25502, 25451, 25328
189 static u32
_rtl92d_phy_calculate_bit_shift(u32 bitmask
)
193 for (i
= 0; i
<= 31; i
++) {
194 if (((bitmask
>> i
) & 0x1) == 1)
201 u32
rtl92d_phy_query_bb_reg(struct ieee80211_hw
*hw
, u32 regaddr
, u32 bitmask
)
203 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
204 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
205 u32 returnvalue
, originalvalue
, bitshift
;
207 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
, "regaddr(%#x), bitmask(%#x)\n",
209 if (rtlhal
->during_mac1init_radioa
|| rtlhal
->during_mac0init_radiob
) {
212 /* mac1 use phy0 read radio_b. */
213 /* mac0 use phy1 read radio_b. */
214 if (rtlhal
->during_mac1init_radioa
)
216 else if (rtlhal
->during_mac0init_radiob
)
217 dbi_direct
= BIT(3) | BIT(2);
218 originalvalue
= rtl92de_read_dword_dbi(hw
, (u16
)regaddr
,
221 originalvalue
= rtl_read_dword(rtlpriv
, regaddr
);
223 bitshift
= _rtl92d_phy_calculate_bit_shift(bitmask
);
224 returnvalue
= (originalvalue
& bitmask
) >> bitshift
;
225 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
226 "BBR MASK=0x%x Addr[0x%x]=0x%x\n",
227 bitmask
, regaddr
, originalvalue
);
231 void rtl92d_phy_set_bb_reg(struct ieee80211_hw
*hw
,
232 u32 regaddr
, u32 bitmask
, u32 data
)
234 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
235 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
237 u32 originalvalue
, bitshift
;
239 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
240 "regaddr(%#x), bitmask(%#x), data(%#x)\n",
241 regaddr
, bitmask
, data
);
242 if (rtlhal
->during_mac1init_radioa
)
244 else if (rtlhal
->during_mac0init_radiob
)
245 /* mac0 use phy1 write radio_b. */
246 dbi_direct
= BIT(3) | BIT(2);
247 if (bitmask
!= MASKDWORD
) {
248 if (rtlhal
->during_mac1init_radioa
||
249 rtlhal
->during_mac0init_radiob
)
250 originalvalue
= rtl92de_read_dword_dbi(hw
,
254 originalvalue
= rtl_read_dword(rtlpriv
, regaddr
);
255 bitshift
= _rtl92d_phy_calculate_bit_shift(bitmask
);
256 data
= ((originalvalue
& (~bitmask
)) | (data
<< bitshift
));
258 if (rtlhal
->during_mac1init_radioa
|| rtlhal
->during_mac0init_radiob
)
259 rtl92de_write_dword_dbi(hw
, (u16
) regaddr
, data
, dbi_direct
);
261 rtl_write_dword(rtlpriv
, regaddr
, data
);
262 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
263 "regaddr(%#x), bitmask(%#x), data(%#x)\n",
264 regaddr
, bitmask
, data
);
267 static u32
_rtl92d_phy_rf_serial_read(struct ieee80211_hw
*hw
,
268 enum radio_path rfpath
, u32 offset
)
271 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
272 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
273 struct bb_reg_def
*pphyreg
= &rtlphy
->phyreg_def
[rfpath
];
275 u32 tmplong
, tmplong2
;
280 tmplong
= rtl_get_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER2
, MASKDWORD
);
281 if (rfpath
== RF90_PATH_A
)
284 tmplong2
= rtl_get_bbreg(hw
, pphyreg
->rfhssi_para2
, MASKDWORD
);
285 tmplong2
= (tmplong2
& (~BLSSIREADADDRESS
)) |
286 (newoffset
<< 23) | BLSSIREADEDGE
;
287 rtl_set_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER2
, MASKDWORD
,
288 tmplong
& (~BLSSIREADEDGE
));
290 rtl_set_bbreg(hw
, pphyreg
->rfhssi_para2
, MASKDWORD
, tmplong2
);
293 rtl_set_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER2
, MASKDWORD
,
294 tmplong
| BLSSIREADEDGE
);
296 if (rfpath
== RF90_PATH_A
)
297 rfpi_enable
= (u8
) rtl_get_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER1
,
299 else if (rfpath
== RF90_PATH_B
)
300 rfpi_enable
= (u8
) rtl_get_bbreg(hw
, RFPGA0_XB_HSSIPARAMETER1
,
303 retvalue
= rtl_get_bbreg(hw
, pphyreg
->rf_rbpi
,
306 retvalue
= rtl_get_bbreg(hw
, pphyreg
->rf_rb
,
308 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
, "RFR-%d Addr[0x%x] = 0x%x\n",
309 rfpath
, pphyreg
->rf_rb
, retvalue
);
313 static void _rtl92d_phy_rf_serial_write(struct ieee80211_hw
*hw
,
314 enum radio_path rfpath
,
315 u32 offset
, u32 data
)
319 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
320 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
321 struct bb_reg_def
*pphyreg
= &rtlphy
->phyreg_def
[rfpath
];
325 data_and_addr
= ((newoffset
<< 20) | (data
& 0x000fffff)) & 0x0fffffff;
326 rtl_set_bbreg(hw
, pphyreg
->rf3wire_offset
, MASKDWORD
, data_and_addr
);
327 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
, "RFW-%d Addr[0x%x]=0x%x\n",
328 rfpath
, pphyreg
->rf3wire_offset
, data_and_addr
);
331 u32
rtl92d_phy_query_rf_reg(struct ieee80211_hw
*hw
,
332 enum radio_path rfpath
, u32 regaddr
, u32 bitmask
)
334 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
335 u32 original_value
, readback_value
, bitshift
;
338 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
339 "regaddr(%#x), rfpath(%#x), bitmask(%#x)\n",
340 regaddr
, rfpath
, bitmask
);
341 spin_lock_irqsave(&rtlpriv
->locks
.rf_lock
, flags
);
342 original_value
= _rtl92d_phy_rf_serial_read(hw
, rfpath
, regaddr
);
343 bitshift
= _rtl92d_phy_calculate_bit_shift(bitmask
);
344 readback_value
= (original_value
& bitmask
) >> bitshift
;
345 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_lock
, flags
);
346 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
347 "regaddr(%#x), rfpath(%#x), bitmask(%#x), original_value(%#x)\n",
348 regaddr
, rfpath
, bitmask
, original_value
);
349 return readback_value
;
352 void rtl92d_phy_set_rf_reg(struct ieee80211_hw
*hw
, enum radio_path rfpath
,
353 u32 regaddr
, u32 bitmask
, u32 data
)
355 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
356 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
357 u32 original_value
, bitshift
;
360 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
361 "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
362 regaddr
, bitmask
, data
, rfpath
);
365 spin_lock_irqsave(&rtlpriv
->locks
.rf_lock
, flags
);
366 if (rtlphy
->rf_mode
!= RF_OP_BY_FW
) {
367 if (bitmask
!= RFREG_OFFSET_MASK
) {
368 original_value
= _rtl92d_phy_rf_serial_read(hw
,
370 bitshift
= _rtl92d_phy_calculate_bit_shift(bitmask
);
371 data
= ((original_value
& (~bitmask
)) |
374 _rtl92d_phy_rf_serial_write(hw
, rfpath
, regaddr
, data
);
376 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_lock
, flags
);
377 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
378 "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
379 regaddr
, bitmask
, data
, rfpath
);
382 bool rtl92d_phy_mac_config(struct ieee80211_hw
*hw
)
384 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
389 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
, "Read Rtl819XMACPHY_Array\n");
390 arraylength
= MAC_2T_ARRAYLENGTH
;
391 ptrarray
= rtl8192de_mac_2tarray
;
392 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
, "Img:Rtl819XMAC_Array\n");
393 for (i
= 0; i
< arraylength
; i
= i
+ 2)
394 rtl_write_byte(rtlpriv
, ptrarray
[i
], (u8
) ptrarray
[i
+ 1]);
395 if (rtlpriv
->rtlhal
.macphymode
== SINGLEMAC_SINGLEPHY
) {
396 /* improve 2-stream TX EVM */
397 /* rtl_write_byte(rtlpriv, 0x14,0x71); */
398 /* AMPDU aggregation number 9 */
399 /* rtl_write_word(rtlpriv, REG_MAX_AGGR_NUM, MAX_AGGR_NUM); */
400 rtl_write_byte(rtlpriv
, REG_MAX_AGGR_NUM
, 0x0B);
402 /* 92D need to test to decide the num. */
403 rtl_write_byte(rtlpriv
, REG_MAX_AGGR_NUM
, 0x07);
408 static void _rtl92d_phy_init_bb_rf_register_definition(struct ieee80211_hw
*hw
)
410 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
411 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
413 /* RF Interface Sowrtware Control */
414 /* 16 LSBs if read 32-bit from 0x870 */
415 rtlphy
->phyreg_def
[RF90_PATH_A
].rfintfs
= RFPGA0_XAB_RFINTERFACESW
;
416 /* 16 MSBs if read 32-bit from 0x870 (16-bit for 0x872) */
417 rtlphy
->phyreg_def
[RF90_PATH_B
].rfintfs
= RFPGA0_XAB_RFINTERFACESW
;
418 /* 16 LSBs if read 32-bit from 0x874 */
419 rtlphy
->phyreg_def
[RF90_PATH_C
].rfintfs
= RFPGA0_XCD_RFINTERFACESW
;
420 /* 16 MSBs if read 32-bit from 0x874 (16-bit for 0x876) */
422 rtlphy
->phyreg_def
[RF90_PATH_D
].rfintfs
= RFPGA0_XCD_RFINTERFACESW
;
423 /* RF Interface Readback Value */
424 /* 16 LSBs if read 32-bit from 0x8E0 */
425 rtlphy
->phyreg_def
[RF90_PATH_A
].rfintfi
= RFPGA0_XAB_RFINTERFACERB
;
426 /* 16 MSBs if read 32-bit from 0x8E0 (16-bit for 0x8E2) */
427 rtlphy
->phyreg_def
[RF90_PATH_B
].rfintfi
= RFPGA0_XAB_RFINTERFACERB
;
428 /* 16 LSBs if read 32-bit from 0x8E4 */
429 rtlphy
->phyreg_def
[RF90_PATH_C
].rfintfi
= RFPGA0_XCD_RFINTERFACERB
;
430 /* 16 MSBs if read 32-bit from 0x8E4 (16-bit for 0x8E6) */
431 rtlphy
->phyreg_def
[RF90_PATH_D
].rfintfi
= RFPGA0_XCD_RFINTERFACERB
;
433 /* RF Interface Output (and Enable) */
434 /* 16 LSBs if read 32-bit from 0x860 */
435 rtlphy
->phyreg_def
[RF90_PATH_A
].rfintfo
= RFPGA0_XA_RFINTERFACEOE
;
436 /* 16 LSBs if read 32-bit from 0x864 */
437 rtlphy
->phyreg_def
[RF90_PATH_B
].rfintfo
= RFPGA0_XB_RFINTERFACEOE
;
439 /* RF Interface (Output and) Enable */
440 /* 16 MSBs if read 32-bit from 0x860 (16-bit for 0x862) */
441 rtlphy
->phyreg_def
[RF90_PATH_A
].rfintfe
= RFPGA0_XA_RFINTERFACEOE
;
442 /* 16 MSBs if read 32-bit from 0x864 (16-bit for 0x866) */
443 rtlphy
->phyreg_def
[RF90_PATH_B
].rfintfe
= RFPGA0_XB_RFINTERFACEOE
;
445 /* Addr of LSSI. Wirte RF register by driver */
447 rtlphy
->phyreg_def
[RF90_PATH_A
].rf3wire_offset
=
448 RFPGA0_XA_LSSIPARAMETER
;
449 rtlphy
->phyreg_def
[RF90_PATH_B
].rf3wire_offset
=
450 RFPGA0_XB_LSSIPARAMETER
;
454 rtlphy
->phyreg_def
[RF90_PATH_A
].rflssi_select
= RFPGA0_XAB_RFPARAMETER
;
455 rtlphy
->phyreg_def
[RF90_PATH_B
].rflssi_select
= RFPGA0_XAB_RFPARAMETER
;
456 rtlphy
->phyreg_def
[RF90_PATH_C
].rflssi_select
= RFPGA0_XCD_RFPARAMETER
;
457 rtlphy
->phyreg_def
[RF90_PATH_D
].rflssi_select
= RFPGA0_XCD_RFPARAMETER
;
459 /* Tx AGC Gain Stage (same for all path. Should we remove this?) */
461 rtlphy
->phyreg_def
[RF90_PATH_A
].rftxgain_stage
= RFPGA0_TXGAINSTAGE
;
463 rtlphy
->phyreg_def
[RF90_PATH_B
].rftxgain_stage
= RFPGA0_TXGAINSTAGE
;
465 rtlphy
->phyreg_def
[RF90_PATH_C
].rftxgain_stage
= RFPGA0_TXGAINSTAGE
;
467 rtlphy
->phyreg_def
[RF90_PATH_D
].rftxgain_stage
= RFPGA0_TXGAINSTAGE
;
469 /* Tranceiver A~D HSSI Parameter-1 */
470 /* wire control parameter1 */
471 rtlphy
->phyreg_def
[RF90_PATH_A
].rfhssi_para1
= RFPGA0_XA_HSSIPARAMETER1
;
472 /* wire control parameter1 */
473 rtlphy
->phyreg_def
[RF90_PATH_B
].rfhssi_para1
= RFPGA0_XB_HSSIPARAMETER1
;
475 /* Tranceiver A~D HSSI Parameter-2 */
476 /* wire control parameter2 */
477 rtlphy
->phyreg_def
[RF90_PATH_A
].rfhssi_para2
= RFPGA0_XA_HSSIPARAMETER2
;
478 /* wire control parameter2 */
479 rtlphy
->phyreg_def
[RF90_PATH_B
].rfhssi_para2
= RFPGA0_XB_HSSIPARAMETER2
;
481 /* RF switch Control */
482 /* TR/Ant switch control */
483 rtlphy
->phyreg_def
[RF90_PATH_A
].rfsw_ctrl
= RFPGA0_XAB_SWITCHCONTROL
;
484 rtlphy
->phyreg_def
[RF90_PATH_B
].rfsw_ctrl
= RFPGA0_XAB_SWITCHCONTROL
;
485 rtlphy
->phyreg_def
[RF90_PATH_C
].rfsw_ctrl
= RFPGA0_XCD_SWITCHCONTROL
;
486 rtlphy
->phyreg_def
[RF90_PATH_D
].rfsw_ctrl
= RFPGA0_XCD_SWITCHCONTROL
;
489 rtlphy
->phyreg_def
[RF90_PATH_A
].rfagc_control1
= ROFDM0_XAAGCCORE1
;
490 rtlphy
->phyreg_def
[RF90_PATH_B
].rfagc_control1
= ROFDM0_XBAGCCORE1
;
491 rtlphy
->phyreg_def
[RF90_PATH_C
].rfagc_control1
= ROFDM0_XCAGCCORE1
;
492 rtlphy
->phyreg_def
[RF90_PATH_D
].rfagc_control1
= ROFDM0_XDAGCCORE1
;
495 rtlphy
->phyreg_def
[RF90_PATH_A
].rfagc_control2
= ROFDM0_XAAGCCORE2
;
496 rtlphy
->phyreg_def
[RF90_PATH_B
].rfagc_control2
= ROFDM0_XBAGCCORE2
;
497 rtlphy
->phyreg_def
[RF90_PATH_C
].rfagc_control2
= ROFDM0_XCAGCCORE2
;
498 rtlphy
->phyreg_def
[RF90_PATH_D
].rfagc_control2
= ROFDM0_XDAGCCORE2
;
500 /* RX AFE control 1 */
501 rtlphy
->phyreg_def
[RF90_PATH_A
].rfrxiq_imbal
= ROFDM0_XARXIQIMBALANCE
;
502 rtlphy
->phyreg_def
[RF90_PATH_B
].rfrxiq_imbal
= ROFDM0_XBRXIQIMBALANCE
;
503 rtlphy
->phyreg_def
[RF90_PATH_C
].rfrxiq_imbal
= ROFDM0_XCRXIQIMBALANCE
;
504 rtlphy
->phyreg_def
[RF90_PATH_D
].rfrxiq_imbal
= ROFDM0_XDRXIQIMBALANCE
;
506 /*RX AFE control 1 */
507 rtlphy
->phyreg_def
[RF90_PATH_A
].rfrx_afe
= ROFDM0_XARXAFE
;
508 rtlphy
->phyreg_def
[RF90_PATH_B
].rfrx_afe
= ROFDM0_XBRXAFE
;
509 rtlphy
->phyreg_def
[RF90_PATH_C
].rfrx_afe
= ROFDM0_XCRXAFE
;
510 rtlphy
->phyreg_def
[RF90_PATH_D
].rfrx_afe
= ROFDM0_XDRXAFE
;
512 /* Tx AFE control 1 */
513 rtlphy
->phyreg_def
[RF90_PATH_A
].rftxiq_imbal
= ROFDM0_XATxIQIMBALANCE
;
514 rtlphy
->phyreg_def
[RF90_PATH_B
].rftxiq_imbal
= ROFDM0_XBTxIQIMBALANCE
;
515 rtlphy
->phyreg_def
[RF90_PATH_C
].rftxiq_imbal
= ROFDM0_XCTxIQIMBALANCE
;
516 rtlphy
->phyreg_def
[RF90_PATH_D
].rftxiq_imbal
= ROFDM0_XDTxIQIMBALANCE
;
518 /* Tx AFE control 2 */
519 rtlphy
->phyreg_def
[RF90_PATH_A
].rftx_afe
= ROFDM0_XATxAFE
;
520 rtlphy
->phyreg_def
[RF90_PATH_B
].rftx_afe
= ROFDM0_XBTxAFE
;
521 rtlphy
->phyreg_def
[RF90_PATH_C
].rftx_afe
= ROFDM0_XCTxAFE
;
522 rtlphy
->phyreg_def
[RF90_PATH_D
].rftx_afe
= ROFDM0_XDTxAFE
;
524 /* Tranceiver LSSI Readback SI mode */
525 rtlphy
->phyreg_def
[RF90_PATH_A
].rf_rb
= RFPGA0_XA_LSSIREADBACK
;
526 rtlphy
->phyreg_def
[RF90_PATH_B
].rf_rb
= RFPGA0_XB_LSSIREADBACK
;
527 rtlphy
->phyreg_def
[RF90_PATH_C
].rf_rb
= RFPGA0_XC_LSSIREADBACK
;
528 rtlphy
->phyreg_def
[RF90_PATH_D
].rf_rb
= RFPGA0_XD_LSSIREADBACK
;
530 /* Tranceiver LSSI Readback PI mode */
531 rtlphy
->phyreg_def
[RF90_PATH_A
].rf_rbpi
= TRANSCEIVERA_HSPI_READBACK
;
532 rtlphy
->phyreg_def
[RF90_PATH_B
].rf_rbpi
= TRANSCEIVERB_HSPI_READBACK
;
535 static bool _rtl92d_phy_config_bb_with_headerfile(struct ieee80211_hw
*hw
,
539 u32
*phy_regarray_table
;
540 u32
*agctab_array_table
= NULL
;
541 u32
*agctab_5garray_table
;
542 u16 phy_reg_arraylen
, agctab_arraylen
= 0, agctab_5garraylen
;
543 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
544 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
546 /* Normal chip,Mac0 use AGC_TAB.txt for 2G and 5G band. */
547 if (rtlhal
->interfaceindex
== 0) {
548 agctab_arraylen
= AGCTAB_ARRAYLENGTH
;
549 agctab_array_table
= rtl8192de_agctab_array
;
550 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
551 " ===> phy:MAC0, Rtl819XAGCTAB_Array\n");
553 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
554 agctab_arraylen
= AGCTAB_2G_ARRAYLENGTH
;
555 agctab_array_table
= rtl8192de_agctab_2garray
;
556 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
557 " ===> phy:MAC1, Rtl819XAGCTAB_2GArray\n");
559 agctab_5garraylen
= AGCTAB_5G_ARRAYLENGTH
;
560 agctab_5garray_table
= rtl8192de_agctab_5garray
;
561 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
562 " ===> phy:MAC1, Rtl819XAGCTAB_5GArray\n");
566 phy_reg_arraylen
= PHY_REG_2T_ARRAYLENGTH
;
567 phy_regarray_table
= rtl8192de_phy_reg_2tarray
;
568 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
569 " ===> phy:Rtl819XPHY_REG_Array_PG\n");
570 if (configtype
== BASEBAND_CONFIG_PHY_REG
) {
571 for (i
= 0; i
< phy_reg_arraylen
; i
= i
+ 2) {
572 rtl_addr_delay(phy_regarray_table
[i
]);
573 rtl_set_bbreg(hw
, phy_regarray_table
[i
], MASKDWORD
,
574 phy_regarray_table
[i
+ 1]);
576 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
577 "The phy_regarray_table[0] is %x Rtl819XPHY_REGArray[1] is %x\n",
578 phy_regarray_table
[i
],
579 phy_regarray_table
[i
+ 1]);
581 } else if (configtype
== BASEBAND_CONFIG_AGC_TAB
) {
582 if (rtlhal
->interfaceindex
== 0) {
583 for (i
= 0; i
< agctab_arraylen
; i
= i
+ 2) {
584 rtl_set_bbreg(hw
, agctab_array_table
[i
],
586 agctab_array_table
[i
+ 1]);
587 /* Add 1us delay between BB/RF register
590 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
591 "The Rtl819XAGCTAB_Array_Table[0] is %ul Rtl819XPHY_REGArray[1] is %ul\n",
592 agctab_array_table
[i
],
593 agctab_array_table
[i
+ 1]);
595 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
596 "Normal Chip, MAC0, load Rtl819XAGCTAB_Array\n");
598 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
599 for (i
= 0; i
< agctab_arraylen
; i
= i
+ 2) {
600 rtl_set_bbreg(hw
, agctab_array_table
[i
],
602 agctab_array_table
[i
+ 1]);
603 /* Add 1us delay between BB/RF register
606 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
607 "The Rtl819XAGCTAB_Array_Table[0] is %ul Rtl819XPHY_REGArray[1] is %ul\n",
608 agctab_array_table
[i
],
609 agctab_array_table
[i
+ 1]);
611 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
612 "Load Rtl819XAGCTAB_2GArray\n");
614 for (i
= 0; i
< agctab_5garraylen
; i
= i
+ 2) {
616 agctab_5garray_table
[i
],
618 agctab_5garray_table
[i
+ 1]);
619 /* Add 1us delay between BB/RF registeri
622 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
623 "The Rtl819XAGCTAB_5GArray_Table[0] is %ul Rtl819XPHY_REGArray[1] is %ul\n",
624 agctab_5garray_table
[i
],
625 agctab_5garray_table
[i
+ 1]);
627 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
628 "Load Rtl819XAGCTAB_5GArray\n");
635 static void _rtl92d_store_pwrindex_diffrate_offset(struct ieee80211_hw
*hw
,
636 u32 regaddr
, u32 bitmask
,
639 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
640 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
643 if (regaddr
== RTXAGC_A_RATE18_06
)
645 else if (regaddr
== RTXAGC_A_RATE54_24
)
647 else if (regaddr
== RTXAGC_A_CCK1_MCS32
)
649 else if (regaddr
== RTXAGC_B_CCK11_A_CCK2_11
&& bitmask
== 0xffffff00)
651 else if (regaddr
== RTXAGC_A_MCS03_MCS00
)
653 else if (regaddr
== RTXAGC_A_MCS07_MCS04
)
655 else if (regaddr
== RTXAGC_A_MCS11_MCS08
)
657 else if (regaddr
== RTXAGC_A_MCS15_MCS12
)
659 else if (regaddr
== RTXAGC_B_RATE18_06
)
661 else if (regaddr
== RTXAGC_B_RATE54_24
)
663 else if (regaddr
== RTXAGC_B_CCK1_55_MCS32
)
665 else if (regaddr
== RTXAGC_B_CCK11_A_CCK2_11
&& bitmask
== 0x000000ff)
667 else if (regaddr
== RTXAGC_B_MCS03_MCS00
)
669 else if (regaddr
== RTXAGC_B_MCS07_MCS04
)
671 else if (regaddr
== RTXAGC_B_MCS11_MCS08
)
673 else if (regaddr
== RTXAGC_B_MCS15_MCS12
)
678 rtlphy
->mcs_offset
[rtlphy
->pwrgroup_cnt
][index
] = data
;
679 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
680 "MCSTxPowerLevelOriginalOffset[%d][%d] = 0x%x\n",
681 rtlphy
->pwrgroup_cnt
, index
,
682 rtlphy
->mcs_offset
[rtlphy
->pwrgroup_cnt
][index
]);
684 rtlphy
->pwrgroup_cnt
++;
687 static bool _rtl92d_phy_config_bb_with_pgheaderfile(struct ieee80211_hw
*hw
,
690 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
692 u32
*phy_regarray_table_pg
;
693 u16 phy_regarray_pg_len
;
695 phy_regarray_pg_len
= PHY_REG_ARRAY_PG_LENGTH
;
696 phy_regarray_table_pg
= rtl8192de_phy_reg_array_pg
;
697 if (configtype
== BASEBAND_CONFIG_PHY_REG
) {
698 for (i
= 0; i
< phy_regarray_pg_len
; i
= i
+ 3) {
699 rtl_addr_delay(phy_regarray_table_pg
[i
]);
700 _rtl92d_store_pwrindex_diffrate_offset(hw
,
701 phy_regarray_table_pg
[i
],
702 phy_regarray_table_pg
[i
+ 1],
703 phy_regarray_table_pg
[i
+ 2]);
706 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
707 "configtype != BaseBand_Config_PHY_REG\n");
712 static bool _rtl92d_phy_bb_config(struct ieee80211_hw
*hw
)
714 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
715 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
716 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
717 bool rtstatus
= true;
719 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
, "==>\n");
720 rtstatus
= _rtl92d_phy_config_bb_with_headerfile(hw
,
721 BASEBAND_CONFIG_PHY_REG
);
723 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, "Write BB Reg Fail!!\n");
727 /* if (rtlphy->rf_type == RF_1T2R) {
728 * _rtl92c_phy_bb_config_1t(hw);
729 * RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "Config to 1T!!\n");
732 if (rtlefuse
->autoload_failflag
== false) {
733 rtlphy
->pwrgroup_cnt
= 0;
734 rtstatus
= _rtl92d_phy_config_bb_with_pgheaderfile(hw
,
735 BASEBAND_CONFIG_PHY_REG
);
738 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, "BB_PG Reg Fail!!\n");
741 rtstatus
= _rtl92d_phy_config_bb_with_headerfile(hw
,
742 BASEBAND_CONFIG_AGC_TAB
);
744 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, "AGC Table Fail\n");
747 rtlphy
->cck_high_power
= (bool) (rtl_get_bbreg(hw
,
748 RFPGA0_XA_HSSIPARAMETER2
, 0x200));
753 bool rtl92d_phy_bb_config(struct ieee80211_hw
*hw
)
755 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
760 _rtl92d_phy_init_bb_rf_register_definition(hw
);
761 regval
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
);
762 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
,
763 regval
| BIT(13) | BIT(0) | BIT(1));
764 rtl_write_byte(rtlpriv
, REG_AFE_PLL_CTRL
, 0x83);
765 rtl_write_byte(rtlpriv
, REG_AFE_PLL_CTRL
+ 1, 0xdb);
766 /* 0x1f bit7 bit6 represent for mac0/mac1 driver ready */
767 value
= rtl_read_byte(rtlpriv
, REG_RF_CTRL
);
768 rtl_write_byte(rtlpriv
, REG_RF_CTRL
, value
| RF_EN
| RF_RSTB
|
770 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, FEN_PPLL
| FEN_PCIEA
|
771 FEN_DIO_PCIE
| FEN_BB_GLB_RSTn
| FEN_BBRSTB
);
772 rtl_write_byte(rtlpriv
, REG_AFE_XTAL_CTRL
+ 1, 0x80);
773 if (!(IS_92D_SINGLEPHY(rtlpriv
->rtlhal
.version
))) {
774 regvaldw
= rtl_read_dword(rtlpriv
, REG_LEDCFG0
);
775 rtl_write_dword(rtlpriv
, REG_LEDCFG0
, regvaldw
| BIT(23));
778 return _rtl92d_phy_bb_config(hw
);
781 bool rtl92d_phy_rf_config(struct ieee80211_hw
*hw
)
783 return rtl92d_phy_rf6052_config(hw
);
786 bool rtl92d_phy_config_rf_with_headerfile(struct ieee80211_hw
*hw
,
787 enum rf_content content
,
788 enum radio_path rfpath
)
791 u32
*radioa_array_table
;
792 u32
*radiob_array_table
;
793 u16 radioa_arraylen
, radiob_arraylen
;
794 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
796 radioa_arraylen
= RADIOA_2T_ARRAYLENGTH
;
797 radioa_array_table
= rtl8192de_radioa_2tarray
;
798 radiob_arraylen
= RADIOB_2T_ARRAYLENGTH
;
799 radiob_array_table
= rtl8192de_radiob_2tarray
;
800 if (rtlpriv
->efuse
.internal_pa_5g
[0]) {
801 radioa_arraylen
= RADIOA_2T_INT_PA_ARRAYLENGTH
;
802 radioa_array_table
= rtl8192de_radioa_2t_int_paarray
;
804 if (rtlpriv
->efuse
.internal_pa_5g
[1]) {
805 radiob_arraylen
= RADIOB_2T_INT_PA_ARRAYLENGTH
;
806 radiob_array_table
= rtl8192de_radiob_2t_int_paarray
;
808 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
809 "PHY_ConfigRFWithHeaderFile() Radio_A:Rtl819XRadioA_1TArray\n");
810 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
811 "PHY_ConfigRFWithHeaderFile() Radio_B:Rtl819XRadioB_1TArray\n");
812 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
, "Radio No %x\n", rfpath
);
814 /* this only happens when DMDP, mac0 start on 2.4G,
815 * mac1 start on 5G, mac 0 has to set phy0&phy1
816 * pathA or mac1 has to set phy0&phy1 pathA */
817 if ((content
== radiob_txt
) && (rfpath
== RF90_PATH_A
)) {
818 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
819 " ===> althougth Path A, we load radiob.txt\n");
820 radioa_arraylen
= radiob_arraylen
;
821 radioa_array_table
= radiob_array_table
;
825 for (i
= 0; i
< radioa_arraylen
; i
= i
+ 2) {
826 rtl_rfreg_delay(hw
, rfpath
, radioa_array_table
[i
],
828 radioa_array_table
[i
+ 1]);
832 for (i
= 0; i
< radiob_arraylen
; i
= i
+ 2) {
833 rtl_rfreg_delay(hw
, rfpath
, radiob_array_table
[i
],
835 radiob_array_table
[i
+ 1]);
839 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
840 "switch case not processed\n");
843 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
844 "switch case not processed\n");
850 void rtl92d_phy_get_hw_reg_originalvalue(struct ieee80211_hw
*hw
)
852 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
853 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
855 rtlphy
->default_initialgain
[0] =
856 (u8
) rtl_get_bbreg(hw
, ROFDM0_XAAGCCORE1
, MASKBYTE0
);
857 rtlphy
->default_initialgain
[1] =
858 (u8
) rtl_get_bbreg(hw
, ROFDM0_XBAGCCORE1
, MASKBYTE0
);
859 rtlphy
->default_initialgain
[2] =
860 (u8
) rtl_get_bbreg(hw
, ROFDM0_XCAGCCORE1
, MASKBYTE0
);
861 rtlphy
->default_initialgain
[3] =
862 (u8
) rtl_get_bbreg(hw
, ROFDM0_XDAGCCORE1
, MASKBYTE0
);
863 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
864 "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x\n",
865 rtlphy
->default_initialgain
[0],
866 rtlphy
->default_initialgain
[1],
867 rtlphy
->default_initialgain
[2],
868 rtlphy
->default_initialgain
[3]);
869 rtlphy
->framesync
= (u8
)rtl_get_bbreg(hw
, ROFDM0_RXDETECTOR3
,
871 rtlphy
->framesync_c34
= rtl_get_bbreg(hw
, ROFDM0_RXDETECTOR2
,
873 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
874 "Default framesync (0x%x) = 0x%x\n",
875 ROFDM0_RXDETECTOR3
, rtlphy
->framesync
);
878 static void _rtl92d_get_txpower_index(struct ieee80211_hw
*hw
, u8 channel
,
879 u8
*cckpowerlevel
, u8
*ofdmpowerlevel
)
881 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
882 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
883 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
884 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
885 u8 index
= (channel
- 1);
888 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
890 cckpowerlevel
[RF90_PATH_A
] =
891 rtlefuse
->txpwrlevel_cck
[RF90_PATH_A
][index
];
893 cckpowerlevel
[RF90_PATH_B
] =
894 rtlefuse
->txpwrlevel_cck
[RF90_PATH_B
][index
];
896 cckpowerlevel
[RF90_PATH_A
] = 0;
897 cckpowerlevel
[RF90_PATH_B
] = 0;
899 /* 2. OFDM for 1S or 2S */
900 if (rtlphy
->rf_type
== RF_1T2R
|| rtlphy
->rf_type
== RF_1T1R
) {
901 /* Read HT 40 OFDM TX power */
902 ofdmpowerlevel
[RF90_PATH_A
] =
903 rtlefuse
->txpwrlevel_ht40_1s
[RF90_PATH_A
][index
];
904 ofdmpowerlevel
[RF90_PATH_B
] =
905 rtlefuse
->txpwrlevel_ht40_1s
[RF90_PATH_B
][index
];
906 } else if (rtlphy
->rf_type
== RF_2T2R
) {
907 /* Read HT 40 OFDM TX power */
908 ofdmpowerlevel
[RF90_PATH_A
] =
909 rtlefuse
->txpwrlevel_ht40_2s
[RF90_PATH_A
][index
];
910 ofdmpowerlevel
[RF90_PATH_B
] =
911 rtlefuse
->txpwrlevel_ht40_2s
[RF90_PATH_B
][index
];
915 static void _rtl92d_ccxpower_index_check(struct ieee80211_hw
*hw
,
916 u8 channel
, u8
*cckpowerlevel
, u8
*ofdmpowerlevel
)
918 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
919 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
921 rtlphy
->cur_cck_txpwridx
= cckpowerlevel
[0];
922 rtlphy
->cur_ofdm24g_txpwridx
= ofdmpowerlevel
[0];
925 static u8
_rtl92c_phy_get_rightchnlplace(u8 chnl
)
930 for (place
= 14; place
< sizeof(channel5g
); place
++) {
931 if (channel5g
[place
] == chnl
) {
940 void rtl92d_phy_set_txpower_level(struct ieee80211_hw
*hw
, u8 channel
)
942 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
943 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
944 u8 cckpowerlevel
[2], ofdmpowerlevel
[2];
946 if (!rtlefuse
->txpwr_fromeprom
)
948 channel
= _rtl92c_phy_get_rightchnlplace(channel
);
949 _rtl92d_get_txpower_index(hw
, channel
, &cckpowerlevel
[0],
951 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
952 _rtl92d_ccxpower_index_check(hw
, channel
, &cckpowerlevel
[0],
954 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
955 rtl92d_phy_rf6052_set_cck_txpower(hw
, &cckpowerlevel
[0]);
956 rtl92d_phy_rf6052_set_ofdm_txpower(hw
, &ofdmpowerlevel
[0], channel
);
959 void rtl92d_phy_set_bw_mode(struct ieee80211_hw
*hw
,
960 enum nl80211_channel_type ch_type
)
962 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
963 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
964 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
965 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
966 unsigned long flag
= 0;
970 if (rtlphy
->set_bwmode_inprogress
)
972 if ((is_hal_stop(rtlhal
)) || (RT_CANNOT_IO(hw
))) {
973 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
974 "FALSE driver sleep or unload\n");
977 rtlphy
->set_bwmode_inprogress
= true;
978 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_TRACE
, "Switch to %s bandwidth\n",
979 rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20
?
981 reg_bw_opmode
= rtl_read_byte(rtlpriv
, REG_BWOPMODE
);
982 reg_prsr_rsc
= rtl_read_byte(rtlpriv
, REG_RRSR
+ 2);
983 switch (rtlphy
->current_chan_bw
) {
984 case HT_CHANNEL_WIDTH_20
:
985 reg_bw_opmode
|= BW_OPMODE_20MHZ
;
986 rtl_write_byte(rtlpriv
, REG_BWOPMODE
, reg_bw_opmode
);
988 case HT_CHANNEL_WIDTH_20_40
:
989 reg_bw_opmode
&= ~BW_OPMODE_20MHZ
;
990 rtl_write_byte(rtlpriv
, REG_BWOPMODE
, reg_bw_opmode
);
992 reg_prsr_rsc
= (reg_prsr_rsc
& 0x90) |
993 (mac
->cur_40_prime_sc
<< 5);
994 rtl_write_byte(rtlpriv
, REG_RRSR
+ 2, reg_prsr_rsc
);
997 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
998 "unknown bandwidth: %#X\n", rtlphy
->current_chan_bw
);
1001 switch (rtlphy
->current_chan_bw
) {
1002 case HT_CHANNEL_WIDTH_20
:
1003 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BRFMOD
, 0x0);
1004 rtl_set_bbreg(hw
, RFPGA1_RFMOD
, BRFMOD
, 0x0);
1005 /* SET BIT10 BIT11 for receive cck */
1006 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER2
, BIT(10) |
1009 case HT_CHANNEL_WIDTH_20_40
:
1010 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BRFMOD
, 0x1);
1011 rtl_set_bbreg(hw
, RFPGA1_RFMOD
, BRFMOD
, 0x1);
1012 /* Set Control channel to upper or lower.
1013 * These settings are required only for 40MHz */
1014 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
1015 rtl92d_acquire_cckandrw_pagea_ctl(hw
, &flag
);
1016 rtl_set_bbreg(hw
, RCCK0_SYSTEM
, BCCKSIDEBAND
,
1017 (mac
->cur_40_prime_sc
>> 1));
1018 rtl92d_release_cckandrw_pagea_ctl(hw
, &flag
);
1020 rtl_set_bbreg(hw
, ROFDM1_LSTF
, 0xC00, mac
->cur_40_prime_sc
);
1021 /* SET BIT10 BIT11 for receive cck */
1022 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER2
, BIT(10) |
1024 rtl_set_bbreg(hw
, 0x818, (BIT(26) | BIT(27)),
1025 (mac
->cur_40_prime_sc
==
1026 HAL_PRIME_CHNL_OFFSET_LOWER
) ? 2 : 1);
1029 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1030 "unknown bandwidth: %#X\n", rtlphy
->current_chan_bw
);
1034 rtl92d_phy_rf6052_set_bandwidth(hw
, rtlphy
->current_chan_bw
);
1035 rtlphy
->set_bwmode_inprogress
= false;
1036 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_TRACE
, "<==\n");
1039 static void _rtl92d_phy_stop_trx_before_changeband(struct ieee80211_hw
*hw
)
1041 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BCCKEN
, 0);
1042 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BOFDMEN
, 0);
1043 rtl_set_bbreg(hw
, ROFDM0_TRXPATHENABLE
, MASKBYTE0
, 0x00);
1044 rtl_set_bbreg(hw
, ROFDM1_TRXPATHENABLE
, BDWORD
, 0x0);
1047 static void rtl92d_phy_switch_wirelessband(struct ieee80211_hw
*hw
, u8 band
)
1049 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1050 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1053 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "==>\n");
1054 rtlhal
->bandset
= band
;
1055 rtlhal
->current_bandtype
= band
;
1056 if (IS_92D_SINGLEPHY(rtlhal
->version
))
1057 rtlhal
->bandset
= BAND_ON_BOTH
;
1059 _rtl92d_phy_stop_trx_before_changeband(hw
);
1060 /* reconfig BB/RF according to wireless mode */
1061 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
1062 /* BB & RF Config */
1063 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_DMESG
, "====>2.4G\n");
1064 if (rtlhal
->interfaceindex
== 1)
1065 _rtl92d_phy_config_bb_with_headerfile(hw
,
1066 BASEBAND_CONFIG_AGC_TAB
);
1069 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_DMESG
, "====>5G\n");
1070 if (rtlhal
->interfaceindex
== 1)
1071 _rtl92d_phy_config_bb_with_headerfile(hw
,
1072 BASEBAND_CONFIG_AGC_TAB
);
1074 rtl92d_update_bbrf_configuration(hw
);
1075 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
)
1076 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BCCKEN
, 0x1);
1077 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BOFDMEN
, 0x1);
1080 /* rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 1); */
1081 rtlhal
->reloadtxpowerindex
= true;
1082 /* notice fw know band status 0x81[1]/0x53[1] = 0: 5G, 1: 2G */
1083 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
1084 value8
= rtl_read_byte(rtlpriv
, (rtlhal
->interfaceindex
==
1085 0 ? REG_MAC0
: REG_MAC1
));
1087 rtl_write_byte(rtlpriv
, (rtlhal
->interfaceindex
==
1088 0 ? REG_MAC0
: REG_MAC1
), value8
);
1090 value8
= rtl_read_byte(rtlpriv
, (rtlhal
->interfaceindex
==
1091 0 ? REG_MAC0
: REG_MAC1
));
1092 value8
&= (~BIT(1));
1093 rtl_write_byte(rtlpriv
, (rtlhal
->interfaceindex
==
1094 0 ? REG_MAC0
: REG_MAC1
), value8
);
1097 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "<==Switch Band OK\n");
1100 static void _rtl92d_phy_reload_imr_setting(struct ieee80211_hw
*hw
,
1101 u8 channel
, u8 rfpath
)
1103 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1104 u32 imr_num
= MAX_RF_IMR_INDEX
;
1105 u32 rfmask
= RFREG_OFFSET_MASK
;
1107 unsigned long flag
= 0;
1109 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "====>path %d\n", rfpath
);
1110 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_5G
) {
1111 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "====>5G\n");
1112 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BIT(25) | BIT(24), 0);
1113 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
, 0x00f00000, 0xf);
1116 rtl_set_bbreg(hw
, ROFDM1_CFOTRACKING
, BIT(13) |
1119 rtl_set_bbreg(hw
, ROFDM1_CFOTRACKING
, BIT(13) |
1121 /* leave 0 for channel1-14. */
1122 group
= channel
<= 64 ? 1 : 2;
1123 imr_num
= MAX_RF_IMR_INDEX_NORMAL
;
1124 for (i
= 0; i
< imr_num
; i
++)
1125 rtl_set_rfreg(hw
, (enum radio_path
)rfpath
,
1126 rf_reg_for_5g_swchnl_normal
[i
], rfmask
,
1127 rf_imr_param_normal
[0][group
][i
]);
1128 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
, 0x00f00000, 0);
1129 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BOFDMEN
, 1);
1132 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_LOUD
,
1133 "Load RF IMR parameters for G band. IMR already setting %d\n",
1134 rtlpriv
->rtlhal
.load_imrandiqk_setting_for2g
);
1135 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "====>2.4G\n");
1136 if (!rtlpriv
->rtlhal
.load_imrandiqk_setting_for2g
) {
1137 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_LOUD
,
1138 "Load RF IMR parameters for G band. %d\n",
1140 rtl92d_acquire_cckandrw_pagea_ctl(hw
, &flag
);
1141 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BIT(25) | BIT(24), 0);
1142 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
,
1144 imr_num
= MAX_RF_IMR_INDEX_NORMAL
;
1145 for (i
= 0; i
< imr_num
; i
++) {
1146 rtl_set_rfreg(hw
, (enum radio_path
)rfpath
,
1147 rf_reg_for_5g_swchnl_normal
[i
],
1149 rf_imr_param_normal
[0][0][i
]);
1151 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
,
1153 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BOFDMEN
| BCCKEN
, 3);
1154 rtl92d_release_cckandrw_pagea_ctl(hw
, &flag
);
1157 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "<====\n");
1160 static void _rtl92d_phy_enable_rf_env(struct ieee80211_hw
*hw
,
1161 u8 rfpath
, u32
*pu4_regval
)
1163 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1164 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1165 struct bb_reg_def
*pphyreg
= &rtlphy
->phyreg_def
[rfpath
];
1167 RT_TRACE(rtlpriv
, COMP_RF
, DBG_LOUD
, "====>\n");
1168 /*----Store original RFENV control type----*/
1172 *pu4_regval
= rtl_get_bbreg(hw
, pphyreg
->rfintfs
, BRFSI_RFENV
);
1177 rtl_get_bbreg(hw
, pphyreg
->rfintfs
, BRFSI_RFENV
<< 16);
1180 /*----Set RF_ENV enable----*/
1181 rtl_set_bbreg(hw
, pphyreg
->rfintfe
, BRFSI_RFENV
<< 16, 0x1);
1183 /*----Set RF_ENV output high----*/
1184 rtl_set_bbreg(hw
, pphyreg
->rfintfo
, BRFSI_RFENV
, 0x1);
1186 /* Set bit number of Address and Data for RF register */
1187 /* Set 1 to 4 bits for 8255 */
1188 rtl_set_bbreg(hw
, pphyreg
->rfhssi_para2
, B3WIREADDRESSLENGTH
, 0x0);
1190 /*Set 0 to 12 bits for 8255 */
1191 rtl_set_bbreg(hw
, pphyreg
->rfhssi_para2
, B3WIREDATALENGTH
, 0x0);
1193 RT_TRACE(rtlpriv
, COMP_RF
, DBG_LOUD
, "<====\n");
1196 static void _rtl92d_phy_restore_rf_env(struct ieee80211_hw
*hw
, u8 rfpath
,
1199 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1200 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1201 struct bb_reg_def
*pphyreg
= &rtlphy
->phyreg_def
[rfpath
];
1203 RT_TRACE(rtlpriv
, COMP_RF
, DBG_LOUD
, "=====>\n");
1204 /*----Restore RFENV control type----*/
1208 rtl_set_bbreg(hw
, pphyreg
->rfintfs
, BRFSI_RFENV
, *pu4_regval
);
1212 rtl_set_bbreg(hw
, pphyreg
->rfintfs
, BRFSI_RFENV
<< 16,
1216 RT_TRACE(rtlpriv
, COMP_RF
, DBG_LOUD
, "<=====\n");
1219 static void _rtl92d_phy_switch_rf_setting(struct ieee80211_hw
*hw
, u8 channel
)
1221 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1222 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1223 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
1224 u8 path
= rtlhal
->current_bandtype
==
1225 BAND_ON_5G
? RF90_PATH_A
: RF90_PATH_B
;
1226 u8 index
= 0, i
= 0, rfpath
= RF90_PATH_A
;
1227 bool need_pwr_down
= false, internal_pa
= false;
1228 u32 u4regvalue
, mask
= 0x1C000, value
= 0, u4tmp
, u4tmp2
;
1230 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "====>\n");
1231 /* config path A for 5G */
1232 if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
1233 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "====>5G\n");
1234 u4tmp
= curveindex_5g
[channel
- 1];
1235 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1236 "ver 1 set RF-A, 5G, 0x28 = 0x%x !!\n", u4tmp
);
1237 for (i
= 0; i
< RF_CHNL_NUM_5G
; i
++) {
1238 if (channel
== rf_chnl_5g
[i
] && channel
<= 140)
1241 for (i
= 0; i
< RF_CHNL_NUM_5G_40M
; i
++) {
1242 if (channel
== rf_chnl_5g_40m
[i
] && channel
<= 140)
1245 if (channel
== 149 || channel
== 155 || channel
== 161)
1247 else if (channel
== 151 || channel
== 153 || channel
== 163
1250 else if (channel
== 157 || channel
== 159)
1253 if (rtlhal
->macphymode
== DUALMAC_DUALPHY
1254 && rtlhal
->interfaceindex
== 1) {
1255 need_pwr_down
= rtl92d_phy_enable_anotherphy(hw
, false);
1256 rtlhal
->during_mac1init_radioa
= true;
1257 /* asume no this case */
1259 _rtl92d_phy_enable_rf_env(hw
, path
,
1262 for (i
= 0; i
< RF_REG_NUM_FOR_C_CUT_5G
; i
++) {
1263 if (i
== 0 && (rtlhal
->macphymode
== DUALMAC_DUALPHY
)) {
1264 rtl_set_rfreg(hw
, (enum radio_path
)path
,
1265 rf_reg_for_c_cut_5g
[i
],
1266 RFREG_OFFSET_MASK
, 0xE439D);
1267 } else if (rf_reg_for_c_cut_5g
[i
] == RF_SYN_G4
) {
1268 u4tmp2
= (rf_reg_pram_c_5g
[index
][i
] &
1269 0x7FF) | (u4tmp
<< 11);
1271 u4tmp2
&= ~(BIT(7) | BIT(6));
1272 rtl_set_rfreg(hw
, (enum radio_path
)path
,
1273 rf_reg_for_c_cut_5g
[i
],
1274 RFREG_OFFSET_MASK
, u4tmp2
);
1276 rtl_set_rfreg(hw
, (enum radio_path
)path
,
1277 rf_reg_for_c_cut_5g
[i
],
1279 rf_reg_pram_c_5g
[index
][i
]);
1281 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
1282 "offset 0x%x value 0x%x path %d index %d readback 0x%x\n",
1283 rf_reg_for_c_cut_5g
[i
],
1284 rf_reg_pram_c_5g
[index
][i
],
1286 rtl_get_rfreg(hw
, (enum radio_path
)path
,
1287 rf_reg_for_c_cut_5g
[i
],
1288 RFREG_OFFSET_MASK
));
1291 _rtl92d_phy_restore_rf_env(hw
, path
, &u4regvalue
);
1292 if (rtlhal
->during_mac1init_radioa
)
1293 rtl92d_phy_powerdown_anotherphy(hw
, false);
1296 else if (channel
>= 149)
1298 if (channel
>= 36 && channel
<= 64)
1300 else if (channel
>= 100 && channel
<= 140)
1304 for (rfpath
= RF90_PATH_A
; rfpath
< rtlphy
->num_total_rfpath
;
1306 if (rtlhal
->macphymode
== DUALMAC_DUALPHY
&&
1307 rtlhal
->interfaceindex
== 1) /* MAC 1 5G */
1308 internal_pa
= rtlpriv
->efuse
.internal_pa_5g
[1];
1311 rtlpriv
->efuse
.internal_pa_5g
[rfpath
];
1314 i
< RF_REG_NUM_FOR_C_CUT_5G_INTERNALPA
;
1316 rtl_set_rfreg(hw
, rfpath
,
1317 rf_for_c_cut_5g_internal_pa
[i
],
1319 rf_pram_c_5g_int_pa
[index
][i
]);
1320 RT_TRACE(rtlpriv
, COMP_RF
, DBG_LOUD
,
1321 "offset 0x%x value 0x%x path %d index %d\n",
1322 rf_for_c_cut_5g_internal_pa
[i
],
1323 rf_pram_c_5g_int_pa
[index
][i
],
1327 rtl_set_rfreg(hw
, (enum radio_path
)rfpath
, 0x0B,
1331 } else if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
1332 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "====>2.4G\n");
1333 u4tmp
= curveindex_2g
[channel
- 1];
1334 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1335 "ver 3 set RF-B, 2G, 0x28 = 0x%x !!\n", u4tmp
);
1336 if (channel
== 1 || channel
== 2 || channel
== 4 || channel
== 9
1337 || channel
== 10 || channel
== 11 || channel
== 12)
1339 else if (channel
== 3 || channel
== 13 || channel
== 14)
1341 else if (channel
>= 5 && channel
<= 8)
1343 if (rtlhal
->macphymode
== DUALMAC_DUALPHY
) {
1345 if (rtlhal
->interfaceindex
== 0) {
1347 rtl92d_phy_enable_anotherphy(hw
, true);
1348 rtlhal
->during_mac0init_radiob
= true;
1351 _rtl92d_phy_enable_rf_env(hw
, path
,
1355 for (i
= 0; i
< RF_REG_NUM_FOR_C_CUT_2G
; i
++) {
1356 if (rf_reg_for_c_cut_2g
[i
] == RF_SYN_G7
)
1357 rtl_set_rfreg(hw
, (enum radio_path
)path
,
1358 rf_reg_for_c_cut_2g
[i
],
1360 (rf_reg_param_for_c_cut_2g
[index
][i
] |
1363 rtl_set_rfreg(hw
, (enum radio_path
)path
,
1364 rf_reg_for_c_cut_2g
[i
],
1366 rf_reg_param_for_c_cut_2g
1368 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
1369 "offset 0x%x value 0x%x mak 0x%x path %d index %d readback 0x%x\n",
1370 rf_reg_for_c_cut_2g
[i
],
1371 rf_reg_param_for_c_cut_2g
[index
][i
],
1372 rf_reg_mask_for_c_cut_2g
[i
], path
, index
,
1373 rtl_get_rfreg(hw
, (enum radio_path
)path
,
1374 rf_reg_for_c_cut_2g
[i
],
1375 RFREG_OFFSET_MASK
));
1377 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1378 "cosa ver 3 set RF-B, 2G, 0x28 = 0x%x !!\n",
1379 rf_syn_g4_for_c_cut_2g
| (u4tmp
<< 11));
1381 rtl_set_rfreg(hw
, (enum radio_path
)path
, RF_SYN_G4
,
1383 rf_syn_g4_for_c_cut_2g
| (u4tmp
<< 11));
1385 _rtl92d_phy_restore_rf_env(hw
, path
, &u4regvalue
);
1386 if (rtlhal
->during_mac0init_radiob
)
1387 rtl92d_phy_powerdown_anotherphy(hw
, true);
1389 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "<====\n");
1392 u8
rtl92d_get_rightchnlplace_for_iqk(u8 chnl
)
1394 u8 channel_all
[59] = {
1395 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
1396 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58,
1397 60, 62, 64, 100, 102, 104, 106, 108, 110, 112,
1398 114, 116, 118, 120, 122, 124, 126, 128, 130,
1399 132, 134, 136, 138, 140, 149, 151, 153, 155,
1400 157, 159, 161, 163, 165
1405 for (place
= 14; place
< sizeof(channel_all
); place
++) {
1406 if (channel_all
[place
] == chnl
)
1414 #define MAX_TOLERANCE 5
1415 #define IQK_DELAY_TIME 1 /* ms */
1416 #define MAX_TOLERANCE_92D 3
1418 /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */
1419 static u8
_rtl92d_phy_patha_iqk(struct ieee80211_hw
*hw
, bool configpathb
)
1421 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1422 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1423 u32 regeac
, rege94
, rege9c
, regea4
;
1426 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path A IQK!\n");
1427 /* path-A IQK setting */
1428 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path-A IQK setting!\n");
1429 if (rtlhal
->interfaceindex
== 0) {
1430 rtl_set_bbreg(hw
, 0xe30, MASKDWORD
, 0x10008c1f);
1431 rtl_set_bbreg(hw
, 0xe34, MASKDWORD
, 0x10008c1f);
1433 rtl_set_bbreg(hw
, 0xe30, MASKDWORD
, 0x10008c22);
1434 rtl_set_bbreg(hw
, 0xe34, MASKDWORD
, 0x10008c22);
1436 rtl_set_bbreg(hw
, 0xe38, MASKDWORD
, 0x82140102);
1437 rtl_set_bbreg(hw
, 0xe3c, MASKDWORD
, 0x28160206);
1438 /* path-B IQK setting */
1440 rtl_set_bbreg(hw
, 0xe50, MASKDWORD
, 0x10008c22);
1441 rtl_set_bbreg(hw
, 0xe54, MASKDWORD
, 0x10008c22);
1442 rtl_set_bbreg(hw
, 0xe58, MASKDWORD
, 0x82140102);
1443 rtl_set_bbreg(hw
, 0xe5c, MASKDWORD
, 0x28160206);
1445 /* LO calibration setting */
1446 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "LO calibration setting!\n");
1447 rtl_set_bbreg(hw
, 0xe4c, MASKDWORD
, 0x00462911);
1448 /* One shot, path A LOK & IQK */
1449 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "One shot, path A LOK & IQK!\n");
1450 rtl_set_bbreg(hw
, 0xe48, MASKDWORD
, 0xf9000000);
1451 rtl_set_bbreg(hw
, 0xe48, MASKDWORD
, 0xf8000000);
1453 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1454 "Delay %d ms for One shot, path A LOK & IQK\n",
1456 mdelay(IQK_DELAY_TIME
);
1458 regeac
= rtl_get_bbreg(hw
, 0xeac, MASKDWORD
);
1459 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xeac = 0x%x\n", regeac
);
1460 rege94
= rtl_get_bbreg(hw
, 0xe94, MASKDWORD
);
1461 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xe94 = 0x%x\n", rege94
);
1462 rege9c
= rtl_get_bbreg(hw
, 0xe9c, MASKDWORD
);
1463 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xe9c = 0x%x\n", rege9c
);
1464 regea4
= rtl_get_bbreg(hw
, 0xea4, MASKDWORD
);
1465 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xea4 = 0x%x\n", regea4
);
1466 if (!(regeac
& BIT(28)) && (((rege94
& 0x03FF0000) >> 16) != 0x142) &&
1467 (((rege9c
& 0x03FF0000) >> 16) != 0x42))
1469 else /* if Tx not OK, ignore Rx */
1471 /* if Tx is OK, check whether Rx is OK */
1472 if (!(regeac
& BIT(27)) && (((regea4
& 0x03FF0000) >> 16) != 0x132) &&
1473 (((regeac
& 0x03FF0000) >> 16) != 0x36))
1476 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path A Rx IQK fail!!\n");
1480 /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */
1481 static u8
_rtl92d_phy_patha_iqk_5g_normal(struct ieee80211_hw
*hw
,
1484 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1485 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1486 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1487 u32 regeac
, rege94
, rege9c
, regea4
;
1491 u32 TxOKBit
= BIT(28), RxOKBit
= BIT(27);
1493 if (rtlhal
->interfaceindex
== 1) { /* PHY1 */
1497 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path A IQK!\n");
1498 /* path-A IQK setting */
1499 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path-A IQK setting!\n");
1500 rtl_set_bbreg(hw
, 0xe30, MASKDWORD
, 0x18008c1f);
1501 rtl_set_bbreg(hw
, 0xe34, MASKDWORD
, 0x18008c1f);
1502 rtl_set_bbreg(hw
, 0xe38, MASKDWORD
, 0x82140307);
1503 rtl_set_bbreg(hw
, 0xe3c, MASKDWORD
, 0x68160960);
1504 /* path-B IQK setting */
1506 rtl_set_bbreg(hw
, 0xe50, MASKDWORD
, 0x18008c2f);
1507 rtl_set_bbreg(hw
, 0xe54, MASKDWORD
, 0x18008c2f);
1508 rtl_set_bbreg(hw
, 0xe58, MASKDWORD
, 0x82110000);
1509 rtl_set_bbreg(hw
, 0xe5c, MASKDWORD
, 0x68110000);
1511 /* LO calibration setting */
1512 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "LO calibration setting!\n");
1513 rtl_set_bbreg(hw
, 0xe4c, MASKDWORD
, 0x00462911);
1515 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
, MASKDWORD
, 0x07000f60);
1516 rtl_set_bbreg(hw
, RFPGA0_XA_RFINTERFACEOE
, MASKDWORD
, 0x66e60e30);
1517 for (i
= 0; i
< retrycount
; i
++) {
1518 /* One shot, path A LOK & IQK */
1519 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1520 "One shot, path A LOK & IQK!\n");
1521 rtl_set_bbreg(hw
, 0xe48, MASKDWORD
, 0xf9000000);
1522 rtl_set_bbreg(hw
, 0xe48, MASKDWORD
, 0xf8000000);
1524 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1525 "Delay %d ms for One shot, path A LOK & IQK.\n",
1527 mdelay(IQK_DELAY_TIME
* 10);
1529 regeac
= rtl_get_bbreg(hw
, 0xeac, MASKDWORD
);
1530 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xeac = 0x%x\n", regeac
);
1531 rege94
= rtl_get_bbreg(hw
, 0xe94, MASKDWORD
);
1532 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xe94 = 0x%x\n", rege94
);
1533 rege9c
= rtl_get_bbreg(hw
, 0xe9c, MASKDWORD
);
1534 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xe9c = 0x%x\n", rege9c
);
1535 regea4
= rtl_get_bbreg(hw
, 0xea4, MASKDWORD
);
1536 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xea4 = 0x%x\n", regea4
);
1537 if (!(regeac
& TxOKBit
) &&
1538 (((rege94
& 0x03FF0000) >> 16) != 0x142)) {
1540 } else { /* if Tx not OK, ignore Rx */
1541 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1542 "Path A Tx IQK fail!!\n");
1546 /* if Tx is OK, check whether Rx is OK */
1547 if (!(regeac
& RxOKBit
) &&
1548 (((regea4
& 0x03FF0000) >> 16) != 0x132)) {
1552 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1553 "Path A Rx IQK fail!!\n");
1557 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
, MASKDWORD
,
1558 rtlphy
->iqk_bb_backup
[0]);
1559 rtl_set_bbreg(hw
, RFPGA0_XA_RFINTERFACEOE
, MASKDWORD
,
1560 rtlphy
->iqk_bb_backup
[1]);
1564 /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */
1565 static u8
_rtl92d_phy_pathb_iqk(struct ieee80211_hw
*hw
)
1567 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1568 u32 regeac
, regeb4
, regebc
, regec4
, regecc
;
1571 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path B IQK!\n");
1572 /* One shot, path B LOK & IQK */
1573 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "One shot, path A LOK & IQK!\n");
1574 rtl_set_bbreg(hw
, 0xe60, MASKDWORD
, 0x00000002);
1575 rtl_set_bbreg(hw
, 0xe60, MASKDWORD
, 0x00000000);
1577 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1578 "Delay %d ms for One shot, path B LOK & IQK\n", IQK_DELAY_TIME
);
1579 mdelay(IQK_DELAY_TIME
);
1581 regeac
= rtl_get_bbreg(hw
, 0xeac, MASKDWORD
);
1582 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xeac = 0x%x\n", regeac
);
1583 regeb4
= rtl_get_bbreg(hw
, 0xeb4, MASKDWORD
);
1584 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xeb4 = 0x%x\n", regeb4
);
1585 regebc
= rtl_get_bbreg(hw
, 0xebc, MASKDWORD
);
1586 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xebc = 0x%x\n", regebc
);
1587 regec4
= rtl_get_bbreg(hw
, 0xec4, MASKDWORD
);
1588 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xec4 = 0x%x\n", regec4
);
1589 regecc
= rtl_get_bbreg(hw
, 0xecc, MASKDWORD
);
1590 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xecc = 0x%x\n", regecc
);
1591 if (!(regeac
& BIT(31)) && (((regeb4
& 0x03FF0000) >> 16) != 0x142) &&
1592 (((regebc
& 0x03FF0000) >> 16) != 0x42))
1596 if (!(regeac
& BIT(30)) && (((regec4
& 0x03FF0000) >> 16) != 0x132) &&
1597 (((regecc
& 0x03FF0000) >> 16) != 0x36))
1600 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path B Rx IQK fail!!\n");
1604 /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */
1605 static u8
_rtl92d_phy_pathb_iqk_5g_normal(struct ieee80211_hw
*hw
)
1607 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1608 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1609 u32 regeac
, regeb4
, regebc
, regec4
, regecc
;
1614 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path B IQK!\n");
1615 /* path-A IQK setting */
1616 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path-A IQK setting!\n");
1617 rtl_set_bbreg(hw
, 0xe30, MASKDWORD
, 0x18008c1f);
1618 rtl_set_bbreg(hw
, 0xe34, MASKDWORD
, 0x18008c1f);
1619 rtl_set_bbreg(hw
, 0xe38, MASKDWORD
, 0x82110000);
1620 rtl_set_bbreg(hw
, 0xe3c, MASKDWORD
, 0x68110000);
1622 /* path-B IQK setting */
1623 rtl_set_bbreg(hw
, 0xe50, MASKDWORD
, 0x18008c2f);
1624 rtl_set_bbreg(hw
, 0xe54, MASKDWORD
, 0x18008c2f);
1625 rtl_set_bbreg(hw
, 0xe58, MASKDWORD
, 0x82140307);
1626 rtl_set_bbreg(hw
, 0xe5c, MASKDWORD
, 0x68160960);
1628 /* LO calibration setting */
1629 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "LO calibration setting!\n");
1630 rtl_set_bbreg(hw
, 0xe4c, MASKDWORD
, 0x00462911);
1633 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
, MASKDWORD
, 0x0f600700);
1634 rtl_set_bbreg(hw
, RFPGA0_XB_RFINTERFACEOE
, MASKDWORD
, 0x061f0d30);
1636 for (i
= 0; i
< retrycount
; i
++) {
1637 /* One shot, path B LOK & IQK */
1638 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1639 "One shot, path A LOK & IQK!\n");
1640 rtl_set_bbreg(hw
, 0xe48, MASKDWORD
, 0xfa000000);
1641 rtl_set_bbreg(hw
, 0xe48, MASKDWORD
, 0xf8000000);
1644 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1645 "Delay %d ms for One shot, path B LOK & IQK.\n", 10);
1646 mdelay(IQK_DELAY_TIME
* 10);
1649 regeac
= rtl_get_bbreg(hw
, 0xeac, MASKDWORD
);
1650 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xeac = 0x%x\n", regeac
);
1651 regeb4
= rtl_get_bbreg(hw
, 0xeb4, MASKDWORD
);
1652 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xeb4 = 0x%x\n", regeb4
);
1653 regebc
= rtl_get_bbreg(hw
, 0xebc, MASKDWORD
);
1654 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xebc = 0x%x\n", regebc
);
1655 regec4
= rtl_get_bbreg(hw
, 0xec4, MASKDWORD
);
1656 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xec4 = 0x%x\n", regec4
);
1657 regecc
= rtl_get_bbreg(hw
, 0xecc, MASKDWORD
);
1658 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xecc = 0x%x\n", regecc
);
1659 if (!(regeac
& BIT(31)) &&
1660 (((regeb4
& 0x03FF0000) >> 16) != 0x142))
1664 if (!(regeac
& BIT(30)) &&
1665 (((regec4
& 0x03FF0000) >> 16) != 0x132)) {
1669 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1670 "Path B Rx IQK fail!!\n");
1675 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
, MASKDWORD
,
1676 rtlphy
->iqk_bb_backup
[0]);
1677 rtl_set_bbreg(hw
, RFPGA0_XB_RFINTERFACEOE
, MASKDWORD
,
1678 rtlphy
->iqk_bb_backup
[2]);
1682 static void _rtl92d_phy_save_adda_registers(struct ieee80211_hw
*hw
,
1683 u32
*adda_reg
, u32
*adda_backup
,
1686 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1689 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Save ADDA parameters.\n");
1690 for (i
= 0; i
< regnum
; i
++)
1691 adda_backup
[i
] = rtl_get_bbreg(hw
, adda_reg
[i
], MASKDWORD
);
1694 static void _rtl92d_phy_save_mac_registers(struct ieee80211_hw
*hw
,
1695 u32
*macreg
, u32
*macbackup
)
1697 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1700 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Save MAC parameters.\n");
1701 for (i
= 0; i
< (IQK_MAC_REG_NUM
- 1); i
++)
1702 macbackup
[i
] = rtl_read_byte(rtlpriv
, macreg
[i
]);
1703 macbackup
[i
] = rtl_read_dword(rtlpriv
, macreg
[i
]);
1706 static void _rtl92d_phy_reload_adda_registers(struct ieee80211_hw
*hw
,
1707 u32
*adda_reg
, u32
*adda_backup
,
1710 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1713 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1714 "Reload ADDA power saving parameters !\n");
1715 for (i
= 0; i
< regnum
; i
++)
1716 rtl_set_bbreg(hw
, adda_reg
[i
], MASKDWORD
, adda_backup
[i
]);
1719 static void _rtl92d_phy_reload_mac_registers(struct ieee80211_hw
*hw
,
1720 u32
*macreg
, u32
*macbackup
)
1722 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1725 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Reload MAC parameters !\n");
1726 for (i
= 0; i
< (IQK_MAC_REG_NUM
- 1); i
++)
1727 rtl_write_byte(rtlpriv
, macreg
[i
], (u8
) macbackup
[i
]);
1728 rtl_write_byte(rtlpriv
, macreg
[i
], macbackup
[i
]);
1731 static void _rtl92d_phy_path_adda_on(struct ieee80211_hw
*hw
,
1732 u32
*adda_reg
, bool patha_on
, bool is2t
)
1734 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1738 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "ADDA ON.\n");
1739 pathon
= patha_on
? 0x04db25a4 : 0x0b1b25a4;
1741 pathon
= rtlpriv
->rtlhal
.interfaceindex
== 0 ?
1742 0x04db25a4 : 0x0b1b25a4;
1743 for (i
= 0; i
< IQK_ADDA_REG_NUM
; i
++)
1744 rtl_set_bbreg(hw
, adda_reg
[i
], MASKDWORD
, pathon
);
1747 static void _rtl92d_phy_mac_setting_calibration(struct ieee80211_hw
*hw
,
1748 u32
*macreg
, u32
*macbackup
)
1750 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1753 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "MAC settings for Calibration.\n");
1754 rtl_write_byte(rtlpriv
, macreg
[0], 0x3F);
1756 for (i
= 1; i
< (IQK_MAC_REG_NUM
- 1); i
++)
1757 rtl_write_byte(rtlpriv
, macreg
[i
], (u8
)(macbackup
[i
] &
1759 rtl_write_byte(rtlpriv
, macreg
[i
], (u8
) (macbackup
[i
] & (~BIT(5))));
1762 static void _rtl92d_phy_patha_standby(struct ieee80211_hw
*hw
)
1764 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1765 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path-A standby mode!\n");
1767 rtl_set_bbreg(hw
, 0xe28, MASKDWORD
, 0x0);
1768 rtl_set_bbreg(hw
, RFPGA0_XA_LSSIPARAMETER
, MASKDWORD
, 0x00010000);
1769 rtl_set_bbreg(hw
, 0xe28, MASKDWORD
, 0x80800000);
1772 static void _rtl92d_phy_pimode_switch(struct ieee80211_hw
*hw
, bool pi_mode
)
1774 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1777 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1778 "BB Switch to %s mode!\n", pi_mode
? "PI" : "SI");
1779 mode
= pi_mode
? 0x01000100 : 0x01000000;
1780 rtl_set_bbreg(hw
, 0x820, MASKDWORD
, mode
);
1781 rtl_set_bbreg(hw
, 0x828, MASKDWORD
, mode
);
1784 static void _rtl92d_phy_iq_calibrate(struct ieee80211_hw
*hw
, long result
[][8],
1787 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1788 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1790 u8 patha_ok
, pathb_ok
;
1791 static u32 adda_reg
[IQK_ADDA_REG_NUM
] = {
1792 RFPGA0_XCD_SWITCHCONTROL
, 0xe6c, 0xe70, 0xe74,
1793 0xe78, 0xe7c, 0xe80, 0xe84,
1794 0xe88, 0xe8c, 0xed0, 0xed4,
1795 0xed8, 0xedc, 0xee0, 0xeec
1797 static u32 iqk_mac_reg
[IQK_MAC_REG_NUM
] = {
1798 0x522, 0x550, 0x551, 0x040
1800 static u32 iqk_bb_reg
[IQK_BB_REG_NUM
] = {
1801 RFPGA0_XAB_RFINTERFACESW
, RFPGA0_XA_RFINTERFACEOE
,
1802 RFPGA0_XB_RFINTERFACEOE
, ROFDM0_TRMUXPAR
,
1803 RFPGA0_XCD_RFINTERFACESW
, ROFDM0_TRXPATHENABLE
,
1804 RFPGA0_RFMOD
, RFPGA0_ANALOGPARAMETER4
,
1805 ROFDM0_XAAGCCORE1
, ROFDM0_XBAGCCORE1
1807 const u32 retrycount
= 2;
1810 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "IQK for 2.4G :Start!!!\n");
1812 bbvalue
= rtl_get_bbreg(hw
, RFPGA0_RFMOD
, MASKDWORD
);
1813 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "==>0x%08x\n", bbvalue
);
1814 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "IQ Calibration for %s\n",
1815 is2t
? "2T2R" : "1T1R");
1817 /* Save ADDA parameters, turn Path A ADDA on */
1818 _rtl92d_phy_save_adda_registers(hw
, adda_reg
,
1819 rtlphy
->adda_backup
, IQK_ADDA_REG_NUM
);
1820 _rtl92d_phy_save_mac_registers(hw
, iqk_mac_reg
,
1821 rtlphy
->iqk_mac_backup
);
1822 _rtl92d_phy_save_adda_registers(hw
, iqk_bb_reg
,
1823 rtlphy
->iqk_bb_backup
, IQK_BB_REG_NUM
);
1825 _rtl92d_phy_path_adda_on(hw
, adda_reg
, true, is2t
);
1827 rtlphy
->rfpi_enable
= (u8
) rtl_get_bbreg(hw
,
1828 RFPGA0_XA_HSSIPARAMETER1
, BIT(8));
1830 /* Switch BB to PI mode to do IQ Calibration. */
1831 if (!rtlphy
->rfpi_enable
)
1832 _rtl92d_phy_pimode_switch(hw
, true);
1834 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BIT(24), 0x00);
1835 rtl_set_bbreg(hw
, ROFDM0_TRXPATHENABLE
, MASKDWORD
, 0x03a05600);
1836 rtl_set_bbreg(hw
, ROFDM0_TRMUXPAR
, MASKDWORD
, 0x000800e4);
1837 rtl_set_bbreg(hw
, RFPGA0_XCD_RFINTERFACESW
, MASKDWORD
, 0x22204000);
1838 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
, 0xf00000, 0x0f);
1840 rtl_set_bbreg(hw
, RFPGA0_XA_LSSIPARAMETER
, MASKDWORD
,
1842 rtl_set_bbreg(hw
, RFPGA0_XB_LSSIPARAMETER
, MASKDWORD
,
1846 _rtl92d_phy_mac_setting_calibration(hw
, iqk_mac_reg
,
1847 rtlphy
->iqk_mac_backup
);
1849 rtl_set_bbreg(hw
, 0xb68, MASKDWORD
, 0x0f600000);
1851 rtl_set_bbreg(hw
, 0xb6c, MASKDWORD
, 0x0f600000);
1852 /* IQ calibration setting */
1853 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "IQK setting!\n");
1854 rtl_set_bbreg(hw
, 0xe28, MASKDWORD
, 0x80800000);
1855 rtl_set_bbreg(hw
, 0xe40, MASKDWORD
, 0x01007c00);
1856 rtl_set_bbreg(hw
, 0xe44, MASKDWORD
, 0x01004800);
1857 for (i
= 0; i
< retrycount
; i
++) {
1858 patha_ok
= _rtl92d_phy_patha_iqk(hw
, is2t
);
1859 if (patha_ok
== 0x03) {
1860 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1861 "Path A IQK Success!!\n");
1862 result
[t
][0] = (rtl_get_bbreg(hw
, 0xe94, MASKDWORD
) &
1864 result
[t
][1] = (rtl_get_bbreg(hw
, 0xe9c, MASKDWORD
) &
1866 result
[t
][2] = (rtl_get_bbreg(hw
, 0xea4, MASKDWORD
) &
1868 result
[t
][3] = (rtl_get_bbreg(hw
, 0xeac, MASKDWORD
) &
1871 } else if (i
== (retrycount
- 1) && patha_ok
== 0x01) {
1873 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1874 "Path A IQK Only Tx Success!!\n");
1876 result
[t
][0] = (rtl_get_bbreg(hw
, 0xe94, MASKDWORD
) &
1878 result
[t
][1] = (rtl_get_bbreg(hw
, 0xe9c, MASKDWORD
) &
1882 if (0x00 == patha_ok
)
1883 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path A IQK failed!!\n");
1885 _rtl92d_phy_patha_standby(hw
);
1886 /* Turn Path B ADDA on */
1887 _rtl92d_phy_path_adda_on(hw
, adda_reg
, false, is2t
);
1888 for (i
= 0; i
< retrycount
; i
++) {
1889 pathb_ok
= _rtl92d_phy_pathb_iqk(hw
);
1890 if (pathb_ok
== 0x03) {
1891 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1892 "Path B IQK Success!!\n");
1893 result
[t
][4] = (rtl_get_bbreg(hw
, 0xeb4,
1894 MASKDWORD
) & 0x3FF0000) >> 16;
1895 result
[t
][5] = (rtl_get_bbreg(hw
, 0xebc,
1896 MASKDWORD
) & 0x3FF0000) >> 16;
1897 result
[t
][6] = (rtl_get_bbreg(hw
, 0xec4,
1898 MASKDWORD
) & 0x3FF0000) >> 16;
1899 result
[t
][7] = (rtl_get_bbreg(hw
, 0xecc,
1900 MASKDWORD
) & 0x3FF0000) >> 16;
1902 } else if (i
== (retrycount
- 1) && pathb_ok
== 0x01) {
1904 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1905 "Path B Only Tx IQK Success!!\n");
1906 result
[t
][4] = (rtl_get_bbreg(hw
, 0xeb4,
1907 MASKDWORD
) & 0x3FF0000) >> 16;
1908 result
[t
][5] = (rtl_get_bbreg(hw
, 0xebc,
1909 MASKDWORD
) & 0x3FF0000) >> 16;
1912 if (0x00 == pathb_ok
)
1913 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1914 "Path B IQK failed!!\n");
1917 /* Back to BB mode, load original value */
1918 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
1919 "IQK:Back to BB mode, load original value!\n");
1921 rtl_set_bbreg(hw
, 0xe28, MASKDWORD
, 0);
1923 /* Switch back BB to SI mode after finish IQ Calibration. */
1924 if (!rtlphy
->rfpi_enable
)
1925 _rtl92d_phy_pimode_switch(hw
, false);
1926 /* Reload ADDA power saving parameters */
1927 _rtl92d_phy_reload_adda_registers(hw
, adda_reg
,
1928 rtlphy
->adda_backup
, IQK_ADDA_REG_NUM
);
1929 /* Reload MAC parameters */
1930 _rtl92d_phy_reload_mac_registers(hw
, iqk_mac_reg
,
1931 rtlphy
->iqk_mac_backup
);
1933 _rtl92d_phy_reload_adda_registers(hw
, iqk_bb_reg
,
1934 rtlphy
->iqk_bb_backup
,
1937 _rtl92d_phy_reload_adda_registers(hw
, iqk_bb_reg
,
1938 rtlphy
->iqk_bb_backup
,
1939 IQK_BB_REG_NUM
- 1);
1940 /* load 0xe30 IQC default value */
1941 rtl_set_bbreg(hw
, 0xe30, MASKDWORD
, 0x01008c00);
1942 rtl_set_bbreg(hw
, 0xe34, MASKDWORD
, 0x01008c00);
1944 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "<==\n");
1947 static void _rtl92d_phy_iq_calibrate_5g_normal(struct ieee80211_hw
*hw
,
1948 long result
[][8], u8 t
)
1950 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1951 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1952 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
1953 u8 patha_ok
, pathb_ok
;
1954 static u32 adda_reg
[IQK_ADDA_REG_NUM
] = {
1955 RFPGA0_XCD_SWITCHCONTROL
, 0xe6c, 0xe70, 0xe74,
1956 0xe78, 0xe7c, 0xe80, 0xe84,
1957 0xe88, 0xe8c, 0xed0, 0xed4,
1958 0xed8, 0xedc, 0xee0, 0xeec
1960 static u32 iqk_mac_reg
[IQK_MAC_REG_NUM
] = {
1961 0x522, 0x550, 0x551, 0x040
1963 static u32 iqk_bb_reg
[IQK_BB_REG_NUM
] = {
1964 RFPGA0_XAB_RFINTERFACESW
, RFPGA0_XA_RFINTERFACEOE
,
1965 RFPGA0_XB_RFINTERFACEOE
, ROFDM0_TRMUXPAR
,
1966 RFPGA0_XCD_RFINTERFACESW
, ROFDM0_TRXPATHENABLE
,
1967 RFPGA0_RFMOD
, RFPGA0_ANALOGPARAMETER4
,
1968 ROFDM0_XAAGCCORE1
, ROFDM0_XBAGCCORE1
1971 bool is2t
= IS_92D_SINGLEPHY(rtlhal
->version
);
1973 /* Note: IQ calibration must be performed after loading
1974 * PHY_REG.txt , and radio_a, radio_b.txt */
1976 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "IQK for 5G NORMAL:Start!!!\n");
1977 mdelay(IQK_DELAY_TIME
* 20);
1979 bbvalue
= rtl_get_bbreg(hw
, RFPGA0_RFMOD
, MASKDWORD
);
1980 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "==>0x%08x\n", bbvalue
);
1981 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "IQ Calibration for %s\n",
1982 is2t
? "2T2R" : "1T1R");
1983 /* Save ADDA parameters, turn Path A ADDA on */
1984 _rtl92d_phy_save_adda_registers(hw
, adda_reg
,
1985 rtlphy
->adda_backup
,
1987 _rtl92d_phy_save_mac_registers(hw
, iqk_mac_reg
,
1988 rtlphy
->iqk_mac_backup
);
1990 _rtl92d_phy_save_adda_registers(hw
, iqk_bb_reg
,
1991 rtlphy
->iqk_bb_backup
,
1994 _rtl92d_phy_save_adda_registers(hw
, iqk_bb_reg
,
1995 rtlphy
->iqk_bb_backup
,
1996 IQK_BB_REG_NUM
- 1);
1998 _rtl92d_phy_path_adda_on(hw
, adda_reg
, true, is2t
);
2000 _rtl92d_phy_mac_setting_calibration(hw
, iqk_mac_reg
,
2001 rtlphy
->iqk_mac_backup
);
2003 rtlphy
->rfpi_enable
= (u8
) rtl_get_bbreg(hw
,
2004 RFPGA0_XA_HSSIPARAMETER1
, BIT(8));
2005 /* Switch BB to PI mode to do IQ Calibration. */
2006 if (!rtlphy
->rfpi_enable
)
2007 _rtl92d_phy_pimode_switch(hw
, true);
2008 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BIT(24), 0x00);
2009 rtl_set_bbreg(hw
, ROFDM0_TRXPATHENABLE
, MASKDWORD
, 0x03a05600);
2010 rtl_set_bbreg(hw
, ROFDM0_TRMUXPAR
, MASKDWORD
, 0x000800e4);
2011 rtl_set_bbreg(hw
, RFPGA0_XCD_RFINTERFACESW
, MASKDWORD
, 0x22208000);
2012 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
, 0xf00000, 0x0f);
2015 rtl_set_bbreg(hw
, 0xb68, MASKDWORD
, 0x0f600000);
2017 rtl_set_bbreg(hw
, 0xb6c, MASKDWORD
, 0x0f600000);
2018 /* IQ calibration setting */
2019 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "IQK setting!\n");
2020 rtl_set_bbreg(hw
, 0xe28, MASKDWORD
, 0x80800000);
2021 rtl_set_bbreg(hw
, 0xe40, MASKDWORD
, 0x10007c00);
2022 rtl_set_bbreg(hw
, 0xe44, MASKDWORD
, 0x01004800);
2023 patha_ok
= _rtl92d_phy_patha_iqk_5g_normal(hw
, is2t
);
2024 if (patha_ok
== 0x03) {
2025 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path A IQK Success!!\n");
2026 result
[t
][0] = (rtl_get_bbreg(hw
, 0xe94, MASKDWORD
) &
2028 result
[t
][1] = (rtl_get_bbreg(hw
, 0xe9c, MASKDWORD
) &
2030 result
[t
][2] = (rtl_get_bbreg(hw
, 0xea4, MASKDWORD
) &
2032 result
[t
][3] = (rtl_get_bbreg(hw
, 0xeac, MASKDWORD
) &
2034 } else if (patha_ok
== 0x01) { /* Tx IQK OK */
2035 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2036 "Path A IQK Only Tx Success!!\n");
2038 result
[t
][0] = (rtl_get_bbreg(hw
, 0xe94, MASKDWORD
) &
2040 result
[t
][1] = (rtl_get_bbreg(hw
, 0xe9c, MASKDWORD
) &
2043 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path A IQK Fail!!\n");
2046 /* _rtl92d_phy_patha_standby(hw); */
2047 /* Turn Path B ADDA on */
2048 _rtl92d_phy_path_adda_on(hw
, adda_reg
, false, is2t
);
2049 pathb_ok
= _rtl92d_phy_pathb_iqk_5g_normal(hw
);
2050 if (pathb_ok
== 0x03) {
2051 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2052 "Path B IQK Success!!\n");
2053 result
[t
][4] = (rtl_get_bbreg(hw
, 0xeb4, MASKDWORD
) &
2055 result
[t
][5] = (rtl_get_bbreg(hw
, 0xebc, MASKDWORD
) &
2057 result
[t
][6] = (rtl_get_bbreg(hw
, 0xec4, MASKDWORD
) &
2059 result
[t
][7] = (rtl_get_bbreg(hw
, 0xecc, MASKDWORD
) &
2061 } else if (pathb_ok
== 0x01) { /* Tx IQK OK */
2062 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2063 "Path B Only Tx IQK Success!!\n");
2064 result
[t
][4] = (rtl_get_bbreg(hw
, 0xeb4, MASKDWORD
) &
2066 result
[t
][5] = (rtl_get_bbreg(hw
, 0xebc, MASKDWORD
) &
2069 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2070 "Path B IQK failed!!\n");
2074 /* Back to BB mode, load original value */
2075 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2076 "IQK:Back to BB mode, load original value!\n");
2077 rtl_set_bbreg(hw
, 0xe28, MASKDWORD
, 0);
2080 _rtl92d_phy_reload_adda_registers(hw
, iqk_bb_reg
,
2081 rtlphy
->iqk_bb_backup
,
2084 _rtl92d_phy_reload_adda_registers(hw
, iqk_bb_reg
,
2085 rtlphy
->iqk_bb_backup
,
2086 IQK_BB_REG_NUM
- 1);
2087 /* Reload MAC parameters */
2088 _rtl92d_phy_reload_mac_registers(hw
, iqk_mac_reg
,
2089 rtlphy
->iqk_mac_backup
);
2090 /* Switch back BB to SI mode after finish IQ Calibration. */
2091 if (!rtlphy
->rfpi_enable
)
2092 _rtl92d_phy_pimode_switch(hw
, false);
2093 /* Reload ADDA power saving parameters */
2094 _rtl92d_phy_reload_adda_registers(hw
, adda_reg
,
2095 rtlphy
->adda_backup
,
2098 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "<==\n");
2101 static bool _rtl92d_phy_simularity_compare(struct ieee80211_hw
*hw
,
2102 long result
[][8], u8 c1
, u8 c2
)
2104 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2105 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
2106 u32 i
, j
, diff
, sim_bitmap
, bound
;
2107 u8 final_candidate
[2] = {0xFF, 0xFF}; /* for path A and path B */
2108 bool bresult
= true;
2109 bool is2t
= IS_92D_SINGLEPHY(rtlhal
->version
);
2116 for (i
= 0; i
< bound
; i
++) {
2117 diff
= (result
[c1
][i
] > result
[c2
][i
]) ? (result
[c1
][i
] -
2118 result
[c2
][i
]) : (result
[c2
][i
] - result
[c1
][i
]);
2119 if (diff
> MAX_TOLERANCE_92D
) {
2120 if ((i
== 2 || i
== 6) && !sim_bitmap
) {
2121 if (result
[c1
][i
] + result
[c1
][i
+ 1] == 0)
2122 final_candidate
[(i
/ 4)] = c2
;
2123 else if (result
[c2
][i
] + result
[c2
][i
+ 1] == 0)
2124 final_candidate
[(i
/ 4)] = c1
;
2126 sim_bitmap
= sim_bitmap
| (1 << i
);
2128 sim_bitmap
= sim_bitmap
| (1 << i
);
2132 if (sim_bitmap
== 0) {
2133 for (i
= 0; i
< (bound
/ 4); i
++) {
2134 if (final_candidate
[i
] != 0xFF) {
2135 for (j
= i
* 4; j
< (i
+ 1) * 4 - 2; j
++)
2137 result
[final_candidate
[i
]][j
];
2143 if (!(sim_bitmap
& 0x0F)) { /* path A OK */
2144 for (i
= 0; i
< 4; i
++)
2145 result
[3][i
] = result
[c1
][i
];
2146 } else if (!(sim_bitmap
& 0x03)) { /* path A, Tx OK */
2147 for (i
= 0; i
< 2; i
++)
2148 result
[3][i
] = result
[c1
][i
];
2150 if (!(sim_bitmap
& 0xF0) && is2t
) { /* path B OK */
2151 for (i
= 4; i
< 8; i
++)
2152 result
[3][i
] = result
[c1
][i
];
2153 } else if (!(sim_bitmap
& 0x30)) { /* path B, Tx OK */
2154 for (i
= 4; i
< 6; i
++)
2155 result
[3][i
] = result
[c1
][i
];
2160 static void _rtl92d_phy_patha_fill_iqk_matrix(struct ieee80211_hw
*hw
,
2161 bool iqk_ok
, long result
[][8],
2162 u8 final_candidate
, bool txonly
)
2164 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2165 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
2166 u32 oldval_0
, val_x
, tx0_a
, reg
;
2168 bool is2t
= IS_92D_SINGLEPHY(rtlhal
->version
) ||
2169 rtlhal
->macphymode
== DUALMAC_DUALPHY
;
2171 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2172 "Path A IQ Calibration %s !\n", iqk_ok
? "Success" : "Failed");
2173 if (final_candidate
== 0xFF) {
2175 } else if (iqk_ok
) {
2176 oldval_0
= (rtl_get_bbreg(hw
, ROFDM0_XATxIQIMBALANCE
,
2177 MASKDWORD
) >> 22) & 0x3FF; /* OFDM0_D */
2178 val_x
= result
[final_candidate
][0];
2179 if ((val_x
& 0x00000200) != 0)
2180 val_x
= val_x
| 0xFFFFFC00;
2181 tx0_a
= (val_x
* oldval_0
) >> 8;
2182 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2183 "X = 0x%x, tx0_a = 0x%x, oldval_0 0x%x\n",
2184 val_x
, tx0_a
, oldval_0
);
2185 rtl_set_bbreg(hw
, ROFDM0_XATxIQIMBALANCE
, 0x3FF, tx0_a
);
2186 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
, BIT(24),
2187 ((val_x
* oldval_0
>> 7) & 0x1));
2188 val_y
= result
[final_candidate
][1];
2189 if ((val_y
& 0x00000200) != 0)
2190 val_y
= val_y
| 0xFFFFFC00;
2191 /* path B IQK result + 3 */
2192 if (rtlhal
->interfaceindex
== 1 &&
2193 rtlhal
->current_bandtype
== BAND_ON_5G
)
2195 tx0_c
= (val_y
* oldval_0
) >> 8;
2196 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2197 "Y = 0x%lx, tx0_c = 0x%lx\n",
2199 rtl_set_bbreg(hw
, ROFDM0_XCTxAFE
, 0xF0000000,
2200 ((tx0_c
& 0x3C0) >> 6));
2201 rtl_set_bbreg(hw
, ROFDM0_XATxIQIMBALANCE
, 0x003F0000,
2204 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
, BIT(26),
2205 ((val_y
* oldval_0
>> 7) & 0x1));
2206 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "0xC80 = 0x%x\n",
2207 rtl_get_bbreg(hw
, ROFDM0_XATxIQIMBALANCE
,
2210 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "only Tx OK\n");
2213 reg
= result
[final_candidate
][2];
2214 rtl_set_bbreg(hw
, ROFDM0_XARXIQIMBALANCE
, 0x3FF, reg
);
2215 reg
= result
[final_candidate
][3] & 0x3F;
2216 rtl_set_bbreg(hw
, ROFDM0_XARXIQIMBALANCE
, 0xFC00, reg
);
2217 reg
= (result
[final_candidate
][3] >> 6) & 0xF;
2218 rtl_set_bbreg(hw
, 0xca0, 0xF0000000, reg
);
2222 static void _rtl92d_phy_pathb_fill_iqk_matrix(struct ieee80211_hw
*hw
,
2223 bool iqk_ok
, long result
[][8], u8 final_candidate
, bool txonly
)
2225 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2226 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
2227 u32 oldval_1
, val_x
, tx1_a
, reg
;
2230 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Path B IQ Calibration %s !\n",
2231 iqk_ok
? "Success" : "Failed");
2232 if (final_candidate
== 0xFF) {
2234 } else if (iqk_ok
) {
2235 oldval_1
= (rtl_get_bbreg(hw
, ROFDM0_XBTxIQIMBALANCE
,
2236 MASKDWORD
) >> 22) & 0x3FF;
2237 val_x
= result
[final_candidate
][4];
2238 if ((val_x
& 0x00000200) != 0)
2239 val_x
= val_x
| 0xFFFFFC00;
2240 tx1_a
= (val_x
* oldval_1
) >> 8;
2241 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "X = 0x%x, tx1_a = 0x%x\n",
2243 rtl_set_bbreg(hw
, ROFDM0_XBTxIQIMBALANCE
, 0x3FF, tx1_a
);
2244 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
, BIT(28),
2245 ((val_x
* oldval_1
>> 7) & 0x1));
2246 val_y
= result
[final_candidate
][5];
2247 if ((val_y
& 0x00000200) != 0)
2248 val_y
= val_y
| 0xFFFFFC00;
2249 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
2251 tx1_c
= (val_y
* oldval_1
) >> 8;
2252 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "Y = 0x%lx, tx1_c = 0x%lx\n",
2254 rtl_set_bbreg(hw
, ROFDM0_XDTxAFE
, 0xF0000000,
2255 ((tx1_c
& 0x3C0) >> 6));
2256 rtl_set_bbreg(hw
, ROFDM0_XBTxIQIMBALANCE
, 0x003F0000,
2258 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
, BIT(30),
2259 ((val_y
* oldval_1
>> 7) & 0x1));
2262 reg
= result
[final_candidate
][6];
2263 rtl_set_bbreg(hw
, ROFDM0_XBRXIQIMBALANCE
, 0x3FF, reg
);
2264 reg
= result
[final_candidate
][7] & 0x3F;
2265 rtl_set_bbreg(hw
, ROFDM0_XBRXIQIMBALANCE
, 0xFC00, reg
);
2266 reg
= (result
[final_candidate
][7] >> 6) & 0xF;
2267 rtl_set_bbreg(hw
, ROFDM0_AGCRSSITABLE
, 0x0000F000, reg
);
2271 void rtl92d_phy_iq_calibrate(struct ieee80211_hw
*hw
)
2273 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2274 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2275 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
2277 u8 i
, final_candidate
, indexforchannel
;
2278 bool patha_ok
, pathb_ok
;
2279 long rege94
, rege9c
, regea4
, regeac
, regeb4
;
2280 long regebc
, regec4
, regecc
, regtmp
= 0;
2281 bool is12simular
, is13simular
, is23simular
;
2282 unsigned long flag
= 0;
2284 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2285 "IQK:Start!!!channel %d\n", rtlphy
->current_channel
);
2286 for (i
= 0; i
< 8; i
++) {
2292 final_candidate
= 0xff;
2295 is12simular
= false;
2296 is23simular
= false;
2297 is13simular
= false;
2298 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2299 "IQK !!!currentband %d\n", rtlhal
->current_bandtype
);
2300 rtl92d_acquire_cckandrw_pagea_ctl(hw
, &flag
);
2301 for (i
= 0; i
< 3; i
++) {
2302 if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
2303 _rtl92d_phy_iq_calibrate_5g_normal(hw
, result
, i
);
2304 } else if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
2305 if (IS_92D_SINGLEPHY(rtlhal
->version
))
2306 _rtl92d_phy_iq_calibrate(hw
, result
, i
, true);
2308 _rtl92d_phy_iq_calibrate(hw
, result
, i
, false);
2311 is12simular
= _rtl92d_phy_simularity_compare(hw
, result
,
2314 final_candidate
= 0;
2319 is13simular
= _rtl92d_phy_simularity_compare(hw
, result
,
2322 final_candidate
= 0;
2325 is23simular
= _rtl92d_phy_simularity_compare(hw
, result
,
2328 final_candidate
= 1;
2330 for (i
= 0; i
< 8; i
++)
2331 regtmp
+= result
[3][i
];
2334 final_candidate
= 3;
2336 final_candidate
= 0xFF;
2340 rtl92d_release_cckandrw_pagea_ctl(hw
, &flag
);
2341 for (i
= 0; i
< 4; i
++) {
2342 rege94
= result
[i
][0];
2343 rege9c
= result
[i
][1];
2344 regea4
= result
[i
][2];
2345 regeac
= result
[i
][3];
2346 regeb4
= result
[i
][4];
2347 regebc
= result
[i
][5];
2348 regec4
= result
[i
][6];
2349 regecc
= result
[i
][7];
2350 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2351 "IQK: rege94=%lx rege9c=%lx regea4=%lx regeac=%lx regeb4=%lx regebc=%lx regec4=%lx regecc=%lx\n",
2352 rege94
, rege9c
, regea4
, regeac
, regeb4
, regebc
, regec4
,
2355 if (final_candidate
!= 0xff) {
2356 rtlphy
->reg_e94
= rege94
= result
[final_candidate
][0];
2357 rtlphy
->reg_e9c
= rege9c
= result
[final_candidate
][1];
2358 regea4
= result
[final_candidate
][2];
2359 regeac
= result
[final_candidate
][3];
2360 rtlphy
->reg_eb4
= regeb4
= result
[final_candidate
][4];
2361 rtlphy
->reg_ebc
= regebc
= result
[final_candidate
][5];
2362 regec4
= result
[final_candidate
][6];
2363 regecc
= result
[final_candidate
][7];
2364 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2365 "IQK: final_candidate is %x\n", final_candidate
);
2366 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2367 "IQK: rege94=%lx rege9c=%lx regea4=%lx regeac=%lx regeb4=%lx regebc=%lx regec4=%lx regecc=%lx\n",
2368 rege94
, rege9c
, regea4
, regeac
, regeb4
, regebc
, regec4
,
2370 patha_ok
= pathb_ok
= true;
2372 rtlphy
->reg_e94
= rtlphy
->reg_eb4
= 0x100; /* X default value */
2373 rtlphy
->reg_e9c
= rtlphy
->reg_ebc
= 0x0; /* Y default value */
2375 if ((rege94
!= 0) /*&&(regea4 != 0) */)
2376 _rtl92d_phy_patha_fill_iqk_matrix(hw
, patha_ok
, result
,
2377 final_candidate
, (regea4
== 0));
2378 if (IS_92D_SINGLEPHY(rtlhal
->version
)) {
2379 if ((regeb4
!= 0) /*&&(regec4 != 0) */)
2380 _rtl92d_phy_pathb_fill_iqk_matrix(hw
, pathb_ok
, result
,
2381 final_candidate
, (regec4
== 0));
2383 if (final_candidate
!= 0xFF) {
2384 indexforchannel
= rtl92d_get_rightchnlplace_for_iqk(
2385 rtlphy
->current_channel
);
2387 for (i
= 0; i
< IQK_MATRIX_REG_NUM
; i
++)
2388 rtlphy
->iqk_matrix
[indexforchannel
].
2389 value
[0][i
] = result
[final_candidate
][i
];
2390 rtlphy
->iqk_matrix
[indexforchannel
].iqk_done
=
2393 RT_TRACE(rtlpriv
, COMP_SCAN
| COMP_MLME
, DBG_LOUD
,
2394 "IQK OK indexforchannel %d\n", indexforchannel
);
2398 void rtl92d_phy_reload_iqk_setting(struct ieee80211_hw
*hw
, u8 channel
)
2400 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2401 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2402 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
2405 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "channel %d\n", channel
);
2406 /*------Do IQK for normal chip and test chip 5G band------- */
2407 indexforchannel
= rtl92d_get_rightchnlplace_for_iqk(channel
);
2408 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "indexforchannel %d done %d\n",
2410 rtlphy
->iqk_matrix
[indexforchannel
].iqk_done
);
2411 if (0 && !rtlphy
->iqk_matrix
[indexforchannel
].iqk_done
&&
2414 RT_TRACE(rtlpriv
, COMP_SCAN
| COMP_INIT
, DBG_LOUD
,
2415 "Do IQK Matrix reg for channel:%d....\n", channel
);
2416 rtl92d_phy_iq_calibrate(hw
);
2418 /* Just load the value. */
2419 /* 2G band just load once. */
2420 if (((!rtlhal
->load_imrandiqk_setting_for2g
) &&
2421 indexforchannel
== 0) || indexforchannel
> 0) {
2422 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_LOUD
,
2423 "Just Read IQK Matrix reg for channel:%d....\n",
2425 if ((rtlphy
->iqk_matrix
[indexforchannel
].
2427 /*&&(regea4 != 0) */)
2428 _rtl92d_phy_patha_fill_iqk_matrix(hw
, true,
2430 indexforchannel
].value
, 0,
2431 (rtlphy
->iqk_matrix
[
2432 indexforchannel
].value
[0][2] == 0));
2433 if (IS_92D_SINGLEPHY(rtlhal
->version
)) {
2434 if ((rtlphy
->iqk_matrix
[
2435 indexforchannel
].value
[0][4] != 0)
2436 /*&&(regec4 != 0) */)
2437 _rtl92d_phy_pathb_fill_iqk_matrix(hw
,
2440 indexforchannel
].value
, 0,
2441 (rtlphy
->iqk_matrix
[
2442 indexforchannel
].value
[0][6]
2447 rtlphy
->need_iqk
= false;
2448 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "<====\n");
2451 static u32
_rtl92d_phy_get_abs(u32 val1
, u32 val2
)
2462 static bool _rtl92d_is_legal_5g_channel(struct ieee80211_hw
*hw
, u8 channel
)
2467 for (i
= 0; i
< sizeof(channel5g
); i
++)
2468 if (channel
== channel5g
[i
])
2473 static void _rtl92d_phy_calc_curvindex(struct ieee80211_hw
*hw
,
2474 u32
*targetchnl
, u32
* curvecount_val
,
2475 bool is5g
, u32
*curveindex
)
2477 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2478 u32 smallest_abs_val
= 0xffffffff, u4tmp
;
2480 u8 chnl_num
= is5g
? TARGET_CHNL_NUM_5G
: TARGET_CHNL_NUM_2G
;
2482 for (i
= 0; i
< chnl_num
; i
++) {
2483 if (is5g
&& !_rtl92d_is_legal_5g_channel(hw
, i
+ 1))
2486 for (j
= 0; j
< (CV_CURVE_CNT
* 2); j
++) {
2487 u4tmp
= _rtl92d_phy_get_abs(targetchnl
[i
],
2490 if (u4tmp
< smallest_abs_val
) {
2492 smallest_abs_val
= u4tmp
;
2495 smallest_abs_val
= 0xffffffff;
2496 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "curveindex[%d] = %x\n",
2501 static void _rtl92d_phy_reload_lck_setting(struct ieee80211_hw
*hw
,
2504 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2505 u8 erfpath
= rtlpriv
->rtlhal
.current_bandtype
==
2506 BAND_ON_5G
? RF90_PATH_A
:
2507 IS_92D_SINGLEPHY(rtlpriv
->rtlhal
.version
) ?
2508 RF90_PATH_B
: RF90_PATH_A
;
2509 u32 u4tmp
= 0, u4regvalue
= 0;
2510 bool bneed_powerdown_radio
= false;
2512 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "path %d\n", erfpath
);
2513 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "band type = %d\n",
2514 rtlpriv
->rtlhal
.current_bandtype
);
2515 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "channel = %d\n", channel
);
2516 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_5G
) {/* Path-A for 5G */
2517 u4tmp
= curveindex_5g
[channel
-1];
2518 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2519 "ver 1 set RF-A, 5G, 0x28 = 0x%x !!\n", u4tmp
);
2520 if (rtlpriv
->rtlhal
.macphymode
== DUALMAC_DUALPHY
&&
2521 rtlpriv
->rtlhal
.interfaceindex
== 1) {
2522 bneed_powerdown_radio
=
2523 rtl92d_phy_enable_anotherphy(hw
, false);
2524 rtlpriv
->rtlhal
.during_mac1init_radioa
= true;
2525 /* asume no this case */
2526 if (bneed_powerdown_radio
)
2527 _rtl92d_phy_enable_rf_env(hw
, erfpath
,
2530 rtl_set_rfreg(hw
, erfpath
, RF_SYN_G4
, 0x3f800, u4tmp
);
2531 if (bneed_powerdown_radio
)
2532 _rtl92d_phy_restore_rf_env(hw
, erfpath
, &u4regvalue
);
2533 if (rtlpriv
->rtlhal
.during_mac1init_radioa
)
2534 rtl92d_phy_powerdown_anotherphy(hw
, false);
2535 } else if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
) {
2536 u4tmp
= curveindex_2g
[channel
-1];
2537 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2538 "ver 3 set RF-B, 2G, 0x28 = 0x%x !!\n", u4tmp
);
2539 if (rtlpriv
->rtlhal
.macphymode
== DUALMAC_DUALPHY
&&
2540 rtlpriv
->rtlhal
.interfaceindex
== 0) {
2541 bneed_powerdown_radio
=
2542 rtl92d_phy_enable_anotherphy(hw
, true);
2543 rtlpriv
->rtlhal
.during_mac0init_radiob
= true;
2544 if (bneed_powerdown_radio
)
2545 _rtl92d_phy_enable_rf_env(hw
, erfpath
,
2548 rtl_set_rfreg(hw
, erfpath
, RF_SYN_G4
, 0x3f800, u4tmp
);
2549 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2550 "ver 3 set RF-B, 2G, 0x28 = 0x%x !!\n",
2551 rtl_get_rfreg(hw
, erfpath
, RF_SYN_G4
, 0x3f800));
2552 if (bneed_powerdown_radio
)
2553 _rtl92d_phy_restore_rf_env(hw
, erfpath
, &u4regvalue
);
2554 if (rtlpriv
->rtlhal
.during_mac0init_radiob
)
2555 rtl92d_phy_powerdown_anotherphy(hw
, true);
2557 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_LOUD
, "<====\n");
2560 static void _rtl92d_phy_lc_calibrate_sw(struct ieee80211_hw
*hw
, bool is2t
)
2562 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2563 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
2564 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2565 u8 tmpreg
, index
, rf_mode
[2];
2566 u8 path
= is2t
? 2 : 1;
2569 u32 curvecount_val
[CV_CURVE_CNT
* 2] = {0};
2570 u16 timeout
= 800, timecount
= 0;
2572 /* Check continuous TX and Packet TX */
2573 tmpreg
= rtl_read_byte(rtlpriv
, 0xd03);
2574 /* if Deal with contisuous TX case, disable all continuous TX */
2575 /* if Deal with Packet TX case, block all queues */
2576 if ((tmpreg
& 0x70) != 0)
2577 rtl_write_byte(rtlpriv
, 0xd03, tmpreg
& 0x8F);
2579 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0xFF);
2580 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
, 0xF00000, 0x0F);
2581 for (index
= 0; index
< path
; index
++) {
2582 /* 1. Read original RF mode */
2583 offset
= index
== 0 ? ROFDM0_XAAGCCORE1
: ROFDM0_XBAGCCORE1
;
2584 rf_mode
[index
] = rtl_read_byte(rtlpriv
, offset
);
2585 /* 2. Set RF mode = standby mode */
2586 rtl_set_rfreg(hw
, (enum radio_path
)index
, RF_AC
,
2587 RFREG_OFFSET_MASK
, 0x010000);
2588 if (rtlpci
->init_ready
) {
2589 /* switch CV-curve control by LC-calibration */
2590 rtl_set_rfreg(hw
, (enum radio_path
)index
, RF_SYN_G7
,
2592 /* 4. Set LC calibration begin */
2593 rtl_set_rfreg(hw
, (enum radio_path
)index
, RF_CHNLBW
,
2596 u4tmp
= rtl_get_rfreg(hw
, (enum radio_path
)index
, RF_SYN_G6
,
2598 while ((!(u4tmp
& BIT(11))) && timecount
<= timeout
) {
2601 u4tmp
= rtl_get_rfreg(hw
, (enum radio_path
)index
,
2602 RF_SYN_G6
, RFREG_OFFSET_MASK
);
2604 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2605 "PHY_LCK finish delay for %d ms=2\n", timecount
);
2606 u4tmp
= rtl_get_rfreg(hw
, index
, RF_SYN_G4
, RFREG_OFFSET_MASK
);
2607 if (index
== 0 && rtlhal
->interfaceindex
== 0) {
2608 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2609 "path-A / 5G LCK\n");
2611 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2612 "path-B / 2.4G LCK\n");
2614 memset(&curvecount_val
[0], 0, CV_CURVE_CNT
* 2);
2615 /* Set LC calibration off */
2616 rtl_set_rfreg(hw
, (enum radio_path
)index
, RF_CHNLBW
,
2618 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "set RF 0x18[15] = 0\n");
2619 /* save Curve-counting number */
2620 for (i
= 0; i
< CV_CURVE_CNT
; i
++) {
2621 u32 readval
= 0, readval2
= 0;
2622 rtl_set_rfreg(hw
, (enum radio_path
)index
, 0x3F,
2625 rtl_set_rfreg(hw
, (enum radio_path
)index
, 0x4D,
2626 RFREG_OFFSET_MASK
, 0x0);
2627 readval
= rtl_get_rfreg(hw
, (enum radio_path
)index
,
2628 0x4F, RFREG_OFFSET_MASK
);
2629 curvecount_val
[2 * i
+ 1] = (readval
& 0xfffe0) >> 5;
2630 /* reg 0x4f [4:0] */
2631 /* reg 0x50 [19:10] */
2632 readval2
= rtl_get_rfreg(hw
, (enum radio_path
)index
,
2634 curvecount_val
[2 * i
] = (((readval
& 0x1F) << 10) |
2637 if (index
== 0 && rtlhal
->interfaceindex
== 0)
2638 _rtl92d_phy_calc_curvindex(hw
, targetchnl_5g
,
2640 true, curveindex_5g
);
2642 _rtl92d_phy_calc_curvindex(hw
, targetchnl_2g
,
2644 false, curveindex_2g
);
2645 /* switch CV-curve control mode */
2646 rtl_set_rfreg(hw
, (enum radio_path
)index
, RF_SYN_G7
,
2650 /* Restore original situation */
2651 for (index
= 0; index
< path
; index
++) {
2652 offset
= index
== 0 ? ROFDM0_XAAGCCORE1
: ROFDM0_XBAGCCORE1
;
2653 rtl_write_byte(rtlpriv
, offset
, 0x50);
2654 rtl_write_byte(rtlpriv
, offset
, rf_mode
[index
]);
2656 if ((tmpreg
& 0x70) != 0)
2657 rtl_write_byte(rtlpriv
, 0xd03, tmpreg
);
2658 else /*Deal with Packet TX case */
2659 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0x00);
2660 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER4
, 0xF00000, 0x00);
2661 _rtl92d_phy_reload_lck_setting(hw
, rtlpriv
->phy
.current_channel
);
2664 static void _rtl92d_phy_lc_calibrate(struct ieee80211_hw
*hw
, bool is2t
)
2666 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2668 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "cosa PHY_LCK ver=2\n");
2669 _rtl92d_phy_lc_calibrate_sw(hw
, is2t
);
2672 void rtl92d_phy_lc_calibrate(struct ieee80211_hw
*hw
)
2674 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2675 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2676 struct rtl_hal
*rtlhal
= &(rtlpriv
->rtlhal
);
2677 u32 timeout
= 2000, timecount
= 0;
2679 while (rtlpriv
->mac80211
.act_scanning
&& timecount
< timeout
) {
2684 rtlphy
->lck_inprogress
= true;
2685 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2686 "LCK:Start!!! currentband %x delay %d ms\n",
2687 rtlhal
->current_bandtype
, timecount
);
2688 if (IS_92D_SINGLEPHY(rtlhal
->version
)) {
2689 _rtl92d_phy_lc_calibrate(hw
, true);
2692 _rtl92d_phy_lc_calibrate(hw
, false);
2694 rtlphy
->lck_inprogress
= false;
2695 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
, "LCK:Finish!!!\n");
2698 void rtl92d_phy_ap_calibrate(struct ieee80211_hw
*hw
, char delta
)
2703 static bool _rtl92d_phy_set_sw_chnl_cmdarray(struct swchnlcmd
*cmdtable
,
2704 u32 cmdtableidx
, u32 cmdtablesz
, enum swchnlcmd_id cmdid
,
2705 u32 para1
, u32 para2
, u32 msdelay
)
2707 struct swchnlcmd
*pcmd
;
2709 if (cmdtable
== NULL
) {
2710 RT_ASSERT(false, "cmdtable cannot be NULL\n");
2713 if (cmdtableidx
>= cmdtablesz
)
2716 pcmd
= cmdtable
+ cmdtableidx
;
2717 pcmd
->cmdid
= cmdid
;
2718 pcmd
->para1
= para1
;
2719 pcmd
->para2
= para2
;
2720 pcmd
->msdelay
= msdelay
;
2724 void rtl92d_phy_reset_iqk_result(struct ieee80211_hw
*hw
)
2726 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2727 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2730 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2731 "settings regs %d default regs %d\n",
2732 (int)(sizeof(rtlphy
->iqk_matrix
) /
2733 sizeof(struct iqk_matrix_regs
)),
2734 IQK_MATRIX_REG_NUM
);
2735 /* 0xe94, 0xe9c, 0xea4, 0xeac, 0xeb4, 0xebc, 0xec4, 0xecc */
2736 for (i
= 0; i
< IQK_MATRIX_SETTINGS_NUM
; i
++) {
2737 rtlphy
->iqk_matrix
[i
].value
[0][0] = 0x100;
2738 rtlphy
->iqk_matrix
[i
].value
[0][2] = 0x100;
2739 rtlphy
->iqk_matrix
[i
].value
[0][4] = 0x100;
2740 rtlphy
->iqk_matrix
[i
].value
[0][6] = 0x100;
2741 rtlphy
->iqk_matrix
[i
].value
[0][1] = 0x0;
2742 rtlphy
->iqk_matrix
[i
].value
[0][3] = 0x0;
2743 rtlphy
->iqk_matrix
[i
].value
[0][5] = 0x0;
2744 rtlphy
->iqk_matrix
[i
].value
[0][7] = 0x0;
2745 rtlphy
->iqk_matrix
[i
].iqk_done
= false;
2749 static bool _rtl92d_phy_sw_chnl_step_by_step(struct ieee80211_hw
*hw
,
2750 u8 channel
, u8
*stage
, u8
*step
,
2753 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2754 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2755 struct swchnlcmd precommoncmd
[MAX_PRECMD_CNT
];
2756 u32 precommoncmdcnt
;
2757 struct swchnlcmd postcommoncmd
[MAX_POSTCMD_CNT
];
2758 u32 postcommoncmdcnt
;
2759 struct swchnlcmd rfdependcmd
[MAX_RFDEPENDCMD_CNT
];
2761 struct swchnlcmd
*currentcmd
= NULL
;
2763 u8 num_total_rfpath
= rtlphy
->num_total_rfpath
;
2765 precommoncmdcnt
= 0;
2766 _rtl92d_phy_set_sw_chnl_cmdarray(precommoncmd
, precommoncmdcnt
++,
2768 CMDID_SET_TXPOWEROWER_LEVEL
, 0, 0, 0);
2769 _rtl92d_phy_set_sw_chnl_cmdarray(precommoncmd
, precommoncmdcnt
++,
2770 MAX_PRECMD_CNT
, CMDID_END
, 0, 0, 0);
2771 postcommoncmdcnt
= 0;
2772 _rtl92d_phy_set_sw_chnl_cmdarray(postcommoncmd
, postcommoncmdcnt
++,
2773 MAX_POSTCMD_CNT
, CMDID_END
, 0, 0, 0);
2775 _rtl92d_phy_set_sw_chnl_cmdarray(rfdependcmd
, rfdependcmdcnt
++,
2776 MAX_RFDEPENDCMD_CNT
, CMDID_RF_WRITEREG
,
2777 RF_CHNLBW
, channel
, 0);
2778 _rtl92d_phy_set_sw_chnl_cmdarray(rfdependcmd
, rfdependcmdcnt
++,
2779 MAX_RFDEPENDCMD_CNT
, CMDID_END
,
2785 currentcmd
= &precommoncmd
[*step
];
2788 currentcmd
= &rfdependcmd
[*step
];
2791 currentcmd
= &postcommoncmd
[*step
];
2794 if (currentcmd
->cmdid
== CMDID_END
) {
2795 if ((*stage
) == 2) {
2803 switch (currentcmd
->cmdid
) {
2804 case CMDID_SET_TXPOWEROWER_LEVEL
:
2805 rtl92d_phy_set_txpower_level(hw
, channel
);
2807 case CMDID_WRITEPORT_ULONG
:
2808 rtl_write_dword(rtlpriv
, currentcmd
->para1
,
2811 case CMDID_WRITEPORT_USHORT
:
2812 rtl_write_word(rtlpriv
, currentcmd
->para1
,
2813 (u16
)currentcmd
->para2
);
2815 case CMDID_WRITEPORT_UCHAR
:
2816 rtl_write_byte(rtlpriv
, currentcmd
->para1
,
2817 (u8
)currentcmd
->para2
);
2819 case CMDID_RF_WRITEREG
:
2820 for (rfpath
= 0; rfpath
< num_total_rfpath
; rfpath
++) {
2821 rtlphy
->rfreg_chnlval
[rfpath
] =
2822 ((rtlphy
->rfreg_chnlval
[rfpath
] &
2823 0xffffff00) | currentcmd
->para2
);
2824 if (rtlpriv
->rtlhal
.current_bandtype
==
2826 if (currentcmd
->para2
> 99)
2827 rtlphy
->rfreg_chnlval
[rfpath
] =
2828 rtlphy
->rfreg_chnlval
2829 [rfpath
] | (BIT(18));
2831 rtlphy
->rfreg_chnlval
[rfpath
] =
2832 rtlphy
->rfreg_chnlval
2833 [rfpath
] & (~BIT(18));
2834 rtlphy
->rfreg_chnlval
[rfpath
] |=
2837 rtlphy
->rfreg_chnlval
[rfpath
] &=
2838 ~(BIT(8) | BIT(16) | BIT(18));
2840 rtl_set_rfreg(hw
, (enum radio_path
)rfpath
,
2843 rtlphy
->rfreg_chnlval
[rfpath
]);
2844 _rtl92d_phy_reload_imr_setting(hw
, channel
,
2847 _rtl92d_phy_switch_rf_setting(hw
, channel
);
2848 /* do IQK when all parameters are ready */
2849 rtl92d_phy_reload_iqk_setting(hw
, channel
);
2852 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
2853 "switch case not processed\n");
2858 (*delay
) = currentcmd
->msdelay
;
2863 u8
rtl92d_phy_sw_chnl(struct ieee80211_hw
*hw
)
2865 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2866 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2867 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2869 u32 timeout
= 1000, timecount
= 0;
2870 u8 channel
= rtlphy
->current_channel
;
2873 if (rtlphy
->sw_chnl_inprogress
)
2875 if (rtlphy
->set_bwmode_inprogress
)
2878 if ((is_hal_stop(rtlhal
)) || (RT_CANNOT_IO(hw
))) {
2879 RT_TRACE(rtlpriv
, COMP_CHAN
, DBG_LOUD
,
2880 "sw_chnl_inprogress false driver sleep or unload\n");
2883 while (rtlphy
->lck_inprogress
&& timecount
< timeout
) {
2887 if (rtlhal
->macphymode
== SINGLEMAC_SINGLEPHY
&&
2888 rtlhal
->bandset
== BAND_ON_BOTH
) {
2889 ret_value
= rtl_get_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
,
2891 if (rtlphy
->current_channel
> 14 && !(ret_value
& BIT(0)))
2892 rtl92d_phy_switch_wirelessband(hw
, BAND_ON_5G
);
2893 else if (rtlphy
->current_channel
<= 14 && (ret_value
& BIT(0)))
2894 rtl92d_phy_switch_wirelessband(hw
, BAND_ON_2_4G
);
2896 switch (rtlhal
->current_bandtype
) {
2898 /* Get first channel error when change between
2899 * 5G and 2.4G band. */
2902 RT_ASSERT((channel
> 14), "5G but channel<=14\n");
2905 /* Get first channel error when change between
2906 * 5G and 2.4G band. */
2909 RT_ASSERT((channel
<= 14), "2G but channel>14\n");
2912 RT_ASSERT(false, "Invalid WirelessMode(%#x)!!\n",
2913 rtlpriv
->mac80211
.mode
);
2916 rtlphy
->sw_chnl_inprogress
= true;
2919 rtlphy
->sw_chnl_stage
= 0;
2920 rtlphy
->sw_chnl_step
= 0;
2921 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_TRACE
,
2922 "switch to channel%d\n", rtlphy
->current_channel
);
2925 if (!rtlphy
->sw_chnl_inprogress
)
2927 if (!_rtl92d_phy_sw_chnl_step_by_step(hw
,
2928 rtlphy
->current_channel
,
2929 &rtlphy
->sw_chnl_stage
, &rtlphy
->sw_chnl_step
, &delay
)) {
2935 rtlphy
->sw_chnl_inprogress
= false;
2939 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_TRACE
, "<==\n");
2940 rtlphy
->sw_chnl_inprogress
= false;
2944 static void rtl92d_phy_set_io(struct ieee80211_hw
*hw
)
2946 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2947 struct dig_t
*de_digtable
= &rtlpriv
->dm_digtable
;
2948 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2950 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
,
2951 "--->Cmd(%#x), set_io_inprogress(%d)\n",
2952 rtlphy
->current_io_type
, rtlphy
->set_io_inprogress
);
2953 switch (rtlphy
->current_io_type
) {
2954 case IO_CMD_RESUME_DM_BY_SCAN
:
2955 de_digtable
->cur_igvalue
= rtlphy
->initgain_backup
.xaagccore1
;
2956 rtl92d_dm_write_dig(hw
);
2957 rtl92d_phy_set_txpower_level(hw
, rtlphy
->current_channel
);
2959 case IO_CMD_PAUSE_DM_BY_SCAN
:
2960 rtlphy
->initgain_backup
.xaagccore1
= de_digtable
->cur_igvalue
;
2961 de_digtable
->cur_igvalue
= 0x37;
2962 rtl92d_dm_write_dig(hw
);
2965 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
2966 "switch case not processed\n");
2969 rtlphy
->set_io_inprogress
= false;
2970 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
, "<---(%#x)\n",
2971 rtlphy
->current_io_type
);
2974 bool rtl92d_phy_set_io_cmd(struct ieee80211_hw
*hw
, enum io_type iotype
)
2976 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2977 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2978 bool postprocessing
= false;
2980 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
,
2981 "-->IO Cmd(%#x), set_io_inprogress(%d)\n",
2982 iotype
, rtlphy
->set_io_inprogress
);
2985 case IO_CMD_RESUME_DM_BY_SCAN
:
2986 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
,
2987 "[IO CMD] Resume DM after scan\n");
2988 postprocessing
= true;
2990 case IO_CMD_PAUSE_DM_BY_SCAN
:
2991 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
,
2992 "[IO CMD] Pause DM before scan\n");
2993 postprocessing
= true;
2996 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
2997 "switch case not processed\n");
3001 if (postprocessing
&& !rtlphy
->set_io_inprogress
) {
3002 rtlphy
->set_io_inprogress
= true;
3003 rtlphy
->current_io_type
= iotype
;
3007 rtl92d_phy_set_io(hw
);
3008 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
, "<--IO Type(%#x)\n", iotype
);
3012 static void _rtl92d_phy_set_rfon(struct ieee80211_hw
*hw
)
3014 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3016 /* a. SYS_CLKR 0x08[11] = 1 restore MAC clock */
3017 /* b. SPS_CTRL 0x11[7:0] = 0x2b */
3018 if (rtlpriv
->rtlhal
.macphymode
== SINGLEMAC_SINGLEPHY
)
3019 rtl_write_byte(rtlpriv
, REG_SPS0_CTRL
, 0x2b);
3020 /* c. For PCIE: SYS_FUNC_EN 0x02[7:0] = 0xE3 enable BB TRX function */
3021 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE3);
3022 /* RF_ON_EXCEP(d~g): */
3023 /* d. APSD_CTRL 0x600[7:0] = 0x00 */
3024 rtl_write_byte(rtlpriv
, REG_APSD_CTRL
, 0x00);
3025 /* e. SYS_FUNC_EN 0x02[7:0] = 0xE2 reset BB TRX function again */
3026 /* f. SYS_FUNC_EN 0x02[7:0] = 0xE3 enable BB TRX function*/
3027 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE2);
3028 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE3);
3029 /* g. txpause 0x522[7:0] = 0x00 enable mac tx queue */
3030 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0x00);
3033 static void _rtl92d_phy_set_rfsleep(struct ieee80211_hw
*hw
)
3035 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3039 /* a. TXPAUSE 0x522[7:0] = 0xFF Pause MAC TX queue */
3040 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0xFF);
3041 /* b. RF path 0 offset 0x00 = 0x00 disable RF */
3042 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x00, RFREG_OFFSET_MASK
, 0x00);
3043 /* c. APSD_CTRL 0x600[7:0] = 0x40 */
3044 rtl_write_byte(rtlpriv
, REG_APSD_CTRL
, 0x40);
3045 /* d. APSD_CTRL 0x600[7:0] = 0x00
3046 * APSD_CTRL 0x600[7:0] = 0x00
3047 * RF path 0 offset 0x00 = 0x00
3048 * APSD_CTRL 0x600[7:0] = 0x40
3050 u4btmp
= rtl_get_rfreg(hw
, RF90_PATH_A
, 0, RFREG_OFFSET_MASK
);
3051 while (u4btmp
!= 0 && delay
> 0) {
3052 rtl_write_byte(rtlpriv
, REG_APSD_CTRL
, 0x0);
3053 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x00, RFREG_OFFSET_MASK
, 0x00);
3054 rtl_write_byte(rtlpriv
, REG_APSD_CTRL
, 0x40);
3055 u4btmp
= rtl_get_rfreg(hw
, RF90_PATH_A
, 0, RFREG_OFFSET_MASK
);
3059 /* Jump out the LPS turn off sequence to RF_ON_EXCEP */
3060 rtl_write_byte(rtlpriv
, REG_APSD_CTRL
, 0x00);
3062 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE2);
3063 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE3);
3064 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0x00);
3065 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
3066 "Fail !!! Switch RF timeout\n");
3069 /* e. For PCIE: SYS_FUNC_EN 0x02[7:0] = 0xE2 reset BB TRX function */
3070 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE2);
3071 /* f. SPS_CTRL 0x11[7:0] = 0x22 */
3072 if (rtlpriv
->rtlhal
.macphymode
== SINGLEMAC_SINGLEPHY
)
3073 rtl_write_byte(rtlpriv
, REG_SPS0_CTRL
, 0x22);
3074 /* g. SYS_CLKR 0x08[11] = 0 gated MAC clock */
3077 bool rtl92d_phy_set_rf_power_state(struct ieee80211_hw
*hw
,
3078 enum rf_pwrstate rfpwr_state
)
3081 bool bresult
= true;
3082 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3083 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
3084 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
3085 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
3086 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
3088 struct rtl8192_tx_ring
*ring
= NULL
;
3090 if (rfpwr_state
== ppsc
->rfpwr_state
)
3092 switch (rfpwr_state
) {
3094 if ((ppsc
->rfpwr_state
== ERFOFF
) &&
3095 RT_IN_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
)) {
3097 u32 InitializeCount
= 0;
3100 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
3101 "IPS Set eRf nic enable\n");
3102 rtstatus
= rtl_ps_enable_nic(hw
);
3103 } while (!rtstatus
&& (InitializeCount
< 10));
3105 RT_CLEAR_PS_LEVEL(ppsc
,
3106 RT_RF_OFF_LEVL_HALT_NIC
);
3108 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
3109 "awake, sleeped:%d ms state_inap:%x\n",
3110 jiffies_to_msecs(jiffies
-
3111 ppsc
->last_sleep_jiffies
),
3112 rtlpriv
->psc
.state_inap
);
3113 ppsc
->last_awake_jiffies
= jiffies
;
3114 _rtl92d_phy_set_rfon(hw
);
3117 if (mac
->link_state
== MAC80211_LINKED
)
3118 rtlpriv
->cfg
->ops
->led_control(hw
,
3121 rtlpriv
->cfg
->ops
->led_control(hw
,
3125 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_HALT_NIC
) {
3126 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
3127 "IPS Set eRf nic disable\n");
3128 rtl_ps_disable_nic(hw
);
3129 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
3131 if (ppsc
->rfoff_reason
== RF_CHANGE_BY_IPS
)
3132 rtlpriv
->cfg
->ops
->led_control(hw
,
3135 rtlpriv
->cfg
->ops
->led_control(hw
,
3140 if (ppsc
->rfpwr_state
== ERFOFF
)
3143 for (queue_id
= 0, i
= 0;
3144 queue_id
< RTL_PCI_MAX_TX_QUEUE_COUNT
;) {
3145 ring
= &pcipriv
->dev
.tx_ring
[queue_id
];
3146 if (skb_queue_len(&ring
->queue
) == 0 ||
3147 queue_id
== BEACON_QUEUE
) {
3150 } else if (rtlpci
->pdev
->current_state
!= PCI_D0
) {
3151 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
3152 "eRf Off/Sleep: %d times TcbBusyQueue[%d] !=0 but lower power state!\n",
3156 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
3157 "eRf Off/Sleep: %d times TcbBusyQueue[%d] =%d before doze!\n",
3159 skb_queue_len(&ring
->queue
));
3164 if (i
>= MAX_DOZE_WAITING_TIMES_9x
) {
3165 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
3166 "ERFOFF: %d times TcbBusyQueue[%d] = %d !\n",
3167 MAX_DOZE_WAITING_TIMES_9x
, queue_id
,
3168 skb_queue_len(&ring
->queue
));
3172 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
3173 "Set rfsleep awaked:%d ms\n",
3174 jiffies_to_msecs(jiffies
- ppsc
->last_awake_jiffies
));
3175 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
3176 "sleep awaked:%d ms state_inap:%x\n",
3177 jiffies_to_msecs(jiffies
-
3178 ppsc
->last_awake_jiffies
),
3179 rtlpriv
->psc
.state_inap
);
3180 ppsc
->last_sleep_jiffies
= jiffies
;
3181 _rtl92d_phy_set_rfsleep(hw
);
3184 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
3185 "switch case not processed\n");
3190 ppsc
->rfpwr_state
= rfpwr_state
;
3194 void rtl92d_phy_config_macphymode(struct ieee80211_hw
*hw
)
3196 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3197 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3198 u8 offset
= REG_MAC_PHY_CTRL_NORMAL
;
3200 switch (rtlhal
->macphymode
) {
3201 case DUALMAC_DUALPHY
:
3202 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3203 "MacPhyMode: DUALMAC_DUALPHY\n");
3204 rtl_write_byte(rtlpriv
, offset
, 0xF3);
3206 case SINGLEMAC_SINGLEPHY
:
3207 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3208 "MacPhyMode: SINGLEMAC_SINGLEPHY\n");
3209 rtl_write_byte(rtlpriv
, offset
, 0xF4);
3211 case DUALMAC_SINGLEPHY
:
3212 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3213 "MacPhyMode: DUALMAC_SINGLEPHY\n");
3214 rtl_write_byte(rtlpriv
, offset
, 0xF1);
3219 void rtl92d_phy_config_macphymode_info(struct ieee80211_hw
*hw
)
3221 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3222 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3223 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
3225 switch (rtlhal
->macphymode
) {
3226 case DUALMAC_SINGLEPHY
:
3227 rtlphy
->rf_type
= RF_2T2R
;
3228 rtlhal
->version
|= RF_TYPE_2T2R
;
3229 rtlhal
->bandset
= BAND_ON_BOTH
;
3230 rtlhal
->current_bandtype
= BAND_ON_2_4G
;
3233 case SINGLEMAC_SINGLEPHY
:
3234 rtlphy
->rf_type
= RF_2T2R
;
3235 rtlhal
->version
|= RF_TYPE_2T2R
;
3236 rtlhal
->bandset
= BAND_ON_BOTH
;
3237 rtlhal
->current_bandtype
= BAND_ON_2_4G
;
3240 case DUALMAC_DUALPHY
:
3241 rtlphy
->rf_type
= RF_1T1R
;
3242 rtlhal
->version
&= RF_TYPE_1T1R
;
3243 /* Now we let MAC0 run on 5G band. */
3244 if (rtlhal
->interfaceindex
== 0) {
3245 rtlhal
->bandset
= BAND_ON_5G
;
3246 rtlhal
->current_bandtype
= BAND_ON_5G
;
3248 rtlhal
->bandset
= BAND_ON_2_4G
;
3249 rtlhal
->current_bandtype
= BAND_ON_2_4G
;
3257 u8
rtl92d_get_chnlgroup_fromarray(u8 chnl
)
3260 u8 channel_info
[59] = {
3261 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
3262 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56,
3263 58, 60, 62, 64, 100, 102, 104, 106, 108,
3264 110, 112, 114, 116, 118, 120, 122, 124,
3265 126, 128, 130, 132, 134, 136, 138, 140,
3266 149, 151, 153, 155, 157, 159, 161, 163,
3270 if (channel_info
[chnl
] <= 3)
3272 else if (channel_info
[chnl
] <= 9)
3274 else if (channel_info
[chnl
] <= 14)
3276 else if (channel_info
[chnl
] <= 44)
3278 else if (channel_info
[chnl
] <= 54)
3280 else if (channel_info
[chnl
] <= 64)
3282 else if (channel_info
[chnl
] <= 112)
3284 else if (channel_info
[chnl
] <= 126)
3286 else if (channel_info
[chnl
] <= 140)
3288 else if (channel_info
[chnl
] <= 153)
3290 else if (channel_info
[chnl
] <= 159)
3297 void rtl92d_phy_set_poweron(struct ieee80211_hw
*hw
)
3299 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3300 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3301 unsigned long flags
;
3304 u32 mac_reg
= (rtlhal
->interfaceindex
== 0 ? REG_MAC0
: REG_MAC1
);
3306 /* notice fw know band status 0x81[1]/0x53[1] = 0: 5G, 1: 2G */
3307 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
3308 value8
= rtl_read_byte(rtlpriv
, mac_reg
);
3310 rtl_write_byte(rtlpriv
, mac_reg
, value8
);
3312 value8
= rtl_read_byte(rtlpriv
, mac_reg
);
3313 value8
&= (~BIT(1));
3314 rtl_write_byte(rtlpriv
, mac_reg
, value8
);
3317 if (rtlhal
->macphymode
== SINGLEMAC_SINGLEPHY
) {
3318 value8
= rtl_read_byte(rtlpriv
, REG_MAC0
);
3319 rtl_write_byte(rtlpriv
, REG_MAC0
, value8
| MAC0_ON
);
3321 spin_lock_irqsave(&globalmutex_power
, flags
);
3322 if (rtlhal
->interfaceindex
== 0) {
3323 value8
= rtl_read_byte(rtlpriv
, REG_MAC0
);
3324 rtl_write_byte(rtlpriv
, REG_MAC0
, value8
| MAC0_ON
);
3326 value8
= rtl_read_byte(rtlpriv
, REG_MAC1
);
3327 rtl_write_byte(rtlpriv
, REG_MAC1
, value8
| MAC1_ON
);
3329 value8
= rtl_read_byte(rtlpriv
, REG_POWER_OFF_IN_PROCESS
);
3330 spin_unlock_irqrestore(&globalmutex_power
, flags
);
3331 for (i
= 0; i
< 200; i
++) {
3332 if ((value8
& BIT(7)) == 0) {
3336 spin_lock_irqsave(&globalmutex_power
, flags
);
3337 value8
= rtl_read_byte(rtlpriv
,
3338 REG_POWER_OFF_IN_PROCESS
);
3339 spin_unlock_irqrestore(&globalmutex_power
,
3344 RT_ASSERT(false, "Another mac power off over time\n");
3348 void rtl92d_phy_config_maccoexist_rfpage(struct ieee80211_hw
*hw
)
3350 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3352 switch (rtlpriv
->rtlhal
.macphymode
) {
3353 case DUALMAC_DUALPHY
:
3354 rtl_write_byte(rtlpriv
, REG_DMC
, 0x0);
3355 rtl_write_byte(rtlpriv
, REG_RX_PKT_LIMIT
, 0x08);
3356 rtl_write_word(rtlpriv
, REG_TRXFF_BNDY
+ 2, 0x13ff);
3358 case DUALMAC_SINGLEPHY
:
3359 rtl_write_byte(rtlpriv
, REG_DMC
, 0xf8);
3360 rtl_write_byte(rtlpriv
, REG_RX_PKT_LIMIT
, 0x08);
3361 rtl_write_word(rtlpriv
, REG_TRXFF_BNDY
+ 2, 0x13ff);
3363 case SINGLEMAC_SINGLEPHY
:
3364 rtl_write_byte(rtlpriv
, REG_DMC
, 0x0);
3365 rtl_write_byte(rtlpriv
, REG_RX_PKT_LIMIT
, 0x10);
3366 rtl_write_word(rtlpriv
, (REG_TRXFF_BNDY
+ 2), 0x27FF);
3373 void rtl92d_update_bbrf_configuration(struct ieee80211_hw
*hw
)
3375 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3376 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3377 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
3378 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
3381 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "==>\n");
3382 /* r_select_5G for path_A/B 0 for 2.4G, 1 for 5G */
3383 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
3384 /* r_select_5G for path_A/B,0x878 */
3385 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(0), 0x0);
3386 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(15), 0x0);
3387 if (rtlhal
->macphymode
!= DUALMAC_DUALPHY
) {
3388 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(16), 0x0);
3389 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(31), 0x0);
3391 /* rssi_table_select:index 0 for 2.4G.1~3 for 5G,0xc78 */
3392 rtl_set_bbreg(hw
, ROFDM0_AGCRSSITABLE
, BIT(6) | BIT(7), 0x0);
3394 rtl_set_bbreg(hw
, ROFDM1_CFOTRACKING
, BIT(14) | BIT(13), 0x0);
3396 rtl_set_bbreg(hw
, 0xB30, 0x00F00000, 0xa);
3397 /* TX BB gain shift*1,Just for testchip,0xc80,0xc88 */
3398 rtl_set_bbreg(hw
, ROFDM0_XATxIQIMBALANCE
, MASKDWORD
,
3400 rtl_set_bbreg(hw
, ROFDM0_XBTxIQIMBALANCE
, MASKDWORD
,
3402 if (rtlhal
->macphymode
== DUALMAC_DUALPHY
) {
3403 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
,
3404 BIT(10) | BIT(6) | BIT(5),
3405 ((rtlefuse
->eeprom_c9
& BIT(3)) >> 3) |
3406 (rtlefuse
->eeprom_c9
& BIT(1)) |
3407 ((rtlefuse
->eeprom_cc
& BIT(1)) << 4));
3408 rtl_set_bbreg(hw
, RFPGA0_XA_RFINTERFACEOE
,
3409 BIT(10) | BIT(6) | BIT(5),
3410 ((rtlefuse
->eeprom_c9
& BIT(2)) >> 2) |
3411 ((rtlefuse
->eeprom_c9
& BIT(0)) << 1) |
3412 ((rtlefuse
->eeprom_cc
& BIT(0)) << 5));
3413 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(15), 0);
3415 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
,
3416 BIT(26) | BIT(22) | BIT(21) | BIT(10) |
3418 ((rtlefuse
->eeprom_c9
& BIT(3)) >> 3) |
3419 (rtlefuse
->eeprom_c9
& BIT(1)) |
3420 ((rtlefuse
->eeprom_cc
& BIT(1)) << 4) |
3421 ((rtlefuse
->eeprom_c9
& BIT(7)) << 9) |
3422 ((rtlefuse
->eeprom_c9
& BIT(5)) << 12) |
3423 ((rtlefuse
->eeprom_cc
& BIT(3)) << 18));
3424 rtl_set_bbreg(hw
, RFPGA0_XA_RFINTERFACEOE
,
3425 BIT(10) | BIT(6) | BIT(5),
3426 ((rtlefuse
->eeprom_c9
& BIT(2)) >> 2) |
3427 ((rtlefuse
->eeprom_c9
& BIT(0)) << 1) |
3428 ((rtlefuse
->eeprom_cc
& BIT(0)) << 5));
3429 rtl_set_bbreg(hw
, RFPGA0_XB_RFINTERFACEOE
,
3430 BIT(10) | BIT(6) | BIT(5),
3431 ((rtlefuse
->eeprom_c9
& BIT(6)) >> 6) |
3432 ((rtlefuse
->eeprom_c9
& BIT(4)) >> 3) |
3433 ((rtlefuse
->eeprom_cc
& BIT(2)) << 3));
3434 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
,
3435 BIT(31) | BIT(15), 0);
3439 /* r_select_5G for path_A/B */
3440 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(0), 0x1);
3441 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(15), 0x1);
3442 if (rtlhal
->macphymode
!= DUALMAC_DUALPHY
) {
3443 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(16), 0x1);
3444 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(31), 0x1);
3446 /* rssi_table_select:index 0 for 2.4G.1~3 for 5G */
3447 rtl_set_bbreg(hw
, ROFDM0_AGCRSSITABLE
, BIT(6) | BIT(7), 0x1);
3449 rtl_set_bbreg(hw
, ROFDM1_CFOTRACKING
, BIT(14) | BIT(13), 0x1);
3451 rtl_set_bbreg(hw
, 0xB30, 0x00F00000, 0x0);
3452 /* TX BB gain shift,Just for testchip,0xc80,0xc88 */
3453 if (rtlefuse
->internal_pa_5g
[0])
3454 rtl_set_bbreg(hw
, ROFDM0_XATxIQIMBALANCE
, MASKDWORD
,
3457 rtl_set_bbreg(hw
, ROFDM0_XATxIQIMBALANCE
, MASKDWORD
,
3459 if (rtlefuse
->internal_pa_5g
[1])
3460 rtl_set_bbreg(hw
, ROFDM0_XBTxIQIMBALANCE
, MASKDWORD
,
3463 rtl_set_bbreg(hw
, ROFDM0_XBTxIQIMBALANCE
, MASKDWORD
,
3465 if (rtlhal
->macphymode
== DUALMAC_DUALPHY
) {
3466 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
,
3467 BIT(10) | BIT(6) | BIT(5),
3468 (rtlefuse
->eeprom_cc
& BIT(5)));
3469 rtl_set_bbreg(hw
, RFPGA0_XA_RFINTERFACEOE
, BIT(10),
3470 ((rtlefuse
->eeprom_cc
& BIT(4)) >> 4));
3471 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(15),
3472 (rtlefuse
->eeprom_cc
& BIT(4)) >> 4);
3474 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
,
3475 BIT(26) | BIT(22) | BIT(21) | BIT(10) |
3477 (rtlefuse
->eeprom_cc
& BIT(5)) |
3478 ((rtlefuse
->eeprom_cc
& BIT(7)) << 14));
3479 rtl_set_bbreg(hw
, RFPGA0_XA_RFINTERFACEOE
, BIT(10),
3480 ((rtlefuse
->eeprom_cc
& BIT(4)) >> 4));
3481 rtl_set_bbreg(hw
, RFPGA0_XB_RFINTERFACEOE
, BIT(10),
3482 ((rtlefuse
->eeprom_cc
& BIT(6)) >> 6));
3483 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
,
3485 ((rtlefuse
->eeprom_cc
& BIT(4)) >> 4) |
3486 ((rtlefuse
->eeprom_cc
& BIT(6)) << 10));
3489 /* update IQK related settings */
3490 rtl_set_bbreg(hw
, ROFDM0_XARXIQIMBALANCE
, MASKDWORD
, 0x40000100);
3491 rtl_set_bbreg(hw
, ROFDM0_XBRXIQIMBALANCE
, MASKDWORD
, 0x40000100);
3492 rtl_set_bbreg(hw
, ROFDM0_XCTxAFE
, 0xF0000000, 0x00);
3493 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
, BIT(30) | BIT(28) |
3494 BIT(26) | BIT(24), 0x00);
3495 rtl_set_bbreg(hw
, ROFDM0_XDTxAFE
, 0xF0000000, 0x00);
3496 rtl_set_bbreg(hw
, 0xca0, 0xF0000000, 0x00);
3497 rtl_set_bbreg(hw
, ROFDM0_AGCRSSITABLE
, 0x0000F000, 0x00);
3500 for (rfpath
= RF90_PATH_A
; rfpath
< rtlphy
->num_total_rfpath
;
3502 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
3503 /* MOD_AG for RF path_A 0x18 BIT8,BIT16 */
3504 rtl_set_rfreg(hw
, rfpath
, RF_CHNLBW
, BIT(8) | BIT(16) |
3506 /* RF0x0b[16:14] =3b'111 */
3507 rtl_set_rfreg(hw
, (enum radio_path
)rfpath
, 0x0B,
3510 /* MOD_AG for RF path_A 0x18 BIT8,BIT16 */
3511 rtl_set_rfreg(hw
, rfpath
, RF_CHNLBW
, BIT(8) |
3513 (BIT(16) | BIT(8)) >> 8);
3516 /* Update for all band. */
3518 if (rtlphy
->rf_type
== RF_1T1R
) {
3519 /* Use antenna 0,0xc04,0xd04 */
3520 rtl_set_bbreg(hw
, ROFDM0_TRXPATHENABLE
, MASKBYTE0
, 0x11);
3521 rtl_set_bbreg(hw
, ROFDM1_TRXPATHENABLE
, BDWORD
, 0x1);
3523 /* enable ad/da clock1 for dual-phy reg0x888 */
3524 if (rtlhal
->interfaceindex
== 0) {
3525 rtl_set_bbreg(hw
, RFPGA0_ADDALLOCKEN
, BIT(12) |
3528 rtl92d_phy_enable_anotherphy(hw
, false);
3529 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3530 "MAC1 use DBI to update 0x888\n");
3532 rtl92de_write_dword_dbi(hw
, RFPGA0_ADDALLOCKEN
,
3533 rtl92de_read_dword_dbi(hw
,
3535 BIT(3)) | BIT(12) | BIT(13),
3537 rtl92d_phy_powerdown_anotherphy(hw
, false);
3541 /* Use antenna 0 & 1,0xc04,0xd04 */
3542 rtl_set_bbreg(hw
, ROFDM0_TRXPATHENABLE
, MASKBYTE0
, 0x33);
3543 rtl_set_bbreg(hw
, ROFDM1_TRXPATHENABLE
, BDWORD
, 0x3);
3544 /* disable ad/da clock1,0x888 */
3545 rtl_set_bbreg(hw
, RFPGA0_ADDALLOCKEN
, BIT(12) | BIT(13), 0);
3547 for (rfpath
= RF90_PATH_A
; rfpath
< rtlphy
->num_total_rfpath
;
3549 rtlphy
->rfreg_chnlval
[rfpath
] = rtl_get_rfreg(hw
, rfpath
,
3550 RF_CHNLBW
, RFREG_OFFSET_MASK
);
3551 rtlphy
->reg_rf3c
[rfpath
] = rtl_get_rfreg(hw
, rfpath
, 0x3C,
3554 for (i
= 0; i
< 2; i
++)
3555 RT_TRACE(rtlpriv
, COMP_RF
, DBG_LOUD
, "RF 0x18 = 0x%x\n",
3556 rtlphy
->rfreg_chnlval
[i
]);
3557 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "<==\n");
3561 bool rtl92d_phy_check_poweroff(struct ieee80211_hw
*hw
)
3563 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3564 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3566 unsigned long flags
;
3568 if (rtlhal
->macphymode
== SINGLEMAC_SINGLEPHY
) {
3569 u1btmp
= rtl_read_byte(rtlpriv
, REG_MAC0
);
3570 rtl_write_byte(rtlpriv
, REG_MAC0
, u1btmp
& (~MAC0_ON
));
3573 spin_lock_irqsave(&globalmutex_power
, flags
);
3574 if (rtlhal
->interfaceindex
== 0) {
3575 u1btmp
= rtl_read_byte(rtlpriv
, REG_MAC0
);
3576 rtl_write_byte(rtlpriv
, REG_MAC0
, u1btmp
& (~MAC0_ON
));
3577 u1btmp
= rtl_read_byte(rtlpriv
, REG_MAC1
);
3580 u1btmp
= rtl_read_byte(rtlpriv
, REG_MAC1
);
3581 rtl_write_byte(rtlpriv
, REG_MAC1
, u1btmp
& (~MAC1_ON
));
3582 u1btmp
= rtl_read_byte(rtlpriv
, REG_MAC0
);
3586 spin_unlock_irqrestore(&globalmutex_power
, flags
);
3589 u1btmp
= rtl_read_byte(rtlpriv
, REG_POWER_OFF_IN_PROCESS
);
3591 rtl_write_byte(rtlpriv
, REG_POWER_OFF_IN_PROCESS
, u1btmp
);
3592 spin_unlock_irqrestore(&globalmutex_power
, flags
);