From: David Lechner <dlechner@baylibre.com>
To: linux-spi@vger.kernel.org
Cc: "David Lechner" <dlechner@baylibre.com>,
"Mark Brown" <broonie@kernel.org>,
"Michael Hennerich" <michael.hennerich@analog.com>,
"Nuno Sá" <nuno.sa@analog.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/9] spi: axi-spi-engine: populate xfer->effective_speed_hz
Date: Mon, 4 Dec 2023 11:33:28 -0600 [thread overview]
Message-ID: <20231204-axi-spi-engine-series-2-v1-2-063672323fce@baylibre.com> (raw)
In-Reply-To: <20231204-axi-spi-engine-series-2-v1-0-063672323fce@baylibre.com>
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>
---
drivers/spi/spi-axi-spi-engine.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c
index 982b37ac3063..ee7b904ae5cf 100644
--- a/drivers/spi/spi-axi-spi-engine.c
+++ b/drivers/spi/spi-axi-spi-engine.c
@@ -218,6 +218,27 @@ static void spi_engine_gen_cs(struct spi_engine_program *p, bool dry,
spi_engine_program_add_cmd(p, dry, SPI_ENGINE_CMD_ASSERT(1, mask));
}
+/*
+ * Performs precompile steps on the message.
+ *
+ * The SPI core does most of the message/transfer validation and filling in
+ * fields for us via __spi_validate(). This fixes up anything remaining not
+ * done there.
+ *
+ * NB: This is separate from spi_engine_compile_message() because the latter
+ * is called twice and would otherwise result in double-evaluation.
+ */
+static void spi_engine_precompile_message(struct spi_message *msg)
+{
+ unsigned int clk_div, max_hz = msg->spi->controller->max_speed_hz;
+ struct spi_transfer *xfer;
+
+ list_for_each_entry(xfer, &msg->transfers, transfer_list) {
+ clk_div = DIV_ROUND_UP(max_hz, xfer->speed_hz);
+ xfer->effective_speed_hz = max_hz / min(clk_div, 256U);
+ }
+}
+
static void spi_engine_compile_message(struct spi_engine *spi_engine,
struct spi_message *msg, bool dry, struct spi_engine_program *p)
{
@@ -504,6 +525,8 @@ static int spi_engine_prepare_message(struct spi_controller *host,
if (!st)
return -ENOMEM;
+ spi_engine_precompile_message(msg);
+
p_dry.length = 0;
spi_engine_compile_message(spi_engine, msg, true, &p_dry);
--
2.43.0
next prev parent reply other threads:[~2023-12-04 17:35 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-04 17:33 [PATCH 0/9] spi: axi-spi-engine: improvements round 2 David Lechner
2023-12-04 17:33 ` [PATCH 1/9] spi: axi-spi-engine: return void from spi_engine_compile_message() David Lechner
2023-12-04 17:33 ` David Lechner [this message]
2023-12-04 17:33 ` [PATCH 3/9] spi: axi-spi-engine: remove spi_engine_get_clk_div() David Lechner
2023-12-04 17:33 ` [PATCH 4/9] spi: axi-spi-engine: fix sleep ticks calculation David Lechner
2023-12-04 17:33 ` [PATCH 5/9] spi: axi-spi-engine: remove xfer arg from spi_engine_gen_sleep() David Lechner
2023-12-04 17:33 ` [PATCH 6/9] spi: axi-spi-engine: implement xfer->cs_change_delay David Lechner
2023-12-04 17:33 ` [PATCH 7/9] spi: axi-spi-engine: restore clkdiv at end of message David Lechner
2023-12-04 17:33 ` [PATCH 8/9] spi: axi-spi-engine: remove delay from CS assertion David Lechner
2023-12-04 17:33 ` [PATCH 9/9] spi: axi-spi-engine: add watchdog timer David Lechner
2023-12-05 15:12 ` [PATCH 0/9] spi: axi-spi-engine: improvements round 2 Nuno Sá
2023-12-05 15:52 ` Hennerich, Michael
2023-12-06 21:04 ` Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231204-axi-spi-engine-series-2-v1-2-063672323fce@baylibre.com \
--to=dlechner@baylibre.com \
--cc=broonie@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=michael.hennerich@analog.com \
--cc=nuno.sa@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).