1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2012 Realtek Corporation.*/
11 static bool _rtl8723e_phy_rf6052_config_parafile(struct ieee80211_hw
*hw
);
13 void rtl8723e_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) | 0x0400);
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] &
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 rtl8723e_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;
49 if (rtlefuse
->eeprom_regulatory
!= 0)
52 if (mac
->act_scanning
) {
53 tx_agc
[RF90_PATH_A
] = 0x3f3f3f3f;
54 tx_agc
[RF90_PATH_B
] = 0x3f3f3f3f;
57 for (idx1
= RF90_PATH_A
; idx1
<= RF90_PATH_B
;
59 tx_agc
[idx1
] = ppowerlevel
[idx1
] |
60 (ppowerlevel
[idx1
] << 8) |
61 (ppowerlevel
[idx1
] << 16) |
62 (ppowerlevel
[idx1
] << 24);
66 for (idx1
= RF90_PATH_A
; idx1
<= RF90_PATH_B
; idx1
++) {
67 tx_agc
[idx1
] = ppowerlevel
[idx1
] |
68 (ppowerlevel
[idx1
] << 8) |
69 (ppowerlevel
[idx1
] << 16) |
70 (ppowerlevel
[idx1
] << 24);
73 if (rtlefuse
->eeprom_regulatory
== 0) {
75 (rtlphy
->mcs_txpwrlevel_origoffset
[0][6]) +
76 (rtlphy
->mcs_txpwrlevel_origoffset
[0][7] <<
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
;
96 tmpval
= tx_agc
[RF90_PATH_A
] & 0xff;
97 rtl_set_bbreg(hw
, RTXAGC_A_CCK1_MCS32
, MASKBYTE1
, tmpval
);
99 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
100 "CCK PWR 1M (rf-A) = 0x%x (reg 0x%x)\n", tmpval
,
101 RTXAGC_A_CCK1_MCS32
);
103 tmpval
= tx_agc
[RF90_PATH_A
] >> 8;
105 tmpval
= tmpval
& 0xff00ffff;
107 rtl_set_bbreg(hw
, RTXAGC_B_CCK11_A_CCK2_11
, 0xffffff00, tmpval
);
109 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
110 "CCK PWR 2~11M (rf-A) = 0x%x (reg 0x%x)\n", tmpval
,
111 RTXAGC_B_CCK11_A_CCK2_11
);
113 tmpval
= tx_agc
[RF90_PATH_B
] >> 24;
114 rtl_set_bbreg(hw
, RTXAGC_B_CCK11_A_CCK2_11
, MASKBYTE0
, tmpval
);
116 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
117 "CCK PWR 11M (rf-B) = 0x%x (reg 0x%x)\n", tmpval
,
118 RTXAGC_B_CCK11_A_CCK2_11
);
120 tmpval
= tx_agc
[RF90_PATH_B
] & 0x00ffffff;
121 rtl_set_bbreg(hw
, RTXAGC_B_CCK1_55_MCS32
, 0xffffff00, tmpval
);
123 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
124 "CCK PWR 1~5.5M (rf-B) = 0x%x (reg 0x%x)\n", tmpval
,
125 RTXAGC_B_CCK1_55_MCS32
);
128 static void rtl8723e_phy_get_power_base(struct ieee80211_hw
*hw
,
129 u8
*ppowerlevel
, u8 channel
,
130 u32
*ofdmbase
, u32
*mcsbase
)
132 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
133 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
134 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
135 u32 powerbase0
, powerbase1
;
136 u8 legacy_pwrdiff
, ht20_pwrdiff
;
139 for (i
= 0; i
< 2; i
++) {
140 powerlevel
[i
] = ppowerlevel
[i
];
141 legacy_pwrdiff
= rtlefuse
->txpwr_legacyhtdiff
[i
][channel
- 1];
142 powerbase0
= powerlevel
[i
] + legacy_pwrdiff
;
144 powerbase0
= (powerbase0
<< 24) | (powerbase0
<< 16) |
145 (powerbase0
<< 8) | powerbase0
;
146 *(ofdmbase
+ i
) = powerbase0
;
147 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
148 " [OFDM power base index rf(%c) = 0x%x]\n",
149 ((i
== 0) ? 'A' : 'B'), *(ofdmbase
+ i
));
152 for (i
= 0; i
< 2; i
++) {
153 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20
) {
155 rtlefuse
->txpwr_ht20diff
[i
][channel
- 1];
156 powerlevel
[i
] += ht20_pwrdiff
;
158 powerbase1
= powerlevel
[i
];
159 powerbase1
= (powerbase1
<< 24) |
160 (powerbase1
<< 16) | (powerbase1
<< 8) | powerbase1
;
162 *(mcsbase
+ i
) = powerbase1
;
164 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
165 " [MCS power base index rf(%c) = 0x%x]\n",
166 ((i
== 0) ? 'A' : 'B'), *(mcsbase
+ i
));
170 static void get_txpower_writeval_by_reg(struct ieee80211_hw
*hw
,
171 u8 channel
, u8 index
,
176 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
177 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
178 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
179 u8 i
, chnlgroup
= 0, pwr_diff_limit
[4];
180 u32 writeval
, customer_limit
, rf
;
182 for (rf
= 0; rf
< 2; rf
++) {
183 switch (rtlefuse
->eeprom_regulatory
) {
188 rtlphy
->mcs_txpwrlevel_origoffset
[chnlgroup
][index
+
190 + ((index
< 2) ? powerbase0
[rf
] : powerbase1
[rf
]);
192 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
193 "RTK better performance, writeval(%c) = 0x%x\n",
194 ((rf
== 0) ? 'A' : 'B'), writeval
);
197 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20_40
) {
198 writeval
= ((index
< 2) ? powerbase0
[rf
] :
201 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
202 "Realtek regulatory, 40MHz, writeval(%c) = 0x%x\n",
203 ((rf
== 0) ? 'A' : 'B'), writeval
);
205 if (rtlphy
->pwrgroup_cnt
== 1)
207 if (rtlphy
->pwrgroup_cnt
>= 3) {
210 else if (channel
>= 4 && channel
<= 9)
212 else if (channel
> 9)
214 if (rtlphy
->current_chan_bw
==
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
[rf
][channel
-
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
[rf
][channel
-
256 for (i
= 0; i
< 4; i
++) {
258 (u8
)((rtlphy
->mcs_txpwrlevel_origoffset
260 (rf
? 8 : 0)] & (0x7f <<
261 (i
* 8))) >> (i
* 8));
263 if (rtlphy
->current_chan_bw
==
264 HT_CHANNEL_WIDTH_20_40
) {
265 if (pwr_diff_limit
[i
] >
267 pwrgroup_ht40
[rf
][channel
- 1])
269 rtlefuse
->pwrgroup_ht40
[rf
]
272 if (pwr_diff_limit
[i
] >
274 pwrgroup_ht20
[rf
][channel
- 1])
276 rtlefuse
->pwrgroup_ht20
[rf
]
281 customer_limit
= (pwr_diff_limit
[3] << 24) |
282 (pwr_diff_limit
[2] << 16) |
283 (pwr_diff_limit
[1] << 8) | (pwr_diff_limit
[0]);
285 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
286 "Customer's limit rf(%c) = 0x%x\n",
287 ((rf
== 0) ? 'A' : 'B'), customer_limit
);
289 writeval
= customer_limit
+
290 ((index
< 2) ? powerbase0
[rf
] : powerbase1
[rf
]);
292 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
293 "Customer, writeval rf(%c)= 0x%x\n",
294 ((rf
== 0) ? 'A' : 'B'), writeval
);
299 rtlphy
->mcs_txpwrlevel_origoffset
[chnlgroup
]
300 [index
+ (rf
? 8 : 0)]
301 + ((index
< 2) ? powerbase0
[rf
] : powerbase1
[rf
]);
303 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
304 "RTK better performance, writeval rf(%c) = 0x%x\n",
305 ((rf
== 0) ? 'A' : 'B'), writeval
);
309 if (rtlpriv
->dm
.dynamic_txhighpower_lvl
== TXHIGHPWRLEVEL_BT1
)
310 writeval
= writeval
- 0x06060606;
311 else if (rtlpriv
->dm
.dynamic_txhighpower_lvl
==
313 writeval
= writeval
- 0x0c0c0c0c;
314 *(p_outwriteval
+ rf
) = writeval
;
318 static void _rtl8723e_write_ofdm_power_reg(struct ieee80211_hw
*hw
,
319 u8 index
, u32
*pvalue
)
321 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
322 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
324 u16 regoffset_a
[6] = {
325 RTXAGC_A_RATE18_06
, RTXAGC_A_RATE54_24
,
326 RTXAGC_A_MCS03_MCS00
, RTXAGC_A_MCS07_MCS04
,
327 RTXAGC_A_MCS11_MCS08
, RTXAGC_A_MCS15_MCS12
329 u16 regoffset_b
[6] = {
330 RTXAGC_B_RATE18_06
, RTXAGC_B_RATE54_24
,
331 RTXAGC_B_MCS03_MCS00
, RTXAGC_B_MCS07_MCS04
,
332 RTXAGC_B_MCS11_MCS08
, RTXAGC_B_MCS15_MCS12
334 u8 i
, rf
, pwr_val
[4];
338 for (rf
= 0; rf
< 2; rf
++) {
339 writeval
= pvalue
[rf
];
340 for (i
= 0; i
< 4; i
++) {
341 pwr_val
[i
] = (u8
)((writeval
& (0x7f <<
342 (i
* 8))) >> (i
* 8));
344 if (pwr_val
[i
] > RF6052_MAX_TX_PWR
)
345 pwr_val
[i
] = RF6052_MAX_TX_PWR
;
347 writeval
= (pwr_val
[3] << 24) | (pwr_val
[2] << 16) |
348 (pwr_val
[1] << 8) | pwr_val
[0];
351 regoffset
= regoffset_a
[index
];
353 regoffset
= regoffset_b
[index
];
354 rtl_set_bbreg(hw
, regoffset
, MASKDWORD
, writeval
);
356 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
357 "Set 0x%x = %08x\n", regoffset
, writeval
);
359 if (((get_rf_type(rtlphy
) == RF_2T2R
) &&
360 (regoffset
== RTXAGC_A_MCS15_MCS12
||
361 regoffset
== RTXAGC_B_MCS15_MCS12
)) ||
362 ((get_rf_type(rtlphy
) != RF_2T2R
) &&
363 (regoffset
== RTXAGC_A_MCS07_MCS04
||
364 regoffset
== RTXAGC_B_MCS07_MCS04
))) {
366 writeval
= pwr_val
[3];
367 if (regoffset
== RTXAGC_A_MCS15_MCS12
||
368 regoffset
== RTXAGC_A_MCS07_MCS04
)
370 if (regoffset
== RTXAGC_B_MCS15_MCS12
||
371 regoffset
== RTXAGC_B_MCS07_MCS04
)
374 for (i
= 0; i
< 3; i
++) {
375 writeval
= (writeval
> 6) ? (writeval
- 6) : 0;
376 rtl_write_byte(rtlpriv
, (u32
) (regoffset
+ i
),
383 void rtl8723e_phy_rf6052_set_ofdm_txpower(struct ieee80211_hw
*hw
,
384 u8
*ppowerlevel
, u8 channel
)
386 u32 writeval
[2], powerbase0
[2], powerbase1
[2];
389 rtl8723e_phy_get_power_base(hw
, ppowerlevel
,
390 channel
, &powerbase0
[0], &powerbase1
[0]);
392 for (index
= 0; index
< 6; index
++) {
393 get_txpower_writeval_by_reg(hw
, channel
, index
, &powerbase0
[0],
397 _rtl8723e_write_ofdm_power_reg(hw
, index
, &writeval
[0]);
401 bool rtl8723e_phy_rf6052_config(struct ieee80211_hw
*hw
)
403 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
404 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
406 if (rtlphy
->rf_type
== RF_1T1R
)
407 rtlphy
->num_total_rfpath
= 1;
409 rtlphy
->num_total_rfpath
= 2;
411 return _rtl8723e_phy_rf6052_config_parafile(hw
);
414 static bool _rtl8723e_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
++) {
425 pphyreg
= &rtlphy
->phyreg_def
[rfpath
];
430 u4_regvalue
= rtl_get_bbreg(hw
, pphyreg
->rfintfs
,
435 u4_regvalue
= rtl_get_bbreg(hw
, pphyreg
->rfintfs
,
440 rtl_set_bbreg(hw
, pphyreg
->rfintfe
, BRFSI_RFENV
<< 16, 0x1);
443 rtl_set_bbreg(hw
, pphyreg
->rfintfo
, BRFSI_RFENV
, 0x1);
446 rtl_set_bbreg(hw
, pphyreg
->rfhssi_para2
,
447 B3WIREADDREAALENGTH
, 0x0);
450 rtl_set_bbreg(hw
, pphyreg
->rfhssi_para2
, B3WIREDATALENGTH
, 0x0);
455 rtstatus
= rtl8723e_phy_config_rf_with_headerfile(hw
,
456 (enum radio_path
)rfpath
);
460 rtl8723e_phy_config_rf_with_headerfile(hw
,
461 (enum radio_path
)rfpath
);
472 rtl_set_bbreg(hw
, pphyreg
->rfintfs
,
473 BRFSI_RFENV
, u4_regvalue
);
477 rtl_set_bbreg(hw
, pphyreg
->rfintfs
,
478 BRFSI_RFENV
<< 16, u4_regvalue
);
483 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
484 "Radio[%d] Fail!!\n", rfpath
);
489 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
, "\n");