13
13
#include <zephyr/drivers/pinctrl.h>
14
14
#include <zephyr/mem_mgmt/mem_attr.h>
15
15
#include <soc.h>
16
+ #include <dmm.h>
16
17
#ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
17
18
#include <nrfx_ppi.h>
18
19
#endif
@@ -133,9 +134,6 @@ struct spi_nrfx_config {
133
134
#endif
134
135
uint32_t wake_pin ;
135
136
nrfx_gpiote_t wake_gpiote ;
136
- #ifdef CONFIG_DCACHE
137
- uint32_t mem_attr ;
138
- #endif
139
137
#ifdef SPIM_ANY_FAST
140
138
const struct device * clk_dev ;
141
139
struct nrf_clock_spec clk_spec ;
@@ -144,6 +142,7 @@ struct spi_nrfx_config {
144
142
bool cross_domain ;
145
143
int8_t default_port ;
146
144
#endif
145
+ void * mem_reg ;
147
146
};
148
147
149
148
static 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)
514
513
}
515
514
516
515
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
522
516
tx_buf = dev_data -> tx_buffer ;
523
517
}
524
518
@@ -535,10 +529,20 @@ static void transfer_next_chunk(const struct device *dev)
535
529
536
530
dev_data -> chunk_len = chunk_len ;
537
531
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
+ }
542
546
543
547
#ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
544
548
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)
577
581
{
578
582
const struct device * dev = p_context ;
579
583
struct spi_nrfx_data * dev_data = dev -> data ;
580
- #ifdef CONFIG_DCACHE
581
584
const struct spi_nrfx_config * dev_config = dev -> config ;
582
- #endif
583
585
584
586
if (p_event -> type == NRFX_SPIM_EVENT_DONE ) {
585
587
/* 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)
593
595
#ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
594
596
anomaly_58_workaround_clear (dev_data );
595
597
#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
+
596
609
#ifdef SPI_BUFFER_IN_RAM
597
610
if (spi_context_rx_buf_on (& dev_data -> ctx ) &&
598
611
p_event -> xfer_desc .p_rx_buffer != NULL &&
599
612
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
605
613
(void )memcpy (dev_data -> ctx .rx_buf ,
606
614
dev_data -> rx_buffer ,
607
615
dev_data -> chunk_len );
@@ -889,8 +897,6 @@ static int spi_nrfx_deinit(const struct device *dev)
889
897
return 0 ;
890
898
}
891
899
892
- #define SPIM_MEM_REGION (idx ) DT_PHANDLE(SPIM(idx), memory_regions)
893
-
894
900
#define SPI_NRFX_SPIM_EXTENDED_CONFIG (idx ) \
895
901
IF_ENABLED(NRFX_SPIM_EXTENDED_ENABLED, \
896
902
(.dcx_pin = NRF_SPIM_PIN_NOT_CONNECTED, \
@@ -899,13 +905,6 @@ static int spi_nrfx_deinit(const struct device *dev)
899
905
()) \
900
906
))
901
907
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
-
909
908
/* Get initialization priority of an instance. Instances that requires clock control
910
909
* which is using nrfs (IPC) are initialized later.
911
910
*/
@@ -925,10 +924,10 @@ static int spi_nrfx_deinit(const struct device *dev)
925
924
IF_ENABLED(SPI_BUFFER_IN_RAM, \
926
925
(static uint8_t spim_##idx##_tx_buffer \
927
926
[CONFIG_SPI_NRFX_RAM_BUFFER_SIZE] \
928
- SPIM_MEMORY_SECTION( idx); \
927
+ DMM_MEMORY_SECTION(SPIM( idx) ); \
929
928
static uint8_t spim_##idx##_rx_buffer \
930
929
[CONFIG_SPI_NRFX_RAM_BUFFER_SIZE] \
931
- SPIM_MEMORY_SECTION( idx);)) \
930
+ DMM_MEMORY_SECTION(SPIM( idx)) ;)) \
932
931
static struct spi_nrfx_data spi_##idx##_data = { \
933
932
IF_ENABLED(CONFIG_MULTITHREADING, \
934
933
(SPI_CONTEXT_INIT_LOCK(spi_##idx##_data, ctx),)) \
@@ -965,8 +964,6 @@ static int spi_nrfx_deinit(const struct device *dev)
965
964
.wake_pin = NRF_DT_GPIOS_TO_PSEL_OR(SPIM(idx), wake_gpios, \
966
965
WAKE_PIN_NOT_USED), \
967
966
.wake_gpiote = WAKE_GPIOTE_INSTANCE(SPIM(idx)), \
968
- IF_ENABLED(CONFIG_DCACHE, \
969
- (.mem_attr = SPIM_GET_MEM_ATTR(idx),)) \
970
967
IF_ENABLED(SPIM_ANY_FAST, \
971
968
(.clk_dev = DEVICE_DT_GET_OR_NULL( \
972
969
DT_CLOCKS_CTLR(SPIM(idx))), \
@@ -978,6 +975,7 @@ static int spi_nrfx_deinit(const struct device *dev)
978
975
.default_port = \
979
976
DT_PROP_OR(DT_PHANDLE(SPIM(idx), \
980
977
default_gpio_port), port, -1),)) \
978
+ .mem_reg = DMM_DEV_TO_REG(SPIM(idx)), \
981
979
}; \
982
980
BUILD_ASSERT(!SPIM_HAS_PROP(idx, wake_gpios) || \
983
981
!(DT_GPIO_FLAGS(SPIM(idx), wake_gpios) & GPIO_ACTIVE_LOW),\
@@ -992,12 +990,6 @@ static int spi_nrfx_deinit(const struct device *dev)
992
990
POST_KERNEL, SPIM_INIT_PRIORITY(idx), \
993
991
&spi_nrfx_driver_api)
994
992
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
-
1001
993
#define COND_NRF_SPIM_DEVICE (unused , prefix , i , _ ) \
1002
994
IF_ENABLED(CONFIG_HAS_HW_NRF_SPIM##prefix##i, (SPI_NRFX_SPIM_DEFINE(prefix##i);))
1003
995
0 commit comments