1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
4 * Copyright(c) 2016 Realtek Corporation.
8 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
13 *****************************************************************************/
23 #include "../btcoexist/halbt_precomp.h"
27 static u32 _rtl8822be_phy_calculate_bit_shift(u32 bitmask);
29 _rtl8822be_phy_init_bb_rf_register_definition(struct ieee80211_hw *hw);
31 static long _rtl8822be_phy_txpwr_idx_to_dbm(struct ieee80211_hw *hw,
32 enum wireless_mode wirelessmode,
34 static void rtl8822be_phy_set_rf_on(struct ieee80211_hw *hw);
35 static void rtl8822be_phy_set_io(struct ieee80211_hw *hw);
37 static u8 cck_rates[] = {DESC_RATE1M, DESC_RATE2M, DESC_RATE5_5M, DESC_RATE11M};
38 static u8 sizes_of_cck_retes = 4;
39 static u8 ofdm_rates[] = {DESC_RATE6M, DESC_RATE9M, DESC_RATE12M,
40 DESC_RATE18M, DESC_RATE24M, DESC_RATE36M,
41 DESC_RATE48M, DESC_RATE54M};
42 static u8 sizes_of_ofdm_retes = 8;
43 static u8 ht_rates_1t[] = {DESC_RATEMCS0, DESC_RATEMCS1, DESC_RATEMCS2,
44 DESC_RATEMCS3, DESC_RATEMCS4, DESC_RATEMCS5,
45 DESC_RATEMCS6, DESC_RATEMCS7};
46 static u8 sizes_of_ht_retes_1t = 8;
47 static u8 ht_rates_2t[] = {DESC_RATEMCS8, DESC_RATEMCS9, DESC_RATEMCS10,
48 DESC_RATEMCS11, DESC_RATEMCS12, DESC_RATEMCS13,
49 DESC_RATEMCS14, DESC_RATEMCS15};
50 static u8 sizes_of_ht_retes_2t = 8;
51 static u8 vht_rates_1t[] = {DESC_RATEVHT1SS_MCS0, DESC_RATEVHT1SS_MCS1,
52 DESC_RATEVHT1SS_MCS2, DESC_RATEVHT1SS_MCS3,
53 DESC_RATEVHT1SS_MCS4, DESC_RATEVHT1SS_MCS5,
54 DESC_RATEVHT1SS_MCS6, DESC_RATEVHT1SS_MCS7,
55 DESC_RATEVHT1SS_MCS8, DESC_RATEVHT1SS_MCS9};
56 static u8 vht_rates_2t[] = {DESC_RATEVHT2SS_MCS0, DESC_RATEVHT2SS_MCS1,
57 DESC_RATEVHT2SS_MCS2, DESC_RATEVHT2SS_MCS3,
58 DESC_RATEVHT2SS_MCS4, DESC_RATEVHT2SS_MCS5,
59 DESC_RATEVHT2SS_MCS6, DESC_RATEVHT2SS_MCS7,
60 DESC_RATEVHT2SS_MCS8, DESC_RATEVHT2SS_MCS9};
61 static u8 sizes_of_vht_retes = 10;
63 u32 rtl8822be_phy_query_bb_reg(struct ieee80211_hw *hw, u32 regaddr,
66 struct rtl_priv *rtlpriv = rtl_priv(hw);
67 u32 returnvalue, originalvalue, bitshift;
69 RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE, "regaddr(%#x), bitmask(%#x)\n",
71 originalvalue = rtl_read_dword(rtlpriv, regaddr);
72 bitshift = _rtl8822be_phy_calculate_bit_shift(bitmask);
73 returnvalue = (originalvalue & bitmask) >> bitshift;
75 RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE, "BBR MASK=0x%x Addr[0x%x]=0x%x\n",
76 bitmask, regaddr, originalvalue);
81 void rtl8822be_phy_set_bb_reg(struct ieee80211_hw *hw, u32 regaddr, u32 bitmask,
84 struct rtl_priv *rtlpriv = rtl_priv(hw);
85 u32 originalvalue, bitshift;
87 RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
88 "regaddr(%#x), bitmask(%#x), data(%#x)\n", regaddr, bitmask,
91 if (bitmask != MASKDWORD) {
92 originalvalue = rtl_read_dword(rtlpriv, regaddr);
93 bitshift = _rtl8822be_phy_calculate_bit_shift(bitmask);
94 data = ((originalvalue & (~bitmask)) |
95 ((data << bitshift) & bitmask));
98 rtl_write_dword(rtlpriv, regaddr, data);
100 RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
101 "regaddr(%#x), bitmask(%#x), data(%#x)\n", regaddr, bitmask,
105 u32 rtl8822be_phy_query_rf_reg(struct ieee80211_hw *hw, enum radio_path rfpath,
106 u32 regaddr, u32 bitmask)
108 struct rtl_priv *rtlpriv = rtl_priv(hw);
109 u32 /*original_value,*/ readback_value /*, bitshift*/;
112 RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
113 "regaddr(%#x), rfpath(%#x), bitmask(%#x)\n", regaddr, rfpath,
116 spin_lock_irqsave(&rtlpriv->locks.rf_lock, flags);
118 readback_value = rtlpriv->phydm.ops->phydm_read_rf_reg(
119 rtlpriv, rfpath, regaddr, bitmask);
121 spin_unlock_irqrestore(&rtlpriv->locks.rf_lock, flags);
123 return readback_value;
126 void rtl8822be_phy_set_rf_reg(struct ieee80211_hw *hw, enum radio_path rfpath,
127 u32 regaddr, u32 bitmask, u32 data)
129 struct rtl_priv *rtlpriv = rtl_priv(hw);
132 RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
133 "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
134 regaddr, bitmask, data, rfpath);
136 spin_lock_irqsave(&rtlpriv->locks.rf_lock, flags);
138 rtlpriv->phydm.ops->phydm_write_rf_reg(rtlpriv, rfpath, regaddr,
141 spin_unlock_irqrestore(&rtlpriv->locks.rf_lock, flags);
143 RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
144 "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
145 regaddr, bitmask, data, rfpath);
148 static u32 _rtl8822be_phy_calculate_bit_shift(u32 bitmask)
152 for (i = 0; i <= 31; i++) {
153 if (((bitmask >> i) & 0x1) == 1)
159 bool rtl8822be_halmac_cb_init_mac_register(struct rtl_priv *rtlpriv)
161 return rtlpriv->phydm.ops->phydm_phy_mac_config(rtlpriv);
164 bool rtl8822be_phy_bb_config(struct ieee80211_hw *hw)
166 bool rtstatus = true;
167 struct rtl_priv *rtlpriv = rtl_priv(hw);
168 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
172 rtstatus = rtlpriv->phydm.ops->phydm_phy_bb_config(rtlpriv);
174 /* write 0x28[6:1] = 0x24[30:25] = CrystalCap */
175 crystal_cap = rtlefuse->crystalcap & 0x3F;
176 rtl_set_bbreg(hw, REG_AFE_XTAL_CTRL_8822B, 0x7E000000, crystal_cap);
177 rtl_set_bbreg(hw, REG_AFE_PLL_CTRL_8822B, 0x7E, crystal_cap);
179 /*rtlphy->reg_837 = rtl_read_byte(rtlpriv, 0x837);*/ /*unused*/
184 bool rtl8822be_phy_rf_config(struct ieee80211_hw *hw)
186 struct rtl_priv *rtlpriv = rtl_priv(hw);
187 struct rtl_phy *rtlphy = &rtlpriv->phy;
189 if (rtlphy->rf_type == RF_1T1R)
190 rtlphy->num_total_rfpath = 1;
192 rtlphy->num_total_rfpath = 2;
194 return rtlpriv->phydm.ops->phydm_phy_rf_config(rtlpriv);
197 bool rtl8822be_halmac_cb_init_bb_rf_register(struct rtl_priv *rtlpriv)
199 struct ieee80211_hw *hw = rtlpriv->hw;
200 enum radio_mask txpath, rxpath;
204 _rtl8822be_phy_init_bb_rf_register_definition(hw);
206 rtlpriv->halmac.ops->halmac_phy_power_switch(rtlpriv, 1);
208 /* beofre bb/rf config */
209 rtlpriv->phydm.ops->phydm_parameter_init(rtlpriv, 0);
211 /* do bb/rf config */
212 if (rtl8822be_phy_bb_config(hw) && rtl8822be_phy_rf_config(hw))
215 /* after bb/rf config */
216 rtlpriv->phydm.ops->phydm_parameter_init(rtlpriv, 1);
218 /* set trx mode (keep it to be last, r17376) */
219 txpath = RF_MASK_A | RF_MASK_B;
220 rxpath = RF_MASK_A | RF_MASK_B;
222 ret = rtlpriv->phydm.ops->phydm_trx_mode(rtlpriv, txpath, rxpath,
228 static void _rtl8822be_phy_init_tx_power_by_rate(struct ieee80211_hw *hw)
230 struct rtl_priv *rtlpriv = rtl_priv(hw);
231 struct rtl_phy *rtlphy = &rtlpriv->phy;
233 u8 band, rfpath, txnum, rate;
235 for (band = BAND_ON_2_4G; band <= BAND_ON_5G; ++band)
236 for (rfpath = 0; rfpath < TX_PWR_BY_RATE_NUM_RF; ++rfpath)
237 for (txnum = 0; txnum < TX_PWR_BY_RATE_NUM_RF; ++txnum)
238 for (rate = 0; rate < TX_PWR_BY_RATE_NUM_RATE;
240 rtlphy->tx_power_by_rate_offset
241 [band][rfpath][txnum][rate] = 0;
244 static void _rtl8822be_phy_set_txpower_by_rate_base(struct ieee80211_hw *hw,
246 u8 rate_section, u8 txnum,
249 struct rtl_priv *rtlpriv = rtl_priv(hw);
250 struct rtl_phy *rtlphy = &rtlpriv->phy;
252 if (path > RF90_PATH_D) {
253 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
254 "Invalid Rf Path %d in phy_SetTxPowerByRatBase()\n",
259 if (band != BAND_ON_2_4G && band != BAND_ON_5G) {
260 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
261 "Invalid band %d in phy_SetTxPowerByRatBase()\n",
266 if (rate_section >= MAX_RATE_SECTION ||
267 (band == BAND_ON_5G && rate_section == CCK)) {
269 rtlpriv, COMP_INIT, DBG_LOUD,
270 "Invalid rate_section %d in phy_SetTxPowerByRatBase()\n",
275 if (band == BAND_ON_2_4G)
276 rtlphy->txpwr_by_rate_base_24g[path][txnum][rate_section] =
278 else /* BAND_ON_5G */
279 rtlphy->txpwr_by_rate_base_5g[path][txnum][rate_section - 1] =
283 static u8 _rtl8822be_phy_get_txpower_by_rate_base(struct ieee80211_hw *hw,
284 u8 band, u8 path, u8 txnum,
287 struct rtl_priv *rtlpriv = rtl_priv(hw);
288 struct rtl_phy *rtlphy = &rtlpriv->phy;
291 if (path > RF90_PATH_D) {
292 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
293 "Invalid Rf Path %d in phy_GetTxPowerByRatBase()\n",
298 if (band != BAND_ON_2_4G && band != BAND_ON_5G) {
299 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
300 "Invalid band %d in phy_GetTxPowerByRatBase()\n",
305 if (rate_section >= MAX_RATE_SECTION ||
306 (band == BAND_ON_5G && rate_section == CCK)) {
308 rtlpriv, COMP_INIT, DBG_LOUD,
309 "Invalid rate_section %d in phy_GetTxPowerByRatBase()\n",
314 if (band == BAND_ON_2_4G)
315 value = rtlphy->txpwr_by_rate_base_24g[path][txnum]
317 else /* BAND_ON_5G */
318 value = rtlphy->txpwr_by_rate_base_5g[path][txnum]
324 static void _rtl8822be_phy_store_txpower_by_rate_base(struct ieee80211_hw *hw)
326 struct rtl_priv *rtlpriv = rtl_priv(hw);
327 struct rtl_phy *rtlphy = &rtlpriv->phy;
330 enum rtl_desc_rate rate;
331 enum rate_section section;
332 } rate_sec_base[] = {
334 {DESC_RATE54M, OFDM},
335 {DESC_RATEMCS7, HT_MCS0_MCS7},
336 {DESC_RATEMCS15, HT_MCS8_MCS15},
337 {DESC_RATEVHT1SS_MCS7, VHT_1SSMCS0_1SSMCS9},
338 {DESC_RATEVHT2SS_MCS7, VHT_2SSMCS0_2SSMCS9},
341 u8 band, path, rs, tx_num, base;
344 for (band = BAND_ON_2_4G; band <= BAND_ON_5G; band++) {
345 for (path = RF90_PATH_A; path <= RF90_PATH_B; path++) {
346 for (rs = 0; rs < MAX_RATE_SECTION; rs++) {
347 rate = rate_sec_base[rs].rate;
348 section = rate_sec_base[rs].section;
350 if (IS_1T_RATE(rate))
355 if (band == BAND_ON_5G &&
356 RX_HAL_IS_CCK_RATE(rate))
359 base = rtlphy->tx_power_by_rate_offset
360 [band][path][tx_num][rate];
361 _rtl8822be_phy_set_txpower_by_rate_base(
362 hw, band, path, section, tx_num, base);
368 static void __rtl8822be_phy_cross_reference_core(struct ieee80211_hw *hw,
369 u8 regulation, u8 bw,
372 struct rtl_priv *rtlpriv = rtl_priv(hw);
373 struct rtl_phy *rtlphy = &rtlpriv->phy;
375 s8 pwrlmt, ref_pwrlmt;
377 for (rs = 0; rs < MAX_RATE_SECTION_NUM; ++rs) {
378 /*5G 20M 40M VHT and HT can cross reference*/
379 if (bw != HT_CHANNEL_WIDTH_20 && bw != HT_CHANNEL_WIDTH_20_40)
382 if (rs == HT_MCS0_MCS7)
383 ref_rs = VHT_1SSMCS0_1SSMCS9;
384 else if (rs == HT_MCS8_MCS15)
385 ref_rs = VHT_2SSMCS0_2SSMCS9;
386 else if (rs == VHT_1SSMCS0_1SSMCS9)
387 ref_rs = HT_MCS0_MCS7;
388 else if (rs == VHT_2SSMCS0_2SSMCS9)
389 ref_rs = HT_MCS8_MCS15;
393 ref_pwrlmt = rtlphy->txpwr_limit_5g[regulation][bw][ref_rs]
394 [channel][RF90_PATH_A];
395 if (ref_pwrlmt == MAX_POWER_INDEX)
398 pwrlmt = rtlphy->txpwr_limit_5g[regulation][bw][rs][channel]
400 if (pwrlmt != MAX_POWER_INDEX)
403 rtlphy->txpwr_limit_5g[regulation][bw][rs][channel]
404 [RF90_PATH_A] = ref_pwrlmt;
409 _rtl8822be_phy_cross_reference_ht_and_vht_txpower_limit(struct ieee80211_hw *hw)
411 u8 regulation, bw, channel;
413 for (regulation = 0; regulation < MAX_REGULATION_NUM; ++regulation) {
414 for (bw = 0; bw < MAX_5G_BANDWIDTH_NUM; ++bw) {
415 for (channel = 0; channel < CHANNEL_MAX_NUMBER_5G;
417 __rtl8822be_phy_cross_reference_core(
418 hw, regulation, bw, channel);
424 static void __rtl8822be_txpwr_limit_to_index_2g(struct ieee80211_hw *hw,
425 u8 regulation, u8 bw,
428 struct rtl_priv *rtlpriv = rtl_priv(hw);
429 struct rtl_phy *rtlphy = &rtlpriv->phy;
430 u8 bw40_pwr_base_dbm2_4G;
433 enum rf_tx_num txnum;
437 for (rate_section = 0; rate_section < MAX_RATE_SECTION_NUM;
439 /* obtain the base dBm values in 2.4G band
440 * CCK => 11M, OFDM => 54M, HT 1T => MCS7, HT 2T => MCS15
444 rtlphy->txpwr_limit_2_4g[regulation][bw][rate_section]
445 [channel][RF90_PATH_A];
446 txnum = IS_1T_RATESEC(rate_section) ? RF_1TX : RF_2TX;
448 if (temp_pwrlmt == MAX_POWER_INDEX)
451 for (rf_path = RF90_PATH_A; rf_path < MAX_RF_PATH_NUM;
453 bw40_pwr_base_dbm2_4G =
454 _rtl8822be_phy_get_txpower_by_rate_base(
455 hw, BAND_ON_2_4G, rf_path, txnum,
458 temp_value = temp_pwrlmt - bw40_pwr_base_dbm2_4G;
459 rtlphy->txpwr_limit_2_4g[regulation][bw][rate_section]
460 [channel][rf_path] = temp_value;
463 rtlpriv, COMP_INIT, DBG_TRACE,
464 "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",
465 regulation, bw, rate_section, channel,
466 rtlphy->txpwr_limit_2_4g[regulation][bw]
467 [rate_section][channel]
469 (temp_pwrlmt == 63) ? 0 : temp_pwrlmt / 2,
470 channel, rf_path, bw40_pwr_base_dbm2_4G);
475 static void __rtl8822be_txpwr_limit_to_index_5g(struct ieee80211_hw *hw,
476 u8 regulation, u8 bw,
479 struct rtl_priv *rtlpriv = rtl_priv(hw);
480 struct rtl_phy *rtlphy = &rtlpriv->phy;
481 u8 bw40_pwr_base_dbm5G;
484 enum rf_tx_num txnum;
488 for (rate_section = 0; rate_section < MAX_RATE_SECTION_NUM;
490 /* obtain the base dBm values in 5G band
491 * OFDM => 54M, HT 1T => MCS7, HT 2T => MCS15,
492 * VHT => 1SSMCS7, VHT 2T => 2SSMCS7
496 rtlphy->txpwr_limit_5g[regulation][bw][rate_section]
497 [channel][RF90_PATH_A];
498 txnum = IS_1T_RATESEC(rate_section) ? RF_1TX : RF_2TX;
500 if (temp_pwrlmt == MAX_POWER_INDEX)
503 for (rf_path = RF90_PATH_A; rf_path < MAX_RF_PATH_NUM;
505 bw40_pwr_base_dbm5G =
506 _rtl8822be_phy_get_txpower_by_rate_base(
507 hw, BAND_ON_5G, rf_path, txnum,
510 temp_value = temp_pwrlmt - bw40_pwr_base_dbm5G;
511 rtlphy->txpwr_limit_5g[regulation][bw][rate_section]
512 [channel][rf_path] = temp_value;
515 rtlpriv, COMP_INIT, DBG_TRACE,
516 "TxPwrLimit_5G[regulation %d][bw %d][rateSection %d][channel %d] =%d\n(TxPwrLimit in dBm %d - BW40PwrLmt5G[chnl group %d][rfPath %d] %d)\n",
517 regulation, bw, rate_section, channel,
518 rtlphy->txpwr_limit_5g[regulation][bw]
519 [rate_section][channel]
521 temp_pwrlmt, channel, rf_path,
522 bw40_pwr_base_dbm5G);
528 _rtl8822be_phy_convert_txpower_limit_to_power_index(struct ieee80211_hw *hw)
530 struct rtl_priv *rtlpriv = rtl_priv(hw);
531 u8 regulation, bw, channel;
533 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "=====> %s()\n", __func__);
535 _rtl8822be_phy_cross_reference_ht_and_vht_txpower_limit(hw);
537 for (regulation = 0; regulation < MAX_REGULATION_NUM; ++regulation) {
538 for (bw = 0; bw < MAX_2_4G_BANDWIDTH_NUM; ++bw) {
539 for (channel = 0; channel < CHANNEL_MAX_NUMBER_2G;
541 __rtl8822be_txpwr_limit_to_index_2g(
542 hw, regulation, bw, channel);
547 for (regulation = 0; regulation < MAX_REGULATION_NUM; ++regulation) {
548 for (bw = 0; bw < MAX_5G_BANDWIDTH_NUM; ++bw) {
549 for (channel = 0; channel < CHANNEL_MAX_NUMBER_5G;
551 __rtl8822be_txpwr_limit_to_index_5g(
552 hw, regulation, bw, channel);
556 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "<===== %s()\n", __func__);
559 static void _rtl8822be_phy_init_txpower_limit(struct ieee80211_hw *hw)
561 struct rtl_priv *rtlpriv = rtl_priv(hw);
562 struct rtl_phy *rtlphy = &rtlpriv->phy;
565 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "=====> %s()!\n", __func__);
567 for (i = 0; i < MAX_REGULATION_NUM; ++i) {
568 for (j = 0; j < MAX_2_4G_BANDWIDTH_NUM; ++j)
569 for (k = 0; k < MAX_RATE_SECTION_NUM; ++k)
570 for (m = 0; m < CHANNEL_MAX_NUMBER_2G; ++m)
571 for (l = 0; l < MAX_RF_PATH_NUM; ++l)
572 rtlphy->txpwr_limit_2_4g[i][j]
577 for (i = 0; i < MAX_REGULATION_NUM; ++i) {
578 for (j = 0; j < MAX_5G_BANDWIDTH_NUM; ++j)
579 for (k = 0; k < MAX_RATE_SECTION_NUM; ++k)
580 for (m = 0; m < CHANNEL_MAX_NUMBER_5G; ++m)
581 for (l = 0; l < MAX_RF_PATH_NUM; ++l)
582 rtlphy->txpwr_limit_5g[i][j][k]
587 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "<===== %s()!\n", __func__);
591 _rtl8822be_phy_convert_txpower_dbm_to_relative_value(struct ieee80211_hw *hw)
593 struct rtl_priv *rtlpriv = rtl_priv(hw);
594 struct rtl_phy *rtlphy = &rtlpriv->phy;
596 u8 base = 0, i = 0, value = 0, band = 0, path = 0, txnum = 0;
598 for (band = BAND_ON_2_4G; band <= BAND_ON_5G; ++band) {
599 for (path = RF90_PATH_A; path <= RF90_PATH_B; ++path) {
600 for (txnum = RF_1TX; txnum <= RF_2TX; ++txnum) {
602 base = rtlphy->tx_power_by_rate_offset
605 for (i = 0; i < sizeof(cck_rates); ++i) {
606 value = rtlphy->tx_power_by_rate_offset
609 rtlphy->tx_power_by_rate_offset
611 [cck_rates[i]] = value - base;
615 base = rtlphy->tx_power_by_rate_offset
618 for (i = 0; i < sizeof(ofdm_rates); ++i) {
619 value = rtlphy->tx_power_by_rate_offset
622 rtlphy->tx_power_by_rate_offset
624 [ofdm_rates[i]] = value - base;
628 base = rtlphy->tx_power_by_rate_offset
631 for (i = 0; i < sizeof(ht_rates_1t); ++i) {
632 value = rtlphy->tx_power_by_rate_offset
635 rtlphy->tx_power_by_rate_offset
637 [ht_rates_1t[i]] = value - base;
641 base = rtlphy->tx_power_by_rate_offset
644 for (i = 0; i < sizeof(ht_rates_2t); ++i) {
645 value = rtlphy->tx_power_by_rate_offset
648 rtlphy->tx_power_by_rate_offset
650 [ht_rates_2t[i]] = value - base;
654 base = rtlphy->tx_power_by_rate_offset
656 [DESC_RATEVHT1SS_MCS7];
657 for (i = 0; i < sizeof(vht_rates_1t); ++i) {
658 value = rtlphy->tx_power_by_rate_offset
661 rtlphy->tx_power_by_rate_offset
668 base = rtlphy->tx_power_by_rate_offset
670 [DESC_RATEVHT2SS_MCS7];
671 for (i = 0; i < sizeof(vht_rates_2t); ++i) {
672 value = rtlphy->tx_power_by_rate_offset
675 rtlphy->tx_power_by_rate_offset
684 RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE, "<===%s()\n", __func__);
688 _rtl8822be_phy_txpower_by_rate_configuration(struct ieee80211_hw *hw)
690 /* copy rate_section from
691 * tx_power_by_rate_offset[][rate] to txpwr_by_rate_base_24g/_5g[][rs]
693 _rtl8822be_phy_store_txpower_by_rate_base(hw);
695 /* convert tx_power_by_rate_offset[] to relative value */
696 _rtl8822be_phy_convert_txpower_dbm_to_relative_value(hw);
699 /* string is in decimal */
700 static bool _rtl8822be_get_integer_from_string(char *str, u8 *pint)
705 while (str[i] != '\0') {
706 if (str[i] >= '0' && str[i] <= '9') {
708 *pint += (str[i] - '0');
718 static bool _rtl8822be_eq_n_byte(u8 *str1, u8 *str2, u32 num)
724 if (str1[num] != str2[num])
730 static char _rtl8822be_phy_get_chnl_idx_of_txpwr_lmt(struct ieee80211_hw *hw,
733 struct rtl_priv *rtlpriv = rtl_priv(hw);
734 char channel_index = -1;
737 if (band == BAND_ON_2_4G) {
738 channel_index = channel - 1;
739 } else if (band == BAND_ON_5G) {
740 for (i = 0; i < sizeof(rtl_channel5g) / sizeof(u8); ++i) {
741 if (rtl_channel5g[i] == channel)
745 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, "Invalid Band %d in %s",
749 if (channel_index == -1)
750 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
751 "Invalid Channel %d of Band %d in %s", channel, band,
754 return channel_index;
757 void rtl8822be_phy_set_txpower_limit(struct ieee80211_hw *hw, u8 *pregulation,
758 u8 *pband, u8 *pbandwidth,
759 u8 *prate_section, u8 *prf_path,
760 u8 *pchannel, u8 *ppower_limit)
762 struct rtl_priv *rtlpriv = rtl_priv(hw);
763 struct rtl_phy *rtlphy = &rtlpriv->phy;
764 u8 regulation = 0, bandwidth = 0, rate_section = 0, channel;
766 char power_limit = 0, prev_power_limit, ret;
768 if (!_rtl8822be_get_integer_from_string((char *)pchannel, &channel) ||
769 !_rtl8822be_get_integer_from_string((char *)ppower_limit,
771 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
772 "Illegal index of pwr_lmt table [chnl %d][val %d]\n",
773 channel, power_limit);
777 power_limit > MAX_POWER_INDEX ? MAX_POWER_INDEX : power_limit;
779 if (_rtl8822be_eq_n_byte(pregulation, (u8 *)("FCC"), 3))
781 else if (_rtl8822be_eq_n_byte(pregulation, (u8 *)("MKK"), 3))
783 else if (_rtl8822be_eq_n_byte(pregulation, (u8 *)("ETSI"), 4))
785 else if (_rtl8822be_eq_n_byte(pregulation, (u8 *)("WW13"), 4))
788 if (_rtl8822be_eq_n_byte(prate_section, (u8 *)("CCK"), 3))
790 else if (_rtl8822be_eq_n_byte(prate_section, (u8 *)("OFDM"), 4))
792 else if (_rtl8822be_eq_n_byte(prate_section, (u8 *)("HT"), 2) &&
793 _rtl8822be_eq_n_byte(prf_path, (u8 *)("1T"), 2))
794 rate_section = HT_MCS0_MCS7;
795 else if (_rtl8822be_eq_n_byte(prate_section, (u8 *)("HT"), 2) &&
796 _rtl8822be_eq_n_byte(prf_path, (u8 *)("2T"), 2))
797 rate_section = HT_MCS8_MCS15;
798 else if (_rtl8822be_eq_n_byte(prate_section, (u8 *)("VHT"), 3) &&
799 _rtl8822be_eq_n_byte(prf_path, (u8 *)("1T"), 2))
800 rate_section = VHT_1SSMCS0_1SSMCS9;
801 else if (_rtl8822be_eq_n_byte(prate_section, (u8 *)("VHT"), 3) &&
802 _rtl8822be_eq_n_byte(prf_path, (u8 *)("2T"), 2))
803 rate_section = VHT_2SSMCS0_2SSMCS9;
805 if (_rtl8822be_eq_n_byte(pbandwidth, (u8 *)("20M"), 3))
806 bandwidth = HT_CHANNEL_WIDTH_20;
807 else if (_rtl8822be_eq_n_byte(pbandwidth, (u8 *)("40M"), 3))
808 bandwidth = HT_CHANNEL_WIDTH_20_40;
809 else if (_rtl8822be_eq_n_byte(pbandwidth, (u8 *)("80M"), 3))
810 bandwidth = HT_CHANNEL_WIDTH_80;
811 else if (_rtl8822be_eq_n_byte(pbandwidth, (u8 *)("160M"), 4))
814 if (_rtl8822be_eq_n_byte(pband, (u8 *)("2.4G"), 4)) {
815 ret = _rtl8822be_phy_get_chnl_idx_of_txpwr_lmt(hw, BAND_ON_2_4G,
824 rtlphy->txpwr_limit_2_4g[regulation][bandwidth]
825 [rate_section][channel_index]
828 if (power_limit < prev_power_limit)
829 rtlphy->txpwr_limit_2_4g[regulation][bandwidth]
830 [rate_section][channel_index]
831 [RF90_PATH_A] = power_limit;
833 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
834 "2.4G [regula %d][bw %d][sec %d][chnl %d][val %d]\n",
835 regulation, bandwidth, rate_section, channel_index,
836 rtlphy->txpwr_limit_2_4g[regulation][bandwidth]
837 [rate_section][channel_index]
839 } else if (_rtl8822be_eq_n_byte(pband, (u8 *)("5G"), 2)) {
840 ret = _rtl8822be_phy_get_chnl_idx_of_txpwr_lmt(hw, BAND_ON_5G,
849 rtlphy->txpwr_limit_5g[regulation][bandwidth]
850 [rate_section][channel_index]
853 if (power_limit < prev_power_limit)
854 rtlphy->txpwr_limit_5g[regulation][bandwidth]
855 [rate_section][channel_index]
856 [RF90_PATH_A] = power_limit;
858 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
859 "5G: [regul %d][bw %d][sec %d][chnl %d][val %d]\n",
860 regulation, bandwidth, rate_section, channel,
861 rtlphy->txpwr_limit_5g[regulation][bandwidth]
862 [rate_section][channel_index]
866 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
867 "Cannot recognize the band info in %s\n", pband);
872 bool rtl8822be_load_txpower_by_rate(struct ieee80211_hw *hw)
874 struct rtl_priv *rtlpriv = rtl_priv(hw);
875 bool rtstatus = true;
877 _rtl8822be_phy_init_tx_power_by_rate(hw);
879 rtstatus = rtlpriv->phydm.ops->phydm_load_txpower_by_rate(rtlpriv);
882 pr_err("BB_PG Reg Fail!!\n");
886 _rtl8822be_phy_txpower_by_rate_configuration(hw);
891 bool rtl8822be_load_txpower_limit(struct ieee80211_hw *hw)
893 struct rtl_priv *rtlpriv = rtl_priv(hw);
894 struct rtl_efuse *rtlefuse = rtl_efuse(rtlpriv);
895 bool rtstatus = true;
897 _rtl8822be_phy_init_txpower_limit(hw);
899 if (rtlefuse->eeprom_regulatory == 1)
904 rtstatus = rtlpriv->phydm.ops->phydm_load_txpower_limit(rtlpriv);
907 pr_err("RF TxPwr Limit Fail!!\n");
911 _rtl8822be_phy_convert_txpower_limit_to_power_index(hw);
916 static void _rtl8822be_get_rate_values_of_tx_power_by_rate(
917 struct ieee80211_hw *hw, u32 reg_addr, u32 bit_mask, u32 value,
918 u8 *rate, s8 *pwr_by_rate_val, u8 *rate_num)
920 struct rtl_priv *rtlpriv = rtl_priv(hw);
921 u8 /*index = 0,*/ i = 0;
924 case 0xE00: /*rTxAGC_A_Rate18_06:*/
925 case 0x830: /*rTxAGC_B_Rate18_06:*/
926 rate[0] = DESC_RATE6M;
927 rate[1] = DESC_RATE9M;
928 rate[2] = DESC_RATE12M;
929 rate[3] = DESC_RATE18M;
930 for (i = 0; i < 4; ++i) {
932 (s8)((((value >> (i * 8 + 4)) & 0xF)) * 10 +
933 ((value >> (i * 8)) & 0xF));
938 case 0xE04: /*rTxAGC_A_Rate54_24:*/
939 case 0x834: /*rTxAGC_B_Rate54_24:*/
940 rate[0] = DESC_RATE24M;
941 rate[1] = DESC_RATE36M;
942 rate[2] = DESC_RATE48M;
943 rate[3] = DESC_RATE54M;
944 for (i = 0; i < 4; ++i) {
946 (s8)((((value >> (i * 8 + 4)) & 0xF)) * 10 +
947 ((value >> (i * 8)) & 0xF));
952 case 0xE08: /*rTxAGC_A_CCK1_Mcs32:*/
953 rate[0] = DESC_RATE1M;
954 pwr_by_rate_val[0] = (s8)((((value >> (8 + 4)) & 0xF)) * 10 +
955 ((value >> 8) & 0xF));
959 case 0x86C: /*rTxAGC_B_CCK11_A_CCK2_11:*/
960 if (bit_mask == 0xffffff00) {
961 rate[0] = DESC_RATE2M;
962 rate[1] = DESC_RATE5_5M;
963 rate[2] = DESC_RATE11M;
964 for (i = 1; i < 4; ++i) {
965 pwr_by_rate_val[i - 1] = (s8)(
966 (((value >> (i * 8 + 4)) & 0xF)) * 10 +
967 ((value >> (i * 8)) & 0xF));
970 } else if (bit_mask == 0x000000ff) {
971 rate[0] = DESC_RATE11M;
972 pwr_by_rate_val[0] = (s8)((((value >> 4) & 0xF)) * 10 +
978 case 0xE10: /*rTxAGC_A_Mcs03_Mcs00:*/
979 case 0x83C: /*rTxAGC_B_Mcs03_Mcs00:*/
980 rate[0] = DESC_RATEMCS0;
981 rate[1] = DESC_RATEMCS1;
982 rate[2] = DESC_RATEMCS2;
983 rate[3] = DESC_RATEMCS3;
984 for (i = 0; i < 4; ++i) {
986 (s8)((((value >> (i * 8 + 4)) & 0xF)) * 10 +
987 ((value >> (i * 8)) & 0xF));
992 case 0xE14: /*rTxAGC_A_Mcs07_Mcs04:*/
993 case 0x848: /*rTxAGC_B_Mcs07_Mcs04:*/
994 rate[0] = DESC_RATEMCS4;
995 rate[1] = DESC_RATEMCS5;
996 rate[2] = DESC_RATEMCS6;
997 rate[3] = DESC_RATEMCS7;
998 for (i = 0; i < 4; ++i) {
1000 (s8)((((value >> (i * 8 + 4)) & 0xF)) * 10 +
1001 ((value >> (i * 8)) & 0xF));
1006 case 0xE18: /*rTxAGC_A_Mcs11_Mcs08:*/
1007 case 0x84C: /*rTxAGC_B_Mcs11_Mcs08:*/
1008 rate[0] = DESC_RATEMCS8;
1009 rate[1] = DESC_RATEMCS9;
1010 rate[2] = DESC_RATEMCS10;
1011 rate[3] = DESC_RATEMCS11;
1012 for (i = 0; i < 4; ++i) {
1013 pwr_by_rate_val[i] =
1014 (s8)((((value >> (i * 8 + 4)) & 0xF)) * 10 +
1015 ((value >> (i * 8)) & 0xF));
1020 case 0xE1C: /*rTxAGC_A_Mcs15_Mcs12:*/
1021 case 0x868: /*rTxAGC_B_Mcs15_Mcs12:*/
1022 rate[0] = DESC_RATEMCS12;
1023 rate[1] = DESC_RATEMCS13;
1024 rate[2] = DESC_RATEMCS14;
1025 rate[3] = DESC_RATEMCS15;
1026 for (i = 0; i < 4; ++i) {
1027 pwr_by_rate_val[i] =
1028 (s8)((((value >> (i * 8 + 4)) & 0xF)) * 10 +
1029 ((value >> (i * 8)) & 0xF));
1035 case 0x838: /*rTxAGC_B_CCK1_55_Mcs32:*/
1036 rate[0] = DESC_RATE1M;
1037 rate[1] = DESC_RATE2M;
1038 rate[2] = DESC_RATE5_5M;
1039 for (i = 1; i < 4; ++i) {
1040 pwr_by_rate_val[i - 1] =
1041 (s8)((((value >> (i * 8 + 4)) & 0xF)) * 10 +
1042 ((value >> (i * 8)) & 0xF));
1051 rate[0] = DESC_RATE1M;
1052 rate[1] = DESC_RATE2M;
1053 rate[2] = DESC_RATE5_5M;
1054 rate[3] = DESC_RATE11M;
1055 for (i = 0; i < 4; ++i) {
1056 pwr_by_rate_val[i] =
1057 (s8)((((value >> (i * 8 + 4)) & 0xF)) * 10 +
1058 ((value >> (i * 8)) & 0xF));
1067 rate[0] = DESC_RATE6M;
1068 rate[1] = DESC_RATE9M;
1069 rate[2] = DESC_RATE12M;
1070 rate[3] = DESC_RATE18M;
1071 for (i = 0; i < 4; ++i) {
1072 pwr_by_rate_val[i] =
1073 (s8)((((value >> (i * 8 + 4)) & 0xF)) * 10 +
1074 ((value >> (i * 8)) & 0xF));
1083 rate[0] = DESC_RATE24M;
1084 rate[1] = DESC_RATE36M;
1085 rate[2] = DESC_RATE48M;
1086 rate[3] = DESC_RATE54M;
1087 for (i = 0; i < 4; ++i) {
1088 pwr_by_rate_val[i] =
1089 (s8)((((value >> (i * 8 + 4)) & 0xF)) * 10 +
1090 ((value >> (i * 8)) & 0xF));
1099 rate[0] = DESC_RATEMCS0;
1100 rate[1] = DESC_RATEMCS1;
1101 rate[2] = DESC_RATEMCS2;
1102 rate[3] = DESC_RATEMCS3;
1103 for (i = 0; i < 4; ++i) {
1104 pwr_by_rate_val[i] =
1105 (s8)((((value >> (i * 8 + 4)) & 0xF)) * 10 +
1106 ((value >> (i * 8)) & 0xF));
1115 rate[0] = DESC_RATEMCS4;
1116 rate[1] = DESC_RATEMCS5;
1117 rate[2] = DESC_RATEMCS6;
1118 rate[3] = DESC_RATEMCS7;
1119 for (i = 0; i < 4; ++i) {
1120 pwr_by_rate_val[i] =
1121 (s8)((((value >> (i * 8 + 4)) & 0xF)) * 10 +
1122 ((value >> (i * 8)) & 0xF));
1131 rate[0] = DESC_RATEMCS8;
1132 rate[1] = DESC_RATEMCS9;
1133 rate[2] = DESC_RATEMCS10;
1134 rate[3] = DESC_RATEMCS11;
1135 for (i = 0; i < 4; ++i) {
1136 pwr_by_rate_val[i] =
1137 (s8)((((value >> (i * 8 + 4)) & 0xF)) * 10 +
1138 ((value >> (i * 8)) & 0xF));
1147 rate[0] = DESC_RATEMCS12;
1148 rate[1] = DESC_RATEMCS13;
1149 rate[2] = DESC_RATEMCS14;
1150 rate[3] = DESC_RATEMCS15;
1151 for (i = 0; i < 4; ++i) {
1152 pwr_by_rate_val[i] =
1153 (s8)((((value >> (i * 8 + 4)) & 0xF)) * 10 +
1154 ((value >> (i * 8)) & 0xF));
1163 rate[0] = DESC_RATEVHT1SS_MCS0;
1164 rate[1] = DESC_RATEVHT1SS_MCS1;
1165 rate[2] = DESC_RATEVHT1SS_MCS2;
1166 rate[3] = DESC_RATEVHT1SS_MCS3;
1167 for (i = 0; i < 4; ++i) {
1168 pwr_by_rate_val[i] =
1169 (s8)((((value >> (i * 8 + 4)) & 0xF)) * 10 +
1170 ((value >> (i * 8)) & 0xF));
1179 rate[0] = DESC_RATEVHT1SS_MCS4;
1180 rate[1] = DESC_RATEVHT1SS_MCS5;
1181 rate[2] = DESC_RATEVHT1SS_MCS6;
1182 rate[3] = DESC_RATEVHT1SS_MCS7;
1183 for (i = 0; i < 4; ++i) {
1184 pwr_by_rate_val[i] =
1185 (s8)((((value >> (i * 8 + 4)) & 0xF)) * 10 +
1186 ((value >> (i * 8)) & 0xF));
1195 rate[0] = DESC_RATEVHT1SS_MCS8;
1196 rate[1] = DESC_RATEVHT1SS_MCS9;
1197 rate[2] = DESC_RATEVHT2SS_MCS0;
1198 rate[3] = DESC_RATEVHT2SS_MCS1;
1199 for (i = 0; i < 4; ++i) {
1200 pwr_by_rate_val[i] =
1201 (s8)((((value >> (i * 8 + 4)) & 0xF)) * 10 +
1202 ((value >> (i * 8)) & 0xF));
1211 rate[0] = DESC_RATEVHT2SS_MCS2;
1212 rate[1] = DESC_RATEVHT2SS_MCS3;
1213 rate[2] = DESC_RATEVHT2SS_MCS4;
1214 rate[3] = DESC_RATEVHT2SS_MCS5;
1215 for (i = 0; i < 4; ++i) {
1216 pwr_by_rate_val[i] =
1217 (s8)((((value >> (i * 8 + 4)) & 0xF)) * 10 +
1218 ((value >> (i * 8)) & 0xF));
1227 rate[0] = DESC_RATEVHT2SS_MCS6;
1228 rate[1] = DESC_RATEVHT2SS_MCS7;
1229 rate[2] = DESC_RATEVHT2SS_MCS8;
1230 rate[3] = DESC_RATEVHT2SS_MCS9;
1231 for (i = 0; i < 4; ++i) {
1232 pwr_by_rate_val[i] =
1233 (s8)((((value >> (i * 8 + 4)) & 0xF)) * 10 +
1234 ((value >> (i * 8)) & 0xF));
1240 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1241 "Invalid reg_addr 0x%x in %s()\n", reg_addr, __func__);
1246 void rtl8822be_store_tx_power_by_rate(struct ieee80211_hw *hw, u32 band,
1247 u32 rfpath, u32 txnum, u32 regaddr,
1248 u32 bitmask, u32 data)
1250 struct rtl_priv *rtlpriv = rtl_priv(hw);
1251 struct rtl_phy *rtlphy = &rtlpriv->phy;
1252 u8 i = 0, rates[4] = {0}, rate_num = 0;
1253 s8 pwr_by_rate_val[4] = {0};
1255 _rtl8822be_get_rate_values_of_tx_power_by_rate(
1256 hw, regaddr, bitmask, data, rates, pwr_by_rate_val, &rate_num);
1258 if (band != BAND_ON_2_4G && band != BAND_ON_5G) {
1259 RT_TRACE(rtlpriv, COMP_INIT, DBG_WARNING, "Invalid Band %d\n",
1261 band = BAND_ON_2_4G;
1263 if (rfpath >= MAX_RF_PATH) {
1264 RT_TRACE(rtlpriv, COMP_INIT, DBG_WARNING, "Invalid RfPath %d\n",
1266 rfpath = MAX_RF_PATH - 1;
1268 if (txnum >= MAX_RF_PATH) {
1269 RT_TRACE(rtlpriv, COMP_INIT, DBG_WARNING, "Invalid TxNum %d\n",
1271 txnum = MAX_RF_PATH - 1;
1274 for (i = 0; i < rate_num; ++i) {
1275 u8 rate_idx = rates[i];
1277 if (IS_1T_RATE(rates[i]))
1279 else if (IS_2T_RATE(rates[i]))
1284 rtlphy->tx_power_by_rate_offset[band][rfpath][txnum][rate_idx] =
1288 rtlpriv, COMP_INIT, DBG_LOUD,
1289 "TxPwrByRateOffset[Band %d][RfPath %d][TxNum %d][rate_idx %d] = 0x%x\n",
1290 band, rfpath, txnum, rate_idx,
1291 rtlphy->tx_power_by_rate_offset[band][rfpath][txnum]
1297 _rtl8822be_phy_init_bb_rf_register_definition(struct ieee80211_hw *hw)
1299 struct rtl_priv *rtlpriv = rtl_priv(hw);
1300 struct rtl_phy *rtlphy = &rtlpriv->phy;
1302 rtlphy->phyreg_def[RF90_PATH_A].rfintfs = RFPGA0_XAB_RFINTERFACESW;
1303 rtlphy->phyreg_def[RF90_PATH_B].rfintfs = RFPGA0_XAB_RFINTERFACESW;
1305 rtlphy->phyreg_def[RF90_PATH_A].rfintfo = RFPGA0_XA_RFINTERFACEOE;
1306 rtlphy->phyreg_def[RF90_PATH_B].rfintfo = RFPGA0_XB_RFINTERFACEOE;
1308 rtlphy->phyreg_def[RF90_PATH_A].rfintfe = RFPGA0_XA_RFINTERFACEOE;
1309 rtlphy->phyreg_def[RF90_PATH_B].rfintfe = RFPGA0_XB_RFINTERFACEOE;
1311 rtlphy->phyreg_def[RF90_PATH_A].rf3wire_offset = RA_LSSIWRITE_8822B;
1312 rtlphy->phyreg_def[RF90_PATH_B].rf3wire_offset = RB_LSSIWRITE_8822B;
1314 rtlphy->phyreg_def[RF90_PATH_A].rfhssi_para2 = RHSSIREAD_8822BE;
1315 rtlphy->phyreg_def[RF90_PATH_B].rfhssi_para2 = RHSSIREAD_8822BE;
1317 rtlphy->phyreg_def[RF90_PATH_A].rf_rb = RA_SIREAD_8822B;
1318 rtlphy->phyreg_def[RF90_PATH_B].rf_rb = RB_SIREAD_8822B;
1320 rtlphy->phyreg_def[RF90_PATH_A].rf_rbpi = RA_PIREAD_8822B;
1321 rtlphy->phyreg_def[RF90_PATH_B].rf_rbpi = RB_PIREAD_8822B;
1324 void rtl8822be_phy_get_txpower_level(struct ieee80211_hw *hw, long *powerlevel)
1326 struct rtl_priv *rtlpriv = rtl_priv(hw);
1327 struct rtl_phy *rtlphy = &rtlpriv->phy;
1331 txpwr_level = rtlphy->cur_cck_txpwridx;
1332 txpwr_dbm = _rtl8822be_phy_txpwr_idx_to_dbm(hw, WIRELESS_MODE_B,
1334 txpwr_level = rtlphy->cur_ofdm24g_txpwridx;
1335 if (_rtl8822be_phy_txpwr_idx_to_dbm(hw, WIRELESS_MODE_G, txpwr_level) >
1337 txpwr_dbm = _rtl8822be_phy_txpwr_idx_to_dbm(hw, WIRELESS_MODE_G,
1339 txpwr_level = rtlphy->cur_ofdm24g_txpwridx;
1340 if (_rtl8822be_phy_txpwr_idx_to_dbm(hw, WIRELESS_MODE_N_24G,
1341 txpwr_level) > txpwr_dbm)
1342 txpwr_dbm = _rtl8822be_phy_txpwr_idx_to_dbm(
1343 hw, WIRELESS_MODE_N_24G, txpwr_level);
1344 *powerlevel = txpwr_dbm;
1347 static bool _rtl8822be_phy_get_chnl_index(u8 channel, u8 *chnl_index)
1349 u8 rtl_channel5g[CHANNEL_MAX_NUMBER_5G] = {
1350 36, 38, 40, 42, 44, 46, 48, /* Band 1 */
1351 52, 54, 56, 58, 60, 62, 64, /* Band 2 */
1352 100, 102, 104, 106, 108, 110, 112, /* Band 3 */
1353 116, 118, 120, 122, 124, 126, 128, /* Band 3 */
1354 132, 134, 136, 138, 140, 142, 144, /* Band 3 */
1355 149, 151, 153, 155, 157, 159, 161, /* Band 4 */
1356 165, 167, 169, 171, 173, 175, 177}; /* Band 4 */
1360 if (channel <= 14) {
1362 *chnl_index = channel - 1;
1366 for (i = 0; i < CHANNEL_MAX_NUMBER_5G; ++i) {
1367 if (rtl_channel5g[i] == channel) {
1376 static char _rtl8822be_phy_get_world_wide_limit(char *limit_table)
1378 char min = limit_table[0];
1381 for (i = 0; i < MAX_REGULATION_NUM; ++i) {
1382 if (limit_table[i] < min)
1383 min = limit_table[i];
1388 static char _rtl8822be_phy_get_txpower_limit(struct ieee80211_hw *hw, u8 band,
1389 enum ht_channel_width bandwidth,
1390 enum radio_path rf_path, u8 rate,
1393 struct rtl_priv *rtlpriv = rtl_priv(hw);
1394 struct rtl_efuse *rtlefuse = rtl_efuse(rtlpriv);
1395 struct rtl_phy *rtlphy = &rtlpriv->phy;
1396 short regulation = -1, rate_section = -1, channel_index = -1;
1397 char power_limit = MAX_POWER_INDEX;
1399 if (rtlefuse->eeprom_regulatory == 2)
1400 return MAX_POWER_INDEX;
1402 regulation = TXPWR_LMT_WW;
1420 rate_section = OFDM;
1431 rate_section = HT_MCS0_MCS7;
1436 case DESC_RATEMCS10:
1437 case DESC_RATEMCS11:
1438 case DESC_RATEMCS12:
1439 case DESC_RATEMCS13:
1440 case DESC_RATEMCS14:
1441 case DESC_RATEMCS15:
1442 rate_section = HT_MCS8_MCS15;
1445 case DESC_RATEVHT1SS_MCS0:
1446 case DESC_RATEVHT1SS_MCS1:
1447 case DESC_RATEVHT1SS_MCS2:
1448 case DESC_RATEVHT1SS_MCS3:
1449 case DESC_RATEVHT1SS_MCS4:
1450 case DESC_RATEVHT1SS_MCS5:
1451 case DESC_RATEVHT1SS_MCS6:
1452 case DESC_RATEVHT1SS_MCS7:
1453 case DESC_RATEVHT1SS_MCS8:
1454 case DESC_RATEVHT1SS_MCS9:
1455 rate_section = VHT_1SSMCS0_1SSMCS9;
1458 case DESC_RATEVHT2SS_MCS0:
1459 case DESC_RATEVHT2SS_MCS1:
1460 case DESC_RATEVHT2SS_MCS2:
1461 case DESC_RATEVHT2SS_MCS3:
1462 case DESC_RATEVHT2SS_MCS4:
1463 case DESC_RATEVHT2SS_MCS5:
1464 case DESC_RATEVHT2SS_MCS6:
1465 case DESC_RATEVHT2SS_MCS7:
1466 case DESC_RATEVHT2SS_MCS8:
1467 case DESC_RATEVHT2SS_MCS9:
1468 rate_section = VHT_2SSMCS0_2SSMCS9;
1472 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, "Wrong rate 0x%x\n",
1477 if (band == BAND_ON_5G && rate_section == 0)
1478 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
1479 "Wrong rate 0x%x: No CCK in 5G Band\n", rate);
1481 /* workaround for wrong index combination to obtain tx power limit,
1482 * OFDM only exists in BW 20M
1484 if (rate_section == 1)
1487 /* workaround for wrong index combination to obtain tx power limit,
1488 * CCK table will only be given in BW 20M
1490 if (rate_section == 0)
1493 /* workaround for wrong indxe combination to obtain tx power limit,
1494 * HT on 80M will reference to HT on 40M
1496 if ((rate_section == 2 || rate_section == 3) && band == BAND_ON_5G &&
1500 if (band == BAND_ON_2_4G)
1501 channel_index = _rtl8822be_phy_get_chnl_idx_of_txpwr_lmt(
1502 hw, BAND_ON_2_4G, channel);
1503 else if (band == BAND_ON_5G)
1504 channel_index = _rtl8822be_phy_get_chnl_idx_of_txpwr_lmt(
1505 hw, BAND_ON_5G, channel);
1506 else if (band == BAND_ON_BOTH)
1507 ; /* BAND_ON_BOTH don't care temporarily */
1509 if (band >= BANDMAX || regulation == -1 || bandwidth == -1 ||
1510 rate_section == -1 || channel_index == -1) {
1512 rtlpriv, COMP_POWER, DBG_LOUD,
1513 "Wrong index value to access power limit table [band %d][regulation %d][bandwidth %d][rf_path %d][rate_section %d][chnl %d]\n",
1514 band, regulation, bandwidth, rf_path, rate_section,
1516 return MAX_POWER_INDEX;
1519 if (band == BAND_ON_2_4G) {
1520 char limits[10] = {0};
1523 for (i = 0; i < 4; ++i)
1524 limits[i] = rtlphy->txpwr_limit_2_4g[i][bandwidth]
1530 (regulation == TXPWR_LMT_WW) ?
1531 _rtl8822be_phy_get_world_wide_limit(limits) :
1532 rtlphy->txpwr_limit_2_4g[regulation][bandwidth]
1537 } else if (band == BAND_ON_5G) {
1538 char limits[10] = {0};
1541 for (i = 0; i < MAX_REGULATION_NUM; ++i)
1543 rtlphy->txpwr_limit_5g[i][bandwidth]
1545 [channel_index][rf_path];
1548 (regulation == TXPWR_LMT_WW) ?
1549 _rtl8822be_phy_get_world_wide_limit(limits) :
1550 rtlphy->txpwr_limit_5g[regulation]
1553 [channel_index][rf_path];
1555 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1556 "No power limit table of the specified band\n");
1563 _rtl8822be_phy_get_txpower_by_rate(struct ieee80211_hw *hw, u8 band, u8 path,
1564 u8 rate /* enum rtl_desc8822b_rate */)
1566 struct rtl_priv *rtlpriv = rtl_priv(hw);
1567 struct rtl_phy *rtlphy = &rtlpriv->phy;
1569 char tx_pwr_diff = 0;
1571 if (band != BAND_ON_2_4G && band != BAND_ON_5G)
1574 if (path > RF90_PATH_B)
1577 if ((rate >= DESC_RATEMCS8 && rate <= DESC_RATEMCS15) ||
1578 (rate >= DESC_RATEVHT2SS_MCS0 && rate <= DESC_RATEVHT2SS_MCS9))
1583 tx_pwr_diff = (char)(rtlphy->tx_power_by_rate_offset[band][path][tx_num]
1590 u8 rtl8822be_get_txpower_index(struct ieee80211_hw *hw, u8 path, u8 rate,
1591 u8 bandwidth, u8 channel)
1593 struct rtl_priv *rtlpriv = rtl_priv(hw);
1594 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
1595 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1596 u8 index = (channel - 1);
1598 bool in_24g = false;
1600 char powerdiff_byrate = 0;
1602 if ((rtlhal->current_bandtype == BAND_ON_2_4G &&
1603 (channel > 14 || channel < 1)) ||
1604 (rtlhal->current_bandtype == BAND_ON_5G && channel <= 14)) {
1606 RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
1607 "Illegal channel!!\n");
1610 /* 1. base tx power */
1611 in_24g = _rtl8822be_phy_get_chnl_index(channel, &index);
1613 if (RX_HAL_IS_CCK_RATE(rate))
1614 txpower = rtlefuse->txpwrlevel_cck[path][index];
1615 else if (rate >= DESC_RATE6M)
1616 txpower = rtlefuse->txpwrlevel_ht40_1s[path][index];
1618 RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
1621 if (rate >= DESC_RATE6M && rate <= DESC_RATE54M &&
1622 !RX_HAL_IS_CCK_RATE(rate))
1623 txpower += rtlefuse->txpwr_legacyhtdiff[path][TX_1S];
1625 if (bandwidth == HT_CHANNEL_WIDTH_20) {
1626 if ((rate >= DESC_RATEMCS0 && rate <= DESC_RATEMCS15) ||
1627 (rate >= DESC_RATEVHT1SS_MCS0 &&
1628 rate <= DESC_RATEVHT2SS_MCS9))
1630 rtlefuse->txpwr_ht20diff[path][TX_1S];
1631 if ((rate >= DESC_RATEMCS8 && rate <= DESC_RATEMCS15) ||
1632 (rate >= DESC_RATEVHT2SS_MCS0 &&
1633 rate <= DESC_RATEVHT2SS_MCS9))
1635 rtlefuse->txpwr_ht20diff[path][TX_2S];
1636 } else if (bandwidth == HT_CHANNEL_WIDTH_20_40) {
1637 if ((rate >= DESC_RATEMCS0 && rate <= DESC_RATEMCS15) ||
1638 (rate >= DESC_RATEVHT1SS_MCS0 &&
1639 rate <= DESC_RATEVHT2SS_MCS9))
1641 rtlefuse->txpwr_ht40diff[path][TX_1S];
1642 if ((rate >= DESC_RATEMCS8 && rate <= DESC_RATEMCS15) ||
1643 (rate >= DESC_RATEVHT2SS_MCS0 &&
1644 rate <= DESC_RATEVHT2SS_MCS9))
1646 rtlefuse->txpwr_ht40diff[path][TX_2S];
1647 } else if (bandwidth == HT_CHANNEL_WIDTH_80) {
1648 if ((rate >= DESC_RATEMCS0 && rate <= DESC_RATEMCS15) ||
1649 (rate >= DESC_RATEVHT1SS_MCS0 &&
1650 rate <= DESC_RATEVHT2SS_MCS9))
1652 rtlefuse->txpwr_ht40diff[path][TX_1S];
1653 if ((rate >= DESC_RATEMCS8 && rate <= DESC_RATEMCS15) ||
1654 (rate >= DESC_RATEVHT2SS_MCS0 &&
1655 rate <= DESC_RATEVHT2SS_MCS9))
1657 rtlefuse->txpwr_ht40diff[path][TX_2S];
1661 if (rate >= DESC_RATE6M)
1662 txpower = rtlefuse->txpwr_5g_bw40base[path][index];
1664 RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_WARNING,
1667 if (rate >= DESC_RATE6M && rate <= DESC_RATE54M &&
1668 !RX_HAL_IS_CCK_RATE(rate))
1669 txpower += rtlefuse->txpwr_5g_ofdmdiff[path][TX_1S];
1671 if (bandwidth == HT_CHANNEL_WIDTH_20) {
1672 if ((rate >= DESC_RATEMCS0 && rate <= DESC_RATEMCS15) ||
1673 (rate >= DESC_RATEVHT1SS_MCS0 &&
1674 rate <= DESC_RATEVHT2SS_MCS9))
1675 txpower += rtlefuse->txpwr_5g_bw20diff[path]
1677 if ((rate >= DESC_RATEMCS8 && rate <= DESC_RATEMCS15) ||
1678 (rate >= DESC_RATEVHT2SS_MCS0 &&
1679 rate <= DESC_RATEVHT2SS_MCS9))
1680 txpower += rtlefuse->txpwr_5g_bw20diff[path]
1682 } else if (bandwidth == HT_CHANNEL_WIDTH_20_40) {
1683 if ((rate >= DESC_RATEMCS0 && rate <= DESC_RATEMCS15) ||
1684 (rate >= DESC_RATEVHT1SS_MCS0 &&
1685 rate <= DESC_RATEVHT2SS_MCS9))
1686 txpower += rtlefuse->txpwr_5g_bw40diff[path]
1688 if ((rate >= DESC_RATEMCS8 && rate <= DESC_RATEMCS15) ||
1689 (rate >= DESC_RATEVHT2SS_MCS0 &&
1690 rate <= DESC_RATEVHT2SS_MCS9))
1691 txpower += rtlefuse->txpwr_5g_bw40diff[path]
1693 } else if (bandwidth == HT_CHANNEL_WIDTH_80) {
1696 for (i = 0; i < sizeof(rtl_channel5g_80m) / sizeof(u8);
1698 if (rtl_channel5g_80m[i] == channel)
1701 txpower = rtlefuse->txpwr_5g_bw80base[path][index];
1703 if ((rate >= DESC_RATEMCS0 && rate <= DESC_RATEMCS15) ||
1704 (rate >= DESC_RATEVHT1SS_MCS0 &&
1705 rate <= DESC_RATEVHT2SS_MCS9))
1706 txpower += rtlefuse->txpwr_5g_bw80diff[path]
1708 if ((rate >= DESC_RATEMCS8 && rate <= DESC_RATEMCS15) ||
1709 (rate >= DESC_RATEVHT2SS_MCS0 &&
1710 rate <= DESC_RATEVHT2SS_MCS9))
1711 txpower += rtlefuse->txpwr_5g_bw80diff[path]
1716 /* 2. tx power by rate */
1717 if (rtlefuse->eeprom_regulatory != 2)
1718 powerdiff_byrate = _rtl8822be_phy_get_txpower_by_rate(
1719 hw, (u8)(!in_24g), path, rate);
1721 /* 3. tx power limit */
1722 if (rtlefuse->eeprom_regulatory == 1)
1723 limit = _rtl8822be_phy_get_txpower_limit(
1724 hw, (u8)(!in_24g), bandwidth, path, rate,
1727 limit = MAX_POWER_INDEX;
1730 powerdiff_byrate = powerdiff_byrate > limit ? limit : powerdiff_byrate;
1732 txpower += powerdiff_byrate;
1734 if (txpower > MAX_POWER_INDEX)
1735 txpower = MAX_POWER_INDEX;
1740 static void _rtl8822be_phy_set_txpower_index(struct ieee80211_hw *hw,
1741 u8 power_index, u8 path, u8 rate)
1743 struct rtl_priv *rtlpriv = rtl_priv(hw);
1748 * For 8822B, phydm api use 4 bytes txagc value driver must
1749 * combine every four 1 byte to one 4 byte and send to phydm
1751 shift = rate & 0x03;
1752 index |= ((u32)power_index << (shift * 8));
1757 if (!rtlpriv->phydm.ops->phydm_write_txagc(rtlpriv, index, path,
1759 RT_TRACE(rtlpriv, COMP_TXAGC, DBG_LOUD,
1760 "%s(index:%d, rfpath:%d, rate:0x%02x) fail\n",
1761 __func__, index, path, rate);
1769 static void _rtl8822be_phy_set_txpower_level_by_path(struct ieee80211_hw *hw,
1771 u8 channel, u8 size)
1773 struct rtl_phy *rtlphy = &(rtl_priv(hw)->phy);
1777 for (i = 0; i < size; i++) {
1778 power_index = rtl8822be_get_txpower_index(
1779 hw, path, array[i], rtlphy->current_chan_bw, channel);
1780 _rtl8822be_phy_set_txpower_index(hw, power_index, path,
1785 void rtl8822be_phy_set_txpower_level_by_path(struct ieee80211_hw *hw,
1786 u8 channel, u8 path)
1788 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1791 * Below order is *VERY* important!
1792 * Because _rtl8822be_phy_set_txpower_index() do actually writing
1793 * every four power values.
1795 if (rtlhal->current_bandtype == BAND_ON_2_4G)
1796 _rtl8822be_phy_set_txpower_level_by_path(
1797 hw, cck_rates, path, channel, sizes_of_cck_retes);
1798 _rtl8822be_phy_set_txpower_level_by_path(hw, ofdm_rates, path, channel,
1799 sizes_of_ofdm_retes);
1800 _rtl8822be_phy_set_txpower_level_by_path(hw, ht_rates_1t, path, channel,
1801 sizes_of_ht_retes_1t);
1802 _rtl8822be_phy_set_txpower_level_by_path(hw, ht_rates_2t, path, channel,
1803 sizes_of_ht_retes_2t);
1804 _rtl8822be_phy_set_txpower_level_by_path(hw, vht_rates_1t, path,
1805 channel, sizes_of_vht_retes);
1806 _rtl8822be_phy_set_txpower_level_by_path(hw, vht_rates_2t, path,
1807 channel, sizes_of_vht_retes);
1810 void rtl8822be_phy_set_tx_power_index_by_rs(struct ieee80211_hw *hw, u8 channel,
1811 u8 path, enum rate_section rs)
1816 } rs_ref[MAX_RATE_SECTION] = {
1817 {cck_rates, sizes_of_cck_retes},
1818 {ofdm_rates, sizes_of_ofdm_retes},
1819 {ht_rates_1t, sizes_of_ht_retes_1t},
1820 {ht_rates_2t, sizes_of_ht_retes_2t},
1821 {vht_rates_1t, sizes_of_vht_retes},
1822 {vht_rates_2t, sizes_of_vht_retes},
1825 if (rs >= MAX_RATE_SECTION)
1828 _rtl8822be_phy_set_txpower_level_by_path(hw, rs_ref[rs].array, path,
1829 channel, rs_ref[rs].size);
1832 void rtl8822be_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel)
1834 struct rtl_priv *rtlpriv = rtl_priv(hw);
1835 struct rtl_phy *rtlphy = &rtlpriv->phy;
1838 for (path = RF90_PATH_A; path < rtlphy->num_total_rfpath; ++path)
1839 rtl8822be_phy_set_txpower_level_by_path(hw, channel, path);
1842 static long _rtl8822be_phy_txpwr_idx_to_dbm(struct ieee80211_hw *hw,
1843 enum wireless_mode wirelessmode,
1849 switch (wirelessmode) {
1850 case WIRELESS_MODE_B:
1853 case WIRELESS_MODE_G:
1854 case WIRELESS_MODE_N_24G:
1861 pwrout_dbm = txpwridx / 2 + offset;
1865 void rtl8822be_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation)
1867 struct rtl_priv *rtlpriv = rtl_priv(hw);
1868 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1869 enum io_type iotype = IO_CMD_PAUSE_BAND0_DM_BY_SCAN;
1871 if (!is_hal_stop(rtlhal)) {
1872 switch (operation) {
1873 case SCAN_OPT_BACKUP_BAND0:
1874 iotype = IO_CMD_PAUSE_BAND0_DM_BY_SCAN;
1875 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_IO_CMD,
1879 case SCAN_OPT_BACKUP_BAND1:
1880 iotype = IO_CMD_PAUSE_BAND1_DM_BY_SCAN;
1881 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_IO_CMD,
1885 case SCAN_OPT_RESTORE:
1886 iotype = IO_CMD_RESUME_DM_BY_SCAN;
1887 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_IO_CMD,
1891 pr_err("Unknown Scan Backup operation.\n");
1897 static u8 _rtl8822be_phy_get_pri_ch_id(struct rtl_priv *rtlpriv)
1899 struct rtl_phy *rtlphy = &rtlpriv->phy;
1900 struct rtl_mac *mac = rtl_mac(rtlpriv);
1903 if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_80) {
1904 /* primary channel is at lower subband of 80MHz & 40MHz */
1905 if (mac->cur_40_prime_sc == HAL_PRIME_CHNL_OFFSET_LOWER &&
1906 mac->cur_80_prime_sc == HAL_PRIME_CHNL_OFFSET_LOWER) {
1907 pri_ch_idx = VHT_DATA_SC_20_LOWEST_OF_80MHZ;
1908 /* primary channel is at
1909 * lower subband of 80MHz & upper subband of 40MHz
1911 } else if ((mac->cur_40_prime_sc ==
1912 HAL_PRIME_CHNL_OFFSET_UPPER) &&
1913 (mac->cur_80_prime_sc ==
1914 HAL_PRIME_CHNL_OFFSET_LOWER)) {
1915 pri_ch_idx = VHT_DATA_SC_20_LOWER_OF_80MHZ;
1916 /* primary channel is at
1917 * upper subband of 80MHz & lower subband of 40MHz
1919 } else if ((mac->cur_40_prime_sc ==
1920 HAL_PRIME_CHNL_OFFSET_LOWER) &&
1921 (mac->cur_80_prime_sc ==
1922 HAL_PRIME_CHNL_OFFSET_UPPER)) {
1923 pri_ch_idx = VHT_DATA_SC_20_UPPER_OF_80MHZ;
1924 /* primary channel is at
1925 * upper subband of 80MHz & upper subband of 40MHz
1927 } else if ((mac->cur_40_prime_sc ==
1928 HAL_PRIME_CHNL_OFFSET_UPPER) &&
1929 (mac->cur_80_prime_sc ==
1930 HAL_PRIME_CHNL_OFFSET_UPPER)) {
1931 pri_ch_idx = VHT_DATA_SC_20_UPPERST_OF_80MHZ;
1933 if (mac->cur_80_prime_sc == HAL_PRIME_CHNL_OFFSET_LOWER)
1934 pri_ch_idx = VHT_DATA_SC_40_LOWER_OF_80MHZ;
1935 else if (mac->cur_80_prime_sc ==
1936 HAL_PRIME_CHNL_OFFSET_UPPER)
1937 pri_ch_idx = VHT_DATA_SC_40_UPPER_OF_80MHZ;
1939 } else if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20_40) {
1940 /* primary channel is at upper subband of 40MHz */
1941 if (mac->cur_40_prime_sc == HAL_PRIME_CHNL_OFFSET_UPPER)
1942 pri_ch_idx = VHT_DATA_SC_20_UPPER_OF_80MHZ;
1943 /* primary channel is at lower subband of 40MHz */
1944 else if (mac->cur_40_prime_sc == HAL_PRIME_CHNL_OFFSET_LOWER)
1945 pri_ch_idx = VHT_DATA_SC_20_LOWER_OF_80MHZ;
1953 void rtl8822be_phy_set_bw_mode(struct ieee80211_hw *hw,
1954 enum nl80211_channel_type ch_type)
1956 struct rtl_priv *rtlpriv = rtl_priv(hw);
1957 struct rtl_phy *rtlphy = &rtlpriv->phy;
1958 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1959 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1960 u8 tmp_bw = rtlphy->current_chan_bw;
1962 if (rtlphy->set_bwmode_inprogress)
1964 rtlphy->set_bwmode_inprogress = true;
1965 if ((!is_hal_stop(rtlhal)) && !(RT_CANNOT_IO(hw))) {
1966 /* get primary channel index */
1967 u8 pri_ch_idx = _rtl8822be_phy_get_pri_ch_id(rtlpriv);
1969 /* 3.1 set MAC register */
1970 rtlpriv->halmac.ops->halmac_set_bandwidth(
1971 rtlpriv, rtlphy->current_channel, pri_ch_idx,
1972 rtlphy->current_chan_bw);
1974 /* 3.2 set BB/RF registet */
1975 rtlpriv->phydm.ops->phydm_switch_bandwidth(
1976 rtlpriv, pri_ch_idx, rtlphy->current_chan_bw);
1978 if (!mac->act_scanning)
1979 rtlpriv->phydm.ops->phydm_iq_calibrate(rtlpriv);
1981 rtlphy->set_bwmode_inprogress = false;
1983 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
1984 "FALSE driver sleep or unload\n");
1985 rtlphy->set_bwmode_inprogress = false;
1986 rtlphy->current_chan_bw = tmp_bw;
1990 u8 rtl8822be_phy_sw_chnl(struct ieee80211_hw *hw)
1992 struct rtl_priv *rtlpriv = rtl_priv(hw);
1993 struct rtl_phy *rtlphy = &rtlpriv->phy;
1994 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1995 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1996 u32 timeout = 1000, timecount = 0;
1997 u8 channel = rtlphy->current_channel;
1999 if (rtlphy->sw_chnl_inprogress)
2001 if (rtlphy->set_bwmode_inprogress)
2004 if ((is_hal_stop(rtlhal)) || (RT_CANNOT_IO(hw))) {
2005 RT_TRACE(rtlpriv, COMP_CHAN, DBG_LOUD,
2006 "sw_chnl_inprogress false driver sleep or unload\n");
2009 while (rtlphy->lck_inprogress && timecount < timeout) {
2014 if (rtlphy->current_channel > 14)
2015 rtlhal->current_bandtype = BAND_ON_5G;
2016 else if (rtlphy->current_channel <= 14)
2017 rtlhal->current_bandtype = BAND_ON_2_4G;
2019 if (rtlpriv->cfg->ops->get_btc_status())
2020 rtlpriv->btcoexist.btc_ops->btc_switch_band_notify(
2021 rtlpriv, rtlhal->current_bandtype, mac->act_scanning);
2023 rtlpriv->btcoexist.btc_ops->btc_switch_band_notify_wifi_only(
2024 rtlpriv, rtlhal->current_bandtype, mac->act_scanning);
2026 rtlpriv->phydm.ops->phydm_switch_band(rtlpriv, rtlphy->current_channel);
2028 rtlphy->sw_chnl_inprogress = true;
2032 RT_TRACE(rtlpriv, COMP_SCAN, DBG_TRACE,
2033 "switch to channel%d, band type is %d\n",
2034 rtlphy->current_channel, rtlhal->current_bandtype);
2036 rtlpriv->phydm.ops->phydm_switch_channel(rtlpriv,
2037 rtlphy->current_channel);
2039 rtlpriv->phydm.ops->phydm_clear_txpowertracking_state(rtlpriv);
2041 rtl8822be_phy_set_txpower_level(hw, rtlphy->current_channel);
2043 RT_TRACE(rtlpriv, COMP_SCAN, DBG_TRACE, "\n");
2044 rtlphy->sw_chnl_inprogress = false;
2048 bool rtl8822be_phy_set_io_cmd(struct ieee80211_hw *hw, enum io_type iotype)
2050 struct rtl_priv *rtlpriv = rtl_priv(hw);
2051 struct rtl_phy *rtlphy = &rtlpriv->phy;
2052 bool postprocessing = false;
2054 RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE,
2055 "-->IO Cmd(%#x), set_io_inprogress(%d)\n", iotype,
2056 rtlphy->set_io_inprogress);
2059 case IO_CMD_RESUME_DM_BY_SCAN:
2060 RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE,
2061 "[IO CMD] Resume DM after scan.\n");
2062 postprocessing = true;
2064 case IO_CMD_PAUSE_BAND0_DM_BY_SCAN:
2065 case IO_CMD_PAUSE_BAND1_DM_BY_SCAN:
2066 RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE,
2067 "[IO CMD] Pause DM before scan.\n");
2068 postprocessing = true;
2071 pr_err("switch case not process\n");
2075 if (postprocessing && !rtlphy->set_io_inprogress) {
2076 rtlphy->set_io_inprogress = true;
2077 rtlphy->current_io_type = iotype;
2081 rtl8822be_phy_set_io(hw);
2082 RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE, "IO Type(%#x)\n", iotype);
2086 static void rtl8822be_phy_set_io(struct ieee80211_hw *hw)
2088 struct rtl_priv *rtlpriv = rtl_priv(hw);
2089 struct rtl_phy *rtlphy = &rtlpriv->phy;
2091 RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE,
2092 "--->Cmd(%#x), set_io_inprogress(%d)\n",
2093 rtlphy->current_io_type, rtlphy->set_io_inprogress);
2094 switch (rtlphy->current_io_type) {
2095 case IO_CMD_RESUME_DM_BY_SCAN:
2097 case IO_CMD_PAUSE_BAND0_DM_BY_SCAN:
2099 case IO_CMD_PAUSE_BAND1_DM_BY_SCAN:
2102 pr_err("switch case not process\n");
2105 rtlphy->set_io_inprogress = false;
2106 RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE, "(%#x)\n",
2107 rtlphy->current_io_type);
2110 static void rtl8822be_phy_set_rf_on(struct ieee80211_hw *hw)
2112 struct rtl_priv *rtlpriv = rtl_priv(hw);
2114 rtl_write_byte(rtlpriv, REG_SPS0_CTRL_8822B, 0x2b);
2115 rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN_8822B, 0xE3);
2116 rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN_8822B, 0xE2);
2117 rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN_8822B, 0xE3);
2118 rtl_write_byte(rtlpriv, REG_TXPAUSE_8822B, 0x00);
2121 static bool _rtl8822be_phy_set_rf_power_state(struct ieee80211_hw *hw,
2122 enum rf_pwrstate rfpwr_state)
2124 struct rtl_priv *rtlpriv = rtl_priv(hw);
2125 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
2126 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
2127 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
2128 bool bresult = true;
2130 struct rtl8192_tx_ring *ring = NULL;
2132 switch (rfpwr_state) {
2134 if (ppsc->rfpwr_state == ERFOFF &&
2135 RT_IN_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC)) {
2136 bool rtstatus = false;
2137 u32 initialize_count = 0;
2141 RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
2142 "IPS Set eRf nic enable\n");
2143 rtstatus = rtl_ps_enable_nic(hw);
2144 } while ((!rtstatus) && (initialize_count < 10));
2145 RT_CLEAR_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
2147 RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
2148 "Set ERFON slept:%d ms\n",
2149 jiffies_to_msecs(jiffies -
2150 ppsc->last_sleep_jiffies));
2151 ppsc->last_awake_jiffies = jiffies;
2152 rtl8822be_phy_set_rf_on(hw);
2154 if (mac->link_state == MAC80211_LINKED)
2155 rtlpriv->cfg->ops->led_control(hw, LED_CTL_LINK);
2157 rtlpriv->cfg->ops->led_control(hw, LED_CTL_NO_LINK);
2160 for (queue_id = 0, i = 0;
2161 queue_id < RTL_PCI_MAX_TX_QUEUE_COUNT;) {
2162 ring = &pcipriv->dev.tx_ring[queue_id];
2163 if (queue_id == BEACON_QUEUE ||
2164 skb_queue_len(&ring->queue) == 0) {
2169 rtlpriv, COMP_ERR, DBG_WARNING,
2170 "eRf Off/Sleep: %d times TcbBusyQueue[%d] =%d before doze!\n",
2172 skb_queue_len(&ring->queue));
2177 if (i >= MAX_DOZE_WAITING_TIMES_9x) {
2179 rtlpriv, COMP_ERR, DBG_WARNING,
2180 "\n ERFSLEEP: %d times TcbBusyQueue[%d] = %d !\n",
2181 MAX_DOZE_WAITING_TIMES_9x, queue_id,
2182 skb_queue_len(&ring->queue));
2187 if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC) {
2188 RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
2189 "IPS Set eRf nic disable\n");
2190 rtl_ps_disable_nic(hw);
2191 RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
2193 if (ppsc->rfoff_reason == RF_CHANGE_BY_IPS) {
2194 rtlpriv->cfg->ops->led_control(hw,
2197 rtlpriv->cfg->ops->led_control(
2198 hw, LED_CTL_POWER_OFF);
2203 pr_err("switch case not process\n");
2208 ppsc->rfpwr_state = rfpwr_state;
2212 bool rtl8822be_phy_set_rf_power_state(struct ieee80211_hw *hw,
2213 enum rf_pwrstate rfpwr_state)
2215 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
2217 bool bresult = false;
2219 if (rfpwr_state == ppsc->rfpwr_state)
2221 bresult = _rtl8822be_phy_set_rf_power_state(hw, rfpwr_state);