Commit graph

1005 commits

Author SHA1 Message Date
Tristan Honscheid 0198b7d5f7 emul: Add stub release impl. for emulated SPI driver
`release` is a mandatory method in the `struct spi_driver_api` API but
is not implemented in the SPI emulator. This can cause a test calling
`spi_release()` to segfault. Add a stub implementation that just returns
zero.

Signed-off-by: Tristan Honscheid <honscheid@google.com>
2024-01-09 10:27:06 +01:00
Jakub Zymelka ade49f081d modules: hal_nordic: nrfx: update API version to 3.2.0
Updated API version enables multi-instance GPIOTE driver.
Additionally obsolete symbol that was used to specify
API version in the past was removed.
Affected drivers have been adjusted and appropriate changes
in affected files have been made.

Signed-off-by: Jakub Zymelka <jakub.zymelka@nordicsemi.no>
2024-01-08 11:19:37 +01:00
Pisit Sawangvonganan 3ffcd75469 drivers: spi: set 'spi_driver_api' as 'static const'
This change marks each instance of the 'spi_driver_api' as 'static const'.
The rationale is that 'spi_driver_api' is used for declaring internal
module interfaces and is not intended to be modified at runtime.
By using 'static const', we ensure immutability, leading to usage of only
.rodata and a reduction in the .data area.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-01-05 09:04:51 +01:00
Chekhov Ma 0ce4399a03 driver: mucx_lpspi: enable runtime mmio configuration
Enable runtime mmio configuration in mcux_lpspi driver. The fsl_lpspi
driver relies on physical address to determine instance number.
So mmap flag 'K_MEM_DIRECT_MAP' is required.

Signed-off-by: Chekhov Ma <chekhov.ma@nxp.com>
2024-01-05 09:01:55 +01:00
Jeppe Odgaard ef867e4c7e drivers: spi: align dspi and lpspi spi_mcux_transfer_next_packet
Add return code to lpspi spi_mcux_transfer_next_packet and print the
kStatus_* return code since it information is lost when translated to
errno.

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
2024-01-05 09:01:35 +01:00
Anisetti Avinash Krishna a6fda00254 drivers: spi: pw: Fix SPI Receive FIFO set
Fixes SPI Receive FIFO register set operation.

Signed-off-by: Anisetti Avinash Krishna <anisetti.avinash.krishna@intel.com>
2023-12-20 11:58:56 +00:00
TOKITA Hiroshi 00d1cecedd driver: spi: spi_rpi_pico_pio: Change to use clock controller
Since clock_control has been introduced, use it to obtain the frequency.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
2023-12-20 11:14:24 +01:00
TOKITA Hiroshi 57641875c3 drivers: spi: pl022: Reset device on initializing
Reset the device on initializing via reset controller.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
2023-12-20 11:14:24 +01:00
Andrei-Edward Popa c448866042 drivers: spi: Changed how to get clock frequency for PL022
Changed how to get clock frequency for PL022

Signed-off-by: Andrei-Edward Popa <andrei.popa105@yahoo.com>
Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
2023-12-20 11:14:24 +01:00
Daniel Gaston Ochoa 5781b6a05f Revert "drivers: spi: stm32h7: Use FIFO"
This reverts commit bffa0c6bddbc91d39f4b01baa34e3d0595760d50.

This FIFO implementation causes a regression by which the SPI
peripheral generates several spurious SCK cyles after the last
data has been sent.

Signed-off-by: Daniel Gaston Ochoa <dgastonochoa@gmail.com>
2023-12-18 09:31:00 +01:00
Gustavo Silva f684e299b9 drivers: stm32: use IF_ENABLED() macro in config structs
Use the IF_ENABLED() macro to increase readability in some of
the STM32 drivers.

Fixes #62962

Signed-off-by: Gustavo Silva <gustavograzs@gmail.com>
2023-12-15 14:04:12 +01:00
Adam Wojasinski c88b492842 drivers: spi: nrfx: Update doc for RAM_BUFFER_SIZE Kconfig symbol
Update documentation for SPI_NRFX_RAM_BUFFER_SIZE Kconfig symbol
to reflect new usage of it. Now the symbol specifies size of RX buffer.
The change introducing support for RX buffer placed by a linker in
memory region defined in SPIM devicetree node is in a parent commit
of that one.

Signed-off-by: Adam Wojasinski <adam.wojasinski@nordicsemi.no>
2023-12-14 10:14:26 +01:00
Adam Wojasinski ae75a8f73a drivers: spi: spi_nrfx_spim: Add support for RX buffer from RAM region
This patch adds support for RX buffer placed by a linker in
memory region defined in SPIM devicetree node. The buffer is placed
in memory region defined as devicetree node. The memory region node's
reference is then stored in `memory-regions` property of SPIM node.

Added build time assertion to check if `CONFIG_SPI_NRFX_RAM_BUFFER_SIZE`
Kconfig symbol has value greater than 0 when given SPIM node has
`memory-region` property.

Signed-off-by: Adam Wojasinski <adam.wojasinski@nordicsemi.no>
2023-12-14 10:14:26 +01:00
Mahesh Mahadevan 0dbbc3cc77 drivers: spi: Set the complete_callback flag
The MCUX LPC driver now recognizes the complete_callback
flag. We need to set this flag so we receive a callback
after every block.

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2023-12-14 09:28:38 +01:00
Georgij Cernysiov 9f3d9f7594 drivers: spi: stm32: disable cs when spi is done
Deassert CS after SPI is done.

Signed-off-by: Georgij Cernysiov <geo.cgv@gmail.com>
Co-authored-by: Daniel Gaston Ochoa <dgastonochoa@gmail.com>
2023-12-13 13:58:03 +01:00
Henrik Brix Andersen 7ddc0f713f drivers: spi: mcux: lpspi: fix error on first configure on MKE1xF
Fix error writing to the CR register on the first call to SPI configure on
NXP MKE1xF. On the first call, the module clock is not enabled and writing
to the CR register will fail.

Fixes: #66036

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-12-11 09:52:20 +01:00
Daniel Gaston Ochoa 50f64eaeba drivers: spi: stm32h7: Use FIFO
Use H7 SPI FIFO to improve performance.

Signed-off-by: Daniel Gaston Ochoa <dgastonochoa@gmail.com>
2023-11-30 10:01:19 +01:00
Daniel Gaston Ochoa cb4f54535f drivers: spi: stm32h7: Simplify long function in small ones
Simplify and clarify spi_stm32_shift_m by splitting it in
3 smaller functions with clear names.

Signed-off-by: Daniel Gaston Ochoa <dgastonochoa@gmail.com>
2023-11-30 10:01:19 +01:00
Daniel Gaston Ochoa 02f46fb1f2 drivers: spi: stm32h7: Use a better name for ll_func_tx_is_empty
In H7, TXP indicates when its FIFO has room for, at least, one
packet. Thus, rename ll_func_tx_is_empty as ll_func_tx_is_not_full,
to be consistent in all platforms.

Signed-off-by: Daniel Gaston Ochoa <dgastonochoa@gmail.com>
2023-11-30 10:01:19 +01:00
Daniel Gaston Ochoa 2effd8cce7 drivers: spi: stm32h7: Move startMasterTransfer to transceive
Avoind calling startMasterTransfer multiple times in a
transaction by moving it to the transceive() function.

Signed-off-by: Daniel Gaston Ochoa <dgastonochoa@gmail.com>
2023-11-30 10:01:19 +01:00
Marcin Szymczyk 2a38230a31 drivers: spi: nrfx: add dependency to PPI for PAN 58 on nRF52832
While enabling workaround for PAN 58 the PPI driver is used.
This requires the nrfx PPI driver to be enabled thus CONFIG_NRFX_PPI
Kconfig symbol needs to be set.

Jira: NRFX-1616

Signed-off-by: Marcin Szymczyk <marcin.szymczyk@nordicsemi.no>
2023-11-29 11:30:04 +01:00
Chaitanya Tata 0a1eff8d97 drivers: spim: Move the length check to beginning
This check has to be done independent of whether RAM is used for buffers
or not and depends on device maximum length property.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-11-29 11:30:04 +01:00
Chaitanya Tata 2c0f121727 drivers: spi: spi_nrfx_spim: Use generic macro for RAM address check
Instead of assuming only RAM is accessible by EasyDMA, use the generic
DMA accessible function.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-11-29 11:30:04 +01:00
Adam Wojasinski 058eebe479 drivers: spi: spi_nrfx_spim: Add additional symbol check for frequency
Some targets may not have `NRF_SPIM_HAS_32_MHZ_FREQ` or
`NRF_SPIM_HAS_16_MHZ_FREQ` symbols but have `NRF_SPIM_HAS_PRESCALER`
symbol defined. The symbol informs that target supports 32 MHz and
16 MHz frequencies for SPIM instances.

Signed-off-by: Adam Wojasinski <adam.wojasinski@nordicsemi.no>
2023-11-29 11:30:04 +01:00
Adam Wojasinski e6bcc986bf drivers: spi: spi_nrfx_spim: Include nrf_clock.h only for nRF5340
The CLOCK HAL header is only needed for nRF5340 SoC. It's used when
user wants to configure SPIM instance to 32 Mbps. The HAL checks
if is running at 128 MHz as only then 32 Mbps is supported.

Signed-off-by: Adam Wojasinski <adam.wojasinski@nordicsemi.no>
2023-11-29 11:30:04 +01:00
Emilio Benavente 2f68ad7f89 drivers: spi: spi_mcux_lpspi: Added RTIO Support for LPSPI
Provided APIs to support RTIO with the LPSPI driver.

Signed-off-by: Emilio Benavente <emilio.benavente@nxp.com>
2023-11-28 12:11:52 -06:00
Emilio Benavente 776519075b drivers: spi: Kconfig.mcux_lpspi: Added RTIO Kconfig for lpspi
Added Kconfig that switches RTIO Support in the LPSPI driver.

Signed-off-by: Emilio Benavente <emilio.benavente@nxp.com>
2023-11-28 12:11:52 -06:00
Dean Sellers 897b300b2e drivers: spi: esp32xx: Fix CS reset over split transaction
In the case where a transaction is spilt due to the rx buff len
being longer than the tx or the transaction buffer exceeding the
size of the requested buffer with non gpio CS, the chip select
would be de-asserted/asserted in the middle of the transaction.

Fixes: #57577

Signed-off-by: Dean Sellers <dsellers@evos.com.au>
2023-11-24 14:45:51 +01:00
Benedikt Schmidt 3441fee460 drivers: spi: Implement workaround for unreliable busy flag
For some STM32 MCUs the busy flag of SPI is unreliable. This is a known
issue of the device and described in the device errata.
As a fix implement a configurable timeout which ensures that a call
to spi_transceive will eventually return.
Fixes #64927

Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
2023-11-17 09:22:18 +01:00
Cong Nguyen Huu e59991abfe drivers: spi_nxp_s32: update StateIndex configuration
Set Spi StateIndex equal to index of DT Spi node.
Because number of State array is set base on
number of DT Spi node used. If StateIndex is set
equal to Spi instance, StateIndex can be over array.

Signed-off-by: Cong Nguyen Huu <cong.nguyenhuu@nxp.com>
2023-11-16 09:28:16 +01:00
Andriy Gelman 325e28218f drivers: spi: xmc4xxx: Fix compiler warning with debug flags enabled
Fixes warning when CONFIG_DEBUG_OPTIMIZATION=y:

zephyrproject/modules/hal/infineon/XMCLib/drivers/inc/xmc_usic.h:2132:18:
warning: 'clock_settings' may be used uninitialized [-Wmaybe-uninitialized]
 2132 |                  (uint32_t)passive_level |
      |                  ^~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2023-11-16 09:26:50 +01:00
Andriy Gelman a34d4d1ce9 drivers: spi: xmc4xxx: Fix potential runtime error
Fixes an unhandled interrupt runtime crash if CONFIG_SPI_XMC4XXX_DMA=y and
CONFIG_SPI_XMC4XXX_INTERRUPT=n.

The unhandled interrupt error is triggered because irq_enable() was called
without calling IRQ_CONNECT() when CONFIG_SPI_XMC4XXX_INTERRUPT=n.

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2023-11-16 09:26:50 +01:00
Andriy Gelman 8246d14742 drivers: xmc4xxx: spi: Update buffers before transmitting data
In the interrupt driven spi, spi_context_update_tx() is called once
from the calling thread and then once in spi_xmc4xxx_isr() after each
new byte is received. This actually means that there is one extra call to
spi_context_update_tx(). This is fine if spi_context_update_tx() complete
it's call in the calling thread before the interrupt fires, however, this
cannot be guaranteed especially if the calling thread is pre-emptive and
has a low priority.

Fix this by calling spi_context_update_tx() in the calling thread before
transmitting the first byte.

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2023-11-16 09:26:50 +01:00
Manuel Argüelles c777ef255b spi: nxp_s32: use instance-based DT macros
At present, many of the NXP S32 shim drivers do not make use of
devicetree instance-based macros because the NXP S32 HAL relies on an
index-based approach, requiring knowledge of the peripheral instance
index during both compilation and runtime, and this index might not
align with the devicetree instance index.

The proposed solution in this patch eliminates this limitation by
determining the peripheral instance index during compilation
through macrobatics and defining the driver's ISR within the shim
driver itself.

Signed-off-by: Manuel Argüelles <manuel.arguelles@nxp.com>
2023-11-06 19:02:32 -05:00
Anas Nashif a08bfeb49c syscall: rename Z_OOPS -> K_OOPS
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif ee9f278323 syscall: rename Z_SYSCALL_VERIFY -> K_SYSCALL_VERIFY
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 1a9de05767 syscall: rename Z_SYSCALL_DRIVER_ -> K_SYSCALL_DRIVER_
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 9c4d881183 syscall: rename Z_SYSCALL_ to K_SYSCALL_
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif df9428991a syscall: Z_SYSCALL_MEMORY_ARRAY -> K_SYSCALL_MEMORY_ARRAY
Rename macros and do not use Z_ for internal APIs.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 4e396174ce kernel: move syscall_handler.h to internal include directory
Move the syscall_handler.h header, used internally only to a dedicated
internal folder that should not be used outside of Zephyr.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Adam Wojasinski 30b8d4ca99 drivers: spi: spi_nrfx_spim: Add new SPIM instances in driver
Add support for new instances.

Signed-off-by: Adam Wojasinski <adam.wojasinski@nordicsemi.no>
2023-10-20 15:03:17 +02:00
Adam Wojasinski 5c1daef5ab drivers: spi: nrfx: Add SPIM Kconfig symbols for new instances
Add support for upcomming SPIM instances.

Signed-off-by: Adam Wojasinski <adam.wojasinski@nordicsemi.no>
2023-10-20 15:03:17 +02:00
Ye Weize 2a86016aff drivers: spi: Add Intel SEDI driver
Add a new SPI shim driver for Intel SoCs. Builds upon the SEDI bare
metal SPI driver in the hal-intel module.

Co-Authored-By: Kong Li <li.kong@intel.com>
Signed-off-by: Ye Weize <weize.ye@intel.com>
2023-10-20 14:55:49 +02:00
TOKITA Hiroshi 90bd7863c7 drivers: spi: pl022: correcting error check condition
Only negative return values of pinctrl_apply_state are errors.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
2023-10-20 14:55:03 +02:00
Emilio Benavente 17032a093d drivers: spi: spi_mcux_lpspi: Updated the Async api
Updated the Async API allowing the code path
for DMA while Async is enabled. Added common
DMA function that sets up both tx and rx dma
channels.

