Bluetooth: drivers: Convert NXP HCI driver to new API
Convert the hci_nxp.c HCI driver to use the new HCI driver API. Also move the driver binding under dts/bindings/bluetooth, like all other HCI driver bindings. Signed-off-by: Johan Hedberg <johan.hedberg@gmail.com>
This commit is contained in:
parent
f33aab9889
commit
fcddefd7f0
5 changed files with 41 additions and 22 deletions
|
@ -126,6 +126,8 @@ config BT_DA1469X
|
|||
|
||||
config BT_NXP
|
||||
bool "NXP HCI driver"
|
||||
default y
|
||||
depends on DT_HAS_NXP_HCI_BLE_ENABLED
|
||||
select BT_HCI_SETUP
|
||||
help
|
||||
NXP HCI bluetooth interface
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include <zephyr/init.h>
|
||||
#include <zephyr/drivers/bluetooth/hci_driver.h>
|
||||
#include <zephyr/drivers/bluetooth.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/sys/byteorder.h>
|
||||
#include <zephyr/device.h>
|
||||
|
@ -26,6 +26,10 @@
|
|||
|
||||
#define DT_DRV_COMPAT nxp_hci_ble
|
||||
|
||||
struct bt_nxp_data {
|
||||
bt_hci_recv_t recv;
|
||||
};
|
||||
|
||||
#define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
|
||||
LOG_MODULE_REGISTER(bt_driver);
|
||||
|
||||
|
@ -244,6 +248,8 @@ static struct net_buf *bt_acl_recv(uint8_t *data, size_t len)
|
|||
|
||||
static void hci_rx_cb(uint8_t packetType, uint8_t *data, uint16_t len)
|
||||
{
|
||||
const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0));
|
||||
struct bt_nxp_data *hci = dev->data;
|
||||
struct net_buf *buf;
|
||||
|
||||
switch (packetType) {
|
||||
|
@ -262,14 +268,16 @@ static void hci_rx_cb(uint8_t packetType, uint8_t *data, uint16_t len)
|
|||
|
||||
if (buf) {
|
||||
/* Provide the buffer to the host */
|
||||
bt_recv(buf);
|
||||
hci->recv(dev, buf);
|
||||
}
|
||||
}
|
||||
|
||||
static int bt_nxp_send(struct net_buf *buf)
|
||||
static int bt_nxp_send(const struct device *dev, struct net_buf *buf)
|
||||
{
|
||||
uint8_t packetType;
|
||||
|
||||
ARG_UNUSED(dev);
|
||||
|
||||
switch (bt_buf_get_type(buf)) {
|
||||
case BT_BUF_CMD:
|
||||
packetType = BT_HCI_H4_CMD;
|
||||
|
@ -290,8 +298,9 @@ static int bt_nxp_send(struct net_buf *buf)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int bt_nxp_open(void)
|
||||
static int bt_nxp_open(const struct device *dev, bt_hci_recv_t recv)
|
||||
{
|
||||
struct bt_nxp_data *hci = dev->data;
|
||||
int ret = 0;
|
||||
|
||||
do {
|
||||
|
@ -312,13 +321,16 @@ static int bt_nxp_open(void)
|
|||
LOG_ERR("HCI open failed");
|
||||
break;
|
||||
}
|
||||
|
||||
hci->recv = recv;
|
||||
} while (false);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int bt_nxp_setup(const struct bt_hci_setup_params *params)
|
||||
int bt_nxp_setup(const struct device *dev, const struct bt_hci_setup_params *params)
|
||||
{
|
||||
ARG_UNUSED(dev);
|
||||
ARG_UNUSED(params);
|
||||
|
||||
int ret;
|
||||
|
@ -362,8 +374,9 @@ int bt_nxp_setup(const struct bt_hci_setup_params *params)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int bt_nxp_close(void)
|
||||
static int bt_nxp_close(const struct device *dev)
|
||||
{
|
||||
struct bt_nxp_data *hci = dev->data;
|
||||
int ret = 0;
|
||||
/* Reset the Controller */
|
||||
#if CONFIG_BT_HCI_HOST
|
||||
|
@ -378,23 +391,25 @@ static int bt_nxp_close(void)
|
|||
LOG_ERR("Failed to shutdown BLE controller");
|
||||
}
|
||||
#endif
|
||||
hci->recv = NULL;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct bt_hci_driver drv = {
|
||||
.name = "BT NXP",
|
||||
static const struct bt_hci_driver_api drv = {
|
||||
.open = bt_nxp_open,
|
||||
.setup = bt_nxp_setup,
|
||||
.close = bt_nxp_close,
|
||||
.send = bt_nxp_send,
|
||||
.bus = BT_HCI_DRIVER_BUS_IPM,
|
||||
};
|
||||
|
||||
static int bt_nxp_init(void)
|
||||
static int bt_nxp_init(const struct device *dev)
|
||||
{
|
||||
int status;
|
||||
int ret = 0;
|
||||
|
||||
ARG_UNUSED(dev);
|
||||
|
||||
/* HCI Interrupt */
|
||||
IRQ_CONNECT(HCI_IRQ_N, HCI_IRQ_P, ble_hci_handler, 0, 0);
|
||||
irq_enable(HCI_IRQ_N);
|
||||
|
@ -414,16 +429,16 @@ static int bt_nxp_init(void)
|
|||
ret = status;
|
||||
break;
|
||||
}
|
||||
|
||||
status = bt_hci_driver_register(&drv);
|
||||
if (status < 0) {
|
||||
LOG_ERR("HCI driver registration failed");
|
||||
ret = status;
|
||||
break;
|
||||
}
|
||||
} while (0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SYS_INIT(bt_nxp_init, POST_KERNEL, CONFIG_BT_HCI_INIT_PRIORITY);
|
||||
#define HCI_DEVICE_INIT(inst) \
|
||||
static struct bt_nxp_data hci_data_##inst = { \
|
||||
}; \
|
||||
DEVICE_DT_INST_DEFINE(inst, bt_nxp_init, NULL, &hci_data_##inst, NULL, \
|
||||
POST_KERNEL, CONFIG_BT_HCI_INIT_PRIORITY, &drv)
|
||||
|
||||
/* Only one instance supported right now */
|
||||
HCI_DEVICE_INIT(0)
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
/ {
|
||||
chosen {
|
||||
zephyr,entropy = &trng;
|
||||
zephyr,bt-hci = &hci;
|
||||
};
|
||||
|
||||
cpus {
|
||||
|
|
|
@ -5,8 +5,12 @@ description: NXP BLE HCI information
|
|||
|
||||
compatible: "nxp,hci-ble"
|
||||
|
||||
include: base.yaml
|
||||
include: bt-hci.yaml
|
||||
|
||||
properties:
|
||||
interrupts:
|
||||
required: true
|
||||
bt-hci-name:
|
||||
default: "BT NXP"
|
||||
bt-hci-bus:
|
||||
default: "BT_HCI_BUS_IPM"
|
|
@ -85,9 +85,6 @@ if BT
|
|||
config FLASH
|
||||
default y
|
||||
|
||||
config BT_NXP
|
||||
default y
|
||||
|
||||
config BT_DIS_MANUF
|
||||
default "NXP"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue