linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Applied "spi: sunxi: fix transfer timeout" to the spi tree
@ 2015-08-20 21:06 Mark Brown
  2015-08-20 23:20 ` Mark Brown
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Brown @ 2015-08-20 21:06 UTC (permalink / raw)
  To: Michal Suchanek, Mark Brown, stable; +Cc: linux-spi

The patch

   spi: sunxi: fix transfer timeout

has been applied to the spi tree at

   git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git 

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

>From 63d53d153b62a1d0fb6e95a8936e43ba09ff7beb Mon Sep 17 00:00:00 2001
From: Michal Suchanek <hramrach@gmail.com>
Date: Thu, 20 Aug 2015 14:19:45 +0000
Subject: [PATCH] spi: sunxi: fix transfer timeout

The trasfer timeout is fixed at 1000 ms. Reading a 4Mbyte flash over
1MHz SPI bus takes way longer than that. Calculate the timeout from the
actual time the transfer is supposed to take and multiply by 2 for good
measure.

Signed-off-by: Michal Suchanek <hramrach@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Cc: stable@vger.kernel.org
---
 drivers/spi/spi-sun4i.c | 10 +++++++++-
 drivers/spi/spi-sun6i.c | 10 +++++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-sun4i.c b/drivers/spi/spi-sun4i.c
index fbb0a4d..48532ec 100644
--- a/drivers/spi/spi-sun4i.c
+++ b/drivers/spi/spi-sun4i.c
@@ -170,6 +170,7 @@ static int sun4i_spi_transfer_one(struct spi_master *master,
 {
 	struct sun4i_spi *sspi = spi_master_get_devdata(master);
 	unsigned int mclk_rate, div, timeout;
+	unsigned int start, end, tx_time;
 	unsigned int tx_len = 0;
 	int ret = 0;
 	u32 reg;
@@ -279,9 +280,16 @@ static int sun4i_spi_transfer_one(struct spi_master *master,
 	reg = sun4i_spi_read(sspi, SUN4I_CTL_REG);
 	sun4i_spi_write(sspi, SUN4I_CTL_REG, reg | SUN4I_CTL_XCH);
 
+	tx_time = max_t(int, tfr->len * 8 * 2 / (speed / 1000), 100);
+	start = jiffies;
 	timeout = wait_for_completion_timeout(&sspi->done,
-					      msecs_to_jiffies(1000));
+					      msecs_to_jiffies(tx_time));
+	end = jiffies;
 	if (!timeout) {
+		dev_warn(&master->dev,
+			 "%s: timeout transferring %u bytes@%iHz for %i(%i)ms",
+			 dev_name(&spi->dev), tfr->len, speed,
+			 jiffies_to_msecs(end - start), tx_time);
 		ret = -ETIMEDOUT;
 		goto out;
 	}
diff --git a/drivers/spi/spi-sun6i.c b/drivers/spi/spi-sun6i.c
index ac48f59..3d0f66c 100644
--- a/drivers/spi/spi-sun6i.c
+++ b/drivers/spi/spi-sun6i.c
@@ -162,6 +162,7 @@ static int sun6i_spi_transfer_one(struct spi_master *master,
 	unsigned int mclk_rate, div, timeout;
 	unsigned int tx_len = 0;
 	int ret = 0;
+	unsigned int start, end, tx_time;
 	u32 reg;
 
 	/* We don't support transfer larger than the FIFO */
@@ -269,9 +270,16 @@ static int sun6i_spi_transfer_one(struct spi_master *master,
 	reg = sun6i_spi_read(sspi, SUN6I_TFR_CTL_REG);
 	sun6i_spi_write(sspi, SUN6I_TFR_CTL_REG, reg | SUN6I_TFR_CTL_XCH);
 
+	tx_time = max_t(int, tfr->len * 8 * 2 / (speed / 1000), 100);
+	start = jiffies;
 	timeout = wait_for_completion_timeout(&sspi->done,
-					      msecs_to_jiffies(1000));
+					      msecs_to_jiffies(tx_time));
+	end = jiffies;
 	if (!timeout) {
+		dev_warn(&master->dev,
+			 "%s: timeout transferring %u bytes@%iHz for %i(%i)ms",
+			 dev_name(&spi->dev), tfr->len, speed,
+			 jiffies_to_msecs(end - start), tx_time);
 		ret = -ETIMEDOUT;
 		goto out;
 	}
-- 
2.5.0

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

* Re: Applied "spi: sunxi: fix transfer timeout" to the spi tree
  2015-08-20 21:06 Applied "spi: sunxi: fix transfer timeout" to the spi tree Mark Brown
@ 2015-08-20 23:20 ` Mark Brown
       [not found]   ` <20150820232023.GY12027-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Brown @ 2015-08-20 23:20 UTC (permalink / raw)
  To: Michal Suchanek, stable-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 278 bytes --]

On Thu, Aug 20, 2015 at 02:06:51PM -0700, Mark Brown wrote:
> The patch
> 
>    spi: sunxi: fix transfer timeout
> 
> has been applied to the spi tree at
> 
>    git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git 

...and reverted since it broke the build.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

* Re: Applied "spi: sunxi: fix transfer timeout" to the spi tree
       [not found]   ` <20150820232023.GY12027-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
@ 2015-08-21  8:07     ` Michal Suchanek
  0 siblings, 0 replies; 3+ messages in thread
From: Michal Suchanek @ 2015-08-21  8:07 UTC (permalink / raw)
  To: Mark Brown; +Cc: stable-u79uwXL29TY76Z2rM5mHXA, linux-spi

On 21 August 2015 at 01:20, Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> wrote:
> On Thu, Aug 20, 2015 at 02:06:51PM -0700, Mark Brown wrote:
>> The patch
>>
>>    spi: sunxi: fix transfer timeout
>>
>> has been applied to the spi tree at
>>
>>    git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git
>
> ...and reverted since it broke the build.

It depends on the patch spi: sunxi: check that transfer speed is non-zero

Got the patch order wrong, sorry.

Thanks

Michal
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2015-08-21  8:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-20 21:06 Applied "spi: sunxi: fix transfer timeout" to the spi tree Mark Brown
2015-08-20 23:20 ` Mark Brown
     [not found]   ` <20150820232023.GY12027-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-08-21  8:07     ` Michal Suchanek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).