1 /******************************************************************************
3 * Copyright(c) 2009-2012 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 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
26 * Larry Finger <Larry.Finger@lwfinger.net>
28 *****************************************************************************/
37 void rtl8723ae_phy_rf6052_set_bandwidth(struct ieee80211_hw
*hw
, u8 bandwidth
)
39 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
40 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
43 case HT_CHANNEL_WIDTH_20
:
44 rtlphy
->rfreg_chnlval
[0] = ((rtlphy
->rfreg_chnlval
[0] &
45 0xfffff3ff) | 0x0400);
46 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_CHNLBW
, RFREG_OFFSET_MASK
,
47 rtlphy
->rfreg_chnlval
[0]);
49 case HT_CHANNEL_WIDTH_20_40
:
50 rtlphy
->rfreg_chnlval
[0] = ((rtlphy
->rfreg_chnlval
[0] &
52 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_CHNLBW
, RFREG_OFFSET_MASK
,
53 rtlphy
->rfreg_chnlval
[0]);
56 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
57 "unknown bandwidth: %#X\n", bandwidth
);
62 void rtl8723ae_phy_rf6052_set_cck_txpower(struct ieee80211_hw
*hw
,
65 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
66 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
67 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
68 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
69 u32 tx_agc
[2] = {0, 0}, tmpval
;
70 bool turbo_scanoff
= false;
74 if (rtlefuse
->eeprom_regulatory
!= 0)
77 if (mac
->act_scanning
== true) {
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);
97 if (rtlefuse
->eeprom_regulatory
== 0) {
98 tmpval
= (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] << 24);
104 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
;
117 tmpval
= tx_agc
[RF90_PATH_A
] & 0xff;
118 rtl_set_bbreg(hw
, RTXAGC_A_CCK1_MCS32
, MASKBYTE1
, tmpval
);
120 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
121 "CCK PWR 1M (rf-A) = 0x%x (reg 0x%x)\n", tmpval
,
122 RTXAGC_A_CCK1_MCS32
);
124 tmpval
= tx_agc
[RF90_PATH_A
] >> 8;
126 tmpval
= tmpval
& 0xff00ffff;
128 rtl_set_bbreg(hw
, RTXAGC_B_CCK11_A_CCK2_11
, 0xffffff00, tmpval
);
130 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
131 "CCK PWR 2~11M (rf-A) = 0x%x (reg 0x%x)\n", tmpval
,
132 RTXAGC_B_CCK11_A_CCK2_11
);
134 tmpval
= tx_agc
[RF90_PATH_B
] >> 24;
135 rtl_set_bbreg(hw
, RTXAGC_B_CCK11_A_CCK2_11
, MASKBYTE0
, tmpval
);
137 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
138 "CCK PWR 11M (rf-B) = 0x%x (reg 0x%x)\n", tmpval
,
139 RTXAGC_B_CCK11_A_CCK2_11
);
141 tmpval
= tx_agc
[RF90_PATH_B
] & 0x00ffffff;
142 rtl_set_bbreg(hw
, RTXAGC_B_CCK1_55_MCS32
, 0xffffff00, tmpval
);
144 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
145 "CCK PWR 1~5.5M (rf-B) = 0x%x (reg 0x%x)\n", tmpval
,
146 RTXAGC_B_CCK1_55_MCS32
);
149 static void rtl8723ae_phy_get_power_base(struct ieee80211_hw
*hw
,
150 u8
*ppowerlevel
, u8 channel
,
151 u32
*ofdmbase
, u32
*mcsbase
)
153 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
154 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
155 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
156 u32 powerBase0
, powerBase1
;
157 u8 legacy_pwrdiff
, ht20_pwrdiff
;
160 for (i
= 0; i
< 2; i
++) {
161 powerlevel
[i
] = ppowerlevel
[i
];
162 legacy_pwrdiff
= rtlefuse
->txpwr_legacyhtdiff
[i
][channel
- 1];
163 powerBase0
= powerlevel
[i
] + legacy_pwrdiff
;
165 powerBase0
= (powerBase0
<< 24) | (powerBase0
<< 16) |
166 (powerBase0
<< 8) | powerBase0
;
167 *(ofdmbase
+ i
) = powerBase0
;
168 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
169 " [OFDM power base index rf(%c) = 0x%x]\n",
170 ((i
== 0) ? 'A' : 'B'), *(ofdmbase
+ i
));
173 for (i
= 0; i
< 2; i
++) {
174 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20
) {
175 ht20_pwrdiff
= rtlefuse
->txpwr_ht20diff
[i
][channel
- 1];
176 powerlevel
[i
] += ht20_pwrdiff
;
178 powerBase1
= powerlevel
[i
];
179 powerBase1
= (powerBase1
<< 24) |
180 (powerBase1
<< 16) | (powerBase1
<< 8) | powerBase1
;
182 *(mcsbase
+ i
) = powerBase1
;
184 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
185 " [MCS power base index rf(%c) = 0x%x]\n",
186 ((i
== 0) ? 'A' : 'B'), *(mcsbase
+ i
));
190 static void rtl8723ae_get_txpwr_val_by_reg(struct ieee80211_hw
*hw
,
191 u8 channel
, u8 index
,
196 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
197 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
198 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
199 u8 i
, chnlgroup
= 0, pwr_diff_limit
[4];
200 u32 writeVal
, customer_limit
, rf
;
202 for (rf
= 0; rf
< 2; rf
++) {
203 switch (rtlefuse
->eeprom_regulatory
) {
207 writeVal
= rtlphy
->mcs_offset
[chnlgroup
]
208 [index
+ (rf
? 8 : 0)] +
209 ((index
< 2) ? powerBase0
[rf
] :
212 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
213 "RTK better performance, "
214 "writeVal(%c) = 0x%x\n",
215 ((rf
== 0) ? 'A' : 'B'), writeVal
);
218 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20_40
) {
219 writeVal
= ((index
< 2) ? powerBase0
[rf
] :
222 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
223 "Realtek regulatory, 40MHz, "
224 "writeVal(%c) = 0x%x\n",
225 ((rf
== 0) ? 'A' : 'B'), writeVal
);
227 if (rtlphy
->pwrgroup_cnt
== 1)
229 if (rtlphy
->pwrgroup_cnt
>= 3) {
232 else if (channel
>= 4 && channel
<= 9)
234 else if (channel
> 9)
236 if (rtlphy
->current_chan_bw
==
243 writeVal
= rtlphy
->mcs_offset
[chnlgroup
]
244 [index
+ (rf
? 8 : 0)] + ((index
< 2) ?
248 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
249 "Realtek regulatory, 20MHz, writeVal(%c) = 0x%x\n",
250 ((rf
== 0) ? 'A' : 'B'), writeVal
);
255 ((index
< 2) ? powerBase0
[rf
] : powerBase1
[rf
]);
257 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
258 "Better regulatory, writeVal(%c) = 0x%x\n",
259 ((rf
== 0) ? 'A' : 'B'), writeVal
);
264 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20_40
) {
265 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
266 "customer's limit, 40MHz rf(%c) = 0x%x\n",
267 ((rf
== 0) ? 'A' : 'B'),
268 rtlefuse
->pwrgroup_ht40
[rf
][channel
-1]);
270 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
271 "customer's limit, 20MHz rf(%c) = 0x%x\n",
272 ((rf
== 0) ? 'A' : 'B'),
273 rtlefuse
->pwrgroup_ht20
[rf
][channel
-1]);
275 for (i
= 0; i
< 4; i
++) {
277 (u8
) ((rtlphy
->mcs_offset
278 [chnlgroup
][index
+ (rf
? 8 : 0)] &
279 (0x7f << (i
* 8))) >> (i
* 8));
281 if (rtlphy
->current_chan_bw
==
282 HT_CHANNEL_WIDTH_20_40
) {
283 if (pwr_diff_limit
[i
] >
285 pwrgroup_ht40
[rf
][channel
- 1])
287 rtlefuse
->pwrgroup_ht40
[rf
]
290 if (pwr_diff_limit
[i
] >
292 pwrgroup_ht20
[rf
][channel
- 1])
294 rtlefuse
->pwrgroup_ht20
[rf
]
299 customer_limit
= (pwr_diff_limit
[3] << 24) |
300 (pwr_diff_limit
[2] << 16) |
301 (pwr_diff_limit
[1] << 8) | (pwr_diff_limit
[0]);
303 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
304 "Customer's limit rf(%c) = 0x%x\n",
305 ((rf
== 0) ? 'A' : 'B'), customer_limit
);
307 writeVal
= customer_limit
+
308 ((index
< 2) ? powerBase0
[rf
] : powerBase1
[rf
]);
310 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
311 "Customer, writeVal rf(%c)= 0x%x\n",
312 ((rf
== 0) ? 'A' : 'B'), writeVal
);
316 writeVal
= rtlphy
->mcs_offset
[chnlgroup
][index
+
317 (rf
? 8 : 0)] + ((index
< 2) ? powerBase0
[rf
] :
320 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
321 "RTK better performance, writeVal rf(%c) = 0x%x\n",
322 ((rf
== 0) ? 'A' : 'B'), writeVal
);
326 if (rtlpriv
->dm
.dynamic_txhighpower_lvl
== TXHIGHPWRLEVEL_BT1
)
327 writeVal
= writeVal
- 0x06060606;
328 else if (rtlpriv
->dm
.dynamic_txhighpower_lvl
==
330 writeVal
= writeVal
- 0x0c0c0c0c;
331 *(p_outwriteval
+ rf
) = writeVal
;
335 static void _rtl8723ae_write_ofdm_power_reg(struct ieee80211_hw
*hw
,
336 u8 index
, u32
*pValue
)
338 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
339 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
341 u16 regoffset_a
[6] = {
342 RTXAGC_A_RATE18_06
, RTXAGC_A_RATE54_24
,
343 RTXAGC_A_MCS03_MCS00
, RTXAGC_A_MCS07_MCS04
,
344 RTXAGC_A_MCS11_MCS08
, RTXAGC_A_MCS15_MCS12
346 u16 regoffset_b
[6] = {
347 RTXAGC_B_RATE18_06
, RTXAGC_B_RATE54_24
,
348 RTXAGC_B_MCS03_MCS00
, RTXAGC_B_MCS07_MCS04
,
349 RTXAGC_B_MCS11_MCS08
, RTXAGC_B_MCS15_MCS12
351 u8 i
, rf
, pwr_val
[4];
355 for (rf
= 0; rf
< 2; rf
++) {
356 writeVal
= pValue
[rf
];
357 for (i
= 0; i
< 4; i
++) {
358 pwr_val
[i
] = (u8
) ((writeVal
& (0x7f <<
359 (i
* 8))) >> (i
* 8));
361 if (pwr_val
[i
] > RF6052_MAX_TX_PWR
)
362 pwr_val
[i
] = RF6052_MAX_TX_PWR
;
364 writeVal
= (pwr_val
[3] << 24) | (pwr_val
[2] << 16) |
365 (pwr_val
[1] << 8) | pwr_val
[0];
368 regoffset
= regoffset_a
[index
];
370 regoffset
= regoffset_b
[index
];
371 rtl_set_bbreg(hw
, regoffset
, MASKDWORD
, writeVal
);
373 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
374 "Set 0x%x = %08x\n", regoffset
, writeVal
);
376 if (((get_rf_type(rtlphy
) == RF_2T2R
) &&
377 (regoffset
== RTXAGC_A_MCS15_MCS12
||
378 regoffset
== RTXAGC_B_MCS15_MCS12
)) ||
379 ((get_rf_type(rtlphy
) != RF_2T2R
) &&
380 (regoffset
== RTXAGC_A_MCS07_MCS04
||
381 regoffset
== RTXAGC_B_MCS07_MCS04
))) {
383 writeVal
= pwr_val
[3];
384 if (regoffset
== RTXAGC_A_MCS15_MCS12
||
385 regoffset
== RTXAGC_A_MCS07_MCS04
)
387 if (regoffset
== RTXAGC_B_MCS15_MCS12
||
388 regoffset
== RTXAGC_B_MCS07_MCS04
)
391 for (i
= 0; i
< 3; i
++) {
392 writeVal
= (writeVal
> 6) ? (writeVal
- 6) : 0;
393 rtl_write_byte(rtlpriv
, (u32
) (regoffset
+ i
),
400 void rtl8723ae_phy_rf6052_set_ofdm_txpower(struct ieee80211_hw
*hw
,
401 u8
*ppowerlevel
, u8 channel
)
403 u32 writeVal
[2], powerBase0
[2], powerBase1
[2];
406 rtl8723ae_phy_get_power_base(hw
, ppowerlevel
,
407 channel
, &powerBase0
[0], &powerBase1
[0]);
409 for (index
= 0; index
< 6; index
++) {
410 rtl8723ae_get_txpwr_val_by_reg(hw
, channel
, index
,
415 _rtl8723ae_write_ofdm_power_reg(hw
, index
, &writeVal
[0]);
419 static bool _rtl8723ae_phy_rf6052_config_parafile(struct ieee80211_hw
*hw
)
421 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
422 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
425 bool rtstatus
= true;
426 struct bb_reg_def
*pphyreg
;
428 for (rfpath
= 0; rfpath
< rtlphy
->num_total_rfpath
; rfpath
++) {
430 pphyreg
= &rtlphy
->phyreg_def
[rfpath
];
435 u4_regvalue
= rtl_get_bbreg(hw
, pphyreg
->rfintfs
,
440 u4_regvalue
= rtl_get_bbreg(hw
, pphyreg
->rfintfs
,
445 rtl_set_bbreg(hw
, pphyreg
->rfintfe
, BRFSI_RFENV
<< 16, 0x1);
448 rtl_set_bbreg(hw
, pphyreg
->rfintfo
, BRFSI_RFENV
, 0x1);
451 rtl_set_bbreg(hw
, pphyreg
->rfhssi_para2
,
452 B3WIREADDREAALENGTH
, 0x0);
455 rtl_set_bbreg(hw
, pphyreg
->rfhssi_para2
, B3WIREDATALENGTH
, 0x0);
460 rtstatus
= rtl8723ae_phy_config_rf_with_headerfile(hw
,
461 (enum radio_path
)rfpath
);
464 rtstatus
= rtl8723ae_phy_config_rf_with_headerfile(hw
,
465 (enum radio_path
)rfpath
);
475 rtl_set_bbreg(hw
, pphyreg
->rfintfs
,
476 BRFSI_RFENV
, u4_regvalue
);
480 rtl_set_bbreg(hw
, pphyreg
->rfintfs
,
481 BRFSI_RFENV
<< 16, u4_regvalue
);
484 if (rtstatus
!= true) {
485 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
486 "Radio[%d] Fail!!", rfpath
);
490 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
, "<---\n");
494 bool rtl8723ae_phy_rf6052_config(struct ieee80211_hw
*hw
)
496 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
497 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
499 if (rtlphy
->rf_type
== RF_1T1R
)
500 rtlphy
->num_total_rfpath
= 1;
502 rtlphy
->num_total_rfpath
= 2;
504 return _rtl8723ae_phy_rf6052_config_parafile(hw
);