Bluetooth: drivers: Convert STM32 IPM driver to new API
Convert the ipm_stm32wb.c HCI driver to the new HCI driver API.
Signed-off-by: Johan Hedberg <johan.hedberg@gmail.com>
diff --git a/drivers/bluetooth/hci/Kconfig b/drivers/bluetooth/hci/Kconfig
index dbec279..55d214b 100644
--- a/drivers/bluetooth/hci/Kconfig
+++ b/drivers/bluetooth/hci/Kconfig
@@ -59,6 +59,8 @@
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
diff --git a/drivers/bluetooth/hci/ipm_stm32wb.c b/drivers/bluetooth/hci/ipm_stm32wb.c
index 48c5dd0..df83ee3 100644
--- a/drivers/bluetooth/hci/ipm_stm32wb.c
+++ b/drivers/bluetooth/hci/ipm_stm32wb.c
@@ -11,7 +11,7 @@
#include <zephyr/init.h>
#include <zephyr/sys/util.h>
#include <zephyr/bluetooth/hci.h>
-#include <zephyr/drivers/bluetooth/hci_driver.h>
+#include <zephyr/drivers/bluetooth.h>
#include <zephyr/bluetooth/addr.h>
#include <zephyr/drivers/clock_control/stm32_clock_control.h>
#include <zephyr/irq.h>
@@ -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 @@
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 @@
TL_MM_EvtDone(hcievt);
- bt_recv(buf);
+ hci->recv(dev, buf);
end_loop:
k_sem_give(&ipm_busy);
}
@@ -347,10 +353,12 @@
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 @@
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 @@
/* 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 @@
}
#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 @@
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 @@
.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 @@
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/dts/arm/st/wb/stm32wb.dtsi b/dts/arm/st/wb/stm32wb.dtsi
index a972f3e..fa0c330 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/bindings/bluetooth/st,stm32wb-ble-rf.yaml b/dts/bindings/bluetooth/st,stm32wb-ble-rf.yaml
index 51b46cb..f1903de 100644
--- a/dts/bindings/bluetooth/st,stm32wb-ble-rf.yaml
+++ b/dts/bindings/bluetooth/st,stm32wb-ble-rf.yaml
@@ -6,8 +6,12 @@
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"