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 u32 Rtl8190PciMACPHY_Array[] = {
29 0x03c,0xffff0000,0x00000f0f,
30 0x340,0xffffffff,0x161a1a1a,
31 0x344,0xffffffff,0x12121416,
32 0x348,0x0000ffff,0x00001818,
33 0x12c,0xffffffff,0x04000802,
34 0x318,0x00000fff,0x00000800,
36 u32 Rtl8190PciMACPHY_Array_PG[] = {
37 0x03c,0xffff0000,0x00000f0f,
38 0x340,0xffffffff,0x0a0c0d0f,
39 0x344,0xffffffff,0x06070809,
40 0x344,0xffffffff,0x06070809,
41 0x348,0x0000ffff,0x00000000,
42 0x12c,0xffffffff,0x04000802,
43 0x318,0x00000fff,0x00000800,
46 u32 Rtl8190PciAGCTAB_Array[AGCTAB_ArrayLength] = {
241 u32 Rtl8190PciPHY_REGArray[PHY_REGArrayLength] = {
383 u32 Rtl8190PciPHY_REG_1T2RArray[PHY_REG_1T2RArrayLength] = {
526 u32 Rtl8190PciRadioA_Array[RadioA_ArrayLength] = {
651 u32 Rtl8190PciRadioB_Array[RadioB_ArrayLength] = {
692 u32 Rtl8190PciRadioC_Array[RadioC_ArrayLength] = {
817 u32 Rtl8190PciRadioD_Array[RadioD_ArrayLength] = {
860 static u32 Rtl8192PciEMACPHY_Array[] = {
861 0x03c,0xffff0000,0x00000f0f,
862 0x340,0xffffffff,0x161a1a1a,
863 0x344,0xffffffff,0x12121416,
864 0x348,0x0000ffff,0x00001818,
865 0x12c,0xffffffff,0x04000802,
866 0x318,0x00000fff,0x00000100,
868 static u32 Rtl8192PciEMACPHY_Array_PG[] = {
869 0x03c,0xffff0000,0x00000f0f,
870 0xe00,0xffffffff,0x06090909,
871 0xe04,0xffffffff,0x00030306,
872 0xe08,0x0000ff00,0x00000000,
873 0xe10,0xffffffff,0x0a0c0d0f,
874 0xe14,0xffffffff,0x06070809,
875 0xe18,0xffffffff,0x0a0c0d0f,
876 0xe1c,0xffffffff,0x06070809,
877 0x12c,0xffffffff,0x04000802,
878 0x318,0x00000fff,0x00000800,
880 static u32 Rtl8192PciEAGCTAB_Array[AGCTAB_ArrayLength] = {
1074 static u32 Rtl8192PciEPHY_REGArray[PHY_REGArrayLength] = {
1076 static u32 Rtl8192PciEPHY_REG_1T2RArray[PHY_REG_1T2RArrayLength] = {
1226 static u32 Rtl8192PciERadioA_Array[RadioA_ArrayLength] = {
1351 static u32 Rtl8192PciERadioB_Array[RadioB_ArrayLength] = {
1392 static u32 Rtl8192PciERadioC_Array[RadioC_ArrayLength] = {
1394 static u32 Rtl8192PciERadioD_Array[RadioD_ArrayLength] = {
1398 /*************************Define local function prototype**********************/
1400 static u32 phy_FwRFSerialRead(struct net_device* dev,RF90_RADIO_PATH_E eRFPath,u32 Offset);
1401 static void phy_FwRFSerialWrite(struct net_device* dev,RF90_RADIO_PATH_E eRFPath,u32 Offset,u32 Data);
1402 /*************************Define local function prototype**********************/
1403 /******************************************************************************
1404 *function: This function read BB parameters from Header file we gen,
1405 * and do register read/write
1406 * input: u32 dwBitMask //taget bit pos in the addr to be modified
1408 * return: u32 return the shift bit bit position of the mask
1409 * ****************************************************************************/
1410 static u32 rtl8192_CalculateBitShift(u32 dwBitMask)
1413 for (i=0; i<=31; i++)
1415 if (((dwBitMask>>i)&0x1) == 1)
1420 /******************************************************************************
1421 *function: This function check different RF type to execute legal judgement. If RF Path is illegal, we will return false.
1424 * return: 0(illegal, false), 1(legal,true)
1425 * ***************************************************************************/
1426 u8 rtl8192_phy_CheckIsLegalRFPath(struct net_device* dev, u32 eRFPath)
1429 struct r8192_priv *priv = ieee80211_priv(dev);
1431 if(priv->rf_type == RF_2T4R)
1435 else if (priv->rf_type == RF_1T2R)
1437 if(eRFPath == RF90_PATH_A || eRFPath == RF90_PATH_B)
1439 else if(eRFPath == RF90_PATH_C || eRFPath == RF90_PATH_D)
1444 if (priv->rf_type == RF_2T4R)
1446 else if (priv->rf_type == RF_1T2R)
1448 if (eRFPath == RF90_PATH_A || eRFPath == RF90_PATH_B)
1450 else if (eRFPath == RF90_PATH_C || eRFPath == RF90_PATH_D)
1457 /******************************************************************************
1458 *function: This function set specific bits to BB register
1459 * input: net_device dev
1460 * u32 dwRegAddr //target addr to be modified
1461 * u32 dwBitMask //taget bit pos in the addr to be modified
1462 * u32 dwData //value to be write
1466 * ****************************************************************************/
1467 void rtl8192_setBBreg(struct net_device* dev, u32 dwRegAddr, u32 dwBitMask, u32 dwData)
1469 struct r8192_priv *priv = ieee80211_priv(dev);
1470 u32 OriginalValue, BitShift, NewValue;
1472 if(dwBitMask!= bMaskDWord)
1473 {//if not "double word" write
1474 OriginalValue = read_nic_dword(priv, dwRegAddr);
1475 BitShift = rtl8192_CalculateBitShift(dwBitMask);
1476 NewValue = (((OriginalValue) & (~dwBitMask)) | (dwData << BitShift));
1477 write_nic_dword(priv, dwRegAddr, NewValue);
1479 write_nic_dword(priv, dwRegAddr, dwData);
1481 /******************************************************************************
1482 *function: This function reads specific bits from BB register
1483 * input: net_device dev
1484 * u32 dwRegAddr //target addr to be readback
1485 * u32 dwBitMask //taget bit pos in the addr to be readback
1487 * return: u32 Data //the readback register value
1489 * ****************************************************************************/
1490 u32 rtl8192_QueryBBReg(struct net_device* dev, u32 dwRegAddr, u32 dwBitMask)
1492 struct r8192_priv *priv = ieee80211_priv(dev);
1493 u32 OriginalValue, BitShift;
1495 OriginalValue = read_nic_dword(priv, dwRegAddr);
1496 BitShift = rtl8192_CalculateBitShift(dwBitMask);
1497 return (OriginalValue & dwBitMask) >> BitShift;
1499 /******************************************************************************
1500 *function: This function read register from RF chip
1501 * input: net_device dev
1502 * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D
1503 * u32 Offset //target address to be read
1505 * return: u32 readback value
1506 * 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.
1507 * ****************************************************************************/
1508 static u32 rtl8192_phy_RFSerialRead(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 Offset)
1510 struct r8192_priv *priv = ieee80211_priv(dev);
1513 BB_REGISTER_DEFINITION_T* pPhyReg = &priv->PHYRegDef[eRFPath];
1514 //rtl8192_setBBreg(dev, pPhyReg->rfLSSIReadBack, bLSSIReadBackData, 0);
1515 //make sure RF register offset is correct
1518 //switch page for 8256 RF IC
1519 if (priv->rf_chip == RF_8256)
1522 //analog to digital off, for protection
1523 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0xf00, 0x0);// 0x88c[11:8]
1526 //analog to digital off, for protection
1527 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0xf00, 0x0);// 0x88c[11:8]
1532 priv->RfReg0Value[eRFPath] |= 0x140;
1533 //Switch to Reg_Mode2 for Reg 31-45
1534 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, bMaskDWord, (priv->RfReg0Value[eRFPath]<<16) );
1536 NewOffset = Offset -30;
1538 else if (Offset >= 16)
1540 priv->RfReg0Value[eRFPath] |= 0x100;
1541 priv->RfReg0Value[eRFPath] &= (~0x40);
1542 //Switch to Reg_Mode 1 for Reg16-30
1543 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, bMaskDWord, (priv->RfReg0Value[eRFPath]<<16) );
1545 NewOffset = Offset - 15;
1552 RT_TRACE((COMP_PHY|COMP_ERR), "check RF type here, need to be 8256\n");
1555 //put desired read addr to LSSI control Register
1556 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadAddress, NewOffset);
1557 //Issue a posedge trigger
1559 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadEdge, 0x0);
1560 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadEdge, 0x1);
1563 // TODO: we should not delay such a long time. Ask help from SD3
1566 ret = rtl8192_QueryBBReg(dev, pPhyReg->rfLSSIReadBack, bLSSIReadBackData);
1569 // Switch back to Reg_Mode0;
1570 if(priv->rf_chip == RF_8256)
1572 priv->RfReg0Value[eRFPath] &= 0xebf;
1576 pPhyReg->rf3wireOffset,
1578 (priv->RfReg0Value[eRFPath] << 16));
1581 if(priv->rf_type == RF_2T4R)
1583 //analog to digital on
1584 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0xf00, 0xf);// 0x88c[11:8]
1586 else if(priv->rf_type == RF_1T2R)
1588 //analog to digital on
1589 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0xc00, 0x3);// 0x88c[11:10]
1593 //analog to digital on
1594 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0x300, 0x3);// 0x88c[9:8]
1604 /******************************************************************************
1605 *function: This function write data to RF register
1606 * input: net_device dev
1607 * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D
1608 * u32 Offset //target address to be written
1609 * u32 Data //The new register data to be written
1612 * notice: For RF8256 only.
1613 ===========================================================
1614 *Reg Mode RegCTL[1] RegCTL[0] Note
1615 * (Reg00[12]) (Reg00[10])
1616 *===========================================================
1617 *Reg_Mode0 0 x Reg 0 ~15(0x0 ~ 0xf)
1618 *------------------------------------------------------------------
1619 *Reg_Mode1 1 0 Reg 16 ~30(0x1 ~ 0xf)
1620 *------------------------------------------------------------------
1621 * Reg_Mode2 1 1 Reg 31 ~ 45(0x1 ~ 0xf)
1622 *------------------------------------------------------------------
1623 * ****************************************************************************/
1624 static void rtl8192_phy_RFSerialWrite(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 Offset, u32 Data)
1626 struct r8192_priv *priv = ieee80211_priv(dev);
1627 u32 DataAndAddr = 0, NewOffset = 0;
1628 BB_REGISTER_DEFINITION_T *pPhyReg = &priv->PHYRegDef[eRFPath];
1631 if (priv->rf_chip == RF_8256)
1635 //analog to digital off, for protection
1636 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0xf00, 0x0);// 0x88c[11:8]
1639 //analog to digital off, for protection
1640 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0xf00, 0x0);// 0x88c[11:8]
1646 priv->RfReg0Value[eRFPath] |= 0x140;
1647 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, bMaskDWord, (priv->RfReg0Value[eRFPath] << 16));
1648 NewOffset = Offset - 30;
1650 else if (Offset >= 16)
1652 priv->RfReg0Value[eRFPath] |= 0x100;
1653 priv->RfReg0Value[eRFPath] &= (~0x40);
1654 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, bMaskDWord, (priv->RfReg0Value[eRFPath]<<16));
1655 NewOffset = Offset - 15;
1662 RT_TRACE((COMP_PHY|COMP_ERR), "check RF type here, need to be 8256\n");
1666 // Put write addr in [5:0] and write data in [31:16]
1667 DataAndAddr = (Data<<16) | (NewOffset&0x3f);
1670 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, bMaskDWord, DataAndAddr);
1674 priv->RfReg0Value[eRFPath] = Data;
1676 // Switch back to Reg_Mode0;
1677 if(priv->rf_chip == RF_8256)
1681 priv->RfReg0Value[eRFPath] &= 0xebf;
1684 pPhyReg->rf3wireOffset,
1686 (priv->RfReg0Value[eRFPath] << 16));
1689 if(priv->rf_type == RF_2T4R)
1691 //analog to digital on
1692 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0xf00, 0xf);// 0x88c[11:8]
1694 else if(priv->rf_type == RF_1T2R)
1696 //analog to digital on
1697 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0xc00, 0x3);// 0x88c[11:10]
1701 //analog to digital on
1702 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0x300, 0x3);// 0x88c[9:8]
1708 /******************************************************************************
1709 *function: This function set specific bits to RF register
1710 * input: net_device dev
1711 * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D
1712 * u32 RegAddr //target addr to be modified
1713 * u32 BitMask //taget bit pos in the addr to be modified
1714 * u32 Data //value to be write
1718 * ****************************************************************************/
1719 void rtl8192_phy_SetRFReg(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
1721 struct r8192_priv *priv = ieee80211_priv(dev);
1722 u32 Original_Value, BitShift, New_Value;
1725 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
1728 if(priv->ieee80211->eRFPowerState != eRfOn && !priv->being_init_adapter)
1731 //down(&priv->rf_sem);
1733 RT_TRACE(COMP_PHY, "FW RF CTRL is not ready now\n");
1734 if (priv->Rf_Mode == RF_OP_By_FW)
1736 if (BitMask != bMask12Bits) // RF data is 12 bits only
1738 Original_Value = phy_FwRFSerialRead(dev, eRFPath, RegAddr);
1739 BitShift = rtl8192_CalculateBitShift(BitMask);
1740 New_Value = (((Original_Value) & (~BitMask)) | (Data<< BitShift));
1742 phy_FwRFSerialWrite(dev, eRFPath, RegAddr, New_Value);
1744 phy_FwRFSerialWrite(dev, eRFPath, RegAddr, Data);
1750 if (BitMask != bMask12Bits) // RF data is 12 bits only
1752 Original_Value = rtl8192_phy_RFSerialRead(dev, eRFPath, RegAddr);
1753 BitShift = rtl8192_CalculateBitShift(BitMask);
1754 New_Value = (((Original_Value) & (~BitMask)) | (Data<< BitShift));
1756 rtl8192_phy_RFSerialWrite(dev, eRFPath, RegAddr, New_Value);
1758 rtl8192_phy_RFSerialWrite(dev, eRFPath, RegAddr, Data);
1760 //up(&priv->rf_sem);
1763 /******************************************************************************
1764 *function: This function reads specific bits from RF register
1765 * input: net_device dev
1766 * u32 RegAddr //target addr to be readback
1767 * u32 BitMask //taget bit pos in the addr to be readback
1769 * return: u32 Data //the readback register value
1771 * ****************************************************************************/
1772 u32 rtl8192_phy_QueryRFReg(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 RegAddr, u32 BitMask)
1774 u32 Original_Value, Readback_Value, BitShift;
1775 struct r8192_priv *priv = ieee80211_priv(dev);
1776 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
1779 if(priv->ieee80211->eRFPowerState != eRfOn && !priv->being_init_adapter)
1782 down(&priv->rf_sem);
1783 if (priv->Rf_Mode == RF_OP_By_FW)
1785 Original_Value = phy_FwRFSerialRead(dev, eRFPath, RegAddr);
1790 Original_Value = rtl8192_phy_RFSerialRead(dev, eRFPath, RegAddr);
1793 BitShift = rtl8192_CalculateBitShift(BitMask);
1794 Readback_Value = (Original_Value & BitMask) >> BitShift;
1797 return Readback_Value;
1800 /******************************************************************************
1801 *function: We support firmware to execute RF-R/W.
1806 * ***************************************************************************/
1807 static u32 phy_FwRFSerialRead(
1808 struct net_device* dev,
1809 RF90_RADIO_PATH_E eRFPath,
1812 struct r8192_priv *priv = ieee80211_priv(dev);
1815 //DbgPrint("FW RF CTRL\n\r");
1816 /* 2007/11/02 MH Firmware RF Write control. By Francis' suggestion, we can
1817 not execute the scheme in the initial step. Otherwise, RF-R/W will waste
1818 much time. This is only for site survey. */
1819 // 1. Read operation need not insert data. bit 0-11
1820 //Data &= bMask12Bits;
1821 // 2. Write RF register address. Bit 12-19
1822 Data |= ((Offset&0xFF)<<12);
1823 // 3. Write RF path. bit 20-21
1824 Data |= ((eRFPath&0x3)<<20);
1825 // 4. Set RF read indicator. bit 22=0
1827 // 5. Trigger Fw to operate the command. bit 31
1829 // 6. We can not execute read operation if bit 31 is 1.
1830 while (read_nic_dword(priv, QPNR)&0x80000000)
1832 // If FW can not finish RF-R/W for more than ?? times. We must reset FW.
1835 //DbgPrint("FW not finish RF-R Time=%d\n\r", time);
1841 // 7. Execute read operation.
1842 write_nic_dword(priv, QPNR, Data);
1843 // 8. Check if firmawre send back RF content.
1844 while (read_nic_dword(priv, QPNR)&0x80000000)
1846 // If FW can not finish RF-R/W for more than ?? times. We must reset FW.
1849 //DbgPrint("FW not finish RF-W Time=%d\n\r", time);
1855 return read_nic_dword(priv, RF_DATA);
1858 /******************************************************************************
1859 *function: We support firmware to execute RF-R/W.
1864 * ***************************************************************************/
1866 phy_FwRFSerialWrite(
1867 struct net_device* dev,
1868 RF90_RADIO_PATH_E eRFPath,
1872 struct r8192_priv *priv = ieee80211_priv(dev);
1875 //DbgPrint("N FW RF CTRL RF-%d OF%02x DATA=%03x\n\r", eRFPath, Offset, Data);
1876 /* 2007/11/02 MH Firmware RF Write control. By Francis' suggestion, we can
1877 not execute the scheme in the initial step. Otherwise, RF-R/W will waste
1878 much time. This is only for site survey. */
1880 // 1. Set driver write bit and 12 bit data. bit 0-11
1881 //Data &= bMask12Bits; // Done by uper layer.
1882 // 2. Write RF register address. bit 12-19
1883 Data |= ((Offset&0xFF)<<12);
1884 // 3. Write RF path. bit 20-21
1885 Data |= ((eRFPath&0x3)<<20);
1886 // 4. Set RF write indicator. bit 22=1
1888 // 5. Trigger Fw to operate the command. bit 31=1
1891 // 6. Write operation. We can not write if bit 31 is 1.
1892 while (read_nic_dword(priv, QPNR)&0x80000000)
1894 // If FW can not finish RF-R/W for more than ?? times. We must reset FW.
1897 //DbgPrint("FW not finish RF-W Time=%d\n\r", time);
1903 // 7. No matter check bit. We always force the write. Because FW will
1904 // not accept the command.
1905 write_nic_dword(priv, QPNR, Data);
1906 /* 2007/11/02 MH Acoording to test, we must delay 20us to wait firmware
1907 to finish RF write operation. */
1908 /* 2008/01/17 MH We support delay in firmware side now. */
1914 /******************************************************************************
1915 *function: This function read BB parameters from Header file we gen,
1916 * and do register read/write
1920 * notice: BB parameters may change all the time, so please make
1921 * sure it has been synced with the newest.
1922 * ***************************************************************************/
1923 void rtl8192_phy_configmac(struct net_device* dev)
1925 u32 dwArrayLen = 0, i = 0;
1926 u32* pdwArray = NULL;
1927 struct r8192_priv *priv = ieee80211_priv(dev);
1929 if(Adapter->bInHctTest)
1931 RT_TRACE(COMP_PHY, "Rtl819XMACPHY_ArrayDTM\n");
1932 dwArrayLen = MACPHY_ArrayLengthDTM;
1933 pdwArray = Rtl819XMACPHY_ArrayDTM;
1935 else if(priv->bTXPowerDataReadFromEEPORM)
1937 if(priv->bTXPowerDataReadFromEEPORM)
1939 RT_TRACE(COMP_PHY, "Rtl819XMACPHY_Array_PG\n");
1940 dwArrayLen = MACPHY_Array_PGLength;
1941 pdwArray = Rtl819XMACPHY_Array_PG;
1946 RT_TRACE(COMP_PHY,"Read rtl819XMACPHY_Array\n");
1947 dwArrayLen = MACPHY_ArrayLength;
1948 pdwArray = Rtl819XMACPHY_Array;
1950 for(i = 0; i<dwArrayLen; i=i+3){
1951 RT_TRACE(COMP_DBG, "The Rtl8190MACPHY_Array[0] is %x Rtl8190MACPHY_Array[1] is %x Rtl8190MACPHY_Array[2] is %x\n",
1952 pdwArray[i], pdwArray[i+1], pdwArray[i+2]);
1953 if(pdwArray[i] == 0x318)
1955 pdwArray[i+2] = 0x00000800;
1956 //DbgPrint("ptrArray[i], ptrArray[i+1], ptrArray[i+2] = %x, %x, %x\n",
1957 // ptrArray[i], ptrArray[i+1], ptrArray[i+2]);
1959 rtl8192_setBBreg(dev, pdwArray[i], pdwArray[i+1], pdwArray[i+2]);
1963 /******************************************************************************
1964 *function: This function do dirty work
1968 * notice: BB parameters may change all the time, so please make
1969 * sure it has been synced with the newest.
1970 * ***************************************************************************/
1972 void rtl8192_phyConfigBB(struct net_device* dev, u8 ConfigType)
1976 u32* Rtl819XPHY_REGArray_Table = NULL;
1977 u32* Rtl819XAGCTAB_Array_Table = NULL;
1978 u16 AGCTAB_ArrayLen, PHY_REGArrayLen = 0;
1979 struct r8192_priv *priv = ieee80211_priv(dev);
1981 u32 *rtl8192PhyRegArrayTable = NULL, *rtl8192AgcTabArrayTable = NULL;
1982 if(Adapter->bInHctTest)
1984 AGCTAB_ArrayLen = AGCTAB_ArrayLengthDTM;
1985 Rtl819XAGCTAB_Array_Table = Rtl819XAGCTAB_ArrayDTM;
1987 if(priv->RF_Type == RF_2T4R)
1989 PHY_REGArrayLen = PHY_REGArrayLengthDTM;
1990 Rtl819XPHY_REGArray_Table = Rtl819XPHY_REGArrayDTM;
1992 else if (priv->RF_Type == RF_1T2R)
1994 PHY_REGArrayLen = PHY_REG_1T2RArrayLengthDTM;
1995 Rtl819XPHY_REGArray_Table = Rtl819XPHY_REG_1T2RArrayDTM;
2001 AGCTAB_ArrayLen = AGCTAB_ArrayLength;
2002 Rtl819XAGCTAB_Array_Table = Rtl819XAGCTAB_Array;
2003 if(priv->rf_type == RF_2T4R)
2005 PHY_REGArrayLen = PHY_REGArrayLength;
2006 Rtl819XPHY_REGArray_Table = Rtl819XPHY_REGArray;
2008 else if (priv->rf_type == RF_1T2R)
2010 PHY_REGArrayLen = PHY_REG_1T2RArrayLength;
2011 Rtl819XPHY_REGArray_Table = Rtl819XPHY_REG_1T2RArray;
2015 if (ConfigType == BaseBand_Config_PHY_REG)
2017 for (i=0; i<PHY_REGArrayLen; i+=2)
2019 rtl8192_setBBreg(dev, Rtl819XPHY_REGArray_Table[i], bMaskDWord, Rtl819XPHY_REGArray_Table[i+1]);
2020 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]);
2023 else if (ConfigType == BaseBand_Config_AGC_TAB)
2025 for (i=0; i<AGCTAB_ArrayLen; i+=2)
2027 rtl8192_setBBreg(dev, Rtl819XAGCTAB_Array_Table[i], bMaskDWord, Rtl819XAGCTAB_Array_Table[i+1]);
2028 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]);
2032 /******************************************************************************
2033 *function: This function initialize Register definition offset for Radio Path
2035 * input: net_device dev
2038 * notice: Initialization value here is constant and it should never be changed
2039 * ***************************************************************************/
2040 static void rtl8192_InitBBRFRegDef(struct net_device* dev)
2042 struct r8192_priv *priv = ieee80211_priv(dev);
2043 // RF Interface Sowrtware Control
2044 priv->PHYRegDef[RF90_PATH_A].rfintfs = rFPGA0_XAB_RFInterfaceSW; // 16 LSBs if read 32-bit from 0x870
2045 priv->PHYRegDef[RF90_PATH_B].rfintfs = rFPGA0_XAB_RFInterfaceSW; // 16 MSBs if read 32-bit from 0x870 (16-bit for 0x872)
2046 priv->PHYRegDef[RF90_PATH_C].rfintfs = rFPGA0_XCD_RFInterfaceSW;// 16 LSBs if read 32-bit from 0x874
2047 priv->PHYRegDef[RF90_PATH_D].rfintfs = rFPGA0_XCD_RFInterfaceSW;// 16 MSBs if read 32-bit from 0x874 (16-bit for 0x876)
2049 // RF Interface Readback Value
2050 priv->PHYRegDef[RF90_PATH_A].rfintfi = rFPGA0_XAB_RFInterfaceRB; // 16 LSBs if read 32-bit from 0x8E0
2051 priv->PHYRegDef[RF90_PATH_B].rfintfi = rFPGA0_XAB_RFInterfaceRB;// 16 MSBs if read 32-bit from 0x8E0 (16-bit for 0x8E2)
2052 priv->PHYRegDef[RF90_PATH_C].rfintfi = rFPGA0_XCD_RFInterfaceRB;// 16 LSBs if read 32-bit from 0x8E4
2053 priv->PHYRegDef[RF90_PATH_D].rfintfi = rFPGA0_XCD_RFInterfaceRB;// 16 MSBs if read 32-bit from 0x8E4 (16-bit for 0x8E6)
2055 // RF Interface Output (and Enable)
2056 priv->PHYRegDef[RF90_PATH_A].rfintfo = rFPGA0_XA_RFInterfaceOE; // 16 LSBs if read 32-bit from 0x860
2057 priv->PHYRegDef[RF90_PATH_B].rfintfo = rFPGA0_XB_RFInterfaceOE; // 16 LSBs if read 32-bit from 0x864
2058 priv->PHYRegDef[RF90_PATH_C].rfintfo = rFPGA0_XC_RFInterfaceOE;// 16 LSBs if read 32-bit from 0x868
2059 priv->PHYRegDef[RF90_PATH_D].rfintfo = rFPGA0_XD_RFInterfaceOE;// 16 LSBs if read 32-bit from 0x86C
2061 // RF Interface (Output and) Enable
2062 priv->PHYRegDef[RF90_PATH_A].rfintfe = rFPGA0_XA_RFInterfaceOE; // 16 MSBs if read 32-bit from 0x860 (16-bit for 0x862)
2063 priv->PHYRegDef[RF90_PATH_B].rfintfe = rFPGA0_XB_RFInterfaceOE; // 16 MSBs if read 32-bit from 0x864 (16-bit for 0x866)
2064 priv->PHYRegDef[RF90_PATH_C].rfintfe = rFPGA0_XC_RFInterfaceOE;// 16 MSBs if read 32-bit from 0x86A (16-bit for 0x86A)
2065 priv->PHYRegDef[RF90_PATH_D].rfintfe = rFPGA0_XD_RFInterfaceOE;// 16 MSBs if read 32-bit from 0x86C (16-bit for 0x86E)
2067 //Addr of LSSI. Wirte RF register by driver
2068 priv->PHYRegDef[RF90_PATH_A].rf3wireOffset = rFPGA0_XA_LSSIParameter; //LSSI Parameter
2069 priv->PHYRegDef[RF90_PATH_B].rf3wireOffset = rFPGA0_XB_LSSIParameter;
2070 priv->PHYRegDef[RF90_PATH_C].rf3wireOffset = rFPGA0_XC_LSSIParameter;
2071 priv->PHYRegDef[RF90_PATH_D].rf3wireOffset = rFPGA0_XD_LSSIParameter;
2074 priv->PHYRegDef[RF90_PATH_A].rfLSSI_Select = rFPGA0_XAB_RFParameter; //BB Band Select
2075 priv->PHYRegDef[RF90_PATH_B].rfLSSI_Select = rFPGA0_XAB_RFParameter;
2076 priv->PHYRegDef[RF90_PATH_C].rfLSSI_Select = rFPGA0_XCD_RFParameter;
2077 priv->PHYRegDef[RF90_PATH_D].rfLSSI_Select = rFPGA0_XCD_RFParameter;
2079 // Tx AGC Gain Stage (same for all path. Should we remove this?)
2080 priv->PHYRegDef[RF90_PATH_A].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
2081 priv->PHYRegDef[RF90_PATH_B].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
2082 priv->PHYRegDef[RF90_PATH_C].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
2083 priv->PHYRegDef[RF90_PATH_D].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
2085 // Tranceiver A~D HSSI Parameter-1
2086 priv->PHYRegDef[RF90_PATH_A].rfHSSIPara1 = rFPGA0_XA_HSSIParameter1; //wire control parameter1
2087 priv->PHYRegDef[RF90_PATH_B].rfHSSIPara1 = rFPGA0_XB_HSSIParameter1; //wire control parameter1
2088 priv->PHYRegDef[RF90_PATH_C].rfHSSIPara1 = rFPGA0_XC_HSSIParameter1; //wire control parameter1
2089 priv->PHYRegDef[RF90_PATH_D].rfHSSIPara1 = rFPGA0_XD_HSSIParameter1; //wire control parameter1
2091 // Tranceiver A~D HSSI Parameter-2
2092 priv->PHYRegDef[RF90_PATH_A].rfHSSIPara2 = rFPGA0_XA_HSSIParameter2; //wire control parameter2
2093 priv->PHYRegDef[RF90_PATH_B].rfHSSIPara2 = rFPGA0_XB_HSSIParameter2; //wire control parameter2
2094 priv->PHYRegDef[RF90_PATH_C].rfHSSIPara2 = rFPGA0_XC_HSSIParameter2; //wire control parameter2
2095 priv->PHYRegDef[RF90_PATH_D].rfHSSIPara2 = rFPGA0_XD_HSSIParameter2; //wire control parameter1
2097 // RF switch Control
2098 priv->PHYRegDef[RF90_PATH_A].rfSwitchControl = rFPGA0_XAB_SwitchControl; //TR/Ant switch control
2099 priv->PHYRegDef[RF90_PATH_B].rfSwitchControl = rFPGA0_XAB_SwitchControl;
2100 priv->PHYRegDef[RF90_PATH_C].rfSwitchControl = rFPGA0_XCD_SwitchControl;
2101 priv->PHYRegDef[RF90_PATH_D].rfSwitchControl = rFPGA0_XCD_SwitchControl;
2104 priv->PHYRegDef[RF90_PATH_A].rfAGCControl1 = rOFDM0_XAAGCCore1;
2105 priv->PHYRegDef[RF90_PATH_B].rfAGCControl1 = rOFDM0_XBAGCCore1;
2106 priv->PHYRegDef[RF90_PATH_C].rfAGCControl1 = rOFDM0_XCAGCCore1;
2107 priv->PHYRegDef[RF90_PATH_D].rfAGCControl1 = rOFDM0_XDAGCCore1;
2110 priv->PHYRegDef[RF90_PATH_A].rfAGCControl2 = rOFDM0_XAAGCCore2;
2111 priv->PHYRegDef[RF90_PATH_B].rfAGCControl2 = rOFDM0_XBAGCCore2;
2112 priv->PHYRegDef[RF90_PATH_C].rfAGCControl2 = rOFDM0_XCAGCCore2;
2113 priv->PHYRegDef[RF90_PATH_D].rfAGCControl2 = rOFDM0_XDAGCCore2;
2116 priv->PHYRegDef[RF90_PATH_A].rfRxIQImbalance = rOFDM0_XARxIQImbalance;
2117 priv->PHYRegDef[RF90_PATH_B].rfRxIQImbalance = rOFDM0_XBRxIQImbalance;
2118 priv->PHYRegDef[RF90_PATH_C].rfRxIQImbalance = rOFDM0_XCRxIQImbalance;
2119 priv->PHYRegDef[RF90_PATH_D].rfRxIQImbalance = rOFDM0_XDRxIQImbalance;
2122 priv->PHYRegDef[RF90_PATH_A].rfRxAFE = rOFDM0_XARxAFE;
2123 priv->PHYRegDef[RF90_PATH_B].rfRxAFE = rOFDM0_XBRxAFE;
2124 priv->PHYRegDef[RF90_PATH_C].rfRxAFE = rOFDM0_XCRxAFE;
2125 priv->PHYRegDef[RF90_PATH_D].rfRxAFE = rOFDM0_XDRxAFE;
2128 priv->PHYRegDef[RF90_PATH_A].rfTxIQImbalance = rOFDM0_XATxIQImbalance;
2129 priv->PHYRegDef[RF90_PATH_B].rfTxIQImbalance = rOFDM0_XBTxIQImbalance;
2130 priv->PHYRegDef[RF90_PATH_C].rfTxIQImbalance = rOFDM0_XCTxIQImbalance;
2131 priv->PHYRegDef[RF90_PATH_D].rfTxIQImbalance = rOFDM0_XDTxIQImbalance;
2134 priv->PHYRegDef[RF90_PATH_A].rfTxAFE = rOFDM0_XATxAFE;
2135 priv->PHYRegDef[RF90_PATH_B].rfTxAFE = rOFDM0_XBTxAFE;
2136 priv->PHYRegDef[RF90_PATH_C].rfTxAFE = rOFDM0_XCTxAFE;
2137 priv->PHYRegDef[RF90_PATH_D].rfTxAFE = rOFDM0_XDTxAFE;
2139 // Tranceiver LSSI Readback
2140 priv->PHYRegDef[RF90_PATH_A].rfLSSIReadBack = rFPGA0_XA_LSSIReadBack;
2141 priv->PHYRegDef[RF90_PATH_B].rfLSSIReadBack = rFPGA0_XB_LSSIReadBack;
2142 priv->PHYRegDef[RF90_PATH_C].rfLSSIReadBack = rFPGA0_XC_LSSIReadBack;
2143 priv->PHYRegDef[RF90_PATH_D].rfLSSIReadBack = rFPGA0_XD_LSSIReadBack;
2146 /******************************************************************************
2147 *function: This function is to write register and then readback to make sure whether BB and RF is OK
2148 * input: net_device dev
2149 * HW90_BLOCK_E CheckBlock
2150 * RF90_RADIO_PATH_E eRFPath //only used when checkblock is HW90_BLOCK_RF
2152 * return: return whether BB and RF is ok(0:OK; 1:Fail)
2153 * notice: This function may be removed in the ASIC
2154 * ***************************************************************************/
2155 RT_STATUS rtl8192_phy_checkBBAndRF(struct net_device* dev, HW90_BLOCK_E CheckBlock, RF90_RADIO_PATH_E eRFPath)
2157 struct r8192_priv *priv = ieee80211_priv(dev);
2158 // BB_REGISTER_DEFINITION_T *pPhyReg = &priv->PHYRegDef[eRFPath];
2159 RT_STATUS ret = RT_STATUS_SUCCESS;
2160 u32 i, CheckTimes = 4, dwRegRead = 0;
2162 u32 WriteData[] = {0xfffff027, 0xaa55a02f, 0x00000027, 0x55aa502f};
2163 // Initialize register address offset to be checked
2164 WriteAddr[HW90_BLOCK_MAC] = 0x100;
2165 WriteAddr[HW90_BLOCK_PHY0] = 0x900;
2166 WriteAddr[HW90_BLOCK_PHY1] = 0x800;
2167 WriteAddr[HW90_BLOCK_RF] = 0x3;
2168 RT_TRACE(COMP_PHY, "=======>%s(), CheckBlock:%d\n", __FUNCTION__, CheckBlock);
2169 for(i=0 ; i < CheckTimes ; i++)
2173 // Write Data to register and readback
2177 case HW90_BLOCK_MAC:
2178 RT_TRACE(COMP_ERR, "PHY_CheckBBRFOK(): Never Write 0x100 here!");
2181 case HW90_BLOCK_PHY0:
2182 case HW90_BLOCK_PHY1:
2183 write_nic_dword(priv, WriteAddr[CheckBlock], WriteData[i]);
2184 dwRegRead = read_nic_dword(priv, WriteAddr[CheckBlock]);
2188 WriteData[i] &= 0xfff;
2189 rtl8192_phy_SetRFReg(dev, eRFPath, WriteAddr[HW90_BLOCK_RF], bMask12Bits, WriteData[i]);
2190 // TODO: we should not delay for such a long time. Ask SD3
2192 dwRegRead = rtl8192_phy_QueryRFReg(dev, eRFPath, WriteAddr[HW90_BLOCK_RF], bMaskDWord);
2197 ret = RT_STATUS_FAILURE;
2203 // Check whether readback data is correct
2205 if(dwRegRead != WriteData[i])
2207 RT_TRACE(COMP_ERR, "====>error=====dwRegRead: %x, WriteData: %x \n", dwRegRead, WriteData[i]);
2208 ret = RT_STATUS_FAILURE;
2217 /******************************************************************************
2218 *function: This function initialize BB&RF
2219 * input: net_device dev
2222 * notice: Initialization value may change all the time, so please make
2223 * sure it has been synced with the newest.
2224 * ***************************************************************************/
2225 static RT_STATUS rtl8192_BB_Config_ParaFile(struct net_device* dev)
2227 struct r8192_priv *priv = ieee80211_priv(dev);
2228 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
2229 u8 bRegValue = 0, eCheckItem = 0;
2231 /**************************************
2232 //<1>Initialize BaseBand
2233 **************************************/
2235 /*--set BB Global Reset--*/
2236 bRegValue = read_nic_byte(priv, BB_GLOBAL_RESET);
2237 write_nic_byte(priv, BB_GLOBAL_RESET,(bRegValue|BB_GLOBAL_RESET_BIT));
2239 /*---set BB reset Active---*/
2240 dwRegValue = read_nic_dword(priv, CPU_GEN);
2241 write_nic_dword(priv, CPU_GEN, (dwRegValue&(~CPU_GEN_BB_RST)));
2243 /*----Ckeck FPGAPHY0 and PHY1 board is OK----*/
2244 // TODO: this function should be removed on ASIC , Emily 2007.2.2
2245 for(eCheckItem=(HW90_BLOCK_E)HW90_BLOCK_PHY0; eCheckItem<=HW90_BLOCK_PHY1; eCheckItem++)
2247 rtStatus = rtl8192_phy_checkBBAndRF(dev, (HW90_BLOCK_E)eCheckItem, (RF90_RADIO_PATH_E)0); //don't care RF path
2248 if(rtStatus != RT_STATUS_SUCCESS)
2250 RT_TRACE((COMP_ERR | COMP_PHY), "PHY_RF8256_Config():Check PHY%d Fail!!\n", eCheckItem-1);
2254 /*---- Set CCK and OFDM Block "OFF"----*/
2255 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bCCKEn|bOFDMEn, 0x0);
2256 /*----BB Register Initilazation----*/
2257 //==m==>Set PHY REG From Header<==m==
2258 rtl8192_phyConfigBB(dev, BaseBand_Config_PHY_REG);
2260 /*----Set BB reset de-Active----*/
2261 dwRegValue = read_nic_dword(priv, CPU_GEN);
2262 write_nic_dword(priv, CPU_GEN, (dwRegValue|CPU_GEN_BB_RST));
2264 /*----BB AGC table Initialization----*/
2265 //==m==>Set PHY REG From Header<==m==
2266 rtl8192_phyConfigBB(dev, BaseBand_Config_AGC_TAB);
2268 if (priv->card_8192_version > VERSION_8190_BD)
2270 if(priv->rf_type == RF_2T4R)
2272 // Antenna gain offset from B/C/D to A
2273 dwRegValue = ( priv->AntennaTxPwDiff[2]<<8 |
2274 priv->AntennaTxPwDiff[1]<<4 |
2275 priv->AntennaTxPwDiff[0]);
2278 dwRegValue = 0x0; //Antenna gain offset doesn't make sense in RF 1T2R.
2279 rtl8192_setBBreg(dev, rFPGA0_TxGainStage,
2280 (bXBTxAGC|bXCTxAGC|bXDTxAGC), dwRegValue);
2285 dwRegValue = priv->CrystalCap & 0x3; // bit0~1 of crystal cap
2286 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, bXtalCap01, dwRegValue);
2287 dwRegValue = ((priv->CrystalCap & 0xc)>>2); // bit2~3 of crystal cap
2288 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter2, bXtalCap23, dwRegValue);
2291 dwRegValue = priv->CrystalCap;
2292 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, bXtalCap92x, dwRegValue);
2298 // Check if the CCK HighPower is turned ON.
2299 // This is used to calculate PWDB.
2300 // priv->bCckHighPower = (u8)(rtl8192_QueryBBReg(dev, rFPGA0_XA_HSSIParameter2, 0x200));
2303 /******************************************************************************
2304 *function: This function initialize BB&RF
2305 * input: net_device dev
2308 * notice: Initialization value may change all the time, so please make
2309 * sure it has been synced with the newest.
2310 * ***************************************************************************/
2311 RT_STATUS rtl8192_BBConfig(struct net_device* dev)
2313 rtl8192_InitBBRFRegDef(dev);
2314 //config BB&RF. As hardCode based initialization has not been well
2315 //implemented, so use file first.FIXME:should implement it for hardcode?
2316 return rtl8192_BB_Config_ParaFile(dev);
2319 /******************************************************************************
2320 *function: This function obtains the initialization value of Tx power Level offset
2321 * input: net_device dev
2324 * ***************************************************************************/
2325 void rtl8192_phy_getTxPower(struct net_device* dev)
2327 struct r8192_priv *priv = ieee80211_priv(dev);
2329 priv->MCSTxPowerLevelOriginalOffset[0] =
2330 read_nic_dword(priv, MCS_TXAGC);
2331 priv->MCSTxPowerLevelOriginalOffset[1] =
2332 read_nic_dword(priv, (MCS_TXAGC+4));
2333 priv->CCKTxPowerLevelOriginalOffset =
2334 read_nic_dword(priv, CCK_TXAGC);
2337 priv->MCSTxPowerLevelOriginalOffset[0] =
2338 read_nic_dword(priv, rTxAGC_Rate18_06);
2339 priv->MCSTxPowerLevelOriginalOffset[1] =
2340 read_nic_dword(priv, rTxAGC_Rate54_24);
2341 priv->MCSTxPowerLevelOriginalOffset[2] =
2342 read_nic_dword(priv, rTxAGC_Mcs03_Mcs00);
2343 priv->MCSTxPowerLevelOriginalOffset[3] =
2344 read_nic_dword(priv, rTxAGC_Mcs07_Mcs04);
2345 priv->MCSTxPowerLevelOriginalOffset[4] =
2346 read_nic_dword(priv, rTxAGC_Mcs11_Mcs08);
2347 priv->MCSTxPowerLevelOriginalOffset[5] =
2348 read_nic_dword(priv, rTxAGC_Mcs15_Mcs12);
2352 // read rx initial gain
2353 priv->DefaultInitialGain[0] = read_nic_byte(priv, rOFDM0_XAAGCCore1);
2354 priv->DefaultInitialGain[1] = read_nic_byte(priv, rOFDM0_XBAGCCore1);
2355 priv->DefaultInitialGain[2] = read_nic_byte(priv, rOFDM0_XCAGCCore1);
2356 priv->DefaultInitialGain[3] = read_nic_byte(priv, rOFDM0_XDAGCCore1);
2357 RT_TRACE(COMP_INIT, "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x) \n",
2358 priv->DefaultInitialGain[0], priv->DefaultInitialGain[1],
2359 priv->DefaultInitialGain[2], priv->DefaultInitialGain[3]);
2362 priv->framesync = read_nic_byte(priv, rOFDM0_RxDetector3);
2363 priv->framesyncC34 = read_nic_dword(priv, rOFDM0_RxDetector2);
2364 RT_TRACE(COMP_INIT, "Default framesync (0x%x) = 0x%x \n",
2365 rOFDM0_RxDetector3, priv->framesync);
2366 // read SIFS (save the value read fome MACPHY_REG.txt)
2367 priv->SifsTime = read_nic_word(priv, SIFS);
2370 /******************************************************************************
2371 *function: This function obtains the initialization value of Tx power Level offset
2372 * input: net_device dev
2375 * ***************************************************************************/
2376 void rtl8192_phy_setTxPower(struct net_device* dev, u8 channel)
2378 struct r8192_priv *priv = ieee80211_priv(dev);
2379 u8 powerlevel = 0,powerlevelOFDM24G = 0;
2383 if(priv->epromtype == EPROM_93c46)
2385 powerlevel = priv->TxPowerLevelCCK[channel-1];
2386 powerlevelOFDM24G = priv->TxPowerLevelOFDM24G[channel-1];
2388 else if(priv->epromtype == EPROM_93c56)
2390 if(priv->rf_type == RF_1T2R)
2392 powerlevel = priv->TxPowerLevelCCK_C[channel-1];
2393 powerlevelOFDM24G = priv->TxPowerLevelOFDM24G_C[channel-1];
2395 else if(priv->rf_type == RF_2T4R)
2397 // Mainly we use RF-A Tx Power to write the Tx Power registers, but the RF-C Tx
2398 // Power must be calculated by the antenna diff.
2399 // So we have to rewrite Antenna gain offset register here.
2400 powerlevel = priv->TxPowerLevelCCK_A[channel-1];
2401 powerlevelOFDM24G = priv->TxPowerLevelOFDM24G_A[channel-1];
2403 ant_pwr_diff = priv->TxPowerLevelOFDM24G_C[channel-1]
2404 -priv->TxPowerLevelOFDM24G_A[channel-1];
2405 ant_pwr_diff &= 0xf;
2406 //DbgPrint(" ant_pwr_diff = 0x%x", (u8)(ant_pwr_diff));
2407 priv->RF_C_TxPwDiff = ant_pwr_diff;
2409 priv->AntennaTxPwDiff[2] = 0;// RF-D, don't care
2410 priv->AntennaTxPwDiff[1] = (u8)(ant_pwr_diff);// RF-C
2411 priv->AntennaTxPwDiff[0] = 0;// RF-B, don't care
2413 // Antenna gain offset from B/C/D to A
2414 u4RegValue = ( priv->AntennaTxPwDiff[2]<<8 |
2415 priv->AntennaTxPwDiff[1]<<4 |
2416 priv->AntennaTxPwDiff[0]);
2418 rtl8192_setBBreg(dev, rFPGA0_TxGainStage,
2419 (bXBTxAGC|bXCTxAGC|bXDTxAGC), u4RegValue);
2424 // CCX 2 S31, AP control of client transmit power:
2425 // 1. We shall not exceed Cell Power Limit as possible as we can.
2426 // 2. Tolerance is +/- 5dB.
2427 // 3. 802.11h Power Contraint takes higher precedence over CCX Cell Power Limit.
2430 // 1. 802.11h power contraint
2432 // 071011, by rcnjko.
2434 if( pMgntInfo->OpMode == RT_OP_MODE_INFRASTRUCTURE &&
2435 pMgntInfo->bWithCcxCellPwr &&
2436 channel == pMgntInfo->dot11CurrentChannelNumber)
2438 u8 CckCellPwrIdx = DbmToTxPwrIdx(Adapter, WIRELESS_MODE_B, pMgntInfo->CcxCellPwr);
2439 u8 LegacyOfdmCellPwrIdx = DbmToTxPwrIdx(Adapter, WIRELESS_MODE_G, pMgntInfo->CcxCellPwr);
2440 u8 OfdmCellPwrIdx = DbmToTxPwrIdx(Adapter, WIRELESS_MODE_N_24G, pMgntInfo->CcxCellPwr);
2442 RT_TRACE(COMP_TXAGC, DBG_LOUD,
2443 ("CCX Cell Limit: %d dbm => CCK Tx power index : %d, Legacy OFDM Tx power index : %d, OFDM Tx power index: %d\n",
2444 pMgntInfo->CcxCellPwr, CckCellPwrIdx, LegacyOfdmCellPwrIdx, OfdmCellPwrIdx));
2445 RT_TRACE(COMP_TXAGC, DBG_LOUD,
2446 ("EEPROM channel(%d) => CCK Tx power index: %d, Legacy OFDM Tx power index : %d, OFDM Tx power index: %d\n",
2447 channel, powerlevel, powerlevelOFDM24G + pHalData->LegacyHTTxPowerDiff, powerlevelOFDM24G));
2450 if(powerlevel > CckCellPwrIdx)
2451 powerlevel = CckCellPwrIdx;
2452 // Legacy OFDM, HT OFDM
2453 if(powerlevelOFDM24G + pHalData->LegacyHTTxPowerDiff > OfdmCellPwrIdx)
2455 if((OfdmCellPwrIdx - pHalData->LegacyHTTxPowerDiff) > 0)
2457 powerlevelOFDM24G = OfdmCellPwrIdx - pHalData->LegacyHTTxPowerDiff;
2461 LegacyOfdmCellPwrIdx = 0;
2465 RT_TRACE(COMP_TXAGC, DBG_LOUD,
2466 ("Altered CCK Tx power index : %d, Legacy OFDM Tx power index: %d, OFDM Tx power index: %d\n",
2467 powerlevel, powerlevelOFDM24G + pHalData->LegacyHTTxPowerDiff, powerlevelOFDM24G));
2470 pHalData->CurrentCckTxPwrIdx = powerlevel;
2471 pHalData->CurrentOfdm24GTxPwrIdx = powerlevelOFDM24G;
2473 switch(priv->rf_chip)
2476 // PHY_SetRF8225CckTxPower(Adapter, powerlevel);
2477 // PHY_SetRF8225OfdmTxPower(Adapter, powerlevelOFDM24G);
2480 PHY_SetRF8256CCKTxPower(dev, powerlevel); //need further implement
2481 PHY_SetRF8256OFDMTxPower(dev, powerlevelOFDM24G);
2486 RT_TRACE(COMP_ERR, "unknown rf chip in funtion %s()\n", __FUNCTION__);
2491 /******************************************************************************
2492 *function: This function check Rf chip to do RF config
2493 * input: net_device dev
2495 * return: only 8256 is supported
2496 * ***************************************************************************/
2497 RT_STATUS rtl8192_phy_RFConfig(struct net_device* dev)
2499 struct r8192_priv *priv = ieee80211_priv(dev);
2500 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
2501 switch(priv->rf_chip)
2504 // rtStatus = PHY_RF8225_Config(Adapter);
2507 rtStatus = PHY_RF8256_Config(dev);
2513 //rtStatus = PHY_RF8225_Config(Adapter);
2517 RT_TRACE(COMP_ERR, "error chip id\n");
2523 /******************************************************************************
2524 *function: This function update Initial gain
2525 * input: net_device dev
2527 * return: As Windows has not implemented this, wait for complement
2528 * ***************************************************************************/
2529 void rtl8192_phy_updateInitGain(struct net_device* dev)
2533 /******************************************************************************
2534 *function: This function read RF parameters from general head file, and do RF 3-wire
2535 * input: net_device dev
2537 * return: return code show if RF configuration is successful(0:pass, 1:fail)
2538 * Note: Delay may be required for RF configuration
2539 * ***************************************************************************/
2540 u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device* dev, RF90_RADIO_PATH_E eRFPath)
2549 for(i = 0;i<RadioA_ArrayLength; i=i+2){
2551 if(Rtl819XRadioA_Array[i] == 0xfe){
2555 rtl8192_phy_SetRFReg(dev, eRFPath, Rtl819XRadioA_Array[i], bMask12Bits, Rtl819XRadioA_Array[i+1]);
2561 for(i = 0;i<RadioB_ArrayLength; i=i+2){
2563 if(Rtl819XRadioB_Array[i] == 0xfe){
2567 rtl8192_phy_SetRFReg(dev, eRFPath, Rtl819XRadioB_Array[i], bMask12Bits, Rtl819XRadioB_Array[i+1]);
2573 for(i = 0;i<RadioC_ArrayLength; i=i+2){
2575 if(Rtl819XRadioC_Array[i] == 0xfe){
2579 rtl8192_phy_SetRFReg(dev, eRFPath, Rtl819XRadioC_Array[i], bMask12Bits, Rtl819XRadioC_Array[i+1]);
2585 for(i = 0;i<RadioD_ArrayLength; i=i+2){
2587 if(Rtl819XRadioD_Array[i] == 0xfe){
2591 rtl8192_phy_SetRFReg(dev, eRFPath, Rtl819XRadioD_Array[i], bMask12Bits, Rtl819XRadioD_Array[i+1]);
2603 /******************************************************************************
2604 *function: This function set Tx Power of the channel
2605 * input: struct net_device *dev
2610 * ***************************************************************************/
2611 static void rtl8192_SetTxPowerLevel(struct net_device *dev, u8 channel)
2613 struct r8192_priv *priv = ieee80211_priv(dev);
2614 u8 powerlevel = priv->TxPowerLevelCCK[channel-1];
2615 u8 powerlevelOFDM24G = priv->TxPowerLevelOFDM24G[channel-1];
2617 switch(priv->rf_chip)
2621 PHY_SetRF8225CckTxPower(Adapter, powerlevel);
2622 PHY_SetRF8225OfdmTxPower(Adapter, powerlevelOFDM24G);
2627 PHY_SetRF8256CCKTxPower(dev, powerlevel);
2628 PHY_SetRF8256OFDMTxPower(dev, powerlevelOFDM24G);
2634 RT_TRACE(COMP_ERR, "unknown rf chip ID in rtl8192_SetTxPowerLevel()\n");
2638 /****************************************************************************************
2639 *function: This function set command table variable(struct SwChnlCmd).
2640 * input: SwChnlCmd* CmdTable //table to be set.
2641 * u32 CmdTableIdx //variable index in table to be set
2642 * u32 CmdTableSz //table size.
2643 * SwChnlCmdID CmdID //command ID to set.
2648 * return: true if finished, false otherwise
2650 * ************************************************************************************/
2651 static u8 rtl8192_phy_SetSwChnlCmdArray(
2652 SwChnlCmd* CmdTable,
2663 if(CmdTable == NULL)
2665 RT_TRACE(COMP_ERR, "phy_SetSwChnlCmdArray(): CmdTable cannot be NULL.\n");
2668 if(CmdTableIdx >= CmdTableSz)
2670 RT_TRACE(COMP_ERR, "phy_SetSwChnlCmdArray(): Access invalid index, please check size of the table, CmdTableIdx:%d, CmdTableSz:%d\n",
2671 CmdTableIdx, CmdTableSz);
2675 pCmd = CmdTable + CmdTableIdx;
2676 pCmd->CmdID = CmdID;
2677 pCmd->Para1 = Para1;
2678 pCmd->Para2 = Para2;
2679 pCmd->msDelay = msDelay;
2683 /******************************************************************************
2684 *function: This function set channel step by step
2685 * input: struct net_device *dev
2687 * u8* stage //3 stages
2689 * u32* delay //whether need to delay
2690 * output: store new stage, step and delay for next step(combine with function above)
2691 * return: true if finished, false otherwise
2692 * Note: Wait for simpler function to replace it //wb
2693 * ***************************************************************************/
2694 static u8 rtl8192_phy_SwChnlStepByStep(struct net_device *dev, u8 channel, u8* stage, u8* step, u32* delay)
2696 struct r8192_priv *priv = ieee80211_priv(dev);
2697 // PCHANNEL_ACCESS_SETTING pChnlAccessSetting;
2698 SwChnlCmd PreCommonCmd[MAX_PRECMD_CNT];
2699 u32 PreCommonCmdCnt;
2700 SwChnlCmd PostCommonCmd[MAX_POSTCMD_CNT];
2701 u32 PostCommonCmdCnt;
2702 SwChnlCmd RfDependCmd[MAX_RFDEPENDCMD_CNT];
2704 SwChnlCmd *CurrentCmd = NULL;
2705 //RF90_RADIO_PATH_E eRFPath;
2710 RT_TRACE(COMP_TRACE, "====>%s()====stage:%d, step:%d, channel:%d\n", __FUNCTION__, *stage, *step, channel);
2711 // RT_ASSERT(IsLegalChannel(Adapter, channel), ("illegal channel: %d\n", channel));
2713 #ifdef ENABLE_DOT11D
2714 if (!IsLegalChannel(priv->ieee80211, channel))
2716 RT_TRACE(COMP_ERR, "=============>set to illegal channel:%d\n", channel);
2717 return true; //return true to tell upper caller function this channel setting is finished! Or it will in while loop.
2721 //for(eRFPath = RF90_PATH_A; eRFPath <pHalData->NumTotalRFPath; eRFPath++)
2722 //for(eRFPath = 0; eRFPath <RF90_PATH_MAX; eRFPath++)
2724 //if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
2726 // <1> Fill up pre common command.
2727 PreCommonCmdCnt = 0;
2728 rtl8192_phy_SetSwChnlCmdArray(PreCommonCmd, PreCommonCmdCnt++, MAX_PRECMD_CNT,
2729 CmdID_SetTxPowerLevel, 0, 0, 0);
2730 rtl8192_phy_SetSwChnlCmdArray(PreCommonCmd, PreCommonCmdCnt++, MAX_PRECMD_CNT,
2731 CmdID_End, 0, 0, 0);
2733 // <2> Fill up post common command.
2734 PostCommonCmdCnt = 0;
2736 rtl8192_phy_SetSwChnlCmdArray(PostCommonCmd, PostCommonCmdCnt++, MAX_POSTCMD_CNT,
2737 CmdID_End, 0, 0, 0);
2739 // <3> Fill up RF dependent command.
2741 switch( priv->rf_chip )
2744 if (!(channel >= 1 && channel <= 14))
2746 RT_TRACE(COMP_ERR, "illegal channel for Zebra 8225: %d\n", channel);
2749 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
2750 CmdID_RF_WriteReg, rZebra1_Channel, RF_CHANNEL_TABLE_ZEBRA[channel], 10);
2751 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
2752 CmdID_End, 0, 0, 0);
2756 // TEST!! This is not the table for 8256!!
2757 if (!(channel >= 1 && channel <= 14))
2759 RT_TRACE(COMP_ERR, "illegal channel for Zebra 8256: %d\n", channel);
2762 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
2763 CmdID_RF_WriteReg, rZebra1_Channel, channel, 10);
2764 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
2765 CmdID_End, 0, 0, 0);
2772 RT_TRACE(COMP_ERR, "Unknown RFChipID: %d\n", priv->rf_chip);
2782 CurrentCmd=&PreCommonCmd[*step];
2785 CurrentCmd=&RfDependCmd[*step];
2788 CurrentCmd=&PostCommonCmd[*step];
2792 if(CurrentCmd->CmdID==CmdID_End)
2806 switch(CurrentCmd->CmdID)
2808 case CmdID_SetTxPowerLevel:
2809 if(priv->card_8192_version > (u8)VERSION_8190_BD) //xiong: consider it later!
2810 rtl8192_SetTxPowerLevel(dev,channel);
2812 case CmdID_WritePortUlong:
2813 write_nic_dword(priv, CurrentCmd->Para1, CurrentCmd->Para2);
2815 case CmdID_WritePortUshort:
2816 write_nic_word(priv, CurrentCmd->Para1, (u16)CurrentCmd->Para2);
2818 case CmdID_WritePortUchar:
2819 write_nic_byte(priv, CurrentCmd->Para1, (u8)CurrentCmd->Para2);
2821 case CmdID_RF_WriteReg:
2822 for(eRFPath = 0; eRFPath <priv->NumTotalRFPath; eRFPath++)
2823 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, CurrentCmd->Para1, bMask12Bits, CurrentCmd->Para2<<7);
2831 }/*for(Number of RF paths)*/
2833 (*delay)=CurrentCmd->msDelay;
2838 /******************************************************************************
2839 *function: This function does acturally set channel work
2840 * input: struct net_device *dev
2844 * Note: We should not call this function directly
2845 * ***************************************************************************/
2846 static void rtl8192_phy_FinishSwChnlNow(struct net_device *dev, u8 channel)
2848 struct r8192_priv *priv = ieee80211_priv(dev);
2851 while(!rtl8192_phy_SwChnlStepByStep(dev,channel,&priv->SwChnlStage,&priv->SwChnlStep,&delay))
2854 msleep(delay);//or mdelay? need further consideration
2859 /******************************************************************************
2860 *function: Callback routine of the work item for switch channel.
2865 * ***************************************************************************/
2866 void rtl8192_SwChnl_WorkItem(struct net_device *dev)
2869 struct r8192_priv *priv = ieee80211_priv(dev);
2871 RT_TRACE(COMP_TRACE, "==> SwChnlCallback819xUsbWorkItem()\n");
2873 RT_TRACE(COMP_TRACE, "=====>--%s(), set chan:%d, priv:%p\n", __FUNCTION__, priv->chan, priv);
2875 rtl8192_phy_FinishSwChnlNow(dev , priv->chan);
2877 RT_TRACE(COMP_TRACE, "<== SwChnlCallback819xUsbWorkItem()\n");
2880 /******************************************************************************
2881 *function: This function scheduled actural workitem to set channel
2882 * input: net_device dev
2883 * u8 channel //channel to set
2885 * return: return code show if workitem is scheduled(1:pass, 0:fail)
2886 * Note: Delay may be required for RF configuration
2887 * ***************************************************************************/
2888 u8 rtl8192_phy_SwChnl(struct net_device* dev, u8 channel)
2890 struct r8192_priv *priv = ieee80211_priv(dev);
2891 RT_TRACE(COMP_PHY, "=====>%s()\n", __FUNCTION__);
2894 if(priv->SwChnlInProgress)
2897 // if(pHalData->SetBWModeInProgress)
2900 //--------------------------------------------
2901 switch(priv->ieee80211->mode)
2903 case WIRELESS_MODE_A:
2904 case WIRELESS_MODE_N_5G:
2906 RT_TRACE(COMP_ERR, "WIRELESS_MODE_A but channel<=14");
2910 case WIRELESS_MODE_B:
2912 RT_TRACE(COMP_ERR, "WIRELESS_MODE_B but channel>14");
2916 case WIRELESS_MODE_G:
2917 case WIRELESS_MODE_N_24G:
2919 RT_TRACE(COMP_ERR, "WIRELESS_MODE_G but channel>14");
2924 //--------------------------------------------
2926 priv->SwChnlInProgress = true;
2932 priv->SwChnlStage=0;
2934 // schedule_work(&(priv->SwChnlWorkItem));
2935 // rtl8192_SwChnl_WorkItem(dev);
2937 // queue_work(priv->priv_wq,&(priv->SwChnlWorkItem));
2938 rtl8192_SwChnl_WorkItem(dev);
2940 priv->SwChnlInProgress = false;
2944 static void CCK_Tx_Power_Track_BW_Switch_TSSI(struct net_device *dev )
2946 struct r8192_priv *priv = ieee80211_priv(dev);
2948 switch(priv->CurrentChannelBW)
2951 case HT_CHANNEL_WIDTH_20:
2952 //added by vivi, cck,tx power track, 20080703
2953 priv->CCKPresentAttentuation =
2954 priv->CCKPresentAttentuation_20Mdefault + priv->CCKPresentAttentuation_difference;
2956 if(priv->CCKPresentAttentuation > (CCKTxBBGainTableLength-1))
2957 priv->CCKPresentAttentuation = CCKTxBBGainTableLength-1;
2958 if(priv->CCKPresentAttentuation < 0)
2959 priv->CCKPresentAttentuation = 0;
2961 RT_TRACE(COMP_POWER_TRACKING, "20M, priv->CCKPresentAttentuation = %d\n", priv->CCKPresentAttentuation);
2963 if(priv->ieee80211->current_network.channel== 14 && !priv->bcck_in_ch14)
2965 priv->bcck_in_ch14 = TRUE;
2966 dm_cck_txpower_adjust(dev,priv->bcck_in_ch14);
2968 else if(priv->ieee80211->current_network.channel != 14 && priv->bcck_in_ch14)
2970 priv->bcck_in_ch14 = FALSE;
2971 dm_cck_txpower_adjust(dev,priv->bcck_in_ch14);
2974 dm_cck_txpower_adjust(dev,priv->bcck_in_ch14);
2978 case HT_CHANNEL_WIDTH_20_40:
2979 //added by vivi, cck,tx power track, 20080703
2980 priv->CCKPresentAttentuation =
2981 priv->CCKPresentAttentuation_40Mdefault + priv->CCKPresentAttentuation_difference;
2983 RT_TRACE(COMP_POWER_TRACKING, "40M, priv->CCKPresentAttentuation = %d\n", priv->CCKPresentAttentuation);
2984 if(priv->CCKPresentAttentuation > (CCKTxBBGainTableLength-1))
2985 priv->CCKPresentAttentuation = CCKTxBBGainTableLength-1;
2986 if(priv->CCKPresentAttentuation < 0)
2987 priv->CCKPresentAttentuation = 0;
2989 if(priv->ieee80211->current_network.channel == 14 && !priv->bcck_in_ch14)
2991 priv->bcck_in_ch14 = TRUE;
2992 dm_cck_txpower_adjust(dev,priv->bcck_in_ch14);
2994 else if(priv->ieee80211->current_network.channel != 14 && priv->bcck_in_ch14)
2996 priv->bcck_in_ch14 = FALSE;
2997 dm_cck_txpower_adjust(dev,priv->bcck_in_ch14);
3000 dm_cck_txpower_adjust(dev,priv->bcck_in_ch14);
3006 static void CCK_Tx_Power_Track_BW_Switch_ThermalMeter(struct net_device *dev)
3008 struct r8192_priv *priv = ieee80211_priv(dev);
3010 if(priv->ieee80211->current_network.channel == 14 && !priv->bcck_in_ch14)
3011 priv->bcck_in_ch14 = TRUE;
3012 else if(priv->ieee80211->current_network.channel != 14 && priv->bcck_in_ch14)
3013 priv->bcck_in_ch14 = FALSE;
3015 //write to default index and tx power track will be done in dm.
3016 switch(priv->CurrentChannelBW)
3019 case HT_CHANNEL_WIDTH_20:
3020 if(priv->Record_CCK_20Mindex == 0)
3021 priv->Record_CCK_20Mindex = 6; //set default value.
3022 priv->CCK_index = priv->Record_CCK_20Mindex;//6;
3023 RT_TRACE(COMP_POWER_TRACKING, "20MHz, CCK_Tx_Power_Track_BW_Switch_ThermalMeter(),CCK_index = %d\n", priv->CCK_index);
3027 case HT_CHANNEL_WIDTH_20_40:
3028 priv->CCK_index = priv->Record_CCK_40Mindex;//0;
3029 RT_TRACE(COMP_POWER_TRACKING, "40MHz, CCK_Tx_Power_Track_BW_Switch_ThermalMeter(), CCK_index = %d\n", priv->CCK_index);
3032 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
3036 static void CCK_Tx_Power_Track_BW_Switch(struct net_device *dev)
3039 struct r8192_priv *priv = ieee80211_priv(dev);
3043 CCK_Tx_Power_Track_BW_Switch_TSSI(dev);
3045 //if(pHalData->bDcut == TRUE)
3046 if(priv->IC_Cut >= IC_VersionCut_D)
3047 CCK_Tx_Power_Track_BW_Switch_TSSI(dev);
3049 CCK_Tx_Power_Track_BW_Switch_ThermalMeter(dev);
3055 /******************************************************************************
3056 *function: Callback routine of the work item for set bandwidth mode.
3057 * input: struct net_device *dev
3058 * HT_CHANNEL_WIDTH Bandwidth //20M or 40M
3059 * HT_EXTCHNL_OFFSET Offset //Upper, Lower, or Don't care
3062 * Note: I doubt whether SetBWModeInProgress flag is necessary as we can
3063 * test whether current work in the queue or not.//do I?
3064 * ***************************************************************************/
3065 void rtl8192_SetBWModeWorkItem(struct net_device *dev)
3068 struct r8192_priv *priv = ieee80211_priv(dev);
3071 RT_TRACE(COMP_SWBW, "==>rtl8192_SetBWModeWorkItem() Switch to %s bandwidth\n",
3072 priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz")
3075 if(priv->rf_chip== RF_PSEUDO_11N)
3077 priv->SetBWModeInProgress= false;
3082 priv->SetBWModeInProgress= false;
3085 //<1>Set MAC register
3086 regBwOpMode = read_nic_byte(priv, BW_OPMODE);
3088 switch(priv->CurrentChannelBW)
3090 case HT_CHANNEL_WIDTH_20:
3091 regBwOpMode |= BW_OPMODE_20MHZ;
3092 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
3093 write_nic_byte(priv, BW_OPMODE, regBwOpMode);
3096 case HT_CHANNEL_WIDTH_20_40:
3097 regBwOpMode &= ~BW_OPMODE_20MHZ;
3098 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
3099 write_nic_byte(priv, BW_OPMODE, regBwOpMode);
3103 RT_TRACE(COMP_ERR, "SetChannelBandwidth819xUsb(): unknown Bandwidth: %#X\n",priv->CurrentChannelBW);
3107 //<2>Set PHY related register
3108 switch(priv->CurrentChannelBW)
3110 case HT_CHANNEL_WIDTH_20:
3111 // Add by Vivi 20071119
3112 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x0);
3113 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x0);
3114 // rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00100000, 1);
3116 // Correct the tx power for CCK rate in 20M. Suggest by YN, 20071207
3117 // write_nic_dword(dev, rCCK0_TxFilter1, 0x1a1b0000);
3118 // write_nic_dword(dev, rCCK0_TxFilter2, 0x090e1317);
3119 // write_nic_dword(dev, rCCK0_DebugPort, 0x00000204);
3120 if(!priv->btxpower_tracking)
3122 write_nic_dword(priv, rCCK0_TxFilter1, 0x1a1b0000);
3123 write_nic_dword(priv, rCCK0_TxFilter2, 0x090e1317);
3124 write_nic_dword(priv, rCCK0_DebugPort, 0x00000204);
3127 CCK_Tx_Power_Track_BW_Switch(dev);
3130 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, bADClkPhase, 1);
3131 rtl8192_setBBreg(dev, rOFDM0_RxDetector1, bMaskByte0, 0x44); // 0xc30 is for 8190 only, Emily
3134 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00100000, 1);
3139 case HT_CHANNEL_WIDTH_20_40:
3140 // Add by Vivi 20071119
3141 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x1);
3142 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x1);
3143 //rtl8192_setBBreg(dev, rCCK0_System, bCCKSideBand, (priv->nCur40MhzPrimeSC>>1));
3144 //rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00100000, 0);
3145 //rtl8192_setBBreg(dev, rOFDM1_LSTF, 0xC00, priv->nCur40MhzPrimeSC);
3147 // Correct the tx power for CCK rate in 40M. Suggest by YN, 20071207
3148 //write_nic_dword(dev, rCCK0_TxFilter1, 0x35360000);
3149 //write_nic_dword(dev, rCCK0_TxFilter2, 0x121c252e);
3150 //write_nic_dword(dev, rCCK0_DebugPort, 0x00000409);
3151 if(!priv->btxpower_tracking)
3153 write_nic_dword(priv, rCCK0_TxFilter1, 0x35360000);
3154 write_nic_dword(priv, rCCK0_TxFilter2, 0x121c252e);
3155 write_nic_dword(priv, rCCK0_DebugPort, 0x00000409);
3158 CCK_Tx_Power_Track_BW_Switch(dev);
3160 // Set Control channel to upper or lower. These settings are required only for 40MHz
3161 rtl8192_setBBreg(dev, rCCK0_System, bCCKSideBand, (priv->nCur40MhzPrimeSC>>1));
3162 rtl8192_setBBreg(dev, rOFDM1_LSTF, 0xC00, priv->nCur40MhzPrimeSC);
3166 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, bADClkPhase, 0);
3167 rtl8192_setBBreg(dev, rOFDM0_RxDetector1, bMaskByte0, 0x42); // 0xc30 is for 8190 only, Emily
3169 // Set whether CCK should be sent in upper or lower channel. Suggest by YN. 20071207
3170 // It is set in Tx descriptor for 8192x series
3171 if(priv->nCur40MhzPrimeSC == HAL_PRIME_CHNL_OFFSET_UPPER)
3173 rtl8192_setBBreg(dev, rFPGA0_RFMOD, (BIT6|BIT5), 0x01);
3174 }else if(priv->nCur40MhzPrimeSC == HAL_PRIME_CHNL_OFFSET_LOWER)
3176 rtl8192_setBBreg(dev, rFPGA0_RFMOD, (BIT6|BIT5), 0x02);
3181 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00100000, 0);
3186 RT_TRACE(COMP_ERR, "SetChannelBandwidth819xUsb(): unknown Bandwidth: %#X\n" ,priv->CurrentChannelBW);
3190 //Skip over setting of J-mode in BB register here. Default value is "None J mode". Emily 20070315
3193 //<3>Set RF related register
3194 switch( priv->rf_chip )
3198 PHY_SetRF8225Bandwidth(Adapter, pHalData->CurrentChannelBW);
3203 PHY_SetRF8256Bandwidth(dev, priv->CurrentChannelBW);
3207 // PHY_SetRF8258Bandwidth();
3215 RT_TRACE(COMP_ERR, "Unknown RFChipID: %d\n", priv->rf_chip);
3219 atomic_dec(&(priv->ieee80211->atm_swbw));
3220 priv->SetBWModeInProgress= false;
3222 RT_TRACE(COMP_SWBW, "<==SetBWMode819xUsb()");
3225 /******************************************************************************
3226 *function: This function schedules bandwith switch work.
3227 * input: struct net_device *dev
3228 * HT_CHANNEL_WIDTH Bandwidth //20M or 40M
3229 * HT_EXTCHNL_OFFSET Offset //Upper, Lower, or Don't care
3232 * Note: I doubt whether SetBWModeInProgress flag is necessary as we can
3233 * test whether current work in the queue or not.//do I?
3234 * ***************************************************************************/
3235 void rtl8192_SetBWMode(struct net_device *dev, HT_CHANNEL_WIDTH Bandwidth, HT_EXTCHNL_OFFSET Offset)
3237 struct r8192_priv *priv = ieee80211_priv(dev);
3240 if(priv->SetBWModeInProgress)
3243 atomic_inc(&(priv->ieee80211->atm_swbw));
3244 priv->SetBWModeInProgress= true;
3246 priv->CurrentChannelBW = Bandwidth;
3248 if(Offset==HT_EXTCHNL_OFFSET_LOWER)
3249 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_UPPER;
3250 else if(Offset==HT_EXTCHNL_OFFSET_UPPER)
3251 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_LOWER;
3253 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
3255 //queue_work(priv->priv_wq, &(priv->SetBWModeWorkItem));
3256 // schedule_work(&(priv->SetBWModeWorkItem));
3257 rtl8192_SetBWModeWorkItem(dev);
3262 void InitialGain819xPci(struct net_device *dev, u8 Operation)
3264 #define SCAN_RX_INITIAL_GAIN 0x17
3265 #define POWER_DETECTION_TH 0x08
3266 struct r8192_priv *priv = ieee80211_priv(dev);
3275 RT_TRACE(COMP_SCAN, "IG_Backup, backup the initial gain.\n");
3276 initial_gain = SCAN_RX_INITIAL_GAIN;//pHalData->DefaultInitialGain[0];//
3277 BitMask = bMaskByte0;
3278 if(dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
3279 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); // FW DIG OFF
3280 priv->initgain_backup.xaagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XAAGCCore1, BitMask);
3281 priv->initgain_backup.xbagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XBAGCCore1, BitMask);
3282 priv->initgain_backup.xcagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XCAGCCore1, BitMask);
3283 priv->initgain_backup.xdagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XDAGCCore1, BitMask);
3284 BitMask = bMaskByte2;
3285 priv->initgain_backup.cca = (u8)rtl8192_QueryBBReg(dev, rCCK0_CCA, BitMask);
3287 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc50 is %x\n",priv->initgain_backup.xaagccore1);
3288 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc58 is %x\n",priv->initgain_backup.xbagccore1);
3289 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc60 is %x\n",priv->initgain_backup.xcagccore1);
3290 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc68 is %x\n",priv->initgain_backup.xdagccore1);
3291 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xa0a is %x\n",priv->initgain_backup.cca);
3293 RT_TRACE(COMP_SCAN, "Write scan initial gain = 0x%x \n", initial_gain);
3294 write_nic_byte(priv, rOFDM0_XAAGCCore1, initial_gain);
3295 write_nic_byte(priv, rOFDM0_XBAGCCore1, initial_gain);
3296 write_nic_byte(priv, rOFDM0_XCAGCCore1, initial_gain);
3297 write_nic_byte(priv, rOFDM0_XDAGCCore1, initial_gain);
3298 RT_TRACE(COMP_SCAN, "Write scan 0xa0a = 0x%x \n", POWER_DETECTION_TH);
3299 write_nic_byte(priv, 0xa0a, POWER_DETECTION_TH);
3302 RT_TRACE(COMP_SCAN, "IG_Restore, restore the initial gain.\n");
3303 BitMask = 0x7f; //Bit0~ Bit6
3304 if(dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
3305 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); // FW DIG OFF
3307 rtl8192_setBBreg(dev, rOFDM0_XAAGCCore1, BitMask, (u32)priv->initgain_backup.xaagccore1);
3308 rtl8192_setBBreg(dev, rOFDM0_XBAGCCore1, BitMask, (u32)priv->initgain_backup.xbagccore1);
3309 rtl8192_setBBreg(dev, rOFDM0_XCAGCCore1, BitMask, (u32)priv->initgain_backup.xcagccore1);
3310 rtl8192_setBBreg(dev, rOFDM0_XDAGCCore1, BitMask, (u32)priv->initgain_backup.xdagccore1);
3311 BitMask = bMaskByte2;
3312 rtl8192_setBBreg(dev, rCCK0_CCA, BitMask, (u32)priv->initgain_backup.cca);
3314 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc50 is %x\n",priv->initgain_backup.xaagccore1);
3315 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc58 is %x\n",priv->initgain_backup.xbagccore1);
3316 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc60 is %x\n",priv->initgain_backup.xcagccore1);
3317 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc68 is %x\n",priv->initgain_backup.xdagccore1);
3318 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xa0a is %x\n",priv->initgain_backup.cca);
3320 rtl8192_phy_setTxPower(dev,priv->ieee80211->current_network.channel);
3323 if(dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
3324 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x1); // FW DIG ON
3327 RT_TRACE(COMP_SCAN, "Unknown IG Operation. \n");