Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
* [RFC PATCH v2 0/1] spi: fsl-lpspi: add atomic transfer support
@ 2026-11-27  7:34 ChunYuZhiQiang
  2026-11-27  7:34 ` [RFC PATCH v2 1/1] " ChunYuZhiQiang
  0 siblings, 1 reply; 3+ messages in thread
From: ChunYuZhiQiang @ 2026-11-27  7:34 UTC (permalink / raw)
  To: Mark Brown; +Cc: Frank Li, linux-spi, imx, linux-kernel, Heiko Stübner

This is a resend of the fsl_lpspi follow-up to Heiko Stuebner's "spi:
Implement a atomic transfer as a last resort" series.  v1 was based on an
earlier revision of that series and no longer applied; this version is
based on current broonie/spi for-next, where Heiko's v4 is applied
(for-next 63083539d2bf).

The panic entry point and its pstore/NVMEM user are split into a
follow-up series, so this one only adds a second transfer_atomic()
implementation next to Rockchip's.

The callback uses PIO polling with DMA and interrupts disabled, resets the
controller before the message, handles chip select and delays through the
core helpers, and caches the per-clock rate because clk_get_rate() takes
the clock prepare lock.  Poweroff and restart prepare handlers
runtime-resume the controller before shutdown, matching Rockchip.

Only host mode registers the callback.

Changes in v2:
- rebased onto current for-next with Heiko's v4 applied;
- split spi_sync_atomic() and the pstore/NVMEM user into a separate
  series to keep this controller-only.

Testing: compile-tested on x86 with COMPILE_TEST and on arm64, including
against the for-next version of the driver.  Hardware validation on
i.MX8QXP is still pending.

This cover letter and the patch were prepared with AI assistance; the
submitter must review them before submission.

Thanks,
ChunYuZhiQiang

Signed-off-by: ChunYuZhiQiang <chunyuzhiqiang@yinhe.ht>

ChunYuZhiQiang (1):
  spi: fsl-lpspi: add atomic transfer support

 drivers/spi/spi-fsl-lpspi.c | 171 ++++++++++++++++++++++++++++++++++--
 1 file changed, 163 insertions(+), 8 deletions(-)

base-commit: 63083539d2bf955ccf84042d4b044d1133752bed
-- 
2.47.3


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [RFC PATCH v2 1/1] spi: fsl-lpspi: add atomic transfer support
  2026-11-27  7:34 [RFC PATCH v2 0/1] spi: fsl-lpspi: add atomic transfer support ChunYuZhiQiang
@ 2026-11-27  7:34 ` ChunYuZhiQiang
  2026-11-27  7:59   ` sashiko-bot
  0 siblings, 1 reply; 3+ messages in thread
From: ChunYuZhiQiang @ 2026-11-27  7:34 UTC (permalink / raw)
  To: Mark Brown; +Cc: Frank Li, linux-spi, imx, linux-kernel, Heiko Stübner

Implement transfer_atomic() for the i.MX LPSPI controller, following the
atomic transfer API added by Heiko Stuebner.  The callback uses PIO
polling with interrupts and DMA disabled, handles chip select through
spi_set_cs(), and runs the message synchronously without completions.
The controller is reset before the message so state left by a crashed
transfer does not leak into the atomic path.

The atomic path cannot call clk_get_rate(), because it takes the clock
prepare lock.  Cache the per-clock rate at probe and refresh it in the
normal transfer path; the atomic path only uses the cached value.  A
zero rate is rejected instead of programming a bogus divisor.

Only host mode registers the callback.  Poweroff and restart prepare
handlers runtime-resume the controller so the atomic path can be used
from the shutdown notifiers, matching the Rockchip implementation.

The driver is compile-tested on x86 with COMPILE_TEST and on arm64;
hardware validation on i.MX8QXP is pending.

This patch was prepared with AI assistance; the submitter must review it
before submission.

Signed-off-by: ChunYuZhiQiang <chunyuzhiqiang@yinhe.ht>
---
 drivers/spi/spi-fsl-lpspi.c | 171 ++++++++++++++++++++++++++++++++++--
 1 file changed, 163 insertions(+), 8 deletions(-)

diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c
index ed395f822..e37761d05 100644
--- a/drivers/spi/spi-fsl-lpspi.c
+++ b/drivers/spi/spi-fsl-lpspi.c
@@ -14,6 +14,7 @@
 #include <linux/err.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
+#include <linux/iopoll.h>
 #include <linux/irq.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
@@ -22,6 +23,7 @@
 #include <linux/platform_device.h>
 #include <linux/dma/imx-dma.h>
 #include <linux/pm_runtime.h>
+#include <linux/reboot.h>
 #include <linux/slab.h>
 #include <linux/spi/spi.h>
 #include <linux/spi/spi_bitbang.h>
@@ -112,6 +114,7 @@ struct fsl_lpspi_data {
 	unsigned long base_phys;
 	struct clk *clk_ipg;
 	struct clk *clk_per;
+	u32 perclk_rate;
 	bool is_target;
 	bool is_only_cs1;
 	bool is_first_byte;
@@ -335,7 +338,8 @@ static void fsl_lpspi_set_watermark(struct fsl_lpspi_data *fsl_lpspi)
 	dev_dbg(fsl_lpspi->dev, "FCR=0x%08x\n", temp);
 }
 
-static int fsl_lpspi_set_bitrate(struct fsl_lpspi_data *fsl_lpspi)
+static int fsl_lpspi_set_bitrate(struct fsl_lpspi_data *fsl_lpspi,
+				 bool atomic)
 {
 	struct lpspi_config config = fsl_lpspi->config;
 	unsigned int perclk_rate, div;
@@ -343,7 +347,14 @@ static int fsl_lpspi_set_bitrate(struct fsl_lpspi_data *fsl_lpspi)
 	u8 prescale;
 	int scldiv;
 
-	perclk_rate = clk_get_rate(fsl_lpspi->clk_per);
+	if (atomic) {
+		perclk_rate = fsl_lpspi->perclk_rate;
+	} else {
+		perclk_rate = clk_get_rate(fsl_lpspi->clk_per);
+		fsl_lpspi->perclk_rate = perclk_rate;
+	}
+	if (!perclk_rate)
+		return -EINVAL;
 	prescale_max = fsl_lpspi->devtype_data->prescale_max ?: 7;
 
 	if (!config.speed_hz) {
@@ -427,13 +438,13 @@ static int fsl_lpspi_dma_configure(struct spi_controller *controller)
 	return 0;
 }
 
-static int fsl_lpspi_config(struct fsl_lpspi_data *fsl_lpspi)
+static int fsl_lpspi_config(struct fsl_lpspi_data *fsl_lpspi, bool atomic)
 {
 	u32 temp;
 	int ret;
 
 	if (!fsl_lpspi->is_target) {
-		ret = fsl_lpspi_set_bitrate(fsl_lpspi);
+		ret = fsl_lpspi_set_bitrate(fsl_lpspi, atomic);
 		if (ret)
 			return ret;
 	}
@@ -464,7 +475,7 @@ static int fsl_lpspi_config(struct fsl_lpspi_data *fsl_lpspi)
 
 static int fsl_lpspi_setup_transfer(struct spi_controller *controller,
 				     struct spi_device *spi,
-				     struct spi_transfer *t)
+				     struct spi_transfer *t, bool atomic)
 {
 	struct fsl_lpspi_data *fsl_lpspi =
 				spi_controller_get_devdata(spi->controller);
@@ -496,7 +507,7 @@ static int fsl_lpspi_setup_transfer(struct spi_controller *controller,
 
 	fsl_lpspi->watermark = min(fsl_lpspi->txfifosize, t->len);
 
-	return fsl_lpspi_config(fsl_lpspi);
+	return fsl_lpspi_config(fsl_lpspi, atomic);
 }
 
 static int fsl_lpspi_prepare_message(struct spi_controller *controller,
@@ -515,7 +526,7 @@ static int fsl_lpspi_prepare_message(struct spi_controller *controller,
 
 	fsl_lpspi->is_first_byte = true;
 	fsl_lpspi->usedma = false;
-	ret = fsl_lpspi_setup_transfer(controller, spi, t);
+	ret = fsl_lpspi_setup_transfer(controller, spi, t, false);
 
 	fsl_lpspi->usedma = fsl_lpspi_can_dma(controller, spi, t);
 
@@ -774,6 +785,114 @@ static int fsl_lpspi_pio_transfer(struct fsl_lpspi_data *fsl_lpspi,
 	return ret;
 }
 
+static int fsl_lpspi_pio_xfer_atomic(struct fsl_lpspi_data *fsl_lpspi,
+				     struct spi_transfer *t)
+{
+	u32 sr, timeout_us;
+	int ret;
+
+	/* One frame plus margin, at least 1ms. */
+	timeout_us = DIV_ROUND_UP(8 * USEC_PER_SEC, fsl_lpspi->config.speed_hz);
+	timeout_us = max(timeout_us * 2, 1000U);
+
+	fsl_lpspi->tx_buf = t->tx_buf;
+	fsl_lpspi->rx_buf = t->rx_buf;
+	fsl_lpspi->remain = t->len;
+
+	while (fsl_lpspi->remain) {
+		ret = readl_poll_timeout_atomic(fsl_lpspi->base + IMX7ULP_SR,
+						sr, sr & SR_TDF, 0, timeout_us);
+		if (ret)
+			return ret;
+		fsl_lpspi->tx(fsl_lpspi);
+
+		ret = readl_poll_timeout_atomic(fsl_lpspi->base + IMX7ULP_SR,
+						sr, sr & SR_RDF, 0, timeout_us);
+		if (ret)
+			return ret;
+		fsl_lpspi->rx(fsl_lpspi);
+	}
+
+	ret = readl_poll_timeout_atomic(fsl_lpspi->base + IMX7ULP_SR, sr,
+					sr & SR_TCF, 0, timeout_us);
+	if (ret)
+		return ret;
+
+	writel(SR_TCF, fsl_lpspi->base + IMX7ULP_SR);
+	return 0;
+}
+
+static int fsl_lpspi_transfer_atomic(struct spi_device *spi,
+				     struct spi_message *msg)
+{
+	struct spi_controller *controller = spi->controller;
+	struct fsl_lpspi_data *fsl_lpspi =
+				spi_controller_get_devdata(controller);
+	struct spi_transfer *t, *next;
+	bool first = true;
+	bool keep_cs = false;
+	int ret = 0;
+
+	if (!pm_runtime_active(fsl_lpspi->dev))
+		return -ESHUTDOWN;
+
+	fsl_lpspi->usedma = false;
+	fsl_lpspi_reset(fsl_lpspi);
+	writel(0, fsl_lpspi->base + IMX7ULP_DER);
+
+	t = list_first_entry(&msg->transfers, struct spi_transfer, transfer_list);
+	spi_set_cs(spi, !t->cs_off, false);
+
+	list_for_each_entry(t, &msg->transfers, transfer_list) {
+		if (t->len) {
+			fsl_lpspi->is_first_byte = first;
+			ret = fsl_lpspi_setup_transfer(controller, spi, t, true);
+			if (ret)
+				break;
+			if (t->len %
+			    fsl_lpspi_bytes_per_word(fsl_lpspi->config.bpw)) {
+				ret = -EINVAL;
+				break;
+			}
+
+			fsl_lpspi_set_cmd(fsl_lpspi);
+			fsl_lpspi->is_first_byte = false;
+
+			ret = fsl_lpspi_pio_xfer_atomic(fsl_lpspi, t);
+			if (ret)
+				break;
+
+			fsl_lpspi_reset(fsl_lpspi);
+			first = false;
+		}
+
+		spi_transfer_delay_exec(t);
+
+		if (t->cs_change) {
+			if (list_is_last(&t->transfer_list, &msg->transfers)) {
+				keep_cs = true;
+			} else {
+				if (!t->cs_off)
+					spi_set_cs(spi, false, false);
+				spi_transfer_cs_change_delay_exec(msg, t);
+				next = list_next_entry(t, transfer_list);
+				if (!next->cs_off)
+					spi_set_cs(spi, true, false);
+			}
+		} else if (!list_is_last(&t->transfer_list, &msg->transfers)) {
+			next = list_next_entry(t, transfer_list);
+			if (t->cs_off != next->cs_off)
+				spi_set_cs(spi, !next->cs_off, false);
+		}
+	}
+
+	if (!keep_cs)
+		spi_set_cs(spi, false, false);
+	fsl_lpspi_reset(fsl_lpspi);
+	msg->status = ret;
+	return ret;
+}
+
 static int fsl_lpspi_transfer_one(struct spi_controller *controller,
 				  struct spi_device *spi,
 				  struct spi_transfer *t)
@@ -784,7 +903,7 @@ static int fsl_lpspi_transfer_one(struct spi_controller *controller,
 
 	fsl_lpspi->usedma = fsl_lpspi_can_dma(controller, spi, t);
 
-	ret = fsl_lpspi_setup_transfer(controller, spi, t);
+	ret = fsl_lpspi_setup_transfer(controller, spi, t, false);
 	if (ret < 0)
 		return ret;
 
@@ -878,6 +997,19 @@ static int fsl_lpspi_init_rpm(struct fsl_lpspi_data *fsl_lpspi)
 	return 0;
 }
 
+static int fsl_lpspi_power_off(struct sys_off_data *data)
+{
+	struct fsl_lpspi_data *fsl_lpspi = data->cb_data;
+	int ret;
+
+	ret = pm_runtime_resume_and_get(fsl_lpspi->dev);
+	if (ret)
+		dev_warn(fsl_lpspi->dev,
+			 "failed to resume controller for poweroff: %d\n", ret);
+
+	return 0;
+}
+
 static int fsl_lpspi_probe(struct platform_device *pdev)
 {
 	const struct fsl_lpspi_devtype_data *devtype_data;
@@ -958,6 +1090,9 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
 		goto out_pm_get;
 	}
 
+	/* The atomic transfer path cannot call clk_get_rate(). */
+	fsl_lpspi->perclk_rate = clk_get_rate(fsl_lpspi->clk_per);
+
 	temp = readl(fsl_lpspi->base + IMX7ULP_PARAM);
 	fsl_lpspi->txfifosize = 1 << (temp & 0x0f);
 	fsl_lpspi->rxfifosize = 1 << ((temp >> 8) & 0x0f);
@@ -972,6 +1107,8 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
 	controller->bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 32);
 	controller->prepare_message = fsl_lpspi_prepare_message;
 	controller->transfer_one = fsl_lpspi_transfer_one;
+	if (!fsl_lpspi->is_target)
+		controller->transfer_atomic = fsl_lpspi_transfer_atomic;
 	controller->prepare_transfer_hardware = lpspi_prepare_xfer_hardware;
 	controller->unprepare_transfer_hardware = lpspi_unprepare_xfer_hardware;
 	controller->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
@@ -982,6 +1119,24 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
 	if (!fsl_lpspi->is_target)
 		controller->use_gpio_descriptors = true;
 
+	if (!fsl_lpspi->is_target) {
+		ret = devm_register_sys_off_handler(&pdev->dev,
+						    SYS_OFF_MODE_POWER_OFF_PREPARE,
+						    SYS_OFF_PRIO_DEFAULT,
+						    fsl_lpspi_power_off,
+						    fsl_lpspi);
+		if (ret)
+			goto out_pm_get;
+
+		ret = devm_register_sys_off_handler(&pdev->dev,
+						    SYS_OFF_MODE_RESTART_PREPARE,
+						    SYS_OFF_PRIO_DEFAULT,
+						    fsl_lpspi_power_off,
+						    fsl_lpspi);
+		if (ret)
+			goto out_pm_get;
+	}
+
 	ret = fsl_lpspi_dma_init(&pdev->dev, fsl_lpspi, controller);
 	if (ret == -EPROBE_DEFER)
 		goto out_pm_get;
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH v2 1/1] spi: fsl-lpspi: add atomic transfer support
  2026-11-27  7:34 ` [RFC PATCH v2 1/1] " ChunYuZhiQiang
