OSDN Git Service

cd4f90aeb6ad7cfac1085530d8b16639311a5b88
[android-x86/kernel.git] / drivers / staging / rtl8723bs / hal / HalHWImg8723B_MAC.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
16
17 #include "odm_precomp.h"
18
19 static bool
20 CheckPositive(
21     PDM_ODM_T     pDM_Odm,
22     const u32  Condition1,
23     const u32  Condition2
24    )
25 {
26         u8    _BoardType = ((pDM_Odm->BoardType & BIT4) >> 4) << 0 | /*  _GLNA */
27                            ((pDM_Odm->BoardType & BIT3) >> 3) << 1 | /*  _GPA */
28                            ((pDM_Odm->BoardType & BIT7) >> 7) << 2 | /*  _ALNA */
29                            ((pDM_Odm->BoardType & BIT6) >> 6) << 3 | /*  _APA */
30                            ((pDM_Odm->BoardType & BIT2) >> 2) << 4;  /*  _BT */
31
32         u32   cond1   = Condition1, cond2 = Condition2;
33         u32    driver1 = pDM_Odm->CutVersion       << 24 |
34                                 pDM_Odm->SupportPlatform  << 16 |
35                                 pDM_Odm->PackageType      << 12 |
36                                 pDM_Odm->SupportInterface << 8  |
37                                 _BoardType;
38
39         u32    driver2 = pDM_Odm->TypeGLNA <<  0 |
40                                 pDM_Odm->TypeGPA  <<  8 |
41                                 pDM_Odm->TypeALNA << 16 |
42                                 pDM_Odm->TypeAPA  << 24;
43
44         ODM_RT_TRACE(pDM_Odm, ODM_COMP_INIT, ODM_DBG_TRACE,
45                 ("===> [8812A] CheckPositive (cond1, cond2) = (0x%X 0x%X)\n", cond1, cond2));
46         ODM_RT_TRACE(pDM_Odm, ODM_COMP_INIT, ODM_DBG_TRACE,
47                 ("===> [8812A] CheckPositive (driver1, driver2) = (0x%X 0x%X)\n", driver1, driver2));
48
49         ODM_RT_TRACE(pDM_Odm, ODM_COMP_INIT, ODM_DBG_TRACE,
50                 ("      (Platform, Interface) = (0x%X, 0x%X)\n", pDM_Odm->SupportPlatform, pDM_Odm->SupportInterface));
51         ODM_RT_TRACE(pDM_Odm, ODM_COMP_INIT, ODM_DBG_TRACE,
52                 ("      (Board, Package) = (0x%X, 0x%X)\n", pDM_Odm->BoardType, pDM_Odm->PackageType));
53
54
55         /*  Value Defined Check =============== */
56         /* QFN Type [15:12] and Cut Version [27:24] need to do value check */
57
58         if (((cond1 & 0x0000F000) != 0) && ((cond1 & 0x0000F000) != (driver1 & 0x0000F000)))
59                 return false;
60         if (((cond1 & 0x0F000000) != 0) && ((cond1 & 0x0F000000) != (driver1 & 0x0F000000)))
61                 return false;
62
63         /*  Bit Defined Check ================ */
64     /*  We don't care [31:28] and [23:20] */
65     /*  */
66         cond1   &= 0x000F0FFF;
67         driver1 &= 0x000F0FFF;
68
69         if ((cond1 & driver1) == cond1) {
70                 u32 bitMask = 0;
71                 if ((cond1 & 0x0F) == 0) /*  BoardType is DONTCARE */
72                         return true;
73
74                 if ((cond1 & BIT0) != 0) /* GLNA */
75                         bitMask |= 0x000000FF;
76                 if ((cond1 & BIT1) != 0) /* GPA */
77                         bitMask |= 0x0000FF00;
78                 if ((cond1 & BIT2) != 0) /* ALNA */
79                         bitMask |= 0x00FF0000;
80                 if ((cond1 & BIT3) != 0) /* APA */
81                         bitMask |= 0xFF000000;
82
83                 if ((cond2 & bitMask) == (driver2 & bitMask)) /*  BoardType of each RF path is matched */
84                         return true;
85         }
86         return false;
87 }
88 static bool
89 CheckNegative(
90     PDM_ODM_T     pDM_Odm,
91     const u32  Condition1,
92     const u32  Condition2
93    )
94 {
95     return true;
96 }
97
98 /******************************************************************************
99 *                           MAC_REG.TXT
100 ******************************************************************************/
101
102 static u32 Array_MP_8723B_MAC_REG[] = {
103                 0x02F, 0x00000030,
104                 0x035, 0x00000000,
105                 0x039, 0x00000008,
106                 0x04E, 0x000000E0,
107                 0x064, 0x00000000,
108                 0x067, 0x00000020,
109                 0x428, 0x0000000A,
110                 0x429, 0x00000010,
111                 0x430, 0x00000000,
112                 0x431, 0x00000000,
113                 0x432, 0x00000000,
114                 0x433, 0x00000001,
115                 0x434, 0x00000004,
116                 0x435, 0x00000005,
117                 0x436, 0x00000007,
118                 0x437, 0x00000008,
119                 0x43C, 0x00000004,
120                 0x43D, 0x00000005,
121                 0x43E, 0x00000007,
122                 0x43F, 0x00000008,
123                 0x440, 0x0000005D,
124                 0x441, 0x00000001,
125                 0x442, 0x00000000,
126                 0x444, 0x00000010,
127                 0x445, 0x00000000,
128                 0x446, 0x00000000,
129                 0x447, 0x00000000,
130                 0x448, 0x00000000,
131                 0x449, 0x000000F0,
132                 0x44A, 0x0000000F,
133                 0x44B, 0x0000003E,
134                 0x44C, 0x00000010,
135                 0x44D, 0x00000000,
136                 0x44E, 0x00000000,
137                 0x44F, 0x00000000,
138                 0x450, 0x00000000,
139                 0x451, 0x000000F0,
140                 0x452, 0x0000000F,
141                 0x453, 0x00000000,
142                 0x456, 0x0000005E,
143                 0x460, 0x00000066,
144                 0x461, 0x00000066,
145                 0x4C8, 0x000000FF,
146                 0x4C9, 0x00000008,
147                 0x4CC, 0x000000FF,
148                 0x4CD, 0x000000FF,
149                 0x4CE, 0x00000001,
150                 0x500, 0x00000026,
151                 0x501, 0x000000A2,
152                 0x502, 0x0000002F,
153                 0x503, 0x00000000,
154                 0x504, 0x00000028,
155                 0x505, 0x000000A3,
156                 0x506, 0x0000005E,
157                 0x507, 0x00000000,
158                 0x508, 0x0000002B,
159                 0x509, 0x000000A4,
160                 0x50A, 0x0000005E,
161                 0x50B, 0x00000000,
162                 0x50C, 0x0000004F,
163                 0x50D, 0x000000A4,
164                 0x50E, 0x00000000,
165                 0x50F, 0x00000000,
166                 0x512, 0x0000001C,
167                 0x514, 0x0000000A,
168                 0x516, 0x0000000A,
169                 0x525, 0x0000004F,
170                 0x550, 0x00000010,
171                 0x551, 0x00000010,
172                 0x559, 0x00000002,
173                 0x55C, 0x00000050,
174                 0x55D, 0x000000FF,
175                 0x605, 0x00000030,
176                 0x608, 0x0000000E,
177                 0x609, 0x0000002A,
178                 0x620, 0x000000FF,
179                 0x621, 0x000000FF,
180                 0x622, 0x000000FF,
181                 0x623, 0x000000FF,
182                 0x624, 0x000000FF,
183                 0x625, 0x000000FF,
184                 0x626, 0x000000FF,
185                 0x627, 0x000000FF,
186                 0x638, 0x00000050,
187                 0x63C, 0x0000000A,
188                 0x63D, 0x0000000A,
189                 0x63E, 0x0000000E,
190                 0x63F, 0x0000000E,
191                 0x640, 0x00000040,
192                 0x642, 0x00000040,
193                 0x643, 0x00000000,
194                 0x652, 0x000000C8,
195                 0x66E, 0x00000005,
196                 0x700, 0x00000021,
197                 0x701, 0x00000043,
198                 0x702, 0x00000065,
199                 0x703, 0x00000087,
200                 0x708, 0x00000021,
201                 0x709, 0x00000043,
202                 0x70A, 0x00000065,
203                 0x70B, 0x00000087,
204                 0x765, 0x00000018,
205                 0x76E, 0x00000004,
206
207 };
208
209 void
210 ODM_ReadAndConfig_MP_8723B_MAC_REG(
211         PDM_ODM_T  pDM_Odm
212         )
213 {
214     u32     i         = 0;
215     u32     ArrayLen    = sizeof(Array_MP_8723B_MAC_REG)/sizeof(u32);
216     u32 *    Array       = Array_MP_8723B_MAC_REG;
217
218     ODM_RT_TRACE(pDM_Odm, ODM_COMP_INIT, ODM_DBG_LOUD, ("===> ODM_ReadAndConfig_MP_8723B_MAC_REG\n"));
219
220     for (i = 0; i < ArrayLen; i += 2)
221     {
222         u32 v1 = Array[i];
223         u32 v2 = Array[i+1];
224
225         /*  This (offset, data) pair doesn't care the condition. */
226         if (v1 < 0x40000000)
227         {
228            odm_ConfigMAC_8723B(pDM_Odm, v1, (u8)v2);
229            continue;
230         }
231         else
232         {   /*  This line is the beginning of branch. */
233             bool bMatched = true;
234             u8  cCond  = (u8)((v1 & (BIT29|BIT28)) >> 28);
235
236             if (cCond == COND_ELSE) { /*  ELSE, ENDIF */
237                 bMatched = true;
238                 READ_NEXT_PAIR(v1, v2, i);
239             } else if (! CheckPositive(pDM_Odm, v1, v2)) {
240                 bMatched = false;
241                 READ_NEXT_PAIR(v1, v2, i);
242                 READ_NEXT_PAIR(v1, v2, i);
243             } else {
244                 READ_NEXT_PAIR(v1, v2, i);
245                 if (! CheckNegative(pDM_Odm, v1, v2))
246                     bMatched = false;
247                 else
248                     bMatched = true;
249                 READ_NEXT_PAIR(v1, v2, i);
250             }
251
252             if (bMatched == false)
253             {   /*  Condition isn't matched. Discard the following (offset, data) pairs. */
254                 while (v1 < 0x40000000 && i < ArrayLen -2)
255                     READ_NEXT_PAIR(v1, v2, i);
256
257                 i -= 2; /*  prevent from for-loop += 2 */
258             }
259             else /*  Configure matched pairs and skip to end of if-else. */
260             {
261                 while (v1 < 0x40000000 && i < ArrayLen-2) {
262                     odm_ConfigMAC_8723B(pDM_Odm, v1, (u8)v2);
263                     READ_NEXT_PAIR(v1, v2, i);
264                 }
265
266                 /*  Keeps reading until ENDIF. */
267                 cCond = (u8)((v1 & (BIT29|BIT28)) >> 28);
268                 while (cCond != COND_ENDIF && i < ArrayLen-2) {
269                     READ_NEXT_PAIR(v1, v2, i);
270                     cCond = (u8)((v1 & (BIT29|BIT28)) >> 28);
271                 }
272             }
273         }
274     }
275 }