spi: spi-cadence: Avoid read of RX FIFO before its ready
authorCharles Keepax <ckeepax@opensource.cirrus.com>
Tue, 9 May 2023 16:41:52 +0000 (17:41 +0100)
committerMark Brown <broonie@kernel.org>
Mon, 15 May 2023 01:21:39 +0000 (10:21 +0900)
commita84c11e16dc2cc1faad2e688f8c12beeb369d80c
treea80fa39c63f9cfb44724a84a566c64e4631489e7
parent4c329f5da7cfa366bacfda1328a025dd38951317
spi: spi-cadence: Avoid read of RX FIFO before its ready

Recent changes to cdns_spi_irq introduced some issues.

Firstly, when writing the end of a longer transaction, the code in
cdns_spi_irq will write data into the TX FIFO, then immediately
fall into the if (!xspi->tx_bytes) path and attempt to read data
from the RX FIFO. However this required waiting for the TX FIFO to
empty before the RX data was ready.

Secondly, the variable trans_cnt is now rather inaccurately named
since in cases, where the watermark is set to 1, trans_cnt will be
1 but the count of bytes transferred would be much longer.

Finally, when setting up the transaction we set the watermark to 50%
of the FIFO if the transaction is great than 50% of the FIFO. However,
there is no need to split a tranaction that is smaller than the
whole FIFO, so anything up to the FIFO size can be done in a single
transaction.

Tidy up the code a little, to avoid repeatedly calling
cdns_spi_read_rx_fifo with a count of 1, and correct the three issues
noted above.

Fixes: b1b90514eaa3 ("spi: spi-cadence: Add support for Slave mode")
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com
Link: https://lore.kernel.org/r/20230509164153.3907694-1-ckeepax@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org
drivers/spi/spi-cadence.c