Skip to content

Commit 9d023ec

Browse files
dlechbroonie
authored andcommitted
spi: axi-spi-engine: populate xfer->effective_speed_hz
This adds a new spi_engine_precompile_message() function to the ADI AXI SPI Engine driver to populate the xfer->effective_speed_hz field since the SPI core doesn't/can't do this for us. This driver is already using spi_delay_to_ns() which depends on effective_speed_hz to get an accurate value in some cases. Having an effective_speed_hz value can also be used in future changes to simplify other code. Signed-off-by: David Lechner <dlechner@baylibre.com> Acked-by: Michael Hennerich <michael.hennerich@analog.com> Acked-by: Nuno Sa <nuno.sa@analog.com> Link: https://lore.kernel.org/r/20231204-axi-spi-engine-series-2-v1-2-063672323fce@baylibre.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 2e0d75f commit 9d023ec

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,27 @@ static void spi_engine_gen_cs(struct spi_engine_program *p, bool dry,
218218
spi_engine_program_add_cmd(p, dry, SPI_ENGINE_CMD_ASSERT(1, mask));
219219
}
220220

221+
/*
222+
* Performs precompile steps on the message.
223+
*
224+
* The SPI core does most of the message/transfer validation and filling in
225+
* fields for us via __spi_validate(). This fixes up anything remaining not
226+
* done there.
227+
*
228+
* NB: This is separate from spi_engine_compile_message() because the latter
229+
* is called twice and would otherwise result in double-evaluation.
230+
*/
231+
static void spi_engine_precompile_message(struct spi_message *msg)
232+
{
233+
unsigned int clk_div, max_hz = msg->spi->controller->max_speed_hz;
234+
struct spi_transfer *xfer;
235+
236+
list_for_each_entry(xfer, &msg->transfers, transfer_list) {
237+
clk_div = DIV_ROUND_UP(max_hz, xfer->speed_hz);
238+
xfer->effective_speed_hz = max_hz / min(clk_div, 256U);
239+
}
240+
}
241+
221242
static void spi_engine_compile_message(struct spi_engine *spi_engine,
222243
struct spi_message *msg, bool dry, struct spi_engine_program *p)
223244
{
@@ -504,6 +525,8 @@ static int spi_engine_prepare_message(struct spi_controller *host,
504525
if (!st)
505526
return -ENOMEM;
506527

528+
spi_engine_precompile_message(msg);
529+
507530
p_dry.length = 0;
508531
spi_engine_compile_message(spi_engine, msg, true, &p_dry);
509532

0 commit comments

Comments
 (0)