1 /******************************************************************************
2 *
3 * Copyright(c) 2007 - 2017 Realtek Corporation.
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 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
16 *
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
21 *
22 * Larry Finger <Larry.Finger@lwfinger.net>
23 *
24 *****************************************************************************/
25
26 /*Image2HeaderVersion: R3 1.5.10.1*/
27 #include "mp_precomp.h"
28 #include "../phydm_precomp.h"
29
30 #if (RTL8821C_SUPPORT == 1)
31 static boolean
check_positive(struct dm_struct * dm,const u32 condition1,const u32 condition2,const u32 condition3,const u32 condition4)32 check_positive(struct dm_struct *dm,
33 const u32 condition1,
34 const u32 condition2,
35 const u32 condition3,
36 const u32 condition4
37 )
38 {
39 u32 cond1 = condition1, cond2 = condition2,
40 cond3 = condition3, cond4 = condition4;
41
42 u8 cut_version_for_para =
43 (dm->cut_version == ODM_CUT_A) ? 15 : dm->cut_version;
44
45 u8 pkg_type_for_para =
46 (dm->package_type == 0) ? 15 : dm->package_type;
47
48 u32 driver1 = cut_version_for_para << 24 |
49 (dm->support_interface & 0xF0) << 16 |
50 dm->support_platform << 16 |
51 pkg_type_for_para << 12 |
52 (dm->support_interface & 0x0F) << 8 |
53 dm->rfe_type;
54
55 u32 driver2 = (dm->type_glna & 0xFF) << 0 |
56 (dm->type_gpa & 0xFF) << 8 |
57 (dm->type_alna & 0xFF) << 16 |
58 (dm->type_apa & 0xFF) << 24;
59
60 u32 driver3 = 0;
61
62 u32 driver4 = (dm->type_glna & 0xFF00) >> 8 |
63 (dm->type_gpa & 0xFF00) |
64 (dm->type_alna & 0xFF00) << 8 |
65 (dm->type_apa & 0xFF00) << 16;
66
67 PHYDM_DBG(dm, ODM_COMP_INIT,
68 "===> %s (cond1, cond2, cond3, cond4) = (0x%X 0x%X 0x%X 0x%X)\n",
69 __func__, cond1, cond2, cond3, cond4);
70 PHYDM_DBG(dm, ODM_COMP_INIT,
71 "===> %s (driver1, driver2, driver3, driver4) = (0x%X 0x%X 0x%X 0x%X)\n",
72 __func__, driver1, driver2, driver3, driver4);
73
74 PHYDM_DBG(dm, ODM_COMP_INIT,
75 " (Platform, Interface) = (0x%X, 0x%X)\n",
76 dm->support_platform, dm->support_interface);
77 PHYDM_DBG(dm, ODM_COMP_INIT, " (RFE, Package) = (0x%X, 0x%X)\n",
78 dm->rfe_type, dm->package_type);
79
80 /*============== value Defined Check ===============*/
81 /*cut version [27:24] need to do value check*/
82 if (((cond1 & 0x0F000000) != 0) &&
83 ((cond1 & 0x0F000000) != (driver1 & 0x0F000000)))
84 return false;
85
86 /*pkg type [15:12] need to do value check*/
87 if (((cond1 & 0x0000F000) != 0) &&
88 ((cond1 & 0x0000F000) != (driver1 & 0x0000F000)))
89 return false;
90
91 /*interface [11:8] need to do value check*/
92 if (((cond1 & 0x00000F00) != 0) &&
93 ((cond1 & 0x00000F00) != (driver1 & 0x00000F00)))
94 return false;
95 /*=============== Bit Defined Check ================*/
96 /* We don't care [31:28] */
97
98 cond1 &= 0x000000FF;
99 driver1 &= 0x000000FF;
100
101 if (cond1 == driver1)
102 return true;
103 else
104 return false;
105 }
106
107
108 /******************************************************************************
109 * mac_reg.TXT
110 ******************************************************************************/
111
112 const u32 array_mp_8821c_mac_reg[] = {
113 0x010, 0x00000043,
114 0x025, 0x0000001D,
115 0x026, 0x000000CE,
116 0x04F, 0x00000001,
117 0x029, 0x000000F9,
118 0x420, 0x00000080,
119 0x421, 0x0000000F,
120 0x428, 0x0000000A,
121 0x429, 0x00000010,
122 0x430, 0x00000000,
123 0x431, 0x00000000,
124 0x432, 0x00000000,
125 0x433, 0x00000001,
126 0x434, 0x00000004,
127 0x435, 0x00000005,
128 0x436, 0x00000007,
129 0x437, 0x00000008,
130 0x43C, 0x00000004,
131 0x43D, 0x00000005,
132 0x43E, 0x00000007,
133 0x43F, 0x00000008,
134 0x440, 0x0000005D,
135 0x441, 0x00000001,
136 0x442, 0x00000000,
137 0x444, 0x00000010,
138 0x445, 0x000000F0,
139 0x446, 0x00000001,
140 0x447, 0x000000FE,
141 0x448, 0x00000000,
142 0x449, 0x00000000,
143 0x44A, 0x00000000,
144 0x44B, 0x00000040,
145 0x44C, 0x00000010,
146 0x44D, 0x000000F0,
147 0x44E, 0x0000003F,
148 0x44F, 0x00000000,
149 0x450, 0x00000000,
150 0x451, 0x00000000,
151 0x452, 0x00000000,
152 0x453, 0x00000040,
153 0x455, 0x00000070,
154 0x45E, 0x00000004,
155 0x49C, 0x00000010,
156 0x49D, 0x000000F0,
157 0x49E, 0x00000000,
158 0x49F, 0x00000006,
159 0x4A0, 0x000000E0,
160 0x4A1, 0x00000003,
161 0x4A2, 0x00000000,
162 0x4A3, 0x00000040,
163 0x4A4, 0x00000015,
164 0x4A5, 0x000000F0,
165 0x4A6, 0x00000000,
166 0x4A7, 0x00000006,
167 0x4A8, 0x000000E0,
168 0x4A9, 0x00000000,
169 0x4AA, 0x00000000,
170 0x4AB, 0x00000000,
171 0x7DA, 0x00000008,
172 0x1448, 0x00000006,
173 0x144A, 0x00000006,
174 0x144C, 0x00000006,
175 0x144E, 0x00000006,
176 0x4C8, 0x000000FF,
177 0x4C9, 0x00000008,
178 0x4CC, 0x000000FF,
179 0x4CD, 0x000000FF,
180 0x4CE, 0x00000001,
181 0x4CF, 0x00000008,
182 0x500, 0x00000026,
183 0x501, 0x000000A2,
184 0x502, 0x0000002F,
185 0x503, 0x00000000,
186 0x504, 0x00000028,
187 0x505, 0x000000A3,
188 0x506, 0x0000005E,
189 0x507, 0x00000000,
190 0x508, 0x0000002B,
191 0x509, 0x000000A4,
192 0x50A, 0x0000005E,
193 0x50B, 0x00000000,
194 0x50C, 0x0000004F,
195 0x50D, 0x000000A4,
196 0x50E, 0x00000000,
197 0x50F, 0x00000000,
198 0x512, 0x0000001C,
199 0x514, 0x0000000A,
200 0x516, 0x0000000A,
201 0x521, 0x0000002F,
202 0x525, 0x0000004F,
203 0x551, 0x00000010,
204 0x559, 0x00000002,
205 0x55C, 0x00000050,
206 0x55D, 0x000000FF,
207 0x577, 0x0000000B,
208 0x578, 0x00000014,
209 0x579, 0x00000014,
210 0x57A, 0x00000014,
211 0x5BE, 0x00000064,
212 0x605, 0x00000030,
213 0x608, 0x0000000E,
214 0x609, 0x00000022,
215 0x60C, 0x00000018,
216 0x6A0, 0x000000FF,
217 0x6A1, 0x000000FF,
218 0x6A2, 0x000000FF,
219 0x6A3, 0x000000FF,
220 0x6A4, 0x000000FF,
221 0x6A5, 0x000000FF,
222 0x6DE, 0x00000084,
223 0x620, 0x000000FF,
224 0x621, 0x000000FF,
225 0x622, 0x000000FF,
226 0x623, 0x000000FF,
227 0x624, 0x000000FF,
228 0x625, 0x000000FF,
229 0x626, 0x000000FF,
230 0x627, 0x000000FF,
231 0x638, 0x00000050,
232 0x63C, 0x0000000A,
233 0x63D, 0x0000000A,
234 0x63E, 0x0000000E,
235 0x63F, 0x0000000E,
236 0x640, 0x00000040,
237 0x642, 0x00000040,
238 0x643, 0x00000000,
239 0x652, 0x000000C8,
240 0x66E, 0x00000005,
241 0x700, 0x00000021,
242 0x701, 0x00000043,
243 0x702, 0x00000065,
244 0x703, 0x00000087,
245 0x708, 0x00000021,
246 0x709, 0x00000043,
247 0x70A, 0x00000065,
248 0x70B, 0x00000087,
249 0x718, 0x00000040,
250 0x7D4, 0x00000098,
251
252 };
253
254 void
odm_read_and_config_mp_8821c_mac_reg(struct dm_struct * dm)255 odm_read_and_config_mp_8821c_mac_reg(struct dm_struct *dm)
256 {
257 u32 i = 0;
258 u8 c_cond;
259 boolean is_matched = true, is_skipped = false;
260 u32 array_len =
261 sizeof(array_mp_8821c_mac_reg) / sizeof(u32);
262 u32 *array = (u32 *)array_mp_8821c_mac_reg;
263
264 u32 v1 = 0, v2 = 0, pre_v1 = 0, pre_v2 = 0;
265 u32 a1 = 0, a2 = 0, a3 = 0, a4 = 0;
266
267 PHYDM_DBG(dm, ODM_COMP_INIT, "===> %s\n", __func__);
268
269 while ((i + 1) < array_len) {
270 v1 = array[i];
271 v2 = array[i + 1];
272
273 if (v1 & (BIT(31) | BIT(30))) {/*positive & negative condition*/
274 if (v1 & BIT(31)) {/* positive condition*/
275 c_cond =
276 (u8)((v1 & (BIT(29) | BIT(28))) >> 28);
277 if (c_cond == COND_ENDIF) {/*end*/
278 is_matched = true;
279 is_skipped = false;
280 PHYDM_DBG(dm, ODM_COMP_INIT, "ENDIF\n");
281 } else if (c_cond == COND_ELSE) { /*else*/
282 is_matched = is_skipped ? false : true;
283 PHYDM_DBG(dm, ODM_COMP_INIT, "ELSE\n");
284 } else {/*if , else if*/
285 pre_v1 = v1;
286 pre_v2 = v2;
287 PHYDM_DBG(dm, ODM_COMP_INIT,
288 "IF or ELSE IF\n");
289 }
290 } else if (v1 & BIT(30)) { /*negative condition*/
291 if (!is_skipped) {
292 a1 = pre_v1; a2 = pre_v2;
293 a3 = v1; a4 = v2;
294 if (check_positive(dm,
295 a1, a2, a3, a4)) {
296 is_matched = true;
297 is_skipped = true;
298 } else {
299 is_matched = false;
300 is_skipped = false;
301 }
302 } else {
303 is_matched = false;
304 }
305 }
306 } else {
307 if (is_matched)
308 odm_config_mac_8821c(dm, v1, (u8)v2);
309 }
310 i = i + 2;
311 }
312 }
313
314 u32
odm_get_version_mp_8821c_mac_reg(void)315 odm_get_version_mp_8821c_mac_reg(void)
316 {
317 return 64;
318 }
319
320 #endif /* end of HWIMG_SUPPORT*/
321
322