arch: cxd56xx: Fix SPI transfer without DMA

SPI transfers are dynamically determined to use DMA or not.
The flag to judge is removed in a previous simple refactoring commit.
Revert the logic and fix an issue that SPI transfer fails.
This commit is contained in:
SPRESENSE 2023-01-25 18:14:06 +09:00 committed by Alin Jerpelea
parent 7ac80d4e59
commit e317af0a84

View File

@ -77,6 +77,7 @@ struct cxd56_spidev_s
uint8_t port; /* Port number */ uint8_t port; /* Port number */
int initialized; /* Initialized flag */ int initialized; /* Initialized flag */
#ifdef CONFIG_CXD56_DMAC #ifdef CONFIG_CXD56_DMAC
bool dmaenable; /* Use DMA or not */
DMA_HANDLE rxdmach; /* RX DMA channel handle */ DMA_HANDLE rxdmach; /* RX DMA channel handle */
DMA_HANDLE txdmach; /* TX DMA channel handle */ DMA_HANDLE txdmach; /* TX DMA channel handle */
sem_t dmasem; /* Wait for DMA to complete */ sem_t dmasem; /* Wait for DMA to complete */
@ -878,13 +879,15 @@ static void spi_exchange(struct spi_dev_s *dev, const void *txbuffer,
void *rxbuffer, size_t nwords) void *rxbuffer, size_t nwords)
{ {
#ifdef CONFIG_CXD56_DMAC #ifdef CONFIG_CXD56_DMAC
struct cxd56_spidev_s *priv = (struct cxd56_spidev_s *)dev;
#ifdef CONFIG_CXD56_SPI_DMATHRESHOLD #ifdef CONFIG_CXD56_SPI_DMATHRESHOLD
size_t dmath = CONFIG_CXD56_SPI_DMATHRESHOLD; size_t dmath = CONFIG_CXD56_SPI_DMATHRESHOLD;
#else #else
size_t dmath = 0; size_t dmath = 0;
#endif #endif
if (dmath < nwords) if (priv->dmaenable && dmath < nwords)
{ {
spi_dmaexchange(dev, txbuffer, rxbuffer, nwords); spi_dmaexchange(dev, txbuffer, rxbuffer, nwords);
} }
@ -1217,6 +1220,7 @@ struct spi_dev_s *cxd56_spibus_initialize(int port)
/* DMA settings */ /* DMA settings */
#ifdef CONFIG_CXD56_DMAC #ifdef CONFIG_CXD56_DMAC
priv->dmaenable = false;
priv->txdmach = NULL; priv->txdmach = NULL;
priv->rxdmach = NULL; priv->rxdmach = NULL;
#endif #endif
@ -1334,6 +1338,7 @@ void cxd56_spi_dmaconfig(int port, int chtype, DMA_HANDLE handle,
{ {
/* TX DMA setting */ /* TX DMA setting */
priv->dmaenable = true;
priv->txdmach = handle; priv->txdmach = handle;
memcpy(&priv->txconfig, conf, sizeof(dma_config_t)); memcpy(&priv->txconfig, conf, sizeof(dma_config_t));
} }
@ -1341,6 +1346,7 @@ void cxd56_spi_dmaconfig(int port, int chtype, DMA_HANDLE handle,
{ {
/* RX DMA setting */ /* RX DMA setting */
priv->dmaenable = true;
priv->rxdmach = handle; priv->rxdmach = handle;
memcpy(&priv->rxconfig, conf, sizeof(dma_config_t)); memcpy(&priv->rxconfig, conf, sizeof(dma_config_t));
} }