2 \brief Declaration of library functions
4 Any definitions in this file will be shared among GLUE Layer and internal Driver Stack.
9 /*******************************************************************************
10 * C O M P I L E R F L A G S
11 ********************************************************************************
14 /*******************************************************************************
16 ********************************************************************************
21 #define DFT_TAG "[WMT-FUNC]"
24 /*******************************************************************************
25 * E X T E R N A L R E F E R E N C E S
26 ********************************************************************************
28 #include "osal_typedef.h"
36 /*******************************************************************************
38 ********************************************************************************
43 /*******************************************************************************
45 ********************************************************************************
48 /*******************************************************************************
49 * F U N C T I O N D E C L A R A T I O N S
50 ********************************************************************************
53 /*******************************************************************************
55 ********************************************************************************
57 #if CFG_FUNC_BT_SUPPORT
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
);
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
69 #if CFG_FUNC_FM_SUPPORT
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
);
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
81 #if CFG_FUNC_GPS_SUPPORT
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
);
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
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
);
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
106 #if CFG_FUNC_ANT_SUPPORT
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
);
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
118 /*******************************************************************************
119 * P R I V A T E D A T A
120 ********************************************************************************
122 #if CFG_FUNC_GPS_SUPPORT
123 CMB_PIN_CTRL_REG eediPinOhRegs
[] = {
125 /* pull down ctrl register */
126 .regAddr
= 0x80050020,
127 .regValue
= ~(0x1UL
<< 5),
128 .regMask
= 0x00000020UL
,
131 /* pull up ctrl register */
132 .regAddr
= 0x80050000,
133 .regValue
= 0x1UL
<< 5,
134 .regMask
= 0x00000020UL
,
137 /* iomode ctrl register */
138 .regAddr
= 0x80050110,
139 .regValue
= 0x1UL
<< 0,
140 .regMask
= 0x00000007UL
,
143 /* output high/low ctrl register */
144 .regAddr
= 0x80050040,
145 .regValue
= 0x1UL
<< 5,
146 .regMask
= 0x00000020UL
,
151 CMB_PIN_CTRL_REG eediPinOlRegs
[] = {
153 .regAddr
= 0x80050020,
154 .regValue
= 0x1UL
<< 5,
155 .regMask
= 0x00000020UL
,
158 .regAddr
= 0x80050000,
159 .regValue
= ~(0x1UL
<< 5),
160 .regMask
= 0x00000020UL
,
163 .regAddr
= 0x80050110,
164 .regValue
= 0x1UL
<< 0,
165 .regMask
= 0x00000007UL
,
168 .regAddr
= 0x80050040,
169 .regValue
= ~(0x1UL
<< 5),
170 .regMask
= 0x00000020UL
,
174 CMB_PIN_CTRL_REG eedoPinOhRegs
[] = {
176 .regAddr
= 0x80050020,
177 .regValue
= ~(0x1UL
<< 7),
178 .regMask
= 0x00000080UL
,
181 .regAddr
= 0x80050000,
182 .regValue
= 0x1UL
<< 7,
183 .regMask
= 0x00000080UL
,
186 .regAddr
= 0x80050110,
187 .regValue
= 0x1UL
<< 12,
188 .regMask
= 0x00007000UL
,
191 .regAddr
= 0x80050040,
192 .regValue
= 0x1UL
<< 7,
193 .regMask
= 0x00000080UL
,
198 CMB_PIN_CTRL_REG eedoPinOlRegs
[] = {
200 .regAddr
= 0x80050020,
201 .regValue
= 0x1UL
<< 7,
202 .regMask
= 0x00000080UL
,
205 .regAddr
= 0x80050000,
206 .regValue
= ~(0x1UL
<< 7),
207 .regMask
= 0x00000080UL
,
210 .regAddr
= 0x80050110,
211 .regValue
= 0x1UL
<< 12,
212 .regMask
= 0x00007000UL
,
215 .regAddr
= 0x80050040,
216 .regValue
= ~(0x1UL
<< 7),
217 .regMask
= 0x00000080UL
,
222 CMB_PIN_CTRL_REG gsyncPinOnRegs
[] = {
224 .regAddr
= 0x80050110,
225 .regValue
= 0x3UL
<< 20,
226 .regMask
= 0x7UL
<< 20,
231 CMB_PIN_CTRL_REG gsyncPinOffRegs
[] = {
233 .regAddr
= 0x80050110,
234 .regValue
= 0x0UL
<< 20,
235 .regMask
= 0x7UL
<< 20,
239 /* templete usage for GPIO control */
240 CMB_PIN_CTRL gCmbPinCtrl
[3] = {
242 .pinId
= CMB_PIN_EEDI_ID
,
244 .pFuncOnArray
= eediPinOhRegs
,
245 .pFuncOffArray
= eediPinOlRegs
,
248 .pinId
= CMB_PIN_EEDO_ID
,
250 .pFuncOnArray
= eedoPinOhRegs
,
251 .pFuncOffArray
= eedoPinOlRegs
,
254 .pinId
= CMB_PIN_GSYNC_ID
,
256 .pFuncOnArray
= gsyncPinOnRegs
,
257 .pFuncOffArray
= gsyncPinOffRegs
,
265 /*******************************************************************************
267 ********************************************************************************
270 #if CFG_FUNC_BT_SUPPORT
272 INT32 _osal_inline_
wmt_func_bt_ctrl(ENUM_FUNC_STATE funcState
)
274 /*only need to send turn BT subsystem wmt command */
275 return wmt_core_func_ctrl_cmd(WMTDRV_TYPE_BT
,
277 funcState
) ? MTK_WCN_BOOL_TRUE
: MTK_WCN_BOOL_FALSE
);
280 INT32
wmt_func_bt_on(P_WMT_IC_OPS pOps
, P_WMT_GEN_CONF pConf
)
282 /* return wmt_func_bt_ctrl(FUNC_ON); */
283 return wmt_core_func_ctrl_cmd(WMTDRV_TYPE_BT
, MTK_WCN_BOOL_TRUE
);
286 INT32
wmt_func_bt_off(P_WMT_IC_OPS pOps
, P_WMT_GEN_CONF pConf
)
288 /* return wmt_func_bt_ctrl(FUNC_OFF); */
289 return wmt_core_func_ctrl_cmd(WMTDRV_TYPE_BT
, MTK_WCN_BOOL_FALSE
);
294 #if CFG_FUNC_ANT_SUPPORT
296 INT32 _osal_inline_
wmt_func_ant_ctrl(ENUM_FUNC_STATE funcState
)
298 /*only need to send turn BT subsystem wmt command */
299 return wmt_core_func_ctrl_cmd(WMTDRV_TYPE_ANT
,
301 funcState
) ? MTK_WCN_BOOL_TRUE
: MTK_WCN_BOOL_FALSE
);
304 INT32
wmt_func_ant_on(P_WMT_IC_OPS pOps
, P_WMT_GEN_CONF pConf
)
306 return wmt_core_func_ctrl_cmd(WMTDRV_TYPE_ANT
, MTK_WCN_BOOL_TRUE
);
309 INT32
wmt_func_ant_off(P_WMT_IC_OPS pOps
, P_WMT_GEN_CONF pConf
)
311 return wmt_core_func_ctrl_cmd(WMTDRV_TYPE_ANT
, MTK_WCN_BOOL_FALSE
);
317 #if CFG_FUNC_GPS_SUPPORT
319 INT32 _osal_inline_
wmt_func_gps_ctrl(ENUM_FUNC_STATE funcState
)
321 /*send turn GPS subsystem wmt command */
322 return wmt_core_func_ctrl_cmd(WMTDRV_TYPE_GPS
,
324 funcState
) ? MTK_WCN_BOOL_TRUE
: MTK_WCN_BOOL_FALSE
);
327 INT32
wmt_func_gps_pre_ctrl(P_WMT_IC_OPS pOps
, P_WMT_GEN_CONF pConf
, ENUM_FUNC_STATE funcStatus
)
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
;
340 if (FUNC_ON
!= funcStatus
&& FUNC_OFF
!= funcStatus
) {
341 WMT_ERR_FUNC("invalid funcStatus(%d)\n", funcStatus
);
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
);
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? */
354 WMT_INFO_FUNC("ctrl GPS_SYNC_SET(%d) ok\n", funcStatus
);
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
++) {
362 funcStatus
? &pCmbPinCtrl
->pFuncOnArray
[i
] : &pCmbPinCtrl
->
364 regAddr
= pReg
->regAddr
;
365 regValue
= pReg
->regValue
;
366 regMask
= pReg
->regMask
;
368 iRet
= wmt_core_reg_rw_raw(1, regAddr
, ®Value
, regMask
);
370 WMT_ERR_FUNC("set reg for GPS_SYNC function fail(%d)\n", iRet
);
371 /* TODO:[FixMe][Chaozhong] error handling? */
377 WMT_INFO_FUNC("set reg for GPS_SYNC function okay by chip ic_pin_ctrl\n");
379 WMT_INFO_FUNC("ctrl combo chip gps sync function succeed\n");
380 /* turn on GPS lna ctrl function */
382 if (0 == pConf
->wmt_gps_lna_enable
) {
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
);
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? */
395 WMT_INFO_FUNC("ctrl host gps lna function succeed\n");
398 WMT_INFO_FUNC("combo chip pin(%s) used for gps lna\n",
399 0 == pConf
->wmt_gps_lna_pin
? "EEDI" : "EEDO");
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
) {
405 pCmbPinCtrl
= &gCmbPinCtrl
[CMB_PIN_EEDI_ID
];
406 } else if (1 == pConf
->wmt_gps_lna_pin
) {
408 pCmbPinCtrl
= &gCmbPinCtrl
[CMB_PIN_EEDO_ID
];
410 regNum
= pCmbPinCtrl
->regNum
;
411 for (i
= 0; i
< regNum
; i
++) {
414 funcStatus
? &pCmbPinCtrl
->
415 pFuncOnArray
[i
] : &pCmbPinCtrl
->pFuncOffArray
[i
];
416 regAddr
= pReg
->regAddr
;
417 regValue
= pReg
->regValue
;
418 regMask
= pReg
->regMask
;
420 iRet
= wmt_core_reg_rw_raw(1, regAddr
, ®Value
, regMask
);
423 ("set reg for GPS_LNA function fail(%d)\n",
425 /* TODO:[FixMe][Chaozhong] error handling? */
429 WMT_INFO_FUNC("ctrl combo chip gps lna succeed\n");
432 ("set reg for GPS_LNA function okay by chip ic_pin_ctrl\n");
440 INT32
wmt_func_gps_pre_on(P_WMT_IC_OPS pOps
, P_WMT_GEN_CONF pConf
)
442 return wmt_func_gps_pre_ctrl(pOps
, pConf
, FUNC_ON
);
445 INT32
wmt_func_gps_pre_off(P_WMT_IC_OPS pOps
, P_WMT_GEN_CONF pConf
)
448 return wmt_func_gps_pre_ctrl(pOps
, pConf
, FUNC_OFF
);
452 INT32
wmt_func_gps_on(P_WMT_IC_OPS pOps
, P_WMT_GEN_CONF pConf
)
455 iRet
= wmt_func_gps_pre_on(pOps
, pConf
);
457 iRet
= wmt_func_gps_ctrl(FUNC_ON
);
462 INT32
wmt_func_gps_off(P_WMT_IC_OPS pOps
, P_WMT_GEN_CONF pConf
)
465 iRet
= wmt_func_gps_pre_off(pOps
, pConf
);
467 iRet
= wmt_func_gps_ctrl(FUNC_OFF
);
474 #if CFG_FUNC_FM_SUPPORT
476 INT32 _osal_inline_
wmt_func_fm_ctrl(ENUM_FUNC_STATE funcState
)
478 /*only need to send turn FM subsystem wmt command */
479 return wmt_core_func_ctrl_cmd(WMTDRV_TYPE_FM
,
481 funcState
) ? MTK_WCN_BOOL_TRUE
: MTK_WCN_BOOL_FALSE
);
485 INT32
wmt_func_fm_on(P_WMT_IC_OPS pOps
, P_WMT_GEN_CONF pConf
)
487 /* return wmt_func_fm_ctrl(FUNC_ON); */
488 return wmt_core_func_ctrl_cmd(WMTDRV_TYPE_FM
, MTK_WCN_BOOL_TRUE
);
491 INT32
wmt_func_fm_off(P_WMT_IC_OPS pOps
, P_WMT_GEN_CONF pConf
)
493 /* return wmt_func_fm_ctrl(FUNC_OFF); */
494 return wmt_core_func_ctrl_cmd(WMTDRV_TYPE_FM
, MTK_WCN_BOOL_FALSE
);
499 #if CFG_FUNC_WIFI_SUPPORT
501 INT32
wmt_func_wifi_ctrl(ENUM_FUNC_STATE funcState
)
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
);
508 WMT_ERR_FUNC("WMT-FUNC: turn on WIFI function fail (%d)", iRet
);
515 INT32
wmt_func_wifi_on(P_WMT_IC_OPS pOps
, P_WMT_GEN_CONF pConf
)
517 return wmt_func_wifi_ctrl(FUNC_ON
);
520 INT32
wmt_func_wifi_off(P_WMT_IC_OPS pOps
, P_WMT_GEN_CONF pConf
)
522 return wmt_func_wifi_ctrl(FUNC_OFF
);