OSDN Git Service

spi: spi_qsd: Disable packing for unaliged non DMA mode transfers
authorMukesh Kumar Savaliya <msavaliy@codeaurora.org>
Fri, 31 Mar 2017 07:09:11 +0000 (12:39 +0530)
committerGerrit - the friendly Code Review server <code-review@localhost>
Thu, 6 Apr 2017 11:43:05 +0000 (04:43 -0700)
SPI core has a characterstic that it always sends data in FIFO word size
when we compress the data and fill the FIFO. This helps to improve the
overall througput but sometimes for the data transfers which is not
aligned to FIFO Word [i.e 4] it pads extra bytes and sends out which can
mislead spi slave device.

Do not enable packing if it's a FIFO mode transfer and data size is not
aligned to FIFO word size.

Change-Id: I28f4e3e38db4b882f229c00aa54aabdc72d2c139
Signed-off-by: Mukesh Kumar Savaliya <msavaliy@codeaurora.org>
drivers/spi/spi_qsd.c

index 3194ea3..8efe18d 100644 (file)
@@ -1257,11 +1257,15 @@ static void msm_spi_set_qup_io_modes(struct msm_spi *dd)
        spi_iom &= ~(SPI_IO_M_INPUT_MODE | SPI_IO_M_OUTPUT_MODE);
        spi_iom = (spi_iom | (dd->tx_mode << OUTPUT_MODE_SHIFT));
        spi_iom = (spi_iom | (dd->rx_mode << INPUT_MODE_SHIFT));
-       /* Always enable packing for all % 8 bits_per_word */
-       if (dd->cur_transfer->bits_per_word &&
-               ((dd->cur_transfer->bits_per_word == 8) ||
-               (dd->cur_transfer->bits_per_word == 16) ||
-               (dd->cur_transfer->bits_per_word == 32))) {
+
+       /* Always enable packing for the BAM mode and for non BAM mode only
+        * if bpw is % 8 and transfer length is % 4 Bytes.
+        */
+       if (dd->tx_mode == SPI_BAM_MODE ||
+               ((dd->cur_msg_len % SPI_MAX_BYTES_PER_WORD == 0) &&
+               (dd->cur_transfer->bits_per_word) &&
+               (dd->cur_transfer->bits_per_word <= 32) &&
+               (dd->cur_transfer->bits_per_word % 8 == 0))) {
                spi_iom |= SPI_IO_M_PACK_EN | SPI_IO_M_UNPACK_EN;
                dd->pack_words = true;
        } else {