Commit 53fadb4d authored by Vladimir Oltean's avatar Vladimir Oltean Committed by Mark Brown

spi: spi-fsl-dspi: Simplify bytes_per_word gymnastics

Reduce the if-then-else-if-then-else sequence to:
 - a simple division in the case of bytes_per_word calculation
 - a memcpy command with a variable size. The semantics of larger-than-8
   xfer->bits_per_word is that those words are to be interpreted and
   transmitted in CPU native endianness.
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Link: https://lore.kernel.org/r/20200304220044.11193-2-olteanv@gmail.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent cb71d8ef
...@@ -252,12 +252,7 @@ static u32 dspi_pop_tx(struct fsl_dspi *dspi) ...@@ -252,12 +252,7 @@ static u32 dspi_pop_tx(struct fsl_dspi *dspi)
u32 txdata = 0; u32 txdata = 0;
if (dspi->tx) { if (dspi->tx) {
if (dspi->bytes_per_word == 1) memcpy(&txdata, dspi->tx, dspi->bytes_per_word);
txdata = *(u8 *)dspi->tx;
else if (dspi->bytes_per_word == 2)
txdata = *(u16 *)dspi->tx;
else /* dspi->bytes_per_word == 4 */
txdata = *(u32 *)dspi->tx;
dspi->tx += dspi->bytes_per_word; dspi->tx += dspi->bytes_per_word;
} }
dspi->len -= dspi->bytes_per_word; dspi->len -= dspi->bytes_per_word;
...@@ -284,12 +279,7 @@ static void dspi_push_rx(struct fsl_dspi *dspi, u32 rxdata) ...@@ -284,12 +279,7 @@ static void dspi_push_rx(struct fsl_dspi *dspi, u32 rxdata)
/* Mask off undefined bits */ /* Mask off undefined bits */
rxdata &= (1 << dspi->bits_per_word) - 1; rxdata &= (1 << dspi->bits_per_word) - 1;
if (dspi->bytes_per_word == 1) memcpy(dspi->rx, &rxdata, dspi->bytes_per_word);
*(u8 *)dspi->rx = rxdata;
else if (dspi->bytes_per_word == 2)
*(u16 *)dspi->rx = rxdata;
else /* dspi->bytes_per_word == 4 */
*(u32 *)dspi->rx = rxdata;
dspi->rx += dspi->bytes_per_word; dspi->rx += dspi->bytes_per_word;
} }
...@@ -814,12 +804,7 @@ static int dspi_transfer_one_message(struct spi_controller *ctlr, ...@@ -814,12 +804,7 @@ static int dspi_transfer_one_message(struct spi_controller *ctlr,
dspi->progress = 0; dspi->progress = 0;
/* Validated transfer specific frame size (defaults applied) */ /* Validated transfer specific frame size (defaults applied) */
dspi->bits_per_word = transfer->bits_per_word; dspi->bits_per_word = transfer->bits_per_word;
if (transfer->bits_per_word <= 8) dspi->bytes_per_word = DIV_ROUND_UP(dspi->bits_per_word, 8);
dspi->bytes_per_word = 1;
else if (transfer->bits_per_word <= 16)
dspi->bytes_per_word = 2;
else
dspi->bytes_per_word = 4;
regmap_update_bits(dspi->regmap, SPI_MCR, regmap_update_bits(dspi->regmap, SPI_MCR,
SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF, SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF,
......
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