3 #include "r819xU_phy.h"
4 #include "r819xU_phyreg.h"
5 #include "r8190_rtl8256.h"
7 #include "r819xU_firmware_img.h"
10 #include <linux/bitops.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 checks different RF type to execute legal judgement.
42 * If RF Path is illegal, we will return false.
43 * input: net_device *dev
46 * return: 0(illegal, false), 1(legal, true)
47 *****************************************************************************/
48 u8 rtl8192_phy_CheckIsLegalRFPath(struct net_device *dev, u32 eRFPath)
51 struct r8192_priv *priv = ieee80211_priv(dev);
53 if (priv->rf_type == RF_2T4R) {
55 } else if (priv->rf_type == RF_1T2R) {
56 if (eRFPath == RF90_PATH_A || eRFPath == RF90_PATH_B)
58 else if (eRFPath == RF90_PATH_C || eRFPath == RF90_PATH_D)
64 /******************************************************************************
65 * function: This function sets specific bits to BB register
66 * input: net_device *dev
67 * u32 reg_addr //target addr to be modified
68 * u32 bitmask //taget bit pos to be modified
69 * u32 data //value to be write
73 ******************************************************************************/
74 void rtl8192_setBBreg(struct net_device *dev, u32 reg_addr, u32 bitmask,
80 if (bitmask != bMaskDWord) {
81 read_nic_dword(dev, reg_addr, ®);
82 bitshift = ffs(bitmask) - 1;
84 reg |= data << bitshift;
85 write_nic_dword(dev, reg_addr, reg);
87 write_nic_dword(dev, reg_addr, data);
91 /******************************************************************************
92 * function: This function reads specific bits from BB register
93 * input: net_device *dev
94 * u32 reg_addr //target addr to be readback
95 * u32 bitmask //taget bit pos to be readback
97 * return: u32 data //the readback register value
99 ******************************************************************************/
100 u32 rtl8192_QueryBBReg(struct net_device *dev, u32 reg_addr, u32 bitmask)
104 read_nic_dword(dev, reg_addr, ®);
105 bitshift = ffs(bitmask) - 1;
107 return (reg & bitmask) >> bitshift;
110 static u32 phy_FwRFSerialRead(struct net_device *dev, RF90_RADIO_PATH_E eRFPath,
113 static void phy_FwRFSerialWrite(struct net_device *dev,
114 RF90_RADIO_PATH_E eRFPath, u32 offset,
117 /******************************************************************************
118 * function: This function reads register from RF chip
119 * input: net_device *dev
120 * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D
121 * u32 offset //target address to be read
123 * return: u32 readback value
124 * notice: There are three types of serial operations:
125 * (1) Software serial write.
126 * (2)Hardware LSSI-Low Speed Serial Interface.
127 * (3)Hardware HSSI-High speed serial write.
128 * Driver here need to implement (1) and (2)
129 * ---need more spec for this information.
130 ******************************************************************************/
131 static u32 rtl8192_phy_RFSerialRead(struct net_device *dev,
132 RF90_RADIO_PATH_E eRFPath, u32 offset)
134 struct r8192_priv *priv = ieee80211_priv(dev);
137 BB_REGISTER_DEFINITION_T *pPhyReg = &priv->PHYRegDef[eRFPath];
139 rtl8192_setBBreg(dev, pPhyReg->rfLSSIReadBack, bLSSIReadBackData, 0);
140 /* Make sure RF register offset is correct */
143 /* Switch page for 8256 RF IC */
144 if (priv->rf_chip == RF_8256) {
146 priv->RfReg0Value[eRFPath] |= 0x140;
147 /* Switch to Reg_Mode2 for Reg 31-45 */
148 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset,
150 priv->RfReg0Value[eRFPath]<<16);
152 new_offset = offset - 30;
153 } else if (offset >= 16) {
154 priv->RfReg0Value[eRFPath] |= 0x100;
155 priv->RfReg0Value[eRFPath] &= (~0x40);
156 /* Switch to Reg_Mode1 for Reg16-30 */
157 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset,
159 priv->RfReg0Value[eRFPath]<<16);
161 new_offset = offset - 15;
166 RT_TRACE((COMP_PHY|COMP_ERR),
167 "check RF type here, need to be 8256\n");
170 /* Put desired read addr to LSSI control Register */
171 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadAddress,
173 /* Issue a posedge trigger */
174 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadEdge, 0x0);
175 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadEdge, 0x1);
178 /* TODO: we should not delay such a long time. Ask for help from SD3 */
179 usleep_range(1000, 1000);
181 ret = rtl8192_QueryBBReg(dev, pPhyReg->rfLSSIReadBack,
185 /* Switch back to Reg_Mode0 */
186 if (priv->rf_chip == RF_8256) {
187 priv->RfReg0Value[eRFPath] &= 0xebf;
189 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, bMaskDWord,
190 priv->RfReg0Value[eRFPath] << 16);
196 /******************************************************************************
197 * function: This function writes data to RF register
198 * input: net_device *dev
199 * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D
200 * u32 offset //target address to be written
201 * u32 data //the new register data to be written
204 * notice: For RF8256 only.
205 * ===========================================================================
206 * Reg Mode RegCTL[1] RegCTL[0] Note
207 * (Reg00[12]) (Reg00[10])
208 * ===========================================================================
209 * Reg_Mode0 0 x Reg 0 ~ 15(0x0 ~ 0xf)
210 * ---------------------------------------------------------------------------
211 * Reg_Mode1 1 0 Reg 16 ~ 30(0x1 ~ 0xf)
212 * ---------------------------------------------------------------------------
213 * Reg_Mode2 1 1 Reg 31 ~ 45(0x1 ~ 0xf)
214 * ---------------------------------------------------------------------------
215 *****************************************************************************/
216 static void rtl8192_phy_RFSerialWrite(struct net_device *dev,
217 RF90_RADIO_PATH_E eRFPath, u32 offset,
220 struct r8192_priv *priv = ieee80211_priv(dev);
221 u32 DataAndAddr = 0, new_offset = 0;
222 BB_REGISTER_DEFINITION_T *pPhyReg = &priv->PHYRegDef[eRFPath];
225 if (priv->rf_chip == RF_8256) {
228 priv->RfReg0Value[eRFPath] |= 0x140;
229 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset,
231 priv->RfReg0Value[eRFPath] << 16);
232 new_offset = offset - 30;
233 } else if (offset >= 16) {
234 priv->RfReg0Value[eRFPath] |= 0x100;
235 priv->RfReg0Value[eRFPath] &= (~0x40);
236 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset,
238 priv->RfReg0Value[eRFPath]<<16);
239 new_offset = offset - 15;
244 RT_TRACE((COMP_PHY|COMP_ERR),
245 "check RF type here, need to be 8256\n");
249 /* Put write addr in [5:0] and write data in [31:16] */
250 DataAndAddr = (data<<16) | (new_offset&0x3f);
252 /* Write operation */
253 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, bMaskDWord, DataAndAddr);
257 priv->RfReg0Value[eRFPath] = data;
259 /* Switch back to Reg_Mode0 */
260 if (priv->rf_chip == RF_8256) {
262 priv->RfReg0Value[eRFPath] &= 0xebf;
263 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset,
265 priv->RfReg0Value[eRFPath] << 16);
270 /******************************************************************************
271 * function: This function set specific bits to RF register
272 * input: net_device dev
273 * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D
274 * u32 reg_addr //target addr to be modified
275 * u32 bitmask //taget bit pos to be modified
276 * u32 data //value to be written
280 *****************************************************************************/
281 void rtl8192_phy_SetRFReg(struct net_device *dev, RF90_RADIO_PATH_E eRFPath,
282 u32 reg_addr, u32 bitmask, u32 data)
284 struct r8192_priv *priv = ieee80211_priv(dev);
287 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
290 if (priv->Rf_Mode == RF_OP_By_FW) {
291 if (bitmask != bMask12Bits) {
292 /* RF data is 12 bits only */
293 reg = phy_FwRFSerialRead(dev, eRFPath, reg_addr);
294 bitshift = ffs(bitmask) - 1;
296 reg |= data << bitshift;
298 phy_FwRFSerialWrite(dev, eRFPath, reg_addr, reg);
300 phy_FwRFSerialWrite(dev, eRFPath, reg_addr, data);
306 if (bitmask != bMask12Bits) {
307 /* RF data is 12 bits only */
308 reg = rtl8192_phy_RFSerialRead(dev, eRFPath, reg_addr);
309 bitshift = ffs(bitmask) - 1;
311 reg |= data << bitshift;
313 rtl8192_phy_RFSerialWrite(dev, eRFPath, reg_addr, reg);
315 rtl8192_phy_RFSerialWrite(dev, eRFPath, reg_addr, data);
320 /******************************************************************************
321 * function: This function reads specific bits from RF register
322 * input: net_device *dev
323 * u32 reg_addr //target addr to be readback
324 * u32 bitmask //taget bit pos to be readback
326 * return: u32 data //the readback register value
328 *****************************************************************************/
329 u32 rtl8192_phy_QueryRFReg(struct net_device *dev, RF90_RADIO_PATH_E eRFPath,
330 u32 reg_addr, u32 bitmask)
333 struct r8192_priv *priv = ieee80211_priv(dev);
336 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
338 if (priv->Rf_Mode == RF_OP_By_FW) {
339 reg = phy_FwRFSerialRead(dev, eRFPath, reg_addr);
342 reg = rtl8192_phy_RFSerialRead(dev, eRFPath, reg_addr);
344 bitshift = ffs(bitmask) - 1;
345 reg = (reg & bitmask) >> bitshift;
350 /******************************************************************************
351 * function: We support firmware to execute RF-R/W.
352 * input: net_device *dev
353 * RF90_RADIO_PATH_E eRFPath
358 ****************************************************************************/
359 static u32 phy_FwRFSerialRead(struct net_device *dev, RF90_RADIO_PATH_E eRFPath,
367 /* Firmware RF Write control.
368 * We can not execute the scheme in the initial step.
369 * Otherwise, RF-R/W will waste much time.
370 * This is only for site survey.
372 /* 1. Read operation need not insert data. bit 0-11 */
373 /* 2. Write RF register address. bit 12-19 */
374 data |= ((offset&0xFF)<<12);
375 /* 3. Write RF path. bit 20-21 */
376 data |= ((eRFPath&0x3)<<20);
377 /* 4. Set RF read indicator. bit 22=0 */
378 /* 5. Trigger Fw to operate the command. bit 31 */
380 /* 6. We can not execute read operation if bit 31 is 1. */
381 read_nic_dword(dev, QPNR, &tmp);
382 while (tmp & 0x80000000) {
383 /* If FW can not finish RF-R/W for more than ?? times.
388 read_nic_dword(dev, QPNR, &tmp);
393 /* 7. Execute read operation. */
394 write_nic_dword(dev, QPNR, data);
395 /* 8. Check if firmware send back RF content. */
396 read_nic_dword(dev, QPNR, &tmp);
397 while (tmp & 0x80000000) {
398 /* If FW can not finish RF-R/W for more than ?? times.
403 read_nic_dword(dev, QPNR, &tmp);
408 read_nic_dword(dev, RF_DATA, ®);
413 /******************************************************************************
414 * function: We support firmware to execute RF-R/W.
415 * input: net_device *dev
416 * RF90_RADIO_PATH_E eRFPath
422 ****************************************************************************/
423 static void phy_FwRFSerialWrite(struct net_device *dev,
424 RF90_RADIO_PATH_E eRFPath, u32 offset, u32 data)
429 /* Firmware RF Write control.
430 * We can not execute the scheme in the initial step.
431 * Otherwise, RF-R/W will waste much time.
432 * This is only for site survey.
435 /* 1. Set driver write bit and 12 bit data. bit 0-11 */
436 /* 2. Write RF register address. bit 12-19 */
437 data |= ((offset&0xFF)<<12);
438 /* 3. Write RF path. bit 20-21 */
439 data |= ((eRFPath&0x3)<<20);
440 /* 4. Set RF write indicator. bit 22=1 */
442 /* 5. Trigger Fw to operate the command. bit 31=1 */
445 /* 6. Write operation. We can not write if bit 31 is 1. */
446 read_nic_dword(dev, QPNR, &tmp);
447 while (tmp & 0x80000000) {
448 /* If FW can not finish RF-R/W for more than ?? times.
453 read_nic_dword(dev, QPNR, &tmp);
458 /* 7. No matter check bit. We always force the write.
459 * Because FW will not accept the command.
461 write_nic_dword(dev, QPNR, data);
462 /* According to test, we must delay 20us to wait firmware
463 * to finish RF write operation.
465 /* We support delay in firmware side now. */
468 /******************************************************************************
469 * function: This function reads BB parameters from header file we generate,
470 * and do register read/write
471 * input: net_device *dev
474 * notice: BB parameters may change all the time, so please make
475 * sure it has been synced with the newest.
476 *****************************************************************************/
477 void rtl8192_phy_configmac(struct net_device *dev)
479 u32 dwArrayLen = 0, i;
480 u32 *pdwArray = NULL;
481 struct r8192_priv *priv = ieee80211_priv(dev);
483 if (priv->btxpowerdata_readfromEEPORM) {
484 RT_TRACE(COMP_PHY, "Rtl819XMACPHY_Array_PG\n");
485 dwArrayLen = MACPHY_Array_PGLength;
486 pdwArray = rtl819XMACPHY_Array_PG;
489 RT_TRACE(COMP_PHY, "Rtl819XMACPHY_Array\n");
490 dwArrayLen = MACPHY_ArrayLength;
491 pdwArray = rtl819XMACPHY_Array;
493 for (i = 0; i < dwArrayLen; i = i+3) {
494 if (pdwArray[i] == 0x318)
495 pdwArray[i+2] = 0x00000800;
498 "Rtl8190MACPHY_Array[0]=%x Rtl8190MACPHY_Array[1]=%x Rtl8190MACPHY_Array[2]=%x\n",
499 pdwArray[i], pdwArray[i+1], pdwArray[i+2]);
500 rtl8192_setBBreg(dev, pdwArray[i], pdwArray[i+1],
505 /******************************************************************************
506 * function: This function does dirty work
507 * input: net_device *dev
511 * notice: BB parameters may change all the time, so please make
512 * sure it has been synced with the newest.
513 *****************************************************************************/
514 void rtl8192_phyConfigBB(struct net_device *dev, u8 ConfigType)
519 u32 *rtl8192PhyRegArrayTable = NULL, *rtl8192AgcTabArrayTable = NULL;
521 if (Adapter->bInHctTest) {
522 PHY_REGArrayLen = PHY_REGArrayLengthDTM;
523 AGCTAB_ArrayLen = AGCTAB_ArrayLengthDTM;
524 Rtl8190PHY_REGArray_Table = Rtl819XPHY_REGArrayDTM;
525 Rtl8190AGCTAB_Array_Table = Rtl819XAGCTAB_ArrayDTM;
528 if (ConfigType == BaseBand_Config_PHY_REG) {
529 for (i = 0; i < PHY_REG_1T2RArrayLength; i += 2) {
530 rtl8192_setBBreg(dev, rtl819XPHY_REG_1T2RArray[i],
532 rtl819XPHY_REG_1T2RArray[i+1]);
534 "i: %x, Rtl819xUsbPHY_REGArray[0]=%x Rtl819xUsbPHY_REGArray[1]=%x\n",
535 i, rtl819XPHY_REG_1T2RArray[i],
536 rtl819XPHY_REG_1T2RArray[i+1]);
538 } else if (ConfigType == BaseBand_Config_AGC_TAB) {
539 for (i = 0; i < AGCTAB_ArrayLength; i += 2) {
540 rtl8192_setBBreg(dev, rtl819XAGCTAB_Array[i],
541 bMaskDWord, rtl819XAGCTAB_Array[i+1]);
543 "i: %x, rtl819XAGCTAB_Array[0]=%x rtl819XAGCTAB_Array[1]=%x\n",
544 i, rtl819XAGCTAB_Array[i],
545 rtl819XAGCTAB_Array[i+1]);
550 /******************************************************************************
551 * function: This function initializes Register definition offset for
553 * input: net_device *dev
556 * notice: Initialization value here is constant and it should never
558 *****************************************************************************/
559 static void rtl8192_InitBBRFRegDef(struct net_device *dev)
561 struct r8192_priv *priv = ieee80211_priv(dev);
563 /* RF Interface Software Control */
564 /* 16 LSBs if read 32-bit from 0x870 */
565 priv->PHYRegDef[RF90_PATH_A].rfintfs = rFPGA0_XAB_RFInterfaceSW;
566 /* 16 MSBs if read 32-bit from 0x870 (16-bit for 0x872) */
567 priv->PHYRegDef[RF90_PATH_B].rfintfs = rFPGA0_XAB_RFInterfaceSW;
568 /* 16 LSBs if read 32-bit from 0x874 */
569 priv->PHYRegDef[RF90_PATH_C].rfintfs = rFPGA0_XCD_RFInterfaceSW;
570 /* 16 MSBs if read 32-bit from 0x874 (16-bit for 0x876) */
571 priv->PHYRegDef[RF90_PATH_D].rfintfs = rFPGA0_XCD_RFInterfaceSW;
573 /* RF Interface Readback Value */
574 /* 16 LSBs if read 32-bit from 0x8E0 */
575 priv->PHYRegDef[RF90_PATH_A].rfintfi = rFPGA0_XAB_RFInterfaceRB;
576 /* 16 MSBs if read 32-bit from 0x8E0 (16-bit for 0x8E2) */
577 priv->PHYRegDef[RF90_PATH_B].rfintfi = rFPGA0_XAB_RFInterfaceRB;
578 /* 16 LSBs if read 32-bit from 0x8E4 */
579 priv->PHYRegDef[RF90_PATH_C].rfintfi = rFPGA0_XCD_RFInterfaceRB;
580 /* 16 MSBs if read 32-bit from 0x8E4 (16-bit for 0x8E6) */
581 priv->PHYRegDef[RF90_PATH_D].rfintfi = rFPGA0_XCD_RFInterfaceRB;
583 /* RF Interface Output (and Enable) */
584 /* 16 LSBs if read 32-bit from 0x860 */
585 priv->PHYRegDef[RF90_PATH_A].rfintfo = rFPGA0_XA_RFInterfaceOE;
586 /* 16 LSBs if read 32-bit from 0x864 */
587 priv->PHYRegDef[RF90_PATH_B].rfintfo = rFPGA0_XB_RFInterfaceOE;
588 /* 16 LSBs if read 32-bit from 0x868 */
589 priv->PHYRegDef[RF90_PATH_C].rfintfo = rFPGA0_XC_RFInterfaceOE;
590 /* 16 LSBs if read 32-bit from 0x86C */
591 priv->PHYRegDef[RF90_PATH_D].rfintfo = rFPGA0_XD_RFInterfaceOE;
593 /* RF Interface (Output and) Enable */
594 /* 16 MSBs if read 32-bit from 0x860 (16-bit for 0x862) */
595 priv->PHYRegDef[RF90_PATH_A].rfintfe = rFPGA0_XA_RFInterfaceOE;
596 /* 16 MSBs if read 32-bit from 0x864 (16-bit for 0x866) */
597 priv->PHYRegDef[RF90_PATH_B].rfintfe = rFPGA0_XB_RFInterfaceOE;
598 /* 16 MSBs if read 32-bit from 0x86A (16-bit for 0x86A) */
599 priv->PHYRegDef[RF90_PATH_C].rfintfe = rFPGA0_XC_RFInterfaceOE;
600 /* 16 MSBs if read 32-bit from 0x86C (16-bit for 0x86E) */
601 priv->PHYRegDef[RF90_PATH_D].rfintfe = rFPGA0_XD_RFInterfaceOE;
603 /* Addr of LSSI. Write RF register by driver */
604 priv->PHYRegDef[RF90_PATH_A].rf3wireOffset = rFPGA0_XA_LSSIParameter;
605 priv->PHYRegDef[RF90_PATH_B].rf3wireOffset = rFPGA0_XB_LSSIParameter;
606 priv->PHYRegDef[RF90_PATH_C].rf3wireOffset = rFPGA0_XC_LSSIParameter;
607 priv->PHYRegDef[RF90_PATH_D].rf3wireOffset = rFPGA0_XD_LSSIParameter;
611 priv->PHYRegDef[RF90_PATH_A].rfLSSI_Select = rFPGA0_XAB_RFParameter;
612 priv->PHYRegDef[RF90_PATH_B].rfLSSI_Select = rFPGA0_XAB_RFParameter;
613 priv->PHYRegDef[RF90_PATH_C].rfLSSI_Select = rFPGA0_XCD_RFParameter;
614 priv->PHYRegDef[RF90_PATH_D].rfLSSI_Select = rFPGA0_XCD_RFParameter;
616 /* Tx AGC Gain Stage (same for all path. Should we remove this?) */
617 priv->PHYRegDef[RF90_PATH_A].rfTxGainStage = rFPGA0_TxGainStage;
618 priv->PHYRegDef[RF90_PATH_B].rfTxGainStage = rFPGA0_TxGainStage;
619 priv->PHYRegDef[RF90_PATH_C].rfTxGainStage = rFPGA0_TxGainStage;
620 priv->PHYRegDef[RF90_PATH_D].rfTxGainStage = rFPGA0_TxGainStage;
622 /* Tranceiver A~D HSSI Parameter-1 */
623 /* wire control parameter1 */
624 priv->PHYRegDef[RF90_PATH_A].rfHSSIPara1 = rFPGA0_XA_HSSIParameter1;
625 priv->PHYRegDef[RF90_PATH_B].rfHSSIPara1 = rFPGA0_XB_HSSIParameter1;
626 priv->PHYRegDef[RF90_PATH_C].rfHSSIPara1 = rFPGA0_XC_HSSIParameter1;
627 priv->PHYRegDef[RF90_PATH_D].rfHSSIPara1 = rFPGA0_XD_HSSIParameter1;
629 /* Tranceiver A~D HSSI Parameter-2 */
630 /* wire control parameter2 */
631 priv->PHYRegDef[RF90_PATH_A].rfHSSIPara2 = rFPGA0_XA_HSSIParameter2;
632 priv->PHYRegDef[RF90_PATH_B].rfHSSIPara2 = rFPGA0_XB_HSSIParameter2;
633 priv->PHYRegDef[RF90_PATH_C].rfHSSIPara2 = rFPGA0_XC_HSSIParameter2;
634 priv->PHYRegDef[RF90_PATH_D].rfHSSIPara2 = rFPGA0_XD_HSSIParameter2;
636 /* RF Switch Control */
637 /* TR/Ant switch control */
638 priv->PHYRegDef[RF90_PATH_A].rfSwitchControl = rFPGA0_XAB_SwitchControl;
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;
655 /* RX AFE control 1 */
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;
661 /* RX AFE control 1 */
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;
667 /* Tx AFE control 1 */
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;
673 /* Tx AFE control 2 */
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
688 * sure whether BB and RF is OK
689 * input: net_device *dev
690 * HW90_BLOCK_E CheckBlock
691 * RF90_RADIO_PATH_E eRFPath //only used when checkblock is
694 * return: return whether BB and RF is ok (0:OK, 1:Fail)
695 * notice: This function may be removed in the ASIC
696 ******************************************************************************/
697 u8 rtl8192_phy_checkBBAndRF(struct net_device *dev, HW90_BLOCK_E CheckBlock,
698 RF90_RADIO_PATH_E eRFPath)
701 u32 i, CheckTimes = 4, reg = 0;
703 u32 WriteData[] = {0xfffff027, 0xaa55a02f, 0x00000027, 0x55aa502f};
705 /* Initialize register address offset to be checked */
706 WriteAddr[HW90_BLOCK_MAC] = 0x100;
707 WriteAddr[HW90_BLOCK_PHY0] = 0x900;
708 WriteAddr[HW90_BLOCK_PHY1] = 0x800;
709 WriteAddr[HW90_BLOCK_RF] = 0x3;
710 RT_TRACE(COMP_PHY, "%s(), CheckBlock: %d\n", __func__, CheckBlock);
711 for (i = 0; i < CheckTimes; i++) {
713 /* Write data to register and readback */
714 switch (CheckBlock) {
717 "PHY_CheckBBRFOK(): Never Write 0x100 here!\n");
720 case HW90_BLOCK_PHY0:
721 case HW90_BLOCK_PHY1:
722 write_nic_dword(dev, WriteAddr[CheckBlock],
724 read_nic_dword(dev, WriteAddr[CheckBlock], ®);
728 WriteData[i] &= 0xfff;
729 rtl8192_phy_SetRFReg(dev, eRFPath,
730 WriteAddr[HW90_BLOCK_RF],
731 bMask12Bits, WriteData[i]);
732 /* TODO: we should not delay for such a long time.
735 usleep_range(1000, 1000);
736 reg = rtl8192_phy_QueryRFReg(dev, eRFPath,
737 WriteAddr[HW90_BLOCK_RF],
739 usleep_range(1000, 1000);
748 /* Check whether readback data is correct */
749 if (reg != WriteData[i]) {
750 RT_TRACE((COMP_PHY|COMP_ERR),
751 "error reg: %x, WriteData: %x\n",
761 /******************************************************************************
762 * function: This function initializes BB&RF
763 * input: net_device *dev
766 * notice: Initialization value may change all the time, so please make
767 * sure it has been synced with the newest.
768 ******************************************************************************/
769 static void rtl8192_BB_Config_ParaFile(struct net_device *dev)
771 struct r8192_priv *priv = ieee80211_priv(dev);
772 u8 reg_u8 = 0, eCheckItem = 0, status = 0;
775 /**************************************
776 * <1> Initialize BaseBand
777 *************************************/
779 /* --set BB Global Reset-- */
780 read_nic_byte(dev, BB_GLOBAL_RESET, ®_u8);
781 write_nic_byte(dev, BB_GLOBAL_RESET, (reg_u8|BB_GLOBAL_RESET_BIT));
783 /* ---set BB reset Active--- */
784 read_nic_dword(dev, CPU_GEN, ®_u32);
785 write_nic_dword(dev, CPU_GEN, (reg_u32&(~CPU_GEN_BB_RST)));
787 /* ----Ckeck FPGAPHY0 and PHY1 board is OK---- */
788 /* TODO: this function should be removed on ASIC */
789 for (eCheckItem = (HW90_BLOCK_E)HW90_BLOCK_PHY0;
790 eCheckItem <= HW90_BLOCK_PHY1; eCheckItem++) {
791 /* don't care RF path */
792 status = rtl8192_phy_checkBBAndRF(dev, (HW90_BLOCK_E)eCheckItem,
793 (RF90_RADIO_PATH_E)0);
795 RT_TRACE((COMP_ERR | COMP_PHY),
796 "PHY_RF8256_Config(): Check PHY%d Fail!!\n",
801 /* ---- Set CCK and OFDM Block "OFF"---- */
802 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bCCKEn|bOFDMEn, 0x0);
803 /* ----BB Register Initilazation---- */
804 /* ==m==>Set PHY REG From Header<==m== */
805 rtl8192_phyConfigBB(dev, BaseBand_Config_PHY_REG);
807 /* ----Set BB reset de-Active---- */
808 read_nic_dword(dev, CPU_GEN, ®_u32);
809 write_nic_dword(dev, CPU_GEN, (reg_u32|CPU_GEN_BB_RST));
811 /* ----BB AGC table Initialization---- */
812 /* ==m==>Set PHY REG From Header<==m== */
813 rtl8192_phyConfigBB(dev, BaseBand_Config_AGC_TAB);
815 /* ----Enable XSTAL ---- */
816 write_nic_byte_E(dev, 0x5e, 0x00);
817 if (priv->card_8192_version == (u8)VERSION_819xU_A) {
818 /* Antenna gain offset from B/C/D to A */
819 reg_u32 = priv->AntennaTxPwDiff[1]<<4 |
820 priv->AntennaTxPwDiff[0];
821 rtl8192_setBBreg(dev, rFPGA0_TxGainStage, (bXBTxAGC|bXCTxAGC),
825 reg_u32 = priv->CrystalCap & 0xf;
826 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, bXtalCap,
830 /* Check if the CCK HighPower is turned ON.
831 * This is used to calculate PWDB.
833 priv->bCckHighPower = (u8)rtl8192_QueryBBReg(dev,
834 rFPGA0_XA_HSSIParameter2,
838 /******************************************************************************
839 * function: This function initializes BB&RF
840 * input: net_device *dev
843 * notice: Initialization value may change all the time, so please make
844 * sure it has been synced with the newest.
845 *****************************************************************************/
846 void rtl8192_BBConfig(struct net_device *dev)
848 rtl8192_InitBBRFRegDef(dev);
849 /* config BB&RF. As hardCode based initialization has not been well
850 * implemented, so use file first.
851 * FIXME: should implement it for hardcode?
853 rtl8192_BB_Config_ParaFile(dev);
857 /******************************************************************************
858 * function: This function obtains the initialization value of Tx power Level
860 * input: net_device *dev
863 *****************************************************************************/
864 void rtl8192_phy_getTxPower(struct net_device *dev)
866 struct r8192_priv *priv = ieee80211_priv(dev);
869 read_nic_dword(dev, rTxAGC_Rate18_06,
870 &priv->MCSTxPowerLevelOriginalOffset[0]);
871 read_nic_dword(dev, rTxAGC_Rate54_24,
872 &priv->MCSTxPowerLevelOriginalOffset[1]);
873 read_nic_dword(dev, rTxAGC_Mcs03_Mcs00,
874 &priv->MCSTxPowerLevelOriginalOffset[2]);
875 read_nic_dword(dev, rTxAGC_Mcs07_Mcs04,
876 &priv->MCSTxPowerLevelOriginalOffset[3]);
877 read_nic_dword(dev, rTxAGC_Mcs11_Mcs08,
878 &priv->MCSTxPowerLevelOriginalOffset[4]);
879 read_nic_dword(dev, rTxAGC_Mcs15_Mcs12,
880 &priv->MCSTxPowerLevelOriginalOffset[5]);
882 /* Read rx initial gain */
883 read_nic_byte(dev, rOFDM0_XAAGCCore1, &priv->DefaultInitialGain[0]);
884 read_nic_byte(dev, rOFDM0_XBAGCCore1, &priv->DefaultInitialGain[1]);
885 read_nic_byte(dev, rOFDM0_XCAGCCore1, &priv->DefaultInitialGain[2]);
886 read_nic_byte(dev, rOFDM0_XDAGCCore1, &priv->DefaultInitialGain[3]);
888 "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x)\n",
889 priv->DefaultInitialGain[0], priv->DefaultInitialGain[1],
890 priv->DefaultInitialGain[2], priv->DefaultInitialGain[3]);
893 read_nic_byte(dev, rOFDM0_RxDetector3, &priv->framesync);
894 read_nic_byte(dev, rOFDM0_RxDetector2, &tmp);
895 priv->framesyncC34 = tmp;
896 RT_TRACE(COMP_INIT, "Default framesync (0x%x) = 0x%x\n",
897 rOFDM0_RxDetector3, priv->framesync);
899 /* Read SIFS (save the value read fome MACPHY_REG.txt) */
900 read_nic_word(dev, SIFS, &priv->SifsTime);
903 /******************************************************************************
904 * function: This function sets the initialization value of Tx power Level
906 * input: net_device *dev
910 ******************************************************************************/
911 void rtl8192_phy_setTxPower(struct net_device *dev, u8 channel)
913 struct r8192_priv *priv = ieee80211_priv(dev);
914 u8 powerlevel = priv->TxPowerLevelCCK[channel-1];
915 u8 powerlevelOFDM24G = priv->TxPowerLevelOFDM24G[channel-1];
917 switch (priv->rf_chip) {
919 /* need further implement */
920 PHY_SetRF8256CCKTxPower(dev, powerlevel);
921 PHY_SetRF8256OFDMTxPower(dev, powerlevelOFDM24G);
924 RT_TRACE((COMP_PHY|COMP_ERR),
925 "error RF chipID(8225 or 8258) in function %s()\n",
931 /******************************************************************************
932 * function: This function checks Rf chip to do RF config
933 * input: net_device *dev
935 * return: only 8256 is supported
936 ******************************************************************************/
937 void rtl8192_phy_RFConfig(struct net_device *dev)
939 struct r8192_priv *priv = ieee80211_priv(dev);
941 switch (priv->rf_chip) {
943 PHY_RF8256_Config(dev);
946 RT_TRACE(COMP_ERR, "error chip id\n");
951 /******************************************************************************
952 * function: This function updates Initial gain
953 * input: net_device *dev
955 * return: As Windows has not implemented this, wait for complement
956 ******************************************************************************/
957 void rtl8192_phy_updateInitGain(struct net_device *dev)
961 /******************************************************************************
962 * function: This function read RF parameters from general head file,
964 * input: net_device *dev
965 * RF90_RADIO_PATH_E eRFPath
967 * return: return code show if RF configuration is successful(0:pass, 1:fail)
968 * notice: Delay may be required for RF configuration
969 *****************************************************************************/
970 u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device *dev,
971 RF90_RADIO_PATH_E eRFPath)
978 for (i = 0; i < RadioA_ArrayLength; i = i+2) {
980 if (rtl819XRadioA_Array[i] == 0xfe) {
984 rtl8192_phy_SetRFReg(dev, eRFPath,
985 rtl819XRadioA_Array[i],
987 rtl819XRadioA_Array[i+1]);
993 for (i = 0; i < RadioB_ArrayLength; i = i+2) {
995 if (rtl819XRadioB_Array[i] == 0xfe) {
999 rtl8192_phy_SetRFReg(dev, eRFPath,
1000 rtl819XRadioB_Array[i],
1002 rtl819XRadioB_Array[i+1]);
1008 for (i = 0; i < RadioC_ArrayLength; i = i+2) {
1010 if (rtl819XRadioC_Array[i] == 0xfe) {
1014 rtl8192_phy_SetRFReg(dev, eRFPath,
1015 rtl819XRadioC_Array[i],
1017 rtl819XRadioC_Array[i+1]);
1023 for (i = 0; i < RadioD_ArrayLength; i = i+2) {
1025 if (rtl819XRadioD_Array[i] == 0xfe) {
1029 rtl8192_phy_SetRFReg(dev, eRFPath,
1030 rtl819XRadioD_Array[i],
1032 rtl819XRadioD_Array[i+1]);
1045 /******************************************************************************
1046 * function: This function sets Tx Power of the channel
1047 * input: net_device *dev
1052 ******************************************************************************/
1053 static void rtl8192_SetTxPowerLevel(struct net_device *dev, u8 channel)
1055 struct r8192_priv *priv = ieee80211_priv(dev);
1056 u8 powerlevel = priv->TxPowerLevelCCK[channel-1];
1057 u8 powerlevelOFDM24G = priv->TxPowerLevelOFDM24G[channel-1];
1059 switch (priv->rf_chip) {
1062 PHY_SetRF8225CckTxPower(Adapter, powerlevel);
1063 PHY_SetRF8225OfdmTxPower(Adapter, powerlevelOFDM24G);
1068 PHY_SetRF8256CCKTxPower(dev, powerlevel);
1069 PHY_SetRF8256OFDMTxPower(dev, powerlevelOFDM24G);
1075 RT_TRACE(COMP_ERR, "unknown rf chip ID in %s()\n", __func__);
1080 /******************************************************************************
1081 * function: This function sets RF state on or off
1082 * input: net_device *dev
1083 * RT_RF_POWER_STATE eRFPowerState //Power State to set
1087 *****************************************************************************/
1088 bool rtl8192_SetRFPowerState(struct net_device *dev,
1089 RT_RF_POWER_STATE eRFPowerState)
1091 bool bResult = true;
1092 struct r8192_priv *priv = ieee80211_priv(dev);
1094 if (eRFPowerState == priv->ieee80211->eRFPowerState)
1097 if (priv->SetRFPowerStateInProgress)
1100 priv->SetRFPowerStateInProgress = true;
1102 switch (priv->rf_chip) {
1104 switch (eRFPowerState) {
1107 /* enable RF-Chip A/B - 0x860[4] */
1108 rtl8192_setBBreg(dev, rFPGA0_XA_RFInterfaceOE, BIT(4),
1110 /* analog to digital on - 0x88c[9:8] */
1111 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0x300,
1113 /* digital to analog on - 0x880[4:3] */
1114 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x18,
1116 /* rx antenna on - 0xc04[1:0] */
1117 rtl8192_setBBreg(dev, rOFDM0_TRxPathEnable, 0x3, 0x3);
1118 /* rx antenna on - 0xd04[1:0] */
1119 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0x3, 0x3);
1120 /* analog to digital part2 on - 0x880[6:5] */
1121 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x60,
1132 /* disable RF-Chip A/B - 0x860[4] */
1133 rtl8192_setBBreg(dev, rFPGA0_XA_RFInterfaceOE, BIT(4),
1135 /* analog to digital off, for power save */
1136 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0xf00,
1137 0x0); /* 0x88c[11:8] */
1138 /* digital to analog off, for power save - 0x880[4:3] */
1139 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x18,
1141 /* rx antenna off - 0xc04[3:0] */
1142 rtl8192_setBBreg(dev, rOFDM0_TRxPathEnable, 0xf, 0x0);
1143 /* rx antenna off - 0xd04[3:0] */
1144 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0x0);
1145 /* analog to digital part2 off, for power save */
1146 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x60,
1147 0x0); /* 0x880[6:5] */
1153 RT_TRACE(COMP_ERR, "%s(): unknown state to set: 0x%X\n",
1154 __func__, eRFPowerState);
1159 RT_TRACE(COMP_ERR, "Not support rf_chip(%x)\n", priv->rf_chip);
1164 /* Update current RF state variable. */
1165 pHalData->eRFPowerState = eRFPowerState;
1166 switch (pHalData->RFChipID) {
1168 switch (pHalData->eRFPowerState) {
1170 /* If Rf off reason is from IPS,
1171 * LED should blink with no link
1173 if (pMgntInfo->RfOffReason == RF_CHANGE_BY_IPS)
1174 Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_NO_LINK);
1176 /* Turn off LED if RF is not ON. */
1177 Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_POWER_OFF);
1181 /* Turn on RF we are still linked, which might
1182 * happen when we quickly turn off and on HW RF.
1184 if (pMgntInfo->bMediaConnect)
1185 Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_LINK);
1187 /* Turn off LED if RF is not ON. */
1188 Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_NO_LINK);
1197 RT_TRACE(COMP_RF, DBG_LOUD, "%s(): Unknown RF type\n",
1204 priv->SetRFPowerStateInProgress = false;
1209 /******************************************************************************
1210 * function: This function sets command table variable (struct SwChnlCmd).
1211 * input: SwChnlCmd *CmdTable //table to be set
1212 * u32 CmdTableIdx //variable index in table to be set
1213 * u32 CmdTableSz //table size
1214 * SwChnlCmdID CmdID //command ID to set
1219 * return: true if finished, false otherwise
1221 ******************************************************************************/
1222 static u8 rtl8192_phy_SetSwChnlCmdArray(SwChnlCmd *CmdTable, u32 CmdTableIdx,
1223 u32 CmdTableSz, SwChnlCmdID CmdID,
1224 u32 Para1, u32 Para2, u32 msDelay)
1228 if (CmdTable == NULL) {
1229 RT_TRACE(COMP_ERR, "%s(): CmdTable cannot be NULL\n", __func__);
1232 if (CmdTableIdx >= CmdTableSz) {
1233 RT_TRACE(COMP_ERR, "%s(): Access invalid index, please check size of the table, CmdTableIdx:%d, CmdTableSz:%d\n",
1234 __func__, CmdTableIdx, CmdTableSz);
1238 pCmd = CmdTable + CmdTableIdx;
1239 pCmd->CmdID = CmdID;
1240 pCmd->Para1 = Para1;
1241 pCmd->Para2 = Para2;
1242 pCmd->msDelay = msDelay;
1247 /******************************************************************************
1248 * function: This function sets channel step by step
1249 * input: net_device *dev
1251 * u8 *stage //3 stages
1253 * u32 *delay //whether need to delay
1254 * output: store new stage, step and delay for next step
1255 * (combine with function above)
1256 * return: true if finished, false otherwise
1257 * notice: Wait for simpler function to replace it
1258 *****************************************************************************/
1259 static u8 rtl8192_phy_SwChnlStepByStep(struct net_device *dev, u8 channel,
1260 u8 *stage, u8 *step, u32 *delay)
1262 struct r8192_priv *priv = ieee80211_priv(dev);
1263 SwChnlCmd PreCommonCmd[MAX_PRECMD_CNT];
1264 u32 PreCommonCmdCnt;
1265 SwChnlCmd PostCommonCmd[MAX_POSTCMD_CNT];
1266 u32 PostCommonCmdCnt;
1267 SwChnlCmd RfDependCmd[MAX_RFDEPENDCMD_CNT];
1269 SwChnlCmd *CurrentCmd = NULL;
1272 RT_TRACE(COMP_CH, "%s() stage: %d, step: %d, channel: %d\n",
1273 __func__, *stage, *step, channel);
1274 if (!IsLegalChannel(priv->ieee80211, channel)) {
1275 RT_TRACE(COMP_ERR, "set to illegal channel: %d\n", channel);
1276 /* return true to tell upper caller function this channel
1277 * setting is finished! Or it will in while loop.
1281 /* FIXME: need to check whether channel is legal or not here */
1284 /* <1> Fill up pre common command. */
1285 PreCommonCmdCnt = 0;
1286 rtl8192_phy_SetSwChnlCmdArray(PreCommonCmd, PreCommonCmdCnt++,
1287 MAX_PRECMD_CNT, CmdID_SetTxPowerLevel,
1289 rtl8192_phy_SetSwChnlCmdArray(PreCommonCmd, PreCommonCmdCnt++,
1290 MAX_PRECMD_CNT, CmdID_End, 0, 0, 0);
1292 /* <2> Fill up post common command. */
1293 PostCommonCmdCnt = 0;
1295 rtl8192_phy_SetSwChnlCmdArray(PostCommonCmd, PostCommonCmdCnt++,
1296 MAX_POSTCMD_CNT, CmdID_End, 0, 0, 0);
1298 /* <3> Fill up RF dependent command. */
1300 switch (priv->rf_chip) {
1302 if (!(channel >= 1 && channel <= 14)) {
1304 "illegal channel for Zebra 8225: %d\n",
1308 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++,
1309 MAX_RFDEPENDCMD_CNT,
1312 RF_CHANNEL_TABLE_ZEBRA[channel],
1314 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++,
1315 MAX_RFDEPENDCMD_CNT,
1316 CmdID_End, 0, 0, 0);
1320 /* TEST!! This is not the table for 8256!! */
1321 if (!(channel >= 1 && channel <= 14)) {
1323 "illegal channel for Zebra 8256: %d\n",
1327 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++,
1328 MAX_RFDEPENDCMD_CNT,
1330 rZebra1_Channel, channel, 10);
1331 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++,
1332 MAX_RFDEPENDCMD_CNT,
1333 CmdID_End, 0, 0, 0);
1340 RT_TRACE(COMP_ERR, "Unknown RFChipID: %d\n", priv->rf_chip);
1348 CurrentCmd = &PreCommonCmd[*step];
1351 CurrentCmd = &RfDependCmd[*step];
1354 CurrentCmd = &PostCommonCmd[*step];
1358 if (CurrentCmd->CmdID == CmdID_End) {
1359 if ((*stage) == 2) {
1360 (*delay) = CurrentCmd->msDelay;
1368 switch (CurrentCmd->CmdID) {
1369 case CmdID_SetTxPowerLevel:
1370 if (priv->card_8192_version == (u8)VERSION_819xU_A)
1371 /* consider it later! */
1372 rtl8192_SetTxPowerLevel(dev, channel);
1374 case CmdID_WritePortUlong:
1375 write_nic_dword(dev, CurrentCmd->Para1,
1378 case CmdID_WritePortUshort:
1379 write_nic_word(dev, CurrentCmd->Para1,
1380 (u16)CurrentCmd->Para2);
1382 case CmdID_WritePortUchar:
1383 write_nic_byte(dev, CurrentCmd->Para1,
1384 (u8)CurrentCmd->Para2);
1386 case CmdID_RF_WriteReg:
1387 for (eRFPath = 0; eRFPath < RF90_PATH_MAX; eRFPath++) {
1388 rtl8192_phy_SetRFReg(dev,
1389 (RF90_RADIO_PATH_E)eRFPath,
1402 (*delay) = CurrentCmd->msDelay;
1407 /******************************************************************************
1408 * function: This function does actually set channel work
1409 * input: net_device *dev
1413 * notice: We should not call this function directly
1414 *****************************************************************************/
1415 static void rtl8192_phy_FinishSwChnlNow(struct net_device *dev, u8 channel)
1417 struct r8192_priv *priv = ieee80211_priv(dev);
1420 while (!rtl8192_phy_SwChnlStepByStep(dev, channel, &priv->SwChnlStage,
1421 &priv->SwChnlStep, &delay)) {
1427 /******************************************************************************
1428 * function: Callback routine of the work item for switch channel.
1429 * input: net_device *dev
1433 *****************************************************************************/
1434 void rtl8192_SwChnl_WorkItem(struct net_device *dev)
1437 struct r8192_priv *priv = ieee80211_priv(dev);
1439 RT_TRACE(COMP_CH, "==> SwChnlCallback819xUsbWorkItem(), chan:%d\n",
1443 rtl8192_phy_FinishSwChnlNow(dev, priv->chan);
1445 RT_TRACE(COMP_CH, "<== SwChnlCallback819xUsbWorkItem()\n");
1448 /******************************************************************************
1449 * function: This function scheduled actual work item to set channel
1450 * input: net_device *dev
1451 * u8 channel //channel to set
1453 * return: return code show if workitem is scheduled (1:pass, 0:fail)
1454 * notice: Delay may be required for RF configuration
1455 ******************************************************************************/
1456 u8 rtl8192_phy_SwChnl(struct net_device *dev, u8 channel)
1458 struct r8192_priv *priv = ieee80211_priv(dev);
1460 RT_TRACE(COMP_CH, "%s(), SwChnlInProgress: %d\n", __func__,
1461 priv->SwChnlInProgress);
1464 if (priv->SwChnlInProgress)
1467 /* -------------------------------------------- */
1468 switch (priv->ieee80211->mode) {
1469 case WIRELESS_MODE_A:
1470 case WIRELESS_MODE_N_5G:
1471 if (channel <= 14) {
1472 RT_TRACE(COMP_ERR, "WIRELESS_MODE_A but channel<=14\n");
1476 case WIRELESS_MODE_B:
1478 RT_TRACE(COMP_ERR, "WIRELESS_MODE_B but channel>14\n");
1482 case WIRELESS_MODE_G:
1483 case WIRELESS_MODE_N_24G:
1485 RT_TRACE(COMP_ERR, "WIRELESS_MODE_G but channel>14\n");
1490 /* -------------------------------------------- */
1492 priv->SwChnlInProgress = true;
1496 priv->chan = channel;
1498 priv->SwChnlStage = 0;
1499 priv->SwChnlStep = 0;
1501 rtl8192_SwChnl_WorkItem(dev);
1503 priv->SwChnlInProgress = false;
1507 /******************************************************************************
1508 * function: Callback routine of the work item for set bandwidth mode.
1509 * input: net_device *dev
1512 * notice: I doubt whether SetBWModeInProgress flag is necessary as we can
1513 * test whether current work in the queue or not.//do I?
1514 *****************************************************************************/
1515 void rtl8192_SetBWModeWorkItem(struct net_device *dev)
1518 struct r8192_priv *priv = ieee80211_priv(dev);
1521 RT_TRACE(COMP_SWBW, "%s() Switch to %s bandwidth\n", __func__,
1522 priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz");
1525 if (priv->rf_chip == RF_PSEUDO_11N) {
1526 priv->SetBWModeInProgress = false;
1530 /* <1> Set MAC register */
1531 read_nic_byte(dev, BW_OPMODE, ®BwOpMode);
1533 switch (priv->CurrentChannelBW) {
1534 case HT_CHANNEL_WIDTH_20:
1535 regBwOpMode |= BW_OPMODE_20MHZ;
1536 /* We have not verify whether this register works */
1537 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
1540 case HT_CHANNEL_WIDTH_20_40:
1541 regBwOpMode &= ~BW_OPMODE_20MHZ;
1542 /* We have not verify whether this register works */
1543 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
1548 "SetChannelBandwidth819xUsb(): unknown Bandwidth: %#X\n",
1549 priv->CurrentChannelBW);
1553 /* <2> Set PHY related register */
1554 switch (priv->CurrentChannelBW) {
1555 case HT_CHANNEL_WIDTH_20:
1556 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x0);
1557 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x0);
1558 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1,
1561 /* Correct the tx power for CCK rate in 20M. */
1562 priv->cck_present_attentuation =
1563 priv->cck_present_attentuation_20Mdefault +
1564 priv->cck_present_attentuation_difference;
1566 if (priv->cck_present_attentuation > 22)
1567 priv->cck_present_attentuation = 22;
1568 if (priv->cck_present_attentuation < 0)
1569 priv->cck_present_attentuation = 0;
1571 "20M, pHalData->CCKPresentAttentuation = %d\n",
1572 priv->cck_present_attentuation);
1574 if (priv->chan == 14 && !priv->bcck_in_ch14) {
1575 priv->bcck_in_ch14 = true;
1576 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
1577 } else if (priv->chan != 14 && priv->bcck_in_ch14) {
1578 priv->bcck_in_ch14 = false;
1579 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
1581 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
1585 case HT_CHANNEL_WIDTH_20_40:
1586 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x1);
1587 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x1);
1588 rtl8192_setBBreg(dev, rCCK0_System, bCCKSideBand,
1589 priv->nCur40MhzPrimeSC>>1);
1590 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00100000, 0);
1591 rtl8192_setBBreg(dev, rOFDM1_LSTF, 0xC00,
1592 priv->nCur40MhzPrimeSC);
1593 priv->cck_present_attentuation =
1594 priv->cck_present_attentuation_40Mdefault +
1595 priv->cck_present_attentuation_difference;
1597 if (priv->cck_present_attentuation > 22)
1598 priv->cck_present_attentuation = 22;
1599 if (priv->cck_present_attentuation < 0)
1600 priv->cck_present_attentuation = 0;
1603 "40M, pHalData->CCKPresentAttentuation = %d\n",
1604 priv->cck_present_attentuation);
1605 if (priv->chan == 14 && !priv->bcck_in_ch14) {
1606 priv->bcck_in_ch14 = true;
1607 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
1608 } else if (priv->chan != 14 && priv->bcck_in_ch14) {
1609 priv->bcck_in_ch14 = false;
1610 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
1612 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
1618 "SetChannelBandwidth819xUsb(): unknown Bandwidth: %#X\n",
1619 priv->CurrentChannelBW);
1623 /* Skip over setting of J-mode in BB register here.
1624 * Default value is "None J mode".
1627 /* <3> Set RF related register */
1628 switch (priv->rf_chip) {
1631 PHY_SetRF8225Bandwidth(Adapter, pHalData->CurrentChannelBW);
1636 PHY_SetRF8256Bandwidth(dev, priv->CurrentChannelBW);
1646 RT_TRACE(COMP_ERR, "Unknown RFChipID: %d\n", priv->rf_chip);
1649 priv->SetBWModeInProgress = false;
1651 RT_TRACE(COMP_SWBW, "<==SetBWMode819xUsb(), %d\n",
1652 atomic_read(&priv->ieee80211->atm_swbw));
1655 /******************************************************************************
1656 * function: This function schedules bandwidth switch work.
1657 * input: struct net_deviceq *dev
1658 * HT_CHANNEL_WIDTH bandwidth //20M or 40M
1659 * HT_EXTCHNL_OFFSET offset //Upper, Lower, or Don't care
1662 * notice: I doubt whether SetBWModeInProgress flag is necessary as we can
1663 * test whether current work in the queue or not.//do I?
1664 *****************************************************************************/
1665 void rtl8192_SetBWMode(struct net_device *dev, HT_CHANNEL_WIDTH bandwidth,
1666 HT_EXTCHNL_OFFSET offset)
1668 struct r8192_priv *priv = ieee80211_priv(dev);
1670 if (priv->SetBWModeInProgress)
1672 priv->SetBWModeInProgress = true;
1674 priv->CurrentChannelBW = bandwidth;
1676 if (offset == HT_EXTCHNL_OFFSET_LOWER)
1677 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_UPPER;
1678 else if (offset == HT_EXTCHNL_OFFSET_UPPER)
1679 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_LOWER;
1681 priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
1683 rtl8192_SetBWModeWorkItem(dev);
1687 void InitialGain819xUsb(struct net_device *dev, u8 Operation)
1689 struct r8192_priv *priv = ieee80211_priv(dev);
1691 priv->InitialGainOperateType = Operation;
1694 queue_delayed_work(priv->priv_wq, &priv->initialgain_operate_wq, 0);
1697 void InitialGainOperateWorkItemCallBack(struct work_struct *work)
1699 struct delayed_work *dwork = to_delayed_work(work);
1700 struct r8192_priv *priv = container_of(dwork, struct r8192_priv,
1701 initialgain_operate_wq);
1702 struct net_device *dev = priv->ieee80211->dev;
1703 #define SCAN_RX_INITIAL_GAIN 0x17
1704 #define POWER_DETECTION_TH 0x08
1709 Operation = priv->InitialGainOperateType;
1711 switch (Operation) {
1713 RT_TRACE(COMP_SCAN, "IG_Backup, backup the initial gain.\n");
1714 initial_gain = SCAN_RX_INITIAL_GAIN;
1715 bitmask = bMaskByte0;
1716 if (dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
1718 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8);
1719 priv->initgain_backup.xaagccore1 =
1720 (u8)rtl8192_QueryBBReg(dev, rOFDM0_XAAGCCore1, bitmask);
1721 priv->initgain_backup.xbagccore1 =
1722 (u8)rtl8192_QueryBBReg(dev, rOFDM0_XBAGCCore1, bitmask);
1723 priv->initgain_backup.xcagccore1 =
1724 (u8)rtl8192_QueryBBReg(dev, rOFDM0_XCAGCCore1, bitmask);
1725 priv->initgain_backup.xdagccore1 =
1726 (u8)rtl8192_QueryBBReg(dev, rOFDM0_XDAGCCore1, bitmask);
1727 bitmask = bMaskByte2;
1728 priv->initgain_backup.cca =
1729 (u8)rtl8192_QueryBBReg(dev, rCCK0_CCA, bitmask);
1731 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc50 is %x\n",
1732 priv->initgain_backup.xaagccore1);
1733 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc58 is %x\n",
1734 priv->initgain_backup.xbagccore1);
1735 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc60 is %x\n",
1736 priv->initgain_backup.xcagccore1);
1737 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc68 is %x\n",
1738 priv->initgain_backup.xdagccore1);
1739 RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xa0a is %x\n",
1740 priv->initgain_backup.cca);
1742 RT_TRACE(COMP_SCAN, "Write scan initial gain = 0x%x\n",
1744 write_nic_byte(dev, rOFDM0_XAAGCCore1, initial_gain);
1745 write_nic_byte(dev, rOFDM0_XBAGCCore1, initial_gain);
1746 write_nic_byte(dev, rOFDM0_XCAGCCore1, initial_gain);
1747 write_nic_byte(dev, rOFDM0_XDAGCCore1, initial_gain);
1748 RT_TRACE(COMP_SCAN, "Write scan 0xa0a = 0x%x\n",
1749 POWER_DETECTION_TH);
1750 write_nic_byte(dev, 0xa0a, POWER_DETECTION_TH);
1753 RT_TRACE(COMP_SCAN, "IG_Restore, restore the initial gain.\n");
1754 bitmask = 0x7f; /* Bit0 ~ Bit6 */
1755 if (dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
1757 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8);
1759 rtl8192_setBBreg(dev, rOFDM0_XAAGCCore1, bitmask,
1760 (u32)priv->initgain_backup.xaagccore1);
1761 rtl8192_setBBreg(dev, rOFDM0_XBAGCCore1, bitmask,
1762 (u32)priv->initgain_backup.xbagccore1);
1763 rtl8192_setBBreg(dev, rOFDM0_XCAGCCore1, bitmask,
1764 (u32)priv->initgain_backup.xcagccore1);
1765 rtl8192_setBBreg(dev, rOFDM0_XDAGCCore1, bitmask,
1766 (u32)priv->initgain_backup.xdagccore1);
1767 bitmask = bMaskByte2;
1768 rtl8192_setBBreg(dev, rCCK0_CCA, bitmask,
1769 (u32)priv->initgain_backup.cca);
1771 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc50 is %x\n",
1772 priv->initgain_backup.xaagccore1);
1773 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc58 is %x\n",
1774 priv->initgain_backup.xbagccore1);
1775 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc60 is %x\n",
1776 priv->initgain_backup.xcagccore1);
1777 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc68 is %x\n",
1778 priv->initgain_backup.xdagccore1);
1779 RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xa0a is %x\n",
1780 priv->initgain_backup.cca);
1782 rtl8192_phy_setTxPower(dev, priv->ieee80211->current_network.channel);
1784 if (dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
1786 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x1);
1789 RT_TRACE(COMP_SCAN, "Unknown IG Operation.\n");