1#include "r8192U.h"
2#include "r8192U_hw.h"
3#include "r819xU_phy.h"
4#include "r819xU_phyreg.h"
5#include "r8190_rtl8256.h"
6#include "r8192U_dm.h"
7#include "r819xU_firmware_img.h"
8
9#include "dot11d.h"
10#include <linux/bitops.h>
11
12static u32 RF_CHANNEL_TABLE_ZEBRA[] = {
13 0,
14 0x085c,
15 0x08dc,
16 0x095c,
17 0x09dc,
18 0x0a5c,
19 0x0adc,
20 0x0b5c,
21 0x0bdc,
22 0x0c5c,
23 0x0cdc,
24 0x0d5c,
25 0x0ddc,
26 0x0e5c,
27 0x0f72,
28};
29
30
31#define rtl819XPHY_REG_1T2RArray Rtl8192UsbPHY_REG_1T2RArray
32#define rtl819XMACPHY_Array_PG Rtl8192UsbMACPHY_Array_PG
33#define rtl819XMACPHY_Array Rtl8192UsbMACPHY_Array
34#define rtl819XRadioA_Array Rtl8192UsbRadioA_Array
35#define rtl819XRadioB_Array Rtl8192UsbRadioB_Array
36#define rtl819XRadioC_Array Rtl8192UsbRadioC_Array
37#define rtl819XRadioD_Array Rtl8192UsbRadioD_Array
38#define rtl819XAGCTAB_Array Rtl8192UsbAGCTAB_Array
39
40
41
42
43
44
45
46
47u32 rtl8192_CalculateBitShift(u32 bitmask)
48{
49 u32 i;
50
51 i = ffs(bitmask) - 1;
52 return i;
53}
54
55
56
57
58
59
60
61
62
63u8 rtl8192_phy_CheckIsLegalRFPath(struct net_device *dev, u32 eRFPath)
64{
65 u8 ret = 1;
66 struct r8192_priv *priv = ieee80211_priv(dev);
67
68 if (priv->rf_type == RF_2T4R) {
69 ret = 0;
70 } else if (priv->rf_type == RF_1T2R) {
71 if (eRFPath == RF90_PATH_A || eRFPath == RF90_PATH_B)
72 ret = 1;
73 else if (eRFPath == RF90_PATH_C || eRFPath == RF90_PATH_D)
74 ret = 0;
75 }
76 return ret;
77}
78
79
80
81
82
83
84
85
86
87
88
89void rtl8192_setBBreg(struct net_device *dev, u32 reg_addr, u32 bitmask,
90 u32 data)
91{
92
93 u32 reg, bitshift;
94
95 if (bitmask != bMaskDWord) {
96 read_nic_dword(dev, reg_addr, ®);
97 bitshift = rtl8192_CalculateBitShift(bitmask);
98 reg &= ~bitmask;
99 reg |= data << bitshift;
100 write_nic_dword(dev, reg_addr, reg);
101 } else {
102 write_nic_dword(dev, reg_addr, data);
103 }
104 return;
105}
106
107
108
109
110
111
112
113
114
115
116u32 rtl8192_QueryBBReg(struct net_device *dev, u32 reg_addr, u32 bitmask)
117{
118 u32 reg, bitshift;
119
120 read_nic_dword(dev, reg_addr, ®);
121 bitshift = rtl8192_CalculateBitShift(bitmask);
122
123 return (reg & bitmask) >> bitshift;
124}
125
126static u32 phy_FwRFSerialRead(struct net_device *dev, RF90_RADIO_PATH_E eRFPath,
127 u32 offset);
128
129static void phy_FwRFSerialWrite(struct net_device *dev,
130 RF90_RADIO_PATH_E eRFPath, u32 offset,
131 u32 data);
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147u32 rtl8192_phy_RFSerialRead(struct net_device *dev, RF90_RADIO_PATH_E eRFPath,
148 u32 offset)
149{
150 struct r8192_priv *priv = ieee80211_priv(dev);
151 u32 ret = 0;
152 u32 new_offset = 0;
153 BB_REGISTER_DEFINITION_T *pPhyReg = &priv->PHYRegDef[eRFPath];
154
155 rtl8192_setBBreg(dev, pPhyReg->rfLSSIReadBack, bLSSIReadBackData, 0);
156
157 offset &= 0x3f;
158
159
160 if (priv->rf_chip == RF_8256) {
161 if (offset >= 31) {
162 priv->RfReg0Value[eRFPath] |= 0x140;
163
164 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset,
165 bMaskDWord,
166 priv->RfReg0Value[eRFPath]<<16);
167
168 new_offset = offset - 30;
169 } else if (offset >= 16) {
170 priv->RfReg0Value[eRFPath] |= 0x100;
171 priv->RfReg0Value[eRFPath] &= (~0x40);
172
173 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset,
174 bMaskDWord,
175 priv->RfReg0Value[eRFPath]<<16);
176
177 new_offset = offset - 15;
178 } else {
179 new_offset = offset;
180 }
181 } else {
182 RT_TRACE((COMP_PHY|COMP_ERR),
183 "check RF type here, need to be 8256\n");
184 new_offset = offset;
185 }
186
187 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadAddress,
188 new_offset);
189
190 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadEdge, 0x0);
191 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadEdge, 0x1);
192
193
194
195 usleep_range(1000, 1000);
196
197 ret = rtl8192_QueryBBReg(dev, pPhyReg->rfLSSIReadBack,
198 bLSSIReadBackData);
199
200
201
202 if (priv->rf_chip == RF_8256) {
203 priv->RfReg0Value[eRFPath] &= 0xebf;
204
205 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, bMaskDWord,
206 priv->RfReg0Value[eRFPath] << 16);
207 }
208
209 return ret;
210}
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232void rtl8192_phy_RFSerialWrite(struct net_device *dev,
233 RF90_RADIO_PATH_E eRFPath, u32 offset, u32 data)
234{
235 struct r8192_priv *priv = ieee80211_priv(dev);
236 u32 DataAndAddr = 0, new_offset = 0;
237 BB_REGISTER_DEFINITION_T *pPhyReg = &priv->PHYRegDef[eRFPath];
238
239 offset &= 0x3f;
240 if (priv->rf_chip == RF_8256) {
241
242 if (offset >= 31) {
243 priv->RfReg0Value[eRFPath] |= 0x140;
244 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset,
245 bMaskDWord,
246 priv->RfReg0Value[eRFPath] << 16);
247 new_offset = offset - 30;
248 } else if (offset >= 16) {
249 priv->RfReg0Value[eRFPath] |= 0x100;
250 priv->RfReg0Value[eRFPath] &= (~0x40);
251 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset,
252 bMaskDWord,
253 priv->RfReg0Value[eRFPath]<<16);
254 new_offset = offset - 15;
255 } else {
256 new_offset = offset;
257 }
258 } else {
259 RT_TRACE((COMP_PHY|COMP_ERR),
260 "check RF type here, need to be 8256\n");
261 new_offset = offset;
262 }
263
264
265 DataAndAddr = (data<<16) | (new_offset&0x3f);
266
267
268 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, bMaskDWord, DataAndAddr);
269
270
271 if (offset == 0x0)
272 priv->RfReg0Value[eRFPath] = data;
273
274
275 if (priv->rf_chip == RF_8256) {
276 if (offset != 0) {
277 priv->RfReg0Value[eRFPath] &= 0xebf;
278 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset,
279 bMaskDWord,
280 priv->RfReg0Value[eRFPath] << 16);
281 }
282 }
283 return;
284}
285
286
287
288
289
290
291
292
293
294
295
296
297void rtl8192_phy_SetRFReg(struct net_device *dev, RF90_RADIO_PATH_E eRFPath,
298 u32 reg_addr, u32 bitmask, u32 data)
299{
300 struct r8192_priv *priv = ieee80211_priv(dev);
301 u32 reg, bitshift;
302
303 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
304 return;
305
306 if (priv->Rf_Mode == RF_OP_By_FW) {
307 if (bitmask != bMask12Bits) {
308
309 reg = phy_FwRFSerialRead(dev, eRFPath, reg_addr);
310 bitshift = rtl8192_CalculateBitShift(bitmask);
311 reg &= ~bitmask;
312 reg |= data << bitshift;
313
314 phy_FwRFSerialWrite(dev, eRFPath, reg_addr, reg);
315 } else {
316 phy_FwRFSerialWrite(dev, eRFPath, reg_addr, data);
317 }
318
319 udelay(200);
320
321 } else {
322 if (bitmask != bMask12Bits) {
323
324 reg = rtl8192_phy_RFSerialRead(dev, eRFPath, reg_addr);
325 bitshift = rtl8192_CalculateBitShift(bitmask);
326 reg &= ~bitmask;
327 reg |= data << bitshift;
328
329 rtl8192_phy_RFSerialWrite(dev, eRFPath, reg_addr, reg);
330 } else {
331 rtl8192_phy_RFSerialWrite(dev, eRFPath, reg_addr, data);
332 }
333 }
334 return;
335}
336
337
338
339
340
341
342
343
344
345
346u32 rtl8192_phy_QueryRFReg(struct net_device *dev, RF90_RADIO_PATH_E eRFPath,
347 u32 reg_addr, u32 bitmask)
348{
349 u32 reg, bitshift;
350 struct r8192_priv *priv = ieee80211_priv(dev);
351
352
353 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
354 return 0;
355 if (priv->Rf_Mode == RF_OP_By_FW) {
356 reg = phy_FwRFSerialRead(dev, eRFPath, reg_addr);
357 bitshift = rtl8192_CalculateBitShift(bitmask);
358 reg = (reg & bitmask) >> bitshift;
359 udelay(200);
360 return reg;
361 } else {
362 reg = rtl8192_phy_RFSerialRead(dev, eRFPath, reg_addr);
363 bitshift = rtl8192_CalculateBitShift(bitmask);
364 reg = (reg & bitmask) >> bitshift;
365 return reg;
366 }
367}
368
369
370
371
372
373
374
375
376
377
378static u32 phy_FwRFSerialRead(struct net_device *dev, RF90_RADIO_PATH_E eRFPath,
379 u32 offset)
380{
381 u32 reg = 0;
382 u32 data = 0;
383 u8 time = 0;
384 u32 tmp;
385
386
387
388
389
390
391
392 data |= ((offset&0xFF)<<12);
393
394 data |= ((eRFPath&0x3)<<20);
395
396
397 data |= 0x80000000;
398
399 read_nic_dword(dev, QPNR, &tmp);
400 while (tmp & 0x80000000) {
401
402
403 if (time++ < 100) {
404 udelay(10);
405 read_nic_dword(dev, QPNR, &tmp);
406 } else {
407 break;
408 }
409 }
410
411 write_nic_dword(dev, QPNR, data);
412
413 read_nic_dword(dev, QPNR, &tmp);
414 while (tmp & 0x80000000) {
415
416
417 if (time++ < 100) {
418 udelay(10);
419 read_nic_dword(dev, QPNR, &tmp);
420 } else {
421 return 0;
422 }
423 }
424 read_nic_dword(dev, RF_DATA, ®);
425
426 return reg;
427}
428
429
430
431
432
433
434
435
436
437
438
439static void phy_FwRFSerialWrite(struct net_device *dev,
440 RF90_RADIO_PATH_E eRFPath, u32 offset, u32 data)
441{
442 u8 time = 0;
443 u32 tmp;
444
445
446
447
448
449
450
451
452 data |= ((offset&0xFF)<<12);
453
454 data |= ((eRFPath&0x3)<<20);
455
456 data |= 0x400000;
457
458 data |= 0x80000000;
459
460
461 read_nic_dword(dev, QPNR, &tmp);
462 while (tmp & 0x80000000) {
463
464
465 if (time++ < 100) {
466 udelay(10);
467 read_nic_dword(dev, QPNR, &tmp);
468 } else {
469 break;
470 }
471 }
472
473
474 write_nic_dword(dev, QPNR, data);
475
476
477
478}
479
480
481
482
483
484
485
486
487
488
489void rtl8192_phy_configmac(struct net_device *dev)
490{
491 u32 dwArrayLen = 0, i;
492 u32 *pdwArray = NULL;
493 struct r8192_priv *priv = ieee80211_priv(dev);
494
495 if (priv->btxpowerdata_readfromEEPORM) {
496 RT_TRACE(COMP_PHY, "Rtl819XMACPHY_Array_PG\n");
497 dwArrayLen = MACPHY_Array_PGLength;
498 pdwArray = rtl819XMACPHY_Array_PG;
499
500 } else {
501 RT_TRACE(COMP_PHY, "Rtl819XMACPHY_Array\n");
502 dwArrayLen = MACPHY_ArrayLength;
503 pdwArray = rtl819XMACPHY_Array;
504 }
505 for (i = 0; i < dwArrayLen; i = i+3) {
506 if (pdwArray[i] == 0x318) {
507 pdwArray[i+2] = 0x00000800;
508 }
509
510 RT_TRACE(COMP_DBG,
511 "Rtl8190MACPHY_Array[0]=%x Rtl8190MACPHY_Array[1]=%x Rtl8190MACPHY_Array[2]=%x\n",
512 pdwArray[i], pdwArray[i+1], pdwArray[i+2]);
513 rtl8192_setBBreg(dev, pdwArray[i], pdwArray[i+1],
514 pdwArray[i+2]);
515 }
516 return;
517}
518
519
520
521
522
523
524
525
526
527
528void rtl8192_phyConfigBB(struct net_device *dev, u8 ConfigType)
529{
530 u32 i;
531
532#ifdef TO_DO_LIST
533 u32 *rtl8192PhyRegArrayTable = NULL, *rtl8192AgcTabArrayTable = NULL;
534
535 if (Adapter->bInHctTest) {
536 PHY_REGArrayLen = PHY_REGArrayLengthDTM;
537 AGCTAB_ArrayLen = AGCTAB_ArrayLengthDTM;
538 Rtl8190PHY_REGArray_Table = Rtl819XPHY_REGArrayDTM;
539 Rtl8190AGCTAB_Array_Table = Rtl819XAGCTAB_ArrayDTM;
540 }
541#endif
542 if (ConfigType == BaseBand_Config_PHY_REG) {
543 for (i = 0; i < PHY_REG_1T2RArrayLength; i += 2) {
544 rtl8192_setBBreg(dev, rtl819XPHY_REG_1T2RArray[i],
545 bMaskDWord,
546 rtl819XPHY_REG_1T2RArray[i+1]);
547 RT_TRACE(COMP_DBG,
548 "i: %x, Rtl819xUsbPHY_REGArray[0]=%x Rtl819xUsbPHY_REGArray[1]=%x\n",
549 i, rtl819XPHY_REG_1T2RArray[i],
550 rtl819XPHY_REG_1T2RArray[i+1]);
551 }
552 } else if (ConfigType == BaseBand_Config_AGC_TAB) {
553 for (i = 0; i < AGCTAB_ArrayLength; i += 2) {
554 rtl8192_setBBreg(dev, rtl819XAGCTAB_Array[i],
555 bMaskDWord, rtl819XAGCTAB_Array[i+1]);
556 RT_TRACE(COMP_DBG,
557 "i: %x, rtl819XAGCTAB_Array[0]=%x rtl819XAGCTAB_Array[1]=%x\n",
558 i, rtl819XAGCTAB_Array[i],
559 rtl819XAGCTAB_Array[i+1]);
560 }
561 }
562 return;
563}
564
565
566
567
568
569
570
571
572
573
574void rtl8192_InitBBRFRegDef(struct net_device *dev)
575{
576 struct r8192_priv *priv = ieee80211_priv(dev);
577
578
579
580 priv->PHYRegDef[RF90_PATH_A].rfintfs = rFPGA0_XAB_RFInterfaceSW;
581
582 priv->PHYRegDef[RF90_PATH_B].rfintfs = rFPGA0_XAB_RFInterfaceSW;
583
584 priv->PHYRegDef[RF90_PATH_C].rfintfs = rFPGA0_XCD_RFInterfaceSW;
585
586 priv->PHYRegDef[RF90_PATH_D].rfintfs = rFPGA0_XCD_RFInterfaceSW;
587
588
589
590 priv->PHYRegDef[RF90_PATH_A].rfintfi = rFPGA0_XAB_RFInterfaceRB;
591
592 priv->PHYRegDef[RF90_PATH_B].rfintfi = rFPGA0_XAB_RFInterfaceRB;
593
594 priv->PHYRegDef[RF90_PATH_C].rfintfi = rFPGA0_XCD_RFInterfaceRB;
595
596 priv->PHYRegDef[RF90_PATH_D].rfintfi = rFPGA0_XCD_RFInterfaceRB;
597
598
599
600 priv->PHYRegDef[RF90_PATH_A].rfintfo = rFPGA0_XA_RFInterfaceOE;
601
602 priv->PHYRegDef[RF90_PATH_B].rfintfo = rFPGA0_XB_RFInterfaceOE;
603
604 priv->PHYRegDef[RF90_PATH_C].rfintfo = rFPGA0_XC_RFInterfaceOE;
605
606 priv->PHYRegDef[RF90_PATH_D].rfintfo = rFPGA0_XD_RFInterfaceOE;
607
608
609
610 priv->PHYRegDef[RF90_PATH_A].rfintfe = rFPGA0_XA_RFInterfaceOE;
611
612 priv->PHYRegDef[RF90_PATH_B].rfintfe = rFPGA0_XB_RFInterfaceOE;
613
614 priv->PHYRegDef[RF90_PATH_C].rfintfe = rFPGA0_XC_RFInterfaceOE;
615
616 priv->PHYRegDef[RF90_PATH_D].rfintfe = rFPGA0_XD_RFInterfaceOE;
617
618
619 priv->PHYRegDef[RF90_PATH_A].rf3wireOffset = rFPGA0_XA_LSSIParameter;
620 priv->PHYRegDef[RF90_PATH_B].rf3wireOffset = rFPGA0_XB_LSSIParameter;
621 priv->PHYRegDef[RF90_PATH_C].rf3wireOffset = rFPGA0_XC_LSSIParameter;
622 priv->PHYRegDef[RF90_PATH_D].rf3wireOffset = rFPGA0_XD_LSSIParameter;
623
624
625
626 priv->PHYRegDef[RF90_PATH_A].rfLSSI_Select = rFPGA0_XAB_RFParameter;
627 priv->PHYRegDef[RF90_PATH_B].rfLSSI_Select = rFPGA0_XAB_RFParameter;
628 priv->PHYRegDef[RF90_PATH_C].rfLSSI_Select = rFPGA0_XCD_RFParameter;
629 priv->PHYRegDef[RF90_PATH_D].rfLSSI_Select = rFPGA0_XCD_RFParameter;
630
631
632 priv->PHYRegDef[RF90_PATH_A].rfTxGainStage = rFPGA0_TxGainStage;
633 priv->PHYRegDef[RF90_PATH_B].rfTxGainStage = rFPGA0_TxGainStage;
634 priv->PHYRegDef[RF90_PATH_C].rfTxGainStage = rFPGA0_TxGainStage;
635 priv->PHYRegDef[RF90_PATH_D].rfTxGainStage = rFPGA0_TxGainStage;
636
637
638
639 priv->PHYRegDef[RF90_PATH_A].rfHSSIPara1 = rFPGA0_XA_HSSIParameter1;
640 priv->PHYRegDef[RF90_PATH_B].rfHSSIPara1 = rFPGA0_XB_HSSIParameter1;
641 priv->PHYRegDef[RF90_PATH_C].rfHSSIPara1 = rFPGA0_XC_HSSIParameter1;
642 priv->PHYRegDef[RF90_PATH_D].rfHSSIPara1 = rFPGA0_XD_HSSIParameter1;
643
644
645
646 priv->PHYRegDef[RF90_PATH_A].rfHSSIPara2 = rFPGA0_XA_HSSIParameter2;
647 priv->PHYRegDef[RF90_PATH_B].rfHSSIPara2 = rFPGA0_XB_HSSIParameter2;
648 priv->PHYRegDef[RF90_PATH_C].rfHSSIPara2 = rFPGA0_XC_HSSIParameter2;
649 priv->PHYRegDef[RF90_PATH_D].rfHSSIPara2 = rFPGA0_XD_HSSIParameter2;
650
651
652
653 priv->PHYRegDef[RF90_PATH_A].rfSwitchControl = rFPGA0_XAB_SwitchControl;
654 priv->PHYRegDef[RF90_PATH_B].rfSwitchControl = rFPGA0_XAB_SwitchControl;
655 priv->PHYRegDef[RF90_PATH_C].rfSwitchControl = rFPGA0_XCD_SwitchControl;
656 priv->PHYRegDef[RF90_PATH_D].rfSwitchControl = rFPGA0_XCD_SwitchControl;
657
658
659 priv->PHYRegDef[RF90_PATH_A].rfAGCControl1 = rOFDM0_XAAGCCore1;
660 priv->PHYRegDef[RF90_PATH_B].rfAGCControl1 = rOFDM0_XBAGCCore1;
661 priv->PHYRegDef[RF90_PATH_C].rfAGCControl1 = rOFDM0_XCAGCCore1;
662 priv->PHYRegDef[RF90_PATH_D].rfAGCControl1 = rOFDM0_XDAGCCore1;
663
664
665 priv->PHYRegDef[RF90_PATH_A].rfAGCControl2 = rOFDM0_XAAGCCore2;
666 priv->PHYRegDef[RF90_PATH_B].rfAGCControl2 = rOFDM0_XBAGCCore2;
667 priv->PHYRegDef[RF90_PATH_C].rfAGCControl2 = rOFDM0_XCAGCCore2;
668 priv->PHYRegDef[RF90_PATH_D].rfAGCControl2 = rOFDM0_XDAGCCore2;
669
670
671 priv->PHYRegDef[RF90_PATH_A].rfRxIQImbalance = rOFDM0_XARxIQImbalance;
672 priv->PHYRegDef[RF90_PATH_B].rfRxIQImbalance = rOFDM0_XBRxIQImbalance;
673 priv->PHYRegDef[RF90_PATH_C].rfRxIQImbalance = rOFDM0_XCRxIQImbalance;
674 priv->PHYRegDef[RF90_PATH_D].rfRxIQImbalance = rOFDM0_XDRxIQImbalance;
675
676
677 priv->PHYRegDef[RF90_PATH_A].rfRxAFE = rOFDM0_XARxAFE;
678 priv->PHYRegDef[RF90_PATH_B].rfRxAFE = rOFDM0_XBRxAFE;
679 priv->PHYRegDef[RF90_PATH_C].rfRxAFE = rOFDM0_XCRxAFE;
680 priv->PHYRegDef[RF90_PATH_D].rfRxAFE = rOFDM0_XDRxAFE;
681
682
683 priv->PHYRegDef[RF90_PATH_A].rfTxIQImbalance = rOFDM0_XATxIQImbalance;
684 priv->PHYRegDef[RF90_PATH_B].rfTxIQImbalance = rOFDM0_XBTxIQImbalance;
685 priv->PHYRegDef[RF90_PATH_C].rfTxIQImbalance = rOFDM0_XCTxIQImbalance;
686 priv->PHYRegDef[RF90_PATH_D].rfTxIQImbalance = rOFDM0_XDTxIQImbalance;
687
688
689 priv->PHYRegDef[RF90_PATH_A].rfTxAFE = rOFDM0_XATxAFE;
690 priv->PHYRegDef[RF90_PATH_B].rfTxAFE = rOFDM0_XBTxAFE;
691 priv->PHYRegDef[RF90_PATH_C].rfTxAFE = rOFDM0_XCTxAFE;
692 priv->PHYRegDef[RF90_PATH_D].rfTxAFE = rOFDM0_XDTxAFE;
693
694
695 priv->PHYRegDef[RF90_PATH_A].rfLSSIReadBack = rFPGA0_XA_LSSIReadBack;
696 priv->PHYRegDef[RF90_PATH_B].rfLSSIReadBack = rFPGA0_XB_LSSIReadBack;
697 priv->PHYRegDef[RF90_PATH_C].rfLSSIReadBack = rFPGA0_XC_LSSIReadBack;
698 priv->PHYRegDef[RF90_PATH_D].rfLSSIReadBack = rFPGA0_XD_LSSIReadBack;
699}
700
701
702
703
704
705
706
707
708
709
710
711
712u8 rtl8192_phy_checkBBAndRF(struct net_device *dev, HW90_BLOCK_E CheckBlock,
713 RF90_RADIO_PATH_E eRFPath)
714{
715 u8 ret = 0;
716 u32 i, CheckTimes = 4, reg = 0;
717 u32 WriteAddr[4];
718 u32 WriteData[] = {0xfffff027, 0xaa55a02f, 0x00000027, 0x55aa502f};
719
720
721 WriteAddr[HW90_BLOCK_MAC] = 0x100;
722 WriteAddr[HW90_BLOCK_PHY0] = 0x900;
723 WriteAddr[HW90_BLOCK_PHY1] = 0x800;
724 WriteAddr[HW90_BLOCK_RF] = 0x3;
725 RT_TRACE(COMP_PHY, "%s(), CheckBlock: %d\n", __func__, CheckBlock);
726 for (i = 0; i < CheckTimes; i++) {
727
728
729 switch (CheckBlock) {
730 case HW90_BLOCK_MAC:
731 RT_TRACE(COMP_ERR,
732 "PHY_CheckBBRFOK(): Never Write 0x100 here!\n");
733 break;
734
735 case HW90_BLOCK_PHY0:
736 case HW90_BLOCK_PHY1:
737 write_nic_dword(dev, WriteAddr[CheckBlock],
738 WriteData[i]);
739 read_nic_dword(dev, WriteAddr[CheckBlock], ®);
740 break;
741
742 case HW90_BLOCK_RF:
743 WriteData[i] &= 0xfff;
744 rtl8192_phy_SetRFReg(dev, eRFPath,
745 WriteAddr[HW90_BLOCK_RF],
746 bMask12Bits, WriteData[i]);
747
748
749 usleep_range(1000, 1000);
750 reg = rtl8192_phy_QueryRFReg(dev, eRFPath,
751 WriteAddr[HW90_BLOCK_RF],
752 bMask12Bits);
753 usleep_range(1000, 1000);
754 break;
755
756 default:
757 ret = 1;
758 break;
759 }
760
761
762
763 if (reg != WriteData[i]) {
764 RT_TRACE((COMP_PHY|COMP_ERR),
765 "error reg: %x, WriteData: %x\n",
766 reg, WriteData[i]);
767 ret = 1;
768 break;
769 }
770 }
771
772 return ret;
773}
774
775
776
777
778
779
780
781
782
783void rtl8192_BB_Config_ParaFile(struct net_device *dev)
784{
785 struct r8192_priv *priv = ieee80211_priv(dev);
786 u8 reg_u8 = 0, eCheckItem = 0, status = 0;
787 u32 reg_u32 = 0;
788
789
790
791
792
793
794 read_nic_byte(dev, BB_GLOBAL_RESET, ®_u8);
795 write_nic_byte(dev, BB_GLOBAL_RESET, (reg_u8|BB_GLOBAL_RESET_BIT));
796 mdelay(50);
797
798 read_nic_dword(dev, CPU_GEN, ®_u32);
799 write_nic_dword(dev, CPU_GEN, (reg_u32&(~CPU_GEN_BB_RST)));
800
801
802
803 for (eCheckItem = (HW90_BLOCK_E)HW90_BLOCK_PHY0;
804 eCheckItem <= HW90_BLOCK_PHY1; eCheckItem++) {
805
806 status = rtl8192_phy_checkBBAndRF(dev, (HW90_BLOCK_E)eCheckItem,
807 (RF90_RADIO_PATH_E)0);
808 if (status != 0) {
809 RT_TRACE((COMP_ERR | COMP_PHY),
810 "PHY_RF8256_Config(): Check PHY%d Fail!!\n",
811 eCheckItem-1);
812 return;
813 }
814 }
815
816 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bCCKEn|bOFDMEn, 0x0);
817
818
819 rtl8192_phyConfigBB(dev, BaseBand_Config_PHY_REG);
820
821
822 read_nic_dword(dev, CPU_GEN, ®_u32);
823 write_nic_dword(dev, CPU_GEN, (reg_u32|CPU_GEN_BB_RST));
824
825
826
827 rtl8192_phyConfigBB(dev, BaseBand_Config_AGC_TAB);
828
829
830 write_nic_byte_E(dev, 0x5e, 0x00);
831 if (priv->card_8192_version == (u8)VERSION_819xU_A) {
832
833 reg_u32 = (priv->AntennaTxPwDiff[1]<<4 |
834 priv->AntennaTxPwDiff[0]);
835 rtl8192_setBBreg(dev, rFPGA0_TxGainStage, (bXBTxAGC|bXCTxAGC),
836 reg_u32);
837
838
839 reg_u32 = priv->CrystalCap & 0xf;
840 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, bXtalCap,
841 reg_u32);
842 }
843
844
845
846 priv->bCckHighPower = (u8)rtl8192_QueryBBReg(dev,
847 rFPGA0_XA_HSSIParameter2,
848 0x200);
849 return;
850}
851
852
853
854
855
856
857
858
859
860void rtl8192_BBConfig(struct net_device *dev)
861{
862 rtl8192_InitBBRFRegDef(dev);
863
864
865
866 rtl8192_BB_Config_ParaFile(dev);
867 return;
868}
869
870
871
872
873
874
875
876
877
878void rtl8192_phy_getTxPower(struct net_device *dev)
879{
880 struct r8192_priv *priv = ieee80211_priv(dev);
881 u8 tmp;
882
883 read_nic_dword(dev, rTxAGC_Rate18_06,
884 &priv->MCSTxPowerLevelOriginalOffset[0]);
885 read_nic_dword(dev, rTxAGC_Rate54_24,
886 &priv->MCSTxPowerLevelOriginalOffset[1]);
887 read_nic_dword(dev, rTxAGC_Mcs03_Mcs00,
888 &priv->MCSTxPowerLevelOriginalOffset[2]);
889 read_nic_dword(dev, rTxAGC_Mcs07_Mcs04,
890 &priv->MCSTxPowerLevelOriginalOffset[3]);
891 read_nic_dword(dev, rTxAGC_Mcs11_Mcs08,
892 &priv->MCSTxPowerLevelOriginalOffset[4]);
893 read_nic_dword(dev, rTxAGC_Mcs15_Mcs12,
894 &priv->MCSTxPowerLevelOriginalOffset[5]);
895
896
897 read_nic_byte(dev, rOFDM0_XAAGCCore1, &priv->DefaultInitialGain[0]);
898 read_nic_byte(dev, rOFDM0_XBAGCCore1, &priv->DefaultInitialGain[1]);
899 read_nic_byte(dev, rOFDM0_XCAGCCore1, &priv->DefaultInitialGain[2]);
900 read_nic_byte(dev, rOFDM0_XDAGCCore1, &priv->DefaultInitialGain[3]);
901 RT_TRACE(COMP_INIT,
902 "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x)\n",
903 priv->DefaultInitialGain[0], priv->DefaultInitialGain[1],
904 priv->DefaultInitialGain[2], priv->DefaultInitialGain[3]);
905
906
907 read_nic_byte(dev, rOFDM0_RxDetector3, &priv->framesync);
908 read_nic_byte(dev, rOFDM0_RxDetector2, &tmp);
909 priv->framesyncC34 = tmp;
910 RT_TRACE(COMP_INIT, "Default framesync (0x%x) = 0x%x \n",
911 rOFDM0_RxDetector3, priv->framesync);
912
913
914 read_nic_word(dev, SIFS, &priv->SifsTime);
915
916 return;
917}
918
919
920
921
922
923
924
925
926
927void rtl8192_phy_setTxPower(struct net_device *dev, u8 channel)
928{
929 struct r8192_priv *priv = ieee80211_priv(dev);
930 u8 powerlevel = priv->TxPowerLevelCCK[channel-1];
931 u8 powerlevelOFDM24G = priv->TxPowerLevelOFDM24G[channel-1];
932
933 switch (priv->rf_chip) {
934 case RF_8256:
935
936 PHY_SetRF8256CCKTxPower(dev, powerlevel);
937 PHY_SetRF8256OFDMTxPower(dev, powerlevelOFDM24G);
938 break;
939 default:
940 RT_TRACE((COMP_PHY|COMP_ERR),
941 "error RF chipID(8225 or 8258) in function %s()\n",
942 __func__);
943 break;
944 }
945 return;
946}
947
948
949
950
951
952
953
954void rtl8192_phy_RFConfig(struct net_device *dev)
955{
956 struct r8192_priv *priv = ieee80211_priv(dev);
957
958 switch (priv->rf_chip) {
959 case RF_8256:
960 PHY_RF8256_Config(dev);
961 break;
962 default:
963 RT_TRACE(COMP_ERR, "error chip id\n");
964 break;
965 }
966 return;
967}
968
969
970
971
972
973
974
975void rtl8192_phy_updateInitGain(struct net_device *dev)
976{
977 return;
978}
979
980
981
982
983
984
985
986
987
988
989u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device *dev,
990 RF90_RADIO_PATH_E eRFPath)
991{
992
993 int i;
994 u8 ret = 0;
995
996 switch (eRFPath) {
997 case RF90_PATH_A:
998 for (i = 0; i < RadioA_ArrayLength; i = i+2) {
999
1000 if (rtl819XRadioA_Array[i] == 0xfe) {
1001 mdelay(100);
1002 continue;
1003 }
1004 rtl8192_phy_SetRFReg(dev, eRFPath,
1005 rtl819XRadioA_Array[i],
1006 bMask12Bits,
1007 rtl819XRadioA_Array[i+1]);
1008 mdelay(1);
1009
1010 }
1011 break;
1012 case RF90_PATH_B:
1013 for (i = 0; i < RadioB_ArrayLength; i = i+2) {
1014
1015 if (rtl819XRadioB_Array[i] == 0xfe) {
1016 mdelay(100);
1017 continue;
1018 }
1019 rtl8192_phy_SetRFReg(dev, eRFPath,
1020 rtl819XRadioB_Array[i],
1021 bMask12Bits,
1022 rtl819XRadioB_Array[i+1]);
1023 mdelay(1);
1024
1025 }
1026 break;
1027 case RF90_PATH_C:
1028 for (i = 0; i < RadioC_ArrayLength; i = i+2) {
1029
1030 if (rtl819XRadioC_Array[i] == 0xfe) {
1031 mdelay(100);
1032 continue;
1033 }
1034 rtl8192_phy_SetRFReg(dev, eRFPath,
1035 rtl819XRadioC_Array[i],
1036 bMask12Bits,
1037 rtl819XRadioC_Array[i+1]);
1038 mdelay(1);
1039
1040 }
1041 break;
1042 case RF90_PATH_D:
1043 for (i = 0; i < RadioD_ArrayLength; i = i+2) {
1044
1045 if (rtl819XRadioD_Array[i] == 0xfe) {
1046 mdelay(100);
1047 continue;
1048 }
1049 rtl8192_phy_SetRFReg(dev, eRFPath,
1050 rtl819XRadioD_Array[i],
1051 bMask12Bits,
1052 rtl819XRadioD_Array[i+1]);
1053 mdelay(1);
1054
1055 }
1056 break;
1057 default:
1058 break;
1059 }
1060
1061 return ret;
1062
1063}
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073void rtl8192_SetTxPowerLevel(struct net_device *dev, u8 channel)
1074{
1075 struct r8192_priv *priv = ieee80211_priv(dev);
1076 u8 powerlevel = priv->TxPowerLevelCCK[channel-1];
1077 u8 powerlevelOFDM24G = priv->TxPowerLevelOFDM24G[channel-1];
1078
1079 switch (priv->rf_chip) {
1080 case RF_8225:
1081#ifdef TO_DO_LIST
1082 PHY_SetRF8225CckTxPower(Adapter, powerlevel);
1083 PHY_SetRF8225OfdmTxPower(Adapter, powerlevelOFDM24G);
1084#endif
1085 break;
1086
1087 case RF_8256:
1088 PHY_SetRF8256CCKTxPower(dev, powerlevel);
1089 PHY_SetRF8256OFDMTxPower(dev, powerlevelOFDM24G);
1090 break;
1091
1092 case RF_8258:
1093 break;
1094 default:
1095 RT_TRACE(COMP_ERR, "unknown rf chip ID in %s()\n", __func__);
1096 break;
1097 }
1098 return;
1099}
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109bool rtl8192_SetRFPowerState(struct net_device *dev,
1110 RT_RF_POWER_STATE eRFPowerState)
1111{
1112 bool bResult = true;
1113 struct r8192_priv *priv = ieee80211_priv(dev);
1114
1115 if (eRFPowerState == priv->ieee80211->eRFPowerState)
1116 return false;
1117
1118 if (priv->SetRFPowerStateInProgress == true)
1119 return false;
1120
1121 priv->SetRFPowerStateInProgress = true;
1122
1123 switch (priv->rf_chip) {
1124 case RF_8256:
1125 switch (eRFPowerState) {
1126 case eRfOn:
1127
1128
1129 rtl8192_setBBreg(dev, rFPGA0_XA_RFInterfaceOE, BIT4,
1130 0x1);
1131
1132 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0x300,
1133 0x3);
1134
1135 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x18,
1136 0x3);
1137
1138 rtl8192_setBBreg(dev, rOFDM0_TRxPathEnable, 0x3, 0x3);
1139
1140 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0x3, 0x3);
1141
1142 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x60,
1143 0x3);
1144
1145 break;
1146
1147 case eRfSleep:
1148
1149 break;
1150
1151 case eRfOff:
1152
1153
1154 rtl8192_setBBreg(dev, rFPGA0_XA_RFInterfaceOE, BIT4,
1155 0x0);
1156
1157 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0xf00,
1158 0x0);
1159
1160 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x18,
1161 0x0);
1162
1163 rtl8192_setBBreg(dev, rOFDM0_TRxPathEnable, 0xf, 0x0);
1164
1165 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0x0);
1166
1167 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x60,
1168 0x0);
1169
1170 break;
1171
1172 default:
1173 bResult = false;
1174 RT_TRACE(COMP_ERR, "%s(): unknown state to set: 0x%X\n",
1175 __func__, eRFPowerState);
1176 break;
1177 }
1178 break;
1179 default:
1180 RT_TRACE(COMP_ERR, "Not support rf_chip(%x)\n", priv->rf_chip);
1181 break;
1182 }
1183#ifdef TO_DO_LIST
1184 if (bResult) {
1185
1186 pHalData->eRFPowerState = eRFPowerState;
1187 switch (pHalData->RFChipID) {
1188 case RF_8256:
1189 switch (pHalData->eRFPowerState) {
1190 case eRfOff:
1191
1192
1193 if (pMgntInfo->RfOffReason == RF_CHANGE_BY_IPS)
1194 Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_NO_LINK);
1195 else
1196
1197 Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_POWER_OFF);
1198 break;
1199
1200 case eRfOn:
1201
1202
1203
1204 if (pMgntInfo->bMediaConnect == TRUE)
1205 Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_LINK);
1206 else
1207
1208 Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_NO_LINK);
1209 break;
1210
1211 default:
1212 break;
1213 }
1214 break;
1215
1216 default:
1217 RT_TRACE(COMP_RF, DBG_LOUD, "%s(): Unknown RF type\n",
1218 __func__);
1219 break;
1220 }
1221
1222 }
1223#endif
1224 priv->SetRFPowerStateInProgress = false;
1225
1226 return bResult;
1227}
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242u8 rtl8192_phy_SetSwChnlCmdArray(SwChnlCmd *CmdTable, u32 CmdTableIdx,
1243 u32 CmdTableSz, SwChnlCmdID CmdID, u32 Para1,
1244 u32 Para2, u32 msDelay)
1245{
1246 SwChnlCmd *pCmd;
1247
1248 if (CmdTable == NULL) {
1249 RT_TRACE(COMP_ERR, "%s(): CmdTable cannot be NULL\n", __func__);
1250 return false;
1251 }
1252 if (CmdTableIdx >= CmdTableSz) {
1253 RT_TRACE(COMP_ERR, "%s(): Access invalid index, please check size of the table, CmdTableIdx:%d, CmdTableSz:%d\n",
1254 __func__, CmdTableIdx, CmdTableSz);
1255 return false;
1256 }
1257
1258 pCmd = CmdTable + CmdTableIdx;
1259 pCmd->CmdID = CmdID;
1260 pCmd->Para1 = Para1;
1261 pCmd->Para2 = Para2;
1262 pCmd->msDelay = msDelay;
1263
1264 return true;
1265}
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279u8 rtl8192_phy_SwChnlStepByStep(struct net_device *dev, u8 channel, u8 *stage,
1280 u8 *step, u32 *delay)
1281{
1282 struct r8192_priv *priv = ieee80211_priv(dev);
1283 SwChnlCmd PreCommonCmd[MAX_PRECMD_CNT];
1284 u32 PreCommonCmdCnt;
1285 SwChnlCmd PostCommonCmd[MAX_POSTCMD_CNT];
1286 u32 PostCommonCmdCnt;
1287 SwChnlCmd RfDependCmd[MAX_RFDEPENDCMD_CNT];
1288 u32 RfDependCmdCnt;
1289 SwChnlCmd *CurrentCmd = NULL;
1290 u8 eRFPath;
1291
1292 RT_TRACE(COMP_CH, "%s() stage: %d, step: %d, channel: %d\n",
1293 __func__, *stage, *step, channel);
1294 if (!IsLegalChannel(priv->ieee80211, channel)) {
1295 RT_TRACE(COMP_ERR, "set to illegal channel: %d\n", channel);
1296
1297
1298 return true;
1299 }
1300
1301
1302
1303
1304 PreCommonCmdCnt = 0;
1305 rtl8192_phy_SetSwChnlCmdArray(PreCommonCmd, PreCommonCmdCnt++,
1306 MAX_PRECMD_CNT, CmdID_SetTxPowerLevel,
1307 0, 0, 0);
1308 rtl8192_phy_SetSwChnlCmdArray(PreCommonCmd, PreCommonCmdCnt++,
1309 MAX_PRECMD_CNT, CmdID_End, 0, 0, 0);
1310
1311
1312 PostCommonCmdCnt = 0;
1313
1314 rtl8192_phy_SetSwChnlCmdArray(PostCommonCmd, PostCommonCmdCnt++,
1315 MAX_POSTCMD_CNT, CmdID_End, 0, 0, 0);
1316
1317
1318 RfDependCmdCnt = 0;
1319 switch (priv->rf_chip) {
1320 case RF_8225:
1321 if (!(channel >= 1 && channel <= 14)) {
1322 RT_TRACE(COMP_ERR,
1323 "illegal channel for Zebra 8225: %d\n",
1324 channel);
1325 return true;
1326 }
1327 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++,
1328 MAX_RFDEPENDCMD_CNT,
1329 CmdID_RF_WriteReg,
1330 rZebra1_Channel,
1331 RF_CHANNEL_TABLE_ZEBRA[channel],
1332 10);
1333 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++,
1334 MAX_RFDEPENDCMD_CNT,
1335 CmdID_End, 0, 0, 0);
1336 break;
1337
1338 case RF_8256:
1339
1340 if (!(channel >= 1 && channel <= 14)) {
1341 RT_TRACE(COMP_ERR,
1342 "illegal channel for Zebra 8256: %d\n",
1343 channel);
1344 return true;
1345 }
1346 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++,
1347 MAX_RFDEPENDCMD_CNT,
1348 CmdID_RF_WriteReg,
1349 rZebra1_Channel, channel, 10);
1350 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++,
1351 MAX_RFDEPENDCMD_CNT,
1352 CmdID_End, 0, 0, 0);
1353 break;
1354
1355 case RF_8258:
1356 break;
1357
1358 default:
1359 RT_TRACE(COMP_ERR, "Unknown RFChipID: %d\n", priv->rf_chip);
1360 return true;
1361 break;
1362 }
1363
1364
1365 do {
1366 switch (*stage) {
1367 case 0:
1368 CurrentCmd = &PreCommonCmd[*step];
1369 break;
1370 case 1:
1371 CurrentCmd = &RfDependCmd[*step];
1372 break;
1373 case 2:
1374 CurrentCmd = &PostCommonCmd[*step];
1375 break;
1376 }
1377
1378 if (CurrentCmd->CmdID == CmdID_End) {
1379 if ((*stage) == 2) {
1380 (*delay) = CurrentCmd->msDelay;
1381 return true;
1382 } else {
1383 (*stage)++;
1384 (*step) = 0;
1385 continue;
1386 }
1387 }
1388
1389 switch (CurrentCmd->CmdID) {
1390 case CmdID_SetTxPowerLevel:
1391 if (priv->card_8192_version == (u8)VERSION_819xU_A)
1392
1393 rtl8192_SetTxPowerLevel(dev, channel);
1394 break;
1395 case CmdID_WritePortUlong:
1396 write_nic_dword(dev, CurrentCmd->Para1,
1397 CurrentCmd->Para2);
1398 break;
1399 case CmdID_WritePortUshort:
1400 write_nic_word(dev, CurrentCmd->Para1,
1401 (u16)CurrentCmd->Para2);
1402 break;
1403 case CmdID_WritePortUchar:
1404 write_nic_byte(dev, CurrentCmd->Para1,
1405 (u8)CurrentCmd->Para2);
1406 break;
1407 case CmdID_RF_WriteReg:
1408 for (eRFPath = 0; eRFPath < RF90_PATH_MAX; eRFPath++) {
1409 rtl8192_phy_SetRFReg(dev,
1410 (RF90_RADIO_PATH_E)eRFPath,
1411 CurrentCmd->Para1,
1412 bZebra1_ChannelNum,
1413 CurrentCmd->Para2);
1414 }
1415 break;
1416 default:
1417 break;
1418 }
1419
1420 break;
1421 } while (true);
1422
1423 (*delay) = CurrentCmd->msDelay;
1424 (*step)++;
1425 return false;
1426}
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436void rtl8192_phy_FinishSwChnlNow(struct net_device *dev, u8 channel)
1437{
1438 struct r8192_priv *priv = ieee80211_priv(dev);
1439 u32 delay = 0;
1440
1441 while (!rtl8192_phy_SwChnlStepByStep(dev, channel, &priv->SwChnlStage,
1442 &priv->SwChnlStep, &delay)) {
1443 if (!priv->up)
1444 break;
1445 }
1446}
1447
1448
1449
1450
1451
1452
1453
1454
1455void rtl8192_SwChnl_WorkItem(struct net_device *dev)
1456{
1457
1458 struct r8192_priv *priv = ieee80211_priv(dev);
1459
1460 RT_TRACE(COMP_CH, "==> SwChnlCallback819xUsbWorkItem(), chan:%d\n",
1461 priv->chan);
1462
1463
1464 rtl8192_phy_FinishSwChnlNow(dev, priv->chan);
1465
1466 RT_TRACE(COMP_CH, "<== SwChnlCallback819xUsbWorkItem()\n");
1467}
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477u8 rtl8192_phy_SwChnl(struct net_device *dev, u8 channel)
1478{
1479 struct r8192_priv *priv = ieee80211_priv(dev);
1480 RT_TRACE(COMP_CH, "%s(), SwChnlInProgress: %d\n", __func__,
1481 priv->SwChnlInProgress);
1482 if (!priv->up)
1483 return false;
1484 if (priv->SwChnlInProgress)
1485 return false;
1486
1487
1488 switch (priv->ieee80211->mode) {
1489 case WIRELESS_MODE_A:
1490 case WIRELESS_MODE_N_5G:
1491 if (channel <= 14) {
1492 RT_TRACE(COMP_ERR, "WIRELESS_MODE_A but channel<=14\n");
1493 return false;
1494 }
1495 break;
1496 case WIRELESS_MODE_B:
1497 if (channel > 14) {
1498 RT_TRACE(COMP_ERR, "WIRELESS_MODE_B but channel>14\n");
1499 return false;
1500 }
1501 break;
1502 case WIRELESS_MODE_G:
1503 case WIRELESS_MODE_N_24G:
1504 if (channel > 14) {
1505 RT_TRACE(COMP_ERR, "WIRELESS_MODE_G but channel>14\n");
1506 return false;
1507 }
1508 break;
1509 }
1510
1511
1512 priv->SwChnlInProgress = true;
1513 if (channel == 0)
1514 channel = 1;
1515
1516 priv->chan = channel;
1517
1518 priv->SwChnlStage = 0;
1519 priv->SwChnlStep = 0;
1520 if (priv->up)
1521 rtl8192_SwChnl_WorkItem(dev);
1522
1523 priv->SwChnlInProgress = false;
1524 return true;
1525}
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535void rtl8192_SetBWModeWorkItem(struct net_device *dev)
1536{
1537
1538 struct r8192_priv *priv = ieee80211_priv(dev);
1539 u8 regBwOpMode;
1540
1541 RT_TRACE(COMP_SWBW, "%s() Switch to %s bandwidth\n", __func__,
1542 priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz");
1543
1544
1545 if (priv->rf_chip == RF_PSEUDO_11N) {
1546 priv->SetBWModeInProgress = false;
1547 return;
1548 }
1549
1550
1551 read_nic_byte(dev, BW_OPMODE, ®BwOpMode);
1552
1553 switch (priv->CurrentChannelBW) {
1554 case HT_CHANNEL_WIDTH_20:
1555 regBwOpMode |= BW_OPMODE_20MHZ;
1556
1557 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
1558 break;
1559
1560 case HT_CHANNEL_WIDTH_20_40:
1561 regBwOpMode &= ~BW_OPMODE_20MHZ;
1562
1563 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
1564 break;
1565
1566 default:
1567 RT_TRACE(COMP_ERR,
1568 "SetChannelBandwidth819xUsb(): unknown Bandwidth: %#X\n",
1569 priv->CurrentChannelBW);
1570 break;
1571 }
1572
1573
1574 switch (priv->CurrentChannelBW) {
1575 case HT_CHANNEL_WIDTH_20:
1576 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x0);
1577 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x0);
1578 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1,
1579 0x00100000, 1);
1580
1581
1582 priv->cck_present_attentuation =
1583 priv->cck_present_attentuation_20Mdefault +
1584 priv->cck_present_attentuation_difference;
1585
1586 if (priv->cck_present_attentuation > 22)
1587 priv->cck_present_attentuation = 22;
1588 if (priv->cck_present_attentuation < 0)
1589 priv->cck_present_attentuation = 0;
1590 RT_TRACE(COMP_INIT,
1591 "20M, pHalData->CCKPresentAttentuation = %d\n",
1592 priv->cck_present_attentuation);
1593
1594 if (priv->chan == 14 && !priv->bcck_in_ch14) {
1595 priv->bcck_in_ch14 = TRUE;
1596 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
1597 } else if (priv->chan != 14 && priv->bcck_in_ch14) {
1598 priv->bcck_in_ch14 = FALSE;
1599 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
1600 } else {
1601 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
1602 }
1603
1604 break;
1605 case HT_CHANNEL_WIDTH_20_40:
1606 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x1);
1607 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x1);
1608 rtl8192_setBBreg(dev, rCCK0_System, bCCKSideBand,
1609 priv->nCur40MhzPrimeSC>>1);
1610 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00100000, 0);
1611 rtl8192_setBBreg(dev, rOFDM1_LSTF, 0xC00,
1612 priv->nCur40MhzPrimeSC);
1613 priv->cck_present_attentuation =
1614 priv->cck_present_attentuation_40Mdefault +
1615 priv->cck_present_attentuation_difference;
1616
1617 if (priv->cck_present_attentuation > 22)
1618 priv->cck_present_attentuation = 22;
1619 if (priv->cck_present_attentuation < 0)
1620 priv->cck_present_attentuation = 0;
1621
1622 RT_TRACE(COMP_INIT,
1623 "40M, pHalData->CCKPresentAttentuation = %d\n",
1624 priv->cck_present_attentuation);
1625 if (priv->chan == 14 && !priv->bcck_in_ch14) {
1626 priv->bcck_in_ch14 = true;
1627 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
1628 } else if (priv->chan != 14 && priv->bcck_in_ch14) {
1629 priv->bcck_in_ch14 = false;
1630 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
1631 } else {
1632 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
1633 }
1634
1635 break;
1636 default:
1637 RT_TRACE(COMP_ERR,
1638 "SetChannelBandwidth819xUsb(): unknown Bandwidth: %#X\n",
1639 priv->CurrentChannelBW);
1640 break;
1641
1642 }
1643
1644
1645
1646
1647 switch (priv->rf_chip) {
1648 case RF_8225:
1649#ifdef TO_DO_LIST
1650 PHY_SetRF8225Bandwidth(Adapter, pHalData->CurrentChannelBW);
1651#endif
1652 break;
1653
1654 case RF_8256:
1655 PHY_SetRF8256Bandwidth(dev, priv->CurrentChannelBW);
1656 break;
1657
1658 case RF_8258:
1659 break;
1660
1661 case RF_PSEUDO_11N:
1662 break;
1663
1664 default:
1665 RT_TRACE(COMP_ERR, "Unknown RFChipID: %d\n", priv->rf_chip);
1666 break;
1667 }
1668 priv->SetBWModeInProgress = false;
1669
1670 RT_TRACE(COMP_SWBW, "<==SetBWMode819xUsb(), %d\n",
1671 atomic_read(&priv->ieee80211->atm_swbw));
1672}
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684void rtl8192_SetBWMode(struct net_device *dev, HT_CHANNEL_WIDTH bandwidth,
1685 HT_EXTCHNL_OFFSET offset)
1686{
1687 struct r8192_priv *priv = ieee80211_priv(dev);
1688
1689 if (priv->SetBWModeInProgress)
1690 return;
1691 priv->SetBWModeInProgress = true;
1692
1693 priv->CurrentChannelBW = bandwidth;
1694
1695 if (offset == HT_EXTCHNL_OFFSET_LOWER)
1696 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_UPPER;
1697 else if (offset == HT_EXTCHNL_OFFSET_UPPER)
1698 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_LOWER;
1699 else
1700 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
1701
1702 rtl8192_SetBWModeWorkItem(dev);
1703
1704}
1705
1706void InitialGain819xUsb(struct net_device *dev, u8 Operation)
1707{
1708 struct r8192_priv *priv = ieee80211_priv(dev);
1709
1710 priv->InitialGainOperateType = Operation;
1711
1712 if (priv->up)
1713 queue_delayed_work(priv->priv_wq, &priv->initialgain_operate_wq, 0);
1714}
1715
1716void InitialGainOperateWorkItemCallBack(struct work_struct *work)
1717{
1718 struct delayed_work *dwork = container_of(work, struct delayed_work,
1719 work);
1720 struct r8192_priv *priv = container_of(dwork, struct r8192_priv,
1721 initialgain_operate_wq);
1722 struct net_device *dev = priv->ieee80211->dev;
1723#define SCAN_RX_INITIAL_GAIN 0x17
1724#define POWER_DETECTION_TH 0x08
1725 u32 bitmask;
1726 u8 initial_gain;
1727 u8 Operation;
1728
1729 Operation = priv->InitialGainOperateType;
1730
1731 switch (Operation) {
1732 case IG_Backup:
1733 RT_TRACE(COMP_SCAN, "IG_Backup, backup the initial gain.\n");
1734 initial_gain = SCAN_RX_INITIAL_GAIN;
1735 bitmask = bMaskByte0;
1736 if (dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
1737
1738 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8);
1739 priv->initgain_backup.xaagccore1 =
1740 (u8)rtl8192_QueryBBReg(dev, rOFDM0_XAAGCCore1, bitmask);
1741 priv->initgain_backup.xbagccore1 =
1742 (u8)rtl8192_QueryBBReg(dev, rOFDM0_XBAGCCore1, bitmask);
1743 priv->initgain_backup.xcagccore1 =
1744 (u8)rtl8192_QueryBBReg(dev, rOFDM0_XCAGCCore1, bitmask);
1745 priv->initgain_backup.xdagccore1 =
1746 (u8)rtl8192_QueryBBReg(dev, rOFDM0_XDAGCCore1, bitmask);
1747 bitmask = bMaskByte2;
1748 priv->initgain_backup.cca =
1749 (u8)rtl8192_QueryBBReg(dev, rCCK0_CCA, bitmask);
1750
1751 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc50 is %x\n",
1752 priv->initgain_backup.xaagccore1);
1753 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc58 is %x\n",
1754 priv->initgain_backup.xbagccore1);
1755 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc60 is %x\n",
1756 priv->initgain_backup.xcagccore1);
1757 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc68 is %x\n",
1758 priv->initgain_backup.xdagccore1);
1759 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xa0a is %x\n",
1760 priv->initgain_backup.cca);
1761
1762 RT_TRACE(COMP_SCAN, "Write scan initial gain = 0x%x \n",
1763 initial_gain);
1764 write_nic_byte(dev, rOFDM0_XAAGCCore1, initial_gain);
1765 write_nic_byte(dev, rOFDM0_XBAGCCore1, initial_gain);
1766 write_nic_byte(dev, rOFDM0_XCAGCCore1, initial_gain);
1767 write_nic_byte(dev, rOFDM0_XDAGCCore1, initial_gain);
1768 RT_TRACE(COMP_SCAN, "Write scan 0xa0a = 0x%x \n",
1769 POWER_DETECTION_TH);
1770 write_nic_byte(dev, 0xa0a, POWER_DETECTION_TH);
1771 break;
1772 case IG_Restore:
1773 RT_TRACE(COMP_SCAN, "IG_Restore, restore the initial gain.\n");
1774 bitmask = 0x7f;
1775 if (dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
1776
1777 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8);
1778
1779 rtl8192_setBBreg(dev, rOFDM0_XAAGCCore1, bitmask,
1780 (u32)priv->initgain_backup.xaagccore1);
1781 rtl8192_setBBreg(dev, rOFDM0_XBAGCCore1, bitmask,
1782 (u32)priv->initgain_backup.xbagccore1);
1783 rtl8192_setBBreg(dev, rOFDM0_XCAGCCore1, bitmask,
1784 (u32)priv->initgain_backup.xcagccore1);
1785 rtl8192_setBBreg(dev, rOFDM0_XDAGCCore1, bitmask,
1786 (u32)priv->initgain_backup.xdagccore1);
1787 bitmask = bMaskByte2;
1788 rtl8192_setBBreg(dev, rCCK0_CCA, bitmask,
1789 (u32)priv->initgain_backup.cca);
1790
1791 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc50 is %x\n",
1792 priv->initgain_backup.xaagccore1);
1793 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc58 is %x\n",
1794 priv->initgain_backup.xbagccore1);
1795 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc60 is %x\n",
1796 priv->initgain_backup.xcagccore1);
1797 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc68 is %x\n",
1798 priv->initgain_backup.xdagccore1);
1799 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xa0a is %x\n",
1800 priv->initgain_backup.cca);
1801
1802 rtl8192_phy_setTxPower(dev, priv->ieee80211->current_network.channel);
1803
1804 if (dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
1805
1806 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x1);
1807 break;
1808 default:
1809 RT_TRACE(COMP_SCAN, "Unknown IG Operation. \n");
1810 break;
1811 }
1812}
1813