spi: oc-tiny: Simplify tiny_spi_txrx_bufs implementation when irq is not used
PATCH 1/1 spi: oc-tiny: Simplify tiny_spi_txrx_bufs implementation when irq is not used
Currently we have similar code for (txp && rxp), (txp && !rxp), (!rxp & txp), and (!txp && !rxp) cases. This patch refactors the code a bit to avoid duplicate similar code.
---
Hi Thomas,
I don't have this hardware, so please test this path if you think it is ok. I think there is no functional change with this patch.
Thanks,
Axel
drivers/spi/spi-oc-tiny.c | 62 +++++++++-------------------------------------- 1 file changed, 11 insertions(+), 51 deletions(-)
drivers/spi/spi-oc-tiny.c +11 -51
@@ -153,62 +153,22 @@ static int tiny_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t) }wait_for_completion (&hw->done); - }else if (txp && rxp) { -/* we need to tighten the transfer loop */ -writeb (*txp++, hw->base +TINY_SPI_TXDATA ); -if (t->len >1 ) { -writeb (*txp++, hw->base +TINY_SPI_TXDATA ); -for (i =2 ; i < t->len; i++) { -u8 rx, tx = *txp++; -tiny_spi_wait_txr (hw); - rx =readb (hw->base +TINY_SPI_TXDATA ); -writeb (tx, hw->base +TINY_SPI_TXDATA ); - *rxp++ = rx; - } -tiny_spi_wait_txr (hw); - *rxp++ =readb (hw->base +TINY_SPI_TXDATA ); - } -tiny_spi_wait_txe (hw); - *rxp++ =readb (hw->base +TINY_SPI_RXDATA ); - }else if (rxp) { -writeb (0 , hw->base +TINY_SPI_TXDATA ); -if (t->len >1 ) { -writeb (0 , - hw->base +TINY_SPI_TXDATA ); -for (i =2 ; i < t->len; i++) { -u8 rx; -tiny_spi_wait_txr (hw); - rx =readb (hw->base +TINY_SPI_TXDATA ); -writeb (0 , hw->base +TINY_SPI_TXDATA ); - *rxp++ = rx; - } -tiny_spi_wait_txr (hw); - *rxp++ =readb (hw->base +TINY_SPI_TXDATA ); - } -tiny_spi_wait_txe (hw); - *rxp++ =readb (hw->base +TINY_SPI_RXDATA ); - }else if (txp) { -writeb (*txp++, hw->base +TINY_SPI_TXDATA ); -if (t->len >1 ) { -writeb (*txp++, hw->base +TINY_SPI_TXDATA ); -for (i =2 ; i < t->len; i++) { -u8 tx = *txp++; -tiny_spi_wait_txr (hw); -writeb (tx, hw->base +TINY_SPI_TXDATA ); - } - } -tiny_spi_wait_txe (hw); }else { -writeb (0 , hw->base +TINY_SPI_TXDATA ); -if (t->len >1 ) { -writeb (0 , hw->base +TINY_SPI_TXDATA ); -for (i =2 ; i < t->len; i++) { +/* we need to tighten the transfer loop */ +writeb (txp ? *txp++ :0 , hw->base +TINY_SPI_TXDATA ); +for (i =1 ; i < t->len; i++) { +writeb (txp ? *txp++ :0 , hw->base +TINY_SPI_TXDATA ); + +if (rxp || (i != t->len -1 ))tiny_spi_wait_txr (hw); -writeb (0 , hw->base +TINY_SPI_TXDATA ); - } +if (rxp) + *rxp++ =readb (hw->base +TINY_SPI_TXDATA ); }tiny_spi_wait_txe (hw); +if (rxp) + *rxp++ =readb (hw->base +TINY_SPI_RXDATA ); } +return t->len; }
Signature · 8 lines
1.8.1.2 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 3 lines · Axel Lin
Currently we have similar code for (txp && rxp), (txp && !rxp), (!rxp & txp), and (!txp && !rxp) cases. This patch refactors the code a bit to avoid duplicate similar code.
Applied, thanks - it's actually a moderately common pattern in various ways in drivers. I was thinking it might be good to have the core provide dummy buffers to drivers that need to do bidirectional transfers so the drivers only need to set a flag and don't need to open code this.