1 // SPDX-License-Identifier: GPL-2.0
4 #include "r819xU_phy.h"
5 #include "r819xU_phyreg.h"
6 #include "r8190_rtl8256.h"
8 #include "r819xU_firmware_img.h"
11 #include <linux/bitops.h>
13 static u32 RF_CHANNEL_TABLE_ZEBRA
[] = {
32 #define rtl819XPHY_REG_1T2RArray Rtl8192UsbPHY_REG_1T2RArray
33 #define rtl819XMACPHY_Array_PG Rtl8192UsbMACPHY_Array_PG
34 #define rtl819XMACPHY_Array Rtl8192UsbMACPHY_Array
35 #define rtl819XRadioA_Array Rtl8192UsbRadioA_Array
36 #define rtl819XRadioB_Array Rtl8192UsbRadioB_Array
37 #define rtl819XRadioC_Array Rtl8192UsbRadioC_Array
38 #define rtl819XRadioD_Array Rtl8192UsbRadioD_Array
39 #define rtl819XAGCTAB_Array Rtl8192UsbAGCTAB_Array
41 /******************************************************************************
42 * function: This function checks different RF type to execute legal judgement.
43 * If RF Path is illegal, we will return false.
44 * input: net_device *dev
47 * return: 0(illegal, false), 1(legal, true)
48 *****************************************************************************/
49 u8
rtl8192_phy_CheckIsLegalRFPath(struct net_device
*dev
, u32 eRFPath
)
52 struct r8192_priv
*priv
= ieee80211_priv(dev
);
54 if (priv
->rf_type
== RF_2T4R
) {
56 } else if (priv
->rf_type
== RF_1T2R
) {
57 if (eRFPath
== RF90_PATH_A
|| eRFPath
== RF90_PATH_B
)
59 else if (eRFPath
== RF90_PATH_C
|| eRFPath
== RF90_PATH_D
)
65 /******************************************************************************
66 * function: This function sets specific bits to BB register
67 * input: net_device *dev
68 * u32 reg_addr //target addr to be modified
69 * u32 bitmask //taget bit pos to be modified
70 * u32 data //value to be write
74 ******************************************************************************/
75 void rtl8192_setBBreg(struct net_device
*dev
, u32 reg_addr
, u32 bitmask
,
81 if (bitmask
!= bMaskDWord
) {
82 read_nic_dword(dev
, reg_addr
, ®
);
83 bitshift
= ffs(bitmask
) - 1;
85 reg
|= data
<< bitshift
;
86 write_nic_dword(dev
, reg_addr
, reg
);
88 write_nic_dword(dev
, reg_addr
, data
);
92 /******************************************************************************
93 * function: This function reads specific bits from BB register
94 * input: net_device *dev
95 * u32 reg_addr //target addr to be readback
96 * u32 bitmask //taget bit pos to be readback
98 * return: u32 data //the readback register value
100 ******************************************************************************/
101 u32
rtl8192_QueryBBReg(struct net_device
*dev
, u32 reg_addr
, u32 bitmask
)
105 read_nic_dword(dev
, reg_addr
, ®
);
106 bitshift
= ffs(bitmask
) - 1;
108 return (reg
& bitmask
) >> bitshift
;
111 static u32
phy_FwRFSerialRead(struct net_device
*dev
, RF90_RADIO_PATH_E eRFPath
,
114 static void phy_FwRFSerialWrite(struct net_device
*dev
,
115 RF90_RADIO_PATH_E eRFPath
, u32 offset
,
118 /******************************************************************************
119 * function: This function reads register from RF chip
120 * input: net_device *dev
121 * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D
122 * u32 offset //target address to be read
124 * return: u32 readback value
125 * notice: There are three types of serial operations:
126 * (1) Software serial write.
127 * (2)Hardware LSSI-Low Speed Serial Interface.
128 * (3)Hardware HSSI-High speed serial write.
129 * Driver here need to implement (1) and (2)
130 * ---need more spec for this information.
131 ******************************************************************************/
132 static u32
rtl8192_phy_RFSerialRead(struct net_device
*dev
,
133 RF90_RADIO_PATH_E eRFPath
, u32 offset
)
135 struct r8192_priv
*priv
= ieee80211_priv(dev
);
138 BB_REGISTER_DEFINITION_T
*pPhyReg
= &priv
->PHYRegDef
[eRFPath
];
140 rtl8192_setBBreg(dev
, pPhyReg
->rfLSSIReadBack
, bLSSIReadBackData
, 0);
141 /* Make sure RF register offset is correct */
144 /* Switch page for 8256 RF IC */
145 if (priv
->rf_chip
== RF_8256
) {
147 priv
->RfReg0Value
[eRFPath
] |= 0x140;
148 /* Switch to Reg_Mode2 for Reg 31-45 */
149 rtl8192_setBBreg(dev
, pPhyReg
->rf3wireOffset
,
151 priv
->RfReg0Value
[eRFPath
]<<16);
153 new_offset
= offset
- 30;
154 } else if (offset
>= 16) {
155 priv
->RfReg0Value
[eRFPath
] |= 0x100;
156 priv
->RfReg0Value
[eRFPath
] &= (~0x40);
157 /* Switch to Reg_Mode1 for Reg16-30 */
158 rtl8192_setBBreg(dev
, pPhyReg
->rf3wireOffset
,
160 priv
->RfReg0Value
[eRFPath
]<<16);
162 new_offset
= offset
- 15;
167 RT_TRACE((COMP_PHY
|COMP_ERR
),
168 "check RF type here, need to be 8256\n");
171 /* Put desired read addr to LSSI control Register */
172 rtl8192_setBBreg(dev
, pPhyReg
->rfHSSIPara2
, bLSSIReadAddress
,
174 /* Issue a posedge trigger */
175 rtl8192_setBBreg(dev
, pPhyReg
->rfHSSIPara2
, bLSSIReadEdge
, 0x0);
176 rtl8192_setBBreg(dev
, pPhyReg
->rfHSSIPara2
, bLSSIReadEdge
, 0x1);
179 /* TODO: we should not delay such a long time. Ask for help from SD3 */
180 usleep_range(1000, 1000);
182 ret
= rtl8192_QueryBBReg(dev
, pPhyReg
->rfLSSIReadBack
,
186 /* Switch back to Reg_Mode0 */
187 if (priv
->rf_chip
== RF_8256
) {
188 priv
->RfReg0Value
[eRFPath
] &= 0xebf;
190 rtl8192_setBBreg(dev
, pPhyReg
->rf3wireOffset
, bMaskDWord
,
191 priv
->RfReg0Value
[eRFPath
] << 16);
197 /******************************************************************************
198 * function: This function writes data to RF register
199 * input: net_device *dev
200 * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D
201 * u32 offset //target address to be written
202 * u32 data //the new register data to be written
205 * notice: For RF8256 only.
206 * ===========================================================================
207 * Reg Mode RegCTL[1] RegCTL[0] Note
208 * (Reg00[12]) (Reg00[10])
209 * ===========================================================================
210 * Reg_Mode0 0 x Reg 0 ~ 15(0x0 ~ 0xf)
211 * ---------------------------------------------------------------------------
212 * Reg_Mode1 1 0 Reg 16 ~ 30(0x1 ~ 0xf)
213 * ---------------------------------------------------------------------------
214 * Reg_Mode2 1 1 Reg 31 ~ 45(0x1 ~ 0xf)
215 * ---------------------------------------------------------------------------
216 *****************************************************************************/
217 static void rtl8192_phy_RFSerialWrite(struct net_device
*dev
,
218 RF90_RADIO_PATH_E eRFPath
, u32 offset
,
221 struct r8192_priv
*priv
= ieee80211_priv(dev
);
222 u32 DataAndAddr
= 0, new_offset
= 0;
223 BB_REGISTER_DEFINITION_T
*pPhyReg
= &priv
->PHYRegDef
[eRFPath
];
226 if (priv
->rf_chip
== RF_8256
) {
229 priv
->RfReg0Value
[eRFPath
] |= 0x140;
230 rtl8192_setBBreg(dev
, pPhyReg
->rf3wireOffset
,
232 priv
->RfReg0Value
[eRFPath
] << 16);
233 new_offset
= offset
- 30;
234 } else if (offset
>= 16) {
235 priv
->RfReg0Value
[eRFPath
] |= 0x100;
236 priv
->RfReg0Value
[eRFPath
] &= (~0x40);
237 rtl8192_setBBreg(dev
, pPhyReg
->rf3wireOffset
,
239 priv
->RfReg0Value
[eRFPath
]<<16);
240 new_offset
= offset
- 15;
245 RT_TRACE((COMP_PHY
|COMP_ERR
),
246 "check RF type here, need to be 8256\n");
250 /* Put write addr in [5:0] and write data in [31:16] */
251 DataAndAddr
= (data
<<16) | (new_offset
&0x3f);
253 /* Write operation */
254 rtl8192_setBBreg(dev
, pPhyReg
->rf3wireOffset
, bMaskDWord
, DataAndAddr
);
258 priv
->RfReg0Value
[eRFPath
] = data
;
260 /* Switch back to Reg_Mode0 */
261 if (priv
->rf_chip
== RF_8256
) {
263 priv
->RfReg0Value
[eRFPath
] &= 0xebf;
264 rtl8192_setBBreg(dev
, pPhyReg
->rf3wireOffset
,
266 priv
->RfReg0Value
[eRFPath
] << 16);
271 /******************************************************************************
272 * function: This function set specific bits to RF register
273 * input: net_device dev
274 * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D
275 * u32 reg_addr //target addr to be modified
276 * u32 bitmask //taget bit pos to be modified
277 * u32 data //value to be written
281 *****************************************************************************/
282 void rtl8192_phy_SetRFReg(struct net_device
*dev
, RF90_RADIO_PATH_E eRFPath
,
283 u32 reg_addr
, u32 bitmask
, u32 data
)
285 struct r8192_priv
*priv
= ieee80211_priv(dev
);
288 if (!rtl8192_phy_CheckIsLegalRFPath(dev
, eRFPath
))
291 if (priv
->Rf_Mode
== RF_OP_By_FW
) {
292 if (bitmask
!= bMask12Bits
) {
293 /* RF data is 12 bits only */
294 reg
= phy_FwRFSerialRead(dev
, eRFPath
, reg_addr
);
295 bitshift
= ffs(bitmask
) - 1;
297 reg
|= data
<< bitshift
;
299 phy_FwRFSerialWrite(dev
, eRFPath
, reg_addr
, reg
);
301 phy_FwRFSerialWrite(dev
, eRFPath
, reg_addr
, data
);
307 if (bitmask
!= bMask12Bits
) {
308 /* RF data is 12 bits only */
309 reg
= rtl8192_phy_RFSerialRead(dev
, eRFPath
, reg_addr
);
310 bitshift
= ffs(bitmask
) - 1;
312 reg
|= data
<< bitshift
;
314 rtl8192_phy_RFSerialWrite(dev
, eRFPath
, reg_addr
, reg
);
316 rtl8192_phy_RFSerialWrite(dev
, eRFPath
, reg_addr
, data
);
321 /******************************************************************************
322 * function: This function reads specific bits from RF register
323 * input: net_device *dev
324 * u32 reg_addr //target addr to be readback
325 * u32 bitmask //taget bit pos to be readback
327 * return: u32 data //the readback register value
329 *****************************************************************************/
330 u32
rtl8192_phy_QueryRFReg(struct net_device
*dev
, RF90_RADIO_PATH_E eRFPath
,
331 u32 reg_addr
, u32 bitmask
)
334 struct r8192_priv
*priv
= ieee80211_priv(dev
);
337 if (!rtl8192_phy_CheckIsLegalRFPath(dev
, eRFPath
))
339 if (priv
->Rf_Mode
== RF_OP_By_FW
) {
340 reg
= phy_FwRFSerialRead(dev
, eRFPath
, reg_addr
);
343 reg
= rtl8192_phy_RFSerialRead(dev
, eRFPath
, reg_addr
);
345 bitshift
= ffs(bitmask
) - 1;
346 reg
= (reg
& bitmask
) >> bitshift
;
351 /******************************************************************************
352 * function: We support firmware to execute RF-R/W.
353 * input: net_device *dev
354 * RF90_RADIO_PATH_E eRFPath
359 ****************************************************************************/
360 static u32
phy_FwRFSerialRead(struct net_device
*dev
, RF90_RADIO_PATH_E eRFPath
,
368 /* Firmware RF Write control.
369 * We can not execute the scheme in the initial step.
370 * Otherwise, RF-R/W will waste much time.
371 * This is only for site survey.
373 /* 1. Read operation need not insert data. bit 0-11 */
374 /* 2. Write RF register address. bit 12-19 */
375 data
|= ((offset
&0xFF)<<12);
376 /* 3. Write RF path. bit 20-21 */
377 data
|= ((eRFPath
&0x3)<<20);
378 /* 4. Set RF read indicator. bit 22=0 */
379 /* 5. Trigger Fw to operate the command. bit 31 */
381 /* 6. We can not execute read operation if bit 31 is 1. */
382 read_nic_dword(dev
, QPNR
, &tmp
);
383 while (tmp
& 0x80000000) {
384 /* If FW can not finish RF-R/W for more than ?? times.
389 read_nic_dword(dev
, QPNR
, &tmp
);
394 /* 7. Execute read operation. */
395 write_nic_dword(dev
, QPNR
, data
);
396 /* 8. Check if firmware send back RF content. */
397 read_nic_dword(dev
, QPNR
, &tmp
);
398 while (tmp
& 0x80000000) {
399 /* If FW can not finish RF-R/W for more than ?? times.
404 read_nic_dword(dev
, QPNR
, &tmp
);
409 read_nic_dword(dev
, RF_DATA
, ®
);
414 /******************************************************************************
415 * function: We support firmware to execute RF-R/W.
416 * input: net_device *dev
417 * RF90_RADIO_PATH_E eRFPath
423 ****************************************************************************/
424 static void phy_FwRFSerialWrite(struct net_device
*dev
,
425 RF90_RADIO_PATH_E eRFPath
, u32 offset
, u32 data
)
430 /* Firmware RF Write control.
431 * We can not execute the scheme in the initial step.
432 * Otherwise, RF-R/W will waste much time.
433 * This is only for site survey.
436 /* 1. Set driver write bit and 12 bit data. bit 0-11 */
437 /* 2. Write RF register address. bit 12-19 */
438 data
|= ((offset
&0xFF)<<12);
439 /* 3. Write RF path. bit 20-21 */
440 data
|= ((eRFPath
&0x3)<<20);
441 /* 4. Set RF write indicator. bit 22=1 */
443 /* 5. Trigger Fw to operate the command. bit 31=1 */
446 /* 6. Write operation. We can not write if bit 31 is 1. */
447 read_nic_dword(dev
, QPNR
, &tmp
);
448 while (tmp
& 0x80000000) {
449 /* If FW can not finish RF-R/W for more than ?? times.
454 read_nic_dword(dev
, QPNR
, &tmp
);
459 /* 7. No matter check bit. We always force the write.
460 * Because FW will not accept the command.
462 write_nic_dword(dev
, QPNR
, data
);
463 /* According to test, we must delay 20us to wait firmware
464 * to finish RF write operation.
466 /* We support delay in firmware side now. */
469 /******************************************************************************
470 * function: This function reads BB parameters from header file we generate,
471 * and do register read/write
472 * input: net_device *dev
475 * notice: BB parameters may change all the time, so please make
476 * sure it has been synced with the newest.
477 *****************************************************************************/
478 void rtl8192_phy_configmac(struct net_device
*dev
)
480 u32 dwArrayLen
= 0, i
;
481 u32
*pdwArray
= NULL
;
482 struct r8192_priv
*priv
= ieee80211_priv(dev
);
484 if (priv
->btxpowerdata_readfromEEPORM
) {
485 RT_TRACE(COMP_PHY
, "Rtl819XMACPHY_Array_PG\n");
486 dwArrayLen
= MACPHY_Array_PGLength
;
487 pdwArray
= rtl819XMACPHY_Array_PG
;
490 RT_TRACE(COMP_PHY
, "Rtl819XMACPHY_Array\n");
491 dwArrayLen
= MACPHY_ArrayLength
;
492 pdwArray
= rtl819XMACPHY_Array
;
494 for (i
= 0; i
< dwArrayLen
; i
= i
+3) {
495 if (pdwArray
[i
] == 0x318)
496 pdwArray
[i
+2] = 0x00000800;
499 "Rtl8190MACPHY_Array[0]=%x Rtl8190MACPHY_Array[1]=%x Rtl8190MACPHY_Array[2]=%x\n",
500 pdwArray
[i
], pdwArray
[i
+1], pdwArray
[i
+2]);
501 rtl8192_setBBreg(dev
, pdwArray
[i
], pdwArray
[i
+1],
506 /******************************************************************************
507 * function: This function does dirty work
508 * input: net_device *dev
512 * notice: BB parameters may change all the time, so please make
513 * sure it has been synced with the newest.
514 *****************************************************************************/
515 void rtl8192_phyConfigBB(struct net_device
*dev
, u8 ConfigType
)
520 u32
*rtl8192PhyRegArrayTable
= NULL
, *rtl8192AgcTabArrayTable
= NULL
;
522 if (Adapter
->bInHctTest
) {
523 PHY_REGArrayLen
= PHY_REGArrayLengthDTM
;
524 AGCTAB_ArrayLen
= AGCTAB_ArrayLengthDTM
;
525 Rtl8190PHY_REGArray_Table
= Rtl819XPHY_REGArrayDTM
;
526 Rtl8190AGCTAB_Array_Table
= Rtl819XAGCTAB_ArrayDTM
;
529 if (ConfigType
== BaseBand_Config_PHY_REG
) {
530 for (i
= 0; i
< PHY_REG_1T2RArrayLength
; i
+= 2) {
531 rtl8192_setBBreg(dev
, rtl819XPHY_REG_1T2RArray
[i
],
533 rtl819XPHY_REG_1T2RArray
[i
+1]);
535 "i: %x, Rtl819xUsbPHY_REGArray[0]=%x Rtl819xUsbPHY_REGArray[1]=%x\n",
536 i
, rtl819XPHY_REG_1T2RArray
[i
],
537 rtl819XPHY_REG_1T2RArray
[i
+1]);
539 } else if (ConfigType
== BaseBand_Config_AGC_TAB
) {
540 for (i
= 0; i
< AGCTAB_ArrayLength
; i
+= 2) {
541 rtl8192_setBBreg(dev
, rtl819XAGCTAB_Array
[i
],
542 bMaskDWord
, rtl819XAGCTAB_Array
[i
+1]);
544 "i: %x, rtl819XAGCTAB_Array[0]=%x rtl819XAGCTAB_Array[1]=%x\n",
545 i
, rtl819XAGCTAB_Array
[i
],
546 rtl819XAGCTAB_Array
[i
+1]);
551 /******************************************************************************
552 * function: This function initializes Register definition offset for
554 * input: net_device *dev
557 * notice: Initialization value here is constant and it should never
559 *****************************************************************************/
560 static void rtl8192_InitBBRFRegDef(struct net_device
*dev
)
562 struct r8192_priv
*priv
= ieee80211_priv(dev
);
564 /* RF Interface Software Control */
565 /* 16 LSBs if read 32-bit from 0x870 */
566 priv
->PHYRegDef
[RF90_PATH_A
].rfintfs
= rFPGA0_XAB_RFInterfaceSW
;
567 /* 16 MSBs if read 32-bit from 0x870 (16-bit for 0x872) */
568 priv
->PHYRegDef
[RF90_PATH_B
].rfintfs
= rFPGA0_XAB_RFInterfaceSW
;
569 /* 16 LSBs if read 32-bit from 0x874 */
570 priv
->PHYRegDef
[RF90_PATH_C
].rfintfs
= rFPGA0_XCD_RFInterfaceSW
;
571 /* 16 MSBs if read 32-bit from 0x874 (16-bit for 0x876) */
572 priv
->PHYRegDef
[RF90_PATH_D
].rfintfs
= rFPGA0_XCD_RFInterfaceSW
;
574 /* RF Interface Readback Value */
575 /* 16 LSBs if read 32-bit from 0x8E0 */
576 priv
->PHYRegDef
[RF90_PATH_A
].rfintfi
= rFPGA0_XAB_RFInterfaceRB
;
577 /* 16 MSBs if read 32-bit from 0x8E0 (16-bit for 0x8E2) */
578 priv
->PHYRegDef
[RF90_PATH_B
].rfintfi
= rFPGA0_XAB_RFInterfaceRB
;
579 /* 16 LSBs if read 32-bit from 0x8E4 */
580 priv
->PHYRegDef
[RF90_PATH_C
].rfintfi
= rFPGA0_XCD_RFInterfaceRB
;
581 /* 16 MSBs if read 32-bit from 0x8E4 (16-bit for 0x8E6) */
582 priv
->PHYRegDef
[RF90_PATH_D
].rfintfi
= rFPGA0_XCD_RFInterfaceRB
;
584 /* RF Interface Output (and Enable) */
585 /* 16 LSBs if read 32-bit from 0x860 */
586 priv
->PHYRegDef
[RF90_PATH_A
].rfintfo
= rFPGA0_XA_RFInterfaceOE
;
587 /* 16 LSBs if read 32-bit from 0x864 */
588 priv
->PHYRegDef
[RF90_PATH_B
].rfintfo
= rFPGA0_XB_RFInterfaceOE
;
589 /* 16 LSBs if read 32-bit from 0x868 */
590 priv
->PHYRegDef
[RF90_PATH_C
].rfintfo
= rFPGA0_XC_RFInterfaceOE
;
591 /* 16 LSBs if read 32-bit from 0x86C */
592 priv
->PHYRegDef
[RF90_PATH_D
].rfintfo
= rFPGA0_XD_RFInterfaceOE
;
594 /* RF Interface (Output and) Enable */
595 /* 16 MSBs if read 32-bit from 0x860 (16-bit for 0x862) */
596 priv
->PHYRegDef
[RF90_PATH_A
].rfintfe
= rFPGA0_XA_RFInterfaceOE
;
597 /* 16 MSBs if read 32-bit from 0x864 (16-bit for 0x866) */
598 priv
->PHYRegDef
[RF90_PATH_B
].rfintfe
= rFPGA0_XB_RFInterfaceOE
;
599 /* 16 MSBs if read 32-bit from 0x86A (16-bit for 0x86A) */
600 priv
->PHYRegDef
[RF90_PATH_C
].rfintfe
= rFPGA0_XC_RFInterfaceOE
;
601 /* 16 MSBs if read 32-bit from 0x86C (16-bit for 0x86E) */
602 priv
->PHYRegDef
[RF90_PATH_D
].rfintfe
= rFPGA0_XD_RFInterfaceOE
;
604 /* Addr of LSSI. Write RF register by driver */
605 priv
->PHYRegDef
[RF90_PATH_A
].rf3wireOffset
= rFPGA0_XA_LSSIParameter
;
606 priv
->PHYRegDef
[RF90_PATH_B
].rf3wireOffset
= rFPGA0_XB_LSSIParameter
;
607 priv
->PHYRegDef
[RF90_PATH_C
].rf3wireOffset
= rFPGA0_XC_LSSIParameter
;
608 priv
->PHYRegDef
[RF90_PATH_D
].rf3wireOffset
= rFPGA0_XD_LSSIParameter
;
612 priv
->PHYRegDef
[RF90_PATH_A
].rfLSSI_Select
= rFPGA0_XAB_RFParameter
;
613 priv
->PHYRegDef
[RF90_PATH_B
].rfLSSI_Select
= rFPGA0_XAB_RFParameter
;
614 priv
->PHYRegDef
[RF90_PATH_C
].rfLSSI_Select
= rFPGA0_XCD_RFParameter
;
615 priv
->PHYRegDef
[RF90_PATH_D
].rfLSSI_Select
= rFPGA0_XCD_RFParameter
;
617 /* Tx AGC Gain Stage (same for all path. Should we remove this?) */
618 priv
->PHYRegDef
[RF90_PATH_A
].rfTxGainStage
= rFPGA0_TxGainStage
;
619 priv
->PHYRegDef
[RF90_PATH_B
].rfTxGainStage
= rFPGA0_TxGainStage
;
620 priv
->PHYRegDef
[RF90_PATH_C
].rfTxGainStage
= rFPGA0_TxGainStage
;
621 priv
->PHYRegDef
[RF90_PATH_D
].rfTxGainStage
= rFPGA0_TxGainStage
;
623 /* Tranceiver A~D HSSI Parameter-1 */
624 /* wire control parameter1 */
625 priv
->PHYRegDef
[RF90_PATH_A
].rfHSSIPara1
= rFPGA0_XA_HSSIParameter1
;
626 priv
->PHYRegDef
[RF90_PATH_B
].rfHSSIPara1
= rFPGA0_XB_HSSIParameter1
;
627 priv
->PHYRegDef
[RF90_PATH_C
].rfHSSIPara1
= rFPGA0_XC_HSSIParameter1
;
628 priv
->PHYRegDef
[RF90_PATH_D
].rfHSSIPara1
= rFPGA0_XD_HSSIParameter1
;
630 /* Tranceiver A~D HSSI Parameter-2 */
631 /* wire control parameter2 */
632 priv
->PHYRegDef
[RF90_PATH_A
].rfHSSIPara2
= rFPGA0_XA_HSSIParameter2
;
633 priv
->PHYRegDef
[RF90_PATH_B
].rfHSSIPara2
= rFPGA0_XB_HSSIParameter2
;
634 priv
->PHYRegDef
[RF90_PATH_C
].rfHSSIPara2
= rFPGA0_XC_HSSIParameter2
;
635 priv
->PHYRegDef
[RF90_PATH_D
].rfHSSIPara2
= rFPGA0_XD_HSSIParameter2
;
637 /* RF Switch Control */
638 /* TR/Ant switch control */
639 priv
->PHYRegDef
[RF90_PATH_A
].rfSwitchControl
= rFPGA0_XAB_SwitchControl
;
640 priv
->PHYRegDef
[RF90_PATH_B
].rfSwitchControl
= rFPGA0_XAB_SwitchControl
;
641 priv
->PHYRegDef
[RF90_PATH_C
].rfSwitchControl
= rFPGA0_XCD_SwitchControl
;
642 priv
->PHYRegDef
[RF90_PATH_D
].rfSwitchControl
= rFPGA0_XCD_SwitchControl
;
645 priv
->PHYRegDef
[RF90_PATH_A
].rfAGCControl1
= rOFDM0_XAAGCCore1
;
646 priv
->PHYRegDef
[RF90_PATH_B
].rfAGCControl1
= rOFDM0_XBAGCCore1
;
647 priv
->PHYRegDef
[RF90_PATH_C
].rfAGCControl1
= rOFDM0_XCAGCCore1
;
648 priv
->PHYRegDef
[RF90_PATH_D
].rfAGCControl1
= rOFDM0_XDAGCCore1
;
651 priv
->PHYRegDef
[RF90_PATH_A
].rfAGCControl2
= rOFDM0_XAAGCCore2
;
652 priv
->PHYRegDef
[RF90_PATH_B
].rfAGCControl2
= rOFDM0_XBAGCCore2
;
653 priv
->PHYRegDef
[RF90_PATH_C
].rfAGCControl2
= rOFDM0_XCAGCCore2
;
654 priv
->PHYRegDef
[RF90_PATH_D
].rfAGCControl2
= rOFDM0_XDAGCCore2
;
656 /* RX AFE control 1 */
657 priv
->PHYRegDef
[RF90_PATH_A
].rfRxIQImbalance
= rOFDM0_XARxIQImbalance
;
658 priv
->PHYRegDef
[RF90_PATH_B
].rfRxIQImbalance
= rOFDM0_XBRxIQImbalance
;
659 priv
->PHYRegDef
[RF90_PATH_C
].rfRxIQImbalance
= rOFDM0_XCRxIQImbalance
;
660 priv
->PHYRegDef
[RF90_PATH_D
].rfRxIQImbalance
= rOFDM0_XDRxIQImbalance
;
662 /* RX AFE control 1 */
663 priv
->PHYRegDef
[RF90_PATH_A
].rfRxAFE
= rOFDM0_XARxAFE
;
664 priv
->PHYRegDef
[RF90_PATH_B
].rfRxAFE
= rOFDM0_XBRxAFE
;
665 priv
->PHYRegDef
[RF90_PATH_C
].rfRxAFE
= rOFDM0_XCRxAFE
;
666 priv
->PHYRegDef
[RF90_PATH_D
].rfRxAFE
= rOFDM0_XDRxAFE
;
668 /* Tx AFE control 1 */
669 priv
->PHYRegDef
[RF90_PATH_A
].rfTxIQImbalance
= rOFDM0_XATxIQImbalance
;
670 priv
->PHYRegDef
[RF90_PATH_B
].rfTxIQImbalance
= rOFDM0_XBTxIQImbalance
;
671 priv
->PHYRegDef
[RF90_PATH_C
].rfTxIQImbalance
= rOFDM0_XCTxIQImbalance
;
672 priv
->PHYRegDef
[RF90_PATH_D
].rfTxIQImbalance
= rOFDM0_XDTxIQImbalance
;
674 /* Tx AFE control 2 */
675 priv
->PHYRegDef
[RF90_PATH_A
].rfTxAFE
= rOFDM0_XATxAFE
;
676 priv
->PHYRegDef
[RF90_PATH_B
].rfTxAFE
= rOFDM0_XBTxAFE
;
677 priv
->PHYRegDef
[RF90_PATH_C
].rfTxAFE
= rOFDM0_XCTxAFE
;
678 priv
->PHYRegDef
[RF90_PATH_D
].rfTxAFE
= rOFDM0_XDTxAFE
;
680 /* Tranceiver LSSI Readback */
681 priv
->PHYRegDef
[RF90_PATH_A
].rfLSSIReadBack
= rFPGA0_XA_LSSIReadBack
;
682 priv
->PHYRegDef
[RF90_PATH_B
].rfLSSIReadBack
= rFPGA0_XB_LSSIReadBack
;
683 priv
->PHYRegDef
[RF90_PATH_C
].rfLSSIReadBack
= rFPGA0_XC_LSSIReadBack
;
684 priv
->PHYRegDef
[RF90_PATH_D
].rfLSSIReadBack
= rFPGA0_XD_LSSIReadBack
;
687 /******************************************************************************
688 * function: This function is to write register and then readback to make
689 * sure whether BB and RF is OK
690 * input: net_device *dev
691 * HW90_BLOCK_E CheckBlock
692 * RF90_RADIO_PATH_E eRFPath //only used when checkblock is
695 * return: return whether BB and RF is ok (0:OK, 1:Fail)
696 * notice: This function may be removed in the ASIC
697 ******************************************************************************/
698 u8
rtl8192_phy_checkBBAndRF(struct net_device
*dev
, HW90_BLOCK_E CheckBlock
,
699 RF90_RADIO_PATH_E eRFPath
)
702 u32 i
, CheckTimes
= 4, reg
= 0;
704 u32 WriteData
[] = {0xfffff027, 0xaa55a02f, 0x00000027, 0x55aa502f};
706 /* Initialize register address offset to be checked */
707 WriteAddr
[HW90_BLOCK_MAC
] = 0x100;
708 WriteAddr
[HW90_BLOCK_PHY0
] = 0x900;
709 WriteAddr
[HW90_BLOCK_PHY1
] = 0x800;
710 WriteAddr
[HW90_BLOCK_RF
] = 0x3;
711 RT_TRACE(COMP_PHY
, "%s(), CheckBlock: %d\n", __func__
, CheckBlock
);
712 for (i
= 0; i
< CheckTimes
; i
++) {
714 /* Write data to register and readback */
715 switch (CheckBlock
) {
718 "PHY_CheckBBRFOK(): Never Write 0x100 here!\n");
721 case HW90_BLOCK_PHY0
:
722 case HW90_BLOCK_PHY1
:
723 write_nic_dword(dev
, WriteAddr
[CheckBlock
],
725 read_nic_dword(dev
, WriteAddr
[CheckBlock
], ®
);
729 WriteData
[i
] &= 0xfff;
730 rtl8192_phy_SetRFReg(dev
, eRFPath
,
731 WriteAddr
[HW90_BLOCK_RF
],
732 bMask12Bits
, WriteData
[i
]);
733 /* TODO: we should not delay for such a long time.
736 usleep_range(1000, 1000);
737 reg
= rtl8192_phy_QueryRFReg(dev
, eRFPath
,
738 WriteAddr
[HW90_BLOCK_RF
],
740 usleep_range(1000, 1000);
749 /* Check whether readback data is correct */
750 if (reg
!= WriteData
[i
]) {
751 RT_TRACE((COMP_PHY
|COMP_ERR
),
752 "error reg: %x, WriteData: %x\n",
762 /******************************************************************************
763 * function: This function initializes BB&RF
764 * input: net_device *dev
767 * notice: Initialization value may change all the time, so please make
768 * sure it has been synced with the newest.
769 ******************************************************************************/
770 static void rtl8192_BB_Config_ParaFile(struct net_device
*dev
)
772 struct r8192_priv
*priv
= ieee80211_priv(dev
);
773 u8 reg_u8
= 0, eCheckItem
= 0, status
= 0;
776 /**************************************
777 * <1> Initialize BaseBand
778 *************************************/
780 /* --set BB Global Reset-- */
781 read_nic_byte(dev
, BB_GLOBAL_RESET
, ®_u8
);
782 write_nic_byte(dev
, BB_GLOBAL_RESET
, (reg_u8
|BB_GLOBAL_RESET_BIT
));
784 /* ---set BB reset Active--- */
785 read_nic_dword(dev
, CPU_GEN
, ®_u32
);
786 write_nic_dword(dev
, CPU_GEN
, (reg_u32
&(~CPU_GEN_BB_RST
)));
788 /* ----Ckeck FPGAPHY0 and PHY1 board is OK---- */
789 /* TODO: this function should be removed on ASIC */
790 for (eCheckItem
= (HW90_BLOCK_E
)HW90_BLOCK_PHY0
;
791 eCheckItem
<= HW90_BLOCK_PHY1
; eCheckItem
++) {
792 /* don't care RF path */
793 status
= rtl8192_phy_checkBBAndRF(dev
, (HW90_BLOCK_E
)eCheckItem
,
794 (RF90_RADIO_PATH_E
)0);
796 RT_TRACE((COMP_ERR
| COMP_PHY
),
797 "PHY_RF8256_Config(): Check PHY%d Fail!!\n",
802 /* ---- Set CCK and OFDM Block "OFF"---- */
803 rtl8192_setBBreg(dev
, rFPGA0_RFMOD
, bCCKEn
|bOFDMEn
, 0x0);
804 /* ----BB Register Initilazation---- */
805 /* ==m==>Set PHY REG From Header<==m== */
806 rtl8192_phyConfigBB(dev
, BaseBand_Config_PHY_REG
);
808 /* ----Set BB reset de-Active---- */
809 read_nic_dword(dev
, CPU_GEN
, ®_u32
);
810 write_nic_dword(dev
, CPU_GEN
, (reg_u32
|CPU_GEN_BB_RST
));
812 /* ----BB AGC table Initialization---- */
813 /* ==m==>Set PHY REG From Header<==m== */
814 rtl8192_phyConfigBB(dev
, BaseBand_Config_AGC_TAB
);
816 /* ----Enable XSTAL ---- */
817 write_nic_byte_E(dev
, 0x5e, 0x00);
818 if (priv
->card_8192_version
== (u8
)VERSION_819xU_A
) {
819 /* Antenna gain offset from B/C/D to A */
820 reg_u32
= priv
->AntennaTxPwDiff
[1]<<4 |
821 priv
->AntennaTxPwDiff
[0];
822 rtl8192_setBBreg(dev
, rFPGA0_TxGainStage
, (bXBTxAGC
|bXCTxAGC
),
826 reg_u32
= priv
->CrystalCap
& 0xf;
827 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter1
, bXtalCap
,
831 /* Check if the CCK HighPower is turned ON.
832 * This is used to calculate PWDB.
834 priv
->bCckHighPower
= (u8
)rtl8192_QueryBBReg(dev
,
835 rFPGA0_XA_HSSIParameter2
,
839 /******************************************************************************
840 * function: This function initializes BB&RF
841 * input: net_device *dev
844 * notice: Initialization value may change all the time, so please make
845 * sure it has been synced with the newest.
846 *****************************************************************************/
847 void rtl8192_BBConfig(struct net_device
*dev
)
849 rtl8192_InitBBRFRegDef(dev
);
850 /* config BB&RF. As hardCode based initialization has not been well
851 * implemented, so use file first.
852 * FIXME: should implement it for hardcode?
854 rtl8192_BB_Config_ParaFile(dev
);
858 /******************************************************************************
859 * function: This function obtains the initialization value of Tx power Level
861 * input: net_device *dev
864 *****************************************************************************/
865 void rtl8192_phy_getTxPower(struct net_device
*dev
)
867 struct r8192_priv
*priv
= ieee80211_priv(dev
);
870 read_nic_dword(dev
, rTxAGC_Rate18_06
,
871 &priv
->MCSTxPowerLevelOriginalOffset
[0]);
872 read_nic_dword(dev
, rTxAGC_Rate54_24
,
873 &priv
->MCSTxPowerLevelOriginalOffset
[1]);
874 read_nic_dword(dev
, rTxAGC_Mcs03_Mcs00
,
875 &priv
->MCSTxPowerLevelOriginalOffset
[2]);
876 read_nic_dword(dev
, rTxAGC_Mcs07_Mcs04
,
877 &priv
->MCSTxPowerLevelOriginalOffset
[3]);
878 read_nic_dword(dev
, rTxAGC_Mcs11_Mcs08
,
879 &priv
->MCSTxPowerLevelOriginalOffset
[4]);
880 read_nic_dword(dev
, rTxAGC_Mcs15_Mcs12
,
881 &priv
->MCSTxPowerLevelOriginalOffset
[5]);
883 /* Read rx initial gain */
884 read_nic_byte(dev
, rOFDM0_XAAGCCore1
, &priv
->DefaultInitialGain
[0]);
885 read_nic_byte(dev
, rOFDM0_XBAGCCore1
, &priv
->DefaultInitialGain
[1]);
886 read_nic_byte(dev
, rOFDM0_XCAGCCore1
, &priv
->DefaultInitialGain
[2]);
887 read_nic_byte(dev
, rOFDM0_XDAGCCore1
, &priv
->DefaultInitialGain
[3]);
889 "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x)\n",
890 priv
->DefaultInitialGain
[0], priv
->DefaultInitialGain
[1],
891 priv
->DefaultInitialGain
[2], priv
->DefaultInitialGain
[3]);
894 read_nic_byte(dev
, rOFDM0_RxDetector3
, &priv
->framesync
);
895 read_nic_byte(dev
, rOFDM0_RxDetector2
, &tmp
);
896 priv
->framesyncC34
= tmp
;
897 RT_TRACE(COMP_INIT
, "Default framesync (0x%x) = 0x%x\n",
898 rOFDM0_RxDetector3
, priv
->framesync
);
900 /* Read SIFS (save the value read fome MACPHY_REG.txt) */
901 read_nic_word(dev
, SIFS
, &priv
->SifsTime
);
904 /******************************************************************************
905 * function: This function sets the initialization value of Tx power Level
907 * input: net_device *dev
911 ******************************************************************************/
912 void rtl8192_phy_setTxPower(struct net_device
*dev
, u8 channel
)
914 struct r8192_priv
*priv
= ieee80211_priv(dev
);
915 u8 powerlevel
= priv
->TxPowerLevelCCK
[channel
-1];
916 u8 powerlevelOFDM24G
= priv
->TxPowerLevelOFDM24G
[channel
-1];
918 switch (priv
->rf_chip
) {
920 /* need further implement */
921 PHY_SetRF8256CCKTxPower(dev
, powerlevel
);
922 PHY_SetRF8256OFDMTxPower(dev
, powerlevelOFDM24G
);
925 RT_TRACE((COMP_PHY
|COMP_ERR
),
926 "error RF chipID(8225 or 8258) in function %s()\n",
932 /******************************************************************************
933 * function: This function checks Rf chip to do RF config
934 * input: net_device *dev
936 * return: only 8256 is supported
937 ******************************************************************************/
938 void rtl8192_phy_RFConfig(struct net_device
*dev
)
940 struct r8192_priv
*priv
= ieee80211_priv(dev
);
942 switch (priv
->rf_chip
) {
944 PHY_RF8256_Config(dev
);
947 RT_TRACE(COMP_ERR
, "error chip id\n");
952 /******************************************************************************
953 * function: This function updates Initial gain
954 * input: net_device *dev
956 * return: As Windows has not implemented this, wait for complement
957 ******************************************************************************/
958 void rtl8192_phy_updateInitGain(struct net_device
*dev
)
962 /******************************************************************************
963 * function: This function read RF parameters from general head file,
965 * input: net_device *dev
966 * RF90_RADIO_PATH_E eRFPath
968 * return: return code show if RF configuration is successful(0:pass, 1:fail)
969 * notice: Delay may be required for RF configuration
970 *****************************************************************************/
971 u8
rtl8192_phy_ConfigRFWithHeaderFile(struct net_device
*dev
,
972 RF90_RADIO_PATH_E eRFPath
)
979 for (i
= 0; i
< RadioA_ArrayLength
; i
= i
+2) {
981 if (rtl819XRadioA_Array
[i
] == 0xfe) {
985 rtl8192_phy_SetRFReg(dev
, eRFPath
,
986 rtl819XRadioA_Array
[i
],
988 rtl819XRadioA_Array
[i
+1]);
994 for (i
= 0; i
< RadioB_ArrayLength
; i
= i
+2) {
996 if (rtl819XRadioB_Array
[i
] == 0xfe) {
1000 rtl8192_phy_SetRFReg(dev
, eRFPath
,
1001 rtl819XRadioB_Array
[i
],
1003 rtl819XRadioB_Array
[i
+1]);
1009 for (i
= 0; i
< RadioC_ArrayLength
; i
= i
+2) {
1011 if (rtl819XRadioC_Array
[i
] == 0xfe) {
1015 rtl8192_phy_SetRFReg(dev
, eRFPath
,
1016 rtl819XRadioC_Array
[i
],
1018 rtl819XRadioC_Array
[i
+1]);
1024 for (i
= 0; i
< RadioD_ArrayLength
; i
= i
+2) {
1026 if (rtl819XRadioD_Array
[i
] == 0xfe) {
1030 rtl8192_phy_SetRFReg(dev
, eRFPath
,
1031 rtl819XRadioD_Array
[i
],
1033 rtl819XRadioD_Array
[i
+1]);
1046 /******************************************************************************
1047 * function: This function sets Tx Power of the channel
1048 * input: net_device *dev
1053 ******************************************************************************/
1054 static void rtl8192_SetTxPowerLevel(struct net_device
*dev
, u8 channel
)
1056 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1057 u8 powerlevel
= priv
->TxPowerLevelCCK
[channel
-1];
1058 u8 powerlevelOFDM24G
= priv
->TxPowerLevelOFDM24G
[channel
-1];
1060 switch (priv
->rf_chip
) {
1063 PHY_SetRF8225CckTxPower(Adapter
, powerlevel
);
1064 PHY_SetRF8225OfdmTxPower(Adapter
, powerlevelOFDM24G
);
1069 PHY_SetRF8256CCKTxPower(dev
, powerlevel
);
1070 PHY_SetRF8256OFDMTxPower(dev
, powerlevelOFDM24G
);
1076 RT_TRACE(COMP_ERR
, "unknown rf chip ID in %s()\n", __func__
);
1081 /******************************************************************************
1082 * function: This function sets RF state on or off
1083 * input: net_device *dev
1084 * RT_RF_POWER_STATE eRFPowerState //Power State to set
1088 *****************************************************************************/
1089 bool rtl8192_SetRFPowerState(struct net_device
*dev
,
1090 RT_RF_POWER_STATE eRFPowerState
)
1092 bool bResult
= true;
1093 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1095 if (eRFPowerState
== priv
->ieee80211
->eRFPowerState
)
1098 if (priv
->SetRFPowerStateInProgress
)
1101 priv
->SetRFPowerStateInProgress
= true;
1103 switch (priv
->rf_chip
) {
1105 switch (eRFPowerState
) {
1108 /* enable RF-Chip A/B - 0x860[4] */
1109 rtl8192_setBBreg(dev
, rFPGA0_XA_RFInterfaceOE
, BIT(4),
1111 /* analog to digital on - 0x88c[9:8] */
1112 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter4
, 0x300,
1114 /* digital to analog on - 0x880[4:3] */
1115 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter1
, 0x18,
1117 /* rx antenna on - 0xc04[1:0] */
1118 rtl8192_setBBreg(dev
, rOFDM0_TRxPathEnable
, 0x3, 0x3);
1119 /* rx antenna on - 0xd04[1:0] */
1120 rtl8192_setBBreg(dev
, rOFDM1_TRxPathEnable
, 0x3, 0x3);
1121 /* analog to digital part2 on - 0x880[6:5] */
1122 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter1
, 0x60,
1133 /* disable RF-Chip A/B - 0x860[4] */
1134 rtl8192_setBBreg(dev
, rFPGA0_XA_RFInterfaceOE
, BIT(4),
1136 /* analog to digital off, for power save */
1137 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter4
, 0xf00,
1138 0x0); /* 0x88c[11:8] */
1139 /* digital to analog off, for power save - 0x880[4:3] */
1140 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter1
, 0x18,
1142 /* rx antenna off - 0xc04[3:0] */
1143 rtl8192_setBBreg(dev
, rOFDM0_TRxPathEnable
, 0xf, 0x0);
1144 /* rx antenna off - 0xd04[3:0] */
1145 rtl8192_setBBreg(dev
, rOFDM1_TRxPathEnable
, 0xf, 0x0);
1146 /* analog to digital part2 off, for power save */
1147 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter1
, 0x60,
1148 0x0); /* 0x880[6:5] */
1154 RT_TRACE(COMP_ERR
, "%s(): unknown state to set: 0x%X\n",
1155 __func__
, eRFPowerState
);
1160 RT_TRACE(COMP_ERR
, "Not support rf_chip(%x)\n", priv
->rf_chip
);
1165 /* Update current RF state variable. */
1166 pHalData
->eRFPowerState
= eRFPowerState
;
1167 switch (pHalData
->RFChipID
) {
1169 switch (pHalData
->eRFPowerState
) {
1171 /* If Rf off reason is from IPS,
1172 * LED should blink with no link
1174 if (pMgntInfo
->RfOffReason
== RF_CHANGE_BY_IPS
)
1175 Adapter
->HalFunc
.LedControlHandler(Adapter
, LED_CTL_NO_LINK
);
1177 /* Turn off LED if RF is not ON. */
1178 Adapter
->HalFunc
.LedControlHandler(Adapter
, LED_CTL_POWER_OFF
);
1182 /* Turn on RF we are still linked, which might
1183 * happen when we quickly turn off and on HW RF.
1185 if (pMgntInfo
->bMediaConnect
)
1186 Adapter
->HalFunc
.LedControlHandler(Adapter
, LED_CTL_LINK
);
1188 /* Turn off LED if RF is not ON. */
1189 Adapter
->HalFunc
.LedControlHandler(Adapter
, LED_CTL_NO_LINK
);
1198 RT_TRACE(COMP_RF
, DBG_LOUD
, "%s(): Unknown RF type\n",
1205 priv
->SetRFPowerStateInProgress
= false;
1210 /******************************************************************************
1211 * function: This function sets command table variable (struct SwChnlCmd).
1212 * input: SwChnlCmd *CmdTable //table to be set
1213 * u32 CmdTableIdx //variable index in table to be set
1214 * u32 CmdTableSz //table size
1215 * SwChnlCmdID CmdID //command ID to set
1220 * return: true if finished, false otherwise
1222 ******************************************************************************/
1223 static u8
rtl8192_phy_SetSwChnlCmdArray(SwChnlCmd
*CmdTable
, u32 CmdTableIdx
,
1224 u32 CmdTableSz
, SwChnlCmdID CmdID
,
1225 u32 Para1
, u32 Para2
, u32 msDelay
)
1229 if (CmdTable
== NULL
) {
1230 RT_TRACE(COMP_ERR
, "%s(): CmdTable cannot be NULL\n", __func__
);
1233 if (CmdTableIdx
>= CmdTableSz
) {
1234 RT_TRACE(COMP_ERR
, "%s(): Access invalid index, please check size of the table, CmdTableIdx:%d, CmdTableSz:%d\n",
1235 __func__
, CmdTableIdx
, CmdTableSz
);
1239 pCmd
= CmdTable
+ CmdTableIdx
;
1240 pCmd
->CmdID
= CmdID
;
1241 pCmd
->Para1
= Para1
;
1242 pCmd
->Para2
= Para2
;
1243 pCmd
->msDelay
= msDelay
;
1248 /******************************************************************************
1249 * function: This function sets channel step by step
1250 * input: net_device *dev
1252 * u8 *stage //3 stages
1254 * u32 *delay //whether need to delay
1255 * output: store new stage, step and delay for next step
1256 * (combine with function above)
1257 * return: true if finished, false otherwise
1258 * notice: Wait for simpler function to replace it
1259 *****************************************************************************/
1260 static u8
rtl8192_phy_SwChnlStepByStep(struct net_device
*dev
, u8 channel
,
1261 u8
*stage
, u8
*step
, u32
*delay
)
1263 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1264 SwChnlCmd PreCommonCmd
[MAX_PRECMD_CNT
];
1265 u32 PreCommonCmdCnt
;
1266 SwChnlCmd PostCommonCmd
[MAX_POSTCMD_CNT
];
1267 u32 PostCommonCmdCnt
;
1268 SwChnlCmd RfDependCmd
[MAX_RFDEPENDCMD_CNT
];
1270 SwChnlCmd
*CurrentCmd
= NULL
;
1273 RT_TRACE(COMP_CH
, "%s() stage: %d, step: %d, channel: %d\n",
1274 __func__
, *stage
, *step
, channel
);
1275 if (!IsLegalChannel(priv
->ieee80211
, channel
)) {
1276 RT_TRACE(COMP_ERR
, "set to illegal channel: %d\n", channel
);
1277 /* return true to tell upper caller function this channel
1278 * setting is finished! Or it will in while loop.
1282 /* FIXME: need to check whether channel is legal or not here */
1285 /* <1> Fill up pre common command. */
1286 PreCommonCmdCnt
= 0;
1287 rtl8192_phy_SetSwChnlCmdArray(PreCommonCmd
, PreCommonCmdCnt
++,
1288 MAX_PRECMD_CNT
, CmdID_SetTxPowerLevel
,
1290 rtl8192_phy_SetSwChnlCmdArray(PreCommonCmd
, PreCommonCmdCnt
++,
1291 MAX_PRECMD_CNT
, CmdID_End
, 0, 0, 0);
1293 /* <2> Fill up post common command. */
1294 PostCommonCmdCnt
= 0;
1296 rtl8192_phy_SetSwChnlCmdArray(PostCommonCmd
, PostCommonCmdCnt
++,
1297 MAX_POSTCMD_CNT
, CmdID_End
, 0, 0, 0);
1299 /* <3> Fill up RF dependent command. */
1301 switch (priv
->rf_chip
) {
1303 if (!(channel
>= 1 && channel
<= 14)) {
1305 "illegal channel for Zebra 8225: %d\n",
1309 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd
, RfDependCmdCnt
++,
1310 MAX_RFDEPENDCMD_CNT
,
1313 RF_CHANNEL_TABLE_ZEBRA
[channel
],
1315 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd
, RfDependCmdCnt
++,
1316 MAX_RFDEPENDCMD_CNT
,
1317 CmdID_End
, 0, 0, 0);
1321 /* TEST!! This is not the table for 8256!! */
1322 if (!(channel
>= 1 && channel
<= 14)) {
1324 "illegal channel for Zebra 8256: %d\n",
1328 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd
, RfDependCmdCnt
++,
1329 MAX_RFDEPENDCMD_CNT
,
1331 rZebra1_Channel
, channel
, 10);
1332 rtl8192_phy_SetSwChnlCmdArray(RfDependCmd
, RfDependCmdCnt
++,
1333 MAX_RFDEPENDCMD_CNT
,
1334 CmdID_End
, 0, 0, 0);
1341 RT_TRACE(COMP_ERR
, "Unknown RFChipID: %d\n", priv
->rf_chip
);
1349 CurrentCmd
= &PreCommonCmd
[*step
];
1352 CurrentCmd
= &RfDependCmd
[*step
];
1355 CurrentCmd
= &PostCommonCmd
[*step
];
1359 if (CurrentCmd
->CmdID
== CmdID_End
) {
1360 if ((*stage
) == 2) {
1361 (*delay
) = CurrentCmd
->msDelay
;
1369 switch (CurrentCmd
->CmdID
) {
1370 case CmdID_SetTxPowerLevel
:
1371 if (priv
->card_8192_version
== (u8
)VERSION_819xU_A
)
1372 /* consider it later! */
1373 rtl8192_SetTxPowerLevel(dev
, channel
);
1375 case CmdID_WritePortUlong
:
1376 write_nic_dword(dev
, CurrentCmd
->Para1
,
1379 case CmdID_WritePortUshort
:
1380 write_nic_word(dev
, CurrentCmd
->Para1
,
1381 (u16
)CurrentCmd
->Para2
);
1383 case CmdID_WritePortUchar
:
1384 write_nic_byte(dev
, CurrentCmd
->Para1
,
1385 (u8
)CurrentCmd
->Para2
);
1387 case CmdID_RF_WriteReg
:
1388 for (eRFPath
= 0; eRFPath
< RF90_PATH_MAX
; eRFPath
++) {
1389 rtl8192_phy_SetRFReg(dev
,
1390 (RF90_RADIO_PATH_E
)eRFPath
,
1403 (*delay
) = CurrentCmd
->msDelay
;
1408 /******************************************************************************
1409 * function: This function does actually set channel work
1410 * input: net_device *dev
1414 * notice: We should not call this function directly
1415 *****************************************************************************/
1416 static void rtl8192_phy_FinishSwChnlNow(struct net_device
*dev
, u8 channel
)
1418 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1421 while (!rtl8192_phy_SwChnlStepByStep(dev
, channel
, &priv
->SwChnlStage
,
1422 &priv
->SwChnlStep
, &delay
)) {
1428 /******************************************************************************
1429 * function: Callback routine of the work item for switch channel.
1430 * input: net_device *dev
1434 *****************************************************************************/
1435 void rtl8192_SwChnl_WorkItem(struct net_device
*dev
)
1438 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1440 RT_TRACE(COMP_CH
, "==> SwChnlCallback819xUsbWorkItem(), chan:%d\n",
1444 rtl8192_phy_FinishSwChnlNow(dev
, priv
->chan
);
1446 RT_TRACE(COMP_CH
, "<== SwChnlCallback819xUsbWorkItem()\n");
1449 /******************************************************************************
1450 * function: This function scheduled actual work item to set channel
1451 * input: net_device *dev
1452 * u8 channel //channel to set
1454 * return: return code show if workitem is scheduled (1:pass, 0:fail)
1455 * notice: Delay may be required for RF configuration
1456 ******************************************************************************/
1457 u8
rtl8192_phy_SwChnl(struct net_device
*dev
, u8 channel
)
1459 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1461 RT_TRACE(COMP_CH
, "%s(), SwChnlInProgress: %d\n", __func__
,
1462 priv
->SwChnlInProgress
);
1465 if (priv
->SwChnlInProgress
)
1468 /* -------------------------------------------- */
1469 switch (priv
->ieee80211
->mode
) {
1470 case WIRELESS_MODE_A
:
1471 case WIRELESS_MODE_N_5G
:
1472 if (channel
<= 14) {
1473 RT_TRACE(COMP_ERR
, "WIRELESS_MODE_A but channel<=14\n");
1477 case WIRELESS_MODE_B
:
1479 RT_TRACE(COMP_ERR
, "WIRELESS_MODE_B but channel>14\n");
1483 case WIRELESS_MODE_G
:
1484 case WIRELESS_MODE_N_24G
:
1486 RT_TRACE(COMP_ERR
, "WIRELESS_MODE_G but channel>14\n");
1491 /* -------------------------------------------- */
1493 priv
->SwChnlInProgress
= true;
1497 priv
->chan
= channel
;
1499 priv
->SwChnlStage
= 0;
1500 priv
->SwChnlStep
= 0;
1502 rtl8192_SwChnl_WorkItem(dev
);
1504 priv
->SwChnlInProgress
= false;
1508 /******************************************************************************
1509 * function: Callback routine of the work item for set bandwidth mode.
1510 * input: net_device *dev
1513 * notice: I doubt whether SetBWModeInProgress flag is necessary as we can
1514 * test whether current work in the queue or not.//do I?
1515 *****************************************************************************/
1516 void rtl8192_SetBWModeWorkItem(struct net_device
*dev
)
1519 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1522 RT_TRACE(COMP_SWBW
, "%s() Switch to %s bandwidth\n", __func__
,
1523 priv
->CurrentChannelBW
== HT_CHANNEL_WIDTH_20
?"20MHz":"40MHz");
1526 if (priv
->rf_chip
== RF_PSEUDO_11N
) {
1527 priv
->SetBWModeInProgress
= false;
1531 /* <1> Set MAC register */
1532 read_nic_byte(dev
, BW_OPMODE
, ®BwOpMode
);
1534 switch (priv
->CurrentChannelBW
) {
1535 case HT_CHANNEL_WIDTH_20
:
1536 regBwOpMode
|= BW_OPMODE_20MHZ
;
1537 /* We have not verify whether this register works */
1538 write_nic_byte(dev
, BW_OPMODE
, regBwOpMode
);
1541 case HT_CHANNEL_WIDTH_20_40
:
1542 regBwOpMode
&= ~BW_OPMODE_20MHZ
;
1543 /* We have not verify whether this register works */
1544 write_nic_byte(dev
, BW_OPMODE
, regBwOpMode
);
1549 "SetChannelBandwidth819xUsb(): unknown Bandwidth: %#X\n",
1550 priv
->CurrentChannelBW
);
1554 /* <2> Set PHY related register */
1555 switch (priv
->CurrentChannelBW
) {
1556 case HT_CHANNEL_WIDTH_20
:
1557 rtl8192_setBBreg(dev
, rFPGA0_RFMOD
, bRFMOD
, 0x0);
1558 rtl8192_setBBreg(dev
, rFPGA1_RFMOD
, bRFMOD
, 0x0);
1559 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter1
,
1562 /* Correct the tx power for CCK rate in 20M. */
1563 priv
->cck_present_attenuation
=
1564 priv
->cck_present_attenuation_20Mdefault
+
1565 priv
->cck_present_attenuation_difference
;
1567 if (priv
->cck_present_attenuation
> 22)
1568 priv
->cck_present_attenuation
= 22;
1569 if (priv
->cck_present_attenuation
< 0)
1570 priv
->cck_present_attenuation
= 0;
1572 "20M, pHalData->CCKPresentAttentuation = %d\n",
1573 priv
->cck_present_attenuation
);
1575 if (priv
->chan
== 14 && !priv
->bcck_in_ch14
) {
1576 priv
->bcck_in_ch14
= true;
1577 dm_cck_txpower_adjust(dev
, priv
->bcck_in_ch14
);
1578 } else if (priv
->chan
!= 14 && priv
->bcck_in_ch14
) {
1579 priv
->bcck_in_ch14
= false;
1580 dm_cck_txpower_adjust(dev
, priv
->bcck_in_ch14
);
1582 dm_cck_txpower_adjust(dev
, priv
->bcck_in_ch14
);
1586 case HT_CHANNEL_WIDTH_20_40
:
1587 rtl8192_setBBreg(dev
, rFPGA0_RFMOD
, bRFMOD
, 0x1);
1588 rtl8192_setBBreg(dev
, rFPGA1_RFMOD
, bRFMOD
, 0x1);
1589 rtl8192_setBBreg(dev
, rCCK0_System
, bCCKSideBand
,
1590 priv
->nCur40MhzPrimeSC
>>1);
1591 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter1
, 0x00100000, 0);
1592 rtl8192_setBBreg(dev
, rOFDM1_LSTF
, 0xC00,
1593 priv
->nCur40MhzPrimeSC
);
1594 priv
->cck_present_attenuation
=
1595 priv
->cck_present_attenuation_40Mdefault
+
1596 priv
->cck_present_attenuation_difference
;
1598 if (priv
->cck_present_attenuation
> 22)
1599 priv
->cck_present_attenuation
= 22;
1600 if (priv
->cck_present_attenuation
< 0)
1601 priv
->cck_present_attenuation
= 0;
1604 "40M, pHalData->CCKPresentAttentuation = %d\n",
1605 priv
->cck_present_attenuation
);
1606 if (priv
->chan
== 14 && !priv
->bcck_in_ch14
) {
1607 priv
->bcck_in_ch14
= true;
1608 dm_cck_txpower_adjust(dev
, priv
->bcck_in_ch14
);
1609 } else if (priv
->chan
!= 14 && priv
->bcck_in_ch14
) {
1610 priv
->bcck_in_ch14
= false;
1611 dm_cck_txpower_adjust(dev
, priv
->bcck_in_ch14
);
1613 dm_cck_txpower_adjust(dev
, priv
->bcck_in_ch14
);
1619 "SetChannelBandwidth819xUsb(): unknown Bandwidth: %#X\n",
1620 priv
->CurrentChannelBW
);
1624 /* Skip over setting of J-mode in BB register here.
1625 * Default value is "None J mode".
1628 /* <3> Set RF related register */
1629 switch (priv
->rf_chip
) {
1632 PHY_SetRF8225Bandwidth(Adapter
, pHalData
->CurrentChannelBW
);
1637 PHY_SetRF8256Bandwidth(dev
, priv
->CurrentChannelBW
);
1647 RT_TRACE(COMP_ERR
, "Unknown RFChipID: %d\n", priv
->rf_chip
);
1650 priv
->SetBWModeInProgress
= false;
1652 RT_TRACE(COMP_SWBW
, "<==SetBWMode819xUsb(), %d\n",
1653 atomic_read(&priv
->ieee80211
->atm_swbw
));
1656 /******************************************************************************
1657 * function: This function schedules bandwidth switch work.
1658 * input: struct net_deviceq *dev
1659 * HT_CHANNEL_WIDTH bandwidth //20M or 40M
1660 * HT_EXTCHNL_OFFSET offset //Upper, Lower, or Don't care
1663 * notice: I doubt whether SetBWModeInProgress flag is necessary as we can
1664 * test whether current work in the queue or not.//do I?
1665 *****************************************************************************/
1666 void rtl8192_SetBWMode(struct net_device
*dev
, HT_CHANNEL_WIDTH bandwidth
,
1667 HT_EXTCHNL_OFFSET offset
)
1669 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1671 if (priv
->SetBWModeInProgress
)
1673 priv
->SetBWModeInProgress
= true;
1675 priv
->CurrentChannelBW
= bandwidth
;
1677 if (offset
== HT_EXTCHNL_OFFSET_LOWER
)
1678 priv
->nCur40MhzPrimeSC
= HAL_PRIME_CHNL_OFFSET_UPPER
;
1679 else if (offset
== HT_EXTCHNL_OFFSET_UPPER
)
1680 priv
->nCur40MhzPrimeSC
= HAL_PRIME_CHNL_OFFSET_LOWER
;
1682 priv
->nCur40MhzPrimeSC
= HAL_PRIME_CHNL_OFFSET_DONT_CARE
;
1684 rtl8192_SetBWModeWorkItem(dev
);
1688 void InitialGain819xUsb(struct net_device
*dev
, u8 Operation
)
1690 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1692 priv
->InitialGainOperateType
= Operation
;
1695 queue_delayed_work(priv
->priv_wq
, &priv
->initialgain_operate_wq
, 0);
1698 void InitialGainOperateWorkItemCallBack(struct work_struct
*work
)
1700 struct delayed_work
*dwork
= to_delayed_work(work
);
1701 struct r8192_priv
*priv
= container_of(dwork
, struct r8192_priv
,
1702 initialgain_operate_wq
);
1703 struct net_device
*dev
= priv
->ieee80211
->dev
;
1704 #define SCAN_RX_INITIAL_GAIN 0x17
1705 #define POWER_DETECTION_TH 0x08
1710 Operation
= priv
->InitialGainOperateType
;
1712 switch (Operation
) {
1714 RT_TRACE(COMP_SCAN
, "IG_Backup, backup the initial gain.\n");
1715 initial_gain
= SCAN_RX_INITIAL_GAIN
;
1716 bitmask
= bMaskByte0
;
1717 if (dm_digtable
.dig_algorithm
== DIG_ALGO_BY_FALSE_ALARM
)
1719 rtl8192_setBBreg(dev
, UFWP
, bMaskByte1
, 0x8);
1720 priv
->initgain_backup
.xaagccore1
=
1721 (u8
)rtl8192_QueryBBReg(dev
, rOFDM0_XAAGCCore1
, bitmask
);
1722 priv
->initgain_backup
.xbagccore1
=
1723 (u8
)rtl8192_QueryBBReg(dev
, rOFDM0_XBAGCCore1
, bitmask
);
1724 priv
->initgain_backup
.xcagccore1
=
1725 (u8
)rtl8192_QueryBBReg(dev
, rOFDM0_XCAGCCore1
, bitmask
);
1726 priv
->initgain_backup
.xdagccore1
=
1727 (u8
)rtl8192_QueryBBReg(dev
, rOFDM0_XDAGCCore1
, bitmask
);
1728 bitmask
= bMaskByte2
;
1729 priv
->initgain_backup
.cca
=
1730 (u8
)rtl8192_QueryBBReg(dev
, rCCK0_CCA
, bitmask
);
1732 RT_TRACE(COMP_SCAN
, "Scan InitialGainBackup 0xc50 is %x\n",
1733 priv
->initgain_backup
.xaagccore1
);
1734 RT_TRACE(COMP_SCAN
, "Scan InitialGainBackup 0xc58 is %x\n",
1735 priv
->initgain_backup
.xbagccore1
);
1736 RT_TRACE(COMP_SCAN
, "Scan InitialGainBackup 0xc60 is %x\n",
1737 priv
->initgain_backup
.xcagccore1
);
1738 RT_TRACE(COMP_SCAN
, "Scan InitialGainBackup 0xc68 is %x\n",
1739 priv
->initgain_backup
.xdagccore1
);
1740 RT_TRACE(COMP_SCAN
, "Scan InitialGainBackup 0xa0a is %x\n",
1741 priv
->initgain_backup
.cca
);
1743 RT_TRACE(COMP_SCAN
, "Write scan initial gain = 0x%x\n",
1745 write_nic_byte(dev
, rOFDM0_XAAGCCore1
, initial_gain
);
1746 write_nic_byte(dev
, rOFDM0_XBAGCCore1
, initial_gain
);
1747 write_nic_byte(dev
, rOFDM0_XCAGCCore1
, initial_gain
);
1748 write_nic_byte(dev
, rOFDM0_XDAGCCore1
, initial_gain
);
1749 RT_TRACE(COMP_SCAN
, "Write scan 0xa0a = 0x%x\n",
1750 POWER_DETECTION_TH
);
1751 write_nic_byte(dev
, 0xa0a, POWER_DETECTION_TH
);
1754 RT_TRACE(COMP_SCAN
, "IG_Restore, restore the initial gain.\n");
1755 bitmask
= 0x7f; /* Bit0 ~ Bit6 */
1756 if (dm_digtable
.dig_algorithm
== DIG_ALGO_BY_FALSE_ALARM
)
1758 rtl8192_setBBreg(dev
, UFWP
, bMaskByte1
, 0x8);
1760 rtl8192_setBBreg(dev
, rOFDM0_XAAGCCore1
, bitmask
,
1761 (u32
)priv
->initgain_backup
.xaagccore1
);
1762 rtl8192_setBBreg(dev
, rOFDM0_XBAGCCore1
, bitmask
,
1763 (u32
)priv
->initgain_backup
.xbagccore1
);
1764 rtl8192_setBBreg(dev
, rOFDM0_XCAGCCore1
, bitmask
,
1765 (u32
)priv
->initgain_backup
.xcagccore1
);
1766 rtl8192_setBBreg(dev
, rOFDM0_XDAGCCore1
, bitmask
,
1767 (u32
)priv
->initgain_backup
.xdagccore1
);
1768 bitmask
= bMaskByte2
;
1769 rtl8192_setBBreg(dev
, rCCK0_CCA
, bitmask
,
1770 (u32
)priv
->initgain_backup
.cca
);
1772 RT_TRACE(COMP_SCAN
, "Scan BBInitialGainRestore 0xc50 is %x\n",
1773 priv
->initgain_backup
.xaagccore1
);
1774 RT_TRACE(COMP_SCAN
, "Scan BBInitialGainRestore 0xc58 is %x\n",
1775 priv
->initgain_backup
.xbagccore1
);
1776 RT_TRACE(COMP_SCAN
, "Scan BBInitialGainRestore 0xc60 is %x\n",
1777 priv
->initgain_backup
.xcagccore1
);
1778 RT_TRACE(COMP_SCAN
, "Scan BBInitialGainRestore 0xc68 is %x\n",
1779 priv
->initgain_backup
.xdagccore1
);
1780 RT_TRACE(COMP_SCAN
, "Scan BBInitialGainRestore 0xa0a is %x\n",
1781 priv
->initgain_backup
.cca
);
1783 rtl8192_phy_setTxPower(dev
, priv
->ieee80211
->current_network
.channel
);
1785 if (dm_digtable
.dig_algorithm
== DIG_ALGO_BY_FALSE_ALARM
)
1787 rtl8192_setBBreg(dev
, UFWP
, bMaskByte1
, 0x1);
1790 RT_TRACE(COMP_SCAN
, "Unknown IG Operation.\n");