diff mbox series

[4/4] spi: amd: Check for idle bus before execute opcode

Message ID 20210909111005.304101-4-tanureal@opensource.cirrus.com
State New
Headers show
Series None | expand

Commit Message

Lucas tanure Sept. 9, 2021, 11:10 a.m. UTC
Check if the bus is not in use before starting the
transfer

Signed-off-by: Lucas Tanure <tanureal@opensource.cirrus.com>
---
 drivers/spi/spi-amd.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Charles Keepax Sept. 10, 2021, 8:57 a.m. UTC | #1
On Thu, Sep 09, 2021 at 12:10:05PM +0100, Lucas Tanure wrote:
> Check if the bus is not in use before starting the

> transfer

> 

> Signed-off-by: Lucas Tanure <tanureal@opensource.cirrus.com>

> ---

>  drivers/spi/spi-amd.c | 11 +++++++++--

>  1 file changed, 9 insertions(+), 2 deletions(-)

> 

> diff --git a/drivers/spi/spi-amd.c b/drivers/spi/spi-amd.c

> index 97838b57871c..99b2b0ccff08 100644

> --- a/drivers/spi/spi-amd.c

> +++ b/drivers/spi/spi-amd.c

> @@ -115,11 +115,18 @@ static int amd_spi_busy_wait(struct amd_spi *amd_spi)

>  	return 0;

>  }

>  

> -static void amd_spi_execute_opcode(struct amd_spi *amd_spi)

> +static int amd_spi_execute_opcode(struct amd_spi *amd_spi)

>  {

> +	int ret;

> +

> +	ret = amd_spi_busy_wait(amd_spi);

> +	if (ret)

> +		return ret;

> +

>  	/* Set ExecuteOpCode bit in the CTRL0 register */

>  	amd_spi_setclear_reg32(amd_spi, AMD_SPI_CTRL0_REG, AMD_SPI_EXEC_CMD, AMD_SPI_EXEC_CMD);

> -	amd_spi_busy_wait(amd_spi);

> +

> +	return 0;

>  }


This feels like the commit message could use come additional
explanation. The message states we are moving the wait, but not
why? Also the original code looks slightly more logical, as
in amd_spi_fifo_xfer we read the receive buffer immediately after
calling this function.

Thanks,
Charles
diff mbox series

Patch

diff --git a/drivers/spi/spi-amd.c b/drivers/spi/spi-amd.c
index 97838b57871c..99b2b0ccff08 100644
--- a/drivers/spi/spi-amd.c
+++ b/drivers/spi/spi-amd.c
@@ -115,11 +115,18 @@  static int amd_spi_busy_wait(struct amd_spi *amd_spi)
 	return 0;
 }
 
-static void amd_spi_execute_opcode(struct amd_spi *amd_spi)
+static int amd_spi_execute_opcode(struct amd_spi *amd_spi)
 {
+	int ret;
+
+	ret = amd_spi_busy_wait(amd_spi);
+	if (ret)
+		return ret;
+
 	/* Set ExecuteOpCode bit in the CTRL0 register */
 	amd_spi_setclear_reg32(amd_spi, AMD_SPI_CTRL0_REG, AMD_SPI_EXEC_CMD, AMD_SPI_EXEC_CMD);
-	amd_spi_busy_wait(amd_spi);
+
+	return 0;
 }
 
 static int amd_spi_master_setup(struct spi_device *spi)