summaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi-sun4i.c
diff options
context:
space:
mode:
authorMichal Suchanek <hramrach@gmail.com>2016-06-13 17:46:49 +0000
committerMark Brown <broonie@kernel.org>2016-06-14 10:05:18 +0100
commit719bd6542044efd9b338a53dba1bef45f40ca169 (patch)
tree837acfe993c8949db1570b977c6dd5d2a3cb37fb /drivers/spi/spi-sun4i.c
parent6d9fe44bd73d567d04d3a68a2d2fa521ab9532f2 (diff)
downloadlinux-719bd6542044efd9b338a53dba1bef45f40ca169.tar.gz
linux-719bd6542044efd9b338a53dba1bef45f40ca169.tar.bz2
linux-719bd6542044efd9b338a53dba1bef45f40ca169.zip
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> Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com> Signed-off-by: Mark Brown <broonie@kernel.org> Cc: stable@vger.kernel.org
Diffstat (limited to 'drivers/spi/spi-sun4i.c')
-rw-r--r--drivers/spi/spi-sun4i.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/drivers/spi/spi-sun4i.c b/drivers/spi/spi-sun4i.c
index e7e4aecb3295..cf007f3b83ec 100644
--- a/drivers/spi/spi-sun4i.c
+++ b/drivers/spi/spi-sun4i.c
@@ -173,6 +173,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;
@@ -286,9 +287,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(tfr->len * 8 * 2 / (tfr->speed_hz / 1000), 100U);
+ 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, tfr->speed_hz,
+ jiffies_to_msecs(end - start), tx_time);
ret = -ETIMEDOUT;
goto out;
}