spi: Implement a atomic transfer as a last resort
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v4 Latest6 patches 0 repliesNew
- v37 patches 3 repliesSuperseded
- v26 patches 3 repliesSuperseded
Earlier versions · 1
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v1 | 2 patches | 2 replies | Superseded |
Changes in v4 from the cover letter
- drop the pm-runtime-get patch, before I dig myself deeper into an unrelated thing :-)
Patches in v4 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/6 | spi: Allow spi_toggle_csgpiod() to get called from atomic contextsdrivers/ | +12 | 0 replies | |
| 2/6 | spi: Allow spi_delay_exec() to be used from atomic contextsdrivers/ | +2 | 0 replies | |
| 3/6 | spi: Export spi_set_cs() functiondrivers/ include/ | +4 | 0 replies | |
| 4/6 | spi: Add infrastructure for atomic sync transfersdrivers/ include/ | +75 | 0 replies | |
| 5/6 | spi: rockchip: Fix runtime resume error handlingdrivers/ | +3 | 0 replies | |
| 6/6 | spi: rockchip: Add an atomic transfer functiondrivers/ | +121 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.
Cover letter [PATCH v4 0/6] spi: Implement a atomic transfer as a last resort
SPI devices at times are used as PMICs including a power-controller functionality that should turn off a system.
This happens in an atomic context very late during the shutdown, where no interrupts are available anymore and conflicts with the asynchronous nature of the SPI subsystem.
====== History ======
For the RK806 spi-connected PMIC this has already caused interesting artifacts.
A first change, tried to "fix" the issue by using the SYS_OFF_MODE_POWER_OFF_PREPARE step of poweroff. While this hides the issue, on some devices this now turns the pmic off too early before other important steps are done.
To mitigate that issue for "some" devices, a change [0] tried to use different poweroff phases for i2c and spi devices, where Lee rightfully said, that with this no proper solution would be done - and Lee was right, as that issue now is open since 2024.
The newest change is a simple revert back the old way [1] because of those issues caused on other devices, but that now breaks the SPI side again and also did not take into account that long history.
====== Now =======
The I2C framework has an atomic transfer callback for exactly this late stage transfers since
commit 63b96983a5dd ("i2c: core: introduce callbacks for atomic transfers") and during the discussion it was suggested implementing something like this for SPI too.
As this did not seem to have happened yet, I thought I'd try my luck.
Similar to I2C this is meant only for that latest stage so I stole the gating from there too.
I assume I did not take some SPI specifics into account, but I guess having some code to discuss is a starting point at least :-)
===== Testing =====
Adding the below diff allows the atomic transfer to also work as main transfer function for testing purposes. As SPI's ->transfer() call already lives inside a spinlock_irqsafe context, this allows to find any sleeping elements easily.
@@ -953,6 +953,9 @@
/* Only register atomic transfer in host-mode */
if (!target_mode) {
+ pm_runtime_resume_and_get(rs->dev);
+ ctlr->transfer = rockchip_spi_transfer_atomic;
+
ctlr->transfer_atomic = rockchip_spi_transfer_atomic;
ret = devm_register_sys_off_handler(&pdev->dev,I've also changed the chip-select of my board to use the gpio path, and no sleeping parts were reported anymore after allowing both the spi_exec_delay and gpio chipselect to handle both variants.
===== New =====
changes in v4:
- drop the pm-runtime-get patch, before I dig myself deeper into an unrelated thing :-)
changes in v3:
- core: allow gpio chipselects to be used in atomic contexts
- core: split in-atomic check, a generic one for gpio-cs and delay handling, and specific one for limiting sync calls to power-off events
- rockchip: fail gracefully when not runtime resume (Sebastian Reichel)
changes in v2:
address review comments from Mark Brown
- core: preserve old behaviour for drivers not declaring an atomic transfer function
- core: don't use message optimization - safer, but still validate the message to get bits_per_word defaults etc
- core: make spi_delay_exec usable from atomic contexts
- rockchip: only register atomic transfer in host-mode
- rockchip: provide a wait_for_idle_atomic function, to
not require (non-working) jiffies for timeout
- rockchip: register additional restart handler to enable runtime pm before reboots too
- rockchip: drop runtime-pm from atomic transfer - would sleep anyway
- rockchip: don't prevent power_off, if runtime-resume fails
- rockchip: use core spi's spi_set_cs to also handle gpio-cs
[0] https://lore.kernel.org/lkml/[email protected]/
[1] https://lore.kernel.org/all/[email protected]/
Heiko Stuebner (6):
spi: Allow spi_toggle_csgpiod() to get called from atomic contexts
spi: Allow spi_delay_exec() to be used from atomic contexts
spi: Export spi_set_cs() function
spi: Add infrastructure for atomic sync transfers
spi: rockchip: Fix runtime resume error handling
spi: rockchip: Add an atomic transfer function
drivers/spi/spi-rockchip.c | 125 ++++++++++++++++++++++++++++++++++++- drivers/spi/spi.c | 90 +++++++++++++++++++++++--- include/linux/spi/spi.h | 13 ++++ 3 files changed, 217 insertions(+), 11 deletions(-)
Signature · 1 line
2.53.0