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
);
20 static bool _rtl88e_phy_bb8188e_config_parafile(struct ieee80211_hw
*hw
);
21 static bool _rtl88e_phy_config_mac_with_headerfile(struct ieee80211_hw
*hw
);
22 static bool phy_config_bb_with_headerfile(struct ieee80211_hw
*hw
,
24 static bool phy_config_bb_with_pghdr(struct ieee80211_hw
*hw
,
26 static void _rtl88e_phy_init_bb_rf_register_definition(struct ieee80211_hw
*hw
);
27 static bool _rtl88e_phy_set_sw_chnl_cmdarray(struct swchnlcmd
*cmdtable
,
28 u32 cmdtableidx
, u32 cmdtablesz
,
29 enum swchnlcmd_id cmdid
, u32 para1
,
30 u32 para2
, u32 msdelay
);
31 static bool _rtl88e_phy_sw_chnl_step_by_step(struct ieee80211_hw
*hw
,
32 u8 channel
, u8
*stage
, u8
*step
,
35 static long _rtl88e_phy_txpwr_idx_to_dbm(struct ieee80211_hw
*hw
,
36 enum wireless_mode wirelessmode
,
38 static void rtl88ee_phy_set_rf_on(struct ieee80211_hw
*hw
);
39 static void rtl88e_phy_set_io(struct ieee80211_hw
*hw
);
41 u32
rtl88e_phy_query_bb_reg(struct ieee80211_hw
*hw
, u32 regaddr
, u32 bitmask
)
43 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
44 u32 returnvalue
, originalvalue
, bitshift
;
46 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
47 "regaddr(%#x), bitmask(%#x)\n", regaddr
, bitmask
);
48 originalvalue
= rtl_read_dword(rtlpriv
, regaddr
);
49 bitshift
= _rtl88e_phy_calculate_bit_shift(bitmask
);
50 returnvalue
= (originalvalue
& bitmask
) >> bitshift
;
52 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
53 "BBR MASK=0x%x Addr[0x%x]=0x%x\n", bitmask
,
54 regaddr
, originalvalue
);
60 void rtl88e_phy_set_bb_reg(struct ieee80211_hw
*hw
,
61 u32 regaddr
, u32 bitmask
, u32 data
)
63 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
64 u32 originalvalue
, bitshift
;
66 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
67 "regaddr(%#x), bitmask(%#x), data(%#x)\n",
68 regaddr
, bitmask
, data
);
70 if (bitmask
!= MASKDWORD
) {
71 originalvalue
= rtl_read_dword(rtlpriv
, regaddr
);
72 bitshift
= _rtl88e_phy_calculate_bit_shift(bitmask
);
73 data
= ((originalvalue
& (~bitmask
)) | (data
<< bitshift
));
76 rtl_write_dword(rtlpriv
, regaddr
, data
);
78 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
79 "regaddr(%#x), bitmask(%#x), data(%#x)\n",
80 regaddr
, bitmask
, data
);
83 u32
rtl88e_phy_query_rf_reg(struct ieee80211_hw
*hw
,
84 enum radio_path rfpath
, u32 regaddr
, u32 bitmask
)
86 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
87 u32 original_value
, readback_value
, bitshift
;
89 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
90 "regaddr(%#x), rfpath(%#x), bitmask(%#x)\n",
91 regaddr
, rfpath
, bitmask
);
93 spin_lock(&rtlpriv
->locks
.rf_lock
);
96 original_value
= _rtl88e_phy_rf_serial_read(hw
, rfpath
, regaddr
);
97 bitshift
= _rtl88e_phy_calculate_bit_shift(bitmask
);
98 readback_value
= (original_value
& bitmask
) >> bitshift
;
100 spin_unlock(&rtlpriv
->locks
.rf_lock
);
102 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
103 "regaddr(%#x), rfpath(%#x), bitmask(%#x), original_value(%#x)\n",
104 regaddr
, rfpath
, bitmask
, original_value
);
105 return readback_value
;
108 void rtl88e_phy_set_rf_reg(struct ieee80211_hw
*hw
,
109 enum radio_path rfpath
,
110 u32 regaddr
, u32 bitmask
, u32 data
)
112 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
113 u32 original_value
, bitshift
;
115 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
116 "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
117 regaddr
, bitmask
, data
, rfpath
);
119 spin_lock(&rtlpriv
->locks
.rf_lock
);
121 if (bitmask
!= RFREG_OFFSET_MASK
) {
122 original_value
= _rtl88e_phy_rf_serial_read(hw
,
125 bitshift
= _rtl88e_phy_calculate_bit_shift(bitmask
);
127 ((original_value
& (~bitmask
)) |
131 _rtl88e_phy_rf_serial_write(hw
, rfpath
, regaddr
, data
);
134 spin_unlock(&rtlpriv
->locks
.rf_lock
);
136 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
137 "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
138 regaddr
, bitmask
, data
, rfpath
);
141 static u32
_rtl88e_phy_rf_serial_read(struct ieee80211_hw
*hw
,
142 enum radio_path rfpath
, u32 offset
)
144 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
145 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
146 struct bb_reg_def
*pphyreg
= &rtlphy
->phyreg_def
[rfpath
];
148 u32 tmplong
, tmplong2
;
154 if (RT_CANNOT_IO(hw
)) {
155 pr_err("return all one\n");
158 tmplong
= rtl_get_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER2
, MASKDWORD
);
159 if (rfpath
== RF90_PATH_A
)
162 tmplong2
= rtl_get_bbreg(hw
, pphyreg
->rfhssi_para2
, MASKDWORD
);
163 tmplong2
= (tmplong2
& (~BLSSIREADADDRESS
)) |
164 (newoffset
<< 23) | BLSSIREADEDGE
;
165 rtl_set_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER2
, MASKDWORD
,
166 tmplong
& (~BLSSIREADEDGE
));
168 rtl_set_bbreg(hw
, pphyreg
->rfhssi_para2
, MASKDWORD
, tmplong2
);
170 if (rfpath
== RF90_PATH_A
)
171 rfpi_enable
= (u8
)rtl_get_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER1
,
173 else if (rfpath
== RF90_PATH_B
)
174 rfpi_enable
= (u8
)rtl_get_bbreg(hw
, RFPGA0_XB_HSSIPARAMETER1
,
177 retvalue
= rtl_get_bbreg(hw
, pphyreg
->rf_rbpi
,
180 retvalue
= rtl_get_bbreg(hw
, pphyreg
->rf_rb
,
182 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
183 "RFR-%d Addr[0x%x]=0x%x\n",
184 rfpath
, pphyreg
->rf_rb
, retvalue
);
188 static void _rtl88e_phy_rf_serial_write(struct ieee80211_hw
*hw
,
189 enum radio_path rfpath
, u32 offset
,
194 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
195 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
196 struct bb_reg_def
*pphyreg
= &rtlphy
->phyreg_def
[rfpath
];
198 if (RT_CANNOT_IO(hw
)) {
204 data_and_addr
= ((newoffset
<< 20) | (data
& 0x000fffff)) & 0x0fffffff;
205 rtl_set_bbreg(hw
, pphyreg
->rf3wire_offset
, MASKDWORD
, data_and_addr
);
206 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
207 "RFW-%d Addr[0x%x]=0x%x\n",
208 rfpath
, pphyreg
->rf3wire_offset
, data_and_addr
);
211 static u32
_rtl88e_phy_calculate_bit_shift(u32 bitmask
)
215 for (i
= 0; i
<= 31; i
++) {
216 if (((bitmask
>> i
) & 0x1) == 1)
222 bool rtl88e_phy_mac_config(struct ieee80211_hw
*hw
)
224 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
225 bool rtstatus
= _rtl88e_phy_config_mac_with_headerfile(hw
);
227 rtl_write_byte(rtlpriv
, 0x04CA, 0x0B);
231 bool rtl88e_phy_bb_config(struct ieee80211_hw
*hw
)
233 bool rtstatus
= true;
234 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
236 u8 b_reg_hwparafile
= 1;
238 _rtl88e_phy_init_bb_rf_register_definition(hw
);
239 regval
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
);
240 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
,
241 regval
| BIT(13) | BIT(0) | BIT(1));
243 rtl_write_byte(rtlpriv
, REG_RF_CTRL
, RF_EN
| RF_RSTB
| RF_SDMRSTB
);
244 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
,
245 FEN_PPLL
| FEN_PCIEA
| FEN_DIO_PCIE
|
246 FEN_BB_GLB_RSTN
| FEN_BBRSTB
);
247 tmp
= rtl_read_dword(rtlpriv
, 0x4c);
248 rtl_write_dword(rtlpriv
, 0x4c, tmp
| BIT(23));
249 if (b_reg_hwparafile
== 1)
250 rtstatus
= _rtl88e_phy_bb8188e_config_parafile(hw
);
254 bool rtl88e_phy_rf_config(struct ieee80211_hw
*hw
)
256 return rtl88e_phy_rf6052_config(hw
);
259 static bool _rtl88e_check_condition(struct ieee80211_hw
*hw
,
262 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
263 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
264 u32 _board
= rtlefuse
->board_type
; /*need efuse define*/
265 u32 _interface
= rtlhal
->interface
;
266 u32 _platform
= 0x08;/*SupportPlatform */
269 if (condition
== 0xCDCDCDCD)
272 cond
= condition
& 0xFF;
273 if ((_board
& cond
) == 0 && cond
!= 0x1F)
276 cond
= condition
& 0xFF00;
278 if ((_interface
& cond
) == 0 && cond
!= 0x07)
281 cond
= condition
& 0xFF0000;
283 if ((_platform
& cond
) == 0 && cond
!= 0x0F)
288 static void _rtl8188e_config_rf_reg(struct ieee80211_hw
*hw
, u32 addr
,
289 u32 data
, enum radio_path rfpath
,
294 } else if (addr
== 0xfd) {
296 } else if (addr
== 0xfc) {
298 } else if (addr
== 0xfb) {
300 } else if (addr
== 0xfa) {
302 } else if (addr
== 0xf9) {
305 rtl_set_rfreg(hw
, rfpath
, regaddr
,
312 static void _rtl8188e_config_rf_radio_a(struct ieee80211_hw
*hw
,
315 u32 content
= 0x1000; /*RF Content: radio_a_txt*/
316 u32 maskforphyset
= (u32
)(content
& 0xE000);
318 _rtl8188e_config_rf_reg(hw
, addr
, data
, RF90_PATH_A
,
319 addr
| maskforphyset
);
322 static void _rtl8188e_config_bb_reg(struct ieee80211_hw
*hw
,
327 } else if (addr
== 0xfd) {
329 } else if (addr
== 0xfc) {
331 } else if (addr
== 0xfb) {
333 } else if (addr
== 0xfa) {
335 } else if (addr
== 0xf9) {
338 rtl_set_bbreg(hw
, addr
, MASKDWORD
, data
);
343 static bool _rtl88e_phy_bb8188e_config_parafile(struct ieee80211_hw
*hw
)
345 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
346 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
347 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
350 rtstatus
= phy_config_bb_with_headerfile(hw
, BASEBAND_CONFIG_PHY_REG
);
352 pr_err("Write BB Reg Fail!!\n");
356 if (!rtlefuse
->autoload_failflag
) {
357 rtlphy
->pwrgroup_cnt
= 0;
359 phy_config_bb_with_pghdr(hw
, BASEBAND_CONFIG_PHY_REG
);
362 pr_err("BB_PG Reg Fail!!\n");
366 phy_config_bb_with_headerfile(hw
, BASEBAND_CONFIG_AGC_TAB
);
368 pr_err("AGC Table Fail\n");
371 rtlphy
->cck_high_power
=
372 (bool)(rtl_get_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER2
, 0x200));
377 static bool _rtl88e_phy_config_mac_with_headerfile(struct ieee80211_hw
*hw
)
379 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
384 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
, "Read Rtl8188EMACPHY_Array\n");
385 arraylength
= RTL8188EEMAC_1T_ARRAYLEN
;
386 ptrarray
= RTL8188EEMAC_1T_ARRAY
;
387 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
388 "Img:RTL8188EEMAC_1T_ARRAY LEN %d\n", arraylength
);
389 for (i
= 0; i
< arraylength
; i
= i
+ 2)
390 rtl_write_byte(rtlpriv
, ptrarray
[i
], (u8
)ptrarray
[i
+ 1]);
394 #define READ_NEXT_PAIR(v1, v2, i) \
396 i += 2; v1 = array_table[i]; \
397 v2 = array_table[i+1]; \
400 static void handle_branch1(struct ieee80211_hw
*hw
, u16 arraylen
,
407 for (i
= 0; i
< arraylen
; i
= i
+ 2) {
409 v2
= array_table
[i
+1];
410 if (v1
< 0xcdcdcdcd) {
411 _rtl8188e_config_bb_reg(hw
, v1
, v2
);
412 } else { /*This line is the start line of branch.*/
413 /* to protect READ_NEXT_PAIR not overrun */
414 if (i
>= arraylen
- 2)
417 if (!_rtl88e_check_condition(hw
, array_table
[i
])) {
418 /*Discard the following (offset, data) pairs*/
419 READ_NEXT_PAIR(v1
, v2
, i
);
420 while (v2
!= 0xDEAD &&
422 v2
!= 0xCDCD && i
< arraylen
- 2)
423 READ_NEXT_PAIR(v1
, v2
, i
);
424 i
-= 2; /* prevent from for-loop += 2*/
425 } else { /* Configure matched pairs and skip
428 READ_NEXT_PAIR(v1
, v2
, i
);
429 while (v2
!= 0xDEAD &&
431 v2
!= 0xCDCD && i
< arraylen
- 2) {
432 _rtl8188e_config_bb_reg(hw
, v1
, v2
);
433 READ_NEXT_PAIR(v1
, v2
, i
);
436 while (v2
!= 0xDEAD && i
< arraylen
- 2)
437 READ_NEXT_PAIR(v1
, v2
, i
);
443 static void handle_branch2(struct ieee80211_hw
*hw
, u16 arraylen
,
446 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
451 for (i
= 0; i
< arraylen
; i
= i
+ 2) {
453 v2
= array_table
[i
+1];
454 if (v1
< 0xCDCDCDCD) {
455 rtl_set_bbreg(hw
, array_table
[i
], MASKDWORD
,
459 } else { /*This line is the start line of branch.*/
460 /* to protect READ_NEXT_PAIR not overrun */
461 if (i
>= arraylen
- 2)
464 if (!_rtl88e_check_condition(hw
, array_table
[i
])) {
465 /*Discard the following (offset, data) pairs*/
466 READ_NEXT_PAIR(v1
, v2
, i
);
467 while (v2
!= 0xDEAD &&
469 v2
!= 0xCDCD && i
< arraylen
- 2)
470 READ_NEXT_PAIR(v1
, v2
, i
);
471 i
-= 2; /* prevent from for-loop += 2*/
472 } else { /* Configure matched pairs and skip
475 READ_NEXT_PAIR(v1
, v2
, i
);
476 while (v2
!= 0xDEAD &&
478 v2
!= 0xCDCD && i
< arraylen
- 2) {
479 rtl_set_bbreg(hw
, array_table
[i
],
483 READ_NEXT_PAIR(v1
, v2
, i
);
486 while (v2
!= 0xDEAD && i
< arraylen
- 2)
487 READ_NEXT_PAIR(v1
, v2
, i
);
490 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
491 "The agctab_array_table[0] is %x Rtl818EEPHY_REGArray[1] is %x\n",
492 array_table
[i
], array_table
[i
+ 1]);
496 static bool phy_config_bb_with_headerfile(struct ieee80211_hw
*hw
,
502 if (configtype
== BASEBAND_CONFIG_PHY_REG
) {
503 arraylen
= RTL8188EEPHY_REG_1TARRAYLEN
;
504 array_table
= RTL8188EEPHY_REG_1TARRAY
;
505 handle_branch1(hw
, arraylen
, array_table
);
506 } else if (configtype
== BASEBAND_CONFIG_AGC_TAB
) {
507 arraylen
= RTL8188EEAGCTAB_1TARRAYLEN
;
508 array_table
= RTL8188EEAGCTAB_1TARRAY
;
509 handle_branch2(hw
, arraylen
, array_table
);
514 static void store_pwrindex_rate_offset(struct ieee80211_hw
*hw
,
515 u32 regaddr
, u32 bitmask
,
518 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
519 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
520 int count
= rtlphy
->pwrgroup_cnt
;
522 if (regaddr
== RTXAGC_A_RATE18_06
) {
523 rtlphy
->mcs_txpwrlevel_origoffset
[count
][0] = data
;
524 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
525 "MCSTxPowerLevelOriginalOffset[%d][0] = 0x%x\n",
527 rtlphy
->mcs_txpwrlevel_origoffset
[count
][0]);
529 if (regaddr
== RTXAGC_A_RATE54_24
) {
530 rtlphy
->mcs_txpwrlevel_origoffset
[count
][1] = data
;
531 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
532 "MCSTxPowerLevelOriginalOffset[%d][1] = 0x%x\n",
534 rtlphy
->mcs_txpwrlevel_origoffset
[count
][1]);
536 if (regaddr
== RTXAGC_A_CCK1_MCS32
) {
537 rtlphy
->mcs_txpwrlevel_origoffset
[count
][6] = data
;
538 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
539 "MCSTxPowerLevelOriginalOffset[%d][6] = 0x%x\n",
541 rtlphy
->mcs_txpwrlevel_origoffset
[count
][6]);
543 if (regaddr
== RTXAGC_B_CCK11_A_CCK2_11
&& bitmask
== 0xffffff00) {
544 rtlphy
->mcs_txpwrlevel_origoffset
[count
][7] = data
;
545 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
546 "MCSTxPowerLevelOriginalOffset[%d][7] = 0x%x\n",
548 rtlphy
->mcs_txpwrlevel_origoffset
[count
][7]);
550 if (regaddr
== RTXAGC_A_MCS03_MCS00
) {
551 rtlphy
->mcs_txpwrlevel_origoffset
[count
][2] = data
;
552 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
553 "MCSTxPowerLevelOriginalOffset[%d][2] = 0x%x\n",
555 rtlphy
->mcs_txpwrlevel_origoffset
[count
][2]);
557 if (regaddr
== RTXAGC_A_MCS07_MCS04
) {
558 rtlphy
->mcs_txpwrlevel_origoffset
[count
][3] = data
;
559 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
560 "MCSTxPowerLevelOriginalOffset[%d][3] = 0x%x\n",
562 rtlphy
->mcs_txpwrlevel_origoffset
[count
][3]);
564 if (regaddr
== RTXAGC_A_MCS11_MCS08
) {
565 rtlphy
->mcs_txpwrlevel_origoffset
[count
][4] = data
;
566 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
567 "MCSTxPowerLevelOriginalOffset[%d][4] = 0x%x\n",
569 rtlphy
->mcs_txpwrlevel_origoffset
[count
][4]);
571 if (regaddr
== RTXAGC_A_MCS15_MCS12
) {
572 rtlphy
->mcs_txpwrlevel_origoffset
[count
][5] = data
;
573 if (get_rf_type(rtlphy
) == RF_1T1R
) {
575 rtlphy
->pwrgroup_cnt
= count
;
577 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
578 "MCSTxPowerLevelOriginalOffset[%d][5] = 0x%x\n",
580 rtlphy
->mcs_txpwrlevel_origoffset
[count
][5]);
582 if (regaddr
== RTXAGC_B_RATE18_06
) {
583 rtlphy
->mcs_txpwrlevel_origoffset
[count
][8] = data
;
584 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
585 "MCSTxPowerLevelOriginalOffset[%d][8] = 0x%x\n",
587 rtlphy
->mcs_txpwrlevel_origoffset
[count
][8]);
589 if (regaddr
== RTXAGC_B_RATE54_24
) {
590 rtlphy
->mcs_txpwrlevel_origoffset
[count
][9] = data
;
591 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
592 "MCSTxPowerLevelOriginalOffset[%d][9] = 0x%x\n",
594 rtlphy
->mcs_txpwrlevel_origoffset
[count
][9]);
596 if (regaddr
== RTXAGC_B_CCK1_55_MCS32
) {
597 rtlphy
->mcs_txpwrlevel_origoffset
[count
][14] = data
;
598 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
599 "MCSTxPowerLevelOriginalOffset[%d][14] = 0x%x\n",
601 rtlphy
->mcs_txpwrlevel_origoffset
[count
][14]);
603 if (regaddr
== RTXAGC_B_CCK11_A_CCK2_11
&& bitmask
== 0x000000ff) {
604 rtlphy
->mcs_txpwrlevel_origoffset
[count
][15] = data
;
605 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
606 "MCSTxPowerLevelOriginalOffset[%d][15] = 0x%x\n",
608 rtlphy
->mcs_txpwrlevel_origoffset
[count
][15]);
610 if (regaddr
== RTXAGC_B_MCS03_MCS00
) {
611 rtlphy
->mcs_txpwrlevel_origoffset
[count
][10] = data
;
612 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
613 "MCSTxPowerLevelOriginalOffset[%d][10] = 0x%x\n",
615 rtlphy
->mcs_txpwrlevel_origoffset
[count
][10]);
617 if (regaddr
== RTXAGC_B_MCS07_MCS04
) {
618 rtlphy
->mcs_txpwrlevel_origoffset
[count
][11] = data
;
619 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
620 "MCSTxPowerLevelOriginalOffset[%d][11] = 0x%x\n",
622 rtlphy
->mcs_txpwrlevel_origoffset
[count
][11]);
624 if (regaddr
== RTXAGC_B_MCS11_MCS08
) {
625 rtlphy
->mcs_txpwrlevel_origoffset
[count
][12] = data
;
626 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
627 "MCSTxPowerLevelOriginalOffset[%d][12] = 0x%x\n",
629 rtlphy
->mcs_txpwrlevel_origoffset
[count
][12]);
631 if (regaddr
== RTXAGC_B_MCS15_MCS12
) {
632 rtlphy
->mcs_txpwrlevel_origoffset
[count
][13] = data
;
633 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
634 "MCSTxPowerLevelOriginalOffset[%d][13] = 0x%x\n",
636 rtlphy
->mcs_txpwrlevel_origoffset
[count
][13]);
637 if (get_rf_type(rtlphy
) != RF_1T1R
) {
639 rtlphy
->pwrgroup_cnt
= count
;
644 static bool phy_config_bb_with_pghdr(struct ieee80211_hw
*hw
, u8 configtype
)
646 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
649 u16 phy_reg_page_len
;
652 phy_reg_page_len
= RTL8188EEPHY_REG_ARRAY_PGLEN
;
653 phy_reg_page
= RTL8188EEPHY_REG_ARRAY_PG
;
655 if (configtype
== BASEBAND_CONFIG_PHY_REG
) {
656 for (i
= 0; i
< phy_reg_page_len
; i
= i
+ 3) {
657 v1
= phy_reg_page
[i
];
658 v2
= phy_reg_page
[i
+1];
660 if (v1
< 0xcdcdcdcd) {
661 if (phy_reg_page
[i
] == 0xfe)
663 else if (phy_reg_page
[i
] == 0xfd)
665 else if (phy_reg_page
[i
] == 0xfc)
667 else if (phy_reg_page
[i
] == 0xfb)
669 else if (phy_reg_page
[i
] == 0xfa)
671 else if (phy_reg_page
[i
] == 0xf9)
674 store_pwrindex_rate_offset(hw
, phy_reg_page
[i
],
676 phy_reg_page
[i
+ 2]);
679 if (!_rtl88e_check_condition(hw
,
681 /*don't need the hw_body*/
682 i
+= 2; /* skip the pair of expression*/
683 /* to protect 'i+1' 'i+2' not overrun */
684 if (i
>= phy_reg_page_len
- 2)
687 v1
= phy_reg_page
[i
];
688 v2
= phy_reg_page
[i
+1];
689 while (v2
!= 0xDEAD &&
690 i
< phy_reg_page_len
- 5) {
692 v1
= phy_reg_page
[i
];
693 v2
= phy_reg_page
[i
+1];
699 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
700 "configtype != BaseBand_Config_PHY_REG\n");
705 #define READ_NEXT_RF_PAIR(v1, v2, i) \
708 v1 = radioa_array_table[i]; \
709 v2 = radioa_array_table[i+1]; \
712 static void process_path_a(struct ieee80211_hw
*hw
,
714 u32
*radioa_array_table
)
716 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
720 for (i
= 0; i
< radioa_arraylen
; i
= i
+ 2) {
721 v1
= radioa_array_table
[i
];
722 v2
= radioa_array_table
[i
+1];
723 if (v1
< 0xcdcdcdcd) {
724 _rtl8188e_config_rf_radio_a(hw
, v1
, v2
);
725 } else { /*This line is the start line of branch.*/
726 /* to protect READ_NEXT_PAIR not overrun */
727 if (i
>= radioa_arraylen
- 2)
730 if (!_rtl88e_check_condition(hw
, radioa_array_table
[i
])) {
731 /*Discard the following (offset, data) pairs*/
732 READ_NEXT_RF_PAIR(v1
, v2
, i
);
733 while (v2
!= 0xDEAD &&
736 i
< radioa_arraylen
- 2) {
737 READ_NEXT_RF_PAIR(v1
, v2
, i
);
739 i
-= 2; /* prevent from for-loop += 2*/
740 } else { /* Configure matched pairs and
741 * skip to end of if-else.
743 READ_NEXT_RF_PAIR(v1
, v2
, i
);
744 while (v2
!= 0xDEAD &&
747 i
< radioa_arraylen
- 2) {
748 _rtl8188e_config_rf_radio_a(hw
, v1
, v2
);
749 READ_NEXT_RF_PAIR(v1
, v2
, i
);
752 while (v2
!= 0xDEAD &&
753 i
< radioa_arraylen
- 2)
754 READ_NEXT_RF_PAIR(v1
, v2
, i
);
759 if (rtlhal
->oem_id
== RT_CID_819X_HP
)
760 _rtl8188e_config_rf_radio_a(hw
, 0x52, 0x7E4BD);
763 bool rtl88e_phy_config_rf_with_headerfile(struct ieee80211_hw
*hw
,
764 enum radio_path rfpath
)
766 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
767 u32
*radioa_array_table
;
770 radioa_arraylen
= RTL8188EE_RADIOA_1TARRAYLEN
;
771 radioa_array_table
= RTL8188EE_RADIOA_1TARRAY
;
772 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
773 "Radio_A:RTL8188EE_RADIOA_1TARRAY %d\n", radioa_arraylen
);
774 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Radio No %x\n", rfpath
);
777 process_path_a(hw
, radioa_arraylen
, radioa_array_table
);
787 void rtl88e_phy_get_hw_reg_originalvalue(struct ieee80211_hw
*hw
)
789 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
790 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
792 rtlphy
->default_initialgain
[0] =
793 (u8
)rtl_get_bbreg(hw
, ROFDM0_XAAGCCORE1
, MASKBYTE0
);
794 rtlphy
->default_initialgain
[1] =
795 (u8
)rtl_get_bbreg(hw
, ROFDM0_XBAGCCORE1
, MASKBYTE0
);
796 rtlphy
->default_initialgain
[2] =
797 (u8
)rtl_get_bbreg(hw
, ROFDM0_XCAGCCORE1
, MASKBYTE0
);
798 rtlphy
->default_initialgain
[3] =
799 (u8
)rtl_get_bbreg(hw
, ROFDM0_XDAGCCORE1
, MASKBYTE0
);
801 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
802 "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x\n",
803 rtlphy
->default_initialgain
[0],
804 rtlphy
->default_initialgain
[1],
805 rtlphy
->default_initialgain
[2],
806 rtlphy
->default_initialgain
[3]);
808 rtlphy
->framesync
= (u8
)rtl_get_bbreg(hw
, ROFDM0_RXDETECTOR3
,
810 rtlphy
->framesync_c34
= rtl_get_bbreg(hw
, ROFDM0_RXDETECTOR2
,
813 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
814 "Default framesync (0x%x) = 0x%x\n",
815 ROFDM0_RXDETECTOR3
, rtlphy
->framesync
);
818 static void _rtl88e_phy_init_bb_rf_register_definition(struct ieee80211_hw
*hw
)
820 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
821 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
823 rtlphy
->phyreg_def
[RF90_PATH_A
].rfintfs
= RFPGA0_XAB_RFINTERFACESW
;
824 rtlphy
->phyreg_def
[RF90_PATH_B
].rfintfs
= RFPGA0_XAB_RFINTERFACESW
;
825 rtlphy
->phyreg_def
[RF90_PATH_C
].rfintfs
= RFPGA0_XCD_RFINTERFACESW
;
826 rtlphy
->phyreg_def
[RF90_PATH_D
].rfintfs
= RFPGA0_XCD_RFINTERFACESW
;
828 rtlphy
->phyreg_def
[RF90_PATH_A
].rfintfi
= RFPGA0_XAB_RFINTERFACERB
;
829 rtlphy
->phyreg_def
[RF90_PATH_B
].rfintfi
= RFPGA0_XAB_RFINTERFACERB
;
830 rtlphy
->phyreg_def
[RF90_PATH_C
].rfintfi
= RFPGA0_XCD_RFINTERFACERB
;
831 rtlphy
->phyreg_def
[RF90_PATH_D
].rfintfi
= RFPGA0_XCD_RFINTERFACERB
;
833 rtlphy
->phyreg_def
[RF90_PATH_A
].rfintfo
= RFPGA0_XA_RFINTERFACEOE
;
834 rtlphy
->phyreg_def
[RF90_PATH_B
].rfintfo
= RFPGA0_XB_RFINTERFACEOE
;
836 rtlphy
->phyreg_def
[RF90_PATH_A
].rfintfe
= RFPGA0_XA_RFINTERFACEOE
;
837 rtlphy
->phyreg_def
[RF90_PATH_B
].rfintfe
= RFPGA0_XB_RFINTERFACEOE
;
839 rtlphy
->phyreg_def
[RF90_PATH_A
].rf3wire_offset
=
840 RFPGA0_XA_LSSIPARAMETER
;
841 rtlphy
->phyreg_def
[RF90_PATH_B
].rf3wire_offset
=
842 RFPGA0_XB_LSSIPARAMETER
;
844 rtlphy
->phyreg_def
[RF90_PATH_A
].rflssi_select
= RFPGA0_XAB_RFPARAMETER
;
845 rtlphy
->phyreg_def
[RF90_PATH_B
].rflssi_select
= RFPGA0_XAB_RFPARAMETER
;
846 rtlphy
->phyreg_def
[RF90_PATH_C
].rflssi_select
= RFPGA0_XCD_RFPARAMETER
;
847 rtlphy
->phyreg_def
[RF90_PATH_D
].rflssi_select
= RFPGA0_XCD_RFPARAMETER
;
849 rtlphy
->phyreg_def
[RF90_PATH_A
].rftxgain_stage
= RFPGA0_TXGAINSTAGE
;
850 rtlphy
->phyreg_def
[RF90_PATH_B
].rftxgain_stage
= RFPGA0_TXGAINSTAGE
;
851 rtlphy
->phyreg_def
[RF90_PATH_C
].rftxgain_stage
= RFPGA0_TXGAINSTAGE
;
852 rtlphy
->phyreg_def
[RF90_PATH_D
].rftxgain_stage
= RFPGA0_TXGAINSTAGE
;
854 rtlphy
->phyreg_def
[RF90_PATH_A
].rfhssi_para1
= RFPGA0_XA_HSSIPARAMETER1
;
855 rtlphy
->phyreg_def
[RF90_PATH_B
].rfhssi_para1
= RFPGA0_XB_HSSIPARAMETER1
;
857 rtlphy
->phyreg_def
[RF90_PATH_A
].rfhssi_para2
= RFPGA0_XA_HSSIPARAMETER2
;
858 rtlphy
->phyreg_def
[RF90_PATH_B
].rfhssi_para2
= RFPGA0_XB_HSSIPARAMETER2
;
860 rtlphy
->phyreg_def
[RF90_PATH_A
].rfsw_ctrl
=
861 RFPGA0_XAB_SWITCHCONTROL
;
862 rtlphy
->phyreg_def
[RF90_PATH_B
].rfsw_ctrl
=
863 RFPGA0_XAB_SWITCHCONTROL
;
864 rtlphy
->phyreg_def
[RF90_PATH_C
].rfsw_ctrl
=
865 RFPGA0_XCD_SWITCHCONTROL
;
866 rtlphy
->phyreg_def
[RF90_PATH_D
].rfsw_ctrl
=
867 RFPGA0_XCD_SWITCHCONTROL
;
869 rtlphy
->phyreg_def
[RF90_PATH_A
].rfagc_control1
= ROFDM0_XAAGCCORE1
;
870 rtlphy
->phyreg_def
[RF90_PATH_B
].rfagc_control1
= ROFDM0_XBAGCCORE1
;
871 rtlphy
->phyreg_def
[RF90_PATH_C
].rfagc_control1
= ROFDM0_XCAGCCORE1
;
872 rtlphy
->phyreg_def
[RF90_PATH_D
].rfagc_control1
= ROFDM0_XDAGCCORE1
;
874 rtlphy
->phyreg_def
[RF90_PATH_A
].rfagc_control2
= ROFDM0_XAAGCCORE2
;
875 rtlphy
->phyreg_def
[RF90_PATH_B
].rfagc_control2
= ROFDM0_XBAGCCORE2
;
876 rtlphy
->phyreg_def
[RF90_PATH_C
].rfagc_control2
= ROFDM0_XCAGCCORE2
;
877 rtlphy
->phyreg_def
[RF90_PATH_D
].rfagc_control2
= ROFDM0_XDAGCCORE2
;
879 rtlphy
->phyreg_def
[RF90_PATH_A
].rfrxiq_imbal
= ROFDM0_XARXIQIMBALANCE
;
880 rtlphy
->phyreg_def
[RF90_PATH_B
].rfrxiq_imbal
= ROFDM0_XBRXIQIMBALANCE
;
881 rtlphy
->phyreg_def
[RF90_PATH_C
].rfrxiq_imbal
= ROFDM0_XCRXIQIMBANLANCE
;
882 rtlphy
->phyreg_def
[RF90_PATH_D
].rfrxiq_imbal
= ROFDM0_XDRXIQIMBALANCE
;
884 rtlphy
->phyreg_def
[RF90_PATH_A
].rfrx_afe
= ROFDM0_XARXAFE
;
885 rtlphy
->phyreg_def
[RF90_PATH_B
].rfrx_afe
= ROFDM0_XBRXAFE
;
886 rtlphy
->phyreg_def
[RF90_PATH_C
].rfrx_afe
= ROFDM0_XCRXAFE
;
887 rtlphy
->phyreg_def
[RF90_PATH_D
].rfrx_afe
= ROFDM0_XDRXAFE
;
889 rtlphy
->phyreg_def
[RF90_PATH_A
].rftxiq_imbal
= ROFDM0_XATXIQIMBALANCE
;
890 rtlphy
->phyreg_def
[RF90_PATH_B
].rftxiq_imbal
= ROFDM0_XBTXIQIMBALANCE
;
891 rtlphy
->phyreg_def
[RF90_PATH_C
].rftxiq_imbal
= ROFDM0_XCTXIQIMBALANCE
;
892 rtlphy
->phyreg_def
[RF90_PATH_D
].rftxiq_imbal
= ROFDM0_XDTXIQIMBALANCE
;
894 rtlphy
->phyreg_def
[RF90_PATH_A
].rftx_afe
= ROFDM0_XATXAFE
;
895 rtlphy
->phyreg_def
[RF90_PATH_B
].rftx_afe
= ROFDM0_XBTXAFE
;
897 rtlphy
->phyreg_def
[RF90_PATH_A
].rf_rb
= RFPGA0_XA_LSSIREADBACK
;
898 rtlphy
->phyreg_def
[RF90_PATH_B
].rf_rb
= RFPGA0_XB_LSSIREADBACK
;
900 rtlphy
->phyreg_def
[RF90_PATH_A
].rf_rbpi
= TRANSCEIVEA_HSPI_READBACK
;
901 rtlphy
->phyreg_def
[RF90_PATH_B
].rf_rbpi
= TRANSCEIVEB_HSPI_READBACK
;
904 void rtl88e_phy_get_txpower_level(struct ieee80211_hw
*hw
, long *powerlevel
)
906 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
907 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
911 txpwr_level
= rtlphy
->cur_cck_txpwridx
;
912 txpwr_dbm
= _rtl88e_phy_txpwr_idx_to_dbm(hw
,
913 WIRELESS_MODE_B
, txpwr_level
);
914 txpwr_level
= rtlphy
->cur_ofdm24g_txpwridx
;
915 if (_rtl88e_phy_txpwr_idx_to_dbm(hw
,
917 txpwr_level
) > txpwr_dbm
)
919 _rtl88e_phy_txpwr_idx_to_dbm(hw
, WIRELESS_MODE_G
,
921 txpwr_level
= rtlphy
->cur_ofdm24g_txpwridx
;
922 if (_rtl88e_phy_txpwr_idx_to_dbm(hw
,
924 txpwr_level
) > txpwr_dbm
)
926 _rtl88e_phy_txpwr_idx_to_dbm(hw
, WIRELESS_MODE_N_24G
,
928 *powerlevel
= txpwr_dbm
;
931 static void handle_path_a(struct rtl_efuse
*rtlefuse
, u8 index
,
932 u8
*cckpowerlevel
, u8
*ofdmpowerlevel
,
933 u8
*bw20powerlevel
, u8
*bw40powerlevel
)
935 cckpowerlevel
[RF90_PATH_A
] =
936 rtlefuse
->txpwrlevel_cck
[RF90_PATH_A
][index
];
938 if (rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][index
] > 0x0f)
939 bw20powerlevel
[RF90_PATH_A
] =
940 rtlefuse
->txpwrlevel_ht40_1s
[RF90_PATH_A
][index
] -
941 (~(rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][index
]) + 1);
943 bw20powerlevel
[RF90_PATH_A
] =
944 rtlefuse
->txpwrlevel_ht40_1s
[RF90_PATH_A
][index
] +
945 rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][index
];
946 if (rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][index
] > 0xf)
947 ofdmpowerlevel
[RF90_PATH_A
] =
948 rtlefuse
->txpwrlevel_ht40_1s
[RF90_PATH_A
][index
] -
949 (~(rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][index
])+1);
951 ofdmpowerlevel
[RF90_PATH_A
] =
952 rtlefuse
->txpwrlevel_ht40_1s
[RF90_PATH_A
][index
] +
953 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][index
];
954 bw40powerlevel
[RF90_PATH_A
] =
955 rtlefuse
->txpwrlevel_ht40_1s
[RF90_PATH_A
][index
];
958 static void _rtl88e_get_txpower_index(struct ieee80211_hw
*hw
, u8 channel
,
959 u8
*cckpowerlevel
, u8
*ofdmpowerlevel
,
960 u8
*bw20powerlevel
, u8
*bw40powerlevel
)
962 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
963 u8 index
= (channel
- 1);
966 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
967 if (rf_path
== RF90_PATH_A
) {
968 handle_path_a(rtlefuse
, index
, cckpowerlevel
,
969 ofdmpowerlevel
, bw20powerlevel
,
971 } else if (rf_path
== RF90_PATH_B
) {
972 cckpowerlevel
[RF90_PATH_B
] =
973 rtlefuse
->txpwrlevel_cck
[RF90_PATH_B
][index
];
974 bw20powerlevel
[RF90_PATH_B
] =
975 rtlefuse
->txpwrlevel_ht40_1s
[RF90_PATH_B
][index
] +
976 rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][index
];
977 ofdmpowerlevel
[RF90_PATH_B
] =
978 rtlefuse
->txpwrlevel_ht40_1s
[RF90_PATH_B
][index
] +
979 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_B
][index
];
980 bw40powerlevel
[RF90_PATH_B
] =
981 rtlefuse
->txpwrlevel_ht40_1s
[RF90_PATH_B
][index
];
987 static void _rtl88e_ccxpower_index_check(struct ieee80211_hw
*hw
,
988 u8 channel
, u8
*cckpowerlevel
,
989 u8
*ofdmpowerlevel
, u8
*bw20powerlevel
,
992 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
993 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
995 rtlphy
->cur_cck_txpwridx
= cckpowerlevel
[0];
996 rtlphy
->cur_ofdm24g_txpwridx
= ofdmpowerlevel
[0];
997 rtlphy
->cur_bw20_txpwridx
= bw20powerlevel
[0];
998 rtlphy
->cur_bw40_txpwridx
= bw40powerlevel
[0];
1002 void rtl88e_phy_set_txpower_level(struct ieee80211_hw
*hw
, u8 channel
)
1004 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1005 u8 cckpowerlevel
[MAX_TX_COUNT
] = {0};
1006 u8 ofdmpowerlevel
[MAX_TX_COUNT
] = {0};
1007 u8 bw20powerlevel
[MAX_TX_COUNT
] = {0};
1008 u8 bw40powerlevel
[MAX_TX_COUNT
] = {0};
1010 if (!rtlefuse
->txpwr_fromeprom
)
1012 _rtl88e_get_txpower_index(hw
, channel
,
1013 &cckpowerlevel
[0], &ofdmpowerlevel
[0],
1014 &bw20powerlevel
[0], &bw40powerlevel
[0]);
1015 _rtl88e_ccxpower_index_check(hw
, channel
,
1016 &cckpowerlevel
[0], &ofdmpowerlevel
[0],
1017 &bw20powerlevel
[0], &bw40powerlevel
[0]);
1018 rtl88e_phy_rf6052_set_cck_txpower(hw
, &cckpowerlevel
[0]);
1019 rtl88e_phy_rf6052_set_ofdm_txpower(hw
, &ofdmpowerlevel
[0],
1021 &bw40powerlevel
[0], channel
);
1024 static long _rtl88e_phy_txpwr_idx_to_dbm(struct ieee80211_hw
*hw
,
1025 enum wireless_mode wirelessmode
,
1031 switch (wirelessmode
) {
1032 case WIRELESS_MODE_B
:
1035 case WIRELESS_MODE_G
:
1036 case WIRELESS_MODE_N_24G
:
1043 pwrout_dbm
= txpwridx
/ 2 + offset
;
1047 void rtl88e_phy_scan_operation_backup(struct ieee80211_hw
*hw
, u8 operation
)
1049 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1050 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1051 enum io_type iotype
;
1053 if (!is_hal_stop(rtlhal
)) {
1054 switch (operation
) {
1055 case SCAN_OPT_BACKUP_BAND0
:
1056 iotype
= IO_CMD_PAUSE_BAND0_DM_BY_SCAN
;
1057 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1062 case SCAN_OPT_RESTORE
:
1063 iotype
= IO_CMD_RESUME_DM_BY_SCAN
;
1064 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1069 pr_err("Unknown Scan Backup operation.\n");
1075 void rtl88e_phy_set_bw_mode_callback(struct ieee80211_hw
*hw
)
1077 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1078 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1079 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1080 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1084 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_TRACE
,
1085 "Switch to %s bandwidth\n",
1086 rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20
?
1089 if (is_hal_stop(rtlhal
)) {
1090 rtlphy
->set_bwmode_inprogress
= false;
1094 reg_bw_opmode
= rtl_read_byte(rtlpriv
, REG_BWOPMODE
);
1095 reg_prsr_rsc
= rtl_read_byte(rtlpriv
, REG_RRSR
+ 2);
1097 switch (rtlphy
->current_chan_bw
) {
1098 case HT_CHANNEL_WIDTH_20
:
1099 reg_bw_opmode
|= BW_OPMODE_20MHZ
;
1100 rtl_write_byte(rtlpriv
, REG_BWOPMODE
, reg_bw_opmode
);
1102 case HT_CHANNEL_WIDTH_20_40
:
1103 reg_bw_opmode
&= ~BW_OPMODE_20MHZ
;
1104 rtl_write_byte(rtlpriv
, REG_BWOPMODE
, reg_bw_opmode
);
1106 (reg_prsr_rsc
& 0x90) | (mac
->cur_40_prime_sc
<< 5);
1107 rtl_write_byte(rtlpriv
, REG_RRSR
+ 2, reg_prsr_rsc
);
1110 pr_err("unknown bandwidth: %#X\n",
1111 rtlphy
->current_chan_bw
);
1115 switch (rtlphy
->current_chan_bw
) {
1116 case HT_CHANNEL_WIDTH_20
:
1117 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BRFMOD
, 0x0);
1118 rtl_set_bbreg(hw
, RFPGA1_RFMOD
, BRFMOD
, 0x0);
1119 /* rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 1);*/
1121 case HT_CHANNEL_WIDTH_20_40
:
1122 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BRFMOD
, 0x1);
1123 rtl_set_bbreg(hw
, RFPGA1_RFMOD
, BRFMOD
, 0x1);
1125 rtl_set_bbreg(hw
, RCCK0_SYSTEM
, BCCK_SIDEBAND
,
1126 (mac
->cur_40_prime_sc
>> 1));
1127 rtl_set_bbreg(hw
, ROFDM1_LSTF
, 0xC00, mac
->cur_40_prime_sc
);
1128 /*rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 0);*/
1130 rtl_set_bbreg(hw
, 0x818, (BIT(26) | BIT(27)),
1131 (mac
->cur_40_prime_sc
==
1132 HAL_PRIME_CHNL_OFFSET_LOWER
) ? 2 : 1);
1135 pr_err("unknown bandwidth: %#X\n",
1136 rtlphy
->current_chan_bw
);
1139 rtl88e_phy_rf6052_set_bandwidth(hw
, rtlphy
->current_chan_bw
);
1140 rtlphy
->set_bwmode_inprogress
= false;
1141 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_LOUD
, "\n");
1144 void rtl88e_phy_set_bw_mode(struct ieee80211_hw
*hw
,
1145 enum nl80211_channel_type ch_type
)
1147 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1148 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1149 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1150 u8 tmp_bw
= rtlphy
->current_chan_bw
;
1152 if (rtlphy
->set_bwmode_inprogress
)
1154 rtlphy
->set_bwmode_inprogress
= true;
1155 if ((!is_hal_stop(rtlhal
)) && !(RT_CANNOT_IO(hw
))) {
1156 rtl88e_phy_set_bw_mode_callback(hw
);
1158 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1159 "false driver sleep or unload\n");
1160 rtlphy
->set_bwmode_inprogress
= false;
1161 rtlphy
->current_chan_bw
= tmp_bw
;
1165 void rtl88e_phy_sw_chnl_callback(struct ieee80211_hw
*hw
)
1167 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1168 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1169 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1172 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_TRACE
,
1173 "switch to channel%d\n", rtlphy
->current_channel
);
1174 if (is_hal_stop(rtlhal
))
1177 if (!rtlphy
->sw_chnl_inprogress
)
1179 if (!_rtl88e_phy_sw_chnl_step_by_step
1180 (hw
, rtlphy
->current_channel
, &rtlphy
->sw_chnl_stage
,
1181 &rtlphy
->sw_chnl_step
, &delay
)) {
1187 rtlphy
->sw_chnl_inprogress
= false;
1191 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_TRACE
, "\n");
1194 u8
rtl88e_phy_sw_chnl(struct ieee80211_hw
*hw
)
1196 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1197 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1198 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1200 if (rtlphy
->sw_chnl_inprogress
)
1202 if (rtlphy
->set_bwmode_inprogress
)
1204 WARN_ONCE((rtlphy
->current_channel
> 14),
1205 "rtl8188ee: WIRELESS_MODE_G but channel>14");
1206 rtlphy
->sw_chnl_inprogress
= true;
1207 rtlphy
->sw_chnl_stage
= 0;
1208 rtlphy
->sw_chnl_step
= 0;
1209 if (!(is_hal_stop(rtlhal
)) && !(RT_CANNOT_IO(hw
))) {
1210 rtl88e_phy_sw_chnl_callback(hw
);
1211 RT_TRACE(rtlpriv
, COMP_CHAN
, DBG_LOUD
,
1212 "sw_chnl_inprogress false schedule workitem current channel %d\n",
1213 rtlphy
->current_channel
);
1214 rtlphy
->sw_chnl_inprogress
= false;
1216 RT_TRACE(rtlpriv
, COMP_CHAN
, DBG_LOUD
,
1217 "sw_chnl_inprogress false driver sleep or unload\n");
1218 rtlphy
->sw_chnl_inprogress
= false;
1223 static bool _rtl88e_phy_sw_chnl_step_by_step(struct ieee80211_hw
*hw
,
1224 u8 channel
, u8
*stage
, u8
*step
,
1227 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1228 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1229 struct swchnlcmd precommoncmd
[MAX_PRECMD_CNT
];
1230 u32 precommoncmdcnt
;
1231 struct swchnlcmd postcommoncmd
[MAX_POSTCMD_CNT
];
1232 u32 postcommoncmdcnt
;
1233 struct swchnlcmd rfdependcmd
[MAX_RFDEPENDCMD_CNT
];
1235 struct swchnlcmd
*currentcmd
= NULL
;
1237 u8 num_total_rfpath
= rtlphy
->num_total_rfpath
;
1239 precommoncmdcnt
= 0;
1240 _rtl88e_phy_set_sw_chnl_cmdarray(precommoncmd
, precommoncmdcnt
++,
1242 CMDID_SET_TXPOWEROWER_LEVEL
, 0, 0, 0);
1243 _rtl88e_phy_set_sw_chnl_cmdarray(precommoncmd
, precommoncmdcnt
++,
1244 MAX_PRECMD_CNT
, CMDID_END
, 0, 0, 0);
1246 postcommoncmdcnt
= 0;
1248 _rtl88e_phy_set_sw_chnl_cmdarray(postcommoncmd
, postcommoncmdcnt
++,
1249 MAX_POSTCMD_CNT
, CMDID_END
, 0, 0, 0);
1253 WARN_ONCE((channel
< 1 || channel
> 14),
1254 "rtl8188ee: illegal channel for Zebra: %d\n", channel
);
1256 _rtl88e_phy_set_sw_chnl_cmdarray(rfdependcmd
, rfdependcmdcnt
++,
1257 MAX_RFDEPENDCMD_CNT
, CMDID_RF_WRITEREG
,
1258 RF_CHNLBW
, channel
, 10);
1260 _rtl88e_phy_set_sw_chnl_cmdarray(rfdependcmd
, rfdependcmdcnt
++,
1261 MAX_RFDEPENDCMD_CNT
, CMDID_END
, 0, 0,
1267 currentcmd
= &precommoncmd
[*step
];
1270 currentcmd
= &rfdependcmd
[*step
];
1273 currentcmd
= &postcommoncmd
[*step
];
1276 pr_err("Invalid 'stage' = %d, Check it!\n",
1281 if (currentcmd
->cmdid
== CMDID_END
) {
1289 switch (currentcmd
->cmdid
) {
1290 case CMDID_SET_TXPOWEROWER_LEVEL
:
1291 rtl88e_phy_set_txpower_level(hw
, channel
);
1293 case CMDID_WRITEPORT_ULONG
:
1294 rtl_write_dword(rtlpriv
, currentcmd
->para1
,
1297 case CMDID_WRITEPORT_USHORT
:
1298 rtl_write_word(rtlpriv
, currentcmd
->para1
,
1299 (u16
)currentcmd
->para2
);
1301 case CMDID_WRITEPORT_UCHAR
:
1302 rtl_write_byte(rtlpriv
, currentcmd
->para1
,
1303 (u8
)currentcmd
->para2
);
1305 case CMDID_RF_WRITEREG
:
1306 for (rfpath
= 0; rfpath
< num_total_rfpath
; rfpath
++) {
1307 rtlphy
->rfreg_chnlval
[rfpath
] =
1308 ((rtlphy
->rfreg_chnlval
[rfpath
] &
1309 0xfffffc00) | currentcmd
->para2
);
1311 rtl_set_rfreg(hw
, (enum radio_path
)rfpath
,
1314 rtlphy
->rfreg_chnlval
[rfpath
]);
1318 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
1319 "switch case %#x not processed\n",
1327 (*delay
) = currentcmd
->msdelay
;
1332 static bool _rtl88e_phy_set_sw_chnl_cmdarray(struct swchnlcmd
*cmdtable
,
1333 u32 cmdtableidx
, u32 cmdtablesz
,
1334 enum swchnlcmd_id cmdid
,
1335 u32 para1
, u32 para2
, u32 msdelay
)
1337 struct swchnlcmd
*pcmd
;
1339 if (cmdtable
== NULL
) {
1340 WARN_ONCE(true, "rtl8188ee: cmdtable cannot be NULL.\n");
1344 if (cmdtableidx
>= cmdtablesz
)
1347 pcmd
= cmdtable
+ cmdtableidx
;
1348 pcmd
->cmdid
= cmdid
;
1349 pcmd
->para1
= para1
;
1350 pcmd
->para2
= para2
;
1351 pcmd
->msdelay
= msdelay
;
1355 static u8
_rtl88e_phy_path_a_iqk(struct ieee80211_hw
*hw
, bool config_pathb
)
1357 u32 reg_eac
, reg_e94
, reg_e9c
, reg_ea4
;
1360 rtl_set_bbreg(hw
, 0xe30, MASKDWORD
, 0x10008c1c);
1361 rtl_set_bbreg(hw
, 0xe34, MASKDWORD
, 0x30008c1c);
1362 rtl_set_bbreg(hw
, 0xe38, MASKDWORD
, 0x8214032a);
1363 rtl_set_bbreg(hw
, 0xe3c, MASKDWORD
, 0x28160000);
1365 rtl_set_bbreg(hw
, 0xe4c, MASKDWORD
, 0x00462911);
1366 rtl_set_bbreg(hw
, 0xe48, MASKDWORD
, 0xf9000000);
1367 rtl_set_bbreg(hw
, 0xe48, MASKDWORD
, 0xf8000000);
1369 mdelay(IQK_DELAY_TIME
);
1371 reg_eac
= rtl_get_bbreg(hw
, 0xeac, MASKDWORD
);
1372 reg_e94
= rtl_get_bbreg(hw
, 0xe94, MASKDWORD
);
1373 reg_e9c
= rtl_get_bbreg(hw
, 0xe9c, MASKDWORD
);
1374 reg_ea4
= rtl_get_bbreg(hw
, 0xea4, MASKDWORD
);
1376 if (!(reg_eac
& BIT(28)) &&
1377 (((reg_e94
& 0x03FF0000) >> 16) != 0x142) &&
1378 (((reg_e9c
& 0x03FF0000) >> 16) != 0x42))
1383 static u8
_rtl88e_phy_path_b_iqk(struct ieee80211_hw
*hw
)
1385 u32 reg_eac
, reg_eb4
, reg_ebc
, reg_ec4
, reg_ecc
;
1388 rtl_set_bbreg(hw
, 0xe60, MASKDWORD
, 0x00000002);
1389 rtl_set_bbreg(hw
, 0xe60, MASKDWORD
, 0x00000000);
1390 mdelay(IQK_DELAY_TIME
);
1391 reg_eac
= rtl_get_bbreg(hw
, 0xeac, MASKDWORD
);
1392 reg_eb4
= rtl_get_bbreg(hw
, 0xeb4, MASKDWORD
);
1393 reg_ebc
= rtl_get_bbreg(hw
, 0xebc, MASKDWORD
);
1394 reg_ec4
= rtl_get_bbreg(hw
, 0xec4, MASKDWORD
);
1395 reg_ecc
= rtl_get_bbreg(hw
, 0xecc, MASKDWORD
);
1397 if (!(reg_eac
& BIT(31)) &&
1398 (((reg_eb4
& 0x03FF0000) >> 16) != 0x142) &&
1399 (((reg_ebc
& 0x03FF0000) >> 16) != 0x42))
1403 if (!(reg_eac
& BIT(30)) &&
1404 (((reg_ec4
& 0x03FF0000) >> 16) != 0x132) &&
1405 (((reg_ecc
& 0x03FF0000) >> 16) != 0x36))
1410 static u8
_rtl88e_phy_path_a_rx_iqk(struct ieee80211_hw
*hw
, bool config_pathb
)
1412 u32 reg_eac
, reg_e94
, reg_e9c
, reg_ea4
, u32temp
;
1415 /*Get TXIMR Setting*/
1416 /*Modify RX IQK mode table*/
1417 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x00000000);
1418 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_WE_LUT
, RFREG_OFFSET_MASK
, 0x800a0);
1419 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_RCK_OS
, RFREG_OFFSET_MASK
, 0x30000);
1420 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_TXPA_G1
, RFREG_OFFSET_MASK
, 0x0000f);
1421 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_TXPA_G2
, RFREG_OFFSET_MASK
, 0xf117b);
1422 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x80800000);
1425 rtl_set_bbreg(hw
, RTX_IQK
, MASKDWORD
, 0x01007c00);
1426 rtl_set_bbreg(hw
, RRX_IQK
, MASKDWORD
, 0x81004800);
1428 /*path a IQK setting*/
1429 rtl_set_bbreg(hw
, RTX_IQK_TONE_A
, MASKDWORD
, 0x10008c1c);
1430 rtl_set_bbreg(hw
, RRX_IQK_TONE_A
, MASKDWORD
, 0x30008c1c);
1431 rtl_set_bbreg(hw
, RTX_IQK_PI_A
, MASKDWORD
, 0x82160804);
1432 rtl_set_bbreg(hw
, RRX_IQK_PI_A
, MASKDWORD
, 0x28160000);
1434 /*LO calibration Setting*/
1435 rtl_set_bbreg(hw
, RIQK_AGC_RSP
, MASKDWORD
, 0x0046a911);
1436 /*one shot,path A LOK & iqk*/
1437 rtl_set_bbreg(hw
, RIQK_AGC_PTS
, MASKDWORD
, 0xf9000000);
1438 rtl_set_bbreg(hw
, RIQK_AGC_PTS
, MASKDWORD
, 0xf8000000);
1440 mdelay(IQK_DELAY_TIME
);
1442 reg_eac
= rtl_get_bbreg(hw
, RRX_POWER_AFTER_IQK_A_2
, MASKDWORD
);
1443 reg_e94
= rtl_get_bbreg(hw
, RTX_POWER_BEFORE_IQK_A
, MASKDWORD
);
1444 reg_e9c
= rtl_get_bbreg(hw
, RTX_POWER_AFTER_IQK_A
, MASKDWORD
);
1447 if (!(reg_eac
& BIT(28)) &&
1448 (((reg_e94
& 0x03FF0000) >> 16) != 0x142) &&
1449 (((reg_e9c
& 0x03FF0000) >> 16) != 0x42))
1454 u32temp
= 0x80007C00 | (reg_e94
&0x3FF0000) |
1455 ((reg_e9c
&0x3FF0000) >> 16);
1456 rtl_set_bbreg(hw
, RTX_IQK
, MASKDWORD
, u32temp
);
1458 /*Modify RX IQK mode table*/
1459 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x00000000);
1460 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_WE_LUT
, RFREG_OFFSET_MASK
, 0x800a0);
1461 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_RCK_OS
, RFREG_OFFSET_MASK
, 0x30000);
1462 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_TXPA_G1
, RFREG_OFFSET_MASK
, 0x0000f);
1463 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_TXPA_G2
, RFREG_OFFSET_MASK
, 0xf7ffa);
1464 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x80800000);
1467 rtl_set_bbreg(hw
, RRX_IQK
, MASKDWORD
, 0x01004800);
1469 /*path a IQK setting*/
1470 rtl_set_bbreg(hw
, RTX_IQK_TONE_A
, MASKDWORD
, 0x30008c1c);
1471 rtl_set_bbreg(hw
, RRX_IQK_TONE_A
, MASKDWORD
, 0x10008c1c);
1472 rtl_set_bbreg(hw
, RTX_IQK_PI_A
, MASKDWORD
, 0x82160c05);
1473 rtl_set_bbreg(hw
, RRX_IQK_PI_A
, MASKDWORD
, 0x28160c05);
1475 /*LO calibration Setting*/
1476 rtl_set_bbreg(hw
, RIQK_AGC_RSP
, MASKDWORD
, 0x0046a911);
1477 /*one shot,path A LOK & iqk*/
1478 rtl_set_bbreg(hw
, RIQK_AGC_PTS
, MASKDWORD
, 0xf9000000);
1479 rtl_set_bbreg(hw
, RIQK_AGC_PTS
, MASKDWORD
, 0xf8000000);
1481 mdelay(IQK_DELAY_TIME
);
1483 reg_eac
= rtl_get_bbreg(hw
, RRX_POWER_AFTER_IQK_A_2
, MASKDWORD
);
1484 reg_e94
= rtl_get_bbreg(hw
, RTX_POWER_BEFORE_IQK_A
, MASKDWORD
);
1485 reg_e9c
= rtl_get_bbreg(hw
, RTX_POWER_AFTER_IQK_A
, MASKDWORD
);
1486 reg_ea4
= rtl_get_bbreg(hw
, RRX_POWER_BEFORE_IQK_A_2
, MASKDWORD
);
1488 if (!(reg_eac
& BIT(27)) &&
1489 (((reg_ea4
& 0x03FF0000) >> 16) != 0x132) &&
1490 (((reg_eac
& 0x03FF0000) >> 16) != 0x36))
1495 static void _rtl88e_phy_path_a_fill_iqk_matrix(struct ieee80211_hw
*hw
,
1496 bool iqk_ok
, long result
[][8],
1497 u8 final_candidate
, bool btxonly
)
1499 u32 oldval_0
, x
, tx0_a
, reg
;
1502 if (final_candidate
== 0xFF) {
1504 } else if (iqk_ok
) {
1505 oldval_0
= (rtl_get_bbreg(hw
, ROFDM0_XATXIQIMBALANCE
,
1506 MASKDWORD
) >> 22) & 0x3FF;
1507 x
= result
[final_candidate
][0];
1508 if ((x
& 0x00000200) != 0)
1510 tx0_a
= (x
* oldval_0
) >> 8;
1511 rtl_set_bbreg(hw
, ROFDM0_XATXIQIMBALANCE
, 0x3FF, tx0_a
);
1512 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
, BIT(31),
1513 ((x
* oldval_0
>> 7) & 0x1));
1514 y
= result
[final_candidate
][1];
1515 if ((y
& 0x00000200) != 0)
1517 tx0_c
= (y
* oldval_0
) >> 8;
1518 rtl_set_bbreg(hw
, ROFDM0_XCTXAFE
, 0xF0000000,
1519 ((tx0_c
& 0x3C0) >> 6));
1520 rtl_set_bbreg(hw
, ROFDM0_XATXIQIMBALANCE
, 0x003F0000,
1522 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
, BIT(29),
1523 ((y
* oldval_0
>> 7) & 0x1));
1526 reg
= result
[final_candidate
][2];
1527 rtl_set_bbreg(hw
, ROFDM0_XARXIQIMBALANCE
, 0x3FF, reg
);
1528 reg
= result
[final_candidate
][3] & 0x3F;
1529 rtl_set_bbreg(hw
, ROFDM0_XARXIQIMBALANCE
, 0xFC00, reg
);
1530 reg
= (result
[final_candidate
][3] >> 6) & 0xF;
1531 rtl_set_bbreg(hw
, 0xca0, 0xF0000000, reg
);
1535 static void _rtl88e_phy_save_adda_registers(struct ieee80211_hw
*hw
,
1536 u32
*addareg
, u32
*addabackup
,
1541 for (i
= 0; i
< registernum
; i
++)
1542 addabackup
[i
] = rtl_get_bbreg(hw
, addareg
[i
], MASKDWORD
);
1545 static void _rtl88e_phy_save_mac_registers(struct ieee80211_hw
*hw
,
1546 u32
*macreg
, u32
*macbackup
)
1548 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1551 for (i
= 0; i
< (IQK_MAC_REG_NUM
- 1); i
++)
1552 macbackup
[i
] = rtl_read_byte(rtlpriv
, macreg
[i
]);
1553 macbackup
[i
] = rtl_read_dword(rtlpriv
, macreg
[i
]);
1556 static void _rtl88e_phy_reload_adda_registers(struct ieee80211_hw
*hw
,
1557 u32
*addareg
, u32
*addabackup
,
1562 for (i
= 0; i
< regiesternum
; i
++)
1563 rtl_set_bbreg(hw
, addareg
[i
], MASKDWORD
, addabackup
[i
]);
1566 static void _rtl88e_phy_reload_mac_registers(struct ieee80211_hw
*hw
,
1567 u32
*macreg
, u32
*macbackup
)
1569 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1572 for (i
= 0; i
< (IQK_MAC_REG_NUM
- 1); i
++)
1573 rtl_write_byte(rtlpriv
, macreg
[i
], (u8
) macbackup
[i
]);
1574 rtl_write_dword(rtlpriv
, macreg
[i
], macbackup
[i
]);
1577 static void _rtl88e_phy_path_adda_on(struct ieee80211_hw
*hw
,
1578 u32
*addareg
, bool is_patha_on
, bool is2t
)
1583 pathon
= is_patha_on
? 0x04db25a4 : 0x0b1b25a4;
1584 if (false == is2t
) {
1585 pathon
= 0x0bdb25a0;
1586 rtl_set_bbreg(hw
, addareg
[0], MASKDWORD
, 0x0b1b25a0);
1588 rtl_set_bbreg(hw
, addareg
[0], MASKDWORD
, pathon
);
1591 for (i
= 1; i
< IQK_ADDA_REG_NUM
; i
++)
1592 rtl_set_bbreg(hw
, addareg
[i
], MASKDWORD
, pathon
);
1595 static void _rtl88e_phy_mac_setting_calibration(struct ieee80211_hw
*hw
,
1596 u32
*macreg
, u32
*macbackup
)
1598 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1601 rtl_write_byte(rtlpriv
, macreg
[i
], 0x3F);
1603 for (i
= 1; i
< (IQK_MAC_REG_NUM
- 1); i
++)
1604 rtl_write_byte(rtlpriv
, macreg
[i
],
1605 (u8
) (macbackup
[i
] & (~BIT(3))));
1606 rtl_write_byte(rtlpriv
, macreg
[i
], (u8
) (macbackup
[i
] & (~BIT(5))));
1609 static void _rtl88e_phy_path_a_standby(struct ieee80211_hw
*hw
)
1611 rtl_set_bbreg(hw
, 0xe28, MASKDWORD
, 0x0);
1612 rtl_set_bbreg(hw
, 0x840, MASKDWORD
, 0x00010000);
1613 rtl_set_bbreg(hw
, 0xe28, MASKDWORD
, 0x80800000);
1616 static void _rtl88e_phy_pi_mode_switch(struct ieee80211_hw
*hw
, bool pi_mode
)
1620 mode
= pi_mode
? 0x01000100 : 0x01000000;
1621 rtl_set_bbreg(hw
, 0x820, MASKDWORD
, mode
);
1622 rtl_set_bbreg(hw
, 0x828, MASKDWORD
, mode
);
1625 static bool _rtl88e_phy_simularity_compare(struct ieee80211_hw
*hw
,
1626 long result
[][8], u8 c1
, u8 c2
)
1628 u32 i
, j
, diff
, simularity_bitmap
, bound
;
1629 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1631 u8 final_candidate
[2] = { 0xFF, 0xFF };
1632 bool bresult
= true, is2t
= IS_92C_SERIAL(rtlhal
->version
);
1639 simularity_bitmap
= 0;
1641 for (i
= 0; i
< bound
; i
++) {
1642 diff
= (result
[c1
][i
] > result
[c2
][i
]) ?
1643 (result
[c1
][i
] - result
[c2
][i
]) :
1644 (result
[c2
][i
] - result
[c1
][i
]);
1646 if (diff
> MAX_TOLERANCE
) {
1647 if ((i
== 2 || i
== 6) && !simularity_bitmap
) {
1648 if (result
[c1
][i
] + result
[c1
][i
+ 1] == 0)
1649 final_candidate
[(i
/ 4)] = c2
;
1650 else if (result
[c2
][i
] + result
[c2
][i
+ 1] == 0)
1651 final_candidate
[(i
/ 4)] = c1
;
1653 simularity_bitmap
= simularity_bitmap
|
1657 simularity_bitmap
| (1 << i
);
1661 if (simularity_bitmap
== 0) {
1662 for (i
= 0; i
< (bound
/ 4); i
++) {
1663 if (final_candidate
[i
] != 0xFF) {
1664 for (j
= i
* 4; j
< (i
+ 1) * 4 - 2; j
++)
1666 result
[final_candidate
[i
]][j
];
1671 } else if (!(simularity_bitmap
& 0x0F)) {
1672 for (i
= 0; i
< 4; i
++)
1673 result
[3][i
] = result
[c1
][i
];
1675 } else if (!(simularity_bitmap
& 0xF0) && is2t
) {
1676 for (i
= 4; i
< 8; i
++)
1677 result
[3][i
] = result
[c1
][i
];
1685 static void _rtl88e_phy_iq_calibrate(struct ieee80211_hw
*hw
,
1686 long result
[][8], u8 t
, bool is2t
)
1688 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1689 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1691 u8 patha_ok
, pathb_ok
;
1692 u32 adda_reg
[IQK_ADDA_REG_NUM
] = {
1693 0x85c, 0xe6c, 0xe70, 0xe74,
1694 0xe78, 0xe7c, 0xe80, 0xe84,
1695 0xe88, 0xe8c, 0xed0, 0xed4,
1696 0xed8, 0xedc, 0xee0, 0xeec
1698 u32 iqk_mac_reg
[IQK_MAC_REG_NUM
] = {
1699 0x522, 0x550, 0x551, 0x040
1701 u32 iqk_bb_reg
[IQK_BB_REG_NUM
] = {
1702 ROFDM0_TRXPATHENABLE
, ROFDM0_TRMUXPAR
,
1703 RFPGA0_XCD_RFINTERFACESW
, 0xb68, 0xb6c,
1704 0x870, 0x860, 0x864, 0x800
1706 const u32 retrycount
= 2;
1709 _rtl88e_phy_save_adda_registers(hw
, adda_reg
,
1710 rtlphy
->adda_backup
, 16);
1711 _rtl88e_phy_save_mac_registers(hw
, iqk_mac_reg
,
1712 rtlphy
->iqk_mac_backup
);
1713 _rtl88e_phy_save_adda_registers(hw
, iqk_bb_reg
,
1714 rtlphy
->iqk_bb_backup
,
1717 _rtl88e_phy_path_adda_on(hw
, adda_reg
, true, is2t
);
1719 rtlphy
->rfpi_enable
=
1720 (u8
)rtl_get_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER1
, BIT(8));
1723 if (!rtlphy
->rfpi_enable
)
1724 _rtl88e_phy_pi_mode_switch(hw
, true);
1726 rtl_set_bbreg(hw
, 0x800, BIT(24), 0x00);
1727 rtl_set_bbreg(hw
, 0xc04, MASKDWORD
, 0x03a05600);
1728 rtl_set_bbreg(hw
, 0xc08, MASKDWORD
, 0x000800e4);
1729 rtl_set_bbreg(hw
, 0x874, MASKDWORD
, 0x22204000);
1731 rtl_set_bbreg(hw
, 0x870, BIT(10), 0x01);
1732 rtl_set_bbreg(hw
, 0x870, BIT(26), 0x01);
1733 rtl_set_bbreg(hw
, 0x860, BIT(10), 0x00);
1734 rtl_set_bbreg(hw
, 0x864, BIT(10), 0x00);
1737 rtl_set_bbreg(hw
, 0x840, MASKDWORD
, 0x00010000);
1738 rtl_set_bbreg(hw
, 0x844, MASKDWORD
, 0x00010000);
1740 _rtl88e_phy_mac_setting_calibration(hw
, iqk_mac_reg
,
1741 rtlphy
->iqk_mac_backup
);
1742 rtl_set_bbreg(hw
, 0xb68, MASKDWORD
, 0x0f600000);
1744 rtl_set_bbreg(hw
, 0xb6c, MASKDWORD
, 0x0f600000);
1746 rtl_set_bbreg(hw
, 0xe28, MASKDWORD
, 0x80800000);
1747 rtl_set_bbreg(hw
, 0xe40, MASKDWORD
, 0x01007c00);
1748 rtl_set_bbreg(hw
, 0xe44, MASKDWORD
, 0x81004800);
1749 for (i
= 0; i
< retrycount
; i
++) {
1750 patha_ok
= _rtl88e_phy_path_a_iqk(hw
, is2t
);
1751 if (patha_ok
== 0x01) {
1752 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1753 "Path A Tx IQK Success!!\n");
1754 result
[t
][0] = (rtl_get_bbreg(hw
, 0xe94, MASKDWORD
) &
1756 result
[t
][1] = (rtl_get_bbreg(hw
, 0xe9c, MASKDWORD
) &
1762 for (i
= 0; i
< retrycount
; i
++) {
1763 patha_ok
= _rtl88e_phy_path_a_rx_iqk(hw
, is2t
);
1764 if (patha_ok
== 0x03) {
1765 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1766 "Path A Rx IQK Success!!\n");
1767 result
[t
][2] = (rtl_get_bbreg(hw
, 0xea4, MASKDWORD
) &
1769 result
[t
][3] = (rtl_get_bbreg(hw
, 0xeac, MASKDWORD
) &
1773 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1774 "Path a RX iqk fail!!!\n");
1779 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1780 "Path A IQK Success!!\n");
1782 _rtl88e_phy_path_a_standby(hw
);
1783 _rtl88e_phy_path_adda_on(hw
, adda_reg
, false, is2t
);
1784 for (i
= 0; i
< retrycount
; i
++) {
1785 pathb_ok
= _rtl88e_phy_path_b_iqk(hw
);
1786 if (pathb_ok
== 0x03) {
1787 result
[t
][4] = (rtl_get_bbreg(hw
,
1792 (rtl_get_bbreg(hw
, 0xebc, MASKDWORD
) &
1795 (rtl_get_bbreg(hw
, 0xec4, MASKDWORD
) &
1798 (rtl_get_bbreg(hw
, 0xecc, MASKDWORD
) &
1801 } else if (i
== (retrycount
- 1) && pathb_ok
== 0x01) {
1802 result
[t
][4] = (rtl_get_bbreg(hw
,
1807 result
[t
][5] = (rtl_get_bbreg(hw
, 0xebc, MASKDWORD
) &
1812 rtl_set_bbreg(hw
, 0xe28, MASKDWORD
, 0);
1815 if (!rtlphy
->rfpi_enable
)
1816 _rtl88e_phy_pi_mode_switch(hw
, false);
1817 _rtl88e_phy_reload_adda_registers(hw
, adda_reg
,
1818 rtlphy
->adda_backup
, 16);
1819 _rtl88e_phy_reload_mac_registers(hw
, iqk_mac_reg
,
1820 rtlphy
->iqk_mac_backup
);
1821 _rtl88e_phy_reload_adda_registers(hw
, iqk_bb_reg
,
1822 rtlphy
->iqk_bb_backup
,
1825 rtl_set_bbreg(hw
, 0x840, MASKDWORD
, 0x00032ed3);
1827 rtl_set_bbreg(hw
, 0x844, MASKDWORD
, 0x00032ed3);
1828 rtl_set_bbreg(hw
, 0xe30, MASKDWORD
, 0x01008c00);
1829 rtl_set_bbreg(hw
, 0xe34, MASKDWORD
, 0x01008c00);
1831 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "88ee IQK Finish!!\n");
1834 static void _rtl88e_phy_lc_calibrate(struct ieee80211_hw
*hw
, bool is2t
)
1837 u32 rf_a_mode
= 0, rf_b_mode
= 0, lc_cal
;
1838 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1840 tmpreg
= rtl_read_byte(rtlpriv
, 0xd03);
1842 if ((tmpreg
& 0x70) != 0)
1843 rtl_write_byte(rtlpriv
, 0xd03, tmpreg
& 0x8F);
1845 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0xFF);
1847 if ((tmpreg
& 0x70) != 0) {
1848 rf_a_mode
= rtl_get_rfreg(hw
, RF90_PATH_A
, 0x00, MASK12BITS
);
1851 rf_b_mode
= rtl_get_rfreg(hw
, RF90_PATH_B
, 0x00,
1854 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x00, MASK12BITS
,
1855 (rf_a_mode
& 0x8FFFF) | 0x10000);
1858 rtl_set_rfreg(hw
, RF90_PATH_B
, 0x00, MASK12BITS
,
1859 (rf_b_mode
& 0x8FFFF) | 0x10000);
1861 lc_cal
= rtl_get_rfreg(hw
, RF90_PATH_A
, 0x18, MASK12BITS
);
1863 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x18, MASK12BITS
, lc_cal
| 0x08000);
1867 if ((tmpreg
& 0x70) != 0) {
1868 rtl_write_byte(rtlpriv
, 0xd03, tmpreg
);
1869 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x00, MASK12BITS
, rf_a_mode
);
1872 rtl_set_rfreg(hw
, RF90_PATH_B
, 0x00, MASK12BITS
,
1875 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0x00);
1877 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "\n");
1880 static void _rtl88e_phy_set_rfpath_switch(struct ieee80211_hw
*hw
,
1881 bool bmain
, bool is2t
)
1883 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1884 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1885 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1886 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "\n");
1888 if (is_hal_stop(rtlhal
)) {
1890 u1btmp
= rtl_read_byte(rtlpriv
, REG_LEDCFG0
);
1891 rtl_write_byte(rtlpriv
, REG_LEDCFG0
, u1btmp
| BIT(7));
1892 rtl_set_bbreg(hw
, RFPGA0_XAB_RFPARAMETER
, BIT(13), 0x01);
1896 rtl_set_bbreg(hw
, RFPGA0_XB_RFINTERFACEOE
,
1897 BIT(5) | BIT(6), 0x1);
1899 rtl_set_bbreg(hw
, RFPGA0_XB_RFINTERFACEOE
,
1900 BIT(5) | BIT(6), 0x2);
1902 rtl_set_bbreg(hw
, RFPGA0_XAB_RFINTERFACESW
, BIT(8) | BIT(9), 0);
1903 rtl_set_bbreg(hw
, 0x914, MASKLWORD
, 0x0201);
1905 /* We use the RF definition of MAIN and AUX,
1906 * left antenna and right antenna repectively.
1907 * Default output at AUX.
1910 rtl_set_bbreg(hw
, RFPGA0_XA_RFINTERFACEOE
,
1911 BIT(14) | BIT(13) | BIT(12), 0);
1912 rtl_set_bbreg(hw
, RFPGA0_XB_RFINTERFACEOE
,
1913 BIT(5) | BIT(4) | BIT(3), 0);
1914 if (rtlefuse
->antenna_div_type
== CGCS_RX_HW_ANTDIV
)
1915 rtl_set_bbreg(hw
, RCONFIG_RAM64x16
, BIT(31), 0);
1917 rtl_set_bbreg(hw
, RFPGA0_XA_RFINTERFACEOE
,
1918 BIT(14) | BIT(13) | BIT(12), 1);
1919 rtl_set_bbreg(hw
, RFPGA0_XB_RFINTERFACEOE
,
1920 BIT(5) | BIT(4) | BIT(3), 1);
1921 if (rtlefuse
->antenna_div_type
== CGCS_RX_HW_ANTDIV
)
1922 rtl_set_bbreg(hw
, RCONFIG_RAM64x16
, BIT(31), 1);
1927 #undef IQK_ADDA_REG_NUM
1928 #undef IQK_DELAY_TIME
1930 void rtl88e_phy_iq_calibrate(struct ieee80211_hw
*hw
, bool b_recovery
)
1932 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1933 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1935 u8 i
, final_candidate
;
1937 long reg_e94
, reg_e9c
, reg_ea4
, reg_eb4
, reg_ebc
,
1939 bool is12simular
, is13simular
, is23simular
;
1940 u32 iqk_bb_reg
[9] = {
1941 ROFDM0_XARXIQIMBALANCE
,
1942 ROFDM0_XBRXIQIMBALANCE
,
1943 ROFDM0_ECCATHRESHOLD
,
1944 ROFDM0_AGCRSSITABLE
,
1945 ROFDM0_XATXIQIMBALANCE
,
1946 ROFDM0_XBTXIQIMBALANCE
,
1953 _rtl88e_phy_reload_adda_registers(hw
,
1955 rtlphy
->iqk_bb_backup
, 9);
1959 for (i
= 0; i
< 8; i
++) {
1965 final_candidate
= 0xff;
1967 is12simular
= false;
1968 is23simular
= false;
1969 is13simular
= false;
1970 for (i
= 0; i
< 3; i
++) {
1971 if (get_rf_type(rtlphy
) == RF_2T2R
)
1972 _rtl88e_phy_iq_calibrate(hw
, result
, i
, true);
1974 _rtl88e_phy_iq_calibrate(hw
, result
, i
, false);
1977 _rtl88e_phy_simularity_compare(hw
, result
, 0, 1);
1979 final_candidate
= 0;
1985 _rtl88e_phy_simularity_compare(hw
, result
, 0, 2);
1987 final_candidate
= 0;
1991 _rtl88e_phy_simularity_compare(hw
, result
, 1, 2);
1993 final_candidate
= 1;
1995 for (i
= 0; i
< 8; i
++)
1996 reg_tmp
+= result
[3][i
];
1999 final_candidate
= 3;
2001 final_candidate
= 0xFF;
2005 for (i
= 0; i
< 4; i
++) {
2006 reg_e94
= result
[i
][0];
2007 reg_e9c
= result
[i
][1];
2008 reg_ea4
= result
[i
][2];
2009 reg_eb4
= result
[i
][4];
2010 reg_ebc
= result
[i
][5];
2012 if (final_candidate
!= 0xff) {
2013 reg_e94
= result
[final_candidate
][0];
2014 reg_e9c
= result
[final_candidate
][1];
2015 reg_ea4
= result
[final_candidate
][2];
2016 reg_eb4
= result
[final_candidate
][4];
2017 reg_ebc
= result
[final_candidate
][5];
2018 rtlphy
->reg_eb4
= reg_eb4
;
2019 rtlphy
->reg_ebc
= reg_ebc
;
2020 rtlphy
->reg_e94
= reg_e94
;
2021 rtlphy
->reg_e9c
= reg_e9c
;
2024 rtlphy
->reg_e94
= 0x100;
2025 rtlphy
->reg_eb4
= 0x100;
2026 rtlphy
->reg_e9c
= 0x0;
2027 rtlphy
->reg_ebc
= 0x0;
2029 if (reg_e94
!= 0) /*&&(reg_ea4 != 0) */
2030 _rtl88e_phy_path_a_fill_iqk_matrix(hw
, b_patha_ok
, result
,
2033 if (final_candidate
!= 0xFF) {
2034 for (i
= 0; i
< IQK_MATRIX_REG_NUM
; i
++)
2035 rtlphy
->iqk_matrix
[0].value
[0][i
] =
2036 result
[final_candidate
][i
];
2037 rtlphy
->iqk_matrix
[0].iqk_done
= true;
2040 _rtl88e_phy_save_adda_registers(hw
, iqk_bb_reg
,
2041 rtlphy
->iqk_bb_backup
, 9);
2044 void rtl88e_phy_lc_calibrate(struct ieee80211_hw
*hw
)
2046 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2047 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
2048 struct rtl_hal
*rtlhal
= &rtlpriv
->rtlhal
;
2049 u32 timeout
= 2000, timecount
= 0;
2051 while (rtlpriv
->mac80211
.act_scanning
&& timecount
< timeout
) {
2056 rtlphy
->lck_inprogress
= true;
2057 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2058 "LCK:Start!!! currentband %x delay %d ms\n",
2059 rtlhal
->current_bandtype
, timecount
);
2061 _rtl88e_phy_lc_calibrate(hw
, false);
2063 rtlphy
->lck_inprogress
= false;
2066 void rtl88e_phy_set_rfpath_switch(struct ieee80211_hw
*hw
, bool bmain
)
2068 _rtl88e_phy_set_rfpath_switch(hw
, bmain
, false);
2071 bool rtl88e_phy_set_io_cmd(struct ieee80211_hw
*hw
, enum io_type iotype
)
2073 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2074 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
2075 bool postprocessing
= false;
2077 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
,
2078 "-->IO Cmd(%#x), set_io_inprogress(%d)\n",
2079 iotype
, rtlphy
->set_io_inprogress
);
2082 case IO_CMD_RESUME_DM_BY_SCAN
:
2083 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
,
2084 "[IO CMD] Resume DM after scan.\n");
2085 postprocessing
= true;
2087 case IO_CMD_PAUSE_BAND0_DM_BY_SCAN
:
2088 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
,
2089 "[IO CMD] Pause DM before scan.\n");
2090 postprocessing
= true;
2093 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
2094 "switch case %#x not processed\n", iotype
);
2098 if (postprocessing
&& !rtlphy
->set_io_inprogress
) {
2099 rtlphy
->set_io_inprogress
= true;
2100 rtlphy
->current_io_type
= iotype
;
2104 rtl88e_phy_set_io(hw
);
2105 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
, "IO Type(%#x)\n", iotype
);
2109 static void rtl88e_phy_set_io(struct ieee80211_hw
*hw
)
2111 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2112 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
2113 struct dig_t
*dm_digtable
= &rtlpriv
->dm_digtable
;
2115 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
,
2116 "--->Cmd(%#x), set_io_inprogress(%d)\n",
2117 rtlphy
->current_io_type
, rtlphy
->set_io_inprogress
);
2118 switch (rtlphy
->current_io_type
) {
2119 case IO_CMD_RESUME_DM_BY_SCAN
:
2120 dm_digtable
->cur_igvalue
= rtlphy
->initgain_backup
.xaagccore1
;
2121 /*rtl92c_dm_write_dig(hw);*/
2122 rtl88e_phy_set_txpower_level(hw
, rtlphy
->current_channel
);
2123 rtl_set_bbreg(hw
, RCCK0_CCA
, 0xff0000, 0x83);
2125 case IO_CMD_PAUSE_BAND0_DM_BY_SCAN
:
2126 rtlphy
->initgain_backup
.xaagccore1
= dm_digtable
->cur_igvalue
;
2127 dm_digtable
->cur_igvalue
= 0x17;
2128 rtl_set_bbreg(hw
, RCCK0_CCA
, 0xff0000, 0x40);
2131 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
2132 "switch case %#x not processed\n",
2133 rtlphy
->current_io_type
);
2136 rtlphy
->set_io_inprogress
= false;
2137 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
,
2138 "(%#x)\n", rtlphy
->current_io_type
);
2141 static void rtl88ee_phy_set_rf_on(struct ieee80211_hw
*hw
)
2143 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2145 rtl_write_byte(rtlpriv
, REG_SPS0_CTRL
, 0x2b);
2146 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE3);
2147 /*rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x00);*/
2148 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE2);
2149 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE3);
2150 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0x00);
2153 static void _rtl88ee_phy_set_rf_sleep(struct ieee80211_hw
*hw
)
2155 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2157 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0xFF);
2158 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x00, RFREG_OFFSET_MASK
, 0x00);
2159 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE2);
2160 rtl_write_byte(rtlpriv
, REG_SPS0_CTRL
, 0x22);
2163 static bool _rtl88ee_phy_set_rf_power_state(struct ieee80211_hw
*hw
,
2164 enum rf_pwrstate rfpwr_state
)
2166 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2167 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
2168 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2169 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
2170 bool bresult
= true;
2172 struct rtl8192_tx_ring
*ring
= NULL
;
2174 switch (rfpwr_state
) {
2176 if ((ppsc
->rfpwr_state
== ERFOFF
) &&
2177 RT_IN_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
)) {
2179 u32 initializecount
= 0;
2183 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
2184 "IPS Set eRf nic enable\n");
2185 rtstatus
= rtl_ps_enable_nic(hw
);
2186 } while (!rtstatus
&&
2187 (initializecount
< 10));
2188 RT_CLEAR_PS_LEVEL(ppsc
,
2189 RT_RF_OFF_LEVL_HALT_NIC
);
2191 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
2192 "Set ERFON sleeped:%d ms\n",
2193 jiffies_to_msecs(jiffies
-
2195 last_sleep_jiffies
));
2196 ppsc
->last_awake_jiffies
= jiffies
;
2197 rtl88ee_phy_set_rf_on(hw
);
2199 if (mac
->link_state
== MAC80211_LINKED
) {
2200 rtlpriv
->cfg
->ops
->led_control(hw
,
2203 rtlpriv
->cfg
->ops
->led_control(hw
,
2208 for (queue_id
= 0, i
= 0;
2209 queue_id
< RTL_PCI_MAX_TX_QUEUE_COUNT
;) {
2210 ring
= &pcipriv
->dev
.tx_ring
[queue_id
];
2211 if (queue_id
== BEACON_QUEUE
||
2212 skb_queue_len(&ring
->queue
) == 0) {
2216 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
2217 "eRf Off/Sleep: %d times TcbBusyQueue[%d] =%d before doze!\n",
2219 skb_queue_len(&ring
->queue
));
2224 if (i
>= MAX_DOZE_WAITING_TIMES_9x
) {
2225 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
2226 "\n ERFSLEEP: %d times TcbBusyQueue[%d] = %d !\n",
2227 MAX_DOZE_WAITING_TIMES_9x
,
2229 skb_queue_len(&ring
->queue
));
2234 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_HALT_NIC
) {
2235 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
2236 "IPS Set eRf nic disable\n");
2237 rtl_ps_disable_nic(hw
);
2238 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
2240 if (ppsc
->rfoff_reason
== RF_CHANGE_BY_IPS
) {
2241 rtlpriv
->cfg
->ops
->led_control(hw
,
2244 rtlpriv
->cfg
->ops
->led_control(hw
,
2250 if (ppsc
->rfpwr_state
== ERFOFF
)
2252 for (queue_id
= 0, i
= 0;
2253 queue_id
< RTL_PCI_MAX_TX_QUEUE_COUNT
;) {
2254 ring
= &pcipriv
->dev
.tx_ring
[queue_id
];
2255 if (skb_queue_len(&ring
->queue
) == 0) {
2259 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
2260 "eRf Off/Sleep: %d times TcbBusyQueue[%d] =%d before doze!\n",
2262 skb_queue_len(&ring
->queue
));
2267 if (i
>= MAX_DOZE_WAITING_TIMES_9x
) {
2268 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
2269 "\n ERFSLEEP: %d times TcbBusyQueue[%d] = %d !\n",
2270 MAX_DOZE_WAITING_TIMES_9x
,
2272 skb_queue_len(&ring
->queue
));
2276 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
2277 "Set ERFSLEEP awaked:%d ms\n",
2278 jiffies_to_msecs(jiffies
-
2279 ppsc
->last_awake_jiffies
));
2280 ppsc
->last_sleep_jiffies
= jiffies
;
2281 _rtl88ee_phy_set_rf_sleep(hw
);
2285 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
2286 "switch case %#x not processed\n", rfpwr_state
);
2291 ppsc
->rfpwr_state
= rfpwr_state
;
2295 bool rtl88e_phy_set_rf_power_state(struct ieee80211_hw
*hw
,
2296 enum rf_pwrstate rfpwr_state
)
2298 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
2300 bool bresult
= false;
2302 if (rfpwr_state
== ppsc
->rfpwr_state
)
2304 bresult
= _rtl88ee_phy_set_rf_power_state(hw
, rfpwr_state
);