1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2014 Realtek Corporation.*/
10 #include "../rtl8723com/phy_common.h"
13 #include "../rtl8723com/dm_common.h"
16 #include <linux/kernel.h>
18 static bool _rtl8723be_phy_bb8723b_config_parafile(struct ieee80211_hw
*hw
);
19 static bool _rtl8723be_phy_config_mac_with_headerfile(struct ieee80211_hw
*hw
);
20 static bool _rtl8723be_phy_config_bb_with_headerfile(struct ieee80211_hw
*hw
,
22 static bool _rtl8723be_phy_config_bb_with_pgheaderfile(struct ieee80211_hw
*hw
,
24 static bool _rtl8723be_phy_sw_chnl_step_by_step(struct ieee80211_hw
*hw
,
25 u8 channel
, u8
*stage
,
26 u8
*step
, u32
*delay
);
28 static void rtl8723be_phy_set_rf_on(struct ieee80211_hw
*hw
);
29 static void rtl8723be_phy_set_io(struct ieee80211_hw
*hw
);
31 u32
rtl8723be_phy_query_rf_reg(struct ieee80211_hw
*hw
, enum radio_path rfpath
,
32 u32 regaddr
, u32 bitmask
)
34 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
35 u32 original_value
, readback_value
, bitshift
;
37 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
38 "regaddr(%#x), rfpath(%#x), bitmask(%#x)\n",
39 regaddr
, rfpath
, bitmask
);
41 spin_lock(&rtlpriv
->locks
.rf_lock
);
43 original_value
= rtl8723_phy_rf_serial_read(hw
, rfpath
, regaddr
);
44 bitshift
= rtl8723_phy_calculate_bit_shift(bitmask
);
45 readback_value
= (original_value
& bitmask
) >> bitshift
;
47 spin_unlock(&rtlpriv
->locks
.rf_lock
);
49 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
50 "regaddr(%#x), rfpath(%#x), bitmask(%#x), original_value(%#x)\n",
51 regaddr
, rfpath
, bitmask
, original_value
);
53 return readback_value
;
56 void rtl8723be_phy_set_rf_reg(struct ieee80211_hw
*hw
, enum radio_path path
,
57 u32 regaddr
, u32 bitmask
, u32 data
)
59 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
60 u32 original_value
, bitshift
;
62 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
63 "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
64 regaddr
, bitmask
, data
, path
);
66 spin_lock(&rtlpriv
->locks
.rf_lock
);
68 if (bitmask
!= RFREG_OFFSET_MASK
) {
69 original_value
= rtl8723_phy_rf_serial_read(hw
, path
,
71 bitshift
= rtl8723_phy_calculate_bit_shift(bitmask
);
72 data
= ((original_value
& (~bitmask
)) |
76 rtl8723_phy_rf_serial_write(hw
, path
, regaddr
, data
);
78 spin_unlock(&rtlpriv
->locks
.rf_lock
);
80 RT_TRACE(rtlpriv
, COMP_RF
, DBG_TRACE
,
81 "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
82 regaddr
, bitmask
, data
, path
);
86 bool rtl8723be_phy_mac_config(struct ieee80211_hw
*hw
)
88 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
89 bool rtstatus
= _rtl8723be_phy_config_mac_with_headerfile(hw
);
91 rtl_write_byte(rtlpriv
, 0x04CA, 0x0B);
95 bool rtl8723be_phy_bb_config(struct ieee80211_hw
*hw
)
98 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
100 u8 b_reg_hwparafile
= 1;
102 u8 crystalcap
= rtlpriv
->efuse
.crystalcap
;
103 rtl8723_phy_init_bb_rf_reg_def(hw
);
104 regval
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
);
105 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
,
106 regval
| BIT(13) | BIT(0) | BIT(1));
108 rtl_write_byte(rtlpriv
, REG_RF_CTRL
, RF_EN
| RF_RSTB
| RF_SDMRSTB
);
109 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
,
110 FEN_PPLL
| FEN_PCIEA
| FEN_DIO_PCIE
|
111 FEN_BB_GLB_RSTN
| FEN_BBRSTB
);
112 tmp
= rtl_read_dword(rtlpriv
, 0x4c);
113 rtl_write_dword(rtlpriv
, 0x4c, tmp
| BIT(23));
115 rtl_write_byte(rtlpriv
, REG_AFE_XTAL_CTRL
+ 1, 0x80);
117 if (b_reg_hwparafile
== 1)
118 rtstatus
= _rtl8723be_phy_bb8723b_config_parafile(hw
);
120 crystalcap
= crystalcap
& 0x3F;
121 rtl_set_bbreg(hw
, REG_MAC_PHY_CTRL
, 0xFFF000,
122 (crystalcap
| crystalcap
<< 6));
127 bool rtl8723be_phy_rf_config(struct ieee80211_hw
*hw
)
129 return rtl8723be_phy_rf6052_config(hw
);
132 static bool _rtl8723be_check_positive(struct ieee80211_hw
*hw
,
133 const u32 condition1
,
134 const u32 condition2
)
136 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
137 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
138 u32 cut_ver
= ((rtlhal
->version
& CHIP_VER_RTL_MASK
)
139 >> CHIP_VER_RTL_SHIFT
);
140 u32 intf
= (rtlhal
->interface
== INTF_USB
? BIT(1) : BIT(0));
142 u8 board_type
= ((rtlhal
->board_type
& BIT(4)) >> 4) << 0 | /* _GLNA */
143 ((rtlhal
->board_type
& BIT(3)) >> 3) << 1 | /* _GPA */
144 ((rtlhal
->board_type
& BIT(7)) >> 7) << 2 | /* _ALNA */
145 ((rtlhal
->board_type
& BIT(6)) >> 6) << 3 | /* _APA */
146 ((rtlhal
->board_type
& BIT(2)) >> 2) << 4; /* _BT */
148 u32 cond1
= condition1
, cond2
= condition2
;
149 u32 driver1
= cut_ver
<< 24 | /* CUT ver */
150 0 << 20 | /* interface 2/2 */
151 0x04 << 16 | /* platform */
152 rtlhal
->package_type
<< 12 |
153 intf
<< 8 | /* interface 1/2 */
156 u32 driver2
= rtlhal
->type_glna
<< 0 |
157 rtlhal
->type_gpa
<< 8 |
158 rtlhal
->type_alna
<< 16 |
159 rtlhal
->type_apa
<< 24;
161 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
162 "===> [8812A] CheckPositive (cond1, cond2) = (0x%X 0x%X)\n",
164 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
165 "===> [8812A] CheckPositive (driver1, driver2) = (0x%X 0x%X)\n",
168 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
169 " (Platform, Interface) = (0x%X, 0x%X)\n", 0x04, intf
);
170 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
171 " (Board, Package) = (0x%X, 0x%X)\n",
172 rtlhal
->board_type
, rtlhal
->package_type
);
174 /*============== Value Defined Check ===============*/
175 /*QFN Type [15:12] and Cut Version [27:24] need to do value check*/
177 if (((cond1
& 0x0000F000) != 0) && ((cond1
& 0x0000F000) !=
178 (driver1
& 0x0000F000)))
180 if (((cond1
& 0x0F000000) != 0) && ((cond1
& 0x0F000000) !=
181 (driver1
& 0x0F000000)))
184 /*=============== Bit Defined Check ================*/
185 /* We don't care [31:28] */
188 driver1
&= 0x00FF0FFF;
190 if ((cond1
& driver1
) == cond1
) {
193 if ((cond1
& 0x0F) == 0) /* BoardType is DONTCARE*/
196 if ((cond1
& BIT(0)) != 0) /*GLNA*/
198 if ((cond1
& BIT(1)) != 0) /*GPA*/
200 if ((cond1
& BIT(2)) != 0) /*ALNA*/
202 if ((cond1
& BIT(3)) != 0) /*APA*/
205 /* BoardType of each RF path is matched*/
206 if ((cond2
& mask
) == (driver2
& mask
))
214 static void _rtl8723be_config_rf_reg(struct ieee80211_hw
*hw
, u32 addr
,
215 u32 data
, enum radio_path rfpath
,
218 if (addr
== 0xfe || addr
== 0xffe) {
219 /* In order not to disturb BT music
220 * when wifi init.(1ant NIC only)
224 rtl_set_rfreg(hw
, rfpath
, regaddr
, RFREG_OFFSET_MASK
, data
);
228 static void _rtl8723be_config_rf_radio_a(struct ieee80211_hw
*hw
,
231 u32 content
= 0x1000; /*RF Content: radio_a_txt*/
232 u32 maskforphyset
= (u32
)(content
& 0xE000);
234 _rtl8723be_config_rf_reg(hw
, addr
, data
, RF90_PATH_A
,
235 addr
| maskforphyset
);
239 static void _rtl8723be_phy_init_tx_power_by_rate(struct ieee80211_hw
*hw
)
241 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
242 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
244 u8 band
, path
, txnum
, section
;
246 for (band
= BAND_ON_2_4G
; band
<= BAND_ON_5G
; ++band
)
247 for (path
= 0; path
< TX_PWR_BY_RATE_NUM_RF
; ++path
)
248 for (txnum
= 0; txnum
< TX_PWR_BY_RATE_NUM_RF
; ++txnum
)
250 section
< TX_PWR_BY_RATE_NUM_SECTION
;
252 rtlphy
->tx_power_by_rate_offset
253 [band
][path
][txnum
][section
] = 0;
256 static void _rtl8723be_config_bb_reg(struct ieee80211_hw
*hw
,
261 } else if (addr
== 0xfd) {
263 } else if (addr
== 0xfc) {
265 } else if (addr
== 0xfb) {
267 } else if (addr
== 0xfa) {
269 } else if (addr
== 0xf9) {
272 rtl_set_bbreg(hw
, addr
, MASKDWORD
, data
);
277 static void _rtl8723be_phy_set_txpower_by_rate_base(struct ieee80211_hw
*hw
,
279 u8 path
, u8 rate_section
,
282 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
283 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
285 if (path
> RF90_PATH_D
) {
286 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
287 "Invalid Rf Path %d in phy_SetTxPowerByRatBase()\n",
292 if (band
== BAND_ON_2_4G
) {
293 switch (rate_section
) {
295 rtlphy
->txpwr_by_rate_base_24g
[path
][txnum
][0] = value
;
298 rtlphy
->txpwr_by_rate_base_24g
[path
][txnum
][1] = value
;
301 rtlphy
->txpwr_by_rate_base_24g
[path
][txnum
][2] = value
;
304 rtlphy
->txpwr_by_rate_base_24g
[path
][txnum
][3] = value
;
307 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
308 "Invalid RateSection %d in Band 2.4G, Rf Path %d, %dTx in PHY_SetTxPowerByRateBase()\n",
309 rate_section
, path
, txnum
);
313 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
314 "Invalid Band %d in PHY_SetTxPowerByRateBase()\n",
320 static u8
_rtl8723be_phy_get_txpower_by_rate_base(struct ieee80211_hw
*hw
,
321 u8 band
, u8 path
, u8 txnum
,
324 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
325 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
327 if (path
> RF90_PATH_D
) {
328 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
329 "Invalid Rf Path %d in PHY_GetTxPowerByRateBase()\n",
334 if (band
== BAND_ON_2_4G
) {
335 switch (rate_section
) {
337 value
= rtlphy
->txpwr_by_rate_base_24g
[path
][txnum
][0];
340 value
= rtlphy
->txpwr_by_rate_base_24g
[path
][txnum
][1];
343 value
= rtlphy
->txpwr_by_rate_base_24g
[path
][txnum
][2];
346 value
= rtlphy
->txpwr_by_rate_base_24g
[path
][txnum
][3];
349 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
350 "Invalid RateSection %d in Band 2.4G, Rf Path %d, %dTx in PHY_GetTxPowerByRateBase()\n",
351 rate_section
, path
, txnum
);
355 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
356 "Invalid Band %d in PHY_GetTxPowerByRateBase()\n",
363 static void _rtl8723be_phy_store_txpower_by_rate_base(struct ieee80211_hw
*hw
)
365 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
366 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
368 u8 base
= 0, path
= 0;
370 for (path
= RF90_PATH_A
; path
<= RF90_PATH_B
; ++path
) {
371 if (path
== RF90_PATH_A
) {
372 rawvalue
= (u16
)(rtlphy
->tx_power_by_rate_offset
373 [BAND_ON_2_4G
][path
][RF_1TX
][3] >> 24) & 0xFF;
374 base
= (rawvalue
>> 4) * 10 + (rawvalue
& 0xF);
375 _rtl8723be_phy_set_txpower_by_rate_base(hw
,
376 BAND_ON_2_4G
, path
, CCK
, RF_1TX
, base
);
377 } else if (path
== RF90_PATH_B
) {
378 rawvalue
= (u16
)(rtlphy
->tx_power_by_rate_offset
379 [BAND_ON_2_4G
][path
][RF_1TX
][3] >> 0) & 0xFF;
380 base
= (rawvalue
>> 4) * 10 + (rawvalue
& 0xF);
381 _rtl8723be_phy_set_txpower_by_rate_base(hw
,
386 rawvalue
= (u16
)(rtlphy
->tx_power_by_rate_offset
387 [BAND_ON_2_4G
][path
][RF_1TX
][1] >> 24) & 0xFF;
388 base
= (rawvalue
>> 4) * 10 + (rawvalue
& 0xF);
389 _rtl8723be_phy_set_txpower_by_rate_base(hw
, BAND_ON_2_4G
,
393 rawvalue
= (u16
)(rtlphy
->tx_power_by_rate_offset
394 [BAND_ON_2_4G
][path
][RF_1TX
][5] >> 24) & 0xFF;
395 base
= (rawvalue
>> 4) * 10 + (rawvalue
& 0xF);
396 _rtl8723be_phy_set_txpower_by_rate_base(hw
, BAND_ON_2_4G
,
400 rawvalue
= (u16
)(rtlphy
->tx_power_by_rate_offset
401 [BAND_ON_2_4G
][path
][RF_2TX
][7] >> 24) & 0xFF;
402 base
= (rawvalue
>> 4) * 10 + (rawvalue
& 0xF);
403 _rtl8723be_phy_set_txpower_by_rate_base(hw
, BAND_ON_2_4G
,
409 static void _phy_convert_txpower_dbm_to_relative_value(u32
*data
, u8 start
,
416 for (i
= 3; i
>= 0; --i
) {
417 if (i
>= start
&& i
<= end
) {
418 /* Get the exact value */
419 temp_value
= (u8
)(*data
>> (i
* 8)) & 0xF;
420 temp_value
+= ((u8
)((*data
>> (i
*8 + 4)) & 0xF)) * 10;
422 /* Change the value to a relative value */
423 temp_value
= (temp_value
> base_val
) ?
424 temp_value
- base_val
:
425 base_val
- temp_value
;
427 temp_value
= (u8
)(*data
>> (i
* 8)) & 0xFF;
430 temp_data
|= temp_value
;
435 static void _rtl8723be_phy_convert_txpower_dbm_to_relative_value(
436 struct ieee80211_hw
*hw
)
438 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
439 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
440 u8 base
= 0, rfpath
= RF90_PATH_A
;
442 base
= _rtl8723be_phy_get_txpower_by_rate_base(hw
,
443 BAND_ON_2_4G
, rfpath
, RF_1TX
, CCK
);
444 _phy_convert_txpower_dbm_to_relative_value(
445 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][rfpath
][RF_1TX
][2],
447 _phy_convert_txpower_dbm_to_relative_value(
448 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][rfpath
][RF_1TX
][3],
451 base
= _rtl8723be_phy_get_txpower_by_rate_base(hw
, BAND_ON_2_4G
, rfpath
,
453 _phy_convert_txpower_dbm_to_relative_value(
454 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][rfpath
][RF_1TX
][0],
456 _phy_convert_txpower_dbm_to_relative_value(
457 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][rfpath
][RF_1TX
][1],
460 base
= _rtl8723be_phy_get_txpower_by_rate_base(hw
, BAND_ON_2_4G
,
461 rfpath
, RF_1TX
, HT_MCS0_MCS7
);
462 _phy_convert_txpower_dbm_to_relative_value(
463 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][rfpath
][RF_1TX
][4],
465 _phy_convert_txpower_dbm_to_relative_value(
466 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][rfpath
][RF_1TX
][5],
469 base
= _rtl8723be_phy_get_txpower_by_rate_base(hw
, BAND_ON_2_4G
,
472 _phy_convert_txpower_dbm_to_relative_value(
473 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][rfpath
][RF_2TX
][6],
476 _phy_convert_txpower_dbm_to_relative_value(
477 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][rfpath
][RF_2TX
][7],
480 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_TRACE
,
481 "<===_rtl8723be_phy_convert_txpower_dbm_to_relative_value()\n");
484 static void phy_txpower_by_rate_config(struct ieee80211_hw
*hw
)
486 _rtl8723be_phy_store_txpower_by_rate_base(hw
);
487 _rtl8723be_phy_convert_txpower_dbm_to_relative_value(hw
);
490 static bool _rtl8723be_phy_bb8723b_config_parafile(struct ieee80211_hw
*hw
)
492 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
493 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
494 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
497 /* switch ant to BT */
498 if (rtlpriv
->rtlhal
.interface
== INTF_USB
) {
499 rtl_write_dword(rtlpriv
, 0x948, 0x0);
501 if (rtlpriv
->btcoexist
.btc_info
.single_ant_path
== 0)
502 rtl_write_dword(rtlpriv
, 0x948, 0x280);
504 rtl_write_dword(rtlpriv
, 0x948, 0x0);
507 rtstatus
= _rtl8723be_phy_config_bb_with_headerfile(hw
,
508 BASEBAND_CONFIG_PHY_REG
);
510 pr_err("Write BB Reg Fail!!\n");
513 _rtl8723be_phy_init_tx_power_by_rate(hw
);
514 if (!rtlefuse
->autoload_failflag
) {
515 rtlphy
->pwrgroup_cnt
= 0;
516 rtstatus
= _rtl8723be_phy_config_bb_with_pgheaderfile(hw
,
517 BASEBAND_CONFIG_PHY_REG
);
519 phy_txpower_by_rate_config(hw
);
521 pr_err("BB_PG Reg Fail!!\n");
524 rtstatus
= _rtl8723be_phy_config_bb_with_headerfile(hw
,
525 BASEBAND_CONFIG_AGC_TAB
);
527 pr_err("AGC Table Fail\n");
530 rtlphy
->cck_high_power
= (bool)(rtl_get_bbreg(hw
,
531 RFPGA0_XA_HSSIPARAMETER2
,
536 static bool rtl8723be_phy_config_with_headerfile(struct ieee80211_hw
*hw
,
539 void (*set_reg
)(struct ieee80211_hw
*hw
, u32 regaddr
, u32 data
))
546 bool matched
= true, skipped
= false;
548 while ((i
+ 1) < arraylen
) {
549 u32 v1
= array_table
[i
];
550 u32 v2
= array_table
[i
+ 1];
552 if (v1
& (BIT(31) | BIT(30))) {/*positive & negative condition*/
553 if (v1
& BIT(31)) {/* positive condition*/
554 cond
= (u8
)((v1
& (BIT(29) | BIT(28))) >> 28);
555 if (cond
== COND_ENDIF
) { /*end*/
558 } else if (cond
== COND_ELSE
) { /*else*/
559 matched
= skipped
? false : true;
560 } else {/*if , else if*/
564 if (_rtl8723be_check_positive(
574 } else if (v1
& BIT(30)) { /*negative condition*/
587 static bool _rtl8723be_phy_config_mac_with_headerfile(struct ieee80211_hw
*hw
)
589 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
591 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
, "Read rtl8723beMACPHY_Array\n");
593 return rtl8723be_phy_config_with_headerfile(hw
,
594 RTL8723BEMAC_1T_ARRAY
, RTL8723BEMAC_1T_ARRAYLEN
,
595 rtl_write_byte_with_val32
);
598 static bool _rtl8723be_phy_config_bb_with_headerfile(struct ieee80211_hw
*hw
,
602 if (configtype
== BASEBAND_CONFIG_PHY_REG
)
603 return rtl8723be_phy_config_with_headerfile(hw
,
604 RTL8723BEPHY_REG_1TARRAY
,
605 RTL8723BEPHY_REG_1TARRAYLEN
,
606 _rtl8723be_config_bb_reg
);
607 else if (configtype
== BASEBAND_CONFIG_AGC_TAB
)
608 return rtl8723be_phy_config_with_headerfile(hw
,
609 RTL8723BEAGCTAB_1TARRAY
,
610 RTL8723BEAGCTAB_1TARRAYLEN
,
611 rtl_set_bbreg_with_dwmask
);
616 static u8
_rtl8723be_get_rate_section_index(u32 regaddr
)
621 case RTXAGC_A_RATE18_06
:
624 case RTXAGC_A_RATE54_24
:
627 case RTXAGC_A_CCK1_MCS32
:
630 case RTXAGC_B_CCK11_A_CCK2_11
:
633 case RTXAGC_A_MCS03_MCS00
:
636 case RTXAGC_A_MCS07_MCS04
:
639 case RTXAGC_A_MCS11_MCS08
:
642 case RTXAGC_A_MCS15_MCS12
:
645 case RTXAGC_B_RATE18_06
:
648 case RTXAGC_B_RATE54_24
:
651 case RTXAGC_B_CCK1_55_MCS32
:
654 case RTXAGC_B_MCS03_MCS00
:
657 case RTXAGC_B_MCS07_MCS04
:
660 case RTXAGC_B_MCS11_MCS08
:
663 case RTXAGC_B_MCS15_MCS12
:
668 if (regaddr
>= 0xC20 && regaddr
<= 0xC4C)
669 index
= (u8
)((regaddr
- 0xC20) / 4);
670 else if (regaddr
>= 0xE20 && regaddr
<= 0xE4C)
671 index
= (u8
)((regaddr
- 0xE20) / 4);
677 static void _rtl8723be_store_tx_power_by_rate(struct ieee80211_hw
*hw
,
678 u32 band
, u32 rfpath
,
679 u32 txnum
, u32 regaddr
,
680 u32 bitmask
, u32 data
)
682 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
683 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
684 u8 rate_section
= _rtl8723be_get_rate_section_index(regaddr
);
686 if (band
!= BAND_ON_2_4G
&& band
!= BAND_ON_5G
) {
687 RT_TRACE(rtlpriv
, FPHY
, PHY_TXPWR
, "Invalid Band %d\n", band
);
690 if (rfpath
> MAX_RF_PATH
- 1) {
691 RT_TRACE(rtlpriv
, FPHY
, PHY_TXPWR
,
692 "Invalid RfPath %d\n", rfpath
);
695 if (txnum
> MAX_RF_PATH
- 1) {
696 RT_TRACE(rtlpriv
, FPHY
, PHY_TXPWR
, "Invalid TxNum %d\n", txnum
);
700 rtlphy
->tx_power_by_rate_offset
[band
][rfpath
][txnum
][rate_section
] =
705 static bool _rtl8723be_phy_config_bb_with_pgheaderfile(struct ieee80211_hw
*hw
,
708 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
710 u32
*phy_regarray_table_pg
;
711 u16 phy_regarray_pg_len
;
712 u32 v1
= 0, v2
= 0, v3
= 0, v4
= 0, v5
= 0, v6
= 0;
714 phy_regarray_pg_len
= RTL8723BEPHY_REG_ARRAY_PGLEN
;
715 phy_regarray_table_pg
= RTL8723BEPHY_REG_ARRAY_PG
;
717 if (configtype
== BASEBAND_CONFIG_PHY_REG
) {
718 for (i
= 0; i
< phy_regarray_pg_len
; i
= i
+ 6) {
719 v1
= phy_regarray_table_pg
[i
];
720 v2
= phy_regarray_table_pg
[i
+1];
721 v3
= phy_regarray_table_pg
[i
+2];
722 v4
= phy_regarray_table_pg
[i
+3];
723 v5
= phy_regarray_table_pg
[i
+4];
724 v6
= phy_regarray_table_pg
[i
+5];
726 if (v1
< 0xcdcdcdcd) {
727 if (phy_regarray_table_pg
[i
] == 0xfe ||
728 phy_regarray_table_pg
[i
] == 0xffe)
731 _rtl8723be_store_tx_power_by_rate(hw
,
732 v1
, v2
, v3
, v4
, v5
, v6
);
737 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
738 "configtype != BaseBand_Config_PHY_REG\n");
743 bool rtl8723be_phy_config_rf_with_headerfile(struct ieee80211_hw
*hw
,
744 enum radio_path rfpath
)
746 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
747 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
750 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Radio No %x\n", rfpath
);
753 ret
= rtl8723be_phy_config_with_headerfile(hw
,
754 RTL8723BE_RADIOA_1TARRAY
,
755 RTL8723BE_RADIOA_1TARRAYLEN
,
756 _rtl8723be_config_rf_radio_a
);
758 if (rtlhal
->oem_id
== RT_CID_819X_HP
)
759 _rtl8723be_config_rf_radio_a(hw
, 0x52, 0x7E4BD);
765 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
766 "switch case %#x not processed\n", rfpath
);
772 void rtl8723be_phy_get_hw_reg_originalvalue(struct ieee80211_hw
*hw
)
774 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
775 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
777 rtlphy
->default_initialgain
[0] =
778 (u8
)rtl_get_bbreg(hw
, ROFDM0_XAAGCCORE1
, MASKBYTE0
);
779 rtlphy
->default_initialgain
[1] =
780 (u8
)rtl_get_bbreg(hw
, ROFDM0_XBAGCCORE1
, MASKBYTE0
);
781 rtlphy
->default_initialgain
[2] =
782 (u8
)rtl_get_bbreg(hw
, ROFDM0_XCAGCCORE1
, MASKBYTE0
);
783 rtlphy
->default_initialgain
[3] =
784 (u8
)rtl_get_bbreg(hw
, ROFDM0_XDAGCCORE1
, MASKBYTE0
);
786 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
787 "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x\n",
788 rtlphy
->default_initialgain
[0],
789 rtlphy
->default_initialgain
[1],
790 rtlphy
->default_initialgain
[2],
791 rtlphy
->default_initialgain
[3]);
793 rtlphy
->framesync
= (u8
)rtl_get_bbreg(hw
, ROFDM0_RXDETECTOR3
,
795 rtlphy
->framesync_c34
= rtl_get_bbreg(hw
, ROFDM0_RXDETECTOR2
,
798 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
799 "Default framesync (0x%x) = 0x%x\n",
800 ROFDM0_RXDETECTOR3
, rtlphy
->framesync
);
803 static u8
_rtl8723be_phy_get_ratesection_intxpower_byrate(enum radio_path path
,
814 case DESC92C_RATE5_5M
:
815 if (path
== RF90_PATH_A
)
817 else if (path
== RF90_PATH_B
)
821 case DESC92C_RATE11M
:
827 case DESC92C_RATE12M
:
828 case DESC92C_RATE18M
:
832 case DESC92C_RATE24M
:
833 case DESC92C_RATE36M
:
834 case DESC92C_RATE48M
:
835 case DESC92C_RATE54M
:
839 case DESC92C_RATEMCS0
:
840 case DESC92C_RATEMCS1
:
841 case DESC92C_RATEMCS2
:
842 case DESC92C_RATEMCS3
:
846 case DESC92C_RATEMCS4
:
847 case DESC92C_RATEMCS5
:
848 case DESC92C_RATEMCS6
:
849 case DESC92C_RATEMCS7
:
853 case DESC92C_RATEMCS8
:
854 case DESC92C_RATEMCS9
:
855 case DESC92C_RATEMCS10
:
856 case DESC92C_RATEMCS11
:
860 case DESC92C_RATEMCS12
:
861 case DESC92C_RATEMCS13
:
862 case DESC92C_RATEMCS14
:
863 case DESC92C_RATEMCS15
:
868 WARN_ONCE(true, "rtl8723be: Rate_Section is Illegal\n");
875 static u8
_rtl8723be_get_txpower_by_rate(struct ieee80211_hw
*hw
,
877 enum radio_path rfpath
, u8 rate
)
879 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
880 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
881 u8 shift
= 0, rate_section
, tx_num
;
884 rate_section
= _rtl8723be_phy_get_ratesection_intxpower_byrate(rfpath
,
886 tx_num
= RF_TX_NUM_NONIMPLEMENT
;
888 if (tx_num
== RF_TX_NUM_NONIMPLEMENT
) {
889 if (rate
>= DESC92C_RATEMCS8
&& rate
<= DESC92C_RATEMCS15
)
897 case DESC92C_RATE24M
:
898 case DESC92C_RATEMCS0
:
899 case DESC92C_RATEMCS4
:
900 case DESC92C_RATEMCS8
:
901 case DESC92C_RATEMCS12
:
907 case DESC92C_RATE36M
:
908 case DESC92C_RATEMCS1
:
909 case DESC92C_RATEMCS5
:
910 case DESC92C_RATEMCS9
:
911 case DESC92C_RATEMCS13
:
914 case DESC92C_RATE5_5M
:
915 case DESC92C_RATE12M
:
916 case DESC92C_RATE48M
:
917 case DESC92C_RATEMCS2
:
918 case DESC92C_RATEMCS6
:
919 case DESC92C_RATEMCS10
:
920 case DESC92C_RATEMCS14
:
923 case DESC92C_RATE11M
:
924 case DESC92C_RATE18M
:
925 case DESC92C_RATE54M
:
926 case DESC92C_RATEMCS3
:
927 case DESC92C_RATEMCS7
:
928 case DESC92C_RATEMCS11
:
929 case DESC92C_RATEMCS15
:
933 WARN_ONCE(true, "rtl8723be: Rate_Section is Illegal\n");
936 tx_pwr_diff
= (u8
)(rtlphy
->tx_power_by_rate_offset
[band
][rfpath
][tx_num
]
937 [rate_section
] >> shift
) & 0xff;
942 static u8
_rtl8723be_get_txpower_index(struct ieee80211_hw
*hw
, u8 path
,
943 u8 rate
, u8 bandwidth
, u8 channel
)
945 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
946 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
947 u8 index
= (channel
- 1);
949 u8 power_diff_byrate
= 0;
951 if (channel
> 14 || channel
< 1) {
953 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
,
954 "Illegal channel!\n");
956 if (RX_HAL_IS_CCK_RATE(rate
))
957 txpower
= rtlefuse
->txpwrlevel_cck
[path
][index
];
958 else if (DESC92C_RATE6M
<= rate
)
959 txpower
= rtlefuse
->txpwrlevel_ht40_1s
[path
][index
];
961 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
,
964 if (DESC92C_RATE6M
<= rate
&& rate
<= DESC92C_RATE54M
&&
965 !RX_HAL_IS_CCK_RATE(rate
))
966 txpower
+= rtlefuse
->txpwr_legacyhtdiff
[0][TX_1S
];
968 if (bandwidth
== HT_CHANNEL_WIDTH_20
) {
969 if (DESC92C_RATEMCS0
<= rate
&& rate
<= DESC92C_RATEMCS15
)
970 txpower
+= rtlefuse
->txpwr_ht20diff
[0][TX_1S
];
971 if (DESC92C_RATEMCS8
<= rate
&& rate
<= DESC92C_RATEMCS15
)
972 txpower
+= rtlefuse
->txpwr_ht20diff
[0][TX_2S
];
973 } else if (bandwidth
== HT_CHANNEL_WIDTH_20_40
) {
974 if (DESC92C_RATEMCS0
<= rate
&& rate
<= DESC92C_RATEMCS15
)
975 txpower
+= rtlefuse
->txpwr_ht40diff
[0][TX_1S
];
976 if (DESC92C_RATEMCS8
<= rate
&& rate
<= DESC92C_RATEMCS15
)
977 txpower
+= rtlefuse
->txpwr_ht40diff
[0][TX_2S
];
980 if (rtlefuse
->eeprom_regulatory
!= 2)
981 power_diff_byrate
= _rtl8723be_get_txpower_by_rate(hw
,
985 txpower
+= power_diff_byrate
;
987 if (txpower
> MAX_POWER_INDEX
)
988 txpower
= MAX_POWER_INDEX
;
993 static void _rtl8723be_phy_set_txpower_index(struct ieee80211_hw
*hw
,
994 u8 power_index
, u8 path
, u8 rate
)
996 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
997 if (path
== RF90_PATH_A
) {
1000 rtl8723_phy_set_bb_reg(hw
, RTXAGC_A_CCK1_MCS32
,
1001 MASKBYTE1
, power_index
);
1003 case DESC92C_RATE2M
:
1004 rtl8723_phy_set_bb_reg(hw
, RTXAGC_B_CCK11_A_CCK2_11
,
1005 MASKBYTE1
, power_index
);
1007 case DESC92C_RATE5_5M
:
1008 rtl8723_phy_set_bb_reg(hw
, RTXAGC_B_CCK11_A_CCK2_11
,
1009 MASKBYTE2
, power_index
);
1011 case DESC92C_RATE11M
:
1012 rtl8723_phy_set_bb_reg(hw
, RTXAGC_B_CCK11_A_CCK2_11
,
1013 MASKBYTE3
, power_index
);
1016 case DESC92C_RATE6M
:
1017 rtl8723_phy_set_bb_reg(hw
, RTXAGC_A_RATE18_06
,
1018 MASKBYTE0
, power_index
);
1020 case DESC92C_RATE9M
:
1021 rtl8723_phy_set_bb_reg(hw
, RTXAGC_A_RATE18_06
,
1022 MASKBYTE1
, power_index
);
1024 case DESC92C_RATE12M
:
1025 rtl8723_phy_set_bb_reg(hw
, RTXAGC_A_RATE18_06
,
1026 MASKBYTE2
, power_index
);
1028 case DESC92C_RATE18M
:
1029 rtl8723_phy_set_bb_reg(hw
, RTXAGC_A_RATE18_06
,
1030 MASKBYTE3
, power_index
);
1033 case DESC92C_RATE24M
:
1034 rtl8723_phy_set_bb_reg(hw
, RTXAGC_A_RATE54_24
,
1035 MASKBYTE0
, power_index
);
1037 case DESC92C_RATE36M
:
1038 rtl8723_phy_set_bb_reg(hw
, RTXAGC_A_RATE54_24
,
1039 MASKBYTE1
, power_index
);
1041 case DESC92C_RATE48M
:
1042 rtl8723_phy_set_bb_reg(hw
, RTXAGC_A_RATE54_24
,
1043 MASKBYTE2
, power_index
);
1045 case DESC92C_RATE54M
:
1046 rtl8723_phy_set_bb_reg(hw
, RTXAGC_A_RATE54_24
,
1047 MASKBYTE3
, power_index
);
1050 case DESC92C_RATEMCS0
:
1051 rtl8723_phy_set_bb_reg(hw
, RTXAGC_A_MCS03_MCS00
,
1052 MASKBYTE0
, power_index
);
1054 case DESC92C_RATEMCS1
:
1055 rtl8723_phy_set_bb_reg(hw
, RTXAGC_A_MCS03_MCS00
,
1056 MASKBYTE1
, power_index
);
1058 case DESC92C_RATEMCS2
:
1059 rtl8723_phy_set_bb_reg(hw
, RTXAGC_A_MCS03_MCS00
,
1060 MASKBYTE2
, power_index
);
1062 case DESC92C_RATEMCS3
:
1063 rtl8723_phy_set_bb_reg(hw
, RTXAGC_A_MCS03_MCS00
,
1064 MASKBYTE3
, power_index
);
1067 case DESC92C_RATEMCS4
:
1068 rtl8723_phy_set_bb_reg(hw
, RTXAGC_A_MCS07_MCS04
,
1069 MASKBYTE0
, power_index
);
1071 case DESC92C_RATEMCS5
:
1072 rtl8723_phy_set_bb_reg(hw
, RTXAGC_A_MCS07_MCS04
,
1073 MASKBYTE1
, power_index
);
1075 case DESC92C_RATEMCS6
:
1076 rtl8723_phy_set_bb_reg(hw
, RTXAGC_A_MCS07_MCS04
,
1077 MASKBYTE2
, power_index
);
1079 case DESC92C_RATEMCS7
:
1080 rtl8723_phy_set_bb_reg(hw
, RTXAGC_A_MCS07_MCS04
,
1081 MASKBYTE3
, power_index
);
1084 case DESC92C_RATEMCS8
:
1085 rtl8723_phy_set_bb_reg(hw
, RTXAGC_A_MCS11_MCS08
,
1086 MASKBYTE0
, power_index
);
1088 case DESC92C_RATEMCS9
:
1089 rtl8723_phy_set_bb_reg(hw
, RTXAGC_A_MCS11_MCS08
,
1090 MASKBYTE1
, power_index
);
1092 case DESC92C_RATEMCS10
:
1093 rtl8723_phy_set_bb_reg(hw
, RTXAGC_A_MCS11_MCS08
,
1094 MASKBYTE2
, power_index
);
1096 case DESC92C_RATEMCS11
:
1097 rtl8723_phy_set_bb_reg(hw
, RTXAGC_A_MCS11_MCS08
,
1098 MASKBYTE3
, power_index
);
1102 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
, "Invalid Rate!!\n");
1106 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
, "Invalid RFPath!!\n");
1110 void rtl8723be_phy_set_txpower_level(struct ieee80211_hw
*hw
, u8 channel
)
1112 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1113 u8 cck_rates
[] = {DESC92C_RATE1M
, DESC92C_RATE2M
,
1114 DESC92C_RATE5_5M
, DESC92C_RATE11M
};
1115 u8 ofdm_rates
[] = {DESC92C_RATE6M
, DESC92C_RATE9M
,
1116 DESC92C_RATE12M
, DESC92C_RATE18M
,
1117 DESC92C_RATE24M
, DESC92C_RATE36M
,
1118 DESC92C_RATE48M
, DESC92C_RATE54M
};
1119 u8 ht_rates_1t
[] = {DESC92C_RATEMCS0
, DESC92C_RATEMCS1
,
1120 DESC92C_RATEMCS2
, DESC92C_RATEMCS3
,
1121 DESC92C_RATEMCS4
, DESC92C_RATEMCS5
,
1122 DESC92C_RATEMCS6
, DESC92C_RATEMCS7
};
1126 if (!rtlefuse
->txpwr_fromeprom
)
1129 for (i
= 0; i
< ARRAY_SIZE(cck_rates
); i
++) {
1130 power_index
= _rtl8723be_get_txpower_index(hw
, RF90_PATH_A
,
1132 rtl_priv(hw
)->phy
.current_chan_bw
,
1134 _rtl8723be_phy_set_txpower_index(hw
, power_index
, RF90_PATH_A
,
1137 for (i
= 0; i
< ARRAY_SIZE(ofdm_rates
); i
++) {
1138 power_index
= _rtl8723be_get_txpower_index(hw
, RF90_PATH_A
,
1140 rtl_priv(hw
)->phy
.current_chan_bw
,
1142 _rtl8723be_phy_set_txpower_index(hw
, power_index
, RF90_PATH_A
,
1145 for (i
= 0; i
< ARRAY_SIZE(ht_rates_1t
); i
++) {
1146 power_index
= _rtl8723be_get_txpower_index(hw
, RF90_PATH_A
,
1148 rtl_priv(hw
)->phy
.current_chan_bw
,
1150 _rtl8723be_phy_set_txpower_index(hw
, power_index
, RF90_PATH_A
,
1155 void rtl8723be_phy_scan_operation_backup(struct ieee80211_hw
*hw
, u8 operation
)
1157 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1158 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1159 enum io_type iotype
;
1161 if (!is_hal_stop(rtlhal
)) {
1162 switch (operation
) {
1163 case SCAN_OPT_BACKUP_BAND0
:
1164 iotype
= IO_CMD_PAUSE_BAND0_DM_BY_SCAN
;
1165 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_IO_CMD
,
1169 case SCAN_OPT_RESTORE
:
1170 iotype
= IO_CMD_RESUME_DM_BY_SCAN
;
1171 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_IO_CMD
,
1175 pr_err("Unknown Scan Backup operation.\n");
1181 void rtl8723be_phy_set_bw_mode_callback(struct ieee80211_hw
*hw
)
1183 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1184 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1185 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1186 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1190 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_TRACE
,
1191 "Switch to %s bandwidth\n",
1192 rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20
?
1195 if (is_hal_stop(rtlhal
)) {
1196 rtlphy
->set_bwmode_inprogress
= false;
1200 reg_bw_opmode
= rtl_read_byte(rtlpriv
, REG_BWOPMODE
);
1201 reg_prsr_rsc
= rtl_read_byte(rtlpriv
, REG_RRSR
+ 2);
1203 switch (rtlphy
->current_chan_bw
) {
1204 case HT_CHANNEL_WIDTH_20
:
1205 reg_bw_opmode
|= BW_OPMODE_20MHZ
;
1206 rtl_write_byte(rtlpriv
, REG_BWOPMODE
, reg_bw_opmode
);
1208 case HT_CHANNEL_WIDTH_20_40
:
1209 reg_bw_opmode
&= ~BW_OPMODE_20MHZ
;
1210 rtl_write_byte(rtlpriv
, REG_BWOPMODE
, reg_bw_opmode
);
1211 reg_prsr_rsc
= (reg_prsr_rsc
& 0x90) |
1212 (mac
->cur_40_prime_sc
<< 5);
1213 rtl_write_byte(rtlpriv
, REG_RRSR
+ 2, reg_prsr_rsc
);
1216 pr_err("unknown bandwidth: %#X\n",
1217 rtlphy
->current_chan_bw
);
1221 switch (rtlphy
->current_chan_bw
) {
1222 case HT_CHANNEL_WIDTH_20
:
1223 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BRFMOD
, 0x0);
1224 rtl_set_bbreg(hw
, RFPGA1_RFMOD
, BRFMOD
, 0x0);
1225 /* rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 1);*/
1227 case HT_CHANNEL_WIDTH_20_40
:
1228 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BRFMOD
, 0x1);
1229 rtl_set_bbreg(hw
, RFPGA1_RFMOD
, BRFMOD
, 0x1);
1231 rtl_set_bbreg(hw
, RCCK0_SYSTEM
, BCCK_SIDEBAND
,
1232 (mac
->cur_40_prime_sc
>> 1));
1233 rtl_set_bbreg(hw
, ROFDM1_LSTF
, 0xC00, mac
->cur_40_prime_sc
);
1234 /*rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 0);*/
1236 rtl_set_bbreg(hw
, 0x818, (BIT(26) | BIT(27)),
1237 (mac
->cur_40_prime_sc
==
1238 HAL_PRIME_CHNL_OFFSET_LOWER
) ? 2 : 1);
1241 pr_err("unknown bandwidth: %#X\n",
1242 rtlphy
->current_chan_bw
);
1245 rtl8723be_phy_rf6052_set_bandwidth(hw
, rtlphy
->current_chan_bw
);
1246 rtlphy
->set_bwmode_inprogress
= false;
1247 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_LOUD
, "\n");
1250 void rtl8723be_phy_set_bw_mode(struct ieee80211_hw
*hw
,
1251 enum nl80211_channel_type ch_type
)
1253 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1254 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1255 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1256 u8 tmp_bw
= rtlphy
->current_chan_bw
;
1258 if (rtlphy
->set_bwmode_inprogress
)
1260 rtlphy
->set_bwmode_inprogress
= true;
1261 if ((!is_hal_stop(rtlhal
)) && !(RT_CANNOT_IO(hw
))) {
1262 rtl8723be_phy_set_bw_mode_callback(hw
);
1264 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1265 "false driver sleep or unload\n");
1266 rtlphy
->set_bwmode_inprogress
= false;
1267 rtlphy
->current_chan_bw
= tmp_bw
;
1271 void rtl8723be_phy_sw_chnl_callback(struct ieee80211_hw
*hw
)
1273 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1274 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1275 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1278 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_TRACE
,
1279 "switch to channel%d\n", rtlphy
->current_channel
);
1280 if (is_hal_stop(rtlhal
))
1283 if (!rtlphy
->sw_chnl_inprogress
)
1285 if (!_rtl8723be_phy_sw_chnl_step_by_step(hw
,
1286 rtlphy
->current_channel
,
1287 &rtlphy
->sw_chnl_stage
,
1288 &rtlphy
->sw_chnl_step
,
1295 rtlphy
->sw_chnl_inprogress
= false;
1299 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_TRACE
, "\n");
1302 u8
rtl8723be_phy_sw_chnl(struct ieee80211_hw
*hw
)
1304 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1305 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1306 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1308 if (rtlphy
->sw_chnl_inprogress
)
1310 if (rtlphy
->set_bwmode_inprogress
)
1312 WARN_ONCE((rtlphy
->current_channel
> 14),
1313 "rtl8723be: WIRELESS_MODE_G but channel>14");
1314 rtlphy
->sw_chnl_inprogress
= true;
1315 rtlphy
->sw_chnl_stage
= 0;
1316 rtlphy
->sw_chnl_step
= 0;
1317 if (!(is_hal_stop(rtlhal
)) && !(RT_CANNOT_IO(hw
))) {
1318 rtl8723be_phy_sw_chnl_callback(hw
);
1319 RT_TRACE(rtlpriv
, COMP_CHAN
, DBG_LOUD
,
1320 "sw_chnl_inprogress false schedule workitem current channel %d\n",
1321 rtlphy
->current_channel
);
1322 rtlphy
->sw_chnl_inprogress
= false;
1324 RT_TRACE(rtlpriv
, COMP_CHAN
, DBG_LOUD
,
1325 "sw_chnl_inprogress false driver sleep or unload\n");
1326 rtlphy
->sw_chnl_inprogress
= false;
1331 static bool _rtl8723be_phy_sw_chnl_step_by_step(struct ieee80211_hw
*hw
,
1332 u8 channel
, u8
*stage
,
1333 u8
*step
, u32
*delay
)
1335 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1336 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1337 struct swchnlcmd precommoncmd
[MAX_PRECMD_CNT
];
1338 u32 precommoncmdcnt
;
1339 struct swchnlcmd postcommoncmd
[MAX_POSTCMD_CNT
];
1340 u32 postcommoncmdcnt
;
1341 struct swchnlcmd rfdependcmd
[MAX_RFDEPENDCMD_CNT
];
1343 struct swchnlcmd
*currentcmd
= NULL
;
1345 u8 num_total_rfpath
= rtlphy
->num_total_rfpath
;
1347 precommoncmdcnt
= 0;
1348 rtl8723_phy_set_sw_chnl_cmdarray(precommoncmd
, precommoncmdcnt
++,
1350 CMDID_SET_TXPOWEROWER_LEVEL
,
1352 rtl8723_phy_set_sw_chnl_cmdarray(precommoncmd
, precommoncmdcnt
++,
1353 MAX_PRECMD_CNT
, CMDID_END
, 0, 0, 0);
1355 postcommoncmdcnt
= 0;
1357 rtl8723_phy_set_sw_chnl_cmdarray(postcommoncmd
, postcommoncmdcnt
++,
1358 MAX_POSTCMD_CNT
, CMDID_END
,
1363 WARN_ONCE((channel
< 1 || channel
> 14),
1364 "rtl8723be: illegal channel for Zebra: %d\n", channel
);
1366 rtl8723_phy_set_sw_chnl_cmdarray(rfdependcmd
, rfdependcmdcnt
++,
1367 MAX_RFDEPENDCMD_CNT
,
1369 RF_CHNLBW
, channel
, 10);
1371 rtl8723_phy_set_sw_chnl_cmdarray(rfdependcmd
, rfdependcmdcnt
++,
1372 MAX_RFDEPENDCMD_CNT
,
1373 CMDID_END
, 0, 0, 0);
1378 currentcmd
= &precommoncmd
[*step
];
1381 currentcmd
= &rfdependcmd
[*step
];
1384 currentcmd
= &postcommoncmd
[*step
];
1387 pr_err("Invalid 'stage' = %d, Check it!\n",
1392 if (currentcmd
->cmdid
== CMDID_END
) {
1393 if ((*stage
) == 2) {
1402 switch (currentcmd
->cmdid
) {
1403 case CMDID_SET_TXPOWEROWER_LEVEL
:
1404 rtl8723be_phy_set_txpower_level(hw
, channel
);
1406 case CMDID_WRITEPORT_ULONG
:
1407 rtl_write_dword(rtlpriv
, currentcmd
->para1
,
1410 case CMDID_WRITEPORT_USHORT
:
1411 rtl_write_word(rtlpriv
, currentcmd
->para1
,
1412 (u16
)currentcmd
->para2
);
1414 case CMDID_WRITEPORT_UCHAR
:
1415 rtl_write_byte(rtlpriv
, currentcmd
->para1
,
1416 (u8
)currentcmd
->para2
);
1418 case CMDID_RF_WRITEREG
:
1419 for (rfpath
= 0; rfpath
< num_total_rfpath
; rfpath
++) {
1420 rtlphy
->rfreg_chnlval
[rfpath
] =
1421 ((rtlphy
->rfreg_chnlval
[rfpath
] &
1422 0xfffffc00) | currentcmd
->para2
);
1424 rtl_set_rfreg(hw
, (enum radio_path
)rfpath
,
1427 rtlphy
->rfreg_chnlval
[rfpath
]);
1431 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
1432 "switch case %#x not processed\n",
1440 (*delay
) = currentcmd
->msdelay
;
1445 static u8
_rtl8723be_phy_path_a_iqk(struct ieee80211_hw
*hw
)
1447 u32 reg_eac
, reg_e94
, reg_e9c
, tmp
;
1450 /* leave IQK mode */
1451 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x00000000);
1452 /* switch to path A */
1453 rtl_set_bbreg(hw
, 0x948, MASKDWORD
, 0x00000000);
1454 /* enable path A PA in TXIQK mode */
1455 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_WE_LUT
, RFREG_OFFSET_MASK
, 0x800a0);
1456 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_RCK_OS
, RFREG_OFFSET_MASK
, 0x20000);
1457 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_TXPA_G1
, RFREG_OFFSET_MASK
, 0x0003f);
1458 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_TXPA_G2
, RFREG_OFFSET_MASK
, 0xc7f87);
1461 /* path-A IQK setting */
1463 rtl_set_bbreg(hw
, RTX_IQK
, MASKDWORD
, 0x01007c00);
1464 rtl_set_bbreg(hw
, RRX_IQK
, MASKDWORD
, 0x01004800);
1465 /* path-A IQK setting */
1466 rtl_set_bbreg(hw
, RTX_IQK_TONE_A
, MASKDWORD
, 0x18008c1c);
1467 rtl_set_bbreg(hw
, RRX_IQK_TONE_A
, MASKDWORD
, 0x38008c1c);
1468 rtl_set_bbreg(hw
, RTX_IQK_TONE_B
, MASKDWORD
, 0x38008c1c);
1469 rtl_set_bbreg(hw
, RRX_IQK_TONE_B
, MASKDWORD
, 0x38008c1c);
1471 rtl_set_bbreg(hw
, RTX_IQK_PI_A
, MASKDWORD
, 0x821403ea);
1472 rtl_set_bbreg(hw
, RRX_IQK_PI_A
, MASKDWORD
, 0x28160000);
1473 rtl_set_bbreg(hw
, RTX_IQK_PI_B
, MASKDWORD
, 0x82110000);
1474 rtl_set_bbreg(hw
, RRX_IQK_PI_B
, MASKDWORD
, 0x28110000);
1475 /* LO calibration setting */
1476 rtl_set_bbreg(hw
, RIQK_AGC_RSP
, MASKDWORD
, 0x00462911);
1477 /* enter IQK mode */
1478 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x80800000);
1480 /* One shot, path A LOK & IQK */
1481 rtl_set_bbreg(hw
, RIQK_AGC_PTS
, MASKDWORD
, 0xf9000000);
1482 rtl_set_bbreg(hw
, RIQK_AGC_PTS
, MASKDWORD
, 0xf8000000);
1484 mdelay(IQK_DELAY_TIME
);
1486 /* leave IQK mode */
1487 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x00000000);
1490 reg_eac
= rtl_get_bbreg(hw
, 0xeac, MASKDWORD
);
1491 reg_e94
= rtl_get_bbreg(hw
, 0xe94, MASKDWORD
);
1492 reg_e9c
= rtl_get_bbreg(hw
, 0xe9c, MASKDWORD
);
1494 if (!(reg_eac
& BIT(28)) &&
1495 (((reg_e94
& 0x03FF0000) >> 16) != 0x142) &&
1496 (((reg_e9c
& 0x03FF0000) >> 16) != 0x42))
1498 else /* if Tx not OK, ignore Rx */
1501 /* Allen 20131125 */
1502 tmp
= (reg_e9c
& 0x03FF0000) >> 16;
1503 if ((tmp
& 0x200) > 0)
1506 if (!(reg_eac
& BIT(28)) &&
1507 (((reg_e94
& 0x03FF0000) >> 16) < 0x110) &&
1508 (((reg_e94
& 0x03FF0000) >> 16) > 0xf0) &&
1511 else /* if Tx not OK, ignore Rx */
1517 /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */
1518 static u8
_rtl8723be_phy_path_a_rx_iqk(struct ieee80211_hw
*hw
)
1520 u32 reg_eac
, reg_e94
, reg_e9c
, reg_ea4
, u32tmp
, tmp
;
1523 /* leave IQK mode */
1524 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x00000000);
1526 /* switch to path A */
1527 rtl_set_bbreg(hw
, 0x948, MASKDWORD
, 0x00000000);
1529 /* 1 Get TXIMR setting */
1530 /* modify RXIQK mode table */
1531 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_WE_LUT
, 0x80000, 0x1);
1532 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_RCK_OS
, RFREG_OFFSET_MASK
, 0x30000);
1533 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_TXPA_G1
, RFREG_OFFSET_MASK
, 0x0001f);
1534 /* LNA2 off, PA on for Dcut */
1535 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_TXPA_G2
, RFREG_OFFSET_MASK
, 0xf7fb7);
1536 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x80800000);
1539 rtl_set_bbreg(hw
, RTX_IQK
, MASKDWORD
, 0x01007c00);
1540 rtl_set_bbreg(hw
, RRX_IQK
, MASKDWORD
, 0x01004800);
1542 /* path-A IQK setting */
1543 rtl_set_bbreg(hw
, RTX_IQK_TONE_A
, MASKDWORD
, 0x18008c1c);
1544 rtl_set_bbreg(hw
, RRX_IQK_TONE_A
, MASKDWORD
, 0x38008c1c);
1545 rtl_set_bbreg(hw
, RTX_IQK_TONE_B
, MASKDWORD
, 0x38008c1c);
1546 rtl_set_bbreg(hw
, RRX_IQK_TONE_B
, MASKDWORD
, 0x38008c1c);
1548 rtl_set_bbreg(hw
, RTX_IQK_PI_A
, MASKDWORD
, 0x82160ff0);
1549 rtl_set_bbreg(hw
, RRX_IQK_PI_A
, MASKDWORD
, 0x28110000);
1550 rtl_set_bbreg(hw
, RTX_IQK_PI_B
, MASKDWORD
, 0x82110000);
1551 rtl_set_bbreg(hw
, RRX_IQK_PI_B
, MASKDWORD
, 0x28110000);
1553 /* LO calibration setting */
1554 rtl_set_bbreg(hw
, RIQK_AGC_RSP
, MASKDWORD
, 0x0046a911);
1556 /* enter IQK mode */
1557 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x80800000);
1559 /* One shot, path A LOK & IQK */
1560 rtl_set_bbreg(hw
, RIQK_AGC_PTS
, MASKDWORD
, 0xf9000000);
1561 rtl_set_bbreg(hw
, RIQK_AGC_PTS
, MASKDWORD
, 0xf8000000);
1563 mdelay(IQK_DELAY_TIME
);
1565 /* leave IQK mode */
1566 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x00000000);
1569 reg_eac
= rtl_get_bbreg(hw
, RRX_POWER_AFTER_IQK_A_2
, MASKDWORD
);
1570 reg_e94
= rtl_get_bbreg(hw
, RTX_POWER_BEFORE_IQK_A
, MASKDWORD
);
1571 reg_e9c
= rtl_get_bbreg(hw
, RTX_POWER_AFTER_IQK_A
, MASKDWORD
);
1573 if (!(reg_eac
& BIT(28)) &&
1574 (((reg_e94
& 0x03FF0000) >> 16) != 0x142) &&
1575 (((reg_e9c
& 0x03FF0000) >> 16) != 0x42))
1577 else /* if Tx not OK, ignore Rx */
1580 /* Allen 20131125 */
1581 tmp
= (reg_e9c
& 0x03FF0000) >> 16;
1582 if ((tmp
& 0x200) > 0)
1585 if (!(reg_eac
& BIT(28)) &&
1586 (((reg_e94
& 0x03FF0000) >> 16) < 0x110) &&
1587 (((reg_e94
& 0x03FF0000) >> 16) > 0xf0) &&
1590 else /* if Tx not OK, ignore Rx */
1593 u32tmp
= 0x80007C00 | (reg_e94
& 0x3FF0000) |
1594 ((reg_e9c
& 0x3FF0000) >> 16);
1595 rtl_set_bbreg(hw
, RTX_IQK
, MASKDWORD
, u32tmp
);
1598 /* modify RXIQK mode table */
1599 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x00000000);
1600 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_WE_LUT
, 0x80000, 0x1);
1601 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_RCK_OS
, RFREG_OFFSET_MASK
, 0x30000);
1602 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_TXPA_G1
, RFREG_OFFSET_MASK
, 0x0001f);
1603 /* LAN2 on, PA off for Dcut */
1604 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_TXPA_G2
, RFREG_OFFSET_MASK
, 0xf7d77);
1606 /* PA, PAD setting */
1607 rtl_set_rfreg(hw
, RF90_PATH_A
, 0xdf, RFREG_OFFSET_MASK
, 0xf80);
1608 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x55, RFREG_OFFSET_MASK
, 0x4021f);
1611 rtl_set_bbreg(hw
, RRX_IQK
, MASKDWORD
, 0x01004800);
1613 /* path-A IQK setting */
1614 rtl_set_bbreg(hw
, RTX_IQK_TONE_A
, MASKDWORD
, 0x38008c1c);
1615 rtl_set_bbreg(hw
, RRX_IQK_TONE_A
, MASKDWORD
, 0x18008c1c);
1616 rtl_set_bbreg(hw
, RTX_IQK_TONE_B
, MASKDWORD
, 0x38008c1c);
1617 rtl_set_bbreg(hw
, RRX_IQK_TONE_B
, MASKDWORD
, 0x38008c1c);
1619 rtl_set_bbreg(hw
, RTX_IQK_PI_A
, MASKDWORD
, 0x82110000);
1620 rtl_set_bbreg(hw
, RRX_IQK_PI_A
, MASKDWORD
, 0x2816001f);
1621 rtl_set_bbreg(hw
, RTX_IQK_PI_B
, MASKDWORD
, 0x82110000);
1622 rtl_set_bbreg(hw
, RRX_IQK_PI_B
, MASKDWORD
, 0x28110000);
1624 /* LO calibration setting */
1625 rtl_set_bbreg(hw
, RIQK_AGC_RSP
, MASKDWORD
, 0x0046a8d1);
1627 /* enter IQK mode */
1628 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x80800000);
1630 /* One shot, path A LOK & IQK */
1631 rtl_set_bbreg(hw
, RIQK_AGC_PTS
, MASKDWORD
, 0xf9000000);
1632 rtl_set_bbreg(hw
, RIQK_AGC_PTS
, MASKDWORD
, 0xf8000000);
1634 mdelay(IQK_DELAY_TIME
);
1636 /* leave IQK mode */
1637 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x00000000);
1640 reg_eac
= rtl_get_bbreg(hw
, RRX_POWER_AFTER_IQK_A_2
, MASKDWORD
);
1641 reg_ea4
= rtl_get_bbreg(hw
, RRX_POWER_BEFORE_IQK_A_2
, MASKDWORD
);
1643 /* leave IQK mode */
1644 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x00000000);
1645 rtl_set_rfreg(hw
, RF90_PATH_A
, 0xdf, RFREG_OFFSET_MASK
, 0x780);
1647 /* Allen 20131125 */
1648 tmp
= (reg_eac
& 0x03FF0000) >> 16;
1649 if ((tmp
& 0x200) > 0)
1651 /* if Tx is OK, check whether Rx is OK */
1652 if (!(reg_eac
& BIT(27)) &&
1653 (((reg_ea4
& 0x03FF0000) >> 16) != 0x132) &&
1654 (((reg_eac
& 0x03FF0000) >> 16) != 0x36))
1656 else if (!(reg_eac
& BIT(27)) &&
1657 (((reg_ea4
& 0x03FF0000) >> 16) < 0x110) &&
1658 (((reg_ea4
& 0x03FF0000) >> 16) > 0xf0) &&
1665 static u8
_rtl8723be_phy_path_b_iqk(struct ieee80211_hw
*hw
)
1667 u32 reg_eac
, reg_e94
, reg_e9c
, tmp
;
1670 /* leave IQK mode */
1671 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x00000000);
1672 /* switch to path B */
1673 rtl_set_bbreg(hw
, 0x948, MASKDWORD
, 0x00000280);
1675 /* enable path B PA in TXIQK mode */
1676 rtl_set_rfreg(hw
, RF90_PATH_A
, 0xed, RFREG_OFFSET_MASK
, 0x00020);
1677 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x43, RFREG_OFFSET_MASK
, 0x40fc1);
1681 rtl_set_bbreg(hw
, RTX_IQK
, MASKDWORD
, 0x01007c00);
1682 rtl_set_bbreg(hw
, RRX_IQK
, MASKDWORD
, 0x01004800);
1683 /* path-A IQK setting */
1684 rtl_set_bbreg(hw
, RTX_IQK_TONE_A
, MASKDWORD
, 0x18008c1c);
1685 rtl_set_bbreg(hw
, RRX_IQK_TONE_A
, MASKDWORD
, 0x38008c1c);
1686 rtl_set_bbreg(hw
, RTX_IQK_TONE_B
, MASKDWORD
, 0x38008c1c);
1687 rtl_set_bbreg(hw
, RRX_IQK_TONE_B
, MASKDWORD
, 0x38008c1c);
1689 rtl_set_bbreg(hw
, RTX_IQK_PI_A
, MASKDWORD
, 0x821403ea);
1690 rtl_set_bbreg(hw
, RRX_IQK_PI_A
, MASKDWORD
, 0x28110000);
1691 rtl_set_bbreg(hw
, RTX_IQK_PI_B
, MASKDWORD
, 0x82110000);
1692 rtl_set_bbreg(hw
, RRX_IQK_PI_B
, MASKDWORD
, 0x28110000);
1694 /* LO calibration setting */
1695 rtl_set_bbreg(hw
, RIQK_AGC_RSP
, MASKDWORD
, 0x00462911);
1697 /* enter IQK mode */
1698 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x80800000);
1700 /* One shot, path B LOK & IQK */
1701 rtl_set_bbreg(hw
, RIQK_AGC_PTS
, MASKDWORD
, 0xf9000000);
1702 rtl_set_bbreg(hw
, RIQK_AGC_PTS
, MASKDWORD
, 0xf8000000);
1704 mdelay(IQK_DELAY_TIME
);
1706 /* leave IQK mode */
1707 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x00000000);
1710 reg_eac
= rtl_get_bbreg(hw
, RRX_POWER_AFTER_IQK_A_2
, MASKDWORD
);
1711 reg_e94
= rtl_get_bbreg(hw
, RTX_POWER_BEFORE_IQK_A
, MASKDWORD
);
1712 reg_e9c
= rtl_get_bbreg(hw
, RTX_POWER_AFTER_IQK_A
, MASKDWORD
);
1714 if (!(reg_eac
& BIT(28)) &&
1715 (((reg_e94
& 0x03FF0000) >> 16) != 0x142) &&
1716 (((reg_e9c
& 0x03FF0000) >> 16) != 0x42))
1721 /* Allen 20131125 */
1722 tmp
= (reg_e9c
& 0x03FF0000) >> 16;
1723 if ((tmp
& 0x200) > 0)
1726 if (!(reg_eac
& BIT(28)) &&
1727 (((reg_e94
& 0x03FF0000) >> 16) < 0x110) &&
1728 (((reg_e94
& 0x03FF0000) >> 16) > 0xf0) &&
1737 /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */
1738 static u8
_rtl8723be_phy_path_b_rx_iqk(struct ieee80211_hw
*hw
)
1740 u32 reg_e94
, reg_e9c
, reg_ea4
, reg_eac
, u32tmp
, tmp
;
1743 /* leave IQK mode */
1744 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x00000000);
1745 /* switch to path B */
1746 rtl_set_bbreg(hw
, 0x948, MASKDWORD
, 0x00000280);
1748 /* 1 Get TXIMR setting */
1749 /* modify RXIQK mode table */
1750 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_WE_LUT
, RFREG_OFFSET_MASK
, 0x800a0);
1751 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_RCK_OS
, RFREG_OFFSET_MASK
, 0x30000);
1752 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_TXPA_G1
, RFREG_OFFSET_MASK
, 0x0001f);
1753 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_TXPA_G2
, RFREG_OFFSET_MASK
, 0xf7ff7);
1755 /* open PA S1 & SMIXER */
1756 rtl_set_rfreg(hw
, RF90_PATH_A
, 0xed, RFREG_OFFSET_MASK
, 0x00020);
1757 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x43, RFREG_OFFSET_MASK
, 0x60fed);
1760 rtl_set_bbreg(hw
, RTX_IQK
, MASKDWORD
, 0x01007c00);
1761 rtl_set_bbreg(hw
, RRX_IQK
, MASKDWORD
, 0x01004800);
1763 /* path-B IQK setting */
1764 rtl_set_bbreg(hw
, RTX_IQK_TONE_A
, MASKDWORD
, 0x18008c1c);
1765 rtl_set_bbreg(hw
, RRX_IQK_TONE_A
, MASKDWORD
, 0x38008c1c);
1766 rtl_set_bbreg(hw
, RTX_IQK_TONE_B
, MASKDWORD
, 0x38008c1c);
1767 rtl_set_bbreg(hw
, RRX_IQK_TONE_B
, MASKDWORD
, 0x38008c1c);
1769 rtl_set_bbreg(hw
, RTX_IQK_PI_A
, MASKDWORD
, 0x82160ff0);
1770 rtl_set_bbreg(hw
, RRX_IQK_PI_A
, MASKDWORD
, 0x28110000);
1771 rtl_set_bbreg(hw
, RTX_IQK_PI_B
, MASKDWORD
, 0x82110000);
1772 rtl_set_bbreg(hw
, RRX_IQK_PI_B
, MASKDWORD
, 0x28110000);
1774 /* LO calibration setting */
1775 rtl_set_bbreg(hw
, RIQK_AGC_RSP
, MASKDWORD
, 0x0046a911);
1776 /* enter IQK mode */
1777 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x80800000);
1779 /* One shot, path B TXIQK @ RXIQK */
1780 rtl_set_bbreg(hw
, RIQK_AGC_PTS
, MASKDWORD
, 0xf9000000);
1781 rtl_set_bbreg(hw
, RIQK_AGC_PTS
, MASKDWORD
, 0xf8000000);
1783 mdelay(IQK_DELAY_TIME
);
1785 /* leave IQK mode */
1786 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x00000000);
1788 reg_eac
= rtl_get_bbreg(hw
, RRX_POWER_AFTER_IQK_A_2
, MASKDWORD
);
1789 reg_e94
= rtl_get_bbreg(hw
, RTX_POWER_BEFORE_IQK_A
, MASKDWORD
);
1790 reg_e9c
= rtl_get_bbreg(hw
, RTX_POWER_AFTER_IQK_A
, MASKDWORD
);
1792 if (!(reg_eac
& BIT(28)) &&
1793 (((reg_e94
& 0x03FF0000) >> 16) != 0x142) &&
1794 (((reg_e9c
& 0x03FF0000) >> 16) != 0x42))
1796 else /* if Tx not OK, ignore Rx */
1799 /* Allen 20131125 */
1800 tmp
= (reg_e9c
& 0x03FF0000) >> 16;
1801 if ((tmp
& 0x200) > 0)
1804 if (!(reg_eac
& BIT(28)) &&
1805 (((reg_e94
& 0x03FF0000) >> 16) < 0x110) &&
1806 (((reg_e94
& 0x03FF0000) >> 16) > 0xf0) &&
1812 u32tmp
= 0x80007C00 | (reg_e94
& 0x3FF0000) |
1813 ((reg_e9c
& 0x3FF0000) >> 16);
1814 rtl_set_bbreg(hw
, RTX_IQK
, MASKDWORD
, u32tmp
);
1818 /* <20121009, Kordan> RF Mode = 3 */
1819 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x00000000);
1820 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_WE_LUT
, 0x80000, 0x1);
1821 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_RCK_OS
, RFREG_OFFSET_MASK
, 0x30000);
1822 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_TXPA_G1
, RFREG_OFFSET_MASK
, 0x0001f);
1823 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_TXPA_G2
, RFREG_OFFSET_MASK
, 0xf7d77);
1824 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_WE_LUT
, 0x80000, 0x0);
1826 /* open PA S1 & close SMIXER */
1827 rtl_set_rfreg(hw
, RF90_PATH_A
, 0xed, RFREG_OFFSET_MASK
, 0x00020);
1828 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x43, RFREG_OFFSET_MASK
, 0x60fbd);
1831 rtl_set_bbreg(hw
, RRX_IQK
, MASKDWORD
, 0x01004800);
1833 /* path-B IQK setting */
1834 rtl_set_bbreg(hw
, RTX_IQK_TONE_A
, MASKDWORD
, 0x38008c1c);
1835 rtl_set_bbreg(hw
, RRX_IQK_TONE_A
, MASKDWORD
, 0x18008c1c);
1836 rtl_set_bbreg(hw
, RTX_IQK_TONE_B
, MASKDWORD
, 0x38008c1c);
1837 rtl_set_bbreg(hw
, RRX_IQK_TONE_B
, MASKDWORD
, 0x38008c1c);
1839 rtl_set_bbreg(hw
, RTX_IQK_PI_A
, MASKDWORD
, 0x82110000);
1840 rtl_set_bbreg(hw
, RRX_IQK_PI_A
, MASKDWORD
, 0x2816001f);
1841 rtl_set_bbreg(hw
, RTX_IQK_PI_B
, MASKDWORD
, 0x82110000);
1842 rtl_set_bbreg(hw
, RRX_IQK_PI_B
, MASKDWORD
, 0x28110000);
1844 /* LO calibration setting */
1845 rtl_set_bbreg(hw
, RIQK_AGC_RSP
, MASKDWORD
, 0x0046a8d1);
1846 /* enter IQK mode */
1847 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x80800000);
1849 /* One shot, path B LOK & IQK */
1850 rtl_set_bbreg(hw
, RIQK_AGC_PTS
, MASKDWORD
, 0xf9000000);
1851 rtl_set_bbreg(hw
, RIQK_AGC_PTS
, MASKDWORD
, 0xf8000000);
1853 mdelay(IQK_DELAY_TIME
);
1855 /* leave IQK mode */
1856 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0x00000000);
1858 reg_eac
= rtl_get_bbreg(hw
, RRX_POWER_AFTER_IQK_A_2
, MASKDWORD
);
1859 reg_ea4
= rtl_get_bbreg(hw
, RRX_POWER_BEFORE_IQK_A_2
, MASKDWORD
);
1861 /* Allen 20131125 */
1862 tmp
= (reg_eac
& 0x03FF0000) >> 16;
1863 if ((tmp
& 0x200) > 0)
1866 /* if Tx is OK, check whether Rx is OK */
1867 if (!(reg_eac
& BIT(27)) &&
1868 (((reg_ea4
& 0x03FF0000) >> 16) != 0x132) &&
1869 (((reg_eac
& 0x03FF0000) >> 16) != 0x36))
1871 else if (!(reg_eac
& BIT(27)) &&
1872 (((reg_ea4
& 0x03FF0000) >> 16) < 0x110) &&
1873 (((reg_ea4
& 0x03FF0000) >> 16) > 0xf0) &&
1882 static void _rtl8723be_phy_path_b_fill_iqk_matrix(struct ieee80211_hw
*hw
,
1888 u32 oldval_1
, x
, tx1_a
, reg
;
1891 if (final_candidate
== 0xFF) {
1893 } else if (b_iqk_ok
) {
1894 oldval_1
= (rtl_get_bbreg(hw
, ROFDM0_XBTXIQIMBALANCE
,
1895 MASKDWORD
) >> 22) & 0x3FF;
1896 x
= result
[final_candidate
][4];
1897 if ((x
& 0x00000200) != 0)
1899 tx1_a
= (x
* oldval_1
) >> 8;
1900 rtl_set_bbreg(hw
, ROFDM0_XBTXIQIMBALANCE
, 0x3FF, tx1_a
);
1901 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
, BIT(27),
1902 ((x
* oldval_1
>> 7) & 0x1));
1903 y
= result
[final_candidate
][5];
1904 if ((y
& 0x00000200) != 0)
1906 tx1_c
= (y
* oldval_1
) >> 8;
1907 rtl_set_bbreg(hw
, ROFDM0_XDTXAFE
, 0xF0000000,
1908 ((tx1_c
& 0x3C0) >> 6));
1909 rtl_set_bbreg(hw
, ROFDM0_XBTXIQIMBALANCE
, 0x003F0000,
1911 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
, BIT(25),
1912 ((y
* oldval_1
>> 7) & 0x1));
1915 reg
= result
[final_candidate
][6];
1916 rtl_set_bbreg(hw
, ROFDM0_XBRXIQIMBALANCE
, 0x3FF, reg
);
1917 reg
= result
[final_candidate
][7] & 0x3F;
1918 rtl_set_bbreg(hw
, ROFDM0_XBRXIQIMBALANCE
, 0xFC00, reg
);
1919 reg
= (result
[final_candidate
][7] >> 6) & 0xF;
1920 /* rtl_set_bbreg(hw, 0xca0, 0xF0000000, reg); */
1924 static bool _rtl8723be_phy_simularity_compare(struct ieee80211_hw
*hw
,
1925 long result
[][8], u8 c1
, u8 c2
)
1927 u32 i
, j
, diff
, simularity_bitmap
, bound
= 0;
1929 u8 final_candidate
[2] = {0xFF, 0xFF}; /* for path A and path B */
1930 bool bresult
= true; /* is2t = true*/
1931 s32 tmp1
= 0, tmp2
= 0;
1935 simularity_bitmap
= 0;
1937 for (i
= 0; i
< bound
; i
++) {
1938 if ((i
== 1) || (i
== 3) || (i
== 5) || (i
== 7)) {
1939 if ((result
[c1
][i
] & 0x00000200) != 0)
1940 tmp1
= result
[c1
][i
] | 0xFFFFFC00;
1942 tmp1
= result
[c1
][i
];
1944 if ((result
[c2
][i
] & 0x00000200) != 0)
1945 tmp2
= result
[c2
][i
] | 0xFFFFFC00;
1947 tmp2
= result
[c2
][i
];
1949 tmp1
= result
[c1
][i
];
1950 tmp2
= result
[c2
][i
];
1953 diff
= (tmp1
> tmp2
) ? (tmp1
- tmp2
) : (tmp2
- tmp1
);
1955 if (diff
> MAX_TOLERANCE
) {
1956 if ((i
== 2 || i
== 6) && !simularity_bitmap
) {
1957 if (result
[c1
][i
] + result
[c1
][i
+ 1] == 0)
1958 final_candidate
[(i
/ 4)] = c2
;
1959 else if (result
[c2
][i
] + result
[c2
][i
+ 1] == 0)
1960 final_candidate
[(i
/ 4)] = c1
;
1962 simularity_bitmap
|= (1 << i
);
1964 simularity_bitmap
|= (1 << i
);
1968 if (simularity_bitmap
== 0) {
1969 for (i
= 0; i
< (bound
/ 4); i
++) {
1970 if (final_candidate
[i
] != 0xFF) {
1971 for (j
= i
* 4; j
< (i
+ 1) * 4 - 2; j
++)
1973 result
[final_candidate
[i
]][j
];
1979 if (!(simularity_bitmap
& 0x03)) { /* path A TX OK */
1980 for (i
= 0; i
< 2; i
++)
1981 result
[3][i
] = result
[c1
][i
];
1983 if (!(simularity_bitmap
& 0x0c)) { /* path A RX OK */
1984 for (i
= 2; i
< 4; i
++)
1985 result
[3][i
] = result
[c1
][i
];
1987 if (!(simularity_bitmap
& 0x30)) { /* path B TX OK */
1988 for (i
= 4; i
< 6; i
++)
1989 result
[3][i
] = result
[c1
][i
];
1991 if (!(simularity_bitmap
& 0xc0)) { /* path B RX OK */
1992 for (i
= 6; i
< 8; i
++)
1993 result
[3][i
] = result
[c1
][i
];
1999 static void _rtl8723be_phy_iq_calibrate(struct ieee80211_hw
*hw
,
2000 long result
[][8], u8 t
, bool is2t
)
2002 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2003 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
2005 u8 patha_ok
, pathb_ok
;
2006 u32 adda_reg
[IQK_ADDA_REG_NUM
] = {
2007 0x85c, 0xe6c, 0xe70, 0xe74,
2008 0xe78, 0xe7c, 0xe80, 0xe84,
2009 0xe88, 0xe8c, 0xed0, 0xed4,
2010 0xed8, 0xedc, 0xee0, 0xeec
2013 u32 iqk_mac_reg
[IQK_MAC_REG_NUM
] = {
2014 0x522, 0x550, 0x551, 0x040
2016 u32 iqk_bb_reg
[IQK_BB_REG_NUM
] = {
2017 ROFDM0_TRXPATHENABLE
, ROFDM0_TRMUXPAR
,
2018 RFPGA0_XCD_RFINTERFACESW
, 0xb68, 0xb6c,
2022 const u32 retrycount
= 2;
2024 u32 path_sel_bb
;/* path_sel_rf */
2026 u8 tmp_reg_c50
, tmp_reg_c58
;
2028 tmp_reg_c50
= rtl_get_bbreg(hw
, 0xc50, MASKBYTE0
);
2029 tmp_reg_c58
= rtl_get_bbreg(hw
, 0xc58, MASKBYTE0
);
2032 rtl8723_save_adda_registers(hw
, adda_reg
,
2033 rtlphy
->adda_backup
, 16);
2034 rtl8723_phy_save_mac_registers(hw
, iqk_mac_reg
,
2035 rtlphy
->iqk_mac_backup
);
2036 rtl8723_save_adda_registers(hw
, iqk_bb_reg
,
2037 rtlphy
->iqk_bb_backup
,
2040 rtl8723_phy_path_adda_on(hw
, adda_reg
, true, is2t
);
2042 rtlphy
->rfpi_enable
= (u8
)rtl_get_bbreg(hw
,
2043 RFPGA0_XA_HSSIPARAMETER1
,
2047 path_sel_bb
= rtl_get_bbreg(hw
, 0x948, MASKDWORD
);
2049 rtl8723_phy_mac_setting_calibration(hw
, iqk_mac_reg
,
2050 rtlphy
->iqk_mac_backup
);
2052 rtl_set_bbreg(hw
, 0xa04, 0x0f000000, 0xf);
2053 rtl_set_bbreg(hw
, 0xc04, MASKDWORD
, 0x03a05600);
2054 rtl_set_bbreg(hw
, 0xc08, MASKDWORD
, 0x000800e4);
2055 rtl_set_bbreg(hw
, 0x874, MASKDWORD
, 0x22204000);
2058 for (i
= 0; i
< retrycount
; i
++) {
2059 patha_ok
= _rtl8723be_phy_path_a_iqk(hw
);
2060 if (patha_ok
== 0x01) {
2061 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2062 "Path A Tx IQK Success!!\n");
2063 result
[t
][0] = (rtl_get_bbreg(hw
, 0xe94, MASKDWORD
) &
2065 result
[t
][1] = (rtl_get_bbreg(hw
, 0xe9c, MASKDWORD
) &
2069 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2070 "Path A Tx IQK Fail!!\n");
2074 for (i
= 0; i
< retrycount
; i
++) {
2075 patha_ok
= _rtl8723be_phy_path_a_rx_iqk(hw
);
2076 if (patha_ok
== 0x03) {
2077 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2078 "Path A Rx IQK Success!!\n");
2079 result
[t
][2] = (rtl_get_bbreg(hw
, 0xea4, MASKDWORD
) &
2081 result
[t
][3] = (rtl_get_bbreg(hw
, 0xeac, MASKDWORD
) &
2085 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2086 "Path A Rx IQK Fail!!\n");
2089 if (0x00 == patha_ok
)
2090 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Path A IQK Fail!!\n");
2094 for (i
= 0; i
< retrycount
; i
++) {
2095 pathb_ok
= _rtl8723be_phy_path_b_iqk(hw
);
2096 if (pathb_ok
== 0x01) {
2097 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2098 "Path B Tx IQK Success!!\n");
2099 result
[t
][4] = (rtl_get_bbreg(hw
, 0xe94,
2102 result
[t
][5] = (rtl_get_bbreg(hw
, 0xe9c,
2107 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2108 "Path B Tx IQK Fail!!\n");
2111 for (i
= 0; i
< retrycount
; i
++) {
2112 pathb_ok
= _rtl8723be_phy_path_b_rx_iqk(hw
);
2113 if (pathb_ok
== 0x03) {
2114 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2115 "Path B Rx IQK Success!!\n");
2116 result
[t
][6] = (rtl_get_bbreg(hw
, 0xea4,
2119 result
[t
][7] = (rtl_get_bbreg(hw
, 0xeac,
2124 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2125 "Path B Rx IQK Fail!!\n");
2129 /* Back to BB mode, load original value */
2130 rtl_set_bbreg(hw
, RFPGA0_IQK
, MASKDWORD
, 0);
2133 rtl8723_phy_reload_adda_registers(hw
, adda_reg
,
2134 rtlphy
->adda_backup
, 16);
2135 rtl8723_phy_reload_mac_registers(hw
, iqk_mac_reg
,
2136 rtlphy
->iqk_mac_backup
);
2137 rtl8723_phy_reload_adda_registers(hw
, iqk_bb_reg
,
2138 rtlphy
->iqk_bb_backup
,
2141 rtl_set_bbreg(hw
, 0x948, MASKDWORD
, path_sel_bb
);
2142 /*rtl_set_rfreg(hw, RF90_PATH_B, 0xb0, 0xfffff, path_sel_rf);*/
2144 rtl_set_bbreg(hw
, 0xc50, MASKBYTE0
, 0x50);
2145 rtl_set_bbreg(hw
, 0xc50, MASKBYTE0
, tmp_reg_c50
);
2147 rtl_set_bbreg(hw
, 0xc58, MASKBYTE0
, 0x50);
2148 rtl_set_bbreg(hw
, 0xc58, MASKBYTE0
, tmp_reg_c58
);
2150 rtl_set_bbreg(hw
, 0xe30, MASKDWORD
, 0x01008c00);
2151 rtl_set_bbreg(hw
, 0xe34, MASKDWORD
, 0x01008c00);
2153 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "8723be IQK Finish!!\n");
2156 static u8
_get_right_chnl_place_for_iqk(u8 chnl
)
2158 u8 channel_all
[TARGET_CHNL_NUM_2G_5G
] = {
2159 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
2160 13, 14, 36, 38, 40, 42, 44, 46,
2161 48, 50, 52, 54, 56, 58, 60, 62, 64,
2162 100, 102, 104, 106, 108, 110,
2163 112, 114, 116, 118, 120, 122,
2164 124, 126, 128, 130, 132, 134, 136,
2165 138, 140, 149, 151, 153, 155, 157,
2166 159, 161, 163, 165};
2170 for (place
= 14; place
< sizeof(channel_all
); place
++) {
2171 if (channel_all
[place
] == chnl
)
2178 static void _rtl8723be_phy_lc_calibrate(struct ieee80211_hw
*hw
, bool is2t
)
2181 u32 rf_a_mode
= 0, rf_b_mode
= 0, lc_cal
;
2182 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2184 tmpreg
= rtl_read_byte(rtlpriv
, 0xd03);
2186 if ((tmpreg
& 0x70) != 0)
2187 rtl_write_byte(rtlpriv
, 0xd03, tmpreg
& 0x8F);
2189 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0xFF);
2191 if ((tmpreg
& 0x70) != 0) {
2192 rf_a_mode
= rtl_get_rfreg(hw
, RF90_PATH_A
, 0x00, MASK12BITS
);
2195 rf_b_mode
= rtl_get_rfreg(hw
, RF90_PATH_B
, 0x00,
2198 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x00, MASK12BITS
,
2199 (rf_a_mode
& 0x8FFFF) | 0x10000);
2202 rtl_set_rfreg(hw
, RF90_PATH_B
, 0x00, MASK12BITS
,
2203 (rf_b_mode
& 0x8FFFF) | 0x10000);
2205 lc_cal
= rtl_get_rfreg(hw
, RF90_PATH_A
, 0x18, MASK12BITS
);
2207 rtl_set_rfreg(hw
, RF90_PATH_A
, 0xb0, RFREG_OFFSET_MASK
, 0xdfbe0);
2208 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x18, MASK12BITS
, 0x8c0a);
2210 /* In order not to disturb BT music when wifi init.(1ant NIC only) */
2212 /* In order not to disturb BT music when wifi init.(1ant NIC only) */
2215 rtl_set_rfreg(hw
, RF90_PATH_A
, 0xb0, RFREG_OFFSET_MASK
, 0xdffe0);
2217 if ((tmpreg
& 0x70) != 0) {
2218 rtl_write_byte(rtlpriv
, 0xd03, tmpreg
);
2219 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x00, MASK12BITS
, rf_a_mode
);
2222 rtl_set_rfreg(hw
, RF90_PATH_B
, 0x00,
2223 MASK12BITS
, rf_b_mode
);
2225 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0x00);
2227 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "\n");
2230 static void _rtl8723be_phy_set_rfpath_switch(struct ieee80211_hw
*hw
,
2231 bool bmain
, bool is2t
)
2233 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2234 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "\n");
2236 if (bmain
) /* left antenna */
2237 rtl_set_bbreg(hw
, 0x92C, MASKDWORD
, 0x1);
2239 rtl_set_bbreg(hw
, 0x92C, MASKDWORD
, 0x2);
2242 #undef IQK_ADDA_REG_NUM
2243 #undef IQK_DELAY_TIME
2244 /* IQK is merge from Merge Temp */
2245 void rtl8723be_phy_iq_calibrate(struct ieee80211_hw
*hw
, bool b_recovery
)
2247 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2248 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
2250 u8 i
, final_candidate
, idx
;
2251 bool b_patha_ok
, b_pathb_ok
;
2252 long reg_e94
, reg_e9c
, reg_ea4
, reg_eb4
, reg_ebc
, reg_ec4
;
2254 bool is12simular
, is13simular
, is23simular
;
2255 u32 iqk_bb_reg
[9] = {
2256 ROFDM0_XARXIQIMBALANCE
,
2257 ROFDM0_XBRXIQIMBALANCE
,
2258 ROFDM0_ECCATHRESHOLD
,
2259 ROFDM0_AGCRSSITABLE
,
2260 ROFDM0_XATXIQIMBALANCE
,
2261 ROFDM0_XBTXIQIMBALANCE
,
2266 u32 path_sel_bb
= 0; /* path_sel_rf = 0 */
2268 if (rtlphy
->lck_inprogress
)
2271 spin_lock(&rtlpriv
->locks
.iqk_lock
);
2272 rtlphy
->lck_inprogress
= true;
2273 spin_unlock(&rtlpriv
->locks
.iqk_lock
);
2276 rtl8723_phy_reload_adda_registers(hw
, iqk_bb_reg
,
2277 rtlphy
->iqk_bb_backup
, 9);
2281 path_sel_bb
= rtl_get_bbreg(hw
, 0x948, MASKDWORD
);
2282 /* path_sel_rf = rtl_get_rfreg(hw, RF90_PATH_A, 0xb0, 0xfffff); */
2284 for (i
= 0; i
< 8; i
++) {
2290 final_candidate
= 0xff;
2293 is12simular
= false;
2294 is23simular
= false;
2295 is13simular
= false;
2296 for (i
= 0; i
< 3; i
++) {
2297 _rtl8723be_phy_iq_calibrate(hw
, result
, i
, true);
2299 is12simular
= _rtl8723be_phy_simularity_compare(hw
,
2303 final_candidate
= 0;
2308 is13simular
= _rtl8723be_phy_simularity_compare(hw
,
2312 final_candidate
= 0;
2315 is23simular
= _rtl8723be_phy_simularity_compare(hw
,
2319 final_candidate
= 1;
2321 for (i
= 0; i
< 8; i
++)
2322 reg_tmp
+= result
[3][i
];
2325 final_candidate
= 3;
2327 final_candidate
= 0xFF;
2331 for (i
= 0; i
< 4; i
++) {
2332 reg_e94
= result
[i
][0];
2333 reg_e9c
= result
[i
][1];
2334 reg_ea4
= result
[i
][2];
2335 reg_eb4
= result
[i
][4];
2336 reg_ebc
= result
[i
][5];
2337 reg_ec4
= result
[i
][6];
2339 if (final_candidate
!= 0xff) {
2340 reg_e94
= result
[final_candidate
][0];
2341 rtlphy
->reg_e94
= reg_e94
;
2342 reg_e9c
= result
[final_candidate
][1];
2343 rtlphy
->reg_e9c
= reg_e9c
;
2344 reg_ea4
= result
[final_candidate
][2];
2345 reg_eb4
= result
[final_candidate
][4];
2346 rtlphy
->reg_eb4
= reg_eb4
;
2347 reg_ebc
= result
[final_candidate
][5];
2348 rtlphy
->reg_ebc
= reg_ebc
;
2349 reg_ec4
= result
[final_candidate
][6];
2353 rtlphy
->reg_e94
= 0x100;
2354 rtlphy
->reg_eb4
= 0x100;
2355 rtlphy
->reg_e9c
= 0x0;
2356 rtlphy
->reg_ebc
= 0x0;
2359 rtl8723_phy_path_a_fill_iqk_matrix(hw
, b_patha_ok
, result
,
2363 _rtl8723be_phy_path_b_fill_iqk_matrix(hw
, b_pathb_ok
, result
,
2367 idx
= _get_right_chnl_place_for_iqk(rtlphy
->current_channel
);
2369 if (final_candidate
< 4) {
2370 for (i
= 0; i
< IQK_MATRIX_REG_NUM
; i
++)
2371 rtlphy
->iqk_matrix
[idx
].value
[0][i
] =
2372 result
[final_candidate
][i
];
2373 rtlphy
->iqk_matrix
[idx
].iqk_done
= true;
2376 rtl8723_save_adda_registers(hw
, iqk_bb_reg
,
2377 rtlphy
->iqk_bb_backup
, 9);
2379 rtl_set_bbreg(hw
, 0x948, MASKDWORD
, path_sel_bb
);
2380 /* rtl_set_rfreg(hw, RF90_PATH_A, 0xb0, 0xfffff, path_sel_rf); */
2383 spin_lock(&rtlpriv
->locks
.iqk_lock
);
2384 rtlphy
->lck_inprogress
= false;
2385 spin_unlock(&rtlpriv
->locks
.iqk_lock
);
2388 void rtl8723be_phy_lc_calibrate(struct ieee80211_hw
*hw
)
2390 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2391 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
2392 struct rtl_hal
*rtlhal
= &rtlpriv
->rtlhal
;
2393 u32 timeout
= 2000, timecount
= 0;
2395 while (rtlpriv
->mac80211
.act_scanning
&& timecount
< timeout
) {
2400 rtlphy
->lck_inprogress
= true;
2401 RTPRINT(rtlpriv
, FINIT
, INIT_IQK
,
2402 "LCK:Start!!! currentband %x delay %d ms\n",
2403 rtlhal
->current_bandtype
, timecount
);
2405 _rtl8723be_phy_lc_calibrate(hw
, false);
2407 rtlphy
->lck_inprogress
= false;
2410 void rtl8723be_phy_set_rfpath_switch(struct ieee80211_hw
*hw
, bool bmain
)
2412 _rtl8723be_phy_set_rfpath_switch(hw
, bmain
, true);
2415 bool rtl8723be_phy_set_io_cmd(struct ieee80211_hw
*hw
, enum io_type iotype
)
2417 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2418 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
2419 bool b_postprocessing
= false;
2421 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
,
2422 "-->IO Cmd(%#x), set_io_inprogress(%d)\n",
2423 iotype
, rtlphy
->set_io_inprogress
);
2426 case IO_CMD_RESUME_DM_BY_SCAN
:
2427 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
,
2428 "[IO CMD] Resume DM after scan.\n");
2429 b_postprocessing
= true;
2431 case IO_CMD_PAUSE_BAND0_DM_BY_SCAN
:
2432 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
,
2433 "[IO CMD] Pause DM before scan.\n");
2434 b_postprocessing
= true;
2437 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
2438 "switch case %#x not processed\n", iotype
);
2442 if (b_postprocessing
&& !rtlphy
->set_io_inprogress
) {
2443 rtlphy
->set_io_inprogress
= true;
2444 rtlphy
->current_io_type
= iotype
;
2448 rtl8723be_phy_set_io(hw
);
2449 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
, "IO Type(%#x)\n", iotype
);
2453 static void rtl8723be_phy_set_io(struct ieee80211_hw
*hw
)
2455 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2456 struct dig_t
*dm_digtable
= &rtlpriv
->dm_digtable
;
2457 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
2459 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
,
2460 "--->Cmd(%#x), set_io_inprogress(%d)\n",
2461 rtlphy
->current_io_type
, rtlphy
->set_io_inprogress
);
2462 switch (rtlphy
->current_io_type
) {
2463 case IO_CMD_RESUME_DM_BY_SCAN
:
2464 dm_digtable
->cur_igvalue
= rtlphy
->initgain_backup
.xaagccore1
;
2465 /*rtl92c_dm_write_dig(hw);*/
2466 rtl8723be_phy_set_txpower_level(hw
, rtlphy
->current_channel
);
2467 rtl_set_bbreg(hw
, RCCK0_CCA
, 0xff0000, 0x83);
2469 case IO_CMD_PAUSE_BAND0_DM_BY_SCAN
:
2470 rtlphy
->initgain_backup
.xaagccore1
= dm_digtable
->cur_igvalue
;
2471 dm_digtable
->cur_igvalue
= 0x17;
2472 rtl_set_bbreg(hw
, RCCK0_CCA
, 0xff0000, 0x40);
2475 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
2476 "switch case %#x not processed\n",
2477 rtlphy
->current_io_type
);
2480 rtlphy
->set_io_inprogress
= false;
2481 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_TRACE
,
2482 "(%#x)\n", rtlphy
->current_io_type
);
2485 static void rtl8723be_phy_set_rf_on(struct ieee80211_hw
*hw
)
2487 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2489 rtl_write_byte(rtlpriv
, REG_SPS0_CTRL
, 0x2b);
2490 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE3);
2491 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE2);
2492 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE3);
2493 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0x00);
2496 static void _rtl8723be_phy_set_rf_sleep(struct ieee80211_hw
*hw
)
2498 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2500 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0xFF);
2501 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x00, RFREG_OFFSET_MASK
, 0x00);
2502 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE2);
2503 rtl_write_byte(rtlpriv
, REG_SPS0_CTRL
, 0x22);
2506 static bool _rtl8723be_phy_set_rf_power_state(struct ieee80211_hw
*hw
,
2507 enum rf_pwrstate rfpwr_state
)
2509 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2510 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
2511 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2512 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
2513 bool bresult
= true;
2515 struct rtl8192_tx_ring
*ring
= NULL
;
2517 switch (rfpwr_state
) {
2519 if ((ppsc
->rfpwr_state
== ERFOFF
) &&
2520 RT_IN_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
)) {
2522 u32 initializecount
= 0;
2525 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
2526 "IPS Set eRf nic enable\n");
2527 rtstatus
= rtl_ps_enable_nic(hw
);
2528 } while (!rtstatus
&& (initializecount
< 10));
2529 RT_CLEAR_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
2531 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
2532 "Set ERFON sleeped:%d ms\n",
2533 jiffies_to_msecs(jiffies
-
2534 ppsc
->last_sleep_jiffies
));
2535 ppsc
->last_awake_jiffies
= jiffies
;
2536 rtl8723be_phy_set_rf_on(hw
);
2538 if (mac
->link_state
== MAC80211_LINKED
)
2539 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_LINK
);
2541 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_NO_LINK
);
2546 for (queue_id
= 0, i
= 0;
2547 queue_id
< RTL_PCI_MAX_TX_QUEUE_COUNT
;) {
2548 ring
= &pcipriv
->dev
.tx_ring
[queue_id
];
2549 /* Don't check BEACON Q.
2550 * BEACON Q is always not empty,
2551 * because '_rtl8723be_cmd_send_packet'
2553 if (queue_id
== BEACON_QUEUE
||
2554 skb_queue_len(&ring
->queue
) == 0) {
2558 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
2559 "eRf Off/Sleep: %d times TcbBusyQueue[%d] =%d before doze!\n",
2561 skb_queue_len(&ring
->queue
));
2566 if (i
>= MAX_DOZE_WAITING_TIMES_9x
) {
2567 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
2568 "ERFSLEEP: %d times TcbBusyQueue[%d] = %d !\n",
2569 MAX_DOZE_WAITING_TIMES_9x
,
2571 skb_queue_len(&ring
->queue
));
2576 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_HALT_NIC
) {
2577 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
2578 "IPS Set eRf nic disable\n");
2579 rtl_ps_disable_nic(hw
);
2580 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
2582 if (ppsc
->rfoff_reason
== RF_CHANGE_BY_IPS
) {
2583 rtlpriv
->cfg
->ops
->led_control(hw
,
2586 rtlpriv
->cfg
->ops
->led_control(hw
,
2593 if (ppsc
->rfpwr_state
== ERFOFF
)
2595 for (queue_id
= 0, i
= 0;
2596 queue_id
< RTL_PCI_MAX_TX_QUEUE_COUNT
;) {
2597 ring
= &pcipriv
->dev
.tx_ring
[queue_id
];
2598 if (skb_queue_len(&ring
->queue
) == 0) {
2602 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
2603 "eRf Off/Sleep: %d times TcbBusyQueue[%d] =%d before doze!\n",
2605 skb_queue_len(&ring
->queue
));
2610 if (i
>= MAX_DOZE_WAITING_TIMES_9x
) {
2611 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
2612 "ERFSLEEP: %d times TcbBusyQueue[%d] = %d !\n",
2613 MAX_DOZE_WAITING_TIMES_9x
,
2615 skb_queue_len(&ring
->queue
));
2619 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
2620 "Set ERFSLEEP awaked:%d ms\n",
2621 jiffies_to_msecs(jiffies
-
2622 ppsc
->last_awake_jiffies
));
2623 ppsc
->last_sleep_jiffies
= jiffies
;
2624 _rtl8723be_phy_set_rf_sleep(hw
);
2628 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
2629 "switch case %#x not processed\n", rfpwr_state
);
2634 ppsc
->rfpwr_state
= rfpwr_state
;
2638 bool rtl8723be_phy_set_rf_power_state(struct ieee80211_hw
*hw
,
2639 enum rf_pwrstate rfpwr_state
)
2641 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
2643 bool bresult
= false;
2645 if (rfpwr_state
== ppsc
->rfpwr_state
)
2647 bresult
= _rtl8723be_phy_set_rf_power_state(hw
, rfpwr_state
);