Skip to content

Commit

Permalink
arch/arm64/src/imx9/imx9_lpspi.c: Fix 9-16 bit transfers and dcache i…
Browse files Browse the repository at this point in the history
…nvalidate

Signed-off-by: Jukka Laitinen <[email protected]>
  • Loading branch information
jlaitine committed Oct 22, 2024
1 parent 1409b72 commit d3c9fef
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions arch/arm64/src/imx9/imx9_lpspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@
#define SPI_SR_CLEAR (LPSPI_SR_WCF | LPSPI_SR_FCF | LPSPI_SR_TCF | \
LPSPI_SR_TEF | LPSPI_SR_REF | LPSPI_SR_DMF)

#if !defined(ARMV8A_DCACHE_LINESIZE) || ARMV8A_DCACHE_LINESIZE == 0
# undef ARMV8A_DCACHE_LINESIZE
# define ARMV8A_DCACHE_LINESIZE 64
#endif

#define DCACHE_LINEMASK (ARMV8A_DCACHE_LINESIZE - 1)
#define DCACHE_ALIGN_UP(a) (((a) + DCACHE_LINEMASK) & ~DCACHE_LINEMASK)

/****************************************************************************
* Private Types
****************************************************************************/
Expand Down Expand Up @@ -1323,7 +1331,7 @@ static void imx9_lpspi_exchange(struct spi_dev_s *dev,

/* Convert the number of word to a number of bytes */

nbytes = (priv->nbits > 8) ? nwords << 2 : nwords;
nbytes = (priv->nbits > 8) ? nwords << 1 : nwords;

/* Invalid DMA channels fall back to non-DMA method. */

Expand Down Expand Up @@ -1404,7 +1412,7 @@ static void imx9_lpspi_exchange(struct spi_dev_s *dev,
config.daddr = (uintptr_t) (rxbuffer ? priv->rxbuf : rxdummy);
config.soff = 0;
config.doff = rxbuffer ? adjust : 0;
config.iter = nbytes;
config.iter = nwords;
config.flags = EDMA_CONFIG_LINKTYPE_LINKNONE;
config.ssize = adjust == 1 ? EDMA_8BIT : EDMA_16BIT;
config.dsize = adjust == 1 ? EDMA_8BIT : EDMA_16BIT;
Expand All @@ -1418,7 +1426,7 @@ static void imx9_lpspi_exchange(struct spi_dev_s *dev,
config.daddr = priv->spibase + IMX9_LPSPI_TDR_OFFSET;
config.soff = txbuffer ? adjust : 0;
config.doff = 0;
config.iter = nbytes;
config.iter = nwords;
config.flags = EDMA_CONFIG_LINKTYPE_LINKNONE;
config.ssize = adjust == 1 ? EDMA_8BIT : EDMA_16BIT;
config.dsize = adjust == 1 ? EDMA_8BIT : EDMA_16BIT;
Expand Down Expand Up @@ -1464,7 +1472,7 @@ static void imx9_lpspi_exchange(struct spi_dev_s *dev,
/* Flush the RX data to ram */

up_invalidate_dcache((uintptr_t)priv->rxbuf,
(uintptr_t)priv->rxbuf + nbytes);
(uintptr_t)priv->rxbuf + DCACHE_ALIGN_UP(nbytes));

/* Copy data to user buffer */

Expand Down

0 comments on commit d3c9fef

Please sign in to comment.