mtk_btif_exp.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. #ifndef _MTK_BTIF_EXP_H_
  2. #define _MTK_BTIF_EXP_H_
  3. /*--------------marco defination---------------*/
  4. #define BTIF_MAX_LEN_PER_PKT 2048
  5. #define BTIF_RXD_BE_BLOCKED_DETECT 1
  6. /*--------------Enum Defination---------------*/
  7. typedef enum _ENUM_BTIF_DPIDLE_ {
  8. BTIF_DPIDLE_DISABLE = 0,
  9. BTIF_DPIDLE_ENABLE = BTIF_DPIDLE_DISABLE + 1,
  10. BTIF_DPIDLE_MAX,
  11. } ENUM_BTIF_DPIDLE_CTRL;
  12. typedef enum _ENUM_BTIF_LPBK_MODE_ {
  13. BTIF_LPBK_DISABLE = 0,
  14. BTIF_LPBK_ENABLE = BTIF_LPBK_DISABLE + 1,
  15. BTIF_LPBK_MAX,
  16. } ENUM_BTIF_LPBK_MODE;
  17. typedef enum _ENUM_BTIF_DBG_ID_ {
  18. BTIF_DISABLE_LOGGER = 0,
  19. BTIF_ENABLE_LOGGER = BTIF_DISABLE_LOGGER + 1,
  20. BTIF_DUMP_LOG = BTIF_ENABLE_LOGGER + 1,
  21. BTIF_CLR_LOG = BTIF_DUMP_LOG + 1,
  22. BTIF_DUMP_BTIF_REG = BTIF_CLR_LOG + 1,
  23. BTIF_ENABLE_RT_LOG = BTIF_DUMP_BTIF_REG + 1,
  24. BTIF_DISABLE_RT_LOG = BTIF_ENABLE_RT_LOG + 1,
  25. BTIF_DBG_MAX,
  26. } ENUM_BTIF_DBG_ID;
  27. typedef enum _ENUM_BTIF_OP_ERROR_CODE_ {
  28. E_BTIF_AGAIN = 0,
  29. E_BTIF_FAIL = -1,
  30. E_BTIF_BAD_POINTER = -2,
  31. E_BTIF_NO_SPACE = -3,
  32. E_BTIF_INTR = -4,
  33. E_BTIF_INVAL_PARAM = -5,
  34. E_BTIF_ALREADY_OPEN = -6,
  35. E_BTIF_NOT_OPEN = -7,
  36. E_BTIF_INVAL_STATE = -8,
  37. } ENUM_BTIF_OP_ERROR_CODE;
  38. /*--------------End of Enum Defination---------------*/
  39. /*--------------Type Definition---------------*/
  40. typedef int (*MTK_WCN_BTIF_RX_CB) (const unsigned char *p_buf,
  41. unsigned int len);
  42. /*--------------End of Type Definition---------------*/
  43. /*--------------Normal Mode API declearation---------------*/
  44. /*****************************************************************************
  45. * FUNCTION
  46. * mtk_wcn_btif_open
  47. * DESCRIPTION
  48. * open BTIF interface, will do BTIF module HW and SW initialization
  49. * PARAMETERS
  50. * p_owner [IN] pointer to owner who call this API,
  51. * currently there are 2 owner ("stp" or "btif_tester")
  52. * may use this module
  53. * user's id string must be less than 32 bytes
  54. * for "stp", BTIF will call rx callback function to route rx data to STP module
  55. * for "stp_tester", BTIF will save rx data
  56. * and wait for native process to access
  57. * p_id [IN] BTIF's user id will be put to this address
  58. * RETURNS
  59. * int 0 = succeed; others = fail, for detailed information,
  60. * please see ENUM_BTIF_OP_ERROR_CODE
  61. * if open success, value p_id will be the only identifier for
  62. * user to access BTIF's other operations
  63. * including read/write/dpidle_ctrl/rx_cb_retister
  64. * this user id is only an identifier used for owner identification
  65. *****************************************************************************/
  66. int mtk_wcn_btif_open(char *p_owner, unsigned long *p_id);
  67. /*****************************************************************************
  68. * FUNCTION
  69. * mtk_wcn_btif_close
  70. * DESCRIPTION
  71. * close BTIF interface, will do BTIF module HW and SW de-initialization
  72. * once this API is called, p_btif should never be used by BTIF's user again
  73. * PARAMETERS
  74. * u_id [IN] BTIF's user id
  75. * RETURNS
  76. * int 0 = succeed;
  77. * others = fail, for detailed information, please see ENUM_BTIF_OP_ERROR_CODE
  78. *****************************************************************************/
  79. int mtk_wcn_btif_close(unsigned long u_id);
  80. /*****************************************************************************
  81. * FUNCTION
  82. * mtk_wcn_btif_write
  83. * DESCRIPTION
  84. * send data throuth BTIF module
  85. * there's no internal buffer to cache STP data in BTIF driver,
  86. * if in DMA mode
  87. * btif driver will check if there's enough space
  88. * in vFIFO for data to send in DMA mode
  89. * if yes, put data to vFIFO and return corresponding data length to caller
  90. * if no, corresponding error code will be returned to called
  91. * PARAMETERS
  92. * p_btif [IN] pointer returned by mtk_wcn_btif_open
  93. * p_buf [IN] pointer to target data to send
  94. * len [IN] data length (should be less than 2014 bytes per STP package)
  95. *
  96. * if in non-DMA mode, BTIF driver will try to write to THR of BTIF controller
  97. * if btif driver detected that no space is available in Tx FIFO,
  98. * will return E_BTIF_NO_SPACE,
  99. * mostly something is wrong with BTIF or consys when this
  100. * return value is returned
  101. * RETURNS
  102. * int positive: data length send through BTIF;
  103. * negative: please see ENUM_BTIF_OP_ERROR_CODE
  104. * E_BTIF_AGAIN (0) will be returned to caller if btif does not have
  105. * enough vFIFO to send data, when caller get 0,
  106. * he should wait for a moment (5~10ms maybe) and
  107. * try a few times (maybe 10~20)
  108. * if still get E_BTIF_AGAIN, should call BTIF's debug API and
  109. * dump BTIF driver and BTIF/DMA register information to kernel log
  110. * for debug
  111. * E_BTIF_BAD_POINTER will be returned to caller if btif is not
  112. * opened successfully before call this API
  113. * E_BTIF_INVAL_PARAM will be returned if parameter is not valid
  114. *****************************************************************************/
  115. int mtk_wcn_btif_write(unsigned long u_id,
  116. const unsigned char *p_buf, unsigned int len);
  117. /*****************************************************************************
  118. * FUNCTION
  119. * mtk_wcn_btif_read
  120. * DESCRIPTION
  121. * read data from BTIF module
  122. * PARAMETERS
  123. * p_btif [IN] pointer returned by mtk_wcn_btif_open
  124. * p_buf [IN/OUT] pointer to buffer where rx data will be put
  125. * max_len [IN] max buffer length
  126. * RETURNS
  127. * int positive: data length read from BTIF;
  128. * negative: please see ENUM_BTIF_OP_ERROR_CODE
  129. *****************************************************************************/
  130. int mtk_wcn_btif_read(unsigned long u_id,
  131. unsigned char *p_buf, unsigned int max_len);
  132. /*****************************************************************************
  133. * FUNCTION
  134. * mtk_wcn_btif_dpidle_ctrl
  135. * DESCRIPTION
  136. * control if BTIF module allow system enter deepidle state or not
  137. * PARAMETERS
  138. * p_btif [IN] pointer returned by mtk_wcn_btif_open
  139. * en_flag [IN] one of ENUM_BTIF_DPIDLE_CTRL
  140. * RETURNS
  141. * int always return 0
  142. *****************************************************************************/
  143. int mtk_wcn_btif_dpidle_ctrl(unsigned long u_id, ENUM_BTIF_DPIDLE_CTRL en_flag);
  144. /*****************************************************************************
  145. * FUNCTION
  146. * mtk_wcn_btif_rx_cb_register
  147. * DESCRIPTION
  148. * register rx callback function to BTIF module by btif user
  149. * PARAMETERS
  150. * p_btif [IN] pointer returned by mtk_wcn_btif_open
  151. * rx_cb [IN] pointer to stp rx handler callback function,
  152. * should be comply with MTK_WCN_BTIF_RX_CB
  153. * RETURNS
  154. * int 0 = succeed;
  155. * others = fail, for detailed information, please see ENUM_BTIF_OP_ERROR_CODE
  156. *****************************************************************************/
  157. int mtk_wcn_btif_rx_cb_register(unsigned long u_id, MTK_WCN_BTIF_RX_CB rx_cb);
  158. /*****************************************************************************
  159. * FUNCTION
  160. * mtk_wcn_btif_wakeup_consys
  161. * DESCRIPTION
  162. * once sleep command is sent to con sys,
  163. * should call this API before send wakeup command to
  164. * make con sys aware host want to send data to consys
  165. * PARAMETERS
  166. * p_btif [IN] pointer returned by mtk_wcn_btif_open
  167. * RETURNS
  168. * int 0 = succeed;
  169. * others = fail, for detailed information, please see ENUM_BTIF_OP_ERROR_CODE
  170. *****************************************************************************/
  171. int mtk_wcn_btif_wakeup_consys(unsigned long u_id);
  172. /*--------------End of Normal Mode API declearation----------------*/
  173. /*--------------Debug Purpose API declearation----------------*/
  174. /*****************************************************************************
  175. * FUNCTION
  176. * mtk_wcn_btif_loopback_ctrl
  177. * DESCRIPTION
  178. * enable/disable BTIF internal loopback function,
  179. * when this function is enabled,
  180. * data send to btif will be received by btif itself
  181. * only for debug purpose, should never use this function in normal mode
  182. * PARAMETERS
  183. * p_btif [IN] pointer returned by mtk_wcn_btif_open
  184. * enable [IN] loopback mode control flag, enable or disable,
  185. * shou be one of ENUM_BTIF_LPBK_MODE
  186. * RETURNS
  187. * int 0 = succeed;
  188. * others = fail, for detailed information, please see ENUM_BTIF_OP_ERROR_CODE
  189. *****************************************************************************/
  190. int mtk_wcn_btif_loopback_ctrl(unsigned long u_id, ENUM_BTIF_LPBK_MODE enable);
  191. /*****************************************************************************
  192. * FUNCTION
  193. * mtk_wcn_btif_logger_ctrl
  194. * DESCRIPTION
  195. * control BTIF logger function's behavior
  196. * PARAMETERS
  197. * p_btif [IN] pointer returned by mtk_wcn_btif_open
  198. * flag [IN] should be one of ENUM_BTIF_DBG_ID
  199. * BTIF_DISABLE_LOGGER - disable btif logger
  200. * BTIF_ENABLE_LOGGER - enable btif logger
  201. * BTIF_DUMP_LOG - dump log logged by btif
  202. * BTIF_CLR_LOG - clear btif log buffer
  203. * BTIF_DUMP_BTIF_REG - dump btif controller's register
  204. * BTIF_DUMP_DMA_REG - dump DMA controller's register
  205. * RETURNS
  206. * int 0 = succeed;
  207. * others = fail, for detailed information,
  208. * please see ENUM_BTIF_OP_ERROR_CODE
  209. *****************************************************************************/
  210. int mtk_wcn_btif_dbg_ctrl(unsigned long u_id, ENUM_BTIF_DBG_ID flag);
  211. /*-----------End of Debug Purpose API declearation------------*/
  212. /*****************************************************************************
  213. * FUNCTION
  214. * mtk_wcn_btif_parser_wmt_evt
  215. * DESCRIPTION
  216. * parser wmt sleep/wakeup evt in btif bbs buffer for debug
  217. * PARAMETERS
  218. * p_btif [IN] pointer returned by mtk_wcn_btif_open
  219. * sub_str [IN] the str to be parsered
  220. * str_len [IN] the length of sub_str
  221. * RETURNS
  222. * bool true = succeed;
  223. * false = fail;
  224. *****************************************************************************/
  225. bool mtk_wcn_btif_parser_wmt_evt(unsigned long u_id,
  226. const char *sub_str, unsigned int str_len);
  227. int mtk_btif_exp_open_test(void);
  228. int mtk_btif_exp_close_test(void);
  229. int mtk_btif_exp_write_test(void);
  230. int mtk_btif_exp_suspend_test(void);
  231. int mtk_btif_exp_resume_test(void);
  232. int mtk_btif_exp_enter_dpidle_test(void);
  233. int mtk_btif_exp_exit_dpidle_test(void);
  234. int mtk_btif_exp_write_stress_test(unsigned int length, unsigned int loop);
  235. int mtk_btif_exp_log_debug_test(int flag);
  236. int mtk_btif_exp_restore_noirq_test(void);
  237. int btif_wakeup_consys_no_id(void);
  238. int mtk_btif_exp_clock_ctrl(int en);
  239. #if BTIF_RXD_BE_BLOCKED_DETECT
  240. int mtk_btif_rxd_be_blocked_flag_get(void);
  241. #endif
  242. #endif /*_MTK_BTIF_EXP_H_*/