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 * 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 _rtl92ce_phy_rf6052_config_parafile(struct ieee80211_hw
*hw
);
35 void rtl92ce_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) | 0x0400);
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] &
50 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_CHNLBW
, RFREG_OFFSET_MASK
,
51 rtlphy
->rfreg_chnlval
[0]);
54 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
55 "unknown bandwidth: %#X\n", bandwidth
);
60 void rtl92ce_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;
72 if (rtlefuse
->eeprom_regulatory
!= 0)
75 if (mac
->act_scanning
) {
76 tx_agc
[RF90_PATH_A
] = 0x3f3f3f3f;
77 tx_agc
[RF90_PATH_B
] = 0x3f3f3f3f;
80 for (idx1
= RF90_PATH_A
; idx1
<= RF90_PATH_B
; idx1
++) {
81 tx_agc
[idx1
] = ppowerlevel
[idx1
] |
82 (ppowerlevel
[idx1
] << 8) |
83 (ppowerlevel
[idx1
] << 16) |
84 (ppowerlevel
[idx1
] << 24);
88 for (idx1
= RF90_PATH_A
; idx1
<= RF90_PATH_B
; idx1
++) {
89 tx_agc
[idx1
] = ppowerlevel
[idx1
] |
90 (ppowerlevel
[idx1
] << 8) |
91 (ppowerlevel
[idx1
] << 16) |
92 (ppowerlevel
[idx1
] << 24);
95 if (rtlefuse
->eeprom_regulatory
== 0) {
96 tmpval
= (rtlphy
->mcs_offset
[0][6]) +
97 (rtlphy
->mcs_offset
[0][7] << 8);
98 tx_agc
[RF90_PATH_A
] += tmpval
;
100 tmpval
= (rtlphy
->mcs_offset
[0][14]) +
101 (rtlphy
->mcs_offset
[0][15] << 24);
102 tx_agc
[RF90_PATH_B
] += tmpval
;
106 for (idx1
= RF90_PATH_A
; idx1
<= RF90_PATH_B
; idx1
++) {
107 ptr
= (u8
*) (&(tx_agc
[idx1
]));
108 for (idx2
= 0; idx2
< 4; idx2
++) {
109 if (*ptr
> RF6052_MAX_TX_PWR
)
110 *ptr
= RF6052_MAX_TX_PWR
;
115 tmpval
= tx_agc
[RF90_PATH_A
] & 0xff;
116 rtl_set_bbreg(hw
, RTXAGC_A_CCK1_MCS32
, MASKBYTE1
, tmpval
);
118 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
119 "CCK PWR 1M (rf-A) = 0x%x (reg 0x%x)\n",
120 tmpval
, RTXAGC_A_CCK1_MCS32
);
122 tmpval
= tx_agc
[RF90_PATH_A
] >> 8;
124 tmpval
= tmpval
& 0xff00ffff;
126 rtl_set_bbreg(hw
, RTXAGC_B_CCK11_A_CCK2_11
, 0xffffff00, tmpval
);
128 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
129 "CCK PWR 2~11M (rf-A) = 0x%x (reg 0x%x)\n",
130 tmpval
, RTXAGC_B_CCK11_A_CCK2_11
);
132 tmpval
= tx_agc
[RF90_PATH_B
] >> 24;
133 rtl_set_bbreg(hw
, RTXAGC_B_CCK11_A_CCK2_11
, MASKBYTE0
, tmpval
);
135 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
136 "CCK PWR 11M (rf-B) = 0x%x (reg 0x%x)\n",
137 tmpval
, RTXAGC_B_CCK11_A_CCK2_11
);
139 tmpval
= tx_agc
[RF90_PATH_B
] & 0x00ffffff;
140 rtl_set_bbreg(hw
, RTXAGC_B_CCK1_55_MCS32
, 0xffffff00, tmpval
);
142 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
143 "CCK PWR 1~5.5M (rf-B) = 0x%x (reg 0x%x)\n",
144 tmpval
, RTXAGC_B_CCK1_55_MCS32
);
147 static void rtl92c_phy_get_power_base(struct ieee80211_hw
*hw
,
148 u8
*ppowerlevel
, u8 channel
,
149 u32
*ofdmbase
, u32
*mcsbase
)
151 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
152 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
153 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
154 u32 powerBase0
, powerBase1
;
155 u8 legacy_pwrdiff
, ht20_pwrdiff
;
158 for (i
= 0; i
< 2; i
++) {
159 powerlevel
[i
] = ppowerlevel
[i
];
160 legacy_pwrdiff
= rtlefuse
->txpwr_legacyhtdiff
[i
][channel
- 1];
161 powerBase0
= powerlevel
[i
] + legacy_pwrdiff
;
163 powerBase0
= (powerBase0
<< 24) | (powerBase0
<< 16) |
164 (powerBase0
<< 8) | powerBase0
;
165 *(ofdmbase
+ i
) = powerBase0
;
166 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
167 " [OFDM power base index rf(%c) = 0x%x]\n",
168 i
== 0 ? 'A' : 'B', *(ofdmbase
+ i
));
171 for (i
= 0; i
< 2; i
++) {
172 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20
) {
173 ht20_pwrdiff
= rtlefuse
->txpwr_ht20diff
[i
][channel
- 1];
174 powerlevel
[i
] += ht20_pwrdiff
;
176 powerBase1
= powerlevel
[i
];
177 powerBase1
= (powerBase1
<< 24) |
178 (powerBase1
<< 16) | (powerBase1
<< 8) | powerBase1
;
180 *(mcsbase
+ i
) = powerBase1
;
182 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
183 " [MCS power base index rf(%c) = 0x%x]\n",
184 i
== 0 ? 'A' : 'B', *(mcsbase
+ i
));
188 static void _rtl92c_get_txpower_writeval_by_regulatory(struct ieee80211_hw
*hw
,
189 u8 channel
, u8 index
,
194 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
195 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
196 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
197 u8 i
, chnlgroup
= 0, pwr_diff_limit
[4];
198 u32 writeVal
, customer_limit
, rf
;
200 for (rf
= 0; rf
< 2; rf
++) {
201 switch (rtlefuse
->eeprom_regulatory
) {
205 writeVal
= rtlphy
->mcs_offset
[chnlgroup
][index
+
207 + ((index
< 2) ? powerBase0
[rf
] : powerBase1
[rf
]);
209 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
210 "RTK better performance, writeVal(%c) = 0x%x\n",
211 rf
== 0 ? 'A' : 'B', writeVal
);
214 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20_40
) {
215 writeVal
= ((index
< 2) ? powerBase0
[rf
] :
218 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
219 "Realtek regulatory, 40MHz, writeVal(%c) = 0x%x\n",
220 rf
== 0 ? 'A' : 'B', writeVal
);
222 if (rtlphy
->pwrgroup_cnt
== 1)
224 if (rtlphy
->pwrgroup_cnt
>= 3) {
227 else if (channel
>= 4 && channel
<= 9)
229 else if (channel
> 9)
231 if (rtlphy
->pwrgroup_cnt
== 4)
235 writeVal
= rtlphy
->mcs_offset
[chnlgroup
]
236 [index
+ (rf
? 8 : 0)] + ((index
< 2) ?
240 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
241 "Realtek regulatory, 20MHz, writeVal(%c) = 0x%x\n",
242 rf
== 0 ? 'A' : 'B', writeVal
);
247 ((index
< 2) ? powerBase0
[rf
] : powerBase1
[rf
]);
249 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
250 "Better regulatory, writeVal(%c) = 0x%x\n",
251 rf
== 0 ? 'A' : 'B', writeVal
);
256 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20_40
) {
257 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
258 "customer's limit, 40MHz rf(%c) = 0x%x\n",
260 rtlefuse
->pwrgroup_ht40
[rf
][channel
-
263 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
264 "customer's limit, 20MHz rf(%c) = 0x%x\n",
266 rtlefuse
->pwrgroup_ht20
[rf
][channel
-
269 for (i
= 0; i
< 4; i
++) {
270 pwr_diff_limit
[i
] = (u8
) ((rtlphy
->mcs_offset
272 (rf
? 8 : 0)] & (0x7f << (i
* 8))) >>
275 if (rtlphy
->current_chan_bw
==
276 HT_CHANNEL_WIDTH_20_40
) {
277 if (pwr_diff_limit
[i
] >
279 pwrgroup_ht40
[rf
][channel
- 1])
281 rtlefuse
->pwrgroup_ht40
[rf
]
284 if (pwr_diff_limit
[i
] >
286 pwrgroup_ht20
[rf
][channel
- 1])
288 rtlefuse
->pwrgroup_ht20
[rf
]
293 customer_limit
= (pwr_diff_limit
[3] << 24) |
294 (pwr_diff_limit
[2] << 16) |
295 (pwr_diff_limit
[1] << 8) | (pwr_diff_limit
[0]);
297 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
298 "Customer's limit rf(%c) = 0x%x\n",
299 rf
== 0 ? 'A' : 'B', customer_limit
);
301 writeVal
= customer_limit
+
302 ((index
< 2) ? powerBase0
[rf
] : powerBase1
[rf
]);
304 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
305 "Customer, writeVal rf(%c)= 0x%x\n",
306 rf
== 0 ? 'A' : 'B', writeVal
);
310 writeVal
= rtlphy
->mcs_offset
[chnlgroup
]
311 [index
+ (rf
? 8 : 0)]
312 + ((index
< 2) ? powerBase0
[rf
] : powerBase1
[rf
]);
314 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
315 "RTK better performance, writeVal rf(%c) = 0x%x\n",
316 rf
== 0 ? 'A' : 'B', writeVal
);
320 if (rtlpriv
->dm
.dynamic_txhighpower_lvl
== TXHIGHPWRLEVEL_BT1
)
321 writeVal
= writeVal
- 0x06060606;
322 else if (rtlpriv
->dm
.dynamic_txhighpower_lvl
==
324 writeVal
= writeVal
- 0x0c0c0c0c;
325 *(p_outwriteval
+ rf
) = writeVal
;
329 static void _rtl92c_write_ofdm_power_reg(struct ieee80211_hw
*hw
,
330 u8 index
, u32
*pValue
)
332 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
333 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
335 u16 regoffset_a
[6] = {
336 RTXAGC_A_RATE18_06
, RTXAGC_A_RATE54_24
,
337 RTXAGC_A_MCS03_MCS00
, RTXAGC_A_MCS07_MCS04
,
338 RTXAGC_A_MCS11_MCS08
, RTXAGC_A_MCS15_MCS12
340 u16 regoffset_b
[6] = {
341 RTXAGC_B_RATE18_06
, RTXAGC_B_RATE54_24
,
342 RTXAGC_B_MCS03_MCS00
, RTXAGC_B_MCS07_MCS04
,
343 RTXAGC_B_MCS11_MCS08
, RTXAGC_B_MCS15_MCS12
345 u8 i
, rf
, pwr_val
[4];
349 for (rf
= 0; rf
< 2; rf
++) {
350 writeVal
= pValue
[rf
];
351 for (i
= 0; i
< 4; i
++) {
352 pwr_val
[i
] = (u8
) ((writeVal
& (0x7f <<
353 (i
* 8))) >> (i
* 8));
355 if (pwr_val
[i
] > RF6052_MAX_TX_PWR
)
356 pwr_val
[i
] = RF6052_MAX_TX_PWR
;
358 writeVal
= (pwr_val
[3] << 24) | (pwr_val
[2] << 16) |
359 (pwr_val
[1] << 8) | pwr_val
[0];
362 regoffset
= regoffset_a
[index
];
364 regoffset
= regoffset_b
[index
];
365 rtl_set_bbreg(hw
, regoffset
, MASKDWORD
, writeVal
);
367 RTPRINT(rtlpriv
, FPHY
, PHY_TXPWR
,
368 "Set 0x%x = %08x\n", regoffset
, writeVal
);
370 if (((get_rf_type(rtlphy
) == RF_2T2R
) &&
371 (regoffset
== RTXAGC_A_MCS15_MCS12
||
372 regoffset
== RTXAGC_B_MCS15_MCS12
)) ||
373 ((get_rf_type(rtlphy
) != RF_2T2R
) &&
374 (regoffset
== RTXAGC_A_MCS07_MCS04
||
375 regoffset
== RTXAGC_B_MCS07_MCS04
))) {
377 writeVal
= pwr_val
[3];
378 if (regoffset
== RTXAGC_A_MCS15_MCS12
||
379 regoffset
== RTXAGC_A_MCS07_MCS04
)
381 if (regoffset
== RTXAGC_B_MCS15_MCS12
||
382 regoffset
== RTXAGC_B_MCS07_MCS04
)
385 for (i
= 0; i
< 3; i
++) {
386 writeVal
= (writeVal
> 6) ? (writeVal
- 6) : 0;
387 rtl_write_byte(rtlpriv
, (u32
) (regoffset
+ i
),
394 void rtl92ce_phy_rf6052_set_ofdm_txpower(struct ieee80211_hw
*hw
,
395 u8
*ppowerlevel
, u8 channel
)
397 u32 writeVal
[2], powerBase0
[2], powerBase1
[2];
400 rtl92c_phy_get_power_base(hw
, ppowerlevel
,
401 channel
, &powerBase0
[0], &powerBase1
[0]);
403 for (index
= 0; index
< 6; index
++) {
404 _rtl92c_get_txpower_writeval_by_regulatory(hw
,
410 _rtl92c_write_ofdm_power_reg(hw
, index
, &writeVal
[0]);
414 bool rtl92ce_phy_rf6052_config(struct ieee80211_hw
*hw
)
416 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
417 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
419 if (rtlphy
->rf_type
== RF_1T1R
)
420 rtlphy
->num_total_rfpath
= 1;
422 rtlphy
->num_total_rfpath
= 2;
424 return _rtl92ce_phy_rf6052_config_parafile(hw
);
428 static bool _rtl92ce_phy_rf6052_config_parafile(struct ieee80211_hw
*hw
)
430 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
431 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
434 bool rtstatus
= true;
435 struct bb_reg_def
*pphyreg
;
437 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
= rtl92c_phy_config_rf_with_headerfile(hw
,
470 (enum radio_path
)rfpath
);
473 rtstatus
= rtl92c_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!!\n", rfpath
);
503 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
, "<---\n");