diff --git a/boards/96boards/carbon/96b_carbon_stm32f401xe.dts b/boards/96boards/carbon/96b_carbon_stm32f401xe.dts index d94c67dc79d99..4f2365f303ebd 100644 --- a/boards/96boards/carbon/96b_carbon_stm32f401xe.dts +++ b/boards/96boards/carbon/96b_carbon_stm32f401xe.dts @@ -20,6 +20,7 @@ zephyr,sram = &sram0; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &hci_spi; }; leds { @@ -124,7 +125,7 @@ pinctrl-names = "default"; /* Nordic nRF51822-QFAC */ - bt-hci@0 { + hci_spi: bt-hci@0 { compatible = "zephyr,bt-hci-spi"; reg = <0>; reset-gpios = <&gpiob 4 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; diff --git a/boards/96boards/carbon/Kconfig.defconfig b/boards/96boards/carbon/Kconfig.defconfig index cede46b95fe39..2cf1bbdc6fcec 100644 --- a/boards/96boards/carbon/Kconfig.defconfig +++ b/boards/96boards/carbon/Kconfig.defconfig @@ -14,9 +14,8 @@ if BT config SPI default y -choice BT_HCI_BUS_TYPE - default BT_SPI -endchoice +config BT_SPI + default y endif # BT diff --git a/boards/ambiq/apollo3_evb/apollo3_evb.dts b/boards/ambiq/apollo3_evb/apollo3_evb.dts index be6cb5e0e3969..51b19c55e236f 100644 --- a/boards/ambiq/apollo3_evb/apollo3_evb.dts +++ b/boards/ambiq/apollo3_evb/apollo3_evb.dts @@ -15,6 +15,7 @@ zephyr,shell-uart = &uart0; zephyr,uart-pipe = &uart0; zephyr,flash-controller = &flash; + zephyr,bt_hci = &bt_hci_apollo; }; aliases { diff --git a/boards/ambiq/apollo3p_evb/apollo3p_evb.dts b/boards/ambiq/apollo3p_evb/apollo3p_evb.dts index f0ad77017c064..277675449c4fa 100644 --- a/boards/ambiq/apollo3p_evb/apollo3p_evb.dts +++ b/boards/ambiq/apollo3p_evb/apollo3p_evb.dts @@ -15,6 +15,7 @@ zephyr,shell-uart = &uart0; zephyr,uart-pipe = &uart0; zephyr,flash-controller = &flash; + zephyr,bt_hci = &bt_hci_apollo; }; aliases { diff --git a/boards/ambiq/apollo4p_blue_kxr_evb/Kconfig.defconfig b/boards/ambiq/apollo4p_blue_kxr_evb/Kconfig.defconfig index 87e1c5a8764f9..7303c78a28644 100644 --- a/boards/ambiq/apollo4p_blue_kxr_evb/Kconfig.defconfig +++ b/boards/ambiq/apollo4p_blue_kxr_evb/Kconfig.defconfig @@ -9,10 +9,6 @@ if BT config MAIN_STACK_SIZE default 2048 -choice BT_HCI_BUS_TYPE - default BT_AMBIQ_HCI -endchoice - config BT_BUF_ACL_TX_COUNT default 14 diff --git a/boards/ambiq/apollo4p_blue_kxr_evb/apollo4p_blue_kxr_evb.dts b/boards/ambiq/apollo4p_blue_kxr_evb/apollo4p_blue_kxr_evb.dts index f9aa3c11c31c1..130a195154c8b 100644 --- a/boards/ambiq/apollo4p_blue_kxr_evb/apollo4p_blue_kxr_evb.dts +++ b/boards/ambiq/apollo4p_blue_kxr_evb/apollo4p_blue_kxr_evb.dts @@ -15,6 +15,7 @@ zephyr,shell-uart = &uart0; zephyr,uart-pipe = &uart0; zephyr,flash-controller = &flash; + zephyr,bt-hci = &bt_hci_apollo; }; aliases { diff --git a/boards/arduino/giga_r1/arduino_giga_r1_stm32h747xx_m7.dts b/boards/arduino/giga_r1/arduino_giga_r1_stm32h747xx_m7.dts index af7f0d673bedc..5d6e0dd7d883c 100644 --- a/boards/arduino/giga_r1/arduino_giga_r1_stm32h747xx_m7.dts +++ b/boards/arduino/giga_r1/arduino_giga_r1_stm32h747xx_m7.dts @@ -18,7 +18,7 @@ zephyr,console = &usart1; zephyr,shell-uart = &usart1; zephyr,uart-mcumgr = &usart1; - zephyr,bt-uart = &uart7; + zephyr,bt-hci = &bt_hci_uart; zephyr,sram = &sram0; zephyr,flash = &flash0; zephyr,canbus = &fdcan2; @@ -97,12 +97,17 @@ status = "okay"; hw-flow-control; - murata-1dx { - compatible = "infineon,cyw43xxx-bt-hci"; - bt-reg-on-gpios = <&gpioa 10 GPIO_ACTIVE_HIGH>; - bt-host-wake-gpios = <&gpiog 3 GPIO_ACTIVE_HIGH>; - bt-dev-wake-gpios = <&gpioh 7 GPIO_ACTIVE_HIGH>; - fw-download-speed = <115200>; + bt_hci_uart: bt_hci_uart { + compatible = "zephyr,bt-hci-uart"; + status = "okay"; + + murata-1dx { + compatible = "infineon,cyw43xxx-bt-hci"; + bt-reg-on-gpios = <&gpioa 10 GPIO_ACTIVE_HIGH>; + bt-host-wake-gpios = <&gpiog 3 GPIO_ACTIVE_HIGH>; + bt-dev-wake-gpios = <&gpioh 7 GPIO_ACTIVE_HIGH>; + fw-download-speed = <115200>; + }; }; }; diff --git a/boards/espressif/esp32_devkitc_wroom/Kconfig.defconfig b/boards/espressif/esp32_devkitc_wroom/Kconfig.defconfig index 6da35bf9735f0..374b423b5483c 100644 --- a/boards/espressif/esp32_devkitc_wroom/Kconfig.defconfig +++ b/boards/espressif/esp32_devkitc_wroom/Kconfig.defconfig @@ -12,10 +12,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD default 40960 if BT default 4096 -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice - endif # BOARD_ESP32_DEVKITC_WROOM_ESP32_PROCPU if BOARD_ESP32_DEVKITC_WROOM_ESP32_APPCPU diff --git a/boards/espressif/esp32_devkitc_wroom/esp32_devkitc_wroom_procpu.dts b/boards/espressif/esp32_devkitc_wroom/esp32_devkitc_wroom_procpu.dts index 6ba26177f5250..37a117d80dbe9 100644 --- a/boards/espressif/esp32_devkitc_wroom/esp32_devkitc_wroom_procpu.dts +++ b/boards/espressif/esp32_devkitc_wroom/esp32_devkitc_wroom_procpu.dts @@ -36,6 +36,7 @@ zephyr,shell-uart = &uart0; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &esp32_bt_hci; }; }; @@ -165,3 +166,7 @@ }; }; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/espressif/esp32_devkitc_wrover/Kconfig.defconfig b/boards/espressif/esp32_devkitc_wrover/Kconfig.defconfig index ba249b4a0a6af..c56c404a40e7f 100644 --- a/boards/espressif/esp32_devkitc_wrover/Kconfig.defconfig +++ b/boards/espressif/esp32_devkitc_wrover/Kconfig.defconfig @@ -10,10 +10,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD default 40960 if BT default 4096 -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice - endif # BOARD_ESP32_DEVKITC_WROVER_ESP32_PROCPU if BOARD_ESP32_DEVKITC_WROVER_ESP32_APPCPU diff --git a/boards/espressif/esp32_devkitc_wrover/esp32_devkitc_wrover_procpu.dts b/boards/espressif/esp32_devkitc_wrover/esp32_devkitc_wrover_procpu.dts index 8d414b1e8903f..f6ad45109c398 100644 --- a/boards/espressif/esp32_devkitc_wrover/esp32_devkitc_wrover_procpu.dts +++ b/boards/espressif/esp32_devkitc_wrover/esp32_devkitc_wrover_procpu.dts @@ -36,6 +36,7 @@ zephyr,shell-uart = &uart0; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &esp32_bt_hci; }; }; @@ -161,3 +162,7 @@ }; }; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/espressif/esp32_ethernet_kit/Kconfig.defconfig b/boards/espressif/esp32_ethernet_kit/Kconfig.defconfig index c1c49d1e0fdbb..75b0cc9f631ef 100644 --- a/boards/espressif/esp32_ethernet_kit/Kconfig.defconfig +++ b/boards/espressif/esp32_ethernet_kit/Kconfig.defconfig @@ -19,10 +19,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD default 40960 if BT default 4096 -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice - endif # BOARD_ESP32_ETHERNET_KIT_ESP32_PROCPU if BOARD_ESP32_ETHERNET_KIT_ESP32_APPCPU diff --git a/boards/espressif/esp32_ethernet_kit/esp32_ethernet_kit_procpu.dts b/boards/espressif/esp32_ethernet_kit/esp32_ethernet_kit_procpu.dts index 7c6c32970b745..124fa29df4e99 100644 --- a/boards/espressif/esp32_ethernet_kit/esp32_ethernet_kit_procpu.dts +++ b/boards/espressif/esp32_ethernet_kit/esp32_ethernet_kit_procpu.dts @@ -23,6 +23,7 @@ zephyr,shell-uart = &uart0; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &esp32_bt_hci; }; }; @@ -122,3 +123,7 @@ ð { phy-handle = <&phy>; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/espressif/esp32c3_devkitm/Kconfig.defconfig b/boards/espressif/esp32c3_devkitm/Kconfig.defconfig index 9944bb871951b..cf5aeac8382d0 100644 --- a/boards/espressif/esp32c3_devkitm/Kconfig.defconfig +++ b/boards/espressif/esp32c3_devkitm/Kconfig.defconfig @@ -9,7 +9,3 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD default 51200 if WIFI default 40960 if BT default 4096 - -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice diff --git a/boards/espressif/esp32c3_devkitm/esp32c3_devkitm.dts b/boards/espressif/esp32c3_devkitm/esp32c3_devkitm.dts index 039e72b48935c..ae11ed41aa2e2 100644 --- a/boards/espressif/esp32c3_devkitm/esp32c3_devkitm.dts +++ b/boards/espressif/esp32c3_devkitm/esp32c3_devkitm.dts @@ -20,6 +20,7 @@ zephyr,shell-uart = &uart0; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &esp32_bt_hci; }; aliases { @@ -130,3 +131,7 @@ }; }; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/espressif/esp32s3_devkitc/Kconfig.defconfig b/boards/espressif/esp32s3_devkitc/Kconfig.defconfig index 9b109ab4525bd..d539cd6652349 100644 --- a/boards/espressif/esp32s3_devkitc/Kconfig.defconfig +++ b/boards/espressif/esp32s3_devkitc/Kconfig.defconfig @@ -12,10 +12,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD default 40960 if BT default 4096 -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice - endif # BOARD_ESP32S3_DEVKITC_ESP32S3_PROCPU if BOARD_ESP32S3_DEVKITC_ESP32S3_APPCPU diff --git a/boards/espressif/esp32s3_devkitc/esp32s3_devkitc_procpu.dts b/boards/espressif/esp32s3_devkitc/esp32s3_devkitc_procpu.dts index 8894649a1bcc2..afff520f7ba14 100644 --- a/boards/espressif/esp32s3_devkitc/esp32s3_devkitc_procpu.dts +++ b/boards/espressif/esp32s3_devkitc/esp32s3_devkitc_procpu.dts @@ -25,6 +25,7 @@ zephyr,shell-uart = &uart0; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &esp32_bt_hci; }; aliases { @@ -168,3 +169,7 @@ }; }; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/espressif/esp32s3_devkitm/Kconfig.defconfig b/boards/espressif/esp32s3_devkitm/Kconfig.defconfig index 1905ae5f5515b..26339590ee31e 100644 --- a/boards/espressif/esp32s3_devkitm/Kconfig.defconfig +++ b/boards/espressif/esp32s3_devkitm/Kconfig.defconfig @@ -12,10 +12,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD default 40960 if BT default 4096 -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice - endif # BOARD_ESP32S3_DEVKITM_ESP32S3_PROCPU if BOARD_ESP32S3_DEVKITM_ESP32S3_APPCPU diff --git a/boards/espressif/esp32s3_devkitm/esp32s3_devkitm_procpu.dts b/boards/espressif/esp32s3_devkitm/esp32s3_devkitm_procpu.dts index 3ee4131ab33c6..c88bf0d01012e 100644 --- a/boards/espressif/esp32s3_devkitm/esp32s3_devkitm_procpu.dts +++ b/boards/espressif/esp32s3_devkitm/esp32s3_devkitm_procpu.dts @@ -25,6 +25,7 @@ zephyr,shell-uart = &uart0; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &esp32_bt_hci; }; aliases { @@ -172,3 +173,7 @@ }; }; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/espressif/esp_wrover_kit/Kconfig.defconfig b/boards/espressif/esp_wrover_kit/Kconfig.defconfig index a05a1684d6b14..adf8cd7e3980e 100644 --- a/boards/espressif/esp_wrover_kit/Kconfig.defconfig +++ b/boards/espressif/esp_wrover_kit/Kconfig.defconfig @@ -12,10 +12,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD default 40960 if BT default 4096 -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice - config DISK_DRIVER_SDMMC default y diff --git a/boards/espressif/esp_wrover_kit/esp_wrover_kit_procpu.dts b/boards/espressif/esp_wrover_kit/esp_wrover_kit_procpu.dts index ad900df0e46d4..5edfe4f761caa 100644 --- a/boards/espressif/esp_wrover_kit/esp_wrover_kit_procpu.dts +++ b/boards/espressif/esp_wrover_kit/esp_wrover_kit_procpu.dts @@ -36,6 +36,7 @@ zephyr,code-partition = &slot0_partition; zephyr,display = &ili9341; zephyr,sdhc = &sdhc1; + zephyr,bt-hci = &esp32_bt_hci; }; leds { @@ -243,3 +244,7 @@ }; }; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/ezurio/bl5340_dvk/Kconfig.defconfig b/boards/ezurio/bl5340_dvk/Kconfig.defconfig index 65c005ee28605..ece5d8d8d3960 100644 --- a/boards/ezurio/bl5340_dvk/Kconfig.defconfig +++ b/boards/ezurio/bl5340_dvk/Kconfig.defconfig @@ -57,9 +57,8 @@ config FLASH_LOAD_SIZE endif # BOARD_BL5340_DVK_NRF5340_CPUAPP_NS -choice BT_HCI_BUS_TYPE - default BT_HCI_IPC if BT -endchoice +config BT_HCI_IPC + default y if BT config HEAP_MEM_POOL_ADD_SIZE_BOARD int diff --git a/boards/ezurio/bl5340_dvk/bl5340_dvk_nrf5340_cpuapp_common.dtsi b/boards/ezurio/bl5340_dvk/bl5340_dvk_nrf5340_cpuapp_common.dtsi index 1f4d3f46a2032..372144f15b097 100644 --- a/boards/ezurio/bl5340_dvk/bl5340_dvk_nrf5340_cpuapp_common.dtsi +++ b/boards/ezurio/bl5340_dvk/bl5340_dvk_nrf5340_cpuapp_common.dtsi @@ -15,7 +15,7 @@ zephyr,bt-mon-uart = &uart0; zephyr,bt-c2h-uart = &uart0; zephyr,display = &ili9340; - zephyr,bt-hci-ipc = &ipc0; + zephyr,bt-hci = &bt_hci_ipc0; }; /* Main LEDs and buttons are on an I2C TCA9538 GPIO port expander */ diff --git a/boards/hardkernel/odroid_go/Kconfig.defconfig b/boards/hardkernel/odroid_go/Kconfig.defconfig index 8b9cb59d3f354..58874c1f51408 100644 --- a/boards/hardkernel/odroid_go/Kconfig.defconfig +++ b/boards/hardkernel/odroid_go/Kconfig.defconfig @@ -25,10 +25,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD default 40960 if BT default 4096 -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice - endif # BOARD_ODROID_GO_ESP32_PROCPU if BOARD_ODROID_GO_ESP32_APPCPU diff --git a/boards/hardkernel/odroid_go/odroid_go_procpu.dts b/boards/hardkernel/odroid_go/odroid_go_procpu.dts index 0d150d08f1603..c7de3a9c576e4 100644 --- a/boards/hardkernel/odroid_go/odroid_go_procpu.dts +++ b/boards/hardkernel/odroid_go/odroid_go_procpu.dts @@ -20,6 +20,7 @@ zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; zephyr,display = &ili9341; + zephyr,bt-hci = &esp32_bt_hci; }; leds { @@ -206,3 +207,7 @@ }; }; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/heltec/heltec_wifi_lora32_v2/Kconfig.defconfig b/boards/heltec/heltec_wifi_lora32_v2/Kconfig.defconfig index 4f459aa0ca425..a2979499b658f 100644 --- a/boards/heltec/heltec_wifi_lora32_v2/Kconfig.defconfig +++ b/boards/heltec/heltec_wifi_lora32_v2/Kconfig.defconfig @@ -12,10 +12,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD default 40960 if BT default 4096 -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice - endif # BOARD_HELTEC_WIFI_LORA32_V2_ESP32_PROCPU if BOARD_HELTEC_WIFI_LORA32_V2_ESP32_APPCPU diff --git a/boards/heltec/heltec_wifi_lora32_v2/heltec_wifi_lora32_v2_procpu.dts b/boards/heltec/heltec_wifi_lora32_v2/heltec_wifi_lora32_v2_procpu.dts index 5fdec28fe3389..4c7cedf82b5fc 100644 --- a/boards/heltec/heltec_wifi_lora32_v2/heltec_wifi_lora32_v2_procpu.dts +++ b/boards/heltec/heltec_wifi_lora32_v2/heltec_wifi_lora32_v2_procpu.dts @@ -55,6 +55,7 @@ zephyr,shell-uart = &uart0; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &esp32_bt_hci; }; }; @@ -149,5 +150,9 @@ }; }; +&esp32_bt_hci { + status = "okay"; +}; + /* Required by the ssd1306_128x64 shield which enables the OLED display */ arduino_i2c: &i2c0 {}; diff --git a/boards/heltec/heltec_wireless_stick_lite_v3/Kconfig.defconfig b/boards/heltec/heltec_wireless_stick_lite_v3/Kconfig.defconfig index 82915e44b949b..c1aa6f030c767 100644 --- a/boards/heltec/heltec_wireless_stick_lite_v3/Kconfig.defconfig +++ b/boards/heltec/heltec_wireless_stick_lite_v3/Kconfig.defconfig @@ -13,10 +13,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD default 40960 if BT default 4096 -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice - endif # BOARD_HELTEC_WIRELESS_STICK_LITE_V3_ESP32S3_PROCPU if BOARD_HELTEC_WIRELESS_STICK_LITE_V3_ESP32S3_APPCPU diff --git a/boards/heltec/heltec_wireless_stick_lite_v3/heltec_wireless_stick_lite_v3_procpu.dts b/boards/heltec/heltec_wireless_stick_lite_v3/heltec_wireless_stick_lite_v3_procpu.dts index ca455d9d78025..854eb101fe4d7 100644 --- a/boards/heltec/heltec_wireless_stick_lite_v3/heltec_wireless_stick_lite_v3_procpu.dts +++ b/boards/heltec/heltec_wireless_stick_lite_v3/heltec_wireless_stick_lite_v3_procpu.dts @@ -72,6 +72,7 @@ zephyr,shell-uart = &uart0; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &esp32_bt_hci; }; }; @@ -205,3 +206,7 @@ }; }; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/infineon/cy8cproto_062_4343w/Kconfig.defconfig b/boards/infineon/cy8cproto_062_4343w/Kconfig.defconfig index 270370c766015..5573b7f041773 100644 --- a/boards/infineon/cy8cproto_062_4343w/Kconfig.defconfig +++ b/boards/infineon/cy8cproto_062_4343w/Kconfig.defconfig @@ -36,13 +36,6 @@ config UART bool default y -config BT_UART - default y - -choice BT_HCI_BUS_TYPE - default BT_H4 -endchoice - endif # BT # Heap Pool Size diff --git a/boards/infineon/cy8cproto_062_4343w/cy8cproto_062_4343w.dts b/boards/infineon/cy8cproto_062_4343w/cy8cproto_062_4343w.dts index 7997344dd540a..b9e74ac685d0b 100644 --- a/boards/infineon/cy8cproto_062_4343w/cy8cproto_062_4343w.dts +++ b/boards/infineon/cy8cproto_062_4343w/cy8cproto_062_4343w.dts @@ -25,7 +25,7 @@ zephyr,flash = &flash0; zephyr,console = &uart5; zephyr,shell-uart = &uart5; - zephyr,bt_uart = &uart2; + zephyr,bt-hci = &bt_hci_uart; }; }; @@ -58,17 +58,22 @@ uart2: &scb2 { /* HW Flow control must be enabled for HCI H4 */ hw-flow-control; - bt-hci { - status = "okay"; - compatible = "infineon,cyw43xxx-bt-hci"; - bt-reg-on-gpios = <&gpio_prt3 4 (GPIO_ACTIVE_HIGH)>; - - /* Configuration UART speeds for firmware download (fw-download-speed) and - * HCI operation (hci-operation-speed). - * If hci-operation-speed or fw-download-speed are not defined in bt-hci{...} - * node, cyw43xx driver will use bus/current-speed as default speed. - */ - fw-download-speed = <3000000>; + bt_hci_uart: bt_hci_uart { + compatible = "zephyr,bt-hci-uart"; + + murata-1dx { + status = "okay"; + compatible = "infineon,cyw43xxx-bt-hci"; + bt-reg-on-gpios = <&gpio_prt3 4 (GPIO_ACTIVE_HIGH)>; + + /* Configuration UART speeds for firmware download (fw-download-speed) + * and HCI operation (hci-operation-speed). + * If hci-operation-speed or fw-download-speed are not defined in + * bt-hci{...} node, cyw43xx driver will use bus/current-speed as + * default speed. + */ + fw-download-speed = <3000000>; + }; }; }; diff --git a/boards/infineon/cy8cproto_063_ble/Kconfig.defconfig b/boards/infineon/cy8cproto_063_ble/Kconfig.defconfig index 2d079f63a6b48..4123455e9f93b 100644 --- a/boards/infineon/cy8cproto_063_ble/Kconfig.defconfig +++ b/boards/infineon/cy8cproto_063_ble/Kconfig.defconfig @@ -6,8 +6,6 @@ if BOARD_CY8CPROTO_063_BLE -choice BT_HCI_BUS_TYPE - default BT_PSOC6_BLESS if BT -endchoice +# No defaults to change for now endif # BOARD_CY8CPROTO_063_BLE diff --git a/boards/infineon/cy8cproto_063_ble/cy8cproto_063_ble.dts b/boards/infineon/cy8cproto_063_ble/cy8cproto_063_ble.dts index 0f96ff07a774f..5516895fddd8b 100644 --- a/boards/infineon/cy8cproto_063_ble/cy8cproto_063_ble.dts +++ b/boards/infineon/cy8cproto_063_ble/cy8cproto_063_ble.dts @@ -27,6 +27,7 @@ zephyr,flash = &flash0; zephyr,console = &uart5; zephyr,shell-uart = &uart5; + zephyr,bt-hci = &bluetooth; }; /delete-node/ cpu@0; diff --git a/boards/ite/it82xx2_evb/it82xx2_evb.dts b/boards/ite/it82xx2_evb/it82xx2_evb.dts index bd623e969c54f..29e8ad721c88d 100644 --- a/boards/ite/it82xx2_evb/it82xx2_evb.dts +++ b/boards/ite/it82xx2_evb/it82xx2_evb.dts @@ -25,7 +25,7 @@ chosen { zephyr,console = &uart1; zephyr,shell-uart = &uart1; - zephyr,bt-uart = &uart2; + zephyr,bt-hci = &bt_hci_uart; zephyr,sram = &sram0; zephyr,flash = &flash0; zephyr,flash-controller = &flashctrl; @@ -115,6 +115,11 @@ status = "okay"; current-speed = <460800>; clock-frequency = <1843200>; + + bt_hci_uart: bt_hci_uart { + compatible = "zephyr,bt-hci-uart"; + status = "okay"; + }; }; &ite_uart1_wrapper { diff --git a/boards/ite/it8xxx2_evb/it8xxx2_evb.dts b/boards/ite/it8xxx2_evb/it8xxx2_evb.dts index c111e9092aa15..0ee42f981f084 100644 --- a/boards/ite/it8xxx2_evb/it8xxx2_evb.dts +++ b/boards/ite/it8xxx2_evb/it8xxx2_evb.dts @@ -25,7 +25,7 @@ chosen { zephyr,console = &uart1; zephyr,shell-uart = &uart1; - zephyr,bt-uart = &uart2; + zephyr,bt-hci = &bt_hci_uart; zephyr,sram = &sram0; zephyr,flash = &flash0; zephyr,flash-controller = &flashctrl; @@ -105,6 +105,11 @@ status = "okay"; current-speed = <460800>; clock-frequency = <1843200>; + + bt_hci_uart: bt_hci_uart { + compatible = "zephyr,bt-hci-uart"; + status = "okay"; + }; }; &ite_uart1_wrapper { status = "okay"; diff --git a/boards/kincony/kincony_kc868_a32/Kconfig.defconfig b/boards/kincony/kincony_kc868_a32/Kconfig.defconfig index e8705a11f9850..4d4613b36ad53 100644 --- a/boards/kincony/kincony_kc868_a32/Kconfig.defconfig +++ b/boards/kincony/kincony_kc868_a32/Kconfig.defconfig @@ -10,10 +10,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD default 40960 if BT default 4096 -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice - endif # BOARD_KINCONY_KC868_A32_ESP32_PROCPU if BOARD_KINCONY_KC868_A32_ESP32_APPCPU diff --git a/boards/kincony/kincony_kc868_a32/kincony_kc868_a32_procpu.dts b/boards/kincony/kincony_kc868_a32/kincony_kc868_a32_procpu.dts index 5b60336d1bb2e..be7da2765efaf 100644 --- a/boards/kincony/kincony_kc868_a32/kincony_kc868_a32_procpu.dts +++ b/boards/kincony/kincony_kc868_a32/kincony_kc868_a32_procpu.dts @@ -23,6 +23,7 @@ zephyr,shell-uart = &uart0; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &esp32_bt_hci; }; }; @@ -203,3 +204,7 @@ }; }; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/luatos/esp32c3_luatos_core/Kconfig.defconfig b/boards/luatos/esp32c3_luatos_core/Kconfig.defconfig index 054ac2567296e..f6ad1adaa1cb9 100644 --- a/boards/luatos/esp32c3_luatos_core/Kconfig.defconfig +++ b/boards/luatos/esp32c3_luatos_core/Kconfig.defconfig @@ -9,7 +9,3 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD default 51200 if WIFI default 40960 if BT default 4096 - -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice diff --git a/boards/luatos/esp32c3_luatos_core/esp32c3_luatos_core.dts b/boards/luatos/esp32c3_luatos_core/esp32c3_luatos_core.dts index 00a6983355781..cfdfd771d13ec 100644 --- a/boards/luatos/esp32c3_luatos_core/esp32c3_luatos_core.dts +++ b/boards/luatos/esp32c3_luatos_core/esp32c3_luatos_core.dts @@ -15,5 +15,6 @@ zephyr,shell-uart = &uart0; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &esp32_bt_hci; }; }; diff --git a/boards/luatos/esp32c3_luatos_core/esp32c3_luatos_core.dtsi b/boards/luatos/esp32c3_luatos_core/esp32c3_luatos_core.dtsi index 904668716f6ef..c7b5b62754759 100644 --- a/boards/luatos/esp32c3_luatos_core/esp32c3_luatos_core.dtsi +++ b/boards/luatos/esp32c3_luatos_core/esp32c3_luatos_core.dtsi @@ -130,3 +130,7 @@ }; }; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/luatos/esp32s3_luatos_core/Kconfig.defconfig b/boards/luatos/esp32s3_luatos_core/Kconfig.defconfig index 093805f235b01..a14482e325d1c 100644 --- a/boards/luatos/esp32s3_luatos_core/Kconfig.defconfig +++ b/boards/luatos/esp32s3_luatos_core/Kconfig.defconfig @@ -12,10 +12,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD default 40960 if BT default 4096 -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice - endif # BOARD_ESP32S3_LUATOS_CORE_ESP32S3_PROCPU || BOARD_ESP32S3_LUATOS_CORE_ESP32S3_PROCPU_USB if BOARD_ESP32S3_LUATOS_CORE_ESP32S3_APPCPU || BOARD_ESP32S3_LUATOS_CORE_ESP32S3_APPCPU_USB diff --git a/boards/luatos/esp32s3_luatos_core/esp32s3_luatos_core.dtsi b/boards/luatos/esp32s3_luatos_core/esp32s3_luatos_core.dtsi index 883280c7b3172..60365fdcd65a3 100644 --- a/boards/luatos/esp32s3_luatos_core/esp32s3_luatos_core.dtsi +++ b/boards/luatos/esp32s3_luatos_core/esp32s3_luatos_core.dtsi @@ -141,3 +141,7 @@ }; }; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/luatos/esp32s3_luatos_core/esp32s3_luatos_core_procpu.dts b/boards/luatos/esp32s3_luatos_core/esp32s3_luatos_core_procpu.dts index 8c44d0cebd794..2a04d5680668a 100644 --- a/boards/luatos/esp32s3_luatos_core/esp32s3_luatos_core_procpu.dts +++ b/boards/luatos/esp32s3_luatos_core/esp32s3_luatos_core_procpu.dts @@ -26,5 +26,6 @@ zephyr,shell-uart = &uart0; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &esp32_bt_hci; }; }; diff --git a/boards/luatos/esp32s3_luatos_core/esp32s3_luatos_core_procpu_usb.dts b/boards/luatos/esp32s3_luatos_core/esp32s3_luatos_core_procpu_usb.dts index 0a707724f9f0a..a4182a4ba80ae 100644 --- a/boards/luatos/esp32s3_luatos_core/esp32s3_luatos_core_procpu_usb.dts +++ b/boards/luatos/esp32s3_luatos_core/esp32s3_luatos_core_procpu_usb.dts @@ -25,6 +25,7 @@ zephyr,console = &usb_serial; zephyr,shell-uart = &usb_serial; zephyr,flash = &flash0; + zephyr,bt_hci = &esp32_bt_hci; }; }; diff --git a/boards/m5stack/m5stack_atom_lite/Kconfig.defconfig b/boards/m5stack/m5stack_atom_lite/Kconfig.defconfig index d56d34b22d783..2b223f5409bed 100644 --- a/boards/m5stack/m5stack_atom_lite/Kconfig.defconfig +++ b/boards/m5stack/m5stack_atom_lite/Kconfig.defconfig @@ -12,10 +12,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD default 40960 if BT default 4096 -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice - endif # BOARD_M5STACK_ATOM_LITE_ESP32_PROCPU if BOARD_M5STACK_ATOM_LITE_ESP32_APPCPU diff --git a/boards/m5stack/m5stack_atom_lite/m5stack_atom_lite_procpu.dts b/boards/m5stack/m5stack_atom_lite/m5stack_atom_lite_procpu.dts index e4fae9d25434d..3a8557f679436 100644 --- a/boards/m5stack/m5stack_atom_lite/m5stack_atom_lite_procpu.dts +++ b/boards/m5stack/m5stack_atom_lite/m5stack_atom_lite_procpu.dts @@ -24,6 +24,7 @@ zephyr,shell-uart = &uart0; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &esp32_bt_hci; }; aliases { @@ -180,3 +181,7 @@ }; }; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/m5stack/m5stack_atoms3/Kconfig.defconfig b/boards/m5stack/m5stack_atoms3/Kconfig.defconfig index c0dadaceeb4d1..f3b59178417ce 100644 --- a/boards/m5stack/m5stack_atoms3/Kconfig.defconfig +++ b/boards/m5stack/m5stack_atoms3/Kconfig.defconfig @@ -14,10 +14,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD default 40960 if BT default 4096 -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice - endif # BOARD_M5STACK_ATOMS3_ESP32S3_PROCPU if BOARD_M5STACK_ATOMS3_ESP32S3_APPCPU diff --git a/boards/m5stack/m5stack_atoms3/m5stack_atoms3_procpu.dts b/boards/m5stack/m5stack_atoms3/m5stack_atoms3_procpu.dts index aa80e0b835673..ad433760fcab7 100644 --- a/boards/m5stack/m5stack_atoms3/m5stack_atoms3_procpu.dts +++ b/boards/m5stack/m5stack_atoms3/m5stack_atoms3_procpu.dts @@ -21,6 +21,7 @@ zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; zephyr,display = &st7789v; + zephyr,bt-hci = &esp32_bt_hci; }; aliases { @@ -177,3 +178,7 @@ }; }; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/m5stack/m5stack_atoms3_lite/Kconfig.defconfig b/boards/m5stack/m5stack_atoms3_lite/Kconfig.defconfig index 8039b4762cde2..f0f262cd1f3a6 100644 --- a/boards/m5stack/m5stack_atoms3_lite/Kconfig.defconfig +++ b/boards/m5stack/m5stack_atoms3_lite/Kconfig.defconfig @@ -14,10 +14,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD config KERNEL_MEM_POOL default y -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice - endif # BOARD_M5STACK_ATOMS3_LITE_ESP32S3_PROCPU if BOARD_M5STACK_ATOMS3_LITE_ESP32S3_APPCPU diff --git a/boards/m5stack/m5stack_atoms3_lite/m5stack_atoms3_lite_procpu.dts b/boards/m5stack/m5stack_atoms3_lite/m5stack_atoms3_lite_procpu.dts index 9f2cc84555858..166ee2014ca01 100644 --- a/boards/m5stack/m5stack_atoms3_lite/m5stack_atoms3_lite_procpu.dts +++ b/boards/m5stack/m5stack_atoms3_lite/m5stack_atoms3_lite_procpu.dts @@ -22,6 +22,7 @@ zephyr,shell-uart = &usb_serial; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &esp32_bt_hci; }; aliases { @@ -145,3 +146,7 @@ }; }; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/m5stack/m5stack_core2/Kconfig.defconfig b/boards/m5stack/m5stack_core2/Kconfig.defconfig index 2c0a21ef88da2..fd9614d6cbbfb 100644 --- a/boards/m5stack/m5stack_core2/Kconfig.defconfig +++ b/boards/m5stack/m5stack_core2/Kconfig.defconfig @@ -15,10 +15,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD config KERNEL_MEM_POOL default y -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice - config GPIO_HOGS_INIT_PRIORITY default 70 diff --git a/boards/m5stack/m5stack_core2/m5stack_core2_procpu.dts b/boards/m5stack/m5stack_core2/m5stack_core2_procpu.dts index fec843884ca83..841dcdf38bef1 100644 --- a/boards/m5stack/m5stack_core2/m5stack_core2_procpu.dts +++ b/boards/m5stack/m5stack_core2/m5stack_core2_procpu.dts @@ -34,6 +34,7 @@ zephyr,display = &ili9342c; zephyr,code-partition = &slot0_partition; zephyr,rtc = &pfc8563_rtc; + zephyr,bt-hci = &esp32_bt_hci; }; leds { @@ -283,3 +284,7 @@ }; }; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/m5stack/m5stack_stamps3/Kconfig.defconfig b/boards/m5stack/m5stack_stamps3/Kconfig.defconfig index 70493b8d4751d..903059dffbc8a 100644 --- a/boards/m5stack/m5stack_stamps3/Kconfig.defconfig +++ b/boards/m5stack/m5stack_stamps3/Kconfig.defconfig @@ -14,10 +14,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD config KERNEL_MEM_POOL default y -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice - endif # BOARD_M5STACK_STAMPS3_ESP32S3_PROCPU if BOARD_M5STACK_STAMPS3_ESP32S3_APPCPU diff --git a/boards/m5stack/m5stack_stamps3/m5stack_stamps3_procpu.dts b/boards/m5stack/m5stack_stamps3/m5stack_stamps3_procpu.dts index 522518f7e077c..9e231fba57f0d 100644 --- a/boards/m5stack/m5stack_stamps3/m5stack_stamps3_procpu.dts +++ b/boards/m5stack/m5stack_stamps3/m5stack_stamps3_procpu.dts @@ -23,6 +23,7 @@ zephyr,shell-uart = &usb_serial; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &esp32_bt_hci; }; aliases { @@ -185,3 +186,7 @@ }; }; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/m5stack/m5stickc_plus/Kconfig.defconfig b/boards/m5stack/m5stickc_plus/Kconfig.defconfig index aea1b614a01ac..a6b957227be56 100644 --- a/boards/m5stack/m5stickc_plus/Kconfig.defconfig +++ b/boards/m5stack/m5stickc_plus/Kconfig.defconfig @@ -12,10 +12,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD default 40960 if BT default 4096 -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice - config GPIO_HOGS_INIT_PRIORITY default 70 diff --git a/boards/m5stack/m5stickc_plus/m5stickc_plus_procpu.dts b/boards/m5stack/m5stickc_plus/m5stickc_plus_procpu.dts index b397c7d5b05fd..0c34c90e056e8 100644 --- a/boards/m5stack/m5stickc_plus/m5stickc_plus_procpu.dts +++ b/boards/m5stack/m5stickc_plus/m5stickc_plus_procpu.dts @@ -33,6 +33,7 @@ zephyr,code-partition = &slot0_partition; zephyr,rtc = &bm8563; zephyr,display = &st7789v; + zephyr,bt-hci = &esp32_bt_hci; }; leds { @@ -240,3 +241,7 @@ }; }; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/m5stack/stamp_c3/Kconfig.defconfig b/boards/m5stack/stamp_c3/Kconfig.defconfig index 4ce7fe02e1200..dcc3a4225487d 100644 --- a/boards/m5stack/stamp_c3/Kconfig.defconfig +++ b/boards/m5stack/stamp_c3/Kconfig.defconfig @@ -9,11 +9,3 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD default 51200 if WIFI default 40960 if BT default 4096 - -if BT - -choice BT_HCI_BUS_TYPE - default BT_ESP32 -endchoice - -endif # BT diff --git a/boards/m5stack/stamp_c3/stamp_c3.dts b/boards/m5stack/stamp_c3/stamp_c3.dts index e9d519a2a5f8f..ef026e9445441 100644 --- a/boards/m5stack/stamp_c3/stamp_c3.dts +++ b/boards/m5stack/stamp_c3/stamp_c3.dts @@ -20,6 +20,7 @@ zephyr,shell-uart = &uart0; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &esp32_bt_hci; }; aliases { @@ -129,3 +130,7 @@ }; }; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/native/native_posix/Kconfig.defconfig b/boards/native/native_posix/Kconfig.defconfig index 6db6f0aee1b5a..70d597b4192e0 100644 --- a/boards/native/native_posix/Kconfig.defconfig +++ b/boards/native/native_posix/Kconfig.defconfig @@ -22,11 +22,6 @@ config ETH_NATIVE_POSIX endif # NETWORKING -choice BT_HCI_BUS_TYPE - default BT_USERCHAN - depends on BT_HCI -endchoice - if CONSOLE config POSIX_ARCH_CONSOLE diff --git a/boards/native/native_sim/Kconfig.defconfig b/boards/native/native_sim/Kconfig.defconfig index 02d6b1d646599..0cb80bbcf4524 100644 --- a/boards/native/native_sim/Kconfig.defconfig +++ b/boards/native/native_sim/Kconfig.defconfig @@ -22,11 +22,6 @@ config ETH_NATIVE_POSIX endif # NETWORKING -choice BT_HCI_BUS_TYPE - default BT_USERCHAN - depends on BT_HCI -endchoice - if CONSOLE config POSIX_ARCH_CONSOLE diff --git a/boards/native/native_sim/native_sim.dts b/boards/native/native_sim/native_sim.dts index 87d6297f7491d..95b5ee5c06522 100644 --- a/boards/native/native_sim/native_sim.dts +++ b/boards/native/native_sim/native_sim.dts @@ -24,6 +24,7 @@ zephyr,display = &sdl_dc; zephyr,canbus = &can_loopback0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &bt_hci_userchan; }; aliases { @@ -218,4 +219,9 @@ #dma-cells = <1>; stack-size = <4096>; }; + + bt_hci_userchan: bt_hci_userchan { + compatible = "zephyr,bt-hci-userchan"; + status = "okay"; + }; }; diff --git a/boards/native/nrf_bsim/Kconfig.defconfig b/boards/native/nrf_bsim/Kconfig.defconfig index c3c786e45db24..2ff17802977fd 100644 --- a/boards/native/nrf_bsim/Kconfig.defconfig +++ b/boards/native/nrf_bsim/Kconfig.defconfig @@ -60,9 +60,8 @@ if BOARD_NRF5340BSIM_NRF5340_CPUAPP config IPC_SERVICE_BACKEND_RPMSG_SHMEM_RESET default y if IPC_SERVICE_BACKEND_RPMSG -choice BT_HCI_BUS_TYPE - default BT_HCI_IPC -endchoice +config BT_HCI_IPC + default y if BT endif # BOARD_NRF5340BSIM_NRF5340_CPUAPP diff --git a/boards/native/nrf_bsim/nrf52_bsim.dts b/boards/native/nrf_bsim/nrf52_bsim.dts index bb6321c4d5310..ad3ac181ae7d6 100644 --- a/boards/native/nrf_bsim/nrf52_bsim.dts +++ b/boards/native/nrf_bsim/nrf52_bsim.dts @@ -38,8 +38,6 @@ zephyr,flash = &flash0; /* UART used by the BT controller UART HCI driver by default: */ zephyr,bt-c2h-uart = &uart1; - /* UART used by the BT host UART HCI driver by default: */ - zephyr,bt-uart = &uart1; }; soc { @@ -117,4 +115,9 @@ pinctrl-1 = <&uart1_sleep>; pinctrl-names = "default", "sleep"; hw-flow-control; + + bt_hci_uart: bt_hci_uart { + compatible = "zephyr,bt-hci-uart"; + status = "okay"; + }; }; diff --git a/boards/native/nrf_bsim/nrf5340bsim_nrf5340_cpuapp.dts b/boards/native/nrf_bsim/nrf5340bsim_nrf5340_cpuapp.dts index aa1f235e16e58..11073e6182de3 100644 --- a/boards/native/nrf_bsim/nrf5340bsim_nrf5340_cpuapp.dts +++ b/boards/native/nrf_bsim/nrf5340bsim_nrf5340_cpuapp.dts @@ -43,7 +43,7 @@ chosen { zephyr,entropy = &rng_hci; zephyr,flash = &flash0; - zephyr,bt-hci-ipc = &ipc0; + zephyr,bt-hci = &bt_hci_ipc0; nordic,802154-spinel-ipc = &ipc0; zephyr,ieee802154 = &ieee802154; }; diff --git a/boards/nordic/nrf5340_audio_dk/Kconfig.defconfig b/boards/nordic/nrf5340_audio_dk/Kconfig.defconfig index c8d07e2adfab8..62316a2aeb096 100644 --- a/boards/nordic/nrf5340_audio_dk/Kconfig.defconfig +++ b/boards/nordic/nrf5340_audio_dk/Kconfig.defconfig @@ -53,9 +53,8 @@ config FLASH_LOAD_SIZE endif # BOARD_NRF5340_AUDIO_DK_NRF5340_CPUAPP_NS -choice BT_HCI_BUS_TYPE - default BT_HCI_IPC if BT -endchoice +config BT_HCI_IPC + default y if BT config HEAP_MEM_POOL_ADD_SIZE_BOARD int diff --git a/boards/nordic/nrf5340_audio_dk/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi b/boards/nordic/nrf5340_audio_dk/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi index 8504e23ed7e50..7f62b86263945 100644 --- a/boards/nordic/nrf5340_audio_dk/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi +++ b/boards/nordic/nrf5340_audio_dk/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi @@ -13,7 +13,7 @@ zephyr,uart-mcumgr = &uart0; zephyr,bt-mon-uart = &uart0; zephyr,bt-c2h-uart = &uart0; - zephyr,bt-hci-ipc = &ipc0; + zephyr,bt-hci = &bt_hci_ipc0; watchdog0 = &wdt0; }; diff --git a/boards/nordic/nrf5340dk/Kconfig.defconfig b/boards/nordic/nrf5340dk/Kconfig.defconfig index 67d7c7db9d553..972d8433c9016 100644 --- a/boards/nordic/nrf5340dk/Kconfig.defconfig +++ b/boards/nordic/nrf5340dk/Kconfig.defconfig @@ -60,9 +60,8 @@ config MBOX_NRFX_IPC if BOARD_NRF5340DK_NRF5340_CPUAPP || BOARD_NRF5340DK_NRF5340_CPUAPP_NS -choice BT_HCI_BUS_TYPE - default BT_HCI_IPC if BT -endchoice +config BT_HCI_IPC + default y if BT config HEAP_MEM_POOL_ADD_SIZE_BOARD int diff --git a/boards/nordic/nrf5340dk/nrf5340_cpuapp_common.dtsi b/boards/nordic/nrf5340dk/nrf5340_cpuapp_common.dtsi index b32519dd02b13..df46b7c64277c 100644 --- a/boards/nordic/nrf5340dk/nrf5340_cpuapp_common.dtsi +++ b/boards/nordic/nrf5340dk/nrf5340_cpuapp_common.dtsi @@ -14,7 +14,7 @@ zephyr,uart-mcumgr = &uart0; zephyr,bt-mon-uart = &uart0; zephyr,bt-c2h-uart = &uart0; - zephyr,bt-hci-ipc = &ipc0; + zephyr,bt-hci = &bt_hci_ipc0; nordic,802154-spinel-ipc = &ipc0; zephyr,ieee802154 = &ieee802154; }; diff --git a/boards/nordic/nrf54h20dk/Kconfig.defconfig b/boards/nordic/nrf54h20dk/Kconfig.defconfig index 74fe93905ac33..e37975f96adf4 100644 --- a/boards/nordic/nrf54h20dk/Kconfig.defconfig +++ b/boards/nordic/nrf54h20dk/Kconfig.defconfig @@ -3,9 +3,8 @@ if BOARD_NRF54H20DK_NRF54H20_CPUAPP -choice BT_HCI_BUS_TYPE - default BT_HCI_IPC if BT -endchoice +config BT_HCI_IPC + default y if BT endif # BOARD_NRF54H20DK_NRF54H20_CPUAPP diff --git a/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuapp.dts b/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuapp.dts index 1d9e5dd4a545e..4e6a9f0d57de4 100644 --- a/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuapp.dts +++ b/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuapp.dts @@ -25,7 +25,7 @@ zephyr,sram = &cpuapp_data; zephyr,shell-uart = &uart136; zephyr,ieee802154 = &cpuapp_ieee802154; - zephyr,bt-hci-ipc = &ipc0; + zephyr,bt-hci = &bt_hci_ipc0; nordic,802154-spinel-ipc = &ipc0; zephyr,canbus = &can120; }; @@ -155,6 +155,11 @@ ipc0: &cpuapp_cpurad_ipc { rx-region = <&cpurad_cpuapp_ipc_shm>; tx-blocks = <32>; rx-blocks = <32>; + + bt_hci_ipc0: bt_hci_ipc0 { + compatible = "zephyr,bt-hci-ipc"; + status = "okay"; + }; }; &cpuapp_cpusys_ipc { diff --git a/boards/nordic/thingy53/Kconfig.defconfig b/boards/nordic/thingy53/Kconfig.defconfig index 701bd9be4e6fa..92eac11503dbe 100644 --- a/boards/nordic/thingy53/Kconfig.defconfig +++ b/boards/nordic/thingy53/Kconfig.defconfig @@ -55,9 +55,8 @@ endif # BOARD_THINGY53_NRF5340_CPUAPP_NS if !TRUSTED_EXECUTION_SECURE -choice BT_HCI_BUS_TYPE - default BT_HCI_IPC if BT -endchoice +config BT_HCI_IPC + default y if BT config HEAP_MEM_POOL_ADD_SIZE_BOARD int diff --git a/boards/nordic/thingy53/thingy53_nrf5340_common.dtsi b/boards/nordic/thingy53/thingy53_nrf5340_common.dtsi index 017fa9e8a2674..782174d48b015 100644 --- a/boards/nordic/thingy53/thingy53_nrf5340_common.dtsi +++ b/boards/nordic/thingy53/thingy53_nrf5340_common.dtsi @@ -14,6 +14,7 @@ zephyr,bt-mon-uart = &cdc_acm_uart; zephyr,bt-c2h-uart = &cdc_acm_uart; zephyr,bt-hci-ipc = &ipc0; + zephyr,bt-hci = &bt_hci_ipc0; nordic,802154-spinel-ipc = &ipc0; zephyr,ieee802154 = &ieee802154; }; diff --git a/boards/nxp/hexiwear/hexiwear_mk64f12.dts b/boards/nxp/hexiwear/hexiwear_mk64f12.dts index 91961b19ad026..18cc0a3704526 100644 --- a/boards/nxp/hexiwear/hexiwear_mk64f12.dts +++ b/boards/nxp/hexiwear/hexiwear_mk64f12.dts @@ -28,7 +28,7 @@ zephyr,code-partition = &slot0_partition; zephyr,console = &uart0; zephyr,shell-uart = &uart0; - zephyr,bt-uart = &uart4; + zephyr,bt-hci = &bt_hci_uart; }; leds { @@ -153,6 +153,11 @@ current-speed = <115200>; pinctrl-0 = <&uart4_default>; pinctrl-names = "default"; + + bt_hci_uart: bt_hci_uart { + compatible = "zephyr,bt-hci-uart"; + status = "okay"; + }; }; &gpioa { diff --git a/boards/olimex/olimex_esp32_evb/Kconfig.defconfig b/boards/olimex/olimex_esp32_evb/Kconfig.defconfig index c15264f5538df..e326963903832 100644 --- a/boards/olimex/olimex_esp32_evb/Kconfig.defconfig +++ b/boards/olimex/olimex_esp32_evb/Kconfig.defconfig @@ -12,10 +12,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD default 40960 if BT default 4096 -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice - endif # BOARD_OLIMEX_ESP32_EVB_ESP32_PROCPU if BOARD_OLIMEX_ESP32_EVB_ESP32_APPCPU diff --git a/boards/olimex/olimex_esp32_evb/olimex_esp32_evb_procpu.dts b/boards/olimex/olimex_esp32_evb/olimex_esp32_evb_procpu.dts index e092f9766b594..c239263ea537b 100644 --- a/boards/olimex/olimex_esp32_evb/olimex_esp32_evb_procpu.dts +++ b/boards/olimex/olimex_esp32_evb/olimex_esp32_evb_procpu.dts @@ -20,6 +20,7 @@ zephyr,sram = &sram0; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &esp32_bt_hci; }; aliases { @@ -164,3 +165,7 @@ uext_spi: &spi2 {}; }; }; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/openisa/rv32m1_vega/rv32m1_vega_openisa_rv32m1_ri5cy.dts b/boards/openisa/rv32m1_vega/rv32m1_vega_openisa_rv32m1_ri5cy.dts index c985318455360..ceba94b4794ae 100644 --- a/boards/openisa/rv32m1_vega/rv32m1_vega_openisa_rv32m1_ri5cy.dts +++ b/boards/openisa/rv32m1_vega/rv32m1_vega_openisa_rv32m1_ri5cy.dts @@ -19,9 +19,14 @@ zephyr,shell-uart = &lpuart0; zephyr,uart-pipe = &lpuart0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &bt_hci_controller; }; }; +&bt_hci_controller { + status = "okay"; +}; + &m4_flash { /* * For more information, see: diff --git a/boards/others/icev_wireless/Kconfig.defconfig b/boards/others/icev_wireless/Kconfig.defconfig index 96ed16249d4ae..b7c82093375ff 100644 --- a/boards/others/icev_wireless/Kconfig.defconfig +++ b/boards/others/icev_wireless/Kconfig.defconfig @@ -7,7 +7,3 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD default 51200 if WIFI default 40960 if BT default 4096 - -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice diff --git a/boards/others/icev_wireless/icev_wireless.dts b/boards/others/icev_wireless/icev_wireless.dts index 6015780833554..6209aeac7c21e 100644 --- a/boards/others/icev_wireless/icev_wireless.dts +++ b/boards/others/icev_wireless/icev_wireless.dts @@ -20,6 +20,7 @@ zephyr,shell-uart = &usb_serial; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &esp32_bt_hci; }; aliases { @@ -126,3 +127,7 @@ }; }; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/panasonic/pan1783/Kconfig.defconfig b/boards/panasonic/pan1783/Kconfig.defconfig index ec08e860bbde5..6c70d441e9150 100644 --- a/boards/panasonic/pan1783/Kconfig.defconfig +++ b/boards/panasonic/pan1783/Kconfig.defconfig @@ -8,9 +8,8 @@ config MBOX_NRFX_IPC if SOC_NRF5340_CPUAPP_QKAA -choice BT_HCI_BUS_TYPE - default BT_HCI_IPC if BT -endchoice +config BT_HCI_IPC + default y if BT config HEAP_MEM_POOL_ADD_SIZE_BOARD int diff --git a/boards/panasonic/pan1783/pan1783_nrf5340_cpuapp_common.dtsi b/boards/panasonic/pan1783/pan1783_nrf5340_cpuapp_common.dtsi index 8fd97ed8ce26e..c1d4c5739e256 100644 --- a/boards/panasonic/pan1783/pan1783_nrf5340_cpuapp_common.dtsi +++ b/boards/panasonic/pan1783/pan1783_nrf5340_cpuapp_common.dtsi @@ -14,7 +14,7 @@ zephyr,uart-mcumgr = &uart0; zephyr,bt-mon-uart = &uart0; zephyr,bt-c2h-uart = &uart0; - zephyr,bt-hci-ipc = &ipc0; + zephyr,bt-hci = &bt_hci_ipc0; nordic,802154-spinel-ipc = &ipc0; zephyr,ieee802154 = &ieee802154; }; diff --git a/boards/qemu/cortex_m3/qemu_cortex_m3.dts b/boards/qemu/cortex_m3/qemu_cortex_m3.dts index 2e0bd95755f27..b035736a9f7b7 100644 --- a/boards/qemu/cortex_m3/qemu_cortex_m3.dts +++ b/boards/qemu/cortex_m3/qemu_cortex_m3.dts @@ -20,7 +20,7 @@ zephyr,flash = &flash0; zephyr,console = &uart0; zephyr,shell-uart = &uart0; - zephyr,bt-uart = &uart2; + zephyr,bt-hci = &bt_hci_uart; zephyr,uart-pipe = &uart1; zephyr,bt-mon-uart = &uart2; }; @@ -39,6 +39,11 @@ &uart2 { status = "okay"; current-speed = <115200>; + + bt_hci_uart: bt_hci_uart { + compatible = "zephyr,bt-hci-uart"; + status = "okay"; + }; }; ð { diff --git a/boards/qemu/x86/qemu_x86.dts b/boards/qemu/x86/qemu_x86.dts index 023c551eb47ac..907e8a1ec1cb7 100644 --- a/boards/qemu/x86/qemu_x86.dts +++ b/boards/qemu/x86/qemu_x86.dts @@ -37,8 +37,8 @@ zephyr,sram = &dram0; zephyr,flash = &flash0; zephyr,console = &uart0; + zephyr,bt-hci = &bt_hci_uart; zephyr,shell-uart = &uart0; - zephyr,bt-uart = &uart1; zephyr,uart-pipe = &uart1; zephyr,bt-mon-uart = &uart1; zephyr,code-partition = &slot0_partition; @@ -125,6 +125,11 @@ &uart1 { status = "okay"; current-speed = <115200>; + + bt_hci_uart: bt_hci_uart { + compatible = "zephyr,bt-hci-uart"; + status = "okay"; + }; }; &hpet { diff --git a/boards/raytac/mdbt53_db_40/Kconfig.defconfig b/boards/raytac/mdbt53_db_40/Kconfig.defconfig index 7bb0e9da9484c..bb53d3ae8f477 100644 --- a/boards/raytac/mdbt53_db_40/Kconfig.defconfig +++ b/boards/raytac/mdbt53_db_40/Kconfig.defconfig @@ -53,9 +53,8 @@ config FLASH_LOAD_SIZE endif # BOARD_RAYTAC_MDBT53_DB_40_NRF5340_CPUAPP_NS -choice BT_HCI_BUS_TYPE - default BT_HCI_IPC if BT -endchoice +config BT_HCI_IPC + default y if BT config HEAP_MEM_POOL_ADD_SIZE_BOARD int diff --git a/boards/raytac/mdbt53_db_40/raytac_mdbt53_db_40_nrf5340_cpuapp_common.dts b/boards/raytac/mdbt53_db_40/raytac_mdbt53_db_40_nrf5340_cpuapp_common.dts index 3af7de1f17edf..62a49e520698a 100644 --- a/boards/raytac/mdbt53_db_40/raytac_mdbt53_db_40_nrf5340_cpuapp_common.dts +++ b/boards/raytac/mdbt53_db_40/raytac_mdbt53_db_40_nrf5340_cpuapp_common.dts @@ -14,7 +14,7 @@ zephyr,uart-mcumgr = &uart0; zephyr,bt-mon-uart = &uart0; zephyr,bt-c2h-uart = &uart0; - zephyr,bt-hci-ipc = &ipc0; + zephyr,bt-hci = &bt_hci_ipc0; nordic,802154-spinel-ipc = &ipc0; zephyr,ieee802154 = &ieee802154; }; diff --git a/boards/raytac/mdbt53v_db_40/Kconfig.defconfig b/boards/raytac/mdbt53v_db_40/Kconfig.defconfig index 9cdb1683eed02..9573720773d15 100644 --- a/boards/raytac/mdbt53v_db_40/Kconfig.defconfig +++ b/boards/raytac/mdbt53v_db_40/Kconfig.defconfig @@ -53,9 +53,8 @@ config FLASH_LOAD_SIZE endif # BOARD_RAYTAC_MDBT53V_DB_40_NRF5340_CPUAPP_NS -choice BT_HCI_BUS_TYPE - default BT_HCI_IPC if BT -endchoice +config BT_HCI_IPC + default y if BT config HEAP_MEM_POOL_ADD_SIZE_BOARD int diff --git a/boards/raytac/mdbt53v_db_40/raytac_mdbt53v_db_40_nrf5340_cpuapp_common.dts b/boards/raytac/mdbt53v_db_40/raytac_mdbt53v_db_40_nrf5340_cpuapp_common.dts index c7d7521d08b05..3c1b42307a6ec 100644 --- a/boards/raytac/mdbt53v_db_40/raytac_mdbt53v_db_40_nrf5340_cpuapp_common.dts +++ b/boards/raytac/mdbt53v_db_40/raytac_mdbt53v_db_40_nrf5340_cpuapp_common.dts @@ -14,7 +14,7 @@ zephyr,uart-mcumgr = &uart0; zephyr,bt-mon-uart = &uart0; zephyr,bt-c2h-uart = &uart0; - zephyr,bt-hci-ipc = &ipc0; + zephyr,bt-hci = &bt_hci_ipc0; nordic,802154-spinel-ipc = &ipc0; zephyr,ieee802154 = &ieee802154; }; diff --git a/boards/renesas/da1469x_dk_pro/Kconfig.defconfig b/boards/renesas/da1469x_dk_pro/Kconfig.defconfig index d491f8c1ebd47..4ef15e108a440 100644 --- a/boards/renesas/da1469x_dk_pro/Kconfig.defconfig +++ b/boards/renesas/da1469x_dk_pro/Kconfig.defconfig @@ -64,10 +64,6 @@ endif # PM || PM_DEVICE if BT -choice BT_HCI_BUS_TYPE - default BT_DA1469X -endchoice - config BT_WAIT_NOP default y diff --git a/boards/renesas/da1469x_dk_pro/da1469x_dk_pro.dts b/boards/renesas/da1469x_dk_pro/da1469x_dk_pro.dts index f84a97b2020bf..f866df49a859a 100644 --- a/boards/renesas/da1469x_dk_pro/da1469x_dk_pro.dts +++ b/boards/renesas/da1469x_dk_pro/da1469x_dk_pro.dts @@ -19,6 +19,7 @@ zephyr,console = &uart; zephyr,shell-uart = &uart; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &bt_hci_da1469x; }; lvgl_pointer { @@ -178,3 +179,7 @@ zephyr_udc0: &usbd { pinctrl-1 = <&spi2_sleep>; pinctrl-names = "default", "sleep"; }; + +&bt_hci_da1469x { + status = "okay"; +}; diff --git a/boards/seeed/xiao_esp32c3/Kconfig.defconfig b/boards/seeed/xiao_esp32c3/Kconfig.defconfig index f70e724ed8e0c..4171bb04bc276 100644 --- a/boards/seeed/xiao_esp32c3/Kconfig.defconfig +++ b/boards/seeed/xiao_esp32c3/Kconfig.defconfig @@ -7,7 +7,3 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD default 51200 if WIFI default 40960 if BT default 4096 - -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice diff --git a/boards/seeed/xiao_esp32c3/xiao_esp32c3.dts b/boards/seeed/xiao_esp32c3/xiao_esp32c3.dts index 943cda08b7dbf..68687958b8a2a 100644 --- a/boards/seeed/xiao_esp32c3/xiao_esp32c3.dts +++ b/boards/seeed/xiao_esp32c3/xiao_esp32c3.dts @@ -21,6 +21,7 @@ zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; zephyr,canbus = &twai; + zephyr,bt-hci = &esp32_bt_hci; }; aliases { @@ -118,3 +119,7 @@ }; }; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/seeed/xiao_esp32s3/Kconfig.defconfig b/boards/seeed/xiao_esp32s3/Kconfig.defconfig index 424820d78adc9..b9222985d8dd0 100644 --- a/boards/seeed/xiao_esp32s3/Kconfig.defconfig +++ b/boards/seeed/xiao_esp32s3/Kconfig.defconfig @@ -10,10 +10,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD default 40960 if BT default 4096 -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice - endif # BOARD_XIAO_ESP32S3_ESP32S3_PROCPU if BOARD_XIAO_ESP32S3_ESP32S3_APPCPU diff --git a/boards/seeed/xiao_esp32s3/xiao_esp32s3_procpu.dts b/boards/seeed/xiao_esp32s3/xiao_esp32s3_procpu.dts index 17c2ca3eeec43..2c1349b735c4c 100644 --- a/boards/seeed/xiao_esp32s3/xiao_esp32s3_procpu.dts +++ b/boards/seeed/xiao_esp32s3/xiao_esp32s3_procpu.dts @@ -20,6 +20,7 @@ zephyr,shell-uart = &usb_serial; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &esp32_bt_hci; }; aliases { @@ -127,3 +128,7 @@ }; }; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/shields/frdm_kw41z/frdm_kw41z.overlay b/boards/shields/frdm_kw41z/frdm_kw41z.overlay index 3807b2f6a2dab..8e9f14fbfb433 100644 --- a/boards/shields/frdm_kw41z/frdm_kw41z.overlay +++ b/boards/shields/frdm_kw41z/frdm_kw41z.overlay @@ -6,11 +6,16 @@ / { chosen { - zephyr,bt-uart = &arduino_serial; + zephyr,bt-hci = &bt_hci_uart; }; }; &arduino_serial { status = "okay"; current-speed = <115200>; + + bt_hci_uart: bt_hci_uart { + compatible = "zephyr,bt-hci-uart"; + status = "okay"; + }; }; diff --git a/boards/shields/x_nucleo_bnrg2a1/Kconfig.defconfig b/boards/shields/x_nucleo_bnrg2a1/Kconfig.defconfig index 88f16f95dc56e..94ace9e384989 100644 --- a/boards/shields/x_nucleo_bnrg2a1/Kconfig.defconfig +++ b/boards/shields/x_nucleo_bnrg2a1/Kconfig.defconfig @@ -8,9 +8,8 @@ if BT config SPI default y -choice BT_HCI_BUS_TYPE - default BT_SPI -endchoice +config BT_SPI + default y config BT_BLUENRG_ACI default y diff --git a/boards/shields/x_nucleo_bnrg2a1/x_nucleo_bnrg2a1.overlay b/boards/shields/x_nucleo_bnrg2a1/x_nucleo_bnrg2a1.overlay index 177ac9eb9484d..535373ea307d7 100644 --- a/boards/shields/x_nucleo_bnrg2a1/x_nucleo_bnrg2a1.overlay +++ b/boards/shields/x_nucleo_bnrg2a1/x_nucleo_bnrg2a1.overlay @@ -4,10 +4,16 @@ * SPDX-License-Identifier: Apache-2.0 */ + / { + chosen { + zephyr,bt-hci = &hci_spi; + }; + }; + &arduino_spi { cs-gpios = <&arduino_header 1 GPIO_ACTIVE_LOW>; /* A1 */ - bluenrg-2@0 { + hci_spi: bluenrg-2@0 { compatible = "st,hci-spi-v2"; reg = <0>; reset-gpios = <&arduino_header 13 GPIO_ACTIVE_LOW>; /* D7 */ diff --git a/boards/shields/x_nucleo_idb05a1/Kconfig.defconfig b/boards/shields/x_nucleo_idb05a1/Kconfig.defconfig index a5fe2515b5034..276ee66467992 100644 --- a/boards/shields/x_nucleo_idb05a1/Kconfig.defconfig +++ b/boards/shields/x_nucleo_idb05a1/Kconfig.defconfig @@ -8,9 +8,8 @@ if BT config SPI default y -choice BT_HCI_BUS_TYPE - default BT_SPI -endchoice +config BT_SPI + default y config BT_BLUENRG_ACI default y diff --git a/boards/shields/x_nucleo_idb05a1/x_nucleo_idb05a1.overlay b/boards/shields/x_nucleo_idb05a1/x_nucleo_idb05a1.overlay index e6dff3c9c9f33..f508f0b26a0b4 100644 --- a/boards/shields/x_nucleo_idb05a1/x_nucleo_idb05a1.overlay +++ b/boards/shields/x_nucleo_idb05a1/x_nucleo_idb05a1.overlay @@ -4,6 +4,12 @@ * SPDX-License-Identifier: Apache-2.0 */ + / { + chosen { + zephyr,bt-hci = &spbtle_rf_x_nucleo_idb05a1; + }; + }; + &arduino_spi { cs-gpios = <&arduino_header 1 GPIO_ACTIVE_LOW>; /* A1 */ diff --git a/boards/silabs/efr32_radio/Kconfig.defconfig b/boards/silabs/efr32_radio/Kconfig.defconfig index ce20c2ef360b0..dd57f067b92ec 100644 --- a/boards/silabs/efr32_radio/Kconfig.defconfig +++ b/boards/silabs/efr32_radio/Kconfig.defconfig @@ -42,10 +42,6 @@ config MAIN_STACK_SIZE default 3072 if PM default 2304 -choice BT_HCI_BUS_TYPE - default BT_SILABS_HCI -endchoice - endif # BT endif # BOARD_EFR32_RADIO diff --git a/boards/silabs/efr32_radio/efr32_radio_efr32bg13p632f512gm48.dts b/boards/silabs/efr32_radio/efr32_radio_efr32bg13p632f512gm48.dts index 4dde0cfd1ce28..4f9b51a0a5548 100644 --- a/boards/silabs/efr32_radio/efr32_radio_efr32bg13p632f512gm48.dts +++ b/boards/silabs/efr32_radio/efr32_radio_efr32bg13p632f512gm48.dts @@ -11,6 +11,10 @@ / { model = "Silicon Labs BRD4104A (Blue Gecko Radio Board)"; compatible = "silabs,efr32_radio_brd4104a", "silabs,efr32bg13p"; + + chosen { + zephyr,bt-hci = &bt_hci_silabs; + }; }; &cpu0 { @@ -56,3 +60,7 @@ }; }; + +&bt_hci_silabs { + status = "okay"; +}; diff --git a/boards/silabs/efr32_radio/efr32_radio_efr32mg12p432f1024gl125.dts b/boards/silabs/efr32_radio/efr32_radio_efr32mg12p432f1024gl125.dts index f69a84cc414a6..442ba7cd8704d 100644 --- a/boards/silabs/efr32_radio/efr32_radio_efr32mg12p432f1024gl125.dts +++ b/boards/silabs/efr32_radio/efr32_radio_efr32mg12p432f1024gl125.dts @@ -11,6 +11,10 @@ / { model = "Silicon Labs BRD4161A (Mighty Gecko Radio Board)"; compatible = "silabs,efr32_radio_brd4161a", "silabs,efr32mg12p"; + + chosen { + zephyr,bt-hci = &bt_hci_silabs; + }; }; &cpu0 { @@ -89,3 +93,7 @@ status = "okay"; }; }; + +&bt_hci_silabs { + status = "okay"; +}; diff --git a/boards/silabs/efr32_radio/efr32_radio_efr32mg12p433f1024gm68.dts b/boards/silabs/efr32_radio/efr32_radio_efr32mg12p433f1024gm68.dts index 2aabcf7fafff6..6fb38626f3925 100644 --- a/boards/silabs/efr32_radio/efr32_radio_efr32mg12p433f1024gm68.dts +++ b/boards/silabs/efr32_radio/efr32_radio_efr32mg12p433f1024gm68.dts @@ -11,6 +11,10 @@ / { model = "Silicon Labs BRD4170A (Mighty Gecko Radio Board)"; compatible = "silabs,efr32_radio_brd4170a", "silabs,efr32mg12p"; + + chosen { + zephyr,bt-hci = &bt_hci_silabs; + }; }; &cpu0 { @@ -56,3 +60,7 @@ }; }; + +&bt_hci_silabs { + status = "okay"; +}; diff --git a/boards/silabs/efr32_thunderboard/Kconfig.defconfig b/boards/silabs/efr32_thunderboard/Kconfig.defconfig index 9c11626351895..9b45efccc9001 100644 --- a/boards/silabs/efr32_thunderboard/Kconfig.defconfig +++ b/boards/silabs/efr32_thunderboard/Kconfig.defconfig @@ -28,10 +28,6 @@ config MAIN_STACK_SIZE default 3072 if PM default 2304 -choice BT_HCI_BUS_TYPE - default BT_SILABS_HCI -endchoice - endif # BT config REGULATOR diff --git a/boards/silabs/efr32_thunderboard/efr32bg22_brd4184.dtsi b/boards/silabs/efr32_thunderboard/efr32bg22_brd4184.dtsi index 13576e3f295a8..14b81b4513b78 100644 --- a/boards/silabs/efr32_thunderboard/efr32bg22_brd4184.dtsi +++ b/boards/silabs/efr32_thunderboard/efr32bg22_brd4184.dtsi @@ -20,6 +20,7 @@ chosen { zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &bt_hci_silabs; }; }; @@ -55,3 +56,7 @@ &sw_imu_enable { enable-gpios = <&gpiob GECKO_PIN(4) GPIO_ACTIVE_HIGH>; }; + +&bt_hci_silabs { + status = "okay"; +}; diff --git a/boards/silabs/efr32xg24_dk2601b/Kconfig.defconfig b/boards/silabs/efr32xg24_dk2601b/Kconfig.defconfig index dbd2884e28ab7..a750af1541a86 100644 --- a/boards/silabs/efr32xg24_dk2601b/Kconfig.defconfig +++ b/boards/silabs/efr32xg24_dk2601b/Kconfig.defconfig @@ -33,10 +33,6 @@ config MINIMAL_LIBC_MALLOC_ARENA_SIZE config MAIN_STACK_SIZE default 2304 -choice BT_HCI_BUS_TYPE - default BT_SILABS_HCI -endchoice - if SHELL config SHELL_STACK_SIZE diff --git a/boards/silabs/efr32xg24_dk2601b/efr32xg24_dk2601b.dts b/boards/silabs/efr32xg24_dk2601b/efr32xg24_dk2601b.dts index dc0561a75dfa2..a8d0a1a2cfc5a 100644 --- a/boards/silabs/efr32xg24_dk2601b/efr32xg24_dk2601b.dts +++ b/boards/silabs/efr32xg24_dk2601b/efr32xg24_dk2601b.dts @@ -19,6 +19,7 @@ zephyr,sram = &sram0; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &bt_hci_silabs; }; aliases { @@ -177,3 +178,7 @@ &stimer0 { status = "okay"; }; + +&bt_hci_silabs { + status = "okay"; +}; diff --git a/boards/st/b_l4s5i_iot01a/Kconfig.defconfig b/boards/st/b_l4s5i_iot01a/Kconfig.defconfig index 0000fc670f3ce..317d096e0cea7 100644 --- a/boards/st/b_l4s5i_iot01a/Kconfig.defconfig +++ b/boards/st/b_l4s5i_iot01a/Kconfig.defconfig @@ -27,9 +27,8 @@ if BT config SPI default y -choice BT_HCI_BUS_TYPE - default BT_SPI -endchoice +config BT_SPI + default y config BT_BLUENRG_ACI default y diff --git a/boards/st/b_l4s5i_iot01a/b_l4s5i_iot01a.dts b/boards/st/b_l4s5i_iot01a/b_l4s5i_iot01a.dts index 7f2863f78f4be..d41c75c44bf0d 100644 --- a/boards/st/b_l4s5i_iot01a/b_l4s5i_iot01a.dts +++ b/boards/st/b_l4s5i_iot01a/b_l4s5i_iot01a.dts @@ -22,6 +22,7 @@ zephyr,code-partition = &slot0_partition; zephyr,flash-controller = &mx25r6435f; zephyr,bt-c2h-uart = &usart1; + zephyr,bt-hci = &hci_spi; }; leds { @@ -151,7 +152,7 @@ cs-gpios = <&gpiod 13 GPIO_ACTIVE_LOW>, <&gpioe 0 GPIO_ACTIVE_LOW>; - spbtle-rf@0 { + hci_spi: spbtle-rf@0 { compatible = "st,hci-spi-v1"; reg = <0>; reset-gpios = <&gpioa 8 GPIO_ACTIVE_LOW>; diff --git a/boards/st/b_u585i_iot02a/b_u585i_iot02a.dts b/boards/st/b_u585i_iot02a/b_u585i_iot02a.dts index c2df9e5aa5af0..b452f4b3eba39 100644 --- a/boards/st/b_u585i_iot02a/b_u585i_iot02a.dts +++ b/boards/st/b_u585i_iot02a/b_u585i_iot02a.dts @@ -19,7 +19,7 @@ zephyr,sram = &sram0; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; - zephyr,bt-uart=&uart4; + zephyr,bt-hci = &bt_hci_uart; }; aliases { @@ -81,4 +81,9 @@ pinctrl-names = "default"; current-speed = <100000>; status = "okay"; + + bt_hci_uart: bt_hci_uart { + compatible = "zephyr,bt-hci-uart"; + status = "okay"; + }; }; diff --git a/boards/st/disco_l475_iot1/Kconfig.defconfig b/boards/st/disco_l475_iot1/Kconfig.defconfig index b99f7c57511eb..808425eae0569 100644 --- a/boards/st/disco_l475_iot1/Kconfig.defconfig +++ b/boards/st/disco_l475_iot1/Kconfig.defconfig @@ -27,9 +27,8 @@ if BT config SPI default y -choice BT_HCI_BUS_TYPE - default BT_SPI -endchoice +config BT_SPI + default y config BT_BLUENRG_ACI default y diff --git a/boards/st/disco_l475_iot1/disco_l475_iot1.dts b/boards/st/disco_l475_iot1/disco_l475_iot1.dts index 26276225d2044..c57f9f01e91c0 100644 --- a/boards/st/disco_l475_iot1/disco_l475_iot1.dts +++ b/boards/st/disco_l475_iot1/disco_l475_iot1.dts @@ -22,6 +22,7 @@ zephyr,code-partition = &slot0_partition; zephyr,flash-controller = &mx25r6435f; zephyr,bt-c2h-uart = &usart1; + zephyr,bt-hci = &hci_spi; }; leds { @@ -190,7 +191,7 @@ cs-gpios = <&gpiod 13 GPIO_ACTIVE_LOW>, <&gpioe 0 GPIO_ACTIVE_LOW>; - spbtle-rf@0 { + hci_spi: spbtle-rf@0 { compatible = "st,hci-spi-v1"; reg = <0>; reset-gpios = <&gpioa 8 GPIO_ACTIVE_LOW>; diff --git a/boards/st/nucleo_wb55rg/Kconfig.defconfig b/boards/st/nucleo_wb55rg/Kconfig.defconfig index a482290173980..cd63e8d080e01 100644 --- a/boards/st/nucleo_wb55rg/Kconfig.defconfig +++ b/boards/st/nucleo_wb55rg/Kconfig.defconfig @@ -5,9 +5,8 @@ if BOARD_NUCLEO_WB55RG -choice BT_HCI_BUS_TYPE - default BT_STM32_IPM +config BT_STM32_IPM + default y depends on BT -endchoice endif diff --git a/boards/st/sensortile_box/Kconfig.defconfig b/boards/st/sensortile_box/Kconfig.defconfig index 8e3f0bb167041..faa5dc0864c4d 100644 --- a/boards/st/sensortile_box/Kconfig.defconfig +++ b/boards/st/sensortile_box/Kconfig.defconfig @@ -10,9 +10,8 @@ if BT config SPI default y -choice BT_HCI_BUS_TYPE - default BT_SPI -endchoice +config BT_SPI + default y config BT_BLUENRG_ACI default y diff --git a/boards/st/sensortile_box/sensortile_box.dts b/boards/st/sensortile_box/sensortile_box.dts index 102dbb6a73a73..70a0b4f900701 100644 --- a/boards/st/sensortile_box/sensortile_box.dts +++ b/boards/st/sensortile_box/sensortile_box.dts @@ -19,6 +19,7 @@ zephyr,sram = &sram0; zephyr,flash = &flash0; zephyr,bt-c2h-uart = &usart1; + zephyr,bt-hci = &spbtle_1s_sensortile_box; }; leds { diff --git a/boards/st/sensortile_box_pro/Kconfig.defconfig b/boards/st/sensortile_box_pro/Kconfig.defconfig index f0271728a9a3e..caa346b007540 100644 --- a/boards/st/sensortile_box_pro/Kconfig.defconfig +++ b/boards/st/sensortile_box_pro/Kconfig.defconfig @@ -10,9 +10,8 @@ if BT config SPI default y -choice BT_HCI_BUS_TYPE - default BT_SPI -endchoice +config BT_SPI + default y config BT_BLUENRG_ACI default y diff --git a/boards/st/sensortile_box_pro/sensortile_box_pro.dts b/boards/st/sensortile_box_pro/sensortile_box_pro.dts index 8bd870151a574..06185c32d40a3 100644 --- a/boards/st/sensortile_box_pro/sensortile_box_pro.dts +++ b/boards/st/sensortile_box_pro/sensortile_box_pro.dts @@ -29,6 +29,7 @@ zephyr,sram = &sram0; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &hci_spi; }; leds { @@ -163,7 +164,7 @@ stm32_lp_tick_source: &lptim1 { cs-gpios = <&gpioa 2 GPIO_ACTIVE_LOW>; status = "okay"; - bluenrg-lp@0 { + hci_spi: bluenrg-lp@0 { compatible = "st,hci-spi-v2"; reg = <0>; irq-gpios = <&gpiod 1 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>; diff --git a/boards/st/steval_stwinbx1/Kconfig.defconfig b/boards/st/steval_stwinbx1/Kconfig.defconfig index f10fea5e293b8..594ebede5a70f 100644 --- a/boards/st/steval_stwinbx1/Kconfig.defconfig +++ b/boards/st/steval_stwinbx1/Kconfig.defconfig @@ -10,9 +10,8 @@ if BT config SPI default y -choice BT_HCI_BUS_TYPE - default BT_SPI -endchoice +config BT_SPI + default y config BT_BLUENRG_ACI default y diff --git a/boards/st/steval_stwinbx1/steval_stwinbx1.dts b/boards/st/steval_stwinbx1/steval_stwinbx1.dts index 23eda67338aec..4debd8cc5c19c 100644 --- a/boards/st/steval_stwinbx1/steval_stwinbx1.dts +++ b/boards/st/steval_stwinbx1/steval_stwinbx1.dts @@ -32,6 +32,8 @@ zephyr,sram = &sram0; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; + + zephyr,bt-hci = &hci_spi; }; leds { @@ -164,7 +166,7 @@ stm32_lp_tick_source: &lptim1 { pinctrl-names = "default"; status = "okay"; cs-gpios = <&gpioe 1 GPIO_ACTIVE_LOW>; - bluenrg-2@0 { + hci_spi: bluenrg-2@0 { compatible = "st,hci-spi-v2"; reg = <0>; reset-gpios = <&gpiod 13 GPIO_ACTIVE_LOW>; diff --git a/boards/st/stm32l562e_dk/Kconfig.defconfig b/boards/st/stm32l562e_dk/Kconfig.defconfig index 5dea5bc3a7418..ed9a04edc17a4 100644 --- a/boards/st/stm32l562e_dk/Kconfig.defconfig +++ b/boards/st/stm32l562e_dk/Kconfig.defconfig @@ -10,9 +10,8 @@ if BT config SPI default y -choice BT_HCI_BUS_TYPE - default BT_SPI -endchoice +config BT_SPI + default y config BT_BLUENRG_ACI default y diff --git a/boards/st/stm32l562e_dk/stm32l562e_dk_common.dtsi b/boards/st/stm32l562e_dk/stm32l562e_dk_common.dtsi index cd798b72d03db..6922b6be83fa9 100644 --- a/boards/st/stm32l562e_dk/stm32l562e_dk_common.dtsi +++ b/boards/st/stm32l562e_dk/stm32l562e_dk_common.dtsi @@ -36,6 +36,10 @@ volt-sensor0 = &vref; volt-sensor1 = &vbat; }; + + chosen { + zephyr,bt-hci = &hci_spi; + }; }; &clk_hsi48 { @@ -113,7 +117,7 @@ stm32_lp_tick_source: &lptim1 { cs-gpios = <&gpiog 5 GPIO_ACTIVE_LOW>; status = "okay"; - spbtle-rf@0 { + hci_spi: spbtle-rf@0 { compatible = "st,hci-spi-v1"; reg = <0>; irq-gpios = <&gpiog 6 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>; diff --git a/boards/st/stm32wb5mm_dk/Kconfig.defconfig b/boards/st/stm32wb5mm_dk/Kconfig.defconfig index 37be19b4d1c65..b75d5bdb31d8f 100644 --- a/boards/st/stm32wb5mm_dk/Kconfig.defconfig +++ b/boards/st/stm32wb5mm_dk/Kconfig.defconfig @@ -5,9 +5,8 @@ if BOARD_STM32WB5MM_DK -choice BT_HCI_BUS_TYPE - default BT_STM32_IPM +config BT_STM32_IPM + default y depends on BT -endchoice endif diff --git a/boards/st/stm32wb5mmg/Kconfig.defconfig b/boards/st/stm32wb5mmg/Kconfig.defconfig index e63531f897bac..e07cc7210b21c 100644 --- a/boards/st/stm32wb5mmg/Kconfig.defconfig +++ b/boards/st/stm32wb5mmg/Kconfig.defconfig @@ -5,9 +5,8 @@ if BOARD_STM32WB5MMG -choice BT_HCI_BUS_TYPE - default BT_STM32_IPM +config BT_STM32_IPM + default y depends on BT -endchoice endif diff --git a/boards/up-bridge-the-gap/up_squared/up_squared.dts b/boards/up-bridge-the-gap/up_squared/up_squared.dts index beb83af8b1996..2e8e763115f60 100644 --- a/boards/up-bridge-the-gap/up_squared/up_squared.dts +++ b/boards/up-bridge-the-gap/up_squared/up_squared.dts @@ -25,7 +25,7 @@ zephyr,sram = &dram0; zephyr,console = &uart0; zephyr,shell-uart = &uart0; - zephyr,bt-uart = &uart1; + zephyr,bt-hci = &bt_hci_uart; zephyr,uart-pipe = &uart1; zephyr,bt-mon-uart = &uart1; }; @@ -49,3 +49,10 @@ }; }; }; + +&uart1 { + bt_hci_uart: bt_hci_uart { + compatible = "zephyr,bt-hci-uart"; + status = "okay"; + }; +}; diff --git a/boards/vcc-gnd/yd_esp32/Kconfig.defconfig b/boards/vcc-gnd/yd_esp32/Kconfig.defconfig index 9b7b408dbef2d..2ca1ba1903658 100644 --- a/boards/vcc-gnd/yd_esp32/Kconfig.defconfig +++ b/boards/vcc-gnd/yd_esp32/Kconfig.defconfig @@ -12,10 +12,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD default 40960 if BT default 4096 -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice - endif # BOARD_YD_ESP32_ESP32_PROCPU if BOARD_YD_ESP32_ESP32_APPCPU diff --git a/boards/vcc-gnd/yd_esp32/yd_esp32_procpu.dts b/boards/vcc-gnd/yd_esp32/yd_esp32_procpu.dts index 62b657c44d077..a409ed6e90962 100644 --- a/boards/vcc-gnd/yd_esp32/yd_esp32_procpu.dts +++ b/boards/vcc-gnd/yd_esp32/yd_esp32_procpu.dts @@ -35,6 +35,7 @@ zephyr,shell-uart = &uart0; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; + zephyr,bt-hci = &esp32_bt_hci; }; }; @@ -173,3 +174,7 @@ }; }; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/boards/waveshare/esp32s3_touch_lcd_1_28/Kconfig.defconfig b/boards/waveshare/esp32s3_touch_lcd_1_28/Kconfig.defconfig index 33296a8e529bb..06c61c850aa11 100644 --- a/boards/waveshare/esp32s3_touch_lcd_1_28/Kconfig.defconfig +++ b/boards/waveshare/esp32s3_touch_lcd_1_28/Kconfig.defconfig @@ -10,10 +10,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD default 40960 if BT default 4096 -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice - endif # BOARD_ESP32S3_TOUCH_LCD_1_28_ESP32S3_PROCPU if BOARD_ESP32S3_TOUCH_LCD_1_28_ESP32S3_APPCPU diff --git a/boards/waveshare/esp32s3_touch_lcd_1_28/esp32s3_touch_lcd_1_28_esp32s3_procpu.dts b/boards/waveshare/esp32s3_touch_lcd_1_28/esp32s3_touch_lcd_1_28_esp32s3_procpu.dts index c00b23ba14786..f6a62874fe50a 100644 --- a/boards/waveshare/esp32s3_touch_lcd_1_28/esp32s3_touch_lcd_1_28_esp32s3_procpu.dts +++ b/boards/waveshare/esp32s3_touch_lcd_1_28/esp32s3_touch_lcd_1_28_esp32s3_procpu.dts @@ -30,6 +30,7 @@ zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; zephyr,display = &gc9a01; + zephyr,bt-hci = &esp32_bt_hci; }; /* Buttons */ @@ -174,3 +175,7 @@ &wdt0 { status = "okay"; }; + +&esp32_bt_hci { + status = "okay"; +}; diff --git a/cmake/emu/qemu.cmake b/cmake/emu/qemu.cmake index 6103fc1cefc15..0fd445f3c5939 100644 --- a/cmake/emu/qemu.cmake +++ b/cmake/emu/qemu.cmake @@ -100,7 +100,7 @@ endif() # Add a BT serial device when building for bluetooth, unless the # application explicitly opts out with NO_QEMU_SERIAL_BT_SERVER. if(CONFIG_BT) - if(CONFIG_BT_NO_DRIVER) + if(NOT CONFIG_BT_UART) set(NO_QEMU_SERIAL_BT_SERVER 1) endif() if(NOT NO_QEMU_SERIAL_BT_SERVER) diff --git a/doc/build/dts/api/api.rst b/doc/build/dts/api/api.rst index 44b87653cc3fe..e76ad997fb519 100644 --- a/doc/build/dts/api/api.rst +++ b/doc/build/dts/api/api.rst @@ -386,8 +386,8 @@ device. :ref:`bluetooth-hci-uart-sample` * - zephyr,bt-mon-uart - Sets UART device used for the Bluetooth monitor logging - * - zephyr,bt-uart - - Sets UART device used by Bluetooth + * - zephyr,bt-hci + - Selects the HCI device used by the Bluetooth host stack * - zephyr,canbus - Sets the default CAN controller * - zephyr,ccm diff --git a/doc/releases/migration-guide-3.7.rst b/doc/releases/migration-guide-3.7.rst index 46d504d85893d..6a425a98ce465 100644 --- a/doc/releases/migration-guide-3.7.rst +++ b/doc/releases/migration-guide-3.7.rst @@ -236,6 +236,17 @@ Analog-to-Digital Converter (ADC) Bluetooth HCI ============= + * A new HCI driver API was introduced (:github:`72323`) and the old one deprecated. The new API + follows the normal Zephyr driver model, with devicetree nodes, etc. The host now + selects which driver instance to use as the controller by looking for a ``zephyr,bt-hci`` + chosen property. The devicetree bindings for all HCI drivers derive from a common + ``bt-hci.yaml`` base binding. + * As part of the new HCI driver API, the ``zephyr,bt-uart`` chosen property is no longer used, + rather the UART HCI drivers select their UART by looking for the parent devicetree node of the + HCI driver instance node. + * As part of the new HCI driver API, the ``zephyr,bt-hci-ipc`` chosen property is only used for + the controller side, whereas the HCI driver now relies on nodes with the compatible string + ``zephyr,bt-hci-ipc``. * The ``BT_HCI_VS_EXT`` Kconfig option was deleted and the feature is now included in the :kconfig:option:`BT_HCI_VS` Kconfig option. * The ``BT_HCI_VS_EVT`` Kconfig option was removed, since vendor event support is implicit if diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig index 46bf62bb1a7ff..a1680af6583d0 100644 --- a/drivers/bluetooth/Kconfig +++ b/drivers/bluetooth/Kconfig @@ -12,7 +12,7 @@ menuconfig BT_DRIVERS bool "Bluetooth drivers" default y - depends on BT && !BT_CTLR + depends on BT if BT_DRIVERS diff --git a/drivers/bluetooth/hci/Kconfig b/drivers/bluetooth/hci/Kconfig index 282eda93e9720..3c5572cda5296 100644 --- a/drivers/bluetooth/hci/Kconfig +++ b/drivers/bluetooth/hci/Kconfig @@ -10,13 +10,11 @@ config BT_UART select SERIAL select UART_INTERRUPT_DRIVEN - -choice BT_HCI_BUS_TYPE - prompt "Bluetooth HCI driver" - config BT_H4 bool "H:4 UART" select BT_UART + default y + depends on DT_HAS_ZEPHYR_BT_HCI_UART_ENABLED help Bluetooth H:4 UART driver. Requires hardware flow control lines to be available. @@ -25,6 +23,8 @@ config BT_H5 bool "H:5 UART [EXPERIMENTAL]" select BT_UART select EXPERIMENTAL + default y + depends on DT_HAS_ZEPHYR_BT_HCI_3WIRE_UART_ENABLED help Bluetooth three-wire (H:5) UART driver. Implementation of HCI Three-Wire UART Transport Layer. @@ -38,6 +38,8 @@ config BT_RPMSG config BT_HCI_IPC bool "HCI using the IPC subsystem" + default y + depends on DT_HAS_ZEPHYR_BT_HCI_IPC_ENABLED select BT_HAS_HCI_VS select IPC_SERVICE select MBOX @@ -57,6 +59,8 @@ config BT_SPI config BT_STM32_IPM bool "IPM HCI" + default y + depends on DT_HAS_ST_STM32WB_RF_ENABLED select USE_STM32_HAL_CORTEX select HAS_STM32LIB help @@ -64,13 +68,16 @@ config BT_STM32_IPM config BT_STM32WBA bool "STM32WBA HCI driver" + default y + depends on DT_HAS_ST_HCI_STM32WBA_ENABLED select HAS_STM32LIB help ST STM32WBA HCI Bluetooth interface config BT_SILABS_HCI bool "Silicon Labs Bluetooth interface" - depends on SOC_SERIES_EFR32BG22 || SOC_SERIES_EFR32MG24 || SOC_SERIES_EFR32BG27 + default y + depends on DT_HAS_SILABS_BT_HCI_ENABLED depends on !PM || SOC_GECKO_PM_BACKEND_PMGR select SOC_GECKO_USE_RAIL select ENTROPY_GENERATOR @@ -85,6 +92,8 @@ config BT_SILABS_HCI config BT_USERCHAN bool "HCI User Channel based driver" depends on BOARD_NATIVE_POSIX + default y + depends on DT_HAS_ZEPHYR_BT_HCI_USERCHAN_ENABLED help This driver provides access to the local Linux host's Bluetooth adapter using a User Channel HCI socket to the Linux kernel. It @@ -94,11 +103,15 @@ config BT_USERCHAN config BT_ESP32 bool "ESP32 HCI driver" + default y + depends on DT_HAS_ESPRESSIF_ESP32_BT_HCI_ENABLED help Espressif HCI bluetooth interface config BT_PSOC6_BLESS bool "PSOC6 BLESS driver" + default y + depends on DT_HAS_INFINEON_CAT1_BLESS_HCI_ENABLED select BT_HCI_SETUP help PSOC6 BLESS driver with BLE Controller which operates in @@ -106,25 +119,24 @@ config BT_PSOC6_BLESS config BT_DA1469X bool "DA1469x HCI driver" + default y + depends on DT_HAS_RENESAS_BT_HCI_DA1469X_ENABLED help Bluetooth HCI driver for communication with CMAC core on DA1469x MCU. config BT_NXP bool "NXP HCI driver" + default y + depends on DT_HAS_NXP_HCI_BLE_ENABLED select BT_HCI_SETUP help NXP HCI bluetooth interface -config BT_NO_DRIVER - bool "No default HCI driver" - select BT_HAS_HCI_VS - help - This is intended for unit tests where no internal driver - should be selected. - config BT_AMBIQ_HCI bool "AMBIQ BT HCI driver" + default y + depends on DT_HAS_AMBIQ_BT_HCI_SPI_ENABLED select SPI select GPIO if SOC_SERIES_APOLLO4X select CLOCK_CONTROL if SOC_SERIES_APOLLO4X @@ -133,8 +145,6 @@ config BT_AMBIQ_HCI Supports Ambiq Bluetooth SoC using SPI as the communication protocol. HCI packets are sent and received as single Byte transfers. -endchoice - if BT_SPI config BT_SPI_INIT_PRIORITY diff --git a/drivers/bluetooth/hci/apollox_blue.c b/drivers/bluetooth/hci/apollox_blue.c index a25af495bf6e1..7994069a5a2a4 100644 --- a/drivers/bluetooth/hci/apollox_blue.c +++ b/drivers/bluetooth/hci/apollox_blue.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include diff --git a/drivers/bluetooth/hci/cyw43xxx.c b/drivers/bluetooth/hci/cyw43xxx.c index 8da6192610dbe..252b40129d7ad 100644 --- a/drivers/bluetooth/hci/cyw43xxx.c +++ b/drivers/bluetooth/hci/cyw43xxx.c @@ -25,11 +25,11 @@ LOG_MODULE_REGISTER(cyw43xxx_driver); #include -BUILD_ASSERT(DT_PROP(DT_CHOSEN(zephyr_bt_uart), hw_flow_control) == 1, - "hw_flow_control must be enabled for HCI H4 UART"); - #define DT_DRV_COMPAT infineon_cyw43xxx_bt_hci +BUILD_ASSERT(DT_PROP(DT_INST_GPARENT(0), hw_flow_control) == 1, + "hw_flow_control must be enabled for HCI H4 UART"); + /* BT settling time after power on */ #define BT_POWER_ON_SETTLING_TIME_MS (500u) diff --git a/drivers/bluetooth/hci/h4.c b/drivers/bluetooth/hci/h4.c index 16b28b52586a3..412214c7f3224 100644 --- a/drivers/bluetooth/hci/h4.c +++ b/drivers/bluetooth/hci/h4.c @@ -20,7 +20,7 @@ #include #include -#include +#include #define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL #include @@ -30,168 +30,183 @@ LOG_MODULE_REGISTER(bt_driver); #include "../util.h" -static K_KERNEL_STACK_DEFINE(rx_thread_stack, CONFIG_BT_DRV_RX_STACK_SIZE); -static struct k_thread rx_thread_data; +#define DT_DRV_COMPAT zephyr_bt_hci_uart -static struct { - struct net_buf *buf; - struct k_fifo fifo; +struct h4_data { + struct { + struct net_buf *buf; + struct k_fifo fifo; - uint16_t remaining; - uint16_t discard; + uint16_t remaining; + uint16_t discard; - bool have_hdr; - bool discardable; + bool have_hdr; + bool discardable; - uint8_t hdr_len; + uint8_t hdr_len; - uint8_t type; - union { - struct bt_hci_evt_hdr evt; - struct bt_hci_acl_hdr acl; - struct bt_hci_iso_hdr iso; - uint8_t hdr[4]; - }; -} rx = { - .fifo = Z_FIFO_INITIALIZER(rx.fifo), -}; + uint8_t type; + union { + struct bt_hci_evt_hdr evt; + struct bt_hci_acl_hdr acl; + struct bt_hci_iso_hdr iso; + uint8_t hdr[4]; + }; + } rx; -static struct { - uint8_t type; - struct net_buf *buf; - struct k_fifo fifo; -} tx = { - .fifo = Z_FIFO_INITIALIZER(tx.fifo), + struct { + uint8_t type; + struct net_buf *buf; + struct k_fifo fifo; + } tx; + + bt_hci_recv_t recv; }; -static const struct device *const h4_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_bt_uart)); +struct h4_config { + const struct device *uart; + k_thread_stack_t *rx_thread_stack; + size_t rx_thread_stack_size; + struct k_thread *rx_thread; +}; -static inline void h4_get_type(void) +static inline void h4_get_type(const struct device *dev) { + const struct h4_config *cfg = dev->config; + struct h4_data *h4 = dev->data; + /* Get packet type */ - if (uart_fifo_read(h4_dev, &rx.type, 1) != 1) { + if (uart_fifo_read(cfg->uart, &h4->rx.type, 1) != 1) { LOG_WRN("Unable to read H:4 packet type"); - rx.type = BT_HCI_H4_NONE; + h4->rx.type = BT_HCI_H4_NONE; return; } - switch (rx.type) { + switch (h4->rx.type) { case BT_HCI_H4_EVT: - rx.remaining = sizeof(rx.evt); - rx.hdr_len = rx.remaining; + h4->rx.remaining = sizeof(h4->rx.evt); + h4->rx.hdr_len = h4->rx.remaining; break; case BT_HCI_H4_ACL: - rx.remaining = sizeof(rx.acl); - rx.hdr_len = rx.remaining; + h4->rx.remaining = sizeof(h4->rx.acl); + h4->rx.hdr_len = h4->rx.remaining; break; case BT_HCI_H4_ISO: if (IS_ENABLED(CONFIG_BT_ISO)) { - rx.remaining = sizeof(rx.iso); - rx.hdr_len = rx.remaining; + h4->rx.remaining = sizeof(h4->rx.iso); + h4->rx.hdr_len = h4->rx.remaining; break; } __fallthrough; default: - LOG_ERR("Unknown H:4 type 0x%02x", rx.type); - rx.type = BT_HCI_H4_NONE; + LOG_ERR("Unknown H:4 type 0x%02x", h4->rx.type); + h4->rx.type = BT_HCI_H4_NONE; } } -static void h4_read_hdr(void) +static void h4_read_hdr(const struct device *dev) { - int bytes_read = rx.hdr_len - rx.remaining; + const struct h4_config *cfg = dev->config; + struct h4_data *h4 = dev->data; + int bytes_read = h4->rx.hdr_len - h4->rx.remaining; int ret; - ret = uart_fifo_read(h4_dev, rx.hdr + bytes_read, rx.remaining); + ret = uart_fifo_read(cfg->uart, h4->rx.hdr + bytes_read, h4->rx.remaining); if (unlikely(ret < 0)) { LOG_ERR("Unable to read from UART (ret %d)", ret); } else { - rx.remaining -= ret; + h4->rx.remaining -= ret; } } -static inline void get_acl_hdr(void) +static inline void get_acl_hdr(const struct device *dev) { - h4_read_hdr(); + struct h4_data *h4 = dev->data; - if (!rx.remaining) { - struct bt_hci_acl_hdr *hdr = &rx.acl; + h4_read_hdr(dev); - rx.remaining = sys_le16_to_cpu(hdr->len); - LOG_DBG("Got ACL header. Payload %u bytes", rx.remaining); - rx.have_hdr = true; + if (!h4->rx.remaining) { + struct bt_hci_acl_hdr *hdr = &h4->rx.acl; + + h4->rx.remaining = sys_le16_to_cpu(hdr->len); + LOG_DBG("Got ACL header. Payload %u bytes", h4->rx.remaining); + h4->rx.have_hdr = true; } } -static inline void get_iso_hdr(void) +static inline void get_iso_hdr(const struct device *dev) { - h4_read_hdr(); + struct h4_data *h4 = dev->data; + + h4_read_hdr(dev); - if (!rx.remaining) { - struct bt_hci_iso_hdr *hdr = &rx.iso; + if (!h4->rx.remaining) { + struct bt_hci_iso_hdr *hdr = &h4->rx.iso; - rx.remaining = bt_iso_hdr_len(sys_le16_to_cpu(hdr->len)); - LOG_DBG("Got ISO header. Payload %u bytes", rx.remaining); - rx.have_hdr = true; + h4->rx.remaining = bt_iso_hdr_len(sys_le16_to_cpu(hdr->len)); + LOG_DBG("Got ISO header. Payload %u bytes", h4->rx.remaining); + h4->rx.have_hdr = true; } } -static inline void get_evt_hdr(void) +static inline void get_evt_hdr(const struct device *dev) { - struct bt_hci_evt_hdr *hdr = &rx.evt; + struct h4_data *h4 = dev->data; + + struct bt_hci_evt_hdr *hdr = &h4->rx.evt; - h4_read_hdr(); + h4_read_hdr(dev); - if (rx.hdr_len == sizeof(*hdr) && rx.remaining < sizeof(*hdr)) { - switch (rx.evt.evt) { + if (h4->rx.hdr_len == sizeof(*hdr) && h4->rx.remaining < sizeof(*hdr)) { + switch (h4->rx.evt.evt) { case BT_HCI_EVT_LE_META_EVENT: - rx.remaining++; - rx.hdr_len++; + h4->rx.remaining++; + h4->rx.hdr_len++; break; #if defined(CONFIG_BT_CLASSIC) case BT_HCI_EVT_INQUIRY_RESULT_WITH_RSSI: case BT_HCI_EVT_EXTENDED_INQUIRY_RESULT: - rx.discardable = true; + h4->rx.discardable = true; break; #endif } } - if (!rx.remaining) { - if (rx.evt.evt == BT_HCI_EVT_LE_META_EVENT && - (rx.hdr[sizeof(*hdr)] == BT_HCI_EVT_LE_ADVERTISING_REPORT)) { + if (!h4->rx.remaining) { + if (h4->rx.evt.evt == BT_HCI_EVT_LE_META_EVENT && + (h4->rx.hdr[sizeof(*hdr)] == BT_HCI_EVT_LE_ADVERTISING_REPORT)) { LOG_DBG("Marking adv report as discardable"); - rx.discardable = true; + h4->rx.discardable = true; } - rx.remaining = hdr->len - (rx.hdr_len - sizeof(*hdr)); + h4->rx.remaining = hdr->len - (h4->rx.hdr_len - sizeof(*hdr)); LOG_DBG("Got event header. Payload %u bytes", hdr->len); - rx.have_hdr = true; + h4->rx.have_hdr = true; } } -static inline void copy_hdr(struct net_buf *buf) +static inline void copy_hdr(struct h4_data *h4) { - net_buf_add_mem(buf, rx.hdr, rx.hdr_len); + net_buf_add_mem(h4->rx.buf, h4->rx.hdr, h4->rx.hdr_len); } -static void reset_rx(void) +static void reset_rx(struct h4_data *h4) { - rx.type = BT_HCI_H4_NONE; - rx.remaining = 0U; - rx.have_hdr = false; - rx.hdr_len = 0U; - rx.discardable = false; + h4->rx.type = BT_HCI_H4_NONE; + h4->rx.remaining = 0U; + h4->rx.have_hdr = false; + h4->rx.hdr_len = 0U; + h4->rx.discardable = false; } -static struct net_buf *get_rx(k_timeout_t timeout) +static struct net_buf *get_rx(struct h4_data *h4, k_timeout_t timeout) { - LOG_DBG("type 0x%02x, evt 0x%02x", rx.type, rx.evt.evt); + LOG_DBG("type 0x%02x, evt 0x%02x", h4->rx.type, h4->rx.evt.evt); - switch (rx.type) { + switch (h4->rx.type) { case BT_HCI_H4_EVT: - return bt_buf_get_evt(rx.evt.evt, rx.discardable, timeout); + return bt_buf_get_evt(h4->rx.evt.evt, h4->rx.discardable, timeout); case BT_HCI_H4_ACL: return bt_buf_get_rx(BT_BUF_ACL_IN, timeout); case BT_HCI_H4_ISO: @@ -205,42 +220,44 @@ static struct net_buf *get_rx(k_timeout_t timeout) static void rx_thread(void *p1, void *p2, void *p3) { + const struct device *dev = p1; + const struct h4_config *cfg = dev->config; + struct h4_data *h4 = dev->data; struct net_buf *buf; - ARG_UNUSED(p1); ARG_UNUSED(p2); ARG_UNUSED(p3); LOG_DBG("started"); while (1) { - LOG_DBG("rx.buf %p", rx.buf); + LOG_DBG("rx.buf %p", h4->rx.buf); /* We can only do the allocation if we know the initial * header, since Command Complete/Status events must use the * original command buffer (if available). */ - if (rx.have_hdr && !rx.buf) { - rx.buf = get_rx(K_FOREVER); - LOG_DBG("Got rx.buf %p", rx.buf); - if (rx.remaining > net_buf_tailroom(rx.buf)) { + if (h4->rx.have_hdr && !h4->rx.buf) { + h4->rx.buf = get_rx(h4, K_FOREVER); + LOG_DBG("Got rx.buf %p", h4->rx.buf); + if (h4->rx.remaining > net_buf_tailroom(h4->rx.buf)) { LOG_ERR("Not enough space in buffer"); - rx.discard = rx.remaining; - reset_rx(); + h4->rx.discard = h4->rx.remaining; + reset_rx(h4); } else { - copy_hdr(rx.buf); + copy_hdr(h4); } } /* Let the ISR continue receiving new packets */ - uart_irq_rx_enable(h4_dev); + uart_irq_rx_enable(cfg->uart); - buf = net_buf_get(&rx.fifo, K_FOREVER); + buf = net_buf_get(&h4->rx.fifo, K_FOREVER); do { - uart_irq_rx_enable(h4_dev); + uart_irq_rx_enable(cfg->uart); LOG_DBG("Calling bt_recv(%p)", buf); - bt_recv(buf); + h4->recv(dev, buf); /* Give other threads a chance to run if the ISR * is receiving data so fast that rx.fifo never @@ -248,8 +265,8 @@ static void rx_thread(void *p1, void *p2, void *p3) */ k_yield(); - uart_irq_rx_disable(h4_dev); - buf = net_buf_get(&rx.fifo, K_NO_WAIT); + uart_irq_rx_disable(cfg->uart); + buf = net_buf_get(&h4->rx.fifo, K_NO_WAIT); } while (buf); } } @@ -268,87 +285,93 @@ static size_t h4_discard(const struct device *uart, size_t len) return err; } -static inline void read_payload(void) +static inline void read_payload(const struct device *dev) { + const struct h4_config *cfg = dev->config; + struct h4_data *h4 = dev->data; struct net_buf *buf; int read; - if (!rx.buf) { + if (!h4->rx.buf) { size_t buf_tailroom; - rx.buf = get_rx(K_NO_WAIT); - if (!rx.buf) { - if (rx.discardable) { - LOG_WRN("Discarding event 0x%02x", rx.evt.evt); - rx.discard = rx.remaining; - reset_rx(); + h4->rx.buf = get_rx(h4, K_NO_WAIT); + if (!h4->rx.buf) { + if (h4->rx.discardable) { + LOG_WRN("Discarding event 0x%02x", h4->rx.evt.evt); + h4->rx.discard = h4->rx.remaining; + reset_rx(h4); return; } LOG_WRN("Failed to allocate, deferring to rx_thread"); - uart_irq_rx_disable(h4_dev); + uart_irq_rx_disable(cfg->uart); return; } - LOG_DBG("Allocated rx.buf %p", rx.buf); + LOG_DBG("Allocated rx.buf %p", h4->rx.buf); - buf_tailroom = net_buf_tailroom(rx.buf); - if (buf_tailroom < rx.remaining) { - LOG_ERR("Not enough space in buffer %u/%zu", rx.remaining, buf_tailroom); - rx.discard = rx.remaining; - reset_rx(); + buf_tailroom = net_buf_tailroom(h4->rx.buf); + if (buf_tailroom < h4->rx.remaining) { + LOG_ERR("Not enough space in buffer %u/%zu", h4->rx.remaining, + buf_tailroom); + h4->rx.discard = h4->rx.remaining; + reset_rx(h4); return; } - copy_hdr(rx.buf); + copy_hdr(h4); } - read = uart_fifo_read(h4_dev, net_buf_tail(rx.buf), rx.remaining); + read = uart_fifo_read(cfg->uart, net_buf_tail(h4->rx.buf), h4->rx.remaining); if (unlikely(read < 0)) { LOG_ERR("Failed to read UART (err %d)", read); return; } - net_buf_add(rx.buf, read); - rx.remaining -= read; + net_buf_add(h4->rx.buf, read); + h4->rx.remaining -= read; - LOG_DBG("got %d bytes, remaining %u", read, rx.remaining); - LOG_DBG("Payload (len %u): %s", rx.buf->len, bt_hex(rx.buf->data, rx.buf->len)); + LOG_DBG("got %d bytes, remaining %u", read, h4->rx.remaining); + LOG_DBG("Payload (len %u): %s", h4->rx.buf->len, + bt_hex(h4->rx.buf->data, h4->rx.buf->len)); - if (rx.remaining) { + if (h4->rx.remaining) { return; } - buf = rx.buf; - rx.buf = NULL; + buf = h4->rx.buf; + h4->rx.buf = NULL; - if (rx.type == BT_HCI_H4_EVT) { + if (h4->rx.type == BT_HCI_H4_EVT) { bt_buf_set_type(buf, BT_BUF_EVT); } else { bt_buf_set_type(buf, BT_BUF_ACL_IN); } - reset_rx(); + reset_rx(h4); LOG_DBG("Putting buf %p to rx fifo", buf); - net_buf_put(&rx.fifo, buf); + net_buf_put(&h4->rx.fifo, buf); } -static inline void read_header(void) +static inline void read_header(const struct device *dev) { - switch (rx.type) { + struct h4_data *h4 = dev->data; + + switch (h4->rx.type) { case BT_HCI_H4_NONE: - h4_get_type(); + h4_get_type(dev); return; case BT_HCI_H4_EVT: - get_evt_hdr(); + get_evt_hdr(dev); break; case BT_HCI_H4_ACL: - get_acl_hdr(); + get_acl_hdr(dev); break; case BT_HCI_H4_ISO: if (IS_ENABLED(CONFIG_BT_ISO)) { - get_iso_hdr(); + get_iso_hdr(dev); break; } __fallthrough; @@ -357,41 +380,43 @@ static inline void read_header(void) return; } - if (rx.have_hdr && rx.buf) { - if (rx.remaining > net_buf_tailroom(rx.buf)) { + if (h4->rx.have_hdr && h4->rx.buf) { + if (h4->rx.remaining > net_buf_tailroom(h4->rx.buf)) { LOG_ERR("Not enough space in buffer"); - rx.discard = rx.remaining; - reset_rx(); + h4->rx.discard = h4->rx.remaining; + reset_rx(h4); } else { - copy_hdr(rx.buf); + copy_hdr(h4); } } } -static inline void process_tx(void) +static inline void process_tx(const struct device *dev) { + const struct h4_config *cfg = dev->config; + struct h4_data *h4 = dev->data; int bytes; - if (!tx.buf) { - tx.buf = net_buf_get(&tx.fifo, K_NO_WAIT); - if (!tx.buf) { + if (!h4->tx.buf) { + h4->tx.buf = net_buf_get(&h4->tx.fifo, K_NO_WAIT); + if (!h4->tx.buf) { LOG_ERR("TX interrupt but no pending buffer!"); - uart_irq_tx_disable(h4_dev); + uart_irq_tx_disable(cfg->uart); return; } } - if (!tx.type) { - switch (bt_buf_get_type(tx.buf)) { + if (!h4->tx.type) { + switch (bt_buf_get_type(h4->tx.buf)) { case BT_BUF_ACL_OUT: - tx.type = BT_HCI_H4_ACL; + h4->tx.type = BT_HCI_H4_ACL; break; case BT_BUF_CMD: - tx.type = BT_HCI_H4_CMD; + h4->tx.type = BT_HCI_H4_CMD; break; case BT_BUF_ISO_OUT: if (IS_ENABLED(CONFIG_BT_ISO)) { - tx.type = BT_HCI_H4_ISO; + h4->tx.type = BT_HCI_H4_ISO; break; } __fallthrough; @@ -400,73 +425,79 @@ static inline void process_tx(void) goto done; } - bytes = uart_fifo_fill(h4_dev, &tx.type, 1); + bytes = uart_fifo_fill(cfg->uart, &h4->tx.type, 1); if (bytes != 1) { LOG_WRN("Unable to send H:4 type"); - tx.type = BT_HCI_H4_NONE; + h4->tx.type = BT_HCI_H4_NONE; return; } } - bytes = uart_fifo_fill(h4_dev, tx.buf->data, tx.buf->len); + bytes = uart_fifo_fill(cfg->uart, h4->tx.buf->data, h4->tx.buf->len); if (unlikely(bytes < 0)) { LOG_ERR("Unable to write to UART (err %d)", bytes); } else { - net_buf_pull(tx.buf, bytes); + net_buf_pull(h4->tx.buf, bytes); } - if (tx.buf->len) { + if (h4->tx.buf->len) { return; } done: - tx.type = BT_HCI_H4_NONE; - net_buf_unref(tx.buf); - tx.buf = net_buf_get(&tx.fifo, K_NO_WAIT); - if (!tx.buf) { - uart_irq_tx_disable(h4_dev); + h4->tx.type = BT_HCI_H4_NONE; + net_buf_unref(h4->tx.buf); + h4->tx.buf = net_buf_get(&h4->tx.fifo, K_NO_WAIT); + if (!h4->tx.buf) { + uart_irq_tx_disable(cfg->uart); } } -static inline void process_rx(void) +static inline void process_rx(const struct device *dev) { - LOG_DBG("remaining %u discard %u have_hdr %u rx.buf %p len %u", rx.remaining, rx.discard, - rx.have_hdr, rx.buf, rx.buf ? rx.buf->len : 0); + const struct h4_config *cfg = dev->config; + struct h4_data *h4 = dev->data; + + LOG_DBG("remaining %u discard %u have_hdr %u rx.buf %p len %u", + h4->rx.remaining, h4->rx.discard, h4->rx.have_hdr, h4->rx.buf, + h4->rx.buf ? h4->rx.buf->len : 0); - if (rx.discard) { - rx.discard -= h4_discard(h4_dev, rx.discard); + if (h4->rx.discard) { + h4->rx.discard -= h4_discard(cfg->uart, h4->rx.discard); return; } - if (rx.have_hdr) { - read_payload(); + if (h4->rx.have_hdr) { + read_payload(dev); } else { - read_header(); + read_header(dev); } } -static void bt_uart_isr(const struct device *unused, void *user_data) +static void bt_uart_isr(const struct device *uart, void *user_data) { - ARG_UNUSED(unused); - ARG_UNUSED(user_data); + struct device *dev = user_data; - while (uart_irq_update(h4_dev) && uart_irq_is_pending(h4_dev)) { - if (uart_irq_tx_ready(h4_dev)) { - process_tx(); + while (uart_irq_update(uart) && uart_irq_is_pending(uart)) { + if (uart_irq_tx_ready(uart)) { + process_tx(dev); } - if (uart_irq_rx_ready(h4_dev)) { - process_rx(); + if (uart_irq_rx_ready(uart)) { + process_rx(dev); } } } -static int h4_send(struct net_buf *buf) +static int h4_send(const struct device *dev, struct net_buf *buf) { + const struct h4_config *cfg = dev->config; + struct h4_data *h4 = dev->data; + LOG_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len); - net_buf_put(&tx.fifo, buf); - uart_irq_tx_enable(h4_dev); + net_buf_put(&h4->tx.fifo, buf); + uart_irq_tx_enable(cfg->uart); return 0; } @@ -477,32 +508,36 @@ static int h4_send(struct net_buf *buf) * * @return 0 on success, negative error value on failure */ -int __weak bt_hci_transport_setup(const struct device *dev) +int __weak bt_hci_transport_setup(const struct device *uart) { - h4_discard(h4_dev, 32); + h4_discard(uart, 32); return 0; } -static int h4_open(void) +static int h4_open(const struct device *dev, bt_hci_recv_t recv) { + const struct h4_config *cfg = dev->config; + struct h4_data *h4 = dev->data; int ret; k_tid_t tid; LOG_DBG(""); - uart_irq_rx_disable(h4_dev); - uart_irq_tx_disable(h4_dev); + uart_irq_rx_disable(cfg->uart); + uart_irq_tx_disable(cfg->uart); - ret = bt_hci_transport_setup(h4_dev); + ret = bt_hci_transport_setup(cfg->uart); if (ret < 0) { return -EIO; } - uart_irq_callback_set(h4_dev, bt_uart_isr); + h4->recv = recv; + + uart_irq_callback_user_data_set(cfg->uart, bt_uart_isr, (void *)dev); - tid = k_thread_create(&rx_thread_data, rx_thread_stack, - K_KERNEL_STACK_SIZEOF(rx_thread_stack), - rx_thread, NULL, NULL, NULL, + tid = k_thread_create(cfg->rx_thread, cfg->rx_thread_stack, + cfg->rx_thread_stack_size, + rx_thread, (void *)dev, NULL, NULL, K_PRIO_COOP(CONFIG_BT_RX_PRIO), 0, K_NO_WAIT); k_thread_name_set(tid, "bt_rx_thread"); @@ -511,8 +546,10 @@ static int h4_open(void) } #if defined(CONFIG_BT_HCI_SETUP) -static int h4_setup(const struct bt_hci_setup_params *params) +static int h4_setup(const struct device *dev, const struct bt_hci_setup_params *params) { + const struct h4_config *cfg = dev->config; + ARG_UNUSED(params); /* Extern bt_h4_vnd_setup function. @@ -523,30 +560,36 @@ static int h4_setup(const struct bt_hci_setup_params *params) */ extern int bt_h4_vnd_setup(const struct device *dev); - return bt_h4_vnd_setup(h4_dev); + return bt_h4_vnd_setup(cfg->uart); } #endif -static const struct bt_hci_driver drv = { - .name = "H:4", - .bus = BT_HCI_DRIVER_BUS_UART, - .open = h4_open, - .send = h4_send, +static const struct bt_hci_driver_api h4_driver_api = { + .open = h4_open, + .send = h4_send, #if defined(CONFIG_BT_HCI_SETUP) - .setup = h4_setup + .setup = h4_setup, #endif }; -static int bt_uart_init(void) -{ - - if (!device_is_ready(h4_dev)) { - return -ENODEV; - } - - bt_hci_driver_register(&drv); - - return 0; -} - -SYS_INIT(bt_uart_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); +#define BT_UART_DEVICE_INIT(inst) \ + static K_KERNEL_STACK_DEFINE(rx_thread_stack_##inst, CONFIG_BT_DRV_RX_STACK_SIZE); \ + static struct k_thread rx_thread_##inst; \ + static const struct h4_config h4_config_##inst = { \ + .uart = DEVICE_DT_GET(DT_INST_PARENT(inst)), \ + .rx_thread_stack = rx_thread_stack_##inst, \ + .rx_thread_stack_size = K_KERNEL_STACK_SIZEOF(rx_thread_stack_##inst), \ + .rx_thread = &rx_thread_##inst, \ + }; \ + static struct h4_data h4_data_##inst = { \ + .rx = { \ + .fifo = Z_FIFO_INITIALIZER(h4_data_##inst.rx.fifo), \ + }, \ + .tx = { \ + .fifo = Z_FIFO_INITIALIZER(h4_data_##inst.tx.fifo), \ + }, \ + }; \ + DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &h4_data_##inst, &h4_config_##inst, \ + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &h4_driver_api) + +DT_INST_FOREACH_STATUS_OKAY(BT_UART_DEVICE_INIT) diff --git a/drivers/bluetooth/hci/h5.c b/drivers/bluetooth/hci/h5.c index 25a3b3e28f622..0be22f61f888f 100644 --- a/drivers/bluetooth/hci/h5.c +++ b/drivers/bluetooth/hci/h5.c @@ -17,11 +17,13 @@ #include #include #include +#include +#include #include #include #include -#include +#include #include "../util.h" @@ -29,14 +31,7 @@ #include LOG_MODULE_REGISTER(bt_driver); -static K_KERNEL_STACK_DEFINE(tx_stack, CONFIG_BT_DRV_TX_STACK_SIZE); -static K_KERNEL_STACK_DEFINE(rx_stack, CONFIG_BT_DRV_RX_STACK_SIZE); - -static struct k_thread tx_thread_data; -static struct k_thread rx_thread_data; - -static struct k_work_delayable ack_work; -static struct k_work_delayable retx_work; +#define DT_DRV_COMPAT zephyr_bt_hci_3wire_uart #define HCI_3WIRE_ACK_PKT 0x00 #define HCI_COMMAND_PKT 0x01 @@ -86,13 +81,21 @@ static bool reliable_packet(uint8_t type) #define H5_SET_LEN(hdr, len) (((hdr)[1] |= ((len) & 0x0f) << 4), \ ((hdr)[2] |= (len) >> 4)) -static struct h5 { +struct h5_data { + /* Needed for delayed work callbacks */ + const struct device *dev; + + bt_hci_recv_t recv; + struct net_buf *rx_buf; struct k_fifo tx_queue; struct k_fifo rx_queue; struct k_fifo unack_queue; + struct k_work_delayable ack_work; + struct k_work_delayable retx_work; + uint8_t tx_win; uint8_t tx_ack; uint8_t tx_seq; @@ -111,9 +114,21 @@ static struct h5 { PAYLOAD, END, } rx_state; -} h5; -static uint8_t unack_queue_len; + uint8_t unack_queue_len; +}; + +struct h5_config { + const struct device *uart; + + k_thread_stack_t *rx_stack; + size_t rx_stack_size; + struct k_thread *rx_thread; + + k_thread_stack_t *tx_stack; + size_t tx_stack_size; + struct k_thread *tx_thread; +}; static const uint8_t sync_req[] = { 0x01, 0x7e }; static const uint8_t sync_rsp[] = { 0x02, 0x7d }; @@ -123,23 +138,21 @@ static const uint8_t conf_rsp[] = { 0x04, 0x7b }; /* H5 signal buffers pool */ #define MAX_SIG_LEN 3 -#define SIGNAL_COUNT 2 +#define SIGNAL_COUNT (2 * DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT)) #define SIG_BUF_SIZE (BT_BUF_RESERVE + MAX_SIG_LEN) NET_BUF_POOL_DEFINE(h5_pool, SIGNAL_COUNT, SIG_BUF_SIZE, 0, NULL); -static const struct device *const h5_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_bt_uart)); - -static void h5_reset_rx(void) +static void h5_reset_rx(struct h5_data *h5) { - if (h5.rx_buf) { - net_buf_unref(h5.rx_buf); - h5.rx_buf = NULL; + if (h5->rx_buf) { + net_buf_unref(h5->rx_buf); + h5->rx_buf = NULL; } - h5.rx_state = START; + h5->rx_state = START; } -static int h5_unslip_byte(uint8_t *byte) +static int h5_unslip_byte(const struct device *uart, uint8_t *byte) { int count; @@ -148,7 +161,7 @@ static int h5_unslip_byte(uint8_t *byte) } do { - count = uart_fifo_read(h5_dev, byte, sizeof(*byte)); + count = uart_fifo_read(uart, byte, sizeof(*byte)); } while (!count); switch (*byte) { @@ -166,20 +179,20 @@ static int h5_unslip_byte(uint8_t *byte) return 0; } -static void process_unack(void) +static void process_unack(struct h5_data *h5) { - uint8_t next_seq = h5.tx_seq; - uint8_t number_removed = unack_queue_len; + uint8_t next_seq = h5->tx_seq; + uint8_t number_removed = h5->unack_queue_len; - if (!unack_queue_len) { + if (!h5->unack_queue_len) { return; } - LOG_DBG("rx_ack %u tx_ack %u tx_seq %u unack_queue_len %u", h5.rx_ack, h5.tx_ack, h5.tx_seq, - unack_queue_len); + LOG_DBG("rx_ack %u tx_ack %u tx_seq %u unack_queue_len %u", h5->rx_ack, h5->tx_ack, + h5->tx_seq, h5->unack_queue_len); - while (unack_queue_len > 0) { - if (next_seq == h5.rx_ack) { + while (h5->unack_queue_len > 0) { + if (next_seq == h5->rx_ack) { /* Next sequence number is the same as last received * ack number */ @@ -191,15 +204,15 @@ static void process_unack(void) next_seq = (next_seq - 1) & 0x07; } - if (next_seq != h5.rx_ack) { - LOG_ERR("Wrong sequence: rx_ack %u tx_seq %u next_seq %u", h5.rx_ack, h5.tx_seq, - next_seq); + if (next_seq != h5->rx_ack) { + LOG_ERR("Wrong sequence: rx_ack %u tx_seq %u next_seq %u", h5->rx_ack, + h5->tx_seq, next_seq); } LOG_DBG("Need to remove %u packet from the queue", number_removed); while (number_removed) { - struct net_buf *buf = net_buf_get(&h5.unack_queue, K_NO_WAIT); + struct net_buf *buf = net_buf_get(&h5->unack_queue, K_NO_WAIT); if (!buf) { LOG_ERR("Unack queue is empty"); @@ -210,7 +223,7 @@ static void process_unack(void) LOG_DBG("Remove buf from the unack_queue"); net_buf_unref(buf); - unack_queue_len--; + h5->unack_queue_len--; number_removed--; } } @@ -261,25 +274,27 @@ static void hexdump(const char *str, const uint8_t *packet, size_t length) #define hexdump(str, packet, length) #endif -static uint8_t h5_slip_byte(uint8_t byte) +static uint8_t h5_slip_byte(const struct device *uart, uint8_t byte) { switch (byte) { case SLIP_DELIMITER: - uart_poll_out(h5_dev, SLIP_ESC); - uart_poll_out(h5_dev, SLIP_ESC_DELIM); + uart_poll_out(uart, SLIP_ESC); + uart_poll_out(uart, SLIP_ESC_DELIM); return 2; case SLIP_ESC: - uart_poll_out(h5_dev, SLIP_ESC); - uart_poll_out(h5_dev, SLIP_ESC_ESC); + uart_poll_out(uart, SLIP_ESC); + uart_poll_out(uart, SLIP_ESC_ESC); return 2; default: - uart_poll_out(h5_dev, byte); + uart_poll_out(uart, byte); return 1; } } -static void h5_send(const uint8_t *payload, uint8_t type, int len) +static void h5_send(const struct device *dev, const uint8_t *payload, uint8_t type, int len) { + const struct h5_config *cfg = dev->config; + struct h5_data *h5 = dev->data; uint8_t hdr[4]; int i; @@ -288,14 +303,14 @@ static void h5_send(const uint8_t *payload, uint8_t type, int len) (void)memset(hdr, 0, sizeof(hdr)); /* Set ACK for outgoing packet and stop delayed work */ - H5_SET_ACK(hdr, h5.tx_ack); + H5_SET_ACK(hdr, h5->tx_ack); /* If cancel fails we may ack the same seq number twice, this is OK. */ - (void)k_work_cancel_delayable(&ack_work); + (void)k_work_cancel_delayable(&h5->ack_work); if (reliable_packet(type)) { H5_SET_RELIABLE(hdr); - H5_SET_SEQ(hdr, h5.tx_seq); - h5.tx_seq = (h5.tx_seq + 1) % 8; + H5_SET_SEQ(hdr, h5->tx_seq); + h5->tx_seq = (h5->tx_seq + 1) % 8; } H5_SET_TYPE(hdr, type); @@ -306,97 +321,100 @@ static void h5_send(const uint8_t *payload, uint8_t type, int len) h5_print_header(hdr, "TX: <"); - uart_poll_out(h5_dev, SLIP_DELIMITER); + uart_poll_out(cfg->uart, SLIP_DELIMITER); for (i = 0; i < 4; i++) { - h5_slip_byte(hdr[i]); + h5_slip_byte(cfg->uart, hdr[i]); } for (i = 0; i < len; i++) { - h5_slip_byte(payload[i]); + h5_slip_byte(cfg->uart, payload[i]); } - uart_poll_out(h5_dev, SLIP_DELIMITER); + uart_poll_out(cfg->uart, SLIP_DELIMITER); } /* Delayed work taking care about retransmitting packets */ static void retx_timeout(struct k_work *work) { - ARG_UNUSED(work); + struct k_work_delayable *delayable = k_work_delayable_from_work(work); + struct h5_data *h5 = CONTAINER_OF(delayable, struct h5_data, retx_work); - LOG_DBG("unack_queue_len %u", unack_queue_len); + LOG_DBG("unack_queue_len %u", h5->unack_queue_len); - if (unack_queue_len) { + if (h5->unack_queue_len) { struct k_fifo tmp_queue; struct net_buf *buf; k_fifo_init(&tmp_queue); /* Queue to temporary queue */ - while ((buf = net_buf_get(&h5.tx_queue, K_NO_WAIT))) { + while ((buf = net_buf_get(&h5->tx_queue, K_NO_WAIT))) { net_buf_put(&tmp_queue, buf); } /* Queue unack packets to the beginning of the queue */ - while ((buf = net_buf_get(&h5.unack_queue, K_NO_WAIT))) { + while ((buf = net_buf_get(&h5->unack_queue, K_NO_WAIT))) { /* include also packet type */ net_buf_push(buf, sizeof(uint8_t)); - net_buf_put(&h5.tx_queue, buf); - h5.tx_seq = (h5.tx_seq - 1) & 0x07; - unack_queue_len--; + net_buf_put(&h5->tx_queue, buf); + h5->tx_seq = (h5->tx_seq - 1) & 0x07; + h5->unack_queue_len--; } /* Queue saved packets from temp queue */ while ((buf = net_buf_get(&tmp_queue, K_NO_WAIT))) { - net_buf_put(&h5.tx_queue, buf); + net_buf_put(&h5->tx_queue, buf); } } } static void ack_timeout(struct k_work *work) { - ARG_UNUSED(work); + struct k_work_delayable *delayable = k_work_delayable_from_work(work); + struct h5_data *h5 = CONTAINER_OF(delayable, struct h5_data, ack_work); LOG_DBG(""); - h5_send(NULL, HCI_3WIRE_ACK_PKT, 0); + h5_send(h5->dev, NULL, HCI_3WIRE_ACK_PKT, 0); } -static void h5_process_complete_packet(uint8_t *hdr) +static void h5_process_complete_packet(const struct device *dev, uint8_t *hdr) { + struct h5_data *h5 = dev->data; struct net_buf *buf; LOG_DBG(""); /* rx_ack should be in every packet */ - h5.rx_ack = H5_HDR_ACK(hdr); + h5->rx_ack = H5_HDR_ACK(hdr); if (reliable_packet(H5_HDR_PKT_TYPE(hdr))) { /* For reliable packet increment next transmit ack number */ - h5.tx_ack = (h5.tx_ack + 1) % 8; + h5->tx_ack = (h5->tx_ack + 1) % 8; /* Submit delayed work to ack the packet */ - k_work_reschedule(&ack_work, H5_RX_ACK_TIMEOUT); + k_work_reschedule(&h5->ack_work, H5_RX_ACK_TIMEOUT); } h5_print_header(hdr, "RX: >"); - process_unack(); + process_unack(h5); - buf = h5.rx_buf; - h5.rx_buf = NULL; + buf = h5->rx_buf; + h5->rx_buf = NULL; switch (H5_HDR_PKT_TYPE(hdr)) { case HCI_3WIRE_ACK_PKT: net_buf_unref(buf); break; case HCI_3WIRE_LINK_PKT: - net_buf_put(&h5.rx_queue, buf); + net_buf_put(&h5->rx_queue, buf); break; case HCI_EVENT_PKT: case HCI_ACLDATA_PKT: case HCI_ISODATA_PKT: hexdump("=> ", buf->data, buf->len); - bt_recv(buf); + h5->recv(dev, buf); break; } } @@ -406,22 +424,21 @@ static inline struct net_buf *get_evt_buf(uint8_t evt) return bt_buf_get_evt(evt, false, K_NO_WAIT); } -static void bt_uart_isr(const struct device *unused, void *user_data) +static void bt_uart_isr(const struct device *uart, void *user_data) { + const struct device *dev = user_data; + struct h5_data *h5 = dev->data; static int remaining; uint8_t byte; int ret; static uint8_t hdr[4]; size_t buf_tailroom; - ARG_UNUSED(unused); - ARG_UNUSED(user_data); - - while (uart_irq_update(h5_dev) && - uart_irq_is_pending(h5_dev)) { + while (uart_irq_update(uart) && + uart_irq_is_pending(uart)) { - if (!uart_irq_rx_ready(h5_dev)) { - if (uart_irq_tx_ready(h5_dev)) { + if (!uart_irq_rx_ready(uart)) { + if (uart_irq_tx_ready(uart)) { LOG_DBG("transmit ready"); } else { LOG_DBG("spurious interrupt"); @@ -430,15 +447,15 @@ static void bt_uart_isr(const struct device *unused, void *user_data) break; } - ret = uart_fifo_read(h5_dev, &byte, sizeof(byte)); + ret = uart_fifo_read(uart, &byte, sizeof(byte)); if (!ret) { continue; } - switch (h5.rx_state) { + switch (h5->rx_state) { case START: if (byte == SLIP_DELIMITER) { - h5.rx_state = HEADER; + h5->rx_state = HEADER; remaining = sizeof(hdr); } break; @@ -451,8 +468,8 @@ static void bt_uart_isr(const struct device *unused, void *user_data) continue; } - if (h5_unslip_byte(&byte) < 0) { - h5_reset_rx(); + if (h5_unslip_byte(uart, &byte) < 0) { + h5_reset_rx(h5); continue; } @@ -470,86 +487,85 @@ static void bt_uart_isr(const struct device *unused, void *user_data) /* The buffer is allocated only once we know * the exact event type. */ - h5.rx_state = PAYLOAD; + h5->rx_state = PAYLOAD; break; case HCI_ACLDATA_PKT: - h5.rx_buf = bt_buf_get_rx(BT_BUF_ACL_IN, - K_NO_WAIT); - if (!h5.rx_buf) { + h5->rx_buf = bt_buf_get_rx(BT_BUF_ACL_IN, + K_NO_WAIT); + if (!h5->rx_buf) { LOG_WRN("No available data buffers"); - h5_reset_rx(); + h5_reset_rx(h5); continue; } - h5.rx_state = PAYLOAD; + h5->rx_state = PAYLOAD; break; case HCI_ISODATA_PKT: - h5.rx_buf = bt_buf_get_rx(BT_BUF_ISO_IN, - K_NO_WAIT); - if (!h5.rx_buf) { + h5->rx_buf = bt_buf_get_rx(BT_BUF_ISO_IN, K_NO_WAIT); + if (!h5->rx_buf) { LOG_WRN("No available data buffers"); - h5_reset_rx(); + h5_reset_rx(h5); continue; } - h5.rx_state = PAYLOAD; + h5->rx_state = PAYLOAD; break; case HCI_3WIRE_LINK_PKT: case HCI_3WIRE_ACK_PKT: - h5.rx_buf = net_buf_alloc(&h5_pool, K_NO_WAIT); - if (!h5.rx_buf) { + h5->rx_buf = net_buf_alloc(&h5_pool, K_NO_WAIT); + if (!h5->rx_buf) { LOG_WRN("No available signal buffers"); - h5_reset_rx(); + h5_reset_rx(h5); continue; } - h5.rx_state = PAYLOAD; + h5->rx_state = PAYLOAD; break; default: LOG_ERR("Wrong packet type %u", H5_HDR_PKT_TYPE(hdr)); - h5.rx_state = END; + h5->rx_state = END; break; } if (!remaining) { - h5.rx_state = END; + h5->rx_state = END; } break; case PAYLOAD: - if (h5_unslip_byte(&byte) < 0) { - h5_reset_rx(); + if (h5_unslip_byte(uart, &byte) < 0) { + h5_reset_rx(h5); continue; } /* Allocate HCI event buffer now that we know the * exact event type. */ - if (!h5.rx_buf) { - h5.rx_buf = get_evt_buf(byte); - if (!h5.rx_buf) { + if (!h5->rx_buf) { + h5->rx_buf = get_evt_buf(byte); + if (!h5->rx_buf) { LOG_WRN("No available event buffers"); - h5_reset_rx(); + h5_reset_rx(h5); continue; } } - buf_tailroom = net_buf_tailroom(h5.rx_buf); + buf_tailroom = net_buf_tailroom(h5->rx_buf); if (buf_tailroom < sizeof(byte)) { LOG_ERR("Not enough space in buffer %zu/%zu", sizeof(byte), buf_tailroom); - h5_reset_rx(); + h5_reset_rx(h5); break; } - net_buf_add_mem(h5.rx_buf, &byte, sizeof(byte)); + net_buf_add_mem(h5->rx_buf, &byte, sizeof(byte)); remaining--; if (!remaining) { - h5.rx_state = END; + h5->rx_state = END; } break; case END: if (byte != SLIP_DELIMITER) { LOG_ERR("Missing ending SLIP_DELIMITER"); - h5_reset_rx(); + h5_reset_rx(h5); break; } @@ -560,15 +576,15 @@ static void bt_uart_isr(const struct device *unused, void *user_data) * full packet anyway to clear UART. */ if (H5_HDR_RELIABLE(hdr) && - H5_HDR_SEQ(hdr) != h5.tx_ack) { - LOG_ERR("Seq expected %u got %u. Drop packet", h5.tx_ack, + H5_HDR_SEQ(hdr) != h5->tx_ack) { + LOG_ERR("Seq expected %u got %u. Drop packet", h5->tx_ack, H5_HDR_SEQ(hdr)); - h5_reset_rx(); + h5_reset_rx(h5); break; } - h5_process_complete_packet(hdr); - h5.rx_state = START; + h5_process_complete_packet(dev, hdr); + h5->rx_state = START; break; } } @@ -579,8 +595,9 @@ static uint8_t h5_get_type(struct net_buf *buf) return net_buf_pull_u8(buf); } -static int h5_queue(struct net_buf *buf) +static int h5_queue(const struct device *dev, struct net_buf *buf) { + struct h5_data *h5 = dev->data; uint8_t type; LOG_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len); @@ -602,29 +619,31 @@ static int h5_queue(struct net_buf *buf) memcpy(net_buf_push(buf, sizeof(type)), &type, sizeof(type)); - net_buf_put(&h5.tx_queue, buf); + net_buf_put(&h5->tx_queue, buf); return 0; } static void tx_thread(void *p1, void *p2, void *p3) { - ARG_UNUSED(p1); + const struct device *dev = p1; + struct h5_data *h5 = dev->data; + ARG_UNUSED(p2); ARG_UNUSED(p3); LOG_DBG(""); /* FIXME: make periodic sending */ - h5_send(sync_req, HCI_3WIRE_LINK_PKT, sizeof(sync_req)); + h5_send(dev, sync_req, HCI_3WIRE_LINK_PKT, sizeof(sync_req)); while (true) { struct net_buf *buf; uint8_t type; - LOG_DBG("link_state %u", h5.link_state); + LOG_DBG("link_state %u", h5->link_state); - switch (h5.link_state) { + switch (h5->link_state) { case UNINIT: /* FIXME: send sync */ k_sleep(K_MSEC(100)); @@ -634,32 +653,34 @@ static void tx_thread(void *p1, void *p2, void *p3) k_sleep(K_MSEC(100)); break; case ACTIVE: - buf = net_buf_get(&h5.tx_queue, K_FOREVER); + buf = net_buf_get(&h5->tx_queue, K_FOREVER); type = h5_get_type(buf); - h5_send(buf->data, type, buf->len); + h5_send(dev, buf->data, type, buf->len); /* buf is dequeued from tx_queue and queued to unack * queue. */ - net_buf_put(&h5.unack_queue, buf); - unack_queue_len++; + net_buf_put(&h5->unack_queue, buf); + h5->unack_queue_len++; - k_work_reschedule(&retx_work, H5_TX_ACK_TIMEOUT); + k_work_reschedule(&h5->retx_work, H5_TX_ACK_TIMEOUT); break; } } } -static void h5_set_txwin(uint8_t *conf) +static void h5_set_txwin(struct h5_data *h5, uint8_t *conf) { - conf[2] = h5.tx_win & 0x07; + conf[2] = h5->tx_win & 0x07; } static void rx_thread(void *p1, void *p2, void *p3) { - ARG_UNUSED(p1); + const struct device *dev = p1; + struct h5_data *h5 = dev->data; + ARG_UNUSED(p2); ARG_UNUSED(p3); @@ -668,42 +689,42 @@ static void rx_thread(void *p1, void *p2, void *p3) while (true) { struct net_buf *buf; - buf = net_buf_get(&h5.rx_queue, K_FOREVER); + buf = net_buf_get(&h5->rx_queue, K_FOREVER); hexdump("=> ", buf->data, buf->len); if (!memcmp(buf->data, sync_req, sizeof(sync_req))) { - if (h5.link_state == ACTIVE) { + if (h5->link_state == ACTIVE) { /* TODO Reset H5 */ } - h5_send(sync_rsp, HCI_3WIRE_LINK_PKT, sizeof(sync_rsp)); + h5_send(dev, sync_rsp, HCI_3WIRE_LINK_PKT, sizeof(sync_rsp)); } else if (!memcmp(buf->data, sync_rsp, sizeof(sync_rsp))) { - if (h5.link_state == ACTIVE) { + if (h5->link_state == ACTIVE) { /* TODO Reset H5 */ } - h5.link_state = INIT; - h5_set_txwin(conf_req); - h5_send(conf_req, HCI_3WIRE_LINK_PKT, sizeof(conf_req)); + h5->link_state = INIT; + h5_set_txwin(h5, conf_req); + h5_send(dev, conf_req, HCI_3WIRE_LINK_PKT, sizeof(conf_req)); } else if (!memcmp(buf->data, conf_req, 2)) { /* * The Host sends Config Response messages without a * Configuration Field. */ - h5_send(conf_rsp, HCI_3WIRE_LINK_PKT, sizeof(conf_rsp)); + h5_send(dev, conf_rsp, HCI_3WIRE_LINK_PKT, sizeof(conf_rsp)); /* Then send Config Request with Configuration Field */ - h5_set_txwin(conf_req); - h5_send(conf_req, HCI_3WIRE_LINK_PKT, sizeof(conf_req)); + h5_set_txwin(h5, conf_req); + h5_send(dev, conf_req, HCI_3WIRE_LINK_PKT, sizeof(conf_req)); } else if (!memcmp(buf->data, conf_rsp, 2)) { - h5.link_state = ACTIVE; + h5->link_state = ACTIVE; if (buf->len > 2) { /* Configuration field present */ - h5.tx_win = (buf->data[2] & 0x07); + h5->tx_win = (buf->data[2] & 0x07); } - LOG_DBG("Finished H5 configuration, tx_win %u", h5.tx_win); + LOG_DBG("Finished H5 configuration, tx_win %u", h5->tx_win); } else { LOG_ERR("Not handled yet %x %x", buf->data[0], buf->data[1]); } @@ -717,74 +738,91 @@ static void rx_thread(void *p1, void *p2, void *p3) } } -static void h5_init(void) +static void h5_init(const struct device *dev) { + const struct h5_config *cfg = dev->config; + struct h5_data *h5 = dev->data; + k_tid_t tid; + LOG_DBG(""); - h5.link_state = UNINIT; - h5.rx_state = START; - h5.tx_win = 4U; + h5->link_state = UNINIT; + h5->rx_state = START; + h5->tx_win = 4U; /* TX thread */ - k_fifo_init(&h5.tx_queue); - k_thread_create(&tx_thread_data, tx_stack, - K_KERNEL_STACK_SIZEOF(tx_stack), - tx_thread, NULL, NULL, NULL, - K_PRIO_COOP(CONFIG_BT_HCI_TX_PRIO), - 0, K_NO_WAIT); - k_thread_name_set(&tx_thread_data, "tx_thread"); - - k_fifo_init(&h5.rx_queue); - k_thread_create(&rx_thread_data, rx_stack, - K_KERNEL_STACK_SIZEOF(rx_stack), - rx_thread, NULL, NULL, NULL, - K_PRIO_COOP(CONFIG_BT_RX_PRIO), - 0, K_NO_WAIT); - k_thread_name_set(&rx_thread_data, "rx_thread"); + k_fifo_init(&h5->tx_queue); + tid = k_thread_create(cfg->tx_thread, cfg->tx_stack, cfg->tx_stack_size, + tx_thread, (void *)dev, NULL, NULL, + K_PRIO_COOP(CONFIG_BT_HCI_TX_PRIO), + 0, K_NO_WAIT); + k_thread_name_set(tid, "tx_thread"); + + k_fifo_init(&h5->rx_queue); + tid = k_thread_create(cfg->rx_thread, cfg->rx_stack, cfg->rx_stack_size, + rx_thread, (void *)dev, NULL, NULL, + K_PRIO_COOP(CONFIG_BT_RX_PRIO), + 0, K_NO_WAIT); + k_thread_name_set(tid, "rx_thread"); /* Unack queue */ - k_fifo_init(&h5.unack_queue); + k_fifo_init(&h5->unack_queue); /* Init delayed work */ - k_work_init_delayable(&ack_work, ack_timeout); - k_work_init_delayable(&retx_work, retx_timeout); + k_work_init_delayable(&h5->ack_work, ack_timeout); + k_work_init_delayable(&h5->retx_work, retx_timeout); } -static int h5_open(void) +static int h5_open(const struct device *dev, bt_hci_recv_t recv) { + const struct h5_config *cfg = dev->config; + struct h5_data *h5 = dev->data; + LOG_DBG(""); - uart_irq_rx_disable(h5_dev); - uart_irq_tx_disable(h5_dev); + /* This is needed so that we can access the device struct from within the + * delayed work callbacks. + */ + h5->dev = dev; - bt_uart_drain(h5_dev); + h5->recv = recv; - uart_irq_callback_set(h5_dev, bt_uart_isr); + uart_irq_rx_disable(cfg->uart); + uart_irq_tx_disable(cfg->uart); - h5_init(); + bt_uart_drain(cfg->uart); - uart_irq_rx_enable(h5_dev); + uart_irq_callback_user_data_set(cfg->uart, bt_uart_isr, (void *)dev); - return 0; -} + h5_init(dev); -static const struct bt_hci_driver drv = { - .name = "H:5", - .bus = BT_HCI_DRIVER_BUS_UART, - .open = h5_open, - .send = h5_queue, -}; - -static int bt_uart_init(void) -{ - - if (!device_is_ready(h5_dev)) { - return -ENODEV; - } - - bt_hci_driver_register(&drv); + uart_irq_rx_enable(cfg->uart); return 0; } -SYS_INIT(bt_uart_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); +static const struct bt_hci_driver_api h5_driver_api = { + .open = h5_open, + .send = h5_queue, +}; + +#define BT_UART_DEVICE_INIT(inst) \ + static K_KERNEL_STACK_DEFINE(rx_thread_stack_##inst, CONFIG_BT_DRV_RX_STACK_SIZE); \ + static struct k_thread rx_thread_##inst; \ + static K_KERNEL_STACK_DEFINE(tx_thread_stack_##inst, CONFIG_BT_DRV_TX_STACK_SIZE); \ + static struct k_thread tx_thread_##inst; \ + static const struct h5_config h5_config_##inst = { \ + .uart = DEVICE_DT_GET(DT_INST_PARENT(inst)), \ + .rx_stack = rx_thread_stack_##inst, \ + .rx_stack_size = K_KERNEL_STACK_SIZEOF(rx_thread_stack_##inst), \ + .rx_thread = &rx_thread_##inst, \ + .tx_stack = tx_thread_stack_##inst, \ + .tx_stack_size = K_KERNEL_STACK_SIZEOF(tx_thread_stack_##inst), \ + .tx_thread = &tx_thread_##inst, \ + }; \ + static struct h5_data h5_##inst; \ + DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &h5_##inst, &h5_config_##inst, \ + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &h5_driver_api) + + +DT_INST_FOREACH_STATUS_OKAY(BT_UART_DEVICE_INIT) diff --git a/drivers/bluetooth/hci/hci_ambiq.c b/drivers/bluetooth/hci/hci_ambiq.c index daaf943dca557..34a2360a2c21f 100644 --- a/drivers/bluetooth/hci/hci_ambiq.c +++ b/drivers/bluetooth/hci/hci_ambiq.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL @@ -72,6 +72,10 @@ static const struct spi_buf_set spi_rx = {.buffers = &spi_rx_buf, .count = 1}; static K_SEM_DEFINE(sem_irq, 0, 1); static K_SEM_DEFINE(sem_spi_available, 1, 1); +struct bt_apollo_data { + bt_hci_recv_t recv; +}; + void bt_packet_irq_isr(const struct device *unused1, struct gpio_callback *unused2, uint32_t unused3) { @@ -288,7 +292,9 @@ static struct net_buf *bt_hci_acl_recv(uint8_t *data, size_t len) static void bt_spi_rx_thread(void *p1, void *p2, void *p3) { - ARG_UNUSED(p1); + const struct device *dev = p1; + struct bt_apollo_data *hci = dev->data; + ARG_UNUSED(p2); ARG_UNUSED(p3); @@ -331,13 +337,13 @@ static void bt_spi_rx_thread(void *p1, void *p2, void *p3) /* Post the RX message to host stack to process */ if (buf) { - bt_recv(buf); + hci->recv(dev, buf); } } while (0); } } -static int bt_hci_send(struct net_buf *buf) +static int bt_apollo_send(const struct device *dev, struct net_buf *buf) { int ret = 0; @@ -368,8 +374,9 @@ static int bt_hci_send(struct net_buf *buf) return ret; } -static int bt_hci_open(void) +static int bt_apollo_open(const struct device *dev, bt_hci_recv_t recv) { + struct bt_apollo_data *hci = dev->data; int ret; ret = bt_hci_transport_setup(spi_dev); @@ -379,15 +386,18 @@ static int bt_hci_open(void) /* Start RX thread */ k_thread_create(&spi_rx_thread_data, spi_rx_stack, K_KERNEL_STACK_SIZEOF(spi_rx_stack), - (k_thread_entry_t)bt_spi_rx_thread, NULL, NULL, NULL, + (k_thread_entry_t)bt_spi_rx_thread, (void *)dev, NULL, NULL, K_PRIO_COOP(CONFIG_BT_DRIVER_RX_HIGH_PRIO), 0, K_NO_WAIT); ret = bt_apollo_controller_init(spi_send_packet); + if (ret == 0) { + hci->recv = recv; + } return ret; } -static int bt_spi_setup(const struct bt_hci_setup_params *params) +static int bt_apollo_setup(const struct device *dev, const struct bt_hci_setup_params *params) { ARG_UNUSED(params); @@ -398,18 +408,18 @@ static int bt_spi_setup(const struct bt_hci_setup_params *params) return ret; } -static const struct bt_hci_driver drv = { - .name = "ambiq hci", - .bus = BT_HCI_DRIVER_BUS_SPI, - .open = bt_hci_open, - .send = bt_hci_send, - .setup = bt_spi_setup, +static const struct bt_hci_driver_api drv = { + .open = bt_apollo_open, + .send = bt_apollo_send, + .setup = bt_apollo_setup, }; -static int bt_hci_init(void) +static int bt_apollo_init(const struct device *dev) { int ret; + ARG_UNUSED(dev); + if (!device_is_ready(spi_dev)) { LOG_ERR("SPI device not ready"); return -ENODEV; @@ -420,11 +430,16 @@ static int bt_hci_init(void) return ret; } - bt_hci_driver_register(&drv); - LOG_DBG("BT HCI initialized"); return 0; } -SYS_INIT(bt_hci_init, POST_KERNEL, CONFIG_BT_HCI_INIT_PRIORITY); +#define HCI_DEVICE_INIT(inst) \ + static struct bt_apollo_data hci_data_##inst = { \ + }; \ + DEVICE_DT_INST_DEFINE(inst, bt_apollo_init, NULL, &hci_data_##inst, NULL, \ + POST_KERNEL, CONFIG_BT_HCI_INIT_PRIORITY, &drv) + +/* Only one instance supported right now */ +HCI_DEVICE_INIT(0) diff --git a/drivers/bluetooth/hci/hci_da1469x.c b/drivers/bluetooth/hci/hci_da1469x.c index c97b83f3b35cf..18733d8444cdb 100644 --- a/drivers/bluetooth/hci/hci_da1469x.c +++ b/drivers/bluetooth/hci/hci_da1469x.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include @@ -26,6 +26,12 @@ LOG_MODULE_REGISTER(hci_da1469x); +#define DT_DRV_COMPAT renesas_bt_hci_da1469x + +struct hci_data { + bt_hci_recv_t recv; +}; + static K_KERNEL_STACK_DEFINE(rng_thread_stack, CONFIG_BT_RX_STACK_SIZE); static struct k_thread rng_thread_data; struct k_sem rng_sem; @@ -205,9 +211,10 @@ static void rx_isr_stop(void) static void rx_thread(void *p1, void *p2, void *p3) { + const struct device *dev = p1; + struct hci_data *hci = dev->data; struct net_buf *buf; - ARG_UNUSED(p1); ARG_UNUSED(p2); ARG_UNUSED(p3); @@ -240,7 +247,7 @@ static void rx_thread(void *p1, void *p2, void *p3) rx_isr_start(); LOG_DBG("Calling bt_recv(%p)", buf); - bt_recv(buf); + hci->recv(dev, buf); /* Give other threads a chance to run if the ISR * is receiving data so fast that rx.fifo never @@ -420,13 +427,14 @@ static void rng_thread(void *p1, void *p2, void *p3) } } -static int bt_da1469x_open(void) +static int bt_da1469x_open(const struct device *dev, bt_hci_recv_t recv) { + struct hci_data *hci = dev->data; k_tid_t tid; tid = k_thread_create(&rx_thread_data, rx_thread_stack, K_KERNEL_STACK_SIZEOF(rx_thread_stack), - rx_thread, NULL, NULL, NULL, + rx_thread, (void *)dev, NULL, NULL, K_PRIO_COOP(CONFIG_BT_RX_PRIO), 0, K_NO_WAIT); k_thread_name_set(tid, "bt_rx_thread"); @@ -440,6 +448,8 @@ static int bt_da1469x_open(void) 0, K_NO_WAIT); k_thread_name_set(tid, "bt_rng_thread"); + hci->recv = recv; + cmac_enable(); irq_enable(CMAC2SYS_IRQn); @@ -447,17 +457,23 @@ static int bt_da1469x_open(void) } #ifdef CONFIG_BT_HCI_HOST -static int bt_da1469x_close(void) +static int bt_da1469x_close(const struct device *dev) { + struct hci_data *hci = dev->data; + irq_disable(CMAC2SYS_IRQn); cmac_disable(); + hci->recv = NULL; + return 0; } #endif /* CONFIG_BT_HCI_HOST */ -static int bt_da1469x_send(struct net_buf *buf) +static int bt_da1469x_send(const struct device *dev, struct net_buf *buf) { + ARG_UNUSED(dev); + switch (bt_buf_get_type(buf)) { case BT_BUF_ACL_OUT: LOG_DBG("ACL: buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len); @@ -479,20 +495,16 @@ static int bt_da1469x_send(struct net_buf *buf) return 0; } -static const struct bt_hci_driver drv = { - .name = "BT DA1469x", - .bus = BT_HCI_DRIVER_BUS_IPM, +static const struct bt_hci_driver_api drv = { .open = bt_da1469x_open, .close = bt_da1469x_close, .send = bt_da1469x_send, }; -static int bt_da1469x_init(void) +static int bt_da1469x_init(const struct device *dev) { irq_disable(CMAC2SYS_IRQn); - bt_hci_driver_register(&drv); - cmac_disable(); cmac_load_image(); cmac_configure_pdc(); @@ -503,4 +515,11 @@ static int bt_da1469x_init(void) return 0; } -SYS_INIT(bt_da1469x_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); +#define HCI_DEVICE_INIT(inst) \ + static struct hci_data hci_data_##inst = { \ + }; \ + DEVICE_DT_INST_DEFINE(inst, bt_da1469x_init, NULL, &hci_data_##inst, NULL, \ + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &drv) + +/* Only one instance supported right now */ +HCI_DEVICE_INIT(0) diff --git a/drivers/bluetooth/hci/hci_esp32.c b/drivers/bluetooth/hci/hci_esp32.c index 311dddf916c32..7536e9f7622e9 100644 --- a/drivers/bluetooth/hci/hci_esp32.c +++ b/drivers/bluetooth/hci/hci_esp32.c @@ -9,7 +9,7 @@ #include #include -#include +#include #include @@ -17,8 +17,14 @@ #include LOG_MODULE_REGISTER(bt_hci_driver_esp32); +#define DT_DRV_COMPAT espressif_esp32_bt_hci + #define HCI_BT_ESP32_TIMEOUT K_MSEC(2000) +struct bt_esp32_data { + bt_hci_recv_t recv; +}; + static K_SEM_DEFINE(hci_send_sem, 1, 1); static bool is_hci_event_discardable(const uint8_t *evt_data) @@ -180,6 +186,8 @@ static struct net_buf *bt_esp_iso_recv(uint8_t *data, size_t remaining) static int hci_esp_host_rcv_pkt(uint8_t *data, uint16_t len) { + const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0)); + struct bt_esp32_data *hci = dev->data; uint8_t pkt_indicator; struct net_buf *buf = NULL; size_t remaining = len; @@ -210,7 +218,7 @@ static int hci_esp_host_rcv_pkt(uint8_t *data, uint16_t len) if (buf) { LOG_DBG("Calling bt_recv(%p)", buf); - bt_recv(buf); + hci->recv(dev, buf); } return 0; @@ -226,7 +234,7 @@ static esp_vhci_host_callback_t vhci_host_cb = { hci_esp_host_rcv_pkt }; -static int bt_esp32_send(struct net_buf *buf) +static int bt_esp32_send(const struct device *dev, struct net_buf *buf) { int err = 0; uint8_t pkt_indicator; @@ -316,8 +324,9 @@ static int bt_esp32_ble_deinit(void) return 0; } -static int bt_esp32_open(void) +static int bt_esp32_open(const struct device *dev, bt_hci_recv_t recv) { + struct bt_esp32_data *hci = dev->data; int err; err = bt_esp32_ble_init(); @@ -325,13 +334,16 @@ static int bt_esp32_open(void) return err; } + hci->recv = recv; + LOG_DBG("ESP32 BT started"); return 0; } -static int bt_esp32_close(void) +static int bt_esp32_close(const struct device *dev) { + struct bt_esp32_data *hci = dev->data; int err; err = bt_esp32_ble_deinit(); @@ -339,27 +351,24 @@ static int bt_esp32_close(void) return err; } + hci->recv = NULL; + LOG_DBG("ESP32 BT stopped"); return 0; } -static const struct bt_hci_driver drv = { - .name = "BT ESP32", +static const struct bt_hci_driver_api drv = { .open = bt_esp32_open, .send = bt_esp32_send, .close = bt_esp32_close, - .bus = BT_HCI_DRIVER_BUS_IPM, -#if defined(CONFIG_BT_DRIVER_QUIRK_NO_AUTO_DLE) - .quirks = BT_QUIRK_NO_AUTO_DLE, -#endif }; -static int bt_esp32_init(void) -{ - bt_hci_driver_register(&drv); - - return 0; -} +#define BT_ESP32_DEVICE_INIT(inst) \ + static struct bt_esp32_data bt_esp32_data_##inst = { \ + }; \ + DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &bt_esp32_data_##inst, NULL, \ + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &drv) -SYS_INIT(bt_esp32_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); +/* Only one instance supported */ +BT_ESP32_DEVICE_INIT(0) diff --git a/drivers/bluetooth/hci/hci_nxp.c b/drivers/bluetooth/hci/hci_nxp.c index 293ba3cfff1ee..ff9d9628c1607 100644 --- a/drivers/bluetooth/hci/hci_nxp.c +++ b/drivers/bluetooth/hci/hci_nxp.c @@ -9,7 +9,7 @@ /* -------------------------------------------------------------------------- */ #include -#include +#include #include #include #include @@ -26,6 +26,10 @@ #define DT_DRV_COMPAT nxp_hci_ble +struct bt_nxp_data { + bt_hci_recv_t recv; +}; + #define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL LOG_MODULE_REGISTER(bt_driver); @@ -244,6 +248,8 @@ static struct net_buf *bt_acl_recv(uint8_t *data, size_t len) static void hci_rx_cb(uint8_t packetType, uint8_t *data, uint16_t len) { + const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0)); + struct bt_nxp_data *hci = dev->data; struct net_buf *buf; switch (packetType) { @@ -262,14 +268,16 @@ static void hci_rx_cb(uint8_t packetType, uint8_t *data, uint16_t len) if (buf) { /* Provide the buffer to the host */ - bt_recv(buf); + hci->recv(dev, buf); } } -static int bt_nxp_send(struct net_buf *buf) +static int bt_nxp_send(const struct device *dev, struct net_buf *buf) { uint8_t packetType; + ARG_UNUSED(dev); + switch (bt_buf_get_type(buf)) { case BT_BUF_CMD: packetType = BT_HCI_H4_CMD; @@ -290,8 +298,9 @@ static int bt_nxp_send(struct net_buf *buf) return 0; } -static int bt_nxp_open(void) +static int bt_nxp_open(const struct device *dev, bt_hci_recv_t recv) { + struct bt_nxp_data *hci = dev->data; int ret = 0; do { @@ -312,13 +321,16 @@ static int bt_nxp_open(void) LOG_ERR("HCI open failed"); break; } + + hci->recv = recv; } while (false); return ret; } -int bt_nxp_setup(const struct bt_hci_setup_params *params) +int bt_nxp_setup(const struct device *dev, const struct bt_hci_setup_params *params) { + ARG_UNUSED(dev); ARG_UNUSED(params); int ret; @@ -362,8 +374,9 @@ int bt_nxp_setup(const struct bt_hci_setup_params *params) return ret; } -static int bt_nxp_close(void) +static int bt_nxp_close(const struct device *dev) { + struct bt_nxp_data *hci = dev->data; int ret = 0; /* Reset the Controller */ #if CONFIG_BT_HCI_HOST @@ -378,23 +391,25 @@ static int bt_nxp_close(void) LOG_ERR("Failed to shutdown BLE controller"); } #endif + hci->recv = NULL; + return ret; } -static const struct bt_hci_driver drv = { - .name = "BT NXP", +static const struct bt_hci_driver_api drv = { .open = bt_nxp_open, .setup = bt_nxp_setup, .close = bt_nxp_close, .send = bt_nxp_send, - .bus = BT_HCI_DRIVER_BUS_IPM, }; -static int bt_nxp_init(void) +static int bt_nxp_init(const struct device *dev) { int status; int ret = 0; + ARG_UNUSED(dev); + /* HCI Interrupt */ IRQ_CONNECT(HCI_IRQ_N, HCI_IRQ_P, ble_hci_handler, 0, 0); irq_enable(HCI_IRQ_N); @@ -414,16 +429,16 @@ static int bt_nxp_init(void) ret = status; break; } - - status = bt_hci_driver_register(&drv); - if (status < 0) { - LOG_ERR("HCI driver registration failed"); - ret = status; - break; - } } while (0); return ret; } -SYS_INIT(bt_nxp_init, POST_KERNEL, CONFIG_BT_HCI_INIT_PRIORITY); +#define HCI_DEVICE_INIT(inst) \ + static struct bt_nxp_data hci_data_##inst = { \ + }; \ + DEVICE_DT_INST_DEFINE(inst, bt_nxp_init, NULL, &hci_data_##inst, NULL, \ + POST_KERNEL, CONFIG_BT_HCI_INIT_PRIORITY, &drv) + +/* Only one instance supported right now */ +HCI_DEVICE_INIT(0) diff --git a/drivers/bluetooth/hci/hci_psoc6_bless.c b/drivers/bluetooth/hci/hci_psoc6_bless.c index af6804f2f1759..5f4d1fdd13ddd 100644 --- a/drivers/bluetooth/hci/hci_psoc6_bless.c +++ b/drivers/bluetooth/hci/hci_psoc6_bless.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include @@ -32,6 +32,10 @@ LOG_MODULE_REGISTER(psoc6_bless); #define DT_DRV_COMPAT infineon_cat1_bless_hci +struct psoc6_bless_data { + bt_hci_recv_t recv; +}; + #define BLE_LOCK_TMOUT_MS (1000) #define BLE_THREAD_SEM_TMOUT_MS (1000) @@ -94,6 +98,8 @@ static void psoc6_bless_isr_handler(const struct device *dev) static void psoc6_bless_events_handler(uint32_t eventCode, void *eventParam) { + const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0)); + struct psoc6_bless_data *hci = dev->data; cy_stc_ble_hci_tx_packet_info_t *hci_rx = NULL; struct net_buf *buf = NULL; size_t buf_tailroom = 0; @@ -135,13 +141,16 @@ static void psoc6_bless_events_handler(uint32_t eventCode, void *eventParam) return; } net_buf_add_mem(buf, hci_rx->data, hci_rx->dataLength); - bt_recv(buf); + hci->recv(dev, buf); } -static int psoc6_bless_open(void) +static int psoc6_bless_open(const struct device *dev, bt_hci_recv_t recv) { + struct psoc6_bless_data *hci = dev->data; k_tid_t tid; + hci->recv = recv; + tid = k_thread_create(&psoc6_bless_rx_thread_data, psoc6_bless_rx_thread_stack, K_KERNEL_STACK_SIZEOF(psoc6_bless_rx_thread_stack), psoc6_bless_rx_thread, NULL, NULL, NULL, @@ -151,10 +160,12 @@ static int psoc6_bless_open(void) return 0; } -static int psoc6_bless_send(struct net_buf *buf) +static int psoc6_bless_send(const struct device *dev, struct net_buf *buf) { cy_en_ble_api_result_t result; + ARG_UNUSED(dev); + memset(&hci_tx_pkt, 0, sizeof(cy_stc_ble_hci_tx_packet_info_t)); hci_tx_pkt.dataLength = buf->len; @@ -190,8 +201,9 @@ static int psoc6_bless_send(struct net_buf *buf) return 0; } -static int psoc6_bless_setup(const struct bt_hci_setup_params *params) +static int psoc6_bless_setup(const struct device *dev, const struct bt_hci_setup_params *params) { + ARG_UNUSED(dev); ARG_UNUSED(params); struct net_buf *buf; int err; @@ -217,17 +229,11 @@ static int psoc6_bless_setup(const struct bt_hci_setup_params *params) return 0; } -static int psoc6_bless_hci_init(void) +static int psoc6_bless_hci_init(const struct device *dev) { cy_en_ble_api_result_t result; - static const struct bt_hci_driver drv = { - .name = "PSoC 6 BLESS", - .bus = BT_HCI_DRIVER_BUS_VIRTUAL, - .quirks = BT_QUIRK_NO_RESET, - .open = psoc6_bless_open, - .send = psoc6_bless_send, - .setup = psoc6_bless_setup, - }; + + ARG_UNUSED(dev); /* Connect BLE interrupt to ISR */ IRQ_CONNECT(DT_INST_IRQN(0), DT_INST_IRQ(0, priority), psoc6_bless_isr_handler, 0, 0); @@ -252,10 +258,20 @@ static int psoc6_bless_hci_init(void) /* Enables BLE Low-power mode (LPM)*/ Cy_BLE_EnableLowPowerMode(); - /* Register a BLESS HCI driver to the Bluetooth stack. */ - bt_hci_driver_register(&drv); - return 0; } -SYS_INIT(psoc6_bless_hci_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); +static const struct bt_hci_driver_api drv = { + .open = psoc6_bless_open, + .send = psoc6_bless_send, + .setup = psoc6_bless_setup, +}; + +#define PSOC6_BLESS_DEVICE_INIT(inst) \ + static struct psoc6_bless_data psoc6_bless_data_##inst = { \ + }; \ + DEVICE_DT_INST_DEFINE(inst, psoc6_bless_hci_init, NULL, &psoc6_bless_data_##inst, NULL, \ + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &drv) + +/* Only one instance supported */ +PSOC6_BLESS_DEVICE_INIT(0) diff --git a/drivers/bluetooth/hci/hci_spi_st.c b/drivers/bluetooth/hci/hci_spi_st.c index d4b964ba21c68..fcfe2f4b75024 100644 --- a/drivers/bluetooth/hci/hci_spi_st.c +++ b/drivers/bluetooth/hci/hci_spi_st.c @@ -22,7 +22,7 @@ #include #include -#include +#include #include #define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL @@ -90,6 +90,10 @@ static struct k_thread spi_rx_thread_data; #define BLUENRG_CONFIG_LL_ONLY_OFFSET 0x2C #define BLUENRG_CONFIG_LL_ONLY_LEN 0x01 +struct bt_spi_data { + bt_hci_recv_t recv; +}; + static const struct spi_dt_spec bus = SPI_DT_SPEC_INST_GET( 0, SPI_OP_MODE_MASTER | SPI_TRANSFER_MSB | SPI_WORD_SET(8) | SPI_LOCK_ON, 0); @@ -351,7 +355,8 @@ static int bt_spi_send_aci_config(uint8_t offset, const uint8_t *value, size_t v } #if !defined(CONFIG_BT_HCI_RAW) -static int bt_spi_bluenrg_setup(const struct bt_hci_setup_params *params) +static int bt_spi_bluenrg_setup(const struct device *dev, + const struct bt_hci_setup_params *params) { int ret; const bt_addr_t *addr = ¶ms->public_addr; @@ -496,7 +501,9 @@ static int bt_spi_rx_buf_construct(uint8_t *msg, struct net_buf **bufp, uint16_t static void bt_spi_rx_thread(void *p1, void *p2, void *p3) { - ARG_UNUSED(p1); + const struct device *dev = p1; + struct bt_spi_data *hci = dev->data; + ARG_UNUSED(p2); ARG_UNUSED(p3); @@ -539,14 +546,14 @@ static void bt_spi_rx_thread(void *p1, void *p2, void *p3) ret = bt_spi_rx_buf_construct(rxmsg, &buf, size); if (!ret) { /* Handle the received HCI data */ - bt_recv(buf); + hci->recv(dev, buf); buf = NULL; } } while (READ_CONDITION); } } -static int bt_spi_send(struct net_buf *buf) +static int bt_spi_send(const struct device *dev, struct net_buf *buf) { uint16_t size; uint8_t rx_first[1]; @@ -632,8 +639,9 @@ static int bt_spi_send(struct net_buf *buf) return ret; } -static int bt_spi_open(void) +static int bt_spi_open(const struct device *dev, bt_hci_recv_t recv) { + struct bt_spi_data *hci = dev->data; int err; /* Configure RST pin and hold BLE in Reset */ @@ -660,6 +668,8 @@ static int bt_spi_open(void) return err; } + hci->recv = recv; + /* Take BLE out of reset */ k_sleep(K_MSEC(DT_INST_PROP_OR(0, reset_assert_duration_ms, 0))); gpio_pin_set_dt(&rst_gpio, 0); @@ -667,7 +677,7 @@ static int bt_spi_open(void) /* Start RX thread */ k_thread_create(&spi_rx_thread_data, spi_rx_stack, K_KERNEL_STACK_SIZEOF(spi_rx_stack), - bt_spi_rx_thread, NULL, NULL, NULL, + bt_spi_rx_thread, (void *)dev, NULL, NULL, K_PRIO_COOP(CONFIG_BT_DRIVER_RX_HIGH_PRIO), 0, K_NO_WAIT); @@ -683,10 +693,7 @@ static int bt_spi_open(void) return 0; } -static const struct bt_hci_driver drv = { - .name = DEVICE_DT_NAME(DT_DRV_INST(0)), - .bus = BT_HCI_DRIVER_BUS_SPI, - .quirks = BT_QUIRK_NO_RESET, +static const struct bt_hci_driver_api drv = { #if defined(CONFIG_BT_BLUENRG_ACI) && !defined(CONFIG_BT_HCI_RAW) .setup = bt_spi_bluenrg_setup, #endif /* CONFIG_BT_BLUENRG_ACI && !CONFIG_BT_HCI_RAW */ @@ -694,7 +701,7 @@ static const struct bt_hci_driver drv = { .send = bt_spi_send, }; -static int bt_spi_init(void) +static int bt_spi_init(const struct device *dev) { if (!spi_is_ready_dt(&bus)) { @@ -712,12 +719,16 @@ static int bt_spi_init(void) return -ENODEV; } - bt_hci_driver_register(&drv); - - LOG_DBG("BT SPI initialized"); return 0; } -SYS_INIT(bt_spi_init, POST_KERNEL, CONFIG_BT_SPI_INIT_PRIORITY); +#define HCI_DEVICE_INIT(inst) \ + static struct bt_spi_data hci_data_##inst = { \ + }; \ + DEVICE_DT_INST_DEFINE(inst, bt_spi_init, NULL, &hci_data_##inst, NULL, \ + POST_KERNEL, CONFIG_BT_SPI_INIT_PRIORITY, &drv) + +/* Only one instance supported right now */ +HCI_DEVICE_INIT(0) diff --git a/drivers/bluetooth/hci/hci_stm32wba.c b/drivers/bluetooth/hci/hci_stm32wba.c index 4e29edbf26ccf..34e2385b2414d 100644 --- a/drivers/bluetooth/hci/hci_stm32wba.c +++ b/drivers/bluetooth/hci/hci_stm32wba.c @@ -7,11 +7,10 @@ * SPDX-License-Identifier: Apache-2.0 */ - #include #include #include -#include +#include #include #include #include @@ -27,6 +26,12 @@ #include LOG_MODULE_REGISTER(hci_wba); +#define DT_DRV_COMPAT st_hci_stm32wba + +struct hci_data { + bt_hci_recv_t recv; +}; + static K_SEM_DEFINE(hci_sem, 1, 1); #define BLE_CTRLR_STACK_BUFFER_SIZE 300 @@ -212,9 +217,10 @@ static struct net_buf *treat_iso(const uint8_t *data, size_t len, return buf; } -static int receive_data(const uint8_t *data, size_t len, +static int receive_data(const struct device *dev, const uint8_t *data, size_t len, const uint8_t *ext_data, size_t ext_len) { + struct hci_data *hci = dev->data; uint8_t pkt_indicator; struct net_buf *buf; int err = 0; @@ -242,7 +248,7 @@ static int receive_data(const uint8_t *data, size_t len, } if (buf) { - bt_recv(buf); + hci->recv(dev, buf); } else { err = -ENOMEM; ll_state_busy = 1; @@ -254,6 +260,7 @@ static int receive_data(const uint8_t *data, size_t len, uint8_t BLECB_Indication(const uint8_t *data, uint16_t length, const uint8_t *ext_data, uint16_t ext_length) { + const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0)); int ret = 0; int err; @@ -264,7 +271,7 @@ uint8_t BLECB_Indication(const uint8_t *data, uint16_t length, k_sem_take(&hci_sem, K_FOREVER); - err = receive_data(data, (size_t)length - 1, + err = receive_data(dev, data, (size_t)length - 1, ext_data, (size_t)ext_length); k_sem_give(&hci_sem); @@ -278,12 +285,14 @@ uint8_t BLECB_Indication(const uint8_t *data, uint16_t length, return ret; } -static int bt_hci_stm32wba_send(struct net_buf *buf) +static int bt_hci_stm32wba_send(const struct device *dev, struct net_buf *buf) { uint16_t event_length; uint8_t pkt_indicator; uint8_t tx_buffer[BLE_CTRLR_STACK_BUFFER_SIZE]; + ARG_UNUSED(dev); + k_sem_take(&hci_sem, K_FOREVER); LOG_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len); @@ -311,7 +320,7 @@ static int bt_hci_stm32wba_send(struct net_buf *buf) LOG_DBG("event_length: %u", event_length); if (event_length) { - receive_data((uint8_t *)&tx_buffer, (size_t)event_length, NULL, 0); + receive_data(dev, (uint8_t *)&tx_buffer, (size_t)event_length, NULL, 0); } k_sem_give(&hci_sem); @@ -349,8 +358,9 @@ static int bt_ble_ctlr_init(void) return 0; } -static int bt_hci_stm32wba_open(void) +static int bt_hci_stm32wba_open(const struct device *dev, bt_hci_recv_t recv) { + struct hci_data *data = dev->data; int ret = 0; link_layer_register_isr(); @@ -358,6 +368,9 @@ static int bt_hci_stm32wba_open(void) ll_sys_config_params(); ret = bt_ble_ctlr_init(); + if (ret == 0) { + data->recv = recv; + } /* TODO. Enable Flash manager once available */ if (IS_ENABLED(CONFIG_FLASH)) { @@ -367,18 +380,16 @@ static int bt_hci_stm32wba_open(void) return ret; } -static const struct bt_hci_driver drv = { - .name = "BT IPM", - .bus = BT_HCI_DRIVER_BUS_IPM, +static const struct bt_hci_driver_api drv = { .open = bt_hci_stm32wba_open, .send = bt_hci_stm32wba_send, }; -static int bt_stm32wba_hci_init(void) -{ - bt_hci_driver_register(&drv); - - return 0; -} +#define HCI_DEVICE_INIT(inst) \ + static struct hci_data hci_data_##inst = { \ + }; \ + DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &hci_data_##inst, NULL, \ + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &drv) -SYS_INIT(bt_stm32wba_hci_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); +/* Only one instance supported */ +HCI_DEVICE_INIT(0) diff --git a/drivers/bluetooth/hci/ipc.c b/drivers/bluetooth/hci/ipc.c index 54a8556d1384a..9d63d12ec3286 100644 --- a/drivers/bluetooth/hci/ipc.c +++ b/drivers/bluetooth/hci/ipc.c @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include @@ -18,10 +18,17 @@ #include LOG_MODULE_REGISTER(bt_hci_driver); +#define DT_DRV_COMPAT zephyr_bt_hci_ipc + #define IPC_BOUND_TIMEOUT_IN_MS K_MSEC(1000) -static struct ipc_ept hci_ept; -static K_SEM_DEFINE(ipc_bound_sem, 0, 1); +struct ipc_data { + bt_hci_recv_t recv; + struct ipc_ept hci_ept; + struct ipc_ept_cfg hci_ept_cfg; + struct k_sem bound_sem; + const struct device *ipc; +}; static bool is_hci_event_discardable(const uint8_t *evt_data) { @@ -200,8 +207,9 @@ static struct net_buf *bt_ipc_iso_recv(const uint8_t *data, size_t remaining) return buf; } -static void bt_ipc_rx(const uint8_t *data, size_t len) +static void bt_ipc_rx(const struct device *dev, const uint8_t *data, size_t len) { + struct ipc_data *ipc = dev->data; uint8_t pkt_indicator; struct net_buf *buf = NULL; size_t remaining = len; @@ -231,14 +239,15 @@ static void bt_ipc_rx(const uint8_t *data, size_t len) if (buf) { LOG_DBG("Calling bt_recv(%p)", buf); - bt_recv(buf); + ipc->recv(dev, buf); LOG_HEXDUMP_DBG(buf->data, buf->len, "RX buf payload:"); } } -static int bt_ipc_send(struct net_buf *buf) +static int bt_ipc_send(const struct device *dev, struct net_buf *buf) { + struct ipc_data *data = dev->data; int err; uint8_t pkt_indicator; @@ -261,7 +270,7 @@ static int bt_ipc_send(struct net_buf *buf) net_buf_push_u8(buf, pkt_indicator); LOG_HEXDUMP_DBG(buf->data, buf->len, "Final HCI buffer:"); - err = ipc_service_send(&hci_ept, buf->data, buf->len); + err = ipc_service_send(&data->hci_ept, buf->data, buf->len); if (err < 0) { LOG_ERR("Failed to send (err %d)", err); } @@ -273,21 +282,18 @@ static int bt_ipc_send(struct net_buf *buf) static void hci_ept_bound(void *priv) { - k_sem_give(&ipc_bound_sem); + const struct device *dev = priv; + struct ipc_data *ipc = dev->data; + + k_sem_give(&ipc->bound_sem); } static void hci_ept_recv(const void *data, size_t len, void *priv) { - bt_ipc_rx(data, len); -} + const struct device *dev = priv; -static struct ipc_ept_cfg hci_ept_cfg = { - .name = "nrf_bt_hci", - .cb = { - .bound = hci_ept_bound, - .received = hci_ept_recv, - }, -}; + bt_ipc_rx(dev, data, len); +} int __weak bt_hci_transport_setup(const struct device *dev) { @@ -301,13 +307,11 @@ int __weak bt_hci_transport_teardown(const struct device *dev) return 0; } -static int bt_ipc_open(void) +static int bt_ipc_open(const struct device *dev, bt_hci_recv_t recv) { + struct ipc_data *ipc = dev->data; int err; - const struct device *hci_ipc_instance = - DEVICE_DT_GET(DT_CHOSEN(zephyr_bt_hci_ipc)); - err = bt_hci_transport_setup(NULL); if (err) { LOG_ERR("HCI transport setup failed with: %d\n", err); @@ -316,29 +320,32 @@ static int bt_ipc_open(void) LOG_DBG(""); - err = ipc_service_open_instance(hci_ipc_instance); + err = ipc_service_open_instance(ipc->ipc); if (err && (err != -EALREADY)) { LOG_ERR("IPC service instance initialization failed: %d\n", err); return err; } - err = ipc_service_register_endpoint(hci_ipc_instance, &hci_ept, &hci_ept_cfg); + err = ipc_service_register_endpoint(ipc->ipc, &ipc->hci_ept, &ipc->hci_ept_cfg); if (err) { LOG_ERR("Registering endpoint failed with %d", err); return err; } - err = k_sem_take(&ipc_bound_sem, IPC_BOUND_TIMEOUT_IN_MS); + err = k_sem_take(&ipc->bound_sem, IPC_BOUND_TIMEOUT_IN_MS); if (err) { LOG_ERR("Endpoint binding failed with %d", err); return err; } + ipc->recv = recv; + return 0; } -static int bt_ipc_close(void) +static int bt_ipc_close(const struct device *dev) { + struct ipc_data *ipc = dev->data; int err; if (IS_ENABLED(CONFIG_BT_HCI_HOST)) { @@ -349,16 +356,13 @@ static int bt_ipc_close(void) } } - err = ipc_service_deregister_endpoint(&hci_ept); + err = ipc_service_deregister_endpoint(&ipc->hci_ept); if (err) { LOG_ERR("Deregistering HCI endpoint failed with: %d", err); return err; } - const struct device *hci_ipc_instance = - DEVICE_DT_GET(DT_CHOSEN(zephyr_bt_hci_ipc)); - - err = ipc_service_close_instance(hci_ipc_instance); + err = ipc_service_close_instance(ipc->ipc); if (err) { LOG_ERR("Closing IPC service failed with: %d", err); return err; @@ -370,31 +374,31 @@ static int bt_ipc_close(void) return err; } + ipc->recv = NULL; + return 0; } -static const struct bt_hci_driver drv = { - .name = "IPC", +static const struct bt_hci_driver_api drv = { .open = bt_ipc_open, .close = bt_ipc_close, .send = bt_ipc_send, - .bus = BT_HCI_DRIVER_BUS_IPM, -#if defined(CONFIG_BT_DRIVER_QUIRK_NO_AUTO_DLE) - .quirks = BT_QUIRK_NO_AUTO_DLE, -#endif }; -static int bt_ipc_init(void) -{ - - int err; - - err = bt_hci_driver_register(&drv); - if (err < 0) { - LOG_ERR("Failed to register BT HIC driver (err %d)", err); - } - - return err; -} - -SYS_INIT(bt_ipc_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); +#define IPC_DEVICE_INIT(inst) \ + static struct ipc_data ipc_data_##inst = { \ + .bound_sem = Z_SEM_INITIALIZER(ipc_data_##inst.bound_sem, 0, 1), \ + .hci_ept_cfg = { \ + .name = DT_INST_PROP(inst, bt_hci_ipc_name), \ + .cb = { \ + .bound = hci_ept_bound, \ + .received = hci_ept_recv, \ + }, \ + .priv = (void *)DEVICE_DT_INST_GET(inst), \ + }, \ + .ipc = DEVICE_DT_GET(DT_INST_PARENT(inst)), \ + }; \ + DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &ipc_data_##inst, NULL, \ + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &drv) + +DT_INST_FOREACH_STATUS_OKAY(IPC_DEVICE_INIT) diff --git a/drivers/bluetooth/hci/ipm_stm32wb.c b/drivers/bluetooth/hci/ipm_stm32wb.c index 48c5dd0a99cae..df83ee36d54c9 100644 --- a/drivers/bluetooth/hci/ipm_stm32wb.c +++ b/drivers/bluetooth/hci/ipm_stm32wb.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include @@ -21,7 +21,11 @@ #include "shci.h" #include "shci_tl.h" -static const struct stm32_pclken clk_cfg[] = STM32_DT_CLOCKS(DT_NODELABEL(ble_rf)); +struct hci_data { + bt_hci_recv_t recv; +}; + +static const struct stm32_pclken clk_cfg[] = STM32_DT_CLOCKS(DT_DRV_INST(0)); #define POOL_SIZE (CFG_TLBLE_EVT_QUEUE_LENGTH * 4 * \ DIVC((sizeof(TL_PacketHeader_t) + TL_BLE_EVENT_FRAME_SIZE), 4)) @@ -156,7 +160,9 @@ void TM_EvtReceivedCb(TL_EvtPacket_t *hcievt) static void bt_ipm_rx_thread(void *p1, void *p2, void *p3) { - ARG_UNUSED(p1); + const struct device *dev = p1; + struct hci_data *hci = dev->data; + ARG_UNUSED(p2); ARG_UNUSED(p3); @@ -245,7 +251,7 @@ static void bt_ipm_rx_thread(void *p1, void *p2, void *p3) TL_MM_EvtDone(hcievt); - bt_recv(buf); + hci->recv(dev, buf); end_loop: k_sem_give(&ipm_busy); } @@ -347,10 +353,12 @@ void transport_init(void) TL_Enable(); } -static int bt_ipm_send(struct net_buf *buf) +static int bt_ipm_send(const struct device *dev, struct net_buf *buf) { TL_CmdPacket_t *ble_cmd_buff = &BleCmdBuffer; + ARG_UNUSED(dev); + k_sem_take(&ipm_busy, K_FOREVER); switch (bt_buf_get_type(buf)) { @@ -534,8 +542,9 @@ static int c2_reset(void) return 0; } -static int bt_ipm_open(void) +static int bt_ipm_open(const struct device *dev, bt_hci_recv_t recv) { + struct hci_data *hci = dev->data; int err; if (!c2_started_flag) { @@ -553,7 +562,7 @@ static int bt_ipm_open(void) /* Start RX thread */ k_thread_create(&ipm_rx_thread_data, ipm_rx_stack, K_KERNEL_STACK_SIZEOF(ipm_rx_stack), - bt_ipm_rx_thread, NULL, NULL, NULL, + bt_ipm_rx_thread, (void *)dev, NULL, NULL, K_PRIO_COOP(CONFIG_BT_DRIVER_RX_HIGH_PRIO), 0, K_NO_WAIT); @@ -564,14 +573,17 @@ static int bt_ipm_open(void) } #endif /* CONFIG_BT_HCI_HOST */ + hci->recv = recv; + LOG_DBG("IPM Channel Open Completed"); return 0; } #ifdef CONFIG_BT_HCI_HOST -static int bt_ipm_close(void) +static int bt_ipm_close(const struct device *dev) { + struct hci_data *hci = dev->data; int err; struct net_buf *rsp; @@ -590,15 +602,15 @@ static int bt_ipm_close(void) k_thread_abort(&ipm_rx_thread_data); + hci->recv = NULL; + LOG_DBG("IPM Channel Close Completed"); return err; } #endif /* CONFIG_BT_HCI_HOST */ -static const struct bt_hci_driver drv = { - .name = "BT IPM", - .bus = BT_HCI_DRIVER_BUS_IPM, +static const struct bt_hci_driver_api drv = { .open = bt_ipm_open, #ifdef CONFIG_BT_HCI_HOST .close = bt_ipm_close, @@ -606,12 +618,11 @@ static const struct bt_hci_driver drv = { .send = bt_ipm_send, }; -static int _bt_ipm_init(void) +static int _bt_ipm_init(const struct device *dev) { int err; - - bt_hci_driver_register(&drv); + ARG_UNUSED(dev); err = c2_reset(); if (err) { @@ -621,4 +632,11 @@ static int _bt_ipm_init(void) return 0; } -SYS_INIT(_bt_ipm_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); +#define HCI_DEVICE_INIT(inst) \ + static struct hci_data hci_data_##inst = { \ + }; \ + DEVICE_DT_INST_DEFINE(inst, _bt_ipm_init, NULL, &hci_data_##inst, NULL, \ + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &drv) + +/* Only one instance supported right now */ +HCI_DEVICE_INIT(0) diff --git a/drivers/bluetooth/hci/slz_hci.c b/drivers/bluetooth/hci/slz_hci.c index a3daf33460711..1dcb0278fd7e0 100644 --- a/drivers/bluetooth/hci/slz_hci.c +++ b/drivers/bluetooth/hci/slz_hci.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #include @@ -16,6 +16,12 @@ #include LOG_MODULE_REGISTER(bt_hci_driver_slz); +#define DT_DRV_COMPAT silabs_bt_hci + +struct hci_data { + bt_hci_recv_t recv; +}; + #define SL_BT_CONFIG_ACCEPT_LIST_SIZE 1 #define SL_BT_CONFIG_MAX_CONNECTIONS 1 #define SL_BT_CONFIG_USER_ADVERTISERS 1 @@ -53,6 +59,8 @@ void rail_isr_installer(void) */ uint32_t hci_common_transport_transmit(uint8_t *data, int16_t len) { + const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0)); + struct hci_data *hci = dev->data; struct net_buf *buf; uint8_t packet_type = data[0]; uint8_t event_code; @@ -77,17 +85,19 @@ uint32_t hci_common_transport_transmit(uint8_t *data, int16_t len) } net_buf_add_mem(buf, data, len); - bt_recv(buf); + hci->recv(dev, buf); sl_btctrl_hci_transmit_complete(0); return 0; } -static int slz_bt_send(struct net_buf *buf) +static int slz_bt_send(const struct device *dev, struct net_buf *buf) { int rv = 0; + ARG_UNUSED(dev); + switch (bt_buf_get_type(buf)) { case BT_BUF_ACL_OUT: net_buf_push_u8(buf, h4_acl); @@ -119,8 +129,9 @@ static void slz_thread_func(void *p1, void *p2, void *p3) slz_ll_thread_func(); } -static int slz_bt_open(void) +static int slz_bt_open(const struct device *dev, bt_hci_recv_t recv) { + struct hci_data *hci = dev->data; int ret; /* Start RX thread */ @@ -185,6 +196,8 @@ static int slz_bt_open(void) } #endif + hci->recv = recv; + LOG_DBG("SiLabs BT HCI started"); return 0; @@ -193,24 +206,16 @@ static int slz_bt_open(void) return ret; } -static const struct bt_hci_driver drv = { - .name = "sl:bt", - .bus = BT_HCI_DRIVER_BUS_UART, +static const struct bt_hci_driver_api drv = { .open = slz_bt_open, .send = slz_bt_send, - .quirks = BT_QUIRK_NO_RESET }; -static int slz_bt_init(void) -{ - int ret; - - ret = bt_hci_driver_register(&drv); - if (ret) { - LOG_ERR("Failed to register SiLabs BT HCI %d", ret); - } - - return ret; -} +#define HCI_DEVICE_INIT(inst) \ + static struct hci_data hci_data_##inst = { \ + }; \ + DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &hci_data_##inst, NULL, \ + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &drv) -SYS_INIT(slz_bt_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); +/* Only one instance supported right now */ +HCI_DEVICE_INIT(0) diff --git a/drivers/bluetooth/hci/spi.c b/drivers/bluetooth/hci/spi.c index 26d8f32afd0a7..05e46a1d182cf 100644 --- a/drivers/bluetooth/hci/spi.c +++ b/drivers/bluetooth/hci/spi.c @@ -15,7 +15,7 @@ #include #include -#include +#include #define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL #include @@ -66,6 +66,10 @@ LOG_MODULE_REGISTER(bt_driver); be transmitted across this HCI link #endif /* CONFIG_BT_L2CAP_TX_MTU > MAX_MTU */ +struct bt_spi_data { + bt_hci_recv_t recv; +}; + static uint8_t __noinit rxmsg[SPI_MAX_MSG_LEN]; static uint8_t __noinit txmsg[SPI_MAX_MSG_LEN]; @@ -236,7 +240,9 @@ static struct net_buf *bt_spi_rx_buf_construct(uint8_t *msg) static void bt_spi_rx_thread(void *p1, void *p2, void *p3) { - ARG_UNUSED(p1); + const struct device *dev = p1; + struct bt_spi_data *hci = dev->data; + ARG_UNUSED(p2); ARG_UNUSED(p3); @@ -288,17 +294,19 @@ static void bt_spi_rx_thread(void *p1, void *p2, void *p3) buf = bt_spi_rx_buf_construct(rxmsg); if (buf) { /* Handle the received HCI data */ - bt_recv(buf); + hci->recv(dev, buf); } } } -static int bt_spi_send(struct net_buf *buf) +static int bt_spi_send(const struct device *dev, struct net_buf *buf) { uint16_t size; uint8_t rx_first[1]; int ret; + ARG_UNUSED(dev); + LOG_DBG(""); /* Buffer needs an additional byte for type */ @@ -364,8 +372,9 @@ static int bt_spi_send(struct net_buf *buf) return ret; } -static int bt_spi_open(void) +static int bt_spi_open(const struct device *dev, bt_hci_recv_t recv) { + struct bt_spi_data *hci = dev->data; int err; /* Configure RST pin and hold BLE in Reset */ @@ -392,6 +401,8 @@ static int bt_spi_open(void) return err; } + hci->recv = recv; + /* Take BLE out of reset */ k_sleep(K_MSEC(DT_INST_PROP_OR(0, reset_assert_duration_ms, 0))); gpio_pin_set_dt(&rst_gpio, 0); @@ -399,7 +410,7 @@ static int bt_spi_open(void) /* Start RX thread */ k_thread_create(&spi_rx_thread_data, spi_rx_stack, K_KERNEL_STACK_SIZEOF(spi_rx_stack), - bt_spi_rx_thread, NULL, NULL, NULL, + bt_spi_rx_thread, (void *)dev, NULL, NULL, K_PRIO_COOP(CONFIG_BT_DRIVER_RX_HIGH_PRIO), 0, K_NO_WAIT); @@ -409,15 +420,14 @@ static int bt_spi_open(void) return 0; } -static const struct bt_hci_driver drv = { - .name = DEVICE_DT_NAME(DT_DRV_INST(0)), - .bus = BT_HCI_DRIVER_BUS_SPI, +static const struct bt_hci_driver_api drv = { .open = bt_spi_open, .send = bt_spi_send, }; -static int bt_spi_init(void) +static int bt_spi_init(const struct device *dev) { + ARG_UNUSED(dev); if (!spi_is_ready_dt(&bus)) { LOG_ERR("SPI device not ready"); @@ -434,12 +444,16 @@ static int bt_spi_init(void) return -ENODEV; } - bt_hci_driver_register(&drv); - - LOG_DBG("BT SPI initialized"); return 0; } -SYS_INIT(bt_spi_init, POST_KERNEL, CONFIG_BT_SPI_INIT_PRIORITY); +#define HCI_DEVICE_INIT(inst) \ + static struct bt_spi_data hci_data_##inst = { \ + }; \ + DEVICE_DT_INST_DEFINE(inst, bt_spi_init, NULL, &hci_data_##inst, NULL, \ + POST_KERNEL, CONFIG_BT_SPI_INIT_PRIORITY, &drv) + +/* Only one instance supported right now */ +HCI_DEVICE_INIT(0) diff --git a/drivers/bluetooth/hci/userchan.c b/drivers/bluetooth/hci/userchan.c index 8a1ae24127496..a5f6810b82b7e 100644 --- a/drivers/bluetooth/hci/userchan.c +++ b/drivers/bluetooth/hci/userchan.c @@ -30,12 +30,20 @@ #include #include -#include +#include #define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL #include LOG_MODULE_REGISTER(bt_driver); +#define DT_DRV_COMPAT zephyr_bt_hci_userchan + +struct uc_data { + int fd; + bt_hci_recv_t recv; + +}; + #define BTPROTO_HCI 1 struct sockaddr_hci { sa_family_t hci_family; @@ -50,8 +58,6 @@ static K_KERNEL_STACK_DEFINE(rx_thread_stack, CONFIG_ARCH_POSIX_RECOMMENDED_STACK_SIZE); static struct k_thread rx_thread_data; -static int uc_fd = -1; - static unsigned short bt_dev_index; #define TCP_ADDR_BUFF_SIZE 16 @@ -158,16 +164,18 @@ static int32_t hci_packet_complete(const uint8_t *buf, uint16_t buf_len) return (int32_t)header_len + payload_len; } -static bool uc_ready(void) +static bool uc_ready(int fd) { - struct pollfd pollfd = { .fd = uc_fd, .events = POLLIN }; + struct pollfd pollfd = { .fd = fd, .events = POLLIN }; return (poll(&pollfd, 1, 0) == 1); } static void rx_thread(void *p1, void *p2, void *p3) { - ARG_UNUSED(p1); + const struct device *dev = p1; + struct uc_data *uc = dev->data; + ARG_UNUSED(p2); ARG_UNUSED(p3); @@ -183,14 +191,14 @@ static void rx_thread(void *p1, void *p2, void *p3) ssize_t len; const uint8_t *frame_start = frame; - if (!uc_ready()) { + if (!uc_ready(uc->fd)) { k_sleep(K_MSEC(1)); continue; } LOG_DBG("calling read()"); - len = read(uc_fd, frame + frame_size, sizeof(frame) - frame_size); + len = read(uc->fd, frame + frame_size, sizeof(frame) - frame_size); if (len < 0) { if (errno == EINTR) { k_yield(); @@ -198,8 +206,8 @@ static void rx_thread(void *p1, void *p2, void *p3) } LOG_ERR("Reading socket failed, errno %d", errno); - close(uc_fd); - uc_fd = -1; + close(uc->fd); + uc->fd = -1; return; } @@ -256,18 +264,20 @@ static void rx_thread(void *p1, void *p2, void *p3) LOG_DBG("Calling bt_recv(%p)", buf); - bt_recv(buf); + uc->recv(dev, buf); } k_yield(); } } -static int uc_send(struct net_buf *buf) +static int uc_send(const struct device *dev, struct net_buf *buf) { + struct uc_data *uc = dev->data; + LOG_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len); - if (uc_fd < 0) { + if (uc->fd < 0) { LOG_ERR("User channel not open"); return -EIO; } @@ -290,7 +300,7 @@ static int uc_send(struct net_buf *buf) return -EINVAL; } - if (write(uc_fd, buf->data, buf->len) < 0) { + if (write(uc->fd, buf->data, buf->len) < 0) { return -errno; } @@ -350,25 +360,28 @@ static int user_chan_open(void) return fd; } -static int uc_open(void) +static int uc_open(const struct device *dev, bt_hci_recv_t recv) { + struct uc_data *uc = dev->data; + if (hci_socket) { LOG_DBG("hci%d", bt_dev_index); } else { LOG_DBG("hci %s:%d", ip_addr, port); } - - uc_fd = user_chan_open(); - if (uc_fd < 0) { - return uc_fd; + uc->fd = user_chan_open(); + if (uc->fd < 0) { + return uc->fd; } - LOG_DBG("User Channel opened as fd %d", uc_fd); + uc->recv = recv; + + LOG_DBG("User Channel opened as fd %d", uc->fd); k_thread_create(&rx_thread_data, rx_thread_stack, K_KERNEL_STACK_SIZEOF(rx_thread_stack), - rx_thread, NULL, NULL, NULL, + rx_thread, (void *)dev, NULL, NULL, K_PRIO_COOP(CONFIG_BT_DRIVER_RX_HIGH_PRIO), 0, K_NO_WAIT); @@ -377,22 +390,31 @@ static int uc_open(void) return 0; } -static const struct bt_hci_driver drv = { - .name = "HCI User Channel", - .bus = BT_HCI_DRIVER_BUS_UART, - .open = uc_open, - .send = uc_send, +static const struct bt_hci_driver_api uc_drv_api = { + .open = uc_open, + .send = uc_send, }; -static int bt_uc_init(void) +static int uc_init(const struct device *dev) { - - bt_hci_driver_register(&drv); + if (!arg_found) { + posix_print_warning("Warning: Bluetooth device missing.\n" + "Specify either a local hci interface --bt-dev=hciN\n" + "or a valid hci tcp server --bt-dev=ip_address:port\n"); + return -ENODEV; + } return 0; } -SYS_INIT(bt_uc_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); +#define UC_DEVICE_INIT(inst) \ + static struct uc_data uc_data_##inst = { \ + .fd = -1, \ + }; \ + DEVICE_DT_INST_DEFINE(inst, uc_init, NULL, &uc_data_##inst, NULL, \ + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &uc_drv_api) + +DT_INST_FOREACH_STATUS_OKAY(UC_DEVICE_INIT) static void cmd_bt_dev_found(char *argv, int offset) { @@ -446,14 +468,4 @@ static void add_btuserchan_arg(void) native_add_command_line_opts(btuserchan_args); } -static void btuserchan_check_arg(void) -{ - if (!arg_found) { - posix_print_error_and_exit("Error: Bluetooth device missing.\n" - "Specify either a local hci interface --bt-dev=hciN\n" - "or a valid hci tcp server --bt-dev=ip_address:port\n"); - } -} - NATIVE_TASK(add_btuserchan_arg, PRE_BOOT_1, 10); -NATIVE_TASK(btuserchan_check_arg, PRE_BOOT_2, 10); diff --git a/dts/arm/ambiq/ambiq_apollo3_blue.dtsi b/dts/arm/ambiq/ambiq_apollo3_blue.dtsi index af03e4e519560..ae1028ab4a1f3 100644 --- a/dts/arm/ambiq/ambiq_apollo3_blue.dtsi +++ b/dts/arm/ambiq/ambiq_apollo3_blue.dtsi @@ -287,7 +287,7 @@ status = "disabled"; ambiq,pwrcfg = <&pwrcfg 0x8 0x8000>; - bt-hci@0 { + bt_hci_apollo: bt-hci@0 { compatible = "ambiq,bt-hci-spi"; reg = <0>; }; diff --git a/dts/arm/ambiq/ambiq_apollo3p_blue.dtsi b/dts/arm/ambiq/ambiq_apollo3p_blue.dtsi index e22dd52350df0..afaf69692dd5a 100644 --- a/dts/arm/ambiq/ambiq_apollo3p_blue.dtsi +++ b/dts/arm/ambiq/ambiq_apollo3p_blue.dtsi @@ -307,7 +307,7 @@ status = "disabled"; ambiq,pwrcfg = <&pwrcfg 0x8 0x8000>; - bt-hci@0 { + bt_hci_apollo: bt-hci@0 { compatible = "ambiq,bt-hci-spi"; reg = <0>; }; diff --git a/dts/arm/ambiq/ambiq_apollo4p_blue.dtsi b/dts/arm/ambiq/ambiq_apollo4p_blue.dtsi index 7f4d7145877fb..9656eadc98445 100644 --- a/dts/arm/ambiq/ambiq_apollo4p_blue.dtsi +++ b/dts/arm/ambiq/ambiq_apollo4p_blue.dtsi @@ -174,7 +174,7 @@ status = "disabled"; ambiq,pwrcfg = <&pwrcfg 0x4 0x20>; - bt-hci@0 { + bt_hci_apollo: bt-hci@0 { compatible = "ambiq,bt-hci-spi"; reg = <0>; irq-gpios = <&gpio32_63 21 GPIO_ACTIVE_HIGH>; diff --git a/dts/arm/nordic/nrf51822.dtsi b/dts/arm/nordic/nrf51822.dtsi index b64de1d4985c8..11cc9eff2f9e8 100644 --- a/dts/arm/nordic/nrf51822.dtsi +++ b/dts/arm/nordic/nrf51822.dtsi @@ -5,6 +5,7 @@ / { chosen { + zephyr,bt-hci = &bt_hci_controller; zephyr,entropy = &rng; zephyr,flash-controller = &flash_controller; }; @@ -73,6 +74,11 @@ reg = <0x40001000 0x1000>; interrupts = <1 NRF_DEFAULT_IRQ_PRIORITY>; status = "okay"; + + bt_hci_controller: bt_hci_controller { + compatible = "zephyr,bt-hci-ll-sw-split"; + status = "okay"; + }; }; uart0: uart@40002000 { diff --git a/dts/arm/nordic/nrf52805.dtsi b/dts/arm/nordic/nrf52805.dtsi index c5a184d5e288c..b375ef1706975 100644 --- a/dts/arm/nordic/nrf52805.dtsi +++ b/dts/arm/nordic/nrf52805.dtsi @@ -9,6 +9,7 @@ / { chosen { + zephyr,bt-hci = &bt_hci_controller; zephyr,entropy = &rng; zephyr,flash-controller = &flash_controller; }; @@ -86,6 +87,11 @@ interrupts = <1 NRF_DEFAULT_IRQ_PRIORITY>; status = "okay"; ble-2mbps-supported; + + bt_hci_controller: bt_hci_controller { + compatible = "zephyr,bt-hci-ll-sw-split"; + status = "okay"; + }; }; uart0: uart@40002000 { diff --git a/dts/arm/nordic/nrf52810.dtsi b/dts/arm/nordic/nrf52810.dtsi index 1ca4a9ea378a3..0c95fe96e70df 100644 --- a/dts/arm/nordic/nrf52810.dtsi +++ b/dts/arm/nordic/nrf52810.dtsi @@ -5,6 +5,7 @@ / { chosen { + zephyr,bt-hci = &bt_hci_controller; zephyr,entropy = &rng; zephyr,flash-controller = &flash_controller; }; @@ -90,6 +91,11 @@ interrupts = <1 NRF_DEFAULT_IRQ_PRIORITY>; status = "okay"; ble-2mbps-supported; + + bt_hci_controller: bt_hci_controller { + compatible = "zephyr,bt-hci-ll-sw-split"; + status = "okay"; + }; }; uart0: uart@40002000 { diff --git a/dts/arm/nordic/nrf52811.dtsi b/dts/arm/nordic/nrf52811.dtsi index 63b8567658773..2176bfa93c744 100644 --- a/dts/arm/nordic/nrf52811.dtsi +++ b/dts/arm/nordic/nrf52811.dtsi @@ -9,6 +9,7 @@ / { chosen { + zephyr,bt-hci = &bt_hci_controller; zephyr,entropy = &rng; zephyr,flash-controller = &flash_controller; }; @@ -102,6 +103,11 @@ compatible = "nordic,nrf-ieee802154"; status = "disabled"; }; + + bt_hci_controller: bt_hci_controller { + compatible = "zephyr,bt-hci-ll-sw-split"; + status = "okay"; + }; }; uart0: uart@40002000 { diff --git a/dts/arm/nordic/nrf52820.dtsi b/dts/arm/nordic/nrf52820.dtsi index f93e449b0b2cc..d6bd6e65f66cf 100644 --- a/dts/arm/nordic/nrf52820.dtsi +++ b/dts/arm/nordic/nrf52820.dtsi @@ -10,6 +10,7 @@ / { chosen { + zephyr,bt-hci = &bt_hci_controller; zephyr,entropy = &rng; zephyr,flash-controller = &flash_controller; }; @@ -98,6 +99,11 @@ compatible = "nordic,nrf-ieee802154"; status = "disabled"; }; + + bt_hci_controller: bt_hci_controller { + compatible = "zephyr,bt-hci-ll-sw-split"; + status = "okay"; + }; }; uart0: uart@40002000 { diff --git a/dts/arm/nordic/nrf52832.dtsi b/dts/arm/nordic/nrf52832.dtsi index 13ee05226b76f..bdb76a05d5b59 100644 --- a/dts/arm/nordic/nrf52832.dtsi +++ b/dts/arm/nordic/nrf52832.dtsi @@ -5,6 +5,7 @@ / { chosen { + zephyr,bt-hci = &bt_hci_controller; zephyr,entropy = &rng; zephyr,flash-controller = &flash_controller; }; @@ -90,6 +91,11 @@ interrupts = <1 NRF_DEFAULT_IRQ_PRIORITY>; status = "okay"; ble-2mbps-supported; + + bt_hci_controller: bt_hci_controller { + compatible = "zephyr,bt-hci-ll-sw-split"; + status = "okay"; + }; }; uart0: uart@40002000 { diff --git a/dts/arm/nordic/nrf52833.dtsi b/dts/arm/nordic/nrf52833.dtsi index f22cb36bc14a4..40c3f1efcad4b 100644 --- a/dts/arm/nordic/nrf52833.dtsi +++ b/dts/arm/nordic/nrf52833.dtsi @@ -9,6 +9,7 @@ / { chosen { + zephyr,bt-hci = &bt_hci_controller; zephyr,entropy = &rng; zephyr,flash-controller = &flash_controller; }; @@ -97,6 +98,11 @@ compatible = "nordic,nrf-ieee802154"; status = "disabled"; }; + + bt_hci_controller: bt_hci_controller { + compatible = "zephyr,bt-hci-ll-sw-split"; + status = "okay"; + }; }; uart0: uart@40002000 { diff --git a/dts/arm/nordic/nrf52840.dtsi b/dts/arm/nordic/nrf52840.dtsi index 4cfb7abc511ef..120a5a87b1355 100644 --- a/dts/arm/nordic/nrf52840.dtsi +++ b/dts/arm/nordic/nrf52840.dtsi @@ -5,6 +5,7 @@ / { chosen { + zephyr,bt-hci = &bt_hci_controller; zephyr,entropy = &rng; zephyr,flash-controller = &flash_controller; }; @@ -92,6 +93,11 @@ compatible = "nordic,nrf-ieee802154"; status = "disabled"; }; + + bt_hci_controller: bt_hci_controller { + compatible = "zephyr,bt-hci-ll-sw-split"; + status = "okay"; + }; }; uart0: uart@40002000 { diff --git a/dts/arm/nordic/nrf5340_cpuapp_ipc.dtsi b/dts/arm/nordic/nrf5340_cpuapp_ipc.dtsi index 9dc8f70a7d0ce..f5cda20e9613f 100644 --- a/dts/arm/nordic/nrf5340_cpuapp_ipc.dtsi +++ b/dts/arm/nordic/nrf5340_cpuapp_ipc.dtsi @@ -11,4 +11,9 @@ ipc0: ipc0 { mbox-names = "tx", "rx"; role = "host"; status = "okay"; + + bt_hci_ipc0: bt_hci_ipc0 { + compatible = "zephyr,bt-hci-ipc"; + status = "okay"; + }; }; diff --git a/dts/arm/nordic/nrf5340_cpunet.dtsi b/dts/arm/nordic/nrf5340_cpunet.dtsi index 8a95b3e99850a..4e05f4a1df02e 100644 --- a/dts/arm/nordic/nrf5340_cpunet.dtsi +++ b/dts/arm/nordic/nrf5340_cpunet.dtsi @@ -9,6 +9,7 @@ / { chosen { + zephyr,bt-hci = &bt_hci_controller; zephyr,entropy = &rng; zephyr,flash-controller = &flash_controller; }; @@ -100,6 +101,11 @@ compatible = "nordic,nrf-ieee802154"; status = "disabled"; }; + + bt_hci_controller: bt_hci_controller { + compatible = "zephyr,bt-hci-ll-sw-split"; + status = "okay"; + }; }; rng: random@41009000 { diff --git a/dts/arm/nordic/nrf54l15_cpuapp.dtsi b/dts/arm/nordic/nrf54l15_cpuapp.dtsi index 6a4f5fcae239e..f2264079e8d60 100644 --- a/dts/arm/nordic/nrf54l15_cpuapp.dtsi +++ b/dts/arm/nordic/nrf54l15_cpuapp.dtsi @@ -17,6 +17,10 @@ cpuflpr_vevif: &cpuflpr_vevif_remote {}; /delete-node/ &cpuflpr_clic; / { + chosen { + zephyr,bt-hci = &bt_hci_controller; + }; + soc { compatible = "simple-bus"; interrupt-parent = <&cpuapp_nvic>; @@ -29,6 +33,10 @@ cpuflpr_vevif: &cpuflpr_vevif_remote {}; }; }; +&bt_hci_controller { + status = "okay"; +}; + &cpuapp_ppb { compatible = "simple-bus"; ranges; diff --git a/dts/arm/nxp/nxp_rw6xx_common.dtsi b/dts/arm/nxp/nxp_rw6xx_common.dtsi index 60c3dc9d2d542..722c3a65c5ed9 100644 --- a/dts/arm/nxp/nxp_rw6xx_common.dtsi +++ b/dts/arm/nxp/nxp_rw6xx_common.dtsi @@ -16,6 +16,7 @@ / { chosen { zephyr,entropy = &trng; + zephyr,bt-hci = &hci; }; cpus { diff --git a/dts/arm/renesas/smartbond/da1469x.dtsi b/dts/arm/renesas/smartbond/da1469x.dtsi index 3ab063af25cc7..05f250935f32f 100644 --- a/dts/arm/renesas/smartbond/da1469x.dtsi +++ b/dts/arm/renesas/smartbond/da1469x.dtsi @@ -394,6 +394,11 @@ reg = <0x34000000 0x48>; status = "disabled"; }; + + bt_hci_da1469x: bt_hci_da1469x { + compatible = "renesas,bt-hci-da1469x"; + status = "disabled"; + }; }; }; diff --git a/dts/arm/silabs/efr32bg2x.dtsi b/dts/arm/silabs/efr32bg2x.dtsi index 70df9708d116a..9cd0618cd41c9 100644 --- a/dts/arm/silabs/efr32bg2x.dtsi +++ b/dts/arm/silabs/efr32bg2x.dtsi @@ -224,6 +224,11 @@ #io-channel-cells = <1>; }; }; + + bt_hci_silabs: bt_hci_silabs { + compatible = "silabs,bt-hci"; + status = "disabled"; + }; }; / { diff --git a/dts/arm/silabs/efr32mg.dtsi b/dts/arm/silabs/efr32mg.dtsi index cfbbde48af9b1..a7926f6710f6b 100644 --- a/dts/arm/silabs/efr32mg.dtsi +++ b/dts/arm/silabs/efr32mg.dtsi @@ -234,6 +234,11 @@ }; }; + bt_hci_silabs: bt_hci_silabs { + compatible = "silabs,bt-hci"; + status = "disabled"; + }; + pinctrl: pin-controller { /* Pin controller is a "virtual" device since SiLabs SoCs do pin * control in a distributed way (GPIO registers and PSEL diff --git a/dts/arm/silabs/efr32mg24.dtsi b/dts/arm/silabs/efr32mg24.dtsi index 860cedddeda5f..b92100c85a567 100644 --- a/dts/arm/silabs/efr32mg24.dtsi +++ b/dts/arm/silabs/efr32mg24.dtsi @@ -213,6 +213,12 @@ #io-channel-cells = <1>; }; }; + + + bt_hci_silabs: bt_hci_silabs { + compatible = "silabs,bt-hci"; + status = "disabled"; + }; }; / { diff --git a/dts/arm/silabs/efr32xg13p.dtsi b/dts/arm/silabs/efr32xg13p.dtsi index 96d9c6493d18d..3444eb6e391f4 100644 --- a/dts/arm/silabs/efr32xg13p.dtsi +++ b/dts/arm/silabs/efr32xg13p.dtsi @@ -181,6 +181,11 @@ }; }; + bt_hci_silabs: bt_hci_silabs { + compatible = "silabs,bt-hci"; + status = "disabled"; + }; + pinctrl: pin-controller { /* Pin controller is a "virtual" device since SiLabs SoCs do pin * control in a distributed way (GPIO registers and PSEL diff --git a/dts/arm/st/wb/stm32wb.dtsi b/dts/arm/st/wb/stm32wb.dtsi index a972f3ef9c6d6..fa0c3304fe287 100644 --- a/dts/arm/st/wb/stm32wb.dtsi +++ b/dts/arm/st/wb/stm32wb.dtsi @@ -23,6 +23,7 @@ chosen { zephyr,entropy = &rng; zephyr,flash-controller = &flash; + zephyr,bt-hci = &ble_rf; }; cpus { diff --git a/dts/arm/st/wba/stm32wba.dtsi b/dts/arm/st/wba/stm32wba.dtsi index 05efb0a9431e1..5b402ae9501c5 100644 --- a/dts/arm/st/wba/stm32wba.dtsi +++ b/dts/arm/st/wba/stm32wba.dtsi @@ -23,6 +23,7 @@ zephyr,entropy = &rng; zephyr,flash-controller = &flash; st,lptim-stdby-timer = &rtc; + zephyr,bt-hci = &bt_hci_wba; }; cpus { @@ -472,6 +473,11 @@ }; }; + bt_hci_wba: bt_hci_wba { + compatible = "st,hci-stm32wba"; + status = "okay"; + }; + swj_port: swj_port { compatible = "swj-connector"; pinctrl-0 = <&debug_jtms_swdio_pa13 &debug_jtck_swclk_pa14 diff --git a/dts/bindings/bluetooth/ambiq,bt-hci-spi.yaml b/dts/bindings/bluetooth/ambiq,bt-hci-spi.yaml index 42df66d218094..cbaabb318c1b5 100644 --- a/dts/bindings/bluetooth/ambiq,bt-hci-spi.yaml +++ b/dts/bindings/bluetooth/ambiq,bt-hci-spi.yaml @@ -7,6 +7,8 @@ description: | compatible: "ambiq,bt-hci-spi" +include: bt-hci.yaml + properties: reg: type: array @@ -30,3 +32,9 @@ properties: controller. The host needs to enable XO32MHz when receiving low to high edge interrupts and disable XO32MHz when receiving high to low edge interrupts. + + bt-hci-name: + default: "ambiq hci" + + bt-hci-bus: + default: "BT_HCI_BUS_SPI" diff --git a/dts/bindings/bluetooth/bt-hci.yaml b/dts/bindings/bluetooth/bt-hci.yaml new file mode 100644 index 0000000000000..e53b9022e9069 --- /dev/null +++ b/dts/bindings/bluetooth/bt-hci.yaml @@ -0,0 +1,28 @@ +# Common fields for Bluetooth HCI devices + +include: base.yaml + +properties: + bt-hci-name: + type: string + description: Name of the HCI transport + bt-hci-bus: + type: string + description: Bus of the transport + enum: + - "BT_HCI_BUS_VIRTUAL" + - "BT_HCI_BUS_USB" + - "BT_HCI_BUS_PCCARD" + - "BT_HCI_BUS_UART" + - "BT_HCI_BUS_RS232" + - "BT_HCI_BUS_PCI" + - "BT_HCI_BUS_SDIO" + - "BT_HCI_BUS_SPI" + - "BT_HCI_BUS_I2C" + - "BT_HCI_BUS_IPM" + bt-hci-quirks: + type: string-array + description: HCI device quirks + bt-hci-vs-ext: + type: boolean + description: Zephyr HCI vendor extensions are supported diff --git a/dts/bindings/bluetooth/espressif,esp32-bt-hci.yaml b/dts/bindings/bluetooth/espressif,esp32-bt-hci.yaml new file mode 100644 index 0000000000000..e095fcd9510a4 --- /dev/null +++ b/dts/bindings/bluetooth/espressif,esp32-bt-hci.yaml @@ -0,0 +1,13 @@ +description: Bluetooth HCI for Espressif ESP32 + +compatible: "espressif,esp32-bt-hci" + +include: bt-hci.yaml + +properties: + bt-hci-name: + default: "BT ESP32" + bt-hci-bus: + default: "BT_HCI_BUS_IPM" + bt-hci-quirks: + default: ["BT_HCI_QUIRK_NO_AUTO_DLE"] diff --git a/dts/bindings/bluetooth/infineon,cat1-bless-hci.yaml b/dts/bindings/bluetooth/infineon,cat1-bless-hci.yaml index 0d38855c00edb..80671e581350e 100644 --- a/dts/bindings/bluetooth/infineon,cat1-bless-hci.yaml +++ b/dts/bindings/bluetooth/infineon,cat1-bless-hci.yaml @@ -8,8 +8,14 @@ description: | compatible: "infineon,cat1-bless-hci" -include: base.yaml +include: bt-hci.yaml properties: + bt-hci-name: + default: "PSoC 6 BLESS" + bt-hci-bus: + default: "BT_HCI_BUS_VIRTUAL" + bt-hci-quirks: + default: ["BT_HCI_QUIRK_NO_RESET"] interrupts: required: true diff --git a/dts/bindings/arm/nxp,hci-ble.yaml b/dts/bindings/bluetooth/nxp,hci-ble.yaml similarity index 62% rename from dts/bindings/arm/nxp,hci-ble.yaml rename to dts/bindings/bluetooth/nxp,hci-ble.yaml index 7620ec8eb6988..f2c05c2fda1d9 100644 --- a/dts/bindings/arm/nxp,hci-ble.yaml +++ b/dts/bindings/bluetooth/nxp,hci-ble.yaml @@ -5,8 +5,12 @@ description: NXP BLE HCI information compatible: "nxp,hci-ble" -include: base.yaml +include: bt-hci.yaml properties: interrupts: required: true + bt-hci-name: + default: "BT NXP" + bt-hci-bus: + default: "BT_HCI_BUS_IPM" diff --git a/dts/bindings/bluetooth/renesas,bt-hci-da1469x.yaml b/dts/bindings/bluetooth/renesas,bt-hci-da1469x.yaml new file mode 100644 index 0000000000000..cd66b0119538b --- /dev/null +++ b/dts/bindings/bluetooth/renesas,bt-hci-da1469x.yaml @@ -0,0 +1,11 @@ +description: Bluetooth HCI for Renesas DA1469x + +compatible: "renesas,bt-hci-da1469x" + +include: bt-hci.yaml + +properties: + bt-hci-name: + default: "BT DA1469x" + bt-hci-bus: + default: "BT_HCI_BUS_IPM" diff --git a/dts/bindings/bluetooth/silabs,bt-hci.yaml b/dts/bindings/bluetooth/silabs,bt-hci.yaml new file mode 100644 index 0000000000000..9dc5b67947c58 --- /dev/null +++ b/dts/bindings/bluetooth/silabs,bt-hci.yaml @@ -0,0 +1,13 @@ +description: Bluetooth HCI on Silabs boards + +compatible: "silabs,bt-hci" + +include: bt-hci.yaml + +properties: + bt-hci-name: + default: "sl:bt" + bt-hci-bus: + default: "BT_HCI_BUS_VIRTUAL" + bt-hci-quirks: + default: ["BT_HCI_QUIRK_NO_RESET"] diff --git a/dts/bindings/bluetooth/st,hci-spi-v1.yaml b/dts/bindings/bluetooth/st,hci-spi-v1.yaml index 3784c88ded047..020a796af85f0 100644 --- a/dts/bindings/bluetooth/st,hci-spi-v1.yaml +++ b/dts/bindings/bluetooth/st,hci-spi-v1.yaml @@ -6,3 +6,7 @@ description: STMicroelectronics SPI protocol V1 compatible with BlueNRG-MS devic compatible: "st,hci-spi-v1" include: zephyr,bt-hci-spi.yaml + +properties: + bt-hci-quirks: + default: ["BT_HCI_QUIRK_NO_RESET"] diff --git a/dts/bindings/bluetooth/st,hci-spi-v2.yaml b/dts/bindings/bluetooth/st,hci-spi-v2.yaml index 36b25eae76894..97b62dc90bd82 100644 --- a/dts/bindings/bluetooth/st,hci-spi-v2.yaml +++ b/dts/bindings/bluetooth/st,hci-spi-v2.yaml @@ -6,3 +6,7 @@ description: STMicroelectronics SPI protocol V2 compatible with BlueNRG-1 and su compatible: "st,hci-spi-v2" include: zephyr,bt-hci-spi.yaml + +properties: + bt-hci-quirks: + default: ["BT_HCI_QUIRK_NO_RESET"] diff --git a/dts/bindings/bluetooth/st,hci-stm32wba.yaml b/dts/bindings/bluetooth/st,hci-stm32wba.yaml new file mode 100644 index 0000000000000..ea7c8dbbcc735 --- /dev/null +++ b/dts/bindings/bluetooth/st,hci-stm32wba.yaml @@ -0,0 +1,11 @@ +description: Bluetooth HCI driver for ST STM32WBA + +compatible: "st,hci-stm32wba" + +include: bt-hci.yaml + +properties: + bt-hci-name: + default: "BT IPM" + bt-hci-bus: + default: "BT_HCI_BUS_IPM" diff --git a/dts/bindings/bluetooth/st,stm32wb-ble-rf.yaml b/dts/bindings/bluetooth/st,stm32wb-ble-rf.yaml index 51b46cbff1738..f1903de684000 100644 --- a/dts/bindings/bluetooth/st,stm32wb-ble-rf.yaml +++ b/dts/bindings/bluetooth/st,stm32wb-ble-rf.yaml @@ -6,8 +6,12 @@ description: | compatible: "st,stm32wb-rf" -include: base.yaml +include: bt-hci.yaml properties: - clocks: - required: true + clocks: + required: true + bt-hci-name: + default: "BT IPM" + bt-hci-bus: + default: "BT_HCI_BUS_IPM" diff --git a/dts/bindings/bluetooth/zephyr,bt-hci-3wire-uart.yaml b/dts/bindings/bluetooth/zephyr,bt-hci-3wire-uart.yaml new file mode 100644 index 0000000000000..d2a5f62c2137d --- /dev/null +++ b/dts/bindings/bluetooth/zephyr,bt-hci-3wire-uart.yaml @@ -0,0 +1,13 @@ +# UART Bluetooth HCI device + +description: Bluetooth HCI behind a 3-Wire UART device (H:5) + +compatible: "zephyr,bt-hci-3wire-uart" + +include: bt-hci.yaml + +properties: + bt-hci-name: + default: "H:5" + bt-hci-bus: + default: "BT_HCI_BUS_UART" diff --git a/dts/bindings/bluetooth/zephyr,bt-hci-ipc.yaml b/dts/bindings/bluetooth/zephyr,bt-hci-ipc.yaml new file mode 100644 index 0000000000000..88780827ce47e --- /dev/null +++ b/dts/bindings/bluetooth/zephyr,bt-hci-ipc.yaml @@ -0,0 +1,17 @@ +description: Bluetooth HCI using the IPC subsystem + +compatible: "zephyr,bt-hci-ipc" + +include: bt-hci.yaml + +properties: + bt-hci-name: + default: "IPC" + bt-hci-bus: + default: "BT_HCI_BUS_IPM" + bt-hci-quirks: + default: ["BT_HCI_QUIRK_NO_AUTO_DLE"] + bt-hci-ipc-name: + type: string + default: "nrf_bt_hci" + description: IPC endpoint name diff --git a/dts/bindings/bluetooth/zephyr,bt-hci-ll-sw-split.yaml b/dts/bindings/bluetooth/zephyr,bt-hci-ll-sw-split.yaml new file mode 100644 index 0000000000000..f53cf49e90e05 --- /dev/null +++ b/dts/bindings/bluetooth/zephyr,bt-hci-ll-sw-split.yaml @@ -0,0 +1,13 @@ +description: Bluetooth HCI provided by the native Zephyr Bluetooth Controller + +compatible: "zephyr,bt-hci-ll-sw-split" + +include: bt-hci.yaml + +properties: + bt-hci-name: + default: "Controller" + bt-hci-bus: + default: "BT_HCI_BUS_VIRTUAL" + bt-hci-quirks: + default: ["BT_HCI_QUIRK_NO_AUTO_DLE"] diff --git a/dts/bindings/bluetooth/zephyr,bt-hci-spi.yaml b/dts/bindings/bluetooth/zephyr,bt-hci-spi.yaml index 50d0e311461b5..0447e69d5f19f 100644 --- a/dts/bindings/bluetooth/zephyr,bt-hci-spi.yaml +++ b/dts/bindings/bluetooth/zephyr,bt-hci-spi.yaml @@ -7,7 +7,7 @@ description: | compatible: "zephyr,bt-hci-spi" -include: spi-device.yaml +include: [spi-device.yaml, bt-hci.yaml] properties: irq-gpios: @@ -35,3 +35,9 @@ properties: resulting in an ignored transaction that then needs to be performed a second time. The default of 20uS was chosen as the lowest delay that reliably eliminated double transactions between a nRF9160 host and a nRF52832 controller. + + bt-hci-name: + default: "SPI" + + bt-hci-bus: + default: "BT_HCI_BUS_SPI" diff --git a/dts/bindings/bluetooth/zephyr,bt-hci-uart.yaml b/dts/bindings/bluetooth/zephyr,bt-hci-uart.yaml new file mode 100644 index 0000000000000..d14f8e3035648 --- /dev/null +++ b/dts/bindings/bluetooth/zephyr,bt-hci-uart.yaml @@ -0,0 +1,13 @@ +# UART Bluetooth HCI device + +description: Bluetooth HCI behind a UART device (H:4) + +compatible: "zephyr,bt-hci-uart" + +include: bt-hci.yaml + +properties: + bt-hci-name: + default: "H:4" + bt-hci-bus: + default: "BT_HCI_BUS_UART" diff --git a/dts/bindings/bluetooth/zephyr,bt-hci-userchan.yaml b/dts/bindings/bluetooth/zephyr,bt-hci-userchan.yaml new file mode 100644 index 0000000000000..124a298353275 --- /dev/null +++ b/dts/bindings/bluetooth/zephyr,bt-hci-userchan.yaml @@ -0,0 +1,11 @@ +description: Bluetooth HCI provided by a Linux HCI user channel socket + +compatible: "zephyr,bt-hci-userchan" + +include: bt-hci.yaml + +properties: + bt-hci-name: + default: "HCI User Channel" + bt-hci-bus: + default: "BT_HCI_BUS_UART" diff --git a/dts/common/nordic/nrf54l15.dtsi b/dts/common/nordic/nrf54l15.dtsi index 0b8eb1c549a87..8896b94f87488 100644 --- a/dts/common/nordic/nrf54l15.dtsi +++ b/dts/common/nordic/nrf54l15.dtsi @@ -264,6 +264,11 @@ compatible = "nordic,nrf-ieee802154"; status = "disabled"; }; + + bt_hci_controller: bt_hci_controller { + compatible = "zephyr,bt-hci-ll-sw-split"; + status = "disabled"; + }; }; dppic20: dppic@c2000 { diff --git a/dts/riscv/espressif/esp32c3/esp32c3_common.dtsi b/dts/riscv/espressif/esp32c3/esp32c3_common.dtsi index 43f171f57a1be..71b703114c36b 100644 --- a/dts/riscv/espressif/esp32c3/esp32c3_common.dtsi +++ b/dts/riscv/espressif/esp32c3/esp32c3_common.dtsi @@ -24,6 +24,7 @@ zephyr,canbus = &twai; zephyr,entropy = &trng0; zephyr,flash-controller = &flash; + zephyr,bt-hci = &esp32_bt_hci; }; cpus { @@ -68,6 +69,11 @@ status = "disabled"; }; + esp32_bt_hci: esp32_bt_hci { + compatible = "espressif,esp32-bt-hci"; + status = "disabled"; + }; + soc { #address-cells = <1>; #size-cells = <1>; diff --git a/dts/riscv/openisa/rv32m1.dtsi b/dts/riscv/openisa/rv32m1.dtsi index afbc7c41c23a0..cb234eba99827 100644 --- a/dts/riscv/openisa/rv32m1.dtsi +++ b/dts/riscv/openisa/rv32m1.dtsi @@ -524,5 +524,10 @@ write-block-size = <8>; }; }; + + bt_hci_controller: bt_hci_controller { + compatible = "zephyr,bt-hci-ll-sw-split"; + status = "disabled"; + }; }; }; diff --git a/dts/xtensa/espressif/esp32/esp32_common.dtsi b/dts/xtensa/espressif/esp32/esp32_common.dtsi index d721dd08a2c9e..ae348b1288fb2 100644 --- a/dts/xtensa/espressif/esp32/esp32_common.dtsi +++ b/dts/xtensa/espressif/esp32/esp32_common.dtsi @@ -19,6 +19,7 @@ zephyr,canbus = &twai; zephyr,entropy = &trng0; zephyr,flash-controller = &flash; + zephyr,bt-hci = &esp32_bt_hci; }; cpus { @@ -66,6 +67,11 @@ status = "disabled"; }; + esp32_bt_hci: esp32_bt_hci { + compatible = "espressif,esp32-bt-hci"; + status = "disabled"; + }; + eth: eth { compatible = "espressif,esp32-eth"; interrupts = ; diff --git a/dts/xtensa/espressif/esp32s2/esp32s2_common.dtsi b/dts/xtensa/espressif/esp32s2/esp32s2_common.dtsi index 3a88d973c4773..a855bd0df97b8 100644 --- a/dts/xtensa/espressif/esp32s2/esp32s2_common.dtsi +++ b/dts/xtensa/espressif/esp32s2/esp32s2_common.dtsi @@ -63,6 +63,11 @@ status = "disabled"; }; + esp32_bt_hci: esp32_bt_hci { + compatible = "espressif,esp32-bt-hci"; + status = "disabled"; + }; + pinctrl: pin-controller { compatible = "espressif,esp32-pinctrl"; status = "okay"; diff --git a/dts/xtensa/espressif/esp32s3/esp32s3_common.dtsi b/dts/xtensa/espressif/esp32s3/esp32s3_common.dtsi index 284b74211fdb5..2b571a6596087 100644 --- a/dts/xtensa/espressif/esp32s3/esp32s3_common.dtsi +++ b/dts/xtensa/espressif/esp32s3/esp32s3_common.dtsi @@ -70,6 +70,11 @@ status = "disabled"; }; + esp32_bt_hci: esp32_bt_hci { + compatible = "espressif,esp32-bt-hci"; + status = "disabled"; + }; + pinctrl: pin-controller { compatible = "espressif,esp32-pinctrl"; status = "okay"; diff --git a/include/zephyr/drivers/bluetooth.h b/include/zephyr/drivers/bluetooth.h new file mode 100644 index 0000000000000..f447c76b79253 --- /dev/null +++ b/include/zephyr/drivers/bluetooth.h @@ -0,0 +1,257 @@ +/** @file + * @brief Bluetooth HCI driver API. + * + * Copyright (c) 2024 Johan Hedberg + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef ZEPHYR_INCLUDE_DRIVERS_BLUETOOTH_H_ +#define ZEPHYR_INCLUDE_DRIVERS_BLUETOOTH_H_ + +/** + * @brief Bluetooth HCI APIs + * @defgroup bt_hci_api Bluetooth HCI APIs + * @ingroup bluetooth + * @{ + */ + +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_hci_setup_params { + /** The public identity address to give to the controller. This field is used when the + * driver selects @kconfig{CONFIG_BT_HCI_SET_PUBLIC_ADDR} to indicate that it supports + * setting the controller's public address. + */ + bt_addr_t public_addr; +}; + +enum { + /* The host should never send HCI_Reset */ + BT_HCI_QUIRK_NO_RESET = BIT(0), + /* The controller does not auto-initiate a DLE procedure when the + * initial connection data length parameters are not equal to the + * default data length parameters. Therefore the host should initiate + * the DLE procedure after connection establishment. + */ + BT_HCI_QUIRK_NO_AUTO_DLE = BIT(1), +}; + +/** Possible values for the 'bus' member of the bt_hci_driver struct */ +enum bt_hci_bus { + BT_HCI_BUS_VIRTUAL = 0, + BT_HCI_BUS_USB = 1, + BT_HCI_BUS_PCCARD = 2, + BT_HCI_BUS_UART = 3, + BT_HCI_BUS_RS232 = 4, + BT_HCI_BUS_PCI = 5, + BT_HCI_BUS_SDIO = 6, + BT_HCI_BUS_SPI = 7, + BT_HCI_BUS_I2C = 8, + BT_HCI_BUS_IPM = 9, +}; + +#define BT_DT_HCI_QUIRK_OR(node_id, prop, idx) DT_STRING_TOKEN_BY_IDX(node_id, prop, idx) +#define BT_DT_HCI_QUIRKS_GET(node_id) COND_CODE_1(DT_NODE_HAS_PROP(node_id, bt_hci_quirks), \ + (DT_FOREACH_PROP_ELEM_SEP(node_id, \ + bt_hci_quirks, \ + BT_DT_HCI_QUIRK_OR, \ + (|))), \ + (0)) +#define BT_DT_HCI_QUIRKS_INST_GET(inst) BT_DT_HCI_QUIRKS_GET(DT_DRV_INST(inst)) + +#define BT_DT_HCI_NAME_GET(node_id) DT_PROP_OR(node_id, bt_hci_name, "HCI") +#define BT_DT_HCI_NAME_INST_GET(inst) BT_DT_HCI_NAME_GET(DT_DRV_INST(inst)) + +#define BT_DT_HCI_BUS_GET(node_id) DT_STRING_TOKEN_OR(node_id, bt_hci_bus, BT_HCI_BUS_VIRTUAL) +#define BT_DT_HCI_BUS_INST_GET(inst) BT_DT_HCI_BUS_GET(DT_DRV_INST(inst)) + +typedef int (*bt_hci_recv_t)(const struct device *dev, struct net_buf *buf); + +__subsystem struct bt_hci_driver_api { + int (*open)(const struct device *dev, bt_hci_recv_t recv); + int (*close)(const struct device *dev); + int (*send)(const struct device *dev, struct net_buf *buf); +#if defined(CONFIG_BT_HCI_SETUP) + int (*setup)(const struct device *dev, + const struct bt_hci_setup_params *param); +#endif /* defined(CONFIG_BT_HCI_SETUP) */ +}; + +/** + * @brief Open the HCI transport. + * + * Opens the HCI transport for operation. This function must not + * return until the transport is ready for operation, meaning it + * is safe to start calling the send() handler. + * + * @param dev HCI device + * @param recv This is callback through which the HCI driver provides the + * host with data from the controller. The buffer passed to + * the callback will have its type set with bt_buf_set_type(). + * The callback is expected to be called from thread context. + * + * @return 0 on success or negative POSIX error number on failure. + */ +static inline int bt_hci_open(const struct device *dev, bt_hci_recv_t recv) +{ + const struct bt_hci_driver_api *api = (const struct bt_hci_driver_api *)dev->api; + + return api->open(dev, recv); +} + +/** + * @brief Close the HCI transport. + * + * Closes the HCI transport. This function must not return until the + * transport is closed. + * + * @param dev HCI device + * + * @return 0 on success or negative POSIX error number on failure. + */ +static inline int bt_hci_close(const struct device *dev) +{ + const struct bt_hci_driver_api *api = (const struct bt_hci_driver_api *)dev->api; + + if (api->close == NULL) { + return -ENOSYS; + } + + return api->close(dev); +} + +/** + * @brief Send HCI buffer to controller. + * + * Send an HCI packet to the controller. The packet type of the buffer + * must be set using bt_buf_set_type(). + * + * @note This function must only be called from a cooperative thread. + * + * @param dev HCI device + * @param buf Buffer containing data to be sent to the controller. + * + * @return 0 on success or negative POSIX error number on failure. + */ +static inline int bt_hci_send(const struct device *dev, struct net_buf *buf) +{ + const struct bt_hci_driver_api *api = (const struct bt_hci_driver_api *)dev->api; + + return api->send(dev, buf); +} + +#if defined(CONFIG_BT_HCI_SETUP) || defined(__DOXYGEN__) +/** + * @brief HCI vendor-specific setup + * + * Executes vendor-specific commands sequence to initialize + * BT Controller before BT Host executes Reset sequence. This is normally + * called directly after bt_hci_open(). + * + * @note @kconfig{CONFIG_BT_HCI_SETUP} must be selected for this + * field to be available. + * + * @return 0 on success or negative POSIX error number on failure. + */ +static inline int bt_hci_setup(const struct device *dev, struct bt_hci_setup_params *params) +{ + const struct bt_hci_driver_api *api = (const struct bt_hci_driver_api *)dev->api; + + if (api->setup == NULL) { + return -ENOSYS; + } + + return api->setup(dev, params); +} +#endif + +/** + * @} + */ + +/* The following functions are not strictly part of the HCI driver API, in that + * they do not take as input a struct device which implements the HCI driver API. + */ + +/** + * @brief Setup the HCI transport, which usually means to reset the + * Bluetooth IC. + * + * @note A weak version of this function is included in the H4 driver, so + * defining it is optional per board. + * + * @param dev The device structure for the bus connecting to the IC + * + * @return 0 on success, negative error value on failure + */ +int bt_hci_transport_setup(const struct device *dev); + +/** + * @brief Teardown the HCI transport. + * + * @note A weak version of this function is included in the IPC driver, so + * defining it is optional. NRF5340 includes support to put network core + * in reset state. + * + * @param dev The device structure for the bus connecting to the IC + * + * @return 0 on success, negative error value on faulure + */ +int bt_hci_transport_teardown(const struct device *dev); + +/** Allocate an HCI event buffer. + * + * This function allocates a new buffer for an HCI event. It is given the + * event code and the total length of the parameters. Upon successful return + * the buffer is ready to have the parameters encoded into it. + * + * @param evt HCI event OpCode. + * @param len Length of event parameters. + * + * @return Newly allocated buffer. + */ +struct net_buf *bt_hci_evt_create(uint8_t evt, uint8_t len); + +/** Allocate an HCI Command Complete event buffer. + * + * This function allocates a new buffer for HCI Command Complete event. + * It is given the OpCode (encoded e.g. using the BT_OP macro) and the total + * length of the parameters. Upon successful return the buffer is ready to have + * the parameters encoded into it. + * + * @param op HCI command OpCode. + * @param plen Length of command parameters. + * + * @return Newly allocated buffer. + */ +struct net_buf *bt_hci_cmd_complete_create(uint16_t op, uint8_t plen); + +/** Allocate an HCI Command Status event buffer. + * + * This function allocates a new buffer for HCI Command Status event. + * It is given the OpCode (encoded e.g. using the BT_OP macro) and the status + * code. Upon successful return the buffer is ready to have the parameters + * encoded into it. + * + * @param op HCI command OpCode. + * @param status Status code. + * + * @return Newly allocated buffer. + */ +struct net_buf *bt_hci_cmd_status_create(uint16_t op, uint8_t status); + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_DRIVERS_BLUETOOTH_H_ */ diff --git a/include/zephyr/drivers/bluetooth/hci_driver.h b/include/zephyr/drivers/bluetooth/hci_driver.h index 08aacc853f36c..6f76889876e37 100644 --- a/include/zephyr/drivers/bluetooth/hci_driver.h +++ b/include/zephyr/drivers/bluetooth/hci_driver.h @@ -37,8 +37,6 @@ enum { BT_QUIRK_NO_AUTO_DLE = BIT(1), }; -#define IS_BT_QUIRK_NO_AUTO_DLE(bt_dev) ((bt_dev)->drv->quirks & BT_QUIRK_NO_AUTO_DLE) - /** * @brief Receive data from the controller/HCI driver. * @@ -49,8 +47,10 @@ enum { * @param buf Network buffer containing data from the controller. * * @return 0 on success or negative error number on failure. + * + * @deprecated Use the new HCI driver interface instead: @ref bt_hci_api */ -int bt_recv(struct net_buf *buf); +__deprecated int bt_recv(struct net_buf *buf); /** Possible values for the 'bus' member of the bt_hci_driver struct */ enum bt_hci_driver_bus { @@ -156,8 +156,10 @@ struct bt_hci_driver { * @param drv A bt_hci_driver struct representing the driver. * * @return 0 on success or negative error number on failure. + * + * @deprecated Use the new HCI driver interface instead: @ref bt_hci_api */ -int bt_hci_driver_register(const struct bt_hci_driver *drv); +__deprecated int bt_hci_driver_register(const struct bt_hci_driver *drv); /** * @brief Setup the HCI transport, which usually means to reset the diff --git a/samples/bluetooth/hci_uart/README.rst b/samples/bluetooth/hci_uart/README.rst index a7a82fc8d01d0..84fc12080992b 100644 --- a/samples/bluetooth/hci_uart/README.rst +++ b/samples/bluetooth/hci_uart/README.rst @@ -177,9 +177,9 @@ driver instead of the built-in controller: CONFIG_BT_HCI=y CONFIG_BT_CTLR=n - CONFIG_BT_H4=y -Similarly, the `zephyr,bt-uart` DTS property selects which uart to use: +Similarly, the `zephyr,bt-hci` DTS property selects which HCI instance to use. +The UART needs to have as its child node a HCI UART node: .. code-block:: dts @@ -187,6 +187,14 @@ Similarly, the `zephyr,bt-uart` DTS property selects which uart to use: chosen { zephyr,console = &uart0; zephyr,shell-uart = &uart0; - zephyr,bt-uart = &uart1; + zephyr,bt-hci = &bt_hci_uart; + }; + }; + + &uart1 { + status = "okay"; + bt_hci_uart: bt_hci_uart { + compatible = "zephyr,bt-hci-uart"; + status = "okay"; }; }; diff --git a/samples/bluetooth/hci_uart_3wire/README.rst b/samples/bluetooth/hci_uart_3wire/README.rst index 2b664d499d638..43e9ea0c6d9a8 100644 --- a/samples/bluetooth/hci_uart_3wire/README.rst +++ b/samples/bluetooth/hci_uart_3wire/README.rst @@ -177,9 +177,9 @@ driver instead of the built-in controller: CONFIG_BT_HCI=y CONFIG_BT_CTLR=n - CONFIG_BT_H5=y -Similarly, the `zephyr,bt-uart` DTS property selects which uart to use: +Similarly, the `zephyr,bt-hci` DTS property selects which HCI instance to use. +The UART needs to have as its child node a HCI UART node: .. code-block:: dts @@ -187,6 +187,14 @@ Similarly, the `zephyr,bt-uart` DTS property selects which uart to use: chosen { zephyr,console = &uart0; zephyr,shell-uart = &uart0; - zephyr,bt-uart = &uart1; + zephyr,bt-hci = &bt_hci_uart; + }; + }; + + &uart1 { + status = "okay"; + bt_hci_uart: bt_hci_uart { + compatible = "zephyr,bt-hci-3wire-uart"; + status = "okay"; }; }; diff --git a/samples/bluetooth/hci_uart_async/README.rst b/samples/bluetooth/hci_uart_async/README.rst index 7dbb4bbbdb63c..065231e926c3c 100644 --- a/samples/bluetooth/hci_uart_async/README.rst +++ b/samples/bluetooth/hci_uart_async/README.rst @@ -143,9 +143,9 @@ driver instead of the built-in controller: CONFIG_BT_HCI=y CONFIG_BT_CTLR=n - CONFIG_BT_H4=y -Similarly, the `zephyr,bt-uart` DTS property selects which uart to use: +Similarly, the `zephyr,bt-hci` DTS property selects which HCI instance to use. +The UART needs to have as its child node a HCI UART node: .. code-block:: dts @@ -153,6 +153,14 @@ Similarly, the `zephyr,bt-uart` DTS property selects which uart to use: chosen { zephyr,console = &uart0; zephyr,shell-uart = &uart0; - zephyr,bt-uart = &uart1; + zephyr,bt-hci = &bt_hci_uart; + }; + }; + + &uart1 { + status = "okay"; + bt_hci_uart: bt_hci_uart { + compatible = "zephyr,bt-hci-uart"; + status = "okay"; }; }; diff --git a/samples/bluetooth/hci_uart_async/boards/nrf52_bsim.overlay b/samples/bluetooth/hci_uart_async/boards/nrf52_bsim.overlay index adef7109b3c9f..e3745738a19c8 100644 --- a/samples/bluetooth/hci_uart_async/boards/nrf52_bsim.overlay +++ b/samples/bluetooth/hci_uart_async/boards/nrf52_bsim.overlay @@ -1 +1,3 @@ -/* Purposely empty. To avoid using the one provided by the application */ +&bt_hci_uart { + status = "disabled"; +}; diff --git a/samples/bluetooth/hci_uart_async/src/hci_uart_async.c b/samples/bluetooth/hci_uart_async/src/hci_uart_async.c index e3e32eba4af1f..856ebc4752486 100644 --- a/samples/bluetooth/hci_uart_async/src/hci_uart_async.c +++ b/samples/bluetooth/hci_uart_async/src/hci_uart_async.c @@ -151,10 +151,11 @@ static void send_hw_error(void) struct net_buf *buf = bt_buf_get_rx(BT_BUF_EVT, K_FOREVER); + net_buf_add_u8(buf, BT_HCI_H4_EVT); net_buf_add_mem(buf, hci_evt_hw_err, sizeof(hci_evt_hw_err)); /* Inject the message into the c2h queue. */ - bt_recv(buf); + net_buf_put(&c2h_queue, buf); /* The c2h thread will send the message at some point. The host * will receive it and reset the controller. diff --git a/samples/bluetooth/periodic_adv_conn/sample.yaml b/samples/bluetooth/periodic_adv_conn/sample.yaml index cfc9d0522f492..cc3ea8e24e902 100644 --- a/samples/bluetooth/periodic_adv_conn/sample.yaml +++ b/samples/bluetooth/periodic_adv_conn/sample.yaml @@ -6,10 +6,6 @@ tests: platform_allow: - qemu_cortex_m3 - qemu_x86 - - nrf52840dk/nrf52840 tags: bluetooth integration_platforms: - - nrf52840dk/nrf52840 - extra_configs: - - CONFIG_BT_CTLR=n - - CONFIG_BT_NO_DRIVER=y + - qemu_cortex_m3 diff --git a/samples/bluetooth/periodic_adv_rsp/sample.yaml b/samples/bluetooth/periodic_adv_rsp/sample.yaml index dcb37b9fe4a83..fd22311303b16 100644 --- a/samples/bluetooth/periodic_adv_rsp/sample.yaml +++ b/samples/bluetooth/periodic_adv_rsp/sample.yaml @@ -6,10 +6,6 @@ tests: platform_allow: - qemu_cortex_m3 - qemu_x86 - - nrf52840dk/nrf52840 tags: bluetooth integration_platforms: - - nrf52840dk/nrf52840 - extra_configs: - - CONFIG_BT_CTLR=n - - CONFIG_BT_NO_DRIVER=y + - qemu_cortex_m3 diff --git a/samples/bluetooth/periodic_sync_conn/sample.yaml b/samples/bluetooth/periodic_sync_conn/sample.yaml index e7aca788eea6b..a13d15c8ff0c3 100644 --- a/samples/bluetooth/periodic_sync_conn/sample.yaml +++ b/samples/bluetooth/periodic_sync_conn/sample.yaml @@ -6,10 +6,6 @@ tests: platform_allow: - qemu_cortex_m3 - qemu_x86 - - nrf52840dk/nrf52840 tags: bluetooth integration_platforms: - - nrf52840dk/nrf52840 - extra_configs: - - CONFIG_BT_CTLR=n - - CONFIG_BT_NO_DRIVER=y + - qemu_cortex_m3 diff --git a/samples/bluetooth/periodic_sync_rsp/sample.yaml b/samples/bluetooth/periodic_sync_rsp/sample.yaml index c0f073b19e01b..e31e7f61badd2 100644 --- a/samples/bluetooth/periodic_sync_rsp/sample.yaml +++ b/samples/bluetooth/periodic_sync_rsp/sample.yaml @@ -6,10 +6,6 @@ tests: platform_allow: - qemu_cortex_m3 - qemu_x86 - - nrf52840dk/nrf52840 tags: bluetooth integration_platforms: - - nrf52840dk/nrf52840 - extra_configs: - - CONFIG_BT_CTLR=n - - CONFIG_BT_NO_DRIVER=y + - qemu_cortex_m3 diff --git a/samples/subsys/ipc/ipc_service/icmsg/boards/nrf5340dk_nrf5340_cpuapp.overlay b/samples/subsys/ipc/ipc_service/icmsg/boards/nrf5340dk_nrf5340_cpuapp.overlay index 22650211611f0..f782bdd85784c 100644 --- a/samples/subsys/ipc/ipc_service/icmsg/boards/nrf5340dk_nrf5340_cpuapp.overlay +++ b/samples/subsys/ipc/ipc_service/icmsg/boards/nrf5340dk_nrf5340_cpuapp.overlay @@ -31,6 +31,11 @@ mboxes = <&mbox 0>, <&mbox 1>; mbox-names = "tx", "rx"; status = "okay"; + + bt_hci_ipc0: bt_hci_ipc0 { + compatible = "zephyr,bt-hci-ipc"; + status = "okay"; + }; }; }; }; diff --git a/samples/subsys/ipc/ipc_service/multi_endpoint/boards/nrf5340dk_nrf5340_cpuapp.overlay b/samples/subsys/ipc/ipc_service/multi_endpoint/boards/nrf5340dk_nrf5340_cpuapp.overlay index 35cffd8ad350b..216561b349be0 100644 --- a/samples/subsys/ipc/ipc_service/multi_endpoint/boards/nrf5340dk_nrf5340_cpuapp.overlay +++ b/samples/subsys/ipc/ipc_service/multi_endpoint/boards/nrf5340dk_nrf5340_cpuapp.overlay @@ -39,6 +39,11 @@ mboxes = <&mbox 0>, <&mbox 1>; mbox-names = "tx", "rx"; status = "okay"; + + bt_hci_ipc0: bt_hci_ipc0 { + compatible = "zephyr,bt-hci-ipc"; + status = "okay"; + }; }; ipc1: ipc1 { diff --git a/samples/subsys/ipc/ipc_service/multi_endpoint/boards/nrf5340dk_nrf5340_cpuapp_icbmsg.overlay b/samples/subsys/ipc/ipc_service/multi_endpoint/boards/nrf5340dk_nrf5340_cpuapp_icbmsg.overlay index 3db9db032f4c4..2d85fbbf79c1b 100644 --- a/samples/subsys/ipc/ipc_service/multi_endpoint/boards/nrf5340dk_nrf5340_cpuapp_icbmsg.overlay +++ b/samples/subsys/ipc/ipc_service/multi_endpoint/boards/nrf5340dk_nrf5340_cpuapp_icbmsg.overlay @@ -41,6 +41,11 @@ mboxes = <&mbox 0>, <&mbox 1>; mbox-names = "tx", "rx"; status = "okay"; + + bt_hci_ipc0: bt_hci_ipc0 { + compatible = "zephyr,bt-hci-ipc"; + status = "okay"; + }; }; ipc1: ipc1 { diff --git a/samples/subsys/ipc/ipc_service/static_vrings/boards/nrf5340dk_nrf5340_cpuapp.overlay b/samples/subsys/ipc/ipc_service/static_vrings/boards/nrf5340dk_nrf5340_cpuapp.overlay index 520f007a82179..f07f75fc9a1a7 100644 --- a/samples/subsys/ipc/ipc_service/static_vrings/boards/nrf5340dk_nrf5340_cpuapp.overlay +++ b/samples/subsys/ipc/ipc_service/static_vrings/boards/nrf5340dk_nrf5340_cpuapp.overlay @@ -33,6 +33,11 @@ mbox-names = "tx", "rx"; role = "host"; status = "okay"; + + bt_hci_ipc0: bt_hci_ipc0 { + compatible = "zephyr,bt-hci-ipc"; + status = "okay"; + }; }; ipc1: ipc1 { diff --git a/samples/subsys/logging/multidomain/boards/nrf5340dk_nrf5340_cpuapp.overlay b/samples/subsys/logging/multidomain/boards/nrf5340dk_nrf5340_cpuapp.overlay index eac4af423aef7..75e9f1b57442f 100644 --- a/samples/subsys/logging/multidomain/boards/nrf5340dk_nrf5340_cpuapp.overlay +++ b/samples/subsys/logging/multidomain/boards/nrf5340dk_nrf5340_cpuapp.overlay @@ -34,6 +34,11 @@ mbox-names = "tx", "rx"; role = "host"; status = "okay"; + + bt_hci_ipc0: bt_hci_ipc0 { + status = "okay"; + compatible = "zephyr,bt-hci-ipc"; + }; }; ipc1: ipc1 { diff --git a/soc/ambiq/apollo3x/Kconfig.defconfig.apollo3_blue b/soc/ambiq/apollo3x/Kconfig.defconfig.apollo3_blue index 370ec60873453..4655c8fd20aba 100644 --- a/soc/ambiq/apollo3x/Kconfig.defconfig.apollo3_blue +++ b/soc/ambiq/apollo3x/Kconfig.defconfig.apollo3_blue @@ -12,10 +12,6 @@ config MAIN_STACK_SIZE if BT -choice BT_HCI_BUS_TYPE - default BT_AMBIQ_HCI -endchoice - config BT_BUF_ACL_TX_COUNT default 4 diff --git a/soc/ambiq/apollo3x/Kconfig.defconfig.apollo3p_blue b/soc/ambiq/apollo3x/Kconfig.defconfig.apollo3p_blue index 930c8bc15f5da..a94b45cc59818 100644 --- a/soc/ambiq/apollo3x/Kconfig.defconfig.apollo3p_blue +++ b/soc/ambiq/apollo3x/Kconfig.defconfig.apollo3p_blue @@ -12,10 +12,6 @@ config MAIN_STACK_SIZE if BT -choice BT_HCI_BUS_TYPE - default BT_AMBIQ_HCI -endchoice - config BT_BUF_ACL_TX_COUNT default 4 diff --git a/soc/nxp/rw/Kconfig.defconfig b/soc/nxp/rw/Kconfig.defconfig index d00e99ed2619b..198b0b1a597ec 100644 --- a/soc/nxp/rw/Kconfig.defconfig +++ b/soc/nxp/rw/Kconfig.defconfig @@ -85,10 +85,6 @@ if BT config FLASH default y -choice BT_HCI_BUS_TYPE - default BT_NXP -endchoice - config BT_DIS_MANUF default "NXP" diff --git a/soc/st/stm32/stm32wbax/Kconfig.defconfig b/soc/st/stm32/stm32wbax/Kconfig.defconfig index 6e47a7ba7f3f3..b6dfd878afd52 100644 --- a/soc/st/stm32/stm32wbax/Kconfig.defconfig +++ b/soc/st/stm32/stm32wbax/Kconfig.defconfig @@ -13,11 +13,6 @@ config STM32_LPTIM_TIMER config STM32_FLASH_PREFETCH default y -choice BT_HCI_BUS_TYPE - default BT_STM32WBA - depends on BT -endchoice - config BT_STM32WBA select DYNAMIC_INTERRUPTS select DYNAMIC_DIRECT_INTERRUPTS diff --git a/subsys/bluetooth/common/Kconfig b/subsys/bluetooth/common/Kconfig index 9ccd4e184f6f8..ce64b4d70c8bd 100644 --- a/subsys/bluetooth/common/Kconfig +++ b/subsys/bluetooth/common/Kconfig @@ -175,8 +175,12 @@ config BT_BUF_CMD_TX_COUNT endmenu +# Workaround to have commas on function arguments +ZEPHYR_BT_HCI := zephyr,bt-hci + config BT_HAS_HCI_VS bool + default $(dt_chosen_bool_prop,$(ZEPHYR_BT_HCI),bt-hci-vs-ext) help This option is set by the Bluetooth controller to indicate support for the Zephyr HCI Vendor-Specific Commands and Event. diff --git a/subsys/bluetooth/controller/Kconfig b/subsys/bluetooth/controller/Kconfig index a401502dbfe57..9c21740b813ce 100644 --- a/subsys/bluetooth/controller/Kconfig +++ b/subsys/bluetooth/controller/Kconfig @@ -133,6 +133,7 @@ endchoice config BT_CTLR_HCI bool "Host Controller Interface (HCI)" default y + depends on DT_HAS_ZEPHYR_BT_HCI_LL_SW_SPLIT_ENABLED help Enable the Host Controller interface (HCI) in the Controller. This should almost always be enabled, except in a few special diff --git a/subsys/bluetooth/controller/hci/hci_driver.c b/subsys/bluetooth/controller/hci/hci_driver.c index f174ca02c728c..d5826c9dc592b 100644 --- a/subsys/bluetooth/controller/hci/hci_driver.c +++ b/subsys/bluetooth/controller/hci/hci_driver.c @@ -21,7 +21,7 @@ #include #include -#include +#include #ifdef CONFIG_CLOCK_CONTROL_NRF #include @@ -66,6 +66,12 @@ #include LOG_MODULE_REGISTER(bt_ctlr_hci_driver); +#define DT_DRV_COMPAT zephyr_bt_hci_ll_sw_split + +struct hci_driver_data { + bt_hci_recv_t recv; +}; + static struct k_sem sem_prio_recv; static struct k_fifo recv_fifo; @@ -120,8 +126,10 @@ static inline uint8_t bt_hci_evt_get_flags(uint8_t evt) * tree) 'recv blocking' API to the normal single-receiver * `bt_recv` API. */ -static int bt_recv_prio(struct net_buf *buf) +static int bt_recv_prio(const struct device *dev, struct net_buf *buf) { + struct hci_driver_data *data = dev->data; + if (bt_buf_get_type(buf) == BT_BUF_EVT) { struct bt_hci_evt_hdr *hdr = (void *)buf->data; uint8_t evt_flags = bt_hci_evt_get_flags(hdr->evt); @@ -133,7 +141,7 @@ static int bt_recv_prio(struct net_buf *buf) } } - return bt_recv(buf); + return data->recv(dev, buf); } #if defined(CONFIG_BT_CTLR_ISO) @@ -167,6 +175,8 @@ isoal_status_t sink_sdu_emit_hci(const struct isoal_sink *sink_ctx, const struct isoal_emitted_sdu_frag *sdu_frag, const struct isoal_emitted_sdu *sdu) { + const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0)); + struct hci_driver_data *data = dev->data; struct bt_hci_iso_sdu_ts_hdr *sdu_hdr; uint16_t packet_status_flag; struct bt_hci_iso_hdr *hdr; @@ -249,7 +259,7 @@ isoal_status_t sink_sdu_emit_hci(const struct isoal_sink *sink_ctx, hdr->len = sys_cpu_to_le16(len); /* send fragment up the chain */ - bt_recv(buf); + data->recv(dev, buf); } return ISOAL_STATUS_OK; @@ -322,6 +332,8 @@ static struct net_buf *process_prio_evt(struct node_rx_pdu *node_rx, */ static void prio_recv_thread(void *p1, void *p2, void *p3) { + const struct device *dev = p1; + while (1) { struct node_rx_pdu *node_rx; struct net_buf *buf; @@ -358,7 +370,7 @@ static void prio_recv_thread(void *p1, void *p2, void *p3) false, K_FOREVER); hci_num_cmplt_encode(buf, handle, num_cmplt); LOG_DBG("Num Complete: 0x%04x:%u", handle, num_cmplt); - bt_recv_prio(buf); + bt_recv_prio(dev, buf); k_yield(); #endif /* CONFIG_BT_CONN || CONFIG_BT_CTLR_ADV_ISO || CONFIG_BT_CTLR_CONN_ISO */ } @@ -382,7 +394,7 @@ static void prio_recv_thread(void *p1, void *p2, void *p3) ll_rx_mem_release((void **)&node_rx); } - bt_recv_prio(buf); + bt_recv_prio(dev, buf); /* bt_recv_prio would not release normal evt * buf. */ @@ -661,6 +673,9 @@ static inline struct net_buf *process_hbuf(struct node_rx_pdu *n) */ static void recv_thread(void *p1, void *p2, void *p3) { + const struct device *dev = p1; + struct hci_driver_data *data = dev->data; + #if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL) /* @todo: check if the events structure really needs to be static */ static struct k_poll_event events[2] = { @@ -719,7 +734,7 @@ static void recv_thread(void *p1, void *p2, void *p3) LOG_DBG("Packet in: type:%u len:%u", bt_buf_get_type(frag), frag->len); - bt_recv(frag); + data->recv(dev, frag); } else { net_buf_unref(frag); } @@ -729,7 +744,7 @@ static void recv_thread(void *p1, void *p2, void *p3) } } -static int cmd_handle(struct net_buf *buf) +static int cmd_handle(const struct device *dev, struct net_buf *buf) { struct node_rx_pdu *node_rx = NULL; struct net_buf *evt; @@ -737,7 +752,7 @@ static int cmd_handle(struct net_buf *buf) evt = hci_cmd_handle(buf, (void **) &node_rx); if (evt) { LOG_DBG("Replying with event of %u bytes", evt->len); - bt_recv_prio(evt); + bt_recv_prio(dev, evt); if (node_rx) { LOG_DBG("RX node enqueue"); @@ -750,7 +765,7 @@ static int cmd_handle(struct net_buf *buf) } #if defined(CONFIG_BT_CONN) -static int acl_handle(struct net_buf *buf) +static int acl_handle(const struct device *dev, struct net_buf *buf) { struct net_buf *evt; int err; @@ -758,7 +773,7 @@ static int acl_handle(struct net_buf *buf) err = hci_acl_handle(buf, &evt); if (evt) { LOG_DBG("Replying with event of %u bytes", evt->len); - bt_recv_prio(evt); + bt_recv_prio(dev, evt); } return err; @@ -766,7 +781,7 @@ static int acl_handle(struct net_buf *buf) #endif /* CONFIG_BT_CONN */ #if defined(CONFIG_BT_CTLR_ADV_ISO) || defined(CONFIG_BT_CTLR_CONN_ISO) -static int iso_handle(struct net_buf *buf) +static int iso_handle(const struct device *dev, struct net_buf *buf) { struct net_buf *evt; int err; @@ -774,14 +789,14 @@ static int iso_handle(struct net_buf *buf) err = hci_iso_handle(buf, &evt); if (evt) { LOG_DBG("Replying with event of %u bytes", evt->len); - bt_recv_prio(evt); + bt_recv_prio(dev, evt); } return err; } #endif /* CONFIG_BT_CTLR_ADV_ISO || CONFIG_BT_CTLR_CONN_ISO */ -static int hci_driver_send(struct net_buf *buf) +static int hci_driver_send(const struct device *dev, struct net_buf *buf) { uint8_t type; int err; @@ -797,15 +812,15 @@ static int hci_driver_send(struct net_buf *buf) switch (type) { #if defined(CONFIG_BT_CONN) case BT_BUF_ACL_OUT: - err = acl_handle(buf); + err = acl_handle(dev, buf); break; #endif /* CONFIG_BT_CONN */ case BT_BUF_CMD: - err = cmd_handle(buf); + err = cmd_handle(dev, buf); break; #if defined(CONFIG_BT_CTLR_ADV_ISO) || defined(CONFIG_BT_CTLR_CONN_ISO) case BT_BUF_ISO_OUT: - err = iso_handle(buf); + err = iso_handle(dev, buf); break; #endif /* CONFIG_BT_CTLR_ADV_ISO || CONFIG_BT_CTLR_CONN_ISO */ default: @@ -822,8 +837,9 @@ static int hci_driver_send(struct net_buf *buf) return err; } -static int hci_driver_open(void) +static int hci_driver_open(const struct device *dev, bt_hci_recv_t recv) { + struct hci_driver_data *data = dev->data; uint32_t err; DEBUG_INIT(); @@ -837,6 +853,8 @@ static int hci_driver_open(void) return err; } + data->recv = recv; + #if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL) k_poll_signal_init(&hbuf_signal); hci_init(&hbuf_signal); @@ -846,13 +864,13 @@ static int hci_driver_open(void) k_thread_create(&prio_recv_thread_data, prio_recv_thread_stack, K_KERNEL_STACK_SIZEOF(prio_recv_thread_stack), - prio_recv_thread, NULL, NULL, NULL, + prio_recv_thread, (void *)dev, NULL, NULL, K_PRIO_COOP(CONFIG_BT_DRIVER_RX_HIGH_PRIO), 0, K_NO_WAIT); k_thread_name_set(&prio_recv_thread_data, "BT RX pri"); k_thread_create(&recv_thread_data, recv_thread_stack, K_KERNEL_STACK_SIZEOF(recv_thread_stack), - recv_thread, NULL, NULL, NULL, + recv_thread, (void *)dev, NULL, NULL, K_PRIO_COOP(CONFIG_BT_RX_PRIO), 0, K_NO_WAIT); k_thread_name_set(&recv_thread_data, "BT RX"); @@ -861,8 +879,10 @@ static int hci_driver_open(void) return 0; } -static int hci_driver_close(void) +static int hci_driver_close(const struct device *dev) { + struct hci_driver_data *data = dev->data; + /* Resetting the LL stops all roles */ ll_deinit(); @@ -872,24 +892,22 @@ static int hci_driver_close(void) /* Abort RX thread */ k_thread_abort(&recv_thread_data); + /* Clear the (host) receive callback */ + data->recv = NULL; + return 0; } -static const struct bt_hci_driver drv = { - .name = "Controller", - .bus = BT_HCI_DRIVER_BUS_VIRTUAL, - .quirks = BT_QUIRK_NO_AUTO_DLE, - .open = hci_driver_open, +static const struct bt_hci_driver_api hci_driver_api = { + .open = hci_driver_open, .close = hci_driver_close, - .send = hci_driver_send, + .send = hci_driver_send, }; -static int hci_driver_init(void) -{ - - bt_hci_driver_register(&drv); - - return 0; -} +#define BT_HCI_CONTROLLER_INIT(inst) \ + static struct hci_driver_data data_##inst; \ + DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &data_##inst, NULL, POST_KERNEL, \ + CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &hci_driver_api) -SYS_INIT(hci_driver_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); +/* Only a single instance is supported */ +BT_HCI_CONTROLLER_INIT(0) diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index fcdb69a75778f..52aa6b39c1562 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -27,7 +27,11 @@ #include #include #include +#if DT_HAS_CHOSEN(zephyr_bt_hci) +#include +#else #include +#endif #include "common/bt_str.h" #include "common/assert.h" @@ -63,6 +67,10 @@ #include LOG_MODULE_REGISTER(bt_hci_core); +#define BT_HCI_DEV DT_CHOSEN(zephyr_bt_hci) +#define BT_HCI_BUS BT_DT_HCI_BUS_GET(BT_HCI_DEV) +#define BT_HCI_NAME BT_DT_HCI_NAME_GET(BT_HCI_DEV) + #define HCI_CMD_TIMEOUT K_SECONDS(10) /* Stacks for the threads */ @@ -85,6 +93,9 @@ struct bt_dev bt_dev = { #if defined(CONFIG_BT_DEVICE_APPEARANCE_DYNAMIC) .appearance = CONFIG_BT_DEVICE_APPEARANCE, #endif +#if DT_HAS_CHOSEN(zephyr_bt_hci) + .hci = DEVICE_DT_GET(BT_HCI_DEV), +#endif }; static bt_ready_cb_t ready_cb; @@ -112,6 +123,28 @@ static struct cmd_data cmd_data[CONFIG_BT_BUF_CMD_TX_COUNT]; #define cmd(buf) (&cmd_data[net_buf_id(buf)]) #define acl(buf) ((struct acl_data *)net_buf_user_data(buf)) +#if DT_HAS_CHOSEN(zephyr_bt_hci) +static bool drv_quirk_no_reset(void) +{ + return ((BT_DT_HCI_QUIRKS_GET(DT_CHOSEN(zephyr_bt_hci)) & BT_HCI_QUIRK_NO_RESET) != 0); +} + +__maybe_unused static bool drv_quirk_no_auto_dle(void) +{ + return ((BT_DT_HCI_QUIRKS_GET(DT_CHOSEN(zephyr_bt_hci)) & BT_HCI_QUIRK_NO_AUTO_DLE) != 0); +} +#else +static bool drv_quirk_no_reset(void) +{ + return ((bt_dev.drv->quirks & BT_QUIRK_NO_RESET) != 0); +} + +__maybe_unused static bool drv_quirk_no_auto_dle(void) +{ + return ((bt_dev.drv->quirks & BT_QUIRK_NO_AUTO_DLE) != 0); +} +#endif + void bt_hci_cmd_state_set_init(struct net_buf *buf, struct bt_hci_cmd_state_set *state, atomic_t *target, int bit, bool val) @@ -1150,7 +1183,7 @@ static void conn_auto_initiate(struct bt_conn *conn) if (IS_ENABLED(CONFIG_BT_AUTO_DATA_LEN_UPDATE) && BT_FEAT_LE_DLE(bt_dev.le.features)) { - if (IS_BT_QUIRK_NO_AUTO_DLE(&bt_dev)) { + if (drv_quirk_no_auto_dle()) { uint16_t tx_octets, tx_time; err = hci_le_read_max_data_len(&tx_octets, &tx_time); @@ -3175,7 +3208,7 @@ static int common_init(void) struct net_buf *rsp; int err; - if (!(bt_dev.drv->quirks & BT_QUIRK_NO_RESET)) { + if (!drv_quirk_no_reset()) { /* Send HCI_RESET */ err = bt_hci_cmd_send_sync(BT_HCI_OP_RESET, NULL, &rsp); if (err) { @@ -3879,12 +3912,19 @@ static int hci_init(void) } #endif /* defined(CONFIG_BT_HCI_SET_PUBLIC_ADDR) */ +#if DT_HAS_CHOSEN(zephyr_bt_hci) + err = bt_hci_setup(bt_dev.hci, &setup_params); + if (err && err != -ENOSYS) { + return err; + } +#else if (bt_dev.drv->setup) { err = bt_dev.drv->setup(&setup_params); if (err) { return err; } } +#endif #endif /* defined(CONFIG_BT_HCI_SETUP) */ err = common_init(); @@ -3939,7 +3979,11 @@ int bt_send(struct net_buf *buf) return bt_hci_ecc_send(buf); } +#if DT_HAS_CHOSEN(zephyr_bt_hci) + return bt_hci_send(bt_dev.hci, buf); +#else return bt_dev.drv->send(buf); +#endif } static const struct event_handler prio_events[] = { @@ -4041,8 +4085,14 @@ static int bt_recv_unsafe(struct net_buf *buf) } } +#if DT_HAS_CHOSEN(zephyr_bt_hci) +int bt_hci_recv(const struct device *dev, struct net_buf *buf) +{ + ARG_UNUSED(dev); +#else int bt_recv(struct net_buf *buf) { +#endif int err; k_sched_lock(); @@ -4052,6 +4102,8 @@ int bt_recv(struct net_buf *buf) return err; } +/* Old-style HCI driver registration */ +#if !DT_HAS_CHOSEN(zephyr_bt_hci) int bt_hci_driver_register(const struct bt_hci_driver *drv) { if (bt_dev.drv) { @@ -4071,6 +4123,7 @@ int bt_hci_driver_register(const struct bt_hci_driver *drv) return 0; } +#endif /* !DT_HAS_CHOSEN(zephyr_bt_hci) */ void bt_finalize_init(void) { @@ -4192,10 +4245,19 @@ int bt_enable(bt_ready_cb_t cb) { int err; +#if DT_HAS_CHOSEN(zephyr_bt_hci) + if (!device_is_ready(bt_dev.hci)) { + LOG_ERR("HCI driver is not ready"); + return -ENODEV; + } + + bt_monitor_new_index(BT_MONITOR_TYPE_PRIMARY, BT_HCI_BUS, BT_ADDR_ANY, BT_HCI_NAME); +#else /* !DT_HAS_CHONSEN(zephyr_bt_hci) */ if (!bt_dev.drv) { LOG_ERR("No HCI driver registered"); return -ENODEV; } +#endif atomic_clear_bit(bt_dev.flags, BT_DEV_DISABLE); @@ -4244,7 +4306,11 @@ int bt_enable(bt_ready_cb_t cb) k_thread_name_set(&bt_workq.thread, "BT RX WQ"); #endif +#if DT_HAS_CHOSEN(zephyr_bt_hci) + err = bt_hci_open(bt_dev.hci, bt_hci_recv); +#else err = bt_dev.drv->open(); +#endif if (err) { LOG_ERR("HCI driver open failed (%d)", err); return err; @@ -4264,6 +4330,7 @@ int bt_disable(void) { int err; +#if !DT_HAS_CHOSEN(zephyr_bt_hci) if (!bt_dev.drv) { LOG_ERR("No HCI driver registered"); return -ENODEV; @@ -4272,6 +4339,7 @@ int bt_disable(void) if (!bt_dev.drv->close) { return -ENOTSUP; } +#endif if (atomic_test_and_set_bit(bt_dev.flags, BT_DEV_DISABLE)) { return -EALREADY; @@ -4280,29 +4348,6 @@ int bt_disable(void) /* Clear BT_DEV_READY before disabling HCI link */ atomic_clear_bit(bt_dev.flags, BT_DEV_READY); - err = bt_dev.drv->close(); - if (err) { - LOG_ERR("HCI driver close failed (%d)", err); - - /* Re-enable BT_DEV_READY to avoid inconsistent stack state */ - atomic_set_bit(bt_dev.flags, BT_DEV_READY); - - return err; - } - - /* Some functions rely on checking this bitfield */ - memset(bt_dev.supported_commands, 0x00, sizeof(bt_dev.supported_commands)); - - /* Reset IDs and corresponding keys. */ - bt_dev.id_count = 0; -#if defined(CONFIG_BT_SMP) - bt_dev.le.rl_entries = 0; - bt_keys_reset(); -#endif - - /* If random address was set up - clear it */ - bt_addr_le_copy(&bt_dev.random_addr, BT_ADDR_LE_ANY); - #if defined(CONFIG_BT_BROADCASTER) bt_adv_reset_adv_pool(); #endif /* CONFIG_BT_BROADCASTER */ @@ -4331,6 +4376,38 @@ int bt_disable(void) k_thread_abort(&bt_workq.thread); #endif +#if DT_HAS_CHOSEN(zephyr_bt_hci) + err = bt_hci_close(bt_dev.hci); + if (err == -ENOSYS) { + atomic_clear_bit(bt_dev.flags, BT_DEV_DISABLE); + atomic_set_bit(bt_dev.flags, BT_DEV_READY); + return -ENOTSUP; + } +#else + err = bt_dev.drv->close(); +#endif + if (err) { + LOG_ERR("HCI driver close failed (%d)", err); + + /* Re-enable BT_DEV_READY to avoid inconsistent stack state */ + atomic_set_bit(bt_dev.flags, BT_DEV_READY); + + return err; + } + + /* Some functions rely on checking this bitfield */ + memset(bt_dev.supported_commands, 0x00, sizeof(bt_dev.supported_commands)); + + /* Reset IDs and corresponding keys. */ + bt_dev.id_count = 0; +#if defined(CONFIG_BT_SMP) + bt_dev.le.rl_entries = 0; + bt_keys_reset(); +#endif + + /* If random address was set up - clear it */ + bt_addr_le_copy(&bt_dev.random_addr, BT_ADDR_LE_ANY); + if (IS_ENABLED(CONFIG_BT_ISO)) { bt_iso_reset(); } diff --git a/subsys/bluetooth/host/hci_core.h b/subsys/bluetooth/host/hci_core.h index 8c5dcb6d31f4c..8bb98bb1b4251 100644 --- a/subsys/bluetooth/host/hci_core.h +++ b/subsys/bluetooth/host/hci_core.h @@ -7,6 +7,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + /* LL connection parameters */ #define LE_CONN_LATENCY 0x0000 #define LE_CONN_TIMEOUT 0x002a @@ -403,8 +405,12 @@ struct bt_dev { /* Queue for outgoing HCI commands */ struct k_fifo cmd_tx_queue; +#if DT_HAS_CHOSEN(zephyr_bt_hci) + const struct device *hci; +#else /* Registered HCI driver */ const struct bt_hci_driver *drv; +#endif #if defined(CONFIG_BT_PRIVACY) /* Local Identity Resolving Key */ @@ -439,6 +445,10 @@ extern sys_slist_t bt_auth_info_cbs; enum bt_security_err bt_security_err_get(uint8_t hci_err); #endif /* CONFIG_BT_SMP || CONFIG_BT_CLASSIC */ +#if DT_HAS_CHOSEN(zephyr_bt_hci) +int bt_hci_recv(const struct device *dev, struct net_buf *buf); +#endif + /* Data type to store state related with command to be updated * when command completes successfully. */ diff --git a/subsys/bluetooth/host/hci_ecc.c b/subsys/bluetooth/host/hci_ecc.c index 8c1b1a777b9dd..718d90176fa7d 100644 --- a/subsys/bluetooth/host/hci_ecc.c +++ b/subsys/bluetooth/host/hci_ecc.c @@ -19,9 +19,14 @@ #include #include +#include #include #include +#if DT_HAS_CHOSEN(zephyr_bt_hci) +#include +#else #include +#endif #include "common/bt_str.h" @@ -92,7 +97,11 @@ static void send_cmd_status(uint16_t opcode, uint8_t status) evt->opcode = sys_cpu_to_le16(opcode); evt->status = status; +#if DT_HAS_CHOSEN(zephyr_bt_hci) + bt_hci_recv(bt_dev.hci, buf); +#else bt_recv(buf); +#endif } static uint8_t generate_keys(void) @@ -154,7 +163,11 @@ static void emulate_le_p256_public_key_cmd(void) atomic_clear_bit(flags, PENDING_PUB_KEY); +#if DT_HAS_CHOSEN(zephyr_bt_hci) + bt_hci_recv(bt_dev.hci, buf); +#else bt_recv(buf); +#endif } static void emulate_le_generate_dhkey(void) @@ -202,7 +215,11 @@ static void emulate_le_generate_dhkey(void) atomic_clear_bit(flags, PENDING_DHKEY); +#if DT_HAS_CHOSEN(zephyr_bt_hci) + bt_hci_recv(bt_dev.hci, buf); +#else bt_recv(buf); +#endif } static void ecc_process(struct k_work *work) @@ -327,7 +344,11 @@ int bt_hci_ecc_send(struct net_buf *buf) } } +#if DT_HAS_CHOSEN(zephyr_bt_hci) + return bt_hci_send(bt_dev.hci, buf); +#else return bt_dev.drv->send(buf); +#endif } void bt_hci_ecc_supported_commands(uint8_t *supported_commands) diff --git a/subsys/bluetooth/host/hci_raw.c b/subsys/bluetooth/host/hci_raw.c index 2aa8a4fe3d1dc..64340c22108e6 100644 --- a/subsys/bluetooth/host/hci_raw.c +++ b/subsys/bluetooth/host/hci_raw.c @@ -9,8 +9,13 @@ #include #include #include +#include +#if DT_HAS_CHOSEN(zephyr_bt_hci) +#include +#else #include +#endif #include #include #include @@ -26,12 +31,6 @@ #include LOG_MODULE_REGISTER(bt_hci_raw); -#define H4_CMD 0x01 -#define H4_ACL 0x02 -#define H4_SCO 0x03 -#define H4_EVT 0x04 -#define H4_ISO 0x05 - static struct k_fifo *raw_rx; #if defined(CONFIG_BT_HCI_RAW_H4_ENABLE) @@ -54,10 +53,19 @@ NET_BUF_POOL_FIXED_DEFINE(hci_iso_pool, CONFIG_BT_ISO_TX_BUF_COUNT, sizeof(struct bt_buf_data), NULL); #endif /* CONFIG_BT_ISO */ -struct bt_dev_raw bt_dev; +#define BT_HCI_DEV DT_CHOSEN(zephyr_bt_hci) +#define BT_HCI_BUS BT_DT_HCI_BUS_GET(BT_HCI_DEV) +#define BT_HCI_NAME BT_DT_HCI_NAME_GET(BT_HCI_DEV) + +struct bt_dev_raw bt_dev = { +#if DT_HAS_CHOSEN(zephyr_bt_hci) + .hci = DEVICE_DT_GET(BT_HCI_DEV), +#endif +}; struct bt_hci_raw_cmd_ext *cmd_ext; static size_t cmd_ext_size; +#if !DT_HAS_CHOSEN(zephyr_bt_hci) int bt_hci_driver_register(const struct bt_hci_driver *drv) { if (bt_dev.drv) { @@ -77,6 +85,7 @@ int bt_hci_driver_register(const struct bt_hci_driver *drv) return 0; } +#endif struct net_buf *bt_buf_get_rx(enum bt_buf_type type, k_timeout_t timeout) { @@ -127,16 +136,16 @@ struct net_buf *bt_buf_get_tx(enum bt_buf_type type, k_timeout_t timeout, uint8_t h4_type = ((uint8_t *)data)[0]; switch (h4_type) { - case H4_CMD: + case BT_HCI_H4_CMD: type = BT_BUF_CMD; pool = &hci_cmd_pool; break; - case H4_ACL: + case BT_HCI_H4_ACL: type = BT_BUF_ACL_OUT; pool = &hci_acl_pool; break; #if defined(CONFIG_BT_ISO) - case H4_ISO: + case BT_HCI_H4_ISO: type = BT_BUF_ISO_OUT; pool = &hci_iso_pool; break; @@ -182,8 +191,14 @@ struct net_buf *bt_buf_get_evt(uint8_t evt, bool discardable, k_timeout_t timeou return bt_buf_get_rx(BT_BUF_EVT, timeout); } +#if DT_HAS_CHOSEN(zephyr_bt_hci) +int bt_hci_recv(const struct device *dev, struct net_buf *buf) +{ + ARG_UNUSED(dev); +#else int bt_recv(struct net_buf *buf) { +#endif LOG_DBG("buf %p len %u", buf, buf->len); bt_monitor_send(bt_monitor_opcode(buf), buf->data, buf->len); @@ -192,14 +207,14 @@ int bt_recv(struct net_buf *buf) raw_mode == BT_HCI_RAW_MODE_H4) { switch (bt_buf_get_type(buf)) { case BT_BUF_EVT: - net_buf_push_u8(buf, H4_EVT); + net_buf_push_u8(buf, BT_HCI_H4_EVT); break; case BT_BUF_ACL_IN: - net_buf_push_u8(buf, H4_ACL); + net_buf_push_u8(buf, BT_HCI_H4_ACL); break; case BT_BUF_ISO_IN: if (IS_ENABLED(CONFIG_BT_ISO)) { - net_buf_push_u8(buf, H4_ISO); + net_buf_push_u8(buf, BT_HCI_H4_ISO); break; } __fallthrough; @@ -228,7 +243,11 @@ static void bt_cmd_complete_ext(uint16_t op, uint8_t status) cc = net_buf_add(buf, sizeof(*cc)); cc->status = status; +#if DT_HAS_CHOSEN(zephyr_bt_hci) + bt_hci_recv(bt_dev.hci, buf); +#else bt_recv(buf); +#endif } static uint8_t bt_send_ext(struct net_buf *buf) @@ -308,7 +327,11 @@ int bt_send(struct net_buf *buf) return bt_hci_ecc_send(buf); } +#if DT_HAS_CHOSEN(zephyr_bt_hci) + return bt_hci_send(bt_dev.hci, buf); +#else return bt_dev.drv->send(buf); +#endif } int bt_hci_raw_set_mode(uint8_t mode) @@ -346,19 +369,31 @@ void bt_hci_raw_cmd_ext_register(struct bt_hci_raw_cmd_ext *cmds, size_t size) int bt_enable_raw(struct k_fifo *rx_queue) { - const struct bt_hci_driver *drv = bt_dev.drv; int err; LOG_DBG(""); raw_rx = rx_queue; - if (!bt_dev.drv) { +#if DT_HAS_CHOSEN(zephyr_bt_hci) + if (!device_is_ready(bt_dev.hci)) { + LOG_ERR("HCI driver is not ready"); + return -ENODEV; + } + + bt_monitor_new_index(BT_MONITOR_TYPE_PRIMARY, BT_HCI_BUS, BT_ADDR_ANY, BT_HCI_NAME); + + err = bt_hci_open(bt_dev.hci, bt_hci_recv); +#else + const struct bt_hci_driver *drv = bt_dev.drv; + + if (!drv) { LOG_ERR("No HCI driver registered"); return -ENODEV; } err = drv->open(); +#endif if (err) { LOG_ERR("HCI driver open failed (%d)", err); return err; diff --git a/subsys/bluetooth/host/hci_raw_internal.h b/subsys/bluetooth/host/hci_raw_internal.h index 9539cc1035076..af09144f78596 100644 --- a/subsys/bluetooth/host/hci_raw_internal.h +++ b/subsys/bluetooth/host/hci_raw_internal.h @@ -6,15 +6,26 @@ #ifndef __BT_HCI_RAW_INTERNAL_H #define __BT_HCI_RAW_INTERNAL_H +#include +#include + #ifdef __cplusplus extern "C" { #endif struct bt_dev_raw { +#if DT_HAS_CHOSEN(zephyr_bt_hci) + const struct device *hci; +#else /* Registered HCI driver */ const struct bt_hci_driver *drv; +#endif }; +#if DT_HAS_CHOSEN(zephyr_bt_hci) +int bt_hci_recv(const struct device *dev, struct net_buf *buf); +#endif + extern struct bt_dev_raw bt_dev; #ifdef __cplusplus diff --git a/subsys/testsuite/boards/unit_testing/unit_testing/Kconfig.defconfig b/subsys/testsuite/boards/unit_testing/unit_testing/Kconfig.defconfig index 38c6d4b301988..8bc3b63d77886 100644 --- a/subsys/testsuite/boards/unit_testing/unit_testing/Kconfig.defconfig +++ b/subsys/testsuite/boards/unit_testing/unit_testing/Kconfig.defconfig @@ -2,12 +2,11 @@ # # Copyright (c) 2022 Nordic Semiconductor -# Bluetooth unit tests expect this backend -choice BT_HCI_BUS_TYPE - default BT_NO_DRIVER -endchoice - # Controller HCI support requires e.g. devicetree, which isn't available # for unit tests. config BT_CTLR_HCI default n + +# Bluetooth unit tests assume HCI vendor extensions are available +config BT_HAS_HCI_VS + default y diff --git a/tests/bluetooth/addr/prj.conf b/tests/bluetooth/addr/prj.conf index fec5098eecffe..1f86a43c20848 100644 --- a/tests/bluetooth/addr/prj.conf +++ b/tests/bluetooth/addr/prj.conf @@ -3,4 +3,4 @@ CONFIG_ZTEST=y CONFIG_BT=y CONFIG_BT_CTLR=n -CONFIG_BT_NO_DRIVER=y +CONFIG_BT_H4=n diff --git a/tests/bluetooth/addr/test.overlay b/tests/bluetooth/addr/test.overlay new file mode 100644 index 0000000000000..badbe2f392aac --- /dev/null +++ b/tests/bluetooth/addr/test.overlay @@ -0,0 +1,5 @@ +/ { + chosen { + /delete-property/ zephyr,bt-hci; + }; +}; diff --git a/tests/bluetooth/addr/testcase.yaml b/tests/bluetooth/addr/testcase.yaml index c4746b2da2990..54cfe092aeecb 100644 --- a/tests/bluetooth/addr/testcase.yaml +++ b/tests/bluetooth/addr/testcase.yaml @@ -1,5 +1,7 @@ tests: bluetooth.addr: + extra_args: + - EXTRA_DTC_OVERLAY_FILE="test.overlay" platform_allow: - native_posix - native_posix/native/64 diff --git a/tests/bluetooth/bluetooth/dts/bindings/zephyr,bt-hci-test.yaml b/tests/bluetooth/bluetooth/dts/bindings/zephyr,bt-hci-test.yaml new file mode 100644 index 0000000000000..cd5c0ecd76074 --- /dev/null +++ b/tests/bluetooth/bluetooth/dts/bindings/zephyr,bt-hci-test.yaml @@ -0,0 +1,11 @@ +description: Bluetooth HCI for test purposes + +compatible: "zephyr,bt-hci-test" + +include: bt-hci.yaml + +properties: + bt-hci-name: + default: "test" + bt-hci-bus: + default: "BT_HCI_BUS_VIRTUAL" diff --git a/tests/bluetooth/bluetooth/prj.conf b/tests/bluetooth/bluetooth/prj.conf index ee911c4313276..43ee74e49e6ff 100644 --- a/tests/bluetooth/bluetooth/prj.conf +++ b/tests/bluetooth/bluetooth/prj.conf @@ -1,6 +1,6 @@ CONFIG_BT=y CONFIG_BT_CTLR=n -CONFIG_BT_NO_DRIVER=y +CONFIG_BT_H4=n CONFIG_LOG=y CONFIG_UART_INTERRUPT_DRIVEN=n CONFIG_ZTEST=y diff --git a/tests/bluetooth/bluetooth/src/bluetooth.c b/tests/bluetooth/bluetooth/src/bluetooth.c index 4b02efdcdc977..92889f9b598ea 100644 --- a/tests/bluetooth/bluetooth/src/bluetooth.c +++ b/tests/bluetooth/bluetooth/src/bluetooth.c @@ -13,11 +13,16 @@ #include #include -#include +#include + +#define DT_DRV_COMPAT zephyr_bt_hci_test + +struct driver_data { +}; #define EXPECTED_ERROR -ENOSYS -static int driver_open(void) +static int driver_open(const struct device *dev, bt_hci_recv_t recv) { TC_PRINT("driver: %s\n", __func__); @@ -25,29 +30,28 @@ static int driver_open(void) return EXPECTED_ERROR; } -static int driver_send(struct net_buf *buf) +static int driver_send(const struct device *dev, struct net_buf *buf) { return 0; } -static const struct bt_hci_driver drv = { - .name = "test", - .bus = BT_HCI_DRIVER_BUS_VIRTUAL, - .open = driver_open, - .send = driver_send, +static const struct bt_hci_driver_api driver_api = { + .open = driver_open, + .send = driver_send, }; -static void driver_init(void) -{ - bt_hci_driver_register(&drv); -} +#define TEST_DEVICE_INIT(inst) \ + static struct driver_data driver_data_##inst = { \ + }; \ + DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &driver_data_##inst, NULL, \ + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &driver_api) + +DT_INST_FOREACH_STATUS_OKAY(TEST_DEVICE_INIT) ZTEST_SUITE(test_bluetooth, NULL, NULL, NULL, NULL, NULL); ZTEST(test_bluetooth, test_bluetooth_entry) { - driver_init(); - zassert_true((bt_enable(NULL) == EXPECTED_ERROR), "bt_enable failed"); } diff --git a/tests/bluetooth/bluetooth/test.overlay b/tests/bluetooth/bluetooth/test.overlay new file mode 100644 index 0000000000000..c0f0b1c5b2998 --- /dev/null +++ b/tests/bluetooth/bluetooth/test.overlay @@ -0,0 +1,10 @@ +/ { + chosen { + zephyr,bt-hci = &bt_hci_test; + }; + + bt_hci_test: bt_hci_test { + compatible = "zephyr,bt-hci-test"; + status = "okay"; + }; +}; diff --git a/tests/bluetooth/bluetooth/testcase.yaml b/tests/bluetooth/bluetooth/testcase.yaml index a7dccced9ea0b..3c54ea6f7bfe4 100644 --- a/tests/bluetooth/bluetooth/testcase.yaml +++ b/tests/bluetooth/bluetooth/testcase.yaml @@ -1,5 +1,7 @@ tests: bluetooth.general: + extra_args: + - EXTRA_DTC_OVERLAY_FILE="test.overlay" platform_allow: - qemu_x86 - qemu_cortex_m3 diff --git a/tests/bluetooth/bt_crypto/prj.conf b/tests/bluetooth/bt_crypto/prj.conf index fec5098eecffe..1f86a43c20848 100644 --- a/tests/bluetooth/bt_crypto/prj.conf +++ b/tests/bluetooth/bt_crypto/prj.conf @@ -3,4 +3,4 @@ CONFIG_ZTEST=y CONFIG_BT=y CONFIG_BT_CTLR=n -CONFIG_BT_NO_DRIVER=y +CONFIG_BT_H4=n diff --git a/tests/bluetooth/bt_crypto/test.overlay b/tests/bluetooth/bt_crypto/test.overlay new file mode 100644 index 0000000000000..badbe2f392aac --- /dev/null +++ b/tests/bluetooth/bt_crypto/test.overlay @@ -0,0 +1,5 @@ +/ { + chosen { + /delete-property/ zephyr,bt-hci; + }; +}; diff --git a/tests/bluetooth/bt_crypto/testcase.yaml b/tests/bluetooth/bt_crypto/testcase.yaml index e486846175e21..430d763d0cb23 100644 --- a/tests/bluetooth/bt_crypto/testcase.yaml +++ b/tests/bluetooth/bt_crypto/testcase.yaml @@ -1,5 +1,7 @@ tests: bluetooth.bt_crypto: + extra_args: + - EXTRA_DTC_OVERLAY_FILE="test.overlay" platform_allow: - native_posix - native_posix/native/64 diff --git a/tests/bluetooth/bt_crypto_ccm/prj.conf b/tests/bluetooth/bt_crypto_ccm/prj.conf index 68662d4a0c581..4ab1d5395f7fc 100644 --- a/tests/bluetooth/bt_crypto_ccm/prj.conf +++ b/tests/bluetooth/bt_crypto_ccm/prj.conf @@ -3,6 +3,6 @@ CONFIG_ZTEST=y CONFIG_BT=y CONFIG_BT_CTLR=n -CONFIG_BT_NO_DRIVER=y +CONFIG_BT_H4=n CONFIG_LOG=y diff --git a/tests/bluetooth/bt_crypto_ccm/test.overlay b/tests/bluetooth/bt_crypto_ccm/test.overlay new file mode 100644 index 0000000000000..badbe2f392aac --- /dev/null +++ b/tests/bluetooth/bt_crypto_ccm/test.overlay @@ -0,0 +1,5 @@ +/ { + chosen { + /delete-property/ zephyr,bt-hci; + }; +}; diff --git a/tests/bluetooth/bt_crypto_ccm/testcase.yaml b/tests/bluetooth/bt_crypto_ccm/testcase.yaml index 43c35f6a757b7..77dd0dcbb8e12 100644 --- a/tests/bluetooth/bt_crypto_ccm/testcase.yaml +++ b/tests/bluetooth/bt_crypto_ccm/testcase.yaml @@ -1,5 +1,7 @@ tests: bluetooth.bt_crypto_ccm: + extra_args: + - EXTRA_DTC_OVERLAY_FILE="test.overlay" platform_allow: - native_posix - native_posix/native/64 diff --git a/tests/bluetooth/gatt/prj.conf b/tests/bluetooth/gatt/prj.conf index c59f96a921e17..f705142d55275 100644 --- a/tests/bluetooth/gatt/prj.conf +++ b/tests/bluetooth/gatt/prj.conf @@ -3,7 +3,7 @@ CONFIG_ZTEST=y CONFIG_BT=y CONFIG_BT_CTLR=n -CONFIG_BT_NO_DRIVER=y +CONFIG_BT_H4=n CONFIG_LOG=y CONFIG_BT_PERIPHERAL=y diff --git a/tests/bluetooth/gatt/test.overlay b/tests/bluetooth/gatt/test.overlay new file mode 100644 index 0000000000000..badbe2f392aac --- /dev/null +++ b/tests/bluetooth/gatt/test.overlay @@ -0,0 +1,5 @@ +/ { + chosen { + /delete-property/ zephyr,bt-hci; + }; +}; diff --git a/tests/bluetooth/gatt/testcase.yaml b/tests/bluetooth/gatt/testcase.yaml index 5e1fa97a4b998..135f6d823ede4 100644 --- a/tests/bluetooth/gatt/testcase.yaml +++ b/tests/bluetooth/gatt/testcase.yaml @@ -1,5 +1,7 @@ tests: bluetooth.gatt: + extra_args: + - EXTRA_DTC_OVERLAY_FILE="test.overlay" platform_allow: - native_posix - native_posix/native/64 diff --git a/tests/bluetooth/hci_prop_evt/dts/bindings/zephyr,bt-hci-test.yaml b/tests/bluetooth/hci_prop_evt/dts/bindings/zephyr,bt-hci-test.yaml new file mode 100644 index 0000000000000..7d8adacc90806 --- /dev/null +++ b/tests/bluetooth/hci_prop_evt/dts/bindings/zephyr,bt-hci-test.yaml @@ -0,0 +1,13 @@ +description: Bluetooth HCI for test purposes + +compatible: "zephyr,bt-hci-test" + +include: bt-hci.yaml + +properties: + bt-hci-name: + default: "test" + bt-hci-bus: + default: "BT_HCI_BUS_VIRTUAL" + bt-hci-quirks: + default: ["BT_HCI_QUIRK_NO_RESET"] diff --git a/tests/bluetooth/hci_prop_evt/prj.conf b/tests/bluetooth/hci_prop_evt/prj.conf index 56460e4ab1ab6..5d87f13964c09 100644 --- a/tests/bluetooth/hci_prop_evt/prj.conf +++ b/tests/bluetooth/hci_prop_evt/prj.conf @@ -3,7 +3,7 @@ CONFIG_ZTEST=y CONFIG_BT=y CONFIG_BT_CTLR=n -CONFIG_BT_NO_DRIVER=y +CONFIG_BT_H4=n CONFIG_BT_HCI_VS_EVT_USER=y diff --git a/tests/bluetooth/hci_prop_evt/src/main.c b/tests/bluetooth/hci_prop_evt/src/main.c index cf46a2bad6531..ea433b62df42d 100644 --- a/tests/bluetooth/hci_prop_evt/src/main.c +++ b/tests/bluetooth/hci_prop_evt/src/main.c @@ -15,9 +15,15 @@ #include #include #include -#include +#include #include +#define DT_DRV_COMPAT zephyr_bt_hci_test + +struct driver_data { + bt_hci_recv_t recv; +}; + /* HCI Proprietary vendor event */ const uint8_t hci_prop_evt_prefix[2] = { 0xAB, 0xBA }; @@ -84,10 +90,12 @@ static int cmd_handle_helper(uint16_t opcode, struct net_buf *cmd, } /* Lookup the command opcode and invoke handler. */ -static int cmd_handle(struct net_buf *cmd, +static int cmd_handle(const struct device *dev, + struct net_buf *cmd, const struct cmd_handler *handlers, size_t num_handlers) { + struct driver_data *drv = dev->data; struct net_buf *evt = NULL; struct bt_hci_evt_cc_status *ccst; struct bt_hci_cmd_hdr *chdr; @@ -105,7 +113,7 @@ static int cmd_handle(struct net_buf *cmd, } if (evt) { - bt_recv(evt); + drv->recv(dev, evt); } return err; @@ -207,15 +215,19 @@ static const struct cmd_handler cmds[] = { }; /* HCI driver open. */ -static int driver_open(void) +static int driver_open(const struct device *dev, bt_hci_recv_t recv) { + struct driver_data *drv = dev->data; + + drv->recv = recv; + return 0; } /* HCI driver send. */ -static int driver_send(struct net_buf *buf) +static int driver_send(const struct device *dev, struct net_buf *buf) { - zassert_true(cmd_handle(buf, cmds, ARRAY_SIZE(cmds)) == 0, + zassert_true(cmd_handle(dev, buf, cmds, ARRAY_SIZE(cmds)) == 0, "Unknown HCI command"); net_buf_unref(buf); @@ -223,15 +235,19 @@ static int driver_send(struct net_buf *buf) return 0; } -/* HCI driver structure. */ -static const struct bt_hci_driver drv = { - .name = "test", - .bus = BT_HCI_DRIVER_BUS_VIRTUAL, - .open = driver_open, - .send = driver_send, - .quirks = BT_QUIRK_NO_RESET, +static const struct bt_hci_driver_api driver_api = { + .open = driver_open, + .send = driver_send, }; +#define TEST_DEVICE_INIT(inst) \ + static struct driver_data driver_data_##inst = { \ + }; \ + DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &driver_data_##inst, NULL, \ + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &driver_api) + +DT_INST_FOREACH_STATUS_OKAY(TEST_DEVICE_INIT) + struct bt_recv_job_data { struct k_work work; /* Work item */ struct k_sem *sync; /* Semaphore to synchronize with */ @@ -243,12 +259,14 @@ struct bt_recv_job_data { /* Work item handler for bt_recv() jobs. */ static void bt_recv_job_cb(struct k_work *item) { + const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0)); + struct driver_data *drv = dev->data; struct bt_recv_job_data *data = CONTAINER_OF(item, struct bt_recv_job_data, work); struct k_sem *sync = job(data->buf)->sync; /* Send net buffer to host */ - bt_recv(data->buf); + drv->recv(dev, data->buf); data->buf = NULL; /* Wake up bt_recv_job_submit */ @@ -350,9 +368,6 @@ ZTEST_SUITE(test_hci_prop_evt, NULL, NULL, NULL, NULL, NULL); /* Test. */ ZTEST(test_hci_prop_evt, test_hci_prop_evt_entry) { - /* Register the test HCI driver */ - bt_hci_driver_register(&drv); - /* Go! Wait until Bluetooth initialization is done */ zassert_true((bt_enable(NULL) == 0), "bt_enable failed"); diff --git a/tests/bluetooth/hci_prop_evt/test.overlay b/tests/bluetooth/hci_prop_evt/test.overlay new file mode 100644 index 0000000000000..c0f0b1c5b2998 --- /dev/null +++ b/tests/bluetooth/hci_prop_evt/test.overlay @@ -0,0 +1,10 @@ +/ { + chosen { + zephyr,bt-hci = &bt_hci_test; + }; + + bt_hci_test: bt_hci_test { + compatible = "zephyr,bt-hci-test"; + status = "okay"; + }; +}; diff --git a/tests/bluetooth/hci_prop_evt/testcase.yaml b/tests/bluetooth/hci_prop_evt/testcase.yaml index dde90adf9bc12..e1a41372ada9d 100644 --- a/tests/bluetooth/hci_prop_evt/testcase.yaml +++ b/tests/bluetooth/hci_prop_evt/testcase.yaml @@ -1,5 +1,7 @@ tests: bluetooth.hci_prop_evt: + extra_args: + - EXTRA_DTC_OVERLAY_FILE="test.overlay" platform_allow: - qemu_x86 - qemu_cortex_m3 diff --git a/tests/bluetooth/hci_uart_async/boards/native_posix.conf b/tests/bluetooth/hci_uart_async/boards/native_posix.conf deleted file mode 100644 index d9130d07be5bd..0000000000000 --- a/tests/bluetooth/hci_uart_async/boards/native_posix.conf +++ /dev/null @@ -1,3 +0,0 @@ -# Print logs and test results on stdout as this not the -# default when SERIAL=y. -CONFIG_LOG_BACKEND_NATIVE_POSIX=y diff --git a/tests/bluetooth/hci_uart_async/boards/native_sim.conf b/tests/bluetooth/hci_uart_async/boards/native_sim.conf deleted file mode 100644 index d9130d07be5bd..0000000000000 --- a/tests/bluetooth/hci_uart_async/boards/native_sim.conf +++ /dev/null @@ -1,3 +0,0 @@ -# Print logs and test results on stdout as this not the -# default when SERIAL=y. -CONFIG_LOG_BACKEND_NATIVE_POSIX=y diff --git a/tests/bluetooth/hci_uart_async/dts/bindings/zephyr,bt-hci-test.yaml b/tests/bluetooth/hci_uart_async/dts/bindings/zephyr,bt-hci-test.yaml new file mode 100644 index 0000000000000..893e6a78cdc23 --- /dev/null +++ b/tests/bluetooth/hci_uart_async/dts/bindings/zephyr,bt-hci-test.yaml @@ -0,0 +1,11 @@ +description: Bluetooth HCI for test purposes + +compatible: "zephyr,bt-hci-test" + +include: bt-hci.yaml + +properties: + bt-hci-name: + default: "Mock Controller" + bt-hci-bus: + default: "BT_HCI_BUS_VIRTUAL" diff --git a/tests/bluetooth/hci_uart_async/prj.conf b/tests/bluetooth/hci_uart_async/prj.conf index 408e8f611e413..5f558afdebf51 100644 --- a/tests/bluetooth/hci_uart_async/prj.conf +++ b/tests/bluetooth/hci_uart_async/prj.conf @@ -1,5 +1,3 @@ -CONFIG_BT_NO_DRIVER=y - CONFIG_RING_BUFFER=y CONFIG_ASSERT=y diff --git a/tests/bluetooth/hci_uart_async/src/test_hci_uart_async.c b/tests/bluetooth/hci_uart_async/src/test_hci_uart_async.c index 08ea8bc1a79bc..69b35ff7f4835 100644 --- a/tests/bluetooth/hci_uart_async/src/test_hci_uart_async.c +++ b/tests/bluetooth/hci_uart_async/src/test_hci_uart_async.c @@ -14,7 +14,7 @@ #include #include -#include +#include #include LOG_MODULE_REGISTER(test, LOG_LEVEL_DBG); @@ -27,22 +27,35 @@ static const struct device *const zephyr_bt_c2h_uart = DEVICE_DT_GET(DT_CHOSEN(z /* The DUT is Sandwiched between the mock serial interface and a mock * controller. {{{ */ +#define DT_DRV_COMPAT zephyr_bt_hci_test + +struct drv_data { + bt_hci_recv_t recv; +}; + static void serial_vnd_data_callback(const struct device *dev, void *user_data); -static int drv_send(struct net_buf *buf); -static int drv_open(void); -static const struct bt_hci_driver drv = { - .name = "Mock Controller", - .bus = BT_HCI_DRIVER_BUS_VIRTUAL, +static int drv_send(const struct device *dev, struct net_buf *buf); +static int drv_open(const struct device *dev, bt_hci_recv_t recv); + +static const struct bt_hci_driver_api drv_api = { .open = drv_open, .send = drv_send, }; -static int sys_init_hci_driver_register(void) + +static int drv_init(const struct device *dev) { serial_vnd_set_callback(zephyr_bt_c2h_uart, serial_vnd_data_callback, NULL); - bt_hci_driver_register(&drv); return 0; } -SYS_INIT(sys_init_hci_driver_register, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); + +#define TEST_DEVICE_INIT(inst) \ + static struct drv_data drv_data_##inst = { \ + }; \ + DEVICE_DT_INST_DEFINE(inst, drv_init, NULL, &drv_data_##inst, NULL, \ + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &drv_api) + +DT_INST_FOREACH_STATUS_OKAY(TEST_DEVICE_INIT) + /* }}} */ /* Start the DUT "main thread". The settings for this thread are selected as @@ -68,9 +81,14 @@ SYS_INIT(sys_init_spawn_hci_uart, POST_KERNEL, 64); /* Mock controller callbacks. {{{ */ -static int drv_open(void) +static int drv_open(const struct device *dev, bt_hci_recv_t recv) { + struct drv_data *drv = dev->data; + LOG_DBG("drv_open"); + + drv->recv = recv; + return 0; } @@ -82,7 +100,7 @@ static int drv_open(void) * should use #bt_recv to send c2h packets to the DUT. */ K_FIFO_DEFINE(drv_send_fifo); /* elem T: net_buf */ -static int drv_send(struct net_buf *buf) +static int drv_send(const struct device *dev, struct net_buf *buf) { LOG_DBG("buf %p type %d len %u", buf, bt_buf_get_type(buf), buf->len); LOG_HEXDUMP_DBG(buf->data, buf->len, "buf"); @@ -206,13 +224,15 @@ ZTEST(hci_uart, test_h2c_cmd_flow_control) /* The controller sends a HCI Command Complete response. */ { + const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0)); + struct drv_data *drv = dev->data; int err; struct net_buf *buf = bt_buf_get_rx(BT_BUF_EVT, K_NO_WAIT); zassert_not_null(buf); net_buf_add_mem(buf, hci_msg_rx_evt_cmd_complete, sizeof(hci_msg_rx_evt_cmd_complete)); - err = bt_recv(buf); + err = drv->recv(dev, buf); zassert_equal(err, 0, "bt_recv failed"); } } diff --git a/tests/bluetooth/hci_uart_async/test.overlay b/tests/bluetooth/hci_uart_async/test.overlay new file mode 100644 index 0000000000000..c0f0b1c5b2998 --- /dev/null +++ b/tests/bluetooth/hci_uart_async/test.overlay @@ -0,0 +1,10 @@ +/ { + chosen { + zephyr,bt-hci = &bt_hci_test; + }; + + bt_hci_test: bt_hci_test { + compatible = "zephyr,bt-hci-test"; + status = "okay"; + }; +}; diff --git a/tests/bluetooth/hci_uart_async/testcase.yaml b/tests/bluetooth/hci_uart_async/testcase.yaml index 8df5113b354cd..b189149d104c7 100644 --- a/tests/bluetooth/hci_uart_async/testcase.yaml +++ b/tests/bluetooth/hci_uart_async/testcase.yaml @@ -1,5 +1,7 @@ tests: bluetooth.hci_uart_async: + extra_args: + - EXTRA_DTC_OVERLAY_FILE="test.overlay" tags: - bluetooth - uart diff --git a/tests/bluetooth/host_long_adv_recv/dts/bindings/zephyr,bt-hci-test.yaml b/tests/bluetooth/host_long_adv_recv/dts/bindings/zephyr,bt-hci-test.yaml new file mode 100644 index 0000000000000..7d8adacc90806 --- /dev/null +++ b/tests/bluetooth/host_long_adv_recv/dts/bindings/zephyr,bt-hci-test.yaml @@ -0,0 +1,13 @@ +description: Bluetooth HCI for test purposes + +compatible: "zephyr,bt-hci-test" + +include: bt-hci.yaml + +properties: + bt-hci-name: + default: "test" + bt-hci-bus: + default: "BT_HCI_BUS_VIRTUAL" + bt-hci-quirks: + default: ["BT_HCI_QUIRK_NO_RESET"] diff --git a/tests/bluetooth/host_long_adv_recv/prj.conf b/tests/bluetooth/host_long_adv_recv/prj.conf index ab58ed5327b07..96c30582c5012 100644 --- a/tests/bluetooth/host_long_adv_recv/prj.conf +++ b/tests/bluetooth/host_long_adv_recv/prj.conf @@ -3,10 +3,10 @@ CONFIG_ZTEST=y CONFIG_BT=y CONFIG_BT_CTLR=n +CONFIG_BT_H4=n CONFIG_BT_HCI=n CONFIG_BT_HCI_RAW=n CONFIG_BT_OBSERVER=y -CONFIG_BT_NO_DRIVER=y CONFIG_BT_EXT_ADV=y CONFIG_LOG=y diff --git a/tests/bluetooth/host_long_adv_recv/src/main.c b/tests/bluetooth/host_long_adv_recv/src/main.c index ef3862456aa9c..4fb364990555f 100644 --- a/tests/bluetooth/host_long_adv_recv/src/main.c +++ b/tests/bluetooth/host_long_adv_recv/src/main.c @@ -16,9 +16,15 @@ #include #include #include -#include +#include #include +#define DT_DRV_COMPAT zephyr_bt_hci_test + +struct driver_data { + bt_hci_recv_t recv; +}; + #define LOG_LEVEL CONFIG_BT_LOG_LEVEL #include LOG_MODULE_REGISTER(host_test_app); @@ -111,8 +117,10 @@ static int cmd_handle_helper(uint16_t opcode, struct net_buf *cmd, struct net_bu } /* Lookup the command opcode and invoke handler. */ -static int cmd_handle(struct net_buf *cmd, const struct cmd_handler *handlers, size_t num_handlers) +static int cmd_handle(const struct device *dev, struct net_buf *cmd, + const struct cmd_handler *handlers, size_t num_handlers) { + struct driver_data *drv = dev->data; struct net_buf *evt = NULL; struct bt_hci_evt_cc_status *ccst; struct bt_hci_cmd_hdr *chdr; @@ -130,7 +138,7 @@ static int cmd_handle(struct net_buf *cmd, const struct cmd_handler *handlers, s } if (evt) { - bt_recv(evt); + drv->recv(dev, evt); } return err; @@ -215,30 +223,39 @@ static const struct cmd_handler cmds[] = { }; /* HCI driver open. */ -static int driver_open(void) +static int driver_open(const struct device *dev, bt_hci_recv_t recv) { + struct driver_data *drv = dev->data; + + drv->recv = recv; + return 0; } /* HCI driver send. */ -static int driver_send(struct net_buf *buf) +static int driver_send(const struct device *dev, struct net_buf *buf) { - zassert_true(cmd_handle(buf, cmds, ARRAY_SIZE(cmds)) == 0, "Unknown HCI command"); + zassert_true(cmd_handle(dev, buf, cmds, ARRAY_SIZE(cmds)) == 0, "Unknown HCI command"); net_buf_unref(buf); return 0; } -/* HCI driver structure. */ -static const struct bt_hci_driver drv = { - .name = "test", - .bus = BT_HCI_DRIVER_BUS_VIRTUAL, +static const struct bt_hci_driver_api driver_api = { .open = driver_open, .send = driver_send, - .quirks = 0, }; +#define TEST_DEVICE_INIT(inst) \ + static struct driver_data driver_data_##inst = { \ + }; \ + DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &driver_data_##inst, NULL, \ + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &driver_api) + +DT_INST_FOREACH_STATUS_OKAY(TEST_DEVICE_INIT) + + struct bt_recv_job_data { struct k_work work; /* Work item */ struct k_sem *sync; /* Semaphore to synchronize with */ @@ -250,10 +267,12 @@ struct bt_recv_job_data { /* Work item handler for bt_recv() jobs. */ static void bt_recv_job_cb(struct k_work *item) { + const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0)); + struct driver_data *drv = dev->data; struct bt_recv_job_data *data = CONTAINER_OF(item, struct bt_recv_job_data, work); /* Send net buffer to host */ - bt_recv(data->buf); + drv->recv(dev, data->buf); /* Wake up bt_recv_job_submit */ k_sem_give(job(data->buf)->sync); @@ -357,9 +376,6 @@ ZTEST(long_adv_rx_tests, test_host_long_adv_recv) { struct test_adv_report expected_reports[2]; - /* Register the test HCI driver */ - bt_hci_driver_register(&drv); - /* Go! Wait until Bluetooth initialization is done */ zassert_true((bt_enable(NULL) == 0), "bt_enable failed"); diff --git a/tests/bluetooth/host_long_adv_recv/test.overlay b/tests/bluetooth/host_long_adv_recv/test.overlay new file mode 100644 index 0000000000000..c0f0b1c5b2998 --- /dev/null +++ b/tests/bluetooth/host_long_adv_recv/test.overlay @@ -0,0 +1,10 @@ +/ { + chosen { + zephyr,bt-hci = &bt_hci_test; + }; + + bt_hci_test: bt_hci_test { + compatible = "zephyr,bt-hci-test"; + status = "okay"; + }; +}; diff --git a/tests/bluetooth/host_long_adv_recv/testcase.yaml b/tests/bluetooth/host_long_adv_recv/testcase.yaml index 7957d03a796f2..dfe4465a42e38 100644 --- a/tests/bluetooth/host_long_adv_recv/testcase.yaml +++ b/tests/bluetooth/host_long_adv_recv/testcase.yaml @@ -1,5 +1,7 @@ tests: bluetooth.host_long_adv_recv: + extra_args: + - EXTRA_DTC_OVERLAY_FILE="test.overlay" platform_allow: - native_posix - native_posix/native/64 diff --git a/tests/bluetooth/init/h5.overlay b/tests/bluetooth/init/h5.overlay new file mode 100644 index 0000000000000..8c49815cb099a --- /dev/null +++ b/tests/bluetooth/init/h5.overlay @@ -0,0 +1,16 @@ +/ { + chosen { + zephyr,bt-hci = &bt_hci_3wire_uart; + }; +}; + +&bt_hci_uart { + status = "disabled"; +}; + +&uart2 { + bt_hci_3wire_uart: bt_hci_3wire_uart { + compatible = "zephyr,bt-hci-3wire-uart"; + status = "okay"; + }; +}; diff --git a/tests/bluetooth/init/testcase.yaml b/tests/bluetooth/init/testcase.yaml index 63267a96c8e5d..69afaaf8b08d3 100644 --- a/tests/bluetooth/init/testcase.yaml +++ b/tests/bluetooth/init/testcase.yaml @@ -326,10 +326,14 @@ tests: - nrf52840dk/nrf52840 - nrf51dk/nrf51822 bluetooth.init.test_h5: - extra_args: CONF_FILE=prj_h5.conf + extra_args: + - CONF_FILE=prj_h5.conf + - DTC_OVERLAY_FILE=h5.overlay platform_allow: qemu_cortex_m3 bluetooth.init.test_h5_dbg: - extra_args: CONF_FILE=prj_h5_dbg.conf + extra_args: + - CONF_FILE=prj_h5_dbg.conf + - DTC_OVERLAY_FILE=h5.overlay platform_allow: qemu_cortex_m3 bluetooth.init.test_llcp: extra_args: CONF_FILE=prj_llcp.conf diff --git a/tests/bluetooth/l2cap/prj.conf b/tests/bluetooth/l2cap/prj.conf index 69eb3d64ca7ba..ace0bc553f428 100644 --- a/tests/bluetooth/l2cap/prj.conf +++ b/tests/bluetooth/l2cap/prj.conf @@ -3,7 +3,7 @@ CONFIG_ZTEST=y CONFIG_BT=y CONFIG_BT_CTLR=n -CONFIG_BT_NO_DRIVER=y +CONFIG_BT_H4=n CONFIG_LOG=y CONFIG_BT_PERIPHERAL=y diff --git a/tests/bluetooth/l2cap/test.overlay b/tests/bluetooth/l2cap/test.overlay new file mode 100644 index 0000000000000..badbe2f392aac --- /dev/null +++ b/tests/bluetooth/l2cap/test.overlay @@ -0,0 +1,5 @@ +/ { + chosen { + /delete-property/ zephyr,bt-hci; + }; +}; diff --git a/tests/bluetooth/l2cap/testcase.yaml b/tests/bluetooth/l2cap/testcase.yaml index 8996672c866a1..5f19cf2eb73d8 100644 --- a/tests/bluetooth/l2cap/testcase.yaml +++ b/tests/bluetooth/l2cap/testcase.yaml @@ -1,5 +1,7 @@ tests: bluetooth.l2cap: + extra_args: + - EXTRA_DTC_OVERLAY_FILE="test.overlay" platform_allow: - native_posix - native_posix/native/64 diff --git a/tests/bluetooth/mesh/blob_io_flash/prj.conf b/tests/bluetooth/mesh/blob_io_flash/prj.conf index 7db7efc16cd35..36de7f6b0dac8 100644 --- a/tests/bluetooth/mesh/blob_io_flash/prj.conf +++ b/tests/bluetooth/mesh/blob_io_flash/prj.conf @@ -10,7 +10,6 @@ CONFIG_FLASH_SIMULATOR=y CONFIG_FLASH_SIMULATOR_DOUBLE_WRITES=y CONFIG_BT=y -CONFIG_BT_NO_DRIVER=y CONFIG_BT_OBSERVER=y CONFIG_BT_PERIPHERAL=y CONFIG_BT_MESH=y diff --git a/tests/bluetooth/mesh/blob_io_flash/test.overlay b/tests/bluetooth/mesh/blob_io_flash/test.overlay new file mode 100644 index 0000000000000..98f90303b70f9 --- /dev/null +++ b/tests/bluetooth/mesh/blob_io_flash/test.overlay @@ -0,0 +1,9 @@ +/ { + chosen { + /delete-property/ zephyr,bt-hci; + }; +}; + +&bt_hci_userchan { + status = "disabled"; +}; diff --git a/tests/bluetooth/mesh/blob_io_flash/testcase.yaml b/tests/bluetooth/mesh/blob_io_flash/testcase.yaml index c27ea3081af90..d5ad661d9efbe 100644 --- a/tests/bluetooth/mesh/blob_io_flash/testcase.yaml +++ b/tests/bluetooth/mesh/blob_io_flash/testcase.yaml @@ -1,5 +1,7 @@ tests: bluetooth.mesh.blob_io_flash: + extra_args: + - EXTRA_DTC_OVERLAY_FILE="test.overlay" platform_allow: - native_posix - native_sim diff --git a/tests/bluetooth/shell/boards/mimxrt1060_evk.overlay b/tests/bluetooth/shell/boards/mimxrt1060_evk.overlay index f48eea9172ce5..538460a73601e 100644 --- a/tests/bluetooth/shell/boards/mimxrt1060_evk.overlay +++ b/tests/bluetooth/shell/boards/mimxrt1060_evk.overlay @@ -6,7 +6,7 @@ / { chosen { - zephyr,bt-uart = &lpuart3; + zephyr,bt-hci = &bt_hci_uart; }; }; @@ -14,4 +14,9 @@ status = "okay"; current-speed = <3000000>; hw-flow-control; + + bt_hci_uart: bt_hci_uart { + compatible = "zephyr,bt-hci-uart"; + status = "okay"; + }; }; diff --git a/tests/bluetooth/uuid/prj.conf b/tests/bluetooth/uuid/prj.conf index fec5098eecffe..1f86a43c20848 100644 --- a/tests/bluetooth/uuid/prj.conf +++ b/tests/bluetooth/uuid/prj.conf @@ -3,4 +3,4 @@ CONFIG_ZTEST=y CONFIG_BT=y CONFIG_BT_CTLR=n -CONFIG_BT_NO_DRIVER=y +CONFIG_BT_H4=n diff --git a/tests/bluetooth/uuid/test.overlay b/tests/bluetooth/uuid/test.overlay new file mode 100644 index 0000000000000..badbe2f392aac --- /dev/null +++ b/tests/bluetooth/uuid/test.overlay @@ -0,0 +1,5 @@ +/ { + chosen { + /delete-property/ zephyr,bt-hci; + }; +}; diff --git a/tests/bluetooth/uuid/testcase.yaml b/tests/bluetooth/uuid/testcase.yaml index 20e43e29a271d..e3382e875c9cc 100644 --- a/tests/bluetooth/uuid/testcase.yaml +++ b/tests/bluetooth/uuid/testcase.yaml @@ -1,5 +1,7 @@ tests: bluetooth.uuid: + extra_args: + - EXTRA_DTC_OVERLAY_FILE="test.overlay" platform_allow: - native_posix - native_posix/native/64 diff --git a/tests/bsim/bluetooth/hci_uart/compile.sh b/tests/bsim/bluetooth/hci_uart/compile.sh index e617ca0d30993..ed177513a055e 100755 --- a/tests/bsim/bluetooth/hci_uart/compile.sh +++ b/tests/bsim/bluetooth/hci_uart/compile.sh @@ -10,7 +10,8 @@ set -ue source ${ZEPHYR_BASE}/tests/bsim/compile.source -app=tests/bsim/bluetooth/ll/conn conf_file=prj_split_hci_uart.conf compile +app=tests/bsim/bluetooth/ll/conn conf_file=prj_split_hci_uart.conf \ + cmake_extra_args=-DEXTRA_DTC_OVERLAY_FILE=hci-uart.overlay compile app=samples/bluetooth/hci_uart compile app=samples/bluetooth/hci_uart_async compile diff --git a/tests/bsim/bluetooth/ll/conn/hci-uart.overlay b/tests/bsim/bluetooth/ll/conn/hci-uart.overlay new file mode 100644 index 0000000000000..1dad3b168b93e --- /dev/null +++ b/tests/bsim/bluetooth/ll/conn/hci-uart.overlay @@ -0,0 +1,5 @@ +/ { + chosen { + zephyr,bt-hci = &bt_hci_uart; + }; +}; diff --git a/tests/bsim/bluetooth/ll/conn/prj_split_hci_uart.conf b/tests/bsim/bluetooth/ll/conn/prj_split_hci_uart.conf index 58844e5a95104..4c39731af6a42 100644 --- a/tests/bsim/bluetooth/ll/conn/prj_split_hci_uart.conf +++ b/tests/bsim/bluetooth/ll/conn/prj_split_hci_uart.conf @@ -15,4 +15,3 @@ CONFIG_BT_L2CAP_TX_BUF_COUNT=6 CONFIG_BT_HCI=y CONFIG_BT_CTLR=n -CONFIG_BT_H4=y