From: Axel Lin <axel.lin@ingics.com>
Date: Thu, 15 Aug 2013 06:18:46 +0000 (+0800)
Subject: spi: altera: Simplify altera_spi_txrx implementation for noirq case
X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=72be0ee42ebaf744d4a5cf684ee68dba59d6bac1;p=GitHub%2Fexynos8895%2Fandroid_kernel_samsung_universal8895.git

spi: altera: Simplify altera_spi_txrx implementation for noirq case

This patch simplifies the code and makes it better in readability.
Now the logic in the while loop is simply
"write to ALTERA_SPI_TXDATA then read from ALTERA_SPI_TXDATA".

There is a slightly logic change because now we avoid a read-write cycle when
hw->len is 0. Since the code in bitbang library will call bitbang->txrx_bufs()
only when t->len is not 0, this is not a problem.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Acked-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Mark Brown <broonie@linaro.org>
---

diff --git a/drivers/spi/spi-altera.c b/drivers/spi/spi-altera.c
index 81b9adb6e766..453fa5ac04ad 100644
--- a/drivers/spi/spi-altera.c
+++ b/drivers/spi/spi-altera.c
@@ -150,12 +150,12 @@ static int altera_spi_txrx(struct spi_device *spi, struct spi_transfer *t)
 		hw->imr &= ~ALTERA_SPI_CONTROL_IRRDY_MSK;
 		writel(hw->imr, hw->base + ALTERA_SPI_CONTROL);
 	} else {
-		/* send the first byte */
-		writel(hw_txbyte(hw, 0), hw->base + ALTERA_SPI_TXDATA);
-
-		while (1) {
+		while (hw->count < hw->len) {
 			unsigned int rxd;
 
+			writel(hw_txbyte(hw, hw->count),
+			       hw->base + ALTERA_SPI_TXDATA);
+
 			while (!(readl(hw->base + ALTERA_SPI_STATUS) &
 				 ALTERA_SPI_STATUS_RRDY_MSK))
 				cpu_relax();
@@ -174,14 +174,7 @@ static int altera_spi_txrx(struct spi_device *spi, struct spi_transfer *t)
 			}
 
 			hw->count++;
-
-			if (hw->count < hw->len)
-				writel(hw_txbyte(hw, hw->count),
-				       hw->base + ALTERA_SPI_TXDATA);
-			else
-				break;
 		}
-
 	}
 
 	return hw->count * hw->bytes_per_word;