From 30c41e955958329a3edda9cad53305faa11b719f Mon Sep 17 00:00:00 2001 From: Aaron Ye Date: Thu, 30 May 2024 17:40:18 +0800 Subject: [PATCH] drivers: bluetooth: hci_ambiq: add necessary SPI CS control Before sending packet to controller the host needs to poll the status of controller to know it's ready, or before reading packets from controller the host needs to get the payload size of coming packets by sending specific command and putting the status or size to the rx buffer, the CS should be held at this moment to continue to send or receive packets. This change is needed for the based SPI driver update. Signed-off-by: Aaron Ye --- drivers/bluetooth/hci/hci_ambiq.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/bluetooth/hci/hci_ambiq.c b/drivers/bluetooth/hci/hci_ambiq.c index 9428594980d..daaf943dca5 100644 --- a/drivers/bluetooth/hci/hci_ambiq.c +++ b/drivers/bluetooth/hci/hci_ambiq.c @@ -85,6 +85,18 @@ static inline int bt_spi_transceive(void *tx, uint32_t tx_len, void *rx, uint32_ spi_tx_buf.len = (size_t)tx_len; spi_rx_buf.buf = rx; spi_rx_buf.len = (size_t)rx_len; + + /* Before sending packet to controller the host needs to poll the status of + * controller to know it's ready, or before reading packets from controller + * the host needs to get the payload size of coming packets by sending specific + * command and putting the status or size to the rx buffer, the CS should be + * held at this moment to continue to send or receive packets. + */ + if (tx_len && rx_len) { + spi_cfg.operation |= SPI_HOLD_ON_CS; + } else { + spi_cfg.operation &= ~SPI_HOLD_ON_CS; + } return spi_transceive(spi_dev, &spi_cfg, &spi_tx, &spi_rx); }