Commit graph

512 commits

Author SHA1 Message Date
Michael Hope e68287dd90 drivers: spi: fix the fast path on the SAM0 driver
To keep the bus fully loaded, the SAM0 has a fast path that recognises
special cases like TX only, RX only, or TX/RX of the same size.
Commit #ea2431f32f7 accidentally disabled this.

This increases the utilisation from around 30 % to around 90 % at 48
MHz.

Signed-off-by: Michael Hope <mlhx@google.com>
2020-07-06 10:02:14 -04:00
Michael Hope 8181eede5d drivers: spi: ensure the first byte has been loaded in the TX fast path
The SAM0 has a data register and a shift register.  Data that is
written to the data register is transferred to the shift register by
the peripheral.

On the SAMD51, the CPU is fast enough that the first data write hasn't
been transferred to the shift register by the time the next data write
occurs, causing the second write to be dropped, causing the receiver
to wait forever.

Fix by spinning until the data register is empty.

Signed-off-by: Michael Hope <mlhx@google.com>
2020-07-06 10:01:35 -04:00
Maureen Helm 10c1ded452 drivers: spi: Add optional delays to mcux dspi and lpspi drivers
Adds optional device tree properties to set delays between spi chip
select assert/deassert and clock edges in the mcux dspi and lpspi
drivers. If these properties are not set, then the minimum supported
delays are used.

Verified that tests/drivers/spi/spi_loopback/ still passes on
mimxrt1050_evk (lpspi driver) and frdm_k64f (dspi driver).

Measured with a scope that the pcs-sck-delay and sck-pcs-delay times on
the first spi transaction in the test are reduced from 7.82 us to 20 ns
on mimxrt1050_evk.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2020-07-02 07:57:36 -04:00
Jordan Yates 5963ebaf33 drivers: spi: CS configuration through devicetree
Add an additional option to the spi_cs_control struct that records how
the pin has been configured in devicetree. For drivers that are not
updated, the CS behaviour is the same as before (Push-Pull).

Use the devicetree knowledge with the GPIO subsystem so that the correct
physical pin levels for the CS pin are automatically selected.

Fixes #26267

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2020-07-01 16:40:03 -05:00
Karsten Koenig 189ae8c890 drivers: spi: rv32m1_lpspi: Fix null tx
Initialize the dummy data transfer so spi transfer is defined even for
an undefined tx data buffer. This aligns the rv32m1 spi driver with the
mcux spi driver.

Signed-off-by: Karsten Koenig <karsten.koenig.030@gmail.com>
2020-06-17 09:30:12 +02:00
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Martí Bolívar 3852e08126 drivers: spi_ll_stm32: fix COND_CODE_1 usage
The consequent and alternate expressions for COND_CODE_1 must be
enclosed in parentheses, like this:

COND_CODE_1(PREDICATE, (consequent), (alternate))

The parens are missing in exactly one place in the tree. Fix it.

Reported-by: Peter Bigot <peter.bigot@nordicsemi.no>
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-29 23:07:19 +02:00
Vincent Wan 002de4decf drivers: spi: cc13xx_cc26xx: set power config based on SPI base addr
The power configuration is dependent on which SPI is physically used.
In order to allow DT_INST_FOREACH_STATUS_OKAY() to iterate through
instances without the assumption that index 0 corresponds to SPI0
(which would be incorrect in the case when only SPI1 is enabled),
we need to check the base address to identify which SPI is being dealt
with.

Fixes #25673

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2020-05-28 10:30:14 +02:00
Erwan Gouriou ac98a786d4 drivers/spi: stm32: Fix use of single dma channel
Current dma struture code didn't allowed only rx channel removal,
disabling tx channel (in spi client node) was leading compilation
issue.
Fix this by moving conditional code inside SPI_DMA_CHANNEL macro and
get the part of code which is present or removed (SPI_DMA_CHANNEL_INIT)
outside of {}.
Additionally, fix indentation on '\' in whole instance init macros

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-05-18 19:14:37 +02:00
Martí Bolívar 6e8775ff84 devicetree: remove DT_HAS_NODE_STATUS_OKAY
Several reviewers agreed that DT_HAS_NODE_STATUS_OKAY(...) was an
undesirable API for the following reasons:

