Commit d79b2d07 authored by Ricardo Ribalda Delgado's avatar Ricardo Ribalda Delgado Committed by Mark Brown

spi/xilinx: Convert remainding_bytes in remaining words

Simplify the code by using the unit used on most of the code logic.
Signed-off-by: default avatarRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent c3092941
...@@ -86,7 +86,7 @@ struct xilinx_spi { ...@@ -86,7 +86,7 @@ struct xilinx_spi {
u8 *rx_ptr; /* pointer in the Tx buffer */ u8 *rx_ptr; /* pointer in the Tx buffer */
const u8 *tx_ptr; /* pointer in the Rx buffer */ const u8 *tx_ptr; /* pointer in the Rx buffer */
int remaining_bytes; /* the number of bytes left to transfer */ int remaining_words; /* the number of words left to transfer */
u8 bits_per_word; u8 bits_per_word;
int buffer_size; /* buffer size in words */ int buffer_size; /* buffer size in words */
u32 cs_inactive; /* Level of the CS pins when inactive*/ u32 cs_inactive; /* Level of the CS pins when inactive*/
...@@ -231,7 +231,7 @@ static int xilinx_spi_setup_transfer(struct spi_device *spi, ...@@ -231,7 +231,7 @@ static int xilinx_spi_setup_transfer(struct spi_device *spi,
static void xilinx_spi_fill_tx_fifo(struct xilinx_spi *xspi, int n_words) static void xilinx_spi_fill_tx_fifo(struct xilinx_spi *xspi, int n_words)
{ {
xspi->remaining_bytes -= n_words * xspi->bits_per_word / 8; xspi->remaining_words -= n_words;
while (n_words--) while (n_words--)
xilinx_spi_tx(xspi); xilinx_spi_tx(xspi);
...@@ -246,15 +246,14 @@ static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t) ...@@ -246,15 +246,14 @@ static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t)
xspi->tx_ptr = t->tx_buf; xspi->tx_ptr = t->tx_buf;
xspi->rx_ptr = t->rx_buf; xspi->rx_ptr = t->rx_buf;
xspi->remaining_bytes = t->len; xspi->remaining_words = (t->len * 8) / xspi->bits_per_word;
reinit_completion(&xspi->done); reinit_completion(&xspi->done);
while (xspi->remaining_bytes) { while (xspi->remaining_words) {
u16 cr = 0; u16 cr = 0;
int n_words; int n_words;
n_words = (xspi->remaining_bytes * 8) / xspi->bits_per_word; n_words = min(xspi->remaining_words, xspi->buffer_size);
n_words = min(n_words, xspi->buffer_size);
xilinx_spi_fill_tx_fifo(xspi, n_words); xilinx_spi_fill_tx_fifo(xspi, n_words);
...@@ -286,7 +285,7 @@ static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t) ...@@ -286,7 +285,7 @@ static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t)
xilinx_spi_rx(xspi); xilinx_spi_rx(xspi);
} }
return t->len - xspi->remaining_bytes; return t->len;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment