1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 ******************************************************************************/
17 #include <drv_types.h>
20 * Function: PHY_CalculateBitShift
22 * OverView: Get shifted position of the BitMask
28 * Return: u32 Return the shift bit bit position of the mask
30 u32 PHY_CalculateBitShift(u32 BitMask)
34 for (i = 0; i <= 31; i++) {
35 if (((BitMask>>i) & 0x1) == 1)
44 /* ==> RF shadow Operation API Code Section!!! */
46 /*-----------------------------------------------------------------------------
47 * Function: PHY_RFShadowRead
50 * PHY_RFShadowRecorver
51 * PHY_RFShadowCompareAll
52 * PHY_RFShadowRecorverAll
53 * PHY_RFShadowCompareFlagSet
54 * PHY_RFShadowRecorverFlagSet
56 * Overview: When we set RF register, we must write shadow at first.
57 * When we are running, we must compare shadow abd locate error addr.
58 * Decide to recorver or not.
68 * 11/20/2008 MHC Create Version 0.
70 *---------------------------------------------------------------------------*/
71 u32 PHY_RFShadowRead(IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset)
73 return RF_Shadow[eRFPath][Offset].Value;
75 } /* PHY_RFShadowRead */
78 void PHY_RFShadowWrite(
79 IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset, IN u32 Data
82 RF_Shadow[eRFPath][Offset].Value = (Data & bRFRegOffsetMask);
83 RF_Shadow[eRFPath][Offset].Driver_Write = true;
85 } /* PHY_RFShadowWrite */
88 bool PHY_RFShadowCompare(IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset)
91 /* Check if we need to check the register */
92 if (RF_Shadow[eRFPath][Offset].Compare == true) {
93 reg = rtw_hal_read_rfreg(Adapter, eRFPath, Offset, bRFRegOffsetMask);
94 /* Compare shadow and real rf register for 20bits!! */
95 if (RF_Shadow[eRFPath][Offset].Value != reg) {
96 /* Locate error position. */
97 RF_Shadow[eRFPath][Offset].ErrorOrNot = true;
98 /* RT_TRACE(COMP_INIT, DBG_LOUD, */
99 /* PHY_RFShadowCompare RF-%d Addr%02lx Err = %05lx\n", */
100 /* eRFPath, Offset, reg)); */
102 return RF_Shadow[eRFPath][Offset].ErrorOrNot;
105 } /* PHY_RFShadowCompare */
108 void PHY_RFShadowRecorver(IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset)
110 /* Check if the address is error */
111 if (RF_Shadow[eRFPath][Offset].ErrorOrNot == true) {
112 /* Check if we need to recorver the register. */
113 if (RF_Shadow[eRFPath][Offset].Recorver == true) {
114 rtw_hal_write_rfreg(Adapter, eRFPath, Offset, bRFRegOffsetMask,
115 RF_Shadow[eRFPath][Offset].Value);
116 /* RT_TRACE(COMP_INIT, DBG_LOUD, */
117 /* PHY_RFShadowRecorver RF-%d Addr%02lx=%05lx", */
118 /* eRFPath, Offset, RF_Shadow[eRFPath][Offset].Value)); */
122 } /* PHY_RFShadowRecorver */
125 void PHY_RFShadowCompareAll(IN PADAPTER Adapter)
128 u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
130 for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
131 for (Offset = 0; Offset < maxReg; Offset++) {
132 PHY_RFShadowCompare(Adapter, eRFPath, Offset);
136 } /* PHY_RFShadowCompareAll */
139 void PHY_RFShadowRecorverAll(IN PADAPTER Adapter)
142 u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
144 for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
145 for (Offset = 0; Offset < maxReg; Offset++) {
146 PHY_RFShadowRecorver(Adapter, eRFPath, Offset);
150 } /* PHY_RFShadowRecorverAll */
154 PHY_RFShadowCompareFlagSet(
155 IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset, IN u8 Type
158 /* Set True or False!!! */
159 RF_Shadow[eRFPath][Offset].Compare = Type;
161 } /* PHY_RFShadowCompareFlagSet */
164 void PHY_RFShadowRecorverFlagSet(
165 IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset, IN u8 Type
168 /* Set True or False!!! */
169 RF_Shadow[eRFPath][Offset].Recorver = Type;
171 } /* PHY_RFShadowRecorverFlagSet */
174 void PHY_RFShadowCompareFlagSetAll(IN PADAPTER Adapter)
177 u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
179 for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
180 for (Offset = 0; Offset < maxReg; Offset++) {
181 /* 2008/11/20 MH For S3S4 test, we only check reg 26/27 now!!!! */
182 if (Offset != 0x26 && Offset != 0x27)
183 PHY_RFShadowCompareFlagSet(Adapter, eRFPath, Offset, false);
185 PHY_RFShadowCompareFlagSet(Adapter, eRFPath, Offset, true);
189 } /* PHY_RFShadowCompareFlagSetAll */
192 void PHY_RFShadowRecorverFlagSetAll(IN PADAPTER Adapter)
195 u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
197 for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
198 for (Offset = 0; Offset < maxReg; Offset++) {
199 /* 2008/11/20 MH For S3S4 test, we only check reg 26/27 now!!!! */
200 if (Offset != 0x26 && Offset != 0x27)
201 PHY_RFShadowRecorverFlagSet(Adapter, eRFPath, Offset, false);
203 PHY_RFShadowRecorverFlagSet(Adapter, eRFPath, Offset, true);
207 } /* PHY_RFShadowCompareFlagSetAll */
209 void PHY_RFShadowRefresh(IN PADAPTER Adapter)
212 u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
214 for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
215 for (Offset = 0; Offset < maxReg; Offset++) {
216 RF_Shadow[eRFPath][Offset].Value = 0;
217 RF_Shadow[eRFPath][Offset].Compare = false;
218 RF_Shadow[eRFPath][Offset].Recorver = false;
219 RF_Shadow[eRFPath][Offset].ErrorOrNot = false;
220 RF_Shadow[eRFPath][Offset].Driver_Write = false;
224 } /* PHY_RFShadowRead */