Signed-off-by: Emilio Benavente <emilio.benavente@nxp.com>
2023-10-14 10:55:02 +03:00
Aaron Ye a94422f686 drivers: spi: Fix the Ambiq apollo4p SPI transmission failure.
The instruction length can only be 0~5.
Use am_hal_iom_blocking_transfer and specify clearly the TX/RX direction.
Hold CS to continue to RX expected response after instruction transmission.

Signed-off-by: Aaron Ye <aye@ambiq.com>
2023-10-03 15:24:20 +01:00
Aaron Ye 7cf21d1080 drivers: spi: Fix Ambiq apollo4p SPI reconfiguration.
The configured SPI should not be configured again.
Otherwise it would cause SPI transmission failure.

Signed-off-by: Aaron Ye <aye@ambiq.com>
2023-10-03 15:24:20 +01:00
Aaron Ye 4e7d1b0f74 drivers: spi: Fix Ambiq apollo4p SPI mode configuration.
The commit fixes the SPI mode improper configuration.
Otherwise the MODE_3 and MODE_0 cases would never be entered as expected.

Signed-off-by: Aaron Ye <aye@ambiq.com>
2023-10-03 15:24:20 +01:00
Andrzej Głąbek eafe6a9a31 drivers: spi_nrfx_spis: Handle empty spi_buf_set structures properly
SPI API allows `spi_buf_set` structures with no buffers linked to them
(with `.buffers = NULL`). Correct the spi_nrfx_spis driver so that it
is able to deal with such structures.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2023-09-27 17:49:28 +02:00
Manuel Argüelles ca3310145f drivers: select nocache only when supported
NOCACHE_MEMORY depends on ARCH_HAS_NOCACHE_MEMORY_SUPPORT, so
don't try to select the symbol if not supported.

Signed-off-by: Manuel Argüelles <manuel.arguelles@nxp.com>
2023-09-26 15:09:51 +02:00
Dat Nguyen Duy 910d417a92 drivers: spi_mcux_lpspi: add support dma per instance
Currently, the driver imply understand that all instances
will use dma when CONFIG_SPI_MCUX_LPSPI_DMA is set. There
might be an instance doesn't need DMA, so instead of enforce
spi_transceive API to use DMA, add more flexible to enable
DMA only when required

Signed-off-by: Dat Nguyen Duy <dat.nguyenduy@nxp.com>
2023-09-25 09:50:01 +02:00
Manuel Argüelles cdcba384bc spi: nxp_s32: use clock control APIs
Use clock control API to retrieve the module's frequency and
update the boards using it to provide the source clocks.

Signed-off-by: Manuel Argüelles <manuel.arguelles@nxp.com>
2023-09-22 09:24:40 +02:00
Daniel Gaston Ochoa 0e72d63a01 drivers: spi: stm32h7 Fix SPI DMA 16 bits frames
Modify STM32H7 SPI driver so that it updates the rx/tx
pointers correctly (depending on the frame size) when DMA
is enabled. Also, make the dummy rx/tx buffer cache-coherent.

Signed-off-by: Daniel Gaston Ochoa <dgastonochoa@gmail.com>
2023-09-20 11:33:28 +01:00
Daniel Gaston Ochoa 8e6b401ca4 drivers: spi: stm32h7 Check nocache memory correctly
The way of setting a nocache region in devicetree has changed.
Adapt the H7 SPI driver to this new circumstance.

Signed-off-by: Daniel Gaston Ochoa <dgastonochoa@gmail.com>
2023-09-20 11:33:28 +01:00
Gerard Marull-Paretas 0660719346 drivers: nrf: select PINCTRL
Drivers for nRF SoCs using pinctrl did not select PINCTRL. This means
boards are forced to enable PINCTRL.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2023-09-20 08:57:09 +02:00
Hein Wessels 3e369ec8ed drivers: spi: stm32: LOG_INF should be LOG_DBG to not clutter console
Drivers should only log extra information during initialization if
debug logging is enabled. Otherwise it always clutters the console
when not required.

Signed-off-by: Hein Wessels <heinwessels93@gmail.com>
2023-09-18 10:41:41 +01:00
Carlo Caione e4a125b6a4 dt: Make zephyr,memory-attr a capabilities bitmask
This is the final step in making the `zephyr,memory-attr` property
actually useful.

The problem with the current implementation is that `zephyr,memory-attr`
is an enum type, this is making very difficult to use that to actually
describe the memory capabilities. The solution proposed in this PR is to
use the `zephyr,memory-attr` property as an OR-ed bitmask of memory
attributes.

With the change proposed in this PR it is possible in the DeviceTree to
mark the memory regions with a bitmask of attributes by using the
`zephyr,memory-attr` property. This property and the related memory
region can then be retrieved at run-time by leveraging a provided helper
library or the usual DT helpers.

The set of general attributes that can be specified in the property are
defined and explained in
`include/zephyr/dt-bindings/memory-attr/memory-attr.h` (the list can be
extended when needed).

For example, to mark a memory region in the DeviceTree as volatile,
non-cacheable, out-of-order:

   mem: memory@10000000 {
       compatible = "mmio-sram";
       reg = <0x10000000 0x1000>;
       zephyr,memory-attr = <( DT_MEM_VOLATILE |
			       DT_MEM_NON_CACHEABLE |
			       DT_MEM_OOO )>;
   };

