[PATCH 1/2] spi: Add infrastructure for atomic sync transfers
Mark Brown
broonie at kernel.org
Mon Nov 9 14:02:46 PST 2026
> There are cases where SPI transfers are needed during times without
> interrupts like shutdown when a PMIC should turn off the system.
> I2C already has atomic transfers for exactly that case, so introduce a
> similar concept for SPI. Similar to I2C, this is and should stay a
> corner-case, so is only allowed during the shutdown stages of the kernel,
> when interrupts are already turned off.
> So add a in-atomic check stolen from I2C and an optional transfer_atomic
> callback drivers can implement to do immediate uninterrupted transfers
> and let spi_sync() determine if the state is late enough to use it.
> spi_async() does not require a sleeping context for itself, so while it
> could in theory also be included, its called waiting for the completion
> can sleep, so would still cause the splat about it.
> +static int __spi_sync_atomic(struct spi_device *spi, struct spi_message *message)
> +{
> + struct spi_controller *ctlr = spi->controller;
> + unsigned long flags;
> + int status;
> +
> + if (!ctlr->transfer_atomic) {
We do have some existing users that appear to rely on using spi_sync()
to power off like SC27xx. I suspect they are tolerating the splats, or
just don't work, but either way we should try to preserve the current
behaviour for them.
> + status = spi_maybe_optimize_message(spi, message);
Message optimisation may try to do things like allocations that are a
bad idea in atomic context - it seems safer to just use the message as
is in this context.
--
Mark Brown <broonie at kernel.org>
More information about the Linux-rockchip
mailing list