spi: sprd: Fix the error data length in SPI read-only mode
authorLanqing Liu <lanqing.liu@spreadtrum.com>
Tue, 15 Jan 2019 13:46:50 +0000 (21:46 +0800)
committerMark Brown <broonie@kernel.org>
Tue, 15 Jan 2019 14:16:35 +0000 (14:16 +0000)
In SPI read-only mode, we will always return the writing length,
which is always the power of "bits_per_word", but the length unit
using by users is byte.

Thus this patch fixes the returning length by getting from
read_bufs() function to get the correct length.

Signed-off-by: Lanqing Liu <lanqing.liu@spreadtrum.com>
Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-sprd.c

index 8daa24eec6242ee38a66e6ee9b8476dccdf8b8c4..fa324ce194b297b019f756e611b1d9b60b6bbf65 100644 (file)
@@ -380,7 +380,7 @@ static int sprd_spi_txrx_bufs(struct spi_device *sdev, struct spi_transfer *t)
 {
        struct sprd_spi *ss = spi_controller_get_devdata(sdev->controller);
        u32 trans_len = ss->trans_len, len;
-       int ret, write_size = 0;
+       int ret, write_size = 0, read_size = 0;
 
        while (trans_len) {
                len = trans_len > SPRD_SPI_FIFO_SIZE ? SPRD_SPI_FIFO_SIZE :
@@ -416,13 +416,15 @@ static int sprd_spi_txrx_bufs(struct spi_device *sdev, struct spi_transfer *t)
                        goto complete;
 
                if (ss->trans_mode & SPRD_SPI_RX_MODE)
-                       ss->read_bufs(ss, len);
+                       read_size += ss->read_bufs(ss, len);
 
                trans_len -= len;
        }
 
-       ret = write_size;
-
+       if (ss->trans_mode & SPRD_SPI_TX_MODE)
+               ret = write_size;
+       else
+               ret = read_size;
 complete:
        sprd_spi_enter_idle(ss);