88#include <zephyr/drivers/spi/rtio.h>
99#include <zephyr/drivers/pinctrl.h>
1010#include <zephyr/drivers/gpio.h>
11+ #include <dmm.h>
1112#include <soc.h>
1213#include <nrfx_spis.h>
1314#include <zephyr/pm/device.h>
@@ -40,6 +41,7 @@ struct spi_nrfx_config {
4041#endif
4142 const struct pinctrl_dev_config * pcfg ;
4243 struct gpio_dt_spec wake_gpio ;
44+ void * mem_reg ;
4345};
4446
4547static inline nrf_spis_mode_t get_nrf_spis_mode (uint16_t operation )
@@ -126,6 +128,7 @@ static int prepare_for_transfer(const struct device *dev,
126128{
127129 const struct spi_nrfx_config * dev_config = dev -> config ;
128130 nrfx_err_t result ;
131+ int err ;
129132
130133 if (tx_buf_len > dev_config -> max_buf_len ||
131134 rx_buf_len > dev_config -> max_buf_len ) {
@@ -134,14 +137,34 @@ static int prepare_for_transfer(const struct device *dev,
134137 return - EINVAL ;
135138 }
136139
140+ err = dmm_buffer_out_prepare (dev_config -> mem_reg , tx_buf , tx_buf_len , (void * * )& tx_buf );
141+ if (err != 0 ) {
142+ LOG_ERR ("DMM TX allocation failed err=%d" , err );
143+ goto out_alloc_failed ;
144+ }
145+
146+ err = dmm_buffer_in_prepare (dev_config -> mem_reg , rx_buf , rx_buf_len , (void * * )& rx_buf );
147+ if (err != 0 ) {
148+ LOG_ERR ("DMM RX allocation failed err=%d" , err );
149+ goto in_alloc_failed ;
150+ }
151+
137152 result = nrfx_spis_buffers_set (& dev_config -> spis ,
138153 tx_buf , tx_buf_len ,
139154 rx_buf , rx_buf_len );
140155 if (result != NRFX_SUCCESS ) {
141- return - EIO ;
156+ err = - EIO ;
157+ goto buffers_set_failed ;
142158 }
143159
144160 return 0 ;
161+
162+ buffers_set_failed :
163+ dmm_buffer_in_release (dev_config -> mem_reg , rx_buf , rx_buf_len , rx_buf );
164+ in_alloc_failed :
165+ dmm_buffer_out_release (dev_config -> mem_reg , (void * )tx_buf );
166+ out_alloc_failed :
167+ return err ;
145168}
146169
147170static void wake_callback (const struct device * dev , struct gpio_callback * cb ,
@@ -205,6 +228,7 @@ static int transceive(const struct device *dev,
205228 nrf_spis_enable (dev_config -> spis .p_reg );
206229 }
207230
231+ spi_context_buffers_setup (& dev_data -> ctx , tx_bufs , rx_bufs , 1 );
208232 error = prepare_for_transfer (dev ,
209233 tx_buf ? tx_buf -> buf : NULL ,
210234 tx_buf ? tx_buf -> len : 0 ,
@@ -288,9 +312,22 @@ static DEVICE_API(spi, spi_nrfx_driver_api) = {
288312
289313static void event_handler (const nrfx_spis_evt_t * p_event , void * p_context )
290314{
291- struct spi_nrfx_data * dev_data = p_context ;
315+ const struct device * dev = p_context ;
316+ struct spi_nrfx_data * dev_data = dev -> data ;
317+ const struct spi_nrfx_config * dev_config = dev -> config ;
292318
293319 if (p_event -> evt_type == NRFX_SPIS_XFER_DONE ) {
320+ int err ;
321+
322+
323+ err = dmm_buffer_out_release (dev_config -> mem_reg , p_event -> p_tx_buf );
324+ (void )err ;
325+ __ASSERT_NO_MSG (err == 0 );
326+
327+ err = dmm_buffer_in_release (dev_config -> mem_reg , dev_data -> ctx .rx_buf ,
328+ p_event -> rx_amount , p_event -> p_rx_buf );
329+ __ASSERT_NO_MSG (err == 0 );
330+
294331 spi_context_complete (& dev_data -> ctx , dev_data -> dev ,
295332 p_event -> rx_amount );
296333
@@ -361,7 +398,7 @@ static int spi_nrfx_init(const struct device *dev)
361398 * actually used are set in configure() when a transfer is prepared.
362399 */
363400 result = nrfx_spis_init (& dev_config -> spis , & dev_config -> config ,
364- event_handler , dev_data );
401+ event_handler , ( void * ) dev );
365402
366403 if (result != NRFX_SUCCESS ) {
367404 LOG_ERR ("Failed to initialize device: %s" , dev -> name );
@@ -416,7 +453,13 @@ static int spi_nrfx_init(const struct device *dev)
416453 * - Name-based HAL IRQ handlers, e.g. nrfx_spis_0_irq_handler
417454 */
418455
419- #define SPIS (idx ) DT_NODELABEL(spi##idx)
456+ #define SPIS_NODE (idx ) \
457+ COND_CODE_1(CONFIG_SOC_NRF54H20, \
458+ (COND_CODE_1(IS_EQ(idx, 120), (spis##idx), (spi##idx))), \
459+ (spi##idx))
460+
461+ #define SPIS (idx ) DT_NODELABEL(SPIS_NODE(idx))
462+
420463#define SPIS_PROP (idx , prop ) DT_PROP(SPIS(idx), prop)
421464
422465#define SPI_NRFX_SPIS_DEFINE (idx ) \
@@ -453,6 +496,7 @@ static int spi_nrfx_init(const struct device *dev)
453496 (.gpd_ctrl = NRF_PERIPH_GET_FREQUENCY(SPIS(idx)) > \
454497 NRFX_MHZ_TO_HZ(16UL),)) \
455498 .wake_gpio = GPIO_DT_SPEC_GET_OR(SPIS(idx), wake_gpios, {0}), \
499+ .mem_reg = DMM_DEV_TO_REG(SPIS(idx)), \
456500 }; \
457501 BUILD_ASSERT(!DT_NODE_HAS_PROP(SPIS(idx), wake_gpios) || \
458502 !(DT_GPIO_FLAGS(SPIS(idx), wake_gpios) & GPIO_ACTIVE_LOW),\
0 commit comments