Bluetooth: drivers: Convert Silabs HCI driver to new API

Convert the slz_hci.c HCI driver to use the new HCI driver API. This also
fixes the HCI bus type to correctly indicate VIRTUAL instead of UART.

Signed-off-by: Johan Hedberg <johan.hedberg@gmail.com>
This commit is contained in:
Johan Hedberg 2024-06-02 12:28:18 +03:00 committed by Anas Nashif
commit 3ecd7dbd4c
15 changed files with 95 additions and 30 deletions

View file

@ -42,9 +42,6 @@ config MAIN_STACK_SIZE
default 3072 if PM default 3072 if PM
default 2304 default 2304
config BT_SILABS_HCI
default y
endif # BT endif # BT
endif # BOARD_EFR32_RADIO endif # BOARD_EFR32_RADIO

View file

@ -11,6 +11,10 @@
/ { / {
model = "Silicon Labs BRD4104A (Blue Gecko Radio Board)"; model = "Silicon Labs BRD4104A (Blue Gecko Radio Board)";
compatible = "silabs,efr32_radio_brd4104a", "silabs,efr32bg13p"; compatible = "silabs,efr32_radio_brd4104a", "silabs,efr32bg13p";
chosen {
zephyr,bt-hci = &bt_hci_silabs;
};
}; };
&cpu0 { &cpu0 {
@ -56,3 +60,7 @@
}; };
}; };
&bt_hci_silabs {
status = "okay";
};

View file

@ -11,6 +11,10 @@
/ { / {
model = "Silicon Labs BRD4161A (Mighty Gecko Radio Board)"; model = "Silicon Labs BRD4161A (Mighty Gecko Radio Board)";
compatible = "silabs,efr32_radio_brd4161a", "silabs,efr32mg12p"; compatible = "silabs,efr32_radio_brd4161a", "silabs,efr32mg12p";
chosen {
zephyr,bt-hci = &bt_hci_silabs;
};
}; };
&cpu0 { &cpu0 {
@ -89,3 +93,7 @@
status = "okay"; status = "okay";
}; };
}; };
&bt_hci_silabs {
status = "okay";
};

View file

@ -11,6 +11,10 @@
/ { / {
model = "Silicon Labs BRD4170A (Mighty Gecko Radio Board)"; model = "Silicon Labs BRD4170A (Mighty Gecko Radio Board)";
compatible = "silabs,efr32_radio_brd4170a", "silabs,efr32mg12p"; compatible = "silabs,efr32_radio_brd4170a", "silabs,efr32mg12p";
chosen {
zephyr,bt-hci = &bt_hci_silabs;
};
}; };
&cpu0 { &cpu0 {
@ -56,3 +60,7 @@
}; };
}; };
&bt_hci_silabs {
status = "okay";
};

View file

@ -28,9 +28,6 @@ config MAIN_STACK_SIZE
default 3072 if PM default 3072 if PM
default 2304 default 2304
config BT_SILABS_HCI
default y
endif # BT endif # BT
config REGULATOR config REGULATOR

View file

@ -20,6 +20,7 @@
chosen { chosen {
zephyr,code-partition = &slot0_partition; zephyr,code-partition = &slot0_partition;
zephyr,bt-hci = &bt_hci_silabs;
}; };
}; };
@ -55,3 +56,7 @@
&sw_imu_enable { &sw_imu_enable {
enable-gpios = <&gpiob GECKO_PIN(4) GPIO_ACTIVE_HIGH>; enable-gpios = <&gpiob GECKO_PIN(4) GPIO_ACTIVE_HIGH>;
}; };
&bt_hci_silabs {
status = "okay";
};

View file

@ -33,9 +33,6 @@ config MINIMAL_LIBC_MALLOC_ARENA_SIZE
config MAIN_STACK_SIZE config MAIN_STACK_SIZE
default 2304 default 2304
config BT_SILABS_HCI
default y
if SHELL if SHELL
config SHELL_STACK_SIZE config SHELL_STACK_SIZE

View file