@ 2026-11-27  7:59   ` sashiko-bot
  0 siblings, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-27  7:59 UTC (permalink / raw)
  To: ChunYuZhiQiang; +Cc: imx, Frank.Li

Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [High] spi: fsl-lpspi: RX watermark deadlock in
  fsl_lpspi_pio_xfer_atomic()
- [High] spi: fsl-lpspi: SR_TCF timeout with TCR_CONT in
  fsl_lpspi_pio_xfer_atomic()
- [High] spi: fsl-lpspi: TCR_CONTC set after reset in
  fsl_lpspi_transfer_atomic()
- [Medium] spi: fsl-lpspi: CS asserted before CPOL/CPHA in
  fsl_lpspi_transfer_atomic()
- [Medium] spi: fsl-lpspi: wrong word-size check in
  fsl_lpspi_transfer_atomic()
- [Medium] spi: fsl-lpspi: missing actual_length in
  fsl_lpspi_transfer_atomic()
- [Low] spi: fsl-lpspi: unedited AI assistance placeholder note in
  commit message
--

commit 82f1685db0bb8dc824359af32b18e4e751d9a022
Author: ChunYuZhiQiang <chunyuzhiqiang@yinhe.ht>

spi: fsl-lpspi: add atomic transfer support

This commit adds a transfer_atomic() callback for the i.MX LPSPI controller
using polled PIO, caches the peripheral clock rate for atomic context, and
registers sys-off handlers to runtime-resume the controller before shutdown
or restart.

> This patch was prepared with AI assistance; the submitter must review it
> before submission.

[Severity: Low]
This looks like an unedited reminder from an AI tool that should be
removed from the commit message before merging.

> diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c
> index ed395f822dab1..e37761d05cd5e 100644
> --- a/drivers/spi/spi-fsl-lpspi.c
> +++ b/drivers/spi/spi-fsl-lpspi.c

[ ... ]

> @@ -774,6 +785,114 @@ static int fsl_lpspi_pio_transfer(struct fsl_lpspi_data *fsl_lpspi,
>  	return ret;
>  }
>  
> +static int fsl_lpspi_pio_xfer_atomic(struct fsl_lpspi_data *fsl_lpspi,
> +				     struct spi_transfer *t)
> +{
> +	u32 sr, timeout_us;
> +	int ret;
> +
> +	/* One frame plus margin, at least 1ms. */
> +	timeout_us = DIV_ROUND_UP(8 * USEC_PER_SEC, fsl_lpspi->config.speed_hz);
> +	timeout_us = max(timeout_us * 2, 1000U);
> +
> +	fsl_lpspi->tx_buf = t->tx_buf;
> +	fsl_lpspi->rx_buf = t->rx_buf;
> +	fsl_lpspi->remain = t->len;
> +
> +	while (fsl_lpspi->remain) {
> +		ret = readl_poll_timeout_atomic(fsl_lpspi->base + IMX7ULP_SR,
> +						sr, sr & SR_TDF, 0, timeout_us);
> +		if (ret)
> +			return ret;
> +		fsl_lpspi->tx(fsl_lpspi);
> +
> +		ret = readl_poll_timeout_atomic(fsl_lpspi->base + IMX7ULP_SR,
> +						sr, sr & SR_RDF, 0, timeout_us);
> +		if (ret)
> +			return ret;
> +		fsl_lpspi->rx(fsl_lpspi);
> +	}

[Severity: High]
Will polling SR_RDF after transmitting a single word time out whenever
t->len >= 2?

fsl_lpspi_setup_transfer() sets fsl_lpspi->watermark to
min(fsl_lpspi->txfifosize, t->len), and fsl_lpspi_set_watermark() writes
FCR_RXWATER = fsl_lpspi->watermark >> 1 (>= 1 for t->len >= 2).  In the
LPSPI controller, SR_RDF only asserts when the RX FIFO word count is
strictly greater than FCR_RXWATER.  Because this loop only puts one word
in flight at a time, RXCOUNT reaches 1 and SR_RDF never asserts, so every
multi-byte transfer fails with -ETIMEDOUT.  (The interrupt PIO path avoids
this in fsl_lpspi_read_rx_fifo() by checking RSR_RXEMPTY in IMX7ULP_RSR
instead of SR_RDF.)

> +
> +	ret = readl_poll_timeout_atomic(fsl_lpspi->base + IMX7ULP_SR, sr,
> +					sr & SR_TCF, 0, timeout_us);
> +	if (ret)
> +		return ret;

[Severity: High]
Can SR_TCF assert here while continuous transfer mode (TCR_CONT) is still
active?

Because fsl_lpspi->usedma is false, fsl_lpspi_set_cmd() sets TCR_CONT in
IMX7ULP_TCR, which keeps the transfer active after the TX FIFO drains
until a new command word without TCR_CONTC is written to IMX7ULP_TCR (as
fsl_lpspi_write_tx_fifo() and fsl_lpspi_isr() do before waiting for
SR_FCF).  Without terminating the continuous command in IMX7ULP_TCR, this
poll on SR_TCF stalls for timeout_us and returns -ETIMEDOUT.

> +
> +	writel(SR_TCF, fsl_lpspi->base + IMX7ULP_SR);
> +	return 0;
> +}
> +
> +static int fsl_lpspi_transfer_atomic(struct spi_device *spi,
> +				     struct spi_message *msg)
> +{
> +	struct spi_controller *controller = spi->controller;
> +	struct fsl_lpspi_data *fsl_lpspi =
> +				spi_controller_get_devdata(controller);
> +	struct spi_transfer *t, *next;
> +	bool first = true;
> +	bool keep_cs = false;
> +	int ret = 0;
> +
> +	if (!pm_runtime_active(fsl_lpspi->dev))
> +		return -ESHUTDOWN;
> +
> +	fsl_lpspi->usedma = false;
> +	fsl_lpspi_reset(fsl_lpspi);
> +	writel(0, fsl_lpspi->base + IMX7ULP_DER);
> +
> +	t = list_first_entry(&msg->transfers, struct spi_transfer, transfer_list);
> +	spi_set_cs(spi, !t->cs_off, false);

[Severity: Medium]
Does asserting chip select before fsl_lpspi_setup_transfer() and
fsl_lpspi_set_cmd() glitch SCLK while CS is active?

In the normal path, fsl_lpspi_prepare_message() programs TCR_CPOL and
TCR_CPHA before the core asserts CS (see 7ae4d097b752 ("spi:
spi-fsl-lpspi: Handle clock polarity and phase")).  __spi_sync_atomic()
does not call prepare_message(), so asserting CS right after
fsl_lpspi_reset() causes any clock polarity transition to happen while the
target device is already selected.

> +
> +	list_for_each_entry(t, &msg->transfers, transfer_list) {
> +		if (t->len) {
> +			fsl_lpspi->is_first_byte = first;
> +			ret = fsl_lpspi_setup_transfer(controller, spi, t, true);
> +			if (ret)
> +				break;
> +			if (t->len %
> +			    fsl_lpspi_bytes_per_word(fsl_lpspi->config.bpw)) {
> +				ret = -EINVAL;
> +				break;
> +			}

[Severity: Medium]
Does this length check reject valid 17..24 bits-per-word transfers?

For 17 <= bpw <= 24, __spi_validate() and fsl_lpspi_buf_tx_u32() /
fsl_lpspi_buf_rx_u32() use a 4-byte (sizeof(u32)) stride in memory,
whereas fsl_lpspi_bytes_per_word(bpw) returns DIV_ROUND_UP(bpw, 8) == 3.
A 17..24-bit transfer whose byte length is a multiple of 4 (such as 4 or 8
bytes) will fail here with -EINVAL.

> +
> +			fsl_lpspi_set_cmd(fsl_lpspi);
> +			fsl_lpspi->is_first_byte = false;
> +
> +			ret = fsl_lpspi_pio_xfer_atomic(fsl_lpspi, t);
> +			if (ret)
> +				break;
> +
> +			fsl_lpspi_reset(fsl_lpspi);
> +			first = false;
> +		}

[Severity: High]
Does calling fsl_lpspi_reset() at the end of each transfer break
subsequent transfers in a multi-transfer message?

fsl_lpspi_reset() clears CR_MEN and flushes the TX and RX FIFOs,
destroying any active continuous transfer state in the hardware (and
deasserting native PCS if GPIO CS is not used).  Setting first = false
then causes the next transfer's fsl_lpspi_set_cmd() to write TCR_CONTC = 1
to a freshly reset controller with no active TCR_CONT command, which sets
the Transmit Error Flag (SR[TEF]) and drops the command.

> +
> +		spi_transfer_delay_exec(t);
> +
> +		if (t->cs_change) {
> +			if (list_is_last(&t->transfer_list, &msg->transfers)) {
> +				keep_cs = true;
> +			} else {
> +				if (!t->cs_off)
> +					spi_set_cs(spi, false, false);
> +				spi_transfer_cs_change_delay_exec(msg, t);
> +				next = list_next_entry(t, transfer_list);
> +				if (!next->cs_off)
> +					spi_set_cs(spi, true, false);
> +			}
> +		} else if (!list_is_last(&t->transfer_list, &msg->transfers)) {
> +			next = list_next_entry(t, transfer_list);
> +			if (t->cs_off != next->cs_off)
> +				spi_set_cs(spi, !next->cs_off, false);
> +		}
> +	}
> +
> +	if (!keep_cs)
> +		spi_set_cs(spi, false, false);
> +	fsl_lpspi_reset(fsl_lpspi);
> +	msg->status = ret;
> +	return ret;
> +}

[Severity: Medium]
Should fsl_lpspi_transfer_atomic() update msg->actual_length and
t->effective_speed_hz?

__spi_sync_atomic() calls controller->transfer_atomic() directly without
going through spi_transfer_one_message(), so leaving msg->actual_length
unupdated causes callers that check it (such as spi_mem_exec_op()) to
treat completed atomic transfers as failed.  Populating
t->effective_speed_hz after fsl_lpspi_setup_transfer() (as
fsl_lpspi_transfer_one() does) is also needed for SPI_DELAY_UNIT_SCK
delays in spi_transfer_delay_exec() and
spi_transfer_cs_change_delay_exec().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127073454.351296-1-chunyuzhiqiang@yinhe.ht?part=1

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-27  7:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27  7:34 [RFC PATCH v2 0/1] spi: fsl-lpspi: add atomic transfer support ChunYuZhiQiang
2026-11-27  7:34 ` [RFC PATCH v2 1/1] " ChunYuZhiQiang
2026-11-27  7:59   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox