1
2
3
4
5
6
7
8
9
10
11#include "r8192U.h"
12#include "r8192U_hw.h"
13#include "r819xU_phyreg.h"
14#include "r819xU_phy.h"
15#include "r8190_rtl8256.h"
16
17
18
19
20
21
22
23
24
25
26void PHY_SetRF8256Bandwidth(struct net_device *dev, HT_CHANNEL_WIDTH Bandwidth)
27{
28 u8 eRFPath;
29 struct r8192_priv *priv = ieee80211_priv(dev);
30
31
32
33
34 for (eRFPath = 0; eRFPath < RF90_PATH_MAX; eRFPath++) {
35 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
36 continue;
37
38 switch (Bandwidth) {
39 case HT_CHANNEL_WIDTH_20:
40 if (priv->card_8192_version == VERSION_819xU_A
41 || priv->card_8192_version
42 == VERSION_819xU_B) {
43 rtl8192_phy_SetRFReg(dev,
44 (RF90_RADIO_PATH_E)eRFPath,
45 0x0b, bMask12Bits, 0x100);
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);
55 } else {
56 RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown hardware version\n");
57 }
58 break;
59 case HT_CHANNEL_WIDTH_20_40:
60 if (priv->card_8192_version == VERSION_819xU_A || priv->card_8192_version == VERSION_819xU_B) {
61 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x0b, bMask12Bits, 0x300);
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);
64
65 if (priv->chan == 3 || priv->chan == 9)
66
67 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x14, bMask12Bits, 0x59b);
68 else
69 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x14, bMask12Bits, 0x5ab);
70 } else {
71 RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown hardware version\n");
72 }
73 break;
74 default:
75 RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown Bandwidth: %#X\n", Bandwidth);
76 break;
77
78 }
79 }
80}
81
82
83
84
85
86
87
88void PHY_RF8256_Config(struct net_device *dev)
89{
90 struct r8192_priv *priv = ieee80211_priv(dev);
91
92
93
94
95 priv->NumTotalRFPath = RTL819X_TOTAL_RF_PATH;
96
97 phy_RF8256_Config_ParaFile(dev);
98}
99
100
101
102
103
104
105
106void phy_RF8256_Config_ParaFile(struct net_device *dev)
107{
108 u32 u4RegValue = 0;
109 u8 eRFPath;
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;
116 u8 ret = 0;
117
118 for (eRFPath = (RF90_RADIO_PATH_E)RF90_PATH_A; eRFPath < priv->NumTotalRFPath; eRFPath++) {
119 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
120 continue;
121
122 pPhyReg = &priv->PHYRegDef[eRFPath];
123
124
125
126
127
128 switch (eRFPath) {
129 case RF90_PATH_A:
130 case RF90_PATH_C:
131 u4RegValue = rtl8192_QueryBBReg(dev, pPhyReg->rfintfs, bRFSI_RFENV);
132 break;
133 case RF90_PATH_B:
134 case RF90_PATH_D:
135 u4RegValue = rtl8192_QueryBBReg(dev, pPhyReg->rfintfs, bRFSI_RFENV<<16);
136 break;
137 }
138
139
140 rtl8192_setBBreg(dev, pPhyReg->rfintfe, bRFSI_RFENV<<16, 0x1);
141
142
143 rtl8192_setBBreg(dev, pPhyReg->rfintfo, bRFSI_RFENV, 0x1);
144
145
146 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireAddressLength, 0x0);
147 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireDataLength, 0x0);
148
149 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E) eRFPath, 0x0, bMask12Bits, 0xbf);
150
151
152
153
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;
157 }
158
159 RetryTimes = ConstRetryTimes;
160 RF3_Final_Value = 0;
161
162 switch (eRFPath) {
163 case RF90_PATH_A:
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);
168 RetryTimes--;
169 }
170 break;
171 case RF90_PATH_B:
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);
176 RetryTimes--;
177 }
178 break;
179 case RF90_PATH_C:
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);
184 RetryTimes--;
185 }
186 break;
187 case RF90_PATH_D:
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);
192 RetryTimes--;
193 }
194 break;
195 }
196
197
198 switch (eRFPath) {
199 case RF90_PATH_A:
200 case RF90_PATH_C:
201 rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV, u4RegValue);
202 break;
203 case RF90_PATH_B:
204 case RF90_PATH_D:
205 rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV<<16, u4RegValue);
206 break;
207 }
208
209 if (ret) {
210 RT_TRACE(COMP_ERR, "phy_RF8256_Config_ParaFile():Radio[%d] Fail!!", eRFPath);
211 goto phy_RF8256_Config_ParaFile_Fail;
212 }
213
214 }
215
216 RT_TRACE(COMP_PHY, "PHY Initialization Success\n");
217 return;
218
219phy_RF8256_Config_ParaFile_Fail:
220 RT_TRACE(COMP_ERR, "PHY Initialization failed\n");
221}
222
223
224void PHY_SetRF8256CCKTxPower(struct net_device *dev, u8 powerlevel)
225{
226 u32 TxAGC = 0;
227 struct r8192_priv *priv = ieee80211_priv(dev);
228 TxAGC = powerlevel;
229
230 if (priv->bDynamicTxLowPower) {
231 if (priv->CustomerID == RT_CID_819x_Netcore)
232 TxAGC = 0x22;
233 else
234 TxAGC += priv->CckPwEnl;
235 }
236
237 if (TxAGC > 0x24)
238 TxAGC = 0x24;
239 rtl8192_setBBreg(dev, rTxAGC_CCK_Mcs32, bTxAGCRateCCK, TxAGC);
240}
241
242
243void PHY_SetRF8256OFDMTxPower(struct net_device *dev, u8 powerlevel)
244{
245 struct r8192_priv *priv = ieee80211_priv(dev);
246
247 u32 writeVal, powerBase0, powerBase1, writeVal_tmp;
248 u8 index = 0;
249 u16 RegOffset[6] = {0xe00, 0xe04, 0xe10, 0xe14, 0xe18, 0xe1c};
250 u8 byte0, byte1, byte2, byte3;
251
252 powerBase0 = powerlevel + priv->TxPowerDiff;
253 powerBase0 = (powerBase0<<24) | (powerBase0<<16) | (powerBase0<<8) | powerBase0;
254 powerBase1 = powerlevel;
255 powerBase1 = (powerBase1<<24) | (powerBase1<<16) | (powerBase1<<8) | powerBase1;
256
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);
263
264 if (byte0 > 0x24)
265
266 byte0 = 0x24;
267 if (byte1 > 0x24)
268 byte1 = 0x24;
269 if (byte2 > 0x24)
270 byte2 = 0x24;
271 if (byte3 > 0x24)
272 byte3 = 0x24;
273
274
275 if (index == 3) {
276 writeVal_tmp = (byte3<<24) | (byte2<<16) | (byte1<<8) | byte0;
277 priv->Pwr_Track = writeVal_tmp;
278 }
279
280 if (priv->bDynamicTxHighPower) {
281
282
283
284 writeVal = 0x03030303;
285 } else {
286 writeVal = (byte3<<24) | (byte2<<16) | (byte1<<8) | byte0;
287 }
288 rtl8192_setBBreg(dev, RegOffset[index], 0x7f7f7f7f, writeVal);
289 }
290 return;
291
292}
293