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"
42 //#include "r8192S_FwImgDTM.h"
44 #include "ieee80211/dot11d.h"
46 /*---------------------------Define Local Constant---------------------------*/
47 /* Channel switch:The size of command tables for switch channel*/
48 #define MAX_PRECMD_CNT 16
49 #define MAX_RFDEPENDCMD_CNT 16
50 #define MAX_POSTCMD_CNT 16
51 #define MAX_DOZE_WAITING_TIMES_9x 64
53 /*------------------------Define local variable------------------------------*/
57 phy_CalculateBitShift(u32 BitMask);
59 phy_ConfigMACWithHeaderFile(struct net_device* dev);
61 phy_InitBBRFRegisterDefinition(struct net_device* dev);
63 phy_BB8192S_Config_ParaFile(struct net_device* dev);
65 phy_ConfigBBWithHeaderFile(struct net_device* dev,u8 ConfigType);
67 phy_SetRFPowerState8192SU(struct net_device* dev,RT_RF_POWER_STATE eRFPowerState);
69 SetBWModeCallback8192SUsbWorkItem(struct net_device *dev);
71 SetBWModeCallback8192SUsbWorkItem(struct net_device *dev);
73 SwChnlCallback8192SUsbWorkItem(struct net_device *dev );
75 phy_FinishSwChnlNow(struct net_device* dev,u8 channel);
78 struct net_device* dev,
85 phy_ConfigBBWithPgHeaderFile(struct net_device* dev,u8 ConfigType);
86 static long phy_TxPwrIdxToDbm( struct net_device* dev, WIRELESS_MODE WirelessMode, u8 TxPwrIdx);
87 static u8 phy_DbmToTxPwrIdx( struct net_device* dev, WIRELESS_MODE WirelessMode, long PowerInDbm);
88 void phy_SetFwCmdIOCallback(struct net_device* dev);
90 //#if ((HAL_CODE_BASE == RTL8192_S) && (DEV_BUS_TYPE==USB_INTERFACE))
93 // Base Band read by 4181 to make sure that operation could be done in unlimited cycle.
96 // - Only use on RTL8192S USB interface.
99 // Created by Roger, 2008.09.06.
102 u32 phy_QueryUsbBBReg(struct net_device* dev, u32 RegAddr)
104 struct r8192_priv *priv = ieee80211_priv(dev);
105 u32 ReturnValue = 0xffffffff;
107 u8 BBWaitCounter = 0;
111 // <Roger_Notes> Due to PASSIVE_LEVEL, so we ONLY simply busy waiting for a while here.
112 // We have to make sure that previous BB I/O has been done.
115 while(priv->bChangeBBInProgress)
118 RT_TRACE(COMP_RF, "phy_QueryUsbBBReg(): Wait 1 ms (%d times)...\n", BBWaitCounter);
121 // Wait too long, return FALSE to avoid to be stuck here.
122 if((BBWaitCounter > 100) )//||RT_USB_CANNOT_IO(Adapter))
124 RT_TRACE(COMP_RF, "phy_QueryUsbBBReg(): (%d) Wait too logn to query BB!!\n", BBWaitCounter);
129 priv->bChangeBBInProgress = true;
131 read_nic_dword(dev, RegAddr);
134 {// Make sure that access could be done.
135 if((read_nic_byte(dev, PHY_REG)&HST_RDBUSY) == 0)
137 }while( --PollingCnt );
141 RT_TRACE(COMP_RF, "Fail!!!phy_QueryUsbBBReg(): RegAddr(%#x) = %#x\n", RegAddr, ReturnValue);
145 // Data FW read back.
146 ReturnValue = read_nic_dword(dev, PHY_REG_DATA);
147 RT_TRACE(COMP_RF, "phy_QueryUsbBBReg(): RegAddr(%#x) = %#x, PollingCnt(%d)\n", RegAddr, ReturnValue, PollingCnt);
150 priv->bChangeBBInProgress = false;
159 // Base Band wrote by 4181 to make sure that operation could be done in unlimited cycle.
162 // - Only use on RTL8192S USB interface.
165 // Created by Roger, 2008.09.06.
169 phy_SetUsbBBReg(struct net_device* dev,u32 RegAddr,u32 Data)
171 struct r8192_priv *priv = ieee80211_priv(dev);
172 u8 BBWaitCounter = 0;
174 RT_TRACE(COMP_RF, "phy_SetUsbBBReg(): RegAddr(%#x) <= %#x\n", RegAddr, Data);
177 // <Roger_Notes> Due to PASSIVE_LEVEL, so we ONLY simply busy waiting for a while here.
178 // We have to make sure that previous BB I/O has been done.
181 while(priv->bChangeBBInProgress)
184 RT_TRACE(COMP_RF, "phy_SetUsbBBReg(): Wait 1 ms (%d times)...\n", BBWaitCounter);
187 if((BBWaitCounter > 100))// || RT_USB_CANNOT_IO(Adapter))
189 RT_TRACE(COMP_RF, "phy_SetUsbBBReg(): (%d) Wait too logn to query BB!!\n", BBWaitCounter);
194 priv->bChangeBBInProgress = true;
195 //printk("**************%s: RegAddr:%x Data:%x\n", __FUNCTION__,RegAddr, Data);
196 write_nic_dword(dev, RegAddr, Data);
198 priv->bChangeBBInProgress = false;
205 // RF read by 4181 to make sure that operation could be done in unlimited cycle.
208 // - Only use on RTL8192S USB interface.
210 // - RT_RF_OPERATE_SPINLOCK is acquired and keep on holding to the end.FIXLZM
212 // Created by Roger, 2008.09.06.
215 u32 phy_QueryUsbRFReg( struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 Offset)
218 struct r8192_priv *priv = ieee80211_priv(dev);
219 //u32 value = 0, ReturnValue = 0;
221 //u32 tmplong,tmplong2;
223 u8 RFWaitCounter = 0;
227 // <Roger_Notes> Due to PASSIVE_LEVEL, so we ONLY simply busy waiting for a while here.
228 // We have to make sure that previous RF I/O has been done.
231 while(priv->bChangeRFInProgress)
233 //PlatformReleaseSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
234 //spin_lock_irqsave(&priv->rf_lock, flags); //LZM,090318
238 RT_TRACE(COMP_RF, "phy_QueryUsbRFReg(): Wait 1 ms (%d times)...\n", RFWaitCounter);
241 if((RFWaitCounter > 100)) //|| RT_USB_CANNOT_IO(Adapter))
243 RT_TRACE(COMP_RF, "phy_QueryUsbRFReg(): (%d) Wait too logn to query BB!!\n", RFWaitCounter);
248 //PlatformAcquireSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
252 priv->bChangeRFInProgress = true;
253 //PlatformReleaseSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
256 Offset &= 0x3f; //RF_Offset= 0x00~0x3F
258 write_nic_dword(dev, RF_BB_CMD_ADDR, 0xF0000002|
259 (Offset<<8)| //RF_Offset= 0x00~0x3F
260 (eRFPath<<16)); //RF_Path = 0(A) or 1(B)
263 {// Make sure that access could be done.
264 if(read_nic_dword(dev, RF_BB_CMD_ADDR) == 0)
266 }while( --PollingCnt );
268 // Data FW read back.
269 ReturnValue = read_nic_dword(dev, RF_BB_CMD_DATA);
271 //PlatformAcquireSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
272 //spin_unlock_irqrestore(&priv->rf_lock, flags); //LZM,090318
274 priv->bChangeRFInProgress = false;
276 RT_TRACE(COMP_RF, "phy_QueryUsbRFReg(): eRFPath(%d), Offset(%#x) = %#x\n", eRFPath, Offset, ReturnValue);
285 // RF wrote by 4181 to make sure that operation could be done in unlimited cycle.
288 // - Only use on RTL8192S USB interface.
290 // - RT_RF_OPERATE_SPINLOCK is acquired and keep on holding to the end.FIXLZM
292 // Created by Roger, 2008.09.06.
295 void phy_SetUsbRFReg(struct net_device* dev,RF90_RADIO_PATH_E eRFPath,u32 RegAddr,u32 Data)
298 struct r8192_priv *priv = ieee80211_priv(dev);
300 u8 RFWaitCounter = 0;
304 // <Roger_Notes> Due to PASSIVE_LEVEL, so we ONLY simply busy waiting for a while here.
305 // We have to make sure that previous BB I/O has been done.
308 while(priv->bChangeRFInProgress)
310 //PlatformReleaseSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
311 //spin_lock_irqsave(&priv->rf_lock, flags); //LZM,090318
315 RT_TRACE(COMP_RF, "phy_SetUsbRFReg(): Wait 1 ms (%d times)...\n", RFWaitCounter);
318 if((RFWaitCounter > 100))// || RT_USB_CANNOT_IO(Adapter))
320 RT_TRACE(COMP_RF, "phy_SetUsbRFReg(): (%d) Wait too logn to query BB!!\n", RFWaitCounter);
325 //PlatformAcquireSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
329 priv->bChangeRFInProgress = true;
330 //PlatformReleaseSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
333 RegAddr &= 0x3f; //RF_Offset= 0x00~0x3F
335 write_nic_dword(dev, RF_BB_CMD_DATA, Data);
336 write_nic_dword(dev, RF_BB_CMD_ADDR, 0xF0000003|
337 (RegAddr<<8)| //RF_Offset= 0x00~0x3F
338 (eRFPath<<16)); //RF_Path = 0(A) or 1(B)
341 {// Make sure that access could be done.
342 if(read_nic_dword(dev, RF_BB_CMD_ADDR) == 0)
344 }while( --PollingCnt );
348 RT_TRACE(COMP_RF, "phy_SetUsbRFReg(): Set RegAddr(%#x) = %#x Fail!!!\n", RegAddr, Data);
351 //PlatformAcquireSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
352 //spin_unlock_irqrestore(&priv->rf_lock, flags); //LZM,090318
354 priv->bChangeRFInProgress = false;
359 /*---------------------Define local function prototype-----------------------*/
362 /*----------------------------Function Body----------------------------------*/
364 // 1. BB register R/W API
367 * Function: PHY_QueryBBReg
369 * OverView: Read "sepcific bits" from BB register
373 * u32 RegAddr, //The target address to be readback
374 * u32 BitMask //The target bit position in the target address
377 * Return: u32 Data //The readback register value
378 * Note: This function is equal to "GetRegSetting" in PHY programming guide
380 //use phy dm core 8225 8256 6052
381 //u32 PHY_QueryBBReg(struct net_device* dev,u32 RegAddr, u32 BitMask)
382 u32 rtl8192_QueryBBReg(struct net_device* dev, u32 RegAddr, u32 BitMask)
385 u32 ReturnValue = 0, OriginalValue, BitShift;
388 RT_TRACE(COMP_RF, "--->PHY_QueryBBReg(): RegAddr(%#x), BitMask(%#x)\n", RegAddr, BitMask);
391 // <Roger_Notes> Due to 8051 operation cycle (limitation cycle: 6us) and 1-Byte access issue, we should use
392 // 4181 to access Base Band instead of 8051 on USB interface to make sure that access could be done in
396 //#if ((HAL_CODE_BASE == RTL8192_S) && (DEV_BUS_TYPE==USB_INTERFACE))
397 if(IS_BB_REG_OFFSET_92S(RegAddr))
399 //if(RT_USB_CANNOT_IO(Adapter)) return FALSE;
401 if((RegAddr & 0x03) != 0)
403 printk("%s: Not DWORD alignment!!\n", __FUNCTION__);
407 OriginalValue = phy_QueryUsbBBReg(dev, RegAddr);
411 OriginalValue = read_nic_dword(dev, RegAddr);
414 BitShift = phy_CalculateBitShift(BitMask);
415 ReturnValue = (OriginalValue & BitMask) >> BitShift;
417 //RTPRINT(FPHY, PHY_BBR, ("BBR MASK=0x%x Addr[0x%x]=0x%x\n", BitMask, RegAddr, OriginalValue));
418 RT_TRACE(COMP_RF, "<---PHY_QueryBBReg(): RegAddr(%#x), BitMask(%#x), OriginalValue(%#x)\n", RegAddr, BitMask, OriginalValue);
419 return (ReturnValue);
423 * Function: PHY_SetBBReg
425 * OverView: Write "Specific bits" to BB register (page 8~)
429 * u32 RegAddr, //The target address to be modified
430 * u32 BitMask //The target bit position in the target address
432 * u32 Data //The new register value in the target bit position
433 * //of the target address
437 * Note: This function is equal to "PutRegSetting" in PHY programming guide
439 //use phy dm core 8225 8256
440 //void PHY_SetBBReg(struct net_device* dev,u32 RegAddr, u32 BitMask, u32 Data )
441 void rtl8192_setBBreg(struct net_device* dev, u32 RegAddr, u32 BitMask, u32 Data)
443 u32 OriginalValue, BitShift, NewValue;
446 RT_TRACE(COMP_RF, "--->PHY_SetBBReg(): RegAddr(%#x), BitMask(%#x), Data(%#x)\n", RegAddr, BitMask, Data);
449 // <Roger_Notes> Due to 8051 operation cycle (limitation cycle: 6us) and 1-Byte access issue, we should use
450 // 4181 to access Base Band instead of 8051 on USB interface to make sure that access could be done in
454 //#if ((HAL_CODE_BASE == RTL8192_S) && (DEV_BUS_TYPE==USB_INTERFACE))
455 if(IS_BB_REG_OFFSET_92S(RegAddr))
457 if((RegAddr & 0x03) != 0)
459 printk("%s: Not DWORD alignment!!\n", __FUNCTION__);
463 if(BitMask!= bMaskDWord)
464 {//if not "double word" write
465 OriginalValue = phy_QueryUsbBBReg(dev, RegAddr);
466 BitShift = phy_CalculateBitShift(BitMask);
467 NewValue = (((OriginalValue) & (~BitMask))|(Data << BitShift));
468 phy_SetUsbBBReg(dev, RegAddr, NewValue);
470 phy_SetUsbBBReg(dev, RegAddr, Data);
474 if(BitMask!= bMaskDWord)
475 {//if not "double word" write
476 OriginalValue = read_nic_dword(dev, RegAddr);
477 BitShift = phy_CalculateBitShift(BitMask);
478 NewValue = (((OriginalValue) & (~BitMask)) | (Data << BitShift));
479 write_nic_dword(dev, RegAddr, NewValue);
481 write_nic_dword(dev, RegAddr, Data);
484 //RT_TRACE(COMP_RF, "<---PHY_SetBBReg(): RegAddr(%#x), BitMask(%#x), Data(%#x)\n", RegAddr, BitMask, Data);
491 // 2. RF register R/W API
494 * Function: PHY_QueryRFReg
496 * OverView: Query "Specific bits" to RF register (page 8~)
500 * RF90_RADIO_PATH_E eRFPath, //Radio path of A/B/C/D
501 * u32 RegAddr, //The target address to be read
502 * u32 BitMask //The target bit position in the target address
506 * Return: u32 Readback value
507 * Note: This function is equal to "GetRFRegSetting" in PHY programming guide
510 //u32 PHY_QueryRFReg(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 RegAddr, u32 BitMask)
511 u32 rtl8192_phy_QueryRFReg(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 RegAddr, u32 BitMask)
513 u32 Original_Value, Readback_Value, BitShift;//, flags;
514 struct r8192_priv *priv = ieee80211_priv(dev);
517 RT_TRACE(COMP_RF, "--->PHY_QueryRFReg(): RegAddr(%#x), eRFPath(%#x), BitMask(%#x)\n", RegAddr, eRFPath,BitMask);
519 if (!((priv->rf_pathmap >> eRFPath) & 0x1))
521 printk("EEEEEError: rfpath off! rf_pathmap=%x eRFPath=%x\n", priv->rf_pathmap, eRFPath);
525 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
527 printk("EEEEEError: not legal rfpath! eRFPath=%x\n", eRFPath);
531 /* 2008/01/17 MH We get and release spin lock when reading RF register. */
532 //PlatformAcquireSpinLock(dev, RT_RF_OPERATE_SPINLOCK);FIXLZM
533 //spin_lock_irqsave(&priv->rf_lock, flags); //YJ,test,090113
536 // <Roger_Notes> Due to 8051 operation cycle (limitation cycle: 6us) and 1-Byte access issue, we should use
537 // 4181 to access Base Band instead of 8051 on USB interface to make sure that access could be done in
541 //#if (HAL_CODE_BASE == RTL8192_S && DEV_BUS_TYPE==USB_INTERFACE)
542 //if(RT_USB_CANNOT_IO(Adapter)) return FALSE;
543 Original_Value = phy_QueryUsbRFReg(dev, eRFPath, RegAddr);
545 BitShift = phy_CalculateBitShift(BitMask);
546 Readback_Value = (Original_Value & BitMask) >> BitShift;
547 //spin_unlock_irqrestore(&priv->rf_lock, flags); //YJ,test,090113
549 //PlatformReleaseSpinLock(dev, RT_RF_OPERATE_SPINLOCK);
551 //RTPRINT(FPHY, PHY_RFR, ("RFR-%d MASK=0x%x Addr[0x%x]=0x%x\n", eRFPath, BitMask, RegAddr, Original_Value));
553 return (Readback_Value);
557 * Function: PHY_SetRFReg
559 * OverView: Write "Specific bits" to RF register (page 8~)
563 * RF90_RADIO_PATH_E eRFPath, //Radio path of A/B/C/D
564 * u32 RegAddr, //The target address to be modified
565 * u32 BitMask //The target bit position in the target address
567 * u32 Data //The new register Data in the target bit position
568 * //of the target address
572 * Note: This function is equal to "PutRFRegSetting" in PHY programming guide
575 //void PHY_SetRFReg(struct net_device* dev,RF90_RADIO_PATH_E eRFPath, u32 RegAddr, u32 BitMask,u32 Data )
576 void rtl8192_phy_SetRFReg(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
579 struct r8192_priv *priv = ieee80211_priv(dev);
580 u32 Original_Value, BitShift, New_Value;//, flags;
582 RT_TRACE(COMP_RF, "--->PHY_SetRFReg(): RegAddr(%#x), BitMask(%#x), Data(%#x), eRFPath(%#x)\n",
583 RegAddr, BitMask, Data, eRFPath);
585 if (!((priv->rf_pathmap >> eRFPath) & 0x1))
587 printk("EEEEEError: rfpath off! rf_pathmap=%x eRFPath=%x\n", priv->rf_pathmap, eRFPath);
590 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
592 printk("EEEEEError: not legal rfpath! eRFPath=%x\n", eRFPath);
596 /* 2008/01/17 MH We get and release spin lock when writing RF register. */
597 //PlatformAcquireSpinLock(dev, RT_RF_OPERATE_SPINLOCK);
598 //spin_lock_irqsave(&priv->rf_lock, flags); //YJ,test,090113
601 // <Roger_Notes> Due to 8051 operation cycle (limitation cycle: 6us) and 1-Byte access issue, we should use
602 // 4181 to access Base Band instead of 8051 on USB interface to make sure that access could be done in
606 //#if (HAL_CODE_BASE == RTL8192_S && DEV_BUS_TYPE==USB_INTERFACE)
607 //if(RT_USB_CANNOT_IO(Adapter)) return;
609 if (BitMask != bRFRegOffsetMask) // RF data is 12 bits only
611 Original_Value = phy_QueryUsbRFReg(dev, eRFPath, RegAddr);
612 BitShift = phy_CalculateBitShift(BitMask);
613 New_Value = (((Original_Value)&(~BitMask))|(Data<< BitShift));
614 phy_SetUsbRFReg(dev, eRFPath, RegAddr, New_Value);
617 phy_SetUsbRFReg(dev, eRFPath, RegAddr, Data);
618 //PlatformReleaseSpinLock(dev, RT_RF_OPERATE_SPINLOCK);
619 //spin_unlock_irqrestore(&priv->rf_lock, flags); //YJ,test,090113
621 //RTPRINT(FPHY, PHY_RFW, ("RFW-%d MASK=0x%x Addr[0x%x]=0x%x\n", eRFPath, BitMask, RegAddr, Data));
622 RT_TRACE(COMP_RF, "<---PHY_SetRFReg(): RegAddr(%#x), BitMask(%#x), Data(%#x), eRFPath(%#x)\n",
623 RegAddr, BitMask, Data, eRFPath);
628 * Function: phy_CalculateBitShift
630 * OverView: Get shifted position of the BitMask
636 * Return: u32 Return the shift bit bit position of the mask
639 static u32 phy_CalculateBitShift(u32 BitMask)
645 if ( ((BitMask>>i) & 0x1 ) == 1)
654 // 3. Initial MAC/BB/RF config by reading MAC/BB/RF txt.
656 /*-----------------------------------------------------------------------------
657 * Function: PHY_MACConfig8192S
659 * Overview: Condig MAC by header file or parameter file.
669 * 08/12/2008 MHC Create Version 0.
671 *---------------------------------------------------------------------------*/
673 extern bool PHY_MACConfig8192S(struct net_device* dev)
675 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
680 rtStatus = phy_ConfigMACWithHeaderFile(dev);
681 return (rtStatus == RT_STATUS_SUCCESS) ? true:false;
687 PHY_BBConfig8192S(struct net_device* dev)
689 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
691 u8 PathMap = 0, index = 0, rf_num = 0;
692 struct r8192_priv *priv = ieee80211_priv(dev);
693 phy_InitBBRFRegisterDefinition(dev);
698 //switch( Adapter->MgntInfo.bRegHwParaFile )
701 // phy_BB8190_Config_HardCode(dev);
705 rtStatus = phy_BB8192S_Config_ParaFile(dev);
710 // phy_BB8190_Config_HardCode(dev);
711 // phy_BB8192S_Config_ParaFile(dev);
715 // phy_BB8190_Config_HardCode(dev);
718 PathMap = (u8)(rtl8192_QueryBBReg(dev, rFPGA0_TxInfo, 0xf) |
719 rtl8192_QueryBBReg(dev, rOFDM0_TRxPathEnable, 0xf));
720 priv->rf_pathmap = PathMap;
721 for(index = 0; index<4; index++)
723 if((PathMap>>index)&0x1)
727 if((priv->rf_type==RF_1T1R && rf_num!=1) ||
728 (priv->rf_type==RF_1T2R && rf_num!=2) ||
729 (priv->rf_type==RF_2T2R && rf_num!=2) ||
730 (priv->rf_type==RF_2T2R_GREEN && rf_num!=2) ||
731 (priv->rf_type==RF_2T4R && rf_num!=4))
733 RT_TRACE( COMP_INIT, "PHY_BBConfig8192S: RF_Type(%x) does not match RF_Num(%x)!!\n", priv->rf_type, rf_num);
735 return (rtStatus == RT_STATUS_SUCCESS) ? 1:0;
740 PHY_RFConfig8192S(struct net_device* dev)
742 struct r8192_priv *priv = ieee80211_priv(dev);
743 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
745 //Set priv->rf_chip = RF_8225 to do real PHY FPGA initilization
747 //<Roger_EXP> We assign RF type here temporally. 2008.09.12.
748 priv->rf_chip = RF_6052;
753 switch(priv->rf_chip)
757 rtStatus = PHY_RF6052_Config(dev);
761 //rtStatus = PHY_RF8256_Config(dev);
768 //rtStatus = PHY_RF8225_Config(dev);
774 return (rtStatus == RT_STATUS_SUCCESS) ? 1:0;
778 // Joseph test: new initialize order!!
779 // Test only!! This part need to be re-organized.
780 // Now it is just for 8256.
784 phy_BB8190_Config_HardCode(struct net_device* dev)
786 //RT_ASSERT(FALSE, ("This function is not implement yet!! \n"));
787 return RT_STATUS_SUCCESS;
791 /*-----------------------------------------------------------------------------
792 * Function: phy_SetBBtoDiffRFWithHeaderFile()
794 * Overview: This function
797 * Input: PADAPTER Adapter
798 * u1Byte ConfigType 0 => PHY_CONFIG
802 * Return: RT_STATUS_SUCCESS: configuration file exist
806 *---------------------------------------------------------------------------*/
808 phy_SetBBtoDiffRFWithHeaderFile(struct net_device* dev, u8 ConfigType)
811 struct r8192_priv *priv = ieee80211_priv(dev);
812 u32* Rtl819XPHY_REGArraytoXTXR_Table;
813 u16 PHY_REGArraytoXTXRLen;
815 //#if (HAL_CODE_BASE != RTL8192_S)
817 if(priv->rf_type == RF_1T1R)
819 Rtl819XPHY_REGArraytoXTXR_Table = Rtl819XPHY_REG_to1T1R_Array;
820 PHY_REGArraytoXTXRLen = PHY_ChangeTo_1T1RArrayLength;
822 else if(priv->rf_type == RF_1T2R)
824 Rtl819XPHY_REGArraytoXTXR_Table = Rtl819XPHY_REG_to1T2R_Array;
825 PHY_REGArraytoXTXRLen = PHY_ChangeTo_1T2RArrayLength;
827 //else if(priv->rf_type == RF_2T2R || priv->rf_type == RF_2T2R_GREEN)
829 // Rtl819XPHY_REGArraytoXTXR_Table = Rtl819XPHY_REG_to2T2R_Array;
830 // PHY_REGArraytoXTXRLen = PHY_ChangeTo_2T2RArrayLength;
834 return RT_STATUS_FAILURE;
837 if(ConfigType == BaseBand_Config_PHY_REG)
839 for(i=0;i<PHY_REGArraytoXTXRLen;i=i+3)
841 if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xfe)
843 else if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xfd)
845 else if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xfc)
847 else if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xfb)
849 else if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xfa)
851 else if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xf9)
853 rtl8192_setBBreg(dev, Rtl819XPHY_REGArraytoXTXR_Table[i], Rtl819XPHY_REGArraytoXTXR_Table[i+1], Rtl819XPHY_REGArraytoXTXR_Table[i+2]);
854 //RT_TRACE(COMP_SEND,
855 //"The Rtl819XPHY_REGArraytoXTXR_Table[0] is %lx Rtl819XPHY_REGArraytoXTXR_Table[1] is %lx Rtl819XPHY_REGArraytoXTXR_Table[2] is %lx \n",
856 //Rtl819XPHY_REGArraytoXTXR_Table[i],Rtl819XPHY_REGArraytoXTXR_Table[i+1], Rtl819XPHY_REGArraytoXTXR_Table[i+2]);
860 RT_TRACE(COMP_SEND, "phy_SetBBtoDiffRFWithHeaderFile(): ConfigType != BaseBand_Config_PHY_REG\n");
862 //#endif // #if (HAL_CODE_BASE != RTL8192_S)
863 return RT_STATUS_SUCCESS;
869 phy_BB8192S_Config_ParaFile(struct net_device* dev)
871 struct r8192_priv *priv = ieee80211_priv(dev);
872 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
875 //char szBBRegFile[] = RTL819X_PHY_REG;
876 //char szBBRegFile1T2R[] = RTL819X_PHY_REG_1T2R;
877 //char szBBRegPgFile[] = RTL819X_PHY_REG_PG;
878 //char szAGCTableFile[] = RTL819X_AGC_TAB;
879 //char szBBRegto1T1RFile[] = RTL819X_PHY_REG_to1T1R;
880 //char szBBRegto1T2RFile[] = RTL819X_PHY_REG_to1T2R;
882 RT_TRACE(COMP_INIT, "==>phy_BB8192S_Config_ParaFile\n");
885 // 1. Read PHY_REG.TXT BB INIT!!
886 // We will seperate as 1T1R/1T2R/1T2R_GREEN/2T2R
888 if (priv->rf_type == RF_1T2R || priv->rf_type == RF_2T2R ||
889 priv->rf_type == RF_1T1R ||priv->rf_type == RF_2T2R_GREEN)
891 rtStatus = phy_ConfigBBWithHeaderFile(dev,BaseBand_Config_PHY_REG);
892 if(priv->rf_type != RF_2T2R && priv->rf_type != RF_2T2R_GREEN)
893 {//2008.11.10 Added by tynli. The default PHY_REG.txt we read is for 2T2R,
894 //so we should reconfig BB reg with the right PHY parameters.
895 rtStatus = phy_SetBBtoDiffRFWithHeaderFile(dev,BaseBand_Config_PHY_REG);
898 rtStatus = RT_STATUS_FAILURE;
900 if(rtStatus != RT_STATUS_SUCCESS){
901 RT_TRACE(COMP_INIT, "phy_BB8192S_Config_ParaFile():Write BB Reg Fail!!");
902 goto phy_BB8190_Config_ParaFile_Fail;
906 // 2. If EEPROM or EFUSE autoload OK, We must config by PHY_REG_PG.txt
908 if (priv->AutoloadFailFlag == false)
910 rtStatus = phy_ConfigBBWithPgHeaderFile(dev,BaseBand_Config_PHY_REG);
912 if(rtStatus != RT_STATUS_SUCCESS){
913 RT_TRACE(COMP_INIT, "phy_BB8192S_Config_ParaFile():BB_PG Reg Fail!!");
914 goto phy_BB8190_Config_ParaFile_Fail;
918 // 3. BB AGC table Initialization
920 rtStatus = phy_ConfigBBWithHeaderFile(dev,BaseBand_Config_AGC_TAB);
922 if(rtStatus != RT_STATUS_SUCCESS){
923 printk( "phy_BB8192S_Config_ParaFile():AGC Table Fail\n");
924 goto phy_BB8190_Config_ParaFile_Fail;
928 // Check if the CCK HighPower is turned ON.
929 // This is used to calculate PWDB.
930 priv->bCckHighPower = (bool)(rtl8192_QueryBBReg(dev, rFPGA0_XA_HSSIParameter2, 0x200));
933 phy_BB8190_Config_ParaFile_Fail:
937 /*-----------------------------------------------------------------------------
938 * Function: phy_ConfigMACWithHeaderFile()
940 * Overview: This function read BB parameters from Header file we gen, and do register
943 * Input: PADAPTER Adapter
948 * Return: RT_STATUS_SUCCESS: configuration file exist
950 * Note: The format of MACPHY_REG.txt is different from PHY and RF.
951 * [Register][Mask][Value]
952 *---------------------------------------------------------------------------*/
955 phy_ConfigMACWithHeaderFile(struct net_device* dev)
960 //struct r8192_priv *priv = ieee80211_priv(dev);
962 //#if (HAL_CODE_BASE != RTL8192_S)
963 /*if(Adapter->bInHctTest)
965 RT_TRACE(COMP_INIT, DBG_LOUD, ("Rtl819XMACPHY_ArrayDTM\n"));
966 ArrayLength = MACPHY_ArrayLengthDTM;
967 ptrArray = Rtl819XMACPHY_ArrayDTM;
969 else if(pHalData->bTXPowerDataReadFromEEPORM)
971 // RT_TRACE(COMP_INIT, DBG_LOUD, ("Rtl819XMACPHY_Array_PG\n"));
972 // ArrayLength = MACPHY_Array_PGLength;
973 // ptrArray = Rtl819XMACPHY_Array_PG;
976 { //2008.11.06 Modified by tynli.
977 RT_TRACE(COMP_INIT, "Read Rtl819XMACPHY_Array\n");
978 ArrayLength = MAC_2T_ArrayLength;
979 ptrArray = Rtl819XMAC_Array;
982 /*for(i = 0 ;i < ArrayLength;i=i+3){
983 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]));
984 if(ptrArray[i] == 0x318)
986 ptrArray[i+2] = 0x00000800;
987 //DbgPrint("ptrArray[i], ptrArray[i+1], ptrArray[i+2] = %x, %x, %x\n",
988 // ptrArray[i], ptrArray[i+1], ptrArray[i+2]);
990 PHY_SetBBReg(Adapter, ptrArray[i], ptrArray[i+1], ptrArray[i+2]);
992 for(i = 0 ;i < ArrayLength;i=i+2){ // Add by tynli for 2 column
993 write_nic_byte(dev, ptrArray[i], (u8)ptrArray[i+1]);
996 return RT_STATUS_SUCCESS;
999 /*-----------------------------------------------------------------------------
1000 * Function: phy_ConfigBBWithHeaderFile()
1002 * Overview: This function read BB parameters from general file format, and do register
1005 * Input: PADAPTER Adapter
1006 * u8 ConfigType 0 => PHY_CONFIG
1011 * Return: RT_STATUS_SUCCESS: configuration file exist
1013 *---------------------------------------------------------------------------*/
1016 phy_ConfigBBWithHeaderFile(struct net_device* dev,u8 ConfigType)
1020 u32* Rtl819XPHY_REGArray_Table;
1021 u32* Rtl819XAGCTAB_Array_Table;
1022 u16 PHY_REGArrayLen, AGCTAB_ArrayLen;
1023 //struct r8192_priv *priv = ieee80211_priv(dev);
1024 //#if (HAL_CODE_BASE != RTL8192_S)
1025 /*if(Adapter->bInHctTest)
1028 AGCTAB_ArrayLen = AGCTAB_ArrayLengthDTM;
1029 Rtl819XAGCTAB_Array_Table = Rtl819XAGCTAB_ArrayDTM;
1031 if(pHalData->RF_Type == RF_2T4R)
1033 PHY_REGArrayLen = PHY_REGArrayLengthDTM;
1034 Rtl819XPHY_REGArray_Table = Rtl819XPHY_REGArrayDTM;
1036 else if (pHalData->RF_Type == RF_1T2R)
1038 PHY_REGArrayLen = PHY_REG_1T2RArrayLengthDTM;
1039 Rtl819XPHY_REGArray_Table = Rtl819XPHY_REG_1T2RArrayDTM;
1047 // 2008.11.06 Modified by tynli.
1049 AGCTAB_ArrayLen = AGCTAB_ArrayLength;
1050 Rtl819XAGCTAB_Array_Table = Rtl819XAGCTAB_Array;
1051 PHY_REGArrayLen = PHY_REG_2T2RArrayLength; // Default RF_type: 2T2R
1052 Rtl819XPHY_REGArray_Table = Rtl819XPHY_REG_Array;
1055 if(ConfigType == BaseBand_Config_PHY_REG)
1057 for(i=0;i<PHY_REGArrayLen;i=i+2)
1059 if (Rtl819XPHY_REGArray_Table[i] == 0xfe)
1061 else if (Rtl819XPHY_REGArray_Table[i] == 0xfd)
1063 else if (Rtl819XPHY_REGArray_Table[i] == 0xfc)
1065 else if (Rtl819XPHY_REGArray_Table[i] == 0xfb)
1067 else if (Rtl819XPHY_REGArray_Table[i] == 0xfa)
1069 else if (Rtl819XPHY_REGArray_Table[i] == 0xf9)
1071 rtl8192_setBBreg(dev, Rtl819XPHY_REGArray_Table[i], bMaskDWord, Rtl819XPHY_REGArray_Table[i+1]);
1072 //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]);
1076 else if(ConfigType == BaseBand_Config_AGC_TAB){
1077 for(i=0;i<AGCTAB_ArrayLen;i=i+2)
1079 rtl8192_setBBreg(dev, Rtl819XAGCTAB_Array_Table[i], bMaskDWord, Rtl819XAGCTAB_Array_Table[i+1]);
1082 //#endif // #if (HAL_CODE_BASE != RTL8192_S)
1083 return RT_STATUS_SUCCESS;
1086 /*-----------------------------------------------------------------------------
1087 * Function: phy_ConfigBBWithPgHeaderFile
1089 * Overview: Config PHY_REG_PG array
1099 * 11/06/2008 MHC Add later!!!!!!.. Please modify for new files!!!!
1100 * 11/10/2008 tynli Modify to mew files.
1102 *---------------------------------------------------------------------------*/
1104 phy_ConfigBBWithPgHeaderFile(struct net_device* dev,u8 ConfigType)
1108 u32* Rtl819XPHY_REGArray_Table_PG;
1109 u16 PHY_REGArrayPGLen;
1110 //struct r8192_priv *priv = ieee80211_priv(dev);
1111 //#if (HAL_CODE_BASE != RTL8192_S)
1112 // Default: pHalData->RF_Type = RF_2T2R.
1114 PHY_REGArrayPGLen = PHY_REG_Array_PGLength;
1115 Rtl819XPHY_REGArray_Table_PG = Rtl819XPHY_REG_Array_PG;
1117 if(ConfigType == BaseBand_Config_PHY_REG)
1119 for(i=0;i<PHY_REGArrayPGLen;i=i+3)
1121 if (Rtl819XPHY_REGArray_Table_PG[i] == 0xfe)
1123 else if (Rtl819XPHY_REGArray_Table_PG[i] == 0xfd)
1125 else if (Rtl819XPHY_REGArray_Table_PG[i] == 0xfc)
1127 else if (Rtl819XPHY_REGArray_Table_PG[i] == 0xfb)
1129 else if (Rtl819XPHY_REGArray_Table_PG[i] == 0xfa)
1131 else if (Rtl819XPHY_REGArray_Table_PG[i] == 0xf9)
1133 rtl8192_setBBreg(dev, Rtl819XPHY_REGArray_Table_PG[i], Rtl819XPHY_REGArray_Table_PG[i+1], Rtl819XPHY_REGArray_Table_PG[i+2]);
1134 //RT_TRACE(COMP_SEND, "The Rtl819XPHY_REGArray_Table_PG[0] is %lx Rtl819XPHY_REGArray_Table_PG[1] is %lx \n",
1135 // Rtl819XPHY_REGArray_Table_PG[i], Rtl819XPHY_REGArray_Table_PG[i+1]);
1138 RT_TRACE(COMP_SEND, "phy_ConfigBBWithPgHeaderFile(): ConfigType != BaseBand_Config_PHY_REG\n");
1140 return RT_STATUS_SUCCESS;
1142 } /* phy_ConfigBBWithPgHeaderFile */
1144 /*-----------------------------------------------------------------------------
1145 * Function: PHY_ConfigRFWithHeaderFile()
1147 * Overview: This function read RF parameters from general file format, and do RF 3-wire
1149 * Input: PADAPTER Adapter
1151 * RF90_RADIO_PATH_E eRFPath
1155 * Return: RT_STATUS_SUCCESS: configuration file exist
1157 * Note: Delay may be required for RF configuration
1158 *---------------------------------------------------------------------------*/
1159 //in 8256 phy_RF8256_Config_ParaFile only
1160 //RT_STATUS PHY_ConfigRFWithHeaderFile(struct net_device* dev,RF90_RADIO_PATH_E eRFPath)
1161 u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device* dev, RF90_RADIO_PATH_E eRFPath)
1164 struct r8192_priv *priv = ieee80211_priv(dev);
1167 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
1168 u32 *Rtl819XRadioA_Array_Table;
1169 u32 *Rtl819XRadioB_Array_Table;
1170 //u32* Rtl819XRadioC_Array_Table;
1171 //u32* Rtl819XRadioD_Array_Table;
1172 u16 RadioA_ArrayLen,RadioB_ArrayLen;
1174 { //2008.11.06 Modified by tynli
1175 RadioA_ArrayLen = RadioA_1T_ArrayLength;
1176 Rtl819XRadioA_Array_Table=Rtl819XRadioA_Array;
1177 Rtl819XRadioB_Array_Table=Rtl819XRadioB_Array;
1178 RadioB_ArrayLen = RadioB_ArrayLength;
1181 if( priv->rf_type == RF_2T2R_GREEN )
1183 Rtl819XRadioB_Array_Table = Rtl819XRadioB_GM_Array;
1184 RadioB_ArrayLen = RadioB_GM_ArrayLength;
1188 Rtl819XRadioB_Array_Table = Rtl819XRadioB_Array;
1189 RadioB_ArrayLen = RadioB_ArrayLength;
1192 rtStatus = RT_STATUS_SUCCESS;
1194 // When initialization, we want the delay function(mdelay(), delay_us()
1195 // ==> actually we call PlatformStallExecution()) to do NdisStallExecution()
1196 // [busy wait] instead of NdisMSleep(). So we acquire RT_INITIAL_SPINLOCK
1197 // to run at Dispatch level to achive it.
1198 //cosa PlatformAcquireSpinLock(Adapter, RT_INITIAL_SPINLOCK);
1202 for(i = 0;i<RadioA_ArrayLen; i=i+2){
1203 if(Rtl819XRadioA_Array_Table[i] == 0xfe)
1204 { // Deay specific ms. Only RF configuration require delay.
1205 //#if (DEV_BUS_TYPE == USB_INTERFACE)
1208 else if (Rtl819XRadioA_Array_Table[i] == 0xfd)
1210 else if (Rtl819XRadioA_Array_Table[i] == 0xfc)
1212 else if (Rtl819XRadioA_Array_Table[i] == 0xfb)
1214 //PlatformStallExecution(50);
1215 else if (Rtl819XRadioA_Array_Table[i] == 0xfa)
1217 else if (Rtl819XRadioA_Array_Table[i] == 0xf9)
1221 rtl8192_phy_SetRFReg(dev, eRFPath, Rtl819XRadioA_Array_Table[i], bRFRegOffsetMask, Rtl819XRadioA_Array_Table[i+1]);
1226 for(i = 0;i<RadioB_ArrayLen; i=i+2){
1227 if(Rtl819XRadioB_Array_Table[i] == 0xfe)
1228 { // Deay specific ms. Only RF configuration require delay.
1229 //#if (DEV_BUS_TYPE == USB_INTERFACE)
1232 else if (Rtl819XRadioB_Array_Table[i] == 0xfd)
1234 else if (Rtl819XRadioB_Array_Table[i] == 0xfc)
1236 else if (Rtl819XRadioB_Array_Table[i] == 0xfb)
1238 else if (Rtl819XRadioB_Array_Table[i] == 0xfa)
1240 else if (Rtl819XRadioB_Array_Table[i] == 0xf9)
1244 rtl8192_phy_SetRFReg(dev, eRFPath, Rtl819XRadioB_Array_Table[i], bRFRegOffsetMask, Rtl819XRadioB_Array_Table[i+1]);
1260 /*-----------------------------------------------------------------------------
1261 * Function: PHY_CheckBBAndRFOK()
1263 * Overview: This function is write register and then readback to make sure whether
1264 * BB[PHY0, PHY1], RF[Patha, path b, path c, path d] is Ok
1266 * Input: PADAPTER Adapter
1267 * HW90_BLOCK_E CheckBlock
1268 * RF90_RADIO_PATH_E eRFPath // it is used only when CheckBlock is HW90_BLOCK_RF
1272 * Return: RT_STATUS_SUCCESS: PHY is OK
1274 * Note: This function may be removed in the ASIC
1275 *---------------------------------------------------------------------------*/
1276 //in 8256 phy_RF8256_Config_HardCode
1277 //but we don't use it temp
1280 struct net_device* dev,
1281 HW90_BLOCK_E CheckBlock,
1282 RF90_RADIO_PATH_E eRFPath
1285 //struct r8192_priv *priv = ieee80211_priv(dev);
1286 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
1287 u32 i, CheckTimes = 4,ulRegRead = 0;
1289 u32 WriteData[] = {0xfffff027, 0xaa55a02f, 0x00000027, 0x55aa502f};
1291 // Initialize register address offset to be checked
1292 WriteAddr[HW90_BLOCK_MAC] = 0x100;
1293 WriteAddr[HW90_BLOCK_PHY0] = 0x900;
1294 WriteAddr[HW90_BLOCK_PHY1] = 0x800;
1295 WriteAddr[HW90_BLOCK_RF] = 0x3;
1297 for(i=0 ; i < CheckTimes ; i++)
1301 // Write Data to register and readback
1305 case HW90_BLOCK_MAC:
1306 //RT_ASSERT(FALSE, ("PHY_CheckBBRFOK(): Never Write 0x100 here!"));
1307 RT_TRACE(COMP_INIT, "PHY_CheckBBRFOK(): Never Write 0x100 here!\n");
1310 case HW90_BLOCK_PHY0:
1311 case HW90_BLOCK_PHY1:
1312 write_nic_dword(dev, WriteAddr[CheckBlock], WriteData[i]);
1313 ulRegRead = read_nic_dword(dev, WriteAddr[CheckBlock]);
1317 // When initialization, we want the delay function(mdelay(), delay_us()
1318 // ==> actually we call PlatformStallExecution()) to do NdisStallExecution()
1319 // [busy wait] instead of NdisMSleep(). So we acquire RT_INITIAL_SPINLOCK
1320 // to run at Dispatch level to achive it.
1321 //cosa PlatformAcquireSpinLock(dev, RT_INITIAL_SPINLOCK);
1322 WriteData[i] &= 0xfff;
1323 rtl8192_phy_SetRFReg(dev, eRFPath, WriteAddr[HW90_BLOCK_RF], bRFRegOffsetMask, WriteData[i]);
1324 // TODO: we should not delay for such a long time. Ask SD3
1326 ulRegRead = rtl8192_phy_QueryRFReg(dev, eRFPath, WriteAddr[HW90_BLOCK_RF], bMaskDWord);
1328 //cosa PlatformReleaseSpinLock(dev, RT_INITIAL_SPINLOCK);
1332 rtStatus = RT_STATUS_FAILURE;
1338 // Check whether readback data is correct
1340 if(ulRegRead != WriteData[i])
1342 //RT_TRACE(COMP_FPGA, ("ulRegRead: %x, WriteData: %x \n", ulRegRead, WriteData[i]));
1343 RT_TRACE(COMP_ERR, "read back error(read:%x, write:%x)\n", ulRegRead, WriteData[i]);
1344 rtStatus = RT_STATUS_FAILURE;
1352 //no use temp in windows driver
1355 PHY_SetRFPowerState8192SUsb(
1356 struct net_device* dev,
1357 RF_POWER_STATE RFPowerState
1360 struct r8192_priv *priv = ieee80211_priv(dev);
1361 bool WaitShutDown = FALSE;
1363 //RF90_RADIO_PATH_E eRFPath;
1365 BB_REGISTER_DEFINITION_T *pPhyReg;
1367 if(priv->SetRFPowerStateInProgress == TRUE)
1370 priv->SetRFPowerStateInProgress = TRUE;
1372 // TODO: Emily, 2006.11.21, we should rewrite this function
1374 if(RFPowerState==RF_SHUT_DOWN)
1376 RFPowerState=RF_OFF;
1381 priv->RFPowerState = RFPowerState;
1382 switch( priv->rf_chip )
1386 switch( RFPowerState )
1400 switch( RFPowerState )
1409 for(eRFPath=(RF90_RADIO_PATH_E)RF90_PATH_A; eRFPath < RF90_PATH_MAX; eRFPath++)
1411 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
1414 pPhyReg = &priv->PHYRegDef[eRFPath];
1415 rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV, bRFSI_RFENV);
1416 rtl8192_setBBreg(dev, pPhyReg->rfintfo, bRFSI_RFENV, 0);
1424 }// switch( priv->rf_chip )
1426 priv->SetRFPowerStateInProgress = FALSE;
1431 //no use temp in windows driver
1433 PHY_UpdateInitialGain(
1434 struct net_device* dev
1437 struct r8192_priv *priv = ieee80211_priv(dev);
1438 //unsigned char *IGTable;
1439 //u8 DIG_CurrentInitialGain = 4;
1441 switch(priv->rf_chip)
1454 RT_TRACE(COMP_DBG, "PHY_UpdateInitialGain(): unknown rf_chip: %#X\n", priv->rf_chip);
1460 //YJ,modified,090107
1461 void PHY_GetHWRegOriginalValue(struct net_device* dev)
1463 struct r8192_priv *priv = ieee80211_priv(dev);
1465 // read tx power offset
1467 priv->MCSTxPowerLevelOriginalOffset[0] =
1468 rtl8192_QueryBBReg(dev, rTxAGC_Rate18_06, bMaskDWord);
1469 priv->MCSTxPowerLevelOriginalOffset[1] =
1470 rtl8192_QueryBBReg(dev, rTxAGC_Rate54_24, bMaskDWord);
1471 priv->MCSTxPowerLevelOriginalOffset[2] =
1472 rtl8192_QueryBBReg(dev, rTxAGC_Mcs03_Mcs00, bMaskDWord);
1473 priv->MCSTxPowerLevelOriginalOffset[3] =
1474 rtl8192_QueryBBReg(dev, rTxAGC_Mcs07_Mcs04, bMaskDWord);
1475 priv->MCSTxPowerLevelOriginalOffset[4] =
1476 rtl8192_QueryBBReg(dev, rTxAGC_Mcs11_Mcs08, bMaskDWord);
1477 priv->MCSTxPowerLevelOriginalOffset[5] =
1478 rtl8192_QueryBBReg(dev, rTxAGC_Mcs15_Mcs12, bMaskDWord);
1481 priv->MCSTxPowerLevelOriginalOffset[6] =
1482 rtl8192_QueryBBReg(dev, rTxAGC_CCK_Mcs32, bMaskDWord);
1483 RT_TRACE(COMP_INIT, "Legacy OFDM =%08x/%08x HT_OFDM=%08x/%08x/%08x/%08x\n",
1484 priv->MCSTxPowerLevelOriginalOffset[0], priv->MCSTxPowerLevelOriginalOffset[1] ,
1485 priv->MCSTxPowerLevelOriginalOffset[2], priv->MCSTxPowerLevelOriginalOffset[3] ,
1486 priv->MCSTxPowerLevelOriginalOffset[4], priv->MCSTxPowerLevelOriginalOffset[5] );
1488 // read rx initial gain
1489 priv->DefaultInitialGain[0] = rtl8192_QueryBBReg(dev, rOFDM0_XAAGCCore1, bMaskByte0);
1490 priv->DefaultInitialGain[1] = rtl8192_QueryBBReg(dev, rOFDM0_XBAGCCore1, bMaskByte0);
1491 priv->DefaultInitialGain[2] = rtl8192_QueryBBReg(dev, rOFDM0_XCAGCCore1, bMaskByte0);
1492 priv->DefaultInitialGain[3] = rtl8192_QueryBBReg(dev, rOFDM0_XDAGCCore1, bMaskByte0);
1493 RT_TRACE(COMP_INIT, "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x) \n",
1494 priv->DefaultInitialGain[0], priv->DefaultInitialGain[1],
1495 priv->DefaultInitialGain[2], priv->DefaultInitialGain[3]);
1498 priv->framesync = rtl8192_QueryBBReg(dev, rOFDM0_RxDetector3, bMaskByte0);
1499 priv->framesyncC34 = rtl8192_QueryBBReg(dev, rOFDM0_RxDetector2, bMaskDWord);
1500 RT_TRACE(COMP_INIT, "Default framesync (0x%x) = 0x%x \n",
1501 rOFDM0_RxDetector3, priv->framesync);
1503 //YJ,modified,090107,end
1508 * Function: phy_InitBBRFRegisterDefinition
1510 * OverView: Initialize Register definition offset for Radio Path A/B/C/D
1517 * Note: The initialization value is constant and it should never be changes
1520 static void phy_InitBBRFRegisterDefinition( struct net_device* dev)
1522 struct r8192_priv *priv = ieee80211_priv(dev);
1524 // RF Interface Sowrtware Control
1525 priv->PHYRegDef[RF90_PATH_A].rfintfs = rFPGA0_XAB_RFInterfaceSW; // 16 LSBs if read 32-bit from 0x870
1526 priv->PHYRegDef[RF90_PATH_B].rfintfs = rFPGA0_XAB_RFInterfaceSW; // 16 MSBs if read 32-bit from 0x870 (16-bit for 0x872)
1527 priv->PHYRegDef[RF90_PATH_C].rfintfs = rFPGA0_XCD_RFInterfaceSW;// 16 LSBs if read 32-bit from 0x874
1528 priv->PHYRegDef[RF90_PATH_D].rfintfs = rFPGA0_XCD_RFInterfaceSW;// 16 MSBs if read 32-bit from 0x874 (16-bit for 0x876)
1530 // RF Interface Readback Value
1531 priv->PHYRegDef[RF90_PATH_A].rfintfi = rFPGA0_XAB_RFInterfaceRB; // 16 LSBs if read 32-bit from 0x8E0
1532 priv->PHYRegDef[RF90_PATH_B].rfintfi = rFPGA0_XAB_RFInterfaceRB;// 16 MSBs if read 32-bit from 0x8E0 (16-bit for 0x8E2)
1533 priv->PHYRegDef[RF90_PATH_C].rfintfi = rFPGA0_XCD_RFInterfaceRB;// 16 LSBs if read 32-bit from 0x8E4
1534 priv->PHYRegDef[RF90_PATH_D].rfintfi = rFPGA0_XCD_RFInterfaceRB;// 16 MSBs if read 32-bit from 0x8E4 (16-bit for 0x8E6)
1536 // RF Interface Output (and Enable)
1537 priv->PHYRegDef[RF90_PATH_A].rfintfo = rFPGA0_XA_RFInterfaceOE; // 16 LSBs if read 32-bit from 0x860
1538 priv->PHYRegDef[RF90_PATH_B].rfintfo = rFPGA0_XB_RFInterfaceOE; // 16 LSBs if read 32-bit from 0x864
1539 priv->PHYRegDef[RF90_PATH_C].rfintfo = rFPGA0_XC_RFInterfaceOE;// 16 LSBs if read 32-bit from 0x868
1540 priv->PHYRegDef[RF90_PATH_D].rfintfo = rFPGA0_XD_RFInterfaceOE;// 16 LSBs if read 32-bit from 0x86C
1542 // RF Interface (Output and) Enable
1543 priv->PHYRegDef[RF90_PATH_A].rfintfe = rFPGA0_XA_RFInterfaceOE; // 16 MSBs if read 32-bit from 0x860 (16-bit for 0x862)
1544 priv->PHYRegDef[RF90_PATH_B].rfintfe = rFPGA0_XB_RFInterfaceOE; // 16 MSBs if read 32-bit from 0x864 (16-bit for 0x866)
1545 priv->PHYRegDef[RF90_PATH_C].rfintfe = rFPGA0_XC_RFInterfaceOE;// 16 MSBs if read 32-bit from 0x86A (16-bit for 0x86A)
1546 priv->PHYRegDef[RF90_PATH_D].rfintfe = rFPGA0_XD_RFInterfaceOE;// 16 MSBs if read 32-bit from 0x86C (16-bit for 0x86E)
1548 //Addr of LSSI. Wirte RF register by driver
1549 priv->PHYRegDef[RF90_PATH_A].rf3wireOffset = rFPGA0_XA_LSSIParameter; //LSSI Parameter
1550 priv->PHYRegDef[RF90_PATH_B].rf3wireOffset = rFPGA0_XB_LSSIParameter;
1551 priv->PHYRegDef[RF90_PATH_C].rf3wireOffset = rFPGA0_XC_LSSIParameter;
1552 priv->PHYRegDef[RF90_PATH_D].rf3wireOffset = rFPGA0_XD_LSSIParameter;
1555 priv->PHYRegDef[RF90_PATH_A].rfLSSI_Select = rFPGA0_XAB_RFParameter; //BB Band Select
1556 priv->PHYRegDef[RF90_PATH_B].rfLSSI_Select = rFPGA0_XAB_RFParameter;
1557 priv->PHYRegDef[RF90_PATH_C].rfLSSI_Select = rFPGA0_XCD_RFParameter;
1558 priv->PHYRegDef[RF90_PATH_D].rfLSSI_Select = rFPGA0_XCD_RFParameter;
1560 // Tx AGC Gain Stage (same for all path. Should we remove this?)
1561 priv->PHYRegDef[RF90_PATH_A].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
1562 priv->PHYRegDef[RF90_PATH_B].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
1563 priv->PHYRegDef[RF90_PATH_C].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
1564 priv->PHYRegDef[RF90_PATH_D].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
1566 // Tranceiver A~D HSSI Parameter-1
1567 priv->PHYRegDef[RF90_PATH_A].rfHSSIPara1 = rFPGA0_XA_HSSIParameter1; //wire control parameter1
1568 priv->PHYRegDef[RF90_PATH_B].rfHSSIPara1 = rFPGA0_XB_HSSIParameter1; //wire control parameter1
1569 priv->PHYRegDef[RF90_PATH_C].rfHSSIPara1 = rFPGA0_XC_HSSIParameter1; //wire control parameter1
1570 priv->PHYRegDef[RF90_PATH_D].rfHSSIPara1 = rFPGA0_XD_HSSIParameter1; //wire control parameter1
1572 // Tranceiver A~D HSSI Parameter-2
1573 priv->PHYRegDef[RF90_PATH_A].rfHSSIPara2 = rFPGA0_XA_HSSIParameter2; //wire control parameter2
1574 priv->PHYRegDef[RF90_PATH_B].rfHSSIPara2 = rFPGA0_XB_HSSIParameter2; //wire control parameter2
1575 priv->PHYRegDef[RF90_PATH_C].rfHSSIPara2 = rFPGA0_XC_HSSIParameter2; //wire control parameter2
1576 priv->PHYRegDef[RF90_PATH_D].rfHSSIPara2 = rFPGA0_XD_HSSIParameter2; //wire control parameter1
1578 // RF switch Control
1579 priv->PHYRegDef[RF90_PATH_A].rfSwitchControl = rFPGA0_XAB_SwitchControl; //TR/Ant switch control
1580 priv->PHYRegDef[RF90_PATH_B].rfSwitchControl = rFPGA0_XAB_SwitchControl;
1581 priv->PHYRegDef[RF90_PATH_C].rfSwitchControl = rFPGA0_XCD_SwitchControl;
1582 priv->PHYRegDef[RF90_PATH_D].rfSwitchControl = rFPGA0_XCD_SwitchControl;
1585 priv->PHYRegDef[RF90_PATH_A].rfAGCControl1 = rOFDM0_XAAGCCore1;
1586 priv->PHYRegDef[RF90_PATH_B].rfAGCControl1 = rOFDM0_XBAGCCore1;
1587 priv->PHYRegDef[RF90_PATH_C].rfAGCControl1 = rOFDM0_XCAGCCore1;
1588 priv->PHYRegDef[RF90_PATH_D].rfAGCControl1 = rOFDM0_XDAGCCore1;
1591 priv->PHYRegDef[RF90_PATH_A].rfAGCControl2 = rOFDM0_XAAGCCore2;
1592 priv->PHYRegDef[RF90_PATH_B].rfAGCControl2 = rOFDM0_XBAGCCore2;
1593 priv->PHYRegDef[RF90_PATH_C].rfAGCControl2 = rOFDM0_XCAGCCore2;
1594 priv->PHYRegDef[RF90_PATH_D].rfAGCControl2 = rOFDM0_XDAGCCore2;
1597 priv->PHYRegDef[RF90_PATH_A].rfRxIQImbalance = rOFDM0_XARxIQImbalance;
1598 priv->PHYRegDef[RF90_PATH_B].rfRxIQImbalance = rOFDM0_XBRxIQImbalance;
1599 priv->PHYRegDef[RF90_PATH_C].rfRxIQImbalance = rOFDM0_XCRxIQImbalance;
1600 priv->PHYRegDef[RF90_PATH_D].rfRxIQImbalance = rOFDM0_XDRxIQImbalance;
1603 priv->PHYRegDef[RF90_PATH_A].rfRxAFE = rOFDM0_XARxAFE;
1604 priv->PHYRegDef[RF90_PATH_B].rfRxAFE = rOFDM0_XBRxAFE;
1605 priv->PHYRegDef[RF90_PATH_C].rfRxAFE = rOFDM0_XCRxAFE;
1606 priv->PHYRegDef[RF90_PATH_D].rfRxAFE = rOFDM0_XDRxAFE;
1609 priv->PHYRegDef[RF90_PATH_A].rfTxIQImbalance = rOFDM0_XATxIQImbalance;
1610 priv->PHYRegDef[RF90_PATH_B].rfTxIQImbalance = rOFDM0_XBTxIQImbalance;
1611 priv->PHYRegDef[RF90_PATH_C].rfTxIQImbalance = rOFDM0_XCTxIQImbalance;
1612 priv->PHYRegDef[RF90_PATH_D].rfTxIQImbalance = rOFDM0_XDTxIQImbalance;
1615 priv->PHYRegDef[RF90_PATH_A].rfTxAFE = rOFDM0_XATxAFE;
1616 priv->PHYRegDef[RF90_PATH_B].rfTxAFE = rOFDM0_XBTxAFE;
1617 priv->PHYRegDef[RF90_PATH_C].rfTxAFE = rOFDM0_XCTxAFE;
1618 priv->PHYRegDef[RF90_PATH_D].rfTxAFE = rOFDM0_XDTxAFE;
1620 // Tranceiver LSSI Readback SI mode
1621 priv->PHYRegDef[RF90_PATH_A].rfLSSIReadBack = rFPGA0_XA_LSSIReadBack;
1622 priv->PHYRegDef[RF90_PATH_B].rfLSSIReadBack = rFPGA0_XB_LSSIReadBack;
1623 priv->PHYRegDef[RF90_PATH_C].rfLSSIReadBack = rFPGA0_XC_LSSIReadBack;
1624 priv->PHYRegDef[RF90_PATH_D].rfLSSIReadBack = rFPGA0_XD_LSSIReadBack;
1626 // Tranceiver LSSI Readback PI mode
1627 priv->PHYRegDef[RF90_PATH_A].rfLSSIReadBackPi = TransceiverA_HSPI_Readback;
1628 priv->PHYRegDef[RF90_PATH_B].rfLSSIReadBackPi = TransceiverB_HSPI_Readback;
1629 //pHalData->PHYRegDef[RF90_PATH_C].rfLSSIReadBackPi = rFPGA0_XC_LSSIReadBack;
1630 //pHalData->PHYRegDef[RF90_PATH_D].rfLSSIReadBackPi = rFPGA0_XD_LSSIReadBack;
1636 // Description: Change RF power state.
1638 // Assumption: This function must be executed in re-schdulable context,
1639 // ie. PASSIVE_LEVEL.
1641 // 050823, by rcnjko.
1642 //not understand it seem's use in init
1643 //SetHwReg8192SUsb--->HalFunc.SetHwRegHandler
1644 bool PHY_SetRFPowerState(struct net_device* dev, RT_RF_POWER_STATE eRFPowerState)
1646 struct r8192_priv *priv = ieee80211_priv(dev);
1647 bool bResult = FALSE;
1649 RT_TRACE(COMP_RF, "---------> PHY_SetRFPowerState(): eRFPowerState(%d)\n", eRFPowerState);
1651 if(eRFPowerState == priv->ieee80211->eRFPowerState)
1653 RT_TRACE(COMP_RF, "<--------- PHY_SetRFPowerState(): discard the request for eRFPowerState(%d) is the same.\n", eRFPowerState);
1657 bResult = phy_SetRFPowerState8192SU(dev, eRFPowerState);
1659 RT_TRACE(COMP_RF, "<--------- PHY_SetRFPowerState(): bResult(%d)\n", bResult);
1665 static bool phy_SetRFPowerState8192SU(struct net_device* dev,RT_RF_POWER_STATE eRFPowerState)
1667 struct r8192_priv *priv = ieee80211_priv(dev);
1668 bool bResult = TRUE;
1673 if(priv->SetRFPowerStateInProgress == TRUE)
1676 priv->SetRFPowerStateInProgress = TRUE;
1678 switch(priv->rf_chip )
1681 switch( eRFPowerState )
1684 write_nic_dword(dev, WFM5, FW_BB_RESET_ENABLE);
1685 write_nic_word(dev, CMDR, 0x37FC);
1686 write_nic_byte(dev, PHY_CCA, 0x3);
1687 write_nic_byte(dev, TXPAUSE, 0x00);
1688 write_nic_byte(dev, SPS1_CTRL, 0x64);
1692 // In current solution, RFSleep=RFOff in order to save power under 802.11 power save.
1693 // By Bruce, 2008-01-16.
1697 if (priv->ieee80211->eRFPowerState == eRfSleep || priv->ieee80211->eRFPowerState == eRfOff)
1700 // Make sure BusyQueue is empty befor turn off RFE pwoer.
1701 for(QueueID = 0, i = 0; QueueID < MAX_TX_QUEUE; )
1703 if(RTIsListEmpty(&Adapter->TcbBusyQueue[QueueID]))
1710 RT_TRACE(COMP_POWER, "eRf Off/Sleep: %d times TcbBusyQueue[%d] !=0 before doze!\n", (i+1), QueueID);
1715 if(i >= MAX_DOZE_WAITING_TIMES_9x)
1717 RT_TRACE(COMP_POWER, "\n\n\n SetZebraRFPowerState8185B(): eRfOff: %d times TcbBusyQueue[%d] != 0 !!!\n\n\n", MAX_DOZE_WAITING_TIMES_9x, QueueID);
1723 //RF Off/Sleep sequence. Designed/tested from SD4 Scott, SD1 Grent and Jonbon.
1724 // Added by Bruce, 2008-11-22.
1726 //==================================================================
1727 // (0) Disable FW BB reset checking
1728 write_nic_dword(dev, WFM5, FW_BB_RESET_DISABLE);
1730 // (1) Switching Power Supply Register : Disable LD12 & SW12 (for IT)
1731 u1bTmp = read_nic_byte(dev, LDOV12D_CTRL);
1733 write_nic_byte(dev, LDOV12D_CTRL, u1bTmp);
1735 write_nic_byte(dev, SPS1_CTRL, 0x0);
1736 write_nic_byte(dev, TXPAUSE, 0xFF);
1738 // (2) MAC Tx/Rx enable, BB enable, CCK/OFDM enable
1739 write_nic_word(dev, CMDR, 0x77FC);
1740 write_nic_byte(dev, PHY_CCA, 0x0);
1743 write_nic_word(dev, CMDR, 0x37FC);
1746 write_nic_word(dev, CMDR, 0x77FC);
1749 // (3) Reset BB TRX blocks
1750 write_nic_word(dev, CMDR, 0x57FC);
1755 //RT_ASSERT(FALSE, ("phy_SetRFPowerState8192SU(): unknow state to set: 0x%X!!!\n", eRFPowerState));
1761 priv->ieee80211->eRFPowerState = eRFPowerState;
1765 // Update current RF state variable.
1766 priv->ieee80211->eRFPowerState = eRFPowerState;
1768 switch(priv->rf_chip )
1771 switch(priv->ieee80211->eRFPowerState)
1775 //If Rf off reason is from IPS, Led should blink with no link, by Maddest 071015
1777 if(pMgntInfo->RfOffReason==RF_CHANGE_BY_IPS )
1779 dev->HalFunc.LedControlHandler(dev,LED_CTL_NO_LINK);
1783 // Turn off LED if RF is not ON.
1784 dev->HalFunc.LedControlHandler(dev, LED_CTL_POWER_OFF);
1789 // Turn on RF we are still linked, which might happen when
1790 // we quickly turn off and on HW RF. 2006.05.12, by rcnjko.
1791 if( pMgntInfo->bMediaConnect == TRUE )
1793 dev->HalFunc.LedControlHandler(dev, LED_CTL_LINK);
1797 // Turn off LED if RF is not ON.
1798 dev->HalFunc.LedControlHandler(dev, LED_CTL_NO_LINK);
1810 RT_TRACE(COMP_RF, "phy_SetRFPowerState8192SU(): Unknown RF type\n");
1815 priv->SetRFPowerStateInProgress = FALSE;
1820 /*-----------------------------------------------------------------------------
1821 * Function: GetTxPowerLevel8190()
1823 * Overview: This function is export to "common" moudule
1825 * Input: PADAPTER Adapter
1826 * psByte Power Level
1832 *---------------------------------------------------------------------------*/
1835 PHY_GetTxPowerLevel8192S(
1836 struct net_device* dev,
1840 struct r8192_priv *priv = ieee80211_priv(dev);
1844 // Because the Tx power indexes are different, we report the maximum of them to
1845 // meet the CCX TPC request. By Bruce, 2008-01-31.
1849 TxPwrLevel = priv->CurrentCckTxPwrIdx;
1850 TxPwrDbm = phy_TxPwrIdxToDbm(dev, WIRELESS_MODE_B, TxPwrLevel);
1853 TxPwrLevel = priv->CurrentOfdm24GTxPwrIdx + priv->LegacyHTTxPowerDiff;
1855 // Compare with Legacy OFDM Tx power.
1856 if(phy_TxPwrIdxToDbm(dev, WIRELESS_MODE_G, TxPwrLevel) > TxPwrDbm)
1857 TxPwrDbm = phy_TxPwrIdxToDbm(dev, WIRELESS_MODE_G, TxPwrLevel);
1860 TxPwrLevel = priv->CurrentOfdm24GTxPwrIdx;
1862 // Compare with HT OFDM Tx power.
1863 if(phy_TxPwrIdxToDbm(dev, WIRELESS_MODE_N_24G, TxPwrLevel) > TxPwrDbm)
1864 TxPwrDbm = phy_TxPwrIdxToDbm(dev, WIRELESS_MODE_N_24G, TxPwrLevel);
1866 *powerlevel = TxPwrDbm;
1869 /*-----------------------------------------------------------------------------
1870 * Function: SetTxPowerLevel8190()
1872 * Overview: This function is export to "HalCommon" moudule
1874 * Input: PADAPTER Adapter
1880 * 2008/11/04 MHC We remove EEPROM_93C56.
1881 * We need to move CCX relative code to independet file.
1882 * 2009/01/21 MHC Support new EEPROM format from SD3 requirement.
1883 *---------------------------------------------------------------------------*/
1884 void PHY_SetTxPowerLevel8192S(struct net_device* dev, u8 channel)
1886 struct r8192_priv *priv = ieee80211_priv(dev);
1887 //HAL_DATA_TYPE *pHalData = GET_HAL_DATA(dev);
1888 u8 powerlevel = (u8)EEPROM_Default_TxPower, powerlevelOFDM24G = 0x10;
1889 s8 ant_pwr_diff = 0;
1891 u8 index = (channel -1);
1892 // 2009/01/22 MH Add for new EEPROM format from SD3
1893 u8 pwrdiff[2] = {0};
1894 u8 ht20pwr[2] = {0}, ht40pwr[2] = {0};
1895 u8 rfpath = 0, rfpathnum = 2;
1897 if(priv->bTXPowerDataReadFromEEPORM == FALSE)
1901 // Read predefined TX power index in EEPROM
1903 // if(priv->epromtype == EPROM_93c46)
1906 // Mainly we use RF-A Tx Power to write the Tx Power registers, but the RF-B Tx
1907 // Power must be calculated by the antenna diff.
1908 // So we have to rewrite Antenna gain offset register here.
1909 // Please refer to BB register 0x80c
1911 // 2. For OFDM 1T or 2T
1915 powerlevel = priv->RfTxPwrLevelCck[0][index];
1917 if (priv->rf_type == RF_1T2R || priv->rf_type == RF_1T1R)
1919 // Read HT 40 OFDM TX power
1920 powerlevelOFDM24G = priv->RfTxPwrLevelOfdm1T[0][index];
1921 // RF B HT OFDM pwr-RFA HT OFDM pwr
1922 // Only one RF we need not to decide B <-> A pwr diff
1924 // Legacy<->HT pwr diff, we only care about path A.
1926 // We only assume 1T as RF path A
1928 ht20pwr[0] = ht40pwr[0] = priv->RfTxPwrLevelOfdm1T[0][index];
1930 else if (priv->rf_type == RF_2T2R)
1932 // Read HT 40 OFDM TX power
1933 powerlevelOFDM24G = priv->RfTxPwrLevelOfdm2T[0][index];
1934 // RF B HT OFDM pwr-RFA HT OFDM pwr
1935 ant_pwr_diff = priv->RfTxPwrLevelOfdm2T[1][index] -
1936 priv->RfTxPwrLevelOfdm2T[0][index];
1937 // RF B (HT OFDM pwr+legacy-ht-diff) -(RFA HT OFDM pwr+legacy-ht-diff)
1938 // We can not handle Path B&A HT/Legacy pwr diff for 92S now.
1940 //RTPRINT(FPHY, PHY_TXPWR, ("CH-%d HT40 A/B Pwr index = %x/%x(%d/%d)\n",
1941 //channel, priv->RfTxPwrLevelOfdm2T[0][index],
1942 //priv->RfTxPwrLevelOfdm2T[1][index],
1943 //priv->RfTxPwrLevelOfdm2T[0][index],
1944 //priv->RfTxPwrLevelOfdm2T[1][index]));
1946 ht20pwr[0] = ht40pwr[0] = priv->RfTxPwrLevelOfdm2T[0][index];
1947 ht20pwr[1] = ht40pwr[1] = priv->RfTxPwrLevelOfdm2T[1][index];
1951 // 2009/01/21 MH Support new EEPROM format from SD3 requirement
1952 // 2009/02/10 Cosa, Here is only for reg B/C/D to A gain diff.
1954 if (priv->EEPROMVersion == 2) // Defined by SD1 Jong
1956 if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20)
1958 for (rfpath = 0; rfpath < rfpathnum; rfpath++)
1960 // HT 20<->40 pwr diff
1961 pwrdiff[rfpath] = priv->TxPwrHt20Diff[rfpath][index];
1963 // Calculate Antenna pwr diff
1964 if (pwrdiff[rfpath] < 8) // 0~+7
1966 ht20pwr[rfpath] += pwrdiff[rfpath];
1968 else // index8-15=-8~-1
1970 ht20pwr[rfpath] -= (15-pwrdiff[rfpath]);
1974 // RF B HT OFDM pwr-RFA HT OFDM pwr
1975 if (priv->rf_type == RF_2T2R)
1976 ant_pwr_diff = ht20pwr[1] - ht20pwr[0];
1978 //RTPRINT(FPHY, PHY_TXPWR,
1979 //("HT20 to HT40 pwrdiff[A/B]=%d/%d, ant_pwr_diff=%d(B-A=%d-%d)\n",
1980 //pwrdiff[0], pwrdiff[1], ant_pwr_diff, ht20pwr[1], ht20pwr[0]));
1983 // Band Edge scheme is enabled for FCC mode
1984 if (priv->TxPwrbandEdgeFlag == 1/* && pHalData->ChannelPlan == 0*/)
1986 for (rfpath = 0; rfpath < rfpathnum; rfpath++)
1988 pwrdiff[rfpath] = 0;
1989 if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40)
1992 pwrdiff[rfpath] = priv->TxPwrbandEdgeHt40[rfpath][0];
1993 else if (channel >= 9)
1994 pwrdiff[rfpath] = priv->TxPwrbandEdgeHt40[rfpath][1];
1996 pwrdiff[rfpath] = 0;
1998 ht40pwr[rfpath] -= pwrdiff[rfpath];
2000 else if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20)
2003 pwrdiff[rfpath] = priv->TxPwrbandEdgeHt20[rfpath][0];
2004 else if (channel >= 11)
2005 pwrdiff[rfpath] = priv->TxPwrbandEdgeHt20[rfpath][1];
2007 pwrdiff[rfpath] = 0;
2009 ht20pwr[rfpath] -= pwrdiff[rfpath];
2013 if (priv->rf_type == RF_2T2R)
2015 // HT 20/40 must decide if they need to minus BD pwr offset
2016 if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40)
2017 ant_pwr_diff = ht40pwr[1] - ht40pwr[0];
2019 ant_pwr_diff = ht20pwr[1] - ht20pwr[0];
2021 if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20)
2023 if (channel <= 1 || channel >= 11)
2025 //RTPRINT(FPHY, PHY_TXPWR,
2026 //("HT20 Band-edge pwrdiff[A/B]=%d/%d, ant_pwr_diff=%d(B-A=%d-%d)\n",
2027 //pwrdiff[0], pwrdiff[1], ant_pwr_diff, ht20pwr[1], ht20pwr[0]));
2032 if (channel <= 3 || channel >= 9)
2034 //RTPRINT(FPHY, PHY_TXPWR,
2035 //("HT40 Band-edge pwrdiff[A/B]=%d/%d, ant_pwr_diff=%d(B-A=%d-%d)\n",
2036 //pwrdiff[0], pwrdiff[1], ant_pwr_diff, ht40pwr[1], ht40pwr[0]));
2042 //Cosa added for protection, the reg rFPGA0_TxGainStage
2043 // range is from 7~-8, index = 0x0~0xf
2044 if(ant_pwr_diff > 7)
2046 if(ant_pwr_diff < -8)
2049 //RTPRINT(FPHY, PHY_TXPWR,
2050 //("CCK/HT Power index = %x/%x(%d/%d), ant_pwr_diff=%d\n",
2051 //powerlevel, powerlevelOFDM24G, powerlevel, powerlevelOFDM24G, ant_pwr_diff));
2053 ant_pwr_diff &= 0xf;
2055 // Antenna TX power difference
2056 priv->AntennaTxPwDiff[2] = 0;// RF-D, don't care
2057 priv->AntennaTxPwDiff[1] = 0;// RF-C, don't care
2058 priv->AntennaTxPwDiff[0] = (u8)(ant_pwr_diff); // RF-B
2060 // Antenna gain offset from B/C/D to A
2061 u4RegValue = ( priv->AntennaTxPwDiff[2]<<8 |
2062 priv->AntennaTxPwDiff[1]<<4 |
2063 priv->AntennaTxPwDiff[0] );
2065 // Notify Tx power difference for B/C/D to A!!!
2066 rtl8192_setBBreg(dev, rFPGA0_TxGainStage, (bXBTxAGC|bXCTxAGC|bXDTxAGC), u4RegValue);
2070 // CCX 2 S31, AP control of client transmit power:
2071 // 1. We shall not exceed Cell Power Limit as possible as we can.
2072 // 2. Tolerance is +/- 5dB.
2073 // 3. 802.11h Power Contraint takes higher precedence over CCX Cell Power Limit.
2076 // 1. 802.11h power contraint
2078 // 071011, by rcnjko.
2080 #ifdef TODO //WB, 11h has not implemented now.
2081 if( priv->ieee80211->iw_mode != IW_MODE_INFRA && priv->bWithCcxCellPwr &&
2082 channel == priv->ieee80211->current_network.channel)// & priv->ieee80211->mAssoc )
2084 u8 CckCellPwrIdx = phy_DbmToTxPwrIdx(dev, WIRELESS_MODE_B, priv->CcxCellPwr);
2085 u8 LegacyOfdmCellPwrIdx = phy_DbmToTxPwrIdx(dev, WIRELESS_MODE_G, priv->CcxCellPwr);
2086 u8 OfdmCellPwrIdx = phy_DbmToTxPwrIdx(dev, WIRELESS_MODE_N_24G, priv->CcxCellPwr);
2088 RT_TRACE(COMP_TXAGC,
2089 ("CCX Cell Limit: %d dbm => CCK Tx power index : %d, Legacy OFDM Tx power index : %d, OFDM Tx power index: %d\n",
2090 priv->CcxCellPwr, CckCellPwrIdx, LegacyOfdmCellPwrIdx, OfdmCellPwrIdx));
2091 RT_TRACE(COMP_TXAGC,
2092 ("EEPROM channel(%d) => CCK Tx power index: %d, Legacy OFDM Tx power index : %d, OFDM Tx power index: %d\n",
2093 channel, powerlevel, powerlevelOFDM24G + priv->LegacyHTTxPowerDiff, powerlevelOFDM24G));
2096 if(powerlevel > CckCellPwrIdx)
2097 powerlevel = CckCellPwrIdx;
2098 // Legacy OFDM, HT OFDM
2099 if(powerlevelOFDM24G + priv->LegacyHTTxPowerDiff > LegacyOfdmCellPwrIdx)
2101 if((OfdmCellPwrIdx - priv->LegacyHTTxPowerDiff) > 0)
2103 powerlevelOFDM24G = OfdmCellPwrIdx - priv->LegacyHTTxPowerDiff;
2107 powerlevelOFDM24G = 0;
2111 RT_TRACE(COMP_TXAGC,
2112 ("Altered CCK Tx power index : %d, Legacy OFDM Tx power index: %d, OFDM Tx power index: %d\n",
2113 powerlevel, powerlevelOFDM24G + priv->LegacyHTTxPowerDiff, powerlevelOFDM24G));
2117 priv->CurrentCckTxPwrIdx = powerlevel;
2118 priv->CurrentOfdm24GTxPwrIdx = powerlevelOFDM24G;
2120 switch(priv->rf_chip)
2123 //PHY_SetRF8225CckTxPower(dev, powerlevel);
2124 //PHY_SetRF8225OfdmTxPower(dev, powerlevelOFDM24G);
2131 PHY_RF6052SetCckTxPower(dev, powerlevel);
2132 PHY_RF6052SetOFDMTxPower(dev, powerlevelOFDM24G);
2145 // Update transmit power level of all channel supported.
2149 // By Bruce, 2008-02-04.
2151 bool PHY_UpdateTxPowerDbm8192S(struct net_device* dev, long powerInDbm)
2153 struct r8192_priv *priv = ieee80211_priv(dev);
2157 // TODO: A mode Tx power.
2158 u8 CckTxPwrIdx = phy_DbmToTxPwrIdx(dev, WIRELESS_MODE_B, powerInDbm);
2159 u8 OfdmTxPwrIdx = phy_DbmToTxPwrIdx(dev, WIRELESS_MODE_N_24G, powerInDbm);
2161 if(OfdmTxPwrIdx - priv->LegacyHTTxPowerDiff > 0)
2162 OfdmTxPwrIdx -= priv->LegacyHTTxPowerDiff;
2166 for(idx = 0; idx < 14; idx++)
2168 priv->TxPowerLevelCCK[idx] = CckTxPwrIdx;
2169 priv->TxPowerLevelCCK_A[idx] = CckTxPwrIdx;
2170 priv->TxPowerLevelCCK_C[idx] = CckTxPwrIdx;
2171 priv->TxPowerLevelOFDM24G[idx] = OfdmTxPwrIdx;
2172 priv->TxPowerLevelOFDM24G_A[idx] = OfdmTxPwrIdx;
2173 priv->TxPowerLevelOFDM24G_C[idx] = OfdmTxPwrIdx;
2175 for (rf_path = 0; rf_path < 2; rf_path++)
2177 priv->RfTxPwrLevelCck[rf_path][idx] = CckTxPwrIdx;
2178 priv->RfTxPwrLevelOfdm1T[rf_path][idx] = \
2179 priv->RfTxPwrLevelOfdm2T[rf_path][idx] = OfdmTxPwrIdx;
2183 PHY_SetTxPowerLevel8192S(dev, priv->chan);
2190 When beacon interval is changed, the values of the
2191 hw registers should be modified.
2192 By tynli, 2008.10.24.
2196 extern void PHY_SetBeaconHwReg( struct net_device* dev, u16 BeaconInterval)
2200 NewBeaconNum = BeaconInterval *32 - 64;
2201 //PlatformEFIOWrite4Byte(Adapter, WFM3+4, NewBeaconNum);
2202 //PlatformEFIOWrite4Byte(Adapter, WFM3, 0xB026007C);
2203 write_nic_dword(dev, WFM3+4, NewBeaconNum);
2204 write_nic_dword(dev, WFM3, 0xB026007C);
2209 // Map dBm into Tx power index according to
2210 // current HW model, for example, RF and PA, and
2211 // current wireless mode.
2212 // By Bruce, 2008-01-29.
2214 static u8 phy_DbmToTxPwrIdx(
2215 struct net_device* dev,
2216 WIRELESS_MODE WirelessMode,
2220 //struct r8192_priv *priv = ieee80211_priv(dev);
2226 // Tested by MP, we found that CCK Index 0 equals to -7dbm, OFDM legacy equals to
2227 // 3dbm, and OFDM HT equals to 0dbm repectively.
2229 // The mapping may be different by different NICs. Do not use this formula for what needs accurate result.
2230 // By Bruce, 2008-01-29.
2232 switch(WirelessMode)
2234 case WIRELESS_MODE_B:
2238 case WIRELESS_MODE_G:
2239 case WIRELESS_MODE_N_24G:
2246 if((PowerInDbm - Offset) > 0)
2248 TxPwrIdx = (u8)((PowerInDbm - Offset) * 2);
2255 // Tx Power Index is too large.
2256 if(TxPwrIdx > MAX_TXPWR_IDX_NMODE_92S)
2257 TxPwrIdx = MAX_TXPWR_IDX_NMODE_92S;
2263 // Map Tx power index into dBm according to
2264 // current HW model, for example, RF and PA, and
2265 // current wireless mode.
2266 // By Bruce, 2008-01-29.
2268 static long phy_TxPwrIdxToDbm(
2269 struct net_device* dev,
2270 WIRELESS_MODE WirelessMode,
2274 //struct r8192_priv *priv = ieee80211_priv(dev);
2279 // Tested by MP, we found that CCK Index 0 equals to -7dbm, OFDM legacy equals to
2280 // 3dbm, and OFDM HT equals to 0dbm repectively.
2282 // The mapping may be different by different NICs. Do not use this formula for what needs accurate result.
2283 // By Bruce, 2008-01-29.
2285 switch(WirelessMode)
2287 case WIRELESS_MODE_B:
2291 case WIRELESS_MODE_G:
2292 case WIRELESS_MODE_N_24G:
2299 PwrOutDbm = TxPwrIdx / 2 + Offset; // Discard the decimal part.
2306 PHY_ScanOperationBackup8192S(
2307 IN PADAPTER Adapter,
2312 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
2313 PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
2315 u1Byte initial_gain;
2321 if(!Adapter->bDriverStopped)
2325 case SCAN_OPT_BACKUP:
2327 // <Roger_Notes> We halt FW DIG and disable high ppower both two DMs here
2328 // and resume both two DMs while scan complete.
2331 Adapter->HalFunc.SetFwCmdHandler(Adapter, FW_CMD_PAUSE_DM_BY_SCAN);
2334 case SCAN_OPT_RESTORE:
2336 // <Roger_Notes> We resume DIG and enable high power both two DMs here and
2337 // recover earlier DIG settings.
2340 Adapter->HalFunc.SetFwCmdHandler(Adapter, FW_CMD_RESUME_DM_BY_SCAN);
2344 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Unknown Scan Backup Operation. \n"));
2352 void PHY_InitialGain8192S(struct net_device* dev,u8 Operation )
2355 //struct r8192_priv *priv = ieee80211_priv(dev);
2360 /*-----------------------------------------------------------------------------
2361 * Function: SetBWModeCallback8190Pci()
2363 * Overview: Timer callback function for SetSetBWMode
2365 * Input: PRT_TIMER pTimer
2371 * Note: (1) We do not take j mode into consideration now
2372 * (2) Will two workitem of "switch channel" and "switch channel bandwidth" run
2374 *---------------------------------------------------------------------------*/
2375 // use in phy only (in win it's timer)
2376 void PHY_SetBWModeCallback8192S(struct net_device *dev)
2378 struct r8192_priv *priv = ieee80211_priv(dev);
2383 // Added it for 20/40 mhz switch time evaluation by guangan 070531
2385 //u8Byte BeginTime, EndTime;
2388 RT_TRACE(COMP_SWBW, "==>SetBWModeCallback8190Pci() Switch to %s bandwidth\n", \
2389 priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz");
2391 if(priv->rf_chip == RF_PSEUDO_11N)
2393 priv->SetBWModeInProgress= FALSE;
2400 // Added it for 20/40 mhz switch time evaluation by guangan 070531
2401 //NowL = read_nic_dword(dev, TSFR);
2402 //NowH = read_nic_dword(dev, TSFR+4);
2403 //BeginTime = ((u8Byte)NowH << 32) + NowL;
2406 //3//<1>Set MAC register
2408 regBwOpMode = read_nic_byte(dev, BW_OPMODE);
2409 regRRSR_RSC = read_nic_byte(dev, RRSR+2);
2411 switch(priv->CurrentChannelBW)
2413 case HT_CHANNEL_WIDTH_20:
2414 //if(priv->card_8192_version >= VERSION_8192S_BCUT)
2415 // write_nic_byte(dev, rFPGA0_AnalogParameter2, 0x58);
2417 regBwOpMode |= BW_OPMODE_20MHZ;
2418 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
2419 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
2422 case HT_CHANNEL_WIDTH_20_40:
2423 //if(priv->card_8192_version >= VERSION_8192S_BCUT)
2424 // write_nic_byte(dev, rFPGA0_AnalogParameter2, 0x18);
2426 regBwOpMode &= ~BW_OPMODE_20MHZ;
2427 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
2428 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
2429 regRRSR_RSC = (regRRSR_RSC&0x90) |(priv->nCur40MhzPrimeSC<<5);
2430 write_nic_byte(dev, RRSR+2, regRRSR_RSC);
2434 RT_TRACE(COMP_DBG, "SetBWModeCallback8190Pci():\
2435 unknown Bandwidth: %#X\n",priv->CurrentChannelBW);
2440 //3//<2>Set PHY related register
2442 switch(priv->CurrentChannelBW)
2445 case HT_CHANNEL_WIDTH_20:
2446 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x0);
2447 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x0);
2449 // Correct the tx power for CCK rate in 40M. Suggest by YN, 20071207
2450 // It is set in Tx descriptor for 8192x series
2451 //write_nic_dword(dev, rCCK0_TxFilter1, 0x1a1b0000);
2452 //write_nic_dword(dev, rCCK0_TxFilter2, 0x090e1317);
2453 //write_nic_dword(dev, rCCK0_DebugPort, 0x00000204);
2455 if (priv->card_8192_version >= VERSION_8192S_BCUT)
2456 write_nic_byte(dev, rFPGA0_AnalogParameter2, 0x58);
2462 case HT_CHANNEL_WIDTH_20_40:
2463 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x1);
2464 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x1);
2466 // Correct the tx power for CCK rate in 40M. Suggest by YN, 20071207
2467 //write_nic_dword(dev, rCCK0_TxFilter1, 0x35360000);
2468 //write_nic_dword(dev, rCCK0_TxFilter2, 0x121c252e);
2469 //write_nic_dword(dev, rCCK0_DebugPort, 0x00000409);
2471 // Set Control channel to upper or lower. These settings are required only for 40MHz
2472 rtl8192_setBBreg(dev, rCCK0_System, bCCKSideBand, (priv->nCur40MhzPrimeSC>>1));
2473 rtl8192_setBBreg(dev, rOFDM1_LSTF, 0xC00, priv->nCur40MhzPrimeSC);
2475 //rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00300000, 3);
2476 if (priv->card_8192_version >= VERSION_8192S_BCUT)
2477 write_nic_byte(dev, rFPGA0_AnalogParameter2, 0x18);
2482 RT_TRACE(COMP_DBG, "SetBWModeCallback8190Pci(): unknown Bandwidth: %#X\n"\
2483 ,priv->CurrentChannelBW);
2487 //Skip over setting of J-mode in BB register here. Default value is "None J mode". Emily 20070315
2489 // Added it for 20/40 mhz switch time evaluation by guangan 070531
2490 //NowL = read_nic_dword(dev, TSFR);
2491 //NowH = read_nic_dword(dev, TSFR+4);
2492 //EndTime = ((u8Byte)NowH << 32) + NowL;
2493 //RT_TRACE(COMP_SCAN, DBG_LOUD, ("SetBWModeCallback8190Pci: time of SetBWMode = %I64d us!\n", (EndTime - BeginTime)));
2495 //3<3>Set RF related register
2496 switch( priv->rf_chip )
2499 //PHY_SetRF8225Bandwidth(dev, priv->CurrentChannelBW);
2503 // Please implement this function in Hal8190PciPhy8256.c
2504 //PHY_SetRF8256Bandwidth(dev, priv->CurrentChannelBW);
2508 // Please implement this function in Hal8190PciPhy8258.c
2509 // PHY_SetRF8258Bandwidth();
2517 PHY_RF6052SetBandwidth(dev, priv->CurrentChannelBW);
2520 printk("Unknown rf_chip: %d\n", priv->rf_chip);
2524 priv->SetBWModeInProgress= FALSE;
2526 RT_TRACE(COMP_SWBW, "<==SetBWModeCallback8190Pci() \n" );
2530 /*-----------------------------------------------------------------------------
2531 * Function: SetBWMode8190Pci()
2533 * Overview: This function is export to "HalCommon" moudule
2535 * Input: PADAPTER Adapter
2536 * HT_CHANNEL_WIDTH Bandwidth //20M or 40M
2542 * Note: We do not take j mode into consideration now
2543 *---------------------------------------------------------------------------*/
2544 //extern void PHY_SetBWMode8192S( struct net_device* dev,
2545 // HT_CHANNEL_WIDTH Bandwidth, // 20M or 40M
2546 // HT_EXTCHNL_OFFSET Offset // Upper, Lower, or Don't care
2547 void rtl8192_SetBWMode(struct net_device *dev, HT_CHANNEL_WIDTH Bandwidth, HT_EXTCHNL_OFFSET Offset)
2549 struct r8192_priv *priv = ieee80211_priv(dev);
2550 HT_CHANNEL_WIDTH tmpBW = priv->CurrentChannelBW;
2553 // Modified it for 20/40 mhz switch by guangan 070531
2557 //if(priv->SwChnlInProgress)
2558 // if(pMgntInfo->bScanInProgress)
2560 // RT_TRACE(COMP_SCAN, DBG_LOUD, ("SetBWMode8190Pci() %s Exit because bScanInProgress!\n",
2561 // Bandwidth == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz"));
2565 // if(priv->SetBWModeInProgress)
2567 // // Modified it for 20/40 mhz switch by guangan 070531
2568 // RT_TRACE(COMP_SCAN, DBG_LOUD, ("SetBWMode8190Pci() %s cancel last timer because SetBWModeInProgress!\n",
2569 // Bandwidth == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz"));
2570 // PlatformCancelTimer(dev, &priv->SetBWModeTimer);
2574 if(priv->SetBWModeInProgress)
2577 priv->SetBWModeInProgress= TRUE;
2579 priv->CurrentChannelBW = Bandwidth;
2581 if(Offset==HT_EXTCHNL_OFFSET_LOWER)
2582 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_UPPER;
2583 else if(Offset==HT_EXTCHNL_OFFSET_UPPER)
2584 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_LOWER;
2586 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
2588 if((priv->up) )// && !(RT_CANNOT_IO(Adapter) && Adapter->bInSetPower) )
2590 SetBWModeCallback8192SUsbWorkItem(dev);
2594 RT_TRACE(COMP_SCAN, "PHY_SetBWMode8192S() SetBWModeInProgress FALSE driver sleep or unload\n");
2595 priv->SetBWModeInProgress= FALSE;
2596 priv->CurrentChannelBW = tmpBW;
2600 // use in phy only (in win it's timer)
2601 void PHY_SwChnlCallback8192S(struct net_device *dev)
2604 struct r8192_priv *priv = ieee80211_priv(dev);
2608 RT_TRACE(COMP_CH, "==>SwChnlCallback8190Pci(), switch to channel %d\n", priv->chan);
2613 if(priv->rf_chip == RF_PSEUDO_11N)
2615 priv->SwChnlInProgress=FALSE;
2616 return; //return immediately if it is peudo-phy
2620 if(!priv->SwChnlInProgress)
2623 //if(!phy_SwChnlStepByStep(dev, priv->CurrentChannel, &priv->SwChnlStage, &priv->SwChnlStep, &delay))
2624 if(!phy_SwChnlStepByStep(dev, priv->chan, &priv->SwChnlStage, &priv->SwChnlStep, &delay))
2629 //PlatformSetTimer(dev, &priv->SwChnlTimer, delay);
2630 //mod_timer(&priv->SwChnlTimer, jiffies + MSECS(delay));
2631 //==>PHY_SwChnlCallback8192S(dev); for 92se
2632 //==>SwChnlCallback8192SUsb(dev) for 92su
2639 priv->SwChnlInProgress=FALSE;
2645 // Call after initialization
2646 //extern void PHY_SwChnl8192S(struct net_device* dev, u8 channel)
2647 u8 rtl8192_phy_SwChnl(struct net_device* dev, u8 channel)
2649 struct r8192_priv *priv = ieee80211_priv(dev);
2650 //u8 tmpchannel =channel;
2651 //bool bResult = false;
2656 if(priv->SwChnlInProgress)
2659 if(priv->SetBWModeInProgress)
2662 //--------------------------------------------
2663 switch(priv->ieee80211->mode)
2665 case WIRELESS_MODE_A:
2666 case WIRELESS_MODE_N_5G:
2668 RT_TRACE(COMP_ERR, "WIRELESS_MODE_A but channel<=14");
2673 case WIRELESS_MODE_B:
2675 RT_TRACE(COMP_ERR, "WIRELESS_MODE_B but channel>14");
2680 case WIRELESS_MODE_G:
2681 case WIRELESS_MODE_N_24G:
2683 RT_TRACE(COMP_ERR, "WIRELESS_MODE_G but channel>14");
2689 ;//RT_TRACE(COMP_ERR, "Invalid WirelessMode(%#x)!!\n", priv->ieee80211->mode);
2692 //--------------------------------------------
2694 priv->SwChnlInProgress = TRUE;
2700 priv->SwChnlStage=0;
2703 if((priv->up))// && !(RT_CANNOT_IO(Adapter) && Adapter->bInSetPower))
2705 SwChnlCallback8192SUsbWorkItem(dev);
2709 RT_TRACE(COMP_SCAN, "PHY_SwChnl8192S SwChnlInProgress TRUE schdule workitem done\n");
2713 RT_TRACE(COMP_SCAN, "PHY_SwChnl8192S SwChnlInProgress FALSE schdule workitem error\n");
2714 priv->SwChnlInProgress = false;
2715 priv->CurrentChannel = tmpchannel;
2721 RT_TRACE(COMP_SCAN, "PHY_SwChnl8192S SwChnlInProgress FALSE driver sleep or unload\n");
2722 priv->SwChnlInProgress = false;
2723 //priv->CurrentChannel = tmpchannel;
2731 // Switch channel synchronously. Called by SwChnlByDelayHandler.
2733 // Implemented by Bruce, 2008-02-14.
2734 // The following procedure is operted according to SwChanlCallback8190Pci().
2735 // However, this procedure is performed synchronously which should be running under
2739 void PHY_SwChnlPhy8192S( // Only called during initialize
2740 struct net_device* dev,
2744 struct r8192_priv *priv = ieee80211_priv(dev);
2746 RT_TRACE(COMP_SCAN, "==>PHY_SwChnlPhy8192S(), switch to channel %d.\n", priv->chan);
2750 if(RT_CANNOT_IO(dev))
2754 // Channel Switching is in progress.
2755 if(priv->SwChnlInProgress)
2758 //return immediately if it is peudo-phy
2759 if(priv->rf_chip == RF_PSEUDO_11N)
2761 priv->SwChnlInProgress=FALSE;
2765 priv->SwChnlInProgress = TRUE;
2771 priv->SwChnlStage = 0;
2772 priv->SwChnlStep = 0;
2774 phy_FinishSwChnlNow(dev,channel);
2776 priv->SwChnlInProgress = FALSE;
2781 phy_SetSwChnlCmdArray(
2782 SwChnlCmd* CmdTable,
2793 if(CmdTable == NULL)
2795 //RT_ASSERT(FALSE, ("phy_SetSwChnlCmdArray(): CmdTable cannot be NULL.\n"));
2798 if(CmdTableIdx >= CmdTableSz)
2801 // ("phy_SetSwChnlCmdArray(): Access invalid index, please check size of the table, CmdTableIdx:%d, CmdTableSz:%d\n",
2802 //CmdTableIdx, CmdTableSz));
2806 pCmd = CmdTable + CmdTableIdx;
2807 pCmd->CmdID = CmdID;
2808 pCmd->Para1 = Para1;
2809 pCmd->Para2 = Para2;
2810 pCmd->msDelay = msDelay;
2817 phy_SwChnlStepByStep(
2818 struct net_device* dev,
2825 struct r8192_priv *priv = ieee80211_priv(dev);
2826 //PCHANNEL_ACCESS_SETTING pChnlAccessSetting;
2827 SwChnlCmd PreCommonCmd[MAX_PRECMD_CNT];
2828 u32 PreCommonCmdCnt;
2829 SwChnlCmd PostCommonCmd[MAX_POSTCMD_CNT];
2830 u32 PostCommonCmdCnt;
2831 SwChnlCmd RfDependCmd[MAX_RFDEPENDCMD_CNT];
2833 SwChnlCmd *CurrentCmd = NULL;
2836 //RT_ASSERT((dev != NULL), ("Adapter should not be NULL\n"));
2837 //RT_ASSERT(IsLegalChannel(dev, channel), ("illegal channel: %d\n", channel));
2838 RT_TRACE(COMP_CH, "===========>%s(), channel:%d, stage:%d, step:%d\n", __FUNCTION__, channel, *stage, *step);
2839 //RT_ASSERT((pHalData != NULL), ("pHalData should not be NULL\n"));
2840 if (!IsLegalChannel(priv->ieee80211, channel))
2842 RT_TRACE(COMP_ERR, "=============>set to illegal channel:%d\n", channel);
2843 return true; //return true to tell upper caller function this channel setting is finished! Or it will in while loop.
2846 //pChnlAccessSetting = &Adapter->MgntInfo.Info8185.ChannelAccessSetting;
2847 //RT_ASSERT((pChnlAccessSetting != NULL), ("pChnlAccessSetting should not be NULL\n"));
2849 //for(eRFPath = RF90_PATH_A; eRFPath <priv->NumTotalRFPath; eRFPath++)
2850 //for(eRFPath = 0; eRFPath <priv->NumTotalRFPath; eRFPath++)
2852 // <1> Fill up pre common command.
2853 PreCommonCmdCnt = 0;
2854 phy_SetSwChnlCmdArray(PreCommonCmd, PreCommonCmdCnt++, MAX_PRECMD_CNT,
2855 CmdID_SetTxPowerLevel, 0, 0, 0);
2856 phy_SetSwChnlCmdArray(PreCommonCmd, PreCommonCmdCnt++, MAX_PRECMD_CNT,
2857 CmdID_End, 0, 0, 0);
2859 // <2> Fill up post common command.
2860 PostCommonCmdCnt = 0;
2862 phy_SetSwChnlCmdArray(PostCommonCmd, PostCommonCmdCnt++, MAX_POSTCMD_CNT,
2863 CmdID_End, 0, 0, 0);
2865 // <3> Fill up RF dependent command.
2867 switch( priv->rf_chip )
2870 if (channel < 1 || channel > 14)
2871 RT_TRACE(COMP_ERR, "illegal channel for zebra:%d\n", channel);
2872 //RT_ASSERT((channel >= 1 && channel <= 14), ("illegal channel for Zebra: %d\n", channel));
2873 // 2008/09/04 MH Change channel.
2874 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
2875 CmdID_RF_WriteReg, rRfChannel, channel, 10);
2876 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
2877 CmdID_End, 0, 0, 0);
2881 if (channel < 1 || channel > 14)
2882 RT_TRACE(COMP_ERR, "illegal channel for zebra:%d\n", channel);
2883 // TEST!! This is not the table for 8256!!
2884 //RT_ASSERT((channel >= 1 && channel <= 14), ("illegal channel for Zebra: %d\n", channel));
2885 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
2886 CmdID_RF_WriteReg, rRfChannel, channel, 10);
2887 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
2888 CmdID_End, 0, 0, 0);
2892 if (channel < 1 || channel > 14)
2893 RT_TRACE(COMP_ERR, "illegal channel for zebra:%d\n", channel);
2894 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
2895 CmdID_RF_WriteReg, RF_CHNLBW, channel, 10);
2896 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
2897 CmdID_End, 0, 0, 0);
2904 //RT_ASSERT(FALSE, ("Unknown rf_chip: %d\n", priv->rf_chip));
2914 CurrentCmd=&PreCommonCmd[*step];
2917 CurrentCmd=&RfDependCmd[*step];
2920 CurrentCmd=&PostCommonCmd[*step];
2924 if(CurrentCmd->CmdID==CmdID_End)
2938 switch(CurrentCmd->CmdID)
2940 case CmdID_SetTxPowerLevel:
2941 //if(priv->card_8192_version > VERSION_8190_BD)
2942 PHY_SetTxPowerLevel8192S(dev,channel);
2944 case CmdID_WritePortUlong:
2945 write_nic_dword(dev, CurrentCmd->Para1, CurrentCmd->Para2);
2947 case CmdID_WritePortUshort:
2948 write_nic_word(dev, CurrentCmd->Para1, (u16)CurrentCmd->Para2);
2950 case CmdID_WritePortUchar:
2951 write_nic_byte(dev, CurrentCmd->Para1, (u8)CurrentCmd->Para2);
2953 case CmdID_RF_WriteReg: // Only modify channel for the register now !!!!!
2954 for(eRFPath = 0; eRFPath <priv->NumTotalRFPath; eRFPath++)
2956 // For new T65 RF 0222d register 0x18 bit 0-9 = channel number.
2957 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, CurrentCmd->Para1, 0x1f, (CurrentCmd->Para2));
2958 //printk("====>%x, %x, read_back:%x\n", CurrentCmd->Para2,CurrentCmd->Para1, rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, CurrentCmd->Para1, 0x1f));
2967 //cosa }/*for(Number of RF paths)*/
2969 (*delay)=CurrentCmd->msDelay;
2971 RT_TRACE(COMP_CH, "<===========%s(), channel:%d, stage:%d, step:%d\n", __FUNCTION__, channel, *stage, *step);
2975 //called PHY_SwChnlPhy8192S, SwChnlCallback8192SUsbWorkItem
2978 phy_FinishSwChnlNow( // We should not call this function directly
2979 struct net_device* dev,
2983 struct r8192_priv *priv = ieee80211_priv(dev);
2986 while(!phy_SwChnlStepByStep(dev,channel,&priv->SwChnlStage,&priv->SwChnlStep,&delay))
2996 /*-----------------------------------------------------------------------------
2997 * Function: PHYCheckIsLegalRfPath8190Pci()
2999 * Overview: Check different RF type to execute legal judgement. If RF Path is illegal
3000 * We will return false.
3010 * 11/15/2007 MHC Create Version 0.
3012 *---------------------------------------------------------------------------*/
3013 //called by rtl8192_phy_QueryRFReg, rtl8192_phy_SetRFReg, PHY_SetRFPowerState8192SUsb
3015 //PHY_CheckIsLegalRfPath8192S(
3016 // struct net_device* dev,
3018 u8 rtl8192_phy_CheckIsLegalRFPath(struct net_device* dev, u32 eRFPath)
3020 // struct r8192_priv *priv = ieee80211_priv(dev);
3021 bool rtValue = TRUE;
3023 // NOt check RF Path now.!
3026 } /* PHY_CheckIsLegalRfPath8192S */
3030 /*-----------------------------------------------------------------------------
3031 * Function: PHY_IQCalibrate8192S()
3033 * Overview: After all MAC/PHY/RF is configued. We must execute IQ calibration
3034 * to improve RF EVM!!?
3036 * Input: IN PADAPTER pAdapter
3044 * 10/07/2008 MHC Create. Document from SD3 RFSI Jenyu.
3046 *---------------------------------------------------------------------------*/
3047 //called by InitializeAdapter8192SE
3049 PHY_IQCalibrate( struct net_device* dev)
3051 //struct r8192_priv *priv = ieee80211_priv(dev);
3057 // 1. Check QFN68 or 64 92S (Read from EEPROM)
3062 // For 1T2R IQK only now !!!
3063 for (i = 0; i < 10; i++)
3066 rtl8192_setBBreg(dev, 0xc04, bMaskDWord, 0x00a05430);
3067 //PlatformStallExecution(5);
3069 rtl8192_setBBreg(dev, 0xc08, bMaskDWord, 0x000800e4);
3071 rtl8192_setBBreg(dev, 0xe28, bMaskDWord, 0x80800000);
3073 rtl8192_setBBreg(dev, 0xe40, bMaskDWord, 0x02140148);
3075 rtl8192_setBBreg(dev, 0xe44, bMaskDWord, 0x681604a2);
3077 rtl8192_setBBreg(dev, 0xe4c, bMaskDWord, 0x000028d1);
3079 rtl8192_setBBreg(dev, 0xe60, bMaskDWord, 0x0214014d);
3081 rtl8192_setBBreg(dev, 0xe64, bMaskDWord, 0x281608ba);
3083 rtl8192_setBBreg(dev, 0xe6c, bMaskDWord, 0x000028d1);
3085 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xfb000001);
3087 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xf8000001);
3089 rtl8192_setBBreg(dev, 0xc04, bMaskDWord, 0x00a05433);
3091 rtl8192_setBBreg(dev, 0xc08, bMaskDWord, 0x000000e4);
3093 rtl8192_setBBreg(dev, 0xe28, bMaskDWord, 0x0);
3096 reg = rtl8192_QueryBBReg(dev, 0xeac, bMaskDWord);
3098 // Readback IQK value and rewrite
3099 if (!(reg&(BIT27|BIT28|BIT30|BIT31)))
3101 old_value = (rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord) & 0x3FF);
3103 // Calibrate init gain for A path for TX0
3104 X = (rtl8192_QueryBBReg(dev, 0xe94, bMaskDWord) & 0x03FF0000)>>16;
3105 TXA[RF90_PATH_A] = (X * old_value)/0x100;
3106 reg = rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord);
3107 reg = (reg & 0xFFFFFC00) | (u32)TXA[RF90_PATH_A];
3108 rtl8192_setBBreg(dev, 0xc80, bMaskDWord, reg);
3111 // Calibrate init gain for C path for TX0
3112 Y = ( rtl8192_QueryBBReg(dev, 0xe9C, bMaskDWord) & 0x03FF0000)>>16;
3113 TX0[RF90_PATH_C] = ((Y * old_value)/0x100);
3114 reg = rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord);
3115 reg = (reg & 0xffc0ffff) |((u32) (TX0[RF90_PATH_C]&0x3F)<<16);
3116 rtl8192_setBBreg(dev, 0xc80, bMaskDWord, reg);
3117 reg = rtl8192_QueryBBReg(dev, 0xc94, bMaskDWord);
3118 reg = (reg & 0x0fffffff) |(((Y&0x3c0)>>6)<<28);
3119 rtl8192_setBBreg(dev, 0xc94, bMaskDWord, reg);
3122 // Calibrate RX A and B for RX0
3123 reg = rtl8192_QueryBBReg(dev, 0xc14, bMaskDWord);
3124 X = (rtl8192_QueryBBReg(dev, 0xea4, bMaskDWord) & 0x03FF0000)>>16;
3125 reg = (reg & 0xFFFFFC00) |X;
3126 rtl8192_setBBreg(dev, 0xc14, bMaskDWord, reg);
3127 Y = (rtl8192_QueryBBReg(dev, 0xeac, bMaskDWord) & 0x003F0000)>>16;
3128 reg = (reg & 0xFFFF03FF) |Y<<10;
3129 rtl8192_setBBreg(dev, 0xc14, bMaskDWord, reg);
3131 old_value = (rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord) & 0x3FF);
3133 // Calibrate init gain for A path for TX1 !!!!!!
3134 X = (rtl8192_QueryBBReg(dev, 0xeb4, bMaskDWord) & 0x03FF0000)>>16;
3135 reg = rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord);
3136 TXA[RF90_PATH_A] = (X * old_value) / 0x100;
3137 reg = (reg & 0xFFFFFC00) | TXA[RF90_PATH_A];
3138 rtl8192_setBBreg(dev, 0xc88, bMaskDWord, reg);
3141 // Calibrate init gain for C path for TX1
3142 Y = (rtl8192_QueryBBReg(dev, 0xebc, bMaskDWord)& 0x03FF0000)>>16;
3143 TX0[RF90_PATH_C] = ((Y * old_value)/0x100);
3144 reg = rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord);
3145 reg = (reg & 0xffc0ffff) |( (TX0[RF90_PATH_C]&0x3F)<<16);
3146 rtl8192_setBBreg(dev, 0xc88, bMaskDWord, reg);
3147 reg = rtl8192_QueryBBReg(dev, 0xc9c, bMaskDWord);
3148 reg = (reg & 0x0fffffff) |(((Y&0x3c0)>>6)<<28);
3149 rtl8192_setBBreg(dev, 0xc9c, bMaskDWord, reg);
3152 // Calibrate RX A and B for RX1
3153 reg = rtl8192_QueryBBReg(dev, 0xc1c, bMaskDWord);
3154 X = (rtl8192_QueryBBReg(dev, 0xec4, bMaskDWord) & 0x03FF0000)>>16;
3155 reg = (reg & 0xFFFFFC00) |X;
3156 rtl8192_setBBreg(dev, 0xc1c, bMaskDWord, reg);
3158 Y = (rtl8192_QueryBBReg(dev, 0xecc, bMaskDWord) & 0x003F0000)>>16;
3159 reg = (reg & 0xFFFF03FF) |Y<<10;
3160 rtl8192_setBBreg(dev, 0xc1c, bMaskDWord, reg);
3163 RT_TRACE(COMP_INIT, "PHY_IQCalibrate OK\n");
3171 // 3. QFN64. Not enabled now !!! We must use different gain table for 1T2R.
3177 /*-----------------------------------------------------------------------------
3178 * Function: PHY_IQCalibrateBcut()
3180 * Overview: After all MAC/PHY/RF is configued. We must execute IQ calibration
3181 * to improve RF EVM!!?
3183 * Input: IN PADAPTER pAdapter
3191 * 11/18/2008 MHC Create. Document from SD3 RFSI Jenyu.
3192 * 92S B-cut QFN 68 pin IQ calibration procedure.doc
3194 *---------------------------------------------------------------------------*/
3195 extern void PHY_IQCalibrateBcut(struct net_device* dev)
3197 //struct r8192_priv *priv = ieee80211_priv(dev);
3198 //PMGNT_INFO pMgntInfo = &pAdapter->MgntInfo;
3203 u32 calibrate_set[13] = {0};
3207 // 0. Check QFN68 or 64 92S (Read from EEPROM/EFUSE)
3210 // 1. Save e70~ee0 register setting, and load calibration setting
3213 0xee0[31:0]=0x3fed92fb;
3214 0xedc[31:0] =0x3fed92fb;
3215 0xe70[31:0] =0x3fed92fb;
3216 0xe74[31:0] =0x3fed92fb;
3217 0xe78[31:0] =0x3fed92fb;
3218 0xe7c[31:0]= 0x3fed92fb;
3219 0xe80[31:0]= 0x3fed92fb;
3220 0xe84[31:0]= 0x3fed92fb;
3221 0xe88[31:0]= 0x3fed92fb;
3222 0xe8c[31:0]= 0x3fed92fb;
3223 0xed0[31:0]= 0x3fed92fb;
3224 0xed4[31:0]= 0x3fed92fb;
3225 0xed8[31:0]= 0x3fed92fb;
3227 calibrate_set [0] = 0xee0;
3228 calibrate_set [1] = 0xedc;
3229 calibrate_set [2] = 0xe70;
3230 calibrate_set [3] = 0xe74;
3231 calibrate_set [4] = 0xe78;
3232 calibrate_set [5] = 0xe7c;
3233 calibrate_set [6] = 0xe80;
3234 calibrate_set [7] = 0xe84;
3235 calibrate_set [8] = 0xe88;
3236 calibrate_set [9] = 0xe8c;
3237 calibrate_set [10] = 0xed0;
3238 calibrate_set [11] = 0xed4;
3239 calibrate_set [12] = 0xed8;
3240 //RT_TRACE(COMP_INIT, DBG_LOUD, ("Save e70~ee0 register setting\n"));
3241 for (i = 0; i < 13; i++)
3243 load_value[i] = rtl8192_QueryBBReg(dev, calibrate_set[i], bMaskDWord);
3244 rtl8192_setBBreg(dev, calibrate_set[i], bMaskDWord, 0x3fed92fb);
3248 RfPiEnable = (u8)rtl8192_QueryBBReg(dev, rFPGA0_XA_HSSIParameter1, BIT8);
3253 // For 1T2R IQK only now !!!
3254 for (i = 0; i < 10; i++)
3256 RT_TRACE(COMP_INIT, "IQK -%d\n", i);
3257 //BB switch to PI mode. If default is PI mode, ignoring 2 commands below.
3258 if (!RfPiEnable) //if original is SI mode, then switch to PI mode.
3260 //DbgPrint("IQK Switch to PI mode\n");
3261 rtl8192_setBBreg(dev, 0x820, bMaskDWord, 0x01000100);
3262 rtl8192_setBBreg(dev, 0x828, bMaskDWord, 0x01000100);
3266 // 2. IQ calibration & LO leakage calibration
3267 rtl8192_setBBreg(dev, 0xc04, bMaskDWord, 0x00a05430);
3269 rtl8192_setBBreg(dev, 0xc08, bMaskDWord, 0x000800e4);
3271 rtl8192_setBBreg(dev, 0xe28, bMaskDWord, 0x80800000);
3273 //path-A IQ K and LO K gain setting
3274 rtl8192_setBBreg(dev, 0xe40, bMaskDWord, 0x02140102);
3276 rtl8192_setBBreg(dev, 0xe44, bMaskDWord, 0x681604c2);
3278 //set LO calibration
3279 rtl8192_setBBreg(dev, 0xe4c, bMaskDWord, 0x000028d1);
3281 //path-B IQ K and LO K gain setting
3282 rtl8192_setBBreg(dev, 0xe60, bMaskDWord, 0x02140102);
3284 rtl8192_setBBreg(dev, 0xe64, bMaskDWord, 0x28160d05);
3287 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xfb000000);
3289 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xf8000000);
3296 rtl8192_setBBreg(dev, 0xe6c, bMaskDWord, 0x020028d1);
3299 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xfb000000);
3301 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xf8000000);
3306 rtl8192_setBBreg(dev, 0xc04, bMaskDWord, 0x00a05433);
3308 rtl8192_setBBreg(dev, 0xc08, bMaskDWord, 0x000000e4);
3310 rtl8192_setBBreg(dev, 0xe28, bMaskDWord, 0x0);
3312 if (!RfPiEnable) //if original is SI mode, then switch to PI mode.
3314 //DbgPrint("IQK Switch back to SI mode\n");
3315 rtl8192_setBBreg(dev, 0x820, bMaskDWord, 0x01000000);
3316 rtl8192_setBBreg(dev, 0x828, bMaskDWord, 0x01000000);
3320 reg = rtl8192_QueryBBReg(dev, 0xeac, bMaskDWord);
3322 // 3. check fail bit, and fill BB IQ matrix
3323 // Readback IQK value and rewrite
3324 if (!(reg&(BIT27|BIT28|BIT30|BIT31)))
3326 old_value = (rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord) & 0x3FF);
3328 // Calibrate init gain for A path for TX0
3329 X = (rtl8192_QueryBBReg(dev, 0xe94, bMaskDWord) & 0x03FF0000)>>16;
3330 TXA[RF90_PATH_A] = (X * old_value)/0x100;
3331 reg = rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord);
3332 reg = (reg & 0xFFFFFC00) | (u32)TXA[RF90_PATH_A];
3333 rtl8192_setBBreg(dev, 0xc80, bMaskDWord, reg);
3336 // Calibrate init gain for C path for TX0
3337 Y = ( rtl8192_QueryBBReg(dev, 0xe9C, bMaskDWord) & 0x03FF0000)>>16;
3338 TX0[RF90_PATH_C] = ((Y * old_value)/0x100);
3339 reg = rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord);
3340 reg = (reg & 0xffc0ffff) |((u32) (TX0[RF90_PATH_C]&0x3F)<<16);
3341 rtl8192_setBBreg(dev, 0xc80, bMaskDWord, reg);
3342 reg = rtl8192_QueryBBReg(dev, 0xc94, bMaskDWord);
3343 reg = (reg & 0x0fffffff) |(((Y&0x3c0)>>6)<<28);
3344 rtl8192_setBBreg(dev, 0xc94, bMaskDWord, reg);
3347 // Calibrate RX A and B for RX0
3348 reg = rtl8192_QueryBBReg(dev, 0xc14, bMaskDWord);
3349 X = (rtl8192_QueryBBReg(dev, 0xea4, bMaskDWord) & 0x03FF0000)>>16;
3350 reg = (reg & 0xFFFFFC00) |X;
3351 rtl8192_setBBreg(dev, 0xc14, bMaskDWord, reg);
3352 Y = (rtl8192_QueryBBReg(dev, 0xeac, bMaskDWord) & 0x003F0000)>>16;
3353 reg = (reg & 0xFFFF03FF) |Y<<10;
3354 rtl8192_setBBreg(dev, 0xc14, bMaskDWord, reg);
3356 old_value = (rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord) & 0x3FF);
3358 // Calibrate init gain for A path for TX1 !!!!!!
3359 X = (rtl8192_QueryBBReg(dev, 0xeb4, bMaskDWord) & 0x03FF0000)>>16;
3360 reg = rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord);
3361 TXA[RF90_PATH_A] = (X * old_value) / 0x100;
3362 reg = (reg & 0xFFFFFC00) | TXA[RF90_PATH_A];
3363 rtl8192_setBBreg(dev, 0xc88, bMaskDWord, reg);
3366 // Calibrate init gain for C path for TX1
3367 Y = (rtl8192_QueryBBReg(dev, 0xebc, bMaskDWord)& 0x03FF0000)>>16;
3368 TX0[RF90_PATH_C] = ((Y * old_value)/0x100);
3369 reg = rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord);
3370 reg = (reg & 0xffc0ffff) |( (TX0[RF90_PATH_C]&0x3F)<<16);
3371 rtl8192_setBBreg(dev, 0xc88, bMaskDWord, reg);
3372 reg = rtl8192_QueryBBReg(dev, 0xc9c, bMaskDWord);
3373 reg = (reg & 0x0fffffff) |(((Y&0x3c0)>>6)<<28);
3374 rtl8192_setBBreg(dev, 0xc9c, bMaskDWord, reg);
3377 // Calibrate RX A and B for RX1
3378 reg = rtl8192_QueryBBReg(dev, 0xc1c, bMaskDWord);
3379 X = (rtl8192_QueryBBReg(dev, 0xec4, bMaskDWord) & 0x03FF0000)>>16;
3380 reg = (reg & 0xFFFFFC00) |X;
3381 rtl8192_setBBreg(dev, 0xc1c, bMaskDWord, reg);
3383 Y = (rtl8192_QueryBBReg(dev, 0xecc, bMaskDWord) & 0x003F0000)>>16;
3384 reg = (reg & 0xFFFF03FF) |Y<<10;
3385 rtl8192_setBBreg(dev, 0xc1c, bMaskDWord, reg);
3388 RT_TRACE(COMP_INIT, "PHY_IQCalibrate OK\n");
3395 // 4. Reload e70~ee0 register setting.
3397 //RT_TRACE(COMP_INIT, DBG_LOUD, ("Reload e70~ee0 register setting.\n"));
3398 for (i = 0; i < 13; i++)
3399 rtl8192_setBBreg(dev, calibrate_set[i], bMaskDWord, load_value[i]);
3403 // 3. QFN64. Not enabled now !!! We must use different gain table for 1T2R.
3408 } // PHY_IQCalibrateBcut
3412 // Move from phycfg.c to gen.c to be code independent later
3414 //-------------------------Move to other DIR later----------------------------*/
3415 //#if (DEV_BUS_TYPE == USB_INTERFACE)
3417 // use in phy only (in win it's timer)
3418 void SwChnlCallback8192SUsb(struct net_device *dev)
3421 struct r8192_priv *priv = ieee80211_priv(dev);
3425 RT_TRACE(COMP_SCAN, "==>SwChnlCallback8190Pci(), switch to channel\
3432 if(priv->rf_chip == RF_PSEUDO_11N)
3434 priv->SwChnlInProgress=FALSE;
3435 return; //return immediately if it is peudo-phy
3439 if(!priv->SwChnlInProgress)
3442 if(!phy_SwChnlStepByStep(dev, priv->chan, &priv->SwChnlStage, &priv->SwChnlStep, &delay))
3446 //PlatformSetTimer(dev, &priv->SwChnlTimer, delay);
3454 priv->SwChnlInProgress=FALSE;
3462 // Callback routine of the work item for switch channel.
3464 // use in phy only (in win it's work)
3465 void SwChnlCallback8192SUsbWorkItem(struct net_device *dev )
3467 struct r8192_priv *priv = ieee80211_priv(dev);
3469 RT_TRACE(COMP_TRACE, "==> SwChnlCallback8192SUsbWorkItem()\n");
3471 if(pAdapter->bInSetPower && RT_USB_CANNOT_IO(pAdapter))
3473 RT_TRACE(COMP_SCAN, DBG_LOUD, ("<== SwChnlCallback8192SUsbWorkItem() SwChnlInProgress FALSE driver sleep or unload\n"));
3475 pHalData->SwChnlInProgress = FALSE;
3479 phy_FinishSwChnlNow(dev, priv->chan);
3480 priv->SwChnlInProgress = FALSE;
3482 RT_TRACE(COMP_TRACE, "<== SwChnlCallback8192SUsbWorkItem()\n");
3486 /*-----------------------------------------------------------------------------
3487 * Function: SetBWModeCallback8192SUsb()
3489 * Overview: Timer callback function for SetSetBWMode
3491 * Input: PRT_TIMER pTimer
3497 * Note: (1) We do not take j mode into consideration now
3498 * (2) Will two workitem of "switch channel" and "switch channel bandwidth" run
3500 *---------------------------------------------------------------------------*/
3501 //====>//rtl8192_SetBWMode
3502 // use in phy only (in win it's timer)
3503 void SetBWModeCallback8192SUsb(struct net_device *dev)
3505 struct r8192_priv *priv = ieee80211_priv(dev);
3508 // Added it for 20/40 mhz switch time evaluation by guangan 070531
3510 //u8Byte BeginTime, EndTime;
3513 RT_TRACE(COMP_SCAN, "==>SetBWModeCallback8190Pci() Switch to %s bandwidth\n", \
3514 priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz");
3516 if(priv->rf_chip == RF_PSEUDO_11N)
3518 priv->SetBWModeInProgress= FALSE;
3525 // Added it for 20/40 mhz switch time evaluation by guangan 070531
3526 //NowL = read_nic_dword(dev, TSFR);
3527 //NowH = read_nic_dword(dev, TSFR+4);
3528 //BeginTime = ((u8Byte)NowH << 32) + NowL;
3530 //3<1>Set MAC register
3531 regBwOpMode = read_nic_byte(dev, BW_OPMODE);
3532 regRRSR_RSC = read_nic_byte(dev, RRSR+2);
3534 switch(priv->CurrentChannelBW)
3536 case HT_CHANNEL_WIDTH_20:
3537 regBwOpMode |= BW_OPMODE_20MHZ;
3538 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
3539 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
3542 case HT_CHANNEL_WIDTH_20_40:
3543 regBwOpMode &= ~BW_OPMODE_20MHZ;
3544 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
3545 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
3547 regRRSR_RSC = (regRRSR_RSC&0x90) |(priv->nCur40MhzPrimeSC<<5);
3548 write_nic_byte(dev, RRSR+2, regRRSR_RSC);
3552 RT_TRACE(COMP_DBG, "SetChannelBandwidth8190Pci():\
3553 unknown Bandwidth: %#X\n",priv->CurrentChannelBW);
3557 //3 <2>Set PHY related register
3558 switch(priv->CurrentChannelBW)
3560 case HT_CHANNEL_WIDTH_20:
3561 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x0);
3562 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x0);
3564 if (priv->card_8192_version >= VERSION_8192S_BCUT)
3565 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter2, 0xff, 0x58);
3568 case HT_CHANNEL_WIDTH_20_40:
3569 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x1);
3570 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x1);
3571 rtl8192_setBBreg(dev, rCCK0_System, bCCKSideBand, (priv->nCur40MhzPrimeSC>>1));
3572 rtl8192_setBBreg(dev, rOFDM1_LSTF, 0xC00, priv->nCur40MhzPrimeSC);
3574 // Correct the tx power for CCK rate in 40M. Suggest by YN, 20071207
3575 //PHY_SetBBReg(Adapter, rCCK0_TxFilter1, bMaskDWord, 0x35360000);
3576 //PHY_SetBBReg(Adapter, rCCK0_TxFilter2, bMaskDWord, 0x121c252e);
3577 //PHY_SetBBReg(Adapter, rCCK0_DebugPort, bMaskDWord, 0x00000409);
3578 //PHY_SetBBReg(Adapter, rFPGA0_AnalogParameter1, bADClkPhase, 0);
3580 if (priv->card_8192_version >= VERSION_8192S_BCUT)
3581 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter2, 0xff, 0x18);
3585 RT_TRACE(COMP_DBG, "SetChannelBandwidth8190Pci(): unknown Bandwidth: %#X\n"\
3586 ,priv->CurrentChannelBW);
3590 //Skip over setting of J-mode in BB register here. Default value is "None J mode". Emily 20070315
3592 // Added it for 20/40 mhz switch time evaluation by guangan 070531
3593 //NowL = read_nic_dword(dev, TSFR);
3594 //NowH = read_nic_dword(dev, TSFR+4);
3595 //EndTime = ((u8Byte)NowH << 32) + NowL;
3596 //RT_TRACE(COMP_SCAN, DBG_LOUD, ("SetBWModeCallback8190Pci: time of SetBWMode = %I64d us!\n", (EndTime - BeginTime)));
3599 //3<3>Set RF related register
3600 switch( priv->rf_chip )
3603 PHY_SetRF8225Bandwidth(dev, priv->CurrentChannelBW);
3607 // Please implement this function in Hal8190PciPhy8256.c
3608 //PHY_SetRF8256Bandwidth(dev, priv->CurrentChannelBW);
3612 PHY_RF6052SetBandwidth(dev, priv->CurrentChannelBW);
3616 // Please implement this function in Hal8190PciPhy8258.c
3617 // PHY_SetRF8258Bandwidth();
3625 //RT_ASSERT(FALSE, ("Unknown rf_chip: %d\n", priv->rf_chip));
3629 priv->SetBWModeInProgress= FALSE;
3631 RT_TRACE(COMP_SCAN, "<==SetBWMode8190Pci()" );
3635 // Callback routine of the work item for set bandwidth mode.
3637 // use in phy only (in win it's work)
3638 void SetBWModeCallback8192SUsbWorkItem(struct net_device *dev)
3640 struct r8192_priv *priv = ieee80211_priv(dev);
3643 // Added it for 20/40 mhz switch time evaluation by guangan 070531
3645 //u8Byte BeginTime, EndTime;
3648 RT_TRACE(COMP_SCAN, "==>SetBWModeCallback8192SUsbWorkItem() Switch to %s bandwidth\n", \
3649 priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz");
3651 if(priv->rf_chip == RF_PSEUDO_11N)
3653 priv->SetBWModeInProgress= FALSE;
3660 // Added it for 20/40 mhz switch time evaluation by guangan 070531
3661 //NowL = read_nic_dword(dev, TSFR);
3662 //NowH = read_nic_dword(dev, TSFR+4);
3663 //BeginTime = ((u8Byte)NowH << 32) + NowL;
3665 //3<1>Set MAC register
3666 regBwOpMode = read_nic_byte(dev, BW_OPMODE);
3667 regRRSR_RSC = read_nic_byte(dev, RRSR+2);
3669 switch(priv->CurrentChannelBW)
3671 case HT_CHANNEL_WIDTH_20:
3672 regBwOpMode |= BW_OPMODE_20MHZ;
3673 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
3674 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
3677 case HT_CHANNEL_WIDTH_20_40:
3678 regBwOpMode &= ~BW_OPMODE_20MHZ;
3679 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
3680 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
3681 regRRSR_RSC = (regRRSR_RSC&0x90) |(priv->nCur40MhzPrimeSC<<5);
3682 write_nic_byte(dev, RRSR+2, regRRSR_RSC);
3687 RT_TRACE(COMP_DBG, "SetBWModeCallback8192SUsbWorkItem():\
3688 unknown Bandwidth: %#X\n",priv->CurrentChannelBW);
3692 //3 <2>Set PHY related register
3693 switch(priv->CurrentChannelBW)
3695 case HT_CHANNEL_WIDTH_20:
3696 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x0);
3697 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x0);
3699 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter2, 0xff, 0x58);
3702 case HT_CHANNEL_WIDTH_20_40:
3703 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x1);
3704 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x1);
3706 // Set Control channel to upper or lower. These settings are required only for 40MHz
3707 rtl8192_setBBreg(dev, rCCK0_System, bCCKSideBand, (priv->nCur40MhzPrimeSC>>1));
3708 rtl8192_setBBreg(dev, rOFDM1_LSTF, 0xC00, priv->nCur40MhzPrimeSC);
3710 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter2, 0xff, 0x18);
3716 RT_TRACE(COMP_DBG, "SetBWModeCallback8192SUsbWorkItem(): unknown Bandwidth: %#X\n"\
3717 ,priv->CurrentChannelBW);
3721 //Skip over setting of J-mode in BB register here. Default value is "None J mode". Emily 20070315
3723 //3<3>Set RF related register
3724 switch( priv->rf_chip )
3727 PHY_SetRF8225Bandwidth(dev, priv->CurrentChannelBW);
3731 // Please implement this function in Hal8190PciPhy8256.c
3732 //PHY_SetRF8256Bandwidth(dev, priv->CurrentChannelBW);
3736 PHY_RF6052SetBandwidth(dev, priv->CurrentChannelBW);
3740 // Please implement this function in Hal8190PciPhy8258.c
3741 // PHY_SetRF8258Bandwidth();
3749 //RT_ASSERT(FALSE, ("Unknown rf_chip: %d\n", priv->rf_chip));
3753 priv->SetBWModeInProgress= FALSE;
3755 RT_TRACE(COMP_SCAN, "<==SetBWModeCallback8192SUsbWorkItem()" );
3758 //--------------------------Move to oter DIR later-------------------------------*/
3759 void InitialGain8192S(struct net_device *dev, u8 Operation)
3762 struct r8192_priv *priv = ieee80211_priv(dev);
3767 void InitialGain819xUsb(struct net_device *dev, u8 Operation)
3769 struct r8192_priv *priv = ieee80211_priv(dev);
3771 priv->InitialGainOperateType = Operation;
3775 queue_delayed_work(priv->priv_wq,&priv->initialgain_operate_wq,0);
3779 extern void InitialGainOperateWorkItemCallBack(struct work_struct *work)
3781 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
3782 struct r8192_priv *priv = container_of(dwork,struct r8192_priv,initialgain_operate_wq);
3783 struct net_device *dev = priv->ieee80211->dev;
3784 #define SCAN_RX_INITIAL_GAIN 0x17
3785 #define POWER_DETECTION_TH 0x08
3790 Operation = priv->InitialGainOperateType;
3795 RT_TRACE(COMP_SCAN, "IG_Backup, backup the initial gain.\n");
3796 initial_gain = SCAN_RX_INITIAL_GAIN;//priv->DefaultInitialGain[0];//
3797 BitMask = bMaskByte0;
3798 if(dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
3799 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); // FW DIG OFF
3800 priv->initgain_backup.xaagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XAAGCCore1, BitMask);
3801 priv->initgain_backup.xbagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XBAGCCore1, BitMask);
3802 priv->initgain_backup.xcagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XCAGCCore1, BitMask);
3803 priv->initgain_backup.xdagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XDAGCCore1, BitMask);
3804 BitMask = bMaskByte2;
3805 priv->initgain_backup.cca = (u8)rtl8192_QueryBBReg(dev, rCCK0_CCA, BitMask);
3807 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc50 is %x\n",priv->initgain_backup.xaagccore1);
3808 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc58 is %x\n",priv->initgain_backup.xbagccore1);
3809 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc60 is %x\n",priv->initgain_backup.xcagccore1);
3810 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc68 is %x\n",priv->initgain_backup.xdagccore1);
3811 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xa0a is %x\n",priv->initgain_backup.cca);
3813 RT_TRACE(COMP_SCAN, "Write scan initial gain = 0x%x \n", initial_gain);
3814 write_nic_byte(dev, rOFDM0_XAAGCCore1, initial_gain);
3815 write_nic_byte(dev, rOFDM0_XBAGCCore1, initial_gain);
3816 write_nic_byte(dev, rOFDM0_XCAGCCore1, initial_gain);
3817 write_nic_byte(dev, rOFDM0_XDAGCCore1, initial_gain);
3818 RT_TRACE(COMP_SCAN, "Write scan 0xa0a = 0x%x \n", POWER_DETECTION_TH);
3819 write_nic_byte(dev, 0xa0a, POWER_DETECTION_TH);
3822 RT_TRACE(COMP_SCAN, "IG_Restore, restore the initial gain.\n");
3823 BitMask = 0x7f; //Bit0~ Bit6
3824 if(dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
3825 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); // FW DIG OFF
3827 rtl8192_setBBreg(dev, rOFDM0_XAAGCCore1, BitMask, (u32)priv->initgain_backup.xaagccore1);
3828 rtl8192_setBBreg(dev, rOFDM0_XBAGCCore1, BitMask, (u32)priv->initgain_backup.xbagccore1);
3829 rtl8192_setBBreg(dev, rOFDM0_XCAGCCore1, BitMask, (u32)priv->initgain_backup.xcagccore1);
3830 rtl8192_setBBreg(dev, rOFDM0_XDAGCCore1, BitMask, (u32)priv->initgain_backup.xdagccore1);
3831 BitMask = bMaskByte2;
3832 rtl8192_setBBreg(dev, rCCK0_CCA, BitMask, (u32)priv->initgain_backup.cca);
3834 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc50 is %x\n",priv->initgain_backup.xaagccore1);
3835 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc58 is %x\n",priv->initgain_backup.xbagccore1);
3836 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc60 is %x\n",priv->initgain_backup.xcagccore1);
3837 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc68 is %x\n",priv->initgain_backup.xdagccore1);
3838 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xa0a is %x\n",priv->initgain_backup.cca);
3840 PHY_SetTxPowerLevel8192S(dev,priv->ieee80211->current_network.channel);
3842 if(dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
3843 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x1); // FW DIG ON
3846 RT_TRACE(COMP_SCAN, "Unknown IG Operation. \n");
3852 //-----------------------------------------------------------------------------
3854 // Schedule workitem to send specific CMD IO to FW.
3855 // Added by Roger, 2008.12.03.
3857 //-----------------------------------------------------------------------------
3858 bool HalSetFwCmd8192S(struct net_device* dev, FW_CMD_IO_TYPE FwCmdIO)
3860 struct r8192_priv *priv = ieee80211_priv(dev);
3861 u16 FwCmdWaitCounter = 0;
3863 u16 FwCmdWaitLimit = 1000;
3865 //if(IS_HARDWARE_TYPE_8192SU(Adapter) && Adapter->bInHctTest)
3866 if(priv->bInHctTest)
3869 RT_TRACE(COMP_CMD, "-->HalSetFwCmd8192S(): Set FW Cmd(%x), SetFwCmdInProgress(%d)\n", (u32)FwCmdIO, priv->SetFwCmdInProgress);
3871 // Will be done by high power respectively.
3872 if(FwCmdIO==FW_CMD_DIG_HALT || FwCmdIO==FW_CMD_DIG_RESUME)
3874 RT_TRACE(COMP_CMD, "<--HalSetFwCmd8192S(): Set FW Cmd(%x)\n", (u32)FwCmdIO);
3879 while(priv->SetFwCmdInProgress && FwCmdWaitCounter<FwCmdWaitLimit)
3881 //if(RT_USB_CANNOT_IO(Adapter))
3883 // RT_TRACE(COMP_CMD, DBG_WARNING, ("HalSetFwCmd8192S(): USB can NOT IO!!\n"));
3887 RT_TRACE(COMP_CMD, "HalSetFwCmd8192S(): previous workitem not finish!!\n");
3889 FwCmdWaitCounter ++;
3890 RT_TRACE(COMP_CMD, "HalSetFwCmd8192S(): Wait 10 ms (%d times)...\n", FwCmdWaitCounter);
3894 if(FwCmdWaitCounter == FwCmdWaitLimit)
3896 //RT_ASSERT(FALSE, ("SetFwCmdIOWorkItemCallback(): Wait too logn to set FW CMD\n"));
3897 RT_TRACE(COMP_CMD, "HalSetFwCmd8192S(): Wait too logn to set FW CMD\n");
3901 if (priv->SetFwCmdInProgress)
3903 RT_TRACE(COMP_ERR, "<--HalSetFwCmd8192S(): Set FW Cmd(%#x)\n", FwCmdIO);
3906 priv->SetFwCmdInProgress = TRUE;
3907 priv->CurrentFwCmdIO = FwCmdIO; // Update current FW Cmd for callback use.
3909 phy_SetFwCmdIOCallback(dev);
3912 void ChkFwCmdIoDone(struct net_device* dev)
3914 u16 PollingCnt = 1000;
3918 {// Make sure that CMD IO has be accepted by FW.
3920 if(RT_USB_CANNOT_IO(Adapter))
3922 RT_TRACE(COMP_CMD, "ChkFwCmdIoDone(): USB can NOT IO!!\n");
3926 udelay(10); // sleep 20us
3927 tmpValue = read_nic_dword(dev, WFM5);
3930 RT_TRACE(COMP_CMD, "[FW CMD] Set FW Cmd success!!\n");
3935 RT_TRACE(COMP_CMD, "[FW CMD] Polling FW Cmd PollingCnt(%d)!!\n", PollingCnt);
3937 }while( --PollingCnt );
3941 RT_TRACE(COMP_ERR, "[FW CMD] Set FW Cmd fail!!\n");
3944 // Callback routine of the timer callback for FW Cmd IO.
3947 // This routine will send specific CMD IO to FW and check whether it is done.
3949 void phy_SetFwCmdIOCallback(struct net_device* dev)
3951 //struct net_device* dev = (struct net_device*) data;
3953 static u32 ScanRegister;
3954 struct r8192_priv *priv = ieee80211_priv(dev);
3957 RT_TRACE(COMP_CMD, "SetFwCmdIOTimerCallback(): driver is going to unload\n");
3961 RT_TRACE(COMP_CMD, "--->SetFwCmdIOTimerCallback(): Cmd(%#x), SetFwCmdInProgress(%d)\n", priv->CurrentFwCmdIO, priv->SetFwCmdInProgress);
3963 switch(priv->CurrentFwCmdIO)
3965 case FW_CMD_HIGH_PWR_ENABLE:
3966 if((priv->ieee80211->pHTInfo->IOTAction & HT_IOT_ACT_DISABLE_HIGH_POWER)==0)
3967 write_nic_dword(dev, WFM5, FW_HIGH_PWR_ENABLE);
3970 case FW_CMD_HIGH_PWR_DISABLE:
3971 write_nic_dword(dev, WFM5, FW_HIGH_PWR_DISABLE);
3974 case FW_CMD_DIG_RESUME:
3975 write_nic_dword(dev, WFM5, FW_DIG_RESUME);
3978 case FW_CMD_DIG_HALT:
3979 write_nic_dword(dev, WFM5, FW_DIG_HALT);
3983 // <Roger_Notes> The following FW CMD IO was combined into single operation
3984 // (i.e., to prevent number of system workitem out of resource!!).
3987 case FW_CMD_RESUME_DM_BY_SCAN:
3988 RT_TRACE(COMP_CMD, "[FW CMD] Set HIGHPWR enable and DIG resume!!\n");
3989 if((priv->ieee80211->pHTInfo->IOTAction & HT_IOT_ACT_DISABLE_HIGH_POWER)==0)
3991 write_nic_dword(dev, WFM5, FW_HIGH_PWR_ENABLE); //break;
3992 ChkFwCmdIoDone(dev);
3994 write_nic_dword(dev, WFM5, FW_DIG_RESUME);
3997 case FW_CMD_PAUSE_DM_BY_SCAN:
3998 RT_TRACE(COMP_CMD, "[FW CMD] Set HIGHPWR disable and DIG halt!!\n");
3999 write_nic_dword(dev, WFM5, FW_HIGH_PWR_DISABLE); //break;
4000 ChkFwCmdIoDone(dev);
4001 write_nic_dword(dev, WFM5, FW_DIG_HALT);
4005 // <Roger_Notes> The following FW CMD IO should be checked
4006 // (i.e., workitem schedule timing issue!!).
4009 case FW_CMD_DIG_DISABLE:
4010 RT_TRACE(COMP_CMD, "[FW CMD] Set DIG disable!!\n");
4011 write_nic_dword(dev, WFM5, FW_DIG_DISABLE);
4014 case FW_CMD_DIG_ENABLE:
4015 RT_TRACE(COMP_CMD, "[FW CMD] Set DIG enable!!\n");
4016 write_nic_dword(dev, WFM5, FW_DIG_ENABLE);
4019 case FW_CMD_RA_RESET:
4020 write_nic_dword(dev, WFM5, FW_RA_RESET);
4023 case FW_CMD_RA_ACTIVE:
4024 write_nic_dword(dev, WFM5, FW_RA_ACTIVE);
4027 case FW_CMD_RA_REFRESH_N:
4028 RT_TRACE(COMP_CMD, "[FW CMD] Set RA refresh!! N\n");
4029 if(priv->ieee80211->pHTInfo->IOTRaFunc & HT_IOT_RAFUNC_DISABLE_ALL)
4030 input = FW_RA_REFRESH;
4032 input = FW_RA_REFRESH | (priv->ieee80211->pHTInfo->IOTRaFunc << 8);
4033 write_nic_dword(dev, WFM5, input);
4035 case FW_CMD_RA_REFRESH_BG:
4036 RT_TRACE(COMP_CMD, "[FW CMD] Set RA refresh!! B/G\n");
4037 write_nic_dword(dev, WFM5, FW_RA_REFRESH);
4038 ChkFwCmdIoDone(dev);
4039 write_nic_dword(dev, WFM5, FW_RA_ENABLE_BG);
4042 case FW_CMD_IQK_ENABLE:
4043 write_nic_dword(dev, WFM5, FW_IQK_ENABLE);
4046 case FW_CMD_TXPWR_TRACK_ENABLE:
4047 write_nic_dword(dev, WFM5, FW_TXPWR_TRACK_ENABLE);
4050 case FW_CMD_TXPWR_TRACK_DISABLE:
4051 write_nic_dword(dev, WFM5, FW_TXPWR_TRACK_DISABLE);
4055 RT_TRACE(COMP_CMD,"Unknown FW Cmd IO(%#x)\n", priv->CurrentFwCmdIO);
4059 ChkFwCmdIoDone(dev);
4061 switch(priv->CurrentFwCmdIO)
4063 case FW_CMD_HIGH_PWR_DISABLE:
4064 //if(pMgntInfo->bTurboScan)
4066 //Lower initial gain
4067 rtl8192_setBBreg(dev, rOFDM0_XAAGCCore1, bMaskByte0, 0x17);
4068 rtl8192_setBBreg(dev, rOFDM0_XBAGCCore1, bMaskByte0, 0x17);
4070 rtl8192_setBBreg(dev, rCCK0_CCA, bMaskByte2, 0x40);
4071 // Disable OFDM Part
4072 rtl8192_setBBreg(dev, rOFDM0_TRMuxPar, bMaskByte2, 0x1);
4073 ScanRegister = rtl8192_QueryBBReg(dev, rOFDM0_RxDetector1,bMaskDWord);
4074 rtl8192_setBBreg(dev, rOFDM0_RxDetector1, 0xf, 0xf);
4075 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0x0);
4079 case FW_CMD_HIGH_PWR_ENABLE:
4080 //if(pMgntInfo->bTurboScan)
4082 rtl8192_setBBreg(dev, rOFDM0_XAAGCCore1, bMaskByte0, 0x36);
4083 rtl8192_setBBreg(dev, rOFDM0_XBAGCCore1, bMaskByte0, 0x36);
4086 rtl8192_setBBreg(dev, rCCK0_CCA, bMaskByte2, 0x83);
4088 rtl8192_setBBreg(dev, rOFDM0_TRMuxPar, bMaskByte2, 0x0);
4090 //LZM ADD because sometimes there is no FW_CMD_HIGH_PWR_DISABLE, this value will be 0.
4091 if(ScanRegister != 0){
4092 rtl8192_setBBreg(dev, rOFDM0_RxDetector1, bMaskDWord, ScanRegister);
4095 if(priv->rf_type == RF_1T2R || priv->rf_type == RF_2T2R)
4096 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0x3);
4098 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0x1);
4103 priv->SetFwCmdInProgress = false;// Clear FW CMD operation flag.
4104 RT_TRACE(COMP_CMD, "<---SetFwCmdIOWorkItemCallback()\n");