[RFC PATCH 0/2] spi: panic atomic transfers and fsl_lpspi support

From: ChunYuZhiQiang

Date: Mon Nov 16 2026 - 04:54:34 EST


This is a follow-up to Heiko Stuebner's "spi: Implement a atomic transfer
as a last resort" series. These patches are based on that series; they
are not standalone.

Patch 1 relies on the atomic GPIO chip-select handling that Heiko
announced for v3 of his series. With v2, spi_set_cs() still calls
gpiod_set_value_cansleep(), so GPIO chip selects would sleep in the
atomic path. I will rebase on v3 once it is available.

Patch 1 implements transfer_atomic() for the i.MX LPSPI controller. It is
a second controller implementation for the new API, next to the Rockchip
one. The callback uses PIO polling with DMA and interrupts disabled, uses
the core spi_set_cs() and delay 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
the Rockchip implementation.

Patch 2 adds an explicit spi_sync_atomic() entry point for panic and oops.
The shutdown path added by Heiko is gated on system_state being past
SYSTEM_RUNNING; panic and oops run while system_state is still
SYSTEM_RUNNING, so they cannot use it. The new entry point reuses the
controller's transfer_atomic() callback, takes the bus locks with
trylock so a normal transfer in progress on another CPU returns -EBUSY
instead of deadlocking, and validates the message without allocating or
optimizing it.

The expected user is pstore over an SPI FRAM. Such a system has no
retained RAM and must persist the crash log before the next reset. The
pstore/nvmem side is still a work in progress; I would like to get the
SPI direction agreed before building on it.

Testing:

- a mock controller test in qemu exercises the panic entry point and
the error paths; all tests pass;
- spi.c and spi-fsl-lpspi.c compile on x86 with COMPILE_TEST and on
arm64 with the i.MX defconfig;
- hardware validation on i.MX8QXP is still pending.

Questions:

1. Is an explicit spi_sync_atomic() acceptable, or would you prefer to
extend spi_in_atomic_mode() to cover panic and oops so that
spi_sync() keeps switching transparently?
2. Is trylock on both bus_lock_mutex and bus_lock_spinlock the right
behaviour for panic context? The spi-mem panic write code already
checks mutex_is_locked() before entering the controller.
3. Should the fsl_lpspi implementation be a separate patch, as here, or
folded into the core series?

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

Thanks,
ChunYuZhiQiang

Signed-off-by: ChunYuZhiQiang <chunyuzhiqiang@xxxxxxxx>

ChunYuZhiQiang (2):
spi: fsl-lpspi: add atomic transfer support
spi: add spi_sync_atomic() for panic and oops

drivers/spi/spi-fsl-lpspi.c | 171 ++++++++++++++++++++++++++++++++++--
drivers/spi/spi.c | 72 +++++++++++++--
include/linux/spi/spi.h | 1 +
3 files changed, 231 insertions(+), 13 deletions(-)

--
2.47.3