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>
This commit is contained in:
Andrzej Głąbek 2020-03-27 12:53:34 +00:00 committed by Carles Cufí
commit 011e9bac0b
5 changed files with 52 additions and 123 deletions

View file

@ -9,8 +9,6 @@ menuconfig I2C_NRFX
depends on SOC_FAMILY_NRF
help
Enable support for nrfx TWI drivers for nRF MCU series.
Peripherals with the same instance ID cannot be used together,
e.g. I2C_0 and SPI_0. You may need to disable SPI_0 or SPI_1.
if I2C_NRFX
@ -18,96 +16,48 @@ if I2C_NRFX
DT_COMPAT_NORDIC_NRF_TWI := nordic,nrf-twi
DT_COMPAT_NORDIC_NRF_TWIM := nordic,nrf-twim
# In most Nordic SoCs, SPI and TWI peripherals with the same instance
# number share certain resources and therefore cannot be used at the
# same time (in nRF91 and nRF53 Series this limitation concerns UART
# peripherals as well). In nRF52810 though, there are only single
# instances of these peripherals and they are arranged in a different
# way, so this limitation does not apply.
if I2C_0 && (SOC_NRF52810 || \
(!SPI_0 && !(SOC_SERIES_NRF91X && UART_0_NRF_UARTE)) || \
(!SPI_0 && !(SOC_SERIES_NRF53X && UART_0_NRF_UARTE)))
config I2C_0_NRF_TWI
def_bool $(dt_nodelabel_has_compat,i2c0,$(DT_COMPAT_NORDIC_NRF_TWI))
depends on HAS_HW_NRF_TWI0
select NRFX_TWI0
help
Enable nRF TWI Master without EasyDMA on port 0.
config I2C_0_NRF_TWIM
def_bool $(dt_nodelabel_has_compat,i2c0,$(DT_COMPAT_NORDIC_NRF_TWIM))
depends on HAS_HW_NRF_TWIM0
select NRFX_TWIM0
help
Enable nRF TWI Master with EasyDMA on port 0.
This peripheral accepts transfers from RAM only,
if provided buffer is placed in flash, transfer will fail.
endif # I2C_0 && (SOC_NRF52810 || ...
# In Nordic SoCs, SPI and TWI peripherals with the same instance number
# share certain resources and therefore cannot be used at the same time
# (in nRF91 and nRF53 Series this limitation concerns UART peripherals
# as well).
if I2C_1 && !SPI_1 && \
!(SOC_SERIES_NRF91X && UART_1_NRF_UARTE) && \
!(SOC_SERIES_NRF53X && UART_1_NRF_UARTE)
config I2C_1_NRF_TWI
def_bool $(dt_nodelabel_has_compat,i2c1,$(DT_COMPAT_NORDIC_NRF_TWI))
depends on HAS_HW_NRF_TWI1
select NRFX_TWI1
help
Enable nRF TWI Master without EasyDMA on port 1.
config I2C_1_NRF_TWIM
def_bool $(dt_nodelabel_has_compat,i2c1,$(DT_COMPAT_NORDIC_NRF_TWIM))
depends on HAS_HW_NRF_TWIM1
select NRFX_TWIM1
help
Enable nRF TWI Master with EasyDMA on port 1.
This peripheral accepts transfers from RAM only,
if provided buffer is placed in flash, transfer will fail.
endif # I2C_1 && !SPI_1 && ...
# In Nordic SoCs, SPI and TWI peripherals with the same instance number
# share certain resources and therefore cannot be used at the same time
# (in nRF91 and nRF53 Series this limitation concerns UART peripherals
# as well).
if I2C_2 && !SPI_2 && \
!(SOC_SERIES_NRF91X && UART_2_NRF_UARTE) && \
!(SOC_SERIES_NRF53X && UART_2_NRF_UARTE)
config I2C_2_NRF_TWIM
def_bool $(dt_nodelabel_has_compat,i2c2,$(DT_COMPAT_NORDIC_NRF_TWIM))
depends on HAS_HW_NRF_TWIM2
select NRFX_TWIM2
help
Enable nRF TWI Master with EasyDMA on port 2.
This peripheral accepts transfers from RAM only,
if provided buffer is placed in flash, transfer will fail.
endif # I2C_2 && !SPI_2 && ...
# In Nordic SoCs, SPI and TWI peripherals with the same instance number
# share certain resources and therefore cannot be used at the same time
# (in nRF91 and nRF53 Series this limitation concerns UART peripherals
# as well).
if I2C_3 && !SPI_3 && \
!(SOC_SERIES_NRF91X && UART_3_NRF_UARTE) && \
!(SOC_SERIES_NRF53X && UART_3_NRF_UARTE)
config I2C_3_NRF_TWIM
def_bool $(dt_nodelabel_has_compat,i2c3,$(DT_COMPAT_NORDIC_NRF_TWIM))
depends on HAS_HW_NRF_TWIM3
select NRFX_TWIM3
help
Enable nRF TWI Master with EasyDMA on port 3.
This peripheral accepts transfers from RAM only,
if provided buffer is placed in flash, transfer will fail.
endif # I2C_3 && !SPI_3 && ...
endif # I2C_NRFX

