1
2
3
4
5
6
7
8
9
10
11
12#include "r8192U.h"
13#include "r8192U_hw.h"
14#include "r819xU_phyreg.h"
15#include "r819xU_phy.h"
16#include "r8190_rtl8256.h"
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 for(eRFPath = 0; eRFPath <RF90_PATH_MAX; eRFPath++)
33 {
34 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
35 continue;
36
37 switch(Bandwidth)
38 {
39 case HT_CHANNEL_WIDTH_20:
40 if(priv->card_8192_version == VERSION_819xU_A || priv->card_8192_version == VERSION_819xU_B)
41 {
42 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x0b, bMask12Bits, 0x100);
43 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x2c, bMask12Bits, 0x3d7);
44 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x0e, bMask12Bits, 0x021);
45
46
47 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x14, bMask12Bits, 0x5ab);
48 }
49 else
50 {
51 RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown hardware version\n");
52 }
53
54 break;
55 case HT_CHANNEL_WIDTH_20_40:
56 if(priv->card_8192_version == VERSION_819xU_A ||priv->card_8192_version == VERSION_819xU_B)
57 {
58 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x0b, bMask12Bits, 0x300);
59 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x2c, bMask12Bits, 0x3df);
60 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x0e, bMask12Bits, 0x0a1);
61
62
63 if(priv->chan == 3 || priv->chan == 9)
64 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x14, bMask12Bits, 0x59b);
65 else
66 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x14, bMask12Bits, 0x5ab);
67 }
68 else
69 {
70 RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown hardware version\n");
71 }
72
73
74 break;
75 default:
76 RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown Bandwidth: %#X\n",Bandwidth );
77 break;
78
79 }
80 }
81 return;
82}
83
84
85
86
87
88
89void PHY_RF8256_Config(struct net_device* dev)
90{
91 struct r8192_priv *priv = ieee80211_priv(dev);
92
93
94
95 priv->NumTotalRFPath = RTL819X_TOTAL_RF_PATH;
96
97 phy_RF8256_Config_ParaFile(dev);
98
99 return;
100}
101
102
103
104
105
106
107void phy_RF8256_Config_ParaFile(struct net_device* dev)
108{
109 u32 u4RegValue = 0;
110
111
112
113
114 u8 eRFPath;
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;
121 u8 ret = 0;
122
123
124
125 for(eRFPath = (RF90_RADIO_PATH_E)RF90_PATH_A; eRFPath <priv->NumTotalRFPath; eRFPath++)
126 {
127 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
128 continue;
129
130 pPhyReg = &priv->PHYRegDef[eRFPath];
131
132
133
134
135
136 switch(eRFPath)
137 {
138 case RF90_PATH_A:
139 case RF90_PATH_C:
140 u4RegValue = rtl8192_QueryBBReg(dev, pPhyReg->rfintfs, bRFSI_RFENV);
141 break;
142 case RF90_PATH_B :
143 case RF90_PATH_D:
144 u4RegValue = rtl8192_QueryBBReg(dev, pPhyReg->rfintfs, bRFSI_RFENV<<16);
145 break;
146 }
147
148
149 rtl8192_setBBreg(dev, pPhyReg->rfintfe, bRFSI_RFENV<<16, 0x1);
150
151
152 rtl8192_setBBreg(dev, pPhyReg->rfintfo, bRFSI_RFENV, 0x1);
153
154
155 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireAddressLength, 0x0);
156 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireDataLength, 0x0);
157
158 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E) eRFPath, 0x0, bMask12Bits, 0xbf);
159
160
161
162 if (rtl8192_phy_checkBBAndRF(dev, HW90_BLOCK_RF, (RF90_RADIO_PATH_E)eRFPath))
163 {
164 RT_TRACE(COMP_ERR, "PHY_RF8256_Config():Check Radio[%d] Fail!!\n", eRFPath);
165 goto phy_RF8256_Config_ParaFile_Fail;
166 }
167
168 RetryTimes = ConstRetryTimes;
169 RF3_Final_Value = 0;
170
171 switch(eRFPath)
172 {
173 case RF90_PATH_A:
174 while(RF3_Final_Value!=RegValueToBeCheck && RetryTimes!=0)
175 {
176 ret = rtl8192_phy_ConfigRFWithHeaderFile(dev,(RF90_RADIO_PATH_E)eRFPath);
177 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, RegOffSetToBeCheck, bMask12Bits);
178 RT_TRACE(COMP_RF, "RF %d %d register final value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value);
179 RetryTimes--;
180 }
181 break;
182 case RF90_PATH_B:
183 while(RF3_Final_Value!=RegValueToBeCheck && RetryTimes!=0)
184 {
185 ret = rtl8192_phy_ConfigRFWithHeaderFile(dev,(RF90_RADIO_PATH_E)eRFPath);
186 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, RegOffSetToBeCheck, bMask12Bits);
187 RT_TRACE(COMP_RF, "RF %d %d register final value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value);
188 RetryTimes--;
189 }
190 break;
191 case RF90_PATH_C:
192 while(RF3_Final_Value!=RegValueToBeCheck && RetryTimes!=0)
193 {
194 ret = rtl8192_phy_ConfigRFWithHeaderFile(dev,(RF90_RADIO_PATH_E)eRFPath);
195 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, RegOffSetToBeCheck, bMask12Bits);
196 RT_TRACE(COMP_RF, "RF %d %d register final value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value);
197 RetryTimes--;
198 }
199 break;
200 case RF90_PATH_D:
201 while(RF3_Final_Value!=RegValueToBeCheck && RetryTimes!=0)
202 {
203 ret = rtl8192_phy_ConfigRFWithHeaderFile(dev,(RF90_RADIO_PATH_E)eRFPath);
204 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, RegOffSetToBeCheck, bMask12Bits);
205 RT_TRACE(COMP_RF, "RF %d %d register final value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value);
206 RetryTimes--;
207 }
208 break;
209 }
210
211 ;
212 switch(eRFPath)
213 {
214 case RF90_PATH_A:
215 case RF90_PATH_C:
216 rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV, u4RegValue);
217 break;
218 case RF90_PATH_B :
219 case RF90_PATH_D:
220 rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV<<16, u4RegValue);
221 break;
222 }
223
224 if(ret){
225 RT_TRACE(COMP_ERR, "phy_RF8256_Config_ParaFile():Radio[%d] Fail!!", eRFPath);
226 goto phy_RF8256_Config_ParaFile_Fail;
227 }
228
229 }
230
231 RT_TRACE(COMP_PHY, "PHY Initialization Success\n") ;
232 return ;
233
234phy_RF8256_Config_ParaFile_Fail:
235 RT_TRACE(COMP_ERR, "PHY Initialization failed\n") ;
236 return ;
237}
238
239
240void PHY_SetRF8256CCKTxPower(struct net_device* dev, u8 powerlevel)
241{
242 u32 TxAGC=0;
243 struct r8192_priv *priv = ieee80211_priv(dev);
244
245 TxAGC = powerlevel;
246
247 if(priv->bDynamicTxLowPower == TRUE )
248 {
249 if(priv->CustomerID == RT_CID_819x_Netcore)
250 TxAGC = 0x22;
251 else
252 TxAGC += priv->CckPwEnl;
253 }
254
255 if(TxAGC > 0x24)
256 TxAGC = 0x24;
257 rtl8192_setBBreg(dev, rTxAGC_CCK_Mcs32, bTxAGCRateCCK, TxAGC);
258}
259
260
261void PHY_SetRF8256OFDMTxPower(struct net_device* dev, u8 powerlevel)
262{
263 struct r8192_priv *priv = ieee80211_priv(dev);
264
265 u32 writeVal, powerBase0, powerBase1, writeVal_tmp;
266 u8 index = 0;
267 u16 RegOffset[6] = {0xe00, 0xe04, 0xe10, 0xe14, 0xe18, 0xe1c};
268 u8 byte0, byte1, byte2, byte3;
269
270 powerBase0 = powerlevel + priv->TxPowerDiff;
271 powerBase0 = (powerBase0<<24) | (powerBase0<<16) |(powerBase0<<8) |powerBase0;
272 powerBase1 = powerlevel;
273 powerBase1 = (powerBase1<<24) | (powerBase1<<16) |(powerBase1<<8) |powerBase1;
274
275 for(index=0; index<6; index++)
276 {
277 writeVal = priv->MCSTxPowerLevelOriginalOffset[index] + ((index<2)?powerBase0:powerBase1);
278 byte0 = (u8)(writeVal & 0x7f);
279 byte1 = (u8)((writeVal & 0x7f00)>>8);
280 byte2 = (u8)((writeVal & 0x7f0000)>>16);
281 byte3 = (u8)((writeVal & 0x7f000000)>>24);
282 if(byte0 > 0x24)
283 byte0 = 0x24;
284 if(byte1 > 0x24)
285 byte1 = 0x24;
286 if(byte2 > 0x24)
287 byte2 = 0x24;
288 if(byte3 > 0x24)
289 byte3 = 0x24;
290
291
292 if(index == 3)
293 {
294 writeVal_tmp = (byte3<<24) | (byte2<<16) |(byte1<<8) |byte0;
295 priv->Pwr_Track = writeVal_tmp;
296 }
297
298 if(priv->bDynamicTxHighPower == TRUE)
299 {
300
301 writeVal = 0x03030303;
302 }
303 else
304 {
305 writeVal = (byte3<<24) | (byte2<<16) |(byte1<<8) |byte0;
306 }
307 rtl8192_setBBreg(dev, RegOffset[index], 0x7f7f7f7f, writeVal);
308 }
309 return;
310
311}
312