linux/drivers/staging/rtl8723bs/hal/hal_phy.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2/******************************************************************************
   3 *
   4 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
   5 *
   6 ******************************************************************************/
   7#define _HAL_PHY_C_
   8
   9#include <drv_types.h>
  10
  11/**
  12* Function:     PHY_CalculateBitShift
  13*
  14* OverView:     Get shifted position of the BitMask
  15*
  16* Input:
  17*               u32     BitMask,
  18*
  19* Output:       none
  20* Return:               u32     Return the shift bit bit position of the mask
  21*/
  22u32 PHY_CalculateBitShift(u32 BitMask)
  23{
  24        u32 i;
  25
  26        for (i = 0; i <= 31; i++) {
  27                if (((BitMask>>i) &  0x1) == 1)
  28                        break;
  29        }
  30
  31        return i;
  32}
  33
  34
  35/*  */
  36/*  ==> RF shadow Operation API Code Section!!! */
  37/*  */
  38/*-----------------------------------------------------------------------------
  39 * Function:    PHY_RFShadowRead
  40 *                      PHY_RFShadowWrite
  41 *                      PHY_RFShadowCompare
  42 *                      PHY_RFShadowRecorver
  43 *                      PHY_RFShadowCompareAll
  44 *                      PHY_RFShadowRecorverAll
  45 *                      PHY_RFShadowCompareFlagSet
  46 *                      PHY_RFShadowRecorverFlagSet
  47 *
  48 * Overview:    When we set RF register, we must write shadow at first.
  49 *              When we are running, we must compare shadow abd locate error addr.
  50 *              Decide to recorver or not.
  51 *
  52 * Input:       NONE
  53 *
  54 * Output:      NONE
  55 *
  56 * Return:      NONE
  57 *
  58 * Revised History:
  59 * When                 Who             Remark
  60 * 11/20/2008   MHC             Create Version 0.
  61 *
  62 *---------------------------------------------------------------------------*/
  63u32 PHY_RFShadowRead(IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset)
  64{
  65        return  RF_Shadow[eRFPath][Offset].Value;
  66
  67}       /* PHY_RFShadowRead */
  68
  69
  70void PHY_RFShadowWrite(
  71        IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset, IN u32 Data
  72)
  73{
  74        RF_Shadow[eRFPath][Offset].Value = (Data & bRFRegOffsetMask);
  75        RF_Shadow[eRFPath][Offset].Driver_Write = true;
  76
  77}       /* PHY_RFShadowWrite */
  78
  79
  80bool PHY_RFShadowCompare(IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset)
  81{
  82        u32 reg;
  83        /*  Check if we need to check the register */
  84        if (RF_Shadow[eRFPath][Offset].Compare == true) {
  85                reg = rtw_hal_read_rfreg(Adapter, eRFPath, Offset, bRFRegOffsetMask);
  86                /*  Compare shadow and real rf register for 20bits!! */
  87                if (RF_Shadow[eRFPath][Offset].Value != reg) {
  88                        /*  Locate error position. */
  89                        RF_Shadow[eRFPath][Offset].ErrorOrNot = true;
  90                        /* RT_TRACE(COMP_INIT, DBG_LOUD, */
  91                        /* PHY_RFShadowCompare RF-%d Addr%02lx Err = %05lx\n", */
  92                        /* eRFPath, Offset, reg)); */
  93                }
  94                return RF_Shadow[eRFPath][Offset].ErrorOrNot;
  95        }
  96        return false;
  97}       /* PHY_RFShadowCompare */
  98
  99
 100void PHY_RFShadowRecorver(IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset)
 101{
 102        /*  Check if the address is error */
 103        if (RF_Shadow[eRFPath][Offset].ErrorOrNot == true) {
 104                /*  Check if we need to recorver the register. */
 105                if (RF_Shadow[eRFPath][Offset].Recorver == true) {
 106                        rtw_hal_write_rfreg(Adapter, eRFPath, Offset, bRFRegOffsetMask,
 107                                                        RF_Shadow[eRFPath][Offset].Value);
 108                        /* RT_TRACE(COMP_INIT, DBG_LOUD, */
 109                        /* PHY_RFShadowRecorver RF-%d Addr%02lx=%05lx", */
 110                        /* eRFPath, Offset, RF_Shadow[eRFPath][Offset].Value)); */
 111                }
 112        }
 113
 114}       /* PHY_RFShadowRecorver */
 115
 116
 117void PHY_RFShadowCompareAll(IN PADAPTER Adapter)
 118{
 119        u8 eRFPath = 0;
 120        u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
 121
 122        for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
 123                for (Offset = 0; Offset < maxReg; Offset++) {
 124                        PHY_RFShadowCompare(Adapter, eRFPath, Offset);
 125                }
 126        }
 127
 128}       /* PHY_RFShadowCompareAll */
 129
 130
 131void PHY_RFShadowRecorverAll(IN PADAPTER Adapter)
 132{
 133        u8 eRFPath = 0;
 134        u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
 135
 136        for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
 137                for (Offset = 0; Offset < maxReg; Offset++) {
 138                        PHY_RFShadowRecorver(Adapter, eRFPath, Offset);
 139                }
 140        }
 141
 142}       /* PHY_RFShadowRecorverAll */
 143
 144
 145void
 146PHY_RFShadowCompareFlagSet(
 147        IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset, IN u8 Type
 148)
 149{
 150        /*  Set True or False!!! */
 151        RF_Shadow[eRFPath][Offset].Compare = Type;
 152
 153}       /* PHY_RFShadowCompareFlagSet */
 154
 155
 156void PHY_RFShadowRecorverFlagSet(
 157        IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset, IN u8 Type
 158)
 159{
 160        /*  Set True or False!!! */
 161        RF_Shadow[eRFPath][Offset].Recorver = Type;
 162
 163}       /* PHY_RFShadowRecorverFlagSet */
 164
 165
 166void PHY_RFShadowCompareFlagSetAll(IN PADAPTER Adapter)
 167{
 168        u8 eRFPath = 0;
 169        u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
 170
 171        for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
 172                for (Offset = 0; Offset < maxReg; Offset++) {
 173                        /*  2008/11/20 MH For S3S4 test, we only check reg 26/27 now!!!! */
 174                        if (Offset != 0x26 && Offset != 0x27)
 175                                PHY_RFShadowCompareFlagSet(Adapter, eRFPath, Offset, false);
 176                        else
 177                                PHY_RFShadowCompareFlagSet(Adapter, eRFPath, Offset, true);
 178                }
 179        }
 180
 181}       /* PHY_RFShadowCompareFlagSetAll */
 182
 183
 184void PHY_RFShadowRecorverFlagSetAll(IN PADAPTER Adapter)
 185{
 186        u8 eRFPath = 0;
 187        u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
 188
 189        for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
 190                for (Offset = 0; Offset < maxReg; Offset++) {
 191                        /*  2008/11/20 MH For S3S4 test, we only check reg 26/27 now!!!! */
 192                        if (Offset != 0x26 && Offset != 0x27)
 193                                PHY_RFShadowRecorverFlagSet(Adapter, eRFPath, Offset, false);
 194                        else
 195                                PHY_RFShadowRecorverFlagSet(Adapter, eRFPath, Offset, true);
 196                }
 197        }
 198
 199}       /* PHY_RFShadowCompareFlagSetAll */
 200
 201void PHY_RFShadowRefresh(IN PADAPTER Adapter)
 202{
 203        u8 eRFPath = 0;
 204        u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
 205
 206        for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
 207                for (Offset = 0; Offset < maxReg; Offset++) {
 208                        RF_Shadow[eRFPath][Offset].Value = 0;
 209                        RF_Shadow[eRFPath][Offset].Compare = false;
 210                        RF_Shadow[eRFPath][Offset].Recorver  = false;
 211                        RF_Shadow[eRFPath][Offset].ErrorOrNot = false;
 212                        RF_Shadow[eRFPath][Offset].Driver_Write = false;
 213                }
 214        }
 215
 216}       /* PHY_RFShadowRead */
 217