您的位置:首页 > 移动开发 > Android开发

Android BCM4330 蓝牙BT驱动调试记录

2013-04-01 14:38 417 查看
网上关于BT的驱动很少,所以我在开发过程中把其中的步骤记录下来。供大家相互学习讨论。

一、关于BT driver的移植:

1. Enablebluetootch in BoadConfig.mk
       BOARD_HAVE_BLUETOOTH := true

2.实现BT电源管理rfkill驱动。
Kernel/driver/bluetooth/bluetooth-power.c    高通的这个文件基本上不用动。
在kernel\arch\arm\mach_msm7x27.c: static int bluetooth_power(int on)中
实现:上电:把bt_reset pin 和bt_reg_on pin 拉低
                mdelay(10);
              把bt_resetpin 和bt_reg_on pin 拉高
              mdelay(150)
      下电:把bt_reset pin 和bt_reg_on pin 拉低       
 
3. RebuildAndroid image and reboot
命令行测试:
echo 0 >/sys/class/rfkill/rfkill0/state   //BT下电
echo 1 >/sys/class/rfkill/rfkill0/state   //BT上电
brcm_patchram_plus-d --patchram /etc/firmware/BCM4329B1_002.002.023.0061.0062.hcd/dev/ttyHS0
hciattach -s115200 /dev/ttyHS0 any
没任何错误提示是可以用以下测试
hciconfig hci0up
hcitool scan
 
4.实现BT睡眠唤醒机制
Kernel\drivers\bluetooth\bluesleep.c一般来说这个文件改动比较少,但可能逻辑上会有些问题。需要小的改动。
在kernel\arch\arm\mach_xxx/board_xxx.c:bluesleep_resources中定义gpio_host_wake(BT唤醒host脚)、gpio_ext_wake(host唤醒BT脚)、host_wake(BT唤醒host的中断号)。
注:各个平台的board_xxx.c文件名字不同,请客户确认 

5.系统集成
1)在init.qcom.rc中确认有下面的内容:
service hciattach/system/bin/sh /system/etc/init.qcom.bt.sh
    user bluetooth
    group qcom_oncrpc bluetooth net_bt_admin
    disabled
    oneshot
 
2)修改init.qcom.bt.sh
确认有:
BLUETOOTH_SLEEP_PATH=/proc/bluetooth/sleep/proto
echo 1 >$BLUETOOTH_SLEEP_PATH
/system/bin/hciattach-n /dev/ttyHS0 any 3000000 flow & 改为:
./brcm_patchram_plus--enable_lpm –enable_hci --patchram /system/etc/wifi/BCM4329BT.hcd --baudrate3000000 /dev/ttyHS0 &
注掉:高通下载firmware的命令。
 
6.重新编译system。此时BT应该能运行了。

二、BT的休眠唤醒配置

BT的休眠在driver/bluetooth/bluesleep.c中,首先驱动的名字叫“bluesleep”与arch/arm/mach-msm/board-msm7x30.c相匹配就执行platform_driver_probe(&bluesleep_driver, bluesleep_probe)然后调用static int __init bluesleep_probe(struct platform_device *pdev),这里会配置两个引脚HOST_WAKE_BT
& BT_WAKE_HOST 
bsi = kzalloc(sizeof(struct bluesleep_info), GFP_KERNEL);

        if (!bsi)

                return -ENOMEM;

        res = platform_get_resource_byname(pdev, IORESOURCE_IO,

                                "gpio_host_wake");

        if (!res) {

                BT_ERR("couldn't find host_wake gpio\n");

                ret = -ENODEV;

                goto free_bsi;

        }

        bsi->host_wake = res->start;

        //[SIMT-zhangmin-111230] change the configuration of BT sleep gpio from bt_power to here {

        gpio_tlmm_config(GPIO_CFG(bsi->host_wake, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),GPIO_CFG_ENABLE);

        //[SIMT-zhangmin-111230] }

        ret = gpio_request(bsi->host_wake, "bt_host_wake");

        if (ret)

                goto free_bsi;

        ret = gpio_direction_input(bsi->host_wake);

 bsi->host_wake_irq = platform_get_irq_byname(pdev, "host_wake");

如上代码所示,主要将HOST_WAKE_BT设置为输出脚,BT_WAKE_HOST 设置为输入脚并也设置为中断脚,等待BT芯片的唤醒。
然后再bluesleep_init函数中建立BT目录/proc/bluetooth/sleep/读btwake中HOST_WAKE_BT的状态。读出的状态值为0或1。
或在BT目录/proc/bluetooth/sleep/写btwake中HOST_WAKE_BT的状态。写出状态值为0或1。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: