|
6 | 6 |
|
7 | 7 | #include <errno.h>
|
8 | 8 | #include <stddef.h>
|
| 9 | +#include <string.h> |
9 | 10 |
|
10 | 11 | #include <zephyr/kernel.h>
|
11 | 12 | #include <zephyr/arch/cpu.h>
|
|
16 | 17 | #include <zephyr/sys/util.h>
|
17 | 18 | #include <zephyr/sys/byteorder.h>
|
18 | 19 | #include <zephyr/sys/crc.h>
|
19 |
| -#include <string.h> |
| 20 | + |
| 21 | +#include <zephyr/bluetooth/bluetooth.h> |
| 22 | +#include <zephyr/bluetooth/hci.h> |
20 | 23 |
|
21 | 24 | #define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
|
22 | 25 | #include <zephyr/logging/log.h>
|
@@ -1056,7 +1059,6 @@ static int bt_nxp_ctlr_init(void)
|
1056 | 1059 | }
|
1057 | 1060 |
|
1058 | 1061 | speed = DT_PROP(DT_INST_GPARENT(0), current_speed);
|
1059 |
| - speed = DT_PROP_OR(DT_DRV_INST(0), hci_operation_speed, speed); |
1060 | 1062 | uart_dev_data.primary_speed = DT_PROP_OR(DT_DRV_INST(0), fw_download_primary_speed, speed);
|
1061 | 1063 | uart_dev_data.secondary_speed =
|
1062 | 1064 | 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)
|
1175 | 1177 |
|
1176 | 1178 | return bt_nxp_ctlr_init();
|
1177 | 1179 | }
|
| 1180 | + |
| 1181 | +#define BT_HCI_VSC_BAUDRATE_UPDATE_LENGTH 4 |
| 1182 | +#define BT_HCI_VSC_BAUDRATE_UPDATE_OPCODE BT_OP(BT_OGF_VS, 0x09) |
| 1183 | + |
| 1184 | +static int bt_hci_baudrate_update(const struct device *dev, uint32_t baudrate) |
| 1185 | +{ |
| 1186 | + int err; |
| 1187 | + struct net_buf *buf; |
| 1188 | + |
| 1189 | + buf = bt_hci_cmd_create(BT_HCI_VSC_BAUDRATE_UPDATE_OPCODE, |
| 1190 | + BT_HCI_VSC_BAUDRATE_UPDATE_LENGTH); |
| 1191 | + if (!buf) { |
| 1192 | + LOG_ERR("Fail to allocate buffer"); |
| 1193 | + return -ENOBUFS; |
| 1194 | + } |
| 1195 | + |
| 1196 | + /* Add new baudrate to the buffer */ |
| 1197 | + net_buf_add_le32(buf, baudrate); |
| 1198 | + |
| 1199 | + err = bt_hci_cmd_send_sync(BT_HCI_VSC_BAUDRATE_UPDATE_OPCODE, buf, NULL); |
| 1200 | + if (err) { |
| 1201 | + LOG_ERR("Fail to send baudrate update cmd"); |
| 1202 | + return err; |
| 1203 | + } |
| 1204 | + |
| 1205 | + return 0; |
| 1206 | +} |
| 1207 | + |
| 1208 | +int bt_h4_vnd_setup(const struct device *dev) |
| 1209 | +{ |
| 1210 | + int err; |
| 1211 | + uint32_t default_speed; |
| 1212 | + uint32_t operation_speed; |
| 1213 | + bool flowcontrol_of_hci; |
| 1214 | + |
| 1215 | + if (dev != uart_dev) { |
| 1216 | + return -EINVAL; |
| 1217 | + } |
| 1218 | + |
| 1219 | + if (!device_is_ready(uart_dev)) { |
| 1220 | + return -ENODEV; |
| 1221 | + } |
| 1222 | + |
| 1223 | + default_speed = DT_PROP(DT_INST_GPARENT(0), current_speed); |
| 1224 | + operation_speed = DT_PROP_OR(DT_DRV_INST(0), hci_operation_speed, default_speed); |
| 1225 | + flowcontrol_of_hci = (bool)DT_PROP_OR(DT_DRV_INST(0), hw_flow_control, false); |
| 1226 | + |
| 1227 | + if (operation_speed == default_speed) { |
| 1228 | + return 0; |
| 1229 | + } |
| 1230 | + |
| 1231 | + err = bt_hci_baudrate_update(dev, operation_speed); |
| 1232 | + if (err) { |
| 1233 | + return err; |
| 1234 | + } |
| 1235 | + |
| 1236 | + /* BT waiting time after controller bandrate updated */ |
| 1237 | + (void)k_msleep(CONFIG_BT_H4_NXP_CTLR_WAIT_TIME_AFTER_BAUDRATE_UPDATE); |
| 1238 | + |
| 1239 | + err = fw_upload_uart_reconfig(operation_speed, flowcontrol_of_hci); |
| 1240 | + if (err) { |
| 1241 | + LOG_ERR("Fail to update uart bandrate"); |
| 1242 | + return err; |
| 1243 | + } |
| 1244 | + |
| 1245 | + return 0; |
| 1246 | +} |
0 commit comments