@ -19,6 +19,7 @@
zephyr,sram = &sram0; zephyr,sram = &sram0;
zephyr,flash = &flash0; zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition; zephyr,code-partition = &slot0_partition;
zephyr,bt-hci = &bt_hci_silabs;
}; };
aliases { aliases {
@ -177,3 +178,7 @@
&stimer0 { &stimer0 {
status = "okay"; status = "okay";
}; };
&bt_hci_silabs {
status = "okay";
};

View file

@ -76,7 +76,8 @@ config BT_STM32WBA
config BT_SILABS_HCI config BT_SILABS_HCI
bool "Silicon Labs Bluetooth interface" 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 depends on !PM || SOC_GECKO_PM_BACKEND_PMGR
select SOC_GECKO_USE_RAIL select SOC_GECKO_USE_RAIL
select ENTROPY_GENERATOR select ENTROPY_GENERATOR

View file

@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include <zephyr/drivers/bluetooth/hci_driver.h> #include <zephyr/drivers/bluetooth.h>
#include <sl_btctrl_linklayer.h> #include <sl_btctrl_linklayer.h>
#include <sl_hci_common_transport.h> #include <sl_hci_common_transport.h>
@ -16,6 +16,12 @@
#include <zephyr/logging/log.h> #include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(bt_hci_driver_slz); 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_ACCEPT_LIST_SIZE 1
#define SL_BT_CONFIG_MAX_CONNECTIONS 1 #define SL_BT_CONFIG_MAX_CONNECTIONS 1
#define SL_BT_CONFIG_USER_ADVERTISERS 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) 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; struct net_buf *buf;
uint8_t packet_type = data[0]; uint8_t packet_type = data[0];
uint8_t event_code; 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); net_buf_add_mem(buf, data, len);
bt_recv(buf); hci->recv(dev, buf);
sl_btctrl_hci_transmit_complete(0); sl_btctrl_hci_transmit_complete(0);
return 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; int rv = 0;
ARG_UNUSED(dev);
switch (bt_buf_get_type(buf)) { switch (bt_buf_get_type(buf)) {
case BT_BUF_ACL_OUT: case BT_BUF_ACL_OUT:
net_buf_push_u8(buf, h4_acl); 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(); 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; int ret;
/* Start RX thread */ /* Start RX thread */
@ -185,6 +196,8 @@ static int slz_bt_open(void)
} }
#endif #endif
hci->recv = recv;
LOG_DBG("SiLabs BT HCI started"); LOG_DBG("SiLabs BT HCI started");
return 0; return 0;
@ -193,24 +206,16 @@ deinit:
return ret; return ret;
} }
static const struct bt_hci_driver drv = { static const struct bt_hci_driver_api drv = {
.name = "sl:bt",
.bus = BT_HCI_DRIVER_BUS_UART,
.open = slz_bt_open, .open = slz_bt_open,
.send = slz_bt_send, .send = slz_bt_send,
.quirks = BT_QUIRK_NO_RESET
}; };
static int slz_bt_init(void) #define HCI_DEVICE_INIT(inst) \
{ static struct hci_data hci_data_##inst = { \
int ret; }; \
DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &hci_data_##inst, NULL, \
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &drv)
ret = bt_hci_driver_register(&drv); /* Only one instance supported right now */
if (ret) { HCI_DEVICE_INIT(0)
LOG_ERR("Failed to register SiLabs BT HCI %d", ret);
}
return ret;
}
SYS_INIT(slz_bt_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);

View file

@ -224,6 +224,11 @@
#io-channel-cells = <1>; #io-channel-cells = <1>;
}; };
}; };
bt_hci_silabs: bt_hci_silabs {
compatible = "silabs,bt-hci";
status = "disabled";
};
}; };
/ { / {

View file

@ -234,6 +234,11 @@
}; };
}; };
bt_hci_silabs: bt_hci_silabs {
compatible = "silabs,bt-hci";
status = "disabled";
};
pinctrl: pin-controller { pinctrl: pin-controller {
/* Pin controller is a "virtual" device since SiLabs SoCs do pin /* Pin controller is a "virtual" device since SiLabs SoCs do pin
* control in a distributed way (GPIO registers and PSEL * control in a distributed way (GPIO registers and PSEL

View file

@ -213,6 +213,12 @@
#io-channel-cells = <1>; #io-channel-cells = <1>;
}; };
}; };
bt_hci_silabs: bt_hci_silabs {
compatible = "silabs,bt-hci";
status = "disabled";
};
}; };
/ { / {

View file

@ -181,6 +181,11 @@
}; };
}; };
bt_hci_silabs: bt_hci_silabs {
compatible = "silabs,bt-hci";
status = "disabled";
};
pinctrl: pin-controller { pinctrl: pin-controller {
/* Pin controller is a "virtual" device since SiLabs SoCs do pin /* Pin controller is a "virtual" device since SiLabs SoCs do pin
* control in a distributed way (GPIO registers and PSEL * control in a distributed way (GPIO registers and PSEL

View file

@ -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"]