1313#include <zephyr/drivers/pinctrl.h>
1414#include <zephyr/mem_mgmt/mem_attr.h>
1515#include <soc.h>
16+ #include <dmm.h>
1617#ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
1718#include <nrfx_ppi.h>
1819#endif
@@ -133,9 +134,6 @@ struct spi_nrfx_config {
133134#endif
134135 uint32_t wake_pin ;
135136 nrfx_gpiote_t wake_gpiote ;
136- #ifdef CONFIG_DCACHE
137- uint32_t mem_attr ;
138- #endif
139137#ifdef SPIM_ANY_FAST
140138 const struct device * clk_dev ;
141139 struct nrf_clock_spec clk_spec ;
@@ -144,6 +142,7 @@ struct spi_nrfx_config {
144142 bool cross_domain ;
145143 int8_t default_port ;
146144#endif
145+ void * mem_reg ;
147146};
148147
149148static void event_handler (const nrfx_spim_evt_t * p_event , void * p_context );
@@ -514,11 +513,6 @@ static void transfer_next_chunk(const struct device *dev)
514513 }
515514
516515 memcpy (dev_data -> tx_buffer , tx_buf , chunk_len );
517- #ifdef CONFIG_DCACHE
518- if (dev_config -> mem_attr & DT_MEM_CACHEABLE ) {
519- sys_cache_data_flush_range (dev_data -> tx_buffer , chunk_len );
520- }
521- #endif
522516 tx_buf = dev_data -> tx_buffer ;
523517 }
524518
@@ -535,10 +529,20 @@ static void transfer_next_chunk(const struct device *dev)
535529
536530 dev_data -> chunk_len = chunk_len ;
537531
538- xfer .p_tx_buffer = tx_buf ;
539- xfer .tx_length = spi_context_tx_buf_on (ctx ) ? chunk_len : 0 ;
540- xfer .p_rx_buffer = rx_buf ;
541- xfer .rx_length = spi_context_rx_buf_on (ctx ) ? chunk_len : 0 ;
532+ xfer .tx_length = spi_context_tx_buf_on (ctx ) ? chunk_len : 0 ;
533+ xfer .rx_length = spi_context_rx_buf_on (ctx ) ? chunk_len : 0 ;
534+
535+ error = dmm_buffer_out_prepare (dev_config -> mem_reg , tx_buf , xfer .tx_length ,
536+ (void * * )& xfer .p_tx_buffer );
537+ if (error != 0 ) {
538+ goto out_alloc_failed ;
539+ }
540+
541+ error = dmm_buffer_in_prepare (dev_config -> mem_reg , rx_buf , xfer .rx_length ,
542+ (void * * )& xfer .p_rx_buffer );
543+ if (error != 0 ) {
544+ goto in_alloc_failed ;
545+ }
542546
543547#ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
544548 if (xfer .rx_length == 1 && xfer .tx_length <= 1 ) {
@@ -577,9 +581,7 @@ static void event_handler(const nrfx_spim_evt_t *p_event, void *p_context)
577581{
578582 const struct device * dev = p_context ;
579583 struct spi_nrfx_data * dev_data = dev -> data ;
580- #ifdef CONFIG_DCACHE
581584 const struct spi_nrfx_config * dev_config = dev -> config ;
582- #endif
583585
584586 if (p_event -> type == NRFX_SPIM_EVENT_DONE ) {
585587 /* Chunk length is set to 0 when a transaction is aborted
@@ -593,15 +595,21 @@ static void event_handler(const nrfx_spim_evt_t *p_event, void *p_context)
593595#ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
594596 anomaly_58_workaround_clear (dev_data );
595597#endif
598+
599+ if (spi_context_tx_buf_on (& dev_data -> ctx )) {
600+ dmm_buffer_out_release (dev_config -> mem_reg ,
601+ (void * * )p_event -> xfer_desc .p_tx_buffer );
602+ }
603+
604+ if (spi_context_rx_buf_on (& dev_data -> ctx )) {
605+ dmm_buffer_in_release (dev_config -> mem_reg , dev_data -> ctx .rx_buf ,
606+ dev_data -> chunk_len , p_event -> xfer_desc .p_rx_buffer );
607+ }
608+
596609#ifdef SPI_BUFFER_IN_RAM
597610 if (spi_context_rx_buf_on (& dev_data -> ctx ) &&
598611 p_event -> xfer_desc .p_rx_buffer != NULL &&
599612 p_event -> xfer_desc .p_rx_buffer != dev_data -> ctx .rx_buf ) {
600- #ifdef CONFIG_DCACHE
601- if (dev_config -> mem_attr & DT_MEM_CACHEABLE ) {
602- sys_cache_data_invd_range (dev_data -> rx_buffer , dev_data -> chunk_len );
603- }
604- #endif
605613 (void )memcpy (dev_data -> ctx .rx_buf ,
606614 dev_data -> rx_buffer ,
607615 dev_data -> chunk_len );
@@ -889,8 +897,6 @@ static int spi_nrfx_deinit(const struct device *dev)
889897 return 0 ;
890898}
891899
892- #define SPIM_MEM_REGION (idx ) DT_PHANDLE(SPIM(idx), memory_regions)
893-
894900#define SPI_NRFX_SPIM_EXTENDED_CONFIG (idx ) \
895901 IF_ENABLED(NRFX_SPIM_EXTENDED_ENABLED, \
896902 (.dcx_pin = NRF_SPIM_PIN_NOT_CONNECTED, \
@@ -899,13 +905,6 @@ static int spi_nrfx_deinit(const struct device *dev)
899905 ()) \
900906 ))
901907
902- #define SPIM_GET_MEM_ATTR (idx ) \
903- COND_CODE_1(SPIM_HAS_PROP(idx, memory_regions), \
904- (COND_CODE_1(DT_NODE_HAS_PROP(SPIM_MEM_REGION(idx), zephyr_memory_attr), \
905- (DT_PROP(SPIM_MEM_REGION(idx), zephyr_memory_attr)), \
906- (0))), \
907- (0))
908-
909908/* Get initialization priority of an instance. Instances that requires clock control
910909 * which is using nrfs (IPC) are initialized later.
911910 */
@@ -925,10 +924,10 @@ static int spi_nrfx_deinit(const struct device *dev)
925924 IF_ENABLED(SPI_BUFFER_IN_RAM, \
926925 (static uint8_t spim_##idx##_tx_buffer \
927926 [CONFIG_SPI_NRFX_RAM_BUFFER_SIZE] \
928- SPIM_MEMORY_SECTION( idx); \
927+ DMM_MEMORY_SECTION(SPIM( idx) ); \
929928 static uint8_t spim_##idx##_rx_buffer \
930929 [CONFIG_SPI_NRFX_RAM_BUFFER_SIZE] \
931- SPIM_MEMORY_SECTION( idx);)) \
930+ DMM_MEMORY_SECTION(SPIM( idx)) ;)) \
932931 static struct spi_nrfx_data spi_##idx##_data = { \
933932 IF_ENABLED(CONFIG_MULTITHREADING, \
934933 (SPI_CONTEXT_INIT_LOCK(spi_##idx##_data, ctx),)) \
@@ -965,8 +964,6 @@ static int spi_nrfx_deinit(const struct device *dev)
965964 .wake_pin = NRF_DT_GPIOS_TO_PSEL_OR(SPIM(idx), wake_gpios, \
966965 WAKE_PIN_NOT_USED), \
967966 .wake_gpiote = WAKE_GPIOTE_INSTANCE(SPIM(idx)), \
968- IF_ENABLED(CONFIG_DCACHE, \
969- (.mem_attr = SPIM_GET_MEM_ATTR(idx),)) \
970967 IF_ENABLED(SPIM_ANY_FAST, \
971968 (.clk_dev = DEVICE_DT_GET_OR_NULL( \
972969 DT_CLOCKS_CTLR(SPIM(idx))), \
@@ -978,6 +975,7 @@ static int spi_nrfx_deinit(const struct device *dev)
978975 .default_port = \
979976 DT_PROP_OR(DT_PHANDLE(SPIM(idx), \
980977 default_gpio_port), port, -1),)) \
978+ .mem_reg = DMM_DEV_TO_REG(SPIM(idx)), \
981979 }; \
982980 BUILD_ASSERT(!SPIM_HAS_PROP(idx, wake_gpios) || \
983981 !(DT_GPIO_FLAGS(SPIM(idx), wake_gpios) & GPIO_ACTIVE_LOW),\
@@ -992,12 +990,6 @@ static int spi_nrfx_deinit(const struct device *dev)
992990 POST_KERNEL, SPIM_INIT_PRIORITY(idx), \
993991 &spi_nrfx_driver_api)
994992
995- #define SPIM_MEMORY_SECTION (idx ) \
996- COND_CODE_1(SPIM_HAS_PROP(idx, memory_regions), \
997- (__attribute__((__section__(LINKER_DT_NODE_REGION_NAME( \
998- SPIM_MEM_REGION(idx)))))), \
999- ())
1000-
1001993#define COND_NRF_SPIM_DEVICE (unused , prefix , i , _ ) \
1002994 IF_ENABLED(CONFIG_HAS_HW_NRF_SPIM##prefix##i, (SPI_NRFX_SPIM_DEFINE(prefix##i);))
1003995
0 commit comments