Commit graph zephyr/drivers/spi
Author SHA1 Message Date
Bjarki Arge Andreasen
c7b21a904f drivers: spi: nrfx_spim: clear cs before suspend
Clear CS before suspending the SPIM device to ensure SCK remains
stable until CS is cleared. Suspending the SPIM device can result in
SCK changing state which a child device may see as a spurious clock.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
2026-10-28 22:49:28 -04:00
Benjamin Cabé
4c2013ccdb drivers: spi: stm32: log the frequency set by the prescaler
When the prescaler bypass is not available, the prescaler table starts
at a division by 2 and the table index is offset by shift, since commit
a0ffee2b92 ("drivers: spi: stm32: add support for baudrate prescaler
bypass"). The debug message of spi_stm32_configure() ignored this offset
and reported twice the actual frequency and half the divider.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5.5
2026-10-28 22:44:47 -04:00
Camille BAUD
85674fcbe2 drivers: spi: Enable BL808 SPI
Enable SPI on BL808

Signed-off-by: Camille BAUD <mail@massdriver.space>
2026-10-28 22:42:49 -04:00
Adrien Lessard
1ba5543730 drivers: spi: stm32: make DMA support depend on a dmas property
With CONFIG_SPI_STM32_DMA=y and no enabled SPI node with a dmas
property, dma_callback() is never referenced and the build emits a
-Wunused-function warning. DMA support is useless without a DMA
channel, so make SPI_STM32_DMA depend on an enabled st,stm32-spi node
having a dmas property.

Assisted-by: Claude:claude-opus-5.5
Signed-off-by: Adrien Lessard <adrien.lessard@rbr-global.com>
2026-10-28 22:42:16 -04:00
Takumi Ando
214339b069 drivers: spi: xlnx_zynqmp_gqspi: Fix baud-rate divisor updates
The divisor mask is unshifted, so clearing it affects bits 2:0 rather
than bits 5:3 of GQSPI_CFG. Old divisor bits remain set and are ORed
with the new value when changing the SPI frequency.

With a 300 MHz reference clock, switching requests from 40 MHz to
5 MHz and back leaves the clock at 1.171875 MHz instead of 37.5 MHz.
Shift the mask before clearing the divisor field.

Assisted-by: Codex:GPT-6
Signed-off-by: Takumi Ando <takumi@spacecubics.com>
2026-10-28 22:42:06 -04:00
Benjamin Cabé
569192b7d3 drivers: spi: sam0: skip the receive DMA channel for TX-only transfers
The DMA path always ran a receive channel next to the transmit one,
only to know when the last byte had been shifted out. For write-only
transfers, such as display pixel data, that doubles the DMA traffic and
the SERCOM DATA accesses through the peripheral bridge, which limits the
throughput at high bus clocks.

When there is nothing to receive, turn the receiver off, run the
transmit channel alone and, once it has loaded the last byte, wait for
INTFLAG.TXC, at most two byte times, before releasing chip select. The
receiver is turned back on before completing, which also flushes it, so
the other paths are unchanged.

On a Wio Terminal driving its ILI9341 at 60 MHz, a renderer streaming
about 150 KB per frame went from 29 to 35 fps, its wait for the display
going from 10 ms to 5 ms per frame.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-10-28 22:36:39 -04:00
Hashimoto Kenichi
0abbceee51 drivers: spi: lpspi: mask the receive data for transmit-only DMA transfers
A transfer with no receive buffer still runs the receive DMA, which
moves every received word out of the FIFO only for it to be discarded.
Set TCR[RXMSK] instead, which the reference manual suggests for
half-duplex transfers, and do not start the receive DMA. With receive
masked there is no receive callback, so each transmit callback moves on
to the next chunk by itself and the last one completes the transfer.
That relies on the previous commit: the transmit DMA finishes before the
last word has left the shift register.

Mask only when no buffer in the receive set passed in takes data. NULL
receive buffers are still consumed alongside the transmit data, so the
transfer clocks as many words as it would unmasked. A peripheral keeps
the receive DMA, since completing from the transmit side would not wait
for the controller to clock the data out.

Measured on an i.MX RT1176 driving an ST7789 through MIPI DBI SPI on
v4.4.2, with this series and the board's local Ethernet patches
applied, drawing 76x284 frames row by row while the board receives TCP
continuously on the 1G port, in 10 s windows:

  without this change   8 windows, 198 to 200 frames, 50.3 ms per frame
  with it              14 windows, 202 to 239 frames (median 222),
                       45.1 ms per frame on average

A frame is about 10% shorter on average. With the change the frame time
varies from window to window; without it, it hardly moves.

No transfer timed out in either case. On an earlier tree the unmasked
receive FIFO overflowed under load, SR[REF] ended the transfer and the
caller got -ETIMEDOUT, since the driver does not look at REF; that did
not reproduce here.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Hashimoto Kenichi <hashimoto.kenichi@genetec.co.jp>
2026-10-28 22:36:02 -04:00
Hashimoto Kenichi
354d870a2e drivers: spi: lpspi: finish with the bus before releasing CS and completing
Draining the TX FIFO does not mean the transfer is over: the last word
is still in the shift register when the FIFO reports empty. Poll SR[MBF]
as well, using the same cycle limit as lpspi_wait_tx_fifo_empty().

Release the chip select before spi_context_complete() rather than after,
on both the success and the error path. That call wakes the waiting
thread, or for an asynchronous transfer runs the user callback in
interrupt context; either may start the next transfer, which would then
be deselected. For an asynchronous transfer the callback is also the
only place the chip select is released, since the check after
spi_context_wait_for_completion() never runs.

A transfer usually completes from the receive DMA callback, and the last
received word only lands once it has been shifted in, so the bus is
already idle by then. The next commit completes transmit-only transfers
from the transmit DMA callback instead, which fires while the last word
is still going out; it depends on this one.

The transmit callback can also be serviced after the last receive one,
when both are pending and the receive one is taken first. That path
completed the transfer without the TCR that ends the continuous frame,
so a hardware chip select stayed asserted and SR[MBF] stayed set. Issue
it there as well.

A timeout in the wait is reported to the caller as -EIO. The wait is
skipped in peripheral mode, where SR[MBF] follows the chip select driven
by the controller, and when SPI_HOLD_ON_CS keeps the frame open on
LPSPI version 2.

Measured on an i.MX RT1176 driving an ST7789 through MIPI DBI SPI on
v4.4.2, with the next commit applied and this one removed (SCK at 1 MHz):

- With a GPIO chip select, 150 of 609 clocks during panel init went out
  with CS deasserted. The panel never left sleep and stayed blank.
- With hardware PCS0, DC changed before the last bit of each transfer,
  so the panel latched the last byte of every parameter phase as a
  command. The image came up colour-inverted: the low byte of a RASET
  row number had been executed as INVON (0x21).

With both commits applied, both configurations draw the test pattern
correctly. With neither, they do as well.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Hashimoto Kenichi <hashimoto.kenichi@genetec.co.jp>
2026-10-28 22:36:02 -04:00
Ryomei Osaki
4c1cb39059 drivers: spi: use spi_context_clear_completion()
Replace the open-coded semaphore/ready-flag resets in spi_nrfx_spi,
spi_cdns, spi_ambiq_spic and spi_mcux_ecspi with the new helper. For
spi_cdns and spi_ambiq_spic this also covers the !CONFIG_MULTITHREADING
path, which previously did not compile because struct spi_context has no
sync member there.

No functional change with CONFIG_MULTITHREADING.

Signed-off-by: Ryomei Osaki <o.ryomei1020@gmail.com>
2026-10-28 22:32:42 -04:00
Ryomei Osaki
17f1397e4e drivers: spi: spi_context: add spi_context_clear_completion()
A driver that gives up on a transfer, typically after
spi_context_wait_for_completion() timed out and the transfer was
aborted, has to discard the completion a late interrupt may still
signal; otherwise the stale signal satisfies the next transfer's wait
immediately.

The signal lives in ctx->sync with CONFIG_MULTITHREADING and in
ctx->ready without it, so every driver had to open-code the #ifdef, and
some reset only the semaphore.

Add spi_context_clear_completion() to hide this, next to
spi_context_wait_for_completion() and spi_context_complete().

Signed-off-by: Ryomei Osaki <o.ryomei1020@gmail.com>
2026-10-28 22:32:42 -04:00
Benjamin Cabé
b70dbaf045 drivers: spi: esp32: drop unused SPI_MASTER_FREQ_* macros
Nothing uses them; removing them also drops non-inclusive terminology
from the driver.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5.5
2026-10-22 09:44:52 +02:00
Priyanshu Singh
e60b8649ad spi: rtio: transparent scratch buffer for discard read operations
When decomposing asymmetric SPI transceive buffers where rx_buf is NULL
(discard buffer), unconditional pointer arithmetic (rx_buf += len)
corrupted NULL into an invalid address (e.g. 0x00000003), causing
BusFaults. Furthermore, passing NULL rx buffers directly down to driver
DMA engines risks vector table corruption or controller hangs.

Introduce CONFIG_SPI_RTIO_SCRATCH_BUF_SIZE (default 32 bytes) and route
discard/dummy reads into an internal scratch bit-bucket buffer within
spi_rtio_copy(), chunking larger reads to keep DMA transfers bounded.
Guard all buffer pointer advancements against NULL, and flatten the
tx_len == rx_len branching structure.

Fixes #108313

Signed-off-by: Priyanshu Singh <singhpriyanshu9838@gmail.com>
2026-10-22 09:37:44 +02:00
Marvin Gnad
25a1095167 drivers: spi: mcux_ecspi: send several frames in one burst
The driver left BURST_LENGTH at the word size and put one frame in each
burst, so a burst carried 8 of the 32 bits a Tx FIFO word holds and cost
an interrupt of its own. A burst is also the controller's chip-select
window, so on the native chip select the CS framed single frames and
dropped in between, which no device expecting a held chip select can use.

Set the burst length per transfer and pack as many frames as fit into the
FIFO word the transfer already writes. A chip-select window now spans up
to 32 bits and raises one interrupt. Any word size up to 32 bits packs,
the frames becoming fields of that word. Longer transfers still split
into 32-bit bursts; spreading a burst over several FIFO words needs a
different alignment rule and is left to a follow-up.

Each frame is masked to the word size on its way into a field, keeping a
caller's spare container bits out of the neighbouring frame; on receive
those bits are now zero where they previously held whatever the received
word carried above the frame width. The frames of a burst also go out
back to back, where each used to be separated by the inter-burst delay:
word_delay is not implemented here, and implementing it would need
PERIODREG and one frame per burst again.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Marvin Gnad <marvin.gnad@gmail.com>
2026-10-21 15:05:23 -05:00
Marvin Gnad
e74fa6f042 drivers: spi: mcux_ecspi: extract the frame accessors
Each direction picks its load or store width from the data frame
size with a switch of its own, inline where the frame is moved.
Give each direction a helper instead, so that moving more than one
frame does not nest a switch inside a loop.

No functional change intended.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Marvin Gnad <marvin.gnad@gmail.com>
2026-10-21 15:05:23 -05:00
Benjamin Cabé
a2d3b72cc1 drivers: spi: shell: drive the CS GPIO set with spi cs
spi_cs_is_gpio() checks the cs_is_gpio flag of the configuration since
commit a60f93d742 ("include: drivers: spi.h: Get CS delay parameters
from DT"), and the spi cs command never set it, so the chip select was
left inactive during spi transceive. Set the flag along with the GPIO.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5.5
2026-10-21 13:47:12 +02:00
Bjarki Arge Andreasen
1debf63ba7 drivers: spi: spi_nrfx_spim_rtio: clear CS on end txn
When a transaction ends, CS must be cleared if SPI_HOLD_ON_CS is
not set, before the next transaction starts. Currently CS is only
cleared if there is no pending transaction.

Update iodev_end_txn() to clear CS if not SPI_HOLD_ON_CS, regardless
of whether a transaction is pending.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
2026-10-21 11:45:52 +02:00
Guillaume Gautier
da22fbbda2 drivers: spi: stm32: make sure eot/dxp are disabled before transfer start
Disable the EOT and DXP interrupt before starting a transfer.
This is re-added here to solve #122018.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2026-10-20 17:31:31 +02:00
Benjamin Cabé
0dea497165 drivers: spi: esp32: do not insert timing dummy cycles in every transfer
spi_hal_setup_trans() already adds timing_conf.timing_dummy, the MISO
compensation for the GPIO matrix delay, to half-duplex reads unless
no_compensate is set. Copying it into trans_config.dummy_bits as well
inserted these dummy cycles before every transfer, shifting written
data, and applied them twice on half-duplex reads. Leave dummy_bits at
zero and let the HAL apply the compensation, as ESP-IDF does.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-10-20 17:25:12 +02:00
Sylvio Alves
42984ac4bb drivers: spi: esp32: do not drive mosi on half-duplex reads
In half-duplex mode the write phase runs before the read phase.
The driver enabled the write phase for every chunk that receives
data, through the zero-filled TX buffer on DMA transfers and the
MOSI enable on CPU transfers. Read-only chunks then clocked out
zeros before the read, and the input delay compensation dummy
cycles landed before that write phase instead of the read.

Enable the write phase only when there is data to send, or when
receiving in full-duplex mode.

Assisted-by: Claude:opus-5
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2026-10-19 16:30:52 +02:00
Prathamesh Sachin Sapkal
54ccbb177d drivers: spi: nxp_kinetis_l: reject unreachable bus frequency
While reading spi_nxp_kinetis_l_configure() I noticed what happens when
the requested frequency is lower than the slowest the SPI block can
generate (module clock / 4096). The divisor loop only accepts values
that do not exceed the request, so nothing gets picked and
best_sppr/best_spr stay at their initial 0. That is the fastest
setting, divide by 2, so asking for 1 kHz on a 24 MHz clock ends up
running at 12 MHz, and configure() still returns 0.

Run the divisor search first, before any register is written, and
return -EINVAL if no divisor fits, like spi_cc13xx_cc26xx does for the
frequencies it can't generate. Requests the hardware can meet get the
same divisor as before. A requested frequency of 0 is now rejected too.

I don't have an FRDM-KL25Z, so this is not tested on hardware. I
checked the loop on a PC with a small standalone program for 24 MHz and
48 MHz clocks: same result as before for every reachable frequency, and
-EINVAL for the ones below the limit.

Assisted-by: Claude:claude-sonnet-5-5
Signed-off-by: Prathamesh Sachin Sapkal <prathameshssapkal@gmail.com>
2026-10-15 14:23:30 +02:00
Hashimoto Kenichi
70a559efb2 drivers: spi: lpspi: maintain the D-cache around DMA transfers
eDMA is not coherent with the D-cache and nothing else in the path does
cache maintenance. A TX buffer in cached RAM is still in the D-cache
when the DMA reads main memory, so the peripheral transmits whatever RAM
held beforehand: zeroes for a .bss buffer, stale bytes for one on the
stack. The transfer reports success either way.

Clean the TX buffers before starting and clean-and-invalidate the RX
buffers from the completion callback. The invalidate cannot go after
spi_context_wait_for_completion(), which does not wait for an
asynchronous transfer.

RX is cleaned as well as invalidated so that a plain invalidate cannot
discard dirty bytes a neighbour owns. Note this does not make the
partial lines at the two ends safe either way; only a buffer aligned to
and padded out to the cache line size avoids both hazards. Fixing that
in general needs a bounce buffer and a copy on every transfer.

Fixes: #81125

Assisted-by: Claude:claude-opus-5
Signed-off-by: Hashimoto Kenichi <hashimoto.kenichi@genetec.co.jp>
2026-10-15 14:08:28 +02:00
Bas van Loon
8422c6110c drivers: spi: lpspi: Adhere to maximum allowable SCK frequency.
The current implementation does not follow the LPSPI SCK frequency
restriction. Update the driver to cap the max. frequency which is
allowed for the LPSPI peripheral.

Signed-off-by: Bas van Loon <bas@arch-embedded.com>
2026-10-14 13:44:30 +02:00
Bas van Loon
bcccfcae95 drivers: spi: lpspi: Work around errata ERR051472.
ERR051472:
 The SR[REF] would assert if software disables
 the LPSPI module after receiving some data and
 then enabled the LPSPI again without performing
 a software reset.

Clear SR[REF] flag after LPSPI module enabled.

Signed-off-by: Bas van Loon <bas@arch-embedded.com>
2026-10-14 13:44:30 +02:00
Bas van Loon
0f58cf764b drivers: spi: lpspi: Work around errata ERR050606.
The RT1170 has a bug that causes it to not always read back
the current real value of the TCR register. To work around
the issue, we read another register in between as mentioned
in the errata sheet and check if the value has been updated.

Signed-off-by: Bas van Loon <bas@arch-embedded.com>
2026-10-14 13:44:30 +02:00
Pisit Sawangvonganan
8eaf92f312 drivers: {sensor, serial, spi, tee, usb, usb_c}: fix typo
Utilize a code spell-checking tool to scan for and correct spelling errors
in all files within:
- `drivers/sensor`
- `drivers/serial`
- `drivers/spi`
- `drivers/tee`
- `drivers/usb`
- `drivers/usb_c`

Assisted-by: Claude:claude-sonnet-5-5 codespell
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2026-10-13 17:06:54 +02:00
Guillaume Gautier
ef37420fe3 drivers: spi: stm32: disable interrupts before transfer start
Move the disabling of interrupts from the transceive function to the
spi_stm32_msg_start function to also cover RTIO case.

This change fixes an issue seen on WBA with RTIO: with a short transfer
(1 byte), the EOT interrupt would be raised as soon as the data was sent,
leaving no time to decrease the internal tx_len. The driver was then unable
to properly complete the transaction.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2026-10-08 08:04:20 +02:00
Benjamin Cabé
34b6eca8ba drivers: spi: esp32: fail on unsupported clock configuration
spi_hal_cal_clock_conf() fails without writing the timing configuration
when a full-duplex transfer routed through the GPIO matrix would need
dummy cycle compensation, e.g. at 40 MHz on the ESP32. The result was
ignored, so transfers silently went out with a stale clock setting.

Fail with -ENOTSUP and an error message instead, and clear the cached
configuration so that the next transfer does not skip the check.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-10-07 05:05:25 +02:00
Pisit Sawangvonganan
82eb2b07da drivers: spi: infineon: drop dead spiMode branch in set_frequency
The SCB reinit block in spi_set_frequency() only runs when
data->is_peripheral is false, so the spiMode ternary always evaluated
to CY_SCB_SPI_MASTER. Assign CY_SCB_SPI_MASTER directly.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2026-09-30 12:52:22 +02:00
Pisit Sawangvonganan
f6aca4e87a drivers: spi: infineon: reuse oversampled_freq in divider search
`ifx_cat1_spi_int_frequency()` stores `(hz * oversample_value)` in
`oversampled_freq` at the top of each loop iteration, but the range
checks and the divider calculation recompute the product. Use the
stored value instead.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2026-09-30 12:52:22 +02:00
Duc Bui
a5be3574d0 drivers: spi: renesas: Initialize p_reg in extended configuration
Initialize p_reg with the register base address from devicetree.
Add an explicit `(void *)` cast when assigning the const device pointer to
the FSP context field to avoid the build warning.

Signed-off-by: Duc Bui <duc.bui.vt@bp.renesas.com>
Signed-off-by: Tien Nguyen <tien.nguyen.zg@renesas.com>
2026-09-28 14:32:02 -04:00
Manimaran A
13b980838e drivers: spi: xec: restrict QMSPI access when TAF is enabled
eSPI TAF takes exclusive ownership of the QMSPI controller when
enabled. The transceive and release paths already reject requests
in that case; extend the same check to the PM action callback so
suspend/resume/turn on/off do not touch registers TAF is using.

Signed-off-by: Manimaran A <manimaran.a@microchip.com>
2026-09-28 14:31:22 -04:00
Guillaume Gautier
d713a3253a drivers: spi: stm32: Enable EOT interrupts after sending first data
Enable EOT interrupts after finishing filling the TxFIFO. Otherwise, the
interrupt can be triggered before the tx_len data is decremented, which
leads to a stall.
Also explicitly disable the EOT before starting the transfer.
It solves an issue seen on WBA with the spi_loopback test.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2026-09-24 12:03:09 +02:00
Guillaume Gautier
80c360e2a2 drivers: spi: stm32: abstract H7-specific transfer operations
Add helper functions for transfer size, FIFO-related interrupts, and
status flags so the SPI driver can use a common workflow across STM32
series. These new helpers are empty (or return 0) for non-H7 variants.

This allows removing a bunch of preprocessor guards, making the driver
code more easily readable.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2026-09-24 12:03:09 +02:00
Guillaume Gautier
ae63a875a8 drivers: spi: stm32: Use IS_ENABLED instead of #ifdef for interrupts
Use the IS_ENABLED macro instead of #ifdef for CONFIG_SPI_STM32_INTERRUPT
when possible.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2026-09-24 12:03:09 +02:00
Guillaume Gautier
b002128532 drivers: spi: stm32: read RxFIFO before filling TxFIFO
Rework FIFO handling for full- and half-duplex transfers to prevent
RxFIFO overruns. Read pending RX data before sending new TX data and
drain the RxFIFO at end of transfer.

Use explicit equality checks for each transfer direction to make the
FIFO handling workflow clearer.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2026-09-24 12:03:09 +02:00
Guillaume Gautier
5e79ef4a04 drivers: spi: stm32: H7-like: fallback to non-FIFO mode
For H7-like devices, it is possible to set the SPI size transfer prior to
starting the communication. It is useful to increase performance,
especially when combined with the use of the FIFO threshold.
But this size is limited and can't be arbitrarily high (depending on SoCs
and SPI instances, it is typically either 65535 or 1023).
When the transfer size exceeds this limit, the driver now automatically
fallback to the unlimited transfer option instead of returning an error.

Although performance are inferior in this case, at least the transfer
takes place.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2026-09-24 12:03:09 +02:00
Guillaume Gautier
d719bb4c67 drivers: spi: stm32h7: seed one initial frame at transfer start
For H7-devices in full-duplex master mode, seed one initial SPI frame at
transfer start instead of relying on the TXP flag only for the first
transfer. Now only DXP and EOT flag are used (in both polling and IT).

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2026-09-24 12:03:09 +02:00
Guillaume Gautier
a680d22aa5 drivers: spi: stm32: dma fallback to it/polling when buffers are cached
In the STM32 SPI driver, buffers in cache are not supported in DMA mode.
Instead of returning an error in such cases, fallback to interrupt or
polling mode so that the transfer still takes place.
Replace the error message by a warning.

Also move the asynchronous check after the cache one to avoid falling
back to polling mode while in asynchronous mode.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2026-09-24 12:03:09 +02:00
Quang Le
d4f4923008 drivers: spi: Add support DMA support for SPI on RZ/A3UL
- Add DMA support for SPI on RZ/A3UL since the previously supported
  had not supported DMA.

Signed-off-by: Quang Le <quang.le.eb@bp.renesas.com>
Signed-off-by: Tien Nguyen <tien.nguyen.zg@renesas.com>
2026-09-24 09:52:01 +02:00
Guillaume Gautier
be2ca806d9 include: drivers: dma: stm32: remove slot argument from dma macro
The slot argument from macros STM32_DT_INST_DMA_SLOT* was useless.
With it the macro was basically a redefinition a the Zephyr macro.
It is now removed to be similar to other STM32 DMA macros that call
DT_INST_DMAS_CELL_BY_NAME.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2026-09-22 17:56:13 +02:00
Guillaume Gautier
89a0b76898 include: drivers: dma: stm32: rename macros with DT_INST for consistency
Typically Zephyr device tree macros that take a inst as argument
start with DT_INST_.
For the STM32 DMA driver we currently have several macros taking an inst as
argument but missing this prefix.
For consistency, it is added to these macros. The goal is to also define
DT_ variants of these macros that take a node_id as argument.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2026-09-22 17:56:13 +02:00
Ryomei Osaki
68795ea4fd drivers: spi: spi_mcux_ecspi: abort transfer on completion timeout
When spi_context_wait_for_completion() times out, the SDK transfer
handle is left busy and every later transfer on the bus fails with
kStatus_ECSPI_Busy until reboot.

Abort the transfer and deassert the chip select on error so the bus
recovers, as spi_nrfx_spim already does on -ETIMEDOUT.

ECSPI_MasterTransferHandleIRQ() does not check the handle state, so a
completion interrupt latched just before the abort would still run the
callback, start the next word and signal the context again. Disarm the
callback with a flag before aborting, with interrupts locked so the ISR
cannot interleave with the abort, and clear the completion signal
(ctx.sync, or ctx.ready without CONFIG_MULTITHREADING) to drop a
completion that raced in before the flag was set.

Signed-off-by: Ryomei Osaki <o.ryomei1020@gmail.com>
2026-09-21 11:26:40 +01:00
Jonas Berg
2e86988809 drivers: spi: stm32: Enable control of SPI pins when peripheral is idle
The SDO pin (previously known as MOSI) of the STM32 SPI controller is
floating when the SPI is idle. As we use a pull-up on that pin (it is
used as a multi-function pin), this causes an idle-high voltage
on the SDO pin. We use the SDO pin for control of WS2812 LEDs, and they
require an idle-low voltage.

Add a devicetree setting 'st,gpio-control' so the SPI controller keeps
control of the SDO pin also between transmissions.
This enables the AFCNTR bit in the STM32 SPI controller, via the
LL_SPI_EnableGPIOControl() HAL function.

The functionality is available for SPI in STM32H7, STM32H5, STM32C5
and some other series: all that rely on "st,stm32h7-spi"
DT compatible ID.

Tested on STM32H562.

Signed-off-by: Jonas Berg <jonas.berg@voiapp.io>
2026-09-19 10:29:58 +02:00
Bill Waters
08e757eb13 drivers: spi: spi_infineon_pdl: add device_deinit hook
Add an ifx_cat1_spi_deinit() implementation and register it via
SPI_DEVICE_DT_INST_DEINIT_DEFINE so device_deinit(dev) succeeds on the
Infineon PSE84 / CAT1 SCB SPI driver. Without this hook the upstream
tests/drivers/spi/spi_loopback test_spi_deinit case returns -ENOTSUP and
skips.

The deinit:
- returns -EBUSY while a transfer is still in flight, to avoid tearing
  down the SCB block in the middle of a transaction. The busy check is
  consolidated into ifx_cat1_spi_is_busy(), which reports busy while the
  SPI context still holds outstanding tx/rx buffers
  (spi_context_tx_on()/spi_context_rx_on()), while Cy_SCB_SPI_IsBusBusy()
  is active, or while an async transfer is still pending. The large-chunk
  DMA path drives the transfer purely through the DMA channels without
  setting data->pending, and Cy_SCB_SPI_IsBusBusy() can read idle between
  FIFO-paced DMA bursts, so the SPI context buffer state is used as the
  authoritative in-flight indicator that covers both the FIFO and DMA
  paths for synchronous and asynchronous transfers,
- unregisters the deep-sleep SysPm callback (only when CONFIG_PM=y),
- disables the SCB IRQ and the SCB SPI block (Cy_SCB_SPI_Disable),
- stops the rx and tx DMA channels via the shared ifx_cat1_spi_dma_stop()
  helper, also used by ifx_cat1_spi_release() (only when
  CONFIG_SPI_INFINEON_DMA=y),
- deinits the SCB SPI block last with Cy_SCB_SPI_DeInit(), then clears the
  cached SPI config so the next transceive after device_init() takes the
  full reconfigure path instead of being short-circuited by
  spi_context_configured().

The DMA channels are stopped before the SCB is deinitialized so the SCB
teardown is the last hardware step, and the rx/tx dma_stop sequence is
factored into ifx_cat1_spi_dma_stop() rather than duplicated between the
deinit and release paths.

The deinit function and its reference in the device definition are
guarded by CONFIG_DEVICE_DEINIT_SUPPORT, matching the pattern used by
drivers/spi/spi_nrfx_spim.c and drivers/spi/spi_bflb.c.

Also drop the unused dma_configured field from struct ifx_cat1_spi_data:
it was never read and never set to true anywhere in the driver.

Verified on kit_pse84_eval/pse846gps2dbzc4a/m55:
  - [spi_loopback.test_spi_deinit] PASS
  - [spi_loopback.test_spi_deinit_busy] PASS (device_deinit() returns
    -EBUSY while an 8192-byte DMA transfer is in flight, then succeeds
    and re-inits once the bus is idle)

Assisted-by: AI (GitHub Copilot)
Signed-off-by: Bill Waters <bill.waters@infineon.com>
2026-09-19 10:29:24 +02:00
Martin Hoff
1b928aeca6 soc: silabs: enable new clock managers
This commit enables the new clock managers by switching the device
tree to use the new bindings. It also moves some initialization code
from the old clock manager to soc_early_init_hook() since some clocks
configuration needs to be done before the clock drivers are initialized.

Signed-off-by: Martin Hoff <martin.hoff@silabs.com>
2026-09-18 11:14:08 +01:00
Benjamin Cabé
ceacfa7cff drivers: spi: nxp_kinetis_l: drop the deprecated mode macro
The driver rejects peripheral mode with SPI_OP_MODE_SLAVE, which is
marked __DEPRECATED_MACRO and so makes the build fail under -Werror.
Use SPI_OP_MODE_PERIPHERAL instead and reword the log message to match
the controller/peripheral terminology the other SPI drivers use.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5
2026-09-16 16:19:41 +01:00
Khai Cao
ee68d2dd21 drivers: spi: Add DMAC support to SCI B SPI driver for RA MCU
- Add CONFIG_SPI_RENESAS_RA_SCI_B_DMAC configuration option
- Add device tree properties for DTC (rx-dtc, tx-dtc)
- Support both DTC/DMAC transfer with shared transfer infrastructure
- Add tx-dtc and rx-dtc properties to device tree binding
- Add DMAC configurations, interrupt and callback declarations

Signed-off-by: Khai Cao <khai.cao.xk@renesas.com>
Signed-off-by: Khoa Nguyen <khoa.nguyen.xh@renesas.com>
2026-09-16 09:22:24 +02:00
Khai Cao
422aeb50de drivers: spi: Add DMAC support to SPI B driver
- Add CONFIG_SPI_B_DMAC configuration option
- Support both DTC/DMAC transfer with shared transfer infrastructure
- Add DMAC configurations, interrupt and callback declarations

Signed-off-by: Khai Cao <khai.cao.xk@renesas.com>
Signed-off-by: Khoa Nguyen <khoa.nguyen.xh@renesas.com>
2026-09-16 09:22:24 +02:00
Mohamed Azhar
a5b36890b4 drivers: spi: microchip: Update g1 driver
Connect every SERCOM interrupt line the devicetree node declares via
LISTIFY(DT_INST_NUM_IRQS), instead of a fixed index 0-3 subset

Signed-off-by: Mohamed Azhar <mohamed.azhar@microchip.com>
2026-09-09 07:40:33 +02:00
Benjamin Cabé
5e057c6d8c drivers: spi: add VIRTIO SPI driver
Add a driver for the VIRTIO SPI controller device (virtio spec 1.4,
section 5.21), letting a Zephyr guest drive a SPI bus exposed by a
hypervisor or a vhost-user backend.

The device carries a single transfer per request, so a transceive call
is split into one request per contiguous chunk of the buffer sets, with
cs_change holding the chip select asserted in between. The controller
capabilities are read from the device configuration space at init and
checked against the SPI configuration. Every request is a round trip to
the device, so the SPI API can only be used from a thread.

Assisted-by: Claude Code:opus-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-09-07 21:06:52 -04:00