A Bluetooth SDIO card driver talks with hardware through SDIO interface, providing R/W method for Bluetooth Adapter layer, here’s the class diagram for this relationship:
The outbound Bluetooth data path:
- Upper layer use HCI interface send() to send data/command packet, implemented as btmrvl_send_frame() in this driver.
- Put this packet in adapter’s tx queue, wakeup the main data processing thread (like NAPI in a network driver, thread function is btmrvl_service_main_thread()).
- In main data procssing thread, re-organize skb data payload for DMA transfer (in btmrvl_tx_pkt()).
- Call sdio_writesb() to write data to hardware (in btmrvl_sdio_host_to_card()).
The incoming Bluetooth data path:
- SDIO card received a data packet, triggered a interrupt to host.
- The SDIO ISR triggred the main data processing thread.
- In this thread, allocate a skb with DAM aligned, call sdio_readsb() to read the data from SDIO interface (in btmrvl_sdio_card_to_host()).
- Call hci_recv_frame(skb) to send this data packet to upper layer Bluetooth stack.
Appendix: How to register a driver specific ISR to SDIO’s ISR:
1 2 3 4 5 6 7 8 9 10 |
|
1 2 3 4 5 6 7 |
|
Source Code:
Note: How to load firmware for a SDIO device
1 2 3 4 5 6 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Alternatively, you can use request_firmware_nowait() if current thread is not allowed to sleep for a long time.
1
|
|
Reference:
1 2 3 4 5 |
|
Footnote: sdio_claim_host(card->func)
- card->func means an independent function residues in same card (there maybe different functions implemented in same card simultaneously, like BT and Wifi in MRVL 8787 module. The device field in struct sdio_device_id is used as function id to distinguish these functions, in this driver, the device field in driver is 0x911B for MRVL_BT_SD8787, it reflected as: 0x911b in /sys/class/mmc_host/mmc1/mmc1\:0001/mmc1\:0001\:3/device.
- sdio_claim_host() is acting like a lock, I guess this will serialize access to same SD device between different functions, and also between different threads inside same function.