3 #include "r819xE_phyreg.h"
4 #include "r8190_rtl8256.h"
5 #include "r819xE_phy.h"
8 #include "ieee80211/dot11d.h"
10 static const u32 RF_CHANNEL_TABLE_ZEBRA
[] = {
28 static u32 Rtl8192PciEMACPHY_Array
[] = {
29 0x03c,0xffff0000,0x00000f0f,
30 0x340,0xffffffff,0x161a1a1a,
31 0x344,0xffffffff,0x12121416,
32 0x348,0x0000ffff,0x00001818,
33 0x12c,0xffffffff,0x04000802,
34 0x318,0x00000fff,0x00000100,
36 static u32 Rtl8192PciEMACPHY_Array_PG
[] = {
37 0x03c,0xffff0000,0x00000f0f,
38 0xe00,0xffffffff,0x06090909,
39 0xe04,0xffffffff,0x00030306,
40 0xe08,0x0000ff00,0x00000000,
41 0xe10,0xffffffff,0x0a0c0d0f,
42 0xe14,0xffffffff,0x06070809,
43 0xe18,0xffffffff,0x0a0c0d0f,
44 0xe1c,0xffffffff,0x06070809,
45 0x12c,0xffffffff,0x04000802,
46 0x318,0x00000fff,0x00000800,
48 static u32 Rtl8192PciEAGCTAB_Array
[AGCTAB_ArrayLength
] = {
242 static u32 Rtl8192PciEPHY_REGArray
[PHY_REGArrayLength
] = {
244 static u32 Rtl8192PciEPHY_REG_1T2RArray
[PHY_REG_1T2RArrayLength
] = {
394 static u32 Rtl8192PciERadioA_Array
[RadioA_ArrayLength
] = {
519 static u32 Rtl8192PciERadioB_Array
[RadioB_ArrayLength
] = {
560 static u32 Rtl8192PciERadioC_Array
[RadioC_ArrayLength
] = {
562 static u32 Rtl8192PciERadioD_Array
[RadioD_ArrayLength
] = {
565 /*************************Define local function prototype**********************/
567 static u32
phy_FwRFSerialRead(struct net_device
* dev
,RF90_RADIO_PATH_E eRFPath
,u32 Offset
);
568 static void phy_FwRFSerialWrite(struct net_device
* dev
,RF90_RADIO_PATH_E eRFPath
,u32 Offset
,u32 Data
);
569 /*************************Define local function prototype**********************/
570 /******************************************************************************
571 *function: This function read BB parameters from Header file we gen,
572 * and do register read/write
573 * input: u32 dwBitMask //taget bit pos in the addr to be modified
575 * return: u32 return the shift bit bit position of the mask
576 * ****************************************************************************/
577 static u32
rtl8192_CalculateBitShift(u32 dwBitMask
)
580 for (i
=0; i
<=31; i
++)
582 if (((dwBitMask
>>i
)&0x1) == 1)
587 /******************************************************************************
588 *function: This function check different RF type to execute legal judgement. If RF Path is illegal, we will return false.
591 * return: 0(illegal, false), 1(legal,true)
592 * ***************************************************************************/
593 u8
rtl8192_phy_CheckIsLegalRFPath(struct net_device
* dev
, u32 eRFPath
)
596 struct r8192_priv
*priv
= ieee80211_priv(dev
);
598 if (priv
->rf_type
== RF_2T4R
)
600 else if (priv
->rf_type
== RF_1T2R
)
602 if (eRFPath
== RF90_PATH_A
|| eRFPath
== RF90_PATH_B
)
604 else if (eRFPath
== RF90_PATH_C
|| eRFPath
== RF90_PATH_D
)
610 /******************************************************************************
611 *function: This function set specific bits to BB register
612 * input: net_device dev
613 * u32 dwRegAddr //target addr to be modified
614 * u32 dwBitMask //taget bit pos in the addr to be modified
615 * u32 dwData //value to be write
619 * ****************************************************************************/
620 void rtl8192_setBBreg(struct net_device
* dev
, u32 dwRegAddr
, u32 dwBitMask
, u32 dwData
)
622 struct r8192_priv
*priv
= ieee80211_priv(dev
);
623 u32 OriginalValue
, BitShift
, NewValue
;
625 if(dwBitMask
!= bMaskDWord
)
626 {//if not "double word" write
627 OriginalValue
= read_nic_dword(priv
, dwRegAddr
);
628 BitShift
= rtl8192_CalculateBitShift(dwBitMask
);
629 NewValue
= (((OriginalValue
) & (~dwBitMask
)) | (dwData
<< BitShift
));
630 write_nic_dword(priv
, dwRegAddr
, NewValue
);
632 write_nic_dword(priv
, dwRegAddr
, dwData
);
634 /******************************************************************************
635 *function: This function reads specific bits from BB register
636 * input: net_device dev
637 * u32 dwRegAddr //target addr to be readback
638 * u32 dwBitMask //taget bit pos in the addr to be readback
640 * return: u32 Data //the readback register value
642 * ****************************************************************************/
643 u32
rtl8192_QueryBBReg(struct net_device
* dev
, u32 dwRegAddr
, u32 dwBitMask
)
645 struct r8192_priv
*priv
= ieee80211_priv(dev
);
646 u32 OriginalValue
, BitShift
;
648 OriginalValue
= read_nic_dword(priv
, dwRegAddr
);
649 BitShift
= rtl8192_CalculateBitShift(dwBitMask
);
650 return (OriginalValue
& dwBitMask
) >> BitShift
;
652 /******************************************************************************
653 *function: This function read register from RF chip
654 * input: net_device dev
655 * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D
656 * u32 Offset //target address to be read
658 * return: u32 readback value
659 * notice: There are three types of serial operations:(1) Software serial write.(2)Hardware LSSI-Low Speed Serial Interface.(3)Hardware HSSI-High speed serial write. Driver here need to implement (1) and (2)---need more spec for this information.
660 * ****************************************************************************/
661 static u32
rtl8192_phy_RFSerialRead(struct net_device
* dev
, RF90_RADIO_PATH_E eRFPath
, u32 Offset
)
663 struct r8192_priv
*priv
= ieee80211_priv(dev
);
666 BB_REGISTER_DEFINITION_T
* pPhyReg
= &priv
->PHYRegDef
[eRFPath
];
667 //rtl8192_setBBreg(dev, pPhyReg->rfLSSIReadBack, bLSSIReadBackData, 0);
668 //make sure RF register offset is correct
671 //switch page for 8256 RF IC
672 if (priv
->rf_chip
== RF_8256
)
674 //analog to digital off, for protection
675 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter4
, 0xf00, 0x0);// 0x88c[11:8]
678 priv
->RfReg0Value
[eRFPath
] |= 0x140;
679 //Switch to Reg_Mode2 for Reg 31-45
680 rtl8192_setBBreg(dev
, pPhyReg
->rf3wireOffset
, bMaskDWord
, (priv
->RfReg0Value
[eRFPath
]<<16) );
682 NewOffset
= Offset
-30;
684 else if (Offset
>= 16)
686 priv
->RfReg0Value
[eRFPath
] |= 0x100;
687 priv
->RfReg0Value
[eRFPath
] &= (~0x40);
688 //Switch to Reg_Mode 1 for Reg16-30
689 rtl8192_setBBreg(dev
, pPhyReg
->rf3wireOffset
, bMaskDWord
, (priv
->RfReg0Value
[eRFPath
]<<16) );
691 NewOffset
= Offset
- 15;
698 RT_TRACE((COMP_PHY
|COMP_ERR
), "check RF type here, need to be 8256\n");
701 //put desired read addr to LSSI control Register
702 rtl8192_setBBreg(dev
, pPhyReg
->rfHSSIPara2
, bLSSIReadAddress
, NewOffset
);
703 //Issue a posedge trigger
705 rtl8192_setBBreg(dev
, pPhyReg
->rfHSSIPara2
, bLSSIReadEdge
, 0x0);
706 rtl8192_setBBreg(dev
, pPhyReg
->rfHSSIPara2
, bLSSIReadEdge
, 0x1);
709 // TODO: we should not delay such a long time. Ask help from SD3
712 ret
= rtl8192_QueryBBReg(dev
, pPhyReg
->rfLSSIReadBack
, bLSSIReadBackData
);
715 // Switch back to Reg_Mode0;
716 if(priv
->rf_chip
== RF_8256
)
718 priv
->RfReg0Value
[eRFPath
] &= 0xebf;
722 pPhyReg
->rf3wireOffset
,
724 (priv
->RfReg0Value
[eRFPath
] << 16));
726 //analog to digital on
727 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter4
, 0x300, 0x3);// 0x88c[9:8]
735 /******************************************************************************
736 *function: This function write data to RF register
737 * input: net_device dev
738 * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D
739 * u32 Offset //target address to be written
740 * u32 Data //The new register data to be written
743 * notice: For RF8256 only.
744 ===========================================================
745 *Reg Mode RegCTL[1] RegCTL[0] Note
746 * (Reg00[12]) (Reg00[10])
747 *===========================================================
748 *Reg_Mode0 0 x Reg 0 ~15(0x0 ~ 0xf)
749 *------------------------------------------------------------------
750 *Reg_Mode1 1 0 Reg 16 ~30(0x1 ~ 0xf)
751 *------------------------------------------------------------------
752 * Reg_Mode2 1 1 Reg 31 ~ 45(0x1 ~ 0xf)
753 *------------------------------------------------------------------
754 * ****************************************************************************/
755 static void rtl8192_phy_RFSerialWrite(struct net_device
* dev
, RF90_RADIO_PATH_E eRFPath
, u32 Offset
, u32 Data
)
757 struct r8192_priv
*priv
= ieee80211_priv(dev
);
758 u32 DataAndAddr
= 0, NewOffset
= 0;
759 BB_REGISTER_DEFINITION_T
*pPhyReg
= &priv
->PHYRegDef
[eRFPath
];
762 if (priv
->rf_chip
== RF_8256
)
765 //analog to digital off, for protection
766 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter4
, 0xf00, 0x0);// 0x88c[11:8]
770 priv
->RfReg0Value
[eRFPath
] |= 0x140;
771 rtl8192_setBBreg(dev
, pPhyReg
->rf3wireOffset
, bMaskDWord
, (priv
->RfReg0Value
[eRFPath
] << 16));
772 NewOffset
= Offset
- 30;
774 else if (Offset
>= 16)
776 priv
->RfReg0Value
[eRFPath
] |= 0x100;
777 priv
->RfReg0Value
[eRFPath
] &= (~0x40);
778 rtl8192_setBBreg(dev
, pPhyReg
->rf3wireOffset
, bMaskDWord
, (priv
->RfReg0Value
[eRFPath
]<<16));
779 NewOffset
= Offset
- 15;
786 RT_TRACE((COMP_PHY
|COMP_ERR
), "check RF type here, need to be 8256\n");
790 // Put write addr in [5:0] and write data in [31:16]
791 DataAndAddr
= (Data
<<16) | (NewOffset
&0x3f);
794 rtl8192_setBBreg(dev
, pPhyReg
->rf3wireOffset
, bMaskDWord
, DataAndAddr
);
798 priv
->RfReg0Value
[eRFPath
] = Data
;
800 // Switch back to Reg_Mode0;
801 if(priv
->rf_chip
== RF_8256
)
805 priv
->RfReg0Value
[eRFPath
] &= 0xebf;
808 pPhyReg
->rf3wireOffset
,
810 (priv
->RfReg0Value
[eRFPath
] << 16));
812 //analog to digital on
813 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter4
, 0x300, 0x3);// 0x88c[9:8]
817 /******************************************************************************
818 *function: This function set specific bits to RF register
819 * input: net_device dev
820 * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D
821 * u32 RegAddr //target addr to be modified
822 * u32 BitMask //taget bit pos in the addr to be modified
823 * u32 Data //value to be write
827 * ****************************************************************************/
828 void rtl8192_phy_SetRFReg(struct net_device
* dev
, RF90_RADIO_PATH_E eRFPath
, u32 RegAddr
, u32 BitMask
, u32 Data
)
830 struct r8192_priv
*priv
= ieee80211_priv(dev
);
831 u32 Original_Value
, BitShift
, New_Value
;
834 if (!rtl8192_phy_CheckIsLegalRFPath(dev
, eRFPath
))
836 if(priv
->ieee80211
->eRFPowerState
!= eRfOn
&& !priv
->being_init_adapter
)
838 //down(&priv->rf_sem);
840 RT_TRACE(COMP_PHY
, "FW RF CTRL is not ready now\n");
841 if (priv
->Rf_Mode
== RF_OP_By_FW
)
843 if (BitMask
!= bMask12Bits
) // RF data is 12 bits only
845 Original_Value
= phy_FwRFSerialRead(dev
, eRFPath
, RegAddr
);
846 BitShift
= rtl8192_CalculateBitShift(BitMask
);
847 New_Value
= (((Original_Value
) & (~BitMask
)) | (Data
<< BitShift
));
849 phy_FwRFSerialWrite(dev
, eRFPath
, RegAddr
, New_Value
);
851 phy_FwRFSerialWrite(dev
, eRFPath
, RegAddr
, Data
);
857 if (BitMask
!= bMask12Bits
) // RF data is 12 bits only
859 Original_Value
= rtl8192_phy_RFSerialRead(dev
, eRFPath
, RegAddr
);
860 BitShift
= rtl8192_CalculateBitShift(BitMask
);
861 New_Value
= (((Original_Value
) & (~BitMask
)) | (Data
<< BitShift
));
863 rtl8192_phy_RFSerialWrite(dev
, eRFPath
, RegAddr
, New_Value
);
865 rtl8192_phy_RFSerialWrite(dev
, eRFPath
, RegAddr
, Data
);
870 /******************************************************************************
871 *function: This function reads specific bits from RF register
872 * input: net_device dev
873 * u32 RegAddr //target addr to be readback
874 * u32 BitMask //taget bit pos in the addr to be readback
876 * return: u32 Data //the readback register value
878 * ****************************************************************************/
879 u32
rtl8192_phy_QueryRFReg(struct net_device
* dev
, RF90_RADIO_PATH_E eRFPath
, u32 RegAddr
, u32 BitMask
)
881 u32 Original_Value
, Readback_Value
, BitShift
;
882 struct r8192_priv
*priv
= ieee80211_priv(dev
);
883 if (!rtl8192_phy_CheckIsLegalRFPath(dev
, eRFPath
))
885 if(priv
->ieee80211
->eRFPowerState
!= eRfOn
&& !priv
->being_init_adapter
)
888 if (priv
->Rf_Mode
== RF_OP_By_FW
)
890 Original_Value
= phy_FwRFSerialRead(dev
, eRFPath
, RegAddr
);
895 Original_Value
= rtl8192_phy_RFSerialRead(dev
, eRFPath
, RegAddr
);
898 BitShift
= rtl8192_CalculateBitShift(BitMask
);
899 Readback_Value
= (Original_Value
& BitMask
) >> BitShift
;
902 return Readback_Value
;
905 /******************************************************************************
906 *function: We support firmware to execute RF-R/W.
911 * ***************************************************************************/
912 static u32
phy_FwRFSerialRead(
913 struct net_device
* dev
,
914 RF90_RADIO_PATH_E eRFPath
,
917 struct r8192_priv
*priv
= ieee80211_priv(dev
);
920 //DbgPrint("FW RF CTRL\n\r");
921 /* 2007/11/02 MH Firmware RF Write control. By Francis' suggestion, we can
922 not execute the scheme in the initial step. Otherwise, RF-R/W will waste
923 much time. This is only for site survey. */
924 // 1. Read operation need not insert data. bit 0-11
925 //Data &= bMask12Bits;
926 // 2. Write RF register address. Bit 12-19
927 Data
|= ((Offset
&0xFF)<<12);
928 // 3. Write RF path. bit 20-21
929 Data
|= ((eRFPath
&0x3)<<20);
930 // 4. Set RF read indicator. bit 22=0
932 // 5. Trigger Fw to operate the command. bit 31
934 // 6. We can not execute read operation if bit 31 is 1.
935 while (read_nic_dword(priv
, QPNR
)&0x80000000)
937 // If FW can not finish RF-R/W for more than ?? times. We must reset FW.
940 //DbgPrint("FW not finish RF-R Time=%d\n\r", time);
946 // 7. Execute read operation.
947 write_nic_dword(priv
, QPNR
, Data
);
948 // 8. Check if firmawre send back RF content.
949 while (read_nic_dword(priv
, QPNR
)&0x80000000)
951 // If FW can not finish RF-R/W for more than ?? times. We must reset FW.
954 //DbgPrint("FW not finish RF-W Time=%d\n\r", time);
960 return read_nic_dword(priv
, RF_DATA
);
963 /******************************************************************************
964 *function: We support firmware to execute RF-R/W.
969 * ***************************************************************************/
972 struct net_device
* dev
,
973 RF90_RADIO_PATH_E eRFPath
,
977 struct r8192_priv
*priv
= ieee80211_priv(dev
);
980 //DbgPrint("N FW RF CTRL RF-%d OF%02x DATA=%03x\n\r", eRFPath, Offset, Data);
981 /* 2007/11/02 MH Firmware RF Write control. By Francis' suggestion, we can
982 not execute the scheme in the initial step. Otherwise, RF-R/W will waste
983 much time. This is only for site survey. */
985 // 1. Set driver write bit and 12 bit data. bit 0-11
986 //Data &= bMask12Bits; // Done by uper layer.
987 // 2. Write RF register address. bit 12-19
988 Data
|= ((Offset
&0xFF)<<12);
989 // 3. Write RF path. bit 20-21
990 Data
|= ((eRFPath
&0x3)<<20);
991 // 4. Set RF write indicator. bit 22=1
993 // 5. Trigger Fw to operate the command. bit 31=1
996 // 6. Write operation. We can not write if bit 31 is 1.
997 while (read_nic_dword(priv
, QPNR
)&0x80000000)
999 // If FW can not finish RF-R/W for more than ?? times. We must reset FW.
1002 //DbgPrint("FW not finish RF-W Time=%d\n\r", time);
1008 // 7. No matter check bit. We always force the write. Because FW will
1009 // not accept the command.
1010 write_nic_dword(priv
, QPNR
, Data
);
1011 /* 2007/11/02 MH Acoording to test, we must delay 20us to wait firmware
1012 to finish RF write operation. */
1013 /* 2008/01/17 MH We support delay in firmware side now. */
1019 /******************************************************************************
1020 *function: This function read BB parameters from Header file we gen,
1021 * and do register read/write
1025 * notice: BB parameters may change all the time, so please make
1026 * sure it has been synced with the newest.
1027 * ***************************************************************************/
1028 void rtl8192_phy_configmac(struct net_device
* dev
)
1030 u32 dwArrayLen
= 0, i
= 0;
1031 u32
* pdwArray
= NULL
;
1032 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1034 if(Adapter
->bInHctTest
)
1036 RT_TRACE(COMP_PHY
, "Rtl819XMACPHY_ArrayDTM\n");
1037 dwArrayLen
= MACPHY_ArrayLengthDTM
;
1038 pdwArray
= Rtl819XMACPHY_ArrayDTM
;
1040 else if(priv
->bTXPowerDataReadFromEEPORM
)
1042 if(priv
->bTXPowerDataReadFromEEPORM
)
1044 RT_TRACE(COMP_PHY
, "Rtl819XMACPHY_Array_PG\n");
1045 dwArrayLen
= MACPHY_Array_PGLength
;
1046 pdwArray
= Rtl819XMACPHY_Array_PG
;
1051 RT_TRACE(COMP_PHY
,"Read rtl819XMACPHY_Array\n");
1052 dwArrayLen
= MACPHY_ArrayLength
;
1053 pdwArray
= Rtl819XMACPHY_Array
;
1055 for(i
= 0; i
<dwArrayLen
; i
=i
+3){
1056 RT_TRACE(COMP_DBG
, "The Rtl8190MACPHY_Array[0] is %x Rtl8190MACPHY_Array[1] is %x Rtl8190MACPHY_Array[2] is %x\n",
1057 pdwArray
[i
], pdwArray
[i
+1], pdwArray
[i
+2]);
1058 if(pdwArray
[i
] == 0x318)
1060 pdwArray
[i
+2] = 0x00000800;
1061 //DbgPrint("ptrArray[i], ptrArray[i+1], ptrArray[i+2] = %x, %x, %x\n",
1062 // ptrArray[i], ptrArray[i+1], ptrArray[i+2]);
1064 rtl8192_setBBreg(dev
, pdwArray
[i
], pdwArray
[i
+1], pdwArray
[i
+2]);
1068 /******************************************************************************
1069 *function: This function do dirty work
1073 * notice: BB parameters may change all the time, so please make
1074 * sure it has been synced with the newest.
1075 * ***************************************************************************/
1077 void rtl8192_phyConfigBB(struct net_device
* dev
, u8 ConfigType
)
1081 u32
* Rtl819XPHY_REGArray_Table
= NULL
;
1082 u32
* Rtl819XAGCTAB_Array_Table
= NULL
;
1083 u16 AGCTAB_ArrayLen
, PHY_REGArrayLen
= 0;
1084 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1086 u32
*rtl8192PhyRegArrayTable
= NULL
, *rtl8192AgcTabArrayTable
= NULL
;
1087 if(Adapter
->bInHctTest
)
1089 AGCTAB_ArrayLen
= AGCTAB_ArrayLengthDTM
;
1090 Rtl819XAGCTAB_Array_Table
= Rtl819XAGCTAB_ArrayDTM
;
1092 if(priv
->RF_Type
== RF_2T4R
)
1094 PHY_REGArrayLen
= PHY_REGArrayLengthDTM
;
1095 Rtl819XPHY_REGArray_Table
= Rtl819XPHY_REGArrayDTM
;
1097 else if (priv
->RF_Type
== RF_1T2R
)
1099 PHY_REGArrayLen
= PHY_REG_1T2RArrayLengthDTM
;
1100 Rtl819XPHY_REGArray_Table
= Rtl819XPHY_REG_1T2RArrayDTM
;
1106 AGCTAB_ArrayLen
= AGCTAB_ArrayLength
;
1107 Rtl819XAGCTAB_Array_Table
= Rtl819XAGCTAB_Array
;
1108 if(priv
->rf_type
== RF_2T4R
)
1110 PHY_REGArrayLen
= PHY_REGArrayLength
;
1111 Rtl819XPHY_REGArray_Table
= Rtl819XPHY_REGArray
;
1113 else if (priv
->rf_type
== RF_1T2R
)
1115 PHY_REGArrayLen
= PHY_REG_1T2RArrayLength
;
1116 Rtl819XPHY_REGArray_Table
= Rtl819XPHY_REG_1T2RArray
;
1120 if (ConfigType
== BaseBand_Config_PHY_REG
)
1122 for (i
=0; i
<PHY_REGArrayLen
; i
+=2)
1124 rtl8192_setBBreg(dev
, Rtl819XPHY_REGArray_Table
[i
], bMaskDWord
, Rtl819XPHY_REGArray_Table
[i
+1]);
1125 RT_TRACE(COMP_DBG
, "i: %x, The Rtl819xUsbPHY_REGArray[0] is %x Rtl819xUsbPHY_REGArray[1] is %x \n",i
, Rtl819XPHY_REGArray_Table
[i
], Rtl819XPHY_REGArray_Table
[i
+1]);
1128 else if (ConfigType
== BaseBand_Config_AGC_TAB
)
1130 for (i
=0; i
<AGCTAB_ArrayLen
; i
+=2)
1132 rtl8192_setBBreg(dev
, Rtl819XAGCTAB_Array_Table
[i
], bMaskDWord
, Rtl819XAGCTAB_Array_Table
[i
+1]);
1133 RT_TRACE(COMP_DBG
, "i:%x, The rtl819XAGCTAB_Array[0] is %x rtl819XAGCTAB_Array[1] is %x \n",i
, Rtl819XAGCTAB_Array_Table
[i
], Rtl819XAGCTAB_Array_Table
[i
+1]);
1137 /******************************************************************************
1138 *function: This function initialize Register definition offset for Radio Path
1140 * input: net_device dev
1143 * notice: Initialization value here is constant and it should never be changed
1144 * ***************************************************************************/
1145 static void rtl8192_InitBBRFRegDef(struct net_device
* dev
)
1147 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1148 // RF Interface Sowrtware Control
1149 priv
->PHYRegDef
[RF90_PATH_A
].rfintfs
= rFPGA0_XAB_RFInterfaceSW
; // 16 LSBs if read 32-bit from 0x870
1150 priv
->PHYRegDef
[RF90_PATH_B
].rfintfs
= rFPGA0_XAB_RFInterfaceSW
; // 16 MSBs if read 32-bit from 0x870 (16-bit for 0x872)
1151 priv
->PHYRegDef
[RF90_PATH_C
].rfintfs
= rFPGA0_XCD_RFInterfaceSW
;// 16 LSBs if read 32-bit from 0x874
1152 priv
->PHYRegDef
[RF90_PATH_D
].rfintfs
= rFPGA0_XCD_RFInterfaceSW
;// 16 MSBs if read 32-bit from 0x874 (16-bit for 0x876)
1154 // RF Interface Readback Value
1155 priv
->PHYRegDef
[RF90_PATH_A
].rfintfi
= rFPGA0_XAB_RFInterfaceRB
; // 16 LSBs if read 32-bit from 0x8E0
1156 priv
->PHYRegDef
[RF90_PATH_B
].rfintfi
= rFPGA0_XAB_RFInterfaceRB
;// 16 MSBs if read 32-bit from 0x8E0 (16-bit for 0x8E2)
1157 priv
->PHYRegDef
[RF90_PATH_C
].rfintfi
= rFPGA0_XCD_RFInterfaceRB
;// 16 LSBs if read 32-bit from 0x8E4
1158 priv
->PHYRegDef
[RF90_PATH_D
].rfintfi
= rFPGA0_XCD_RFInterfaceRB
;// 16 MSBs if read 32-bit from 0x8E4 (16-bit for 0x8E6)
1160 // RF Interface Output (and Enable)
1161 priv
->PHYRegDef
[RF90_PATH_A
].rfintfo
= rFPGA0_XA_RFInterfaceOE
; // 16 LSBs if read 32-bit from 0x860
1162 priv
->PHYRegDef
[RF90_PATH_B
].rfintfo
= rFPGA0_XB_RFInterfaceOE
; // 16 LSBs if read 32-bit from 0x864
1163 priv
->PHYRegDef
[RF90_PATH_C
].rfintfo
= rFPGA0_XC_RFInterfaceOE
;// 16 LSBs if read 32-bit from 0x868
1164 priv
->PHYRegDef
[RF90_PATH_D
].rfintfo
= rFPGA0_XD_RFInterfaceOE
;// 16 LSBs if read 32-bit from 0x86C
1166 // RF Interface (Output and) Enable
1167 priv
->PHYRegDef
[RF90_PATH_A
].rfintfe
= rFPGA0_XA_RFInterfaceOE
; // 16 MSBs if read 32-bit from 0x860 (16-bit for 0x862)
1168 priv
->PHYRegDef
[RF90_PATH_B
].rfintfe
= rFPGA0_XB_RFInterfaceOE
; // 16 MSBs if read 32-bit from 0x864 (16-bit for 0x866)
1169 priv
->PHYRegDef
[RF90_PATH_C
].rfintfe
= rFPGA0_XC_RFInterfaceOE
;// 16 MSBs if read 32-bit from 0x86A (16-bit for 0x86A)
1170 priv
->PHYRegDef
[RF90_PATH_D
].rfintfe
= rFPGA0_XD_RFInterfaceOE
;// 16 MSBs if read 32-bit from 0x86C (16-bit for 0x86E)
1172 //Addr of LSSI. Wirte RF register by driver
1173 priv
->PHYRegDef
[RF90_PATH_A
].rf3wireOffset
= rFPGA0_XA_LSSIParameter
; //LSSI Parameter
1174 priv
->PHYRegDef
[RF90_PATH_B
].rf3wireOffset
= rFPGA0_XB_LSSIParameter
;
1175 priv
->PHYRegDef
[RF90_PATH_C
].rf3wireOffset
= rFPGA0_XC_LSSIParameter
;
1176 priv
->PHYRegDef
[RF90_PATH_D
].rf3wireOffset
= rFPGA0_XD_LSSIParameter
;
1179 priv
->PHYRegDef
[RF90_PATH_A
].rfLSSI_Select
= rFPGA0_XAB_RFParameter
; //BB Band Select
1180 priv
->PHYRegDef
[RF90_PATH_B
].rfLSSI_Select
= rFPGA0_XAB_RFParameter
;
1181 priv
->PHYRegDef
[RF90_PATH_C
].rfLSSI_Select
= rFPGA0_XCD_RFParameter
;
1182 priv
->PHYRegDef
[RF90_PATH_D
].rfLSSI_Select
= rFPGA0_XCD_RFParameter
;
1184 // Tx AGC Gain Stage (same for all path. Should we remove this?)
1185 priv
->PHYRegDef
[RF90_PATH_A
].rfTxGainStage
= rFPGA0_TxGainStage
; //Tx gain stage
1186 priv
->PHYRegDef
[RF90_PATH_B
].rfTxGainStage
= rFPGA0_TxGainStage
; //Tx gain stage
1187 priv
->PHYRegDef
[RF90_PATH_C
].rfTxGainStage
= rFPGA0_TxGainStage
; //Tx gain stage
1188 priv
->PHYRegDef
[RF90_PATH_D
].rfTxGainStage
= rFPGA0_TxGainStage
; //Tx gain stage
1190 // Tranceiver A~D HSSI Parameter-1
1191 priv
->PHYRegDef
[RF90_PATH_A
].rfHSSIPara1
= rFPGA0_XA_HSSIParameter1
; //wire control parameter1
1192 priv
->PHYRegDef
[RF90_PATH_B
].rfHSSIPara1
= rFPGA0_XB_HSSIParameter1
; //wire control parameter1
1193 priv
->PHYRegDef
[RF90_PATH_C
].rfHSSIPara1
= rFPGA0_XC_HSSIParameter1
; //wire control parameter1
1194 priv
->PHYRegDef
[RF90_PATH_D
].rfHSSIPara1
= rFPGA0_XD_HSSIParameter1
; //wire control parameter1
1196 // Tranceiver A~D HSSI Parameter-2
1197 priv
->PHYRegDef
[RF90_PATH_A
].rfHSSIPara2
= rFPGA0_XA_HSSIParameter2
; //wire control parameter2
1198 priv
->PHYRegDef
[RF90_PATH_B
].rfHSSIPara2
= rFPGA0_XB_HSSIParameter2
; //wire control parameter2
1199 priv
->PHYRegDef
[RF90_PATH_C
].rfHSSIPara2
= rFPGA0_XC_HSSIParameter2
; //wire control parameter2
1200 priv
->PHYRegDef
[RF90_PATH_D
].rfHSSIPara2
= rFPGA0_XD_HSSIParameter2
; //wire control parameter1
1202 // RF switch Control
1203 priv
->PHYRegDef
[RF90_PATH_A
].rfSwitchControl
= rFPGA0_XAB_SwitchControl
; //TR/Ant switch control
1204 priv
->PHYRegDef
[RF90_PATH_B
].rfSwitchControl
= rFPGA0_XAB_SwitchControl
;
1205 priv
->PHYRegDef
[RF90_PATH_C
].rfSwitchControl
= rFPGA0_XCD_SwitchControl
;
1206 priv
->PHYRegDef
[RF90_PATH_D
].rfSwitchControl
= rFPGA0_XCD_SwitchControl
;
1209 priv
->PHYRegDef
[RF90_PATH_A
].rfAGCControl1
= rOFDM0_XAAGCCore1
;
1210 priv
->PHYRegDef
[RF90_PATH_B
].rfAGCControl1
= rOFDM0_XBAGCCore1
;
1211 priv
->PHYRegDef
[RF90_PATH_C
].rfAGCControl1
= rOFDM0_XCAGCCore1
;
1212 priv
->PHYRegDef
[RF90_PATH_D
].rfAGCControl1
= rOFDM0_XDAGCCore1
;
1215 priv
->PHYRegDef
[RF90_PATH_A
].rfAGCControl2
= rOFDM0_XAAGCCore2
;
1216 priv
->PHYRegDef
[RF90_PATH_B
].rfAGCControl2
= rOFDM0_XBAGCCore2
;
1217 priv
->PHYRegDef
[RF90_PATH_C
].rfAGCControl2
= rOFDM0_XCAGCCore2
;
1218 priv
->PHYRegDef
[RF90_PATH_D
].rfAGCControl2
= rOFDM0_XDAGCCore2
;
1221 priv
->PHYRegDef
[RF90_PATH_A
].rfRxIQImbalance
= rOFDM0_XARxIQImbalance
;
1222 priv
->PHYRegDef
[RF90_PATH_B
].rfRxIQImbalance
= rOFDM0_XBRxIQImbalance
;
1223 priv
->PHYRegDef
[RF90_PATH_C
].rfRxIQImbalance
= rOFDM0_XCRxIQImbalance
;
1224 priv
->PHYRegDef
[RF90_PATH_D
].rfRxIQImbalance
= rOFDM0_XDRxIQImbalance
;
1227 priv
->PHYRegDef
[RF90_PATH_A
].rfRxAFE
= rOFDM0_XARxAFE
;
1228 priv
->PHYRegDef
[RF90_PATH_B
].rfRxAFE
= rOFDM0_XBRxAFE
;
1229 priv
->PHYRegDef
[RF90_PATH_C
].rfRxAFE
= rOFDM0_XCRxAFE
;
1230 priv
->PHYRegDef
[RF90_PATH_D
].rfRxAFE
= rOFDM0_XDRxAFE
;
1233 priv
->PHYRegDef
[RF90_PATH_A
].rfTxIQImbalance
= rOFDM0_XATxIQImbalance
;
1234 priv
->PHYRegDef
[RF90_PATH_B
].rfTxIQImbalance
= rOFDM0_XBTxIQImbalance
;
1235 priv
->PHYRegDef
[RF90_PATH_C
].rfTxIQImbalance
= rOFDM0_XCTxIQImbalance
;
1236 priv
->PHYRegDef
[RF90_PATH_D
].rfTxIQImbalance
= rOFDM0_XDTxIQImbalance
;
1239 priv
->PHYRegDef
[RF90_PATH_A
].rfTxAFE
= rOFDM0_XATxAFE
;
1240 priv
->PHYRegDef
[RF90_PATH_B
].rfTxAFE
= rOFDM0_XBTxAFE
;
1241 priv
->PHYRegDef
[RF90_PATH_C
].rfTxAFE
= rOFDM0_XCTxAFE
;
1242 priv
->PHYRegDef
[RF90_PATH_D
].rfTxAFE
= rOFDM0_XDTxAFE
;
1244 // Tranceiver LSSI Readback
1245 priv
->PHYRegDef
[RF90_PATH_A
].rfLSSIReadBack
= rFPGA0_XA_LSSIReadBack
;
1246 priv
->PHYRegDef
[RF90_PATH_B
].rfLSSIReadBack
= rFPGA0_XB_LSSIReadBack
;
1247 priv
->PHYRegDef
[RF90_PATH_C
].rfLSSIReadBack
= rFPGA0_XC_LSSIReadBack
;
1248 priv
->PHYRegDef
[RF90_PATH_D
].rfLSSIReadBack
= rFPGA0_XD_LSSIReadBack
;
1251 /******************************************************************************
1252 *function: This function is to write register and then readback to make sure whether BB and RF is OK
1253 * input: net_device dev
1254 * HW90_BLOCK_E CheckBlock
1255 * RF90_RADIO_PATH_E eRFPath //only used when checkblock is HW90_BLOCK_RF
1257 * return: return whether BB and RF is ok(0:OK; 1:Fail)
1258 * notice: This function may be removed in the ASIC
1259 * ***************************************************************************/
1260 RT_STATUS
rtl8192_phy_checkBBAndRF(struct net_device
* dev
, HW90_BLOCK_E CheckBlock
, RF90_RADIO_PATH_E eRFPath
)
1262 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1263 // BB_REGISTER_DEFINITION_T *pPhyReg = &priv->PHYRegDef[eRFPath];
1264 RT_STATUS ret
= RT_STATUS_SUCCESS
;
1265 u32 i
, CheckTimes
= 4, dwRegRead
= 0;
1267 u32 WriteData
[] = {0xfffff027, 0xaa55a02f, 0x00000027, 0x55aa502f};
1268 // Initialize register address offset to be checked
1269 WriteAddr
[HW90_BLOCK_MAC
] = 0x100;
1270 WriteAddr
[HW90_BLOCK_PHY0
] = 0x900;
1271 WriteAddr
[HW90_BLOCK_PHY1
] = 0x800;
1272 WriteAddr
[HW90_BLOCK_RF
] = 0x3;
1273 RT_TRACE(COMP_PHY
, "=======>%s(), CheckBlock:%d\n", __FUNCTION__
, CheckBlock
);
1274 for(i
=0 ; i
< CheckTimes
; i
++)
1278 // Write Data to register and readback
1282 case HW90_BLOCK_MAC
:
1283 RT_TRACE(COMP_ERR
, "PHY_CheckBBRFOK(): Never Write 0x100 here!");
1286 case HW90_BLOCK_PHY0
:
1287 case HW90_BLOCK_PHY1
:
1288 write_nic_dword(priv
, WriteAddr
[CheckBlock
], WriteData
[i
]);
1289 dwRegRead
= read_nic_dword(priv
, WriteAddr
[CheckBlock
]);
1293 WriteData
[i
] &= 0xfff;
1294 rtl8192_phy_SetRFReg(dev
, eRFPath
, WriteAddr
[HW90_BLOCK_RF
], bMask12Bits
, WriteData
[i
]);
1295 // TODO: we should not delay for such a long time. Ask SD3
1297 dwRegRead
= rtl8192_phy_QueryRFReg(dev
, eRFPath
, WriteAddr
[HW90_BLOCK_RF
], bMaskDWord
);
1302 ret
= RT_STATUS_FAILURE
;
1308 // Check whether readback data is correct
1310 if(dwRegRead
!= WriteData
[i
])
1312 RT_TRACE(COMP_ERR
, "====>error=====dwRegRead: %x, WriteData: %x \n", dwRegRead
, WriteData
[i
]);
1313 ret
= RT_STATUS_FAILURE
;
1322 /******************************************************************************
1323 *function: This function initialize BB&RF
1324 * input: net_device dev
1327 * notice: Initialization value may change all the time, so please make
1328 * sure it has been synced with the newest.
1329 * ***************************************************************************/
1330 static RT_STATUS
rtl8192_BB_Config_ParaFile(struct net_device
* dev
)
1332 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1333 RT_STATUS rtStatus
= RT_STATUS_SUCCESS
;
1334 u8 bRegValue
= 0, eCheckItem
= 0;
1336 /**************************************
1337 //<1>Initialize BaseBand
1338 **************************************/
1340 /*--set BB Global Reset--*/
1341 bRegValue
= read_nic_byte(priv
, BB_GLOBAL_RESET
);
1342 write_nic_byte(priv
, BB_GLOBAL_RESET
,(bRegValue
|BB_GLOBAL_RESET_BIT
));
1344 /*---set BB reset Active---*/
1345 dwRegValue
= read_nic_dword(priv
, CPU_GEN
);
1346 write_nic_dword(priv
, CPU_GEN
, (dwRegValue
&(~CPU_GEN_BB_RST
)));
1348 /*----Ckeck FPGAPHY0 and PHY1 board is OK----*/
1349 // TODO: this function should be removed on ASIC , Emily 2007.2.2
1350 for(eCheckItem
=(HW90_BLOCK_E
)HW90_BLOCK_PHY0
; eCheckItem
<=HW90_BLOCK_PHY1
; eCheckItem
++)
1352 rtStatus
= rtl8192_phy_checkBBAndRF(dev
, (HW90_BLOCK_E
)eCheckItem
, (RF90_RADIO_PATH_E
)0); //don't care RF path
1353 if(rtStatus
!= RT_STATUS_SUCCESS
)
1355 RT_TRACE((COMP_ERR
| COMP_PHY
), "PHY_RF8256_Config():Check PHY%d Fail!!\n", eCheckItem
-1);
1359 /*---- Set CCK and OFDM Block "OFF"----*/
1360 rtl8192_setBBreg(dev
, rFPGA0_RFMOD
, bCCKEn
|bOFDMEn
, 0x0);
1361 /*----BB Register Initilazation----*/
1362 //==m==>Set PHY REG From Header<==m==
1363 rtl8192_phyConfigBB(dev
, BaseBand_Config_PHY_REG
);
1365 /*----Set BB reset de-Active----*/
1366 dwRegValue
= read_nic_dword(priv
, CPU_GEN
);
1367 write_nic_dword(priv
, CPU_GEN
, (dwRegValue
|CPU_GEN_BB_RST
));
1369 /*----BB AGC table Initialization----*/
1370 //==m==>Set PHY REG From Header<==m==
1371 rtl8192_phyConfigBB(dev
, BaseBand_Config_AGC_TAB
);
1373 if (priv
->card_8192_version
> VERSION_8190_BD
)
1375 if(priv
->rf_type
== RF_2T4R
)
1377 // Antenna gain offset from B/C/D to A
1378 dwRegValue
= ( priv
->AntennaTxPwDiff
[2]<<8 |
1379 priv
->AntennaTxPwDiff
[1]<<4 |
1380 priv
->AntennaTxPwDiff
[0]);
1383 dwRegValue
= 0x0; //Antenna gain offset doesn't make sense in RF 1T2R.
1384 rtl8192_setBBreg(dev
, rFPGA0_TxGainStage
,
1385 (bXBTxAGC
|bXCTxAGC
|bXDTxAGC
), dwRegValue
);
1389 dwRegValue
= priv
->CrystalCap
;
1390 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter1
, bXtalCap92x
, dwRegValue
);
1393 // Check if the CCK HighPower is turned ON.
1394 // This is used to calculate PWDB.
1395 // priv->bCckHighPower = (u8)(rtl8192_QueryBBReg(dev, rFPGA0_XA_HSSIParameter2, 0x200));
1398 /******************************************************************************
1399 *function: This function initialize BB&RF
1400 * input: net_device dev
1403 * notice: Initialization value may change all the time, so please make
1404 * sure it has been synced with the newest.
1405 * ***************************************************************************/
1406 RT_STATUS
rtl8192_BBConfig(struct net_device
* dev
)
1408 rtl8192_InitBBRFRegDef(dev
);
1409 //config BB&RF. As hardCode based initialization has not been well
1410 //implemented, so use file first.FIXME:should implement it for hardcode?
1411 return rtl8192_BB_Config_ParaFile(dev
);
1414 /******************************************************************************
1415 *function: This function obtains the initialization value of Tx power Level offset
1416 * input: net_device dev
1419 * ***************************************************************************/
1420 void rtl8192_phy_getTxPower(struct net_device
* dev
)
1422 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1424 priv
->MCSTxPowerLevelOriginalOffset
[0] =
1425 read_nic_dword(priv
, rTxAGC_Rate18_06
);
1426 priv
->MCSTxPowerLevelOriginalOffset
[1] =
1427 read_nic_dword(priv
, rTxAGC_Rate54_24
);
1428 priv
->MCSTxPowerLevelOriginalOffset
[2] =
1429 read_nic_dword(priv
, rTxAGC_Mcs03_Mcs00
);
1430 priv
->MCSTxPowerLevelOriginalOffset
[3] =
1431 read_nic_dword(priv
, rTxAGC_Mcs07_Mcs04
);
1432 priv
->MCSTxPowerLevelOriginalOffset
[4] =
1433 read_nic_dword(priv
, rTxAGC_Mcs11_Mcs08
);
1434 priv
->MCSTxPowerLevelOriginalOffset
[5] =
1435 read_nic_dword(priv
, rTxAGC_Mcs15_Mcs12
);
1437 // read rx initial gain
1438 priv
->DefaultInitialGain
[0] = read_nic_byte(priv
, rOFDM0_XAAGCCore1
);
1439 priv
->DefaultInitialGain
[1] = read_nic_byte(priv
, rOFDM0_XBAGCCore1
);
1440 priv
->DefaultInitialGain
[2] = read_nic_byte(priv
, rOFDM0_XCAGCCore1
);
1441 priv
->DefaultInitialGain
[3] = read_nic_byte(priv
, rOFDM0_XDAGCCore1
);
1442 RT_TRACE(COMP_INIT
, "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x) \n",
1443 priv
->DefaultInitialGain
[0], priv
->DefaultInitialGain
[1],
1444 priv
->DefaultInitialGain
[2], priv
->DefaultInitialGain
[3]);
1447 priv
->framesync
= read_nic_byte(priv
, rOFDM0_RxDetector3
);
1448 priv
->framesyncC34
= read_nic_dword(priv
, rOFDM0_RxDetector2
);
1449 RT_TRACE(COMP_INIT
, "Default framesync (0x%x) = 0x%x \n",
1450 rOFDM0_RxDetector3
, priv
->framesync
);
1451 // read SIFS (save the value read fome MACPHY_REG.txt)
1452 priv
->SifsTime
= read_nic_word(priv
, SIFS
);
1455 /******************************************************************************
1456 *function: This function obtains the initialization value of Tx power Level offset
1457 * input: net_device dev
1460 * ***************************************************************************/
1461 void rtl8192_phy_setTxPower(struct net_device
* dev
, u8 channel
)
1463 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1464 u8 powerlevel
= 0,powerlevelOFDM24G
= 0;
1468 if(priv
->epromtype
== EPROM_93c46
)
1470 powerlevel
= priv
->TxPowerLevelCCK
[channel
-1];
1471 powerlevelOFDM24G
= priv
->TxPowerLevelOFDM24G
[channel
-1];
1473 else if(priv
->epromtype
== EPROM_93c56
)
1475 if(priv
->rf_type
== RF_1T2R
)
1477 powerlevel
= priv
->TxPowerLevelCCK_C
[channel
-1];
1478 powerlevelOFDM24G
= priv
->TxPowerLevelOFDM24G_C
[channel
-1];
1480 else if(priv
->rf_type
== RF_2T4R
)
1482 // Mainly we use RF-A Tx Power to write the Tx Power registers, but the RF-C Tx
1483 // Power must be calculated by the antenna diff.
1484 // So we have to rewrite Antenna gain offset register here.
1485 powerlevel
= priv
->TxPowerLevelCCK_A
[channel
-1];
1486 powerlevelOFDM24G
= priv
->TxPowerLevelOFDM24G_A
[channel
-1];
1488 ant_pwr_diff
= priv
->TxPowerLevelOFDM24G_C
[channel
-1]
1489 -priv
->TxPowerLevelOFDM24G_A
[channel
-1];
1490 ant_pwr_diff
&= 0xf;
1491 //DbgPrint(" ant_pwr_diff = 0x%x", (u8)(ant_pwr_diff));
1492 priv
->RF_C_TxPwDiff
= ant_pwr_diff
;
1494 priv
->AntennaTxPwDiff
[2] = 0;// RF-D, don't care
1495 priv
->AntennaTxPwDiff
[1] = (u8
)(ant_pwr_diff
);// RF-C
1496 priv
->AntennaTxPwDiff
[0] = 0;// RF-B, don't care
1498 // Antenna gain offset from B/C/D to A
1499 u4RegValue
= ( priv
->AntennaTxPwDiff
[2]<<8 |
1500 priv
->AntennaTxPwDiff
[1]<<4 |
1501 priv
->AntennaTxPwDiff
[0]);
1503 rtl8192_setBBreg(dev
, rFPGA0_TxGainStage
,
1504 (bXBTxAGC
|bXCTxAGC
|bXDTxAGC
), u4RegValue
);
1509 // CCX 2 S31, AP control of client transmit power:
1510 // 1. We shall not exceed Cell Power Limit as possible as we can.
1511 // 2. Tolerance is +/- 5dB.
1512 // 3. 802.11h Power Contraint takes higher precedence over CCX Cell Power Limit.
1515 // 1. 802.11h power contraint
1517 // 071011, by rcnjko.
1519 if( pMgntInfo
->OpMode
== RT_OP_MODE_INFRASTRUCTURE
&&
1520 pMgntInfo
->bWithCcxCellPwr
&&
1521 channel
== pMgntInfo
->dot11CurrentChannelNumber
)
1523 u8 CckCellPwrIdx
= DbmToTxPwrIdx(Adapter
, WIRELESS_MODE_B
, pMgntInfo
->CcxCellPwr
);
1524 u8 LegacyOfdmCellPwrIdx
= DbmToTxPwrIdx(Adapter
, WIRELESS_MODE_G
, pMgntInfo
->CcxCellPwr
);
1525 u8 OfdmCellPwrIdx
= DbmToTxPwrIdx(Adapter
, WIRELESS_MODE_N_24G
, pMgntInfo
->CcxCellPwr
);
1527 RT_TRACE(COMP_TXAGC
, DBG_LOUD
,
1528 ("CCX Cell Limit: %d dbm => CCK Tx power index : %d, Legacy OFDM Tx power index : %d, OFDM Tx power index: %d\n",
1529 pMgntInfo
->CcxCellPwr
, CckCellPwrIdx
, LegacyOfdmCellPwrIdx
, OfdmCellPwrIdx
));
1530 RT_TRACE(COMP_TXAGC
, DBG_LOUD
,
1531 ("EEPROM channel(%d) => CCK Tx power index: %d, Legacy OFDM Tx power index : %d, OFDM Tx power index: %d\n",
1532 channel
, powerlevel
, powerlevelOFDM24G
+ pHalData
->LegacyHTTxPowerDiff
, powerlevelOFDM24G
));
1535 if(powerlevel
> CckCellPwrIdx
)
1536 powerlevel
= CckCellPwrIdx
;
1537 // Legacy OFDM, HT OFDM
1538 if(powerlevelOFDM24G
+ pHalData
->LegacyHTTxPowerDiff
> OfdmCellPwrIdx
)
1540 if((OfdmCellPwrIdx
- pHalData
->LegacyHTTxPowerDiff
) > 0)
1542 powerlevelOFDM24G
= OfdmCellPwrIdx
- pHalData
->LegacyHTTxPowerDiff
;
1546 LegacyOfdmCellPwrIdx
= 0;
1550 RT_TRACE(COMP_TXAGC
, DBG_LOUD
,
1551 ("Altered CCK Tx power index : %d, Legacy OFDM Tx power index: %d, OFDM Tx power index: %d\n",
1552 powerlevel
, powerlevelOFDM24G
+ pHalData
->LegacyHTTxPowerDiff
, powerlevelOFDM24G
));
1555 pHalData
->CurrentCckTxPwrIdx
= powerlevel
;
1556 pHalData
->CurrentOfdm24GTxPwrIdx
= powerlevelOFDM24G
;
1558 switch(priv
->rf_chip
)
1561 // PHY_SetRF8225CckTxPower(Adapter, powerlevel);
1562 // PHY_SetRF8225OfdmTxPower(Adapter, powerlevelOFDM24G);
1565 PHY_SetRF8256CCKTxPower(dev
, powerlevel
); //need further implement
1566 PHY_SetRF8256OFDMTxPower(dev
, powerlevelOFDM24G
);
1571 RT_TRACE(COMP_ERR
, "unknown rf chip in funtion %s()\n", __FUNCTION__
);
1576 /******************************************************************************
1577 *function: This function check Rf chip to do RF config
1578 * input: net_device dev
1580 * return: only 8256 is supported
1581 * ***************************************************************************/
1582 RT_STATUS
rtl8192_phy_RFConfig(struct net_device
* dev
)
1584 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1585 RT_STATUS rtStatus
= RT_STATUS_SUCCESS
;
1586 switch(priv
->rf_chip
)
1589 // rtStatus = PHY_RF8225_Config(Adapter);
1592 rtStatus
= PHY_RF8256_Config(dev
);
1598 //rtStatus = PHY_RF8225_Config(Adapter);
1602 RT_TRACE(COMP_ERR
, "error chip id\n");
1608 /******************************************************************************
1609 *function: This function update Initial gain
1610 * input: net_device dev
1612 * return: As Windows has not implemented this, wait for complement
1613 * ***************************************************************************/
1614 void rtl8192_phy_updateInitGain(struct net_device
* dev
)
1618 /******************************************************************************
1619 *function: This function read RF parameters from general head file, and do RF 3-wire
1620 * input: net_device dev
1622 * return: return code show if RF configuration is successful(0:pass, 1:fail)
1623 * Note: Delay may be required for RF configuration
1624 * ***************************************************************************/
1625 u8
rtl8192_phy_ConfigRFWithHeaderFile(struct net_device
* dev
, RF90_RADIO_PATH_E eRFPath
)
1634 for(i
= 0;i
<RadioA_ArrayLength
; i
=i
+2){
1636 if(Rtl819XRadioA_Array
[i
] == 0xfe){
1640 rtl8192_phy_SetRFReg(dev
, eRFPath
, Rtl819XRadioA_Array
[i
], bMask12Bits
, Rtl819XRadioA_Array
[i
+1]);
1646 for(i
= 0;i
<RadioB_ArrayLength
; i
=i
+2){
1648 if(Rtl819XRadioB_Array
[i
] == 0xfe){
1652 rtl8192_phy_SetRFReg(dev
, eRFPath
, Rtl819XRadioB_Array
[i
], bMask12Bits
, Rtl819XRadioB_Array
[i
+1]);
1658 for(i
= 0;i
<RadioC_ArrayLength
; i
=i
+2){
1660 if(Rtl819XRadioC_Array
[i
] == 0xfe){
1664 rtl8192_phy_SetRFReg(dev
, eRFPath
, Rtl819XRadioC_Array
[i
], bMask12Bits
, Rtl819XRadioC_Array
[i
+1]);
1670 for(i
= 0;i
<RadioD_ArrayLength
; i
=i
+2){
1672 if(Rtl819XRadioD_Array
[i
] == 0xfe){
1676 rtl8192_phy_SetRFReg(dev
, eRFPath
, Rtl819XRadioD_Array
[i
], bMask12Bits
, Rtl819XRadioD_Array
[i
+1]);
1688 /******************************************************************************
1689 *function: This function set Tx Power of the channel
1690 * input: struct net_device *dev
1695 * ***************************************************************************/
1696 static void rtl8192_SetTxPowerLevel(struct net_device
*dev
, u8 channel
)
1698 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1699 u8 powerlevel
= priv
->TxPowerLevelCCK
[channel
-1];
1700 u8 powerlevelOFDM24G
= priv
->TxPowerLevelOFDM24G
[channel
-1];
1702 switch(priv
->rf_chip
)
1706 PHY_SetRF8225CckTxPower(Adapter
, powerlevel
);
1707 PHY_SetRF8225OfdmTxPower(Adapter
, powerlevelOFDM24G
);
1712 PHY_SetRF8256CCKTxPower(dev
, powerlevel
);
1713 PHY_SetRF8256OFDMTxPower(dev
, powerlevelOFDM24G
);
1719 RT_TRACE(COMP_ERR
, "unknown rf chip ID in rtl8192_SetTxPowerLevel()\n");
1723 /****************************************************************************************
1724 *function: This function set command table variable(struct SwChnlCmd).
1725 * input: SwChnlCmd* CmdTable //table to be set.
1726 * u32 CmdTableIdx //variable index in table to be set
1727 * u32 CmdTableSz //table size.
1728 * SwChnlCmdID CmdID //command ID to set.
1733 * return: true if finished, false otherwise
1735 * ************************************************************************************/
1736 static u8
rtl8192_phy_SetSwChnlCmdArray(
1737 SwChnlCmd
* CmdTable
,
1748 if(CmdTable
== NULL
)
1750 RT_TRACE(COMP_ERR
, "phy_SetSwChnlCmdArray(): CmdTable cannot be NULL.\n");
1753 if(CmdTableIdx
>= CmdTableSz
)
1755 RT_TRACE(COMP_ERR
, "phy_SetSwChnlCmdArray(): Access invalid index, please check size of the table, CmdTableIdx:%d, CmdTableSz:%d\n",
1756 CmdTableIdx
, CmdTableSz
);
1760 pCmd
= CmdTable
+ CmdTableIdx
;
1761 pCmd
->CmdID
= CmdID
;
1762 pCmd
->Para1
= Para1
;
1763 pCmd
->Para2
= Para2
;
1764 pCmd
->msDelay
= msDelay
;
1768 /******************************************************************************
1769 *function: This function set channel step by step
1770 * input: struct net_device *dev
1772 * u8* stage //3 stages
1774 * u32* delay //whether need to delay
1775 * output: store new stage, step and delay for next step(combine with function above)
1776 * return: true if finished, false otherwise
1777 * Note: Wait for simpler function to replace it //wb
1778 * ***************************************************************************/
1779 static u8
rtl8192_phy_SwChnlStepByStep(struct net_device
*dev
, u8 channel
, u8
* stage
, u8
* step
, u32
* delay
)
1781 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1782 // PCHANNEL_ACCESS_SETTING pChnlAccessSetting;
1783 SwChnlCmd PreCommonCmd
[MAX_PRECMD_CNT
];
1784 u32 PreCommonCmdCnt
;
1785 SwChnlCmd PostCommonCmd
[MAX_POSTCMD_CNT
];
1786 u32 PostCommonCmdCnt
;
1787 SwChnlCmd RfDependCmd
[MAX_RFDEPENDCMD_CNT
];
1789 SwChnlCmd
*CurrentCmd
= NULL
;
1790 //RF90_RADIO_PATH_E eRFPath;
1795 RT_TRACE(COMP_TRACE
, "====>%s()====stage:%d, step:%d, channel:%d\n", __FUNCTION__
, *stage
, *step
, channel
);
1796 // RT_ASSERT(IsLegalChannel(Adapter, channel), ("illegal channel: %d\n", channel));
1798 #ifdef ENABLE_DOT11D
1799 if (!IsLegalChannel(priv
->ieee80211
, channel
))
1801 RT_TRACE(COMP_ERR
, "=============>set to illegal channel:%d\n", channel
);
1802 return true; //return true to tell upper caller function this channel setting is finished! Or it will in while loop.
1806 //for(eRFPath = RF90_PATH_A; eRFPath <pHalData->NumTotalRFPath; eRFPath++)
1807 //for(eRFPath = 0; eRFPath <RF90_PATH_MAX; eRFPath++)
1809 //if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
1811 // <1> Fill up pre common command.
1812 PreCommonCmdCnt
= 0;
1813 rtl8192_phy_SetSwChnlCmdArray(PreCommonCmd
, PreCommonCmdCnt
++, MAX_PRECMD_CNT
,
1814 CmdID_SetTxPowerLevel
, 0, 0, 0);
1815 rtl8192_phy_SetSwChnlCmdArray(PreCommonCmd
, PreCommonCmdCnt
++, MAX_PRECMD_CNT
,
1816 CmdID_End
, 0, 0, 0);
1818 // <2> Fill up post common command.
1819 PostCommonCmdCnt
= 0;
1821 rtl8192_phy_SetSwChnlCmdArray(PostCommonCmd
, PostCommonCmdCnt
++, MAX_POSTCMD_CNT
,
1822 CmdID_End
, 0, 0, 0);
1824 // <3> Fill up RF dependent command.
1826 switch( priv
->rf_chip
)
1829 if (!(channel
>= 1 && channel
<= 14))
1831 RT_TRACE(COMP_ERR
, "illegal channel for Zebra 8225: %d\n", channel
);
1834 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd
, RfDependCmdCnt
++, MAX_RFDEPENDCMD_CNT
,
1835 CmdID_RF_WriteReg
, rZebra1_Channel
, RF_CHANNEL_TABLE_ZEBRA
[channel
], 10);
1836 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd
, RfDependCmdCnt
++, MAX_RFDEPENDCMD_CNT
,
1837 CmdID_End
, 0, 0, 0);
1841 // TEST!! This is not the table for 8256!!
1842 if (!(channel
>= 1 && channel
<= 14))
1844 RT_TRACE(COMP_ERR
, "illegal channel for Zebra 8256: %d\n", channel
);
1847 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd
, RfDependCmdCnt
++, MAX_RFDEPENDCMD_CNT
,
1848 CmdID_RF_WriteReg
, rZebra1_Channel
, channel
, 10);
1849 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd
, RfDependCmdCnt
++, MAX_RFDEPENDCMD_CNT
,
1850 CmdID_End
, 0, 0, 0);
1857 RT_TRACE(COMP_ERR
, "Unknown RFChipID: %d\n", priv
->rf_chip
);
1867 CurrentCmd
=&PreCommonCmd
[*step
];
1870 CurrentCmd
=&RfDependCmd
[*step
];
1873 CurrentCmd
=&PostCommonCmd
[*step
];
1877 if(CurrentCmd
->CmdID
==CmdID_End
)
1891 switch(CurrentCmd
->CmdID
)
1893 case CmdID_SetTxPowerLevel
:
1894 if(priv
->card_8192_version
> (u8
)VERSION_8190_BD
) //xiong: consider it later!
1895 rtl8192_SetTxPowerLevel(dev
,channel
);
1897 case CmdID_WritePortUlong
:
1898 write_nic_dword(priv
, CurrentCmd
->Para1
, CurrentCmd
->Para2
);
1900 case CmdID_WritePortUshort
:
1901 write_nic_word(priv
, CurrentCmd
->Para1
, (u16
)CurrentCmd
->Para2
);
1903 case CmdID_WritePortUchar
:
1904 write_nic_byte(priv
, CurrentCmd
->Para1
, (u8
)CurrentCmd
->Para2
);
1906 case CmdID_RF_WriteReg
:
1907 for(eRFPath
= 0; eRFPath
<priv
->NumTotalRFPath
; eRFPath
++)
1908 rtl8192_phy_SetRFReg(dev
, (RF90_RADIO_PATH_E
)eRFPath
, CurrentCmd
->Para1
, bMask12Bits
, CurrentCmd
->Para2
<<7);
1916 }/*for(Number of RF paths)*/
1918 (*delay
)=CurrentCmd
->msDelay
;
1923 /******************************************************************************
1924 *function: This function does acturally set channel work
1925 * input: struct net_device *dev
1929 * Note: We should not call this function directly
1930 * ***************************************************************************/
1931 static void rtl8192_phy_FinishSwChnlNow(struct net_device
*dev
, u8 channel
)
1933 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1936 while(!rtl8192_phy_SwChnlStepByStep(dev
,channel
,&priv
->SwChnlStage
,&priv
->SwChnlStep
,&delay
))
1939 msleep(delay
);//or mdelay? need further consideration
1944 /******************************************************************************
1945 *function: Callback routine of the work item for switch channel.
1950 * ***************************************************************************/
1951 void rtl8192_SwChnl_WorkItem(struct net_device
*dev
)
1954 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1956 RT_TRACE(COMP_TRACE
, "==> SwChnlCallback819xUsbWorkItem()\n");
1958 RT_TRACE(COMP_TRACE
, "=====>--%s(), set chan:%d, priv:%p\n", __FUNCTION__
, priv
->chan
, priv
);
1960 rtl8192_phy_FinishSwChnlNow(dev
, priv
->chan
);
1962 RT_TRACE(COMP_TRACE
, "<== SwChnlCallback819xUsbWorkItem()\n");
1965 /******************************************************************************
1966 *function: This function scheduled actural workitem to set channel
1967 * input: net_device dev
1968 * u8 channel //channel to set
1970 * return: return code show if workitem is scheduled(1:pass, 0:fail)
1971 * Note: Delay may be required for RF configuration
1972 * ***************************************************************************/
1973 u8
rtl8192_phy_SwChnl(struct net_device
* dev
, u8 channel
)
1975 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1976 RT_TRACE(COMP_PHY
, "=====>%s()\n", __FUNCTION__
);
1979 if(priv
->SwChnlInProgress
)
1982 // if(pHalData->SetBWModeInProgress)
1985 //--------------------------------------------
1986 switch(priv
->ieee80211
->mode
)
1988 case WIRELESS_MODE_A
:
1989 case WIRELESS_MODE_N_5G
:
1991 RT_TRACE(COMP_ERR
, "WIRELESS_MODE_A but channel<=14");
1995 case WIRELESS_MODE_B
:
1997 RT_TRACE(COMP_ERR
, "WIRELESS_MODE_B but channel>14");
2001 case WIRELESS_MODE_G
:
2002 case WIRELESS_MODE_N_24G
:
2004 RT_TRACE(COMP_ERR
, "WIRELESS_MODE_G but channel>14");
2009 //--------------------------------------------
2011 priv
->SwChnlInProgress
= true;
2017 priv
->SwChnlStage
=0;
2019 // schedule_work(&(priv->SwChnlWorkItem));
2020 // rtl8192_SwChnl_WorkItem(dev);
2022 // queue_work(priv->priv_wq,&(priv->SwChnlWorkItem));
2023 rtl8192_SwChnl_WorkItem(dev
);
2025 priv
->SwChnlInProgress
= false;
2029 static void CCK_Tx_Power_Track_BW_Switch_TSSI(struct net_device
*dev
)
2031 struct r8192_priv
*priv
= ieee80211_priv(dev
);
2033 switch(priv
->CurrentChannelBW
)
2036 case HT_CHANNEL_WIDTH_20
:
2037 //added by vivi, cck,tx power track, 20080703
2038 priv
->CCKPresentAttentuation
=
2039 priv
->CCKPresentAttentuation_20Mdefault
+ priv
->CCKPresentAttentuation_difference
;
2041 if(priv
->CCKPresentAttentuation
> (CCKTxBBGainTableLength
-1))
2042 priv
->CCKPresentAttentuation
= CCKTxBBGainTableLength
-1;
2043 if(priv
->CCKPresentAttentuation
< 0)
2044 priv
->CCKPresentAttentuation
= 0;
2046 RT_TRACE(COMP_POWER_TRACKING
, "20M, priv->CCKPresentAttentuation = %d\n", priv
->CCKPresentAttentuation
);
2048 if(priv
->ieee80211
->current_network
.channel
== 14 && !priv
->bcck_in_ch14
)
2050 priv
->bcck_in_ch14
= TRUE
;
2051 dm_cck_txpower_adjust(dev
,priv
->bcck_in_ch14
);
2053 else if(priv
->ieee80211
->current_network
.channel
!= 14 && priv
->bcck_in_ch14
)
2055 priv
->bcck_in_ch14
= FALSE
;
2056 dm_cck_txpower_adjust(dev
,priv
->bcck_in_ch14
);
2059 dm_cck_txpower_adjust(dev
,priv
->bcck_in_ch14
);
2063 case HT_CHANNEL_WIDTH_20_40
:
2064 //added by vivi, cck,tx power track, 20080703
2065 priv
->CCKPresentAttentuation
=
2066 priv
->CCKPresentAttentuation_40Mdefault
+ priv
->CCKPresentAttentuation_difference
;
2068 RT_TRACE(COMP_POWER_TRACKING
, "40M, priv->CCKPresentAttentuation = %d\n", priv
->CCKPresentAttentuation
);
2069 if(priv
->CCKPresentAttentuation
> (CCKTxBBGainTableLength
-1))
2070 priv
->CCKPresentAttentuation
= CCKTxBBGainTableLength
-1;
2071 if(priv
->CCKPresentAttentuation
< 0)
2072 priv
->CCKPresentAttentuation
= 0;
2074 if(priv
->ieee80211
->current_network
.channel
== 14 && !priv
->bcck_in_ch14
)
2076 priv
->bcck_in_ch14
= TRUE
;
2077 dm_cck_txpower_adjust(dev
,priv
->bcck_in_ch14
);
2079 else if(priv
->ieee80211
->current_network
.channel
!= 14 && priv
->bcck_in_ch14
)
2081 priv
->bcck_in_ch14
= FALSE
;
2082 dm_cck_txpower_adjust(dev
,priv
->bcck_in_ch14
);
2085 dm_cck_txpower_adjust(dev
,priv
->bcck_in_ch14
);
2090 static void CCK_Tx_Power_Track_BW_Switch_ThermalMeter(struct net_device
*dev
)
2092 struct r8192_priv
*priv
= ieee80211_priv(dev
);
2094 if(priv
->ieee80211
->current_network
.channel
== 14 && !priv
->bcck_in_ch14
)
2095 priv
->bcck_in_ch14
= TRUE
;
2096 else if(priv
->ieee80211
->current_network
.channel
!= 14 && priv
->bcck_in_ch14
)
2097 priv
->bcck_in_ch14
= FALSE
;
2099 //write to default index and tx power track will be done in dm.
2100 switch(priv
->CurrentChannelBW
)
2103 case HT_CHANNEL_WIDTH_20
:
2104 if(priv
->Record_CCK_20Mindex
== 0)
2105 priv
->Record_CCK_20Mindex
= 6; //set default value.
2106 priv
->CCK_index
= priv
->Record_CCK_20Mindex
;//6;
2107 RT_TRACE(COMP_POWER_TRACKING
, "20MHz, CCK_Tx_Power_Track_BW_Switch_ThermalMeter(),CCK_index = %d\n", priv
->CCK_index
);
2111 case HT_CHANNEL_WIDTH_20_40
:
2112 priv
->CCK_index
= priv
->Record_CCK_40Mindex
;//0;
2113 RT_TRACE(COMP_POWER_TRACKING
, "40MHz, CCK_Tx_Power_Track_BW_Switch_ThermalMeter(), CCK_index = %d\n", priv
->CCK_index
);
2116 dm_cck_txpower_adjust(dev
, priv
->bcck_in_ch14
);
2119 static void CCK_Tx_Power_Track_BW_Switch(struct net_device
*dev
)
2121 struct r8192_priv
*priv
= ieee80211_priv(dev
);
2123 //if(pHalData->bDcut == TRUE)
2124 if(priv
->IC_Cut
>= IC_VersionCut_D
)
2125 CCK_Tx_Power_Track_BW_Switch_TSSI(dev
);
2127 CCK_Tx_Power_Track_BW_Switch_ThermalMeter(dev
);
2132 /******************************************************************************
2133 *function: Callback routine of the work item for set bandwidth mode.
2134 * input: struct net_device *dev
2135 * HT_CHANNEL_WIDTH Bandwidth //20M or 40M
2136 * HT_EXTCHNL_OFFSET Offset //Upper, Lower, or Don't care
2139 * Note: I doubt whether SetBWModeInProgress flag is necessary as we can
2140 * test whether current work in the queue or not.//do I?
2141 * ***************************************************************************/
2142 void rtl8192_SetBWModeWorkItem(struct net_device
*dev
)
2145 struct r8192_priv
*priv
= ieee80211_priv(dev
);
2148 RT_TRACE(COMP_SWBW
, "==>rtl8192_SetBWModeWorkItem() Switch to %s bandwidth\n",
2149 priv
->CurrentChannelBW
== HT_CHANNEL_WIDTH_20
?"20MHz":"40MHz")
2152 if(priv
->rf_chip
== RF_PSEUDO_11N
)
2154 priv
->SetBWModeInProgress
= false;
2159 priv
->SetBWModeInProgress
= false;
2162 //<1>Set MAC register
2163 regBwOpMode
= read_nic_byte(priv
, BW_OPMODE
);
2165 switch(priv
->CurrentChannelBW
)
2167 case HT_CHANNEL_WIDTH_20
:
2168 regBwOpMode
|= BW_OPMODE_20MHZ
;
2169 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
2170 write_nic_byte(priv
, BW_OPMODE
, regBwOpMode
);
2173 case HT_CHANNEL_WIDTH_20_40
:
2174 regBwOpMode
&= ~BW_OPMODE_20MHZ
;
2175 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
2176 write_nic_byte(priv
, BW_OPMODE
, regBwOpMode
);
2180 RT_TRACE(COMP_ERR
, "SetChannelBandwidth819xUsb(): unknown Bandwidth: %#X\n",priv
->CurrentChannelBW
);
2184 //<2>Set PHY related register
2185 switch(priv
->CurrentChannelBW
)
2187 case HT_CHANNEL_WIDTH_20
:
2188 // Add by Vivi 20071119
2189 rtl8192_setBBreg(dev
, rFPGA0_RFMOD
, bRFMOD
, 0x0);
2190 rtl8192_setBBreg(dev
, rFPGA1_RFMOD
, bRFMOD
, 0x0);
2191 // rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00100000, 1);
2193 // Correct the tx power for CCK rate in 20M. Suggest by YN, 20071207
2194 // write_nic_dword(dev, rCCK0_TxFilter1, 0x1a1b0000);
2195 // write_nic_dword(dev, rCCK0_TxFilter2, 0x090e1317);
2196 // write_nic_dword(dev, rCCK0_DebugPort, 0x00000204);
2197 if(!priv
->btxpower_tracking
)
2199 write_nic_dword(priv
, rCCK0_TxFilter1
, 0x1a1b0000);
2200 write_nic_dword(priv
, rCCK0_TxFilter2
, 0x090e1317);
2201 write_nic_dword(priv
, rCCK0_DebugPort
, 0x00000204);
2204 CCK_Tx_Power_Track_BW_Switch(dev
);
2206 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter1
, 0x00100000, 1);
2208 case HT_CHANNEL_WIDTH_20_40
:
2209 // Add by Vivi 20071119
2210 rtl8192_setBBreg(dev
, rFPGA0_RFMOD
, bRFMOD
, 0x1);
2211 rtl8192_setBBreg(dev
, rFPGA1_RFMOD
, bRFMOD
, 0x1);
2212 //rtl8192_setBBreg(dev, rCCK0_System, bCCKSideBand, (priv->nCur40MhzPrimeSC>>1));
2213 //rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00100000, 0);
2214 //rtl8192_setBBreg(dev, rOFDM1_LSTF, 0xC00, priv->nCur40MhzPrimeSC);
2216 // Correct the tx power for CCK rate in 40M. Suggest by YN, 20071207
2217 //write_nic_dword(dev, rCCK0_TxFilter1, 0x35360000);
2218 //write_nic_dword(dev, rCCK0_TxFilter2, 0x121c252e);
2219 //write_nic_dword(dev, rCCK0_DebugPort, 0x00000409);
2220 if(!priv
->btxpower_tracking
)
2222 write_nic_dword(priv
, rCCK0_TxFilter1
, 0x35360000);
2223 write_nic_dword(priv
, rCCK0_TxFilter2
, 0x121c252e);
2224 write_nic_dword(priv
, rCCK0_DebugPort
, 0x00000409);
2227 CCK_Tx_Power_Track_BW_Switch(dev
);
2229 // Set Control channel to upper or lower. These settings are required only for 40MHz
2230 rtl8192_setBBreg(dev
, rCCK0_System
, bCCKSideBand
, (priv
->nCur40MhzPrimeSC
>>1));
2231 rtl8192_setBBreg(dev
, rOFDM1_LSTF
, 0xC00, priv
->nCur40MhzPrimeSC
);
2234 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter1
, 0x00100000, 0);
2237 RT_TRACE(COMP_ERR
, "SetChannelBandwidth819xUsb(): unknown Bandwidth: %#X\n" ,priv
->CurrentChannelBW
);
2241 //Skip over setting of J-mode in BB register here. Default value is "None J mode". Emily 20070315
2243 //<3>Set RF related register
2244 switch( priv
->rf_chip
)
2248 PHY_SetRF8225Bandwidth(Adapter
, pHalData
->CurrentChannelBW
);
2253 PHY_SetRF8256Bandwidth(dev
, priv
->CurrentChannelBW
);
2257 // PHY_SetRF8258Bandwidth();
2265 RT_TRACE(COMP_ERR
, "Unknown RFChipID: %d\n", priv
->rf_chip
);
2269 atomic_dec(&(priv
->ieee80211
->atm_swbw
));
2270 priv
->SetBWModeInProgress
= false;
2272 RT_TRACE(COMP_SWBW
, "<==SetBWMode819xUsb()");
2275 /******************************************************************************
2276 *function: This function schedules bandwith switch work.
2277 * input: struct net_device *dev
2278 * HT_CHANNEL_WIDTH Bandwidth //20M or 40M
2279 * HT_EXTCHNL_OFFSET Offset //Upper, Lower, or Don't care
2282 * Note: I doubt whether SetBWModeInProgress flag is necessary as we can
2283 * test whether current work in the queue or not.//do I?
2284 * ***************************************************************************/
2285 void rtl8192_SetBWMode(struct net_device
*dev
, HT_CHANNEL_WIDTH Bandwidth
, HT_EXTCHNL_OFFSET Offset
)
2287 struct r8192_priv
*priv
= ieee80211_priv(dev
);
2290 if(priv
->SetBWModeInProgress
)
2293 atomic_inc(&(priv
->ieee80211
->atm_swbw
));
2294 priv
->SetBWModeInProgress
= true;
2296 priv
->CurrentChannelBW
= Bandwidth
;
2298 if(Offset
==HT_EXTCHNL_OFFSET_LOWER
)
2299 priv
->nCur40MhzPrimeSC
= HAL_PRIME_CHNL_OFFSET_UPPER
;
2300 else if(Offset
==HT_EXTCHNL_OFFSET_UPPER
)
2301 priv
->nCur40MhzPrimeSC
= HAL_PRIME_CHNL_OFFSET_LOWER
;
2303 priv
->nCur40MhzPrimeSC
= HAL_PRIME_CHNL_OFFSET_DONT_CARE
;
2305 //queue_work(priv->priv_wq, &(priv->SetBWModeWorkItem));
2306 // schedule_work(&(priv->SetBWModeWorkItem));
2307 rtl8192_SetBWModeWorkItem(dev
);
2312 void InitialGain819xPci(struct net_device
*dev
, u8 Operation
)
2314 #define SCAN_RX_INITIAL_GAIN 0x17
2315 #define POWER_DETECTION_TH 0x08
2316 struct r8192_priv
*priv
= ieee80211_priv(dev
);
2325 RT_TRACE(COMP_SCAN
, "IG_Backup, backup the initial gain.\n");
2326 initial_gain
= SCAN_RX_INITIAL_GAIN
;//pHalData->DefaultInitialGain[0];//
2327 BitMask
= bMaskByte0
;
2328 if(dm_digtable
.dig_algorithm
== DIG_ALGO_BY_FALSE_ALARM
)
2329 rtl8192_setBBreg(dev
, UFWP
, bMaskByte1
, 0x8); // FW DIG OFF
2330 priv
->initgain_backup
.xaagccore1
= (u8
)rtl8192_QueryBBReg(dev
, rOFDM0_XAAGCCore1
, BitMask
);
2331 priv
->initgain_backup
.xbagccore1
= (u8
)rtl8192_QueryBBReg(dev
, rOFDM0_XBAGCCore1
, BitMask
);
2332 priv
->initgain_backup
.xcagccore1
= (u8
)rtl8192_QueryBBReg(dev
, rOFDM0_XCAGCCore1
, BitMask
);
2333 priv
->initgain_backup
.xdagccore1
= (u8
)rtl8192_QueryBBReg(dev
, rOFDM0_XDAGCCore1
, BitMask
);
2334 BitMask
= bMaskByte2
;
2335 priv
->initgain_backup
.cca
= (u8
)rtl8192_QueryBBReg(dev
, rCCK0_CCA
, BitMask
);
2337 RT_TRACE(COMP_SCAN
, "Scan InitialGainBackup 0xc50 is %x\n",priv
->initgain_backup
.xaagccore1
);
2338 RT_TRACE(COMP_SCAN
, "Scan InitialGainBackup 0xc58 is %x\n",priv
->initgain_backup
.xbagccore1
);
2339 RT_TRACE(COMP_SCAN
, "Scan InitialGainBackup 0xc60 is %x\n",priv
->initgain_backup
.xcagccore1
);
2340 RT_TRACE(COMP_SCAN
, "Scan InitialGainBackup 0xc68 is %x\n",priv
->initgain_backup
.xdagccore1
);
2341 RT_TRACE(COMP_SCAN
, "Scan InitialGainBackup 0xa0a is %x\n",priv
->initgain_backup
.cca
);
2343 RT_TRACE(COMP_SCAN
, "Write scan initial gain = 0x%x \n", initial_gain
);
2344 write_nic_byte(priv
, rOFDM0_XAAGCCore1
, initial_gain
);
2345 write_nic_byte(priv
, rOFDM0_XBAGCCore1
, initial_gain
);
2346 write_nic_byte(priv
, rOFDM0_XCAGCCore1
, initial_gain
);
2347 write_nic_byte(priv
, rOFDM0_XDAGCCore1
, initial_gain
);
2348 RT_TRACE(COMP_SCAN
, "Write scan 0xa0a = 0x%x \n", POWER_DETECTION_TH
);
2349 write_nic_byte(priv
, 0xa0a, POWER_DETECTION_TH
);
2352 RT_TRACE(COMP_SCAN
, "IG_Restore, restore the initial gain.\n");
2353 BitMask
= 0x7f; //Bit0~ Bit6
2354 if(dm_digtable
.dig_algorithm
== DIG_ALGO_BY_FALSE_ALARM
)
2355 rtl8192_setBBreg(dev
, UFWP
, bMaskByte1
, 0x8); // FW DIG OFF
2357 rtl8192_setBBreg(dev
, rOFDM0_XAAGCCore1
, BitMask
, (u32
)priv
->initgain_backup
.xaagccore1
);
2358 rtl8192_setBBreg(dev
, rOFDM0_XBAGCCore1
, BitMask
, (u32
)priv
->initgain_backup
.xbagccore1
);
2359 rtl8192_setBBreg(dev
, rOFDM0_XCAGCCore1
, BitMask
, (u32
)priv
->initgain_backup
.xcagccore1
);
2360 rtl8192_setBBreg(dev
, rOFDM0_XDAGCCore1
, BitMask
, (u32
)priv
->initgain_backup
.xdagccore1
);
2361 BitMask
= bMaskByte2
;
2362 rtl8192_setBBreg(dev
, rCCK0_CCA
, BitMask
, (u32
)priv
->initgain_backup
.cca
);
2364 RT_TRACE(COMP_SCAN
, "Scan BBInitialGainRestore 0xc50 is %x\n",priv
->initgain_backup
.xaagccore1
);
2365 RT_TRACE(COMP_SCAN
, "Scan BBInitialGainRestore 0xc58 is %x\n",priv
->initgain_backup
.xbagccore1
);
2366 RT_TRACE(COMP_SCAN
, "Scan BBInitialGainRestore 0xc60 is %x\n",priv
->initgain_backup
.xcagccore1
);
2367 RT_TRACE(COMP_SCAN
, "Scan BBInitialGainRestore 0xc68 is %x\n",priv
->initgain_backup
.xdagccore1
);
2368 RT_TRACE(COMP_SCAN
, "Scan BBInitialGainRestore 0xa0a is %x\n",priv
->initgain_backup
.cca
);
2370 rtl8192_phy_setTxPower(dev
,priv
->ieee80211
->current_network
.channel
);
2373 if(dm_digtable
.dig_algorithm
== DIG_ALGO_BY_FALSE_ALARM
)
2374 rtl8192_setBBreg(dev
, UFWP
, bMaskByte1
, 0x1); // FW DIG ON
2377 RT_TRACE(COMP_SCAN
, "Unknown IG Operation. \n");