]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
spi: imx: Use correct number of bytes per words
authorMaxime Chevallier <maxime.chevallier@bootlin.com>
Tue, 17 Jul 2018 14:31:52 +0000 (16:31 +0200)
committerMark Brown <broonie@kernel.org>
Tue, 24 Jul 2018 14:58:28 +0000 (15:58 +0100)
The SPI core enforces that we always use the next power-of-two number of
bytes to store words. As a result, a 24 bits word will be stored in 4
bytes.

This commit fixes the spi_imx_bytes_per_word function to return the
correct number of bytes.

This also allows to get rid of unnecessary checks in the can_dma
function, since the SPI core validates that we always have a transfer
length that is a multiple of the number of bytes per word.

Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-imx.c

index ecafbda5ec9483af63ea506163a4f155963e6422..3ae706dac6603d8a0ae35eeb014cd83d860e053d 100644 (file)
@@ -202,7 +202,12 @@ static unsigned int spi_imx_clkdiv_2(unsigned int fin,
 
 static int spi_imx_bytes_per_word(const int bits_per_word)
 {
-       return DIV_ROUND_UP(bits_per_word, BITS_PER_BYTE);
+       if (bits_per_word <= 8)
+               return 1;
+       else if (bits_per_word <= 16)
+               return 2;
+       else
+               return 4;
 }
 
 static bool spi_imx_can_dma(struct spi_master *master, struct spi_device *spi,
@@ -219,9 +224,6 @@ static bool spi_imx_can_dma(struct spi_master *master, struct spi_device *spi,
 
        bytes_per_word = spi_imx_bytes_per_word(transfer->bits_per_word);
 
-       if (bytes_per_word != 1 && bytes_per_word != 2 && bytes_per_word != 4)
-               return false;
-
        for (i = spi_imx->devtype_data->fifo_size / 2; i > 0; i--) {
                if (!(transfer->len % (i * bytes_per_word)))
                        break;