View file

@ -24,17 +24,12 @@ DT_COMPAT_NORDIC_NRF_UARTE := nordic,nrf-uarte
# ----------------- port 0 -----------------
config UART_0_NRF_UART
def_bool $(dt_nodelabel_has_compat,uart0,$(DT_COMPAT_NORDIC_NRF_UART))
depends on HAS_HW_NRF_UART0
select NRF_UART_PERIPHERAL
help
Enable nRF UART without EasyDMA on port 0.
config UART_0_NRF_UARTE
def_bool $(dt_nodelabel_has_compat,uart0,$(DT_COMPAT_NORDIC_NRF_UARTE))
# In nRF91 and nRF53 Series SoCs, UART peripherals share certain resources with
# SPI and TWI peripherals having the same instance number, and therefore
# these cannot be used simultaneously.
depends on HAS_HW_NRF_UARTE0 && !((SOC_SERIES_NRF91X || SOC_SERIES_NRF53X) && (SPI_0 || I2C_0))
select NRF_UARTE_PERIPHERAL
help
Enable nRF UART with EasyDMA on port 0.
@ -104,10 +99,6 @@ endif # UART_0_NRF_UART || UART_0_NRF_UARTE
# ----------------- port 1 -----------------
config UART_1_NRF_UARTE
def_bool $(dt_nodelabel_has_compat,uart1,$(DT_COMPAT_NORDIC_NRF_UARTE))
# In nRF91 and nRF53 Series SoCs, UART peripherals share certain resources with
# SPI and TWI peripherals having the same instance number, and therefore
# these cannot be used simultaneously.
depends on HAS_HW_NRF_UARTE1 && !((SOC_SERIES_NRF91X || SOC_SERIES_NRF53X) && (SPI_1 || I2C_1))
select NRF_UARTE_PERIPHERAL
help
Enable nRF UART with EasyDMA on port 1.
@ -176,10 +167,6 @@ endif # UART_1_NRF_UARTE
# ----------------- port 2 -----------------
config UART_2_NRF_UARTE
def_bool $(dt_nodelabel_has_compat,uart2,$(DT_COMPAT_NORDIC_NRF_UARTE))
# In nRF91 and nRF53 Series SoCs, UART peripherals share certain resources with
# SPI and TWI peripherals having the same instance number, and therefore
# these cannot be used simultaneously.
depends on HAS_HW_NRF_UARTE2 && !((SOC_SERIES_NRF91X || SOC_SERIES_NRF53X) && (SPI_2 || I2C_2))
select NRF_UARTE_PERIPHERAL
help
Enable nRF UART with EasyDMA on port 2.
@ -247,10 +234,6 @@ endif # UART_2_NRF_UARTE
# ----------------- port 3 -----------------
config UART_3_NRF_UARTE
def_bool $(dt_nodelabel_has_compat,uart3,$(DT_COMPAT_NORDIC_NRF_UARTE))
# In nRF91 and nRF53 Series SoCs, UART peripherals share certain resources with
# SPI and TWI peripherals having the same instance number, and therefore
# these cannot be used simultaneously.
depends on HAS_HW_NRF_UARTE3 && !((SOC_SERIES_NRF91X || SOC_SERIES_NRF53X) && (SPI_3 || I2C_3))
select NRF_UARTE_PERIPHERAL
help
Enable nRF UART with EasyDMA on port 3.

