1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2014 Realtek Corporation.*/
11 static bool _rtl8723be_phy_rf6052_config_parafile(struct ieee80211_hw
*hw
);
13 void rtl8723be_phy_rf6052_set_bandwidth(struct ieee80211_hw
*hw
, u8 bandwidth
)
15 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
16 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
19 case HT_CHANNEL_WIDTH_20
:
20 rtlphy
->rfreg_chnlval
[0] = ((rtlphy
->rfreg_chnlval
[0] &
21 0xfffff3ff) | BIT(10) | BIT(11));
22 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_CHNLBW
, RFREG_OFFSET_MASK
,
23 rtlphy
->rfreg_chnlval
[0]);
25 case HT_CHANNEL_WIDTH_20_40
:
26 rtlphy
->rfreg_chnlval
[0] = ((rtlphy
->rfreg_chnlval
[0] &
27 0xfffff3ff) | BIT(10));
28 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_CHNLBW
, RFREG_OFFSET_MASK
,
29 rtlphy
->rfreg_chnlval
[0]);
32 pr_err("unknown bandwidth: %#X\n", bandwidth
);
37 void rtl8723be_phy_rf6052_set_cck_txpower(struct ieee80211_hw
*hw
,
40 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
41 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
42 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
43 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
44 u32 tx_agc
[2] = {0, 0}, tmpval
;
45 bool turbo_scanoff
= false;
51 if (rtlefuse
->eeprom_regulatory
!= 0)
54 if (mac
->act_scanning
) {
55 tx_agc
[RF90_PATH_A
] = 0x3f3f3f3f;
56 tx_agc
[RF90_PATH_B
] = 0x3f3f3f3f;
59 for (idx1
= RF90_PATH_A
; idx1
<= RF90_PATH_B
; idx1
++) {
60 tx_agc
[idx1
] = ppowerlevel
[idx1
] |
61 (ppowerlevel
[idx1
] << 8) |
62 (ppowerlevel
[idx1
] << 16) |
63 (ppowerlevel
[idx1
] << 24);
67 for (idx1
= RF90_PATH_A
; idx1
<= RF90_PATH_B
; idx1
++) {
68 tx_agc
[idx1
] = ppowerlevel
[idx1
] |
69 (ppowerlevel
[idx1
] << 8) |
70 (ppowerlevel
[idx1
] << 16) |
71 (ppowerlevel
[idx1
] << 24);
74 if (rtlefuse
->eeprom_regulatory
== 0) {
76 (rtlphy
->mcs_txpwrlevel_origoffset
[0][6]) +
77 (rtlphy
->mcs_txpwrlevel_origoffset
[0][7] << 8);
78 tx_agc
[RF90_PATH_A
] += tmpval
;
80 tmpval
= (rtlphy
->mcs_txpwrlevel_origoffset
[0][14]) +
81 (rtlphy
->mcs_txpwrlevel_origoffset
[0][15] <<
83 tx_agc
[RF90_PATH_B
] += tmpval
;
87 for (idx1
= RF90_PATH_A
; idx1
<= RF90_PATH_B
; idx1
++) {
88 ptr
= (u8
*)(&(tx_agc
[idx1
]));
89 for (idx2
= 0; idx2
< 4; idx2
++) {
90 if (*ptr
> RF6052_MAX_TX_PWR
)
91 *ptr
= RF6052_MAX_TX_PWR
;
95 rtl8723be_dm_txpower_track_adjust(hw
, 1, &direction
, &pwrtrac_value
);
97 tx_agc
[0] += pwrtrac_value
;
98 tx_agc
[1] += pwrtrac_value
;
99 } else if (direction
== 2) {
100 tx_agc
[0] -= pwrtrac_value
;
101 tx_agc
[1] -= pwrtrac_value
;
103 tmpval
= tx_agc
[RF90_PATH_A
] & 0xff;
104 rtl_set_bbreg(hw
, RTXAGC_A_CCK1_MCS32
, MASKBYTE1
, tmpval
);
106 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
107 "CCK PWR 1M (rf-A) = 0x%x (reg 0x%x)\n", tmpval
,
108 RTXAGC_A_CCK1_MCS32
);
110 tmpval
= tx_agc
[RF90_PATH_A
] >> 8;
112 /*tmpval = tmpval & 0xff00ffff;*/
114 rtl_set_bbreg(hw
, RTXAGC_B_CCK11_A_CCK2_11
, 0xffffff00, tmpval
);
116 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
117 "CCK PWR 2~11M (rf-A) = 0x%x (reg 0x%x)\n", tmpval
,
118 RTXAGC_B_CCK11_A_CCK2_11
);
120 tmpval
= tx_agc
[RF90_PATH_B
] >> 24;
121 rtl_set_bbreg(hw
, RTXAGC_B_CCK11_A_CCK2_11
, MASKBYTE0
, tmpval
);
123 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
124 "CCK PWR 11M (rf-B) = 0x%x (reg 0x%x)\n", tmpval
,
125 RTXAGC_B_CCK11_A_CCK2_11
);
127 tmpval
= tx_agc
[RF90_PATH_B
] & 0x00ffffff;
128 rtl_set_bbreg(hw
, RTXAGC_B_CCK1_55_MCS32
, 0xffffff00, tmpval
);
130 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
131 "CCK PWR 1~5.5M (rf-B) = 0x%x (reg 0x%x)\n", tmpval
,
132 RTXAGC_B_CCK1_55_MCS32
);
135 static void rtl8723be_phy_get_power_base(struct ieee80211_hw
*hw
,
136 u8
*ppowerlevel_ofdm
,
137 u8
*ppowerlevel_bw20
,
138 u8
*ppowerlevel_bw40
,
139 u8 channel
, u32
*ofdmbase
,
142 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
143 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
144 u32 powerbase0
, powerbase1
;
147 for (i
= 0; i
< 2; i
++) {
148 powerbase0
= ppowerlevel_ofdm
[i
];
150 powerbase0
= (powerbase0
<< 24) | (powerbase0
<< 16) |
151 (powerbase0
<< 8) | powerbase0
;
152 *(ofdmbase
+ i
) = powerbase0
;
153 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
154 " [OFDM power base index rf(%c) = 0x%x]\n",
155 ((i
== 0) ? 'A' : 'B'), *(ofdmbase
+ i
));
158 for (i
= 0; i
< 2; i
++) {
159 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20
)
160 powerlevel
[i
] = ppowerlevel_bw20
[i
];
162 powerlevel
[i
] = ppowerlevel_bw40
[i
];
164 powerbase1
= powerlevel
[i
];
165 powerbase1
= (powerbase1
<< 24) | (powerbase1
<< 16) |
166 (powerbase1
<< 8) | powerbase1
;
168 *(mcsbase
+ i
) = powerbase1
;
170 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
171 " [MCS power base index rf(%c) = 0x%x]\n",
172 ((i
== 0) ? 'A' : 'B'), *(mcsbase
+ i
));
176 static void _rtl8723be_get_txpower_writeval_by_regulatory(
177 struct ieee80211_hw
*hw
,
178 u8 channel
, u8 index
,
183 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
184 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
185 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
186 u8 i
, chnlgroup
= 0, pwr_diff_limit
[4], pwr_diff
= 0, customer_pwr_diff
;
187 u32 writeval
, customer_limit
, rf
;
189 for (rf
= 0; rf
< 2; rf
++) {
190 switch (rtlefuse
->eeprom_regulatory
) {
195 rtlphy
->mcs_txpwrlevel_origoffset
[chnlgroup
][index
+
197 + ((index
< 2) ? powerbase0
[rf
] : powerbase1
[rf
]);
199 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
200 "RTK better performance, writeval(%c) = 0x%x\n",
201 ((rf
== 0) ? 'A' : 'B'), writeval
);
204 if (rtlphy
->pwrgroup_cnt
== 1) {
209 else if (channel
< 6)
211 else if (channel
< 9)
213 else if (channel
< 12)
215 else if (channel
< 14)
217 else if (channel
== 14)
222 rtlphy
->mcs_txpwrlevel_origoffset
[chnlgroup
]
223 [index
+ (rf
? 8 : 0)] + ((index
< 2) ?
227 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
228 "Realtek regulatory, 20MHz, writeval(%c) = 0x%x\n",
229 ((rf
== 0) ? 'A' : 'B'), writeval
);
234 ((index
< 2) ? powerbase0
[rf
] : powerbase1
[rf
]);
236 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
237 "Better regulatory, writeval(%c) = 0x%x\n",
238 ((rf
== 0) ? 'A' : 'B'), writeval
);
243 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20_40
) {
244 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
245 "customer's limit, 40MHz rf(%c) = 0x%x\n",
246 ((rf
== 0) ? 'A' : 'B'),
247 rtlefuse
->pwrgroup_ht40
250 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
251 "customer's limit, 20MHz rf(%c) = 0x%x\n",
252 ((rf
== 0) ? 'A' : 'B'),
253 rtlefuse
->pwrgroup_ht20
259 rtlefuse
->txpwr_legacyhtdiff
[rf
][channel
-1];
260 else if (rtlphy
->current_chan_bw
==
263 rtlefuse
->txpwr_ht20diff
[rf
][channel
-1];
265 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20_40
)
267 rtlefuse
->pwrgroup_ht40
[rf
][channel
-1];
270 rtlefuse
->pwrgroup_ht20
[rf
][channel
-1];
272 if (pwr_diff
> customer_pwr_diff
)
275 pwr_diff
= customer_pwr_diff
- pwr_diff
;
277 for (i
= 0; i
< 4; i
++) {
279 (u8
)((rtlphy
->mcs_txpwrlevel_origoffset
280 [chnlgroup
][index
+ (rf
? 8 : 0)] &
281 (0x7f << (i
* 8))) >> (i
* 8));
283 if (pwr_diff_limit
[i
] > pwr_diff
)
284 pwr_diff_limit
[i
] = pwr_diff
;
287 customer_limit
= (pwr_diff_limit
[3] << 24) |
288 (pwr_diff_limit
[2] << 16) |
289 (pwr_diff_limit
[1] << 8) |
292 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
293 "Customer's limit rf(%c) = 0x%x\n",
294 ((rf
== 0) ? 'A' : 'B'), customer_limit
);
296 writeval
= customer_limit
+ ((index
< 2) ?
300 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
301 "Customer, writeval rf(%c)= 0x%x\n",
302 ((rf
== 0) ? 'A' : 'B'), writeval
);
307 rtlphy
->mcs_txpwrlevel_origoffset
[chnlgroup
]
308 [index
+ (rf
? 8 : 0)]
309 + ((index
< 2) ? powerbase0
[rf
] : powerbase1
[rf
]);
311 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
312 "RTK better performance, writeval rf(%c) = 0x%x\n",
313 ((rf
== 0) ? 'A' : 'B'), writeval
);
317 if (rtlpriv
->dm
.dynamic_txhighpower_lvl
== TXHIGHPWRLEVEL_BT1
)
318 writeval
= writeval
- 0x06060606;
319 else if (rtlpriv
->dm
.dynamic_txhighpower_lvl
==
321 writeval
= writeval
- 0x0c0c0c0c;
322 *(p_outwriteval
+ rf
) = writeval
;
326 static void _rtl8723be_write_ofdm_power_reg(struct ieee80211_hw
*hw
,
327 u8 index
, u32
*pvalue
)
329 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
330 u16 regoffset_a
[6] = {
331 RTXAGC_A_RATE18_06
, RTXAGC_A_RATE54_24
,
332 RTXAGC_A_MCS03_MCS00
, RTXAGC_A_MCS07_MCS04
,
333 RTXAGC_A_MCS11_MCS08
, RTXAGC_A_MCS15_MCS12
335 u16 regoffset_b
[6] = {
336 RTXAGC_B_RATE18_06
, RTXAGC_B_RATE54_24
,
337 RTXAGC_B_MCS03_MCS00
, RTXAGC_B_MCS07_MCS04
,
338 RTXAGC_B_MCS11_MCS08
, RTXAGC_B_MCS15_MCS12
340 u8 i
, rf
, pwr_val
[4];
344 for (rf
= 0; rf
< 2; rf
++) {
345 writeval
= pvalue
[rf
];
346 for (i
= 0; i
< 4; i
++) {
347 pwr_val
[i
] = (u8
)((writeval
& (0x7f <<
348 (i
* 8))) >> (i
* 8));
350 if (pwr_val
[i
] > RF6052_MAX_TX_PWR
)
351 pwr_val
[i
] = RF6052_MAX_TX_PWR
;
353 writeval
= (pwr_val
[3] << 24) | (pwr_val
[2] << 16) |
354 (pwr_val
[1] << 8) | pwr_val
[0];
357 regoffset
= regoffset_a
[index
];
359 regoffset
= regoffset_b
[index
];
360 rtl_set_bbreg(hw
, regoffset
, MASKDWORD
, writeval
);
362 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
363 "Set 0x%x = %08x\n", regoffset
, writeval
);
367 void rtl8723be_phy_rf6052_set_ofdm_txpower(struct ieee80211_hw
*hw
,
368 u8
*ppowerlevel_ofdm
,
369 u8
*ppowerlevel_bw20
,
370 u8
*ppowerlevel_bw40
, u8 channel
)
372 u32 writeval
[2], powerbase0
[2], powerbase1
[2];
377 rtl8723be_phy_get_power_base(hw
, ppowerlevel_ofdm
, ppowerlevel_bw20
,
378 ppowerlevel_bw40
, channel
,
379 &powerbase0
[0], &powerbase1
[0]);
381 rtl8723be_dm_txpower_track_adjust(hw
, 1, &direction
, &pwrtrac_value
);
383 for (index
= 0; index
< 6; index
++) {
384 _rtl8723be_get_txpower_writeval_by_regulatory(hw
,
389 if (direction
== 1) {
390 writeval
[0] += pwrtrac_value
;
391 writeval
[1] += pwrtrac_value
;
392 } else if (direction
== 2) {
393 writeval
[0] -= pwrtrac_value
;
394 writeval
[1] -= pwrtrac_value
;
396 _rtl8723be_write_ofdm_power_reg(hw
, index
, &writeval
[0]);
400 bool rtl8723be_phy_rf6052_config(struct ieee80211_hw
*hw
)
402 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
403 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
405 if (rtlphy
->rf_type
== RF_1T1R
)
406 rtlphy
->num_total_rfpath
= 1;
408 rtlphy
->num_total_rfpath
= 2;
410 return _rtl8723be_phy_rf6052_config_parafile(hw
);
414 static bool _rtl8723be_phy_rf6052_config_parafile(struct ieee80211_hw
*hw
)
416 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
417 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
420 bool rtstatus
= true;
421 struct bb_reg_def
*pphyreg
;
423 for (rfpath
= 0; rfpath
< rtlphy
->num_total_rfpath
; rfpath
++) {
424 pphyreg
= &rtlphy
->phyreg_def
[rfpath
];
429 u4_regvalue
= rtl_get_bbreg(hw
, pphyreg
->rfintfs
,
434 u4_regvalue
= rtl_get_bbreg(hw
, pphyreg
->rfintfs
,
439 rtl_set_bbreg(hw
, pphyreg
->rfintfe
, BRFSI_RFENV
<< 16, 0x1);
442 rtl_set_bbreg(hw
, pphyreg
->rfintfo
, BRFSI_RFENV
, 0x1);
445 rtl_set_bbreg(hw
, pphyreg
->rfhssi_para2
,
446 B3WIREADDREAALENGTH
, 0x0);
449 rtl_set_bbreg(hw
, pphyreg
->rfhssi_para2
, B3WIREDATALENGTH
, 0x0);
454 rtstatus
= rtl8723be_phy_config_rf_with_headerfile(hw
,
455 (enum radio_path
)rfpath
);
458 rtstatus
= rtl8723be_phy_config_rf_with_headerfile(hw
,
459 (enum radio_path
)rfpath
);
470 rtl_set_bbreg(hw
, pphyreg
->rfintfs
,
471 BRFSI_RFENV
, u4_regvalue
);
475 rtl_set_bbreg(hw
, pphyreg
->rfintfs
,
476 BRFSI_RFENV
<< 16, u4_regvalue
);
481 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
482 "Radio[%d] Fail!!\n", rfpath
);
487 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
, "\n");