Skip to content

Commit

Permalink
drivers: bluetooth: hci_nxp_setup: support for bt disable and reinit
Browse files Browse the repository at this point in the history
- added flag in nxp setup driver to perform HCI controller firmware-
  load and configuration only once. This avoid loading/setting-up
  controller fw on successive bt_init() after bt_disable() call.

Signed-off-by: Nirav Agrawal <[email protected]>
  • Loading branch information
nirav-agrawal committed Mar 10, 2025
1 parent 237701e commit 4952520
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
7 changes: 5 additions & 2 deletions drivers/bluetooth/hci/h4.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/*
* Copyright (c) 2015-2016 Intel Corporation
* Copyright 2025 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -256,8 +257,10 @@ static void rx_thread(void *p1, void *p2, void *p3)
do {
uart_irq_rx_enable(cfg->uart);

LOG_DBG("Calling bt_recv(%p)", buf);
h4->recv(dev, buf);
if (h4->recv != NULL) {
LOG_DBG("Calling bt_recv(%p)", buf);
h4->recv(dev, buf);
}

/* Give other threads a chance to run if the ISR
* is receiving data so fast that rx.fifo never
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;
}

0 comments on commit 4952520

Please sign in to comment.