spi: oc_tiny_spi: Refactor to simplify spi_xfer implementation
PATCH 1/1 spi: oc_tiny_spi: Refactor to simplify spi_xfer implementation
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,
This path is similar to the patch I sent for spi-oc-tiny.c linux driver. I'd appreciate if you can review and test this patch. Regards,
Axel
drivers/spi/oc_tiny_spi.c | 85 ++++++----------------------------------------- 1 file changed, 11 insertions(+), 74 deletions(-)
drivers/spi/oc_tiny_spi.c +11 -74
@@ -158,85 +158,22 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,spi_cs_activate (slave);/* we need to tighten the transfer loop */ -if (txp && rxp) { -writeb (*txp++, ®s->txdata); -if (bytes >1 ) { -writeb (*txp++, ®s->txdata); -for (i =2 ; i < bytes; i++) { -u8 rx, tx = *txp++; -while (!(readb (®s->status) & -TINY_SPI_STATUS_TXR )) +writeb (txp ? *txp++ :CONFIG_TINY_SPI_IDLE_VAL , ®s->txdata); +for (i =1 ; i < bytes; i++) { +writeb (txp ? *txp++ :CONFIG_TINY_SPI_IDLE_VAL , ®s->txdata); + +if (rxp || (i != bytes -1 )) { +while (!(readb (®s->status) &TINY_SPI_STATUS_TXR )) ; - rx =readb (®s->txdata); -writeb (tx, ®s->txdata); - *rxp++ = rx; - } -while (!(readb (®s->status) & -TINY_SPI_STATUS_TXR )) - ; - *rxp++ =readb (®s->txdata); } -while (!(readb (®s->status) & -TINY_SPI_STATUS_TXE )) - ; - *rxp++ =readb (®s->rxdata); - }else if (rxp) { -writeb (CONFIG_TINY_SPI_IDLE_VAL , ®s->txdata); -if (bytes >1 ) { -writeb (CONFIG_TINY_SPI_IDLE_VAL , - ®s->txdata); -for (i =2 ; i < bytes; i++) { -u8 rx; -while (!(readb (®s->status) & -TINY_SPI_STATUS_TXR )) - ; - rx =readb (®s->txdata); -writeb (CONFIG_TINY_SPI_IDLE_VAL , - ®s->txdata); - *rxp++ = rx; - } -while (!(readb (®s->status) & -TINY_SPI_STATUS_TXR )) - ; + +if (rxp) *rxp++ =readb (®s->txdata); - } -while (!(readb (®s->status) & -TINY_SPI_STATUS_TXE )) + } +while (!(readb (®s->status) &TINY_SPI_STATUS_TXE )) ; +if (rxp) *rxp++ =readb (®s->rxdata); - }else if (txp) { -writeb (*txp++, ®s->txdata); -if (bytes >1 ) { -writeb (*txp++, ®s->txdata); -for (i =2 ; i < bytes; i++) { -u8 tx = *txp++; -while (!(readb (®s->status) & -TINY_SPI_STATUS_TXR )) - ; -writeb (tx, ®s->txdata); - } - } -while (!(readb (®s->status) & -TINY_SPI_STATUS_TXE )) - ; - }else { -writeb (CONFIG_TINY_SPI_IDLE_VAL , ®s->txdata); -if (bytes >1 ) { -writeb (CONFIG_TINY_SPI_IDLE_VAL , - ®s->txdata); -for (i =2 ; i < bytes; i++) { -while (!(readb (®s->status) & -TINY_SPI_STATUS_TXR )) - ; -writeb (CONFIG_TINY_SPI_IDLE_VAL , - ®s->txdata); - } - } -while (!(readb (®s->status) & -TINY_SPI_STATUS_TXE )) - ; - } - done:if (flags &SPI_XFER_END )spi_cs_deactivate (slave);
Signature · 1 line
1.8.1.2
PATCH 1/1 spi: oc_tiny_spi: Refactor to simplify spi_xfer implementation
Hi Axel,
Any testing on this patch?
Quoted 120 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.
Signed-off-by Axel Lin <[email protected]>---
Hi Thomas,
This path is similar to the patch I sent forspi-oc-tiny.clinux driver. I'd appreciate if you can review and test this patch. Regards,
Axeldrivers/spi/oc_tiny_spi.c | 85 ++++++----------------------------------------- 1 file changed, 11 insertions(+), 74 deletions(-)drivers/spi/oc_tiny_spi.c +11
-75@@ -158,85 +158,22 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,spi_cs_activate (slave);/* we need to tighten the transfer loop */ -if (txp && rxp) { -writeb (*txp++, ®s->txdata); -if (bytes >1 ) { -writeb (*txp++, ®s->txdata); -for (i =2 ; i < bytes; i++) { -u8 rx, tx = *txp++; -while (!(readb (®s->status) & -TINY_SPI_STATUS_TXR )) +writeb (txp ? *txp++ :CONFIG_TINY_SPI_IDLE_VAL , ®s->txdata); +for (i =1 ; i < bytes; i++) { +writeb (txp ? *txp++ :CONFIG_TINY_SPI_IDLE_VAL , ®s->txdata); + +if (rxp || (i != bytes -1 )) { +while (!(readb (®s->status) &TINY_SPI_STATUS_TXR )) ; - rx =readb (®s->txdata); -writeb (tx, ®s->txdata); - *rxp++ = rx; - } -while (!(readb (®s->status) & -TINY_SPI_STATUS_TXR )) - ; - *rxp++ =readb (®s->txdata); } -while (!(readb (®s->status) & -TINY_SPI_STATUS_TXE )) - ; - *rxp++ =readb (®s->rxdata); - }else if (rxp) { -writeb (CONFIG_TINY_SPI_IDLE_VAL , ®s->txdata); -if (bytes >1 ) { -writeb (CONFIG_TINY_SPI_IDLE_VAL , - ®s->txdata); -for (i =2 ; i < bytes; i++) { -u8 rx; -while (!(readb (®s->status) & -TINY_SPI_STATUS_TXR )) - ; - rx =readb (®s->txdata); -writeb (CONFIG_TINY_SPI_IDLE_VAL , - ®s->txdata); - *rxp++ = rx; - } -while (!(readb (®s->status) & -TINY_SPI_STATUS_TXR )) - ; + +if (rxp) *rxp++ =readb (®s->txdata); - } -while (!(readb (®s->status) & -TINY_SPI_STATUS_TXE )) + } +while (!(readb (®s->status) &TINY_SPI_STATUS_TXE )) ; +if (rxp) *rxp++ =readb (®s->rxdata); - }else if (txp) { -writeb (*txp++, ®s->txdata); -if (bytes >1 ) { -writeb (*txp++, ®s->txdata); -for (i =2 ; i < bytes; i++) { -u8 tx = *txp++; -while (!(readb (®s->status) & -TINY_SPI_STATUS_TXR )) - ; -writeb (tx, ®s->txdata); - } - } -while (!(readb (®s->status) & -TINY_SPI_STATUS_TXE )) - ; - }else { -writeb (CONFIG_TINY_SPI_IDLE_VAL , ®s->txdata); -if (bytes >1 ) { -writeb (CONFIG_TINY_SPI_IDLE_VAL , - ®s->txdata); -for (i =2 ; i < bytes; i++) { -while (!(readb (®s->status) & -TINY_SPI_STATUS_TXR )) - ; -writeb (CONFIG_TINY_SPI_IDLE_VAL , - ®s->txdata); - } - } -while (!(readb (®s->status) & -TINY_SPI_STATUS_TXE )) - ; - } - done:if (flags &SPI_XFER_END )spi_cs_deactivate (slave); --1.8.1.2
Quoted 4 lines
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot
thanks!
Signature · 1 line
Jagan.