View file

@ -7,8 +7,6 @@ menuconfig SPI_NRFX
depends on SOC_FAMILY_NRF
help
Enable support for nrfx SPI drivers for nRF MCU series.
Peripherals with the same instance ID cannot be used together,
e.g. SPI_0 and I2C_0. You may need to disable I2C_0 or I2C_1.
if SPI_NRFX
@ -30,18 +28,8 @@ DT_COMPAT_NORDIC_NRF_SPI := nordic,nrf-spi
DT_COMPAT_NORDIC_NRF_SPIM := nordic,nrf-spim
DT_COMPAT_NORDIC_NRF_SPIS := nordic,nrf-spis
# In most Nordic SoCs, SPI and TWI peripherals with the same instance number
# share certain resources and therefore cannot be used at the same time
# (in nRF91 and nRF53 Series this limitation concerns UART peripherals as well).
# In nRF52810 though, there are only single instances of these peripherals
# and they are arranged in a different way, so this limitation does not apply.
if SPI_0 && (SOC_NRF52810 || \
(!I2C_0 && !(SOC_SERIES_NRF91X && UART_0_NRF_UARTE)) ||\
(!I2C_0 && !(SOC_SERIES_NRF53X && UART_0_NRF_UARTE)))
config SPI_0_NRF_SPI
def_bool $(dt_nodelabel_has_compat,spi0,$(DT_COMPAT_NORDIC_NRF_SPI))
depends on HAS_HW_NRF_SPI0
select NRFX_SPI0
help
Enable nRF SPI Master without EasyDMA on port 0.
@ -51,14 +39,13 @@ config SPI_0_NRF_SPIM
# This driver is not available for nRF52832 because of Product Anomaly 58
# (SPIM: An additional byte is clocked out when RXD.MAXCNT == 1 and TXD.MAXCNT <= 1)
# Allow the 'EasyDMA' driver only if this automatic safety-disable is overridden
depends on HAS_HW_NRF_SPIM0 && (!SOC_NRF52832 || SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58)
depends on (!SOC_NRF52832 || SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58)
select NRFX_SPIM0
help
Enable nRF SPI Master with EasyDMA on port 0.
config SPI_0_NRF_SPIS
def_bool $(dt_nodelabel_has_compat,spi0,$(DT_COMPAT_NORDIC_NRF_SPIS))
depends on HAS_HW_NRF_SPIS0
depends on SPI_SLAVE
select NRFX_SPIS0
help
@ -75,18 +62,8 @@ config SPI_0_NRF_ORC
Over-read character. Character clocked out after an over-read
of the transmit buffer.
endif # SPI_0 && (SOC_NRF52810 || ...
# In Nordic SoCs, SPI and TWI peripherals with the same instance number
# share certain resources and therefore cannot be used at the same time
# (in nRF91 and nRF53 Series this limitation concerns UART peripherals as well).
if SPI_1 && !I2C_1 && \
!(SOC_SERIES_NRF91X && UART_1_NRF_UARTE) && \
!(SOC_SERIES_NRF53X && UART_1_NRF_UARTE)
config SPI_1_NRF_SPI
def_bool $(dt_nodelabel_has_compat,spi1,$(DT_COMPAT_NORDIC_NRF_SPI))
depends on HAS_HW_NRF_SPI1
select NRFX_SPI1
help
Enable nRF SPI Master without EasyDMA on port 1.
@ -96,14 +73,13 @@ config SPI_1_NRF_SPIM
# This driver is not available for nRF52832 because of Product Anomaly 58
# (SPIM: An additional byte is clocked out when RXD.MAXCNT == 1 and TXD.MAXCNT <= 1)
# Allow the 'EasyDMA' driver only if this automatic safety-disable is overridden
depends on HAS_HW_NRF_SPIM1 && (!SOC_NRF52832 || SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58)
depends on (!SOC_NRF52832 || SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58)
select NRFX_SPIM1
help
Enable nRF SPI Master with EasyDMA on port 1.
config SPI_1_NRF_SPIS
def_bool $(dt_nodelabel_has_compat,spi1,$(DT_COMPAT_NORDIC_NRF_SPIS))
depends on HAS_HW_NRF_SPIS1
depends on SPI_SLAVE
select NRFX_SPIS1
help
@ -120,18 +96,8 @@ config SPI_1_NRF_ORC
Over-read character. Character clocked out after an over-read
of the transmit buffer.
endif # SPI_1 && !I2C_1 && !(SOC_SERIES_NRF91X && UART_1_NRF_UARTE) && ...
# In Nordic SoCs, SPI and TWI peripherals with the same instance number
# share certain resources and therefore cannot be used at the same time
# (in nRF91 and nRF53 Series this limitation concerns UART peripherals as well).
if SPI_2 && !I2C_2 && \
!(SOC_SERIES_NRF91X && UART_2_NRF_UARTE) && \
!(SOC_SERIES_NRF53X && UART_2_NRF_UARTE)
config SPI_2_NRF_SPI
def_bool $(dt_nodelabel_has_compat,spi2,$(DT_COMPAT_NORDIC_NRF_SPI))
depends on HAS_HW_NRF_SPI2
select NRFX_SPI2
help
Enable nRF SPI Master without EasyDMA on port 2.
@ -141,14 +107,13 @@ config SPI_2_NRF_SPIM
# This driver is not available for nRF52832 because of Product Anomaly 58
# (SPIM: An additional byte is clocked out when RXD.MAXCNT == 1 and TXD.MAXCNT <= 1)
# Allow the 'EasyDMA' driver only if this automatic safety-disable is overridden
depends on HAS_HW_NRF_SPIM2 && (!SOC_NRF52832 || SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58)
depends on (!SOC_NRF52832 || SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58)
select NRFX_SPIM2
help
Enable nRF SPI Master with EasyDMA on port 2.
config SPI_2_NRF_SPIS
def_bool $(dt_nodelabel_has_compat,spi2,$(DT_COMPAT_NORDIC_NRF_SPIS))
depends on HAS_HW_NRF_SPIS2
depends on SPI_SLAVE
select NRFX_SPIS2
help
@ -165,25 +130,14 @@ config SPI_2_NRF_ORC
Over-read character. Character clocked out after an over-read
of the transmit buffer.
endif # SPI_2 && !I2C_2 && !(SOC_SERIES_NRF91X && UART_2_NRF_UARTE) && ...
# In Nordic SoCs, SPI and TWI peripherals with the same instance number
# share certain resources and therefore cannot be used at the same time
# (in nRF91 and nRF53 Series this limitation concerns UART peripherals as well).
if SPI_3 && !I2C_3 && \
!(SOC_SERIES_NRF91X && UART_3_NRF_UARTE) && \
!(SOC_SERIES_NRF53X && UART_3_NRF_UARTE)
config SPI_3_NRF_SPIM
def_bool $(dt_nodelabel_has_compat,spi3,$(DT_COMPAT_NORDIC_NRF_SPIM))
depends on HAS_HW_NRF_SPIM3
select NRFX_SPIM3
help
Enable nRF SPI Master with EasyDMA on port 3.
config SPI_3_NRF_SPIS
def_bool $(dt_nodelabel_has_compat,spi3,$(DT_COMPAT_NORDIC_NRF_SPIS))
depends on HAS_HW_NRF_SPIS3
depends on SPI_SLAVE
select NRFX_SPIS3
help
@ -210,13 +164,8 @@ config SPI_3_NRF_RX_DELAY
edge of SCK (leading or trailing, depending on the CPHA setting used)
until the input serial data on MISO is actually sampled.
endif # SPI_3 && !I2C_3 && !(SOC_SERIES_NRF91X && UART_3_NRF_UARTE) && ...
if SPI_4
config SPI_4_NRF_SPIM
def_bool $(dt_nodelabel_has_compat,spi4,$(DT_COMPAT_NORDIC_NRF_SPIM))
depends on HAS_HW_NRF_SPIM4
select NRFX_SPIM4
help
Enable nRF SPI Master with EasyDMA on port 4.
@ -240,8 +189,6 @@ config SPI_4_NRF_RX_DELAY
edge of SCK (leading or trailing, depending on the CPHA setting used)
until the input serial data on MISO is actually sampled.
endif # SPI_4
config SPI_NRFX_RAM_BUFFER_SIZE
int "Size of RAM buffers for SPIM peripherals"
default 0

View file

@ -4,4 +4,5 @@ add_subdirectory(${SOC_SERIES})
zephyr_sources(
validate_base_addresses.c
validate_enabled_instances.c
)

View file

@ -0,0 +1,48 @@
/*
* Copyright (c) 2020 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <kernel.h>
#define I2C_ENABLED(idx) (IS_ENABLED(CONFIG_I2C) && \
DT_HAS_NODE(DT_NODELABEL(i2c##idx)))
#define SPI_ENABLED(idx) (IS_ENABLED(CONFIG_SPI) && \
DT_HAS_NODE(DT_NODELABEL(spi##idx)))
#define UART_ENABLED(idx) (IS_ENABLED(CONFIG_SERIAL) && \
(IS_ENABLED(CONFIG_SOC_SERIES_NRF53X) || \
IS_ENABLED(CONFIG_SOC_SERIES_NRF91X)) && \
DT_HAS_NODE(DT_NODELABEL(uart##idx)))
/*
* In most Nordic SoCs, SPI and TWI peripherals with the same instance number
* share certain resources and therefore cannot be used at the same time (in
* nRF53 and nRF91 Series this limitation concerns UART peripherals as well).
* In nRF52810 though, there are only single instances of these peripherals
* and they are arranged in a different way, so this limitation does not apply.
*
* The build assertions below check if conflicting peripheral instances are not
* enabled simultaneously.
*/
#define CHECK(idx) \
!(I2C_ENABLED(idx) && SPI_ENABLED(idx)) && \
!(I2C_ENABLED(idx) && UART_ENABLED(idx)) && \
!(SPI_ENABLED(idx) && UART_ENABLED(idx))
#define MSG(idx) \
"Only one of the following peripherals can be enabled: " \
"SPI"#idx", SPIM"#idx", SPIS"#idx", TWI"#idx", TWIM"#idx", TWIS"#idx \
IF_ENABLED(CONFIG_SOC_SERIES_NRF53X, (", UARTE"#idx)) \
IF_ENABLED(CONFIG_SOC_SERIES_NRF91X, (", UARTE"#idx)) \
". Check nodes with status \"okay\" in zephyr.dts."
#if !IS_ENABLED(CONFIG_SOC_NRF52810)
BUILD_ASSERT(CHECK(0), MSG(0));
#endif
BUILD_ASSERT(CHECK(1), MSG(1));
BUILD_ASSERT(CHECK(2), MSG(2));
BUILD_ASSERT(CHECK(3), MSG(3));