Bcm4330 Bluetooth analysis summary

Source: Internet
Author: User

 

Bluetooth is implemented on the HCI Layer regardless of the underlying hardware driver. That is to say, the driver of HCI on the host is mainly to provide unified interfaces for the upper layer, so that the upper layer protocol does not depend on the specific hardware implementation. The firmware of HCI in the hardware communicates with the driver of HCI on the host, such as UART, USB, and SDIO.

The HCI Layer is abstracted as an hci_dev struct in front of all devices. Therefore, no matter which bluetooth device the actual device is or how it connects to the host, you must register an hci_dev device with the HCI and Bluetooth core layers. The registration process is completed by the hci_registe_dev () function. You can also use the hci_unregister_dev () function to uninstall a bluetooth device.

There are many specific Bluetooth drivers, which are commonly used in Linux kernel. For example, hci_vhci.c is the Bluetooth virtual master controller driver, hci_uart.c (or hci_ldisc.c) is the serial port interface master controller driver, btusb. c is the USB Interface main controller driver, btsdio. c is the SDIO main controller driver.

 

To sum up, the three steps of Bluetooth driver are as follows:

1. The serial driver must be ready first (for uart Bluetooth), which is a bridge between the cpu and the bluetooth module.

2. Bluetooth initialization, module power-on and PSKEY settings.

3. Use hciattach to establish a data connection channel between the serial port and the Bluetooth protocol layer.

 

Bluetooth module power-on

Generally, it is controlled by a GPIO, which is usually high first, low, and then high;

PSKEY settings

To send commands to the bluetooth module through the serial port, you must set the baud rate and the crystal oscillator frequency of the bluetooth module, otherwise, it does not know how to jump. Of course, the initialization process may be different for different chips, and firmware may also be downloaded. This is generally done through bccmd.

 

After the above settings, the bluetooth module can work normally;

However, there is no link with the above Protocol Layer, that is, the data received from uart has not been transmitted to the hci Layer;

How to pass the uart, that is, the data transmitted by the bluetooth module, to the hci Layer is implemented through a mechanism called disc in the driver, this mechanism is intended to filter or restrict characters to be received. However, in the Bluetooth driver, the data is directly transmitted to the Bluetooth protocol layer, and the serial port control is no longer returned;

The comparison diagram of Uart handed over to the hci Layer:

 

To sum up the data process,

Basically:

1,
The uart port obtains the data of the bluetooth module;

2,
The uart port is passed to hci_uart through ldisc;

3,
Hci_uart is passed to the bcsp on it;

4,
Pass bcsp to hci Layer;

5,
Pass hci Layer to l2cap Layer

6. Send The l2cap layer to rfcomm;

 

 

Rfkill platform device

Static structresource nabi2_bcm4330_rfkill_resources [] = {

{

. Name = "bcm4330_nshutdown_gpio ",

. Start = TEGRA_GPIO_PD0,

. End = TEGRA_GPIO_PD0,

. Flags = IORESOURCE_IO,

},

{

. Name = "bcm4330_nreset_gpio ",

. Start = TEGRA_GPIO_PU0,

. End = TEGRA_GPIO_PU0,

. Flags = IORESOURCE_IO,

},

};

Static structplatform_device nabi2_bcm4330_rfkill_device = {

. Name = "bcm4330_rfkill ",

. Id =-1,

. Num_resources = ARRAY_SIZE (nabi2_bcm4330_rfkill_resources ),

. Resource = nabi2_bcm4330_rfkill_resources,

};

 

Rfkill platform Driver (mainly used to power Bluetooth and power off)

Static intbcm4330_bt_rfkill_set_power (void * data, bool blocked)

{

Module power-on and power-off operations.

}

Static const structrfkill_ops bcm4330_bt_rfkill_ops = {

. Set_block = bcm4330_bt_rfkill_set_power,

};

Static int bcm4330_rfkill_probe (structplatform_device * pdev ){

......

Bt_rfkill = rfkill_alloc ("bcm4330bluetooth", & pdev-> Dev,

Rfkill_type_bluetooth, & bcm4330_bt_rfkill_ops, null );

Rfkill_register (bt_rfkill );

......

}

