1 /******************************************************************************
3 (c) Copyright 2008, RealTEK Technologies Inc. All Rights Reserved.
7 Note: Merge 92SE/SU PHY config as below
10 3. Initial BB/RF/MAC config by reading BB/MAC/RF txt.
13 5. Initial gain switch API.
14 6. Other BB/MAC/RF API.
16 Function: PHY: Extern function, phy: local function
18 Export: PHY_FunctionName
24 08/08/2008 MHC 1. Port from 9x series phycfg.c
25 2. Reorganize code arch and ad description.
26 3. Collect similar function.
27 4. Seperate extern/local API.
28 08/12/2008 MHC We must merge or move USB PHY relative function later.
29 10/07/2008 MHC Add IQ calibration for PHY.(Only 1T2R mode now!!!)
30 11/06/2008 MHC Add TX Power index PG file to config in 0xExx register
31 area to map with EEPROM/EFUSE tx pwr index.
33 ******************************************************************************/
35 #include "r8192U_dm.h"
36 #include "r8192S_rtl6052.h"
38 #include "r8192S_hw.h"
39 #include "r8192S_phy.h"
40 #include "r8192S_phyreg.h"
41 #include "r8192SU_HWImg.h"
43 #include "ieee80211/dot11d.h"
45 /*---------------------------Define Local Constant---------------------------*/
46 /* Channel switch:The size of command tables for switch channel*/
47 #define MAX_PRECMD_CNT 16
48 #define MAX_RFDEPENDCMD_CNT 16
49 #define MAX_POSTCMD_CNT 16
50 #define MAX_DOZE_WAITING_TIMES_9x 64
52 /*------------------------Define local variable------------------------------*/
56 phy_CalculateBitShift(u32 BitMask);
58 phy_ConfigMACWithHeaderFile(struct net_device* dev);
60 phy_InitBBRFRegisterDefinition(struct net_device* dev);
62 phy_BB8192S_Config_ParaFile(struct net_device* dev);
64 phy_ConfigBBWithHeaderFile(struct net_device* dev,u8 ConfigType);
66 phy_SetRFPowerState8192SU(struct net_device* dev,RT_RF_POWER_STATE eRFPowerState);
68 SetBWModeCallback8192SUsbWorkItem(struct net_device *dev);
70 SetBWModeCallback8192SUsbWorkItem(struct net_device *dev);
72 SwChnlCallback8192SUsbWorkItem(struct net_device *dev );
74 phy_FinishSwChnlNow(struct net_device* dev,u8 channel);
77 struct net_device* dev,
84 phy_ConfigBBWithPgHeaderFile(struct net_device* dev,u8 ConfigType);
85 static long phy_TxPwrIdxToDbm( struct net_device* dev, WIRELESS_MODE WirelessMode, u8 TxPwrIdx);
86 static u8 phy_DbmToTxPwrIdx( struct net_device* dev, WIRELESS_MODE WirelessMode, long PowerInDbm);
87 void phy_SetFwCmdIOCallback(struct net_device* dev);
89 //#if ((HAL_CODE_BASE == RTL8192_S) && (DEV_BUS_TYPE==USB_INTERFACE))
92 // Base Band read by 4181 to make sure that operation could be done in unlimited cycle.
95 // - Only use on RTL8192S USB interface.
98 // Created by Roger, 2008.09.06.
101 u32 phy_QueryUsbBBReg(struct net_device* dev, u32 RegAddr)
103 struct r8192_priv *priv = ieee80211_priv(dev);
104 u32 ReturnValue = 0xffffffff;
106 u8 BBWaitCounter = 0;
110 // <Roger_Notes> Due to PASSIVE_LEVEL, so we ONLY simply busy waiting for a while here.
111 // We have to make sure that previous BB I/O has been done.
114 while(priv->bChangeBBInProgress)
117 RT_TRACE(COMP_RF, "phy_QueryUsbBBReg(): Wait 1 ms (%d times)...\n", BBWaitCounter);
120 // Wait too long, return FALSE to avoid to be stuck here.
121 if((BBWaitCounter > 100) )//||RT_USB_CANNOT_IO(Adapter))
123 RT_TRACE(COMP_RF, "phy_QueryUsbBBReg(): (%d) Wait too logn to query BB!!\n", BBWaitCounter);
128 priv->bChangeBBInProgress = true;
130 read_nic_dword(dev, RegAddr);
133 {// Make sure that access could be done.
134 if((read_nic_byte(dev, PHY_REG)&HST_RDBUSY) == 0)
136 }while( --PollingCnt );
140 RT_TRACE(COMP_RF, "Fail!!!phy_QueryUsbBBReg(): RegAddr(%#x) = %#x\n", RegAddr, ReturnValue);
144 // Data FW read back.
145 ReturnValue = read_nic_dword(dev, PHY_REG_DATA);
146 RT_TRACE(COMP_RF, "phy_QueryUsbBBReg(): RegAddr(%#x) = %#x, PollingCnt(%d)\n", RegAddr, ReturnValue, PollingCnt);
149 priv->bChangeBBInProgress = false;
158 // Base Band wrote by 4181 to make sure that operation could be done in unlimited cycle.
161 // - Only use on RTL8192S USB interface.
164 // Created by Roger, 2008.09.06.
168 phy_SetUsbBBReg(struct net_device* dev,u32 RegAddr,u32 Data)
170 struct r8192_priv *priv = ieee80211_priv(dev);
171 u8 BBWaitCounter = 0;
173 RT_TRACE(COMP_RF, "phy_SetUsbBBReg(): RegAddr(%#x) <= %#x\n", RegAddr, Data);
176 // <Roger_Notes> Due to PASSIVE_LEVEL, so we ONLY simply busy waiting for a while here.
177 // We have to make sure that previous BB I/O has been done.
180 while(priv->bChangeBBInProgress)
183 RT_TRACE(COMP_RF, "phy_SetUsbBBReg(): Wait 1 ms (%d times)...\n", BBWaitCounter);
186 if((BBWaitCounter > 100))// || RT_USB_CANNOT_IO(Adapter))
188 RT_TRACE(COMP_RF, "phy_SetUsbBBReg(): (%d) Wait too logn to query BB!!\n", BBWaitCounter);
193 priv->bChangeBBInProgress = true;
194 //printk("**************%s: RegAddr:%x Data:%x\n", __FUNCTION__,RegAddr, Data);
195 write_nic_dword(dev, RegAddr, Data);
197 priv->bChangeBBInProgress = false;
204 // RF read by 4181 to make sure that operation could be done in unlimited cycle.
207 // - Only use on RTL8192S USB interface.
209 // - RT_RF_OPERATE_SPINLOCK is acquired and keep on holding to the end.FIXLZM
211 // Created by Roger, 2008.09.06.
214 u32 phy_QueryUsbRFReg( struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 Offset)
217 struct r8192_priv *priv = ieee80211_priv(dev);
218 //u32 value = 0, ReturnValue = 0;
220 //u32 tmplong,tmplong2;
222 u8 RFWaitCounter = 0;
226 // <Roger_Notes> Due to PASSIVE_LEVEL, so we ONLY simply busy waiting for a while here.
227 // We have to make sure that previous RF I/O has been done.
230 while(priv->bChangeRFInProgress)
232 //PlatformReleaseSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
233 //spin_lock_irqsave(&priv->rf_lock, flags); //LZM,090318
237 RT_TRACE(COMP_RF, "phy_QueryUsbRFReg(): Wait 1 ms (%d times)...\n", RFWaitCounter);
240 if((RFWaitCounter > 100)) //|| RT_USB_CANNOT_IO(Adapter))
242 RT_TRACE(COMP_RF, "phy_QueryUsbRFReg(): (%d) Wait too logn to query BB!!\n", RFWaitCounter);
247 //PlatformAcquireSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
251 priv->bChangeRFInProgress = true;
252 //PlatformReleaseSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
255 Offset &= 0x3f; //RF_Offset= 0x00~0x3F
257 write_nic_dword(dev, RF_BB_CMD_ADDR, 0xF0000002|
258 (Offset<<8)| //RF_Offset= 0x00~0x3F
259 (eRFPath<<16)); //RF_Path = 0(A) or 1(B)
262 {// Make sure that access could be done.
263 if(read_nic_dword(dev, RF_BB_CMD_ADDR) == 0)
265 }while( --PollingCnt );
267 // Data FW read back.
268 ReturnValue = read_nic_dword(dev, RF_BB_CMD_DATA);
270 //PlatformAcquireSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
271 //spin_unlock_irqrestore(&priv->rf_lock, flags); //LZM,090318
273 priv->bChangeRFInProgress = false;
275 RT_TRACE(COMP_RF, "phy_QueryUsbRFReg(): eRFPath(%d), Offset(%#x) = %#x\n", eRFPath, Offset, ReturnValue);
284 // RF wrote by 4181 to make sure that operation could be done in unlimited cycle.
287 // - Only use on RTL8192S USB interface.
289 // - RT_RF_OPERATE_SPINLOCK is acquired and keep on holding to the end.FIXLZM
291 // Created by Roger, 2008.09.06.
294 void phy_SetUsbRFReg(struct net_device* dev,RF90_RADIO_PATH_E eRFPath,u32 RegAddr,u32 Data)
297 struct r8192_priv *priv = ieee80211_priv(dev);
299 u8 RFWaitCounter = 0;
303 // <Roger_Notes> Due to PASSIVE_LEVEL, so we ONLY simply busy waiting for a while here.
304 // We have to make sure that previous BB I/O has been done.
307 while(priv->bChangeRFInProgress)
309 //PlatformReleaseSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
310 //spin_lock_irqsave(&priv->rf_lock, flags); //LZM,090318
314 RT_TRACE(COMP_RF, "phy_SetUsbRFReg(): Wait 1 ms (%d times)...\n", RFWaitCounter);
317 if((RFWaitCounter > 100))// || RT_USB_CANNOT_IO(Adapter))
319 RT_TRACE(COMP_RF, "phy_SetUsbRFReg(): (%d) Wait too logn to query BB!!\n", RFWaitCounter);
324 //PlatformAcquireSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
328 priv->bChangeRFInProgress = true;
329 //PlatformReleaseSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
332 RegAddr &= 0x3f; //RF_Offset= 0x00~0x3F
334 write_nic_dword(dev, RF_BB_CMD_DATA, Data);
335 write_nic_dword(dev, RF_BB_CMD_ADDR, 0xF0000003|
336 (RegAddr<<8)| //RF_Offset= 0x00~0x3F
337 (eRFPath<<16)); //RF_Path = 0(A) or 1(B)
340 {// Make sure that access could be done.
341 if(read_nic_dword(dev, RF_BB_CMD_ADDR) == 0)
343 }while( --PollingCnt );
347 RT_TRACE(COMP_RF, "phy_SetUsbRFReg(): Set RegAddr(%#x) = %#x Fail!!!\n", RegAddr, Data);
350 //PlatformAcquireSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
351 //spin_unlock_irqrestore(&priv->rf_lock, flags); //LZM,090318
353 priv->bChangeRFInProgress = false;
358 /*---------------------Define local function prototype-----------------------*/
361 /*----------------------------Function Body----------------------------------*/
363 // 1. BB register R/W API
366 * Function: PHY_QueryBBReg
368 * OverView: Read "sepcific bits" from BB register
372 * u32 RegAddr, //The target address to be readback
373 * u32 BitMask //The target bit position in the target address
376 * Return: u32 Data //The readback register value
377 * Note: This function is equal to "GetRegSetting" in PHY programming guide
379 //use phy dm core 8225 8256 6052
380 //u32 PHY_QueryBBReg(struct net_device* dev,u32 RegAddr, u32 BitMask)
381 u32 rtl8192_QueryBBReg(struct net_device* dev, u32 RegAddr, u32 BitMask)
384 u32 ReturnValue = 0, OriginalValue, BitShift;
387 RT_TRACE(COMP_RF, "--->PHY_QueryBBReg(): RegAddr(%#x), BitMask(%#x)\n", RegAddr, BitMask);
390 // <Roger_Notes> Due to 8051 operation cycle (limitation cycle: 6us) and 1-Byte access issue, we should use
391 // 4181 to access Base Band instead of 8051 on USB interface to make sure that access could be done in
395 //#if ((HAL_CODE_BASE == RTL8192_S) && (DEV_BUS_TYPE==USB_INTERFACE))
396 if(IS_BB_REG_OFFSET_92S(RegAddr))
398 //if(RT_USB_CANNOT_IO(Adapter)) return FALSE;
400 if((RegAddr & 0x03) != 0)
402 printk("%s: Not DWORD alignment!!\n", __FUNCTION__);
406 OriginalValue = phy_QueryUsbBBReg(dev, RegAddr);
410 OriginalValue = read_nic_dword(dev, RegAddr);
413 BitShift = phy_CalculateBitShift(BitMask);
414 ReturnValue = (OriginalValue & BitMask) >> BitShift;
416 //RTPRINT(FPHY, PHY_BBR, ("BBR MASK=0x%x Addr[0x%x]=0x%x\n", BitMask, RegAddr, OriginalValue));
417 RT_TRACE(COMP_RF, "<---PHY_QueryBBReg(): RegAddr(%#x), BitMask(%#x), OriginalValue(%#x)\n", RegAddr, BitMask, OriginalValue);
418 return (ReturnValue);
422 * Function: PHY_SetBBReg
424 * OverView: Write "Specific bits" to BB register (page 8~)
428 * u32 RegAddr, //The target address to be modified
429 * u32 BitMask //The target bit position in the target address
431 * u32 Data //The new register value in the target bit position
432 * //of the target address
436 * Note: This function is equal to "PutRegSetting" in PHY programming guide
438 //use phy dm core 8225 8256
439 //void PHY_SetBBReg(struct net_device* dev,u32 RegAddr, u32 BitMask, u32 Data )
440 void rtl8192_setBBreg(struct net_device* dev, u32 RegAddr, u32 BitMask, u32 Data)
442 u32 OriginalValue, BitShift, NewValue;
445 RT_TRACE(COMP_RF, "--->PHY_SetBBReg(): RegAddr(%#x), BitMask(%#x), Data(%#x)\n", RegAddr, BitMask, Data);
448 // <Roger_Notes> Due to 8051 operation cycle (limitation cycle: 6us) and 1-Byte access issue, we should use
449 // 4181 to access Base Band instead of 8051 on USB interface to make sure that access could be done in
453 //#if ((HAL_CODE_BASE == RTL8192_S) && (DEV_BUS_TYPE==USB_INTERFACE))
454 if(IS_BB_REG_OFFSET_92S(RegAddr))
456 if((RegAddr & 0x03) != 0)
458 printk("%s: Not DWORD alignment!!\n", __FUNCTION__);
462 if(BitMask!= bMaskDWord)
463 {//if not "double word" write
464 OriginalValue = phy_QueryUsbBBReg(dev, RegAddr);
465 BitShift = phy_CalculateBitShift(BitMask);
466 NewValue = (((OriginalValue) & (~BitMask))|(Data << BitShift));
467 phy_SetUsbBBReg(dev, RegAddr, NewValue);
469 phy_SetUsbBBReg(dev, RegAddr, Data);
473 if(BitMask!= bMaskDWord)
474 {//if not "double word" write
475 OriginalValue = read_nic_dword(dev, RegAddr);
476 BitShift = phy_CalculateBitShift(BitMask);
477 NewValue = (((OriginalValue) & (~BitMask)) | (Data << BitShift));
478 write_nic_dword(dev, RegAddr, NewValue);
480 write_nic_dword(dev, RegAddr, Data);
483 //RT_TRACE(COMP_RF, "<---PHY_SetBBReg(): RegAddr(%#x), BitMask(%#x), Data(%#x)\n", RegAddr, BitMask, Data);
490 // 2. RF register R/W API
493 * Function: PHY_QueryRFReg
495 * OverView: Query "Specific bits" to RF register (page 8~)
499 * RF90_RADIO_PATH_E eRFPath, //Radio path of A/B/C/D
500 * u32 RegAddr, //The target address to be read
501 * u32 BitMask //The target bit position in the target address
505 * Return: u32 Readback value
506 * Note: This function is equal to "GetRFRegSetting" in PHY programming guide
509 //u32 PHY_QueryRFReg(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 RegAddr, u32 BitMask)
510 u32 rtl8192_phy_QueryRFReg(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 RegAddr, u32 BitMask)
512 u32 Original_Value, Readback_Value, BitShift;//, flags;
513 struct r8192_priv *priv = ieee80211_priv(dev);
516 RT_TRACE(COMP_RF, "--->PHY_QueryRFReg(): RegAddr(%#x), eRFPath(%#x), BitMask(%#x)\n", RegAddr, eRFPath,BitMask);
518 if (!((priv->rf_pathmap >> eRFPath) & 0x1))
520 printk("EEEEEError: rfpath off! rf_pathmap=%x eRFPath=%x\n", priv->rf_pathmap, eRFPath);
524 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
526 printk("EEEEEError: not legal rfpath! eRFPath=%x\n", eRFPath);
530 /* 2008/01/17 MH We get and release spin lock when reading RF register. */
531 //PlatformAcquireSpinLock(dev, RT_RF_OPERATE_SPINLOCK);FIXLZM
532 //spin_lock_irqsave(&priv->rf_lock, flags); //YJ,test,090113
535 // <Roger_Notes> Due to 8051 operation cycle (limitation cycle: 6us) and 1-Byte access issue, we should use
536 // 4181 to access Base Band instead of 8051 on USB interface to make sure that access could be done in
540 //#if (HAL_CODE_BASE == RTL8192_S && DEV_BUS_TYPE==USB_INTERFACE)
541 //if(RT_USB_CANNOT_IO(Adapter)) return FALSE;
542 Original_Value = phy_QueryUsbRFReg(dev, eRFPath, RegAddr);
544 BitShift = phy_CalculateBitShift(BitMask);
545 Readback_Value = (Original_Value & BitMask) >> BitShift;
546 //spin_unlock_irqrestore(&priv->rf_lock, flags); //YJ,test,090113
548 //PlatformReleaseSpinLock(dev, RT_RF_OPERATE_SPINLOCK);
550 //RTPRINT(FPHY, PHY_RFR, ("RFR-%d MASK=0x%x Addr[0x%x]=0x%x\n", eRFPath, BitMask, RegAddr, Original_Value));
552 return (Readback_Value);
556 * Function: PHY_SetRFReg
558 * OverView: Write "Specific bits" to RF register (page 8~)
562 * RF90_RADIO_PATH_E eRFPath, //Radio path of A/B/C/D
563 * u32 RegAddr, //The target address to be modified
564 * u32 BitMask //The target bit position in the target address
566 * u32 Data //The new register Data in the target bit position
567 * //of the target address
571 * Note: This function is equal to "PutRFRegSetting" in PHY programming guide
574 //void PHY_SetRFReg(struct net_device* dev,RF90_RADIO_PATH_E eRFPath, u32 RegAddr, u32 BitMask,u32 Data )
575 void rtl8192_phy_SetRFReg(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
578 struct r8192_priv *priv = ieee80211_priv(dev);
579 u32 Original_Value, BitShift, New_Value;//, flags;
581 RT_TRACE(COMP_RF, "--->PHY_SetRFReg(): RegAddr(%#x), BitMask(%#x), Data(%#x), eRFPath(%#x)\n",
582 RegAddr, BitMask, Data, eRFPath);
584 if (!((priv->rf_pathmap >> eRFPath) & 0x1))
586 printk("EEEEEError: rfpath off! rf_pathmap=%x eRFPath=%x\n", priv->rf_pathmap, eRFPath);
589 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
591 printk("EEEEEError: not legal rfpath! eRFPath=%x\n", eRFPath);
595 /* 2008/01/17 MH We get and release spin lock when writing RF register. */
596 //PlatformAcquireSpinLock(dev, RT_RF_OPERATE_SPINLOCK);
597 //spin_lock_irqsave(&priv->rf_lock, flags); //YJ,test,090113
600 // <Roger_Notes> Due to 8051 operation cycle (limitation cycle: 6us) and 1-Byte access issue, we should use
601 // 4181 to access Base Band instead of 8051 on USB interface to make sure that access could be done in
605 //#if (HAL_CODE_BASE == RTL8192_S && DEV_BUS_TYPE==USB_INTERFACE)
606 //if(RT_USB_CANNOT_IO(Adapter)) return;
608 if (BitMask != bRFRegOffsetMask) // RF data is 12 bits only
610 Original_Value = phy_QueryUsbRFReg(dev, eRFPath, RegAddr);
611 BitShift = phy_CalculateBitShift(BitMask);
612 New_Value = (((Original_Value)&(~BitMask))|(Data<< BitShift));
613 phy_SetUsbRFReg(dev, eRFPath, RegAddr, New_Value);
616 phy_SetUsbRFReg(dev, eRFPath, RegAddr, Data);
617 //PlatformReleaseSpinLock(dev, RT_RF_OPERATE_SPINLOCK);
618 //spin_unlock_irqrestore(&priv->rf_lock, flags); //YJ,test,090113
620 //RTPRINT(FPHY, PHY_RFW, ("RFW-%d MASK=0x%x Addr[0x%x]=0x%x\n", eRFPath, BitMask, RegAddr, Data));
621 RT_TRACE(COMP_RF, "<---PHY_SetRFReg(): RegAddr(%#x), BitMask(%#x), Data(%#x), eRFPath(%#x)\n",
622 RegAddr, BitMask, Data, eRFPath);
627 * Function: phy_CalculateBitShift
629 * OverView: Get shifted position of the BitMask
635 * Return: u32 Return the shift bit bit position of the mask
638 static u32 phy_CalculateBitShift(u32 BitMask)
644 if ( ((BitMask>>i) & 0x1 ) == 1)
653 // 3. Initial MAC/BB/RF config by reading MAC/BB/RF txt.
655 /*-----------------------------------------------------------------------------
656 * Function: PHY_MACConfig8192S
658 * Overview: Condig MAC by header file or parameter file.
668 * 08/12/2008 MHC Create Version 0.
670 *---------------------------------------------------------------------------*/
672 extern bool PHY_MACConfig8192S(struct net_device* dev)
674 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
679 rtStatus = phy_ConfigMACWithHeaderFile(dev);
680 return (rtStatus == RT_STATUS_SUCCESS) ? true:false;
686 PHY_BBConfig8192S(struct net_device* dev)
688 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
690 u8 PathMap = 0, index = 0, rf_num = 0;
691 struct r8192_priv *priv = ieee80211_priv(dev);
692 phy_InitBBRFRegisterDefinition(dev);
697 //switch( Adapter->MgntInfo.bRegHwParaFile )
700 // phy_BB8190_Config_HardCode(dev);
704 rtStatus = phy_BB8192S_Config_ParaFile(dev);
709 // phy_BB8190_Config_HardCode(dev);
710 // phy_BB8192S_Config_ParaFile(dev);
714 // phy_BB8190_Config_HardCode(dev);
717 PathMap = (u8)(rtl8192_QueryBBReg(dev, rFPGA0_TxInfo, 0xf) |
718 rtl8192_QueryBBReg(dev, rOFDM0_TRxPathEnable, 0xf));
719 priv->rf_pathmap = PathMap;
720 for(index = 0; index<4; index++)
722 if((PathMap>>index)&0x1)
726 if((priv->rf_type==RF_1T1R && rf_num!=1) ||
727 (priv->rf_type==RF_1T2R && rf_num!=2) ||
728 (priv->rf_type==RF_2T2R && rf_num!=2) ||
729 (priv->rf_type==RF_2T2R_GREEN && rf_num!=2) ||
730 (priv->rf_type==RF_2T4R && rf_num!=4))
732 RT_TRACE( COMP_INIT, "PHY_BBConfig8192S: RF_Type(%x) does not match RF_Num(%x)!!\n", priv->rf_type, rf_num);
734 return (rtStatus == RT_STATUS_SUCCESS) ? 1:0;
739 PHY_RFConfig8192S(struct net_device* dev)
741 struct r8192_priv *priv = ieee80211_priv(dev);
742 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
744 //Set priv->rf_chip = RF_8225 to do real PHY FPGA initilization
746 //<Roger_EXP> We assign RF type here temporally. 2008.09.12.
747 priv->rf_chip = RF_6052;
752 switch(priv->rf_chip)
756 rtStatus = PHY_RF6052_Config(dev);
760 //rtStatus = PHY_RF8256_Config(dev);
767 //rtStatus = PHY_RF8225_Config(dev);
773 return (rtStatus == RT_STATUS_SUCCESS) ? 1:0;
777 // Joseph test: new initialize order!!
778 // Test only!! This part need to be re-organized.
779 // Now it is just for 8256.
783 phy_BB8190_Config_HardCode(struct net_device* dev)
785 //RT_ASSERT(FALSE, ("This function is not implement yet!! \n"));
786 return RT_STATUS_SUCCESS;
790 /*-----------------------------------------------------------------------------
791 * Function: phy_SetBBtoDiffRFWithHeaderFile()
793 * Overview: This function
796 * Input: PADAPTER Adapter
797 * u1Byte ConfigType 0 => PHY_CONFIG
801 * Return: RT_STATUS_SUCCESS: configuration file exist
805 *---------------------------------------------------------------------------*/
807 phy_SetBBtoDiffRFWithHeaderFile(struct net_device* dev, u8 ConfigType)
810 struct r8192_priv *priv = ieee80211_priv(dev);
811 u32* Rtl819XPHY_REGArraytoXTXR_Table;
812 u16 PHY_REGArraytoXTXRLen;
814 //#if (HAL_CODE_BASE != RTL8192_S)
816 if(priv->rf_type == RF_1T1R)
818 Rtl819XPHY_REGArraytoXTXR_Table = Rtl819XPHY_REG_to1T1R_Array;
819 PHY_REGArraytoXTXRLen = PHY_ChangeTo_1T1RArrayLength;
821 else if(priv->rf_type == RF_1T2R)
823 Rtl819XPHY_REGArraytoXTXR_Table = Rtl819XPHY_REG_to1T2R_Array;
824 PHY_REGArraytoXTXRLen = PHY_ChangeTo_1T2RArrayLength;
826 //else if(priv->rf_type == RF_2T2R || priv->rf_type == RF_2T2R_GREEN)
828 // Rtl819XPHY_REGArraytoXTXR_Table = Rtl819XPHY_REG_to2T2R_Array;
829 // PHY_REGArraytoXTXRLen = PHY_ChangeTo_2T2RArrayLength;
833 return RT_STATUS_FAILURE;
836 if(ConfigType == BaseBand_Config_PHY_REG)
838 for(i=0;i<PHY_REGArraytoXTXRLen;i=i+3)
840 if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xfe)
842 else if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xfd)
844 else if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xfc)
846 else if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xfb)
848 else if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xfa)
850 else if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xf9)
852 rtl8192_setBBreg(dev, Rtl819XPHY_REGArraytoXTXR_Table[i], Rtl819XPHY_REGArraytoXTXR_Table[i+1], Rtl819XPHY_REGArraytoXTXR_Table[i+2]);
853 //RT_TRACE(COMP_SEND,
854 //"The Rtl819XPHY_REGArraytoXTXR_Table[0] is %lx Rtl819XPHY_REGArraytoXTXR_Table[1] is %lx Rtl819XPHY_REGArraytoXTXR_Table[2] is %lx \n",
855 //Rtl819XPHY_REGArraytoXTXR_Table[i],Rtl819XPHY_REGArraytoXTXR_Table[i+1], Rtl819XPHY_REGArraytoXTXR_Table[i+2]);
859 RT_TRACE(COMP_SEND, "phy_SetBBtoDiffRFWithHeaderFile(): ConfigType != BaseBand_Config_PHY_REG\n");
861 //#endif // #if (HAL_CODE_BASE != RTL8192_S)
862 return RT_STATUS_SUCCESS;
868 phy_BB8192S_Config_ParaFile(struct net_device* dev)
870 struct r8192_priv *priv = ieee80211_priv(dev);
871 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
874 //char szBBRegFile[] = RTL819X_PHY_REG;
875 //char szBBRegFile1T2R[] = RTL819X_PHY_REG_1T2R;
876 //char szBBRegPgFile[] = RTL819X_PHY_REG_PG;
877 //char szAGCTableFile[] = RTL819X_AGC_TAB;
878 //char szBBRegto1T1RFile[] = RTL819X_PHY_REG_to1T1R;
879 //char szBBRegto1T2RFile[] = RTL819X_PHY_REG_to1T2R;
881 RT_TRACE(COMP_INIT, "==>phy_BB8192S_Config_ParaFile\n");
884 // 1. Read PHY_REG.TXT BB INIT!!
885 // We will seperate as 1T1R/1T2R/1T2R_GREEN/2T2R
887 if (priv->rf_type == RF_1T2R || priv->rf_type == RF_2T2R ||
888 priv->rf_type == RF_1T1R ||priv->rf_type == RF_2T2R_GREEN)
890 rtStatus = phy_ConfigBBWithHeaderFile(dev,BaseBand_Config_PHY_REG);
891 if(priv->rf_type != RF_2T2R && priv->rf_type != RF_2T2R_GREEN)
892 {//2008.11.10 Added by tynli. The default PHY_REG.txt we read is for 2T2R,
893 //so we should reconfig BB reg with the right PHY parameters.
894 rtStatus = phy_SetBBtoDiffRFWithHeaderFile(dev,BaseBand_Config_PHY_REG);
897 rtStatus = RT_STATUS_FAILURE;
899 if(rtStatus != RT_STATUS_SUCCESS){
900 RT_TRACE(COMP_INIT, "phy_BB8192S_Config_ParaFile():Write BB Reg Fail!!");
901 goto phy_BB8190_Config_ParaFile_Fail;
905 // 2. If EEPROM or EFUSE autoload OK, We must config by PHY_REG_PG.txt
907 if (priv->AutoloadFailFlag == false)
909 rtStatus = phy_ConfigBBWithPgHeaderFile(dev,BaseBand_Config_PHY_REG);
911 if(rtStatus != RT_STATUS_SUCCESS){
912 RT_TRACE(COMP_INIT, "phy_BB8192S_Config_ParaFile():BB_PG Reg Fail!!");
913 goto phy_BB8190_Config_ParaFile_Fail;
917 // 3. BB AGC table Initialization
919 rtStatus = phy_ConfigBBWithHeaderFile(dev,BaseBand_Config_AGC_TAB);
921 if(rtStatus != RT_STATUS_SUCCESS){
922 printk( "phy_BB8192S_Config_ParaFile():AGC Table Fail\n");
923 goto phy_BB8190_Config_ParaFile_Fail;
927 // Check if the CCK HighPower is turned ON.
928 // This is used to calculate PWDB.
929 priv->bCckHighPower = (bool)(rtl8192_QueryBBReg(dev, rFPGA0_XA_HSSIParameter2, 0x200));
932 phy_BB8190_Config_ParaFile_Fail:
936 /*-----------------------------------------------------------------------------
937 * Function: phy_ConfigMACWithHeaderFile()
939 * Overview: This function read BB parameters from Header file we gen, and do register
942 * Input: PADAPTER Adapter
947 * Return: RT_STATUS_SUCCESS: configuration file exist
949 * Note: The format of MACPHY_REG.txt is different from PHY and RF.
950 * [Register][Mask][Value]
951 *---------------------------------------------------------------------------*/
954 phy_ConfigMACWithHeaderFile(struct net_device* dev)
959 //struct r8192_priv *priv = ieee80211_priv(dev);
961 //#if (HAL_CODE_BASE != RTL8192_S)
962 /*if(Adapter->bInHctTest)
964 RT_TRACE(COMP_INIT, DBG_LOUD, ("Rtl819XMACPHY_ArrayDTM\n"));
965 ArrayLength = MACPHY_ArrayLengthDTM;
966 ptrArray = Rtl819XMACPHY_ArrayDTM;
968 else if(pHalData->bTXPowerDataReadFromEEPORM)
970 // RT_TRACE(COMP_INIT, DBG_LOUD, ("Rtl819XMACPHY_Array_PG\n"));
971 // ArrayLength = MACPHY_Array_PGLength;
972 // ptrArray = Rtl819XMACPHY_Array_PG;
975 { //2008.11.06 Modified by tynli.
976 RT_TRACE(COMP_INIT, "Read Rtl819XMACPHY_Array\n");
977 ArrayLength = MAC_2T_ArrayLength;
978 ptrArray = Rtl819XMAC_Array;
981 /*for(i = 0 ;i < ArrayLength;i=i+3){
982 RT_TRACE(COMP_SEND, DBG_LOUD, ("The Rtl819XMACPHY_Array[0] is %lx Rtl819XMACPHY_Array[1] is %lx Rtl819XMACPHY_Array[2] is %lx\n",ptrArray[i], ptrArray[i+1], ptrArray[i+2]));
983 if(ptrArray[i] == 0x318)
985 ptrArray[i+2] = 0x00000800;
986 //DbgPrint("ptrArray[i], ptrArray[i+1], ptrArray[i+2] = %x, %x, %x\n",
987 // ptrArray[i], ptrArray[i+1], ptrArray[i+2]);
989 PHY_SetBBReg(Adapter, ptrArray[i], ptrArray[i+1], ptrArray[i+2]);
991 for(i = 0 ;i < ArrayLength;i=i+2){ // Add by tynli for 2 column
992 write_nic_byte(dev, ptrArray[i], (u8)ptrArray[i+1]);
995 return RT_STATUS_SUCCESS;
998 /*-----------------------------------------------------------------------------
999 * Function: phy_ConfigBBWithHeaderFile()
1001 * Overview: This function read BB parameters from general file format, and do register
1004 * Input: PADAPTER Adapter
1005 * u8 ConfigType 0 => PHY_CONFIG
1010 * Return: RT_STATUS_SUCCESS: configuration file exist
1012 *---------------------------------------------------------------------------*/
1015 phy_ConfigBBWithHeaderFile(struct net_device* dev,u8 ConfigType)
1019 u32* Rtl819XPHY_REGArray_Table;
1020 u32* Rtl819XAGCTAB_Array_Table;
1021 u16 PHY_REGArrayLen, AGCTAB_ArrayLen;
1022 //struct r8192_priv *priv = ieee80211_priv(dev);
1023 //#if (HAL_CODE_BASE != RTL8192_S)
1024 /*if(Adapter->bInHctTest)
1027 AGCTAB_ArrayLen = AGCTAB_ArrayLengthDTM;
1028 Rtl819XAGCTAB_Array_Table = Rtl819XAGCTAB_ArrayDTM;
1030 if(pHalData->RF_Type == RF_2T4R)
1032 PHY_REGArrayLen = PHY_REGArrayLengthDTM;
1033 Rtl819XPHY_REGArray_Table = Rtl819XPHY_REGArrayDTM;
1035 else if (pHalData->RF_Type == RF_1T2R)
1037 PHY_REGArrayLen = PHY_REG_1T2RArrayLengthDTM;
1038 Rtl819XPHY_REGArray_Table = Rtl819XPHY_REG_1T2RArrayDTM;
1046 // 2008.11.06 Modified by tynli.
1048 AGCTAB_ArrayLen = AGCTAB_ArrayLength;
1049 Rtl819XAGCTAB_Array_Table = Rtl819XAGCTAB_Array;
1050 PHY_REGArrayLen = PHY_REG_2T2RArrayLength; // Default RF_type: 2T2R
1051 Rtl819XPHY_REGArray_Table = Rtl819XPHY_REG_Array;
1054 if(ConfigType == BaseBand_Config_PHY_REG)
1056 for(i=0;i<PHY_REGArrayLen;i=i+2)
1058 if (Rtl819XPHY_REGArray_Table[i] == 0xfe)
1060 else if (Rtl819XPHY_REGArray_Table[i] == 0xfd)
1062 else if (Rtl819XPHY_REGArray_Table[i] == 0xfc)
1064 else if (Rtl819XPHY_REGArray_Table[i] == 0xfb)
1066 else if (Rtl819XPHY_REGArray_Table[i] == 0xfa)
1068 else if (Rtl819XPHY_REGArray_Table[i] == 0xf9)
1070 rtl8192_setBBreg(dev, Rtl819XPHY_REGArray_Table[i], bMaskDWord, Rtl819XPHY_REGArray_Table[i+1]);
1071 //RT_TRACE(COMP_SEND, "The Rtl819XPHY_REGArray_Table[0] is %lx Rtl819XPHY_REGArray[1] is %lx \n",Rtl819XPHY_REGArray_Table[i], Rtl819XPHY_REGArray_Table[i+1]);
1075 else if(ConfigType == BaseBand_Config_AGC_TAB){
1076 for(i=0;i<AGCTAB_ArrayLen;i=i+2)
1078 rtl8192_setBBreg(dev, Rtl819XAGCTAB_Array_Table[i], bMaskDWord, Rtl819XAGCTAB_Array_Table[i+1]);
1081 //#endif // #if (HAL_CODE_BASE != RTL8192_S)
1082 return RT_STATUS_SUCCESS;
1085 /*-----------------------------------------------------------------------------
1086 * Function: phy_ConfigBBWithPgHeaderFile
1088 * Overview: Config PHY_REG_PG array
1098 * 11/06/2008 MHC Add later!!!!!!.. Please modify for new files!!!!
1099 * 11/10/2008 tynli Modify to mew files.
1101 *---------------------------------------------------------------------------*/
1103 phy_ConfigBBWithPgHeaderFile(struct net_device* dev,u8 ConfigType)
1107 u32* Rtl819XPHY_REGArray_Table_PG;
1108 u16 PHY_REGArrayPGLen;
1109 //struct r8192_priv *priv = ieee80211_priv(dev);
1110 //#if (HAL_CODE_BASE != RTL8192_S)
1111 // Default: pHalData->RF_Type = RF_2T2R.
1113 PHY_REGArrayPGLen = PHY_REG_Array_PGLength;
1114 Rtl819XPHY_REGArray_Table_PG = Rtl819XPHY_REG_Array_PG;
1116 if(ConfigType == BaseBand_Config_PHY_REG)
1118 for(i=0;i<PHY_REGArrayPGLen;i=i+3)
1120 if (Rtl819XPHY_REGArray_Table_PG[i] == 0xfe)
1122 else if (Rtl819XPHY_REGArray_Table_PG[i] == 0xfd)
1124 else if (Rtl819XPHY_REGArray_Table_PG[i] == 0xfc)
1126 else if (Rtl819XPHY_REGArray_Table_PG[i] == 0xfb)
1128 else if (Rtl819XPHY_REGArray_Table_PG[i] == 0xfa)
1130 else if (Rtl819XPHY_REGArray_Table_PG[i] == 0xf9)
1132 rtl8192_setBBreg(dev, Rtl819XPHY_REGArray_Table_PG[i], Rtl819XPHY_REGArray_Table_PG[i+1], Rtl819XPHY_REGArray_Table_PG[i+2]);
1133 //RT_TRACE(COMP_SEND, "The Rtl819XPHY_REGArray_Table_PG[0] is %lx Rtl819XPHY_REGArray_Table_PG[1] is %lx \n",
1134 // Rtl819XPHY_REGArray_Table_PG[i], Rtl819XPHY_REGArray_Table_PG[i+1]);
1137 RT_TRACE(COMP_SEND, "phy_ConfigBBWithPgHeaderFile(): ConfigType != BaseBand_Config_PHY_REG\n");
1139 return RT_STATUS_SUCCESS;
1141 } /* phy_ConfigBBWithPgHeaderFile */
1143 /*-----------------------------------------------------------------------------
1144 * Function: PHY_ConfigRFWithHeaderFile()
1146 * Overview: This function read RF parameters from general file format, and do RF 3-wire
1148 * Input: PADAPTER Adapter
1150 * RF90_RADIO_PATH_E eRFPath
1154 * Return: RT_STATUS_SUCCESS: configuration file exist
1156 * Note: Delay may be required for RF configuration
1157 *---------------------------------------------------------------------------*/
1158 //in 8256 phy_RF8256_Config_ParaFile only
1159 //RT_STATUS PHY_ConfigRFWithHeaderFile(struct net_device* dev,RF90_RADIO_PATH_E eRFPath)
1160 u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device* dev, RF90_RADIO_PATH_E eRFPath)
1163 struct r8192_priv *priv = ieee80211_priv(dev);
1166 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
1167 u32 *Rtl819XRadioA_Array_Table;
1168 u32 *Rtl819XRadioB_Array_Table;
1169 //u32* Rtl819XRadioC_Array_Table;
1170 //u32* Rtl819XRadioD_Array_Table;
1171 u16 RadioA_ArrayLen,RadioB_ArrayLen;
1173 { //2008.11.06 Modified by tynli
1174 RadioA_ArrayLen = RadioA_1T_ArrayLength;
1175 Rtl819XRadioA_Array_Table=Rtl819XRadioA_Array;
1176 Rtl819XRadioB_Array_Table=Rtl819XRadioB_Array;
1177 RadioB_ArrayLen = RadioB_ArrayLength;
1180 if( priv->rf_type == RF_2T2R_GREEN )
1182 Rtl819XRadioB_Array_Table = Rtl819XRadioB_GM_Array;
1183 RadioB_ArrayLen = RadioB_GM_ArrayLength;
1187 Rtl819XRadioB_Array_Table = Rtl819XRadioB_Array;
1188 RadioB_ArrayLen = RadioB_ArrayLength;
1191 rtStatus = RT_STATUS_SUCCESS;
1193 // When initialization, we want the delay function(mdelay(), delay_us()
1194 // ==> actually we call PlatformStallExecution()) to do NdisStallExecution()
1195 // [busy wait] instead of NdisMSleep(). So we acquire RT_INITIAL_SPINLOCK
1196 // to run at Dispatch level to achive it.
1197 //cosa PlatformAcquireSpinLock(Adapter, RT_INITIAL_SPINLOCK);
1201 for(i = 0;i<RadioA_ArrayLen; i=i+2){
1202 if(Rtl819XRadioA_Array_Table[i] == 0xfe)
1203 { // Deay specific ms. Only RF configuration require delay.
1204 //#if (DEV_BUS_TYPE == USB_INTERFACE)
1207 else if (Rtl819XRadioA_Array_Table[i] == 0xfd)
1209 else if (Rtl819XRadioA_Array_Table[i] == 0xfc)
1211 else if (Rtl819XRadioA_Array_Table[i] == 0xfb)
1213 //PlatformStallExecution(50);
1214 else if (Rtl819XRadioA_Array_Table[i] == 0xfa)
1216 else if (Rtl819XRadioA_Array_Table[i] == 0xf9)
1220 rtl8192_phy_SetRFReg(dev, eRFPath, Rtl819XRadioA_Array_Table[i], bRFRegOffsetMask, Rtl819XRadioA_Array_Table[i+1]);
1225 for(i = 0;i<RadioB_ArrayLen; i=i+2){
1226 if(Rtl819XRadioB_Array_Table[i] == 0xfe)
1227 { // Deay specific ms. Only RF configuration require delay.
1228 //#if (DEV_BUS_TYPE == USB_INTERFACE)
1231 else if (Rtl819XRadioB_Array_Table[i] == 0xfd)
1233 else if (Rtl819XRadioB_Array_Table[i] == 0xfc)
1235 else if (Rtl819XRadioB_Array_Table[i] == 0xfb)
1237 else if (Rtl819XRadioB_Array_Table[i] == 0xfa)
1239 else if (Rtl819XRadioB_Array_Table[i] == 0xf9)
1243 rtl8192_phy_SetRFReg(dev, eRFPath, Rtl819XRadioB_Array_Table[i], bRFRegOffsetMask, Rtl819XRadioB_Array_Table[i+1]);
1259 /*-----------------------------------------------------------------------------
1260 * Function: PHY_CheckBBAndRFOK()
1262 * Overview: This function is write register and then readback to make sure whether
1263 * BB[PHY0, PHY1], RF[Patha, path b, path c, path d] is Ok
1265 * Input: PADAPTER Adapter
1266 * HW90_BLOCK_E CheckBlock
1267 * RF90_RADIO_PATH_E eRFPath // it is used only when CheckBlock is HW90_BLOCK_RF
1271 * Return: RT_STATUS_SUCCESS: PHY is OK
1273 * Note: This function may be removed in the ASIC
1274 *---------------------------------------------------------------------------*/
1275 //in 8256 phy_RF8256_Config_HardCode
1276 //but we don't use it temp
1279 struct net_device* dev,
1280 HW90_BLOCK_E CheckBlock,
1281 RF90_RADIO_PATH_E eRFPath
1284 //struct r8192_priv *priv = ieee80211_priv(dev);
1285 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
1286 u32 i, CheckTimes = 4,ulRegRead = 0;
1288 u32 WriteData[] = {0xfffff027, 0xaa55a02f, 0x00000027, 0x55aa502f};
1290 // Initialize register address offset to be checked
1291 WriteAddr[HW90_BLOCK_MAC] = 0x100;
1292 WriteAddr[HW90_BLOCK_PHY0] = 0x900;
1293 WriteAddr[HW90_BLOCK_PHY1] = 0x800;
1294 WriteAddr[HW90_BLOCK_RF] = 0x3;
1296 for(i=0 ; i < CheckTimes ; i++)
1300 // Write Data to register and readback
1304 case HW90_BLOCK_MAC:
1305 //RT_ASSERT(FALSE, ("PHY_CheckBBRFOK(): Never Write 0x100 here!"));
1306 RT_TRACE(COMP_INIT, "PHY_CheckBBRFOK(): Never Write 0x100 here!\n");
1309 case HW90_BLOCK_PHY0:
1310 case HW90_BLOCK_PHY1:
1311 write_nic_dword(dev, WriteAddr[CheckBlock], WriteData[i]);
1312 ulRegRead = read_nic_dword(dev, WriteAddr[CheckBlock]);
1316 // When initialization, we want the delay function(mdelay(), delay_us()
1317 // ==> actually we call PlatformStallExecution()) to do NdisStallExecution()
1318 // [busy wait] instead of NdisMSleep(). So we acquire RT_INITIAL_SPINLOCK
1319 // to run at Dispatch level to achive it.
1320 //cosa PlatformAcquireSpinLock(dev, RT_INITIAL_SPINLOCK);
1321 WriteData[i] &= 0xfff;
1322 rtl8192_phy_SetRFReg(dev, eRFPath, WriteAddr[HW90_BLOCK_RF], bRFRegOffsetMask, WriteData[i]);
1323 // TODO: we should not delay for such a long time. Ask SD3
1325 ulRegRead = rtl8192_phy_QueryRFReg(dev, eRFPath, WriteAddr[HW90_BLOCK_RF], bMaskDWord);
1327 //cosa PlatformReleaseSpinLock(dev, RT_INITIAL_SPINLOCK);
1331 rtStatus = RT_STATUS_FAILURE;
1337 // Check whether readback data is correct
1339 if(ulRegRead != WriteData[i])
1341 //RT_TRACE(COMP_FPGA, ("ulRegRead: %x, WriteData: %x \n", ulRegRead, WriteData[i]));
1342 RT_TRACE(COMP_ERR, "read back error(read:%x, write:%x)\n", ulRegRead, WriteData[i]);
1343 rtStatus = RT_STATUS_FAILURE;
1351 //no use temp in windows driver
1354 PHY_SetRFPowerState8192SUsb(
1355 struct net_device* dev,
1356 RF_POWER_STATE RFPowerState
1359 struct r8192_priv *priv = ieee80211_priv(dev);
1360 bool WaitShutDown = FALSE;
1362 //RF90_RADIO_PATH_E eRFPath;
1364 BB_REGISTER_DEFINITION_T *pPhyReg;
1366 if(priv->SetRFPowerStateInProgress == TRUE)
1369 priv->SetRFPowerStateInProgress = TRUE;
1371 // TODO: Emily, 2006.11.21, we should rewrite this function
1373 if(RFPowerState==RF_SHUT_DOWN)
1375 RFPowerState=RF_OFF;
1380 priv->RFPowerState = RFPowerState;
1381 switch( priv->rf_chip )
1385 switch( RFPowerState )
1399 switch( RFPowerState )
1408 for(eRFPath=(RF90_RADIO_PATH_E)RF90_PATH_A; eRFPath < RF90_PATH_MAX; eRFPath++)
1410 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
1413 pPhyReg = &priv->PHYRegDef[eRFPath];
1414 rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV, bRFSI_RFENV);
1415 rtl8192_setBBreg(dev, pPhyReg->rfintfo, bRFSI_RFENV, 0);
1423 }// switch( priv->rf_chip )
1425 priv->SetRFPowerStateInProgress = FALSE;
1430 //no use temp in windows driver
1432 PHY_UpdateInitialGain(
1433 struct net_device* dev
1436 struct r8192_priv *priv = ieee80211_priv(dev);
1437 //unsigned char *IGTable;
1438 //u8 DIG_CurrentInitialGain = 4;
1440 switch(priv->rf_chip)
1453 RT_TRACE(COMP_DBG, "PHY_UpdateInitialGain(): unknown rf_chip: %#X\n", priv->rf_chip);
1459 //YJ,modified,090107
1460 void PHY_GetHWRegOriginalValue(struct net_device* dev)
1462 struct r8192_priv *priv = ieee80211_priv(dev);
1464 // read tx power offset
1466 priv->MCSTxPowerLevelOriginalOffset[0] =
1467 rtl8192_QueryBBReg(dev, rTxAGC_Rate18_06, bMaskDWord);
1468 priv->MCSTxPowerLevelOriginalOffset[1] =
1469 rtl8192_QueryBBReg(dev, rTxAGC_Rate54_24, bMaskDWord);
1470 priv->MCSTxPowerLevelOriginalOffset[2] =
1471 rtl8192_QueryBBReg(dev, rTxAGC_Mcs03_Mcs00, bMaskDWord);
1472 priv->MCSTxPowerLevelOriginalOffset[3] =
1473 rtl8192_QueryBBReg(dev, rTxAGC_Mcs07_Mcs04, bMaskDWord);
1474 priv->MCSTxPowerLevelOriginalOffset[4] =
1475 rtl8192_QueryBBReg(dev, rTxAGC_Mcs11_Mcs08, bMaskDWord);
1476 priv->MCSTxPowerLevelOriginalOffset[5] =
1477 rtl8192_QueryBBReg(dev, rTxAGC_Mcs15_Mcs12, bMaskDWord);
1480 priv->MCSTxPowerLevelOriginalOffset[6] =
1481 rtl8192_QueryBBReg(dev, rTxAGC_CCK_Mcs32, bMaskDWord);
1482 RT_TRACE(COMP_INIT, "Legacy OFDM =%08x/%08x HT_OFDM=%08x/%08x/%08x/%08x\n",
1483 priv->MCSTxPowerLevelOriginalOffset[0], priv->MCSTxPowerLevelOriginalOffset[1] ,
1484 priv->MCSTxPowerLevelOriginalOffset[2], priv->MCSTxPowerLevelOriginalOffset[3] ,
1485 priv->MCSTxPowerLevelOriginalOffset[4], priv->MCSTxPowerLevelOriginalOffset[5] );
1487 // read rx initial gain
1488 priv->DefaultInitialGain[0] = rtl8192_QueryBBReg(dev, rOFDM0_XAAGCCore1, bMaskByte0);
1489 priv->DefaultInitialGain[1] = rtl8192_QueryBBReg(dev, rOFDM0_XBAGCCore1, bMaskByte0);
1490 priv->DefaultInitialGain[2] = rtl8192_QueryBBReg(dev, rOFDM0_XCAGCCore1, bMaskByte0);
1491 priv->DefaultInitialGain[3] = rtl8192_QueryBBReg(dev, rOFDM0_XDAGCCore1, bMaskByte0);
1492 RT_TRACE(COMP_INIT, "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x) \n",
1493 priv->DefaultInitialGain[0], priv->DefaultInitialGain[1],
1494 priv->DefaultInitialGain[2], priv->DefaultInitialGain[3]);
1497 priv->framesync = rtl8192_QueryBBReg(dev, rOFDM0_RxDetector3, bMaskByte0);
1498 priv->framesyncC34 = rtl8192_QueryBBReg(dev, rOFDM0_RxDetector2, bMaskDWord);
1499 RT_TRACE(COMP_INIT, "Default framesync (0x%x) = 0x%x \n",
1500 rOFDM0_RxDetector3, priv->framesync);
1502 //YJ,modified,090107,end
1507 * Function: phy_InitBBRFRegisterDefinition
1509 * OverView: Initialize Register definition offset for Radio Path A/B/C/D
1516 * Note: The initialization value is constant and it should never be changes
1519 static void phy_InitBBRFRegisterDefinition( struct net_device* dev)
1521 struct r8192_priv *priv = ieee80211_priv(dev);
1523 // RF Interface Sowrtware Control
1524 priv->PHYRegDef[RF90_PATH_A].rfintfs = rFPGA0_XAB_RFInterfaceSW; // 16 LSBs if read 32-bit from 0x870
1525 priv->PHYRegDef[RF90_PATH_B].rfintfs = rFPGA0_XAB_RFInterfaceSW; // 16 MSBs if read 32-bit from 0x870 (16-bit for 0x872)
1526 priv->PHYRegDef[RF90_PATH_C].rfintfs = rFPGA0_XCD_RFInterfaceSW;// 16 LSBs if read 32-bit from 0x874
1527 priv->PHYRegDef[RF90_PATH_D].rfintfs = rFPGA0_XCD_RFInterfaceSW;// 16 MSBs if read 32-bit from 0x874 (16-bit for 0x876)
1529 // RF Interface Readback Value
1530 priv->PHYRegDef[RF90_PATH_A].rfintfi = rFPGA0_XAB_RFInterfaceRB; // 16 LSBs if read 32-bit from 0x8E0
1531 priv->PHYRegDef[RF90_PATH_B].rfintfi = rFPGA0_XAB_RFInterfaceRB;// 16 MSBs if read 32-bit from 0x8E0 (16-bit for 0x8E2)
1532 priv->PHYRegDef[RF90_PATH_C].rfintfi = rFPGA0_XCD_RFInterfaceRB;// 16 LSBs if read 32-bit from 0x8E4
1533 priv->PHYRegDef[RF90_PATH_D].rfintfi = rFPGA0_XCD_RFInterfaceRB;// 16 MSBs if read 32-bit from 0x8E4 (16-bit for 0x8E6)
1535 // RF Interface Output (and Enable)
1536 priv->PHYRegDef[RF90_PATH_A].rfintfo = rFPGA0_XA_RFInterfaceOE; // 16 LSBs if read 32-bit from 0x860
1537 priv->PHYRegDef[RF90_PATH_B].rfintfo = rFPGA0_XB_RFInterfaceOE; // 16 LSBs if read 32-bit from 0x864
1538 priv->PHYRegDef[RF90_PATH_C].rfintfo = rFPGA0_XC_RFInterfaceOE;// 16 LSBs if read 32-bit from 0x868
1539 priv->PHYRegDef[RF90_PATH_D].rfintfo = rFPGA0_XD_RFInterfaceOE;// 16 LSBs if read 32-bit from 0x86C
1541 // RF Interface (Output and) Enable
1542 priv->PHYRegDef[RF90_PATH_A].rfintfe = rFPGA0_XA_RFInterfaceOE; // 16 MSBs if read 32-bit from 0x860 (16-bit for 0x862)
1543 priv->PHYRegDef[RF90_PATH_B].rfintfe = rFPGA0_XB_RFInterfaceOE; // 16 MSBs if read 32-bit from 0x864 (16-bit for 0x866)
1544 priv->PHYRegDef[RF90_PATH_C].rfintfe = rFPGA0_XC_RFInterfaceOE;// 16 MSBs if read 32-bit from 0x86A (16-bit for 0x86A)
1545 priv->PHYRegDef[RF90_PATH_D].rfintfe = rFPGA0_XD_RFInterfaceOE;// 16 MSBs if read 32-bit from 0x86C (16-bit for 0x86E)
1547 //Addr of LSSI. Wirte RF register by driver
1548 priv->PHYRegDef[RF90_PATH_A].rf3wireOffset = rFPGA0_XA_LSSIParameter; //LSSI Parameter
1549 priv->PHYRegDef[RF90_PATH_B].rf3wireOffset = rFPGA0_XB_LSSIParameter;
1550 priv->PHYRegDef[RF90_PATH_C].rf3wireOffset = rFPGA0_XC_LSSIParameter;
1551 priv->PHYRegDef[RF90_PATH_D].rf3wireOffset = rFPGA0_XD_LSSIParameter;
1554 priv->PHYRegDef[RF90_PATH_A].rfLSSI_Select = rFPGA0_XAB_RFParameter; //BB Band Select
1555 priv->PHYRegDef[RF90_PATH_B].rfLSSI_Select = rFPGA0_XAB_RFParameter;
1556 priv->PHYRegDef[RF90_PATH_C].rfLSSI_Select = rFPGA0_XCD_RFParameter;
1557 priv->PHYRegDef[RF90_PATH_D].rfLSSI_Select = rFPGA0_XCD_RFParameter;
1559 // Tx AGC Gain Stage (same for all path. Should we remove this?)
1560 priv->PHYRegDef[RF90_PATH_A].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
1561 priv->PHYRegDef[RF90_PATH_B].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
1562 priv->PHYRegDef[RF90_PATH_C].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
1563 priv->PHYRegDef[RF90_PATH_D].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
1565 // Tranceiver A~D HSSI Parameter-1
1566 priv->PHYRegDef[RF90_PATH_A].rfHSSIPara1 = rFPGA0_XA_HSSIParameter1; //wire control parameter1
1567 priv->PHYRegDef[RF90_PATH_B].rfHSSIPara1 = rFPGA0_XB_HSSIParameter1; //wire control parameter1
1568 priv->PHYRegDef[RF90_PATH_C].rfHSSIPara1 = rFPGA0_XC_HSSIParameter1; //wire control parameter1
1569 priv->PHYRegDef[RF90_PATH_D].rfHSSIPara1 = rFPGA0_XD_HSSIParameter1; //wire control parameter1
1571 // Tranceiver A~D HSSI Parameter-2
1572 priv->PHYRegDef[RF90_PATH_A].rfHSSIPara2 = rFPGA0_XA_HSSIParameter2; //wire control parameter2
1573 priv->PHYRegDef[RF90_PATH_B].rfHSSIPara2 = rFPGA0_XB_HSSIParameter2; //wire control parameter2
1574 priv->PHYRegDef[RF90_PATH_C].rfHSSIPara2 = rFPGA0_XC_HSSIParameter2; //wire control parameter2
1575 priv->PHYRegDef[RF90_PATH_D].rfHSSIPara2 = rFPGA0_XD_HSSIParameter2; //wire control parameter1
1577 // RF switch Control
1578 priv->PHYRegDef[RF90_PATH_A].rfSwitchControl = rFPGA0_XAB_SwitchControl; //TR/Ant switch control
1579 priv->PHYRegDef[RF90_PATH_B].rfSwitchControl = rFPGA0_XAB_SwitchControl;
1580 priv->PHYRegDef[RF90_PATH_C].rfSwitchControl = rFPGA0_XCD_SwitchControl;
1581 priv->PHYRegDef[RF90_PATH_D].rfSwitchControl = rFPGA0_XCD_SwitchControl;
1584 priv->PHYRegDef[RF90_PATH_A].rfAGCControl1 = rOFDM0_XAAGCCore1;
1585 priv->PHYRegDef[RF90_PATH_B].rfAGCControl1 = rOFDM0_XBAGCCore1;
1586 priv->PHYRegDef[RF90_PATH_C].rfAGCControl1 = rOFDM0_XCAGCCore1;
1587 priv->PHYRegDef[RF90_PATH_D].rfAGCControl1 = rOFDM0_XDAGCCore1;
1590 priv->PHYRegDef[RF90_PATH_A].rfAGCControl2 = rOFDM0_XAAGCCore2;
1591 priv->PHYRegDef[RF90_PATH_B].rfAGCControl2 = rOFDM0_XBAGCCore2;
1592 priv->PHYRegDef[RF90_PATH_C].rfAGCControl2 = rOFDM0_XCAGCCore2;
1593 priv->PHYRegDef[RF90_PATH_D].rfAGCControl2 = rOFDM0_XDAGCCore2;
1596 priv->PHYRegDef[RF90_PATH_A].rfRxIQImbalance = rOFDM0_XARxIQImbalance;
1597 priv->PHYRegDef[RF90_PATH_B].rfRxIQImbalance = rOFDM0_XBRxIQImbalance;
1598 priv->PHYRegDef[RF90_PATH_C].rfRxIQImbalance = rOFDM0_XCRxIQImbalance;
1599 priv->PHYRegDef[RF90_PATH_D].rfRxIQImbalance = rOFDM0_XDRxIQImbalance;
1602 priv->PHYRegDef[RF90_PATH_A].rfRxAFE = rOFDM0_XARxAFE;
1603 priv->PHYRegDef[RF90_PATH_B].rfRxAFE = rOFDM0_XBRxAFE;
1604 priv->PHYRegDef[RF90_PATH_C].rfRxAFE = rOFDM0_XCRxAFE;
1605 priv->PHYRegDef[RF90_PATH_D].rfRxAFE = rOFDM0_XDRxAFE;
1608 priv->PHYRegDef[RF90_PATH_A].rfTxIQImbalance = rOFDM0_XATxIQImbalance;
1609 priv->PHYRegDef[RF90_PATH_B].rfTxIQImbalance = rOFDM0_XBTxIQImbalance;
1610 priv->PHYRegDef[RF90_PATH_C].rfTxIQImbalance = rOFDM0_XCTxIQImbalance;
1611 priv->PHYRegDef[RF90_PATH_D].rfTxIQImbalance = rOFDM0_XDTxIQImbalance;
1614 priv->PHYRegDef[RF90_PATH_A].rfTxAFE = rOFDM0_XATxAFE;
1615 priv->PHYRegDef[RF90_PATH_B].rfTxAFE = rOFDM0_XBTxAFE;
1616 priv->PHYRegDef[RF90_PATH_C].rfTxAFE = rOFDM0_XCTxAFE;
1617 priv->PHYRegDef[RF90_PATH_D].rfTxAFE = rOFDM0_XDTxAFE;
1619 // Tranceiver LSSI Readback SI mode
1620 priv->PHYRegDef[RF90_PATH_A].rfLSSIReadBack = rFPGA0_XA_LSSIReadBack;
1621 priv->PHYRegDef[RF90_PATH_B].rfLSSIReadBack = rFPGA0_XB_LSSIReadBack;
1622 priv->PHYRegDef[RF90_PATH_C].rfLSSIReadBack = rFPGA0_XC_LSSIReadBack;
1623 priv->PHYRegDef[RF90_PATH_D].rfLSSIReadBack = rFPGA0_XD_LSSIReadBack;
1625 // Tranceiver LSSI Readback PI mode
1626 priv->PHYRegDef[RF90_PATH_A].rfLSSIReadBackPi = TransceiverA_HSPI_Readback;
1627 priv->PHYRegDef[RF90_PATH_B].rfLSSIReadBackPi = TransceiverB_HSPI_Readback;
1628 //pHalData->PHYRegDef[RF90_PATH_C].rfLSSIReadBackPi = rFPGA0_XC_LSSIReadBack;
1629 //pHalData->PHYRegDef[RF90_PATH_D].rfLSSIReadBackPi = rFPGA0_XD_LSSIReadBack;
1635 // Description: Change RF power state.
1637 // Assumption: This function must be executed in re-schdulable context,
1638 // ie. PASSIVE_LEVEL.
1640 // 050823, by rcnjko.
1641 //not understand it seem's use in init
1642 //SetHwReg8192SUsb--->HalFunc.SetHwRegHandler
1643 bool PHY_SetRFPowerState(struct net_device* dev, RT_RF_POWER_STATE eRFPowerState)
1645 struct r8192_priv *priv = ieee80211_priv(dev);
1646 bool bResult = FALSE;
1648 RT_TRACE(COMP_RF, "---------> PHY_SetRFPowerState(): eRFPowerState(%d)\n", eRFPowerState);
1650 if(eRFPowerState == priv->ieee80211->eRFPowerState)
1652 RT_TRACE(COMP_RF, "<--------- PHY_SetRFPowerState(): discard the request for eRFPowerState(%d) is the same.\n", eRFPowerState);
1656 bResult = phy_SetRFPowerState8192SU(dev, eRFPowerState);
1658 RT_TRACE(COMP_RF, "<--------- PHY_SetRFPowerState(): bResult(%d)\n", bResult);
1664 static bool phy_SetRFPowerState8192SU(struct net_device* dev,RT_RF_POWER_STATE eRFPowerState)
1666 struct r8192_priv *priv = ieee80211_priv(dev);
1667 bool bResult = TRUE;
1672 if(priv->SetRFPowerStateInProgress == TRUE)
1675 priv->SetRFPowerStateInProgress = TRUE;
1677 switch(priv->rf_chip )
1680 switch( eRFPowerState )
1683 write_nic_dword(dev, WFM5, FW_BB_RESET_ENABLE);
1684 write_nic_word(dev, CMDR, 0x37FC);
1685 write_nic_byte(dev, PHY_CCA, 0x3);
1686 write_nic_byte(dev, TXPAUSE, 0x00);
1687 write_nic_byte(dev, SPS1_CTRL, 0x64);
1691 // In current solution, RFSleep=RFOff in order to save power under 802.11 power save.
1692 // By Bruce, 2008-01-16.
1696 if (priv->ieee80211->eRFPowerState == eRfSleep || priv->ieee80211->eRFPowerState == eRfOff)
1699 //RF Off/Sleep sequence. Designed/tested from SD4 Scott, SD1 Grent and Jonbon.
1700 // Added by Bruce, 2008-11-22.
1702 //==================================================================
1703 // (0) Disable FW BB reset checking
1704 write_nic_dword(dev, WFM5, FW_BB_RESET_DISABLE);
1706 // (1) Switching Power Supply Register : Disable LD12 & SW12 (for IT)
1707 u1bTmp = read_nic_byte(dev, LDOV12D_CTRL);
1709 write_nic_byte(dev, LDOV12D_CTRL, u1bTmp);
1711 write_nic_byte(dev, SPS1_CTRL, 0x0);
1712 write_nic_byte(dev, TXPAUSE, 0xFF);
1714 // (2) MAC Tx/Rx enable, BB enable, CCK/OFDM enable
1715 write_nic_word(dev, CMDR, 0x77FC);
1716 write_nic_byte(dev, PHY_CCA, 0x0);
1719 write_nic_word(dev, CMDR, 0x37FC);
1722 write_nic_word(dev, CMDR, 0x77FC);
1725 // (3) Reset BB TRX blocks
1726 write_nic_word(dev, CMDR, 0x57FC);
1731 //RT_ASSERT(FALSE, ("phy_SetRFPowerState8192SU(): unknown state to set: 0x%X!!!\n", eRFPowerState));
1737 priv->ieee80211->eRFPowerState = eRFPowerState;
1741 // Update current RF state variable.
1742 priv->ieee80211->eRFPowerState = eRFPowerState;
1744 switch(priv->rf_chip )
1747 switch(priv->ieee80211->eRFPowerState)
1751 //If Rf off reason is from IPS, Led should blink with no link, by Maddest 071015
1753 if(pMgntInfo->RfOffReason==RF_CHANGE_BY_IPS )
1755 dev->HalFunc.LedControlHandler(dev,LED_CTL_NO_LINK);
1759 // Turn off LED if RF is not ON.
1760 dev->HalFunc.LedControlHandler(dev, LED_CTL_POWER_OFF);
1765 // Turn on RF we are still linked, which might happen when
1766 // we quickly turn off and on HW RF. 2006.05.12, by rcnjko.
1767 if( pMgntInfo->bMediaConnect == TRUE )
1769 dev->HalFunc.LedControlHandler(dev, LED_CTL_LINK);
1773 // Turn off LED if RF is not ON.
1774 dev->HalFunc.LedControlHandler(dev, LED_CTL_NO_LINK);
1786 RT_TRACE(COMP_RF, "phy_SetRFPowerState8192SU(): Unknown RF type\n");
1791 priv->SetRFPowerStateInProgress = FALSE;
1796 /*-----------------------------------------------------------------------------
1797 * Function: GetTxPowerLevel8190()
1799 * Overview: This function is export to "common" moudule
1801 * Input: PADAPTER Adapter
1802 * psByte Power Level
1808 *---------------------------------------------------------------------------*/
1811 PHY_GetTxPowerLevel8192S(
1812 struct net_device* dev,
1816 struct r8192_priv *priv = ieee80211_priv(dev);
1820 // Because the Tx power indexes are different, we report the maximum of them to
1821 // meet the CCX TPC request. By Bruce, 2008-01-31.
1825 TxPwrLevel = priv->CurrentCckTxPwrIdx;
1826 TxPwrDbm = phy_TxPwrIdxToDbm(dev, WIRELESS_MODE_B, TxPwrLevel);
1829 TxPwrLevel = priv->CurrentOfdm24GTxPwrIdx + priv->LegacyHTTxPowerDiff;
1831 // Compare with Legacy OFDM Tx power.
1832 if(phy_TxPwrIdxToDbm(dev, WIRELESS_MODE_G, TxPwrLevel) > TxPwrDbm)
1833 TxPwrDbm = phy_TxPwrIdxToDbm(dev, WIRELESS_MODE_G, TxPwrLevel);
1836 TxPwrLevel = priv->CurrentOfdm24GTxPwrIdx;
1838 // Compare with HT OFDM Tx power.
1839 if(phy_TxPwrIdxToDbm(dev, WIRELESS_MODE_N_24G, TxPwrLevel) > TxPwrDbm)
1840 TxPwrDbm = phy_TxPwrIdxToDbm(dev, WIRELESS_MODE_N_24G, TxPwrLevel);
1842 *powerlevel = TxPwrDbm;
1845 /*-----------------------------------------------------------------------------
1846 * Function: SetTxPowerLevel8190()
1848 * Overview: This function is export to "HalCommon" moudule
1850 * Input: PADAPTER Adapter
1856 * 2008/11/04 MHC We remove EEPROM_93C56.
1857 * We need to move CCX relative code to independet file.
1858 * 2009/01/21 MHC Support new EEPROM format from SD3 requirement.
1859 *---------------------------------------------------------------------------*/
1860 void PHY_SetTxPowerLevel8192S(struct net_device* dev, u8 channel)
1862 struct r8192_priv *priv = ieee80211_priv(dev);
1863 //HAL_DATA_TYPE *pHalData = GET_HAL_DATA(dev);
1864 u8 powerlevel = (u8)EEPROM_Default_TxPower, powerlevelOFDM24G = 0x10;
1865 s8 ant_pwr_diff = 0;
1867 u8 index = (channel -1);
1868 // 2009/01/22 MH Add for new EEPROM format from SD3
1869 u8 pwrdiff[2] = {0};
1870 u8 ht20pwr[2] = {0}, ht40pwr[2] = {0};
1871 u8 rfpath = 0, rfpathnum = 2;
1873 if(priv->bTXPowerDataReadFromEEPORM == FALSE)
1877 * Read predefined TX power index in EEPROM
1881 // Mainly we use RF-A Tx Power to write the Tx Power registers, but the RF-B Tx
1882 // Power must be calculated by the antenna diff.
1883 // So we have to rewrite Antenna gain offset register here.
1884 // Please refer to BB register 0x80c
1886 // 2. For OFDM 1T or 2T
1890 powerlevel = priv->RfTxPwrLevelCck[0][index];
1892 if (priv->rf_type == RF_1T2R || priv->rf_type == RF_1T1R)
1894 // Read HT 40 OFDM TX power
1895 powerlevelOFDM24G = priv->RfTxPwrLevelOfdm1T[0][index];
1896 // RF B HT OFDM pwr-RFA HT OFDM pwr
1897 // Only one RF we need not to decide B <-> A pwr diff
1899 // Legacy<->HT pwr diff, we only care about path A.
1901 // We only assume 1T as RF path A
1903 ht20pwr[0] = ht40pwr[0] = priv->RfTxPwrLevelOfdm1T[0][index];
1905 else if (priv->rf_type == RF_2T2R)
1907 // Read HT 40 OFDM TX power
1908 powerlevelOFDM24G = priv->RfTxPwrLevelOfdm2T[0][index];
1909 // RF B HT OFDM pwr-RFA HT OFDM pwr
1910 ant_pwr_diff = priv->RfTxPwrLevelOfdm2T[1][index] -
1911 priv->RfTxPwrLevelOfdm2T[0][index];
1912 // RF B (HT OFDM pwr+legacy-ht-diff) -(RFA HT OFDM pwr+legacy-ht-diff)
1913 // We can not handle Path B&A HT/Legacy pwr diff for 92S now.
1915 //RTPRINT(FPHY, PHY_TXPWR, ("CH-%d HT40 A/B Pwr index = %x/%x(%d/%d)\n",
1916 //channel, priv->RfTxPwrLevelOfdm2T[0][index],
1917 //priv->RfTxPwrLevelOfdm2T[1][index],
1918 //priv->RfTxPwrLevelOfdm2T[0][index],
1919 //priv->RfTxPwrLevelOfdm2T[1][index]));
1921 ht20pwr[0] = ht40pwr[0] = priv->RfTxPwrLevelOfdm2T[0][index];
1922 ht20pwr[1] = ht40pwr[1] = priv->RfTxPwrLevelOfdm2T[1][index];
1926 // 2009/01/21 MH Support new EEPROM format from SD3 requirement
1927 // 2009/02/10 Cosa, Here is only for reg B/C/D to A gain diff.
1929 if (priv->EEPROMVersion == 2) // Defined by SD1 Jong
1931 if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20)
1933 for (rfpath = 0; rfpath < rfpathnum; rfpath++)
1935 // HT 20<->40 pwr diff
1936 pwrdiff[rfpath] = priv->TxPwrHt20Diff[rfpath][index];
1938 // Calculate Antenna pwr diff
1939 if (pwrdiff[rfpath] < 8) // 0~+7
1941 ht20pwr[rfpath] += pwrdiff[rfpath];
1943 else // index8-15=-8~-1
1945 ht20pwr[rfpath] -= (15-pwrdiff[rfpath]);
1949 // RF B HT OFDM pwr-RFA HT OFDM pwr
1950 if (priv->rf_type == RF_2T2R)
1951 ant_pwr_diff = ht20pwr[1] - ht20pwr[0];
1953 //RTPRINT(FPHY, PHY_TXPWR,
1954 //("HT20 to HT40 pwrdiff[A/B]=%d/%d, ant_pwr_diff=%d(B-A=%d-%d)\n",
1955 //pwrdiff[0], pwrdiff[1], ant_pwr_diff, ht20pwr[1], ht20pwr[0]));
1958 // Band Edge scheme is enabled for FCC mode
1959 if (priv->TxPwrbandEdgeFlag == 1/* && pHalData->ChannelPlan == 0*/)
1961 for (rfpath = 0; rfpath < rfpathnum; rfpath++)
1963 pwrdiff[rfpath] = 0;
1964 if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40)
1967 pwrdiff[rfpath] = priv->TxPwrbandEdgeHt40[rfpath][0];
1968 else if (channel >= 9)
1969 pwrdiff[rfpath] = priv->TxPwrbandEdgeHt40[rfpath][1];
1971 pwrdiff[rfpath] = 0;
1973 ht40pwr[rfpath] -= pwrdiff[rfpath];
1975 else if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20)
1978 pwrdiff[rfpath] = priv->TxPwrbandEdgeHt20[rfpath][0];
1979 else if (channel >= 11)
1980 pwrdiff[rfpath] = priv->TxPwrbandEdgeHt20[rfpath][1];
1982 pwrdiff[rfpath] = 0;
1984 ht20pwr[rfpath] -= pwrdiff[rfpath];
1988 if (priv->rf_type == RF_2T2R)
1990 // HT 20/40 must decide if they need to minus BD pwr offset
1991 if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40)
1992 ant_pwr_diff = ht40pwr[1] - ht40pwr[0];
1994 ant_pwr_diff = ht20pwr[1] - ht20pwr[0];
1996 if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20)
1998 if (channel <= 1 || channel >= 11)
2000 //RTPRINT(FPHY, PHY_TXPWR,
2001 //("HT20 Band-edge pwrdiff[A/B]=%d/%d, ant_pwr_diff=%d(B-A=%d-%d)\n",
2002 //pwrdiff[0], pwrdiff[1], ant_pwr_diff, ht20pwr[1], ht20pwr[0]));
2007 if (channel <= 3 || channel >= 9)
2009 //RTPRINT(FPHY, PHY_TXPWR,
2010 //("HT40 Band-edge pwrdiff[A/B]=%d/%d, ant_pwr_diff=%d(B-A=%d-%d)\n",
2011 //pwrdiff[0], pwrdiff[1], ant_pwr_diff, ht40pwr[1], ht40pwr[0]));
2017 //Cosa added for protection, the reg rFPGA0_TxGainStage
2018 // range is from 7~-8, index = 0x0~0xf
2019 if(ant_pwr_diff > 7)
2021 if(ant_pwr_diff < -8)
2024 //RTPRINT(FPHY, PHY_TXPWR,
2025 //("CCK/HT Power index = %x/%x(%d/%d), ant_pwr_diff=%d\n",
2026 //powerlevel, powerlevelOFDM24G, powerlevel, powerlevelOFDM24G, ant_pwr_diff));
2028 ant_pwr_diff &= 0xf;
2030 // Antenna TX power difference
2031 priv->AntennaTxPwDiff[2] = 0;// RF-D, don't care
2032 priv->AntennaTxPwDiff[1] = 0;// RF-C, don't care
2033 priv->AntennaTxPwDiff[0] = (u8)(ant_pwr_diff); // RF-B
2035 // Antenna gain offset from B/C/D to A
2036 u4RegValue = ( priv->AntennaTxPwDiff[2]<<8 |
2037 priv->AntennaTxPwDiff[1]<<4 |
2038 priv->AntennaTxPwDiff[0] );
2040 // Notify Tx power difference for B/C/D to A!!!
2041 rtl8192_setBBreg(dev, rFPGA0_TxGainStage, (bXBTxAGC|bXCTxAGC|bXDTxAGC), u4RegValue);
2045 // CCX 2 S31, AP control of client transmit power:
2046 // 1. We shall not exceed Cell Power Limit as possible as we can.
2047 // 2. Tolerance is +/- 5dB.
2048 // 3. 802.11h Power Contraint takes higher precedence over CCX Cell Power Limit.
2051 // 1. 802.11h power contraint
2053 // 071011, by rcnjko.
2055 #ifdef TODO //WB, 11h has not implemented now.
2056 if( priv->ieee80211->iw_mode != IW_MODE_INFRA && priv->bWithCcxCellPwr &&
2057 channel == priv->ieee80211->current_network.channel)// & priv->ieee80211->mAssoc )
2059 u8 CckCellPwrIdx = phy_DbmToTxPwrIdx(dev, WIRELESS_MODE_B, priv->CcxCellPwr);
2060 u8 LegacyOfdmCellPwrIdx = phy_DbmToTxPwrIdx(dev, WIRELESS_MODE_G, priv->CcxCellPwr);
2061 u8 OfdmCellPwrIdx = phy_DbmToTxPwrIdx(dev, WIRELESS_MODE_N_24G, priv->CcxCellPwr);
2063 RT_TRACE(COMP_TXAGC,
2064 ("CCX Cell Limit: %d dbm => CCK Tx power index : %d, Legacy OFDM Tx power index : %d, OFDM Tx power index: %d\n",
2065 priv->CcxCellPwr, CckCellPwrIdx, LegacyOfdmCellPwrIdx, OfdmCellPwrIdx));
2066 RT_TRACE(COMP_TXAGC,
2067 ("EEPROM channel(%d) => CCK Tx power index: %d, Legacy OFDM Tx power index : %d, OFDM Tx power index: %d\n",
2068 channel, powerlevel, powerlevelOFDM24G + priv->LegacyHTTxPowerDiff, powerlevelOFDM24G));
2071 if(powerlevel > CckCellPwrIdx)
2072 powerlevel = CckCellPwrIdx;
2073 // Legacy OFDM, HT OFDM
2074 if(powerlevelOFDM24G + priv->LegacyHTTxPowerDiff > LegacyOfdmCellPwrIdx)
2076 if((OfdmCellPwrIdx - priv->LegacyHTTxPowerDiff) > 0)
2078 powerlevelOFDM24G = OfdmCellPwrIdx - priv->LegacyHTTxPowerDiff;
2082 powerlevelOFDM24G = 0;
2086 RT_TRACE(COMP_TXAGC,
2087 ("Altered CCK Tx power index : %d, Legacy OFDM Tx power index: %d, OFDM Tx power index: %d\n",
2088 powerlevel, powerlevelOFDM24G + priv->LegacyHTTxPowerDiff, powerlevelOFDM24G));
2092 priv->CurrentCckTxPwrIdx = powerlevel;
2093 priv->CurrentOfdm24GTxPwrIdx = powerlevelOFDM24G;
2095 switch(priv->rf_chip)
2098 //PHY_SetRF8225CckTxPower(dev, powerlevel);
2099 //PHY_SetRF8225OfdmTxPower(dev, powerlevelOFDM24G);
2106 PHY_RF6052SetCckTxPower(dev, powerlevel);
2107 PHY_RF6052SetOFDMTxPower(dev, powerlevelOFDM24G);
2120 // Update transmit power level of all channel supported.
2124 // By Bruce, 2008-02-04.
2126 bool PHY_UpdateTxPowerDbm8192S(struct net_device* dev, long powerInDbm)
2128 struct r8192_priv *priv = ieee80211_priv(dev);
2132 // TODO: A mode Tx power.
2133 u8 CckTxPwrIdx = phy_DbmToTxPwrIdx(dev, WIRELESS_MODE_B, powerInDbm);
2134 u8 OfdmTxPwrIdx = phy_DbmToTxPwrIdx(dev, WIRELESS_MODE_N_24G, powerInDbm);
2136 if(OfdmTxPwrIdx - priv->LegacyHTTxPowerDiff > 0)
2137 OfdmTxPwrIdx -= priv->LegacyHTTxPowerDiff;
2141 for(idx = 0; idx < 14; idx++)
2143 priv->TxPowerLevelCCK[idx] = CckTxPwrIdx;
2144 priv->TxPowerLevelCCK_A[idx] = CckTxPwrIdx;
2145 priv->TxPowerLevelCCK_C[idx] = CckTxPwrIdx;
2146 priv->TxPowerLevelOFDM24G[idx] = OfdmTxPwrIdx;
2147 priv->TxPowerLevelOFDM24G_A[idx] = OfdmTxPwrIdx;
2148 priv->TxPowerLevelOFDM24G_C[idx] = OfdmTxPwrIdx;
2150 for (rf_path = 0; rf_path < 2; rf_path++)
2152 priv->RfTxPwrLevelCck[rf_path][idx] = CckTxPwrIdx;
2153 priv->RfTxPwrLevelOfdm1T[rf_path][idx] = \
2154 priv->RfTxPwrLevelOfdm2T[rf_path][idx] = OfdmTxPwrIdx;
2158 PHY_SetTxPowerLevel8192S(dev, priv->chan);
2165 When beacon interval is changed, the values of the
2166 hw registers should be modified.
2167 By tynli, 2008.10.24.
2171 extern void PHY_SetBeaconHwReg( struct net_device* dev, u16 BeaconInterval)
2175 NewBeaconNum = BeaconInterval *32 - 64;
2176 //PlatformEFIOWrite4Byte(Adapter, WFM3+4, NewBeaconNum);
2177 //PlatformEFIOWrite4Byte(Adapter, WFM3, 0xB026007C);
2178 write_nic_dword(dev, WFM3+4, NewBeaconNum);
2179 write_nic_dword(dev, WFM3, 0xB026007C);
2184 // Map dBm into Tx power index according to
2185 // current HW model, for example, RF and PA, and
2186 // current wireless mode.
2187 // By Bruce, 2008-01-29.
2189 static u8 phy_DbmToTxPwrIdx(
2190 struct net_device* dev,
2191 WIRELESS_MODE WirelessMode,
2195 //struct r8192_priv *priv = ieee80211_priv(dev);
2201 // Tested by MP, we found that CCK Index 0 equals to -7dbm, OFDM legacy equals to
2202 // 3dbm, and OFDM HT equals to 0dbm repectively.
2204 // The mapping may be different by different NICs. Do not use this formula for what needs accurate result.
2205 // By Bruce, 2008-01-29.
2207 switch(WirelessMode)
2209 case WIRELESS_MODE_B:
2213 case WIRELESS_MODE_G:
2214 case WIRELESS_MODE_N_24G:
2221 if((PowerInDbm - Offset) > 0)
2223 TxPwrIdx = (u8)((PowerInDbm - Offset) * 2);
2230 // Tx Power Index is too large.
2231 if(TxPwrIdx > MAX_TXPWR_IDX_NMODE_92S)
2232 TxPwrIdx = MAX_TXPWR_IDX_NMODE_92S;
2238 // Map Tx power index into dBm according to
2239 // current HW model, for example, RF and PA, and
2240 // current wireless mode.
2241 // By Bruce, 2008-01-29.
2243 static long phy_TxPwrIdxToDbm(
2244 struct net_device* dev,
2245 WIRELESS_MODE WirelessMode,
2249 //struct r8192_priv *priv = ieee80211_priv(dev);
2254 // Tested by MP, we found that CCK Index 0 equals to -7dbm, OFDM legacy equals to
2255 // 3dbm, and OFDM HT equals to 0dbm repectively.
2257 // The mapping may be different by different NICs. Do not use this formula for what needs accurate result.
2258 // By Bruce, 2008-01-29.
2260 switch(WirelessMode)
2262 case WIRELESS_MODE_B:
2266 case WIRELESS_MODE_G:
2267 case WIRELESS_MODE_N_24G:
2274 PwrOutDbm = TxPwrIdx / 2 + Offset; // Discard the decimal part.
2281 PHY_ScanOperationBackup8192S(
2282 IN PADAPTER Adapter,
2287 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
2288 PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
2290 u1Byte initial_gain;
2296 if(!Adapter->bDriverStopped)
2300 case SCAN_OPT_BACKUP:
2302 // <Roger_Notes> We halt FW DIG and disable high ppower both two DMs here
2303 // and resume both two DMs while scan complete.
2306 Adapter->HalFunc.SetFwCmdHandler(Adapter, FW_CMD_PAUSE_DM_BY_SCAN);
2309 case SCAN_OPT_RESTORE:
2311 // <Roger_Notes> We resume DIG and enable high power both two DMs here and
2312 // recover earlier DIG settings.
2315 Adapter->HalFunc.SetFwCmdHandler(Adapter, FW_CMD_RESUME_DM_BY_SCAN);
2319 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Unknown Scan Backup Operation. \n"));
2327 void PHY_InitialGain8192S(struct net_device* dev,u8 Operation )
2330 //struct r8192_priv *priv = ieee80211_priv(dev);
2335 /*-----------------------------------------------------------------------------
2336 * Function: SetBWModeCallback8190Pci()
2338 * Overview: Timer callback function for SetSetBWMode
2340 * Input: PRT_TIMER pTimer
2346 * Note: (1) We do not take j mode into consideration now
2347 * (2) Will two workitem of "switch channel" and "switch channel bandwidth" run
2349 *---------------------------------------------------------------------------*/
2350 // use in phy only (in win it's timer)
2351 void PHY_SetBWModeCallback8192S(struct net_device *dev)
2353 struct r8192_priv *priv = ieee80211_priv(dev);
2358 // Added it for 20/40 mhz switch time evaluation by guangan 070531
2360 //u8Byte BeginTime, EndTime;
2363 RT_TRACE(COMP_SWBW, "==>SetBWModeCallback8190Pci() Switch to %s bandwidth\n", \
2364 priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz");
2366 if(priv->rf_chip == RF_PSEUDO_11N)
2368 priv->SetBWModeInProgress= FALSE;
2375 // Added it for 20/40 mhz switch time evaluation by guangan 070531
2376 //NowL = read_nic_dword(dev, TSFR);
2377 //NowH = read_nic_dword(dev, TSFR+4);
2378 //BeginTime = ((u8Byte)NowH << 32) + NowL;
2381 //3//<1>Set MAC register
2383 regBwOpMode = read_nic_byte(dev, BW_OPMODE);
2384 regRRSR_RSC = read_nic_byte(dev, RRSR+2);
2386 switch(priv->CurrentChannelBW)
2388 case HT_CHANNEL_WIDTH_20:
2389 //if(priv->card_8192_version >= VERSION_8192S_BCUT)
2390 // write_nic_byte(dev, rFPGA0_AnalogParameter2, 0x58);
2392 regBwOpMode |= BW_OPMODE_20MHZ;
2393 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
2394 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
2397 case HT_CHANNEL_WIDTH_20_40:
2398 //if(priv->card_8192_version >= VERSION_8192S_BCUT)
2399 // write_nic_byte(dev, rFPGA0_AnalogParameter2, 0x18);
2401 regBwOpMode &= ~BW_OPMODE_20MHZ;
2402 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
2403 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
2404 regRRSR_RSC = (regRRSR_RSC&0x90) |(priv->nCur40MhzPrimeSC<<5);
2405 write_nic_byte(dev, RRSR+2, regRRSR_RSC);
2409 RT_TRACE(COMP_DBG, "SetBWModeCallback8190Pci(): unknown Bandwidth: %#X\n",
2410 priv->CurrentChannelBW);
2415 //3//<2>Set PHY related register
2417 switch(priv->CurrentChannelBW)
2420 case HT_CHANNEL_WIDTH_20:
2421 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x0);
2422 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x0);
2424 // Correct the tx power for CCK rate in 40M. Suggest by YN, 20071207
2425 // It is set in Tx descriptor for 8192x series
2426 //write_nic_dword(dev, rCCK0_TxFilter1, 0x1a1b0000);
2427 //write_nic_dword(dev, rCCK0_TxFilter2, 0x090e1317);
2428 //write_nic_dword(dev, rCCK0_DebugPort, 0x00000204);
2430 if (priv->card_8192_version >= VERSION_8192S_BCUT)
2431 write_nic_byte(dev, rFPGA0_AnalogParameter2, 0x58);
2437 case HT_CHANNEL_WIDTH_20_40:
2438 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x1);
2439 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x1);
2441 // Correct the tx power for CCK rate in 40M. Suggest by YN, 20071207
2442 //write_nic_dword(dev, rCCK0_TxFilter1, 0x35360000);
2443 //write_nic_dword(dev, rCCK0_TxFilter2, 0x121c252e);
2444 //write_nic_dword(dev, rCCK0_DebugPort, 0x00000409);
2446 // Set Control channel to upper or lower. These settings are required only for 40MHz
2447 rtl8192_setBBreg(dev, rCCK0_System, bCCKSideBand, (priv->nCur40MhzPrimeSC>>1));
2448 rtl8192_setBBreg(dev, rOFDM1_LSTF, 0xC00, priv->nCur40MhzPrimeSC);
2450 //rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00300000, 3);
2451 if (priv->card_8192_version >= VERSION_8192S_BCUT)
2452 write_nic_byte(dev, rFPGA0_AnalogParameter2, 0x18);
2457 RT_TRACE(COMP_DBG, "SetBWModeCallback8190Pci(): unknown Bandwidth: %#X\n"\
2458 ,priv->CurrentChannelBW);
2462 //Skip over setting of J-mode in BB register here. Default value is "None J mode". Emily 20070315
2464 // Added it for 20/40 mhz switch time evaluation by guangan 070531
2465 //NowL = read_nic_dword(dev, TSFR);
2466 //NowH = read_nic_dword(dev, TSFR+4);
2467 //EndTime = ((u8Byte)NowH << 32) + NowL;
2468 //RT_TRACE(COMP_SCAN, DBG_LOUD, ("SetBWModeCallback8190Pci: time of SetBWMode = %I64d us!\n", (EndTime - BeginTime)));
2470 //3<3>Set RF related register
2471 switch( priv->rf_chip )
2474 //PHY_SetRF8225Bandwidth(dev, priv->CurrentChannelBW);
2478 // Please implement this function in Hal8190PciPhy8256.c
2479 //PHY_SetRF8256Bandwidth(dev, priv->CurrentChannelBW);
2483 // Please implement this function in Hal8190PciPhy8258.c
2484 // PHY_SetRF8258Bandwidth();
2492 PHY_RF6052SetBandwidth(dev, priv->CurrentChannelBW);
2495 printk("Unknown rf_chip: %d\n", priv->rf_chip);
2499 priv->SetBWModeInProgress= FALSE;
2501 RT_TRACE(COMP_SWBW, "<==SetBWModeCallback8190Pci() \n" );
2505 /*-----------------------------------------------------------------------------
2506 * Function: SetBWMode8190Pci()
2508 * Overview: This function is export to "HalCommon" moudule
2510 * Input: PADAPTER Adapter
2511 * HT_CHANNEL_WIDTH Bandwidth //20M or 40M
2517 * Note: We do not take j mode into consideration now
2518 *---------------------------------------------------------------------------*/
2519 //extern void PHY_SetBWMode8192S( struct net_device* dev,
2520 // HT_CHANNEL_WIDTH Bandwidth, // 20M or 40M
2521 // HT_EXTCHNL_OFFSET Offset // Upper, Lower, or Don't care
2522 void rtl8192_SetBWMode(struct net_device *dev, HT_CHANNEL_WIDTH Bandwidth, HT_EXTCHNL_OFFSET Offset)
2524 struct r8192_priv *priv = ieee80211_priv(dev);
2525 HT_CHANNEL_WIDTH tmpBW = priv->CurrentChannelBW;
2528 // Modified it for 20/40 mhz switch by guangan 070531
2532 //if(priv->SwChnlInProgress)
2533 // if(pMgntInfo->bScanInProgress)
2535 // RT_TRACE(COMP_SCAN, DBG_LOUD, ("SetBWMode8190Pci() %s Exit because bScanInProgress!\n",
2536 // Bandwidth == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz"));
2540 // if(priv->SetBWModeInProgress)
2542 // // Modified it for 20/40 mhz switch by guangan 070531
2543 // RT_TRACE(COMP_SCAN, DBG_LOUD, ("SetBWMode8190Pci() %s cancel last timer because SetBWModeInProgress!\n",
2544 // Bandwidth == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz"));
2545 // PlatformCancelTimer(dev, &priv->SetBWModeTimer);
2549 if(priv->SetBWModeInProgress)
2552 priv->SetBWModeInProgress= TRUE;
2554 priv->CurrentChannelBW = Bandwidth;
2556 if(Offset==HT_EXTCHNL_OFFSET_LOWER)
2557 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_UPPER;
2558 else if(Offset==HT_EXTCHNL_OFFSET_UPPER)
2559 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_LOWER;
2561 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
2563 if((priv->up) )// && !(RT_CANNOT_IO(Adapter) && Adapter->bInSetPower) )
2565 SetBWModeCallback8192SUsbWorkItem(dev);
2569 RT_TRACE(COMP_SCAN, "PHY_SetBWMode8192S() SetBWModeInProgress FALSE driver sleep or unload\n");
2570 priv->SetBWModeInProgress= FALSE;
2571 priv->CurrentChannelBW = tmpBW;
2575 // use in phy only (in win it's timer)
2576 void PHY_SwChnlCallback8192S(struct net_device *dev)
2579 struct r8192_priv *priv = ieee80211_priv(dev);
2583 RT_TRACE(COMP_CH, "==>SwChnlCallback8190Pci(), switch to channel %d\n", priv->chan);
2588 if(priv->rf_chip == RF_PSEUDO_11N)
2590 priv->SwChnlInProgress=FALSE;
2591 return; //return immediately if it is peudo-phy
2595 if(!priv->SwChnlInProgress)
2598 //if(!phy_SwChnlStepByStep(dev, priv->CurrentChannel, &priv->SwChnlStage, &priv->SwChnlStep, &delay))
2599 if(!phy_SwChnlStepByStep(dev, priv->chan, &priv->SwChnlStage, &priv->SwChnlStep, &delay))
2604 //PlatformSetTimer(dev, &priv->SwChnlTimer, delay);
2605 //mod_timer(&priv->SwChnlTimer, jiffies + MSECS(delay));
2606 //==>PHY_SwChnlCallback8192S(dev); for 92se
2607 //==>SwChnlCallback8192SUsb(dev) for 92su
2614 priv->SwChnlInProgress=FALSE;
2620 // Call after initialization
2621 //extern void PHY_SwChnl8192S(struct net_device* dev, u8 channel)
2622 u8 rtl8192_phy_SwChnl(struct net_device* dev, u8 channel)
2624 struct r8192_priv *priv = ieee80211_priv(dev);
2625 //u8 tmpchannel =channel;
2626 //bool bResult = false;
2631 if(priv->SwChnlInProgress)
2634 if(priv->SetBWModeInProgress)
2637 //--------------------------------------------
2638 switch(priv->ieee80211->mode)
2640 case WIRELESS_MODE_A:
2641 case WIRELESS_MODE_N_5G:
2643 RT_TRACE(COMP_ERR, "WIRELESS_MODE_A but channel<=14");
2648 case WIRELESS_MODE_B:
2650 RT_TRACE(COMP_ERR, "WIRELESS_MODE_B but channel>14");
2655 case WIRELESS_MODE_G:
2656 case WIRELESS_MODE_N_24G:
2658 RT_TRACE(COMP_ERR, "WIRELESS_MODE_G but channel>14");
2664 ;//RT_TRACE(COMP_ERR, "Invalid WirelessMode(%#x)!!\n", priv->ieee80211->mode);
2667 //--------------------------------------------
2669 priv->SwChnlInProgress = TRUE;
2675 priv->SwChnlStage=0;
2678 if((priv->up))// && !(RT_CANNOT_IO(Adapter) && Adapter->bInSetPower))
2680 SwChnlCallback8192SUsbWorkItem(dev);
2684 RT_TRACE(COMP_SCAN, "PHY_SwChnl8192S SwChnlInProgress TRUE schdule workitem done\n");
2688 RT_TRACE(COMP_SCAN, "PHY_SwChnl8192S SwChnlInProgress FALSE schdule workitem error\n");
2689 priv->SwChnlInProgress = false;
2690 priv->CurrentChannel = tmpchannel;
2696 RT_TRACE(COMP_SCAN, "PHY_SwChnl8192S SwChnlInProgress FALSE driver sleep or unload\n");
2697 priv->SwChnlInProgress = false;
2698 //priv->CurrentChannel = tmpchannel;
2706 // Switch channel synchronously. Called by SwChnlByDelayHandler.
2708 // Implemented by Bruce, 2008-02-14.
2709 // The following procedure is operted according to SwChanlCallback8190Pci().
2710 // However, this procedure is performed synchronously which should be running under
2714 void PHY_SwChnlPhy8192S( // Only called during initialize
2715 struct net_device* dev,
2719 struct r8192_priv *priv = ieee80211_priv(dev);
2721 RT_TRACE(COMP_SCAN, "==>PHY_SwChnlPhy8192S(), switch to channel %d.\n", priv->chan);
2725 if(RT_CANNOT_IO(dev))
2729 // Channel Switching is in progress.
2730 if(priv->SwChnlInProgress)
2733 //return immediately if it is peudo-phy
2734 if(priv->rf_chip == RF_PSEUDO_11N)
2736 priv->SwChnlInProgress=FALSE;
2740 priv->SwChnlInProgress = TRUE;
2746 priv->SwChnlStage = 0;
2747 priv->SwChnlStep = 0;
2749 phy_FinishSwChnlNow(dev,channel);
2751 priv->SwChnlInProgress = FALSE;
2756 phy_SetSwChnlCmdArray(
2757 SwChnlCmd* CmdTable,
2768 if(CmdTable == NULL)
2770 //RT_ASSERT(FALSE, ("phy_SetSwChnlCmdArray(): CmdTable cannot be NULL.\n"));
2773 if(CmdTableIdx >= CmdTableSz)
2776 // ("phy_SetSwChnlCmdArray(): Access invalid index, please check size of the table, CmdTableIdx:%d, CmdTableSz:%d\n",
2777 //CmdTableIdx, CmdTableSz));
2781 pCmd = CmdTable + CmdTableIdx;
2782 pCmd->CmdID = CmdID;
2783 pCmd->Para1 = Para1;
2784 pCmd->Para2 = Para2;
2785 pCmd->msDelay = msDelay;
2792 phy_SwChnlStepByStep(
2793 struct net_device* dev,
2800 struct r8192_priv *priv = ieee80211_priv(dev);
2801 //PCHANNEL_ACCESS_SETTING pChnlAccessSetting;
2802 SwChnlCmd PreCommonCmd[MAX_PRECMD_CNT];
2803 u32 PreCommonCmdCnt;
2804 SwChnlCmd PostCommonCmd[MAX_POSTCMD_CNT];
2805 u32 PostCommonCmdCnt;
2806 SwChnlCmd RfDependCmd[MAX_RFDEPENDCMD_CNT];
2808 SwChnlCmd *CurrentCmd = NULL;
2811 //RT_ASSERT((dev != NULL), ("Adapter should not be NULL\n"));
2812 //RT_ASSERT(IsLegalChannel(dev, channel), ("illegal channel: %d\n", channel));
2813 RT_TRACE(COMP_CH, "===========>%s(), channel:%d, stage:%d, step:%d\n", __FUNCTION__, channel, *stage, *step);
2814 //RT_ASSERT((pHalData != NULL), ("pHalData should not be NULL\n"));
2815 if (!IsLegalChannel(priv->ieee80211, channel))
2817 RT_TRACE(COMP_ERR, "=============>set to illegal channel:%d\n", channel);
2818 return true; //return true to tell upper caller function this channel setting is finished! Or it will in while loop.
2821 //pChnlAccessSetting = &Adapter->MgntInfo.Info8185.ChannelAccessSetting;
2822 //RT_ASSERT((pChnlAccessSetting != NULL), ("pChnlAccessSetting should not be NULL\n"));
2824 //for(eRFPath = RF90_PATH_A; eRFPath <priv->NumTotalRFPath; eRFPath++)
2825 //for(eRFPath = 0; eRFPath <priv->NumTotalRFPath; eRFPath++)
2827 // <1> Fill up pre common command.
2828 PreCommonCmdCnt = 0;
2829 phy_SetSwChnlCmdArray(PreCommonCmd, PreCommonCmdCnt++, MAX_PRECMD_CNT,
2830 CmdID_SetTxPowerLevel, 0, 0, 0);
2831 phy_SetSwChnlCmdArray(PreCommonCmd, PreCommonCmdCnt++, MAX_PRECMD_CNT,
2832 CmdID_End, 0, 0, 0);
2834 // <2> Fill up post common command.
2835 PostCommonCmdCnt = 0;
2837 phy_SetSwChnlCmdArray(PostCommonCmd, PostCommonCmdCnt++, MAX_POSTCMD_CNT,
2838 CmdID_End, 0, 0, 0);
2840 // <3> Fill up RF dependent command.
2842 switch( priv->rf_chip )
2845 if (channel < 1 || channel > 14)
2846 RT_TRACE(COMP_ERR, "illegal channel for zebra:%d\n", channel);
2847 //RT_ASSERT((channel >= 1 && channel <= 14), ("illegal channel for Zebra: %d\n", channel));
2848 // 2008/09/04 MH Change channel.
2849 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
2850 CmdID_RF_WriteReg, rRfChannel, channel, 10);
2851 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
2852 CmdID_End, 0, 0, 0);
2856 if (channel < 1 || channel > 14)
2857 RT_TRACE(COMP_ERR, "illegal channel for zebra:%d\n", channel);
2858 // TEST!! This is not the table for 8256!!
2859 //RT_ASSERT((channel >= 1 && channel <= 14), ("illegal channel for Zebra: %d\n", channel));
2860 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
2861 CmdID_RF_WriteReg, rRfChannel, channel, 10);
2862 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
2863 CmdID_End, 0, 0, 0);
2867 if (channel < 1 || channel > 14)
2868 RT_TRACE(COMP_ERR, "illegal channel for zebra:%d\n", channel);
2869 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
2870 CmdID_RF_WriteReg, RF_CHNLBW, channel, 10);
2871 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
2872 CmdID_End, 0, 0, 0);
2879 //RT_ASSERT(FALSE, ("Unknown rf_chip: %d\n", priv->rf_chip));
2889 CurrentCmd=&PreCommonCmd[*step];
2892 CurrentCmd=&RfDependCmd[*step];
2895 CurrentCmd=&PostCommonCmd[*step];
2899 if(CurrentCmd->CmdID==CmdID_End)
2913 switch(CurrentCmd->CmdID)
2915 case CmdID_SetTxPowerLevel:
2916 //if(priv->card_8192_version > VERSION_8190_BD)
2917 PHY_SetTxPowerLevel8192S(dev,channel);
2919 case CmdID_WritePortUlong:
2920 write_nic_dword(dev, CurrentCmd->Para1, CurrentCmd->Para2);
2922 case CmdID_WritePortUshort:
2923 write_nic_word(dev, CurrentCmd->Para1, (u16)CurrentCmd->Para2);
2925 case CmdID_WritePortUchar:
2926 write_nic_byte(dev, CurrentCmd->Para1, (u8)CurrentCmd->Para2);
2928 case CmdID_RF_WriteReg: // Only modify channel for the register now !!!!!
2929 for(eRFPath = 0; eRFPath <priv->NumTotalRFPath; eRFPath++)
2931 // For new T65 RF 0222d register 0x18 bit 0-9 = channel number.
2932 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, CurrentCmd->Para1, 0x1f, (CurrentCmd->Para2));
2933 //printk("====>%x, %x, read_back:%x\n", CurrentCmd->Para2,CurrentCmd->Para1, rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, CurrentCmd->Para1, 0x1f));
2942 //cosa }/*for(Number of RF paths)*/
2944 (*delay)=CurrentCmd->msDelay;
2946 RT_TRACE(COMP_CH, "<===========%s(), channel:%d, stage:%d, step:%d\n", __FUNCTION__, channel, *stage, *step);
2950 //called PHY_SwChnlPhy8192S, SwChnlCallback8192SUsbWorkItem
2953 phy_FinishSwChnlNow( // We should not call this function directly
2954 struct net_device* dev,
2958 struct r8192_priv *priv = ieee80211_priv(dev);
2961 while(!phy_SwChnlStepByStep(dev,channel,&priv->SwChnlStage,&priv->SwChnlStep,&delay))
2971 /*-----------------------------------------------------------------------------
2972 * Function: PHYCheckIsLegalRfPath8190Pci()
2974 * Overview: Check different RF type to execute legal judgement. If RF Path is illegal
2975 * We will return false.
2985 * 11/15/2007 MHC Create Version 0.
2987 *---------------------------------------------------------------------------*/
2988 //called by rtl8192_phy_QueryRFReg, rtl8192_phy_SetRFReg, PHY_SetRFPowerState8192SUsb
2990 //PHY_CheckIsLegalRfPath8192S(
2991 // struct net_device* dev,
2993 u8 rtl8192_phy_CheckIsLegalRFPath(struct net_device* dev, u32 eRFPath)
2995 // struct r8192_priv *priv = ieee80211_priv(dev);
2996 bool rtValue = TRUE;
2998 // NOt check RF Path now.!
3001 } /* PHY_CheckIsLegalRfPath8192S */
3005 /*-----------------------------------------------------------------------------
3006 * Function: PHY_IQCalibrate8192S()
3008 * Overview: After all MAC/PHY/RF is configued. We must execute IQ calibration
3009 * to improve RF EVM!!?
3011 * Input: IN PADAPTER pAdapter
3019 * 10/07/2008 MHC Create. Document from SD3 RFSI Jenyu.
3021 *---------------------------------------------------------------------------*/
3022 //called by InitializeAdapter8192SE
3024 PHY_IQCalibrate( struct net_device* dev)
3026 //struct r8192_priv *priv = ieee80211_priv(dev);
3032 // 1. Check QFN68 or 64 92S (Read from EEPROM)
3037 // For 1T2R IQK only now !!!
3038 for (i = 0; i < 10; i++)
3041 rtl8192_setBBreg(dev, 0xc04, bMaskDWord, 0x00a05430);
3042 //PlatformStallExecution(5);
3044 rtl8192_setBBreg(dev, 0xc08, bMaskDWord, 0x000800e4);
3046 rtl8192_setBBreg(dev, 0xe28, bMaskDWord, 0x80800000);
3048 rtl8192_setBBreg(dev, 0xe40, bMaskDWord, 0x02140148);
3050 rtl8192_setBBreg(dev, 0xe44, bMaskDWord, 0x681604a2);
3052 rtl8192_setBBreg(dev, 0xe4c, bMaskDWord, 0x000028d1);
3054 rtl8192_setBBreg(dev, 0xe60, bMaskDWord, 0x0214014d);
3056 rtl8192_setBBreg(dev, 0xe64, bMaskDWord, 0x281608ba);
3058 rtl8192_setBBreg(dev, 0xe6c, bMaskDWord, 0x000028d1);
3060 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xfb000001);
3062 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xf8000001);
3064 rtl8192_setBBreg(dev, 0xc04, bMaskDWord, 0x00a05433);
3066 rtl8192_setBBreg(dev, 0xc08, bMaskDWord, 0x000000e4);
3068 rtl8192_setBBreg(dev, 0xe28, bMaskDWord, 0x0);
3071 reg = rtl8192_QueryBBReg(dev, 0xeac, bMaskDWord);
3073 // Readback IQK value and rewrite
3074 if (!(reg&(BIT27|BIT28|BIT30|BIT31)))
3076 old_value = (rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord) & 0x3FF);
3078 // Calibrate init gain for A path for TX0
3079 X = (rtl8192_QueryBBReg(dev, 0xe94, bMaskDWord) & 0x03FF0000)>>16;
3080 TXA[RF90_PATH_A] = (X * old_value)/0x100;
3081 reg = rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord);
3082 reg = (reg & 0xFFFFFC00) | (u32)TXA[RF90_PATH_A];
3083 rtl8192_setBBreg(dev, 0xc80, bMaskDWord, reg);
3086 // Calibrate init gain for C path for TX0
3087 Y = ( rtl8192_QueryBBReg(dev, 0xe9C, bMaskDWord) & 0x03FF0000)>>16;
3088 TX0[RF90_PATH_C] = ((Y * old_value)/0x100);
3089 reg = rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord);
3090 reg = (reg & 0xffc0ffff) |((u32) (TX0[RF90_PATH_C]&0x3F)<<16);
3091 rtl8192_setBBreg(dev, 0xc80, bMaskDWord, reg);
3092 reg = rtl8192_QueryBBReg(dev, 0xc94, bMaskDWord);
3093 reg = (reg & 0x0fffffff) |(((Y&0x3c0)>>6)<<28);
3094 rtl8192_setBBreg(dev, 0xc94, bMaskDWord, reg);
3097 // Calibrate RX A and B for RX0
3098 reg = rtl8192_QueryBBReg(dev, 0xc14, bMaskDWord);
3099 X = (rtl8192_QueryBBReg(dev, 0xea4, bMaskDWord) & 0x03FF0000)>>16;
3100 reg = (reg & 0xFFFFFC00) |X;
3101 rtl8192_setBBreg(dev, 0xc14, bMaskDWord, reg);
3102 Y = (rtl8192_QueryBBReg(dev, 0xeac, bMaskDWord) & 0x003F0000)>>16;
3103 reg = (reg & 0xFFFF03FF) |Y<<10;
3104 rtl8192_setBBreg(dev, 0xc14, bMaskDWord, reg);
3106 old_value = (rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord) & 0x3FF);
3108 // Calibrate init gain for A path for TX1 !!!!!!
3109 X = (rtl8192_QueryBBReg(dev, 0xeb4, bMaskDWord) & 0x03FF0000)>>16;
3110 reg = rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord);
3111 TXA[RF90_PATH_A] = (X * old_value) / 0x100;
3112 reg = (reg & 0xFFFFFC00) | TXA[RF90_PATH_A];
3113 rtl8192_setBBreg(dev, 0xc88, bMaskDWord, reg);
3116 // Calibrate init gain for C path for TX1
3117 Y = (rtl8192_QueryBBReg(dev, 0xebc, bMaskDWord)& 0x03FF0000)>>16;
3118 TX0[RF90_PATH_C] = ((Y * old_value)/0x100);
3119 reg = rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord);
3120 reg = (reg & 0xffc0ffff) |( (TX0[RF90_PATH_C]&0x3F)<<16);
3121 rtl8192_setBBreg(dev, 0xc88, bMaskDWord, reg);
3122 reg = rtl8192_QueryBBReg(dev, 0xc9c, bMaskDWord);
3123 reg = (reg & 0x0fffffff) |(((Y&0x3c0)>>6)<<28);
3124 rtl8192_setBBreg(dev, 0xc9c, bMaskDWord, reg);
3127 // Calibrate RX A and B for RX1
3128 reg = rtl8192_QueryBBReg(dev, 0xc1c, bMaskDWord);
3129 X = (rtl8192_QueryBBReg(dev, 0xec4, bMaskDWord) & 0x03FF0000)>>16;
3130 reg = (reg & 0xFFFFFC00) |X;
3131 rtl8192_setBBreg(dev, 0xc1c, bMaskDWord, reg);
3133 Y = (rtl8192_QueryBBReg(dev, 0xecc, bMaskDWord) & 0x003F0000)>>16;
3134 reg = (reg & 0xFFFF03FF) |Y<<10;
3135 rtl8192_setBBreg(dev, 0xc1c, bMaskDWord, reg);
3138 RT_TRACE(COMP_INIT, "PHY_IQCalibrate OK\n");
3146 // 3. QFN64. Not enabled now !!! We must use different gain table for 1T2R.
3152 /*-----------------------------------------------------------------------------
3153 * Function: PHY_IQCalibrateBcut()
3155 * Overview: After all MAC/PHY/RF is configued. We must execute IQ calibration
3156 * to improve RF EVM!!?
3158 * Input: IN PADAPTER pAdapter
3166 * 11/18/2008 MHC Create. Document from SD3 RFSI Jenyu.
3167 * 92S B-cut QFN 68 pin IQ calibration procedure.doc
3169 *---------------------------------------------------------------------------*/
3170 extern void PHY_IQCalibrateBcut(struct net_device* dev)
3172 //struct r8192_priv *priv = ieee80211_priv(dev);
3173 //PMGNT_INFO pMgntInfo = &pAdapter->MgntInfo;
3178 u32 calibrate_set[13] = {0};
3182 // 0. Check QFN68 or 64 92S (Read from EEPROM/EFUSE)
3185 // 1. Save e70~ee0 register setting, and load calibration setting
3188 0xee0[31:0]=0x3fed92fb;
3189 0xedc[31:0] =0x3fed92fb;
3190 0xe70[31:0] =0x3fed92fb;
3191 0xe74[31:0] =0x3fed92fb;
3192 0xe78[31:0] =0x3fed92fb;
3193 0xe7c[31:0]= 0x3fed92fb;
3194 0xe80[31:0]= 0x3fed92fb;
3195 0xe84[31:0]= 0x3fed92fb;
3196 0xe88[31:0]= 0x3fed92fb;
3197 0xe8c[31:0]= 0x3fed92fb;
3198 0xed0[31:0]= 0x3fed92fb;
3199 0xed4[31:0]= 0x3fed92fb;
3200 0xed8[31:0]= 0x3fed92fb;
3202 calibrate_set [0] = 0xee0;
3203 calibrate_set [1] = 0xedc;
3204 calibrate_set [2] = 0xe70;
3205 calibrate_set [3] = 0xe74;
3206 calibrate_set [4] = 0xe78;
3207 calibrate_set [5] = 0xe7c;
3208 calibrate_set [6] = 0xe80;
3209 calibrate_set [7] = 0xe84;
3210 calibrate_set [8] = 0xe88;
3211 calibrate_set [9] = 0xe8c;
3212 calibrate_set [10] = 0xed0;
3213 calibrate_set [11] = 0xed4;
3214 calibrate_set [12] = 0xed8;
3215 //RT_TRACE(COMP_INIT, DBG_LOUD, ("Save e70~ee0 register setting\n"));
3216 for (i = 0; i < 13; i++)
3218 load_value[i] = rtl8192_QueryBBReg(dev, calibrate_set[i], bMaskDWord);
3219 rtl8192_setBBreg(dev, calibrate_set[i], bMaskDWord, 0x3fed92fb);
3223 RfPiEnable = (u8)rtl8192_QueryBBReg(dev, rFPGA0_XA_HSSIParameter1, BIT8);
3228 // For 1T2R IQK only now !!!
3229 for (i = 0; i < 10; i++)
3231 RT_TRACE(COMP_INIT, "IQK -%d\n", i);
3232 //BB switch to PI mode. If default is PI mode, ignoring 2 commands below.
3233 if (!RfPiEnable) //if original is SI mode, then switch to PI mode.
3235 //DbgPrint("IQK Switch to PI mode\n");
3236 rtl8192_setBBreg(dev, 0x820, bMaskDWord, 0x01000100);
3237 rtl8192_setBBreg(dev, 0x828, bMaskDWord, 0x01000100);
3241 // 2. IQ calibration & LO leakage calibration
3242 rtl8192_setBBreg(dev, 0xc04, bMaskDWord, 0x00a05430);
3244 rtl8192_setBBreg(dev, 0xc08, bMaskDWord, 0x000800e4);
3246 rtl8192_setBBreg(dev, 0xe28, bMaskDWord, 0x80800000);
3248 //path-A IQ K and LO K gain setting
3249 rtl8192_setBBreg(dev, 0xe40, bMaskDWord, 0x02140102);
3251 rtl8192_setBBreg(dev, 0xe44, bMaskDWord, 0x681604c2);
3253 //set LO calibration
3254 rtl8192_setBBreg(dev, 0xe4c, bMaskDWord, 0x000028d1);
3256 //path-B IQ K and LO K gain setting
3257 rtl8192_setBBreg(dev, 0xe60, bMaskDWord, 0x02140102);
3259 rtl8192_setBBreg(dev, 0xe64, bMaskDWord, 0x28160d05);
3262 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xfb000000);
3264 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xf8000000);
3271 rtl8192_setBBreg(dev, 0xe6c, bMaskDWord, 0x020028d1);
3274 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xfb000000);
3276 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xf8000000);
3281 rtl8192_setBBreg(dev, 0xc04, bMaskDWord, 0x00a05433);
3283 rtl8192_setBBreg(dev, 0xc08, bMaskDWord, 0x000000e4);
3285 rtl8192_setBBreg(dev, 0xe28, bMaskDWord, 0x0);
3287 if (!RfPiEnable) //if original is SI mode, then switch to PI mode.
3289 //DbgPrint("IQK Switch back to SI mode\n");
3290 rtl8192_setBBreg(dev, 0x820, bMaskDWord, 0x01000000);
3291 rtl8192_setBBreg(dev, 0x828, bMaskDWord, 0x01000000);
3295 reg = rtl8192_QueryBBReg(dev, 0xeac, bMaskDWord);
3297 // 3. check fail bit, and fill BB IQ matrix
3298 // Readback IQK value and rewrite
3299 if (!(reg&(BIT27|BIT28|BIT30|BIT31)))
3301 old_value = (rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord) & 0x3FF);
3303 // Calibrate init gain for A path for TX0
3304 X = (rtl8192_QueryBBReg(dev, 0xe94, bMaskDWord) & 0x03FF0000)>>16;
3305 TXA[RF90_PATH_A] = (X * old_value)/0x100;
3306 reg = rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord);
3307 reg = (reg & 0xFFFFFC00) | (u32)TXA[RF90_PATH_A];
3308 rtl8192_setBBreg(dev, 0xc80, bMaskDWord, reg);
3311 // Calibrate init gain for C path for TX0
3312 Y = ( rtl8192_QueryBBReg(dev, 0xe9C, bMaskDWord) & 0x03FF0000)>>16;
3313 TX0[RF90_PATH_C] = ((Y * old_value)/0x100);
3314 reg = rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord);
3315 reg = (reg & 0xffc0ffff) |((u32) (TX0[RF90_PATH_C]&0x3F)<<16);
3316 rtl8192_setBBreg(dev, 0xc80, bMaskDWord, reg);
3317 reg = rtl8192_QueryBBReg(dev, 0xc94, bMaskDWord);
3318 reg = (reg & 0x0fffffff) |(((Y&0x3c0)>>6)<<28);
3319 rtl8192_setBBreg(dev, 0xc94, bMaskDWord, reg);
3322 // Calibrate RX A and B for RX0
3323 reg = rtl8192_QueryBBReg(dev, 0xc14, bMaskDWord);
3324 X = (rtl8192_QueryBBReg(dev, 0xea4, bMaskDWord) & 0x03FF0000)>>16;
3325 reg = (reg & 0xFFFFFC00) |X;
3326 rtl8192_setBBreg(dev, 0xc14, bMaskDWord, reg);
3327 Y = (rtl8192_QueryBBReg(dev, 0xeac, bMaskDWord) & 0x003F0000)>>16;
3328 reg = (reg & 0xFFFF03FF) |Y<<10;
3329 rtl8192_setBBreg(dev, 0xc14, bMaskDWord, reg);
3331 old_value = (rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord) & 0x3FF);
3333 // Calibrate init gain for A path for TX1 !!!!!!
3334 X = (rtl8192_QueryBBReg(dev, 0xeb4, bMaskDWord) & 0x03FF0000)>>16;
3335 reg = rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord);
3336 TXA[RF90_PATH_A] = (X * old_value) / 0x100;
3337 reg = (reg & 0xFFFFFC00) | TXA[RF90_PATH_A];
3338 rtl8192_setBBreg(dev, 0xc88, bMaskDWord, reg);
3341 // Calibrate init gain for C path for TX1
3342 Y = (rtl8192_QueryBBReg(dev, 0xebc, bMaskDWord)& 0x03FF0000)>>16;
3343 TX0[RF90_PATH_C] = ((Y * old_value)/0x100);
3344 reg = rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord);
3345 reg = (reg & 0xffc0ffff) |( (TX0[RF90_PATH_C]&0x3F)<<16);
3346 rtl8192_setBBreg(dev, 0xc88, bMaskDWord, reg);
3347 reg = rtl8192_QueryBBReg(dev, 0xc9c, bMaskDWord);
3348 reg = (reg & 0x0fffffff) |(((Y&0x3c0)>>6)<<28);
3349 rtl8192_setBBreg(dev, 0xc9c, bMaskDWord, reg);
3352 // Calibrate RX A and B for RX1
3353 reg = rtl8192_QueryBBReg(dev, 0xc1c, bMaskDWord);
3354 X = (rtl8192_QueryBBReg(dev, 0xec4, bMaskDWord) & 0x03FF0000)>>16;
3355 reg = (reg & 0xFFFFFC00) |X;
3356 rtl8192_setBBreg(dev, 0xc1c, bMaskDWord, reg);
3358 Y = (rtl8192_QueryBBReg(dev, 0xecc, bMaskDWord) & 0x003F0000)>>16;
3359 reg = (reg & 0xFFFF03FF) |Y<<10;
3360 rtl8192_setBBreg(dev, 0xc1c, bMaskDWord, reg);
3363 RT_TRACE(COMP_INIT, "PHY_IQCalibrate OK\n");
3370 // 4. Reload e70~ee0 register setting.
3372 //RT_TRACE(COMP_INIT, DBG_LOUD, ("Reload e70~ee0 register setting.\n"));
3373 for (i = 0; i < 13; i++)
3374 rtl8192_setBBreg(dev, calibrate_set[i], bMaskDWord, load_value[i]);
3378 // 3. QFN64. Not enabled now !!! We must use different gain table for 1T2R.
3383 } // PHY_IQCalibrateBcut
3387 // Move from phycfg.c to gen.c to be code independent later
3389 //-------------------------Move to other DIR later----------------------------*/
3390 //#if (DEV_BUS_TYPE == USB_INTERFACE)
3392 // use in phy only (in win it's timer)
3393 void SwChnlCallback8192SUsb(struct net_device *dev)
3396 struct r8192_priv *priv = ieee80211_priv(dev);
3400 RT_TRACE(COMP_SCAN, "==>SwChnlCallback8190Pci(), switch to channel %d\n",
3407 if(priv->rf_chip == RF_PSEUDO_11N)
3409 priv->SwChnlInProgress=FALSE;
3410 return; //return immediately if it is peudo-phy
3414 if(!priv->SwChnlInProgress)
3417 if(!phy_SwChnlStepByStep(dev, priv->chan, &priv->SwChnlStage, &priv->SwChnlStep, &delay))
3421 //PlatformSetTimer(dev, &priv->SwChnlTimer, delay);
3429 priv->SwChnlInProgress=FALSE;
3437 // Callback routine of the work item for switch channel.
3439 // use in phy only (in win it's work)
3440 void SwChnlCallback8192SUsbWorkItem(struct net_device *dev )
3442 struct r8192_priv *priv = ieee80211_priv(dev);
3444 RT_TRACE(COMP_TRACE, "==> SwChnlCallback8192SUsbWorkItem()\n");
3446 if(pAdapter->bInSetPower && RT_USB_CANNOT_IO(pAdapter))
3448 RT_TRACE(COMP_SCAN, DBG_LOUD, ("<== SwChnlCallback8192SUsbWorkItem() SwChnlInProgress FALSE driver sleep or unload\n"));
3450 pHalData->SwChnlInProgress = FALSE;
3454 phy_FinishSwChnlNow(dev, priv->chan);
3455 priv->SwChnlInProgress = FALSE;
3457 RT_TRACE(COMP_TRACE, "<== SwChnlCallback8192SUsbWorkItem()\n");
3461 /*-----------------------------------------------------------------------------
3462 * Function: SetBWModeCallback8192SUsb()
3464 * Overview: Timer callback function for SetSetBWMode
3466 * Input: PRT_TIMER pTimer
3472 * Note: (1) We do not take j mode into consideration now
3473 * (2) Will two workitem of "switch channel" and "switch channel bandwidth" run
3475 *---------------------------------------------------------------------------*/
3476 //====>//rtl8192_SetBWMode
3477 // use in phy only (in win it's timer)
3478 void SetBWModeCallback8192SUsb(struct net_device *dev)
3480 struct r8192_priv *priv = ieee80211_priv(dev);
3483 // Added it for 20/40 mhz switch time evaluation by guangan 070531
3485 //u8Byte BeginTime, EndTime;
3488 RT_TRACE(COMP_SCAN, "==>SetBWModeCallback8190Pci() Switch to %s bandwidth\n", \
3489 priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz");
3491 if(priv->rf_chip == RF_PSEUDO_11N)
3493 priv->SetBWModeInProgress= FALSE;
3500 // Added it for 20/40 mhz switch time evaluation by guangan 070531
3501 //NowL = read_nic_dword(dev, TSFR);
3502 //NowH = read_nic_dword(dev, TSFR+4);
3503 //BeginTime = ((u8Byte)NowH << 32) + NowL;
3505 //3<1>Set MAC register
3506 regBwOpMode = read_nic_byte(dev, BW_OPMODE);
3507 regRRSR_RSC = read_nic_byte(dev, RRSR+2);
3509 switch(priv->CurrentChannelBW)
3511 case HT_CHANNEL_WIDTH_20:
3512 regBwOpMode |= BW_OPMODE_20MHZ;
3513 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
3514 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
3517 case HT_CHANNEL_WIDTH_20_40:
3518 regBwOpMode &= ~BW_OPMODE_20MHZ;
3519 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
3520 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
3522 regRRSR_RSC = (regRRSR_RSC&0x90) |(priv->nCur40MhzPrimeSC<<5);
3523 write_nic_byte(dev, RRSR+2, regRRSR_RSC);
3527 RT_TRACE(COMP_DBG, "SetChannelBandwidth8190Pci(): unknown Bandwidth: %#X\n",
3528 priv->CurrentChannelBW);
3532 //3 <2>Set PHY related register
3533 switch(priv->CurrentChannelBW)
3535 case HT_CHANNEL_WIDTH_20:
3536 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x0);
3537 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x0);
3539 if (priv->card_8192_version >= VERSION_8192S_BCUT)
3540 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter2, 0xff, 0x58);
3543 case HT_CHANNEL_WIDTH_20_40:
3544 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x1);
3545 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x1);
3546 rtl8192_setBBreg(dev, rCCK0_System, bCCKSideBand, (priv->nCur40MhzPrimeSC>>1));
3547 rtl8192_setBBreg(dev, rOFDM1_LSTF, 0xC00, priv->nCur40MhzPrimeSC);
3549 // Correct the tx power for CCK rate in 40M. Suggest by YN, 20071207
3550 //PHY_SetBBReg(Adapter, rCCK0_TxFilter1, bMaskDWord, 0x35360000);
3551 //PHY_SetBBReg(Adapter, rCCK0_TxFilter2, bMaskDWord, 0x121c252e);
3552 //PHY_SetBBReg(Adapter, rCCK0_DebugPort, bMaskDWord, 0x00000409);
3553 //PHY_SetBBReg(Adapter, rFPGA0_AnalogParameter1, bADClkPhase, 0);
3555 if (priv->card_8192_version >= VERSION_8192S_BCUT)
3556 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter2, 0xff, 0x18);
3560 RT_TRACE(COMP_DBG, "SetChannelBandwidth8190Pci(): unknown Bandwidth: %#X\n"\
3561 ,priv->CurrentChannelBW);
3565 //Skip over setting of J-mode in BB register here. Default value is "None J mode". Emily 20070315
3567 // Added it for 20/40 mhz switch time evaluation by guangan 070531
3568 //NowL = read_nic_dword(dev, TSFR);
3569 //NowH = read_nic_dword(dev, TSFR+4);
3570 //EndTime = ((u8Byte)NowH << 32) + NowL;
3571 //RT_TRACE(COMP_SCAN, DBG_LOUD, ("SetBWModeCallback8190Pci: time of SetBWMode = %I64d us!\n", (EndTime - BeginTime)));
3574 //3<3>Set RF related register
3575 switch( priv->rf_chip )
3578 PHY_SetRF8225Bandwidth(dev, priv->CurrentChannelBW);
3582 // Please implement this function in Hal8190PciPhy8256.c
3583 //PHY_SetRF8256Bandwidth(dev, priv->CurrentChannelBW);
3587 PHY_RF6052SetBandwidth(dev, priv->CurrentChannelBW);
3591 // Please implement this function in Hal8190PciPhy8258.c
3592 // PHY_SetRF8258Bandwidth();
3600 //RT_ASSERT(FALSE, ("Unknown rf_chip: %d\n", priv->rf_chip));
3604 priv->SetBWModeInProgress= FALSE;
3606 RT_TRACE(COMP_SCAN, "<==SetBWMode8190Pci()" );
3610 * Callback routine of the work item for set bandwidth mode.
3612 * use in phy only (in win it's work)
3614 void SetBWModeCallback8192SUsbWorkItem(struct net_device *dev)
3616 struct r8192_priv *priv = ieee80211_priv(dev);
3620 RT_TRACE(COMP_SCAN, "%s(): Switch to %s bandwidth", __func__,
3621 priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20 ? "20MHz" : "40MHz");
3623 if (priv->rf_chip == RF_PSEUDO_11N) {
3624 priv->SetBWModeInProgress= FALSE;
3629 /* Set MAC register */
3630 regBwOpMode = read_nic_byte(dev, BW_OPMODE);
3631 regRRSR_RSC = read_nic_byte(dev, RRSR+2);
3632 switch (priv->CurrentChannelBW) {
3633 case HT_CHANNEL_WIDTH_20:
3634 regBwOpMode |= BW_OPMODE_20MHZ;
3635 /* we have not verified whether this register works */
3636 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
3638 case HT_CHANNEL_WIDTH_20_40:
3639 regBwOpMode &= ~BW_OPMODE_20MHZ;
3640 /* we have not verified whether this register works */
3641 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
3642 regRRSR_RSC = (regRRSR_RSC&0x90) | (priv->nCur40MhzPrimeSC<<5);
3643 write_nic_byte(dev, RRSR+2, regRRSR_RSC);
3646 RT_TRACE(COMP_DBG, "%s(): unknown Bandwidth: %#X", __func__,
3647 priv->CurrentChannelBW);
3650 /* Set PHY related register */
3651 switch (priv->CurrentChannelBW) {
3652 case HT_CHANNEL_WIDTH_20:
3653 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x0);
3654 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x0);
3655 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter2, 0xff, 0x58);
3657 case HT_CHANNEL_WIDTH_20_40:
3658 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x1);
3659 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x1);
3661 * Set Control channel to upper or lower.
3662 * These settings are required only for 40MHz
3664 rtl8192_setBBreg(dev, rCCK0_System, bCCKSideBand,
3665 (priv->nCur40MhzPrimeSC>>1));
3666 rtl8192_setBBreg(dev, rOFDM1_LSTF, 0xC00,
3667 priv->nCur40MhzPrimeSC);
3668 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter2, 0xff, 0x18);
3671 RT_TRACE(COMP_DBG, "%s(): unknown Bandwidth: %#X", __func__,
3672 priv->CurrentChannelBW);
3677 * Skip over setting of J-mode in BB register here.
3678 * Default value is "None J mode".
3681 /* Set RF related register */
3682 switch (priv->rf_chip) {
3684 PHY_SetRF8225Bandwidth(dev, priv->CurrentChannelBW);
3687 /* Please implement this function in Hal8190PciPhy8256.c */
3688 /* PHY_SetRF8256Bandwidth(dev, priv->CurrentChannelBW); */
3691 PHY_RF6052SetBandwidth(dev, priv->CurrentChannelBW);
3694 /* Please implement this function in Hal8190PciPhy8258.c */
3695 /* PHY_SetRF8258Bandwidth(); */
3701 RT_TRACE(COMP_DBG, "%s(): unknown rf_chip: %d", __func__,
3705 priv->SetBWModeInProgress= FALSE;
3708 //--------------------------Move to oter DIR later-------------------------------*/
3709 void InitialGain8192S(struct net_device *dev, u8 Operation)
3712 struct r8192_priv *priv = ieee80211_priv(dev);
3717 void InitialGain819xUsb(struct net_device *dev, u8 Operation)
3719 struct r8192_priv *priv = ieee80211_priv(dev);
3721 priv->InitialGainOperateType = Operation;
3725 queue_delayed_work(priv->priv_wq,&priv->initialgain_operate_wq,0);
3729 extern void InitialGainOperateWorkItemCallBack(struct work_struct *work)
3731 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
3732 struct r8192_priv *priv = container_of(dwork,struct r8192_priv,initialgain_operate_wq);
3733 struct net_device *dev = priv->ieee80211->dev;
3734 #define SCAN_RX_INITIAL_GAIN 0x17
3735 #define POWER_DETECTION_TH 0x08
3740 Operation = priv->InitialGainOperateType;
3745 RT_TRACE(COMP_SCAN, "IG_Backup, backup the initial gain.\n");
3746 initial_gain = SCAN_RX_INITIAL_GAIN;//priv->DefaultInitialGain[0];//
3747 BitMask = bMaskByte0;
3748 if(dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
3749 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); // FW DIG OFF
3750 priv->initgain_backup.xaagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XAAGCCore1, BitMask);
3751 priv->initgain_backup.xbagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XBAGCCore1, BitMask);
3752 priv->initgain_backup.xcagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XCAGCCore1, BitMask);
3753 priv->initgain_backup.xdagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XDAGCCore1, BitMask);
3754 BitMask = bMaskByte2;
3755 priv->initgain_backup.cca = (u8)rtl8192_QueryBBReg(dev, rCCK0_CCA, BitMask);
3757 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc50 is %x\n",priv->initgain_backup.xaagccore1);
3758 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc58 is %x\n",priv->initgain_backup.xbagccore1);
3759 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc60 is %x\n",priv->initgain_backup.xcagccore1);
3760 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc68 is %x\n",priv->initgain_backup.xdagccore1);
3761 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xa0a is %x\n",priv->initgain_backup.cca);
3763 RT_TRACE(COMP_SCAN, "Write scan initial gain = 0x%x \n", initial_gain);
3764 write_nic_byte(dev, rOFDM0_XAAGCCore1, initial_gain);
3765 write_nic_byte(dev, rOFDM0_XBAGCCore1, initial_gain);
3766 write_nic_byte(dev, rOFDM0_XCAGCCore1, initial_gain);
3767 write_nic_byte(dev, rOFDM0_XDAGCCore1, initial_gain);
3768 RT_TRACE(COMP_SCAN, "Write scan 0xa0a = 0x%x \n", POWER_DETECTION_TH);
3769 write_nic_byte(dev, 0xa0a, POWER_DETECTION_TH);
3772 RT_TRACE(COMP_SCAN, "IG_Restore, restore the initial gain.\n");
3773 BitMask = 0x7f; //Bit0~ Bit6
3774 if(dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
3775 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); // FW DIG OFF
3777 rtl8192_setBBreg(dev, rOFDM0_XAAGCCore1, BitMask, (u32)priv->initgain_backup.xaagccore1);
3778 rtl8192_setBBreg(dev, rOFDM0_XBAGCCore1, BitMask, (u32)priv->initgain_backup.xbagccore1);
3779 rtl8192_setBBreg(dev, rOFDM0_XCAGCCore1, BitMask, (u32)priv->initgain_backup.xcagccore1);
3780 rtl8192_setBBreg(dev, rOFDM0_XDAGCCore1, BitMask, (u32)priv->initgain_backup.xdagccore1);
3781 BitMask = bMaskByte2;
3782 rtl8192_setBBreg(dev, rCCK0_CCA, BitMask, (u32)priv->initgain_backup.cca);
3784 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc50 is %x\n",priv->initgain_backup.xaagccore1);
3785 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc58 is %x\n",priv->initgain_backup.xbagccore1);
3786 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc60 is %x\n",priv->initgain_backup.xcagccore1);
3787 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc68 is %x\n",priv->initgain_backup.xdagccore1);
3788 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xa0a is %x\n",priv->initgain_backup.cca);
3790 PHY_SetTxPowerLevel8192S(dev,priv->ieee80211->current_network.channel);
3792 if(dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
3793 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x1); // FW DIG ON
3796 RT_TRACE(COMP_SCAN, "Unknown IG Operation. \n");
3802 //-----------------------------------------------------------------------------
3804 // Schedule workitem to send specific CMD IO to FW.
3805 // Added by Roger, 2008.12.03.
3807 //-----------------------------------------------------------------------------
3808 bool HalSetFwCmd8192S(struct net_device* dev, FW_CMD_IO_TYPE FwCmdIO)
3810 struct r8192_priv *priv = ieee80211_priv(dev);
3811 u16 FwCmdWaitCounter = 0;
3813 u16 FwCmdWaitLimit = 1000;
3815 //if(IS_HARDWARE_TYPE_8192SU(Adapter) && Adapter->bInHctTest)
3816 if(priv->bInHctTest)
3819 RT_TRACE(COMP_CMD, "-->HalSetFwCmd8192S(): Set FW Cmd(%x), SetFwCmdInProgress(%d)\n", (u32)FwCmdIO, priv->SetFwCmdInProgress);
3821 // Will be done by high power respectively.
3822 if(FwCmdIO==FW_CMD_DIG_HALT || FwCmdIO==FW_CMD_DIG_RESUME)
3824 RT_TRACE(COMP_CMD, "<--HalSetFwCmd8192S(): Set FW Cmd(%x)\n", (u32)FwCmdIO);
3829 while(priv->SetFwCmdInProgress && FwCmdWaitCounter<FwCmdWaitLimit)
3831 //if(RT_USB_CANNOT_IO(Adapter))
3833 // RT_TRACE(COMP_CMD, DBG_WARNING, ("HalSetFwCmd8192S(): USB can NOT IO!!\n"));
3837 RT_TRACE(COMP_CMD, "HalSetFwCmd8192S(): previous workitem not finish!!\n");
3839 FwCmdWaitCounter ++;
3840 RT_TRACE(COMP_CMD, "HalSetFwCmd8192S(): Wait 10 ms (%d times)...\n", FwCmdWaitCounter);
3844 if(FwCmdWaitCounter == FwCmdWaitLimit)
3846 //RT_ASSERT(FALSE, ("SetFwCmdIOWorkItemCallback(): Wait too logn to set FW CMD\n"));
3847 RT_TRACE(COMP_CMD, "HalSetFwCmd8192S(): Wait too logn to set FW CMD\n");
3851 if (priv->SetFwCmdInProgress)
3853 RT_TRACE(COMP_ERR, "<--HalSetFwCmd8192S(): Set FW Cmd(%#x)\n", FwCmdIO);
3856 priv->SetFwCmdInProgress = TRUE;
3857 priv->CurrentFwCmdIO = FwCmdIO; // Update current FW Cmd for callback use.
3859 phy_SetFwCmdIOCallback(dev);
3862 void ChkFwCmdIoDone(struct net_device* dev)
3864 u16 PollingCnt = 1000;
3868 {// Make sure that CMD IO has be accepted by FW.
3870 if(RT_USB_CANNOT_IO(Adapter))
3872 RT_TRACE(COMP_CMD, "ChkFwCmdIoDone(): USB can NOT IO!!\n");
3876 udelay(10); // sleep 20us
3877 tmpValue = read_nic_dword(dev, WFM5);
3880 RT_TRACE(COMP_CMD, "[FW CMD] Set FW Cmd success!!\n");
3885 RT_TRACE(COMP_CMD, "[FW CMD] Polling FW Cmd PollingCnt(%d)!!\n", PollingCnt);
3887 }while( --PollingCnt );
3891 RT_TRACE(COMP_ERR, "[FW CMD] Set FW Cmd fail!!\n");
3894 // Callback routine of the timer callback for FW Cmd IO.
3897 // This routine will send specific CMD IO to FW and check whether it is done.
3899 void phy_SetFwCmdIOCallback(struct net_device* dev)
3901 //struct net_device* dev = (struct net_device*) data;
3903 static u32 ScanRegister;
3904 struct r8192_priv *priv = ieee80211_priv(dev);
3907 RT_TRACE(COMP_CMD, "SetFwCmdIOTimerCallback(): driver is going to unload\n");
3911 RT_TRACE(COMP_CMD, "--->SetFwCmdIOTimerCallback(): Cmd(%#x), SetFwCmdInProgress(%d)\n", priv->CurrentFwCmdIO, priv->SetFwCmdInProgress);
3913 switch(priv->CurrentFwCmdIO)
3915 case FW_CMD_HIGH_PWR_ENABLE:
3916 if((priv->ieee80211->pHTInfo->IOTAction & HT_IOT_ACT_DISABLE_HIGH_POWER)==0)
3917 write_nic_dword(dev, WFM5, FW_HIGH_PWR_ENABLE);
3920 case FW_CMD_HIGH_PWR_DISABLE:
3921 write_nic_dword(dev, WFM5, FW_HIGH_PWR_DISABLE);
3924 case FW_CMD_DIG_RESUME:
3925 write_nic_dword(dev, WFM5, FW_DIG_RESUME);
3928 case FW_CMD_DIG_HALT:
3929 write_nic_dword(dev, WFM5, FW_DIG_HALT);
3933 // <Roger_Notes> The following FW CMD IO was combined into single operation
3934 // (i.e., to prevent number of system workitem out of resource!!).
3937 case FW_CMD_RESUME_DM_BY_SCAN:
3938 RT_TRACE(COMP_CMD, "[FW CMD] Set HIGHPWR enable and DIG resume!!\n");
3939 if((priv->ieee80211->pHTInfo->IOTAction & HT_IOT_ACT_DISABLE_HIGH_POWER)==0)
3941 write_nic_dword(dev, WFM5, FW_HIGH_PWR_ENABLE); //break;
3942 ChkFwCmdIoDone(dev);
3944 write_nic_dword(dev, WFM5, FW_DIG_RESUME);
3947 case FW_CMD_PAUSE_DM_BY_SCAN:
3948 RT_TRACE(COMP_CMD, "[FW CMD] Set HIGHPWR disable and DIG halt!!\n");
3949 write_nic_dword(dev, WFM5, FW_HIGH_PWR_DISABLE); //break;
3950 ChkFwCmdIoDone(dev);
3951 write_nic_dword(dev, WFM5, FW_DIG_HALT);
3955 // <Roger_Notes> The following FW CMD IO should be checked
3956 // (i.e., workitem schedule timing issue!!).
3959 case FW_CMD_DIG_DISABLE:
3960 RT_TRACE(COMP_CMD, "[FW CMD] Set DIG disable!!\n");
3961 write_nic_dword(dev, WFM5, FW_DIG_DISABLE);
3964 case FW_CMD_DIG_ENABLE:
3965 RT_TRACE(COMP_CMD, "[FW CMD] Set DIG enable!!\n");
3966 write_nic_dword(dev, WFM5, FW_DIG_ENABLE);
3969 case FW_CMD_RA_RESET:
3970 write_nic_dword(dev, WFM5, FW_RA_RESET);
3973 case FW_CMD_RA_ACTIVE:
3974 write_nic_dword(dev, WFM5, FW_RA_ACTIVE);
3977 case FW_CMD_RA_REFRESH_N:
3978 RT_TRACE(COMP_CMD, "[FW CMD] Set RA refresh!! N\n");
3979 if(priv->ieee80211->pHTInfo->IOTRaFunc & HT_IOT_RAFUNC_DISABLE_ALL)
3980 input = FW_RA_REFRESH;
3982 input = FW_RA_REFRESH | (priv->ieee80211->pHTInfo->IOTRaFunc << 8);
3983 write_nic_dword(dev, WFM5, input);
3985 case FW_CMD_RA_REFRESH_BG:
3986 RT_TRACE(COMP_CMD, "[FW CMD] Set RA refresh!! B/G\n");
3987 write_nic_dword(dev, WFM5, FW_RA_REFRESH);
3988 ChkFwCmdIoDone(dev);
3989 write_nic_dword(dev, WFM5, FW_RA_ENABLE_BG);
3992 case FW_CMD_IQK_ENABLE:
3993 write_nic_dword(dev, WFM5, FW_IQK_ENABLE);
3996 case FW_CMD_TXPWR_TRACK_ENABLE:
3997 write_nic_dword(dev, WFM5, FW_TXPWR_TRACK_ENABLE);
4000 case FW_CMD_TXPWR_TRACK_DISABLE:
4001 write_nic_dword(dev, WFM5, FW_TXPWR_TRACK_DISABLE);
4005 RT_TRACE(COMP_CMD,"Unknown FW Cmd IO(%#x)\n", priv->CurrentFwCmdIO);
4009 ChkFwCmdIoDone(dev);
4011 switch(priv->CurrentFwCmdIO)
4013 case FW_CMD_HIGH_PWR_DISABLE:
4014 //if(pMgntInfo->bTurboScan)
4016 //Lower initial gain
4017 rtl8192_setBBreg(dev, rOFDM0_XAAGCCore1, bMaskByte0, 0x17);
4018 rtl8192_setBBreg(dev, rOFDM0_XBAGCCore1, bMaskByte0, 0x17);
4020 rtl8192_setBBreg(dev, rCCK0_CCA, bMaskByte2, 0x40);
4021 // Disable OFDM Part
4022 rtl8192_setBBreg(dev, rOFDM0_TRMuxPar, bMaskByte2, 0x1);
4023 ScanRegister = rtl8192_QueryBBReg(dev, rOFDM0_RxDetector1,bMaskDWord);
4024 rtl8192_setBBreg(dev, rOFDM0_RxDetector1, 0xf, 0xf);
4025 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0x0);
4029 case FW_CMD_HIGH_PWR_ENABLE:
4030 //if(pMgntInfo->bTurboScan)
4032 rtl8192_setBBreg(dev, rOFDM0_XAAGCCore1, bMaskByte0, 0x36);
4033 rtl8192_setBBreg(dev, rOFDM0_XBAGCCore1, bMaskByte0, 0x36);
4036 rtl8192_setBBreg(dev, rCCK0_CCA, bMaskByte2, 0x83);
4038 rtl8192_setBBreg(dev, rOFDM0_TRMuxPar, bMaskByte2, 0x0);
4040 //LZM ADD because sometimes there is no FW_CMD_HIGH_PWR_DISABLE, this value will be 0.
4041 if(ScanRegister != 0){
4042 rtl8192_setBBreg(dev, rOFDM0_RxDetector1, bMaskDWord, ScanRegister);
4045 if(priv->rf_type == RF_1T2R || priv->rf_type == RF_2T2R)
4046 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0x3);
4048 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0x1);
4053 priv->SetFwCmdInProgress = false;// Clear FW CMD operation flag.
4054 RT_TRACE(COMP_CMD, "<---SetFwCmdIOWorkItemCallback()\n");