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>
This commit is contained in:
Andrzej Głąbek 2023-07-20 09:58:43 +02:00 committed by Carles Cufí
commit fa609e5844
6 changed files with 48 additions and 118 deletions

View file

@ -16,9 +16,9 @@ zephyr_library_sources_ifdef(CONFIG_SPI_SAM spi_sam.c)
zephyr_library_sources_ifdef(CONFIG_SPI_SAM0 spi_sam0.c) zephyr_library_sources_ifdef(CONFIG_SPI_SAM0 spi_sam0.c)
zephyr_library_sources_ifdef(CONFIG_SPI_SIFIVE spi_sifive.c) zephyr_library_sources_ifdef(CONFIG_SPI_SIFIVE spi_sifive.c)
zephyr_library_sources_ifdef(CONFIG_SPI_RV32M1_LPSPI spi_rv32m1_lpspi.c) zephyr_library_sources_ifdef(CONFIG_SPI_RV32M1_LPSPI spi_rv32m1_lpspi.c)
zephyr_library_sources_ifdef(CONFIG_NRFX_SPI spi_nrfx_spi.c) zephyr_library_sources_ifdef(CONFIG_SPI_NRFX_SPI spi_nrfx_spi.c)
zephyr_library_sources_ifdef(CONFIG_NRFX_SPIM spi_nrfx_spim.c) zephyr_library_sources_ifdef(CONFIG_SPI_NRFX_SPIM spi_nrfx_spim.c)
zephyr_library_sources_ifdef(CONFIG_NRFX_SPIS spi_nrfx_spis.c) zephyr_library_sources_ifdef(CONFIG_SPI_NRFX_SPIS spi_nrfx_spis.c)
zephyr_library_sources_ifdef(CONFIG_SPI_LITESPI spi_litespi.c) zephyr_library_sources_ifdef(CONFIG_SPI_LITESPI spi_litespi.c)
zephyr_library_sources_ifdef(CONFIG_SPI_OC_SIMPLE spi_oc_simple.c) zephyr_library_sources_ifdef(CONFIG_SPI_OC_SIMPLE spi_oc_simple.c)
zephyr_library_sources_ifdef(CONFIG_SPI_XEC_QMSPI spi_xec_qmspi.c) zephyr_library_sources_ifdef(CONFIG_SPI_XEC_QMSPI spi_xec_qmspi.c)

View file

