From: sashiko-bot@kernel.org
To: ChunYuZhiQiang <chunyuzhiqiang@yinhe.ht>
Cc: imx@lists.linux.dev, Frank.Li@kernel.org
Subject: Re: [RFC PATCH v3] spi: fsl-lpspi: add atomic transfer support
Date: Fri, 27 Nov 2026 13:26:10 +0000 [thread overview]
Message-ID: <sashiko-outbox-237486@kernel.org> (raw)
In-Reply-To: <20261127125827.22857-1-chunyuzhiqiang@yinhe.ht>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] spi: fsl-lpspi: premature TCR_CONTC clear in
fsl_lpspi_pio_xfer_atomic()
- [High] spi: fsl-lpspi: broken TCR_CONTC handling in
fsl_lpspi_transfer_atomic()
--
commit 1c6b4fd740bc599cecc8d77f094463efe4a15041
Author: ChunYuZhiQiang <chunyuzhiqiang@yinhe.ht>
spi: fsl-lpspi: add atomic transfer support
This commit implements the transfer_atomic() callback for the i.MX LPSPI
controller using PIO polling, caches the peripheral clock rate for atomic
contexts, and registers sys_off handlers to runtime-resume the controller
before poweroff and restart.
> 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);
> + if (ret)
> + return ret;
[Severity: High]
Does writing IMX7ULP_TCR with TCR_CONTC cleared before calling
fsl_lpspi->tx() push the command word into the TX FIFO ahead of the last
data word rather than after it?
Writes to IMX7ULP_TCR and IMX7ULP_TDR are queued sequentially in the same
TX FIFO, and the value read from IMX7ULP_TCR still has TCR_CONT set. In
the normal PIO path, fsl_lpspi_write_tx_fifo() pushes all data words via
fsl_lpspi->tx() until fsl_lpspi->remain reaches 0 before writing
IMX7ULP_TCR with TCR_CONTC cleared:
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);
}
...
}
Queuing the command word before fsl_lpspi->tx() writes the final data word
leaves continuous mode active after that final word is shifted out.
Single-word atomic transfers will never assert SR_FCF and will time out,
while multi-word transfers will end the continuous frame one word early
and transmit the last word in a new unterminated continuous transfer.
> + writel(SR_FCF, fsl_lpspi->base + IMX7ULP_SR);
> + return 0;
> +}
> +
> +static int fsl_lpspi_transfer_atomic(struct spi_device *spi,
> + struct spi_message *msg)
> +{
[ ... ]
> + list_for_each_entry(t, &msg->transfers, transfer_list) {
> + if (t->len) {
> + fsl_lpspi->is_first_byte = first_xfer;
> + ret = fsl_lpspi_setup_transfer(controller, spi, t, true);
> + if (ret)
> + break;
> +
> + t->effective_speed_hz = fsl_lpspi->config.effective_speed_hz;
> +
> + if (t->len %
> + spi_bpw_to_bytes(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;
> +
> + msg->actual_length += t->len;
> + fsl_lpspi_reset(fsl_lpspi);
> + first_xfer = false;
> + }
[Severity: High]
Does setting first_xfer = false after fsl_lpspi_pio_xfer_atomic() and
fsl_lpspi_reset() cause subsequent transfers in a multi-transfer message
to start with TCR_CONTC set when no continuous transfer is active?
At the end of each transfer, fsl_lpspi_pio_xfer_atomic() terminates the
frame and waits for SR_FCF, and fsl_lpspi_reset() disables the module and
flushes the TX and RX FIFOs. On the next transfer in msg->transfers,
fsl_lpspi->is_first_byte is set to false, so fsl_lpspi_set_cmd() programs
TCR_CONT | TCR_CONTC into IMX7ULP_TCR even though the previous continuous
transfer already completed and the controller was reset. Combined with
fsl_lpspi_pio_xfer_atomic() clearing TCR_CONTC before writing the last
data word to IMX7ULP_TDR, multi-transfer atomic messages will fail or time
out.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127125827.22857-1-chunyuzhiqiang@yinhe.ht?part=1
prev parent reply other threads:[~2026-11-27 13:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 12:58 [RFC PATCH v3] spi: fsl-lpspi: add atomic transfer support ChunYuZhiQiang
2026-11-27 13:26 ` 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-237486@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.