Small analysis of MTK Bt/wifi

Source: Internet
Author: User

Idle time to consult the MTK Bt/wifi corresponding information, understand a little frame knowledge, and the underlying driver did a simple code flow tracking, but also left some problems, now do a simple record, not sure if there is still time and opportunity to continue to improve.

is the MT6589 platform, SDIO interface hardware circuit diagram, the platform has four groups of Sdio, of which MT6520/28 will be used in one of the groups, of course, SDIO only for WiFi data communication.

In the Init.project.rc file,



View the makefile file that generated the Mtk_hif_sdio.ko so that the corresponding source files can be found,

obj-$ (Config_mtk_combo) + = mtk_hif_sdio$ (ext_flag). O

mtk_hif_sdio$ (ext_flag)-objs: = linux/pub/hif_sdio.o

mtk_hif_sdio$ (ext_flag)-objs + = LINUX/PUB/HIF_SDIO_CHRDEV.O

mtk_hif_sdio$ (ext_flag)-objs + = PLATFORM/ALPS/MTK_WCN_CMB_HW.O

mtk_hif_sdio$ (ext_flag)-objs + = PLATFORM/ALPS/WMT_PLAT_ALPS.O

mtk_hif_sdio$ (ext_flag)-objs + = LINUX/PUB/OSAL.O

Module entry:


Similarly, the following results can be obtained,



obj-$ (Config_mtk_combo) + = mtk_stp_wmt$ (ext_flag). O

# WMT Driver-core part

mtk_stp_wmt$ (ext_flag)-objs: = CORE/WMT_CORE.O core/wmt_ctrl.o core/wmt_func.o core/wmt_ic_6620.ocore/wmt_lib.o Core /wmt_conf.o

#ifeq ($ (mtk_combo_chip), MT6628)

mtk_stp_wmt$ (ext_flag)-objs + = CORE/WMT_IC_6628.O


# WMT Driver-linux Private part

mtk_stp_wmt$ (ext_flag)-objs + = LINUX/PRI/WMT_DEV.O LINUX/PRI/WMT_EXP.O

mtk_stp_wmt$ (ext_flag)-objs + = LINUX/PRI/WMT_TM.O

# WMT Driver-osal

mtk_stp_wmt$ (ext_flag)-objs + = LINUX/PUB/OSAL.O

# WMT Driver-platform Implementation

Ccflags-y + =-D wmt_plat_alps

mtk_stp_wmt$ (ext_flag)-objs + = PLATFORM/ALPS/WMT_PLAT_ALPS.O

mtk_stp_wmt$ (ext_flag)-objs + = PLATFORM/ALPS/WMT_PLAT_STUB.O

# Fixme:select desired HW According to ProjectConfiguration

#ifeq ($ (mtk_combo_chip), MT6628)

#mtk_stp_wmt $ (ext_flag)-objs + = PLATFORM/ALPS/MTK_WCN_CMB_HW_6628.O


mtk_stp_wmt$ (ext_flag)-objs + = PLATFORM/ALPS/MTK_WCN_CMB_HW.O


mtk_stp_wmt$ (ext_flag)-objs + = LINUX/PRI/STP_EXP.O core/stp_core.ocore/psm_core.o core/btm_core.o linux/pri/stp_ Dbg.o

#ifeq ($ (mtk_combo_chip), MT6628)

# WMT stub part (built-in kernel image)








Simple analysis of HIF_SDIO.C files


Line 1794th, register the driver mtk_sdio_client_drv on the Sdio bus,

Sdio on the bus, the driver is paired with the device by MTK_SDIO_ID_TBL.

And the Sdio_func equipment, by the host to the device power, recognition and other actions to find and generate a series.

Hif_sdio_probe function: After finding the corresponding Sdio_func, join the list table and enable the Func to set the maximum data transfer buf when the host communicates with it.

Enables a SDIO functionfor usage

The identification process of SDIO equipment is probably as follows,


Init_delayed_work (&host->detect,mmc_rescan) in the Mmc_alloc_host function;

Mmc_rescan----> Mmc_rescan_try_freq---->mmc_attach_sdio

If there is time to continue to understand the MTK host implementation code and Host->detect call.

Go back to the Hif_sdio_init function, line 1798th, call the Hifsdiod_start function,

Create a consys-id-query thread, run every 10s, and don't know what it's for?

Return to the Hif_sdio_init function, line 1800th, call the Hif_sdio_create_dev_node function

