aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi
diff options
context:
space:
mode:
authorRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>2015-01-23 11:08:35 -0500
committerMark Brown <broonie@kernel.org>2015-01-27 12:25:34 -0500
commitc5d348dffa7ca1f072ff5526171a2b88bbffc24b (patch)
tree883632810a8ce926534cc3e6e403f1ef3fcec5c9 /drivers/spi
parent0240f94516964db00d0fc1d1e676f3c273710e17 (diff)
spi/xilinx: Simplify data read from the Rx FIFO
The number of words in the read buffer will be exactly the same as the number of words written on write buffer, once the transaction has finished. Instead of cheking the rx_empty flags for every word simply save the number of words written by fill_tx_fifo. Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/spi')
-rw-r--r--drivers/spi/spi-xilinx.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/drivers/spi/spi-xilinx.c b/drivers/spi/spi-xilinx.c
index e1d9a2003ae6..416b227eb302 100644
--- a/drivers/spi/spi-xilinx.c
+++ b/drivers/spi/spi-xilinx.c
@@ -221,9 +221,10 @@ static int xilinx_spi_setup_transfer(struct spi_device *spi,
221 return 0; 221 return 0;
222} 222}
223 223
224static void xilinx_spi_fill_tx_fifo(struct xilinx_spi *xspi) 224static int xilinx_spi_fill_tx_fifo(struct xilinx_spi *xspi)
225{ 225{
226 u8 sr; 226 u8 sr;
227 int n_words = 0;
227 228
228 /* Fill the Tx FIFO with as many bytes as possible */ 229 /* Fill the Tx FIFO with as many bytes as possible */
229 sr = xspi->read_fn(xspi->regs + XSPI_SR_OFFSET); 230 sr = xspi->read_fn(xspi->regs + XSPI_SR_OFFSET);
@@ -234,7 +235,10 @@ static void xilinx_spi_fill_tx_fifo(struct xilinx_spi *xspi)
234 xspi->write_fn(0, xspi->regs + XSPI_TXD_OFFSET); 235 xspi->write_fn(0, xspi->regs + XSPI_TXD_OFFSET);
235 xspi->remaining_bytes -= xspi->bits_per_word / 8; 236 xspi->remaining_bytes -= xspi->bits_per_word / 8;
236 sr = xspi->read_fn(xspi->regs + XSPI_SR_OFFSET); 237 sr = xspi->read_fn(xspi->regs + XSPI_SR_OFFSET);
238 n_words++;
237 } 239 }
240
241 return n_words;
238} 242}
239 243
240static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t) 244static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t)
@@ -259,9 +263,9 @@ static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t)
259 263
260 for (;;) { 264 for (;;) {
261 u16 cr; 265 u16 cr;
262 u8 sr; 266 int n_words;
263 267
264 xilinx_spi_fill_tx_fifo(xspi); 268 n_words = xilinx_spi_fill_tx_fifo(xspi);
265 269
266 /* Start the transfer by not inhibiting the transmitter any 270 /* Start the transfer by not inhibiting the transmitter any
267 * longer 271 * longer
@@ -282,11 +286,8 @@ static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t)
282 xspi->regs + XSPI_CR_OFFSET); 286 xspi->regs + XSPI_CR_OFFSET);
283 287
284 /* Read out all the data from the Rx FIFO */ 288 /* Read out all the data from the Rx FIFO */
285 sr = xspi->read_fn(xspi->regs + XSPI_SR_OFFSET); 289 while (n_words--)
286 while ((sr & XSPI_SR_RX_EMPTY_MASK) == 0) {
287 xspi->rx_fn(xspi); 290 xspi->rx_fn(xspi);
288 sr = xspi->read_fn(xspi->regs + XSPI_SR_OFFSET);
289 }
290 291
291 /* See if there is more data to send */ 292 /* See if there is more data to send */
292 if (xspi->remaining_bytes <= 0) 293 if (xspi->remaining_bytes <= 0)