summaryrefslogtreecommitdiff
path: root/drivers/spi
AgeCommit message (Collapse)Author
47 hoursspi: ar934x: Convert to devm_spi_register_controller()Felix Gu
Switch to devm_spi_register_controller() and drop the unneeded .remove callback and dev_set_drvdata(). Signed-off-by: Felix Gu <ustc.gu@gmail.com> Link: https://patch.msgid.link/20260907-ar934x-v1-1-71327eb482bc@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
2 daysspi: orion: yield to scheduler in transfer wait loopRosen Penev
orion_spi_wait_till_ready() busy-waits in a tight udelay(1) loop, up to 2000 iterations, and is called per byte from the polled, byte-at-a-time transfer path. On SoCs such as the Armada 388 (e.g. SolidRun Helios4), which also run SATA over the shared internal MBus fabric, this stalls the CPU for the whole transfer and delays servicing of SATA interrupts. Under sustained activity this can cause SATA timeouts and link resets (sometimes renegotiating down to SATA II, 3 Gbps). Add cond_resched() to the wait loop so the scheduler can run pending IRQs between polls. This is a no-op at runtime unless the kernel is built with CONFIG_PREEMPT enabled, where it lets other peripheral interrupts be serviced during SPI transfers. Built with LLVM=1 ARCH=powerpc; passes checkpatch --strict. Assisted-by: opencode:big-pickle Signed-off-by: Rosen Penev <rosenp@gmail.com> Link: https://patch.msgid.link/20260907005750.230103-1-rosenp@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
3 daysspi: fix typos in commentsHemanth Selam
Fix typos in comments, reported by scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Only touches comments, no code changes. Assisted-by: Cursor:claude-opus-5 Signed-off-by: Hemanth Selam <hemanth.selam@gmail.com> Link: https://patch.msgid.link/20260904110420.13707-1-hemanth.selam@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
3 daysspi: ma35d1-qspi: Flag the DTR capability correctlyMark Brown
Miquel Raynal <miquel.raynal@bootlin.com> says: Mark pointed out that the DTR capability was not correctly enabled since I had to set the extra ctlr->dtr_caps flag. For testing, I commented out the spi-mem ops/caps and figured out DTR variants were still not picked up. This was due to the spi-mem fallback implementation of ->exec_op() not forwarding the DTR flag. Link: https://patch.msgid.link/20260904-perso-ma35d1-master-v1-0-b6936e8c6fa1@bootlin.com
3 daysspi: ma35d1-qspi: Allow DTR operations with the regular SPI APIMiquel Raynal
The feature was implemented but not actually enabled for regular SPI operations (as opposed to spi-mem operations). Make sure the missing capability is actually set. Reported-by: Mark Brown <broonie@kernel.org> Closes: https://lore.kernel.org/all/09c3928f-4b58-4ac6-8e1a-84dfe3ff6b92@sirena.org.uk/ Fixes: 15e9362f6190 ("spi: ma35d1-qspi: Add DTR support") Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://patch.msgid.link/20260904-perso-ma35d1-master-v1-2-b6936e8c6fa1@bootlin.com Signed-off-by: Mark Brown <broonie@kernel.org>
3 daysspi: spi-mem: Enable DTR transfers using the standard APIMiquel Raynal
Most spi-mem operations today go through controllers implementing the spi-mem API. But it is also totally possible to use any standard SPI controller to operate these memories. If the controllers support DTR, there is no reason to prevent this feature from being used. Extend spi_mem_exec_op()'s fallback to the standard SPI API, by filling the transfer DTR information. Doing so also requires checking the dtr_caps flag, of course. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://patch.msgid.link/20260904-perso-ma35d1-master-v1-1-b6936e8c6fa1@bootlin.com Signed-off-by: Mark Brown <broonie@kernel.org>
5 daystreewide: refresh kmalloc_obj() conversionsKees Cook
This is another run of the Coccinelle script for converting kmalloc() family of allocations to kmalloc_obj() via the existing rules in scripts/coccinelle/api/kmalloc_objs.cocci This catches both the set of kmalloc() uses added since the first kmalloc_obj() conversions in v7.0 and adds a large group missed in the first pass due to Coccinelle not interacting well with the cleanup.h scoped_...() family of macros[1]. I worked around this with spatch's "--macro-file" argument to a file with all the scoped_...() macros mapped to Coccinelle's YACFE_ITERATOR[2] as that was the closest viable control flow indicator I could find. Build tested allmodconfig on x86, arm64, arm, loongarch, mips, powerpc, riscv, and s390 with no new warnings. Link: https://lore.kernel.org/lkml/202609021314.8A9C0B8@keescook/ [1] Link: https://github.com/coccinelle/coccinelle/blob/master/standard.h [2] Signed-off-by: Kees Cook <kees+treewide@kernel.org>
6 daysspi: mtk-nor: fix runtime PM usage count leak in probe error pathFelix Gu
mtk_nor_probe() takes a runtime PM reference with pm_runtime_get_noresume() before registering the controller, but the error path never drops it. Balance the get with pm_runtime_put_noidle() in the error path. Fixes: 3bfd9103c7af ("spi: spi-mtk-nor: Add power management support") Signed-off-by: Felix Gu <ustc.gu@gmail.com> Link: https://patch.msgid.link/20260904-mtk-nor-v1-1-cefdca098f83@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
6 daysspi: ma35d1-qspi: assert reset on probe error pathsLi Youhong
nuvoton_qspi_probe() pulses the exclusive reset and leaves it deasserted for normal operation. Later probe failures returned without re-asserting the reset, leaving the controller out of reset after a failed probe. Assert the reset on those error paths. Fixes: 78b16af159ae ("spi: ma35d1-qspi: Add Nuvoton MA35D1 QSPI controller support") Signed-off-by: Li Youhong <liyouhong@kylinos.cn> Link: https://patch.msgid.link/20260901025129.359960-1-dayou5941@163.com Signed-off-by: Mark Brown <broonie@kernel.org>
6 daysspi: ingenic: release tx DMA channel when rx request failsFelix Gu
When the rx channel request fails, the driver carries on without DMA but the tx channel it already acquired stayed claimed until devm teardown. Release it on the error path so it goes straight back to the DMA engine for other users. Signed-off-by: Felix Gu <ustc.gu@gmail.com> Link: https://patch.msgid.link/20260904-ingenic-v1-1-06218181a4f8@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
6 daysspi: add support for Amlogic A9Mark Brown
Xianwei Zhao <xianwei.zhao@amlogic.com> says: Add bindings for A9 with some features, and driver for A9 base on A4. Fix the incorrect keep_ss of the last descriptor. Link: https://patch.msgid.link/20260731-a9-spisg-v3-0-a15da3f70029@amlogic.com
6 daysspi: amlogic: spisg: Add support for A9 controller featuresXianwei Zhao
The Amlogic A9 SPISG controller extends the A4 controller with additional configuration options, including: - Extended CS setup timing - Hardware-controlled CS hold timing - MOSI idle output configuration - Configurable word delay Add SoC-specific capability data and configure these features when they are supported by the underlying hardware while keeping compatibility with existing A4 controllers. Signed-off-by: Xianwei Zhao <xianwei.zhao@amlogic.com> Link: https://patch.msgid.link/20260731-a9-spisg-v3-4-a15da3f70029@amlogic.com Signed-off-by: Mark Brown <broonie@kernel.org>
6 daysspi: amlogic: spisg: Fix the incorrect keep_ss of the last descriptorSunny Luo
The driver currently unconditionally clears CFG_KEEP_SS on the last descriptor, causing the last transfer's cs_change setting to be ignored. Record the cs_change value of the last SPI transfer and use it to program CFG_KEEP_SS on the final descriptor. When a null descriptor is inserted to implement the cs-hold delay, keep CFG_KEEP_SS set on the preceding transfer descriptor and apply the recorded value to the final descriptor instead. This ensures the controller handles chip select correctly for the last transfer regardless of whether a cs-hold delay is required. Fixes: cef9991e04ae ("spi: Add Amlogic SPISG driver") Signed-off-by: Sunny Luo <sunny.luo@amlogic.com> Signed-off-by: Xianwei Zhao <xianwei.zhao@amlogic.com> Link: https://patch.msgid.link/20260731-a9-spisg-v3-3-a15da3f70029@amlogic.com Signed-off-by: Mark Brown <broonie@kernel.org>
6 daysspi: amlogic: spisg: Fix transfer size limit and timeout handlingXianwei Zhao
The CFG_BLOCK_NUM field can encode at most 20 bits, so reduce SPISG_BLOCK_MAX to 0xfffff to avoid programming a zero-length transfer. Perform the delay calculation in 64-bit arithmetic to avoid overflow when converting nanoseconds to SPI clock cycles. Stop the controller on transfer timeout by clearing the descriptor list register before returning an error. Fixes: cef9991e04ae ("spi: Add Amlogic SPISG driver") Signed-off-by: Xianwei Zhao <xianwei.zhao@amlogic.com> Link: https://patch.msgid.link/20260731-a9-spisg-v3-2-a15da3f70029@amlogic.com Signed-off-by: Mark Brown <broonie@kernel.org>
6 daysspi: qcom-geni: Add shutdown and panic notifier supportMark Brown
Praveen Talari <praveen.talari@oss.qualcomm.com> says: On VM-based platforms, if an SPI DMA transfer is in progress when the guest is torn down (via reboot/shutdown or a panic/crash), the DMA engine can keep issuing transactions to IOVAs that have already been invalidated as part of teardown. The SMMU then raises context faults, which can affect other VMs sharing the same SMMU instance and obscure the real root cause of the crash. This series adds two independent quiesce paths for the GENI SPI controller so that any in-progress transfer is stopped and the DMA engine is left idle before the IOVA mappings are torn down: - Patch 1 adds a platform shutdown() callback that suspends the SPI controller (via spi_controller_suspend()) on a normal reboot/shutdown path, where sleeping is safe. - Patch 2 registers a panic notifier that cancels/aborts the in-flight command and resets the TX/RX DMA FSMs (or terminates the GPI DMA channels) when the kernel panics, covering the crash path as well. The notifier bails out early if the device is not runtime-active or has no active command, and otherwise uses readl_poll_timeout_atomic() to poll status registers directly instead of waiting on completions/IRQs like the regular error-handling path does, since panic notifiers run with IRQs and preemption disabled. The notifier is registered before devm_spi_register_controller() so a panic during child device probing is still handled. Link: https://patch.msgid.link/20260818-add-shutdown-and-panic-notifier-for-spi-v3-0-8b62c4bc2d21@oss.qualcomm.com
6 daysspi: qcom-geni: Add panic notifier to cancel and reset DMA during panicPraveen Talari
When a VM crashes with an active SPI DMA transfer in progress, the SMMU raises context faults as the DMA engine continues to access IOVAs that are invalidated when the VM's memory context is torn down. These faults can affect other VMs sharing the same SMMU instance and obscure the root cause of the crash. Register a panic notifier that cancels (or aborts, if cancel doesn't complete) the in-flight command and resets the TX/RX DMA FSMs, so the DMA engine stops issuing transactions against invalidated IOVAs before the system halts. For GPI DMA mode, the DMA channels are terminated directly via dmaengine_terminate_async(). The notifier bails out early if the device is not runtime-active or if there's no active GENI command, avoiding unnecessary register accesses while the SE is clock-gated or idle. Since panic notifiers run with IRQs and preemption disabled, completion-based waits used by the regular error-handling path (handle_se_timeout()) cannot be reused here. Instead, the relevant status registers are polled directly with readl_poll_timeout_atomic(), which is safe to call in this context. Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com> Link: https://patch.msgid.link/20260818-add-shutdown-and-panic-notifier-for-spi-v3-2-8b62c4bc2d21@oss.qualcomm.com Signed-off-by: Mark Brown <broonie@kernel.org>
6 daysspi: qcom-geni: Add shutdown callback to quiesce hardware on rebootPraveen Talari
During system reboot, an active SPI transfer can leave the GENI Serial Engine in an indeterminate state. On VM-based platforms, if a DMA transfer is in progress when the VM is shut down, the SMMU can raise context faults as the DMA engine continues to access IOVAs that have already been invalidated during VM teardown. Add a shutdown callback to suspend the SPI controller and abort any in-progress transfer, ensuring the DMA engine is idle and all IOVA mappings are retired before the system resets. Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com> Link: https://patch.msgid.link/20260818-add-shutdown-and-panic-notifier-for-spi-v3-1-8b62c4bc2d21@oss.qualcomm.com Signed-off-by: Mark Brown <broonie@kernel.org>
10 daysspi: omap2-mcspi: Remove unbalanced pm_runtime_put_sync() callsFelix Gu
pm_runtime_put_sync() is called in the probe error path and in remove when nothing holds a runtime PM reference anymore, so it underflows the usage count. Fixes: 0e6f357a5deb ("spi: omap2-mcspi: Fix PM regression with deferred probe for pm_runtime_reinit") Signed-off-by: Felix Gu <ustc.gu@gmail.com> Link: https://patch.msgid.link/20260826-mcspi-v1-1-0a8dd7f6dd56@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
10 daysspi: qcom-geni: rename setup_fifo_params() to setup_spi_params() and make it ↵Viken Dadhaniya
void The function always returned 0 and had no error paths, so change its return type to void. Drop the now-dead ret variable and error check in spi_geni_prepare_message(). setup_fifo_params() is called for both GENI_SE_FIFO and GENI_SE_DMA modes, so the "fifo" in the name is misleading. Rename it to setup_spi_params() to better reflect its purpose of configuring SPI mode parameters (CS, CPHA, CPOL, loopback, LSB-first). No functional change. Signed-off-by: Viken Dadhaniya <viken.dadhaniya@oss.qualcomm.com> Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> Reviewed-by: Mukesh Kumar Savaliya <mukesh.savaliya@oss.qualcomm.com> Link: https://patch.msgid.link/20260824-spi-qcom-geni-cleanup-setup-fifo-params-v1-1-bdf98ae62953@oss.qualcomm.com Signed-off-by: Mark Brown <broonie@kernel.org>
10 daysspi: sunplus: handle signal interruption in transfer waitAndrew Gaylard
wait_for_completion_interruptible_timeout() returns -ERESTARTSYS when interrupted by a signal, 0 on timeout, and positive on success. The previous check was: if (!wait_for_completion_interruptible_timeout(...)) SIGKILL caused the interrupted path to fall through as if the transfer succeeded. The loop then re-entered mutex_lock() on the next iteration, which is TASK_UNINTERRUPTIBLE. The process could not be killed while blocked there. Check ret <= 0 and return -EINTR for the interrupted case so the process can exit promptly on SIGKILL. Signed-off-by: Andrew Gaylard <ag@ffroot.co.za> Link: https://patch.msgid.link/20260820125835.1584270-1-ag@ffroot.co.za Signed-off-by: Mark Brown <broonie@kernel.org>
11 daysspi: sh-msiof: propagate setup runtime-PM errorsPengpeng Hou
sh_msiof_spi_setup() ignores pm_runtime_get_sync() before programming native chip-select registers and marking the configuration initialized. Use the checked runtime-PM helper and return failure before register access. Fixes: 7ff0b53c4051 ("spi: sh-msiof: Avoid writing to registers from spi_master.setup()") Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn> Link: https://patch.msgid.link/20260830140133.24156-1-pengpeng@iscas.ac.cn Signed-off-by: Mark Brown <broonie@kernel.org>
11 daysspi: Kconfig cleanupsMark Brown
Andy Shevchenko <andriy.shevchenko@linux.intel.com> says: With time the section order is diverged, put it back into order. Link: https://patch.msgid.link/20260821105541.1432348-1-andriy.shevchenko@linux.intel.com
11 daysspi: Fix the section ordering in accordance with the commentAndy Shevchenko
The comments in all sections tell that the list of the sections should be alphabetically ordered. With time this went apart, mostly for Freescale entries. So, put the things into order again. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://patch.msgid.link/20260821105541.1432348-4-andriy.shevchenko@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
11 daysspi: Drop redundant dependency on SPI_MASTERAndy Shevchenko
The sections defined under 'if SPI_MASTER' already imply that the SPI_MASTER is selected. Drop redundant dependencies. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://patch.msgid.link/20260821105541.1432348-3-andriy.shevchenko@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
11 daysspi: Fix tab and space mixture in KconfigAndy Shevchenko
There are a couple of sections which indented using spaces and not tabs. Fix them. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://patch.msgid.link/20260821105541.1432348-2-andriy.shevchenko@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
11 daysspi: virtio: drop duplicate completion initFrancesco Valla
The completion iused for SPI transfers is initialized twice in the same function, without it being used in between. Drop the redundant initialization. Signed-off-by: Francesco Valla <francesco@valla.it> Link: https://patch.msgid.link/20260830-virtio-spi-fix-v1-1-62f486f4acdc@valla.it Signed-off-by: Mark Brown <broonie@kernel.org>
14 daysMerge tag 'spi-fix-v7.3-merge-window' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi Pull spi fixes from Mark Brown: "A couple of fixes that came in during the merge window: Geert fixed an uninitialised data bug in the amlogic-spisg driver which could crash and in the Loongson driver Li Jun hooked up the existing suspend operations more fully to fix hibernation" * tag 'spi-fix-v7.3-merge-window' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi: spi: loongson: pm: add .freeze .poweroff .thaw .restore spi: amlogic-spisg: Make sure clk_init_data is fully initialized
2026-08-20spi: loongson: pm: add .freeze .poweroff .thaw .restoreLi Jun
after execute s4, the spi error, [ 1104.754246][ 4] [ T1] tpm_tis_spi spi-SMO0768:00: SPI transfer failed: -110 [ 1104.761503][ 4] [ T1] spi_master spi1: failed to transfer one message from queue [ 1104.769201][ 4] [ T1] spi_master spi1: noqueue transfer failed [ 1104.776344][ 4] [ T1] tpm_tis_spi spi-SMO0768:00: SPI transfer failed: -110 [ 1104.783609][ 4] [ T1] spi_master spi1: failed to transfer one message from queue [ 1104.791308][ 4] [ T1] spi_master spi1: noqueue transfer failed [ 1104.797446][ 4] [ T1] gttadd tpm_chip_start1 ret = -110 and in s4 the loongson_spi_resume&suspend are not called at all. use DEFINE_SIMPLE_DEV_PM_OPS() add .freeze .poweroff .thaw .restore, after s4 the spi communication is normal. Signed-off-by: Li Jun <lijun01@kylinos.cn> Link: https://patch.msgid.link/20260820092351.101605-1-lijun01@kylinos.cn Signed-off-by: Mark Brown <broonie@kernel.org>
2026-08-20spi: amlogic-spisg: Make sure clk_init_data is fully initializedGeert Uytterhoeven
The clk_init_data structure contains several mutually-exclusive members for different methods to specify the possible parents of a clock, prompting drivers to initialize only the members they need. However, not initializing all members may cause subtle issues, which are only exposed when CONFIG_INIT_STACK_ALL_PATTERN or CONFIG_INIT_STACK_NONE is enabled. aml_spisg_clk_init() fills in init.parent_data, and assumes that init.parent_names is NULL. However, the latter in uninitialized, and thus may cause a crash. Make sure all members are fully initialized, to fix such bugs, and to avoid future breakage when converting drivers to a different method for specifying the parents. Fixes: cef9991e04aed330 ("spi: Add Amlogic SPISG driver") Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Reviewed-by: Brian Masney <bmasney@redhat.com> Reviewed-by: Xianwei Zhao <xianwei.zhao@amlogic.com> Link: https://patch.msgid.link/9fb35ae0aedb7a6db0db6c78a8193c7602dd9d44.1787165329.git.geert+renesas@glider.be Signed-off-by: Mark Brown <broonie@kernel.org>
2026-08-19Merge tag 'spi-v7.3' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi Pull spi updates from Mark Brown: "Along with a lot of driver specific work we've got a couple of core features here. The bigger one is that we've now got support for instantiating devices from sysfs similarly to how it's already done for I2C, this is used with development boards with non-enumerable expansion headers since SPI devices need to be manually specified. We also have support for the DQS signal on higher end flash devices. - Support for instantiating devices from sysfs, useful for development boards with non-enumerable plugin modules, from Vishwaroop A. - Support for DQS in spi-mem, an additional signal used by flash devices to avoid clock skew from Miquel Raynal. - Support for more advanced SPI modes on DesignWare controllers from Sudip Mukherjee. - Changes from Jisheng Zhang to update to modern methods of specifying the PM callbacks. - Fixes for DMA mapping error handling, plus KUnit tests for this, from Honghui Jiang. - Substantial cleanup and performance work in the nxp-spi driver. - Support for Microchip LAN969x, Nuvoton MA35D1 QSPI, Qualcomm SA8255p and SA8797P, and StarFive JHB100 SFC" * tag 'spi-v7.3' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi: (132 commits) spi: Add KUnit coverage for DMA mapping error paths spi: Clear current DMA devices when unmapping a message spi: Move __spi_unmap_msg() before __spi_map_msg() spi: Fix DMA mapping ownership on partial map failure spi: dt-bindings: sun6i: Add compatibles for A733's SPI controllers spi: ma35d1-qspi: Use the existing update helper spi: ma35d1-qspi: Add DTR support spi: ma35d1-qspi: Allow several command bytes spi: ma35d1-qspi: Move speed setting to bus configuration spi: ma35d1-qspi: Remove redundant reset operation spi: dw: Remove shadowed dws in dw_spi_setup() spi: img-spfi: don't disable runtime PM on DMA deferred probe spi: mtk-nor: Propagate errors from IRQ request spi: mtk-nor: Propagate errors from optional IRQ lookup spi: spi-qpic-snand: Handle Macronix quad read opcode 0x6b spi: spi-qpic-snand: add quad mode support spi: spi-qpic-snand: move command mapping helper spi: hisi-sfc-v3xx: Propagate errors from optional IRQ lookup spi: meson-spifc: use devm_pm_runtime_set_active_enabled spi: sprd-adi: Fix probe succeeding without registering the controller ...
2026-08-14spi: Fix DMA mapping ownership on partial map failureMark Brown
Honghui Jiang <jiang_hh2019@163.com> says: A partial DMA mapping failure can leave per-transfer mapping flags set while cur_{tx,rx}_dma_dev are NULL or still refer to the devices used for an earlier message. The subsequent cleanup may then unmap a transfer with a NULL or stale device. Before commit e289df82344f ("spi: Rework per message DMA mapped flag to be per transfer"), partial-failure handling was already incomplete, but __spi_unmap_msg() was gated by cur_msg_mapped, which was set only after the whole message mapped successfully. Earlier mappings could leak, but cleanup could not unmap them with an unpublished device. The per-transfer conversion removed that gate: mapping flags can now remain set while cur_{tx,rx}_dma_dev are still unpublished, turning the leak into a NULL- or stale-device unmap regression. Patch 1 publishes the mapping devices before the loop and unwinds every failure through __spi_unmap_msg(). It keeps the forward declaration so it is independently buildable and straightforward to backport. Patch 2 then removes the declaration by moving __spi_unmap_msg() above __spi_map_msg(). Patch 3 clears the current DMA device pointers once the message has been unmapped, while leaving them intact during partial-map unwind and DMA-to-PIO fallback. Patch 4 adds the DMA mapping KUnit suite as a separate translation unit. Only patch 1 is a stable candidate; patches 2 through 4 are follow-up cleanup and test changes for mainline. Testing: - Patch 1 builds independently with the x86_64 reproducer configuration. - The spi_dma KUnit suite passes all four cases on x86_64 and UML. Moving the DMA device assignments back after the mapping loop makes both failure-path cases fail. - The default and all-tests KUnit configurations both select the suite. - All four reproducer cases complete without an oops when run as the first message, and map/unmap counts are balanced after a successful first message. - After message cleanup, cur_{tx,rx}_dma_dev are NULL. v1: https://lore.kernel.org/r/20260805151456.756579-1-jiang_hh2019@163.com Link: https://patch.msgid.link/20260814031419.43378-1-jiang_hh2019@163.com
2026-08-14spi: Add KUnit coverage for DMA mapping error pathsHonghui Jiang
Add KUnit tests for the __spi_map_msg() error paths. The tests verify that a later TX or RX mapping failure clears the mapping state of earlier transfers and leaves cur_{tx,rx}_dma_dev identifying the current mapping device. A zero-length transfer causes sg_alloc_table() to return -EINVAL, providing deterministic failure injection without test hooks. Additional cases cover successful map/unmap and a message which requires no mapping. Build the DMA suite as a separate translation unit, exposing the two internal mapping helpers only for KUnit through the local internal header. Enable SPI in the default and all-tests KUnit configurations so the suite is exercised there. Signed-off-by: Honghui Jiang <jiang_hh2019@163.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://patch.msgid.link/20260814031419.43378-5-jiang_hh2019@163.com Signed-off-by: Mark Brown <broonie@kernel.org>
2026-08-14spi: Clear current DMA devices when unmapping a messageHonghui Jiang
The current DMA device pointers remain set after a message has been unmapped. Existing users either check the corresponding mapped flag or access the pointers before finalizing the message, but retaining stale device pointers is fragile. Clear both pointers in spi_unmap_msg() after the internal unmap completes. Keep them intact in __spi_unmap_msg(), since that helper is also used during partial-map unwind and the in-message DMA-to-PIO fallback, before processing of the current message is complete. Suggested-by: Andy Shevchenko <andy@kernel.org> Signed-off-by: Honghui Jiang <jiang_hh2019@163.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://patch.msgid.link/20260814031419.43378-4-jiang_hh2019@163.com Signed-off-by: Mark Brown <broonie@kernel.org>
2026-08-14spi: Move __spi_unmap_msg() before __spi_map_msg()Honghui Jiang
Move __spi_unmap_msg() above __spi_map_msg() so the mapping error path can call it without a forward declaration. This is a code-only relocation with no functional change. Suggested-by: Andy Shevchenko <andy@kernel.org> Signed-off-by: Honghui Jiang <jiang_hh2019@163.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://patch.msgid.link/20260814031419.43378-3-jiang_hh2019@163.com Signed-off-by: Mark Brown <broonie@kernel.org>
2026-08-14spi: Fix DMA mapping ownership on partial map failureHonghui Jiang
If RX mapping fails after TX mapping succeeds, __spi_map_msg() unmaps TX but leaves tx_sg_mapped set. If TX mapping fails on a later transfer, mappings created for earlier transfers remain active. In both cases, cur_{tx,rx}_dma_dev have not yet been updated because they are assigned only after every transfer has been mapped. The subsequent spi_unmap_msg() may therefore unmap the TX mapping again or release earlier mappings using a NULL or stale device. Using a NULL device can trigger an oops. An empty SG table does not prevent the NULL dereference because dma_unmap_sg_attrs() accesses the device before checking the entry count. Publish both mapping devices before mapping starts and unwind all failures through __spi_unmap_msg(). This clears the mapping flags and releases each mapping once with the device that created it. Publishing the devices before the loop also refreshes them when no transfer needs mapping. No mapping flag is set in that case, so current users do not use the pointers as mapping owners. Fixes: e289df82344f ("spi: Rework per message DMA mapped flag to be per transfer") Cc: stable@vger.kernel.org Signed-off-by: Honghui Jiang <jiang_hh2019@163.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://patch.msgid.link/20260814031419.43378-2-jiang_hh2019@163.com Signed-off-by: Mark Brown <broonie@kernel.org>
2026-08-14spi: ma35d1-qspi: Improvements and DTR supportMark Brown
Miquel Raynal <miquel.raynal@bootlin.com> says: I am in possession of an MA35D1 NuMaker board. The SPI controller has been contributed, but: 1- it lacks a DT descriptions [1] 2- it does not work with current clock driver [2] 3- it can be improved Link: https://lore.kernel.org/linux-arm-kernel/20260813-perso-ma35d1-upstream-dts-v1-0-bb237fd7c3c2@bootlin.com [1] Link: https://lore.kernel.org/linux-clk/20260813-perso-ma35d1-upstream-clk-v1-1-e78e5e6172ea@bootlin.com [2] This series is addressing #3 by: - reusing existing helpers - refactoring a bit the code - adding DTR support Link: https://patch.msgid.link/20260813-perso-ma35d1-upstream-qspi-v1-0-b217b9870eb1@bootlin.com
2026-08-14spi: ma35d1-qspi: Use the existing update helperMiquel Raynal
Read modify writes are already covered by a local helper, so use it. No functional change. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://patch.msgid.link/20260813-perso-ma35d1-upstream-qspi-v1-5-b217b9870eb1@bootlin.com Signed-off-by: Mark Brown <broonie@kernel.org>
2026-08-14spi: ma35d1-qspi: Add DTR supportMiquel Raynal
The controller has DTR support, a bit must be set for it. The behaviour is interesting though, as the speed won't improve when enabled. This is because there seems to be an internal divisor (/2) which keeps the rate equal when DTR is enabled. As a result, this commit also doubles the target bus speed, which in practice does not happen. This way, there is a real gain: Before: $ flash_speed /dev/mtd0 -dc10 eraseblock write speed is 1000 KiB/s [...] eraseblock read speed is 1199 KiB/s [...] After: $ flash_speed /dev/mtd0 -dc10 eraseblock write speed is 985 KiB/s [...] eraseblock read speed is 1540 KiB/s [...] Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://patch.msgid.link/20260813-perso-ma35d1-upstream-qspi-v1-4-b217b9870eb1@bootlin.com Signed-off-by: Mark Brown <broonie@kernel.org>
2026-08-14spi: ma35d1-qspi: Allow several command bytesMiquel Raynal
The controller is capable of sending several bytes for the command, it does not even know this is a command. Just mimic the address steps here to allow double byte commands, which may be needed for DTR support. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://patch.msgid.link/20260813-perso-ma35d1-upstream-qspi-v1-3-b217b9870eb1@bootlin.com Signed-off-by: Mark Brown <broonie@kernel.org>
2026-08-14spi: ma35d1-qspi: Move speed setting to bus configurationMiquel Raynal
The speed setting is wrongly placed inside the "setup transfer" helper, since the bus configuration may require the speed to be correct. Indeed, DTR mode (not yet available) divides by 2 the bus clock when enabled. As a result, to remain at a constant clock speed (and improve the data rate), we must double the bus clock when enabling DTR. In order to prepare for this change, move all the bus configuration required for each step of the operation inside a unique helper called nuvoton_qspi_configure_bus(). Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://patch.msgid.link/20260813-perso-ma35d1-upstream-qspi-v1-2-b217b9870eb1@bootlin.com Signed-off-by: Mark Brown <broonie@kernel.org>
2026-08-14spi: ma35d1-qspi: Remove redundant reset operationMiquel Raynal
The bus width is always set before every operation, no need to reset it manually at the end of each transfer. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://patch.msgid.link/20260813-perso-ma35d1-upstream-qspi-v1-1-b217b9870eb1@bootlin.com Signed-off-by: Mark Brown <broonie@kernel.org>
2026-08-14spi: dw: Remove shadowed dws in dw_spi_setup()Liang Hao
The controller private data is already fetched at the start of dw_spi_setup(). Drop the redundant inner declaration that shadows it. Signed-off-by: Liang Hao <haohlliang@gmail.com> Link: https://patch.msgid.link/20260814114235.31281-1-haohlliang@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
2026-08-13spi: virtio: mark device ready before registering the controllerJasper Wise
virtio_spi_probe() registers the SPI controller with devm_spi_register_controller(). spi_register_controller() binds a child inline unless its driver has asked for asynchronous probing, so a peripheral that performs a transfer during its own probe reaches virtio_spi_transfer_one(), which kicks the virtqueue before probe has returned. The driver never calls virtio_device_ready(), so DRIVER_OK is set on its behalf by virtio_dev_probe(), only once probe has returned. The virtio spec is explicit about that ordering in 3.1 Device Initialization: | The driver MUST NOT send any buffer available notifications to the | device before setting DRIVER_OK. A device that waits for DRIVER_OK before servicing the queue therefore leaves the transfer unanswered, and virtio_spi_transfer_one() waits for its completion with no timeout, so probe never returns. Mark the device ready before registering the controller, as done for the same reason in commit f5866db64f34 ("virtio_console: enable VQs early") and commit 1d774589f924 ("i2c: virtio: mark device ready before registering the adapter"). Fixes: f98cabe3f6cf ("SPI: Add virtio SPI driver") Signed-off-by: Jasper Wise <jaspwise@amazon.co.uk> Link: https://patch.msgid.link/20260813084618.613172-1-jaspwise@amazon.co.uk Signed-off-by: Mark Brown <broonie@kernel.org>
2026-08-12spi: img-spfi: don't disable runtime PM on DMA deferred probeFelix Gu
When dma_request_chan() returns -EPROBE_DEFER, the error path jumps to disable_pm and calls pm_runtime_disable() even though pm_runtime_enable() was never called, leaving disable_depth unbalanced and the device permanently PM-disabled. Route the defer path through free_dma to skip pm_runtime_disable(). Fixes: 6bfbf4d0aa0c ("spi: img-spfi: Use dma_request_chan() instead dma_request_slave_channel()") Signed-off-by: Felix Gu <ustc.gu@gmail.com> Link: https://patch.msgid.link/20260808-spfi-v1-1-6bc4345be430@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
2026-08-12spi: mtk-nor: Propagate errors from IRQ requestbui duc phuc
Treat a failure from devm_request_irq() as a probe error instead of continuing without an IRQ after only reporting a warning. Return the error through the existing error path to ensure the driver does not continue with an unsuccessfully requested IRQ. Signed-off-by: bui duc phuc <phucduc.bui@gmail.com> Link: https://patch.msgid.link/20260807102932.45785-2-phucduc.bui@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
2026-08-12spi: mtk-nor: Propagate errors from optional IRQ lookupbui duc phuc
platform_get_irq_optional() returns a positive IRQ number on success or a negative error code on failure. For an optional IRQ, -ENXIO indicates that no IRQ is available, while other errors should be propagated. Propagate errors such as -EPROBE_DEFER and -EINVAL instead of continuing probe without the IRQ. Signed-off-by: bui duc phuc <phucduc.bui@gmail.com> Link: https://patch.msgid.link/20260807102932.45785-1-phucduc.bui@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
2026-08-11Add quad mode support for QPIC SNANDMark Brown
Md Sadre Alam <md.alam@oss.qualcomm.com> says: The Qualcomm QPIC SPI-NAND controller supports both single (x1) and quad (x4) transfer modes, however the current driver operates only in single-bit mode. This series adds support for quad data transfers and includes a vendor-specific fix required for Macronix SPI-NAND devices. Link: https://patch.msgid.link/20260807-quad-v2-0-8ec821e2f22b@oss.qualcomm.com
2026-08-11spi: spi-qpic-snand: Handle Macronix quad read opcode 0x6bMd Sadre Alam
Macronix SPI-NAND devices use opcode 0x6b for quad output cache reads, while most other devices use opcode 0xeb. The QPIC SPI-NAND driver does not currently recognize opcode 0x6b, causing read operations to fail when Macronix devices select this cache read variant. Add the Macronix-specific read opcode to the command mapping logic and treat it the same as the existing quad read operations. This allows Macronix SPI-NAND devices to operate correctly in quad read mode. Signed-off-by: Md Sadre Alam <md.alam@oss.qualcomm.com> Link: https://patch.msgid.link/20260807-quad-v2-3-8ec821e2f22b@oss.qualcomm.com Signed-off-by: Mark Brown <broonie@kernel.org>
2026-08-11spi: spi-qpic-snand: add quad mode supportMd Sadre Alam
Add support for quad (x4) transfer mode in the QPIC SPI NAND driver. The controller supports both single (x1) and quad (x4) SPI transfers, but the driver currently operates only in x1 mode. Track the QUAD enable state from the device configuration register (0xB0) and switch the data transfer width accordingly. When the core enables quad mode, use x4 transfers for read and program operations to improve throughput. Introduce a quad_mode flag in struct qpic_spi_nand to cache the current device state. The flag is updated based on GET_FEATURE responses from the configuration register. Signed-off-by: Md Sadre Alam <md.alam@oss.qualcomm.com> Link: https://patch.msgid.link/20260807-quad-v2-2-8ec821e2f22b@oss.qualcomm.com Signed-off-by: Mark Brown <broonie@kernel.org>
2026-08-11spi: spi-qpic-snand: move command mapping helperMd Sadre Alam
Move qcom_spi_cmd_mapping() above qcom_spi_read_page() so it can be used by read path changes added in a subsequent patch. No functional change. Signed-off-by: Md Sadre Alam <md.alam@oss.qualcomm.com> Link: https://patch.msgid.link/20260807-quad-v2-1-8ec821e2f22b@oss.qualcomm.com Signed-off-by: Mark Brown <broonie@kernel.org>