net: wireless: rockchip_wlan: add rtl8723cs support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723cs / hal / phydm / rtl8703b / halhwimg8703b_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.18*/
22 #include "mp_precomp.h"
23 #include "../phydm_precomp.h"
24
25 #if (RTL8703B_SUPPORT == 1)
26 static boolean
27 check_positive(
28         struct PHY_DM_STRUCT     *p_dm_odm,
29         const u32  condition1,
30         const u32  condition2,
31         const u32  condition3,
32         const u32  condition4
33 )
34 {
35         u8    _board_type = ((p_dm_odm->board_type & BIT(4)) >> 4) << 0 | /* _GLNA*/
36                     ((p_dm_odm->board_type & BIT(3)) >> 3) << 1 | /* _GPA*/
37                     ((p_dm_odm->board_type & BIT(7)) >> 7) << 2 | /* _ALNA*/
38                     ((p_dm_odm->board_type & BIT(6)) >> 6) << 3 | /* _APA */
39                     ((p_dm_odm->board_type & BIT(2)) >> 2) << 4;  /* _BT*/
40
41         u32     cond1   = condition1, cond2 = condition2, cond3 = condition3, cond4 = condition4;
42         u32    driver1 = p_dm_odm->cut_version       << 24 |
43                          (p_dm_odm->support_interface & 0xF0) << 16 |
44                          p_dm_odm->support_platform  << 16 |
45                          p_dm_odm->package_type      << 12 |
46                          (p_dm_odm->support_interface & 0x0F) << 8  |
47                          _board_type;
48
49         u32    driver2 = (p_dm_odm->type_glna & 0xFF) <<  0 |
50                          (p_dm_odm->type_gpa & 0xFF)  <<  8 |
51                          (p_dm_odm->type_alna & 0xFF) << 16 |
52                          (p_dm_odm->type_apa & 0xFF)  << 24;
53
54         u32    driver3 = 0;
55
56         u32    driver4 = (p_dm_odm->type_glna & 0xFF00) >>  8 |
57                          (p_dm_odm->type_gpa & 0xFF00) |
58                          (p_dm_odm->type_alna & 0xFF00) << 8 |
59                          (p_dm_odm->type_apa & 0xFF00)  << 16;
60
61         ODM_RT_TRACE(p_dm_odm, ODM_COMP_INIT, ODM_DBG_TRACE,
62                 ("===> check_positive (cond1, cond2, cond3, cond4) = (0x%X 0x%X 0x%X 0x%X)\n", cond1, cond2, cond3, cond4));
63         ODM_RT_TRACE(p_dm_odm, ODM_COMP_INIT, ODM_DBG_TRACE,
64                 ("===> check_positive (driver1, driver2, driver3, driver4) = (0x%X 0x%X 0x%X 0x%X)\n", driver1, driver2, driver3, driver4));
65
66         ODM_RT_TRACE(p_dm_odm, ODM_COMP_INIT, ODM_DBG_TRACE,
67                 ("      (Platform, Interface) = (0x%X, 0x%X)\n", p_dm_odm->support_platform, p_dm_odm->support_interface));
68         ODM_RT_TRACE(p_dm_odm, ODM_COMP_INIT, ODM_DBG_TRACE,
69                 ("      (Board, Package) = (0x%X, 0x%X)\n", p_dm_odm->board_type, p_dm_odm->package_type));
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                 u32 bit_mask = 0;
88
89                 if ((cond1 & 0x0F) == 0) /* board_type is DONTCARE*/
90                         return true;
91
92                 if ((cond1 & BIT(0)) != 0) /*GLNA*/
93                         bit_mask |= 0x000000FF;
94                 if ((cond1 & BIT(1)) != 0) /*GPA*/
95                         bit_mask |= 0x0000FF00;
96                 if ((cond1 & BIT(2)) != 0) /*ALNA*/
97                         bit_mask |= 0x00FF0000;
98                 if ((cond1 & BIT(3)) != 0) /*APA*/
99                         bit_mask |= 0xFF000000;
100
101                 if (((cond2 & bit_mask) == (driver2 & bit_mask)) && ((cond4 & bit_mask) == (driver4 & bit_mask)))  /* board_type of each RF path is matched*/
102                         return true;
103                 else
104                         return false;
105         } else
106                 return false;
107 }
108 static boolean
109 check_negative(
110         struct PHY_DM_STRUCT     *p_dm_odm,
111         const u32  condition1,
112         const u32  condition2
113 )
114 {
115         return true;
116 }
117
118 /******************************************************************************
119 *                           MAC_REG.TXT
120 ******************************************************************************/
121
122 u32 array_mp_8703b_mac_reg[] = {
123         0x02F, 0x00000030,
124         0x035, 0x00000000,
125         0x067, 0x00000002,
126         0x092, 0x00000080,
127         0x421, 0x0000000F,
128         0x428, 0x0000000A,
129         0x429, 0x00000010,
130         0x430, 0x00000000,
131         0x431, 0x00000000,
132         0x432, 0x00000000,
133         0x433, 0x00000001,
134         0x434, 0x00000004,
135         0x435, 0x00000005,
136         0x436, 0x00000007,
137         0x437, 0x00000008,
138         0x43C, 0x00000004,
139         0x43D, 0x00000005,
140         0x43E, 0x00000007,
141         0x43F, 0x00000008,
142         0x440, 0x0000005D,
143         0x441, 0x00000001,
144         0x442, 0x00000000,
145         0x444, 0x00000010,
146         0x445, 0x00000000,
147         0x446, 0x00000000,
148         0x447, 0x00000000,
149         0x448, 0x00000000,
150         0x449, 0x000000F0,
151         0x44A, 0x0000000F,
152         0x44B, 0x0000003E,
153         0x44C, 0x00000010,
154         0x44D, 0x00000000,
155         0x44E, 0x00000000,
156         0x44F, 0x00000000,
157         0x450, 0x00000000,
158         0x451, 0x000000F0,
159         0x452, 0x0000000F,
160         0x453, 0x00000000,
161         0x456, 0x0000005E,
162         0x460, 0x00000066,
163         0x461, 0x00000066,
164         0x4C8, 0x000000FF,
165         0x4C9, 0x00000008,
166         0x4CC, 0x000000FF,
167         0x4CD, 0x000000FF,
168         0x4CE, 0x00000001,
169         0x500, 0x00000026,
170         0x501, 0x000000A2,
171         0x502, 0x0000002F,
172         0x503, 0x00000000,
173         0x504, 0x00000028,
174         0x505, 0x000000A3,
175         0x506, 0x0000005E,
176         0x507, 0x00000000,
177         0x508, 0x0000002B,
178         0x509, 0x000000A4,
179         0x50A, 0x0000005E,
180         0x50B, 0x00000000,
181         0x50C, 0x0000004F,
182         0x50D, 0x000000A4,
183         0x50E, 0x00000000,
184         0x50F, 0x00000000,
185         0x512, 0x0000001C,
186         0x514, 0x0000000A,
187         0x516, 0x0000000A,
188         0x525, 0x0000004F,
189         0x550, 0x00000010,
190         0x551, 0x00000010,
191         0x559, 0x00000002,
192         0x55C, 0x00000028,
193         0x55D, 0x000000FF,
194         0x605, 0x00000030,
195         0x608, 0x0000000E,
196         0x609, 0x0000002A,
197         0x620, 0x000000FF,
198         0x621, 0x000000FF,
199         0x622, 0x000000FF,
200         0x623, 0x000000FF,
201         0x624, 0x000000FF,
202         0x625, 0x000000FF,
203         0x626, 0x000000FF,
204         0x627, 0x000000FF,
205         0x638, 0x00000028,
206         0x63C, 0x0000000A,
207         0x63D, 0x0000000A,
208         0x63E, 0x0000000C,
209         0x63F, 0x0000000C,
210         0x640, 0x00000040,
211         0x642, 0x00000040,
212         0x643, 0x00000000,
213         0x652, 0x000000C8,
214         0x66A, 0x000000B0,
215         0x66E, 0x00000005,
216         0x700, 0x00000021,
217         0x701, 0x00000043,
218         0x702, 0x00000065,
219         0x703, 0x00000087,
220         0x708, 0x00000021,
221         0x709, 0x00000043,
222         0x70A, 0x00000065,
223         0x70B, 0x00000087,
224         0x765, 0x00000018,
225         0x76E, 0x00000004,
226
227 };
228
229 void
230 odm_read_and_config_mp_8703b_mac_reg(
231         struct PHY_DM_STRUCT  *p_dm_odm
232 )
233 {
234         u32     i         = 0;
235         u8     c_cond;
236         boolean is_matched = true, is_skipped = false;
237         u32     array_len    = sizeof(array_mp_8703b_mac_reg) / sizeof(u32);
238         u32    *array       = array_mp_8703b_mac_reg;
239
240         u32     v1 = 0, v2 = 0, pre_v1 = 0, pre_v2 = 0;
241
242         ODM_RT_TRACE(p_dm_odm, ODM_COMP_INIT, ODM_DBG_LOUD, ("===> odm_read_and_config_mp_8703b_mac_reg\n"));
243
244         while ((i + 1) < array_len) {
245                 v1 = array[i];
246                 v2 = array[i + 1];
247
248                 if (v1 & (BIT(31) | BIT30)) {/*positive & negative condition*/
249                         if (v1 & BIT(31)) {/* positive condition*/
250                                 c_cond  = (u8)((v1 & (BIT(29) | BIT(28))) >> 28);
251                                 if (c_cond == COND_ENDIF) {/*end*/
252                                         is_matched = true;
253                                         is_skipped = false;
254                                         ODM_RT_TRACE(p_dm_odm, ODM_COMP_INIT, ODM_DBG_LOUD, ("ENDIF\n"));
255                                 } else if (c_cond == COND_ELSE) { /*else*/
256                                         is_matched = is_skipped ? false : true;
257                                         ODM_RT_TRACE(p_dm_odm, ODM_COMP_INIT, ODM_DBG_LOUD, ("ELSE\n"));
258                                 } else {/*if , else if*/
259                                         pre_v1 = v1;
260                                         pre_v2 = v2;
261                                         ODM_RT_TRACE(p_dm_odm, ODM_COMP_INIT, ODM_DBG_LOUD, ("IF or ELSE IF\n"));
262                                 }
263                         } else if (v1 & BIT(30)) { /*negative condition*/
264                                 if (is_skipped == false) {
265                                         if (check_positive(p_dm_odm, pre_v1, pre_v2, v1, v2)) {
266                                                 is_matched = true;
267                                                 is_skipped = true;
268                                         } else {
269                                                 is_matched = false;
270                                                 is_skipped = false;
271                                         }
272                                 } else
273                                         is_matched = false;
274                         }
275                 } else {
276                         if (is_matched)
277                                 odm_config_mac_8703b(p_dm_odm, v1, (u8)v2);
278                 }
279                 i = i + 2;
280         }
281 }
282
283 u32
284 odm_get_version_mp_8703b_mac_reg(void)
285 {
286         return 17;
287 }
288
289 #endif /* end of HWIMG_SUPPORT*/