diff --git a/boards/renesas/da1469x_dk_pro/Kconfig.defconfig b/boards/renesas/da1469x_dk_pro/Kconfig.defconfig index b0e0f1ff8ee..4ef15e108a4 100644 --- a/boards/renesas/da1469x_dk_pro/Kconfig.defconfig +++ b/boards/renesas/da1469x_dk_pro/Kconfig.defconfig @@ -64,9 +64,6 @@ endif # PM || PM_DEVICE if BT -config BT_DA1469X - default y - config BT_WAIT_NOP default y diff --git a/boards/renesas/da1469x_dk_pro/da1469x_dk_pro.dts b/boards/renesas/da1469x_dk_pro/da1469x_dk_pro.dts index f84a97b2020..f866df49a85 100644 --- a/boards/renesas/da1469x_dk_pro/da1469x_dk_pro.dts +++ b/boards/renesas/da1469x_dk_pro/da1469x_dk_pro.dts @@ -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"; +}; diff --git a/drivers/bluetooth/hci/Kconfig b/drivers/bluetooth/hci/Kconfig index 55d214bfd82..b4575a81578 100644 --- a/drivers/bluetooth/hci/Kconfig +++ b/drivers/bluetooth/hci/Kconfig @@ -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. diff --git a/drivers/bluetooth/hci/hci_da1469x.c b/drivers/bluetooth/hci/hci_da1469x.c index c97b83f3b35..18733d8444c 100644 --- a/drivers/bluetooth/hci/hci_da1469x.c +++ b/drivers/bluetooth/hci/hci_da1469x.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include @@ -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) diff --git a/dts/arm/renesas/smartbond/da1469x.dtsi b/dts/arm/renesas/smartbond/da1469x.dtsi index 3ab063af25c..05f250935f3 100644 --- a/dts/arm/renesas/smartbond/da1469x.dtsi +++ b/dts/arm/renesas/smartbond/da1469x.dtsi @@ -394,6 +394,11 @@ reg = <0x34000000 0x48>; status = "disabled"; }; + + bt_hci_da1469x: bt_hci_da1469x { + compatible = "renesas,bt-hci-da1469x"; + status = "disabled"; + }; }; }; diff --git a/dts/bindings/bluetooth/renesas,bt-hci-da1469x.yaml b/dts/bindings/bluetooth/renesas,bt-hci-da1469x.yaml new file mode 100644 index 00000000000..cd66b011953 --- /dev/null +++ b/dts/bindings/bluetooth/renesas,bt-hci-da1469x.yaml @@ -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"