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"
39 #include "r8192S_hw.h"
40 #include "r8192S_phy.h"
41 #include "r8192S_phyreg.h"
42 #include "r8192SU_HWImg.h"
43 //#include "r8192S_FwImgDTM.h"
45 #include "r8192U_hw.h"
46 #include "r819xU_phy.h"
47 #include "r819xU_phyreg.h"
50 #include "ieee80211/dot11d.h"
52 /*---------------------------Define Local Constant---------------------------*/
53 /* Channel switch:The size of command tables for switch channel*/
54 #define MAX_PRECMD_CNT 16
55 #define MAX_RFDEPENDCMD_CNT 16
56 #define MAX_POSTCMD_CNT 16
57 #define MAX_DOZE_WAITING_TIMES_9x 64
59 /*------------------------Define local variable------------------------------*/
62 static u32 RF_CHANNEL_TABLE_ZEBRA[]={
78 0x0f72,//2484 //20040810
83 phy_CalculateBitShift(u32 BitMask);
85 phy_ConfigMACWithHeaderFile(struct net_device* dev);
87 phy_InitBBRFRegisterDefinition(struct net_device* dev);
89 phy_BB8192S_Config_ParaFile(struct net_device* dev);
91 phy_ConfigBBWithHeaderFile(struct net_device* dev,u8 ConfigType);
93 phy_SetRFPowerState8192SU(struct net_device* dev,RT_RF_POWER_STATE eRFPowerState);
95 SetBWModeCallback8192SUsbWorkItem(struct net_device *dev);
97 SetBWModeCallback8192SUsbWorkItem(struct net_device *dev);
99 SwChnlCallback8192SUsbWorkItem(struct net_device *dev );
101 phy_FinishSwChnlNow(struct net_device* dev,u8 channel);
103 phy_SwChnlStepByStep(
104 struct net_device* dev,
111 phy_ConfigBBWithPgHeaderFile(struct net_device* dev,u8 ConfigType);
113 static u32 phy_FwRFSerialRead( struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 Offset);
114 static u32 phy_RFSerialRead(struct net_device* dev,RF90_RADIO_PATH_E eRFPath,u32 Offset);
115 static void phy_FwRFSerialWrite( struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 Offset, u32 Data);
116 static void phy_RFSerialWrite( struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 Offset, u32 Data);
118 static long phy_TxPwrIdxToDbm( struct net_device* dev, WIRELESS_MODE WirelessMode, u8 TxPwrIdx);
119 static u8 phy_DbmToTxPwrIdx( struct net_device* dev, WIRELESS_MODE WirelessMode, long PowerInDbm);
120 void phy_SetFwCmdIOCallback(struct net_device* dev);
122 //#if ((HAL_CODE_BASE == RTL8192_S) && (DEV_BUS_TYPE==USB_INTERFACE))
126 // Base Band read by 4181 to make sure that operation could be done in unlimited cycle.
129 // - Only use on RTL8192S USB interface.
132 // Created by Roger, 2008.09.06.
135 u32 phy_QueryUsbBBReg(struct net_device* dev, u32 RegAddr)
137 struct r8192_priv *priv = ieee80211_priv(dev);
138 u32 ReturnValue = 0xffffffff;
140 u8 BBWaitCounter = 0;
144 // <Roger_Notes> Due to PASSIVE_LEVEL, so we ONLY simply busy waiting for a while here.
145 // We have to make sure that previous BB I/O has been done.
148 while(priv->bChangeBBInProgress)
151 RT_TRACE(COMP_RF, "phy_QueryUsbBBReg(): Wait 1 ms (%d times)...\n", BBWaitCounter);
154 // Wait too long, return FALSE to avoid to be stuck here.
155 if((BBWaitCounter > 100) )//||RT_USB_CANNOT_IO(Adapter))
157 RT_TRACE(COMP_RF, "phy_QueryUsbBBReg(): (%d) Wait too logn to query BB!!\n", BBWaitCounter);
162 priv->bChangeBBInProgress = true;
164 read_nic_dword(dev, RegAddr);
167 {// Make sure that access could be done.
168 if((read_nic_byte(dev, PHY_REG)&HST_RDBUSY) == 0)
170 }while( --PollingCnt );
174 RT_TRACE(COMP_RF, "Fail!!!phy_QueryUsbBBReg(): RegAddr(%#x) = %#x\n", RegAddr, ReturnValue);
178 // Data FW read back.
179 ReturnValue = read_nic_dword(dev, PHY_REG_DATA);
180 RT_TRACE(COMP_RF, "phy_QueryUsbBBReg(): RegAddr(%#x) = %#x, PollingCnt(%d)\n", RegAddr, ReturnValue, PollingCnt);
183 priv->bChangeBBInProgress = false;
192 // Base Band wrote by 4181 to make sure that operation could be done in unlimited cycle.
195 // - Only use on RTL8192S USB interface.
198 // Created by Roger, 2008.09.06.
202 phy_SetUsbBBReg(struct net_device* dev,u32 RegAddr,u32 Data)
204 struct r8192_priv *priv = ieee80211_priv(dev);
205 u8 BBWaitCounter = 0;
207 RT_TRACE(COMP_RF, "phy_SetUsbBBReg(): RegAddr(%#x) <= %#x\n", RegAddr, Data);
210 // <Roger_Notes> Due to PASSIVE_LEVEL, so we ONLY simply busy waiting for a while here.
211 // We have to make sure that previous BB I/O has been done.
214 while(priv->bChangeBBInProgress)
217 RT_TRACE(COMP_RF, "phy_SetUsbBBReg(): Wait 1 ms (%d times)...\n", BBWaitCounter);
220 if((BBWaitCounter > 100))// || RT_USB_CANNOT_IO(Adapter))
222 RT_TRACE(COMP_RF, "phy_SetUsbBBReg(): (%d) Wait too logn to query BB!!\n", BBWaitCounter);
227 priv->bChangeBBInProgress = true;
228 //printk("**************%s: RegAddr:%x Data:%x\n", __FUNCTION__,RegAddr, Data);
229 write_nic_dword(dev, RegAddr, Data);
231 priv->bChangeBBInProgress = false;
238 // RF read by 4181 to make sure that operation could be done in unlimited cycle.
241 // - Only use on RTL8192S USB interface.
243 // - RT_RF_OPERATE_SPINLOCK is acquired and keep on holding to the end.FIXLZM
245 // Created by Roger, 2008.09.06.
248 u32 phy_QueryUsbRFReg( struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 Offset)
251 struct r8192_priv *priv = ieee80211_priv(dev);
252 //u32 value = 0, ReturnValue = 0;
254 //u32 tmplong,tmplong2;
256 u8 RFWaitCounter = 0;
260 // <Roger_Notes> Due to PASSIVE_LEVEL, so we ONLY simply busy waiting for a while here.
261 // We have to make sure that previous RF I/O has been done.
264 while(priv->bChangeRFInProgress)
266 //PlatformReleaseSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
267 //spin_lock_irqsave(&priv->rf_lock, flags); //LZM,090318
271 RT_TRACE(COMP_RF, "phy_QueryUsbRFReg(): Wait 1 ms (%d times)...\n", RFWaitCounter);
274 if((RFWaitCounter > 100)) //|| RT_USB_CANNOT_IO(Adapter))
276 RT_TRACE(COMP_RF, "phy_QueryUsbRFReg(): (%d) Wait too logn to query BB!!\n", RFWaitCounter);
281 //PlatformAcquireSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
285 priv->bChangeRFInProgress = true;
286 //PlatformReleaseSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
289 Offset &= 0x3f; //RF_Offset= 0x00~0x3F
291 write_nic_dword(dev, RF_BB_CMD_ADDR, 0xF0000002|
292 (Offset<<8)| //RF_Offset= 0x00~0x3F
293 (eRFPath<<16)); //RF_Path = 0(A) or 1(B)
296 {// Make sure that access could be done.
297 if(read_nic_dword(dev, RF_BB_CMD_ADDR) == 0)
299 }while( --PollingCnt );
301 // Data FW read back.
302 ReturnValue = read_nic_dword(dev, RF_BB_CMD_DATA);
304 //PlatformAcquireSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
305 //spin_unlock_irqrestore(&priv->rf_lock, flags); //LZM,090318
307 priv->bChangeRFInProgress = false;
309 RT_TRACE(COMP_RF, "phy_QueryUsbRFReg(): eRFPath(%d), Offset(%#x) = %#x\n", eRFPath, Offset, ReturnValue);
318 // RF wrote by 4181 to make sure that operation could be done in unlimited cycle.
321 // - Only use on RTL8192S USB interface.
323 // - RT_RF_OPERATE_SPINLOCK is acquired and keep on holding to the end.FIXLZM
325 // Created by Roger, 2008.09.06.
328 void phy_SetUsbRFReg(struct net_device* dev,RF90_RADIO_PATH_E eRFPath,u32 RegAddr,u32 Data)
331 struct r8192_priv *priv = ieee80211_priv(dev);
333 u8 RFWaitCounter = 0;
337 // <Roger_Notes> Due to PASSIVE_LEVEL, so we ONLY simply busy waiting for a while here.
338 // We have to make sure that previous BB I/O has been done.
341 while(priv->bChangeRFInProgress)
343 //PlatformReleaseSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
344 //spin_lock_irqsave(&priv->rf_lock, flags); //LZM,090318
348 RT_TRACE(COMP_RF, "phy_SetUsbRFReg(): Wait 1 ms (%d times)...\n", RFWaitCounter);
351 if((RFWaitCounter > 100))// || RT_USB_CANNOT_IO(Adapter))
353 RT_TRACE(COMP_RF, "phy_SetUsbRFReg(): (%d) Wait too logn to query BB!!\n", RFWaitCounter);
358 //PlatformAcquireSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
362 priv->bChangeRFInProgress = true;
363 //PlatformReleaseSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
366 RegAddr &= 0x3f; //RF_Offset= 0x00~0x3F
368 write_nic_dword(dev, RF_BB_CMD_DATA, Data);
369 write_nic_dword(dev, RF_BB_CMD_ADDR, 0xF0000003|
370 (RegAddr<<8)| //RF_Offset= 0x00~0x3F
371 (eRFPath<<16)); //RF_Path = 0(A) or 1(B)
374 {// Make sure that access could be done.
375 if(read_nic_dword(dev, RF_BB_CMD_ADDR) == 0)
377 }while( --PollingCnt );
381 RT_TRACE(COMP_RF, "phy_SetUsbRFReg(): Set RegAddr(%#x) = %#x Fail!!!\n", RegAddr, Data);
384 //PlatformAcquireSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
385 //spin_unlock_irqrestore(&priv->rf_lock, flags); //LZM,090318
387 priv->bChangeRFInProgress = false;
393 /*---------------------Define local function prototype-----------------------*/
396 /*----------------------------Function Body----------------------------------*/
398 // 1. BB register R/W API
401 * Function: PHY_QueryBBReg
403 * OverView: Read "sepcific bits" from BB register
407 * u32 RegAddr, //The target address to be readback
408 * u32 BitMask //The target bit position in the target address
411 * Return: u32 Data //The readback register value
412 * Note: This function is equal to "GetRegSetting" in PHY programming guide
414 //use phy dm core 8225 8256 6052
415 //u32 PHY_QueryBBReg(struct net_device* dev,u32 RegAddr, u32 BitMask)
416 u32 rtl8192_QueryBBReg(struct net_device* dev, u32 RegAddr, u32 BitMask)
419 u32 ReturnValue = 0, OriginalValue, BitShift;
422 RT_TRACE(COMP_RF, "--->PHY_QueryBBReg(): RegAddr(%#x), BitMask(%#x)\n", RegAddr, BitMask);
425 // <Roger_Notes> Due to 8051 operation cycle (limitation cycle: 6us) and 1-Byte access issue, we should use
426 // 4181 to access Base Band instead of 8051 on USB interface to make sure that access could be done in
430 //#if ((HAL_CODE_BASE == RTL8192_S) && (DEV_BUS_TYPE==USB_INTERFACE))
432 if(IS_BB_REG_OFFSET_92S(RegAddr))
434 //if(RT_USB_CANNOT_IO(Adapter)) return FALSE;
436 if((RegAddr & 0x03) != 0)
438 printk("%s: Not DWORD alignment!!\n", __FUNCTION__);
442 OriginalValue = phy_QueryUsbBBReg(dev, RegAddr);
447 OriginalValue = read_nic_dword(dev, RegAddr);
450 BitShift = phy_CalculateBitShift(BitMask);
451 ReturnValue = (OriginalValue & BitMask) >> BitShift;
453 //RTPRINT(FPHY, PHY_BBR, ("BBR MASK=0x%x Addr[0x%x]=0x%x\n", BitMask, RegAddr, OriginalValue));
454 RT_TRACE(COMP_RF, "<---PHY_QueryBBReg(): RegAddr(%#x), BitMask(%#x), OriginalValue(%#x)\n", RegAddr, BitMask, OriginalValue);
455 return (ReturnValue);
459 * Function: PHY_SetBBReg
461 * OverView: Write "Specific bits" to BB register (page 8~)
465 * u32 RegAddr, //The target address to be modified
466 * u32 BitMask //The target bit position in the target address
468 * u32 Data //The new register value in the target bit position
469 * //of the target address
473 * Note: This function is equal to "PutRegSetting" in PHY programming guide
475 //use phy dm core 8225 8256
476 //void PHY_SetBBReg(struct net_device* dev,u32 RegAddr, u32 BitMask, u32 Data )
477 void rtl8192_setBBreg(struct net_device* dev, u32 RegAddr, u32 BitMask, u32 Data)
479 u32 OriginalValue, BitShift, NewValue;
482 RT_TRACE(COMP_RF, "--->PHY_SetBBReg(): RegAddr(%#x), BitMask(%#x), Data(%#x)\n", RegAddr, BitMask, Data);
485 // <Roger_Notes> Due to 8051 operation cycle (limitation cycle: 6us) and 1-Byte access issue, we should use
486 // 4181 to access Base Band instead of 8051 on USB interface to make sure that access could be done in
490 //#if ((HAL_CODE_BASE == RTL8192_S) && (DEV_BUS_TYPE==USB_INTERFACE))
492 if(IS_BB_REG_OFFSET_92S(RegAddr))
494 if((RegAddr & 0x03) != 0)
496 printk("%s: Not DWORD alignment!!\n", __FUNCTION__);
500 if(BitMask!= bMaskDWord)
501 {//if not "double word" write
502 OriginalValue = phy_QueryUsbBBReg(dev, RegAddr);
503 BitShift = phy_CalculateBitShift(BitMask);
504 NewValue = (((OriginalValue) & (~BitMask))|(Data << BitShift));
505 phy_SetUsbBBReg(dev, RegAddr, NewValue);
507 phy_SetUsbBBReg(dev, RegAddr, Data);
512 if(BitMask!= bMaskDWord)
513 {//if not "double word" write
514 OriginalValue = read_nic_dword(dev, RegAddr);
515 BitShift = phy_CalculateBitShift(BitMask);
516 NewValue = (((OriginalValue) & (~BitMask)) | (Data << BitShift));
517 write_nic_dword(dev, RegAddr, NewValue);
519 write_nic_dword(dev, RegAddr, Data);
522 //RT_TRACE(COMP_RF, "<---PHY_SetBBReg(): RegAddr(%#x), BitMask(%#x), Data(%#x)\n", RegAddr, BitMask, Data);
529 // 2. RF register R/W API
532 * Function: PHY_QueryRFReg
534 * OverView: Query "Specific bits" to RF register (page 8~)
538 * RF90_RADIO_PATH_E eRFPath, //Radio path of A/B/C/D
539 * u32 RegAddr, //The target address to be read
540 * u32 BitMask //The target bit position in the target address
544 * Return: u32 Readback value
545 * Note: This function is equal to "GetRFRegSetting" in PHY programming guide
548 //u32 PHY_QueryRFReg(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 RegAddr, u32 BitMask)
549 u32 rtl8192_phy_QueryRFReg(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 RegAddr, u32 BitMask)
551 u32 Original_Value, Readback_Value, BitShift;//, flags;
552 struct r8192_priv *priv = ieee80211_priv(dev);
555 RT_TRACE(COMP_RF, "--->PHY_QueryRFReg(): RegAddr(%#x), eRFPath(%#x), BitMask(%#x)\n", RegAddr, eRFPath,BitMask);
557 if (!((priv->rf_pathmap >> eRFPath) & 0x1))
559 printk("EEEEEError: rfpath off! rf_pathmap=%x eRFPath=%x\n", priv->rf_pathmap, eRFPath);
563 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
565 printk("EEEEEError: not legal rfpath! eRFPath=%x\n", eRFPath);
569 /* 2008/01/17 MH We get and release spin lock when reading RF register. */
570 //PlatformAcquireSpinLock(dev, RT_RF_OPERATE_SPINLOCK);FIXLZM
571 //spin_lock_irqsave(&priv->rf_lock, flags); //YJ,test,090113
574 // <Roger_Notes> Due to 8051 operation cycle (limitation cycle: 6us) and 1-Byte access issue, we should use
575 // 4181 to access Base Band instead of 8051 on USB interface to make sure that access could be done in
579 //#if (HAL_CODE_BASE == RTL8192_S && DEV_BUS_TYPE==USB_INTERFACE)
581 //if(RT_USB_CANNOT_IO(Adapter)) return FALSE;
582 Original_Value = phy_QueryUsbRFReg(dev, eRFPath, RegAddr);
584 if (priv->Rf_Mode == RF_OP_By_FW)
586 Original_Value = phy_FwRFSerialRead(dev, eRFPath, RegAddr);
590 Original_Value = phy_RFSerialRead(dev, eRFPath, RegAddr);
594 BitShift = phy_CalculateBitShift(BitMask);
595 Readback_Value = (Original_Value & BitMask) >> BitShift;
596 //spin_unlock_irqrestore(&priv->rf_lock, flags); //YJ,test,090113
598 //PlatformReleaseSpinLock(dev, RT_RF_OPERATE_SPINLOCK);
600 //RTPRINT(FPHY, PHY_RFR, ("RFR-%d MASK=0x%x Addr[0x%x]=0x%x\n", eRFPath, BitMask, RegAddr, Original_Value));
602 return (Readback_Value);
606 * Function: PHY_SetRFReg
608 * OverView: Write "Specific bits" to RF register (page 8~)
612 * RF90_RADIO_PATH_E eRFPath, //Radio path of A/B/C/D
613 * u32 RegAddr, //The target address to be modified
614 * u32 BitMask //The target bit position in the target address
616 * u32 Data //The new register Data in the target bit position
617 * //of the target address
621 * Note: This function is equal to "PutRFRegSetting" in PHY programming guide
624 //void PHY_SetRFReg(struct net_device* dev,RF90_RADIO_PATH_E eRFPath, u32 RegAddr, u32 BitMask,u32 Data )
625 void rtl8192_phy_SetRFReg(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
628 struct r8192_priv *priv = ieee80211_priv(dev);
629 u32 Original_Value, BitShift, New_Value;//, flags;
631 RT_TRACE(COMP_RF, "--->PHY_SetRFReg(): RegAddr(%#x), BitMask(%#x), Data(%#x), eRFPath(%#x)\n",
632 RegAddr, BitMask, Data, eRFPath);
634 if (!((priv->rf_pathmap >> eRFPath) & 0x1))
636 printk("EEEEEError: rfpath off! rf_pathmap=%x eRFPath=%x\n", priv->rf_pathmap, eRFPath);
639 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
641 printk("EEEEEError: not legal rfpath! eRFPath=%x\n", eRFPath);
645 /* 2008/01/17 MH We get and release spin lock when writing RF register. */
646 //PlatformAcquireSpinLock(dev, RT_RF_OPERATE_SPINLOCK);
647 //spin_lock_irqsave(&priv->rf_lock, flags); //YJ,test,090113
650 // <Roger_Notes> Due to 8051 operation cycle (limitation cycle: 6us) and 1-Byte access issue, we should use
651 // 4181 to access Base Band instead of 8051 on USB interface to make sure that access could be done in
655 //#if (HAL_CODE_BASE == RTL8192_S && DEV_BUS_TYPE==USB_INTERFACE)
657 //if(RT_USB_CANNOT_IO(Adapter)) return;
659 if (BitMask != bRFRegOffsetMask) // RF data is 12 bits only
661 Original_Value = phy_QueryUsbRFReg(dev, eRFPath, RegAddr);
662 BitShift = phy_CalculateBitShift(BitMask);
663 New_Value = (((Original_Value)&(~BitMask))|(Data<< BitShift));
664 phy_SetUsbRFReg(dev, eRFPath, RegAddr, New_Value);
667 phy_SetUsbRFReg(dev, eRFPath, RegAddr, Data);
669 if (priv->Rf_Mode == RF_OP_By_FW)
671 //DbgPrint("eRFPath-%d Addr[%02x] = %08x\n", eRFPath, RegAddr, Data);
672 if (BitMask != bRFRegOffsetMask) // RF data is 12 bits only
674 Original_Value = phy_FwRFSerialRead(dev, eRFPath, RegAddr);
675 BitShift = phy_CalculateBitShift(BitMask);
676 New_Value = (((Original_Value) & (~BitMask)) | (Data<< BitShift));
678 phy_FwRFSerialWrite(dev, eRFPath, RegAddr, New_Value);
681 phy_FwRFSerialWrite(dev, eRFPath, RegAddr, Data);
685 //DbgPrint("eRFPath-%d Addr[%02x] = %08x\n", eRFPath, RegAddr, Data);
686 if (BitMask != bRFRegOffsetMask) // RF data is 12 bits only
688 Original_Value = phy_RFSerialRead(dev, eRFPath, RegAddr);
689 BitShift = phy_CalculateBitShift(BitMask);
690 New_Value = (((Original_Value) & (~BitMask)) | (Data<< BitShift));
692 phy_RFSerialWrite(dev, eRFPath, RegAddr, New_Value);
695 phy_RFSerialWrite(dev, eRFPath, RegAddr, Data);
699 //PlatformReleaseSpinLock(dev, RT_RF_OPERATE_SPINLOCK);
700 //spin_unlock_irqrestore(&priv->rf_lock, flags); //YJ,test,090113
702 //RTPRINT(FPHY, PHY_RFW, ("RFW-%d MASK=0x%x Addr[0x%x]=0x%x\n", eRFPath, BitMask, RegAddr, Data));
703 RT_TRACE(COMP_RF, "<---PHY_SetRFReg(): RegAddr(%#x), BitMask(%#x), Data(%#x), eRFPath(%#x)\n",
704 RegAddr, BitMask, Data, eRFPath);
709 /*-----------------------------------------------------------------------------
710 * Function: phy_FwRFSerialRead()
712 * Overview: We support firmware to execute RF-R/W.
722 * 01/21/2008 MHC Create Version 0.
724 *---------------------------------------------------------------------------*/
728 struct net_device* dev,
729 RF90_RADIO_PATH_E eRFPath,
736 //DbgPrint("FW RF CTRL\n\r");
737 /* 2007/11/02 MH Firmware RF Write control. By Francis' suggestion, we can
738 not execute the scheme in the initial step. Otherwise, RF-R/W will waste
739 much time. This is only for site survey. */
740 // 1. Read operation need not insert data. bit 0-11
741 //Data &= bMask12Bits;
742 // 2. Write RF register address. Bit 12-19
743 Data |= ((Offset&0xFF)<<12);
744 // 3. Write RF path. bit 20-21
745 Data |= ((eRFPath&0x3)<<20);
746 // 4. Set RF read indicator. bit 22=0
748 // 5. Trigger Fw to operate the command. bit 31
750 // 6. We can not execute read operation if bit 31 is 1.
751 while (PlatformIORead4Byte(dev, QPNR)&0x80000000)
753 // If FW can not finish RF-R/W for more than ?? times. We must reset FW.
756 //DbgPrint("FW not finish RF-R Time=%d\n\r", time);
762 // 7. Execute read operation.
763 PlatformIOWrite4Byte(dev, QPNR, Data);
764 // 8. Check if firmawre send back RF content.
765 while (PlatformIORead4Byte(dev, QPNR)&0x80000000)
767 // If FW can not finish RF-R/W for more than ?? times. We must reset FW.
770 //DbgPrint("FW not finish RF-W Time=%d\n\r", time);
776 retValue = PlatformIORead4Byte(dev, RF_DATA);
780 } /* phy_FwRFSerialRead */
782 /*-----------------------------------------------------------------------------
783 * Function: phy_FwRFSerialWrite()
785 * Overview: We support firmware to execute RF-R/W.
795 * 01/21/2008 MHC Create Version 0.
797 *---------------------------------------------------------------------------*/
801 struct net_device* dev,
802 RF90_RADIO_PATH_E eRFPath,
808 DbgPrint("N FW RF CTRL RF-%d OF%02x DATA=%03x\n\r", eRFPath, Offset, Data);
809 /* 2007/11/02 MH Firmware RF Write control. By Francis' suggestion, we can
810 not execute the scheme in the initial step. Otherwise, RF-R/W will waste
811 much time. This is only for site survey. */
813 // 1. Set driver write bit and 12 bit data. bit 0-11
814 //Data &= bMask12Bits; // Done by uper layer.
815 // 2. Write RF register address. bit 12-19
816 Data |= ((Offset&0xFF)<<12);
817 // 3. Write RF path. bit 20-21
818 Data |= ((eRFPath&0x3)<<20);
819 // 4. Set RF write indicator. bit 22=1
821 // 5. Trigger Fw to operate the command. bit 31=1
824 // 6. Write operation. We can not write if bit 31 is 1.
825 while (PlatformIORead4Byte(dev, QPNR)&0x80000000)
827 // If FW can not finish RF-R/W for more than ?? times. We must reset FW.
830 //DbgPrint("FW not finish RF-W Time=%d\n\r", time);
836 // 7. No matter check bit. We always force the write. Because FW will
837 // not accept the command.
838 PlatformIOWrite4Byte(dev, QPNR, Data);
839 /* 2007/11/02 MH Acoording to test, we must delay 20us to wait firmware
840 to finish RF write operation. */
841 /* 2008/01/17 MH We support delay in firmware side now. */
844 } /* phy_FwRFSerialWrite */
847 * Function: phy_RFSerialRead
849 * OverView: Read regster from RF chips
853 * RF90_RADIO_PATH_E eRFPath, //Radio path of A/B/C/D
854 * u32 Offset, //The target address to be read
857 * Return: u32 reback value
858 * Note: Threre are three types of serial operations:
859 * 1. Software serial write
860 * 2. Hardware LSSI-Low Speed Serial Interface
861 * 3. Hardware HSSI-High speed
862 * serial write. Driver need to implement (1) and (2).
863 * This function is equal to the combination of RF_ReadReg() and RFLSSIRead()
866 static u32 phy_RFSerialRead(struct net_device* dev,RF90_RADIO_PATH_E eRFPath,u32 Offset)
870 struct r8192_priv *priv = ieee80211_priv(dev);
871 BB_REGISTER_DEFINITION_T *pPhyReg = &priv->PHYRegDef[eRFPath];
877 // Make sure RF register offset is correct
882 // Switch page for 8256 RF IC
884 if( priv->rf_chip == RF_8256 ||
885 priv->rf_chip == RF_8225 ||
886 priv->rf_chip == RF_6052)
888 //analog to digital off, for protection
889 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0xf00, 0x0);// 0x88c[11:8]
893 priv->RFReadPageCnt[2]++;//cosa add for debug
894 priv->RfReg0Value[eRFPath] |= 0x140;
896 // Switch to Reg_Mode2 for Reg31~45
897 rtl8192_setBBreg(dev,
898 pPhyReg->rf3wireOffset,
900 (priv->RfReg0Value[eRFPath] << 16) );
903 NewOffset = Offset - 30;
907 priv->RFReadPageCnt[1]++;//cosa add for debug
908 priv->RfReg0Value[eRFPath] |= 0x100;
909 priv->RfReg0Value[eRFPath] &= (~0x40);
911 // Switch to Reg_Mode1 for Reg16~30
912 rtl8192_setBBreg(dev,
913 pPhyReg->rf3wireOffset,
915 (priv->RfReg0Value[eRFPath] << 16) );
918 NewOffset = Offset - 15;
922 priv->RFReadPageCnt[0]++;//cosa add for debug
930 // Put desired read address to LSSI control register
932 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadAddress, NewOffset);
935 // Issue a posedge trigger
937 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadEdge, 0x0);
938 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadEdge, 0x1);
940 // TODO: we should not delay such a long time. Ask help from SD3
943 retValue = rtl8192_QueryBBReg(dev, pPhyReg->rfLSSIReadBack, bLSSIReadBackData);
945 // Switch back to Reg_Mode0;
946 if( priv->rf_chip == RF_8256 ||
947 priv->rf_chip == RF_8225 ||
948 priv->rf_chip == RF_0222D)
952 priv->RfReg0Value[eRFPath] &= 0xebf;
956 pPhyReg->rf3wireOffset,
958 (priv->RfReg0Value[eRFPath] << 16) );
961 //analog to digital on
962 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0xf00, 0xf);// 0x88c[11:8]
971 * Function: phy_RFSerialWrite
973 * OverView: Write data to RF register (page 8~)
977 * RF90_RADIO_PATH_E eRFPath, //Radio path of A/B/C/D
978 * u32 Offset, //The target address to be read
979 * u32 Data //The new register Data in the target bit position
980 * //of the target to be read
984 * Note: Threre are three types of serial operations:
985 * 1. Software serial write
986 * 2. Hardware LSSI-Low Speed Serial Interface
987 * 3. Hardware HSSI-High speed
988 * serial write. Driver need to implement (1) and (2).
989 * This function is equal to the combination of RF_ReadReg() and RFLSSIRead()
991 * Note: For RF8256 only
992 * The total count of RTL8256(Zebra4) register is around 36 bit it only employs
993 * 4-bit RF address. RTL8256 uses "register mode control bit" (Reg00[12], Reg00[10])
994 * to access register address bigger than 0xf. See "Appendix-4 in PHY Configuration
995 * programming guide" for more details.
996 * Thus, we define a sub-finction for RTL8526 register address conversion
997 * ===========================================================
998 * Register Mode RegCTL[1] RegCTL[0] Note
999 * (Reg00[12]) (Reg00[10])
1000 * ===========================================================
1001 * Reg_Mode0 0 x Reg 0 ~15(0x0 ~ 0xf)
1002 * ------------------------------------------------------------------
1003 * Reg_Mode1 1 0 Reg 16 ~30(0x1 ~ 0xf)
1004 * ------------------------------------------------------------------
1005 * Reg_Mode2 1 1 Reg 31 ~ 45(0x1 ~ 0xf)
1006 * ------------------------------------------------------------------
1011 struct net_device* dev,
1012 RF90_RADIO_PATH_E eRFPath,
1017 u32 DataAndAddr = 0;
1018 struct r8192_priv *priv = ieee80211_priv(dev);
1019 BB_REGISTER_DEFINITION_T *pPhyReg = &priv->PHYRegDef[eRFPath];
1025 PHY_RFShadowWrite(dev, eRFPath, Offset, Data);
1028 // Switch page for 8256 RF IC
1029 if( priv->rf_chip == RF_8256 ||
1030 priv->rf_chip == RF_8225 ||
1031 priv->rf_chip == RF_0222D)
1033 //analog to digital off, for protection
1034 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0xf00, 0x0);// 0x88c[11:8]
1038 priv->RFWritePageCnt[2]++;//cosa add for debug
1039 priv->RfReg0Value[eRFPath] |= 0x140;
1041 rtl8192_setBBreg(dev,
1042 pPhyReg->rf3wireOffset,
1044 (priv->RfReg0Value[eRFPath] << 16) );
1046 NewOffset = Offset - 30;
1048 }else if(Offset>=16)
1050 priv->RFWritePageCnt[1]++;//cosa add for debug
1051 priv->RfReg0Value[eRFPath] |= 0x100;
1052 priv->RfReg0Value[eRFPath] &= (~0x40);
1055 rtl8192_setBBreg(dev,
1056 pPhyReg->rf3wireOffset,
1058 (priv->RfReg0Value[eRFPath] << 16) );
1060 NewOffset = Offset - 15;
1064 priv->RFWritePageCnt[0]++;//cosa add for debug
1072 // Put write addr in [5:0] and write data in [31:16]
1074 DataAndAddr = (Data<<16) | (NewOffset&0x3f);
1079 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, bMaskDWord, DataAndAddr);
1083 priv->RfReg0Value[eRFPath] = Data;
1085 // Switch back to Reg_Mode0;
1086 if( priv->rf_chip == RF_8256 ||
1087 priv->rf_chip == RF_8225 ||
1088 priv->rf_chip == RF_0222D)
1094 priv->RfReg0Value[eRFPath] &= 0xebf;
1097 pPhyReg->rf3wireOffset,
1099 (priv->RfReg0Value[eRFPath] << 16) );
1102 //analog to digital on
1103 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0xf00, 0xf);// 0x88c[11:8]
1109 * Function: phy_RFSerialRead
1111 * OverView: Read regster from RF chips
1115 * RF90_RADIO_PATH_E eRFPath, //Radio path of A/B/C/D
1116 * u4Byte Offset, //The target address to be read
1119 * Return: u4Byte reback value
1120 * Note: Threre are three types of serial operations:
1121 * 1. Software serial write
1122 * 2. Hardware LSSI-Low Speed Serial Interface
1123 * 3. Hardware HSSI-High speed
1124 * serial write. Driver need to implement (1) and (2).
1125 * This function is equal to the combination of RF_ReadReg() and RFLSSIRead()
1129 phy_RFSerialRead(struct net_device* dev,RF90_RADIO_PATH_E eRFPath,u32 Offset)
1133 struct r8192_priv *priv = ieee80211_priv(dev);
1134 BB_REGISTER_DEFINITION_T *pPhyReg = &priv->PHYRegDef[eRFPath];
1137 u32 tmplong,tmplong2;
1140 if(pHalData->RFChipID == RF_8225 && Offset > 0x24) //36 valid regs
1142 if(pHalData->RFChipID == RF_8256 && Offset > 0x2D) //45 valid regs
1146 // Make sure RF register offset is correct
1151 // Switch page for 8256 RF IC
1155 // For 92S LSSI Read RFLSSIRead
1156 // For RF A/B write 0x824/82c(does not work in the future)
1157 // We must use 0x824 for RF A and B to execute read trigger
1158 tmplong = rtl8192_QueryBBReg(dev, rFPGA0_XA_HSSIParameter2, bMaskDWord);
1159 tmplong2 = rtl8192_QueryBBReg(dev, pPhyReg->rfHSSIPara2, bMaskDWord);
1160 tmplong2 = (tmplong2 & (~bLSSIReadAddress)) | (NewOffset<<23) | bLSSIReadEdge; //T65 RF
1162 rtl8192_setBBreg(dev, rFPGA0_XA_HSSIParameter2, bMaskDWord, tmplong&(~bLSSIReadEdge));
1165 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bMaskDWord, tmplong2);
1168 rtl8192_setBBreg(dev, rFPGA0_XA_HSSIParameter2, bMaskDWord, tmplong|bLSSIReadEdge);
1171 if(eRFPath == RF90_PATH_A)
1172 RfPiEnable = (u8)rtl8192_QueryBBReg(dev, rFPGA0_XA_HSSIParameter1, BIT8);
1173 else if(eRFPath == RF90_PATH_B)
1174 RfPiEnable = (u8)rtl8192_QueryBBReg(dev, rFPGA0_XB_HSSIParameter1, BIT8);
1177 { // Read from BBreg8b8, 12 bits for 8190, 20bits for T65 RF
1178 retValue = rtl8192_QueryBBReg(dev, pPhyReg->rfLSSIReadBackPi, bLSSIReadBackData);
1179 //DbgPrint("Readback from RF-PI : 0x%x\n", retValue);
1182 { //Read from BBreg8a0, 12 bits for 8190, 20 bits for T65 RF
1183 retValue = rtl8192_QueryBBReg(dev, pPhyReg->rfLSSIReadBack, bLSSIReadBackData);
1184 //DbgPrint("Readback from RF-SI : 0x%x\n", retValue);
1186 //RTPRINT(FPHY, PHY_RFR, ("RFR-%d Addr[0x%x]=0x%x\n", eRFPath, pPhyReg->rfLSSIReadBack, retValue));
1195 * Function: phy_RFSerialWrite
1197 * OverView: Write data to RF register (page 8~)
1201 * RF90_RADIO_PATH_E eRFPath, //Radio path of A/B/C/D
1202 * u4Byte Offset, //The target address to be read
1203 * u4Byte Data //The new register Data in the target bit position
1204 * //of the target to be read
1208 * Note: Threre are three types of serial operations:
1209 * 1. Software serial write
1210 * 2. Hardware LSSI-Low Speed Serial Interface
1211 * 3. Hardware HSSI-High speed
1212 * serial write. Driver need to implement (1) and (2).
1213 * This function is equal to the combination of RF_ReadReg() and RFLSSIRead()
1215 * Note: For RF8256 only
1216 * The total count of RTL8256(Zebra4) register is around 36 bit it only employs
1217 * 4-bit RF address. RTL8256 uses "register mode control bit" (Reg00[12], Reg00[10])
1218 * to access register address bigger than 0xf. See "Appendix-4 in PHY Configuration
1219 * programming guide" for more details.
1220 * Thus, we define a sub-finction for RTL8526 register address conversion
1221 * ===========================================================
1222 * Register Mode RegCTL[1] RegCTL[0] Note
1223 * (Reg00[12]) (Reg00[10])
1224 * ===========================================================
1225 * Reg_Mode0 0 x Reg 0 ~15(0x0 ~ 0xf)
1226 * ------------------------------------------------------------------
1227 * Reg_Mode1 1 0 Reg 16 ~30(0x1 ~ 0xf)
1228 * ------------------------------------------------------------------
1229 * Reg_Mode2 1 1 Reg 31 ~ 45(0x1 ~ 0xf)
1230 * ------------------------------------------------------------------
1232 * 2008/09/02 MH Add 92S RF definition
1238 phy_RFSerialWrite(struct net_device* dev,RF90_RADIO_PATH_E eRFPath,u32 Offset,u32 Data)
1240 u32 DataAndAddr = 0;
1241 struct r8192_priv *priv = ieee80211_priv(dev);
1242 BB_REGISTER_DEFINITION_T *pPhyReg = &priv->PHYRegDef[eRFPath];
1246 //<Roger_TODO> We should check valid regs for RF_6052 case.
1247 if(pHalData->RFChipID == RF_8225 && Offset > 0x24) //36 valid regs
1249 if(pHalData->RFChipID == RF_8256 && Offset > 0x2D) //45 valid regs
1258 PHY_RFShadowWrite(dev, eRFPath, Offset, Data);
1261 // Switch page for 8256 RF IC
1266 // Put write addr in [5:0] and write data in [31:16]
1268 //DataAndAddr = (Data<<16) | (NewOffset&0x3f);
1269 DataAndAddr = ((NewOffset<<20) | (Data&0x000fffff)) & 0x0fffffff; // T65 RF
1274 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, bMaskDWord, DataAndAddr);
1275 //RTPRINT(FPHY, PHY_RFW, ("RFW-%d Addr[0x%x]=0x%x\n", eRFPath, pPhyReg->rf3wireOffset, DataAndAddr));
1282 * Function: phy_CalculateBitShift
1284 * OverView: Get shifted position of the BitMask
1290 * Return: u32 Return the shift bit bit position of the mask
1293 static u32 phy_CalculateBitShift(u32 BitMask)
1297 for(i=0; i<=31; i++)
1299 if ( ((BitMask>>i) & 0x1 ) == 1)
1308 // 3. Initial MAC/BB/RF config by reading MAC/BB/RF txt.
1310 /*-----------------------------------------------------------------------------
1311 * Function: PHY_MACConfig8192S
1313 * Overview: Condig MAC by header file or parameter file.
1323 * 08/12/2008 MHC Create Version 0.
1325 *---------------------------------------------------------------------------*/
1327 extern bool PHY_MACConfig8192S(struct net_device* dev)
1329 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
1334 rtStatus = phy_ConfigMACWithHeaderFile(dev);
1335 return (rtStatus == RT_STATUS_SUCCESS) ? true:false;
1341 PHY_BBConfig8192S(struct net_device* dev)
1343 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
1345 u8 PathMap = 0, index = 0, rf_num = 0;
1346 struct r8192_priv *priv = ieee80211_priv(dev);
1347 phy_InitBBRFRegisterDefinition(dev);
1350 // Config BB and AGC
1352 //switch( Adapter->MgntInfo.bRegHwParaFile )
1355 // phy_BB8190_Config_HardCode(dev);
1359 rtStatus = phy_BB8192S_Config_ParaFile(dev);
1364 // phy_BB8190_Config_HardCode(dev);
1365 // phy_BB8192S_Config_ParaFile(dev);
1369 // phy_BB8190_Config_HardCode(dev);
1372 PathMap = (u8)(rtl8192_QueryBBReg(dev, rFPGA0_TxInfo, 0xf) |
1373 rtl8192_QueryBBReg(dev, rOFDM0_TRxPathEnable, 0xf));
1374 priv->rf_pathmap = PathMap;
1375 for(index = 0; index<4; index++)
1377 if((PathMap>>index)&0x1)
1381 if((priv->rf_type==RF_1T1R && rf_num!=1) ||
1382 (priv->rf_type==RF_1T2R && rf_num!=2) ||
1383 (priv->rf_type==RF_2T2R && rf_num!=2) ||
1384 (priv->rf_type==RF_2T2R_GREEN && rf_num!=2) ||
1385 (priv->rf_type==RF_2T4R && rf_num!=4))
1387 RT_TRACE( COMP_INIT, "PHY_BBConfig8192S: RF_Type(%x) does not match RF_Num(%x)!!\n", priv->rf_type, rf_num);
1389 return (rtStatus == RT_STATUS_SUCCESS) ? 1:0;
1394 PHY_RFConfig8192S(struct net_device* dev)
1396 struct r8192_priv *priv = ieee80211_priv(dev);
1397 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
1399 //Set priv->rf_chip = RF_8225 to do real PHY FPGA initilization
1401 //<Roger_EXP> We assign RF type here temporally. 2008.09.12.
1402 priv->rf_chip = RF_6052;
1407 switch(priv->rf_chip)
1411 rtStatus = PHY_RF6052_Config(dev);
1415 //rtStatus = PHY_RF8256_Config(dev);
1422 //rtStatus = PHY_RF8225_Config(dev);
1428 return (rtStatus == RT_STATUS_SUCCESS) ? 1:0;
1432 // Joseph test: new initialize order!!
1433 // Test only!! This part need to be re-organized.
1434 // Now it is just for 8256.
1438 phy_BB8190_Config_HardCode(struct net_device* dev)
1440 //RT_ASSERT(FALSE, ("This function is not implement yet!! \n"));
1441 return RT_STATUS_SUCCESS;
1445 /*-----------------------------------------------------------------------------
1446 * Function: phy_SetBBtoDiffRFWithHeaderFile()
1448 * Overview: This function
1451 * Input: PADAPTER Adapter
1452 * u1Byte ConfigType 0 => PHY_CONFIG
1456 * Return: RT_STATUS_SUCCESS: configuration file exist
1460 *---------------------------------------------------------------------------*/
1462 phy_SetBBtoDiffRFWithHeaderFile(struct net_device* dev, u8 ConfigType)
1465 struct r8192_priv *priv = ieee80211_priv(dev);
1466 u32* Rtl819XPHY_REGArraytoXTXR_Table;
1467 u16 PHY_REGArraytoXTXRLen;
1469 //#if (HAL_CODE_BASE != RTL8192_S)
1471 if(priv->rf_type == RF_1T1R)
1473 Rtl819XPHY_REGArraytoXTXR_Table = Rtl819XPHY_REG_to1T1R_Array;
1474 PHY_REGArraytoXTXRLen = PHY_ChangeTo_1T1RArrayLength;
1476 else if(priv->rf_type == RF_1T2R)
1478 Rtl819XPHY_REGArraytoXTXR_Table = Rtl819XPHY_REG_to1T2R_Array;
1479 PHY_REGArraytoXTXRLen = PHY_ChangeTo_1T2RArrayLength;
1481 //else if(priv->rf_type == RF_2T2R || priv->rf_type == RF_2T2R_GREEN)
1483 // Rtl819XPHY_REGArraytoXTXR_Table = Rtl819XPHY_REG_to2T2R_Array;
1484 // PHY_REGArraytoXTXRLen = PHY_ChangeTo_2T2RArrayLength;
1488 return RT_STATUS_FAILURE;
1491 if(ConfigType == BaseBand_Config_PHY_REG)
1493 for(i=0;i<PHY_REGArraytoXTXRLen;i=i+3)
1495 if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xfe)
1497 else if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xfd)
1499 else if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xfc)
1501 else if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xfb)
1503 else if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xfa)
1505 else if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xf9)
1507 rtl8192_setBBreg(dev, Rtl819XPHY_REGArraytoXTXR_Table[i], Rtl819XPHY_REGArraytoXTXR_Table[i+1], Rtl819XPHY_REGArraytoXTXR_Table[i+2]);
1508 //RT_TRACE(COMP_SEND,
1509 //"The Rtl819XPHY_REGArraytoXTXR_Table[0] is %lx Rtl819XPHY_REGArraytoXTXR_Table[1] is %lx Rtl819XPHY_REGArraytoXTXR_Table[2] is %lx \n",
1510 //Rtl819XPHY_REGArraytoXTXR_Table[i],Rtl819XPHY_REGArraytoXTXR_Table[i+1], Rtl819XPHY_REGArraytoXTXR_Table[i+2]);
1514 RT_TRACE(COMP_SEND, "phy_SetBBtoDiffRFWithHeaderFile(): ConfigType != BaseBand_Config_PHY_REG\n");
1516 //#endif // #if (HAL_CODE_BASE != RTL8192_S)
1517 return RT_STATUS_SUCCESS;
1523 phy_BB8192S_Config_ParaFile(struct net_device* dev)
1525 struct r8192_priv *priv = ieee80211_priv(dev);
1526 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
1529 //char szBBRegFile[] = RTL819X_PHY_REG;
1530 //char szBBRegFile1T2R[] = RTL819X_PHY_REG_1T2R;
1531 //char szBBRegPgFile[] = RTL819X_PHY_REG_PG;
1532 //char szAGCTableFile[] = RTL819X_AGC_TAB;
1533 //char szBBRegto1T1RFile[] = RTL819X_PHY_REG_to1T1R;
1534 //char szBBRegto1T2RFile[] = RTL819X_PHY_REG_to1T2R;
1536 RT_TRACE(COMP_INIT, "==>phy_BB8192S_Config_ParaFile\n");
1539 // 1. Read PHY_REG.TXT BB INIT!!
1540 // We will seperate as 1T1R/1T2R/1T2R_GREEN/2T2R
1542 if (priv->rf_type == RF_1T2R || priv->rf_type == RF_2T2R ||
1543 priv->rf_type == RF_1T1R ||priv->rf_type == RF_2T2R_GREEN)
1545 rtStatus = phy_ConfigBBWithHeaderFile(dev,BaseBand_Config_PHY_REG);
1546 if(priv->rf_type != RF_2T2R && priv->rf_type != RF_2T2R_GREEN)
1547 {//2008.11.10 Added by tynli. The default PHY_REG.txt we read is for 2T2R,
1548 //so we should reconfig BB reg with the right PHY parameters.
1549 rtStatus = phy_SetBBtoDiffRFWithHeaderFile(dev,BaseBand_Config_PHY_REG);
1552 rtStatus = RT_STATUS_FAILURE;
1554 if(rtStatus != RT_STATUS_SUCCESS){
1555 RT_TRACE(COMP_INIT, "phy_BB8192S_Config_ParaFile():Write BB Reg Fail!!");
1556 goto phy_BB8190_Config_ParaFile_Fail;
1560 // 2. If EEPROM or EFUSE autoload OK, We must config by PHY_REG_PG.txt
1562 if (priv->AutoloadFailFlag == false)
1564 rtStatus = phy_ConfigBBWithPgHeaderFile(dev,BaseBand_Config_PHY_REG);
1566 if(rtStatus != RT_STATUS_SUCCESS){
1567 RT_TRACE(COMP_INIT, "phy_BB8192S_Config_ParaFile():BB_PG Reg Fail!!");
1568 goto phy_BB8190_Config_ParaFile_Fail;
1572 // 3. BB AGC table Initialization
1574 rtStatus = phy_ConfigBBWithHeaderFile(dev,BaseBand_Config_AGC_TAB);
1576 if(rtStatus != RT_STATUS_SUCCESS){
1577 printk( "phy_BB8192S_Config_ParaFile():AGC Table Fail\n");
1578 goto phy_BB8190_Config_ParaFile_Fail;
1582 #if 0 // 2008/08/18 MH Disable for 92SE
1583 if(pHalData->VersionID > VERSION_8190_BD)
1585 //if(pHalData->RF_Type == RF_2T4R)
1587 // Antenna gain offset from B/C/D to A
1588 u4RegValue = ( pHalData->AntennaTxPwDiff[2]<<8 |
1589 pHalData->AntennaTxPwDiff[1]<<4 |
1590 pHalData->AntennaTxPwDiff[0]);
1595 PHY_SetBBReg(dev, rFPGA0_TxGainStage,
1596 (bXBTxAGC|bXCTxAGC|bXDTxAGC), u4RegValue);
1600 u4RegValue = pHalData->CrystalCap;
1601 PHY_SetBBReg(dev, rFPGA0_AnalogParameter1, bXtalCap92x, u4RegValue);
1603 //u4RegValue = ((pHalData->CrystalCap & 0xc)>>2); // bit2~3 of crystal cap
1604 //PHY_SetBBReg(Adapter, rFPGA0_AnalogParameter2, bXtalCap23, u4RegValue);
1609 // Check if the CCK HighPower is turned ON.
1610 // This is used to calculate PWDB.
1611 priv->bCckHighPower = (bool)(rtl8192_QueryBBReg(dev, rFPGA0_XA_HSSIParameter2, 0x200));
1614 phy_BB8190_Config_ParaFile_Fail:
1618 /*-----------------------------------------------------------------------------
1619 * Function: phy_ConfigMACWithHeaderFile()
1621 * Overview: This function read BB parameters from Header file we gen, and do register
1624 * Input: PADAPTER Adapter
1629 * Return: RT_STATUS_SUCCESS: configuration file exist
1631 * Note: The format of MACPHY_REG.txt is different from PHY and RF.
1632 * [Register][Mask][Value]
1633 *---------------------------------------------------------------------------*/
1636 phy_ConfigMACWithHeaderFile(struct net_device* dev)
1639 u32 ArrayLength = 0;
1641 //struct r8192_priv *priv = ieee80211_priv(dev);
1643 //#if (HAL_CODE_BASE != RTL8192_S)
1644 /*if(Adapter->bInHctTest)
1646 RT_TRACE(COMP_INIT, DBG_LOUD, ("Rtl819XMACPHY_ArrayDTM\n"));
1647 ArrayLength = MACPHY_ArrayLengthDTM;
1648 ptrArray = Rtl819XMACPHY_ArrayDTM;
1650 else if(pHalData->bTXPowerDataReadFromEEPORM)
1652 // RT_TRACE(COMP_INIT, DBG_LOUD, ("Rtl819XMACPHY_Array_PG\n"));
1653 // ArrayLength = MACPHY_Array_PGLength;
1654 // ptrArray = Rtl819XMACPHY_Array_PG;
1657 { //2008.11.06 Modified by tynli.
1658 RT_TRACE(COMP_INIT, "Read Rtl819XMACPHY_Array\n");
1659 ArrayLength = MAC_2T_ArrayLength;
1660 ptrArray = Rtl819XMAC_Array;
1663 /*for(i = 0 ;i < ArrayLength;i=i+3){
1664 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]));
1665 if(ptrArray[i] == 0x318)
1667 ptrArray[i+2] = 0x00000800;
1668 //DbgPrint("ptrArray[i], ptrArray[i+1], ptrArray[i+2] = %x, %x, %x\n",
1669 // ptrArray[i], ptrArray[i+1], ptrArray[i+2]);
1671 PHY_SetBBReg(Adapter, ptrArray[i], ptrArray[i+1], ptrArray[i+2]);
1673 for(i = 0 ;i < ArrayLength;i=i+2){ // Add by tynli for 2 column
1674 write_nic_byte(dev, ptrArray[i], (u8)ptrArray[i+1]);
1677 return RT_STATUS_SUCCESS;
1680 /*-----------------------------------------------------------------------------
1681 * Function: phy_ConfigBBWithHeaderFile()
1683 * Overview: This function read BB parameters from general file format, and do register
1686 * Input: PADAPTER Adapter
1687 * u8 ConfigType 0 => PHY_CONFIG
1692 * Return: RT_STATUS_SUCCESS: configuration file exist
1694 *---------------------------------------------------------------------------*/
1697 phy_ConfigBBWithHeaderFile(struct net_device* dev,u8 ConfigType)
1701 u32* Rtl819XPHY_REGArray_Table;
1702 u32* Rtl819XAGCTAB_Array_Table;
1703 u16 PHY_REGArrayLen, AGCTAB_ArrayLen;
1704 //struct r8192_priv *priv = ieee80211_priv(dev);
1705 //#if (HAL_CODE_BASE != RTL8192_S)
1706 /*if(Adapter->bInHctTest)
1709 AGCTAB_ArrayLen = AGCTAB_ArrayLengthDTM;
1710 Rtl819XAGCTAB_Array_Table = Rtl819XAGCTAB_ArrayDTM;
1712 if(pHalData->RF_Type == RF_2T4R)
1714 PHY_REGArrayLen = PHY_REGArrayLengthDTM;
1715 Rtl819XPHY_REGArray_Table = Rtl819XPHY_REGArrayDTM;
1717 else if (pHalData->RF_Type == RF_1T2R)
1719 PHY_REGArrayLen = PHY_REG_1T2RArrayLengthDTM;
1720 Rtl819XPHY_REGArray_Table = Rtl819XPHY_REG_1T2RArrayDTM;
1728 // 2008.11.06 Modified by tynli.
1730 AGCTAB_ArrayLen = AGCTAB_ArrayLength;
1731 Rtl819XAGCTAB_Array_Table = Rtl819XAGCTAB_Array;
1732 PHY_REGArrayLen = PHY_REG_2T2RArrayLength; // Default RF_type: 2T2R
1733 Rtl819XPHY_REGArray_Table = Rtl819XPHY_REG_Array;
1736 if(ConfigType == BaseBand_Config_PHY_REG)
1738 for(i=0;i<PHY_REGArrayLen;i=i+2)
1740 if (Rtl819XPHY_REGArray_Table[i] == 0xfe)
1742 else if (Rtl819XPHY_REGArray_Table[i] == 0xfd)
1744 else if (Rtl819XPHY_REGArray_Table[i] == 0xfc)
1746 else if (Rtl819XPHY_REGArray_Table[i] == 0xfb)
1748 else if (Rtl819XPHY_REGArray_Table[i] == 0xfa)
1750 else if (Rtl819XPHY_REGArray_Table[i] == 0xf9)
1752 rtl8192_setBBreg(dev, Rtl819XPHY_REGArray_Table[i], bMaskDWord, Rtl819XPHY_REGArray_Table[i+1]);
1753 //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]);
1757 else if(ConfigType == BaseBand_Config_AGC_TAB){
1758 for(i=0;i<AGCTAB_ArrayLen;i=i+2)
1760 rtl8192_setBBreg(dev, Rtl819XAGCTAB_Array_Table[i], bMaskDWord, Rtl819XAGCTAB_Array_Table[i+1]);
1763 //#endif // #if (HAL_CODE_BASE != RTL8192_S)
1764 return RT_STATUS_SUCCESS;
1767 /*-----------------------------------------------------------------------------
1768 * Function: phy_ConfigBBWithPgHeaderFile
1770 * Overview: Config PHY_REG_PG array
1780 * 11/06/2008 MHC Add later!!!!!!.. Please modify for new files!!!!
1781 * 11/10/2008 tynli Modify to mew files.
1783 *---------------------------------------------------------------------------*/
1785 phy_ConfigBBWithPgHeaderFile(struct net_device* dev,u8 ConfigType)
1789 u32* Rtl819XPHY_REGArray_Table_PG;
1790 u16 PHY_REGArrayPGLen;
1791 //struct r8192_priv *priv = ieee80211_priv(dev);
1792 //#if (HAL_CODE_BASE != RTL8192_S)
1793 // Default: pHalData->RF_Type = RF_2T2R.
1795 PHY_REGArrayPGLen = PHY_REG_Array_PGLength;
1796 Rtl819XPHY_REGArray_Table_PG = Rtl819XPHY_REG_Array_PG;
1798 if(ConfigType == BaseBand_Config_PHY_REG)
1800 for(i=0;i<PHY_REGArrayPGLen;i=i+3)
1802 if (Rtl819XPHY_REGArray_Table_PG[i] == 0xfe)
1804 else if (Rtl819XPHY_REGArray_Table_PG[i] == 0xfd)
1806 else if (Rtl819XPHY_REGArray_Table_PG[i] == 0xfc)
1808 else if (Rtl819XPHY_REGArray_Table_PG[i] == 0xfb)
1810 else if (Rtl819XPHY_REGArray_Table_PG[i] == 0xfa)
1812 else if (Rtl819XPHY_REGArray_Table_PG[i] == 0xf9)
1814 rtl8192_setBBreg(dev, Rtl819XPHY_REGArray_Table_PG[i], Rtl819XPHY_REGArray_Table_PG[i+1], Rtl819XPHY_REGArray_Table_PG[i+2]);
1815 //RT_TRACE(COMP_SEND, "The Rtl819XPHY_REGArray_Table_PG[0] is %lx Rtl819XPHY_REGArray_Table_PG[1] is %lx \n",
1816 // Rtl819XPHY_REGArray_Table_PG[i], Rtl819XPHY_REGArray_Table_PG[i+1]);
1819 RT_TRACE(COMP_SEND, "phy_ConfigBBWithPgHeaderFile(): ConfigType != BaseBand_Config_PHY_REG\n");
1821 return RT_STATUS_SUCCESS;
1823 } /* phy_ConfigBBWithPgHeaderFile */
1825 /*-----------------------------------------------------------------------------
1826 * Function: PHY_ConfigRFWithHeaderFile()
1828 * Overview: This function read RF parameters from general file format, and do RF 3-wire
1830 * Input: PADAPTER Adapter
1832 * RF90_RADIO_PATH_E eRFPath
1836 * Return: RT_STATUS_SUCCESS: configuration file exist
1838 * Note: Delay may be required for RF configuration
1839 *---------------------------------------------------------------------------*/
1840 //in 8256 phy_RF8256_Config_ParaFile only
1841 //RT_STATUS PHY_ConfigRFWithHeaderFile(struct net_device* dev,RF90_RADIO_PATH_E eRFPath)
1842 u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device* dev, RF90_RADIO_PATH_E eRFPath)
1845 struct r8192_priv *priv = ieee80211_priv(dev);
1848 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
1849 u32 *Rtl819XRadioA_Array_Table;
1850 u32 *Rtl819XRadioB_Array_Table;
1851 //u32* Rtl819XRadioC_Array_Table;
1852 //u32* Rtl819XRadioD_Array_Table;
1853 u16 RadioA_ArrayLen,RadioB_ArrayLen;
1855 { //2008.11.06 Modified by tynli
1856 RadioA_ArrayLen = RadioA_1T_ArrayLength;
1857 Rtl819XRadioA_Array_Table=Rtl819XRadioA_Array;
1858 Rtl819XRadioB_Array_Table=Rtl819XRadioB_Array;
1859 RadioB_ArrayLen = RadioB_ArrayLength;
1862 if( priv->rf_type == RF_2T2R_GREEN )
1864 Rtl819XRadioB_Array_Table = Rtl819XRadioB_GM_Array;
1865 RadioB_ArrayLen = RadioB_GM_ArrayLength;
1869 Rtl819XRadioB_Array_Table = Rtl819XRadioB_Array;
1870 RadioB_ArrayLen = RadioB_ArrayLength;
1873 rtStatus = RT_STATUS_SUCCESS;
1875 // When initialization, we want the delay function(mdelay(), delay_us()
1876 // ==> actually we call PlatformStallExecution()) to do NdisStallExecution()
1877 // [busy wait] instead of NdisMSleep(). So we acquire RT_INITIAL_SPINLOCK
1878 // to run at Dispatch level to achive it.
1879 //cosa PlatformAcquireSpinLock(Adapter, RT_INITIAL_SPINLOCK);
1883 for(i = 0;i<RadioA_ArrayLen; i=i+2){
1884 if(Rtl819XRadioA_Array_Table[i] == 0xfe)
1885 { // Deay specific ms. Only RF configuration require delay.
1886 //#if (DEV_BUS_TYPE == USB_INTERFACE)
1893 else if (Rtl819XRadioA_Array_Table[i] == 0xfd)
1895 else if (Rtl819XRadioA_Array_Table[i] == 0xfc)
1897 else if (Rtl819XRadioA_Array_Table[i] == 0xfb)
1899 //PlatformStallExecution(50);
1900 else if (Rtl819XRadioA_Array_Table[i] == 0xfa)
1902 else if (Rtl819XRadioA_Array_Table[i] == 0xf9)
1906 rtl8192_phy_SetRFReg(dev, eRFPath, Rtl819XRadioA_Array_Table[i], bRFRegOffsetMask, Rtl819XRadioA_Array_Table[i+1]);
1911 for(i = 0;i<RadioB_ArrayLen; i=i+2){
1912 if(Rtl819XRadioB_Array_Table[i] == 0xfe)
1913 { // Deay specific ms. Only RF configuration require delay.
1914 //#if (DEV_BUS_TYPE == USB_INTERFACE)
1921 else if (Rtl819XRadioB_Array_Table[i] == 0xfd)
1923 else if (Rtl819XRadioB_Array_Table[i] == 0xfc)
1925 else if (Rtl819XRadioB_Array_Table[i] == 0xfb)
1927 else if (Rtl819XRadioB_Array_Table[i] == 0xfa)
1929 else if (Rtl819XRadioB_Array_Table[i] == 0xf9)
1933 rtl8192_phy_SetRFReg(dev, eRFPath, Rtl819XRadioB_Array_Table[i], bRFRegOffsetMask, Rtl819XRadioB_Array_Table[i+1]);
1949 /*-----------------------------------------------------------------------------
1950 * Function: PHY_CheckBBAndRFOK()
1952 * Overview: This function is write register and then readback to make sure whether
1953 * BB[PHY0, PHY1], RF[Patha, path b, path c, path d] is Ok
1955 * Input: PADAPTER Adapter
1956 * HW90_BLOCK_E CheckBlock
1957 * RF90_RADIO_PATH_E eRFPath // it is used only when CheckBlock is HW90_BLOCK_RF
1961 * Return: RT_STATUS_SUCCESS: PHY is OK
1963 * Note: This function may be removed in the ASIC
1964 *---------------------------------------------------------------------------*/
1965 //in 8256 phy_RF8256_Config_HardCode
1966 //but we don't use it temp
1969 struct net_device* dev,
1970 HW90_BLOCK_E CheckBlock,
1971 RF90_RADIO_PATH_E eRFPath
1974 //struct r8192_priv *priv = ieee80211_priv(dev);
1975 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
1976 u32 i, CheckTimes = 4,ulRegRead = 0;
1978 u32 WriteData[] = {0xfffff027, 0xaa55a02f, 0x00000027, 0x55aa502f};
1980 // Initialize register address offset to be checked
1981 WriteAddr[HW90_BLOCK_MAC] = 0x100;
1982 WriteAddr[HW90_BLOCK_PHY0] = 0x900;
1983 WriteAddr[HW90_BLOCK_PHY1] = 0x800;
1984 WriteAddr[HW90_BLOCK_RF] = 0x3;
1986 for(i=0 ; i < CheckTimes ; i++)
1990 // Write Data to register and readback
1994 case HW90_BLOCK_MAC:
1995 //RT_ASSERT(FALSE, ("PHY_CheckBBRFOK(): Never Write 0x100 here!"));
1996 RT_TRACE(COMP_INIT, "PHY_CheckBBRFOK(): Never Write 0x100 here!\n");
1999 case HW90_BLOCK_PHY0:
2000 case HW90_BLOCK_PHY1:
2001 write_nic_dword(dev, WriteAddr[CheckBlock], WriteData[i]);
2002 ulRegRead = read_nic_dword(dev, WriteAddr[CheckBlock]);
2006 // When initialization, we want the delay function(mdelay(), delay_us()
2007 // ==> actually we call PlatformStallExecution()) to do NdisStallExecution()
2008 // [busy wait] instead of NdisMSleep(). So we acquire RT_INITIAL_SPINLOCK
2009 // to run at Dispatch level to achive it.
2010 //cosa PlatformAcquireSpinLock(dev, RT_INITIAL_SPINLOCK);
2011 WriteData[i] &= 0xfff;
2012 rtl8192_phy_SetRFReg(dev, eRFPath, WriteAddr[HW90_BLOCK_RF], bRFRegOffsetMask, WriteData[i]);
2013 // TODO: we should not delay for such a long time. Ask SD3
2015 ulRegRead = rtl8192_phy_QueryRFReg(dev, eRFPath, WriteAddr[HW90_BLOCK_RF], bMaskDWord);
2017 //cosa PlatformReleaseSpinLock(dev, RT_INITIAL_SPINLOCK);
2021 rtStatus = RT_STATUS_FAILURE;
2027 // Check whether readback data is correct
2029 if(ulRegRead != WriteData[i])
2031 //RT_TRACE(COMP_FPGA, ("ulRegRead: %x, WriteData: %x \n", ulRegRead, WriteData[i]));
2032 RT_TRACE(COMP_ERR, "read back error(read:%x, write:%x)\n", ulRegRead, WriteData[i]);
2033 rtStatus = RT_STATUS_FAILURE;
2041 //no use temp in windows driver
2044 PHY_SetRFPowerState8192SUsb(
2045 struct net_device* dev,
2046 RF_POWER_STATE RFPowerState
2049 struct r8192_priv *priv = ieee80211_priv(dev);
2050 bool WaitShutDown = FALSE;
2052 //RF90_RADIO_PATH_E eRFPath;
2054 BB_REGISTER_DEFINITION_T *pPhyReg;
2056 if(priv->SetRFPowerStateInProgress == TRUE)
2059 priv->SetRFPowerStateInProgress = TRUE;
2061 // TODO: Emily, 2006.11.21, we should rewrite this function
2063 if(RFPowerState==RF_SHUT_DOWN)
2065 RFPowerState=RF_OFF;
2070 priv->RFPowerState = RFPowerState;
2071 switch( priv->rf_chip )
2075 switch( RFPowerState )
2089 switch( RFPowerState )
2098 for(eRFPath=(RF90_RADIO_PATH_E)RF90_PATH_A; eRFPath < RF90_PATH_MAX; eRFPath++)
2100 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
2103 pPhyReg = &priv->PHYRegDef[eRFPath];
2104 rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV, bRFSI_RFENV);
2105 rtl8192_setBBreg(dev, pPhyReg->rfintfo, bRFSI_RFENV, 0);
2113 }// switch( priv->rf_chip )
2115 priv->SetRFPowerStateInProgress = FALSE;
2120 //no use temp in windows driver
2122 PHY_UpdateInitialGain(
2123 struct net_device* dev
2126 struct r8192_priv *priv = ieee80211_priv(dev);
2127 //unsigned char *IGTable;
2128 //u8 DIG_CurrentInitialGain = 4;
2130 switch(priv->rf_chip)
2143 RT_TRACE(COMP_DBG, "PHY_UpdateInitialGain(): unknown rf_chip: %#X\n", priv->rf_chip);
2149 //YJ,modified,090107
2150 void PHY_GetHWRegOriginalValue(struct net_device* dev)
2152 struct r8192_priv *priv = ieee80211_priv(dev);
2154 // read tx power offset
2156 priv->MCSTxPowerLevelOriginalOffset[0] =
2157 rtl8192_QueryBBReg(dev, rTxAGC_Rate18_06, bMaskDWord);
2158 priv->MCSTxPowerLevelOriginalOffset[1] =
2159 rtl8192_QueryBBReg(dev, rTxAGC_Rate54_24, bMaskDWord);
2160 priv->MCSTxPowerLevelOriginalOffset[2] =
2161 rtl8192_QueryBBReg(dev, rTxAGC_Mcs03_Mcs00, bMaskDWord);
2162 priv->MCSTxPowerLevelOriginalOffset[3] =
2163 rtl8192_QueryBBReg(dev, rTxAGC_Mcs07_Mcs04, bMaskDWord);
2164 priv->MCSTxPowerLevelOriginalOffset[4] =
2165 rtl8192_QueryBBReg(dev, rTxAGC_Mcs11_Mcs08, bMaskDWord);
2166 priv->MCSTxPowerLevelOriginalOffset[5] =
2167 rtl8192_QueryBBReg(dev, rTxAGC_Mcs15_Mcs12, bMaskDWord);
2170 priv->MCSTxPowerLevelOriginalOffset[6] =
2171 rtl8192_QueryBBReg(dev, rTxAGC_CCK_Mcs32, bMaskDWord);
2172 RT_TRACE(COMP_INIT, "Legacy OFDM =%08x/%08x HT_OFDM=%08x/%08x/%08x/%08x\n",
2173 priv->MCSTxPowerLevelOriginalOffset[0], priv->MCSTxPowerLevelOriginalOffset[1] ,
2174 priv->MCSTxPowerLevelOriginalOffset[2], priv->MCSTxPowerLevelOriginalOffset[3] ,
2175 priv->MCSTxPowerLevelOriginalOffset[4], priv->MCSTxPowerLevelOriginalOffset[5] );
2177 // read rx initial gain
2178 priv->DefaultInitialGain[0] = rtl8192_QueryBBReg(dev, rOFDM0_XAAGCCore1, bMaskByte0);
2179 priv->DefaultInitialGain[1] = rtl8192_QueryBBReg(dev, rOFDM0_XBAGCCore1, bMaskByte0);
2180 priv->DefaultInitialGain[2] = rtl8192_QueryBBReg(dev, rOFDM0_XCAGCCore1, bMaskByte0);
2181 priv->DefaultInitialGain[3] = rtl8192_QueryBBReg(dev, rOFDM0_XDAGCCore1, bMaskByte0);
2182 RT_TRACE(COMP_INIT, "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x) \n",
2183 priv->DefaultInitialGain[0], priv->DefaultInitialGain[1],
2184 priv->DefaultInitialGain[2], priv->DefaultInitialGain[3]);
2187 priv->framesync = rtl8192_QueryBBReg(dev, rOFDM0_RxDetector3, bMaskByte0);
2188 priv->framesyncC34 = rtl8192_QueryBBReg(dev, rOFDM0_RxDetector2, bMaskDWord);
2189 RT_TRACE(COMP_INIT, "Default framesync (0x%x) = 0x%x \n",
2190 rOFDM0_RxDetector3, priv->framesync);
2192 //YJ,modified,090107,end
2197 * Function: phy_InitBBRFRegisterDefinition
2199 * OverView: Initialize Register definition offset for Radio Path A/B/C/D
2206 * Note: The initialization value is constant and it should never be changes
2209 static void phy_InitBBRFRegisterDefinition( struct net_device* dev)
2211 struct r8192_priv *priv = ieee80211_priv(dev);
2213 // RF Interface Sowrtware Control
2214 priv->PHYRegDef[RF90_PATH_A].rfintfs = rFPGA0_XAB_RFInterfaceSW; // 16 LSBs if read 32-bit from 0x870
2215 priv->PHYRegDef[RF90_PATH_B].rfintfs = rFPGA0_XAB_RFInterfaceSW; // 16 MSBs if read 32-bit from 0x870 (16-bit for 0x872)
2216 priv->PHYRegDef[RF90_PATH_C].rfintfs = rFPGA0_XCD_RFInterfaceSW;// 16 LSBs if read 32-bit from 0x874
2217 priv->PHYRegDef[RF90_PATH_D].rfintfs = rFPGA0_XCD_RFInterfaceSW;// 16 MSBs if read 32-bit from 0x874 (16-bit for 0x876)
2219 // RF Interface Readback Value
2220 priv->PHYRegDef[RF90_PATH_A].rfintfi = rFPGA0_XAB_RFInterfaceRB; // 16 LSBs if read 32-bit from 0x8E0
2221 priv->PHYRegDef[RF90_PATH_B].rfintfi = rFPGA0_XAB_RFInterfaceRB;// 16 MSBs if read 32-bit from 0x8E0 (16-bit for 0x8E2)
2222 priv->PHYRegDef[RF90_PATH_C].rfintfi = rFPGA0_XCD_RFInterfaceRB;// 16 LSBs if read 32-bit from 0x8E4
2223 priv->PHYRegDef[RF90_PATH_D].rfintfi = rFPGA0_XCD_RFInterfaceRB;// 16 MSBs if read 32-bit from 0x8E4 (16-bit for 0x8E6)
2225 // RF Interface Output (and Enable)
2226 priv->PHYRegDef[RF90_PATH_A].rfintfo = rFPGA0_XA_RFInterfaceOE; // 16 LSBs if read 32-bit from 0x860
2227 priv->PHYRegDef[RF90_PATH_B].rfintfo = rFPGA0_XB_RFInterfaceOE; // 16 LSBs if read 32-bit from 0x864
2228 priv->PHYRegDef[RF90_PATH_C].rfintfo = rFPGA0_XC_RFInterfaceOE;// 16 LSBs if read 32-bit from 0x868
2229 priv->PHYRegDef[RF90_PATH_D].rfintfo = rFPGA0_XD_RFInterfaceOE;// 16 LSBs if read 32-bit from 0x86C
2231 // RF Interface (Output and) Enable
2232 priv->PHYRegDef[RF90_PATH_A].rfintfe = rFPGA0_XA_RFInterfaceOE; // 16 MSBs if read 32-bit from 0x860 (16-bit for 0x862)
2233 priv->PHYRegDef[RF90_PATH_B].rfintfe = rFPGA0_XB_RFInterfaceOE; // 16 MSBs if read 32-bit from 0x864 (16-bit for 0x866)
2234 priv->PHYRegDef[RF90_PATH_C].rfintfe = rFPGA0_XC_RFInterfaceOE;// 16 MSBs if read 32-bit from 0x86A (16-bit for 0x86A)
2235 priv->PHYRegDef[RF90_PATH_D].rfintfe = rFPGA0_XD_RFInterfaceOE;// 16 MSBs if read 32-bit from 0x86C (16-bit for 0x86E)
2237 //Addr of LSSI. Wirte RF register by driver
2238 priv->PHYRegDef[RF90_PATH_A].rf3wireOffset = rFPGA0_XA_LSSIParameter; //LSSI Parameter
2239 priv->PHYRegDef[RF90_PATH_B].rf3wireOffset = rFPGA0_XB_LSSIParameter;
2240 priv->PHYRegDef[RF90_PATH_C].rf3wireOffset = rFPGA0_XC_LSSIParameter;
2241 priv->PHYRegDef[RF90_PATH_D].rf3wireOffset = rFPGA0_XD_LSSIParameter;
2244 priv->PHYRegDef[RF90_PATH_A].rfLSSI_Select = rFPGA0_XAB_RFParameter; //BB Band Select
2245 priv->PHYRegDef[RF90_PATH_B].rfLSSI_Select = rFPGA0_XAB_RFParameter;
2246 priv->PHYRegDef[RF90_PATH_C].rfLSSI_Select = rFPGA0_XCD_RFParameter;
2247 priv->PHYRegDef[RF90_PATH_D].rfLSSI_Select = rFPGA0_XCD_RFParameter;
2249 // Tx AGC Gain Stage (same for all path. Should we remove this?)
2250 priv->PHYRegDef[RF90_PATH_A].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
2251 priv->PHYRegDef[RF90_PATH_B].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
2252 priv->PHYRegDef[RF90_PATH_C].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
2253 priv->PHYRegDef[RF90_PATH_D].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
2255 // Tranceiver A~D HSSI Parameter-1
2256 priv->PHYRegDef[RF90_PATH_A].rfHSSIPara1 = rFPGA0_XA_HSSIParameter1; //wire control parameter1
2257 priv->PHYRegDef[RF90_PATH_B].rfHSSIPara1 = rFPGA0_XB_HSSIParameter1; //wire control parameter1
2258 priv->PHYRegDef[RF90_PATH_C].rfHSSIPara1 = rFPGA0_XC_HSSIParameter1; //wire control parameter1
2259 priv->PHYRegDef[RF90_PATH_D].rfHSSIPara1 = rFPGA0_XD_HSSIParameter1; //wire control parameter1
2261 // Tranceiver A~D HSSI Parameter-2
2262 priv->PHYRegDef[RF90_PATH_A].rfHSSIPara2 = rFPGA0_XA_HSSIParameter2; //wire control parameter2
2263 priv->PHYRegDef[RF90_PATH_B].rfHSSIPara2 = rFPGA0_XB_HSSIParameter2; //wire control parameter2
2264 priv->PHYRegDef[RF90_PATH_C].rfHSSIPara2 = rFPGA0_XC_HSSIParameter2; //wire control parameter2
2265 priv->PHYRegDef[RF90_PATH_D].rfHSSIPara2 = rFPGA0_XD_HSSIParameter2; //wire control parameter1
2267 // RF switch Control
2268 priv->PHYRegDef[RF90_PATH_A].rfSwitchControl = rFPGA0_XAB_SwitchControl; //TR/Ant switch control
2269 priv->PHYRegDef[RF90_PATH_B].rfSwitchControl = rFPGA0_XAB_SwitchControl;
2270 priv->PHYRegDef[RF90_PATH_C].rfSwitchControl = rFPGA0_XCD_SwitchControl;
2271 priv->PHYRegDef[RF90_PATH_D].rfSwitchControl = rFPGA0_XCD_SwitchControl;
2274 priv->PHYRegDef[RF90_PATH_A].rfAGCControl1 = rOFDM0_XAAGCCore1;
2275 priv->PHYRegDef[RF90_PATH_B].rfAGCControl1 = rOFDM0_XBAGCCore1;
2276 priv->PHYRegDef[RF90_PATH_C].rfAGCControl1 = rOFDM0_XCAGCCore1;
2277 priv->PHYRegDef[RF90_PATH_D].rfAGCControl1 = rOFDM0_XDAGCCore1;
2280 priv->PHYRegDef[RF90_PATH_A].rfAGCControl2 = rOFDM0_XAAGCCore2;
2281 priv->PHYRegDef[RF90_PATH_B].rfAGCControl2 = rOFDM0_XBAGCCore2;
2282 priv->PHYRegDef[RF90_PATH_C].rfAGCControl2 = rOFDM0_XCAGCCore2;
2283 priv->PHYRegDef[RF90_PATH_D].rfAGCControl2 = rOFDM0_XDAGCCore2;
2286 priv->PHYRegDef[RF90_PATH_A].rfRxIQImbalance = rOFDM0_XARxIQImbalance;
2287 priv->PHYRegDef[RF90_PATH_B].rfRxIQImbalance = rOFDM0_XBRxIQImbalance;
2288 priv->PHYRegDef[RF90_PATH_C].rfRxIQImbalance = rOFDM0_XCRxIQImbalance;
2289 priv->PHYRegDef[RF90_PATH_D].rfRxIQImbalance = rOFDM0_XDRxIQImbalance;
2292 priv->PHYRegDef[RF90_PATH_A].rfRxAFE = rOFDM0_XARxAFE;
2293 priv->PHYRegDef[RF90_PATH_B].rfRxAFE = rOFDM0_XBRxAFE;
2294 priv->PHYRegDef[RF90_PATH_C].rfRxAFE = rOFDM0_XCRxAFE;
2295 priv->PHYRegDef[RF90_PATH_D].rfRxAFE = rOFDM0_XDRxAFE;
2298 priv->PHYRegDef[RF90_PATH_A].rfTxIQImbalance = rOFDM0_XATxIQImbalance;
2299 priv->PHYRegDef[RF90_PATH_B].rfTxIQImbalance = rOFDM0_XBTxIQImbalance;
2300 priv->PHYRegDef[RF90_PATH_C].rfTxIQImbalance = rOFDM0_XCTxIQImbalance;
2301 priv->PHYRegDef[RF90_PATH_D].rfTxIQImbalance = rOFDM0_XDTxIQImbalance;
2304 priv->PHYRegDef[RF90_PATH_A].rfTxAFE = rOFDM0_XATxAFE;
2305 priv->PHYRegDef[RF90_PATH_B].rfTxAFE = rOFDM0_XBTxAFE;
2306 priv->PHYRegDef[RF90_PATH_C].rfTxAFE = rOFDM0_XCTxAFE;
2307 priv->PHYRegDef[RF90_PATH_D].rfTxAFE = rOFDM0_XDTxAFE;
2309 // Tranceiver LSSI Readback SI mode
2310 priv->PHYRegDef[RF90_PATH_A].rfLSSIReadBack = rFPGA0_XA_LSSIReadBack;
2311 priv->PHYRegDef[RF90_PATH_B].rfLSSIReadBack = rFPGA0_XB_LSSIReadBack;
2312 priv->PHYRegDef[RF90_PATH_C].rfLSSIReadBack = rFPGA0_XC_LSSIReadBack;
2313 priv->PHYRegDef[RF90_PATH_D].rfLSSIReadBack = rFPGA0_XD_LSSIReadBack;
2315 // Tranceiver LSSI Readback PI mode
2316 priv->PHYRegDef[RF90_PATH_A].rfLSSIReadBackPi = TransceiverA_HSPI_Readback;
2317 priv->PHYRegDef[RF90_PATH_B].rfLSSIReadBackPi = TransceiverB_HSPI_Readback;
2318 //pHalData->PHYRegDef[RF90_PATH_C].rfLSSIReadBackPi = rFPGA0_XC_LSSIReadBack;
2319 //pHalData->PHYRegDef[RF90_PATH_D].rfLSSIReadBackPi = rFPGA0_XD_LSSIReadBack;
2325 // Description: Change RF power state.
2327 // Assumption: This function must be executed in re-schdulable context,
2328 // ie. PASSIVE_LEVEL.
2330 // 050823, by rcnjko.
2331 //not understand it seem's use in init
2332 //SetHwReg8192SUsb--->HalFunc.SetHwRegHandler
2333 bool PHY_SetRFPowerState(struct net_device* dev, RT_RF_POWER_STATE eRFPowerState)
2335 struct r8192_priv *priv = ieee80211_priv(dev);
2336 bool bResult = FALSE;
2338 RT_TRACE(COMP_RF, "---------> PHY_SetRFPowerState(): eRFPowerState(%d)\n", eRFPowerState);
2340 if(eRFPowerState == priv->ieee80211->eRFPowerState)
2342 RT_TRACE(COMP_RF, "<--------- PHY_SetRFPowerState(): discard the request for eRFPowerState(%d) is the same.\n", eRFPowerState);
2346 bResult = phy_SetRFPowerState8192SU(dev, eRFPowerState);
2348 RT_TRACE(COMP_RF, "<--------- PHY_SetRFPowerState(): bResult(%d)\n", bResult);
2354 static bool phy_SetRFPowerState8192SU(struct net_device* dev,RT_RF_POWER_STATE eRFPowerState)
2356 struct r8192_priv *priv = ieee80211_priv(dev);
2357 bool bResult = TRUE;
2362 if(priv->SetRFPowerStateInProgress == TRUE)
2365 priv->SetRFPowerStateInProgress = TRUE;
2367 switch(priv->rf_chip )
2370 switch( eRFPowerState )
2373 write_nic_dword(dev, WFM5, FW_BB_RESET_ENABLE);
2374 write_nic_word(dev, CMDR, 0x37FC);
2375 write_nic_byte(dev, PHY_CCA, 0x3);
2376 write_nic_byte(dev, TXPAUSE, 0x00);
2377 write_nic_byte(dev, SPS1_CTRL, 0x64);
2381 // In current solution, RFSleep=RFOff in order to save power under 802.11 power save.
2382 // By Bruce, 2008-01-16.
2386 if (priv->ieee80211->eRFPowerState == eRfSleep || priv->ieee80211->eRFPowerState == eRfOff)
2389 // Make sure BusyQueue is empty befor turn off RFE pwoer.
2390 for(QueueID = 0, i = 0; QueueID < MAX_TX_QUEUE; )
2392 if(RTIsListEmpty(&Adapter->TcbBusyQueue[QueueID]))
2399 RT_TRACE(COMP_POWER, "eRf Off/Sleep: %d times TcbBusyQueue[%d] !=0 before doze!\n", (i+1), QueueID);
2404 if(i >= MAX_DOZE_WAITING_TIMES_9x)
2406 RT_TRACE(COMP_POWER, "\n\n\n SetZebraRFPowerState8185B(): eRfOff: %d times TcbBusyQueue[%d] != 0 !!!\n\n\n", MAX_DOZE_WAITING_TIMES_9x, QueueID);
2412 //RF Off/Sleep sequence. Designed/tested from SD4 Scott, SD1 Grent and Jonbon.
2413 // Added by Bruce, 2008-11-22.
2415 //==================================================================
2416 // (0) Disable FW BB reset checking
2417 write_nic_dword(dev, WFM5, FW_BB_RESET_DISABLE);
2419 // (1) Switching Power Supply Register : Disable LD12 & SW12 (for IT)
2420 u1bTmp = read_nic_byte(dev, LDOV12D_CTRL);
2422 write_nic_byte(dev, LDOV12D_CTRL, u1bTmp);
2424 write_nic_byte(dev, SPS1_CTRL, 0x0);
2425 write_nic_byte(dev, TXPAUSE, 0xFF);
2427 // (2) MAC Tx/Rx enable, BB enable, CCK/OFDM enable
2428 write_nic_word(dev, CMDR, 0x77FC);
2429 write_nic_byte(dev, PHY_CCA, 0x0);
2432 write_nic_word(dev, CMDR, 0x37FC);
2435 write_nic_word(dev, CMDR, 0x77FC);
2438 // (3) Reset BB TRX blocks
2439 write_nic_word(dev, CMDR, 0x57FC);
2444 //RT_ASSERT(FALSE, ("phy_SetRFPowerState8192SU(): unknow state to set: 0x%X!!!\n", eRFPowerState));
2450 priv->ieee80211->eRFPowerState = eRFPowerState;
2454 // Update current RF state variable.
2455 priv->ieee80211->eRFPowerState = eRFPowerState;
2457 switch(priv->rf_chip )
2460 switch(priv->ieee80211->eRFPowerState)
2464 //If Rf off reason is from IPS, Led should blink with no link, by Maddest 071015
2466 if(pMgntInfo->RfOffReason==RF_CHANGE_BY_IPS )
2468 dev->HalFunc.LedControlHandler(dev,LED_CTL_NO_LINK);
2472 // Turn off LED if RF is not ON.
2473 dev->HalFunc.LedControlHandler(dev, LED_CTL_POWER_OFF);
2478 // Turn on RF we are still linked, which might happen when
2479 // we quickly turn off and on HW RF. 2006.05.12, by rcnjko.
2480 if( pMgntInfo->bMediaConnect == TRUE )
2482 dev->HalFunc.LedControlHandler(dev, LED_CTL_LINK);
2486 // Turn off LED if RF is not ON.
2487 dev->HalFunc.LedControlHandler(dev, LED_CTL_NO_LINK);
2499 RT_TRACE(COMP_RF, "phy_SetRFPowerState8192SU(): Unknown RF type\n");
2504 priv->SetRFPowerStateInProgress = FALSE;
2509 /*-----------------------------------------------------------------------------
2510 * Function: GetTxPowerLevel8190()
2512 * Overview: This function is export to "common" moudule
2514 * Input: PADAPTER Adapter
2515 * psByte Power Level
2521 *---------------------------------------------------------------------------*/
2524 PHY_GetTxPowerLevel8192S(
2525 struct net_device* dev,
2529 struct r8192_priv *priv = ieee80211_priv(dev);
2533 // Because the Tx power indexes are different, we report the maximum of them to
2534 // meet the CCX TPC request. By Bruce, 2008-01-31.
2538 TxPwrLevel = priv->CurrentCckTxPwrIdx;
2539 TxPwrDbm = phy_TxPwrIdxToDbm(dev, WIRELESS_MODE_B, TxPwrLevel);
2542 TxPwrLevel = priv->CurrentOfdm24GTxPwrIdx + priv->LegacyHTTxPowerDiff;
2544 // Compare with Legacy OFDM Tx power.
2545 if(phy_TxPwrIdxToDbm(dev, WIRELESS_MODE_G, TxPwrLevel) > TxPwrDbm)
2546 TxPwrDbm = phy_TxPwrIdxToDbm(dev, WIRELESS_MODE_G, TxPwrLevel);
2549 TxPwrLevel = priv->CurrentOfdm24GTxPwrIdx;
2551 // Compare with HT OFDM Tx power.
2552 if(phy_TxPwrIdxToDbm(dev, WIRELESS_MODE_N_24G, TxPwrLevel) > TxPwrDbm)
2553 TxPwrDbm = phy_TxPwrIdxToDbm(dev, WIRELESS_MODE_N_24G, TxPwrLevel);
2555 *powerlevel = TxPwrDbm;
2558 /*-----------------------------------------------------------------------------
2559 * Function: SetTxPowerLevel8190()
2561 * Overview: This function is export to "HalCommon" moudule
2563 * Input: PADAPTER Adapter
2569 * 2008/11/04 MHC We remove EEPROM_93C56.
2570 * We need to move CCX relative code to independet file.
2571 * 2009/01/21 MHC Support new EEPROM format from SD3 requirement.
2572 *---------------------------------------------------------------------------*/
2573 void PHY_SetTxPowerLevel8192S(struct net_device* dev, u8 channel)
2575 struct r8192_priv *priv = ieee80211_priv(dev);
2576 //HAL_DATA_TYPE *pHalData = GET_HAL_DATA(dev);
2577 u8 powerlevel = (u8)EEPROM_Default_TxPower, powerlevelOFDM24G = 0x10;
2578 s8 ant_pwr_diff = 0;
2580 u8 index = (channel -1);
2581 // 2009/01/22 MH Add for new EEPROM format from SD3
2582 u8 pwrdiff[2] = {0};
2583 u8 ht20pwr[2] = {0}, ht40pwr[2] = {0};
2584 u8 rfpath = 0, rfpathnum = 2;
2586 if(priv->bTXPowerDataReadFromEEPORM == FALSE)
2590 // Read predefined TX power index in EEPROM
2592 // if(priv->epromtype == EPROM_93c46)
2595 // Mainly we use RF-A Tx Power to write the Tx Power registers, but the RF-B Tx
2596 // Power must be calculated by the antenna diff.
2597 // So we have to rewrite Antenna gain offset register here.
2598 // Please refer to BB register 0x80c
2600 // 2. For OFDM 1T or 2T
2604 powerlevel = priv->RfTxPwrLevelCck[0][index];
2606 if (priv->rf_type == RF_1T2R || priv->rf_type == RF_1T1R)
2608 // Read HT 40 OFDM TX power
2609 powerlevelOFDM24G = priv->RfTxPwrLevelOfdm1T[0][index];
2610 // RF B HT OFDM pwr-RFA HT OFDM pwr
2611 // Only one RF we need not to decide B <-> A pwr diff
2613 // Legacy<->HT pwr diff, we only care about path A.
2615 // We only assume 1T as RF path A
2617 ht20pwr[0] = ht40pwr[0] = priv->RfTxPwrLevelOfdm1T[0][index];
2619 else if (priv->rf_type == RF_2T2R)
2621 // Read HT 40 OFDM TX power
2622 powerlevelOFDM24G = priv->RfTxPwrLevelOfdm2T[0][index];
2623 // RF B HT OFDM pwr-RFA HT OFDM pwr
2624 ant_pwr_diff = priv->RfTxPwrLevelOfdm2T[1][index] -
2625 priv->RfTxPwrLevelOfdm2T[0][index];
2626 // RF B (HT OFDM pwr+legacy-ht-diff) -(RFA HT OFDM pwr+legacy-ht-diff)
2627 // We can not handle Path B&A HT/Legacy pwr diff for 92S now.
2629 //RTPRINT(FPHY, PHY_TXPWR, ("CH-%d HT40 A/B Pwr index = %x/%x(%d/%d)\n",
2630 //channel, priv->RfTxPwrLevelOfdm2T[0][index],
2631 //priv->RfTxPwrLevelOfdm2T[1][index],
2632 //priv->RfTxPwrLevelOfdm2T[0][index],
2633 //priv->RfTxPwrLevelOfdm2T[1][index]));
2635 ht20pwr[0] = ht40pwr[0] = priv->RfTxPwrLevelOfdm2T[0][index];
2636 ht20pwr[1] = ht40pwr[1] = priv->RfTxPwrLevelOfdm2T[1][index];
2640 // 2009/01/21 MH Support new EEPROM format from SD3 requirement
2641 // 2009/02/10 Cosa, Here is only for reg B/C/D to A gain diff.
2643 if (priv->EEPROMVersion == 2) // Defined by SD1 Jong
2645 if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20)
2647 for (rfpath = 0; rfpath < rfpathnum; rfpath++)
2649 // HT 20<->40 pwr diff
2650 pwrdiff[rfpath] = priv->TxPwrHt20Diff[rfpath][index];
2652 // Calculate Antenna pwr diff
2653 if (pwrdiff[rfpath] < 8) // 0~+7
2655 #if 0//cosa, it doesn't need to add the offset here
2657 powerlevelOFDM24G += pwrdiff[rfpath];
2659 ht20pwr[rfpath] += pwrdiff[rfpath];
2661 else // index8-15=-8~-1
2663 #if 0//cosa, it doesn't need to add the offset here
2665 powerlevelOFDM24G -= (15-pwrdiff[rfpath]);
2667 ht20pwr[rfpath] -= (15-pwrdiff[rfpath]);
2671 // RF B HT OFDM pwr-RFA HT OFDM pwr
2672 if (priv->rf_type == RF_2T2R)
2673 ant_pwr_diff = ht20pwr[1] - ht20pwr[0];
2675 //RTPRINT(FPHY, PHY_TXPWR,
2676 //("HT20 to HT40 pwrdiff[A/B]=%d/%d, ant_pwr_diff=%d(B-A=%d-%d)\n",
2677 //pwrdiff[0], pwrdiff[1], ant_pwr_diff, ht20pwr[1], ht20pwr[0]));
2680 // Band Edge scheme is enabled for FCC mode
2681 if (priv->TxPwrbandEdgeFlag == 1/* && pHalData->ChannelPlan == 0*/)
2683 for (rfpath = 0; rfpath < rfpathnum; rfpath++)
2685 pwrdiff[rfpath] = 0;
2686 if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40)
2689 pwrdiff[rfpath] = priv->TxPwrbandEdgeHt40[rfpath][0];
2690 else if (channel >= 9)
2691 pwrdiff[rfpath] = priv->TxPwrbandEdgeHt40[rfpath][1];
2693 pwrdiff[rfpath] = 0;
2695 ht40pwr[rfpath] -= pwrdiff[rfpath];
2697 else if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20)
2700 pwrdiff[rfpath] = priv->TxPwrbandEdgeHt20[rfpath][0];
2701 else if (channel >= 11)
2702 pwrdiff[rfpath] = priv->TxPwrbandEdgeHt20[rfpath][1];
2704 pwrdiff[rfpath] = 0;
2706 ht20pwr[rfpath] -= pwrdiff[rfpath];
2708 #if 0//cosa, it doesn't need to add the offset here
2710 powerlevelOFDM24G -= pwrdiff[rfpath];
2714 if (priv->rf_type == RF_2T2R)
2716 // HT 20/40 must decide if they need to minus BD pwr offset
2717 if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40)
2718 ant_pwr_diff = ht40pwr[1] - ht40pwr[0];
2720 ant_pwr_diff = ht20pwr[1] - ht20pwr[0];
2722 if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20)
2724 if (channel <= 1 || channel >= 11)
2726 //RTPRINT(FPHY, PHY_TXPWR,
2727 //("HT20 Band-edge pwrdiff[A/B]=%d/%d, ant_pwr_diff=%d(B-A=%d-%d)\n",
2728 //pwrdiff[0], pwrdiff[1], ant_pwr_diff, ht20pwr[1], ht20pwr[0]));
2733 if (channel <= 3 || channel >= 9)
2735 //RTPRINT(FPHY, PHY_TXPWR,
2736 //("HT40 Band-edge pwrdiff[A/B]=%d/%d, ant_pwr_diff=%d(B-A=%d-%d)\n",
2737 //pwrdiff[0], pwrdiff[1], ant_pwr_diff, ht40pwr[1], ht40pwr[0]));
2741 #if 0//cosa, useless
2742 // Read HT/Legacy OFDM diff
2743 legacy_ant_pwr_diff= pHalData->TxPwrLegacyHtDiff[RF90_PATH_A][index];
2747 //Cosa added for protection, the reg rFPGA0_TxGainStage
2748 // range is from 7~-8, index = 0x0~0xf
2749 if(ant_pwr_diff > 7)
2751 if(ant_pwr_diff < -8)
2754 //RTPRINT(FPHY, PHY_TXPWR,
2755 //("CCK/HT Power index = %x/%x(%d/%d), ant_pwr_diff=%d\n",
2756 //powerlevel, powerlevelOFDM24G, powerlevel, powerlevelOFDM24G, ant_pwr_diff));
2758 ant_pwr_diff &= 0xf;
2760 // Antenna TX power difference
2761 priv->AntennaTxPwDiff[2] = 0;// RF-D, don't care
2762 priv->AntennaTxPwDiff[1] = 0;// RF-C, don't care
2763 priv->AntennaTxPwDiff[0] = (u8)(ant_pwr_diff); // RF-B
2765 // Antenna gain offset from B/C/D to A
2766 u4RegValue = ( priv->AntennaTxPwDiff[2]<<8 |
2767 priv->AntennaTxPwDiff[1]<<4 |
2768 priv->AntennaTxPwDiff[0] );
2770 // Notify Tx power difference for B/C/D to A!!!
2771 rtl8192_setBBreg(dev, rFPGA0_TxGainStage, (bXBTxAGC|bXCTxAGC|bXDTxAGC), u4RegValue);
2775 // CCX 2 S31, AP control of client transmit power:
2776 // 1. We shall not exceed Cell Power Limit as possible as we can.
2777 // 2. Tolerance is +/- 5dB.
2778 // 3. 802.11h Power Contraint takes higher precedence over CCX Cell Power Limit.
2781 // 1. 802.11h power contraint
2783 // 071011, by rcnjko.
2785 #ifdef TODO //WB, 11h has not implemented now.
2786 if( priv->ieee80211->iw_mode != IW_MODE_INFRA && priv->bWithCcxCellPwr &&
2787 channel == priv->ieee80211->current_network.channel)// & priv->ieee80211->mAssoc )
2789 u8 CckCellPwrIdx = phy_DbmToTxPwrIdx(dev, WIRELESS_MODE_B, priv->CcxCellPwr);
2790 u8 LegacyOfdmCellPwrIdx = phy_DbmToTxPwrIdx(dev, WIRELESS_MODE_G, priv->CcxCellPwr);
2791 u8 OfdmCellPwrIdx = phy_DbmToTxPwrIdx(dev, WIRELESS_MODE_N_24G, priv->CcxCellPwr);
2793 RT_TRACE(COMP_TXAGC,
2794 ("CCX Cell Limit: %d dbm => CCK Tx power index : %d, Legacy OFDM Tx power index : %d, OFDM Tx power index: %d\n",
2795 priv->CcxCellPwr, CckCellPwrIdx, LegacyOfdmCellPwrIdx, OfdmCellPwrIdx));
2796 RT_TRACE(COMP_TXAGC,
2797 ("EEPROM channel(%d) => CCK Tx power index: %d, Legacy OFDM Tx power index : %d, OFDM Tx power index: %d\n",
2798 channel, powerlevel, powerlevelOFDM24G + priv->LegacyHTTxPowerDiff, powerlevelOFDM24G));
2801 if(powerlevel > CckCellPwrIdx)
2802 powerlevel = CckCellPwrIdx;
2803 // Legacy OFDM, HT OFDM
2804 if(powerlevelOFDM24G + priv->LegacyHTTxPowerDiff > LegacyOfdmCellPwrIdx)
2806 if((OfdmCellPwrIdx - priv->LegacyHTTxPowerDiff) > 0)
2808 powerlevelOFDM24G = OfdmCellPwrIdx - priv->LegacyHTTxPowerDiff;
2812 powerlevelOFDM24G = 0;
2816 RT_TRACE(COMP_TXAGC,
2817 ("Altered CCK Tx power index : %d, Legacy OFDM Tx power index: %d, OFDM Tx power index: %d\n",
2818 powerlevel, powerlevelOFDM24G + priv->LegacyHTTxPowerDiff, powerlevelOFDM24G));
2822 priv->CurrentCckTxPwrIdx = powerlevel;
2823 priv->CurrentOfdm24GTxPwrIdx = powerlevelOFDM24G;
2825 switch(priv->rf_chip)
2828 //PHY_SetRF8225CckTxPower(dev, powerlevel);
2829 //PHY_SetRF8225OfdmTxPower(dev, powerlevelOFDM24G);
2834 PHY_SetRF8256CCKTxPower(dev, powerlevel);
2835 PHY_SetRF8256OFDMTxPower(dev, powerlevelOFDM24G);
2840 PHY_RF6052SetCckTxPower(dev, powerlevel);
2841 PHY_RF6052SetOFDMTxPower(dev, powerlevelOFDM24G);
2854 // Update transmit power level of all channel supported.
2858 // By Bruce, 2008-02-04.
2860 bool PHY_UpdateTxPowerDbm8192S(struct net_device* dev, long powerInDbm)
2862 struct r8192_priv *priv = ieee80211_priv(dev);
2866 // TODO: A mode Tx power.
2867 u8 CckTxPwrIdx = phy_DbmToTxPwrIdx(dev, WIRELESS_MODE_B, powerInDbm);
2868 u8 OfdmTxPwrIdx = phy_DbmToTxPwrIdx(dev, WIRELESS_MODE_N_24G, powerInDbm);
2870 if(OfdmTxPwrIdx - priv->LegacyHTTxPowerDiff > 0)
2871 OfdmTxPwrIdx -= priv->LegacyHTTxPowerDiff;
2875 for(idx = 0; idx < 14; idx++)
2877 priv->TxPowerLevelCCK[idx] = CckTxPwrIdx;
2878 priv->TxPowerLevelCCK_A[idx] = CckTxPwrIdx;
2879 priv->TxPowerLevelCCK_C[idx] = CckTxPwrIdx;
2880 priv->TxPowerLevelOFDM24G[idx] = OfdmTxPwrIdx;
2881 priv->TxPowerLevelOFDM24G_A[idx] = OfdmTxPwrIdx;
2882 priv->TxPowerLevelOFDM24G_C[idx] = OfdmTxPwrIdx;
2884 for (rf_path = 0; rf_path < 2; rf_path++)
2886 priv->RfTxPwrLevelCck[rf_path][idx] = CckTxPwrIdx;
2887 priv->RfTxPwrLevelOfdm1T[rf_path][idx] = \
2888 priv->RfTxPwrLevelOfdm2T[rf_path][idx] = OfdmTxPwrIdx;
2892 PHY_SetTxPowerLevel8192S(dev, priv->chan);
2899 When beacon interval is changed, the values of the
2900 hw registers should be modified.
2901 By tynli, 2008.10.24.
2905 extern void PHY_SetBeaconHwReg( struct net_device* dev, u16 BeaconInterval)
2909 NewBeaconNum = BeaconInterval *32 - 64;
2910 //PlatformEFIOWrite4Byte(Adapter, WFM3+4, NewBeaconNum);
2911 //PlatformEFIOWrite4Byte(Adapter, WFM3, 0xB026007C);
2912 write_nic_dword(dev, WFM3+4, NewBeaconNum);
2913 write_nic_dword(dev, WFM3, 0xB026007C);
2918 // Map dBm into Tx power index according to
2919 // current HW model, for example, RF and PA, and
2920 // current wireless mode.
2921 // By Bruce, 2008-01-29.
2923 static u8 phy_DbmToTxPwrIdx(
2924 struct net_device* dev,
2925 WIRELESS_MODE WirelessMode,
2929 //struct r8192_priv *priv = ieee80211_priv(dev);
2935 // Tested by MP, we found that CCK Index 0 equals to -7dbm, OFDM legacy equals to
2936 // 3dbm, and OFDM HT equals to 0dbm repectively.
2938 // The mapping may be different by different NICs. Do not use this formula for what needs accurate result.
2939 // By Bruce, 2008-01-29.
2941 switch(WirelessMode)
2943 case WIRELESS_MODE_B:
2947 case WIRELESS_MODE_G:
2948 case WIRELESS_MODE_N_24G:
2955 if((PowerInDbm - Offset) > 0)
2957 TxPwrIdx = (u8)((PowerInDbm - Offset) * 2);
2964 // Tx Power Index is too large.
2965 if(TxPwrIdx > MAX_TXPWR_IDX_NMODE_92S)
2966 TxPwrIdx = MAX_TXPWR_IDX_NMODE_92S;
2972 // Map Tx power index into dBm according to
2973 // current HW model, for example, RF and PA, and
2974 // current wireless mode.
2975 // By Bruce, 2008-01-29.
2977 static long phy_TxPwrIdxToDbm(
2978 struct net_device* dev,
2979 WIRELESS_MODE WirelessMode,
2983 //struct r8192_priv *priv = ieee80211_priv(dev);
2988 // Tested by MP, we found that CCK Index 0 equals to -7dbm, OFDM legacy equals to
2989 // 3dbm, and OFDM HT equals to 0dbm repectively.
2991 // The mapping may be different by different NICs. Do not use this formula for what needs accurate result.
2992 // By Bruce, 2008-01-29.
2994 switch(WirelessMode)
2996 case WIRELESS_MODE_B:
3000 case WIRELESS_MODE_G:
3001 case WIRELESS_MODE_N_24G:
3008 PwrOutDbm = TxPwrIdx / 2 + Offset; // Discard the decimal part.
3015 PHY_ScanOperationBackup8192S(
3016 IN PADAPTER Adapter,
3021 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
3022 PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
3024 u1Byte initial_gain;
3030 if(!Adapter->bDriverStopped)
3034 case SCAN_OPT_BACKUP:
3036 // <Roger_Notes> We halt FW DIG and disable high ppower both two DMs here
3037 // and resume both two DMs while scan complete.
3040 Adapter->HalFunc.SetFwCmdHandler(Adapter, FW_CMD_PAUSE_DM_BY_SCAN);
3043 case SCAN_OPT_RESTORE:
3045 // <Roger_Notes> We resume DIG and enable high power both two DMs here and
3046 // recover earlier DIG settings.
3049 Adapter->HalFunc.SetFwCmdHandler(Adapter, FW_CMD_RESUME_DM_BY_SCAN);
3053 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Unknown Scan Backup Operation. \n"));
3061 void PHY_InitialGain8192S(struct net_device* dev,u8 Operation )
3064 //struct r8192_priv *priv = ieee80211_priv(dev);
3068 #if 0 // For 8192s test disable
3069 if(!dev->bDriverStopped)
3074 RT_TRACE(COMP_SCAN, DBG_LOUD, ("IG_Backup, backup the initial gain.\n"));
3075 initial_gain = priv->DefaultInitialGain[0];
3076 BitMask = bMaskByte0;
3077 if(DM_DigTable.Dig_Algorithm == DIG_ALGO_BY_FALSE_ALARM)
3078 PHY_SetMacReg(dev, UFWP, bMaskByte1, 0x8); // FW DIG OFF
3079 pMgntInfo->InitGain_Backup.XAAGCCore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XAAGCCore1, BitMask);
3080 pMgntInfo->InitGain_Backup.XBAGCCore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XBAGCCore1, BitMask);
3081 pMgntInfo->InitGain_Backup.XCAGCCore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XCAGCCore1, BitMask);
3082 pMgntInfo->InitGain_Backup.XDAGCCore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XDAGCCore1, BitMask);
3083 BitMask = bMaskByte2;
3084 pMgntInfo->InitGain_Backup.CCA = (u8)rtl8192_QueryBBReg(dev, rCCK0_CCA, BitMask);
3086 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Scan InitialGainBackup 0xc50 is %x\n",pMgntInfo->InitGain_Backup.XAAGCCore1));
3087 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Scan InitialGainBackup 0xc58 is %x\n",pMgntInfo->InitGain_Backup.XBAGCCore1));
3088 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Scan InitialGainBackup 0xc60 is %x\n",pMgntInfo->InitGain_Backup.XCAGCCore1));
3089 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Scan InitialGainBackup 0xc68 is %x\n",pMgntInfo->InitGain_Backup.XDAGCCore1));
3090 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Scan InitialGainBackup 0xa0a is %x\n",pMgntInfo->InitGain_Backup.CCA));
3092 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Write scan initial gain = 0x%x \n", initial_gain));
3093 write_nic_byte(dev, rOFDM0_XAAGCCore1, initial_gain);
3094 write_nic_byte(dev, rOFDM0_XBAGCCore1, initial_gain);
3095 write_nic_byte(dev, rOFDM0_XCAGCCore1, initial_gain);
3096 write_nic_byte(dev, rOFDM0_XDAGCCore1, initial_gain);
3099 RT_TRACE(COMP_SCAN, DBG_LOUD, ("IG_Restore, restore the initial gain.\n"));
3100 BitMask = 0x7f; //Bit0~ Bit6
3101 if(DM_DigTable.Dig_Algorithm == DIG_ALGO_BY_FALSE_ALARM)
3102 PHY_SetMacReg(dev, UFWP, bMaskByte1, 0x8); // FW DIG OFF
3104 rtl8192_setBBreg(dev, rOFDM0_XAAGCCore1, BitMask, (u32)pMgntInfo->InitGain_Backup.XAAGCCore1);
3105 rtl8192_setBBreg(dev, rOFDM0_XBAGCCore1, BitMask, (u32)pMgntInfo->InitGain_Backup.XBAGCCore1);
3106 rtl8192_setBBreg(dev, rOFDM0_XCAGCCore1, BitMask, (u32)pMgntInfo->InitGain_Backup.XCAGCCore1);
3107 rtl8192_setBBreg(dev, rOFDM0_XDAGCCore1, BitMask, (u32)pMgntInfo->InitGain_Backup.XDAGCCore1);
3108 BitMask = (BIT22|BIT23);
3109 rtl8192_setBBreg(dev, rCCK0_CCA, BitMask, (u32)pMgntInfo->InitGain_Backup.CCA);
3111 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Scan BBInitialGainRestore 0xc50 is %x\n",pMgntInfo->InitGain_Backup.XAAGCCore1));
3112 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Scan BBInitialGainRestore 0xc58 is %x\n",pMgntInfo->InitGain_Backup.XBAGCCore1));
3113 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Scan BBInitialGainRestore 0xc60 is %x\n",pMgntInfo->InitGain_Backup.XCAGCCore1));
3114 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Scan BBInitialGainRestore 0xc68 is %x\n",pMgntInfo->InitGain_Backup.XDAGCCore1));
3115 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Scan BBInitialGainRestore 0xa0a is %x\n",pMgntInfo->InitGain_Backup.CCA));
3117 if(DM_DigTable.Dig_Algorithm == DIG_ALGO_BY_FALSE_ALARM)
3118 PHY_SetMacReg(dev, UFWP, bMaskByte1, 0x1); // FW DIG ON
3121 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Unknown IG Operation. \n"));
3128 /*-----------------------------------------------------------------------------
3129 * Function: SetBWModeCallback8190Pci()
3131 * Overview: Timer callback function for SetSetBWMode
3133 * Input: PRT_TIMER pTimer
3139 * Note: (1) We do not take j mode into consideration now
3140 * (2) Will two workitem of "switch channel" and "switch channel bandwidth" run
3142 *---------------------------------------------------------------------------*/
3143 // use in phy only (in win it's timer)
3144 void PHY_SetBWModeCallback8192S(struct net_device *dev)
3146 struct r8192_priv *priv = ieee80211_priv(dev);
3151 // Added it for 20/40 mhz switch time evaluation by guangan 070531
3153 //u8Byte BeginTime, EndTime;
3156 RT_TRACE(COMP_SWBW, "==>SetBWModeCallback8190Pci() Switch to %s bandwidth\n", \
3157 priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz");
3159 if(priv->rf_chip == RF_PSEUDO_11N)
3161 priv->SetBWModeInProgress= FALSE;
3168 // Added it for 20/40 mhz switch time evaluation by guangan 070531
3169 //NowL = read_nic_dword(dev, TSFR);
3170 //NowH = read_nic_dword(dev, TSFR+4);
3171 //BeginTime = ((u8Byte)NowH << 32) + NowL;
3174 //3//<1>Set MAC register
3176 regBwOpMode = read_nic_byte(dev, BW_OPMODE);
3177 regRRSR_RSC = read_nic_byte(dev, RRSR+2);
3179 switch(priv->CurrentChannelBW)
3181 case HT_CHANNEL_WIDTH_20:
3182 //if(priv->card_8192_version >= VERSION_8192S_BCUT)
3183 // write_nic_byte(dev, rFPGA0_AnalogParameter2, 0x58);
3185 regBwOpMode |= BW_OPMODE_20MHZ;
3186 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
3187 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
3190 case HT_CHANNEL_WIDTH_20_40:
3191 //if(priv->card_8192_version >= VERSION_8192S_BCUT)
3192 // write_nic_byte(dev, rFPGA0_AnalogParameter2, 0x18);
3194 regBwOpMode &= ~BW_OPMODE_20MHZ;
3195 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
3196 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
3197 regRRSR_RSC = (regRRSR_RSC&0x90) |(priv->nCur40MhzPrimeSC<<5);
3198 write_nic_byte(dev, RRSR+2, regRRSR_RSC);
3202 RT_TRACE(COMP_DBG, "SetBWModeCallback8190Pci():\
3203 unknown Bandwidth: %#X\n",priv->CurrentChannelBW);
3208 //3//<2>Set PHY related register
3210 switch(priv->CurrentChannelBW)
3213 case HT_CHANNEL_WIDTH_20:
3214 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x0);
3215 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x0);
3217 // Correct the tx power for CCK rate in 40M. Suggest by YN, 20071207
3218 // It is set in Tx descriptor for 8192x series
3219 //write_nic_dword(dev, rCCK0_TxFilter1, 0x1a1b0000);
3220 //write_nic_dword(dev, rCCK0_TxFilter2, 0x090e1317);
3221 //write_nic_dword(dev, rCCK0_DebugPort, 0x00000204);
3223 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskDWord, 0x1a1b0000);
3224 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, 0x090e1317);
3225 rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskDWord, 0x00000204);
3226 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00300000, 3);
3229 if (priv->card_8192_version >= VERSION_8192S_BCUT)
3230 write_nic_byte(dev, rFPGA0_AnalogParameter2, 0x58);
3236 case HT_CHANNEL_WIDTH_20_40:
3237 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x1);
3238 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x1);
3240 // Correct the tx power for CCK rate in 40M. Suggest by YN, 20071207
3241 //write_nic_dword(dev, rCCK0_TxFilter1, 0x35360000);
3242 //write_nic_dword(dev, rCCK0_TxFilter2, 0x121c252e);
3243 //write_nic_dword(dev, rCCK0_DebugPort, 0x00000409);
3245 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskDWord, 0x35360000);
3246 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, 0x121c252e);
3247 rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskDWord, 0x00000409);
3250 // Set Control channel to upper or lower. These settings are required only for 40MHz
3251 rtl8192_setBBreg(dev, rCCK0_System, bCCKSideBand, (priv->nCur40MhzPrimeSC>>1));
3252 rtl8192_setBBreg(dev, rOFDM1_LSTF, 0xC00, priv->nCur40MhzPrimeSC);
3254 //rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00300000, 3);
3255 if (priv->card_8192_version >= VERSION_8192S_BCUT)
3256 write_nic_byte(dev, rFPGA0_AnalogParameter2, 0x18);
3261 RT_TRACE(COMP_DBG, "SetBWModeCallback8190Pci(): unknown Bandwidth: %#X\n"\
3262 ,priv->CurrentChannelBW);
3266 //Skip over setting of J-mode in BB register here. Default value is "None J mode". Emily 20070315
3268 // Added it for 20/40 mhz switch time evaluation by guangan 070531
3269 //NowL = read_nic_dword(dev, TSFR);
3270 //NowH = read_nic_dword(dev, TSFR+4);
3271 //EndTime = ((u8Byte)NowH << 32) + NowL;
3272 //RT_TRACE(COMP_SCAN, DBG_LOUD, ("SetBWModeCallback8190Pci: time of SetBWMode = %I64d us!\n", (EndTime - BeginTime)));
3274 //3<3>Set RF related register
3275 switch( priv->rf_chip )
3278 //PHY_SetRF8225Bandwidth(dev, priv->CurrentChannelBW);
3282 // Please implement this function in Hal8190PciPhy8256.c
3283 //PHY_SetRF8256Bandwidth(dev, priv->CurrentChannelBW);
3287 // Please implement this function in Hal8190PciPhy8258.c
3288 // PHY_SetRF8258Bandwidth();
3296 PHY_RF6052SetBandwidth(dev, priv->CurrentChannelBW);
3299 printk("Unknown rf_chip: %d\n", priv->rf_chip);
3303 priv->SetBWModeInProgress= FALSE;
3305 RT_TRACE(COMP_SWBW, "<==SetBWModeCallback8190Pci() \n" );
3309 /*-----------------------------------------------------------------------------
3310 * Function: SetBWMode8190Pci()
3312 * Overview: This function is export to "HalCommon" moudule
3314 * Input: PADAPTER Adapter
3315 * HT_CHANNEL_WIDTH Bandwidth //20M or 40M
3321 * Note: We do not take j mode into consideration now
3322 *---------------------------------------------------------------------------*/
3323 //extern void PHY_SetBWMode8192S( struct net_device* dev,
3324 // HT_CHANNEL_WIDTH Bandwidth, // 20M or 40M
3325 // HT_EXTCHNL_OFFSET Offset // Upper, Lower, or Don't care
3326 void rtl8192_SetBWMode(struct net_device *dev, HT_CHANNEL_WIDTH Bandwidth, HT_EXTCHNL_OFFSET Offset)
3328 struct r8192_priv *priv = ieee80211_priv(dev);
3329 HT_CHANNEL_WIDTH tmpBW = priv->CurrentChannelBW;
3332 // Modified it for 20/40 mhz switch by guangan 070531
3336 //if(priv->SwChnlInProgress)
3337 // if(pMgntInfo->bScanInProgress)
3339 // RT_TRACE(COMP_SCAN, DBG_LOUD, ("SetBWMode8190Pci() %s Exit because bScanInProgress!\n",
3340 // Bandwidth == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz"));
3344 // if(priv->SetBWModeInProgress)
3346 // // Modified it for 20/40 mhz switch by guangan 070531
3347 // RT_TRACE(COMP_SCAN, DBG_LOUD, ("SetBWMode8190Pci() %s cancel last timer because SetBWModeInProgress!\n",
3348 // Bandwidth == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz"));
3349 // PlatformCancelTimer(dev, &priv->SetBWModeTimer);
3353 if(priv->SetBWModeInProgress)
3356 priv->SetBWModeInProgress= TRUE;
3358 priv->CurrentChannelBW = Bandwidth;
3360 if(Offset==HT_EXTCHNL_OFFSET_LOWER)
3361 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_UPPER;
3362 else if(Offset==HT_EXTCHNL_OFFSET_UPPER)
3363 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_LOWER;
3365 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
3368 if(!priv->bDriverStopped)
3371 PlatformScheduleWorkItem(&(priv->SetBWModeWorkItem));//SetBWModeCallback8192SUsbWorkItem
3373 PlatformSetTimer(dev, &(priv->SetBWModeTimer), 0);//PHY_SetBWModeCallback8192S
3377 if((priv->up) )// && !(RT_CANNOT_IO(Adapter) && Adapter->bInSetPower) )
3380 PHY_SetBWModeCallback8192S(dev);
3381 #elif defined(RTL8192SU)
3382 SetBWModeCallback8192SUsbWorkItem(dev);
3387 RT_TRACE(COMP_SCAN, "PHY_SetBWMode8192S() SetBWModeInProgress FALSE driver sleep or unload\n");
3388 priv->SetBWModeInProgress= FALSE;
3389 priv->CurrentChannelBW = tmpBW;
3393 // use in phy only (in win it's timer)
3394 void PHY_SwChnlCallback8192S(struct net_device *dev)
3397 struct r8192_priv *priv = ieee80211_priv(dev);
3401 RT_TRACE(COMP_CH, "==>SwChnlCallback8190Pci(), switch to channel %d\n", priv->chan);
3406 if(priv->rf_chip == RF_PSEUDO_11N)
3408 priv->SwChnlInProgress=FALSE;
3409 return; //return immediately if it is peudo-phy
3413 if(!priv->SwChnlInProgress)
3416 //if(!phy_SwChnlStepByStep(dev, priv->CurrentChannel, &priv->SwChnlStage, &priv->SwChnlStep, &delay))
3417 if(!phy_SwChnlStepByStep(dev, priv->chan, &priv->SwChnlStage, &priv->SwChnlStep, &delay))
3422 //PlatformSetTimer(dev, &priv->SwChnlTimer, delay);
3423 //mod_timer(&priv->SwChnlTimer, jiffies + MSECS(delay));
3424 //==>PHY_SwChnlCallback8192S(dev); for 92se
3425 //==>SwChnlCallback8192SUsb(dev) for 92su
3432 priv->SwChnlInProgress=FALSE;
3438 // Call after initialization
3439 //extern void PHY_SwChnl8192S(struct net_device* dev, u8 channel)
3440 u8 rtl8192_phy_SwChnl(struct net_device* dev, u8 channel)
3442 struct r8192_priv *priv = ieee80211_priv(dev);
3443 //u8 tmpchannel =channel;
3444 //bool bResult = false;
3449 if(priv->SwChnlInProgress)
3452 if(priv->SetBWModeInProgress)
3455 //--------------------------------------------
3456 switch(priv->ieee80211->mode)
3458 case WIRELESS_MODE_A:
3459 case WIRELESS_MODE_N_5G:
3461 RT_TRACE(COMP_ERR, "WIRELESS_MODE_A but channel<=14");
3466 case WIRELESS_MODE_B:
3468 RT_TRACE(COMP_ERR, "WIRELESS_MODE_B but channel>14");
3473 case WIRELESS_MODE_G:
3474 case WIRELESS_MODE_N_24G:
3476 RT_TRACE(COMP_ERR, "WIRELESS_MODE_G but channel>14");
3482 ;//RT_TRACE(COMP_ERR, "Invalid WirelessMode(%#x)!!\n", priv->ieee80211->mode);
3485 //--------------------------------------------
3487 priv->SwChnlInProgress = TRUE;
3493 priv->SwChnlStage=0;
3496 if((priv->up))// && !(RT_CANNOT_IO(Adapter) && Adapter->bInSetPower))
3499 PHY_SwChnlCallback8192S(dev);
3500 #elif defined(RTL8192SU)
3501 SwChnlCallback8192SUsbWorkItem(dev);
3506 RT_TRACE(COMP_SCAN, "PHY_SwChnl8192S SwChnlInProgress TRUE schdule workitem done\n");
3510 RT_TRACE(COMP_SCAN, "PHY_SwChnl8192S SwChnlInProgress FALSE schdule workitem error\n");
3511 priv->SwChnlInProgress = false;
3512 priv->CurrentChannel = tmpchannel;
3518 RT_TRACE(COMP_SCAN, "PHY_SwChnl8192S SwChnlInProgress FALSE driver sleep or unload\n");
3519 priv->SwChnlInProgress = false;
3520 //priv->CurrentChannel = tmpchannel;
3528 // Switch channel synchronously. Called by SwChnlByDelayHandler.
3530 // Implemented by Bruce, 2008-02-14.
3531 // The following procedure is operted according to SwChanlCallback8190Pci().
3532 // However, this procedure is performed synchronously which should be running under
3536 void PHY_SwChnlPhy8192S( // Only called during initialize
3537 struct net_device* dev,
3541 struct r8192_priv *priv = ieee80211_priv(dev);
3543 RT_TRACE(COMP_SCAN, "==>PHY_SwChnlPhy8192S(), switch to channel %d.\n", priv->chan);
3547 if(RT_CANNOT_IO(dev))
3551 // Channel Switching is in progress.
3552 if(priv->SwChnlInProgress)
3555 //return immediately if it is peudo-phy
3556 if(priv->rf_chip == RF_PSEUDO_11N)
3558 priv->SwChnlInProgress=FALSE;
3562 priv->SwChnlInProgress = TRUE;
3568 priv->SwChnlStage = 0;
3569 priv->SwChnlStep = 0;
3571 phy_FinishSwChnlNow(dev,channel);
3573 priv->SwChnlInProgress = FALSE;
3578 phy_SetSwChnlCmdArray(
3579 SwChnlCmd* CmdTable,
3590 if(CmdTable == NULL)
3592 //RT_ASSERT(FALSE, ("phy_SetSwChnlCmdArray(): CmdTable cannot be NULL.\n"));
3595 if(CmdTableIdx >= CmdTableSz)
3598 // ("phy_SetSwChnlCmdArray(): Access invalid index, please check size of the table, CmdTableIdx:%d, CmdTableSz:%d\n",
3599 //CmdTableIdx, CmdTableSz));
3603 pCmd = CmdTable + CmdTableIdx;
3604 pCmd->CmdID = CmdID;
3605 pCmd->Para1 = Para1;
3606 pCmd->Para2 = Para2;
3607 pCmd->msDelay = msDelay;
3614 phy_SwChnlStepByStep(
3615 struct net_device* dev,
3622 struct r8192_priv *priv = ieee80211_priv(dev);
3623 //PCHANNEL_ACCESS_SETTING pChnlAccessSetting;
3624 SwChnlCmd PreCommonCmd[MAX_PRECMD_CNT];
3625 u32 PreCommonCmdCnt;
3626 SwChnlCmd PostCommonCmd[MAX_POSTCMD_CNT];
3627 u32 PostCommonCmdCnt;
3628 SwChnlCmd RfDependCmd[MAX_RFDEPENDCMD_CNT];
3630 SwChnlCmd *CurrentCmd = NULL;
3633 //RT_ASSERT((dev != NULL), ("Adapter should not be NULL\n"));
3634 //RT_ASSERT(IsLegalChannel(dev, channel), ("illegal channel: %d\n", channel));
3635 RT_TRACE(COMP_CH, "===========>%s(), channel:%d, stage:%d, step:%d\n", __FUNCTION__, channel, *stage, *step);
3636 //RT_ASSERT((pHalData != NULL), ("pHalData should not be NULL\n"));
3637 if (!IsLegalChannel(priv->ieee80211, channel))
3639 RT_TRACE(COMP_ERR, "=============>set to illegal channel:%d\n", channel);
3640 return true; //return true to tell upper caller function this channel setting is finished! Or it will in while loop.
3643 //pChnlAccessSetting = &Adapter->MgntInfo.Info8185.ChannelAccessSetting;
3644 //RT_ASSERT((pChnlAccessSetting != NULL), ("pChnlAccessSetting should not be NULL\n"));
3646 //for(eRFPath = RF90_PATH_A; eRFPath <priv->NumTotalRFPath; eRFPath++)
3647 //for(eRFPath = 0; eRFPath <priv->NumTotalRFPath; eRFPath++)
3649 // <1> Fill up pre common command.
3650 PreCommonCmdCnt = 0;
3651 phy_SetSwChnlCmdArray(PreCommonCmd, PreCommonCmdCnt++, MAX_PRECMD_CNT,
3652 CmdID_SetTxPowerLevel, 0, 0, 0);
3653 phy_SetSwChnlCmdArray(PreCommonCmd, PreCommonCmdCnt++, MAX_PRECMD_CNT,
3654 CmdID_End, 0, 0, 0);
3656 // <2> Fill up post common command.
3657 PostCommonCmdCnt = 0;
3659 phy_SetSwChnlCmdArray(PostCommonCmd, PostCommonCmdCnt++, MAX_POSTCMD_CNT,
3660 CmdID_End, 0, 0, 0);
3662 // <3> Fill up RF dependent command.
3664 switch( priv->rf_chip )
3667 if (channel < 1 || channel > 14)
3668 RT_TRACE(COMP_ERR, "illegal channel for zebra:%d\n", channel);
3669 //RT_ASSERT((channel >= 1 && channel <= 14), ("illegal channel for Zebra: %d\n", channel));
3670 // 2008/09/04 MH Change channel.
3671 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
3672 CmdID_RF_WriteReg, rRfChannel, channel, 10);
3673 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
3674 CmdID_End, 0, 0, 0);
3678 if (channel < 1 || channel > 14)
3679 RT_TRACE(COMP_ERR, "illegal channel for zebra:%d\n", channel);
3680 // TEST!! This is not the table for 8256!!
3681 //RT_ASSERT((channel >= 1 && channel <= 14), ("illegal channel for Zebra: %d\n", channel));
3682 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
3683 CmdID_RF_WriteReg, rRfChannel, channel, 10);
3684 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
3685 CmdID_End, 0, 0, 0);
3689 if (channel < 1 || channel > 14)
3690 RT_TRACE(COMP_ERR, "illegal channel for zebra:%d\n", channel);
3691 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
3692 CmdID_RF_WriteReg, RF_CHNLBW, channel, 10);
3693 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
3694 CmdID_End, 0, 0, 0);
3701 //RT_ASSERT(FALSE, ("Unknown rf_chip: %d\n", priv->rf_chip));
3711 CurrentCmd=&PreCommonCmd[*step];
3714 CurrentCmd=&RfDependCmd[*step];
3717 CurrentCmd=&PostCommonCmd[*step];
3721 if(CurrentCmd->CmdID==CmdID_End)
3735 switch(CurrentCmd->CmdID)
3737 case CmdID_SetTxPowerLevel:
3738 //if(priv->card_8192_version > VERSION_8190_BD)
3739 PHY_SetTxPowerLevel8192S(dev,channel);
3741 case CmdID_WritePortUlong:
3742 write_nic_dword(dev, CurrentCmd->Para1, CurrentCmd->Para2);
3744 case CmdID_WritePortUshort:
3745 write_nic_word(dev, CurrentCmd->Para1, (u16)CurrentCmd->Para2);
3747 case CmdID_WritePortUchar:
3748 write_nic_byte(dev, CurrentCmd->Para1, (u8)CurrentCmd->Para2);
3750 case CmdID_RF_WriteReg: // Only modify channel for the register now !!!!!
3751 for(eRFPath = 0; eRFPath <priv->NumTotalRFPath; eRFPath++)
3753 #if (defined RTL8192SE ||defined RTL8192SU )
3754 // For new T65 RF 0222d register 0x18 bit 0-9 = channel number.
3755 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, CurrentCmd->Para1, 0x1f, (CurrentCmd->Para2));
3756 //printk("====>%x, %x, read_back:%x\n", CurrentCmd->Para2,CurrentCmd->Para1, rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, CurrentCmd->Para1, 0x1f));
3758 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, CurrentCmd->Para1, bRFRegOffsetMask, ((CurrentCmd->Para2)<<7));
3768 //cosa }/*for(Number of RF paths)*/
3770 (*delay)=CurrentCmd->msDelay;
3772 RT_TRACE(COMP_CH, "<===========%s(), channel:%d, stage:%d, step:%d\n", __FUNCTION__, channel, *stage, *step);
3776 //called PHY_SwChnlPhy8192S, SwChnlCallback8192SUsbWorkItem
3779 phy_FinishSwChnlNow( // We should not call this function directly
3780 struct net_device* dev,
3784 struct r8192_priv *priv = ieee80211_priv(dev);
3787 while(!phy_SwChnlStepByStep(dev,channel,&priv->SwChnlStage,&priv->SwChnlStep,&delay))
3797 /*-----------------------------------------------------------------------------
3798 * Function: PHYCheckIsLegalRfPath8190Pci()
3800 * Overview: Check different RF type to execute legal judgement. If RF Path is illegal
3801 * We will return false.
3811 * 11/15/2007 MHC Create Version 0.
3813 *---------------------------------------------------------------------------*/
3814 //called by rtl8192_phy_QueryRFReg, rtl8192_phy_SetRFReg, PHY_SetRFPowerState8192SUsb
3816 //PHY_CheckIsLegalRfPath8192S(
3817 // struct net_device* dev,
3819 u8 rtl8192_phy_CheckIsLegalRFPath(struct net_device* dev, u32 eRFPath)
3821 // struct r8192_priv *priv = ieee80211_priv(dev);
3822 bool rtValue = TRUE;
3824 // NOt check RF Path now.!
3826 if (priv->rf_type == RF_1T2R && eRFPath != RF90_PATH_A)
3830 if (priv->rf_type == RF_1T2R && eRFPath != RF90_PATH_A)
3837 } /* PHY_CheckIsLegalRfPath8192S */
3841 /*-----------------------------------------------------------------------------
3842 * Function: PHY_IQCalibrate8192S()
3844 * Overview: After all MAC/PHY/RF is configued. We must execute IQ calibration
3845 * to improve RF EVM!!?
3847 * Input: IN PADAPTER pAdapter
3855 * 10/07/2008 MHC Create. Document from SD3 RFSI Jenyu.
3857 *---------------------------------------------------------------------------*/
3858 //called by InitializeAdapter8192SE
3860 PHY_IQCalibrate( struct net_device* dev)
3862 //struct r8192_priv *priv = ieee80211_priv(dev);
3868 // 1. Check QFN68 or 64 92S (Read from EEPROM)
3873 // For 1T2R IQK only now !!!
3874 for (i = 0; i < 10; i++)
3877 rtl8192_setBBreg(dev, 0xc04, bMaskDWord, 0x00a05430);
3878 //PlatformStallExecution(5);
3880 rtl8192_setBBreg(dev, 0xc08, bMaskDWord, 0x000800e4);
3882 rtl8192_setBBreg(dev, 0xe28, bMaskDWord, 0x80800000);
3884 rtl8192_setBBreg(dev, 0xe40, bMaskDWord, 0x02140148);
3886 rtl8192_setBBreg(dev, 0xe44, bMaskDWord, 0x681604a2);
3888 rtl8192_setBBreg(dev, 0xe4c, bMaskDWord, 0x000028d1);
3890 rtl8192_setBBreg(dev, 0xe60, bMaskDWord, 0x0214014d);
3892 rtl8192_setBBreg(dev, 0xe64, bMaskDWord, 0x281608ba);
3894 rtl8192_setBBreg(dev, 0xe6c, bMaskDWord, 0x000028d1);
3896 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xfb000001);
3898 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xf8000001);
3900 rtl8192_setBBreg(dev, 0xc04, bMaskDWord, 0x00a05433);
3902 rtl8192_setBBreg(dev, 0xc08, bMaskDWord, 0x000000e4);
3904 rtl8192_setBBreg(dev, 0xe28, bMaskDWord, 0x0);
3907 reg = rtl8192_QueryBBReg(dev, 0xeac, bMaskDWord);
3909 // Readback IQK value and rewrite
3910 if (!(reg&(BIT27|BIT28|BIT30|BIT31)))
3912 old_value = (rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord) & 0x3FF);
3914 // Calibrate init gain for A path for TX0
3915 X = (rtl8192_QueryBBReg(dev, 0xe94, bMaskDWord) & 0x03FF0000)>>16;
3916 TXA[RF90_PATH_A] = (X * old_value)/0x100;
3917 reg = rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord);
3918 reg = (reg & 0xFFFFFC00) | (u32)TXA[RF90_PATH_A];
3919 rtl8192_setBBreg(dev, 0xc80, bMaskDWord, reg);
3922 // Calibrate init gain for C path for TX0
3923 Y = ( rtl8192_QueryBBReg(dev, 0xe9C, bMaskDWord) & 0x03FF0000)>>16;
3924 TX0[RF90_PATH_C] = ((Y * old_value)/0x100);
3925 reg = rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord);
3926 reg = (reg & 0xffc0ffff) |((u32) (TX0[RF90_PATH_C]&0x3F)<<16);
3927 rtl8192_setBBreg(dev, 0xc80, bMaskDWord, reg);
3928 reg = rtl8192_QueryBBReg(dev, 0xc94, bMaskDWord);
3929 reg = (reg & 0x0fffffff) |(((Y&0x3c0)>>6)<<28);
3930 rtl8192_setBBreg(dev, 0xc94, bMaskDWord, reg);
3933 // Calibrate RX A and B for RX0
3934 reg = rtl8192_QueryBBReg(dev, 0xc14, bMaskDWord);
3935 X = (rtl8192_QueryBBReg(dev, 0xea4, bMaskDWord) & 0x03FF0000)>>16;
3936 reg = (reg & 0xFFFFFC00) |X;
3937 rtl8192_setBBreg(dev, 0xc14, bMaskDWord, reg);
3938 Y = (rtl8192_QueryBBReg(dev, 0xeac, bMaskDWord) & 0x003F0000)>>16;
3939 reg = (reg & 0xFFFF03FF) |Y<<10;
3940 rtl8192_setBBreg(dev, 0xc14, bMaskDWord, reg);
3942 old_value = (rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord) & 0x3FF);
3944 // Calibrate init gain for A path for TX1 !!!!!!
3945 X = (rtl8192_QueryBBReg(dev, 0xeb4, bMaskDWord) & 0x03FF0000)>>16;
3946 reg = rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord);
3947 TXA[RF90_PATH_A] = (X * old_value) / 0x100;
3948 reg = (reg & 0xFFFFFC00) | TXA[RF90_PATH_A];
3949 rtl8192_setBBreg(dev, 0xc88, bMaskDWord, reg);
3952 // Calibrate init gain for C path for TX1
3953 Y = (rtl8192_QueryBBReg(dev, 0xebc, bMaskDWord)& 0x03FF0000)>>16;
3954 TX0[RF90_PATH_C] = ((Y * old_value)/0x100);
3955 reg = rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord);
3956 reg = (reg & 0xffc0ffff) |( (TX0[RF90_PATH_C]&0x3F)<<16);
3957 rtl8192_setBBreg(dev, 0xc88, bMaskDWord, reg);
3958 reg = rtl8192_QueryBBReg(dev, 0xc9c, bMaskDWord);
3959 reg = (reg & 0x0fffffff) |(((Y&0x3c0)>>6)<<28);
3960 rtl8192_setBBreg(dev, 0xc9c, bMaskDWord, reg);
3963 // Calibrate RX A and B for RX1
3964 reg = rtl8192_QueryBBReg(dev, 0xc1c, bMaskDWord);
3965 X = (rtl8192_QueryBBReg(dev, 0xec4, bMaskDWord) & 0x03FF0000)>>16;
3966 reg = (reg & 0xFFFFFC00) |X;
3967 rtl8192_setBBreg(dev, 0xc1c, bMaskDWord, reg);
3969 Y = (rtl8192_QueryBBReg(dev, 0xecc, bMaskDWord) & 0x003F0000)>>16;
3970 reg = (reg & 0xFFFF03FF) |Y<<10;
3971 rtl8192_setBBreg(dev, 0xc1c, bMaskDWord, reg);
3974 RT_TRACE(COMP_INIT, "PHY_IQCalibrate OK\n");
3982 // 3. QFN64. Not enabled now !!! We must use different gain table for 1T2R.
3988 /*-----------------------------------------------------------------------------
3989 * Function: PHY_IQCalibrateBcut()
3991 * Overview: After all MAC/PHY/RF is configued. We must execute IQ calibration
3992 * to improve RF EVM!!?
3994 * Input: IN PADAPTER pAdapter
4002 * 11/18/2008 MHC Create. Document from SD3 RFSI Jenyu.
4003 * 92S B-cut QFN 68 pin IQ calibration procedure.doc
4005 *---------------------------------------------------------------------------*/
4006 extern void PHY_IQCalibrateBcut(struct net_device* dev)
4008 //struct r8192_priv *priv = ieee80211_priv(dev);
4009 //PMGNT_INFO pMgntInfo = &pAdapter->MgntInfo;
4014 u32 calibrate_set[13] = {0};
4018 // 0. Check QFN68 or 64 92S (Read from EEPROM/EFUSE)
4021 // 1. Save e70~ee0 register setting, and load calibration setting
4024 0xee0[31:0]=0x3fed92fb;
4025 0xedc[31:0] =0x3fed92fb;
4026 0xe70[31:0] =0x3fed92fb;
4027 0xe74[31:0] =0x3fed92fb;
4028 0xe78[31:0] =0x3fed92fb;
4029 0xe7c[31:0]= 0x3fed92fb;
4030 0xe80[31:0]= 0x3fed92fb;
4031 0xe84[31:0]= 0x3fed92fb;
4032 0xe88[31:0]= 0x3fed92fb;
4033 0xe8c[31:0]= 0x3fed92fb;
4034 0xed0[31:0]= 0x3fed92fb;
4035 0xed4[31:0]= 0x3fed92fb;
4036 0xed8[31:0]= 0x3fed92fb;
4038 calibrate_set [0] = 0xee0;
4039 calibrate_set [1] = 0xedc;
4040 calibrate_set [2] = 0xe70;
4041 calibrate_set [3] = 0xe74;
4042 calibrate_set [4] = 0xe78;
4043 calibrate_set [5] = 0xe7c;
4044 calibrate_set [6] = 0xe80;
4045 calibrate_set [7] = 0xe84;
4046 calibrate_set [8] = 0xe88;
4047 calibrate_set [9] = 0xe8c;
4048 calibrate_set [10] = 0xed0;
4049 calibrate_set [11] = 0xed4;
4050 calibrate_set [12] = 0xed8;
4051 //RT_TRACE(COMP_INIT, DBG_LOUD, ("Save e70~ee0 register setting\n"));
4052 for (i = 0; i < 13; i++)
4054 load_value[i] = rtl8192_QueryBBReg(dev, calibrate_set[i], bMaskDWord);
4055 rtl8192_setBBreg(dev, calibrate_set[i], bMaskDWord, 0x3fed92fb);
4059 RfPiEnable = (u8)rtl8192_QueryBBReg(dev, rFPGA0_XA_HSSIParameter1, BIT8);
4064 // For 1T2R IQK only now !!!
4065 for (i = 0; i < 10; i++)
4067 RT_TRACE(COMP_INIT, "IQK -%d\n", i);
4068 //BB switch to PI mode. If default is PI mode, ignoring 2 commands below.
4069 if (!RfPiEnable) //if original is SI mode, then switch to PI mode.
4071 //DbgPrint("IQK Switch to PI mode\n");
4072 rtl8192_setBBreg(dev, 0x820, bMaskDWord, 0x01000100);
4073 rtl8192_setBBreg(dev, 0x828, bMaskDWord, 0x01000100);
4077 // 2. IQ calibration & LO leakage calibration
4078 rtl8192_setBBreg(dev, 0xc04, bMaskDWord, 0x00a05430);
4080 rtl8192_setBBreg(dev, 0xc08, bMaskDWord, 0x000800e4);
4082 rtl8192_setBBreg(dev, 0xe28, bMaskDWord, 0x80800000);
4084 //path-A IQ K and LO K gain setting
4085 rtl8192_setBBreg(dev, 0xe40, bMaskDWord, 0x02140102);
4087 rtl8192_setBBreg(dev, 0xe44, bMaskDWord, 0x681604c2);
4089 //set LO calibration
4090 rtl8192_setBBreg(dev, 0xe4c, bMaskDWord, 0x000028d1);
4092 //path-B IQ K and LO K gain setting
4093 rtl8192_setBBreg(dev, 0xe60, bMaskDWord, 0x02140102);
4095 rtl8192_setBBreg(dev, 0xe64, bMaskDWord, 0x28160d05);
4098 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xfb000000);
4100 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xf8000000);
4107 rtl8192_setBBreg(dev, 0xe6c, bMaskDWord, 0x020028d1);
4110 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xfb000000);
4112 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xf8000000);
4117 rtl8192_setBBreg(dev, 0xc04, bMaskDWord, 0x00a05433);
4119 rtl8192_setBBreg(dev, 0xc08, bMaskDWord, 0x000000e4);
4121 rtl8192_setBBreg(dev, 0xe28, bMaskDWord, 0x0);
4123 if (!RfPiEnable) //if original is SI mode, then switch to PI mode.
4125 //DbgPrint("IQK Switch back to SI mode\n");
4126 rtl8192_setBBreg(dev, 0x820, bMaskDWord, 0x01000000);
4127 rtl8192_setBBreg(dev, 0x828, bMaskDWord, 0x01000000);
4131 reg = rtl8192_QueryBBReg(dev, 0xeac, bMaskDWord);
4133 // 3. check fail bit, and fill BB IQ matrix
4134 // Readback IQK value and rewrite
4135 if (!(reg&(BIT27|BIT28|BIT30|BIT31)))
4137 old_value = (rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord) & 0x3FF);
4139 // Calibrate init gain for A path for TX0
4140 X = (rtl8192_QueryBBReg(dev, 0xe94, bMaskDWord) & 0x03FF0000)>>16;
4141 TXA[RF90_PATH_A] = (X * old_value)/0x100;
4142 reg = rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord);
4143 reg = (reg & 0xFFFFFC00) | (u32)TXA[RF90_PATH_A];
4144 rtl8192_setBBreg(dev, 0xc80, bMaskDWord, reg);
4147 // Calibrate init gain for C path for TX0
4148 Y = ( rtl8192_QueryBBReg(dev, 0xe9C, bMaskDWord) & 0x03FF0000)>>16;
4149 TX0[RF90_PATH_C] = ((Y * old_value)/0x100);
4150 reg = rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord);
4151 reg = (reg & 0xffc0ffff) |((u32) (TX0[RF90_PATH_C]&0x3F)<<16);
4152 rtl8192_setBBreg(dev, 0xc80, bMaskDWord, reg);
4153 reg = rtl8192_QueryBBReg(dev, 0xc94, bMaskDWord);
4154 reg = (reg & 0x0fffffff) |(((Y&0x3c0)>>6)<<28);
4155 rtl8192_setBBreg(dev, 0xc94, bMaskDWord, reg);
4158 // Calibrate RX A and B for RX0
4159 reg = rtl8192_QueryBBReg(dev, 0xc14, bMaskDWord);
4160 X = (rtl8192_QueryBBReg(dev, 0xea4, bMaskDWord) & 0x03FF0000)>>16;
4161 reg = (reg & 0xFFFFFC00) |X;
4162 rtl8192_setBBreg(dev, 0xc14, bMaskDWord, reg);
4163 Y = (rtl8192_QueryBBReg(dev, 0xeac, bMaskDWord) & 0x003F0000)>>16;
4164 reg = (reg & 0xFFFF03FF) |Y<<10;
4165 rtl8192_setBBreg(dev, 0xc14, bMaskDWord, reg);
4167 old_value = (rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord) & 0x3FF);
4169 // Calibrate init gain for A path for TX1 !!!!!!
4170 X = (rtl8192_QueryBBReg(dev, 0xeb4, bMaskDWord) & 0x03FF0000)>>16;
4171 reg = rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord);
4172 TXA[RF90_PATH_A] = (X * old_value) / 0x100;
4173 reg = (reg & 0xFFFFFC00) | TXA[RF90_PATH_A];
4174 rtl8192_setBBreg(dev, 0xc88, bMaskDWord, reg);
4177 // Calibrate init gain for C path for TX1
4178 Y = (rtl8192_QueryBBReg(dev, 0xebc, bMaskDWord)& 0x03FF0000)>>16;
4179 TX0[RF90_PATH_C] = ((Y * old_value)/0x100);
4180 reg = rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord);
4181 reg = (reg & 0xffc0ffff) |( (TX0[RF90_PATH_C]&0x3F)<<16);
4182 rtl8192_setBBreg(dev, 0xc88, bMaskDWord, reg);
4183 reg = rtl8192_QueryBBReg(dev, 0xc9c, bMaskDWord);
4184 reg = (reg & 0x0fffffff) |(((Y&0x3c0)>>6)<<28);
4185 rtl8192_setBBreg(dev, 0xc9c, bMaskDWord, reg);
4188 // Calibrate RX A and B for RX1
4189 reg = rtl8192_QueryBBReg(dev, 0xc1c, bMaskDWord);
4190 X = (rtl8192_QueryBBReg(dev, 0xec4, bMaskDWord) & 0x03FF0000)>>16;
4191 reg = (reg & 0xFFFFFC00) |X;
4192 rtl8192_setBBreg(dev, 0xc1c, bMaskDWord, reg);
4194 Y = (rtl8192_QueryBBReg(dev, 0xecc, bMaskDWord) & 0x003F0000)>>16;
4195 reg = (reg & 0xFFFF03FF) |Y<<10;
4196 rtl8192_setBBreg(dev, 0xc1c, bMaskDWord, reg);
4199 RT_TRACE(COMP_INIT, "PHY_IQCalibrate OK\n");
4206 // 4. Reload e70~ee0 register setting.
4208 //RT_TRACE(COMP_INIT, DBG_LOUD, ("Reload e70~ee0 register setting.\n"));
4209 for (i = 0; i < 13; i++)
4210 rtl8192_setBBreg(dev, calibrate_set[i], bMaskDWord, load_value[i]);
4214 // 3. QFN64. Not enabled now !!! We must use different gain table for 1T2R.
4219 } // PHY_IQCalibrateBcut
4223 // Move from phycfg.c to gen.c to be code independent later
4225 //-------------------------Move to other DIR later----------------------------*/
4226 //#if (DEV_BUS_TYPE == USB_INTERFACE)
4229 // use in phy only (in win it's timer)
4230 void SwChnlCallback8192SUsb(struct net_device *dev)
4233 struct r8192_priv *priv = ieee80211_priv(dev);
4237 RT_TRACE(COMP_SCAN, "==>SwChnlCallback8190Pci(), switch to channel\
4244 if(priv->rf_chip == RF_PSEUDO_11N)
4246 priv->SwChnlInProgress=FALSE;
4247 return; //return immediately if it is peudo-phy
4251 if(!priv->SwChnlInProgress)
4254 if(!phy_SwChnlStepByStep(dev, priv->chan, &priv->SwChnlStage, &priv->SwChnlStep, &delay))
4258 //PlatformSetTimer(dev, &priv->SwChnlTimer, delay);
4266 priv->SwChnlInProgress=FALSE;
4274 // Callback routine of the work item for switch channel.
4276 // use in phy only (in win it's work)
4277 void SwChnlCallback8192SUsbWorkItem(struct net_device *dev )
4279 struct r8192_priv *priv = ieee80211_priv(dev);
4281 RT_TRACE(COMP_TRACE, "==> SwChnlCallback8192SUsbWorkItem()\n");
4283 if(pAdapter->bInSetPower && RT_USB_CANNOT_IO(pAdapter))
4285 RT_TRACE(COMP_SCAN, DBG_LOUD, ("<== SwChnlCallback8192SUsbWorkItem() SwChnlInProgress FALSE driver sleep or unload\n"));
4287 pHalData->SwChnlInProgress = FALSE;
4291 phy_FinishSwChnlNow(dev, priv->chan);
4292 priv->SwChnlInProgress = FALSE;
4294 RT_TRACE(COMP_TRACE, "<== SwChnlCallback8192SUsbWorkItem()\n");
4298 /*-----------------------------------------------------------------------------
4299 * Function: SetBWModeCallback8192SUsb()
4301 * Overview: Timer callback function for SetSetBWMode
4303 * Input: PRT_TIMER pTimer
4309 * Note: (1) We do not take j mode into consideration now
4310 * (2) Will two workitem of "switch channel" and "switch channel bandwidth" run
4312 *---------------------------------------------------------------------------*/
4313 //====>//rtl8192_SetBWMode
4314 // use in phy only (in win it's timer)
4315 void SetBWModeCallback8192SUsb(struct net_device *dev)
4317 struct r8192_priv *priv = ieee80211_priv(dev);
4320 // Added it for 20/40 mhz switch time evaluation by guangan 070531
4322 //u8Byte BeginTime, EndTime;
4325 RT_TRACE(COMP_SCAN, "==>SetBWModeCallback8190Pci() Switch to %s bandwidth\n", \
4326 priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz");
4328 if(priv->rf_chip == RF_PSEUDO_11N)
4330 priv->SetBWModeInProgress= FALSE;
4337 // Added it for 20/40 mhz switch time evaluation by guangan 070531
4338 //NowL = read_nic_dword(dev, TSFR);
4339 //NowH = read_nic_dword(dev, TSFR+4);
4340 //BeginTime = ((u8Byte)NowH << 32) + NowL;
4342 //3<1>Set MAC register
4343 regBwOpMode = read_nic_byte(dev, BW_OPMODE);
4344 regRRSR_RSC = read_nic_byte(dev, RRSR+2);
4346 switch(priv->CurrentChannelBW)
4348 case HT_CHANNEL_WIDTH_20:
4349 regBwOpMode |= BW_OPMODE_20MHZ;
4350 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
4351 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
4354 case HT_CHANNEL_WIDTH_20_40:
4355 regBwOpMode &= ~BW_OPMODE_20MHZ;
4356 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
4357 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
4359 regRRSR_RSC = (regRRSR_RSC&0x90) |(priv->nCur40MhzPrimeSC<<5);
4360 write_nic_byte(dev, RRSR+2, regRRSR_RSC);
4364 RT_TRACE(COMP_DBG, "SetChannelBandwidth8190Pci():\
4365 unknown Bandwidth: %#X\n",priv->CurrentChannelBW);
4369 //3 <2>Set PHY related register
4370 switch(priv->CurrentChannelBW)
4372 case HT_CHANNEL_WIDTH_20:
4373 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x0);
4374 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x0);
4376 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00300000, 3);
4378 // Correct the tx power for CCK rate in 20M. Suggest by YN, 20071207
4379 //write_nic_dword(dev, rCCK0_TxFilter1, 0x1a1b0000);
4380 //write_nic_dword(dev, rCCK0_TxFilter2, 0x090e1317);
4381 //write_nic_dword(dev, rCCK0_DebugPort, 0x00000204);
4382 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskDWord, 0x1a1b0000);
4383 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, 0x090e1317);
4384 rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskDWord, 0x00000204);
4385 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00300000, 3);
4388 if (priv->card_8192_version >= VERSION_8192S_BCUT)
4389 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter2, 0xff, 0x58);
4392 case HT_CHANNEL_WIDTH_20_40:
4393 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x1);
4394 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x1);
4395 rtl8192_setBBreg(dev, rCCK0_System, bCCKSideBand, (priv->nCur40MhzPrimeSC>>1));
4396 rtl8192_setBBreg(dev, rOFDM1_LSTF, 0xC00, priv->nCur40MhzPrimeSC);
4398 // Correct the tx power for CCK rate in 40M. Suggest by YN, 20071207
4399 //PHY_SetBBReg(Adapter, rCCK0_TxFilter1, bMaskDWord, 0x35360000);
4400 //PHY_SetBBReg(Adapter, rCCK0_TxFilter2, bMaskDWord, 0x121c252e);
4401 //PHY_SetBBReg(Adapter, rCCK0_DebugPort, bMaskDWord, 0x00000409);
4402 //PHY_SetBBReg(Adapter, rFPGA0_AnalogParameter1, bADClkPhase, 0);
4404 if (priv->card_8192_version >= VERSION_8192S_BCUT)
4405 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter2, 0xff, 0x18);
4409 RT_TRACE(COMP_DBG, "SetChannelBandwidth8190Pci(): unknown Bandwidth: %#X\n"\
4410 ,priv->CurrentChannelBW);
4414 //Skip over setting of J-mode in BB register here. Default value is "None J mode". Emily 20070315
4416 // Added it for 20/40 mhz switch time evaluation by guangan 070531
4417 //NowL = read_nic_dword(dev, TSFR);
4418 //NowH = read_nic_dword(dev, TSFR+4);
4419 //EndTime = ((u8Byte)NowH << 32) + NowL;
4420 //RT_TRACE(COMP_SCAN, DBG_LOUD, ("SetBWModeCallback8190Pci: time of SetBWMode = %I64d us!\n", (EndTime - BeginTime)));
4423 //3<3>Set RF related register
4424 switch( priv->rf_chip )
4427 PHY_SetRF8225Bandwidth(dev, priv->CurrentChannelBW);
4431 // Please implement this function in Hal8190PciPhy8256.c
4432 //PHY_SetRF8256Bandwidth(dev, priv->CurrentChannelBW);
4436 PHY_RF6052SetBandwidth(dev, priv->CurrentChannelBW);
4440 // Please implement this function in Hal8190PciPhy8258.c
4441 // PHY_SetRF8258Bandwidth();
4449 //RT_ASSERT(FALSE, ("Unknown rf_chip: %d\n", priv->rf_chip));
4453 priv->SetBWModeInProgress= FALSE;
4455 RT_TRACE(COMP_SCAN, "<==SetBWMode8190Pci()" );
4459 // Callback routine of the work item for set bandwidth mode.
4461 // use in phy only (in win it's work)
4462 void SetBWModeCallback8192SUsbWorkItem(struct net_device *dev)
4464 struct r8192_priv *priv = ieee80211_priv(dev);
4467 // Added it for 20/40 mhz switch time evaluation by guangan 070531
4469 //u8Byte BeginTime, EndTime;
4472 RT_TRACE(COMP_SCAN, "==>SetBWModeCallback8192SUsbWorkItem() Switch to %s bandwidth\n", \
4473 priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz");
4475 if(priv->rf_chip == RF_PSEUDO_11N)
4477 priv->SetBWModeInProgress= FALSE;
4484 // Added it for 20/40 mhz switch time evaluation by guangan 070531
4485 //NowL = read_nic_dword(dev, TSFR);
4486 //NowH = read_nic_dword(dev, TSFR+4);
4487 //BeginTime = ((u8Byte)NowH << 32) + NowL;
4489 //3<1>Set MAC register
4490 regBwOpMode = read_nic_byte(dev, BW_OPMODE);
4491 regRRSR_RSC = read_nic_byte(dev, RRSR+2);
4493 switch(priv->CurrentChannelBW)
4495 case HT_CHANNEL_WIDTH_20:
4496 regBwOpMode |= BW_OPMODE_20MHZ;
4497 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
4498 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
4501 case HT_CHANNEL_WIDTH_20_40:
4502 regBwOpMode &= ~BW_OPMODE_20MHZ;
4503 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
4504 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
4505 regRRSR_RSC = (regRRSR_RSC&0x90) |(priv->nCur40MhzPrimeSC<<5);
4506 write_nic_byte(dev, RRSR+2, regRRSR_RSC);
4511 RT_TRACE(COMP_DBG, "SetBWModeCallback8192SUsbWorkItem():\
4512 unknown Bandwidth: %#X\n",priv->CurrentChannelBW);
4516 //3 <2>Set PHY related register
4517 switch(priv->CurrentChannelBW)
4519 case HT_CHANNEL_WIDTH_20:
4520 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x0);
4521 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x0);
4524 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, bADClkPhase, 1);
4526 // Correct the tx power for CCK rate in 20M. Suggest by YN, 20071207
4527 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskDWord, 0x1a1b0000);
4528 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, 0x090e1317);
4529 rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskDWord, 0x00000204);
4530 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00100000, 1);
4533 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter2, 0xff, 0x58);
4536 case HT_CHANNEL_WIDTH_20_40:
4537 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x1);
4538 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x1);
4540 rtl8192_setBBreg(dev, rCCK0_System, bCCKSideBand, (priv->nCur40MhzPrimeSC>>1));
4542 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, bADClkPhase, 0);
4544 rtl8192_setBBreg(dev, rOFDM1_LSTF, 0xC00, priv->nCur40MhzPrimeSC);
4545 // Correct the tx power for CCK rate in 40M. Suggest by YN, 20071207
4546 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskDWord, 0x35360000);
4547 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, 0x121c252e);
4548 rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskDWord, 0x00000409);
4551 // Set Control channel to upper or lower. These settings are required only for 40MHz
4552 rtl8192_setBBreg(dev, rCCK0_System, bCCKSideBand, (priv->nCur40MhzPrimeSC>>1));
4553 rtl8192_setBBreg(dev, rOFDM1_LSTF, 0xC00, priv->nCur40MhzPrimeSC);
4555 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter2, 0xff, 0x18);
4561 RT_TRACE(COMP_DBG, "SetBWModeCallback8192SUsbWorkItem(): unknown Bandwidth: %#X\n"\
4562 ,priv->CurrentChannelBW);
4566 //Skip over setting of J-mode in BB register here. Default value is "None J mode". Emily 20070315
4568 //3<3>Set RF related register
4569 switch( priv->rf_chip )
4572 PHY_SetRF8225Bandwidth(dev, priv->CurrentChannelBW);
4576 // Please implement this function in Hal8190PciPhy8256.c
4577 //PHY_SetRF8256Bandwidth(dev, priv->CurrentChannelBW);
4581 PHY_RF6052SetBandwidth(dev, priv->CurrentChannelBW);
4585 // Please implement this function in Hal8190PciPhy8258.c
4586 // PHY_SetRF8258Bandwidth();
4594 //RT_ASSERT(FALSE, ("Unknown rf_chip: %d\n", priv->rf_chip));
4598 priv->SetBWModeInProgress= FALSE;
4600 RT_TRACE(COMP_SCAN, "<==SetBWModeCallback8192SUsbWorkItem()" );
4603 //--------------------------Move to oter DIR later-------------------------------*/
4605 void InitialGain8192S(struct net_device *dev, u8 Operation)
4608 struct r8192_priv *priv = ieee80211_priv(dev);
4614 void InitialGain819xUsb(struct net_device *dev, u8 Operation)
4616 struct r8192_priv *priv = ieee80211_priv(dev);
4618 priv->InitialGainOperateType = Operation;
4622 queue_delayed_work(priv->priv_wq,&priv->initialgain_operate_wq,0);
4626 extern void InitialGainOperateWorkItemCallBack(struct work_struct *work)
4628 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
4629 struct r8192_priv *priv = container_of(dwork,struct r8192_priv,initialgain_operate_wq);
4630 struct net_device *dev = priv->ieee80211->dev;
4631 #define SCAN_RX_INITIAL_GAIN 0x17
4632 #define POWER_DETECTION_TH 0x08
4637 Operation = priv->InitialGainOperateType;
4642 RT_TRACE(COMP_SCAN, "IG_Backup, backup the initial gain.\n");
4643 initial_gain = SCAN_RX_INITIAL_GAIN;//priv->DefaultInitialGain[0];//
4644 BitMask = bMaskByte0;
4645 if(dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
4646 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); // FW DIG OFF
4647 priv->initgain_backup.xaagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XAAGCCore1, BitMask);
4648 priv->initgain_backup.xbagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XBAGCCore1, BitMask);
4649 priv->initgain_backup.xcagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XCAGCCore1, BitMask);
4650 priv->initgain_backup.xdagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XDAGCCore1, BitMask);
4651 BitMask = bMaskByte2;
4652 priv->initgain_backup.cca = (u8)rtl8192_QueryBBReg(dev, rCCK0_CCA, BitMask);
4654 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc50 is %x\n",priv->initgain_backup.xaagccore1);
4655 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc58 is %x\n",priv->initgain_backup.xbagccore1);
4656 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc60 is %x\n",priv->initgain_backup.xcagccore1);
4657 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc68 is %x\n",priv->initgain_backup.xdagccore1);
4658 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xa0a is %x\n",priv->initgain_backup.cca);
4660 RT_TRACE(COMP_SCAN, "Write scan initial gain = 0x%x \n", initial_gain);
4661 write_nic_byte(dev, rOFDM0_XAAGCCore1, initial_gain);
4662 write_nic_byte(dev, rOFDM0_XBAGCCore1, initial_gain);
4663 write_nic_byte(dev, rOFDM0_XCAGCCore1, initial_gain);
4664 write_nic_byte(dev, rOFDM0_XDAGCCore1, initial_gain);
4665 RT_TRACE(COMP_SCAN, "Write scan 0xa0a = 0x%x \n", POWER_DETECTION_TH);
4666 write_nic_byte(dev, 0xa0a, POWER_DETECTION_TH);
4669 RT_TRACE(COMP_SCAN, "IG_Restore, restore the initial gain.\n");
4670 BitMask = 0x7f; //Bit0~ Bit6
4671 if(dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
4672 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); // FW DIG OFF
4674 rtl8192_setBBreg(dev, rOFDM0_XAAGCCore1, BitMask, (u32)priv->initgain_backup.xaagccore1);
4675 rtl8192_setBBreg(dev, rOFDM0_XBAGCCore1, BitMask, (u32)priv->initgain_backup.xbagccore1);
4676 rtl8192_setBBreg(dev, rOFDM0_XCAGCCore1, BitMask, (u32)priv->initgain_backup.xcagccore1);
4677 rtl8192_setBBreg(dev, rOFDM0_XDAGCCore1, BitMask, (u32)priv->initgain_backup.xdagccore1);
4678 BitMask = bMaskByte2;
4679 rtl8192_setBBreg(dev, rCCK0_CCA, BitMask, (u32)priv->initgain_backup.cca);
4681 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc50 is %x\n",priv->initgain_backup.xaagccore1);
4682 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc58 is %x\n",priv->initgain_backup.xbagccore1);
4683 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc60 is %x\n",priv->initgain_backup.xcagccore1);
4684 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc68 is %x\n",priv->initgain_backup.xdagccore1);
4685 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xa0a is %x\n",priv->initgain_backup.cca);
4687 PHY_SetTxPowerLevel8192S(dev,priv->ieee80211->current_network.channel);
4689 if(dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
4690 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x1); // FW DIG ON
4693 RT_TRACE(COMP_SCAN, "Unknown IG Operation. \n");
4698 #endif // #if (DEV_BUS_TYPE == USB_INTERFACE)
4700 //-----------------------------------------------------------------------------
4702 // Schedule workitem to send specific CMD IO to FW.
4703 // Added by Roger, 2008.12.03.
4705 //-----------------------------------------------------------------------------
4706 bool HalSetFwCmd8192S(struct net_device* dev, FW_CMD_IO_TYPE FwCmdIO)
4708 struct r8192_priv *priv = ieee80211_priv(dev);
4709 u16 FwCmdWaitCounter = 0;
4711 u16 FwCmdWaitLimit = 1000;
4713 //if(IS_HARDWARE_TYPE_8192SU(Adapter) && Adapter->bInHctTest)
4714 if(priv->bInHctTest)
4717 RT_TRACE(COMP_CMD, "-->HalSetFwCmd8192S(): Set FW Cmd(%x), SetFwCmdInProgress(%d)\n", (u32)FwCmdIO, priv->SetFwCmdInProgress);
4719 // Will be done by high power respectively.
4720 if(FwCmdIO==FW_CMD_DIG_HALT || FwCmdIO==FW_CMD_DIG_RESUME)
4722 RT_TRACE(COMP_CMD, "<--HalSetFwCmd8192S(): Set FW Cmd(%x)\n", (u32)FwCmdIO);
4727 while(priv->SetFwCmdInProgress && FwCmdWaitCounter<FwCmdWaitLimit)
4729 //if(RT_USB_CANNOT_IO(Adapter))
4731 // RT_TRACE(COMP_CMD, DBG_WARNING, ("HalSetFwCmd8192S(): USB can NOT IO!!\n"));
4735 RT_TRACE(COMP_CMD, "HalSetFwCmd8192S(): previous workitem not finish!!\n");
4737 FwCmdWaitCounter ++;
4738 RT_TRACE(COMP_CMD, "HalSetFwCmd8192S(): Wait 10 ms (%d times)...\n", FwCmdWaitCounter);
4742 if(FwCmdWaitCounter == FwCmdWaitLimit)
4744 //RT_ASSERT(FALSE, ("SetFwCmdIOWorkItemCallback(): Wait too logn to set FW CMD\n"));
4745 RT_TRACE(COMP_CMD, "HalSetFwCmd8192S(): Wait too logn to set FW CMD\n");
4749 if (priv->SetFwCmdInProgress)
4751 RT_TRACE(COMP_ERR, "<--HalSetFwCmd8192S(): Set FW Cmd(%#x)\n", FwCmdIO);
4754 priv->SetFwCmdInProgress = TRUE;
4755 priv->CurrentFwCmdIO = FwCmdIO; // Update current FW Cmd for callback use.
4757 phy_SetFwCmdIOCallback(dev);
4760 void ChkFwCmdIoDone(struct net_device* dev)
4762 u16 PollingCnt = 1000;
4766 {// Make sure that CMD IO has be accepted by FW.
4768 if(RT_USB_CANNOT_IO(Adapter))
4770 RT_TRACE(COMP_CMD, "ChkFwCmdIoDone(): USB can NOT IO!!\n");
4774 udelay(10); // sleep 20us
4775 tmpValue = read_nic_dword(dev, WFM5);
4778 RT_TRACE(COMP_CMD, "[FW CMD] Set FW Cmd success!!\n");
4783 RT_TRACE(COMP_CMD, "[FW CMD] Polling FW Cmd PollingCnt(%d)!!\n", PollingCnt);
4785 }while( --PollingCnt );
4789 RT_TRACE(COMP_ERR, "[FW CMD] Set FW Cmd fail!!\n");
4792 // Callback routine of the timer callback for FW Cmd IO.
4795 // This routine will send specific CMD IO to FW and check whether it is done.
4797 void phy_SetFwCmdIOCallback(struct net_device* dev)
4799 //struct net_device* dev = (struct net_device*) data;
4801 static u32 ScanRegister;
4802 struct r8192_priv *priv = ieee80211_priv(dev);
4805 RT_TRACE(COMP_CMD, "SetFwCmdIOTimerCallback(): driver is going to unload\n");
4809 RT_TRACE(COMP_CMD, "--->SetFwCmdIOTimerCallback(): Cmd(%#x), SetFwCmdInProgress(%d)\n", priv->CurrentFwCmdIO, priv->SetFwCmdInProgress);
4811 switch(priv->CurrentFwCmdIO)
4813 case FW_CMD_HIGH_PWR_ENABLE:
4814 if((priv->ieee80211->pHTInfo->IOTAction & HT_IOT_ACT_DISABLE_HIGH_POWER)==0)
4815 write_nic_dword(dev, WFM5, FW_HIGH_PWR_ENABLE);
4818 case FW_CMD_HIGH_PWR_DISABLE:
4819 write_nic_dword(dev, WFM5, FW_HIGH_PWR_DISABLE);
4822 case FW_CMD_DIG_RESUME:
4823 write_nic_dword(dev, WFM5, FW_DIG_RESUME);
4826 case FW_CMD_DIG_HALT:
4827 write_nic_dword(dev, WFM5, FW_DIG_HALT);
4831 // <Roger_Notes> The following FW CMD IO was combined into single operation
4832 // (i.e., to prevent number of system workitem out of resource!!).
4835 case FW_CMD_RESUME_DM_BY_SCAN:
4836 RT_TRACE(COMP_CMD, "[FW CMD] Set HIGHPWR enable and DIG resume!!\n");
4837 if((priv->ieee80211->pHTInfo->IOTAction & HT_IOT_ACT_DISABLE_HIGH_POWER)==0)
4839 write_nic_dword(dev, WFM5, FW_HIGH_PWR_ENABLE); //break;
4840 ChkFwCmdIoDone(dev);
4842 write_nic_dword(dev, WFM5, FW_DIG_RESUME);
4845 case FW_CMD_PAUSE_DM_BY_SCAN:
4846 RT_TRACE(COMP_CMD, "[FW CMD] Set HIGHPWR disable and DIG halt!!\n");
4847 write_nic_dword(dev, WFM5, FW_HIGH_PWR_DISABLE); //break;
4848 ChkFwCmdIoDone(dev);
4849 write_nic_dword(dev, WFM5, FW_DIG_HALT);
4853 // <Roger_Notes> The following FW CMD IO should be checked
4854 // (i.e., workitem schedule timing issue!!).
4857 case FW_CMD_DIG_DISABLE:
4858 RT_TRACE(COMP_CMD, "[FW CMD] Set DIG disable!!\n");
4859 write_nic_dword(dev, WFM5, FW_DIG_DISABLE);
4862 case FW_CMD_DIG_ENABLE:
4863 RT_TRACE(COMP_CMD, "[FW CMD] Set DIG enable!!\n");
4864 write_nic_dword(dev, WFM5, FW_DIG_ENABLE);
4867 case FW_CMD_RA_RESET:
4868 write_nic_dword(dev, WFM5, FW_RA_RESET);
4871 case FW_CMD_RA_ACTIVE:
4872 write_nic_dword(dev, WFM5, FW_RA_ACTIVE);
4875 case FW_CMD_RA_REFRESH_N:
4876 RT_TRACE(COMP_CMD, "[FW CMD] Set RA refresh!! N\n");
4877 if(priv->ieee80211->pHTInfo->IOTRaFunc & HT_IOT_RAFUNC_DISABLE_ALL)
4878 input = FW_RA_REFRESH;
4880 input = FW_RA_REFRESH | (priv->ieee80211->pHTInfo->IOTRaFunc << 8);
4881 write_nic_dword(dev, WFM5, input);
4883 case FW_CMD_RA_REFRESH_BG:
4884 RT_TRACE(COMP_CMD, "[FW CMD] Set RA refresh!! B/G\n");
4885 write_nic_dword(dev, WFM5, FW_RA_REFRESH);
4886 ChkFwCmdIoDone(dev);
4887 write_nic_dword(dev, WFM5, FW_RA_ENABLE_BG);
4890 case FW_CMD_IQK_ENABLE:
4891 write_nic_dword(dev, WFM5, FW_IQK_ENABLE);
4894 case FW_CMD_TXPWR_TRACK_ENABLE:
4895 write_nic_dword(dev, WFM5, FW_TXPWR_TRACK_ENABLE);
4898 case FW_CMD_TXPWR_TRACK_DISABLE:
4899 write_nic_dword(dev, WFM5, FW_TXPWR_TRACK_DISABLE);
4903 RT_TRACE(COMP_CMD,"Unknown FW Cmd IO(%#x)\n", priv->CurrentFwCmdIO);
4907 ChkFwCmdIoDone(dev);
4909 switch(priv->CurrentFwCmdIO)
4911 case FW_CMD_HIGH_PWR_DISABLE:
4912 //if(pMgntInfo->bTurboScan)
4914 //Lower initial gain
4915 rtl8192_setBBreg(dev, rOFDM0_XAAGCCore1, bMaskByte0, 0x17);
4916 rtl8192_setBBreg(dev, rOFDM0_XBAGCCore1, bMaskByte0, 0x17);
4918 rtl8192_setBBreg(dev, rCCK0_CCA, bMaskByte2, 0x40);
4919 // Disable OFDM Part
4920 rtl8192_setBBreg(dev, rOFDM0_TRMuxPar, bMaskByte2, 0x1);
4921 ScanRegister = rtl8192_QueryBBReg(dev, rOFDM0_RxDetector1,bMaskDWord);
4922 rtl8192_setBBreg(dev, rOFDM0_RxDetector1, 0xf, 0xf);
4923 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0x0);
4927 case FW_CMD_HIGH_PWR_ENABLE:
4928 //if(pMgntInfo->bTurboScan)
4930 rtl8192_setBBreg(dev, rOFDM0_XAAGCCore1, bMaskByte0, 0x36);
4931 rtl8192_setBBreg(dev, rOFDM0_XBAGCCore1, bMaskByte0, 0x36);
4934 rtl8192_setBBreg(dev, rCCK0_CCA, bMaskByte2, 0x83);
4936 rtl8192_setBBreg(dev, rOFDM0_TRMuxPar, bMaskByte2, 0x0);
4938 //LZM ADD because sometimes there is no FW_CMD_HIGH_PWR_DISABLE, this value will be 0.
4939 if(ScanRegister != 0){
4940 rtl8192_setBBreg(dev, rOFDM0_RxDetector1, bMaskDWord, ScanRegister);
4943 if(priv->rf_type == RF_1T2R || priv->rf_type == RF_2T2R)
4944 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0x3);
4946 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0x1);
4951 priv->SetFwCmdInProgress = false;// Clear FW CMD operation flag.
4952 RT_TRACE(COMP_CMD, "<---SetFwCmdIOWorkItemCallback()\n");