1 /******************************************************************************
3 * Copyright(c) 2009-2013 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 rtl88e_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) | BIT(10) | BIT(11));
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] &
51 0xfffff3ff) | BIT(10));
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 rtl88e_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;
76 if (rtlefuse
->eeprom_regulatory
!= 0)
79 if (mac
->act_scanning
== true) {
80 tx_agc
[RF90_PATH_A
] = 0x3f3f3f3f;
81 tx_agc
[RF90_PATH_B
] = 0x3f3f3f3f;
84 for (idx1
= RF90_PATH_A
; idx1
<= RF90_PATH_B
; idx1
++) {
85 tx_agc
[idx1
] = plevel
[idx1
] |
87 (plevel
[idx1
] << 16) |
92 for (idx1
= RF90_PATH_A
; idx1
<= RF90_PATH_B
; idx1
++) {
93 tx_agc
[idx1
] = plevel
[idx1
] | (plevel
[idx1
] << 8) |
94 (plevel
[idx1
] << 16) |
98 if (rtlefuse
->eeprom_regulatory
== 0) {
99 tmpval
= (rtlphy
->mcs_offset
[0][6]) +
100 (rtlphy
->mcs_offset
[0][7] << 8);
101 tx_agc
[RF90_PATH_A
] += tmpval
;
103 tmpval
= (rtlphy
->mcs_offset
[0][14]) +
104 (rtlphy
->mcs_offset
[0][15] << 24);
105 tx_agc
[RF90_PATH_B
] += tmpval
;
109 for (idx1
= RF90_PATH_A
; idx1
<= RF90_PATH_B
; idx1
++) {
110 ptr
= (u8
*)(&(tx_agc
[idx1
]));
111 for (idx2
= 0; idx2
< 4; idx2
++) {
112 if (*ptr
> RF6052_MAX_TX_PWR
)
113 *ptr
= RF6052_MAX_TX_PWR
;
117 rtl88e_dm_txpower_track_adjust(hw
, 1, &direction
, &pwrtrac_value
);
118 if (direction
== 1) {
119 tx_agc
[0] += pwrtrac_value
;
120 tx_agc
[1] += pwrtrac_value
;
121 } else if (direction
== 2) {
122 tx_agc
[0] -= pwrtrac_value
;
123 tx_agc
[1] -= pwrtrac_value
;
125 tmpval
= tx_agc
[RF90_PATH_A
] & 0xff;
126 rtl_set_bbreg(hw
, RTXAGC_A_CCK1_MCS32
, MASKBYTE1
, tmpval
);
128 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
129 "CCK PWR 1M (rf-A) = 0x%x (reg 0x%x)\n", tmpval
,
130 RTXAGC_A_CCK1_MCS32
);
132 tmpval
= tx_agc
[RF90_PATH_A
] >> 8;
134 rtl_set_bbreg(hw
, RTXAGC_B_CCK11_A_CCK2_11
, 0xffffff00, tmpval
);
136 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
137 "CCK PWR 2~11M (rf-A) = 0x%x (reg 0x%x)\n", tmpval
,
138 RTXAGC_B_CCK11_A_CCK2_11
);
140 tmpval
= tx_agc
[RF90_PATH_B
] >> 24;
141 rtl_set_bbreg(hw
, RTXAGC_B_CCK11_A_CCK2_11
, MASKBYTE0
, tmpval
);
143 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
144 "CCK PWR 11M (rf-B) = 0x%x (reg 0x%x)\n", tmpval
,
145 RTXAGC_B_CCK11_A_CCK2_11
);
147 tmpval
= tx_agc
[RF90_PATH_B
] & 0x00ffffff;
148 rtl_set_bbreg(hw
, RTXAGC_B_CCK1_55_MCS32
, 0xffffff00, tmpval
);
150 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
151 "CCK PWR 1~5.5M (rf-B) = 0x%x (reg 0x%x)\n", tmpval
,
152 RTXAGC_B_CCK1_55_MCS32
);
155 static void rtl88e_phy_get_power_base(struct ieee80211_hw
*hw
,
156 u8
*pwrlvlofdm
, u8
*pwrlvlbw20
,
157 u8
*pwrlvlbw40
, u8 channel
,
158 u32
*ofdmbase
, u32
*mcsbase
)
160 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
161 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
165 for (i
= 0; i
< 2; i
++) {
166 base0
= pwrlvlofdm
[i
];
168 base0
= (base0
<< 24) | (base0
<< 16) |
169 (base0
<< 8) | base0
;
170 *(ofdmbase
+ i
) = base0
;
171 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
172 "[OFDM power base index rf(%c) = 0x%x]\n",
173 ((i
== 0) ? 'A' : 'B'), *(ofdmbase
+ i
));
176 for (i
= 0; i
< 2; i
++) {
177 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20
)
178 powerlevel
[i
] = pwrlvlbw20
[i
];
180 powerlevel
[i
] = pwrlvlbw40
[i
];
181 base1
= powerlevel
[i
];
182 base1
= (base1
<< 24) |
183 (base1
<< 16) | (base1
<< 8) | base1
;
185 *(mcsbase
+ i
) = base1
;
187 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
188 "[MCS power base index rf(%c) = 0x%x]\n",
189 ((i
== 0) ? 'A' : 'B'), *(mcsbase
+ i
));
193 static void get_txpwr_by_reg(struct ieee80211_hw
*hw
, u8 chan
, u8 index
,
194 u32
*base0
, u32
*base1
, u32
*outval
)
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
, chg
= 0, pwr_lim
[4], pwr_diff
= 0, cust_pwr_dif
;
200 u32 writeval
, cust_lim
, rf
, tmp
;
204 for (rf
= 0; rf
< 2; rf
++) {
205 j
= index
+ (rf
? 8 : 0);
206 tmp
= ((index
< 2) ? base0
[rf
] : base1
[rf
]);
207 switch (rtlefuse
->eeprom_regulatory
) {
211 writeval
= rtlphy
->mcs_offset
[chg
][j
] + tmp
;
213 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
214 "RTK better performance, "
215 "writeval(%c) = 0x%x\n",
216 ((rf
== 0) ? 'A' : 'B'), writeval
);
219 if (rtlphy
->pwrgroup_cnt
== 1) {
226 writeval
= rtlphy
->mcs_offset
[chg
][j
] + tmp
;
228 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
229 "Realtek regulatory, 20MHz, writeval(%c) = 0x%x\n",
230 ((rf
== 0) ? 'A' : 'B'), writeval
);
233 writeval
= ((index
< 2) ? base0
[rf
] : base1
[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
][ch
]);
248 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
249 "customer's limit, 20MHz rf(%c) = 0x%x\n",
250 ((rf
== 0) ? 'A' : 'B'),
251 rtlefuse
->pwrgroup_ht20
[rf
][ch
]);
255 pwr_diff
= rtlefuse
->txpwr_legacyhtdiff
[rf
][ch
];
256 else if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20
)
257 pwr_diff
= rtlefuse
->txpwr_ht20diff
[rf
][ch
];
259 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20_40
)
260 cust_pwr_dif
= rtlefuse
->pwrgroup_ht40
[rf
][ch
];
262 cust_pwr_dif
= rtlefuse
->pwrgroup_ht20
[rf
][ch
];
264 if (pwr_diff
> cust_pwr_dif
)
267 pwr_diff
= cust_pwr_dif
- pwr_diff
;
269 for (i
= 0; i
< 4; i
++) {
270 pwr_lim
[i
] = (u8
)((rtlphy
->mcs_offset
[chg
][j
] &
271 (0x7f << (i
* 8))) >> (i
* 8));
273 if (pwr_lim
[i
] > pwr_diff
)
274 pwr_lim
[i
] = pwr_diff
;
277 cust_lim
= (pwr_lim
[3] << 24) | (pwr_lim
[2] << 16) |
278 (pwr_lim
[1] << 8) | (pwr_lim
[0]);
280 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
281 "Customer's limit rf(%c) = 0x%x\n",
282 ((rf
== 0) ? 'A' : 'B'), cust_lim
);
284 writeval
= cust_lim
+ tmp
;
286 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
287 "Customer, writeval rf(%c) = 0x%x\n",
288 ((rf
== 0) ? 'A' : 'B'), writeval
);
292 writeval
= rtlphy
->mcs_offset
[chg
][j
] + tmp
;
294 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
295 "RTK better performance, writeval "
297 ((rf
== 0) ? 'A' : 'B'), writeval
);
301 if (rtlpriv
->dm
.dynamic_txhighpower_lvl
== TXHIGHPWRLEVEL_BT1
)
302 writeval
= writeval
- 0x06060606;
303 else if (rtlpriv
->dm
.dynamic_txhighpower_lvl
==
305 writeval
-= 0x0c0c0c0c;
306 *(outval
+ rf
) = writeval
;
310 static void write_ofdm_pwr(struct ieee80211_hw
*hw
, u8 index
, u32
*pvalue
)
312 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
313 u16 regoffset_a
[6] = {
314 RTXAGC_A_RATE18_06
, RTXAGC_A_RATE54_24
,
315 RTXAGC_A_MCS03_MCS00
, RTXAGC_A_MCS07_MCS04
,
316 RTXAGC_A_MCS11_MCS08
, RTXAGC_A_MCS15_MCS12
318 u16 regoffset_b
[6] = {
319 RTXAGC_B_RATE18_06
, RTXAGC_B_RATE54_24
,
320 RTXAGC_B_MCS03_MCS00
, RTXAGC_B_MCS07_MCS04
,
321 RTXAGC_B_MCS11_MCS08
, RTXAGC_B_MCS15_MCS12
323 u8 i
, rf
, pwr_val
[4];
327 for (rf
= 0; rf
< 2; rf
++) {
328 writeval
= pvalue
[rf
];
329 for (i
= 0; i
< 4; i
++) {
330 pwr_val
[i
] = (u8
) ((writeval
& (0x7f <<
331 (i
* 8))) >> (i
* 8));
333 if (pwr_val
[i
] > RF6052_MAX_TX_PWR
)
334 pwr_val
[i
] = RF6052_MAX_TX_PWR
;
336 writeval
= (pwr_val
[3] << 24) | (pwr_val
[2] << 16) |
337 (pwr_val
[1] << 8) | pwr_val
[0];
340 regoffset
= regoffset_a
[index
];
342 regoffset
= regoffset_b
[index
];
343 rtl_set_bbreg(hw
, regoffset
, MASKDWORD
, writeval
);
345 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
346 "Set 0x%x = %08x\n", regoffset
, writeval
);
350 void rtl88e_phy_rf6052_set_ofdm_txpower(struct ieee80211_hw
*hw
,
353 u8
*pwrlvlbw40
, u8 chan
)
355 u32 writeval
[2], base0
[2], base1
[2];
360 rtl88e_phy_get_power_base(hw
, pwrlvlofdm
, pwrlvlbw20
,
361 pwrlvlbw40
, chan
, &base0
[0],
364 rtl88e_dm_txpower_track_adjust(hw
, 1, &direction
, &pwrtrac_value
);
366 for (index
= 0; index
< 6; index
++) {
367 get_txpwr_by_reg(hw
, chan
, index
, &base0
[0], &base1
[0],
369 if (direction
== 1) {
370 writeval
[0] += pwrtrac_value
;
371 writeval
[1] += pwrtrac_value
;
372 } else if (direction
== 2) {
373 writeval
[0] -= pwrtrac_value
;
374 writeval
[1] -= pwrtrac_value
;
376 write_ofdm_pwr(hw
, index
, &writeval
[0]);
380 static bool rf6052_conf_para(struct ieee80211_hw
*hw
)
382 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
383 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
386 bool rtstatus
= true;
387 struct bb_reg_def
*pphyreg
;
389 for (rfpath
= 0; rfpath
< rtlphy
->num_total_rfpath
; rfpath
++) {
390 pphyreg
= &rtlphy
->phyreg_def
[rfpath
];
395 u4val
= rtl_get_bbreg(hw
, pphyreg
->rfintfs
,
400 u4val
= rtl_get_bbreg(hw
, pphyreg
->rfintfs
,
405 rtl_set_bbreg(hw
, pphyreg
->rfintfe
, BRFSI_RFENV
<< 16, 0x1);
408 rtl_set_bbreg(hw
, pphyreg
->rfintfo
, BRFSI_RFENV
, 0x1);
411 rtl_set_bbreg(hw
, pphyreg
->rfhssi_para2
,
412 B3WIREADDREAALENGTH
, 0x0);
415 rtl_set_bbreg(hw
, pphyreg
->rfhssi_para2
, B3WIREDATALENGTH
, 0x0);
420 rtstatus
= rtl88e_phy_config_rf_with_headerfile(hw
,
421 (enum radio_path
)rfpath
);
424 rtstatus
= rtl88e_phy_config_rf_with_headerfile(hw
,
425 (enum radio_path
)rfpath
);
436 rtl_set_bbreg(hw
, pphyreg
->rfintfs
, BRFSI_RFENV
, u4val
);
440 rtl_set_bbreg(hw
, pphyreg
->rfintfs
, BRFSI_RFENV
<< 16,
445 if (rtstatus
!= true) {
446 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
447 "Radio[%d] Fail!!", rfpath
);
452 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
, "\n");
456 bool rtl88e_phy_rf6052_config(struct ieee80211_hw
*hw
)
458 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
459 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
461 if (rtlphy
->rf_type
== RF_1T1R
)
462 rtlphy
->num_total_rfpath
= 1;
464 rtlphy
->num_total_rfpath
= 2;
466 return rf6052_conf_para(hw
);