The `zephyr,memory-attr` property can also be used to set
architecture-specific custom attributes that can be interpreted at run
time. This is leveraged, among other things, to create MPU regions out
of DeviceTree defined memory regions on ARM, for example:

   mem: memory@10000000 {
       compatible = "mmio-sram";
       reg = <0x10000000 0x1000>;
       zephyr,memory-region = "NOCACHE_REGION";
       zephyr,memory-attr = <( DT_ARM_MPU(ATTR_MPU_RAM_NOCACHE) )>;
   };

See `include/zephyr/dt-bindings/memory-attr/memory-attr-mpu.h` to see
how an architecture can define its own special memory attributes (in
this case ARM MPU).

The property can also be used to set custom software-specific
attributes. For example we can think of marking a memory region as
available to be used for memory allocation (not yet implemented):

   mem: memory@10000000 {
       compatible = "mmio-sram";
       reg = <0x10000000 0x1000>;
       zephyr,memory-attr = <( DT_MEM_NON_CACHEABLE |
			       DT_MEM_SW_ALLOCATABLE )>;
   };

Or maybe we can leverage the property to specify some alignment
requirements for the region:

   mem: memory@10000000 {
       compatible = "mmio-sram";
       reg = <0x10000000 0x1000>;
       zephyr,memory-attr = <( DT_MEM_CACHEABLE |
			       DT_MEM_SW_ALIGN(32) )>;
   };

The conventional and recommended way to deal and manage with memory
regions marked with attributes is by using the provided `mem-attr`
helper library by enabling `CONFIG_MEM_ATTR` (or by using the usual DT
helpers).

When this option is enabled the list of memory regions and their
attributes are compiled in a user-accessible array and a set of
functions is made available that can be used to query, probe and act on
regions and attributes, see `include/zephyr/mem_mgmt/mem_attr.h`

Note that the `zephyr,memory-attr` property is only a descriptive
property of the capabilities of the associated memory  region, but it
does not result in any actual setting for the memory to be set. The
user, code or subsystem willing to use this information to do some work
(for example creating an MPU region out of the property) must use either
the provided `mem-attr` library or the usual DeviceTree helpers to
perform the required work / setting.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2023-09-15 12:46:54 +02:00
Manimaran A b328e920b6 drivers: spi: Microchip MEC172x SPI fix for Zephyr 3.4 breakage
Zephyr version 3.4 changed the SPI context structure and macros
which broke the logic in the MEC172x SPI driver configuration API.
This was not detected by CI due to no tests for this driver are in
the tree. The driver now behaves like most other SPI drivers requiring
a different configuration structure pointer to be passed if any item
in the configuration changes.

Signed-off-by: Manimaran A <manimaran.a@microchip.com>
2023-09-13 12:01:18 +02:00
Erwan Gouriou 9b56e8ac63 Revert "drivers/spi: stm32: fix TX-only mode"
This reverts commit 31cd3b1f61.

This change is causing regression in SPI loopback tests.

Signed-off-by: Erwan Gouriou <erwan.gouriou@st.com>
2023-09-12 14:45:37 +02:00
Sreeram Tatapudi fd04f8cc81 drivers: spi: Initial version of the Infineon CAT1 SPI driver
Initial version of Infineon CAT1 SPI Driver supporting synchronous
and asynchronous data transfer API

Signed-off-by: Sreeram Tatapudi <sreeram.praveen@infineon.com>
2023-09-12 10:55:01 +02:00
David Lamparter 31cd3b1f61 drivers/spi: stm32: fix TX-only mode
When doing a TX-only SPI operation, the RX not empty flag will never get
set, thus this will just hang forever.

Found/tested on STM32L462 trying to drive some WS2812 RGB LEDs.

Signed-off-by: David Lamparter <equinox@diac24.net>
2023-09-11 19:56:25 +02:00
Mateusz Sierszulski 8db11e6a0a drivers: spi: Add Ambiq MSPI driver
This commit adds MSPI driver for Apollo4 SoCs.

Signed-off-by: Mateusz Sierszulski <msierszulski@antmicro.com>
2023-09-08 14:44:12 +02:00
Steve Boylan 85cbc7a96e drivers: spi: spi_pico_pio: Add basic support for SPI via PIO
Add fundamental feature support for RP2040 PIO SPI peripherals.
This commit implements synchronous transfer with 8-bit MSB
format.  Using PIO allows any GPIO pins to be assigned the roles
of CS, CLK, MOSI, and MISO.

Optional features not implemented yet:

  - Interrupt based transfer
  - DMA transfer
  - Slave mode
  - Varying word size
  - 3-wire SPI support
  - LSB-first

Updated in response to review comments.
Further updates from second round of review.
Rename spi_pico_pio.c source to match zephyr/MAINTAINERS.yml
Remove unnecessary initialization code.
Resolve merge conflicts

Signed-off-by: Steve Boylan <stephen.boylan@beechwoods.com>
2023-09-01 16:36:41 +02:00
Daniel Gaston Ochoa d434693c15 stm32h7: spi: Use TXC instead of EOT
Check the TXC flag instead of EOT for the case of endless
transactions (TSIZE = 0), which in this case is always as
the stm32 SPI driver doesn't set TSIZE.

