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"
54 /*---------------------------Define Local Constant---------------------------*/
55 /* Channel switch:The size of command tables for switch channel*/
56 #define MAX_PRECMD_CNT 16
57 #define MAX_RFDEPENDCMD_CNT 16
58 #define MAX_POSTCMD_CNT 16
59 #define MAX_DOZE_WAITING_TIMES_9x 64
61 /*------------------------Define local variable------------------------------*/
64 static u32 RF_CHANNEL_TABLE_ZEBRA[]={
80 0x0f72,//2484 //20040810
85 phy_CalculateBitShift(u32 BitMask);
87 phy_ConfigMACWithHeaderFile(struct net_device* dev);
89 phy_InitBBRFRegisterDefinition(struct net_device* dev);
91 phy_BB8192S_Config_ParaFile(struct net_device* dev);
93 phy_ConfigBBWithHeaderFile(struct net_device* dev,u8 ConfigType);
95 phy_SetRFPowerState8192SU(struct net_device* dev,RT_RF_POWER_STATE eRFPowerState);
97 SetBWModeCallback8192SUsbWorkItem(struct net_device *dev);
99 SetBWModeCallback8192SUsbWorkItem(struct net_device *dev);
101 SwChnlCallback8192SUsbWorkItem(struct net_device *dev );
103 phy_FinishSwChnlNow(struct net_device* dev,u8 channel);
105 phy_SwChnlStepByStep(
106 struct net_device* dev,
113 phy_ConfigBBWithPgHeaderFile(struct net_device* dev,u8 ConfigType);
115 static u32 phy_FwRFSerialRead( struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 Offset);
116 static u32 phy_RFSerialRead(struct net_device* dev,RF90_RADIO_PATH_E eRFPath,u32 Offset);
117 static void phy_FwRFSerialWrite( struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 Offset, u32 Data);
118 static void phy_RFSerialWrite( struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 Offset, u32 Data);
120 static long phy_TxPwrIdxToDbm( struct net_device* dev, WIRELESS_MODE WirelessMode, u8 TxPwrIdx);
121 static u8 phy_DbmToTxPwrIdx( struct net_device* dev, WIRELESS_MODE WirelessMode, long PowerInDbm);
122 void phy_SetFwCmdIOCallback(struct net_device* dev);
124 //#if ((HAL_CODE_BASE == RTL8192_S) && (DEV_BUS_TYPE==USB_INTERFACE))
128 // Base Band read by 4181 to make sure that operation could be done in unlimited cycle.
131 // - Only use on RTL8192S USB interface.
134 // Created by Roger, 2008.09.06.
137 u32 phy_QueryUsbBBReg(struct net_device* dev, u32 RegAddr)
139 struct r8192_priv *priv = ieee80211_priv(dev);
140 u32 ReturnValue = 0xffffffff;
142 u8 BBWaitCounter = 0;
146 // <Roger_Notes> Due to PASSIVE_LEVEL, so we ONLY simply busy waiting for a while here.
147 // We have to make sure that previous BB I/O has been done.
150 while(priv->bChangeBBInProgress)
153 RT_TRACE(COMP_RF, "phy_QueryUsbBBReg(): Wait 1 ms (%d times)...\n", BBWaitCounter);
156 // Wait too long, return FALSE to avoid to be stuck here.
157 if((BBWaitCounter > 100) )//||RT_USB_CANNOT_IO(Adapter))
159 RT_TRACE(COMP_RF, "phy_QueryUsbBBReg(): (%d) Wait too logn to query BB!!\n", BBWaitCounter);
164 priv->bChangeBBInProgress = true;
166 read_nic_dword(dev, RegAddr);
169 {// Make sure that access could be done.
170 if((read_nic_byte(dev, PHY_REG)&HST_RDBUSY) == 0)
172 }while( --PollingCnt );
176 RT_TRACE(COMP_RF, "Fail!!!phy_QueryUsbBBReg(): RegAddr(%#x) = %#x\n", RegAddr, ReturnValue);
180 // Data FW read back.
181 ReturnValue = read_nic_dword(dev, PHY_REG_DATA);
182 RT_TRACE(COMP_RF, "phy_QueryUsbBBReg(): RegAddr(%#x) = %#x, PollingCnt(%d)\n", RegAddr, ReturnValue, PollingCnt);
185 priv->bChangeBBInProgress = false;
194 // Base Band wrote by 4181 to make sure that operation could be done in unlimited cycle.
197 // - Only use on RTL8192S USB interface.
200 // Created by Roger, 2008.09.06.
204 phy_SetUsbBBReg(struct net_device* dev,u32 RegAddr,u32 Data)
206 struct r8192_priv *priv = ieee80211_priv(dev);
207 u8 BBWaitCounter = 0;
209 RT_TRACE(COMP_RF, "phy_SetUsbBBReg(): RegAddr(%#x) <= %#x\n", RegAddr, Data);
212 // <Roger_Notes> Due to PASSIVE_LEVEL, so we ONLY simply busy waiting for a while here.
213 // We have to make sure that previous BB I/O has been done.
216 while(priv->bChangeBBInProgress)
219 RT_TRACE(COMP_RF, "phy_SetUsbBBReg(): Wait 1 ms (%d times)...\n", BBWaitCounter);
222 if((BBWaitCounter > 100))// || RT_USB_CANNOT_IO(Adapter))
224 RT_TRACE(COMP_RF, "phy_SetUsbBBReg(): (%d) Wait too logn to query BB!!\n", BBWaitCounter);
229 priv->bChangeBBInProgress = true;
230 //printk("**************%s: RegAddr:%x Data:%x\n", __FUNCTION__,RegAddr, Data);
231 write_nic_dword(dev, RegAddr, Data);
233 priv->bChangeBBInProgress = false;
240 // RF read by 4181 to make sure that operation could be done in unlimited cycle.
243 // - Only use on RTL8192S USB interface.
245 // - RT_RF_OPERATE_SPINLOCK is acquired and keep on holding to the end.FIXLZM
247 // Created by Roger, 2008.09.06.
250 u32 phy_QueryUsbRFReg( struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 Offset)
253 struct r8192_priv *priv = ieee80211_priv(dev);
254 //u32 value = 0, ReturnValue = 0;
256 //u32 tmplong,tmplong2;
258 u8 RFWaitCounter = 0;
262 // <Roger_Notes> Due to PASSIVE_LEVEL, so we ONLY simply busy waiting for a while here.
263 // We have to make sure that previous RF I/O has been done.
266 while(priv->bChangeRFInProgress)
268 //PlatformReleaseSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
269 //spin_lock_irqsave(&priv->rf_lock, flags); //LZM,090318
273 RT_TRACE(COMP_RF, "phy_QueryUsbRFReg(): Wait 1 ms (%d times)...\n", RFWaitCounter);
276 if((RFWaitCounter > 100)) //|| RT_USB_CANNOT_IO(Adapter))
278 RT_TRACE(COMP_RF, "phy_QueryUsbRFReg(): (%d) Wait too logn to query BB!!\n", RFWaitCounter);
283 //PlatformAcquireSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
287 priv->bChangeRFInProgress = true;
288 //PlatformReleaseSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
291 Offset &= 0x3f; //RF_Offset= 0x00~0x3F
293 write_nic_dword(dev, RF_BB_CMD_ADDR, 0xF0000002|
294 (Offset<<8)| //RF_Offset= 0x00~0x3F
295 (eRFPath<<16)); //RF_Path = 0(A) or 1(B)
298 {// Make sure that access could be done.
299 if(read_nic_dword(dev, RF_BB_CMD_ADDR) == 0)
301 }while( --PollingCnt );
303 // Data FW read back.
304 ReturnValue = read_nic_dword(dev, RF_BB_CMD_DATA);
306 //PlatformAcquireSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
307 //spin_unlock_irqrestore(&priv->rf_lock, flags); //LZM,090318
309 priv->bChangeRFInProgress = false;
311 RT_TRACE(COMP_RF, "phy_QueryUsbRFReg(): eRFPath(%d), Offset(%#x) = %#x\n", eRFPath, Offset, ReturnValue);
320 // RF wrote by 4181 to make sure that operation could be done in unlimited cycle.
323 // - Only use on RTL8192S USB interface.
325 // - RT_RF_OPERATE_SPINLOCK is acquired and keep on holding to the end.FIXLZM
327 // Created by Roger, 2008.09.06.
330 void phy_SetUsbRFReg(struct net_device* dev,RF90_RADIO_PATH_E eRFPath,u32 RegAddr,u32 Data)
333 struct r8192_priv *priv = ieee80211_priv(dev);
335 u8 RFWaitCounter = 0;
339 // <Roger_Notes> Due to PASSIVE_LEVEL, so we ONLY simply busy waiting for a while here.
340 // We have to make sure that previous BB I/O has been done.
343 while(priv->bChangeRFInProgress)
345 //PlatformReleaseSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
346 //spin_lock_irqsave(&priv->rf_lock, flags); //LZM,090318
350 RT_TRACE(COMP_RF, "phy_SetUsbRFReg(): Wait 1 ms (%d times)...\n", RFWaitCounter);
353 if((RFWaitCounter > 100))// || RT_USB_CANNOT_IO(Adapter))
355 RT_TRACE(COMP_RF, "phy_SetUsbRFReg(): (%d) Wait too logn to query BB!!\n", RFWaitCounter);
360 //PlatformAcquireSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
364 priv->bChangeRFInProgress = true;
365 //PlatformReleaseSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
368 RegAddr &= 0x3f; //RF_Offset= 0x00~0x3F
370 write_nic_dword(dev, RF_BB_CMD_DATA, Data);
371 write_nic_dword(dev, RF_BB_CMD_ADDR, 0xF0000003|
372 (RegAddr<<8)| //RF_Offset= 0x00~0x3F
373 (eRFPath<<16)); //RF_Path = 0(A) or 1(B)
376 {// Make sure that access could be done.
377 if(read_nic_dword(dev, RF_BB_CMD_ADDR) == 0)
379 }while( --PollingCnt );
383 RT_TRACE(COMP_RF, "phy_SetUsbRFReg(): Set RegAddr(%#x) = %#x Fail!!!\n", RegAddr, Data);
386 //PlatformAcquireSpinLock(Adapter, RT_RF_OPERATE_SPINLOCK);
387 //spin_unlock_irqrestore(&priv->rf_lock, flags); //LZM,090318
389 priv->bChangeRFInProgress = false;
395 /*---------------------Define local function prototype-----------------------*/
398 /*----------------------------Function Body----------------------------------*/
400 // 1. BB register R/W API
403 * Function: PHY_QueryBBReg
405 * OverView: Read "sepcific bits" from BB register
409 * u32 RegAddr, //The target address to be readback
410 * u32 BitMask //The target bit position in the target address
413 * Return: u32 Data //The readback register value
414 * Note: This function is equal to "GetRegSetting" in PHY programming guide
416 //use phy dm core 8225 8256 6052
417 //u32 PHY_QueryBBReg(struct net_device* dev,u32 RegAddr, u32 BitMask)
418 u32 rtl8192_QueryBBReg(struct net_device* dev, u32 RegAddr, u32 BitMask)
421 u32 ReturnValue = 0, OriginalValue, BitShift;
423 #if (DISABLE_BB_RF == 1)
427 RT_TRACE(COMP_RF, "--->PHY_QueryBBReg(): RegAddr(%#x), BitMask(%#x)\n", RegAddr, BitMask);
430 // <Roger_Notes> Due to 8051 operation cycle (limitation cycle: 6us) and 1-Byte access issue, we should use
431 // 4181 to access Base Band instead of 8051 on USB interface to make sure that access could be done in
435 //#if ((HAL_CODE_BASE == RTL8192_S) && (DEV_BUS_TYPE==USB_INTERFACE))
437 if(IS_BB_REG_OFFSET_92S(RegAddr))
439 //if(RT_USB_CANNOT_IO(Adapter)) return FALSE;
441 if((RegAddr & 0x03) != 0)
443 printk("%s: Not DWORD alignment!!\n", __FUNCTION__);
447 OriginalValue = phy_QueryUsbBBReg(dev, RegAddr);
452 OriginalValue = read_nic_dword(dev, RegAddr);
455 BitShift = phy_CalculateBitShift(BitMask);
456 ReturnValue = (OriginalValue & BitMask) >> BitShift;
458 //RTPRINT(FPHY, PHY_BBR, ("BBR MASK=0x%x Addr[0x%x]=0x%x\n", BitMask, RegAddr, OriginalValue));
459 RT_TRACE(COMP_RF, "<---PHY_QueryBBReg(): RegAddr(%#x), BitMask(%#x), OriginalValue(%#x)\n", RegAddr, BitMask, OriginalValue);
460 return (ReturnValue);
464 * Function: PHY_SetBBReg
466 * OverView: Write "Specific bits" to BB register (page 8~)
470 * u32 RegAddr, //The target address to be modified
471 * u32 BitMask //The target bit position in the target address
473 * u32 Data //The new register value in the target bit position
474 * //of the target address
478 * Note: This function is equal to "PutRegSetting" in PHY programming guide
480 //use phy dm core 8225 8256
481 //void PHY_SetBBReg(struct net_device* dev,u32 RegAddr, u32 BitMask, u32 Data )
482 void rtl8192_setBBreg(struct net_device* dev, u32 RegAddr, u32 BitMask, u32 Data)
484 u32 OriginalValue, BitShift, NewValue;
486 #if (DISABLE_BB_RF == 1)
490 RT_TRACE(COMP_RF, "--->PHY_SetBBReg(): RegAddr(%#x), BitMask(%#x), Data(%#x)\n", RegAddr, BitMask, Data);
493 // <Roger_Notes> Due to 8051 operation cycle (limitation cycle: 6us) and 1-Byte access issue, we should use
494 // 4181 to access Base Band instead of 8051 on USB interface to make sure that access could be done in
498 //#if ((HAL_CODE_BASE == RTL8192_S) && (DEV_BUS_TYPE==USB_INTERFACE))
500 if(IS_BB_REG_OFFSET_92S(RegAddr))
502 if((RegAddr & 0x03) != 0)
504 printk("%s: Not DWORD alignment!!\n", __FUNCTION__);
508 if(BitMask!= bMaskDWord)
509 {//if not "double word" write
510 OriginalValue = phy_QueryUsbBBReg(dev, RegAddr);
511 BitShift = phy_CalculateBitShift(BitMask);
512 NewValue = (((OriginalValue) & (~BitMask))|(Data << BitShift));
513 phy_SetUsbBBReg(dev, RegAddr, NewValue);
515 phy_SetUsbBBReg(dev, RegAddr, Data);
520 if(BitMask!= bMaskDWord)
521 {//if not "double word" write
522 OriginalValue = read_nic_dword(dev, RegAddr);
523 BitShift = phy_CalculateBitShift(BitMask);
524 NewValue = (((OriginalValue) & (~BitMask)) | (Data << BitShift));
525 write_nic_dword(dev, RegAddr, NewValue);
527 write_nic_dword(dev, RegAddr, Data);
530 //RT_TRACE(COMP_RF, "<---PHY_SetBBReg(): RegAddr(%#x), BitMask(%#x), Data(%#x)\n", RegAddr, BitMask, Data);
537 // 2. RF register R/W API
540 * Function: PHY_QueryRFReg
542 * OverView: Query "Specific bits" to RF register (page 8~)
546 * RF90_RADIO_PATH_E eRFPath, //Radio path of A/B/C/D
547 * u32 RegAddr, //The target address to be read
548 * u32 BitMask //The target bit position in the target address
552 * Return: u32 Readback value
553 * Note: This function is equal to "GetRFRegSetting" in PHY programming guide
556 //u32 PHY_QueryRFReg(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 RegAddr, u32 BitMask)
557 u32 rtl8192_phy_QueryRFReg(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 RegAddr, u32 BitMask)
559 u32 Original_Value, Readback_Value, BitShift;//, flags;
560 struct r8192_priv *priv = ieee80211_priv(dev);
562 #if (DISABLE_BB_RF == 1)
566 RT_TRACE(COMP_RF, "--->PHY_QueryRFReg(): RegAddr(%#x), eRFPath(%#x), BitMask(%#x)\n", RegAddr, eRFPath,BitMask);
568 if (!((priv->rf_pathmap >> eRFPath) & 0x1))
570 printk("EEEEEError: rfpath off! rf_pathmap=%x eRFPath=%x\n", priv->rf_pathmap, eRFPath);
574 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
576 printk("EEEEEError: not legal rfpath! eRFPath=%x\n", eRFPath);
580 /* 2008/01/17 MH We get and release spin lock when reading RF register. */
581 //PlatformAcquireSpinLock(dev, RT_RF_OPERATE_SPINLOCK);FIXLZM
582 //spin_lock_irqsave(&priv->rf_lock, flags); //YJ,test,090113
585 // <Roger_Notes> Due to 8051 operation cycle (limitation cycle: 6us) and 1-Byte access issue, we should use
586 // 4181 to access Base Band instead of 8051 on USB interface to make sure that access could be done in
590 //#if (HAL_CODE_BASE == RTL8192_S && DEV_BUS_TYPE==USB_INTERFACE)
592 //if(RT_USB_CANNOT_IO(Adapter)) return FALSE;
593 Original_Value = phy_QueryUsbRFReg(dev, eRFPath, RegAddr);
595 if (priv->Rf_Mode == RF_OP_By_FW)
597 Original_Value = phy_FwRFSerialRead(dev, eRFPath, RegAddr);
601 Original_Value = phy_RFSerialRead(dev, eRFPath, RegAddr);
605 BitShift = phy_CalculateBitShift(BitMask);
606 Readback_Value = (Original_Value & BitMask) >> BitShift;
607 //spin_unlock_irqrestore(&priv->rf_lock, flags); //YJ,test,090113
609 //PlatformReleaseSpinLock(dev, RT_RF_OPERATE_SPINLOCK);
611 //RTPRINT(FPHY, PHY_RFR, ("RFR-%d MASK=0x%x Addr[0x%x]=0x%x\n", eRFPath, BitMask, RegAddr, Original_Value));
613 return (Readback_Value);
617 * Function: PHY_SetRFReg
619 * OverView: Write "Specific bits" to RF register (page 8~)
623 * RF90_RADIO_PATH_E eRFPath, //Radio path of A/B/C/D
624 * u32 RegAddr, //The target address to be modified
625 * u32 BitMask //The target bit position in the target address
627 * u32 Data //The new register Data in the target bit position
628 * //of the target address
632 * Note: This function is equal to "PutRFRegSetting" in PHY programming guide
635 //void PHY_SetRFReg(struct net_device* dev,RF90_RADIO_PATH_E eRFPath, u32 RegAddr, u32 BitMask,u32 Data )
636 void rtl8192_phy_SetRFReg(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
639 struct r8192_priv *priv = ieee80211_priv(dev);
640 u32 Original_Value, BitShift, New_Value;//, flags;
641 #if (DISABLE_BB_RF == 1)
645 RT_TRACE(COMP_RF, "--->PHY_SetRFReg(): RegAddr(%#x), BitMask(%#x), Data(%#x), eRFPath(%#x)\n",
646 RegAddr, BitMask, Data, eRFPath);
648 if (!((priv->rf_pathmap >> eRFPath) & 0x1))
650 printk("EEEEEError: rfpath off! rf_pathmap=%x eRFPath=%x\n", priv->rf_pathmap, eRFPath);
653 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
655 printk("EEEEEError: not legal rfpath! eRFPath=%x\n", eRFPath);
659 /* 2008/01/17 MH We get and release spin lock when writing RF register. */
660 //PlatformAcquireSpinLock(dev, RT_RF_OPERATE_SPINLOCK);
661 //spin_lock_irqsave(&priv->rf_lock, flags); //YJ,test,090113
664 // <Roger_Notes> Due to 8051 operation cycle (limitation cycle: 6us) and 1-Byte access issue, we should use
665 // 4181 to access Base Band instead of 8051 on USB interface to make sure that access could be done in
669 //#if (HAL_CODE_BASE == RTL8192_S && DEV_BUS_TYPE==USB_INTERFACE)
671 //if(RT_USB_CANNOT_IO(Adapter)) return;
673 if (BitMask != bRFRegOffsetMask) // RF data is 12 bits only
675 Original_Value = phy_QueryUsbRFReg(dev, eRFPath, RegAddr);
676 BitShift = phy_CalculateBitShift(BitMask);
677 New_Value = (((Original_Value)&(~BitMask))|(Data<< BitShift));
678 phy_SetUsbRFReg(dev, eRFPath, RegAddr, New_Value);
681 phy_SetUsbRFReg(dev, eRFPath, RegAddr, Data);
683 if (priv->Rf_Mode == RF_OP_By_FW)
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_FwRFSerialRead(dev, eRFPath, RegAddr);
689 BitShift = phy_CalculateBitShift(BitMask);
690 New_Value = (((Original_Value) & (~BitMask)) | (Data<< BitShift));
692 phy_FwRFSerialWrite(dev, eRFPath, RegAddr, New_Value);
695 phy_FwRFSerialWrite(dev, eRFPath, RegAddr, Data);
699 //DbgPrint("eRFPath-%d Addr[%02x] = %08x\n", eRFPath, RegAddr, Data);
700 if (BitMask != bRFRegOffsetMask) // RF data is 12 bits only
702 Original_Value = phy_RFSerialRead(dev, eRFPath, RegAddr);
703 BitShift = phy_CalculateBitShift(BitMask);
704 New_Value = (((Original_Value) & (~BitMask)) | (Data<< BitShift));
706 phy_RFSerialWrite(dev, eRFPath, RegAddr, New_Value);
709 phy_RFSerialWrite(dev, eRFPath, RegAddr, Data);
713 //PlatformReleaseSpinLock(dev, RT_RF_OPERATE_SPINLOCK);
714 //spin_unlock_irqrestore(&priv->rf_lock, flags); //YJ,test,090113
716 //RTPRINT(FPHY, PHY_RFW, ("RFW-%d MASK=0x%x Addr[0x%x]=0x%x\n", eRFPath, BitMask, RegAddr, Data));
717 RT_TRACE(COMP_RF, "<---PHY_SetRFReg(): RegAddr(%#x), BitMask(%#x), Data(%#x), eRFPath(%#x)\n",
718 RegAddr, BitMask, Data, eRFPath);
723 /*-----------------------------------------------------------------------------
724 * Function: phy_FwRFSerialRead()
726 * Overview: We support firmware to execute RF-R/W.
736 * 01/21/2008 MHC Create Version 0.
738 *---------------------------------------------------------------------------*/
742 struct net_device* dev,
743 RF90_RADIO_PATH_E eRFPath,
750 //DbgPrint("FW RF CTRL\n\r");
751 /* 2007/11/02 MH Firmware RF Write control. By Francis' suggestion, we can
752 not execute the scheme in the initial step. Otherwise, RF-R/W will waste
753 much time. This is only for site survey. */
754 // 1. Read operation need not insert data. bit 0-11
755 //Data &= bMask12Bits;
756 // 2. Write RF register address. Bit 12-19
757 Data |= ((Offset&0xFF)<<12);
758 // 3. Write RF path. bit 20-21
759 Data |= ((eRFPath&0x3)<<20);
760 // 4. Set RF read indicator. bit 22=0
762 // 5. Trigger Fw to operate the command. bit 31
764 // 6. We can not execute read operation if bit 31 is 1.
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-R Time=%d\n\r", time);
776 // 7. Execute read operation.
777 PlatformIOWrite4Byte(dev, QPNR, Data);
778 // 8. Check if firmawre send back RF content.
779 while (PlatformIORead4Byte(dev, QPNR)&0x80000000)
781 // If FW can not finish RF-R/W for more than ?? times. We must reset FW.
784 //DbgPrint("FW not finish RF-W Time=%d\n\r", time);
790 retValue = PlatformIORead4Byte(dev, RF_DATA);
794 } /* phy_FwRFSerialRead */
796 /*-----------------------------------------------------------------------------
797 * Function: phy_FwRFSerialWrite()
799 * Overview: We support firmware to execute RF-R/W.
809 * 01/21/2008 MHC Create Version 0.
811 *---------------------------------------------------------------------------*/
815 struct net_device* dev,
816 RF90_RADIO_PATH_E eRFPath,
822 DbgPrint("N FW RF CTRL RF-%d OF%02x DATA=%03x\n\r", eRFPath, Offset, Data);
823 /* 2007/11/02 MH Firmware RF Write control. By Francis' suggestion, we can
824 not execute the scheme in the initial step. Otherwise, RF-R/W will waste
825 much time. This is only for site survey. */
827 // 1. Set driver write bit and 12 bit data. bit 0-11
828 //Data &= bMask12Bits; // Done by uper layer.
829 // 2. Write RF register address. bit 12-19
830 Data |= ((Offset&0xFF)<<12);
831 // 3. Write RF path. bit 20-21
832 Data |= ((eRFPath&0x3)<<20);
833 // 4. Set RF write indicator. bit 22=1
835 // 5. Trigger Fw to operate the command. bit 31=1
838 // 6. Write operation. We can not write if bit 31 is 1.
839 while (PlatformIORead4Byte(dev, QPNR)&0x80000000)
841 // If FW can not finish RF-R/W for more than ?? times. We must reset FW.
844 //DbgPrint("FW not finish RF-W Time=%d\n\r", time);
850 // 7. No matter check bit. We always force the write. Because FW will
851 // not accept the command.
852 PlatformIOWrite4Byte(dev, QPNR, Data);
853 /* 2007/11/02 MH Acoording to test, we must delay 20us to wait firmware
854 to finish RF write operation. */
855 /* 2008/01/17 MH We support delay in firmware side now. */
858 } /* phy_FwRFSerialWrite */
861 * Function: phy_RFSerialRead
863 * OverView: Read regster from RF chips
867 * RF90_RADIO_PATH_E eRFPath, //Radio path of A/B/C/D
868 * u32 Offset, //The target address to be read
871 * Return: u32 reback value
872 * Note: Threre are three types of serial operations:
873 * 1. Software serial write
874 * 2. Hardware LSSI-Low Speed Serial Interface
875 * 3. Hardware HSSI-High speed
876 * serial write. Driver need to implement (1) and (2).
877 * This function is equal to the combination of RF_ReadReg() and RFLSSIRead()
880 static u32 phy_RFSerialRead(struct net_device* dev,RF90_RADIO_PATH_E eRFPath,u32 Offset)
884 struct r8192_priv *priv = ieee80211_priv(dev);
885 BB_REGISTER_DEFINITION_T *pPhyReg = &priv->PHYRegDef[eRFPath];
891 // Make sure RF register offset is correct
896 // Switch page for 8256 RF IC
898 if( priv->rf_chip == RF_8256 ||
899 priv->rf_chip == RF_8225 ||
900 priv->rf_chip == RF_6052)
902 //analog to digital off, for protection
903 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0xf00, 0x0);// 0x88c[11:8]
907 priv->RFReadPageCnt[2]++;//cosa add for debug
908 priv->RfReg0Value[eRFPath] |= 0x140;
910 // Switch to Reg_Mode2 for Reg31~45
911 rtl8192_setBBreg(dev,
912 pPhyReg->rf3wireOffset,
914 (priv->RfReg0Value[eRFPath] << 16) );
917 NewOffset = Offset - 30;
921 priv->RFReadPageCnt[1]++;//cosa add for debug
922 priv->RfReg0Value[eRFPath] |= 0x100;
923 priv->RfReg0Value[eRFPath] &= (~0x40);
925 // Switch to Reg_Mode1 for Reg16~30
926 rtl8192_setBBreg(dev,
927 pPhyReg->rf3wireOffset,
929 (priv->RfReg0Value[eRFPath] << 16) );
932 NewOffset = Offset - 15;
936 priv->RFReadPageCnt[0]++;//cosa add for debug
944 // Put desired read address to LSSI control register
946 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadAddress, NewOffset);
949 // Issue a posedge trigger
951 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadEdge, 0x0);
952 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadEdge, 0x1);
954 // TODO: we should not delay such a long time. Ask help from SD3
957 retValue = rtl8192_QueryBBReg(dev, pPhyReg->rfLSSIReadBack, bLSSIReadBackData);
959 // Switch back to Reg_Mode0;
960 if( priv->rf_chip == RF_8256 ||
961 priv->rf_chip == RF_8225 ||
962 priv->rf_chip == RF_0222D)
966 priv->RfReg0Value[eRFPath] &= 0xebf;
970 pPhyReg->rf3wireOffset,
972 (priv->RfReg0Value[eRFPath] << 16) );
975 //analog to digital on
976 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0xf00, 0xf);// 0x88c[11:8]
985 * Function: phy_RFSerialWrite
987 * OverView: Write data to RF register (page 8~)
991 * RF90_RADIO_PATH_E eRFPath, //Radio path of A/B/C/D
992 * u32 Offset, //The target address to be read
993 * u32 Data //The new register Data in the target bit position
994 * //of the target to be read
998 * Note: Threre are three types of serial operations:
999 * 1. Software serial write
1000 * 2. Hardware LSSI-Low Speed Serial Interface
1001 * 3. Hardware HSSI-High speed
1002 * serial write. Driver need to implement (1) and (2).
1003 * This function is equal to the combination of RF_ReadReg() and RFLSSIRead()
1005 * Note: For RF8256 only
1006 * The total count of RTL8256(Zebra4) register is around 36 bit it only employs
1007 * 4-bit RF address. RTL8256 uses "register mode control bit" (Reg00[12], Reg00[10])
1008 * to access register address bigger than 0xf. See "Appendix-4 in PHY Configuration
1009 * programming guide" for more details.
1010 * Thus, we define a sub-finction for RTL8526 register address conversion
1011 * ===========================================================
1012 * Register Mode RegCTL[1] RegCTL[0] Note
1013 * (Reg00[12]) (Reg00[10])
1014 * ===========================================================
1015 * Reg_Mode0 0 x Reg 0 ~15(0x0 ~ 0xf)
1016 * ------------------------------------------------------------------
1017 * Reg_Mode1 1 0 Reg 16 ~30(0x1 ~ 0xf)
1018 * ------------------------------------------------------------------
1019 * Reg_Mode2 1 1 Reg 31 ~ 45(0x1 ~ 0xf)
1020 * ------------------------------------------------------------------
1025 struct net_device* dev,
1026 RF90_RADIO_PATH_E eRFPath,
1031 u32 DataAndAddr = 0;
1032 struct r8192_priv *priv = ieee80211_priv(dev);
1033 BB_REGISTER_DEFINITION_T *pPhyReg = &priv->PHYRegDef[eRFPath];
1039 PHY_RFShadowWrite(dev, eRFPath, Offset, Data);
1042 // Switch page for 8256 RF IC
1043 if( priv->rf_chip == RF_8256 ||
1044 priv->rf_chip == RF_8225 ||
1045 priv->rf_chip == RF_0222D)
1047 //analog to digital off, for protection
1048 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0xf00, 0x0);// 0x88c[11:8]
1052 priv->RFWritePageCnt[2]++;//cosa add for debug
1053 priv->RfReg0Value[eRFPath] |= 0x140;
1055 rtl8192_setBBreg(dev,
1056 pPhyReg->rf3wireOffset,
1058 (priv->RfReg0Value[eRFPath] << 16) );
1060 NewOffset = Offset - 30;
1062 }else if(Offset>=16)
1064 priv->RFWritePageCnt[1]++;//cosa add for debug
1065 priv->RfReg0Value[eRFPath] |= 0x100;
1066 priv->RfReg0Value[eRFPath] &= (~0x40);
1069 rtl8192_setBBreg(dev,
1070 pPhyReg->rf3wireOffset,
1072 (priv->RfReg0Value[eRFPath] << 16) );
1074 NewOffset = Offset - 15;
1078 priv->RFWritePageCnt[0]++;//cosa add for debug
1086 // Put write addr in [5:0] and write data in [31:16]
1088 DataAndAddr = (Data<<16) | (NewOffset&0x3f);
1093 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, bMaskDWord, DataAndAddr);
1097 priv->RfReg0Value[eRFPath] = Data;
1099 // Switch back to Reg_Mode0;
1100 if( priv->rf_chip == RF_8256 ||
1101 priv->rf_chip == RF_8225 ||
1102 priv->rf_chip == RF_0222D)
1108 priv->RfReg0Value[eRFPath] &= 0xebf;
1111 pPhyReg->rf3wireOffset,
1113 (priv->RfReg0Value[eRFPath] << 16) );
1116 //analog to digital on
1117 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0xf00, 0xf);// 0x88c[11:8]
1123 * Function: phy_RFSerialRead
1125 * OverView: Read regster from RF chips
1129 * RF90_RADIO_PATH_E eRFPath, //Radio path of A/B/C/D
1130 * u4Byte Offset, //The target address to be read
1133 * Return: u4Byte reback value
1134 * Note: Threre are three types of serial operations:
1135 * 1. Software serial write
1136 * 2. Hardware LSSI-Low Speed Serial Interface
1137 * 3. Hardware HSSI-High speed
1138 * serial write. Driver need to implement (1) and (2).
1139 * This function is equal to the combination of RF_ReadReg() and RFLSSIRead()
1143 phy_RFSerialRead(struct net_device* dev,RF90_RADIO_PATH_E eRFPath,u32 Offset)
1147 struct r8192_priv *priv = ieee80211_priv(dev);
1148 BB_REGISTER_DEFINITION_T *pPhyReg = &priv->PHYRegDef[eRFPath];
1151 u32 tmplong,tmplong2;
1154 if(pHalData->RFChipID == RF_8225 && Offset > 0x24) //36 valid regs
1156 if(pHalData->RFChipID == RF_8256 && Offset > 0x2D) //45 valid regs
1160 // Make sure RF register offset is correct
1165 // Switch page for 8256 RF IC
1169 // For 92S LSSI Read RFLSSIRead
1170 // For RF A/B write 0x824/82c(does not work in the future)
1171 // We must use 0x824 for RF A and B to execute read trigger
1172 tmplong = rtl8192_QueryBBReg(dev, rFPGA0_XA_HSSIParameter2, bMaskDWord);
1173 tmplong2 = rtl8192_QueryBBReg(dev, pPhyReg->rfHSSIPara2, bMaskDWord);
1174 tmplong2 = (tmplong2 & (~bLSSIReadAddress)) | (NewOffset<<23) | bLSSIReadEdge; //T65 RF
1176 rtl8192_setBBreg(dev, rFPGA0_XA_HSSIParameter2, bMaskDWord, tmplong&(~bLSSIReadEdge));
1179 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bMaskDWord, tmplong2);
1182 rtl8192_setBBreg(dev, rFPGA0_XA_HSSIParameter2, bMaskDWord, tmplong|bLSSIReadEdge);
1185 if(eRFPath == RF90_PATH_A)
1186 RfPiEnable = (u8)rtl8192_QueryBBReg(dev, rFPGA0_XA_HSSIParameter1, BIT8);
1187 else if(eRFPath == RF90_PATH_B)
1188 RfPiEnable = (u8)rtl8192_QueryBBReg(dev, rFPGA0_XB_HSSIParameter1, BIT8);
1191 { // Read from BBreg8b8, 12 bits for 8190, 20bits for T65 RF
1192 retValue = rtl8192_QueryBBReg(dev, pPhyReg->rfLSSIReadBackPi, bLSSIReadBackData);
1193 //DbgPrint("Readback from RF-PI : 0x%x\n", retValue);
1196 { //Read from BBreg8a0, 12 bits for 8190, 20 bits for T65 RF
1197 retValue = rtl8192_QueryBBReg(dev, pPhyReg->rfLSSIReadBack, bLSSIReadBackData);
1198 //DbgPrint("Readback from RF-SI : 0x%x\n", retValue);
1200 //RTPRINT(FPHY, PHY_RFR, ("RFR-%d Addr[0x%x]=0x%x\n", eRFPath, pPhyReg->rfLSSIReadBack, retValue));
1209 * Function: phy_RFSerialWrite
1211 * OverView: Write data to RF register (page 8~)
1215 * RF90_RADIO_PATH_E eRFPath, //Radio path of A/B/C/D
1216 * u4Byte Offset, //The target address to be read
1217 * u4Byte Data //The new register Data in the target bit position
1218 * //of the target to be read
1222 * Note: Threre are three types of serial operations:
1223 * 1. Software serial write
1224 * 2. Hardware LSSI-Low Speed Serial Interface
1225 * 3. Hardware HSSI-High speed
1226 * serial write. Driver need to implement (1) and (2).
1227 * This function is equal to the combination of RF_ReadReg() and RFLSSIRead()
1229 * Note: For RF8256 only
1230 * The total count of RTL8256(Zebra4) register is around 36 bit it only employs
1231 * 4-bit RF address. RTL8256 uses "register mode control bit" (Reg00[12], Reg00[10])
1232 * to access register address bigger than 0xf. See "Appendix-4 in PHY Configuration
1233 * programming guide" for more details.
1234 * Thus, we define a sub-finction for RTL8526 register address conversion
1235 * ===========================================================
1236 * Register Mode RegCTL[1] RegCTL[0] Note
1237 * (Reg00[12]) (Reg00[10])
1238 * ===========================================================
1239 * Reg_Mode0 0 x Reg 0 ~15(0x0 ~ 0xf)
1240 * ------------------------------------------------------------------
1241 * Reg_Mode1 1 0 Reg 16 ~30(0x1 ~ 0xf)
1242 * ------------------------------------------------------------------
1243 * Reg_Mode2 1 1 Reg 31 ~ 45(0x1 ~ 0xf)
1244 * ------------------------------------------------------------------
1246 * 2008/09/02 MH Add 92S RF definition
1252 phy_RFSerialWrite(struct net_device* dev,RF90_RADIO_PATH_E eRFPath,u32 Offset,u32 Data)
1254 u32 DataAndAddr = 0;
1255 struct r8192_priv *priv = ieee80211_priv(dev);
1256 BB_REGISTER_DEFINITION_T *pPhyReg = &priv->PHYRegDef[eRFPath];
1260 //<Roger_TODO> We should check valid regs for RF_6052 case.
1261 if(pHalData->RFChipID == RF_8225 && Offset > 0x24) //36 valid regs
1263 if(pHalData->RFChipID == RF_8256 && Offset > 0x2D) //45 valid regs
1272 PHY_RFShadowWrite(dev, eRFPath, Offset, Data);
1275 // Switch page for 8256 RF IC
1280 // Put write addr in [5:0] and write data in [31:16]
1282 //DataAndAddr = (Data<<16) | (NewOffset&0x3f);
1283 DataAndAddr = ((NewOffset<<20) | (Data&0x000fffff)) & 0x0fffffff; // T65 RF
1288 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, bMaskDWord, DataAndAddr);
1289 //RTPRINT(FPHY, PHY_RFW, ("RFW-%d Addr[0x%x]=0x%x\n", eRFPath, pPhyReg->rf3wireOffset, DataAndAddr));
1296 * Function: phy_CalculateBitShift
1298 * OverView: Get shifted position of the BitMask
1304 * Return: u32 Return the shift bit bit position of the mask
1307 static u32 phy_CalculateBitShift(u32 BitMask)
1311 for(i=0; i<=31; i++)
1313 if ( ((BitMask>>i) & 0x1 ) == 1)
1322 // 3. Initial MAC/BB/RF config by reading MAC/BB/RF txt.
1324 /*-----------------------------------------------------------------------------
1325 * Function: PHY_MACConfig8192S
1327 * Overview: Condig MAC by header file or parameter file.
1337 * 08/12/2008 MHC Create Version 0.
1339 *---------------------------------------------------------------------------*/
1341 extern bool PHY_MACConfig8192S(struct net_device* dev)
1343 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
1348 #if RTL8190_Download_Firmware_From_Header
1349 rtStatus = phy_ConfigMACWithHeaderFile(dev);
1351 // Not make sure EEPROM, add later
1352 RT_TRACE(COMP_INIT, "Read MACREG.txt\n");
1353 //rtStatus = phy_ConfigMACWithParaFile(dev, RTL819X_PHY_MACREG);// lzm del it temp
1355 return (rtStatus == RT_STATUS_SUCCESS) ? true:false;
1361 PHY_BBConfig8192S(struct net_device* dev)
1363 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
1365 u8 PathMap = 0, index = 0, rf_num = 0;
1366 struct r8192_priv *priv = ieee80211_priv(dev);
1367 phy_InitBBRFRegisterDefinition(dev);
1370 // Config BB and AGC
1372 //switch( Adapter->MgntInfo.bRegHwParaFile )
1375 // phy_BB8190_Config_HardCode(dev);
1379 rtStatus = phy_BB8192S_Config_ParaFile(dev);
1384 // phy_BB8190_Config_HardCode(dev);
1385 // phy_BB8192S_Config_ParaFile(dev);
1389 // phy_BB8190_Config_HardCode(dev);
1392 PathMap = (u8)(rtl8192_QueryBBReg(dev, rFPGA0_TxInfo, 0xf) |
1393 rtl8192_QueryBBReg(dev, rOFDM0_TRxPathEnable, 0xf));
1394 priv->rf_pathmap = PathMap;
1395 for(index = 0; index<4; index++)
1397 if((PathMap>>index)&0x1)
1401 if((priv->rf_type==RF_1T1R && rf_num!=1) ||
1402 (priv->rf_type==RF_1T2R && rf_num!=2) ||
1403 (priv->rf_type==RF_2T2R && rf_num!=2) ||
1404 (priv->rf_type==RF_2T2R_GREEN && rf_num!=2) ||
1405 (priv->rf_type==RF_2T4R && rf_num!=4))
1407 RT_TRACE( COMP_INIT, "PHY_BBConfig8192S: RF_Type(%x) does not match RF_Num(%x)!!\n", priv->rf_type, rf_num);
1409 return (rtStatus == RT_STATUS_SUCCESS) ? 1:0;
1414 PHY_RFConfig8192S(struct net_device* dev)
1416 struct r8192_priv *priv = ieee80211_priv(dev);
1417 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
1419 //Set priv->rf_chip = RF_8225 to do real PHY FPGA initilization
1421 //<Roger_EXP> We assign RF type here temporally. 2008.09.12.
1422 priv->rf_chip = RF_6052;
1427 switch(priv->rf_chip)
1431 rtStatus = PHY_RF6052_Config(dev);
1435 //rtStatus = PHY_RF8256_Config(dev);
1442 //rtStatus = PHY_RF8225_Config(dev);
1448 return (rtStatus == RT_STATUS_SUCCESS) ? 1:0;
1452 // Joseph test: new initialize order!!
1453 // Test only!! This part need to be re-organized.
1454 // Now it is just for 8256.
1458 phy_BB8190_Config_HardCode(struct net_device* dev)
1460 //RT_ASSERT(FALSE, ("This function is not implement yet!! \n"));
1461 return RT_STATUS_SUCCESS;
1465 /*-----------------------------------------------------------------------------
1466 * Function: phy_SetBBtoDiffRFWithHeaderFile()
1468 * Overview: This function
1471 * Input: PADAPTER Adapter
1472 * u1Byte ConfigType 0 => PHY_CONFIG
1476 * Return: RT_STATUS_SUCCESS: configuration file exist
1480 *---------------------------------------------------------------------------*/
1482 phy_SetBBtoDiffRFWithHeaderFile(struct net_device* dev, u8 ConfigType)
1485 struct r8192_priv *priv = ieee80211_priv(dev);
1486 u32* Rtl819XPHY_REGArraytoXTXR_Table;
1487 u16 PHY_REGArraytoXTXRLen;
1489 //#if (HAL_CODE_BASE != RTL8192_S)
1491 if(priv->rf_type == RF_1T1R)
1493 Rtl819XPHY_REGArraytoXTXR_Table = Rtl819XPHY_REG_to1T1R_Array;
1494 PHY_REGArraytoXTXRLen = PHY_ChangeTo_1T1RArrayLength;
1496 else if(priv->rf_type == RF_1T2R)
1498 Rtl819XPHY_REGArraytoXTXR_Table = Rtl819XPHY_REG_to1T2R_Array;
1499 PHY_REGArraytoXTXRLen = PHY_ChangeTo_1T2RArrayLength;
1501 //else if(priv->rf_type == RF_2T2R || priv->rf_type == RF_2T2R_GREEN)
1503 // Rtl819XPHY_REGArraytoXTXR_Table = Rtl819XPHY_REG_to2T2R_Array;
1504 // PHY_REGArraytoXTXRLen = PHY_ChangeTo_2T2RArrayLength;
1508 return RT_STATUS_FAILURE;
1511 if(ConfigType == BaseBand_Config_PHY_REG)
1513 for(i=0;i<PHY_REGArraytoXTXRLen;i=i+3)
1515 if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xfe)
1517 else if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xfd)
1519 else if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xfc)
1521 else if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xfb)
1523 else if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xfa)
1525 else if (Rtl819XPHY_REGArraytoXTXR_Table[i] == 0xf9)
1527 rtl8192_setBBreg(dev, Rtl819XPHY_REGArraytoXTXR_Table[i], Rtl819XPHY_REGArraytoXTXR_Table[i+1], Rtl819XPHY_REGArraytoXTXR_Table[i+2]);
1528 //RT_TRACE(COMP_SEND,
1529 //"The Rtl819XPHY_REGArraytoXTXR_Table[0] is %lx Rtl819XPHY_REGArraytoXTXR_Table[1] is %lx Rtl819XPHY_REGArraytoXTXR_Table[2] is %lx \n",
1530 //Rtl819XPHY_REGArraytoXTXR_Table[i],Rtl819XPHY_REGArraytoXTXR_Table[i+1], Rtl819XPHY_REGArraytoXTXR_Table[i+2]);
1534 RT_TRACE(COMP_SEND, "phy_SetBBtoDiffRFWithHeaderFile(): ConfigType != BaseBand_Config_PHY_REG\n");
1536 //#endif // #if (HAL_CODE_BASE != RTL8192_S)
1537 return RT_STATUS_SUCCESS;
1543 phy_BB8192S_Config_ParaFile(struct net_device* dev)
1545 struct r8192_priv *priv = ieee80211_priv(dev);
1546 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
1549 //char szBBRegFile[] = RTL819X_PHY_REG;
1550 //char szBBRegFile1T2R[] = RTL819X_PHY_REG_1T2R;
1551 //char szBBRegPgFile[] = RTL819X_PHY_REG_PG;
1552 //char szAGCTableFile[] = RTL819X_AGC_TAB;
1553 //char szBBRegto1T1RFile[] = RTL819X_PHY_REG_to1T1R;
1554 //char szBBRegto1T2RFile[] = RTL819X_PHY_REG_to1T2R;
1556 RT_TRACE(COMP_INIT, "==>phy_BB8192S_Config_ParaFile\n");
1559 // 1. Read PHY_REG.TXT BB INIT!!
1560 // We will seperate as 1T1R/1T2R/1T2R_GREEN/2T2R
1562 #if RTL8190_Download_Firmware_From_Header
1563 if (priv->rf_type == RF_1T2R || priv->rf_type == RF_2T2R ||
1564 priv->rf_type == RF_1T1R ||priv->rf_type == RF_2T2R_GREEN)
1566 rtStatus = phy_ConfigBBWithHeaderFile(dev,BaseBand_Config_PHY_REG);
1567 if(priv->rf_type != RF_2T2R && priv->rf_type != RF_2T2R_GREEN)
1568 {//2008.11.10 Added by tynli. The default PHY_REG.txt we read is for 2T2R,
1569 //so we should reconfig BB reg with the right PHY parameters.
1570 rtStatus = phy_SetBBtoDiffRFWithHeaderFile(dev,BaseBand_Config_PHY_REG);
1573 rtStatus = RT_STATUS_FAILURE;
1575 RT_TRACE(COMP_INIT, "RF_Type == %d\n", priv->rf_type);
1576 // No matter what kind of RF we always read PHY_REG.txt. We must copy different
1577 // type of parameter files to phy_reg.txt at first.
1578 if (priv->rf_type == RF_1T2R || priv->rf_type == RF_2T2R ||
1579 priv->rf_type == RF_1T1R ||priv->rf_type == RF_2T2R_GREEN)
1581 rtStatus = phy_ConfigBBWithParaFile(dev, (char* )&szBBRegFile);
1582 if(priv->rf_type != RF_2T2R && priv->rf_type != RF_2T2R_GREEN)
1583 {//2008.11.10 Added by tynli. The default PHY_REG.txt we read is for 2T2R,
1584 //so we should reconfig BB reg with the right PHY parameters.
1585 if(priv->rf_type == RF_1T1R)
1586 rtStatus = phy_SetBBtoDiffRFWithParaFile(dev, (char* )&szBBRegto1T1RFile);
1587 else if(priv->rf_type == RF_1T2R)
1588 rtStatus = phy_SetBBtoDiffRFWithParaFile(dev, (char* )&szBBRegto1T2RFile);
1592 rtStatus = RT_STATUS_FAILURE;
1595 if(rtStatus != RT_STATUS_SUCCESS){
1596 RT_TRACE(COMP_INIT, "phy_BB8192S_Config_ParaFile():Write BB Reg Fail!!");
1597 goto phy_BB8190_Config_ParaFile_Fail;
1601 // 2. If EEPROM or EFUSE autoload OK, We must config by PHY_REG_PG.txt
1603 if (priv->AutoloadFailFlag == false)
1605 #if RTL8190_Download_Firmware_From_Header
1606 rtStatus = phy_ConfigBBWithPgHeaderFile(dev,BaseBand_Config_PHY_REG);
1608 rtStatus = phy_ConfigBBWithPgParaFile(dev, (char* )&szBBRegPgFile);
1611 if(rtStatus != RT_STATUS_SUCCESS){
1612 RT_TRACE(COMP_INIT, "phy_BB8192S_Config_ParaFile():BB_PG Reg Fail!!");
1613 goto phy_BB8190_Config_ParaFile_Fail;
1617 // 3. BB AGC table Initialization
1619 #if RTL8190_Download_Firmware_From_Header
1620 rtStatus = phy_ConfigBBWithHeaderFile(dev,BaseBand_Config_AGC_TAB);
1622 RT_TRACE(COMP_INIT, "phy_BB8192S_Config_ParaFile AGC_TAB.txt\n");
1623 rtStatus = phy_ConfigBBWithParaFile(Adapter, (char* )&szAGCTableFile);
1626 if(rtStatus != RT_STATUS_SUCCESS){
1627 printk( "phy_BB8192S_Config_ParaFile():AGC Table Fail\n");
1628 goto phy_BB8190_Config_ParaFile_Fail;
1632 #if 0 // 2008/08/18 MH Disable for 92SE
1633 if(pHalData->VersionID > VERSION_8190_BD)
1635 //if(pHalData->RF_Type == RF_2T4R)
1637 // Antenna gain offset from B/C/D to A
1638 u4RegValue = ( pHalData->AntennaTxPwDiff[2]<<8 |
1639 pHalData->AntennaTxPwDiff[1]<<4 |
1640 pHalData->AntennaTxPwDiff[0]);
1645 PHY_SetBBReg(dev, rFPGA0_TxGainStage,
1646 (bXBTxAGC|bXCTxAGC|bXDTxAGC), u4RegValue);
1650 u4RegValue = pHalData->CrystalCap;
1651 PHY_SetBBReg(dev, rFPGA0_AnalogParameter1, bXtalCap92x, u4RegValue);
1653 //u4RegValue = ((pHalData->CrystalCap & 0xc)>>2); // bit2~3 of crystal cap
1654 //PHY_SetBBReg(Adapter, rFPGA0_AnalogParameter2, bXtalCap23, u4RegValue);
1659 // Check if the CCK HighPower is turned ON.
1660 // This is used to calculate PWDB.
1661 priv->bCckHighPower = (bool)(rtl8192_QueryBBReg(dev, rFPGA0_XA_HSSIParameter2, 0x200));
1664 phy_BB8190_Config_ParaFile_Fail:
1668 /*-----------------------------------------------------------------------------
1669 * Function: phy_ConfigMACWithHeaderFile()
1671 * Overview: This function read BB parameters from Header file we gen, and do register
1674 * Input: PADAPTER Adapter
1679 * Return: RT_STATUS_SUCCESS: configuration file exist
1681 * Note: The format of MACPHY_REG.txt is different from PHY and RF.
1682 * [Register][Mask][Value]
1683 *---------------------------------------------------------------------------*/
1686 phy_ConfigMACWithHeaderFile(struct net_device* dev)
1689 u32 ArrayLength = 0;
1691 //struct r8192_priv *priv = ieee80211_priv(dev);
1693 //#if (HAL_CODE_BASE != RTL8192_S)
1694 /*if(Adapter->bInHctTest)
1696 RT_TRACE(COMP_INIT, DBG_LOUD, ("Rtl819XMACPHY_ArrayDTM\n"));
1697 ArrayLength = MACPHY_ArrayLengthDTM;
1698 ptrArray = Rtl819XMACPHY_ArrayDTM;
1700 else if(pHalData->bTXPowerDataReadFromEEPORM)
1702 // RT_TRACE(COMP_INIT, DBG_LOUD, ("Rtl819XMACPHY_Array_PG\n"));
1703 // ArrayLength = MACPHY_Array_PGLength;
1704 // ptrArray = Rtl819XMACPHY_Array_PG;
1707 { //2008.11.06 Modified by tynli.
1708 RT_TRACE(COMP_INIT, "Read Rtl819XMACPHY_Array\n");
1709 ArrayLength = MAC_2T_ArrayLength;
1710 ptrArray = Rtl819XMAC_Array;
1713 /*for(i = 0 ;i < ArrayLength;i=i+3){
1714 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]));
1715 if(ptrArray[i] == 0x318)
1717 ptrArray[i+2] = 0x00000800;
1718 //DbgPrint("ptrArray[i], ptrArray[i+1], ptrArray[i+2] = %x, %x, %x\n",
1719 // ptrArray[i], ptrArray[i+1], ptrArray[i+2]);
1721 PHY_SetBBReg(Adapter, ptrArray[i], ptrArray[i+1], ptrArray[i+2]);
1723 for(i = 0 ;i < ArrayLength;i=i+2){ // Add by tynli for 2 column
1724 write_nic_byte(dev, ptrArray[i], (u8)ptrArray[i+1]);
1727 return RT_STATUS_SUCCESS;
1730 /*-----------------------------------------------------------------------------
1731 * Function: phy_ConfigBBWithHeaderFile()
1733 * Overview: This function read BB parameters from general file format, and do register
1736 * Input: PADAPTER Adapter
1737 * u8 ConfigType 0 => PHY_CONFIG
1742 * Return: RT_STATUS_SUCCESS: configuration file exist
1744 *---------------------------------------------------------------------------*/
1747 phy_ConfigBBWithHeaderFile(struct net_device* dev,u8 ConfigType)
1751 u32* Rtl819XPHY_REGArray_Table;
1752 u32* Rtl819XAGCTAB_Array_Table;
1753 u16 PHY_REGArrayLen, AGCTAB_ArrayLen;
1754 //struct r8192_priv *priv = ieee80211_priv(dev);
1755 //#if (HAL_CODE_BASE != RTL8192_S)
1756 /*if(Adapter->bInHctTest)
1759 AGCTAB_ArrayLen = AGCTAB_ArrayLengthDTM;
1760 Rtl819XAGCTAB_Array_Table = Rtl819XAGCTAB_ArrayDTM;
1762 if(pHalData->RF_Type == RF_2T4R)
1764 PHY_REGArrayLen = PHY_REGArrayLengthDTM;
1765 Rtl819XPHY_REGArray_Table = Rtl819XPHY_REGArrayDTM;
1767 else if (pHalData->RF_Type == RF_1T2R)
1769 PHY_REGArrayLen = PHY_REG_1T2RArrayLengthDTM;
1770 Rtl819XPHY_REGArray_Table = Rtl819XPHY_REG_1T2RArrayDTM;
1778 // 2008.11.06 Modified by tynli.
1780 AGCTAB_ArrayLen = AGCTAB_ArrayLength;
1781 Rtl819XAGCTAB_Array_Table = Rtl819XAGCTAB_Array;
1782 PHY_REGArrayLen = PHY_REG_2T2RArrayLength; // Default RF_type: 2T2R
1783 Rtl819XPHY_REGArray_Table = Rtl819XPHY_REG_Array;
1786 if(ConfigType == BaseBand_Config_PHY_REG)
1788 for(i=0;i<PHY_REGArrayLen;i=i+2)
1790 if (Rtl819XPHY_REGArray_Table[i] == 0xfe)
1792 else if (Rtl819XPHY_REGArray_Table[i] == 0xfd)
1794 else if (Rtl819XPHY_REGArray_Table[i] == 0xfc)
1796 else if (Rtl819XPHY_REGArray_Table[i] == 0xfb)
1798 else if (Rtl819XPHY_REGArray_Table[i] == 0xfa)
1800 else if (Rtl819XPHY_REGArray_Table[i] == 0xf9)
1802 rtl8192_setBBreg(dev, Rtl819XPHY_REGArray_Table[i], bMaskDWord, Rtl819XPHY_REGArray_Table[i+1]);
1803 //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]);
1807 else if(ConfigType == BaseBand_Config_AGC_TAB){
1808 for(i=0;i<AGCTAB_ArrayLen;i=i+2)
1810 rtl8192_setBBreg(dev, Rtl819XAGCTAB_Array_Table[i], bMaskDWord, Rtl819XAGCTAB_Array_Table[i+1]);
1813 //#endif // #if (HAL_CODE_BASE != RTL8192_S)
1814 return RT_STATUS_SUCCESS;
1817 /*-----------------------------------------------------------------------------
1818 * Function: phy_ConfigBBWithPgHeaderFile
1820 * Overview: Config PHY_REG_PG array
1830 * 11/06/2008 MHC Add later!!!!!!.. Please modify for new files!!!!
1831 * 11/10/2008 tynli Modify to mew files.
1833 *---------------------------------------------------------------------------*/
1835 phy_ConfigBBWithPgHeaderFile(struct net_device* dev,u8 ConfigType)
1839 u32* Rtl819XPHY_REGArray_Table_PG;
1840 u16 PHY_REGArrayPGLen;
1841 //struct r8192_priv *priv = ieee80211_priv(dev);
1842 //#if (HAL_CODE_BASE != RTL8192_S)
1843 // Default: pHalData->RF_Type = RF_2T2R.
1845 PHY_REGArrayPGLen = PHY_REG_Array_PGLength;
1846 Rtl819XPHY_REGArray_Table_PG = Rtl819XPHY_REG_Array_PG;
1848 if(ConfigType == BaseBand_Config_PHY_REG)
1850 for(i=0;i<PHY_REGArrayPGLen;i=i+3)
1852 if (Rtl819XPHY_REGArray_Table_PG[i] == 0xfe)
1854 else if (Rtl819XPHY_REGArray_Table_PG[i] == 0xfd)
1856 else if (Rtl819XPHY_REGArray_Table_PG[i] == 0xfc)
1858 else if (Rtl819XPHY_REGArray_Table_PG[i] == 0xfb)
1860 else if (Rtl819XPHY_REGArray_Table_PG[i] == 0xfa)
1862 else if (Rtl819XPHY_REGArray_Table_PG[i] == 0xf9)
1864 rtl8192_setBBreg(dev, Rtl819XPHY_REGArray_Table_PG[i], Rtl819XPHY_REGArray_Table_PG[i+1], Rtl819XPHY_REGArray_Table_PG[i+2]);
1865 //RT_TRACE(COMP_SEND, "The Rtl819XPHY_REGArray_Table_PG[0] is %lx Rtl819XPHY_REGArray_Table_PG[1] is %lx \n",
1866 // Rtl819XPHY_REGArray_Table_PG[i], Rtl819XPHY_REGArray_Table_PG[i+1]);
1869 RT_TRACE(COMP_SEND, "phy_ConfigBBWithPgHeaderFile(): ConfigType != BaseBand_Config_PHY_REG\n");
1871 return RT_STATUS_SUCCESS;
1873 } /* phy_ConfigBBWithPgHeaderFile */
1875 /*-----------------------------------------------------------------------------
1876 * Function: PHY_ConfigRFWithHeaderFile()
1878 * Overview: This function read RF parameters from general file format, and do RF 3-wire
1880 * Input: PADAPTER Adapter
1882 * RF90_RADIO_PATH_E eRFPath
1886 * Return: RT_STATUS_SUCCESS: configuration file exist
1888 * Note: Delay may be required for RF configuration
1889 *---------------------------------------------------------------------------*/
1890 //in 8256 phy_RF8256_Config_ParaFile only
1891 //RT_STATUS PHY_ConfigRFWithHeaderFile(struct net_device* dev,RF90_RADIO_PATH_E eRFPath)
1892 u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device* dev, RF90_RADIO_PATH_E eRFPath)
1895 struct r8192_priv *priv = ieee80211_priv(dev);
1898 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
1899 u32 *Rtl819XRadioA_Array_Table;
1900 u32 *Rtl819XRadioB_Array_Table;
1901 //u32* Rtl819XRadioC_Array_Table;
1902 //u32* Rtl819XRadioD_Array_Table;
1903 u16 RadioA_ArrayLen,RadioB_ArrayLen;
1905 { //2008.11.06 Modified by tynli
1906 RadioA_ArrayLen = RadioA_1T_ArrayLength;
1907 Rtl819XRadioA_Array_Table=Rtl819XRadioA_Array;
1908 Rtl819XRadioB_Array_Table=Rtl819XRadioB_Array;
1909 RadioB_ArrayLen = RadioB_ArrayLength;
1912 if( priv->rf_type == RF_2T2R_GREEN )
1914 Rtl819XRadioB_Array_Table = Rtl819XRadioB_GM_Array;
1915 RadioB_ArrayLen = RadioB_GM_ArrayLength;
1919 Rtl819XRadioB_Array_Table = Rtl819XRadioB_Array;
1920 RadioB_ArrayLen = RadioB_ArrayLength;
1923 rtStatus = RT_STATUS_SUCCESS;
1925 // When initialization, we want the delay function(mdelay(), delay_us()
1926 // ==> actually we call PlatformStallExecution()) to do NdisStallExecution()
1927 // [busy wait] instead of NdisMSleep(). So we acquire RT_INITIAL_SPINLOCK
1928 // to run at Dispatch level to achive it.
1929 //cosa PlatformAcquireSpinLock(Adapter, RT_INITIAL_SPINLOCK);
1933 for(i = 0;i<RadioA_ArrayLen; i=i+2){
1934 if(Rtl819XRadioA_Array_Table[i] == 0xfe)
1935 { // Deay specific ms. Only RF configuration require delay.
1936 //#if (DEV_BUS_TYPE == USB_INTERFACE)
1943 else if (Rtl819XRadioA_Array_Table[i] == 0xfd)
1945 else if (Rtl819XRadioA_Array_Table[i] == 0xfc)
1947 else if (Rtl819XRadioA_Array_Table[i] == 0xfb)
1949 //PlatformStallExecution(50);
1950 else if (Rtl819XRadioA_Array_Table[i] == 0xfa)
1952 else if (Rtl819XRadioA_Array_Table[i] == 0xf9)
1956 rtl8192_phy_SetRFReg(dev, eRFPath, Rtl819XRadioA_Array_Table[i], bRFRegOffsetMask, Rtl819XRadioA_Array_Table[i+1]);
1961 for(i = 0;i<RadioB_ArrayLen; i=i+2){
1962 if(Rtl819XRadioB_Array_Table[i] == 0xfe)
1963 { // Deay specific ms. Only RF configuration require delay.
1964 //#if (DEV_BUS_TYPE == USB_INTERFACE)
1971 else if (Rtl819XRadioB_Array_Table[i] == 0xfd)
1973 else if (Rtl819XRadioB_Array_Table[i] == 0xfc)
1975 else if (Rtl819XRadioB_Array_Table[i] == 0xfb)
1977 else if (Rtl819XRadioB_Array_Table[i] == 0xfa)
1979 else if (Rtl819XRadioB_Array_Table[i] == 0xf9)
1983 rtl8192_phy_SetRFReg(dev, eRFPath, Rtl819XRadioB_Array_Table[i], bRFRegOffsetMask, Rtl819XRadioB_Array_Table[i+1]);
1999 /*-----------------------------------------------------------------------------
2000 * Function: PHY_CheckBBAndRFOK()
2002 * Overview: This function is write register and then readback to make sure whether
2003 * BB[PHY0, PHY1], RF[Patha, path b, path c, path d] is Ok
2005 * Input: PADAPTER Adapter
2006 * HW90_BLOCK_E CheckBlock
2007 * RF90_RADIO_PATH_E eRFPath // it is used only when CheckBlock is HW90_BLOCK_RF
2011 * Return: RT_STATUS_SUCCESS: PHY is OK
2013 * Note: This function may be removed in the ASIC
2014 *---------------------------------------------------------------------------*/
2015 //in 8256 phy_RF8256_Config_HardCode
2016 //but we don't use it temp
2019 struct net_device* dev,
2020 HW90_BLOCK_E CheckBlock,
2021 RF90_RADIO_PATH_E eRFPath
2024 //struct r8192_priv *priv = ieee80211_priv(dev);
2025 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
2026 u32 i, CheckTimes = 4,ulRegRead = 0;
2028 u32 WriteData[] = {0xfffff027, 0xaa55a02f, 0x00000027, 0x55aa502f};
2030 // Initialize register address offset to be checked
2031 WriteAddr[HW90_BLOCK_MAC] = 0x100;
2032 WriteAddr[HW90_BLOCK_PHY0] = 0x900;
2033 WriteAddr[HW90_BLOCK_PHY1] = 0x800;
2034 WriteAddr[HW90_BLOCK_RF] = 0x3;
2036 for(i=0 ; i < CheckTimes ; i++)
2040 // Write Data to register and readback
2044 case HW90_BLOCK_MAC:
2045 //RT_ASSERT(FALSE, ("PHY_CheckBBRFOK(): Never Write 0x100 here!"));
2046 RT_TRACE(COMP_INIT, "PHY_CheckBBRFOK(): Never Write 0x100 here!\n");
2049 case HW90_BLOCK_PHY0:
2050 case HW90_BLOCK_PHY1:
2051 write_nic_dword(dev, WriteAddr[CheckBlock], WriteData[i]);
2052 ulRegRead = read_nic_dword(dev, WriteAddr[CheckBlock]);
2056 // When initialization, we want the delay function(mdelay(), delay_us()
2057 // ==> actually we call PlatformStallExecution()) to do NdisStallExecution()
2058 // [busy wait] instead of NdisMSleep(). So we acquire RT_INITIAL_SPINLOCK
2059 // to run at Dispatch level to achive it.
2060 //cosa PlatformAcquireSpinLock(dev, RT_INITIAL_SPINLOCK);
2061 WriteData[i] &= 0xfff;
2062 rtl8192_phy_SetRFReg(dev, eRFPath, WriteAddr[HW90_BLOCK_RF], bRFRegOffsetMask, WriteData[i]);
2063 // TODO: we should not delay for such a long time. Ask SD3
2065 ulRegRead = rtl8192_phy_QueryRFReg(dev, eRFPath, WriteAddr[HW90_BLOCK_RF], bMaskDWord);
2067 //cosa PlatformReleaseSpinLock(dev, RT_INITIAL_SPINLOCK);
2071 rtStatus = RT_STATUS_FAILURE;
2077 // Check whether readback data is correct
2079 if(ulRegRead != WriteData[i])
2081 //RT_TRACE(COMP_FPGA, ("ulRegRead: %x, WriteData: %x \n", ulRegRead, WriteData[i]));
2082 RT_TRACE(COMP_ERR, "read back error(read:%x, write:%x)\n", ulRegRead, WriteData[i]);
2083 rtStatus = RT_STATUS_FAILURE;
2091 //no use temp in windows driver
2094 PHY_SetRFPowerState8192SUsb(
2095 struct net_device* dev,
2096 RF_POWER_STATE RFPowerState
2099 struct r8192_priv *priv = ieee80211_priv(dev);
2100 bool WaitShutDown = FALSE;
2102 //RF90_RADIO_PATH_E eRFPath;
2104 BB_REGISTER_DEFINITION_T *pPhyReg;
2106 if(priv->SetRFPowerStateInProgress == TRUE)
2109 priv->SetRFPowerStateInProgress = TRUE;
2111 // TODO: Emily, 2006.11.21, we should rewrite this function
2113 if(RFPowerState==RF_SHUT_DOWN)
2115 RFPowerState=RF_OFF;
2120 priv->RFPowerState = RFPowerState;
2121 switch( priv->rf_chip )
2125 switch( RFPowerState )
2139 switch( RFPowerState )
2148 for(eRFPath=(RF90_RADIO_PATH_E)RF90_PATH_A; eRFPath < RF90_PATH_MAX; eRFPath++)
2150 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
2153 pPhyReg = &priv->PHYRegDef[eRFPath];
2154 rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV, bRFSI_RFENV);
2155 rtl8192_setBBreg(dev, pPhyReg->rfintfo, bRFSI_RFENV, 0);
2163 }// switch( priv->rf_chip )
2165 priv->SetRFPowerStateInProgress = FALSE;
2170 //no use temp in windows driver
2172 PHY_UpdateInitialGain(
2173 struct net_device* dev
2176 struct r8192_priv *priv = ieee80211_priv(dev);
2177 //unsigned char *IGTable;
2178 //u8 DIG_CurrentInitialGain = 4;
2180 switch(priv->rf_chip)
2193 RT_TRACE(COMP_DBG, "PHY_UpdateInitialGain(): unknown rf_chip: %#X\n", priv->rf_chip);
2199 //YJ,modified,090107
2200 void PHY_GetHWRegOriginalValue(struct net_device* dev)
2202 struct r8192_priv *priv = ieee80211_priv(dev);
2204 // read tx power offset
2206 priv->MCSTxPowerLevelOriginalOffset[0] =
2207 rtl8192_QueryBBReg(dev, rTxAGC_Rate18_06, bMaskDWord);
2208 priv->MCSTxPowerLevelOriginalOffset[1] =
2209 rtl8192_QueryBBReg(dev, rTxAGC_Rate54_24, bMaskDWord);
2210 priv->MCSTxPowerLevelOriginalOffset[2] =
2211 rtl8192_QueryBBReg(dev, rTxAGC_Mcs03_Mcs00, bMaskDWord);
2212 priv->MCSTxPowerLevelOriginalOffset[3] =
2213 rtl8192_QueryBBReg(dev, rTxAGC_Mcs07_Mcs04, bMaskDWord);
2214 priv->MCSTxPowerLevelOriginalOffset[4] =
2215 rtl8192_QueryBBReg(dev, rTxAGC_Mcs11_Mcs08, bMaskDWord);
2216 priv->MCSTxPowerLevelOriginalOffset[5] =
2217 rtl8192_QueryBBReg(dev, rTxAGC_Mcs15_Mcs12, bMaskDWord);
2220 priv->MCSTxPowerLevelOriginalOffset[6] =
2221 rtl8192_QueryBBReg(dev, rTxAGC_CCK_Mcs32, bMaskDWord);
2222 RT_TRACE(COMP_INIT, "Legacy OFDM =%08x/%08x HT_OFDM=%08x/%08x/%08x/%08x\n",
2223 priv->MCSTxPowerLevelOriginalOffset[0], priv->MCSTxPowerLevelOriginalOffset[1] ,
2224 priv->MCSTxPowerLevelOriginalOffset[2], priv->MCSTxPowerLevelOriginalOffset[3] ,
2225 priv->MCSTxPowerLevelOriginalOffset[4], priv->MCSTxPowerLevelOriginalOffset[5] );
2227 // read rx initial gain
2228 priv->DefaultInitialGain[0] = rtl8192_QueryBBReg(dev, rOFDM0_XAAGCCore1, bMaskByte0);
2229 priv->DefaultInitialGain[1] = rtl8192_QueryBBReg(dev, rOFDM0_XBAGCCore1, bMaskByte0);
2230 priv->DefaultInitialGain[2] = rtl8192_QueryBBReg(dev, rOFDM0_XCAGCCore1, bMaskByte0);
2231 priv->DefaultInitialGain[3] = rtl8192_QueryBBReg(dev, rOFDM0_XDAGCCore1, bMaskByte0);
2232 RT_TRACE(COMP_INIT, "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x) \n",
2233 priv->DefaultInitialGain[0], priv->DefaultInitialGain[1],
2234 priv->DefaultInitialGain[2], priv->DefaultInitialGain[3]);
2237 priv->framesync = rtl8192_QueryBBReg(dev, rOFDM0_RxDetector3, bMaskByte0);
2238 priv->framesyncC34 = rtl8192_QueryBBReg(dev, rOFDM0_RxDetector2, bMaskDWord);
2239 RT_TRACE(COMP_INIT, "Default framesync (0x%x) = 0x%x \n",
2240 rOFDM0_RxDetector3, priv->framesync);
2242 //YJ,modified,090107,end
2247 * Function: phy_InitBBRFRegisterDefinition
2249 * OverView: Initialize Register definition offset for Radio Path A/B/C/D
2256 * Note: The initialization value is constant and it should never be changes
2259 static void phy_InitBBRFRegisterDefinition( struct net_device* dev)
2261 struct r8192_priv *priv = ieee80211_priv(dev);
2263 // RF Interface Sowrtware Control
2264 priv->PHYRegDef[RF90_PATH_A].rfintfs = rFPGA0_XAB_RFInterfaceSW; // 16 LSBs if read 32-bit from 0x870
2265 priv->PHYRegDef[RF90_PATH_B].rfintfs = rFPGA0_XAB_RFInterfaceSW; // 16 MSBs if read 32-bit from 0x870 (16-bit for 0x872)
2266 priv->PHYRegDef[RF90_PATH_C].rfintfs = rFPGA0_XCD_RFInterfaceSW;// 16 LSBs if read 32-bit from 0x874
2267 priv->PHYRegDef[RF90_PATH_D].rfintfs = rFPGA0_XCD_RFInterfaceSW;// 16 MSBs if read 32-bit from 0x874 (16-bit for 0x876)
2269 // RF Interface Readback Value
2270 priv->PHYRegDef[RF90_PATH_A].rfintfi = rFPGA0_XAB_RFInterfaceRB; // 16 LSBs if read 32-bit from 0x8E0
2271 priv->PHYRegDef[RF90_PATH_B].rfintfi = rFPGA0_XAB_RFInterfaceRB;// 16 MSBs if read 32-bit from 0x8E0 (16-bit for 0x8E2)
2272 priv->PHYRegDef[RF90_PATH_C].rfintfi = rFPGA0_XCD_RFInterfaceRB;// 16 LSBs if read 32-bit from 0x8E4
2273 priv->PHYRegDef[RF90_PATH_D].rfintfi = rFPGA0_XCD_RFInterfaceRB;// 16 MSBs if read 32-bit from 0x8E4 (16-bit for 0x8E6)
2275 // RF Interface Output (and Enable)
2276 priv->PHYRegDef[RF90_PATH_A].rfintfo = rFPGA0_XA_RFInterfaceOE; // 16 LSBs if read 32-bit from 0x860
2277 priv->PHYRegDef[RF90_PATH_B].rfintfo = rFPGA0_XB_RFInterfaceOE; // 16 LSBs if read 32-bit from 0x864
2278 priv->PHYRegDef[RF90_PATH_C].rfintfo = rFPGA0_XC_RFInterfaceOE;// 16 LSBs if read 32-bit from 0x868
2279 priv->PHYRegDef[RF90_PATH_D].rfintfo = rFPGA0_XD_RFInterfaceOE;// 16 LSBs if read 32-bit from 0x86C
2281 // RF Interface (Output and) Enable
2282 priv->PHYRegDef[RF90_PATH_A].rfintfe = rFPGA0_XA_RFInterfaceOE; // 16 MSBs if read 32-bit from 0x860 (16-bit for 0x862)
2283 priv->PHYRegDef[RF90_PATH_B].rfintfe = rFPGA0_XB_RFInterfaceOE; // 16 MSBs if read 32-bit from 0x864 (16-bit for 0x866)
2284 priv->PHYRegDef[RF90_PATH_C].rfintfe = rFPGA0_XC_RFInterfaceOE;// 16 MSBs if read 32-bit from 0x86A (16-bit for 0x86A)
2285 priv->PHYRegDef[RF90_PATH_D].rfintfe = rFPGA0_XD_RFInterfaceOE;// 16 MSBs if read 32-bit from 0x86C (16-bit for 0x86E)
2287 //Addr of LSSI. Wirte RF register by driver
2288 priv->PHYRegDef[RF90_PATH_A].rf3wireOffset = rFPGA0_XA_LSSIParameter; //LSSI Parameter
2289 priv->PHYRegDef[RF90_PATH_B].rf3wireOffset = rFPGA0_XB_LSSIParameter;
2290 priv->PHYRegDef[RF90_PATH_C].rf3wireOffset = rFPGA0_XC_LSSIParameter;
2291 priv->PHYRegDef[RF90_PATH_D].rf3wireOffset = rFPGA0_XD_LSSIParameter;
2294 priv->PHYRegDef[RF90_PATH_A].rfLSSI_Select = rFPGA0_XAB_RFParameter; //BB Band Select
2295 priv->PHYRegDef[RF90_PATH_B].rfLSSI_Select = rFPGA0_XAB_RFParameter;
2296 priv->PHYRegDef[RF90_PATH_C].rfLSSI_Select = rFPGA0_XCD_RFParameter;
2297 priv->PHYRegDef[RF90_PATH_D].rfLSSI_Select = rFPGA0_XCD_RFParameter;
2299 // Tx AGC Gain Stage (same for all path. Should we remove this?)
2300 priv->PHYRegDef[RF90_PATH_A].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
2301 priv->PHYRegDef[RF90_PATH_B].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
2302 priv->PHYRegDef[RF90_PATH_C].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
2303 priv->PHYRegDef[RF90_PATH_D].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
2305 // Tranceiver A~D HSSI Parameter-1
2306 priv->PHYRegDef[RF90_PATH_A].rfHSSIPara1 = rFPGA0_XA_HSSIParameter1; //wire control parameter1
2307 priv->PHYRegDef[RF90_PATH_B].rfHSSIPara1 = rFPGA0_XB_HSSIParameter1; //wire control parameter1
2308 priv->PHYRegDef[RF90_PATH_C].rfHSSIPara1 = rFPGA0_XC_HSSIParameter1; //wire control parameter1
2309 priv->PHYRegDef[RF90_PATH_D].rfHSSIPara1 = rFPGA0_XD_HSSIParameter1; //wire control parameter1
2311 // Tranceiver A~D HSSI Parameter-2
2312 priv->PHYRegDef[RF90_PATH_A].rfHSSIPara2 = rFPGA0_XA_HSSIParameter2; //wire control parameter2
2313 priv->PHYRegDef[RF90_PATH_B].rfHSSIPara2 = rFPGA0_XB_HSSIParameter2; //wire control parameter2
2314 priv->PHYRegDef[RF90_PATH_C].rfHSSIPara2 = rFPGA0_XC_HSSIParameter2; //wire control parameter2
2315 priv->PHYRegDef[RF90_PATH_D].rfHSSIPara2 = rFPGA0_XD_HSSIParameter2; //wire control parameter1
2317 // RF switch Control
2318 priv->PHYRegDef[RF90_PATH_A].rfSwitchControl = rFPGA0_XAB_SwitchControl; //TR/Ant switch control
2319 priv->PHYRegDef[RF90_PATH_B].rfSwitchControl = rFPGA0_XAB_SwitchControl;
2320 priv->PHYRegDef[RF90_PATH_C].rfSwitchControl = rFPGA0_XCD_SwitchControl;
2321 priv->PHYRegDef[RF90_PATH_D].rfSwitchControl = rFPGA0_XCD_SwitchControl;
2324 priv->PHYRegDef[RF90_PATH_A].rfAGCControl1 = rOFDM0_XAAGCCore1;
2325 priv->PHYRegDef[RF90_PATH_B].rfAGCControl1 = rOFDM0_XBAGCCore1;
2326 priv->PHYRegDef[RF90_PATH_C].rfAGCControl1 = rOFDM0_XCAGCCore1;
2327 priv->PHYRegDef[RF90_PATH_D].rfAGCControl1 = rOFDM0_XDAGCCore1;
2330 priv->PHYRegDef[RF90_PATH_A].rfAGCControl2 = rOFDM0_XAAGCCore2;
2331 priv->PHYRegDef[RF90_PATH_B].rfAGCControl2 = rOFDM0_XBAGCCore2;
2332 priv->PHYRegDef[RF90_PATH_C].rfAGCControl2 = rOFDM0_XCAGCCore2;
2333 priv->PHYRegDef[RF90_PATH_D].rfAGCControl2 = rOFDM0_XDAGCCore2;
2336 priv->PHYRegDef[RF90_PATH_A].rfRxIQImbalance = rOFDM0_XARxIQImbalance;
2337 priv->PHYRegDef[RF90_PATH_B].rfRxIQImbalance = rOFDM0_XBRxIQImbalance;
2338 priv->PHYRegDef[RF90_PATH_C].rfRxIQImbalance = rOFDM0_XCRxIQImbalance;
2339 priv->PHYRegDef[RF90_PATH_D].rfRxIQImbalance = rOFDM0_XDRxIQImbalance;
2342 priv->PHYRegDef[RF90_PATH_A].rfRxAFE = rOFDM0_XARxAFE;
2343 priv->PHYRegDef[RF90_PATH_B].rfRxAFE = rOFDM0_XBRxAFE;
2344 priv->PHYRegDef[RF90_PATH_C].rfRxAFE = rOFDM0_XCRxAFE;
2345 priv->PHYRegDef[RF90_PATH_D].rfRxAFE = rOFDM0_XDRxAFE;
2348 priv->PHYRegDef[RF90_PATH_A].rfTxIQImbalance = rOFDM0_XATxIQImbalance;
2349 priv->PHYRegDef[RF90_PATH_B].rfTxIQImbalance = rOFDM0_XBTxIQImbalance;
2350 priv->PHYRegDef[RF90_PATH_C].rfTxIQImbalance = rOFDM0_XCTxIQImbalance;
2351 priv->PHYRegDef[RF90_PATH_D].rfTxIQImbalance = rOFDM0_XDTxIQImbalance;
2354 priv->PHYRegDef[RF90_PATH_A].rfTxAFE = rOFDM0_XATxAFE;
2355 priv->PHYRegDef[RF90_PATH_B].rfTxAFE = rOFDM0_XBTxAFE;
2356 priv->PHYRegDef[RF90_PATH_C].rfTxAFE = rOFDM0_XCTxAFE;
2357 priv->PHYRegDef[RF90_PATH_D].rfTxAFE = rOFDM0_XDTxAFE;
2359 // Tranceiver LSSI Readback SI mode
2360 priv->PHYRegDef[RF90_PATH_A].rfLSSIReadBack = rFPGA0_XA_LSSIReadBack;
2361 priv->PHYRegDef[RF90_PATH_B].rfLSSIReadBack = rFPGA0_XB_LSSIReadBack;
2362 priv->PHYRegDef[RF90_PATH_C].rfLSSIReadBack = rFPGA0_XC_LSSIReadBack;
2363 priv->PHYRegDef[RF90_PATH_D].rfLSSIReadBack = rFPGA0_XD_LSSIReadBack;
2365 // Tranceiver LSSI Readback PI mode
2366 priv->PHYRegDef[RF90_PATH_A].rfLSSIReadBackPi = TransceiverA_HSPI_Readback;
2367 priv->PHYRegDef[RF90_PATH_B].rfLSSIReadBackPi = TransceiverB_HSPI_Readback;
2368 //pHalData->PHYRegDef[RF90_PATH_C].rfLSSIReadBackPi = rFPGA0_XC_LSSIReadBack;
2369 //pHalData->PHYRegDef[RF90_PATH_D].rfLSSIReadBackPi = rFPGA0_XD_LSSIReadBack;
2375 // Description: Change RF power state.
2377 // Assumption: This function must be executed in re-schdulable context,
2378 // ie. PASSIVE_LEVEL.
2380 // 050823, by rcnjko.
2381 //not understand it seem's use in init
2382 //SetHwReg8192SUsb--->HalFunc.SetHwRegHandler
2383 bool PHY_SetRFPowerState(struct net_device* dev, RT_RF_POWER_STATE eRFPowerState)
2385 struct r8192_priv *priv = ieee80211_priv(dev);
2386 bool bResult = FALSE;
2388 RT_TRACE(COMP_RF, "---------> PHY_SetRFPowerState(): eRFPowerState(%d)\n", eRFPowerState);
2390 if(eRFPowerState == priv->ieee80211->eRFPowerState)
2392 RT_TRACE(COMP_RF, "<--------- PHY_SetRFPowerState(): discard the request for eRFPowerState(%d) is the same.\n", eRFPowerState);
2396 bResult = phy_SetRFPowerState8192SU(dev, eRFPowerState);
2398 RT_TRACE(COMP_RF, "<--------- PHY_SetRFPowerState(): bResult(%d)\n", bResult);
2404 static bool phy_SetRFPowerState8192SU(struct net_device* dev,RT_RF_POWER_STATE eRFPowerState)
2406 struct r8192_priv *priv = ieee80211_priv(dev);
2407 bool bResult = TRUE;
2412 if(priv->SetRFPowerStateInProgress == TRUE)
2415 priv->SetRFPowerStateInProgress = TRUE;
2417 switch(priv->rf_chip )
2420 switch( eRFPowerState )
2423 write_nic_dword(dev, WFM5, FW_BB_RESET_ENABLE);
2424 write_nic_word(dev, CMDR, 0x37FC);
2425 write_nic_byte(dev, PHY_CCA, 0x3);
2426 write_nic_byte(dev, TXPAUSE, 0x00);
2427 write_nic_byte(dev, SPS1_CTRL, 0x64);
2431 // In current solution, RFSleep=RFOff in order to save power under 802.11 power save.
2432 // By Bruce, 2008-01-16.
2436 if (priv->ieee80211->eRFPowerState == eRfSleep || priv->ieee80211->eRFPowerState == eRfOff)
2439 // Make sure BusyQueue is empty befor turn off RFE pwoer.
2440 for(QueueID = 0, i = 0; QueueID < MAX_TX_QUEUE; )
2442 if(RTIsListEmpty(&Adapter->TcbBusyQueue[QueueID]))
2449 RT_TRACE(COMP_POWER, "eRf Off/Sleep: %d times TcbBusyQueue[%d] !=0 before doze!\n", (i+1), QueueID);
2454 if(i >= MAX_DOZE_WAITING_TIMES_9x)
2456 RT_TRACE(COMP_POWER, "\n\n\n SetZebraRFPowerState8185B(): eRfOff: %d times TcbBusyQueue[%d] != 0 !!!\n\n\n", MAX_DOZE_WAITING_TIMES_9x, QueueID);
2462 //RF Off/Sleep sequence. Designed/tested from SD4 Scott, SD1 Grent and Jonbon.
2463 // Added by Bruce, 2008-11-22.
2465 //==================================================================
2466 // (0) Disable FW BB reset checking
2467 write_nic_dword(dev, WFM5, FW_BB_RESET_DISABLE);
2469 // (1) Switching Power Supply Register : Disable LD12 & SW12 (for IT)
2470 u1bTmp = read_nic_byte(dev, LDOV12D_CTRL);
2472 write_nic_byte(dev, LDOV12D_CTRL, u1bTmp);
2474 write_nic_byte(dev, SPS1_CTRL, 0x0);
2475 write_nic_byte(dev, TXPAUSE, 0xFF);
2477 // (2) MAC Tx/Rx enable, BB enable, CCK/OFDM enable
2478 write_nic_word(dev, CMDR, 0x77FC);
2479 write_nic_byte(dev, PHY_CCA, 0x0);
2482 write_nic_word(dev, CMDR, 0x37FC);
2485 write_nic_word(dev, CMDR, 0x77FC);
2488 // (3) Reset BB TRX blocks
2489 write_nic_word(dev, CMDR, 0x57FC);
2494 //RT_ASSERT(FALSE, ("phy_SetRFPowerState8192SU(): unknow state to set: 0x%X!!!\n", eRFPowerState));
2500 priv->ieee80211->eRFPowerState = eRFPowerState;
2504 // Update current RF state variable.
2505 priv->ieee80211->eRFPowerState = eRFPowerState;
2507 switch(priv->rf_chip )
2510 switch(priv->ieee80211->eRFPowerState)
2514 //If Rf off reason is from IPS, Led should blink with no link, by Maddest 071015
2516 if(pMgntInfo->RfOffReason==RF_CHANGE_BY_IPS )
2518 dev->HalFunc.LedControlHandler(dev,LED_CTL_NO_LINK);
2522 // Turn off LED if RF is not ON.
2523 dev->HalFunc.LedControlHandler(dev, LED_CTL_POWER_OFF);
2528 // Turn on RF we are still linked, which might happen when
2529 // we quickly turn off and on HW RF. 2006.05.12, by rcnjko.
2530 if( pMgntInfo->bMediaConnect == TRUE )
2532 dev->HalFunc.LedControlHandler(dev, LED_CTL_LINK);
2536 // Turn off LED if RF is not ON.
2537 dev->HalFunc.LedControlHandler(dev, LED_CTL_NO_LINK);
2549 RT_TRACE(COMP_RF, "phy_SetRFPowerState8192SU(): Unknown RF type\n");
2554 priv->SetRFPowerStateInProgress = FALSE;
2559 /*-----------------------------------------------------------------------------
2560 * Function: GetTxPowerLevel8190()
2562 * Overview: This function is export to "common" moudule
2564 * Input: PADAPTER Adapter
2565 * psByte Power Level
2571 *---------------------------------------------------------------------------*/
2574 PHY_GetTxPowerLevel8192S(
2575 struct net_device* dev,
2579 struct r8192_priv *priv = ieee80211_priv(dev);
2583 // Because the Tx power indexes are different, we report the maximum of them to
2584 // meet the CCX TPC request. By Bruce, 2008-01-31.
2588 TxPwrLevel = priv->CurrentCckTxPwrIdx;
2589 TxPwrDbm = phy_TxPwrIdxToDbm(dev, WIRELESS_MODE_B, TxPwrLevel);
2592 TxPwrLevel = priv->CurrentOfdm24GTxPwrIdx + priv->LegacyHTTxPowerDiff;
2594 // Compare with Legacy OFDM Tx power.
2595 if(phy_TxPwrIdxToDbm(dev, WIRELESS_MODE_G, TxPwrLevel) > TxPwrDbm)
2596 TxPwrDbm = phy_TxPwrIdxToDbm(dev, WIRELESS_MODE_G, TxPwrLevel);
2599 TxPwrLevel = priv->CurrentOfdm24GTxPwrIdx;
2601 // Compare with HT OFDM Tx power.
2602 if(phy_TxPwrIdxToDbm(dev, WIRELESS_MODE_N_24G, TxPwrLevel) > TxPwrDbm)
2603 TxPwrDbm = phy_TxPwrIdxToDbm(dev, WIRELESS_MODE_N_24G, TxPwrLevel);
2605 *powerlevel = TxPwrDbm;
2608 /*-----------------------------------------------------------------------------
2609 * Function: SetTxPowerLevel8190()
2611 * Overview: This function is export to "HalCommon" moudule
2613 * Input: PADAPTER Adapter
2619 * 2008/11/04 MHC We remove EEPROM_93C56.
2620 * We need to move CCX relative code to independet file.
2621 * 2009/01/21 MHC Support new EEPROM format from SD3 requirement.
2622 *---------------------------------------------------------------------------*/
2623 void PHY_SetTxPowerLevel8192S(struct net_device* dev, u8 channel)
2625 struct r8192_priv *priv = ieee80211_priv(dev);
2626 //HAL_DATA_TYPE *pHalData = GET_HAL_DATA(dev);
2627 u8 powerlevel = (u8)EEPROM_Default_TxPower, powerlevelOFDM24G = 0x10;
2628 s8 ant_pwr_diff = 0;
2630 u8 index = (channel -1);
2631 // 2009/01/22 MH Add for new EEPROM format from SD3
2632 u8 pwrdiff[2] = {0};
2633 u8 ht20pwr[2] = {0}, ht40pwr[2] = {0};
2634 u8 rfpath = 0, rfpathnum = 2;
2636 if(priv->bTXPowerDataReadFromEEPORM == FALSE)
2640 // Read predefined TX power index in EEPROM
2642 // if(priv->epromtype == EPROM_93c46)
2644 #ifdef EEPROM_OLD_FORMAT_SUPPORT
2645 powerlevel = priv->TxPowerLevelCCK[index];
2646 powerlevelOFDM24G = priv->TxPowerLevelOFDM24G[index];
2649 // Mainly we use RF-A Tx Power to write the Tx Power registers, but the RF-B Tx
2650 // Power must be calculated by the antenna diff.
2651 // So we have to rewrite Antenna gain offset register here.
2652 // Please refer to BB register 0x80c
2654 // 2. For OFDM 1T or 2T
2658 powerlevel = priv->RfTxPwrLevelCck[0][index];
2660 if (priv->rf_type == RF_1T2R || priv->rf_type == RF_1T1R)
2662 // Read HT 40 OFDM TX power
2663 powerlevelOFDM24G = priv->RfTxPwrLevelOfdm1T[0][index];
2664 // RF B HT OFDM pwr-RFA HT OFDM pwr
2665 // Only one RF we need not to decide B <-> A pwr diff
2667 // Legacy<->HT pwr diff, we only care about path A.
2669 // We only assume 1T as RF path A
2671 ht20pwr[0] = ht40pwr[0] = priv->RfTxPwrLevelOfdm1T[0][index];
2673 else if (priv->rf_type == RF_2T2R)
2675 // Read HT 40 OFDM TX power
2676 powerlevelOFDM24G = priv->RfTxPwrLevelOfdm2T[0][index];
2677 // RF B HT OFDM pwr-RFA HT OFDM pwr
2678 ant_pwr_diff = priv->RfTxPwrLevelOfdm2T[1][index] -
2679 priv->RfTxPwrLevelOfdm2T[0][index];
2680 // RF B (HT OFDM pwr+legacy-ht-diff) -(RFA HT OFDM pwr+legacy-ht-diff)
2681 // We can not handle Path B&A HT/Legacy pwr diff for 92S now.
2683 //RTPRINT(FPHY, PHY_TXPWR, ("CH-%d HT40 A/B Pwr index = %x/%x(%d/%d)\n",
2684 //channel, priv->RfTxPwrLevelOfdm2T[0][index],
2685 //priv->RfTxPwrLevelOfdm2T[1][index],
2686 //priv->RfTxPwrLevelOfdm2T[0][index],
2687 //priv->RfTxPwrLevelOfdm2T[1][index]));
2689 ht20pwr[0] = ht40pwr[0] = priv->RfTxPwrLevelOfdm2T[0][index];
2690 ht20pwr[1] = ht40pwr[1] = priv->RfTxPwrLevelOfdm2T[1][index];
2694 // 2009/01/21 MH Support new EEPROM format from SD3 requirement
2695 // 2009/02/10 Cosa, Here is only for reg B/C/D to A gain diff.
2697 if (priv->EEPROMVersion == 2) // Defined by SD1 Jong
2699 if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20)
2701 for (rfpath = 0; rfpath < rfpathnum; rfpath++)
2703 // HT 20<->40 pwr diff
2704 pwrdiff[rfpath] = priv->TxPwrHt20Diff[rfpath][index];
2706 // Calculate Antenna pwr diff
2707 if (pwrdiff[rfpath] < 8) // 0~+7
2709 #if 0//cosa, it doesn't need to add the offset here
2711 powerlevelOFDM24G += pwrdiff[rfpath];
2713 ht20pwr[rfpath] += pwrdiff[rfpath];
2715 else // index8-15=-8~-1
2717 #if 0//cosa, it doesn't need to add the offset here
2719 powerlevelOFDM24G -= (15-pwrdiff[rfpath]);
2721 ht20pwr[rfpath] -= (15-pwrdiff[rfpath]);
2725 // RF B HT OFDM pwr-RFA HT OFDM pwr
2726 if (priv->rf_type == RF_2T2R)
2727 ant_pwr_diff = ht20pwr[1] - ht20pwr[0];
2729 //RTPRINT(FPHY, PHY_TXPWR,
2730 //("HT20 to HT40 pwrdiff[A/B]=%d/%d, ant_pwr_diff=%d(B-A=%d-%d)\n",
2731 //pwrdiff[0], pwrdiff[1], ant_pwr_diff, ht20pwr[1], ht20pwr[0]));
2734 // Band Edge scheme is enabled for FCC mode
2735 if (priv->TxPwrbandEdgeFlag == 1/* && pHalData->ChannelPlan == 0*/)
2737 for (rfpath = 0; rfpath < rfpathnum; rfpath++)
2739 pwrdiff[rfpath] = 0;
2740 if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40)
2743 pwrdiff[rfpath] = priv->TxPwrbandEdgeHt40[rfpath][0];
2744 else if (channel >= 9)
2745 pwrdiff[rfpath] = priv->TxPwrbandEdgeHt40[rfpath][1];
2747 pwrdiff[rfpath] = 0;
2749 ht40pwr[rfpath] -= pwrdiff[rfpath];
2751 else if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20)
2754 pwrdiff[rfpath] = priv->TxPwrbandEdgeHt20[rfpath][0];
2755 else if (channel >= 11)
2756 pwrdiff[rfpath] = priv->TxPwrbandEdgeHt20[rfpath][1];
2758 pwrdiff[rfpath] = 0;
2760 ht20pwr[rfpath] -= pwrdiff[rfpath];
2762 #if 0//cosa, it doesn't need to add the offset here
2764 powerlevelOFDM24G -= pwrdiff[rfpath];
2768 if (priv->rf_type == RF_2T2R)
2770 // HT 20/40 must decide if they need to minus BD pwr offset
2771 if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40)
2772 ant_pwr_diff = ht40pwr[1] - ht40pwr[0];
2774 ant_pwr_diff = ht20pwr[1] - ht20pwr[0];
2776 if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20)
2778 if (channel <= 1 || channel >= 11)
2780 //RTPRINT(FPHY, PHY_TXPWR,
2781 //("HT20 Band-edge pwrdiff[A/B]=%d/%d, ant_pwr_diff=%d(B-A=%d-%d)\n",
2782 //pwrdiff[0], pwrdiff[1], ant_pwr_diff, ht20pwr[1], ht20pwr[0]));
2787 if (channel <= 3 || channel >= 9)
2789 //RTPRINT(FPHY, PHY_TXPWR,
2790 //("HT40 Band-edge pwrdiff[A/B]=%d/%d, ant_pwr_diff=%d(B-A=%d-%d)\n",
2791 //pwrdiff[0], pwrdiff[1], ant_pwr_diff, ht40pwr[1], ht40pwr[0]));
2795 #if 0//cosa, useless
2796 // Read HT/Legacy OFDM diff
2797 legacy_ant_pwr_diff= pHalData->TxPwrLegacyHtDiff[RF90_PATH_A][index];
2801 //Cosa added for protection, the reg rFPGA0_TxGainStage
2802 // range is from 7~-8, index = 0x0~0xf
2803 if(ant_pwr_diff > 7)
2805 if(ant_pwr_diff < -8)
2808 //RTPRINT(FPHY, PHY_TXPWR,
2809 //("CCK/HT Power index = %x/%x(%d/%d), ant_pwr_diff=%d\n",
2810 //powerlevel, powerlevelOFDM24G, powerlevel, powerlevelOFDM24G, ant_pwr_diff));
2812 ant_pwr_diff &= 0xf;
2814 // Antenna TX power difference
2815 priv->AntennaTxPwDiff[2] = 0;// RF-D, don't care
2816 priv->AntennaTxPwDiff[1] = 0;// RF-C, don't care
2817 priv->AntennaTxPwDiff[0] = (u8)(ant_pwr_diff); // RF-B
2819 // Antenna gain offset from B/C/D to A
2820 u4RegValue = ( priv->AntennaTxPwDiff[2]<<8 |
2821 priv->AntennaTxPwDiff[1]<<4 |
2822 priv->AntennaTxPwDiff[0] );
2824 // Notify Tx power difference for B/C/D to A!!!
2825 rtl8192_setBBreg(dev, rFPGA0_TxGainStage, (bXBTxAGC|bXCTxAGC|bXDTxAGC), u4RegValue);
2830 // CCX 2 S31, AP control of client transmit power:
2831 // 1. We shall not exceed Cell Power Limit as possible as we can.
2832 // 2. Tolerance is +/- 5dB.
2833 // 3. 802.11h Power Contraint takes higher precedence over CCX Cell Power Limit.
2836 // 1. 802.11h power contraint
2838 // 071011, by rcnjko.
2840 #ifdef TODO //WB, 11h has not implemented now.
2841 if( priv->ieee80211->iw_mode != IW_MODE_INFRA && priv->bWithCcxCellPwr &&
2842 channel == priv->ieee80211->current_network.channel)// & priv->ieee80211->mAssoc )
2844 u8 CckCellPwrIdx = phy_DbmToTxPwrIdx(dev, WIRELESS_MODE_B, priv->CcxCellPwr);
2845 u8 LegacyOfdmCellPwrIdx = phy_DbmToTxPwrIdx(dev, WIRELESS_MODE_G, priv->CcxCellPwr);
2846 u8 OfdmCellPwrIdx = phy_DbmToTxPwrIdx(dev, WIRELESS_MODE_N_24G, priv->CcxCellPwr);
2848 RT_TRACE(COMP_TXAGC,
2849 ("CCX Cell Limit: %d dbm => CCK Tx power index : %d, Legacy OFDM Tx power index : %d, OFDM Tx power index: %d\n",
2850 priv->CcxCellPwr, CckCellPwrIdx, LegacyOfdmCellPwrIdx, OfdmCellPwrIdx));
2851 RT_TRACE(COMP_TXAGC,
2852 ("EEPROM channel(%d) => CCK Tx power index: %d, Legacy OFDM Tx power index : %d, OFDM Tx power index: %d\n",
2853 channel, powerlevel, powerlevelOFDM24G + priv->LegacyHTTxPowerDiff, powerlevelOFDM24G));
2856 if(powerlevel > CckCellPwrIdx)
2857 powerlevel = CckCellPwrIdx;
2858 // Legacy OFDM, HT OFDM
2859 if(powerlevelOFDM24G + priv->LegacyHTTxPowerDiff > LegacyOfdmCellPwrIdx)
2861 if((OfdmCellPwrIdx - priv->LegacyHTTxPowerDiff) > 0)
2863 powerlevelOFDM24G = OfdmCellPwrIdx - priv->LegacyHTTxPowerDiff;
2867 powerlevelOFDM24G = 0;
2871 RT_TRACE(COMP_TXAGC,
2872 ("Altered CCK Tx power index : %d, Legacy OFDM Tx power index: %d, OFDM Tx power index: %d\n",
2873 powerlevel, powerlevelOFDM24G + priv->LegacyHTTxPowerDiff, powerlevelOFDM24G));
2877 priv->CurrentCckTxPwrIdx = powerlevel;
2878 priv->CurrentOfdm24GTxPwrIdx = powerlevelOFDM24G;
2880 switch(priv->rf_chip)
2883 //PHY_SetRF8225CckTxPower(dev, powerlevel);
2884 //PHY_SetRF8225OfdmTxPower(dev, powerlevelOFDM24G);
2889 PHY_SetRF8256CCKTxPower(dev, powerlevel);
2890 PHY_SetRF8256OFDMTxPower(dev, powerlevelOFDM24G);
2895 PHY_RF6052SetCckTxPower(dev, powerlevel);
2896 PHY_RF6052SetOFDMTxPower(dev, powerlevelOFDM24G);
2909 // Update transmit power level of all channel supported.
2913 // By Bruce, 2008-02-04.
2915 bool PHY_UpdateTxPowerDbm8192S(struct net_device* dev, long powerInDbm)
2917 struct r8192_priv *priv = ieee80211_priv(dev);
2921 // TODO: A mode Tx power.
2922 u8 CckTxPwrIdx = phy_DbmToTxPwrIdx(dev, WIRELESS_MODE_B, powerInDbm);
2923 u8 OfdmTxPwrIdx = phy_DbmToTxPwrIdx(dev, WIRELESS_MODE_N_24G, powerInDbm);
2925 if(OfdmTxPwrIdx - priv->LegacyHTTxPowerDiff > 0)
2926 OfdmTxPwrIdx -= priv->LegacyHTTxPowerDiff;
2930 for(idx = 0; idx < 14; idx++)
2932 priv->TxPowerLevelCCK[idx] = CckTxPwrIdx;
2933 priv->TxPowerLevelCCK_A[idx] = CckTxPwrIdx;
2934 priv->TxPowerLevelCCK_C[idx] = CckTxPwrIdx;
2935 priv->TxPowerLevelOFDM24G[idx] = OfdmTxPwrIdx;
2936 priv->TxPowerLevelOFDM24G_A[idx] = OfdmTxPwrIdx;
2937 priv->TxPowerLevelOFDM24G_C[idx] = OfdmTxPwrIdx;
2939 for (rf_path = 0; rf_path < 2; rf_path++)
2941 priv->RfTxPwrLevelCck[rf_path][idx] = CckTxPwrIdx;
2942 priv->RfTxPwrLevelOfdm1T[rf_path][idx] = \
2943 priv->RfTxPwrLevelOfdm2T[rf_path][idx] = OfdmTxPwrIdx;
2947 PHY_SetTxPowerLevel8192S(dev, priv->chan);
2954 When beacon interval is changed, the values of the
2955 hw registers should be modified.
2956 By tynli, 2008.10.24.
2960 extern void PHY_SetBeaconHwReg( struct net_device* dev, u16 BeaconInterval)
2964 NewBeaconNum = BeaconInterval *32 - 64;
2965 //PlatformEFIOWrite4Byte(Adapter, WFM3+4, NewBeaconNum);
2966 //PlatformEFIOWrite4Byte(Adapter, WFM3, 0xB026007C);
2967 write_nic_dword(dev, WFM3+4, NewBeaconNum);
2968 write_nic_dword(dev, WFM3, 0xB026007C);
2973 // Map dBm into Tx power index according to
2974 // current HW model, for example, RF and PA, and
2975 // current wireless mode.
2976 // By Bruce, 2008-01-29.
2978 static u8 phy_DbmToTxPwrIdx(
2979 struct net_device* dev,
2980 WIRELESS_MODE WirelessMode,
2984 //struct r8192_priv *priv = ieee80211_priv(dev);
2990 // Tested by MP, we found that CCK Index 0 equals to -7dbm, OFDM legacy equals to
2991 // 3dbm, and OFDM HT equals to 0dbm repectively.
2993 // The mapping may be different by different NICs. Do not use this formula for what needs accurate result.
2994 // By Bruce, 2008-01-29.
2996 switch(WirelessMode)
2998 case WIRELESS_MODE_B:
3002 case WIRELESS_MODE_G:
3003 case WIRELESS_MODE_N_24G:
3010 if((PowerInDbm - Offset) > 0)
3012 TxPwrIdx = (u8)((PowerInDbm - Offset) * 2);
3019 // Tx Power Index is too large.
3020 if(TxPwrIdx > MAX_TXPWR_IDX_NMODE_92S)
3021 TxPwrIdx = MAX_TXPWR_IDX_NMODE_92S;
3027 // Map Tx power index into dBm according to
3028 // current HW model, for example, RF and PA, and
3029 // current wireless mode.
3030 // By Bruce, 2008-01-29.
3032 static long phy_TxPwrIdxToDbm(
3033 struct net_device* dev,
3034 WIRELESS_MODE WirelessMode,
3038 //struct r8192_priv *priv = ieee80211_priv(dev);
3043 // Tested by MP, we found that CCK Index 0 equals to -7dbm, OFDM legacy equals to
3044 // 3dbm, and OFDM HT equals to 0dbm repectively.
3046 // The mapping may be different by different NICs. Do not use this formula for what needs accurate result.
3047 // By Bruce, 2008-01-29.
3049 switch(WirelessMode)
3051 case WIRELESS_MODE_B:
3055 case WIRELESS_MODE_G:
3056 case WIRELESS_MODE_N_24G:
3063 PwrOutDbm = TxPwrIdx / 2 + Offset; // Discard the decimal part.
3070 PHY_ScanOperationBackup8192S(
3071 IN PADAPTER Adapter,
3076 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
3077 PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
3079 u1Byte initial_gain;
3084 #if(RTL8192S_DISABLE_FW_DM == 0)
3086 if(!Adapter->bDriverStopped)
3090 case SCAN_OPT_BACKUP:
3092 // <Roger_Notes> We halt FW DIG and disable high ppower both two DMs here
3093 // and resume both two DMs while scan complete.
3096 Adapter->HalFunc.SetFwCmdHandler(Adapter, FW_CMD_PAUSE_DM_BY_SCAN);
3099 case SCAN_OPT_RESTORE:
3101 // <Roger_Notes> We resume DIG and enable high power both two DMs here and
3102 // recover earlier DIG settings.
3105 Adapter->HalFunc.SetFwCmdHandler(Adapter, FW_CMD_RESUME_DM_BY_SCAN);
3109 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Unknown Scan Backup Operation. \n"));
3118 void PHY_InitialGain8192S(struct net_device* dev,u8 Operation )
3121 //struct r8192_priv *priv = ieee80211_priv(dev);
3125 #if 0 // For 8192s test disable
3126 if(!dev->bDriverStopped)
3131 RT_TRACE(COMP_SCAN, DBG_LOUD, ("IG_Backup, backup the initial gain.\n"));
3132 initial_gain = priv->DefaultInitialGain[0];
3133 BitMask = bMaskByte0;
3134 if(DM_DigTable.Dig_Algorithm == DIG_ALGO_BY_FALSE_ALARM)
3135 PHY_SetMacReg(dev, UFWP, bMaskByte1, 0x8); // FW DIG OFF
3136 pMgntInfo->InitGain_Backup.XAAGCCore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XAAGCCore1, BitMask);
3137 pMgntInfo->InitGain_Backup.XBAGCCore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XBAGCCore1, BitMask);
3138 pMgntInfo->InitGain_Backup.XCAGCCore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XCAGCCore1, BitMask);
3139 pMgntInfo->InitGain_Backup.XDAGCCore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XDAGCCore1, BitMask);
3140 BitMask = bMaskByte2;
3141 pMgntInfo->InitGain_Backup.CCA = (u8)rtl8192_QueryBBReg(dev, rCCK0_CCA, BitMask);
3143 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Scan InitialGainBackup 0xc50 is %x\n",pMgntInfo->InitGain_Backup.XAAGCCore1));
3144 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Scan InitialGainBackup 0xc58 is %x\n",pMgntInfo->InitGain_Backup.XBAGCCore1));
3145 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Scan InitialGainBackup 0xc60 is %x\n",pMgntInfo->InitGain_Backup.XCAGCCore1));
3146 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Scan InitialGainBackup 0xc68 is %x\n",pMgntInfo->InitGain_Backup.XDAGCCore1));
3147 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Scan InitialGainBackup 0xa0a is %x\n",pMgntInfo->InitGain_Backup.CCA));
3149 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Write scan initial gain = 0x%x \n", initial_gain));
3150 write_nic_byte(dev, rOFDM0_XAAGCCore1, initial_gain);
3151 write_nic_byte(dev, rOFDM0_XBAGCCore1, initial_gain);
3152 write_nic_byte(dev, rOFDM0_XCAGCCore1, initial_gain);
3153 write_nic_byte(dev, rOFDM0_XDAGCCore1, initial_gain);
3156 RT_TRACE(COMP_SCAN, DBG_LOUD, ("IG_Restore, restore the initial gain.\n"));
3157 BitMask = 0x7f; //Bit0~ Bit6
3158 if(DM_DigTable.Dig_Algorithm == DIG_ALGO_BY_FALSE_ALARM)
3159 PHY_SetMacReg(dev, UFWP, bMaskByte1, 0x8); // FW DIG OFF
3161 rtl8192_setBBreg(dev, rOFDM0_XAAGCCore1, BitMask, (u32)pMgntInfo->InitGain_Backup.XAAGCCore1);
3162 rtl8192_setBBreg(dev, rOFDM0_XBAGCCore1, BitMask, (u32)pMgntInfo->InitGain_Backup.XBAGCCore1);
3163 rtl8192_setBBreg(dev, rOFDM0_XCAGCCore1, BitMask, (u32)pMgntInfo->InitGain_Backup.XCAGCCore1);
3164 rtl8192_setBBreg(dev, rOFDM0_XDAGCCore1, BitMask, (u32)pMgntInfo->InitGain_Backup.XDAGCCore1);
3165 BitMask = (BIT22|BIT23);
3166 rtl8192_setBBreg(dev, rCCK0_CCA, BitMask, (u32)pMgntInfo->InitGain_Backup.CCA);
3168 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Scan BBInitialGainRestore 0xc50 is %x\n",pMgntInfo->InitGain_Backup.XAAGCCore1));
3169 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Scan BBInitialGainRestore 0xc58 is %x\n",pMgntInfo->InitGain_Backup.XBAGCCore1));
3170 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Scan BBInitialGainRestore 0xc60 is %x\n",pMgntInfo->InitGain_Backup.XCAGCCore1));
3171 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Scan BBInitialGainRestore 0xc68 is %x\n",pMgntInfo->InitGain_Backup.XDAGCCore1));
3172 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Scan BBInitialGainRestore 0xa0a is %x\n",pMgntInfo->InitGain_Backup.CCA));
3174 if(DM_DigTable.Dig_Algorithm == DIG_ALGO_BY_FALSE_ALARM)
3175 PHY_SetMacReg(dev, UFWP, bMaskByte1, 0x1); // FW DIG ON
3178 RT_TRACE(COMP_SCAN, DBG_LOUD, ("Unknown IG Operation. \n"));
3185 /*-----------------------------------------------------------------------------
3186 * Function: SetBWModeCallback8190Pci()
3188 * Overview: Timer callback function for SetSetBWMode
3190 * Input: PRT_TIMER pTimer
3196 * Note: (1) We do not take j mode into consideration now
3197 * (2) Will two workitem of "switch channel" and "switch channel bandwidth" run
3199 *---------------------------------------------------------------------------*/
3200 // use in phy only (in win it's timer)
3201 void PHY_SetBWModeCallback8192S(struct net_device *dev)
3203 struct r8192_priv *priv = ieee80211_priv(dev);
3208 // Added it for 20/40 mhz switch time evaluation by guangan 070531
3210 //u8Byte BeginTime, EndTime;
3213 RT_TRACE(COMP_SWBW, "==>SetBWModeCallback8190Pci() Switch to %s bandwidth\n", \
3214 priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz");
3216 if(priv->rf_chip == RF_PSEUDO_11N)
3218 priv->SetBWModeInProgress= FALSE;
3225 // Added it for 20/40 mhz switch time evaluation by guangan 070531
3226 //NowL = read_nic_dword(dev, TSFR);
3227 //NowH = read_nic_dword(dev, TSFR+4);
3228 //BeginTime = ((u8Byte)NowH << 32) + NowL;
3231 //3//<1>Set MAC register
3233 regBwOpMode = read_nic_byte(dev, BW_OPMODE);
3234 regRRSR_RSC = read_nic_byte(dev, RRSR+2);
3236 switch(priv->CurrentChannelBW)
3238 case HT_CHANNEL_WIDTH_20:
3239 //if(priv->card_8192_version >= VERSION_8192S_BCUT)
3240 // write_nic_byte(dev, rFPGA0_AnalogParameter2, 0x58);
3242 regBwOpMode |= BW_OPMODE_20MHZ;
3243 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
3244 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
3247 case HT_CHANNEL_WIDTH_20_40:
3248 //if(priv->card_8192_version >= VERSION_8192S_BCUT)
3249 // write_nic_byte(dev, rFPGA0_AnalogParameter2, 0x18);
3251 regBwOpMode &= ~BW_OPMODE_20MHZ;
3252 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
3253 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
3254 regRRSR_RSC = (regRRSR_RSC&0x90) |(priv->nCur40MhzPrimeSC<<5);
3255 write_nic_byte(dev, RRSR+2, regRRSR_RSC);
3259 RT_TRACE(COMP_DBG, "SetBWModeCallback8190Pci():\
3260 unknown Bandwidth: %#X\n",priv->CurrentChannelBW);
3265 //3//<2>Set PHY related register
3267 switch(priv->CurrentChannelBW)
3270 case HT_CHANNEL_WIDTH_20:
3271 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x0);
3272 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x0);
3274 // Correct the tx power for CCK rate in 40M. Suggest by YN, 20071207
3275 // It is set in Tx descriptor for 8192x series
3276 //write_nic_dword(dev, rCCK0_TxFilter1, 0x1a1b0000);
3277 //write_nic_dword(dev, rCCK0_TxFilter2, 0x090e1317);
3278 //write_nic_dword(dev, rCCK0_DebugPort, 0x00000204);
3280 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskDWord, 0x1a1b0000);
3281 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, 0x090e1317);
3282 rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskDWord, 0x00000204);
3283 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00300000, 3);
3286 if (priv->card_8192_version >= VERSION_8192S_BCUT)
3287 write_nic_byte(dev, rFPGA0_AnalogParameter2, 0x58);
3293 case HT_CHANNEL_WIDTH_20_40:
3294 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x1);
3295 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x1);
3297 // Correct the tx power for CCK rate in 40M. Suggest by YN, 20071207
3298 //write_nic_dword(dev, rCCK0_TxFilter1, 0x35360000);
3299 //write_nic_dword(dev, rCCK0_TxFilter2, 0x121c252e);
3300 //write_nic_dword(dev, rCCK0_DebugPort, 0x00000409);
3302 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskDWord, 0x35360000);
3303 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, 0x121c252e);
3304 rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskDWord, 0x00000409);
3307 // Set Control channel to upper or lower. These settings are required only for 40MHz
3308 rtl8192_setBBreg(dev, rCCK0_System, bCCKSideBand, (priv->nCur40MhzPrimeSC>>1));
3309 rtl8192_setBBreg(dev, rOFDM1_LSTF, 0xC00, priv->nCur40MhzPrimeSC);
3311 //rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00300000, 3);
3312 if (priv->card_8192_version >= VERSION_8192S_BCUT)
3313 write_nic_byte(dev, rFPGA0_AnalogParameter2, 0x18);
3318 RT_TRACE(COMP_DBG, "SetBWModeCallback8190Pci(): unknown Bandwidth: %#X\n"\
3319 ,priv->CurrentChannelBW);
3323 //Skip over setting of J-mode in BB register here. Default value is "None J mode". Emily 20070315
3325 // Added it for 20/40 mhz switch time evaluation by guangan 070531
3326 //NowL = read_nic_dword(dev, TSFR);
3327 //NowH = read_nic_dword(dev, TSFR+4);
3328 //EndTime = ((u8Byte)NowH << 32) + NowL;
3329 //RT_TRACE(COMP_SCAN, DBG_LOUD, ("SetBWModeCallback8190Pci: time of SetBWMode = %I64d us!\n", (EndTime - BeginTime)));
3331 //3<3>Set RF related register
3332 switch( priv->rf_chip )
3335 //PHY_SetRF8225Bandwidth(dev, priv->CurrentChannelBW);
3339 // Please implement this function in Hal8190PciPhy8256.c
3340 //PHY_SetRF8256Bandwidth(dev, priv->CurrentChannelBW);
3344 // Please implement this function in Hal8190PciPhy8258.c
3345 // PHY_SetRF8258Bandwidth();
3353 PHY_RF6052SetBandwidth(dev, priv->CurrentChannelBW);
3356 printk("Unknown rf_chip: %d\n", priv->rf_chip);
3360 priv->SetBWModeInProgress= FALSE;
3362 RT_TRACE(COMP_SWBW, "<==SetBWModeCallback8190Pci() \n" );
3366 /*-----------------------------------------------------------------------------
3367 * Function: SetBWMode8190Pci()
3369 * Overview: This function is export to "HalCommon" moudule
3371 * Input: PADAPTER Adapter
3372 * HT_CHANNEL_WIDTH Bandwidth //20M or 40M
3378 * Note: We do not take j mode into consideration now
3379 *---------------------------------------------------------------------------*/
3380 //extern void PHY_SetBWMode8192S( struct net_device* dev,
3381 // HT_CHANNEL_WIDTH Bandwidth, // 20M or 40M
3382 // HT_EXTCHNL_OFFSET Offset // Upper, Lower, or Don't care
3383 void rtl8192_SetBWMode(struct net_device *dev, HT_CHANNEL_WIDTH Bandwidth, HT_EXTCHNL_OFFSET Offset)
3385 struct r8192_priv *priv = ieee80211_priv(dev);
3386 HT_CHANNEL_WIDTH tmpBW = priv->CurrentChannelBW;
3389 // Modified it for 20/40 mhz switch by guangan 070531
3393 //if(priv->SwChnlInProgress)
3394 // if(pMgntInfo->bScanInProgress)
3396 // RT_TRACE(COMP_SCAN, DBG_LOUD, ("SetBWMode8190Pci() %s Exit because bScanInProgress!\n",
3397 // Bandwidth == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz"));
3401 // if(priv->SetBWModeInProgress)
3403 // // Modified it for 20/40 mhz switch by guangan 070531
3404 // RT_TRACE(COMP_SCAN, DBG_LOUD, ("SetBWMode8190Pci() %s cancel last timer because SetBWModeInProgress!\n",
3405 // Bandwidth == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz"));
3406 // PlatformCancelTimer(dev, &priv->SetBWModeTimer);
3410 if(priv->SetBWModeInProgress)
3413 priv->SetBWModeInProgress= TRUE;
3415 priv->CurrentChannelBW = Bandwidth;
3417 if(Offset==HT_EXTCHNL_OFFSET_LOWER)
3418 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_UPPER;
3419 else if(Offset==HT_EXTCHNL_OFFSET_UPPER)
3420 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_LOWER;
3422 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
3425 if(!priv->bDriverStopped)
3428 PlatformScheduleWorkItem(&(priv->SetBWModeWorkItem));//SetBWModeCallback8192SUsbWorkItem
3430 PlatformSetTimer(dev, &(priv->SetBWModeTimer), 0);//PHY_SetBWModeCallback8192S
3434 if((priv->up) )// && !(RT_CANNOT_IO(Adapter) && Adapter->bInSetPower) )
3437 PHY_SetBWModeCallback8192S(dev);
3438 #elif defined(RTL8192SU)
3439 SetBWModeCallback8192SUsbWorkItem(dev);
3444 RT_TRACE(COMP_SCAN, "PHY_SetBWMode8192S() SetBWModeInProgress FALSE driver sleep or unload\n");
3445 priv->SetBWModeInProgress= FALSE;
3446 priv->CurrentChannelBW = tmpBW;
3450 // use in phy only (in win it's timer)
3451 void PHY_SwChnlCallback8192S(struct net_device *dev)
3454 struct r8192_priv *priv = ieee80211_priv(dev);
3458 RT_TRACE(COMP_CH, "==>SwChnlCallback8190Pci(), switch to channel %d\n", priv->chan);
3463 if(priv->rf_chip == RF_PSEUDO_11N)
3465 priv->SwChnlInProgress=FALSE;
3466 return; //return immediately if it is peudo-phy
3470 if(!priv->SwChnlInProgress)
3473 //if(!phy_SwChnlStepByStep(dev, priv->CurrentChannel, &priv->SwChnlStage, &priv->SwChnlStep, &delay))
3474 if(!phy_SwChnlStepByStep(dev, priv->chan, &priv->SwChnlStage, &priv->SwChnlStep, &delay))
3479 //PlatformSetTimer(dev, &priv->SwChnlTimer, delay);
3480 //mod_timer(&priv->SwChnlTimer, jiffies + MSECS(delay));
3481 //==>PHY_SwChnlCallback8192S(dev); for 92se
3482 //==>SwChnlCallback8192SUsb(dev) for 92su
3489 priv->SwChnlInProgress=FALSE;
3495 // Call after initialization
3496 //extern void PHY_SwChnl8192S(struct net_device* dev, u8 channel)
3497 u8 rtl8192_phy_SwChnl(struct net_device* dev, u8 channel)
3499 struct r8192_priv *priv = ieee80211_priv(dev);
3500 //u8 tmpchannel =channel;
3501 //bool bResult = false;
3506 if(priv->SwChnlInProgress)
3509 if(priv->SetBWModeInProgress)
3512 //--------------------------------------------
3513 switch(priv->ieee80211->mode)
3515 case WIRELESS_MODE_A:
3516 case WIRELESS_MODE_N_5G:
3518 RT_TRACE(COMP_ERR, "WIRELESS_MODE_A but channel<=14");
3523 case WIRELESS_MODE_B:
3525 RT_TRACE(COMP_ERR, "WIRELESS_MODE_B but channel>14");
3530 case WIRELESS_MODE_G:
3531 case WIRELESS_MODE_N_24G:
3533 RT_TRACE(COMP_ERR, "WIRELESS_MODE_G but channel>14");
3539 ;//RT_TRACE(COMP_ERR, "Invalid WirelessMode(%#x)!!\n", priv->ieee80211->mode);
3542 //--------------------------------------------
3544 priv->SwChnlInProgress = TRUE;
3550 priv->SwChnlStage=0;
3553 if((priv->up))// && !(RT_CANNOT_IO(Adapter) && Adapter->bInSetPower))
3556 PHY_SwChnlCallback8192S(dev);
3557 #elif defined(RTL8192SU)
3558 SwChnlCallback8192SUsbWorkItem(dev);
3563 RT_TRACE(COMP_SCAN, "PHY_SwChnl8192S SwChnlInProgress TRUE schdule workitem done\n");
3567 RT_TRACE(COMP_SCAN, "PHY_SwChnl8192S SwChnlInProgress FALSE schdule workitem error\n");
3568 priv->SwChnlInProgress = false;
3569 priv->CurrentChannel = tmpchannel;
3575 RT_TRACE(COMP_SCAN, "PHY_SwChnl8192S SwChnlInProgress FALSE driver sleep or unload\n");
3576 priv->SwChnlInProgress = false;
3577 //priv->CurrentChannel = tmpchannel;
3585 // Switch channel synchronously. Called by SwChnlByDelayHandler.
3587 // Implemented by Bruce, 2008-02-14.
3588 // The following procedure is operted according to SwChanlCallback8190Pci().
3589 // However, this procedure is performed synchronously which should be running under
3593 void PHY_SwChnlPhy8192S( // Only called during initialize
3594 struct net_device* dev,
3598 struct r8192_priv *priv = ieee80211_priv(dev);
3600 RT_TRACE(COMP_SCAN, "==>PHY_SwChnlPhy8192S(), switch to channel %d.\n", priv->chan);
3604 if(RT_CANNOT_IO(dev))
3608 // Channel Switching is in progress.
3609 if(priv->SwChnlInProgress)
3612 //return immediately if it is peudo-phy
3613 if(priv->rf_chip == RF_PSEUDO_11N)
3615 priv->SwChnlInProgress=FALSE;
3619 priv->SwChnlInProgress = TRUE;
3625 priv->SwChnlStage = 0;
3626 priv->SwChnlStep = 0;
3628 phy_FinishSwChnlNow(dev,channel);
3630 priv->SwChnlInProgress = FALSE;
3635 phy_SetSwChnlCmdArray(
3636 SwChnlCmd* CmdTable,
3647 if(CmdTable == NULL)
3649 //RT_ASSERT(FALSE, ("phy_SetSwChnlCmdArray(): CmdTable cannot be NULL.\n"));
3652 if(CmdTableIdx >= CmdTableSz)
3655 // ("phy_SetSwChnlCmdArray(): Access invalid index, please check size of the table, CmdTableIdx:%d, CmdTableSz:%d\n",
3656 //CmdTableIdx, CmdTableSz));
3660 pCmd = CmdTable + CmdTableIdx;
3661 pCmd->CmdID = CmdID;
3662 pCmd->Para1 = Para1;
3663 pCmd->Para2 = Para2;
3664 pCmd->msDelay = msDelay;
3671 phy_SwChnlStepByStep(
3672 struct net_device* dev,
3679 struct r8192_priv *priv = ieee80211_priv(dev);
3680 //PCHANNEL_ACCESS_SETTING pChnlAccessSetting;
3681 SwChnlCmd PreCommonCmd[MAX_PRECMD_CNT];
3682 u32 PreCommonCmdCnt;
3683 SwChnlCmd PostCommonCmd[MAX_POSTCMD_CNT];
3684 u32 PostCommonCmdCnt;
3685 SwChnlCmd RfDependCmd[MAX_RFDEPENDCMD_CNT];
3687 SwChnlCmd *CurrentCmd = NULL;
3690 //RT_ASSERT((dev != NULL), ("Adapter should not be NULL\n"));
3691 //RT_ASSERT(IsLegalChannel(dev, channel), ("illegal channel: %d\n", channel));
3692 RT_TRACE(COMP_CH, "===========>%s(), channel:%d, stage:%d, step:%d\n", __FUNCTION__, channel, *stage, *step);
3693 //RT_ASSERT((pHalData != NULL), ("pHalData should not be NULL\n"));
3694 #ifdef ENABLE_DOT11D
3695 if (!IsLegalChannel(priv->ieee80211, channel))
3697 RT_TRACE(COMP_ERR, "=============>set to illegal channel:%d\n", channel);
3698 return true; //return true to tell upper caller function this channel setting is finished! Or it will in while loop.
3702 //pChnlAccessSetting = &Adapter->MgntInfo.Info8185.ChannelAccessSetting;
3703 //RT_ASSERT((pChnlAccessSetting != NULL), ("pChnlAccessSetting should not be NULL\n"));
3705 //for(eRFPath = RF90_PATH_A; eRFPath <priv->NumTotalRFPath; eRFPath++)
3706 //for(eRFPath = 0; eRFPath <priv->NumTotalRFPath; eRFPath++)
3708 // <1> Fill up pre common command.
3709 PreCommonCmdCnt = 0;
3710 phy_SetSwChnlCmdArray(PreCommonCmd, PreCommonCmdCnt++, MAX_PRECMD_CNT,
3711 CmdID_SetTxPowerLevel, 0, 0, 0);
3712 phy_SetSwChnlCmdArray(PreCommonCmd, PreCommonCmdCnt++, MAX_PRECMD_CNT,
3713 CmdID_End, 0, 0, 0);
3715 // <2> Fill up post common command.
3716 PostCommonCmdCnt = 0;
3718 phy_SetSwChnlCmdArray(PostCommonCmd, PostCommonCmdCnt++, MAX_POSTCMD_CNT,
3719 CmdID_End, 0, 0, 0);
3721 // <3> Fill up RF dependent command.
3723 switch( priv->rf_chip )
3726 if (channel < 1 || channel > 14)
3727 RT_TRACE(COMP_ERR, "illegal channel for zebra:%d\n", channel);
3728 //RT_ASSERT((channel >= 1 && channel <= 14), ("illegal channel for Zebra: %d\n", channel));
3729 // 2008/09/04 MH Change channel.
3730 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
3731 CmdID_RF_WriteReg, rRfChannel, channel, 10);
3732 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
3733 CmdID_End, 0, 0, 0);
3737 if (channel < 1 || channel > 14)
3738 RT_TRACE(COMP_ERR, "illegal channel for zebra:%d\n", channel);
3739 // TEST!! This is not the table for 8256!!
3740 //RT_ASSERT((channel >= 1 && channel <= 14), ("illegal channel for Zebra: %d\n", channel));
3741 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
3742 CmdID_RF_WriteReg, rRfChannel, channel, 10);
3743 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
3744 CmdID_End, 0, 0, 0);
3748 if (channel < 1 || channel > 14)
3749 RT_TRACE(COMP_ERR, "illegal channel for zebra:%d\n", channel);
3750 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
3751 CmdID_RF_WriteReg, RF_CHNLBW, channel, 10);
3752 phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
3753 CmdID_End, 0, 0, 0);
3760 //RT_ASSERT(FALSE, ("Unknown rf_chip: %d\n", priv->rf_chip));
3770 CurrentCmd=&PreCommonCmd[*step];
3773 CurrentCmd=&RfDependCmd[*step];
3776 CurrentCmd=&PostCommonCmd[*step];
3780 if(CurrentCmd->CmdID==CmdID_End)
3794 switch(CurrentCmd->CmdID)
3796 case CmdID_SetTxPowerLevel:
3797 //if(priv->card_8192_version > VERSION_8190_BD)
3798 PHY_SetTxPowerLevel8192S(dev,channel);
3800 case CmdID_WritePortUlong:
3801 write_nic_dword(dev, CurrentCmd->Para1, CurrentCmd->Para2);
3803 case CmdID_WritePortUshort:
3804 write_nic_word(dev, CurrentCmd->Para1, (u16)CurrentCmd->Para2);
3806 case CmdID_WritePortUchar:
3807 write_nic_byte(dev, CurrentCmd->Para1, (u8)CurrentCmd->Para2);
3809 case CmdID_RF_WriteReg: // Only modify channel for the register now !!!!!
3810 for(eRFPath = 0; eRFPath <priv->NumTotalRFPath; eRFPath++)
3812 #if (defined RTL8192SE ||defined RTL8192SU )
3813 // For new T65 RF 0222d register 0x18 bit 0-9 = channel number.
3814 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, CurrentCmd->Para1, 0x1f, (CurrentCmd->Para2));
3815 //printk("====>%x, %x, read_back:%x\n", CurrentCmd->Para2,CurrentCmd->Para1, rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, CurrentCmd->Para1, 0x1f));
3817 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, CurrentCmd->Para1, bRFRegOffsetMask, ((CurrentCmd->Para2)<<7));
3827 //cosa }/*for(Number of RF paths)*/
3829 (*delay)=CurrentCmd->msDelay;
3831 RT_TRACE(COMP_CH, "<===========%s(), channel:%d, stage:%d, step:%d\n", __FUNCTION__, channel, *stage, *step);
3835 //called PHY_SwChnlPhy8192S, SwChnlCallback8192SUsbWorkItem
3838 phy_FinishSwChnlNow( // We should not call this function directly
3839 struct net_device* dev,
3843 struct r8192_priv *priv = ieee80211_priv(dev);
3846 while(!phy_SwChnlStepByStep(dev,channel,&priv->SwChnlStage,&priv->SwChnlStep,&delay))
3856 /*-----------------------------------------------------------------------------
3857 * Function: PHYCheckIsLegalRfPath8190Pci()
3859 * Overview: Check different RF type to execute legal judgement. If RF Path is illegal
3860 * We will return false.
3870 * 11/15/2007 MHC Create Version 0.
3872 *---------------------------------------------------------------------------*/
3873 //called by rtl8192_phy_QueryRFReg, rtl8192_phy_SetRFReg, PHY_SetRFPowerState8192SUsb
3875 //PHY_CheckIsLegalRfPath8192S(
3876 // struct net_device* dev,
3878 u8 rtl8192_phy_CheckIsLegalRFPath(struct net_device* dev, u32 eRFPath)
3880 // struct r8192_priv *priv = ieee80211_priv(dev);
3881 bool rtValue = TRUE;
3883 // NOt check RF Path now.!
3885 if (priv->rf_type == RF_1T2R && eRFPath != RF90_PATH_A)
3889 if (priv->rf_type == RF_1T2R && eRFPath != RF90_PATH_A)
3896 } /* PHY_CheckIsLegalRfPath8192S */
3900 /*-----------------------------------------------------------------------------
3901 * Function: PHY_IQCalibrate8192S()
3903 * Overview: After all MAC/PHY/RF is configued. We must execute IQ calibration
3904 * to improve RF EVM!!?
3906 * Input: IN PADAPTER pAdapter
3914 * 10/07/2008 MHC Create. Document from SD3 RFSI Jenyu.
3916 *---------------------------------------------------------------------------*/
3917 //called by InitializeAdapter8192SE
3919 PHY_IQCalibrate( struct net_device* dev)
3921 //struct r8192_priv *priv = ieee80211_priv(dev);
3927 // 1. Check QFN68 or 64 92S (Read from EEPROM)
3932 // For 1T2R IQK only now !!!
3933 for (i = 0; i < 10; i++)
3936 rtl8192_setBBreg(dev, 0xc04, bMaskDWord, 0x00a05430);
3937 //PlatformStallExecution(5);
3939 rtl8192_setBBreg(dev, 0xc08, bMaskDWord, 0x000800e4);
3941 rtl8192_setBBreg(dev, 0xe28, bMaskDWord, 0x80800000);
3943 rtl8192_setBBreg(dev, 0xe40, bMaskDWord, 0x02140148);
3945 rtl8192_setBBreg(dev, 0xe44, bMaskDWord, 0x681604a2);
3947 rtl8192_setBBreg(dev, 0xe4c, bMaskDWord, 0x000028d1);
3949 rtl8192_setBBreg(dev, 0xe60, bMaskDWord, 0x0214014d);
3951 rtl8192_setBBreg(dev, 0xe64, bMaskDWord, 0x281608ba);
3953 rtl8192_setBBreg(dev, 0xe6c, bMaskDWord, 0x000028d1);
3955 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xfb000001);
3957 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xf8000001);
3959 rtl8192_setBBreg(dev, 0xc04, bMaskDWord, 0x00a05433);
3961 rtl8192_setBBreg(dev, 0xc08, bMaskDWord, 0x000000e4);
3963 rtl8192_setBBreg(dev, 0xe28, bMaskDWord, 0x0);
3966 reg = rtl8192_QueryBBReg(dev, 0xeac, bMaskDWord);
3968 // Readback IQK value and rewrite
3969 if (!(reg&(BIT27|BIT28|BIT30|BIT31)))
3971 old_value = (rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord) & 0x3FF);
3973 // Calibrate init gain for A path for TX0
3974 X = (rtl8192_QueryBBReg(dev, 0xe94, bMaskDWord) & 0x03FF0000)>>16;
3975 TXA[RF90_PATH_A] = (X * old_value)/0x100;
3976 reg = rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord);
3977 reg = (reg & 0xFFFFFC00) | (u32)TXA[RF90_PATH_A];
3978 rtl8192_setBBreg(dev, 0xc80, bMaskDWord, reg);
3981 // Calibrate init gain for C path for TX0
3982 Y = ( rtl8192_QueryBBReg(dev, 0xe9C, bMaskDWord) & 0x03FF0000)>>16;
3983 TX0[RF90_PATH_C] = ((Y * old_value)/0x100);
3984 reg = rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord);
3985 reg = (reg & 0xffc0ffff) |((u32) (TX0[RF90_PATH_C]&0x3F)<<16);
3986 rtl8192_setBBreg(dev, 0xc80, bMaskDWord, reg);
3987 reg = rtl8192_QueryBBReg(dev, 0xc94, bMaskDWord);
3988 reg = (reg & 0x0fffffff) |(((Y&0x3c0)>>6)<<28);
3989 rtl8192_setBBreg(dev, 0xc94, bMaskDWord, reg);
3992 // Calibrate RX A and B for RX0
3993 reg = rtl8192_QueryBBReg(dev, 0xc14, bMaskDWord);
3994 X = (rtl8192_QueryBBReg(dev, 0xea4, bMaskDWord) & 0x03FF0000)>>16;
3995 reg = (reg & 0xFFFFFC00) |X;
3996 rtl8192_setBBreg(dev, 0xc14, bMaskDWord, reg);
3997 Y = (rtl8192_QueryBBReg(dev, 0xeac, bMaskDWord) & 0x003F0000)>>16;
3998 reg = (reg & 0xFFFF03FF) |Y<<10;
3999 rtl8192_setBBreg(dev, 0xc14, bMaskDWord, reg);
4001 old_value = (rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord) & 0x3FF);
4003 // Calibrate init gain for A path for TX1 !!!!!!
4004 X = (rtl8192_QueryBBReg(dev, 0xeb4, bMaskDWord) & 0x03FF0000)>>16;
4005 reg = rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord);
4006 TXA[RF90_PATH_A] = (X * old_value) / 0x100;
4007 reg = (reg & 0xFFFFFC00) | TXA[RF90_PATH_A];
4008 rtl8192_setBBreg(dev, 0xc88, bMaskDWord, reg);
4011 // Calibrate init gain for C path for TX1
4012 Y = (rtl8192_QueryBBReg(dev, 0xebc, bMaskDWord)& 0x03FF0000)>>16;
4013 TX0[RF90_PATH_C] = ((Y * old_value)/0x100);
4014 reg = rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord);
4015 reg = (reg & 0xffc0ffff) |( (TX0[RF90_PATH_C]&0x3F)<<16);
4016 rtl8192_setBBreg(dev, 0xc88, bMaskDWord, reg);
4017 reg = rtl8192_QueryBBReg(dev, 0xc9c, bMaskDWord);
4018 reg = (reg & 0x0fffffff) |(((Y&0x3c0)>>6)<<28);
4019 rtl8192_setBBreg(dev, 0xc9c, bMaskDWord, reg);
4022 // Calibrate RX A and B for RX1
4023 reg = rtl8192_QueryBBReg(dev, 0xc1c, bMaskDWord);
4024 X = (rtl8192_QueryBBReg(dev, 0xec4, bMaskDWord) & 0x03FF0000)>>16;
4025 reg = (reg & 0xFFFFFC00) |X;
4026 rtl8192_setBBreg(dev, 0xc1c, bMaskDWord, reg);
4028 Y = (rtl8192_QueryBBReg(dev, 0xecc, bMaskDWord) & 0x003F0000)>>16;
4029 reg = (reg & 0xFFFF03FF) |Y<<10;
4030 rtl8192_setBBreg(dev, 0xc1c, bMaskDWord, reg);
4033 RT_TRACE(COMP_INIT, "PHY_IQCalibrate OK\n");
4041 // 3. QFN64. Not enabled now !!! We must use different gain table for 1T2R.
4047 /*-----------------------------------------------------------------------------
4048 * Function: PHY_IQCalibrateBcut()
4050 * Overview: After all MAC/PHY/RF is configued. We must execute IQ calibration
4051 * to improve RF EVM!!?
4053 * Input: IN PADAPTER pAdapter
4061 * 11/18/2008 MHC Create. Document from SD3 RFSI Jenyu.
4062 * 92S B-cut QFN 68 pin IQ calibration procedure.doc
4064 *---------------------------------------------------------------------------*/
4065 extern void PHY_IQCalibrateBcut(struct net_device* dev)
4067 //struct r8192_priv *priv = ieee80211_priv(dev);
4068 //PMGNT_INFO pMgntInfo = &pAdapter->MgntInfo;
4073 u32 calibrate_set[13] = {0};
4077 // 0. Check QFN68 or 64 92S (Read from EEPROM/EFUSE)
4080 // 1. Save e70~ee0 register setting, and load calibration setting
4083 0xee0[31:0]=0x3fed92fb;
4084 0xedc[31:0] =0x3fed92fb;
4085 0xe70[31:0] =0x3fed92fb;
4086 0xe74[31:0] =0x3fed92fb;
4087 0xe78[31:0] =0x3fed92fb;
4088 0xe7c[31:0]= 0x3fed92fb;
4089 0xe80[31:0]= 0x3fed92fb;
4090 0xe84[31:0]= 0x3fed92fb;
4091 0xe88[31:0]= 0x3fed92fb;
4092 0xe8c[31:0]= 0x3fed92fb;
4093 0xed0[31:0]= 0x3fed92fb;
4094 0xed4[31:0]= 0x3fed92fb;
4095 0xed8[31:0]= 0x3fed92fb;
4097 calibrate_set [0] = 0xee0;
4098 calibrate_set [1] = 0xedc;
4099 calibrate_set [2] = 0xe70;
4100 calibrate_set [3] = 0xe74;
4101 calibrate_set [4] = 0xe78;
4102 calibrate_set [5] = 0xe7c;
4103 calibrate_set [6] = 0xe80;
4104 calibrate_set [7] = 0xe84;
4105 calibrate_set [8] = 0xe88;
4106 calibrate_set [9] = 0xe8c;
4107 calibrate_set [10] = 0xed0;
4108 calibrate_set [11] = 0xed4;
4109 calibrate_set [12] = 0xed8;
4110 //RT_TRACE(COMP_INIT, DBG_LOUD, ("Save e70~ee0 register setting\n"));
4111 for (i = 0; i < 13; i++)
4113 load_value[i] = rtl8192_QueryBBReg(dev, calibrate_set[i], bMaskDWord);
4114 rtl8192_setBBreg(dev, calibrate_set[i], bMaskDWord, 0x3fed92fb);
4118 RfPiEnable = (u8)rtl8192_QueryBBReg(dev, rFPGA0_XA_HSSIParameter1, BIT8);
4123 // For 1T2R IQK only now !!!
4124 for (i = 0; i < 10; i++)
4126 RT_TRACE(COMP_INIT, "IQK -%d\n", i);
4127 //BB switch to PI mode. If default is PI mode, ignoring 2 commands below.
4128 if (!RfPiEnable) //if original is SI mode, then switch to PI mode.
4130 //DbgPrint("IQK Switch to PI mode\n");
4131 rtl8192_setBBreg(dev, 0x820, bMaskDWord, 0x01000100);
4132 rtl8192_setBBreg(dev, 0x828, bMaskDWord, 0x01000100);
4136 // 2. IQ calibration & LO leakage calibration
4137 rtl8192_setBBreg(dev, 0xc04, bMaskDWord, 0x00a05430);
4139 rtl8192_setBBreg(dev, 0xc08, bMaskDWord, 0x000800e4);
4141 rtl8192_setBBreg(dev, 0xe28, bMaskDWord, 0x80800000);
4143 //path-A IQ K and LO K gain setting
4144 rtl8192_setBBreg(dev, 0xe40, bMaskDWord, 0x02140102);
4146 rtl8192_setBBreg(dev, 0xe44, bMaskDWord, 0x681604c2);
4148 //set LO calibration
4149 rtl8192_setBBreg(dev, 0xe4c, bMaskDWord, 0x000028d1);
4151 //path-B IQ K and LO K gain setting
4152 rtl8192_setBBreg(dev, 0xe60, bMaskDWord, 0x02140102);
4154 rtl8192_setBBreg(dev, 0xe64, bMaskDWord, 0x28160d05);
4157 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xfb000000);
4159 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xf8000000);
4166 rtl8192_setBBreg(dev, 0xe6c, bMaskDWord, 0x020028d1);
4169 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xfb000000);
4171 rtl8192_setBBreg(dev, 0xe48, bMaskDWord, 0xf8000000);
4176 rtl8192_setBBreg(dev, 0xc04, bMaskDWord, 0x00a05433);
4178 rtl8192_setBBreg(dev, 0xc08, bMaskDWord, 0x000000e4);
4180 rtl8192_setBBreg(dev, 0xe28, bMaskDWord, 0x0);
4182 if (!RfPiEnable) //if original is SI mode, then switch to PI mode.
4184 //DbgPrint("IQK Switch back to SI mode\n");
4185 rtl8192_setBBreg(dev, 0x820, bMaskDWord, 0x01000000);
4186 rtl8192_setBBreg(dev, 0x828, bMaskDWord, 0x01000000);
4190 reg = rtl8192_QueryBBReg(dev, 0xeac, bMaskDWord);
4192 // 3. check fail bit, and fill BB IQ matrix
4193 // Readback IQK value and rewrite
4194 if (!(reg&(BIT27|BIT28|BIT30|BIT31)))
4196 old_value = (rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord) & 0x3FF);
4198 // Calibrate init gain for A path for TX0
4199 X = (rtl8192_QueryBBReg(dev, 0xe94, bMaskDWord) & 0x03FF0000)>>16;
4200 TXA[RF90_PATH_A] = (X * old_value)/0x100;
4201 reg = rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord);
4202 reg = (reg & 0xFFFFFC00) | (u32)TXA[RF90_PATH_A];
4203 rtl8192_setBBreg(dev, 0xc80, bMaskDWord, reg);
4206 // Calibrate init gain for C path for TX0
4207 Y = ( rtl8192_QueryBBReg(dev, 0xe9C, bMaskDWord) & 0x03FF0000)>>16;
4208 TX0[RF90_PATH_C] = ((Y * old_value)/0x100);
4209 reg = rtl8192_QueryBBReg(dev, 0xc80, bMaskDWord);
4210 reg = (reg & 0xffc0ffff) |((u32) (TX0[RF90_PATH_C]&0x3F)<<16);
4211 rtl8192_setBBreg(dev, 0xc80, bMaskDWord, reg);
4212 reg = rtl8192_QueryBBReg(dev, 0xc94, bMaskDWord);
4213 reg = (reg & 0x0fffffff) |(((Y&0x3c0)>>6)<<28);
4214 rtl8192_setBBreg(dev, 0xc94, bMaskDWord, reg);
4217 // Calibrate RX A and B for RX0
4218 reg = rtl8192_QueryBBReg(dev, 0xc14, bMaskDWord);
4219 X = (rtl8192_QueryBBReg(dev, 0xea4, bMaskDWord) & 0x03FF0000)>>16;
4220 reg = (reg & 0xFFFFFC00) |X;
4221 rtl8192_setBBreg(dev, 0xc14, bMaskDWord, reg);
4222 Y = (rtl8192_QueryBBReg(dev, 0xeac, bMaskDWord) & 0x003F0000)>>16;
4223 reg = (reg & 0xFFFF03FF) |Y<<10;
4224 rtl8192_setBBreg(dev, 0xc14, bMaskDWord, reg);
4226 old_value = (rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord) & 0x3FF);
4228 // Calibrate init gain for A path for TX1 !!!!!!
4229 X = (rtl8192_QueryBBReg(dev, 0xeb4, bMaskDWord) & 0x03FF0000)>>16;
4230 reg = rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord);
4231 TXA[RF90_PATH_A] = (X * old_value) / 0x100;
4232 reg = (reg & 0xFFFFFC00) | TXA[RF90_PATH_A];
4233 rtl8192_setBBreg(dev, 0xc88, bMaskDWord, reg);
4236 // Calibrate init gain for C path for TX1
4237 Y = (rtl8192_QueryBBReg(dev, 0xebc, bMaskDWord)& 0x03FF0000)>>16;
4238 TX0[RF90_PATH_C] = ((Y * old_value)/0x100);
4239 reg = rtl8192_QueryBBReg(dev, 0xc88, bMaskDWord);
4240 reg = (reg & 0xffc0ffff) |( (TX0[RF90_PATH_C]&0x3F)<<16);
4241 rtl8192_setBBreg(dev, 0xc88, bMaskDWord, reg);
4242 reg = rtl8192_QueryBBReg(dev, 0xc9c, bMaskDWord);
4243 reg = (reg & 0x0fffffff) |(((Y&0x3c0)>>6)<<28);
4244 rtl8192_setBBreg(dev, 0xc9c, bMaskDWord, reg);
4247 // Calibrate RX A and B for RX1
4248 reg = rtl8192_QueryBBReg(dev, 0xc1c, bMaskDWord);
4249 X = (rtl8192_QueryBBReg(dev, 0xec4, bMaskDWord) & 0x03FF0000)>>16;
4250 reg = (reg & 0xFFFFFC00) |X;
4251 rtl8192_setBBreg(dev, 0xc1c, bMaskDWord, reg);
4253 Y = (rtl8192_QueryBBReg(dev, 0xecc, bMaskDWord) & 0x003F0000)>>16;
4254 reg = (reg & 0xFFFF03FF) |Y<<10;
4255 rtl8192_setBBreg(dev, 0xc1c, bMaskDWord, reg);
4258 RT_TRACE(COMP_INIT, "PHY_IQCalibrate OK\n");
4265 // 4. Reload e70~ee0 register setting.
4267 //RT_TRACE(COMP_INIT, DBG_LOUD, ("Reload e70~ee0 register setting.\n"));
4268 for (i = 0; i < 13; i++)
4269 rtl8192_setBBreg(dev, calibrate_set[i], bMaskDWord, load_value[i]);
4273 // 3. QFN64. Not enabled now !!! We must use different gain table for 1T2R.
4278 } // PHY_IQCalibrateBcut
4282 // Move from phycfg.c to gen.c to be code independent later
4284 //-------------------------Move to other DIR later----------------------------*/
4285 //#if (DEV_BUS_TYPE == USB_INTERFACE)
4288 // use in phy only (in win it's timer)
4289 void SwChnlCallback8192SUsb(struct net_device *dev)
4292 struct r8192_priv *priv = ieee80211_priv(dev);
4296 RT_TRACE(COMP_SCAN, "==>SwChnlCallback8190Pci(), switch to channel\
4303 if(priv->rf_chip == RF_PSEUDO_11N)
4305 priv->SwChnlInProgress=FALSE;
4306 return; //return immediately if it is peudo-phy
4310 if(!priv->SwChnlInProgress)
4313 if(!phy_SwChnlStepByStep(dev, priv->chan, &priv->SwChnlStage, &priv->SwChnlStep, &delay))
4317 //PlatformSetTimer(dev, &priv->SwChnlTimer, delay);
4325 priv->SwChnlInProgress=FALSE;
4333 // Callback routine of the work item for switch channel.
4335 // use in phy only (in win it's work)
4336 void SwChnlCallback8192SUsbWorkItem(struct net_device *dev )
4338 struct r8192_priv *priv = ieee80211_priv(dev);
4340 RT_TRACE(COMP_TRACE, "==> SwChnlCallback8192SUsbWorkItem()\n");
4342 if(pAdapter->bInSetPower && RT_USB_CANNOT_IO(pAdapter))
4344 RT_TRACE(COMP_SCAN, DBG_LOUD, ("<== SwChnlCallback8192SUsbWorkItem() SwChnlInProgress FALSE driver sleep or unload\n"));
4346 pHalData->SwChnlInProgress = FALSE;
4350 phy_FinishSwChnlNow(dev, priv->chan);
4351 priv->SwChnlInProgress = FALSE;
4353 RT_TRACE(COMP_TRACE, "<== SwChnlCallback8192SUsbWorkItem()\n");
4357 /*-----------------------------------------------------------------------------
4358 * Function: SetBWModeCallback8192SUsb()
4360 * Overview: Timer callback function for SetSetBWMode
4362 * Input: PRT_TIMER pTimer
4368 * Note: (1) We do not take j mode into consideration now
4369 * (2) Will two workitem of "switch channel" and "switch channel bandwidth" run
4371 *---------------------------------------------------------------------------*/
4372 //====>//rtl8192_SetBWMode
4373 // use in phy only (in win it's timer)
4374 void SetBWModeCallback8192SUsb(struct net_device *dev)
4376 struct r8192_priv *priv = ieee80211_priv(dev);
4379 // Added it for 20/40 mhz switch time evaluation by guangan 070531
4381 //u8Byte BeginTime, EndTime;
4384 RT_TRACE(COMP_SCAN, "==>SetBWModeCallback8190Pci() Switch to %s bandwidth\n", \
4385 priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz");
4387 if(priv->rf_chip == RF_PSEUDO_11N)
4389 priv->SetBWModeInProgress= FALSE;
4396 // Added it for 20/40 mhz switch time evaluation by guangan 070531
4397 //NowL = read_nic_dword(dev, TSFR);
4398 //NowH = read_nic_dword(dev, TSFR+4);
4399 //BeginTime = ((u8Byte)NowH << 32) + NowL;
4401 //3<1>Set MAC register
4402 regBwOpMode = read_nic_byte(dev, BW_OPMODE);
4403 regRRSR_RSC = read_nic_byte(dev, RRSR+2);
4405 switch(priv->CurrentChannelBW)
4407 case HT_CHANNEL_WIDTH_20:
4408 regBwOpMode |= BW_OPMODE_20MHZ;
4409 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
4410 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
4413 case HT_CHANNEL_WIDTH_20_40:
4414 regBwOpMode &= ~BW_OPMODE_20MHZ;
4415 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
4416 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
4418 regRRSR_RSC = (regRRSR_RSC&0x90) |(priv->nCur40MhzPrimeSC<<5);
4419 write_nic_byte(dev, RRSR+2, regRRSR_RSC);
4423 RT_TRACE(COMP_DBG, "SetChannelBandwidth8190Pci():\
4424 unknown Bandwidth: %#X\n",priv->CurrentChannelBW);
4428 //3 <2>Set PHY related register
4429 switch(priv->CurrentChannelBW)
4431 case HT_CHANNEL_WIDTH_20:
4432 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x0);
4433 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x0);
4435 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00300000, 3);
4437 // Correct the tx power for CCK rate in 20M. Suggest by YN, 20071207
4438 //write_nic_dword(dev, rCCK0_TxFilter1, 0x1a1b0000);
4439 //write_nic_dword(dev, rCCK0_TxFilter2, 0x090e1317);
4440 //write_nic_dword(dev, rCCK0_DebugPort, 0x00000204);
4441 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskDWord, 0x1a1b0000);
4442 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, 0x090e1317);
4443 rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskDWord, 0x00000204);
4444 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00300000, 3);
4447 if (priv->card_8192_version >= VERSION_8192S_BCUT)
4448 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter2, 0xff, 0x58);
4451 case HT_CHANNEL_WIDTH_20_40:
4452 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x1);
4453 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x1);
4454 rtl8192_setBBreg(dev, rCCK0_System, bCCKSideBand, (priv->nCur40MhzPrimeSC>>1));
4455 rtl8192_setBBreg(dev, rOFDM1_LSTF, 0xC00, priv->nCur40MhzPrimeSC);
4457 // Correct the tx power for CCK rate in 40M. Suggest by YN, 20071207
4458 //PHY_SetBBReg(Adapter, rCCK0_TxFilter1, bMaskDWord, 0x35360000);
4459 //PHY_SetBBReg(Adapter, rCCK0_TxFilter2, bMaskDWord, 0x121c252e);
4460 //PHY_SetBBReg(Adapter, rCCK0_DebugPort, bMaskDWord, 0x00000409);
4461 //PHY_SetBBReg(Adapter, rFPGA0_AnalogParameter1, bADClkPhase, 0);
4463 if (priv->card_8192_version >= VERSION_8192S_BCUT)
4464 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter2, 0xff, 0x18);
4468 RT_TRACE(COMP_DBG, "SetChannelBandwidth8190Pci(): unknown Bandwidth: %#X\n"\
4469 ,priv->CurrentChannelBW);
4473 //Skip over setting of J-mode in BB register here. Default value is "None J mode". Emily 20070315
4475 // Added it for 20/40 mhz switch time evaluation by guangan 070531
4476 //NowL = read_nic_dword(dev, TSFR);
4477 //NowH = read_nic_dword(dev, TSFR+4);
4478 //EndTime = ((u8Byte)NowH << 32) + NowL;
4479 //RT_TRACE(COMP_SCAN, DBG_LOUD, ("SetBWModeCallback8190Pci: time of SetBWMode = %I64d us!\n", (EndTime - BeginTime)));
4482 //3<3>Set RF related register
4483 switch( priv->rf_chip )
4486 PHY_SetRF8225Bandwidth(dev, priv->CurrentChannelBW);
4490 // Please implement this function in Hal8190PciPhy8256.c
4491 //PHY_SetRF8256Bandwidth(dev, priv->CurrentChannelBW);
4495 PHY_RF6052SetBandwidth(dev, priv->CurrentChannelBW);
4499 // Please implement this function in Hal8190PciPhy8258.c
4500 // PHY_SetRF8258Bandwidth();
4508 //RT_ASSERT(FALSE, ("Unknown rf_chip: %d\n", priv->rf_chip));
4512 priv->SetBWModeInProgress= FALSE;
4514 RT_TRACE(COMP_SCAN, "<==SetBWMode8190Pci()" );
4518 // Callback routine of the work item for set bandwidth mode.
4520 // use in phy only (in win it's work)
4521 void SetBWModeCallback8192SUsbWorkItem(struct net_device *dev)
4523 struct r8192_priv *priv = ieee80211_priv(dev);
4526 // Added it for 20/40 mhz switch time evaluation by guangan 070531
4528 //u8Byte BeginTime, EndTime;
4531 RT_TRACE(COMP_SCAN, "==>SetBWModeCallback8192SUsbWorkItem() Switch to %s bandwidth\n", \
4532 priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz");
4534 if(priv->rf_chip == RF_PSEUDO_11N)
4536 priv->SetBWModeInProgress= FALSE;
4543 // Added it for 20/40 mhz switch time evaluation by guangan 070531
4544 //NowL = read_nic_dword(dev, TSFR);
4545 //NowH = read_nic_dword(dev, TSFR+4);
4546 //BeginTime = ((u8Byte)NowH << 32) + NowL;
4548 //3<1>Set MAC register
4549 regBwOpMode = read_nic_byte(dev, BW_OPMODE);
4550 regRRSR_RSC = read_nic_byte(dev, RRSR+2);
4552 switch(priv->CurrentChannelBW)
4554 case HT_CHANNEL_WIDTH_20:
4555 regBwOpMode |= BW_OPMODE_20MHZ;
4556 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
4557 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
4560 case HT_CHANNEL_WIDTH_20_40:
4561 regBwOpMode &= ~BW_OPMODE_20MHZ;
4562 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
4563 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
4564 regRRSR_RSC = (regRRSR_RSC&0x90) |(priv->nCur40MhzPrimeSC<<5);
4565 write_nic_byte(dev, RRSR+2, regRRSR_RSC);
4570 RT_TRACE(COMP_DBG, "SetBWModeCallback8192SUsbWorkItem():\
4571 unknown Bandwidth: %#X\n",priv->CurrentChannelBW);
4575 //3 <2>Set PHY related register
4576 switch(priv->CurrentChannelBW)
4578 case HT_CHANNEL_WIDTH_20:
4579 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x0);
4580 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x0);
4583 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, bADClkPhase, 1);
4585 // Correct the tx power for CCK rate in 20M. Suggest by YN, 20071207
4586 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskDWord, 0x1a1b0000);
4587 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, 0x090e1317);
4588 rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskDWord, 0x00000204);
4589 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00100000, 1);
4592 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter2, 0xff, 0x58);
4595 case HT_CHANNEL_WIDTH_20_40:
4596 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x1);
4597 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x1);
4599 rtl8192_setBBreg(dev, rCCK0_System, bCCKSideBand, (priv->nCur40MhzPrimeSC>>1));
4601 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, bADClkPhase, 0);
4603 rtl8192_setBBreg(dev, rOFDM1_LSTF, 0xC00, priv->nCur40MhzPrimeSC);
4604 // Correct the tx power for CCK rate in 40M. Suggest by YN, 20071207
4605 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskDWord, 0x35360000);
4606 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, 0x121c252e);
4607 rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskDWord, 0x00000409);
4610 // Set Control channel to upper or lower. These settings are required only for 40MHz
4611 rtl8192_setBBreg(dev, rCCK0_System, bCCKSideBand, (priv->nCur40MhzPrimeSC>>1));
4612 rtl8192_setBBreg(dev, rOFDM1_LSTF, 0xC00, priv->nCur40MhzPrimeSC);
4614 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter2, 0xff, 0x18);
4620 RT_TRACE(COMP_DBG, "SetBWModeCallback8192SUsbWorkItem(): unknown Bandwidth: %#X\n"\
4621 ,priv->CurrentChannelBW);
4625 //Skip over setting of J-mode in BB register here. Default value is "None J mode". Emily 20070315
4627 //3<3>Set RF related register
4628 switch( priv->rf_chip )
4631 PHY_SetRF8225Bandwidth(dev, priv->CurrentChannelBW);
4635 // Please implement this function in Hal8190PciPhy8256.c
4636 //PHY_SetRF8256Bandwidth(dev, priv->CurrentChannelBW);
4640 PHY_RF6052SetBandwidth(dev, priv->CurrentChannelBW);
4644 // Please implement this function in Hal8190PciPhy8258.c
4645 // PHY_SetRF8258Bandwidth();
4653 //RT_ASSERT(FALSE, ("Unknown rf_chip: %d\n", priv->rf_chip));
4657 priv->SetBWModeInProgress= FALSE;
4659 RT_TRACE(COMP_SCAN, "<==SetBWModeCallback8192SUsbWorkItem()" );
4662 //--------------------------Move to oter DIR later-------------------------------*/
4664 void InitialGain8192S(struct net_device *dev, u8 Operation)
4667 struct r8192_priv *priv = ieee80211_priv(dev);
4673 void InitialGain819xUsb(struct net_device *dev, u8 Operation)
4675 struct r8192_priv *priv = ieee80211_priv(dev);
4677 priv->InitialGainOperateType = Operation;
4681 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
4682 queue_delayed_work(priv->priv_wq,&priv->initialgain_operate_wq,0);
4684 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
4685 schedule_task(&priv->initialgain_operate_wq);
4687 queue_work(priv->priv_wq,&priv->initialgain_operate_wq);
4693 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
4694 extern void InitialGainOperateWorkItemCallBack(struct work_struct *work)
4696 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
4697 struct r8192_priv *priv = container_of(dwork,struct r8192_priv,initialgain_operate_wq);
4698 struct net_device *dev = priv->ieee80211->dev;
4700 extern void InitialGainOperateWorkItemCallBack(struct net_device *dev)
4702 struct r8192_priv *priv = ieee80211_priv(dev);
4704 #define SCAN_RX_INITIAL_GAIN 0x17
4705 #define POWER_DETECTION_TH 0x08
4710 Operation = priv->InitialGainOperateType;
4715 RT_TRACE(COMP_SCAN, "IG_Backup, backup the initial gain.\n");
4716 initial_gain = SCAN_RX_INITIAL_GAIN;//priv->DefaultInitialGain[0];//
4717 BitMask = bMaskByte0;
4718 if(dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
4719 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); // FW DIG OFF
4720 priv->initgain_backup.xaagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XAAGCCore1, BitMask);
4721 priv->initgain_backup.xbagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XBAGCCore1, BitMask);
4722 priv->initgain_backup.xcagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XCAGCCore1, BitMask);
4723 priv->initgain_backup.xdagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XDAGCCore1, BitMask);
4724 BitMask = bMaskByte2;
4725 priv->initgain_backup.cca = (u8)rtl8192_QueryBBReg(dev, rCCK0_CCA, BitMask);
4727 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc50 is %x\n",priv->initgain_backup.xaagccore1);
4728 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc58 is %x\n",priv->initgain_backup.xbagccore1);
4729 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc60 is %x\n",priv->initgain_backup.xcagccore1);
4730 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc68 is %x\n",priv->initgain_backup.xdagccore1);
4731 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xa0a is %x\n",priv->initgain_backup.cca);
4733 RT_TRACE(COMP_SCAN, "Write scan initial gain = 0x%x \n", initial_gain);
4734 write_nic_byte(dev, rOFDM0_XAAGCCore1, initial_gain);
4735 write_nic_byte(dev, rOFDM0_XBAGCCore1, initial_gain);
4736 write_nic_byte(dev, rOFDM0_XCAGCCore1, initial_gain);
4737 write_nic_byte(dev, rOFDM0_XDAGCCore1, initial_gain);
4738 RT_TRACE(COMP_SCAN, "Write scan 0xa0a = 0x%x \n", POWER_DETECTION_TH);
4739 write_nic_byte(dev, 0xa0a, POWER_DETECTION_TH);
4742 RT_TRACE(COMP_SCAN, "IG_Restore, restore the initial gain.\n");
4743 BitMask = 0x7f; //Bit0~ Bit6
4744 if(dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
4745 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); // FW DIG OFF
4747 rtl8192_setBBreg(dev, rOFDM0_XAAGCCore1, BitMask, (u32)priv->initgain_backup.xaagccore1);
4748 rtl8192_setBBreg(dev, rOFDM0_XBAGCCore1, BitMask, (u32)priv->initgain_backup.xbagccore1);
4749 rtl8192_setBBreg(dev, rOFDM0_XCAGCCore1, BitMask, (u32)priv->initgain_backup.xcagccore1);
4750 rtl8192_setBBreg(dev, rOFDM0_XDAGCCore1, BitMask, (u32)priv->initgain_backup.xdagccore1);
4751 BitMask = bMaskByte2;
4752 rtl8192_setBBreg(dev, rCCK0_CCA, BitMask, (u32)priv->initgain_backup.cca);
4754 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc50 is %x\n",priv->initgain_backup.xaagccore1);
4755 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc58 is %x\n",priv->initgain_backup.xbagccore1);
4756 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc60 is %x\n",priv->initgain_backup.xcagccore1);
4757 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc68 is %x\n",priv->initgain_backup.xdagccore1);
4758 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xa0a is %x\n",priv->initgain_backup.cca);
4760 PHY_SetTxPowerLevel8192S(dev,priv->ieee80211->current_network.channel);
4762 if(dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
4763 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x1); // FW DIG ON
4766 RT_TRACE(COMP_SCAN, "Unknown IG Operation. \n");
4771 #endif // #if (DEV_BUS_TYPE == USB_INTERFACE)
4773 //-----------------------------------------------------------------------------
4775 // Schedule workitem to send specific CMD IO to FW.
4776 // Added by Roger, 2008.12.03.
4778 //-----------------------------------------------------------------------------
4779 bool HalSetFwCmd8192S(struct net_device* dev, FW_CMD_IO_TYPE FwCmdIO)
4781 struct r8192_priv *priv = ieee80211_priv(dev);
4782 u16 FwCmdWaitCounter = 0;
4784 u16 FwCmdWaitLimit = 1000;
4786 //if(IS_HARDWARE_TYPE_8192SU(Adapter) && Adapter->bInHctTest)
4787 if(priv->bInHctTest)
4790 RT_TRACE(COMP_CMD, "-->HalSetFwCmd8192S(): Set FW Cmd(%x), SetFwCmdInProgress(%d)\n", (u32)FwCmdIO, priv->SetFwCmdInProgress);
4792 // Will be done by high power respectively.
4793 if(FwCmdIO==FW_CMD_DIG_HALT || FwCmdIO==FW_CMD_DIG_RESUME)
4795 RT_TRACE(COMP_CMD, "<--HalSetFwCmd8192S(): Set FW Cmd(%x)\n", (u32)FwCmdIO);
4800 while(priv->SetFwCmdInProgress && FwCmdWaitCounter<FwCmdWaitLimit)
4802 //if(RT_USB_CANNOT_IO(Adapter))
4804 // RT_TRACE(COMP_CMD, DBG_WARNING, ("HalSetFwCmd8192S(): USB can NOT IO!!\n"));
4808 RT_TRACE(COMP_CMD, "HalSetFwCmd8192S(): previous workitem not finish!!\n");
4810 FwCmdWaitCounter ++;
4811 RT_TRACE(COMP_CMD, "HalSetFwCmd8192S(): Wait 10 ms (%d times)...\n", FwCmdWaitCounter);
4815 if(FwCmdWaitCounter == FwCmdWaitLimit)
4817 //RT_ASSERT(FALSE, ("SetFwCmdIOWorkItemCallback(): Wait too logn to set FW CMD\n"));
4818 RT_TRACE(COMP_CMD, "HalSetFwCmd8192S(): Wait too logn to set FW CMD\n");
4822 if (priv->SetFwCmdInProgress)
4824 RT_TRACE(COMP_ERR, "<--HalSetFwCmd8192S(): Set FW Cmd(%#x)\n", FwCmdIO);
4827 priv->SetFwCmdInProgress = TRUE;
4828 priv->CurrentFwCmdIO = FwCmdIO; // Update current FW Cmd for callback use.
4830 phy_SetFwCmdIOCallback(dev);
4833 void ChkFwCmdIoDone(struct net_device* dev)
4835 u16 PollingCnt = 1000;
4839 {// Make sure that CMD IO has be accepted by FW.
4841 if(RT_USB_CANNOT_IO(Adapter))
4843 RT_TRACE(COMP_CMD, "ChkFwCmdIoDone(): USB can NOT IO!!\n");
4847 udelay(10); // sleep 20us
4848 tmpValue = read_nic_dword(dev, WFM5);
4851 RT_TRACE(COMP_CMD, "[FW CMD] Set FW Cmd success!!\n");
4856 RT_TRACE(COMP_CMD, "[FW CMD] Polling FW Cmd PollingCnt(%d)!!\n", PollingCnt);
4858 }while( --PollingCnt );
4862 RT_TRACE(COMP_ERR, "[FW CMD] Set FW Cmd fail!!\n");
4865 // Callback routine of the timer callback for FW Cmd IO.
4868 // This routine will send specific CMD IO to FW and check whether it is done.
4870 void phy_SetFwCmdIOCallback(struct net_device* dev)
4872 //struct net_device* dev = (struct net_device*) data;
4874 static u32 ScanRegister;
4875 struct r8192_priv *priv = ieee80211_priv(dev);
4878 RT_TRACE(COMP_CMD, "SetFwCmdIOTimerCallback(): driver is going to unload\n");
4882 RT_TRACE(COMP_CMD, "--->SetFwCmdIOTimerCallback(): Cmd(%#x), SetFwCmdInProgress(%d)\n", priv->CurrentFwCmdIO, priv->SetFwCmdInProgress);
4884 switch(priv->CurrentFwCmdIO)
4886 case FW_CMD_HIGH_PWR_ENABLE:
4887 if((priv->ieee80211->pHTInfo->IOTAction & HT_IOT_ACT_DISABLE_HIGH_POWER)==0)
4888 write_nic_dword(dev, WFM5, FW_HIGH_PWR_ENABLE);
4891 case FW_CMD_HIGH_PWR_DISABLE:
4892 write_nic_dword(dev, WFM5, FW_HIGH_PWR_DISABLE);
4895 case FW_CMD_DIG_RESUME:
4896 write_nic_dword(dev, WFM5, FW_DIG_RESUME);
4899 case FW_CMD_DIG_HALT:
4900 write_nic_dword(dev, WFM5, FW_DIG_HALT);
4904 // <Roger_Notes> The following FW CMD IO was combined into single operation
4905 // (i.e., to prevent number of system workitem out of resource!!).
4908 case FW_CMD_RESUME_DM_BY_SCAN:
4909 RT_TRACE(COMP_CMD, "[FW CMD] Set HIGHPWR enable and DIG resume!!\n");
4910 if((priv->ieee80211->pHTInfo->IOTAction & HT_IOT_ACT_DISABLE_HIGH_POWER)==0)
4912 write_nic_dword(dev, WFM5, FW_HIGH_PWR_ENABLE); //break;
4913 ChkFwCmdIoDone(dev);
4915 write_nic_dword(dev, WFM5, FW_DIG_RESUME);
4918 case FW_CMD_PAUSE_DM_BY_SCAN:
4919 RT_TRACE(COMP_CMD, "[FW CMD] Set HIGHPWR disable and DIG halt!!\n");
4920 write_nic_dword(dev, WFM5, FW_HIGH_PWR_DISABLE); //break;
4921 ChkFwCmdIoDone(dev);
4922 write_nic_dword(dev, WFM5, FW_DIG_HALT);
4926 // <Roger_Notes> The following FW CMD IO should be checked
4927 // (i.e., workitem schedule timing issue!!).
4930 case FW_CMD_DIG_DISABLE:
4931 RT_TRACE(COMP_CMD, "[FW CMD] Set DIG disable!!\n");
4932 write_nic_dword(dev, WFM5, FW_DIG_DISABLE);
4935 case FW_CMD_DIG_ENABLE:
4936 RT_TRACE(COMP_CMD, "[FW CMD] Set DIG enable!!\n");
4937 write_nic_dword(dev, WFM5, FW_DIG_ENABLE);
4940 case FW_CMD_RA_RESET:
4941 write_nic_dword(dev, WFM5, FW_RA_RESET);
4944 case FW_CMD_RA_ACTIVE:
4945 write_nic_dword(dev, WFM5, FW_RA_ACTIVE);
4948 case FW_CMD_RA_REFRESH_N:
4949 RT_TRACE(COMP_CMD, "[FW CMD] Set RA refresh!! N\n");
4950 if(priv->ieee80211->pHTInfo->IOTRaFunc & HT_IOT_RAFUNC_DISABLE_ALL)
4951 input = FW_RA_REFRESH;
4953 input = FW_RA_REFRESH | (priv->ieee80211->pHTInfo->IOTRaFunc << 8);
4954 write_nic_dword(dev, WFM5, input);
4956 case FW_CMD_RA_REFRESH_BG:
4957 RT_TRACE(COMP_CMD, "[FW CMD] Set RA refresh!! B/G\n");
4958 write_nic_dword(dev, WFM5, FW_RA_REFRESH);
4959 ChkFwCmdIoDone(dev);
4960 write_nic_dword(dev, WFM5, FW_RA_ENABLE_BG);
4963 case FW_CMD_IQK_ENABLE:
4964 write_nic_dword(dev, WFM5, FW_IQK_ENABLE);
4967 case FW_CMD_TXPWR_TRACK_ENABLE:
4968 write_nic_dword(dev, WFM5, FW_TXPWR_TRACK_ENABLE);
4971 case FW_CMD_TXPWR_TRACK_DISABLE:
4972 write_nic_dword(dev, WFM5, FW_TXPWR_TRACK_DISABLE);
4976 RT_TRACE(COMP_CMD,"Unknown FW Cmd IO(%#x)\n", priv->CurrentFwCmdIO);
4980 ChkFwCmdIoDone(dev);
4982 switch(priv->CurrentFwCmdIO)
4984 case FW_CMD_HIGH_PWR_DISABLE:
4985 //if(pMgntInfo->bTurboScan)
4987 //Lower initial gain
4988 rtl8192_setBBreg(dev, rOFDM0_XAAGCCore1, bMaskByte0, 0x17);
4989 rtl8192_setBBreg(dev, rOFDM0_XBAGCCore1, bMaskByte0, 0x17);
4991 rtl8192_setBBreg(dev, rCCK0_CCA, bMaskByte2, 0x40);
4992 // Disable OFDM Part
4993 rtl8192_setBBreg(dev, rOFDM0_TRMuxPar, bMaskByte2, 0x1);
4994 ScanRegister = rtl8192_QueryBBReg(dev, rOFDM0_RxDetector1,bMaskDWord);
4995 rtl8192_setBBreg(dev, rOFDM0_RxDetector1, 0xf, 0xf);
4996 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0x0);
5000 case FW_CMD_HIGH_PWR_ENABLE:
5001 //if(pMgntInfo->bTurboScan)
5003 rtl8192_setBBreg(dev, rOFDM0_XAAGCCore1, bMaskByte0, 0x36);
5004 rtl8192_setBBreg(dev, rOFDM0_XBAGCCore1, bMaskByte0, 0x36);
5007 rtl8192_setBBreg(dev, rCCK0_CCA, bMaskByte2, 0x83);
5009 rtl8192_setBBreg(dev, rOFDM0_TRMuxPar, bMaskByte2, 0x0);
5011 //LZM ADD because sometimes there is no FW_CMD_HIGH_PWR_DISABLE, this value will be 0.
5012 if(ScanRegister != 0){
5013 rtl8192_setBBreg(dev, rOFDM0_RxDetector1, bMaskDWord, ScanRegister);
5016 if(priv->rf_type == RF_1T2R || priv->rf_type == RF_2T2R)
5017 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0x3);
5019 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0x1);
5024 priv->SetFwCmdInProgress = false;// Clear FW CMD operation flag.
5025 RT_TRACE(COMP_CMD, "<---SetFwCmdIOWorkItemCallback()\n");