Create a hifsdiod character device and get chipid.

WMT Drive


Wmt_init function,

Line 1680th, call Stp_drv_init, mainly initializes the STP_CORE_CTX structure.

Line 1682th to 1696th, register MTK_STP_WMT character device, MKNOD/DEV/STPWMT C 190 0; that is, its device is/DEV/STPWMT

Following the simple process of tracking BT data, after the BT driver is loaded, it will generate the/DEV/STPBT device file, the operation function in the MTK library file, through the operation control of the kernel STPBT device files.



Register Mtk_stp_bt_chrdev character device, while Bt_dev_major is 192, in INIT.PROJECT.RC:MKNOD/DEV/STPBT C 192 0; So the character device is/DEV/STPBT, the corresponding device operation is as follows:


mtk_wcn_wmt_func_on (WMTDRV_TYPE_BT)->mtk_wcn_wmt_func_ctrl (wmtdrv_type_bt,wmt_opid_func_on); That is, send (wmtdrv_type_bt,wmt_opid_func_on) the message to the processing center,

Line 81st gets the p_osal_op from the GDevWmt.rFreeOpQ.queue array,

GDevWmt.rFreeOpQ.queue Queue in

The Mediatek\kernel\drivers\combo\common\core\wmt_lib.c:wmt_lib_init function is fully populated by Gdevwmt.arque, as shown in the following code.

Line 98th, Wmt_lib_host_awake_get->wmt_plat_wake_lock_ctrl (Wl_op_get), as shown in the code below,

Depending on whether the counter is greater than the Wmtwakelock/unlock sleep lock.

Line 100th, Disable_psm_monitor->wmt_lib_ps_disable->mtk_wcn_stp_psm_disable

Mtk_wcn_stp_is_uart_fullset_mode Judging whether it is Mtkstp_uart_full_mode

Stp_set_support_protocol <-Mtk_wcn_stp_set_mode <-wmt_ctrl_stp_conf_ex <-

Wmt_ctrl_stp_conf the wmt_ctrl_stp_conf data member in the array wmt_ctrl_func corresponding to the function pointer, <-Wmt_ctrl <-

Mt6628_sw_init <-wmt_ic_ops_mt6628 <-wmt_core_hw_check corresponding operation entry is saved in Gmtkwmtctx.p_ic_ops.


Mediatek\kernel\drivers\combo\common\core\wmt_lib.c:wmtd_thread Message Queuing forwarding mechanism processing center,

Created by Wmt_init-Wmt_lib_init.

Mtk_wcn_stp_is_ready determine if STP is ready

On line 106th, Wmt_lib_put_act_op joins P_osal_op to the RACTIVEOPQ queue, wakes up the message processing thread, and waits for the return of the processing result.

Processing Flow:

Pop->op.opid= wmt_opid_func_on;

Pop->op.au4opdata[0]= WMTDRV_TYPE_BT;

Wmt_core_opid-> Wmt_core_opid_handler, opfunc_func_on

Iret= (* (gpwmtfuncops[drvtype]->func_on)) (Gmtkwmtctx.p_ic_ops,wmt_conf_get_cfg ()); -

Wmt_func_bt_ops-> wmt_func_bt_on, Wmt_core_func_ctrl_cmd (wmtdrv_type_bt,mtk_wcn_bool_true), the function code is as follows,

Wmt_core_tx-WMT_CTRL_TX_EX->mtk_wcn_stp_send_data (pData, size, wmt_task_indx);

Stp_send_tx_queue (STP_CORE_CTX.SEQUENCE.TXSEQ);->

(*SYS_IF_TX) (&stp_core_ctx.tx_buf[tx_read],last_len, &ret);

The SYS_IF_TX function pointer is assigned a value in the Mtk_wcn_stp_init function, from the Stp_drv_init function can be learned that the corresponding function is MTK_WCN_SYS_IF_TX, the code is as follows,

The STP_UART_IF_TX is assigned by the Stp_uart_tty_open function call Mtk_wcn_stp_register_if_tx to MTK_WCN_UART_TX, that is, the final data is sent out by the UART.

Subsequent UART is how to determine which and how to connect the data call process, or continue to analyze.

Mtk_wcn_wmt_msgcb_reg (WMTDRV_TYPE_BT, BT_CDEV_RST_CB)


Small analysis of MTK Bt/wifi

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.