Static struct platform_driverbcm4330_rfkill_driver = {

. Probe = bcm4330_rfkill_probe,

. Driver = {

. Name = "bcm4330_rfkill ",

. Owner = this_module,

},

};

Static int _ init bcm4330_rfkill_init (void)

{

Returnplatform_driver_register (& bcm4330_rfkill_driver );

}

 

Rfkill driver is very simple. It just registers a platform driver of bcm4330_rfkill_driver. Register an rfkill_ops
Bcm4330_bt_rfkill_ops function set. When you operate on/sys/class/rfkill/rfkill0/state, the function bcm4330_bt_rfkill_set_power is called to power on and off bluetooth.

 

Bluetooth drivers are available in the kernel (except for some products that have their own dedicated drivers, even with the same dedicated driver implementation architecture as the kernel). The serial Bluetooth driver is: /kernel/Drivers/Bluetooth/hci_ldisc.c

There is nothing to say about this driver. hci provides a unified interface function, no matter whether the bluetooth module is usb, sdio, uart ...... You only need to implement these interfaces.

All Bluetooth drivers are centered around an hci_dev struct, and then you can complete the following functions.

Hdev-> open = hci_uart_open;

Hdev-> close = hci_uart_close;

Hdev-> flush = hci_uart_flush;

Hdev-> send = hci_uart_send_frame;

Hdev-> destruct = hci_uart_destruct;

All interfaces are unified on the hci Layer, and the hci Layer is responsible for communicating with the Bluetooth protocol. Therefore, you only need to implement the interfaces provided by the hci Layer, and you do not need to perform multiple functions on the protocol.

 

Add the XXX_init.rc file for Bluetooth initialization as follows:

 

......

# Bluetooth

# Bluetooth MAC address programming

Chown bluetooth/system/etc/bluetooth # The device has the bluetooth permission on this directory

Setprop ro. bt. bdaddr_path "/system/etc/bluetooth/bdaddr" # Set the bluetooth address path

Chmod 0660/sys/class/rfkill/rfkill0/state # The rfkill file has the readable and writable permissions.

Chmod 0660/sys/class/rfkill/rfkill0/type

Chown bluetooth/sys/class/rfkill/rfkill0/state # rfkill file has bluetooth permission

Chown bluetooth/sys/class/rfkill/rfkill0/type

 

# BCM # bccmd is mainly used to initialize Bluetooth, such as power-on, set the baud rate, and download firmware ......

# For details, refer to the brcm_patchram_plus.c file for detailed instructions.

Service hciattach/system/bin/brcm_patchram_plus -- enable_hci -- scopcm = \

-- Baudrate 3000000 -- patchram/etc/firmware/bcm4330.hcd -- enable_lpm -- tosleep = 5000 -- create_bdaddr/dev/ttyHS2

# Create a Bluetooth address (because bcm4330 does not have a physical Bluetooth address) and use uart2 to connect to hci.

User bluetooth

Group bluetooth net_bt_admin

Disabled

 

......

 

The Bluetooth driver dependency is that the Bluetooth protocol supports the bluez protocol in android. We only need to select the bluez protocol when preparing it.

CONFIG_BT = y

CONFIG_BT_RFCOMM = y

CONFIG_BT_BNEP = y

CONFIG_BT_CMTP = y

CONFIG_BT_L2CAP = y

CONFIG_BT_SCO = y

If it is linux, or you need to port the bluez protocol on your own.

 

Now, you can use Bluetooth to go To the Bluetooth test.

1. Bluetooth power-on

# Echo 1>/sys/class/rfkill/rfkill0/State

2. Bluetooth Initialization

# Xxx_init.rc.

3. Test Bluetooth driver

# Hciconfig

It indicates that the Bluetooth driver has been properly initialized and loaded.

4. Activate Bluetooth

# Hciconfig hci0 up

# Hciconfig

It indicates that Bluetooth has been activated.

5. view the Bluetooth address

# Hcitool Dev

6. Scan for peripheral Bluetooth devices

# Hcitool Scan

 

The above picture shows that Bluetooth is working properly.

 

7. The above is a command test. To use it on Android, you also need to configure Bluetooth.

Find the corresponding boadconfig. mk file and set board_have_bluetooth.

Board_have_bluetooth: = true

 

 

 

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: info-contact@alibabacloud.com 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.