* [PATCH] atcspi200: Add timeout mechanism in spi_xfer()
@ 2021-04-01 8:48 Dylan Jhong
2021-04-08 2:57 ` Leo Liang
[not found] ` <752D002CFF5D0F4FA35C0100F1D73F3FE5E9827D@ATCPCS12.andestech.com>
0 siblings, 2 replies; 3+ messages in thread
From: Dylan Jhong @ 2021-04-01 8:48 UTC (permalink / raw)
To: u-boot
Adding timeout mechanism to avoid spi driver from stucking
in the while loop in __atcspi200_spi_xfer().
Signed-off-by: Dylan Jhong <dylan@andestech.com>
---
drivers/spi/atcspi200_spi.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/spi/atcspi200_spi.c b/drivers/spi/atcspi200_spi.c
index 634cd56561..775b9ffc25 100644
--- a/drivers/spi/atcspi200_spi.c
+++ b/drivers/spi/atcspi200_spi.c
@@ -201,7 +201,7 @@ static int __atcspi200_spi_xfer(struct nds_spi_slave *ns,
size_t cmd_len = ns->cmd_len;
unsigned long data_len = bitlen / 8;
int rf_cnt;
- int ret = 0;
+ int ret = 0, timeout = 0;
max_tran_len = ns->max_transfer_length;
switch (flags) {
@@ -243,11 +243,12 @@ static int __atcspi200_spi_xfer(struct nds_spi_slave *ns,
ns->tran_len = tran_len;
num_blks = DIV_ROUND_UP(tran_len , CHUNK_SIZE);
num_bytes = (tran_len) % CHUNK_SIZE;
+ timeout = SPI_TIMEOUT;
if(num_bytes == 0)
num_bytes = CHUNK_SIZE;
__atcspi200_spi_start(ns);
- while (num_blks) {
+ while (num_blks && (timeout--)) {
event = in_le32(&ns->regs->status);
if ((event & TXEPTY) && (data_out)) {
__nspi_espi_tx(ns, dout);
@@ -269,6 +270,11 @@ static int __atcspi200_spi_xfer(struct nds_spi_slave *ns,
din = (unsigned char *)din + rx_bytes;
}
}
+
+ if (!timeout) {
+ debug("spi_xfer: %s() timeout\n", __func__);
+ break;
+ }
}
data_len -= tran_len;
--
2.17.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH] atcspi200: Add timeout mechanism in spi_xfer()
2021-04-01 8:48 [PATCH] atcspi200: Add timeout mechanism in spi_xfer() Dylan Jhong
@ 2021-04-08 2:57 ` Leo Liang
[not found] ` <752D002CFF5D0F4FA35C0100F1D73F3FE5E9827D@ATCPCS12.andestech.com>
1 sibling, 0 replies; 3+ messages in thread
From: Leo Liang @ 2021-04-08 2:57 UTC (permalink / raw)
To: u-boot
On Thu, Apr 01, 2021 at 04:48:51PM +0800, Dylan Dai-Rong Jhong(??????) wrote:
> Adding timeout mechanism to avoid spi driver from stucking
> in the while loop in __atcspi200_spi_xfer().
>
> Signed-off-by: Dylan Jhong <dylan@andestech.com>
> ---
> drivers/spi/atcspi200_spi.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/spi/atcspi200_spi.c b/drivers/spi/atcspi200_spi.c
> index 634cd56561..775b9ffc25 100644
> --- a/drivers/spi/atcspi200_spi.c
> +++ b/drivers/spi/atcspi200_spi.c
> @@ -201,7 +201,7 @@ static int __atcspi200_spi_xfer(struct nds_spi_slave *ns,
> size_t cmd_len = ns->cmd_len;
> unsigned long data_len = bitlen / 8;
> int rf_cnt;
> - int ret = 0;
> + int ret = 0, timeout = 0;
>
> max_tran_len = ns->max_transfer_length;
> switch (flags) {
> @@ -243,11 +243,12 @@ static int __atcspi200_spi_xfer(struct nds_spi_slave *ns,
> ns->tran_len = tran_len;
> num_blks = DIV_ROUND_UP(tran_len , CHUNK_SIZE);
> num_bytes = (tran_len) % CHUNK_SIZE;
> + timeout = SPI_TIMEOUT;
> if(num_bytes == 0)
> num_bytes = CHUNK_SIZE;
> __atcspi200_spi_start(ns);
>
> - while (num_blks) {
> + while (num_blks && (timeout--)) {
> event = in_le32(&ns->regs->status);
> if ((event & TXEPTY) && (data_out)) {
> __nspi_espi_tx(ns, dout);
> @@ -269,6 +270,11 @@ static int __atcspi200_spi_xfer(struct nds_spi_slave *ns,
> din = (unsigned char *)din + rx_bytes;
> }
> }
> +
> + if (!timeout) {
> + debug("spi_xfer: %s() timeout\n", __func__);
> + break;
> + }
> }
>
> data_len -= tran_len;
> --
> 2.17.0
>
Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] atcspi200: Add timeout mechanism in spi_xfer()
[not found] ` <752D002CFF5D0F4FA35C0100F1D73F3FE5E9827D@ATCPCS12.andestech.com>
@ 2021-04-23 0:47 ` Rick Chen
0 siblings, 0 replies; 3+ messages in thread
From: Rick Chen @ 2021-04-23 0:47 UTC (permalink / raw)
To: u-boot
> From: Dylan Dai-Rong Jhong(???) <dylan@andestech.com>
> Sent: Thursday, April 01, 2021 4:49 PM
> To: jagan at amarulasolutions.com; u-boot at lists.denx.de
> Cc: Rick Jian-Zhi Chen(???) <rick@andestech.com>; Ruinland Chuan-Tzu Tsa(???) <ruinland@andestech.com>; Alan Quey-Liang Kao(???) <alankao@andestech.com>; Leo Yu-Chi Liang(???) <ycliang@andestech.com>; x5710999x at gmail.com; Dylan Dai-Rong Jhong(???) <dylan@andestech.com>
> Subject: [PATCH] atcspi200: Add timeout mechanism in spi_xfer()
>
> Adding timeout mechanism to avoid spi driver from stucking in the while loop in __atcspi200_spi_xfer().
>
> Signed-off-by: Dylan Jhong <dylan@andestech.com>
> ---
> drivers/spi/atcspi200_spi.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
Reviewed-by: Rick Chen <rick@andestech.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-04-23 0:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-01 8:48 [PATCH] atcspi200: Add timeout mechanism in spi_xfer() Dylan Jhong
2021-04-08 2:57 ` Leo Liang
[not found] ` <752D002CFF5D0F4FA35C0100F1D73F3FE5E9827D@ATCPCS12.andestech.com>
2021-04-23 0:47 ` Rick Chen
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.