OSDN Git Service

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