From 55de58323e458b38b455439a8846cb663deb5508 Mon Sep 17 00:00:00 2001 From: Christophe Kerello Date: Wed, 4 May 2022 11:14:55 +0200 Subject: [PATCH 1/2] fix(st-spi): always check SR_TCF flags in stm32_qspi_wait_cmd() Currently, SR_TCF flag is checked in case there is data, this criteria is not correct. SR_TCF flags is set when programmed number of bytes have been transferred to the memory device ("bytes" comprised command and data send to the SPI device). So even if there is no data, we must check SR_TCF flag. Change-Id: I99c4145e639c1b842feb3690dd78329179c18132 Signed-off-by: Christophe Kerello --- drivers/st/spi/stm32_qspi.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/st/spi/stm32_qspi.c b/drivers/st/spi/stm32_qspi.c index d3c26d94d..28e071907 100644 --- a/drivers/st/spi/stm32_qspi.c +++ b/drivers/st/spi/stm32_qspi.c @@ -1,13 +1,10 @@ /* - * Copyright (c) 2019-2021, STMicroelectronics - All Rights Reserved + * Copyright (c) 2019-2022, STMicroelectronics - All Rights Reserved * * SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */ #include -#include - -#include #include #include @@ -19,6 +16,9 @@ #include #include #include +#include + +#include /* Timeout for device interface reset */ #define TIMEOUT_US_1_MS 1000U @@ -139,10 +139,6 @@ static int stm32_qspi_wait_cmd(const struct spi_mem_op *op) int ret = 0; uint64_t timeout; - if (op->data.nbytes == 0U) { - return stm32_qspi_wait_for_not_busy(); - } - timeout = timeout_init_us(QSPI_CMD_TIMEOUT_US); while ((mmio_read_32(qspi_base() + QSPI_SR) & QSPI_SR_TCF) == 0U) { if (timeout_elapsed(timeout)) { @@ -163,6 +159,10 @@ static int stm32_qspi_wait_cmd(const struct spi_mem_op *op) /* Clear flags */ mmio_write_32(qspi_base() + QSPI_FCR, QSPI_FCR_CTCF | QSPI_FCR_CTEF); + if (ret == 0) { + ret = stm32_qspi_wait_for_not_busy(); + } + return ret; } From 5993b9157fd049d06194083032771ffcf73da086 Mon Sep 17 00:00:00 2001 From: Christophe Kerello Date: Wed, 4 May 2022 11:28:15 +0200 Subject: [PATCH 2/2] fix(st-spi): remove SR_BUSY bit check before sending command Waiting for SR_BUSY bit when receiving a new command is not needed. SR_BUSY bit is already managed in the previous command treatment. Change-Id: I736e8488d354cb165ae765022d864cca1dbdc9ee Signed-off-by: Christophe Kerello --- drivers/st/spi/stm32_qspi.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/st/spi/stm32_qspi.c b/drivers/st/spi/stm32_qspi.c index 28e071907..73aa9ac60 100644 --- a/drivers/st/spi/stm32_qspi.c +++ b/drivers/st/spi/stm32_qspi.c @@ -251,11 +251,6 @@ static int stm32_qspi_exec_op(const struct spi_mem_op *op) op->dummy.buswidth, op->data.buswidth, op->addr.val, op->data.nbytes); - ret = stm32_qspi_wait_for_not_busy(); - if (ret != 0) { - return ret; - } - addr_max = op->addr.val + op->data.nbytes + 1U; if ((op->data.dir == SPI_MEM_DATA_IN) && (op->data.nbytes != 0U)) {