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 *****************************************************************************/
15
16 /*Image2HeaderVersion: 3.5.2*/
17 #include "mp_precomp.h"
18 #include "../phydm_precomp.h"
19
20 #if (RTL8723D_SUPPORT == 1)
21 static boolean
check_positive(struct dm_struct * dm,const u32 condition1,const u32 condition2,const u32 condition3,const u32 condition4)22 check_positive(
23 struct dm_struct *dm,
24 const u32 condition1,
25 const u32 condition2,
26 const u32 condition3,
27 const u32 condition4
28 )
29 {
30 u8 _board_type = ((dm->board_type & BIT(4)) >> 4) << 0 | /* _GLNA*/
31 ((dm->board_type & BIT(3)) >> 3) << 1 | /* _GPA*/
32 ((dm->board_type & BIT(7)) >> 7) << 2 | /* _ALNA*/
33 ((dm->board_type & BIT(6)) >> 6) << 3 | /* _APA */
34 ((dm->board_type & BIT(2)) >> 2) << 4 | /* _BT*/
35 ((dm->board_type & BIT(1)) >> 1) << 5 | /* _NGFF*/
36 ((dm->board_type & BIT(5)) >> 5) << 6; /* _TRSWT*/
37
38 u32 cond1 = condition1, cond2 = condition2, cond3 = condition3, cond4 = condition4;
39
40 u8 cut_version_for_para = (dm->cut_version == ODM_CUT_A) ? 15 : dm->cut_version;
41 u8 pkg_type_for_para = (dm->package_type == 0) ? 15 : dm->package_type;
42
43 u32 driver1 = cut_version_for_para << 24 |
44 (dm->support_interface & 0xF0) << 16 |
45 dm->support_platform << 16 |
46 pkg_type_for_para << 12 |
47 (dm->support_interface & 0x0F) << 8 |
48 _board_type;
49
50 u32 driver2 = (dm->type_glna & 0xFF) << 0 |
51 (dm->type_gpa & 0xFF) << 8 |
52 (dm->type_alna & 0xFF) << 16 |
53 (dm->type_apa & 0xFF) << 24;
54
55 u32 driver3 = 0;
56
57 u32 driver4 = (dm->type_glna & 0xFF00) >> 8 |
58 (dm->type_gpa & 0xFF00) |
59 (dm->type_alna & 0xFF00) << 8 |
60 (dm->type_apa & 0xFF00) << 16;
61
62 PHYDM_DBG(dm, ODM_COMP_INIT,
63 "===> %s (cond1, cond2, cond3, cond4) = (0x%X 0x%X 0x%X 0x%X)\n",
64 __func__, cond1, cond2, cond3, cond4);
65 PHYDM_DBG(dm, ODM_COMP_INIT,
66 "===> %s (driver1, driver2, driver3, driver4) = (0x%X 0x%X 0x%X 0x%X)\n",
67 __func__, driver1, driver2, driver3, driver4);
68
69 PHYDM_DBG(dm, ODM_COMP_INIT,
70 " (Platform, Interface) = (0x%X, 0x%X)\n",
71 dm->support_platform, dm->support_interface);
72 PHYDM_DBG(dm, ODM_COMP_INIT,
73 " (Board, Package) = (0x%X, 0x%X)\n", dm->board_type,
74 dm->package_type);
75
76
77 /*============== value Defined Check ===============*/
78 /*QFN type [15:12] and cut version [27:24] need to do value check*/
79
80 if (((cond1 & 0x0000F000) != 0) && ((cond1 & 0x0000F000) != (driver1 & 0x0000F000)))
81 return false;
82 if (((cond1 & 0x0F000000) != 0) && ((cond1 & 0x0F000000) != (driver1 & 0x0F000000)))
83 return false;
84
85 /*=============== Bit Defined Check ================*/
86 /* We don't care [31:28] */
87
88 cond1 &= 0x00FF0FFF;
89 driver1 &= 0x00FF0FFF;
90
91 if ((cond1 & driver1) == cond1) {
92 u32 bit_mask = 0;
93
94 if ((cond1 & 0x0F) == 0) /* board_type is DONTCARE*/
95 return true;
96
97 if ((cond1 & BIT(0)) != 0) /*GLNA*/
98 bit_mask |= 0x000000FF;
99 if ((cond1 & BIT(1)) != 0) /*GPA*/
100 bit_mask |= 0x0000FF00;
101 if ((cond1 & BIT(2)) != 0) /*ALNA*/
102 bit_mask |= 0x00FF0000;
103 if ((cond1 & BIT(3)) != 0) /*APA*/
104 bit_mask |= 0xFF000000;
105
106 if (((cond2 & bit_mask) == (driver2 & bit_mask)) && ((cond4 & bit_mask) == (driver4 & bit_mask))) /* board_type of each RF path is matched*/
107 return true;
108 else
109 return false;
110 } else
111 return false;
112 }
113
114 /******************************************************************************
115 * mac_reg.TXT
116 ******************************************************************************/
117
118 u32 array_mp_8723d_mac_reg[] = {
119 0x020, 0x00000013,
120 0x02F, 0x00000010,
121 0x077, 0x00000007,
122 0x421, 0x0000000F,
123 0x422, 0x00000078,
124 0x428, 0x0000000A,
125 0x429, 0x00000010,
126 0x430, 0x00000000,
127 0x431, 0x00000000,
128 0x432, 0x00000000,
129 0x433, 0x00000001,
130 0x434, 0x00000002,
131 0x435, 0x00000003,
132 0x436, 0x00000005,
133 0x437, 0x00000007,
134 0x438, 0x00000000,
135 0x439, 0x00000000,
136 0x43A, 0x00000000,
137 0x43B, 0x00000001,
138 0x43C, 0x00000002,
139 0x43D, 0x00000003,
140 0x43E, 0x00000005,
141 0x43F, 0x00000007,
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, 0x000000A0,
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 0x7C0, 0x00000038,
227 0x7C2, 0x0000000F,
228 0x7C3, 0x000000C0,
229 0x7C4, 0x00000077,
230 0x07C, 0x00000003,
231 0x016, 0x000000B3,
232
233 };
234
235 void
odm_read_and_config_mp_8723d_mac_reg(struct dm_struct * dm)236 odm_read_and_config_mp_8723d_mac_reg(struct dm_struct *dm)
237 {
238 u32 i = 0;
239 u8 c_cond;
240 boolean is_matched = true, is_skipped = false;
241 u32 array_len = sizeof(array_mp_8723d_mac_reg) / sizeof(u32);
242 u32 *array = array_mp_8723d_mac_reg;
243
244 u32 v1 = 0, v2 = 0, pre_v1 = 0, pre_v2 = 0;
245
246 PHYDM_DBG(dm, ODM_COMP_INIT, "===> %s\n", __func__);
247
248 while ((i + 1) < array_len) {
249 v1 = array[i];
250 v2 = array[i + 1];
251
252 if (v1 & (BIT(31) | BIT(30))) {/*positive & negative condition*/
253 if (v1 & BIT(31)) {/* positive condition*/
254 c_cond = (u8)((v1 & (BIT(29) | BIT(28))) >> 28);
255 if (c_cond == COND_ENDIF) {/*end*/
256 is_matched = true;
257 is_skipped = false;
258 PHYDM_DBG(dm, ODM_COMP_INIT, "ENDIF\n");
259 } else if (c_cond == COND_ELSE) { /*else*/
260 is_matched = is_skipped ? false : true;
261 PHYDM_DBG(dm, ODM_COMP_INIT, "ELSE\n");
262 } else {/*if , else if*/
263 pre_v1 = v1;
264 pre_v2 = v2;
265 PHYDM_DBG(dm, ODM_COMP_INIT, "IF or ELSE IF\n");
266 }
267 } else if (v1 & BIT(30)) { /*negative condition*/
268 if (is_skipped == false) {
269 if (check_positive(dm, pre_v1, pre_v2, v1, v2)) {
270 is_matched = true;
271 is_skipped = true;
272 } else {
273 is_matched = false;
274 is_skipped = false;
275 }
276 } else
277 is_matched = false;
278 }
279 } else {
280 if (is_matched)
281 odm_config_mac_8723d(dm, v1, (u8)v2);
282 }
283 i = i + 2;
284 }
285 }
286
287 u32
odm_get_version_mp_8723d_mac_reg(void)288 odm_get_version_mp_8723d_mac_reg(void)
289 {
290 return 42;
291 }
292
293 #endif /* end of HWIMG_SUPPORT*/
294
295