1 /******************************************************************************
3 * Copyright(c) 2009-2014 Realtek Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
33 static bool _rtl8723be_phy_rf6052_config_parafile(struct ieee80211_hw
*hw
);
35 void rtl8723be_phy_rf6052_set_bandwidth(struct ieee80211_hw
*hw
, u8 bandwidth
)
37 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
38 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
41 case HT_CHANNEL_WIDTH_20
:
42 rtlphy
->rfreg_chnlval
[0] = ((rtlphy
->rfreg_chnlval
[0] &
43 0xfffff3ff) | BIT(10) | BIT(11));
44 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_CHNLBW
, RFREG_OFFSET_MASK
,
45 rtlphy
->rfreg_chnlval
[0]);
47 case HT_CHANNEL_WIDTH_20_40
:
48 rtlphy
->rfreg_chnlval
[0] = ((rtlphy
->rfreg_chnlval
[0] &
49 0xfffff3ff) | BIT(10));
50 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_CHNLBW
, RFREG_OFFSET_MASK
,
51 rtlphy
->rfreg_chnlval
[0]);
54 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_EMERG
,
55 "unknown bandwidth: %#X\n", bandwidth
);
60 void rtl8723be_phy_rf6052_set_cck_txpower(struct ieee80211_hw
*hw
,
63 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
64 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
65 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
66 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
67 u32 tx_agc
[2] = {0, 0}, tmpval
;
68 bool turbo_scanoff
= false;
74 if (rtlefuse
->eeprom_regulatory
!= 0)
77 if (mac
->act_scanning
) {
78 tx_agc
[RF90_PATH_A
] = 0x3f3f3f3f;
79 tx_agc
[RF90_PATH_B
] = 0x3f3f3f3f;
82 for (idx1
= RF90_PATH_A
; idx1
<= RF90_PATH_B
; idx1
++) {
83 tx_agc
[idx1
] = ppowerlevel
[idx1
] |
84 (ppowerlevel
[idx1
] << 8) |
85 (ppowerlevel
[idx1
] << 16) |
86 (ppowerlevel
[idx1
] << 24);
90 for (idx1
= RF90_PATH_A
; idx1
<= RF90_PATH_B
; idx1
++) {
91 tx_agc
[idx1
] = ppowerlevel
[idx1
] |
92 (ppowerlevel
[idx1
] << 8) |
93 (ppowerlevel
[idx1
] << 16) |
94 (ppowerlevel
[idx1
] << 24);
96 if (rtlefuse
->eeprom_regulatory
== 0) {
98 (rtlphy
->mcs_offset
[0][6]) +
99 (rtlphy
->mcs_offset
[0][7] << 8);
100 tx_agc
[RF90_PATH_A
] += tmpval
;
102 tmpval
= (rtlphy
->mcs_offset
[0][14]) +
103 (rtlphy
->mcs_offset
[0][15] <<
105 tx_agc
[RF90_PATH_B
] += tmpval
;
108 for (idx1
= RF90_PATH_A
; idx1
<= RF90_PATH_B
; idx1
++) {
109 ptr
= (u8
*)(&(tx_agc
[idx1
]));
110 for (idx2
= 0; idx2
< 4; idx2
++) {
111 if (*ptr
> RF6052_MAX_TX_PWR
)
112 *ptr
= RF6052_MAX_TX_PWR
;
116 rtl8723be_dm_txpower_track_adjust(hw
, 1, &direction
, &pwrtrac_value
);
117 if (direction
== 1) {
118 tx_agc
[0] += pwrtrac_value
;
119 tx_agc
[1] += pwrtrac_value
;
120 } else if (direction
== 2) {
121 tx_agc
[0] -= pwrtrac_value
;
122 tx_agc
[1] -= pwrtrac_value
;
124 tmpval
= tx_agc
[RF90_PATH_A
] & 0xff;
125 rtl_set_bbreg(hw
, RTXAGC_A_CCK1_MCS32
, MASKBYTE1
, tmpval
);
127 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
128 "CCK PWR 1M (rf-A) = 0x%x (reg 0x%x)\n", tmpval
,
129 RTXAGC_A_CCK1_MCS32
);
131 tmpval
= tx_agc
[RF90_PATH_A
] >> 8;
133 rtl_set_bbreg(hw
, RTXAGC_B_CCK11_A_CCK2_11
, 0xffffff00, tmpval
);
135 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
136 "CCK PWR 2~11M (rf-A) = 0x%x (reg 0x%x)\n", tmpval
,
137 RTXAGC_B_CCK11_A_CCK2_11
);
139 tmpval
= tx_agc
[RF90_PATH_B
] >> 24;
140 rtl_set_bbreg(hw
, RTXAGC_B_CCK11_A_CCK2_11
, MASKBYTE0
, tmpval
);
142 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
143 "CCK PWR 11M (rf-B) = 0x%x (reg 0x%x)\n", tmpval
,
144 RTXAGC_B_CCK11_A_CCK2_11
);
146 tmpval
= tx_agc
[RF90_PATH_B
] & 0x00ffffff;
147 rtl_set_bbreg(hw
, RTXAGC_B_CCK1_55_MCS32
, 0xffffff00, tmpval
);
149 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
150 "CCK PWR 1~5.5M (rf-B) = 0x%x (reg 0x%x)\n", tmpval
,
151 RTXAGC_B_CCK1_55_MCS32
);
154 static void rtl8723be_phy_get_power_base(struct ieee80211_hw
*hw
,
155 u8
*ppowerlevel_ofdm
,
156 u8
*ppowerlevel_bw20
,
157 u8
*ppowerlevel_bw40
,
158 u8 channel
, u32
*ofdmbase
,
161 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
162 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
163 u32 powerbase0
, powerbase1
;
166 for (i
= 0; i
< 2; i
++) {
167 powerbase0
= ppowerlevel_ofdm
[i
];
169 powerbase0
= (powerbase0
<< 24) | (powerbase0
<< 16) |
170 (powerbase0
<< 8) | powerbase0
;
171 *(ofdmbase
+ i
) = powerbase0
;
172 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
173 " [OFDM power base index rf(%c) = 0x%x]\n",
174 ((i
== 0) ? 'A' : 'B'), *(ofdmbase
+ i
));
177 for (i
= 0; i
< 2; i
++) {
178 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20
)
179 powerlevel
[i
] = ppowerlevel_bw20
[i
];
181 powerlevel
[i
] = ppowerlevel_bw40
[i
];
182 powerbase1
= powerlevel
[i
];
183 powerbase1
= (powerbase1
<< 24) | (powerbase1
<< 16) |
184 (powerbase1
<< 8) | powerbase1
;
186 *(mcsbase
+ i
) = powerbase1
;
188 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
189 " [MCS power base index rf(%c) = 0x%x]\n",
190 ((i
== 0) ? 'A' : 'B'), *(mcsbase
+ i
));
194 static void txpwr_by_regulatory(struct ieee80211_hw
*hw
, u8 channel
, u8 index
,
195 u32
*powerbase0
, u32
*powerbase1
,
198 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
199 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
200 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
201 u8 i
, chnlgroup
= 0, pwr_diff_limit
[4];
202 u8 pwr_diff
= 0, customer_pwr_diff
;
203 u32 writeval
, customer_limit
, rf
;
205 for (rf
= 0; rf
< 2; rf
++) {
206 switch (rtlefuse
->eeprom_regulatory
) {
211 rtlphy
->mcs_offset
[chnlgroup
][index
+ (rf
? 8 : 0)]
212 + ((index
< 2) ? powerbase0
[rf
] : powerbase1
[rf
]);
214 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
215 "RTK better performance, "
216 "writeval(%c) = 0x%x\n",
217 ((rf
== 0) ? 'A' : 'B'), writeval
);
220 if (rtlphy
->pwrgroup_cnt
== 1) {
225 else if (channel
< 6)
227 else if (channel
< 9)
229 else if (channel
< 12)
231 else if (channel
< 14)
233 else if (channel
== 14)
236 writeval
= rtlphy
->mcs_offset
[chnlgroup
]
237 [index
+ (rf
? 8 : 0)] + ((index
< 2) ?
241 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
242 "Realtek regulatory, 20MHz, "
243 "writeval(%c) = 0x%x\n",
244 ((rf
== 0) ? 'A' : 'B'), writeval
);
249 ((index
< 2) ? powerbase0
[rf
] : powerbase1
[rf
]);
251 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
252 "Better regulatory, "
253 "writeval(%c) = 0x%x\n",
254 ((rf
== 0) ? 'A' : 'B'), writeval
);
259 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20_40
) {
260 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
261 "customer's limit, 40MHz "
263 ((rf
== 0) ? 'A' : 'B'),
264 rtlefuse
->pwrgroup_ht40
[rf
]
267 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
268 "customer's limit, 20MHz "
270 ((rf
== 0) ? 'A' : 'B'),
271 rtlefuse
->pwrgroup_ht20
[rf
]
277 rtlefuse
->txpwr_legacyhtdiff
[rf
][channel
-1];
278 else if (rtlphy
->current_chan_bw
==
281 rtlefuse
->txpwr_ht20diff
[rf
][channel
-1];
283 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20_40
)
285 rtlefuse
->pwrgroup_ht40
[rf
][channel
-1];
288 rtlefuse
->pwrgroup_ht20
[rf
][channel
-1];
290 if (pwr_diff
> customer_pwr_diff
)
293 pwr_diff
= customer_pwr_diff
- pwr_diff
;
295 for (i
= 0; i
< 4; i
++) {
297 (u8
)((rtlphy
->mcs_offset
298 [chnlgroup
][index
+ (rf
? 8 : 0)] &
299 (0x7f << (i
* 8))) >> (i
* 8));
301 if (pwr_diff_limit
[i
] > pwr_diff
)
302 pwr_diff_limit
[i
] = pwr_diff
;
305 customer_limit
= (pwr_diff_limit
[3] << 24) |
306 (pwr_diff_limit
[2] << 16) |
307 (pwr_diff_limit
[1] << 8) |
310 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
311 "Customer's limit rf(%c) = 0x%x\n",
312 ((rf
== 0) ? 'A' : 'B'), customer_limit
);
314 writeval
= customer_limit
+ ((index
< 2) ?
318 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
319 "Customer, writeval rf(%c)= 0x%x\n",
320 ((rf
== 0) ? 'A' : 'B'), writeval
);
325 rtlphy
->mcs_offset
[chnlgroup
]
326 [index
+ (rf
? 8 : 0)]
327 + ((index
< 2) ? powerbase0
[rf
] : powerbase1
[rf
]);
329 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
330 "RTK better performance, writeval "
332 ((rf
== 0) ? 'A' : 'B'), writeval
);
336 if (rtlpriv
->dm
.dynamic_txhighpower_lvl
== TXHIGHPWRLEVEL_BT1
)
337 writeval
= writeval
- 0x06060606;
338 else if (rtlpriv
->dm
.dynamic_txhighpower_lvl
==
340 writeval
= writeval
- 0x0c0c0c0c;
341 *(p_outwriteval
+ rf
) = writeval
;
345 static void _rtl8723be_write_ofdm_power_reg(struct ieee80211_hw
*hw
,
346 u8 index
, u32
*value
)
348 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
349 u16 regoffset_a
[6] = {
350 RTXAGC_A_RATE18_06
, RTXAGC_A_RATE54_24
,
351 RTXAGC_A_MCS03_MCS00
, RTXAGC_A_MCS07_MCS04
,
352 RTXAGC_A_MCS11_MCS08
, RTXAGC_A_MCS15_MCS12
354 u16 regoffset_b
[6] = {
355 RTXAGC_B_RATE18_06
, RTXAGC_B_RATE54_24
,
356 RTXAGC_B_MCS03_MCS00
, RTXAGC_B_MCS07_MCS04
,
357 RTXAGC_B_MCS11_MCS08
, RTXAGC_B_MCS15_MCS12
359 u8 i
, rf
, pwr_val
[4];
363 for (rf
= 0; rf
< 2; rf
++) {
364 writeval
= value
[rf
];
365 for (i
= 0; i
< 4; i
++) {
366 pwr_val
[i
] = (u8
) ((writeval
& (0x7f <<
367 (i
* 8))) >> (i
* 8));
369 if (pwr_val
[i
] > RF6052_MAX_TX_PWR
)
370 pwr_val
[i
] = RF6052_MAX_TX_PWR
;
372 writeval
= (pwr_val
[3] << 24) | (pwr_val
[2] << 16) |
373 (pwr_val
[1] << 8) | pwr_val
[0];
376 regoffset
= regoffset_a
[index
];
378 regoffset
= regoffset_b
[index
];
379 rtl_set_bbreg(hw
, regoffset
, MASKDWORD
, writeval
);
381 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
382 "Set 0x%x = %08x\n", regoffset
, writeval
);
386 void rtl8723be_phy_rf6052_set_ofdm_txpower(struct ieee80211_hw
*hw
,
387 u8
*ppowerlevel_ofdm
,
388 u8
*ppowerlevel_bw20
,
389 u8
*ppowerlevel_bw40
, u8 channel
)
391 u32 writeval
[2], powerbase0
[2], powerbase1
[2];
396 rtl8723be_phy_get_power_base(hw
, ppowerlevel_ofdm
, ppowerlevel_bw20
,
397 ppowerlevel_bw40
, channel
,
398 &powerbase0
[0], &powerbase1
[0]);
400 rtl8723be_dm_txpower_track_adjust(hw
, 1, &direction
, &pwrtrac_value
);
402 for (index
= 0; index
< 6; index
++) {
403 txpwr_by_regulatory(hw
, channel
, index
, &powerbase0
[0],
404 &powerbase1
[0], &writeval
[0]);
405 if (direction
== 1) {
406 writeval
[0] += pwrtrac_value
;
407 writeval
[1] += pwrtrac_value
;
408 } else if (direction
== 2) {
409 writeval
[0] -= pwrtrac_value
;
410 writeval
[1] -= pwrtrac_value
;
412 _rtl8723be_write_ofdm_power_reg(hw
, index
, &writeval
[0]);
416 bool rtl8723be_phy_rf6052_config(struct ieee80211_hw
*hw
)
418 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
419 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
421 if (rtlphy
->rf_type
== RF_1T1R
)
422 rtlphy
->num_total_rfpath
= 1;
424 rtlphy
->num_total_rfpath
= 2;
426 return _rtl8723be_phy_rf6052_config_parafile(hw
);
429 static bool _rtl8723be_phy_rf6052_config_parafile(struct ieee80211_hw
*hw
)
431 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
432 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
433 struct bb_reg_def
*pphyreg
;
436 bool rtstatus
= true;
438 for (rfpath
= 0; rfpath
< rtlphy
->num_total_rfpath
; rfpath
++) {
439 pphyreg
= &rtlphy
->phyreg_def
[rfpath
];
444 u4_regvalue
= rtl_get_bbreg(hw
, pphyreg
->rfintfs
,
449 u4_regvalue
= rtl_get_bbreg(hw
, pphyreg
->rfintfs
,
454 rtl_set_bbreg(hw
, pphyreg
->rfintfe
, BRFSI_RFENV
<< 16, 0x1);
457 rtl_set_bbreg(hw
, pphyreg
->rfintfo
, BRFSI_RFENV
, 0x1);
460 rtl_set_bbreg(hw
, pphyreg
->rfhssi_para2
,
461 B3WIREADDREAALENGTH
, 0x0);
464 rtl_set_bbreg(hw
, pphyreg
->rfhssi_para2
, B3WIREDATALENGTH
, 0x0);
469 rtstatus
= rtl8723be_phy_config_rf_with_headerfile(hw
,
470 (enum radio_path
)rfpath
);
473 rtstatus
= rtl8723be_phy_config_rf_with_headerfile(hw
,
474 (enum radio_path
)rfpath
);
485 rtl_set_bbreg(hw
, pphyreg
->rfintfs
,
486 BRFSI_RFENV
, u4_regvalue
);
490 rtl_set_bbreg(hw
, pphyreg
->rfintfs
,
491 BRFSI_RFENV
<< 16, u4_regvalue
);
496 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
497 "Radio[%d] Fail!!", rfpath
);
502 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
, "\n");
This page took 0.072885 seconds and 5 git commands to generate.