Not motivated by any impacted functionality but rather following good
practices. Recursive inclusions may be confusing and hard to diagnose.
Signed-off-by: Luis Ubieda <luisf@croxel.com>
This version is based on the CPU LPSPI driver, directly implementing
the submit call following the non-blocking asynchronous pattern.
This has been re-introduced after struggling to keep up with data
streaming applications, which demands reduced and controlled latency,
which for the default implementation (using RTIO workqueue) is not
guaranteed, due to being serviced by a thread-pool vs directly in the
ISR context.
This version includes limited feature-set, yet stress-tested:
- Required both rx-fifo and tx-fifo to be equal.
- 8-byte words supported only.
- SPI Controller-only supported (target mode not included).
- SPI_HOLD_ON_CS only supported with CS GPIOs.
Signed-off-by: Luis Ubieda <luisf@croxel.com>
This commit adds a new property in the device-tree bindings for swapping
the MISO and MOSI pins of the SPI/I2S peripheral for STM32 microcontrollers
that support it.
Signed-off-by: Arthur Gay <arthur.gay@marshmallow.kids>
The driver did send some extra 0 bytes when the receive hasn't been
finished yet. This patch makes sure to avoid that.
Signed-off-by: Christian Mauderer <christian.mauderer@embedded-brains.de>
At the moment, if you would pass a NULL buffer to the driver, the rx and
tx counts of that buffer would not advance. This patch fixes that.
Signed-off-by: Christian Mauderer <christian.mauderer@embedded-brains.de>
The driver has ignored the first RX buffer. Most likely it has been
modeled for accesses to a SPI flash or similar where the first read data
is not relevant.
This commit makes sure that the driver can work as a universal SPI
master instead.
Signed-off-by: Christian Mauderer <christian.mauderer@embedded-brains.de>
Use the timing params from spi_config that are specific to the slave
instead of using the same timing for the controller for all slaves.
Remove these properties from the LPSPI DT binding.
Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
Requesting/releasing SPIM device may be ISR safe, but
it cannot be reliably known whether managing its power
domain is. Is is then assumed that if power domains are used,
device is no longer ISR safe. This macro let's us check if
we will be requesting/releasing power domains and determines
PM device ISR safety value.
Signed-off-by: Michał Stasiak <michal.stasiak@nordicsemi.no>
Some error cases, and the asynchronous dma case, were not calling
pm_policy_device_power_lock_put() at the right time.
Signed-off-by: Mike J. Chen <mjchen@google.com>
For every TX, the driver used to get both callbacks when
each block was trasnfered and when the entire DMA was complete.
The callback for each block isn't needed so remove it
and reduce intermediate interrupts (the more blocks in
the DMA link, the more needless intermediate interrupts we
now no longer get).
Signed-off-by: Mike J. Chen <mjchen@google.com>
This fixes CI issues ("error: statement with no effect") in the
project's weekly CI run, e.g.:
west twister -p xmc47_relax_kit/xmc4700 -s drivers.spi.loopback.internal
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
In addition to #94710 fixes, SPI RTIO currently fails existing spi
loopback testcase: test_spi_null_tx_rx_buf_set.
This plus the referenced PR enable RTIO-enabled drivers to pass the
testsuite.
Signed-off-by: Luis Ubieda <luisf@croxel.com>
flush pending irq before enableing the irq.
In the litex soc, if an irq is not enabled, it will
it can still be registered and will be pending
if it occurs, it will just not be send to the cpu
until the irq is enabled.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
Within spi_rtio_copy there'd be a case where the tx_buf pointer would
mistakenly get assigned the address of an rx buffer.
Specifically this would happen in the case where there are no rx buffers
provided, and as such this would lead to pontential nullptr dereferences.
Correct the mistake to let tx_buf correctly point to the provided tx
buffers.
Signed-off-by: Emil Dahl Juhl <emil@s16s.ai>
Fixes the `spi_loopback` test failure on board Renesas `rzg3s_smarc` since
the test has been updated by zephyrproject-rtos/zephyr/pull/86383
Signed-off-by: Quang Le <quang.le.eb@bp.renesas.com>
Signed-off-by: Tien Nguyen <tien.nguyen.zg@renesas.com>
As the other spi_nxp_lpspi driver source files use DT_DRV_COMPAT
and that is used to determine in spi_context.h if the gpio cs
code is used, it also have to be defined in spi_nxp_lpspi_common.c
so there is no mismatch and breaking of the driver.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
At this moment, DMA for SPI 3-wire half-duplex operation is not supported
by the pio driver. A check was implemented there to prevent user from
enabling DMA, but wasn't bypassed when CONFIG_SPI_RPI_PICO_PIO_DMA is
not enabled at all, under which the `dma_config` structure isn't defined
at all.
Fixed#94897.
Signed-off-by: Terry Geng <terry@terriex.com>
Series 2 EUSART and SiWx91x GSPI drivers were missing the
`iodev_submit` member from their API structs, leading to
null pointer dereference if CONFIG_SPI_RTIO was used.
Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
This commit disables spi clock during idle to reduce power
consumption.
Tested with: reduce current cons. by around 0.08mA on it515xx_evb
Signed-off-by: Ren Chen <Ren.Chen@ite.com.tw>
Check if cqe is NULL before accessing cqe->result in
spi_rtio_transceive(). Prevents possible null pointer dereference
from rtio_cqe_consume() return value.
CID: 516229
Fixes: #90547
Signed-off-by: sudarsan N <sudarsansamy2002@gmail.com>
remove spi_cs_is_gpio checks before
spi_context_cs_control, as it is also done
inside and we don't need to check two times.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
some platforms dont have these doze related symbols defined, and causes
a build error, fix with #ifdef bandaid.
Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
Split the RX buffer into multiple sub-buffers aligned to DCACHE boundaries
to ensure proper operation during DMA transceive.
Signed-off-by: jacob kung <jacob.kung@egistec.com>
The Egis ET171 SPI controller was based on Andes ATCSPI200,
but has since been modified. In particular, the WrTranCnt and RdTranCnt
fields from the SPI Transfer Control Register have been moved to dedicated
Wr_Tran_Cnt and Rd_Tran_Cnt registers.
Signed-off-by: jacob kung <jacob.kung@egistec.com>
Remove the configs that are not actually used for anything anymore or
never were, or that are redundant with other configs, and don't have any
code changes outside of Kconfig to remove.
Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
The dma driver was determining src_inc and dst_inc from the
config of the first block buffer and ignoring the config
flags for any additional buffers in the chain, which could
lead to incorrect transfers (e.g. in a multiple rx buffer
case, if the first buffer was to receive to NULL,
but the subsequent buffers were not NULL, the bug
would manifest as all transfers being made with
dst_inc of 0). Change the driver to setup
each dma descriptor according to the addr_adj flag
of each block_buffer.
Add check that peripheral transfers have addr_adj set to
NO_CHANGE instead of assuming it, to help catch errors.
Also now check for invalid addr_adj request of
decrement, which this controller doesn't support.
Signed-off-by: Mike J. Chen <mjchen@google.com>
The spi_mcux_flexcomm driver uses a special last DMA blk_cfg
to trigger a release of the SPI chip select. This transfer
is always a 4-byte transfer, regardless of the width specified
during dma_configure().
The way the spi_mcux_flexcomm driver communicated this special
transfer was kind of a hack, where the dma_mcux_lpc driver would
assume that when a blk_cfg with source_addr_adj and dest_addr_adj
both set to NO_CHANGE was for this SPI_TX special case.
However, this is an unsafe hack since it is perfectly valid
to have dma use cases for both src/dest_addr_adj to be NO_CHANGE
that is not for SPI_TX. One example is when transmitting a
fixed/repeating value to a periperhal address (e.g. send 100
bytes of the same value from a single memory address over SPI).
This CL introduces a dma_mcux_lpc specific dma channel_direction
which the two drivers now use to cleary request this special
transfer case.
Signed-off-by: Mike J. Chen <mjchen@google.com>
In spi_mcux_transfer_next_packet(), if the next
transfer start fails, add calls to
spi_context_cs_control() to release cs and
spi_context_complete() with error code -EIO.
Signed-off-by: Mike J. Chen <mjchen@google.com>
The current driver implementation would block even when the async
API was invoked, so it wasn't really async.
This CL also fully chains the DMA transfer using multiple dma blocks
and makes the number of dma blocks available a config value. The
increase in number of dma blocks is needed so that a spi_buf_set
that has many entries can be converted into chained dma transfers
with the last transfer in a separate block that will set the EOT flag.
Also make some improvements:
1) When doing single cnt transfer, don't use the SDK driver but
use a new fucntion spi_mcux_transfer_single_word().
It's much more efficient and does not use an ISR
like the SDK function does just to send one word.
2) Fix calls to spi_context_update_tx/rx() so that the
correct word size is passed in, instead of previously
being hardcoded to 1. This only matters when word size
is two. Evaluate the word_size_bytes and word_size_bits
once and store the values in data instead of computing
it multiple times in various parts of the driver
3) When CONFIG_SPI_MCUX_FLEXCOMM_DMA is defined, we
do not use the IRQ handler, so add #ifdefs to compile
that code out. This reduces code size.
Signed-off-by: Mike J. Chen <mjchen@google.com>
This reverts commit a3530d6a43.
This change incorrect if chip-select is via a GPIO pin,
released by spi_context_cs_control(), and not the controller
default chip-select pin that can be released using a final
FIFOWR.
When GPIO is used for chip-select control, the chip-select could
be released too soon because the transfer callback is invoked
when the last byte is put into the TX FIFO but that byte might
not yet have clocked out yet on the SPI pins. The rx part of
the transfer is really what completes the transfer so ignoring
it is incorrect.
We could try to special case and use ignore only when
spi_context_cs_control() does nothing, but since it is a very
small optimization, it doesn't seem worth the extra
complexity.
Signed-off-by: Mike J. Chen <mjchen@google.com>
support interrupts for rx_ready, so we can use the
time we are waiting for other stuff.
implement async spi transfers.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
To reduce power consumption, the SPI clock is gated when no spi
transaction is in progress. With this mechanism, current
consumption is reduced by approximately 0.1mA when cpu idle.
Signed-off-by: Ren Chen <Ren.Chen@ite.com.tw>
This commit removes gpio-based cs support as it8xxx2 spi
only supports transactions using the dedicated cs pin.
Signed-off-by: Ren Chen <Ren.Chen@ite.com.tw>
The p_context no longer has the const type, so all
Renesas-supported drivers need to be updated accordingly.
Signed-off-by: Khoa Nguyen <khoa.nguyen.xh@renesas.com>