Driver: hci_nxp_setup: Support HCI baudrate update

Change running baudrate from `115200` from `3000000`.

Implement the function `bt_h4_vnd_setup` to update the HCI bandrate.

Add Kconfig `BT_H4_NXP_CTLR_WAIT_TIME_AFTER_BAUDRATE_UPDATE` to set
the waiting time after the controller bandrate HCI vendor specific
command sent. It is used to ensure the controller is ready to update
HCI bandrate.

Select `BT_HCI_SETUP` if `BT_H4_NXP_CTLR` is enabled.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
This commit is contained in:
Lyle Zhu 2024-11-29 11:45:43 +08:00 committed by Benjamin Cabé
commit 56929a26ca
3 changed files with 80 additions and 3 deletions

View file

@ -89,7 +89,7 @@ m2_hci_uart: &lpuart2 {
compatible = "nxp,bt-hci-uart";
sdio-reset-gpios = <&gpio9 15 GPIO_ACTIVE_HIGH>;
w-disable-gpios = <&gpio9 30 GPIO_ACTIVE_HIGH>;
hci-operation-speed = <115200>;
hci-operation-speed = <3000000>;
hw-flow-control;
fw-download-primary-speed = <115200>;
fw-download-secondary-speed = <3000000>;

View file

@ -304,6 +304,7 @@ config BT_H4_NXP_CTLR
select GPIO
depends on BT_H4
select CRC
select BT_HCI_SETUP
default y
depends on DT_HAS_NXP_BT_HCI_UART_ENABLED
help
@ -327,4 +328,11 @@ config BT_H4_NXP_CTLR_WAIT_TIME_AFTER_UPLOAD
help
Waiting time after firmware is uploaded. Unit is millisecond.
config BT_H4_NXP_CTLR_WAIT_TIME_AFTER_BAUDRATE_UPDATE
int "Waiting time after controller baudrate is updated"
range 500 5000
default 500
help
Waiting time after controller baudrate is updated. Unit is millisecond.
endif #BT_H4_NXP_CTLR

View file

@ -6,6 +6,7 @@
#include <errno.h>
#include <stddef.h>
#include <string.h>
#include <zephyr/kernel.h>
#include <zephyr/arch/cpu.h>
@ -16,7 +17,9 @@
#include <zephyr/sys/util.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/sys/crc.h>
#include <string.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/hci.h>
#define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
#include <zephyr/logging/log.h>
@ -1056,7 +1059,6 @@ static int bt_nxp_ctlr_init(void)
}
speed = DT_PROP(DT_INST_GPARENT(0), current_speed);
speed = DT_PROP_OR(DT_DRV_INST(0), hci_operation_speed, speed);
uart_dev_data.primary_speed = DT_PROP_OR(DT_DRV_INST(0), fw_download_primary_speed, speed);
uart_dev_data.secondary_speed =
DT_PROP_OR(DT_DRV_INST(0), fw_download_secondary_speed, speed);
@ -1175,3 +1177,70 @@ int bt_hci_transport_setup(const struct device *dev)
return bt_nxp_ctlr_init();
}
#define BT_HCI_VSC_BAUDRATE_UPDATE_LENGTH 4
#define BT_HCI_VSC_BAUDRATE_UPDATE_OPCODE BT_OP(BT_OGF_VS, 0x09)
static int bt_hci_baudrate_update(const struct device *dev, uint32_t baudrate)
{
int err;
struct net_buf *buf;
buf = bt_hci_cmd_create(BT_HCI_VSC_BAUDRATE_UPDATE_OPCODE,
BT_HCI_VSC_BAUDRATE_UPDATE_LENGTH);
if (!buf) {
LOG_ERR("Fail to allocate buffer");
return -ENOBUFS;
}
/* Add new baudrate to the buffer */
net_buf_add_le32(buf, baudrate);
err = bt_hci_cmd_send_sync(BT_HCI_VSC_BAUDRATE_UPDATE_OPCODE, buf, NULL);
if (err) {
LOG_ERR("Fail to send baudrate update cmd");
return err;
}
return 0;
}
int bt_h4_vnd_setup(const struct device *dev)
{
int err;
uint32_t default_speed;
uint32_t operation_speed;
bool flowcontrol_of_hci;
if (dev != uart_dev) {
return -EINVAL;
}
if (!device_is_ready(uart_dev)) {
return -ENODEV;
}
default_speed = DT_PROP(DT_INST_GPARENT(0), current_speed);
operation_speed = DT_PROP_OR(DT_DRV_INST(0), hci_operation_speed, default_speed);
flowcontrol_of_hci = (bool)DT_PROP_OR(DT_DRV_INST(0), hw_flow_control, false);
if (operation_speed == default_speed) {
return 0;
}
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);
err = fw_upload_uart_reconfig(operation_speed, flowcontrol_of_hci);
if (err) {
LOG_ERR("Fail to update uart bandrate");
return err;
}
return 0;
}