1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2013 Realtek Corporation.*/
11 static bool _rtl88e_phy_rf6052_config_parafile(struct ieee80211_hw
*hw
);
13 void rtl88e_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 rtl88e_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] <<
79 tx_agc
[RF90_PATH_A
] += tmpval
;
81 tmpval
= (rtlphy
->mcs_txpwrlevel_origoffset
[0][14]) +
82 (rtlphy
->mcs_txpwrlevel_origoffset
[0][15] <<
84 tx_agc
[RF90_PATH_B
] += tmpval
;
88 for (idx1
= RF90_PATH_A
; idx1
<= RF90_PATH_B
; idx1
++) {
89 ptr
= (u8
*)(&tx_agc
[idx1
]);
90 for (idx2
= 0; idx2
< 4; idx2
++) {
91 if (*ptr
> RF6052_MAX_TX_PWR
)
92 *ptr
= RF6052_MAX_TX_PWR
;
96 rtl88e_dm_txpower_track_adjust(hw
, 1, &direction
, &pwrtrac_value
);
98 tx_agc
[0] += pwrtrac_value
;
99 tx_agc
[1] += pwrtrac_value
;
100 } else if (direction
== 2) {
101 tx_agc
[0] -= pwrtrac_value
;
102 tx_agc
[1] -= pwrtrac_value
;
104 tmpval
= tx_agc
[RF90_PATH_A
] & 0xff;
105 rtl_set_bbreg(hw
, RTXAGC_A_CCK1_MCS32
, MASKBYTE1
, tmpval
);
107 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
108 "CCK PWR 1M (rf-A) = 0x%x (reg 0x%x)\n", tmpval
,
109 RTXAGC_A_CCK1_MCS32
);
111 tmpval
= tx_agc
[RF90_PATH_A
] >> 8;
113 /*tmpval = tmpval & 0xff00ffff;*/
115 rtl_set_bbreg(hw
, RTXAGC_B_CCK11_A_CCK2_11
, 0xffffff00, tmpval
);
117 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
118 "CCK PWR 2~11M (rf-A) = 0x%x (reg 0x%x)\n", tmpval
,
119 RTXAGC_B_CCK11_A_CCK2_11
);
121 tmpval
= tx_agc
[RF90_PATH_B
] >> 24;
122 rtl_set_bbreg(hw
, RTXAGC_B_CCK11_A_CCK2_11
, MASKBYTE0
, tmpval
);
124 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
125 "CCK PWR 11M (rf-B) = 0x%x (reg 0x%x)\n", tmpval
,
126 RTXAGC_B_CCK11_A_CCK2_11
);
128 tmpval
= tx_agc
[RF90_PATH_B
] & 0x00ffffff;
129 rtl_set_bbreg(hw
, RTXAGC_B_CCK1_55_MCS32
, 0xffffff00, tmpval
);
131 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
132 "CCK PWR 1~5.5M (rf-B) = 0x%x (reg 0x%x)\n", tmpval
,
133 RTXAGC_B_CCK1_55_MCS32
);
136 static void rtl88e_phy_get_power_base(struct ieee80211_hw
*hw
,
137 u8
*ppowerlevel_ofdm
,
138 u8
*ppowerlevel_bw20
,
139 u8
*ppowerlevel_bw40
, u8 channel
,
140 u32
*ofdmbase
, u32
*mcsbase
)
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) |
166 (powerbase1
<< 16) | (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 _rtl88e_get_txpower_writeval_by_regulatory(struct ieee80211_hw
*hw
,
177 u8 channel
, u8 index
,
182 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
183 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
184 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
185 u8 i
, chnlgroup
= 0, pwr_diff_limit
[4], pwr_diff
= 0, customer_pwr_diff
;
186 u32 writeval
, customer_limit
, rf
;
188 for (rf
= 0; rf
< 2; rf
++) {
189 switch (rtlefuse
->eeprom_regulatory
) {
194 rtlphy
->mcs_txpwrlevel_origoffset
195 [chnlgroup
][index
+ (rf
? 8 : 0)]
196 + ((index
< 2) ? powerbase0
[rf
] : powerbase1
[rf
]);
198 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
199 "RTK better performance, writeval(%c) = 0x%x\n",
200 ((rf
== 0) ? 'A' : 'B'), writeval
);
203 if (rtlphy
->pwrgroup_cnt
== 1) {
208 else if (channel
< 6)
210 else if (channel
< 9)
212 else if (channel
< 12)
214 else if (channel
< 14)
216 else if (channel
== 14)
221 rtlphy
->mcs_txpwrlevel_origoffset
[chnlgroup
]
222 [index
+ (rf
? 8 : 0)] + ((index
< 2) ?
226 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
227 "Realtek regulatory, 20MHz, writeval(%c) = 0x%x\n",
228 ((rf
== 0) ? 'A' : 'B'), writeval
);
233 ((index
< 2) ? powerbase0
[rf
] : powerbase1
[rf
]);
235 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
236 "Better regulatory, writeval(%c) = 0x%x\n",
237 ((rf
== 0) ? 'A' : 'B'), writeval
);
242 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20_40
) {
243 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
244 "customer's limit, 40MHz rf(%c) = 0x%x\n",
245 ((rf
== 0) ? 'A' : 'B'),
246 rtlefuse
->pwrgroup_ht40
[rf
][channel
-
249 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
250 "customer's limit, 20MHz rf(%c) = 0x%x\n",
251 ((rf
== 0) ? 'A' : 'B'),
252 rtlefuse
->pwrgroup_ht20
[rf
][channel
-
258 rtlefuse
->txpwr_legacyhtdiff
[rf
][channel
-1];
259 else if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20
)
261 rtlefuse
->txpwr_ht20diff
[rf
][channel
-1];
263 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20_40
)
265 rtlefuse
->pwrgroup_ht40
[rf
][channel
-1];
268 rtlefuse
->pwrgroup_ht20
[rf
][channel
-1];
270 if (pwr_diff
> customer_pwr_diff
)
273 pwr_diff
= customer_pwr_diff
- pwr_diff
;
275 for (i
= 0; i
< 4; i
++) {
277 (u8
)((rtlphy
->mcs_txpwrlevel_origoffset
279 (rf
? 8 : 0)] & (0x7f <<
280 (i
* 8))) >> (i
* 8));
282 if (pwr_diff_limit
[i
] > pwr_diff
)
283 pwr_diff_limit
[i
] = pwr_diff
;
286 customer_limit
= (pwr_diff_limit
[3] << 24) |
287 (pwr_diff_limit
[2] << 16) |
288 (pwr_diff_limit
[1] << 8) | (pwr_diff_limit
[0]);
290 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
291 "Customer's limit rf(%c) = 0x%x\n",
292 ((rf
== 0) ? 'A' : 'B'), customer_limit
);
294 writeval
= customer_limit
+
295 ((index
< 2) ? powerbase0
[rf
] : powerbase1
[rf
]);
297 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
298 "Customer, writeval rf(%c)= 0x%x\n",
299 ((rf
== 0) ? 'A' : 'B'), writeval
);
304 rtlphy
->mcs_txpwrlevel_origoffset
[chnlgroup
]
305 [index
+ (rf
? 8 : 0)]
306 + ((index
< 2) ? powerbase0
[rf
] : powerbase1
[rf
]);
308 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
309 "RTK better performance, writeval rf(%c) = 0x%x\n",
310 ((rf
== 0) ? 'A' : 'B'), writeval
);
314 if (rtlpriv
->dm
.dynamic_txhighpower_lvl
== TXHIGHPWRLEVEL_BT1
)
315 writeval
= writeval
- 0x06060606;
316 else if (rtlpriv
->dm
.dynamic_txhighpower_lvl
==
318 writeval
= writeval
- 0x0c0c0c0c;
319 *(p_outwriteval
+ rf
) = writeval
;
323 static void _rtl88e_write_ofdm_power_reg(struct ieee80211_hw
*hw
,
324 u8 index
, u32
*value
)
326 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
327 u16 regoffset_a
[6] = {
328 RTXAGC_A_RATE18_06
, RTXAGC_A_RATE54_24
,
329 RTXAGC_A_MCS03_MCS00
, RTXAGC_A_MCS07_MCS04
,
330 RTXAGC_A_MCS11_MCS08
, RTXAGC_A_MCS15_MCS12
332 u16 regoffset_b
[6] = {
333 RTXAGC_B_RATE18_06
, RTXAGC_B_RATE54_24
,
334 RTXAGC_B_MCS03_MCS00
, RTXAGC_B_MCS07_MCS04
,
335 RTXAGC_B_MCS11_MCS08
, RTXAGC_B_MCS15_MCS12
337 u8 i
, rf
, pwr_val
[4];
341 for (rf
= 0; rf
< 2; rf
++) {
342 writeval
= value
[rf
];
343 for (i
= 0; i
< 4; i
++) {
344 pwr_val
[i
] = (u8
)((writeval
& (0x7f <<
345 (i
* 8))) >> (i
* 8));
347 if (pwr_val
[i
] > RF6052_MAX_TX_PWR
)
348 pwr_val
[i
] = RF6052_MAX_TX_PWR
;
350 writeval
= (pwr_val
[3] << 24) | (pwr_val
[2] << 16) |
351 (pwr_val
[1] << 8) | pwr_val
[0];
354 regoffset
= regoffset_a
[index
];
356 regoffset
= regoffset_b
[index
];
357 rtl_set_bbreg(hw
, regoffset
, MASKDWORD
, writeval
);
359 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
360 "Set 0x%x = %08x\n", regoffset
, writeval
);
364 void rtl88e_phy_rf6052_set_ofdm_txpower(struct ieee80211_hw
*hw
,
365 u8
*ppowerlevel_ofdm
,
366 u8
*ppowerlevel_bw20
,
367 u8
*ppowerlevel_bw40
, u8 channel
)
369 u32 writeval
[2], powerbase0
[2], powerbase1
[2];
374 rtl88e_phy_get_power_base(hw
, ppowerlevel_ofdm
,
375 ppowerlevel_bw20
, ppowerlevel_bw40
,
376 channel
, &powerbase0
[0], &powerbase1
[0]);
378 rtl88e_dm_txpower_track_adjust(hw
, 1, &direction
, &pwrtrac_value
);
380 for (index
= 0; index
< 6; index
++) {
381 _rtl88e_get_txpower_writeval_by_regulatory(hw
,
386 if (direction
== 1) {
387 writeval
[0] += pwrtrac_value
;
388 writeval
[1] += pwrtrac_value
;
389 } else if (direction
== 2) {
390 writeval
[0] -= pwrtrac_value
;
391 writeval
[1] -= pwrtrac_value
;
393 _rtl88e_write_ofdm_power_reg(hw
, index
, &writeval
[0]);
397 bool rtl88e_phy_rf6052_config(struct ieee80211_hw
*hw
)
399 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
400 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
402 if (rtlphy
->rf_type
== RF_1T1R
)
403 rtlphy
->num_total_rfpath
= 1;
405 rtlphy
->num_total_rfpath
= 2;
407 return _rtl88e_phy_rf6052_config_parafile(hw
);
410 static bool _rtl88e_phy_rf6052_config_parafile(struct ieee80211_hw
*hw
)
412 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
413 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
416 bool rtstatus
= true;
417 struct bb_reg_def
*pphyreg
;
419 for (rfpath
= 0; rfpath
< rtlphy
->num_total_rfpath
; rfpath
++) {
420 pphyreg
= &rtlphy
->phyreg_def
[rfpath
];
425 u4_regvalue
= rtl_get_bbreg(hw
, pphyreg
->rfintfs
,
430 u4_regvalue
= rtl_get_bbreg(hw
, pphyreg
->rfintfs
,
435 rtl_set_bbreg(hw
, pphyreg
->rfintfe
, BRFSI_RFENV
<< 16, 0x1);
438 rtl_set_bbreg(hw
, pphyreg
->rfintfo
, BRFSI_RFENV
, 0x1);
441 rtl_set_bbreg(hw
, pphyreg
->rfhssi_para2
,
442 B3WIREADDREAALENGTH
, 0x0);
445 rtl_set_bbreg(hw
, pphyreg
->rfhssi_para2
, B3WIREDATALENGTH
, 0x0);
450 rtstatus
= rtl88e_phy_config_rf_with_headerfile(hw
,
451 (enum radio_path
)rfpath
);
454 rtstatus
= rtl88e_phy_config_rf_with_headerfile(hw
,
455 (enum radio_path
)rfpath
);
466 rtl_set_bbreg(hw
, pphyreg
->rfintfs
,
467 BRFSI_RFENV
, u4_regvalue
);
471 rtl_set_bbreg(hw
, pphyreg
->rfintfs
,
472 BRFSI_RFENV
<< 16, u4_regvalue
);
477 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
478 "Radio[%d] Fail!!\n", rfpath
);
484 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
, "\n");