1515#include <zephyr/irq.h>
1616LOG_MODULE_REGISTER (spi_nrfx_spi , CONFIG_SPI_LOG_LEVEL );
1717
18+ #define DT_DRV_COMPAT nordic_nrf_spi
19+
1820#include "spi_context.h"
1921#include "spi_nrfx_common.h"
2022
2123struct spi_nrfx_data {
24+ nrfx_spi_t spi ;
2225 struct spi_context ctx ;
2326 const struct device * dev ;
2427 size_t chunk_len ;
@@ -27,15 +30,14 @@ struct spi_nrfx_data {
2730};
2831
2932struct spi_nrfx_config {
30- nrfx_spi_t spi ;
3133 nrfx_spi_config_t def_config ;
3234 void (* irq_connect )(void );
3335 const struct pinctrl_dev_config * pcfg ;
3436 nrfx_gpiote_t * wake_gpiote ;
3537 uint32_t wake_pin ;
3638};
3739
38- static void event_handler (const nrfx_spi_evt_t * p_event , void * p_context );
40+ static void event_handler (const nrfx_spi_event_t * p_event , void * p_context );
3941
4042static inline nrf_spi_frequency_t get_nrf_spi_frequency (uint32_t frequency )
4143{
@@ -143,11 +145,11 @@ static int configure(const struct device *dev,
143145 }
144146
145147 if (dev_data -> initialized ) {
146- nrfx_spi_uninit (& dev_config -> spi );
148+ nrfx_spi_uninit (& dev_data -> spi );
147149 dev_data -> initialized = false;
148150 }
149151
150- result = nrfx_spi_init (& dev_config -> spi , & config ,
152+ result = nrfx_spi_init (& dev_data -> spi , & config ,
151153 event_handler , dev_data );
152154 if (result != 0 ) {
153155 LOG_ERR ("Failed to initialize nrfx driver: %d" , result );
@@ -174,7 +176,6 @@ static void finish_transaction(const struct device *dev, int error)
174176
175177static void transfer_next_chunk (const struct device * dev )
176178{
177- const struct spi_nrfx_config * dev_config = dev -> config ;
178179 struct spi_nrfx_data * dev_data = dev -> data ;
179180 struct spi_context * ctx = & dev_data -> ctx ;
180181 int error = 0 ;
@@ -190,7 +191,7 @@ static void transfer_next_chunk(const struct device *dev)
190191 xfer .tx_length = spi_context_tx_buf_on (ctx ) ? chunk_len : 0 ;
191192 xfer .p_rx_buffer = ctx -> rx_buf ;
192193 xfer .rx_length = spi_context_rx_buf_on (ctx ) ? chunk_len : 0 ;
193- error = nrfx_spi_xfer (& dev_config -> spi , & xfer , 0 );
194+ error = nrfx_spi_xfer (& dev_data -> spi , & xfer , 0 );
194195 if (error == 0 ) {
195196 return ;
196197 }
@@ -201,7 +202,7 @@ static void transfer_next_chunk(const struct device *dev)
201202 finish_transaction (dev , error );
202203}
203204
204- static void event_handler (const nrfx_spi_evt_t * p_event , void * p_context )
205+ static void event_handler (const nrfx_spi_event_t * p_event , void * p_context )
205206{
206207 struct spi_nrfx_data * dev_data = p_context ;
207208
@@ -267,7 +268,7 @@ static int transceive(const struct device *dev,
267268 /* Abort the current transfer by deinitializing
268269 * the nrfx driver.
269270 */
270- nrfx_spi_uninit (& dev_config -> spi );
271+ nrfx_spi_uninit (& dev_data -> spi );
271272 dev_data -> initialized = false;
272273
273274 /* Make sure the transaction is finished (it may be
@@ -363,7 +364,7 @@ static int spi_nrfx_pm_action(const struct device *dev,
363364
364365 case PM_DEVICE_ACTION_SUSPEND :
365366 if (dev_data -> initialized ) {
366- nrfx_spi_uninit (& dev_config -> spi );
367+ nrfx_spi_uninit (& dev_data -> spi );
367368 dev_data -> initialized = false;
368369 }
369370
@@ -424,63 +425,50 @@ static int spi_nrfx_init(const struct device *dev)
424425 * - Name-based HAL IRQ handlers, e.g. nrfx_spi_0_irq_handler
425426 */
426427
427- #define SPI (idx ) DT_NODELABEL(spi##idx)
428- #define SPI_PROP (idx , prop ) DT_PROP(SPI(idx), prop)
428+ #define SPI_PROP (idx , prop ) DT_INST_PROP(idx, prop)
429429
430430#define SPI_NRFX_SPI_DEFINE (idx ) \
431- NRF_DT_CHECK_NODE_HAS_PINCTRL_SLEEP(SPI(idx)); \
432- static void irq_connect##idx(void) \
433- { \
434- IRQ_CONNECT(DT_IRQN(SPI(idx)), DT_IRQ(SPI(idx), priority), \
435- nrfx_isr, nrfx_spi_##idx##_irq_handler, 0); \
436- } \
431+ NRF_DT_CHECK_NODE_HAS_PINCTRL_SLEEP(DT_DRV_INST(idx)); \
437432 static struct spi_nrfx_data spi_##idx##_data = { \
438433 IF_ENABLED(CONFIG_MULTITHREADING, \
439434 (SPI_CONTEXT_INIT_LOCK(spi_##idx##_data, ctx),)) \
440435 IF_ENABLED(CONFIG_MULTITHREADING, \
441436 (SPI_CONTEXT_INIT_SYNC(spi_##idx##_data, ctx),)) \
442- SPI_CONTEXT_CS_GPIOS_INITIALIZE(SPI(idx), ctx) \
443- .dev = DEVICE_DT_GET(SPI(idx)), \
437+ SPI_CONTEXT_CS_GPIOS_INITIALIZE(DT_DRV_INST(idx), ctx) \
438+ .spi = NRFX_SPI_INSTANCE(DT_INST_REG_ADDR(idx)), \
439+ .dev = DEVICE_DT_INST_GET(idx), \
444440 .busy = false, \
445441 }; \
446- PINCTRL_DT_DEFINE(SPI(idx)); \
442+ static void irq_connect##idx(void) \
443+ { \
444+ IRQ_CONNECT(DT_INST_IRQN(idx), DT_INST_IRQ(idx, priority), \
445+ nrfx_spi_irq_handler, &spi_##idx##_data.spi, 0); \
446+ } \
447+ PINCTRL_DT_INST_DEFINE(idx); \
447448 static const struct spi_nrfx_config spi_##idx##z_config = { \
448- .spi = { \
449- .p_reg = (NRF_SPI_Type *)DT_REG_ADDR(SPI(idx)), \
450- .drv_inst_idx = NRFX_SPI##idx##_INST_IDX, \
451- }, \
452449 .def_config = { \
453450 .skip_gpio_cfg = true, \
454451 .skip_psel_cfg = true, \
455452 .ss_pin = NRFX_SPI_PIN_NOT_USED, \
456453 .orc = SPI_PROP(idx, overrun_character), \
457454 }, \
458455 .irq_connect = irq_connect##idx, \
459- .pcfg = PINCTRL_DT_DEV_CONFIG_GET(SPI( idx) ), \
460- .wake_gpiote = WAKE_GPIOTE_NODE(SPI (idx)), \
461- .wake_pin = NRF_DT_GPIOS_TO_PSEL_OR(SPI (idx), wake_gpios, \
462- WAKE_PIN_NOT_USED), \
456+ .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET( idx), \
457+ .wake_gpiote = WAKE_GPIOTE_NODE(DT_DRV_INST (idx)), \
458+ .wake_pin = NRF_DT_GPIOS_TO_PSEL_OR(DT_DRV_INST (idx), \
459+ wake_gpios, WAKE_PIN_NOT_USED),\
463460 }; \
464- BUILD_ASSERT(!DT_NODE_HAS_PROP(SPI (idx), wake_gpios) || \
465- !(DT_GPIO_FLAGS(SPI( idx) , wake_gpios) & GPIO_ACTIVE_LOW), \
461+ BUILD_ASSERT(!DT_NODE_HAS_PROP(DT_DRV_INST (idx), wake_gpios) || \
462+ !(DT_INST_GPIO_FLAGS( idx, wake_gpios) & GPIO_ACTIVE_LOW), \
466463 "WAKE line must be configured as active high"); \
467- PM_DEVICE_DT_DEFINE(SPI( idx) , spi_nrfx_pm_action); \
468- SPI_DEVICE_DT_DEFINE(SPI( idx) , \
464+ PM_DEVICE_DT_INST_DEFINE( idx, spi_nrfx_pm_action); \
465+ SPI_DEVICE_DT_INST_DEFINE( idx, \
469466 spi_nrfx_init, \
470- PM_DEVICE_DT_GET(SPI( idx) ), \
467+ PM_DEVICE_DT_INST_GET( idx), \
471468 &spi_##idx##_data, \
472469 &spi_##idx##z_config, \
473470 POST_KERNEL, CONFIG_SPI_INIT_PRIORITY, \
474471 &spi_nrfx_driver_api)
475472
476- #ifdef CONFIG_HAS_HW_NRF_SPI0
477- SPI_NRFX_SPI_DEFINE (0 );
478- #endif
479-
480- #ifdef CONFIG_HAS_HW_NRF_SPI1
481- SPI_NRFX_SPI_DEFINE (1 );
482- #endif
473+ DT_INST_FOREACH_STATUS_OKAY (SPI_NRFX_SPI_DEFINE )
483474
484- #ifdef CONFIG_HAS_HW_NRF_SPI2
485- SPI_NRFX_SPI_DEFINE (2 );
486- #endif
0 commit comments