mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-25 06:46:00 +00:00
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> Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com> Reviewed-by: Rick Chen <rick@andestech.com>
This commit is contained in:
parent
bc8bbb77f7
commit
1412b8d48a
1 changed files with 8 additions and 2 deletions
|
@ -201,7 +201,7 @@ static int __atcspi200_spi_xfer(struct nds_spi_slave *ns,
|
||||||
size_t cmd_len = ns->cmd_len;
|
size_t cmd_len = ns->cmd_len;
|
||||||
unsigned long data_len = bitlen / 8;
|
unsigned long data_len = bitlen / 8;
|
||||||
int rf_cnt;
|
int rf_cnt;
|
||||||
int ret = 0;
|
int ret = 0, timeout = 0;
|
||||||
|
|
||||||
max_tran_len = ns->max_transfer_length;
|
max_tran_len = ns->max_transfer_length;
|
||||||
switch (flags) {
|
switch (flags) {
|
||||||
|
@ -243,11 +243,12 @@ static int __atcspi200_spi_xfer(struct nds_spi_slave *ns,
|
||||||
ns->tran_len = tran_len;
|
ns->tran_len = tran_len;
|
||||||
num_blks = DIV_ROUND_UP(tran_len , CHUNK_SIZE);
|
num_blks = DIV_ROUND_UP(tran_len , CHUNK_SIZE);
|
||||||
num_bytes = (tran_len) % CHUNK_SIZE;
|
num_bytes = (tran_len) % CHUNK_SIZE;
|
||||||
|
timeout = SPI_TIMEOUT;
|
||||||
if(num_bytes == 0)
|
if(num_bytes == 0)
|
||||||
num_bytes = CHUNK_SIZE;
|
num_bytes = CHUNK_SIZE;
|
||||||
__atcspi200_spi_start(ns);
|
__atcspi200_spi_start(ns);
|
||||||
|
|
||||||
while (num_blks) {
|
while (num_blks && (timeout--)) {
|
||||||
event = in_le32(&ns->regs->status);
|
event = in_le32(&ns->regs->status);
|
||||||
if ((event & TXEPTY) && (data_out)) {
|
if ((event & TXEPTY) && (data_out)) {
|
||||||
__nspi_espi_tx(ns, dout);
|
__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;
|
din = (unsigned char *)din + rx_bytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!timeout) {
|
||||||
|
debug("spi_xfer: %s() timeout\n", __func__);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data_len -= tran_len;
|
data_len -= tran_len;
|
||||||
|
|
Loading…
Add table
Reference in a new issue