@ -11,6 +11,30 @@ menuconfig SPI_NRFX
if SPI_NRFX if SPI_NRFX
config SPI_NRFX_SPI
def_bool y
depends on DT_HAS_NORDIC_NRF_SPI_ENABLED
select NRFX_SPI0 if HAS_HW_NRF_SPI0
select NRFX_SPI1 if HAS_HW_NRF_SPI1
select NRFX_SPI2 if HAS_HW_NRF_SPI2
config SPI_NRFX_SPIM
def_bool y
depends on DT_HAS_NORDIC_NRF_SPIM_ENABLED
select NRFX_SPIM0 if HAS_HW_NRF_SPIM0
select NRFX_SPIM1 if HAS_HW_NRF_SPIM1
select NRFX_SPIM2 if HAS_HW_NRF_SPIM2
select NRFX_SPIM3 if HAS_HW_NRF_SPIM3
select NRFX_SPIM4 if HAS_HW_NRF_SPIM4
config SPI_NRFX_SPIS
def_bool y
depends on DT_HAS_NORDIC_NRF_SPIS_ENABLED
select NRFX_SPIS0 if HAS_HW_NRF_SPIS0
select NRFX_SPIS1 if HAS_HW_NRF_SPIS1
select NRFX_SPIS2 if HAS_HW_NRF_SPIS2
select NRFX_SPIS3 if HAS_HW_NRF_SPIS3
config SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58 config SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
depends on SOC_NRF52832 depends on SOC_NRF52832
bool "Allow enabling the SPIM driver despite PAN 58" bool "Allow enabling the SPIM driver despite PAN 58"
@ -28,106 +52,10 @@ config SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
then nRF52832 PPI and GPIOTE resources can be saved by not then nRF52832 PPI and GPIOTE resources can be saved by not
enabling 'anomaly-58-workaround' via the Devicetree. enabling 'anomaly-58-workaround' via the Devicetree.
config SPI_0_NRF_SPI
def_bool HAS_HW_NRF_SPI0
select NRFX_SPI0
help
Enable nRF SPI Master without EasyDMA on port 0.
config SPI_0_NRF_SPIM
def_bool HAS_HW_NRF_SPIM0
# 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 (!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 HAS_HW_NRF_SPIS0
depends on SPI_SLAVE
select NRFX_SPIS0
help
Enable nRF SPI Slave with EasyDMA on port 0.
Due to hardware limitations the implementation supports only simple
buffers (consisting of one part) located in RAM.
config SPI_1_NRF_SPI
def_bool HAS_HW_NRF_SPI1
select NRFX_SPI1
help
Enable nRF SPI Master without EasyDMA on port 1.
config SPI_1_NRF_SPIM
def_bool HAS_HW_NRF_SPIM1
# 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 (!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 HAS_HW_NRF_SPIS1
depends on SPI_SLAVE
select NRFX_SPIS1
help
Enable nRF SPI Slave with EasyDMA on port 1.
Due to hardware limitations the implementation supports only simple
buffers (consisting of one part) located in RAM.
config SPI_2_NRF_SPI
def_bool HAS_HW_NRF_SPI2
select NRFX_SPI2
help
Enable nRF SPI Master without EasyDMA on port 2.
config SPI_2_NRF_SPIM
def_bool HAS_HW_NRF_SPIM2
# 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 (!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 HAS_HW_NRF_SPIS2
depends on SPI_SLAVE
select NRFX_SPIS2
help
Enable nRF SPI Slave with EasyDMA on port 2.
Due to hardware limitations the implementation supports only simple
buffers (consisting of one part) located in RAM.
config SPI_3_NRF_SPIM
def_bool HAS_HW_NRF_SPIM3
select NRFX_SPIM3
help
Enable nRF SPI Master with EasyDMA on port 3.
config SPI_3_NRF_SPIS
def_bool HAS_HW_NRF_SPIS3
depends on SPI_SLAVE
select NRFX_SPIS3
help
Enable nRF SPI Slave with EasyDMA on port 3.
Due to hardware limitations the implementation supports only simple
buffers (consisting of one part) located in RAM.
config SPI_4_NRF_SPIM
def_bool HAS_HW_NRF_SPIM4
select NRFX_SPIM4
help
Enable nRF SPI Master with EasyDMA on port 4.
config SPI_NRFX_RAM_BUFFER_SIZE config SPI_NRFX_RAM_BUFFER_SIZE
int "Size of RAM buffers for SPIM peripherals" int "Size of RAM buffers for SPIM peripherals"
default 8 default 8
depends on NRFX_SPIM depends on SPI_NRFX_SPIM
help help
SPIM peripherals cannot transmit data directly from flash. Therefore, SPIM peripherals cannot transmit data directly from flash. Therefore,
a buffer in RAM needs to be provided for each instance of SPI driver a buffer in RAM needs to be provided for each instance of SPI driver

View file

@ -423,14 +423,14 @@ static int spi_nrfx_init(const struct device *dev)
POST_KERNEL, CONFIG_SPI_INIT_PRIORITY, \ POST_KERNEL, CONFIG_SPI_INIT_PRIORITY, \
&spi_nrfx_driver_api) &spi_nrfx_driver_api)
#ifdef CONFIG_SPI_0_NRF_SPI #ifdef CONFIG_HAS_HW_NRF_SPI0
SPI_NRFX_SPI_DEFINE(0); SPI_NRFX_SPI_DEFINE(0);
#endif #endif
#ifdef CONFIG_SPI_1_NRF_SPI #ifdef CONFIG_HAS_HW_NRF_SPI1
SPI_NRFX_SPI_DEFINE(1); SPI_NRFX_SPI_DEFINE(1);
#endif #endif
#ifdef CONFIG_SPI_2_NRF_SPI #ifdef CONFIG_HAS_HW_NRF_SPI2
SPI_NRFX_SPI_DEFINE(2); SPI_NRFX_SPI_DEFINE(2);
#endif #endif

View file