Signed-off-by: Daniel Gaston Ochoa <dgastonochoa@gmail.com>
2023-08-30 10:21:05 +02:00
Martin Kiepfer bda6656eca bugfix: esp32: spi: correct idle polarity and mode configuration
Possible fix for incorrection spi mode configuration
on esp32 (#61866)

Signed-off-by: Martin Kiepfer <mrmarteng@teleschirm.org>
2023-08-29 10:25:45 +02:00
Nick Ward 2d65acca3a drivers: gpio: use gpio_is_ready_dt helper function
Update `struct gpio_dt_spec` use with gpio_is_ready_dt()

Signed-off-by: Nick Ward <nix.ward@gmail.com>
2023-08-28 08:48:35 -05:00
Mateusz Sierszulski 2b74109f20 drivers: spi: Add Ambiq SPI driver
This commits adds SPI master driver for Apollo4 SoCs.

Signed-off-by: Mateusz Sierszulski <msierszulski@antmicro.com>
2023-08-25 10:31:58 +02:00
Daniel Gaston Ochoa 818aa2d0c7 drivers: stm32: SPI: SPI nocache buffers can be in CONFIG_NOCACHE_MEMORY
CONFIG_NOCACHE_MEMORY is a valid way of declaring buffers in
nocache regions. Consider them valid in the stm32 SPI driver
nocache check. Also, don't check NULL buffers as the SPI
interface states that such buffers will result in sending
zeroes.

Signed-off-by: Daniel Gaston Ochoa <dgastonochoa@gmail.com>
2023-08-24 15:35:50 +02:00
Fabio Baltieri dce9f06265 drivers: spi: spi_test: use the subsystem common init priority
Use CONFIG_SPI_INIT_PRIORITY like all other SPI drivers for initializing
the test driver.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-08-24 15:35:37 +02:00
Andrzej Głąbek 45dcc6c5db drivers: spi_nrfx_spis: Enable required SPI_SLAVE option in Kconfig
This is a follow-up to commit fa609e5844.

This driver implements SPI slave operations only and cannot be used
without the corresponding Kconfig option enabled.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2023-08-17 11:02:24 +02:00
Manuel Arguelles 35ad5358a4 spi: nxp_s32: use spi_cs_is_gpio() in config initializer
Following #56576, the `cs` field in `struct spi_config` is of type
`struct spi_cs_control` instead of a pointer to the same type.
This PR updated the driver to use `spi_cs_is_gpio()` helper to
check if SPI CS is controlled using a GPIO.

Signed-off-by: Manuel Argüelles <manuel.arguelles@nxp.com>
2023-08-14 18:11:04 +00:00
Daniel Leung 80cd39faed spi: pl022: remove shadow variables
Removes the shadow variable found by -Wshadow. The value of this
variable is the same throughout the for loop, so there is no
need to assign it again for each iteration.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-08-10 08:14:12 +00:00
Adam Wojasinski 9de69aabfd drivers: spi: spi_nrfx_spi: Add CPOL handling on SCK pin
Pin state after SPI deinitialization is based on pinctrl configuration.
On the other hand, CPOL is set during runtime. When the SPI instance
is disabled GPIO takes control over SCK and drives it to state set
by pinctrl driver. This might causes an invalid SCK state
when the transaction is configured with CPOL (Clock Polarity).

To address this issue, a patch was introduced to the SPI driver.
Now, when a SPI instance is configured with CPOL,
the driver is setting in the runtime the correct state of the SCK pin.

Signed-off-by: Adam Wojasinski <adam.wojasinski@nordicsemi.no>
2023-08-09 18:31:28 +00:00
Adam Wojasinski 315dd0f41c drivers: spi: spi_nrfx_spim: Add CPOL handling on SCK pin
Pin state after SPIM deinitialization is based on pinctrl configuration.
On the other hand, CPOL is set during runtime. With the introduction
of the power-optimized SPIM driver, it disables the peripheral instance
once the transfer is completed.
As a result, the GPIO takes control over the SCK pin and drives it
based on pinctrl configuration which causes an invalid SCK state
when the transaction is configured with CPOL (Clock Polarity).

To address this issue, a patch was introduced to the SPIM driver.
Now, when a SPIM instance is configured with CPOL,
the driver is setting in the runtime the correct state of the SCK pin.

Signed-off-by: Adam Wojasinski <adam.wojasinski@nordicsemi.no>
2023-08-09 18:31:28 +00:00
cyliang tw 5148c98e83 drivers: spi: support for Nuvoton numaker series
Add Nuvoton numaker series spi controller, including
full and half duplex support.

Signed-off-by: cyliang tw <cyliang@nuvoton.com>
2023-08-09 08:24:38 +00:00
Sylvio Alves e544bdb5e2 drivers: spi: esp32: fix SOC_ESP32 reference
ESP32 SoC refactoring added new SOC_SERIES definition,
which was missed by #60183. This fixes it.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2023-08-03 18:14:33 +00:00
Sylvio Alves d7bcac091c drivers: spi: esp32: add option to handle lines state
SPI driver is current working for common SPI devices.
However, addressable LED like WS2812 requires MOSI line to be
default LOW during initialization. This PR adds such option.
This has no effect on common SPI operation.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2023-08-03 12:15:18 -04:00
Andrzej Głąbek 7974ff2665 drivers: spi_nrfx_*: Add support for optional WAKE line
Add option to use (by defining the `wake-gpios` devicetree properties)
an additional signal line between SPI master and SPI slave that allows
the latter to stay in low-power state and wake up only when a transfer
is to occur.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2023-08-01 11:07:21 +02:00
Andrzej Głąbek f132f55e32 drivers: spi_nrfx_spis: Refactor prepare_for_transfer()
Refactor the function to make the execution flow in transceive()
clearer. In particular, return error codes directly, not through
spi_context_complete() which is unnecessary in this case.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2023-08-01 11:07:21 +02:00
Manuel Arguelles cd78028e15 drivers: spi: mcux_lpspi: allow to configure data pins
Add binding properties to allow configuring the direction of data pins
SDI and SDO.

Signed-off-by: Manuel Argüelles <manuel.arguelles@nxp.com>
2023-08-01 09:51:16 +02:00
Daniel Gaston Ochoa 1b3e2d98e4 drivers: stm32: SPI: Check that SPI buffers are in a nocache region
DMA only works with non-cached memory regions in H7. Check them
and return an error if they don't match this condition.

Signed-off-by: Daniel Gaston Ochoa <dgastonochoa@gmail.com>
2023-07-28 17:47:57 +02:00
Andrzej Głąbek 927dda06fa drivers: spi_nrfx_spis: Fix obtaining dev pointer in event handler
This is a follow-up to commit 4c20403629.

CONTAINER_OF() cannot be used to obtain the device pointer from its
data pointer as this data is not contained in the device structure.
Instead, use a dedicated member in the device data structure to store
the device pointer.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2023-07-26 09:52:24 +02:00
Marek Matej 6b57b3b786 soc: xtensa,riscv: esp32xx: refactor folder structure
Refactor the ESP32 target SOCs together with
all related boards. Most braking changes includes:

- changing the CONFIG_SOC_ESP32* to refer to
  the actual soc line (esp32,esp32s2,esp32s3,esp32c3)
- replacing CONFIG_SOC with the CONFIG_SOC_SERIES
- creating CONFIG_SOC_FAMILY_ESP32 to embrace all
  the ESP32 across all used architectures
- introducing CONFIG_SOC_PART_NUMBER_* to
  provide a SOC model config
- introducing the 'common' folder to hide all
  commonly used configs and files.
- updating west.yml to reflect previous changes in hal

Signed-off-by: Marek Matej <marek.matej@espressif.com>
2023-07-25 18:12:33 +02:00
Andrzej Głąbek fa609e5844 drivers: spi: nrfx: Clean up driver instantiation
- use CONFIG_HAS_HW_NRF_* symbols consistently in nRF multi-instance
  drivers when creating particular driver instances
- remove unnecessary hidden Kconfig options that indicated the type of
  peripheral to be used by a given instance (e.g. SPI, SPIM, or SPIS)
  and enabled proper nrfx driver instance; instead, use one option per
  peripheral type and include the corresponding shim driver flavor into
  compilation basing on that option (not the one that enables the nrfx
  driver as it was incorrectly done so far in some cases)

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2023-07-25 13:41:51 +02:00
Mulin Chao f34fff91bc driver: flash: npcx: introduce npcx flash driver
This CL attempts to implement npcx's flash driver instead of the
original one (npcx spi driver plus spi_nor flash driver).

Signed-off-by: Mulin Chao <mlchao@nuvoton.com>
2023-07-20 16:22:47 +02:00
Mike J. Chen 04f488accf drivers: spi: mcux_flexcomm: fix DMA bug for 2-byte transfers
The MCUX DMA controller only supports a single data_size
for a DMA transfer, not separate ones for source and
dest. An older version of the DMA driver used
dest_data_size as the DMA transfer size, but the
current one uses MIN(dest/source) as the trasnfer
size, which breaks case when SPI wants to do 2-byte
transfers.

Signed-off-by: Mike J. Chen <mjchen@google.com>
2023-07-19 10:36:23 -05:00
Dipak Shetty 022b234356 drivers: spi: eliminate dead code in spi_mcux_lpspi
The `spi_mcux_transceive` had 2 return calls when the
`CONFIG_SPI_MCUX_LPSPI_DMA` flag was active. The first return would be
called and the later was unreachable. With the fix, now the return calls
are mutually exclusive. Also, the `transceive` call is not compiled with
the `CONFIG_SPI_MCUX_LPSPI_DMA` flag is active.
Fixes #59533

Signed-off-by: Dipak Shetty <dipak.shetty@zeiss.com>
2023-07-18 16:21:26 +02:00
Tristan Honscheid 8fd1ce7579 emul: Only add enabled DT nodes to bus emulators
The eSPI, I2C, and SPI emulators use devicetree macros to build an array
of devices on the virtual bus. Currently, they will add device nodes that
are not status-okay. This leads to linker errors because the respective
device drivers would not have instantiated device structs for these
nodes --assuming the driver was even compiled. This can be frustrating
if nodes need to be disabled for debugging or configuration purposes.

Update the bus emulators to only consider status-okay nodes by changing
the macros used to iterate over bus devices.

Signed-off-by: Tristan Honscheid <honscheid@google.com>
2023-07-12 09:25:18 +02:00
Mike J. Chen 2a4acb2c42 drivers: spi: mcux_flexcomm: fix chip select bug w/ dma transfers
Fix for bug:
https://github.com/zephyrproject-rtos/zephyr/issues/59575

The dma version of the version of the driver can
invoke multiple intermediate dma transfers, like
when the spi_buf_set count is greater than one.
However, there is a bug where chip select is not kept
asserted for all intermediate dma transfers required
to process the entire spi_buf_set.

Signed-off-by: Mike J. Chen <mjchen@google.com>
2023-07-11 08:05:59 -05:00
Benedikt Schmidt 39391b4a16 drivers: spi: replace timeout for STM32 DMA slave mode
Replace the timeout for a SPI transceive in slave mode for STM32 DMA
operations with a K_FOREVER. Being an SPI slave means we do not
know when the transaction will start, hence it does not make sense
to have a timeout in such a case.
This will resolve issue #60000.

Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
2023-07-10 15:13:19 +02:00
Tristan Honscheid 81310769a9 emul: spi: SPI_EMUL_INIT(n) hard-coded to instance #0
The `SPI_EMUL_INIT(n)` macro used to instantiate SPI bus emulators
builds an array of SPI devices attached to the bus, but always checks
instance #0 of the bus and not `n`. This makes multiple instances of an
emulated SPI bus unusable and popualtes them all with bus 0's devices.

Change the `0` to `n`, which matches how the I2C bus emulator does it.

Signed-off-by: Tristan Honscheid <honscheid@google.com>
2023-07-07 09:17:12 +02:00
Daniel Leung 26ecaba4af drivers: syscalls: use zephyr_syscall_header
This adds a few line use zephyr_syscall_header() to include
headers containing syscall function prototypes.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-06-17 07:57:45 -04:00
Guillaume Gautier c73c7d5728 drivers: spi: stm32h7: add a small delay after enabling
Add a small delay after enabling SPI to prevent transfer stalling.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2023-06-05 10:48:59 -04:00
Siyuan Cheng d2e91c6b8f drivers: spi: fix spi_dw interrupt mask
Found EMSDP board SPI-FLASH sample broke after adding DFSS
into spi_dw. Found wrong interrput mask resulting in false
interrupt enabled. Now fixed it to fit both DFSS and DW.

Signed-off-by: Siyuan Cheng <siyuanc@synopsys.com>
2023-05-30 10:49:47 -04:00
Qipeng Zha bc3ea1bb99 drivers: spi: add SPI device statistics
Enable below statistics for SPI by follow Zephyr STATS subsystem,
    rx_bytes, tx_bytes, transfer_error.

and add SPI_DEVICE_DT_DEFINE helper macro to define SPI device.

Signed-off-by: Xiaolu Sun <xiaolu.sun@intel.com>
Signed-off-by: Qipeng Zha <qipeng.zha@intel.com>
2023-05-23 22:15:25 -04:00
Siyuan Cheng cbdd2f38da drivers: spi: add Data Fusion Subsystem SPI driver
Introduce DesignWare ARC Data Fusion IP Subsystem(DFSS) SPI
driver for ARC boards, i.e. EMSDP, which uses DW SPI to controll
SPI-Flash and DFSS SPI to connect external devices. Both drivers
share most source code, but DFSS uses ARC auxiliary registers.
Move FIFO depth setting to device tree.

Signed-off-by: Siyuan Cheng <siyuanc@synopsys.com>
2023-05-22 15:25:19 +02:00
Johann Fischer fdb631c5d7 drivers: spi_nrfx_spim: bring back get_nrf_spim_frequency
Commit 246393e830
("drivers: spi: spi_nrfx_spim: Remove nrf_frequency_t handling")'
introduced two changes, one of them is removing the function
get_nrf_spim_frequency with a strange justification.
This change  breaks support for peripherals written in a common way,
where the maximum frequency is set to the maximum supported
by the peripheral, not the controller, see shields for example.

On the occasion of bringing it back, the original function was
refactored to be easier to read and understand.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2023-05-17 16:21:52 +02:00
Shawn Nematbakhsh 5002ea4c42 drivers: spi: Add OpenTitan SPI driver
Add driver for OpenTitan SPI host.

Tested and verified single SPI full duplex on opentitan_earlgrey in
Verilator.

Signed-off-by: Shawn Nematbakhsh <shawn@rivosinc.com>
2023-05-10 16:48:46 +09:00
Tom Burdick e4b10328b4 rtio: Use mpsc for submission and completion queue
Rather than the rings, which weren't shared between userspace and kernel
space in Zephyr like they are in Linux with io_uring, use atomic mpsc
queues for submission and completion queues.

Most importantly this removes a potential head of line blocker in the
submission queue as the sqe would be held until a task is completed.

As additional bonuses this avoids some additional locks and restrictions
about what can be submitted and where. It also removes the need for
two executors as all chains/transactions are done concurrently.

Lastly this opens up the possibility for a common pool of sqe's to
allocate from potentially saving lots of memory.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2023-05-10 00:39:43 +09:00
Dean Sellers 308cec45b0 drivers: spi: esp32xx: Add chip select setup and hold time
Added device tree bindings and implementaion for setting the
spi controllers chip select setup and hold time settings.

Signed-off-by: Dean Sellers <dsellers@evos.com.au>
2023-05-09 14:31:15 +02:00