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);
51 "PHY_SetRF8256Bandwidth(): 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);
70 "PHY_SetRF8256Bandwidth(): unknown hardware version\n");
77 "PHY_SetRF8256Bandwidth(): unknown Bandwidth: %#X\n",
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 return phy_RF8256_Config_ParaFile(dev);
93 bool phy_RF8256_Config_ParaFile(struct net_device *dev)
98 struct bb_reg_definition *pPhyReg;
99 struct r8192_priv *priv = rtllib_priv(dev);
100 u32 RegOffSetToBeCheck = 0x3;
101 u32 RegValueToBeCheck = 0x7f1;
102 u32 RF3_Final_Value = 0;
103 u8 ConstRetryTimes = 5, RetryTimes = 5;
106 for (eRFPath = (enum rf90_radio_path)RF90_PATH_A;
107 eRFPath < priv->NumTotalRFPath; eRFPath++) {
108 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
111 pPhyReg = &priv->PHYRegDef[eRFPath];
117 u4RegValue = rtl8192_QueryBBReg(dev, pPhyReg->rfintfs,
122 u4RegValue = rtl8192_QueryBBReg(dev, pPhyReg->rfintfs,
127 rtl8192_setBBreg(dev, pPhyReg->rfintfe, bRFSI_RFENV<<16, 0x1);
129 rtl8192_setBBreg(dev, pPhyReg->rfintfo, bRFSI_RFENV, 0x1);
131 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2,
132 b3WireAddressLength, 0x0);
133 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2,
134 b3WireDataLength, 0x0);
136 rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path) eRFPath, 0x0,
139 rtStatus = rtl8192_phy_checkBBAndRF(dev, HW90_BLOCK_RF,
140 (enum rf90_radio_path)eRFPath);
143 "PHY_RF8256_Config():Check Radio[%d] Fail!!\n",
145 goto phy_RF8256_Config_ParaFile_Fail;
148 RetryTimes = ConstRetryTimes;
152 while (RF3_Final_Value != RegValueToBeCheck &&
154 ret = rtl8192_phy_ConfigRFWithHeaderFile(dev,
155 (enum rf90_radio_path)eRFPath);
156 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev,
157 (enum rf90_radio_path)eRFPath,
161 "RF %d %d register final value: %x\n",
162 eRFPath, RegOffSetToBeCheck,
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,
177 "RF %d %d register final value: %x\n",
178 eRFPath, RegOffSetToBeCheck,
184 while (RF3_Final_Value != RegValueToBeCheck &&
186 ret = rtl8192_phy_ConfigRFWithHeaderFile(dev,
187 (enum rf90_radio_path)eRFPath);
188 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev,
189 (enum rf90_radio_path)eRFPath,
193 "RF %d %d register final value: %x\n",
194 eRFPath, RegOffSetToBeCheck,
200 while (RF3_Final_Value != RegValueToBeCheck &&
202 ret = rtl8192_phy_ConfigRFWithHeaderFile(dev,
203 (enum rf90_radio_path)eRFPath);
204 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev,
205 (enum rf90_radio_path)eRFPath,
206 RegOffSetToBeCheck, bMask12Bits);
208 "RF %d %d register final value: %x\n",
209 eRFPath, RegOffSetToBeCheck,
219 rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV,
224 rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV<<16,
231 "phy_RF8256_Config_ParaFile():Radio[%d] Fail!!",
233 goto phy_RF8256_Config_ParaFile_Fail;
238 RT_TRACE(COMP_PHY, "PHY Initialization Success\n");
241 phy_RF8256_Config_ParaFile_Fail:
242 RT_TRACE(COMP_ERR, "PHY Initialization failed\n");
246 void PHY_SetRF8256CCKTxPower(struct net_device *dev, u8 powerlevel)
249 struct r8192_priv *priv = rtllib_priv(dev);
252 if (priv->bDynamicTxLowPower) {
253 if (priv->CustomerID == RT_CID_819x_Netcore)
256 TxAGC += priv->CckPwEnl;
260 rtl8192_setBBreg(dev, rTxAGC_CCK_Mcs32, bTxAGCRateCCK, TxAGC);
264 void PHY_SetRF8256OFDMTxPower(struct net_device *dev, u8 powerlevel)
266 struct r8192_priv *priv = rtllib_priv(dev);
267 u32 writeVal, powerBase0, powerBase1, writeVal_tmp;
269 u16 RegOffset[6] = {0xe00, 0xe04, 0xe10, 0xe14, 0xe18, 0xe1c};
270 u8 byte0, byte1, byte2, byte3;
272 powerBase0 = powerlevel + priv->LegacyHTTxPowerDiff;
273 powerBase0 = (powerBase0 << 24) | (powerBase0 << 16) |
274 (powerBase0 << 8) | powerBase0;
275 powerBase1 = powerlevel;
276 powerBase1 = (powerBase1 << 24) | (powerBase1 << 16) |
277 (powerBase1 << 8) | powerBase1;
279 for (index = 0; index < 6; index++) {
280 writeVal = (u32)(priv->MCSTxPowerLevelOriginalOffset[index] +
281 ((index < 2) ? powerBase0 : powerBase1));
282 byte0 = (u8)(writeVal & 0x7f);
283 byte1 = (u8)((writeVal & 0x7f00)>>8);
284 byte2 = (u8)((writeVal & 0x7f0000)>>16);
285 byte3 = (u8)((writeVal & 0x7f000000)>>24);
296 writeVal_tmp = (byte3 << 24) | (byte2 << 16) |
297 (byte1 << 8) | byte0;
298 priv->Pwr_Track = writeVal_tmp;
301 if (priv->bDynamicTxHighPower)
302 writeVal = 0x03030303;
304 writeVal = (byte3 << 24) | (byte2 << 16) |
305 (byte1 << 8) | byte0;
306 rtl8192_setBBreg(dev, RegOffset[index], 0x7f7f7f7f, writeVal);