1 // SPDX-License-Identifier: GPL-2.0
3 * This is part of the rtl8192 driver
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"
18 * Forward declaration of local functions
20 static void phy_rf8256_config_para_file(struct net_device *dev);
22 /*--------------------------------------------------------------------------
23 * Overview: set RF band width (20M or 40M)
24 * Input: struct net_device* dev
25 * WIRELESS_BANDWIDTH_E Bandwidth //20M or 40M
28 * Note: 8226 support both 20M and 40 MHz
29 *--------------------------------------------------------------------------
31 void phy_set_rf8256_bandwidth(struct net_device *dev, enum ht_channel_width Bandwidth)
34 struct r8192_priv *priv = ieee80211_priv(dev);
36 /* for(eRFPath = RF90_PATH_A; eRFPath <pHalData->NumTotalRFPath;
39 for (eRFPath = 0; eRFPath < RF90_PATH_MAX; eRFPath++) {
40 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
44 case HT_CHANNEL_WIDTH_20:
45 if (priv->card_8192_version == VERSION_819XU_A ||
46 priv->card_8192_version == VERSION_819XU_B) {
47 /* 8256 D-cut, E-cut, xiong: consider it later! */
48 rtl8192_phy_SetRFReg(dev,
49 (enum rf90_radio_path_e)eRFPath,
50 0x0b, bMask12Bits, 0x100); /* phy para:1ba */
51 rtl8192_phy_SetRFReg(dev,
52 (enum rf90_radio_path_e)eRFPath,
53 0x2c, bMask12Bits, 0x3d7);
54 rtl8192_phy_SetRFReg(dev,
55 (enum rf90_radio_path_e)eRFPath,
56 0x0e, bMask12Bits, 0x021);
57 rtl8192_phy_SetRFReg(dev,
58 (enum rf90_radio_path_e)eRFPath,
59 0x14, bMask12Bits, 0x5ab);
61 RT_TRACE(COMP_ERR, "%s(): unknown hardware version\n", __func__);
64 case HT_CHANNEL_WIDTH_20_40:
65 if (priv->card_8192_version == VERSION_819XU_A || priv->card_8192_version == VERSION_819XU_B) { /* 8256 D-cut, E-cut, xiong: consider it later! */
66 rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path_e)eRFPath, 0x0b, bMask12Bits, 0x300); /* phy para:3ba */
67 rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path_e)eRFPath, 0x2c, bMask12Bits, 0x3df);
68 rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path_e)eRFPath, 0x0e, bMask12Bits, 0x0a1);
70 if (priv->chan == 3 || priv->chan == 9)
71 /* I need to set priv->chan whenever current channel changes */
72 rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path_e)eRFPath, 0x14, bMask12Bits, 0x59b);
74 rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path_e)eRFPath, 0x14, bMask12Bits, 0x5ab);
76 RT_TRACE(COMP_ERR, "%s(): unknown hardware version\n", __func__);
80 RT_TRACE(COMP_ERR, "%s(): unknown Bandwidth: %#X\n", __func__, Bandwidth);
86 /*--------------------------------------------------------------------------
87 * Overview: Interface to config 8256
88 * Input: struct net_device* dev
91 *--------------------------------------------------------------------------
93 void phy_rf8256_config(struct net_device *dev)
95 struct r8192_priv *priv = ieee80211_priv(dev);
96 /* Initialize general global value
98 * TODO: Extend RF_PATH_C and RF_PATH_D in the future
100 priv->NumTotalRFPath = RTL819X_TOTAL_RF_PATH;
101 /* Config BB and RF */
102 phy_rf8256_config_para_file(dev);
105 /*--------------------------------------------------------------------------
106 * Overview: Interface to config 8256
107 * Input: struct net_device* dev
110 *--------------------------------------------------------------------------
112 static void phy_rf8256_config_para_file(struct net_device *dev)
116 BB_REGISTER_DEFINITION_T *pPhyReg;
117 struct r8192_priv *priv = ieee80211_priv(dev);
118 u32 RegOffSetToBeCheck = 0x3;
119 u32 RegValueToBeCheck = 0x7f1;
120 u32 RF3_Final_Value = 0;
121 u8 ConstRetryTimes = 5, RetryTimes = 5;
124 for (eRFPath = (enum rf90_radio_path_e)RF90_PATH_A; eRFPath < priv->NumTotalRFPath; eRFPath++) {
125 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
128 pPhyReg = &priv->PHYRegDef[eRFPath];
130 /* Joseph test for shorten RF config
131 * pHalData->RfReg0Value[eRFPath] = rtl8192_phy_QueryRFReg(dev, (enum rf90_radio_path_e)eRFPath, rGlobalCtrl, bMaskDWord);
132 * ----Store original RFENV control type
137 u4RegValue = rtl8192_QueryBBReg(dev, pPhyReg->rfintfs, bRFSI_RFENV);
141 u4RegValue = rtl8192_QueryBBReg(dev, pPhyReg->rfintfs, bRFSI_RFENV << 16);
145 /*----Set RF_ENV enable----*/
146 rtl8192_setBBreg(dev, pPhyReg->rfintfe, bRFSI_RFENV << 16, 0x1);
148 /*----Set RF_ENV output high----*/
149 rtl8192_setBBreg(dev, pPhyReg->rfintfo, bRFSI_RFENV, 0x1);
151 /* Set bit number of Address and Data for RF register */
152 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireAddressLength, 0x0); /* Set 0 to 4 bits for Z-serial and set 1 to 6 bits for 8258 */
153 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireDataLength, 0x0); /* Set 0 to 12 bits for Z-serial and 8258, and set 1 to 14 bits for ??? */
155 rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path_e)eRFPath, 0x0, bMask12Bits, 0xbf);
157 /* Check RF block (for FPGA platform only)----
158 * TODO: this function should be removed on ASIC , Emily 2007.2.2
160 if (rtl8192_phy_checkBBAndRF(dev, HW90_BLOCK_RF, (enum 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, (enum rf90_radio_path_e)eRFPath);
172 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (enum 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, (enum rf90_radio_path_e)eRFPath);
180 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (enum 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, (enum rf90_radio_path_e)eRFPath);
188 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (enum 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, (enum rf90_radio_path_e)eRFPath);
196 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (enum 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, "%s():Radio[%d] Fail!!", __func__, eRFPath);
217 goto phy_RF8256_Config_ParaFile_Fail;
221 RT_TRACE(COMP_PHY, "PHY Initialization Success\n");
224 phy_RF8256_Config_ParaFile_Fail:
225 RT_TRACE(COMP_ERR, "PHY Initialization failed\n");
228 void phy_set_rf8256_cck_tx_power(struct net_device *dev, u8 powerlevel)
231 struct r8192_priv *priv = ieee80211_priv(dev);
235 if (priv->bDynamicTxLowPower) {
236 if (priv->CustomerID == RT_CID_819x_Netcore)
239 TxAGC += priv->CckPwEnl;
244 rtl8192_setBBreg(dev, rTxAGC_CCK_Mcs32, bTxAGCRateCCK, TxAGC);
247 void phy_set_rf8256_ofdm_tx_power(struct net_device *dev, u8 powerlevel)
249 struct r8192_priv *priv = ieee80211_priv(dev);
250 /* Joseph TxPower for 8192 testing */
251 u32 writeVal, powerBase0, powerBase1, writeVal_tmp;
253 u16 RegOffset[6] = {0xe00, 0xe04, 0xe10, 0xe14, 0xe18, 0xe1c};
254 u8 byte0, byte1, byte2, byte3;
256 powerBase0 = powerlevel + priv->TxPowerDiff; /* OFDM rates */
257 powerBase0 = (powerBase0 << 24) | (powerBase0 << 16) | (powerBase0 << 8) | powerBase0;
258 powerBase1 = powerlevel; /* MCS rates */
259 powerBase1 = (powerBase1 << 24) | (powerBase1 << 16) | (powerBase1 << 8) | powerBase1;
261 for (index = 0; index < 6; index++) {
262 writeVal = priv->MCSTxPowerLevelOriginalOffset[index] + ((index < 2) ? powerBase0 : powerBase1);
263 byte0 = (u8)(writeVal & 0x7f);
264 byte1 = (u8)((writeVal & 0x7f00) >> 8);
265 byte2 = (u8)((writeVal & 0x7f0000) >> 16);
266 byte3 = (u8)((writeVal & 0x7f000000) >> 24);
269 /* Max power index = 0x24 */
278 /* for tx power track */
280 writeVal_tmp = (byte3 << 24) | (byte2 << 16) | (byte1 << 8) | byte0;
281 priv->Pwr_Track = writeVal_tmp;
284 if (priv->bDynamicTxHighPower) {
285 /*Add by Jacken 2008/03/06
286 *Emily, 20080613. Set low tx power for both MCS and legacy OFDM
288 writeVal = 0x03030303;
290 writeVal = (byte3 << 24) | (byte2 << 16) | (byte1 << 8) | byte0;
292 rtl8192_setBBreg(dev, RegOffset[index], 0x7f7f7f7f, writeVal);