1 /*
2 * Copyright 2024 Ian Morris
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/kernel.h>
8 #include <zephyr/device.h>
9 #include <zephyr/devicetree.h>
10 #include <zephyr/drivers/gpio.h>
11 #include <zephyr/drivers/uart.h>
12
13 #define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
14 #include <zephyr/logging/log.h>
15 LOG_MODULE_REGISTER(bt_hci_da1453x);
16
17 #define DT_DRV_COMPAT renesas_bt_hci_da1453x
18
bt_hci_transport_setup(const struct device * h4)19 int bt_hci_transport_setup(const struct device *h4)
20 {
21 int err = 0;
22
23 #if DT_INST_NODE_HAS_PROP(0, reset_gpios)
24 char c;
25 struct gpio_dt_spec bt_reset = GPIO_DT_SPEC_GET(DT_DRV_INST(0), reset_gpios);
26
27 if (!gpio_is_ready_dt(&bt_reset)) {
28 LOG_ERR("Error: failed to configure bt_reset %s pin %d", bt_reset.port->name,
29 bt_reset.pin);
30 return -EIO;
31 }
32
33 /* Set bt_reset as output and activate DA1453x reset */
34 err = gpio_pin_configure_dt(&bt_reset, GPIO_OUTPUT_ACTIVE);
35 if (err) {
36 LOG_ERR("Error %d: failed to configure bt_reset %s pin %d", err,
37 bt_reset.port->name, bt_reset.pin);
38 return err;
39 }
40
41 k_sleep(K_MSEC(DT_INST_PROP_OR(0, reset_assert_duration_ms, 0)));
42
43 /* Release the DA1453x from reset */
44 err = gpio_pin_set_dt(&bt_reset, 0);
45 if (err) {
46 return err;
47 }
48
49 /* Wait for the DA1453x to boot */
50 k_sleep(K_MSEC(DT_INST_PROP(0, boot_duration_ms)));
51
52 /* Drain bytes */
53 while (h4 && uart_fifo_read(h4, &c, 1)) {
54 continue;
55 }
56 #endif /* DT_INST_NODE_HAS_PROP(0, reset_gpios) */
57
58 return err;
59 }
60