本项目AP20蓝牙相关初始化文件:
1)蓝牙初始化配置文件/etc/bt_init.config
内容如下:
# command data port name (eg: /dev/ttyHS2)
device = /dev/ttyHS2
# command data port initial operating speed in bps (eg: 115200)
speed = 115200
# command data port normal operating speed in bps (eg: 3000000)
high_speed = 3500000
# if false, the firmware download will be done at 115kbps (false is default)
# if true, the firmware download will be done at high speed (typically >3Mbps)
high_speed_download = true
# Bluetooth device address override for testing (if defined, this is used instead of the factory setting)
#bdaddr = 11:12:13:14:15:16
# PCM interface configuration (is master if true, and slave if false; master by default)
PCM_master = true
# patchram downloader
downloader = /system/bin/bt_downloader --patchram /system/etc/BCM4329B1_002.002.023.0757.0780.hcd /dev/ttyHS2
# attach command
hci_attach = /system/bin/hciattach -s 3500000 /dev/ttyHS2 any 3500000 flow
# config command
hci_config = /system/xbin/hciconfig hci0 up
2)init.rc 中
service bt_init /system/bin/bt_init
class post-zygote_services
oneshot
3)bt_init解析/etc/bt_init.config并配置蓝牙
4)init.rc中
service bluetoothd /system/bin/bluetoothd -n
class post-zygote_services
socket bluetooth stream 660 bluetooth bluetooth
socket dbus_bluetooth stream 660 bluetooth bluetooth
# init.rc does not yet support applying capabilities, so run as root and
# let bluetoothd drop uid to bluetooth with the right linux capabilities
group bluetooth net_bt_admin misc
disabled
5)bluetoothd 调用打开或者关闭蓝牙电源
set_bluetooth_power
一般是打开/sys/class/rfkill/rfkill0/state
但是在一个项目中也有不使用rfkill,而是直接在内核提高/proc/bt_power来操作enable/disable 蓝牙电源
6)如果使用rfkill, 一般在board-stringray-bluetooth.c中probe 函数中调用rfkill_register()
static int __init bcm4329_bluetooth_init(void)
{
return platform_driver_register(&bcm4329_bluetooth_platform_driver);
}
static void __exit bcm4329_bluetooth_exit(void)
{
platform_driver_unregister(&bcm4329_bluetooth_platform_driver);
}
static struct platform_driver bcm4329_bluetooth_platform_driver = {
.probe = bcm4329_bluetooth_probe,
.remove = bcm4329_bluetooth_remove,
.driver = {
.name = "bcm4329_bluetooth",
.owner = THIS_MODULE,
},
};
static int bcm4329_bluetooth_probe(struct platform_device *pdev)
{
int rc = 0;
int ret = 0;
tegra_gpio_enable(BT_RESET_GPIO);
rc = gpio_request(BT_RESET_GPIO, "bcm4329_nreset_gpip");
if (unlikely(rc)) {
tegra_gpio_disable(BT_RESET_GPIO);
return rc;
}
tegra_gpio_enable(BT_SHUTDOWN_GPIO);
rc = gpio_request(BT_SHUTDOWN_GPIO, "bcm4329_nshutdown_gpio");
if (unlikely(rc)) {
tegra_gpio_disable(BT_RESET_GPIO);
tegra_gpio_disable(BT_SHUTDOWN_GPIO);
gpio_free(BT_RESET_GPIO);
return rc;
}
bcm4329_bt_rfkill_set_power(NULL, true);
bt_rfkill = rfkill_alloc("bcm4329 Bluetooth", &pdev->dev,
RFKILL_TYPE_BLUETOOTH, &bcm4329_bt_rfkill_ops,
NULL);
if (unlikely(!bt_rfkill)) {
tegra_gpio_disable(BT_RESET_GPIO);
tegra_gpio_disable(BT_SHUTDOWN_GPIO);
gpio_free(BT_RESET_GPIO);
gpio_free(BT_SHUTDOWN_GPIO);
return -ENOMEM;
}
rfkill_set_states(bt_rfkill, true, false);
rc = rfkill_register(bt_rfkill);
if (unlikely(rc)) {
rfkill_destroy(bt_rfkill);
tegra_gpio_disable(BT_RESET_GPIO);
tegra_gpio_disable(BT_SHUTDOWN_GPIO);
gpio_free(BT_RESET_GPIO);
gpio_free(BT_SHUTDOWN_GPIO);
return -1;
}
ret = bcm_bt_lpm_init(pdev);
if (ret) {
rfkill_unregister(bt_rfkill);
rfkill_destroy(bt_rfkill);
tegra_gpio_disable(BT_RESET_GPIO);
tegra_gpio_disable(BT_SHUTDOWN_GPIO);
gpio_free(BT_RESET_GPIO);
gpio_free(BT_SHUTDOWN_GPIO);
}
return ret;
}
7)上面是蓝牙模块的驱动,更深入处理issue,就需要理解kerne/net/bluetooth目录下面的
HCI 的代码。
下面有时间在理解一下项目中在该目录下面关于蓝牙性能优化的改动。