3 #include "r819xU_phy.h"
4 #include "r819xU_phyreg.h"
5 #include "r8190_rtl8256.h"
7 #include "r819xU_firmware_img.h"
12 static u32 RF_CHANNEL_TABLE_ZEBRA[] = {
31 #define rtl819XPHY_REG_1T2RArray Rtl8192UsbPHY_REG_1T2RArray
32 #define rtl819XMACPHY_Array_PG Rtl8192UsbMACPHY_Array_PG
33 #define rtl819XMACPHY_Array Rtl8192UsbMACPHY_Array
34 #define rtl819XRadioA_Array Rtl8192UsbRadioA_Array
35 #define rtl819XRadioB_Array Rtl8192UsbRadioB_Array
36 #define rtl819XRadioC_Array Rtl8192UsbRadioC_Array
37 #define rtl819XRadioD_Array Rtl8192UsbRadioD_Array
38 #define rtl819XAGCTAB_Array Rtl8192UsbAGCTAB_Array
40 /******************************************************************************
41 *function: This function read BB parameters from Header file we gen,
42 * and do register read/write
43 * input: u32 dwBitMask //taget bit pos in the addr to be modified
45 * return: u32 return the shift bit bit position of the mask
46 * ****************************************************************************/
47 u32 rtl8192_CalculateBitShift(u32 dwBitMask)
52 if (((dwBitMask>>i)&0x1) == 1)
57 /******************************************************************************
58 *function: This function check different RF type to execute legal judgement. If RF Path is illegal, we will return false.
61 * return: 0(illegal, false), 1(legal,true)
62 * ***************************************************************************/
63 u8 rtl8192_phy_CheckIsLegalRFPath(struct net_device* dev, u32 eRFPath)
66 struct r8192_priv *priv = ieee80211_priv(dev);
67 if (priv->rf_type == RF_2T4R)
69 else if (priv->rf_type == RF_1T2R)
71 if (eRFPath == RF90_PATH_A || eRFPath == RF90_PATH_B)
73 else if (eRFPath == RF90_PATH_C || eRFPath == RF90_PATH_D)
78 /******************************************************************************
79 *function: This function set specific bits to BB register
80 * input: net_device dev
81 * u32 dwRegAddr //target addr to be modified
82 * u32 dwBitMask //taget bit pos in the addr to be modified
83 * u32 dwData //value to be write
87 * ****************************************************************************/
88 void rtl8192_setBBreg(struct net_device* dev, u32 dwRegAddr, u32 dwBitMask, u32 dwData)
91 u32 OriginalValue, BitShift, NewValue;
93 if(dwBitMask!= bMaskDWord)
94 {//if not "double word" write
95 OriginalValue = read_nic_dword(dev, dwRegAddr);
96 BitShift = rtl8192_CalculateBitShift(dwBitMask);
97 NewValue = (((OriginalValue) & (~dwBitMask)) | (dwData << BitShift));
98 write_nic_dword(dev, dwRegAddr, NewValue);
100 write_nic_dword(dev, dwRegAddr, dwData);
103 /******************************************************************************
104 *function: This function reads specific bits from BB register
105 * input: net_device dev
106 * u32 dwRegAddr //target addr to be readback
107 * u32 dwBitMask //taget bit pos in the addr to be readback
109 * return: u32 Data //the readback register value
111 * ****************************************************************************/
112 u32 rtl8192_QueryBBReg(struct net_device* dev, u32 dwRegAddr, u32 dwBitMask)
114 u32 Ret = 0, OriginalValue, BitShift;
116 OriginalValue = read_nic_dword(dev, dwRegAddr);
117 BitShift = rtl8192_CalculateBitShift(dwBitMask);
118 Ret =(OriginalValue & dwBitMask) >> BitShift;
122 static u32 phy_FwRFSerialRead( struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 Offset );
124 static void phy_FwRFSerialWrite( struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 Offset, u32 Data);
126 /******************************************************************************
127 *function: This function read register from RF chip
128 * input: net_device dev
129 * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D
130 * u32 Offset //target address to be read
132 * return: u32 readback value
133 * notice: There are three types of serial operations:(1) Software serial write.(2)Hardware LSSI-Low Speed Serial Interface.(3)Hardware HSSI-High speed serial write. Driver here need to implement (1) and (2)---need more spec for this information.
134 * ****************************************************************************/
135 u32 rtl8192_phy_RFSerialRead(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 Offset)
137 struct r8192_priv *priv = ieee80211_priv(dev);
140 BB_REGISTER_DEFINITION_T* pPhyReg = &priv->PHYRegDef[eRFPath];
141 rtl8192_setBBreg(dev, pPhyReg->rfLSSIReadBack, bLSSIReadBackData, 0);
142 //make sure RF register offset is correct
145 //switch page for 8256 RF IC
146 if (priv->rf_chip == RF_8256)
150 priv->RfReg0Value[eRFPath] |= 0x140;
151 //Switch to Reg_Mode2 for Reg 31-45
152 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, bMaskDWord, (priv->RfReg0Value[eRFPath]<<16) );
154 NewOffset = Offset -30;
156 else if (Offset >= 16)
158 priv->RfReg0Value[eRFPath] |= 0x100;
159 priv->RfReg0Value[eRFPath] &= (~0x40);
160 //Switch to Reg_Mode 1 for Reg16-30
161 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, bMaskDWord, (priv->RfReg0Value[eRFPath]<<16) );
163 NewOffset = Offset - 15;
170 RT_TRACE((COMP_PHY|COMP_ERR), "check RF type here, need to be 8256\n");
173 //put desired read addr to LSSI control Register
174 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadAddress, NewOffset);
175 //Issue a posedge trigger
177 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadEdge, 0x0);
178 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadEdge, 0x1);
181 // TODO: we should not delay such a long time. Ask help from SD3
184 ret = rtl8192_QueryBBReg(dev, pPhyReg->rfLSSIReadBack, bLSSIReadBackData);
187 // Switch back to Reg_Mode0;
188 if(priv->rf_chip == RF_8256)
190 priv->RfReg0Value[eRFPath] &= 0xebf;
194 pPhyReg->rf3wireOffset,
196 (priv->RfReg0Value[eRFPath] << 16));
203 /******************************************************************************
204 *function: This function write data to RF register
205 * input: net_device dev
206 * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D
207 * u32 Offset //target address to be written
208 * u32 Data //The new register data to be written
211 * notice: For RF8256 only.
212 ===========================================================
213 *Reg Mode RegCTL[1] RegCTL[0] Note
214 * (Reg00[12]) (Reg00[10])
215 *===========================================================
216 *Reg_Mode0 0 x Reg 0 ~15(0x0 ~ 0xf)
217 *------------------------------------------------------------------
218 *Reg_Mode1 1 0 Reg 16 ~30(0x1 ~ 0xf)
219 *------------------------------------------------------------------
220 * Reg_Mode2 1 1 Reg 31 ~ 45(0x1 ~ 0xf)
221 *------------------------------------------------------------------
222 * ****************************************************************************/
223 void rtl8192_phy_RFSerialWrite(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 Offset, u32 Data)
225 struct r8192_priv *priv = ieee80211_priv(dev);
226 u32 DataAndAddr = 0, NewOffset = 0;
227 BB_REGISTER_DEFINITION_T *pPhyReg = &priv->PHYRegDef[eRFPath];
230 //spin_lock_irqsave(&priv->rf_lock, flags);
231 // down(&priv->rf_sem);
232 if (priv->rf_chip == RF_8256)
237 priv->RfReg0Value[eRFPath] |= 0x140;
238 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, bMaskDWord, (priv->RfReg0Value[eRFPath] << 16));
239 NewOffset = Offset - 30;
241 else if (Offset >= 16)
243 priv->RfReg0Value[eRFPath] |= 0x100;
244 priv->RfReg0Value[eRFPath] &= (~0x40);
245 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, bMaskDWord, (priv->RfReg0Value[eRFPath]<<16));
246 NewOffset = Offset - 15;
253 RT_TRACE((COMP_PHY|COMP_ERR), "check RF type here, need to be 8256\n");
257 // Put write addr in [5:0] and write data in [31:16]
258 DataAndAddr = (Data<<16) | (NewOffset&0x3f);
261 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, bMaskDWord, DataAndAddr);
265 priv->RfReg0Value[eRFPath] = Data;
267 // Switch back to Reg_Mode0;
268 if(priv->rf_chip == RF_8256)
272 priv->RfReg0Value[eRFPath] &= 0xebf;
275 pPhyReg->rf3wireOffset,
277 (priv->RfReg0Value[eRFPath] << 16));
280 //spin_unlock_irqrestore(&priv->rf_lock, flags);
281 // up(&priv->rf_sem);
285 /******************************************************************************
286 *function: This function set specific bits to RF register
287 * input: net_device dev
288 * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D
289 * u32 RegAddr //target addr to be modified
290 * u32 BitMask //taget bit pos in the addr to be modified
291 * u32 Data //value to be write
295 * ****************************************************************************/
296 void rtl8192_phy_SetRFReg(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
298 struct r8192_priv *priv = ieee80211_priv(dev);
299 u32 Original_Value, BitShift, New_Value;
302 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
305 if (priv->Rf_Mode == RF_OP_By_FW)
307 if (BitMask != bMask12Bits) // RF data is 12 bits only
309 Original_Value = phy_FwRFSerialRead(dev, eRFPath, RegAddr);
310 BitShift = rtl8192_CalculateBitShift(BitMask);
311 New_Value = ((Original_Value) & (~BitMask)) | (Data<< BitShift);
313 phy_FwRFSerialWrite(dev, eRFPath, RegAddr, New_Value);
315 phy_FwRFSerialWrite(dev, eRFPath, RegAddr, Data);
322 if (BitMask != bMask12Bits) // RF data is 12 bits only
324 Original_Value = rtl8192_phy_RFSerialRead(dev, eRFPath, RegAddr);
325 BitShift = rtl8192_CalculateBitShift(BitMask);
326 New_Value = (((Original_Value) & (~BitMask)) | (Data<< BitShift));
328 rtl8192_phy_RFSerialWrite(dev, eRFPath, RegAddr, New_Value);
330 rtl8192_phy_RFSerialWrite(dev, eRFPath, RegAddr, Data);
335 /******************************************************************************
336 *function: This function reads specific bits from RF register
337 * input: net_device dev
338 * u32 RegAddr //target addr to be readback
339 * u32 BitMask //taget bit pos in the addr to be readback
341 * return: u32 Data //the readback register value
343 * ****************************************************************************/
344 u32 rtl8192_phy_QueryRFReg(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 RegAddr, u32 BitMask)
346 u32 Original_Value, Readback_Value, BitShift;
347 struct r8192_priv *priv = ieee80211_priv(dev);
350 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
352 if (priv->Rf_Mode == RF_OP_By_FW)
354 Original_Value = phy_FwRFSerialRead(dev, eRFPath, RegAddr);
355 BitShift = rtl8192_CalculateBitShift(BitMask);
356 Readback_Value = (Original_Value & BitMask) >> BitShift;
358 return (Readback_Value);
362 Original_Value = rtl8192_phy_RFSerialRead(dev, eRFPath, RegAddr);
363 BitShift = rtl8192_CalculateBitShift(BitMask);
364 Readback_Value = (Original_Value & BitMask) >> BitShift;
365 return (Readback_Value);
368 /******************************************************************************
369 *function: We support firmware to execute RF-R/W.
374 * ***************************************************************************/
377 struct net_device* dev,
378 RF90_RADIO_PATH_E eRFPath,
384 //DbgPrint("FW RF CTRL\n\r");
385 /* 2007/11/02 MH Firmware RF Write control. By Francis' suggestion, we can
386 not execute the scheme in the initial step. Otherwise, RF-R/W will waste
387 much time. This is only for site survey. */
388 // 1. Read operation need not insert data. bit 0-11
389 //Data &= bMask12Bits;
390 // 2. Write RF register address. Bit 12-19
391 Data |= ((Offset&0xFF)<<12);
392 // 3. Write RF path. bit 20-21
393 Data |= ((eRFPath&0x3)<<20);
394 // 4. Set RF read indicator. bit 22=0
396 // 5. Trigger Fw to operate the command. bit 31
398 // 6. We can not execute read operation if bit 31 is 1.
399 while (read_nic_dword(dev, QPNR)&0x80000000)
401 // If FW can not finish RF-R/W for more than ?? times. We must reset FW.
404 //DbgPrint("FW not finish RF-R Time=%d\n\r", time);
410 // 7. Execute read operation.
411 write_nic_dword(dev, QPNR, Data);
412 // 8. Check if firmawre send back RF content.
413 while (read_nic_dword(dev, QPNR)&0x80000000)
415 // If FW can not finish RF-R/W for more than ?? times. We must reset FW.
418 //DbgPrint("FW not finish RF-W Time=%d\n\r", time);
424 retValue = read_nic_dword(dev, RF_DATA);
428 } /* phy_FwRFSerialRead */
430 /******************************************************************************
431 *function: We support firmware to execute RF-R/W.
436 * ***************************************************************************/
439 struct net_device* dev,
440 RF90_RADIO_PATH_E eRFPath,
446 //DbgPrint("N FW RF CTRL RF-%d OF%02x DATA=%03x\n\r", eRFPath, Offset, Data);
447 /* 2007/11/02 MH Firmware RF Write control. By Francis' suggestion, we can
448 not execute the scheme in the initial step. Otherwise, RF-R/W will waste
449 much time. This is only for site survey. */
451 // 1. Set driver write bit and 12 bit data. bit 0-11
452 //Data &= bMask12Bits; // Done by uper layer.
453 // 2. Write RF register address. bit 12-19
454 Data |= ((Offset&0xFF)<<12);
455 // 3. Write RF path. bit 20-21
456 Data |= ((eRFPath&0x3)<<20);
457 // 4. Set RF write indicator. bit 22=1
459 // 5. Trigger Fw to operate the command. bit 31=1
462 // 6. Write operation. We can not write if bit 31 is 1.
463 while (read_nic_dword(dev, QPNR)&0x80000000)
465 // If FW can not finish RF-R/W for more than ?? times. We must reset FW.
468 //DbgPrint("FW not finish RF-W Time=%d\n\r", time);
474 // 7. No matter check bit. We always force the write. Because FW will
475 // not accept the command.
476 write_nic_dword(dev, QPNR, Data);
477 /* 2007/11/02 MH Acoording to test, we must delay 20us to wait firmware
478 to finish RF write operation. */
479 /* 2008/01/17 MH We support delay in firmware side now. */
482 } /* phy_FwRFSerialWrite */
485 /******************************************************************************
486 *function: This function read BB parameters from Header file we gen,
487 * and do register read/write
491 * notice: BB parameters may change all the time, so please make
492 * sure it has been synced with the newest.
493 * ***************************************************************************/
494 void rtl8192_phy_configmac(struct net_device* dev)
496 u32 dwArrayLen = 0, i;
497 u32* pdwArray = NULL;
498 struct r8192_priv *priv = ieee80211_priv(dev);
500 if(priv->btxpowerdata_readfromEEPORM)
502 RT_TRACE(COMP_PHY, "Rtl819XMACPHY_Array_PG\n");
503 dwArrayLen = MACPHY_Array_PGLength;
504 pdwArray = rtl819XMACPHY_Array_PG;
509 RT_TRACE(COMP_PHY, "Rtl819XMACPHY_Array\n");
510 dwArrayLen = MACPHY_ArrayLength;
511 pdwArray = rtl819XMACPHY_Array;
513 for(i = 0; i<dwArrayLen; i=i+3){
514 if(pdwArray[i] == 0x318)
516 pdwArray[i+2] = 0x00000800;
517 //DbgPrint("ptrArray[i], ptrArray[i+1], ptrArray[i+2] = %x, %x, %x\n",
518 // ptrArray[i], ptrArray[i+1], ptrArray[i+2]);
521 RT_TRACE(COMP_DBG, "The Rtl8190MACPHY_Array[0] is %x Rtl8190MACPHY_Array[1] is %x Rtl8190MACPHY_Array[2] is %x\n",
522 pdwArray[i], pdwArray[i+1], pdwArray[i+2]);
523 rtl8192_setBBreg(dev, pdwArray[i], pdwArray[i+1], pdwArray[i+2]);
529 /******************************************************************************
530 *function: This function do dirty work
534 * notice: BB parameters may change all the time, so please make
535 * sure it has been synced with the newest.
536 * ***************************************************************************/
538 void rtl8192_phyConfigBB(struct net_device* dev, u8 ConfigType)
543 u32 *rtl8192PhyRegArrayTable = NULL, *rtl8192AgcTabArrayTable = NULL;
544 if(Adapter->bInHctTest)
546 PHY_REGArrayLen = PHY_REGArrayLengthDTM;
547 AGCTAB_ArrayLen = AGCTAB_ArrayLengthDTM;
548 Rtl8190PHY_REGArray_Table = Rtl819XPHY_REGArrayDTM;
549 Rtl8190AGCTAB_Array_Table = Rtl819XAGCTAB_ArrayDTM;
552 if (ConfigType == BaseBand_Config_PHY_REG)
554 for (i=0; i<PHY_REG_1T2RArrayLength; i+=2)
556 rtl8192_setBBreg(dev, rtl819XPHY_REG_1T2RArray[i], bMaskDWord, rtl819XPHY_REG_1T2RArray[i+1]);
557 RT_TRACE(COMP_DBG, "i: %x, The Rtl819xUsbPHY_REGArray[0] is %x Rtl819xUsbPHY_REGArray[1] is %x \n",i, rtl819XPHY_REG_1T2RArray[i], rtl819XPHY_REG_1T2RArray[i+1]);
560 else if (ConfigType == BaseBand_Config_AGC_TAB)
562 for (i=0; i<AGCTAB_ArrayLength; i+=2)
564 rtl8192_setBBreg(dev, rtl819XAGCTAB_Array[i], bMaskDWord, rtl819XAGCTAB_Array[i+1]);
565 RT_TRACE(COMP_DBG, "i:%x, The rtl819XAGCTAB_Array[0] is %x rtl819XAGCTAB_Array[1] is %x \n",i, rtl819XAGCTAB_Array[i], rtl819XAGCTAB_Array[i+1]);
572 /******************************************************************************
573 *function: This function initialize Register definition offset for Radio Path
575 * input: net_device dev
578 * notice: Initialization value here is constant and it should never be changed
579 * ***************************************************************************/
580 void rtl8192_InitBBRFRegDef(struct net_device* dev)
582 struct r8192_priv *priv = ieee80211_priv(dev);
583 // RF Interface Sowrtware Control
584 priv->PHYRegDef[RF90_PATH_A].rfintfs = rFPGA0_XAB_RFInterfaceSW; // 16 LSBs if read 32-bit from 0x870
585 priv->PHYRegDef[RF90_PATH_B].rfintfs = rFPGA0_XAB_RFInterfaceSW; // 16 MSBs if read 32-bit from 0x870 (16-bit for 0x872)
586 priv->PHYRegDef[RF90_PATH_C].rfintfs = rFPGA0_XCD_RFInterfaceSW;// 16 LSBs if read 32-bit from 0x874
587 priv->PHYRegDef[RF90_PATH_D].rfintfs = rFPGA0_XCD_RFInterfaceSW;// 16 MSBs if read 32-bit from 0x874 (16-bit for 0x876)
589 // RF Interface Readback Value
590 priv->PHYRegDef[RF90_PATH_A].rfintfi = rFPGA0_XAB_RFInterfaceRB; // 16 LSBs if read 32-bit from 0x8E0
591 priv->PHYRegDef[RF90_PATH_B].rfintfi = rFPGA0_XAB_RFInterfaceRB;// 16 MSBs if read 32-bit from 0x8E0 (16-bit for 0x8E2)
592 priv->PHYRegDef[RF90_PATH_C].rfintfi = rFPGA0_XCD_RFInterfaceRB;// 16 LSBs if read 32-bit from 0x8E4
593 priv->PHYRegDef[RF90_PATH_D].rfintfi = rFPGA0_XCD_RFInterfaceRB;// 16 MSBs if read 32-bit from 0x8E4 (16-bit for 0x8E6)
595 // RF Interface Output (and Enable)
596 priv->PHYRegDef[RF90_PATH_A].rfintfo = rFPGA0_XA_RFInterfaceOE; // 16 LSBs if read 32-bit from 0x860
597 priv->PHYRegDef[RF90_PATH_B].rfintfo = rFPGA0_XB_RFInterfaceOE; // 16 LSBs if read 32-bit from 0x864
598 priv->PHYRegDef[RF90_PATH_C].rfintfo = rFPGA0_XC_RFInterfaceOE;// 16 LSBs if read 32-bit from 0x868
599 priv->PHYRegDef[RF90_PATH_D].rfintfo = rFPGA0_XD_RFInterfaceOE;// 16 LSBs if read 32-bit from 0x86C
601 // RF Interface (Output and) Enable
602 priv->PHYRegDef[RF90_PATH_A].rfintfe = rFPGA0_XA_RFInterfaceOE; // 16 MSBs if read 32-bit from 0x860 (16-bit for 0x862)
603 priv->PHYRegDef[RF90_PATH_B].rfintfe = rFPGA0_XB_RFInterfaceOE; // 16 MSBs if read 32-bit from 0x864 (16-bit for 0x866)
604 priv->PHYRegDef[RF90_PATH_C].rfintfe = rFPGA0_XC_RFInterfaceOE;// 16 MSBs if read 32-bit from 0x86A (16-bit for 0x86A)
605 priv->PHYRegDef[RF90_PATH_D].rfintfe = rFPGA0_XD_RFInterfaceOE;// 16 MSBs if read 32-bit from 0x86C (16-bit for 0x86E)
607 //Addr of LSSI. Wirte RF register by driver
608 priv->PHYRegDef[RF90_PATH_A].rf3wireOffset = rFPGA0_XA_LSSIParameter; //LSSI Parameter
609 priv->PHYRegDef[RF90_PATH_B].rf3wireOffset = rFPGA0_XB_LSSIParameter;
610 priv->PHYRegDef[RF90_PATH_C].rf3wireOffset = rFPGA0_XC_LSSIParameter;
611 priv->PHYRegDef[RF90_PATH_D].rf3wireOffset = rFPGA0_XD_LSSIParameter;
614 priv->PHYRegDef[RF90_PATH_A].rfLSSI_Select = rFPGA0_XAB_RFParameter; //BB Band Select
615 priv->PHYRegDef[RF90_PATH_B].rfLSSI_Select = rFPGA0_XAB_RFParameter;
616 priv->PHYRegDef[RF90_PATH_C].rfLSSI_Select = rFPGA0_XCD_RFParameter;
617 priv->PHYRegDef[RF90_PATH_D].rfLSSI_Select = rFPGA0_XCD_RFParameter;
619 // Tx AGC Gain Stage (same for all path. Should we remove this?)
620 priv->PHYRegDef[RF90_PATH_A].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
621 priv->PHYRegDef[RF90_PATH_B].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
622 priv->PHYRegDef[RF90_PATH_C].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
623 priv->PHYRegDef[RF90_PATH_D].rfTxGainStage = rFPGA0_TxGainStage; //Tx gain stage
625 // Tranceiver A~D HSSI Parameter-1
626 priv->PHYRegDef[RF90_PATH_A].rfHSSIPara1 = rFPGA0_XA_HSSIParameter1; //wire control parameter1
627 priv->PHYRegDef[RF90_PATH_B].rfHSSIPara1 = rFPGA0_XB_HSSIParameter1; //wire control parameter1
628 priv->PHYRegDef[RF90_PATH_C].rfHSSIPara1 = rFPGA0_XC_HSSIParameter1; //wire control parameter1
629 priv->PHYRegDef[RF90_PATH_D].rfHSSIPara1 = rFPGA0_XD_HSSIParameter1; //wire control parameter1
631 // Tranceiver A~D HSSI Parameter-2
632 priv->PHYRegDef[RF90_PATH_A].rfHSSIPara2 = rFPGA0_XA_HSSIParameter2; //wire control parameter2
633 priv->PHYRegDef[RF90_PATH_B].rfHSSIPara2 = rFPGA0_XB_HSSIParameter2; //wire control parameter2
634 priv->PHYRegDef[RF90_PATH_C].rfHSSIPara2 = rFPGA0_XC_HSSIParameter2; //wire control parameter2
635 priv->PHYRegDef[RF90_PATH_D].rfHSSIPara2 = rFPGA0_XD_HSSIParameter2; //wire control parameter1
638 priv->PHYRegDef[RF90_PATH_A].rfSwitchControl = rFPGA0_XAB_SwitchControl; //TR/Ant switch control
639 priv->PHYRegDef[RF90_PATH_B].rfSwitchControl = rFPGA0_XAB_SwitchControl;
640 priv->PHYRegDef[RF90_PATH_C].rfSwitchControl = rFPGA0_XCD_SwitchControl;
641 priv->PHYRegDef[RF90_PATH_D].rfSwitchControl = rFPGA0_XCD_SwitchControl;
644 priv->PHYRegDef[RF90_PATH_A].rfAGCControl1 = rOFDM0_XAAGCCore1;
645 priv->PHYRegDef[RF90_PATH_B].rfAGCControl1 = rOFDM0_XBAGCCore1;
646 priv->PHYRegDef[RF90_PATH_C].rfAGCControl1 = rOFDM0_XCAGCCore1;
647 priv->PHYRegDef[RF90_PATH_D].rfAGCControl1 = rOFDM0_XDAGCCore1;
650 priv->PHYRegDef[RF90_PATH_A].rfAGCControl2 = rOFDM0_XAAGCCore2;
651 priv->PHYRegDef[RF90_PATH_B].rfAGCControl2 = rOFDM0_XBAGCCore2;
652 priv->PHYRegDef[RF90_PATH_C].rfAGCControl2 = rOFDM0_XCAGCCore2;
653 priv->PHYRegDef[RF90_PATH_D].rfAGCControl2 = rOFDM0_XDAGCCore2;
656 priv->PHYRegDef[RF90_PATH_A].rfRxIQImbalance = rOFDM0_XARxIQImbalance;
657 priv->PHYRegDef[RF90_PATH_B].rfRxIQImbalance = rOFDM0_XBRxIQImbalance;
658 priv->PHYRegDef[RF90_PATH_C].rfRxIQImbalance = rOFDM0_XCRxIQImbalance;
659 priv->PHYRegDef[RF90_PATH_D].rfRxIQImbalance = rOFDM0_XDRxIQImbalance;
662 priv->PHYRegDef[RF90_PATH_A].rfRxAFE = rOFDM0_XARxAFE;
663 priv->PHYRegDef[RF90_PATH_B].rfRxAFE = rOFDM0_XBRxAFE;
664 priv->PHYRegDef[RF90_PATH_C].rfRxAFE = rOFDM0_XCRxAFE;
665 priv->PHYRegDef[RF90_PATH_D].rfRxAFE = rOFDM0_XDRxAFE;
668 priv->PHYRegDef[RF90_PATH_A].rfTxIQImbalance = rOFDM0_XATxIQImbalance;
669 priv->PHYRegDef[RF90_PATH_B].rfTxIQImbalance = rOFDM0_XBTxIQImbalance;
670 priv->PHYRegDef[RF90_PATH_C].rfTxIQImbalance = rOFDM0_XCTxIQImbalance;
671 priv->PHYRegDef[RF90_PATH_D].rfTxIQImbalance = rOFDM0_XDTxIQImbalance;
674 priv->PHYRegDef[RF90_PATH_A].rfTxAFE = rOFDM0_XATxAFE;
675 priv->PHYRegDef[RF90_PATH_B].rfTxAFE = rOFDM0_XBTxAFE;
676 priv->PHYRegDef[RF90_PATH_C].rfTxAFE = rOFDM0_XCTxAFE;
677 priv->PHYRegDef[RF90_PATH_D].rfTxAFE = rOFDM0_XDTxAFE;
679 // Tranceiver LSSI Readback
680 priv->PHYRegDef[RF90_PATH_A].rfLSSIReadBack = rFPGA0_XA_LSSIReadBack;
681 priv->PHYRegDef[RF90_PATH_B].rfLSSIReadBack = rFPGA0_XB_LSSIReadBack;
682 priv->PHYRegDef[RF90_PATH_C].rfLSSIReadBack = rFPGA0_XC_LSSIReadBack;
683 priv->PHYRegDef[RF90_PATH_D].rfLSSIReadBack = rFPGA0_XD_LSSIReadBack;
686 /******************************************************************************
687 *function: This function is to write register and then readback to make sure whether BB and RF is OK
688 * input: net_device dev
689 * HW90_BLOCK_E CheckBlock
690 * RF90_RADIO_PATH_E eRFPath //only used when checkblock is HW90_BLOCK_RF
692 * return: return whether BB and RF is ok(0:OK; 1:Fail)
693 * notice: This function may be removed in the ASIC
694 * ***************************************************************************/
695 u8 rtl8192_phy_checkBBAndRF(struct net_device* dev, HW90_BLOCK_E CheckBlock, RF90_RADIO_PATH_E eRFPath)
697 // struct r8192_priv *priv = ieee80211_priv(dev);
698 // BB_REGISTER_DEFINITION_T *pPhyReg = &priv->PHYRegDef[eRFPath];
700 u32 i, CheckTimes = 4, dwRegRead = 0;
702 u32 WriteData[] = {0xfffff027, 0xaa55a02f, 0x00000027, 0x55aa502f};
703 // Initialize register address offset to be checked
704 WriteAddr[HW90_BLOCK_MAC] = 0x100;
705 WriteAddr[HW90_BLOCK_PHY0] = 0x900;
706 WriteAddr[HW90_BLOCK_PHY1] = 0x800;
707 WriteAddr[HW90_BLOCK_RF] = 0x3;
708 RT_TRACE(COMP_PHY, "=======>%s(), CheckBlock:%d\n", __FUNCTION__, CheckBlock);
709 for(i=0 ; i < CheckTimes ; i++)
713 // Write Data to register and readback
718 RT_TRACE(COMP_ERR, "PHY_CheckBBRFOK(): Never Write 0x100 here!");
721 case HW90_BLOCK_PHY0:
722 case HW90_BLOCK_PHY1:
723 write_nic_dword(dev, WriteAddr[CheckBlock], WriteData[i]);
724 dwRegRead = read_nic_dword(dev, WriteAddr[CheckBlock]);
728 WriteData[i] &= 0xfff;
729 rtl8192_phy_SetRFReg(dev, eRFPath, WriteAddr[HW90_BLOCK_RF], bMask12Bits, WriteData[i]);
730 // TODO: we should not delay for such a long time. Ask SD3
732 dwRegRead = rtl8192_phy_QueryRFReg(dev, eRFPath, WriteAddr[HW90_BLOCK_RF], bMask12Bits);
743 // Check whether readback data is correct
745 if(dwRegRead != WriteData[i])
747 RT_TRACE((COMP_PHY|COMP_ERR), "====>error=====dwRegRead: %x, WriteData: %x \n", dwRegRead, WriteData[i]);
757 /******************************************************************************
758 *function: This function initialize BB&RF
759 * input: net_device dev
762 * notice: Initialization value may change all the time, so please make
763 * sure it has been synced with the newest.
764 * ***************************************************************************/
765 void rtl8192_BB_Config_ParaFile(struct net_device* dev)
767 struct r8192_priv *priv = ieee80211_priv(dev);
768 u8 bRegValue = 0, eCheckItem = 0, rtStatus = 0;
770 /**************************************
771 //<1>Initialize BaseBand
772 **************************************/
774 /*--set BB Global Reset--*/
775 bRegValue = read_nic_byte(dev, BB_GLOBAL_RESET);
776 write_nic_byte(dev, BB_GLOBAL_RESET,(bRegValue|BB_GLOBAL_RESET_BIT));
778 /*---set BB reset Active---*/
779 dwRegValue = read_nic_dword(dev, CPU_GEN);
780 write_nic_dword(dev, CPU_GEN, (dwRegValue&(~CPU_GEN_BB_RST)));
782 /*----Ckeck FPGAPHY0 and PHY1 board is OK----*/
783 // TODO: this function should be removed on ASIC , Emily 2007.2.2
784 for(eCheckItem=(HW90_BLOCK_E)HW90_BLOCK_PHY0; eCheckItem<=HW90_BLOCK_PHY1; eCheckItem++)
786 rtStatus = rtl8192_phy_checkBBAndRF(dev, (HW90_BLOCK_E)eCheckItem, (RF90_RADIO_PATH_E)0); //don't care RF path
789 RT_TRACE((COMP_ERR | COMP_PHY), "PHY_RF8256_Config():Check PHY%d Fail!!\n", eCheckItem-1);
793 /*---- Set CCK and OFDM Block "OFF"----*/
794 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bCCKEn|bOFDMEn, 0x0);
795 /*----BB Register Initilazation----*/
796 //==m==>Set PHY REG From Header<==m==
797 rtl8192_phyConfigBB(dev, BaseBand_Config_PHY_REG);
799 /*----Set BB reset de-Active----*/
800 dwRegValue = read_nic_dword(dev, CPU_GEN);
801 write_nic_dword(dev, CPU_GEN, (dwRegValue|CPU_GEN_BB_RST));
803 /*----BB AGC table Initialization----*/
804 //==m==>Set PHY REG From Header<==m==
805 rtl8192_phyConfigBB(dev, BaseBand_Config_AGC_TAB);
807 /*----Enable XSTAL ----*/
808 write_nic_byte_E(dev, 0x5e, 0x00);
809 if (priv->card_8192_version == (u8)VERSION_819xU_A)
811 //Antenna gain offset from B/C/D to A
812 dwRegValue = (priv->AntennaTxPwDiff[1]<<4 | priv->AntennaTxPwDiff[0]);
813 rtl8192_setBBreg(dev, rFPGA0_TxGainStage, (bXBTxAGC|bXCTxAGC), dwRegValue);
816 dwRegValue = priv->CrystalCap & 0xf;
817 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, bXtalCap, dwRegValue);
820 // Check if the CCK HighPower is turned ON.
821 // This is used to calculate PWDB.
822 priv->bCckHighPower = (u8)(rtl8192_QueryBBReg(dev, rFPGA0_XA_HSSIParameter2, 0x200));
825 /******************************************************************************
826 *function: This function initialize BB&RF
827 * input: net_device dev
830 * notice: Initialization value may change all the time, so please make
831 * sure it has been synced with the newest.
832 * ***************************************************************************/
833 void rtl8192_BBConfig(struct net_device* dev)
835 rtl8192_InitBBRFRegDef(dev);
836 //config BB&RF. As hardCode based initialization has not been well
837 //implemented, so use file first.FIXME:should implement it for hardcode?
838 rtl8192_BB_Config_ParaFile(dev);
842 /******************************************************************************
843 *function: This function obtains the initialization value of Tx power Level offset
844 * input: net_device dev
847 * ***************************************************************************/
848 void rtl8192_phy_getTxPower(struct net_device* dev)
850 struct r8192_priv *priv = ieee80211_priv(dev);
851 priv->MCSTxPowerLevelOriginalOffset[0] =
852 read_nic_dword(dev, rTxAGC_Rate18_06);
853 priv->MCSTxPowerLevelOriginalOffset[1] =
854 read_nic_dword(dev, rTxAGC_Rate54_24);
855 priv->MCSTxPowerLevelOriginalOffset[2] =
856 read_nic_dword(dev, rTxAGC_Mcs03_Mcs00);
857 priv->MCSTxPowerLevelOriginalOffset[3] =
858 read_nic_dword(dev, rTxAGC_Mcs07_Mcs04);
859 priv->MCSTxPowerLevelOriginalOffset[4] =
860 read_nic_dword(dev, rTxAGC_Mcs11_Mcs08);
861 priv->MCSTxPowerLevelOriginalOffset[5] =
862 read_nic_dword(dev, rTxAGC_Mcs15_Mcs12);
864 // read rx initial gain
865 priv->DefaultInitialGain[0] = read_nic_byte(dev, rOFDM0_XAAGCCore1);
866 priv->DefaultInitialGain[1] = read_nic_byte(dev, rOFDM0_XBAGCCore1);
867 priv->DefaultInitialGain[2] = read_nic_byte(dev, rOFDM0_XCAGCCore1);
868 priv->DefaultInitialGain[3] = read_nic_byte(dev, rOFDM0_XDAGCCore1);
869 RT_TRACE(COMP_INIT, "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x) \n",
870 priv->DefaultInitialGain[0], priv->DefaultInitialGain[1],
871 priv->DefaultInitialGain[2], priv->DefaultInitialGain[3]);
874 priv->framesync = read_nic_byte(dev, rOFDM0_RxDetector3);
875 priv->framesyncC34 = read_nic_byte(dev, rOFDM0_RxDetector2);
876 RT_TRACE(COMP_INIT, "Default framesync (0x%x) = 0x%x \n",
877 rOFDM0_RxDetector3, priv->framesync);
879 // read SIFS (save the value read fome MACPHY_REG.txt)
880 priv->SifsTime = read_nic_word(dev, SIFS);
885 /******************************************************************************
886 *function: This function obtains the initialization value of Tx power Level offset
887 * input: net_device dev
890 * ***************************************************************************/
891 void rtl8192_phy_setTxPower(struct net_device* dev, u8 channel)
893 struct r8192_priv *priv = ieee80211_priv(dev);
894 u8 powerlevel = priv->TxPowerLevelCCK[channel-1];
895 u8 powerlevelOFDM24G = priv->TxPowerLevelOFDM24G[channel-1];
897 switch(priv->rf_chip)
900 PHY_SetRF8256CCKTxPower(dev, powerlevel); //need further implement
901 PHY_SetRF8256OFDMTxPower(dev, powerlevelOFDM24G);
906 RT_TRACE((COMP_PHY|COMP_ERR), "error RF chipID(8225 or 8258) in function %s()\n", __FUNCTION__);
912 /******************************************************************************
913 *function: This function check Rf chip to do RF config
914 * input: net_device dev
916 * return: only 8256 is supported
917 * ***************************************************************************/
918 void rtl8192_phy_RFConfig(struct net_device* dev)
920 struct r8192_priv *priv = ieee80211_priv(dev);
922 switch(priv->rf_chip)
925 PHY_RF8256_Config(dev);
930 RT_TRACE(COMP_ERR, "error chip id\n");
936 /******************************************************************************
937 *function: This function update Initial gain
938 * input: net_device dev
940 * return: As Windows has not implemented this, wait for complement
941 * ***************************************************************************/
942 void rtl8192_phy_updateInitGain(struct net_device* dev)
947 /******************************************************************************
948 *function: This function read RF parameters from general head file, and do RF 3-wire
949 * input: net_device dev
951 * return: return code show if RF configuration is successful(0:pass, 1:fail)
952 * Note: Delay may be required for RF configuration
953 * ***************************************************************************/
954 u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device* dev, RF90_RADIO_PATH_E eRFPath)
963 for(i = 0;i<RadioA_ArrayLength; i=i+2){
965 if(rtl819XRadioA_Array[i] == 0xfe){
969 rtl8192_phy_SetRFReg(dev, eRFPath, rtl819XRadioA_Array[i], bMask12Bits, rtl819XRadioA_Array[i+1]);
975 for(i = 0;i<RadioB_ArrayLength; i=i+2){
977 if(rtl819XRadioB_Array[i] == 0xfe){
981 rtl8192_phy_SetRFReg(dev, eRFPath, rtl819XRadioB_Array[i], bMask12Bits, rtl819XRadioB_Array[i+1]);
987 for(i = 0;i<RadioC_ArrayLength; i=i+2){
989 if(rtl819XRadioC_Array[i] == 0xfe){
993 rtl8192_phy_SetRFReg(dev, eRFPath, rtl819XRadioC_Array[i], bMask12Bits, rtl819XRadioC_Array[i+1]);
999 for(i = 0;i<RadioD_ArrayLength; i=i+2){
1001 if(rtl819XRadioD_Array[i] == 0xfe){
1005 rtl8192_phy_SetRFReg(dev, eRFPath, rtl819XRadioD_Array[i], bMask12Bits, rtl819XRadioD_Array[i+1]);
1017 /******************************************************************************
1018 *function: This function set Tx Power of the channel
1019 * input: struct net_device *dev
1024 * ***************************************************************************/
1025 void rtl8192_SetTxPowerLevel(struct net_device *dev, u8 channel)
1027 struct r8192_priv *priv = ieee80211_priv(dev);
1028 u8 powerlevel = priv->TxPowerLevelCCK[channel-1];
1029 u8 powerlevelOFDM24G = priv->TxPowerLevelOFDM24G[channel-1];
1031 switch(priv->rf_chip)
1035 PHY_SetRF8225CckTxPower(Adapter, powerlevel);
1036 PHY_SetRF8225OfdmTxPower(Adapter, powerlevelOFDM24G);
1041 PHY_SetRF8256CCKTxPower(dev, powerlevel);
1042 PHY_SetRF8256OFDMTxPower(dev, powerlevelOFDM24G);
1048 RT_TRACE(COMP_ERR, "unknown rf chip ID in rtl8192_SetTxPowerLevel()\n");
1054 /******************************************************************************
1055 *function: This function set RF state on or off
1056 * input: struct net_device *dev
1057 * RT_RF_POWER_STATE eRFPowerState //Power State to set
1061 * ***************************************************************************/
1062 bool rtl8192_SetRFPowerState(struct net_device *dev, RT_RF_POWER_STATE eRFPowerState)
1064 bool bResult = true;
1066 struct r8192_priv *priv = ieee80211_priv(dev);
1068 if(eRFPowerState == priv->ieee80211->eRFPowerState)
1071 if(priv->SetRFPowerStateInProgress == true)
1074 priv->SetRFPowerStateInProgress = true;
1076 switch(priv->rf_chip)
1079 switch( eRFPowerState )
1083 rtl8192_setBBreg(dev, rFPGA0_XA_RFInterfaceOE, BIT4, 0x1); // 0x860[4]
1084 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0x300, 0x3); // 0x88c[4]
1085 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x60, 0x3); // 0x880[6:5]
1086 rtl8192_setBBreg(dev, rOFDM0_TRxPathEnable, 0xf, 0x3); // 0xc04[3:0]
1087 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0x3); // 0xd04[3:0]
1088 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter2, 0x7000, 0x3); // 0x884[14:12]
1089 // for(eRFPath = 0; eRFPath <pHalData->NumTotalRFPath; eRFPath++)
1090 // PHY_SetRFReg(Adapter, (RF90_RADIO_PATH_E)eRFPath, 0x4, 0xC00, 0x2);
1092 //SwChnl(Adapter->ChannelID);
1095 //enable RF-Chip A/B
1096 rtl8192_setBBreg(dev, rFPGA0_XA_RFInterfaceOE, BIT4, 0x1); // 0x860[4]
1097 //analog to digital on
1098 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0x300, 0x3);// 0x88c[9:8]
1099 //digital to analog on
1100 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x18, 0x3); // 0x880[4:3]
1102 rtl8192_setBBreg(dev, rOFDM0_TRxPathEnable, 0x3, 0x3);// 0xc04[1:0]
1104 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0x3, 0x3);// 0xd04[1:0]
1105 //analog to digital part2 on
1106 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x60, 0x3); // 0x880[6:5]
1116 rtl8192_setBBreg(dev, rFPGA0_XA_RFInterfaceOE, BIT4, 0x0); // 0x860[4]
1117 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0x300, 0x0); // 0x88c[4]
1118 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x60, 0x0); // 0x880[6:5]
1119 rtl8192_setBBreg(dev, rOFDM0_TRxPathEnable, 0xf, 0); // 0xc04[3:0]
1120 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0); // 0xd04[3:0]
1121 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter2, 0x7000, 0x0); // 0x884[14:12]
1122 // for(eRFPath = 0; eRFPath <pHalData->NumTotalRFPath; eRFPath++)
1123 // PHY_SetRFReg(Adapter, (RF90_RADIO_PATH_E)eRFPath, 0x4, 0xC00, 0x0);
1126 //disable RF-Chip A/B
1127 rtl8192_setBBreg(dev, rFPGA0_XA_RFInterfaceOE, BIT4, 0x0); // 0x860[4]
1128 //analog to digital off, for power save
1129 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0xf00, 0x0);// 0x88c[11:8]
1130 //digital to analog off, for power save
1131 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x18, 0x0); // 0x880[4:3]
1133 rtl8192_setBBreg(dev, rOFDM0_TRxPathEnable, 0xf, 0x0);// 0xc04[3:0]
1135 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0x0);// 0xd04[3:0]
1136 //analog to digital part2 off, for power save
1137 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x60, 0x0); // 0x880[6:5]
1143 RT_TRACE(COMP_ERR, "SetRFPowerState819xUsb(): unknow state to set: 0x%X!!!\n", eRFPowerState);
1148 RT_TRACE(COMP_ERR, "Not support rf_chip(%x)\n", priv->rf_chip);
1154 // Update current RF state variable.
1155 pHalData->eRFPowerState = eRFPowerState;
1156 switch(pHalData->RFChipID )
1159 switch(pHalData->eRFPowerState)
1163 //If Rf off reason is from IPS, Led should blink with no link, by Maddest 071015
1165 if(pMgntInfo->RfOffReason==RF_CHANGE_BY_IPS )
1167 Adapter->HalFunc.LedControlHandler(Adapter,LED_CTL_NO_LINK);
1171 // Turn off LED if RF is not ON.
1172 Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_POWER_OFF);
1177 // Turn on RF we are still linked, which might happen when
1178 // we quickly turn off and on HW RF. 2006.05.12, by rcnjko.
1179 if( pMgntInfo->bMediaConnect == TRUE )
1181 Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_LINK);
1185 // Turn off LED if RF is not ON.
1186 Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_NO_LINK);
1197 RT_TRACE(COMP_RF, DBG_LOUD, ("SetRFPowerState8190(): Unknown RF type\n"));
1203 priv->SetRFPowerStateInProgress = false;
1208 /****************************************************************************************
1209 *function: This function set command table variable(struct SwChnlCmd).
1210 * input: SwChnlCmd* CmdTable //table to be set.
1211 * u32 CmdTableIdx //variable index in table to be set
1212 * u32 CmdTableSz //table size.
1213 * SwChnlCmdID CmdID //command ID to set.
1218 * return: true if finished, false otherwise
1220 * ************************************************************************************/
1221 u8 rtl8192_phy_SetSwChnlCmdArray(
1222 SwChnlCmd* CmdTable,
1233 if(CmdTable == NULL)
1235 RT_TRACE(COMP_ERR, "phy_SetSwChnlCmdArray(): CmdTable cannot be NULL.\n");
1238 if(CmdTableIdx >= CmdTableSz)
1240 RT_TRACE(COMP_ERR, "phy_SetSwChnlCmdArray(): Access invalid index, please check size of the table, CmdTableIdx:%d, CmdTableSz:%d\n",
1241 CmdTableIdx, CmdTableSz);
1245 pCmd = CmdTable + CmdTableIdx;
1246 pCmd->CmdID = CmdID;
1247 pCmd->Para1 = Para1;
1248 pCmd->Para2 = Para2;
1249 pCmd->msDelay = msDelay;
1253 /******************************************************************************
1254 *function: This function set channel step by step
1255 * input: struct net_device *dev
1257 * u8* stage //3 stages
1259 * u32* delay //whether need to delay
1260 * output: store new stage, step and delay for next step(combine with function above)
1261 * return: true if finished, false otherwise
1262 * Note: Wait for simpler function to replace it //wb
1263 * ***************************************************************************/
1264 u8 rtl8192_phy_SwChnlStepByStep(struct net_device *dev, u8 channel, u8* stage, u8* step, u32* delay)
1266 struct r8192_priv *priv = ieee80211_priv(dev);
1267 // PCHANNEL_ACCESS_SETTING pChnlAccessSetting;
1268 SwChnlCmd PreCommonCmd[MAX_PRECMD_CNT];
1269 u32 PreCommonCmdCnt;
1270 SwChnlCmd PostCommonCmd[MAX_POSTCMD_CNT];
1271 u32 PostCommonCmdCnt;
1272 SwChnlCmd RfDependCmd[MAX_RFDEPENDCMD_CNT];
1274 SwChnlCmd *CurrentCmd = NULL;
1275 //RF90_RADIO_PATH_E eRFPath;
1280 RT_TRACE(COMP_CH, "====>%s()====stage:%d, step:%d, channel:%d\n", __FUNCTION__, *stage, *step, channel);
1281 // RT_ASSERT(IsLegalChannel(Adapter, channel), ("illegal channel: %d\n", channel));
1282 #ifdef ENABLE_DOT11D
1283 if (!IsLegalChannel(priv->ieee80211, channel))
1285 RT_TRACE(COMP_ERR, "=============>set to illegal channel:%d\n", channel);
1286 return true; //return true to tell upper caller function this channel setting is finished! Or it will in while loop.
1289 //FIXME:need to check whether channel is legal or not here.WB
1292 //for(eRFPath = RF90_PATH_A; eRFPath <pHalData->NumTotalRFPath; eRFPath++)
1293 // for(eRFPath = 0; eRFPath <RF90_PATH_MAX; eRFPath++)
1295 // if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
1297 // <1> Fill up pre common command.
1298 PreCommonCmdCnt = 0;
1299 rtl8192_phy_SetSwChnlCmdArray(PreCommonCmd, PreCommonCmdCnt++, MAX_PRECMD_CNT,
1300 CmdID_SetTxPowerLevel, 0, 0, 0);
1301 rtl8192_phy_SetSwChnlCmdArray(PreCommonCmd, PreCommonCmdCnt++, MAX_PRECMD_CNT,
1302 CmdID_End, 0, 0, 0);
1304 // <2> Fill up post common command.
1305 PostCommonCmdCnt = 0;
1307 rtl8192_phy_SetSwChnlCmdArray(PostCommonCmd, PostCommonCmdCnt++, MAX_POSTCMD_CNT,
1308 CmdID_End, 0, 0, 0);
1310 // <3> Fill up RF dependent command.
1312 switch( priv->rf_chip )
1315 if (!(channel >= 1 && channel <= 14))
1317 RT_TRACE(COMP_ERR, "illegal channel for Zebra 8225: %d\n", channel);
1320 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
1321 CmdID_RF_WriteReg, rZebra1_Channel, RF_CHANNEL_TABLE_ZEBRA[channel], 10);
1322 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
1323 CmdID_End, 0, 0, 0);
1327 // TEST!! This is not the table for 8256!!
1328 if (!(channel >= 1 && channel <= 14))
1330 RT_TRACE(COMP_ERR, "illegal channel for Zebra 8256: %d\n", channel);
1333 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
1334 CmdID_RF_WriteReg, rZebra1_Channel, channel, 10);
1335 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
1336 CmdID_End, 0, 0, 0);
1343 RT_TRACE(COMP_ERR, "Unknown RFChipID: %d\n", priv->rf_chip);
1353 CurrentCmd=&PreCommonCmd[*step];
1356 CurrentCmd=&RfDependCmd[*step];
1359 CurrentCmd=&PostCommonCmd[*step];
1363 if(CurrentCmd->CmdID==CmdID_End)
1367 (*delay)=CurrentCmd->msDelay;
1378 switch(CurrentCmd->CmdID)
1380 case CmdID_SetTxPowerLevel:
1381 if(priv->card_8192_version == (u8)VERSION_819xU_A) //xiong: consider it later!
1382 rtl8192_SetTxPowerLevel(dev,channel);
1384 case CmdID_WritePortUlong:
1385 write_nic_dword(dev, CurrentCmd->Para1, CurrentCmd->Para2);
1387 case CmdID_WritePortUshort:
1388 write_nic_word(dev, CurrentCmd->Para1, (u16)CurrentCmd->Para2);
1390 case CmdID_WritePortUchar:
1391 write_nic_byte(dev, CurrentCmd->Para1, (u8)CurrentCmd->Para2);
1393 case CmdID_RF_WriteReg:
1394 for(eRFPath = 0; eRFPath < RF90_PATH_MAX; eRFPath++)
1396 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, CurrentCmd->Para1, bZebra1_ChannelNum, CurrentCmd->Para2);
1405 // }/*for(Number of RF paths)*/
1407 (*delay)=CurrentCmd->msDelay;
1412 /******************************************************************************
1413 *function: This function does acturally set channel work
1414 * input: struct net_device *dev
1418 * Note: We should not call this function directly
1419 * ***************************************************************************/
1420 void rtl8192_phy_FinishSwChnlNow(struct net_device *dev, u8 channel)
1422 struct r8192_priv *priv = ieee80211_priv(dev);
1425 while(!rtl8192_phy_SwChnlStepByStep(dev,channel,&priv->SwChnlStage,&priv->SwChnlStep,&delay))
1428 // msleep(delay);//or mdelay? need further consideration
1433 /******************************************************************************
1434 *function: Callback routine of the work item for switch channel.
1439 * ***************************************************************************/
1440 void rtl8192_SwChnl_WorkItem(struct net_device *dev)
1443 struct r8192_priv *priv = ieee80211_priv(dev);
1445 RT_TRACE(COMP_CH, "==> SwChnlCallback819xUsbWorkItem(), chan:%d\n", priv->chan);
1448 rtl8192_phy_FinishSwChnlNow(dev , priv->chan);
1450 RT_TRACE(COMP_CH, "<== SwChnlCallback819xUsbWorkItem()\n");
1453 /******************************************************************************
1454 *function: This function scheduled actural workitem to set channel
1455 * input: net_device dev
1456 * u8 channel //channel to set
1458 * return: return code show if workitem is scheduled(1:pass, 0:fail)
1459 * Note: Delay may be required for RF configuration
1460 * ***************************************************************************/
1461 u8 rtl8192_phy_SwChnl(struct net_device* dev, u8 channel)
1463 struct r8192_priv *priv = ieee80211_priv(dev);
1464 RT_TRACE(COMP_CH, "=====>%s(), SwChnlInProgress:%d\n", __FUNCTION__, priv->SwChnlInProgress);
1467 if(priv->SwChnlInProgress)
1470 // if(pHalData->SetBWModeInProgress)
1472 if (0) //to test current channel from RF reg 0x7.
1475 for(eRFPath = 0; eRFPath < 2; eRFPath++){
1476 printk("====>set channel:%x\n",rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x7, bZebra1_ChannelNum));
1480 //--------------------------------------------
1481 switch(priv->ieee80211->mode)
1483 case WIRELESS_MODE_A:
1484 case WIRELESS_MODE_N_5G:
1486 RT_TRACE(COMP_ERR, "WIRELESS_MODE_A but channel<=14");
1490 case WIRELESS_MODE_B:
1492 RT_TRACE(COMP_ERR, "WIRELESS_MODE_B but channel>14");
1496 case WIRELESS_MODE_G:
1497 case WIRELESS_MODE_N_24G:
1499 RT_TRACE(COMP_ERR, "WIRELESS_MODE_G but channel>14");
1504 //--------------------------------------------
1506 priv->SwChnlInProgress = true;
1512 priv->SwChnlStage=0;
1514 // schedule_work(&(priv->SwChnlWorkItem));
1515 // rtl8192_SwChnl_WorkItem(dev);
1517 // queue_work(priv->priv_wq,&(priv->SwChnlWorkItem));
1518 rtl8192_SwChnl_WorkItem(dev);
1521 priv->SwChnlInProgress = false;
1527 /******************************************************************************
1528 *function: Callback routine of the work item for set bandwidth mode.
1529 * input: struct net_device *dev
1530 * HT_CHANNEL_WIDTH Bandwidth //20M or 40M
1531 * HT_EXTCHNL_OFFSET Offset //Upper, Lower, or Don't care
1534 * Note: I doubt whether SetBWModeInProgress flag is necessary as we can
1535 * test whether current work in the queue or not.//do I?
1536 * ***************************************************************************/
1537 void rtl8192_SetBWModeWorkItem(struct net_device *dev)
1540 struct r8192_priv *priv = ieee80211_priv(dev);
1543 RT_TRACE(COMP_SWBW, "==>rtl8192_SetBWModeWorkItem() Switch to %s bandwidth\n", \
1544 priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz")
1547 if(priv->rf_chip == RF_PSEUDO_11N)
1549 priv->SetBWModeInProgress= false;
1553 //<1>Set MAC register
1554 regBwOpMode = read_nic_byte(dev, BW_OPMODE);
1556 switch(priv->CurrentChannelBW)
1558 case HT_CHANNEL_WIDTH_20:
1559 regBwOpMode |= BW_OPMODE_20MHZ;
1560 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
1561 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
1564 case HT_CHANNEL_WIDTH_20_40:
1565 regBwOpMode &= ~BW_OPMODE_20MHZ;
1566 // 2007/02/07 Mark by Emily becasue we have not verify whether this register works
1567 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
1571 RT_TRACE(COMP_ERR, "SetChannelBandwidth819xUsb(): unknown Bandwidth: %#X\n",priv->CurrentChannelBW);
1575 //<2>Set PHY related register
1576 switch(priv->CurrentChannelBW)
1578 case HT_CHANNEL_WIDTH_20:
1579 // Add by Vivi 20071119
1580 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x0);
1581 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x0);
1582 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00100000, 1);
1584 // Correct the tx power for CCK rate in 20M. Suggest by YN, 20071207
1586 write_nic_dword(dev, rCCK0_TxFilter1, 0x1a1b0000);
1587 write_nic_dword(dev, rCCK0_TxFilter2, 0x090e1317);
1588 write_nic_dword(dev, rCCK0_DebugPort, 0x00000204);
1590 priv->cck_present_attentuation =
1591 priv->cck_present_attentuation_20Mdefault + priv->cck_present_attentuation_difference;
1593 if(priv->cck_present_attentuation > 22)
1594 priv->cck_present_attentuation= 22;
1595 if(priv->cck_present_attentuation< 0)
1596 priv->cck_present_attentuation = 0;
1597 RT_TRACE(COMP_INIT, "20M, pHalData->CCKPresentAttentuation = %d\n", priv->cck_present_attentuation);
1599 if(priv->chan == 14 && !priv->bcck_in_ch14)
1601 priv->bcck_in_ch14 = TRUE;
1602 dm_cck_txpower_adjust(dev,priv->bcck_in_ch14);
1604 else if(priv->chan != 14 && priv->bcck_in_ch14)
1606 priv->bcck_in_ch14 = FALSE;
1607 dm_cck_txpower_adjust(dev,priv->bcck_in_ch14);
1610 dm_cck_txpower_adjust(dev,priv->bcck_in_ch14);
1613 case HT_CHANNEL_WIDTH_20_40:
1614 // Add by Vivi 20071119
1615 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x1);
1616 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x1);
1617 rtl8192_setBBreg(dev, rCCK0_System, bCCKSideBand, (priv->nCur40MhzPrimeSC>>1));
1618 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00100000, 0);
1619 rtl8192_setBBreg(dev, rOFDM1_LSTF, 0xC00, priv->nCur40MhzPrimeSC);
1621 // Correct the tx power for CCK rate in 40M. Suggest by YN, 20071207
1622 write_nic_dword(dev, rCCK0_TxFilter1, 0x35360000);
1623 write_nic_dword(dev, rCCK0_TxFilter2, 0x121c252e);
1624 write_nic_dword(dev, rCCK0_DebugPort, 0x00000409);
1626 priv->cck_present_attentuation =
1627 priv->cck_present_attentuation_40Mdefault + priv->cck_present_attentuation_difference;
1629 if(priv->cck_present_attentuation > 22)
1630 priv->cck_present_attentuation = 22;
1631 if(priv->cck_present_attentuation < 0)
1632 priv->cck_present_attentuation = 0;
1634 RT_TRACE(COMP_INIT, "40M, pHalData->CCKPresentAttentuation = %d\n", priv->cck_present_attentuation);
1635 if(priv->chan == 14 && !priv->bcck_in_ch14)
1637 priv->bcck_in_ch14 = true;
1638 dm_cck_txpower_adjust(dev,priv->bcck_in_ch14);
1640 else if(priv->chan!= 14 && priv->bcck_in_ch14)
1642 priv->bcck_in_ch14 = false;
1643 dm_cck_txpower_adjust(dev,priv->bcck_in_ch14);
1646 dm_cck_txpower_adjust(dev,priv->bcck_in_ch14);
1650 RT_TRACE(COMP_ERR, "SetChannelBandwidth819xUsb(): unknown Bandwidth: %#X\n" ,priv->CurrentChannelBW);
1654 //Skip over setting of J-mode in BB register here. Default value is "None J mode". Emily 20070315
1657 //<3>Set RF related register
1658 switch( priv->rf_chip )
1662 PHY_SetRF8225Bandwidth(Adapter, pHalData->CurrentChannelBW);
1667 PHY_SetRF8256Bandwidth(dev, priv->CurrentChannelBW);
1671 // PHY_SetRF8258Bandwidth();
1679 RT_TRACE(COMP_ERR, "Unknown RFChipID: %d\n", priv->rf_chip);
1683 priv->SetBWModeInProgress= false;
1685 RT_TRACE(COMP_SWBW, "<==SetBWMode819xUsb(), %d", atomic_read(&(priv->ieee80211->atm_swbw)) );
1688 /******************************************************************************
1689 *function: This function schedules bandwith switch work.
1690 * input: struct net_device *dev
1691 * HT_CHANNEL_WIDTH Bandwidth //20M or 40M
1692 * HT_EXTCHNL_OFFSET Offset //Upper, Lower, or Don't care
1695 * Note: I doubt whether SetBWModeInProgress flag is necessary as we can
1696 * test whether current work in the queue or not.//do I?
1697 * ***************************************************************************/
1698 void rtl8192_SetBWMode(struct net_device *dev, HT_CHANNEL_WIDTH Bandwidth, HT_EXTCHNL_OFFSET Offset)
1700 struct r8192_priv *priv = ieee80211_priv(dev);
1702 if(priv->SetBWModeInProgress)
1704 priv->SetBWModeInProgress= true;
1706 priv->CurrentChannelBW = Bandwidth;
1708 if(Offset==HT_EXTCHNL_OFFSET_LOWER)
1709 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_UPPER;
1710 else if(Offset==HT_EXTCHNL_OFFSET_UPPER)
1711 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_LOWER;
1713 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
1715 //queue_work(priv->priv_wq, &(priv->SetBWModeWorkItem));
1716 // schedule_work(&(priv->SetBWModeWorkItem));
1717 rtl8192_SetBWModeWorkItem(dev);
1721 void InitialGain819xUsb(struct net_device *dev, u8 Operation)
1723 struct r8192_priv *priv = ieee80211_priv(dev);
1725 priv->InitialGainOperateType = Operation;
1729 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
1730 queue_delayed_work(priv->priv_wq,&priv->initialgain_operate_wq,0);
1732 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1733 schedule_task(&priv->initialgain_operate_wq);
1735 queue_work(priv->priv_wq,&priv->initialgain_operate_wq);
1741 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
1742 extern void InitialGainOperateWorkItemCallBack(struct work_struct *work)
1744 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
1745 struct r8192_priv *priv = container_of(dwork,struct r8192_priv,initialgain_operate_wq);
1746 struct net_device *dev = priv->ieee80211->dev;
1748 extern void InitialGainOperateWorkItemCallBack(struct net_device *dev)
1750 struct r8192_priv *priv = ieee80211_priv(dev);
1752 #define SCAN_RX_INITIAL_GAIN 0x17
1753 #define POWER_DETECTION_TH 0x08
1758 Operation = priv->InitialGainOperateType;
1763 RT_TRACE(COMP_SCAN, "IG_Backup, backup the initial gain.\n");
1764 initial_gain = SCAN_RX_INITIAL_GAIN;//priv->DefaultInitialGain[0];//
1765 BitMask = bMaskByte0;
1766 if(dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
1767 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); // FW DIG OFF
1768 priv->initgain_backup.xaagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XAAGCCore1, BitMask);
1769 priv->initgain_backup.xbagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XBAGCCore1, BitMask);
1770 priv->initgain_backup.xcagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XCAGCCore1, BitMask);
1771 priv->initgain_backup.xdagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XDAGCCore1, BitMask);
1772 BitMask = bMaskByte2;
1773 priv->initgain_backup.cca = (u8)rtl8192_QueryBBReg(dev, rCCK0_CCA, BitMask);
1775 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc50 is %x\n",priv->initgain_backup.xaagccore1);
1776 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc58 is %x\n",priv->initgain_backup.xbagccore1);
1777 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc60 is %x\n",priv->initgain_backup.xcagccore1);
1778 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc68 is %x\n",priv->initgain_backup.xdagccore1);
1779 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xa0a is %x\n",priv->initgain_backup.cca);
1781 RT_TRACE(COMP_SCAN, "Write scan initial gain = 0x%x \n", initial_gain);
1782 write_nic_byte(dev, rOFDM0_XAAGCCore1, initial_gain);
1783 write_nic_byte(dev, rOFDM0_XBAGCCore1, initial_gain);
1784 write_nic_byte(dev, rOFDM0_XCAGCCore1, initial_gain);
1785 write_nic_byte(dev, rOFDM0_XDAGCCore1, initial_gain);
1786 RT_TRACE(COMP_SCAN, "Write scan 0xa0a = 0x%x \n", POWER_DETECTION_TH);
1787 write_nic_byte(dev, 0xa0a, POWER_DETECTION_TH);
1790 RT_TRACE(COMP_SCAN, "IG_Restore, restore the initial gain.\n");
1791 BitMask = 0x7f; //Bit0~ Bit6
1792 if(dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
1793 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); // FW DIG OFF
1795 rtl8192_setBBreg(dev, rOFDM0_XAAGCCore1, BitMask, (u32)priv->initgain_backup.xaagccore1);
1796 rtl8192_setBBreg(dev, rOFDM0_XBAGCCore1, BitMask, (u32)priv->initgain_backup.xbagccore1);
1797 rtl8192_setBBreg(dev, rOFDM0_XCAGCCore1, BitMask, (u32)priv->initgain_backup.xcagccore1);
1798 rtl8192_setBBreg(dev, rOFDM0_XDAGCCore1, BitMask, (u32)priv->initgain_backup.xdagccore1);
1799 BitMask = bMaskByte2;
1800 rtl8192_setBBreg(dev, rCCK0_CCA, BitMask, (u32)priv->initgain_backup.cca);
1802 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc50 is %x\n",priv->initgain_backup.xaagccore1);
1803 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc58 is %x\n",priv->initgain_backup.xbagccore1);
1804 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc60 is %x\n",priv->initgain_backup.xcagccore1);
1805 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc68 is %x\n",priv->initgain_backup.xdagccore1);
1806 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xa0a is %x\n",priv->initgain_backup.cca);
1809 SetTxPowerLevel8190(Adapter,priv->CurrentChannel);
1812 SetTxPowerLevel8190(Adapter,priv->CurrentChannel);
1815 rtl8192_phy_setTxPower(dev,priv->ieee80211->current_network.channel);
1818 if(dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
1819 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x1); // FW DIG ON
1822 RT_TRACE(COMP_SCAN, "Unknown IG Operation. \n");