Bluetooth: drivers: Convert DA1469X HCI driver to new API

Convert the Renesas DA1469X HCI driver to the new HCI driver API.

Signed-off-by: Johan Hedberg <johan.hedberg@gmail.com>
This commit is contained in:
Johan Hedberg 2024-06-01 16:51:00 +03:00 committed by Anas Nashif
commit f33aab9889
6 changed files with 56 additions and 17 deletions

View file

@ -64,9 +64,6 @@ endif # PM || PM_DEVICE
if BT
config BT_DA1469X
default y
config BT_WAIT_NOP
default y

View file

@ -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";
};

View file

@ -118,6 +118,8 @@ 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.

View file

@ -9,7 +9,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/irq.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/random/random.h>
@ -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)

View file

@ -394,6 +394,11 @@
reg = <0x34000000 0x48>;
status = "disabled";
};
bt_hci_da1469x: bt_hci_da1469x {
compatible = "renesas,bt-hci-da1469x";
status = "disabled";
};
};
};

View file

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