1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2013 Realtek Corporation.*/
14 static u32
_rtl88e_phy_rf_serial_read(struct ieee80211_hw
*hw
,
15 enum radio_path rfpath
, u32 offset
);
16 static void _rtl88e_phy_rf_serial_write(struct ieee80211_hw
*hw
,
17 enum radio_path rfpath
, u32 offset
,
19 static u32
_rtl88e_phy_calculate_bit_shift(u32 bitmask
)
23 return i
? i
- 1 : 32;
25 static bool _rtl88e_phy_bb8188e_config_parafile(struct ieee80211_hw
*hw
);
26 static bool _rtl88e_phy_config_mac_with_headerfile(struct ieee80211_hw
*hw
);
27 static bool phy_config_bb_with_headerfile(struct ieee80211_hw
*hw
,
29 static bool phy_config_bb_with_pghdr(struct ieee80211_hw
*hw
,
31 static void _rtl88e_phy_init_bb_rf_register_definition(struct ieee80211_hw
*hw
);
32 static bool _rtl88e_phy_set_sw_chnl_cmdarray(struct swchnlcmd
*cmdtable
,
33 u32 cmdtableidx
, u32 cmdtablesz
,
34 enum swchnlcmd_id cmdid
, u32 para1
,
35 u32 para2
, u32 msdelay
);
36 static bool _rtl88e_phy_sw_chnl_step_by_step(struct ieee80211_hw
*hw
,
37 u8 channel
, u8
*stage
, u8
*step
,
40 static long _rtl88e_phy_txpwr_idx_to_dbm(struct ieee80211_hw
*hw
,
41 enum wireless_mode wirelessmode
,
43 static void rtl88ee_phy_set_rf_on(struct ieee80211_hw
*hw
);
44 static void rtl88e_phy_set_io(struct ieee80211_hw
*hw
);
46 u32
rtl88e_phy_query_bb_reg(struct ieee80211_hw
*hw
, u32 regaddr
, u32 bitmask
)
48 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
49 u32 returnvalue
, originalvalue
, bitshift
;
51 rtl_dbg(rtlpriv
, COMP_RF
, DBG_TRACE
,
52 "regaddr(%#x), bitmask(%#x)\n", regaddr
, bitmask
);
53 originalvalue
= rtl_read_dword(rtlpriv
, regaddr
);
54 bitshift
= _rtl88e_phy_calculate_bit_shift(bitmask
);
55 returnvalue
= (originalvalue
& bitmask
) >> bitshift
;
57 rtl_dbg(rtlpriv
, COMP_RF
, DBG_TRACE
,
58 "BBR MASK=0x%x Addr[0x%x]=0x%x\n", bitmask
,
59 regaddr
, originalvalue
);
65 void rtl88e_phy_set_bb_reg(struct ieee80211_hw
*hw
,
66 u32 regaddr
, u32 bitmask
, u32 data
)
68 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
69 u32 originalvalue
, bitshift
;
71 rtl_dbg(rtlpriv
, COMP_RF
, DBG_TRACE
,
72 "regaddr(%#x), bitmask(%#x), data(%#x)\n",
73 regaddr
, bitmask
, data
);
75 if (bitmask
!= MASKDWORD
) {
76 originalvalue
= rtl_read_dword(rtlpriv
, regaddr
);
77 bitshift
= _rtl88e_phy_calculate_bit_shift(bitmask
);
78 data
= ((originalvalue
& (~bitmask
)) | (data
<< bitshift
));
81 rtl_write_dword(rtlpriv
, regaddr
, data
);
83 rtl_dbg(rtlpriv
, COMP_RF
, DBG_TRACE
,
84 "regaddr(%#x), bitmask(%#x), data(%#x)\n",
85 regaddr
, bitmask
, data
);
88 u32
rtl88e_phy_query_rf_reg(struct ieee80211_hw
*hw
,
89 enum radio_path rfpath
, u32 regaddr
, u32 bitmask
)
91 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
92 u32 original_value
, readback_value
, bitshift
;
94 rtl_dbg(rtlpriv
, COMP_RF
, DBG_TRACE
,
95 "regaddr(%#x), rfpath(%#x), bitmask(%#x)\n",
96 regaddr
, rfpath
, bitmask
);
98 spin_lock(&rtlpriv
->locks
.rf_lock
);
101 original_value
= _rtl88e_phy_rf_serial_read(hw
, rfpath
, regaddr
);
102 bitshift
= _rtl88e_phy_calculate_bit_shift(bitmask
);
103 readback_value
= (original_value
& bitmask
) >> bitshift
;
105 spin_unlock(&rtlpriv
->locks
.rf_lock
);
107 rtl_dbg(rtlpriv
, COMP_RF
, DBG_TRACE
,
108 "regaddr(%#x), rfpath(%#x), bitmask(%#x), original_value(%#x)\n",
109 regaddr
, rfpath
, bitmask
, original_value
);
110 return readback_value
;
113 void rtl88e_phy_set_rf_reg(struct ieee80211_hw
*hw
,
114 enum radio_path rfpath
,
115 u32 regaddr
, u32 bitmask
, u32 data
)
117 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
118 u32 original_value
, bitshift
;
120 rtl_dbg(rtlpriv
, COMP_RF
, DBG_TRACE
,
121 "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
122 regaddr
, bitmask
, data
, rfpath
);
124 spin_lock(&rtlpriv
->locks
.rf_lock
);
126 if (bitmask
!= RFREG_OFFSET_MASK
) {
127 original_value
= _rtl88e_phy_rf_serial_read(hw
,
130 bitshift
= _rtl88e_phy_calculate_bit_shift(bitmask
);
132 ((original_value
& (~bitmask
)) |
136 _rtl88e_phy_rf_serial_write(hw
, rfpath
, regaddr
, data
);
139 spin_unlock(&rtlpriv
->locks
.rf_lock
);
141 rtl_dbg(rtlpriv
, COMP_RF
, DBG_TRACE
,
142 "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
143 regaddr
, bitmask
, data
, rfpath
);
146 static u32
_rtl88e_phy_rf_serial_read(struct ieee80211_hw
*hw
,
147 enum radio_path rfpath
, u32 offset
)
149 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
150 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
151 struct bb_reg_def
*pphyreg
= &rtlphy
->phyreg_def
[rfpath
];
153 u32 tmplong
, tmplong2
;
159 if (RT_CANNOT_IO(hw
)) {
160 pr_err("return all one\n");
163 tmplong
= rtl_get_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER2
, MASKDWORD
);
164 if (rfpath
== RF90_PATH_A
)
167 tmplong2
= rtl_get_bbreg(hw
, pphyreg
->rfhssi_para2
, MASKDWORD
);
168 tmplong2
= (tmplong2
& (~BLSSIREADADDRESS
)) |
169 (newoffset
<< 23) | BLSSIREADEDGE
;
170 rtl_set_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER2
, MASKDWORD
,
171 tmplong
& (~BLSSIREADEDGE
));
173 rtl_set_bbreg(hw
, pphyreg
->rfhssi_para2
, MASKDWORD
, tmplong2
);
175 if (rfpath
== RF90_PATH_A
)
176 rfpi_enable
= (u8
)rtl_get_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER1
,
178 else if (rfpath
== RF90_PATH_B
)
179 rfpi_enable
= (u8
)rtl_get_bbreg(hw
, RFPGA0_XB_HSSIPARAMETER1
,
182 retvalue
= rtl_get_bbreg(hw
, pphyreg
->rf_rbpi
,
185 retvalue
= rtl_get_bbreg(hw
, pphyreg
->rf_rb
,
187 rtl_dbg(rtlpriv
, COMP_RF
, DBG_TRACE
,
188 "RFR-%d Addr[0x%x]=0x%x\n",
189 rfpath
, pphyreg
->rf_rb
, retvalue
);
193 static void _rtl88e_phy_rf_serial_write(struct ieee80211_hw
*hw
,
194 enum radio_path rfpath
, u32 offset
,
199 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
200 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
201 struct bb_reg_def
*pphyreg
= &rtlphy
->phyreg_def
[rfpath
];
203 if (RT_CANNOT_IO(hw
)) {
209 data_and_addr
= ((newoffset
<< 20) | (data
& 0x000fffff)) & 0x0fffffff;
210 rtl_set_bbreg(hw
, pphyreg
->rf3wire_offset
, MASKDWORD
, data_and_addr
);
211 rtl_dbg(rtlpriv
, COMP_RF
, DBG_TRACE
,
212 "RFW-%d Addr[0x%x]=0x%x\n",
213 rfpath
, pphyreg
->rf3wire_offset
, data_and_addr
);
216 bool rtl88e_phy_mac_config(struct ieee80211_hw
*hw
)
218 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
219 bool rtstatus
= _rtl88e_phy_config_mac_with_headerfile(hw
);
221 rtl_write_byte(rtlpriv
, 0x04CA, 0x0B);
225 bool rtl88e_phy_bb_config(struct ieee80211_hw
*hw
)
227 bool rtstatus
= true;
228 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
230 u8 b_reg_hwparafile
= 1;
232 _rtl88e_phy_init_bb_rf_register_definition(hw
);
233 regval
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
);
234 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
,
235 regval
| BIT(13) | BIT(0) | BIT(1));
237 rtl_write_byte(rtlpriv
, REG_RF_CTRL
, RF_EN
| RF_RSTB
| RF_SDMRSTB
);
238 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
,
239 FEN_PPLL
| FEN_PCIEA
| FEN_DIO_PCIE
|
240 FEN_BB_GLB_RSTN
| FEN_BBRSTB
);
241 tmp
= rtl_read_dword(rtlpriv
, 0x4c);
242 rtl_write_dword(rtlpriv
, 0x4c, tmp
| BIT(23));
243 if (b_reg_hwparafile
== 1)
244 rtstatus
= _rtl88e_phy_bb8188e_config_parafile(hw
);
248 bool rtl88e_phy_rf_config(struct ieee80211_hw
*hw
)
250 return rtl88e_phy_rf6052_config(hw
);
253 static bool _rtl88e_check_condition(struct ieee80211_hw
*hw
,
256 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
257 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
258 u32 _board
= rtlefuse
->board_type
; /*need efuse define*/
259 u32 _interface
= rtlhal
->interface
;
260 u32 _platform
= 0x08;/*SupportPlatform */
263 if (condition
== 0xCDCDCDCD)
266 cond
= condition
& 0xFF;
267 if ((_board
& cond
) == 0 && cond
!= 0x1F)
270 cond
= condition
& 0xFF00;
272 if ((_interface
& cond
) == 0 && cond
!= 0x07)
275 cond
= condition
& 0xFF0000;
277 if ((_platform
& cond
) == 0 && cond
!= 0x0F)
282 static void _rtl8188e_config_rf_reg(struct ieee80211_hw
*hw
, u32 addr
,
283 u32 data
, enum radio_path rfpath
,
288 } else if (addr
== 0xfd) {
290 } else if (addr
== 0xfc) {
292 } else if (addr
== 0xfb) {
294 } else if (addr
== 0xfa) {
296 } else if (addr
== 0xf9) {
299 rtl_set_rfreg(hw
, rfpath
, regaddr
,
306 static void _rtl8188e_config_rf_radio_a(struct ieee80211_hw
*hw
,
309 u32 content
= 0x1000; /*RF Content: radio_a_txt*/
310 u32 maskforphyset
= (u32
)(content
& 0xE000);
312 _rtl8188e_config_rf_reg(hw
, addr
, data
, RF90_PATH_A
,
313 addr
| maskforphyset
);
316 static void _rtl8188e_config_bb_reg(struct ieee80211_hw
*hw
,
321 } else if (addr
== 0xfd) {
323 } else if (addr
== 0xfc) {
325 } else if (addr
== 0xfb) {
327 } else if (addr
== 0xfa) {
329 } else if (addr
== 0xf9) {
332 rtl_set_bbreg(hw
, addr
, MASKDWORD
, data
);
337 static bool _rtl88e_phy_bb8188e_config_parafile(struct ieee80211_hw
*hw
)
339 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
340 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
341 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
344 rtstatus
= phy_config_bb_with_headerfile(hw
, BASEBAND_CONFIG_PHY_REG
);
346 pr_err("Write BB Reg Fail!!\n");
350 if (!rtlefuse
->autoload_failflag
) {
351 rtlphy
->pwrgroup_cnt
= 0;
353 phy_config_bb_with_pghdr(hw
, BASEBAND_CONFIG_PHY_REG
);
356 pr_err("BB_PG Reg Fail!!\n");
360 phy_config_bb_with_headerfile(hw
, BASEBAND_CONFIG_AGC_TAB
);
362 pr_err("AGC Table Fail\n");
365 rtlphy
->cck_high_power
=
366 (bool)(rtl_get_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER2
, 0x200));
371 static bool _rtl88e_phy_config_mac_with_headerfile(struct ieee80211_hw
*hw
)
373 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
378 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
, "Read Rtl8188EMACPHY_Array\n");
379 arraylength
= RTL8188EEMAC_1T_ARRAYLEN
;
380 ptrarray
= RTL8188EEMAC_1T_ARRAY
;
381 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
382 "Img:RTL8188EEMAC_1T_ARRAY LEN %d\n", arraylength
);
383 for (i
= 0; i
< arraylength
; i
= i
+ 2)
384 rtl_write_byte(rtlpriv
, ptrarray
[i
], (u8
)ptrarray
[i
+ 1]);
388 #define READ_NEXT_PAIR(v1, v2, i) \
390 i += 2; v1 = array_table[i]; \
391 v2 = array_table[i+1]; \
394 static void handle_branch1(struct ieee80211_hw
*hw
, u16 arraylen
,
401 for (i
= 0; i
< arraylen
; i
= i
+ 2) {
403 v2
= array_table
[i
+1];
404 if (v1
< 0xcdcdcdcd) {
405 _rtl8188e_config_bb_reg(hw
, v1
, v2
);
406 } else { /*This line is the start line of branch.*/
407 /* to protect READ_NEXT_PAIR not overrun */
408 if (i
>= arraylen
- 2)
411 if (!_rtl88e_check_condition(hw
, array_table
[i
])) {
412 /*Discard the following (offset, data) pairs*/
413 READ_NEXT_PAIR(v1
, v2
, i
);
414 while (v2
!= 0xDEAD &&
416 v2
!= 0xCDCD && i
< arraylen
- 2)
417 READ_NEXT_PAIR(v1
, v2
, i
);
418 i
-= 2; /* prevent from for-loop += 2*/
419 } else { /* Configure matched pairs and skip
422 READ_NEXT_PAIR(v1
, v2
, i
);
423 while (v2
!= 0xDEAD &&
425 v2
!= 0xCDCD && i
< arraylen
- 2) {
426 _rtl8188e_config_bb_reg(hw
, v1
, v2
);
427 READ_NEXT_PAIR(v1
, v2
, i
);
430 while (v2
!= 0xDEAD && i
< arraylen
- 2)
431 READ_NEXT_PAIR(v1
, v2
, i
);
437 static void handle_branch2(struct ieee80211_hw
*hw
, u16 arraylen
,
440 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
445 for (i
= 0; i
< arraylen
; i
= i
+ 2) {
447 v2
= array_table
[i
+1];
448 if (v1
< 0xCDCDCDCD) {
449 rtl_set_bbreg(hw
, array_table
[i
], MASKDWORD
,
453 } else { /*This line is the start line of branch.*/
454 /* to protect READ_NEXT_PAIR not overrun */
455 if (i
>= arraylen
- 2)
458 if (!_rtl88e_check_condition(hw
, array_table
[i
])) {
459 /*Discard the following (offset, data) pairs*/
460 READ_NEXT_PAIR(v1
, v2
, i
);
461 while (v2
!= 0xDEAD &&
463 v2
!= 0xCDCD && i
< arraylen
- 2)
464 READ_NEXT_PAIR(v1
, v2
, i
);
465 i
-= 2; /* prevent from for-loop += 2*/
466 } else { /* Configure matched pairs and skip
469 READ_NEXT_PAIR(v1
, v2
, i
);
470 while (v2
!= 0xDEAD &&
472 v2
!= 0xCDCD && i
< arraylen
- 2) {
473 rtl_set_bbreg(hw
, array_table
[i
],
477 READ_NEXT_PAIR(v1
, v2
, i
);
480 while (v2
!= 0xDEAD && i
< arraylen
- 2)
481 READ_NEXT_PAIR(v1
, v2
, i
);
484 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
485 "The agctab_array_table[0] is %x Rtl818EEPHY_REGArray[1] is %x\n",
486 array_table
[i
], array_table
[i
+ 1]);
490 static bool phy_config_bb_with_headerfile(struct ieee80211_hw
*hw
,
496 if (configtype
== BASEBAND_CONFIG_PHY_REG
) {
497 arraylen
= RTL8188EEPHY_REG_1TARRAYLEN
;
498 array_table
= RTL8188EEPHY_REG_1TARRAY
;
499 handle_branch1(hw
, arraylen
, array_table
);
500 } else if (configtype
== BASEBAND_CONFIG_AGC_TAB
) {
501 arraylen
= RTL8188EEAGCTAB_1TARRAYLEN
;
502 array_table
= RTL8188EEAGCTAB_1TARRAY
;
503 handle_branch2(hw
, arraylen
, array_table
);
508 static void store_pwrindex_rate_offset(struct ieee80211_hw
*hw
,
509 u32 regaddr
, u32 bitmask
,
512 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
513 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
514 int count
= rtlphy
->pwrgroup_cnt
;
516 if (regaddr
== RTXAGC_A_RATE18_06
) {
517 rtlphy
->mcs_txpwrlevel_origoffset
[count
][0] = data
;
518 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
519 "MCSTxPowerLevelOriginalOffset[%d][0] = 0x%x\n",
521 rtlphy
->mcs_txpwrlevel_origoffset
[count
][0]);
523 if (regaddr
== RTXAGC_A_RATE54_24
) {
524 rtlphy
->mcs_txpwrlevel_origoffset
[count
][1] = data
;
525 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
526 "MCSTxPowerLevelOriginalOffset[%d][1] = 0x%x\n",
528 rtlphy
->mcs_txpwrlevel_origoffset
[count
][1]);
530 if (regaddr
== RTXAGC_A_CCK1_MCS32
) {
531 rtlphy
->mcs_txpwrlevel_origoffset
[count
][6] = data
;
532 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
533 "MCSTxPowerLevelOriginalOffset[%d][6] = 0x%x\n",
535 rtlphy
->mcs_txpwrlevel_origoffset
[count
][6]);
537 if (regaddr
== RTXAGC_B_CCK11_A_CCK2_11
&& bitmask
== 0xffffff00) {
538 rtlphy
->mcs_txpwrlevel_origoffset
[count
][7] = data
;
539 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
540 "MCSTxPowerLevelOriginalOffset[%d][7] = 0x%x\n",
542 rtlphy
->mcs_txpwrlevel_origoffset
[count
][7]);
544 if (regaddr
== RTXAGC_A_MCS03_MCS00
) {
545 rtlphy
->mcs_txpwrlevel_origoffset
[count
][2] = data
;
546 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
547 "MCSTxPowerLevelOriginalOffset[%d][2] = 0x%x\n",
549 rtlphy
->mcs_txpwrlevel_origoffset
[count
][2]);
551 if (regaddr
== RTXAGC_A_MCS07_MCS04
) {
552 rtlphy
->mcs_txpwrlevel_origoffset
[count
][3] = data
;
553 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
554 "MCSTxPowerLevelOriginalOffset[%d][3] = 0x%x\n",
556 rtlphy
->mcs_txpwrlevel_origoffset
[count
][3]);
558 if (regaddr
== RTXAGC_A_MCS11_MCS08
) {
559 rtlphy
->mcs_txpwrlevel_origoffset
[count
][4] = data
;
560 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
561 "MCSTxPowerLevelOriginalOffset[%d][4] = 0x%x\n",
563 rtlphy
->mcs_txpwrlevel_origoffset
[count
][4]);
565 if (regaddr
== RTXAGC_A_MCS15_MCS12
) {
566 rtlphy
->mcs_txpwrlevel_origoffset
[count
][5] = data
;
567 if (get_rf_type(rtlphy
) == RF_1T1R
) {
569 rtlphy
->pwrgroup_cnt
= count
;
571 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
572 "MCSTxPowerLevelOriginalOffset[%d][5] = 0x%x\n",
574 rtlphy
->mcs_txpwrlevel_origoffset
[count
][5]);
576 if (regaddr
== RTXAGC_B_RATE18_06
) {
577 rtlphy
->mcs_txpwrlevel_origoffset
[count
][8] = data
;
578 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
579 "MCSTxPowerLevelOriginalOffset[%d][8] = 0x%x\n",
581 rtlphy
->mcs_txpwrlevel_origoffset
[count
][8]);
583 if (regaddr
== RTXAGC_B_RATE54_24
) {
584 rtlphy
->mcs_txpwrlevel_origoffset
[count
][9] = data
;
585 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
586 "MCSTxPowerLevelOriginalOffset[%d][9] = 0x%x\n",
588 rtlphy
->mcs_txpwrlevel_origoffset
[count
][9]);
590 if (regaddr
== RTXAGC_B_CCK1_55_MCS32
) {
591 rtlphy
->mcs_txpwrlevel_origoffset
[count
][14] = data
;
592 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
593 "MCSTxPowerLevelOriginalOffset[%d][14] = 0x%x\n",
595 rtlphy
->mcs_txpwrlevel_origoffset
[count
][14]);
597 if (regaddr
== RTXAGC_B_CCK11_A_CCK2_11
&& bitmask
== 0x000000ff) {
598 rtlphy
->mcs_txpwrlevel_origoffset
[count
][15] = data
;
599 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
600 "MCSTxPowerLevelOriginalOffset[%d][15] = 0x%x\n",
602 rtlphy
->mcs_txpwrlevel_origoffset
[count
][15]);
604 if (regaddr
== RTXAGC_B_MCS03_MCS00
) {
605 rtlphy
->mcs_txpwrlevel_origoffset
[count
][10] = data
;
606 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
607 "MCSTxPowerLevelOriginalOffset[%d][10] = 0x%x\n",
609 rtlphy
->mcs_txpwrlevel_origoffset
[count
][10]);
611 if (regaddr
== RTXAGC_B_MCS07_MCS04
) {
612 rtlphy
->mcs_txpwrlevel_origoffset
[count
][11] = data
;
613 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
614 "MCSTxPowerLevelOriginalOffset[%d][11] = 0x%x\n",
616 rtlphy
->mcs_txpwrlevel_origoffset
[count
][11]);
618 if (regaddr
== RTXAGC_B_MCS11_MCS08
) {
619 rtlphy
->mcs_txpwrlevel_origoffset
[count
][12] = data
;
620 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
621 "MCSTxPowerLevelOriginalOffset[%d][12] = 0x%x\n",
623 rtlphy
->mcs_txpwrlevel_origoffset
[count
][12]);
625 if (regaddr
== RTXAGC_B_MCS15_MCS12
) {
626 rtlphy
->mcs_txpwrlevel_origoffset
[count
][13] = data
;
627 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
628 "MCSTxPowerLevelOriginalOffset[%d][13] = 0x%x\n",
630 rtlphy
->mcs_txpwrlevel_origoffset
[count
][13]);
631 if (get_rf_type(rtlphy
) != RF_1T1R
) {
633 rtlphy
->pwrgroup_cnt
= count
;
638 static bool phy_config_bb_with_pghdr(struct ieee80211_hw
*hw
, u8 configtype
)
640 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
643 u16 phy_reg_page_len
;
646 phy_reg_page_len
= RTL8188EEPHY_REG_ARRAY_PGLEN
;
647 phy_reg_page
= RTL8188EEPHY_REG_ARRAY_PG
;
649 if (configtype
== BASEBAND_CONFIG_PHY_REG
) {
650 for (i
= 0; i
< phy_reg_page_len
; i
= i
+ 3) {
651 v1
= phy_reg_page
[i
];
652 v2
= phy_reg_page
[i
+1];
654 if (v1
< 0xcdcdcdcd) {
655 if (phy_reg_page
[i
] == 0xfe)
657 else if (phy_reg_page
[i
] == 0xfd)
659 else if (phy_reg_page
[i
] == 0xfc)
661 else if (phy_reg_page
[i
] == 0xfb)
663 else if (phy_reg_page
[i
] == 0xfa)
665 else if (phy_reg_page
[i
] == 0xf9)
668 store_pwrindex_rate_offset(hw
, phy_reg_page
[i
],
670 phy_reg_page
[i
+ 2]);
673 if (!_rtl88e_check_condition(hw
,
675 /*don't need the hw_body*/
676 i
+= 2; /* skip the pair of expression*/
677 /* to protect 'i+1' 'i+2' not overrun */
678 if (i
>= phy_reg_page_len
- 2)
681 v1
= phy_reg_page
[i
];
682 v2
= phy_reg_page
[i
+1];
683 while (v2
!= 0xDEAD &&
684 i
< phy_reg_page_len
- 5) {
686 v1
= phy_reg_page
[i
];
687 v2
= phy_reg_page
[i
+1];
693 rtl_dbg(rtlpriv
, COMP_SEND
, DBG_TRACE
,
694 "configtype != BaseBand_Config_PHY_REG\n");
699 #define READ_NEXT_RF_PAIR(v1, v2, i) \
702 v1 = radioa_array_table[i]; \
703 v2 = radioa_array_table[i+1]; \
706 static void process_path_a(struct ieee80211_hw
*hw
,
708 u32
*radioa_array_table
)
710 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
714 for (i
= 0; i
< radioa_arraylen
; i
= i
+ 2) {
715 v1
= radioa_array_table
[i
];
716 v2
= radioa_array_table
[i
+1];
717 if (v1
< 0xcdcdcdcd) {
718 _rtl8188e_config_rf_radio_a(hw
, v1
, v2
);
719 } else { /*This line is the start line of branch.*/
720 /* to protect READ_NEXT_PAIR not overrun */
721 if (i
>= radioa_arraylen
- 2)
724 if (!_rtl88e_check_condition(hw
, radioa_array_table
[i
])) {
725 /*Discard the following (offset, data) pairs*/
726 READ_NEXT_RF_PAIR(v1
, v2
, i
);
727 while (v2
!= 0xDEAD &&
730 i
< radioa_arraylen
- 2) {
731 READ_NEXT_RF_PAIR(v1
, v2
, i
);
733 i
-= 2; /* prevent from for-loop += 2*/
734 } else { /* Configure matched pairs and
735 * skip to end of if-else.
737 READ_NEXT_RF_PAIR(v1
, v2
, i
);
738 while (v2
!= 0xDEAD &&
741 i
< radioa_arraylen
- 2) {
742 _rtl8188e_config_rf_radio_a(hw
, v1
, v2
);
743 READ_NEXT_RF_PAIR(v1
, v2
, i
);
746 while (v2
!= 0xDEAD &&
747 i
< radioa_arraylen
- 2)
748 READ_NEXT_RF_PAIR(v1
, v2
, i
);
753 if (rtlhal
->oem_id
== RT_CID_819X_HP
)
754 _rtl8188e_config_rf_radio_a(hw
, 0x52, 0x7E4BD);
757 bool rtl88e_phy_config_rf_with_headerfile(struct ieee80211_hw
*hw
,
758 enum radio_path rfpath
)
760 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
761 u32
*radioa_array_table
;
764 radioa_arraylen
= RTL8188EE_RADIOA_1TARRAYLEN
;
765 radioa_array_table
= RTL8188EE_RADIOA_1TARRAY
;
766 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
767 "Radio_A:RTL8188EE_RADIOA_1TARRAY %d\n", radioa_arraylen
);
768 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Radio No %x\n", rfpath
);
771 process_path_a(hw
, radioa_arraylen
, radioa_array_table
);
781 void rtl88e_phy_get_hw_reg_originalvalue(struct ieee80211_hw
*hw
)
783 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
784 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
786 rtlphy
->default_initialgain
[0] =
787 (u8
)rtl_get_bbreg(hw
, ROFDM0_XAAGCCORE1
, MASKBYTE0
);
788 rtlphy
->default_initialgain
[1] =
789 (u8
)rtl_get_bbreg(hw
, ROFDM0_XBAGCCORE1
, MASKBYTE0
);
790 rtlphy
->default_initialgain
[2] =
791 (u8
)rtl_get_bbreg(hw
, ROFDM0_XCAGCCORE1
, MASKBYTE0
);
792 rtlphy
->default_initialgain
[3] =
793 (u8
)rtl_get_bbreg(hw
, ROFDM0_XDAGCCORE1
, MASKBYTE0
);
795 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
796 "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x\n",
797 rtlphy
->default_initialgain
[0],
798 rtlphy
->default_initialgain
[1],
799 rtlphy
->default_initialgain
[2],
800 rtlphy
->default_initialgain
[3]);
802 rtlphy
->framesync
= (u8
)rtl_get_bbreg(hw
, ROFDM0_RXDETECTOR3
,
804 rtlphy
->framesync_c34
= rtl_get_bbreg(hw
, ROFDM0_RXDETECTOR2
,
807 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
808 "Default framesync (0x%x) = 0x%x\n",
809 ROFDM0_RXDETECTOR3
, rtlphy
->framesync
);
812 static void _rtl88e_phy_init_bb_rf_register_definition(struct ieee80211_hw
*hw
)
814 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
815 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
817 rtlphy
->phyreg_def
[RF90_PATH_A
].rfintfs
= RFPGA0_XAB_RFINTERFACESW
;
818 rtlphy
->phyreg_def
[RF90_PATH_B
].rfintfs
= RFPGA0_XAB_RFINTERFACESW
;
819 rtlphy
->phyreg_def
[RF90_PATH_C
].rfintfs
= RFPGA0_XCD_RFINTERFACESW
;
820 rtlphy
->phyreg_def
[RF90_PATH_D
].rfintfs
= RFPGA0_XCD_RFINTERFACESW
;
822 rtlphy
->phyreg_def
[RF90_PATH_A
].rfintfi
= RFPGA0_XAB_RFINTERFACERB
;
823 rtlphy
->phyreg_def
[RF90_PATH_B
].rfintfi
= RFPGA0_XAB_RFINTERFACERB
;
824 rtlphy
->phyreg_def
[RF90_PATH_C
].rfintfi
= RFPGA0_XCD_RFINTERFACERB
;
825 rtlphy
->phyreg_def
[RF90_PATH_D
].rfintfi
= RFPGA0_XCD_RFINTERFACERB
;
827 rtlphy
->phyreg_def
[RF90_PATH_A
].rfintfo
= RFPGA0_XA_RFINTERFACEOE
;
828 rtlphy
->phyreg_def
[RF90_PATH_B
].rfintfo
= RFPGA0_XB_RFINTERFACEOE
;
830 rtlphy
->phyreg_def
[RF90_PATH_A
].rfintfe
= RFPGA0_XA_RFINTERFACEOE
;
831 rtlphy
->phyreg_def
[RF90_PATH_B
].rfintfe
= RFPGA0_XB_RFINTERFACEOE
;
833 rtlphy
->phyreg_def
[RF90_PATH_A
].rf3wire_offset
=
834 RFPGA0_XA_LSSIPARAMETER
;
835 rtlphy
->phyreg_def
[RF90_PATH_B
].rf3wire_offset
=
836 RFPGA0_XB_LSSIPARAMETER
;
838 rtlphy
->phyreg_def
[RF90_PATH_A
].rflssi_select
= RFPGA0_XAB_RFPARAMETER
;
839 rtlphy
->phyreg_def
[RF90_PATH_B
].rflssi_select
= RFPGA0_XAB_RFPARAMETER
;
840 rtlphy
->phyreg_def
[RF90_PATH_C
].rflssi_select
= RFPGA0_XCD_RFPARAMETER
;
841 rtlphy
->phyreg_def
[RF90_PATH_D
].rflssi_select
= RFPGA0_XCD_RFPARAMETER
;
843 rtlphy
->phyreg_def
[RF90_PATH_A
].rftxgain_stage
= RFPGA0_TXGAINSTAGE
;
844 rtlphy
->phyreg_def
[RF90_PATH_B
].rftxgain_stage
= RFPGA0_TXGAINSTAGE
;
845 rtlphy
->phyreg_def
[RF90_PATH_C
].rftxgain_stage
= RFPGA0_TXGAINSTAGE
;
846 rtlphy
->phyreg_def
[RF90_PATH_D
].rftxgain_stage
= RFPGA0_TXGAINSTAGE
;
848 rtlphy
->phyreg_def
[RF90_PATH_A
].rfhssi_para1
= RFPGA0_XA_HSSIPARAMETER1
;
849 rtlphy
->phyreg_def
[RF90_PATH_B
].rfhssi_para1
= RFPGA0_XB_HSSIPARAMETER1
;
851 rtlphy
->phyreg_def
[RF90_PATH_A
].rfhssi_para2
= RFPGA0_XA_HSSIPARAMETER2
;
852 rtlphy
->phyreg_def
[RF90_PATH_B
].rfhssi_para2
= RFPGA0_XB_HSSIPARAMETER2
;
854 rtlphy
->phyreg_def
[RF90_PATH_A
].rfsw_ctrl
=
855 RFPGA0_XAB_SWITCHCONTROL
;
856 rtlphy
->phyreg_def
[RF90_PATH_B
].rfsw_ctrl
=
857 RFPGA0_XAB_SWITCHCONTROL
;
858 rtlphy
->phyreg_def
[RF90_PATH_C
].rfsw_ctrl
=
859 RFPGA0_XCD_SWITCHCONTROL
;
860 rtlphy
->phyreg_def
[RF90_PATH_D
].rfsw_ctrl
=
861 RFPGA0_XCD_SWITCHCONTROL
;
863 rtlphy
->phyreg_def
[RF90_PATH_A
].rfagc_control1
= ROFDM0_XAAGCCORE1
;
864 rtlphy
->phyreg_def
[RF90_PATH_B
].rfagc_control1
= ROFDM0_XBAGCCORE1
;
865 rtlphy
->phyreg_def
[RF90_PATH_C
].rfagc_control1
= ROFDM0_XCAGCCORE1
;
866 rtlphy
->phyreg_def
[RF90_PATH_D
].rfagc_control1
= ROFDM0_XDAGCCORE1
;
868 rtlphy
->phyreg_def
[RF90_PATH_A
].rfagc_control2
= ROFDM0_XAAGCCORE2
;
869 rtlphy
->phyreg_def
[RF90_PATH_B
].rfagc_control2
= ROFDM0_XBAGCCORE2
;
870 rtlphy
->phyreg_def
[RF90_PATH_C
].rfagc_control2
= ROFDM0_XCAGCCORE2
;
871 rtlphy
->phyreg_def
[RF90_PATH_D
].rfagc_control2
= ROFDM0_XDAGCCORE2
;
873 rtlphy
->phyreg_def
[RF90_PATH_A
].rfrxiq_imbal
= ROFDM0_XARXIQIMBALANCE
;
874 rtlphy
->phyreg_def
[RF90_PATH_B
].rfrxiq_imbal
= ROFDM0_XBRXIQIMBALANCE
;
875 rtlphy
->phyreg_def
[RF90_PATH_C
].rfrxiq_imbal
= ROFDM0_XCRXIQIMBANLANCE
;
876 rtlphy
->phyreg_def
[RF90_PATH_D
].rfrxiq_imbal
= ROFDM0_XDRXIQIMBALANCE
;
878 rtlphy
->phyreg_def
[RF90_PATH_A
].rfrx_afe
= ROFDM0_XARXAFE
;
879 rtlphy
->phyreg_def
[RF90_PATH_B
].rfrx_afe
= ROFDM0_XBRXAFE
;
880 rtlphy
->phyreg_def
[RF90_PATH_C
].rfrx_afe
= ROFDM0_XCRXAFE
;
881 rtlphy
->phyreg_def
[RF90_PATH_D
].rfrx_afe
= ROFDM0_XDRXAFE
;
883 rtlphy
->phyreg_def
[RF90_PATH_A
].rftxiq_imbal
= ROFDM0_XATXIQIMBALANCE
;
884 rtlphy
->phyreg_def
[RF90_PATH_B
].rftxiq_imbal
= ROFDM0_XBTXIQIMBALANCE
;
885 rtlphy
->phyreg_def
[RF90_PATH_C
].rftxiq_imbal
= ROFDM0_XCTXIQIMBALANCE
;
886 rtlphy
->phyreg_def
[RF90_PATH_D
].rftxiq_imbal
= ROFDM0_XDTXIQIMBALANCE
;
888 rtlphy
->phyreg_def
[RF90_PATH_A
].rftx_afe
= ROFDM0_XATXAFE
;
889 rtlphy
->phyreg_def
[RF90_PATH_B
].rftx_afe
= ROFDM0_XBTXAFE
;
891 rtlphy
->phyreg_def
[RF90_PATH_A
].rf_rb
= RFPGA0_XA_LSSIREADBACK
;
892 rtlphy
->phyreg_def
[RF90_PATH_B
].rf_rb
= RFPGA0_XB_LSSIREADBACK
;
894 rtlphy
->phyreg_def
[RF90_PATH_A
].rf_rbpi
= TRANSCEIVEA_HSPI_READBACK
;
895 rtlphy
->phyreg_def
[RF90_PATH_B
].rf_rbpi
= TRANSCEIVEB_HSPI_READBACK
;
898 void rtl88e_phy_get_txpower_level(struct ieee80211_hw
*hw
, long *powerlevel
)
900 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
901 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
905 txpwr_level
= rtlphy
->cur_cck_txpwridx
;
906 txpwr_dbm
= _rtl88e_phy_txpwr_idx_to_dbm(hw
,
907 WIRELESS_MODE_B
, txpwr_level
);
908 txpwr_level
= rtlphy
->cur_ofdm24g_txpwridx
;
909 if (_rtl88e_phy_txpwr_idx_to_dbm(hw
,
911 txpwr_level
) > txpwr_dbm
)
913 _rtl88e_phy_txpwr_idx_to_dbm(hw
, WIRELESS_MODE_G
,
915 txpwr_level
= rtlphy
->cur_ofdm24g_txpwridx
;
916 if (_rtl88e_phy_txpwr_idx_to_dbm(hw
,
918 txpwr_level
) > txpwr_dbm
)
920 _rtl88e_phy_txpwr_idx_to_dbm(hw
, WIRELESS_MODE_N_24G
,
922 *powerlevel
= txpwr_dbm
;
925 static void handle_path_a(struct rtl_efuse
*rtlefuse
, u8 index
,
926 u8
*cckpowerlevel
, u8
*ofdmpowerlevel
,
927 u8
*bw20powerlevel
, u8
*bw40powerlevel
)
929 cckpowerlevel
[RF90_PATH_A
] =
930 rtlefuse
->txpwrlevel_cck
[RF90_PATH_A
][index
];
932 if (rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][index
] > 0x0f)
933 bw20powerlevel
[RF90_PATH_A
] =
934 rtlefuse
->txpwrlevel_ht40_1s
[RF90_PATH_A
][index
] -
935 (~(rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][index
]) + 1);
937 bw20powerlevel
[RF90_PATH_A
] =
938 rtlefuse
->txpwrlevel_ht40_1s
[RF90_PATH_A
][index
] +
939 rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][index
];
940 if (rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][index
] > 0xf)
941 ofdmpowerlevel
[RF90_PATH_A
] =
942 rtlefuse
->txpwrlevel_ht40_1s
[RF90_PATH_A
][index
] -
943 (~(rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][index
])+1);
945 ofdmpowerlevel
[RF90_PATH_A
] =
946 rtlefuse
->txpwrlevel_ht40_1s
[RF90_PATH_A
][index
] +
947 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][index
];
948 bw40powerlevel
[RF90_PATH_A
] =
949 rtlefuse
->txpwrlevel_ht40_1s
[RF90_PATH_A
][index
];
952 static void _rtl88e_get_txpower_index(struct ieee80211_hw
*hw
, u8 channel
,
953 u8
*cckpowerlevel
, u8
*ofdmpowerlevel
,
954 u8
*bw20powerlevel
, u8
*bw40powerlevel
)
956 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
957 u8 index
= (channel
- 1);
960 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
961 if (rf_path
== RF90_PATH_A
) {
962 handle_path_a(rtlefuse
, index
, cckpowerlevel
,
963 ofdmpowerlevel
, bw20powerlevel
,
965 } else if (rf_path
== RF90_PATH_B
) {
966 cckpowerlevel
[RF90_PATH_B
] =
967 rtlefuse
->txpwrlevel_cck
[RF90_PATH_B
][index
];
968 bw20powerlevel
[RF90_PATH_B
] =
969 rtlefuse
->txpwrlevel_ht40_1s
[RF90_PATH_B
][index
] +
970 rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][index
];
971 ofdmpowerlevel
[RF90_PATH_B
] =
972 rtlefuse
->txpwrlevel_ht40_1s
[RF90_PATH_B
][index
] +
973 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_B
][index
];
974 bw40powerlevel
[RF90_PATH_B
] =
975 rtlefuse
->txpwrlevel_ht40_1s
[RF90_PATH_B
][index
];
981 static void _rtl88e_ccxpower_index_check(struct ieee80211_hw
*hw
,
982 u8 channel
, u8
*cckpowerlevel
,
983 u8
*ofdmpowerlevel
, u8
*bw20powerlevel
,
986 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
987 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
989 rtlphy
->cur_cck_txpwridx
= cckpowerlevel
[0];
990 rtlphy
->cur_ofdm24g_txpwridx
= ofdmpowerlevel
[0];
991 rtlphy
->cur_bw20_txpwridx
= bw20powerlevel
[0];
992 rtlphy
->cur_bw40_txpwridx
= bw40powerlevel
[0];
996 void rtl88e_phy_set_txpower_level(struct ieee80211_hw
*hw
, u8 channel
)
998 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
999 u8 cckpowerlevel
[MAX_TX_COUNT
] = {0};
1000 u8 ofdmpowerlevel
[MAX_TX_COUNT
] = {0};
1001 u8 bw20powerlevel
[MAX_TX_COUNT
] = {0};
1002 u8 bw40powerlevel
[MAX_TX_COUNT
] = {0};
1004 if (!rtlefuse
->txpwr_fromeprom
)
1006 _rtl88e_get_txpower_index(hw
, channel
,
1007 &cckpowerlevel
[0], &ofdmpowerlevel
[0],
1008 &bw20powerlevel
[0], &bw40powerlevel
[0]);
1009 _rtl88e_ccxpower_index_check(hw
, channel
,
1010 &cckpowerlevel
[0], &ofdmpowerlevel
[0],
1011 &bw20powerlevel
[0], &bw40powerlevel
[0]);
1012 rtl88e_phy_rf6052_set_cck_txpower(hw
, &cckpowerlevel
[0]);
1013 rtl88e_phy_rf6052_set_ofdm_txpower(hw
, &ofdmpowerlevel
[0],
1015 &bw40powerlevel
[0], channel
);
1018 static long _rtl88e_phy_txpwr_idx_to_dbm(struct ieee80211_hw
*hw
,
1019 enum wireless_mode wirelessmode
,
1025 switch (wirelessmode
) {
1026 case WIRELESS_MODE_B
:
1029 case WIRELESS_MODE_G
:
1030 case WIRELESS_MODE_N_24G
:
1037 pwrout_dbm
= txpwridx
/ 2 + offset
;
1041 void rtl88e_phy_scan_operation_backup(struct ieee80211_hw
*hw
, u8 operation
)
1043 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1044 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1045 enum io_type iotype
;
1047 if (!is_hal_stop(rtlhal
)) {
1048 switch (operation
) {
1049 case SCAN_OPT_BACKUP_BAND0
:
1050 iotype
= IO_CMD_PAUSE_BAND0_DM_BY_SCAN
;
1051 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1056 case SCAN_OPT_RESTORE
:
1057 iotype
= IO_CMD_RESUME_DM_BY_SCAN
;
1058 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1063 pr_err("Unknown Scan Backup operation.\n");
1069 void rtl88e_phy_set_bw_mode_callback(struct ieee80211_hw
*hw
)
1071 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1072 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1073 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1074 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1078 rtl_dbg(rtlpriv
, COMP_SCAN
, DBG_TRACE
,
1079 "Switch to %s bandwidth\n",
1080 rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20
?
1083 if (is_hal_stop(rtlhal
)) {
1084 rtlphy
->set_bwmode_inprogress
= false;
1088 reg_bw_opmode
= rtl_read_byte(rtlpriv
, REG_BWOPMODE
);
1089 reg_prsr_rsc
= rtl_read_byte(rtlpriv
, REG_RRSR
+ 2);
1091 switch (rtlphy
->current_chan_bw
) {
1092 case HT_CHANNEL_WIDTH_20
:
1093 reg_bw_opmode
|= BW_OPMODE_20MHZ
;
1094 rtl_write_byte(rtlpriv
, REG_BWOPMODE
, reg_bw_opmode
);
1096 case HT_CHANNEL_WIDTH_20_40
:
1097 reg_bw_opmode
&= ~BW_OPMODE_20MHZ
;
1098 rtl_write_byte(rtlpriv
, REG_BWOPMODE
, reg_bw_opmode
);
1100 (reg_prsr_rsc
& 0x90) | (mac
->cur_40_prime_sc
<< 5);
1101 rtl_write_byte(rtlpriv
, REG_RRSR
+ 2, reg_prsr_rsc
);
1104 pr_err("unknown bandwidth: %#X\n",
1105 rtlphy
->current_chan_bw
);
1109 switch (rtlphy
->current_chan_bw
) {
1110 case HT_CHANNEL_WIDTH_20
:
1111 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BRFMOD
, 0x0);
1112 rtl_set_bbreg(hw
, RFPGA1_RFMOD
, BRFMOD
, 0x0);
1113 /* rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 1);*/
1115 case HT_CHANNEL_WIDTH_20_40
:
1116 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BRFMOD
, 0x1);
1117 rtl_set_bbreg(hw
, RFPGA1_RFMOD
, BRFMOD
, 0x1);
1119 rtl_set_bbreg(hw
, RCCK0_SYSTEM
, BCCK_SIDEBAND
,
1120 (mac
->cur_40_prime_sc
>> 1));
1121 rtl_set_bbreg(hw
, ROFDM1_LSTF
, 0xC00, mac
->cur_40_prime_sc
);
1122 /*rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 0);*/
1124 rtl_set_bbreg(hw
, 0x818, (BIT(26) | BIT(27)),
1125 (mac
->cur_40_prime_sc
==
1126 HAL_PRIME_CHNL_OFFSET_LOWER
) ? 2 : 1);
1129 pr_err("unknown bandwidth: %#X\n",
1130 rtlphy
->current_chan_bw
);
1133 rtl88e_phy_rf6052_set_bandwidth(hw
, rtlphy
->current_chan_bw
);
1134 rtlphy
->set_bwmode_inprogress
= false;
1135 rtl_dbg(rtlpriv
, COMP_SCAN
, DBG_LOUD
, "\n");
1138 void rtl88e_phy_set_bw_mode(struct ieee80211_hw
*hw
,
1139 enum nl80211_channel_type ch_type
)
1141 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1142 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1143 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1144 u8 tmp_bw
= rtlphy
->current_chan_bw
;
1146 if (rtlphy
->set_bwmode_inprogress
)
1148 rtlphy
->set_bwmode_inprogress
= true;
1149 if ((!is_hal_stop(rtlhal
)) && !(RT_CANNOT_IO(hw
))) {
1150 rtl88e_phy_set_bw_mode_callback(hw
);
1152 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1153 "false driver sleep or unload\n");
1154 rtlphy
->set_bwmode_inprogress
= false;
1155 rtlphy
->current_chan_bw
= tmp_bw
;
1159 void rtl88e_phy_sw_chnl_callback(struct ieee80211_hw
*hw
)
1161 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1162 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1163 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1166 rtl_dbg(rtlpriv
, COMP_SCAN
, DBG_TRACE
,
1167 "switch to channel%d\n", rtlphy
->current_channel
);
1168 if (is_hal_stop(rtlhal
))
1171 if (!rtlphy
->sw_chnl_inprogress
)
1173 if (!_rtl88e_phy_sw_chnl_step_by_step
1174 (hw
, rtlphy
->current_channel
, &rtlphy
->sw_chnl_stage
,
1175 &rtlphy
->sw_chnl_step
, &delay
)) {
1181 rtlphy
->sw_chnl_inprogress
= false;
1185 rtl_dbg(rtlpriv
, COMP_SCAN
, DBG_TRACE
, "\n");
1188 u8
rtl88e_phy_sw_chnl(struct ieee80211_hw
*hw
)
1190 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1191 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1192 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1194 if (rtlphy
->sw_chnl_inprogress
)
1196 if (rtlphy
->set_bwmode_inprogress
)
1198 WARN_ONCE((rtlphy
->current_channel
> 14),
1199 "rtl8188ee: WIRELESS_MODE_G but channel>14");
1200 rtlphy
->sw_chnl_inprogress
= true;
1201 rtlphy
->sw_chnl_stage
= 0;
1202 rtlphy
->sw_chnl_step
= 0;
1203 if (!(is_hal_stop(rtlhal
)) && !(RT_CANNOT_IO(hw
))) {
1204 rtl88e_phy_sw_chnl_callback(hw
);
1205 rtl_dbg(rtlpriv
, COMP_CHAN
, DBG_LOUD
,
1206 "sw_chnl_inprogress false schedule workitem current channel %d\n",
1207 rtlphy
->current_channel
);
1208 rtlphy
->sw_chnl_inprogress
= false;
1210 rtl_dbg(rtlpriv
, COMP_CHAN
, DBG_LOUD
,
1211 "sw_chnl_inprogress false driver sleep or unload\n");
1212 rtlphy
->sw_chnl_inprogress
= false;
1217 static bool _rtl88e_phy_sw_chnl_step_by_step(struct ieee80211_hw
*hw
,
1218 u8 channel
, u8
*stage
, u8
*step
,
1221 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1222 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1223 struct swchnlcmd precommoncmd
[MAX_PRECMD_CNT
];
1224 u32 precommoncmdcnt
;
1225 struct swchnlcmd postcommoncmd
[MAX_POSTCMD_CNT
];
1226 u32 postcommoncmdcnt
;
1227 struct swchnlcmd rfdependcmd
[MAX_RFDEPENDCMD_CNT
];
1229 struct swchnlcmd
*currentcmd
= NULL
;
1231 u8 num_total_rfpath
= rtlphy
->num_total_rfpath
;
1233 precommoncmdcnt
= 0;
1234 _rtl88e_phy_set_sw_chnl_cmdarray(precommoncmd
, precommoncmdcnt
++,
1236 CMDID_SET_TXPOWEROWER_LEVEL
, 0, 0, 0);
1237 _rtl88e_phy_set_sw_chnl_cmdarray(precommoncmd
, precommoncmdcnt
++,
1238 MAX_PRECMD_CNT
, CMDID_END
, 0, 0, 0);
1240 postcommoncmdcnt
= 0;
1242 _rtl88e_phy_set_sw_chnl_cmdarray(postcommoncmd
, postcommoncmdcnt
++,
1243 MAX_POSTCMD_CNT
, CMDID_END
, 0, 0, 0);
1247 WARN_ONCE((channel
< 1 || channel
> 14),
1248 "rtl8188ee: illegal channel for Zebra: %d\n", channel
);
1250 _rtl88e_phy_set_sw_chnl_cmdarray(rfdependcmd
, rfdependcmdcnt
++,
1251 MAX_RFDEPENDCMD_CNT
, CMDID_RF_WRITEREG
,
1252 RF_CHNLBW
, channel
, 10);
1254 _rtl88e_phy_set_sw_chnl_cmdarray(rfdependcmd
, rfdependcmdcnt
++,
1255 MAX_RFDEPENDCMD_CNT
, CMDID_END
, 0, 0,
1261 currentcmd
= &precommoncmd
[*step
];
1264 currentcmd
= &rfdependcmd
[*step
];
1267 currentcmd
= &postcommoncmd
[*step
];
1270 pr_err("Invalid 'stage' = %d, Check it!\n",
1275 if (currentcmd
->cmdid
== CMDID_END
) {
1283 switch (currentcmd
->cmdid
) {
1284 case CMDID_SET_TXPOWEROWER_LEVEL
:
1285 rtl88e_phy_set_txpower_level(hw
, channel
);
1287 case CMDID_WRITEPORT_ULONG
:
1288 rtl_write_dword(rtlpriv
, currentcmd
->para1
,
1291 case CMDID_WRITEPORT_USHORT
:
1292 rtl_write_word(rtlpriv
, currentcmd
->para1
,
1293 (u16
)currentcmd
->para2
);
1295 case CMDID_WRITEPORT_UCHAR
:
1296 rtl_write_byte(rtlpriv
, currentcmd
->para1
,
1297 (u8
)currentcmd
->para2
);
1299 case CMDID_RF_WRITEREG
:
1300 for (rfpath
= 0; rfpath
< num_total_rfpath
; rfpath
++) {
1301 rtlphy
->rfreg_chnlval
[rfpath
] =
1302 ((rtlphy
->rfreg_chnlval
[rfpath
] &
1303 0xfffffc00) | currentcmd
->para2
);
1305 rtl_set_rfreg(hw
, (enum radio_path
)rfpath
,
1308 rtlphy
->rfreg_chnlval
[rfpath
]);
1312 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_LOUD
,
1313 "switch case %#x not processed\n",
1321 (*delay
) = currentcmd
->msdelay
;
1326 static bool _rtl88e_phy_set_sw_chnl_cmdarray(struct swchnlcmd
*cmdtable
,
1327 u32 cmdtableidx
, u32 cmdtablesz
,
1328 enum swchnlcmd_id cmdid
,
1329 u32 para1
, u32 para2
, u32 msdelay
)
1331 struct swchnlcmd
*pcmd
;
1333 if (cmdtable
== NULL
) {
1334 WARN_ONCE(true, "rtl8188ee: cmdtable cannot be NULL.\n");
1338 if (cmdtableidx
>= cmdtablesz
)
1341 pcmd
= cmdtable
+ cmdtableidx
;
1342 pcmd
->cmdid
= cmdid
;
1343 pcmd
->para1
= para1
;
1344 pcmd
->para2
= para2
;
1345 pcmd
->msdelay
= msdelay
;
1349 static u8
_rtl88e_phy_path_a_iqk(struct ieee80211_hw
*hw
, bool config_pathb
)
1351 u32 reg_eac
, reg_e94
, reg_e9c
;
1354 rtl_set_bbreg(hw
, 0xe30, MASKDWORD
, 0x10008c1c);
1355 rtl_set_bbreg(hw
, 0xe34, MASKDWORD
, 0x30008c1c);
1356 rtl_set_bbreg(hw
, 0xe38, MASKDWORD
, 0x8214032a);
1357 rtl_set_bbreg(hw
, 0xe3c, MASKDWORD
, 0x28160000);
1359 rtl_set_bbreg(hw
, 0xe4c, MASKDWORD
, 0x00462911);
1360 rtl_set_bbreg(hw
, 0xe48, MASKDWORD
, 0xf9000000);
1361 rtl_set_bbreg(hw
, 0xe48, MASKDWORD
, 0xf8000000);
1363 mdelay(IQK_DELAY_TIME
);
1365 reg_eac
= rtl_get_bbreg(hw
, 0xeac, MASKDWORD
);
1366 reg_e94
= rtl_get_bbreg(hw
, 0xe94, MASKDWORD
);
1367 reg_e9c
= rtl_get_bbreg(hw
, 0xe9c, MASKDWORD
);
1368 rtl_get_bbreg(hw
, 0xea4, MASKDWORD
);
1370 if (!(reg_eac
& BIT(28)) &&
1371 (((reg_e94
& 0x03FF0000) >> 16) != 0x142) &&
1372 (((reg_e9c
& 0x03FF0000) >> 16) != 0x42))
1377 static u8
_rtl88e_phy_path_b_iqk(struct ieee80211_hw
*hw
)
1379 u32 reg_eac
, reg_eb4
, reg_ebc
, reg_ec4
, reg_ecc
;
1382 rtl_set_bbreg(hw
, 0xe60, MASKDWORD
, 0x00000002);
1383 rtl_set_bbreg(hw
, 0xe60, MASKDWORD
, 0x00000000);
1384 mdelay(IQK_DELAY_TIME
);
1385 reg_eac
= rtl_get_bbreg(hw
, 0xeac, MASKDWORD
);
1386 reg_eb4
= rtl_get_bbreg(hw
, 0xeb4, MASKDWORD
);
1387 reg_ebc
= rtl_get_bbreg(hw
, 0xebc, MASKDWORD
);
1388 reg_ec4
= rtl_get_bbreg(hw
, 0xec4, MASKDWORD
);
1389 reg_ecc
= rtl_get_bbreg(hw
, 0xecc, MASKDWORD
);
1391 if (!(reg_eac
& BIT(31)) &&
1392 (((reg_eb4
& 0x03FF0000) >> 16) != 0x142) &&
1393 (((reg_ebc
& 0x03FF0000) >> 16) != 0x42))
1397 if (!(reg_eac
& BIT(30)) &&
1398 (((reg_ec4
& 0x03FF0000) >> 16) != 0x132) &&
1399 (((reg_ecc
& 0x03FF0000) >> 16) != 0x36))
1404 static u8
_rtl88e_phy_path_a_rx_iqk(struct ieee80211_hw
*hw
, bool config_pathb
)
1406 u32 reg_eac
, reg_e94
, reg_e9c
, reg_ea4
, u32temp
;
1409 /*Get TXIMR Setting*/
1410 /*Modify RX IQK mode table*/
1411 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x00000000);
1412 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_WE_LUT
, RFREG_OFFSET_MASK
, 0x800a0);
1413 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_RCK_OS
, RFREG_OFFSET_MASK
, 0x30000);
1414 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_TXPA_G1
, RFREG_OFFSET_MASK
, 0x0000f);
1415 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_TXPA_G2
, RFREG_OFFSET_MASK
, 0xf117b);
1416 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x80800000);
1419 rtl_set_bbreg(hw
, RTX_IQK
, MASKDWORD
, 0x01007c00);
1420 rtl_set_bbreg(hw
, RRX_IQK
, MASKDWORD
, 0x81004800);
1422 /*path a IQK setting*/
1423 rtl_set_bbreg(hw
, RTX_IQK_TONE_A
, MASKDWORD
, 0x10008c1c);
1424 rtl_set_bbreg(hw
, RRX_IQK_TONE_A
, MASKDWORD
, 0x30008c1c);
1425 rtl_set_bbreg(hw
, RTX_IQK_PI_A
, MASKDWORD
, 0x82160804);
1426 rtl_set_bbreg(hw
, RRX_IQK_PI_A
, MASKDWORD
, 0x28160000);
1428 /*LO calibration Setting*/
1429 rtl_set_bbreg(hw
, RIQK_AGC_RSP
, MASKDWORD
, 0x0046a911);
1430 /*one shot,path A LOK & iqk*/
1431 rtl_set_bbreg(hw
, RIQK_AGC_PTS
, MASKDWORD
, 0xf9000000);
1432 rtl_set_bbreg(hw
, RIQK_AGC_PTS
, MASKDWORD
, 0xf8000000);
1434 mdelay(IQK_DELAY_TIME
);
1436 reg_eac
= rtl_get_bbreg(hw
, RRX_POWER_AFTER_IQK_A_2
, MASKDWORD
);
1437 reg_e94
= rtl_get_bbreg(hw
, RTX_POWER_BEFORE_IQK_A
, MASKDWORD
);
1438 reg_e9c
= rtl_get_bbreg(hw
, RTX_POWER_AFTER_IQK_A
, MASKDWORD
);
1441 if (!(reg_eac
& BIT(28)) &&
1442 (((reg_e94
& 0x03FF0000) >> 16) != 0x142) &&
1443 (((reg_e9c
& 0x03FF0000) >> 16) != 0x42))
1448 u32temp
= 0x80007C00 | (reg_e94
&0x3FF0000) |
1449 ((reg_e9c
&0x3FF0000) >> 16);
1450 rtl_set_bbreg(hw
, RTX_IQK
, MASKDWORD
, u32temp
);
1452 /*Modify RX IQK mode table*/
1453 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x00000000);
1454 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_WE_LUT
, RFREG_OFFSET_MASK
, 0x800a0);
1455 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_RCK_OS
, RFREG_OFFSET_MASK
, 0x30000);
1456 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_TXPA_G1
, RFREG_OFFSET_MASK
, 0x0000f);
1457 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_TXPA_G2
, RFREG_OFFSET_MASK
, 0xf7ffa);
1458 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x80800000);
1461 rtl_set_bbreg(hw
, RRX_IQK
, MASKDWORD
, 0x01004800);
1463 /*path a IQK setting*/
1464 rtl_set_bbreg(hw
, RTX_IQK_TONE_A
, MASKDWORD
, 0x30008c1c);
1465 rtl_set_bbreg(hw
, RRX_IQK_TONE_A
, MASKDWORD
, 0x10008c1c);
1466 rtl_set_bbreg(hw
, RTX_IQK_PI_A
, MASKDWORD
, 0x82160c05);
1467 rtl_set_bbreg(hw
, RRX_IQK_PI_A
, MASKDWORD
, 0x28160c05);
1469 /*LO calibration Setting*/
1470 rtl_set_bbreg(hw
, RIQK_AGC_RSP
, MASKDWORD
, 0x0046a911);
1471 /*one shot,path A LOK & iqk*/
1472 rtl_set_bbreg(hw
, RIQK_AGC_PTS
, MASKDWORD
, 0xf9000000);
1473 rtl_set_bbreg(hw
, RIQK_AGC_PTS
, MASKDWORD
, 0xf8000000);
1475 mdelay(IQK_DELAY_TIME
);
1477 reg_eac
= rtl_get_bbreg(hw
, RRX_POWER_AFTER_IQK_A_2
, MASKDWORD
);
1478 reg_e94
= rtl_get_bbreg(hw
, RTX_POWER_BEFORE_IQK_A
, MASKDWORD
);
1479 reg_e9c
= rtl_get_bbreg(hw
, RTX_POWER_AFTER_IQK_A
, MASKDWORD
);
1480 reg_ea4
= rtl_get_bbreg(hw
, RRX_POWER_BEFORE_IQK_A_2
, MASKDWORD
);
1482 if (!(reg_eac
& BIT(27)) &&
1483 (((reg_ea4
& 0x03FF0000) >> 16) != 0x132) &&
1484 (((reg_eac
& 0x03FF0000) >> 16) != 0x36))
1489 static void _rtl88e_phy_path_a_fill_iqk_matrix(struct ieee80211_hw
*hw
,
1490 bool iqk_ok
, long result
[][8],
1491 u8 final_candidate
, bool btxonly
)
1493 u32 oldval_0
, x
, tx0_a
, reg
;
1496 if (final_candidate
== 0xFF) {
1498 } else if (iqk_ok
) {
1499 oldval_0
= (rtl_get_bbreg(hw
, ROFDM0_XATXIQIMBALANCE
,
1500 MASKDWORD
) >> 22) & 0x3FF;
1501 x
= result
[final_candidate
][0];
1502 if ((x
& 0x00000200) != 0)
1504 tx0_a
= (x
* oldval_0
) >> 8;
1505 rtl_set_bbreg(hw
, ROFDM0_XATXIQIMBALANCE
, 0x3FF, tx0_a
);
1506 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
, BIT(31),
1507 ((x
* oldval_0
>> 7) & 0x1));
1508 y
= result
[final_candidate
][1];
1509 if ((y
& 0x00000200) != 0)
1511 tx0_c
= (y
* oldval_0
) >> 8;
1512 rtl_set_bbreg(hw
, ROFDM0_XCTXAFE
, 0xF0000000,
1513 ((tx0_c
& 0x3C0) >> 6));
1514 rtl_set_bbreg(hw
, ROFDM0_XATXIQIMBALANCE
, 0x003F0000,
1516 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
, BIT(29),
1517 ((y
* oldval_0
>> 7) & 0x1));
1520 reg
= result
[final_candidate
][2];
1521 rtl_set_bbreg(hw
, ROFDM0_XARXIQIMBALANCE
, 0x3FF, reg
);
1522 reg
= result
[final_candidate
][3] & 0x3F;
1523 rtl_set_bbreg(hw
, ROFDM0_XARXIQIMBALANCE
, 0xFC00, reg
);
1524 reg
= (result
[final_candidate
][3] >> 6) & 0xF;
1525 rtl_set_bbreg(hw
, 0xca0, 0xF0000000, reg
);
1529 static void _rtl88e_phy_save_adda_registers(struct ieee80211_hw
*hw
,
1530 u32
*addareg
, u32
*addabackup
,
1535 for (i
= 0; i
< registernum
; i
++)
1536 addabackup
[i
] = rtl_get_bbreg(hw
, addareg
[i
], MASKDWORD
);
1539 static void _rtl88e_phy_save_mac_registers(struct ieee80211_hw
*hw
,
1540 u32
*macreg
, u32
*macbackup
)
1542 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1545 for (i
= 0; i
< (IQK_MAC_REG_NUM
- 1); i
++)
1546 macbackup
[i
] = rtl_read_byte(rtlpriv
, macreg
[i
]);
1547 macbackup
[i
] = rtl_read_dword(rtlpriv
, macreg
[i
]);
1550 static void _rtl88e_phy_reload_adda_registers(struct ieee80211_hw
*hw
,
1551 u32
*addareg
, u32
*addabackup
,
1556 for (i
= 0; i
< regiesternum
; i
++)
1557 rtl_set_bbreg(hw
, addareg
[i
], MASKDWORD
, addabackup
[i
]);
1560 static void _rtl88e_phy_reload_mac_registers(struct ieee80211_hw
*hw
,
1561 u32
*macreg
, u32
*macbackup
)
1563 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1566 for (i
= 0; i
< (IQK_MAC_REG_NUM
- 1); i
++)
1567 rtl_write_byte(rtlpriv
, macreg
[i
], (u8
) macbackup
[i
]);
1568 rtl_write_dword(rtlpriv
, macreg
[i
], macbackup
[i
]);
1571 static void _rtl88e_phy_path_adda_on(struct ieee80211_hw
*hw
,
1572 u32
*addareg
, bool is_patha_on
, bool is2t
)
1577 pathon
= is_patha_on
? 0x04db25a4 : 0x0b1b25a4;
1579 pathon
= 0x0bdb25a0;
1580 rtl_set_bbreg(hw
, addareg
[0], MASKDWORD
, 0x0b1b25a0);
1582 rtl_set_bbreg(hw
, addareg
[0], MASKDWORD
, pathon
);
1585 for (i
= 1; i
< IQK_ADDA_REG_NUM
; i
++)
1586 rtl_set_bbreg(hw
, addareg
[i
], MASKDWORD
, pathon
);
1589 static void _rtl88e_phy_mac_setting_calibration(struct ieee80211_hw
*hw
,
1590 u32
*macreg
, u32
*macbackup
)
1592 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1595 rtl_write_byte(rtlpriv
, macreg
[i
], 0x3F);
1597 for (i
= 1; i
< (IQK_MAC_REG_NUM
- 1); i
++)
1598 rtl_write_byte(rtlpriv
, macreg
[i
],
1599 (u8
) (macbackup
[i
] & (~BIT(3))));
1600 rtl_write_byte(rtlpriv
, macreg
[i
], (u8
) (macbackup
[i
] & (~BIT(5))));
1603 static void _rtl88e_phy_path_a_standby(struct ieee80211_hw
*hw
)
1605 rtl_set_bbreg(hw
, 0xe28, MASKDWORD
, 0x0);
1606 rtl_set_bbreg(hw
, 0x840, MASKDWORD
, 0x00010000);
1607 rtl_set_bbreg(hw
, 0xe28, MASKDWORD
, 0x80800000);
1610 static void _rtl88e_phy_pi_mode_switch(struct ieee80211_hw
*hw
, bool pi_mode
)
1614 mode
= pi_mode
? 0x01000100 : 0x01000000;
1615 rtl_set_bbreg(hw
, 0x820, MASKDWORD
, mode
);
1616 rtl_set_bbreg(hw
, 0x828, MASKDWORD
, mode
);
1619 static bool _rtl88e_phy_simularity_compare(struct ieee80211_hw
*hw
,
1620 long result
[][8], u8 c1
, u8 c2
)
1622 u32 i
, j
, diff
, simularity_bitmap
, bound
;
1623 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1625 u8 final_candidate
[2] = { 0xFF, 0xFF };
1626 bool bresult
= true, is2t
= IS_92C_SERIAL(rtlhal
->version
);
1633 simularity_bitmap
= 0;
1635 for (i
= 0; i
< bound
; i
++) {
1636 diff
= (result
[c1
][i
] > result
[c2
][i
]) ?
1637 (result
[c1
][i
] - result
[c2
][i
]) :
1638 (result
[c2
][i
] - result
[c1
][i
]);
1640 if (diff
> MAX_TOLERANCE
) {
1641 if ((i
== 2 || i
== 6) && !simularity_bitmap
) {
1642 if (result
[c1
][i
] + result
[c1
][i
+ 1] == 0)
1643 final_candidate
[(i
/ 4)] = c2
;
1644 else if (result
[c2
][i
] + result
[c2
][i
+ 1] == 0)
1645 final_candidate
[(i
/ 4)] = c1
;
1647 simularity_bitmap
= simularity_bitmap
|
1651 simularity_bitmap
| (1 << i
);
1655 if (simularity_bitmap
== 0) {
1656 for (i
= 0; i
< (bound
/ 4); i
++) {
1657 if (final_candidate
[i
] != 0xFF) {
1658 for (j
= i
* 4; j
< (i
+ 1) * 4 - 2; j
++)
1660 result
[final_candidate
[i
]][j
];
1665 } else if (!(simularity_bitmap
& 0x0F)) {
1666 for (i
= 0; i
< 4; i
++)
1667 result
[3][i
] = result
[c1
][i
];
1669 } else if (!(simularity_bitmap
& 0xF0) && is2t
) {
1670 for (i
= 4; i
< 8; i
++)
1671 result
[3][i
] = result
[c1
][i
];
1679 static void _rtl88e_phy_iq_calibrate(struct ieee80211_hw
*hw
,
1680 long result
[][8], u8 t
, bool is2t
)
1682 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1683 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1685 u8 patha_ok
, pathb_ok
;
1686 u32 adda_reg
[IQK_ADDA_REG_NUM
] = {
1687 0x85c, 0xe6c, 0xe70, 0xe74,
1688 0xe78, 0xe7c, 0xe80, 0xe84,
1689 0xe88, 0xe8c, 0xed0, 0xed4,
1690 0xed8, 0xedc, 0xee0, 0xeec
1692 u32 iqk_mac_reg
[IQK_MAC_REG_NUM
] = {
1693 0x522, 0x550, 0x551, 0x040
1695 u32 iqk_bb_reg
[IQK_BB_REG_NUM
] = {
1696 ROFDM0_TRXPATHENABLE
, ROFDM0_TRMUXPAR
,
1697 RFPGA0_XCD_RFINTERFACESW
, 0xb68, 0xb6c,
1698 0x870, 0x860, 0x864, 0x800
1700 const u32 retrycount
= 2;
1703 _rtl88e_phy_save_adda_registers(hw
, adda_reg
,
1704 rtlphy
->adda_backup
, 16);
1705 _rtl88e_phy_save_mac_registers(hw
, iqk_mac_reg
,
1706 rtlphy
->iqk_mac_backup
);
1707 _rtl88e_phy_save_adda_registers(hw
, iqk_bb_reg
,
1708 rtlphy
->iqk_bb_backup
,
1711 _rtl88e_phy_path_adda_on(hw
, adda_reg
, true, is2t
);
1713 rtlphy
->rfpi_enable
=
1714 (u8
)rtl_get_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER1
, BIT(8));
1717 if (!rtlphy
->rfpi_enable
)
1718 _rtl88e_phy_pi_mode_switch(hw
, true);
1720 rtl_set_bbreg(hw
, 0x800, BIT(24), 0x00);
1721 rtl_set_bbreg(hw
, 0xc04, MASKDWORD
, 0x03a05600);
1722 rtl_set_bbreg(hw
, 0xc08, MASKDWORD
, 0x000800e4);
1723 rtl_set_bbreg(hw
, 0x874, MASKDWORD
, 0x22204000);
1725 rtl_set_bbreg(hw
, 0x870, BIT(10), 0x01);
1726 rtl_set_bbreg(hw
, 0x870, BIT(26), 0x01);
1727 rtl_set_bbreg(hw
, 0x860, BIT(10), 0x00);
1728 rtl_set_bbreg(hw
, 0x864, BIT(10), 0x00);
1731 rtl_set_bbreg(hw
, 0x840, MASKDWORD
, 0x00010000);
1732 rtl_set_bbreg(hw
, 0x844, MASKDWORD
, 0x00010000);
1734 _rtl88e_phy_mac_setting_calibration(hw
, iqk_mac_reg
,
1735 rtlphy
->iqk_mac_backup
);
1736 rtl_set_bbreg(hw
, 0xb68, MASKDWORD
, 0x0f600000);
1738 rtl_set_bbreg(hw
, 0xb6c, MASKDWORD
, 0x0f600000);
1740 rtl_set_bbreg(hw
, 0xe28, MASKDWORD
, 0x80800000);
1741 rtl_set_bbreg(hw
, 0xe40, MASKDWORD
, 0x01007c00);
1742 rtl_set_bbreg(hw
, 0xe44, MASKDWORD
, 0x81004800);
1743 for (i
= 0; i
< retrycount
; i
++) {
1744 patha_ok
= _rtl88e_phy_path_a_iqk(hw
, is2t
);
1745 if (patha_ok
== 0x01) {
1746 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1747 "Path A Tx IQK Success!!\n");
1748 result
[t
][0] = (rtl_get_bbreg(hw
, 0xe94, MASKDWORD
) &
1750 result
[t
][1] = (rtl_get_bbreg(hw
, 0xe9c, MASKDWORD
) &
1756 for (i
= 0; i
< retrycount
; i
++) {
1757 patha_ok
= _rtl88e_phy_path_a_rx_iqk(hw
, is2t
);
1758 if (patha_ok
== 0x03) {
1759 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1760 "Path A Rx IQK Success!!\n");
1761 result
[t
][2] = (rtl_get_bbreg(hw
, 0xea4, MASKDWORD
) &
1763 result
[t
][3] = (rtl_get_bbreg(hw
, 0xeac, MASKDWORD
) &
1767 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1768 "Path a RX iqk fail!!!\n");
1773 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1774 "Path A IQK Success!!\n");
1776 _rtl88e_phy_path_a_standby(hw
);
1777 _rtl88e_phy_path_adda_on(hw
, adda_reg
, false, is2t
);
1778 for (i
= 0; i
< retrycount
; i
++) {
1779 pathb_ok
= _rtl88e_phy_path_b_iqk(hw
);
1780 if (pathb_ok
== 0x03) {
1781 result
[t
][4] = (rtl_get_bbreg(hw
,
1786 (rtl_get_bbreg(hw
, 0xebc, MASKDWORD
) &
1789 (rtl_get_bbreg(hw
, 0xec4, MASKDWORD
) &
1792 (rtl_get_bbreg(hw
, 0xecc, MASKDWORD
) &
1795 } else if (i
== (retrycount
- 1) && pathb_ok
== 0x01) {
1796 result
[t
][4] = (rtl_get_bbreg(hw
,
1801 result
[t
][5] = (rtl_get_bbreg(hw
, 0xebc, MASKDWORD
) &
1806 rtl_set_bbreg(hw
, 0xe28, MASKDWORD
, 0);
1809 if (!rtlphy
->rfpi_enable
)
1810 _rtl88e_phy_pi_mode_switch(hw
, false);
1811 _rtl88e_phy_reload_adda_registers(hw
, adda_reg
,
1812 rtlphy
->adda_backup
, 16);
1813 _rtl88e_phy_reload_mac_registers(hw
, iqk_mac_reg
,
1814 rtlphy
->iqk_mac_backup
);
1815 _rtl88e_phy_reload_adda_registers(hw
, iqk_bb_reg
,
1816 rtlphy
->iqk_bb_backup
,
1819 rtl_set_bbreg(hw
, 0x840, MASKDWORD
, 0x00032ed3);
1821 rtl_set_bbreg(hw
, 0x844, MASKDWORD
, 0x00032ed3);
1822 rtl_set_bbreg(hw
, 0xe30, MASKDWORD
, 0x01008c00);
1823 rtl_set_bbreg(hw
, 0xe34, MASKDWORD
, 0x01008c00);
1825 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
, "88ee IQK Finish!!\n");
1828 static void _rtl88e_phy_lc_calibrate(struct ieee80211_hw
*hw
, bool is2t
)
1831 u32 rf_a_mode
= 0, rf_b_mode
= 0, lc_cal
;
1832 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1834 tmpreg
= rtl_read_byte(rtlpriv
, 0xd03);
1836 if ((tmpreg
& 0x70) != 0)
1837 rtl_write_byte(rtlpriv
, 0xd03, tmpreg
& 0x8F);
1839 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0xFF);
1841 if ((tmpreg
& 0x70) != 0) {
1842 rf_a_mode
= rtl_get_rfreg(hw
, RF90_PATH_A
, 0x00, MASK12BITS
);
1845 rf_b_mode
= rtl_get_rfreg(hw
, RF90_PATH_B
, 0x00,
1848 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x00, MASK12BITS
,
1849 (rf_a_mode
& 0x8FFFF) | 0x10000);
1852 rtl_set_rfreg(hw
, RF90_PATH_B
, 0x00, MASK12BITS
,
1853 (rf_b_mode
& 0x8FFFF) | 0x10000);
1855 lc_cal
= rtl_get_rfreg(hw
, RF90_PATH_A
, 0x18, MASK12BITS
);
1857 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x18, MASK12BITS
, lc_cal
| 0x08000);
1861 if ((tmpreg
& 0x70) != 0) {
1862 rtl_write_byte(rtlpriv
, 0xd03, tmpreg
);
1863 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x00, MASK12BITS
, rf_a_mode
);
1866 rtl_set_rfreg(hw
, RF90_PATH_B
, 0x00, MASK12BITS
,
1869 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0x00);
1871 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
, "\n");
1874 static void _rtl88e_phy_set_rfpath_switch(struct ieee80211_hw
*hw
,
1875 bool bmain
, bool is2t
)
1877 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1878 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1879 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1880 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
, "\n");
1882 if (is_hal_stop(rtlhal
)) {
1884 u1btmp
= rtl_read_byte(rtlpriv
, REG_LEDCFG0
);
1885 rtl_write_byte(rtlpriv
, REG_LEDCFG0
, u1btmp
| BIT(7));
1886 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(13), 0x01);
1890 rtl_set_bbreg(hw
, RFPGA0_XB_RFINTERFACEOE
,
1891 BIT(5) | BIT(6), 0x1);
1893 rtl_set_bbreg(hw
, RFPGA0_XB_RFINTERFACEOE
,
1894 BIT(5) | BIT(6), 0x2);
1896 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
, BIT(8) | BIT(9), 0);
1897 rtl_set_bbreg(hw
, 0x914, MASKLWORD
, 0x0201);
1899 /* We use the RF definition of MAIN and AUX,
1900 * left antenna and right antenna repectively.
1901 * Default output at AUX.
1904 rtl_set_bbreg(hw
, RFPGA0_XA_RFINTERFACEOE
,
1905 BIT(14) | BIT(13) | BIT(12), 0);
1906 rtl_set_bbreg(hw
, RFPGA0_XB_RFINTERFACEOE
,
1907 BIT(5) | BIT(4) | BIT(3), 0);
1908 if (rtlefuse
->antenna_div_type
== CGCS_RX_HW_ANTDIV
)
1909 rtl_set_bbreg(hw
, RCONFIG_RAM64x16
, BIT(31), 0);
1911 rtl_set_bbreg(hw
, RFPGA0_XA_RFINTERFACEOE
,
1912 BIT(14) | BIT(13) | BIT(12), 1);
1913 rtl_set_bbreg(hw
, RFPGA0_XB_RFINTERFACEOE
,
1914 BIT(5) | BIT(4) | BIT(3), 1);
1915 if (rtlefuse
->antenna_div_type
== CGCS_RX_HW_ANTDIV
)
1916 rtl_set_bbreg(hw
, RCONFIG_RAM64x16
, BIT(31), 1);
1921 #undef IQK_ADDA_REG_NUM
1922 #undef IQK_DELAY_TIME
1924 void rtl88e_phy_iq_calibrate(struct ieee80211_hw
*hw
, bool b_recovery
)
1926 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1927 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1929 u8 i
, final_candidate
;
1931 long reg_e94
, reg_e9c
, reg_ea4
, reg_eb4
, reg_ebc
,
1933 bool is12simular
, is13simular
, is23simular
;
1934 u32 iqk_bb_reg
[9] = {
1935 ROFDM0_XARXIQIMBALANCE
,
1936 ROFDM0_XBRXIQIMBALANCE
,
1937 ROFDM0_ECCATHRESHOLD
,
1938 ROFDM0_AGCRSSITABLE
,
1939 ROFDM0_XATXIQIMBALANCE
,
1940 ROFDM0_XBTXIQIMBALANCE
,
1947 _rtl88e_phy_reload_adda_registers(hw
,
1949 rtlphy
->iqk_bb_backup
, 9);
1953 for (i
= 0; i
< 8; i
++) {
1959 final_candidate
= 0xff;
1961 is12simular
= false;
1962 is23simular
= false;
1963 is13simular
= false;
1964 for (i
= 0; i
< 3; i
++) {
1965 if (get_rf_type(rtlphy
) == RF_2T2R
)
1966 _rtl88e_phy_iq_calibrate(hw
, result
, i
, true);
1968 _rtl88e_phy_iq_calibrate(hw
, result
, i
, false);
1971 _rtl88e_phy_simularity_compare(hw
, result
, 0, 1);
1973 final_candidate
= 0;
1979 _rtl88e_phy_simularity_compare(hw
, result
, 0, 2);
1981 final_candidate
= 0;
1985 _rtl88e_phy_simularity_compare(hw
, result
, 1, 2);
1987 final_candidate
= 1;
1989 for (i
= 0; i
< 8; i
++)
1990 reg_tmp
+= result
[3][i
];
1993 final_candidate
= 3;
1995 final_candidate
= 0xFF;
1999 for (i
= 0; i
< 4; i
++) {
2000 reg_e94
= result
[i
][0];
2001 reg_e9c
= result
[i
][1];
2002 reg_ea4
= result
[i
][2];
2003 reg_eb4
= result
[i
][4];
2004 reg_ebc
= result
[i
][5];
2006 if (final_candidate
!= 0xff) {
2007 reg_e94
= result
[final_candidate
][0];
2008 reg_e9c
= result
[final_candidate
][1];
2009 reg_ea4
= result
[final_candidate
][2];
2010 reg_eb4
= result
[final_candidate
][4];
2011 reg_ebc
= result
[final_candidate
][5];
2012 rtlphy
->reg_eb4
= reg_eb4
;
2013 rtlphy
->reg_ebc
= reg_ebc
;
2014 rtlphy
->reg_e94
= reg_e94
;
2015 rtlphy
->reg_e9c
= reg_e9c
;
2018 rtlphy
->reg_e94
= 0x100;
2019 rtlphy
->reg_eb4
= 0x100;
2020 rtlphy
->reg_e9c
= 0x0;
2021 rtlphy
->reg_ebc
= 0x0;
2023 if (reg_e94
!= 0) /*&&(reg_ea4 != 0) */
2024 _rtl88e_phy_path_a_fill_iqk_matrix(hw
, b_patha_ok
, result
,
2027 if (final_candidate
!= 0xFF) {
2028 for (i
= 0; i
< IQK_MATRIX_REG_NUM
; i
++)
2029 rtlphy
->iqk_matrix
[0].value
[0][i
] =
2030 result
[final_candidate
][i
];
2031 rtlphy
->iqk_matrix
[0].iqk_done
= true;
2034 _rtl88e_phy_save_adda_registers(hw
, iqk_bb_reg
,
2035 rtlphy
->iqk_bb_backup
, 9);
2038 void rtl88e_phy_lc_calibrate(struct ieee80211_hw
*hw
)
2040 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2041 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
2042 struct rtl_hal
*rtlhal
= &rtlpriv
->rtlhal
;
2043 u32 timeout
= 2000, timecount
= 0;
2045 while (rtlpriv
->mac80211
.act_scanning
&& timecount
< timeout
) {
2050 rtlphy
->lck_inprogress
= true;
2051 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2052 "LCK:Start!!! currentband %x delay %d ms\n",
2053 rtlhal
->current_bandtype
, timecount
);
2055 _rtl88e_phy_lc_calibrate(hw
, false);
2057 rtlphy
->lck_inprogress
= false;
2060 void rtl88e_phy_set_rfpath_switch(struct ieee80211_hw
*hw
, bool bmain
)
2062 _rtl88e_phy_set_rfpath_switch(hw
, bmain
, false);
2065 bool rtl88e_phy_set_io_cmd(struct ieee80211_hw
*hw
, enum io_type iotype
)
2067 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2068 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
2069 bool postprocessing
= false;
2071 rtl_dbg(rtlpriv
, COMP_CMD
, DBG_TRACE
,
2072 "-->IO Cmd(%#x), set_io_inprogress(%d)\n",
2073 iotype
, rtlphy
->set_io_inprogress
);
2076 case IO_CMD_RESUME_DM_BY_SCAN
:
2077 rtl_dbg(rtlpriv
, COMP_CMD
, DBG_TRACE
,
2078 "[IO CMD] Resume DM after scan.\n");
2079 postprocessing
= true;
2081 case IO_CMD_PAUSE_BAND0_DM_BY_SCAN
:
2082 rtl_dbg(rtlpriv
, COMP_CMD
, DBG_TRACE
,
2083 "[IO CMD] Pause DM before scan.\n");
2084 postprocessing
= true;
2087 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_LOUD
,
2088 "switch case %#x not processed\n", iotype
);
2092 if (postprocessing
&& !rtlphy
->set_io_inprogress
) {
2093 rtlphy
->set_io_inprogress
= true;
2094 rtlphy
->current_io_type
= iotype
;
2098 rtl88e_phy_set_io(hw
);
2099 rtl_dbg(rtlpriv
, COMP_CMD
, DBG_TRACE
, "IO Type(%#x)\n", iotype
);
2103 static void rtl88e_phy_set_io(struct ieee80211_hw
*hw
)
2105 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2106 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
2107 struct dig_t
*dm_digtable
= &rtlpriv
->dm_digtable
;
2109 rtl_dbg(rtlpriv
, COMP_CMD
, DBG_TRACE
,
2110 "--->Cmd(%#x), set_io_inprogress(%d)\n",
2111 rtlphy
->current_io_type
, rtlphy
->set_io_inprogress
);
2112 switch (rtlphy
->current_io_type
) {
2113 case IO_CMD_RESUME_DM_BY_SCAN
:
2114 dm_digtable
->cur_igvalue
= rtlphy
->initgain_backup
.xaagccore1
;
2115 /*rtl92c_dm_write_dig(hw);*/
2116 rtl88e_phy_set_txpower_level(hw
, rtlphy
->current_channel
);
2117 rtl_set_bbreg(hw
, RCCK0_CCA
, 0xff0000, 0x83);
2119 case IO_CMD_PAUSE_BAND0_DM_BY_SCAN
:
2120 rtlphy
->initgain_backup
.xaagccore1
= dm_digtable
->cur_igvalue
;
2121 dm_digtable
->cur_igvalue
= 0x17;
2122 rtl_set_bbreg(hw
, RCCK0_CCA
, 0xff0000, 0x40);
2125 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_LOUD
,
2126 "switch case %#x not processed\n",
2127 rtlphy
->current_io_type
);
2130 rtlphy
->set_io_inprogress
= false;
2131 rtl_dbg(rtlpriv
, COMP_CMD
, DBG_TRACE
,
2132 "(%#x)\n", rtlphy
->current_io_type
);
2135 static void rtl88ee_phy_set_rf_on(struct ieee80211_hw
*hw
)
2137 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2139 rtl_write_byte(rtlpriv
, REG_SPS0_CTRL
, 0x2b);
2140 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE3);
2141 /*rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x00);*/
2142 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE2);
2143 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE3);
2144 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0x00);
2147 static void _rtl88ee_phy_set_rf_sleep(struct ieee80211_hw
*hw
)
2149 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2151 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0xFF);
2152 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x00, RFREG_OFFSET_MASK
, 0x00);
2153 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE2);
2154 rtl_write_byte(rtlpriv
, REG_SPS0_CTRL
, 0x22);
2157 static bool _rtl88ee_phy_set_rf_power_state(struct ieee80211_hw
*hw
,
2158 enum rf_pwrstate rfpwr_state
)
2160 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2161 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
2162 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2163 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
2164 bool bresult
= true;
2166 struct rtl8192_tx_ring
*ring
= NULL
;
2168 switch (rfpwr_state
) {
2170 if ((ppsc
->rfpwr_state
== ERFOFF
) &&
2171 RT_IN_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
)) {
2173 u32 initializecount
= 0;
2177 rtl_dbg(rtlpriv
, COMP_RF
, DBG_DMESG
,
2178 "IPS Set eRf nic enable\n");
2179 rtstatus
= rtl_ps_enable_nic(hw
);
2180 } while (!rtstatus
&&
2181 (initializecount
< 10));
2182 RT_CLEAR_PS_LEVEL(ppsc
,
2183 RT_RF_OFF_LEVL_HALT_NIC
);
2185 rtl_dbg(rtlpriv
, COMP_RF
, DBG_DMESG
,
2186 "Set ERFON slept:%d ms\n",
2187 jiffies_to_msecs(jiffies
-
2188 ppsc
->last_sleep_jiffies
));
2189 ppsc
->last_awake_jiffies
= jiffies
;
2190 rtl88ee_phy_set_rf_on(hw
);
2192 if (mac
->link_state
== MAC80211_LINKED
) {
2193 rtlpriv
->cfg
->ops
->led_control(hw
,
2196 rtlpriv
->cfg
->ops
->led_control(hw
,
2201 for (queue_id
= 0, i
= 0;
2202 queue_id
< RTL_PCI_MAX_TX_QUEUE_COUNT
;) {
2203 ring
= &pcipriv
->dev
.tx_ring
[queue_id
];
2204 if (queue_id
== BEACON_QUEUE
||
2205 skb_queue_len(&ring
->queue
) == 0) {
2209 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_WARNING
,
2210 "eRf Off/Sleep: %d times TcbBusyQueue[%d] =%d before doze!\n",
2212 skb_queue_len(&ring
->queue
));
2217 if (i
>= MAX_DOZE_WAITING_TIMES_9x
) {
2218 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_WARNING
,
2219 "\n ERFSLEEP: %d times TcbBusyQueue[%d] = %d !\n",
2220 MAX_DOZE_WAITING_TIMES_9x
,
2222 skb_queue_len(&ring
->queue
));
2227 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_HALT_NIC
) {
2228 rtl_dbg(rtlpriv
, COMP_RF
, DBG_DMESG
,
2229 "IPS Set eRf nic disable\n");
2230 rtl_ps_disable_nic(hw
);
2231 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
2233 if (ppsc
->rfoff_reason
== RF_CHANGE_BY_IPS
) {
2234 rtlpriv
->cfg
->ops
->led_control(hw
,
2237 rtlpriv
->cfg
->ops
->led_control(hw
,
2243 if (ppsc
->rfpwr_state
== ERFOFF
)
2245 for (queue_id
= 0, i
= 0;
2246 queue_id
< RTL_PCI_MAX_TX_QUEUE_COUNT
;) {
2247 ring
= &pcipriv
->dev
.tx_ring
[queue_id
];
2248 if (skb_queue_len(&ring
->queue
) == 0) {
2252 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_WARNING
,
2253 "eRf Off/Sleep: %d times TcbBusyQueue[%d] =%d before doze!\n",
2255 skb_queue_len(&ring
->queue
));
2260 if (i
>= MAX_DOZE_WAITING_TIMES_9x
) {
2261 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_WARNING
,
2262 "\n ERFSLEEP: %d times TcbBusyQueue[%d] = %d !\n",
2263 MAX_DOZE_WAITING_TIMES_9x
,
2265 skb_queue_len(&ring
->queue
));
2269 rtl_dbg(rtlpriv
, COMP_RF
, DBG_DMESG
,
2270 "Set ERFSLEEP awaked:%d ms\n",
2271 jiffies_to_msecs(jiffies
-
2272 ppsc
->last_awake_jiffies
));
2273 ppsc
->last_sleep_jiffies
= jiffies
;
2274 _rtl88ee_phy_set_rf_sleep(hw
);
2278 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_LOUD
,
2279 "switch case %#x not processed\n", rfpwr_state
);
2284 ppsc
->rfpwr_state
= rfpwr_state
;
2288 bool rtl88e_phy_set_rf_power_state(struct ieee80211_hw
*hw
,
2289 enum rf_pwrstate rfpwr_state
)
2291 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
2293 bool bresult
= false;
2295 if (rfpwr_state
== ppsc
->rfpwr_state
)
2297 bresult
= _rtl88ee_phy_set_rf_power_state(hw
, rfpwr_state
);