Commit graph

97 commits

Author SHA1 Message Date
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
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 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 47968e30cf drivers: spi: dw: handle flags differences in driver
Towards cleaning up (and hopefully removing dts_fixup.h in the near
future).  We need to move the handling of different names for the irq
flag propety into the driver and out of dts_fixup.h.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-17 19:37:59 -04:00
Kumar Gala 69c5aa0b32 driver: spi: dw: convert to DT_INST defines
Convert driver to use DT_INST_ defines.  The preferred defines for
drivers are DT_INST_.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-11 07:59:38 -06:00
Tomasz Bursztyka f5a9d5d1a5 driver/spi: Make DT aliases consistent for the DW drivers
And apply it on all existing fixups.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-01-28 18:18:18 -05:00
Maksim Masalski 33336e78f6 drivers: spi: Support PM busy state where relevant in DW
Need to set device busy when enter into transceive function
in SPI DW driver.
In current SPI DW driver the transceive function don't set busy state,
but that is important for PM busy state.
This will lead to unexpected behaviors when system calls this
function and enter into idle state.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-01-13 11:33:12 -05:00
Anas Nashif 578ae40761 boards: remove quarl_se_c1000
This board and SoC was discontinued some time ago and is currently not
maintained in the zephyr tree.
Remove all associated configurations and variants from the tree.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-07-29 21:30:25 -07:00
Piotr Zięcik 4a543e138d drivers: spi_dw: Get clock frequency from DTS
The spi_dw driver used system clock frequency
as a base for SPI bus frequency calculation.
This commit corrects that by obtaining the needed value from DTS.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-07-24 15:10:02 +02:00
Anas Nashif a2fd7d70ec cleanup: include/: move misc/util.h to sys/util.h
move misc/util.h to sys/util.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif bd70f6f1ed cleanup: include/: move spi.h to drivers/spi.h
move spi.h to drivers/spi.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 17ddd1714c cleanup: include/: move clock_control.h to drivers/clock_control.h
move clock_control.h to drivers/clock_control.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif ef281c4237 cleanup: include/: move sys_io.h to sys/sys_io.h
move sys_io.h to sys/sys_io.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 43a49335f4 include: move interrupt controller headers to interrupt_controller/
Move internal and architecture specific headers from include/drivers to
subfolder for interrupt_controller:

include/drivers/interrupt_controller/

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-25 15:27:00 -04:00
Patrik Flykt 97b3bd11a7 drivers: Rename reserved function names
Rename reserved function names in drivers/ subdirectory. Update
function macros concatenatenating function names with '##'. As
there is a conflict between the existing gpio_sch_manage_callback()
and _gpio_sch_manage_callback() names, leave the latter unmodified.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-03 17:31:00 -04:00
Kumar Gala 2b23e04514 spi: spi_dw: Cleanup stale Kconfig symbols that should be DT
Instance 2 & 3 for some reason never transitioned CONFIG_SPI_*_IRQ_* to
DT prefix.  Fix that since those Kconfig symbols will never exist.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-08 09:34:37 -06:00
Patrik Flykt 8ff96b5a57 drivers: Add 'U' to unsigned variable assignments
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Kumar Gala 6d83738e33 dts: spi: cleanup CONFIG_SPI_x_IRQ_PRI
All of the cases of CONFIG_SPI_x_IRQ_PRI should be DT_SPI_x_IRQ_PRI.
So go ahead and fix them up.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-11-21 12:27:16 -05:00
Kumar Gala 1634cf2248 drivers/spi: Always selecet HAS_DTS_SPI once SPI is enabled
All drivers require DTS for their primary SPI settings.

Removing SPI_[0-9]_NAME config option added some more samples changes.
Usage of these options there was anyway not relevant.

Fixes #11064

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-11-16 14:02:00 -05:00
Andrzej Głąbek 20202902f2 dts_fixups: Use DT_ prefix in all defined labels not related to Kconfig
These changes were obtained by running a script  created by
Ulf Magnusson <Ulf.Magnusson@nordicsemi.no> for the following
specification:

1. Read the contents of all dts_fixup.h files in Zephyr
2. Check the left-hand side of the #define macros (i.e. the X in
   #define X Y)
3. Check if that name is also the name of a Kconfig option
   3.a If it is, then do nothing
   3.b If it is not, then replace CONFIG_ with DT_ or add DT_ if it
       has neither of these two prefixes
4. Replace the use of the changed #define in the code itself
   (.c, .h, .ld)

Additionally, some tweaks had to be added to this script to catch some
of the macros used in the code in a parameterized form, e.g.:
- CONFIG_GPIO_STM32_GPIO##__SUFFIX##_BASE_ADDRESS
- CONFIG_UART_##idx##_TX_PIN
- I2C_SBCON_##_num##_BASE_ADDR
and to prevent adding DT_ prefix to the following symbols:
- FLASH_START
- FLASH_SIZE
- SRAM_START
- SRAM_SIZE
- _ROM_ADDR
- _ROM_SIZE
- _RAM_ADDR
- _RAM_SIZE
which are surprisingly also defined in some dts_fixup.h files.

