aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Brown <broonie@linaro.org>2014-01-30 17:16:41 -0500
committerMark Brown <broonie@linaro.org>2014-02-03 08:04:45 -0500
commit16a0ce4e10edfe376b3071f161c71c4160c89d6b (patch)
tree081e182b8820c09f279a8bb0002e1d9b1aa627fb
parent38dbfb59d1175ef458d006556061adeaa8751b72 (diff)
spi: Add a timeout when waiting for transfers
Don't wait indefinitely for transfers to complete but time out after 10ms more than we expect the transfer to take on the wire. Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r--drivers/spi/spi.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 23756b0f9036..516643d243c6 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -594,6 +594,7 @@ static int spi_transfer_one_message(struct spi_master *master,
594 bool cur_cs = true; 594 bool cur_cs = true;
595 bool keep_cs = false; 595 bool keep_cs = false;
596 int ret = 0; 596 int ret = 0;
597 int ms = 1;
597 598
598 spi_set_cs(msg->spi, true); 599 spi_set_cs(msg->spi, true);
599 600
@@ -611,7 +612,16 @@ static int spi_transfer_one_message(struct spi_master *master,
611 612
612 if (ret > 0) { 613 if (ret > 0) {
613 ret = 0; 614 ret = 0;
614 wait_for_completion(&master->xfer_completion); 615 ms = xfer->len * 8 * 1000 / xfer->speed_hz;
616 ms += 10; /* some tolerance */
617
618 ms = wait_for_completion_timeout(&master->xfer_completion,
619 msecs_to_jiffies(ms));
620 }
621
622 if (ms == 0) {
623 dev_err(&msg->spi->dev, "SPI transfer timed out\n");
624 msg->status = -ETIMEDOUT;
615 } 625 }
616 626
617 trace_spi_transfer_stop(msg, xfer); 627 trace_spi_transfer_stop(msg, xfer);