Commit 0312d591 authored by Geert Uytterhoeven's avatar Geert Uytterhoeven Committed by Mark Brown

spi: sh-msiof: Refactor sh_msiof_transfer_one()

  - Move buffer pointer and length setup to the top,
  - Make unsigned values unsigned,
  - Loop over words and increment pointers instead of recalculating them,
    which allows to kill bytes_done.
Signed-off-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: default avatarMark Brown <broonie@linaro.org>
parent 75b82e23
...@@ -616,16 +616,17 @@ static int sh_msiof_transfer_one(struct spi_master *master, ...@@ -616,16 +616,17 @@ static int sh_msiof_transfer_one(struct spi_master *master,
struct sh_msiof_spi_priv *p = spi_master_get_devdata(master); struct sh_msiof_spi_priv *p = spi_master_get_devdata(master);
void (*tx_fifo)(struct sh_msiof_spi_priv *, const void *, int, int); void (*tx_fifo)(struct sh_msiof_spi_priv *, const void *, int, int);
void (*rx_fifo)(struct sh_msiof_spi_priv *, void *, int, int); void (*rx_fifo)(struct sh_msiof_spi_priv *, void *, int, int);
int bits; const void *tx_buf = t->tx_buf;
int bytes_per_word; void *rx_buf = t->rx_buf;
int bytes_done; unsigned int len = t->len;
int words; unsigned int bits = t->bits_per_word;
unsigned int bytes_per_word;
unsigned int words;
int n; int n;
bool swab; bool swab;
bits = t->bits_per_word;
if (bits <= 8 && t->len > 15 && !(t->len & 3)) { if (bits <= 8 && len > 15 && !(len & 3)) {
bits = 32; bits = 32;
swab = true; swab = true;
} else { } else {
...@@ -639,34 +640,34 @@ static int sh_msiof_transfer_one(struct spi_master *master, ...@@ -639,34 +640,34 @@ static int sh_msiof_transfer_one(struct spi_master *master,
rx_fifo = sh_msiof_spi_read_fifo_8; rx_fifo = sh_msiof_spi_read_fifo_8;
} else if (bits <= 16) { } else if (bits <= 16) {
bytes_per_word = 2; bytes_per_word = 2;
if ((unsigned long)t->tx_buf & 0x01) if ((unsigned long)tx_buf & 0x01)
tx_fifo = sh_msiof_spi_write_fifo_16u; tx_fifo = sh_msiof_spi_write_fifo_16u;
else else
tx_fifo = sh_msiof_spi_write_fifo_16; tx_fifo = sh_msiof_spi_write_fifo_16;
if ((unsigned long)t->rx_buf & 0x01) if ((unsigned long)rx_buf & 0x01)
rx_fifo = sh_msiof_spi_read_fifo_16u; rx_fifo = sh_msiof_spi_read_fifo_16u;
else else
rx_fifo = sh_msiof_spi_read_fifo_16; rx_fifo = sh_msiof_spi_read_fifo_16;
} else if (swab) { } else if (swab) {
bytes_per_word = 4; bytes_per_word = 4;
if ((unsigned long)t->tx_buf & 0x03) if ((unsigned long)tx_buf & 0x03)
tx_fifo = sh_msiof_spi_write_fifo_s32u; tx_fifo = sh_msiof_spi_write_fifo_s32u;
else else
tx_fifo = sh_msiof_spi_write_fifo_s32; tx_fifo = sh_msiof_spi_write_fifo_s32;
if ((unsigned long)t->rx_buf & 0x03) if ((unsigned long)rx_buf & 0x03)
rx_fifo = sh_msiof_spi_read_fifo_s32u; rx_fifo = sh_msiof_spi_read_fifo_s32u;
else else
rx_fifo = sh_msiof_spi_read_fifo_s32; rx_fifo = sh_msiof_spi_read_fifo_s32;
} else { } else {
bytes_per_word = 4; bytes_per_word = 4;
if ((unsigned long)t->tx_buf & 0x03) if ((unsigned long)tx_buf & 0x03)
tx_fifo = sh_msiof_spi_write_fifo_32u; tx_fifo = sh_msiof_spi_write_fifo_32u;
else else
tx_fifo = sh_msiof_spi_write_fifo_32; tx_fifo = sh_msiof_spi_write_fifo_32;
if ((unsigned long)t->rx_buf & 0x03) if ((unsigned long)rx_buf & 0x03)
rx_fifo = sh_msiof_spi_read_fifo_32u; rx_fifo = sh_msiof_spi_read_fifo_32u;
else else
rx_fifo = sh_msiof_spi_read_fifo_32; rx_fifo = sh_msiof_spi_read_fifo_32;
...@@ -676,20 +677,18 @@ static int sh_msiof_transfer_one(struct spi_master *master, ...@@ -676,20 +677,18 @@ static int sh_msiof_transfer_one(struct spi_master *master,
sh_msiof_spi_set_clk_regs(p, clk_get_rate(p->clk), t->speed_hz); sh_msiof_spi_set_clk_regs(p, clk_get_rate(p->clk), t->speed_hz);
/* transfer in fifo sized chunks */ /* transfer in fifo sized chunks */
words = t->len / bytes_per_word; words = len / bytes_per_word;
bytes_done = 0;
while (words > 0) {
while (bytes_done < t->len) { n = sh_msiof_spi_txrx_once(p, tx_fifo, rx_fifo, tx_buf, rx_buf,
void *rx_buf = t->rx_buf ? t->rx_buf + bytes_done : NULL;
const void *tx_buf = t->tx_buf ? t->tx_buf + bytes_done : NULL;
n = sh_msiof_spi_txrx_once(p, tx_fifo, rx_fifo,
tx_buf,
rx_buf,
words, bits); words, bits);
if (n < 0) if (n < 0)
return n; return n;
bytes_done += n * bytes_per_word; if (tx_buf)
tx_buf += n * bytes_per_word;
if (rx_buf)
rx_buf += n * bytes_per_word;
words -= n; words -= n;
} }
......
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