2 \brief Declaration of library functions
4 Any definitions in this file will be shared among GLUE Layer and internal Driver Stack.
10 /*******************************************************************************
11 * C O M P I L E R F L A G S
12 ********************************************************************************
15 /*******************************************************************************
17 ********************************************************************************
22 #define DFT_TAG "[WMT-IC]"
25 /*******************************************************************************
26 * E X T E R N A L R E F E R E N C E S
27 ********************************************************************************
29 #include "osal_typedef.h"
35 /*******************************************************************************
37 ********************************************************************************
40 #define DEFAULT_PATCH_FRAG_SIZE (1000)
41 #define MT6620E2_PATCH_FRAG_SIZE (900)
42 #define WMT_PATCH_FRAG_1ST (0x1)
43 #define WMT_PATCH_FRAG_MID (0x2)
44 #define WMT_PATCH_FRAG_LAST (0x3)
46 #define CFG_CHECK_WMT_RESULT (1)
47 #define CFG_WMT_BT_PORT2 (0) /* BT Port 2 Feature. this command does not need after coex command is downconfirmed by LC,*/
49 #define CFG_SET_OPT_REG (0)
50 #define CFG_WMT_I2S_DBGUART_SUPPORT (0)
51 #define CFG_SET_OPT_REG_SWLA (0)
52 #define CFG_SET_OPT_REG_MCUCLK (0)
53 #define CFG_SET_OPT_REG_MCUIRQ (0)
55 #define CFG_WMT_COREDUMP_ENABLE 0
57 #define CFG_WMT_MULTI_PATCH (1)
58 /*******************************************************************************
60 ********************************************************************************
63 /*******************************************************************************
64 * P R I V A T E D A T A
65 ********************************************************************************
67 #if !(CFG_WMT_MULTI_PATCH)
68 static UCHAR gDefPatchName[NAME_MAX + 1];
70 static UCHAR gFullPatchName[NAME_MAX + 1];
71 static const WMT_IC_INFO_S *gp_mt6620_info = NULL;
73 static UCHAR WMT_WAKEUP_DIS_GATE_CMD[] = {0x1, 0x3, 0x01, 0x00, 0x04};
74 static UCHAR WMT_WAKEUP_DIS_GATE_EVT[] = {0x2, 0x3, 0x02, 0x0, 0x0, 0x04};
76 static UCHAR WMT_WAKEUP_EN_GATE_CMD[] = {0x1, 0x3, 0x01, 0x00, 0x05};
77 static UCHAR WMT_WAKEUP_EN_GATE_EVT[] = {0x2, 0x3, 0x02, 0x0, 0x0, 0x05};
79 static UCHAR WMT_QUERY_BAUD_CMD[] = {0x01, 0x04, 0x01, 0x00, 0x02};
80 static UCHAR WMT_QUERY_BAUD_EVT_115200[] = {0x02, 0x04, 0x06, 0x00, 0x00, 0x02, 0x00, 0xC2, 0x01, 0x00};
81 static UCHAR WMT_QUERY_BAUD_EVT_X[] = {0x02, 0x04, 0x06, 0x00, 0x00, 0x02, 0xAA, 0xAA, 0xAA, 0xBB};
82 static UCHAR WMT_QUERY_STP_CMD[] = {0x01, 0x04, 0x01, 0x00, 0x04};
83 static UCHAR WMT_QUERY_STP_EVT_DEFAULT[] = {0x02, 0x04, 0x06, 0x00, 0x00, 0x04, 0x11, 0x00, 0x00, 0x00};
84 static UCHAR WMT_QUERY_STP_EVT_UART[] = {0x02, 0x04, 0x06, 0x00, 0x00, 0x04, 0xDF, 0x0E, 0x68, 0x01};
85 static UCHAR WMT_SET_BAUD_CMD_X[] = {0x01, 0x04, 0x05, 0x00, 0x01, 0xAA, 0xAA, 0xAA, 0xBB};
86 static UCHAR WMT_SET_BAUD_EVT[] = {0x02, 0x04, 0x02, 0x00, 0x00, 0x01};
87 static UCHAR WMT_SET_WAKEUP_WAKE_CMD_RAW[] = {0xFF};
88 static UCHAR WMT_SET_WAKEUP_WAKE_EVT[] = {0x02, 0x03, 0x02, 0x00, 0x00, 0x03};
89 #if CFG_WMT_MULTI_PATCH
90 static UCHAR WMT_PATCH_ADDRESS_CMD[] = {0x01,0x08,0x10,0x00,0x01,0x01,0x00,0x01,0x64,0x0E,0x00,0x01,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff};
91 static UCHAR WMT_PATCH_ADDRESS_EVT[] = {0x02,0x08,0x04,0x00,0x00,0x00,0x00,0x01};
92 static UCHAR WMT_PATCH_P_ADDRESS_CMD[] = {0x01,0x08,0x10,0x00,0x01,0x01,0x00,0x01,0x38,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff};
93 static UCHAR WMT_PATCH_P_ADDRESS_EVT[] = {0x02,0x08,0x04,0x00,0x00,0x00,0x00,0x01};
96 static UCHAR WMT_PATCH_CMD[] = {0x01, 0x01, 0x00, 0x00, 0x00};
97 static UCHAR WMT_PATCH_EVT[] = {0x02, 0x01, 0x01, 0x00, 0x00};
98 static UCHAR WMT_RESET_CMD[] = {0x01, 0x07, 0x01, 0x00, 0x04};
99 static UCHAR WMT_RESET_EVT[] = {0x02, 0x07, 0x01, 0x00, 0x00};
101 static UCHAR WMT_BTP2_CMD[] = {0x01, 0x10, 0x03, 0x00, 0x01, 0x03, 0x01};
102 static UCHAR WMT_BTP2_EVT[] = {0x02, 0x10, 0x01, 0x00, 0x00};
105 static UCHAR WMT_COEX_SETTING_CONFIG_CMD[] = {0x01, 0x10, 0x04, 0x00, 0x01, 0xAA, 0xBB, 0xCC};
106 static UCHAR WMT_COEX_SETTING_CONFIG_EVT[] = {0x02, 0x10, 0x01, 0x00, 0x00};
107 static UCHAR WMT_BT_COEX_SETTING_CONFIG_CMD[] = {0x01, 0x10, 0x0B,
109 0x00, 0x00, 0x00, 0x00,
110 0xBB,0xCC,0xDD,0xEE,0xFF,0xAA};
111 static UCHAR WMT_BT_COEX_SETTING_CONFIG_EVT[] = {0x02, 0x10, 0x01, 0x00, 0x00};
112 static UCHAR WMT_WIFI_COEX_SETTING_CONFIG_CMD[] = {0x01, 0x10, 0x0C,
114 0x00, 0x00,0x00,0x00,0x00,
115 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0xAA};
116 static UCHAR WMT_WIFI_COEX_SETTING_CONFIG_EVT[] = {0x02, 0x10, 0x01, 0x00, 0x00};
117 static UCHAR WMT_PTA_COEX_SETTING_CONFIG_CMD[] = {0x01, 0x10, 0x0A,
119 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xEE, 0xFF, 0xFF, 0xFE};
120 static UCHAR WMT_PTA_COEX_SETTING_CONFIG_EVT[] = {0x02, 0x10, 0x01, 0x00, 0x00};
121 static UCHAR WMT_MISC_COEX_SETTING_CONFIG_CMD[] = {0x01, 0x10, 0x09,
123 0xAA, 0xAA, 0xAA, 0xAA,
124 0xBB, 0xBB, 0xBB, 0xBB};
125 static UCHAR WMT_MISC_COEX_SETTING_CONFIG_EVT[] = {0x02, 0x10, 0x01, 0x00, 0x00};
127 static UCHAR WMT_SET_STP_CMD[] = {0x01, 0x04, 0x05, 0x00, 0x03, 0xDF, 0x0E, 0x68, 0x01};
128 static UCHAR WMT_SET_STP_EVT[] = {0x02, 0x04, 0x02, 0x00, 0x00, 0x03};
129 static UCHAR WMT_STRAP_CONF_CMD_FM_COMM[] = {0x01, 0x05, 0x02, 0x00, 0x02, 0x02};
130 static UCHAR WMT_STRAP_CONF_EVT[] = {0x02, 0x05, 0x02, 0x00, 0x00, 0x02};
132 static UCHAR WMT_SET_OSC32K_BYPASS_CMD[]= {0x01, 0x0A, 0x01, 0x00, 0x05};
133 static UCHAR WMT_SET_OSC32K_BYPASS_EVT[]= {0x02, 0x0A, 0x01, 0x00, 0x00};
136 static UCHAR WMT_CORE_DUMP_LEVEL_04_CMD[] = {0x1, 0x0F, 0x07, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
137 static UCHAR WMT_CORE_DUMP_LEVEL_04_EVT[] = {0x2, 0x0F, 0x01, 0x00, 0x00};
139 /* enable all interrupt */
140 static UCHAR WMT_SET_ALLINT_REG_CMD[] = {0x01, 0x08, 0x10, 0x00/*length*/
144 ,0x01 /*1 registers*/
145 ,0x00, 0x03, 0x05, 0x80/*addr:0x80050300*/
146 ,0x00, 0xC4, 0x00, 0x00/*value:0x0000C400*/
147 ,0x00, 0xC4, 0x00, 0x00/*mask:0x0000C400*/
150 static UCHAR WMT_SET_ALLINT_REG_EVT[] = {0x02, 0x08, 0x04, 0x00/*length*/
154 ,0x01 /*1 registers*/
157 #if CFG_SET_OPT_REG_SWLA /* enable swla: eesk(7) eecs(8) oscen(19) sck0(24) scs0(25) */
158 static UCHAR WMT_SET_SWLA_REG_CMD[] = {0x01, 0x08, 0x1C, 0x00/*length*/
162 ,0x02 /*2 registers*/
163 ,0x10, 0x01, 0x05, 0x80/*addr:0x80050110*/
164 ,0x10, 0x10, 0x01, 0x00/*value:0x00011010*/
165 ,0xF0, 0xF0, 0x0F, 0x00/*mask:0x000FF0F0*/
166 ,0x40, 0x01, 0x05, 0x80/*addr:0x80050140*/
167 ,0x00, 0x10, 0x01, 0x00/*value:0x00011000*/
168 ,0x00, 0xF0, 0x0F, 0x00/*mask:0x000FF000*/
170 static UCHAR WMT_SET_SWLA_REG_EVT[] = {0x02, 0x08, 0x04, 0x00/*length*/
174 ,0x02 /*2 registers*/
178 #if CFG_SET_OPT_REG_MCUCLK /* enable mcu clk: antsel_4, eedi */
179 static UCHAR WMT_SET_MCUCLK_REG_CMD[] = {0x01, 0x08, (4 + 12*4), 0x00/*length*/
181 ,0x01 /* type: reg */
183 ,0x04 /* 4 registers */
184 ,0x00, 0x04, 0x00, 0x80 /* addr:0x8000 0400 */
185 ,0x00, 0x14, 0x00, 0x00 /* value:0x0000 1400(osc, hclk), 0x0000 1501(PLL, en) */
186 ,0xFF, 0xFF, 0x00, 0x00 /* mask:0x0000 FFFF */
187 ,0x80, 0x01, 0x05, 0x80 /* addr:0x8005 0180 */
188 ,0x12, 0x13, 0x00, 0x00 /* value:0x0000 1312(osc, hclk), 0x0000 1a19(PLL, en) */
189 ,0xFF, 0xFF, 0x00, 0x00 /* mask:0x0000 FFFF */
190 ,0x00, 0x01, 0x05, 0x80 /* addr:0x8005 0100 */
191 ,0x00, 0x00, 0x02, 0x00 /* value:0x0002 0000 */
192 ,0x00, 0x00, 0x0F, 0x00 /* mask:0x000F 0000 */
193 ,0x10, 0x01, 0x05, 0x80 /* addr:0x8005 0110 */
194 ,0x02, 0x00, 0x00, 0x00 /* value:0x0000 0002 */
195 ,0x0F, 0x00, 0x00, 0x00 /* mask:0x0000 000F */
198 static UCHAR WMT_SET_MCUCLK_REG_EVT[] = {0x02, 0x08, 0x04, 0x00/*length*/
200 ,0x00 /* type: reg */
202 ,0x04 /* 4 registers */
206 #if CFG_WMT_I2S_DBGUART_SUPPORT /* register write for debug uart */
207 static UCHAR WMT_SET_DBGUART_REG_CMD[] = {0x01, 0x08, 0x1C, 0x00/*length*/
211 ,0x02 /*2 registers*/
212 ,0x30, 0x01, 0x05, 0x80/*addr:0x80050130*/
213 ,0x00, 0x00, 0x00, 0x00/*value:0x00000000*/
214 ,0xF0, 0x0F, 0x00, 0x00/*mask:0x00000FF0*/
215 ,0x40, 0x01, 0x05, 0x80/*addr:0x80050140*/
216 ,0x00, 0x01, 0x00, 0x00/*value:0x00000100*/
217 ,0x00, 0x01, 0x00, 0x00/*mask:0x00000100*/
219 static UCHAR WMT_SET_DBGUART_REG_EVT[] = {0x02, 0x08, 0x04, 0x00/*length*/
223 ,0x02 /*2 registers*/
227 #if CFG_SET_OPT_REG_MCUIRQ /* enable mcu irq: antsel_4, wlan_act */
229 static UCHAR WMT_SET_MCUIRQ_REG_CMD[] = {0x01, 0x08, (4 + 12*4), 0x00/*length*/
231 ,0x01 /* type: reg */
233 ,0x04 /* 4 registers */
234 ,0x00, 0x04, 0x00, 0x80 /* addr:0x8000_0400 */
235 ,0x03, 0x14, 0x00, 0x00 /* value:0x0000_1403 check confg debug flag 3 low word */
236 ,0xFF, 0xFF, 0x00, 0x00 /* mask:0x0000_FFFF */
238 ,0x10, 0x01, 0x05, 0x80 /* addr:0x8005_0110 */
239 ,0x02, 0x00, 0x00, 0x00 /* value:0x0000_0002 set EEDI as cirq_int_n debug flag (monitor flag2) */
240 ,0x07, 0x00, 0x00, 0x00 /* mask:0x0000_0007 */
241 ,0x00, 0x01, 0x05, 0x80 /* addr:0x8005_0100 */
242 ,0x00, 0x00, 0x02, 0x00 /* value:0x0002_0000 (ANTSEL4=>monitor flag 0, ahb_x2_gt_ck debug flag) */
243 ,0x00, 0x00, 0x07, 0x00 /* mask:0x0007_0000 */
244 /* 1. ARM irq_b, monitor flag 0 */
245 ,0x80, 0x01, 0x05, 0x80 /* addr:0x8005_0180 */
246 ,0x1F, 0x1E, 0x00, 0x00 /* value:0x0000_1E1F check mcusys debug flag */
247 ,0x7F, 0x7F, 0x00, 0x00 /* mask:0x0000_7F7F */
250 static UCHAR WMT_SET_MCUIRQ_REG_EVT[] = {0x02, 0x08, 0x04, 0x00/*length*/
252 ,0x00 /* type: reg */
254 ,0x04 /* 5 registers */
257 static UCHAR WMT_SET_MCUIRQ_REG_CMD[] = {0x01, 0x08, (4 + 12*5), 0x00/*length*/
259 ,0x01 /* type: reg */
261 ,0x05 /* 5 registers */
262 ,0x00, 0x04, 0x00, 0x80 /* addr:0x8000_0400 */
263 ,0x00, 0x02, 0x00, 0x00 /* value:0x0000_0200 [15:8]=0x2 arm irq_b, 0xA irq_bus[5] bt_timcon_irq_b */
264 ,0x00, 0xFF, 0x00, 0x00 /* mask:0x0000_FF00 */
265 /* 1. ARM irq_b, monitor flag 0 */
266 ,0x80, 0x01, 0x05, 0x80 /* addr:0x8005_0180 */
267 ,0x18, 0x00, 0x00, 0x00 /* value:0x0000_0018 [6:0]=001_1000 (monitor flag 0 select, MCUSYS, SEL:8) */
268 ,0x7F, 0x00, 0x00, 0x00 /* mask:0x0000_007F */
269 ,0x00, 0x01, 0x05, 0x80 /* addr:0x8005_0100 */
270 ,0x00, 0x00, 0x02, 0x00 /* value:0x0002_0000 (ANTSEL4=>monitor flag 0) */
271 ,0x00, 0x00, 0x07, 0x00 /* mask:0x0007_0000 */
272 /* 2. irq_bus[5] bt_timcon_irq_b monitor flag 15 */
273 ,0xB0, 0x01, 0x05, 0x80 /* addr:0x8005_01B0 */
274 ,0x00, 0x00, 0x00, 0x16 /* value:0x1600_0000 [30:24]=001_0110 (monitor flag 15 select, MCUSYS, SEL:6) */
275 ,0x00, 0x00, 0x00, 0x7F /* mask:0x7F00_0000 */
276 ,0x30, 0x01, 0x05, 0x80 /* addr:0x8005_0130 */
277 ,0x00, 0x20, 0x00, 0x00 /* value:0x0000_2000 (WLAN_ACT=>monitor flag 15) */
278 ,0x00, 0x70, 0x00, 0x00 /* mask:0x0000_7000 */
281 static UCHAR WMT_SET_MCUIRQ_REG_EVT[] = {0x02, 0x08, 0x04, 0x00/*length*/
283 ,0x00 /* type: reg */
285 ,0x05 /* 5 registers */
290 /* stp sdio init scripts */
291 static struct init_script init_table_1_1[] =
293 /* table_1_1 is only applied to common SDIO interface */
294 INIT_CMD(WMT_SET_ALLINT_REG_CMD, WMT_SET_ALLINT_REG_EVT, "enable all interrupt"),
295 /* only applied to MT6620 E1/E2? */
296 INIT_CMD(WMT_WAKEUP_DIS_GATE_CMD, WMT_WAKEUP_DIS_GATE_EVT, "disable gating"),
300 static struct init_script init_table_1_2[] =
302 INIT_CMD(WMT_QUERY_BAUD_CMD, WMT_QUERY_BAUD_EVT_115200, "query baud 115200"),
303 INIT_CMD(WMT_QUERY_STP_CMD, WMT_QUERY_STP_EVT_DEFAULT, "query stp default"),
304 INIT_CMD(WMT_SET_BAUD_CMD_X, WMT_SET_BAUD_EVT, "set baud rate"),
307 static struct init_script init_table_2[] =
309 INIT_CMD(WMT_QUERY_BAUD_CMD, WMT_QUERY_BAUD_EVT_X, "query baud X"),
312 static struct init_script init_table_3[] =
314 INIT_CMD(WMT_RESET_CMD, WMT_RESET_EVT, "wmt reset"),
316 INIT_CMD(WMT_BTP2_CMD, WMT_BTP2_EVT, "set bt port2"),
321 static struct init_script init_table_3_1[] =
323 INIT_CMD(WMT_WAKEUP_EN_GATE_CMD, WMT_WAKEUP_EN_GATE_EVT, "ensable gating"),
327 static struct init_script init_table_4[] =
329 INIT_CMD(WMT_SET_STP_CMD, WMT_SET_STP_EVT, "set stp"),
332 static struct init_script init_table_5[] =
334 INIT_CMD(WMT_QUERY_STP_CMD, WMT_QUERY_STP_EVT_UART, "query stp uart"),
335 INIT_CMD(WMT_QUERY_BAUD_CMD, WMT_QUERY_BAUD_EVT_X, "query baud X"),
338 static struct init_script init_table_5_1[] = {
339 INIT_CMD(WMT_STRAP_CONF_CMD_FM_COMM, WMT_STRAP_CONF_EVT, "configure FM comm"),
342 static struct init_script init_table_6[] =
345 INIT_CMD(WMT_SET_OSC32K_BYPASS_CMD, WMT_SET_OSC32K_BYPASS_EVT, "set OSC32k by pass mode."),
347 INIT_CMD(WMT_CORE_DUMP_LEVEL_04_CMD,WMT_CORE_DUMP_LEVEL_04_EVT,"setup core dump level"),
350 #if defined(CFG_SET_OPT_REG) && CFG_SET_OPT_REG
351 static struct init_script set_registers[] =
353 //INIT_CMD(WMT_SET_GPS_REG_CMD, WMT_SET_GPS_REG_EVT, "set wmt registers"),
354 //INIT_CMD(WMT_SET_SDIODRV_REG_CMD, WMT_SET_SDIODRV_REG_EVT, "set SDIO driving registers")
355 #if CFG_WMT_I2S_DBGUART_SUPPORT
356 INIT_CMD(WMT_SET_DBGUART_REG_CMD, WMT_SET_DBGUART_REG_EVT, "set debug uart registers"),
358 #if CFG_SET_OPT_REG_SWLA
359 INIT_CMD(WMT_SET_SWLA_REG_CMD, WMT_SET_SWLA_REG_EVT, "set swla registers"),
361 #if CFG_SET_OPT_REG_MCUCLK
362 INIT_CMD(WMT_SET_MCUCLK_REG_CMD, WMT_SET_MCUCLK_REG_EVT, "set mcuclk dbg registers"),
364 #if CFG_SET_OPT_REG_MCUIRQ
365 INIT_CMD(WMT_SET_MCUIRQ_REG_CMD, WMT_SET_MCUIRQ_REG_EVT, "set mcu irq dbg registers"),
370 static struct init_script coex_table[] = {
371 INIT_CMD(WMT_COEX_SETTING_CONFIG_CMD, WMT_COEX_SETTING_CONFIG_EVT, "coex_wmt"),
372 INIT_CMD(WMT_BT_COEX_SETTING_CONFIG_CMD, WMT_BT_COEX_SETTING_CONFIG_EVT, "coex_bt"),
373 INIT_CMD(WMT_WIFI_COEX_SETTING_CONFIG_CMD, WMT_WIFI_COEX_SETTING_CONFIG_EVT, "coex_wifi"),
374 INIT_CMD(WMT_PTA_COEX_SETTING_CONFIG_CMD, WMT_PTA_COEX_SETTING_CONFIG_EVT, "coex_ext_pta"),
375 INIT_CMD(WMT_MISC_COEX_SETTING_CONFIG_CMD, WMT_MISC_COEX_SETTING_CONFIG_EVT, "coex_misc"),
378 /* MT6620 Chip Version and Info Table */
379 static const WMT_IC_INFO_S mt6620_info_table[] = {
382 .cChipName = WMT_IC_NAME_MT6620,
383 .cChipVersion = WMT_IC_VER_E1,
384 .cPatchNameExt = WMT_IC_PATCH_NO_EXT,
385 .eWmtHwVer = WMTHWVER_MT6620_E1,
386 .bWorkWithoutPatch = MTK_WCN_BOOL_FALSE,
387 .bPsmSupport = MTK_WCN_BOOL_FALSE,
391 .cChipName = WMT_IC_NAME_MT6620,
392 .cChipVersion = WMT_IC_VER_E2,
393 .cPatchNameExt = WMT_IC_PATCH_NO_EXT,
394 .eWmtHwVer = WMTHWVER_MT6620_E2,
395 .bWorkWithoutPatch = MTK_WCN_BOOL_FALSE,
396 .bPsmSupport = MTK_WCN_BOOL_FALSE,
400 .cChipName = WMT_IC_NAME_MT6620,
401 .cChipVersion = WMT_IC_VER_E3,
402 .cPatchNameExt = WMT_IC_PATCH_E3_EXT,
403 .eWmtHwVer = WMTHWVER_MT6620_E3,
404 .bWorkWithoutPatch = MTK_WCN_BOOL_FALSE,
405 .bPsmSupport = MTK_WCN_BOOL_TRUE,
409 .cChipName = WMT_IC_NAME_MT6620,
410 .cChipVersion = WMT_IC_VER_E4,
411 .cPatchNameExt = WMT_IC_PATCH_E3_EXT,
412 .eWmtHwVer = WMTHWVER_MT6620_E4,
413 .bWorkWithoutPatch = MTK_WCN_BOOL_FALSE,
414 .bPsmSupport = MTK_WCN_BOOL_TRUE,
418 .cChipName = WMT_IC_NAME_MT6620,
419 .cChipVersion = WMT_IC_VER_E6,
420 .cPatchNameExt = WMT_IC_PATCH_E6_EXT,
421 .eWmtHwVer = WMTHWVER_MT6620_E6,
422 .bWorkWithoutPatch = MTK_WCN_BOOL_TRUE /*MTK_WCN_BOOL_FALSE*/,
423 .bPsmSupport = MTK_WCN_BOOL_TRUE,
427 .cChipName = WMT_IC_NAME_MT6620,
428 .cChipVersion = WMT_IC_VER_E6,
429 .cPatchNameExt = WMT_IC_PATCH_E6_EXT,
430 .eWmtHwVer = WMTHWVER_MT6620_E6,
431 .bWorkWithoutPatch = MTK_WCN_BOOL_TRUE /*MTK_WCN_BOOL_FALSE*/,
432 .bPsmSupport = MTK_WCN_BOOL_TRUE,
436 .cChipName = WMT_IC_NAME_MT6620,
437 .cChipVersion = WMT_IC_VER_E7,
438 .cPatchNameExt = WMT_IC_PATCH_E6_EXT,
439 .eWmtHwVer = WMTHWVER_MT6620_E7,
440 .bWorkWithoutPatch = MTK_WCN_BOOL_TRUE /*MTK_WCN_BOOL_FALSE*/,
441 .bPsmSupport = MTK_WCN_BOOL_TRUE,
445 /*******************************************************************************
446 * F U N C T I O N D E C L A R A T I O N S
447 ********************************************************************************
452 P_WMT_HIF_CONF pWmtHifConf
457 P_WMT_HIF_CONF pWmtHifConf
463 WMT_IC_PIN_STATE state,
469 WMT_IC_PIN_STATE state,
474 mt6620_ver_check (VOID);
476 static const WMT_IC_INFO_S*
477 mt6620_find_wmt_ic_info (
482 wmt_stp_init_coex (VOID);
484 #if CFG_WMT_MULTI_PATCH
486 mt6620_patch_dwn (UINT32 index);
487 static INT32 mt6620_patch_info_prepare(VOID);
490 mt6620_update_patch_name (VOID);
493 mt6620_patch_dwn (VOID);
495 static MTK_WCN_BOOL mt6620_quick_sleep_flag_get(VOID);
497 /*******************************************************************************
498 * P U B L I C D A T A
499 ********************************************************************************
502 /* MT6620 Operation Function Table */
503 const WMT_IC_OPS wmt_ic_ops_mt6620 = {
505 .sw_init = mt6620_sw_init,
506 .sw_deinit = mt6620_sw_deinit,
507 .ic_pin_ctrl = mt6620_pin_ctrl,
508 .ic_ver_check = mt6620_ver_check,
509 .co_clock_ctrl = NULL,
510 .is_quick_sleep = mt6620_quick_sleep_flag_get,
511 .is_aee_dump_support = NULL,
514 /*******************************************************************************
516 ********************************************************************************
521 P_WMT_HIF_CONF pWmtHifConf
531 WMT_DBG_FUNC(" start\n");
533 osal_assert(NULL != gp_mt6620_info);
534 if ( (NULL == gp_mt6620_info)
535 || (NULL == pWmtHifConf)
537 WMT_ERR_FUNC("null pointers: gp_mt6620_info(0x%p), pWmtHifConf(0x%p)\n",
538 gp_mt6620_info, pWmtHifConf);
542 hw_ver = gp_mt6620_info->u4HwVer;
544 //4 <3.1> start init for sdio
545 if (WMT_HIF_SDIO == pWmtHifConf->hifType) {
546 /* 1. enable all INT32 */
547 /* 2. disable mcu gate (only MT6620E1/E2) */
548 iRet = wmt_core_init_script(init_table_1_1, osal_array_size(init_table_1_1));
550 WMT_ERR_FUNC("init_table_1_1 fail:%d\n", iRet);
556 //4 <3.2> start init for uart
557 if (WMT_HIF_UART == pWmtHifConf->hifType) {
558 /* init variable fields for script execution */
559 osal_memcpy(&WMT_SET_BAUD_CMD_X[5], &pWmtHifConf->au4HifConf[0], osal_sizeof(UINT32));
560 WMT_SET_BAUD_CMD_X[8] = (UCHAR)0x00;//0xC0 MTK Flow Control /* no flow control */
561 osal_memcpy(&WMT_QUERY_BAUD_EVT_X[6], &pWmtHifConf->au4HifConf[0], osal_sizeof(UINT32));
562 WMT_QUERY_BAUD_EVT_X[9] = (UCHAR)0x00; //0xC0 MTK Flow Control /* no flow control */
564 /* 3. Query chip baud rate (TEST-ONLY) */
565 /* 4. Query chip STP options (TEST-ONLY) */
566 /* 5. Change chip baud rate: t_baud */
567 //WMT_DBG_FUNC("WMT-CORE: init_table_1_2 set chip baud:%d", pWmtHifConf->au4HifConf[0]);
568 iRet = wmt_core_init_script(init_table_1_2, osal_array_size(init_table_1_2));
570 WMT_ERR_FUNC("init_table_1_2 fail(%d)\n", iRet);
575 /* 6. Set host baudrate and flow control*/
576 ctrlPa1 = pWmtHifConf->au4HifConf[0]; ctrlPa2 = 0;
577 iRet = wmt_core_ctrl(WMT_CTRL_HOST_BAUDRATE_SET, &ctrlPa1, &ctrlPa2);
579 WMT_ERR_FUNC("change baudrate(%d) fail(%d)\n", pWmtHifConf->au4HifConf[0], iRet);
582 WMT_INFO_FUNC("WMT-CORE: change baudrate(%d) ok\n", pWmtHifConf->au4HifConf[0]);
584 /* 7. Wake up chip and check event */
585 // iRet = (*kal_stp_tx_raw)(&WMT_SET_WAKEUP_WAKE_CMD_RAW[0], 1, &u4Res);
586 iRet = wmt_core_tx((PUINT8)&WMT_SET_WAKEUP_WAKE_CMD_RAW[0], 1, &u4Res, MTK_WCN_BOOL_TRUE);
587 if (iRet || (u4Res != 1)) {
588 WMT_ERR_FUNC("write raw iRet(%d) written(%d)\n", iRet, u4Res);
592 osal_memset(evtBuf, 0, osal_sizeof(evtBuf));
593 iRet = wmt_core_rx(evtBuf, osal_sizeof(WMT_SET_WAKEUP_WAKE_EVT), &u4Res);
595 WMT_DBG_FUNC("WAKEUP_WAKE_EVT read len %d [%02x,%02x,%02x,%02x,%02x,%02x]\n",
596 (INT32)u4Res, evtBuf[0], evtBuf[1], evtBuf[2], evtBuf[3], evtBuf[4], evtBuf[5]);
598 if (iRet || (u4Res != osal_sizeof(WMT_SET_WAKEUP_WAKE_EVT))) {
599 WMT_ERR_FUNC("read WAKEUP_WAKE_EVT fail(%d)\n", iRet);
602 //WMT_DBG_FUNC("WMT-CORE: read WMT_SET_WAKEUP_WAKE_EVT ok");
604 #if CFG_CHECK_WMT_RESULT
605 if (osal_memcmp(evtBuf, WMT_SET_WAKEUP_WAKE_EVT, osal_sizeof(WMT_SET_WAKEUP_WAKE_EVT)) != 0) {
606 WMT_ERR_FUNC("WMT-CORE: write WMT_SET_WAKEUP_WAKE_CMD_RAW status fail\n");
611 /* 8. Query baud rate (TEST-ONLY) */
612 iRet = wmt_core_init_script(init_table_2, osal_array_size(init_table_2));
614 WMT_ERR_FUNC("init_table_2 fail(%d)\n", iRet);
619 /* 9. download patch */
620 iRet = mt6620_patch_dwn();
622 WMT_INFO_FUNC("Not to check the patch validity\n");
625 WMT_ERR_FUNC("patch dwn fail (%d)\n", iRet);
629 WMT_INFO_FUNC("patch dwn ok\n");
632 /* 10. WMT Reset command */
633 iRet = wmt_core_init_script(init_table_3, osal_array_size(init_table_3));
635 WMT_ERR_FUNC("init_table_3 fail(%d)\n", iRet);
638 iRet = wmt_stp_init_coex();
640 WMT_ERR_FUNC("init_coex fail(%d)\n", iRet);
644 WMT_INFO_FUNC("init_coex ok\n");
648 /*10-2 enable 32K By Pass Mode*/
649 //if hwVer = E3/E4, please enable 32K by pass mode.
650 //does not support mt6620E1/E2, always enable 32k bypass mode
651 //if ((hwVer == 0x8a10 || hwVer == 0x8a11))
653 WMT_INFO_FUNC("WMT-CORE: init_table_6 OSC32K");
654 iRet = wmt_core_init_script(init_table_6, osal_array_size(init_table_6));
656 WMT_DBG_FUNC("WMT-CORE: init_table_6 OSC32K, successful\n");
659 WMT_WARN_FUNC("init table 6 OSC32K fail, continue init...\n");
665 if (WMT_HIF_UART == pWmtHifConf->hifType) {
666 /* 11. Set chip STP options */
667 iRet = wmt_core_init_script(init_table_4, osal_array_size(init_table_4));
669 WMT_ERR_FUNC("init_table_4 fail(%d)\n", iRet);
673 /* 12. Enable host STP-UART mode */
674 ctrlPa1 = WMT_STP_CONF_MODE; ctrlPa2 = MTKSTP_UART_FULL_MODE;
675 iRet = wmt_core_ctrl(WMT_CTRL_STP_CONF, &ctrlPa1, &ctrlPa2);
676 ctrlPa1 = WMT_STP_CONF_EN; ctrlPa2 = 1;
677 iRet += wmt_core_ctrl(WMT_CTRL_STP_CONF, &ctrlPa1, &ctrlPa2);
679 WMT_ERR_FUNC("enable host STP-UART-FULL mode fail(%d)\n", iRet);
682 WMT_INFO_FUNC("enable host STP-UART-FULL mode\n");
683 /*13. wait for 10ms, enough for chip do mechanism switch.(at least 2ms is needed)*/
685 /* 14. Query chip STP options (TEST-ONLY) */
686 /* 15. Query baud rate (stp, TEST-ONLY) */
687 iRet = wmt_core_init_script(init_table_5, osal_array_size(init_table_5));
689 WMT_ERR_FUNC("init_table_5 fail(%d)\n", iRet);
694 /* 15. Set FM strap */
695 WMT_STRAP_CONF_CMD_FM_COMM[5] = (UCHAR)pWmtHifConf->au4StrapConf[0];
696 WMT_STRAP_CONF_EVT[5] = (UCHAR)pWmtHifConf->au4StrapConf[0];
697 iRet = wmt_core_init_script(init_table_5_1, osal_array_size(init_table_5_1));
699 WMT_ERR_FUNC("init_table_5_1 fm mode(%d) fail(%d)\n",
700 pWmtHifConf->au4StrapConf[0],
704 WMT_INFO_FUNC("set fm mode (%d) ok\n", pWmtHifConf->au4StrapConf[0]);
706 #if CFG_SET_OPT_REG /*set registers*/
707 iRet = wmt_core_init_script(set_registers, osal_array_size(set_registers));
709 WMT_ERR_FUNC("set_registers fail(%d)", iRet);
715 /* 16. trace32 dump when fw assert*/
717 INT32 val = 0x00000001;
718 WMT_INFO_FUNC("WMT-CORE: enable assert dump");
719 wmt_reg_rw_raw(1, 0x0100092c, &val, 0xFFFFFFFF);
723 #if CFG_WMT_PS_SUPPORT
724 osal_assert(NULL != gp_mt6620_info);
725 if (NULL != gp_mt6620_info) {
726 if (MTK_WCN_BOOL_FALSE != gp_mt6620_info->bPsmSupport) {
730 wmt_lib_ps_disable();
741 P_WMT_HIF_CONF pWmtHifConf
750 UINT32 patch_num = 0;
751 UINT32 patch_index = 0;
752 WMT_DBG_FUNC(" start\n");
754 osal_assert(NULL != gp_mt6620_info);
755 if ( (NULL == gp_mt6620_info)
756 || (NULL == pWmtHifConf)
758 WMT_ERR_FUNC("null pointers: gp_mt6620_info(0x%p), pWmtHifConf(0x%p)\n",
759 gp_mt6620_info, pWmtHifConf);
763 hw_ver = gp_mt6620_info->u4HwVer;
765 //4 <3.1> start init for sdio
766 if (WMT_HIF_SDIO == pWmtHifConf->hifType) {
767 /* 1. enable all INT32 */
768 /* 2. disable mcu gate (only MT6620E1/E2) */
769 iRet = wmt_core_init_script(init_table_1_1, osal_array_size(init_table_1_1));
771 WMT_ERR_FUNC("init_table_1_1 fail:%d\n", iRet);
777 //4 <3.2> start init for uart
778 if (WMT_HIF_UART == pWmtHifConf->hifType) {
780 /* init variable fields for script execution */
781 osal_memcpy(&WMT_SET_BAUD_CMD_X[5], &pWmtHifConf->au4HifConf[0], osal_sizeof(UINT32));
782 osal_memcpy(&WMT_QUERY_BAUD_EVT_X[6], &pWmtHifConf->au4HifConf[0], osal_sizeof(UINT32));
783 if (WMT_UART_MTK_SW_FC == pWmtHifConf->uartFcCtrl)
785 WMT_INFO_FUNC("enable MTK SW Flow Control\n");
786 WMT_SET_BAUD_CMD_X[8] = (UCHAR)0x80;//* MTK SW flow control */
787 WMT_QUERY_BAUD_EVT_X[9] = (UCHAR)0x80; //* MTK SW flow control */
789 else if (WMT_UART_LUX_SW_FC == pWmtHifConf->uartFcCtrl)
791 WMT_INFO_FUNC("enable Linux SW Flow Control\n");
792 WMT_SET_BAUD_CMD_X[8] = (UCHAR)0x80;//* Linux SW flow control */
793 WMT_QUERY_BAUD_EVT_X[9] = (UCHAR)0x80; //* Linux SW flow control */
795 else if (WMT_UART_HW_FC == pWmtHifConf->uartFcCtrl)
797 WMT_INFO_FUNC("enable HW Flow Control\n");
798 WMT_SET_BAUD_CMD_X[8] = (UCHAR)0xC0;//* HW flow control */
799 WMT_QUERY_BAUD_EVT_X[9] = (UCHAR)0xC0; //* HW flow control */
802 /* WMT_UART_NO_FC and all other cases!!! */
803 WMT_INFO_FUNC("no Flow Control (uartFcCtrl:%d)\n", pWmtHifConf->uartFcCtrl);
804 WMT_SET_BAUD_CMD_X[8] = (UCHAR)0x00;//* no flow control */
805 WMT_QUERY_BAUD_EVT_X[9] = (UCHAR)0x00; //* no flow control */
808 /* 3. Query chip baud rate (TEST-ONLY) */
809 /* 4. Query chip STP options (TEST-ONLY) */
810 /* 5. Change chip baud rate: t_baud */
811 //WMT_DBG_FUNC("WMT-CORE: init_table_1_2 set chip baud:%d", pWmtHifConf->au4HifConf[0]);
812 iRet = wmt_core_init_script(init_table_1_2, osal_array_size(init_table_1_2));
814 WMT_ERR_FUNC("init_table_1_2 fail(%d)\n", iRet);
819 /* 6. Set host baudrate and flow control*/
820 ctrlPa1 = pWmtHifConf->au4HifConf[0]; ctrlPa2 = 0;
821 iRet = wmt_core_ctrl(WMT_CTRL_HOST_BAUDRATE_SET, &ctrlPa1, &ctrlPa2);
823 WMT_ERR_FUNC("change baudrate(%d) fail(%d)\n", pWmtHifConf->au4HifConf[0], iRet);
826 WMT_INFO_FUNC("WMT-CORE: change baudrate(%d) ok\n", pWmtHifConf->au4HifConf[0]);
828 /* 7. Wake up chip and check event */
829 // iRet = (*kal_stp_tx_raw)(&WMT_SET_WAKEUP_WAKE_CMD_RAW[0], 1, &u4Res);
830 iRet = wmt_core_tx((PUINT8)&WMT_SET_WAKEUP_WAKE_CMD_RAW[0], 1, &u4Res, MTK_WCN_BOOL_TRUE);
831 if (iRet || (u4Res != 1)) {
832 WMT_ERR_FUNC("write raw iRet(%d) written(%d)\n", iRet, u4Res);
836 osal_memset(evtBuf, 0, osal_sizeof(evtBuf));
837 iRet = wmt_core_rx(evtBuf, osal_sizeof(WMT_SET_WAKEUP_WAKE_EVT), &u4Res);
839 WMT_DBG_FUNC("WAKEUP_WAKE_EVT read len %d [%02x,%02x,%02x,%02x,%02x,%02x]\n",
840 (INT32)u4Res, evtBuf[0], evtBuf[1], evtBuf[2], evtBuf[3], evtBuf[4], evtBuf[5]);
842 if (iRet || (u4Res != osal_sizeof(WMT_SET_WAKEUP_WAKE_EVT))) {
843 WMT_ERR_FUNC("read WAKEUP_WAKE_EVT fail(%d)\n", iRet);
846 //WMT_DBG_FUNC("WMT-CORE: read WMT_SET_WAKEUP_WAKE_EVT ok");
848 #if CFG_CHECK_WMT_RESULT
849 if (osal_memcmp(evtBuf, WMT_SET_WAKEUP_WAKE_EVT, osal_sizeof(WMT_SET_WAKEUP_WAKE_EVT)) != 0) {
850 WMT_ERR_FUNC("WMT-CORE: write WMT_SET_WAKEUP_WAKE_CMD_RAW status fail\n");
855 /* 8. Query baud rate (TEST-ONLY) */
856 iRet = wmt_core_init_script(init_table_2, osal_array_size(init_table_2));
858 WMT_ERR_FUNC("init_table_2 fail(%d)\n", iRet);
862 if (WMT_HIF_UART == pWmtHifConf->hifType) {
863 /* 9. Set chip STP options */
864 iRet = wmt_core_init_script(init_table_4, osal_array_size(init_table_4));
866 WMT_ERR_FUNC("init_table_4 fail(%d)\n", iRet);
870 /* 10. Enable host STP-UART mode */
871 ctrlPa1 = WMT_STP_CONF_MODE; ctrlPa2 = MTKSTP_UART_FULL_MODE;
872 iRet = wmt_core_ctrl(WMT_CTRL_STP_CONF, &ctrlPa1, &ctrlPa2);
873 ctrlPa1 = WMT_STP_CONF_EN; ctrlPa2 = 1;
874 iRet += wmt_core_ctrl(WMT_CTRL_STP_CONF, &ctrlPa1, &ctrlPa2);
876 WMT_ERR_FUNC("enable host STP-UART-FULL mode fail(%d)\n", iRet);
879 WMT_INFO_FUNC("enable host STP-UART-FULL mode\n");
880 /*10. wait for 10ms, enough for chip do mechanism switch.(at least 2ms is needed)*/
882 /* 11. Query chip STP options (TEST-ONLY) */
883 /* 12. Query baud rate (stp, TEST-ONLY) */
884 iRet = wmt_core_init_script(init_table_5, osal_array_size(init_table_5));
886 WMT_ERR_FUNC("init_table_5 fail(%d)\n", iRet);
890 /* 13. download patch */
891 #if CFG_WMT_MULTI_PATCH
892 iRet = mt6620_patch_info_prepare();
895 WMT_ERR_FUNC("patch info perpare fail(%d)\n",iRet);
899 ctrlPa1 = 0;ctrlPa2 = 0;
900 wmt_core_ctrl(WMT_CTRL_GET_PATCH_NUM,&ctrlPa1,&ctrlPa2);
902 WMT_INFO_FUNC("patch total num = [%d]\n",patch_num);
904 for(patch_index = 0;patch_index < patch_num;patch_index++)
906 iRet = mt6620_patch_dwn(patch_index);
908 WMT_ERR_FUNC("patch dwn fail (%d),patch_index(%d)\n", iRet,patch_index);
911 iRet = wmt_core_init_script(init_table_3, osal_array_size(init_table_3));
913 WMT_ERR_FUNC("init_table_3 fail(%d)\n", iRet);
918 iRet = mt6620_patch_dwn();
920 WMT_INFO_FUNC("Not to check the patch validity\n");
923 WMT_ERR_FUNC("patch dwn fail (%d)\n", iRet);
927 WMT_INFO_FUNC("patch dwn ok\n");
930 /* 14. WMT Reset command */
931 iRet = wmt_core_init_script(init_table_3, osal_array_size(init_table_3));
933 WMT_ERR_FUNC("init_table_3 fail(%d)\n", iRet);
937 iRet = wmt_stp_init_coex();
939 WMT_ERR_FUNC("init_coex fail(%d)\n", iRet);
943 WMT_INFO_FUNC("init_coex ok\n");
947 /*10-2 enable 32K By Pass Mode*/
948 //if hwVer = E3/E4, please enable 32K by pass mode.
949 //does not support mt6620E1/E2, always enable 32k bypass mode
950 //if ((hwVer == 0x8a10 || hwVer == 0x8a11))
952 WMT_INFO_FUNC("WMT-CORE: init_table_6 OSC32K");
953 iRet = wmt_core_init_script(init_table_6, osal_array_size(init_table_6));
955 WMT_DBG_FUNC("WMT-CORE: init_table_6 OSC32K, successful\n");
958 WMT_WARN_FUNC("init table 6 OSC32K fail, continue init...\n");
966 /* 15. Set FM strap */
967 WMT_STRAP_CONF_CMD_FM_COMM[5] = (UCHAR)pWmtHifConf->au4StrapConf[0];
968 WMT_STRAP_CONF_EVT[5] = (UCHAR)pWmtHifConf->au4StrapConf[0];
969 iRet = wmt_core_init_script(init_table_5_1, osal_array_size(init_table_5_1));
971 WMT_ERR_FUNC("init_table_5_1 fm mode(%d) fail(%d)\n",
972 pWmtHifConf->au4StrapConf[0],
976 WMT_INFO_FUNC("set fm mode (%d) ok\n", pWmtHifConf->au4StrapConf[0]);
978 #if CFG_SET_OPT_REG /*set registers*/
979 iRet = wmt_core_init_script(set_registers, osal_array_size(set_registers));
981 WMT_ERR_FUNC("set_registers fail(%d)", iRet);
987 /* 16. trace32 dump when fw assert*/
989 INT32 val = 0x00000001;
990 WMT_INFO_FUNC("WMT-CORE: enable assert dump");
991 wmt_reg_rw_raw(1, 0x0100092c, &val, 0xFFFFFFFF);
995 #if CFG_WMT_COREDUMP_ENABLE
996 /*Open Core Dump Function @QC begin*/
997 mtk_wcn_stp_coredump_flag_ctrl(1);
999 if (0 != mtk_wcn_stp_coredump_flag_get())
1001 iRet = wmt_core_init_script(init_table_6, osal_array_size(init_table_6));
1003 WMT_ERR_FUNC("init_table_6 core dump setting fail(%d)\n",
1007 WMT_INFO_FUNC("enable mt662x firmware coredump\n");
1012 WMT_INFO_FUNC("disable mt662x firmware coredump\n");
1015 #if CFG_WMT_PS_SUPPORT
1016 osal_assert(NULL != gp_mt6620_info);
1017 if (NULL != gp_mt6620_info) {
1018 if (MTK_WCN_BOOL_FALSE != gp_mt6620_info->bPsmSupport) {
1019 wmt_lib_ps_enable();
1022 wmt_lib_ps_disable();
1033 P_WMT_HIF_CONF pWmtHifConf
1036 WMT_DBG_FUNC(" start\n");
1038 #if CFG_WMT_PS_SUPPORT
1039 osal_assert(NULL != gp_mt6620_info);
1040 if ( (NULL != gp_mt6620_info)
1041 && (MTK_WCN_BOOL_FALSE != gp_mt6620_info->bPsmSupport) ) {
1042 wmt_lib_ps_disable();
1046 gp_mt6620_info = NULL;
1053 WMT_IC_PIN_STATE state,
1060 if ( (flag & WMT_LIB_AIF_FLAG_MASK) == WMT_LIB_AIF_FLAG_SHARE ) {
1061 WMT_INFO_FUNC("PCM & I2S PIN SHARE\n");
1064 /* BT_PCM_OFF & FM line in/out */
1066 ret = wmt_core_reg_rw_raw(1, 0x80050140, &val, 0x00000FF0);
1068 ret += wmt_core_reg_rw_raw(1, 0x80050150, &val, 0x00000800);
1072 /* BT_PCM_ON & FM line in/out */
1074 ret = wmt_core_reg_rw_raw(1, 0x80050140, &val, 0x00000FF0);
1076 ret += wmt_core_reg_rw_raw(1, 0x80050150, &val, 0x00000800);
1080 /* BT_PCM_OFF & FM I2S */
1082 ret = wmt_core_reg_rw_raw(1, 0x80050140, &val, 0x00000FF0);
1083 val = 0x00000800; /* 800:3-wire, 000: 4-wire */
1084 ret += wmt_core_reg_rw_raw(1, 0x80050150, &val, 0x00000800);
1087 WMT_ERR_FUNC("unsupported state (%d) \n", state);
1093 /*PCM & I2S separate*/
1094 WMT_INFO_FUNC("PCM & I2S PIN SEPARATE\n");
1097 /* BT_PCM_OFF & FM line in/out */
1099 ret = wmt_core_reg_rw_raw(1, 0x80050140, &val, 0x00000FF0);
1101 ret += wmt_core_reg_rw_raw(1, 0x80050150, &val, 0x00000800);
1105 /* BT_PCM_ON & FM line in/out */
1107 ret = wmt_core_reg_rw_raw(1, 0x80050140, &val, 0x00000FF0);
1109 ret += wmt_core_reg_rw_raw(1, 0x80050150, &val, 0x00000800);
1113 /* BT_PCM_OFF & FM I2S */
1115 ret = wmt_core_reg_rw_raw(1, 0x80050140, &val, 0x00000FF0);
1116 val = 0x00000800; /* 800:3-wire, 000: 4-wire */
1117 ret += wmt_core_reg_rw_raw(1, 0x80050150, &val, 0x00000800);
1122 ret = wmt_core_reg_rw_raw(1, 0x80050140, &val, 0x00000FF0);
1123 val = 0x00000800; /* 800:3-wire, 000: 4-wire */
1124 ret += wmt_core_reg_rw_raw(1, 0x80050150, &val, 0x00000800);
1127 WMT_ERR_FUNC("unsupported state (%d) \n", state);
1134 WMT_INFO_FUNC("new state(%d) ok\n", state);
1137 WMT_WARN_FUNC("new state(%d) fail(%d)\n", state, ret);
1146 WMT_IC_PIN_STATE state,
1152 WMT_DBG_FUNC("ic pin id:%d, state:%d, flag:0x%x\n", id , state, flag);
1156 case WMT_IC_PIN_AUDIO:
1157 ret = mt6620_aif_ctrl(state, flag);
1160 case WMT_IC_PIN_EEDI:
1161 WMT_WARN_FUNC("TBD!!");
1165 case WMT_IC_PIN_EEDO:
1166 WMT_WARN_FUNC("TBD!!");
1169 case WMT_IC_PIN_GSYNC:
1171 WMT_WARN_FUNC("TBD!!");
1176 WMT_INFO_FUNC("ret = (%d)\n" , ret);
1182 static MTK_WCN_BOOL mt6620_quick_sleep_flag_get(VOID)
1184 return MTK_WCN_BOOL_FALSE;
1190 mt6620_ver_check (VOID)
1195 const WMT_IC_INFO_S *p_info;
1199 /* 1. identify chip versions: HVR(HW_VER) and FVR(FW_VER) */
1200 WMT_LOUD_FUNC("MT6620: before read hw_ver (hw version)\n");
1201 iret = wmt_core_reg_rw_raw(0, GEN_HVR, &hw_ver, GEN_VER_MASK);
1203 WMT_ERR_FUNC("MT6620: read hw_ver fail:%d\n", iret);
1206 WMT_INFO_FUNC("MT6620: read hw_ver (hw version) (0x%x)\n", hw_ver);
1208 WMT_LOUD_FUNC("MT6620: before fw_ver (rom version) \n");
1209 wmt_core_reg_rw_raw(0, GEN_FVR, &fw_ver, GEN_VER_MASK);
1211 WMT_ERR_FUNC("MT6620: read fw_ver fail:%d\n", iret);
1214 WMT_INFO_FUNC("MT6620: read fw_ver (rom version) (0x%x)\n", fw_ver);
1216 p_info = mt6620_find_wmt_ic_info(hw_ver);
1217 if (NULL == p_info) {
1218 WMT_ERR_FUNC("MT6620: hw_ver(0x%x) find wmt ic info fail\n");
1222 WMT_INFO_FUNC("MT6620: wmt ic info: %s.%s (0x%x, WMTHWVER:%d, patch_ext:%s)\n",
1223 p_info->cChipName, p_info->cChipVersion,
1224 p_info->u4HwVer, p_info->eWmtHwVer,
1225 p_info->cPatchNameExt);
1227 /* hw id & version */
1228 ctrlPa1 = (0x00006620UL << 16) | (hw_ver & 0x0000FFFF);
1229 /* translated hw version & fw rom version */
1230 ctrlPa2 = ((UINT32)(p_info->eWmtHwVer) << 16) | (fw_ver & 0x0000FFFF);
1232 iret = wmt_core_ctrl(WMT_CTRL_HWIDVER_SET, &ctrlPa1, &ctrlPa2);
1234 WMT_WARN_FUNC("MT6620: WMT_CTRL_HWIDVER_SET fail(%d)\n", iret);
1237 gp_mt6620_info = p_info;
1241 static const WMT_IC_INFO_S*
1242 mt6620_find_wmt_ic_info (
1246 /* match chipversion with u4HwVer item in mt6620_info_table */
1247 const UINT32 size = osal_array_size(mt6620_info_table);
1250 /* George: reverse the search order to favor newer version products */
1251 // TODO:[FixMe][GeorgeKuo] Remove full match once API wmt_lib_get_hwver() is changed correctly in the future!!
1252 // Leave full match here is a workaround for GPS to distinguish E3/E4 ICs.
1255 while ( (0 <= index)
1256 && (hw_ver != mt6620_info_table[index].u4HwVer) /* full match */
1261 WMT_INFO_FUNC("found ic info(0x%x) by full match! index:%d\n", hw_ver, index);
1262 return &mt6620_info_table[index];
1265 WMT_WARN_FUNC("find no ic info for (0x%x) by full match!try major num match!\n", hw_ver);
1267 /* George: The ONLY CORRECT method to find supported hw table. Match MAJOR
1268 * NUM only can help us support future minor hw ECO, or fab switch, etc.
1269 * FULL matching eliminate such flexibility and software package have to be
1270 * updated EACH TIME even when minor hw ECO or fab switch!!!
1272 /* George: reverse the search order to favor newer version products */
1274 /* major num match */
1275 while ( (0 <= index)
1276 && (MAJORNUM(hw_ver) != MAJORNUM(mt6620_info_table[index].u4HwVer))
1281 WMT_INFO_FUNC("MT6620: found ic info for hw_ver(0x%x) by major num! index:%d\n", hw_ver, index);
1282 return &mt6620_info_table[index];
1285 WMT_ERR_FUNC("MT6620: find no ic info for hw_ver(0x%x) by full match nor major num match!\n", hw_ver);
1291 wmt_stp_init_coex (VOID)
1295 WMT_GEN_CONF *pWmtGenConf;
1304 iRet = wmt_core_ctrl(WMT_CTRL_GET_WMT_CONF, &addr, 0);
1306 WMT_ERR_FUNC("ctrl GET_WMT_CONF fail(%d)\n", iRet);
1309 WMT_INFO_FUNC("ctrl GET_WMT_CONF ok(0x%08lx)\n", addr);
1311 pWmtGenConf = (P_WMT_GEN_CONF)addr;
1313 /*Check if WMT.cfg exists*/
1314 if (pWmtGenConf->cfgExist == 0) {
1315 WMT_INFO_FUNC("cfgExist == 0, skip config chip\n");
1316 /*if WMT.cfg not existed, still return success and adopt the default value*/
1320 /*Dump the coex-related info*/
1321 WMT_DBG_FUNC("coex_wmt:0x%x 0x%x 0x%x\n",
1322 pWmtGenConf->coex_wmt_ant_mode,
1323 pWmtGenConf->coex_wmt_wifi_time_ctl,
1324 pWmtGenConf->coex_wmt_ext_pta_dev_on
1326 WMT_DBG_FUNC("coex_bt:0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1327 pWmtGenConf->coex_bt_rssi_upper_limit,
1328 pWmtGenConf->coex_bt_rssi_mid_limit,
1329 pWmtGenConf->coex_bt_rssi_lower_limit,
1330 pWmtGenConf->coex_bt_pwr_high,
1331 pWmtGenConf->coex_bt_pwr_mid,
1332 pWmtGenConf->coex_bt_pwr_low
1334 WMT_DBG_FUNC("coex_wifi:0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1335 pWmtGenConf->coex_wifi_rssi_upper_limit,
1336 pWmtGenConf->coex_wifi_rssi_mid_limit,
1337 pWmtGenConf->coex_wifi_rssi_lower_limit,
1338 pWmtGenConf->coex_wifi_pwr_high,
1339 pWmtGenConf->coex_wifi_pwr_mid,
1340 pWmtGenConf->coex_wifi_pwr_low
1342 WMT_DBG_FUNC("coex_ext_pta:0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1343 pWmtGenConf->coex_ext_pta_hi_tx_tag,
1344 pWmtGenConf->coex_ext_pta_hi_rx_tag,
1345 pWmtGenConf->coex_ext_pta_lo_tx_tag,
1346 pWmtGenConf->coex_ext_pta_lo_rx_tag,
1347 pWmtGenConf->coex_ext_pta_sample_t1,
1348 pWmtGenConf->coex_ext_pta_sample_t2,
1349 pWmtGenConf->coex_ext_pta_wifi_bt_con_trx
1351 WMT_DBG_FUNC("coex_misc:0x%x 0x%x 0x%x\n",
1352 pWmtGenConf->coex_misc_ext_pta_on,
1353 pWmtGenConf->coex_misc_ext_feature_set
1356 /*command adjustion due to WMT.cfg*/
1357 coex_table[COEX_WMT].cmd[5]= pWmtGenConf->coex_wmt_ant_mode;
1358 coex_table[COEX_WMT].cmd[6]= pWmtGenConf->coex_wmt_wifi_time_ctl;
1359 coex_table[COEX_WMT].cmd[7]= pWmtGenConf->coex_wmt_ext_pta_dev_on;
1360 if (gWmtDbgLvl >= WMT_LOG_DBG) {
1361 wmt_core_dump_data(&coex_table[COEX_WMT].cmd[0],
1362 coex_table[COEX_WMT].str,
1363 coex_table[COEX_WMT].cmdSz);
1366 coex_table[COEX_BT].cmd[9]= pWmtGenConf->coex_bt_rssi_upper_limit;
1367 coex_table[COEX_BT].cmd[10]= pWmtGenConf->coex_bt_rssi_mid_limit;
1368 coex_table[COEX_BT].cmd[11]= pWmtGenConf->coex_bt_rssi_lower_limit;
1369 coex_table[COEX_BT].cmd[12]= pWmtGenConf->coex_bt_pwr_high;
1370 coex_table[COEX_BT].cmd[13]= pWmtGenConf->coex_bt_pwr_mid;
1371 coex_table[COEX_BT].cmd[14]= pWmtGenConf->coex_bt_pwr_low;
1372 if (gWmtDbgLvl >= WMT_LOG_DBG) {
1373 wmt_core_dump_data(&coex_table[COEX_BT].cmd[0],
1374 coex_table[COEX_BT].str,
1375 coex_table[COEX_BT].cmdSz);
1377 coex_table[COEX_WIFI].cmd[10]= pWmtGenConf->coex_wifi_rssi_upper_limit;
1378 coex_table[COEX_WIFI].cmd[11]= pWmtGenConf->coex_wifi_rssi_mid_limit;
1379 coex_table[COEX_WIFI].cmd[12]= pWmtGenConf->coex_wifi_rssi_lower_limit;
1380 coex_table[COEX_WIFI].cmd[13]= pWmtGenConf->coex_wifi_pwr_high;
1381 coex_table[COEX_WIFI].cmd[14]= pWmtGenConf->coex_wifi_pwr_mid;
1382 coex_table[COEX_WIFI].cmd[15]= pWmtGenConf->coex_wifi_pwr_low;
1383 if (gWmtDbgLvl >= WMT_LOG_DBG) {
1384 wmt_core_dump_data(&coex_table[COEX_WIFI].cmd[0],
1385 coex_table[COEX_WIFI].str,
1386 coex_table[COEX_WIFI].cmdSz);
1388 coex_table[COEX_PTA].cmd[5]= pWmtGenConf->coex_ext_pta_hi_tx_tag;
1389 coex_table[COEX_PTA].cmd[6]= pWmtGenConf->coex_ext_pta_hi_rx_tag;
1390 coex_table[COEX_PTA].cmd[7]= pWmtGenConf->coex_ext_pta_lo_tx_tag;
1391 coex_table[COEX_PTA].cmd[8]= pWmtGenConf->coex_ext_pta_lo_rx_tag;
1392 coex_table[COEX_PTA].cmd[9]= ((pWmtGenConf->coex_ext_pta_sample_t1 & 0xff00) >> 8);
1393 coex_table[COEX_PTA].cmd[10]= ((pWmtGenConf->coex_ext_pta_sample_t1 & 0x00ff) >> 0);
1394 coex_table[COEX_PTA].cmd[11]= ((pWmtGenConf->coex_ext_pta_sample_t2 & 0xff00) >> 8);
1395 coex_table[COEX_PTA].cmd[12]= ((pWmtGenConf->coex_ext_pta_sample_t2 & 0x00ff) >> 0);
1396 coex_table[COEX_PTA].cmd[13]= pWmtGenConf->coex_ext_pta_wifi_bt_con_trx;
1397 if (gWmtDbgLvl >= WMT_LOG_DBG) {
1398 wmt_core_dump_data(&coex_table[COEX_PTA].cmd[0],
1399 coex_table[COEX_PTA].str,
1400 coex_table[COEX_PTA].cmdSz);
1403 osal_memcpy(&coex_table[COEX_MISC].cmd[5], &pWmtGenConf->coex_misc_ext_pta_on, sizeof(pWmtGenConf->coex_misc_ext_pta_on));
1404 osal_memcpy(&coex_table[COEX_MISC].cmd[9], &pWmtGenConf->coex_misc_ext_feature_set, sizeof(pWmtGenConf->coex_misc_ext_feature_set));
1405 if (gWmtDbgLvl >= WMT_LOG_DBG) {
1406 wmt_core_dump_data(& coex_table[COEX_MISC].cmd[0], coex_table[COEX_MISC].str, coex_table[COEX_MISC].cmdSz);
1408 iRet = wmt_core_init_script(coex_table, sizeof(coex_table)/sizeof(coex_table[0]));
1413 #if CFG_WMT_MULTI_PATCH
1415 static INT32 mt6620_patch_info_prepare(VOID)
1418 WMT_CTRL_DATA ctrlData;
1420 ctrlData.ctrlId = WMT_CTRL_PATCH_SEARCH;
1421 iRet = wmt_ctrl(&ctrlData);
1426 mt6620_patch_dwn (UINT32 index)
1429 P_WMT_PATCH patchHdr = NULL;
1431 UINT32 patchSize = 0;
1434 UINT16 fragSize = 0;
1438 UINT8 patchevtBuf[8];
1439 UINT8 addressevtBuf[12];
1440 UCHAR addressByte[4];
1441 PCHAR cDataTime = NULL;
1442 /*PCHAR cPlat = NULL;*/
1445 UINT32 u4PatchVer = 0;
1446 UINT32 patchSizePerFrag = 0;
1447 WMT_CTRL_DATA ctrlData;
1449 /*1.check hardware information */
1450 if (NULL == gp_mt6620_info) {
1451 WMT_ERR_FUNC("null gp_mt6620_info!\n");
1455 osal_memset(gFullPatchName,0,osal_sizeof(gFullPatchName));
1457 ctrlData.ctrlId = WMT_CTRL_GET_PATCH_INFO;
1458 ctrlData.au4CtrlData[0] = index + 1;
1459 ctrlData.au4CtrlData[1] = (UINT32)&gFullPatchName;
1460 ctrlData.au4CtrlData[2] = (UINT32)&addressByte;
1461 iRet = wmt_ctrl(&ctrlData);
1462 WMT_INFO_FUNC("the %d time valid patch found: (%s)\n", index+1,gFullPatchName);
1463 //<2.2> read patch content
1464 ctrlData.ctrlId = WMT_CTRL_GET_PATCH;
1465 ctrlData.au4CtrlData[0] = (UINT32)NULL;
1466 ctrlData.au4CtrlData[1] = (UINT32)&gFullPatchName;
1468 ctrlData.au4CtrlData[2] = (UINT32)&pbuf;
1469 ctrlData.au4CtrlData[3] = (UINT32)&patchSize;
1470 iRet = wmt_ctrl(&ctrlData);
1472 WMT_ERR_FUNC("wmt_core: WMT_CTRL_GET_PATCH fail:%d \n", iRet);
1477 /* |<-BCNT_PATCH_BUF_HEADROOM(8) bytes dummy allocated->|<-patch file->| */
1478 pbuf += BCNT_PATCH_BUF_HEADROOM;
1479 /* patch file with header:
1480 * |<-patch header: 28 Bytes->|<-patch body: X Bytes ----->|
1482 patchHdr = (P_WMT_PATCH)pbuf;
1483 // check patch file information
1485 cDataTime = patchHdr->ucDateTime;
1486 u2HwVer = patchHdr->u2HwVer;
1487 u2SwVer = patchHdr->u2SwVer;
1488 u4PatchVer = patchHdr->u4PatchVer;
1489 /*cPlat = &patchHdr->ucPLat[0];*/
1490 cDataTime[15] = '\0';
1492 /* remove patch header:
1493 * |<-patch body: X Bytes (X=patchSize)--->|
1495 patchSize -= sizeof(WMT_PATCH);
1496 pbuf += sizeof(WMT_PATCH);
1500 WMT_INFO_FUNC("===========================================\n");
1501 WMT_INFO_FUNC("[Combo Patch] Built Time = %s\n", cDataTime);
1502 WMT_INFO_FUNC("[Combo Patch] Hw Ver = 0x%x\n", ((u2HwVer & 0x00ff) << 8) | ((u2HwVer & 0xff00) >> 8));
1503 WMT_INFO_FUNC("[Combo Patch] Sw Ver = 0x%x\n", ((u2SwVer & 0x00ff) << 8) | ((u2SwVer & 0xff00) >> 8));
1504 WMT_INFO_FUNC("[Combo Patch] Ph Ver = 0x%04x\n", ((u4PatchVer & 0xff000000) >> 24) | ((u4PatchVer & 0x00ff0000) >> 16));
1505 WMT_INFO_FUNC("[Combo Patch] Platform = %c%c%c%c\n", patchHdr->ucPLat[0],
1506 patchHdr->ucPLat[1], patchHdr->ucPLat[2], patchHdr->ucPLat[3]);
1507 WMT_INFO_FUNC("[Combo Patch] Content Size = 0x%x\n", patchSize);
1508 WMT_INFO_FUNC("[Combo Patch] Content CRC = 0x%04x\n", osal_crc16(pbuf, patchSize));
1509 WMT_INFO_FUNC("===========================================\n");
1512 patchSizePerFrag = (MAJORNUM(gp_mt6620_info->u4HwVer) != 0) ?
1513 DEFAULT_PATCH_FRAG_SIZE : MT6620E2_PATCH_FRAG_SIZE;
1515 /* reserve 1st patch cmd space before patch body
1516 * |<-WMT_CMD: 5Bytes->|<-patch body: X Bytes (X=patchSize)----->|
1518 pbuf -= sizeof(WMT_PATCH_CMD);
1520 fragNum = patchSize / patchSizePerFrag;
1521 fragNum += ((fragNum * patchSizePerFrag) == patchSize) ? 0 : 1;
1523 WMT_DBG_FUNC("patch size(%d) fragNum(%d)\n", patchSize, fragNum);
1525 /*send wmt part patch address command*/
1526 iRet = wmt_core_tx((PUINT8)&WMT_PATCH_ADDRESS_CMD[0],sizeof(WMT_PATCH_ADDRESS_CMD),&u4Res,MTK_WCN_BOOL_FALSE);
1527 if(iRet || (u4Res != sizeof(WMT_PATCH_ADDRESS_CMD)))
1529 WMT_ERR_FUNC("wmt_core:wmt patch address CMD fail(%d),size(%d)\n",iRet,u4Res);
1533 osal_memset(addressevtBuf,0,sizeof(addressevtBuf));
1534 iRet = wmt_core_rx(addressevtBuf,sizeof(WMT_PATCH_ADDRESS_EVT),&u4Res);
1535 if(iRet || (u4Res != sizeof(WMT_PATCH_ADDRESS_EVT)))
1537 WMT_ERR_FUNC("wmt_core:wmt patch address EVT fail(%d),size(%d)\n",iRet,u4Res);
1541 #if CFG_CHECK_WMT_RESULT
1542 if (osal_memcmp(addressevtBuf, WMT_PATCH_ADDRESS_EVT, osal_sizeof(WMT_PATCH_ADDRESS_EVT)) != 0) {
1543 WMT_ERR_FUNC("wmt_core: write WMT_PATCH_ADDRESS_CMD status fail\n");
1549 /*send part patch address command*/
1550 osal_memcpy(&WMT_PATCH_P_ADDRESS_CMD[12], addressByte,osal_sizeof(addressByte));
1551 WMT_INFO_FUNC("4 bytes address command:0x%02x,0x%02x,0x%02x,0x%02x",WMT_PATCH_P_ADDRESS_CMD[12],WMT_PATCH_P_ADDRESS_CMD[13],WMT_PATCH_P_ADDRESS_CMD[14],WMT_PATCH_P_ADDRESS_CMD[15]);
1552 iRet = wmt_core_tx((PUINT8)&WMT_PATCH_P_ADDRESS_CMD[0],sizeof(WMT_PATCH_P_ADDRESS_CMD),&u4Res,MTK_WCN_BOOL_FALSE);
1553 if(iRet || (u4Res != sizeof(WMT_PATCH_P_ADDRESS_CMD)))
1555 WMT_ERR_FUNC("wmt_core:wmt part patch address CMD fail(%d),size(%d),index(%d)\n",iRet,u4Res,index);
1559 osal_memset(addressevtBuf,0,sizeof(addressevtBuf));
1560 iRet = wmt_core_rx(addressevtBuf,sizeof(WMT_PATCH_P_ADDRESS_EVT),&u4Res);
1561 if(iRet || (u4Res != sizeof(WMT_PATCH_P_ADDRESS_EVT)))
1563 WMT_ERR_FUNC("wmt_core:wmt patch address EVT fail(%d),size(%d),index(%d)\n",iRet,u4Res,index);
1567 #if CFG_CHECK_WMT_RESULT
1568 if (osal_memcmp(addressevtBuf, WMT_PATCH_P_ADDRESS_EVT, osal_sizeof(WMT_PATCH_ADDRESS_EVT)) != 0) {
1569 WMT_ERR_FUNC("wmt_core: write WMT_PATCH_ADDRESS_CMD status fail,index(%d)\n",index);
1574 /* send all fragments */
1575 offset = sizeof(WMT_PATCH_CMD);
1577 while (fragSeq < fragNum) {
1578 WMT_DBG_FUNC("patch size(%d) fragNum(%d)\n", patchSize, fragNum);
1579 if (fragSeq == (fragNum-1)) {
1581 fragSize = patchSize - fragSeq * patchSizePerFrag;
1582 WMT_PATCH_CMD[4] = WMT_PATCH_FRAG_LAST;
1585 fragSize = patchSizePerFrag;
1586 WMT_PATCH_CMD[4] = (fragSeq == 0) ? WMT_PATCH_FRAG_1ST: WMT_PATCH_FRAG_MID;
1588 /* update length field in CMD:flag+frag*/
1589 cmdLen = 1 + fragSize;
1590 osal_memcpy(&WMT_PATCH_CMD[2], &cmdLen, 2);
1591 /* copy patch CMD to buf (overwrite last 5-byte in prev frag) */
1592 osal_memcpy(pbuf + offset - sizeof(WMT_PATCH_CMD), WMT_PATCH_CMD, sizeof(WMT_PATCH_CMD));
1594 //iRet = (*kal_stp_tx)(pbuf + offset - sizeof(WMT_PATCH_CMD), fragSize + sizeof(WMT_PATCH_CMD), &u4Res);
1595 iRet = wmt_core_tx(pbuf + offset - sizeof(WMT_PATCH_CMD), fragSize + sizeof(WMT_PATCH_CMD), &u4Res, MTK_WCN_BOOL_FALSE);
1596 if (iRet || (u4Res != fragSize + sizeof(WMT_PATCH_CMD))) {
1597 WMT_ERR_FUNC("wmt_core: write fragSeq(%d) size(%d, %d) fail(%d)\n", fragSeq, fragSize + sizeof(WMT_PATCH_CMD), u4Res, iRet );
1601 WMT_DBG_FUNC("wmt_core: write fragSeq(%d) size(%d, %d) ok\n",
1602 fragSeq, fragSize + sizeof(WMT_PATCH_CMD), u4Res);
1604 osal_memset(patchevtBuf, 0, sizeof(patchevtBuf));
1605 //iRet = (*kal_stp_rx)(evtBuf, sizeof(WMT_PATCH_EVT), &u4Res);
1606 iRet = wmt_core_rx(patchevtBuf, sizeof(WMT_PATCH_EVT), &u4Res);
1607 if (iRet || (u4Res != sizeof(WMT_PATCH_EVT))) {
1608 WMT_ERR_FUNC("wmt_core: read WMT_PATCH_EVT length(%d, %d) fail(%d)\n", sizeof(WMT_PATCH_EVT), u4Res, iRet);
1612 #if CFG_CHECK_WMT_RESULT
1613 if (osal_memcmp(patchevtBuf, WMT_PATCH_EVT, sizeof(WMT_PATCH_EVT)) != 0) {
1614 WMT_ERR_FUNC("wmt_core: compare WMT_PATCH_EVT result error rx(%d):[%02X,%02X,%02X,%02X,%02X] exp(%d):[%02X,%02X,%02X,%02X,%02X]\n",
1615 u4Res, patchevtBuf[0], patchevtBuf[1], patchevtBuf[2], patchevtBuf[3], patchevtBuf[4], sizeof(WMT_PATCH_EVT), WMT_PATCH_EVT[0], WMT_PATCH_EVT[1], WMT_PATCH_EVT[2], WMT_PATCH_EVT[3], WMT_PATCH_EVT[4]);
1620 WMT_DBG_FUNC("wmt_core: read WMT_PATCH_EVT length(%d, %d) ok\n",
1621 sizeof(WMT_PATCH_EVT), u4Res);
1624 WMT_DBG_FUNC("wmt_core: send patch frag(%d) [%02X,%02X,%02X,%02X,%02X] (%d) ok",
1625 fragSeq, WMT_PATCH_CMD[0], WMT_PATCH_CMD[1], WMT_PATCH_CMD[2],
1626 WMT_PATCH_CMD[3], WMT_PATCH_CMD[4], fragSize);
1629 offset += patchSizePerFrag;
1633 WMT_INFO_FUNC("wmt_core: patch dwn:%d frag(%d, %d) %s\n",
1634 iRet, fragSeq, fragSize, (!iRet && (fragSeq == fragNum)) ? "ok": "fail");
1636 if (fragSeq != fragNum) {
1640 /* WMT_CTRL_FREE_PATCH always return 0 */
1641 ctrlData.ctrlId = WMT_CTRL_FREE_PATCH;
1642 ctrlData.au4CtrlData[0] = index + 1;
1643 wmt_ctrl(&ctrlData);
1644 //wmt_core_ctrl(WMT_CTRL_FREE_PATCH, NULL, NULL);
1645 if ( (iRet == -2) || (iRet == -3) ) {
1646 /*no patch found or patch version does not match with hw version, we check if patch is mandatory or not, if yes, return iRet, if not return 0*/
1647 if (MTK_WCN_BOOL_FALSE != gp_mt6620_info->bWorkWithoutPatch) {
1658 mt6620_patch_dwn (VOID)
1661 P_WMT_PATCH patchHdr;
1666 UINT16 fragSize = 0;
1671 PCHAR cDataTime = NULL;
1672 /*PCHAR cPlat = NULL;*/
1675 UINT32 u4PatchVer = 0;
1676 UINT32 patchSizePerFrag = 0;
1677 WMT_CTRL_DATA ctrlData;
1679 /*1.check hardware information */
1680 if (NULL == gp_mt6620_info) {
1681 WMT_ERR_FUNC("null gp_mt6620_info!\n");
1685 ctrlData.ctrlId = WMT_CTRL_GET_PATCH_NAME;
1686 ctrlData.au4CtrlData[0] = (UINT32)&gDefPatchName;
1687 iRet = wmt_ctrl(&ctrlData);
1689 if (mt6620_update_patch_name()) {
1690 WMT_ERR_FUNC("invalid patch name, ommit patch download process.\n");
1694 ctrlData.ctrlId = WMT_CTRL_GET_PATCH;
1695 ctrlData.au4CtrlData[0] = (UINT32)&gDefPatchName;
1696 ctrlData.au4CtrlData[1] = (UINT32)&gFullPatchName;
1697 ctrlData.au4CtrlData[2] = (UINT32)&pbuf;
1698 ctrlData.au4CtrlData[3] = (UINT32)&patchSize;
1699 iRet = wmt_ctrl(&ctrlData);
1701 WMT_ERR_FUNC("wmt_core: WMT_CTRL_GET_PATCH fail:%d \n", iRet);
1706 //<2> search patch and read patch content
1707 //<2.1> search patch
1708 ctrlData.ctrlId = WMT_CTRL_PATCH_SEARCH;
1709 iRet = wmt_ctrl(&ctrlData);
1712 //patch with correct Hw Ver Major Num found
1713 ctrlData.ctrlId = WMT_CTRL_GET_PATCH_NAME;
1714 ctrlData.au4CtrlData[0] = (UINT32)&gFullPatchName;
1715 iRet = wmt_ctrl(&ctrlData);
1717 WMT_INFO_FUNC("valid patch found: (%s)\n", gFullPatchName);
1718 //<2.2> read patch content
1719 ctrlData.ctrlId = WMT_CTRL_GET_PATCH;
1720 ctrlData.au4CtrlData[0] = (UINT32)NULL;
1721 ctrlData.au4CtrlData[1] = (UINT32)&gFullPatchName;
1729 ctrlData.au4CtrlData[2] = (UINT32)&pbuf;
1730 ctrlData.au4CtrlData[3] = (UINT32)&patchSize;
1731 iRet = wmt_ctrl(&ctrlData);
1733 WMT_ERR_FUNC("wmt_core: WMT_CTRL_GET_PATCH fail:%d \n", iRet);
1740 /* |<-BCNT_PATCH_BUF_HEADROOM(8) bytes dummy allocated->|<-patch file->| */
1741 pbuf += BCNT_PATCH_BUF_HEADROOM;
1742 /* patch file with header:
1743 * |<-patch header: 28 Bytes->|<-patch body: X Bytes ----->|
1745 patchHdr = (P_WMT_PATCH)pbuf;
1746 // check patch file information
1748 cDataTime = patchHdr->ucDateTime;
1749 u2HwVer = patchHdr->u2HwVer;
1750 u2SwVer = patchHdr->u2SwVer;
1751 u4PatchVer = patchHdr->u4PatchVer;
1752 /*cPlat = &patchHdr->ucPLat[0];*/
1754 cDataTime[15] = '\0';
1756 /* remove patch header:
1757 * |<-patch body: X Bytes (X=patchSize)--->|
1759 patchSize -= sizeof(WMT_PATCH);
1760 pbuf += sizeof(WMT_PATCH);
1761 WMT_INFO_FUNC("===========================================\n");
1762 WMT_INFO_FUNC("[Combo Patch] Built Time = %s\n", cDataTime);
1763 WMT_INFO_FUNC("[Combo Patch] Hw Ver = 0x%x\n", ((u2HwVer & 0x00ff) << 8) | ((u2HwVer & 0xff00) >> 8));
1764 WMT_INFO_FUNC("[Combo Patch] Sw Ver = 0x%x\n", ((u2SwVer & 0x00ff) << 8) | ((u2SwVer & 0xff00) >> 8));
1765 WMT_INFO_FUNC("[Combo Patch] Ph Ver = 0x%04x\n", ((u4PatchVer & 0xff000000) >> 24) | ((u4PatchVer & 0x00ff0000) >> 16));
1766 WMT_INFO_FUNC("[Combo Patch] Platform = %c%c%c%c\n", patchHdr->ucPLat[0],
1767 patchHdr->ucPLat[1], patchHdr->ucPLat[2], patchHdr->ucPLat[3]);
1768 WMT_INFO_FUNC("[Combo Patch] Content Size = 0x%x\n", patchSize);
1769 WMT_INFO_FUNC("[Combo Patch] Content CRC = 0x%04x\n", osal_crc16(pbuf, patchSize));
1770 WMT_INFO_FUNC("===========================================\n");
1772 patchSizePerFrag = (MAJORNUM(gp_mt6620_info->u4HwVer) != 0) ?
1773 DEFAULT_PATCH_FRAG_SIZE : MT6620E2_PATCH_FRAG_SIZE;
1775 /* reserve 1st patch cmd space before patch body
1776 * |<-WMT_CMD: 5Bytes->|<-patch body: X Bytes (X=patchSize)----->|
1778 pbuf -= sizeof(WMT_PATCH_CMD);
1780 fragNum = patchSize / patchSizePerFrag;
1781 fragNum += ((fragNum * patchSizePerFrag) == patchSize) ? 0 : 1;
1783 WMT_DBG_FUNC("patch size(%d) fragNum(%d)\n", patchSize, fragNum);
1786 /* send all fragments */
1787 offset = sizeof(WMT_PATCH_CMD);
1789 while (fragSeq < fragNum) {
1790 WMT_DBG_FUNC("patch size(%d) fragNum(%d)\n", patchSize, fragNum);
1791 if (fragSeq == (fragNum-1)) {
1793 fragSize = patchSize - fragSeq * patchSizePerFrag;
1794 WMT_PATCH_CMD[4] = WMT_PATCH_FRAG_LAST;
1797 fragSize = patchSizePerFrag;
1798 WMT_PATCH_CMD[4] = (fragSeq == 0) ? WMT_PATCH_FRAG_1ST: WMT_PATCH_FRAG_MID;
1800 /* update length field in CMD:flag+frag*/
1801 cmdLen = 1 + fragSize;
1802 osal_memcpy(&WMT_PATCH_CMD[2], &cmdLen, 2);
1803 /* copy patch CMD to buf (overwrite last 5-byte in prev frag) */
1804 osal_memcpy(pbuf + offset - sizeof(WMT_PATCH_CMD), WMT_PATCH_CMD, sizeof(WMT_PATCH_CMD));
1806 //iRet = (*kal_stp_tx)(pbuf + offset - sizeof(WMT_PATCH_CMD), fragSize + sizeof(WMT_PATCH_CMD), &u4Res);
1807 iRet = wmt_core_tx(pbuf + offset - sizeof(WMT_PATCH_CMD), fragSize + sizeof(WMT_PATCH_CMD), &u4Res, MTK_WCN_BOOL_FALSE);
1808 if (iRet || (u4Res != fragSize + sizeof(WMT_PATCH_CMD))) {
1809 WMT_ERR_FUNC("wmt_core: write fragSeq(%d) size(%d, %d) fail(%d)\n", fragSeq, fragSize + sizeof(WMT_PATCH_CMD), u4Res, iRet );
1813 WMT_DBG_FUNC("wmt_core: write fragSeq(%d) size(%d, %d) ok\n",
1814 fragSeq, fragSize + sizeof(WMT_PATCH_CMD), u4Res);
1816 osal_memset(evtBuf, 0, sizeof(evtBuf));
1817 //iRet = (*kal_stp_rx)(evtBuf, sizeof(WMT_PATCH_EVT), &u4Res);
1818 iRet = wmt_core_rx(evtBuf, sizeof(WMT_PATCH_EVT), &u4Res);
1819 if (iRet || (u4Res != sizeof(WMT_PATCH_EVT))) {
1820 WMT_ERR_FUNC("wmt_core: read WMT_PATCH_EVT length(%d, %d) fail(%d)\n", sizeof(WMT_PATCH_EVT), u4Res, iRet);
1824 #if CFG_CHECK_WMT_RESULT
1825 if (osal_memcmp(evtBuf, WMT_PATCH_EVT, sizeof(WMT_PATCH_EVT)) != 0) {
1826 WMT_ERR_FUNC("wmt_core: compare WMT_PATCH_EVT result error rx(%d):[%02X,%02X,%02X,%02X,%02X] exp(%d):[%02X,%02X,%02X,%02X,%02X]\n",
1827 u4Res, evtBuf[0], evtBuf[1], evtBuf[2], evtBuf[3], evtBuf[4], sizeof(WMT_PATCH_EVT), WMT_PATCH_EVT[0], WMT_PATCH_EVT[1], WMT_PATCH_EVT[2], WMT_PATCH_EVT[3], WMT_PATCH_EVT[4]);
1832 WMT_DBG_FUNC("wmt_core: read WMT_PATCH_EVT length(%d, %d) ok\n",
1833 sizeof(WMT_PATCH_EVT), u4Res);
1836 WMT_DBG_FUNC("wmt_core: send patch frag(%d) [%02X,%02X,%02X,%02X,%02X] (%d) ok",
1837 fragSeq, WMT_PATCH_CMD[0], WMT_PATCH_CMD[1], WMT_PATCH_CMD[2],
1838 WMT_PATCH_CMD[3], WMT_PATCH_CMD[4], fragSize);
1841 offset += patchSizePerFrag;
1845 WMT_INFO_FUNC("wmt_core: patch dwn:%d frag(%d, %d) %s\n",
1846 iRet, fragSeq, fragSize, (!iRet && (fragSeq == fragNum)) ? "ok": "fail");
1848 if (fragSeq != fragNum) {
1852 /* WMT_CTRL_FREE_PATCH always return 0 */
1853 wmt_core_ctrl(WMT_CTRL_FREE_PATCH, NULL, NULL);
1854 if ( (iRet == -2) || (iRet == -3) ) {
1855 /*no patch found or patch version does not match with hw version, we check if patch is mandatory or not, if yes, return iRet, if not return 0*/
1856 if (MTK_WCN_BOOL_FALSE != gp_mt6620_info->bWorkWithoutPatch) {
1865 mt6620_update_patch_name (VOID)
1868 UCHAR cTmpPatchName[NAME_MAX + 1] = {0};
1870 /*init.get hardware version */
1871 // TODO:[FixMe][GeorgeKuo]: check using memcpy or strncpy???
1872 /*osal_memcpy (gFullPatchName, gDefPatchName, osal_strlen(gDefPatchName));*/
1873 osal_strncpy(gFullPatchName, gDefPatchName, osal_sizeof(gFullPatchName));
1875 /*1.check hardware information */
1876 if (NULL == gp_mt6620_info) {
1877 WMT_ERR_FUNC("null gp_mt6620_info!\n");
1878 osal_memset(gFullPatchName, 0, osal_sizeof(gFullPatchName));
1882 /*2.make possible firmware patch name with original name and hardware version*/
1883 if ( (osal_strlen(gDefPatchName) > osal_strlen(WMT_IC_PATCH_TAIL))
1884 && ((osal_strlen(gDefPatchName) + osal_strlen(WMT_IC_PATCH_DUMMY_EXT) <= NAME_MAX))
1886 len = osal_strlen(gDefPatchName) - osal_strlen(WMT_IC_PATCH_TAIL);
1887 osal_memcpy (cTmpPatchName, gDefPatchName, len > NAME_MAX ? NAME_MAX : len);
1888 osal_memcpy (cTmpPatchName + osal_strlen(cTmpPatchName), gp_mt6620_info->cPatchNameExt, osal_strlen(gp_mt6620_info->cPatchNameExt));
1889 osal_memcpy (cTmpPatchName + osal_strlen(cTmpPatchName), WMT_IC_PATCH_TAIL, osal_strlen(WMT_IC_PATCH_TAIL));
1890 cTmpPatchName[osal_strlen(cTmpPatchName)] = '\0';
1893 WMT_ERR_FUNC("invalid default firmware patch name (%s)\n", gDefPatchName);
1894 osal_memset(gFullPatchName, 0, osal_sizeof(gFullPatchName));
1898 /*patch with versioned name exist , update cFullPatchName with full named patch*/
1899 osal_memcpy (gFullPatchName, cTmpPatchName, osal_strlen(cTmpPatchName));
1900 *(gFullPatchName + osal_strlen(cTmpPatchName)) = '\0';
1901 WMT_INFO_FUNC("full firmware patch name: %s\n", cTmpPatchName);