1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2010 Realtek Corporation.*/
14 #include "../btcoexist/halbt_precomp.h"
18 #define READ_NEXT_PAIR(array_table, v1, v2, i) \
21 v1 = array_table[i]; \
22 v2 = array_table[i+1]; \
25 static u32
_rtl8821ae_phy_rf_serial_read(struct ieee80211_hw
*hw
,
26 enum radio_path rfpath
, u32 offset
);
27 static void _rtl8821ae_phy_rf_serial_write(struct ieee80211_hw
*hw
,
28 enum radio_path rfpath
, u32 offset
,
30 static u32
_rtl8821ae_phy_calculate_bit_shift(u32 bitmask
)
34 return i
? i
- 1 : 32;
36 static bool _rtl8821ae_phy_bb8821a_config_parafile(struct ieee80211_hw
*hw
);
37 /*static bool _rtl8812ae_phy_config_mac_with_headerfile(struct ieee80211_hw *hw);*/
38 static bool _rtl8821ae_phy_config_mac_with_headerfile(struct ieee80211_hw
*hw
);
39 static bool _rtl8821ae_phy_config_bb_with_headerfile(struct ieee80211_hw
*hw
,
41 static bool _rtl8821ae_phy_config_bb_with_pgheaderfile(struct ieee80211_hw
*hw
,
43 static void phy_init_bb_rf_register_definition(struct ieee80211_hw
*hw
);
45 static long _rtl8821ae_phy_txpwr_idx_to_dbm(struct ieee80211_hw
*hw
,
46 enum wireless_mode wirelessmode
,
48 static void rtl8821ae_phy_set_rf_on(struct ieee80211_hw
*hw
);
49 static void rtl8821ae_phy_set_io(struct ieee80211_hw
*hw
);
51 static void rtl8812ae_fixspur(struct ieee80211_hw
*hw
,
52 enum ht_channel_width band_width
, u8 channel
)
54 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
56 /*C cut Item12 ADC FIFO CLOCK*/
57 if (IS_VENDOR_8812A_C_CUT(rtlhal
->version
)) {
58 if (band_width
== HT_CHANNEL_WIDTH_20_40
&& channel
== 11)
59 rtl_set_bbreg(hw
, RRFMOD
, 0xC00, 0x3);
60 /* 0x8AC[11:10] = 2'b11*/
62 rtl_set_bbreg(hw
, RRFMOD
, 0xC00, 0x2);
63 /* 0x8AC[11:10] = 2'b10*/
65 /* <20120914, Kordan> A workaround to resolve
66 * 2480Mhz spur by setting ADC clock as 160M. (Asked by Binson)
68 if (band_width
== HT_CHANNEL_WIDTH_20
&&
69 (channel
== 13 || channel
== 14)) {
70 rtl_set_bbreg(hw
, RRFMOD
, 0x300, 0x3);
71 /*0x8AC[9:8] = 2'b11*/
72 rtl_set_bbreg(hw
, RADC_BUF_CLK
, BIT(30), 1);
74 } else if (band_width
== HT_CHANNEL_WIDTH_20_40
&&
76 rtl_set_bbreg(hw
, RADC_BUF_CLK
, BIT(30), 1);
78 } else if (band_width
!= HT_CHANNEL_WIDTH_80
) {
79 rtl_set_bbreg(hw
, RRFMOD
, 0x300, 0x2);
80 /*0x8AC[9:8] = 2'b10*/
81 rtl_set_bbreg(hw
, RADC_BUF_CLK
, BIT(30), 0);
84 } else if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
85 /* <20120914, Kordan> A workaround to resolve
86 * 2480Mhz spur by setting ADC clock as 160M.
88 if (band_width
== HT_CHANNEL_WIDTH_20
&&
89 (channel
== 13 || channel
== 14))
90 rtl_set_bbreg(hw
, RRFMOD
, 0x300, 0x3);
92 else if (channel
<= 14) /*2.4G only*/
93 rtl_set_bbreg(hw
, RRFMOD
, 0x300, 0x2);
98 u32
rtl8821ae_phy_query_bb_reg(struct ieee80211_hw
*hw
, u32 regaddr
,
101 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
102 u32 returnvalue
, originalvalue
, bitshift
;
104 rtl_dbg(rtlpriv
, COMP_RF
, DBG_TRACE
,
105 "regaddr(%#x), bitmask(%#x)\n",
107 originalvalue
= rtl_read_dword(rtlpriv
, regaddr
);
108 bitshift
= _rtl8821ae_phy_calculate_bit_shift(bitmask
);
109 returnvalue
= (originalvalue
& bitmask
) >> bitshift
;
111 rtl_dbg(rtlpriv
, COMP_RF
, DBG_TRACE
,
112 "BBR MASK=0x%x Addr[0x%x]=0x%x\n",
113 bitmask
, regaddr
, originalvalue
);
117 void rtl8821ae_phy_set_bb_reg(struct ieee80211_hw
*hw
,
118 u32 regaddr
, u32 bitmask
, u32 data
)
120 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
121 u32 originalvalue
, bitshift
;
123 rtl_dbg(rtlpriv
, COMP_RF
, DBG_TRACE
,
124 "regaddr(%#x), bitmask(%#x), data(%#x)\n",
125 regaddr
, bitmask
, data
);
127 if (bitmask
!= MASKDWORD
) {
128 originalvalue
= rtl_read_dword(rtlpriv
, regaddr
);
129 bitshift
= _rtl8821ae_phy_calculate_bit_shift(bitmask
);
130 data
= ((originalvalue
& (~bitmask
)) |
131 ((data
<< bitshift
) & bitmask
));
134 rtl_write_dword(rtlpriv
, regaddr
, data
);
136 rtl_dbg(rtlpriv
, COMP_RF
, DBG_TRACE
,
137 "regaddr(%#x), bitmask(%#x), data(%#x)\n",
138 regaddr
, bitmask
, data
);
141 u32
rtl8821ae_phy_query_rf_reg(struct ieee80211_hw
*hw
,
142 enum radio_path rfpath
, u32 regaddr
,
145 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
146 u32 original_value
, readback_value
, bitshift
;
148 rtl_dbg(rtlpriv
, COMP_RF
, DBG_TRACE
,
149 "regaddr(%#x), rfpath(%#x), bitmask(%#x)\n",
150 regaddr
, rfpath
, bitmask
);
152 spin_lock(&rtlpriv
->locks
.rf_lock
);
154 original_value
= _rtl8821ae_phy_rf_serial_read(hw
, rfpath
, regaddr
);
155 bitshift
= _rtl8821ae_phy_calculate_bit_shift(bitmask
);
156 readback_value
= (original_value
& bitmask
) >> bitshift
;
158 spin_unlock(&rtlpriv
->locks
.rf_lock
);
160 rtl_dbg(rtlpriv
, COMP_RF
, DBG_TRACE
,
161 "regaddr(%#x), rfpath(%#x), bitmask(%#x), original_value(%#x)\n",
162 regaddr
, rfpath
, bitmask
, original_value
);
164 return readback_value
;
167 void rtl8821ae_phy_set_rf_reg(struct ieee80211_hw
*hw
,
168 enum radio_path rfpath
,
169 u32 regaddr
, u32 bitmask
, u32 data
)
171 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
172 u32 original_value
, bitshift
;
174 rtl_dbg(rtlpriv
, COMP_RF
, DBG_TRACE
,
175 "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
176 regaddr
, bitmask
, data
, rfpath
);
178 spin_lock(&rtlpriv
->locks
.rf_lock
);
180 if (bitmask
!= RFREG_OFFSET_MASK
) {
182 _rtl8821ae_phy_rf_serial_read(hw
, rfpath
, regaddr
);
183 bitshift
= _rtl8821ae_phy_calculate_bit_shift(bitmask
);
184 data
= ((original_value
& (~bitmask
)) | (data
<< bitshift
));
187 _rtl8821ae_phy_rf_serial_write(hw
, rfpath
, regaddr
, data
);
189 spin_unlock(&rtlpriv
->locks
.rf_lock
);
191 rtl_dbg(rtlpriv
, COMP_RF
, DBG_TRACE
,
192 "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
193 regaddr
, bitmask
, data
, rfpath
);
196 static u32
_rtl8821ae_phy_rf_serial_read(struct ieee80211_hw
*hw
,
197 enum radio_path rfpath
, u32 offset
)
199 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
200 bool is_pi_mode
= false;
203 /* 2009/06/17 MH We can not execute IO for power
204 save or other accident mode.*/
205 if (RT_CANNOT_IO(hw
)) {
206 pr_err("return all one\n");
209 /* <20120809, Kordan> CCA OFF(when entering),
210 asked by James to avoid reading the wrong value.
211 <20120828, Kordan> Toggling CCA would affect RF 0x0, skip it!*/
213 !((rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) ||
214 (IS_VENDOR_8812A_C_CUT(rtlhal
->version
))))
215 rtl_set_bbreg(hw
, RCCAONSEC
, 0x8, 1);
218 if (rfpath
== RF90_PATH_A
)
219 is_pi_mode
= (bool)rtl_get_bbreg(hw
, 0xC00, 0x4);
220 else if (rfpath
== RF90_PATH_B
)
221 is_pi_mode
= (bool)rtl_get_bbreg(hw
, 0xE00, 0x4);
223 rtl_set_bbreg(hw
, RHSSIREAD_8821AE
, 0xff, offset
);
225 if ((rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) ||
226 (IS_VENDOR_8812A_C_CUT(rtlhal
->version
)))
230 if (rfpath
== RF90_PATH_A
)
232 rtl_get_bbreg(hw
, RA_PIREAD_8821A
, BLSSIREADBACKDATA
);
233 else if (rfpath
== RF90_PATH_B
)
235 rtl_get_bbreg(hw
, RB_PIREAD_8821A
, BLSSIREADBACKDATA
);
237 if (rfpath
== RF90_PATH_A
)
239 rtl_get_bbreg(hw
, RA_SIREAD_8821A
, BLSSIREADBACKDATA
);
240 else if (rfpath
== RF90_PATH_B
)
242 rtl_get_bbreg(hw
, RB_SIREAD_8821A
, BLSSIREADBACKDATA
);
245 /*<20120809, Kordan> CCA ON(when exiting),
246 * asked by James to avoid reading the wrong value.
247 * <20120828, Kordan> Toggling CCA would affect RF 0x0, skip it!
250 !((rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) ||
251 (IS_VENDOR_8812A_C_CUT(rtlhal
->version
))))
252 rtl_set_bbreg(hw
, RCCAONSEC
, 0x8, 0);
256 static void _rtl8821ae_phy_rf_serial_write(struct ieee80211_hw
*hw
,
257 enum radio_path rfpath
, u32 offset
,
260 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
261 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
262 struct bb_reg_def
*pphyreg
= &rtlphy
->phyreg_def
[rfpath
];
266 if (RT_CANNOT_IO(hw
)) {
272 data_and_addr
= ((newoffset
<< 20) |
273 (data
& 0x000fffff)) & 0x0fffffff;
274 rtl_set_bbreg(hw
, pphyreg
->rf3wire_offset
, MASKDWORD
, data_and_addr
);
275 rtl_dbg(rtlpriv
, COMP_RF
, DBG_TRACE
,
276 "RFW-%d Addr[0x%x]=0x%x\n",
277 rfpath
, pphyreg
->rf3wire_offset
, data_and_addr
);
280 bool rtl8821ae_phy_mac_config(struct ieee80211_hw
*hw
)
284 rtstatus
= _rtl8821ae_phy_config_mac_with_headerfile(hw
);
289 bool rtl8821ae_phy_bb_config(struct ieee80211_hw
*hw
)
291 bool rtstatus
= true;
292 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
293 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
294 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
295 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
299 phy_init_bb_rf_register_definition(hw
);
301 regval
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
);
303 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, regval
);
304 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
,
305 regval
| FEN_BB_GLB_RSTN
| FEN_BBRSTB
);
307 rtl_write_byte(rtlpriv
, REG_RF_CTRL
, 0x7);
308 rtl_write_byte(rtlpriv
, REG_OPT_CTRL
+ 2, 0x7);
310 rtstatus
= _rtl8821ae_phy_bb8821a_config_parafile(hw
);
312 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
313 crystal_cap
= rtlefuse
->crystalcap
& 0x3F;
314 rtl_set_bbreg(hw
, REG_MAC_PHY_CTRL
, 0x7FF80000,
315 (crystal_cap
| (crystal_cap
<< 6)));
317 crystal_cap
= rtlefuse
->crystalcap
& 0x3F;
318 rtl_set_bbreg(hw
, REG_MAC_PHY_CTRL
, 0xFFF000,
319 (crystal_cap
| (crystal_cap
<< 6)));
321 rtlphy
->reg_837
= rtl_read_byte(rtlpriv
, 0x837);
326 bool rtl8821ae_phy_rf_config(struct ieee80211_hw
*hw
)
328 return rtl8821ae_phy_rf6052_config(hw
);
331 static void _rtl8812ae_phy_set_rfe_reg_24g(struct ieee80211_hw
*hw
)
333 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
334 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
337 switch (rtlhal
->rfe_type
) {
339 rtl_set_bbreg(hw
, RA_RFE_PINMUX
, BMASKDWORD
, 0x54337770);
340 rtl_set_bbreg(hw
, RB_RFE_PINMUX
, BMASKDWORD
, 0x54337770);
341 rtl_set_bbreg(hw
, RA_RFE_INV
, BMASKRFEINV
, 0x010);
342 rtl_set_bbreg(hw
, RB_RFE_INV
, BMASKRFEINV
, 0x010);
343 rtl_set_bbreg(hw
, 0x900, 0x00000303, 0x1);
346 rtl_set_bbreg(hw
, RA_RFE_PINMUX
, BMASKDWORD
, 0x77777777);
347 rtl_set_bbreg(hw
, RB_RFE_PINMUX
, BMASKDWORD
, 0x77777777);
348 rtl_set_bbreg(hw
, RA_RFE_INV
, BMASKRFEINV
, 0x001);
349 rtl_set_bbreg(hw
, RB_RFE_INV
, BMASKRFEINV
, 0x001);
352 rtl_write_byte(rtlpriv
, RA_RFE_PINMUX
+ 2, 0x77);
353 rtl_set_bbreg(hw
, RB_RFE_PINMUX
, BMASKDWORD
, 0x77777777);
354 tmp
= rtl_read_byte(rtlpriv
, RA_RFE_INV
+ 3);
355 rtl_write_byte(rtlpriv
, RA_RFE_INV
+ 3, tmp
& ~0x1);
356 rtl_set_bbreg(hw
, RB_RFE_INV
, BMASKRFEINV
, 0x000);
359 if (rtlpriv
->btcoexist
.bt_coexistence
) {
360 rtl_set_bbreg(hw
, RA_RFE_PINMUX
, 0xffffff, 0x777777);
361 rtl_set_bbreg(hw
, RB_RFE_PINMUX
, BMASKDWORD
,
363 rtl_set_bbreg(hw
, RA_RFE_INV
, 0x33f00000, 0x000);
364 rtl_set_bbreg(hw
, RB_RFE_INV
, BMASKRFEINV
, 0x000);
371 rtl_set_bbreg(hw
, RA_RFE_PINMUX
, BMASKDWORD
, 0x77777777);
372 rtl_set_bbreg(hw
, RB_RFE_PINMUX
, BMASKDWORD
, 0x77777777);
373 rtl_set_bbreg(hw
, RA_RFE_INV
, BMASKRFEINV
, 0x000);
374 rtl_set_bbreg(hw
, RB_RFE_INV
, BMASKRFEINV
, 0x000);
379 static void _rtl8812ae_phy_set_rfe_reg_5g(struct ieee80211_hw
*hw
)
381 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
382 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
385 switch (rtlhal
->rfe_type
) {
387 rtl_set_bbreg(hw
, RA_RFE_PINMUX
, BMASKDWORD
, 0x77337717);
388 rtl_set_bbreg(hw
, RB_RFE_PINMUX
, BMASKDWORD
, 0x77337717);
389 rtl_set_bbreg(hw
, RA_RFE_INV
, BMASKRFEINV
, 0x010);
390 rtl_set_bbreg(hw
, RB_RFE_INV
, BMASKRFEINV
, 0x010);
393 if (rtlpriv
->btcoexist
.bt_coexistence
) {
394 rtl_set_bbreg(hw
, RA_RFE_PINMUX
, 0xffffff, 0x337717);
395 rtl_set_bbreg(hw
, RB_RFE_PINMUX
, BMASKDWORD
,
397 rtl_set_bbreg(hw
, RA_RFE_INV
, 0x33f00000, 0x000);
398 rtl_set_bbreg(hw
, RB_RFE_INV
, BMASKRFEINV
, 0x000);
400 rtl_set_bbreg(hw
, RA_RFE_PINMUX
, BMASKDWORD
,
402 rtl_set_bbreg(hw
, RB_RFE_PINMUX
, BMASKDWORD
,
404 rtl_set_bbreg(hw
, RA_RFE_INV
, BMASKRFEINV
, 0x000);
405 rtl_set_bbreg(hw
, RB_RFE_INV
, BMASKRFEINV
, 0x000);
409 rtl_set_bbreg(hw
, RA_RFE_PINMUX
, BMASKDWORD
, 0x54337717);
410 rtl_set_bbreg(hw
, RB_RFE_PINMUX
, BMASKDWORD
, 0x54337717);
411 rtl_set_bbreg(hw
, RA_RFE_INV
, BMASKRFEINV
, 0x010);
412 rtl_set_bbreg(hw
, RB_RFE_INV
, BMASKRFEINV
, 0x010);
413 rtl_set_bbreg(hw
, 0x900, 0x00000303, 0x1);
416 rtl_write_byte(rtlpriv
, RA_RFE_PINMUX
+ 2, 0x33);
417 rtl_set_bbreg(hw
, RB_RFE_PINMUX
, BMASKDWORD
, 0x77337777);
418 tmp
= rtl_read_byte(rtlpriv
, RA_RFE_INV
+ 3);
419 rtl_write_byte(rtlpriv
, RA_RFE_INV
+ 3, tmp
| 0x1);
420 rtl_set_bbreg(hw
, RB_RFE_INV
, BMASKRFEINV
, 0x010);
425 rtl_set_bbreg(hw
, RA_RFE_PINMUX
, BMASKDWORD
, 0x77337777);
426 rtl_set_bbreg(hw
, RB_RFE_PINMUX
, BMASKDWORD
, 0x77337777);
427 rtl_set_bbreg(hw
, RA_RFE_INV
, BMASKRFEINV
, 0x010);
428 rtl_set_bbreg(hw
, RB_RFE_INV
, BMASKRFEINV
, 0x010);
433 u32
phy_get_tx_swing_8812A(struct ieee80211_hw
*hw
, u8 band
,
436 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
437 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
438 struct rtl_dm
*rtldm
= rtl_dm(rtlpriv
);
439 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
440 s8 reg_swing_2g
= -1;/* 0xff; */
441 s8 reg_swing_5g
= -1;/* 0xff; */
442 s8 swing_2g
= -1 * reg_swing_2g
;
443 s8 swing_5g
= -1 * reg_swing_5g
;
445 const s8 auto_temp
= -1;
447 rtl_dbg(rtlpriv
, COMP_SCAN
, DBG_LOUD
,
448 "===> PHY_GetTXBBSwing_8812A, bbSwing_2G: %d, bbSwing_5G: %d,autoload_failflag=%d.\n",
449 (int)swing_2g
, (int)swing_5g
,
450 (int)rtlefuse
->autoload_failflag
);
452 if (rtlefuse
->autoload_failflag
) {
453 if (band
== BAND_ON_2_4G
) {
454 rtldm
->swing_diff_2g
= swing_2g
;
456 out
= 0x200; /* 0 dB */
457 } else if (swing_2g
== -3) {
458 out
= 0x16A; /* -3 dB */
459 } else if (swing_2g
== -6) {
460 out
= 0x101; /* -6 dB */
461 } else if (swing_2g
== -9) {
462 out
= 0x0B6; /* -9 dB */
464 rtldm
->swing_diff_2g
= 0;
467 } else if (band
== BAND_ON_5G
) {
468 rtldm
->swing_diff_5g
= swing_5g
;
470 out
= 0x200; /* 0 dB */
471 } else if (swing_5g
== -3) {
472 out
= 0x16A; /* -3 dB */
473 } else if (swing_5g
== -6) {
474 out
= 0x101; /* -6 dB */
475 } else if (swing_5g
== -9) {
476 out
= 0x0B6; /* -9 dB */
478 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
479 rtldm
->swing_diff_5g
= -3;
482 rtldm
->swing_diff_5g
= 0;
487 rtldm
->swing_diff_2g
= -3;
488 rtldm
->swing_diff_5g
= -3;
489 out
= 0x16A; /* -3 dB */
492 u32 swing
= 0, swing_a
= 0, swing_b
= 0;
494 if (band
== BAND_ON_2_4G
) {
495 if (reg_swing_2g
== auto_temp
) {
496 efuse_shadow_read(hw
, 1, 0xC6, (u32
*)&swing
);
497 swing
= (swing
== 0xFF) ? 0x00 : swing
;
498 } else if (swing_2g
== 0) {
499 swing
= 0x00; /* 0 dB */
500 } else if (swing_2g
== -3) {
501 swing
= 0x05; /* -3 dB */
502 } else if (swing_2g
== -6) {
503 swing
= 0x0A; /* -6 dB */
504 } else if (swing_2g
== -9) {
505 swing
= 0xFF; /* -9 dB */
510 if (reg_swing_5g
== auto_temp
) {
511 efuse_shadow_read(hw
, 1, 0xC7, (u32
*)&swing
);
512 swing
= (swing
== 0xFF) ? 0x00 : swing
;
513 } else if (swing_5g
== 0) {
514 swing
= 0x00; /* 0 dB */
515 } else if (swing_5g
== -3) {
516 swing
= 0x05; /* -3 dB */
517 } else if (swing_5g
== -6) {
518 swing
= 0x0A; /* -6 dB */
519 } else if (swing_5g
== -9) {
520 swing
= 0xFF; /* -9 dB */
526 swing_a
= (swing
& 0x3) >> 0; /* 0xC6/C7[1:0] */
527 swing_b
= (swing
& 0xC) >> 2; /* 0xC6/C7[3:2] */
528 rtl_dbg(rtlpriv
, COMP_SCAN
, DBG_LOUD
,
529 "===> PHY_GetTXBBSwing_8812A, swingA: 0x%X, swingB: 0x%X\n",
533 if (swing_a
== 0x0) {
534 if (band
== BAND_ON_2_4G
)
535 rtldm
->swing_diff_2g
= 0;
537 rtldm
->swing_diff_5g
= 0;
538 out
= 0x200; /* 0 dB */
539 } else if (swing_a
== 0x1) {
540 if (band
== BAND_ON_2_4G
)
541 rtldm
->swing_diff_2g
= -3;
543 rtldm
->swing_diff_5g
= -3;
544 out
= 0x16A; /* -3 dB */
545 } else if (swing_a
== 0x2) {
546 if (band
== BAND_ON_2_4G
)
547 rtldm
->swing_diff_2g
= -6;
549 rtldm
->swing_diff_5g
= -6;
550 out
= 0x101; /* -6 dB */
551 } else if (swing_a
== 0x3) {
552 if (band
== BAND_ON_2_4G
)
553 rtldm
->swing_diff_2g
= -9;
555 rtldm
->swing_diff_5g
= -9;
556 out
= 0x0B6; /* -9 dB */
559 if (swing_b
== 0x0) {
560 if (band
== BAND_ON_2_4G
)
561 rtldm
->swing_diff_2g
= 0;
563 rtldm
->swing_diff_5g
= 0;
564 out
= 0x200; /* 0 dB */
565 } else if (swing_b
== 0x1) {
566 if (band
== BAND_ON_2_4G
)
567 rtldm
->swing_diff_2g
= -3;
569 rtldm
->swing_diff_5g
= -3;
570 out
= 0x16A; /* -3 dB */
571 } else if (swing_b
== 0x2) {
572 if (band
== BAND_ON_2_4G
)
573 rtldm
->swing_diff_2g
= -6;
575 rtldm
->swing_diff_5g
= -6;
576 out
= 0x101; /* -6 dB */
577 } else if (swing_b
== 0x3) {
578 if (band
== BAND_ON_2_4G
)
579 rtldm
->swing_diff_2g
= -9;
581 rtldm
->swing_diff_5g
= -9;
582 out
= 0x0B6; /* -9 dB */
586 rtl_dbg(rtlpriv
, COMP_SCAN
, DBG_LOUD
,
587 "<=== PHY_GetTXBBSwing_8812A, out = 0x%X\n", out
);
591 void rtl8821ae_phy_switch_wirelessband(struct ieee80211_hw
*hw
, u8 band
)
593 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
594 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
595 struct rtl_dm
*rtldm
= rtl_dm(rtlpriv
);
596 u8 current_band
= rtlhal
->current_bandtype
;
597 s8 bb_diff_between_band
;
599 rtl8821ae_phy_query_bb_reg(hw
, RTXPATH
, 0xf0);
600 rtl8821ae_phy_query_bb_reg(hw
, RCCK_RX
, 0x0f000000);
601 rtlhal
->current_bandtype
= (enum band_type
) band
;
602 /* reconfig BB/RF according to wireless mode */
603 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
605 rtl_set_bbreg(hw
, ROFDMCCKEN
, BOFDMEN
|BCCKEN
, 0x03);
607 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
608 /* 0xCB0[15:12] = 0x7 (LNA_On)*/
609 rtl_set_bbreg(hw
, RA_RFE_PINMUX
, 0xF000, 0x7);
610 /* 0xCB0[7:4] = 0x7 (PAPE_A)*/
611 rtl_set_bbreg(hw
, RA_RFE_PINMUX
, 0xF0, 0x7);
614 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
616 rtl_set_bbreg(hw
, 0x834, 0x3, 0x1);
619 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
620 /* 0xC1C[11:8] = 0 */
621 rtl_set_bbreg(hw
, RA_TXSCALE
, 0xF00, 0);
623 /* 0x82C[1:0] = 2b'00 */
624 rtl_set_bbreg(hw
, 0x82c, 0x3, 0);
627 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
)
628 _rtl8812ae_phy_set_rfe_reg_24g(hw
);
630 rtl_set_bbreg(hw
, RTXPATH
, 0xf0, 0x1);
631 rtl_set_bbreg(hw
, RCCK_RX
, 0x0f000000, 0x1);
633 rtl_write_byte(rtlpriv
, REG_CCK_CHECK
, 0x0);
634 } else {/* 5G band */
637 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
638 /*0xCB0[15:12] = 0x5 (LNA_On)*/
639 rtl_set_bbreg(hw
, RA_RFE_PINMUX
, 0xF000, 0x5);
640 /*0xCB0[7:4] = 0x4 (PAPE_A)*/
641 rtl_set_bbreg(hw
, RA_RFE_PINMUX
, 0xF0, 0x4);
644 rtl_write_byte(rtlpriv
, REG_CCK_CHECK
, 0x80);
647 reg_41a
= rtl_read_word(rtlpriv
, REG_TXPKT_EMPTY
);
648 rtl_dbg(rtlpriv
, COMP_SCAN
, DBG_LOUD
,
649 "Reg41A value %d\n", reg_41a
);
651 while ((reg_41a
!= 0x30) && (count
< 50)) {
653 rtl_dbg(rtlpriv
, COMP_SCAN
, DBG_LOUD
, "Delay 50us\n");
655 reg_41a
= rtl_read_word(rtlpriv
, REG_TXPKT_EMPTY
);
658 rtl_dbg(rtlpriv
, COMP_SCAN
, DBG_LOUD
,
659 "Reg41A value %d\n", reg_41a
);
662 rtl_dbg(rtlpriv
, COMP_MLME
, DBG_LOUD
,
663 "PHY_SwitchWirelessBand8812(): Switch to 5G Band. Count = %d reg41A=0x%x\n",
666 /* 2012/02/01, Sinda add registry to switch workaround
667 without long-run verification for scan issue. */
668 rtl_set_bbreg(hw
, ROFDMCCKEN
, BOFDMEN
|BCCKEN
, 0x03);
670 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
672 rtl_set_bbreg(hw
, 0x834, 0x3, 0x2);
675 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
676 /* AGC table select */
678 rtl_set_bbreg(hw
, RA_TXSCALE
, 0xF00, 1);
680 /* 0x82C[1:0] = 2'b00 */
681 rtl_set_bbreg(hw
, 0x82c, 0x3, 1);
683 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
)
684 _rtl8812ae_phy_set_rfe_reg_5g(hw
);
686 rtl_set_bbreg(hw
, RTXPATH
, 0xf0, 0);
687 rtl_set_bbreg(hw
, RCCK_RX
, 0x0f000000, 0xf);
689 rtl_dbg(rtlpriv
, COMP_SCAN
, DBG_LOUD
,
690 "==>PHY_SwitchWirelessBand8812() BAND_ON_5G settings OFDM index 0x%x\n",
691 rtlpriv
->dm
.ofdm_index
[RF90_PATH_A
]);
694 if ((rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) ||
695 (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
)) {
697 rtl_set_bbreg(hw
, RA_TXSCALE
, 0xFFE00000,
698 phy_get_tx_swing_8812A(hw
, band
, RF90_PATH_A
));
700 rtl_set_bbreg(hw
, RB_TXSCALE
, 0xFFE00000,
701 phy_get_tx_swing_8812A(hw
, band
, RF90_PATH_B
));
703 /* <20121005, Kordan> When TxPowerTrack is ON,
704 * we should take care of the change of BB swing.
705 * That is, reset all info to trigger Tx power tracking.
707 if (band
!= current_band
) {
708 bb_diff_between_band
=
709 (rtldm
->swing_diff_2g
- rtldm
->swing_diff_5g
);
710 bb_diff_between_band
= (band
== BAND_ON_2_4G
) ?
711 bb_diff_between_band
:
712 (-1 * bb_diff_between_band
);
713 rtldm
->default_ofdm_index
+= bb_diff_between_band
* 2;
715 rtl8821ae_dm_clear_txpower_tracking_state(hw
);
718 rtl_dbg(rtlpriv
, COMP_SCAN
, DBG_TRACE
,
719 "<==%s():Switch Band OK.\n", __func__
);
723 static bool _rtl8821ae_check_positive(struct ieee80211_hw
*hw
,
724 const u32 condition1
,
725 const u32 condition2
)
727 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
728 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
729 u32 cut_ver
= ((rtlhal
->version
& CHIP_VER_RTL_MASK
)
730 >> CHIP_VER_RTL_SHIFT
);
731 u32 intf
= (rtlhal
->interface
== INTF_USB
? BIT(1) : BIT(0));
733 u8 board_type
= ((rtlhal
->board_type
& BIT(4)) >> 4) << 0 | /* _GLNA */
734 ((rtlhal
->board_type
& BIT(3)) >> 3) << 1 | /* _GPA */
735 ((rtlhal
->board_type
& BIT(7)) >> 7) << 2 | /* _ALNA */
736 ((rtlhal
->board_type
& BIT(6)) >> 6) << 3 | /* _APA */
737 ((rtlhal
->board_type
& BIT(2)) >> 2) << 4; /* _BT */
739 u32 cond1
= condition1
, cond2
= condition2
;
740 u32 driver1
= cut_ver
<< 24 | /* CUT ver */
741 0 << 20 | /* interface 2/2 */
742 0x04 << 16 | /* platform */
743 rtlhal
->package_type
<< 12 |
744 intf
<< 8 | /* interface 1/2 */
747 u32 driver2
= rtlhal
->type_glna
<< 0 |
748 rtlhal
->type_gpa
<< 8 |
749 rtlhal
->type_alna
<< 16 |
750 rtlhal
->type_apa
<< 24;
752 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
753 "===> [8812A] CheckPositive (cond1, cond2) = (0x%X 0x%X)\n",
755 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
756 "===> [8812A] CheckPositive (driver1, driver2) = (0x%X 0x%X)\n",
759 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
760 " (Platform, Interface) = (0x%X, 0x%X)\n", 0x04, intf
);
761 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
762 " (Board, Package) = (0x%X, 0x%X)\n",
763 rtlhal
->board_type
, rtlhal
->package_type
);
765 /*============== Value Defined Check ===============*/
766 /*QFN Type [15:12] and Cut Version [27:24] need to do value check*/
768 if (((cond1
& 0x0000F000) != 0) && ((cond1
& 0x0000F000) !=
769 (driver1
& 0x0000F000)))
771 if (((cond1
& 0x0F000000) != 0) && ((cond1
& 0x0F000000) !=
772 (driver1
& 0x0F000000)))
775 /*=============== Bit Defined Check ================*/
776 /* We don't care [31:28] */
779 driver1
&= 0x00FF0FFF;
781 if ((cond1
& driver1
) == cond1
) {
784 if ((cond1
& 0x0F) == 0) /* BoardType is DONTCARE*/
787 if ((cond1
& BIT(0)) != 0) /*GLNA*/
789 if ((cond1
& BIT(1)) != 0) /*GPA*/
791 if ((cond1
& BIT(2)) != 0) /*ALNA*/
793 if ((cond1
& BIT(3)) != 0) /*APA*/
796 /* BoardType of each RF path is matched*/
797 if ((cond2
& mask
) == (driver2
& mask
))
805 static bool _rtl8821ae_check_condition(struct ieee80211_hw
*hw
,
808 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
809 u32 _board
= rtlefuse
->board_type
; /*need efuse define*/
810 u32 _interface
= 0x01; /* ODM_ITRF_PCIE */
811 u32 _platform
= 0x08;/* ODM_WIN */
812 u32 cond
= condition
;
814 if (condition
== 0xCDCDCDCD)
817 cond
= condition
& 0xFF;
818 if ((_board
!= cond
) && cond
!= 0xFF)
821 cond
= condition
& 0xFF00;
823 if ((_interface
& cond
) == 0 && cond
!= 0x07)
826 cond
= condition
& 0xFF0000;
828 if ((_platform
& cond
) == 0 && cond
!= 0x0F)
833 static void _rtl8821ae_config_rf_reg(struct ieee80211_hw
*hw
,
835 enum radio_path rfpath
, u32 regaddr
)
837 if (addr
== 0xfe || addr
== 0xffe) {
838 /* In order not to disturb BT music when
839 * wifi init.(1ant NIC only)
843 rtl_set_rfreg(hw
, rfpath
, regaddr
, RFREG_OFFSET_MASK
, data
);
848 static void _rtl8821ae_config_rf_radio_a(struct ieee80211_hw
*hw
,
851 u32 content
= 0x1000; /*RF Content: radio_a_txt*/
852 u32 maskforphyset
= (u32
)(content
& 0xE000);
854 _rtl8821ae_config_rf_reg(hw
, addr
, data
,
855 RF90_PATH_A
, addr
| maskforphyset
);
858 static void _rtl8821ae_config_rf_radio_b(struct ieee80211_hw
*hw
,
861 u32 content
= 0x1001; /*RF Content: radio_b_txt*/
862 u32 maskforphyset
= (u32
)(content
& 0xE000);
864 _rtl8821ae_config_rf_reg(hw
, addr
, data
,
865 RF90_PATH_B
, addr
| maskforphyset
);
868 static void _rtl8821ae_config_bb_reg(struct ieee80211_hw
*hw
,
873 else if (addr
== 0xfd)
875 else if (addr
== 0xfc)
877 else if (addr
== 0xfb)
879 else if (addr
== 0xfa)
881 else if (addr
== 0xf9)
884 rtl_set_bbreg(hw
, addr
, MASKDWORD
, data
);
889 static void _rtl8821ae_phy_init_tx_power_by_rate(struct ieee80211_hw
*hw
)
891 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
892 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
893 u8 band
, rfpath
, txnum
, rate_section
;
895 for (band
= BAND_ON_2_4G
; band
<= BAND_ON_5G
; ++band
)
896 for (rfpath
= 0; rfpath
< TX_PWR_BY_RATE_NUM_RF
; ++rfpath
)
897 for (txnum
= 0; txnum
< TX_PWR_BY_RATE_NUM_RF
; ++txnum
)
898 for (rate_section
= 0;
899 rate_section
< TX_PWR_BY_RATE_NUM_SECTION
;
901 rtlphy
->tx_power_by_rate_offset
[band
]
902 [rfpath
][txnum
][rate_section
] = 0;
905 static void _rtl8821ae_phy_set_txpower_by_rate_base(struct ieee80211_hw
*hw
,
910 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
911 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
913 if (path
> RF90_PATH_D
) {
914 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
915 "Invalid Rf Path %d in phy_SetTxPowerByRatBase()\n", path
);
919 if (band
== BAND_ON_2_4G
) {
920 switch (rate_section
) {
922 rtlphy
->txpwr_by_rate_base_24g
[path
][txnum
][0] = value
;
925 rtlphy
->txpwr_by_rate_base_24g
[path
][txnum
][1] = value
;
928 rtlphy
->txpwr_by_rate_base_24g
[path
][txnum
][2] = value
;
931 rtlphy
->txpwr_by_rate_base_24g
[path
][txnum
][3] = value
;
933 case VHT_1SSMCS0_1SSMCS9
:
934 rtlphy
->txpwr_by_rate_base_24g
[path
][txnum
][4] = value
;
936 case VHT_2SSMCS0_2SSMCS9
:
937 rtlphy
->txpwr_by_rate_base_24g
[path
][txnum
][5] = value
;
940 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
941 "Invalid RateSection %d in Band 2.4G,Rf Path %d, %dTx in PHY_SetTxPowerByRateBase()\n",
942 rate_section
, path
, txnum
);
945 } else if (band
== BAND_ON_5G
) {
946 switch (rate_section
) {
948 rtlphy
->txpwr_by_rate_base_5g
[path
][txnum
][0] = value
;
951 rtlphy
->txpwr_by_rate_base_5g
[path
][txnum
][1] = value
;
954 rtlphy
->txpwr_by_rate_base_5g
[path
][txnum
][2] = value
;
956 case VHT_1SSMCS0_1SSMCS9
:
957 rtlphy
->txpwr_by_rate_base_5g
[path
][txnum
][3] = value
;
959 case VHT_2SSMCS0_2SSMCS9
:
960 rtlphy
->txpwr_by_rate_base_5g
[path
][txnum
][4] = value
;
963 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
964 "Invalid RateSection %d in Band 5G, Rf Path %d, %dTx in PHY_SetTxPowerByRateBase()\n",
965 rate_section
, path
, txnum
);
969 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
970 "Invalid Band %d in PHY_SetTxPowerByRateBase()\n", band
);
974 static u8
_rtl8821ae_phy_get_txpower_by_rate_base(struct ieee80211_hw
*hw
,
976 u8 txnum
, u8 rate_section
)
978 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
979 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
982 if (path
> RF90_PATH_D
) {
983 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
984 "Invalid Rf Path %d in PHY_GetTxPowerByRateBase()\n",
989 if (band
== BAND_ON_2_4G
) {
990 switch (rate_section
) {
992 value
= rtlphy
->txpwr_by_rate_base_24g
[path
][txnum
][0];
995 value
= rtlphy
->txpwr_by_rate_base_24g
[path
][txnum
][1];
998 value
= rtlphy
->txpwr_by_rate_base_24g
[path
][txnum
][2];
1001 value
= rtlphy
->txpwr_by_rate_base_24g
[path
][txnum
][3];
1003 case VHT_1SSMCS0_1SSMCS9
:
1004 value
= rtlphy
->txpwr_by_rate_base_24g
[path
][txnum
][4];
1006 case VHT_2SSMCS0_2SSMCS9
:
1007 value
= rtlphy
->txpwr_by_rate_base_24g
[path
][txnum
][5];
1010 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1011 "Invalid RateSection %d in Band 2.4G, Rf Path %d, %dTx in PHY_GetTxPowerByRateBase()\n",
1012 rate_section
, path
, txnum
);
1015 } else if (band
== BAND_ON_5G
) {
1016 switch (rate_section
) {
1018 value
= rtlphy
->txpwr_by_rate_base_5g
[path
][txnum
][0];
1021 value
= rtlphy
->txpwr_by_rate_base_5g
[path
][txnum
][1];
1024 value
= rtlphy
->txpwr_by_rate_base_5g
[path
][txnum
][2];
1026 case VHT_1SSMCS0_1SSMCS9
:
1027 value
= rtlphy
->txpwr_by_rate_base_5g
[path
][txnum
][3];
1029 case VHT_2SSMCS0_2SSMCS9
:
1030 value
= rtlphy
->txpwr_by_rate_base_5g
[path
][txnum
][4];
1033 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1034 "Invalid RateSection %d in Band 5G, Rf Path %d, %dTx in PHY_GetTxPowerByRateBase()\n",
1035 rate_section
, path
, txnum
);
1039 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1040 "Invalid Band %d in PHY_GetTxPowerByRateBase()\n", band
);
1046 static void _rtl8821ae_phy_store_txpower_by_rate_base(struct ieee80211_hw
*hw
)
1048 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1049 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1051 u8 base
= 0, path
= 0;
1053 for (path
= RF90_PATH_A
; path
<= RF90_PATH_B
; ++path
) {
1054 rawvalue
= (u16
)(rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][path
][RF_1TX
][0] >> 24) & 0xFF;
1055 base
= (rawvalue
>> 4) * 10 + (rawvalue
& 0xF);
1056 _rtl8821ae_phy_set_txpower_by_rate_base(hw
, BAND_ON_2_4G
, path
, CCK
, RF_1TX
, base
);
1058 rawvalue
= (u16
)(rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][path
][RF_1TX
][2] >> 24) & 0xFF;
1059 base
= (rawvalue
>> 4) * 10 + (rawvalue
& 0xF);
1060 _rtl8821ae_phy_set_txpower_by_rate_base(hw
, BAND_ON_2_4G
, path
, OFDM
, RF_1TX
, base
);
1062 rawvalue
= (u16
)(rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][path
][RF_1TX
][4] >> 24) & 0xFF;
1063 base
= (rawvalue
>> 4) * 10 + (rawvalue
& 0xF);
1064 _rtl8821ae_phy_set_txpower_by_rate_base(hw
, BAND_ON_2_4G
, path
, HT_MCS0_MCS7
, RF_1TX
, base
);
1066 rawvalue
= (u16
)(rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][path
][RF_2TX
][6] >> 24) & 0xFF;
1067 base
= (rawvalue
>> 4) * 10 + (rawvalue
& 0xF);
1068 _rtl8821ae_phy_set_txpower_by_rate_base(hw
, BAND_ON_2_4G
, path
, HT_MCS8_MCS15
, RF_2TX
, base
);
1070 rawvalue
= (u16
)(rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][path
][RF_1TX
][8] >> 24) & 0xFF;
1071 base
= (rawvalue
>> 4) * 10 + (rawvalue
& 0xF);
1072 _rtl8821ae_phy_set_txpower_by_rate_base(hw
, BAND_ON_2_4G
, path
, VHT_1SSMCS0_1SSMCS9
, RF_1TX
, base
);
1074 rawvalue
= (u16
)(rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][path
][RF_2TX
][11] >> 8) & 0xFF;
1075 base
= (rawvalue
>> 4) * 10 + (rawvalue
& 0xF);
1076 _rtl8821ae_phy_set_txpower_by_rate_base(hw
, BAND_ON_2_4G
, path
, VHT_2SSMCS0_2SSMCS9
, RF_2TX
, base
);
1078 rawvalue
= (u16
)(rtlphy
->tx_power_by_rate_offset
[BAND_ON_5G
][path
][RF_1TX
][2] >> 24) & 0xFF;
1079 base
= (rawvalue
>> 4) * 10 + (rawvalue
& 0xF);
1080 _rtl8821ae_phy_set_txpower_by_rate_base(hw
, BAND_ON_5G
, path
, OFDM
, RF_1TX
, base
);
1082 rawvalue
= (u16
)(rtlphy
->tx_power_by_rate_offset
[BAND_ON_5G
][path
][RF_1TX
][4] >> 24) & 0xFF;
1083 base
= (rawvalue
>> 4) * 10 + (rawvalue
& 0xF);
1084 _rtl8821ae_phy_set_txpower_by_rate_base(hw
, BAND_ON_5G
, path
, HT_MCS0_MCS7
, RF_1TX
, base
);
1086 rawvalue
= (u16
)(rtlphy
->tx_power_by_rate_offset
[BAND_ON_5G
][path
][RF_2TX
][6] >> 24) & 0xFF;
1087 base
= (rawvalue
>> 4) * 10 + (rawvalue
& 0xF);
1088 _rtl8821ae_phy_set_txpower_by_rate_base(hw
, BAND_ON_5G
, path
, HT_MCS8_MCS15
, RF_2TX
, base
);
1090 rawvalue
= (u16
)(rtlphy
->tx_power_by_rate_offset
[BAND_ON_5G
][path
][RF_1TX
][8] >> 24) & 0xFF;
1091 base
= (rawvalue
>> 4) * 10 + (rawvalue
& 0xF);
1092 _rtl8821ae_phy_set_txpower_by_rate_base(hw
, BAND_ON_5G
, path
, VHT_1SSMCS0_1SSMCS9
, RF_1TX
, base
);
1094 rawvalue
= (u16
)(rtlphy
->tx_power_by_rate_offset
[BAND_ON_5G
][path
][RF_2TX
][11] >> 8) & 0xFF;
1095 base
= (rawvalue
>> 4) * 10 + (rawvalue
& 0xF);
1096 _rtl8821ae_phy_set_txpower_by_rate_base(hw
, BAND_ON_5G
, path
, VHT_2SSMCS0_2SSMCS9
, RF_2TX
, base
);
1100 static void _phy_convert_txpower_dbm_to_relative_value(u32
*data
, u8 start
,
1101 u8 end
, u8 base_val
)
1107 for (i
= 3; i
>= 0; --i
) {
1108 if (i
>= start
&& i
<= end
) {
1109 /* Get the exact value */
1110 temp_value
= (u8
)(*data
>> (i
* 8)) & 0xF;
1111 temp_value
+= ((u8
)((*data
>> (i
* 8 + 4)) & 0xF)) * 10;
1113 /* Change the value to a relative value */
1114 temp_value
= (temp_value
> base_val
) ? temp_value
-
1115 base_val
: base_val
- temp_value
;
1117 temp_value
= (u8
)(*data
>> (i
* 8)) & 0xFF;
1120 temp_data
|= temp_value
;
1125 static void _rtl8812ae_phy_cross_reference_ht_and_vht_txpower_limit(struct ieee80211_hw
*hw
)
1127 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1128 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1129 u8 regulation
, bw
, channel
, rate_section
;
1132 for (regulation
= 0; regulation
< MAX_REGULATION_NUM
; ++regulation
) {
1133 for (bw
= 0; bw
< MAX_5G_BANDWIDTH_NUM
; ++bw
) {
1134 for (channel
= 0; channel
< CHANNEL_MAX_NUMBER_5G
; ++channel
) {
1135 for (rate_section
= 0; rate_section
< MAX_RATE_SECTION_NUM
; ++rate_section
) {
1136 temp_pwrlmt
= rtlphy
->txpwr_limit_5g
[regulation
]
1137 [bw
][rate_section
][channel
][RF90_PATH_A
];
1138 if (temp_pwrlmt
== MAX_POWER_INDEX
) {
1139 if (bw
== 0 || bw
== 1) { /*5G 20M 40M VHT and HT can cross reference*/
1140 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1141 "No power limit table of the specified band %d, bandwidth %d, ratesection %d, channel %d, rf path %d\n",
1142 1, bw
, rate_section
, channel
, RF90_PATH_A
);
1143 if (rate_section
== 2) {
1144 rtlphy
->txpwr_limit_5g
[regulation
][bw
][2][channel
][RF90_PATH_A
] =
1145 rtlphy
->txpwr_limit_5g
[regulation
][bw
][4][channel
][RF90_PATH_A
];
1146 } else if (rate_section
== 4) {
1147 rtlphy
->txpwr_limit_5g
[regulation
][bw
][4][channel
][RF90_PATH_A
] =
1148 rtlphy
->txpwr_limit_5g
[regulation
][bw
][2][channel
][RF90_PATH_A
];
1149 } else if (rate_section
== 3) {
1150 rtlphy
->txpwr_limit_5g
[regulation
][bw
][3][channel
][RF90_PATH_A
] =
1151 rtlphy
->txpwr_limit_5g
[regulation
][bw
][5][channel
][RF90_PATH_A
];
1152 } else if (rate_section
== 5) {
1153 rtlphy
->txpwr_limit_5g
[regulation
][bw
][5][channel
][RF90_PATH_A
] =
1154 rtlphy
->txpwr_limit_5g
[regulation
][bw
][3][channel
][RF90_PATH_A
];
1157 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1158 "use other value %d\n",
1168 static u8
_rtl8812ae_phy_get_txpower_by_rate_base_index(struct ieee80211_hw
*hw
,
1169 enum band_type band
, u8 rate
)
1171 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1173 if (band
== BAND_ON_2_4G
) {
1216 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1217 "Wrong rate 0x%x to obtain index in 2.4G in PHY_GetTxPowerByRateBaseIndex()\n",
1221 } else if (band
== BAND_ON_5G
) {
1256 case MGN_VHT1SS_MCS0
:
1257 case MGN_VHT1SS_MCS1
:
1258 case MGN_VHT1SS_MCS2
:
1259 case MGN_VHT1SS_MCS3
:
1260 case MGN_VHT1SS_MCS4
:
1261 case MGN_VHT1SS_MCS5
:
1262 case MGN_VHT1SS_MCS6
:
1263 case MGN_VHT1SS_MCS7
:
1264 case MGN_VHT1SS_MCS8
:
1265 case MGN_VHT1SS_MCS9
:
1269 case MGN_VHT2SS_MCS0
:
1270 case MGN_VHT2SS_MCS1
:
1271 case MGN_VHT2SS_MCS2
:
1272 case MGN_VHT2SS_MCS3
:
1273 case MGN_VHT2SS_MCS4
:
1274 case MGN_VHT2SS_MCS5
:
1275 case MGN_VHT2SS_MCS6
:
1276 case MGN_VHT2SS_MCS7
:
1277 case MGN_VHT2SS_MCS8
:
1278 case MGN_VHT2SS_MCS9
:
1283 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1284 "Wrong rate 0x%x to obtain index in 5G in PHY_GetTxPowerByRateBaseIndex()\n",
1293 static void _rtl8812ae_phy_convert_txpower_limit_to_power_index(struct ieee80211_hw
*hw
)
1295 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1296 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1297 u8 bw40_pwr_base_dbm2_4G
, bw40_pwr_base_dbm5G
;
1298 u8 regulation
, bw
, channel
, rate_section
;
1299 u8 base_index2_4G
= 0;
1300 u8 base_index5G
= 0;
1301 s8 temp_value
= 0, temp_pwrlmt
= 0;
1304 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1305 "=====> _rtl8812ae_phy_convert_txpower_limit_to_power_index()\n");
1307 _rtl8812ae_phy_cross_reference_ht_and_vht_txpower_limit(hw
);
1309 for (regulation
= 0; regulation
< MAX_REGULATION_NUM
; ++regulation
) {
1310 for (bw
= 0; bw
< MAX_2_4G_BANDWIDTH_NUM
; ++bw
) {
1311 for (channel
= 0; channel
< CHANNEL_MAX_NUMBER_2G
; ++channel
) {
1312 for (rate_section
= 0; rate_section
< MAX_RATE_SECTION_NUM
; ++rate_section
) {
1313 /* obtain the base dBm values in 2.4G band
1314 CCK => 11M, OFDM => 54M, HT 1T => MCS7, HT 2T => MCS15*/
1315 if (rate_section
== 0) { /*CCK*/
1317 _rtl8812ae_phy_get_txpower_by_rate_base_index(hw
,
1318 BAND_ON_2_4G
, MGN_11M
);
1319 } else if (rate_section
== 1) { /*OFDM*/
1321 _rtl8812ae_phy_get_txpower_by_rate_base_index(hw
,
1322 BAND_ON_2_4G
, MGN_54M
);
1323 } else if (rate_section
== 2) { /*HT IT*/
1325 _rtl8812ae_phy_get_txpower_by_rate_base_index(hw
,
1326 BAND_ON_2_4G
, MGN_MCS7
);
1327 } else if (rate_section
== 3) { /*HT 2T*/
1329 _rtl8812ae_phy_get_txpower_by_rate_base_index(hw
,
1330 BAND_ON_2_4G
, MGN_MCS15
);
1333 temp_pwrlmt
= rtlphy
->txpwr_limit_2_4g
[regulation
]
1334 [bw
][rate_section
][channel
][RF90_PATH_A
];
1336 for (rf_path
= RF90_PATH_A
;
1337 rf_path
< MAX_RF_PATH_NUM
;
1339 if (rate_section
== 3)
1340 bw40_pwr_base_dbm2_4G
=
1341 rtlphy
->txpwr_by_rate_base_24g
[rf_path
][RF_2TX
][base_index2_4G
];
1343 bw40_pwr_base_dbm2_4G
=
1344 rtlphy
->txpwr_by_rate_base_24g
[rf_path
][RF_1TX
][base_index2_4G
];
1346 if (temp_pwrlmt
!= MAX_POWER_INDEX
) {
1347 temp_value
= temp_pwrlmt
- bw40_pwr_base_dbm2_4G
;
1348 rtlphy
->txpwr_limit_2_4g
[regulation
]
1349 [bw
][rate_section
][channel
][rf_path
] =
1353 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1354 "TxPwrLimit_2_4G[regulation %d][bw %d][rateSection %d][channel %d] = %d\n(TxPwrLimit in dBm %d - BW40PwrLmt2_4G[channel %d][rfpath %d] %d)\n",
1355 regulation
, bw
, rate_section
, channel
,
1356 rtlphy
->txpwr_limit_2_4g
[regulation
][bw
]
1357 [rate_section
][channel
][rf_path
], (temp_pwrlmt
== 63)
1358 ? 0 : temp_pwrlmt
/2, channel
, rf_path
,
1359 bw40_pwr_base_dbm2_4G
);
1365 for (regulation
= 0; regulation
< MAX_REGULATION_NUM
; ++regulation
) {
1366 for (bw
= 0; bw
< MAX_5G_BANDWIDTH_NUM
; ++bw
) {
1367 for (channel
= 0; channel
< CHANNEL_MAX_NUMBER_5G
; ++channel
) {
1368 for (rate_section
= 0; rate_section
< MAX_RATE_SECTION_NUM
; ++rate_section
) {
1369 /* obtain the base dBm values in 5G band
1370 OFDM => 54M, HT 1T => MCS7, HT 2T => MCS15,
1371 VHT => 1SSMCS7, VHT 2T => 2SSMCS7*/
1372 if (rate_section
== 1) { /*OFDM*/
1374 _rtl8812ae_phy_get_txpower_by_rate_base_index(hw
,
1375 BAND_ON_5G
, MGN_54M
);
1376 } else if (rate_section
== 2) { /*HT 1T*/
1378 _rtl8812ae_phy_get_txpower_by_rate_base_index(hw
,
1379 BAND_ON_5G
, MGN_MCS7
);
1380 } else if (rate_section
== 3) { /*HT 2T*/
1382 _rtl8812ae_phy_get_txpower_by_rate_base_index(hw
,
1383 BAND_ON_5G
, MGN_MCS15
);
1384 } else if (rate_section
== 4) { /*VHT 1T*/
1386 _rtl8812ae_phy_get_txpower_by_rate_base_index(hw
,
1387 BAND_ON_5G
, MGN_VHT1SS_MCS7
);
1388 } else if (rate_section
== 5) { /*VHT 2T*/
1390 _rtl8812ae_phy_get_txpower_by_rate_base_index(hw
,
1391 BAND_ON_5G
, MGN_VHT2SS_MCS7
);
1394 temp_pwrlmt
= rtlphy
->txpwr_limit_5g
[regulation
]
1395 [bw
][rate_section
][channel
]
1398 for (rf_path
= RF90_PATH_A
;
1399 rf_path
< MAX_RF_PATH_NUM
;
1401 if (rate_section
== 3 || rate_section
== 5)
1402 bw40_pwr_base_dbm5G
=
1403 rtlphy
->txpwr_by_rate_base_5g
[rf_path
]
1404 [RF_2TX
][base_index5G
];
1406 bw40_pwr_base_dbm5G
=
1407 rtlphy
->txpwr_by_rate_base_5g
[rf_path
]
1408 [RF_1TX
][base_index5G
];
1410 if (temp_pwrlmt
!= MAX_POWER_INDEX
) {
1412 temp_pwrlmt
- bw40_pwr_base_dbm5G
;
1413 rtlphy
->txpwr_limit_5g
[regulation
]
1414 [bw
][rate_section
][channel
]
1415 [rf_path
] = temp_value
;
1418 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1419 "TxPwrLimit_5G[regulation %d][bw %d][rateSection %d][channel %d] =%d\n(TxPwrLimit in dBm %d - BW40PwrLmt5G[chnl group %d][rfpath %d] %d)\n",
1420 regulation
, bw
, rate_section
,
1421 channel
, rtlphy
->txpwr_limit_5g
[regulation
]
1422 [bw
][rate_section
][channel
][rf_path
],
1423 temp_pwrlmt
, channel
, rf_path
, bw40_pwr_base_dbm5G
);
1429 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1430 "<===== %s()\n", __func__
);
1433 static void _rtl8821ae_phy_init_txpower_limit(struct ieee80211_hw
*hw
)
1435 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1436 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1439 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1440 "=====>`%s()!\n", __func__
);
1442 for (i
= 0; i
< MAX_REGULATION_NUM
; ++i
) {
1443 for (j
= 0; j
< MAX_2_4G_BANDWIDTH_NUM
; ++j
)
1444 for (k
= 0; k
< MAX_RATE_SECTION_NUM
; ++k
)
1445 for (m
= 0; m
< CHANNEL_MAX_NUMBER_2G
; ++m
)
1446 for (l
= 0; l
< MAX_RF_PATH_NUM
; ++l
)
1447 rtlphy
->txpwr_limit_2_4g
1451 for (i
= 0; i
< MAX_REGULATION_NUM
; ++i
) {
1452 for (j
= 0; j
< MAX_5G_BANDWIDTH_NUM
; ++j
)
1453 for (k
= 0; k
< MAX_RATE_SECTION_NUM
; ++k
)
1454 for (m
= 0; m
< CHANNEL_MAX_NUMBER_5G
; ++m
)
1455 for (l
= 0; l
< MAX_RF_PATH_NUM
; ++l
)
1456 rtlphy
->txpwr_limit_5g
1461 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1462 "<===== %s()!\n", __func__
);
1465 static void _rtl8821ae_phy_convert_txpower_dbm_to_relative_value(struct ieee80211_hw
*hw
)
1467 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1468 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1469 u8 base
= 0, rfpath
= 0;
1471 for (rfpath
= RF90_PATH_A
; rfpath
<= RF90_PATH_B
; ++rfpath
) {
1472 base
= _rtl8821ae_phy_get_txpower_by_rate_base(hw
, BAND_ON_2_4G
, rfpath
, RF_1TX
, CCK
);
1473 _phy_convert_txpower_dbm_to_relative_value(
1474 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][rfpath
][RF_1TX
][0],
1477 base
= _rtl8821ae_phy_get_txpower_by_rate_base(hw
, BAND_ON_2_4G
, rfpath
, RF_1TX
, OFDM
);
1478 _phy_convert_txpower_dbm_to_relative_value(
1479 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][rfpath
][RF_1TX
][1],
1481 _phy_convert_txpower_dbm_to_relative_value(
1482 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][rfpath
][RF_1TX
][2],
1485 base
= _rtl8821ae_phy_get_txpower_by_rate_base(hw
, BAND_ON_2_4G
, rfpath
, RF_1TX
, HT_MCS0_MCS7
);
1486 _phy_convert_txpower_dbm_to_relative_value(
1487 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][rfpath
][RF_1TX
][3],
1489 _phy_convert_txpower_dbm_to_relative_value(
1490 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][rfpath
][RF_1TX
][4],
1493 base
= _rtl8821ae_phy_get_txpower_by_rate_base(hw
, BAND_ON_2_4G
, rfpath
, RF_2TX
, HT_MCS8_MCS15
);
1495 _phy_convert_txpower_dbm_to_relative_value(
1496 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][rfpath
][RF_2TX
][5],
1499 _phy_convert_txpower_dbm_to_relative_value(
1500 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][rfpath
][RF_2TX
][6],
1503 base
= _rtl8821ae_phy_get_txpower_by_rate_base(hw
, BAND_ON_2_4G
, rfpath
, RF_1TX
, VHT_1SSMCS0_1SSMCS9
);
1504 _phy_convert_txpower_dbm_to_relative_value(
1505 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][rfpath
][RF_1TX
][7],
1507 _phy_convert_txpower_dbm_to_relative_value(
1508 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][rfpath
][RF_1TX
][8],
1510 _phy_convert_txpower_dbm_to_relative_value(
1511 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][rfpath
][RF_1TX
][9],
1514 base
= _rtl8821ae_phy_get_txpower_by_rate_base(hw
, BAND_ON_2_4G
, rfpath
, RF_2TX
, VHT_2SSMCS0_2SSMCS9
);
1515 _phy_convert_txpower_dbm_to_relative_value(
1516 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][rfpath
][RF_1TX
][9],
1518 _phy_convert_txpower_dbm_to_relative_value(
1519 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][rfpath
][RF_2TX
][10],
1521 _phy_convert_txpower_dbm_to_relative_value(
1522 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_2_4G
][rfpath
][RF_2TX
][11],
1525 base
= _rtl8821ae_phy_get_txpower_by_rate_base(hw
, BAND_ON_5G
, rfpath
, RF_1TX
, OFDM
);
1526 _phy_convert_txpower_dbm_to_relative_value(
1527 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_5G
][rfpath
][RF_1TX
][1],
1529 _phy_convert_txpower_dbm_to_relative_value(
1530 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_5G
][rfpath
][RF_1TX
][2],
1533 base
= _rtl8821ae_phy_get_txpower_by_rate_base(hw
, BAND_ON_5G
, rfpath
, RF_1TX
, HT_MCS0_MCS7
);
1534 _phy_convert_txpower_dbm_to_relative_value(
1535 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_5G
][rfpath
][RF_1TX
][3],
1537 _phy_convert_txpower_dbm_to_relative_value(
1538 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_5G
][rfpath
][RF_1TX
][4],
1541 base
= _rtl8821ae_phy_get_txpower_by_rate_base(hw
, BAND_ON_5G
, rfpath
, RF_2TX
, HT_MCS8_MCS15
);
1542 _phy_convert_txpower_dbm_to_relative_value(
1543 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_5G
][rfpath
][RF_2TX
][5],
1545 _phy_convert_txpower_dbm_to_relative_value(
1546 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_5G
][rfpath
][RF_2TX
][6],
1549 base
= _rtl8821ae_phy_get_txpower_by_rate_base(hw
, BAND_ON_5G
, rfpath
, RF_1TX
, VHT_1SSMCS0_1SSMCS9
);
1550 _phy_convert_txpower_dbm_to_relative_value(
1551 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_5G
][rfpath
][RF_1TX
][7],
1553 _phy_convert_txpower_dbm_to_relative_value(
1554 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_5G
][rfpath
][RF_1TX
][8],
1556 _phy_convert_txpower_dbm_to_relative_value(
1557 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_5G
][rfpath
][RF_1TX
][9],
1560 base
= _rtl8821ae_phy_get_txpower_by_rate_base(hw
, BAND_ON_5G
, rfpath
, RF_2TX
, VHT_2SSMCS0_2SSMCS9
);
1561 _phy_convert_txpower_dbm_to_relative_value(
1562 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_5G
][rfpath
][RF_1TX
][9],
1564 _phy_convert_txpower_dbm_to_relative_value(
1565 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_5G
][rfpath
][RF_2TX
][10],
1567 _phy_convert_txpower_dbm_to_relative_value(
1568 &rtlphy
->tx_power_by_rate_offset
[BAND_ON_5G
][rfpath
][RF_2TX
][11],
1572 rtl_dbg(rtlpriv
, COMP_POWER
, DBG_TRACE
,
1573 "<===_rtl8821ae_phy_convert_txpower_dbm_to_relative_value()\n");
1576 static void _rtl8821ae_phy_txpower_by_rate_configuration(struct ieee80211_hw
*hw
)
1578 _rtl8821ae_phy_store_txpower_by_rate_base(hw
);
1579 _rtl8821ae_phy_convert_txpower_dbm_to_relative_value(hw
);
1582 /* string is in decimal */
1583 static bool _rtl8812ae_get_integer_from_string(const char *str
, u8
*pint
)
1588 while (str
[i
] != '\0') {
1589 if (str
[i
] >= '0' && str
[i
] <= '9') {
1591 *pint
+= (str
[i
] - '0');
1601 static bool _rtl8812ae_eq_n_byte(const char *str1
, const char *str2
, u32 num
)
1607 if (str1
[num
] != str2
[num
])
1613 static s8
_rtl8812ae_phy_get_chnl_idx_of_txpwr_lmt(struct ieee80211_hw
*hw
,
1614 u8 band
, u8 channel
)
1616 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1617 s8 channel_index
= -1;
1620 if (band
== BAND_ON_2_4G
)
1621 channel_index
= channel
- 1;
1622 else if (band
== BAND_ON_5G
) {
1623 for (i
= 0; i
< sizeof(channel5g
)/sizeof(u8
); ++i
) {
1624 if (channel5g
[i
] == channel
)
1628 rtl_dbg(rtlpriv
, COMP_POWER
, DBG_LOUD
, "Invalid Band %d in %s\n",
1631 if (channel_index
== -1)
1632 rtl_dbg(rtlpriv
, COMP_POWER
, DBG_LOUD
,
1633 "Invalid Channel %d of Band %d in %s\n", channel
,
1636 return channel_index
;
1639 static void _rtl8812ae_phy_set_txpower_limit(struct ieee80211_hw
*hw
,
1640 const char *pregulation
,
1641 const char *pband
, const char *pbandwidth
,
1642 const char *prate_section
, const char *prf_path
,
1643 const char *pchannel
, const char *ppower_limit
)
1645 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1646 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1647 u8 regulation
= 0, bandwidth
= 0, rate_section
= 0, channel
;
1649 s8 power_limit
= 0, prev_power_limit
, ret
;
1651 if (!_rtl8812ae_get_integer_from_string(pchannel
, &channel
) ||
1652 !_rtl8812ae_get_integer_from_string(ppower_limit
,
1654 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1655 "Illegal index of pwr_lmt table [chnl %d][val %d]\n",
1656 channel
, power_limit
);
1659 power_limit
= power_limit
> MAX_POWER_INDEX
?
1660 MAX_POWER_INDEX
: power_limit
;
1662 if (_rtl8812ae_eq_n_byte(pregulation
, "FCC", 3))
1664 else if (_rtl8812ae_eq_n_byte(pregulation
, "MKK", 3))
1666 else if (_rtl8812ae_eq_n_byte(pregulation
, "ETSI", 4))
1668 else if (_rtl8812ae_eq_n_byte(pregulation
, "WW13", 4))
1671 if (_rtl8812ae_eq_n_byte(prate_section
, "CCK", 3))
1673 else if (_rtl8812ae_eq_n_byte(prate_section
, "OFDM", 4))
1675 else if (_rtl8812ae_eq_n_byte(prate_section
, "HT", 2) &&
1676 _rtl8812ae_eq_n_byte(prf_path
, "1T", 2))
1678 else if (_rtl8812ae_eq_n_byte(prate_section
, "HT", 2) &&
1679 _rtl8812ae_eq_n_byte(prf_path
, "2T", 2))
1681 else if (_rtl8812ae_eq_n_byte(prate_section
, "VHT", 3) &&
1682 _rtl8812ae_eq_n_byte(prf_path
, "1T", 2))
1684 else if (_rtl8812ae_eq_n_byte(prate_section
, "VHT", 3) &&
1685 _rtl8812ae_eq_n_byte(prf_path
, "2T", 2))
1688 if (_rtl8812ae_eq_n_byte(pbandwidth
, "20M", 3))
1690 else if (_rtl8812ae_eq_n_byte(pbandwidth
, "40M", 3))
1692 else if (_rtl8812ae_eq_n_byte(pbandwidth
, "80M", 3))
1694 else if (_rtl8812ae_eq_n_byte(pbandwidth
, "160M", 4))
1697 if (_rtl8812ae_eq_n_byte(pband
, "2.4G", 4)) {
1698 ret
= _rtl8812ae_phy_get_chnl_idx_of_txpwr_lmt(hw
,
1705 channel_index
= ret
;
1707 prev_power_limit
= rtlphy
->txpwr_limit_2_4g
[regulation
]
1708 [bandwidth
][rate_section
]
1709 [channel_index
][RF90_PATH_A
];
1711 if (power_limit
< prev_power_limit
)
1712 rtlphy
->txpwr_limit_2_4g
[regulation
][bandwidth
]
1713 [rate_section
][channel_index
][RF90_PATH_A
] =
1716 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1717 "2.4G [regula %d][bw %d][sec %d][chnl %d][val %d]\n",
1718 regulation
, bandwidth
, rate_section
, channel_index
,
1719 rtlphy
->txpwr_limit_2_4g
[regulation
][bandwidth
]
1720 [rate_section
][channel_index
][RF90_PATH_A
]);
1721 } else if (_rtl8812ae_eq_n_byte(pband
, "5G", 2)) {
1722 ret
= _rtl8812ae_phy_get_chnl_idx_of_txpwr_lmt(hw
,
1729 channel_index
= ret
;
1731 prev_power_limit
= rtlphy
->txpwr_limit_5g
[regulation
][bandwidth
]
1732 [rate_section
][channel_index
]
1735 if (power_limit
< prev_power_limit
)
1736 rtlphy
->txpwr_limit_5g
[regulation
][bandwidth
]
1737 [rate_section
][channel_index
][RF90_PATH_A
] = power_limit
;
1739 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1740 "5G: [regul %d][bw %d][sec %d][chnl %d][val %d]\n",
1741 regulation
, bandwidth
, rate_section
, channel
,
1742 rtlphy
->txpwr_limit_5g
[regulation
][bandwidth
]
1743 [rate_section
][channel_index
][RF90_PATH_A
]);
1745 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1746 "Cannot recognize the band info in %s\n", pband
);
1751 static void _rtl8812ae_phy_config_bb_txpwr_lmt(struct ieee80211_hw
*hw
,
1752 const char *regulation
, const char *band
,
1753 const char *bandwidth
, const char *rate_section
,
1754 const char *rf_path
, const char *channel
,
1755 const char *power_limit
)
1757 _rtl8812ae_phy_set_txpower_limit(hw
, regulation
, band
, bandwidth
,
1758 rate_section
, rf_path
, channel
,
1762 static void _rtl8821ae_phy_read_and_config_txpwr_lmt(struct ieee80211_hw
*hw
)
1764 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1765 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1770 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
1771 array_len
= RTL8812AE_TXPWR_LMT_ARRAY_LEN
;
1772 array
= RTL8812AE_TXPWR_LMT
;
1774 array_len
= RTL8821AE_TXPWR_LMT_ARRAY_LEN
;
1775 array
= RTL8821AE_TXPWR_LMT
;
1778 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
, "\n");
1780 for (i
= 0; i
< array_len
; i
+= 7) {
1781 const char *regulation
= array
[i
];
1782 const char *band
= array
[i
+1];
1783 const char *bandwidth
= array
[i
+2];
1784 const char *rate
= array
[i
+3];
1785 const char *rf_path
= array
[i
+4];
1786 const char *chnl
= array
[i
+5];
1787 const char *val
= array
[i
+6];
1789 _rtl8812ae_phy_config_bb_txpwr_lmt(hw
, regulation
, band
,
1790 bandwidth
, rate
, rf_path
,
1795 static bool _rtl8821ae_phy_bb8821a_config_parafile(struct ieee80211_hw
*hw
)
1797 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1798 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1799 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1802 _rtl8821ae_phy_init_txpower_limit(hw
);
1804 /* RegEnableTxPowerLimit == 1 for 8812a & 8821a */
1805 if (rtlefuse
->eeprom_regulatory
!= 2)
1806 _rtl8821ae_phy_read_and_config_txpwr_lmt(hw
);
1808 rtstatus
= _rtl8821ae_phy_config_bb_with_headerfile(hw
,
1809 BASEBAND_CONFIG_PHY_REG
);
1811 pr_err("Write BB Reg Fail!!\n");
1814 _rtl8821ae_phy_init_tx_power_by_rate(hw
);
1815 if (rtlefuse
->autoload_failflag
== false) {
1816 rtstatus
= _rtl8821ae_phy_config_bb_with_pgheaderfile(hw
,
1817 BASEBAND_CONFIG_PHY_REG
);
1820 pr_err("BB_PG Reg Fail!!\n");
1824 _rtl8821ae_phy_txpower_by_rate_configuration(hw
);
1826 /* RegEnableTxPowerLimit == 1 for 8812a & 8821a */
1827 if (rtlefuse
->eeprom_regulatory
!= 2)
1828 _rtl8812ae_phy_convert_txpower_limit_to_power_index(hw
);
1830 rtstatus
= _rtl8821ae_phy_config_bb_with_headerfile(hw
,
1831 BASEBAND_CONFIG_AGC_TAB
);
1834 pr_err("AGC Table Fail\n");
1837 rtlphy
->cck_high_power
= (bool)(rtl_get_bbreg(hw
,
1838 RFPGA0_XA_HSSIPARAMETER2
, 0x200));
1843 __rtl8821ae_phy_config_with_headerfile(struct ieee80211_hw
*hw
,
1844 u32
*array_table
, u16 arraylen
,
1845 void (*set_reg
)(struct ieee80211_hw
*hw
,
1846 u32 regaddr
, u32 data
))
1849 #define COND_ENDIF 3
1853 bool matched
= true, skipped
= false;
1855 while ((i
+ 1) < arraylen
) {
1856 u32 v1
= array_table
[i
];
1857 u32 v2
= array_table
[i
+ 1];
1859 if (v1
& (BIT(31) | BIT(30))) {/*positive & negative condition*/
1860 if (v1
& BIT(31)) {/* positive condition*/
1861 cond
= (u8
)((v1
& (BIT(29) | BIT(28))) >> 28);
1862 if (cond
== COND_ENDIF
) {/*end*/
1865 } else if (cond
== COND_ELSE
) /*else*/
1866 matched
= skipped
? false : true;
1867 else {/*if , else if*/
1871 if (_rtl8821ae_check_positive(
1881 } else if (v1
& BIT(30)) { /*negative condition*/
1886 set_reg(hw
, v1
, v2
);
1894 static bool _rtl8821ae_phy_config_mac_with_headerfile(struct ieee80211_hw
*hw
)
1896 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1897 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1901 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
, "Read MAC_REG_Array\n");
1902 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
1903 arraylength
= RTL8821AE_MAC_1T_ARRAYLEN
;
1904 ptrarray
= RTL8821AE_MAC_REG_ARRAY
;
1906 arraylength
= RTL8812AE_MAC_1T_ARRAYLEN
;
1907 ptrarray
= RTL8812AE_MAC_REG_ARRAY
;
1909 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1910 "Img: MAC_REG_ARRAY LEN %d\n", arraylength
);
1912 return __rtl8821ae_phy_config_with_headerfile(hw
,
1913 ptrarray
, arraylength
, rtl_write_byte_with_val32
);
1916 static bool _rtl8821ae_phy_config_bb_with_headerfile(struct ieee80211_hw
*hw
,
1919 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1920 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1924 if (configtype
== BASEBAND_CONFIG_PHY_REG
) {
1925 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
1926 arraylen
= RTL8812AE_PHY_REG_1TARRAYLEN
;
1927 array_table
= RTL8812AE_PHY_REG_ARRAY
;
1929 arraylen
= RTL8821AE_PHY_REG_1TARRAYLEN
;
1930 array_table
= RTL8821AE_PHY_REG_ARRAY
;
1933 return __rtl8821ae_phy_config_with_headerfile(hw
,
1934 array_table
, arraylen
,
1935 _rtl8821ae_config_bb_reg
);
1936 } else if (configtype
== BASEBAND_CONFIG_AGC_TAB
) {
1937 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
1938 arraylen
= RTL8812AE_AGC_TAB_1TARRAYLEN
;
1939 array_table
= RTL8812AE_AGC_TAB_ARRAY
;
1941 arraylen
= RTL8821AE_AGC_TAB_1TARRAYLEN
;
1942 array_table
= RTL8821AE_AGC_TAB_ARRAY
;
1945 return __rtl8821ae_phy_config_with_headerfile(hw
,
1946 array_table
, arraylen
,
1947 rtl_set_bbreg_with_dwmask
);
1952 static u8
_rtl8821ae_get_rate_section_index(u32 regaddr
)
1956 if (regaddr
>= 0xC20 && regaddr
<= 0xC4C)
1957 index
= (u8
)((regaddr
- 0xC20) / 4);
1958 else if (regaddr
>= 0xE20 && regaddr
<= 0xE4C)
1959 index
= (u8
)((regaddr
- 0xE20) / 4);
1962 "rtl8821ae: Invalid RegAddr 0x%x\n", regaddr
);
1966 static void _rtl8821ae_store_tx_power_by_rate(struct ieee80211_hw
*hw
,
1967 u32 band
, u32 rfpath
,
1968 u32 txnum
, u32 regaddr
,
1969 u32 bitmask
, u32 data
)
1971 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1972 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1973 u8 rate_section
= _rtl8821ae_get_rate_section_index(regaddr
);
1975 if (band
!= BAND_ON_2_4G
&& band
!= BAND_ON_5G
) {
1976 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_WARNING
, "Invalid Band %d\n", band
);
1977 band
= BAND_ON_2_4G
;
1979 if (rfpath
>= MAX_RF_PATH
) {
1980 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_WARNING
, "Invalid RfPath %d\n", rfpath
);
1981 rfpath
= MAX_RF_PATH
- 1;
1983 if (txnum
>= MAX_RF_PATH
) {
1984 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_WARNING
, "Invalid TxNum %d\n", txnum
);
1985 txnum
= MAX_RF_PATH
- 1;
1987 rtlphy
->tx_power_by_rate_offset
[band
][rfpath
][txnum
][rate_section
] = data
;
1988 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1989 "TxPwrByRateOffset[Band %d][RfPath %d][TxNum %d][RateSection %d] = 0x%x\n",
1990 band
, rfpath
, txnum
, rate_section
,
1991 rtlphy
->tx_power_by_rate_offset
[band
][rfpath
][txnum
][rate_section
]);
1994 static bool _rtl8821ae_phy_config_bb_with_pgheaderfile(struct ieee80211_hw
*hw
,
1997 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1998 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
2002 u32 v1
, v2
, v3
, v4
, v5
, v6
;
2004 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
2005 arraylen
= RTL8812AE_PHY_REG_ARRAY_PGLEN
;
2006 array
= RTL8812AE_PHY_REG_ARRAY_PG
;
2008 arraylen
= RTL8821AE_PHY_REG_ARRAY_PGLEN
;
2009 array
= RTL8821AE_PHY_REG_ARRAY_PG
;
2012 if (configtype
!= BASEBAND_CONFIG_PHY_REG
) {
2013 rtl_dbg(rtlpriv
, COMP_SEND
, DBG_TRACE
,
2014 "configtype != BaseBand_Config_PHY_REG\n");
2017 for (i
= 0; i
< arraylen
; i
+= 6) {
2025 if (v1
< 0xCDCDCDCD) {
2026 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
&&
2027 (v4
== 0xfe || v4
== 0xffe)) {
2032 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
2035 else if (v4
== 0xfd)
2037 else if (v4
== 0xfc)
2039 else if (v4
== 0xfb)
2041 else if (v4
== 0xfa)
2043 else if (v4
== 0xf9)
2046 _rtl8821ae_store_tx_power_by_rate(hw
, v1
, v2
, v3
,
2050 /*don't need the hw_body*/
2051 if (!_rtl8821ae_check_condition(hw
, v1
)) {
2052 i
+= 2; /* skip the pair of expression*/
2056 while (v2
!= 0xDEAD) {
2069 bool rtl8812ae_phy_config_rf_with_headerfile(struct ieee80211_hw
*hw
,
2070 enum radio_path rfpath
)
2072 u32
*radioa_array_table_a
, *radioa_array_table_b
;
2073 u16 radioa_arraylen_a
, radioa_arraylen_b
;
2074 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2076 radioa_arraylen_a
= RTL8812AE_RADIOA_1TARRAYLEN
;
2077 radioa_array_table_a
= RTL8812AE_RADIOA_ARRAY
;
2078 radioa_arraylen_b
= RTL8812AE_RADIOB_1TARRAYLEN
;
2079 radioa_array_table_b
= RTL8812AE_RADIOB_ARRAY
;
2080 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2081 "Radio_A:RTL8821AE_RADIOA_ARRAY %d\n", radioa_arraylen_a
);
2082 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Radio No %x\n", rfpath
);
2085 return __rtl8821ae_phy_config_with_headerfile(hw
,
2086 radioa_array_table_a
, radioa_arraylen_a
,
2087 _rtl8821ae_config_rf_radio_a
);
2089 return __rtl8821ae_phy_config_with_headerfile(hw
,
2090 radioa_array_table_b
, radioa_arraylen_b
,
2091 _rtl8821ae_config_rf_radio_b
);
2094 pr_err("switch case %#x not processed\n", rfpath
);
2100 bool rtl8821ae_phy_config_rf_with_headerfile(struct ieee80211_hw
*hw
,
2101 enum radio_path rfpath
)
2103 u32
*radioa_array_table
;
2104 u16 radioa_arraylen
;
2105 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2107 radioa_arraylen
= RTL8821AE_RADIOA_1TARRAYLEN
;
2108 radioa_array_table
= RTL8821AE_RADIOA_ARRAY
;
2109 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2110 "Radio_A:RTL8821AE_RADIOA_ARRAY %d\n", radioa_arraylen
);
2111 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Radio No %x\n", rfpath
);
2114 return __rtl8821ae_phy_config_with_headerfile(hw
,
2115 radioa_array_table
, radioa_arraylen
,
2116 _rtl8821ae_config_rf_radio_a
);
2121 pr_err("switch case %#x not processed\n", rfpath
);
2127 void rtl8821ae_phy_get_hw_reg_originalvalue(struct ieee80211_hw
*hw
)
2129 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2130 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
2132 rtlphy
->default_initialgain
[0] =
2133 (u8
)rtl_get_bbreg(hw
, ROFDM0_XAAGCCORE1
, MASKBYTE0
);
2134 rtlphy
->default_initialgain
[1] =
2135 (u8
)rtl_get_bbreg(hw
, ROFDM0_XBAGCCORE1
, MASKBYTE0
);
2136 rtlphy
->default_initialgain
[2] =
2137 (u8
)rtl_get_bbreg(hw
, ROFDM0_XCAGCCORE1
, MASKBYTE0
);
2138 rtlphy
->default_initialgain
[3] =
2139 (u8
)rtl_get_bbreg(hw
, ROFDM0_XDAGCCORE1
, MASKBYTE0
);
2141 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
2142 "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x\n",
2143 rtlphy
->default_initialgain
[0],
2144 rtlphy
->default_initialgain
[1],
2145 rtlphy
->default_initialgain
[2],
2146 rtlphy
->default_initialgain
[3]);
2148 rtlphy
->framesync
= (u8
)rtl_get_bbreg(hw
,
2149 ROFDM0_RXDETECTOR3
, MASKBYTE0
);
2150 rtlphy
->framesync_c34
= rtl_get_bbreg(hw
,
2151 ROFDM0_RXDETECTOR2
, MASKDWORD
);
2153 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
2154 "Default framesync (0x%x) = 0x%x\n",
2155 ROFDM0_RXDETECTOR3
, rtlphy
->framesync
);
2158 static void phy_init_bb_rf_register_definition(struct ieee80211_hw
*hw
)
2160 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2161 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
2163 rtlphy
->phyreg_def
[RF90_PATH_A
].rfintfs
= RFPGA0_XAB_RFINTERFACESW
;
2164 rtlphy
->phyreg_def
[RF90_PATH_B
].rfintfs
= RFPGA0_XAB_RFINTERFACESW
;
2166 rtlphy
->phyreg_def
[RF90_PATH_A
].rfintfo
= RFPGA0_XA_RFINTERFACEOE
;
2167 rtlphy
->phyreg_def
[RF90_PATH_B
].rfintfo
= RFPGA0_XB_RFINTERFACEOE
;
2169 rtlphy
->phyreg_def
[RF90_PATH_A
].rfintfe
= RFPGA0_XA_RFINTERFACEOE
;
2170 rtlphy
->phyreg_def
[RF90_PATH_B
].rfintfe
= RFPGA0_XB_RFINTERFACEOE
;
2172 rtlphy
->phyreg_def
[RF90_PATH_A
].rf3wire_offset
= RA_LSSIWRITE_8821A
;
2173 rtlphy
->phyreg_def
[RF90_PATH_B
].rf3wire_offset
= RB_LSSIWRITE_8821A
;
2175 rtlphy
->phyreg_def
[RF90_PATH_A
].rfhssi_para2
= RHSSIREAD_8821AE
;
2176 rtlphy
->phyreg_def
[RF90_PATH_B
].rfhssi_para2
= RHSSIREAD_8821AE
;
2178 rtlphy
->phyreg_def
[RF90_PATH_A
].rf_rb
= RA_SIREAD_8821A
;
2179 rtlphy
->phyreg_def
[RF90_PATH_B
].rf_rb
= RB_SIREAD_8821A
;
2181 rtlphy
->phyreg_def
[RF90_PATH_A
].rf_rbpi
= RA_PIREAD_8821A
;
2182 rtlphy
->phyreg_def
[RF90_PATH_B
].rf_rbpi
= RB_PIREAD_8821A
;
2185 void rtl8821ae_phy_get_txpower_level(struct ieee80211_hw
*hw
, long *powerlevel
)
2187 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2188 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
2192 txpwr_level
= rtlphy
->cur_cck_txpwridx
;
2193 txpwr_dbm
= _rtl8821ae_phy_txpwr_idx_to_dbm(hw
,
2194 WIRELESS_MODE_B
, txpwr_level
);
2195 txpwr_level
= rtlphy
->cur_ofdm24g_txpwridx
;
2196 if (_rtl8821ae_phy_txpwr_idx_to_dbm(hw
,
2198 txpwr_level
) > txpwr_dbm
)
2200 _rtl8821ae_phy_txpwr_idx_to_dbm(hw
, WIRELESS_MODE_G
,
2202 txpwr_level
= rtlphy
->cur_ofdm24g_txpwridx
;
2203 if (_rtl8821ae_phy_txpwr_idx_to_dbm(hw
,
2204 WIRELESS_MODE_N_24G
,
2205 txpwr_level
) > txpwr_dbm
)
2207 _rtl8821ae_phy_txpwr_idx_to_dbm(hw
, WIRELESS_MODE_N_24G
,
2209 *powerlevel
= txpwr_dbm
;
2212 static bool _rtl8821ae_phy_get_chnl_index(u8 channel
, u8
*chnl_index
)
2217 if (channel
<= 14) {
2219 *chnl_index
= channel
- 1;
2223 for (i
= 0; i
< CHANNEL_MAX_NUMBER_5G
; ++i
) {
2224 if (channel5g
[i
] == channel
) {
2233 static s8
_rtl8821ae_phy_get_ratesection_intxpower_byrate(u8 path
, u8 rate
)
2235 s8 rate_section
= 0;
2269 case DESC_RATEMCS10
:
2270 case DESC_RATEMCS11
:
2273 case DESC_RATEMCS12
:
2274 case DESC_RATEMCS13
:
2275 case DESC_RATEMCS14
:
2276 case DESC_RATEMCS15
:
2279 case DESC_RATEVHT1SS_MCS0
:
2280 case DESC_RATEVHT1SS_MCS1
:
2281 case DESC_RATEVHT1SS_MCS2
:
2282 case DESC_RATEVHT1SS_MCS3
:
2285 case DESC_RATEVHT1SS_MCS4
:
2286 case DESC_RATEVHT1SS_MCS5
:
2287 case DESC_RATEVHT1SS_MCS6
:
2288 case DESC_RATEVHT1SS_MCS7
:
2291 case DESC_RATEVHT1SS_MCS8
:
2292 case DESC_RATEVHT1SS_MCS9
:
2293 case DESC_RATEVHT2SS_MCS0
:
2294 case DESC_RATEVHT2SS_MCS1
:
2297 case DESC_RATEVHT2SS_MCS2
:
2298 case DESC_RATEVHT2SS_MCS3
:
2299 case DESC_RATEVHT2SS_MCS4
:
2300 case DESC_RATEVHT2SS_MCS5
:
2303 case DESC_RATEVHT2SS_MCS6
:
2304 case DESC_RATEVHT2SS_MCS7
:
2305 case DESC_RATEVHT2SS_MCS8
:
2306 case DESC_RATEVHT2SS_MCS9
:
2310 WARN_ONCE(true, "rtl8821ae: Rate_Section is Illegal\n");
2314 return rate_section
;
2317 static s8
_rtl8812ae_phy_get_world_wide_limit(s8
*limit_table
)
2319 s8 min
= limit_table
[0];
2322 for (i
= 0; i
< MAX_REGULATION_NUM
; ++i
) {
2323 if (limit_table
[i
] < min
)
2324 min
= limit_table
[i
];
2329 static s8
_rtl8812ae_phy_get_txpower_limit(struct ieee80211_hw
*hw
,
2331 enum ht_channel_width bandwidth
,
2332 enum radio_path rf_path
,
2333 u8 rate
, u8 channel
)
2335 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2336 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtlpriv
);
2337 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
2338 short band_temp
= -1, regulation
= -1, bandwidth_temp
= -1,
2339 rate_section
= -1, channel_temp
= -1;
2340 u16 regu
, bdwidth
, sec
, chnl
;
2341 s8 power_limit
= MAX_POWER_INDEX
;
2343 if (rtlefuse
->eeprom_regulatory
== 2)
2344 return MAX_POWER_INDEX
;
2346 regulation
= TXPWR_LMT_WW
;
2348 if (band
== BAND_ON_2_4G
)
2350 else if (band
== BAND_ON_5G
)
2353 if (bandwidth
== HT_CHANNEL_WIDTH_20
)
2355 else if (bandwidth
== HT_CHANNEL_WIDTH_20_40
)
2357 else if (bandwidth
== HT_CHANNEL_WIDTH_80
)
2389 case DESC_RATEMCS10
:
2390 case DESC_RATEMCS11
:
2391 case DESC_RATEMCS12
:
2392 case DESC_RATEMCS13
:
2393 case DESC_RATEMCS14
:
2394 case DESC_RATEMCS15
:
2397 case DESC_RATEVHT1SS_MCS0
:
2398 case DESC_RATEVHT1SS_MCS1
:
2399 case DESC_RATEVHT1SS_MCS2
:
2400 case DESC_RATEVHT1SS_MCS3
:
2401 case DESC_RATEVHT1SS_MCS4
:
2402 case DESC_RATEVHT1SS_MCS5
:
2403 case DESC_RATEVHT1SS_MCS6
:
2404 case DESC_RATEVHT1SS_MCS7
:
2405 case DESC_RATEVHT1SS_MCS8
:
2406 case DESC_RATEVHT1SS_MCS9
:
2409 case DESC_RATEVHT2SS_MCS0
:
2410 case DESC_RATEVHT2SS_MCS1
:
2411 case DESC_RATEVHT2SS_MCS2
:
2412 case DESC_RATEVHT2SS_MCS3
:
2413 case DESC_RATEVHT2SS_MCS4
:
2414 case DESC_RATEVHT2SS_MCS5
:
2415 case DESC_RATEVHT2SS_MCS6
:
2416 case DESC_RATEVHT2SS_MCS7
:
2417 case DESC_RATEVHT2SS_MCS8
:
2418 case DESC_RATEVHT2SS_MCS9
:
2422 rtl_dbg(rtlpriv
, COMP_POWER
, DBG_LOUD
,
2423 "Wrong rate 0x%x\n", rate
);
2427 if (band_temp
== BAND_ON_5G
&& rate_section
== 0)
2428 rtl_dbg(rtlpriv
, COMP_POWER
, DBG_LOUD
,
2429 "Wrong rate 0x%x: No CCK in 5G Band\n", rate
);
2431 /*workaround for wrong index combination to obtain tx power limit,
2432 OFDM only exists in BW 20M*/
2433 if (rate_section
== 1)
2436 /*workaround for wrong index combination to obtain tx power limit,
2437 *HT on 80M will reference to HT on 40M
2439 if ((rate_section
== 2 || rate_section
== 3) && band
== BAND_ON_5G
&&
2440 bandwidth_temp
== 2)
2443 if (band
== BAND_ON_2_4G
)
2444 channel_temp
= _rtl8812ae_phy_get_chnl_idx_of_txpwr_lmt(hw
,
2445 BAND_ON_2_4G
, channel
);
2446 else if (band
== BAND_ON_5G
)
2447 channel_temp
= _rtl8812ae_phy_get_chnl_idx_of_txpwr_lmt(hw
,
2448 BAND_ON_5G
, channel
);
2449 else if (band
== BAND_ON_BOTH
) {
2450 ;/* BAND_ON_BOTH don't care temporarily */
2453 if (band_temp
== -1 || regulation
== -1 || bandwidth_temp
== -1 ||
2454 rate_section
== -1 || channel_temp
== -1) {
2455 rtl_dbg(rtlpriv
, COMP_POWER
, DBG_LOUD
,
2456 "Wrong index value to access power limit table [band %d][regulation %d][bandwidth %d][rf_path %d][rate_section %d][chnl %d]\n",
2457 band_temp
, regulation
, bandwidth_temp
, rf_path
,
2458 rate_section
, channel_temp
);
2459 return MAX_POWER_INDEX
;
2463 bdwidth
= bandwidth_temp
;
2465 chnl
= channel_temp
;
2467 if (band
== BAND_ON_2_4G
) {
2468 s8 limits
[10] = {0};
2471 for (i
= 0; i
< 4; ++i
)
2472 limits
[i
] = rtlphy
->txpwr_limit_2_4g
[i
][bdwidth
]
2473 [sec
][chnl
][rf_path
];
2475 power_limit
= (regulation
== TXPWR_LMT_WW
) ?
2476 _rtl8812ae_phy_get_world_wide_limit(limits
) :
2477 rtlphy
->txpwr_limit_2_4g
[regu
][bdwidth
]
2478 [sec
][chnl
][rf_path
];
2479 } else if (band
== BAND_ON_5G
) {
2480 s8 limits
[10] = {0};
2483 for (i
= 0; i
< MAX_REGULATION_NUM
; ++i
)
2484 limits
[i
] = rtlphy
->txpwr_limit_5g
[i
][bdwidth
]
2485 [sec
][chnl
][rf_path
];
2487 power_limit
= (regulation
== TXPWR_LMT_WW
) ?
2488 _rtl8812ae_phy_get_world_wide_limit(limits
) :
2489 rtlphy
->txpwr_limit_5g
[regu
][chnl
]
2490 [sec
][chnl
][rf_path
];
2492 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2493 "No power limit table of the specified band\n");
2498 static s8
_rtl8821ae_phy_get_txpower_by_rate(struct ieee80211_hw
*hw
,
2499 u8 band
, u8 path
, u8 rate
)
2501 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2502 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
2503 u8 shift
= 0, rate_section
, tx_num
;
2507 rate_section
= _rtl8821ae_phy_get_ratesection_intxpower_byrate(path
, rate
);
2508 tx_num
= RF_TX_NUM_NONIMPLEMENT
;
2510 if (tx_num
== RF_TX_NUM_NONIMPLEMENT
) {
2511 if ((rate
>= DESC_RATEMCS8
&& rate
<= DESC_RATEMCS15
) ||
2512 (rate
>= DESC_RATEVHT2SS_MCS2
&& rate
<= DESC_RATEVHT2SS_MCS9
))
2525 case DESC_RATEMCS12
:
2526 case DESC_RATEVHT1SS_MCS0
:
2527 case DESC_RATEVHT1SS_MCS4
:
2528 case DESC_RATEVHT1SS_MCS8
:
2529 case DESC_RATEVHT2SS_MCS2
:
2530 case DESC_RATEVHT2SS_MCS6
:
2539 case DESC_RATEMCS13
:
2540 case DESC_RATEVHT1SS_MCS1
:
2541 case DESC_RATEVHT1SS_MCS5
:
2542 case DESC_RATEVHT1SS_MCS9
:
2543 case DESC_RATEVHT2SS_MCS3
:
2544 case DESC_RATEVHT2SS_MCS7
:
2552 case DESC_RATEMCS10
:
2553 case DESC_RATEMCS14
:
2554 case DESC_RATEVHT1SS_MCS2
:
2555 case DESC_RATEVHT1SS_MCS6
:
2556 case DESC_RATEVHT2SS_MCS0
:
2557 case DESC_RATEVHT2SS_MCS4
:
2558 case DESC_RATEVHT2SS_MCS8
:
2566 case DESC_RATEMCS11
:
2567 case DESC_RATEMCS15
:
2568 case DESC_RATEVHT1SS_MCS3
:
2569 case DESC_RATEVHT1SS_MCS7
:
2570 case DESC_RATEVHT2SS_MCS1
:
2571 case DESC_RATEVHT2SS_MCS5
:
2572 case DESC_RATEVHT2SS_MCS9
:
2576 WARN_ONCE(true, "rtl8821ae: Rate_Section is Illegal\n");
2580 tx_pwr_diff
= (u8
)(rtlphy
->tx_power_by_rate_offset
[band
][path
]
2581 [tx_num
][rate_section
] >> shift
) & 0xff;
2583 /* RegEnableTxPowerLimit == 1 for 8812a & 8821a */
2584 if (rtlpriv
->efuse
.eeprom_regulatory
!= 2) {
2585 limit
= _rtl8812ae_phy_get_txpower_limit(hw
, band
,
2586 rtlphy
->current_chan_bw
, path
, rate
,
2587 rtlphy
->current_channel
);
2589 if (rate
== DESC_RATEVHT1SS_MCS8
|| rate
== DESC_RATEVHT1SS_MCS9
||
2590 rate
== DESC_RATEVHT2SS_MCS8
|| rate
== DESC_RATEVHT2SS_MCS9
) {
2592 if (tx_pwr_diff
< (-limit
))
2593 tx_pwr_diff
= -limit
;
2597 tx_pwr_diff
= limit
;
2599 tx_pwr_diff
= tx_pwr_diff
> limit
? limit
: tx_pwr_diff
;
2601 rtl_dbg(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
,
2602 "Maximum power by rate %d, final power by rate %d\n",
2603 limit
, tx_pwr_diff
);
2609 static u8
_rtl8821ae_get_txpower_index(struct ieee80211_hw
*hw
, u8 path
,
2610 u8 rate
, u8 bandwidth
, u8 channel
)
2612 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2613 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
2614 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
2615 u8 index
= (channel
- 1);
2617 bool in_24g
= false;
2618 s8 powerdiff_byrate
= 0;
2620 if (((rtlhal
->current_bandtype
== BAND_ON_2_4G
) &&
2621 (channel
> 14 || channel
< 1)) ||
2622 ((rtlhal
->current_bandtype
== BAND_ON_5G
) && (channel
<= 14))) {
2624 rtl_dbg(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
,
2625 "Illegal channel!!\n");
2628 in_24g
= _rtl8821ae_phy_get_chnl_index(channel
, &index
);
2630 if (RTL8821AE_RX_HAL_IS_CCK_RATE(rate
))
2631 txpower
= rtlefuse
->txpwrlevel_cck
[path
][index
];
2632 else if (DESC_RATE6M
<= rate
)
2633 txpower
= rtlefuse
->txpwrlevel_ht40_1s
[path
][index
];
2635 rtl_dbg(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
, "invalid rate\n");
2637 if (DESC_RATE6M
<= rate
&& rate
<= DESC_RATE54M
&&
2638 !RTL8821AE_RX_HAL_IS_CCK_RATE(rate
))
2639 txpower
+= rtlefuse
->txpwr_legacyhtdiff
[path
][TX_1S
];
2641 if (bandwidth
== HT_CHANNEL_WIDTH_20
) {
2642 if ((DESC_RATEMCS0
<= rate
&& rate
<= DESC_RATEMCS15
) ||
2643 (DESC_RATEVHT1SS_MCS0
<= rate
&& rate
<= DESC_RATEVHT2SS_MCS9
))
2644 txpower
+= rtlefuse
->txpwr_ht20diff
[path
][TX_1S
];
2645 if ((DESC_RATEMCS8
<= rate
&& rate
<= DESC_RATEMCS15
) ||
2646 (DESC_RATEVHT2SS_MCS0
<= rate
&& rate
<= DESC_RATEVHT2SS_MCS9
))
2647 txpower
+= rtlefuse
->txpwr_ht20diff
[path
][TX_2S
];
2648 } else if (bandwidth
== HT_CHANNEL_WIDTH_20_40
) {
2649 if ((DESC_RATEMCS0
<= rate
&& rate
<= DESC_RATEMCS15
) ||
2650 (DESC_RATEVHT1SS_MCS0
<= rate
&& rate
<= DESC_RATEVHT2SS_MCS9
))
2651 txpower
+= rtlefuse
->txpwr_ht40diff
[path
][TX_1S
];
2652 if ((DESC_RATEMCS8
<= rate
&& rate
<= DESC_RATEMCS15
) ||
2653 (DESC_RATEVHT2SS_MCS0
<= rate
&& rate
<= DESC_RATEVHT2SS_MCS9
))
2654 txpower
+= rtlefuse
->txpwr_ht40diff
[path
][TX_2S
];
2655 } else if (bandwidth
== HT_CHANNEL_WIDTH_80
) {
2656 if ((DESC_RATEMCS0
<= rate
&& rate
<= DESC_RATEMCS15
) ||
2657 (DESC_RATEVHT1SS_MCS0
<= rate
&&
2658 rate
<= DESC_RATEVHT2SS_MCS9
))
2659 txpower
+= rtlefuse
->txpwr_ht40diff
[path
][TX_1S
];
2660 if ((DESC_RATEMCS8
<= rate
&& rate
<= DESC_RATEMCS15
) ||
2661 (DESC_RATEVHT2SS_MCS0
<= rate
&&
2662 rate
<= DESC_RATEVHT2SS_MCS9
))
2663 txpower
+= rtlefuse
->txpwr_ht40diff
[path
][TX_2S
];
2666 if (DESC_RATE6M
<= rate
)
2667 txpower
= rtlefuse
->txpwr_5g_bw40base
[path
][index
];
2669 rtl_dbg(rtlpriv
, COMP_POWER_TRACKING
, DBG_WARNING
,
2672 if (DESC_RATE6M
<= rate
&& rate
<= DESC_RATE54M
&&
2673 !RTL8821AE_RX_HAL_IS_CCK_RATE(rate
))
2674 txpower
+= rtlefuse
->txpwr_5g_ofdmdiff
[path
][TX_1S
];
2676 if (bandwidth
== HT_CHANNEL_WIDTH_20
) {
2677 if ((DESC_RATEMCS0
<= rate
&& rate
<= DESC_RATEMCS15
) ||
2678 (DESC_RATEVHT1SS_MCS0
<= rate
&&
2679 rate
<= DESC_RATEVHT2SS_MCS9
))
2680 txpower
+= rtlefuse
->txpwr_5g_bw20diff
[path
][TX_1S
];
2681 if ((DESC_RATEMCS8
<= rate
&& rate
<= DESC_RATEMCS15
) ||
2682 (DESC_RATEVHT2SS_MCS0
<= rate
&&
2683 rate
<= DESC_RATEVHT2SS_MCS9
))
2684 txpower
+= rtlefuse
->txpwr_5g_bw20diff
[path
][TX_2S
];
2685 } else if (bandwidth
== HT_CHANNEL_WIDTH_20_40
) {
2686 if ((DESC_RATEMCS0
<= rate
&& rate
<= DESC_RATEMCS15
) ||
2687 (DESC_RATEVHT1SS_MCS0
<= rate
&&
2688 rate
<= DESC_RATEVHT2SS_MCS9
))
2689 txpower
+= rtlefuse
->txpwr_5g_bw40diff
[path
][TX_1S
];
2690 if ((DESC_RATEMCS8
<= rate
&& rate
<= DESC_RATEMCS15
) ||
2691 (DESC_RATEVHT2SS_MCS0
<= rate
&&
2692 rate
<= DESC_RATEVHT2SS_MCS9
))
2693 txpower
+= rtlefuse
->txpwr_5g_bw40diff
[path
][TX_2S
];
2694 } else if (bandwidth
== HT_CHANNEL_WIDTH_80
) {
2697 for (i
= 0; i
< sizeof(channel5g_80m
) / sizeof(u8
); ++i
)
2698 if (channel5g_80m
[i
] == channel
)
2701 if ((DESC_RATEMCS0
<= rate
&& rate
<= DESC_RATEMCS15
) ||
2702 (DESC_RATEVHT1SS_MCS0
<= rate
&&
2703 rate
<= DESC_RATEVHT2SS_MCS9
))
2704 txpower
= rtlefuse
->txpwr_5g_bw80base
[path
][index
]
2705 + rtlefuse
->txpwr_5g_bw80diff
[path
][TX_1S
];
2706 if ((DESC_RATEMCS8
<= rate
&& rate
<= DESC_RATEMCS15
) ||
2707 (DESC_RATEVHT2SS_MCS0
<= rate
&&
2708 rate
<= DESC_RATEVHT2SS_MCS9
))
2709 txpower
= rtlefuse
->txpwr_5g_bw80base
[path
][index
]
2710 + rtlefuse
->txpwr_5g_bw80diff
[path
][TX_1S
]
2711 + rtlefuse
->txpwr_5g_bw80diff
[path
][TX_2S
];
2714 if (rtlefuse
->eeprom_regulatory
!= 2)
2716 _rtl8821ae_phy_get_txpower_by_rate(hw
, (u8
)(!in_24g
),
2719 if (rate
== DESC_RATEVHT1SS_MCS8
|| rate
== DESC_RATEVHT1SS_MCS9
||
2720 rate
== DESC_RATEVHT2SS_MCS8
|| rate
== DESC_RATEVHT2SS_MCS9
)
2721 txpower
-= powerdiff_byrate
;
2723 txpower
+= powerdiff_byrate
;
2725 if (rate
> DESC_RATE11M
)
2726 txpower
+= rtlpriv
->dm
.remnant_ofdm_swing_idx
[path
];
2728 txpower
+= rtlpriv
->dm
.remnant_cck_idx
;
2730 if (txpower
> MAX_POWER_INDEX
)
2731 txpower
= MAX_POWER_INDEX
;
2736 static void _rtl8821ae_phy_set_txpower_index(struct ieee80211_hw
*hw
,
2737 u8 power_index
, u8 path
, u8 rate
)
2739 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2741 if (path
== RF90_PATH_A
) {
2744 rtl_set_bbreg(hw
, RTXAGC_A_CCK11_CCK1
,
2745 MASKBYTE0
, power_index
);
2748 rtl_set_bbreg(hw
, RTXAGC_A_CCK11_CCK1
,
2749 MASKBYTE1
, power_index
);
2752 rtl_set_bbreg(hw
, RTXAGC_A_CCK11_CCK1
,
2753 MASKBYTE2
, power_index
);
2756 rtl_set_bbreg(hw
, RTXAGC_A_CCK11_CCK1
,
2757 MASKBYTE3
, power_index
);
2760 rtl_set_bbreg(hw
, RTXAGC_A_OFDM18_OFDM6
,
2761 MASKBYTE0
, power_index
);
2764 rtl_set_bbreg(hw
, RTXAGC_A_OFDM18_OFDM6
,
2765 MASKBYTE1
, power_index
);
2768 rtl_set_bbreg(hw
, RTXAGC_A_OFDM18_OFDM6
,
2769 MASKBYTE2
, power_index
);
2772 rtl_set_bbreg(hw
, RTXAGC_A_OFDM18_OFDM6
,
2773 MASKBYTE3
, power_index
);
2776 rtl_set_bbreg(hw
, RTXAGC_A_OFDM54_OFDM24
,
2777 MASKBYTE0
, power_index
);
2780 rtl_set_bbreg(hw
, RTXAGC_A_OFDM54_OFDM24
,
2781 MASKBYTE1
, power_index
);
2784 rtl_set_bbreg(hw
, RTXAGC_A_OFDM54_OFDM24
,
2785 MASKBYTE2
, power_index
);
2788 rtl_set_bbreg(hw
, RTXAGC_A_OFDM54_OFDM24
,
2789 MASKBYTE3
, power_index
);
2792 rtl_set_bbreg(hw
, RTXAGC_A_MCS03_MCS00
,
2793 MASKBYTE0
, power_index
);
2796 rtl_set_bbreg(hw
, RTXAGC_A_MCS03_MCS00
,
2797 MASKBYTE1
, power_index
);
2800 rtl_set_bbreg(hw
, RTXAGC_A_MCS03_MCS00
,
2801 MASKBYTE2
, power_index
);
2804 rtl_set_bbreg(hw
, RTXAGC_A_MCS03_MCS00
,
2805 MASKBYTE3
, power_index
);
2808 rtl_set_bbreg(hw
, RTXAGC_A_MCS07_MCS04
,
2809 MASKBYTE0
, power_index
);
2812 rtl_set_bbreg(hw
, RTXAGC_A_MCS07_MCS04
,
2813 MASKBYTE1
, power_index
);
2816 rtl_set_bbreg(hw
, RTXAGC_A_MCS07_MCS04
,
2817 MASKBYTE2
, power_index
);
2820 rtl_set_bbreg(hw
, RTXAGC_A_MCS07_MCS04
,
2821 MASKBYTE3
, power_index
);
2824 rtl_set_bbreg(hw
, RTXAGC_A_MCS11_MCS08
,
2825 MASKBYTE0
, power_index
);
2828 rtl_set_bbreg(hw
, RTXAGC_A_MCS11_MCS08
,
2829 MASKBYTE1
, power_index
);
2831 case DESC_RATEMCS10
:
2832 rtl_set_bbreg(hw
, RTXAGC_A_MCS11_MCS08
,
2833 MASKBYTE2
, power_index
);
2835 case DESC_RATEMCS11
:
2836 rtl_set_bbreg(hw
, RTXAGC_A_MCS11_MCS08
,
2837 MASKBYTE3
, power_index
);
2839 case DESC_RATEMCS12
:
2840 rtl_set_bbreg(hw
, RTXAGC_A_MCS15_MCS12
,
2841 MASKBYTE0
, power_index
);
2843 case DESC_RATEMCS13
:
2844 rtl_set_bbreg(hw
, RTXAGC_A_MCS15_MCS12
,
2845 MASKBYTE1
, power_index
);
2847 case DESC_RATEMCS14
:
2848 rtl_set_bbreg(hw
, RTXAGC_A_MCS15_MCS12
,
2849 MASKBYTE2
, power_index
);
2851 case DESC_RATEMCS15
:
2852 rtl_set_bbreg(hw
, RTXAGC_A_MCS15_MCS12
,
2853 MASKBYTE3
, power_index
);
2855 case DESC_RATEVHT1SS_MCS0
:
2856 rtl_set_bbreg(hw
, RTXAGC_A_NSS1INDEX3_NSS1INDEX0
,
2857 MASKBYTE0
, power_index
);
2859 case DESC_RATEVHT1SS_MCS1
:
2860 rtl_set_bbreg(hw
, RTXAGC_A_NSS1INDEX3_NSS1INDEX0
,
2861 MASKBYTE1
, power_index
);
2863 case DESC_RATEVHT1SS_MCS2
:
2864 rtl_set_bbreg(hw
, RTXAGC_A_NSS1INDEX3_NSS1INDEX0
,
2865 MASKBYTE2
, power_index
);
2867 case DESC_RATEVHT1SS_MCS3
:
2868 rtl_set_bbreg(hw
, RTXAGC_A_NSS1INDEX3_NSS1INDEX0
,
2869 MASKBYTE3
, power_index
);
2871 case DESC_RATEVHT1SS_MCS4
:
2872 rtl_set_bbreg(hw
, RTXAGC_A_NSS1INDEX7_NSS1INDEX4
,
2873 MASKBYTE0
, power_index
);
2875 case DESC_RATEVHT1SS_MCS5
:
2876 rtl_set_bbreg(hw
, RTXAGC_A_NSS1INDEX7_NSS1INDEX4
,
2877 MASKBYTE1
, power_index
);
2879 case DESC_RATEVHT1SS_MCS6
:
2880 rtl_set_bbreg(hw
, RTXAGC_A_NSS1INDEX7_NSS1INDEX4
,
2881 MASKBYTE2
, power_index
);
2883 case DESC_RATEVHT1SS_MCS7
:
2884 rtl_set_bbreg(hw
, RTXAGC_A_NSS1INDEX7_NSS1INDEX4
,
2885 MASKBYTE3
, power_index
);
2887 case DESC_RATEVHT1SS_MCS8
:
2888 rtl_set_bbreg(hw
, RTXAGC_A_NSS2INDEX1_NSS1INDEX8
,
2889 MASKBYTE0
, power_index
);
2891 case DESC_RATEVHT1SS_MCS9
:
2892 rtl_set_bbreg(hw
, RTXAGC_A_NSS2INDEX1_NSS1INDEX8
,
2893 MASKBYTE1
, power_index
);
2895 case DESC_RATEVHT2SS_MCS0
:
2896 rtl_set_bbreg(hw
, RTXAGC_A_NSS2INDEX1_NSS1INDEX8
,
2897 MASKBYTE2
, power_index
);
2899 case DESC_RATEVHT2SS_MCS1
:
2900 rtl_set_bbreg(hw
, RTXAGC_A_NSS2INDEX1_NSS1INDEX8
,
2901 MASKBYTE3
, power_index
);
2903 case DESC_RATEVHT2SS_MCS2
:
2904 rtl_set_bbreg(hw
, RTXAGC_A_NSS2INDEX5_NSS2INDEX2
,
2905 MASKBYTE0
, power_index
);
2907 case DESC_RATEVHT2SS_MCS3
:
2908 rtl_set_bbreg(hw
, RTXAGC_A_NSS2INDEX5_NSS2INDEX2
,
2909 MASKBYTE1
, power_index
);
2911 case DESC_RATEVHT2SS_MCS4
:
2912 rtl_set_bbreg(hw
, RTXAGC_A_NSS2INDEX5_NSS2INDEX2
,
2913 MASKBYTE2
, power_index
);
2915 case DESC_RATEVHT2SS_MCS5
:
2916 rtl_set_bbreg(hw
, RTXAGC_A_NSS2INDEX5_NSS2INDEX2
,
2917 MASKBYTE3
, power_index
);
2919 case DESC_RATEVHT2SS_MCS6
:
2920 rtl_set_bbreg(hw
, RTXAGC_A_NSS2INDEX9_NSS2INDEX6
,
2921 MASKBYTE0
, power_index
);
2923 case DESC_RATEVHT2SS_MCS7
:
2924 rtl_set_bbreg(hw
, RTXAGC_A_NSS2INDEX9_NSS2INDEX6
,
2925 MASKBYTE1
, power_index
);
2927 case DESC_RATEVHT2SS_MCS8
:
2928 rtl_set_bbreg(hw
, RTXAGC_A_NSS2INDEX9_NSS2INDEX6
,
2929 MASKBYTE2
, power_index
);
2931 case DESC_RATEVHT2SS_MCS9
:
2932 rtl_set_bbreg(hw
, RTXAGC_A_NSS2INDEX9_NSS2INDEX6
,
2933 MASKBYTE3
, power_index
);
2936 rtl_dbg(rtlpriv
, COMP_POWER
, DBG_LOUD
,
2937 "Invalid Rate!!\n");
2940 } else if (path
== RF90_PATH_B
) {
2943 rtl_set_bbreg(hw
, RTXAGC_B_CCK11_CCK1
,
2944 MASKBYTE0
, power_index
);
2947 rtl_set_bbreg(hw
, RTXAGC_B_CCK11_CCK1
,
2948 MASKBYTE1
, power_index
);
2951 rtl_set_bbreg(hw
, RTXAGC_B_CCK11_CCK1
,
2952 MASKBYTE2
, power_index
);
2955 rtl_set_bbreg(hw
, RTXAGC_B_CCK11_CCK1
,
2956 MASKBYTE3
, power_index
);
2959 rtl_set_bbreg(hw
, RTXAGC_B_OFDM18_OFDM6
,
2960 MASKBYTE0
, power_index
);
2963 rtl_set_bbreg(hw
, RTXAGC_B_OFDM18_OFDM6
,
2964 MASKBYTE1
, power_index
);
2967 rtl_set_bbreg(hw
, RTXAGC_B_OFDM18_OFDM6
,
2968 MASKBYTE2
, power_index
);
2971 rtl_set_bbreg(hw
, RTXAGC_B_OFDM18_OFDM6
,
2972 MASKBYTE3
, power_index
);
2975 rtl_set_bbreg(hw
, RTXAGC_B_OFDM54_OFDM24
,
2976 MASKBYTE0
, power_index
);
2979 rtl_set_bbreg(hw
, RTXAGC_B_OFDM54_OFDM24
,
2980 MASKBYTE1
, power_index
);
2983 rtl_set_bbreg(hw
, RTXAGC_B_OFDM54_OFDM24
,
2984 MASKBYTE2
, power_index
);
2987 rtl_set_bbreg(hw
, RTXAGC_B_OFDM54_OFDM24
,
2988 MASKBYTE3
, power_index
);
2991 rtl_set_bbreg(hw
, RTXAGC_B_MCS03_MCS00
,
2992 MASKBYTE0
, power_index
);
2995 rtl_set_bbreg(hw
, RTXAGC_B_MCS03_MCS00
,
2996 MASKBYTE1
, power_index
);
2999 rtl_set_bbreg(hw
, RTXAGC_B_MCS03_MCS00
,
3000 MASKBYTE2
, power_index
);
3003 rtl_set_bbreg(hw
, RTXAGC_B_MCS03_MCS00
,
3004 MASKBYTE3
, power_index
);
3007 rtl_set_bbreg(hw
, RTXAGC_B_MCS07_MCS04
,
3008 MASKBYTE0
, power_index
);
3011 rtl_set_bbreg(hw
, RTXAGC_B_MCS07_MCS04
,
3012 MASKBYTE1
, power_index
);
3015 rtl_set_bbreg(hw
, RTXAGC_B_MCS07_MCS04
,
3016 MASKBYTE2
, power_index
);
3019 rtl_set_bbreg(hw
, RTXAGC_B_MCS07_MCS04
,
3020 MASKBYTE3
, power_index
);
3023 rtl_set_bbreg(hw
, RTXAGC_B_MCS11_MCS08
,
3024 MASKBYTE0
, power_index
);
3027 rtl_set_bbreg(hw
, RTXAGC_B_MCS11_MCS08
,
3028 MASKBYTE1
, power_index
);
3030 case DESC_RATEMCS10
:
3031 rtl_set_bbreg(hw
, RTXAGC_B_MCS11_MCS08
,
3032 MASKBYTE2
, power_index
);
3034 case DESC_RATEMCS11
:
3035 rtl_set_bbreg(hw
, RTXAGC_B_MCS11_MCS08
,
3036 MASKBYTE3
, power_index
);
3038 case DESC_RATEMCS12
:
3039 rtl_set_bbreg(hw
, RTXAGC_B_MCS15_MCS12
,
3040 MASKBYTE0
, power_index
);
3042 case DESC_RATEMCS13
:
3043 rtl_set_bbreg(hw
, RTXAGC_B_MCS15_MCS12
,
3044 MASKBYTE1
, power_index
);
3046 case DESC_RATEMCS14
:
3047 rtl_set_bbreg(hw
, RTXAGC_B_MCS15_MCS12
,
3048 MASKBYTE2
, power_index
);
3050 case DESC_RATEMCS15
:
3051 rtl_set_bbreg(hw
, RTXAGC_B_MCS15_MCS12
,
3052 MASKBYTE3
, power_index
);
3054 case DESC_RATEVHT1SS_MCS0
:
3055 rtl_set_bbreg(hw
, RTXAGC_B_NSS1INDEX3_NSS1INDEX0
,
3056 MASKBYTE0
, power_index
);
3058 case DESC_RATEVHT1SS_MCS1
:
3059 rtl_set_bbreg(hw
, RTXAGC_B_NSS1INDEX3_NSS1INDEX0
,
3060 MASKBYTE1
, power_index
);
3062 case DESC_RATEVHT1SS_MCS2
:
3063 rtl_set_bbreg(hw
, RTXAGC_B_NSS1INDEX3_NSS1INDEX0
,
3064 MASKBYTE2
, power_index
);
3066 case DESC_RATEVHT1SS_MCS3
:
3067 rtl_set_bbreg(hw
, RTXAGC_B_NSS1INDEX3_NSS1INDEX0
,
3068 MASKBYTE3
, power_index
);
3070 case DESC_RATEVHT1SS_MCS4
:
3071 rtl_set_bbreg(hw
, RTXAGC_B_NSS1INDEX7_NSS1INDEX4
,
3072 MASKBYTE0
, power_index
);
3074 case DESC_RATEVHT1SS_MCS5
:
3075 rtl_set_bbreg(hw
, RTXAGC_B_NSS1INDEX7_NSS1INDEX4
,
3076 MASKBYTE1
, power_index
);
3078 case DESC_RATEVHT1SS_MCS6
:
3079 rtl_set_bbreg(hw
, RTXAGC_B_NSS1INDEX7_NSS1INDEX4
,
3080 MASKBYTE2
, power_index
);
3082 case DESC_RATEVHT1SS_MCS7
:
3083 rtl_set_bbreg(hw
, RTXAGC_B_NSS1INDEX7_NSS1INDEX4
,
3084 MASKBYTE3
, power_index
);
3086 case DESC_RATEVHT1SS_MCS8
:
3087 rtl_set_bbreg(hw
, RTXAGC_B_NSS2INDEX1_NSS1INDEX8
,
3088 MASKBYTE0
, power_index
);
3090 case DESC_RATEVHT1SS_MCS9
:
3091 rtl_set_bbreg(hw
, RTXAGC_B_NSS2INDEX1_NSS1INDEX8
,
3092 MASKBYTE1
, power_index
);
3094 case DESC_RATEVHT2SS_MCS0
:
3095 rtl_set_bbreg(hw
, RTXAGC_B_NSS2INDEX1_NSS1INDEX8
,
3096 MASKBYTE2
, power_index
);
3098 case DESC_RATEVHT2SS_MCS1
:
3099 rtl_set_bbreg(hw
, RTXAGC_B_NSS2INDEX1_NSS1INDEX8
,
3100 MASKBYTE3
, power_index
);
3102 case DESC_RATEVHT2SS_MCS2
:
3103 rtl_set_bbreg(hw
, RTXAGC_B_NSS2INDEX5_NSS2INDEX2
,
3104 MASKBYTE0
, power_index
);
3106 case DESC_RATEVHT2SS_MCS3
:
3107 rtl_set_bbreg(hw
, RTXAGC_B_NSS2INDEX5_NSS2INDEX2
,
3108 MASKBYTE1
, power_index
);
3110 case DESC_RATEVHT2SS_MCS4
:
3111 rtl_set_bbreg(hw
, RTXAGC_B_NSS2INDEX5_NSS2INDEX2
,
3112 MASKBYTE2
, power_index
);
3114 case DESC_RATEVHT2SS_MCS5
:
3115 rtl_set_bbreg(hw
, RTXAGC_B_NSS2INDEX5_NSS2INDEX2
,
3116 MASKBYTE3
, power_index
);
3118 case DESC_RATEVHT2SS_MCS6
:
3119 rtl_set_bbreg(hw
, RTXAGC_B_NSS2INDEX9_NSS2INDEX6
,
3120 MASKBYTE0
, power_index
);
3122 case DESC_RATEVHT2SS_MCS7
:
3123 rtl_set_bbreg(hw
, RTXAGC_B_NSS2INDEX9_NSS2INDEX6
,
3124 MASKBYTE1
, power_index
);
3126 case DESC_RATEVHT2SS_MCS8
:
3127 rtl_set_bbreg(hw
, RTXAGC_B_NSS2INDEX9_NSS2INDEX6
,
3128 MASKBYTE2
, power_index
);
3130 case DESC_RATEVHT2SS_MCS9
:
3131 rtl_set_bbreg(hw
, RTXAGC_B_NSS2INDEX9_NSS2INDEX6
,
3132 MASKBYTE3
, power_index
);
3135 rtl_dbg(rtlpriv
, COMP_POWER
, DBG_LOUD
,
3136 "Invalid Rate!!\n");
3140 rtl_dbg(rtlpriv
, COMP_POWER
, DBG_LOUD
,
3141 "Invalid RFPath!!\n");
3145 static void _rtl8821ae_phy_set_txpower_level_by_path(struct ieee80211_hw
*hw
,
3147 u8 channel
, u8 size
)
3149 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3150 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
3154 for (i
= 0; i
< size
; i
++) {
3156 _rtl8821ae_get_txpower_index(hw
, path
, array
[i
],
3157 rtlphy
->current_chan_bw
,
3159 _rtl8821ae_phy_set_txpower_index(hw
, power_index
, path
,
3164 static void _rtl8821ae_phy_txpower_training_by_path(struct ieee80211_hw
*hw
,
3165 u8 bw
, u8 channel
, u8 path
)
3167 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3168 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
3171 u32 power_level
, data
, offset
;
3173 if (path
>= rtlphy
->num_total_rfpath
)
3177 if (path
== RF90_PATH_A
) {
3179 _rtl8821ae_get_txpower_index(hw
, RF90_PATH_A
,
3180 DESC_RATEMCS7
, bw
, channel
);
3181 offset
= RA_TXPWRTRAING
;
3184 _rtl8821ae_get_txpower_index(hw
, RF90_PATH_B
,
3185 DESC_RATEMCS7
, bw
, channel
);
3186 offset
= RB_TXPWRTRAING
;
3189 for (i
= 0; i
< 3; i
++) {
3191 power_level
= power_level
- 10;
3193 power_level
= power_level
- 8;
3195 power_level
= power_level
- 6;
3197 data
|= (((power_level
> 2) ? (power_level
) : 2) << (i
* 8));
3199 rtl_set_bbreg(hw
, offset
, 0xffffff, data
);
3202 void rtl8821ae_phy_set_txpower_level_by_path(struct ieee80211_hw
*hw
,
3203 u8 channel
, u8 path
)
3205 /* struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); */
3206 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3207 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3208 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
3209 u8 cck_rates
[] = {DESC_RATE1M
, DESC_RATE2M
, DESC_RATE5_5M
,
3211 u8 sizes_of_cck_retes
= 4;
3212 u8 ofdm_rates
[] = {DESC_RATE6M
, DESC_RATE9M
, DESC_RATE12M
,
3213 DESC_RATE18M
, DESC_RATE24M
, DESC_RATE36M
,
3214 DESC_RATE48M
, DESC_RATE54M
};
3215 u8 sizes_of_ofdm_retes
= 8;
3216 u8 ht_rates_1t
[] = {DESC_RATEMCS0
, DESC_RATEMCS1
, DESC_RATEMCS2
,
3217 DESC_RATEMCS3
, DESC_RATEMCS4
, DESC_RATEMCS5
,
3218 DESC_RATEMCS6
, DESC_RATEMCS7
};
3219 u8 sizes_of_ht_retes_1t
= 8;
3220 u8 ht_rates_2t
[] = {DESC_RATEMCS8
, DESC_RATEMCS9
,
3221 DESC_RATEMCS10
, DESC_RATEMCS11
,
3222 DESC_RATEMCS12
, DESC_RATEMCS13
,
3223 DESC_RATEMCS14
, DESC_RATEMCS15
};
3224 u8 sizes_of_ht_retes_2t
= 8;
3225 u8 vht_rates_1t
[] = {DESC_RATEVHT1SS_MCS0
, DESC_RATEVHT1SS_MCS1
,
3226 DESC_RATEVHT1SS_MCS2
, DESC_RATEVHT1SS_MCS3
,
3227 DESC_RATEVHT1SS_MCS4
, DESC_RATEVHT1SS_MCS5
,
3228 DESC_RATEVHT1SS_MCS6
, DESC_RATEVHT1SS_MCS7
,
3229 DESC_RATEVHT1SS_MCS8
, DESC_RATEVHT1SS_MCS9
};
3230 u8 vht_rates_2t
[] = {DESC_RATEVHT2SS_MCS0
, DESC_RATEVHT2SS_MCS1
,
3231 DESC_RATEVHT2SS_MCS2
, DESC_RATEVHT2SS_MCS3
,
3232 DESC_RATEVHT2SS_MCS4
, DESC_RATEVHT2SS_MCS5
,
3233 DESC_RATEVHT2SS_MCS6
, DESC_RATEVHT2SS_MCS7
,
3234 DESC_RATEVHT2SS_MCS8
, DESC_RATEVHT2SS_MCS9
};
3235 u8 sizes_of_vht_retes
= 10;
3237 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
)
3238 _rtl8821ae_phy_set_txpower_level_by_path(hw
, cck_rates
, path
, channel
,
3239 sizes_of_cck_retes
);
3241 _rtl8821ae_phy_set_txpower_level_by_path(hw
, ofdm_rates
, path
, channel
,
3242 sizes_of_ofdm_retes
);
3243 _rtl8821ae_phy_set_txpower_level_by_path(hw
, ht_rates_1t
, path
, channel
,
3244 sizes_of_ht_retes_1t
);
3245 _rtl8821ae_phy_set_txpower_level_by_path(hw
, vht_rates_1t
, path
, channel
,
3246 sizes_of_vht_retes
);
3248 if (rtlphy
->num_total_rfpath
>= 2) {
3249 _rtl8821ae_phy_set_txpower_level_by_path(hw
, ht_rates_2t
, path
,
3251 sizes_of_ht_retes_2t
);
3252 _rtl8821ae_phy_set_txpower_level_by_path(hw
, vht_rates_2t
, path
,
3254 sizes_of_vht_retes
);
3257 _rtl8821ae_phy_txpower_training_by_path(hw
, rtlphy
->current_chan_bw
,
3261 /*just in case, write txpower in DW, to reduce time*/
3262 void rtl8821ae_phy_set_txpower_level(struct ieee80211_hw
*hw
, u8 channel
)
3264 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3265 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
3268 for (path
= RF90_PATH_A
; path
< rtlphy
->num_total_rfpath
; ++path
)
3269 rtl8821ae_phy_set_txpower_level_by_path(hw
, channel
, path
);
3272 static long _rtl8821ae_phy_txpwr_idx_to_dbm(struct ieee80211_hw
*hw
,
3273 enum wireless_mode wirelessmode
,
3279 switch (wirelessmode
) {
3280 case WIRELESS_MODE_B
:
3283 case WIRELESS_MODE_G
:
3284 case WIRELESS_MODE_N_24G
:
3291 pwrout_dbm
= txpwridx
/ 2 + offset
;
3295 void rtl8821ae_phy_scan_operation_backup(struct ieee80211_hw
*hw
, u8 operation
)
3297 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3298 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3299 enum io_type iotype
= IO_CMD_PAUSE_BAND0_DM_BY_SCAN
;
3301 if (!is_hal_stop(rtlhal
)) {
3302 switch (operation
) {
3303 case SCAN_OPT_BACKUP_BAND0
:
3304 iotype
= IO_CMD_PAUSE_BAND0_DM_BY_SCAN
;
3305 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
3310 case SCAN_OPT_BACKUP_BAND1
:
3311 iotype
= IO_CMD_PAUSE_BAND1_DM_BY_SCAN
;
3312 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
3317 case SCAN_OPT_RESTORE
:
3318 iotype
= IO_CMD_RESUME_DM_BY_SCAN
;
3319 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
3324 pr_err("Unknown Scan Backup operation.\n");
3330 static void _rtl8821ae_phy_set_reg_bw(struct rtl_priv
*rtlpriv
, u8 bw
)
3332 u16 reg_rf_mode_bw
, tmp
= 0;
3334 reg_rf_mode_bw
= rtl_read_word(rtlpriv
, REG_TRXPTCL_CTL
);
3336 case HT_CHANNEL_WIDTH_20
:
3337 rtl_write_word(rtlpriv
, REG_TRXPTCL_CTL
, reg_rf_mode_bw
& 0xFE7F);
3339 case HT_CHANNEL_WIDTH_20_40
:
3340 tmp
= reg_rf_mode_bw
| BIT(7);
3341 rtl_write_word(rtlpriv
, REG_TRXPTCL_CTL
, tmp
& 0xFEFF);
3343 case HT_CHANNEL_WIDTH_80
:
3344 tmp
= reg_rf_mode_bw
| BIT(8);
3345 rtl_write_word(rtlpriv
, REG_TRXPTCL_CTL
, tmp
& 0xFF7F);
3348 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_WARNING
, "unknown Bandwidth: 0x%x\n", bw
);
3353 static u8
_rtl8821ae_phy_get_secondary_chnl(struct rtl_priv
*rtlpriv
)
3355 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
3356 struct rtl_mac
*mac
= rtl_mac(rtlpriv
);
3357 u8 sc_set_40
= 0, sc_set_20
= 0;
3359 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_80
) {
3360 if (mac
->cur_80_prime_sc
== PRIME_CHNL_OFFSET_LOWER
)
3361 sc_set_40
= VHT_DATA_SC_40_LOWER_OF_80MHZ
;
3362 else if (mac
->cur_80_prime_sc
== PRIME_CHNL_OFFSET_UPPER
)
3363 sc_set_40
= VHT_DATA_SC_40_UPPER_OF_80MHZ
;
3365 pr_err("SCMapping: Not Correct Primary40MHz Setting\n");
3367 if ((mac
->cur_40_prime_sc
== PRIME_CHNL_OFFSET_LOWER
) &&
3368 (mac
->cur_80_prime_sc
== HAL_PRIME_CHNL_OFFSET_LOWER
))
3369 sc_set_20
= VHT_DATA_SC_20_LOWEST_OF_80MHZ
;
3370 else if ((mac
->cur_40_prime_sc
== PRIME_CHNL_OFFSET_UPPER
) &&
3371 (mac
->cur_80_prime_sc
== HAL_PRIME_CHNL_OFFSET_LOWER
))
3372 sc_set_20
= VHT_DATA_SC_20_LOWER_OF_80MHZ
;
3373 else if ((mac
->cur_40_prime_sc
== PRIME_CHNL_OFFSET_LOWER
) &&
3374 (mac
->cur_80_prime_sc
== HAL_PRIME_CHNL_OFFSET_UPPER
))
3375 sc_set_20
= VHT_DATA_SC_20_UPPER_OF_80MHZ
;
3376 else if ((mac
->cur_40_prime_sc
== PRIME_CHNL_OFFSET_UPPER
) &&
3377 (mac
->cur_80_prime_sc
== HAL_PRIME_CHNL_OFFSET_UPPER
))
3378 sc_set_20
= VHT_DATA_SC_20_UPPERST_OF_80MHZ
;
3380 pr_err("SCMapping: Not Correct Primary40MHz Setting\n");
3381 } else if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20_40
) {
3382 if (mac
->cur_40_prime_sc
== PRIME_CHNL_OFFSET_UPPER
)
3383 sc_set_20
= VHT_DATA_SC_20_UPPER_OF_80MHZ
;
3384 else if (mac
->cur_40_prime_sc
== PRIME_CHNL_OFFSET_LOWER
)
3385 sc_set_20
= VHT_DATA_SC_20_LOWER_OF_80MHZ
;
3387 pr_err("SCMapping: Not Correct Primary40MHz Setting\n");
3389 return (sc_set_40
<< 4) | sc_set_20
;
3392 void rtl8821ae_phy_set_bw_mode_callback(struct ieee80211_hw
*hw
)
3394 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3395 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
3399 rtl_dbg(rtlpriv
, COMP_SCAN
, DBG_TRACE
,
3400 "Switch to %s bandwidth\n",
3401 (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20
?
3403 (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20_40
?
3404 "40MHz" : "80MHz")));
3406 _rtl8821ae_phy_set_reg_bw(rtlpriv
, rtlphy
->current_chan_bw
);
3407 sub_chnl
= _rtl8821ae_phy_get_secondary_chnl(rtlpriv
);
3408 rtl_write_byte(rtlpriv
, 0x0483, sub_chnl
);
3410 switch (rtlphy
->current_chan_bw
) {
3411 case HT_CHANNEL_WIDTH_20
:
3412 rtl_set_bbreg(hw
, RRFMOD
, 0x003003C3, 0x00300200);
3413 rtl_set_bbreg(hw
, RADC_BUF_CLK
, BIT(30), 0);
3415 if (rtlphy
->rf_type
== RF_2T2R
)
3416 rtl_set_bbreg(hw
, RL1PEAKTH
, 0x03C00000, 7);
3418 rtl_set_bbreg(hw
, RL1PEAKTH
, 0x03C00000, 8);
3420 case HT_CHANNEL_WIDTH_20_40
:
3421 rtl_set_bbreg(hw
, RRFMOD
, 0x003003C3, 0x00300201);
3422 rtl_set_bbreg(hw
, RADC_BUF_CLK
, BIT(30), 0);
3423 rtl_set_bbreg(hw
, RRFMOD
, 0x3C, sub_chnl
);
3424 rtl_set_bbreg(hw
, RCCAONSEC
, 0xf0000000, sub_chnl
);
3426 if (rtlphy
->reg_837
& BIT(2))
3429 if (rtlphy
->rf_type
== RF_2T2R
)
3434 /* 0x848[25:22] = 0x6 */
3435 rtl_set_bbreg(hw
, RL1PEAKTH
, 0x03C00000, l1pk_val
);
3437 if (sub_chnl
== VHT_DATA_SC_20_UPPER_OF_80MHZ
)
3438 rtl_set_bbreg(hw
, RCCK_SYSTEM
, BCCK_SYSTEM
, 1);
3440 rtl_set_bbreg(hw
, RCCK_SYSTEM
, BCCK_SYSTEM
, 0);
3443 case HT_CHANNEL_WIDTH_80
:
3444 /* 0x8ac[21,20,9:6,1,0]=8'b11100010 */
3445 rtl_set_bbreg(hw
, RRFMOD
, 0x003003C3, 0x00300202);
3447 rtl_set_bbreg(hw
, RADC_BUF_CLK
, BIT(30), 1);
3448 rtl_set_bbreg(hw
, RRFMOD
, 0x3C, sub_chnl
);
3449 rtl_set_bbreg(hw
, RCCAONSEC
, 0xf0000000, sub_chnl
);
3451 if (rtlphy
->reg_837
& BIT(2))
3454 if (rtlphy
->rf_type
== RF_2T2R
)
3459 rtl_set_bbreg(hw
, RL1PEAKTH
, 0x03C00000, l1pk_val
);
3463 pr_err("unknown bandwidth: %#X\n",
3464 rtlphy
->current_chan_bw
);
3468 rtl8812ae_fixspur(hw
, rtlphy
->current_chan_bw
, rtlphy
->current_channel
);
3470 rtl8821ae_phy_rf6052_set_bandwidth(hw
, rtlphy
->current_chan_bw
);
3471 rtlphy
->set_bwmode_inprogress
= false;
3473 rtl_dbg(rtlpriv
, COMP_SCAN
, DBG_LOUD
, "\n");
3476 void rtl8821ae_phy_set_bw_mode(struct ieee80211_hw
*hw
,
3477 enum nl80211_channel_type ch_type
)
3479 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3480 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
3481 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3482 u8 tmp_bw
= rtlphy
->current_chan_bw
;
3484 if (rtlphy
->set_bwmode_inprogress
)
3486 rtlphy
->set_bwmode_inprogress
= true;
3487 if ((!is_hal_stop(rtlhal
)) && !(RT_CANNOT_IO(hw
)))
3488 rtl8821ae_phy_set_bw_mode_callback(hw
);
3490 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_WARNING
,
3491 "FALSE driver sleep or unload\n");
3492 rtlphy
->set_bwmode_inprogress
= false;
3493 rtlphy
->current_chan_bw
= tmp_bw
;
3497 void rtl8821ae_phy_sw_chnl_callback(struct ieee80211_hw
*hw
)
3499 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3500 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3501 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
3502 u8 channel
= rtlphy
->current_channel
;
3506 rtl_dbg(rtlpriv
, COMP_SCAN
, DBG_TRACE
,
3507 "switch to channel%d\n", rtlphy
->current_channel
);
3508 if (is_hal_stop(rtlhal
))
3511 if (36 <= channel
&& channel
<= 48)
3513 else if (50 <= channel
&& channel
<= 64)
3515 else if (100 <= channel
&& channel
<= 116)
3517 else if (118 <= channel
)
3521 rtl_set_bbreg(hw
, RFC_AREA
, 0x1ffe0000, data
);
3523 for (path
= RF90_PATH_A
; path
< rtlphy
->num_total_rfpath
; path
++) {
3524 if (36 <= channel
&& channel
<= 64)
3526 else if (100 <= channel
&& channel
<= 140)
3528 else if (140 < channel
)
3532 rtl8821ae_phy_set_rf_reg(hw
, path
, RF_CHNLBW
,
3533 BIT(18)|BIT(17)|BIT(16)|BIT(9)|BIT(8), data
);
3535 rtl8821ae_phy_set_rf_reg(hw
, path
, RF_CHNLBW
,
3536 BMASKBYTE0
, channel
);
3539 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
3540 if (36 <= channel
&& channel
<= 64)
3544 rtl8821ae_phy_set_rf_reg(hw
, path
, RF_APK
,
3545 BRFREGOFFSETMASK
, data
);
3549 rtl_dbg(rtlpriv
, COMP_SCAN
, DBG_TRACE
, "\n");
3552 u8
rtl8821ae_phy_sw_chnl(struct ieee80211_hw
*hw
)
3554 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3555 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
3556 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3557 u32 timeout
= 1000, timecount
= 0;
3558 u8 channel
= rtlphy
->current_channel
;
3560 if (rtlphy
->sw_chnl_inprogress
)
3562 if (rtlphy
->set_bwmode_inprogress
)
3565 if ((is_hal_stop(rtlhal
)) || (RT_CANNOT_IO(hw
))) {
3566 rtl_dbg(rtlpriv
, COMP_CHAN
, DBG_LOUD
,
3567 "sw_chnl_inprogress false driver sleep or unload\n");
3570 while (rtlphy
->lck_inprogress
&& timecount
< timeout
) {
3575 if (rtlphy
->current_channel
> 14 && rtlhal
->current_bandtype
!= BAND_ON_5G
)
3576 rtl8821ae_phy_switch_wirelessband(hw
, BAND_ON_5G
);
3577 else if (rtlphy
->current_channel
<= 14 && rtlhal
->current_bandtype
!= BAND_ON_2_4G
)
3578 rtl8821ae_phy_switch_wirelessband(hw
, BAND_ON_2_4G
);
3580 rtlphy
->sw_chnl_inprogress
= true;
3584 rtl_dbg(rtlpriv
, COMP_SCAN
, DBG_TRACE
,
3585 "switch to channel%d, band type is %d\n",
3586 rtlphy
->current_channel
, rtlhal
->current_bandtype
);
3588 rtl8821ae_phy_sw_chnl_callback(hw
);
3590 rtl8821ae_dm_clear_txpower_tracking_state(hw
);
3591 rtl8821ae_phy_set_txpower_level(hw
, rtlphy
->current_channel
);
3593 rtl_dbg(rtlpriv
, COMP_SCAN
, DBG_TRACE
, "\n");
3594 rtlphy
->sw_chnl_inprogress
= false;
3598 u8
_rtl8812ae_get_right_chnl_place_for_iqk(u8 chnl
)
3600 static const u8 channel_all
[TARGET_CHNL_NUM_2G_5G_8812
] = {
3601 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
3602 14, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54,
3603 56, 58, 60, 62, 64, 100, 102, 104, 106, 108,
3604 110, 112, 114, 116, 118, 120, 122, 124, 126,
3605 128, 130, 132, 134, 136, 138, 140, 149, 151,
3606 153, 155, 157, 159, 161, 163, 165};
3610 for (place
= 14; place
< sizeof(channel_all
); place
++)
3611 if (channel_all
[place
] == chnl
)
3618 #define MACBB_REG_NUM 10
3619 #define AFE_REG_NUM 14
3620 #define RF_REG_NUM 3
3622 static void _rtl8821ae_iqk_backup_macbb(struct ieee80211_hw
*hw
,
3624 u32
*backup_macbb_reg
, u32 mac_bb_num
)
3626 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3629 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x0); /*[31] = 0 --> Page C*/
3630 /*save MACBB default value*/
3631 for (i
= 0; i
< mac_bb_num
; i
++)
3632 macbb_backup
[i
] = rtl_read_dword(rtlpriv
, backup_macbb_reg
[i
]);
3634 rtl_dbg(rtlpriv
, COMP_IQK
, DBG_LOUD
, "BackupMacBB Success!!!!\n");
3637 static void _rtl8821ae_iqk_backup_afe(struct ieee80211_hw
*hw
, u32
*afe_backup
,
3638 u32
*backup_afe_REG
, u32 afe_num
)
3640 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3643 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x0); /*[31] = 0 --> Page C*/
3644 /*Save AFE Parameters */
3645 for (i
= 0; i
< afe_num
; i
++)
3646 afe_backup
[i
] = rtl_read_dword(rtlpriv
, backup_afe_REG
[i
]);
3647 rtl_dbg(rtlpriv
, COMP_IQK
, DBG_LOUD
, "BackupAFE Success!!!!\n");
3650 static void _rtl8821ae_iqk_backup_rf(struct ieee80211_hw
*hw
, u32
*rfa_backup
,
3651 u32
*rfb_backup
, u32
*backup_rf_reg
,
3654 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3657 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x0); /*[31] = 0 --> Page C*/
3658 /*Save RF Parameters*/
3659 for (i
= 0; i
< rf_num
; i
++) {
3660 rfa_backup
[i
] = rtl_get_rfreg(hw
, RF90_PATH_A
, backup_rf_reg
[i
],
3662 rfb_backup
[i
] = rtl_get_rfreg(hw
, RF90_PATH_B
, backup_rf_reg
[i
],
3665 rtl_dbg(rtlpriv
, COMP_IQK
, DBG_LOUD
, "BackupRF Success!!!!\n");
3668 static void _rtl8821ae_iqk_configure_mac(
3669 struct ieee80211_hw
*hw
3672 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3673 /* ========MAC register setting========*/
3674 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x0); /*[31] = 0 --> Page C*/
3675 rtl_write_byte(rtlpriv
, 0x522, 0x3f);
3676 rtl_set_bbreg(hw
, 0x550, BIT(11) | BIT(3), 0x0);
3677 rtl_write_byte(rtlpriv
, 0x808, 0x00); /*RX ante off*/
3678 rtl_set_bbreg(hw
, 0x838, 0xf, 0xc); /*CCA off*/
3681 static void _rtl8821ae_iqk_tx_fill_iqc(struct ieee80211_hw
*hw
,
3682 enum radio_path path
, u32 tx_x
, u32 tx_y
)
3684 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3687 /* [31] = 1 --> Page C1 */
3688 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x1);
3689 rtl_write_dword(rtlpriv
, 0xc90, 0x00000080);
3690 rtl_write_dword(rtlpriv
, 0xcc4, 0x20040000);
3691 rtl_write_dword(rtlpriv
, 0xcc8, 0x20000000);
3692 rtl_set_bbreg(hw
, 0xccc, 0x000007ff, tx_y
);
3693 rtl_set_bbreg(hw
, 0xcd4, 0x000007ff, tx_x
);
3694 rtl_dbg(rtlpriv
, COMP_IQK
, DBG_LOUD
,
3695 "TX_X = %x;;TX_Y = %x =====> fill to IQC\n",
3697 rtl_dbg(rtlpriv
, COMP_IQK
, DBG_LOUD
,
3698 "0xcd4 = %x;;0xccc = %x ====>fill to IQC\n",
3699 rtl_get_bbreg(hw
, 0xcd4, 0x000007ff),
3700 rtl_get_bbreg(hw
, 0xccc, 0x000007ff));
3707 static void _rtl8821ae_iqk_rx_fill_iqc(struct ieee80211_hw
*hw
,
3708 enum radio_path path
, u32 rx_x
, u32 rx_y
)
3710 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3713 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x0); /* [31] = 0 --> Page C */
3714 rtl_set_bbreg(hw
, 0xc10, 0x000003ff, rx_x
>>1);
3715 rtl_set_bbreg(hw
, 0xc10, 0x03ff0000, rx_y
>>1);
3716 rtl_dbg(rtlpriv
, COMP_IQK
, DBG_LOUD
,
3717 "rx_x = %x;;rx_y = %x ====>fill to IQC\n",
3718 rx_x
>> 1, rx_y
>> 1);
3719 rtl_dbg(rtlpriv
, COMP_IQK
, DBG_LOUD
,
3720 "0xc10 = %x ====>fill to IQC\n",
3721 rtl_read_dword(rtlpriv
, 0xc10));
3730 static void _rtl8821ae_iqk_tx(struct ieee80211_hw
*hw
, enum radio_path path
)
3732 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3733 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
3734 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3736 u32 tx_fail
, rx_fail
, delay_count
, iqk_ready
, cal_retry
, cal
= 0, temp_reg65
;
3737 int tx_x
= 0, tx_y
= 0, rx_x
= 0, rx_y
= 0, tx_average
= 0, rx_average
= 0;
3738 int tx_x0
[cal_num
], tx_y0
[cal_num
], tx_x0_rxk
[cal_num
],
3739 tx_y0_rxk
[cal_num
], rx_x0
[cal_num
], rx_y0
[cal_num
],
3740 tx_dt
[cal_num
], rx_dt
[cal_num
];
3741 bool tx0iqkok
= false, rx0iqkok
= false;
3742 bool vdf_enable
= false;
3743 int i
, k
, vdf_y
[3], vdf_x
[3],
3744 ii
, dx
= 0, dy
= 0, tx_finish
= 0, rx_finish
= 0;
3746 rtl_dbg(rtlpriv
, COMP_IQK
, DBG_LOUD
,
3747 "BandWidth = %d.\n",
3748 rtlphy
->current_chan_bw
);
3749 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_80
)
3752 while (cal
< cal_num
) {
3755 temp_reg65
= rtl_get_rfreg(hw
, path
, 0x65, 0xffffffff);
3757 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x0); /*[31] = 0 --> Page C*/
3758 /*========Path-A AFE all on========*/
3759 /*Port 0 DAC/ADC on*/
3760 rtl_write_dword(rtlpriv
, 0xc60, 0x77777777);
3761 rtl_write_dword(rtlpriv
, 0xc64, 0x77777777);
3762 rtl_write_dword(rtlpriv
, 0xc68, 0x19791979);
3763 rtl_write_dword(rtlpriv
, 0xc6c, 0x19791979);
3764 rtl_write_dword(rtlpriv
, 0xc70, 0x19791979);
3765 rtl_write_dword(rtlpriv
, 0xc74, 0x19791979);
3766 rtl_write_dword(rtlpriv
, 0xc78, 0x19791979);
3767 rtl_write_dword(rtlpriv
, 0xc7c, 0x19791979);
3768 rtl_write_dword(rtlpriv
, 0xc80, 0x19791979);
3769 rtl_write_dword(rtlpriv
, 0xc84, 0x19791979);
3771 rtl_set_bbreg(hw
, 0xc00, 0xf, 0x4); /*hardware 3-wire off*/
3774 /* ====== LOK ====== */
3775 /*DAC/ADC sampling rate (160 MHz)*/
3776 rtl_set_bbreg(hw
, 0xc5c, BIT(26) | BIT(25) | BIT(24), 0x7);
3778 /* 2. LoK RF Setting (at BW = 20M) */
3779 rtl_set_rfreg(hw
, path
, 0xef, RFREG_OFFSET_MASK
, 0x80002);
3780 rtl_set_rfreg(hw
, path
, 0x18, 0x00c00, 0x3); /* BW 20M */
3781 rtl_set_rfreg(hw
, path
, 0x30, RFREG_OFFSET_MASK
, 0x20000);
3782 rtl_set_rfreg(hw
, path
, 0x31, RFREG_OFFSET_MASK
, 0x0003f);
3783 rtl_set_rfreg(hw
, path
, 0x32, RFREG_OFFSET_MASK
, 0xf3fc3);
3784 rtl_set_rfreg(hw
, path
, 0x65, RFREG_OFFSET_MASK
, 0x931d5);
3785 rtl_set_rfreg(hw
, path
, 0x8f, RFREG_OFFSET_MASK
, 0x8a001);
3786 rtl_set_bbreg(hw
, 0xcb8, 0xf, 0xd);
3787 rtl_write_dword(rtlpriv
, 0x90c, 0x00008000);
3788 rtl_write_dword(rtlpriv
, 0xb00, 0x03000100);
3789 rtl_set_bbreg(hw
, 0xc94, BIT(0), 0x1);
3790 rtl_write_dword(rtlpriv
, 0x978, 0x29002000);/* TX (X,Y) */
3791 rtl_write_dword(rtlpriv
, 0x97c, 0xa9002000);/* RX (X,Y) */
3792 rtl_write_dword(rtlpriv
, 0x984, 0x00462910);/* [0]:AGC_en, [15]:idac_K_Mask */
3794 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x1); /* [31] = 1 --> Page C1 */
3795 rtl_write_dword(rtlpriv
, 0xc88, 0x821403f4);
3797 if (rtlhal
->current_bandtype
)
3798 rtl_write_dword(rtlpriv
, 0xc8c, 0x68163e96);
3800 rtl_write_dword(rtlpriv
, 0xc8c, 0x28163e96);
3802 rtl_write_dword(rtlpriv
, 0xc80, 0x18008c10);/* TX_TONE_idx[9:0], TxK_Mask[29] TX_Tone = 16 */
3803 rtl_write_dword(rtlpriv
, 0xc84, 0x38008c10);/* RX_TONE_idx[9:0], RxK_Mask[29] */
3804 rtl_write_dword(rtlpriv
, 0xcb8, 0x00100000);/* cb8[20] \B1N SI/PI \A8Ï¥\CE\C5v\A4\C1\B5\B9 iqk_dpk module */
3805 rtl_write_dword(rtlpriv
, 0x980, 0xfa000000);
3806 rtl_write_dword(rtlpriv
, 0x980, 0xf8000000);
3808 mdelay(10); /* Delay 10ms */
3809 rtl_write_dword(rtlpriv
, 0xcb8, 0x00000000);
3811 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x0); /* [31] = 0 --> Page C */
3812 rtl_set_rfreg(hw
, path
, 0x58, 0x7fe00, rtl_get_rfreg(hw
, path
, 0x8, 0xffc00)); /* Load LOK */
3814 switch (rtlphy
->current_chan_bw
) {
3816 rtl_set_rfreg(hw
, path
, 0x18, 0x00c00, 0x1);
3819 rtl_set_rfreg(hw
, path
, 0x18, 0x00c00, 0x0);
3825 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x1); /* [31] = 1 --> Page C1 */
3827 /* 3. TX RF Setting */
3828 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x0); /* [31] = 0 --> Page C */
3829 rtl_set_rfreg(hw
, path
, 0xef, RFREG_OFFSET_MASK
, 0x80000);
3830 rtl_set_rfreg(hw
, path
, 0x30, RFREG_OFFSET_MASK
, 0x20000);
3831 rtl_set_rfreg(hw
, path
, 0x31, RFREG_OFFSET_MASK
, 0x0003f);
3832 rtl_set_rfreg(hw
, path
, 0x32, RFREG_OFFSET_MASK
, 0xf3fc3);
3833 rtl_set_rfreg(hw
, path
, 0x65, RFREG_OFFSET_MASK
, 0x931d5);
3834 rtl_set_rfreg(hw
, path
, 0x8f, RFREG_OFFSET_MASK
, 0x8a001);
3835 rtl_set_rfreg(hw
, path
, 0xef, RFREG_OFFSET_MASK
, 0x00000);
3836 /* ODM_SetBBReg(pDM_Odm, 0xcb8, 0xf, 0xd); */
3837 rtl_write_dword(rtlpriv
, 0x90c, 0x00008000);
3838 rtl_write_dword(rtlpriv
, 0xb00, 0x03000100);
3839 rtl_set_bbreg(hw
, 0xc94, BIT(0), 0x1);
3840 rtl_write_dword(rtlpriv
, 0x978, 0x29002000);/* TX (X,Y) */
3841 rtl_write_dword(rtlpriv
, 0x97c, 0xa9002000);/* RX (X,Y) */
3842 rtl_write_dword(rtlpriv
, 0x984, 0x0046a910);/* [0]:AGC_en, [15]:idac_K_Mask */
3844 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x1); /* [31] = 1 --> Page C1 */
3845 rtl_write_dword(rtlpriv
, 0xc88, 0x821403f1);
3846 if (rtlhal
->current_bandtype
)
3847 rtl_write_dword(rtlpriv
, 0xc8c, 0x40163e96);
3849 rtl_write_dword(rtlpriv
, 0xc8c, 0x00163e96);
3851 if (vdf_enable
== 1) {
3852 rtl_dbg(rtlpriv
, COMP_IQK
, DBG_LOUD
, "VDF_enable\n");
3853 for (k
= 0; k
<= 2; k
++) {
3856 rtl_write_dword(rtlpriv
, 0xc80, 0x18008c38);/* TX_TONE_idx[9:0], TxK_Mask[29] TX_Tone = 16 */
3857 rtl_write_dword(rtlpriv
, 0xc84, 0x38008c38);/* RX_TONE_idx[9:0], RxK_Mask[29] */
3858 rtl_set_bbreg(hw
, 0xce8, BIT(31), 0x0);
3861 rtl_set_bbreg(hw
, 0xc80, BIT(28), 0x0);
3862 rtl_set_bbreg(hw
, 0xc84, BIT(28), 0x0);
3863 rtl_set_bbreg(hw
, 0xce8, BIT(31), 0x0);
3866 rtl_dbg(rtlpriv
, COMP_IQK
, DBG_LOUD
,
3867 "vdf_y[1] = %x;;;vdf_y[0] = %x\n", vdf_y
[1]>>21 & 0x00007ff, vdf_y
[0]>>21 & 0x00007ff);
3868 rtl_dbg(rtlpriv
, COMP_IQK
, DBG_LOUD
,
3869 "vdf_x[1] = %x;;;vdf_x[0] = %x\n", vdf_x
[1]>>21 & 0x00007ff, vdf_x
[0]>>21 & 0x00007ff);
3870 tx_dt
[cal
] = (vdf_y
[1]>>20)-(vdf_y
[0]>>20);
3871 tx_dt
[cal
] = ((16*tx_dt
[cal
])*10000/15708);
3872 tx_dt
[cal
] = (tx_dt
[cal
] >> 1)+(tx_dt
[cal
] & BIT(0));
3873 rtl_write_dword(rtlpriv
, 0xc80, 0x18008c20);/* TX_TONE_idx[9:0], TxK_Mask[29] TX_Tone = 16 */
3874 rtl_write_dword(rtlpriv
, 0xc84, 0x38008c20);/* RX_TONE_idx[9:0], RxK_Mask[29] */
3875 rtl_set_bbreg(hw
, 0xce8, BIT(31), 0x1);
3876 rtl_set_bbreg(hw
, 0xce8, 0x3fff0000, tx_dt
[cal
] & 0x00003fff);
3881 rtl_write_dword(rtlpriv
, 0xcb8, 0x00100000);/* cb8[20] \B1N SI/PI \A8Ï¥\CE\C5v\A4\C1\B5\B9 iqk_dpk module */
3885 rtl_write_dword(rtlpriv
, 0x980, 0xfa000000);
3886 rtl_write_dword(rtlpriv
, 0x980, 0xf8000000);
3888 mdelay(10); /* Delay 10ms */
3889 rtl_write_dword(rtlpriv
, 0xcb8, 0x00000000);
3892 iqk_ready
= rtl_get_bbreg(hw
, 0xd00, BIT(10));
3893 if ((~iqk_ready
) || (delay_count
> 20))
3901 if (delay_count
< 20) { /* If 20ms No Result, then cal_retry++ */
3902 /* ============TXIQK Check============== */
3903 tx_fail
= rtl_get_bbreg(hw
, 0xd00, BIT(12));
3906 rtl_write_dword(rtlpriv
, 0xcb8, 0x02000000);
3907 vdf_x
[k
] = rtl_get_bbreg(hw
, 0xd00, 0x07ff0000)<<21;
3908 rtl_write_dword(rtlpriv
, 0xcb8, 0x04000000);
3909 vdf_y
[k
] = rtl_get_bbreg(hw
, 0xd00, 0x07ff0000)<<21;
3913 rtl_set_bbreg(hw
, 0xccc, 0x000007ff, 0x0);
3914 rtl_set_bbreg(hw
, 0xcd4, 0x000007ff, 0x200);
3917 if (cal_retry
== 10)
3923 if (cal_retry
== 10)
3929 tx_x0
[cal
] = vdf_x
[k
-1];
3930 tx_y0
[cal
] = vdf_y
[k
-1];
3933 rtl_write_dword(rtlpriv
, 0xc80, 0x18008c10);/* TX_TONE_idx[9:0], TxK_Mask[29] TX_Tone = 16 */
3934 rtl_write_dword(rtlpriv
, 0xc84, 0x38008c10);/* RX_TONE_idx[9:0], RxK_Mask[29] */
3935 rtl_write_dword(rtlpriv
, 0xcb8, 0x00100000);/* cb8[20] \B1N SI/PI \A8Ï¥\CE\C5v\A4\C1\B5\B9 iqk_dpk module */
3939 rtl_write_dword(rtlpriv
, 0x980, 0xfa000000);
3940 rtl_write_dword(rtlpriv
, 0x980, 0xf8000000);
3942 mdelay(10); /* Delay 10ms */
3943 rtl_write_dword(rtlpriv
, 0xcb8, 0x00000000);
3946 iqk_ready
= rtl_get_bbreg(hw
, 0xd00, BIT(10));
3947 if ((~iqk_ready
) || (delay_count
> 20))
3955 if (delay_count
< 20) { /* If 20ms No Result, then cal_retry++ */
3956 /* ============TXIQK Check============== */
3957 tx_fail
= rtl_get_bbreg(hw
, 0xd00, BIT(12));
3960 rtl_write_dword(rtlpriv
, 0xcb8, 0x02000000);
3961 tx_x0
[cal
] = rtl_get_bbreg(hw
, 0xd00, 0x07ff0000)<<21;
3962 rtl_write_dword(rtlpriv
, 0xcb8, 0x04000000);
3963 tx_y0
[cal
] = rtl_get_bbreg(hw
, 0xd00, 0x07ff0000)<<21;
3967 rtl_set_bbreg(hw
, 0xccc, 0x000007ff, 0x0);
3968 rtl_set_bbreg(hw
, 0xcd4, 0x000007ff, 0x200);
3971 if (cal_retry
== 10)
3977 if (cal_retry
== 10)
3983 if (tx0iqkok
== false)
3984 break; /* TXK fail, Don't do RXK */
3986 if (vdf_enable
== 1) {
3987 rtl_set_bbreg(hw
, 0xce8, BIT(31), 0x0); /* TX VDF Disable */
3988 rtl_dbg(rtlpriv
, COMP_IQK
, DBG_LOUD
, "RXVDF Start\n");
3989 for (k
= 0; k
<= 2; k
++) {
3990 /* ====== RX mode TXK (RXK Step 1) ====== */
3991 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x0); /* [31] = 0 --> Page C */
3992 /* 1. TX RF Setting */
3993 rtl_set_rfreg(hw
, path
, 0xef, RFREG_OFFSET_MASK
, 0x80000);
3994 rtl_set_rfreg(hw
, path
, 0x30, RFREG_OFFSET_MASK
, 0x30000);
3995 rtl_set_rfreg(hw
, path
, 0x31, RFREG_OFFSET_MASK
, 0x00029);
3996 rtl_set_rfreg(hw
, path
, 0x32, RFREG_OFFSET_MASK
, 0xd7ffb);
3997 rtl_set_rfreg(hw
, path
, 0x65, RFREG_OFFSET_MASK
, temp_reg65
);
3998 rtl_set_rfreg(hw
, path
, 0x8f, RFREG_OFFSET_MASK
, 0x8a001);
3999 rtl_set_rfreg(hw
, path
, 0xef, RFREG_OFFSET_MASK
, 0x00000);
4001 rtl_set_bbreg(hw
, 0xcb8, 0xf, 0xd);
4002 rtl_write_dword(rtlpriv
, 0x978, 0x29002000);/* TX (X,Y) */
4003 rtl_write_dword(rtlpriv
, 0x97c, 0xa9002000);/* RX (X,Y) */
4004 rtl_write_dword(rtlpriv
, 0x984, 0x0046a910);/* [0]:AGC_en, [15]:idac_K_Mask */
4005 rtl_write_dword(rtlpriv
, 0x90c, 0x00008000);
4006 rtl_write_dword(rtlpriv
, 0xb00, 0x03000100);
4007 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x1); /* [31] = 1 --> Page C1 */
4011 rtl_write_dword(rtlpriv
, 0xc80, 0x18008c38);/* TX_TONE_idx[9:0], TxK_Mask[29] TX_Tone = 16 */
4012 rtl_write_dword(rtlpriv
, 0xc84, 0x38008c38);/* RX_TONE_idx[9:0], RxK_Mask[29] */
4013 rtl_set_bbreg(hw
, 0xce8, BIT(30), 0x0);
4018 rtl_write_dword(rtlpriv
, 0xc80, 0x08008c38);/* TX_TONE_idx[9:0], TxK_Mask[29] TX_Tone = 16 */
4019 rtl_write_dword(rtlpriv
, 0xc84, 0x28008c38);/* RX_TONE_idx[9:0], RxK_Mask[29] */
4020 rtl_set_bbreg(hw
, 0xce8, BIT(30), 0x0);
4025 rtl_dbg(rtlpriv
, COMP_IQK
, DBG_LOUD
,
4026 "VDF_Y[1] = %x;;;VDF_Y[0] = %x\n",
4027 vdf_y
[1] >> 21 & 0x00007ff,
4028 vdf_y
[0] >> 21 & 0x00007ff);
4029 rtl_dbg(rtlpriv
, COMP_IQK
, DBG_LOUD
,
4030 "VDF_X[1] = %x;;;VDF_X[0] = %x\n",
4031 vdf_x
[1] >> 21 & 0x00007ff,
4032 vdf_x
[0] >> 21 & 0x00007ff);
4033 rx_dt
[cal
] = (vdf_y
[1]>>20)-(vdf_y
[0]>>20);
4034 rtl_dbg(rtlpriv
, COMP_IQK
, DBG_LOUD
, "Rx_dt = %d\n",
4036 rx_dt
[cal
] = ((16*rx_dt
[cal
])*10000/13823);
4037 rx_dt
[cal
] = (rx_dt
[cal
] >> 1)+(rx_dt
[cal
] & BIT(0));
4038 rtl_write_dword(rtlpriv
, 0xc80, 0x18008c20);/* TX_TONE_idx[9:0], TxK_Mask[29] TX_Tone = 16 */
4039 rtl_write_dword(rtlpriv
, 0xc84, 0x38008c20);/* RX_TONE_idx[9:0], RxK_Mask[29] */
4040 rtl_set_bbreg(hw
, 0xce8, 0x00003fff, rx_dt
[cal
] & 0x00003fff);
4046 rtl_write_dword(rtlpriv
, 0xc88, 0x821603e0);
4047 rtl_write_dword(rtlpriv
, 0xc8c, 0x68163e96);
4048 rtl_write_dword(rtlpriv
, 0xcb8, 0x00100000);/* cb8[20] \B1N SI/PI \A8Ï¥\CE\C5v\A4\C1\B5\B9 iqk_dpk module */
4052 rtl_write_dword(rtlpriv
, 0x980, 0xfa000000);
4053 rtl_write_dword(rtlpriv
, 0x980, 0xf8000000);
4055 mdelay(10); /* Delay 10ms */
4056 rtl_write_dword(rtlpriv
, 0xcb8, 0x00000000);
4059 iqk_ready
= rtl_get_bbreg(hw
, 0xd00, BIT(10));
4060 if ((~iqk_ready
) || (delay_count
> 20))
4068 if (delay_count
< 20) { /* If 20ms No Result, then cal_retry++ */
4069 /* ============TXIQK Check============== */
4070 tx_fail
= rtl_get_bbreg(hw
, 0xd00, BIT(12));
4073 rtl_write_dword(rtlpriv
, 0xcb8, 0x02000000);
4074 tx_x0_rxk
[cal
] = rtl_get_bbreg(hw
, 0xd00, 0x07ff0000)<<21;
4075 rtl_write_dword(rtlpriv
, 0xcb8, 0x04000000);
4076 tx_y0_rxk
[cal
] = rtl_get_bbreg(hw
, 0xd00, 0x07ff0000)<<21;
4082 if (cal_retry
== 10)
4088 if (cal_retry
== 10)
4093 if (tx0iqkok
== false) { /* If RX mode TXK fail, then take TXK Result */
4094 tx_x0_rxk
[cal
] = tx_x0
[cal
];
4095 tx_y0_rxk
[cal
] = tx_y0
[cal
];
4100 "RXK Step 1 fail\n");
4103 /* ====== RX IQK ====== */
4104 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x0); /* [31] = 0 --> Page C */
4105 /* 1. RX RF Setting */
4106 rtl_set_rfreg(hw
, path
, 0xef, RFREG_OFFSET_MASK
, 0x80000);
4107 rtl_set_rfreg(hw
, path
, 0x30, RFREG_OFFSET_MASK
, 0x30000);
4108 rtl_set_rfreg(hw
, path
, 0x31, RFREG_OFFSET_MASK
, 0x0002f);
4109 rtl_set_rfreg(hw
, path
, 0x32, RFREG_OFFSET_MASK
, 0xfffbb);
4110 rtl_set_rfreg(hw
, path
, 0x8f, RFREG_OFFSET_MASK
, 0x88001);
4111 rtl_set_rfreg(hw
, path
, 0x65, RFREG_OFFSET_MASK
, 0x931d8);
4112 rtl_set_rfreg(hw
, path
, 0xef, RFREG_OFFSET_MASK
, 0x00000);
4114 rtl_set_bbreg(hw
, 0x978, 0x03FF8000, (tx_x0_rxk
[cal
])>>21&0x000007ff);
4115 rtl_set_bbreg(hw
, 0x978, 0x000007FF, (tx_y0_rxk
[cal
])>>21&0x000007ff);
4116 rtl_set_bbreg(hw
, 0x978, BIT(31), 0x1);
4117 rtl_set_bbreg(hw
, 0x97c, BIT(31), 0x0);
4118 rtl_set_bbreg(hw
, 0xcb8, 0xF, 0xe);
4119 rtl_write_dword(rtlpriv
, 0x90c, 0x00008000);
4120 rtl_write_dword(rtlpriv
, 0x984, 0x0046a911);
4122 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x1); /* [31] = 1 --> Page C1 */
4123 rtl_set_bbreg(hw
, 0xc80, BIT(29), 0x1);
4124 rtl_set_bbreg(hw
, 0xc84, BIT(29), 0x0);
4125 rtl_write_dword(rtlpriv
, 0xc88, 0x02140119);
4127 rtl_write_dword(rtlpriv
, 0xc8c, 0x28160d00); /* pDM_Odm->SupportInterface == 1 */
4130 rtl_set_bbreg(hw
, 0xce8, BIT(30), 0x1); /* RX VDF Enable */
4131 rtl_write_dword(rtlpriv
, 0xcb8, 0x00100000);/* cb8[20] \B1N SI/PI \A8Ï¥\CE\C5v\A4\C1\B5\B9 iqk_dpk module */
4136 rtl_write_dword(rtlpriv
, 0x980, 0xfa000000);
4137 rtl_write_dword(rtlpriv
, 0x980, 0xf8000000);
4139 mdelay(10); /* Delay 10ms */
4140 rtl_write_dword(rtlpriv
, 0xcb8, 0x00000000);
4143 iqk_ready
= rtl_get_bbreg(hw
, 0xd00, BIT(10));
4144 if ((~iqk_ready
) || (delay_count
> 20))
4152 if (delay_count
< 20) { /* If 20ms No Result, then cal_retry++ */
4153 /* ============RXIQK Check============== */
4154 rx_fail
= rtl_get_bbreg(hw
, 0xd00, BIT(11));
4156 rtl_write_dword(rtlpriv
, 0xcb8, 0x06000000);
4157 vdf_x
[k
] = rtl_get_bbreg(hw
, 0xd00, 0x07ff0000)<<21;
4158 rtl_write_dword(rtlpriv
, 0xcb8, 0x08000000);
4159 vdf_y
[k
] = rtl_get_bbreg(hw
, 0xd00, 0x07ff0000)<<21;
4163 rtl_set_bbreg(hw
, 0xc10, 0x000003ff, 0x200>>1);
4164 rtl_set_bbreg(hw
, 0xc10, 0x03ff0000, 0x0>>1);
4167 if (cal_retry
== 10)
4174 if (cal_retry
== 10)
4181 rx_x0
[cal
] = vdf_x
[k
-1];
4182 rx_y0
[cal
] = vdf_y
[k
-1];
4184 rtl_set_bbreg(hw
, 0xce8, BIT(31), 0x1); /* TX VDF Enable */
4188 /* ====== RX mode TXK (RXK Step 1) ====== */
4189 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x0); /* [31] = 0 --> Page C */
4190 /* 1. TX RF Setting */
4191 rtl_set_rfreg(hw
, path
, 0xef, RFREG_OFFSET_MASK
, 0x80000);
4192 rtl_set_rfreg(hw
, path
, 0x30, RFREG_OFFSET_MASK
, 0x30000);
4193 rtl_set_rfreg(hw
, path
, 0x31, RFREG_OFFSET_MASK
, 0x00029);
4194 rtl_set_rfreg(hw
, path
, 0x32, RFREG_OFFSET_MASK
, 0xd7ffb);
4195 rtl_set_rfreg(hw
, path
, 0x65, RFREG_OFFSET_MASK
, temp_reg65
);
4196 rtl_set_rfreg(hw
, path
, 0x8f, RFREG_OFFSET_MASK
, 0x8a001);
4197 rtl_set_rfreg(hw
, path
, 0xef, RFREG_OFFSET_MASK
, 0x00000);
4198 rtl_write_dword(rtlpriv
, 0x90c, 0x00008000);
4199 rtl_write_dword(rtlpriv
, 0xb00, 0x03000100);
4200 rtl_write_dword(rtlpriv
, 0x984, 0x0046a910);/* [0]:AGC_en, [15]:idac_K_Mask */
4202 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x1); /* [31] = 1 --> Page C1 */
4203 rtl_write_dword(rtlpriv
, 0xc80, 0x18008c10);/* TX_TONE_idx[9:0], TxK_Mask[29] TX_Tone = 16 */
4204 rtl_write_dword(rtlpriv
, 0xc84, 0x38008c10);/* RX_TONE_idx[9:0], RxK_Mask[29] */
4205 rtl_write_dword(rtlpriv
, 0xc88, 0x821603e0);
4206 /* ODM_Write4Byte(pDM_Odm, 0xc8c, 0x68163e96); */
4207 rtl_write_dword(rtlpriv
, 0xcb8, 0x00100000);/* cb8[20] \B1N SI/PI \A8Ï¥\CE\C5v\A4\C1\B5\B9 iqk_dpk module */
4211 rtl_write_dword(rtlpriv
, 0x980, 0xfa000000);
4212 rtl_write_dword(rtlpriv
, 0x980, 0xf8000000);
4214 mdelay(10); /* Delay 10ms */
4215 rtl_write_dword(rtlpriv
, 0xcb8, 0x00000000);
4218 iqk_ready
= rtl_get_bbreg(hw
, 0xd00, BIT(10));
4219 if ((~iqk_ready
) || (delay_count
> 20))
4227 if (delay_count
< 20) { /* If 20ms No Result, then cal_retry++ */
4228 /* ============TXIQK Check============== */
4229 tx_fail
= rtl_get_bbreg(hw
, 0xd00, BIT(12));
4232 rtl_write_dword(rtlpriv
, 0xcb8, 0x02000000);
4233 tx_x0_rxk
[cal
] = rtl_get_bbreg(hw
, 0xd00, 0x07ff0000)<<21;
4234 rtl_write_dword(rtlpriv
, 0xcb8, 0x04000000);
4235 tx_y0_rxk
[cal
] = rtl_get_bbreg(hw
, 0xd00, 0x07ff0000)<<21;
4241 if (cal_retry
== 10)
4247 if (cal_retry
== 10)
4252 if (tx0iqkok
== false) { /* If RX mode TXK fail, then take TXK Result */
4253 tx_x0_rxk
[cal
] = tx_x0
[cal
];
4254 tx_y0_rxk
[cal
] = tx_y0
[cal
];
4256 rtl_dbg(rtlpriv
, COMP_IQK
,
4260 /* ====== RX IQK ====== */
4261 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x0); /* [31] = 0 --> Page C */
4262 /* 1. RX RF Setting */
4263 rtl_set_rfreg(hw
, path
, 0xef, RFREG_OFFSET_MASK
, 0x80000);
4264 rtl_set_rfreg(hw
, path
, 0x30, RFREG_OFFSET_MASK
, 0x30000);
4265 rtl_set_rfreg(hw
, path
, 0x31, RFREG_OFFSET_MASK
, 0x0002f);
4266 rtl_set_rfreg(hw
, path
, 0x32, RFREG_OFFSET_MASK
, 0xfffbb);
4267 rtl_set_rfreg(hw
, path
, 0x8f, RFREG_OFFSET_MASK
, 0x88001);
4268 rtl_set_rfreg(hw
, path
, 0x65, RFREG_OFFSET_MASK
, 0x931d8);
4269 rtl_set_rfreg(hw
, path
, 0xef, RFREG_OFFSET_MASK
, 0x00000);
4271 rtl_set_bbreg(hw
, 0x978, 0x03FF8000, (tx_x0_rxk
[cal
])>>21&0x000007ff);
4272 rtl_set_bbreg(hw
, 0x978, 0x000007FF, (tx_y0_rxk
[cal
])>>21&0x000007ff);
4273 rtl_set_bbreg(hw
, 0x978, BIT(31), 0x1);
4274 rtl_set_bbreg(hw
, 0x97c, BIT(31), 0x0);
4275 /* ODM_SetBBReg(pDM_Odm, 0xcb8, 0xF, 0xe); */
4276 rtl_write_dword(rtlpriv
, 0x90c, 0x00008000);
4277 rtl_write_dword(rtlpriv
, 0x984, 0x0046a911);
4279 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x1); /* [31] = 1 --> Page C1 */
4280 rtl_write_dword(rtlpriv
, 0xc80, 0x38008c10);/* TX_TONE_idx[9:0], TxK_Mask[29] TX_Tone = 16 */
4281 rtl_write_dword(rtlpriv
, 0xc84, 0x18008c10);/* RX_TONE_idx[9:0], RxK_Mask[29] */
4282 rtl_write_dword(rtlpriv
, 0xc88, 0x02140119);
4284 rtl_write_dword(rtlpriv
, 0xc8c, 0x28160d00); /*pDM_Odm->SupportInterface == 1*/
4286 rtl_write_dword(rtlpriv
, 0xcb8, 0x00100000);/* cb8[20] \B1N SI/PI \A8Ï¥\CE\C5v\A4\C1\B5\B9 iqk_dpk module */
4291 rtl_write_dword(rtlpriv
, 0x980, 0xfa000000);
4292 rtl_write_dword(rtlpriv
, 0x980, 0xf8000000);
4294 mdelay(10); /* Delay 10ms */
4295 rtl_write_dword(rtlpriv
, 0xcb8, 0x00000000);
4298 iqk_ready
= rtl_get_bbreg(hw
, 0xd00, BIT(10));
4299 if ((~iqk_ready
) || (delay_count
> 20))
4307 if (delay_count
< 20) { /* If 20ms No Result, then cal_retry++ */
4308 /* ============RXIQK Check============== */
4309 rx_fail
= rtl_get_bbreg(hw
, 0xd00, BIT(11));
4311 rtl_write_dword(rtlpriv
, 0xcb8, 0x06000000);
4312 rx_x0
[cal
] = rtl_get_bbreg(hw
, 0xd00, 0x07ff0000)<<21;
4313 rtl_write_dword(rtlpriv
, 0xcb8, 0x08000000);
4314 rx_y0
[cal
] = rtl_get_bbreg(hw
, 0xd00, 0x07ff0000)<<21;
4318 rtl_set_bbreg(hw
, 0xc10, 0x000003ff, 0x200>>1);
4319 rtl_set_bbreg(hw
, 0xc10, 0x03ff0000, 0x0>>1);
4322 if (cal_retry
== 10)
4329 if (cal_retry
== 10)
4339 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x0); /* [31] = 0 --> Page C */
4340 rtl_set_rfreg(hw
, path
, 0x65, RFREG_OFFSET_MASK
, temp_reg65
);
4348 /* FillIQK Result */
4351 rtl_dbg(rtlpriv
, COMP_IQK
, DBG_LOUD
,
4352 "========Path_A =======\n");
4353 if (tx_average
== 0)
4356 for (i
= 0; i
< tx_average
; i
++) {
4357 rtl_dbg(rtlpriv
, COMP_IQK
, DBG_LOUD
,
4358 "TX_X0_RXK[%d] = %x ;; TX_Y0_RXK[%d] = %x\n", i
,
4359 (tx_x0_rxk
[i
]) >> 21 & 0x000007ff, i
,
4360 (tx_y0_rxk
[i
]) >> 21 & 0x000007ff);
4361 rtl_dbg(rtlpriv
, COMP_IQK
, DBG_LOUD
,
4362 "TX_X0[%d] = %x ;; TX_Y0[%d] = %x\n", i
,
4363 (tx_x0
[i
]) >> 21 & 0x000007ff, i
,
4364 (tx_y0
[i
]) >> 21 & 0x000007ff);
4366 for (i
= 0; i
< tx_average
; i
++) {
4367 for (ii
= i
+1; ii
< tx_average
; ii
++) {
4368 dx
= (tx_x0
[i
]>>21) - (tx_x0
[ii
]>>21);
4369 if (dx
< 3 && dx
> -3) {
4370 dy
= (tx_y0
[i
]>>21) - (tx_y0
[ii
]>>21);
4371 if (dy
< 3 && dy
> -3) {
4372 tx_x
= ((tx_x0
[i
]>>21) + (tx_x0
[ii
]>>21))/2;
4373 tx_y
= ((tx_y0
[i
]>>21) + (tx_y0
[ii
]>>21))/2;
4384 _rtl8821ae_iqk_tx_fill_iqc(hw
, path
, tx_x
, tx_y
); /* ? */
4386 _rtl8821ae_iqk_tx_fill_iqc(hw
, path
, 0x200, 0x0);
4388 if (rx_average
== 0)
4391 for (i
= 0; i
< rx_average
; i
++)
4392 rtl_dbg(rtlpriv
, COMP_IQK
, DBG_LOUD
,
4393 "RX_X0[%d] = %x ;; RX_Y0[%d] = %x\n", i
,
4394 (rx_x0
[i
])>>21&0x000007ff, i
,
4395 (rx_y0
[i
])>>21&0x000007ff);
4396 for (i
= 0; i
< rx_average
; i
++) {
4397 for (ii
= i
+1; ii
< rx_average
; ii
++) {
4398 dx
= (rx_x0
[i
]>>21) - (rx_x0
[ii
]>>21);
4399 if (dx
< 4 && dx
> -4) {
4400 dy
= (rx_y0
[i
]>>21) - (rx_y0
[ii
]>>21);
4401 if (dy
< 4 && dy
> -4) {
4402 rx_x
= ((rx_x0
[i
]>>21) + (rx_x0
[ii
]>>21))/2;
4403 rx_y
= ((rx_y0
[i
]>>21) + (rx_y0
[ii
]>>21))/2;
4414 _rtl8821ae_iqk_rx_fill_iqc(hw
, path
, rx_x
, rx_y
);
4416 _rtl8821ae_iqk_rx_fill_iqc(hw
, path
, 0x200, 0x0);
4423 static void _rtl8821ae_iqk_restore_rf(struct ieee80211_hw
*hw
,
4424 enum radio_path path
,
4426 u32
*rf_backup
, u32 rf_reg_num
)
4428 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
4431 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x0); /* [31] = 0 --> Page C */
4432 for (i
= 0; i
< RF_REG_NUM
; i
++)
4433 rtl_set_rfreg(hw
, path
, backup_rf_reg
[i
], RFREG_OFFSET_MASK
,
4438 rtl_dbg(rtlpriv
, COMP_IQK
, DBG_LOUD
,
4439 "RestoreRF Path A Success!!!!\n");
4446 static void _rtl8821ae_iqk_restore_afe(struct ieee80211_hw
*hw
,
4447 u32
*afe_backup
, u32
*backup_afe_reg
,
4451 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
4453 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x0); /* [31] = 0 --> Page C */
4454 /* Reload AFE Parameters */
4455 for (i
= 0; i
< afe_num
; i
++)
4456 rtl_write_dword(rtlpriv
, backup_afe_reg
[i
], afe_backup
[i
]);
4457 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x1); /* [31] = 1 --> Page C1 */
4458 rtl_write_dword(rtlpriv
, 0xc80, 0x0);
4459 rtl_write_dword(rtlpriv
, 0xc84, 0x0);
4460 rtl_write_dword(rtlpriv
, 0xc88, 0x0);
4461 rtl_write_dword(rtlpriv
, 0xc8c, 0x3c000000);
4462 rtl_write_dword(rtlpriv
, 0xc90, 0x00000080);
4463 rtl_write_dword(rtlpriv
, 0xc94, 0x00000000);
4464 rtl_write_dword(rtlpriv
, 0xcc4, 0x20040000);
4465 rtl_write_dword(rtlpriv
, 0xcc8, 0x20000000);
4466 rtl_write_dword(rtlpriv
, 0xcb8, 0x0);
4467 rtl_dbg(rtlpriv
, COMP_IQK
, DBG_LOUD
, "RestoreAFE Success!!!!\n");
4470 static void _rtl8821ae_iqk_restore_macbb(struct ieee80211_hw
*hw
,
4472 u32
*backup_macbb_reg
,
4476 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
4478 rtl_set_bbreg(hw
, 0x82c, BIT(31), 0x0); /* [31] = 0 --> Page C */
4479 /* Reload MacBB Parameters */
4480 for (i
= 0; i
< macbb_num
; i
++)
4481 rtl_write_dword(rtlpriv
, backup_macbb_reg
[i
], macbb_backup
[i
]);
4482 rtl_dbg(rtlpriv
, COMP_IQK
, DBG_LOUD
, "RestoreMacBB Success!!!!\n");
4485 #undef MACBB_REG_NUM
4489 #define MACBB_REG_NUM 11
4490 #define AFE_REG_NUM 12
4491 #define RF_REG_NUM 3
4493 static void _rtl8821ae_phy_iq_calibrate(struct ieee80211_hw
*hw
)
4495 u32 macbb_backup
[MACBB_REG_NUM
];
4496 u32 afe_backup
[AFE_REG_NUM
];
4497 u32 rfa_backup
[RF_REG_NUM
];
4498 u32 rfb_backup
[RF_REG_NUM
];
4499 u32 backup_macbb_reg
[MACBB_REG_NUM
] = {
4500 0xb00, 0x520, 0x550, 0x808, 0x90c, 0xc00, 0xc50,
4501 0xe00, 0xe50, 0x838, 0x82c
4503 u32 backup_afe_reg
[AFE_REG_NUM
] = {
4504 0xc5c, 0xc60, 0xc64, 0xc68, 0xc6c, 0xc70, 0xc74,
4505 0xc78, 0xc7c, 0xc80, 0xc84, 0xcb8
4507 u32 backup_rf_reg
[RF_REG_NUM
] = {0x65, 0x8f, 0x0};
4509 _rtl8821ae_iqk_backup_macbb(hw
, macbb_backup
, backup_macbb_reg
,
4511 _rtl8821ae_iqk_backup_afe(hw
, afe_backup
, backup_afe_reg
, AFE_REG_NUM
);
4512 _rtl8821ae_iqk_backup_rf(hw
, rfa_backup
, rfb_backup
, backup_rf_reg
,
4515 _rtl8821ae_iqk_configure_mac(hw
);
4516 _rtl8821ae_iqk_tx(hw
, RF90_PATH_A
);
4517 _rtl8821ae_iqk_restore_rf(hw
, RF90_PATH_A
, backup_rf_reg
, rfa_backup
,
4520 _rtl8821ae_iqk_restore_afe(hw
, afe_backup
, backup_afe_reg
, AFE_REG_NUM
);
4521 _rtl8821ae_iqk_restore_macbb(hw
, macbb_backup
, backup_macbb_reg
,
4525 static void _rtl8821ae_phy_set_rfpath_switch(struct ieee80211_hw
*hw
, bool main
)
4527 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
4528 /* struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); */
4529 /* struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); */
4530 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
, "\n");
4533 rtl_set_bbreg(hw
, RA_RFE_PINMUX
+ 4, BIT(29) | BIT(28), 0x1);
4535 rtl_set_bbreg(hw
, RA_RFE_PINMUX
+ 4, BIT(29) | BIT(28), 0x2);
4538 #undef IQK_ADDA_REG_NUM
4539 #undef IQK_DELAY_TIME
4541 void rtl8812ae_phy_iq_calibrate(struct ieee80211_hw
*hw
, bool b_recovery
)
4545 void rtl8812ae_do_iqk(struct ieee80211_hw
*hw
, u8 delta_thermal_index
,
4546 u8 thermal_value
, u8 threshold
)
4548 struct rtl_dm
*rtldm
= rtl_dm(rtl_priv(hw
));
4550 rtldm
->thermalvalue_iqk
= thermal_value
;
4551 rtl8812ae_phy_iq_calibrate(hw
, false);
4554 void rtl8821ae_phy_iq_calibrate(struct ieee80211_hw
*hw
, bool b_recovery
)
4556 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
4557 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
4559 if (!rtlphy
->lck_inprogress
) {
4560 spin_lock(&rtlpriv
->locks
.iqk_lock
);
4561 rtlphy
->lck_inprogress
= true;
4562 spin_unlock(&rtlpriv
->locks
.iqk_lock
);
4564 _rtl8821ae_phy_iq_calibrate(hw
);
4566 spin_lock(&rtlpriv
->locks
.iqk_lock
);
4567 rtlphy
->lck_inprogress
= false;
4568 spin_unlock(&rtlpriv
->locks
.iqk_lock
);
4572 void rtl8821ae_reset_iqk_result(struct ieee80211_hw
*hw
)
4574 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
4575 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
4578 rtl_dbg(rtlpriv
, COMP_IQK
, DBG_LOUD
,
4579 "rtl8812ae_dm_reset_iqk_result:: settings regs %d default regs %d\n",
4580 (int)(sizeof(rtlphy
->iqk_matrix
) /
4581 sizeof(struct iqk_matrix_regs
)),
4582 IQK_MATRIX_SETTINGS_NUM
);
4584 for (i
= 0; i
< IQK_MATRIX_SETTINGS_NUM
; i
++) {
4585 rtlphy
->iqk_matrix
[i
].value
[0][0] = 0x100;
4586 rtlphy
->iqk_matrix
[i
].value
[0][2] = 0x100;
4587 rtlphy
->iqk_matrix
[i
].value
[0][4] = 0x100;
4588 rtlphy
->iqk_matrix
[i
].value
[0][6] = 0x100;
4590 rtlphy
->iqk_matrix
[i
].value
[0][1] = 0x0;
4591 rtlphy
->iqk_matrix
[i
].value
[0][3] = 0x0;
4592 rtlphy
->iqk_matrix
[i
].value
[0][5] = 0x0;
4593 rtlphy
->iqk_matrix
[i
].value
[0][7] = 0x0;
4595 rtlphy
->iqk_matrix
[i
].iqk_done
= false;
4599 void rtl8821ae_do_iqk(struct ieee80211_hw
*hw
, u8 delta_thermal_index
,
4600 u8 thermal_value
, u8 threshold
)
4602 struct rtl_dm
*rtldm
= rtl_dm(rtl_priv(hw
));
4604 rtl8821ae_reset_iqk_result(hw
);
4606 rtldm
->thermalvalue_iqk
= thermal_value
;
4607 rtl8821ae_phy_iq_calibrate(hw
, false);
4610 void rtl8821ae_phy_lc_calibrate(struct ieee80211_hw
*hw
)
4614 void rtl8821ae_phy_ap_calibrate(struct ieee80211_hw
*hw
, s8 delta
)
4618 void rtl8821ae_phy_set_rfpath_switch(struct ieee80211_hw
*hw
, bool bmain
)
4620 _rtl8821ae_phy_set_rfpath_switch(hw
, bmain
);
4623 bool rtl8821ae_phy_set_io_cmd(struct ieee80211_hw
*hw
, enum io_type iotype
)
4625 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
4626 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
4627 bool postprocessing
= false;
4629 rtl_dbg(rtlpriv
, COMP_CMD
, DBG_TRACE
,
4630 "-->IO Cmd(%#x), set_io_inprogress(%d)\n",
4631 iotype
, rtlphy
->set_io_inprogress
);
4634 case IO_CMD_RESUME_DM_BY_SCAN
:
4635 rtl_dbg(rtlpriv
, COMP_CMD
, DBG_TRACE
,
4636 "[IO CMD] Resume DM after scan.\n");
4637 postprocessing
= true;
4639 case IO_CMD_PAUSE_BAND0_DM_BY_SCAN
:
4640 case IO_CMD_PAUSE_BAND1_DM_BY_SCAN
:
4641 rtl_dbg(rtlpriv
, COMP_CMD
, DBG_TRACE
,
4642 "[IO CMD] Pause DM before scan.\n");
4643 postprocessing
= true;
4646 pr_err("switch case %#x not processed\n",
4651 if (postprocessing
&& !rtlphy
->set_io_inprogress
) {
4652 rtlphy
->set_io_inprogress
= true;
4653 rtlphy
->current_io_type
= iotype
;
4657 rtl8821ae_phy_set_io(hw
);
4658 rtl_dbg(rtlpriv
, COMP_CMD
, DBG_TRACE
, "IO Type(%#x)\n", iotype
);
4662 static void rtl8821ae_phy_set_io(struct ieee80211_hw
*hw
)
4664 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
4665 struct dig_t
*dm_digtable
= &rtlpriv
->dm_digtable
;
4666 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
4668 rtl_dbg(rtlpriv
, COMP_CMD
, DBG_TRACE
,
4669 "--->Cmd(%#x), set_io_inprogress(%d)\n",
4670 rtlphy
->current_io_type
, rtlphy
->set_io_inprogress
);
4671 switch (rtlphy
->current_io_type
) {
4672 case IO_CMD_RESUME_DM_BY_SCAN
:
4673 if (rtlpriv
->mac80211
.opmode
== NL80211_IFTYPE_ADHOC
)
4674 _rtl8821ae_resume_tx_beacon(hw
);
4675 rtl8821ae_dm_write_dig(hw
, rtlphy
->initgain_backup
.xaagccore1
);
4676 rtl8821ae_dm_write_cck_cca_thres(hw
,
4677 rtlphy
->initgain_backup
.cca
);
4679 case IO_CMD_PAUSE_BAND0_DM_BY_SCAN
:
4680 if (rtlpriv
->mac80211
.opmode
== NL80211_IFTYPE_ADHOC
)
4681 _rtl8821ae_stop_tx_beacon(hw
);
4682 rtlphy
->initgain_backup
.xaagccore1
= dm_digtable
->cur_igvalue
;
4683 rtl8821ae_dm_write_dig(hw
, 0x17);
4684 rtlphy
->initgain_backup
.cca
= dm_digtable
->cur_cck_cca_thres
;
4685 rtl8821ae_dm_write_cck_cca_thres(hw
, 0x40);
4687 case IO_CMD_PAUSE_BAND1_DM_BY_SCAN
:
4690 pr_err("switch case %#x not processed\n",
4691 rtlphy
->current_io_type
);
4694 rtlphy
->set_io_inprogress
= false;
4695 rtl_dbg(rtlpriv
, COMP_CMD
, DBG_TRACE
,
4696 "(%#x)\n", rtlphy
->current_io_type
);
4699 static void rtl8821ae_phy_set_rf_on(struct ieee80211_hw
*hw
)
4701 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
4703 rtl_write_byte(rtlpriv
, REG_SPS0_CTRL
, 0x2b);
4704 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE3);
4705 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE2);
4706 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, 0xE3);
4707 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0x00);
4710 static bool _rtl8821ae_phy_set_rf_power_state(struct ieee80211_hw
*hw
,
4711 enum rf_pwrstate rfpwr_state
)
4713 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
4714 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
4715 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
4716 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
4717 bool bresult
= true;
4719 struct rtl8192_tx_ring
*ring
= NULL
;
4721 switch (rfpwr_state
) {
4723 if ((ppsc
->rfpwr_state
== ERFOFF
) &&
4724 RT_IN_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
)) {
4725 bool rtstatus
= false;
4726 u32 initializecount
= 0;
4730 rtl_dbg(rtlpriv
, COMP_RF
, DBG_DMESG
,
4731 "IPS Set eRf nic enable\n");
4732 rtstatus
= rtl_ps_enable_nic(hw
);
4733 } while (!rtstatus
&& (initializecount
< 10));
4734 RT_CLEAR_PS_LEVEL(ppsc
,
4735 RT_RF_OFF_LEVL_HALT_NIC
);
4737 rtl_dbg(rtlpriv
, COMP_RF
, DBG_DMESG
,
4738 "Set ERFON slept:%d ms\n",
4739 jiffies_to_msecs(jiffies
-
4740 ppsc
->last_sleep_jiffies
));
4741 ppsc
->last_awake_jiffies
= jiffies
;
4742 rtl8821ae_phy_set_rf_on(hw
);
4744 if (mac
->link_state
== MAC80211_LINKED
) {
4745 rtlpriv
->cfg
->ops
->led_control(hw
,
4748 rtlpriv
->cfg
->ops
->led_control(hw
,
4753 for (queue_id
= 0, i
= 0;
4754 queue_id
< RTL_PCI_MAX_TX_QUEUE_COUNT
;) {
4755 ring
= &pcipriv
->dev
.tx_ring
[queue_id
];
4756 if (queue_id
== BEACON_QUEUE
||
4757 skb_queue_len(&ring
->queue
) == 0) {
4761 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_WARNING
,
4762 "eRf Off/Sleep: %d times TcbBusyQueue[%d] =%d before doze!\n",
4764 skb_queue_len(&ring
->queue
));
4769 if (i
>= MAX_DOZE_WAITING_TIMES_9x
) {
4770 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_WARNING
,
4771 "\n ERFSLEEP: %d times TcbBusyQueue[%d] = %d !\n",
4772 MAX_DOZE_WAITING_TIMES_9x
,
4774 skb_queue_len(&ring
->queue
));
4779 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_HALT_NIC
) {
4780 rtl_dbg(rtlpriv
, COMP_RF
, DBG_DMESG
,
4781 "IPS Set eRf nic disable\n");
4782 rtl_ps_disable_nic(hw
);
4783 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
4785 if (ppsc
->rfoff_reason
== RF_CHANGE_BY_IPS
) {
4786 rtlpriv
->cfg
->ops
->led_control(hw
,
4789 rtlpriv
->cfg
->ops
->led_control(hw
,
4795 pr_err("switch case %#x not processed\n",
4801 ppsc
->rfpwr_state
= rfpwr_state
;
4805 bool rtl8821ae_phy_set_rf_power_state(struct ieee80211_hw
*hw
,
4806 enum rf_pwrstate rfpwr_state
)
4808 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
4810 bool bresult
= false;
4812 if (rfpwr_state
== ppsc
->rfpwr_state
)
4814 bresult
= _rtl8821ae_phy_set_rf_power_state(hw
, rfpwr_state
);