Skip to content

Commit

Permalink
Bluetooth: drivers: Convert DA1469X HCI driver to new API
Browse files Browse the repository at this point in the history
Convert the Renesas DA1469X HCI driver to the new HCI driver API.

Signed-off-by: Johan Hedberg <[email protected]>
  • Loading branch information
jhedberg authored and nashif committed Jun 11, 2024
1 parent 501e715 commit f33aab9
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 17 deletions.
3 changes: 0 additions & 3 deletions boards/renesas/da1469x_dk_pro/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ endif # PM || PM_DEVICE

if BT

config BT_DA1469X
default y

config BT_WAIT_NOP
default y

Expand Down
5 changes: 5 additions & 0 deletions boards/renesas/da1469x_dk_pro/da1469x_dk_pro.dts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
zephyr,console = &uart;
zephyr,shell-uart = &uart;
zephyr,code-partition = &slot0_partition;
zephyr,bt-hci = &bt_hci_da1469x;
};

lvgl_pointer {
Expand Down Expand Up @@ -178,3 +179,7 @@ zephyr_udc0: &usbd {
pinctrl-1 = <&spi2_sleep>;
pinctrl-names = "default", "sleep";
};

&bt_hci_da1469x {
status = "okay";
};
2 changes: 2 additions & 0 deletions drivers/bluetooth/hci/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
47 changes: 33 additions & 14 deletions drivers/bluetooth/hci/hci_da1469x.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand All @@ -440,24 +448,32 @@ 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);

return 0;
}

#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);
Expand All @@ -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();
Expand All @@ -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)
5 changes: 5 additions & 0 deletions dts/arm/renesas/smartbond/da1469x.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@
reg = <0x34000000 0x48>;
status = "disabled";
};

bt_hci_da1469x: bt_hci_da1469x {
compatible = "renesas,bt-hci-da1469x";
status = "disabled";
};
};
};

Expand Down
11 changes: 11 additions & 0 deletions dts/bindings/bluetooth/renesas,bt-hci-da1469x.yaml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit f33aab9

Please sign in to comment.