Skip to content

Commit 9162d29

Browse files
hramrachgregkh
authored andcommitted
spi: sun4i: fix FIFO limit
commit 6d9fe44bd73d567d04d3a68a2d2fa521ab9532f2 upstream. When testing SPI without DMA I noticed that filling the FIFO on the spi controller causes timeout. Always leave room for one byte in the FIFO. Signed-off-by: Michal Suchanek <hramrach@gmail.com> Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com> Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 873b6e3 commit 9162d29

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

drivers/spi/spi-sun4i.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ static int sun4i_spi_transfer_one(struct spi_master *master,
177177

178178
/* We don't support transfer larger than the FIFO */
179179
if (tfr->len > SUN4I_FIFO_DEPTH)
180-
return -EINVAL;
180+
return -EMSGSIZE;
181+
182+
if (tfr->tx_buf && tfr->len >= SUN4I_FIFO_DEPTH)
183+
return -EMSGSIZE;
181184

182185
reinit_completion(&sspi->done);
183186
sspi->tx_buf = tfr->tx_buf;
@@ -270,8 +273,12 @@ static int sun4i_spi_transfer_one(struct spi_master *master,
270273
sun4i_spi_write(sspi, SUN4I_BURST_CNT_REG, SUN4I_BURST_CNT(tfr->len));
271274
sun4i_spi_write(sspi, SUN4I_XMIT_CNT_REG, SUN4I_XMIT_CNT(tx_len));
272275

273-
/* Fill the TX FIFO */
274-
sun4i_spi_fill_fifo(sspi, SUN4I_FIFO_DEPTH);
276+
/*
277+
* Fill the TX FIFO
278+
* Filling the FIFO fully causes timeout for some reason
279+
* at least on spi2 on A10s
280+
*/
281+
sun4i_spi_fill_fifo(sspi, SUN4I_FIFO_DEPTH - 1);
275282

276283
/* Enable the interrupts */
277284
sun4i_spi_write(sspi, SUN4I_INT_CTL_REG, SUN4I_INT_CTL_TC);

0 commit comments

Comments
 (0)