spi: cadence: Detect transmit FIFO depth
authorLars-Peter Clausen <lars@metafoo.de>
Fri, 27 May 2022 09:11:43 +0000 (11:11 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 6 Jun 2022 11:32:25 +0000 (12:32 +0100)
commit7b40322f7183a92c4303457528ae7cda571c60b9
tree3f2a3153917625270b5a589f7a13d98863d77dd4
parent21b511ddee09a78909035ec47a6a594349fe3296
spi: cadence: Detect transmit FIFO depth

The depth of the transmit FIFO for the Cadence SPI controller is currently
hardcoded to 128. But the depth is a synthesis configuration parameter of
the core and can vary between different SoCs.

If the configured FIFO size is less than 128 the driver will busy loop in
the cdns_spi_fill_tx_fifo() function waiting for FIFO space to become
available.

Depending on the length and speed of the transfer it can spin for a
significant amount of time. The cdns_spi_fill_tx_fifo() function is called
from the drivers interrupt handler, so it can leave interrupts disabled for
a prolonged amount of time.

In addition the read FIFO will also overflow and data will be discarded.

To avoid this detect the actual size of the FIFO and use that rather than
the hardcoded value.

To detect the FIFO size the FIFO threshold register is used. The register
is sized so that it can hold FIFO size - 1 as its maximum value. Bits that
are not needed to hold the threshold value will always read 0. By writing
0xffff to the register and then reading back the value in the register we
get the FIFO size.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Link: https://lore.kernel.org/r/20220527091143.3780378-1-lars@metafoo.de
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-cadence.c