Finally, some manual corrections had to be done as well:
- name##_IRQ -> DT_##name##_IRQ in uart_stm32.c

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2018-11-13 10:44:42 -06:00
Anas Nashif aab35b34ac drivers: spi_dw: remove unused LOG_DOMAIN define
This define for the log domain in obsolete and not being used.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-11-02 15:31:44 -05:00
Kumar Gala aa2bdbe322 drivers: Remove board.h include
We either don't need board.h in the driver or we should be include soc.h
instead.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-11-01 13:21:11 -04:00
Anas Nashif f4fb215148 drivers: spi_dw: remove debug message
Remove debug message using undefined functions.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-08 17:49:12 -04:00
Anas Nashif 88aa2ca49f driver: spi: use new logger
move SPI drivers to use new logger.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-08 17:49:12 -04:00
Maureen Helm 55caa7b743 drivers: spi: Select HAS_DTS_SPI in designware driver
Makes the designware spi driver consistent with other spi drivers by
selecting HAS_DTS_SPI in the driver. This required adding spi nodes and
dts fixups to several arc and x86 socs, as well as enabling those nodes
in associated boards.

Also refactors the driver to use the base address, interrupt number, and
interrupt priority from dts.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2018-09-28 06:27:06 +05:30
Tomasz Bursztyka 33e3ae711e drivers/spi: Handle the case when tx buf/len is NULL/>0 in DW driver
This is a rare but valid case when you request the controller to send
dummy bytes on your behalf (it saves memory as you don't need to provide
a valid buffer, just NULL and the numbers of dummy bytes as length).

Without it, user code can get stuck into interrupt loop.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-05-29 16:21:08 -04:00
Wayne Ren 3f24975514 drivers: spi: fix the bug of slave selection in spi_dw
According to data sheet of dw_spi, ser reg is used to
select spi device/slave.

one bit in ser maps to one spi device/slave, i.e..
cs 0 ---> bit 0
cs 1 ---> bit 1
cs 2 ---> bit 2

the original code has a bug. the config->slave cannot
directly be written into ser. It should be mapped to
the correct bits through 1 << config->slave.

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-05-14 17:23:03 -04:00
Tomasz Bursztyka f4ad698847 drivers/spi: Remove DW spi slave test left over
This reset to 0 was used for testing threshold on slave mode.

Coverity-CID: 185402

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-30 08:07:06 -04:00
Tomasz Bursztyka 011ad6f7db drivers/spi: Fix tmod update on DW driver
Logical or is unsufficent for setting up new tmod: it's required to
remove previous one first. Indeed, 0 as tmod is valid (tx-rx mode), but
previous tmod could be 10 or 01, so a logical or will keep the previous
tmod leading to a bogus transaction.

Fixing also a rebase issue visible when debug mode is enabled. Slave
callback is a left over from a test on spi slave.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-05 12:04:56 +03:00
Tomasz Bursztyka 1086fdf1f4 drivers/spi: spi_context lock makes transceive function reentrant in DW
No need to check on busy bit from hardware.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-04 19:02:35 +02:00
Tomasz Bursztyka 79308dd1a8 drivers/spi: Simplify how error is forwarded from ISR handler in DW
No need to test it twice then in completed().

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-04 19:02:35 +02:00
Tomasz Bursztyka 841a420709 drivers/spi: Add slave mode support to the DesignWare driver
It involves a minor change on which register is configured.
Most of the change is with threshold handling.
Handling the Kconfig based supported mode per-port.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-04 19:02:35 +02:00
Tomasz Bursztyka a863494463 drivers/spi: Enable port 3 and 4 on DW driver
This will be useful on Quark_SE ARC core which can access x86 core SPI
controller.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-04 19:02:35 +02:00
Tomasz Bursztyka 423f0095c7 drivers/spi: Specify options per-port on DW driver
Generalize clock control. Make interrupt policy per-port.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-04 19:02:35 +02:00
Tomasz Bursztyka 57a1f7b4f1 drivers/spi: Add support for TX or RX only modes on DW driver
As for RX only, computing the NDF will be used for EEPROM mode.
Only a way to determine EEPROM mode is missing.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-04 19:02:35 +02:00
Tomasz Bursztyka da42c0077c api/spi: Add a dedicated Kconfig option for asynchronous mode enablement
Instead of using CONFIG_POLL, which is not directly related to SPI and
is a kernel option, let's have SPI_ASYNC instead. When enabled, it will
select POLL automatically.

Fixes #5839

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-04 19:02:35 +02:00
Tomasz Bursztyka ea2431f32f api/spi: Reduce parameter number on transceive function
tx_bufs/tx_count and rx_bufs/rx_count can be hold in another dedicated
structure, thus reducing the number of parameters to transceive. This
permits to avoid using the stack when calling transceive.

Since we saved parameters, we can expose back the struct device pointer,
to stay consistent with other device driver APIs.

