From 8379f64393a6b2c482af06f62ed8c02ee0319331 Mon Sep 17 00:00:00 2001 From: Hao Luo Date: Thu, 27 Jun 2024 18:32:50 +0800 Subject: [PATCH] drivers: bluetooth: hci_ambiq: get the spi cfg from the device Use the SPI configuration from the SPI device for data transaction. Signed-off-by: Hao Luo --- .../apollo4p_blue_kxr_evb.dts | 6 +- drivers/bluetooth/hci/hci_ambiq.c | 34 ++++--- drivers/spi/Kconfig.ambiq | 1 + dts/arm/ambiq/ambiq_apollo3_blue.dtsi | 3 +- dts/arm/ambiq/ambiq_apollo3p_blue.dtsi | 3 +- dts/arm/ambiq/ambiq_apollo4p_blue.dtsi | 89 +++++++++++++++++-- dts/bindings/bluetooth/ambiq,bt-hci-spi.yaml | 2 +- 7 files changed, 106 insertions(+), 32 deletions(-) diff --git a/boards/ambiq/apollo4p_blue_kxr_evb/apollo4p_blue_kxr_evb.dts b/boards/ambiq/apollo4p_blue_kxr_evb/apollo4p_blue_kxr_evb.dts index 599fc3fd017..6a246a1f12e 100644 --- a/boards/ambiq/apollo4p_blue_kxr_evb/apollo4p_blue_kxr_evb.dts +++ b/boards/ambiq/apollo4p_blue_kxr_evb/apollo4p_blue_kxr_evb.dts @@ -71,7 +71,7 @@ status = "okay"; }; -&iom0 { +&i2c0 { compatible = "ambiq,i2c"; pinctrl-0 = <&i2c0_default>; pinctrl-names = "default"; @@ -79,7 +79,7 @@ status = "okay"; }; -&iom1 { +&spi1 { compatible = "ambiq,spi"; pinctrl-0 = <&spi1_default>; pinctrl-names = "default"; @@ -88,7 +88,7 @@ status = "okay"; }; -&iom4 { +&spi4 { pinctrl-0 = <&spi4_default>; pinctrl-names = "default"; status = "okay"; diff --git a/drivers/bluetooth/hci/hci_ambiq.c b/drivers/bluetooth/hci/hci_ambiq.c index 34a2360a2c2..622b400ba8a 100644 --- a/drivers/bluetooth/hci/hci_ambiq.c +++ b/drivers/bluetooth/hci/hci_ambiq.c @@ -22,9 +22,6 @@ LOG_MODULE_REGISTER(bt_hci_driver); #include "apollox_blue.h" -#define HCI_SPI_NODE DT_COMPAT_GET_ANY_STATUS_OKAY(ambiq_bt_hci_spi) -#define SPI_DEV_NODE DT_BUS(HCI_SPI_NODE) - /* Offset of special item */ #define PACKET_TYPE 0 #define PACKET_TYPE_SIZE 1 @@ -56,11 +53,13 @@ LOG_MODULE_REGISTER(bt_hci_driver); #define SPI_BUSY_TX_ATTEMPTS 200 static uint8_t __noinit rxmsg[SPI_MAX_RX_MSG_LEN]; -static const struct device *spi_dev = DEVICE_DT_GET(SPI_DEV_NODE); -static struct spi_config spi_cfg = { - .operation = SPI_OP_MODE_MASTER | SPI_TRANSFER_MSB | SPI_MODE_CPOL | SPI_MODE_CPHA | - SPI_WORD_SET(8), -}; + +static struct spi_dt_spec spi_bus = + SPI_DT_SPEC_INST_GET(0, + SPI_OP_MODE_MASTER | SPI_HALF_DUPLEX | SPI_TRANSFER_MSB | + SPI_MODE_CPOL | SPI_MODE_CPHA | SPI_WORD_SET(8), + 0); + static K_KERNEL_STACK_DEFINE(spi_rx_stack, CONFIG_BT_DRV_RX_STACK_SIZE); static struct k_thread spi_rx_thread_data; @@ -97,11 +96,11 @@ static inline int bt_spi_transceive(void *tx, uint32_t tx_len, void *rx, uint32_ * held at this moment to continue to send or receive packets. */ if (tx_len && rx_len) { - spi_cfg.operation |= SPI_HOLD_ON_CS; + spi_bus.config.operation |= SPI_HOLD_ON_CS; } else { - spi_cfg.operation &= ~SPI_HOLD_ON_CS; + spi_bus.config.operation &= ~SPI_HOLD_ON_CS; } - return spi_transceive(spi_dev, &spi_cfg, &spi_tx, &spi_rx); + return spi_transceive_dt(&spi_bus, &spi_tx, &spi_rx); } static int spi_send_packet(uint8_t *data, uint16_t len) @@ -379,7 +378,7 @@ static int bt_apollo_open(const struct device *dev, bt_hci_recv_t recv) struct bt_apollo_data *hci = dev->data; int ret; - ret = bt_hci_transport_setup(spi_dev); + ret = bt_hci_transport_setup(spi_bus.bus); if (ret) { return ret; } @@ -420,7 +419,7 @@ static int bt_apollo_init(const struct device *dev) ARG_UNUSED(dev); - if (!device_is_ready(spi_dev)) { + if (!device_is_ready(spi_bus.bus)) { LOG_ERR("SPI device not ready"); return -ENODEV; } @@ -435,11 +434,10 @@ static int bt_apollo_init(const struct device *dev) return 0; } -#define HCI_DEVICE_INIT(inst) \ - static struct bt_apollo_data hci_data_##inst = { \ - }; \ - DEVICE_DT_INST_DEFINE(inst, bt_apollo_init, NULL, &hci_data_##inst, NULL, \ - POST_KERNEL, CONFIG_BT_HCI_INIT_PRIORITY, &drv) +#define HCI_DEVICE_INIT(inst) \ + static struct bt_apollo_data hci_data_##inst = {}; \ + DEVICE_DT_INST_DEFINE(inst, bt_apollo_init, NULL, &hci_data_##inst, NULL, POST_KERNEL, \ + CONFIG_BT_HCI_INIT_PRIORITY, &drv) /* Only one instance supported right now */ HCI_DEVICE_INIT(0) diff --git a/drivers/spi/Kconfig.ambiq b/drivers/spi/Kconfig.ambiq index 5121655fb8b..f3f7a8ba1a3 100644 --- a/drivers/spi/Kconfig.ambiq +++ b/drivers/spi/Kconfig.ambiq @@ -10,6 +10,7 @@ menuconfig SPI_AMBIQ bool "AMBIQ SPI driver" default y depends on DT_HAS_AMBIQ_SPI_ENABLED + select GPIO select AMBIQ_HAL select AMBIQ_HAL_USE_SPI help diff --git a/dts/arm/ambiq/ambiq_apollo3_blue.dtsi b/dts/arm/ambiq/ambiq_apollo3_blue.dtsi index ae1028ab4a1..824729c8427 100644 --- a/dts/arm/ambiq/ambiq_apollo3_blue.dtsi +++ b/dts/arm/ambiq/ambiq_apollo3_blue.dtsi @@ -278,7 +278,7 @@ ambiq,pwrcfg = <&pwrcfg 0x8 0x800>; }; - bleif: bleif@5000c000 { + bleif: spi@5000c000 { compatible = "ambiq,spi-bleif"; reg = <0x5000c000 0x414>; interrupts = <12 1>; @@ -289,6 +289,7 @@ bt_hci_apollo: bt-hci@0 { compatible = "ambiq,bt-hci-spi"; + spi-max-frequency = ; reg = <0>; }; }; diff --git a/dts/arm/ambiq/ambiq_apollo3p_blue.dtsi b/dts/arm/ambiq/ambiq_apollo3p_blue.dtsi index 06af754aef5..d3e23687d02 100644 --- a/dts/arm/ambiq/ambiq_apollo3p_blue.dtsi +++ b/dts/arm/ambiq/ambiq_apollo3p_blue.dtsi @@ -319,7 +319,7 @@ ambiq,pwrcfg = <&pwrcfg 0x8 0x2000>; }; - bleif: bleif@5000c000 { + bleif: spi@5000c000 { compatible = "ambiq,spi-bleif"; reg = <0x5000c000 0x414>; interrupts = <12 1>; @@ -330,6 +330,7 @@ bt_hci_apollo: bt-hci@0 { compatible = "ambiq,bt-hci-spi"; + spi-max-frequency = ; reg = <0>; }; }; diff --git a/dts/arm/ambiq/ambiq_apollo4p_blue.dtsi b/dts/arm/ambiq/ambiq_apollo4p_blue.dtsi index 9656eadc984..2e438a2940a 100644 --- a/dts/arm/ambiq/ambiq_apollo4p_blue.dtsi +++ b/dts/arm/ambiq/ambiq_apollo4p_blue.dtsi @@ -126,7 +126,7 @@ ambiq,pwrcfg = <&pwrcfg 0x4 0x1000>; }; - iom0: iom@40050000 { + spi0: spi@40050000 { reg = <0x40050000 0x1000>; #address-cells = <1>; #size-cells = <0>; @@ -135,7 +135,7 @@ ambiq,pwrcfg = <&pwrcfg 0x4 0x2>; }; - iom1: iom@40051000 { + spi1: spi@40051000 { reg = <0x40051000 0x1000>; #address-cells = <1>; #size-cells = <0>; @@ -144,7 +144,7 @@ ambiq,pwrcfg = <&pwrcfg 0x4 0x4>; }; - iom2: iom@40052000 { + spi2: spi@40052000 { reg = <0x40052000 0x1000>; #address-cells = <1>; #size-cells = <0>; @@ -153,7 +153,7 @@ ambiq,pwrcfg = <&pwrcfg 0x4 0x8>; }; - iom3: iom@40053000 { + spi3: spi@40053000 { reg = <0x40053000 0x1000>; #address-cells = <1>; #size-cells = <0>; @@ -162,7 +162,7 @@ ambiq,pwrcfg = <&pwrcfg 0x4 0x10>; }; - iom4: spi@40054000 { + spi4: spi@40054000 { /* IOM4 works as SPI and is wired internally for BLE HCI. */ compatible = "ambiq,spi"; reg = <0x40054000 0x1000>; @@ -177,13 +177,14 @@ bt_hci_apollo: bt-hci@0 { compatible = "ambiq,bt-hci-spi"; reg = <0>; + spi-max-frequency = ; irq-gpios = <&gpio32_63 21 GPIO_ACTIVE_HIGH>; reset-gpios = <&gpio32_63 23 GPIO_ACTIVE_LOW>; clkreq-gpios = <&gpio32_63 20 GPIO_ACTIVE_HIGH>; }; }; - iom5: iom@40055000 { + spi5: spi@40055000 { reg = <0x40055000 0x1000>; #address-cells = <1>; #size-cells = <0>; @@ -192,7 +193,7 @@ ambiq,pwrcfg = <&pwrcfg 0x4 0x40>; }; - iom6: iom@40056000 { + spi6: spi@40056000 { reg = <0x40056000 0x1000>; #address-cells = <1>; #size-cells = <0>; @@ -201,7 +202,79 @@ ambiq,pwrcfg = <&pwrcfg 0x4 0x80>; }; - iom7: iom@40057000 { + spi7: spi@40057000 { + reg = <0x40057000 0x1000>; + #address-cells = <1>; + #size-cells = <0>; + interrupts = <13 0>; + status = "disabled"; + ambiq,pwrcfg = <&pwrcfg 0x4 0x100>; + }; + + i2c0: i2c@40050000 { + reg = <0x40050000 0x1000>; + #address-cells = <1>; + #size-cells = <0>; + interrupts = <6 0>; + status = "disabled"; + ambiq,pwrcfg = <&pwrcfg 0x4 0x2>; + }; + + i2c1: i2c@40051000 { + reg = <0x40051000 0x1000>; + #address-cells = <1>; + #size-cells = <0>; + interrupts = <7 0>; + status = "disabled"; + ambiq,pwrcfg = <&pwrcfg 0x4 0x4>; + }; + + i2c2: i2c@40052000 { + reg = <0x40052000 0x1000>; + #address-cells = <1>; + #size-cells = <0>; + interrupts = <8 0>; + status = "disabled"; + ambiq,pwrcfg = <&pwrcfg 0x4 0x8>; + }; + + i2c3: i2c@40053000 { + reg = <0x40053000 0x1000>; + #address-cells = <1>; + #size-cells = <0>; + interrupts = <9 0>; + status = "disabled"; + ambiq,pwrcfg = <&pwrcfg 0x4 0x10>; + }; + + i2c4: i2c@40054000 { + reg = <0x40054000 0x1000>; + #address-cells = <1>; + #size-cells = <0>; + interrupts = <10 0>; + status = "disabled"; + ambiq,pwrcfg = <&pwrcfg 0x4 0x20>; + }; + + i2c5: i2c@40055000 { + reg = <0x40055000 0x1000>; + #address-cells = <1>; + #size-cells = <0>; + interrupts = <11 0>; + status = "disabled"; + ambiq,pwrcfg = <&pwrcfg 0x4 0x40>; + }; + + i2c6: i2c@40056000 { + reg = <0x40056000 0x1000>; + #address-cells = <1>; + #size-cells = <0>; + interrupts = <12 0>; + status = "disabled"; + ambiq,pwrcfg = <&pwrcfg 0x4 0x80>; + }; + + i2c7: i2c@40057000 { reg = <0x40057000 0x1000>; #address-cells = <1>; #size-cells = <0>; diff --git a/dts/bindings/bluetooth/ambiq,bt-hci-spi.yaml b/dts/bindings/bluetooth/ambiq,bt-hci-spi.yaml index cbaabb318c1..8816d57bf66 100644 --- a/dts/bindings/bluetooth/ambiq,bt-hci-spi.yaml +++ b/dts/bindings/bluetooth/ambiq,bt-hci-spi.yaml @@ -7,7 +7,7 @@ description: | compatible: "ambiq,bt-hci-spi" -include: bt-hci.yaml +include: [spi-device.yaml, bt-hci.yaml] properties: reg: