import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / connectivity / combo / common / core / wmt_func.c
1 /*! \file
2 \brief Declaration of library functions
3
4 Any definitions in this file will be shared among GLUE Layer and internal Driver Stack.
5 */
6
7
8
9 /*******************************************************************************
10 * C O M P I L E R F L A G S
11 ********************************************************************************
12 */
13
14 /*******************************************************************************
15 * M A C R O S
16 ********************************************************************************
17 */
18 #ifdef DFT_TAG
19 #undef DFT_TAG
20 #endif
21 #define DFT_TAG "[WMT-FUNC]"
22
23
24 /*******************************************************************************
25 * E X T E R N A L R E F E R E N C E S
26 ********************************************************************************
27 */
28 #include "osal_typedef.h"
29
30 #include "wmt_func.h"
31 #include "wmt_lib.h"
32 #include "wmt_core.h"
33
34
35
36 /*******************************************************************************
37 * C O N S T A N T S
38 ********************************************************************************
39 */
40
41
42
43 /*******************************************************************************
44 * D A T A T Y P E S
45 ********************************************************************************
46 */
47
48 /*******************************************************************************
49 * F U N C T I O N D E C L A R A T I O N S
50 ********************************************************************************
51 */
52
53 /*******************************************************************************
54 * P U B L I C D A T A
55 ********************************************************************************
56 */
57 #if CFG_FUNC_BT_SUPPORT
58
59 static INT32 wmt_func_bt_on(P_WMT_IC_OPS pOps, P_WMT_GEN_CONF pConf);
60 static INT32 wmt_func_bt_off(P_WMT_IC_OPS pOps, P_WMT_GEN_CONF pConf);
61
62 WMT_FUNC_OPS wmt_func_bt_ops = {
63 /* BT subsystem function on/off */
64 .func_on = wmt_func_bt_on,
65 .func_off = wmt_func_bt_off
66 };
67 #endif
68
69 #if CFG_FUNC_FM_SUPPORT
70
71 static INT32 wmt_func_fm_on(P_WMT_IC_OPS pOps, P_WMT_GEN_CONF pConf);
72 static INT32 wmt_func_fm_off(P_WMT_IC_OPS pOps, P_WMT_GEN_CONF pConf);
73
74 WMT_FUNC_OPS wmt_func_fm_ops = {
75 /* FM subsystem function on/off */
76 .func_on = wmt_func_fm_on,
77 .func_off = wmt_func_fm_off
78 };
79 #endif
80
81 #if CFG_FUNC_GPS_SUPPORT
82
83 static INT32 wmt_func_gps_on(P_WMT_IC_OPS pOps, P_WMT_GEN_CONF pConf);
84 static INT32 wmt_func_gps_off(P_WMT_IC_OPS pOps, P_WMT_GEN_CONF pConf);
85
86 WMT_FUNC_OPS wmt_func_gps_ops = {
87 /* GPS subsystem function on/off */
88 .func_on = wmt_func_gps_on,
89 .func_off = wmt_func_gps_off
90 };
91
92 #endif
93
94 #if CFG_FUNC_WIFI_SUPPORT
95 static INT32 wmt_func_wifi_on(P_WMT_IC_OPS pOps, P_WMT_GEN_CONF pConf);
96 static INT32 wmt_func_wifi_off(P_WMT_IC_OPS pOps, P_WMT_GEN_CONF pConf);
97
98 WMT_FUNC_OPS wmt_func_wifi_ops = {
99 /* Wi-Fi subsystem function on/off */
100 .func_on = wmt_func_wifi_on,
101 .func_off = wmt_func_wifi_off
102 };
103 #endif
104
105
106 #if CFG_FUNC_ANT_SUPPORT
107
108 static INT32 wmt_func_ant_on(P_WMT_IC_OPS pOps, P_WMT_GEN_CONF pConf);
109 static INT32 wmt_func_ant_off(P_WMT_IC_OPS pOps, P_WMT_GEN_CONF pConf);
110
111 WMT_FUNC_OPS wmt_func_ant_ops = {
112 /* BT subsystem function on/off */
113 .func_on = wmt_func_ant_on,
114 .func_off = wmt_func_ant_off
115 };
116 #endif
117
118 /*******************************************************************************
119 * P R I V A T E D A T A
120 ********************************************************************************
121 */
122 #if CFG_FUNC_GPS_SUPPORT
123 CMB_PIN_CTRL_REG eediPinOhRegs[] = {
124 {
125 /* pull down ctrl register */
126 .regAddr = 0x80050020,
127 .regValue = ~(0x1UL << 5),
128 .regMask = 0x00000020UL,
129 },
130 {
131 /* pull up ctrl register */
132 .regAddr = 0x80050000,
133 .regValue = 0x1UL << 5,
134 .regMask = 0x00000020UL,
135 },
136 {
137 /* iomode ctrl register */
138 .regAddr = 0x80050110,
139 .regValue = 0x1UL << 0,
140 .regMask = 0x00000007UL,
141 },
142 {
143 /* output high/low ctrl register */
144 .regAddr = 0x80050040,
145 .regValue = 0x1UL << 5,
146 .regMask = 0x00000020UL,
147 }
148
149 };
150
151 CMB_PIN_CTRL_REG eediPinOlRegs[] = {
152 {
153 .regAddr = 0x80050020,
154 .regValue = 0x1UL << 5,
155 .regMask = 0x00000020UL,
156 },
157 {
158 .regAddr = 0x80050000,
159 .regValue = ~(0x1UL << 5),
160 .regMask = 0x00000020UL,
161 },
162 {
163 .regAddr = 0x80050110,
164 .regValue = 0x1UL << 0,
165 .regMask = 0x00000007UL,
166 },
167 {
168 .regAddr = 0x80050040,
169 .regValue = ~(0x1UL << 5),
170 .regMask = 0x00000020UL,
171 }
172 };
173
174 CMB_PIN_CTRL_REG eedoPinOhRegs[] = {
175 {
176 .regAddr = 0x80050020,
177 .regValue = ~(0x1UL << 7),
178 .regMask = 0x00000080UL,
179 },
180 {
181 .regAddr = 0x80050000,
182 .regValue = 0x1UL << 7,
183 .regMask = 0x00000080UL,
184 },
185 {
186 .regAddr = 0x80050110,
187 .regValue = 0x1UL << 12,
188 .regMask = 0x00007000UL,
189 },
190 {
191 .regAddr = 0x80050040,
192 .regValue = 0x1UL << 7,
193 .regMask = 0x00000080UL,
194 }
195 };
196
197
198 CMB_PIN_CTRL_REG eedoPinOlRegs[] = {
199 {
200 .regAddr = 0x80050020,
201 .regValue = 0x1UL << 7,
202 .regMask = 0x00000080UL,
203 },
204 {
205 .regAddr = 0x80050000,
206 .regValue = ~(0x1UL << 7),
207 .regMask = 0x00000080UL,
208 },
209 {
210 .regAddr = 0x80050110,
211 .regValue = 0x1UL << 12,
212 .regMask = 0x00007000UL,
213 },
214 {
215 .regAddr = 0x80050040,
216 .regValue = ~(0x1UL << 7),
217 .regMask = 0x00000080UL,
218 }
219
220 };
221
222 CMB_PIN_CTRL_REG gsyncPinOnRegs[] = {
223 {
224 .regAddr = 0x80050110,
225 .regValue = 0x3UL << 20,
226 .regMask = 0x7UL << 20,
227 }
228
229 };
230
231 CMB_PIN_CTRL_REG gsyncPinOffRegs[] = {
232 {
233 .regAddr = 0x80050110,
234 .regValue = 0x0UL << 20,
235 .regMask = 0x7UL << 20,
236 }
237 };
238
239 /* templete usage for GPIO control */
240 CMB_PIN_CTRL gCmbPinCtrl[3] = {
241 {
242 .pinId = CMB_PIN_EEDI_ID,
243 .regNum = 4,
244 .pFuncOnArray = eediPinOhRegs,
245 .pFuncOffArray = eediPinOlRegs,
246 },
247 {
248 .pinId = CMB_PIN_EEDO_ID,
249 .regNum = 4,
250 .pFuncOnArray = eedoPinOhRegs,
251 .pFuncOffArray = eedoPinOlRegs,
252 },
253 {
254 .pinId = CMB_PIN_GSYNC_ID,
255 .regNum = 1,
256 .pFuncOnArray = gsyncPinOnRegs,
257 .pFuncOffArray = gsyncPinOffRegs,
258 }
259 };
260 #endif
261
262
263
264
265 /*******************************************************************************
266 * F U N C T I O N S
267 ********************************************************************************
268 */
269
270 #if CFG_FUNC_BT_SUPPORT
271
272 INT32 _osal_inline_ wmt_func_bt_ctrl(ENUM_FUNC_STATE funcState)
273 {
274 /*only need to send turn BT subsystem wmt command */
275 return wmt_core_func_ctrl_cmd(WMTDRV_TYPE_BT,
276 (FUNC_ON ==
277 funcState) ? MTK_WCN_BOOL_TRUE : MTK_WCN_BOOL_FALSE);
278 }
279
280 INT32 wmt_func_bt_on(P_WMT_IC_OPS pOps, P_WMT_GEN_CONF pConf)
281 {
282 /* return wmt_func_bt_ctrl(FUNC_ON); */
283 return wmt_core_func_ctrl_cmd(WMTDRV_TYPE_BT, MTK_WCN_BOOL_TRUE);
284 }
285
286 INT32 wmt_func_bt_off(P_WMT_IC_OPS pOps, P_WMT_GEN_CONF pConf)
287 {
288 /* return wmt_func_bt_ctrl(FUNC_OFF); */
289 return wmt_core_func_ctrl_cmd(WMTDRV_TYPE_BT, MTK_WCN_BOOL_FALSE);
290 }
291
292 #endif
293
294 #if CFG_FUNC_ANT_SUPPORT
295
296 INT32 _osal_inline_ wmt_func_ant_ctrl(ENUM_FUNC_STATE funcState)
297 {
298 /*only need to send turn BT subsystem wmt command */
299 return wmt_core_func_ctrl_cmd(WMTDRV_TYPE_ANT,
300 (FUNC_ON ==
301 funcState) ? MTK_WCN_BOOL_TRUE : MTK_WCN_BOOL_FALSE);
302 }
303
304 INT32 wmt_func_ant_on(P_WMT_IC_OPS pOps, P_WMT_GEN_CONF pConf)
305 {
306 return wmt_core_func_ctrl_cmd(WMTDRV_TYPE_ANT, MTK_WCN_BOOL_TRUE);
307 }
308
309 INT32 wmt_func_ant_off(P_WMT_IC_OPS pOps, P_WMT_GEN_CONF pConf)
310 {
311 return wmt_core_func_ctrl_cmd(WMTDRV_TYPE_ANT, MTK_WCN_BOOL_FALSE);
312 }
313
314 #endif
315
316
317 #if CFG_FUNC_GPS_SUPPORT
318
319 INT32 _osal_inline_ wmt_func_gps_ctrl(ENUM_FUNC_STATE funcState)
320 {
321 /*send turn GPS subsystem wmt command */
322 return wmt_core_func_ctrl_cmd(WMTDRV_TYPE_GPS,
323 (FUNC_ON ==
324 funcState) ? MTK_WCN_BOOL_TRUE : MTK_WCN_BOOL_FALSE);
325 }
326
327 INT32 wmt_func_gps_pre_ctrl(P_WMT_IC_OPS pOps, P_WMT_GEN_CONF pConf, ENUM_FUNC_STATE funcStatus)
328 {
329 UINT32 i = 0;
330 UINT32 iRet = 0;
331 UINT32 regAddr = 0;
332 UINT32 regValue = 0;
333 UINT32 regMask = 0;
334 UINT32 regNum = 0;
335 P_CMB_PIN_CTRL_REG pReg;
336 P_CMB_PIN_CTRL pCmbPinCtrl;
337 WMT_CTRL_DATA ctrlData;
338 WMT_IC_PIN_ID wmtIcPinId = WMT_IC_PIN_MAX;
339 /* sanity check */
340 if (FUNC_ON != funcStatus && FUNC_OFF != funcStatus) {
341 WMT_ERR_FUNC("invalid funcStatus(%d)\n", funcStatus);
342 return -1;
343 }
344 /* turn on GPS sync function on both side */
345 ctrlData.ctrlId = WMT_CTRL_GPS_SYNC_SET;
346 ctrlData.au4CtrlData[0] = (FUNC_ON == funcStatus) ? 1 : 0;
347 iRet = wmt_ctrl(&ctrlData);
348 if (iRet) {
349 /*we suppose this would never print */
350 WMT_ERR_FUNC("ctrl GPS_SYNC_SET(%d) fail, ret(%d)\n", funcStatus, iRet);
351 /* TODO:[FixMe][George] error handling? */
352 return -2;
353 } else {
354 WMT_INFO_FUNC("ctrl GPS_SYNC_SET(%d) ok\n", funcStatus);
355 }
356 if ((NULL == pOps->ic_pin_ctrl) || (0 > pOps->ic_pin_ctrl(WMT_IC_PIN_GSYNC, FUNC_ON == funcStatus ? WMT_IC_PIN_MUX : WMT_IC_PIN_GPIO, 1))) { /*WMT_IC_PIN_GSYNC */
357 pCmbPinCtrl = &gCmbPinCtrl[CMB_PIN_GSYNC_ID];
358 regNum = pCmbPinCtrl->regNum;
359 for (i = 0; i < regNum; i++) {
360 pReg =
361 FUNC_ON ==
362 funcStatus ? &pCmbPinCtrl->pFuncOnArray[i] : &pCmbPinCtrl->
363 pFuncOffArray[i];
364 regAddr = pReg->regAddr;
365 regValue = pReg->regValue;
366 regMask = pReg->regMask;
367
368 iRet = wmt_core_reg_rw_raw(1, regAddr, &regValue, regMask);
369 if (iRet) {
370 WMT_ERR_FUNC("set reg for GPS_SYNC function fail(%d)\n", iRet);
371 /* TODO:[FixMe][Chaozhong] error handling? */
372 return -2;
373 }
374
375 }
376 } else {
377 WMT_INFO_FUNC("set reg for GPS_SYNC function okay by chip ic_pin_ctrl\n");
378 }
379 WMT_INFO_FUNC("ctrl combo chip gps sync function succeed\n");
380 /* turn on GPS lna ctrl function */
381 if (NULL != pConf) {
382 if (0 == pConf->wmt_gps_lna_enable) {
383
384 WMT_INFO_FUNC("host pin used for gps lna\n");
385 /* host LNA ctrl pin needed */
386 ctrlData.ctrlId = WMT_CTRL_GPS_LNA_SET;
387 ctrlData.au4CtrlData[0] = FUNC_ON == funcStatus ? 1 : 0;
388 iRet = wmt_ctrl(&ctrlData);
389 if (iRet) {
390 /*we suppose this would never print */
391 WMT_ERR_FUNC("ctrl host GPS_LNA output high fail, ret(%d)\n", iRet);
392 /* TODO:[FixMe][Chaozhong] error handling? */
393 return -3;
394 } else {
395 WMT_INFO_FUNC("ctrl host gps lna function succeed\n");
396 }
397 } else {
398 WMT_INFO_FUNC("combo chip pin(%s) used for gps lna\n",
399 0 == pConf->wmt_gps_lna_pin ? "EEDI" : "EEDO");
400 wmtIcPinId =
401 0 == pConf->wmt_gps_lna_pin ? WMT_IC_PIN_EEDI : WMT_IC_PIN_EEDO;
402 if ((NULL == pOps->ic_pin_ctrl) || (0 > pOps->ic_pin_ctrl(wmtIcPinId, FUNC_ON == funcStatus ? WMT_IC_PIN_GPIO_HIGH : WMT_IC_PIN_GPIO_LOW, 1))) { /*WMT_IC_PIN_GSYNC */
403 if (0 == pConf->wmt_gps_lna_pin) {
404 /* EEDI needed */
405 pCmbPinCtrl = &gCmbPinCtrl[CMB_PIN_EEDI_ID];
406 } else if (1 == pConf->wmt_gps_lna_pin) {
407 /* EEDO needed */
408 pCmbPinCtrl = &gCmbPinCtrl[CMB_PIN_EEDO_ID];
409 }
410 regNum = pCmbPinCtrl->regNum;
411 for (i = 0; i < regNum; i++) {
412 pReg =
413 FUNC_ON ==
414 funcStatus ? &pCmbPinCtrl->
415 pFuncOnArray[i] : &pCmbPinCtrl->pFuncOffArray[i];
416 regAddr = pReg->regAddr;
417 regValue = pReg->regValue;
418 regMask = pReg->regMask;
419
420 iRet = wmt_core_reg_rw_raw(1, regAddr, &regValue, regMask);
421 if (iRet) {
422 WMT_ERR_FUNC
423 ("set reg for GPS_LNA function fail(%d)\n",
424 iRet);
425 /* TODO:[FixMe][Chaozhong] error handling? */
426 return -3;
427 }
428 }
429 WMT_INFO_FUNC("ctrl combo chip gps lna succeed\n");
430 } else {
431 WMT_INFO_FUNC
432 ("set reg for GPS_LNA function okay by chip ic_pin_ctrl\n");
433 }
434 }
435 }
436 return 0;
437
438 }
439
440 INT32 wmt_func_gps_pre_on(P_WMT_IC_OPS pOps, P_WMT_GEN_CONF pConf)
441 {
442 return wmt_func_gps_pre_ctrl(pOps, pConf, FUNC_ON);
443 }
444
445 INT32 wmt_func_gps_pre_off(P_WMT_IC_OPS pOps, P_WMT_GEN_CONF pConf)
446 {
447
448 return wmt_func_gps_pre_ctrl(pOps, pConf, FUNC_OFF);
449 }
450
451
452 INT32 wmt_func_gps_on(P_WMT_IC_OPS pOps, P_WMT_GEN_CONF pConf)
453 {
454 INT32 iRet = 0;
455 iRet = wmt_func_gps_pre_on(pOps, pConf);
456 if (0 == iRet) {
457 iRet = wmt_func_gps_ctrl(FUNC_ON);
458 }
459 return iRet;
460 }
461
462 INT32 wmt_func_gps_off(P_WMT_IC_OPS pOps, P_WMT_GEN_CONF pConf)
463 {
464 INT32 iRet = 0;
465 iRet = wmt_func_gps_pre_off(pOps, pConf);
466 if (0 == iRet) {
467 iRet = wmt_func_gps_ctrl(FUNC_OFF);
468 }
469 return iRet;
470
471 }
472 #endif
473
474 #if CFG_FUNC_FM_SUPPORT
475
476 INT32 _osal_inline_ wmt_func_fm_ctrl(ENUM_FUNC_STATE funcState)
477 {
478 /*only need to send turn FM subsystem wmt command */
479 return wmt_core_func_ctrl_cmd(WMTDRV_TYPE_FM,
480 (FUNC_ON ==
481 funcState) ? MTK_WCN_BOOL_TRUE : MTK_WCN_BOOL_FALSE);
482 }
483
484
485 INT32 wmt_func_fm_on(P_WMT_IC_OPS pOps, P_WMT_GEN_CONF pConf)
486 {
487 /* return wmt_func_fm_ctrl(FUNC_ON); */
488 return wmt_core_func_ctrl_cmd(WMTDRV_TYPE_FM, MTK_WCN_BOOL_TRUE);
489 }
490
491 INT32 wmt_func_fm_off(P_WMT_IC_OPS pOps, P_WMT_GEN_CONF pConf)
492 {
493 /* return wmt_func_fm_ctrl(FUNC_OFF); */
494 return wmt_core_func_ctrl_cmd(WMTDRV_TYPE_FM, MTK_WCN_BOOL_FALSE);
495 }
496
497 #endif
498
499 #if CFG_FUNC_WIFI_SUPPORT
500
501 INT32 wmt_func_wifi_ctrl(ENUM_FUNC_STATE funcState)
502 {
503 INT32 iRet = 0;
504 UINT32 ctrlPa1 = WMT_SDIO_FUNC_WIFI;
505 UINT32 ctrlPa2 = (FUNC_ON == funcState) ? 1 : 0; /* turn on Wi-Fi driver */
506 iRet = wmt_core_ctrl(WMT_CTRL_SDIO_FUNC, &ctrlPa1, &ctrlPa2);
507 if (iRet) {
508 WMT_ERR_FUNC("WMT-FUNC: turn on WIFI function fail (%d)", iRet);
509 return -1;
510 }
511 return 0;
512 }
513
514
515 INT32 wmt_func_wifi_on(P_WMT_IC_OPS pOps, P_WMT_GEN_CONF pConf)
516 {
517 return wmt_func_wifi_ctrl(FUNC_ON);
518 }
519
520 INT32 wmt_func_wifi_off(P_WMT_IC_OPS pOps, P_WMT_GEN_CONF pConf)
521 {
522 return wmt_func_wifi_ctrl(FUNC_OFF);
523 }
524 #endif