Fixes #5839

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-04 19:02:35 +02:00
Tomasz Bursztyka f3f9fab20e api/spi: Make spi_config parameter constant
As the content of this struct will not be modified by drivers, it's
better to pass it as constant. Also, if someday struct device can be
made contant too, this change will make spi ready for registering the
spi_config into ROM directly.

Fixes #5839

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-04 19:02:35 +02:00
Tomasz Bursztyka c968a85d85 drivers/spi: Properly check for rx/tx and buffering on
Current buffers might be configured to skip data, thus only len will be
set, buf will be NULL. Buffer should be used if only len is > 0 and
buffer is valid as well.

tx/rx are "on" if len is > 0
tx/rx buf should be touched if only len is > 0 _and_ buf != NULL.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-01-29 23:30:55 -05:00
Tomasz Bursztyka 5405e93852 drivers/spi: Use sync_status relevantly in DW driver
Removing internal boolean in order to use the proper error code hold in
spi_context which was relevantly added in commit 6c717095b8.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-09-15 08:07:41 -04:00
Michał Kruszewski 12faf2cf92 spi: Allow updating TX and RX of spi context by multiple words.
Previous approach allowed only single word update for single
function call. Updating context in ISR was inefficient for
controllers supporting automatic multiple data packets transaction.

Signed-off-by: Michał Kruszewski <michal.kruszewski@nordicsemi.no>
2017-09-13 09:26:49 -04:00
Marti Bolivar 3ac9ca0859 spi: dw: fix spi_dw_init()
It is incorrect to call spi_context_release() on a
spi_dw_data object's ctx field before data->ctx->config is first
set in spi_dw_configure(). This is because spi_context_release()
reads ctx->config->operation. In particular, during spi_dw_init(),
calling spi_context_release() reads the uninitialized memory in
spi->ctx->config->operation.

Call spi_context_unlock_unconditionally() instead to properly increase
the semaphore count.

Without this patch, the first call to spi_transceive() can block
forever depending on the value of the uninitialized memory holding
spi->ctx->config->operation.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-07-14 18:10:38 +03:00
Kumar Gala b71b86ed03 spi: Cleanup use of C99 types
We introduced some see C99 types, so convert them over to the Zephyr
types.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-06-22 13:47:28 -04:00
Tomasz Bursztyka cced7fd47a api/spi: Change transceive functions signature
Instead of NULL terminated buffer arrays, let's add a parameter for each
that tells the number of spi_buf in it.

It adds a little bit more complexity in driver's side (spi_context.h)
but not on user side (bufer one has to take care of providing the NULL
pointer at the end of the array, now he requires to give the count).

This will saves a significant amount of bytes in more complex setup than
the current dumb spi driver sample.

Fix and Use size_t everywhere (spi_context.h was using u32_t).

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-06-01 10:49:30 -04:00
Tomasz Bursztyka c2913ad025 drivers/spi: Handle ressource locking and release in DW driver
Again this is made as generic as possible through driver's
spi_context API.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-05-19 18:52:25 -04:00
Tomasz Bursztyka 10c1e49f84 api/spi: Add 2 specific control bits for special use cases.
SPI_HOLD_ON_CS can be used to ask the SPI device to keep CS on, after
the transaction. And this undefinitely, until another config is used.
This will inhibate the gpio cs delay, if any. This might be useful when
doing consecutive calls on one slave without releasing the CS.

SPI_LOCK_ON is to be used with caution as it will keep the SPI device
locked for the current config being used after each transaction. This
can be necessary if one needs to do consecutive calls on a slave without
any olher caller to interfere.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-05-19 18:52:25 -04:00
Tomasz Bursztyka 587dd5d275 drivers/spi: Add support for async call in DW driver in a generic way
All is done through the generic spi_context driver's API as it will be
generic to all SPI drivers.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-05-19 18:52:25 -04:00
Tomasz Bursztyka 761a1d9429 api: Add asynchronous call support to SPI API
Adding a struct k_poll_signal parameter to driver's API unique
exposed function.

If not NULL, the call will be handled as asynchronous and will
return right after the transaction has started, on the contrary
of current logic where is waits for the transaction to finish
(= synchronous).

In order to save stack, let's move the device pointer to struct
spi_config. So the call is still at a maximum of 4 parameters.

Adapting spi_dw.c and spi driver sample to the change so it still
builts.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-05-19 18:52:25 -04:00
Tomasz Bursztyka b9838475ac drivers/spi: Handle synchronous calls in a generic manner in DW driver
All SPI drivers have this same way to handle synchronous call, thus
let's generalize it in struct spi_context, with a relevant API and apply
the change into SPI DW driver.

spi_context API will prove to be useful once asynchronous call will be
handled as well, through the same completion functions used now only for
synchronous call. It will be transparent for the driver.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-05-19 18:52:25 -04:00
Tomasz Bursztyka 0bd83d21f2 drivers/spi: Add reentrance support to DW driver in a generic manner
Let's improve common SPI driver context by adding a lock and generic
function to get/release it.

It's statically initialized to save a bit of ROM.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-05-19 18:52:25 -04:00