From f48a57b2a84e742533125d04b9e6937696257ec0 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Sat, 25 May 2024 09:55:48 +0300 Subject: [PATCH] Bluetooth: drivers: Remove unmaintained B91 HCI driver The driver isn't currently buildable due to "west blobs" support never having been added for hal_telink. Furthermore, even if the blob dependency is manually made available it turns out the code has bitrotten to the point where it doesn't build anymore. This situation has continued for several years without anyone taking action, so I think it's safe to assume this is unmaintained and should be removed. Signed-off-by: Johan Hedberg --- .../telink/tlsr9518adk80d/Kconfig.defconfig | 16 -- drivers/bluetooth/hci/CMakeLists.txt | 1 - drivers/bluetooth/hci/Kconfig | 5 - drivers/bluetooth/hci/hci_b91.c | 248 ------------------ subsys/bluetooth/host/Kconfig | 1 - west.yml | 2 +- 6 files changed, 1 insertion(+), 272 deletions(-) delete mode 100644 drivers/bluetooth/hci/hci_b91.c diff --git a/boards/telink/tlsr9518adk80d/Kconfig.defconfig b/boards/telink/tlsr9518adk80d/Kconfig.defconfig index 001ad287586..a1dc3d5f582 100644 --- a/boards/telink/tlsr9518adk80d/Kconfig.defconfig +++ b/boards/telink/tlsr9518adk80d/Kconfig.defconfig @@ -6,22 +6,6 @@ if BOARD_TLSR9518ADK80D config SOC_FLASH_TELINK_B91 default y if FLASH -if BT - -# BLE Controller SDK from hal_telink requires -# Telink's toolchain with FPU support -config FPU - default y if "$(ZEPHYR_TOOLCHAIN_VARIANT)" != "zephyr" - -config BT_HCI_ACL_FLOW_CONTROL - default n - -choice BT_HCI_BUS_TYPE - default BT_B91 -endchoice - -endif # BT - # Workaround for not being able to have commas in macro arguments DT_CHOSEN_Z_CODE_PARTITION := zephyr,code-partition diff --git a/drivers/bluetooth/hci/CMakeLists.txt b/drivers/bluetooth/hci/CMakeLists.txt index ca3f62f9e59..94210e79631 100644 --- a/drivers/bluetooth/hci/CMakeLists.txt +++ b/drivers/bluetooth/hci/CMakeLists.txt @@ -13,7 +13,6 @@ if(CONFIG_BT_HCI_IPC) endif() endif() -zephyr_library_sources_ifdef(CONFIG_BT_B91 hci_b91.c) zephyr_library_sources_ifdef(CONFIG_BT_AIROC cyw43xxx.c) zephyr_library_sources_ifdef(CONFIG_BT_ESP32 hci_esp32.c) zephyr_library_sources_ifdef(CONFIG_BT_H4 h4.c) diff --git a/drivers/bluetooth/hci/Kconfig b/drivers/bluetooth/hci/Kconfig index a6e53508bc4..d00cb731563 100644 --- a/drivers/bluetooth/hci/Kconfig +++ b/drivers/bluetooth/hci/Kconfig @@ -97,11 +97,6 @@ config BT_ESP32 help Espressif HCI bluetooth interface -config BT_B91 - bool "Telink B91 HCI driver" - help - Telink B91 HCI bluetooth interface - config BT_PSOC6_BLESS bool "PSOC6 BLESS driver" select BT_HCI_SETUP diff --git a/drivers/bluetooth/hci/hci_b91.c b/drivers/bluetooth/hci/hci_b91.c deleted file mode 100644 index 9909718e94b..00000000000 --- a/drivers/bluetooth/hci/hci_b91.c +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Copyright (c) 2022, Telink Semiconductor (Shanghai) Co., Ltd. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include -#include - -#include - -#define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL -#include -LOG_MODULE_REGISTER(bt_hci_driver_b91); - -#define HCI_BT_B91_TIMEOUT K_MSEC(2000) - -static K_SEM_DEFINE(hci_send_sem, 1, 1); - -static bool is_hci_event_discardable(const uint8_t *evt_data) -{ - uint8_t evt_type = evt_data[0]; - - switch (evt_type) { -#if defined(CONFIG_BT_CLASSIC) - case BT_HCI_EVT_INQUIRY_RESULT_WITH_RSSI: - case BT_HCI_EVT_EXTENDED_INQUIRY_RESULT: - return true; -#endif - case BT_HCI_EVT_LE_META_EVENT: { - uint8_t subevt_type = evt_data[sizeof(struct bt_hci_evt_hdr)]; - - switch (subevt_type) { - case BT_HCI_EVT_LE_ADVERTISING_REPORT: - return true; - default: - return false; - } - } - default: - return false; - } -} - -static struct net_buf *bt_b91_evt_recv(uint8_t *data, size_t len) -{ - bool discardable; - struct bt_hci_evt_hdr hdr; - struct net_buf *buf; - size_t buf_tailroom; - - if (len < sizeof(hdr)) { - LOG_ERR("Not enough data for event header"); - return NULL; - } - - discardable = is_hci_event_discardable(data); - - memcpy((void *)&hdr, data, sizeof(hdr)); - data += sizeof(hdr); - len -= sizeof(hdr); - - if (len != hdr.len) { - LOG_ERR("Event payload length is not correct"); - return NULL; - } - LOG_DBG("len %u", hdr.len); - - buf = bt_buf_get_evt(hdr.evt, discardable, K_NO_WAIT); - if (!buf) { - if (discardable) { - LOG_DBG("Discardable buffer pool full, ignoring event"); - } else { - LOG_ERR("No available event buffers!"); - } - return buf; - } - - net_buf_add_mem(buf, &hdr, sizeof(hdr)); - - buf_tailroom = net_buf_tailroom(buf); - if (buf_tailroom < len) { - LOG_ERR("Not enough space in buffer %zu/%zu", len, buf_tailroom); - net_buf_unref(buf); - return NULL; - } - - net_buf_add_mem(buf, data, len); - - return buf; -} - -static struct net_buf *bt_b91_acl_recv(uint8_t *data, size_t len) -{ - struct bt_hci_acl_hdr hdr; - struct net_buf *buf; - size_t buf_tailroom; - - if (len < sizeof(hdr)) { - LOG_ERR("Not enough data for ACL header"); - return NULL; - } - - buf = bt_buf_get_rx(BT_BUF_ACL_IN, K_NO_WAIT); - if (buf) { - memcpy((void *)&hdr, data, sizeof(hdr)); - data += sizeof(hdr); - len -= sizeof(hdr); - } else { - LOG_ERR("No available ACL buffers!"); - return NULL; - } - - if (len != sys_le16_to_cpu(hdr.len)) { - LOG_ERR("ACL payload length is not correct"); - net_buf_unref(buf); - return NULL; - } - - net_buf_add_mem(buf, &hdr, sizeof(hdr)); - buf_tailroom = net_buf_tailroom(buf); - if (buf_tailroom < len) { - LOG_ERR("Not enough space in buffer %zu/%zu", len, buf_tailroom); - net_buf_unref(buf); - return NULL; - } - - LOG_DBG("len %u", len); - net_buf_add_mem(buf, data, len); - - return buf; -} - -static void hci_b91_host_rcv_pkt(uint8_t *data, uint16_t len) -{ - uint8_t pkt_indicator; - struct net_buf *buf; - - LOG_HEXDUMP_DBG(data, len, "host packet data:"); - - pkt_indicator = *data++; - len -= sizeof(pkt_indicator); - - switch (pkt_indicator) { - case BT_HCI_H4_EVT: - buf = bt_b91_evt_recv(data, len); - break; - - case BT_HCI_H4_ACL: - buf = bt_b91_acl_recv(data, len); - break; - - default: - buf = NULL; - LOG_ERR("Unknown HCI type %u", pkt_indicator); - } - - if (buf) { - LOG_DBG("Calling bt_recv(%p)", buf); - bt_recv(buf); - } -} - -static void hci_b91_controller_rcv_pkt_ready(void) -{ - k_sem_give(&hci_send_sem); -} - -static b91_bt_host_callback_t vhci_host_cb = { - .host_send_available = hci_b91_controller_rcv_pkt_ready, - .host_read_packet = hci_b91_host_rcv_pkt -}; - -static int bt_b91_send(struct net_buf *buf) -{ - int err = 0; - uint8_t type; - - LOG_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len); - - switch (bt_buf_get_type(buf)) { - case BT_BUF_ACL_OUT: - type = BT_HCI_H4_ACL; - break; - - case BT_BUF_CMD: - type = BT_HCI_H4_CMD; - break; - - default: - LOG_ERR("Unknown type %u", bt_buf_get_type(buf)); - goto done; - } - - LOG_HEXDUMP_DBG(buf->data, buf->len, "Final HCI buffer:"); - - if (k_sem_take(&hci_send_sem, HCI_BT_B91_TIMEOUT) == 0) { - b91_bt_host_send_packet(type, buf->data, buf->len); - } else { - LOG_ERR("Send packet timeout error"); - err = -ETIMEDOUT; - } - -done: - net_buf_unref(buf); - k_sem_give(&hci_send_sem); - - return err; -} - -static int hci_b91_open(void) -{ - int status; - - status = b91_bt_controller_init(); - if (status) { - LOG_ERR("Bluetooth controller init failed %d", status); - return status; - } - - b91_bt_host_callback_register(&vhci_host_cb); - - LOG_DBG("B91 BT started"); - - return 0; -} - -static const struct bt_hci_driver drv = { - .name = "BT B91", - .open = hci_b91_open, - .send = bt_b91_send, - .bus = BT_HCI_DRIVER_BUS_IPM, -#if defined(CONFIG_BT_DRIVER_QUIRK_NO_AUTO_DLE) - .quirks = BT_QUIRK_NO_AUTO_DLE, -#endif -}; - -static int bt_b91_init(void) -{ - - bt_hci_driver_register(&drv); - - return 0; -} - -SYS_INIT(bt_b91_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); diff --git a/subsys/bluetooth/host/Kconfig b/subsys/bluetooth/host/Kconfig index f880ed805d9..535d9386001 100644 --- a/subsys/bluetooth/host/Kconfig +++ b/subsys/bluetooth/host/Kconfig @@ -53,7 +53,6 @@ config BT_HCI_TX_STACK_SIZE default 768 if BT_CTLR && BT_LL_SW_SPLIT default 512 if BT_USERCHAN default 640 if BT_STM32_IPM - default 1024 if BT_B91 # Even if no driver is selected the following default is still # needed e.g. for unit tests. This default will also server as # the worst-case stack size if an out-of-tree controller is used. diff --git a/west.yml b/west.yml index 9b76766022e..9ad7242e776 100644 --- a/west.yml +++ b/west.yml @@ -239,7 +239,7 @@ manifest: groups: - hal - name: hal_telink - revision: 38573af589173259801ae6c2b34b7d4c9e626746 + revision: 4226c7fc17d5a34e557d026d428fc766191a0800 path: modules/hal/telink groups: - hal