1. 程式人生 > >[MTK] BT驅動除錯總結

[MTK] BT驅動除錯總結

首先在init.Project.rc裡面找例如找fm bt wifi gps等等。。。
    # STP, WMT, GPS, FM and BT Driver
    insmod /system/lib/modules/mtk_stp_core.ko
    insmod /system/lib/modules/mtk_stp_uart.ko
    insmod /system/lib/modules/mtk_hif_sdio.ko
    insmod /system/lib/modules/mtk_stp_wmt.ko
    insmod /system/lib/modules/mtk_stp_gps.ko
    insmod /system/lib/modules/mtk_stp_bt.ko

    insmod /system/lib/modules/mtk_fm_drv.ko
    insmod /system/lib/modules/mtk_fm_priv.ko
    insmod /system/lib/modules/mtk_wmt_wifi.ko
上面載入驅動!!
如mtk_找bt驅動stp_bt.ko相關檔案 search mtk_stp_bt
找到與Makefile相關的依賴檔案
搜尋結果:
obj-$(CONFIG_MTK_COMBO_BT) += mtk_stp_bt$(EXT_FLAG).o
mtk_stp_bt$(EXT_FLAG)-objs:= linux/stp_chrdev_bt.o
結果為依靠上層linux目錄的stp_chrdev_bt.o檔案即找到stp_chrdev_bt.c原始檔,進入觀察正好是bt驅動程式碼,呵呵!!

第一步搜尋
bt 驅動
/beetle/mediatek/kernel/drivers/combo/common/linux/stp_chrdev_bt.c

-->mknod /dev/stpbt  c 192 0; 靜態手動建立的裝置節點-->init.rc 這種方式建立的靜態裝置節點在呼叫驅動的時候就會找相關匹配的
所以在程式碼建立主裝置號的時候就會有一個與之相匹配的裝置號-->192
在驅動程式碼stp_chrdev_bt.c中
#define BT_DEV_MAJOR 192 
static int BT_major = BT_DEV_MAJOR;       /* dynamic allocation */

module_param(BT_major, uint, 0);
static int BT_init(void)
440{
441    dev_t dev = MKDEV(BT_major, 0);//建立主裝置號!!!!
442    int alloc_ret = 0;
443    int cdev_err = 0;
.............
}
bt_drv.c
Pxa.c --->關於uart驅動相關
Mtk.c----->關於uart驅動相關
Hci_ldis.c --->hci_uart_init();-->Hci_bcsp.c-->bcsp_init();
Hci_bcsp.c-->uart_init();
Hci_bcsp.c-->main(int argc, char *argv[])
pxa.c --->static int serial_pxa_startup(struct uart_port *port)設定中斷-->static inline irqreturn_t serial_pxa_irq(int irq, void *dev_id) 中斷處理-->static inline void receive_chars(struct uart_pxa_port *up, int *status)接收資料-->tty_flip_buffer_push(tty)-->傳送到disc中
Tty_buffer.c --->static void flush_to_ldisc(struct work_struct *work) 將資料寫入 disc-->Tty_ldisc.c-->receive_buf()-->hci_uart_ldisc.receive_buf= hci_uart_tty_receive;-->hci_ldisc.c-->hci_uart_tty_receive-->將資料交給了hci層
{
static void hci_uart_tty_receive(struct tty_struct *tty, const u8 *data, char *flags, int count)
{
struct hci_uart *hu = (void *)tty->disc_data;


if (!hu || tty != hu->tty)
return;


if (!test_bit(HCI_UART_PROTO_SET, &hu->flags))
return;


spin_lock(&hu->rx_lock);
hu->proto->recv(hu, (void *) data, count);
hu->hdev->stat.byte_rx += count;
spin_unlock(&hu->rx_lock);


tty_unthrottle(tty);
}
}
Hci_bcsp.c ---> static int bcsp_recv(struct hci_uart *hu, void *data, int count) 接收hci_uart傳上來的資料。
--> static void bcsp_complete_rx_pkt(struct hci_uart *hu)-->hci_core.c -->int hci_recv_frame(struct sk_buff *skb)

BT資料流程
1 uart口取得藍芽模組資料;
2 uart口通過ldisc傳個hci_uart;
3 hci_uart傳給其上的bcsp;
4 bcsp 傳給hci層
5 hci傳給l2cap層
5 l2cap層傳給rfcomm
從上層到驅動分析:

Settings.java(mBluetoothEnabler)--> LocalBluetoothAdapter.java-->BluetoothAdapter.java-->IBluetooth.java-->IBluetooth.aidl-->BluetoothService.java-->BluetoothAdapterStateMachine.java-->BluetoothService.java

bt上電
Stp_chrdev_bt.c-->BT_open(struct inode *inode,struct file *file)-->

---->Wmt_exp.c -->mtk_wcn_wmt_func_on