drivers: spi_mcux_lpspi: Fix synchronous DMA CS

Fix the chip select when using the synchronous API with DMA path.

Note need to use TxDataRequest flag instead of ModuleBusy flag now
because module busy flag will not deassert until PCS deasserts.

This does not fix CS for the non-DMA path, because that would require a
large driver rework.

Do not skip configuration when calling transceive with the same spi_cfg
because we need to write a new command word.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
This commit is contained in:
Declan Snyder 2024-09-19 13:20:49 -05:00 committed by Anas Nashif
parent 0186bfb2d0
commit 30a8f87d6a

View file

@ -199,11 +199,6 @@ static int spi_mcux_configure(const struct device *dev,
uint32_t clock_freq; uint32_t clock_freq;
uint32_t word_size; uint32_t word_size;
if (spi_context_configured(&data->ctx, spi_cfg)) {
/* This configuration is already in use */
return 0;
}
if (spi_cfg->operation & SPI_HALF_DUPLEX) { if (spi_cfg->operation & SPI_HALF_DUPLEX) {
LOG_ERR("Half-duplex not supported"); LOG_ERR("Half-duplex not supported");
return -ENOTSUP; return -ENOTSUP;
@ -517,6 +512,8 @@ static int transceive_dma(const struct device *dev,
return ret; return ret;
} }
base->TCR |= LPSPI_TCR_CONT_MASK;
/* DMA is fast enough watermarks are not required */ /* DMA is fast enough watermarks are not required */
LPSPI_SetFifoWatermarks(base, 0U, 0U); LPSPI_SetFifoWatermarks(base, 0U, 0U);
@ -531,6 +528,11 @@ static int transceive_dma(const struct device *dev,
if (ret != 0) { if (ret != 0) {
goto out; goto out;
} }
while (!(LPSPI_GetStatusFlags(base) & kLPSPI_TxDataRequestFlag)) {
/* wait until previous tx finished */
}
/* Enable DMA Requests */ /* Enable DMA Requests */
LPSPI_EnableDMA(base, kLPSPI_TxDmaEnable | kLPSPI_RxDmaEnable); LPSPI_EnableDMA(base, kLPSPI_TxDmaEnable | kLPSPI_RxDmaEnable);
@ -539,9 +541,6 @@ static int transceive_dma(const struct device *dev,
if (ret != 0) { if (ret != 0) {
goto out; goto out;
} }
while ((LPSPI_GetStatusFlags(base) & kLPSPI_ModuleBusyFlag)) {
/* wait until module is idle */
}
/* Disable DMA */ /* Disable DMA */
LPSPI_DisableDMA(base, kLPSPI_TxDmaEnable | kLPSPI_RxDmaEnable); LPSPI_DisableDMA(base, kLPSPI_TxDmaEnable | kLPSPI_RxDmaEnable);
@ -551,6 +550,7 @@ static int transceive_dma(const struct device *dev,
spi_context_update_rx(&data->ctx, 1, dma_size); spi_context_update_rx(&data->ctx, 1, dma_size);
} }
spi_context_cs_control(&data->ctx, false); spi_context_cs_control(&data->ctx, false);
base->TCR = 0;
out: out:
spi_context_release(&data->ctx, ret); spi_context_release(&data->ctx, ret);