1 /******************************************************************************
2 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
4 * This program is distributed in the hope that it will be useful, but WITHOUT
5 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
9 * You should have received a copy of the GNU General Public License along with
10 * this program; if not, write to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
13 * The full GNU General Public License is included in this distribution in the
14 * file called LICENSE.
16 * Contact Information:
17 * wlanfae <wlanfae@realtek.com>
18 ******************************************************************************/
21 #include "r8192E_phyreg.h"
22 #include "r8192E_phy.h"
23 #include "r8190P_rtl8256.h"
25 void PHY_SetRF8256Bandwidth(struct net_device
*dev
,
26 enum ht_channel_width Bandwidth
)
29 struct r8192_priv
*priv
= rtllib_priv(dev
);
31 for (eRFPath
= 0; eRFPath
< priv
->NumTotalRFPath
; eRFPath
++) {
32 if (!rtl8192_phy_CheckIsLegalRFPath(dev
, eRFPath
))
36 case HT_CHANNEL_WIDTH_20
:
37 if (priv
->card_8192_version
== VERSION_8190_BD
||
38 priv
->card_8192_version
== VERSION_8190_BE
) {
39 rtl8192_phy_SetRFReg(dev
,
40 (enum rf90_radio_path
)eRFPath
,
41 0x0b, bMask12Bits
, 0x100);
42 rtl8192_phy_SetRFReg(dev
,
43 (enum rf90_radio_path
)eRFPath
,
44 0x2c, bMask12Bits
, 0x3d7);
45 rtl8192_phy_SetRFReg(dev
,
46 (enum rf90_radio_path
)eRFPath
,
47 0x0e, bMask12Bits
, 0x021);
50 RT_TRACE(COMP_ERR
, "PHY_SetRF8256Bandwidth(): "
51 "unknown hardware version\n");
55 case HT_CHANNEL_WIDTH_20_40
:
56 if (priv
->card_8192_version
== VERSION_8190_BD
||
57 priv
->card_8192_version
== VERSION_8190_BE
) {
58 rtl8192_phy_SetRFReg(dev
,
59 (enum rf90_radio_path
)eRFPath
,
60 0x0b, bMask12Bits
, 0x300);
61 rtl8192_phy_SetRFReg(dev
,
62 (enum rf90_radio_path
)eRFPath
,
63 0x2c, bMask12Bits
, 0x3ff);
64 rtl8192_phy_SetRFReg(dev
,
65 (enum rf90_radio_path
)eRFPath
,
66 0x0e, bMask12Bits
, 0x0e1);
69 RT_TRACE(COMP_ERR
, "PHY_SetRF8256Bandwidth(): "
70 "unknown hardware version\n");
76 RT_TRACE(COMP_ERR
, "PHY_SetRF8256Bandwidth(): unknown "
77 "Bandwidth: %#X\n", Bandwidth
);
85 bool PHY_RF8256_Config(struct net_device
*dev
)
87 struct r8192_priv
*priv
= rtllib_priv(dev
);
89 priv
->NumTotalRFPath
= RTL819X_TOTAL_RF_PATH
;
90 rtStatus
= phy_RF8256_Config_ParaFile(dev
);
95 bool phy_RF8256_Config_ParaFile(struct net_device
*dev
)
100 struct bb_reg_definition
*pPhyReg
;
101 struct r8192_priv
*priv
= rtllib_priv(dev
);
102 u32 RegOffSetToBeCheck
= 0x3;
103 u32 RegValueToBeCheck
= 0x7f1;
104 u32 RF3_Final_Value
= 0;
105 u8 ConstRetryTimes
= 5, RetryTimes
= 5;
108 for (eRFPath
= (enum rf90_radio_path
)RF90_PATH_A
;
109 eRFPath
< priv
->NumTotalRFPath
; eRFPath
++) {
110 if (!rtl8192_phy_CheckIsLegalRFPath(dev
, eRFPath
))
113 pPhyReg
= &priv
->PHYRegDef
[eRFPath
];
119 u4RegValue
= rtl8192_QueryBBReg(dev
, pPhyReg
->rfintfs
,
124 u4RegValue
= rtl8192_QueryBBReg(dev
, pPhyReg
->rfintfs
,
129 rtl8192_setBBreg(dev
, pPhyReg
->rfintfe
, bRFSI_RFENV
<<16, 0x1);
131 rtl8192_setBBreg(dev
, pPhyReg
->rfintfo
, bRFSI_RFENV
, 0x1);
133 rtl8192_setBBreg(dev
, pPhyReg
->rfHSSIPara2
,
134 b3WireAddressLength
, 0x0);
135 rtl8192_setBBreg(dev
, pPhyReg
->rfHSSIPara2
,
136 b3WireDataLength
, 0x0);
138 rtl8192_phy_SetRFReg(dev
, (enum rf90_radio_path
) eRFPath
, 0x0,
141 rtStatus
= rtl8192_phy_checkBBAndRF(dev
, HW90_BLOCK_RF
,
142 (enum rf90_radio_path
)eRFPath
);
143 if (rtStatus
!= true) {
144 RT_TRACE(COMP_ERR
, "PHY_RF8256_Config():Check "
145 "Radio[%d] Fail!!\n", eRFPath
);
146 goto phy_RF8256_Config_ParaFile_Fail
;
149 RetryTimes
= ConstRetryTimes
;
153 while (RF3_Final_Value
!= RegValueToBeCheck
&&
155 ret
= rtl8192_phy_ConfigRFWithHeaderFile(dev
,
156 (enum rf90_radio_path
)eRFPath
);
157 RF3_Final_Value
= rtl8192_phy_QueryRFReg(dev
,
158 (enum rf90_radio_path
)eRFPath
,
161 RT_TRACE(COMP_RF
, "RF %d %d register final "
162 "value: %x\n", eRFPath
,
163 RegOffSetToBeCheck
, RF3_Final_Value
);
168 while (RF3_Final_Value
!= RegValueToBeCheck
&&
170 ret
= rtl8192_phy_ConfigRFWithHeaderFile(dev
,
171 (enum rf90_radio_path
)eRFPath
);
172 RF3_Final_Value
= rtl8192_phy_QueryRFReg(dev
,
173 (enum rf90_radio_path
)eRFPath
,
176 RT_TRACE(COMP_RF
, "RF %d %d register final "
177 "value: %x\n", eRFPath
,
178 RegOffSetToBeCheck
, RF3_Final_Value
);
183 while (RF3_Final_Value
!= RegValueToBeCheck
&&
185 ret
= rtl8192_phy_ConfigRFWithHeaderFile(dev
,
186 (enum rf90_radio_path
)eRFPath
);
187 RF3_Final_Value
= rtl8192_phy_QueryRFReg(dev
,
188 (enum rf90_radio_path
)eRFPath
,
191 RT_TRACE(COMP_RF
, "RF %d %d register final "
192 "value: %x\n", eRFPath
,
193 RegOffSetToBeCheck
, RF3_Final_Value
);
198 while (RF3_Final_Value
!= RegValueToBeCheck
&&
200 ret
= rtl8192_phy_ConfigRFWithHeaderFile(dev
,
201 (enum rf90_radio_path
)eRFPath
);
202 RF3_Final_Value
= rtl8192_phy_QueryRFReg(dev
,
203 (enum rf90_radio_path
)eRFPath
,
204 RegOffSetToBeCheck
, bMask12Bits
);
205 RT_TRACE(COMP_RF
, "RF %d %d register final "
206 "value: %x\n", eRFPath
,
207 RegOffSetToBeCheck
, RF3_Final_Value
);
216 rtl8192_setBBreg(dev
, pPhyReg
->rfintfs
, bRFSI_RFENV
,
221 rtl8192_setBBreg(dev
, pPhyReg
->rfintfs
, bRFSI_RFENV
<<16,
227 RT_TRACE(COMP_ERR
, "phy_RF8256_Config_ParaFile():"
228 "Radio[%d] Fail!!", eRFPath
);
229 goto phy_RF8256_Config_ParaFile_Fail
;
234 RT_TRACE(COMP_PHY
, "PHY Initialization Success\n") ;
237 phy_RF8256_Config_ParaFile_Fail
:
238 RT_TRACE(COMP_ERR
, "PHY Initialization failed\n") ;
242 void PHY_SetRF8256CCKTxPower(struct net_device
*dev
, u8 powerlevel
)
245 struct r8192_priv
*priv
= rtllib_priv(dev
);
248 if (priv
->bDynamicTxLowPower
== true) {
249 if (priv
->CustomerID
== RT_CID_819x_Netcore
)
252 TxAGC
+= priv
->CckPwEnl
;
256 rtl8192_setBBreg(dev
, rTxAGC_CCK_Mcs32
, bTxAGCRateCCK
, TxAGC
);
260 void PHY_SetRF8256OFDMTxPower(struct net_device
*dev
, u8 powerlevel
)
262 struct r8192_priv
*priv
= rtllib_priv(dev
);
263 u32 writeVal
, powerBase0
, powerBase1
, writeVal_tmp
;
265 u16 RegOffset
[6] = {0xe00, 0xe04, 0xe10, 0xe14, 0xe18, 0xe1c};
266 u8 byte0
, byte1
, byte2
, byte3
;
268 powerBase0
= powerlevel
+ priv
->LegacyHTTxPowerDiff
;
269 powerBase0
= (powerBase0
<< 24) | (powerBase0
<< 16) |
270 (powerBase0
<< 8) | powerBase0
;
271 powerBase1
= powerlevel
;
272 powerBase1
= (powerBase1
<< 24) | (powerBase1
<< 16) |
273 (powerBase1
<< 8) | powerBase1
;
275 for (index
= 0; index
< 6; index
++) {
276 writeVal
= (u32
)(priv
->MCSTxPowerLevelOriginalOffset
[index
] +
277 ((index
< 2) ? powerBase0
: powerBase1
));
278 byte0
= (u8
)(writeVal
& 0x7f);
279 byte1
= (u8
)((writeVal
& 0x7f00)>>8);
280 byte2
= (u8
)((writeVal
& 0x7f0000)>>16);
281 byte3
= (u8
)((writeVal
& 0x7f000000)>>24);
292 writeVal_tmp
= (byte3
<< 24) | (byte2
<< 16) |
293 (byte1
<< 8) | byte0
;
294 priv
->Pwr_Track
= writeVal_tmp
;
297 if (priv
->bDynamicTxHighPower
== true)
298 writeVal
= 0x03030303;
300 writeVal
= (byte3
<< 24) | (byte2
<< 16) |
301 (byte1
<< 8) | byte0
;
302 rtl8192_setBBreg(dev
, RegOffset
[index
], 0x7f7f7f7f, writeVal
);