From adb69b42aaf457f9cc11d13249e0fcc88dfd8eae Mon Sep 17 00:00:00 2001 From: Jukka Laitinen Date: Wed, 23 Oct 2024 11:15:44 +0300 Subject: [PATCH] arch/arm64/src/imx9/imx9_lpspi.c: Small cache operation optimization There is no need to invalidate the RX buffer before every transfer. It is never gets dirty, so it is good to invalidate initially after allocation, and after each transfer. Signed-off-by: Jukka Laitinen --- arch/arm64/src/imx9/imx9_lpspi.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/arch/arm64/src/imx9/imx9_lpspi.c b/arch/arm64/src/imx9/imx9_lpspi.c index 5d8e788115002..610276a5f8b21 100644 --- a/arch/arm64/src/imx9/imx9_lpspi.c +++ b/arch/arm64/src/imx9/imx9_lpspi.c @@ -1386,14 +1386,6 @@ static void imx9_lpspi_exchange(struct spi_dev_s *dev, (uintptr_t)priv->txbuf + nbytes); } - if (rxbuffer) - { - /* Prepare the RX buffer for DMA */ - - up_invalidate_dcache((uintptr_t)priv->rxbuf, - (uintptr_t)priv->rxbuf + nbytes); - } - /* Set up the DMA */ adjust = (priv->nbits > 8) ? 2 : 1; @@ -2079,6 +2071,12 @@ struct spi_dev_s *imx9_lpspibus_initialize(int bus) priv->txbuf = imx9_dma_alloc(CONFIG_IMX9_LPSPI_DMA_BUFFER_SIZE); priv->rxbuf = imx9_dma_alloc(CONFIG_IMX9_LPSPI_DMA_BUFFER_SIZE); DEBUGASSERT(priv->txbuf && priv->rxbuf); + + /* Invalidate the RX buffer area initially */ + + up_invalidate_dcache((uintptr_t)priv->rxbuf, + (uintptr_t)priv->rxbuf + + CONFIG_IMX9_LPSPI_DMA_BUFFER_SIZE); } } else