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!
12 #include "r8192U_hw.h"
13 #include "r819xU_phyreg.h"
14 #include "r819xU_phy.h"
15 #include "r8190_rtl8256.h"
17 /*--------------------------------------------------------------------------
18 * Overview: set RF band width (20M or 40M)
19 * Input: struct net_device* dev
20 * WIRELESS_BANDWIDTH_E Bandwidth //20M or 40M
23 * Note: 8226 support both 20M and 40 MHz
24 *--------------------------------------------------------------------------
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);
52 rtl8192_phy_SetRFReg(dev,
53 (RF90_RADIO_PATH_E)eRFPath,
54 0x14, bMask12Bits, 0x5ab);
56 RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown hardware version\n");
59 case HT_CHANNEL_WIDTH_20_40:
60 if (priv->card_8192_version == VERSION_819xU_A || priv->card_8192_version == VERSION_819xU_B) { /* 8256 D-cut, E-cut, xiong: consider it later! */
61 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x0b, bMask12Bits, 0x300); /* phy para:3ba */
62 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x2c, bMask12Bits, 0x3df);
63 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x0e, bMask12Bits, 0x0a1);
65 if (priv->chan == 3 || priv->chan == 9)
66 /* I need to set priv->chan whenever current channel changes */
67 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x14, bMask12Bits, 0x59b);
69 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x14, bMask12Bits, 0x5ab);
71 RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown hardware version\n");
75 RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown Bandwidth: %#X\n", Bandwidth);
81 /*--------------------------------------------------------------------------
82 * Overview: Interface to config 8256
83 * Input: struct net_device* dev
86 *--------------------------------------------------------------------------
88 void PHY_RF8256_Config(struct net_device *dev)
90 struct r8192_priv *priv = ieee80211_priv(dev);
91 /* Initialize general global value
93 * TODO: Extend RF_PATH_C and RF_PATH_D in the future
95 priv->NumTotalRFPath = RTL819X_TOTAL_RF_PATH;
96 /* Config BB and RF */
97 phy_RF8256_Config_ParaFile(dev);
99 /*--------------------------------------------------------------------------
100 * Overview: Interface to config 8256
101 * Input: struct net_device* dev
104 *--------------------------------------------------------------------------
106 void phy_RF8256_Config_ParaFile(struct net_device *dev)
110 BB_REGISTER_DEFINITION_T *pPhyReg;
111 struct r8192_priv *priv = ieee80211_priv(dev);
112 u32 RegOffSetToBeCheck = 0x3;
113 u32 RegValueToBeCheck = 0x7f1;
114 u32 RF3_Final_Value = 0;
115 u8 ConstRetryTimes = 5, RetryTimes = 5;
118 for (eRFPath = (RF90_RADIO_PATH_E)RF90_PATH_A; eRFPath < priv->NumTotalRFPath; eRFPath++) {
119 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
122 pPhyReg = &priv->PHYRegDef[eRFPath];
124 /* Joseph test for shorten RF config
125 * pHalData->RfReg0Value[eRFPath] = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, rGlobalCtrl, bMaskDWord);
126 * ----Store original RFENV control type
131 u4RegValue = rtl8192_QueryBBReg(dev, pPhyReg->rfintfs, bRFSI_RFENV);
135 u4RegValue = rtl8192_QueryBBReg(dev, pPhyReg->rfintfs, bRFSI_RFENV<<16);
139 /*----Set RF_ENV enable----*/
140 rtl8192_setBBreg(dev, pPhyReg->rfintfe, bRFSI_RFENV<<16, 0x1);
142 /*----Set RF_ENV output high----*/
143 rtl8192_setBBreg(dev, pPhyReg->rfintfo, bRFSI_RFENV, 0x1);
145 /* Set bit number of Address and Data for RF register */
146 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireAddressLength, 0x0); /* Set 0 to 4 bits for Z-serial and set 1 to 6 bits for 8258 */
147 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireDataLength, 0x0); /* Set 0 to 12 bits for Z-serial and 8258, and set 1 to 14 bits for ??? */
149 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E) eRFPath, 0x0, bMask12Bits, 0xbf);
151 /* Check RF block (for FPGA platform only)----
152 * TODO: this function should be removed on ASIC , Emily 2007.2.2
154 if (rtl8192_phy_checkBBAndRF(dev, HW90_BLOCK_RF, (RF90_RADIO_PATH_E)eRFPath)) {
155 RT_TRACE(COMP_ERR, "PHY_RF8256_Config():Check Radio[%d] Fail!!\n", eRFPath);
156 goto phy_RF8256_Config_ParaFile_Fail;
159 RetryTimes = ConstRetryTimes;
161 /*----Initialize RF fom connfiguration file----*/
164 while (RF3_Final_Value != RegValueToBeCheck && RetryTimes != 0) {
165 ret = rtl8192_phy_ConfigRFWithHeaderFile(dev, (RF90_RADIO_PATH_E)eRFPath);
166 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, RegOffSetToBeCheck, bMask12Bits);
167 RT_TRACE(COMP_RF, "RF %d %d register final value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value);
172 while (RF3_Final_Value != RegValueToBeCheck && RetryTimes != 0) {
173 ret = rtl8192_phy_ConfigRFWithHeaderFile(dev, (RF90_RADIO_PATH_E)eRFPath);
174 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, RegOffSetToBeCheck, bMask12Bits);
175 RT_TRACE(COMP_RF, "RF %d %d register final value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value);
180 while (RF3_Final_Value != RegValueToBeCheck && RetryTimes != 0) {
181 ret = rtl8192_phy_ConfigRFWithHeaderFile(dev, (RF90_RADIO_PATH_E)eRFPath);
182 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, RegOffSetToBeCheck, bMask12Bits);
183 RT_TRACE(COMP_RF, "RF %d %d register final value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value);
188 while (RF3_Final_Value != RegValueToBeCheck && RetryTimes != 0) {
189 ret = rtl8192_phy_ConfigRFWithHeaderFile(dev, (RF90_RADIO_PATH_E)eRFPath);
190 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, RegOffSetToBeCheck, bMask12Bits);
191 RT_TRACE(COMP_RF, "RF %d %d register final value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value);
197 /*----Restore RFENV control type----*/
201 rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV, u4RegValue);
205 rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV<<16, u4RegValue);
210 RT_TRACE(COMP_ERR, "phy_RF8256_Config_ParaFile():Radio[%d] Fail!!", eRFPath);
211 goto phy_RF8256_Config_ParaFile_Fail;
216 RT_TRACE(COMP_PHY, "PHY Initialization Success\n");
219 phy_RF8256_Config_ParaFile_Fail:
220 RT_TRACE(COMP_ERR, "PHY Initialization failed\n");
224 void PHY_SetRF8256CCKTxPower(struct net_device *dev, u8 powerlevel)
227 struct r8192_priv *priv = ieee80211_priv(dev);
230 if (priv->bDynamicTxLowPower) {
231 if (priv->CustomerID == RT_CID_819x_Netcore)
234 TxAGC += priv->CckPwEnl;
239 rtl8192_setBBreg(dev, rTxAGC_CCK_Mcs32, bTxAGCRateCCK, TxAGC);
243 void PHY_SetRF8256OFDMTxPower(struct net_device *dev, u8 powerlevel)
245 struct r8192_priv *priv = ieee80211_priv(dev);
246 /* Joseph TxPower for 8192 testing */
247 u32 writeVal, powerBase0, powerBase1, writeVal_tmp;
249 u16 RegOffset[6] = {0xe00, 0xe04, 0xe10, 0xe14, 0xe18, 0xe1c};
250 u8 byte0, byte1, byte2, byte3;
252 powerBase0 = powerlevel + priv->TxPowerDiff; /* OFDM rates */
253 powerBase0 = (powerBase0<<24) | (powerBase0<<16) | (powerBase0<<8) | powerBase0;
254 powerBase1 = powerlevel; /* MCS rates */
255 powerBase1 = (powerBase1<<24) | (powerBase1<<16) | (powerBase1<<8) | powerBase1;
257 for (index = 0; index < 6; index++) {
258 writeVal = priv->MCSTxPowerLevelOriginalOffset[index] + ((index < 2)?powerBase0:powerBase1);
259 byte0 = (u8)(writeVal & 0x7f);
260 byte1 = (u8)((writeVal & 0x7f00)>>8);
261 byte2 = (u8)((writeVal & 0x7f0000)>>16);
262 byte3 = (u8)((writeVal & 0x7f000000)>>24);
265 /* Max power index = 0x24 */
274 /* for tx power track */
276 writeVal_tmp = (byte3<<24) | (byte2<<16) | (byte1<<8) | byte0;
277 priv->Pwr_Track = writeVal_tmp;
280 if (priv->bDynamicTxHighPower) {
281 /*Add by Jacken 2008/03/06
282 *Emily, 20080613. Set low tx power for both MCS and legacy OFDM
284 writeVal = 0x03030303;
286 writeVal = (byte3<<24) | (byte2<<16) | (byte1<<8) | byte0;
288 rtl8192_setBBreg(dev, RegOffset[index], 0x7f7f7f7f, writeVal);