@ -23,6 +23,12 @@ LOG_MODULE_REGISTER(spi_nrfx_spim, CONFIG_SPI_LOG_LEVEL);
#include "spi_context.h" #include "spi_context.h"
#if defined(CONFIG_SOC_NRF52832) && !defined(CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58)
#error This driver is not available by default for nRF52832 because of Product Anomaly 58 \
(SPIM: An additional byte is clocked out when RXD.MAXCNT == 1 and TXD.MAXCNT <= 1). \
Use CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58=y to override this limitation.
#endif
#if (CONFIG_SPI_NRFX_RAM_BUFFER_SIZE > 0) #if (CONFIG_SPI_NRFX_RAM_BUFFER_SIZE > 0)
#define SPI_BUFFER_IN_RAM 1 #define SPI_BUFFER_IN_RAM 1
#endif #endif
@ -613,22 +619,22 @@ static int spi_nrfx_init(const struct device *dev)
DT_PHANDLE(SPIM(idx), memory_regions)))))), \ DT_PHANDLE(SPIM(idx), memory_regions)))))), \
()) ())
#ifdef CONFIG_SPI_0_NRF_SPIM #ifdef CONFIG_HAS_HW_NRF_SPIM0
SPI_NRFX_SPIM_DEFINE(0); SPI_NRFX_SPIM_DEFINE(0);
#endif #endif
#ifdef CONFIG_SPI_1_NRF_SPIM #ifdef CONFIG_HAS_HW_NRF_SPIM1
SPI_NRFX_SPIM_DEFINE(1); SPI_NRFX_SPIM_DEFINE(1);
#endif #endif
#ifdef CONFIG_SPI_2_NRF_SPIM #ifdef CONFIG_HAS_HW_NRF_SPIM2
SPI_NRFX_SPIM_DEFINE(2); SPI_NRFX_SPIM_DEFINE(2);
#endif #endif
#ifdef CONFIG_SPI_3_NRF_SPIM #ifdef CONFIG_HAS_HW_NRF_SPIM3
SPI_NRFX_SPIM_DEFINE(3); SPI_NRFX_SPIM_DEFINE(3);
#endif #endif
#ifdef CONFIG_SPI_4_NRF_SPIM #ifdef CONFIG_HAS_HW_NRF_SPIM4
SPI_NRFX_SPIM_DEFINE(4); SPI_NRFX_SPIM_DEFINE(4);
#endif #endif

View file

@ -301,18 +301,18 @@ static int spi_nrfx_init(const struct device *dev)
CONFIG_SPI_INIT_PRIORITY, \ CONFIG_SPI_INIT_PRIORITY, \
&spi_nrfx_driver_api) &spi_nrfx_driver_api)
#ifdef CONFIG_SPI_0_NRF_SPIS #ifdef CONFIG_HAS_HW_NRF_SPIS0
SPI_NRFX_SPIS_DEFINE(0); SPI_NRFX_SPIS_DEFINE(0);
#endif #endif
#ifdef CONFIG_SPI_1_NRF_SPIS #ifdef CONFIG_HAS_HW_NRF_SPIS1
SPI_NRFX_SPIS_DEFINE(1); SPI_NRFX_SPIS_DEFINE(1);
#endif #endif
#ifdef CONFIG_SPI_2_NRF_SPIS #ifdef CONFIG_HAS_HW_NRF_SPIS2
SPI_NRFX_SPIS_DEFINE(2); SPI_NRFX_SPIS_DEFINE(2);
#endif #endif
#ifdef CONFIG_SPI_3_NRF_SPIS #ifdef CONFIG_HAS_HW_NRF_SPIS3
SPI_NRFX_SPIS_DEFINE(3); SPI_NRFX_SPIS_DEFINE(3);
#endif #endif

View file

@ -15,10 +15,6 @@ zephyr_library_include_directories(
${ZEPHYR_BASE}/arch/arm/include ${ZEPHYR_BASE}/arch/arm/include
) )
if(CONFIG_SOC_NRF52832) if(CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58 AND CONFIG_SPI_NRFX_SPIM)
if(CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58)
if(CONFIG_SPI_0_NRF_SPIM OR CONFIG_SPI_1_NRF_SPIM OR CONFIG_SPI_2_NRF_SPIM)
message(WARNING "Both SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58 and an NRF SPIM driver are enabled, therefore PAN 58 will apply if RXD.MAXCNT == 1 and TXD.MAXCNT <= 1") message(WARNING "Both SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58 and an NRF SPIM driver are enabled, therefore PAN 58 will apply if RXD.MAXCNT == 1 and TXD.MAXCNT <= 1")
endif()
endif()
endif() endif()