2 This is part of the rtl8192 driver
3 released under the GPL (See file COPYING for details).
5 This files contains programming code for the rtl8256
8 *Many* thanks to Realtek Corp. for their great support!
13 #include "r8192U_hw.h"
14 #include "r819xU_phyreg.h"
15 #include "r819xU_phy.h"
16 #include "r8190_rtl8256.h"
18 /*--------------------------------------------------------------------------
19 * Overview: set RF band width (20M or 40M)
20 * Input: struct net_device* dev
21 * WIRELESS_BANDWIDTH_E Bandwidth //20M or 40M
24 * Note: 8226 support both 20M and 40 MHz
25 *---------------------------------------------------------------------------*/
26 void PHY_SetRF8256Bandwidth(struct net_device *dev , HT_CHANNEL_WIDTH Bandwidth)
29 struct r8192_priv *priv = ieee80211_priv(dev);
31 /* for(eRFPath = RF90_PATH_A; eRFPath <pHalData->NumTotalRFPath;
34 for (eRFPath = 0; eRFPath < RF90_PATH_MAX; eRFPath++) {
35 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
39 case HT_CHANNEL_WIDTH_20:
40 if (priv->card_8192_version == VERSION_819xU_A
41 || priv->card_8192_version
42 == VERSION_819xU_B) { /* 8256 D-cut, E-cut, xiong: consider it later! */
43 rtl8192_phy_SetRFReg(dev,
44 (RF90_RADIO_PATH_E)eRFPath,
45 0x0b, bMask12Bits, 0x100); /* phy para:1ba */
46 rtl8192_phy_SetRFReg(dev,
47 (RF90_RADIO_PATH_E)eRFPath,
48 0x2c, bMask12Bits, 0x3d7);
49 rtl8192_phy_SetRFReg(dev,
50 (RF90_RADIO_PATH_E)eRFPath,
51 0x0e, bMask12Bits, 0x021);
53 /* cosa add for sd3's request 01/23/2008
55 rtl8192_phy_SetRFReg(dev,
56 (RF90_RADIO_PATH_E)eRFPath,
57 0x14, bMask12Bits, 0x5ab);
59 RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown hardware version\n");
62 case HT_CHANNEL_WIDTH_20_40:
63 if (priv->card_8192_version == VERSION_819xU_A || priv->card_8192_version == VERSION_819xU_B) { /* 8256 D-cut, E-cut, xiong: consider it later! */
64 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x0b, bMask12Bits, 0x300); //phy para:3ba
65 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x2c, bMask12Bits, 0x3df);
66 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x0e, bMask12Bits, 0x0a1);
68 //cosa add for sd3's request 01/23/2008
69 if (priv->chan == 3 || priv->chan == 9)
70 //I need to set priv->chan whenever current channel changes
71 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x14, bMask12Bits, 0x59b);
73 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x14, bMask12Bits, 0x5ab);
75 RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown hardware version\n");
79 RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown Bandwidth: %#X\n", Bandwidth);
85 /*--------------------------------------------------------------------------
86 * Overview: Interface to config 8256
87 * Input: struct net_device* dev
90 *---------------------------------------------------------------------------*/
91 void PHY_RF8256_Config(struct net_device *dev)
93 struct r8192_priv *priv = ieee80211_priv(dev);
94 // Initialize general global value
96 // TODO: Extend RF_PATH_C and RF_PATH_D in the future
97 priv->NumTotalRFPath = RTL819X_TOTAL_RF_PATH;
99 phy_RF8256_Config_ParaFile(dev);
101 /*--------------------------------------------------------------------------
102 * Overview: Interface to config 8256
103 * Input: struct net_device* dev
106 *---------------------------------------------------------------------------*/
107 void phy_RF8256_Config_ParaFile(struct net_device *dev)
110 //static s1Byte szRadioAFile[] = RTL819X_PHY_RADIO_A;
111 //static s1Byte szRadioBFile[] = RTL819X_PHY_RADIO_B;
112 //static s1Byte szRadioCFile[] = RTL819X_PHY_RADIO_C;
113 //static s1Byte szRadioDFile[] = RTL819X_PHY_RADIO_D;
115 BB_REGISTER_DEFINITION_T *pPhyReg;
116 struct r8192_priv *priv = ieee80211_priv(dev);
117 u32 RegOffSetToBeCheck = 0x3;
118 u32 RegValueToBeCheck = 0x7f1;
119 u32 RF3_Final_Value = 0;
120 u8 ConstRetryTimes = 5, RetryTimes = 5;
122 //3//-----------------------------------------------------------------
123 //3// <2> Initialize RF
124 //3//-----------------------------------------------------------------
125 for (eRFPath = (RF90_RADIO_PATH_E)RF90_PATH_A; eRFPath < priv->NumTotalRFPath; eRFPath++) {
126 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
129 pPhyReg = &priv->PHYRegDef[eRFPath];
131 // Joseph test for shorten RF config
132 // pHalData->RfReg0Value[eRFPath] = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, rGlobalCtrl, bMaskDWord);
134 /*----Store original RFENV control type----*/
138 u4RegValue = rtl8192_QueryBBReg(dev, pPhyReg->rfintfs, bRFSI_RFENV);
142 u4RegValue = rtl8192_QueryBBReg(dev, pPhyReg->rfintfs, bRFSI_RFENV<<16);
146 /*----Set RF_ENV enable----*/
147 rtl8192_setBBreg(dev, pPhyReg->rfintfe, bRFSI_RFENV<<16, 0x1);
149 /*----Set RF_ENV output high----*/
150 rtl8192_setBBreg(dev, pPhyReg->rfintfo, bRFSI_RFENV, 0x1);
152 /* Set bit number of Address and Data for RF register */
153 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireAddressLength, 0x0); // Set 0 to 4 bits for Z-serial and set 1 to 6 bits for 8258
154 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireDataLength, 0x0); // Set 0 to 12 bits for Z-serial and 8258, and set 1 to 14 bits for ???
156 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E) eRFPath, 0x0, bMask12Bits, 0xbf);
158 /*----Check RF block (for FPGA platform only)----*/
159 // TODO: this function should be removed on ASIC , Emily 2007.2.2
160 if (rtl8192_phy_checkBBAndRF(dev, HW90_BLOCK_RF, (RF90_RADIO_PATH_E)eRFPath)) {
161 RT_TRACE(COMP_ERR, "PHY_RF8256_Config():Check Radio[%d] Fail!!\n", eRFPath);
162 goto phy_RF8256_Config_ParaFile_Fail;
165 RetryTimes = ConstRetryTimes;
167 /*----Initialize RF fom connfiguration file----*/
170 while (RF3_Final_Value != RegValueToBeCheck && RetryTimes != 0) {
171 ret = rtl8192_phy_ConfigRFWithHeaderFile(dev, (RF90_RADIO_PATH_E)eRFPath);
172 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, RegOffSetToBeCheck, bMask12Bits);
173 RT_TRACE(COMP_RF, "RF %d %d register final value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value);
178 while (RF3_Final_Value != RegValueToBeCheck && RetryTimes != 0) {
179 ret = rtl8192_phy_ConfigRFWithHeaderFile(dev, (RF90_RADIO_PATH_E)eRFPath);
180 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, RegOffSetToBeCheck, bMask12Bits);
181 RT_TRACE(COMP_RF, "RF %d %d register final value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value);
186 while (RF3_Final_Value != RegValueToBeCheck && RetryTimes != 0) {
187 ret = rtl8192_phy_ConfigRFWithHeaderFile(dev, (RF90_RADIO_PATH_E)eRFPath);
188 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, RegOffSetToBeCheck, bMask12Bits);
189 RT_TRACE(COMP_RF, "RF %d %d register final value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value);
194 while (RF3_Final_Value != RegValueToBeCheck && RetryTimes != 0) {
195 ret = rtl8192_phy_ConfigRFWithHeaderFile(dev, (RF90_RADIO_PATH_E)eRFPath);
196 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, RegOffSetToBeCheck, bMask12Bits);
197 RT_TRACE(COMP_RF, "RF %d %d register final value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value);
203 /*----Restore RFENV control type----*/;
207 rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV, u4RegValue);
211 rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV<<16, u4RegValue);
216 RT_TRACE(COMP_ERR, "phy_RF8256_Config_ParaFile():Radio[%d] Fail!!", eRFPath);
217 goto phy_RF8256_Config_ParaFile_Fail;
222 RT_TRACE(COMP_PHY, "PHY Initialization Success\n");
225 phy_RF8256_Config_ParaFile_Fail:
226 RT_TRACE(COMP_ERR, "PHY Initialization failed\n");
230 void PHY_SetRF8256CCKTxPower(struct net_device *dev, u8 powerlevel)
233 struct r8192_priv *priv = ieee80211_priv(dev);
234 //modified by vivi, 20080109
237 if (priv->bDynamicTxLowPower == TRUE) {
238 //cosa 05/22/2008 for scan
239 if (priv->CustomerID == RT_CID_819x_Netcore)
242 TxAGC += priv->CckPwEnl;
247 rtl8192_setBBreg(dev, rTxAGC_CCK_Mcs32, bTxAGCRateCCK, TxAGC);
251 void PHY_SetRF8256OFDMTxPower(struct net_device *dev, u8 powerlevel)
253 struct r8192_priv *priv = ieee80211_priv(dev);
254 //Joseph TxPower for 8192 testing
255 u32 writeVal, powerBase0, powerBase1, writeVal_tmp;
257 u16 RegOffset[6] = {0xe00, 0xe04, 0xe10, 0xe14, 0xe18, 0xe1c};
258 u8 byte0, byte1, byte2, byte3;
260 powerBase0 = powerlevel + priv->TxPowerDiff; //OFDM rates
261 powerBase0 = (powerBase0<<24) | (powerBase0<<16) | (powerBase0<<8) | powerBase0;
262 powerBase1 = powerlevel; //MCS rates
263 powerBase1 = (powerBase1<<24) | (powerBase1<<16) | (powerBase1<<8) | powerBase1;
265 for (index = 0; index < 6; index++) {
266 writeVal = priv->MCSTxPowerLevelOriginalOffset[index] + ((index < 2)?powerBase0:powerBase1);
267 byte0 = (u8)(writeVal & 0x7f);
268 byte1 = (u8)((writeVal & 0x7f00)>>8);
269 byte2 = (u8)((writeVal & 0x7f0000)>>16);
270 byte3 = (u8)((writeVal & 0x7f000000)>>24);
273 /* Max power index = 0x24 */
284 writeVal_tmp = (byte3<<24) | (byte2<<16) | (byte1<<8) | byte0;
285 priv->Pwr_Track = writeVal_tmp;
288 if (priv->bDynamicTxHighPower == TRUE) {
289 /*Add by Jacken 2008/03/06
290 *Emily, 20080613. Set low tx power for both MCS and legacy OFDM
292 writeVal = 0x03030303;
294 writeVal = (byte3<<24) | (byte2<<16) | (byte1<<8) | byte0;
296 rtl8192_setBBreg(dev, RegOffset[index], 0x7f7f7f7f, writeVal);