Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: bluetooth: hci: add support for bt_disable() function call #86645

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions drivers/bluetooth/hci/hci_nxp.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 NXP
* Copyright 2023-2025 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -507,13 +507,7 @@ static int bt_nxp_close(const struct device *dev)
{
struct bt_nxp_data *hci = dev->data;
int ret = 0;
/* Reset the Controller */
if (IS_ENABLED(CONFIG_BT_HCI_HOST)) {
ret = bt_hci_cmd_send_sync(BT_HCI_OP_RESET, NULL, NULL);
if (ret) {
LOG_ERR("Failed to reset BLE controller");
}
}

hci->recv = NULL;

return ret;
Expand Down
23 changes: 16 additions & 7 deletions drivers/bluetooth/hci/hci_nxp_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ struct nxp_ctlr_fw_upload_state {
bool is_error_case;
bool is_cmd7_req;
bool is_entry_point_req;
bool is_setup_done;

uint8_t last_5bytes_buffer[6];
};
Expand Down Expand Up @@ -1171,11 +1172,15 @@ static int bt_nxp_ctlr_init(void)

int bt_hci_transport_setup(const struct device *dev)
{
int ret = 0;
if (dev != uart_dev) {
return -EINVAL;
}

return bt_nxp_ctlr_init();
if (!fw_upload.is_setup_done) {
ret = bt_nxp_ctlr_init();
}
return ret;
}

#define BT_HCI_VSC_BAUDRATE_UPDATE_LENGTH 4
Expand Down Expand Up @@ -1228,19 +1233,23 @@ int bt_h4_vnd_setup(const struct device *dev)
return 0;
}

err = bt_hci_baudrate_update(dev, operation_speed);
if (err) {
return err;
}
if (!fw_upload.is_setup_done) {
err = bt_hci_baudrate_update(dev, operation_speed);
if (err) {
return err;
}

/* BT waiting time after controller bandrate updated */
(void)k_msleep(CONFIG_BT_H4_NXP_CTLR_WAIT_TIME_AFTER_BAUDRATE_UPDATE);
/* BT waiting time after controller bandrate updated */
(void)k_msleep(CONFIG_BT_H4_NXP_CTLR_WAIT_TIME_AFTER_BAUDRATE_UPDATE);
}

err = fw_upload_uart_reconfig(operation_speed, flowcontrol_of_hci);
if (err) {
LOG_ERR("Fail to update uart bandrate");
return err;
}

fw_upload.is_setup_done = true;

return 0;
}
9 changes: 1 addition & 8 deletions drivers/bluetooth/hci/ipc.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2019 Nordic Semiconductor ASA
* Copyright 2025 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -378,14 +379,6 @@ static int bt_ipc_close(const struct device *dev)
struct ipc_data *ipc = dev->data;
int err;

if (IS_ENABLED(CONFIG_BT_HCI_HOST)) {
err = bt_hci_cmd_send_sync(BT_HCI_OP_RESET, NULL, NULL);
if (err) {
LOG_ERR("Sending reset command failed with: %d", err);
return err;
}
}

err = ipc_service_deregister_endpoint(&ipc->hci_ept);
if (err) {
LOG_ERR("Deregistering HCI endpoint failed with: %d", err);
Expand Down
28 changes: 17 additions & 11 deletions subsys/bluetooth/host/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/*
* Copyright (c) 2017-2025 Nordic Semiconductor ASA
* Copyright (c) 2015-2016 Intel Corporation
* Copyright 2025 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -2390,17 +2391,10 @@ static void le_ltk_request(struct net_buf *buf)
}
#endif /* CONFIG_BT_SMP */

static void hci_reset_complete(struct net_buf *buf)
static void hci_reset_complete(void)
{
uint8_t status = buf->data[0];
atomic_t flags;

LOG_DBG("status 0x%02x %s", status, bt_hci_err_to_str(status));

if (status) {
return;
}

if (IS_ENABLED(CONFIG_BT_OBSERVER)) {
bt_scan_reset();
}
Expand Down Expand Up @@ -3256,12 +3250,12 @@ static int common_init(void)

if (!drv_quirk_no_reset()) {
/* Send HCI_RESET */
err = bt_hci_cmd_send_sync(BT_HCI_OP_RESET, NULL, &rsp);
err = bt_hci_cmd_send_sync(BT_HCI_OP_RESET, NULL, NULL);
if (err) {
return err;
}
hci_reset_complete(rsp);
net_buf_unref(rsp);

hci_reset_complete();
}

/* Read Local Supported Features */
Expand Down Expand Up @@ -4384,6 +4378,18 @@ int bt_disable(void)
disconnected_handles_reset();
#endif /* CONFIG_BT_CONN */

/* Reset the Controller */
if (!drv_quirk_no_reset()) {

err = bt_hci_cmd_send_sync(BT_HCI_OP_RESET, NULL, NULL);
if (err) {
LOG_ERR("Failed to reset BLE controller");
return err;
}

hci_reset_complete();
}

err = bt_hci_close(bt_dev.hci);
if (err == -ENOSYS) {
atomic_clear_bit(bt_dev.flags, BT_DEV_DISABLE);
Expand Down
Loading