mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] spi: davinci: Adapt transfer's timeout to transfer's length
@ 2024-08-28  6:31 Bastien Curutchet
  2024-08-28 16:30 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Bastien Curutchet @ 2024-08-28  6:31 UTC (permalink / raw)
  To: Mark Brown
  Cc: linux-spi, linux-kernel, Thomas Petazzoni, Herve Codina,
	Christopher Cordahi, Bastien Curutchet

The timeout used when waiting for transfer's completion is always set to
HZ. This isn't enough if a transfer is too large or if the bus speed is
too low.

Use the bus speed and the transfer length to calculate an appropriate
timeout

Signed-off-by: Bastien Curutchet <bastien.curutchet@bootlin.com>
---
 drivers/spi/spi-davinci.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-davinci.c b/drivers/spi/spi-davinci.c
index f7e8b5efa50e..ad26c8409733 100644
--- a/drivers/spi/spi-davinci.c
+++ b/drivers/spi/spi-davinci.c
@@ -570,6 +570,7 @@ static int davinci_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
 	u32 errors = 0;
 	struct davinci_spi_config *spicfg;
 	struct davinci_spi_platform_data *pdata;
+	unsigned long timeout;
 
 	dspi = spi_controller_get_devdata(spi->controller);
 	pdata = &dspi->pdata;
@@ -661,7 +662,12 @@ static int davinci_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
 
 	/* Wait for the transfer to complete */
 	if (spicfg->io_type != SPI_IO_TYPE_POLL) {
-		if (wait_for_completion_timeout(&dspi->done, HZ) == 0)
+		timeout = DIV_ROUND_UP(t->speed_hz, MSEC_PER_SEC);
+		timeout = DIV_ROUND_UP(t->len * 8, timeout);
+		/* Assume we are at most 2x slower than the nominal bus speed */
+		timeout = 2 * msecs_to_jiffies(timeout);
+
+		if (wait_for_completion_timeout(&dspi->done, timeout) == 0)
 			errors = SPIFLG_TIMEOUT_MASK;
 	} else {
 		while (dspi->rcount > 0 || dspi->wcount > 0) {
-- 
2.45.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] spi: davinci: Adapt transfer's timeout to transfer's length
  2024-08-28  6:31 [PATCH] spi: davinci: Adapt transfer's timeout to transfer's length Bastien Curutchet
@ 2024-08-28 16:30 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2024-08-28 16:30 UTC (permalink / raw)
  To: Bastien Curutchet
  Cc: linux-spi, linux-kernel, Thomas Petazzoni, Herve Codina,
	Christopher Cordahi

On Wed, 28 Aug 2024 08:31:31 +0200, Bastien Curutchet wrote:
> The timeout used when waiting for transfer's completion is always set to
> HZ. This isn't enough if a transfer is too large or if the bus speed is
> too low.
> 
> Use the bus speed and the transfer length to calculate an appropriate
> timeout
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/1] spi: davinci: Adapt transfer's timeout to transfer's length
      commit: 2fe6102bf01a5f4f48f211c2e5c8a274342fccb1

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-08-28 16:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-28  6:31 [PATCH] spi: davinci: Adapt transfer's timeout to transfer's length Bastien Curutchet
2024-08-28 16:30 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®