Skip to content

Commit 4e34f82

Browse files
dlechnunojsa
authored andcommitted
spi: axi-spi-engine: wait for completion in setup
Add a polling wait for SPI instruction execution to complete in the spi_engine_setup() function. In practice, these instructions complete in a few 10s of nanoseconds, so we never ran into any race conditions, but it is good practice to wait for the completion of the SPI engine instructions before returning from the setup function. Signed-off-by: David Lechner <dlechner@baylibre.com> Link: https://patch.msgid.link/20250428-adi-main-v1-1-4b8a1b88a212@baylibre.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 98aa331 commit 4e34f82

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

‎drivers/spi/spi-axi-spi-engine.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/fpga/adi-axi-common.h>
1515
#include <linux/interrupt.h>
1616
#include <linux/io.h>
17+
#include <linux/iopoll.h>
1718
#include <linux/of.h>
1819
#include <linux/module.h>
1920
#include <linux/overflow.h>
@@ -739,12 +740,16 @@ static int spi_engine_setup(struct spi_device *device)
739740
{
740741
struct spi_controller *host = device->controller;
741742
struct spi_engine *spi_engine = spi_controller_get_devdata(host);
743+
unsigned int reg;
742744

743745
if (device->mode & SPI_CS_HIGH)
744746
spi_engine->cs_inv |= BIT(spi_get_chipselect(device, 0));
745747
else
746748
spi_engine->cs_inv &= ~BIT(spi_get_chipselect(device, 0));
747749

750+
writel_relaxed(SPI_ENGINE_CMD_SYNC(0),
751+
spi_engine->base + SPI_ENGINE_REG_CMD_FIFO);
752+
748753
writel_relaxed(SPI_ENGINE_CMD_CS_INV(spi_engine->cs_inv),
749754
spi_engine->base + SPI_ENGINE_REG_CMD_FIFO);
750755

@@ -755,7 +760,11 @@ static int spi_engine_setup(struct spi_device *device)
755760
writel_relaxed(SPI_ENGINE_CMD_ASSERT(0, 0xff),
756761
spi_engine->base + SPI_ENGINE_REG_CMD_FIFO);
757762

758-
return 0;
763+
writel_relaxed(SPI_ENGINE_CMD_SYNC(1),
764+
spi_engine->base + SPI_ENGINE_REG_CMD_FIFO);
765+
766+
return readl_relaxed_poll_timeout(spi_engine->base + SPI_ENGINE_REG_SYNC_ID,
767+
reg, reg == 1, 1, 1000);
759768
}
760769

761770
static int spi_engine_transfer_one_message(struct spi_controller *host,

0 commit comments

Comments
 (0)