spi: axi-spi-engine: omit SYNC from offload instructions
authorDavid Lechner <dlechner@baylibre.com>
Mon, 28 Apr 2025 20:58:59 +0000 (15:58 -0500)
committerMark Brown <broonie@kernel.org>
Wed, 30 Apr 2025 00:38:40 +0000 (09:38 +0900)
Add optimization to omit SYNC instructions from offload messages.
Starting with IP core v1.5.0, the SYNC instruction is no longer required
for proper operation when using the offload feature. Omitting the SYNC
instruction saves a few clock cycles needed to executed which can e.g.
allow achieving higher sample rates on ADCs.

Signed-off-by: David Lechner <dlechner@baylibre.com>
Link: https://patch.msgid.link/20250428-adi-main-v1-4-4b8a1b88a212@baylibre.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-axi-spi-engine.c

index b54d2e1437c9993d251aa2842d9040ec0949a78d..8cc19934b48b5276f49c4049dcb2dbbeb4112871 100644 (file)
@@ -162,6 +162,7 @@ struct spi_engine {
        unsigned int offload_sdo_mem_size;
        struct spi_offload *offload;
        u32 offload_caps;
+       bool offload_requires_sync;
 };
 
 static void spi_engine_program_add_cmd(struct spi_engine_program *p,
@@ -702,6 +703,8 @@ static void spi_engine_offload_unprepare(struct spi_offload *offload)
 
 static int spi_engine_optimize_message(struct spi_message *msg)
 {
+       struct spi_controller *host = msg->spi->controller;
+       struct spi_engine *spi_engine = spi_controller_get_devdata(host);
        struct spi_engine_program p_dry, *p;
        int ret;
 
@@ -718,8 +721,13 @@ static int spi_engine_optimize_message(struct spi_message *msg)
 
        spi_engine_compile_message(msg, false, p);
 
-       spi_engine_program_add_cmd(p, false, SPI_ENGINE_CMD_SYNC(
-               msg->offload ? 0 : AXI_SPI_ENGINE_CUR_MSG_SYNC_ID));
+       /*
+        * Non-offload needs SYNC for completion interrupt. Older versions of
+        * the IP core also need SYNC for offload to work properly.
+        */
+       if (!msg->offload || spi_engine->offload_requires_sync)
+               spi_engine_program_add_cmd(p, false, SPI_ENGINE_CMD_SYNC(
+                       msg->offload ? 0 : AXI_SPI_ENGINE_CUR_MSG_SYNC_ID));
 
        msg->opt_state = p;
 
@@ -1055,6 +1063,9 @@ static int spi_engine_probe(struct platform_device *pdev)
                spi_engine->offload_sdo_mem_size = SPI_ENGINE_OFFLOAD_SDO_FIFO_SIZE;
        }
 
+       /* IP v1.5 dropped the requirement for SYNC in offload messages. */
+       spi_engine->offload_requires_sync = ADI_AXI_PCORE_VER_MINOR(version) < 5;
+
        writel_relaxed(0x00, spi_engine->base + SPI_ENGINE_REG_RESET);
        writel_relaxed(0xff, spi_engine->base + SPI_ENGINE_REG_INT_PENDING);
        writel_relaxed(0x00, spi_engine->base + SPI_ENGINE_REG_INT_ENABLE);