From: sashiko-bot@kernel.org
To: ChunYuZhiQiang <chunyuzhiqiang@yinhe.ht>
Cc: imx@lists.linux.dev, Frank.Li@kernel.org
Subject: Re: [RFC PATCH v4] spi: fsl-lpspi: add atomic transfer support
Date: Fri, 27 Nov 2026 14:19:08 +0000 [thread overview]
Message-ID: <sashiko-outbox-237552@kernel.org> (raw)
In-Reply-To: <20261127140228.48851-1-chunyuzhiqiang@yinhe.ht>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] spi: fsl-lpspi: premature TCR_CONTC clear in
fsl_lpspi_pio_xfer_atomic()
--
commit f448f305f9614918db9e4edf6fb2c18c134df2de
Author: ChunYuZhiQiang <chunyuzhiqiang@yinhe.ht>
spi: fsl-lpspi: add atomic transfer support
This commit implements transfer_atomic() for the i.MX LPSPI controller
using PIO polling, caches the per-clock rate for atomic context, and
registers poweroff and restart prepare handlers to runtime-resume the
controller.
> diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c
> index ed395f822dab1..bc76a564137b9 100644
> --- a/drivers/spi/spi-fsl-lpspi.c
> +++ b/drivers/spi/spi-fsl-lpspi.c
[ ... ]
> @@ -774,6 +785,148 @@ 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, temp, timeout_us;
> + unsigned int bytes_per_word;
> + int ret;
> +
> + /* One frame plus margin, at least 1ms. */
> + timeout_us = DIV_ROUND_UP(fsl_lpspi->config.bpw * USEC_PER_SEC,
> + fsl_lpspi->config.speed_hz);
> + timeout_us = max(timeout_us * 2, 1000U);
> +
> + bytes_per_word = spi_bpw_to_bytes(fsl_lpspi->config.bpw);
> + 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;
> +
> + /* Terminate continuous mode before the last frame. */
> + if (fsl_lpspi->remain == bytes_per_word) {
> + temp = readl(fsl_lpspi->base + IMX7ULP_TCR);
> + temp &= ~TCR_CONTC;
> + writel(temp, fsl_lpspi->base + IMX7ULP_TCR);
> + }
> +
> + fsl_lpspi->tx(fsl_lpspi);
> +
> + ret = readl_poll_timeout_atomic(fsl_lpspi->base + IMX7ULP_RSR,
> + sr, !(sr & RSR_RXEMPTY), 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_FCF, 0, timeout_us);
[Severity: High]
Does writing IMX7ULP_TCR with TCR_CONTC cleared before calling
fsl_lpspi->tx() queue the terminating command word ahead of the final data
word in the shared TX FIFO?
Because temp read from IMX7ULP_TCR still has TCR_CONT set and writes to
IMX7ULP_TCR and IMX7ULP_TDR share the TX FIFO, a single-word atomic
transfer pushes the command word before the data word and queues no
command word after it, so continuous mode never ends and the SR_FCF poll
times out with -ETIMEDOUT. Multi-word transfers end the frame one word
early and leave the final word in an unterminated continuous transfer.
In the normal PIO path, fsl_lpspi_write_tx_fifo() pushes the data words
via fsl_lpspi->tx() first and clears TCR_CONTC only after
fsl_lpspi->remain reaches zero:
drivers/spi/spi-fsl-lpspi.c:fsl_lpspi_write_tx_fifo() {
...
while (txfifo_cnt < fsl_lpspi->txfifosize && fsl_lpspi->remain) {
fsl_lpspi->tx(fsl_lpspi);
txfifo_cnt++;
}
if (txfifo_cnt < fsl_lpspi->txfifosize) {
if (!fsl_lpspi->is_target) {
temp = readl(fsl_lpspi->base + IMX7ULP_TCR);
temp &= ~TCR_CONTC;
writel(temp, fsl_lpspi->base + IMX7ULP_TCR);
}
...
}
Wait for SR_TDF and write IMX7ULP_TCR with TCR_CONTC cleared after the
final data word has been pushed by fsl_lpspi->tx(), as the commit message
describes.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127140228.48851-1-chunyuzhiqiang@yinhe.ht?part=1
prev parent reply other threads:[~2026-11-27 14:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 14:02 [RFC PATCH v4] spi: fsl-lpspi: add atomic transfer support ChunYuZhiQiang
2026-11-27 14:19 ` sashiko-bot [this message]
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=sashiko-outbox-237552@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=chunyuzhiqiang@yinhe.ht \
--cc=imx@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
/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