net: wireless: rockchip_wlan: add rtl8188eu support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8188eu / hal / phydm / rtl8188e / halhwimg8188e_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 * You should have received a copy of the GNU General Public License along with 
15 * this program; if not, write to the Free Software Foundation, Inc., 
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA 
17
18
19 ******************************************************************************/
20
21 /*Image2HeaderVersion: 2.14*/
22 #include "mp_precomp.h"
23 #include "../phydm_precomp.h"
24
25 #if (RTL8188E_SUPPORT == 1)
26 static BOOLEAN
27 CheckPositive(
28         IN  PDM_ODM_T     pDM_Odm,
29         IN  const u4Byte  Condition1,
30         IN  const u4Byte  Condition2,
31         IN      const u4Byte  Condition3,
32         IN      const u4Byte  Condition4
33 )
34 {
35         u1Byte    _BoardType = ((pDM_Odm->BoardType & BIT4) >> 4) << 0 | /* _GLNA*/
36                                 ((pDM_Odm->BoardType & BIT3) >> 3) << 1 | /* _GPA*/ 
37                                 ((pDM_Odm->BoardType & BIT7) >> 7) << 2 | /* _ALNA*/
38                                 ((pDM_Odm->BoardType & BIT6) >> 6) << 3 | /* _APA */
39                                 ((pDM_Odm->BoardType & BIT2) >> 2) << 4;  /* _BT*/  
40
41         u4Byte  cond1   = Condition1, cond2 = Condition2, cond3 = Condition3, cond4 = Condition4;
42         u4Byte    driver1 = pDM_Odm->CutVersion       << 24 | 
43                                 (pDM_Odm->SupportInterface & 0xF0) << 16 | 
44                                 pDM_Odm->SupportPlatform  << 16 | 
45                                 pDM_Odm->PackageType      << 12 | 
46                                 (pDM_Odm->SupportInterface & 0x0F) << 8  |
47                                 _BoardType;
48
49         u4Byte    driver2 = (pDM_Odm->TypeGLNA & 0xFF) <<  0 |  
50                                 (pDM_Odm->TypeGPA & 0xFF)  <<  8 | 
51                                 (pDM_Odm->TypeALNA & 0xFF) << 16 | 
52                                 (pDM_Odm->TypeAPA & 0xFF)  << 24; 
53
54 u4Byte    driver3 = 0;
55
56         u4Byte    driver4 = (pDM_Odm->TypeGLNA & 0xFF00) >>  8 |
57                                 (pDM_Odm->TypeGPA & 0xFF00) |
58                                 (pDM_Odm->TypeALNA & 0xFF00) << 8 |
59                                 (pDM_Odm->TypeAPA & 0xFF00)  << 16;
60
61         ODM_RT_TRACE(pDM_Odm, ODM_COMP_INIT, ODM_DBG_TRACE, 
62         ("===> CheckPositive (cond1, cond2, cond3, cond4) = (0x%X 0x%X 0x%X 0x%X)\n", cond1, cond2, cond3, cond4));
63         ODM_RT_TRACE(pDM_Odm, ODM_COMP_INIT, ODM_DBG_TRACE, 
64         ("===> CheckPositive (driver1, driver2, driver3, driver4) = (0x%X 0x%X 0x%X 0x%X)\n", driver1, driver2, driver3, driver4));
65
66         ODM_RT_TRACE(pDM_Odm, ODM_COMP_INIT, ODM_DBG_TRACE, 
67         ("      (Platform, Interface) = (0x%X, 0x%X)\n", pDM_Odm->SupportPlatform, pDM_Odm->SupportInterface));
68         ODM_RT_TRACE(pDM_Odm, ODM_COMP_INIT, ODM_DBG_TRACE, 
69         ("      (Board, Package) = (0x%X, 0x%X)\n", pDM_Odm->BoardType, pDM_Odm->PackageType));
70
71
72         /*============== Value Defined Check ===============*/
73         /*QFN Type [15:12] and Cut Version [27:24] need to do value check*/
74         
75         if (((cond1 & 0x0000F000) != 0) && ((cond1 & 0x0000F000) != (driver1 & 0x0000F000)))
76                 return FALSE;
77         if (((cond1 & 0x0F000000) != 0) && ((cond1 & 0x0F000000) != (driver1 & 0x0F000000)))
78                 return FALSE;
79
80         /*=============== Bit Defined Check ================*/
81         /* We don't care [31:28] */
82
83         cond1   &= 0x00FF0FFF; 
84         driver1 &= 0x00FF0FFF; 
85
86         if ((cond1 & driver1) == cond1) {
87                 u4Byte bitMask = 0;
88
89                 if ((cond1 & 0x0F) == 0) /* BoardType is DONTCARE*/
90                         return TRUE;
91
92                 if ((cond1 & BIT0) != 0) /*GLNA*/
93                         bitMask |= 0x000000FF;
94                 if ((cond1 & BIT1) != 0) /*GPA*/
95                         bitMask |= 0x0000FF00;
96                 if ((cond1 & BIT2) != 0) /*ALNA*/
97                         bitMask |= 0x00FF0000;
98                 if ((cond1 & BIT3) != 0) /*APA*/
99                         bitMask |= 0xFF000000;
100
101                 if (((cond2 & bitMask) == (driver2 & bitMask)) && ((cond4 & bitMask) == (driver4 & bitMask)))  /* BoardType of each RF path is matched*/
102                         return TRUE;
103                 else
104                         return FALSE;
105         } else
106                 return FALSE;
107 }
108 static BOOLEAN
109 CheckNegative(
110         IN  PDM_ODM_T     pDM_Odm,
111         IN  const u4Byte  Condition1,
112         IN  const u4Byte  Condition2
113 )
114 {
115         return TRUE;
116 }
117
118 /******************************************************************************
119 *                           MAC_REG.TXT
120 ******************************************************************************/
121
122 u4Byte Array_MP_8188E_MAC_REG[] = { 
123                 0x026, 0x00000041,
124                 0x027, 0x00000035,
125         0x80000003,     0x00000000,     0x40000000,     0x00000000,
126                 0x040, 0x0000000C,
127         0x90000001,     0x00000000,     0x40000000,     0x00000000,
128                 0x040, 0x0000000C,
129         0xA0000000,     0x00000000,
130                 0x040, 0x00000000,
131         0xB0000000,     0x00000000,
132                 0x421, 0x0000000F,
133                 0x428, 0x0000000A,
134                 0x429, 0x00000010,
135                 0x430, 0x00000000,
136                 0x431, 0x00000001,
137                 0x432, 0x00000002,
138                 0x433, 0x00000004,
139                 0x434, 0x00000005,
140                 0x435, 0x00000006,
141                 0x436, 0x00000007,
142                 0x437, 0x00000008,
143                 0x438, 0x00000000,
144                 0x439, 0x00000000,
145                 0x43A, 0x00000001,
146                 0x43B, 0x00000002,
147                 0x43C, 0x00000004,
148                 0x43D, 0x00000005,
149                 0x43E, 0x00000006,
150                 0x43F, 0x00000007,
151                 0x440, 0x0000005D,
152                 0x441, 0x00000001,
153                 0x442, 0x00000000,
154                 0x444, 0x00000015,
155                 0x445, 0x000000F0,
156                 0x446, 0x0000000F,
157                 0x447, 0x00000000,
158                 0x458, 0x00000041,
159                 0x459, 0x000000A8,
160                 0x45A, 0x00000072,
161                 0x45B, 0x000000B9,
162                 0x460, 0x00000066,
163                 0x461, 0x00000066,
164                 0x480, 0x00000008,
165                 0x4C8, 0x000000FF,
166                 0x4C9, 0x00000008,
167                 0x4CC, 0x000000FF,
168                 0x4CD, 0x000000FF,
169                 0x4CE, 0x00000001,
170                 0x4D3, 0x00000001,
171                 0x500, 0x00000026,
172                 0x501, 0x000000A2,
173                 0x502, 0x0000002F,
174                 0x503, 0x00000000,
175                 0x504, 0x00000028,
176                 0x505, 0x000000A3,
177                 0x506, 0x0000005E,
178                 0x507, 0x00000000,
179                 0x508, 0x0000002B,
180                 0x509, 0x000000A4,
181                 0x50A, 0x0000005E,
182                 0x50B, 0x00000000,
183                 0x50C, 0x0000004F,
184                 0x50D, 0x000000A4,
185                 0x50E, 0x00000000,
186                 0x50F, 0x00000000,
187                 0x512, 0x0000001C,
188                 0x514, 0x0000000A,
189                 0x516, 0x0000000A,
190                 0x525, 0x0000004F,
191                 0x550, 0x00000010,
192                 0x551, 0x00000010,
193                 0x559, 0x00000002,
194                 0x55D, 0x000000FF,
195                 0x605, 0x00000030,
196                 0x608, 0x0000000E,
197                 0x609, 0x0000002A,
198                 0x620, 0x000000FF,
199                 0x621, 0x000000FF,
200                 0x622, 0x000000FF,
201                 0x623, 0x000000FF,
202                 0x624, 0x000000FF,
203                 0x625, 0x000000FF,
204                 0x626, 0x000000FF,
205                 0x627, 0x000000FF,
206                 0x63C, 0x00000008,
207                 0x63D, 0x00000008,
208                 0x63E, 0x0000000C,
209                 0x63F, 0x0000000C,
210                 0x640, 0x00000040,
211                 0x652, 0x00000020,
212                 0x66E, 0x00000005,
213                 0x700, 0x00000021,
214                 0x701, 0x00000043,
215                 0x702, 0x00000065,
216                 0x703, 0x00000087,
217                 0x708, 0x00000021,
218                 0x709, 0x00000043,
219                 0x70A, 0x00000065,
220                 0x70B, 0x00000087,
221
222 };
223
224 void
225 ODM_ReadAndConfig_MP_8188E_MAC_REG(
226         IN   PDM_ODM_T  pDM_Odm
227 )
228 {
229         u4Byte     i         = 0;
230         u1Byte     cCond;
231         BOOLEAN bMatched = TRUE, bSkipped = FALSE;
232         u4Byte     ArrayLen    = sizeof(Array_MP_8188E_MAC_REG)/sizeof(u4Byte);
233         pu4Byte    Array       = Array_MP_8188E_MAC_REG;
234         
235         u4Byte  v1 = 0, v2 = 0, pre_v1 = 0, pre_v2 = 0;
236
237         ODM_RT_TRACE(pDM_Odm, ODM_COMP_INIT, ODM_DBG_LOUD, ("===> ODM_ReadAndConfig_MP_8188E_MAC_REG\n"));
238
239         while ((i + 1) < ArrayLen) {
240                 v1 = Array[i];
241                 v2 = Array[i + 1];
242
243                 if (v1 & (BIT31 | BIT30)) {/*positive & negative condition*/
244                         if (v1 & BIT31) {/* positive condition*/
245                                 cCond  = (u1Byte)((v1 & (BIT29|BIT28)) >> 28);
246                                 if (cCond == COND_ENDIF) {/*end*/
247                                         bMatched = TRUE;
248                                         bSkipped = FALSE;
249                                         ODM_RT_TRACE(pDM_Odm, ODM_COMP_INIT, ODM_DBG_LOUD, ("ENDIF\n"));
250                                 } else if (cCond == COND_ELSE) { /*else*/
251                                         bMatched = bSkipped?FALSE:TRUE;
252                                         ODM_RT_TRACE(pDM_Odm, ODM_COMP_INIT, ODM_DBG_LOUD, ("ELSE\n"));
253                                 }
254                                 else {/*if , else if*/
255                                         pre_v1 = v1;
256                                         pre_v2 = v2;
257                                         ODM_RT_TRACE(pDM_Odm, ODM_COMP_INIT, ODM_DBG_LOUD, ("IF or ELSE IF\n"));
258                                 }
259                         } else if (v1 & BIT30) { /*negative condition*/
260                                 if (bSkipped == FALSE) {
261                                         if (CheckPositive(pDM_Odm, pre_v1, pre_v2, v1, v2)) {
262                                                 bMatched = TRUE;
263                                                 bSkipped = TRUE;
264                                         } else {
265                                                 bMatched = FALSE;
266                                                 bSkipped = FALSE;
267                                         }
268                                 } else
269                                         bMatched = FALSE;
270                         }
271                 } else {
272                         if (bMatched)
273                                 odm_ConfigMAC_8188E(pDM_Odm, v1, (u1Byte)v2);
274                 }
275                 i = i + 2;
276         }
277 }
278
279 u4Byte
280 ODM_GetVersion_MP_8188E_MAC_REG(void)
281 {
282            return 63;
283 }
284
285 #endif /* end of HWIMG_SUPPORT*/
286