Skip to content

Commit 5d61841

Browse files
Sean Andersonbroonie
authored andcommitted
spi: zynqmp-gqspi: Scale timeout by data size
Large blocks of data time out when reading because we don't wait long enough for the transfer to complete. Scale our timeouts based on the amount of data we are tranferring, with a healthy dose of pessimism. Signed-off-by: Sean Anderson <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 7c626ce commit 5d61841

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

drivers/spi/spi-zynqmp-gqspi.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,18 @@ static int __maybe_unused zynqmp_runtime_resume(struct device *dev)
10331033
return 0;
10341034
}
10351035

1036+
static unsigned long zynqmp_qspi_timeout(struct zynqmp_qspi *xqspi, u8 bits,
1037+
unsigned long bytes)
1038+
{
1039+
unsigned long timeout;
1040+
1041+
/* Assume we are at most 2x slower than the nominal bus speed */
1042+
timeout = mult_frac(bytes, 2 * 8 * MSEC_PER_SEC,
1043+
bits * xqspi->speed_hz);
1044+
/* And add 100 ms for scheduling delays */
1045+
return msecs_to_jiffies(timeout + 100);
1046+
}
1047+
10361048
/**
10371049
* zynqmp_qspi_exec_op() - Initiates the QSPI transfer
10381050
* @mem: The SPI memory
@@ -1049,6 +1061,7 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
10491061
{
10501062
struct zynqmp_qspi *xqspi = spi_controller_get_devdata
10511063
(mem->spi->controller);
1064+
unsigned long timeout;
10521065
int err = 0, i;
10531066
u32 genfifoentry = 0;
10541067
u16 opcode = op->cmd.opcode;
@@ -1077,8 +1090,10 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
10771090
zynqmp_gqspi_write(xqspi, GQSPI_IER_OFST,
10781091
GQSPI_IER_GENFIFOEMPTY_MASK |
10791092
GQSPI_IER_TXNOT_FULL_MASK);
1080-
if (!wait_for_completion_timeout
1081-
(&xqspi->data_completion, msecs_to_jiffies(1000))) {
1093+
timeout = zynqmp_qspi_timeout(xqspi, op->cmd.buswidth,
1094+
op->cmd.nbytes);
1095+
if (!wait_for_completion_timeout(&xqspi->data_completion,
1096+
timeout)) {
10821097
err = -ETIMEDOUT;
10831098
goto return_err;
10841099
}
@@ -1104,8 +1119,10 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
11041119
GQSPI_IER_TXEMPTY_MASK |
11051120
GQSPI_IER_GENFIFOEMPTY_MASK |
11061121
GQSPI_IER_TXNOT_FULL_MASK);
1107-
if (!wait_for_completion_timeout
1108-
(&xqspi->data_completion, msecs_to_jiffies(1000))) {
1122+
timeout = zynqmp_qspi_timeout(xqspi, op->addr.buswidth,
1123+
op->addr.nbytes);
1124+
if (!wait_for_completion_timeout(&xqspi->data_completion,
1125+
timeout)) {
11091126
err = -ETIMEDOUT;
11101127
goto return_err;
11111128
}
@@ -1173,8 +1190,9 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
11731190
GQSPI_IER_RXEMPTY_MASK);
11741191
}
11751192
}
1176-
if (!wait_for_completion_timeout
1177-
(&xqspi->data_completion, msecs_to_jiffies(1000)))
1193+
timeout = zynqmp_qspi_timeout(xqspi, op->data.buswidth,
1194+
op->data.nbytes);
1195+
if (!wait_for_completion_timeout(&xqspi->data_completion, timeout))
11781196
err = -ETIMEDOUT;
11791197
}
11801198

0 commit comments

Comments
 (0)