Skip to content

Commit 8fc13b8

Browse files
dlechbroonie
authored andcommitted
spi: axi-spi-engine: don't repeat mode config for offload
Add an optimization to avoid repeating the config instruction in each SPI message when using SPI offloading. Instead, the instruction is run once when the SPI offload trigger is enabled. This is done to allow higher sample rates for ADCs using this SPI controller. Signed-off-by: David Lechner <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 1d0ee0c commit 8fc13b8

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ struct spi_engine_offload {
141141
struct spi_engine *spi_engine;
142142
unsigned long flags;
143143
unsigned int offload_num;
144+
unsigned int spi_mode_config;
144145
};
145146

146147
struct spi_engine {
@@ -284,6 +285,7 @@ static void spi_engine_compile_message(struct spi_message *msg, bool dry,
284285
{
285286
struct spi_device *spi = msg->spi;
286287
struct spi_controller *host = spi->controller;
288+
struct spi_engine_offload *priv;
287289
struct spi_transfer *xfer;
288290
int clk_div, new_clk_div, inst_ns;
289291
bool keep_cs = false;
@@ -297,9 +299,18 @@ static void spi_engine_compile_message(struct spi_message *msg, bool dry,
297299

298300
clk_div = 1;
299301

300-
spi_engine_program_add_cmd(p, dry,
301-
SPI_ENGINE_CMD_WRITE(SPI_ENGINE_CMD_REG_CONFIG,
302-
spi_engine_get_config(spi)));
302+
/*
303+
* As an optimization, SPI offload sets once this when the offload is
304+
* enabled instead of repeating the instruction in each message.
305+
*/
306+
if (msg->offload) {
307+
priv = msg->offload->priv;
308+
priv->spi_mode_config = spi_engine_get_config(spi);
309+
} else {
310+
spi_engine_program_add_cmd(p, dry,
311+
SPI_ENGINE_CMD_WRITE(SPI_ENGINE_CMD_REG_CONFIG,
312+
spi_engine_get_config(spi)));
313+
}
303314

304315
xfer = list_first_entry(&msg->transfers, struct spi_transfer, transfer_list);
305316
spi_engine_gen_cs(p, dry, spi, !xfer->cs_off);
@@ -842,6 +853,22 @@ static int spi_engine_trigger_enable(struct spi_offload *offload)
842853
struct spi_engine_offload *priv = offload->priv;
843854
struct spi_engine *spi_engine = priv->spi_engine;
844855
unsigned int reg;
856+
int ret;
857+
858+
writel_relaxed(SPI_ENGINE_CMD_SYNC(0),
859+
spi_engine->base + SPI_ENGINE_REG_CMD_FIFO);
860+
861+
writel_relaxed(SPI_ENGINE_CMD_WRITE(SPI_ENGINE_CMD_REG_CONFIG,
862+
priv->spi_mode_config),
863+
spi_engine->base + SPI_ENGINE_REG_CMD_FIFO);
864+
865+
writel_relaxed(SPI_ENGINE_CMD_SYNC(1),
866+
spi_engine->base + SPI_ENGINE_REG_CMD_FIFO);
867+
868+
ret = readl_relaxed_poll_timeout(spi_engine->base + SPI_ENGINE_REG_SYNC_ID,
869+
reg, reg == 1, 1, 1000);
870+
if (ret)
871+
return ret;
845872

846873
reg = readl_relaxed(spi_engine->base +
847874
SPI_ENGINE_REG_OFFLOAD_CTRL(priv->offload_num));

0 commit comments

Comments
 (0)