mtk_btif_exp.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. #ifdef DFT_TAG
  2. #undef DFT_TAG
  3. #endif
  4. #define DFT_TAG "MTK-BTIF-EXP"
  5. /*#include "mtk_btif_exp.h"*/
  6. #include "mtk_btif.h"
  7. /*---------------------------------Function----------------------------------*/
  8. p_mtk_btif btif_exp_srh_id(unsigned long u_id)
  9. {
  10. int index = 0;
  11. p_mtk_btif p_btif = NULL;
  12. struct list_head *p_list = NULL;
  13. struct list_head *tmp = NULL;
  14. p_mtk_btif_user p_user = NULL;
  15. for (index = 0; (index < BTIF_PORT_NR) && (NULL == p_btif); index++) {
  16. p_list = &(g_btif[index].user_list);
  17. list_for_each(tmp, p_list) {
  18. p_user = container_of(tmp, mtk_btif_user, entry);
  19. if (u_id == p_user->u_id) {
  20. p_btif = p_user->p_btif;
  21. BTIF_DBG_FUNC
  22. ("BTIF's user id(0x%p), p_btif(0x%p)\n",
  23. p_user->u_id, p_btif);
  24. break;
  25. }
  26. }
  27. }
  28. if (NULL == p_btif) {
  29. BTIF_INFO_FUNC
  30. ("no btif structure found for BTIF's user id(0x%lx)\n",
  31. u_id);
  32. }
  33. return p_btif;
  34. }
  35. /*-----Normal Mode API declearation-------*/
  36. /*****************************************************************************
  37. * FUNCTION
  38. * mtk_wcn_btif_open
  39. * DESCRIPTION
  40. * open BTIF interface, will do BTIF module HW and SW initialization
  41. * PARAMETERS
  42. * p_owner [IN] pointer to owner who call this API,
  43. * currently there are 2 owner ("stp" or "btif_tester")
  44. * may use this module
  45. * for "stp", BTIF will call rx callback function to route rx data to STP module
  46. * for "stp_tester", BTIF will save rx data and wait for native process to access
  47. * p_id [IN] BTIF's user id will be put to this address
  48. * RETURNS
  49. * int 0 = BTIF module initialization fail; negative = BTIF module initialization success
  50. * if open success, value p_id will be the only identifier
  51. * for user to access BTIF's other operations
  52. * including read/write/dpidle_ctrl/rx_cb_retister
  53. * this user id is only an identifier used for owner identification
  54. *****************************************************************************/
  55. int mtk_wcn_btif_open(char *p_owner, unsigned long *p_id)
  56. {
  57. int i_ret = -1;
  58. unsigned int index = 0;
  59. p_mtk_btif_user p_new_user = NULL;
  60. p_mtk_btif p_btif = &g_btif[index];
  61. struct list_head *p_user_list = &(p_btif->user_list);
  62. BTIF_DBG_FUNC("++");
  63. BTIF_DBG_FUNC("p_btif(0x%p)\n", p_btif);
  64. if (mutex_lock_killable(&(p_btif->ops_mtx))) {
  65. BTIF_ERR_FUNC("mutex_lock_killable return failed\n");
  66. return E_BTIF_INTR;
  67. }
  68. if ((NULL == p_owner) || (NULL == p_id)) {
  69. if (p_id)
  70. *p_id = 0;
  71. BTIF_ERR_FUNC("parameter invalid, p_owner(0x%p), p_id(0x%p)\n",
  72. p_owner, p_id);
  73. BTIF_MUTEX_UNLOCK(&(p_btif->ops_mtx));
  74. return E_BTIF_INVAL_PARAM;
  75. }
  76. /*check if btif is already opened or not, if yes, just return fail*/
  77. if (!list_empty(p_user_list)) {
  78. struct list_head *pos;
  79. p_mtk_btif_user p_user;
  80. BTIF_ERR_FUNC("BTIF's user list is not empty\n");
  81. list_for_each(pos, p_user_list) {
  82. p_user = container_of(pos, mtk_btif_user, entry);
  83. BTIF_INFO_FUNC("BTIF's user id(0x%lx), name(%s)\n",
  84. p_user->u_id, p_user->u_name);
  85. }
  86. /*leave p_id alone*/
  87. BTIF_MUTEX_UNLOCK(&(p_btif->ops_mtx));
  88. return E_BTIF_ALREADY_OPEN;
  89. }
  90. p_new_user = vmalloc(sizeof(mtk_btif_user));
  91. if (NULL != p_new_user) {
  92. INIT_LIST_HEAD(&(p_new_user->entry));
  93. p_new_user->enable = false;
  94. p_new_user->p_btif = p_btif;
  95. p_new_user->u_id = (unsigned long)p_new_user;
  96. strncpy(p_new_user->u_name, p_owner, sizeof(p_new_user->u_name) - 1);
  97. p_new_user->u_name[sizeof(p_new_user->u_name) - 1] = '\0';
  98. BTIF_DBG_FUNC("owner name:%s, recorded name:%s\n",
  99. p_owner, p_new_user->u_name);
  100. i_ret = btif_open(p_btif);
  101. if (i_ret) {
  102. BTIF_ERR_FUNC("btif_open failed, i_ret(%d)\n", i_ret);
  103. *p_id = 0;
  104. /*free btif new user's structure*/
  105. vfree(p_new_user);
  106. p_new_user = NULL;
  107. } else {
  108. BTIF_INFO_FUNC("btif_open succeed\n");
  109. *p_id = p_new_user->u_id;
  110. /*mark enable flag to true*/
  111. p_new_user->enable = true;
  112. /*add to uer lsit*/
  113. list_add_tail(&(p_new_user->entry), p_user_list);
  114. }
  115. } else {
  116. *p_id = 0;
  117. i_ret = -ENOMEM;
  118. BTIF_ERR_FUNC("allocate memory for mtk_btif_user failed\n");
  119. }
  120. BTIF_MUTEX_UNLOCK(&(p_btif->ops_mtx));
  121. BTIF_DBG_FUNC("--");
  122. return i_ret;
  123. }
  124. EXPORT_SYMBOL(mtk_wcn_btif_open);
  125. /*****************************************************************************
  126. * FUNCTION
  127. * mtk_wcn_btif_close
  128. * DESCRIPTION
  129. * close BTIF interface, will do BTIF module HW and SW de-initialization
  130. * once this API is called, p_btif should never be used by BTIF's user again
  131. * PARAMETERS
  132. * u_id [IN] BTIF's user id
  133. * RETURNS
  134. * int 0 = succeed;
  135. * others = fail,
  136. * for detailed information, please see ENUM_BTIF_OP_ERROR_CODE
  137. *****************************************************************************/
  138. int mtk_wcn_btif_close(unsigned long u_id)
  139. {
  140. int i_ret = -1;
  141. p_mtk_btif p_btif = NULL;
  142. struct list_head *pos = NULL;
  143. struct list_head *p_user_list = NULL;
  144. BTIF_DBG_FUNC("++");
  145. p_btif = btif_exp_srh_id(u_id);
  146. if (NULL == p_btif)
  147. return E_BTIF_INVAL_PARAM;
  148. if (mutex_lock_killable(&(p_btif->ops_mtx))) {
  149. BTIF_ERR_FUNC("mutex_lock_killable return failed\n");
  150. return E_BTIF_INTR;
  151. }
  152. p_user_list = &(p_btif->user_list);
  153. list_for_each(pos, p_user_list) {
  154. p_mtk_btif_user p_user =
  155. container_of(pos, mtk_btif_user, entry);
  156. if (p_user->u_id == u_id) {
  157. BTIF_INFO_FUNC
  158. ("user who's id is 0x%lx deleted from user list\n",
  159. u_id);
  160. list_del(pos);
  161. vfree(p_user);
  162. i_ret = btif_close(p_btif);
  163. if (i_ret)
  164. BTIF_WARN_FUNC("BTIF close failed");
  165. break;
  166. }
  167. }
  168. BTIF_MUTEX_UNLOCK(&(p_btif->ops_mtx));
  169. BTIF_DBG_FUNC("--");
  170. return 0;
  171. }
  172. EXPORT_SYMBOL(mtk_wcn_btif_close);
  173. /*****************************************************************************
  174. * FUNCTION
  175. * mtk_wcn_btif_write
  176. * DESCRIPTION
  177. * send data throuth BTIF module
  178. * there's no internal buffer to cache STP data in BTIF driver,
  179. * if in DMA mode
  180. * btif driver will check if there's enough space in vFIFO for data to send in DMA mode
  181. * if yes, put data to vFIFO and return corresponding data length to caller
  182. * if no, corresponding error code will be returned to called
  183. * PARAMETERS
  184. * p_btif [IN] pointer returned by mtk_wcn_btif_open
  185. * p_buf [IN] pointer to target data to send
  186. * len [IN] data length (should be less than 2014 bytes per STP package)
  187. *
  188. * if in non-DMA mode, BTIF driver will try to write to THR of BTIF controller
  189. * if btif driver detected that no space is available in Tx FIFO,
  190. * will return E_BTIF_NO_SPACE, mostly something is wrong with BTIF or
  191. * consys when this return value is returned
  192. * RETURNS
  193. * int positive: data length send through BTIF;
  194. * negative: please see ENUM_BTIF_OP_ERROR_CODE
  195. * E_BTIF_AGAIN (0) will be returned to caller
  196. * if btif does not have enough vFIFO to send data,
  197. * when caller get 0, he should wait for a moment
  198. * (5~10ms maybe) and try a few times (maybe 10~20)
  199. * if still get E_BTIF_AGAIN,
  200. * should call BTIF's debug API and dump BTIF driver
  201. * and BTIF/DMA register information to kernel log for debug
  202. * E_BTIF_BAD_POINTER will be returned to caller
  203. * if btif is not opened successfully before call this API
  204. * E_BTIF_INVAL_PARAM will be returned if parameter is not valid
  205. *****************************************************************************/
  206. int mtk_wcn_btif_write(unsigned long u_id,
  207. const unsigned char *p_buf, unsigned int len)
  208. {
  209. int i_ret = -1;
  210. p_mtk_btif p_btif = NULL;
  211. BTIF_DBG_FUNC("++");
  212. p_btif = btif_exp_srh_id(u_id);
  213. if (NULL == p_btif)
  214. return E_BTIF_INVAL_PARAM;
  215. if (NULL == p_buf) {
  216. BTIF_ERR_FUNC("invalid p_buf (0x%p)\n", p_buf);
  217. return E_BTIF_INVAL_PARAM;
  218. }
  219. if ((0 == len) || (BTIF_MAX_LEN_PER_PKT < len)) {
  220. BTIF_ERR_FUNC("invalid buffer length(%d)\n", len);
  221. return E_BTIF_INVAL_PARAM;
  222. }
  223. i_ret = btif_send_data(p_btif, p_buf, len);
  224. BTIF_DBG_FUNC("--, i_ret:%d\n", i_ret);
  225. return i_ret;
  226. }
  227. EXPORT_SYMBOL(mtk_wcn_btif_write);
  228. /*****************************************************************************
  229. * FUNCTION
  230. * mtk_wcn_btif_read
  231. * DESCRIPTION
  232. * read data from BTIF module
  233. * PARAMETERS
  234. * p_btif [IN] pointer returned by mtk_wcn_btif_open
  235. * p_buf [IN/OUT] pointer to buffer where rx data will be put
  236. * max_len [IN] max buffer length
  237. * RETURNS
  238. * int positive: data length read from BTIF;
  239. * negative: please see ENUM_BTIF_OP_ERROR_CODE
  240. *****************************************************************************/
  241. int mtk_wcn_btif_read(unsigned long u_id,
  242. unsigned char *p_buf, unsigned int max_len)
  243. {
  244. return 0;
  245. }
  246. /*****************************************************************************
  247. * FUNCTION
  248. * mtk_wcn_btif_dpidle_ctrl
  249. * DESCRIPTION
  250. * control if BTIF module allow system enter deepidle state or not
  251. * PARAMETERS
  252. * p_btif [IN] pointer returned by mtk_wcn_btif_open
  253. * en_flag [IN] one of ENUM_BTIF_DPIDLE_CTRL
  254. * RETURNS
  255. * int always return 0
  256. *****************************************************************************/
  257. int mtk_wcn_btif_dpidle_ctrl(unsigned long u_id, ENUM_BTIF_DPIDLE_CTRL en_flag)
  258. {
  259. int i_ret = -1;
  260. p_mtk_btif p_btif = NULL;
  261. p_btif = btif_exp_srh_id(u_id);
  262. if (NULL == p_btif)
  263. return E_BTIF_INVAL_PARAM;
  264. if (BTIF_DPIDLE_DISABLE == en_flag)
  265. i_ret = btif_exit_dpidle(p_btif);
  266. else
  267. i_ret = btif_enter_dpidle(p_btif);
  268. return i_ret;
  269. }
  270. EXPORT_SYMBOL(mtk_wcn_btif_dpidle_ctrl);
  271. /*****************************************************************************
  272. * FUNCTION
  273. * mtk_wcn_btif_rx_cb_register
  274. * DESCRIPTION
  275. * register rx callback function to BTIF module by btif user
  276. * PARAMETERS
  277. * p_btif [IN] pointer returned by mtk_wcn_btif_open
  278. * rx_cb [IN] pointer to stp rx handler callback function,
  279. * should be comply with MTK_WCN_BTIF_RX_CB
  280. * RETURNS
  281. * int 0 = succeed;
  282. * others = fail, for detailed information,
  283. * please see ENUM_BTIF_OP_ERROR_CODE
  284. *****************************************************************************/
  285. int mtk_wcn_btif_rx_cb_register(unsigned long u_id, MTK_WCN_BTIF_RX_CB rx_cb)
  286. {
  287. int i_ret = -1;
  288. p_mtk_btif p_btif = NULL;
  289. p_btif = btif_exp_srh_id(u_id);
  290. if (NULL == p_btif)
  291. return E_BTIF_INVAL_PARAM;
  292. i_ret = btif_rx_cb_reg(p_btif, rx_cb);
  293. return i_ret;
  294. }
  295. EXPORT_SYMBOL(mtk_wcn_btif_rx_cb_register);
  296. /*****************************************************************************
  297. * FUNCTION
  298. * mtk_wcn_btif_wakeup_consys
  299. * DESCRIPTION
  300. * once sleep command is sent to con sys,
  301. * should call this API before send wakeup command
  302. * to make con sys aware host want to send data to consys
  303. * PARAMETERS
  304. * p_btif [IN] pointer returned by mtk_wcn_btif_open
  305. * RETURNS
  306. * int 0 = succeed; others = fail, for detailed information, please see ENUM_BTIF_OP_ERROR_CODE
  307. *****************************************************************************/
  308. int mtk_wcn_btif_wakeup_consys(unsigned long u_id)
  309. {
  310. int i_ret = -1;
  311. p_mtk_btif p_btif = NULL;
  312. p_btif = btif_exp_srh_id(u_id);
  313. if (NULL == p_btif)
  314. return E_BTIF_INVAL_PARAM;
  315. /*i_ret = hal_btif_raise_wak_sig(p_btif->p_btif_info);*/
  316. i_ret = btif_raise_wak_signal(p_btif);
  317. return i_ret;
  318. }
  319. EXPORT_SYMBOL(mtk_wcn_btif_wakeup_consys);
  320. /***************End of Normal Mode API declearation**********/
  321. /***************Debug Purpose API declearation**********/
  322. /*****************************************************************************
  323. * FUNCTION
  324. * mtk_wcn_btif_loopback_ctrl
  325. * DESCRIPTION
  326. * enable/disable BTIF internal loopback function,
  327. * when this function is enabled data send to btif
  328. * will be received by btif itself
  329. * only for debug purpose, should never use this function in normal mode
  330. * PARAMETERS
  331. * p_btif [IN] pointer returned by mtk_wcn_btif_open
  332. * enable [IN] loopback mode control flag, enable or disable,
  333. * shou be one of ENUM_BTIF_LPBK_MODE
  334. * RETURNS
  335. * int 0 = succeed;
  336. * others = fail, for detailed information, please see ENUM_BTIF_OP_ERROR_CODE
  337. *****************************************************************************/
  338. int mtk_wcn_btif_loopback_ctrl(unsigned long u_id, ENUM_BTIF_LPBK_MODE enable)
  339. {
  340. int i_ret = -1;
  341. p_mtk_btif p_btif = NULL;
  342. p_btif = btif_exp_srh_id(u_id);
  343. if (NULL == p_btif)
  344. return E_BTIF_INVAL_PARAM;
  345. i_ret =
  346. btif_lpbk_ctrl(p_btif, enable == BTIF_LPBK_ENABLE ? true : false);
  347. return i_ret;
  348. }
  349. EXPORT_SYMBOL(mtk_wcn_btif_loopback_ctrl);
  350. /*****************************************************************************
  351. * FUNCTION
  352. * mtk_wcn_btif_logger_ctrl
  353. * DESCRIPTION
  354. * control BTIF logger function's behavior
  355. * PARAMETERS
  356. * p_btif [IN] pointer returned by mtk_wcn_btif_open
  357. * flag [IN] should be one of ENUM_BTIF_DBG_ID
  358. * BTIF_DISABLE_LOGGER - disable btif logger
  359. * BTIF_ENABLE_LOGGER - enable btif logger
  360. * BTIF_DUMP_LOG - dump log logged by btif
  361. * BTIF_CLR_LOG - clear btif log buffer
  362. * BTIF_DUMP_BTIF_REG - dump btif controller's register
  363. * BTIF_DUMP_DMA_REG - dump DMA controller's register
  364. * RETURNS
  365. * int 0 = succeed; others = fail, for detailed information, please see ENUM_BTIF_OP_ERROR_CODE
  366. *****************************************************************************/
  367. int mtk_wcn_btif_dbg_ctrl(unsigned long u_id, ENUM_BTIF_DBG_ID flag)
  368. {
  369. int i_ret = -1;
  370. p_mtk_btif p_btif = NULL;
  371. p_btif = btif_exp_srh_id(u_id);
  372. if (NULL == p_btif)
  373. return E_BTIF_INVAL_PARAM;
  374. i_ret = 0;
  375. switch (flag) {
  376. case BTIF_DISABLE_LOGGER:{
  377. BTIF_INFO_FUNC
  378. ("disable btif log function for both Tx and Rx\n");
  379. btif_log_buf_disable(&p_btif->tx_log);
  380. btif_log_buf_disable(&p_btif->rx_log);
  381. }
  382. break;
  383. case BTIF_ENABLE_LOGGER:{
  384. BTIF_INFO_FUNC
  385. ("enable btif log function for both Tx and Rx\n");
  386. btif_log_buf_enable(&p_btif->tx_log);
  387. btif_log_buf_enable(&p_btif->rx_log);
  388. }
  389. break;
  390. case BTIF_DUMP_LOG:{
  391. BTIF_INFO_FUNC("dump btif log for both Tx and Rx\n");
  392. btif_log_buf_dmp_out(&p_btif->tx_log);
  393. btif_log_buf_dmp_out(&p_btif->rx_log);
  394. }
  395. break;
  396. case BTIF_CLR_LOG:{
  397. BTIF_INFO_FUNC("clear btif log for both Tx and Rx\n");
  398. btif_log_buf_reset(&p_btif->tx_log);
  399. btif_log_buf_reset(&p_btif->rx_log);
  400. }
  401. break;
  402. case BTIF_DUMP_BTIF_REG:
  403. /*TBD*/ btif_dump_reg(p_btif);
  404. break;
  405. case BTIF_ENABLE_RT_LOG:
  406. BTIF_INFO_FUNC
  407. ("enable btif real time log for both Tx and Rx\n");
  408. btif_log_output_enable(&p_btif->tx_log);
  409. btif_log_output_enable(&p_btif->rx_log);
  410. break;
  411. case BTIF_DISABLE_RT_LOG:
  412. BTIF_INFO_FUNC
  413. ("disable btif real time log for both Tx and Rx\n");
  414. btif_log_output_disable(&p_btif->tx_log);
  415. btif_log_output_disable(&p_btif->rx_log);
  416. break;
  417. default:
  418. BTIF_INFO_FUNC("not supported flag:%d\n", flag);
  419. i_ret = -2;
  420. break;
  421. }
  422. return i_ret;
  423. }
  424. EXPORT_SYMBOL(mtk_wcn_btif_dbg_ctrl);
  425. bool mtk_wcn_btif_parser_wmt_evt(unsigned long u_id,
  426. const char *sub_str, unsigned int str_len)
  427. {
  428. bool b_ret = false;
  429. p_mtk_btif p_btif = NULL;
  430. p_btif = btif_exp_srh_id(u_id);
  431. if (NULL == p_btif)
  432. return E_BTIF_INVAL_PARAM;
  433. b_ret = btif_parser_wmt_evt(p_btif, sub_str, str_len);
  434. BTIF_INFO_FUNC("parser wmt evt %s\n", b_ret ? "ok" : "fail");
  435. return b_ret;
  436. }
  437. /**********End of Debug Purpose API declearation**********/
  438. int btif_open_no_id(void)
  439. {
  440. int i_ret = 0;
  441. p_mtk_btif p_btif = &g_btif[0];
  442. i_ret = btif_open(p_btif);
  443. if (i_ret)
  444. BTIF_ERR_FUNC("btif_open failed, i_ret(%d)\n", i_ret);
  445. else
  446. BTIF_INFO_FUNC("btif_open succeed\n");
  447. return i_ret;
  448. }
  449. int btif_close_no_id(void)
  450. {
  451. int i_ret = 0;
  452. p_mtk_btif p_btif = &g_btif[0];
  453. i_ret = btif_close(p_btif);
  454. if (i_ret)
  455. BTIF_ERR_FUNC("btif_close failed, i_ret(%d)\n", i_ret);
  456. else
  457. BTIF_INFO_FUNC("btif_close succeed\n");
  458. return i_ret;
  459. }
  460. int btif_write_no_id(const unsigned char *p_buf, unsigned int len)
  461. {
  462. int i_ret = -1;
  463. p_mtk_btif p_btif = &g_btif[0];
  464. BTIF_DBG_FUNC("++");
  465. if (NULL == p_buf) {
  466. BTIF_ERR_FUNC("invalid p_buf (0x%p)\n", p_buf);
  467. return E_BTIF_INVAL_PARAM;
  468. }
  469. if ((0 == len) || (BTIF_MAX_LEN_PER_PKT < len)) {
  470. BTIF_ERR_FUNC("invalid buffer length(%d)\n", len);
  471. return E_BTIF_INVAL_PARAM;
  472. }
  473. i_ret = btif_send_data(p_btif, p_buf, len);
  474. BTIF_DBG_FUNC("--, i_ret:%d\n", i_ret);
  475. return i_ret;
  476. }
  477. int btif_dpidle_ctrl_no_id(ENUM_BTIF_DPIDLE_CTRL en_flag)
  478. {
  479. int i_ret = -1;
  480. p_mtk_btif p_btif = &g_btif[0];
  481. if (BTIF_DPIDLE_DISABLE == en_flag)
  482. i_ret = btif_exit_dpidle(p_btif);
  483. else
  484. i_ret = btif_enter_dpidle(p_btif);
  485. return i_ret;
  486. }
  487. int btif_wakeup_consys_no_id(void)
  488. {
  489. int i_ret = -1;
  490. p_mtk_btif p_btif = &g_btif[0];
  491. /*i_ret = hal_btif_raise_wak_sig(p_btif->p_btif_info);*/
  492. i_ret = btif_raise_wak_signal(p_btif);
  493. return i_ret;
  494. }
  495. int btif_loopback_ctrl_no_id(ENUM_BTIF_LPBK_MODE enable)
  496. {
  497. int i_ret = -1;
  498. p_mtk_btif p_btif = &g_btif[0];
  499. i_ret =
  500. btif_lpbk_ctrl(p_btif, enable == BTIF_LPBK_ENABLE ? true : false);
  501. return i_ret;
  502. }
  503. int btif_dbg_ctrl_no_id(ENUM_BTIF_DBG_ID flag)
  504. {
  505. int i_ret = -1;
  506. p_mtk_btif p_btif = &g_btif[0];
  507. i_ret = 0;
  508. switch (flag) {
  509. case BTIF_DISABLE_LOGGER:{
  510. BTIF_INFO_FUNC
  511. ("disable btif log function for both Tx and Rx\n");
  512. btif_log_buf_disable(&p_btif->tx_log);
  513. btif_log_buf_disable(&p_btif->rx_log);
  514. }
  515. break;
  516. case BTIF_ENABLE_LOGGER:{
  517. BTIF_INFO_FUNC
  518. ("enable btif log function for both Tx and Rx\n");
  519. btif_log_buf_enable(&p_btif->tx_log);
  520. btif_log_buf_enable(&p_btif->rx_log);
  521. }
  522. break;
  523. case BTIF_DUMP_LOG:{
  524. BTIF_INFO_FUNC("dump btif log for both Tx and Rx\n");
  525. btif_log_buf_dmp_out(&p_btif->tx_log);
  526. btif_log_buf_dmp_out(&p_btif->rx_log);
  527. }
  528. break;
  529. case BTIF_CLR_LOG:{
  530. BTIF_INFO_FUNC("clear btif log for both Tx and Rx\n");
  531. btif_log_buf_reset(&p_btif->tx_log);
  532. btif_log_buf_reset(&p_btif->rx_log);
  533. }
  534. break;
  535. case BTIF_DUMP_BTIF_REG:
  536. /*TBD*/ btif_dump_reg(p_btif);
  537. break;
  538. case BTIF_ENABLE_RT_LOG:
  539. BTIF_INFO_FUNC
  540. ("enable btif real time log for both Tx and Rx\n");
  541. btif_log_output_enable(&p_btif->tx_log);
  542. btif_log_output_enable(&p_btif->rx_log);
  543. break;
  544. case BTIF_DISABLE_RT_LOG:
  545. BTIF_INFO_FUNC
  546. ("disable btif real time log for both Tx and Rx\n");
  547. btif_log_output_disable(&p_btif->tx_log);
  548. btif_log_output_disable(&p_btif->rx_log);
  549. break;
  550. default:
  551. BTIF_INFO_FUNC("not supported flag:%d\n", flag);
  552. i_ret = -2;
  553. break;
  554. }
  555. return i_ret;
  556. }
  557. int mtk_btif_exp_open_test(void)
  558. {
  559. int i_ret = 0;
  560. i_ret = btif_open_no_id();
  561. if (i_ret < 0) {
  562. BTIF_INFO_FUNC("mtk_wcn_btif_open failed\n");
  563. return -1;
  564. }
  565. BTIF_INFO_FUNC("mtk_wcn_btif_open succeed\n");
  566. return i_ret;
  567. }
  568. int mtk_btif_exp_close_test(void)
  569. {
  570. int i_ret = 0;
  571. i_ret = btif_close_no_id();
  572. if (i_ret < 0) {
  573. BTIF_INFO_FUNC("mtk_wcn_btif_close failed\n");
  574. return -1;
  575. }
  576. BTIF_INFO_FUNC("mtk_wcn_btif_close succeed\n");
  577. return i_ret;
  578. }
  579. int mtk_btif_exp_write_test(void)
  580. {
  581. return mtk_btif_exp_write_stress_test(100, 10);
  582. }
  583. int mtk_btif_exp_write_stress_test(unsigned int length, unsigned int max_loop)
  584. {
  585. #define BUF_LEN 1024
  586. int i_ret = 0;
  587. int idx = 0;
  588. int buf_len = length > BUF_LEN ? BUF_LEN : length;
  589. int loop = max_loop > 1000000 ? 1000000 : max_loop;
  590. unsigned char *buffer;
  591. buffer = kmalloc(BUF_LEN, GFP_KERNEL);
  592. if (!buffer) {
  593. BTIF_ERR_FUNC("btif tester kmalloc failed\n");
  594. return -1;
  595. }
  596. for (idx = 0; idx < buf_len; idx++)
  597. /* btif_stress_test_buf[idx] = BUF_LEN -idx; */
  598. *(buffer + idx) = idx % 255;
  599. i_ret = btif_loopback_ctrl_no_id(BTIF_LPBK_ENABLE);
  600. BTIF_INFO_FUNC("mtk_wcn_btif_loopback_ctrl returned %d\n", i_ret);
  601. while (loop--) {
  602. i_ret = btif_write_no_id(buffer, buf_len);
  603. BTIF_INFO_FUNC("mtk_wcn_btif_write left loop:%d, i_ret:%d\n",
  604. loop, i_ret);
  605. if (i_ret != buf_len) {
  606. BTIF_INFO_FUNC
  607. ("mtk_wcn_btif_write failed, target len %d, sent len: %d\n",
  608. buf_len, i_ret);
  609. break;
  610. }
  611. buf_len--;
  612. if (0 >= buf_len)
  613. buf_len = length > BUF_LEN ? BUF_LEN : length;
  614. }
  615. kfree(buffer);
  616. return i_ret;
  617. }
  618. int mtk_btif_exp_suspend_test(void)
  619. {
  620. int i_ret = 0;
  621. p_mtk_btif p_btif = &g_btif[0];
  622. i_ret = _btif_suspend(p_btif);
  623. return i_ret;
  624. }
  625. int mtk_btif_exp_restore_noirq_test(void)
  626. {
  627. int i_ret = 0;
  628. p_mtk_btif p_btif = &g_btif[0];
  629. i_ret = _btif_restore_noirq(p_btif);
  630. return i_ret;
  631. }
  632. int mtk_btif_exp_clock_ctrl(int en)
  633. {
  634. int i_ret = 0;
  635. p_mtk_btif p_btif = &g_btif[0];
  636. i_ret = btif_clock_ctrl(p_btif, en);
  637. return i_ret;
  638. }
  639. int mtk_btif_exp_resume_test(void)
  640. {
  641. int i_ret = 0;
  642. p_mtk_btif p_btif = &g_btif[0];
  643. i_ret = _btif_resume(p_btif);
  644. return i_ret;
  645. }
  646. int mtk_btif_exp_enter_dpidle_test(void)
  647. {
  648. return btif_dpidle_ctrl_no_id(BTIF_DPIDLE_ENABLE);
  649. }
  650. int mtk_btif_exp_exit_dpidle_test(void)
  651. {
  652. return btif_dpidle_ctrl_no_id(BTIF_DPIDLE_DISABLE);
  653. }
  654. int mtk_btif_exp_log_debug_test(int flag)
  655. {
  656. int i_ret = 0;
  657. i_ret = btif_dbg_ctrl_no_id(flag);
  658. return i_ret;
  659. }
  660. /************End of Function**********/