- it's inconsistent with the rest of the DT_NODE_HAS_FOO names
- DT_NODE_HAS_FOO_BAR_BAZ(node) was agreed upon as a shorthand
  for macros which are equivalent to
  DT_NODE_HAS_FOO(node) && DT_NODE_HAS_BAR(node) &&
- DT_NODE_HAS_BAZ(node), and DT_HAS_NODE_STATUS_OKAY is an odd duck
- DT_NODE_HAS_STATUS(..., okay) was viewed as more readable anyway
- it is seen as a somewhat aesthetically challenged name

Replace all users with DT_NODE_HAS_STATUS(..., okay), which is
semantically equivalent.

This is mostly done with sed, but a few remaining cases were done by
hand, along with whitespace, docs, and comment changes. These special
cases include the Nordic SOC static assert files.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-13 18:24:42 +02:00
Francois Ramu 1a163673c7 drivers: spi: driver reloading dma buffers in the main transceive loop
With this change, the spi transceive with dma function
waits for the spi busy flag reset and for the dma transfer end.
Then it reloads the channels until all buffers are consumed.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2020-05-13 16:22:10 +02:00
Francois Ramu c83e2a41ae drivers: spi: driver dma callback function to set transfer flag
This change avoids the reload of the dma channel
in the callback function, just sets the corresponding Tx, Rx flag.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2020-05-13 16:22:10 +02:00
Martí Bolívar 7e0eed9235 devicetree: allow access to all nodes
Usually, we want to operate only on "available" device
nodes ("available" means "status is okay and a matching binding is
found"), but that's not true in all cases.

Sometimes we want to operate on special nodes without matching
bindings, such as those describing memory.

To handle the distinction, change various additional devicetree APIs
making it clear that they operate only on available device nodes,
adjusting gen_defines and devicetree.h implementation details
accordingly:

- emit macros for all existing nodes in gen_defines.py, regardless
  of status or matching binding
- rename DT_NUM_INST to DT_NUM_INST_STATUS_OKAY
- rename DT_NODE_HAS_COMPAT to DT_NODE_HAS_COMPAT_STATUS_OKAY
- rename DT_INST_FOREACH to DT_INST_FOREACH_STATUS_OKAY
- rename DT_ANY_INST_ON_BUS to DT_ANY_INST_ON_BUS_STATUS_OKAY
- rewrite DT_HAS_NODE_STATUS_OKAY in terms of a new DT_NODE_HAS_STATUS
- resurrect DT_HAS_NODE in the form of DT_NODE_EXISTS
- remove DT_COMPAT_ON_BUS as a public API
- use the new default_prop_types edtlib parameter

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-08 19:37:18 -05:00
Tomasz Bursztyka 97326c0445 device: Fix structure attributes access
Since struct devconfig was merged earlier into struct device, let's fix
accessing config_info, name, ... attributes everywhere via:

grep -rlZ 'dev->config->' | xargs -0 sed -i 's/dev->config->/dev->/g'

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-05-08 23:07:44 +02:00
Kumar Gala 0a7d4e2135 devicetree: Change DT_FOREACH_IMPL_ to not insert semicolon
Remove semicolon between instance invocations of DT_FOREACH_IMPL_ and
thus DT_INST_FOREACH.  This provides more flexibility to the user.  This
requires we fixup in tree users to add semicolon where needed.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-07 20:03:56 -05:00
Andrei Gansari ec7fad0853 drivers: spi_mcux_flexcomm clock increase
Attached Flexcomm SPI driver to the main clock used by the core.
This means setting the SPI clock the same value as the core clock.

Signed-off-by: Andrei Gansari <andrei.gansari@nxp.com>
2020-05-07 12:47:34 -05:00
Kumar Gala a58777e251 drivers: dma: atmel_sam0: Convert to use devicetree macros for dma dev
Convert to using DT_INST_LABEL() in the dma driver and convert dma users
to use the DMA property macros to get the dma controller name.  We make
the assumption in the drivers that there is a single DMA controller
instance.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-07 00:49:32 -05:00
Vincent Wan da60111949 drivers: spi: cc13xx_cc26xx: remove usage of CONFIG_SPI_0/1
Clean up as we wish to move away from using these Kconfig settings.
Also removing them from the boards' default config.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2020-05-06 17:48:13 -05:00
Martí Bolívar 87e1743ae0 devicetree: replace DT_HAS_DRV_INST with DT_INST_FOREACH
Make drivers multi-instance wherever possible using DT_INST_FOREACH.
This allows removing DT_HAS_DRV_INST in favor of making drivers just
do the right thing regardless of how many instances there are.

There are a few exceptions:

- SoC drivers which use CMake input files (like i2c_dw.c) or otherwise
  would require more time to convert than I have at the moment. For the
  sake of expediency, just inline the DT_HAS_DRV_INST expansion for
  now in these cases.

- SoC drivers which are explicitly single-instance (like the nRF SAADC
  driver). Again for the sake of expediency, drop a BUILD_ASSERT in
  those cases to make sure the assumption that all supported SoCs have
  at most one available instance is valid, failing fast otherwise.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-06 17:35:08 -05:00
Kumar Gala fdd85d5ad7 dts: Rename DT_HAS_NODE macro to DT_HAS_NODE_STATUS_OKAY
Rename DT_HAS_NODE to DT_HAS_NODE_STATUS_OKAY so the semantics are
clear.  As going forward DT_HAS_NODE will report if a NODE exists
regardless of its status.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-06 05:25:41 -05:00
Benjamin Valentin 8a99bd0da8 drivers: spi: spi_sam0: fix spi_sam0_fast_txrx()
The optimisation in `spi_sam0_fast_txrx()` is broken, loading
two bytes into the `DATA` register in rapid succession will lose
one byte.

This can be observed by running `tests/drivers/spi/spi_loopback`.
The test will get stuck in `spi_sam0_fast_txrx()` forever waiting
for the final byte.

Undo this small optimisation and only load the next byte into the
`DATA` register after the response has been received.

This fixes `tests/drivers/spi/spi_loopback`.

Signed-off-by: Benjamin Valentin <benpicco@googlemail.com>
2020-05-05 09:58:29 -05:00
Francois Ramu 469e505278 drivers: spi: control of the dma callback on spi client for stm32
The DMA callback function now controls the tx or rx buffers
and reload dma in case of multiple trnasfer before the transfer ends

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2020-05-04 09:46:07 -05:00
Francois Ramu ce093dc35e drivers: spi: Enable dma transfer for SPI on stm32
Enable dma operations with or w/o a dmamux on STM32
for SPI periph/memory operations.
Use the pi dma client with dma macros

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2020-05-04 09:46:07 -05:00
Daniel Leung f59d56b534 drivers: spi: xec_qmspi: Convert to using DT_INST macros
Convert driver to use instance macro's instead of dts_fixup.h based
macros.  This moves us closer to removing both dts_fixup.h and per
instance Kconfig symbols.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2020-04-28 07:43:31 -05:00
Kumar Gala aa63b07019 drivers: spi: spi_sam0: rework devicetree support
Rework the devicetree to utilize new DT_INST macros and extract per
instance data for clocks and dma from devicetree.  We update the
atmel,sam0-spi binding for dma to replace the rxdma and txdma
properties with proper 'dmas' property.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-25 09:30:16 -05:00
Kumar Gala dbeb3ba32e drivers: spi: spi_sam: rework device tree support
Reworked spi_sam driver to utilize new DT_INST macros as part of
this rework we also now get pin ctrl/mux configuration information
from the device tree instead of via Kconfig and defines in soc_pinmap.h

We remove defines from dts_fixup.h and soc_pinmap.h and associated
Kconfig symbols that are no longer needed due to getting all that
information from devicetree.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-25 09:29:54 -05:00
Kumar Gala 8b6acb5e91 soc: arm: replace DT_CPU_CLOCK_FREQUENCY with new dt macros
Replace DT_CPU_CLOCK_FREQUENCY with a PATH based reference to cpu@0
(DT_PATH(cpus, cpu_0)) and than getting the clock_frequency property:

DT_CPU_CLOCK_FREQUENCY -> DT_PROP(DT_PATH(cpus, cpu_0), clock_frequency)

This lets us remove DT_CPU_CLOCK_FREQUENCY from dts_fixup.h.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-23 23:55:37 -05:00
Vincent Wan 0915ccca46 drivers: cc13xx_cc26xx: use DT_INST_FOREACH to reduce code duplication
Use DT_INST_FOREACH macro to combine code used for multiple instances.
Remove unnecessary Kconfig options for UART instances.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2020-04-23 17:29:53 -05:00
Vincent Wan 9d89ce1d6d drivers: cc13xx_cc26xx: Convert drivers to use more new DT_INST macros
Changing more of DT_* prefixed macros that refer to instances to use
DT_INST macros.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2020-04-23 17:29:53 -05:00
Tobias Svehagen 688f506d4b drivers: spi: sifive: Fix bug with checking if tx fifo is full
The check of the SF_TXDATA_FULL flag is only done on the register
address and not on the actual register content.

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2020-04-23 17:28:48 +02:00
Kumar Gala 5999787e6e drivers: spi: spi_stm32: Convert DT_COMPAT_ define usage to new macros
Convert driver from using DT_COMPAT_ST_STM32_SPI_FIFO to new macro
DT_HAS_COMPAT(st_stm32_spi_fifo).

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-23 05:58:17 -05:00
Kumar Gala fac0d7d90e drivers: spi: mcux_lpspi: Convert to DT_INST
Convert driver to use new DT_INST macros throughout.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-20 15:23:47 -05:00
Kumar Gala df302727dc drivers: spi: mcux_flexcomm: Convert to DT_INST
Convert driver to use new DT_INST macros throughout.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-20 15:23:47 -05:00
Kumar Gala 1d33ed3dfc drivers: spi: mcux_dspi: Convert to DT_INST
Convert driver to use new DT_INST macros throughout.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-20 15:23:47 -05:00
Martí Bolívar 44cf00d6e1 drivers: spi: nordic: finish conversion to new DT API
The SPIM driver has been converted already. Convert the SPI and SPIS
drivers too. Leave existing Kconfigs in place.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-04-20 15:43:39 +02:00
Maureen Helm 1b6d4dd223 drivers: spi: Set dummy data in mcux drivers
Sets the "dummy data" value to send when the transmit buffer is null.
Fixes the spi_null_tx_buf test in tests/drivers/spi/spi_loopback on the
lpcxpresso54114 board.

Tested on frdm_k64f, mimxrt1050_evk, and lpcxpresso54114_m4 boards.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2020-04-16 06:01:43 -05:00
Kumar Gala 8c60bc0b07 drivers: spi: rv32m1_spi: Convert driver to new DT_INST macros
Convert driver to use DT_INST macros and remove related board per
instance Kconfig symbol usage.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-10 14:38:04 -05:00
Andrzej Głąbek 011e9bac0b drivers: nrf: Remove no longer suitable dependencies on Kconfig options
Make I2C and SPI drivers for nRF SoCs no longer dependent on Kconfig
options that enable instances (i.e. I2C_x and SPI_x). Now these drivers
enable hardware instances when corresponding nodes in devicetree are
enabled (have status "okay").
For I2C, SPI, and UART drivers, instead of using Kconfig dependencies
to prevent enabling of hardware instances that cannot be used together
(e.g. SPIM1 and TWIM1), a file that signals invalid configurations with
build assertions is added to compilation.
Also dependencies on HAS_HW_NRF_* options are removed from Kconfigs
of I2C, SPI, and UART drivers, as for hidden options that activate
proper type of driver such dependencies are not actually helpful.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2020-04-03 14:47:32 +02:00
Andrzej Głąbek cb0cb3f2e8 drivers/spi/Kconfig.nrfx: Choose driver type basing on DT compatible
Remove prompts from Kconfig options `SPI_x_NRF_SPI*` that select the
type of nrfx driver (for SPI, SPIM, or SPIS peripheral) to be used
for a given instance. This prevents the options from being modified
in configuration files.
Instead, make one of these options selected by default according to the
"compatible" property set for the corresponding SPI node in devicetree.

This eliminates the need of changing both the "compatible" property in
devicetree and the Kconfig option selecting the driver type when a user
wants to switch between SPI, SPIM, and SPIS for a given instance.

Since all `SPI_x_NRF_SPI*` options are made "hidden" by this commit,
all their occurrences in configuration files are removed.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2020-04-03 14:47:32 +02:00
Kumar Gala 36049b1657 drivers: Convert to use DT_INST_FOREACH
Convert drivers that have the following pattern:

   #if DT_INST_NODE_HAS_PROP(0, label)
   INIT_MACRO(0)
   #endif

   ...

   #if DT_INST_NODE_HAS_PROP(n, label)
   INIT_MACRO(n)
   #endif

to use DT_INST_FOREACH(INIT_MACRO) instead.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-31 19:29:22 -05:00
Vincent Wan 16fab6c4f8 drivers: cc13xx_cc26xx: guard references to sleep states
Use of macros such as SYS_POWER_STATE_SLEEP_2 needs to be guarded by
making sure CONFIG_SYS_POWER_SLEEP_STATES is defined.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2020-03-31 07:38:31 -05:00
Oleg Zhurakivskyy b1e1f64d14 global: Replace BUILD_ASSERT_MSG() with BUILD_ASSERT()
Replace all occurences of BUILD_ASSERT_MSG() with BUILD_ASSERT()
as a result of merging BUILD_ASSERT() and BUILD_ASSERT_MSG().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-31 07:18:06 +02:00
Kumar Gala 73c1f8d63e drivers: spi: spi_oc_simple: Convert to new DT_INST macros
Convert older DT_INST_ macro use the new include/devicetree.h
DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-30 13:09:34 -05:00
Kumar Gala 88469b7010 drivers: litex: Convert litex drivers to new DT_INST macros
Convert older DT_INST_ macro use in litex drivers to the new
include/devicetree.h DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-30 12:49:43 -05:00
Kumar Gala 0c4779d413 drivers: spi: spi_dw: Convert to new DT_INST macros
Convert older DT_INST_ macro use the new include/devicetree.h
DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-30 08:29:30 -05:00
Kumar Gala 020a899ec3 drivers: sifive: Convert sifive drivers to new DT_INST macros
Convert older DT_INST_ macro use in sifive drivers to the new
include/devicetree.h DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-26 16:06:09 -05:00
Kumar Gala 989484b4bf drivers: stm32: Convert STM32 drivers to new DT_INST macros
Convert older DT_INST_ macro use in STM32 drivers to the new
include/devicetree.h DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-26 12:22:12 -05:00
Kumar Gala 4cb0a5d992 drivers: silabs: Convert silabs drivers to new DT_INST macros
Convert older DT_INST_ macro use in silab drivers to the new
include/devicetree.h DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-26 05:26:23 -05:00
Kumar Gala e7df99d4ee drivers: cc13xx_cc26xx: Convert drivers to new DT_INST macros
Convert older DT_INST_ macro use in cc13xx_cc26xx drivers to the new
include/devicetree.h DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-26 05:20:19 -05:00
Vincent Wan ddfb1b5ec7 drivers: spi: cc13xx_cc26xx: add power management support
Add a dependency on the SSI resource in the TI Power module, and add
support for device PM.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2020-03-25 16:21:33 -04:00