linux/drivers/staging/r8188eu/hal/rtl8188e_phycfg.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2/* Copyright(c) 2007 - 2011 Realtek Corporation. */
   3
   4#define _RTL8188E_PHYCFG_C_
   5
   6#include "../include/osdep_service.h"
   7#include "../include/drv_types.h"
   8#include "../include/rtw_iol.h"
   9#include "../include/rtl8188e_hal.h"
  10
  11/*---------------------------Define Local Constant---------------------------*/
  12/* Channel switch:The size of command tables for switch channel*/
  13#define MAX_PRECMD_CNT 16
  14#define MAX_RFDEPENDCMD_CNT 16
  15#define MAX_POSTCMD_CNT 16
  16
  17#define MAX_DOZE_WAITING_TIMES_9x 64
  18
  19/*---------------------------Define Local Constant---------------------------*/
  20
  21/*------------------------Define global variable-----------------------------*/
  22
  23/*------------------------Define local variable------------------------------*/
  24
  25/*--------------------Define export function prototype-----------------------*/
  26/*  Please refer to header file */
  27/*--------------------Define export function prototype-----------------------*/
  28
  29/*----------------------------Function Body----------------------------------*/
  30/*  */
  31/*  1. BB register R/W API */
  32/*  */
  33
  34/**
  35* Function:     phy_CalculateBitShift
  36*
  37* OverView:     Get shifted position of the BitMask
  38*
  39* Input:
  40*                       u32             BitMask,
  41*
  42* Output:       none
  43* Return:               u32             Return the shift bit bit position of the mask
  44*/
  45static  u32 phy_CalculateBitShift(u32 BitMask)
  46{
  47        u32 i;
  48
  49        for (i = 0; i <= 31; i++) {
  50                if (((BitMask >> i) & 0x1) == 1)
  51                        break;
  52        }
  53        return i;
  54}
  55
  56/**
  57* Function:     PHY_QueryBBReg
  58*
  59* OverView:     Read "sepcific bits" from BB register
  60*
  61* Input:
  62*                       struct adapter *Adapter,
  63*                       u32                     RegAddr,        The target address to be readback
  64*                       u32                     BitMask         The target bit position in the target address
  65*                                                               to be readback
  66* Output:       None
  67* Return:               u32                     Data            The readback register value
  68* Note:         This function is equal to "GetRegSetting" in PHY programming guide
  69*/
  70u32
  71rtl8188e_PHY_QueryBBReg(
  72                struct adapter *Adapter,
  73                u32 RegAddr,
  74                u32 BitMask
  75        )
  76{
  77        u32 ReturnValue = 0, OriginalValue, BitShift;
  78
  79        OriginalValue = rtw_read32(Adapter, RegAddr);
  80        BitShift = phy_CalculateBitShift(BitMask);
  81        ReturnValue = (OriginalValue & BitMask) >> BitShift;
  82        return ReturnValue;
  83}
  84
  85/**
  86* Function:     PHY_SetBBReg
  87*
  88* OverView:     Write "Specific bits" to BB register (page 8~)
  89*
  90* Input:
  91*                       struct adapter *Adapter,
  92*                       u32                     RegAddr,        The target address to be modified
  93*                       u32                     BitMask         The target bit position in the target address
  94*                                                                       to be modified
  95*                       u32                     Data            The new register value in the target bit position
  96*                                                                       of the target address
  97*
  98* Output:       None
  99* Return:               None
 100* Note:         This function is equal to "PutRegSetting" in PHY programming guide
 101*/
 102
 103void rtl8188e_PHY_SetBBReg(struct adapter *Adapter, u32 RegAddr, u32 BitMask, u32 Data)
 104{
 105        u32 OriginalValue, BitShift;
 106
 107        if (BitMask != bMaskDWord) { /* if not "double word" write */
 108                OriginalValue = rtw_read32(Adapter, RegAddr);
 109                BitShift = phy_CalculateBitShift(BitMask);
 110                Data = ((OriginalValue & (~BitMask)) | (Data << BitShift));
 111        }
 112
 113        rtw_write32(Adapter, RegAddr, Data);
 114}
 115
 116/*  */
 117/*  2. RF register R/W API */
 118/*  */
 119/**
 120* Function:     phy_RFSerialRead
 121*
 122* OverView:     Read regster from RF chips
 123*
 124* Input:
 125*                       struct adapter *Adapter,
 126*                       enum rf_radio_path eRFPath,     Radio path of A/B/C/D
 127*                       u32                     Offset,         The target address to be read
 128*
 129* Output:       None
 130* Return:               u32                     reback value
 131* Note:         Threre are three types of serial operations:
 132*                       1. Software serial write
 133*                       2. Hardware LSSI-Low Speed Serial Interface
 134*                       3. Hardware HSSI-High speed
 135*                       serial write. Driver need to implement (1) and (2).
 136*                       This function is equal to the combination of RF_ReadReg() and  RFLSSIRead()
 137*/
 138static  u32
 139phy_RFSerialRead(
 140                struct adapter *Adapter,
 141                enum rf_radio_path eRFPath,
 142                u32 Offset
 143        )
 144{
 145        u32 retValue = 0;
 146        struct hal_data_8188e                           *pHalData = GET_HAL_DATA(Adapter);
 147        struct bb_reg_def *pPhyReg = &pHalData->PHYRegDef[eRFPath];
 148        u32 NewOffset;
 149        u32 tmplong, tmplong2;
 150        u8      RfPiEnable = 0;
 151        /*  */
 152        /*  Make sure RF register offset is correct */
 153        /*  */
 154        Offset &= 0xff;
 155
 156        /*  */
 157        /*  Switch page for 8256 RF IC */
 158        /*  */
 159        NewOffset = Offset;
 160
 161        /*  For 92S LSSI Read RFLSSIRead */
 162        /*  For RF A/B write 0x824/82c(does not work in the future) */
 163        /*  We must use 0x824 for RF A and B to execute read trigger */
 164        tmplong = PHY_QueryBBReg(Adapter, rFPGA0_XA_HSSIParameter2, bMaskDWord);
 165        if (eRFPath == RF_PATH_A)
 166                tmplong2 = tmplong;
 167        else
 168                tmplong2 = PHY_QueryBBReg(Adapter, pPhyReg->rfHSSIPara2, bMaskDWord);
 169
 170        tmplong2 = (tmplong2 & (~bLSSIReadAddress)) | (NewOffset << 23) | bLSSIReadEdge;        /* T65 RF */
 171
 172        PHY_SetBBReg(Adapter, rFPGA0_XA_HSSIParameter2, bMaskDWord, tmplong & (~bLSSIReadEdge));
 173        udelay(10);/*  PlatformStallExecution(10); */
 174
 175        PHY_SetBBReg(Adapter, pPhyReg->rfHSSIPara2, bMaskDWord, tmplong2);
 176        udelay(100);/* PlatformStallExecution(100); */
 177
 178        udelay(10);/* PlatformStallExecution(10); */
 179
 180        if (eRFPath == RF_PATH_A)
 181                RfPiEnable = (u8)PHY_QueryBBReg(Adapter, rFPGA0_XA_HSSIParameter1, BIT(8));
 182        else if (eRFPath == RF_PATH_B)
 183                RfPiEnable = (u8)PHY_QueryBBReg(Adapter, rFPGA0_XB_HSSIParameter1, BIT(8));
 184
 185        if (RfPiEnable) {       /*  Read from BBreg8b8, 12 bits for 8190, 20bits for T65 RF */
 186                retValue = PHY_QueryBBReg(Adapter, pPhyReg->rfLSSIReadBackPi, bLSSIReadBackData);
 187        } else {        /* Read from BBreg8a0, 12 bits for 8190, 20 bits for T65 RF */
 188                retValue = PHY_QueryBBReg(Adapter, pPhyReg->rfLSSIReadBack, bLSSIReadBackData);
 189        }
 190        return retValue;
 191}
 192
 193/**
 194* Function:     phy_RFSerialWrite
 195*
 196* OverView:     Write data to RF register (page 8~)
 197*
 198* Input:
 199*                       struct adapter *Adapter,
 200*                       enum rf_radio_path eRFPath,     Radio path of A/B/C/D
 201*                       u32                     Offset,         The target address to be read
 202*                       u32                     Data            The new register Data in the target bit position
 203*                                                                       of the target to be read
 204*
 205* Output:       None
 206* Return:               None
 207* Note:         Threre are three types of serial operations:
 208*                       1. Software serial write
 209*                       2. Hardware LSSI-Low Speed Serial Interface
 210*                       3. Hardware HSSI-High speed
 211*                       serial write. Driver need to implement (1) and (2).
 212*                       This function is equal to the combination of RF_ReadReg() and  RFLSSIRead()
 213 *
 214 * Note:                  For RF8256 only
 215 *                       The total count of RTL8256(Zebra4) register is around 36 bit it only employs
 216 *                       4-bit RF address. RTL8256 uses "register mode control bit" (Reg00[12], Reg00[10])
 217 *                       to access register address bigger than 0xf. See "Appendix-4 in PHY Configuration
 218 *                       programming guide" for more details.
 219 *                       Thus, we define a sub-finction for RTL8526 register address conversion
 220 *                     ===========================================================
 221 *                       Register Mode          RegCTL[1]               RegCTL[0]               Note
 222 *                                                              (Reg00[12])             (Reg00[10])
 223 *                     ===========================================================
 224 *                       Reg_Mode0                              0                               x                       Reg 0 ~15(0x0 ~ 0xf)
 225 *                     ------------------------------------------------------------------
 226 *                       Reg_Mode1                              1                               0                       Reg 16 ~30(0x1 ~ 0xf)
 227 *                     ------------------------------------------------------------------
 228 *                       Reg_Mode2                              1                               1                       Reg 31 ~ 45(0x1 ~ 0xf)
 229 *                     ------------------------------------------------------------------
 230 *
 231 *      2008/09/02      MH      Add 92S RF definition
 232 *
 233 *
 234 *
 235*/
 236static  void
 237phy_RFSerialWrite(
 238                struct adapter *Adapter,
 239                enum rf_radio_path eRFPath,
 240                u32 Offset,
 241                u32 Data
 242        )
 243{
 244        u32 DataAndAddr = 0;
 245        struct hal_data_8188e                           *pHalData = GET_HAL_DATA(Adapter);
 246        struct bb_reg_def *pPhyReg = &pHalData->PHYRegDef[eRFPath];
 247        u32 NewOffset;
 248
 249        /*  2009/06/17 MH We can not execute IO for power save or other accident mode. */
 250
 251        Offset &= 0xff;
 252
 253        /*  */
 254        /*  Switch page for 8256 RF IC */
 255        /*  */
 256        NewOffset = Offset;
 257
 258        /*  */
 259        /*  Put write addr in [5:0]  and write data in [31:16] */
 260        /*  */
 261        DataAndAddr = ((NewOffset << 20) | (Data & 0x000fffff)) & 0x0fffffff;   /*  T65 RF */
 262
 263        /*  */
 264        /*  Write Operation */
 265        /*  */
 266        PHY_SetBBReg(Adapter, pPhyReg->rf3wireOffset, bMaskDWord, DataAndAddr);
 267}
 268
 269/**
 270* Function:     PHY_QueryRFReg
 271*
 272* OverView:     Query "Specific bits" to RF register (page 8~)
 273*
 274* Input:
 275*                       struct adapter *Adapter,
 276*                       enum rf_radio_path eRFPath,     Radio path of A/B/C/D
 277*                       u32                     RegAddr,        The target address to be read
 278*                       u32                     BitMask         The target bit position in the target address
 279*                                                                       to be read
 280*
 281* Output:       None
 282* Return:               u32                     Readback value
 283* Note:         This function is equal to "GetRFRegSetting" in PHY programming guide
 284*/
 285u32 rtl8188e_PHY_QueryRFReg(struct adapter *Adapter, enum rf_radio_path eRFPath,
 286                            u32 RegAddr, u32 BitMask)
 287{
 288        u32 Original_Value, Readback_Value, BitShift;
 289
 290        Original_Value = phy_RFSerialRead(Adapter, eRFPath, RegAddr);
 291
 292        BitShift =  phy_CalculateBitShift(BitMask);
 293        Readback_Value = (Original_Value & BitMask) >> BitShift;
 294        return Readback_Value;
 295}
 296
 297/**
 298* Function:     PHY_SetRFReg
 299*
 300* OverView:     Write "Specific bits" to RF register (page 8~)
 301*
 302* Input:
 303*                       struct adapter *Adapter,
 304*                       enum rf_radio_path eRFPath,     Radio path of A/B/C/D
 305*                       u32                     RegAddr,        The target address to be modified
 306*                       u32                     BitMask         The target bit position in the target address
 307*                                                                       to be modified
 308*                       u32                     Data            The new register Data in the target bit position
 309*                                                                       of the target address
 310*
 311* Output:       None
 312* Return:               None
 313* Note:         This function is equal to "PutRFRegSetting" in PHY programming guide
 314*/
 315void
 316rtl8188e_PHY_SetRFReg(
 317                struct adapter *Adapter,
 318                enum rf_radio_path eRFPath,
 319                u32 RegAddr,
 320                u32 BitMask,
 321                u32 Data
 322        )
 323{
 324        u32 Original_Value, BitShift;
 325
 326        /*  RF data is 12 bits only */
 327        if (BitMask != bRFRegOffsetMask) {
 328                Original_Value = phy_RFSerialRead(Adapter, eRFPath, RegAddr);
 329                BitShift =  phy_CalculateBitShift(BitMask);
 330                Data = ((Original_Value & (~BitMask)) | (Data << BitShift));
 331        }
 332
 333        phy_RFSerialWrite(Adapter, eRFPath, RegAddr, Data);
 334}
 335
 336/*  */
 337/*  3. Initial MAC/BB/RF config by reading MAC/BB/RF txt. */
 338/*  */
 339
 340/*-----------------------------------------------------------------------------
 341 * Function:    PHY_MACConfig8192C
 342 *
 343 * Overview:    Condig MAC by header file or parameter file.
 344 *
 345 * Input:       NONE
 346 *
 347 * Output:      NONE
 348 *
 349 * Return:      NONE
 350 *
 351 * Revised History:
 352 *  When                Who             Remark
 353 *  08/12/2008  MHC             Create Version 0.
 354 *
 355 *---------------------------------------------------------------------------*/
 356s32 PHY_MACConfig8188E(struct adapter *Adapter)
 357{
 358        struct hal_data_8188e   *pHalData = GET_HAL_DATA(Adapter);
 359        int rtStatus = _SUCCESS;
 360
 361        /*  */
 362        /*  Config MAC */
 363        /*  */
 364        if (HAL_STATUS_FAILURE == ODM_ConfigMACWithHeaderFile(&pHalData->odmpriv))
 365                rtStatus = _FAIL;
 366
 367        /*  2010.07.13 AMPDU aggregation number B */
 368        rtw_write16(Adapter, REG_MAX_AGGR_NUM, MAX_AGGR_NUM);
 369
 370        return rtStatus;
 371}
 372
 373/**
 374* Function:     phy_InitBBRFRegisterDefinition
 375*
 376* OverView:     Initialize Register definition offset for Radio Path A/B/C/D
 377*
 378* Input:
 379*                       struct adapter *Adapter,
 380*
 381* Output:       None
 382* Return:               None
 383* Note:         The initialization value is constant and it should never be changes
 384*/
 385static  void
 386phy_InitBBRFRegisterDefinition(
 387                struct adapter *Adapter
 388)
 389{
 390        struct hal_data_8188e           *pHalData = GET_HAL_DATA(Adapter);
 391
 392        /*  RF Interface Sowrtware Control */
 393        pHalData->PHYRegDef[RF_PATH_A].rfintfs = rFPGA0_XAB_RFInterfaceSW; /*  16 LSBs if read 32-bit from 0x870 */
 394        pHalData->PHYRegDef[RF_PATH_B].rfintfs = rFPGA0_XAB_RFInterfaceSW; /*  16 MSBs if read 32-bit from 0x870 (16-bit for 0x872) */
 395        pHalData->PHYRegDef[RF_PATH_C].rfintfs = rFPGA0_XCD_RFInterfaceSW;/*  16 LSBs if read 32-bit from 0x874 */
 396        pHalData->PHYRegDef[RF_PATH_D].rfintfs = rFPGA0_XCD_RFInterfaceSW;/*  16 MSBs if read 32-bit from 0x874 (16-bit for 0x876) */
 397
 398        /*  RF Interface Readback Value */
 399        pHalData->PHYRegDef[RF_PATH_A].rfintfi = rFPGA0_XAB_RFInterfaceRB; /*  16 LSBs if read 32-bit from 0x8E0 */
 400        pHalData->PHYRegDef[RF_PATH_B].rfintfi = rFPGA0_XAB_RFInterfaceRB;/*  16 MSBs if read 32-bit from 0x8E0 (16-bit for 0x8E2) */
 401        pHalData->PHYRegDef[RF_PATH_C].rfintfi = rFPGA0_XCD_RFInterfaceRB;/*  16 LSBs if read 32-bit from 0x8E4 */
 402        pHalData->PHYRegDef[RF_PATH_D].rfintfi = rFPGA0_XCD_RFInterfaceRB;/*  16 MSBs if read 32-bit from 0x8E4 (16-bit for 0x8E6) */
 403
 404        /*  RF Interface Output (and Enable) */
 405        pHalData->PHYRegDef[RF_PATH_A].rfintfo = rFPGA0_XA_RFInterfaceOE; /*  16 LSBs if read 32-bit from 0x860 */
 406        pHalData->PHYRegDef[RF_PATH_B].rfintfo = rFPGA0_XB_RFInterfaceOE; /*  16 LSBs if read 32-bit from 0x864 */
 407
 408        /*  RF Interface (Output and)  Enable */
 409        pHalData->PHYRegDef[RF_PATH_A].rfintfe = rFPGA0_XA_RFInterfaceOE; /*  16 MSBs if read 32-bit from 0x860 (16-bit for 0x862) */
 410        pHalData->PHYRegDef[RF_PATH_B].rfintfe = rFPGA0_XB_RFInterfaceOE; /*  16 MSBs if read 32-bit from 0x864 (16-bit for 0x866) */
 411
 412        /* Addr of LSSI. Wirte RF register by driver */
 413        pHalData->PHYRegDef[RF_PATH_A].rf3wireOffset = rFPGA0_XA_LSSIParameter; /* LSSI Parameter */
 414        pHalData->PHYRegDef[RF_PATH_B].rf3wireOffset = rFPGA0_XB_LSSIParameter;
 415
 416        /*  RF parameter */
 417        pHalData->PHYRegDef[RF_PATH_A].rfLSSI_Select = rFPGA0_XAB_RFParameter;  /* BB Band Select */
 418        pHalData->PHYRegDef[RF_PATH_B].rfLSSI_Select = rFPGA0_XAB_RFParameter;
 419        pHalData->PHYRegDef[RF_PATH_C].rfLSSI_Select = rFPGA0_XCD_RFParameter;
 420        pHalData->PHYRegDef[RF_PATH_D].rfLSSI_Select = rFPGA0_XCD_RFParameter;
 421
 422        /*  Tx AGC Gain Stage (same for all path. Should we remove this?) */
 423        pHalData->PHYRegDef[RF_PATH_A].rfTxGainStage = rFPGA0_TxGainStage; /* Tx gain stage */
 424        pHalData->PHYRegDef[RF_PATH_B].rfTxGainStage = rFPGA0_TxGainStage; /* Tx gain stage */
 425        pHalData->PHYRegDef[RF_PATH_C].rfTxGainStage = rFPGA0_TxGainStage; /* Tx gain stage */
 426        pHalData->PHYRegDef[RF_PATH_D].rfTxGainStage = rFPGA0_TxGainStage; /* Tx gain stage */
 427
 428        /*  Tranceiver A~D HSSI Parameter-1 */
 429        pHalData->PHYRegDef[RF_PATH_A].rfHSSIPara1 = rFPGA0_XA_HSSIParameter1;  /* wire control parameter1 */
 430        pHalData->PHYRegDef[RF_PATH_B].rfHSSIPara1 = rFPGA0_XB_HSSIParameter1;  /* wire control parameter1 */
 431
 432        /*  Tranceiver A~D HSSI Parameter-2 */
 433        pHalData->PHYRegDef[RF_PATH_A].rfHSSIPara2 = rFPGA0_XA_HSSIParameter2;  /* wire control parameter2 */
 434        pHalData->PHYRegDef[RF_PATH_B].rfHSSIPara2 = rFPGA0_XB_HSSIParameter2;  /* wire control parameter2 */
 435
 436        /*  RF switch Control */
 437        pHalData->PHYRegDef[RF_PATH_A].rfSwitchControl = rFPGA0_XAB_SwitchControl; /* TR/Ant switch control */
 438        pHalData->PHYRegDef[RF_PATH_B].rfSwitchControl = rFPGA0_XAB_SwitchControl;
 439        pHalData->PHYRegDef[RF_PATH_C].rfSwitchControl = rFPGA0_XCD_SwitchControl;
 440        pHalData->PHYRegDef[RF_PATH_D].rfSwitchControl = rFPGA0_XCD_SwitchControl;
 441
 442        /*  AGC control 1 */
 443        pHalData->PHYRegDef[RF_PATH_A].rfAGCControl1 = rOFDM0_XAAGCCore1;
 444        pHalData->PHYRegDef[RF_PATH_B].rfAGCControl1 = rOFDM0_XBAGCCore1;
 445        pHalData->PHYRegDef[RF_PATH_C].rfAGCControl1 = rOFDM0_XCAGCCore1;
 446        pHalData->PHYRegDef[RF_PATH_D].rfAGCControl1 = rOFDM0_XDAGCCore1;
 447
 448        /*  AGC control 2 */
 449        pHalData->PHYRegDef[RF_PATH_A].rfAGCControl2 = rOFDM0_XAAGCCore2;
 450        pHalData->PHYRegDef[RF_PATH_B].rfAGCControl2 = rOFDM0_XBAGCCore2;
 451        pHalData->PHYRegDef[RF_PATH_C].rfAGCControl2 = rOFDM0_XCAGCCore2;
 452        pHalData->PHYRegDef[RF_PATH_D].rfAGCControl2 = rOFDM0_XDAGCCore2;
 453
 454        /*  RX AFE control 1 */
 455        pHalData->PHYRegDef[RF_PATH_A].rfRxIQImbalance = rOFDM0_XARxIQImbalance;
 456        pHalData->PHYRegDef[RF_PATH_B].rfRxIQImbalance = rOFDM0_XBRxIQImbalance;
 457        pHalData->PHYRegDef[RF_PATH_C].rfRxIQImbalance = rOFDM0_XCRxIQImbalance;
 458        pHalData->PHYRegDef[RF_PATH_D].rfRxIQImbalance = rOFDM0_XDRxIQImbalance;
 459
 460        /*  RX AFE control 1 */
 461        pHalData->PHYRegDef[RF_PATH_A].rfRxAFE = rOFDM0_XARxAFE;
 462        pHalData->PHYRegDef[RF_PATH_B].rfRxAFE = rOFDM0_XBRxAFE;
 463        pHalData->PHYRegDef[RF_PATH_C].rfRxAFE = rOFDM0_XCRxAFE;
 464        pHalData->PHYRegDef[RF_PATH_D].rfRxAFE = rOFDM0_XDRxAFE;
 465
 466        /*  Tx AFE control 1 */
 467        pHalData->PHYRegDef[RF_PATH_A].rfTxIQImbalance = rOFDM0_XATxIQImbalance;
 468        pHalData->PHYRegDef[RF_PATH_B].rfTxIQImbalance = rOFDM0_XBTxIQImbalance;
 469        pHalData->PHYRegDef[RF_PATH_C].rfTxIQImbalance = rOFDM0_XCTxIQImbalance;
 470        pHalData->PHYRegDef[RF_PATH_D].rfTxIQImbalance = rOFDM0_XDTxIQImbalance;
 471
 472        /*  Tx AFE control 2 */
 473        pHalData->PHYRegDef[RF_PATH_A].rfTxAFE = rOFDM0_XATxAFE;
 474        pHalData->PHYRegDef[RF_PATH_B].rfTxAFE = rOFDM0_XBTxAFE;
 475        pHalData->PHYRegDef[RF_PATH_C].rfTxAFE = rOFDM0_XCTxAFE;
 476        pHalData->PHYRegDef[RF_PATH_D].rfTxAFE = rOFDM0_XDTxAFE;
 477
 478        /*  Tranceiver LSSI Readback SI mode */
 479        pHalData->PHYRegDef[RF_PATH_A].rfLSSIReadBack = rFPGA0_XA_LSSIReadBack;
 480        pHalData->PHYRegDef[RF_PATH_B].rfLSSIReadBack = rFPGA0_XB_LSSIReadBack;
 481        pHalData->PHYRegDef[RF_PATH_C].rfLSSIReadBack = rFPGA0_XC_LSSIReadBack;
 482        pHalData->PHYRegDef[RF_PATH_D].rfLSSIReadBack = rFPGA0_XD_LSSIReadBack;
 483
 484        /*  Tranceiver LSSI Readback PI mode */
 485        pHalData->PHYRegDef[RF_PATH_A].rfLSSIReadBackPi = TransceiverA_HSPI_Readback;
 486        pHalData->PHYRegDef[RF_PATH_B].rfLSSIReadBackPi = TransceiverB_HSPI_Readback;
 487}
 488
 489void storePwrIndexDiffRateOffset(struct adapter *Adapter, u32 RegAddr, u32 BitMask, u32 Data)
 490{
 491        struct hal_data_8188e   *pHalData = GET_HAL_DATA(Adapter);
 492
 493        if (RegAddr == rTxAGC_A_Rate18_06)
 494                pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][0] = Data;
 495        if (RegAddr == rTxAGC_A_Rate54_24)
 496                pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][1] = Data;
 497        if (RegAddr == rTxAGC_A_CCK1_Mcs32)
 498                pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][6] = Data;
 499        if (RegAddr == rTxAGC_B_CCK11_A_CCK2_11 && BitMask == 0xffffff00)
 500                pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][7] = Data;
 501        if (RegAddr == rTxAGC_A_Mcs03_Mcs00)
 502                pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][2] = Data;
 503        if (RegAddr == rTxAGC_A_Mcs07_Mcs04)
 504                pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][3] = Data;
 505        if (RegAddr == rTxAGC_A_Mcs11_Mcs08)
 506                pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][4] = Data;
 507        if (RegAddr == rTxAGC_A_Mcs15_Mcs12) {
 508                pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][5] = Data;
 509                if (pHalData->rf_type == RF_1T1R)
 510                        pHalData->pwrGroupCnt++;
 511        }
 512        if (RegAddr == rTxAGC_B_Rate18_06)
 513                pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][8] = Data;
 514        if (RegAddr == rTxAGC_B_Rate54_24)
 515                pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][9] = Data;
 516        if (RegAddr == rTxAGC_B_CCK1_55_Mcs32)
 517                pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][14] = Data;
 518        if (RegAddr == rTxAGC_B_CCK11_A_CCK2_11 && BitMask == 0x000000ff)
 519                pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][15] = Data;
 520        if (RegAddr == rTxAGC_B_Mcs03_Mcs00)
 521                pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][10] = Data;
 522        if (RegAddr == rTxAGC_B_Mcs07_Mcs04)
 523                pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][11] = Data;
 524        if (RegAddr == rTxAGC_B_Mcs11_Mcs08)
 525                pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][12] = Data;
 526        if (RegAddr == rTxAGC_B_Mcs15_Mcs12) {
 527                pHalData->MCSTxPowerLevelOriginalOffset[pHalData->pwrGroupCnt][13] = Data;
 528                if (pHalData->rf_type != RF_1T1R)
 529                        pHalData->pwrGroupCnt++;
 530        }
 531}
 532
 533static  int phy_BB8188E_Config_ParaFile(struct adapter *Adapter)
 534{
 535        struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(Adapter);
 536        struct hal_data_8188e           *pHalData = GET_HAL_DATA(Adapter);
 537        int                     rtStatus = _SUCCESS;
 538
 539        /*  */
 540        /*  1. Read PHY_REG.TXT BB INIT!! */
 541        /*  We will separate as 88C / 92C according to chip version */
 542        /*  */
 543        if (HAL_STATUS_FAILURE == ODM_ConfigBBWithHeaderFile(&pHalData->odmpriv, CONFIG_BB_PHY_REG))
 544                rtStatus = _FAIL;
 545        if (rtStatus != _SUCCESS)
 546                goto phy_BB8190_Config_ParaFile_Fail;
 547
 548        /*  2. If EEPROM or EFUSE autoload OK, We must config by PHY_REG_PG.txt */
 549        if (!pEEPROM->bautoload_fail_flag) {
 550                pHalData->pwrGroupCnt = 0;
 551
 552                if (HAL_STATUS_FAILURE == ODM_ConfigBBWithHeaderFile(&pHalData->odmpriv, CONFIG_BB_PHY_REG_PG))
 553                        rtStatus = _FAIL;
 554        }
 555
 556        if (rtStatus != _SUCCESS)
 557                goto phy_BB8190_Config_ParaFile_Fail;
 558
 559        /*  3. BB AGC table Initialization */
 560        if (HAL_STATUS_FAILURE == ODM_ConfigBBWithHeaderFile(&pHalData->odmpriv,  CONFIG_BB_AGC_TAB))
 561                rtStatus = _FAIL;
 562
 563        if (rtStatus != _SUCCESS)
 564                goto phy_BB8190_Config_ParaFile_Fail;
 565
 566phy_BB8190_Config_ParaFile_Fail:
 567
 568        return rtStatus;
 569}
 570
 571int
 572PHY_BBConfig8188E(
 573                struct adapter *Adapter
 574        )
 575{
 576        int     rtStatus = _SUCCESS;
 577        struct hal_data_8188e   *pHalData = GET_HAL_DATA(Adapter);
 578        u32 RegVal;
 579        u8 CrystalCap;
 580
 581        phy_InitBBRFRegisterDefinition(Adapter);
 582
 583        /*  Enable BB and RF */
 584        RegVal = rtw_read16(Adapter, REG_SYS_FUNC_EN);
 585        rtw_write16(Adapter, REG_SYS_FUNC_EN, (u16)(RegVal | BIT(13) | BIT(0) | BIT(1)));
 586
 587        /*  20090923 Joseph: Advised by Steven and Jenyu. Power sequence before init RF. */
 588
 589        rtw_write8(Adapter, REG_RF_CTRL, RF_EN | RF_RSTB | RF_SDMRSTB);
 590
 591        rtw_write8(Adapter, REG_SYS_FUNC_EN, FEN_USBA | FEN_USBD | FEN_BB_GLB_RSTn | FEN_BBRSTB);
 592
 593        /*  Config BB and AGC */
 594        rtStatus = phy_BB8188E_Config_ParaFile(Adapter);
 595
 596        /*  write 0x24[16:11] = 0x24[22:17] = CrystalCap */
 597        CrystalCap = pHalData->CrystalCap & 0x3F;
 598        PHY_SetBBReg(Adapter, REG_AFE_XTAL_CTRL, 0x7ff800, (CrystalCap | (CrystalCap << 6)));
 599
 600        return rtStatus;
 601}
 602
 603int PHY_RFConfig8188E(struct adapter *Adapter)
 604{
 605        int             rtStatus = _SUCCESS;
 606
 607        /*  RF config */
 608        rtStatus = PHY_RF6052_Config8188E(Adapter);
 609        return rtStatus;
 610}
 611
 612/*-----------------------------------------------------------------------------
 613 * Function:    PHY_ConfigRFWithParaFile()
 614 *
 615 * Overview:    This function read RF parameters from general file format, and do RF 3-wire
 616 *
 617 * Input:       struct adapter *Adapter
 618 *                      ps8                                     pFileName
 619 *                      enum rf_radio_path eRFPath
 620 *
 621 * Output:      NONE
 622 *
 623 * Return:      RT_STATUS_SUCCESS: configuration file exist
 624 *
 625 * Note:                Delay may be required for RF configuration
 626 *---------------------------------------------------------------------------*/
 627int rtl8188e_PHY_ConfigRFWithParaFile(struct adapter *Adapter, u8 *pFileName, enum rf_radio_path eRFPath)
 628{
 629        return _SUCCESS;
 630}
 631
 632void
 633rtl8192c_PHY_GetHWRegOriginalValue(
 634                struct adapter *Adapter
 635        )
 636{
 637        struct hal_data_8188e   *pHalData = GET_HAL_DATA(Adapter);
 638
 639        /*  read rx initial gain */
 640        pHalData->DefaultInitialGain[0] = (u8)PHY_QueryBBReg(Adapter, rOFDM0_XAAGCCore1, bMaskByte0);
 641        pHalData->DefaultInitialGain[1] = (u8)PHY_QueryBBReg(Adapter, rOFDM0_XBAGCCore1, bMaskByte0);
 642        pHalData->DefaultInitialGain[2] = (u8)PHY_QueryBBReg(Adapter, rOFDM0_XCAGCCore1, bMaskByte0);
 643        pHalData->DefaultInitialGain[3] = (u8)PHY_QueryBBReg(Adapter, rOFDM0_XDAGCCore1, bMaskByte0);
 644
 645        /*  read framesync */
 646        pHalData->framesync = (u8)PHY_QueryBBReg(Adapter, rOFDM0_RxDetector3, bMaskByte0);
 647        pHalData->framesyncC34 = PHY_QueryBBReg(Adapter, rOFDM0_RxDetector2, bMaskDWord);
 648}
 649
 650/*  */
 651/*      Description: */
 652/*              Map dBm into Tx power index according to */
 653/*              current HW model, for example, RF and PA, and */
 654/*              current wireless mode. */
 655/*      By Bruce, 2008-01-29. */
 656/*  */
 657static  u8 phy_DbmToTxPwrIdx(struct adapter *Adapter, enum wireless_mode WirelessMode, int PowerInDbm)
 658{
 659        u8 TxPwrIdx = 0;
 660        int                             Offset = 0;
 661
 662        /*  */
 663        /*  Tested by MP, we found that CCK Index 0 equals to 8dbm, OFDM legacy equals to */
 664        /*  3dbm, and OFDM HT equals to 0dbm respectively. */
 665        /*  Note: */
 666        /*      The mapping may be different by different NICs. Do not use this formula for what needs accurate result. */
 667        /*  By Bruce, 2008-01-29. */
 668        /*  */
 669        switch (WirelessMode) {
 670        case WIRELESS_MODE_B:
 671                Offset = -7;
 672                break;
 673
 674        case WIRELESS_MODE_G:
 675        case WIRELESS_MODE_N_24G:
 676        default:
 677                Offset = -8;
 678                break;
 679        }
 680
 681        if ((PowerInDbm - Offset) > 0)
 682                TxPwrIdx = (u8)((PowerInDbm - Offset) * 2);
 683        else
 684                TxPwrIdx = 0;
 685
 686        /*  Tx Power Index is too large. */
 687        if (TxPwrIdx > MAX_TXPWR_IDX_NMODE_92S)
 688                TxPwrIdx = MAX_TXPWR_IDX_NMODE_92S;
 689
 690        return TxPwrIdx;
 691}
 692
 693/*  */
 694/*      Description: */
 695/*              Map Tx power index into dBm according to */
 696/*              current HW model, for example, RF and PA, and */
 697/*              current wireless mode. */
 698/*      By Bruce, 2008-01-29. */
 699/*  */
 700static int phy_TxPwrIdxToDbm(struct adapter *Adapter, enum wireless_mode WirelessMode, u8 TxPwrIdx)
 701{
 702        int                             Offset = 0;
 703        int                             PwrOutDbm = 0;
 704
 705        /*  */
 706        /*  Tested by MP, we found that CCK Index 0 equals to -7dbm, OFDM legacy equals to -8dbm. */
 707        /*  Note: */
 708        /*      The mapping may be different by different NICs. Do not use this formula for what needs accurate result. */
 709        /*  By Bruce, 2008-01-29. */
 710        /*  */
 711        switch (WirelessMode) {
 712        case WIRELESS_MODE_B:
 713                Offset = -7;
 714                break;
 715        case WIRELESS_MODE_G:
 716        case WIRELESS_MODE_N_24G:
 717        default:
 718                Offset = -8;
 719                break;
 720        }
 721
 722        PwrOutDbm = TxPwrIdx / 2 + Offset; /*  Discard the decimal part. */
 723
 724        return PwrOutDbm;
 725}
 726
 727/*-----------------------------------------------------------------------------
 728 * Function:    GetTxPowerLevel8190()
 729 *
 730 * Overview:    This function is export to "common" moudule
 731 *
 732 * Input:       struct adapter *Adapter
 733 *                      psByte                  Power Level
 734 *
 735 * Output:      NONE
 736 *
 737 * Return:      NONE
 738 *
 739 *---------------------------------------------------------------------------*/
 740void PHY_GetTxPowerLevel8188E(struct adapter *Adapter, u32 *powerlevel)
 741{
 742        struct hal_data_8188e   *pHalData = GET_HAL_DATA(Adapter);
 743        u8 TxPwrLevel = 0;
 744        int                     TxPwrDbm;
 745
 746        /*  */
 747        /*  Because the Tx power indexes are different, we report the maximum of them to */
 748        /*  meet the CCX TPC request. By Bruce, 2008-01-31. */
 749        /*  */
 750
 751        /*  CCK */
 752        TxPwrLevel = pHalData->CurrentCckTxPwrIdx;
 753        TxPwrDbm = phy_TxPwrIdxToDbm(Adapter, WIRELESS_MODE_B, TxPwrLevel);
 754
 755        /*  Legacy OFDM */
 756        TxPwrLevel = pHalData->CurrentOfdm24GTxPwrIdx + pHalData->LegacyHTTxPowerDiff;
 757
 758        /*  Compare with Legacy OFDM Tx power. */
 759        if (phy_TxPwrIdxToDbm(Adapter, WIRELESS_MODE_G, TxPwrLevel) > TxPwrDbm)
 760                TxPwrDbm = phy_TxPwrIdxToDbm(Adapter, WIRELESS_MODE_G, TxPwrLevel);
 761
 762        /*  HT OFDM */
 763        TxPwrLevel = pHalData->CurrentOfdm24GTxPwrIdx;
 764
 765        /*  Compare with HT OFDM Tx power. */
 766        if (phy_TxPwrIdxToDbm(Adapter, WIRELESS_MODE_N_24G, TxPwrLevel) > TxPwrDbm)
 767                TxPwrDbm = phy_TxPwrIdxToDbm(Adapter, WIRELESS_MODE_N_24G, TxPwrLevel);
 768
 769        *powerlevel = TxPwrDbm;
 770}
 771
 772static void getTxPowerIndex88E(struct adapter *Adapter, u8 channel, u8 *cckPowerLevel,
 773                               u8 *ofdmPowerLevel, u8 *BW20PowerLevel,
 774                               u8 *BW40PowerLevel)
 775{
 776        struct hal_data_8188e *pHalData = GET_HAL_DATA(Adapter);
 777        u8 index = (channel - 1);
 778        u8 TxCount = 0, path_nums;
 779
 780        if ((RF_1T2R == pHalData->rf_type) || (RF_1T1R == pHalData->rf_type))
 781                path_nums = 1;
 782        else
 783                path_nums = 2;
 784
 785        for (TxCount = 0; TxCount < path_nums; TxCount++) {
 786                if (TxCount == RF_PATH_A) {
 787                        /*  1. CCK */
 788                        cckPowerLevel[TxCount]  = pHalData->Index24G_CCK_Base[TxCount][index];
 789                        /* 2. OFDM */
 790                        ofdmPowerLevel[TxCount] = pHalData->Index24G_BW40_Base[RF_PATH_A][index] +
 791                                pHalData->OFDM_24G_Diff[TxCount][RF_PATH_A];
 792                        /*  1. BW20 */
 793                        BW20PowerLevel[TxCount] = pHalData->Index24G_BW40_Base[RF_PATH_A][index] +
 794                                pHalData->BW20_24G_Diff[TxCount][RF_PATH_A];
 795                        /* 2. BW40 */
 796                        BW40PowerLevel[TxCount] = pHalData->Index24G_BW40_Base[TxCount][index];
 797                } else if (TxCount == RF_PATH_B) {
 798                        /*  1. CCK */
 799                        cckPowerLevel[TxCount]  = pHalData->Index24G_CCK_Base[TxCount][index];
 800                        /* 2. OFDM */
 801                        ofdmPowerLevel[TxCount] = pHalData->Index24G_BW40_Base[RF_PATH_A][index] +
 802                        pHalData->BW20_24G_Diff[RF_PATH_A][index] +
 803                        pHalData->BW20_24G_Diff[TxCount][index];
 804                        /*  1. BW20 */
 805                        BW20PowerLevel[TxCount] = pHalData->Index24G_BW40_Base[RF_PATH_A][index] +
 806                        pHalData->BW20_24G_Diff[TxCount][RF_PATH_A] +
 807                        pHalData->BW20_24G_Diff[TxCount][index];
 808                        /* 2. BW40 */
 809                        BW40PowerLevel[TxCount] = pHalData->Index24G_BW40_Base[TxCount][index];
 810                } else if (TxCount == RF_PATH_C) {
 811                        /*  1. CCK */
 812                        cckPowerLevel[TxCount]  = pHalData->Index24G_CCK_Base[TxCount][index];
 813                        /* 2. OFDM */
 814                        ofdmPowerLevel[TxCount] = pHalData->Index24G_BW40_Base[RF_PATH_A][index] +
 815                        pHalData->BW20_24G_Diff[RF_PATH_A][index] +
 816                        pHalData->BW20_24G_Diff[RF_PATH_B][index] +
 817                        pHalData->BW20_24G_Diff[TxCount][index];
 818                        /*  1. BW20 */
 819                        BW20PowerLevel[TxCount] = pHalData->Index24G_BW40_Base[RF_PATH_A][index] +
 820                        pHalData->BW20_24G_Diff[RF_PATH_A][index] +
 821                        pHalData->BW20_24G_Diff[RF_PATH_B][index] +
 822                        pHalData->BW20_24G_Diff[TxCount][index];
 823                        /* 2. BW40 */
 824                        BW40PowerLevel[TxCount] = pHalData->Index24G_BW40_Base[TxCount][index];
 825                } else if (TxCount == RF_PATH_D) {
 826                        /*  1. CCK */
 827                        cckPowerLevel[TxCount]  = pHalData->Index24G_CCK_Base[TxCount][index];
 828                        /* 2. OFDM */
 829                        ofdmPowerLevel[TxCount] = pHalData->Index24G_BW40_Base[RF_PATH_A][index] +
 830                        pHalData->BW20_24G_Diff[RF_PATH_A][index] +
 831                        pHalData->BW20_24G_Diff[RF_PATH_B][index] +
 832                        pHalData->BW20_24G_Diff[RF_PATH_C][index] +
 833                        pHalData->BW20_24G_Diff[TxCount][index];
 834
 835                        /*  1. BW20 */
 836                        BW20PowerLevel[TxCount] = pHalData->Index24G_BW40_Base[RF_PATH_A][index] +
 837                        pHalData->BW20_24G_Diff[RF_PATH_A][index] +
 838                        pHalData->BW20_24G_Diff[RF_PATH_B][index] +
 839                        pHalData->BW20_24G_Diff[RF_PATH_C][index] +
 840                        pHalData->BW20_24G_Diff[TxCount][index];
 841
 842                        /* 2. BW40 */
 843                        BW40PowerLevel[TxCount] = pHalData->Index24G_BW40_Base[TxCount][index];
 844                }
 845        }
 846}
 847
 848static void phy_PowerIndexCheck88E(struct adapter *Adapter, u8 channel, u8 *cckPowerLevel,
 849                                   u8 *ofdmPowerLevel, u8 *BW20PowerLevel, u8 *BW40PowerLevel)
 850{
 851        struct hal_data_8188e           *pHalData = GET_HAL_DATA(Adapter);
 852
 853        pHalData->CurrentCckTxPwrIdx = cckPowerLevel[0];
 854        pHalData->CurrentOfdm24GTxPwrIdx = ofdmPowerLevel[0];
 855        pHalData->CurrentBW2024GTxPwrIdx = BW20PowerLevel[0];
 856        pHalData->CurrentBW4024GTxPwrIdx = BW40PowerLevel[0];
 857}
 858
 859/*-----------------------------------------------------------------------------
 860 * Function:    SetTxPowerLevel8190()
 861 *
 862 * Overview:    This function is export to "HalCommon" moudule
 863 *                      We must consider RF path later!!!!!!!
 864 *
 865 * Input:       struct adapter *Adapter
 866 *                      u8              channel
 867 *
 868 * Output:      NONE
 869 *
 870 * Return:      NONE
 871 *      2008/11/04      MHC             We remove EEPROM_93C56.
 872 *                                              We need to move CCX relative code to independet file.
 873 *      2009/01/21      MHC             Support new EEPROM format from SD3 requirement.
 874 *
 875 *---------------------------------------------------------------------------*/
 876void
 877PHY_SetTxPowerLevel8188E(
 878                struct adapter *Adapter,
 879                u8 channel
 880        )
 881{
 882        u8 cckPowerLevel[MAX_TX_COUNT] = {0};
 883        u8 ofdmPowerLevel[MAX_TX_COUNT] = {0};/*  [0]:RF-A, [1]:RF-B */
 884        u8 BW20PowerLevel[MAX_TX_COUNT] = {0};
 885        u8 BW40PowerLevel[MAX_TX_COUNT] = {0};
 886
 887        getTxPowerIndex88E(Adapter, channel, &cckPowerLevel[0], &ofdmPowerLevel[0], &BW20PowerLevel[0], &BW40PowerLevel[0]);
 888
 889        phy_PowerIndexCheck88E(Adapter, channel, &cckPowerLevel[0], &ofdmPowerLevel[0], &BW20PowerLevel[0], &BW40PowerLevel[0]);
 890
 891        rtl8188e_PHY_RF6052SetCckTxPower(Adapter, &cckPowerLevel[0]);
 892        rtl8188e_PHY_RF6052SetOFDMTxPower(Adapter, &ofdmPowerLevel[0], &BW20PowerLevel[0], &BW40PowerLevel[0], channel);
 893}
 894
 895/*  */
 896/*      Description: */
 897/*              Update transmit power level of all channel supported. */
 898/*  */
 899/*      TODO: */
 900/*              A mode. */
 901/*      By Bruce, 2008-02-04. */
 902/*  */
 903bool
 904PHY_UpdateTxPowerDbm8188E(
 905                struct adapter *Adapter,
 906                int             powerInDbm
 907        )
 908{
 909        struct hal_data_8188e   *pHalData = GET_HAL_DATA(Adapter);
 910        u8 idx;
 911        u8 rf_path;
 912
 913        /*  TODO: A mode Tx power. */
 914        u8 CckTxPwrIdx = phy_DbmToTxPwrIdx(Adapter, WIRELESS_MODE_B, powerInDbm);
 915        u8 OfdmTxPwrIdx = phy_DbmToTxPwrIdx(Adapter, WIRELESS_MODE_N_24G, powerInDbm);
 916
 917        if (OfdmTxPwrIdx - pHalData->LegacyHTTxPowerDiff > 0)
 918                OfdmTxPwrIdx -= pHalData->LegacyHTTxPowerDiff;
 919        else
 920                OfdmTxPwrIdx = 0;
 921
 922        for (idx = 0; idx < 14; idx++) {
 923                for (rf_path = 0; rf_path < 2; rf_path++) {
 924                        pHalData->TxPwrLevelCck[rf_path][idx] = CckTxPwrIdx;
 925                        pHalData->TxPwrLevelHT40_1S[rf_path][idx] =
 926                        pHalData->TxPwrLevelHT40_2S[rf_path][idx] = OfdmTxPwrIdx;
 927                }
 928        }
 929        return true;
 930}
 931
 932void
 933PHY_ScanOperationBackup8188E(
 934                struct adapter *Adapter,
 935                u8 Operation
 936        )
 937{
 938}
 939
 940/*-----------------------------------------------------------------------------
 941 * Function:    PHY_SetBWModeCallback8192C()
 942 *
 943 * Overview:    Timer callback function for SetSetBWMode
 944 *
 945 * Input:               PRT_TIMER               pTimer
 946 *
 947 * Output:      NONE
 948 *
 949 * Return:      NONE
 950 *
 951 * Note:                (1) We do not take j mode into consideration now
 952 *                      (2) Will two workitem of "switch channel" and "switch channel bandwidth" run
 953 *                           concurrently?
 954 *---------------------------------------------------------------------------*/
 955static void
 956_PHY_SetBWMode92C(
 957                struct adapter *Adapter
 958)
 959{
 960        struct hal_data_8188e *pHalData = GET_HAL_DATA(Adapter);
 961        u8 regBwOpMode;
 962        u8 regRRSR_RSC;
 963
 964        if (pHalData->rf_chip == RF_PSEUDO_11N)
 965                return;
 966
 967        /*  There is no 40MHz mode in RF_8225. */
 968        if (pHalData->rf_chip == RF_8225)
 969                return;
 970
 971        if (Adapter->bDriverStopped)
 972                return;
 973
 974        /* 3 */
 975        /* 3<1>Set MAC register */
 976        /* 3 */
 977
 978        regBwOpMode = rtw_read8(Adapter, REG_BWOPMODE);
 979        regRRSR_RSC = rtw_read8(Adapter, REG_RRSR + 2);
 980
 981        switch (pHalData->CurrentChannelBW) {
 982        case HT_CHANNEL_WIDTH_20:
 983                regBwOpMode |= BW_OPMODE_20MHZ;
 984                /*  2007/02/07 Mark by Emily because we have not verify whether this register works */
 985                rtw_write8(Adapter, REG_BWOPMODE, regBwOpMode);
 986                break;
 987        case HT_CHANNEL_WIDTH_40:
 988                regBwOpMode &= ~BW_OPMODE_20MHZ;
 989                /*  2007/02/07 Mark by Emily because we have not verify whether this register works */
 990                rtw_write8(Adapter, REG_BWOPMODE, regBwOpMode);
 991                regRRSR_RSC = (regRRSR_RSC & 0x90) | (pHalData->nCur40MhzPrimeSC << 5);
 992                rtw_write8(Adapter, REG_RRSR + 2, regRRSR_RSC);
 993                break;
 994        default:
 995                break;
 996        }
 997
 998        /* 3  */
 999        /* 3 <2>Set PHY related register */
1000        /* 3 */
1001        switch (pHalData->CurrentChannelBW) {
1002        /* 20 MHz channel*/
1003        case HT_CHANNEL_WIDTH_20:
1004                PHY_SetBBReg(Adapter, rFPGA0_RFMOD, bRFMOD, 0x0);
1005                PHY_SetBBReg(Adapter, rFPGA1_RFMOD, bRFMOD, 0x0);
1006                break;
1007        /* 40 MHz channel*/
1008        case HT_CHANNEL_WIDTH_40:
1009                PHY_SetBBReg(Adapter, rFPGA0_RFMOD, bRFMOD, 0x1);
1010                PHY_SetBBReg(Adapter, rFPGA1_RFMOD, bRFMOD, 0x1);
1011                /*  Set Control channel to upper or lower. These settings are required only for 40MHz */
1012                PHY_SetBBReg(Adapter, rCCK0_System, bCCKSideBand, (pHalData->nCur40MhzPrimeSC >> 1));
1013                PHY_SetBBReg(Adapter, rOFDM1_LSTF, 0xC00, pHalData->nCur40MhzPrimeSC);
1014                PHY_SetBBReg(Adapter, 0x818, (BIT(26) | BIT(27)),
1015                             (pHalData->nCur40MhzPrimeSC == HAL_PRIME_CHNL_OFFSET_LOWER) ? 2 : 1);
1016                break;
1017        default:
1018                break;
1019        }
1020        /* Skip over setting of J-mode in BB register here. Default value is "None J mode". Emily 20070315 */
1021
1022        /* 3<3>Set RF related register */
1023        switch (pHalData->rf_chip) {
1024        case RF_8225:
1025                break;
1026        case RF_8256:
1027                /*  Please implement this function in Hal8190PciPhy8256.c */
1028                break;
1029        case RF_PSEUDO_11N:
1030                break;
1031        case RF_6052:
1032                rtl8188e_PHY_RF6052SetBandwidth(Adapter, pHalData->CurrentChannelBW);
1033                break;
1034        default:
1035                break;
1036        }
1037}
1038
1039 /*-----------------------------------------------------------------------------
1040 * Function:   SetBWMode8190Pci()
1041 *
1042 * Overview:  This function is export to "HalCommon" moudule
1043 *
1044 * Input:               struct adapter *Adapter
1045 *                      enum ht_channel_width Bandwidth 20M or 40M
1046 *
1047 * Output:      NONE
1048 *
1049 * Return:      NONE
1050 *
1051 * Note:                We do not take j mode into consideration now
1052 *---------------------------------------------------------------------------*/
1053void PHY_SetBWMode8188E(struct adapter *Adapter, enum ht_channel_width Bandwidth,       /*  20M or 40M */
1054                        unsigned char   Offset)         /*  Upper, Lower, or Don't care */
1055{
1056        struct hal_data_8188e   *pHalData = GET_HAL_DATA(Adapter);
1057        enum ht_channel_width tmpBW = pHalData->CurrentChannelBW;
1058
1059        pHalData->CurrentChannelBW = Bandwidth;
1060
1061        pHalData->nCur40MhzPrimeSC = Offset;
1062
1063        if ((!Adapter->bDriverStopped) && (!Adapter->bSurpriseRemoved))
1064                _PHY_SetBWMode92C(Adapter);
1065        else
1066                pHalData->CurrentChannelBW = tmpBW;
1067}
1068
1069static void _PHY_SwChnl8192C(struct adapter *Adapter, u8 channel)
1070{
1071        u8 eRFPath;
1072        u32 param1, param2;
1073        struct hal_data_8188e   *pHalData = GET_HAL_DATA(Adapter);
1074
1075        if (Adapter->bNotifyChannelChange)
1076                DBG_88E("[%s] ch = %d\n", __func__, channel);
1077
1078        /* s1. pre common command - CmdID_SetTxPowerLevel */
1079        PHY_SetTxPowerLevel8188E(Adapter, channel);
1080
1081        /* s2. RF dependent command - CmdID_RF_WriteReg, param1=RF_CHNLBW, param2=channel */
1082        param1 = RF_CHNLBW;
1083        param2 = channel;
1084        for (eRFPath = 0; eRFPath < pHalData->NumTotalRFPath; eRFPath++) {
1085                pHalData->RfRegChnlVal[eRFPath] = ((pHalData->RfRegChnlVal[eRFPath] & 0xfffffc00) | param2);
1086                PHY_SetRFReg(Adapter, (enum rf_radio_path)eRFPath, param1, bRFRegOffsetMask, pHalData->RfRegChnlVal[eRFPath]);
1087        }
1088}
1089
1090void PHY_SwChnl8188E(struct adapter *Adapter, u8 channel)
1091{
1092        /*  Call after initialization */
1093        struct hal_data_8188e   *pHalData = GET_HAL_DATA(Adapter);
1094
1095        if (pHalData->rf_chip == RF_PSEUDO_11N)
1096                return;         /* return immediately if it is peudo-phy */
1097
1098        if (channel == 0)
1099                channel = 1;
1100
1101        if ((!Adapter->bDriverStopped) && (!Adapter->bSurpriseRemoved)) {
1102                pHalData->CurrentChannel = channel;
1103                _PHY_SwChnl8192C(Adapter, channel);
1104        }
1105}
1106