Commit 501e7158 authored by Johan Hedberg's avatar Johan Hedberg Committed by Anas Nashif
Browse files

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: default avatarJohan Hedberg <johan.hedberg@gmail.com>
parent b7b606bd
Loading
Loading
Loading
Loading
+2 −0
Changes for drivers/bluetooth/hci/Kconfig: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -59,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
+33 −15
Changes for drivers/bluetooth/hci/ipm_stm32wb.c: 33 added lines, 15 removed lines.
Original line number Diff line number Diff line
@@ -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 @@ 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)
+1 −0
Changes for dts/arm/st/wb/stm32wb.dtsi: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
	chosen {
		zephyr,entropy = &rng;
		zephyr,flash-controller = &flash;
		zephyr,bt-hci = &ble_rf;
	};

	cpus {
+5 −1
Changes for dts/bindings/bluetooth/st,stm32wb-ble-rf.yaml: 5 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -6,8 +6,12 @@ description: |

compatible: "st,stm32wb-rf"

include: base.yaml
include: bt-hci.yaml

properties:
  clocks:
    required: true
  bt-hci-name:
    default: "BT IPM"
  bt-hci-bus:
    default: "BT_HCI_BUS_IPM"