From cbea40b0e1cd9cf79ed24d3f4e1a78305cbc2237 Mon Sep 17 00:00:00 2001 From: Mukesh Kumar Savaliya Date: Fri, 31 Mar 2017 12:39:11 +0530 Subject: [PATCH] spi: spi_qsd: Disable packing for unaliged non DMA mode transfers 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 --- drivers/spi/spi_qsd.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi_qsd.c b/drivers/spi/spi_qsd.c index 3194ea365952..8efe18dcc98f 100644 --- a/drivers/spi/spi_qsd.c +++ b/drivers/spi/spi_qsd.c @@ -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 { -- 2.11.0